Skip to content

ythx-101/live-panel-skill

live-panel

Verified

Build a terminal-style, always-running animated architecture diagram (a "live panel") from a JSON config and render it to an mp4. Use when the user wants a system, agent or org architecture diagram that looks like a monitoring dashboard in a terminal window - fixed layout, glowing packets on the wires, scrolling log, counters, bars that flip state - as a screen-recording-style video or a live web page, instead of a static picture or a step-by-step reveal. 中文:当用户要做"活的"架构图、agent 树或系统监控面板风格的动画(mp4 视频或循环网页)时使用——终端里一直在跑的监控面板外观,固定布局、线上流动的数据包、滚动日志、翻转的计数器和状态条;不是静态图,也不是分步演示。

FileKindSize
SKILL.mdskill md11.2 KB
assets/fonts/Excalifont-OFL.txtmarkdown5.1 KB
assets/fonts/Excalifont-Regular-Latin.woff2binary24.4 KB
assets/fonts/SmileySans-OFL.txtmarkdown4.3 KB
assets/fonts/SmileySans-Oblique.woff2binary1.1 MB
assets/fonts/Xiaolai-OFL.txtmarkdown4.3 KB
assets/template.htmlother35.9 KB
assets/views/LUCIDE-LICENSE.txtmarkdown3.1 KB
assets/views/ROUGH-LICENSE.txtmarkdown1.0 KB
assets/views/excalidraw.jsscript50.0 KB
assets/views/funnel.jsscript15.5 KB
assets/views/loop.jsscript74.3 KB
assets/views/ring.jsscript15.2 KB
assets/views/sketchboard.jsscript18.7 KB
examples/agent-architecture/agent-architecture.mp4binary1.4 MB
examples/agent-architecture/config.jsonconfig37.1 KB
examples/agent-architecture/preview.webpbinary1.2 MB
examples/airbnb/airbnb.mp4binary1.9 MB
examples/airbnb/config.jsonconfig20.3 KB
examples/airbnb/preview.webpbinary1.4 MB
examples/codex-agents/codex-agents.mp4binary1.8 MB
examples/codex-agents/config.jsonconfig19.1 KB
examples/codex-agents/preview.webpbinary1.6 MB
examples/excalidraw-aqua/README.mdmarkdown760 B
examples/excalidraw-aqua/build_config.pyscript6.6 KB
examples/excalidraw-aqua/config-3x4.jsonconfig8.3 KB
examples/excalidraw-aqua/config-4x5.jsonconfig8.3 KB
examples/excalidraw-aqua/preview.webpbinary2.3 MB
examples/excalidraw-gardener/README.mdmarkdown671 B
examples/excalidraw-gardener/build_config.pyscript6.4 KB
examples/excalidraw-gardener/config-3x4.jsonconfig7.6 KB
examples/excalidraw-gardener/config-4x5.jsonconfig7.6 KB
examples/excalidraw-gardener/preview.webpbinary1.2 MB
examples/excalidraw-import/agent-loop.excalidrawother6.7 KB
examples/excalidraw-import/agent-loop.mp4binary1.6 MB
examples/excalidraw-import/config.jsonconfig3.9 KB
examples/funnel-karpathy/config.jsonconfig1.2 KB
examples/funnel/config.jsonconfig1.2 KB
examples/funnel/funnel.mp4binary1.1 MB
examples/funnel/preview.webpbinary475.3 KB
examples/hybrid-agent/README.mdmarkdown729 B
examples/hybrid-agent/config.jsonconfig6.2 KB
examples/loop-poteto/config.jsonconfig6.6 KB
examples/loop-poteto/loop-poteto.mp4binary2.1 MB
examples/loop-poteto/preview-dark.webpbinary638.3 KB
examples/loop-poteto/preview-light.webpbinary627.2 KB
examples/minimal/config.jsonconfig1.9 KB
examples/minimal/preview.webpbinary146.3 KB
examples/ring/config.jsonconfig940 B
examples/ring/preview.webpbinary150.9 KB
examples/ring/ring.mp4binary593.1 KB
references/config-schema.mdmarkdown4.9 KB
references/motion-grammar.mdmarkdown6.4 KB
references/verify-view.mdmarkdown3.3 KB
references/view-rules.mdmarkdown4.3 KB
references/views.mdmarkdown24.7 KB
scripts/check_frames.pyexecutablescript4.6 KB
scripts/excalidraw_import.pyscript14.7 KB
scripts/fetch_fonts.shexecutablescript528 B
scripts/livepanel.pyexecutablescript10.2 KB
scripts/render.pyexecutablescript3.8 KB
scripts/scaffold.pyexecutablescript25.0 KB
scripts/verify_view.pyscript28.5 KB

assets/views/excalidraw.js

View on GitHub
/* live-panel view: excalidraw — a hand-drawn Excalidraw-style diagram that keeps running.
   Rounded pastel boxes with a double rough stroke, handwritten text (Excalifont + Xiaolai via theme.fonts), hand-drawn
   curved arrows, dashed loop-backs whose dashes march, corner icons. Motion: the sketch "boils" (a new rough variant every
   boil.step s, nudged by boil.amp so it stays subtle), and a script of `steps` gives exactly one protagonist at a time:
   its box gets a pen-drawn outline and a handwritten note, then its arrow is inked while a dot (solid) or a paper note
   (dashed) rides it. Pure function of t; nothing is created in seek; loops seamlessly over `period`.
   Bundles rough.js 4.6.6 (MIT, (c) 2019 Preet Shihn, see ROUGH-LICENSE.txt), scoped to this file; its Math.random
   fallbacks are replaced by a deterministic generator (every call here passes a seed anyway). */
