house-lights 1.0.0 → 1.0.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/package.json +1 -1
- package/skills/back-of-napkin/assets/VERSION +2 -2
- package/skills/back-of-napkin/assets/player.html +3 -3
- package/skills/back-of-napkin/references/recipe.md +1 -1
- package/skills/back-of-napkin/references/text.md +1 -1
- package/skills/back-of-napkin/scripts/contract.mjs +1 -1
- package/skills/back-of-napkin/scripts/engine-build.mjs +1 -1
- package/skills/back-of-napkin/scripts/mermaid.mjs +1 -1
- package/skills/back-of-napkin/scripts/pptx.mjs +16 -16
- package/skills/back-of-napkin/scripts/syntax.mjs +1 -1
- package/skills/chalk-talk/assets/player.html +3 -3
- package/skills/chalk-talk/scripts/pptx.mjs +16 -16
- package/skills/dress-rehearsal/assets/VERSION +1 -1
- package/skills/dress-rehearsal/assets/drill.html +3 -3
- package/skills/dress-rehearsal/references/format.md +2 -1
- package/skills/dress-rehearsal/scripts/build.mjs +3 -8
- package/skills/dress-rehearsal/scripts/engine.mjs +59 -58
- package/skills/gates-and-handoffs/assets/VERSION +1 -1
- package/skills/gates-and-handoffs/assets/lesson.html +3 -3
- package/skills/service-blueprint/assets/VERSION +1 -1
- package/skills/service-blueprint/assets/lesson.html +3 -3
- package/skills/service-blueprint/assets/map.html +22 -20
- package/skills/service-blueprint/scripts/engine.mjs +19 -19
|
@@ -146,11 +146,11 @@ body.still #stage { padding: 0; max-width: none; }
|
|
|
146
146
|
</head>
|
|
147
147
|
<body>
|
|
148
148
|
<main id="stage">
|
|
149
|
-
<nav id="course" class="course"
|
|
149
|
+
<nav id="course" class="course" hidden></nav>
|
|
150
150
|
<div id="lesson"></div>
|
|
151
151
|
</main>
|
|
152
152
|
<script type="application/json" id="chalk-recipe">{{RECIPE}}</script>
|
|
153
|
-
<script>"use strict";(()=>{var Jr=Object.create;var Be=Object.defineProperty;var to=Object.getOwnPropertyDescriptor;var eo=Object.getOwnPropertyNames;var no=Object.getPrototypeOf,ro=Object.prototype.hasOwnProperty;var oo=(e,t,n)=>t in e?Be(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var so=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var io=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of eo(t))!ro.call(e,o)&&o!==n&&Be(e,o,{get:()=>t[o],enumerable:!(r=to(t,o))||r.enumerable});return e};var Pn=(e,t,n)=>(n=e!=null?Jr(no(e)):{},io(t||!e||!e.__esModule?Be(n,"default",{value:e,enumerable:!0}):n,e));var q=(e,t,n)=>oo(e,typeof t!="symbol"?t+"":t,n);var $n=so(vn=>{var Cr=Object.defineProperty,Jo=e=>Cr(e,"__esModule",{value:!0}),ts=(e,t)=>{for(var n in t)Cr(e,n,{get:t[n],enumerable:!0})};Jo(vn);ts(vn,{GIFEncoder:()=>Ir,applyPalette:()=>ls,default:()=>ws,nearestColor:()=>ps,nearestColorIndex:()=>jr,nearestColorIndexWithDistance:()=>Nr,prequantize:()=>cs,quantize:()=>is,snapColorsToPalette:()=>ds});var es={signature:"GIF",version:"89a",trailer:59,extensionIntroducer:33,applicationExtensionLabel:255,graphicControlExtensionLabel:249,imageSeparator:44,signatureSize:3,versionSize:3,globalColorTableFlagMask:128,colorResolutionMask:112,sortFlagMask:8,globalColorTableSizeMask:7,applicationIdentifierSize:8,applicationAuthCodeSize:3,disposalMethodMask:28,userInputFlagMask:2,transparentColorFlagMask:1,localColorTableFlagMask:128,interlaceFlagMask:64,idSortFlagMask:32,localColorTableSizeMask:7};function Tr(e=256){let t=0,n=new Uint8Array(e);return{get buffer(){return n.buffer},reset(){t=0},bytesView(){return n.subarray(0,t)},bytes(){return n.slice(0,t)},writeByte(o){r(t+1),n[t]=o,t++},writeBytes(o,s=0,a=o.length){r(t+a);for(let i=0;i<a;i++)n[t++]=o[i+s]},writeBytesView(o,s=0,a=o.byteLength){r(t+a),n.set(o.subarray(s,s+a),t),t+=a}};function r(o){var s=n.length;if(s>=o)return;var a=1024*1024;o=Math.max(o,s*(s<a?2:1.125)>>>0),s!=0&&(o=Math.max(o,256));let i=n;n=new Uint8Array(o),t>0&&n.set(i.subarray(0,t),0)}}var wn=12,Or=5003,ns=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535];function rs(e,t,n,r,o=Tr(512),s=new Uint8Array(256),a=new Int32Array(Or),i=new Int32Array(Or)){let l=a.length,c=Math.max(2,r);s.fill(0),i.fill(0),a.fill(-1);let h=0,u=0,d=c+1,p=d,m=!1,g=p,f=(1<<g)-1,b=1<<d-1,y=b+1,w=b+2,k=0,v=n[0],M=0;for(let C=l;C<65536;C*=2)++M;M=8-M,o.writeByte(c),R(b);let S=n.length;for(let C=1;C<S;C++)t:{let L=n[C],D=(L<<wn)+v,I=L<<M^v;if(a[I]===D){v=i[I];break t}let W=I===0?1:l-I;for(;a[I]>=0;)if(I-=W,I<0&&(I+=l),a[I]===D){v=i[I];break t}R(v),v=L,w<1<<wn?(i[I]=w++,a[I]=D):(a.fill(-1),w=b+2,m=!0,R(b))}return R(v),R(y),o.writeByte(0),o.bytesView();function R(C){for(h&=ns[u],u>0?h|=C<<u:h=C,u+=g;u>=8;)s[k++]=h&255,k>=254&&(o.writeByte(k),o.writeBytesView(s,0,k),k=0),h>>=8,u-=8;if((w>f||m)&&(m?(g=p,f=(1<<g)-1,m=!1):(++g,f=g===wn?1<<g:(1<<g)-1)),C==y){for(;u>0;)s[k++]=h&255,k>=254&&(o.writeByte(k),o.writeBytesView(s,0,k),k=0),h>>=8,u-=8;k>0&&(o.writeByte(k),o.writeBytesView(s,0,k),k=0)}}}var os=rs;function zr(e,t,n){return e<<8&63488|t<<2&992|n>>3}function Br(e,t,n,r){return e>>4|t&240|(n&240)<<4|(r&240)<<8}function Rr(e,t,n){return e>>4<<8|t&240|n>>4}function Pe(e,t,n){return e<t?t:e>n?n:e}function ce(e){return e*e}function Pr(e,t,n){var r=0,o=1e100;let s=e[t],a=s.cnt,i=s.ac,l=s.rc,c=s.gc,h=s.bc;for(var u=s.fw;u!=0;u=e[u].fw){let p=e[u],m=p.cnt,g=a*m/(a+m);if(!(g>=o)){var d=0;n&&(d+=g*ce(p.ac-i),d>=o)||(d+=g*ce(p.rc-l),!(d>=o)&&(d+=g*ce(p.gc-c),!(d>=o)&&(d+=g*ce(p.bc-h),!(d>=o)&&(o=d,r=u))))}}s.err=o,s.nn=r}function xn(){return{ac:0,rc:0,gc:0,bc:0,cnt:0,nn:0,fw:0,bk:0,tm:0,mtm:0,err:0}}function ss(e,t){let n=t==="rgb444"?4096:65536,r=new Array(n),o=e.length;if(t==="rgba4444")for(let s=0;s<o;++s){let a=e[s],i=a>>24&255,l=a>>16&255,c=a>>8&255,h=a&255,u=Br(h,c,l,i),d=u in r?r[u]:r[u]=xn();d.rc+=h,d.gc+=c,d.bc+=l,d.ac+=i,d.cnt++}else if(t==="rgb444")for(let s=0;s<o;++s){let a=e[s],i=a>>16&255,l=a>>8&255,c=a&255,h=Rr(c,l,i),u=h in r?r[h]:r[h]=xn();u.rc+=c,u.gc+=l,u.bc+=i,u.cnt++}else for(let s=0;s<o;++s){let a=e[s],i=a>>16&255,l=a>>8&255,c=a&255,h=zr(c,l,i),u=h in r?r[h]:r[h]=xn();u.rc+=c,u.gc+=l,u.bc+=i,u.cnt++}return r}function is(e,t,n={}){let{format:r="rgb565",clearAlpha:o=!0,clearAlphaColor:s=0,clearAlphaThreshold:a=0,oneBitAlpha:i=!1}=n;if(!e||!e.buffer)throw new Error("quantize() expected RGBA Uint8Array data");if(!(e instanceof Uint8Array)&&!(e instanceof Uint8ClampedArray))throw new Error("quantize() expected RGBA Uint8Array data");let l=new Uint32Array(e.buffer),c=n.useSqrt!==!1,h=r==="rgba4444",u=ss(l,r),d=u.length,p=d-1,m=new Uint32Array(d+1);for(var g=0,b=0;b<d;++b){let V=u[b];if(V!=null){var f=1/V.cnt;h&&(V.ac*=f),V.rc*=f,V.gc*=f,V.bc*=f,u[g++]=V}}ce(t)/g<.022&&(c=!1);for(var b=0;b<g-1;++b)u[b].fw=b+1,u[b+1].bk=b,c&&(u[b].cnt=Math.sqrt(u[b].cnt));c&&(u[b].cnt=Math.sqrt(u[b].cnt));var y,w,k;for(b=0;b<g;++b){Pr(u,b,!1);var v=u[b].err;for(w=++m[0];w>1&&(k=w>>1,!(u[y=m[k]].err<=v));w=k)m[w]=y;m[w]=b}var M=g-t;for(b=0;b<M;){for(var S;;){var R=m[1];if(S=u[R],S.tm>=S.mtm&&u[S.nn].mtm<=S.tm)break;S.mtm==p?R=m[1]=m[m[0]--]:(Pr(u,R,!1),S.tm=b);var v=u[R].err;for(w=1;(k=w+w)<=m[0]&&(k<m[0]&&u[m[k]].err>u[m[k+1]].err&&k++,!(v<=u[y=m[k]].err));w=k)m[w]=y;m[w]=R}var C=u[S.nn],L=S.cnt,D=C.cnt,f=1/(L+D);h&&(S.ac=f*(L*S.ac+D*C.ac)),S.rc=f*(L*S.rc+D*C.rc),S.gc=f*(L*S.gc+D*C.gc),S.bc=f*(L*S.bc+D*C.bc),S.cnt+=C.cnt,S.mtm=++b,u[C.bk].fw=C.fw,u[C.fw].bk=C.bk,C.mtm=p}let I=[];var W=0;for(b=0;;++W){let X=Pe(Math.round(u[b].rc),0,255),V=Pe(Math.round(u[b].gc),0,255),pt=Pe(Math.round(u[b].bc),0,255),tt=255;h&&(tt=Pe(Math.round(u[b].ac),0,255),i&&(tt=tt<=(typeof i=="number"?i:127)?0:255),o&&tt<=a&&(X=V=pt=s,tt=0));let J=h?[X,V,pt,tt]:[X,V,pt];if(as(I,J)||I.push(J),(b=u[b].fw)==0)break}return I}function as(e,t){for(let n=0;n<e.length;n++){let r=e[n],o=r[0]===t[0]&&r[1]===t[1]&&r[2]===t[2],s=r.length>=4&&t.length>=4?r[3]===t[3]:!0;if(o&&s)return!0}return!1}function Ce(e,t){var n=0,r;for(r=0;r<e.length;r++){let o=e[r]-t[r];n+=o*o}return n}function Le(e,t){return t>1?Math.round(e/t)*t:e}function cs(e,{roundRGB:t=5,roundAlpha:n=10,oneBitAlpha:r=null}={}){let o=new Uint32Array(e.buffer);for(let s=0;s<o.length;s++){let a=o[s],i=a>>24&255,l=a>>16&255,c=a>>8&255,h=a&255;i=Le(i,n),r&&(i=i<=(typeof r=="number"?r:127)?0:255),h=Le(h,t),c=Le(c,t),l=Le(l,t),o[s]=i<<24|l<<16|c<<8|h<<0}}function ls(e,t,n="rgb565"){if(!e||!e.buffer)throw new Error("quantize() expected RGBA Uint8Array data");if(!(e instanceof Uint8Array)&&!(e instanceof Uint8ClampedArray))throw new Error("quantize() expected RGBA Uint8Array data");if(t.length>256)throw new Error("applyPalette() only works with 256 colors or less");let r=new Uint32Array(e.buffer),o=r.length,s=n==="rgb444"?4096:65536,a=new Uint8Array(o),i=new Array(s),l=n==="rgba4444";if(n==="rgba4444")for(let c=0;c<o;c++){let h=r[c],u=h>>24&255,d=h>>16&255,p=h>>8&255,m=h&255,g=Br(m,p,d,u),f=g in i?i[g]:i[g]=hs(m,p,d,u,t);a[c]=f}else{let c=n==="rgb444"?Rr:zr;for(let h=0;h<o;h++){let u=r[h],d=u>>16&255,p=u>>8&255,m=u&255,g=c(m,p,d),f=g in i?i[g]:i[g]=us(m,p,d,t);a[h]=f}}return a}function hs(e,t,n,r,o){let s=0,a=1e100;for(let i=0;i<o.length;i++){let l=o[i],c=l[3],h=jt(c-r);if(h>a)continue;let u=l[0];if(h+=jt(u-e),h>a)continue;let d=l[1];if(h+=jt(d-t),h>a)continue;let p=l[2];h+=jt(p-n),!(h>a)&&(a=h,s=i)}return s}function us(e,t,n,r){let o=0,s=1e100;for(let a=0;a<r.length;a++){let i=r[a],l=i[0],c=jt(l-e);if(c>s)continue;let h=i[1];if(c+=jt(h-t),c>s)continue;let u=i[2];c+=jt(u-n),!(c>s)&&(s=c,o=a)}return o}function ds(e,t,n=5){if(!e.length||!t.length)return;let r=e.map(a=>a.slice(0,3)),o=n*n,s=e[0].length;for(let a=0;a<t.length;a++){let i=t[a];i.length<s?i=[i[0],i[1],i[2],255]:i.length>s?i=i.slice(0,3):i=i.slice();let l=Nr(r,i.slice(0,3),Ce),c=l[0],h=l[1];h>0&&h<=o&&(e[c]=i)}}function jt(e){return e*e}function jr(e,t,n=Ce){let r=1/0,o=-1;for(let s=0;s<e.length;s++){let a=e[s],i=n(t,a);i<r&&(r=i,o=s)}return o}function Nr(e,t,n=Ce){let r=1/0,o=-1;for(let s=0;s<e.length;s++){let a=e[s],i=n(t,a);i<r&&(r=i,o=s)}return[o,r]}function ps(e,t,n=Ce){return e[jr(e,t,n)]}function Ir(e={}){let{initialCapacity:t=4096,auto:n=!0}=e,r=Tr(t),o=5003,s=new Uint8Array(256),a=new Int32Array(o),i=new Int32Array(o),l=!1;return{reset(){r.reset(),l=!1},finish(){r.writeByte(es.trailer)},bytes(){return r.bytes()},bytesView(){return r.bytesView()},get buffer(){return r.buffer},get stream(){return r},writeHeader:c,writeFrame(h,u,d,p={}){let{transparent:m=!1,transparentIndex:g=0,delay:f=0,palette:b=null,repeat:y=0,colorDepth:w=8,dispose:k=-1}=p,v=!1;if(n?l||(v=!0,c(),l=!0):v=!!p.first,u=Math.max(0,Math.floor(u)),d=Math.max(0,Math.floor(d)),v){if(!b)throw new Error("First frame must include a { palette } option");ms(r,u,d,b,w),Lr(r,b),y>=0&&gs(r,y)}let M=Math.round(f/10);fs(r,k,M,m,g);let S=!!b&&!v;bs(r,u,d,S?b:null),S&&Lr(r,b),ys(r,h,u,d,w,s,a,i)}};function c(){Dr(r,"GIF89a")}}function fs(e,t,n,r,o){e.writeByte(33),e.writeByte(249),e.writeByte(4),o<0&&(o=0,r=!1);var s,a;r?(s=1,a=2):(s=0,a=0),t>=0&&(a=t&7),a<<=2,e.writeByte(0|a|0|s),Et(e,n),e.writeByte(o||0),e.writeByte(0)}function ms(e,t,n,r,o=8){let i=kn(r.length)-1,l=128|o-1<<4|0|i,c=0,h=0;Et(e,t),Et(e,n),e.writeBytes([l,c,h])}function gs(e,t){e.writeByte(33),e.writeByte(255),e.writeByte(11),Dr(e,"NETSCAPE2.0"),e.writeByte(3),e.writeByte(1),Et(e,t),e.writeByte(0)}function Lr(e,t){let n=1<<kn(t.length);for(let r=0;r<n;r++){let o=[0,0,0];r<t.length&&(o=t[r]),e.writeByte(o[0]),e.writeByte(o[1]),e.writeByte(o[2])}}function bs(e,t,n,r){if(e.writeByte(44),Et(e,0),Et(e,0),Et(e,t),Et(e,n),r){let a=kn(r.length)-1;e.writeByte(128|a)}else e.writeByte(0)}function ys(e,t,n,r,o=8,s,a,i){os(n,r,t,o,e,s,a,i)}function Et(e,t){e.writeByte(t&255),e.writeByte(t>>8&255)}function Dr(e,t){for(var n=0;n<t.length;n++)e.writeByte(t.charCodeAt(n))}function kn(e){return Math.max(Math.ceil(Math.log2(e)),1)}var ws=Ir});function Re(e,t,n){if(e&&e.length){let[r,o]=t,s=Math.PI/180*n,a=Math.cos(s),i=Math.sin(s);for(let l of e){let[c,h]=l;l[0]=(c-r)*a-(h-o)*i+r,l[1]=(c-r)*i+(h-o)*a+o}}}function ao(e,t){return e[0]===t[0]&&e[1]===t[1]}function co(e,t,n,r=1){let o=n,s=Math.max(t,.1),a=e[0]&&e[0][0]&&typeof e[0][0]=="number"?[e]:e,i=[0,0];if(o)for(let c of a)Re(c,i,o);let l=function(c,h,u){let d=[];for(let y of c){let w=[...y];ao(w[0],w[w.length-1])||w.push([w[0][0],w[0][1]]),w.length>2&&d.push(w)}let p=[];h=Math.max(h,.1);let m=[];for(let y of d)for(let w=0;w<y.length-1;w++){let k=y[w],v=y[w+1];if(k[1]!==v[1]){let M=Math.min(k[1],v[1]);m.push({ymin:M,ymax:Math.max(k[1],v[1]),x:M===k[1]?k[0]:v[0],islope:(v[0]-k[0])/(v[1]-k[1])})}}if(m.sort((y,w)=>y.ymin<w.ymin?-1:y.ymin>w.ymin?1:y.x<w.x?-1:y.x>w.x?1:y.ymax===w.ymax?0:(y.ymax-w.ymax)/Math.abs(y.ymax-w.ymax)),!m.length)return p;let g=[],f=m[0].ymin,b=0;for(;g.length||m.length;){if(m.length){let y=-1;for(let w=0;w<m.length&&!(m[w].ymin>f);w++)y=w;m.splice(0,y+1).forEach(w=>{g.push({s:f,edge:w})})}if(g=g.filter(y=>!(y.edge.ymax<=f)),g.sort((y,w)=>y.edge.x===w.edge.x?0:(y.edge.x-w.edge.x)/Math.abs(y.edge.x-w.edge.x)),(u!==1||b%h==0)&&g.length>1)for(let y=0;y<g.length;y+=2){let w=y+1;if(w>=g.length)break;let k=g[y].edge,v=g[w].edge;p.push([[Math.round(k.x),f],[Math.round(v.x),f]])}f+=u,g.forEach(y=>{y.edge.x=y.edge.x+u*y.edge.islope}),b++}return p}(a,s,r);if(o){for(let c of a)Re(c,i,-o);(function(c,h,u){let d=[];c.forEach(p=>d.push(...p)),Re(d,h,u)})(l,i,-o)}return l}function ne(e,t){var n;let r=t.hachureAngle+90,o=t.hachureGap;o<0&&(o=4*t.strokeWidth),o=Math.round(Math.max(o,.1));let s=1;return t.roughness>=1&&(((n=t.randomizer)===null||n===void 0?void 0:n.next())||Math.random())>.7&&(s=o),co(e,o,r,s||1)}var ee=class{constructor(t){this.helper=t}fillPolygons(t,n){return this._fillPolygons(t,n)}_fillPolygons(t,n){let r=ne(t,n);return{type:"fillSketch",ops:this.renderLines(r,n)}}renderLines(t,n){let r=[];for(let o of t)r.push(...this.helper.doubleLineOps(o[0][0],o[0][1],o[1][0],o[1][1],n));return r}};function we(e){let t=e[0],n=e[1];return Math.sqrt(Math.pow(t[0]-n[0],2)+Math.pow(t[1]-n[1],2))}var Fe=class extends ee{fillPolygons(t,n){let r=n.hachureGap;r<0&&(r=4*n.strokeWidth),r=Math.max(r,.1);let o=ne(t,Object.assign({},n,{hachureGap:r})),s=Math.PI/180*n.hachureAngle,a=[],i=.5*r*Math.cos(s),l=.5*r*Math.sin(s);for(let[c,h]of o)we([c,h])&&a.push([[c[0]-i,c[1]+l],[...h]],[[c[0]+i,c[1]-l],[...h]]);return{type:"fillSketch",ops:this.renderLines(a,n)}}},_e=class extends ee{fillPolygons(t,n){let r=this._fillPolygons(t,n),o=Object.assign({},n,{hachureAngle:n.hachureAngle+90}),s=this._fillPolygons(t,o);return r.ops=r.ops.concat(s.ops),r}},qe=class{constructor(t){this.helper=t}fillPolygons(t,n){let r=ne(t,n=Object.assign({},n,{hachureAngle:0}));return this.dotsOnLines(r,n)}dotsOnLines(t,n){let r=[],o=n.hachureGap;o<0&&(o=4*n.strokeWidth),o=Math.max(o,.1);let s=n.fillWeight;s<0&&(s=n.strokeWidth/2);let a=o/4;for(let i of t){let l=we(i),c=l/o,h=Math.ceil(c)-1,u=l-h*o,d=(i[0][0]+i[1][0])/2-o/4,p=Math.min(i[0][1],i[1][1]);for(let m=0;m<h;m++){let g=p+u+m*o,f=d-a+2*Math.random()*a,b=g-a+2*Math.random()*a,y=this.helper.ellipse(f,b,s,s,n);r.push(...y.ops)}}return{type:"fillSketch",ops:r}}},Ge=class{constructor(t){this.helper=t}fillPolygons(t,n){let r=ne(t,n);return{type:"fillSketch",ops:this.dashedLine(r,n)}}dashedLine(t,n){let r=n.dashOffset<0?n.hachureGap<0?4*n.strokeWidth:n.hachureGap:n.dashOffset,o=n.dashGap<0?n.hachureGap<0?4*n.strokeWidth:n.hachureGap:n.dashGap,s=[];return t.forEach(a=>{let i=we(a),l=Math.floor(i/(r+o)),c=(i+o-l*(r+o))/2,h=a[0],u=a[1];h[0]>u[0]&&(h=a[1],u=a[0]);let d=Math.atan((u[1]-h[1])/(u[0]-h[0]));for(let p=0;p<l;p++){let m=p*(r+o),g=m+r,f=[h[0]+m*Math.cos(d)+c*Math.cos(d),h[1]+m*Math.sin(d)+c*Math.sin(d)],b=[h[0]+g*Math.cos(d)+c*Math.cos(d),h[1]+g*Math.sin(d)+c*Math.sin(d)];s.push(...this.helper.doubleLineOps(f[0],f[1],b[0],b[1],n))}}),s}},Xe=class{constructor(t){this.helper=t}fillPolygons(t,n){let r=n.hachureGap<0?4*n.strokeWidth:n.hachureGap,o=n.zigzagOffset<0?r:n.zigzagOffset,s=ne(t,n=Object.assign({},n,{hachureGap:r+o}));return{type:"fillSketch",ops:this.zigzagLines(s,o,n)}}zigzagLines(t,n,r){let o=[];return t.forEach(s=>{let a=we(s),i=Math.round(a/(2*n)),l=s[0],c=s[1];l[0]>c[0]&&(l=s[1],c=s[0]);let h=Math.atan((c[1]-l[1])/(c[0]-l[0]));for(let u=0;u<i;u++){let d=2*u*n,p=2*(u+1)*n,m=Math.sqrt(2*Math.pow(n,2)),g=[l[0]+d*Math.cos(h),l[1]+d*Math.sin(h)],f=[l[0]+p*Math.cos(h),l[1]+p*Math.sin(h)],b=[g[0]+m*Math.cos(h+Math.PI/4),g[1]+m*Math.sin(h+Math.PI/4)];o.push(...this.helper.doubleLineOps(g[0],g[1],b[0],b[1],r),...this.helper.doubleLineOps(b[0],b[1],f[0],f[1],r))}}),o}},it={},Ye=class{constructor(t){this.seed=t}next(){return this.seed?(2**31-1&(this.seed=Math.imul(48271,this.seed)))/2**31:Math.random()}},lo=0,je=1,Ln=2,ue={A:7,a:7,C:6,c:6,H:1,h:1,L:2,l:2,M:2,m:2,Q:4,q:4,S:4,s:4,T:2,t:2,V:1,v:1,Z:0,z:0};function Ne(e,t){return e.type===t}function Ze(e){let t=[],n=function(a){let i=new Array;for(;a!=="";)if(a.match(/^([ \t\r\n,]+)/))a=a.substr(RegExp.$1.length);else if(a.match(/^([aAcChHlLmMqQsStTvVzZ])/))i[i.length]={type:lo,text:RegExp.$1},a=a.substr(RegExp.$1.length);else{if(!a.match(/^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)/))return[];i[i.length]={type:je,text:`${parseFloat(RegExp.$1)}`},a=a.substr(RegExp.$1.length)}return i[i.length]={type:Ln,text:""},i}(e),r="BOD",o=0,s=n[o];for(;!Ne(s,Ln);){let a=0,i=[];if(r==="BOD"){if(s.text!=="M"&&s.text!=="m")return Ze("M0,0"+e);o++,a=ue[s.text],r=s.text}else Ne(s,je)?a=ue[r]:(o++,a=ue[s.text],r=s.text);if(!(o+a<n.length))throw new Error("Path data ended short");for(let l=o;l<o+a;l++){let c=n[l];if(!Ne(c,je))throw new Error("Param not a number: "+r+","+c.text);i[i.length]=+c.text}if(typeof ue[r]!="number")throw new Error("Bad segment: "+r);{let l={key:r,data:i};t.push(l),o+=a,s=n[o],r==="M"&&(r="L"),r==="m"&&(r="l")}}return t}function In(e){let t=0,n=0,r=0,o=0,s=[];for(let{key:a,data:i}of e)switch(a){case"M":s.push({key:"M",data:[...i]}),[t,n]=i,[r,o]=i;break;case"m":t+=i[0],n+=i[1],s.push({key:"M",data:[t,n]}),r=t,o=n;break;case"L":s.push({key:"L",data:[...i]}),[t,n]=i;break;case"l":t+=i[0],n+=i[1],s.push({key:"L",data:[t,n]});break;case"C":s.push({key:"C",data:[...i]}),t=i[4],n=i[5];break;case"c":{let l=i.map((c,h)=>h%2?c+n:c+t);s.push({key:"C",data:l}),t=l[4],n=l[5];break}case"Q":s.push({key:"Q",data:[...i]}),t=i[2],n=i[3];break;case"q":{let l=i.map((c,h)=>h%2?c+n:c+t);s.push({key:"Q",data:l}),t=l[2],n=l[3];break}case"A":s.push({key:"A",data:[...i]}),t=i[5],n=i[6];break;case"a":t+=i[5],n+=i[6],s.push({key:"A",data:[i[0],i[1],i[2],i[3],i[4],t,n]});break;case"H":s.push({key:"H",data:[...i]}),t=i[0];break;case"h":t+=i[0],s.push({key:"H",data:[t]});break;case"V":s.push({key:"V",data:[...i]}),n=i[0];break;case"v":n+=i[0],s.push({key:"V",data:[n]});break;case"S":s.push({key:"S",data:[...i]}),t=i[2],n=i[3];break;case"s":{let l=i.map((c,h)=>h%2?c+n:c+t);s.push({key:"S",data:l}),t=l[2],n=l[3];break}case"T":s.push({key:"T",data:[...i]}),t=i[0],n=i[1];break;case"t":t+=i[0],n+=i[1],s.push({key:"T",data:[t,n]});break;case"Z":case"z":s.push({key:"Z",data:[]}),t=r,n=o}return s}function Dn(e){let t=[],n="",r=0,o=0,s=0,a=0,i=0,l=0;for(let{key:c,data:h}of e){switch(c){case"M":t.push({key:"M",data:[...h]}),[r,o]=h,[s,a]=h;break;case"C":t.push({key:"C",data:[...h]}),r=h[4],o=h[5],i=h[2],l=h[3];break;case"L":t.push({key:"L",data:[...h]}),[r,o]=h;break;case"H":r=h[0],t.push({key:"L",data:[r,o]});break;case"V":o=h[0],t.push({key:"L",data:[r,o]});break;case"S":{let u=0,d=0;n==="C"||n==="S"?(u=r+(r-i),d=o+(o-l)):(u=r,d=o),t.push({key:"C",data:[u,d,...h]}),i=h[0],l=h[1],r=h[2],o=h[3];break}case"T":{let[u,d]=h,p=0,m=0;n==="Q"||n==="T"?(p=r+(r-i),m=o+(o-l)):(p=r,m=o);let g=r+2*(p-r)/3,f=o+2*(m-o)/3,b=u+2*(p-u)/3,y=d+2*(m-d)/3;t.push({key:"C",data:[g,f,b,y,u,d]}),i=p,l=m,r=u,o=d;break}case"Q":{let[u,d,p,m]=h,g=r+2*(u-r)/3,f=o+2*(d-o)/3,b=p+2*(u-p)/3,y=m+2*(d-m)/3;t.push({key:"C",data:[g,f,b,y,p,m]}),i=u,l=d,r=p,o=m;break}case"A":{let u=Math.abs(h[0]),d=Math.abs(h[1]),p=h[2],m=h[3],g=h[4],f=h[5],b=h[6];u===0||d===0?(t.push({key:"C",data:[r,o,f,b,f,b]}),r=f,o=b):(r!==f||o!==b)&&(Fn(r,o,f,b,u,d,p,m,g).forEach(function(y){t.push({key:"C",data:y})}),r=f,o=b);break}case"Z":t.push({key:"Z",data:[]}),r=s,o=a}n=c}return t}function Jt(e,t,n){return[e*Math.cos(n)-t*Math.sin(n),e*Math.sin(n)+t*Math.cos(n)]}function Fn(e,t,n,r,o,s,a,i,l,c){let h=(u=a,Math.PI*u/180);var u;let d=[],p=0,m=0,g=0,f=0;if(c)[p,m,g,f]=c;else{[e,t]=Jt(e,t,-h),[n,r]=Jt(n,r,-h);let W=(e-n)/2,X=(t-r)/2,V=W*W/(o*o)+X*X/(s*s);V>1&&(V=Math.sqrt(V),o*=V,s*=V);let pt=o*o,tt=s*s,J=pt*tt-pt*X*X-tt*W*W,Qt=pt*X*X+tt*W*W,Ot=(i===l?-1:1)*Math.sqrt(Math.abs(J/Qt));g=Ot*o*X/s+(e+n)/2,f=Ot*-s*W/o+(t+r)/2,p=Math.asin(parseFloat(((t-f)/s).toFixed(9))),m=Math.asin(parseFloat(((r-f)/s).toFixed(9))),e<g&&(p=Math.PI-p),n<g&&(m=Math.PI-m),p<0&&(p=2*Math.PI+p),m<0&&(m=2*Math.PI+m),l&&p>m&&(p-=2*Math.PI),!l&&m>p&&(m-=2*Math.PI)}let b=m-p;if(Math.abs(b)>120*Math.PI/180){let W=m,X=n,V=r;m=l&&m>p?p+120*Math.PI/180*1:p+120*Math.PI/180*-1,d=Fn(n=g+o*Math.cos(m),r=f+s*Math.sin(m),X,V,o,s,a,0,l,[m,W,g,f])}b=m-p;let y=Math.cos(p),w=Math.sin(p),k=Math.cos(m),v=Math.sin(m),M=Math.tan(b/4),S=4/3*o*M,R=4/3*s*M,C=[e,t],L=[e+S*w,t-R*y],D=[n+S*v,r-R*k],I=[n,r];if(L[0]=2*C[0]-L[0],L[1]=2*C[1]-L[1],c)return[L,D,I].concat(d);{d=[L,D,I].concat(d);let W=[];for(let X=0;X<d.length;X+=3){let V=Jt(d[X][0],d[X][1],h),pt=Jt(d[X+1][0],d[X+1][1],h),tt=Jt(d[X+2][0],d[X+2][1],h);W.push([V[0],V[1],pt[0],pt[1],tt[0],tt[1]])}return W}}var ho={randOffset:function(e,t){return O(e,t)},randOffsetWithRange:function(e,t,n){return ge(e,t,n)},ellipse:function(e,t,n,r,o){let s=qn(n,r,o);return Ve(e,t,o,s).opset},doubleLineOps:function(e,t,n,r,o){return vt(e,t,n,r,o,!0)}};function _n(e,t,n,r,o){return{type:"path",ops:vt(e,t,n,r,o)}}function fe(e,t,n){let r=(e||[]).length;if(r>2){let o=[];for(let s=0;s<r-1;s++)o.push(...vt(e[s][0],e[s][1],e[s+1][0],e[s+1][1],n));return t&&o.push(...vt(e[r-1][0],e[r-1][1],e[0][0],e[0][1],n)),{type:"path",ops:o}}return r===2?_n(e[0][0],e[0][1],e[1][0],e[1][1],n):{type:"path",ops:[]}}function uo(e,t,n,r,o){return function(s,a){return fe(s,!0,a)}([[e,t],[e+n,t],[e+n,t+r],[e,t+r]],o)}function Cn(e,t){if(e.length){let n=typeof e[0][0]=="number"?[e]:e,r=de(n[0],1*(1+.2*t.roughness),t),o=t.disableMultiStroke?[]:de(n[0],1.5*(1+.22*t.roughness),Bn(t));for(let s=1;s<n.length;s++){let a=n[s];if(a.length){let i=de(a,1*(1+.2*t.roughness),t),l=t.disableMultiStroke?[]:de(a,1.5*(1+.22*t.roughness),Bn(t));for(let c of i)c.op!=="move"&&r.push(c);for(let c of l)c.op!=="move"&&o.push(c)}}return{type:"path",ops:r.concat(o)}}return{type:"path",ops:[]}}function qn(e,t,n){let r=Math.sqrt(2*Math.PI*Math.sqrt((Math.pow(e/2,2)+Math.pow(t/2,2))/2)),o=Math.ceil(Math.max(n.curveStepCount,n.curveStepCount/Math.sqrt(200)*r)),s=2*Math.PI/o,a=Math.abs(e/2),i=Math.abs(t/2),l=1-n.curveFitting;return a+=O(a*l,n),i+=O(i*l,n),{increment:s,rx:a,ry:i}}function Ve(e,t,n,r){let[o,s]=Rn(r.increment,e,t,r.rx,r.ry,1,r.increment*ge(.1,ge(.4,1,n),n),n),a=be(o,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[i]=Rn(r.increment,e,t,r.rx,r.ry,1.5,0,n),l=be(i,null,n);a=a.concat(l)}return{estimatedPoints:s,opset:{type:"path",ops:a}}}function Tn(e,t,n,r,o,s,a,i,l){let c=e,h=t,u=Math.abs(n/2),d=Math.abs(r/2);u+=O(.01*u,l),d+=O(.01*d,l);let p=o,m=s;for(;p<0;)p+=2*Math.PI,m+=2*Math.PI;m-p>2*Math.PI&&(p=0,m=2*Math.PI);let g=2*Math.PI/l.curveStepCount,f=Math.min(g/2,(m-p)/2),b=jn(f,c,h,u,d,p,m,1,l);if(!l.disableMultiStroke){let y=jn(f,c,h,u,d,p,m,1.5,l);b.push(...y)}return a&&(i?b.push(...vt(c,h,c+u*Math.cos(p),h+d*Math.sin(p),l),...vt(c,h,c+u*Math.cos(m),h+d*Math.sin(m),l)):b.push({op:"lineTo",data:[c,h]},{op:"lineTo",data:[c+u*Math.cos(p),h+d*Math.sin(p)]})),{type:"path",ops:b}}function zn(e,t){let n=Dn(In(Ze(e))),r=[],o=[0,0],s=[0,0];for(let{key:a,data:i}of n)switch(a){case"M":s=[i[0],i[1]],o=[i[0],i[1]];break;case"L":r.push(...vt(s[0],s[1],i[0],i[1],t)),s=[i[0],i[1]];break;case"C":{let[l,c,h,u,d,p]=i;r.push(...po(l,c,h,u,d,p,s,t)),s=[d,p];break}case"Z":r.push(...vt(s[0],s[1],o[0],o[1],t)),s=[o[0],o[1]]}return{type:"path",ops:r}}function Ie(e,t){let n=[];for(let r of e)if(r.length){let o=t.maxRandomnessOffset||0,s=r.length;if(s>2){n.push({op:"move",data:[r[0][0]+O(o,t),r[0][1]+O(o,t)]});for(let a=1;a<s;a++)n.push({op:"lineTo",data:[r[a][0]+O(o,t),r[a][1]+O(o,t)]})}}return{type:"fillPath",ops:n}}function It(e,t){return function(n,r){let o=n.fillStyle||"hachure";if(!it[o])switch(o){case"zigzag":it[o]||(it[o]=new Fe(r));break;case"cross-hatch":it[o]||(it[o]=new _e(r));break;case"dots":it[o]||(it[o]=new qe(r));break;case"dashed":it[o]||(it[o]=new Ge(r));break;case"zigzag-line":it[o]||(it[o]=new Xe(r));break;default:o="hachure",it[o]||(it[o]=new ee(r))}return it[o]}(t,ho).fillPolygons(e,t)}function Bn(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function Gn(e){return e.randomizer||(e.randomizer=new Ye(e.seed||0)),e.randomizer.next()}function ge(e,t,n,r=1){return n.roughness*r*(Gn(n)*(t-e)+e)}function O(e,t,n=1){return ge(-e,e,t,n)}function vt(e,t,n,r,o,s=!1){let a=s?o.disableMultiStrokeFill:o.disableMultiStroke,i=We(e,t,n,r,o,!0,!1);if(a)return i;let l=We(e,t,n,r,o,!0,!0);return i.concat(l)}function We(e,t,n,r,o,s,a){let i=Math.pow(e-n,2)+Math.pow(t-r,2),l=Math.sqrt(i),c=1;c=l<200?1:l>500?.4:-.0016668*l+1.233334;let h=o.maxRandomnessOffset||0;h*h*100>i&&(h=l/10);let u=h/2,d=.2+.2*Gn(o),p=o.bowing*o.maxRandomnessOffset*(r-t)/200,m=o.bowing*o.maxRandomnessOffset*(e-n)/200;p=O(p,o,c),m=O(m,o,c);let g=[],f=()=>O(u,o,c),b=()=>O(h,o,c),y=o.preserveVertices;return s&&(a?g.push({op:"move",data:[e+(y?0:f()),t+(y?0:f())]}):g.push({op:"move",data:[e+(y?0:O(h,o,c)),t+(y?0:O(h,o,c))]})),a?g.push({op:"bcurveTo",data:[p+e+(n-e)*d+f(),m+t+(r-t)*d+f(),p+e+2*(n-e)*d+f(),m+t+2*(r-t)*d+f(),n+(y?0:f()),r+(y?0:f())]}):g.push({op:"bcurveTo",data:[p+e+(n-e)*d+b(),m+t+(r-t)*d+b(),p+e+2*(n-e)*d+b(),m+t+2*(r-t)*d+b(),n+(y?0:b()),r+(y?0:b())]}),g}function de(e,t,n){if(!e.length)return[];let r=[];r.push([e[0][0]+O(t,n),e[0][1]+O(t,n)]),r.push([e[0][0]+O(t,n),e[0][1]+O(t,n)]);for(let o=1;o<e.length;o++)r.push([e[o][0]+O(t,n),e[o][1]+O(t,n)]),o===e.length-1&&r.push([e[o][0]+O(t,n),e[o][1]+O(t,n)]);return be(r,null,n)}function be(e,t,n){let r=e.length,o=[];if(r>3){let s=[],a=1-n.curveTightness;o.push({op:"move",data:[e[1][0],e[1][1]]});for(let i=1;i+2<r;i++){let l=e[i];s[0]=[l[0],l[1]],s[1]=[l[0]+(a*e[i+1][0]-a*e[i-1][0])/6,l[1]+(a*e[i+1][1]-a*e[i-1][1])/6],s[2]=[e[i+1][0]+(a*e[i][0]-a*e[i+2][0])/6,e[i+1][1]+(a*e[i][1]-a*e[i+2][1])/6],s[3]=[e[i+1][0],e[i+1][1]],o.push({op:"bcurveTo",data:[s[1][0],s[1][1],s[2][0],s[2][1],s[3][0],s[3][1]]})}if(t&&t.length===2){let i=n.maxRandomnessOffset;o.push({op:"lineTo",data:[t[0]+O(i,n),t[1]+O(i,n)]})}}else r===3?(o.push({op:"move",data:[e[1][0],e[1][1]]}),o.push({op:"bcurveTo",data:[e[1][0],e[1][1],e[2][0],e[2][1],e[2][0],e[2][1]]})):r===2&&o.push(...We(e[0][0],e[0][1],e[1][0],e[1][1],n,!0,!0));return o}function Rn(e,t,n,r,o,s,a,i){let l=[],c=[];if(i.roughness===0){e/=4,c.push([t+r*Math.cos(-e),n+o*Math.sin(-e)]);for(let h=0;h<=2*Math.PI;h+=e){let u=[t+r*Math.cos(h),n+o*Math.sin(h)];l.push(u),c.push(u)}c.push([t+r*Math.cos(0),n+o*Math.sin(0)]),c.push([t+r*Math.cos(e),n+o*Math.sin(e)])}else{let h=O(.5,i)-Math.PI/2;c.push([O(s,i)+t+.9*r*Math.cos(h-e),O(s,i)+n+.9*o*Math.sin(h-e)]);let u=2*Math.PI+h-.01;for(let d=h;d<u;d+=e){let p=[O(s,i)+t+r*Math.cos(d),O(s,i)+n+o*Math.sin(d)];l.push(p),c.push(p)}c.push([O(s,i)+t+r*Math.cos(h+2*Math.PI+.5*a),O(s,i)+n+o*Math.sin(h+2*Math.PI+.5*a)]),c.push([O(s,i)+t+.98*r*Math.cos(h+a),O(s,i)+n+.98*o*Math.sin(h+a)]),c.push([O(s,i)+t+.9*r*Math.cos(h+.5*a),O(s,i)+n+.9*o*Math.sin(h+.5*a)])}return[c,l]}function jn(e,t,n,r,o,s,a,i,l){let c=s+O(.1,l),h=[];h.push([O(i,l)+t+.9*r*Math.cos(c-e),O(i,l)+n+.9*o*Math.sin(c-e)]);for(let u=c;u<=a;u+=e)h.push([O(i,l)+t+r*Math.cos(u),O(i,l)+n+o*Math.sin(u)]);return h.push([t+r*Math.cos(a),n+o*Math.sin(a)]),h.push([t+r*Math.cos(a),n+o*Math.sin(a)]),be(h,null,l)}function po(e,t,n,r,o,s,a,i){let l=[],c=[i.maxRandomnessOffset||1,(i.maxRandomnessOffset||1)+.3],h=[0,0],u=i.disableMultiStroke?1:2,d=i.preserveVertices;for(let p=0;p<u;p++)p===0?l.push({op:"move",data:[a[0],a[1]]}):l.push({op:"move",data:[a[0]+(d?0:O(c[0],i)),a[1]+(d?0:O(c[0],i))]}),h=d?[o,s]:[o+O(c[p],i),s+O(c[p],i)],l.push({op:"bcurveTo",data:[e+O(c[p],i),t+O(c[p],i),n+O(c[p],i),r+O(c[p],i),h[0],h[1]]});return l}function te(e){return[...e]}function Nn(e,t=0){let n=e.length;if(n<3)throw new Error("A curve must have at least three points.");let r=[];if(n===3)r.push(te(e[0]),te(e[1]),te(e[2]),te(e[2]));else{let o=[];o.push(e[0],e[0]);for(let i=1;i<e.length;i++)o.push(e[i]),i===e.length-1&&o.push(e[i]);let s=[],a=1-t;r.push(te(o[0]));for(let i=1;i+2<o.length;i++){let l=o[i];s[0]=[l[0],l[1]],s[1]=[l[0]+(a*o[i+1][0]-a*o[i-1][0])/6,l[1]+(a*o[i+1][1]-a*o[i-1][1])/6],s[2]=[o[i+1][0]+(a*o[i][0]-a*o[i+2][0])/6,o[i+1][1]+(a*o[i][1]-a*o[i+2][1])/6],s[3]=[o[i+1][0],o[i+1][1]],r.push(s[1],s[2],s[3])}}return r}function me(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function fo(e,t,n){let r=me(t,n);if(r===0)return me(e,t);let o=((e[0]-t[0])*(n[0]-t[0])+(e[1]-t[1])*(n[1]-t[1]))/r;return o=Math.max(0,Math.min(1,o)),me(e,Pt(t,n,o))}function Pt(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function He(e,t,n,r){let o=r||[];if(function(i,l){let c=i[l+0],h=i[l+1],u=i[l+2],d=i[l+3],p=3*h[0]-2*c[0]-d[0];p*=p;let m=3*h[1]-2*c[1]-d[1];m*=m;let g=3*u[0]-2*d[0]-c[0];g*=g;let f=3*u[1]-2*d[1]-c[1];return f*=f,p<g&&(p=g),m<f&&(m=f),p+m}(e,t)<n){let i=e[t+0];o.length?(s=o[o.length-1],a=i,Math.sqrt(me(s,a))>1&&o.push(i)):o.push(i),o.push(e[t+3])}else{let l=e[t+0],c=e[t+1],h=e[t+2],u=e[t+3],d=Pt(l,c,.5),p=Pt(c,h,.5),m=Pt(h,u,.5),g=Pt(d,p,.5),f=Pt(p,m,.5),b=Pt(g,f,.5);He([l,d,g,b],0,n,o),He([b,f,m,u],0,n,o)}var s,a;return o}function mo(e,t){return ye(e,0,e.length,t)}function ye(e,t,n,r,o){let s=o||[],a=e[t],i=e[n-1],l=0,c=1;for(let h=t+1;h<n-1;++h){let u=fo(e[h],a,i);u>l&&(l=u,c=h)}return Math.sqrt(l)>r?(ye(e,t,c+1,r,s),ye(e,c,n,r,s)):(s.length||s.push(a),s.push(i)),s}function De(e,t=.15,n){let r=[],o=(e.length-1)/3;for(let s=0;s<o;s++)He(e,3*s,t,r);return n&&n>0?ye(r,0,r.length,n):r}var ht="none",Dt=class{constructor(t){this.defaultOptions={maxRandomnessOffset:2,roughness:1,bowing:1,stroke:"#000",strokeWidth:1,curveTightness:0,curveFitting:.95,curveStepCount:9,fillStyle:"hachure",fillWeight:-1,hachureAngle:-41,hachureGap:-1,dashOffset:-1,dashGap:-1,zigzagOffset:-1,seed:0,disableMultiStroke:!1,disableMultiStrokeFill:!1,preserveVertices:!1,fillShapeRoughnessGain:.8},this.config=t||{},this.config.options&&(this.defaultOptions=this._o(this.config.options))}static newSeed(){return Math.floor(Math.random()*2**31)}_o(t){return t?Object.assign({},this.defaultOptions,t):this.defaultOptions}_d(t,n,r){return{shape:t,sets:n||[],options:r||this.defaultOptions}}line(t,n,r,o,s){let a=this._o(s);return this._d("line",[_n(t,n,r,o,a)],a)}rectangle(t,n,r,o,s){let a=this._o(s),i=[],l=uo(t,n,r,o,a);if(a.fill){let c=[[t,n],[t+r,n],[t+r,n+o],[t,n+o]];a.fillStyle==="solid"?i.push(Ie([c],a)):i.push(It([c],a))}return a.stroke!==ht&&i.push(l),this._d("rectangle",i,a)}ellipse(t,n,r,o,s){let a=this._o(s),i=[],l=qn(r,o,a),c=Ve(t,n,a,l);if(a.fill)if(a.fillStyle==="solid"){let h=Ve(t,n,a,l).opset;h.type="fillPath",i.push(h)}else i.push(It([c.estimatedPoints],a));return a.stroke!==ht&&i.push(c.opset),this._d("ellipse",i,a)}circle(t,n,r,o){let s=this.ellipse(t,n,r,r,o);return s.shape="circle",s}linearPath(t,n){let r=this._o(n);return this._d("linearPath",[fe(t,!1,r)],r)}arc(t,n,r,o,s,a,i=!1,l){let c=this._o(l),h=[],u=Tn(t,n,r,o,s,a,i,!0,c);if(i&&c.fill)if(c.fillStyle==="solid"){let d=Object.assign({},c);d.disableMultiStroke=!0;let p=Tn(t,n,r,o,s,a,!0,!1,d);p.type="fillPath",h.push(p)}else h.push(function(d,p,m,g,f,b,y){let w=d,k=p,v=Math.abs(m/2),M=Math.abs(g/2);v+=O(.01*v,y),M+=O(.01*M,y);let S=f,R=b;for(;S<0;)S+=2*Math.PI,R+=2*Math.PI;R-S>2*Math.PI&&(S=0,R=2*Math.PI);let C=(R-S)/y.curveStepCount,L=[];for(let D=S;D<=R;D+=C)L.push([w+v*Math.cos(D),k+M*Math.sin(D)]);return L.push([w+v*Math.cos(R),k+M*Math.sin(R)]),L.push([w,k]),It([L],y)}(t,n,r,o,s,a,c));return c.stroke!==ht&&h.push(u),this._d("arc",h,c)}curve(t,n){let r=this._o(n),o=[],s=Cn(t,r);if(r.fill&&r.fill!==ht)if(r.fillStyle==="solid"){let a=Cn(t,Object.assign(Object.assign({},r),{disableMultiStroke:!0,roughness:r.roughness?r.roughness+r.fillShapeRoughnessGain:0}));o.push({type:"fillPath",ops:this._mergedShape(a.ops)})}else{let a=[],i=t;if(i.length){let l=typeof i[0][0]=="number"?[i]:i;for(let c of l)c.length<3?a.push(...c):c.length===3?a.push(...De(Nn([c[0],c[0],c[1],c[2]]),10,(1+r.roughness)/2)):a.push(...De(Nn(c),10,(1+r.roughness)/2))}a.length&&o.push(It([a],r))}return r.stroke!==ht&&o.push(s),this._d("curve",o,r)}polygon(t,n){let r=this._o(n),o=[],s=fe(t,!0,r);return r.fill&&(r.fillStyle==="solid"?o.push(Ie([t],r)):o.push(It([t],r))),r.stroke!==ht&&o.push(s),this._d("polygon",o,r)}path(t,n){let r=this._o(n),o=[];if(!t)return this._d("path",o,r);t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");let s=r.fill&&r.fill!=="transparent"&&r.fill!==ht,a=r.stroke!==ht,i=!!(r.simplification&&r.simplification<1),l=function(h,u,d){let p=Dn(In(Ze(h))),m=[],g=[],f=[0,0],b=[],y=()=>{b.length>=4&&g.push(...De(b,u)),b=[]},w=()=>{y(),g.length&&(m.push(g),g=[])};for(let{key:v,data:M}of p)switch(v){case"M":w(),f=[M[0],M[1]],g.push(f);break;case"L":y(),g.push([M[0],M[1]]);break;case"C":if(!b.length){let S=g.length?g[g.length-1]:f;b.push([S[0],S[1]])}b.push([M[0],M[1]]),b.push([M[2],M[3]]),b.push([M[4],M[5]]);break;case"Z":y(),g.push([f[0],f[1]])}if(w(),!d)return m;let k=[];for(let v of m){let M=mo(v,d);M.length&&k.push(M)}return k}(t,1,i?4-4*(r.simplification||1):(1+r.roughness)/2),c=zn(t,r);if(s)if(r.fillStyle==="solid")if(l.length===1){let h=zn(t,Object.assign(Object.assign({},r),{disableMultiStroke:!0,roughness:r.roughness?r.roughness+r.fillShapeRoughnessGain:0}));o.push({type:"fillPath",ops:this._mergedShape(h.ops)})}else o.push(Ie(l,r));else o.push(It(l,r));return a&&(i?l.forEach(h=>{o.push(fe(h,!1,r))}):o.push(c)),this._d("path",o,r)}opsToPath(t,n){let r="";for(let o of t.ops){let s=typeof n=="number"&&n>=0?o.data.map(a=>+a.toFixed(n)):o.data;switch(o.op){case"move":r+=`M${s[0]} ${s[1]} `;break;case"bcurveTo":r+=`C${s[0]} ${s[1]}, ${s[2]} ${s[3]}, ${s[4]} ${s[5]} `;break;case"lineTo":r+=`L${s[0]} ${s[1]} `}}return r.trim()}toPaths(t){let n=t.sets||[],r=t.options||this.defaultOptions,o=[];for(let s of n){let a=null;switch(s.type){case"path":a={d:this.opsToPath(s),stroke:r.stroke,strokeWidth:r.strokeWidth,fill:ht};break;case"fillPath":a={d:this.opsToPath(s),stroke:ht,strokeWidth:0,fill:r.fill||ht};break;case"fillSketch":a=this.fillSketch(s,r)}a&&o.push(a)}return o}fillSketch(t,n){let r=n.fillWeight;return r<0&&(r=n.strokeWidth/2),{d:this.opsToPath(t),stroke:n.fill||ht,strokeWidth:r,fill:ht}}_mergedShape(t){return t.filter((n,r)=>r===0||n.op!=="move")}},Ue=class{constructor(t,n){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new Dt(n)}draw(t){let n=t.sets||[],r=t.options||this.getDefaultOptions(),o=this.ctx,s=t.options.fixedDecimalPlaceDigits;for(let a of n)switch(a.type){case"path":o.save(),o.strokeStyle=r.stroke==="none"?"transparent":r.stroke,o.lineWidth=r.strokeWidth,r.strokeLineDash&&o.setLineDash(r.strokeLineDash),r.strokeLineDashOffset&&(o.lineDashOffset=r.strokeLineDashOffset),this._drawToContext(o,a,s),o.restore();break;case"fillPath":{o.save(),o.fillStyle=r.fill||"";let i=t.shape==="curve"||t.shape==="polygon"||t.shape==="path"?"evenodd":"nonzero";this._drawToContext(o,a,s,i),o.restore();break}case"fillSketch":this.fillSketch(o,a,r)}}fillSketch(t,n,r){let o=r.fillWeight;o<0&&(o=r.strokeWidth/2),t.save(),r.fillLineDash&&t.setLineDash(r.fillLineDash),r.fillLineDashOffset&&(t.lineDashOffset=r.fillLineDashOffset),t.strokeStyle=r.fill||"",t.lineWidth=o,this._drawToContext(t,n,r.fixedDecimalPlaceDigits),t.restore()}_drawToContext(t,n,r,o="nonzero"){t.beginPath();for(let s of n.ops){let a=typeof r=="number"&&r>=0?s.data.map(i=>+i.toFixed(r)):s.data;switch(s.op){case"move":t.moveTo(a[0],a[1]);break;case"bcurveTo":t.bezierCurveTo(a[0],a[1],a[2],a[3],a[4],a[5]);break;case"lineTo":t.lineTo(a[0],a[1])}}n.type==="fillPath"?t.fill(o):t.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(t,n,r,o,s){let a=this.gen.line(t,n,r,o,s);return this.draw(a),a}rectangle(t,n,r,o,s){let a=this.gen.rectangle(t,n,r,o,s);return this.draw(a),a}ellipse(t,n,r,o,s){let a=this.gen.ellipse(t,n,r,o,s);return this.draw(a),a}circle(t,n,r,o){let s=this.gen.circle(t,n,r,o);return this.draw(s),s}linearPath(t,n){let r=this.gen.linearPath(t,n);return this.draw(r),r}polygon(t,n){let r=this.gen.polygon(t,n);return this.draw(r),r}arc(t,n,r,o,s,a,i=!1,l){let c=this.gen.arc(t,n,r,o,s,a,i,l);return this.draw(c),c}curve(t,n){let r=this.gen.curve(t,n);return this.draw(r),r}path(t,n){let r=this.gen.path(t,n);return this.draw(r),r}},pe="http://www.w3.org/2000/svg",Ke=class{constructor(t,n){this.svg=t,this.gen=new Dt(n)}draw(t){let n=t.sets||[],r=t.options||this.getDefaultOptions(),o=this.svg.ownerDocument||window.document,s=o.createElementNS(pe,"g"),a=t.options.fixedDecimalPlaceDigits;for(let i of n){let l=null;switch(i.type){case"path":l=o.createElementNS(pe,"path"),l.setAttribute("d",this.opsToPath(i,a)),l.setAttribute("stroke",r.stroke),l.setAttribute("stroke-width",r.strokeWidth+""),l.setAttribute("fill","none"),r.strokeLineDash&&l.setAttribute("stroke-dasharray",r.strokeLineDash.join(" ").trim()),r.strokeLineDashOffset&&l.setAttribute("stroke-dashoffset",`${r.strokeLineDashOffset}`);break;case"fillPath":l=o.createElementNS(pe,"path"),l.setAttribute("d",this.opsToPath(i,a)),l.setAttribute("stroke","none"),l.setAttribute("stroke-width","0"),l.setAttribute("fill",r.fill||""),t.shape!=="curve"&&t.shape!=="polygon"||l.setAttribute("fill-rule","evenodd");break;case"fillSketch":l=this.fillSketch(o,i,r)}l&&s.appendChild(l)}return s}fillSketch(t,n,r){let o=r.fillWeight;o<0&&(o=r.strokeWidth/2);let s=t.createElementNS(pe,"path");return s.setAttribute("d",this.opsToPath(n,r.fixedDecimalPlaceDigits)),s.setAttribute("stroke",r.fill||""),s.setAttribute("stroke-width",o+""),s.setAttribute("fill","none"),r.fillLineDash&&s.setAttribute("stroke-dasharray",r.fillLineDash.join(" ").trim()),r.fillLineDashOffset&&s.setAttribute("stroke-dashoffset",`${r.fillLineDashOffset}`),s}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}opsToPath(t,n){return this.gen.opsToPath(t,n)}line(t,n,r,o,s){let a=this.gen.line(t,n,r,o,s);return this.draw(a)}rectangle(t,n,r,o,s){let a=this.gen.rectangle(t,n,r,o,s);return this.draw(a)}ellipse(t,n,r,o,s){let a=this.gen.ellipse(t,n,r,o,s);return this.draw(a)}circle(t,n,r,o){let s=this.gen.circle(t,n,r,o);return this.draw(s)}linearPath(t,n){let r=this.gen.linearPath(t,n);return this.draw(r)}polygon(t,n){let r=this.gen.polygon(t,n);return this.draw(r)}arc(t,n,r,o,s,a,i=!1,l){let c=this.gen.arc(t,n,r,o,s,a,i,l);return this.draw(c)}curve(t,n){let r=this.gen.curve(t,n);return this.draw(r)}path(t,n){let r=this.gen.path(t,n);return this.draw(r)}},Xn={canvas:(e,t)=>new Ue(e,t),svg:(e,t)=>new Ke(e,t),generator:e=>new Dt(e),newSeed:()=>Dt.newSeed()};var Yn={sqrt:Math.sqrt,abs:Math.abs,sin:Math.sin,cos:Math.cos,tan:Math.tan,min:Math.min,max:Math.max,round:Math.round,floor:Math.floor,ceil:Math.ceil,pow:Math.pow,log:Math.log,exp:Math.exp},Vn={pi:Math.PI,e:Math.E},Je=["and","or","not"],mt=class extends Error{};function go(e){let t=[],n=/\s*(\d+(?:\.\d+)?|\.\d+|[A-Za-z_][A-Za-z_0-9]*|>=|<=|==|!=|[-+*/^(),<>])/y,r=0;for(;r<e.length&&!/^\s*$/.test(e.slice(r));){n.lastIndex=r;let o=n.exec(e);if(!o)throw new mt(`Unexpected character in "${e}" (position ${r})`);let s=o[1];/^[\d.]/.test(s)?t.push({kind:"num",value:parseFloat(s)}):/^[A-Za-z_]/.test(s)?t.push({kind:"id",value:s}):t.push({kind:"op",value:s}),r=n.lastIndex}return t}var Qe=class{constructor(t,n,r){q(this,"i",0);q(this,"tokens");q(this,"scope");q(this,"src");this.tokens=t,this.scope=n,this.src=r}parse(){let t=this.or();if(this.i<this.tokens.length)throw new mt(`Leftover input at the end of "${this.src}"`);return t}peekOp(...t){let n=this.tokens[this.i];return n&&n.kind==="op"&&t.includes(n.value)?n.value:null}expect(t){if(!this.peekOp(t))throw new mt(`Expected "${t}" in "${this.src}"`);this.i++}word(t){let n=this.tokens[this.i];return!!n&&n.kind==="id"&&n.value===t}or(){let t=this.and();for(;this.word("or");){this.i++;let n=this.and();t=t!==0||n!==0?1:0}return t}and(){let t=this.not();for(;this.word("and");){this.i++;let n=this.not();t=t!==0&&n!==0?1:0}return t}not(){return this.word("not")?(this.i++,this.not()===0?1:0):this.compare()}compare(){let t=this.sum(),n=this.peekOp(">","<",">=","<=","==","!=");if(!n)return t;this.i++;let r=this.sum();return(n===">"?t>r:n==="<"?t<r:n===">="?t>=r:n==="<="?t<=r:n==="=="?t===r:t!==r)?1:0}sum(){let t=this.term(),n;for(;n=this.peekOp("+","-");){this.i++;let r=this.term();t=n==="+"?t+r:t-r}return t}term(){let t=this.unary(),n;for(;n=this.peekOp("*","/");){this.i++;let r=this.unary();t=n==="*"?t*r:t/r}return t}unary(){return this.peekOp("-")?(this.i++,-this.unary()):this.peekOp("+")?(this.i++,this.unary()):this.power()}power(){let t=this.primary();return this.peekOp("^")?(this.i++,Math.pow(t,this.unary())):t}primary(){let t=this.tokens[this.i];if(!t)throw new mt(`Incomplete expression: "${this.src}"`);if(t.kind==="num")return this.i++,t.value;if(t.kind==="id"){if(this.i++,this.peekOp("(")){if(!Object.hasOwn(Yn,t.value))throw new mt(`Unknown function "${t.value}"`);let n=Yn[t.value];this.i++;let r=[];if(!this.peekOp(")"))for(r.push(this.or());this.peekOp(",");)this.i++,r.push(this.or());return this.expect(")"),n(...r)}if(Je.includes(t.value))throw new mt(`"${t.value}" needs parentheses here, in "${this.src}"`);if(Object.hasOwn(this.scope,t.value))return this.scope[t.value];if(Object.hasOwn(Vn,t.value))return Vn[t.value];throw new mt(`Unknown variable "${t.value}" in "${this.src}"`)}if(t.value==="("){this.i++;let n=this.or();return this.expect(")"),n}throw new mt(`Unexpected symbol "${t.value}" in "${this.src}"`)}};function bo(e,t){return new Qe(go(e),t,e).parse()}function B(e,t){let n=typeof e=="number"?e:bo(e,t);if(!Number.isFinite(n))throw new mt(`Non-finite result in "${e}".`);return n}var Wn="pt-BR";function Ft(e,t,n=Wn){if(!isFinite(e))return"?";let r=t===void 0?{maximumFractionDigits:2,minimumFractionDigits:0}:{maximumFractionDigits:t,minimumFractionDigits:t};return new Intl.NumberFormat(n,r).format(e)}function nt(e,t,n=Wn){return e.replace(/\{([^{}:]+)(?::(\d))?\}/g,(r,o,s)=>Ft(B(o,t),s===void 0?void 0:Number(s),n))}var re=["person","person-pointing","person-sitting","house","car","bus","coin","phone","document","server","bank","cloud","queue","desk","computer","clock","lock","money-arrow","tree","school","hospital","factory","truck","cart","safe","bulb","gear","database","robot","ship","container","warehouse","box","pallet","shop","shelf","field","cup","function","api-gateway","cache","cluster","board","book","pencil"],_t={pessoa:"person","pessoa-apontando":"person-pointing","pessoa-sentada":"person-sitting",casa:"house",carro:"car",onibus:"bus",moeda:"coin",celular:"phone",documento:"document",servidor:"server",banco:"bank",nuvem:"cloud",fila:"queue",mesa:"desk",computador:"computer",relogio:"clock",cadeado:"lock","seta-dinheiro":"money-arrow"},qt=e=>re.includes(e)?e:typeof e=="string"&&Object.hasOwn(_t,e)?_t[e]:void 0,tn=80,Un=e=>qt(e)!==void 0,x={skin:"#E8C6A5",shirt:"#A9BCC3",wood:"#D8C29C",gold:"#F2C94C",paper:"#FFFFFF",screen:"#DCE8F0",device:"#5B6B7C",roof:"#D9785F",wall:"#F3E3C3",car:"#7FA7C9",bus:"#E9C46A",green:"#7DBE8A",dark:"#4A4A4A",metal:"#C9D3DD",board:"#2F4F3F",chalk:"#F2EFE6"},E=(e,t,n,r,o,s)=>({kind:"polygon",points:[[e,t],[e+n,t],[e+n,t+r],[e,t+r]],fill:o,main:s}),P=(...e)=>({kind:"polyline",points:e});function Kn(e){return[{kind:"polygon",points:[[-.15,-.72],[.15,-.72],[.19,-.38],[-.19,-.38]],fill:x.shirt,main:!0},{kind:"circle",c:[0,-.87],r:.11,fill:x.skin},...e,P([-.08,-.38],[-.1,0]),P([.08,-.38],[.1,0])]}var Hn=Kn([P([-.15,-.7],[-.25,-.42]),P([.15,-.7],[.25,-.42])]);function yo(e,t,n){let r=([o,s])=>[n+o*t,s*t];return e.map(o=>o.kind==="circle"?{...o,c:r(o.c),r:o.r*t}:{...o,points:o.points.map(r)})}function wo(){let e=[[-.28,-.3,.18],[-.06,-.45,.25],[.2,-.4,.21],[.37,-.27,.13]],t=[];for(let n=0;n<=24;n++){let r=-.46+.96*n/24,o=e.filter(([s,,a])=>Math.abs(r-s)<=a).map(([s,a,i])=>a-Math.sqrt(Math.max(0,i*i-(r-s)**2)));o.length&&t.push([r,Math.min(...o)])}return[...t,[.42,-.12],[-.4,-.12]]}var xo={person:Hn,"person-pointing":Kn([P([-.15,-.7],[-.25,-.42]),P([.15,-.69],[.47,-.73])]),"person-sitting":[P([-.3,-.8],[-.27,-.4]),P([-.32,-.4],[.2,-.4]),P([-.27,-.4],[-.27,0]),P([.16,-.4],[.16,0]),{kind:"polygon",points:[[-.22,-.77],[.04,-.77],[.06,-.44],[-.22,-.44]],fill:x.shirt,main:!0},{kind:"circle",c:[-.08,-.9],r:.1,fill:x.skin},P([-.1,-.44],[.3,-.44],[.32,0]),P([0,-.74],[.18,-.55],[.3,-.58])],house:[E(-.4,-.6,.8,.6,x.wall,!0),{kind:"polygon",points:[[-.5,-.58],[0,-1],[.5,-.58]],fill:x.roof},E(-.08,-.32,.16,.32,x.wood),E(.16,-.46,.16,.14,x.screen)],car:[{kind:"polygon",fill:x.car,main:!0,points:[[-.5,-.14],[-.5,-.32],[-.3,-.36],[-.18,-.56],[.2,-.56],[.32,-.36],[.5,-.32],[.5,-.14]]},{kind:"polygon",points:[[-.14,-.51],[.17,-.51],[.25,-.37],[-.22,-.37]],fill:x.screen},{kind:"circle",c:[-.28,-.12],r:.1,fill:x.dark},{kind:"circle",c:[.28,-.12],r:.1,fill:x.dark}],bus:[E(-.5,-.66,1,.52,x.bus,!0),...[-.42,-.21,0,.21].map(e=>E(e,-.6,.15,.16,x.screen)),P([-.5,-.3],[.5,-.3]),{kind:"circle",c:[-.3,-.12],r:.1,fill:x.dark},{kind:"circle",c:[.3,-.12],r:.1,fill:x.dark}],coin:[{kind:"circle",c:[0,-.42],r:.4,fill:x.gold,main:!0},{kind:"circle",c:[0,-.42],r:.3},{kind:"curve",points:[[.1,-.56],[-.08,-.57],[-.09,-.46],[.08,-.39],[.08,-.29],[-.11,-.28]]},P([0,-.64],[0,-.2])],phone:[E(-.26,-1,.52,1,x.device,!0),E(-.2,-.92,.4,.76,x.screen),{kind:"circle",c:[0,-.08],r:.035,fill:x.paper}],document:[{kind:"polygon",points:[[-.36,-1],[.16,-1],[.36,-.8],[.36,0],[-.36,0]],fill:x.paper,main:!0},P([.16,-1],[.16,-.8],[.36,-.8]),...[-.66,-.5,-.34,-.18].map(e=>P([-.22,e],[.22,e]))],server:[-1,-.66,-.32].flatMap(e=>[E(-.36,e,.72,.3,x.metal,!0),P([-.26,e+.15],[.06,e+.15]),{kind:"circle",c:[.22,e+.15],r:.035,fill:x.green}]),bank:[{kind:"polygon",points:[[-.5,-.74],[0,-1],[.5,-.74]],fill:x.wall,main:!0},E(-.45,-.74,.9,.08,x.wall),...[-.33,-.11,.11,.33].map(e=>E(e-.04,-.66,.08,.56,x.paper)),E(-.5,-.1,1,.1,x.wall)],cloud:[{kind:"polygon",points:wo(),fill:x.paper,main:!0}],queue:[-.32,0,.32].flatMap(e=>yo(Hn,.7,e)),desk:[E(-.5,-.5,1,.07,x.wood,!0),P([-.42,-.43],[-.42,0]),P([.42,-.43],[.42,0])],computer:[E(-.45,-1,.9,.6,x.device,!0),E(-.39,-.94,.78,.48,x.screen),{kind:"polygon",points:[[-.06,-.4],[.06,-.4],[.1,-.1],[-.1,-.1]],fill:x.device},E(-.25,-.1,.5,.08,x.device)],clock:[{kind:"circle",c:[0,-.48],r:.45,fill:x.paper,main:!0},...[[0,-.9,0,-.82],[.42,-.48,.34,-.48],[0,-.06,0,-.14],[-.42,-.48,-.34,-.48]].map(([e,t,n,r])=>P([e,t],[n,r])),P([0,-.48],[0,-.78]),P([0,-.48],[.2,-.48])],lock:[{kind:"curve",points:[[-.22,-.52],[-.22,-.76],[0,-.96],[.22,-.76],[.22,-.52]]},E(-.36,-.54,.72,.54,x.bus,!0),{kind:"circle",c:[0,-.32],r:.06,fill:x.dark},P([0,-.28],[0,-.14])],"money-arrow":[{kind:"polygon",fill:x.green,main:!0,points:[[-.5,-.4],[.12,-.4],[.12,-.56],[.5,-.3],[.12,-.04],[.12,-.2],[-.5,-.2]]},{kind:"circle",c:[-.2,-.3],r:.16,fill:x.gold},P([-.2,-.4],[-.2,-.2])],tree:[E(-.07,-.36,.14,.36,x.wood),{kind:"circle",c:[0,-.64],r:.3,fill:x.green,main:!0}],school:[E(-.45,-.6,.9,.6,x.wall,!0),{kind:"polygon",points:[[-.5,-.6],[0,-.82],[.5,-.6]],fill:x.roof},E(-.08,-.28,.16,.28,x.wood),E(-.36,-.48,.16,.12,x.screen),E(.2,-.48,.16,.12,x.screen),P([0,-.82],[0,-1]),{kind:"polygon",points:[[0,-1],[.17,-.95],[0,-.9]],fill:x.roof}],hospital:[E(-.4,-.8,.8,.8,x.paper,!0),E(-.045,-.7,.09,.26,"#C8442C"),E(-.13,-.615,.26,.09,"#C8442C"),E(-.1,-.24,.2,.24,x.metal)],factory:[{kind:"polygon",points:[[-.5,0],[-.5,-.5],[-.25,-.65],[-.25,-.5],[0,-.65],[0,-.5],[.25,-.65],[.25,-.5],[.5,-.5],[.5,0]],fill:x.wall,main:!0},E(.3,-.95,.12,.3,x.dark),E(-.38,-.32,.16,.12,x.screen),E(-.08,-.32,.16,.12,x.screen),E(.22,-.32,.16,.12,x.screen)],truck:[E(-.5,-.62,.62,.46,x.metal,!0),{kind:"polygon",points:[[.12,-.16],[.12,-.5],[.34,-.5],[.48,-.32],[.48,-.16]],fill:x.bus},{kind:"polygon",points:[[.18,-.46],[.32,-.46],[.42,-.33],[.18,-.33]],fill:x.screen},{kind:"circle",c:[-.3,-.1],r:.1,fill:x.dark},{kind:"circle",c:[.3,-.1],r:.1,fill:x.dark}],cart:[P([-.48,-.78],[-.4,-.62]),{kind:"polygon",points:[[-.4,-.62],[.42,-.62],[.32,-.26],[-.3,-.26]],fill:x.metal,main:!0},P([-.3,-.26],[-.3,-.14],[.32,-.14]),{kind:"circle",c:[-.22,-.07],r:.06,fill:x.dark},{kind:"circle",c:[.24,-.07],r:.06,fill:x.dark}],safe:[E(-.4,-.82,.8,.82,x.device,!0),E(-.3,-.72,.6,.62,x.metal),{kind:"circle",c:[0,-.41],r:.13,fill:x.paper},P([0,-.41],[.08,-.47])],bulb:[{kind:"circle",c:[0,-.62],r:.3,fill:x.gold,main:!0},E(-.13,-.33,.26,.2,x.metal),{kind:"curve",points:[[-.09,-.52],[0,-.66],[.09,-.52]]},P([-.08,-.08],[.08,-.08])],gear:[{kind:"polygon",points:[[.42,-.5],[.296,-.378],[.297,-.203],[.122,-.204],[0,-.08],[-.122,-.204],[-.297,-.203],[-.296,-.378],[-.42,-.5],[-.296,-.622],[-.297,-.797],[-.122,-.796],[-0,-.92],[.122,-.796],[.297,-.797],[.296,-.622]],fill:x.metal,main:!0},{kind:"circle",c:[0,-.5],r:.12,fill:x.paper}],database:[{kind:"polygon",points:[[-.35,-.8],[.35,-.8],[.35,-.16],[-.35,-.16]],fill:x.screen,main:!0},{kind:"polygon",points:[[.35,-.8],[.303,-.755],[.175,-.722],[0,-.71],[-.175,-.722],[-.303,-.755],[-.35,-.8],[-.303,-.845],[-.175,-.878],[-0,-.89],[.175,-.878],[.303,-.845]],fill:x.metal},{kind:"curve",points:[[-.35,-.16],[0,-.06],[.35,-.16]]},{kind:"curve",points:[[-.35,-.58],[0,-.48],[.35,-.58]]},{kind:"curve",points:[[-.35,-.37],[0,-.27],[.35,-.37]]}],robot:[P([0,-.95],[0,-1]),E(-.22,-.95,.44,.3,x.metal),{kind:"circle",c:[-.09,-.81],r:.045,fill:x.screen},{kind:"circle",c:[.09,-.81],r:.045,fill:x.screen},E(-.28,-.62,.56,.42,x.metal,!0),P([-.28,-.55],[-.42,-.35]),P([.28,-.55],[.42,-.35]),E(-.2,-.2,.12,.2,x.device),E(.08,-.2,.12,.2,x.device)],ship:[{kind:"polygon",points:[[-.48,-.3],[.48,-.3],[.36,-.04],[-.4,-.04]],fill:x.car,main:!0},E(-.42,-.62,.14,.32,x.wall),E(-.24,-.5,.2,.2,x.roof),E(-.02,-.5,.2,.2,x.bus),E(.2,-.5,.2,.2,x.green),{kind:"curve",points:[[-.5,0],[-.3,-.04],[-.1,0],[.1,-.04],[.3,0],[.5,-.04]]}],container:[E(-.46,-.52,.92,.52,x.roof,!0),...[-.3,-.15,0,.15,.3].map(e=>P([e,-.48],[e,-.04]))],warehouse:[{kind:"polygon",points:[[-.46,0],[.46,0],[.46,-.55],[0,-.82],[-.46,-.55]],fill:x.wall,main:!0},E(-.2,-.38,.4,.38,x.metal),P([-.2,-.26],[.2,-.26]),P([-.2,-.13],[.2,-.13])],box:[E(-.36,-.5,.52,.5,x.wood,!0),{kind:"polygon",points:[[-.36,-.5],[.16,-.5],[.36,-.64],[-.16,-.64]],fill:x.wood},{kind:"polygon",points:[[.16,0],[.36,-.14],[.36,-.64],[.16,-.5]],fill:x.wood},P([-.1,-.5],[.1,-.64])],pallet:[E(-.46,-.12,.92,.06,x.wood),...[-.42,-.05,.32].map(e=>E(e,-.06,.1,.06,x.wood)),E(-.42,-.5,.4,.38,x.wood,!0),E(.02,-.5,.4,.38,x.wood),E(-.2,-.82,.4,.32,x.wood)],shop:[E(-.42,-.6,.84,.6,x.wall,!0),{kind:"polygon",points:[[-.48,-.6],[.48,-.6],[.42,-.78],[-.42,-.78]],fill:x.roof},E(-.34,-.48,.34,.26,x.screen),E(.08,-.42,.24,.42,x.wood)],shelf:[E(-.4,-.92,.8,.92,x.paper,!0),P([-.4,-.62],[.4,-.62]),P([-.4,-.32],[.4,-.32]),E(-.32,-.8,.16,.18,x.roof),E(-.1,-.78,.14,.16,x.bus),E(.1,-.5,.22,.18,x.green),E(-.3,-.2,.24,.2,x.wood)],field:[P([-.48,0],[.48,0]),...[-.3,0,.3].flatMap(e=>[{kind:"curve",points:[[e,0],[e-.02,-.25],[e,-.5]]},{kind:"circle",c:[e-.08,-.32],r:.07,fill:x.green,main:!0},{kind:"circle",c:[e+.08,-.42],r:.07,fill:x.green,main:!0},{kind:"circle",c:[e,-.52],r:.06,fill:x.roof}])],cup:[{kind:"polygon",points:[[-.26,-.52],[.26,-.52],[.2,-.1],[-.2,-.1]],fill:x.paper,main:!0},{kind:"curve",points:[[.24,-.44],[.4,-.38],[.22,-.2]]},{kind:"polygon",points:[[-.46,-.1],[.46,-.1],[.36,0],[-.36,0]],fill:x.paper},{kind:"curve",points:[[-.08,-.62],[-.02,-.72],[-.08,-.84]]},{kind:"curve",points:[[.08,-.62],[.14,-.72],[.08,-.84]]}],function:[E(-.38,-.72,.76,.62,x.screen,!0),P([-.14,-.62],[0,-.62],[.14,-.2]),P([.02,-.42],[-.14,-.2])],"api-gateway":[E(-.12,-.8,.24,.8,x.metal,!0),P([-.48,-.55],[-.16,-.55]),P([-.24,-.62],[-.16,-.55],[-.24,-.48]),P([.16,-.3],[.48,-.3]),P([.4,-.37],[.48,-.3],[.4,-.23])],cache:[E(-.34,-.66,.68,.66,x.metal,!0),{kind:"polygon",points:[[.04,-.58],[-.12,-.3],[0,-.3],[-.06,-.08],[.14,-.38],[.02,-.38]],fill:x.gold}],cluster:[{kind:"curve",points:[[-.4,-.8],[0,-.86],[.4,-.8],[.48,-.45],[.4,-.1],[0,-.04],[-.4,-.1],[-.48,-.45],[-.4,-.8]]},E(-.3,-.7,.24,.2,x.screen,!0),E(.06,-.7,.24,.2,x.screen,!0),E(-.12,-.38,.24,.2,x.screen,!0)],board:[E(-.48,-.9,.96,.6,x.board,!0),E(-.34,-.76,.42,.03,x.chalk),E(-.34,-.62,.58,.03,x.chalk),E(-.34,-.48,.3,.03,x.chalk),P([-.3,-.3],[-.36,0]),P([.3,-.3],[.36,0])],book:[{kind:"polygon",points:[[0,-.62],[-.46,-.7],[-.46,-.1],[0,-.04]],fill:x.paper,main:!0},{kind:"polygon",points:[[0,-.62],[.46,-.7],[.46,-.1],[0,-.04]],fill:x.paper,main:!0},P([-.36,-.52],[-.1,-.48]),P([-.36,-.38],[-.1,-.34]),P([.1,-.48],[.36,-.52]),P([.1,-.34],[.36,-.38])],pencil:[{kind:"polygon",points:[[-.38,-.12],[.22,-.72],[.34,-.6],[-.26,0]],fill:x.bus,main:!0},{kind:"polygon",points:[[.22,-.72],[.34,-.6],[.44,-.86]],fill:x.wood},{kind:"polygon",points:[[-.38,-.12],[-.26,0],[-.46,-.02]],fill:x.roof}]},Zn=["happy","sad","surprised","worried","idea"],Qn={person:[0,-.87,.11],"person-pointing":[0,-.87,.11],"person-sitting":[-.08,-.9,.1]},Jn=e=>{let t=qt(e);return!!t&&t in Qn};function ko(e,t){let n=qt(e),r=n&&Qn[n];if(!r)return[];let[o,s,a]=r,i=a/.11,l=(u,d)=>[o+u*i,s+d*i],c=[{kind:"circle",c:l(-.04,-.015),r:.012*i,fill:x.dark},{kind:"circle",c:l(.04,-.015),r:.012*i,fill:x.dark}],h={kind:"curve",points:[l(-.05,.03),l(0,.06),l(.05,.03)]};switch(t){case"happy":return[...c,h];case"sad":return[...c,{kind:"curve",points:[l(-.05,.065),l(0,.035),l(.05,.065)]}];case"surprised":return[...c,{kind:"circle",c:l(0,.05),r:.022*i}];case"worried":return[...c,{kind:"polyline",points:[l(-.05,.055),l(-.017,.04),l(.017,.065),l(.05,.05)]}];case"idea":return[...c,h,{kind:"circle",c:l(0,-.26),r:.07*i,fill:x.gold},{kind:"polygon",points:[l(-.03,-.19),l(.03,-.19),l(.03,-.16),l(-.03,-.16)],fill:x.metal},{kind:"polyline",points:[l(-.11,-.3),l(-.15,-.33)]},{kind:"polyline",points:[l(.11,-.3),l(.15,-.33)]},{kind:"polyline",points:[l(0,-.36),l(0,-.41)]}]}}function tr(e,t,n=tn,r=!1,o,s){let[a,i]=t,l=([d,p])=>[a+(r?-d:d)*n,i+p*n],c=s&&Object.hasOwn(s,e)?s[e]:void 0,h=qt(e);if(!c&&!h)throw new Error(`Unknown prop "${e}".`);return(c??[...xo[h],...o?ko(h,o).map(d=>({...d,fine:!0})):[]]).map(d=>d.kind==="circle"?{...d,c:l(d.c),r:d.r*n}:{...d,points:d.points.map(l)})}var er=["spin","drive","steam","talk","pulse","float"],vo=["lesson","pitch","arch","decision","data","timeline","story"],nr=8,rr=6,or=2e5,sr=6e5,ir=24;function Ct(e){let t=Object.entries(e.params??{}),n=ut(e),r=[n];for(let o of Object.keys(e.switches??{}))r.length<9&&r.push({...n,[o]:n[o]?0:1});for(let[o,s]of t)for(let a of[s.min,s.max])a!==s.value&&r.length<9&&r.push({...n,[o]:a});return r}function ut(e){let t={};for(let[n,r]of Object.entries(e.params??{}))t[n]=r.value;for(let[n,r]of Object.entries(e.switches??{}))t[n]=r.on?1:0;return t}var cr=["card","line","arrow","polyline","polygon","curve","circle","ellipse","plot","text","highlight","pause","prop","repeat","when","move","link","counter","row","column","grid","axis","timeline","balloon","brace","note","table","bars","chain","animate","lottie"],$t=["text","prop","card","counter","circle","ellipse"],ar=["row","column","grid","chain"],$o=50;function U(e,t){if(!e||typeof e!="object"||Array.isArray(e))throw new Error(`${t}: expected an object.`)}function Y(e,t){if(typeof e!="string"||!e.trim()||e.length>2e3)throw new Error(`${t}: expected text of 1 to 2000 characters.`)}function F(e,t,n=-1e4,r=1e4){if(typeof e!="number"||!Number.isFinite(e)||e<n||e>r)throw new Error(`${t}: expected a number between ${n} and ${r}.`)}function ot(e,t){if(typeof e=="string"){if(Y(e,t),e.length>300)throw new Error(`${t}: expression too long.`)}else F(e,t)}function rt(e,t){if(!Array.isArray(e)||e.length!==2)throw new Error(`${t}: expected [x, y].`);e.forEach((n,r)=>ot(n,`${t}[${r}]`))}function ft(e,t){e!==void 0&&Y(e,t)}function st(e,t,n){if(e!==void 0&&(typeof e!="string"||!t.includes(e)))throw new Error(`${n}: choose one of ${t.join(", ")}.`)}function xe(e){if(!/^[A-Za-z_][A-Za-z_0-9]*$/.test(e)||["__proto__","constructor","prototype",...Je].includes(e))throw new Error(`Invalid variable name: "${e}".`)}var Gt=(e,t)=>t.includes("{")||e.exact.has(t)||[...e.repeated].some(n=>t.startsWith(`${n}-`)&&/^\d+$/.test(t.slice(n.length+1)));function Lt(e,t,n,r){r&&e[t]===void 0&&(e[t]=[0,0]),rt(e[t],`${n}.${t}`)}function oe(e,t,n,r,o=!1){if(U(e,t),++n.count>500)throw new Error(`${t}: a recipe draws at most 500 steps, counting those inside repeat and when.`);if(r){for(let i of["chapter","say","duration"])if(e[i]!==void 0)throw new Error(`${t}.${i}: put it on the ${r} step itself, not on a step inside it.`);if(e.type==="pause")throw new Error(`${t}: a pause cannot go inside ${r}.`);if(e.type==="repeat"&&r==="repeat")throw new Error(`${t}: a repeat cannot go inside another repeat.`);if(ar.includes(r)&&e.place!==void 0)throw new Error(`${t}.place: the ${r} places the steps inside it.`)}if(!cr.includes(e.type))throw new Error(`${t}: unknown type "${e.type}".`);for(let i of["id","say","chapter"])ft(e[i],`${t}.${i}`);if(e.duration!==void 0&&F(e.duration,`${t}.duration`,0,3e4),e.nudge!==void 0){if(["pause","move","link","animate"].includes(e.type))throw new Error(`${t}.nudge: a ${e.type} has no place of its own to move.`);if(!Array.isArray(e.nudge)||e.nudge.length!==2)throw new Error(`${t}.nudge: use [dx, dy].`);e.nudge.forEach((i,l)=>F(i,`${t}.nudge[${l}]`,-900,900))}let s=r!==null&&ar.includes(r)||o;if(e.place!==void 0){if(!$t.includes(e.type))throw new Error(`${t}.place: only ${$t.join(", ")} can be placed.`);if(U(e.place,`${t}.place`),Y(e.place.to,`${t}.place.to`),!Gt(n,String(e.place.to)))throw new Error(`${t}.place.to: no earlier step has the id "${e.place.to}".`);if(!["below","above","left","right"].includes(e.place.side))throw new Error(`${t}.place.side: choose one of below, above, left, right.`);e.place.gap!==void 0&&F(e.place.gap,`${t}.place.gap`,-200,400),st(e.place.align,["center","start","end"],`${t}.place.align`)}let a=s||e.place!==void 0;if(e.style!==void 0){U(e.style,`${t}.style`);for(let i of["color","fill"]){let l=e.style[i];if(l!==void 0&&(typeof l!="string"||!/^(#[\da-f]{3,8}|[a-z]+)$/i.test(l)))throw new Error(`${t}.style.${i}: use a hex colour or a colour name, no URLs.`)}for(let i of["width","roughness","bowing"])e.style[i]!==void 0&&F(e.style[i],`${t}.style.${i}`,0,20);if(e.style.opacity!==void 0&&F(e.style.opacity,`${t}.style.opacity`,0,1),e.style.dashed!==void 0&&typeof e.style.dashed!="boolean")throw new Error(`${t}: dashed must be a boolean.`);st(e.style.fillStyle,["hachure","solid","zigzag","cross-hatch","dots"],`${t}.style.fillStyle`)}switch(e.type){case"line":case"arrow":case"highlight":rt(e.from,`${t}.from`),rt(e.to,`${t}.to`),e.thickness!==void 0&&F(e.thickness,`${t}.thickness`,1,200);break;case"polyline":case"polygon":case"curve":if(!Array.isArray(e.points)||e.points.length<(e.type==="polygon"?3:2)||e.points.length>500)throw new Error(`${t}: points needs ${e.type==="polygon"?3:2} to 500 points.`);e.points.forEach((i,l)=>rt(i,`${t}.points[${l}]`));break;case"circle":case"ellipse":Lt(e,"center",t,a);for(let i of e.type==="circle"?["r"]:["rx","ry"])ot(e[i],`${t}.${i}`),typeof e[i]=="number"&&F(e[i],`${t}.${i}`,0);break;case"text":Lt(e,"at",t,a),Y(e.text,`${t}.text`),e.size!==void 0&&F(e.size,`${t}.size`,1,200),e.rotate!==void 0&&F(e.rotate,`${t}.rotate`,-360,360),st(e.font,["hand","body"],`${t}.font`),st(e.anchor,["start","middle","end"],`${t}.anchor`);break;case"card":Lt(e,"at",t,a),ot(e.w,`${t}.w`),ot(e.h,`${t}.h`);for(let i of["w","h"])typeof e[i]=="number"&&F(e[i],`${t}.${i}`,40);if(Y(e.title,`${t}.title`),e.lines!==void 0){if(!Array.isArray(e.lines)||e.lines.length>6)throw new Error(`${t}: at most 6 lines per card.`);e.lines.forEach((i,l)=>Y(i,`${t}.lines[${l}]`))}break;case"plot":Y(e.fn,`${t}.fn`),e.var!==void 0&&(Y(e.var,`${t}.var`),xe(String(e.var))),rt(e.domain,`${t}.domain`),rt(e.range,`${t}.range`),U(e.box,`${t}.box`);for(let i of["x","y","w","h"])ot(e.box[i],`${t}.box.${i}`);if(e.samples!==void 0&&(F(e.samples,`${t}.samples`,2,1e3),!Number.isInteger(e.samples)))throw new Error(`${t}: samples must be an integer.`);break;case"pause":F(e.ms,`${t}.ms`,0,3e4),ft(e.ask,`${t}.ask`);break;case"prop":if(!Un(e.name)&&!n.figures.has(String(e.name))){let i=n.figures.size?`, or one the recipe defines (${[...n.figures].join(", ")})`:"";throw new Error(`${t}.name: unknown prop "${String(e.name)}"; use one of ${re.join(", ")}${i}.`)}if(Lt(e,"at",t,a),e.size!==void 0&&(ot(e.size,`${t}.size`),typeof e.size=="number"&&F(e.size,`${t}.size`,10,1e3)),ft(e.label,`${t}.label`),e.flip!==void 0&&typeof e.flip!="boolean")throw new Error(`${t}.flip: expected true or false.`);if(e.mood!==void 0){if(!Jn(e.name))throw new Error(`${t}.mood: only a person (person, person-pointing, person-sitting) has a face.`);st(e.mood,Zn,`${t}.mood`)}break;case"repeat":if(ot(e.times,`${t}.times`),typeof e.times=="number"&&(F(e.times,`${t}.times`,0,$o),!Number.isInteger(e.times)))throw new Error(`${t}.times: expected a whole number.`);oe(e.step,`${t}.step`,n,"repeat",s);break;case"when":if(ot(e.if,`${t}.if`),!Array.isArray(e.steps)||e.steps.length===0||e.steps.length>50)throw new Error(`${t}.steps: expected 1 to 50 steps.`);e.steps.forEach((i,l)=>oe(i,`${t}.steps[${l}]`,n,r??"when"));break;case"move":if(Y(e.target,`${t}.target`),!Gt(n,String(e.target)))throw new Error(`${t}.target: no earlier step has the id "${e.target}".`);rt(e.to,`${t}.to`),st(e.along,["line","curve"],`${t}.along`),e.ms!==void 0&&F(e.ms,`${t}.ms`,200,5e3);break;case"lottie":if(Y(e.src,`${t}.src`),rt(e.at,`${t}.at`),e.size!==void 0&&(ot(e.size,`${t}.size`),typeof e.size=="number"&&F(e.size,`${t}.size`,24,1e3)),e.loop!==void 0&&typeof e.loop!="boolean")throw new Error(`${t}.loop: expected true or false.`);break;case"animate":if(Y(e.target,`${t}.target`),!Gt(n,String(e.target)))throw new Error(`${t}.target: no earlier step has the id "${e.target}".`);if(st(e.effect,[...er,"stop"],`${t}.effect`),e.effect===void 0)throw new Error(`${t}.effect: choose one of ${[...er,"stop"].join(", ")}.`);st(e.speed,["slow","fast"],`${t}.speed`);break;case"link":for(let i of["from","to"])if(Y(e[i],`${t}.${i}`),!Gt(n,String(e[i])))throw new Error(`${t}.${i}: no earlier step has the id "${e[i]}".`);ft(e.label,`${t}.label`);break;case"counter":if(Lt(e,"at",t,a),ot(e.value,`${t}.value`),e.format!==void 0&&(Y(e.format,`${t}.format`),!String(e.format).includes("{v")))throw new Error(`${t}.format: show the number as {v}, e.g. "R$ {v:0}".`);e.size!==void 0&&F(e.size,`${t}.size`,1,200),st(e.anchor,["start","middle","end"],`${t}.anchor`);break;case"row":case"column":case"grid":if(s)throw new Error(`${t}: a ${e.type} cannot go inside another ${r}.`);if(Lt(e,"at",t,!1),e.gap!==void 0&&F(e.gap,`${t}.gap`,0,400),e.type==="grid"){if(F(e.columns,`${t}.columns`,1,12),!Number.isInteger(e.columns))throw new Error(`${t}.columns: expected a whole number.`)}else st(e.align,["center","start","end"],`${t}.align`);if(!Array.isArray(e.steps)||e.steps.length===0||e.steps.length>50)throw new Error(`${t}.steps: expected 1 to 50 steps.`);e.steps.forEach((i,l)=>{U(i,`${t}.steps[${l}]`);let c=i.type==="repeat"?i.step?.type:i.type;if(!$t.includes(c))throw new Error(`${t}.steps[${l}]: a ${e.type} holds only ${$t.join(", ")} (or a repeat of one).`);oe(i,`${t}.steps[${l}]`,n,e.type)});break;case"chain":if(s)throw new Error(`${t}: a chain cannot go inside a ${r}.`);if(Lt(e,"at",t,!1),e.gap!==void 0&&e.gap!=="auto"&&F(e.gap,`${t}.gap`,0,400),st(e.direction,["right","down"],`${t}.direction`),e.wrap!==void 0&&typeof e.wrap!="boolean")throw new Error(`${t}.wrap: expected true or false.`);if(ft(e.forward,`${t}.forward`),ft(e.back,`${t}.back`),e.size!==void 0&&(ot(e.size,`${t}.size`),typeof e.size=="number"&&F(e.size,`${t}.size`,10,1e3)),!Array.isArray(e.steps)||e.steps.length<2||e.steps.length>12)throw new Error(`${t}.steps: a chain joins 2 to 12 pieces.`);e.steps.forEach((i,l)=>{if(U(i,`${t}.steps[${l}]`),!$t.includes(i.type))throw new Error(`${t}.steps[${l}]: a chain holds only ${$t.join(", ")}.`);oe(i,`${t}.steps[${l}]`,n,"chain")});break;case"axis":case"timeline":if(rt(e.from,`${t}.from`),rt(e.to,`${t}.to`),rt(e.domain,`${t}.domain`),e.type==="axis"){if(e.ticks!==void 0){if(Array.isArray(e.ticks)){if(e.ticks.length>30)throw new Error(`${t}.ticks: at most 30 marks.`);e.ticks.forEach((i,l)=>F(i,`${t}.ticks[${l}]`))}else if(F(e.ticks,`${t}.ticks`,0,30),!Number.isInteger(e.ticks))throw new Error(`${t}.ticks: expected a whole number.`)}if(ft(e.label,`${t}.label`),e.format!==void 0&&(Y(e.format,`${t}.format`),!String(e.format).includes("{v")))throw new Error(`${t}.format: show the number as {v}, e.g. "{v} km".`)}else{if(!Array.isArray(e.marks)||e.marks.length===0||e.marks.length>20)throw new Error(`${t}.marks: expected 1 to 20 marks.`);e.marks.forEach((i,l)=>{U(i,`${t}.marks[${l}]`),ot(i.at,`${t}.marks[${l}].at`),ft(i.label,`${t}.marks[${l}].label`),ft(i.text,`${t}.marks[${l}].text`)})}break;case"balloon":if(Y(e.to,`${t}.to`),!Gt(n,String(e.to)))throw new Error(`${t}.to: no earlier step has the id "${e.to}".`);if(Y(e.text,`${t}.text`),String(e.text).length>300)throw new Error(`${t}.text: keep a balloon under 300 characters.`);st(e.side,["below","above","left","right"],`${t}.side`),st(e.kind,["speech","thought"],`${t}.kind`),e.width!==void 0&&F(e.width,`${t}.width`,80,600),e.size!==void 0&&F(e.size,`${t}.size`,12,60);break;case"brace":if(rt(e.from,`${t}.from`),rt(e.to,`${t}.to`),ft(e.label,`${t}.label`),e.flip!==void 0&&typeof e.flip!="boolean")throw new Error(`${t}.flip: expected true or false.`);break;case"note":if(rt(e.at,`${t}.at`),Y(e.text,`${t}.text`),e.to===void 0==(e.point===void 0))throw new Error(`${t}: a note points either to an element (to) or to a point (point).`);if(e.to!==void 0){if(Y(e.to,`${t}.to`),!Gt(n,String(e.to)))throw new Error(`${t}.to: no earlier step has the id "${e.to}".`)}else rt(e.point,`${t}.point`);e.size!==void 0&&F(e.size,`${t}.size`,12,60);break;case"table":if(rt(e.at,`${t}.at`),!Array.isArray(e.rows)||e.rows.length===0||e.rows.length>12)throw new Error(`${t}.rows: expected 1 to 12 rows.`);if(e.rows.forEach((i,l)=>{if(!Array.isArray(i)||i.length===0||i.length>6)throw new Error(`${t}.rows[${l}]: expected 1 to 6 cells.`);i.forEach((c,h)=>{if(typeof c!="string"||c.length>120)throw new Error(`${t}.rows[${l}][${h}]: expected text of up to 120 characters.`)})}),e.header!==void 0&&typeof e.header!="boolean")throw new Error(`${t}.header: expected true or false.`);e.size!==void 0&&F(e.size,`${t}.size`,12,40);break;case"bars":U(e.box,`${t}.box`);for(let i of["x","y","w","h"])ot(e.box[i],`${t}.box.${i}`);if(!Array.isArray(e.values)||e.values.length===0||e.values.length>12)throw new Error(`${t}.values: expected 1 to 12 values.`);if(e.values.forEach((i,l)=>ot(i,`${t}.values[${l}]`)),e.labels!==void 0){if(!Array.isArray(e.labels)||e.labels.length>e.values.length)throw new Error(`${t}.labels: at most one label per value.`);e.labels.forEach((i,l)=>Y(i,`${t}.labels[${l}]`))}if(e.max!==void 0&&ot(e.max,`${t}.max`),e.format!==void 0&&(Y(e.format,`${t}.format`),!String(e.format).includes("{v")))throw new Error(`${t}.format: show the number as {v}, e.g. "{v}%".`);break}typeof e.id=="string"&&(r==="repeat"?n.repeated:n.exact).add(e.id)}function So(e,t){let n=`defs.${e}`;if(!/^[a-z][a-z0-9-]{1,30}$/.test(e))throw new Error(`${n}: a figure's name is 2 to 31 lowercase letters, digits or -, starting with a letter.`);if(qt(e)||Object.hasOwn(_t,e)||cr.includes(e)||["define","title","param","switch","var"].includes(e))throw new Error(`${n}: "${e}" is already a prop or a step; choose another name.`);if(U(t,n),!Array.isArray(t.shapes)||t.shapes.length===0||t.shapes.length>ir)throw new Error(`${n}.shapes: expected 1 to ${ir} shapes.`);let r=(o,s)=>{if(typeof o!="number"||!Number.isInteger(o)||o<0||o>100)throw new Error(`${s}: expected a whole number from 0 to 100 (the figure's grid, y down; it stands at 50,100).`)};t.shapes.forEach((o,s)=>{let a=`${n}.shapes[${s}]`;if(U(o,a),o.fill!==void 0&&(typeof o.fill!="string"||!/^(#[0-9a-fA-F]{3,8}|[a-z]{3,20})$/.test(o.fill)))throw new Error(`${a}.fill: a colour, as hex or a plain name.`);if(o.kind==="circle"){if(!Array.isArray(o.c)||o.c.length!==2)throw new Error(`${a}.c: expected [x, y].`);o.c.forEach((l,c)=>r(l,`${a}.c[${c}]`)),r(o.r,`${a}.r`);return}if(!["polygon","polyline","curve"].includes(o.kind))throw new Error(`${a}.kind: choose one of polygon, polyline, curve, circle.`);let i=o.kind==="polygon"?3:2;if(!Array.isArray(o.points)||o.points.length<i||o.points.length>40)throw new Error(`${a}.points: a ${o.kind} takes ${i} to 40 points.`);o.points.forEach((l,c)=>{if(!Array.isArray(l)||l.length!==2)throw new Error(`${a}.points[${c}]: expected [x, y].`);l.forEach((h,u)=>r(h,`${a}.points[${c}][${u}]`))})})}function Mo(e,t){let n=`lottie "${e}"`;U(t,n);let r=JSON.stringify(t).length;if(r>or)throw new Error(`${n}: ${Math.round(r/1e3)} KB; an animation can have at most ${or/1e3} KB.`);for(let s of["fr","ip","op","w","h"])F(t[s],`${n}.${s}`,0,1e5);if(typeof t.v!="string"||!Array.isArray(t.layers))throw new Error(`${n}: not a Lottie animation (it needs v and layers).`);let o=(s,a)=>{if(Array.isArray(s))return s.forEach((i,l)=>o(i,`${a}[${l}]`));if(!(!s||typeof s!="object"))for(let[i,l]of Object.entries(s)){if(i==="x"&&typeof l=="string")throw new Error(`${n}: the animation has an expression (code inside it, at ${a}); only animations without expressions play.`);o(l,`${a}.${i}`)}};o(t.layers,"layers");for(let s of Array.isArray(t.assets)?t.assets:[]){let a=s?.p;if(typeof a=="string"&&a&&!a.startsWith("data:")&&!Array.isArray(s.layers))throw new Error(`${n}: an image from outside the animation ("${a.slice(0,40)}"); only images inside it (data:) are kept.`)}return r}function en(e){U(e,"The recipe");let t=e;F(t.width,"width",100,4e3),F(t.height,"height",100,4e3);for(let o of["id","title","category"])ft(t[o],o);if(t.locale!==void 0&&!(typeof t.locale=="string"&&/^[a-zA-Z]{2,3}(-[a-zA-Z0-9]{2,8})*$/.test(t.locale)&&Intl.NumberFormat.supportedLocalesOf([t.locale]).length>0))throw new Error('locale: expected a language tag such as "en-US" or "pt-BR".');if(st(t.background,["dots","grid","plain"],"background"),st(t.kind,vo,"kind"),ft(t.source,"source"),t.quiz!==void 0&&t.kind!==void 0&&t.kind!=="lesson")throw new Error(`quiz: only a lesson has a quiz (this drawing is a ${t.kind}).`);if(st(t.theme,["paper","chalkboard"],"theme"),t.quiz!==void 0){if(U(t.quiz,"quiz"),Y(t.quiz.question,"quiz.question"),!Array.isArray(t.quiz.options)||t.quiz.options.length<2||t.quiz.options.length>4)throw new Error("quiz.options: expected 2 to 4 options.");if(t.quiz.options.forEach((o,s)=>{if(U(o,`quiz.options[${s}]`),Y(o.text,`quiz.options[${s}].text`),Y(o.why,`quiz.options[${s}].why`),typeof o.right!="boolean")throw new Error(`quiz.options[${s}].right: expected true or false.`)}),t.quiz.options.filter(o=>o.right===!0).length!==1)throw new Error("quiz.options: exactly one option is right.")}if(t.learning!==void 0){U(t.learning,"learning");for(let o of["goal","question","answer","caveat"])Y(t.learning[o],`learning.${o}`)}if(t.params!==void 0){U(t.params,"params");for(let[o,s]of Object.entries(t.params))if(xe(o),U(s,`params.${o}`),Y(s.label,`params.${o}.label`),F(s.min,`${o}.min`),F(s.max,`${o}.max`),F(s.step,`${o}.step`,1e-6),F(s.value,`${o}.value`,s.min,s.max),s.max<=s.min)throw new Error(`${o}: max must be greater than min.`)}if(t.vars!==void 0){U(t.vars,"vars");for(let[o,s]of Object.entries(t.vars))xe(o),ot(s,`vars.${o}`)}if(t.switches!==void 0){U(t.switches,"switches");let o=Object.entries(t.switches);if(o.length>8)throw new Error("switches: at most 8.");for(let[s,a]of o){if(xe(s),Object.hasOwn(t.params??{},s)||Object.hasOwn(t.vars??{},s))throw new Error(`switches.${s}: the name is already a param or a var.`);if(U(a,`switches.${s}`),Y(a.label,`switches.${s}.label`),typeof a.on!="boolean")throw new Error(`switches.${s}.on: expected true or false.`)}}if(!Array.isArray(t.steps)||t.steps.length===0||t.steps.length>250)throw new Error("A recipe needs 1 to 250 steps.");let n=new Set;if(t.defs!==void 0){U(t.defs,"defs");let o=Object.entries(t.defs);if(o.length>nr)throw new Error(`defs: at most ${nr} figures.`);for(let[s,a]of o)So(s,a),n.add(s)}if(t.lotties!==void 0){U(t.lotties,"lotties");let o=Object.entries(t.lotties);if(o.length>rr)throw new Error(`lotties: at most ${rr} animations.`);let s=o.reduce((a,[i,l])=>a+Mo(i,l),0);if(s>sr)throw new Error(`lotties: ${Math.round(s/1e3)} KB in all; at most ${sr/1e3} KB.`)}if(t.credits!==void 0){if(!Array.isArray(t.credits)||t.credits.length>5)throw new Error("credits: at most 5 lines.");t.credits.forEach((o,s)=>Y(o,`credits[${s}]`))}let r={exact:new Set,repeated:new Set,count:0,figures:n};return t.steps.forEach((o,s)=>oe(o,`Step ${s+1}`,r,null)),{...t,id:t.id??"pasted",title:t.title??"",background:t.background??"dots"}}function se(e,t="Start"){let n=e.steps.flatMap((r,o)=>r.chapter?[{title:r.chapter,start:o}]:[]);return(!n.length||n[0].start!==0)&&n.unshift({title:t,start:0}),n.map((r,o)=>({...r,end:(n[o+1]?.start??e.steps.length)-1}))}var Eo=50,Ao=(e,t)=>Math.max(0,Math.min(Eo,Math.round(B(e,t)))),Xt=(e,t)=>t===0?e:typeof e=="number"?Math.round((e+t)*100)/100:`(${e})${t<0?"-":"+"}${Math.abs(t)}`,gt=(e,t,n)=>[Xt(e[0],t),Xt(e[1],n)];function zt(e,t,n){switch(e.type){case"prop":case"text":case"card":case"counter":case"lottie":return{...e,at:gt(e.at,t,n)};case"circle":case"ellipse":return{...e,center:gt(e.center,t,n)};case"line":case"arrow":case"highlight":return{...e,from:gt(e.from,t,n),to:gt(e.to,t,n)};case"polyline":case"polygon":case"curve":return{...e,points:e.points.map(r=>gt(r,t,n))};case"plot":return{...e,box:{...e.box,x:Xt(e.box.x,t),y:Xt(e.box.y,n)}};case"repeat":return{...e,step:zt(e.step,t,n)};case"row":case"column":case"grid":case"chain":return{...e,at:gt(e.at,t,n)};case"axis":case"timeline":case"brace":return{...e,from:gt(e.from,t,n),to:gt(e.to,t,n)};case"note":return{...e,at:gt(e.at,t,n),...e.point?{point:gt(e.point,t,n)}:{}};case"table":return{...e,at:gt(e.at,t,n)};case"bars":return{...e,box:{...e.box,x:Xt(e.box.x,t),y:Xt(e.box.y,n)}};case"when":return{...e,steps:e.steps.map(r=>zt(r,t,n))};default:return e}}function Tt(e,t,n=[]){if(e.nudge){let{nudge:r,...o}=e;return Tt(zt(o,r[0],r[1]),t,n).map(s=>({...s,nudge:[(s.nudge?.[0]??0)+r[0],(s.nudge?.[1]??0)+r[1]]}))}return e.type==="repeat"?Array.from({length:Ao(e.times,t)},(r,o)=>Tt(e.step,{...t,i:o},[...n,o]).map(s=>({...s,id:s.id&&`${s.id}-${o}`}))).flat():e.type==="when"?B(e.if,t)!==0?e.steps.flatMap((r,o)=>Tt(r,t,[...n,o])):[]:[{step:e,scope:t,path:n,id:e.id}]}var St=(e,t)=>e.includes("{")?nt(e,t):e;function hr(e,t){let n=r=>[B(r[0],t),B(r[1],t)];switch(e.type){case"prop":case"text":case"card":case"counter":case"lottie":return n(e.at);case"circle":case"ellipse":return n(e.center);case"line":case"arrow":case"highlight":return n(e.from);case"polyline":case"polygon":case"curve":return n(e.points[0]);case"plot":return[B(e.box.x,t),B(e.box.y,t)];case"row":case"column":case"grid":case"chain":return n(e.at);case"axis":case"timeline":case"brace":return n(e.from);case"note":case"table":return n(e.at);case"bars":return[B(e.box.x,t),B(e.box.y,t)];default:return null}}function Yt(e,t,n=0){let[r,o]=[e.x+e.w/2,e.y+e.h/2],[s,a]=[t[0]-r,t[1]-o],i=Math.hypot(s,a);if(i===0)return[r,o];let l=s===0?1/0:e.w/2/Math.abs(s),c=a===0?1/0:e.h/2/Math.abs(a),h=Math.min(l,c);return[r+s*h+s/i*n,o+a*h+a/i*n]}function rn(e,t,n=8){let r=[e.x+e.w/2,e.y+e.h/2],o=[t.x+t.w/2,t.y+t.h/2];return[Yt(e,o,n),Yt(t,r,n)]}function ur(e,t,n=16){let[r,o]=[t[0]-e[0],t[1]-e[1]],s=Math.hypot(r,o)||1,[a,i]=[-o/s,r/s];(i>0||i===0&&a<0)&&([a,i]=[-a,-i]);let l=[(e[0]+t[0])/2,(e[1]+t[1])/2];return{at:[l[0]+a*n,l[1]+i*n],anchor:a>.5?"start":a<-.5?"end":"middle"}}function on(e,t,n,r="line"){if(r==="line")return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n];let[o,s]=[t[0]-e[0],t[1]-e[1]],a=Math.hypot(o,s),[i,l]=a?[-s/a,o/a]:[0,0];l>0&&([i,l]=[-i,-l]);let c=[(e[0]+t[0])/2+i*a*.3,(e[1]+t[1])/2+l*a*.3],h=1-n;return[h*h*e[0]+2*h*n*c[0]+n*n*t[0],h*h*e[1]+2*h*n*c[1]+n*n*t[1]]}var sn=(e,t)=>Number.isInteger(e)?Math.round(e*t):e*t,ve=(e,t,n,r)=>nt(e??"{v}",{...n,v:t},r);function ke(e){let t=0;for(let n of e)n.type==="move"&&n.ms?t=Math.max(t,n.ms):n.type==="repeat"?t=Math.max(t,ke([n.step])):n.type==="when"&&(t=Math.max(t,ke(n.steps)));return t}var dt=e=>Math.round(e*100)/100,lr=e=>Math.max(0,e.w)*Math.max(0,e.h);function Oo(e,t){let n=Math.min(e.x+e.w,t.x+t.w)-Math.max(e.x,t.x),r=Math.min(e.y+e.h,t.y+t.h)-Math.max(e.y,t.y);return n>0&&r>0?n*r:0}function an(e,t,n,r=24,o="center"){let s=(l,c,h)=>o==="start"?l:o==="end"?l+c-h:l+(c-h)/2,[a,i]=n==="below"?[s(t.x,t.w,e.w),t.y+t.h+r]:n==="above"?[s(t.x,t.w,e.w),t.y-r-e.h]:n==="right"?[t.x+t.w+r,s(t.y,t.h,e.h)]:[t.x-r-e.w,s(t.y,t.h,e.h)];return[dt(a-e.x),dt(i-e.y)]}function dr(e,t,n,r=24,o="center",s=1){if(!t.length)return[];if(e==="grid"){let c=Math.max(1,s),h=Math.max(...t.map(d=>d.w)),u=Math.max(...t.map(d=>d.h));return t.map((d,p)=>{let[m,g]=[p%c,Math.floor(p/c)];return[dt(n[0]+m*(h+r)+(h-d.w)/2-d.x),dt(n[1]+g*(u+r)+(u-d.h)/2-d.y)]})}let a=e==="row",i=Math.max(...t.map(c=>a?c.h:c.w)),l=a?n[0]:n[1];return t.map(c=>{let[h,u]=a?[c.w,c.h]:[c.h,c.w],d=o==="start"?0:o==="end"?i-u:(i-u)/2,[p,m]=a?[l,n[1]+d]:[n[0]+d,l];return l+=h+r,[dt(p-c.x),dt(m-c.y)]})}var nn=16,Po=240,Lo=90;function pr(e,t,n,r={},o=30){if(!e.length)return{deltas:[],lines:[]};let s=r.direction==="down",a=p=>s?p.h:p.w,i=(s?n.h-t[1]:n.w-t[0])-o,l=p=>r.gap!==void 0&&r.gap!=="auto"?r.gap:p.length<2?nn:Math.min(Po,Math.max(nn,(i-p.reduce((m,g)=>m+g,0))/(p.length-1))),c=[[]],h=0;e.forEach((p,m)=>{let g=c[c.length-1],f=(g.length?nn:0)+a(p);r.wrap&&g.length&&h+f>i?(c.push([m]),h=a(p)):(g.push(m),h+=f)});let u=new Array(e.length),d=s?t[0]:t[1];for(let p of c){let m=l(p.map(b=>a(e[b]))),g=Math.max(...p.map(b=>s?e[b].w:e[b].h)),f=s?t[1]:t[0];for(let b of p){let y=e[b],[w,k]=s?[d+(g-y.w)/2,f]:[f,d+g-y.h];u[b]=[dt(w-y.x),dt(k-y.y)],f+=a(y)+m}d+=g+Lo}return{deltas:u,lines:c}}function fr(e,t,n=!1,r=8){if(n){let[i,l]=[e.x+e.w/2,t.x+t.w/2],[c,h]=[e.y+e.h+24,t.y-24],u=(e.x+e.w+t.x)/2;return[[i,e.y+e.h+r],[i,c],[u,c],[u,h],[l,h],[l,t.y-r]]}let o=e.x+e.w+24,s=(e.y+e.h+t.y)/2,a=t.x+t.w/2;return[[e.x+e.w+r,e.y+e.h/2],[o,e.y+e.h/2],[o,s],[a,s],[a,t.y-r]]}function cn(e,t,n,r=30){let o=(s,a,i)=>a>i-2*r?s<0||s+a>i?(i-a)/2-s:0:s<0?r-s:s+a>i?i-r-(s+a):0;return[dt(o(e.x,e.w,t)),dt(o(e.y,e.h,n))]}function mr(e,t,n,r=60,o=4){let s=a=>t.some(i=>Oo(a,i)>.2*Math.min(lr(a),lr(i)));if(!s(e))return 0;for(let a=o;a<=r;a+=o)for(let i of[a,-a]){let l={...e,y:e.y+i};if(l.y>=0&&l.y+l.h<=n&&!s(l))return i}return 0}function gr(e,t){if(Array.isArray(t))return t;let n=t??5;return n===0?[]:Array.from({length:n+1},(r,o)=>dt(e[0]+(e[1]-e[0])*o/n))}function ln(e,t,n,r){let o=(r-n[0])/(n[1]-n[0]);return!Number.isFinite(o)||o<-1e-9||o>1+1e-9?null:[dt(e[0]+(t[0]-e[0])*o),dt(e[1]+(t[1]-e[1])*o)]}function hn(e,t){let[n,r]=[t[0]-e[0],t[1]-e[1]],o=Math.hypot(n,r)||1,s=[-r/o,n/o];return(Math.abs(n)>=Math.abs(r)?s[1]<0:s[0]>0)&&(s=[-s[0],-s[1]]),[s[0]||0,s[1]||0]}var Co="http://www.w3.org/2000/svg",bt="#2B2B2B",To={"#2b2b2b":"#F4F1E8","#242424":"#F4F1E8",black:"#F4F1E8","#2f5bea":"#A8C1FF","#1f4e9a":"#A8C1FF",blue:"#A8C1FF","#c8442c":"#FF9F8A",red:"#FF9F8A","#2e8f62":"#93E2AE","#0e7a0b":"#93E2AE",green:"#93E2AE","#8c8578":"#CFC9BC","#5e5a52":"#D9D3C6",grey:"#CFC9BC",gray:"#CFC9BC","#ffffff":"#34493D","#fff":"#34493D",white:"#34493D"},zo=["text","card","prop","counter"],un={hand:"'Caveat', cursive",body:"'Shantell Sans', system-ui, sans-serif"},Vt=class extends Error{},br=e=>e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2,Bo="cubic-bezier(.45,0,.55,1)",Ro="[data-anim]{transform-box:fill-box;transform-origin:center}[data-anim=talk]{transform-origin:center bottom}@keyframes ct-spin{to{transform:rotate(360deg)}}@keyframes ct-drive{0%,100%{transform:translate(0,0)}25%{transform:translate(-5px,-2px) rotate(-1deg)}75%{transform:translate(5px,-2px) rotate(1deg)}}@keyframes ct-talk{0%,100%{transform:rotate(0) scaleY(1)}50%{transform:rotate(-2deg) scaleY(1.03)}}@keyframes ct-pulse{0%,100%{transform:scale(1)}50%{transform:scale(1.1)}}@keyframes ct-float{0%,100%{transform:translateY(0)}50%{transform:translateY(-7px)}}@keyframes ct-wisp{0%{opacity:0;transform:translateY(6px)}30%{opacity:.9}100%{opacity:0;transform:translateY(-14px)}}@media (prefers-reduced-motion:reduce){[data-anim]{animation:none!important}}",jo={spin:[3200,"linear"],drive:[1600,"ease-in-out"],talk:[900,"ease-in-out"],pulse:[1400,"ease-in-out"],float:[3e3,"ease-in-out"],wisp:[2100,"ease-out"]},pn;function yr(e){pn=e}var wr="@keyframes ct-draw{from{stroke-dasharray:var(--l) var(--l);stroke-dashoffset:var(--l)}to{stroke-dasharray:var(--l) var(--l);stroke-dashoffset:0}}@keyframes ct-write{from{transform:scaleX(0)}}@keyframes ct-fade{from{opacity:0}}@keyframes ct-show{0%,100%{opacity:1}}@keyframes ct-wait{0%,100%{opacity:0}}@keyframes ct-move{from{transform:translate(var(--fx),var(--fy))}50%{transform:translate(var(--mx),var(--my))}}@media (prefers-reduced-motion:reduce){*{animation:none!important}}";function _(e,t={}){let n=document.createElementNS(Co,e);for(let[r,o]of Object.entries(t))n.setAttribute(r,String(o));return n}var dn=e=>[e.x+e.w/2,e.y+e.h/2];function No(e){return 1e3+e*97}function $e(e,t=e.steps.length-1){let n=[],r=Math.min(t,e.steps.length-1);for(let o=0;o<=r;){let s=e.steps[o],a=o;if(s.type!=="pause")for(;a<r;){let l=e.steps[a+1];if(l.type==="pause"||l.say||l.chapter)break;a++}let i=s.type==="pause"?s.ms:s.duration===0?0:Math.min(1600,Math.max(1e3,s.duration??(s.type==="text"?1400:1100)));n.push({start:o,end:a,duration:s.type==="pause"?i:Math.max(i,ke(e.steps.slice(o,a+1)))}),o=a+1}return n}function Mt(e,t){let n={};for(let[r,o]of Object.entries(e.params??{}))n[r]=t[r]??o.value;for(let[r,o]of Object.entries(e.switches??{}))n[r]=t[r]??(o.on?1:0)?1:0;for(let[r,o]of Object.entries(e.vars??{}))n[r]=B(o,n);return n}var Io=0,at=class{constructor(t,n=()=>{}){q(this,"uid",`dw${++Io}`);q(this,"gen",Xn.generator());q(this,"run",0);q(this,"speed",1);q(this,"layers");q(this,"defs");q(this,"named",new Map);q(this,"locale");q(this,"paper",{w:0,h:0});q(this,"textBoxes",[]);q(this,"leafNudge");q(this,"theme","paper");q(this,"css",!1);q(this,"figures",{});q(this,"motion","run");q(this,"beatAt",0);q(this,"steam",new Map);q(this,"scene");q(this,"lotties",{});q(this,"playing",[]);q(this,"svg");q(this,"onSay");this.svg=t,this.onSay=n}stop(){this.run++,this.layers&&(this.layers.pencil.style.opacity="0")}setSpeed(t){if(!Number.isFinite(t)||t<=0)throw new Error("The speed must be a positive number.");this.speed=t}async render(t,n,r){let o=++this.run;this.setSpeed(r.speed??1);let s=Mt(t,n);this.locale=t.locale,this.theme=r.theme??t.theme??"paper",this.css=!!r.css&&!r.animate,this.motion=r.motion??"run",this.scene=t,this.setup(t);let a=0;try{for(let i of $e(t,r.until)){if(o!==this.run)throw new Vt;this.beatAt=a;let l=[],c,h=r.animate&&i.start>=(r.from??0);for(let u=i.start;u<=i.end;u++){let d=t.steps[u];if(r.onStep?.(u),d.say&&this.onSay(c=nt(d.say,s,t.locale)),d.type!=="pause"){let p=this.made(()=>{for(let m of Tt(d,s))l.push(...this.buildLeaf(m,u,h))});for(let m of p)m.dataset.step=String(u)}}if(this.css&&(t.steps[i.start].type!=="pause"&&this.schedule(l,a,i.duration),a+=i.duration),h&&r.beforeBeat&&(await r.beforeBeat(c,i.start),o!==this.run))throw new Vt;h&&(t.steps[i.start].type==="pause"?(this.layers.pencil.style.opacity="0",await this.tween(i.duration,o,()=>{})):await this.play(l,i.duration,o))}r.animate&&(this.layers.pencil.style.opacity="0")}catch(i){if(!(i instanceof Vt))throw i}}setup(t){this.figures=Do(t.defs),this.steam.clear(),this.lotties=t.lotties??{};for(let l of this.playing)l.destroy();this.playing=[];let n=this.svg;if(n.replaceChildren(),n.setAttribute("viewBox",`0 0 ${t.width} ${t.height}`),n.style.aspectRatio=`${t.width} / ${t.height}`,n.setAttribute("aria-label",t.title),this.defs=_("defs"),n.append(this.defs),JSON.stringify(t.steps).includes('"type":"animate"')){let l=_("style");l.textContent=Ro,n.append(l)}let r=t.background??"dots",o=this.theme==="chalkboard";if(r!=="plain"){let l=_("pattern",{id:`${this.uid}-paper`,width:r==="grid"?24:22,height:r==="grid"?24:22,patternUnits:"userSpaceOnUse"});l.append(r==="grid"?_("path",{d:"M24 0H0V24",fill:"none",stroke:o?"#33473B":"#DCE5EF","stroke-width":1}):_("circle",{cx:11,cy:11,r:1.2,fill:o?"#3A5043":"#D9D2C3"})),this.defs.append(l)}n.append(_("rect",{width:t.width,height:t.height,fill:o?"#26372E":"#FBF7EE"})),r!=="plain"&&n.append(_("rect",{width:t.width,height:t.height,fill:`url(#${this.uid}-paper)`}));let s=_("g"),a=_("g"),i=this.makePencil();n.append(s,a,i),this.layers={highlight:s,ink:a,pencil:i},this.named.clear(),this.paper={w:t.width,h:t.height},this.textBoxes=[]}made(t){let n=[this.layers.ink,this.layers.highlight],r=n.map(o=>o.childElementCount);return t(),n.flatMap((o,s)=>[...o.children].slice(r[s]))}seedOf(t,n){return No(t)+n.reduce((r,o)=>r*31+o+1,0)*7}buildLeaf(t,n,r){var h;let o=t.step.type;if(o==="row"||o==="column"||o==="grid")return this.arrange(t,n,r);if(o==="chain")return this.chain(t,n,r);let s=[n,...t.path].join("_"),a=this.seedOf(n,t.path),i=t.arranged?t.step:this.settle(t,s,a),l=[];this.leafNudge=t.nudge;let c=this.made(()=>{l=this.build(i,s,a,t.scope,r)});this.leafNudge=void 0;for(let u of c)(h=u.dataset).type??(h.type=i.type);if(c.length&&(i.type==="text"||i.type==="counter")&&this.textBoxes.push(this.boxOf(c,0,0)),t.id&&c.length){let u=hr(i,t.scope)??dn(this.boxOf(c,0,0));this.named.set(t.id,{els:c,anchor:u,dx:0,dy:0})}return l}measure(t){let n=[this.layers.ink,this.layers.highlight,this.defs],r=n.map(i=>i.childElementCount);t();let o=n.map((i,l)=>[...i.children].slice(r[l])),s=[...o[0],...o[1]],a=s.length?this.boxOf(s,0,0):null;return o.flat().forEach(i=>i.remove()),a}settle(t,n,r){let o=t.step,s=o.type==="text"?!o.rotate:zo.includes(o.type);if(!(o.place&&$t.includes(o.type))&&!s)return o;let a=this.measure(()=>this.build(o,n,r,t.scope,!1));if(!a)return o;let[i,l]=[0,0],c=o.place&&this.named.get(St(o.place.to,t.scope));if(o.place&&c&&([i,l]=an(a,this.boxOf(c.els,c.dx,c.dy),o.place.side,o.place.gap,o.place.align),i+=t.nudge?.[0]??0,l+=t.nudge?.[1]??0),s){let h={...a,x:a.x+i,y:a.y+l},[u,d]=cn(h,this.paper.w,this.paper.h);i+=u,l+=d,(o.type==="text"||o.type==="counter")&&(l+=mr({...h,x:h.x+u,y:h.y+d},this.textBoxes,this.paper.h))}return i||l?zt(o,i,l):o}arrange(t,n,r){let o=t.step,s=o.steps.flatMap((h,u)=>Tt(h,t.scope,[...t.path,u])),a=s.map(h=>this.measure(()=>this.build(h.step,[n,...h.path].join("_"),this.seedOf(n,h.path),h.scope,!1))??{x:0,y:0,w:0,h:0}),i=dr(o.type,a,this.pt(o.at,t.scope),o.gap??24,o.type==="grid"?"center":o.align??"center",o.type==="grid"?o.columns:1),l=[],c=this.made(()=>{l=s.flatMap((h,u)=>this.buildLeaf({...h,step:zt(h.step,...i[u]),arranged:!0},n,r))});if(t.id&&c.length){let h=this.boxOf(c,0,0);this.named.set(t.id,{els:c,anchor:dn(h),dx:0,dy:0})}return l}chain(t,n,r){let o=t.step,a=o.steps.map(g=>o.size!==void 0&&g.type==="prop"&&g.size===void 0?{...g,size:o.size}:g).flatMap((g,f)=>Tt(g,t.scope,[...t.path,f])),i=a.map(g=>this.measure(()=>this.build(g.step,[n,...g.path].join("_"),this.seedOf(n,g.path),g.scope,!1))??{x:0,y:0,w:0,h:0}),l=o.direction==="down",{deltas:c,lines:h}=pr(i,this.pt(o.at,t.scope),this.paper,{gap:o.gap,direction:o.direction,wrap:o.wrap}),u=i.map((g,f)=>({...g,x:g.x+c[f][0],y:g.y+c[f][1]})),d=this.roughOpts(o.style,this.seedOf(n,[...t.path,99])),p=[],m=this.made(()=>{p=a.flatMap((y,w)=>this.buildLeaf({...y,step:zt(y.step,...c[w]),arranged:!0},n,r));let g={...o.style,color:o.style?.color??"#8C8578"};h.forEach((y,w)=>{y.slice(1).forEach(M=>p.push(...this.arrow(...rn(u[M-1],u[M]),{...d,seed:d.seed+M},g,r)));let k=h[w+1];if(!k)return;let v=fr(u[y[y.length-1]],u[k[0]],l);p.push(...this.addDrawable(this.gen.linearPath(v.slice(0,-1),{...d,seed:d.seed+50+w}),g,r)),p.push(...this.arrow(v[v.length-2],v[v.length-1],{...d,seed:d.seed+60+w},g,r))});let f={x:Math.min(...u.map(y=>y.x)),y:Math.min(...u.map(y=>y.y)),w:0,h:0};f.w=Math.max(...u.map(y=>y.x+y.w))-f.x,f.h=Math.max(...u.map(y=>y.y+y.h))-f.y;let b=(y,w,k,v)=>{let M=34+w*70,[S,R]=l?[[f.x+f.w+M,f.y],[f.x+f.w+M,f.y+f.h]]:[[f.x,f.y+f.h+M],[f.x+f.w,f.y+f.h+M]],C={...o.style,color:k,width:3};p.push(...this.arrow(v?R:S,v?S:R,{...this.roughOpts(C,d.seed+80+w)},C,r));let L=l?{type:"text",at:[S[0]+14,(S[1]+R[1])/2],text:y,size:24,anchor:"start",style:{color:k}}:{type:"text",at:[(S[0]+R[0])/2,S[1]+32],text:y,size:24,anchor:"middle",style:{color:k}};p.push(this.addText(L,`${n}-chain-${w}`,t.scope,r))};o.forward&&b(o.forward,0,"#2E8F62",!1),o.back&&b(o.back,o.forward?1:0,"#2F5BEA",!0)});if(t.id&&m.length){let g=this.boxOf(m,0,0);this.named.set(t.id,{els:m,anchor:dn(g),dx:0,dy:0})}return p}animate(t,n){let r=St(t.target,n),o=this.named.get(r);if(!o)return;let s=o.els.map(h=>h.querySelector("[data-body]")??h);this.steam.get(r)?.remove(),this.steam.delete(r);for(let h of s)delete h.dataset.anim,h.style.animation="";if(t.effect==="stop")return;let a=t.speed==="slow"?1.6:t.speed==="fast"?.6:1,i=(h,u,d=0)=>{let[p,m]=jo[u];h.dataset.anim=u,h.dataset.animStart=String(performance.now()-d);let g=this.motion==="rest"?-(u==="wisp"?p*a*.3:0):this.css?this.beatAt+d:-d;h.style.animation=`ct-${u} ${Math.round(p*a)}ms ${m} ${Math.round(g)}ms infinite`,this.motion==="rest"&&(h.style.animationPlayState="paused")};if(t.effect!=="steam"){for(let h of s)i(h,t.effect);return}let l=this.boxOf(o.els,o.dx,o.dy),c=_("g");c.dataset.steam=r,[-.18,0,.18].forEach((h,u)=>{let d=l.x+l.w*(.5+h),p=_("path",{d:`M${d} ${l.y-4} q 6 -9 0 -18 q -6 -9 0 -18`,fill:"none",stroke:"#8C8578","stroke-width":2,"stroke-linecap":"round"});c.append(p),i(p,"wisp",u*700)}),this.layers.ink.append(c),this.steam.set(r,c)}lottie(t,n,r,o){let[s,a]=this.pt(t.at,r),i=t.size===void 0?120:B(t.size,r),[l,c]=[s-i/2,a-i/2],h=_("g");h.dataset.lottie=t.src,this.layers.ink.append(h),h.append(_("rect",{x:l,y:c,width:i,height:i,fill:"none",stroke:"none","data-box":1}));let u=this.lotties[t.src];if(u&&pn){let d=_("g");h.append(d);let p=pn.loadAnimation({container:d,renderer:"svg",loop:t.loop??!0,autoplay:this.motion==="run"&&!this.css,animationData:JSON.parse(JSON.stringify(u))}),m=d.querySelector("svg");if(m)for(let[g,f]of Object.entries({x:l,y:c,width:i,height:i}))m.setAttribute(g,String(f));(this.motion==="rest"||this.css)&&p.goToAndStop(Math.floor(p.totalFrames/2),!0),this.playing.push(p)}else{let d=this.roughOpts({color:"#8C8578",dashed:!0},Number(n.split("_")[0])*7+3);h.append(...this.made(()=>this.addDrawable(this.gen.rectangle(l,c,i,i,d),{color:"#8C8578",dashed:!0},!1))),this.addText({type:"text",at:[s,a+8],text:`\u25B6 ${t.src}`,size:20,anchor:"middle",style:{color:"#8C8578"}},`${n}-lottie`,r,!1,h)}return o&&(h.style.opacity="0"),[{kind:"fade",el:h,opacity:1}]}boxOf(t,n,r){let o=t.map(c=>c.getBBox()),s=Math.min(...o.map(c=>c.x)),a=Math.min(...o.map(c=>c.y)),i=Math.max(...o.map(c=>c.x+c.width))-s,l=Math.max(...o.map(c=>c.y+c.height))-a;return{x:s+n,y:a+r,w:i,h:l}}place(t,n,r){for(let o of t.els)o.dataset.base===void 0&&(o.dataset.base=o.getAttribute("transform")??""),o.setAttribute("transform",`translate(${n} ${r}) ${o.dataset.base}`.trim()),o.dataset.dx=String(n),o.dataset.dy=String(r)}makePencil(){let t=_("g",{"aria-hidden":"true",class:"dw-pencil"});t.style.opacity="0",t.style.transition="opacity .25s",t.style.pointerEvents="none";let n=_("g",{transform:"translate(-3,-46) scale(1.15)"});return n.append(_("path",{d:"M3 40 L 8 28 L 33 3 L 41 11 L 16 36 Z",fill:"#FFD25E",stroke:bt,"stroke-width":2,"stroke-linejoin":"round"}),_("path",{d:"M3 40 L 8 28 L 16 36 Z",fill:"#F1D9B5",stroke:bt,"stroke-width":2,"stroke-linejoin":"round"}),_("path",{d:"M3 40 L 5.3 34.4 L 8.6 37.7 Z",fill:bt}),_("path",{d:"M29 7 L 37 15",stroke:bt,"stroke-width":2})),t.append(n),t}roughOpts(t,n){return{stroke:t?.color??bt,strokeWidth:t?.width??2.6,roughness:t?.roughness??1.6,bowing:t?.bowing??1.4,fill:t?.fill,fillStyle:t?.fillStyle??"hachure",hachureGap:7,seed:n}}tint(t){return t&&this.theme==="chalkboard"?To[t.toLowerCase()]??t:t}pt(t,n){return[B(t[0],n),B(t[1],n)]}build(t,n,r,o,s){let a=this.roughOpts(t.style,r),i=this.gen,l=c=>this.pt(c,o);switch(t.type){case"card":{let[c,h]=l(t.at),u=B(t.w,o),d=B(t.h,o),p=t.lines??[];if(u<40||d<70+p.length*28)throw new Error(`Card "${t.title}": not enough room for its content.`);let m=this.addDrawable(i.rectangle(c,h,u,d,a),t.style,s);return[t.title,...p].forEach((f,b)=>{let y=this.addText({type:"text",at:[c+u/2,h+38+b*28],text:f,size:b===0?30:22,anchor:"middle",style:{color:t.style?.color}},`${n}-${b}`,o,s);if(y.width>u-24)throw new Error(`Card "${t.title}": text too wide; raise w or shorten the line.`);m.push(y)}),m}case"line":return this.addDrawable(i.line(...l(t.from),...l(t.to),a),t.style,s);case"arrow":return this.arrow(l(t.from),l(t.to),a,t.style,s);case"polyline":return this.addDrawable(i.linearPath(t.points.map(l),a),t.style,s);case"polygon":return this.addDrawable(i.polygon(t.points.map(l),a),t.style,s);case"curve":return this.addDrawable(i.curve(t.points.map(l),a),t.style,s);case"circle":{let[c,h]=l(t.center);return this.addDrawable(i.circle(c,h,B(t.r,o)*2,a),t.style,s)}case"ellipse":{let[c,h]=l(t.center);return this.addDrawable(i.ellipse(c,h,B(t.rx,o)*2,B(t.ry,o)*2,a),t.style,s)}case"plot":return this.addDrawable(i.curve(this.samplePlot(t,o),a),t.style,s);case"highlight":{let[c,h]=l(t.from),[u,d]=l(t.to),p=_("path",{d:`M${c} ${h} L${u} ${d}`,stroke:this.theme==="chalkboard"&&!t.style?.color?"#7C6E26":this.tint(t.style?.color??"#FFE45C")??"#FFE45C","stroke-width":t.thickness??18,"stroke-linecap":"round",fill:"none",opacity:t.style?.opacity??.8});return p.dataset.marker="1",this.layers.highlight.append(p),[this.hide(p,s)]}case"text":return[this.addText(t,n,o,s)];case"pause":case"repeat":case"when":case"row":case"column":case"grid":case"chain":return[];case"axis":case"timeline":return this.line(t,n,a,o,s);case"balloon":return this.balloon(t,n,a,o,s);case"brace":return this.brace(t,n,a,o,s);case"note":return this.note(t,n,a,o,s);case"table":return this.table(t,n,a,o,s);case"bars":return this.bars(t,n,a,o,s);case"prop":return this.prop(t,n,a,o,s);case"counter":{let[c,h]=l(t.at),u=B(t.value,o),d=_("g"),p=_("text",{x:c,y:h,fill:this.tint(t.style?.color??bt)??bt,"font-family":un.hand,"font-size":t.size??34,"font-weight":700,"text-anchor":t.anchor??"start"});return p.textContent=ve(t.format,s?0:u,o,this.locale),d.append(p),this.layers.ink.append(d),[{kind:"count",el:p,format:t.format,value:u,scope:o,locale:this.locale}]}case"link":{let[c,h]=[this.named.get(St(t.from,o)),this.named.get(St(t.to,o))];if(!c||!h)return[];let[u,d]=rn(this.boxOf(c.els,c.dx,c.dy),this.boxOf(h.els,h.dx,h.dy)),p=this.arrow(u,d,a,t.style,s);if(t.label){let m=ur(u,d);p.push(this.addText({type:"text",at:m.at,text:t.label,size:22,anchor:m.anchor,style:{color:t.style?.color}},`${n}-label`,o,s))}return p}case"animate":return this.animate(t,o),[];case"lottie":return this.lottie(t,n,o,s);case"move":{let c=this.named.get(St(t.target,o));if(!c)return[];let[h,u]=l(t.to),d=[c.dx,c.dy],p=[h-c.anchor[0],u-c.anchor[1]];return[c.dx,c.dy]=p,s?[{kind:"move",entry:c,from:d,to:p,along:t.along??"line",ms:t.ms}]:(this.place(c,...p),this.css?[{kind:"move",entry:c,from:d,to:p,along:t.along??"line",ms:t.ms}]:[])}}}line(t,n,r,o,s){let[a,i]=[this.pt(t.from,o),this.pt(t.to,o)],l=[B(t.domain[0],o),B(t.domain[1],o)];if(l[0]===l[1])throw new Error(`${t.type==="axis"?"Axis":"Timeline"}: the domain needs two different ends.`);let c=hn(a,i),h=Math.abs(i[0]-a[0])>=Math.abs(i[1]-a[1]),u=t.style?.color,d=(f,b,y,w=22,k=h?"middle":c[0]<0?"end":"start",v="hand")=>this.addText({type:"text",at:f,text:b,size:w,anchor:k,font:v,style:{color:u}},`${n}-${y}`,o,s),p=(f,b,y)=>this.addDrawable(this.gen.line(f[0]-c[0]*y,f[1]-c[1]*y,f[0]+c[0]*y,f[1]+c[1]*y,{...r,seed:r.seed+10+b}),t.style,s),m=(f,b)=>[f[0]+c[0]*b,f[1]+c[1]*b+(h?c[1]>0?8:-2:7)];if(t.type==="axis"){let f=this.arrow(a,i,r,t.style,s);return gr(l,t.ticks).forEach((b,y)=>{let w=ln(a,i,l,b);w&&f.push(...p(w,y,7),d(m(w,22),nt(t.format??"{v}",{...o,v:b},this.locale),`t${y}`))}),t.label&&f.push(d(h?[i[0],i[1]+c[1]*56+8]:[i[0],i[1]-22],t.label,"label",24,h?"end":"middle")),f}let g=this.addDrawable(this.gen.line(...a,...i,r),t.style,s);return t.marks.forEach((f,b)=>{let y=ln(a,i,l,B(f.at,o));y&&(g.push(...p(y,b,10)),f.label&&g.push(d(m(y,-26),f.label,`l${b}`,26,h?"middle":c[0]<0?"start":"end")),f.text&&g.push(d(m(y,30),f.text,`x${b}`,21)))}),g}arrow(t,n,r,o,s){return[...this.addDrawable(this.gen.line(...t,...n,r),o,s),...this.head(t,n,r,o,s)]}head(t,n,r,o,s){let a=Math.atan2(n[1]-t[1],n[0]-t[0]),i=16,l=[n[0]-i*Math.cos(a-.45),n[1]-i*Math.sin(a-.45)],c=[n[0]-i*Math.cos(a+.45),n[1]-i*Math.sin(a+.45)];return this.addDrawable(this.gen.linearPath([l,n,c],{...r,seed:r.seed+1}),o,s)}textWidth(t,n,r,o=r==="body"?400:700){let s=_("text",{"font-family":un[r],"font-size":n,"font-weight":o});s.textContent=t,this.layers.ink.append(s);let a=s.getComputedTextLength();return s.remove(),a}wrap(t,n,r){let o=[];for(let s of t.split(/\s+/).filter(Boolean)){let a=o.at(-1);a!==void 0&&this.textWidth(`${a} ${s}`,n,"hand")<=r?o[o.length-1]=`${a} ${s}`:o.push(s)}return o}balloon(t,n,r,o,s){let a=this.named.get(St(t.to,o));if(!a)return[];let i=this.boxOf(a.els,a.dx,a.dy),l=t.size??24,c=this.wrap(nt(t.text,o,this.locale),l,t.width??240),h=Math.max(...c.map(L=>this.textWidth(L,l,"hand")))+32,u=c.length*l*1.2+22,d=[t.side??"above","right","left","above","below"],p=(L,[D,I])=>L==="above"||L==="below"?[Math.max(30,Math.min(D,this.paper.w-30-h)),I]:[D,Math.max(30,Math.min(I,this.paper.h-30-u))],m=d.map(L=>p(L,an({x:0,y:0,w:h,h:u},i,L,28))),[g,f]=m.find(([L,D])=>L>=0&&D>=0&&L+h<=this.paper.w&&D+u<=this.paper.h)??m[0];g+=this.leafNudge?.[0]??0,f+=this.leafNudge?.[1]??0;let[b,y]=cn({x:g,y:f,w:h,h:u},this.paper.w,this.paper.h);[g,f]=[g+b,f+y];let w=16,k=`M${g+w} ${f} H${g+h-w} Q${g+h} ${f} ${g+h} ${f+w} V${f+u-w} Q${g+h} ${f+u} ${g+h-w} ${f+u} H${g+w} Q${g} ${f+u} ${g} ${f+u-w} V${f+w} Q${g} ${f} ${g+w} ${f} Z`,v={...r,fill:t.style?.fill??"#FFFFFF",fillStyle:"solid",roughness:Math.min(r.roughness??1.6,1)},M=this.addDrawable(this.gen.path(k,v),t.style,s),S=[g+h/2,f+u/2],R=Yt(i,S,6),C=Yt({x:g,y:f,w:h,h:u},R,0);if(t.kind==="thought")for(let[L,D,I]of[[.35,7,2],[.7,4,3]]){let W=[C[0]+(R[0]-C[0])*L,C[1]+(R[1]-C[1])*L];M.push(...this.addDrawable(this.gen.circle(W[0],W[1],D*2,{...v,seed:r.seed+I}),t.style,s))}else{let L=Math.abs(C[0]-S[0])*u>Math.abs(C[1]-S[1])*h?[0,1]:[1,0],D=[C[0]-L[0]*10,C[1]-L[1]*10],I=[C[0]+L[0]*10,C[1]+L[1]*10];M.push(...this.addDrawable(this.gen.polygon([D,R,I],{...v,seed:r.seed+2}),t.style,s))}return c.forEach((L,D)=>{M.push(this.addText({type:"text",at:[S[0],f+11+l*1.2*(D+1)-l*.25],text:L,size:l,anchor:"middle",style:{color:t.style?.color}},`${n}-${D}`,o,s))}),M}brace(t,n,r,o,s){let[a,i]=[this.pt(t.from,o),this.pt(t.to,o)],l=hn(a,i),c=t.flip?[-l[0],-l[1]]:l,h=Math.hypot(i[0]-a[0],i[1]-a[1])||1,u=[(i[0]-a[0])/h,(i[1]-a[1])/h],d=Math.min(16,h*.08),p=(g,f)=>[a[0]+u[0]*h*g+c[0]*f,a[1]+u[1]*h*g+c[1]*f],m=this.addDrawable(this.gen.curve([a,p(.06,d),p(.44,d),p(.5,d*2),p(.56,d),p(.94,d),i],r),t.style,s);if(t.label){let g=Math.abs(u[0])>=Math.abs(u[1]),f=p(.5,d*2+22),b=g?"middle":c[0]<0?"end":"start";m.push(this.addText({type:"text",at:[f[0],f[1]+(g?c[1]>0?8:-2:7)],text:t.label,size:24,anchor:b,style:{color:t.style?.color}},`${n}-label`,o,s))}return m}note(t,n,r,o,s){let a=t.style?.color??"#2F5BEA",i=[],l=this.made(()=>{i.push(this.addText({type:"text",at:t.at,text:t.text,size:t.size??24,style:{color:a}},`${n}-text`,o,s))}),c=this.boxOf(l,0,0),h=t.to!==void 0?this.named.get(St(t.to,o)):void 0;if(t.to!==void 0&&!h)return i;let u=h?this.boxOf(h.els,h.dx,h.dy):null,d=u?[u.x+u.w/2,u.y+u.h/2]:this.pt(t.point,o),[p,m]=[c.x+c.w/2,c.y+c.h/2],g=d[1]>c.y+c.h,f=d[1]<c.y,b=g?[p,c.y+c.h+6]:f?[p,c.y-6]:d[0]>p?[c.x+c.w+8,m]:[c.x-8,m],y=u?Yt(u,b,8):d,[w,k]=[(b[0]+y[0])/2,(b[1]+y[1])/2],v=Math.hypot(y[0]-b[0],y[1]-b[1])||1,M=I=>[w-(y[1]-b[1])/v*v*.22*I,k+(y[0]-b[0])/v*v*.22*I],[S,R]=[c.x+c.w/2,c.y+c.h/2],C=I=>Math.hypot(I[0]-S,I[1]-R),L=C(M(1))>=C(M(-1))?M(1):M(-1),D={...r,stroke:a};return i.push(...this.addDrawable(this.gen.curve([b,L,y],D),{...t.style,color:a},s),...this.head(L,y,D,{...t.style,color:a},s)),i}table(t,n,r,o,s){let[a,i]=this.pt(t.at,o),l=t.size??22,c=t.header??!0,h=t.rows.map(k=>k.map(v=>nt(v,o,this.locale))),u=Math.max(...h.map(k=>k.length)),d=k=>c&&k===0?"hand":"body",p=Array.from({length:u},(k,v)=>Math.max(40,...h.map((M,S)=>M[v]?this.textWidth(M[v],l,d(S)):0))+28),m=l*1.7,[g,f]=[p.reduce((k,v)=>k+v,0),m*h.length],b=this.addDrawable(this.gen.rectangle(a,i,g,f,r),t.style,s),y=r.seed+3;for(let k=1;k<h.length;k++)b.push(...this.addDrawable(this.gen.line(a,i+m*k,a+g,i+m*k,{...r,seed:y++,strokeWidth:c&&k===1?2.6:1.4}),t.style,s));let w=a;return p.slice(0,-1).forEach(k=>{w+=k,b.push(...this.addDrawable(this.gen.line(w,i,w,i+f,{...r,seed:y++,strokeWidth:1.4}),t.style,s))}),h.forEach((k,v)=>{let M=a;k.forEach((S,R)=>{S&&b.push(this.addText({type:"text",at:[M+p[R]/2,i+m*v+m*.66],text:S,size:l,font:d(v),anchor:"middle",style:{color:t.style?.color}},`${n}-${v}-${R}`,{},s)),M+=p[R]})}),b}bars(t,n,r,o,s){let[a,i,l,c]=[B(t.box.x,o),B(t.box.y,o),B(t.box.w,o),B(t.box.h,o)],h=t.values.map(f=>B(f,o)),u=()=>this.scene?Ct(this.scene).flatMap(f=>{let b={...o,...Mt(this.scene,f)};return t.values.map(y=>{try{return B(y,b)}catch{return 0}})}):h,d=t.max!==void 0?B(t.max,o):Math.max(...h,...u(),0)||1,p=l/h.length,m=t.style?.fill??"#2F5BEA",g=this.addDrawable(this.gen.line(a,i+c,a+l,i+c,r),t.style,s);return h.forEach((f,b)=>{let y=Math.max(0,Math.min(c,f/d*c)),w=a+p*b+p/2;y>=1&&g.push(...this.addDrawable(this.gen.rectangle(w-p*.3,i+c-y,p*.6,y,{...r,fill:m,fillStyle:t.style?.fillStyle??"hachure",seed:r.seed+5+b}),{...t.style,fill:m},s)),g.push(this.addText({type:"text",at:[w,i+c-y-10],text:nt(t.format??"{v}",{...o,v:f},this.locale),size:22,anchor:"middle",style:{color:t.style?.color}},`${n}-v${b}`,o,s));let k=t.labels?.[b];k&&g.push(this.addText({type:"text",at:[w,i+c+30],text:k,size:22,anchor:"middle",style:{color:t.style?.color}},`${n}-l${b}`,o,s))}),g}prop(t,n,r,o,s){let[a,i]=this.pt(t.at,o),l=t.size===void 0?tn:B(t.size,o),c=_("g");c.dataset.prop=t.name,this.layers.ink.append(c);let h=_("g");h.dataset.body="1",c.append(h);let u=t.style?.width??Math.max(1.2,Math.min(2.6,l/36)),d=[];return tr(t.name,[a,i],l,t.flip??!1,t.mood,this.figures).forEach((p,m)=>{let g=p.kind!=="circle"&&p.kind!=="polygon"?void 0:p.main&&t.style?.fill?t.style.fill:p.fill,f=p.fine?{...r,strokeWidth:Math.max(.8,u*.45),roughness:.3,bowing:0,fill:g,fillStyle:"solid",seed:r.seed+m}:{...r,strokeWidth:u,fill:g,fillStyle:t.style?.fillStyle??"solid",seed:r.seed+m},b=p.kind==="circle"?this.gen.circle(p.c[0],p.c[1],p.r*2,f):p.kind==="polygon"?this.gen.polygon(p.points,f):p.kind==="curve"?this.gen.curve(p.points,f):this.gen.linearPath(p.points,f);d.push(...this.addDrawable(b,{opacity:t.style?.opacity,dashed:t.style?.dashed},s,h))}),t.label&&d.push(this.addText({type:"text",at:[a,i+28],text:t.label,size:22,anchor:"middle",style:{color:t.style?.color}},`${n}-label`,o,s,c)),d}samplePlot(t,n){let r=t.var??"x",[o,s]=[B(t.domain[0],n),B(t.domain[1],n)],[a,i]=[B(t.range[0],n),B(t.range[1],n)];if(o===s||a===i)throw new Error("Plot: domain and range need different ends.");let l=B(t.box.x,n),c=B(t.box.y,n),h=B(t.box.w,n),u=B(t.box.h,n),d=t.samples??40,p=[];for(let m=0;m<=d;m++){let g=o+(s-o)*m/d,f=B(t.fn,{...n,[r]:g}),b=c+u-(f-a)/(i-a)*u;p.push([l+(g-o)/(s-o)*h,Math.max(c,Math.min(c+u,b))])}return p}addDrawable(t,n,r,o=this.layers.ink){let s=[];return this.gen.toPaths(t).forEach(a=>{let i=_("path",{d:a.d,stroke:this.tint(a.stroke)??"none","stroke-width":a.strokeWidth,fill:this.tint(a.fill)??"none","stroke-linecap":"round","stroke-linejoin":"round"});n?.opacity!==void 0&&i.setAttribute("opacity",String(n.opacity)),n?.fill&&a.stroke===n.fill&&(a.fill??"none")==="none"&&(i.dataset.hatch="1"),o.append(i),a.fill&&a.fill!=="none"?(r&&(i.style.opacity="0"),s.push({kind:"fade",el:i,opacity:n?.opacity??1})):(s.push(this.hide(i,r)),n?.dashed&&(i.dataset.dashed="1"),n?.dashed&&!r&&i.setAttribute("stroke-dasharray","9 8"))}),s}hide(t,n){let r=t.getTotalLength();return n&&(t.style.strokeDasharray=`${r} ${r}`,t.style.strokeDashoffset=`${r}`),{kind:"path",el:t,length:r}}addText(t,n,r,o,s=this.layers.ink){let[a,i]=this.pt(t.at,r),l=t.rotate??0,c=_("g",l?{transform:`rotate(${l} ${a} ${i})`}:{}),h=_("text",{x:a,y:i,fill:this.tint(t.style?.color??bt)??bt,"font-family":un[t.font??"hand"],"font-size":t.size??30,"font-weight":t.font==="body"?400:700,"text-anchor":t.anchor??"start"});h.textContent=nt(t.text,r,this.locale),c.append(h),s.append(c);let u=h.getBBox(),d=`${this.uid}-clip-${this.run}-${n}`,p=_("clipPath",{id:d}),m=_("rect",{x:u.x-4,y:u.y-12,width:o?0:u.width+8,height:u.height+24});return p.append(m),this.defs.append(p),h.setAttribute("clip-path",`url(#${d})`),{kind:"text",clip:m,width:u.width+8,x:u.x-4,y:i+2,angle:l,ox:a,oy:i}}play(t,n,r){let o=t.find(s=>s.kind==="text")??t.find(s=>s.kind==="path");return this.layers.pencil.style.opacity=o?"1":"0",this.tween(n,r,s=>{for(let a of t)if(a.kind==="path")this.revealPath(a,s,a===o);else if(a.kind==="text")this.revealText(a,s,a===o);else if(a.kind==="count")a.el.textContent=ve(a.format,s===1?a.value:sn(a.value,s),a.scope,a.locale);else if(a.kind==="move"){let i=a.ms?Math.min(1,s*n/a.ms):s;this.place(a.entry,...on(a.from,a.to,i,a.along))}else a.el.style.opacity=String(s*a.opacity)})}revealPath(t,n,r){let o=t.length*n;if(t.el.style.strokeDashoffset=String(t.length-o),r){let s=t.el.getPointAtLength(o);this.layers.pencil.setAttribute("transform",`translate(${s.x} ${s.y})`)}n===1&&(t.el.style.strokeDasharray="",t.el.style.strokeDashoffset="",t.el.dataset.dashed&&t.el.setAttribute("stroke-dasharray","9 8"))}revealText(t,n,r){let o=t.width*n;if(t.clip.setAttribute("width",String(o)),!r)return;let s=this.layers.pencil,a=t.angle*Math.PI/180,i=t.x+o-t.ox,l=t.y-t.oy,c=t.ox+i*Math.cos(a)-l*Math.sin(a),h=t.oy+i*Math.sin(a)+l*Math.cos(a);s.setAttribute("transform",`translate(${c} ${h-6-Math.abs(Math.sin(n*40))*7})`)}schedule(t,n,r){if(r<=0)return;let o=(s,a,i=r,l=n,c=Bo,h="backwards")=>{s.style.animation=`${a} ${Math.round(i)}ms ${c} ${Math.round(l)}ms ${h}`};for(let s of t)if(s.kind==="path")s.el.style.setProperty("--l",String(Math.ceil(s.length)+1)),o(s.el,"ct-draw");else if(s.kind==="text")s.clip.style.transformBox="fill-box",s.clip.style.transformOrigin="0 0",o(s.clip,"ct-write");else if(s.kind==="fade")o(s.el,"ct-fade");else if(s.kind==="count"){let i=r/12;for(let l=0;l<12;l++){let c=s.el.cloneNode();c.textContent=ve(s.format,sn(s.value,br(l/12)),s.scope,s.locale),c.style.opacity="0",o(c,"ct-show",i,n+l*i,"step-end","none"),s.el.before(c)}o(s.el,"ct-wait",n+r,0,"step-end")}else if(s.kind==="move"){let a=on(s.from,s.to,.5,s.along);for(let i of s.entry.els){let l=_("g");i.replaceWith(l),l.append(i),l.style.setProperty("--fx",`${s.from[0]-s.to[0]}px`),l.style.setProperty("--fy",`${s.from[1]-s.to[1]}px`),l.style.setProperty("--mx",`${a[0]-s.to[0]}px`),l.style.setProperty("--my",`${a[1]-s.to[1]}px`),o(l,"ct-move",s.ms??r)}}}tween(t,n,r){return new Promise((o,s)=>{let a=performance.now(),i=0,l=c=>{if(n!==this.run)return s(new Vt);i+=(c-a)*this.speed,a=c;let h=Math.min(1,i/Math.max(1,t));r(h===1?1:br(h)),h<1?requestAnimationFrame(l):o()};requestAnimationFrame(l)})}};function Do(e){let t=([n,r])=>[(n-50)/100,(r-100)/100];return Object.fromEntries(Object.entries(e??{}).map(([n,r])=>[n,r.shapes.map((o,s)=>o.kind==="circle"?{kind:"circle",c:t(o.c),r:o.r/100,fill:o.fill,main:s===0}:o.kind==="polygon"?{kind:"polygon",points:o.points.map(t),fill:o.fill,main:s===0}:{kind:o.kind,points:o.points.map(t)})]))}var j=class extends Error{constructor(n,r){super(`line ${n}: ${r}`);q(this,"line");this.line=n}};function Fo(e,t){let n=[],r="",o=!1;for(let s=0;s<e.length;s++){let a=e[s];if(a==="\\"&&o&&s+1<e.length){r+=a+e[++s];continue}a==='"'&&(o=!o),/\s/.test(a)&&!o?(r&&n.push(r),r=""):r+=a}if(o)throw new j(t,"a quote is not closed.");return r&&n.push(r),n}function _o(e){let t={no:0,indent:-1,tokens:[],children:[]},n=[t];return e.split(/\r?\n/).forEach((r,o)=>{let s=o+1;if(!r.trim()||r.trim().startsWith("//"))return;let a=r.length-r.trimStart().length,i=r.trim(),l=i.startsWith("#")?["#",i.slice(1).trim()]:i.startsWith(">")?[">",i.slice(1).trim()]:i.startsWith("json ")?["json",i.slice(5).trim()]:i.startsWith("|")?["|",i]:Fo(i,s),c={no:s,indent:a,tokens:l,children:[]};for(;n.length>1&&n[n.length-1].indent>=a;)n.pop();n[n.length-1].children.push(c),n.push(c)}),t.children}var ct=e=>e.length>=2&&e.startsWith('"')&&e.endsWith('"'),Z=e=>ct(e)?e.slice(1,-1).replace(/\\(.)/g,"$1"):e,mn=/^-?\d+(\.\d+)?$/;function lt(e,t){if(mn.test(e))return Number(e);if(ct(e))return Z(e);if(/^[A-Za-z_][A-Za-z_0-9]*$/.test(e))return e;throw new j(t,`expected a number or an expression in quotes, got ${e}.`)}function Rt(e){let t=[],n="",r=!1;for(let o of e)o==='"'&&(r=!r),o===","&&!r?(t.push(n),n=""):n+=o;return t.push(n),t}function Bt(e,t){let n=e?Rt(e):[];if(n.length!==2)throw new j(t,`expected a point x,y, got ${e??"nothing"}.`);return[lt(n[0],t),lt(n[1],t)]}function Se(e,t){let n=e?.match(/^(.+?)\.\.(.+)$/);if(!n)throw new j(t,`expected a range a..b, got ${e??"nothing"}.`);return[lt(n[1],t),lt(n[2],t)]}var qo=new Set(["text","card","line","arrow","highlight","polyline","polygon","curve","circle","ellipse","plot","pause","row","column","grid","repeat","when","move","counter","axis","timeline","brace","note","table","bars","json","chain","animate","lottie"]),fn={"right-of":"right","left-of":"left",above:"above",below:"below"},Go=["color","fill","roughness","bowing","fillStyle","opacity"],xr=new Set(["gap","size","r","rx","ry","w","h","columns","ms","thickness"]),kr=new Set(["dashed","flip","noheader","wrap"]);function Q(e,t,n){let r={};for(let o=0;o<e.length;o++){let s=e[o],a,i;if(kr.has(s)){s==="dashed"?r.dashed=!0:s==="flip"?t.flip=!0:s==="wrap"?t.wrap=!0:t.header=!1;continue}let l=s.indexOf("=");if(l>0&&!ct(s))[a,i]=[s.slice(0,l),s.slice(l+1)];else if(xr.has(s)&&o+1<e.length)[a,i]=[s,e[++o]];else throw new j(n,`did not understand \xAB${s}\xBB.`);a==="stroke"?r.width=Number(i):Go.includes(a)?r[a]=mn.test(i)?Number(i):Z(i):a==="nudge"?t.nudge=Bt(i,n).map(Number):a==="ticks"?t.ticks=i.includes(",")?Rt(i).map(Number):Number(i):a==="labels"?t.labels=Rt(i).map(Z):a==="id"||a==="anchor"||a==="font"||a==="mood"||a==="along"||a==="side"||a==="kind"||a==="var"||a==="align"||a==="label"||a==="format"||a==="fn"||a==="forward"||a==="back"||a==="direction"?t[a]=Z(i):t[a]=lt(i,n)}return Object.keys(r).length&&(t.style=r),t}function yt(e,t,n,r){let[o,s]=e;if(o==="at")return t[n]=Bt(s,r),e.slice(2);if(o in fn){if(!s||ct(s))throw new j(r,`${o} needs the id of an earlier step.`);t.place={to:s,side:fn[o]};let a=e.slice(2);if(a[0]==="gap"||a[0]?.startsWith("gap=")){let l=a[0]==="gap"?a[1]:a[0].slice(4);t.place.gap=Number(l),a=a.slice(a[0]==="gap"?2:1)}let i=a.findIndex(l=>l.startsWith("align="));return i>=0&&(t.place.align=a[i].slice(6),a=a.filter((l,c)=>c!==i)),a}return e}function Me(e,t){let{no:n,tokens:r}=e,[o,...s]=r,a=()=>e.children.map(c=>Me(c,t)),i=(c,h)=>{if(!c||!ct(c))throw new j(n,`${o} needs ${h} in quotes.`);return Z(c)},l=c=>{if(s[1]!=="->")throw new j(n,`write ${c} x,y -> x,y.`);return{type:c,from:Bt(s[0],n),to:Bt(s[2],n)}};if(o==="json")try{return JSON.parse(s[0])}catch{throw new j(n,"the JSON on this line is not valid.")}if(s[0]==="->"&&!qo.has(o)&&!t.has(o)){let c={type:"link",from:o,to:s[1]},h=s.slice(2);return h[0]&&ct(h[0])&&([c.label,h]=[Z(h[0]),h.slice(1)]),Q(h,c,n)}if(s[0]==="says"||s[0]==="thinks"){let c={type:"balloon",to:o,text:i(s[1],"what is said"),...s[0]==="thinks"?{kind:"thought"}:{}};return Q(s.slice(2),c,n)}if(t.has(o)){let c={type:"prop",name:o},h=s,u=h[0];return u&&!ct(u)&&!u.includes("=")&&u!=="at"&&!(u in fn)&&!xr.has(u)&&!kr.has(u)&&([c.id,h]=[u,h.slice(1)]),h=yt(h,c,"at",n),h[0]&&ct(h[0])&&([c.label,h]=[Z(h[0]),h.slice(1)]),Q(h,c,n)}switch(o){case"text":{let c={type:"text",text:i(s[0],"its text")};return Q(yt(s.slice(1),c,"at",n),c,n)}case"card":{let c={type:"card"},h=yt(s,c,"at",n),u=h.filter(ct).map(Z);if(h=h.filter(d=>!ct(d)),!u.length)throw new j(n,"a card needs a title in quotes.");return[c.title]=u,u.length>1&&(c.lines=u.slice(1)),Q(h,c,n)}case"line":case"arrow":case"highlight":return Q(s.slice(3),l(o),n);case"brace":{let c=l("brace"),h=s.slice(3);return h[0]&&ct(h[0])&&([c.label,h]=[Z(h[0]),h.slice(1)]),Q(h,c,n)}case"polyline":case"polygon":case"curve":{let c=s.filter(h=>/,/.test(h)&&!h.includes("="));return Q(s.slice(c.length),{type:o,points:c.map(h=>Bt(h,n))},n)}case"circle":case"ellipse":{let c={type:o};return Q(yt(s,c,"center",n),c,n)}case"plot":{let c={type:"plot",fn:i(s[0],"the formula")},h=[];for(let u=1;u<s.length;u++)if(s[u]==="domain")c.domain=Se(s[++u],n);else if(s[u]==="range")c.range=Se(s[++u],n);else if(s[u]==="box"){let d=Rt(s[++u]??"");if(d.length!==4)throw new j(n,"write box x,y,w,h.");let[p,m,g,f]=d.map(b=>lt(b,n));c.box={x:p,y:m,w:g,h:f}}else h.push(s[u]);return Q(h,c,n)}case"pause":{let c={type:"pause",ms:600},h=s;return h[0]&&mn.test(h[0])&&([c.ms,h]=[Number(h[0]),h.slice(1)]),h[0]==="ask"&&([c.ask,h]=[i(h[1],"the question"),h.slice(2)]),Q(h,c,n)}case"row":case"column":case"grid":case"chain":{let c={type:o},h=yt(s,c,"at",n);return Q(h,c,n),c.steps=a(),c}case"repeat":{let c=s[0]?.replace(/:$/,"");if(!c)throw new j(n,"write repeat n: <step>.");let h={type:"repeat",times:lt(c,n)},u=s.slice(1);if(u.length)h.step=Me({...e,tokens:u,children:[]},t);else if(e.children.length===1)[h.step]=a();else throw new j(n,"a repeat holds one step: on the same line after \xAB:\xBB, or one line under it.");return h}case"when":{let c=s[0]?.replace(/:$/,"");if(!c)throw new j(n,"write when <condition>:.");let h=s.slice(1);return{type:"when",if:lt(c,n),steps:h.length?[Me({...e,tokens:h,children:[]},t)]:a()}}case"lottie":{if(!s[0])throw new j(n,"write lottie <name> at x,y, or lottie ./file.json at x,y.");let c={type:"lottie",src:s[0]},h=s.slice(1);h[0]&&h[0]!=="at"&&!h[0].includes("=")&&([c.id,h]=[h[0],h.slice(1)]),h=yt(h,c,"at",n);for(let u of h){let[d,p]=u.split("=");if(d==="loop"&&(p==="true"||p==="false"))c.loop=p==="true";else if(d==="size"&&p)c.size=lt(p,n);else throw new j(n,`did not understand \xAB${u}\xBB (a lottie takes size=\u2026 and loop=false).`)}return c}case"animate":{if(!s[0]||!s[1]||s[1].includes("="))throw new j(n,"write animate <id> spin|drive|steam|talk|pulse|float, or animate <id> stop.");let c={type:"animate",target:s[0],effect:s[1]};for(let h of s.slice(2)){let[u,d]=h.split("=");if(u==="speed"&&d)c.speed=d;else throw new j(n,`did not understand \xAB${h}\xBB (an animate takes speed=slow or speed=fast).`)}return c}case"move":{if(s[1]!=="to")throw new j(n,"write move <id> to x,y.");return Q(s.slice(3),{type:"move",target:s[0],to:Bt(s[2],n)},n)}case"counter":{let c={type:"counter"},h=yt(s,c,"at",n);return c.value=lt(h[0]??"",n),h=h.slice(1),h[0]&&ct(h[0])&&([c.format,h]=[Z(h[0]),h.slice(1)]),Q(h,c,n)}case"axis":case"timeline":{let c=l(o),h=s.slice(3);if(h[0]!=="domain")throw new j(n,`write ${o} x,y -> x,y domain a..b.`);return c.domain=Se(h[1],n),h=h.slice(2),o==="timeline"&&(c.marks=e.children.map(u=>{let[d,p,m,g]=u.tokens;if(d!=="mark")throw new j(u.no,'under a timeline, write mark <when> "label" "text".');return{at:lt(p??"",u.no),...m?{label:Z(m)}:{},...g?{text:Z(g)}:{}}})),Q(h,c,n)}case"note":{let c={type:"note"},h=yt(s,c,"at",n);if(c.text=i(h[0],"its text"),h[1]!=="->")throw new j(n,'write note at x,y "text" -> <id or x,y>.');let u=h[2]??"";return/,/.test(u)?c.point=Bt(u,n):c.to=u,h=h.slice(3),Q(h,c,n)}case"table":{let c={type:"table"};return Q(yt(s,c,"at",n),c,n),c.rows=e.children.map(h=>{if(h.tokens[0]!=="|")throw new j(h.no,"under a table, write rows as | a | b |.");return h.tokens[1].replace(/^\||\|$/g,"").split("|").map(u=>u.trim())}),c}case"bars":{let c={type:"bars"},h=[];for(let u=0;u<s.length;u++)if(s[u]==="box"){let d=Rt(s[++u]??"");if(d.length!==4)throw new j(n,"write box x,y,w,h.");let[p,m,g,f]=d.map(b=>lt(b,n));c.box={x:p,y:m,w:g,h:f}}else s[u]==="values"?c.values=Rt(s[++u]??"").map(d=>lt(d,n)):s[u]==="labels"?c.labels=Rt(s[++u]??"").map(Z):h.push(s[u]);return Q(h,c,n)}}throw new j(n,`\xAB${o}\xBB is not a step, a prop or an id followed by -> / says.`)}function Xo(e){let{no:t,tokens:n}=e,r=[],o=n[0],s=1;for(;n[s]==="->";){let i=n[s+1];if(!i||ct(i))throw new j(t,'write a -> b "label" -> c "label".');let l={type:"link",from:o,to:i};s+=2,n[s]&&ct(n[s])&&(l.label=Z(n[s++])),r.push(l),o=i}let a=n.slice(s);return r.map(i=>Q([...a],i,t))}function Yo(e){let{no:t,tokens:n}=e,[r,...o]=n,s=l=>{let c=l?.match(/^(\d{1,3}),(\d{1,3})$/);if(!c||Number(c[1])>100||Number(c[2])>100)throw new j(t,`on a figure's grid a point is two whole numbers from 0 to 100, like 24,48 (got ${l??"nothing"}).`);return[Number(c[1]),Number(c[2])]},a={kind:r},i=o;if(r==="circle")i[0]==="at"&&(i=i.slice(1)),a.c=s(i[0]),i=i.slice(1);else if(r==="polygon"||r==="polyline"||r==="curve"){let l=i.filter(c=>c.includes(",")&&!c.includes("="));a.points=l.map(s),i=i.slice(l.length)}else throw new j(t,`a figure is made of polygon, polyline, curve and circle lines, not \xAB${r}\xBB.`);for(let l of i){let[c,h]=l.split("=");if(c==="fill"&&h)a.fill=Z(h);else if(c==="r"&&h&&/^\d{1,3}$/.test(h))a.r=Number(h);else throw new j(t,`did not understand \xAB${l}\xBB in a figure (only fill=\u2026 and, on a circle, r=\u2026).`)}return a}function vr(e,t){let n=new Set(t),r={id:"lesson",title:"",width:900,height:560},o=[],s,a;for(let i of _o(e)){let{no:l,tokens:c}=i,[h,...u]=c,d=f=>{if(!u[0])throw new j(l,`${h} needs ${f}.`);return Z(u.join(" "))};switch(!["->","says","thinks"].includes(u[0])?h:""){case"#":s=u[0];continue;case">":a=u[0];continue;case"title":r.title=d("a title");continue;case"id":r.id=d("an id");continue;case"category":r.category=d("a category");continue;case"theme":r.theme=d("paper or chalkboard");continue;case"locale":r.locale=d("a language tag");continue;case"kind":r.kind=d("what the drawing is for");continue;case"source":r.source=d("where the numbers come from");continue;case"background":r.background=d("dots, grid or plain");continue;case"size":{let f=u[0]?.match(/^(\d+)x(\d+)$/);if(!f)throw new j(l,"write size 900x560.");[r.width,r.height]=[Number(f[1]),Number(f[2])];continue}case"param":{let[f,b,y,...w]=u,[k,v]=Se(y,l).map(Number),M={label:Z(b??""),min:k,max:v,step:1,value:k};for(let S=0;S<w.length;S++)if(w[S].startsWith("step="))M.step=Number(w[S].slice(5));else if(w[S]==="=")M.value=Number(w[++S]);else throw new j(l,`did not understand \xAB${w[S]}\xBB.`);r.params={...r.params,[f]:M};continue}case"switch":{let[f,b,y]=u;r.switches={...r.switches,[f]:{label:Z(b??""),on:y==="on"}};continue}case"var":{if(u[1]!=="=")throw new j(l,"write var name = value.");r.vars={...r.vars,[u[0]]:lt(u[2]??"",l)};continue}case"learning":{let[f,b]=u;if(!["goal","question","answer","caveat"].includes(f))throw new j(l,'write learning goal|question|answer|caveat "\u2026".');r.learning={...r.learning,[f]:Z(b??"")};continue}case"define":{let f=u[0];if(!f)throw new j(l,"write define <name> and its shapes under it.");r.defs={...r.defs,[f]:{shapes:i.children.map(Yo)}},n.add(f);continue}case"quiz":{r.quiz={question:Z(u[0]??""),options:i.children.map(f=>{let[b,...y]=f.tokens;if(b!=="*"&&b!=="-")throw new j(f.no,"under a quiz, write * right option -- why, or - wrong option -- why.");let w=y.map(Z).join(" "),[k,v=""]=w.split(/\s+--\s+/);return{text:k.trim(),right:b==="*",why:v.trim()}})};continue}}let m=u[0]==="->"&&u.indexOf("->",1)>0?Xo(i):[Me(i,n)],[g]=m;s!==void 0&&([g.chapter,s]=[s,void 0]),a!==void 0&&([g.say,a]=[a,void 0]),o.push(...m)}return r.steps=o,r}var Ee=2,gn=.2,Vo=3,Wo=.5,wt=e=>Math.max(0,e.w)*Math.max(0,e.h);function Ae(e,t){let n=Math.min(e.x+e.w,t.x+t.w)-Math.max(e.x,t.x),r=Math.min(e.y+e.h,t.y+t.h)-Math.max(e.y,t.y);return n>0&&r>0?n*r:0}var Ho=(e,[t,n])=>t>e.x+2&&t<e.x+e.w-2&&n>e.y+2&&n<e.y+e.h-2,ie=e=>e.text?` (\xAB${e.text.slice(0,40)}\xBB)`:"",Uo=(e,t)=>{let[n,r]=[e.box,t.box];return(e.type==="circle"||e.type==="ellipse")&&r.x>=n.x-2&&r.y>=n.y-2&&r.x+r.w<=n.x+n.w+2&&r.y+r.h<=n.y+n.h+2};function Ko(e,t,n){let r=new Map;for(let i of e){let l=i.box;(l.x<-Ee||l.y<-Ee||l.x+l.w>t+Ee||l.y+l.h>n+Ee)&&r.set(`off:${i.step}`,`step ${i.step+1}${ie(i)} goes off the paper (${t}\xD7${n})`)}let o=e.filter(i=>i.kind==="text");for(let i=0;i<o.length;i++)for(let l=i+1;l<o.length;l++){let[c,h]=[o[i],o[l]];c.step!==h.step&&Ae(c.box,h.box)>gn*Math.min(wt(c.box),wt(h.box))&&r.set(`texts:${c.step}:${h.step}`,`the texts of steps ${c.step+1}${ie(c)} and ${h.step+1}${ie(h)} overlap`)}for(let i of o)for(let l of e)l.kind!=="stroke"||l.step===i.step||Uo(l,i)||(l.points??[]).filter(c=>Ho(i.box,c)).length>Vo&&r.set(`cross:${l.step}:${i.step}`,`a line of step ${l.step+1} crosses the text of step ${i.step+1}${ie(i)}`);for(let i of o)for(let l of e)l.kind!=="shape"||l.step===i.step||Ae(i.box,l.box)>gn*wt(i.box)&&r.set(`on:${l.step}:${i.step}`,`the text of step ${i.step+1}${ie(i)} sits on the drawing of step ${l.step+1}`);let s=new Map;for(let i of e){if(i.kind!=="fill"||i.type!=="balloon")continue;let l=s.get(i.step);(!l||wt(i.box)>wt(l.box))&&s.set(i.step,i)}for(let i of s.values())for(let l of e)l.kind!=="shape"||l.step===i.step||Ae(i.box,l.box)>gn*Math.min(wt(i.box),wt(l.box))&&r.set(`balloon:${i.step}:${l.step}`,`the balloon of step ${i.step+1} sits on the drawing of step ${l.step+1}`);let a=e.filter(i=>i.kind==="shape");for(let i=0;i<a.length;i++)for(let l=i+1;l<a.length;l++){let[c,h]=[a[i],a[l]];c.step!==h.step&&Ae(c.box,h.box)>Wo*Math.min(wt(c.box),wt(h.box))&&r.set(`piled:${c.step}:${h.step}`,`the drawings of steps ${c.step+1} and ${h.step+1} sit on each other`)}return[...r].map(([i,l])=>({key:i,text:l}))}function Zo(e,t){let n=[];for(let r of e.querySelectorAll("[data-step]")){let o=Number(r.dataset.step),s=r.dataset.type??t.steps[o]?.type,[a,i]=[Number(r.dataset.dx??0),Number(r.dataset.dy??0)],l=u=>({x:u.x+a,y:u.y+i,w:u.width,h:u.height});if(r.dataset.lottie!==void 0){let u=r.querySelector("[data-box]").getBBox();n.push({step:o,type:s,kind:"shape",box:l(u)});continue}let c=r.querySelector("text");if(r.dataset.prop){let u=[...r.querySelectorAll("path")].map(m=>l(m.getBBox())),d=Math.min(...u.map(m=>m.x)),p=Math.min(...u.map(m=>m.y));n.push({step:o,type:s,kind:"shape",box:{x:d,y:p,w:Math.max(...u.map(m=>m.x+m.w))-d,h:Math.max(...u.map(m=>m.y+m.h))-p}})}if(c){n.push({step:o,type:s,kind:"text",text:c.textContent??"",box:l(c.getBBox())});continue}if(!(r instanceof SVGPathElement))continue;let h=l(r.getBBox());if(r.dataset.marker)n.push({step:o,type:s,kind:"marker",box:h});else if(r.dataset.hatch)n.push({step:o,type:s,kind:"hatch",box:h});else if((r.getAttribute("fill")??"none")!=="none")n.push({step:o,type:s,kind:"fill",box:h});else{if(r.getAttribute("stroke")==="none"||Number(r.getAttribute("stroke-width")??1)===0)continue;{let u=r.getTotalLength(),d=Math.min(300,Math.max(2,Math.ceil(u/6))),p=[];for(let m=0;m<=d;m++){let g=r.getPointAtLength(u*m/d);p.push([g.x+a,g.y+i])}n.push({step:o,type:s,kind:"stroke",box:h,points:p})}}}return n}async function Oe(e){let t=document.createElement("div");t.setAttribute("aria-hidden","true"),t.style.cssText="position:fixed;left:-20000px;top:0;width:900px;visibility:hidden;pointer-events:none";let n=document.createElementNS("http://www.w3.org/2000/svg","svg");t.append(n),document.body.append(t);let r=new Map,o=Ct(e);try{let a=new at(n);for(let i of o){await a.render(e,i,{animate:!1,motion:"rest"});let l=Object.entries(i).map(([c,h])=>`${c}=${h}`).join(", ");for(let c of Ko(Zo(n,e),e.width,e.height)){let h=r.get(c.key);r.set(c.key,{text:h?.text??c.text,at:[...h?.at??[],l]})}}}finally{t.remove()}let s=o.length;return{combos:s,keys:[...r.keys()],problems:[...r.values()].map(({text:a,at:i})=>i.length===s||!i[0]?a:`${a} (at ${i.join("; ")})`)}}var Wt="http://www.w3.org/2000/svg",Sr=e=>{let t=e.viewBox.baseVal;return t&&t.width?{w:t.width,h:t.height}:{w:e.clientWidth||900,h:e.clientHeight||560}};function Qo(e,t,n){let{w:r,h:o}=Sr(e),s=e.cloneNode(!0);s.querySelectorAll(".dw-pointer").forEach(c=>c.remove());let a=performance.now();s.querySelectorAll("[data-anim]").forEach(c=>{c.style.animationPlayState!=="paused"&&(c.style.animationDelay=`${-Math.round(a-Number(c.dataset.animStart??a))}ms`,c.style.animationPlayState="paused")}),s.setAttribute("xmlns",Wt),s.setAttribute("width",String(r)),s.setAttribute("height",String(o));let i=document.createElementNS(Wt,"style");i.textContent=t;let l=document.createElementNS(Wt,"rect");return l.setAttribute("width","100%"),l.setAttribute("height","100%"),l.setAttribute("fill",n),s.prepend(l),s.prepend(i),new XMLSerializer().serializeToString(s)}async function Mr(e,t,n,r){let{svg:o,done:s}=Er(e.width);try{await new at(o).render(e,t,{animate:!1,css:!0,theme:r});let a=o.cloneNode(!0);a.querySelector(".dw-pencil")?.remove(),a.removeAttribute("style"),a.setAttribute("xmlns",Wt),a.setAttribute("width",String(e.width)),a.setAttribute("height",String(e.height));let i=new XMLSerializer().serializeToString(a),l=n.split(/(?=@font-face)/).filter(h=>{let u=h.match(/font-family:\s*['"]?([^'";]+)/)?.[1],d=h.match(/font-weight:\s*(\d+)/)?.[1];return u&&i.includes(u)&&(!d||new RegExp(`font-weight="${d}"`).test(i))}),c=document.createElementNS(Wt,"style");return c.textContent=l.join("")+wr,a.prepend(c),new XMLSerializer().serializeToString(a)}finally{s()}}async function $r(e,t,n,r=2,o){let{w:s,h:a}=Sr(e),i=new Image;i.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(Qo(e,t,n))}`,await i.decode();let l=o??document.createElement("canvas");l.width=Math.round(s*r),l.height=Math.round(a*r);let c=l.getContext("2d");return c.fillStyle=n,c.fillRect(0,0,l.width,l.height),c.drawImage(i,0,0,l.width,l.height),l}function Er(e){let t=document.createElement("div");t.setAttribute("aria-hidden","true"),t.style.cssText=`position:fixed;left:-20000px;top:0;width:${e}px;pointer-events:none`;let n=document.createElementNS(Wt,"svg");return t.append(n),document.body.append(t),{svg:n,done:()=>t.remove()}}async function ae(e,t,n,r){let{svg:o,done:s}=Er(e.width),a=document.createElement("canvas"),i=new at(o),l=!1,c=async()=>{if(!l){l=!0;try{await $r(o,n.faces,n.paper,n.scale,a),await r(a)}finally{l=!1}}},h=setInterval(()=>void c(),1e3/n.fps);try{let u=n.from??0,d=n.until??e.steps.length-1;await i.render(e,t,{animate:!0,theme:n.theme,beforeBeat:n.say,from:n.from,until:n.until,onStep:p=>n.onProgress?.((p-u+1)/(d-u+1))}),await new Promise(p=>setTimeout(p,1500))}finally{for(clearInterval(h);l;)await new Promise(u=>setTimeout(u,20));await $r(o,n.faces,n.paper,n.scale,a),await r(a),i.stop(),s()}}function bn(e,t=n=>MediaRecorder.isTypeSupported(n)){let n=["video/mp4;codecs=avc1","video/mp4"],r=["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm"];return(e==="mp4"?[...n,...r]:r).find(t)}async function yn(e,t,n){let r=document.createElement("canvas");r.width=e.width,r.height=e.height;let o=r.getContext("2d");o.fillStyle=n.paper,o.fillRect(0,0,r.width,r.height);let s=r.captureStream(24),a=n.audio?.(s),i=bn(n.prefer),l=new MediaRecorder(s,i?{mimeType:i}:void 0),c=[];l.ondataavailable=u=>u.data.size&&c.push(u.data);let h=new Promise(u=>l.onstop=()=>u());l.start(500);try{await ae(e,t,{...n,fps:12,scale:1},u=>{o.drawImage(u,0,0,r.width,r.height)})}finally{l.stop(),await h,a?.()}return new Blob(c,{type:l.mimeType||i||"video/webm"})}function Ar(e,t,n){return yn(e,t,{...n,prefer:"webm"})}var Zt=Pn($n(),1);var Ht=Pn($n(),1),Te={en:{start:"Start",back:"Back",next:"Next",playAll:"Play all",chapter:(e,t)=>`Chapter ${e} of ${t}`,values:"Move the values",think:"Think about it",answer:"One possible answer",caveat:"Where the comparison stops",download:"Download",checking:"Checking the drawing\u2026",checked:e=>`Checked at ${e} ${e===1?"setting":"settings"}: nothing leaves the paper and no text covers another.`,problems:"The check found:",broken:"This drawing could not be opened:",keys:"\u2192 next \xB7 \u2190 back \xB7 Space play all",made:"Made with chalk-talk",board:"Chalkboard",voice:"Narration",recording:e=>`Recording\u2026 ${e}%`,show:"Show me",yourTurn:"Your turn",transcript:"Transcript",again:"Try another",valuesShort:e=>`Values (${e})`,expand:"Expand",all:"All",present:"Present",presentKeys:"click, \u2192 or PageDown next \xB7 \u2190 or PageUp back \xB7 Esc stop",notes:"Speaker notes",now:"Now",after:"Next",end:"The end",notesBlocked:"the browser blocked the notes window",since:"since the start",on:"on",off:"off"},pt:{start:"In\xEDcio",back:"Voltar",next:"Pr\xF3ximo",playAll:"Tocar tudo",chapter:(e,t)=>`Cap\xEDtulo ${e} de ${t}`,values:"Mexa nos valores",think:"Para pensar",answer:"Uma resposta poss\xEDvel",caveat:"Onde a compara\xE7\xE3o para",download:"Baixar",checking:"Conferindo o desenho\u2026",checked:e=>`Conferido em ${e} ${e===1?"posi\xE7\xE3o":"posi\xE7\xF5es"}: nada sai do papel e nenhum texto cobre outro.`,problems:"A confer\xEAncia achou:",broken:"Este desenho n\xE3o p\xF4de ser aberto:",keys:"\u2192 pr\xF3ximo \xB7 \u2190 voltar \xB7 Espa\xE7o tocar tudo",made:"Feito com chalk-talk",board:"Quadro-negro",voice:"Narra\xE7\xE3o",recording:e=>`Gravando\u2026 ${e}%`,show:"Mostrar",yourTurn:"Sua vez",transcript:"Transcri\xE7\xE3o",again:"Tentar outra",valuesShort:e=>`Valores (${e})`,expand:"Expandir",all:"Tudo",present:"Apresentar",presentKeys:"clique, \u2192 ou PageDown avan\xE7a \xB7 \u2190 ou PageUp volta \xB7 Esc sai",notes:"Notas do apresentador",now:"Agora",after:"Depois",end:"Fim",notesBlocked:"o navegador bloqueou a janela de notas",since:"desde o come\xE7o",on:"ligado",off:"desligado"}},Mn=()=>navigator.language.toLowerCase().startsWith("pt")?"pt":"en",ze=e=>e.locale?e.locale.toLowerCase().startsWith("pt")?"pt":"en":Mn(),xs=`
|
|
153
|
+
<script>"use strict";(()=>{var Jr=Object.create;var Be=Object.defineProperty;var to=Object.getOwnPropertyDescriptor;var eo=Object.getOwnPropertyNames;var no=Object.getPrototypeOf,ro=Object.prototype.hasOwnProperty;var oo=(e,t,n)=>t in e?Be(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var so=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var io=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of eo(t))!ro.call(e,o)&&o!==n&&Be(e,o,{get:()=>t[o],enumerable:!(r=to(t,o))||r.enumerable});return e};var Pn=(e,t,n)=>(n=e!=null?Jr(no(e)):{},io(t||!e||!e.__esModule?Be(n,"default",{value:e,enumerable:!0}):n,e));var q=(e,t,n)=>oo(e,typeof t!="symbol"?t+"":t,n);var $n=so(vn=>{var Cr=Object.defineProperty,Jo=e=>Cr(e,"__esModule",{value:!0}),ts=(e,t)=>{for(var n in t)Cr(e,n,{get:t[n],enumerable:!0})};Jo(vn);ts(vn,{GIFEncoder:()=>Ir,applyPalette:()=>cs,default:()=>ws,nearestColor:()=>ps,nearestColorIndex:()=>jr,nearestColorIndexWithDistance:()=>Nr,prequantize:()=>ls,quantize:()=>is,snapColorsToPalette:()=>ds});var es={signature:"GIF",version:"89a",trailer:59,extensionIntroducer:33,applicationExtensionLabel:255,graphicControlExtensionLabel:249,imageSeparator:44,signatureSize:3,versionSize:3,globalColorTableFlagMask:128,colorResolutionMask:112,sortFlagMask:8,globalColorTableSizeMask:7,applicationIdentifierSize:8,applicationAuthCodeSize:3,disposalMethodMask:28,userInputFlagMask:2,transparentColorFlagMask:1,localColorTableFlagMask:128,interlaceFlagMask:64,idSortFlagMask:32,localColorTableSizeMask:7};function Tr(e=256){let t=0,n=new Uint8Array(e);return{get buffer(){return n.buffer},reset(){t=0},bytesView(){return n.subarray(0,t)},bytes(){return n.slice(0,t)},writeByte(o){r(t+1),n[t]=o,t++},writeBytes(o,s=0,a=o.length){r(t+a);for(let i=0;i<a;i++)n[t++]=o[i+s]},writeBytesView(o,s=0,a=o.byteLength){r(t+a),n.set(o.subarray(s,s+a),t),t+=a}};function r(o){var s=n.length;if(s>=o)return;var a=1024*1024;o=Math.max(o,s*(s<a?2:1.125)>>>0),s!=0&&(o=Math.max(o,256));let i=n;n=new Uint8Array(o),t>0&&n.set(i.subarray(0,t),0)}}var wn=12,Or=5003,ns=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535];function rs(e,t,n,r,o=Tr(512),s=new Uint8Array(256),a=new Int32Array(Or),i=new Int32Array(Or)){let c=a.length,l=Math.max(2,r);s.fill(0),i.fill(0),a.fill(-1);let h=0,u=0,d=l+1,p=d,m=!1,g=p,f=(1<<g)-1,b=1<<d-1,y=b+1,w=b+2,k=0,v=n[0],M=0;for(let C=c;C<65536;C*=2)++M;M=8-M,o.writeByte(l),R(b);let S=n.length;for(let C=1;C<S;C++)t:{let L=n[C],D=(L<<wn)+v,I=L<<M^v;if(a[I]===D){v=i[I];break t}let W=I===0?1:c-I;for(;a[I]>=0;)if(I-=W,I<0&&(I+=c),a[I]===D){v=i[I];break t}R(v),v=L,w<1<<wn?(i[I]=w++,a[I]=D):(a.fill(-1),w=b+2,m=!0,R(b))}return R(v),R(y),o.writeByte(0),o.bytesView();function R(C){for(h&=ns[u],u>0?h|=C<<u:h=C,u+=g;u>=8;)s[k++]=h&255,k>=254&&(o.writeByte(k),o.writeBytesView(s,0,k),k=0),h>>=8,u-=8;if((w>f||m)&&(m?(g=p,f=(1<<g)-1,m=!1):(++g,f=g===wn?1<<g:(1<<g)-1)),C==y){for(;u>0;)s[k++]=h&255,k>=254&&(o.writeByte(k),o.writeBytesView(s,0,k),k=0),h>>=8,u-=8;k>0&&(o.writeByte(k),o.writeBytesView(s,0,k),k=0)}}}var os=rs;function zr(e,t,n){return e<<8&63488|t<<2&992|n>>3}function Br(e,t,n,r){return e>>4|t&240|(n&240)<<4|(r&240)<<8}function Rr(e,t,n){return e>>4<<8|t&240|n>>4}function Le(e,t,n){return e<t?t:e>n?n:e}function le(e){return e*e}function Pr(e,t,n){var r=0,o=1e100;let s=e[t],a=s.cnt,i=s.ac,c=s.rc,l=s.gc,h=s.bc;for(var u=s.fw;u!=0;u=e[u].fw){let p=e[u],m=p.cnt,g=a*m/(a+m);if(!(g>=o)){var d=0;n&&(d+=g*le(p.ac-i),d>=o)||(d+=g*le(p.rc-c),!(d>=o)&&(d+=g*le(p.gc-l),!(d>=o)&&(d+=g*le(p.bc-h),!(d>=o)&&(o=d,r=u))))}}s.err=o,s.nn=r}function xn(){return{ac:0,rc:0,gc:0,bc:0,cnt:0,nn:0,fw:0,bk:0,tm:0,mtm:0,err:0}}function ss(e,t){let n=t==="rgb444"?4096:65536,r=new Array(n),o=e.length;if(t==="rgba4444")for(let s=0;s<o;++s){let a=e[s],i=a>>24&255,c=a>>16&255,l=a>>8&255,h=a&255,u=Br(h,l,c,i),d=u in r?r[u]:r[u]=xn();d.rc+=h,d.gc+=l,d.bc+=c,d.ac+=i,d.cnt++}else if(t==="rgb444")for(let s=0;s<o;++s){let a=e[s],i=a>>16&255,c=a>>8&255,l=a&255,h=Rr(l,c,i),u=h in r?r[h]:r[h]=xn();u.rc+=l,u.gc+=c,u.bc+=i,u.cnt++}else for(let s=0;s<o;++s){let a=e[s],i=a>>16&255,c=a>>8&255,l=a&255,h=zr(l,c,i),u=h in r?r[h]:r[h]=xn();u.rc+=l,u.gc+=c,u.bc+=i,u.cnt++}return r}function is(e,t,n={}){let{format:r="rgb565",clearAlpha:o=!0,clearAlphaColor:s=0,clearAlphaThreshold:a=0,oneBitAlpha:i=!1}=n;if(!e||!e.buffer)throw new Error("quantize() expected RGBA Uint8Array data");if(!(e instanceof Uint8Array)&&!(e instanceof Uint8ClampedArray))throw new Error("quantize() expected RGBA Uint8Array data");let c=new Uint32Array(e.buffer),l=n.useSqrt!==!1,h=r==="rgba4444",u=ss(c,r),d=u.length,p=d-1,m=new Uint32Array(d+1);for(var g=0,b=0;b<d;++b){let V=u[b];if(V!=null){var f=1/V.cnt;h&&(V.ac*=f),V.rc*=f,V.gc*=f,V.bc*=f,u[g++]=V}}le(t)/g<.022&&(l=!1);for(var b=0;b<g-1;++b)u[b].fw=b+1,u[b+1].bk=b,l&&(u[b].cnt=Math.sqrt(u[b].cnt));l&&(u[b].cnt=Math.sqrt(u[b].cnt));var y,w,k;for(b=0;b<g;++b){Pr(u,b,!1);var v=u[b].err;for(w=++m[0];w>1&&(k=w>>1,!(u[y=m[k]].err<=v));w=k)m[w]=y;m[w]=b}var M=g-t;for(b=0;b<M;){for(var S;;){var R=m[1];if(S=u[R],S.tm>=S.mtm&&u[S.nn].mtm<=S.tm)break;S.mtm==p?R=m[1]=m[m[0]--]:(Pr(u,R,!1),S.tm=b);var v=u[R].err;for(w=1;(k=w+w)<=m[0]&&(k<m[0]&&u[m[k]].err>u[m[k+1]].err&&k++,!(v<=u[y=m[k]].err));w=k)m[w]=y;m[w]=R}var C=u[S.nn],L=S.cnt,D=C.cnt,f=1/(L+D);h&&(S.ac=f*(L*S.ac+D*C.ac)),S.rc=f*(L*S.rc+D*C.rc),S.gc=f*(L*S.gc+D*C.gc),S.bc=f*(L*S.bc+D*C.bc),S.cnt+=C.cnt,S.mtm=++b,u[C.bk].fw=C.fw,u[C.fw].bk=C.bk,C.mtm=p}let I=[];var W=0;for(b=0;;++W){let X=Le(Math.round(u[b].rc),0,255),V=Le(Math.round(u[b].gc),0,255),pt=Le(Math.round(u[b].bc),0,255),tt=255;h&&(tt=Le(Math.round(u[b].ac),0,255),i&&(tt=tt<=(typeof i=="number"?i:127)?0:255),o&&tt<=a&&(X=V=pt=s,tt=0));let J=h?[X,V,pt,tt]:[X,V,pt];if(as(I,J)||I.push(J),(b=u[b].fw)==0)break}return I}function as(e,t){for(let n=0;n<e.length;n++){let r=e[n],o=r[0]===t[0]&&r[1]===t[1]&&r[2]===t[2],s=r.length>=4&&t.length>=4?r[3]===t[3]:!0;if(o&&s)return!0}return!1}function Te(e,t){var n=0,r;for(r=0;r<e.length;r++){let o=e[r]-t[r];n+=o*o}return n}function Ce(e,t){return t>1?Math.round(e/t)*t:e}function ls(e,{roundRGB:t=5,roundAlpha:n=10,oneBitAlpha:r=null}={}){let o=new Uint32Array(e.buffer);for(let s=0;s<o.length;s++){let a=o[s],i=a>>24&255,c=a>>16&255,l=a>>8&255,h=a&255;i=Ce(i,n),r&&(i=i<=(typeof r=="number"?r:127)?0:255),h=Ce(h,t),l=Ce(l,t),c=Ce(c,t),o[s]=i<<24|c<<16|l<<8|h<<0}}function cs(e,t,n="rgb565"){if(!e||!e.buffer)throw new Error("quantize() expected RGBA Uint8Array data");if(!(e instanceof Uint8Array)&&!(e instanceof Uint8ClampedArray))throw new Error("quantize() expected RGBA Uint8Array data");if(t.length>256)throw new Error("applyPalette() only works with 256 colors or less");let r=new Uint32Array(e.buffer),o=r.length,s=n==="rgb444"?4096:65536,a=new Uint8Array(o),i=new Array(s),c=n==="rgba4444";if(n==="rgba4444")for(let l=0;l<o;l++){let h=r[l],u=h>>24&255,d=h>>16&255,p=h>>8&255,m=h&255,g=Br(m,p,d,u),f=g in i?i[g]:i[g]=hs(m,p,d,u,t);a[l]=f}else{let l=n==="rgb444"?Rr:zr;for(let h=0;h<o;h++){let u=r[h],d=u>>16&255,p=u>>8&255,m=u&255,g=l(m,p,d),f=g in i?i[g]:i[g]=us(m,p,d,t);a[h]=f}}return a}function hs(e,t,n,r,o){let s=0,a=1e100;for(let i=0;i<o.length;i++){let c=o[i],l=c[3],h=jt(l-r);if(h>a)continue;let u=c[0];if(h+=jt(u-e),h>a)continue;let d=c[1];if(h+=jt(d-t),h>a)continue;let p=c[2];h+=jt(p-n),!(h>a)&&(a=h,s=i)}return s}function us(e,t,n,r){let o=0,s=1e100;for(let a=0;a<r.length;a++){let i=r[a],c=i[0],l=jt(c-e);if(l>s)continue;let h=i[1];if(l+=jt(h-t),l>s)continue;let u=i[2];l+=jt(u-n),!(l>s)&&(s=l,o=a)}return o}function ds(e,t,n=5){if(!e.length||!t.length)return;let r=e.map(a=>a.slice(0,3)),o=n*n,s=e[0].length;for(let a=0;a<t.length;a++){let i=t[a];i.length<s?i=[i[0],i[1],i[2],255]:i.length>s?i=i.slice(0,3):i=i.slice();let c=Nr(r,i.slice(0,3),Te),l=c[0],h=c[1];h>0&&h<=o&&(e[l]=i)}}function jt(e){return e*e}function jr(e,t,n=Te){let r=1/0,o=-1;for(let s=0;s<e.length;s++){let a=e[s],i=n(t,a);i<r&&(r=i,o=s)}return o}function Nr(e,t,n=Te){let r=1/0,o=-1;for(let s=0;s<e.length;s++){let a=e[s],i=n(t,a);i<r&&(r=i,o=s)}return[o,r]}function ps(e,t,n=Te){return e[jr(e,t,n)]}function Ir(e={}){let{initialCapacity:t=4096,auto:n=!0}=e,r=Tr(t),o=5003,s=new Uint8Array(256),a=new Int32Array(o),i=new Int32Array(o),c=!1;return{reset(){r.reset(),c=!1},finish(){r.writeByte(es.trailer)},bytes(){return r.bytes()},bytesView(){return r.bytesView()},get buffer(){return r.buffer},get stream(){return r},writeHeader:l,writeFrame(h,u,d,p={}){let{transparent:m=!1,transparentIndex:g=0,delay:f=0,palette:b=null,repeat:y=0,colorDepth:w=8,dispose:k=-1}=p,v=!1;if(n?c||(v=!0,l(),c=!0):v=!!p.first,u=Math.max(0,Math.floor(u)),d=Math.max(0,Math.floor(d)),v){if(!b)throw new Error("First frame must include a { palette } option");ms(r,u,d,b,w),Lr(r,b),y>=0&&gs(r,y)}let M=Math.round(f/10);fs(r,k,M,m,g);let S=!!b&&!v;bs(r,u,d,S?b:null),S&&Lr(r,b),ys(r,h,u,d,w,s,a,i)}};function l(){Dr(r,"GIF89a")}}function fs(e,t,n,r,o){e.writeByte(33),e.writeByte(249),e.writeByte(4),o<0&&(o=0,r=!1);var s,a;r?(s=1,a=2):(s=0,a=0),t>=0&&(a=t&7),a<<=2,e.writeByte(0|a|0|s),Et(e,n),e.writeByte(o||0),e.writeByte(0)}function ms(e,t,n,r,o=8){let i=kn(r.length)-1,c=128|o-1<<4|0|i,l=0,h=0;Et(e,t),Et(e,n),e.writeBytes([c,l,h])}function gs(e,t){e.writeByte(33),e.writeByte(255),e.writeByte(11),Dr(e,"NETSCAPE2.0"),e.writeByte(3),e.writeByte(1),Et(e,t),e.writeByte(0)}function Lr(e,t){let n=1<<kn(t.length);for(let r=0;r<n;r++){let o=[0,0,0];r<t.length&&(o=t[r]),e.writeByte(o[0]),e.writeByte(o[1]),e.writeByte(o[2])}}function bs(e,t,n,r){if(e.writeByte(44),Et(e,0),Et(e,0),Et(e,t),Et(e,n),r){let a=kn(r.length)-1;e.writeByte(128|a)}else e.writeByte(0)}function ys(e,t,n,r,o=8,s,a,i){os(n,r,t,o,e,s,a,i)}function Et(e,t){e.writeByte(t&255),e.writeByte(t>>8&255)}function Dr(e,t){for(var n=0;n<t.length;n++)e.writeByte(t.charCodeAt(n))}function kn(e){return Math.max(Math.ceil(Math.log2(e)),1)}var ws=Ir});function Re(e,t,n){if(e&&e.length){let[r,o]=t,s=Math.PI/180*n,a=Math.cos(s),i=Math.sin(s);for(let c of e){let[l,h]=c;c[0]=(l-r)*a-(h-o)*i+r,c[1]=(l-r)*i+(h-o)*a+o}}}function ao(e,t){return e[0]===t[0]&&e[1]===t[1]}function lo(e,t,n,r=1){let o=n,s=Math.max(t,.1),a=e[0]&&e[0][0]&&typeof e[0][0]=="number"?[e]:e,i=[0,0];if(o)for(let l of a)Re(l,i,o);let c=function(l,h,u){let d=[];for(let y of l){let w=[...y];ao(w[0],w[w.length-1])||w.push([w[0][0],w[0][1]]),w.length>2&&d.push(w)}let p=[];h=Math.max(h,.1);let m=[];for(let y of d)for(let w=0;w<y.length-1;w++){let k=y[w],v=y[w+1];if(k[1]!==v[1]){let M=Math.min(k[1],v[1]);m.push({ymin:M,ymax:Math.max(k[1],v[1]),x:M===k[1]?k[0]:v[0],islope:(v[0]-k[0])/(v[1]-k[1])})}}if(m.sort((y,w)=>y.ymin<w.ymin?-1:y.ymin>w.ymin?1:y.x<w.x?-1:y.x>w.x?1:y.ymax===w.ymax?0:(y.ymax-w.ymax)/Math.abs(y.ymax-w.ymax)),!m.length)return p;let g=[],f=m[0].ymin,b=0;for(;g.length||m.length;){if(m.length){let y=-1;for(let w=0;w<m.length&&!(m[w].ymin>f);w++)y=w;m.splice(0,y+1).forEach(w=>{g.push({s:f,edge:w})})}if(g=g.filter(y=>!(y.edge.ymax<=f)),g.sort((y,w)=>y.edge.x===w.edge.x?0:(y.edge.x-w.edge.x)/Math.abs(y.edge.x-w.edge.x)),(u!==1||b%h==0)&&g.length>1)for(let y=0;y<g.length;y+=2){let w=y+1;if(w>=g.length)break;let k=g[y].edge,v=g[w].edge;p.push([[Math.round(k.x),f],[Math.round(v.x),f]])}f+=u,g.forEach(y=>{y.edge.x=y.edge.x+u*y.edge.islope}),b++}return p}(a,s,r);if(o){for(let l of a)Re(l,i,-o);(function(l,h,u){let d=[];l.forEach(p=>d.push(...p)),Re(d,h,u)})(c,i,-o)}return c}function ne(e,t){var n;let r=t.hachureAngle+90,o=t.hachureGap;o<0&&(o=4*t.strokeWidth),o=Math.round(Math.max(o,.1));let s=1;return t.roughness>=1&&(((n=t.randomizer)===null||n===void 0?void 0:n.next())||Math.random())>.7&&(s=o),lo(e,o,r,s||1)}var ee=class{constructor(t){this.helper=t}fillPolygons(t,n){return this._fillPolygons(t,n)}_fillPolygons(t,n){let r=ne(t,n);return{type:"fillSketch",ops:this.renderLines(r,n)}}renderLines(t,n){let r=[];for(let o of t)r.push(...this.helper.doubleLineOps(o[0][0],o[0][1],o[1][0],o[1][1],n));return r}};function xe(e){let t=e[0],n=e[1];return Math.sqrt(Math.pow(t[0]-n[0],2)+Math.pow(t[1]-n[1],2))}var Fe=class extends ee{fillPolygons(t,n){let r=n.hachureGap;r<0&&(r=4*n.strokeWidth),r=Math.max(r,.1);let o=ne(t,Object.assign({},n,{hachureGap:r})),s=Math.PI/180*n.hachureAngle,a=[],i=.5*r*Math.cos(s),c=.5*r*Math.sin(s);for(let[l,h]of o)xe([l,h])&&a.push([[l[0]-i,l[1]+c],[...h]],[[l[0]+i,l[1]-c],[...h]]);return{type:"fillSketch",ops:this.renderLines(a,n)}}},_e=class extends ee{fillPolygons(t,n){let r=this._fillPolygons(t,n),o=Object.assign({},n,{hachureAngle:n.hachureAngle+90}),s=this._fillPolygons(t,o);return r.ops=r.ops.concat(s.ops),r}},qe=class{constructor(t){this.helper=t}fillPolygons(t,n){let r=ne(t,n=Object.assign({},n,{hachureAngle:0}));return this.dotsOnLines(r,n)}dotsOnLines(t,n){let r=[],o=n.hachureGap;o<0&&(o=4*n.strokeWidth),o=Math.max(o,.1);let s=n.fillWeight;s<0&&(s=n.strokeWidth/2);let a=o/4;for(let i of t){let c=xe(i),l=c/o,h=Math.ceil(l)-1,u=c-h*o,d=(i[0][0]+i[1][0])/2-o/4,p=Math.min(i[0][1],i[1][1]);for(let m=0;m<h;m++){let g=p+u+m*o,f=d-a+2*Math.random()*a,b=g-a+2*Math.random()*a,y=this.helper.ellipse(f,b,s,s,n);r.push(...y.ops)}}return{type:"fillSketch",ops:r}}},Ge=class{constructor(t){this.helper=t}fillPolygons(t,n){let r=ne(t,n);return{type:"fillSketch",ops:this.dashedLine(r,n)}}dashedLine(t,n){let r=n.dashOffset<0?n.hachureGap<0?4*n.strokeWidth:n.hachureGap:n.dashOffset,o=n.dashGap<0?n.hachureGap<0?4*n.strokeWidth:n.hachureGap:n.dashGap,s=[];return t.forEach(a=>{let i=xe(a),c=Math.floor(i/(r+o)),l=(i+o-c*(r+o))/2,h=a[0],u=a[1];h[0]>u[0]&&(h=a[1],u=a[0]);let d=Math.atan((u[1]-h[1])/(u[0]-h[0]));for(let p=0;p<c;p++){let m=p*(r+o),g=m+r,f=[h[0]+m*Math.cos(d)+l*Math.cos(d),h[1]+m*Math.sin(d)+l*Math.sin(d)],b=[h[0]+g*Math.cos(d)+l*Math.cos(d),h[1]+g*Math.sin(d)+l*Math.sin(d)];s.push(...this.helper.doubleLineOps(f[0],f[1],b[0],b[1],n))}}),s}},Xe=class{constructor(t){this.helper=t}fillPolygons(t,n){let r=n.hachureGap<0?4*n.strokeWidth:n.hachureGap,o=n.zigzagOffset<0?r:n.zigzagOffset,s=ne(t,n=Object.assign({},n,{hachureGap:r+o}));return{type:"fillSketch",ops:this.zigzagLines(s,o,n)}}zigzagLines(t,n,r){let o=[];return t.forEach(s=>{let a=xe(s),i=Math.round(a/(2*n)),c=s[0],l=s[1];c[0]>l[0]&&(c=s[1],l=s[0]);let h=Math.atan((l[1]-c[1])/(l[0]-c[0]));for(let u=0;u<i;u++){let d=2*u*n,p=2*(u+1)*n,m=Math.sqrt(2*Math.pow(n,2)),g=[c[0]+d*Math.cos(h),c[1]+d*Math.sin(h)],f=[c[0]+p*Math.cos(h),c[1]+p*Math.sin(h)],b=[g[0]+m*Math.cos(h+Math.PI/4),g[1]+m*Math.sin(h+Math.PI/4)];o.push(...this.helper.doubleLineOps(g[0],g[1],b[0],b[1],r),...this.helper.doubleLineOps(b[0],b[1],f[0],f[1],r))}}),o}},it={},Ye=class{constructor(t){this.seed=t}next(){return this.seed?(2**31-1&(this.seed=Math.imul(48271,this.seed)))/2**31:Math.random()}},co=0,je=1,Ln=2,de={A:7,a:7,C:6,c:6,H:1,h:1,L:2,l:2,M:2,m:2,Q:4,q:4,S:4,s:4,T:2,t:2,V:1,v:1,Z:0,z:0};function Ne(e,t){return e.type===t}function Ze(e){let t=[],n=function(a){let i=new Array;for(;a!=="";)if(a.match(/^([ \t\r\n,]+)/))a=a.substr(RegExp.$1.length);else if(a.match(/^([aAcChHlLmMqQsStTvVzZ])/))i[i.length]={type:co,text:RegExp.$1},a=a.substr(RegExp.$1.length);else{if(!a.match(/^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)/))return[];i[i.length]={type:je,text:`${parseFloat(RegExp.$1)}`},a=a.substr(RegExp.$1.length)}return i[i.length]={type:Ln,text:""},i}(e),r="BOD",o=0,s=n[o];for(;!Ne(s,Ln);){let a=0,i=[];if(r==="BOD"){if(s.text!=="M"&&s.text!=="m")return Ze("M0,0"+e);o++,a=de[s.text],r=s.text}else Ne(s,je)?a=de[r]:(o++,a=de[s.text],r=s.text);if(!(o+a<n.length))throw new Error("Path data ended short");for(let c=o;c<o+a;c++){let l=n[c];if(!Ne(l,je))throw new Error("Param not a number: "+r+","+l.text);i[i.length]=+l.text}if(typeof de[r]!="number")throw new Error("Bad segment: "+r);{let c={key:r,data:i};t.push(c),o+=a,s=n[o],r==="M"&&(r="L"),r==="m"&&(r="l")}}return t}function In(e){let t=0,n=0,r=0,o=0,s=[];for(let{key:a,data:i}of e)switch(a){case"M":s.push({key:"M",data:[...i]}),[t,n]=i,[r,o]=i;break;case"m":t+=i[0],n+=i[1],s.push({key:"M",data:[t,n]}),r=t,o=n;break;case"L":s.push({key:"L",data:[...i]}),[t,n]=i;break;case"l":t+=i[0],n+=i[1],s.push({key:"L",data:[t,n]});break;case"C":s.push({key:"C",data:[...i]}),t=i[4],n=i[5];break;case"c":{let c=i.map((l,h)=>h%2?l+n:l+t);s.push({key:"C",data:c}),t=c[4],n=c[5];break}case"Q":s.push({key:"Q",data:[...i]}),t=i[2],n=i[3];break;case"q":{let c=i.map((l,h)=>h%2?l+n:l+t);s.push({key:"Q",data:c}),t=c[2],n=c[3];break}case"A":s.push({key:"A",data:[...i]}),t=i[5],n=i[6];break;case"a":t+=i[5],n+=i[6],s.push({key:"A",data:[i[0],i[1],i[2],i[3],i[4],t,n]});break;case"H":s.push({key:"H",data:[...i]}),t=i[0];break;case"h":t+=i[0],s.push({key:"H",data:[t]});break;case"V":s.push({key:"V",data:[...i]}),n=i[0];break;case"v":n+=i[0],s.push({key:"V",data:[n]});break;case"S":s.push({key:"S",data:[...i]}),t=i[2],n=i[3];break;case"s":{let c=i.map((l,h)=>h%2?l+n:l+t);s.push({key:"S",data:c}),t=c[2],n=c[3];break}case"T":s.push({key:"T",data:[...i]}),t=i[0],n=i[1];break;case"t":t+=i[0],n+=i[1],s.push({key:"T",data:[t,n]});break;case"Z":case"z":s.push({key:"Z",data:[]}),t=r,n=o}return s}function Dn(e){let t=[],n="",r=0,o=0,s=0,a=0,i=0,c=0;for(let{key:l,data:h}of e){switch(l){case"M":t.push({key:"M",data:[...h]}),[r,o]=h,[s,a]=h;break;case"C":t.push({key:"C",data:[...h]}),r=h[4],o=h[5],i=h[2],c=h[3];break;case"L":t.push({key:"L",data:[...h]}),[r,o]=h;break;case"H":r=h[0],t.push({key:"L",data:[r,o]});break;case"V":o=h[0],t.push({key:"L",data:[r,o]});break;case"S":{let u=0,d=0;n==="C"||n==="S"?(u=r+(r-i),d=o+(o-c)):(u=r,d=o),t.push({key:"C",data:[u,d,...h]}),i=h[0],c=h[1],r=h[2],o=h[3];break}case"T":{let[u,d]=h,p=0,m=0;n==="Q"||n==="T"?(p=r+(r-i),m=o+(o-c)):(p=r,m=o);let g=r+2*(p-r)/3,f=o+2*(m-o)/3,b=u+2*(p-u)/3,y=d+2*(m-d)/3;t.push({key:"C",data:[g,f,b,y,u,d]}),i=p,c=m,r=u,o=d;break}case"Q":{let[u,d,p,m]=h,g=r+2*(u-r)/3,f=o+2*(d-o)/3,b=p+2*(u-p)/3,y=m+2*(d-m)/3;t.push({key:"C",data:[g,f,b,y,p,m]}),i=u,c=d,r=p,o=m;break}case"A":{let u=Math.abs(h[0]),d=Math.abs(h[1]),p=h[2],m=h[3],g=h[4],f=h[5],b=h[6];u===0||d===0?(t.push({key:"C",data:[r,o,f,b,f,b]}),r=f,o=b):(r!==f||o!==b)&&(Fn(r,o,f,b,u,d,p,m,g).forEach(function(y){t.push({key:"C",data:y})}),r=f,o=b);break}case"Z":t.push({key:"Z",data:[]}),r=s,o=a}n=l}return t}function Jt(e,t,n){return[e*Math.cos(n)-t*Math.sin(n),e*Math.sin(n)+t*Math.cos(n)]}function Fn(e,t,n,r,o,s,a,i,c,l){let h=(u=a,Math.PI*u/180);var u;let d=[],p=0,m=0,g=0,f=0;if(l)[p,m,g,f]=l;else{[e,t]=Jt(e,t,-h),[n,r]=Jt(n,r,-h);let W=(e-n)/2,X=(t-r)/2,V=W*W/(o*o)+X*X/(s*s);V>1&&(V=Math.sqrt(V),o*=V,s*=V);let pt=o*o,tt=s*s,J=pt*tt-pt*X*X-tt*W*W,Qt=pt*X*X+tt*W*W,Ot=(i===c?-1:1)*Math.sqrt(Math.abs(J/Qt));g=Ot*o*X/s+(e+n)/2,f=Ot*-s*W/o+(t+r)/2,p=Math.asin(parseFloat(((t-f)/s).toFixed(9))),m=Math.asin(parseFloat(((r-f)/s).toFixed(9))),e<g&&(p=Math.PI-p),n<g&&(m=Math.PI-m),p<0&&(p=2*Math.PI+p),m<0&&(m=2*Math.PI+m),c&&p>m&&(p-=2*Math.PI),!c&&m>p&&(m-=2*Math.PI)}let b=m-p;if(Math.abs(b)>120*Math.PI/180){let W=m,X=n,V=r;m=c&&m>p?p+120*Math.PI/180*1:p+120*Math.PI/180*-1,d=Fn(n=g+o*Math.cos(m),r=f+s*Math.sin(m),X,V,o,s,a,0,c,[m,W,g,f])}b=m-p;let y=Math.cos(p),w=Math.sin(p),k=Math.cos(m),v=Math.sin(m),M=Math.tan(b/4),S=4/3*o*M,R=4/3*s*M,C=[e,t],L=[e+S*w,t-R*y],D=[n+S*v,r-R*k],I=[n,r];if(L[0]=2*C[0]-L[0],L[1]=2*C[1]-L[1],l)return[L,D,I].concat(d);{d=[L,D,I].concat(d);let W=[];for(let X=0;X<d.length;X+=3){let V=Jt(d[X][0],d[X][1],h),pt=Jt(d[X+1][0],d[X+1][1],h),tt=Jt(d[X+2][0],d[X+2][1],h);W.push([V[0],V[1],pt[0],pt[1],tt[0],tt[1]])}return W}}var ho={randOffset:function(e,t){return O(e,t)},randOffsetWithRange:function(e,t,n){return be(e,t,n)},ellipse:function(e,t,n,r,o){let s=qn(n,r,o);return Ve(e,t,o,s).opset},doubleLineOps:function(e,t,n,r,o){return vt(e,t,n,r,o,!0)}};function _n(e,t,n,r,o){return{type:"path",ops:vt(e,t,n,r,o)}}function me(e,t,n){let r=(e||[]).length;if(r>2){let o=[];for(let s=0;s<r-1;s++)o.push(...vt(e[s][0],e[s][1],e[s+1][0],e[s+1][1],n));return t&&o.push(...vt(e[r-1][0],e[r-1][1],e[0][0],e[0][1],n)),{type:"path",ops:o}}return r===2?_n(e[0][0],e[0][1],e[1][0],e[1][1],n):{type:"path",ops:[]}}function uo(e,t,n,r,o){return function(s,a){return me(s,!0,a)}([[e,t],[e+n,t],[e+n,t+r],[e,t+r]],o)}function Cn(e,t){if(e.length){let n=typeof e[0][0]=="number"?[e]:e,r=pe(n[0],1*(1+.2*t.roughness),t),o=t.disableMultiStroke?[]:pe(n[0],1.5*(1+.22*t.roughness),Bn(t));for(let s=1;s<n.length;s++){let a=n[s];if(a.length){let i=pe(a,1*(1+.2*t.roughness),t),c=t.disableMultiStroke?[]:pe(a,1.5*(1+.22*t.roughness),Bn(t));for(let l of i)l.op!=="move"&&r.push(l);for(let l of c)l.op!=="move"&&o.push(l)}}return{type:"path",ops:r.concat(o)}}return{type:"path",ops:[]}}function qn(e,t,n){let r=Math.sqrt(2*Math.PI*Math.sqrt((Math.pow(e/2,2)+Math.pow(t/2,2))/2)),o=Math.ceil(Math.max(n.curveStepCount,n.curveStepCount/Math.sqrt(200)*r)),s=2*Math.PI/o,a=Math.abs(e/2),i=Math.abs(t/2),c=1-n.curveFitting;return a+=O(a*c,n),i+=O(i*c,n),{increment:s,rx:a,ry:i}}function Ve(e,t,n,r){let[o,s]=Rn(r.increment,e,t,r.rx,r.ry,1,r.increment*be(.1,be(.4,1,n),n),n),a=ye(o,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[i]=Rn(r.increment,e,t,r.rx,r.ry,1.5,0,n),c=ye(i,null,n);a=a.concat(c)}return{estimatedPoints:s,opset:{type:"path",ops:a}}}function Tn(e,t,n,r,o,s,a,i,c){let l=e,h=t,u=Math.abs(n/2),d=Math.abs(r/2);u+=O(.01*u,c),d+=O(.01*d,c);let p=o,m=s;for(;p<0;)p+=2*Math.PI,m+=2*Math.PI;m-p>2*Math.PI&&(p=0,m=2*Math.PI);let g=2*Math.PI/c.curveStepCount,f=Math.min(g/2,(m-p)/2),b=jn(f,l,h,u,d,p,m,1,c);if(!c.disableMultiStroke){let y=jn(f,l,h,u,d,p,m,1.5,c);b.push(...y)}return a&&(i?b.push(...vt(l,h,l+u*Math.cos(p),h+d*Math.sin(p),c),...vt(l,h,l+u*Math.cos(m),h+d*Math.sin(m),c)):b.push({op:"lineTo",data:[l,h]},{op:"lineTo",data:[l+u*Math.cos(p),h+d*Math.sin(p)]})),{type:"path",ops:b}}function zn(e,t){let n=Dn(In(Ze(e))),r=[],o=[0,0],s=[0,0];for(let{key:a,data:i}of n)switch(a){case"M":s=[i[0],i[1]],o=[i[0],i[1]];break;case"L":r.push(...vt(s[0],s[1],i[0],i[1],t)),s=[i[0],i[1]];break;case"C":{let[c,l,h,u,d,p]=i;r.push(...po(c,l,h,u,d,p,s,t)),s=[d,p];break}case"Z":r.push(...vt(s[0],s[1],o[0],o[1],t)),s=[o[0],o[1]]}return{type:"path",ops:r}}function Ie(e,t){let n=[];for(let r of e)if(r.length){let o=t.maxRandomnessOffset||0,s=r.length;if(s>2){n.push({op:"move",data:[r[0][0]+O(o,t),r[0][1]+O(o,t)]});for(let a=1;a<s;a++)n.push({op:"lineTo",data:[r[a][0]+O(o,t),r[a][1]+O(o,t)]})}}return{type:"fillPath",ops:n}}function It(e,t){return function(n,r){let o=n.fillStyle||"hachure";if(!it[o])switch(o){case"zigzag":it[o]||(it[o]=new Fe(r));break;case"cross-hatch":it[o]||(it[o]=new _e(r));break;case"dots":it[o]||(it[o]=new qe(r));break;case"dashed":it[o]||(it[o]=new Ge(r));break;case"zigzag-line":it[o]||(it[o]=new Xe(r));break;default:o="hachure",it[o]||(it[o]=new ee(r))}return it[o]}(t,ho).fillPolygons(e,t)}function Bn(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function Gn(e){return e.randomizer||(e.randomizer=new Ye(e.seed||0)),e.randomizer.next()}function be(e,t,n,r=1){return n.roughness*r*(Gn(n)*(t-e)+e)}function O(e,t,n=1){return be(-e,e,t,n)}function vt(e,t,n,r,o,s=!1){let a=s?o.disableMultiStrokeFill:o.disableMultiStroke,i=We(e,t,n,r,o,!0,!1);if(a)return i;let c=We(e,t,n,r,o,!0,!0);return i.concat(c)}function We(e,t,n,r,o,s,a){let i=Math.pow(e-n,2)+Math.pow(t-r,2),c=Math.sqrt(i),l=1;l=c<200?1:c>500?.4:-.0016668*c+1.233334;let h=o.maxRandomnessOffset||0;h*h*100>i&&(h=c/10);let u=h/2,d=.2+.2*Gn(o),p=o.bowing*o.maxRandomnessOffset*(r-t)/200,m=o.bowing*o.maxRandomnessOffset*(e-n)/200;p=O(p,o,l),m=O(m,o,l);let g=[],f=()=>O(u,o,l),b=()=>O(h,o,l),y=o.preserveVertices;return s&&(a?g.push({op:"move",data:[e+(y?0:f()),t+(y?0:f())]}):g.push({op:"move",data:[e+(y?0:O(h,o,l)),t+(y?0:O(h,o,l))]})),a?g.push({op:"bcurveTo",data:[p+e+(n-e)*d+f(),m+t+(r-t)*d+f(),p+e+2*(n-e)*d+f(),m+t+2*(r-t)*d+f(),n+(y?0:f()),r+(y?0:f())]}):g.push({op:"bcurveTo",data:[p+e+(n-e)*d+b(),m+t+(r-t)*d+b(),p+e+2*(n-e)*d+b(),m+t+2*(r-t)*d+b(),n+(y?0:b()),r+(y?0:b())]}),g}function pe(e,t,n){if(!e.length)return[];let r=[];r.push([e[0][0]+O(t,n),e[0][1]+O(t,n)]),r.push([e[0][0]+O(t,n),e[0][1]+O(t,n)]);for(let o=1;o<e.length;o++)r.push([e[o][0]+O(t,n),e[o][1]+O(t,n)]),o===e.length-1&&r.push([e[o][0]+O(t,n),e[o][1]+O(t,n)]);return ye(r,null,n)}function ye(e,t,n){let r=e.length,o=[];if(r>3){let s=[],a=1-n.curveTightness;o.push({op:"move",data:[e[1][0],e[1][1]]});for(let i=1;i+2<r;i++){let c=e[i];s[0]=[c[0],c[1]],s[1]=[c[0]+(a*e[i+1][0]-a*e[i-1][0])/6,c[1]+(a*e[i+1][1]-a*e[i-1][1])/6],s[2]=[e[i+1][0]+(a*e[i][0]-a*e[i+2][0])/6,e[i+1][1]+(a*e[i][1]-a*e[i+2][1])/6],s[3]=[e[i+1][0],e[i+1][1]],o.push({op:"bcurveTo",data:[s[1][0],s[1][1],s[2][0],s[2][1],s[3][0],s[3][1]]})}if(t&&t.length===2){let i=n.maxRandomnessOffset;o.push({op:"lineTo",data:[t[0]+O(i,n),t[1]+O(i,n)]})}}else r===3?(o.push({op:"move",data:[e[1][0],e[1][1]]}),o.push({op:"bcurveTo",data:[e[1][0],e[1][1],e[2][0],e[2][1],e[2][0],e[2][1]]})):r===2&&o.push(...We(e[0][0],e[0][1],e[1][0],e[1][1],n,!0,!0));return o}function Rn(e,t,n,r,o,s,a,i){let c=[],l=[];if(i.roughness===0){e/=4,l.push([t+r*Math.cos(-e),n+o*Math.sin(-e)]);for(let h=0;h<=2*Math.PI;h+=e){let u=[t+r*Math.cos(h),n+o*Math.sin(h)];c.push(u),l.push(u)}l.push([t+r*Math.cos(0),n+o*Math.sin(0)]),l.push([t+r*Math.cos(e),n+o*Math.sin(e)])}else{let h=O(.5,i)-Math.PI/2;l.push([O(s,i)+t+.9*r*Math.cos(h-e),O(s,i)+n+.9*o*Math.sin(h-e)]);let u=2*Math.PI+h-.01;for(let d=h;d<u;d+=e){let p=[O(s,i)+t+r*Math.cos(d),O(s,i)+n+o*Math.sin(d)];c.push(p),l.push(p)}l.push([O(s,i)+t+r*Math.cos(h+2*Math.PI+.5*a),O(s,i)+n+o*Math.sin(h+2*Math.PI+.5*a)]),l.push([O(s,i)+t+.98*r*Math.cos(h+a),O(s,i)+n+.98*o*Math.sin(h+a)]),l.push([O(s,i)+t+.9*r*Math.cos(h+.5*a),O(s,i)+n+.9*o*Math.sin(h+.5*a)])}return[l,c]}function jn(e,t,n,r,o,s,a,i,c){let l=s+O(.1,c),h=[];h.push([O(i,c)+t+.9*r*Math.cos(l-e),O(i,c)+n+.9*o*Math.sin(l-e)]);for(let u=l;u<=a;u+=e)h.push([O(i,c)+t+r*Math.cos(u),O(i,c)+n+o*Math.sin(u)]);return h.push([t+r*Math.cos(a),n+o*Math.sin(a)]),h.push([t+r*Math.cos(a),n+o*Math.sin(a)]),ye(h,null,c)}function po(e,t,n,r,o,s,a,i){let c=[],l=[i.maxRandomnessOffset||1,(i.maxRandomnessOffset||1)+.3],h=[0,0],u=i.disableMultiStroke?1:2,d=i.preserveVertices;for(let p=0;p<u;p++)p===0?c.push({op:"move",data:[a[0],a[1]]}):c.push({op:"move",data:[a[0]+(d?0:O(l[0],i)),a[1]+(d?0:O(l[0],i))]}),h=d?[o,s]:[o+O(l[p],i),s+O(l[p],i)],c.push({op:"bcurveTo",data:[e+O(l[p],i),t+O(l[p],i),n+O(l[p],i),r+O(l[p],i),h[0],h[1]]});return c}function te(e){return[...e]}function Nn(e,t=0){let n=e.length;if(n<3)throw new Error("A curve must have at least three points.");let r=[];if(n===3)r.push(te(e[0]),te(e[1]),te(e[2]),te(e[2]));else{let o=[];o.push(e[0],e[0]);for(let i=1;i<e.length;i++)o.push(e[i]),i===e.length-1&&o.push(e[i]);let s=[],a=1-t;r.push(te(o[0]));for(let i=1;i+2<o.length;i++){let c=o[i];s[0]=[c[0],c[1]],s[1]=[c[0]+(a*o[i+1][0]-a*o[i-1][0])/6,c[1]+(a*o[i+1][1]-a*o[i-1][1])/6],s[2]=[o[i+1][0]+(a*o[i][0]-a*o[i+2][0])/6,o[i+1][1]+(a*o[i][1]-a*o[i+2][1])/6],s[3]=[o[i+1][0],o[i+1][1]],r.push(s[1],s[2],s[3])}}return r}function ge(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function fo(e,t,n){let r=ge(t,n);if(r===0)return ge(e,t);let o=((e[0]-t[0])*(n[0]-t[0])+(e[1]-t[1])*(n[1]-t[1]))/r;return o=Math.max(0,Math.min(1,o)),ge(e,Pt(t,n,o))}function Pt(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function He(e,t,n,r){let o=r||[];if(function(i,c){let l=i[c+0],h=i[c+1],u=i[c+2],d=i[c+3],p=3*h[0]-2*l[0]-d[0];p*=p;let m=3*h[1]-2*l[1]-d[1];m*=m;let g=3*u[0]-2*d[0]-l[0];g*=g;let f=3*u[1]-2*d[1]-l[1];return f*=f,p<g&&(p=g),m<f&&(m=f),p+m}(e,t)<n){let i=e[t+0];o.length?(s=o[o.length-1],a=i,Math.sqrt(ge(s,a))>1&&o.push(i)):o.push(i),o.push(e[t+3])}else{let c=e[t+0],l=e[t+1],h=e[t+2],u=e[t+3],d=Pt(c,l,.5),p=Pt(l,h,.5),m=Pt(h,u,.5),g=Pt(d,p,.5),f=Pt(p,m,.5),b=Pt(g,f,.5);He([c,d,g,b],0,n,o),He([b,f,m,u],0,n,o)}var s,a;return o}function mo(e,t){return we(e,0,e.length,t)}function we(e,t,n,r,o){let s=o||[],a=e[t],i=e[n-1],c=0,l=1;for(let h=t+1;h<n-1;++h){let u=fo(e[h],a,i);u>c&&(c=u,l=h)}return Math.sqrt(c)>r?(we(e,t,l+1,r,s),we(e,l,n,r,s)):(s.length||s.push(a),s.push(i)),s}function De(e,t=.15,n){let r=[],o=(e.length-1)/3;for(let s=0;s<o;s++)He(e,3*s,t,r);return n&&n>0?we(r,0,r.length,n):r}var ht="none",Dt=class{constructor(t){this.defaultOptions={maxRandomnessOffset:2,roughness:1,bowing:1,stroke:"#000",strokeWidth:1,curveTightness:0,curveFitting:.95,curveStepCount:9,fillStyle:"hachure",fillWeight:-1,hachureAngle:-41,hachureGap:-1,dashOffset:-1,dashGap:-1,zigzagOffset:-1,seed:0,disableMultiStroke:!1,disableMultiStrokeFill:!1,preserveVertices:!1,fillShapeRoughnessGain:.8},this.config=t||{},this.config.options&&(this.defaultOptions=this._o(this.config.options))}static newSeed(){return Math.floor(Math.random()*2**31)}_o(t){return t?Object.assign({},this.defaultOptions,t):this.defaultOptions}_d(t,n,r){return{shape:t,sets:n||[],options:r||this.defaultOptions}}line(t,n,r,o,s){let a=this._o(s);return this._d("line",[_n(t,n,r,o,a)],a)}rectangle(t,n,r,o,s){let a=this._o(s),i=[],c=uo(t,n,r,o,a);if(a.fill){let l=[[t,n],[t+r,n],[t+r,n+o],[t,n+o]];a.fillStyle==="solid"?i.push(Ie([l],a)):i.push(It([l],a))}return a.stroke!==ht&&i.push(c),this._d("rectangle",i,a)}ellipse(t,n,r,o,s){let a=this._o(s),i=[],c=qn(r,o,a),l=Ve(t,n,a,c);if(a.fill)if(a.fillStyle==="solid"){let h=Ve(t,n,a,c).opset;h.type="fillPath",i.push(h)}else i.push(It([l.estimatedPoints],a));return a.stroke!==ht&&i.push(l.opset),this._d("ellipse",i,a)}circle(t,n,r,o){let s=this.ellipse(t,n,r,r,o);return s.shape="circle",s}linearPath(t,n){let r=this._o(n);return this._d("linearPath",[me(t,!1,r)],r)}arc(t,n,r,o,s,a,i=!1,c){let l=this._o(c),h=[],u=Tn(t,n,r,o,s,a,i,!0,l);if(i&&l.fill)if(l.fillStyle==="solid"){let d=Object.assign({},l);d.disableMultiStroke=!0;let p=Tn(t,n,r,o,s,a,!0,!1,d);p.type="fillPath",h.push(p)}else h.push(function(d,p,m,g,f,b,y){let w=d,k=p,v=Math.abs(m/2),M=Math.abs(g/2);v+=O(.01*v,y),M+=O(.01*M,y);let S=f,R=b;for(;S<0;)S+=2*Math.PI,R+=2*Math.PI;R-S>2*Math.PI&&(S=0,R=2*Math.PI);let C=(R-S)/y.curveStepCount,L=[];for(let D=S;D<=R;D+=C)L.push([w+v*Math.cos(D),k+M*Math.sin(D)]);return L.push([w+v*Math.cos(R),k+M*Math.sin(R)]),L.push([w,k]),It([L],y)}(t,n,r,o,s,a,l));return l.stroke!==ht&&h.push(u),this._d("arc",h,l)}curve(t,n){let r=this._o(n),o=[],s=Cn(t,r);if(r.fill&&r.fill!==ht)if(r.fillStyle==="solid"){let a=Cn(t,Object.assign(Object.assign({},r),{disableMultiStroke:!0,roughness:r.roughness?r.roughness+r.fillShapeRoughnessGain:0}));o.push({type:"fillPath",ops:this._mergedShape(a.ops)})}else{let a=[],i=t;if(i.length){let c=typeof i[0][0]=="number"?[i]:i;for(let l of c)l.length<3?a.push(...l):l.length===3?a.push(...De(Nn([l[0],l[0],l[1],l[2]]),10,(1+r.roughness)/2)):a.push(...De(Nn(l),10,(1+r.roughness)/2))}a.length&&o.push(It([a],r))}return r.stroke!==ht&&o.push(s),this._d("curve",o,r)}polygon(t,n){let r=this._o(n),o=[],s=me(t,!0,r);return r.fill&&(r.fillStyle==="solid"?o.push(Ie([t],r)):o.push(It([t],r))),r.stroke!==ht&&o.push(s),this._d("polygon",o,r)}path(t,n){let r=this._o(n),o=[];if(!t)return this._d("path",o,r);t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");let s=r.fill&&r.fill!=="transparent"&&r.fill!==ht,a=r.stroke!==ht,i=!!(r.simplification&&r.simplification<1),c=function(h,u,d){let p=Dn(In(Ze(h))),m=[],g=[],f=[0,0],b=[],y=()=>{b.length>=4&&g.push(...De(b,u)),b=[]},w=()=>{y(),g.length&&(m.push(g),g=[])};for(let{key:v,data:M}of p)switch(v){case"M":w(),f=[M[0],M[1]],g.push(f);break;case"L":y(),g.push([M[0],M[1]]);break;case"C":if(!b.length){let S=g.length?g[g.length-1]:f;b.push([S[0],S[1]])}b.push([M[0],M[1]]),b.push([M[2],M[3]]),b.push([M[4],M[5]]);break;case"Z":y(),g.push([f[0],f[1]])}if(w(),!d)return m;let k=[];for(let v of m){let M=mo(v,d);M.length&&k.push(M)}return k}(t,1,i?4-4*(r.simplification||1):(1+r.roughness)/2),l=zn(t,r);if(s)if(r.fillStyle==="solid")if(c.length===1){let h=zn(t,Object.assign(Object.assign({},r),{disableMultiStroke:!0,roughness:r.roughness?r.roughness+r.fillShapeRoughnessGain:0}));o.push({type:"fillPath",ops:this._mergedShape(h.ops)})}else o.push(Ie(c,r));else o.push(It(c,r));return a&&(i?c.forEach(h=>{o.push(me(h,!1,r))}):o.push(l)),this._d("path",o,r)}opsToPath(t,n){let r="";for(let o of t.ops){let s=typeof n=="number"&&n>=0?o.data.map(a=>+a.toFixed(n)):o.data;switch(o.op){case"move":r+=`M${s[0]} ${s[1]} `;break;case"bcurveTo":r+=`C${s[0]} ${s[1]}, ${s[2]} ${s[3]}, ${s[4]} ${s[5]} `;break;case"lineTo":r+=`L${s[0]} ${s[1]} `}}return r.trim()}toPaths(t){let n=t.sets||[],r=t.options||this.defaultOptions,o=[];for(let s of n){let a=null;switch(s.type){case"path":a={d:this.opsToPath(s),stroke:r.stroke,strokeWidth:r.strokeWidth,fill:ht};break;case"fillPath":a={d:this.opsToPath(s),stroke:ht,strokeWidth:0,fill:r.fill||ht};break;case"fillSketch":a=this.fillSketch(s,r)}a&&o.push(a)}return o}fillSketch(t,n){let r=n.fillWeight;return r<0&&(r=n.strokeWidth/2),{d:this.opsToPath(t),stroke:n.fill||ht,strokeWidth:r,fill:ht}}_mergedShape(t){return t.filter((n,r)=>r===0||n.op!=="move")}},Ue=class{constructor(t,n){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new Dt(n)}draw(t){let n=t.sets||[],r=t.options||this.getDefaultOptions(),o=this.ctx,s=t.options.fixedDecimalPlaceDigits;for(let a of n)switch(a.type){case"path":o.save(),o.strokeStyle=r.stroke==="none"?"transparent":r.stroke,o.lineWidth=r.strokeWidth,r.strokeLineDash&&o.setLineDash(r.strokeLineDash),r.strokeLineDashOffset&&(o.lineDashOffset=r.strokeLineDashOffset),this._drawToContext(o,a,s),o.restore();break;case"fillPath":{o.save(),o.fillStyle=r.fill||"";let i=t.shape==="curve"||t.shape==="polygon"||t.shape==="path"?"evenodd":"nonzero";this._drawToContext(o,a,s,i),o.restore();break}case"fillSketch":this.fillSketch(o,a,r)}}fillSketch(t,n,r){let o=r.fillWeight;o<0&&(o=r.strokeWidth/2),t.save(),r.fillLineDash&&t.setLineDash(r.fillLineDash),r.fillLineDashOffset&&(t.lineDashOffset=r.fillLineDashOffset),t.strokeStyle=r.fill||"",t.lineWidth=o,this._drawToContext(t,n,r.fixedDecimalPlaceDigits),t.restore()}_drawToContext(t,n,r,o="nonzero"){t.beginPath();for(let s of n.ops){let a=typeof r=="number"&&r>=0?s.data.map(i=>+i.toFixed(r)):s.data;switch(s.op){case"move":t.moveTo(a[0],a[1]);break;case"bcurveTo":t.bezierCurveTo(a[0],a[1],a[2],a[3],a[4],a[5]);break;case"lineTo":t.lineTo(a[0],a[1])}}n.type==="fillPath"?t.fill(o):t.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(t,n,r,o,s){let a=this.gen.line(t,n,r,o,s);return this.draw(a),a}rectangle(t,n,r,o,s){let a=this.gen.rectangle(t,n,r,o,s);return this.draw(a),a}ellipse(t,n,r,o,s){let a=this.gen.ellipse(t,n,r,o,s);return this.draw(a),a}circle(t,n,r,o){let s=this.gen.circle(t,n,r,o);return this.draw(s),s}linearPath(t,n){let r=this.gen.linearPath(t,n);return this.draw(r),r}polygon(t,n){let r=this.gen.polygon(t,n);return this.draw(r),r}arc(t,n,r,o,s,a,i=!1,c){let l=this.gen.arc(t,n,r,o,s,a,i,c);return this.draw(l),l}curve(t,n){let r=this.gen.curve(t,n);return this.draw(r),r}path(t,n){let r=this.gen.path(t,n);return this.draw(r),r}},fe="http://www.w3.org/2000/svg",Ke=class{constructor(t,n){this.svg=t,this.gen=new Dt(n)}draw(t){let n=t.sets||[],r=t.options||this.getDefaultOptions(),o=this.svg.ownerDocument||window.document,s=o.createElementNS(fe,"g"),a=t.options.fixedDecimalPlaceDigits;for(let i of n){let c=null;switch(i.type){case"path":c=o.createElementNS(fe,"path"),c.setAttribute("d",this.opsToPath(i,a)),c.setAttribute("stroke",r.stroke),c.setAttribute("stroke-width",r.strokeWidth+""),c.setAttribute("fill","none"),r.strokeLineDash&&c.setAttribute("stroke-dasharray",r.strokeLineDash.join(" ").trim()),r.strokeLineDashOffset&&c.setAttribute("stroke-dashoffset",`${r.strokeLineDashOffset}`);break;case"fillPath":c=o.createElementNS(fe,"path"),c.setAttribute("d",this.opsToPath(i,a)),c.setAttribute("stroke","none"),c.setAttribute("stroke-width","0"),c.setAttribute("fill",r.fill||""),t.shape!=="curve"&&t.shape!=="polygon"||c.setAttribute("fill-rule","evenodd");break;case"fillSketch":c=this.fillSketch(o,i,r)}c&&s.appendChild(c)}return s}fillSketch(t,n,r){let o=r.fillWeight;o<0&&(o=r.strokeWidth/2);let s=t.createElementNS(fe,"path");return s.setAttribute("d",this.opsToPath(n,r.fixedDecimalPlaceDigits)),s.setAttribute("stroke",r.fill||""),s.setAttribute("stroke-width",o+""),s.setAttribute("fill","none"),r.fillLineDash&&s.setAttribute("stroke-dasharray",r.fillLineDash.join(" ").trim()),r.fillLineDashOffset&&s.setAttribute("stroke-dashoffset",`${r.fillLineDashOffset}`),s}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}opsToPath(t,n){return this.gen.opsToPath(t,n)}line(t,n,r,o,s){let a=this.gen.line(t,n,r,o,s);return this.draw(a)}rectangle(t,n,r,o,s){let a=this.gen.rectangle(t,n,r,o,s);return this.draw(a)}ellipse(t,n,r,o,s){let a=this.gen.ellipse(t,n,r,o,s);return this.draw(a)}circle(t,n,r,o){let s=this.gen.circle(t,n,r,o);return this.draw(s)}linearPath(t,n){let r=this.gen.linearPath(t,n);return this.draw(r)}polygon(t,n){let r=this.gen.polygon(t,n);return this.draw(r)}arc(t,n,r,o,s,a,i=!1,c){let l=this.gen.arc(t,n,r,o,s,a,i,c);return this.draw(l)}curve(t,n){let r=this.gen.curve(t,n);return this.draw(r)}path(t,n){let r=this.gen.path(t,n);return this.draw(r)}},Xn={canvas:(e,t)=>new Ue(e,t),svg:(e,t)=>new Ke(e,t),generator:e=>new Dt(e),newSeed:()=>Dt.newSeed()};var Yn={sqrt:Math.sqrt,abs:Math.abs,sin:Math.sin,cos:Math.cos,tan:Math.tan,min:Math.min,max:Math.max,round:Math.round,floor:Math.floor,ceil:Math.ceil,pow:Math.pow,log:Math.log,exp:Math.exp},Vn={pi:Math.PI,e:Math.E},Je=["and","or","not"],mt=class extends Error{};function go(e){let t=[],n=/\s*(\d+(?:\.\d+)?|\.\d+|[A-Za-z_][A-Za-z_0-9]*|>=|<=|==|!=|[-+*/^(),<>])/y,r=0;for(;r<e.length&&!/^\s*$/.test(e.slice(r));){n.lastIndex=r;let o=n.exec(e);if(!o)throw new mt(`Unexpected character in "${e}" (position ${r})`);let s=o[1];/^[\d.]/.test(s)?t.push({kind:"num",value:parseFloat(s)}):/^[A-Za-z_]/.test(s)?t.push({kind:"id",value:s}):t.push({kind:"op",value:s}),r=n.lastIndex}return t}var Qe=class{constructor(t,n,r){q(this,"i",0);q(this,"tokens");q(this,"scope");q(this,"src");this.tokens=t,this.scope=n,this.src=r}parse(){let t=this.or();if(this.i<this.tokens.length)throw new mt(`Leftover input at the end of "${this.src}"`);return t}peekOp(...t){let n=this.tokens[this.i];return n&&n.kind==="op"&&t.includes(n.value)?n.value:null}expect(t){if(!this.peekOp(t))throw new mt(`Expected "${t}" in "${this.src}"`);this.i++}word(t){let n=this.tokens[this.i];return!!n&&n.kind==="id"&&n.value===t}or(){let t=this.and();for(;this.word("or");){this.i++;let n=this.and();t=t!==0||n!==0?1:0}return t}and(){let t=this.not();for(;this.word("and");){this.i++;let n=this.not();t=t!==0&&n!==0?1:0}return t}not(){return this.word("not")?(this.i++,this.not()===0?1:0):this.compare()}compare(){let t=this.sum(),n=this.peekOp(">","<",">=","<=","==","!=");if(!n)return t;this.i++;let r=this.sum();return(n===">"?t>r:n==="<"?t<r:n===">="?t>=r:n==="<="?t<=r:n==="=="?t===r:t!==r)?1:0}sum(){let t=this.term(),n;for(;n=this.peekOp("+","-");){this.i++;let r=this.term();t=n==="+"?t+r:t-r}return t}term(){let t=this.unary(),n;for(;n=this.peekOp("*","/");){this.i++;let r=this.unary();t=n==="*"?t*r:t/r}return t}unary(){return this.peekOp("-")?(this.i++,-this.unary()):this.peekOp("+")?(this.i++,this.unary()):this.power()}power(){let t=this.primary();return this.peekOp("^")?(this.i++,Math.pow(t,this.unary())):t}primary(){let t=this.tokens[this.i];if(!t)throw new mt(`Incomplete expression: "${this.src}"`);if(t.kind==="num")return this.i++,t.value;if(t.kind==="id"){if(this.i++,this.peekOp("(")){if(!Object.hasOwn(Yn,t.value))throw new mt(`Unknown function "${t.value}"`);let n=Yn[t.value];this.i++;let r=[];if(!this.peekOp(")"))for(r.push(this.or());this.peekOp(",");)this.i++,r.push(this.or());return this.expect(")"),n(...r)}if(Je.includes(t.value))throw new mt(`"${t.value}" needs parentheses here, in "${this.src}"`);if(Object.hasOwn(this.scope,t.value))return this.scope[t.value];if(Object.hasOwn(Vn,t.value))return Vn[t.value];throw new mt(`Unknown variable "${t.value}" in "${this.src}"`)}if(t.value==="("){this.i++;let n=this.or();return this.expect(")"),n}throw new mt(`Unexpected symbol "${t.value}" in "${this.src}"`)}};function bo(e,t){return new Qe(go(e),t,e).parse()}function B(e,t){let n=typeof e=="number"?e:bo(e,t);if(!Number.isFinite(n))throw new mt(`Non-finite result in "${e}".`);return n}var Wn="pt-BR";function Ft(e,t,n=Wn){if(!isFinite(e))return"?";let r=t===void 0?{maximumFractionDigits:2,minimumFractionDigits:0}:{maximumFractionDigits:t,minimumFractionDigits:t};return new Intl.NumberFormat(n,r).format(e)}function nt(e,t,n=Wn){return e.replace(/\{([^{}:]+)(?::(\d))?\}/g,(r,o,s)=>Ft(B(o,t),s===void 0?void 0:Number(s),n))}var re=["person","person-pointing","person-sitting","house","car","bus","coin","phone","document","server","bank","cloud","queue","desk","computer","clock","lock","money-arrow","tree","school","hospital","factory","truck","cart","safe","bulb","gear","database","robot","ship","container","warehouse","box","pallet","shop","shelf","field","cup","function","api-gateway","cache","cluster","board","book","pencil"],_t={pessoa:"person","pessoa-apontando":"person-pointing","pessoa-sentada":"person-sitting",casa:"house",carro:"car",onibus:"bus",moeda:"coin",celular:"phone",documento:"document",servidor:"server",banco:"bank",nuvem:"cloud",fila:"queue",mesa:"desk",computador:"computer",relogio:"clock",cadeado:"lock","seta-dinheiro":"money-arrow"},qt=e=>re.includes(e)?e:typeof e=="string"&&Object.hasOwn(_t,e)?_t[e]:void 0,tn=80,Un=e=>qt(e)!==void 0,x={skin:"#E8C6A5",shirt:"#A9BCC3",wood:"#D8C29C",gold:"#F2C94C",paper:"#FFFFFF",screen:"#DCE8F0",device:"#5B6B7C",roof:"#D9785F",wall:"#F3E3C3",car:"#7FA7C9",bus:"#E9C46A",green:"#7DBE8A",dark:"#4A4A4A",metal:"#C9D3DD",board:"#2F4F3F",chalk:"#F2EFE6"},E=(e,t,n,r,o,s)=>({kind:"polygon",points:[[e,t],[e+n,t],[e+n,t+r],[e,t+r]],fill:o,main:s}),P=(...e)=>({kind:"polyline",points:e});function Kn(e){return[{kind:"polygon",points:[[-.15,-.72],[.15,-.72],[.19,-.38],[-.19,-.38]],fill:x.shirt,main:!0},{kind:"circle",c:[0,-.87],r:.11,fill:x.skin},...e,P([-.08,-.38],[-.1,0]),P([.08,-.38],[.1,0])]}var Hn=Kn([P([-.15,-.7],[-.25,-.42]),P([.15,-.7],[.25,-.42])]);function yo(e,t,n){let r=([o,s])=>[n+o*t,s*t];return e.map(o=>o.kind==="circle"?{...o,c:r(o.c),r:o.r*t}:{...o,points:o.points.map(r)})}function wo(){let e=[[-.28,-.3,.18],[-.06,-.45,.25],[.2,-.4,.21],[.37,-.27,.13]],t=[];for(let n=0;n<=24;n++){let r=-.46+.96*n/24,o=e.filter(([s,,a])=>Math.abs(r-s)<=a).map(([s,a,i])=>a-Math.sqrt(Math.max(0,i*i-(r-s)**2)));o.length&&t.push([r,Math.min(...o)])}return[...t,[.42,-.12],[-.4,-.12]]}var xo={person:Hn,"person-pointing":Kn([P([-.15,-.7],[-.25,-.42]),P([.15,-.69],[.47,-.73])]),"person-sitting":[P([-.3,-.8],[-.27,-.4]),P([-.32,-.4],[.2,-.4]),P([-.27,-.4],[-.27,0]),P([.16,-.4],[.16,0]),{kind:"polygon",points:[[-.22,-.77],[.04,-.77],[.06,-.44],[-.22,-.44]],fill:x.shirt,main:!0},{kind:"circle",c:[-.08,-.9],r:.1,fill:x.skin},P([-.1,-.44],[.3,-.44],[.32,0]),P([0,-.74],[.18,-.55],[.3,-.58])],house:[E(-.4,-.6,.8,.6,x.wall,!0),{kind:"polygon",points:[[-.5,-.58],[0,-1],[.5,-.58]],fill:x.roof},E(-.08,-.32,.16,.32,x.wood),E(.16,-.46,.16,.14,x.screen)],car:[{kind:"polygon",fill:x.car,main:!0,points:[[-.5,-.14],[-.5,-.32],[-.3,-.36],[-.18,-.56],[.2,-.56],[.32,-.36],[.5,-.32],[.5,-.14]]},{kind:"polygon",points:[[-.14,-.51],[.17,-.51],[.25,-.37],[-.22,-.37]],fill:x.screen},{kind:"circle",c:[-.28,-.12],r:.1,fill:x.dark},{kind:"circle",c:[.28,-.12],r:.1,fill:x.dark}],bus:[E(-.5,-.66,1,.52,x.bus,!0),...[-.42,-.21,0,.21].map(e=>E(e,-.6,.15,.16,x.screen)),P([-.5,-.3],[.5,-.3]),{kind:"circle",c:[-.3,-.12],r:.1,fill:x.dark},{kind:"circle",c:[.3,-.12],r:.1,fill:x.dark}],coin:[{kind:"circle",c:[0,-.42],r:.4,fill:x.gold,main:!0},{kind:"circle",c:[0,-.42],r:.3},{kind:"curve",points:[[.1,-.56],[-.08,-.57],[-.09,-.46],[.08,-.39],[.08,-.29],[-.11,-.28]]},P([0,-.64],[0,-.2])],phone:[E(-.26,-1,.52,1,x.device,!0),E(-.2,-.92,.4,.76,x.screen),{kind:"circle",c:[0,-.08],r:.035,fill:x.paper}],document:[{kind:"polygon",points:[[-.36,-1],[.16,-1],[.36,-.8],[.36,0],[-.36,0]],fill:x.paper,main:!0},P([.16,-1],[.16,-.8],[.36,-.8]),...[-.66,-.5,-.34,-.18].map(e=>P([-.22,e],[.22,e]))],server:[-1,-.66,-.32].flatMap(e=>[E(-.36,e,.72,.3,x.metal,!0),P([-.26,e+.15],[.06,e+.15]),{kind:"circle",c:[.22,e+.15],r:.035,fill:x.green}]),bank:[{kind:"polygon",points:[[-.5,-.74],[0,-1],[.5,-.74]],fill:x.wall,main:!0},E(-.45,-.74,.9,.08,x.wall),...[-.33,-.11,.11,.33].map(e=>E(e-.04,-.66,.08,.56,x.paper)),E(-.5,-.1,1,.1,x.wall)],cloud:[{kind:"polygon",points:wo(),fill:x.paper,main:!0}],queue:[-.32,0,.32].flatMap(e=>yo(Hn,.7,e)),desk:[E(-.5,-.5,1,.07,x.wood,!0),P([-.42,-.43],[-.42,0]),P([.42,-.43],[.42,0])],computer:[E(-.45,-1,.9,.6,x.device,!0),E(-.39,-.94,.78,.48,x.screen),{kind:"polygon",points:[[-.06,-.4],[.06,-.4],[.1,-.1],[-.1,-.1]],fill:x.device},E(-.25,-.1,.5,.08,x.device)],clock:[{kind:"circle",c:[0,-.48],r:.45,fill:x.paper,main:!0},...[[0,-.9,0,-.82],[.42,-.48,.34,-.48],[0,-.06,0,-.14],[-.42,-.48,-.34,-.48]].map(([e,t,n,r])=>P([e,t],[n,r])),P([0,-.48],[0,-.78]),P([0,-.48],[.2,-.48])],lock:[{kind:"curve",points:[[-.22,-.52],[-.22,-.76],[0,-.96],[.22,-.76],[.22,-.52]]},E(-.36,-.54,.72,.54,x.bus,!0),{kind:"circle",c:[0,-.32],r:.06,fill:x.dark},P([0,-.28],[0,-.14])],"money-arrow":[{kind:"polygon",fill:x.green,main:!0,points:[[-.5,-.4],[.12,-.4],[.12,-.56],[.5,-.3],[.12,-.04],[.12,-.2],[-.5,-.2]]},{kind:"circle",c:[-.2,-.3],r:.16,fill:x.gold},P([-.2,-.4],[-.2,-.2])],tree:[E(-.07,-.36,.14,.36,x.wood),{kind:"circle",c:[0,-.64],r:.3,fill:x.green,main:!0}],school:[E(-.45,-.6,.9,.6,x.wall,!0),{kind:"polygon",points:[[-.5,-.6],[0,-.82],[.5,-.6]],fill:x.roof},E(-.08,-.28,.16,.28,x.wood),E(-.36,-.48,.16,.12,x.screen),E(.2,-.48,.16,.12,x.screen),P([0,-.82],[0,-1]),{kind:"polygon",points:[[0,-1],[.17,-.95],[0,-.9]],fill:x.roof}],hospital:[E(-.4,-.8,.8,.8,x.paper,!0),E(-.045,-.7,.09,.26,"#C8442C"),E(-.13,-.615,.26,.09,"#C8442C"),E(-.1,-.24,.2,.24,x.metal)],factory:[{kind:"polygon",points:[[-.5,0],[-.5,-.5],[-.25,-.65],[-.25,-.5],[0,-.65],[0,-.5],[.25,-.65],[.25,-.5],[.5,-.5],[.5,0]],fill:x.wall,main:!0},E(.3,-.95,.12,.3,x.dark),E(-.38,-.32,.16,.12,x.screen),E(-.08,-.32,.16,.12,x.screen),E(.22,-.32,.16,.12,x.screen)],truck:[E(-.5,-.62,.62,.46,x.metal,!0),{kind:"polygon",points:[[.12,-.16],[.12,-.5],[.34,-.5],[.48,-.32],[.48,-.16]],fill:x.bus},{kind:"polygon",points:[[.18,-.46],[.32,-.46],[.42,-.33],[.18,-.33]],fill:x.screen},{kind:"circle",c:[-.3,-.1],r:.1,fill:x.dark},{kind:"circle",c:[.3,-.1],r:.1,fill:x.dark}],cart:[P([-.48,-.78],[-.4,-.62]),{kind:"polygon",points:[[-.4,-.62],[.42,-.62],[.32,-.26],[-.3,-.26]],fill:x.metal,main:!0},P([-.3,-.26],[-.3,-.14],[.32,-.14]),{kind:"circle",c:[-.22,-.07],r:.06,fill:x.dark},{kind:"circle",c:[.24,-.07],r:.06,fill:x.dark}],safe:[E(-.4,-.82,.8,.82,x.device,!0),E(-.3,-.72,.6,.62,x.metal),{kind:"circle",c:[0,-.41],r:.13,fill:x.paper},P([0,-.41],[.08,-.47])],bulb:[{kind:"circle",c:[0,-.62],r:.3,fill:x.gold,main:!0},E(-.13,-.33,.26,.2,x.metal),{kind:"curve",points:[[-.09,-.52],[0,-.66],[.09,-.52]]},P([-.08,-.08],[.08,-.08])],gear:[{kind:"polygon",points:[[.42,-.5],[.296,-.378],[.297,-.203],[.122,-.204],[0,-.08],[-.122,-.204],[-.297,-.203],[-.296,-.378],[-.42,-.5],[-.296,-.622],[-.297,-.797],[-.122,-.796],[-0,-.92],[.122,-.796],[.297,-.797],[.296,-.622]],fill:x.metal,main:!0},{kind:"circle",c:[0,-.5],r:.12,fill:x.paper}],database:[{kind:"polygon",points:[[-.35,-.8],[.35,-.8],[.35,-.16],[-.35,-.16]],fill:x.screen,main:!0},{kind:"polygon",points:[[.35,-.8],[.303,-.755],[.175,-.722],[0,-.71],[-.175,-.722],[-.303,-.755],[-.35,-.8],[-.303,-.845],[-.175,-.878],[-0,-.89],[.175,-.878],[.303,-.845]],fill:x.metal},{kind:"curve",points:[[-.35,-.16],[0,-.06],[.35,-.16]]},{kind:"curve",points:[[-.35,-.58],[0,-.48],[.35,-.58]]},{kind:"curve",points:[[-.35,-.37],[0,-.27],[.35,-.37]]}],robot:[P([0,-.95],[0,-1]),E(-.22,-.95,.44,.3,x.metal),{kind:"circle",c:[-.09,-.81],r:.045,fill:x.screen},{kind:"circle",c:[.09,-.81],r:.045,fill:x.screen},E(-.28,-.62,.56,.42,x.metal,!0),P([-.28,-.55],[-.42,-.35]),P([.28,-.55],[.42,-.35]),E(-.2,-.2,.12,.2,x.device),E(.08,-.2,.12,.2,x.device)],ship:[{kind:"polygon",points:[[-.48,-.3],[.48,-.3],[.36,-.04],[-.4,-.04]],fill:x.car,main:!0},E(-.42,-.62,.14,.32,x.wall),E(-.24,-.5,.2,.2,x.roof),E(-.02,-.5,.2,.2,x.bus),E(.2,-.5,.2,.2,x.green),{kind:"curve",points:[[-.5,0],[-.3,-.04],[-.1,0],[.1,-.04],[.3,0],[.5,-.04]]}],container:[E(-.46,-.52,.92,.52,x.roof,!0),...[-.3,-.15,0,.15,.3].map(e=>P([e,-.48],[e,-.04]))],warehouse:[{kind:"polygon",points:[[-.46,0],[.46,0],[.46,-.55],[0,-.82],[-.46,-.55]],fill:x.wall,main:!0},E(-.2,-.38,.4,.38,x.metal),P([-.2,-.26],[.2,-.26]),P([-.2,-.13],[.2,-.13])],box:[E(-.36,-.5,.52,.5,x.wood,!0),{kind:"polygon",points:[[-.36,-.5],[.16,-.5],[.36,-.64],[-.16,-.64]],fill:x.wood},{kind:"polygon",points:[[.16,0],[.36,-.14],[.36,-.64],[.16,-.5]],fill:x.wood},P([-.1,-.5],[.1,-.64])],pallet:[E(-.46,-.12,.92,.06,x.wood),...[-.42,-.05,.32].map(e=>E(e,-.06,.1,.06,x.wood)),E(-.42,-.5,.4,.38,x.wood,!0),E(.02,-.5,.4,.38,x.wood),E(-.2,-.82,.4,.32,x.wood)],shop:[E(-.42,-.6,.84,.6,x.wall,!0),{kind:"polygon",points:[[-.48,-.6],[.48,-.6],[.42,-.78],[-.42,-.78]],fill:x.roof},E(-.34,-.48,.34,.26,x.screen),E(.08,-.42,.24,.42,x.wood)],shelf:[E(-.4,-.92,.8,.92,x.paper,!0),P([-.4,-.62],[.4,-.62]),P([-.4,-.32],[.4,-.32]),E(-.32,-.8,.16,.18,x.roof),E(-.1,-.78,.14,.16,x.bus),E(.1,-.5,.22,.18,x.green),E(-.3,-.2,.24,.2,x.wood)],field:[P([-.48,0],[.48,0]),...[-.3,0,.3].flatMap(e=>[{kind:"curve",points:[[e,0],[e-.02,-.25],[e,-.5]]},{kind:"circle",c:[e-.08,-.32],r:.07,fill:x.green,main:!0},{kind:"circle",c:[e+.08,-.42],r:.07,fill:x.green,main:!0},{kind:"circle",c:[e,-.52],r:.06,fill:x.roof}])],cup:[{kind:"polygon",points:[[-.26,-.52],[.26,-.52],[.2,-.1],[-.2,-.1]],fill:x.paper,main:!0},{kind:"curve",points:[[.24,-.44],[.4,-.38],[.22,-.2]]},{kind:"polygon",points:[[-.46,-.1],[.46,-.1],[.36,0],[-.36,0]],fill:x.paper},{kind:"curve",points:[[-.08,-.62],[-.02,-.72],[-.08,-.84]]},{kind:"curve",points:[[.08,-.62],[.14,-.72],[.08,-.84]]}],function:[E(-.38,-.72,.76,.62,x.screen,!0),P([-.14,-.62],[0,-.62],[.14,-.2]),P([.02,-.42],[-.14,-.2])],"api-gateway":[E(-.12,-.8,.24,.8,x.metal,!0),P([-.48,-.55],[-.16,-.55]),P([-.24,-.62],[-.16,-.55],[-.24,-.48]),P([.16,-.3],[.48,-.3]),P([.4,-.37],[.48,-.3],[.4,-.23])],cache:[E(-.34,-.66,.68,.66,x.metal,!0),{kind:"polygon",points:[[.04,-.58],[-.12,-.3],[0,-.3],[-.06,-.08],[.14,-.38],[.02,-.38]],fill:x.gold}],cluster:[{kind:"curve",points:[[-.4,-.8],[0,-.86],[.4,-.8],[.48,-.45],[.4,-.1],[0,-.04],[-.4,-.1],[-.48,-.45],[-.4,-.8]]},E(-.3,-.7,.24,.2,x.screen,!0),E(.06,-.7,.24,.2,x.screen,!0),E(-.12,-.38,.24,.2,x.screen,!0)],board:[E(-.48,-.9,.96,.6,x.board,!0),E(-.34,-.76,.42,.03,x.chalk),E(-.34,-.62,.58,.03,x.chalk),E(-.34,-.48,.3,.03,x.chalk),P([-.3,-.3],[-.36,0]),P([.3,-.3],[.36,0])],book:[{kind:"polygon",points:[[0,-.62],[-.46,-.7],[-.46,-.1],[0,-.04]],fill:x.paper,main:!0},{kind:"polygon",points:[[0,-.62],[.46,-.7],[.46,-.1],[0,-.04]],fill:x.paper,main:!0},P([-.36,-.52],[-.1,-.48]),P([-.36,-.38],[-.1,-.34]),P([.1,-.48],[.36,-.52]),P([.1,-.34],[.36,-.38])],pencil:[{kind:"polygon",points:[[-.38,-.12],[.22,-.72],[.34,-.6],[-.26,0]],fill:x.bus,main:!0},{kind:"polygon",points:[[.22,-.72],[.34,-.6],[.44,-.86]],fill:x.wood},{kind:"polygon",points:[[-.38,-.12],[-.26,0],[-.46,-.02]],fill:x.roof}]},Zn=["happy","sad","surprised","worried","idea"],Qn={person:[0,-.87,.11],"person-pointing":[0,-.87,.11],"person-sitting":[-.08,-.9,.1]},Jn=e=>{let t=qt(e);return!!t&&t in Qn};function ko(e,t){let n=qt(e),r=n&&Qn[n];if(!r)return[];let[o,s,a]=r,i=a/.11,c=(u,d)=>[o+u*i,s+d*i],l=[{kind:"circle",c:c(-.04,-.015),r:.012*i,fill:x.dark},{kind:"circle",c:c(.04,-.015),r:.012*i,fill:x.dark}],h={kind:"curve",points:[c(-.05,.03),c(0,.06),c(.05,.03)]};switch(t){case"happy":return[...l,h];case"sad":return[...l,{kind:"curve",points:[c(-.05,.065),c(0,.035),c(.05,.065)]}];case"surprised":return[...l,{kind:"circle",c:c(0,.05),r:.022*i}];case"worried":return[...l,{kind:"polyline",points:[c(-.05,.055),c(-.017,.04),c(.017,.065),c(.05,.05)]}];case"idea":return[...l,h,{kind:"circle",c:c(0,-.26),r:.07*i,fill:x.gold},{kind:"polygon",points:[c(-.03,-.19),c(.03,-.19),c(.03,-.16),c(-.03,-.16)],fill:x.metal},{kind:"polyline",points:[c(-.11,-.3),c(-.15,-.33)]},{kind:"polyline",points:[c(.11,-.3),c(.15,-.33)]},{kind:"polyline",points:[c(0,-.36),c(0,-.41)]}]}}function tr(e,t,n=tn,r=!1,o,s){let[a,i]=t,c=([d,p])=>[a+(r?-d:d)*n,i+p*n],l=s&&Object.hasOwn(s,e)?s[e]:void 0,h=qt(e);if(!l&&!h)throw new Error(`Unknown prop "${e}".`);return(l??[...xo[h],...o?ko(h,o).map(d=>({...d,fine:!0})):[]]).map(d=>d.kind==="circle"?{...d,c:c(d.c),r:d.r*n}:{...d,points:d.points.map(c)})}var er=["spin","drive","steam","talk","pulse","float"],vo=["lesson","pitch","arch","decision","data","timeline","story"],nr=8,rr=6,or=2e5,sr=6e5,ir=24;function Ct(e){let t=Object.entries(e.params??{}),n=ut(e),r=[n];for(let o of Object.keys(e.switches??{}))r.length<9&&r.push({...n,[o]:n[o]?0:1});for(let[o,s]of t)for(let a of[s.min,s.max])a!==s.value&&r.length<9&&r.push({...n,[o]:a});return r}function ut(e){let t={};for(let[n,r]of Object.entries(e.params??{}))t[n]=r.value;for(let[n,r]of Object.entries(e.switches??{}))t[n]=r.on?1:0;return t}var lr=["card","line","arrow","polyline","polygon","curve","circle","ellipse","plot","text","highlight","pause","prop","repeat","when","move","link","counter","row","column","grid","axis","timeline","balloon","brace","note","table","bars","chain","animate","lottie"],$t=["text","prop","card","counter","circle","ellipse"],ar=["row","column","grid","chain"],$o=50;function U(e,t){if(!e||typeof e!="object"||Array.isArray(e))throw new Error(`${t}: expected an object.`)}function Y(e,t){if(typeof e!="string"||!e.trim()||e.length>2e3)throw new Error(`${t}: expected text of 1 to 2000 characters.`)}function F(e,t,n=-1e4,r=1e4){if(typeof e!="number"||!Number.isFinite(e)||e<n||e>r)throw new Error(`${t}: expected a number between ${n} and ${r}.`)}function ot(e,t){if(typeof e=="string"){if(Y(e,t),e.length>300)throw new Error(`${t}: expression too long.`)}else F(e,t)}function rt(e,t){if(!Array.isArray(e)||e.length!==2)throw new Error(`${t}: expected [x, y].`);e.forEach((n,r)=>ot(n,`${t}[${r}]`))}function ft(e,t){e!==void 0&&Y(e,t)}function st(e,t,n){if(e!==void 0&&(typeof e!="string"||!t.includes(e)))throw new Error(`${n}: choose one of ${t.join(", ")}.`)}function ke(e){if(!/^[A-Za-z_][A-Za-z_0-9]*$/.test(e)||["__proto__","constructor","prototype",...Je].includes(e))throw new Error(`Invalid variable name: "${e}".`)}var Gt=(e,t)=>t.includes("{")||e.exact.has(t)||[...e.repeated].some(n=>t.startsWith(`${n}-`)&&/^\d+$/.test(t.slice(n.length+1)));function Lt(e,t,n,r){r&&e[t]===void 0&&(e[t]=[0,0]),rt(e[t],`${n}.${t}`)}function oe(e,t,n,r,o=!1){if(U(e,t),++n.count>500)throw new Error(`${t}: a recipe draws at most 500 steps, counting those inside repeat and when.`);if(r){for(let i of["chapter","say","duration"])if(e[i]!==void 0)throw new Error(`${t}.${i}: put it on the ${r} step itself, not on a step inside it.`);if(e.type==="pause")throw new Error(`${t}: a pause cannot go inside ${r}.`);if(e.type==="repeat"&&r==="repeat")throw new Error(`${t}: a repeat cannot go inside another repeat.`);if(ar.includes(r)&&e.place!==void 0)throw new Error(`${t}.place: the ${r} places the steps inside it.`)}if(!lr.includes(e.type))throw new Error(`${t}: unknown type "${e.type}".`);for(let i of["id","say","chapter"])ft(e[i],`${t}.${i}`);if(e.duration!==void 0&&F(e.duration,`${t}.duration`,0,3e4),e.nudge!==void 0){if(["pause","move","link","animate"].includes(e.type))throw new Error(`${t}.nudge: a ${e.type} has no place of its own to move.`);if(!Array.isArray(e.nudge)||e.nudge.length!==2)throw new Error(`${t}.nudge: use [dx, dy].`);e.nudge.forEach((i,c)=>F(i,`${t}.nudge[${c}]`,-900,900))}let s=r!==null&&ar.includes(r)||o;if(e.place!==void 0){if(!$t.includes(e.type))throw new Error(`${t}.place: only ${$t.join(", ")} can be placed.`);if(U(e.place,`${t}.place`),Y(e.place.to,`${t}.place.to`),!Gt(n,String(e.place.to)))throw new Error(`${t}.place.to: no earlier step has the id "${e.place.to}".`);if(!["below","above","left","right"].includes(e.place.side))throw new Error(`${t}.place.side: choose one of below, above, left, right.`);e.place.gap!==void 0&&F(e.place.gap,`${t}.place.gap`,-200,400),st(e.place.align,["center","start","end"],`${t}.place.align`)}let a=s||e.place!==void 0;if(e.style!==void 0){U(e.style,`${t}.style`);for(let i of["color","fill"]){let c=e.style[i];if(c!==void 0&&(typeof c!="string"||!/^(#[\da-f]{3,8}|[a-z]+)$/i.test(c)))throw new Error(`${t}.style.${i}: use a hex colour or a colour name, no URLs.`)}for(let i of["width","roughness","bowing"])e.style[i]!==void 0&&F(e.style[i],`${t}.style.${i}`,0,20);if(e.style.opacity!==void 0&&F(e.style.opacity,`${t}.style.opacity`,0,1),e.style.dashed!==void 0&&typeof e.style.dashed!="boolean")throw new Error(`${t}: dashed must be a boolean.`);st(e.style.fillStyle,["hachure","solid","zigzag","cross-hatch","dots"],`${t}.style.fillStyle`)}switch(e.type){case"line":case"arrow":case"highlight":rt(e.from,`${t}.from`),rt(e.to,`${t}.to`),e.thickness!==void 0&&F(e.thickness,`${t}.thickness`,1,200);break;case"polyline":case"polygon":case"curve":if(!Array.isArray(e.points)||e.points.length<(e.type==="polygon"?3:2)||e.points.length>500)throw new Error(`${t}: points needs ${e.type==="polygon"?3:2} to 500 points.`);e.points.forEach((i,c)=>rt(i,`${t}.points[${c}]`));break;case"circle":case"ellipse":Lt(e,"center",t,a);for(let i of e.type==="circle"?["r"]:["rx","ry"])ot(e[i],`${t}.${i}`),typeof e[i]=="number"&&F(e[i],`${t}.${i}`,0);break;case"text":Lt(e,"at",t,a),Y(e.text,`${t}.text`),e.size!==void 0&&F(e.size,`${t}.size`,1,200),e.rotate!==void 0&&F(e.rotate,`${t}.rotate`,-360,360),st(e.font,["hand","body"],`${t}.font`),st(e.anchor,["start","middle","end"],`${t}.anchor`);break;case"card":Lt(e,"at",t,a),ot(e.w,`${t}.w`),ot(e.h,`${t}.h`);for(let i of["w","h"])typeof e[i]=="number"&&F(e[i],`${t}.${i}`,40);if(Y(e.title,`${t}.title`),e.lines!==void 0){if(!Array.isArray(e.lines)||e.lines.length>6)throw new Error(`${t}: at most 6 lines per card.`);e.lines.forEach((i,c)=>Y(i,`${t}.lines[${c}]`))}break;case"plot":Y(e.fn,`${t}.fn`),e.var!==void 0&&(Y(e.var,`${t}.var`),ke(String(e.var))),rt(e.domain,`${t}.domain`),rt(e.range,`${t}.range`),U(e.box,`${t}.box`);for(let i of["x","y","w","h"])ot(e.box[i],`${t}.box.${i}`);if(e.samples!==void 0&&(F(e.samples,`${t}.samples`,2,1e3),!Number.isInteger(e.samples)))throw new Error(`${t}: samples must be an integer.`);break;case"pause":F(e.ms,`${t}.ms`,0,3e4),ft(e.ask,`${t}.ask`);break;case"prop":if(!Un(e.name)&&!n.figures.has(String(e.name))){let i=n.figures.size?`, or one the recipe defines (${[...n.figures].join(", ")})`:"";throw new Error(`${t}.name: unknown prop "${String(e.name)}"; use one of ${re.join(", ")}${i}.`)}if(Lt(e,"at",t,a),e.size!==void 0&&(ot(e.size,`${t}.size`),typeof e.size=="number"&&F(e.size,`${t}.size`,10,1e3)),ft(e.label,`${t}.label`),e.flip!==void 0&&typeof e.flip!="boolean")throw new Error(`${t}.flip: expected true or false.`);if(e.mood!==void 0){if(!Jn(e.name))throw new Error(`${t}.mood: only a person (person, person-pointing, person-sitting) has a face.`);st(e.mood,Zn,`${t}.mood`)}break;case"repeat":if(ot(e.times,`${t}.times`),typeof e.times=="number"&&(F(e.times,`${t}.times`,0,$o),!Number.isInteger(e.times)))throw new Error(`${t}.times: expected a whole number.`);oe(e.step,`${t}.step`,n,"repeat",s);break;case"when":if(ot(e.if,`${t}.if`),!Array.isArray(e.steps)||e.steps.length===0||e.steps.length>50)throw new Error(`${t}.steps: expected 1 to 50 steps.`);e.steps.forEach((i,c)=>oe(i,`${t}.steps[${c}]`,n,r??"when"));break;case"move":if(Y(e.target,`${t}.target`),!Gt(n,String(e.target)))throw new Error(`${t}.target: no earlier step has the id "${e.target}".`);rt(e.to,`${t}.to`),st(e.along,["line","curve"],`${t}.along`),e.ms!==void 0&&F(e.ms,`${t}.ms`,200,5e3);break;case"lottie":if(Y(e.src,`${t}.src`),rt(e.at,`${t}.at`),e.size!==void 0&&(ot(e.size,`${t}.size`),typeof e.size=="number"&&F(e.size,`${t}.size`,24,1e3)),e.loop!==void 0&&typeof e.loop!="boolean")throw new Error(`${t}.loop: expected true or false.`);break;case"animate":if(Y(e.target,`${t}.target`),!Gt(n,String(e.target)))throw new Error(`${t}.target: no earlier step has the id "${e.target}".`);if(st(e.effect,[...er,"stop"],`${t}.effect`),e.effect===void 0)throw new Error(`${t}.effect: choose one of ${[...er,"stop"].join(", ")}.`);st(e.speed,["slow","fast"],`${t}.speed`);break;case"link":for(let i of["from","to"])if(Y(e[i],`${t}.${i}`),!Gt(n,String(e[i])))throw new Error(`${t}.${i}: no earlier step has the id "${e[i]}".`);ft(e.label,`${t}.label`);break;case"counter":if(Lt(e,"at",t,a),ot(e.value,`${t}.value`),e.format!==void 0&&(Y(e.format,`${t}.format`),!String(e.format).includes("{v")))throw new Error(`${t}.format: show the number as {v}, e.g. "R$ {v:0}".`);e.size!==void 0&&F(e.size,`${t}.size`,1,200),st(e.anchor,["start","middle","end"],`${t}.anchor`);break;case"row":case"column":case"grid":if(s)throw new Error(`${t}: a ${e.type} cannot go inside another ${r}.`);if(Lt(e,"at",t,!1),e.gap!==void 0&&F(e.gap,`${t}.gap`,0,400),e.type==="grid"){if(F(e.columns,`${t}.columns`,1,12),!Number.isInteger(e.columns))throw new Error(`${t}.columns: expected a whole number.`)}else st(e.align,["center","start","end"],`${t}.align`);if(!Array.isArray(e.steps)||e.steps.length===0||e.steps.length>50)throw new Error(`${t}.steps: expected 1 to 50 steps.`);e.steps.forEach((i,c)=>{U(i,`${t}.steps[${c}]`);let l=i.type==="repeat"?i.step?.type:i.type;if(!$t.includes(l))throw new Error(`${t}.steps[${c}]: a ${e.type} holds only ${$t.join(", ")} (or a repeat of one).`);oe(i,`${t}.steps[${c}]`,n,e.type)});break;case"chain":if(s)throw new Error(`${t}: a chain cannot go inside a ${r}.`);if(Lt(e,"at",t,!1),e.gap!==void 0&&e.gap!=="auto"&&F(e.gap,`${t}.gap`,0,400),st(e.direction,["right","down"],`${t}.direction`),e.wrap!==void 0&&typeof e.wrap!="boolean")throw new Error(`${t}.wrap: expected true or false.`);if(ft(e.forward,`${t}.forward`),ft(e.back,`${t}.back`),e.size!==void 0&&(ot(e.size,`${t}.size`),typeof e.size=="number"&&F(e.size,`${t}.size`,10,1e3)),!Array.isArray(e.steps)||e.steps.length<2||e.steps.length>12)throw new Error(`${t}.steps: a chain joins 2 to 12 pieces.`);e.steps.forEach((i,c)=>{if(U(i,`${t}.steps[${c}]`),!$t.includes(i.type))throw new Error(`${t}.steps[${c}]: a chain holds only ${$t.join(", ")}.`);oe(i,`${t}.steps[${c}]`,n,"chain")});break;case"axis":case"timeline":if(rt(e.from,`${t}.from`),rt(e.to,`${t}.to`),rt(e.domain,`${t}.domain`),e.type==="axis"){if(e.ticks!==void 0){if(Array.isArray(e.ticks)){if(e.ticks.length>30)throw new Error(`${t}.ticks: at most 30 marks.`);e.ticks.forEach((i,c)=>F(i,`${t}.ticks[${c}]`))}else if(F(e.ticks,`${t}.ticks`,0,30),!Number.isInteger(e.ticks))throw new Error(`${t}.ticks: expected a whole number.`)}if(ft(e.label,`${t}.label`),e.format!==void 0&&(Y(e.format,`${t}.format`),!String(e.format).includes("{v")))throw new Error(`${t}.format: show the number as {v}, e.g. "{v} km".`)}else{if(!Array.isArray(e.marks)||e.marks.length===0||e.marks.length>20)throw new Error(`${t}.marks: expected 1 to 20 marks.`);e.marks.forEach((i,c)=>{U(i,`${t}.marks[${c}]`),ot(i.at,`${t}.marks[${c}].at`),ft(i.label,`${t}.marks[${c}].label`),ft(i.text,`${t}.marks[${c}].text`)})}break;case"balloon":if(Y(e.to,`${t}.to`),!Gt(n,String(e.to)))throw new Error(`${t}.to: no earlier step has the id "${e.to}".`);if(Y(e.text,`${t}.text`),String(e.text).length>300)throw new Error(`${t}.text: keep a balloon under 300 characters.`);st(e.side,["below","above","left","right"],`${t}.side`),st(e.kind,["speech","thought"],`${t}.kind`),e.width!==void 0&&F(e.width,`${t}.width`,80,600),e.size!==void 0&&F(e.size,`${t}.size`,12,60);break;case"brace":if(rt(e.from,`${t}.from`),rt(e.to,`${t}.to`),ft(e.label,`${t}.label`),e.flip!==void 0&&typeof e.flip!="boolean")throw new Error(`${t}.flip: expected true or false.`);break;case"note":if(rt(e.at,`${t}.at`),Y(e.text,`${t}.text`),e.to===void 0==(e.point===void 0))throw new Error(`${t}: a note points either to an element (to) or to a point (point).`);if(e.to!==void 0){if(Y(e.to,`${t}.to`),!Gt(n,String(e.to)))throw new Error(`${t}.to: no earlier step has the id "${e.to}".`)}else rt(e.point,`${t}.point`);e.size!==void 0&&F(e.size,`${t}.size`,12,60);break;case"table":if(rt(e.at,`${t}.at`),!Array.isArray(e.rows)||e.rows.length===0||e.rows.length>12)throw new Error(`${t}.rows: expected 1 to 12 rows.`);if(e.rows.forEach((i,c)=>{if(!Array.isArray(i)||i.length===0||i.length>6)throw new Error(`${t}.rows[${c}]: expected 1 to 6 cells.`);i.forEach((l,h)=>{if(typeof l!="string"||l.length>120)throw new Error(`${t}.rows[${c}][${h}]: expected text of up to 120 characters.`)})}),e.header!==void 0&&typeof e.header!="boolean")throw new Error(`${t}.header: expected true or false.`);e.size!==void 0&&F(e.size,`${t}.size`,12,40);break;case"bars":U(e.box,`${t}.box`);for(let i of["x","y","w","h"])ot(e.box[i],`${t}.box.${i}`);if(!Array.isArray(e.values)||e.values.length===0||e.values.length>12)throw new Error(`${t}.values: expected 1 to 12 values.`);if(e.values.forEach((i,c)=>ot(i,`${t}.values[${c}]`)),e.labels!==void 0){if(!Array.isArray(e.labels)||e.labels.length>e.values.length)throw new Error(`${t}.labels: at most one label per value.`);e.labels.forEach((i,c)=>Y(i,`${t}.labels[${c}]`))}if(e.max!==void 0&&ot(e.max,`${t}.max`),e.format!==void 0&&(Y(e.format,`${t}.format`),!String(e.format).includes("{v")))throw new Error(`${t}.format: show the number as {v}, e.g. "{v}%".`);break}typeof e.id=="string"&&(r==="repeat"?n.repeated:n.exact).add(e.id)}function So(e,t){let n=`defs.${e}`;if(!/^[a-z][a-z0-9-]{1,30}$/.test(e))throw new Error(`${n}: a figure's name is 2 to 31 lowercase letters, digits or -, starting with a letter.`);if(qt(e)||Object.hasOwn(_t,e)||lr.includes(e)||["define","title","param","switch","var"].includes(e))throw new Error(`${n}: "${e}" is already a prop or a step; choose another name.`);if(U(t,n),!Array.isArray(t.shapes)||t.shapes.length===0||t.shapes.length>ir)throw new Error(`${n}.shapes: expected 1 to ${ir} shapes.`);let r=(o,s)=>{if(typeof o!="number"||!Number.isInteger(o)||o<0||o>100)throw new Error(`${s}: expected a whole number from 0 to 100 (the figure's grid, y down; it stands at 50,100).`)};t.shapes.forEach((o,s)=>{let a=`${n}.shapes[${s}]`;if(U(o,a),o.fill!==void 0&&(typeof o.fill!="string"||!/^(#[0-9a-fA-F]{3,8}|[a-z]{3,20})$/.test(o.fill)))throw new Error(`${a}.fill: a colour, as hex or a plain name.`);if(o.kind==="circle"){if(!Array.isArray(o.c)||o.c.length!==2)throw new Error(`${a}.c: expected [x, y].`);o.c.forEach((c,l)=>r(c,`${a}.c[${l}]`)),r(o.r,`${a}.r`);return}if(!["polygon","polyline","curve"].includes(o.kind))throw new Error(`${a}.kind: choose one of polygon, polyline, curve, circle.`);let i=o.kind==="polygon"?3:2;if(!Array.isArray(o.points)||o.points.length<i||o.points.length>40)throw new Error(`${a}.points: a ${o.kind} takes ${i} to 40 points.`);o.points.forEach((c,l)=>{if(!Array.isArray(c)||c.length!==2)throw new Error(`${a}.points[${l}]: expected [x, y].`);c.forEach((h,u)=>r(h,`${a}.points[${l}][${u}]`))})})}function Mo(e,t){let n=`lottie "${e}"`;U(t,n);let r=JSON.stringify(t).length;if(r>or)throw new Error(`${n}: ${Math.round(r/1e3)} KB; an animation can have at most ${or/1e3} KB.`);for(let s of["fr","ip","op","w","h"])F(t[s],`${n}.${s}`,0,1e5);if(typeof t.v!="string"||!Array.isArray(t.layers))throw new Error(`${n}: not a Lottie animation (it needs v and layers).`);let o=(s,a)=>{if(Array.isArray(s))return s.forEach((i,c)=>o(i,`${a}[${c}]`));if(!(!s||typeof s!="object"))for(let[i,c]of Object.entries(s)){if(i==="x"&&typeof c=="string")throw new Error(`${n}: the animation has an expression (code inside it, at ${a}); only animations without expressions play.`);o(c,`${a}.${i}`)}};o(t.layers,"layers");for(let s of Array.isArray(t.assets)?t.assets:[]){let a=s?.p;if(typeof a=="string"&&a&&!a.startsWith("data:")&&!Array.isArray(s.layers))throw new Error(`${n}: an image from outside the animation ("${a.slice(0,40)}"); only images inside it (data:) are kept.`)}return r}function en(e){U(e,"The recipe");let t=e;F(t.width,"width",100,4e3),F(t.height,"height",100,4e3);for(let o of["id","title","category"])ft(t[o],o);if(t.locale!==void 0&&!(typeof t.locale=="string"&&/^[a-zA-Z]{2,3}(-[a-zA-Z0-9]{2,8})*$/.test(t.locale)&&Intl.NumberFormat.supportedLocalesOf([t.locale]).length>0))throw new Error('locale: expected a language tag such as "en-US" or "pt-BR".');if(st(t.background,["dots","grid","plain"],"background"),st(t.kind,vo,"kind"),ft(t.source,"source"),t.quiz!==void 0&&t.kind!==void 0&&t.kind!=="lesson")throw new Error(`quiz: only a lesson has a quiz (this drawing is a ${t.kind}).`);if(st(t.theme,["paper","chalkboard"],"theme"),t.quiz!==void 0){if(U(t.quiz,"quiz"),Y(t.quiz.question,"quiz.question"),!Array.isArray(t.quiz.options)||t.quiz.options.length<2||t.quiz.options.length>4)throw new Error("quiz.options: expected 2 to 4 options.");if(t.quiz.options.forEach((o,s)=>{if(U(o,`quiz.options[${s}]`),Y(o.text,`quiz.options[${s}].text`),Y(o.why,`quiz.options[${s}].why`),typeof o.right!="boolean")throw new Error(`quiz.options[${s}].right: expected true or false.`)}),t.quiz.options.filter(o=>o.right===!0).length!==1)throw new Error("quiz.options: exactly one option is right.")}if(t.learning!==void 0){U(t.learning,"learning");for(let o of["goal","question","answer","caveat"])Y(t.learning[o],`learning.${o}`)}if(t.params!==void 0){U(t.params,"params");for(let[o,s]of Object.entries(t.params))if(ke(o),U(s,`params.${o}`),Y(s.label,`params.${o}.label`),F(s.min,`${o}.min`),F(s.max,`${o}.max`),F(s.step,`${o}.step`,1e-6),F(s.value,`${o}.value`,s.min,s.max),s.max<=s.min)throw new Error(`${o}: max must be greater than min.`)}if(t.vars!==void 0){U(t.vars,"vars");for(let[o,s]of Object.entries(t.vars))ke(o),ot(s,`vars.${o}`)}if(t.switches!==void 0){U(t.switches,"switches");let o=Object.entries(t.switches);if(o.length>8)throw new Error("switches: at most 8.");for(let[s,a]of o){if(ke(s),Object.hasOwn(t.params??{},s)||Object.hasOwn(t.vars??{},s))throw new Error(`switches.${s}: the name is already a param or a var.`);if(U(a,`switches.${s}`),Y(a.label,`switches.${s}.label`),typeof a.on!="boolean")throw new Error(`switches.${s}.on: expected true or false.`)}}if(!Array.isArray(t.steps)||t.steps.length===0||t.steps.length>250)throw new Error("A recipe needs 1 to 250 steps.");let n=new Set;if(t.defs!==void 0){U(t.defs,"defs");let o=Object.entries(t.defs);if(o.length>nr)throw new Error(`defs: at most ${nr} figures.`);for(let[s,a]of o)So(s,a),n.add(s)}if(t.lotties!==void 0){U(t.lotties,"lotties");let o=Object.entries(t.lotties);if(o.length>rr)throw new Error(`lotties: at most ${rr} animations.`);let s=o.reduce((a,[i,c])=>a+Mo(i,c),0);if(s>sr)throw new Error(`lotties: ${Math.round(s/1e3)} KB in all; at most ${sr/1e3} KB.`)}if(t.credits!==void 0){if(!Array.isArray(t.credits)||t.credits.length>5)throw new Error("credits: at most 5 lines.");t.credits.forEach((o,s)=>Y(o,`credits[${s}]`))}let r={exact:new Set,repeated:new Set,count:0,figures:n};return t.steps.forEach((o,s)=>oe(o,`Step ${s+1}`,r,null)),{...t,id:t.id??"pasted",title:t.title??"",background:t.background??"dots"}}function se(e,t="Start"){let n=e.steps.flatMap((r,o)=>r.chapter?[{title:r.chapter,start:o}]:[]);return(!n.length||n[0].start!==0)&&n.unshift({title:t,start:0}),n.map((r,o)=>({...r,end:(n[o+1]?.start??e.steps.length)-1}))}var Eo=50,Ao=(e,t)=>Math.max(0,Math.min(Eo,Math.round(B(e,t)))),Xt=(e,t)=>t===0?e:typeof e=="number"?Math.round((e+t)*100)/100:`(${e})${t<0?"-":"+"}${Math.abs(t)}`,gt=(e,t,n)=>[Xt(e[0],t),Xt(e[1],n)];function zt(e,t,n){switch(e.type){case"prop":case"text":case"card":case"counter":case"lottie":return{...e,at:gt(e.at,t,n)};case"circle":case"ellipse":return{...e,center:gt(e.center,t,n)};case"line":case"arrow":case"highlight":return{...e,from:gt(e.from,t,n),to:gt(e.to,t,n)};case"polyline":case"polygon":case"curve":return{...e,points:e.points.map(r=>gt(r,t,n))};case"plot":return{...e,box:{...e.box,x:Xt(e.box.x,t),y:Xt(e.box.y,n)}};case"repeat":return{...e,step:zt(e.step,t,n)};case"row":case"column":case"grid":case"chain":return{...e,at:gt(e.at,t,n)};case"axis":case"timeline":case"brace":return{...e,from:gt(e.from,t,n),to:gt(e.to,t,n)};case"note":return{...e,at:gt(e.at,t,n),...e.point?{point:gt(e.point,t,n)}:{}};case"table":return{...e,at:gt(e.at,t,n)};case"bars":return{...e,box:{...e.box,x:Xt(e.box.x,t),y:Xt(e.box.y,n)}};case"when":return{...e,steps:e.steps.map(r=>zt(r,t,n))};default:return e}}function Tt(e,t,n=[]){if(e.nudge){let{nudge:r,...o}=e;return Tt(zt(o,r[0],r[1]),t,n).map(s=>({...s,nudge:[(s.nudge?.[0]??0)+r[0],(s.nudge?.[1]??0)+r[1]]}))}return e.type==="repeat"?Array.from({length:Ao(e.times,t)},(r,o)=>Tt(e.step,{...t,i:o},[...n,o]).map(s=>({...s,id:s.id&&`${s.id}-${o}`}))).flat():e.type==="when"?B(e.if,t)!==0?e.steps.flatMap((r,o)=>Tt(r,t,[...n,o])):[]:[{step:e,scope:t,path:n,id:e.id}]}var St=(e,t)=>e.includes("{")?nt(e,t):e;function hr(e,t){let n=r=>[B(r[0],t),B(r[1],t)];switch(e.type){case"prop":case"text":case"card":case"counter":case"lottie":return n(e.at);case"circle":case"ellipse":return n(e.center);case"line":case"arrow":case"highlight":return n(e.from);case"polyline":case"polygon":case"curve":return n(e.points[0]);case"plot":return[B(e.box.x,t),B(e.box.y,t)];case"row":case"column":case"grid":case"chain":return n(e.at);case"axis":case"timeline":case"brace":return n(e.from);case"note":case"table":return n(e.at);case"bars":return[B(e.box.x,t),B(e.box.y,t)];default:return null}}function Yt(e,t,n=0){let[r,o]=[e.x+e.w/2,e.y+e.h/2],[s,a]=[t[0]-r,t[1]-o],i=Math.hypot(s,a);if(i===0)return[r,o];let c=s===0?1/0:e.w/2/Math.abs(s),l=a===0?1/0:e.h/2/Math.abs(a),h=Math.min(c,l);return[r+s*h+s/i*n,o+a*h+a/i*n]}function rn(e,t,n=8){let r=[e.x+e.w/2,e.y+e.h/2],o=[t.x+t.w/2,t.y+t.h/2];return[Yt(e,o,n),Yt(t,r,n)]}function ur(e,t,n=16){let[r,o]=[t[0]-e[0],t[1]-e[1]],s=Math.hypot(r,o)||1,[a,i]=[-o/s,r/s];(i>0||i===0&&a<0)&&([a,i]=[-a,-i]);let c=[(e[0]+t[0])/2,(e[1]+t[1])/2];return{at:[c[0]+a*n,c[1]+i*n],anchor:a>.5?"start":a<-.5?"end":"middle"}}function on(e,t,n,r="line"){if(r==="line")return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n];let[o,s]=[t[0]-e[0],t[1]-e[1]],a=Math.hypot(o,s),[i,c]=a?[-s/a,o/a]:[0,0];c>0&&([i,c]=[-i,-c]);let l=[(e[0]+t[0])/2+i*a*.3,(e[1]+t[1])/2+c*a*.3],h=1-n;return[h*h*e[0]+2*h*n*l[0]+n*n*t[0],h*h*e[1]+2*h*n*l[1]+n*n*t[1]]}var sn=(e,t)=>Number.isInteger(e)?Math.round(e*t):e*t,$e=(e,t,n,r)=>nt(e??"{v}",{...n,v:t},r);function ve(e){let t=0;for(let n of e)n.type==="move"&&n.ms?t=Math.max(t,n.ms):n.type==="repeat"?t=Math.max(t,ve([n.step])):n.type==="when"&&(t=Math.max(t,ve(n.steps)));return t}var dt=e=>Math.round(e*100)/100,cr=e=>Math.max(0,e.w)*Math.max(0,e.h);function Oo(e,t){let n=Math.min(e.x+e.w,t.x+t.w)-Math.max(e.x,t.x),r=Math.min(e.y+e.h,t.y+t.h)-Math.max(e.y,t.y);return n>0&&r>0?n*r:0}function an(e,t,n,r=24,o="center"){let s=(c,l,h)=>o==="start"?c:o==="end"?c+l-h:c+(l-h)/2,[a,i]=n==="below"?[s(t.x,t.w,e.w),t.y+t.h+r]:n==="above"?[s(t.x,t.w,e.w),t.y-r-e.h]:n==="right"?[t.x+t.w+r,s(t.y,t.h,e.h)]:[t.x-r-e.w,s(t.y,t.h,e.h)];return[dt(a-e.x),dt(i-e.y)]}function dr(e,t,n,r=24,o="center",s=1){if(!t.length)return[];if(e==="grid"){let l=Math.max(1,s),h=Math.max(...t.map(d=>d.w)),u=Math.max(...t.map(d=>d.h));return t.map((d,p)=>{let[m,g]=[p%l,Math.floor(p/l)];return[dt(n[0]+m*(h+r)+(h-d.w)/2-d.x),dt(n[1]+g*(u+r)+(u-d.h)/2-d.y)]})}let a=e==="row",i=Math.max(...t.map(l=>a?l.h:l.w)),c=a?n[0]:n[1];return t.map(l=>{let[h,u]=a?[l.w,l.h]:[l.h,l.w],d=o==="start"?0:o==="end"?i-u:(i-u)/2,[p,m]=a?[c,n[1]+d]:[n[0]+d,c];return c+=h+r,[dt(p-l.x),dt(m-l.y)]})}var nn=16,Po=240,Lo=90;function pr(e,t,n,r={},o=30){if(!e.length)return{deltas:[],lines:[]};let s=r.direction==="down",a=p=>s?p.h:p.w,i=(s?n.h-t[1]:n.w-t[0])-o,c=p=>r.gap!==void 0&&r.gap!=="auto"?r.gap:p.length<2?nn:Math.min(Po,Math.max(nn,(i-p.reduce((m,g)=>m+g,0))/(p.length-1))),l=[[]],h=0;e.forEach((p,m)=>{let g=l[l.length-1],f=(g.length?nn:0)+a(p);r.wrap&&g.length&&h+f>i?(l.push([m]),h=a(p)):(g.push(m),h+=f)});let u=new Array(e.length),d=s?t[0]:t[1];for(let p of l){let m=c(p.map(b=>a(e[b]))),g=Math.max(...p.map(b=>s?e[b].w:e[b].h)),f=s?t[1]:t[0];for(let b of p){let y=e[b],[w,k]=s?[d+(g-y.w)/2,f]:[f,d+g-y.h];u[b]=[dt(w-y.x),dt(k-y.y)],f+=a(y)+m}d+=g+Lo}return{deltas:u,lines:l}}function fr(e,t,n=!1,r=8){if(n){let[i,c]=[e.x+e.w/2,t.x+t.w/2],[l,h]=[e.y+e.h+24,t.y-24],u=(e.x+e.w+t.x)/2;return[[i,e.y+e.h+r],[i,l],[u,l],[u,h],[c,h],[c,t.y-r]]}let o=e.x+e.w+24,s=(e.y+e.h+t.y)/2,a=t.x+t.w/2;return[[e.x+e.w+r,e.y+e.h/2],[o,e.y+e.h/2],[o,s],[a,s],[a,t.y-r]]}function ln(e,t,n,r=30){let o=(s,a,i)=>a>i-2*r?s<0||s+a>i?(i-a)/2-s:0:s<0?r-s:s+a>i?i-r-(s+a):0;return[dt(o(e.x,e.w,t)),dt(o(e.y,e.h,n))]}function mr(e,t,n,r=60,o=4){let s=a=>t.some(i=>Oo(a,i)>.2*Math.min(cr(a),cr(i)));if(!s(e))return 0;for(let a=o;a<=r;a+=o)for(let i of[a,-a]){let c={...e,y:e.y+i};if(c.y>=0&&c.y+c.h<=n&&!s(c))return i}return 0}function gr(e,t){if(Array.isArray(t))return t;let n=t??5;return n===0?[]:Array.from({length:n+1},(r,o)=>dt(e[0]+(e[1]-e[0])*o/n))}function cn(e,t,n,r){let o=(r-n[0])/(n[1]-n[0]);return!Number.isFinite(o)||o<-1e-9||o>1+1e-9?null:[dt(e[0]+(t[0]-e[0])*o),dt(e[1]+(t[1]-e[1])*o)]}function hn(e,t){let[n,r]=[t[0]-e[0],t[1]-e[1]],o=Math.hypot(n,r)||1,s=[-r/o,n/o];return(Math.abs(n)>=Math.abs(r)?s[1]<0:s[0]>0)&&(s=[-s[0],-s[1]]),[s[0]||0,s[1]||0]}var Co="http://www.w3.org/2000/svg",bt="#2B2B2B",To={"#2b2b2b":"#F4F1E8","#242424":"#F4F1E8",black:"#F4F1E8","#2f5bea":"#A8C1FF","#1f4e9a":"#A8C1FF",blue:"#A8C1FF","#c8442c":"#FF9F8A",red:"#FF9F8A","#2e8f62":"#93E2AE","#0e7a0b":"#93E2AE",green:"#93E2AE","#8c8578":"#CFC9BC","#5e5a52":"#D9D3C6",grey:"#CFC9BC",gray:"#CFC9BC","#ffffff":"#34493D","#fff":"#34493D",white:"#34493D"},zo=["text","card","prop","counter"],un={hand:"'Caveat', cursive",body:"'Shantell Sans', system-ui, sans-serif"},Vt=class extends Error{},br=e=>e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2,Bo="cubic-bezier(.45,0,.55,1)",Ro="[data-anim]{transform-box:fill-box;transform-origin:center}[data-anim=talk]{transform-origin:center bottom}@keyframes ct-spin{to{transform:rotate(360deg)}}@keyframes ct-drive{0%,100%{transform:translate(0,0)}25%{transform:translate(-5px,-2px) rotate(-1deg)}75%{transform:translate(5px,-2px) rotate(1deg)}}@keyframes ct-talk{0%,100%{transform:rotate(0) scaleY(1)}50%{transform:rotate(-2deg) scaleY(1.03)}}@keyframes ct-pulse{0%,100%{transform:scale(1)}50%{transform:scale(1.1)}}@keyframes ct-float{0%,100%{transform:translateY(0)}50%{transform:translateY(-7px)}}@keyframes ct-wisp{0%{opacity:0;transform:translateY(6px)}30%{opacity:.9}100%{opacity:0;transform:translateY(-14px)}}@media (prefers-reduced-motion:reduce){[data-anim]{animation:none!important}}",jo={spin:[3200,"linear"],drive:[1600,"ease-in-out"],talk:[900,"ease-in-out"],pulse:[1400,"ease-in-out"],float:[3e3,"ease-in-out"],wisp:[2100,"ease-out"]},pn;function yr(e){pn=e}var wr="@keyframes ct-draw{from{stroke-dasharray:var(--l) var(--l);stroke-dashoffset:var(--l)}to{stroke-dasharray:var(--l) var(--l);stroke-dashoffset:0}}@keyframes ct-write{from{transform:scaleX(0)}}@keyframes ct-fade{from{opacity:0}}@keyframes ct-show{0%,100%{opacity:1}}@keyframes ct-wait{0%,100%{opacity:0}}@keyframes ct-move{from{transform:translate(var(--fx),var(--fy))}50%{transform:translate(var(--mx),var(--my))}}@media (prefers-reduced-motion:reduce){*{animation:none!important}}";function _(e,t={}){let n=document.createElementNS(Co,e);for(let[r,o]of Object.entries(t))n.setAttribute(r,String(o));return n}var dn=e=>[e.x+e.w/2,e.y+e.h/2];function No(e){return 1e3+e*97}function Se(e,t=e.steps.length-1){let n=[],r=Math.min(t,e.steps.length-1);for(let o=0;o<=r;){let s=e.steps[o],a=o;if(s.type!=="pause")for(;a<r;){let c=e.steps[a+1];if(c.type==="pause"||c.say||c.chapter)break;a++}let i=s.type==="pause"?s.ms:s.duration===0?0:Math.min(1600,Math.max(1e3,s.duration??(s.type==="text"?1400:1100)));n.push({start:o,end:a,duration:s.type==="pause"?i:Math.max(i,ve(e.steps.slice(o,a+1)))}),o=a+1}return n}function Mt(e,t){let n={};for(let[r,o]of Object.entries(e.params??{}))n[r]=t[r]??o.value;for(let[r,o]of Object.entries(e.switches??{}))n[r]=t[r]??(o.on?1:0)?1:0;for(let[r,o]of Object.entries(e.vars??{}))n[r]=B(o,n);return n}var Io=0,at=class{constructor(t,n=()=>{}){q(this,"uid",`dw${++Io}`);q(this,"gen",Xn.generator());q(this,"run",0);q(this,"speed",1);q(this,"layers");q(this,"defs");q(this,"named",new Map);q(this,"locale");q(this,"paper",{w:0,h:0});q(this,"textBoxes",[]);q(this,"leafNudge");q(this,"theme","paper");q(this,"css",!1);q(this,"figures",{});q(this,"motion","run");q(this,"beatAt",0);q(this,"steam",new Map);q(this,"scene");q(this,"lotties",{});q(this,"playing",[]);q(this,"svg");q(this,"onSay");this.svg=t,this.onSay=n}stop(){this.run++,this.layers&&(this.layers.pencil.style.opacity="0")}setSpeed(t){if(!Number.isFinite(t)||t<=0)throw new Error("The speed must be a positive number.");this.speed=t}async render(t,n,r){let o=++this.run;this.setSpeed(r.speed??1);let s=Mt(t,n);this.locale=t.locale,this.theme=r.theme??t.theme??"paper",this.css=!!r.css&&!r.animate,this.motion=r.motion??"run",this.scene=t,this.setup(t);let a=0;try{for(let i of Se(t,r.until)){if(o!==this.run)throw new Vt;this.beatAt=a;let c=[],l,h=r.animate&&i.start>=(r.from??0);for(let u=i.start;u<=i.end;u++){let d=t.steps[u];if(r.onStep?.(u),d.say&&this.onSay(l=nt(d.say,s,t.locale)),d.type!=="pause"){let p=this.made(()=>{for(let m of Tt(d,s))c.push(...this.buildLeaf(m,u,h))});for(let m of p)m.dataset.step=String(u)}}if(this.css&&(t.steps[i.start].type!=="pause"&&this.schedule(c,a,i.duration),a+=i.duration),h&&r.beforeBeat&&(await r.beforeBeat(l,i.start),o!==this.run))throw new Vt;h&&(t.steps[i.start].type==="pause"?(this.layers.pencil.style.opacity="0",await this.tween(i.duration,o,()=>{})):await this.play(c,i.duration,o))}r.animate&&(this.layers.pencil.style.opacity="0")}catch(i){if(!(i instanceof Vt))throw i}}setup(t){this.figures=Do(t.defs),this.steam.clear(),this.lotties=t.lotties??{};for(let c of this.playing)c.destroy();this.playing=[];let n=this.svg;if(n.replaceChildren(),n.setAttribute("viewBox",`0 0 ${t.width} ${t.height}`),n.style.aspectRatio=`${t.width} / ${t.height}`,n.setAttribute("aria-label",t.title),this.defs=_("defs"),n.append(this.defs),JSON.stringify(t.steps).includes('"type":"animate"')){let c=_("style");c.textContent=Ro,n.append(c)}let r=t.background??"dots",o=this.theme==="chalkboard";if(r!=="plain"){let c=_("pattern",{id:`${this.uid}-paper`,width:r==="grid"?24:22,height:r==="grid"?24:22,patternUnits:"userSpaceOnUse"});c.append(r==="grid"?_("path",{d:"M24 0H0V24",fill:"none",stroke:o?"#33473B":"#DCE5EF","stroke-width":1}):_("circle",{cx:11,cy:11,r:1.2,fill:o?"#3A5043":"#D9D2C3"})),this.defs.append(c)}n.append(_("rect",{width:t.width,height:t.height,fill:o?"#26372E":"#FBF7EE"})),r!=="plain"&&n.append(_("rect",{width:t.width,height:t.height,fill:`url(#${this.uid}-paper)`}));let s=_("g"),a=_("g"),i=this.makePencil();n.append(s,a,i),this.layers={highlight:s,ink:a,pencil:i},this.named.clear(),this.paper={w:t.width,h:t.height},this.textBoxes=[]}made(t){let n=[this.layers.ink,this.layers.highlight],r=n.map(o=>o.childElementCount);return t(),n.flatMap((o,s)=>[...o.children].slice(r[s]))}seedOf(t,n){return No(t)+n.reduce((r,o)=>r*31+o+1,0)*7}buildLeaf(t,n,r){var h;let o=t.step.type;if(o==="row"||o==="column"||o==="grid")return this.arrange(t,n,r);if(o==="chain")return this.chain(t,n,r);let s=[n,...t.path].join("_"),a=this.seedOf(n,t.path),i=t.arranged?t.step:this.settle(t,s,a),c=[];this.leafNudge=t.nudge;let l=this.made(()=>{c=this.build(i,s,a,t.scope,r)});this.leafNudge=void 0;for(let u of l)(h=u.dataset).type??(h.type=i.type);if(l.length&&(i.type==="text"||i.type==="counter")&&this.textBoxes.push(this.boxOf(l,0,0)),t.id&&l.length){let u=hr(i,t.scope)??dn(this.boxOf(l,0,0));this.named.set(t.id,{els:l,anchor:u,dx:0,dy:0})}return c}measure(t){let n=[this.layers.ink,this.layers.highlight,this.defs],r=n.map(i=>i.childElementCount);t();let o=n.map((i,c)=>[...i.children].slice(r[c])),s=[...o[0],...o[1]],a=s.length?this.boxOf(s,0,0):null;return o.flat().forEach(i=>i.remove()),a}settle(t,n,r){let o=t.step,s=o.type==="text"?!o.rotate:zo.includes(o.type);if(!(o.place&&$t.includes(o.type))&&!s)return o;let a=this.measure(()=>this.build(o,n,r,t.scope,!1));if(!a)return o;let[i,c]=[0,0],l=o.place&&this.named.get(St(o.place.to,t.scope));if(o.place&&l&&([i,c]=an(a,this.boxOf(l.els,l.dx,l.dy),o.place.side,o.place.gap,o.place.align),i+=t.nudge?.[0]??0,c+=t.nudge?.[1]??0),s){let h={...a,x:a.x+i,y:a.y+c},[u,d]=ln(h,this.paper.w,this.paper.h);i+=u,c+=d,(o.type==="text"||o.type==="counter")&&(c+=mr({...h,x:h.x+u,y:h.y+d},this.textBoxes,this.paper.h))}return i||c?zt(o,i,c):o}arrange(t,n,r){let o=t.step,s=o.steps.flatMap((h,u)=>Tt(h,t.scope,[...t.path,u])),a=s.map(h=>this.measure(()=>this.build(h.step,[n,...h.path].join("_"),this.seedOf(n,h.path),h.scope,!1))??{x:0,y:0,w:0,h:0}),i=dr(o.type,a,this.pt(o.at,t.scope),o.gap??24,o.type==="grid"?"center":o.align??"center",o.type==="grid"?o.columns:1),c=[],l=this.made(()=>{c=s.flatMap((h,u)=>this.buildLeaf({...h,step:zt(h.step,...i[u]),arranged:!0},n,r))});if(t.id&&l.length){let h=this.boxOf(l,0,0);this.named.set(t.id,{els:l,anchor:dn(h),dx:0,dy:0})}return c}chain(t,n,r){let o=t.step,a=o.steps.map(g=>o.size!==void 0&&g.type==="prop"&&g.size===void 0?{...g,size:o.size}:g).flatMap((g,f)=>Tt(g,t.scope,[...t.path,f])),i=a.map(g=>this.measure(()=>this.build(g.step,[n,...g.path].join("_"),this.seedOf(n,g.path),g.scope,!1))??{x:0,y:0,w:0,h:0}),c=o.direction==="down",{deltas:l,lines:h}=pr(i,this.pt(o.at,t.scope),this.paper,{gap:o.gap,direction:o.direction,wrap:o.wrap}),u=i.map((g,f)=>({...g,x:g.x+l[f][0],y:g.y+l[f][1]})),d=this.roughOpts(o.style,this.seedOf(n,[...t.path,99])),p=[],m=this.made(()=>{p=a.flatMap((y,w)=>this.buildLeaf({...y,step:zt(y.step,...l[w]),arranged:!0},n,r));let g={...o.style,color:o.style?.color??"#8C8578"};h.forEach((y,w)=>{y.slice(1).forEach(M=>p.push(...this.arrow(...rn(u[M-1],u[M]),{...d,seed:d.seed+M},g,r)));let k=h[w+1];if(!k)return;let v=fr(u[y[y.length-1]],u[k[0]],c);p.push(...this.addDrawable(this.gen.linearPath(v.slice(0,-1),{...d,seed:d.seed+50+w}),g,r)),p.push(...this.arrow(v[v.length-2],v[v.length-1],{...d,seed:d.seed+60+w},g,r))});let f={x:Math.min(...u.map(y=>y.x)),y:Math.min(...u.map(y=>y.y)),w:0,h:0};f.w=Math.max(...u.map(y=>y.x+y.w))-f.x,f.h=Math.max(...u.map(y=>y.y+y.h))-f.y;let b=(y,w,k,v)=>{let M=34+w*70,[S,R]=c?[[f.x+f.w+M,f.y],[f.x+f.w+M,f.y+f.h]]:[[f.x,f.y+f.h+M],[f.x+f.w,f.y+f.h+M]],C={...o.style,color:k,width:3};p.push(...this.arrow(v?R:S,v?S:R,{...this.roughOpts(C,d.seed+80+w)},C,r));let L=c?{type:"text",at:[S[0]+14,(S[1]+R[1])/2],text:y,size:24,anchor:"start",style:{color:k}}:{type:"text",at:[(S[0]+R[0])/2,S[1]+32],text:y,size:24,anchor:"middle",style:{color:k}};p.push(this.addText(L,`${n}-chain-${w}`,t.scope,r))};o.forward&&b(o.forward,0,"#2E8F62",!1),o.back&&b(o.back,o.forward?1:0,"#2F5BEA",!0)});if(t.id&&m.length){let g=this.boxOf(m,0,0);this.named.set(t.id,{els:m,anchor:dn(g),dx:0,dy:0})}return p}animate(t,n){let r=St(t.target,n),o=this.named.get(r);if(!o)return;let s=o.els.map(h=>h.querySelector("[data-body]")??h);this.steam.get(r)?.remove(),this.steam.delete(r);for(let h of s)delete h.dataset.anim,h.style.animation="";if(t.effect==="stop")return;let a=t.speed==="slow"?1.6:t.speed==="fast"?.6:1,i=(h,u,d=0)=>{let[p,m]=jo[u];h.dataset.anim=u,h.dataset.animStart=String(performance.now()-d);let g=this.motion==="rest"?-(u==="wisp"?p*a*.3:0):this.css?this.beatAt+d:-d;h.style.animation=`ct-${u} ${Math.round(p*a)}ms ${m} ${Math.round(g)}ms infinite`,this.motion==="rest"&&(h.style.animationPlayState="paused")};if(t.effect!=="steam"){for(let h of s)i(h,t.effect);return}let c=this.boxOf(o.els,o.dx,o.dy),l=_("g");l.dataset.steam=r,[-.18,0,.18].forEach((h,u)=>{let d=c.x+c.w*(.5+h),p=_("path",{d:`M${d} ${c.y-4} q 6 -9 0 -18 q -6 -9 0 -18`,fill:"none",stroke:"#8C8578","stroke-width":2,"stroke-linecap":"round"});l.append(p),i(p,"wisp",u*700)}),this.layers.ink.append(l),this.steam.set(r,l)}lottie(t,n,r,o){let[s,a]=this.pt(t.at,r),i=t.size===void 0?120:B(t.size,r),[c,l]=[s-i/2,a-i/2],h=_("g");h.dataset.lottie=t.src,this.layers.ink.append(h),h.append(_("rect",{x:c,y:l,width:i,height:i,fill:"none",stroke:"none","data-box":1}));let u=this.lotties[t.src];if(u&&pn){let d=_("g");h.append(d);let p=pn.loadAnimation({container:d,renderer:"svg",loop:t.loop??!0,autoplay:this.motion==="run"&&!this.css,animationData:JSON.parse(JSON.stringify(u))}),m=d.querySelector("svg");if(m)for(let[g,f]of Object.entries({x:c,y:l,width:i,height:i}))m.setAttribute(g,String(f));(this.motion==="rest"||this.css)&&p.goToAndStop(Math.floor(p.totalFrames/2),!0),this.playing.push(p)}else{let d=this.roughOpts({color:"#8C8578",dashed:!0},Number(n.split("_")[0])*7+3);h.append(...this.made(()=>this.addDrawable(this.gen.rectangle(c,l,i,i,d),{color:"#8C8578",dashed:!0},!1))),this.addText({type:"text",at:[s,a+8],text:`\u25B6 ${t.src}`,size:20,anchor:"middle",style:{color:"#8C8578"}},`${n}-lottie`,r,!1,h)}return o&&(h.style.opacity="0"),[{kind:"fade",el:h,opacity:1}]}boxOf(t,n,r){let o=t.map(l=>l.getBBox()),s=Math.min(...o.map(l=>l.x)),a=Math.min(...o.map(l=>l.y)),i=Math.max(...o.map(l=>l.x+l.width))-s,c=Math.max(...o.map(l=>l.y+l.height))-a;return{x:s+n,y:a+r,w:i,h:c}}place(t,n,r){for(let o of t.els)o.dataset.base===void 0&&(o.dataset.base=o.getAttribute("transform")??""),o.setAttribute("transform",`translate(${n} ${r}) ${o.dataset.base}`.trim()),o.dataset.dx=String(n),o.dataset.dy=String(r)}makePencil(){let t=_("g",{"aria-hidden":"true",class:"dw-pencil"});t.style.opacity="0",t.style.transition="opacity .25s",t.style.pointerEvents="none";let n=_("g",{transform:"translate(-3,-46) scale(1.15)"});return n.append(_("path",{d:"M3 40 L 8 28 L 33 3 L 41 11 L 16 36 Z",fill:"#FFD25E",stroke:bt,"stroke-width":2,"stroke-linejoin":"round"}),_("path",{d:"M3 40 L 8 28 L 16 36 Z",fill:"#F1D9B5",stroke:bt,"stroke-width":2,"stroke-linejoin":"round"}),_("path",{d:"M3 40 L 5.3 34.4 L 8.6 37.7 Z",fill:bt}),_("path",{d:"M29 7 L 37 15",stroke:bt,"stroke-width":2})),t.append(n),t}roughOpts(t,n){return{stroke:t?.color??bt,strokeWidth:t?.width??2.6,roughness:t?.roughness??1.6,bowing:t?.bowing??1.4,fill:t?.fill,fillStyle:t?.fillStyle??"hachure",hachureGap:7,seed:n}}tint(t){return t&&this.theme==="chalkboard"?To[t.toLowerCase()]??t:t}pt(t,n){return[B(t[0],n),B(t[1],n)]}build(t,n,r,o,s){let a=this.roughOpts(t.style,r),i=this.gen,c=l=>this.pt(l,o);switch(t.type){case"card":{let[l,h]=c(t.at),u=B(t.w,o),d=B(t.h,o),p=t.lines??[];if(u<40||d<70+p.length*28)throw new Error(`Card "${t.title}": not enough room for its content.`);let m=this.addDrawable(i.rectangle(l,h,u,d,a),t.style,s);return[t.title,...p].forEach((f,b)=>{let y=this.addText({type:"text",at:[l+u/2,h+38+b*28],text:f,size:b===0?30:22,anchor:"middle",style:{color:t.style?.color}},`${n}-${b}`,o,s);if(y.width>u-24)throw new Error(`Card "${t.title}": text too wide; raise w or shorten the line.`);m.push(y)}),m}case"line":return this.addDrawable(i.line(...c(t.from),...c(t.to),a),t.style,s);case"arrow":return this.arrow(c(t.from),c(t.to),a,t.style,s);case"polyline":return this.addDrawable(i.linearPath(t.points.map(c),a),t.style,s);case"polygon":return this.addDrawable(i.polygon(t.points.map(c),a),t.style,s);case"curve":return this.addDrawable(i.curve(t.points.map(c),a),t.style,s);case"circle":{let[l,h]=c(t.center);return this.addDrawable(i.circle(l,h,B(t.r,o)*2,a),t.style,s)}case"ellipse":{let[l,h]=c(t.center);return this.addDrawable(i.ellipse(l,h,B(t.rx,o)*2,B(t.ry,o)*2,a),t.style,s)}case"plot":return this.addDrawable(i.curve(this.samplePlot(t,o),a),t.style,s);case"highlight":{let[l,h]=c(t.from),[u,d]=c(t.to),p=_("path",{d:`M${l} ${h} L${u} ${d}`,stroke:this.theme==="chalkboard"&&!t.style?.color?"#7C6E26":this.tint(t.style?.color??"#FFE45C")??"#FFE45C","stroke-width":t.thickness??18,"stroke-linecap":"round",fill:"none",opacity:t.style?.opacity??.8});return p.dataset.marker="1",this.layers.highlight.append(p),[this.hide(p,s)]}case"text":return[this.addText(t,n,o,s)];case"pause":case"repeat":case"when":case"row":case"column":case"grid":case"chain":return[];case"axis":case"timeline":return this.line(t,n,a,o,s);case"balloon":return this.balloon(t,n,a,o,s);case"brace":return this.brace(t,n,a,o,s);case"note":return this.note(t,n,a,o,s);case"table":return this.table(t,n,a,o,s);case"bars":return this.bars(t,n,a,o,s);case"prop":return this.prop(t,n,a,o,s);case"counter":{let[l,h]=c(t.at),u=B(t.value,o),d=_("g"),p=_("text",{x:l,y:h,fill:this.tint(t.style?.color??bt)??bt,"font-family":un.hand,"font-size":t.size??34,"font-weight":700,"text-anchor":t.anchor??"start"});return p.textContent=$e(t.format,s?0:u,o,this.locale),d.append(p),this.layers.ink.append(d),[{kind:"count",el:p,format:t.format,value:u,scope:o,locale:this.locale}]}case"link":{let[l,h]=[this.named.get(St(t.from,o)),this.named.get(St(t.to,o))];if(!l||!h)return[];let[u,d]=rn(this.boxOf(l.els,l.dx,l.dy),this.boxOf(h.els,h.dx,h.dy)),p=this.arrow(u,d,a,t.style,s);if(t.label){let m=ur(u,d);p.push(this.addText({type:"text",at:m.at,text:t.label,size:22,anchor:m.anchor,style:{color:t.style?.color}},`${n}-label`,o,s))}return p}case"animate":return this.animate(t,o),[];case"lottie":return this.lottie(t,n,o,s);case"move":{let l=this.named.get(St(t.target,o));if(!l)return[];let[h,u]=c(t.to),d=[l.dx,l.dy],p=[h-l.anchor[0],u-l.anchor[1]];return[l.dx,l.dy]=p,s?[{kind:"move",entry:l,from:d,to:p,along:t.along??"line",ms:t.ms}]:(this.place(l,...p),this.css?[{kind:"move",entry:l,from:d,to:p,along:t.along??"line",ms:t.ms}]:[])}}}line(t,n,r,o,s){let[a,i]=[this.pt(t.from,o),this.pt(t.to,o)],c=[B(t.domain[0],o),B(t.domain[1],o)];if(c[0]===c[1])throw new Error(`${t.type==="axis"?"Axis":"Timeline"}: the domain needs two different ends.`);let l=hn(a,i),h=Math.abs(i[0]-a[0])>=Math.abs(i[1]-a[1]),u=t.style?.color,d=(f,b,y,w=22,k=h?"middle":l[0]<0?"end":"start",v="hand")=>this.addText({type:"text",at:f,text:b,size:w,anchor:k,font:v,style:{color:u}},`${n}-${y}`,o,s),p=(f,b,y)=>this.addDrawable(this.gen.line(f[0]-l[0]*y,f[1]-l[1]*y,f[0]+l[0]*y,f[1]+l[1]*y,{...r,seed:r.seed+10+b}),t.style,s),m=(f,b)=>[f[0]+l[0]*b,f[1]+l[1]*b+(h?l[1]>0?8:-2:7)];if(t.type==="axis"){let f=this.arrow(a,i,r,t.style,s);return gr(c,t.ticks).forEach((b,y)=>{let w=cn(a,i,c,b);w&&f.push(...p(w,y,7),d(m(w,22),nt(t.format??"{v}",{...o,v:b},this.locale),`t${y}`))}),t.label&&f.push(d(h?[i[0],i[1]+l[1]*56+8]:[i[0],i[1]-22],t.label,"label",24,h?"end":"middle")),f}let g=this.addDrawable(this.gen.line(...a,...i,r),t.style,s);return t.marks.forEach((f,b)=>{let y=cn(a,i,c,B(f.at,o));y&&(g.push(...p(y,b,10)),f.label&&g.push(d(m(y,-26),f.label,`l${b}`,26,h?"middle":l[0]<0?"start":"end")),f.text&&g.push(d(m(y,30),f.text,`x${b}`,21)))}),g}arrow(t,n,r,o,s){return[...this.addDrawable(this.gen.line(...t,...n,r),o,s),...this.head(t,n,r,o,s)]}head(t,n,r,o,s){let a=Math.atan2(n[1]-t[1],n[0]-t[0]),i=16,c=[n[0]-i*Math.cos(a-.45),n[1]-i*Math.sin(a-.45)],l=[n[0]-i*Math.cos(a+.45),n[1]-i*Math.sin(a+.45)];return this.addDrawable(this.gen.linearPath([c,n,l],{...r,seed:r.seed+1}),o,s)}textWidth(t,n,r,o=r==="body"?400:700){let s=_("text",{"font-family":un[r],"font-size":n,"font-weight":o});s.textContent=t,this.layers.ink.append(s);let a=s.getComputedTextLength();return s.remove(),a}wrap(t,n,r){let o=[];for(let s of t.split(/\s+/).filter(Boolean)){let a=o.at(-1);a!==void 0&&this.textWidth(`${a} ${s}`,n,"hand")<=r?o[o.length-1]=`${a} ${s}`:o.push(s)}return o}balloon(t,n,r,o,s){let a=this.named.get(St(t.to,o));if(!a)return[];let i=this.boxOf(a.els,a.dx,a.dy),c=t.size??24,l=this.wrap(nt(t.text,o,this.locale),c,t.width??240),h=Math.max(...l.map(L=>this.textWidth(L,c,"hand")))+32,u=l.length*c*1.2+22,d=[t.side??"above","right","left","above","below"],p=(L,[D,I])=>L==="above"||L==="below"?[Math.max(30,Math.min(D,this.paper.w-30-h)),I]:[D,Math.max(30,Math.min(I,this.paper.h-30-u))],m=d.map(L=>p(L,an({x:0,y:0,w:h,h:u},i,L,28))),[g,f]=m.find(([L,D])=>L>=0&&D>=0&&L+h<=this.paper.w&&D+u<=this.paper.h)??m[0];g+=this.leafNudge?.[0]??0,f+=this.leafNudge?.[1]??0;let[b,y]=ln({x:g,y:f,w:h,h:u},this.paper.w,this.paper.h);[g,f]=[g+b,f+y];let w=16,k=`M${g+w} ${f} H${g+h-w} Q${g+h} ${f} ${g+h} ${f+w} V${f+u-w} Q${g+h} ${f+u} ${g+h-w} ${f+u} H${g+w} Q${g} ${f+u} ${g} ${f+u-w} V${f+w} Q${g} ${f} ${g+w} ${f} Z`,v={...r,fill:t.style?.fill??"#FFFFFF",fillStyle:"solid",roughness:Math.min(r.roughness??1.6,1)},M=this.addDrawable(this.gen.path(k,v),t.style,s),S=[g+h/2,f+u/2],R=Yt(i,S,6),C=Yt({x:g,y:f,w:h,h:u},R,0);if(t.kind==="thought")for(let[L,D,I]of[[.35,7,2],[.7,4,3]]){let W=[C[0]+(R[0]-C[0])*L,C[1]+(R[1]-C[1])*L];M.push(...this.addDrawable(this.gen.circle(W[0],W[1],D*2,{...v,seed:r.seed+I}),t.style,s))}else{let L=Math.abs(C[0]-S[0])*u>Math.abs(C[1]-S[1])*h?[0,1]:[1,0],D=[C[0]-L[0]*10,C[1]-L[1]*10],I=[C[0]+L[0]*10,C[1]+L[1]*10];M.push(...this.addDrawable(this.gen.polygon([D,R,I],{...v,seed:r.seed+2}),t.style,s))}return l.forEach((L,D)=>{M.push(this.addText({type:"text",at:[S[0],f+11+c*1.2*(D+1)-c*.25],text:L,size:c,anchor:"middle",style:{color:t.style?.color}},`${n}-${D}`,o,s))}),M}brace(t,n,r,o,s){let[a,i]=[this.pt(t.from,o),this.pt(t.to,o)],c=hn(a,i),l=t.flip?[-c[0],-c[1]]:c,h=Math.hypot(i[0]-a[0],i[1]-a[1])||1,u=[(i[0]-a[0])/h,(i[1]-a[1])/h],d=Math.min(16,h*.08),p=(g,f)=>[a[0]+u[0]*h*g+l[0]*f,a[1]+u[1]*h*g+l[1]*f],m=this.addDrawable(this.gen.curve([a,p(.06,d),p(.44,d),p(.5,d*2),p(.56,d),p(.94,d),i],r),t.style,s);if(t.label){let g=Math.abs(u[0])>=Math.abs(u[1]),f=p(.5,d*2+22),b=g?"middle":l[0]<0?"end":"start";m.push(this.addText({type:"text",at:[f[0],f[1]+(g?l[1]>0?8:-2:7)],text:t.label,size:24,anchor:b,style:{color:t.style?.color}},`${n}-label`,o,s))}return m}note(t,n,r,o,s){let a=t.style?.color??"#2F5BEA",i=[],c=this.made(()=>{i.push(this.addText({type:"text",at:t.at,text:t.text,size:t.size??24,style:{color:a}},`${n}-text`,o,s))}),l=this.boxOf(c,0,0),h=t.to!==void 0?this.named.get(St(t.to,o)):void 0;if(t.to!==void 0&&!h)return i;let u=h?this.boxOf(h.els,h.dx,h.dy):null,d=u?[u.x+u.w/2,u.y+u.h/2]:this.pt(t.point,o),[p,m]=[l.x+l.w/2,l.y+l.h/2],g=d[1]>l.y+l.h,f=d[1]<l.y,b=g?[p,l.y+l.h+6]:f?[p,l.y-6]:d[0]>p?[l.x+l.w+8,m]:[l.x-8,m],y=u?Yt(u,b,8):d,[w,k]=[(b[0]+y[0])/2,(b[1]+y[1])/2],v=Math.hypot(y[0]-b[0],y[1]-b[1])||1,M=I=>[w-(y[1]-b[1])/v*v*.22*I,k+(y[0]-b[0])/v*v*.22*I],[S,R]=[l.x+l.w/2,l.y+l.h/2],C=I=>Math.hypot(I[0]-S,I[1]-R),L=C(M(1))>=C(M(-1))?M(1):M(-1),D={...r,stroke:a};return i.push(...this.addDrawable(this.gen.curve([b,L,y],D),{...t.style,color:a},s),...this.head(L,y,D,{...t.style,color:a},s)),i}table(t,n,r,o,s){let[a,i]=this.pt(t.at,o),c=t.size??22,l=t.header??!0,h=t.rows.map(k=>k.map(v=>nt(v,o,this.locale))),u=Math.max(...h.map(k=>k.length)),d=k=>l&&k===0?"hand":"body",p=Array.from({length:u},(k,v)=>Math.max(40,...h.map((M,S)=>M[v]?this.textWidth(M[v],c,d(S)):0))+28),m=c*1.7,[g,f]=[p.reduce((k,v)=>k+v,0),m*h.length],b=this.addDrawable(this.gen.rectangle(a,i,g,f,r),t.style,s),y=r.seed+3;for(let k=1;k<h.length;k++)b.push(...this.addDrawable(this.gen.line(a,i+m*k,a+g,i+m*k,{...r,seed:y++,strokeWidth:l&&k===1?2.6:1.4}),t.style,s));let w=a;return p.slice(0,-1).forEach(k=>{w+=k,b.push(...this.addDrawable(this.gen.line(w,i,w,i+f,{...r,seed:y++,strokeWidth:1.4}),t.style,s))}),h.forEach((k,v)=>{let M=a;k.forEach((S,R)=>{S&&b.push(this.addText({type:"text",at:[M+p[R]/2,i+m*v+m*.66],text:S,size:c,font:d(v),anchor:"middle",style:{color:t.style?.color}},`${n}-${v}-${R}`,{},s)),M+=p[R]})}),b}bars(t,n,r,o,s){let[a,i,c,l]=[B(t.box.x,o),B(t.box.y,o),B(t.box.w,o),B(t.box.h,o)],h=t.values.map(f=>B(f,o)),u=()=>this.scene?Ct(this.scene).flatMap(f=>{let b={...o,...Mt(this.scene,f)};return t.values.map(y=>{try{return B(y,b)}catch{return 0}})}):h,d=t.max!==void 0?B(t.max,o):Math.max(...h,...u(),0)||1,p=c/h.length,m=t.style?.fill??"#2F5BEA",g=this.addDrawable(this.gen.line(a,i+l,a+c,i+l,r),t.style,s);return h.forEach((f,b)=>{let y=Math.max(0,Math.min(l,f/d*l)),w=a+p*b+p/2;y>=1&&g.push(...this.addDrawable(this.gen.rectangle(w-p*.3,i+l-y,p*.6,y,{...r,fill:m,fillStyle:t.style?.fillStyle??"hachure",seed:r.seed+5+b}),{...t.style,fill:m},s)),g.push(this.addText({type:"text",at:[w,i+l-y-10],text:nt(t.format??"{v}",{...o,v:f},this.locale),size:22,anchor:"middle",style:{color:t.style?.color}},`${n}-v${b}`,o,s));let k=t.labels?.[b];k&&g.push(this.addText({type:"text",at:[w,i+l+30],text:k,size:22,anchor:"middle",style:{color:t.style?.color}},`${n}-l${b}`,o,s))}),g}prop(t,n,r,o,s){let[a,i]=this.pt(t.at,o),c=t.size===void 0?tn:B(t.size,o),l=_("g");l.dataset.prop=t.name,this.layers.ink.append(l);let h=_("g");h.dataset.body="1",l.append(h);let u=t.style?.width??Math.max(1.2,Math.min(2.6,c/36)),d=[];return tr(t.name,[a,i],c,t.flip??!1,t.mood,this.figures).forEach((p,m)=>{let g=p.kind!=="circle"&&p.kind!=="polygon"?void 0:p.main&&t.style?.fill?t.style.fill:p.fill,f=p.fine?{...r,strokeWidth:Math.max(.8,u*.45),roughness:.3,bowing:0,fill:g,fillStyle:"solid",seed:r.seed+m}:{...r,strokeWidth:u,fill:g,fillStyle:t.style?.fillStyle??"solid",seed:r.seed+m},b=p.kind==="circle"?this.gen.circle(p.c[0],p.c[1],p.r*2,f):p.kind==="polygon"?this.gen.polygon(p.points,f):p.kind==="curve"?this.gen.curve(p.points,f):this.gen.linearPath(p.points,f);d.push(...this.addDrawable(b,{opacity:t.style?.opacity,dashed:t.style?.dashed},s,h))}),t.label&&d.push(this.addText({type:"text",at:[a,i+28],text:t.label,size:22,anchor:"middle",style:{color:t.style?.color}},`${n}-label`,o,s,l)),d}samplePlot(t,n){let r=t.var??"x",[o,s]=[B(t.domain[0],n),B(t.domain[1],n)],[a,i]=[B(t.range[0],n),B(t.range[1],n)];if(o===s||a===i)throw new Error("Plot: domain and range need different ends.");let c=B(t.box.x,n),l=B(t.box.y,n),h=B(t.box.w,n),u=B(t.box.h,n),d=t.samples??40,p=[];for(let m=0;m<=d;m++){let g=o+(s-o)*m/d,f=B(t.fn,{...n,[r]:g}),b=l+u-(f-a)/(i-a)*u;p.push([c+(g-o)/(s-o)*h,Math.max(l,Math.min(l+u,b))])}return p}addDrawable(t,n,r,o=this.layers.ink){let s=[];return this.gen.toPaths(t).forEach(a=>{let i=_("path",{d:a.d,stroke:this.tint(a.stroke)??"none","stroke-width":a.strokeWidth,fill:this.tint(a.fill)??"none","stroke-linecap":"round","stroke-linejoin":"round"});n?.opacity!==void 0&&i.setAttribute("opacity",String(n.opacity)),n?.fill&&a.stroke===n.fill&&(a.fill??"none")==="none"&&(i.dataset.hatch="1"),o.append(i),a.fill&&a.fill!=="none"?(r&&(i.style.opacity="0"),s.push({kind:"fade",el:i,opacity:n?.opacity??1})):(s.push(this.hide(i,r)),n?.dashed&&(i.dataset.dashed="1"),n?.dashed&&!r&&i.setAttribute("stroke-dasharray","9 8"))}),s}hide(t,n){let r=t.getTotalLength();return n&&(t.style.strokeDasharray=`${r} ${r}`,t.style.strokeDashoffset=`${r}`),{kind:"path",el:t,length:r}}addText(t,n,r,o,s=this.layers.ink){let[a,i]=this.pt(t.at,r),c=t.rotate??0,l=_("g",c?{transform:`rotate(${c} ${a} ${i})`}:{}),h=_("text",{x:a,y:i,fill:this.tint(t.style?.color??bt)??bt,"font-family":un[t.font??"hand"],"font-size":t.size??30,"font-weight":t.font==="body"?400:700,"text-anchor":t.anchor??"start"});h.textContent=nt(t.text,r,this.locale),l.append(h),s.append(l);let u=h.getBBox(),d=`${this.uid}-clip-${this.run}-${n}`,p=_("clipPath",{id:d}),m=_("rect",{x:u.x-4,y:u.y-12,width:o?0:u.width+8,height:u.height+24});return p.append(m),this.defs.append(p),h.setAttribute("clip-path",`url(#${d})`),{kind:"text",clip:m,width:u.width+8,x:u.x-4,y:i+2,angle:c,ox:a,oy:i}}play(t,n,r){let o=t.find(s=>s.kind==="text")??t.find(s=>s.kind==="path");return this.layers.pencil.style.opacity=o?"1":"0",this.tween(n,r,s=>{for(let a of t)if(a.kind==="path")this.revealPath(a,s,a===o);else if(a.kind==="text")this.revealText(a,s,a===o);else if(a.kind==="count")a.el.textContent=$e(a.format,s===1?a.value:sn(a.value,s),a.scope,a.locale);else if(a.kind==="move"){let i=a.ms?Math.min(1,s*n/a.ms):s;this.place(a.entry,...on(a.from,a.to,i,a.along))}else a.el.style.opacity=String(s*a.opacity)})}revealPath(t,n,r){let o=t.length*n;if(t.el.style.strokeDashoffset=String(t.length-o),r){let s=t.el.getPointAtLength(o);this.layers.pencil.setAttribute("transform",`translate(${s.x} ${s.y})`)}n===1&&(t.el.style.strokeDasharray="",t.el.style.strokeDashoffset="",t.el.dataset.dashed&&t.el.setAttribute("stroke-dasharray","9 8"))}revealText(t,n,r){let o=t.width*n;if(t.clip.setAttribute("width",String(o)),!r)return;let s=this.layers.pencil,a=t.angle*Math.PI/180,i=t.x+o-t.ox,c=t.y-t.oy,l=t.ox+i*Math.cos(a)-c*Math.sin(a),h=t.oy+i*Math.sin(a)+c*Math.cos(a);s.setAttribute("transform",`translate(${l} ${h-6-Math.abs(Math.sin(n*40))*7})`)}schedule(t,n,r){if(r<=0)return;let o=(s,a,i=r,c=n,l=Bo,h="backwards")=>{s.style.animation=`${a} ${Math.round(i)}ms ${l} ${Math.round(c)}ms ${h}`};for(let s of t)if(s.kind==="path")s.el.style.setProperty("--l",String(Math.ceil(s.length)+1)),o(s.el,"ct-draw");else if(s.kind==="text")s.clip.style.transformBox="fill-box",s.clip.style.transformOrigin="0 0",o(s.clip,"ct-write");else if(s.kind==="fade")o(s.el,"ct-fade");else if(s.kind==="count"){let i=r/12;for(let c=0;c<12;c++){let l=s.el.cloneNode();l.textContent=$e(s.format,sn(s.value,br(c/12)),s.scope,s.locale),l.style.opacity="0",o(l,"ct-show",i,n+c*i,"step-end","none"),s.el.before(l)}o(s.el,"ct-wait",n+r,0,"step-end")}else if(s.kind==="move"){let a=on(s.from,s.to,.5,s.along);for(let i of s.entry.els){let c=_("g");i.replaceWith(c),c.append(i),c.style.setProperty("--fx",`${s.from[0]-s.to[0]}px`),c.style.setProperty("--fy",`${s.from[1]-s.to[1]}px`),c.style.setProperty("--mx",`${a[0]-s.to[0]}px`),c.style.setProperty("--my",`${a[1]-s.to[1]}px`),o(c,"ct-move",s.ms??r)}}}tween(t,n,r){return new Promise((o,s)=>{let a=performance.now(),i=0,c=l=>{if(n!==this.run)return s(new Vt);i+=(l-a)*this.speed,a=l;let h=Math.min(1,i/Math.max(1,t));r(h===1?1:br(h)),h<1?requestAnimationFrame(c):o()};requestAnimationFrame(c)})}};function Do(e){let t=([n,r])=>[(n-50)/100,(r-100)/100];return Object.fromEntries(Object.entries(e??{}).map(([n,r])=>[n,r.shapes.map((o,s)=>o.kind==="circle"?{kind:"circle",c:t(o.c),r:o.r/100,fill:o.fill,main:s===0}:o.kind==="polygon"?{kind:"polygon",points:o.points.map(t),fill:o.fill,main:s===0}:{kind:o.kind,points:o.points.map(t)})]))}var j=class extends Error{constructor(n,r){super(`line ${n}: ${r}`);q(this,"line");this.line=n}};function Fo(e,t){let n=[],r="",o=!1;for(let s=0;s<e.length;s++){let a=e[s];if(a==="\\"&&o&&s+1<e.length){r+=a+e[++s];continue}a==='"'&&(o=!o),/\s/.test(a)&&!o?(r&&n.push(r),r=""):r+=a}if(o)throw new j(t,"a quote is not closed.");return r&&n.push(r),n}function _o(e){let t={no:0,indent:-1,tokens:[],children:[]},n=[t];return e.split(/\r?\n/).forEach((r,o)=>{let s=o+1;if(!r.trim()||r.trim().startsWith("//"))return;let a=r.length-r.trimStart().length,i=r.trim(),c=i.startsWith("#")?["#",i.slice(1).trim()]:i.startsWith(">")?[">",i.slice(1).trim()]:i.startsWith("json ")?["json",i.slice(5).trim()]:i.startsWith("|")?["|",i]:Fo(i,s),l={no:s,indent:a,tokens:c,children:[]};for(;n.length>1&&n[n.length-1].indent>=a;)n.pop();n[n.length-1].children.push(l),n.push(l)}),t.children}var lt=e=>e.length>=2&&e.startsWith('"')&&e.endsWith('"'),Z=e=>lt(e)?e.slice(1,-1).replace(/\\(.)/g,"$1"):e,mn=/^-?\d+(\.\d+)?$/;function ct(e,t){if(mn.test(e))return Number(e);if(lt(e))return Z(e);if(/^[A-Za-z_][A-Za-z_0-9]*$/.test(e))return e;throw new j(t,`expected a number or an expression in quotes, got ${e}.`)}function Rt(e){let t=[],n="",r=!1;for(let o of e)o==='"'&&(r=!r),o===","&&!r?(t.push(n),n=""):n+=o;return t.push(n),t}function Bt(e,t){let n=e?Rt(e):[];if(n.length!==2)throw new j(t,`expected a point x,y, got ${e??"nothing"}.`);return[ct(n[0],t),ct(n[1],t)]}function Me(e,t){let n=e?.match(/^(.+?)\.\.(.+)$/);if(!n)throw new j(t,`expected a range a..b, got ${e??"nothing"}.`);return[ct(n[1],t),ct(n[2],t)]}var qo=new Set(["text","card","line","arrow","highlight","polyline","polygon","curve","circle","ellipse","plot","pause","row","column","grid","repeat","when","move","counter","axis","timeline","brace","note","table","bars","json","chain","animate","lottie"]),fn={"right-of":"right","left-of":"left",above:"above",below:"below"},Go=["color","fill","roughness","bowing","fillStyle","opacity"],xr=new Set(["gap","size","r","rx","ry","w","h","columns","ms","thickness"]),kr=new Set(["dashed","flip","noheader","wrap"]);function Q(e,t,n){let r={};for(let o=0;o<e.length;o++){let s=e[o],a,i;if(kr.has(s)){s==="dashed"?r.dashed=!0:s==="flip"?t.flip=!0:s==="wrap"?t.wrap=!0:t.header=!1;continue}let c=s.indexOf("=");if(c>0&&!lt(s))[a,i]=[s.slice(0,c),s.slice(c+1)];else if(xr.has(s)&&o+1<e.length)[a,i]=[s,e[++o]];else throw new j(n,`did not understand \xAB${s}\xBB.`);a==="stroke"?r.width=Number(i):Go.includes(a)?r[a]=mn.test(i)?Number(i):Z(i):a==="nudge"?t.nudge=Bt(i,n).map(Number):a==="ticks"?t.ticks=i.includes(",")?Rt(i).map(Number):Number(i):a==="labels"?t.labels=Rt(i).map(Z):a==="id"||a==="anchor"||a==="font"||a==="mood"||a==="along"||a==="side"||a==="kind"||a==="var"||a==="align"||a==="label"||a==="format"||a==="fn"||a==="forward"||a==="back"||a==="direction"?t[a]=Z(i):t[a]=ct(i,n)}return Object.keys(r).length&&(t.style=r),t}function yt(e,t,n,r){let[o,s]=e;if(o==="at")return t[n]=Bt(s,r),e.slice(2);if(o in fn){if(!s||lt(s))throw new j(r,`${o} needs the id of an earlier step.`);t.place={to:s,side:fn[o]};let a=e.slice(2);if(a[0]==="gap"||a[0]?.startsWith("gap=")){let c=a[0]==="gap"?a[1]:a[0].slice(4);t.place.gap=Number(c),a=a.slice(a[0]==="gap"?2:1)}let i=a.findIndex(c=>c.startsWith("align="));return i>=0&&(t.place.align=a[i].slice(6),a=a.filter((c,l)=>l!==i)),a}return e}function Ee(e,t){let{no:n,tokens:r}=e,[o,...s]=r,a=()=>e.children.map(l=>Ee(l,t)),i=(l,h)=>{if(!l||!lt(l))throw new j(n,`${o} needs ${h} in quotes.`);return Z(l)},c=l=>{if(s[1]!=="->")throw new j(n,`write ${l} x,y -> x,y.`);return{type:l,from:Bt(s[0],n),to:Bt(s[2],n)}};if(o==="json")try{return JSON.parse(s[0])}catch{throw new j(n,"the JSON on this line is not valid.")}if(s[0]==="->"&&!qo.has(o)&&!t.has(o)){let l={type:"link",from:o,to:s[1]},h=s.slice(2);return h[0]&<(h[0])&&([l.label,h]=[Z(h[0]),h.slice(1)]),Q(h,l,n)}if(s[0]==="says"||s[0]==="thinks"){let l={type:"balloon",to:o,text:i(s[1],"what is said"),...s[0]==="thinks"?{kind:"thought"}:{}};return Q(s.slice(2),l,n)}if(t.has(o)){let l={type:"prop",name:o},h=s,u=h[0];return u&&!lt(u)&&!u.includes("=")&&u!=="at"&&!(u in fn)&&!xr.has(u)&&!kr.has(u)&&([l.id,h]=[u,h.slice(1)]),h=yt(h,l,"at",n),h[0]&<(h[0])&&([l.label,h]=[Z(h[0]),h.slice(1)]),Q(h,l,n)}switch(o){case"text":{let l={type:"text",text:i(s[0],"its text")};return Q(yt(s.slice(1),l,"at",n),l,n)}case"card":{let l={type:"card"},h=yt(s,l,"at",n),u=h.filter(lt).map(Z);if(h=h.filter(d=>!lt(d)),!u.length)throw new j(n,"a card needs a title in quotes.");return[l.title]=u,u.length>1&&(l.lines=u.slice(1)),Q(h,l,n)}case"line":case"arrow":case"highlight":return Q(s.slice(3),c(o),n);case"brace":{let l=c("brace"),h=s.slice(3);return h[0]&<(h[0])&&([l.label,h]=[Z(h[0]),h.slice(1)]),Q(h,l,n)}case"polyline":case"polygon":case"curve":{let l=s.filter(h=>/,/.test(h)&&!h.includes("="));return Q(s.slice(l.length),{type:o,points:l.map(h=>Bt(h,n))},n)}case"circle":case"ellipse":{let l={type:o};return Q(yt(s,l,"center",n),l,n)}case"plot":{let l={type:"plot",fn:i(s[0],"the formula")},h=[];for(let u=1;u<s.length;u++)if(s[u]==="domain")l.domain=Me(s[++u],n);else if(s[u]==="range")l.range=Me(s[++u],n);else if(s[u]==="box"){let d=Rt(s[++u]??"");if(d.length!==4)throw new j(n,"write box x,y,w,h.");let[p,m,g,f]=d.map(b=>ct(b,n));l.box={x:p,y:m,w:g,h:f}}else h.push(s[u]);return Q(h,l,n)}case"pause":{let l={type:"pause",ms:600},h=s;return h[0]&&mn.test(h[0])&&([l.ms,h]=[Number(h[0]),h.slice(1)]),h[0]==="ask"&&([l.ask,h]=[i(h[1],"the question"),h.slice(2)]),Q(h,l,n)}case"row":case"column":case"grid":case"chain":{let l={type:o},h=yt(s,l,"at",n);return Q(h,l,n),l.steps=a(),l}case"repeat":{let l=s[0]?.replace(/:$/,"");if(!l)throw new j(n,"write repeat n: <step>.");let h={type:"repeat",times:ct(l,n)},u=s.slice(1);if(u.length)h.step=Ee({...e,tokens:u,children:[]},t);else if(e.children.length===1)[h.step]=a();else throw new j(n,"a repeat holds one step: on the same line after \xAB:\xBB, or one line under it.");return h}case"when":{let l=s[0]?.replace(/:$/,"");if(!l)throw new j(n,"write when <condition>:.");let h=s.slice(1);return{type:"when",if:ct(l,n),steps:h.length?[Ee({...e,tokens:h,children:[]},t)]:a()}}case"lottie":{if(!s[0])throw new j(n,"write lottie <name> at x,y, or lottie ./file.json at x,y.");let l={type:"lottie",src:s[0]},h=s.slice(1);h[0]&&h[0]!=="at"&&!h[0].includes("=")&&([l.id,h]=[h[0],h.slice(1)]),h=yt(h,l,"at",n);for(let u of h){let[d,p]=u.split("=");if(d==="loop"&&(p==="true"||p==="false"))l.loop=p==="true";else if(d==="size"&&p)l.size=ct(p,n);else throw new j(n,`did not understand \xAB${u}\xBB (a lottie takes size=\u2026 and loop=false).`)}return l}case"animate":{if(!s[0]||!s[1]||s[1].includes("="))throw new j(n,"write animate <id> spin|drive|steam|talk|pulse|float, or animate <id> stop.");let l={type:"animate",target:s[0],effect:s[1]};for(let h of s.slice(2)){let[u,d]=h.split("=");if(u==="speed"&&d)l.speed=d;else throw new j(n,`did not understand \xAB${h}\xBB (an animate takes speed=slow or speed=fast).`)}return l}case"move":{if(s[1]!=="to")throw new j(n,"write move <id> to x,y.");return Q(s.slice(3),{type:"move",target:s[0],to:Bt(s[2],n)},n)}case"counter":{let l={type:"counter"},h=yt(s,l,"at",n);return l.value=ct(h[0]??"",n),h=h.slice(1),h[0]&<(h[0])&&([l.format,h]=[Z(h[0]),h.slice(1)]),Q(h,l,n)}case"axis":case"timeline":{let l=c(o),h=s.slice(3);if(h[0]!=="domain")throw new j(n,`write ${o} x,y -> x,y domain a..b.`);return l.domain=Me(h[1],n),h=h.slice(2),o==="timeline"&&(l.marks=e.children.map(u=>{let[d,p,m,g]=u.tokens;if(d!=="mark")throw new j(u.no,'under a timeline, write mark <when> "label" "text".');return{at:ct(p??"",u.no),...m?{label:Z(m)}:{},...g?{text:Z(g)}:{}}})),Q(h,l,n)}case"note":{let l={type:"note"},h=yt(s,l,"at",n);if(l.text=i(h[0],"its text"),h[1]!=="->")throw new j(n,'write note at x,y "text" -> <id or x,y>.');let u=h[2]??"";return/,/.test(u)?l.point=Bt(u,n):l.to=u,h=h.slice(3),Q(h,l,n)}case"table":{let l={type:"table"};return Q(yt(s,l,"at",n),l,n),l.rows=e.children.map(h=>{if(h.tokens[0]!=="|")throw new j(h.no,"under a table, write rows as | a | b |.");return h.tokens[1].replace(/^\||\|$/g,"").split("|").map(u=>u.trim())}),l}case"bars":{let l={type:"bars"},h=[];for(let u=0;u<s.length;u++)if(s[u]==="box"){let d=Rt(s[++u]??"");if(d.length!==4)throw new j(n,"write box x,y,w,h.");let[p,m,g,f]=d.map(b=>ct(b,n));l.box={x:p,y:m,w:g,h:f}}else s[u]==="values"?l.values=Rt(s[++u]??"").map(d=>ct(d,n)):s[u]==="labels"?l.labels=Rt(s[++u]??"").map(Z):h.push(s[u]);return Q(h,l,n)}}throw new j(n,`\xAB${o}\xBB is not a step, a prop or an id followed by -> / says.`)}function Xo(e){let{no:t,tokens:n}=e,r=[],o=n[0],s=1;for(;n[s]==="->";){let i=n[s+1];if(!i||lt(i))throw new j(t,'write a -> b "label" -> c "label".');let c={type:"link",from:o,to:i};s+=2,n[s]&<(n[s])&&(c.label=Z(n[s++])),r.push(c),o=i}let a=n.slice(s);return r.map(i=>Q([...a],i,t))}function Yo(e){let{no:t,tokens:n}=e,[r,...o]=n,s=c=>{let l=c?.match(/^(\d{1,3}),(\d{1,3})$/);if(!l||Number(l[1])>100||Number(l[2])>100)throw new j(t,`on a figure's grid a point is two whole numbers from 0 to 100, like 24,48 (got ${c??"nothing"}).`);return[Number(l[1]),Number(l[2])]},a={kind:r},i=o;if(r==="circle")i[0]==="at"&&(i=i.slice(1)),a.c=s(i[0]),i=i.slice(1);else if(r==="polygon"||r==="polyline"||r==="curve"){let c=i.filter(l=>l.includes(",")&&!l.includes("="));a.points=c.map(s),i=i.slice(c.length)}else throw new j(t,`a figure is made of polygon, polyline, curve and circle lines, not \xAB${r}\xBB.`);for(let c of i){let[l,h]=c.split("=");if(l==="fill"&&h)a.fill=Z(h);else if(l==="r"&&h&&/^\d{1,3}$/.test(h))a.r=Number(h);else throw new j(t,`did not understand \xAB${c}\xBB in a figure (only fill=\u2026 and, on a circle, r=\u2026).`)}return a}function vr(e,t){let n=new Set(t),r={id:"lesson",title:"",width:900,height:560},o=[],s,a;for(let i of _o(e)){let{no:c,tokens:l}=i,[h,...u]=l,d=f=>{if(!u[0])throw new j(c,`${h} needs ${f}.`);return Z(u.join(" "))};switch(!["->","says","thinks"].includes(u[0])?h:""){case"#":s=u[0];continue;case">":a=u[0];continue;case"title":r.title=d("a title");continue;case"id":r.id=d("an id");continue;case"category":r.category=d("a category");continue;case"theme":r.theme=d("paper or chalkboard");continue;case"locale":r.locale=d("a language tag");continue;case"kind":r.kind=d("what the drawing is for");continue;case"source":r.source=d("where the numbers come from");continue;case"background":r.background=d("dots, grid or plain");continue;case"size":{let f=u[0]?.match(/^(\d+)x(\d+)$/);if(!f)throw new j(c,"write size 900x560.");[r.width,r.height]=[Number(f[1]),Number(f[2])];continue}case"param":{let[f,b,y,...w]=u,[k,v]=Me(y,c).map(Number),M={label:Z(b??""),min:k,max:v,step:1,value:k};for(let S=0;S<w.length;S++)if(w[S].startsWith("step="))M.step=Number(w[S].slice(5));else if(w[S]==="=")M.value=Number(w[++S]);else throw new j(c,`did not understand \xAB${w[S]}\xBB.`);r.params={...r.params,[f]:M};continue}case"switch":{let[f,b,y]=u;r.switches={...r.switches,[f]:{label:Z(b??""),on:y==="on"}};continue}case"var":{if(u[1]!=="=")throw new j(c,"write var name = value.");r.vars={...r.vars,[u[0]]:ct(u[2]??"",c)};continue}case"learning":{let[f,b]=u;if(!["goal","question","answer","caveat"].includes(f))throw new j(c,'write learning goal|question|answer|caveat "\u2026".');r.learning={...r.learning,[f]:Z(b??"")};continue}case"define":{let f=u[0];if(!f)throw new j(c,"write define <name> and its shapes under it.");r.defs={...r.defs,[f]:{shapes:i.children.map(Yo)}},n.add(f);continue}case"quiz":{r.quiz={question:Z(u[0]??""),options:i.children.map(f=>{let[b,...y]=f.tokens;if(b!=="*"&&b!=="-")throw new j(f.no,"under a quiz, write * right option -- why, or - wrong option -- why.");let w=y.map(Z).join(" "),[k,v=""]=w.split(/\s+--\s+/);return{text:k.trim(),right:b==="*",why:v.trim()}})};continue}}let m=u[0]==="->"&&u.indexOf("->",1)>0?Xo(i):[Ee(i,n)],[g]=m;s!==void 0&&([g.chapter,s]=[s,void 0]),a!==void 0&&([g.say,a]=[a,void 0]),o.push(...m)}return r.steps=o,r}var Ae=2,gn=.2,Vo=3,Wo=.5,wt=e=>Math.max(0,e.w)*Math.max(0,e.h);function Oe(e,t){let n=Math.min(e.x+e.w,t.x+t.w)-Math.max(e.x,t.x),r=Math.min(e.y+e.h,t.y+t.h)-Math.max(e.y,t.y);return n>0&&r>0?n*r:0}var Ho=(e,[t,n])=>t>e.x+2&&t<e.x+e.w-2&&n>e.y+2&&n<e.y+e.h-2,ie=e=>e.text?` (\xAB${e.text.slice(0,40)}\xBB)`:"",Uo=(e,t)=>{let[n,r]=[e.box,t.box];return(e.type==="circle"||e.type==="ellipse")&&r.x>=n.x-2&&r.y>=n.y-2&&r.x+r.w<=n.x+n.w+2&&r.y+r.h<=n.y+n.h+2};function Ko(e,t,n){let r=new Map;for(let i of e){let c=i.box;(c.x<-Ae||c.y<-Ae||c.x+c.w>t+Ae||c.y+c.h>n+Ae)&&r.set(`off:${i.step}`,`step ${i.step+1}${ie(i)} goes off the paper (${t}\xD7${n})`)}let o=e.filter(i=>i.kind==="text");for(let i=0;i<o.length;i++)for(let c=i+1;c<o.length;c++){let[l,h]=[o[i],o[c]];l.step!==h.step&&Oe(l.box,h.box)>gn*Math.min(wt(l.box),wt(h.box))&&r.set(`texts:${l.step}:${h.step}`,`the texts of steps ${l.step+1}${ie(l)} and ${h.step+1}${ie(h)} overlap`)}for(let i of o)for(let c of e)c.kind!=="stroke"||c.step===i.step||Uo(c,i)||(c.points??[]).filter(l=>Ho(i.box,l)).length>Vo&&r.set(`cross:${c.step}:${i.step}`,`a line of step ${c.step+1} crosses the text of step ${i.step+1}${ie(i)}`);for(let i of o)for(let c of e)c.kind!=="shape"||c.step===i.step||Oe(i.box,c.box)>gn*wt(i.box)&&r.set(`on:${c.step}:${i.step}`,`the text of step ${i.step+1}${ie(i)} sits on the drawing of step ${c.step+1}`);let s=new Map;for(let i of e){if(i.kind!=="fill"||i.type!=="balloon")continue;let c=s.get(i.step);(!c||wt(i.box)>wt(c.box))&&s.set(i.step,i)}for(let i of s.values())for(let c of e)c.kind!=="shape"||c.step===i.step||Oe(i.box,c.box)>gn*Math.min(wt(i.box),wt(c.box))&&r.set(`balloon:${i.step}:${c.step}`,`the balloon of step ${i.step+1} sits on the drawing of step ${c.step+1}`);let a=e.filter(i=>i.kind==="shape");for(let i=0;i<a.length;i++)for(let c=i+1;c<a.length;c++){let[l,h]=[a[i],a[c]];l.step!==h.step&&Oe(l.box,h.box)>Wo*Math.min(wt(l.box),wt(h.box))&&r.set(`piled:${l.step}:${h.step}`,`the drawings of steps ${l.step+1} and ${h.step+1} sit on each other`)}return[...r].map(([i,c])=>({key:i,text:c}))}function Zo(e,t){let n=[];for(let r of e.querySelectorAll("[data-step]")){let o=Number(r.dataset.step),s=r.dataset.type??t.steps[o]?.type,[a,i]=[Number(r.dataset.dx??0),Number(r.dataset.dy??0)],c=u=>({x:u.x+a,y:u.y+i,w:u.width,h:u.height});if(r.dataset.lottie!==void 0){let u=r.querySelector("[data-box]").getBBox();n.push({step:o,type:s,kind:"shape",box:c(u)});continue}let l=r.querySelector("text");if(r.dataset.prop){let u=[...r.querySelectorAll("path")].map(m=>c(m.getBBox())),d=Math.min(...u.map(m=>m.x)),p=Math.min(...u.map(m=>m.y));n.push({step:o,type:s,kind:"shape",box:{x:d,y:p,w:Math.max(...u.map(m=>m.x+m.w))-d,h:Math.max(...u.map(m=>m.y+m.h))-p}})}if(l){n.push({step:o,type:s,kind:"text",text:l.textContent??"",box:c(l.getBBox())});continue}if(!(r instanceof SVGPathElement))continue;let h=c(r.getBBox());if(r.dataset.marker)n.push({step:o,type:s,kind:"marker",box:h});else if(r.dataset.hatch)n.push({step:o,type:s,kind:"hatch",box:h});else if((r.getAttribute("fill")??"none")!=="none")n.push({step:o,type:s,kind:"fill",box:h});else{if(r.getAttribute("stroke")==="none"||Number(r.getAttribute("stroke-width")??1)===0)continue;{let u=r.getTotalLength(),d=Math.min(300,Math.max(2,Math.ceil(u/6))),p=[];for(let m=0;m<=d;m++){let g=r.getPointAtLength(u*m/d);p.push([g.x+a,g.y+i])}n.push({step:o,type:s,kind:"stroke",box:h,points:p})}}}return n}async function Pe(e){let t=document.createElement("div");t.setAttribute("aria-hidden","true"),t.style.cssText="position:fixed;left:-20000px;top:0;width:900px;visibility:hidden;pointer-events:none";let n=document.createElementNS("http://www.w3.org/2000/svg","svg");t.append(n),document.body.append(t);let r=new Map,o=Ct(e);try{let a=new at(n);for(let i of o){await a.render(e,i,{animate:!1,motion:"rest"});let c=Object.entries(i).map(([l,h])=>`${l}=${h}`).join(", ");for(let l of Ko(Zo(n,e),e.width,e.height)){let h=r.get(l.key);r.set(l.key,{text:h?.text??l.text,at:[...h?.at??[],c]})}}}finally{t.remove()}let s=o.length;return{combos:s,keys:[...r.keys()],problems:[...r.values()].map(({text:a,at:i})=>i.length===s||!i[0]?a:`${a} (at ${i.join("; ")})`)}}var Wt="http://www.w3.org/2000/svg",Sr=e=>{let t=e.viewBox.baseVal;return t&&t.width?{w:t.width,h:t.height}:{w:e.clientWidth||900,h:e.clientHeight||560}};function Qo(e,t,n){let{w:r,h:o}=Sr(e),s=e.cloneNode(!0);s.querySelectorAll(".dw-pointer").forEach(l=>l.remove());let a=performance.now();s.querySelectorAll("[data-anim]").forEach(l=>{l.style.animationPlayState!=="paused"&&(l.style.animationDelay=`${-Math.round(a-Number(l.dataset.animStart??a))}ms`,l.style.animationPlayState="paused")}),s.setAttribute("xmlns",Wt),s.setAttribute("width",String(r)),s.setAttribute("height",String(o));let i=document.createElementNS(Wt,"style");i.textContent=t;let c=document.createElementNS(Wt,"rect");return c.setAttribute("width","100%"),c.setAttribute("height","100%"),c.setAttribute("fill",n),s.prepend(c),s.prepend(i),new XMLSerializer().serializeToString(s)}async function Mr(e,t,n,r){let{svg:o,done:s}=Er(e.width);try{await new at(o).render(e,t,{animate:!1,css:!0,theme:r});let a=o.cloneNode(!0);a.querySelector(".dw-pencil")?.remove(),a.removeAttribute("style"),a.setAttribute("xmlns",Wt),a.setAttribute("width",String(e.width)),a.setAttribute("height",String(e.height));let i=new XMLSerializer().serializeToString(a),c=n.split(/(?=@font-face)/).filter(h=>{let u=h.match(/font-family:\s*['"]?([^'";]+)/)?.[1],d=h.match(/font-weight:\s*(\d+)/)?.[1];return u&&i.includes(u)&&(!d||new RegExp(`font-weight="${d}"`).test(i))}),l=document.createElementNS(Wt,"style");return l.textContent=c.join("")+wr,a.prepend(l),new XMLSerializer().serializeToString(a)}finally{s()}}async function $r(e,t,n,r=2,o){let{w:s,h:a}=Sr(e),i=new Image;i.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(Qo(e,t,n))}`,await i.decode();let c=o??document.createElement("canvas");c.width=Math.round(s*r),c.height=Math.round(a*r);let l=c.getContext("2d");return l.fillStyle=n,l.fillRect(0,0,c.width,c.height),l.drawImage(i,0,0,c.width,c.height),c}function Er(e){let t=document.createElement("div");t.setAttribute("aria-hidden","true"),t.style.cssText=`position:fixed;left:-20000px;top:0;width:${e}px;pointer-events:none`;let n=document.createElementNS(Wt,"svg");return t.append(n),document.body.append(t),{svg:n,done:()=>t.remove()}}async function ae(e,t,n,r){let{svg:o,done:s}=Er(e.width),a=document.createElement("canvas"),i=new at(o),c=!1,l=async()=>{if(!c){c=!0;try{await $r(o,n.faces,n.paper,n.scale,a),await r(a)}finally{c=!1}}},h=setInterval(()=>void l(),1e3/n.fps);try{let u=n.from??0,d=n.until??e.steps.length-1;await i.render(e,t,{animate:!0,theme:n.theme,beforeBeat:n.say,from:n.from,until:n.until,onStep:p=>n.onProgress?.((p-u+1)/(d-u+1))}),await new Promise(p=>setTimeout(p,1500))}finally{for(clearInterval(h);c;)await new Promise(u=>setTimeout(u,20));await $r(o,n.faces,n.paper,n.scale,a),await r(a),i.stop(),s()}}function bn(e,t=n=>MediaRecorder.isTypeSupported(n)){let n=["video/mp4;codecs=avc1","video/mp4"],r=["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm"];return(e==="mp4"?[...n,...r]:r).find(t)}async function yn(e,t,n){let r=document.createElement("canvas");r.width=e.width,r.height=e.height;let o=r.getContext("2d");o.fillStyle=n.paper,o.fillRect(0,0,r.width,r.height);let s=r.captureStream(24),a=n.audio?.(s),i=bn(n.prefer),c=new MediaRecorder(s,i?{mimeType:i}:void 0),l=[];c.ondataavailable=u=>u.data.size&&l.push(u.data);let h=new Promise(u=>c.onstop=()=>u());c.start(500);try{await ae(e,t,{...n,fps:12,scale:1},u=>{o.drawImage(u,0,0,r.width,r.height)})}finally{c.stop(),await h,a?.()}return new Blob(l,{type:c.mimeType||i||"video/webm"})}function Ar(e,t,n){return yn(e,t,{...n,prefer:"webm"})}var Zt=Pn($n(),1);var Ht=Pn($n(),1),he={en:{start:"Start",back:"Back",next:"Next",playAll:"Play all",chapter:(e,t)=>`Chapter ${e} of ${t}`,values:"Move the values",think:"Think about it",answer:"One possible answer",caveat:"Where the comparison stops",download:"Download",checking:"Checking the drawing\u2026",checked:e=>`Checked at ${e} ${e===1?"setting":"settings"}: nothing leaves the paper and no text covers another.`,problems:"The check found:",broken:"This drawing could not be opened:",keys:"\u2192 next \xB7 \u2190 back \xB7 Space play all",made:"Made with chalk-talk",board:"Chalkboard",voice:"Narration",recording:e=>`Recording\u2026 ${e}%`,show:"Show me",yourTurn:"Your turn",transcript:"Transcript",again:"Try another",valuesShort:e=>`Values (${e})`,expand:"Expand",all:"All",present:"Present",presentKeys:"click, \u2192 or PageDown next \xB7 \u2190 or PageUp back \xB7 Esc stop",notes:"Speaker notes",now:"Now",after:"Next",end:"The end",notesBlocked:"the browser blocked the notes window",since:"since the start",on:"on",off:"off",lessons:"Lessons"},pt:{start:"In\xEDcio",back:"Voltar",next:"Pr\xF3ximo",playAll:"Tocar tudo",chapter:(e,t)=>`Cap\xEDtulo ${e} de ${t}`,values:"Mexa nos valores",think:"Para pensar",answer:"Uma resposta poss\xEDvel",caveat:"Onde a compara\xE7\xE3o para",download:"Baixar",checking:"Conferindo o desenho\u2026",checked:e=>`Conferido em ${e} ${e===1?"posi\xE7\xE3o":"posi\xE7\xF5es"}: nada sai do papel e nenhum texto cobre outro.`,problems:"A confer\xEAncia achou:",broken:"Este desenho n\xE3o p\xF4de ser aberto:",keys:"\u2192 pr\xF3ximo \xB7 \u2190 voltar \xB7 Espa\xE7o tocar tudo",made:"Feito com chalk-talk",board:"Quadro-negro",voice:"Narra\xE7\xE3o",recording:e=>`Gravando\u2026 ${e}%`,show:"Mostrar",yourTurn:"Sua vez",transcript:"Transcri\xE7\xE3o",again:"Tentar outra",valuesShort:e=>`Valores (${e})`,expand:"Expandir",all:"Tudo",present:"Apresentar",presentKeys:"clique, \u2192 ou PageDown avan\xE7a \xB7 \u2190 ou PageUp volta \xB7 Esc sai",notes:"Notas do apresentador",now:"Agora",after:"Depois",end:"Fim",notesBlocked:"o navegador bloqueou a janela de notas",since:"desde o come\xE7o",on:"ligado",off:"desligado",lessons:"Aulas"}},Mn=()=>navigator.language.toLowerCase().startsWith("pt")?"pt":"en",ze=e=>e.locale?e.locale.toLowerCase().startsWith("pt")?"pt":"en":Mn(),xs=`
|
|
154
154
|
<header class="head">
|
|
155
155
|
<div><span class="eyebrow" data-part="category"></span><h1 data-part="title"></h1></div>
|
|
156
156
|
<div class="tools"><button data-part="present" type="button"></button><button data-part="board" type="button" aria-pressed="false"></button><button data-part="voice" type="button" aria-pressed="false"></button><div data-part="downloads" class="downloads"><button data-part="png" type="button">PNG</button><button data-part="svg" type="button">SVG</button><button data-part="gif" type="button">GIF</button><button data-part="webm" type="button">WebM</button></div></div>
|
|
@@ -176,7 +176,7 @@ body.still #stage { padding: 0; max-width: none; }
|
|
|
176
176
|
<details data-part="transcript" class="card transcript"></details>
|
|
177
177
|
<p class="foot"><span data-part="keys"></span><br><span data-part="made"></span><span data-part="credits"></span></p>
|
|
178
178
|
</aside>
|
|
179
|
-
</div>`;function T(e,t={},n=""){let r=document.createElement(e);for(let[o,s]of Object.entries(t))r.setAttribute(o,s);return n&&(r.textContent=n),r}var At=()=>Promise.all([...document.fonts].map(e=>e.load())).catch(()=>{});async function Fr(e,t,n){let r=Te[n.lang??ze(t)],o=!!n.compact;e.classList.add("chalk-talk"),e.classList.toggle("is-compact",o),e.innerHTML=xs;let s=$=>e.querySelector(`[data-part="${$}"]`),a=$=>s($),i=se(t,r.start),l=e.querySelector('[data-part="paper"]'),c=s("say"),h=new at(l,$=>c.textContent=$),u=matchMedia("(prefers-reduced-motion: reduce)").matches,d=ut(t),p=0,m=0,g=t.theme??n.theme??"paper",f=!1,b=!1,y=!1,w=!1,k=!1,v=null,M=0,S;s("category").textContent=t.category??"",s("title").textContent=t.title;let R=i.map(($,A)=>{let z=T("button",{type:"button"},`${A+1} \xB7 ${$.title}`);return z.addEventListener("click",()=>J(A,A===p+1)),s("chapters").append(z),z});a("back").textContent=`\u25C0 ${r.back}`,a("next").textContent=`${r.next} \u25B6`,a("all").textContent=o?`\u25B6 ${r.all}`:r.playAll,s("keys").textContent=n.keys==="document"?r.keys:"",s("made").textContent=r.made;for(let $ of t.credits??[])s("credits").append(T("br"),T("span",{},$));function C(){R.forEach(($,A)=>{$.className=A===p?"is-on":A<p?"is-seen":"",$.setAttribute("aria-current",A===p?"step":"false")}),s("count").textContent=r.chapter(p+1,i.length),a("back").disabled=p===0,a("next").disabled=p===i.length-1,s("present-foot").textContent=`${p+1} / ${i.length} \xB7 ${i[p].title}`,I()}let L=$=>{let A=i[$],z=Mt(t,d);return t.steps.slice(A.start,A.end+1).flatMap(N=>[N.say,N.type==="pause"?N.ask:void 0].filter(K=>!!K)).map(N=>nt(N,z,t.locale)).join(" ")};function D(){if(v=window.open("","chalk-notes","width=560,height=420"),!v)return void(s("present-foot").dataset.note=r.notesBlocked);let $=v.document;$.title=`${r.notes} \xB7 ${t.title}`;let A=$.createElement("style");A.textContent="body{margin:0;padding:24px;font:18px/1.5 system-ui,sans-serif;color:#242424;background:#fff}h1{margin:0 0 4px;font-size:13px;letter-spacing:.06em;text-transform:uppercase;color:#6b665c}h2{margin:0 0 12px;font-size:24px}p{margin:0 0 18px}.next{color:#6b665c;border-top:1px solid #e0d8c6;padding-top:12px;font-size:16px}.clock{font:28px ui-monospace,Menlo,monospace}.clock small{font:13px system-ui,sans-serif;color:#6b665c;margin-left:8px}",$.head.replaceChildren(A),$.body.replaceChildren();for(let z of["now","title","say","next","clock"])$.body.append(Object.assign($.createElement(z==="title"?"h2":z==="now"?"h1":"p"),{className:z}));I()}function I(){if(!v||v.closed)return;let $=z=>v.document.querySelector(`.${z}`);$("now").textContent=`${r.now} \u2014 ${p+1} / ${i.length}`,$("title").textContent=i[p].title,$("say").textContent=L(p),$("next").textContent=p+1<i.length?`${r.after} \u2014 ${p+2}. ${i[p+1].title}`:r.end;let A=Math.floor((Date.now()-M)/1e3);$("clock").replaceChildren(`${String(Math.floor(A/60)).padStart(2,"0")}:${String(A%60).padStart(2,"0")}`,Object.assign(v.document.createElement("small"),{textContent:r.since}))}function W(){!y||w||(w=!0,M=Date.now(),S=setInterval(I,1e3),e.requestFullscreen?.().then(()=>k=!0).catch(()=>{}),D())}function X($){if(y=$,e.classList.toggle("is-presenting",$),$)return w=!1,J(p,!1);S&&clearInterval(S),k&&document.fullscreenElement&&document.exitFullscreen().catch(()=>{}),k=!1,v?.close(),v=null}function V($){let A=s("ask");A.replaceChildren(T("p",{},$));let z=T("button",{type:"button",class:"primary"},r.show);return A.append(z),A.hidden=!1,z.focus({preventScroll:!0}),new Promise(N=>z.addEventListener("click",()=>{A.hidden=!0,N()},{once:!0}))}async function pt($,A,z){let N=t.steps[A];N.type==="pause"&&N.ask&&await V(nt(N.ask,Mt(t,d),t.locale)),z===m&&f&&$&&await ks($,t.locale??"pt-BR")}function tt(){e.querySelector(".paper").classList.toggle("is-board",g==="chalkboard"),s("board").setAttribute("aria-pressed",String(g==="chalkboard"))}async function J($,A,z){if(b)return;p=Math.max(0,Math.min(i.length-1,$)),C();let N=++m;try{await h.render(t,d,{animate:A&&!u,until:i[p].end,from:z??(p>0?i[p-1].end+1:0),theme:g,beforeBeat:(K,G)=>pt(K,G,N)}),N===m&&p===i.length-1&&Ur()}catch(K){if(N===m)throw K}}a("board").textContent=r.board,s("board").addEventListener("click",()=>{g=g==="chalkboard"?"paper":"chalkboard",tt(),J(p,!1)}),tt(),"speechSynthesis"in window&&!o?(a("voice").textContent=`\u{1F508} ${r.voice}`,s("voice").addEventListener("click",()=>{f=!f,s("voice").setAttribute("aria-pressed",String(f)),f||speechSynthesis.cancel()})):s("voice").remove(),s("back").addEventListener("click",()=>J(p-1,!1)),s("next").addEventListener("click",()=>J(p+1,!0)),s("all").addEventListener("click",()=>J(i.length-1,!0,0));let Qt=$=>{if(!$.target.closest("input, button, summary, textarea, [contenteditable]")){if(W(),$.key==="ArrowRight"||$.key==="PageDown"||y&&($.key===" "||$.key==="Enter"))$.preventDefault(),J(p+1,!0);else if($.key==="ArrowLeft"||$.key==="PageUp")$.preventDefault(),J(p-1,!1);else if(y&&$.key==="Escape")X(!1);else if($.key===" ")$.preventDefault(),J(i.length-1,!0,0);else return;$.stopPropagation()}},Ot=n.keys==="document"?document:e;Ot===e&&(e.tabIndex=0),Ot.addEventListener("keydown",Qt),a("present").textContent=`\u25B6 ${r.present}`,s("present").addEventListener("click",()=>{X(!0),W()}),e.querySelector(".paper").addEventListener("click",$=>{!y||$.target.closest("button, .ask")||(W(),J(p+1,!0))});let On=()=>{y&&k&&!document.fullscreenElement&&X(!1)};if(document.addEventListener("fullscreenchange",On),Wr(),o){let $=a("values-toggle"),A=Object.keys(t.params??{}).length+Object.keys(t.switches??{}).length;A&&($.hidden=!1,$.textContent=`\u2699 ${r.valuesShort(A)}`,$.addEventListener("click",()=>{let z=!e.classList.contains("show-values");e.classList.toggle("show-values",z),$.setAttribute("aria-expanded",String(z))}));for(let z of["learning","quiz","check","transcript"])s(z).remove();s("downloads").remove(),s("board").remove(),s("present").remove(),e.querySelector(".foot").remove()}else Hr(),Kr(),Zr();if(n.onExpand){let $=a("expand");$.hidden=!1,$.textContent=`\u2922 ${r.expand}`,$.addEventListener("click",n.onExpand)}return await At(),o||Qr(),n.present&&(e.classList.add("is-presenting"),y=!0,s("keys").textContent=r.presentKeys),await J(0,!o),{destroy(){b=!0,m++,h.stop(),Ot.removeEventListener("keydown",Qt),document.removeEventListener("fullscreenchange",On),y&&X(!1),f&&speechSynthesis.cancel(),e.replaceChildren()}};function Wr(){let $=s("controls"),A=Object.entries(t.params??{}),z=Object.entries(t.switches??{});if(!A.length&&!z.length)return $.remove();$.append(T("h2",{},r.values));for(let[N,K]of A){let G=T("label",{class:"value"}),H=T("b",{},Ft(d[N],void 0,t.locale)),et=T("input",{type:"range",min:String(K.min),max:String(K.max),step:String(K.step),value:String(d[N])});et.addEventListener("input",()=>{d[N]=Number(et.value),H.textContent=Ft(d[N],void 0,t.locale),J(p,!1)}),G.append(T("span",{},K.label),H,et),$.append(G)}for(let[N,K]of z){let G=T("label",{class:"switch"}),H=T("input",{type:"checkbox"});H.checked=d[N]===1,H.addEventListener("change",()=>{d[N]=H.checked?1:0,J(p,!1)}),G.append(H,T("span",{},K.label)),$.append(G)}}function Hr(){let $=s("learning"),A=t.learning;if(!A)return $.remove();let z=T("details");z.append(T("summary",{},r.answer),T("p",{},A.answer)),$.append(T("h2",{},r.think),T("p",{},A.question),z,T("p",{class:"caveat"},`${r.caveat}: ${A.caveat}`))}function Ur(){let $=s("quiz");if(!$||!t.quiz||$.childElementCount)return;$.hidden=!1;let A=T("p",{class:"why",role:"status"}),z=T("div",{class:"options"});for(let N of t.quiz.options){let K=T("button",{type:"button"},N.text);K.addEventListener("click",()=>{z.querySelectorAll("button").forEach(G=>G.classList.remove("is-right","is-wrong")),K.classList.add(N.right?"is-right":"is-wrong"),A.textContent=N.why,A.className=N.right?"why is-right":"why"}),z.append(K)}$.append(T("h2",{},r.yourTurn),T("p",{},t.quiz.question),z,A)}function Kr(){let $=s("transcript"),A=Mt(t,ut(t)),z=T("ol");for(let N of i){let K=t.steps.slice(N.start,N.end+1).flatMap(H=>[H.say,H.type==="pause"?H.ask:void 0].filter(et=>!!et)),G=T("li");G.append(T("b",{},N.title));for(let H of K)G.append(T("p",{},nt(H,A,t.locale)));z.append(G)}$.append(T("summary",{},r.transcript),z)}function Zr(){let $=s("downloads");$.prepend(T("span",{},r.download));let A=G=>`${(t.id||"drawing").replace(/[^a-z0-9-]+/gi,"-").slice(0,60)}.${G}`;s("svg").addEventListener("click",()=>Sn(new Blob([le(l,n.faces)],{type:"image/svg+xml"}),A("svg")));let z=(G,H,et)=>G.addEventListener("click",async()=>{let he=G.textContent;$.querySelectorAll("button").forEach(kt=>kt.disabled=!0);try{Sn(await H(kt=>G.textContent=r.recording(Math.round(kt*100))),A(et))}finally{G.textContent=he,$.querySelectorAll("button").forEach(kt=>kt.disabled=!1)}}),N=n.faces,K=()=>g==="chalkboard"?"#26372E":"#FBF7EE";"MediaRecorder"in window?z(a("webm"),G=>Ar(t,ut(t),{faces:N,paper:K(),theme:g,onProgress:G}),"webm"):s("webm").remove(),z(a("gif"),async G=>{let H=(0,Ht.GIFEncoder)();return await ae(t,ut(t),{faces:N,paper:K(),theme:g,onProgress:G,fps:8,scale:.6},et=>{let{data:he}=et.getContext("2d").getImageData(0,0,et.width,et.height),kt=(0,Ht.quantize)(he,64);H.writeFrame((0,Ht.applyPalette)(he,kt),et.width,et.height,{palette:kt,delay:125})}),H.finish(),new Blob([H.bytes()],{type:"image/gif"})},"gif"),s("png").addEventListener("click",()=>{let G=new Image;G.onload=()=>{let H=T("canvas",{width:String(t.width*2),height:String(t.height*2)});H.getContext("2d").drawImage(G,0,0,t.width*2,t.height*2),H.toBlob(et=>et&&Sn(et,A("png")),"image/png")},G.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(le(l,n.faces))})}async function Qr(){let $=s("check");$.textContent=r.checking;let A=await Oe(t);if(b)return;if($.className=A.problems.length?"check is-warn":"check is-ok",!A.problems.length)return void($.textContent=`\u2713 ${r.checked(A.combos)}`);$.textContent="";let z=T("ul");for(let N of A.problems)z.append(T("li",{},N));$.append(T("b",{},`! ${r.problems}`),z)}}async function _r(e,t,n){e.classList.add("chalk-talk","is-still");let r=t.theme??n??"paper",o=T("div",{class:`paper${r==="chalkboard"?" is-board":""}`}),s=document.createElementNS("http://www.w3.org/2000/svg","svg");o.append(s),e.replaceChildren(o),await At(),await new at(s).render(t,ut(t),{animate:!1,theme:r,motion:"rest"})}function ks(e,t){return new Promise(n=>{let r=new SpeechSynthesisUtterance(e);r.lang=t;let o=speechSynthesis.getVoices().find(a=>a.lang.toLowerCase().startsWith(t.toLowerCase().slice(0,2)));o&&(r.voice=o);let s=()=>n();r.onend=s,r.onerror=s,setTimeout(s,2e4),speechSynthesis.speak(r)})}function le(e,t){let n=e.cloneNode(!0);n.setAttribute("xmlns","http://www.w3.org/2000/svg");let r=document.createElementNS("http://www.w3.org/2000/svg","style");return r.textContent=t,n.prepend(r),new XMLSerializer().serializeToString(n)}function Sn(e,t){let n=T("a",{href:URL.createObjectURL(e),download:t});n.click(),setTimeout(()=>URL.revokeObjectURL(n.href),1e3)}typeof lottie<"u"&&yr(lottie);var vs=Te[Mn()];var Kt=e=>document.getElementById(e),Ut=()=>Kt("chalk-fonts")?.textContent??"";function $s(){let e=Kt("chalk-recipe"),t=e.getAttribute("type")==="text/chalk-talk"?vr(e.textContent??"",[...re,...Object.keys(_t)]):JSON.parse(e.textContent??"");if(!t||!Array.isArray(t.lessons))return{scene:en(t)};let n=t.lessons.map(s=>en(s)),r=Number(new URLSearchParams(location.search).get("lesson")),o=Number.isInteger(r)&&r>=1&&r<=n.length?r-1:0;return{scene:n[o],course:{title:String(t.course??n[0].title),lessons:n,at:o}}}function Ss(e){let t=Kt("course");t.hidden=!1,t.append(T("b",{},e.title));let n=T("ol");e.lessons.forEach((r,o)=>{let s=T("li"),a=T("a",{href:`?lesson=${o+1}`},r.title);o===e.at&&a.setAttribute("aria-current","page"),s.append(a),n.append(s)}),t.append(n)}function xt(e,t){document.body.append(T("pre",{id:`chalk-${e}`},encodeURIComponent(JSON.stringify(t))))}var En=()=>{let e=document.createElementNS("http://www.w3.org/2000/svg","svg");return document.body.append(e),e};async function Ms(e){await At(),xt("review",await Oe(e))}async function Es(e){let t=En();t.style.width=`${e.width}px`,t.id="paper",t.setAttribute("role","img"),await At(),await new at(t).render(e,ut(e),{animate:!1,motion:"rest"}),xt("snapshot",{svg:t.outerHTML})}var Nt=300;async function As(e){let t=En();t.style.width=`${e.width}px`,await At();let n=new at(t),r=se(e),o=Ct(e),s=Xr(e),a=[];for(let[i,l]of r.entries())for(let c of o){await n.render(e,c,{animate:!1,until:l.end,motion:"rest"});let h=await Yr(le(t,Ut())),u=Object.entries(c).map(([d,p])=>`${d}=${p}`).join(", ");a.push({chapter:i+1,title:l.title,label:s(c),at:u,png:Vr(h,e.width,e.height,An(e)),image:h})}xt("snapshots",{chapters:r.length,settings:o.length,shots:a.map(({image:i,...l})=>l),sheet:Ps(e,r.map(i=>i.title),o.map(s),a.map(i=>i.image))})}function Xr(e){let t=ut(e);return n=>{let r=Object.keys(n).find(o=>n[o]!==t[o]);return r?e.switches?.[r]?`${r}-${n[r]?"on":"off"}`:`${r}-${n[r]===e.params?.[r]?.min?"min":"max"}`:"default"}}function Os(e){let t=ut(e),n=Te[ze(e)];return r=>{let o=Object.keys(r).find(a=>r[a]!==t[a]);if(!o)return"";let s=e.switches?.[o];return s?`${s.label}: ${r[o]?n.on:n.off}`:`${e.params?.[o]?.label??o}: ${Ft(r[o],void 0,e.locale)}`}}var An=e=>e.theme==="chalkboard"?"#26372E":"#FBF7EE";function Yr(e){return new Promise((t,n)=>{let r=new Image;r.onload=()=>t(r),r.onerror=()=>n(new Error("a snapshot did not draw")),r.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(e)})}function Vr(e,t,n,r){let o=T("canvas",{width:String(t),height:String(n)}),s=o.getContext("2d");return s.fillStyle=r,s.fillRect(0,0,t,n),s.drawImage(e,0,0,t,n),o.toDataURL("image/png")}function Ps(e,t,n,r){let o=Math.round(Nt*e.height/e.width),s=16,a=150,i=44,l=T("canvas",{width:String(a+n.length*(Nt+s)),height:String(i+t.length*(o+s))}),c=l.getContext("2d");return c.fillStyle="#FFFFFF",c.fillRect(0,0,l.width,l.height),c.fillStyle="#242424",c.font="15px sans-serif",n.forEach((h,u)=>c.fillText(h,a+u*(Nt+s),28)),t.forEach((h,u)=>{let d=i+u*(o+s);c.fillStyle="#242424",Ls(c,`${u+1}. ${h}`,8,d+18,a-16,18),n.forEach((p,m)=>{let g=a+m*(Nt+s);c.fillStyle=An(e),c.fillRect(g,d,Nt,o),c.drawImage(r[u*n.length+m],g,d,Nt,o),c.strokeStyle="#D8D2C4",c.strokeRect(g+.5,d+.5,Nt-1,o-1)})}),l.toDataURL("image/png")}function Ls(e,t,n,r,o,s){let a="";for(let i of t.split(" "))a&&e.measureText(`${a} ${i}`).width>o?(e.fillText(a,n,r),a=i,r+=s):a=a?`${a} ${i}`:i;a&&e.fillText(a,n,r)}async function Cs(e){await At();try{let t=$e(e).reduce((n,r)=>n+r.duration,0);xt("svg",{svg:await Mr(e,ut(e),Ut()),ms:t})}catch(t){xt("svg",{error:t.message})}}var qr=e=>new Promise(t=>{let n=new FileReader;n.onload=()=>t(String(n.result)),n.readAsDataURL(e)});async function Ts(e){let t=new URLSearchParams(location.search),n=new Set((t.get("export")??"static").split(",")),r=Xr(e),o=Os(e),s=Ct(e),a=(t.get("settings")??"default").split(","),i=a.filter(g=>!s.some(f=>r(f)===g));if(i.length)return xt("export",{error:`no setting called ${i.join(", ")}: the contact sheet names them (${s.map(r).join(", ")})`});await At();let l=se(e),c=En();c.style.width=`${e.width}px`;let h=new at(c),u=An(e),d=async()=>Vr(await Yr(le(c,Ut())),e.width*2,e.height*2,u),p=l.map((g,f)=>{let b=Mt(e,ut(e)),y=e.steps.slice(g.start,g.end+1).flatMap(w=>[w.say,w.type==="pause"?w.ask:void 0].filter(k=>!!k));return{title:g.title,narration:y.map(w=>nt(w,b,e.locale)).join(" "),next:l[f+1]?.title??null}}),m=[];for(let g of a){let f=s.find(y=>r(y)===g),b={name:g,label:o(f)};if(n.has("static")){let y=[];for(let w of l)await h.render(e,f,{animate:!1,until:w.end,motion:"rest"}),y.push(await d());b.static=y}if(n.has("steps")){let y=[];for(let w of l){let k=[];for(let v of $e(e,w.end).filter(M=>M.start>=w.start))await h.render(e,f,{animate:!1,until:v.end,motion:"rest"}),k.push(await d());y.push(k)}b.steps=y}if(n.has("video")){let y=[];for(let w of l)y.push(await qr(await yn(e,f,{faces:Ut(),paper:u,prefer:"mp4",from:w.start,until:w.end})));b.video=y}if(n.has("gif")){let y=[];for(let w of l){let k=(0,Zt.GIFEncoder)();await ae(e,f,{faces:Ut(),paper:u,fps:8,scale:.6,from:w.start,until:w.end},v=>{let{data:M}=v.getContext("2d").getImageData(0,0,v.width,v.height),S=(0,Zt.quantize)(M,64);k.writeFrame((0,Zt.applyPalette)(M,S),v.width,v.height,{palette:S,delay:125})}),k.finish(),y.push(await qr(new Blob([k.bytes()],{type:"image/gif"})))}b.gif=y}m.push(b)}xt("export",{title:e.title,width:e.width,height:e.height,paper:u,notes:p,sets:m,videoType:"MediaRecorder"in window?bn("mp4")??null:null})}async function zs(e){document.body.classList.add("still"),await _r(Kt("stage"),e),document.body.dataset.ready="1"}async function Bs(){let e,t,n=location.hash.slice(1);try{({scene:e,course:t}=$s())}catch(o){if(["review","snapshot","snapshots","svg","export"].includes(n))return xt(n,{error:o.message});Kt("stage").replaceChildren(T("p",{class:"broken"},`${vs.broken} ${o.message}`));return}if(n==="review")return Ms(e);if(n==="snapshot")return Es(e);if(n==="snapshots")return As(e);if(n==="svg")return Cs(e);if(n==="still")return zs(e);if(n==="export")return Ts(e).catch(o=>xt("export",{error:o.message}));document.title=e.title;let r=ze(e);document.documentElement.lang=r==="pt"?"pt-BR":"en",t&&Ss(t),await Fr(Kt("lesson"),e,{faces:Ut(),lang:r,keys:"document",present:n==="present"||document.body.dataset.present==="1"})}var Gr=()=>{Bs()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Gr):Gr();})();
|
|
179
|
+
</div>`;function T(e,t={},n=""){let r=document.createElement(e);for(let[o,s]of Object.entries(t))r.setAttribute(o,s);return n&&(r.textContent=n),r}var At=()=>Promise.all([...document.fonts].map(e=>e.load())).catch(()=>{});async function Fr(e,t,n){let r=he[n.lang??ze(t)],o=!!n.compact;e.classList.add("chalk-talk"),e.classList.toggle("is-compact",o),e.innerHTML=xs;let s=$=>e.querySelector(`[data-part="${$}"]`),a=$=>s($),i=se(t,r.start),c=e.querySelector('[data-part="paper"]'),l=s("say"),h=new at(c,$=>l.textContent=$),u=matchMedia("(prefers-reduced-motion: reduce)").matches,d=ut(t),p=0,m=0,g=t.theme??n.theme??"paper",f=!1,b=!1,y=!1,w=!1,k=!1,v=null,M=0,S;s("category").textContent=t.category??"",s("title").textContent=t.title;let R=i.map(($,A)=>{let z=T("button",{type:"button"},`${A+1} \xB7 ${$.title}`);return z.addEventListener("click",()=>J(A,A===p+1)),s("chapters").append(z),z});a("back").textContent=`\u25C0 ${r.back}`,a("next").textContent=`${r.next} \u25B6`,a("all").textContent=o?`\u25B6 ${r.all}`:r.playAll,s("keys").textContent=n.keys==="document"?r.keys:"",s("made").textContent=r.made;for(let $ of t.credits??[])s("credits").append(T("br"),T("span",{},$));function C(){R.forEach(($,A)=>{$.className=A===p?"is-on":A<p?"is-seen":"",$.setAttribute("aria-current",A===p?"step":"false")}),s("count").textContent=r.chapter(p+1,i.length),a("back").disabled=p===0,a("next").disabled=p===i.length-1,s("present-foot").textContent=`${p+1} / ${i.length} \xB7 ${i[p].title}`,I()}let L=$=>{let A=i[$],z=Mt(t,d);return t.steps.slice(A.start,A.end+1).flatMap(N=>[N.say,N.type==="pause"?N.ask:void 0].filter(K=>!!K)).map(N=>nt(N,z,t.locale)).join(" ")};function D(){if(v=window.open("","chalk-notes","width=560,height=420"),!v)return void(s("present-foot").dataset.note=r.notesBlocked);let $=v.document;$.title=`${r.notes} \xB7 ${t.title}`;let A=$.createElement("style");A.textContent="body{margin:0;padding:24px;font:18px/1.5 system-ui,sans-serif;color:#242424;background:#fff}h1{margin:0 0 4px;font-size:13px;letter-spacing:.06em;text-transform:uppercase;color:#6b665c}h2{margin:0 0 12px;font-size:24px}p{margin:0 0 18px}.next{color:#6b665c;border-top:1px solid #e0d8c6;padding-top:12px;font-size:16px}.clock{font:28px ui-monospace,Menlo,monospace}.clock small{font:13px system-ui,sans-serif;color:#6b665c;margin-left:8px}",$.head.replaceChildren(A),$.body.replaceChildren();for(let z of["now","title","say","next","clock"])$.body.append(Object.assign($.createElement(z==="title"?"h2":z==="now"?"h1":"p"),{className:z}));I()}function I(){if(!v||v.closed)return;let $=z=>v.document.querySelector(`.${z}`);$("now").textContent=`${r.now} \u2014 ${p+1} / ${i.length}`,$("title").textContent=i[p].title,$("say").textContent=L(p),$("next").textContent=p+1<i.length?`${r.after} \u2014 ${p+2}. ${i[p+1].title}`:r.end;let A=Math.floor((Date.now()-M)/1e3);$("clock").replaceChildren(`${String(Math.floor(A/60)).padStart(2,"0")}:${String(A%60).padStart(2,"0")}`,Object.assign(v.document.createElement("small"),{textContent:r.since}))}function W(){!y||w||(w=!0,M=Date.now(),S=setInterval(I,1e3),e.requestFullscreen?.().then(()=>k=!0).catch(()=>{}),D())}function X($){if(y=$,e.classList.toggle("is-presenting",$),$)return w=!1,J(p,!1);S&&clearInterval(S),k&&document.fullscreenElement&&document.exitFullscreen().catch(()=>{}),k=!1,v?.close(),v=null}function V($){let A=s("ask");A.replaceChildren(T("p",{},$));let z=T("button",{type:"button",class:"primary"},r.show);return A.append(z),A.hidden=!1,z.focus({preventScroll:!0}),new Promise(N=>z.addEventListener("click",()=>{A.hidden=!0,N()},{once:!0}))}async function pt($,A,z){let N=t.steps[A];N.type==="pause"&&N.ask&&await V(nt(N.ask,Mt(t,d),t.locale)),z===m&&f&&$&&await ks($,t.locale??"pt-BR")}function tt(){e.querySelector(".paper").classList.toggle("is-board",g==="chalkboard"),s("board").setAttribute("aria-pressed",String(g==="chalkboard"))}async function J($,A,z){if(b)return;p=Math.max(0,Math.min(i.length-1,$)),C();let N=++m;try{await h.render(t,d,{animate:A&&!u,until:i[p].end,from:z??(p>0?i[p-1].end+1:0),theme:g,beforeBeat:(K,G)=>pt(K,G,N)}),N===m&&p===i.length-1&&Ur()}catch(K){if(N===m)throw K}}a("board").textContent=r.board,s("board").addEventListener("click",()=>{g=g==="chalkboard"?"paper":"chalkboard",tt(),J(p,!1)}),tt(),"speechSynthesis"in window&&!o?(a("voice").textContent=`\u{1F508} ${r.voice}`,s("voice").addEventListener("click",()=>{f=!f,s("voice").setAttribute("aria-pressed",String(f)),f||speechSynthesis.cancel()})):s("voice").remove(),s("back").addEventListener("click",()=>J(p-1,!1)),s("next").addEventListener("click",()=>J(p+1,!0)),s("all").addEventListener("click",()=>J(i.length-1,!0,0));let Qt=$=>{if(!$.target.closest("input, button, summary, textarea, [contenteditable]")){if(W(),$.key==="ArrowRight"||$.key==="PageDown"||y&&($.key===" "||$.key==="Enter"))$.preventDefault(),J(p+1,!0);else if($.key==="ArrowLeft"||$.key==="PageUp")$.preventDefault(),J(p-1,!1);else if(y&&$.key==="Escape")X(!1);else if($.key===" ")$.preventDefault(),J(i.length-1,!0,0);else return;$.stopPropagation()}},Ot=n.keys==="document"?document:e;Ot===e&&(e.tabIndex=0),Ot.addEventListener("keydown",Qt),a("present").textContent=`\u25B6 ${r.present}`,s("present").addEventListener("click",()=>{X(!0),W()}),e.querySelector(".paper").addEventListener("click",$=>{!y||$.target.closest("button, .ask")||(W(),J(p+1,!0))});let On=()=>{y&&k&&!document.fullscreenElement&&X(!1)};if(document.addEventListener("fullscreenchange",On),Wr(),o){let $=a("values-toggle"),A=Object.keys(t.params??{}).length+Object.keys(t.switches??{}).length;A&&($.hidden=!1,$.textContent=`\u2699 ${r.valuesShort(A)}`,$.addEventListener("click",()=>{let z=!e.classList.contains("show-values");e.classList.toggle("show-values",z),$.setAttribute("aria-expanded",String(z))}));for(let z of["learning","quiz","check","transcript"])s(z).remove();s("downloads").remove(),s("board").remove(),s("present").remove(),e.querySelector(".foot").remove()}else Hr(),Kr(),Zr();if(n.onExpand){let $=a("expand");$.hidden=!1,$.textContent=`\u2922 ${r.expand}`,$.addEventListener("click",n.onExpand)}return await At(),o||Qr(),n.present&&(e.classList.add("is-presenting"),y=!0,s("keys").textContent=r.presentKeys),await J(0,!o),{destroy(){b=!0,m++,h.stop(),Ot.removeEventListener("keydown",Qt),document.removeEventListener("fullscreenchange",On),y&&X(!1),f&&speechSynthesis.cancel(),e.replaceChildren()}};function Wr(){let $=s("controls"),A=Object.entries(t.params??{}),z=Object.entries(t.switches??{});if(!A.length&&!z.length)return $.remove();$.append(T("h2",{},r.values));for(let[N,K]of A){let G=T("label",{class:"value"}),H=T("b",{},Ft(d[N],void 0,t.locale)),et=T("input",{type:"range",min:String(K.min),max:String(K.max),step:String(K.step),value:String(d[N])});et.addEventListener("input",()=>{d[N]=Number(et.value),H.textContent=Ft(d[N],void 0,t.locale),J(p,!1)}),G.append(T("span",{},K.label),H,et),$.append(G)}for(let[N,K]of z){let G=T("label",{class:"switch"}),H=T("input",{type:"checkbox"});H.checked=d[N]===1,H.addEventListener("change",()=>{d[N]=H.checked?1:0,J(p,!1)}),G.append(H,T("span",{},K.label)),$.append(G)}}function Hr(){let $=s("learning"),A=t.learning;if(!A)return $.remove();let z=T("details");z.append(T("summary",{},r.answer),T("p",{},A.answer)),$.append(T("h2",{},r.think),T("p",{},A.question),z,T("p",{class:"caveat"},`${r.caveat}: ${A.caveat}`))}function Ur(){let $=s("quiz");if(!$||!t.quiz||$.childElementCount)return;$.hidden=!1;let A=T("p",{class:"why",role:"status"}),z=T("div",{class:"options"});for(let N of t.quiz.options){let K=T("button",{type:"button"},N.text);K.addEventListener("click",()=>{z.querySelectorAll("button").forEach(G=>G.classList.remove("is-right","is-wrong")),K.classList.add(N.right?"is-right":"is-wrong"),A.textContent=N.why,A.className=N.right?"why is-right":"why"}),z.append(K)}$.append(T("h2",{},r.yourTurn),T("p",{},t.quiz.question),z,A)}function Kr(){let $=s("transcript"),A=Mt(t,ut(t)),z=T("ol");for(let N of i){let K=t.steps.slice(N.start,N.end+1).flatMap(H=>[H.say,H.type==="pause"?H.ask:void 0].filter(et=>!!et)),G=T("li");G.append(T("b",{},N.title));for(let H of K)G.append(T("p",{},nt(H,A,t.locale)));z.append(G)}$.append(T("summary",{},r.transcript),z)}function Zr(){let $=s("downloads");$.prepend(T("span",{},r.download));let A=G=>`${(t.id||"drawing").replace(/[^a-z0-9-]+/gi,"-").slice(0,60)}.${G}`;s("svg").addEventListener("click",()=>Sn(new Blob([ce(c,n.faces)],{type:"image/svg+xml"}),A("svg")));let z=(G,H,et)=>G.addEventListener("click",async()=>{let ue=G.textContent;$.querySelectorAll("button").forEach(kt=>kt.disabled=!0);try{Sn(await H(kt=>G.textContent=r.recording(Math.round(kt*100))),A(et))}finally{G.textContent=ue,$.querySelectorAll("button").forEach(kt=>kt.disabled=!1)}}),N=n.faces,K=()=>g==="chalkboard"?"#26372E":"#FBF7EE";"MediaRecorder"in window?z(a("webm"),G=>Ar(t,ut(t),{faces:N,paper:K(),theme:g,onProgress:G}),"webm"):s("webm").remove(),z(a("gif"),async G=>{let H=(0,Ht.GIFEncoder)();return await ae(t,ut(t),{faces:N,paper:K(),theme:g,onProgress:G,fps:8,scale:.6},et=>{let{data:ue}=et.getContext("2d").getImageData(0,0,et.width,et.height),kt=(0,Ht.quantize)(ue,64);H.writeFrame((0,Ht.applyPalette)(ue,kt),et.width,et.height,{palette:kt,delay:125})}),H.finish(),new Blob([H.bytes()],{type:"image/gif"})},"gif"),s("png").addEventListener("click",()=>{let G=new Image;G.onload=()=>{let H=T("canvas",{width:String(t.width*2),height:String(t.height*2)});H.getContext("2d").drawImage(G,0,0,t.width*2,t.height*2),H.toBlob(et=>et&&Sn(et,A("png")),"image/png")},G.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(ce(c,n.faces))})}async function Qr(){let $=s("check");$.textContent=r.checking;let A=await Pe(t);if(b)return;if($.className=A.problems.length?"check is-warn":"check is-ok",!A.problems.length)return void($.textContent=`\u2713 ${r.checked(A.combos)}`);$.textContent="";let z=T("ul");for(let N of A.problems)z.append(T("li",{},N));$.append(T("b",{},`! ${r.problems}`),z)}}async function _r(e,t,n){e.classList.add("chalk-talk","is-still");let r=t.theme??n??"paper",o=T("div",{class:`paper${r==="chalkboard"?" is-board":""}`}),s=document.createElementNS("http://www.w3.org/2000/svg","svg");o.append(s),e.replaceChildren(o),await At(),await new at(s).render(t,ut(t),{animate:!1,theme:r,motion:"rest"})}function ks(e,t){return new Promise(n=>{let r=new SpeechSynthesisUtterance(e);r.lang=t;let o=speechSynthesis.getVoices().find(a=>a.lang.toLowerCase().startsWith(t.toLowerCase().slice(0,2)));o&&(r.voice=o);let s=()=>n();r.onend=s,r.onerror=s,setTimeout(s,2e4),speechSynthesis.speak(r)})}function ce(e,t){let n=e.cloneNode(!0);n.setAttribute("xmlns","http://www.w3.org/2000/svg");let r=document.createElementNS("http://www.w3.org/2000/svg","style");return r.textContent=t,n.prepend(r),new XMLSerializer().serializeToString(n)}function Sn(e,t){let n=T("a",{href:URL.createObjectURL(e),download:t});n.click(),setTimeout(()=>URL.revokeObjectURL(n.href),1e3)}typeof lottie<"u"&&yr(lottie);var vs=he[Mn()];var Kt=e=>document.getElementById(e),Ut=()=>Kt("chalk-fonts")?.textContent??"";function $s(){let e=Kt("chalk-recipe"),t=e.getAttribute("type")==="text/chalk-talk"?vr(e.textContent??"",[...re,...Object.keys(_t)]):JSON.parse(e.textContent??"");if(!t||!Array.isArray(t.lessons))return{scene:en(t)};let n=t.lessons.map(s=>en(s)),r=Number(new URLSearchParams(location.search).get("lesson")),o=Number.isInteger(r)&&r>=1&&r<=n.length?r-1:0;return{scene:n[o],course:{title:String(t.course??n[0].title),lessons:n,at:o}}}function Ss(e,t){let n=Kt("course");n.hidden=!1,n.setAttribute("aria-label",t),n.append(T("b",{},e.title));let r=T("ol");e.lessons.forEach((o,s)=>{let a=T("li"),i=T("a",{href:`?lesson=${s+1}`},o.title);s===e.at&&i.setAttribute("aria-current","page"),a.append(i),r.append(a)}),n.append(r)}function xt(e,t){document.body.append(T("pre",{id:`chalk-${e}`},encodeURIComponent(JSON.stringify(t))))}var En=()=>{let e=document.createElementNS("http://www.w3.org/2000/svg","svg");return document.body.append(e),e};async function Ms(e){await At(),xt("review",await Pe(e))}async function Es(e){let t=En();t.style.width=`${e.width}px`,t.id="paper",t.setAttribute("role","img"),await At(),await new at(t).render(e,ut(e),{animate:!1,motion:"rest"}),xt("snapshot",{svg:t.outerHTML})}var Nt=300;async function As(e){let t=En();t.style.width=`${e.width}px`,await At();let n=new at(t),r=se(e),o=Ct(e),s=Xr(e),a=[];for(let[i,c]of r.entries())for(let l of o){await n.render(e,l,{animate:!1,until:c.end,motion:"rest"});let h=await Yr(ce(t,Ut())),u=Object.entries(l).map(([d,p])=>`${d}=${p}`).join(", ");a.push({chapter:i+1,title:c.title,label:s(l),at:u,png:Vr(h,e.width,e.height,An(e)),image:h})}xt("snapshots",{chapters:r.length,settings:o.length,shots:a.map(({image:i,...c})=>c),sheet:Ps(e,r.map(i=>i.title),o.map(s),a.map(i=>i.image))})}function Xr(e){let t=ut(e);return n=>{let r=Object.keys(n).find(o=>n[o]!==t[o]);return r?e.switches?.[r]?`${r}-${n[r]?"on":"off"}`:`${r}-${n[r]===e.params?.[r]?.min?"min":"max"}`:"default"}}function Os(e){let t=ut(e),n=he[ze(e)];return r=>{let o=Object.keys(r).find(a=>r[a]!==t[a]);if(!o)return"";let s=e.switches?.[o];return s?`${s.label}: ${r[o]?n.on:n.off}`:`${e.params?.[o]?.label??o}: ${Ft(r[o],void 0,e.locale)}`}}var An=e=>e.theme==="chalkboard"?"#26372E":"#FBF7EE";function Yr(e){return new Promise((t,n)=>{let r=new Image;r.onload=()=>t(r),r.onerror=()=>n(new Error("a snapshot did not draw")),r.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(e)})}function Vr(e,t,n,r){let o=T("canvas",{width:String(t),height:String(n)}),s=o.getContext("2d");return s.fillStyle=r,s.fillRect(0,0,t,n),s.drawImage(e,0,0,t,n),o.toDataURL("image/png")}function Ps(e,t,n,r){let o=Math.round(Nt*e.height/e.width),s=16,a=150,i=44,c=T("canvas",{width:String(a+n.length*(Nt+s)),height:String(i+t.length*(o+s))}),l=c.getContext("2d");return l.fillStyle="#FFFFFF",l.fillRect(0,0,c.width,c.height),l.fillStyle="#242424",l.font="15px sans-serif",n.forEach((h,u)=>l.fillText(h,a+u*(Nt+s),28)),t.forEach((h,u)=>{let d=i+u*(o+s);l.fillStyle="#242424",Ls(l,`${u+1}. ${h}`,8,d+18,a-16,18),n.forEach((p,m)=>{let g=a+m*(Nt+s);l.fillStyle=An(e),l.fillRect(g,d,Nt,o),l.drawImage(r[u*n.length+m],g,d,Nt,o),l.strokeStyle="#D8D2C4",l.strokeRect(g+.5,d+.5,Nt-1,o-1)})}),c.toDataURL("image/png")}function Ls(e,t,n,r,o,s){let a="";for(let i of t.split(" "))a&&e.measureText(`${a} ${i}`).width>o?(e.fillText(a,n,r),a=i,r+=s):a=a?`${a} ${i}`:i;a&&e.fillText(a,n,r)}async function Cs(e){await At();try{let t=Se(e).reduce((n,r)=>n+r.duration,0);xt("svg",{svg:await Mr(e,ut(e),Ut()),ms:t})}catch(t){xt("svg",{error:t.message})}}var qr=e=>new Promise(t=>{let n=new FileReader;n.onload=()=>t(String(n.result)),n.readAsDataURL(e)});async function Ts(e){let t=new URLSearchParams(location.search),n=new Set((t.get("export")??"static").split(",")),r=Xr(e),o=Os(e),s=Ct(e),a=(t.get("settings")??"default").split(","),i=a.filter(g=>!s.some(f=>r(f)===g));if(i.length)return xt("export",{error:`no setting called ${i.join(", ")}: the contact sheet names them (${s.map(r).join(", ")})`});await At();let c=se(e),l=En();l.style.width=`${e.width}px`;let h=new at(l),u=An(e),d=async()=>Vr(await Yr(ce(l,Ut())),e.width*2,e.height*2,u),p=c.map((g,f)=>{let b=Mt(e,ut(e)),y=e.steps.slice(g.start,g.end+1).flatMap(w=>[w.say,w.type==="pause"?w.ask:void 0].filter(k=>!!k));return{title:g.title,narration:y.map(w=>nt(w,b,e.locale)).join(" "),next:c[f+1]?.title??null}}),m=[];for(let g of a){let f=s.find(y=>r(y)===g),b={name:g,label:o(f)};if(n.has("static")){let y=[];for(let w of c)await h.render(e,f,{animate:!1,until:w.end,motion:"rest"}),y.push(await d());b.static=y}if(n.has("steps")){let y=[];for(let w of c){let k=[];for(let v of Se(e,w.end).filter(M=>M.start>=w.start))await h.render(e,f,{animate:!1,until:v.end,motion:"rest"}),k.push(await d());y.push(k)}b.steps=y}if(n.has("video")){let y=[];for(let w of c)y.push(await qr(await yn(e,f,{faces:Ut(),paper:u,prefer:"mp4",from:w.start,until:w.end})));b.video=y}if(n.has("gif")){let y=[];for(let w of c){let k=(0,Zt.GIFEncoder)();await ae(e,f,{faces:Ut(),paper:u,fps:8,scale:.6,from:w.start,until:w.end},v=>{let{data:M}=v.getContext("2d").getImageData(0,0,v.width,v.height),S=(0,Zt.quantize)(M,64);k.writeFrame((0,Zt.applyPalette)(M,S),v.width,v.height,{palette:S,delay:125})}),k.finish(),y.push(await qr(new Blob([k.bytes()],{type:"image/gif"})))}b.gif=y}m.push(b)}xt("export",{title:e.title,width:e.width,height:e.height,paper:u,notes:p,sets:m,videoType:"MediaRecorder"in window?bn("mp4")??null:null})}async function zs(e){document.body.classList.add("still"),await _r(Kt("stage"),e),document.body.dataset.ready="1"}async function Bs(){let e,t,n=location.hash.slice(1);try{({scene:e,course:t}=$s())}catch(o){if(["review","snapshot","snapshots","svg","export"].includes(n))return xt(n,{error:o.message});Kt("stage").replaceChildren(T("p",{class:"broken"},`${vs.broken} ${o.message}`));return}if(n==="review")return Ms(e);if(n==="snapshot")return Es(e);if(n==="snapshots")return As(e);if(n==="svg")return Cs(e);if(n==="still")return zs(e);if(n==="export")return Ts(e).catch(o=>xt("export",{error:o.message}));document.title=e.title;let r=ze(e);document.documentElement.lang=r==="pt"?"pt-BR":"en",t&&Ss(t,he[r].lessons),await Fr(Kt("lesson"),e,{faces:Ut(),lang:r,keys:"document",present:n==="present"||document.body.dataset.present==="1"})}var Gr=()=>{Bs()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Gr):Gr();})();
|
|
180
180
|
</script>
|
|
181
181
|
</body>
|
|
182
182
|
</html>
|