(function(){
var __rs=987654321; function __rnd(){ __rs=(Math.imul(__rs,1103515245)+12345)>>>0; return __rs/4294967296; }
var rough=function(){"use strict";function t(t,e,s){if(t&&t.length){const[n,o]=e,a=Math.PI/180*s,h=Math.cos(a),r=Math.sin(a);for(const e of t){const[t,s]=e;e[0]=(t-n)*h-(s-o)*r+n,e[1]=(t-n)*r+(s-o)*h+o}}}function e(t,e){return t[0]===e[0]&&t[1]===e[1]}function s(s,n,o,a=1){const h=o,r=Math.max(n,.1),i=s[0]&&s[0][0]&&"number"==typeof s[0][0]?[s]:s,c=[0,0];if(h)for(const e of i)t(e,c,h);const l=function(t,s,n){const o=[];for(const s of t){const t=[...s];e(t[0],t[t.length-1])||t.push([t[0][0],t[0][1]]),t.length>2&&o.push(t)}const a=[];s=Math.max(s,.1);const h=[];for(const t of o)for(let e=0;e<t.length-1;e++){const s=t[e],n=t[e+1];if(s[1]!==n[1]){const t=Math.min(s[1],n[1]);h.push({ymin:t,ymax:Math.max(s[1],n[1]),x:t===s[1]?s[0]:n[0],islope:(n[0]-s[0])/(n[1]-s[1])})}}if(h.sort(((t,e)=>t.ymin<e.ymin?-1:t.ymin>e.ymin?1:t.x<e.x?-1:t.x>e.x?1:t.ymax===e.ymax?0:(t.ymax-e.ymax)/Math.abs(t.ymax-e.ymax))),!h.length)return a;let r=[],i=h[0].ymin,c=0;for(;r.length||h.length;){if(h.length){let t=-1;for(let e=0;e<h.length&&!(h[e].ymin>i);e++)t=e;h.splice(0,t+1).forEach((t=>{r.push({s:i,edge:t})}))}if(r=r.filter((t=>!(t.edge.ymax<=i))),r.sort(((t,e)=>t.edge.x===e.edge.x?0:(t.edge.x-e.edge.x)/Math.abs(t.edge.x-e.edge.x))),(1!==n||c%s==0)&&r.length>1)for(let t=0;t<r.length;t+=2){const e=t+1;if(e>=r.length)break;const s=r[t].edge,n=r[e].edge;a.push([[Math.round(s.x),i],[Math.round(n.x),i]])}i+=n,r.forEach((t=>{t.edge.x=t.edge.x+n*t.edge.islope})),c++}return a}(i,r,a);if(h){for(const e of i)t(e,c,-h);!function(e,s,n){const o=[];e.forEach((t=>o.push(...t))),t(o,s,n)}(l,c,-h)}return l}function n(t,e){var n;const o=e.hachureAngle+90;let a=e.hachureGap;a<0&&(a=4*e.strokeWidth),a=Math.round(Math.max(a,.1));let h=1;return e.roughness>=1&&((null===(n=e.randomizer)||void 0===n?void 0:n.next())||__rnd())>.7&&(h=a),s(t,a,o,h||1)}class o{constructor(t){this.helper=t}fillPolygons(t,e){return this._fillPolygons(t,e)}_fillPolygons(t,e){const s=n(t,e);return{type:"fillSketch",ops:this.renderLines(s,e)}}renderLines(t,e){const s=[];for(const n of t)s.push(...this.helper.doubleLineOps(n[0][0],n[0][1],n[1][0],n[1][1],e));return s}}function a(t){const e=t[0],s=t[1];return Math.sqrt(Math.pow(e[0]-s[0],2)+Math.pow(e[1]-s[1],2))}class h extends o{fillPolygons(t,e){let s=e.hachureGap;s<0&&(s=4*e.strokeWidth),s=Math.max(s,.1);const o=n(t,Object.assign({},e,{hachureGap:s})),h=Math.PI/180*e.hachureAngle,r=[],i=.5*s*Math.cos(h),c=.5*s*Math.sin(h);for(const[t,e]of o)a([t,e])&&r.push([[t[0]-i,t[1]+c],[...e]],[[t[0]+i,t[1]-c],[...e]]);return{type:"fillSketch",ops:this.renderLines(r,e)}}}class r extends o{fillPolygons(t,e){const s=this._fillPolygons(t,e),n=Object.assign({},e,{hachureAngle:e.hachureAngle+90}),o=this._fillPolygons(t,n);return s.ops=s.ops.concat(o.ops),s}}class i{constructor(t){this.helper=t}fillPolygons(t,e){const s=n(t,e=Object.assign({},e,{hachureAngle:0}));return this.dotsOnLines(s,e)}dotsOnLines(t,e){const s=[];let n=e.hachureGap;n<0&&(n=4*e.strokeWidth),n=Math.max(n,.1);let o=e.fillWeight;o<0&&(o=e.strokeWidth/2);const h=n/4;for(const r of t){const t=a(r),i=t/n,c=Math.ceil(i)-1,l=t-c*n,u=(r[0][0]+r[1][0])/2-n/4,p=Math.min(r[0][1],r[1][1]);for(let t=0;t<c;t++){const a=p+l+t*n,r=u-h+2*__rnd()*h,i=a-h+2*__rnd()*h,c=this.helper.ellipse(r,i,o,o,e);s.push(...c.ops)}}return{type:"fillSketch",ops:s}}}class c{constructor(t){this.helper=t}fillPolygons(t,e){const s=n(t,e);return{type:"fillSketch",ops:this.dashedLine(s,e)}}dashedLine(t,e){const s=e.dashOffset<0?e.hachureGap<0?4*e.strokeWidth:e.hachureGap:e.dashOffset,n=e.dashGap<0?e.hachureGap<0?4*e.strokeWidth:e.hachureGap:e.dashGap,o=[];return t.forEach((t=>{const h=a(t),r=Math.floor(h/(s+n)),i=(h+n-r*(s+n))/2;let c=t[0],l=t[1];c[0]>l[0]&&(c=t[1],l=t[0]);const u=Math.atan((l[1]-c[1])/(l[0]-c[0]));for(let t=0;t<r;t++){const a=t*(s+n),h=a+s,r=[c[0]+a*Math.cos(u)+i*Math.cos(u),c[1]+a*Math.sin(u)+i*Math.sin(u)],l=[c[0]+h*Math.cos(u)+i*Math.cos(u),c[1]+h*Math.sin(u)+i*Math.sin(u)];o.push(...this.helper.doubleLineOps(r[0],r[1],l[0],l[1],e))}})),o}}class l{constructor(t){this.helper=t}fillPolygons(t,e){const s=e.hachureGap<0?4*e.strokeWidth:e.hachureGap,o=e.zigzagOffset<0?s:e.zigzagOffset,a=n(t,e=Object.assign({},e,{hachureGap:s+o}));return{type:"fillSketch",ops:this.zigzagLines(a,o,e)}}zigzagLines(t,e,s){const n=[];return t.forEach((t=>{const o=a(t),h=Math.round(o/(2*e));let r=t[0],i=t[1];r[0]>i[0]&&(r=t[1],i=t[0]);const c=Math.atan((i[1]-r[1])/(i[0]-r[0]));for(let t=0;t<h;t++){const o=2*t*e,a=2*(t+1)*e,h=Math.sqrt(2*Math.pow(e,2)),i=[r[0]+o*Math.cos(c),r[1]+o*Math.sin(c)],l=[r[0]+a*Math.cos(c),r[1]+a*Math.sin(c)],u=[i[0]+h*Math.cos(c+Math.PI/4),i[1]+h*Math.sin(c+Math.PI/4)];n.push(...this.helper.doubleLineOps(i[0],i[1],u[0],u[1],s),...this.helper.doubleLineOps(u[0],u[1],l[0],l[1],s))}})),n}}const u={};class p{constructor(t){this.seed=t}next(){return this.seed?(2**31-1&(this.seed=Math.imul(48271,this.seed)))/2**31:__rnd()}}const f=0,d=1,g=2,M={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 k(t,e){return t.type===e}function b(t){const e=[],s=function(t){const e=new Array;for(;""!==t;)if(t.match(/^([ \t\r\n,]+)/))t=t.substr(RegExp.$1.length);else if(t.match(/^([aAcChHlLmMqQsStTvVzZ])/))e[e.length]={type:f,text:RegExp.$1},t=t.substr(RegExp.$1.length);else{if(!t.match(/^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)/))return[];e[e.length]={type:d,text:`${parseFloat(RegExp.$1)}`},t=t.substr(RegExp.$1.length)}return e[e.length]={type:g,text:""},e}(t);let n="BOD",o=0,a=s[o];for(;!k(a,g);){let h=0;const r=[];if("BOD"===n){if("M"!==a.text&&"m"!==a.text)return b("M0,0"+t);o++,h=M[a.text],n=a.text}else k(a,d)?h=M[n]:(o++,h=M[a.text],n=a.text);if(!(o+h<s.length))throw new Error("Path data ended short");for(let t=o;t<o+h;t++){const e=s[t];if(!k(e,d))throw new Error("Param not a number: "+n+","+e.text);r[r.length]=+e.text}if("number"!=typeof M[n])throw new Error("Bad segment: "+n);{const t={key:n,data:r};e.push(t),o+=h,a=s[o],"M"===n&&(n="L"),"m"===n&&(n="l")}}return e}function y(t){let e=0,s=0,n=0,o=0;const a=[];for(const{key:h,data:r}of t)switch(h){case"M":a.push({key:"M",data:[...r]}),[e,s]=r,[n,o]=r;break;case"m":e+=r[0],s+=r[1],a.push({key:"M",data:[e,s]}),n=e,o=s;break;case"L":a.push({key:"L",data:[...r]}),[e,s]=r;break;case"l":e+=r[0],s+=r[1],a.push({key:"L",data:[e,s]});break;case"C":a.push({key:"C",data:[...r]}),e=r[4],s=r[5];break;case"c":{const t=r.map(((t,n)=>n%2?t+s:t+e));a.push({key:"C",data:t}),e=t[4],s=t[5];break}case"Q":a.push({key:"Q",data:[...r]}),e=r[2],s=r[3];break;case"q":{const t=r.map(((t,n)=>n%2?t+s:t+e));a.push({key:"Q",data:t}),e=t[2],s=t[3];break}case"A":a.push({key:"A",data:[...r]}),e=r[5],s=r[6];break;case"a":e+=r[5],s+=r[6],a.push({key:"A",data:[r[0],r[1],r[2],r[3],r[4],e,s]});break;case"H":a.push({key:"H",data:[...r]}),e=r[0];break;case"h":e+=r[0],a.push({key:"H",data:[e]});break;case"V":a.push({key:"V",data:[...r]}),s=r[0];break;case"v":s+=r[0],a.push({key:"V",data:[s]});break;case"S":a.push({key:"S",data:[...r]}),e=r[2],s=r[3];break;case"s":{const t=r.map(((t,n)=>n%2?t+s:t+e));a.push({key:"S",data:t}),e=t[2],s=t[3];break}case"T":a.push({key:"T",data:[...r]}),e=r[0],s=r[1];break;case"t":e+=r[0],s+=r[1],a.push({key:"T",data:[e,s]});break;case"Z":case"z":a.push({key:"Z",data:[]}),e=n,s=o}return a}function m(t){const e=[];let s="",n=0,o=0,a=0,h=0,r=0,i=0;for(const{key:c,data:l}of t){switch(c){case"M":e.push({key:"M",data:[...l]}),[n,o]=l,[a,h]=l;break;case"C":e.push({key:"C",data:[...l]}),n=l[4],o=l[5],r=l[2],i=l[3];break;case"L":e.push({key:"L",data:[...l]}),[n,o]=l;break;case"H":n=l[0],e.push({key:"L",data:[n,o]});break;case"V":o=l[0],e.push({key:"L",data:[n,o]});break;case"S":{let t=0,a=0;"C"===s||"S"===s?(t=n+(n-r),a=o+(o-i)):(t=n,a=o),e.push({key:"C",data:[t,a,...l]}),r=l[0],i=l[1],n=l[2],o=l[3];break}case"T":{const[t,a]=l;let h=0,c=0;"Q"===s||"T"===s?(h=n+(n-r),c=o+(o-i)):(h=n,c=o);const u=n+2*(h-n)/3,p=o+2*(c-o)/3,f=t+2*(h-t)/3,d=a+2*(c-a)/3;e.push({key:"C",data:[u,p,f,d,t,a]}),r=h,i=c,n=t,o=a;break}case"Q":{const[t,s,a,h]=l,c=n+2*(t-n)/3,u=o+2*(s-o)/3,p=a+2*(t-a)/3,f=h+2*(s-h)/3;e.push({key:"C",data:[c,u,p,f,a,h]}),r=t,i=s,n=a,o=h;break}case"A":{const t=Math.abs(l[0]),s=Math.abs(l[1]),a=l[2],h=l[3],r=l[4],i=l[5],c=l[6];if(0===t||0===s)e.push({key:"C",data:[n,o,i,c,i,c]}),n=i,o=c;else if(n!==i||o!==c){x(n,o,i,c,t,s,a,h,r).forEach((function(t){e.push({key:"C",data:t})})),n=i,o=c}break}case"Z":e.push({key:"Z",data:[]}),n=a,o=h}s=c}return e}function w(t,e,s){return[t*Math.cos(s)-e*Math.sin(s),t*Math.sin(s)+e*Math.cos(s)]}function x(t,e,s,n,o,a,h,r,i,c){const l=(u=h,Math.PI*u/180);var u;let p=[],f=0,d=0,g=0,M=0;if(c)[f,d,g,M]=c;else{[t,e]=w(t,e,-l),[s,n]=w(s,n,-l);const h=(t-s)/2,c=(e-n)/2;let u=h*h/(o*o)+c*c/(a*a);u>1&&(u=Math.sqrt(u),o*=u,a*=u);const p=o*o,k=a*a,b=p*k-p*c*c-k*h*h,y=p*c*c+k*h*h,m=(r===i?-1:1)*Math.sqrt(Math.abs(b/y));g=m*o*c/a+(t+s)/2,M=m*-a*h/o+(e+n)/2,f=Math.asin(parseFloat(((e-M)/a).toFixed(9))),d=Math.asin(parseFloat(((n-M)/a).toFixed(9))),t<g&&(f=Math.PI-f),s<g&&(d=Math.PI-d),f<0&&(f=2*Math.PI+f),d<0&&(d=2*Math.PI+d),i&&f>d&&(f-=2*Math.PI),!i&&d>f&&(d-=2*Math.PI)}let k=d-f;if(Math.abs(k)>120*Math.PI/180){const t=d,e=s,r=n;d=i&&d>f?f+120*Math.PI/180*1:f+120*Math.PI/180*-1,p=x(s=g+o*Math.cos(d),n=M+a*Math.sin(d),e,r,o,a,h,0,i,[d,t,g,M])}k=d-f;const b=Math.cos(f),y=Math.sin(f),m=Math.cos(d),P=Math.sin(d),v=Math.tan(k/4),S=4/3*o*v,O=4/3*a*v,L=[t,e],T=[t+S*y,e-O*b],D=[s+S*P,n-O*m],A=[s,n];if(T[0]=2*L[0]-T[0],T[1]=2*L[1]-T[1],c)return[T,D,A].concat(p);{p=[T,D,A].concat(p);const t=[];for(let e=0;e<p.length;e+=3){const s=w(p[e][0],p[e][1],l),n=w(p[e+1][0],p[e+1][1],l),o=w(p[e+2][0],p[e+2][1],l);t.push([s[0],s[1],n[0],n[1],o[0],o[1]])}return t}}const P={randOffset:function(t,e){return G(t,e)},randOffsetWithRange:function(t,e,s){return E(t,e,s)},ellipse:function(t,e,s,n,o){const a=T(s,n,o);return D(t,e,o,a).opset},doubleLineOps:function(t,e,s,n,o){return $(t,e,s,n,o,!0)}};function v(t,e,s,n,o){return{type:"path",ops:$(t,e,s,n,o)}}function S(t,e,s){const n=(t||[]).length;if(n>2){const o=[];for(let e=0;e<n-1;e++)o.push(...$(t[e][0],t[e][1],t[e+1][0],t[e+1][1],s));return e&&o.push(...$(t[n-1][0],t[n-1][1],t[0][0],t[0][1],s)),{type:"path",ops:o}}return 2===n?v(t[0][0],t[0][1],t[1][0],t[1][1],s):{type:"path",ops:[]}}function O(t,e,s,n,o){return function(t,e){return S(t,!0,e)}([[t,e],[t+s,e],[t+s,e+n],[t,e+n]],o)}function L(t,e){if(t.length){const s="number"==typeof t[0][0]?[t]:t,n=j(s[0],1*(1+.2*e.roughness),e),o=e.disableMultiStroke?[]:j(s[0],1.5*(1+.22*e.roughness),z(e));for(let t=1;t<s.length;t++){const a=s[t];if(a.length){const t=j(a,1*(1+.2*e.roughness),e),s=e.disableMultiStroke?[]:j(a,1.5*(1+.22*e.roughness),z(e));for(const e of t)"move"!==e.op&&n.push(e);for(const t of s)"move"!==t.op&&o.push(t)}}return{type:"path",ops:n.concat(o)}}return{type:"path",ops:[]}}function T(t,e,s){const n=Math.sqrt(2*Math.PI*Math.sqrt((Math.pow(t/2,2)+Math.pow(e/2,2))/2)),o=Math.ceil(Math.max(s.curveStepCount,s.curveStepCount/Math.sqrt(200)*n)),a=2*Math.PI/o;let h=Math.abs(t/2),r=Math.abs(e/2);const i=1-s.curveFitting;return h+=G(h*i,s),r+=G(r*i,s),{increment:a,rx:h,ry:r}}function D(t,e,s,n){const[o,a]=F(n.increment,t,e,n.rx,n.ry,1,n.increment*E(.1,E(.4,1,s),s),s);let h=q(o,null,s);if(!s.disableMultiStroke&&0!==s.roughness){const[o]=F(n.increment,t,e,n.rx,n.ry,1.5,0,s),a=q(o,null,s);h=h.concat(a)}return{estimatedPoints:a,opset:{type:"path",ops:h}}}function A(t,e,s,n,o,a,h,r,i){const c=t,l=e;let u=Math.abs(s/2),p=Math.abs(n/2);u+=G(.01*u,i),p+=G(.01*p,i);let f=o,d=a;for(;f<0;)f+=2*Math.PI,d+=2*Math.PI;d-f>2*Math.PI&&(f=0,d=2*Math.PI);const g=2*Math.PI/i.curveStepCount,M=Math.min(g/2,(d-f)/2),k=V(M,c,l,u,p,f,d,1,i);if(!i.disableMultiStroke){const t=V(M,c,l,u,p,f,d,1.5,i);k.push(...t)}return h&&(r?k.push(...$(c,l,c+u*Math.cos(f),l+p*Math.sin(f),i),...$(c,l,c+u*Math.cos(d),l+p*Math.sin(d),i)):k.push({op:"lineTo",data:[c,l]},{op:"lineTo",data:[c+u*Math.cos(f),l+p*Math.sin(f)]})),{type:"path",ops:k}}function _(t,e){const s=m(y(b(t))),n=[];let o=[0,0],a=[0,0];for(const{key:t,data:h}of s)switch(t){case"M":a=[h[0],h[1]],o=[h[0],h[1]];break;case"L":n.push(...$(a[0],a[1],h[0],h[1],e)),a=[h[0],h[1]];break;case"C":{const[t,s,o,r,i,c]=h;n.push(...Z(t,s,o,r,i,c,a,e)),a=[i,c];break}case"Z":n.push(...$(a[0],a[1],o[0],o[1],e)),a=[o[0],o[1]]}return{type:"path",ops:n}}function I(t,e){const s=[];for(const n of t)if(n.length){const t=e.maxRandomnessOffset||0,o=n.length;if(o>2){s.push({op:"move",data:[n[0][0]+G(t,e),n[0][1]+G(t,e)]});for(let a=1;a<o;a++)s.push({op:"lineTo",data:[n[a][0]+G(t,e),n[a][1]+G(t,e)]})}}return{type:"fillPath",ops:s}}function C(t,e){return function(t,e){let s=t.fillStyle||"hachure";if(!u[s])switch(s){case"zigzag":u[s]||(u[s]=new h(e));break;case"cross-hatch":u[s]||(u[s]=new r(e));break;case"dots":u[s]||(u[s]=new i(e));break;case"dashed":u[s]||(u[s]=new c(e));break;case"zigzag-line":u[s]||(u[s]=new l(e));break;default:s="hachure",u[s]||(u[s]=new o(e))}return u[s]}(e,P).fillPolygons(t,e)}function z(t){const e=Object.assign({},t);return e.randomizer=void 0,t.seed&&(e.seed=t.seed+1),e}function W(t){return t.randomizer||(t.randomizer=new p(t.seed||0)),t.randomizer.next()}function E(t,e,s,n=1){return s.roughness*n*(W(s)*(e-t)+t)}function G(t,e,s=1){return E(-t,t,e,s)}function $(t,e,s,n,o,a=!1){const h=a?o.disableMultiStrokeFill:o.disableMultiStroke,r=R(t,e,s,n,o,!0,!1);if(h)return r;const i=R(t,e,s,n,o,!0,!0);return r.concat(i)}function R(t,e,s,n,o,a,h){const r=Math.pow(t-s,2)+Math.pow(e-n,2),i=Math.sqrt(r);let c=1;c=i<200?1:i>500?.4:-.0016668*i+1.233334;let l=o.maxRandomnessOffset||0;l*l*100>r&&(l=i/10);const u=l/2,p=.2+.2*W(o);let f=o.bowing*o.maxRandomnessOffset*(n-e)/200,d=o.bowing*o.maxRandomnessOffset*(t-s)/200;f=G(f,o,c),d=G(d,o,c);const g=[],M=()=>G(u,o,c),k=()=>G(l,o,c),b=o.preserveVertices;return a&&(h?g.push({op:"move",data:[t+(b?0:M()),e+(b?0:M())]}):g.push({op:"move",data:[t+(b?0:G(l,o,c)),e+(b?0:G(l,o,c))]})),h?g.push({op:"bcurveTo",data:[f+t+(s-t)*p+M(),d+e+(n-e)*p+M(),f+t+2*(s-t)*p+M(),d+e+2*(n-e)*p+M(),s+(b?0:M()),n+(b?0:M())]}):g.push({op:"bcurveTo",data:[f+t+(s-t)*p+k(),d+e+(n-e)*p+k(),f+t+2*(s-t)*p+k(),d+e+2*(n-e)*p+k(),s+(b?0:k()),n+(b?0:k())]}),g}function j(t,e,s){if(!t.length)return[];const n=[];n.push([t[0][0]+G(e,s),t[0][1]+G(e,s)]),n.push([t[0][0]+G(e,s),t[0][1]+G(e,s)]);for(let o=1;o<t.length;o++)n.push([t[o][0]+G(e,s),t[o][1]+G(e,s)]),o===t.length-1&&n.push([t[o][0]+G(e,s),t[o][1]+G(e,s)]);return q(n,null,s)}function q(t,e,s){const n=t.length,o=[];if(n>3){const a=[],h=1-s.curveTightness;o.push({op:"move",data:[t[1][0],t[1][1]]});for(let e=1;e+2<n;e++){const s=t[e];a[0]=[s[0],s[1]],a[1]=[s[0]+(h*t[e+1][0]-h*t[e-1][0])/6,s[1]+(h*t[e+1][1]-h*t[e-1][1])/6],a[2]=[t[e+1][0]+(h*t[e][0]-h*t[e+2][0])/6,t[e+1][1]+(h*t[e][1]-h*t[e+2][1])/6],a[3]=[t[e+1][0],t[e+1][1]],o.push({op:"bcurveTo",data:[a[1][0],a[1][1],a[2][0],a[2][1],a[3][0],a[3][1]]})}if(e&&2===e.length){const t=s.maxRandomnessOffset;o.push({op:"lineTo",data:[e[0]+G(t,s),e[1]+G(t,s)]})}}else 3===n?(o.push({op:"move",data:[t[1][0],t[1][1]]}),o.push({op:"bcurveTo",data:[t[1][0],t[1][1],t[2][0],t[2][1],t[2][0],t[2][1]]})):2===n&&o.push(...R(t[0][0],t[0][1],t[1][0],t[1][1],s,!0,!0));return o}function F(t,e,s,n,o,a,h,r){const i=[],c=[];if(0===r.roughness){t/=4,c.push([e+n*Math.cos(-t),s+o*Math.sin(-t)]);for(let a=0;a<=2*Math.PI;a+=t){const t=[e+n*Math.cos(a),s+o*Math.sin(a)];i.push(t),c.push(t)}c.push([e+n*Math.cos(0),s+o*Math.sin(0)]),c.push([e+n*Math.cos(t),s+o*Math.sin(t)])}else{const l=G(.5,r)-Math.PI/2;c.push([G(a,r)+e+.9*n*Math.cos(l-t),G(a,r)+s+.9*o*Math.sin(l-t)]);const u=2*Math.PI+l-.01;for(let h=l;h<u;h+=t){const t=[G(a,r)+e+n*Math.cos(h),G(a,r)+s+o*Math.sin(h)];i.push(t),c.push(t)}c.push([G(a,r)+e+n*Math.cos(l+2*Math.PI+.5*h),G(a,r)+s+o*Math.sin(l+2*Math.PI+.5*h)]),c.push([G(a,r)+e+.98*n*Math.cos(l+h),G(a,r)+s+.98*o*Math.sin(l+h)]),c.push([G(a,r)+e+.9*n*Math.cos(l+.5*h),G(a,r)+s+.9*o*Math.sin(l+.5*h)])}return[c,i]}function V(t,e,s,n,o,a,h,r,i){const c=a+G(.1,i),l=[];l.push([G(r,i)+e+.9*n*Math.cos(c-t),G(r,i)+s+.9*o*Math.sin(c-t)]);for(let a=c;a<=h;a+=t)l.push([G(r,i)+e+n*Math.cos(a),G(r,i)+s+o*Math.sin(a)]);return l.push([e+n*Math.cos(h),s+o*Math.sin(h)]),l.push([e+n*Math.cos(h),s+o*Math.sin(h)]),q(l,null,i)}function Z(t,e,s,n,o,a,h,r){const i=[],c=[r.maxRandomnessOffset||1,(r.maxRandomnessOffset||1)+.3];let l=[0,0];const u=r.disableMultiStroke?1:2,p=r.preserveVertices;for(let f=0;f<u;f++)0===f?i.push({op:"move",data:[h[0],h[1]]}):i.push({op:"move",data:[h[0]+(p?0:G(c[0],r)),h[1]+(p?0:G(c[0],r))]}),l=p?[o,a]:[o+G(c[f],r),a+G(c[f],r)],i.push({op:"bcurveTo",data:[t+G(c[f],r),e+G(c[f],r),s+G(c[f],r),n+G(c[f],r),l[0],l[1]]});return i}function Q(t){return[...t]}function H(t,e=0){const s=t.length;if(s<3)throw new Error("A curve must have at least three points.");const n=[];if(3===s)n.push(Q(t[0]),Q(t[1]),Q(t[2]),Q(t[2]));else{const s=[];s.push(t[0],t[0]);for(let e=1;e<t.length;e++)s.push(t[e]),e===t.length-1&&s.push(t[e]);const o=[],a=1-e;n.push(Q(s[0]));for(let t=1;t+2<s.length;t++){const e=s[t];o[0]=[e[0],e[1]],o[1]=[e[0]+(a*s[t+1][0]-a*s[t-1][0])/6,e[1]+(a*s[t+1][1]-a*s[t-1][1])/6],o[2]=[s[t+1][0]+(a*s[t][0]-a*s[t+2][0])/6,s[t+1][1]+(a*s[t][1]-a*s[t+2][1])/6],o[3]=[s[t+1][0],s[t+1][1]],n.push(o[1],o[2],o[3])}}return n}function N(t,e){return Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2)}function B(t,e,s){const n=N(e,s);if(0===n)return N(t,e);let o=((t[0]-e[0])*(s[0]-e[0])+(t[1]-e[1])*(s[1]-e[1]))/n;return o=Math.max(0,Math.min(1,o)),N(t,J(e,s,o))}function J(t,e,s){return[t[0]+(e[0]-t[0])*s,t[1]+(e[1]-t[1])*s]}function K(t,e,s,n){const o=n||[];if(function(t,e){const s=t[e+0],n=t[e+1],o=t[e+2],a=t[e+3];let h=3*n[0]-2*s[0]-a[0];h*=h;let r=3*n[1]-2*s[1]-a[1];r*=r;let i=3*o[0]-2*a[0]-s[0];i*=i;let c=3*o[1]-2*a[1]-s[1];return c*=c,h<i&&(h=i),r<c&&(r=c),h+r}(t,e)<s){const s=t[e+0];if(o.length){(a=o[o.length-1],h=s,Math.sqrt(N(a,h)))>1&&o.push(s)}else o.push(s);o.push(t[e+3])}else{const n=.5,a=t[e+0],h=t[e+1],r=t[e+2],i=t[e+3],c=J(a,h,n),l=J(h,r,n),u=J(r,i,n),p=J(c,l,n),f=J(l,u,n),d=J(p,f,n);K([a,c,p,d],0,s,o),K([d,f,u,i],0,s,o)}var a,h;return o}function U(t,e){return X(t,0,t.length,e)}function X(t,e,s,n,o){const a=o||[],h=t[e],r=t[s-1];let i=0,c=1;for(let n=e+1;n<s-1;++n){const e=B(t[n],h,r);e>i&&(i=e,c=n)}return Math.sqrt(i)>n?(X(t,e,c+1,n,a),X(t,c,s,n,a)):(a.length||a.push(h),a.push(r)),a}function Y(t,e=.15,s){const n=[],o=(t.length-1)/3;for(let s=0;s<o;s++){K(t,3*s,e,n)}return s&&s>0?X(n,0,n.length,s):n}const tt="none";class et{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(__rnd()*2**31)}_o(t){return t?Object.assign({},this.defaultOptions,t):this.defaultOptions}_d(t,e,s){return{shape:t,sets:e||[],options:s||this.defaultOptions}}line(t,e,s,n,o){const a=this._o(o);return this._d("line",[v(t,e,s,n,a)],a)}rectangle(t,e,s,n,o){const a=this._o(o),h=[],r=O(t,e,s,n,a);if(a.fill){const o=[[t,e],[t+s,e],[t+s,e+n],[t,e+n]];"solid"===a.fillStyle?h.push(I([o],a)):h.push(C([o],a))}return a.stroke!==tt&&h.push(r),this._d("rectangle",h,a)}ellipse(t,e,s,n,o){const a=this._o(o),h=[],r=T(s,n,a),i=D(t,e,a,r);if(a.fill)if("solid"===a.fillStyle){const s=D(t,e,a,r).opset;s.type="fillPath",h.push(s)}else h.push(C([i.estimatedPoints],a));return a.stroke!==tt&&h.push(i.opset),this._d("ellipse",h,a)}circle(t,e,s,n){const o=this.ellipse(t,e,s,s,n);return o.shape="circle",o}linearPath(t,e){const s=this._o(e);return this._d("linearPath",[S(t,!1,s)],s)}arc(t,e,s,n,o,a,h=!1,r){const i=this._o(r),c=[],l=A(t,e,s,n,o,a,h,!0,i);if(h&&i.fill)if("solid"===i.fillStyle){const h=Object.assign({},i);h.disableMultiStroke=!0;const r=A(t,e,s,n,o,a,!0,!1,h);r.type="fillPath",c.push(r)}else c.push(function(t,e,s,n,o,a,h){const r=t,i=e;let c=Math.abs(s/2),l=Math.abs(n/2);c+=G(.01*c,h),l+=G(.01*l,h);let u=o,p=a;for(;u<0;)u+=2*Math.PI,p+=2*Math.PI;p-u>2*Math.PI&&(u=0,p=2*Math.PI);const f=(p-u)/h.curveStepCount,d=[];for(let t=u;t<=p;t+=f)d.push([r+c*Math.cos(t),i+l*Math.sin(t)]);return d.push([r+c*Math.cos(p),i+l*Math.sin(p)]),d.push([r,i]),C([d],h)}(t,e,s,n,o,a,i));return i.stroke!==tt&&c.push(l),this._d("arc",c,i)}curve(t,e){const s=this._o(e),n=[],o=L(t,s);if(s.fill&&s.fill!==tt)if("solid"===s.fillStyle){const e=L(t,Object.assign(Object.assign({},s),{disableMultiStroke:!0,roughness:s.roughness?s.roughness+s.fillShapeRoughnessGain:0}));n.push({type:"fillPath",ops:this._mergedShape(e.ops)})}else{const e=[],o=t;if(o.length){const t="number"==typeof o[0][0]?[o]:o;for(const n of t)n.length<3?e.push(...n):3===n.length?e.push(...Y(H([n[0],n[0],n[1],n[2]]),10,(1+s.roughness)/2)):e.push(...Y(H(n),10,(1+s.roughness)/2))}e.length&&n.push(C([e],s))}return s.stroke!==tt&&n.push(o),this._d("curve",n,s)}polygon(t,e){const s=this._o(e),n=[],o=S(t,!0,s);return s.fill&&("solid"===s.fillStyle?n.push(I([t],s)):n.push(C([t],s))),s.stroke!==tt&&n.push(o),this._d("polygon",n,s)}path(t,e){const s=this._o(e),n=[];if(!t)return this._d("path",n,s);t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");const o=s.fill&&"transparent"!==s.fill&&s.fill!==tt,a=s.stroke!==tt,h=!!(s.simplification&&s.simplification<1),r=function(t,e,s){const n=m(y(b(t))),o=[];let a=[],h=[0,0],r=[];const i=()=>{r.length>=4&&a.push(...Y(r,e)),r=[]},c=()=>{i(),a.length&&(o.push(a),a=[])};for(const{key:t,data:e}of n)switch(t){case"M":c(),h=[e[0],e[1]],a.push(h);break;case"L":i(),a.push([e[0],e[1]]);break;case"C":if(!r.length){const t=a.length?a[a.length-1]:h;r.push([t[0],t[1]])}r.push([e[0],e[1]]),r.push([e[2],e[3]]),r.push([e[4],e[5]]);break;case"Z":i(),a.push([h[0],h[1]])}if(c(),!s)return o;const l=[];for(const t of o){const e=U(t,s);e.length&&l.push(e)}return l}(t,1,h?4-4*(s.simplification||1):(1+s.roughness)/2),i=_(t,s);if(o)if("solid"===s.fillStyle)if(1===r.length){const e=_(t,Object.assign(Object.assign({},s),{disableMultiStroke:!0,roughness:s.roughness?s.roughness+s.fillShapeRoughnessGain:0}));n.push({type:"fillPath",ops:this._mergedShape(e.ops)})}else n.push(I(r,s));else n.push(C(r,s));return a&&(h?r.forEach((t=>{n.push(S(t,!1,s))})):n.push(i)),this._d("path",n,s)}opsToPath(t,e){let s="";for(const n of t.ops){const t="number"==typeof e&&e>=0?n.data.map((t=>+t.toFixed(e))):n.data;switch(n.op){case"move":s+=`M${t[0]} ${t[1]} `;break;case"bcurveTo":s+=`C${t[0]} ${t[1]}, ${t[2]} ${t[3]}, ${t[4]} ${t[5]} `;break;case"lineTo":s+=`L${t[0]} ${t[1]} `}}return s.trim()}toPaths(t){const e=t.sets||[],s=t.options||this.defaultOptions,n=[];for(const t of e){let e=null;switch(t.type){case"path":e={d:this.opsToPath(t),stroke:s.stroke,strokeWidth:s.strokeWidth,fill:tt};break;case"fillPath":e={d:this.opsToPath(t),stroke:tt,strokeWidth:0,fill:s.fill||tt};break;case"fillSketch":e=this.fillSketch(t,s)}e&&n.push(e)}return n}fillSketch(t,e){let s=e.fillWeight;return s<0&&(s=e.strokeWidth/2),{d:this.opsToPath(t),stroke:e.fill||tt,strokeWidth:s,fill:tt}}_mergedShape(t){return t.filter(((t,e)=>0===e||"move"!==t.op))}}class st{constructor(t,e){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new et(e)}draw(t){const e=t.sets||[],s=t.options||this.getDefaultOptions(),n=this.ctx,o=t.options.fixedDecimalPlaceDigits;for(const a of e)switch(a.type){case"path":n.save(),n.strokeStyle="none"===s.stroke?"transparent":s.stroke,n.lineWidth=s.strokeWidth,s.strokeLineDash&&n.setLineDash(s.strokeLineDash),s.strokeLineDashOffset&&(n.lineDashOffset=s.strokeLineDashOffset),this._drawToContext(n,a,o),n.restore();break;case"fillPath":{n.save(),n.fillStyle=s.fill||"";const e="curve"===t.shape||"polygon"===t.shape||"path"===t.shape?"evenodd":"nonzero";this._drawToContext(n,a,o,e),n.restore();break}case"fillSketch":this.fillSketch(n,a,s)}}fillSketch(t,e,s){let n=s.fillWeight;n<0&&(n=s.strokeWidth/2),t.save(),s.fillLineDash&&t.setLineDash(s.fillLineDash),s.fillLineDashOffset&&(t.lineDashOffset=s.fillLineDashOffset),t.strokeStyle=s.fill||"",t.lineWidth=n,this._drawToContext(t,e,s.fixedDecimalPlaceDigits),t.restore()}_drawToContext(t,e,s,n="nonzero"){t.beginPath();for(const n of e.ops){const e="number"==typeof s&&s>=0?n.data.map((t=>+t.toFixed(s))):n.data;switch(n.op){case"move":t.moveTo(e[0],e[1]);break;case"bcurveTo":t.bezierCurveTo(e[0],e[1],e[2],e[3],e[4],e[5]);break;case"lineTo":t.lineTo(e[0],e[1])}}"fillPath"===e.type?t.fill(n):t.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(t,e,s,n,o){const a=this.gen.line(t,e,s,n,o);return this.draw(a),a}rectangle(t,e,s,n,o){const a=this.gen.rectangle(t,e,s,n,o);return this.draw(a),a}ellipse(t,e,s,n,o){const a=this.gen.ellipse(t,e,s,n,o);return this.draw(a),a}circle(t,e,s,n){const o=this.gen.circle(t,e,s,n);return this.draw(o),o}linearPath(t,e){const s=this.gen.linearPath(t,e);return this.draw(s),s}polygon(t,e){const s=this.gen.polygon(t,e);return this.draw(s),s}arc(t,e,s,n,o,a,h=!1,r){const i=this.gen.arc(t,e,s,n,o,a,h,r);return this.draw(i),i}curve(t,e){const s=this.gen.curve(t,e);return this.draw(s),s}path(t,e){const s=this.gen.path(t,e);return this.draw(s),s}}const nt="http://www.w3.org/2000/svg";class ot{constructor(t,e){this.svg=t,this.gen=new et(e)}draw(t){const e=t.sets||[],s=t.options||this.getDefaultOptions(),n=this.svg.ownerDocument||window.document,o=n.createElementNS(nt,"g"),a=t.options.fixedDecimalPlaceDigits;for(const h of e){let e=null;switch(h.type){case"path":e=n.createElementNS(nt,"path"),e.setAttribute("d",this.opsToPath(h,a)),e.setAttribute("stroke",s.stroke),e.setAttribute("stroke-width",s.strokeWidth+""),e.setAttribute("fill","none"),s.strokeLineDash&&e.setAttribute("stroke-dasharray",s.strokeLineDash.join(" ").trim()),s.strokeLineDashOffset&&e.setAttribute("stroke-dashoffset",`${s.strokeLineDashOffset}`);break;case"fillPath":e=n.createElementNS(nt,"path"),e.setAttribute("d",this.opsToPath(h,a)),e.setAttribute("stroke","none"),e.setAttribute("stroke-width","0"),e.setAttribute("fill",s.fill||""),"curve"!==t.shape&&"polygon"!==t.shape||e.setAttribute("fill-rule","evenodd");break;case"fillSketch":e=this.fillSketch(n,h,s)}e&&o.appendChild(e)}return o}fillSketch(t,e,s){let n=s.fillWeight;n<0&&(n=s.strokeWidth/2);const o=t.createElementNS(nt,"path");return o.setAttribute("d",this.opsToPath(e,s.fixedDecimalPlaceDigits)),o.setAttribute("stroke",s.fill||""),o.setAttribute("stroke-width",n+""),o.setAttribute("fill","none"),s.fillLineDash&&o.setAttribute("stroke-dasharray",s.fillLineDash.join(" ").trim()),s.fillLineDashOffset&&o.setAttribute("stroke-dashoffset",`${s.fillLineDashOffset}`),o}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}opsToPath(t,e){return this.gen.opsToPath(t,e)}line(t,e,s,n,o){const a=this.gen.line(t,e,s,n,o);return this.draw(a)}rectangle(t,e,s,n,o){const a=this.gen.rectangle(t,e,s,n,o);return this.draw(a)}ellipse(t,e,s,n,o){const a=this.gen.ellipse(t,e,s,n,o);return this.draw(a)}circle(t,e,s,n){const o=this.gen.circle(t,e,s,n);return this.draw(o)}linearPath(t,e){const s=this.gen.linearPath(t,e);return this.draw(s)}polygon(t,e){const s=this.gen.polygon(t,e);return this.draw(s)}arc(t,e,s,n,o,a,h=!1,r){const i=this.gen.arc(t,e,s,n,o,a,h,r);return this.draw(i)}curve(t,e){const s=this.gen.curve(t,e);return this.draw(s)}path(t,e){const s=this.gen.path(t,e);return this.draw(s)}}return{canvas:(t,e)=>new st(t,e),svg:(t,e)=>new ot(t,e),generator:t=>new et(t),newSeed:()=>et.newSeed()}}();

// ---------------------------------------------------------------------------------------------
// view "excalidraw": a hand-drawn Excalidraw-style diagram that keeps running.
// Everything is drawn in a design space (`space:[W,H]`, default [1000,1250]) and scaled uniformly
// ("contain") into the rect, so one config fits 4:5, 3:4 and 1:1.
// ---------------------------------------------------------------------------------------------
// Excalidraw palette (packages/common/src/colors.ts, COLOR_PALETTE: fill = index 1, deep = open-color 9).
var PAL={
 blue:  {fill:'#a5d8ff', strong:'#1971c2', deep:'#1864ab'},
 green: {fill:'#b2f2bb', strong:'#2f9e44', deep:'#2b8a3e'},
 red:   {fill:'#ffc9c9', strong:'#e03131', deep:'#c92a2a'},
 yellow:{fill:'#ffec99', strong:'#f08c00', deep:'#e67700'},
 violet:{fill:'#d0bfff', strong:'#6741d9', deep:'#5f3dc4'},
 gray:  {fill:'#e9ecef', strong:'#868e96', deep:'#495057'},
 white: {fill:'#ffffff', strong:'#1e1e1e', deep:'#1e1e1e'}
};
var INK='#1e1e1e';
var NUM=/-?\d*\.?\d+(?:e[-+]?\d+)?/gi;

function hueOf(ctx,h){ h=h||'blue'; var p=PAL[h]||PAL.blue, o={};
  // a theme may override any of them: colours `x<hue>`, `x<hue>s`, `x<hue>d`
  ['fill','strong','deep'].forEach(function(k,i){ var n='x'+h+(i===0?'':i===1?'s':'d'); var c=ctx.col(n); o[k]=c||p[k]; });
  return o; }
function tone(ctx,c){ if(!c) return INK; if(c.charAt(0)==='#') return c; if(PAL[c]) return hueOf(ctx,c).deep;
  var t={ink:INK,slate:'#4c6085',sage:'#3f6450',muted:'#5c636b'}; if(t[c]) return ctx.col('x'+c)||t[c]; return ctx.col(c)||INK; }
function lerpD(a,b,k){ var na=a.match(NUM), nb=b.match(NUM); if(!na||!nb||na.length!==nb.length) return null;
  if(a.replace(NUM,'')!==b.replace(NUM,'')) return null;
  var i=0; return a.replace(NUM,function(){ var v=+na[i]+(+nb[i]-+na[i])*k; i++; return String(Math.round(v*100)/100); }); }
function rrPath(x,y,w,h,r){ r=Math.min(r,w/2,h/2);
  return 'M '+(x+r)+' '+y+' L '+(x+w-r)+' '+y+' Q '+(x+w)+' '+y+', '+(x+w)+' '+(y+r)+' L '+(x+w)+' '+(y+h-r)+' Q '+(x+w)+' '+(y+h)+', '+(x+w-r)+' '+(y+h)+
    ' L '+(x+r)+' '+(y+h)+' Q '+x+' '+(y+h)+', '+x+' '+(y+h-r)+' L '+x+' '+(y+r)+' Q '+x+' '+y+', '+(x+r)+' '+y+' Z'; }
// Catmull-Rom through the points -> cubic Bezier path (the centreline used for carriers and arrow heads)
function crPath(P){ var d='M '+P[0][0]+' '+P[0][1];
  for(var i=0;i<P.length-1;i++){ var p0=P[i-1]||P[i], p1=P[i], p2=P[i+1], p3=P[i+2]||p2;
    d+=' C '+(p1[0]+(p2[0]-p0[0])/6)+' '+(p1[1]+(p2[1]-p0[1])/6)+', '+(p2[0]-(p3[0]-p1[0])/6)+' '+(p2[1]-(p3[1]-p1[1])/6)+', '+p2[0]+' '+p2[1]; }
  return d; }
function clamp(x){ return x<0?0:x>1?1:x; }

LP.registerView('excalidraw',{
 build:function(ctx){
  var e=ctx.e, R=ctx.rect, SP=e.space||[1000,1250], SW=SP[0], SH=SP[1];
  var s=Math.min(R.w/SW,R.h/SH), ox=(R.w-SW*s)/2, oy=(R.h-SH*s)/2;
  var period=e.period||24, seed=e.seed||7, boil=e.boil||{}, V=Math.max(1,boil.variants||4), step=boil.step||0.125, amp=boil.amp!=null?boil.amp:0.35;
  var ROUGH=e.roughness!=null?e.roughness:1, SWD=e.strokeWidth||2, FONT='var(--font)';
  var S={t0:e.t0||0,period:period,V:V,step:step,boils:[],nodes:{},edges:{},steps:[],notes:[],problems:[],dash:[],lastK:-1};
  var gen=rough.generator();
  var W=ctx.el('div','','position:absolute;left:'+ox+'px;top:'+oy+'px;width:'+SW+'px;height:'+SH+'px;transform-origin:0 0;transform:scale('+s+');white-space:pre;font-family:'+FONT+';color:'+INK);
  ctx.root.appendChild(W);
  var svg=ctx.svg('svg',{width:SW,height:SH,viewBox:'0 0 '+SW+' '+SH}); svg.style.cssText='position:absolute;left:0;top:0;overflow:visible;pointer-events:none';
  W.appendChild(svg);
  function layer(){ var g=ctx.svg('g'); svg.appendChild(g); return g; }
  var gZone=layer(), gUnder=layer(), gEdge=layer(), gNode=layer(), gIcon=layer(), gOver=layer(), gCarry=layer();
  var seedN=0; function nextSeed(){ seedN++; return (seed*7919+seedN*104729)%2147483000+1; }

  // one rough shape with V boil variants (variant k = base nudged towards an independent sketch by `amp`)
  function shape(parent,fn,opt,attrs,noBoil){
   var s0=nextSeed(), base=gen.toPaths(fn(Object.assign({},opt,{seed:s0}))), sets=[base];
   var nv=noBoil?1:V;
   for(var k=1;k<nv;k++){ var o=gen.toPaths(fn(Object.assign({},opt,{seed:s0+k*7907}))), out=[];
     if(o.length!==base.length){ S.problems.push('boil variant structure differs'); sets.push(base); continue; }
     for(var j=0;j<base.length;j++){ var d=lerpD(base[j].d,o[j].d,amp); if(d==null){ S.problems.push('boil path mismatch'); d=base[j].d; } out.push(Object.assign({},base[j],{d:d})); }
     sets.push(out); }
   var gs=sets.map(function(ps,k){ var g=ctx.svg('g'); if(k>0) g.style.display='none';
     ps.forEach(function(p){ var pa=ctx.svg('path',{d:p.d,stroke:p.stroke||'none','stroke-width':p.strokeWidth||0,fill:p.fill||'none','stroke-linecap':'round','stroke-linejoin':'round'});
       if(attrs) Object.keys(attrs).forEach(function(a){ pa.setAttribute(a,attrs[a]); });
       if(p.fill&&p.fill!=='none'&&(!p.stroke||p.stroke==='none')) pa.setAttribute('stroke','none');
       g.appendChild(pa); });
     parent.appendChild(g); return g; });
   if(gs.length>1) S.boils.push(gs);
   return {gs:gs, base:base};
  }
  function div(parent,css){ var d=ctx.el('div','','position:absolute;'+css); parent.appendChild(d); return d; }
  function textBlock(parent,str,x,y,size,col,align,maxW,lh){ // y = vertical centre of the block
   var lines=String(str).split('\n'), sz=size;
   if(maxW) lines.forEach(function(l){ var f=ctx.fit(l,sz,maxW,FONT,11); sz=Math.min(sz,f.size); });
   lh=Math.round(sz*(lh||1.22)); var h=lh*lines.length, w=maxW||Math.max.apply(null,lines.map(function(l){return ctx.measure(l,sz,FONT)}))+4;
   var left=align==='left'?x:align==='right'?x-w:x-w/2;
   var d=div(parent,'left:'+left+'px;top:'+(y-h/2)+'px;width:'+w+'px;font-size:'+sz+'px;line-height:'+lh+'px;text-align:'+(align||'center')+';color:'+col);
   d.textContent=lines.join('\n'); ctx.mark(d,'text'); return d;
  }

  // ---- zones: a pale wash behind a group of boxes (e.g. inner vs outer loop), drawn once, no boil ----
  (e.zones||[]).forEach(function(Z){ var zf=Z.fill||(Z.hue?hueOf(ctx,Z.hue).fill:'#f1f3f5');
    shape(gZone,function(o){return gen.path(rrPath(Z.x,Z.y,Z.w,Z.h,Z.r||36),o)},{roughness:Z.roughness!=null?Z.roughness:0.9,strokeWidth:Z.stroke?1.6:0,stroke:Z.stroke?tone(ctx,Z.stroke):'none',fill:zf,fillStyle:'solid',preserveVertices:true,disableMultiStroke:true},{opacity:Z.opacity!=null?Z.opacity:1},true); });

  // ---- static texts (title, section labels, asides) ----
  (e.texts||[]).forEach(function(T){ var d=textBlock(W,T.t,T.x,T.y,T.size||28,tone(ctx,T.c),T.align||'center',T.w,T.lh);
    if(T.rot) d.style.transform='rotate('+T.rot+'deg)'; if(T.weight) d.style.webkitTextStroke=T.weight+'px currentColor';
    if(T.underline){ var U=T.underline, w=U.w||ctx.measure(String(T.t).split('\n')[0],parseFloat(d.style.fontSize),FONT), x0=T.align==='left'?T.x:T.align==='right'?T.x-w:T.x-w/2, yy=T.y+(U.dy||parseFloat(d.style.fontSize)*0.62);
      if(U.hue){ var hc=hueOf(ctx,U.hue); shape(gUnder,function(o){return gen.line(x0-6,yy,x0+w+6,yy+(U.tilt||-3),o)},{roughness:1.4,strokeWidth:U.width||12,stroke:hc.fill,disableMultiStroke:true},{opacity:0.9}); }
      else shape(gIcon,function(o){return gen.curve([[x0,yy],[x0+w*0.5,yy+3],[x0+w,yy-2]],o)},{roughness:0.8,strokeWidth:2.4,stroke:INK,disableMultiStroke:false}); } });

  // ---- icons (hand-drawn line art, low roughness, like the Excalidraw library) ----
  (e.icons||[]).forEach(function(I){ var x=I.x, y=I.y, w=I.w||100, k=I.kind, op={roughness:I.roughness!=null?I.roughness:0.55,strokeWidth:I.strokeWidth||1.8,stroke:tone(ctx,I.c||'ink'),fill:'#ffffff',fillStyle:'solid'}, gi=gIcon;
    if(k==='laptop'){ var sw=w*0.78, sh=w*0.5;
      shape(gi,function(o){return gen.path(rrPath(x-sw/2,y-sh*0.62,sw,sh,4),o)},op);
      shape(gi,function(o){return gen.rectangle(x-sw/2+7,y-sh*0.62+7,sw-14,sh-14,o)},Object.assign({},op,{fill:undefined}));
      shape(gi,function(o){return gen.polygon([[x-sw/2-4,y+sh*0.38+2],[x+sw/2+4,y+sh*0.38+2],[x+w/2,y+sh*0.38+w*0.12],[x-w/2,y+sh*0.38+w*0.12]],o)},op);
      shape(gi,function(o){return gen.line(x-w*0.1,y+sh*0.38+w*0.07,x+w*0.1,y+sh*0.38+w*0.07,o)},op);
    } else if(k==='cloud'){ var h=w*0.5, c='M '+(x-w*0.38)+' '+(y+h*0.45)+' C '+(x-w*0.56)+' '+(y+h*0.45)+', '+(x-w*0.56)+' '+(y-h*0.05)+', '+(x-w*0.34)+' '+(y-h*0.02)+
        ' C '+(x-w*0.36)+' '+(y-h*0.5)+', '+(x-w*0.02)+' '+(y-h*0.62)+', '+(x+w*0.06)+' '+(y-h*0.28)+' C '+(x+w*0.18)+' '+(y-h*0.5)+', '+(x+w*0.44)+' '+(y-h*0.36)+', '+(x+w*0.36)+' '+(y-h*0.02)+
        ' C '+(x+w*0.56)+' '+(y+h*0.02)+', '+(x+w*0.56)+' '+(y+h*0.45)+', '+(x+w*0.36)+' '+(y+h*0.45)+' Z';
      shape(gi,function(o){return gen.path(c,o)},op);
    } else if(k==='sprout'){ var hh=w*0.9;
      shape(gi,function(o){return gen.curve([[x,y+hh*0.5],[x-2,y+hh*0.1],[x,y-hh*0.2]],o)},Object.assign({},op,{fill:undefined,stroke:hueOf(ctx,'green').deep}));
      shape(gi,function(o){return gen.path('M '+x+' '+(y-hh*0.05)+' C '+(x-w*0.15)+' '+(y-hh*0.35)+', '+(x-w*0.45)+' '+(y-hh*0.3)+', '+(x-w*0.5)+' '+(y-hh*0.12)+' C '+(x-w*0.35)+' '+(y+hh*0.02)+', '+(x-w*0.1)+' '+(y+hh*0.02)+', '+x+' '+(y-hh*0.05)+' Z',o)},Object.assign({},op,{fill:hueOf(ctx,'green').fill}));
      shape(gi,function(o){return gen.path('M '+x+' '+(y-hh*0.2)+' C '+(x+w*0.1)+' '+(y-hh*0.55)+', '+(x+w*0.42)+' '+(y-hh*0.55)+', '+(x+w*0.5)+' '+(y-hh*0.38)+' C '+(x+w*0.38)+' '+(y-hh*0.18)+', '+(x+w*0.12)+' '+(y-hh*0.14)+', '+x+' '+(y-hh*0.2)+' Z',o)},Object.assign({},op,{fill:hueOf(ctx,'green').fill}));
      shape(gi,function(o){return gen.line(x-w*0.4,y+hh*0.5,x+w*0.4,y+hh*0.5,o)},op);
    } else if(k==='server'){ var bw=w*0.7, bh=w*0.28;
      [0,1].forEach(function(r){ var yy=y-bh+r*(bh+6);
        shape(gi,function(o){return gen.path(rrPath(x-bw/2,yy,bw,bh,5),o)},op);
        shape(gi,function(o){return gen.line(x-bw/2+12,yy+bh/2,x-bw/2+bw*0.45,yy+bh/2,o)},op);
        shape(gi,function(o){return gen.circle(x+bw/2-14,yy+bh/2,6,o)},Object.assign({},op,{fill:hueOf(ctx,'green').strong})); });
    } else if(k==='person'){ var hr=w*0.16;
      shape(gi,function(o){return gen.circle(x,y-w*0.18,hr*2,o)},op);
      shape(gi,function(o){return gen.path('M '+(x-w*0.3)+' '+(y+w*0.32)+' C '+(x-w*0.3)+' '+(y+w*0.02)+', '+(x+w*0.3)+' '+(y+w*0.02)+', '+(x+w*0.3)+' '+(y+w*0.32)+' Z',o)},op);
    } else S.problems.push('unknown icon "'+k+'"'); });

  // ---- nodes: rounded pastel box, double rough stroke, centred handwritten label ----
  (e.nodes||[]).forEach(function(n,i){ var H=hueOf(ctx,n.hue), x0=n.x-n.w/2, y0=n.y-n.h/2, r=n.r!=null?n.r:Math.min(32,Math.min(n.w,n.h)*0.25);
    var sh=shape(gNode,function(o){return gen.path(rrPath(x0,y0,n.w,n.h,r),o)},{roughness:ROUGH,strokeWidth:SWD,stroke:INK,fill:H.fill,fillStyle:'solid',preserveVertices:true});
    var box=div(W,'left:'+x0+'px;top:'+y0+'px;width:'+n.w+'px;height:'+n.h+'px'); ctx.mark(box,'box');
    var lines=String(n.t).split('\n'), sz=n.size||34, pad=n.pad||16, subs=n.sub?String(n.sub).split('\n'):[], ssz=n.subSize||Math.round(sz*0.6);
    lines.forEach(function(l){ sz=Math.min(sz,ctx.fit(l,sz,n.w-pad*2,FONT,11).size); });
    subs.forEach(function(l){ ssz=Math.min(ssz,ctx.fit(l,ssz,n.w-pad*2,FONT,11).size); });
    var lh=Math.round(sz*1.16), slh=Math.round(ssz*1.25), gap=subs.length?Math.round(ssz*0.35):0, th=lh*lines.length+gap+slh*subs.length, ty=(n.h-th)/2;
    var t1=div(box,'left:'+pad+'px;top:'+ty+'px;width:'+(n.w-pad*2)+'px;text-align:center;font-size:'+sz+'px;line-height:'+lh+'px;-webkit-text-stroke:'+(n.weight!=null?n.weight:(e.textWeight!=null?e.textWeight:0.5))+'px '+INK+';color:'+INK); t1.textContent=lines.join('\n'); ctx.mark(t1,'text');
    if(subs.length){ var t2=div(box,'left:'+pad+'px;top:'+(ty+lh*lines.length+gap)+'px;width:'+(n.w-pad*2)+'px;text-align:center;font-size:'+ssz+'px;line-height:'+slh+'px;color:'+tone(ctx,n.subC||'muted')); t2.textContent=subs.join('\n'); ctx.mark(t2,'text'); }
    // focus: a pen loop around the box (squircle, ~1.15 turns so the stroke overshoots its start), drawn on like a pen
    var off=n.focusOff||13, ax=n.w/2+off, ay=n.h/2+off, lp=[], per=2*(2*ax+2*ay)*0.93, ovl=e.focusOverlap||44, turns=1+ovl/per, M=Math.round(48*turns), th0=-2.25+0.4*ctx.hash(seed,i), wob=e.focusWobble!=null?e.focusWobble:3;
    for(var j=0;j<=M;j++){ var th=th0+turns*2*Math.PI*j/M, c=Math.cos(th), sn=Math.sin(th), ex=Math.pow(Math.abs(c),0.4)*(c<0?-1:1), ey=Math.pow(Math.abs(sn),0.4)*(sn<0?-1:1), jit=1+0.03*j/M;
      lp.push([n.x+ax*ex*jit+(j/M)*3+wob*Math.sin(th*3+i*1.7), n.y+ay*ey*jit+wob*Math.sin(th*5+i*2.3)]); }
    var fo=gen.toPaths(gen.curve(lp,{seed:nextSeed(),roughness:e.focusRough!=null?e.focusRough:0.9,strokeWidth:3,stroke:H.strong,disableMultiStroke:true}));
    var fg=ctx.svg('g'); fg.style.display='none'; gOver.appendChild(fg);
    var fps=fo.map(function(p){ var pa=ctx.svg('path',{d:p.d,stroke:H.strong,'stroke-width':3,fill:'none','stroke-linecap':'round','stroke-linejoin':'round'}); fg.appendChild(pa); return pa; });
    var flen=fps.map(function(pa){ return pa.getTotalLength(); });
    S.nodes[n.id]={n:n,H:H,box:box,fg:fg,fps:fps,flen:flen,x0:x0,y0:y0};
  });

  // ---- edges ----
  function anchor(n,side,off,gap){ off=off||0; gap=gap==null?(e.edgeGap!=null?e.edgeGap:22):gap; var x=n.x,y=n.y,w=n.w,h=n.h;
    if(side==='top') return [x+off*w/2,y-h/2-gap]; if(side==='bottom') return [x+off*w/2,y+h/2+gap];
    if(side==='left') return [x-w/2-gap,y+off*h/2]; return [x+w/2+gap,y+off*h/2]; }
  (e.edges||[]).forEach(function(E,i){ var A=S.nodes[E.from], B=S.nodes[E.to]; if(!E.pts&&(!A||!B)){ S.problems.push('edge '+(E.id||i)+': unknown node'); return; }
    var P=E.pts;
    if(!P){ var a=anchor(A.n,E.fromSide||'right',E.fromOff,E.gap), b=anchor(B.n,E.toSide||'left',E.toOff,E.gap), dx=b[0]-a[0], dy=b[1]-a[1], L=Math.hypot(dx,dy)||1, bd=E.bend||0;
      var m=E.via||[(a[0]+b[0])/2-dy/L*bd*L,(a[1]+b[1])/2+dx/L*bd*L]; P=Math.abs(bd)<1e-6&&!E.via?[a,b]:[a,m,b]; }
    var dashed=!!E.dashed, sw=(E.width||(dashed?SWD+0.5:SWD+0.2)), col=tone(ctx,E.c||'ink');
    var op={roughness:E.roughness!=null?E.roughness:ROUGH*(e.edgeRough!=null?e.edgeRough:0.9),strokeWidth:sw,stroke:col,disableMultiStroke:true,preserveVertices:true};
    function stroke(Q,o){ return Q.length===2?gen.line(Q[0][0],Q[0][1],Q[1][0],Q[1][1],o):gen.curve(Q,o); }
    var body=shape(gEdge,function(o){return stroke(P,o)},op,dashed?{'stroke-dasharray':'9 '+(9+sw)}:null);
    // centreline samples
    var cl=ctx.svg('path',{d:crPath(P),fill:'none',stroke:'none'}); gEdge.appendChild(cl); var len=cl.getTotalLength(), N=96, smp=[];
    for(var k=0;k<=N;k++){ var q=cl.getPointAtLength(len*k/N); smp.push([q.x,q.y]); }
    // the second pen stroke of a solid arrow stops short of the head (a full double stroke hooks at the tip)
    if(!dashed&&e.edgeMulti!==false){ var Q2=[0,0.3,0.6,0.86].map(function(f){ var q=smp[Math.round(f*N)]; return [q[0],q[1]]; });
      shape(gEdge,function(o){return gen.curve(Q2,o)},Object.assign({},op,{strokeWidth:sw*0.8,roughness:op.roughness*1.15}),{opacity:0.9}); }
    var tip=smp[N], back=cl.getPointAtLength(Math.max(0,len-18)), ang=Math.atan2(tip[1]-back.y,tip[0]-back.x), hl=E.head||22, ha=(E.headAngle||27)*Math.PI/180;
    var h1=[tip[0]-hl*Math.cos(ang-ha),tip[1]-hl*Math.sin(ang-ha)], h2=[tip[0]-hl*Math.cos(ang+ha),tip[1]-hl*Math.sin(ang+ha)];
    shape(gEdge,function(o){return gen.linearPath([h1,tip,h2],o)},Object.assign({},op,{strokeWidth:Math.max(SWD+0.2,sw*0.9),roughness:0.6,disableMultiStroke:false}));
    // a dashed arrow ends in a short solid stub so no dash fragment dangles under the head
    if(dashed){ var st0=cl.getPointAtLength(Math.max(0,len-15)); shape(gEdge,function(o){return gen.line(st0.x,st0.y,tip[0],tip[1],o)},Object.assign({},op,{roughness:0.4})); }
    if(dashed) S.dash.push({gs:body.gs,cyc:18+sw,n:Math.max(1,Math.round(period*(E.dashSpeed||16)/(18+sw)))});
    // pen overlay: the same stroke in the source hue, drawn on behind the carrier
    var src=A?A.H:hueOf(ctx,'gray'), ov=body.base[0];
    var opa=ctx.svg('path',{d:ov.d,stroke:src.strong,'stroke-width':sw+1,fill:'none','stroke-linecap':'round'}); opa.style.display='none'; gOver.appendChild(opa);
    var olen=opa.getTotalLength();
    // carrier: a dot for solid arrows, a little paper note for dashed ones
    var car=ctx.svg('g'); car.style.display='none'; gCarry.appendChild(car);
    if(dashed){ var nw=E.noteW||58, nh=E.noteH||38, paper=gen.toPaths(gen.path(rrPath(-nw/2,-nh/2,nw,nh,4),{seed:nextSeed(),roughness:1,strokeWidth:1.8,stroke:INK,fill:hueOf(ctx,'yellow').fill,fillStyle:'solid',preserveVertices:true}));
      paper.forEach(function(p){ car.appendChild(ctx.svg('path',{d:p.d,stroke:p.stroke||'none','stroke-width':p.strokeWidth||0,fill:p.fill||'none'})); });
      [-0.22,0.02,0.26].forEach(function(f,j){ var ln=gen.toPaths(gen.line(-nw/2+9,nh*f,nw/2-9-(j===2?16:0),nh*f+1,{seed:nextSeed(),roughness:1.2,strokeWidth:1.6,stroke:'#495057',disableMultiStroke:true}))[0];
        car.appendChild(ctx.svg('path',{d:ln.d,stroke:'#495057','stroke-width':1.6,fill:'none','stroke-linecap':'round'})); });
    } else { car.appendChild(ctx.svg('circle',{r:10,fill:src.strong,'fill-opacity':0.18})); car.appendChild(ctx.svg('circle',{r:6,fill:src.strong})); }
    // label
    if(E.label){ var la=E.labelAt||[(smp[N/2][0]),(smp[N/2][1]-30)]; textBlock(W,E.label,la[0],la[1],E.labelSize||28,tone(ctx,E.labelC||'ink'),E.labelAlign||'center',E.labelW); }
    S.edges[E.id||('e'+i)]={E:E,smp:smp,N:N,ov:opa,olen:olen,car:car,dashed:dashed};
  });

  // ---- steps: one protagonist at a time (node focus + handwritten note, then its arrow is inked and carried) ----
  var steps=e.steps||[], wsum=steps.reduce(function(a,st){return a+(st.dur||1)},0)||1, acc0=0;
  S.starts=steps.map(function(st){ var t0=acc0; acc0+=period*(st.dur||1)/wsum; return t0; }); S.durs=steps.map(function(st){return period*(st.dur||1)/wsum});
  var D=period/(steps.length||1); S.D=D; S.fade=Math.min(0.35,D*0.2); S.gap=e.focusGap!=null?e.focusGap:0.12;
  steps.forEach(function(st,i){ var N_=S.nodes[st.node]; if(!N_){ S.problems.push('step '+(i+1)+': unknown node "'+st.node+'"'); return; }
    var ed=st.edge?S.edges[st.edge]:null; if(st.edge&&!ed) S.problems.push('step '+(i+1)+': unknown edge "'+st.edge+'"');
    if(ed&&ed.E.from&&ed.E.from!==st.node) S.problems.push('step '+(i+1)+': edge '+st.edge+' does not leave '+st.node);
    var nt=null;
    if(st.note){ var n=N_.n, side=st.side||n.noteSide||'top', g=st.gap!=null?st.gap:18, sz=st.size||e.noteSize||24, pos=st.at;
      if(!pos){ pos=side==='top'?[n.x,n.y-n.h/2-g-sz*0.6]:side==='bottom'?[n.x,n.y+n.h/2+g+sz*0.6]:side==='left'?[n.x-n.w/2-g,n.y]:[n.x+n.w/2+g,n.y]; }
      var al=st.align||(side==='left'?'right':side==='right'?'left':'center');
      nt=textBlock(W,st.note,pos[0],pos[1],sz,N_.H.deep,al,st.w); nt.style.display='none'; nt.style.transform='rotate('+(st.rot!=null?st.rot:-1.5)+'deg)'; }
    S.steps.push({node:N_,edge:ed,note:nt,dwell:st.dwell!=null?st.dwell:(ed?0.4:1)}); });
  return S;
 },

 seek:function(t,ctx,S){
  var P=S.period, tt=(((t+S.t0)%P)+P)%P;
  // boil: every `step` seconds the next sketch variant (a whole number of cycles per period)
  var k=Math.floor(tt/S.step+1e-6)%S.V;
  if(k!==S.lastK){ S.boils.forEach(function(gs){ for(var j=0;j<gs.length;j++) gs[j].style.display=j===k?'':'none'; }); S.lastK=k; }
  // dashed arrows march towards their head, a whole number of dash cycles per period
  S.dash.forEach(function(d){ var off=-(tt/P)*d.n*d.cyc; d.gs.forEach(function(g){ for(var c=g.firstChild;c;c=c.nextSibling) c.setAttribute('stroke-dashoffset',off.toFixed(2)); }); });
  var n=S.steps.length; if(!n) return;
  var cur=0; while(cur<n-1&&tt>=S.starts[cur+1]-1e-9) cur++; var D=S.durs[cur], p=(tt-S.starts[cur])/D, prev=(cur-1+n)%n, fadeT=(p*D)/S.fade, fade=1-LP.ease.smooth(fadeT);
  // reset
  Object.keys(S.nodes).forEach(function(id){ S.nodes[id].fg.style.display='none'; });
  Object.keys(S.edges).forEach(function(id){ var E=S.edges[id]; E.ov.style.display='none'; E.car.style.display='none'; });
  S.steps.forEach(function(st){ if(st.note) st.note.style.display='none'; });
  function show(st,ph,op,isCur){ // ph: phase 0..1 of that step, op: opacity
   var N_=st.node, dw=st.dwell;
   // focus outline drawn on during the first 70% of the dwell
   var dq=Math.min(dw,0.45), ps=isCur?(S.fade+S.gap)/D:0; var q=LP.ease.inOut(clamp((ph-ps)/(dq*0.75)));
   if(q>0.002){ N_.fg.style.display=''; N_.fg.style.opacity=op;
     var tot=N_.flen.reduce(function(a,b){return a+b},0), acc=0;
     N_.fps.forEach(function(pa,j){ var L=N_.flen[j], u=clamp((q*tot-acc)/L); acc+=L; pa.style.display=u>0.002?'':'none'; pa.setAttribute('stroke-dasharray',L.toFixed(1)+' '+(L+2).toFixed(1)); pa.setAttribute('stroke-dashoffset',(L*(1-u)).toFixed(1)); }); }
   var nd=isCur?(S.fade+S.gap)/D:0; if(st.note&&ph>=nd){ var r=clamp((ph-nd)/Math.max(0.2,dq*0.8)); st.note.style.display=''; st.note.style.opacity=op; st.note.style.clipPath='inset(-20% '+((1-LP.ease.out(r))*100).toFixed(1)+'% -20% -4%)'; }
   if(st.edge){ var E=st.edge, u=LP.ease.inOut(clamp((ph-dw)/(0.96-dw)));
     // fading out (previous step): the ink retracts from its tail towards the head at full strength, so it never
     // turns into a translucent colour over the black line
     if(ph>dw){ E.ov.style.display=(u>0.01&&op>0.02)?'':'none'; E.ov.style.opacity=E.dashed?0:1; E.ov.setAttribute('stroke-dasharray',E.olen.toFixed(1)+' '+(E.olen+2).toFixed(1));
       E.ov.setAttribute('stroke-dashoffset',(op<1?-(E.olen+2)*(1-op)*0.999:E.olen*(1-u)).toFixed(1));
       var f=u*E.N, i0=Math.min(E.N-1,Math.floor(f)), w=f-i0, a=E.smp[i0], b=E.smp[i0+1], x=a[0]+(b[0]-a[0])*w, y=a[1]+(b[1]-a[1])*w;
       var arrive=clamp((ph-0.9)/0.1); E.car.style.display=''; E.car.style.opacity=(op*(1-0.6*arrive)).toFixed(3);
       E.car.setAttribute('transform','translate('+x.toFixed(1)+' '+y.toFixed(1)+')'+(E.dashed?' rotate('+(-6+4*Math.sin(u*Math.PI*2)).toFixed(1)+')':'')); } }
  }
  if(fade>0&&prev!==cur) show(S.steps[prev],1,fade);
  show(S.steps[cur],p,1,true);
 },

 check:function(ctx){ var S=ctx.state; var out=(S&&S.problems)||[];
  if(S){ var cyc=S.period/S.step; if(Math.abs(cyc-Math.round(cyc))>1e-6||Math.round(cyc)%S.V) out=out.concat(['boil does not loop: period/step must be a whole multiple of variants']); }
  return out.filter(function(v,i,a){return a.indexOf(v)===i}); }
});

})();
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall