iso-explainer 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +110 -2
  3. package/README.pt-BR.md +88 -0
  4. package/bin/iso-explainer.mjs +75 -0
  5. package/package.json +37 -4
  6. package/skills/iso-explainer/SKILL.md +92 -0
  7. package/skills/iso-explainer/assets/fonts/OFL.txt +93 -0
  8. package/skills/iso-explainer/assets/fonts/jetbrains-mono-latin-400-normal.woff2 +0 -0
  9. package/skills/iso-explainer/assets/fonts/jetbrains-mono-latin-500-normal.woff2 +0 -0
  10. package/skills/iso-explainer/assets/fonts/jetbrains-mono-latin-600-normal.woff2 +0 -0
  11. package/skills/iso-explainer/assets/fonts/jetbrains-mono-latin-700-normal.woff2 +0 -0
  12. package/skills/iso-explainer/assets/fonts/jetbrains-mono-latin-800-normal.woff2 +0 -0
  13. package/skills/iso-explainer/assets/runtime/LUCIDE-LICENSE.txt +43 -0
  14. package/skills/iso-explainer/assets/runtime/app.js +687 -0
  15. package/skills/iso-explainer/assets/runtime/engine.js +1177 -0
  16. package/skills/iso-explainer/assets/runtime/icons.js +205 -0
  17. package/skills/iso-explainer/assets/runtime/styles.css +447 -0
  18. package/skills/iso-explainer/assets/runtime/template.html +29 -0
  19. package/skills/iso-explainer/assets/templates/starter.course.json +134 -0
  20. package/skills/iso-explainer/examples/arquitetura-pedidos.docs.json +1743 -0
  21. package/skills/iso-explainer/examples/engenharia-na-pratica.course.json +2074 -0
  22. package/skills/iso-explainer/examples/figures/token-bucket.html +98 -0
  23. package/skills/iso-explainer/examples/historia-pedidos.story.json +1872 -0
  24. package/skills/iso-explainer/references/architecture-mode.md +82 -0
  25. package/skills/iso-explainer/references/design-system.md +58 -0
  26. package/skills/iso-explainer/references/engine.md +64 -0
  27. package/skills/iso-explainer/references/entities.md +70 -0
  28. package/skills/iso-explainer/references/flows.md +67 -0
  29. package/skills/iso-explainer/references/inside.md +64 -0
  30. package/skills/iso-explainer/references/layout.md +122 -0
  31. package/skills/iso-explainer/references/schema.md +157 -0
  32. package/skills/iso-explainer/references/story-mode.md +72 -0
  33. package/skills/iso-explainer/references/storytelling.md +56 -0
  34. package/skills/iso-explainer/scripts/build.mjs +80 -0
  35. package/skills/iso-explainer/scripts/harvest.mjs +240 -0
  36. package/skills/iso-explainer/scripts/lib/resolve.mjs +251 -0
  37. package/skills/iso-explainer/scripts/snapshot.mjs +97 -0
  38. package/skills/iso-explainer/scripts/validate.mjs +41 -0
@@ -0,0 +1,98 @@
1
+ <!doctype html>
2
+ <html lang="pt-BR">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>Rate limit · token bucket</title>
7
+ <!-- Stand-in figure for the example. In real use, build mechanism figures like this with the anatomy skill
8
+ (npx skills add wheresryan22/anatomy -g) and point `inside.html` at its self-contained page. -->
9
+ <style>
10
+ :root { --bg: #faf3e9; --ink: #1d1b18; --muted: #6f6961; --card: #fbf7f1; --line: #ddd3c5; --coin: #f6cd82; --coin-2: #efb041; --ok: #9fd28f; --bad: #e5534b; --req: #f3b47f; --glass: #e6dbf4; color-scheme: light; }
11
+ :root[data-theme="dark"] { --bg: #2a2621; --ink: #efe6d6; --muted: #a3998b; --card: #2e2a24; --line: #4f473d; --glass: #3e3152; color-scheme: dark; }
12
+ * { box-sizing: border-box; }
13
+ html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 13px/1.4 "JetBrains Mono", ui-monospace, Menlo, monospace; }
14
+ body { display: grid; grid-template-rows: minmax(0, 1fr) auto; }
15
+ svg { width: 100%; height: 100%; display: block; }
16
+ .ctl { display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: center; padding: 10px 16px; border-top: 1px solid var(--line); background: var(--card); }
17
+ label { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); }
18
+ label b { color: var(--ink); min-width: 52px; }
19
+ input[type=range] { width: 120px; accent-color: #5fae57; }
20
+ .stat { margin-left: auto; display: flex; gap: 14px; font-size: 11.5px; }
21
+ .stat span b { font-size: 14px; }
22
+ .ok b { color: #3f8f4e; } .bad b { color: #c0392b; }
23
+ </style>
24
+ </head>
25
+ <body>
26
+ <svg viewBox="0 0 640 360" role="img" aria-label="Token bucket: fichas entram numa taxa fixa; cada requisição consome uma ficha; sem fichas, a requisição recebe 429.">
27
+ <defs>
28
+ <linearGradient id="glass" x1="0" x2="1"><stop offset="0" stop-color="var(--glass)" stop-opacity=".55"/><stop offset=".5" stop-color="#ffffff" stop-opacity=".35"/><stop offset="1" stop-color="var(--glass)" stop-opacity=".7"/></linearGradient>
29
+ <pattern id="grid" width="28" height="14" patternUnits="userSpaceOnUse"><path d="M0 7 L14 0 L28 7 L14 14 Z" fill="none" stroke="#a8916f" stroke-opacity=".22" stroke-width=".8"/></pattern>
30
+ </defs>
31
+ <rect width="640" height="360" fill="url(#grid)"/>
32
+ <!-- faucet -->
33
+ <g transform="translate(320 46)" stroke="var(--ink)" stroke-width="1.8" stroke-linejoin="round">
34
+ <rect x="-70" y="-14" width="100" height="22" rx="6" fill="var(--card)"/>
35
+ <path d="M18 8 v18 h-16 v-10" fill="var(--card)"/>
36
+ <text x="-62" y="2" font-size="10.5" font-weight="800" fill="var(--ink)" stroke="none" id="rateLabel">+2 fichas/s</text>
37
+ </g>
38
+ <!-- bucket (cylinder) -->
39
+ <g id="bucket" transform="translate(320 0)">
40
+ <ellipse cx="0" cy="292" rx="96" ry="20" fill="#6b5236" opacity=".18"/>
41
+ <path d="M-86 110 V282 A86 22 0 0 0 86 282 V110" fill="url(#glass)" stroke="var(--ink)" stroke-width="2"/>
42
+ <g id="coins"></g>
43
+ <ellipse cx="0" cy="110" rx="86" ry="22" fill="none" stroke="var(--ink)" stroke-width="2"/>
44
+ <text x="104" y="118" font-size="10.5" fill="var(--muted)">capacidade</text><text x="104" y="132" font-size="12" font-weight="800" fill="var(--ink)">10 fichas</text>
45
+ </g>
46
+ <!-- lanes -->
47
+ <path d="M40 240 H224" stroke="var(--ink)" stroke-width="1.6" stroke-dasharray="5 5" fill="none"/>
48
+ <path d="M416 210 H600" stroke="var(--ink)" stroke-width="1.6" fill="none"/>
49
+ <path d="M416 266 H600" stroke="#c0392b" stroke-width="1.6" stroke-dasharray="6 5" fill="none"/>
50
+ <text x="40" y="228" font-size="10.5" fill="var(--muted)">requisições</text>
51
+ <text x="600" y="200" font-size="10.5" fill="var(--muted)" text-anchor="end">200 · segue para a API</text>
52
+ <text x="600" y="286" font-size="10.5" fill="#c0392b" text-anchor="end">429 · Too Many Requests</text>
53
+ <g id="drops"></g><g id="reqs"></g>
54
+ </svg>
55
+ <div class="ctl">
56
+ <label>reposição <input id="refill" type="range" min="1" max="8" value="2"/><b id="refillV">2/s</b></label>
57
+ <label>tráfego <input id="load" type="range" min="1" max="12" value="5"/><b id="loadV">5 req/s</b></label>
58
+ <div class="stat"><span class="ok">aceitas <b id="okN">0</b></span><span class="bad">rejeitadas <b id="badN">0</b></span></div>
59
+ </div>
60
+ <script>
61
+ {
62
+ const $ = (id) => document.getElementById(id), NS = 'http://www.w3.org/2000/svg';
63
+ const mk = (tag, a) => { const n = document.createElementNS(NS, tag); for (const k in a) n.setAttribute(k, a[k]); return n; };
64
+ const still = matchMedia('(prefers-reduced-motion: reduce)').matches;
65
+ const CAP = 10; let tokens = 6, refill = 2, load = 5, ok = 0, bad = 0, accR = 0, accL = 0, last = performance.now();
66
+ const drops = [], reqs = [];
67
+ function drawCoins() {
68
+ const g = $('coins'); g.innerHTML = '';
69
+ for (let i = 0; i < Math.floor(tokens); i++) {
70
+ const y = 272 - i * 15, x = (i % 2 ? 10 : -10);
71
+ g.appendChild(mk('ellipse', { cx: x, cy: y + 4, rx: 30, ry: 8, fill: 'var(--coin-2)', stroke: 'var(--ink)', 'stroke-width': 1.5 }));
72
+ g.appendChild(mk('ellipse', { cx: x, cy: y, rx: 30, ry: 8, fill: 'var(--coin)', stroke: 'var(--ink)', 'stroke-width': 1.5 }));
73
+ }
74
+ }
75
+ function spawnDrop() { const c = mk('ellipse', { rx: 12, ry: 4, fill: 'var(--coin)', stroke: 'var(--ink)', 'stroke-width': 1.3 }); $('drops').appendChild(c); drops.push({ el: c, y: 74 }); }
76
+ function spawnReq() { const c = mk('circle', { r: 6, fill: 'var(--req)', stroke: 'var(--ink)', 'stroke-width': 1.5 }); $('reqs').appendChild(c); reqs.push({ el: c, x: 40, y: 240, state: 'in' }); }
77
+ function tick(t) {
78
+ const dt = Math.min(0.05, (t - last) / 1000); last = t;
79
+ accR += dt * refill; while (accR >= 1) { accR--; if (tokens + drops.length < CAP) spawnDrop(); }
80
+ accL += dt * load; while (accL >= 1) { accL--; spawnReq(); }
81
+ for (let i = drops.length - 1; i >= 0; i--) { const d = drops[i]; d.y += dt * 260; d.el.setAttribute('cx', 320); d.el.setAttribute('cy', d.y);
82
+ const top = 272 - Math.floor(tokens) * 15; if (d.y >= top) { d.el.remove(); drops.splice(i, 1); tokens = Math.min(CAP, tokens + 1); drawCoins(); } }
83
+ for (let i = reqs.length - 1; i >= 0; i--) { const r = reqs[i];
84
+ if (r.state === 'in') { r.x += dt * 160; if (r.x >= 228) { if (tokens >= 1) { tokens--; ok++; r.state = 'ok'; r.y = 210; r.x = 416; drawCoins(); } else { bad++; r.state = 'bad'; r.y = 266; r.x = 416; r.el.setAttribute('fill', 'var(--bad)'); } } }
85
+ else { r.x += dt * 200; if (r.state === 'ok') r.el.setAttribute('fill', 'var(--ok)'); if (r.x > 610) { r.el.remove(); reqs.splice(i, 1); continue; } }
86
+ r.el.setAttribute('cx', r.x); r.el.setAttribute('cy', r.y);
87
+ }
88
+ $('okN').textContent = ok; $('badN').textContent = bad;
89
+ if (!still) requestAnimationFrame(tick);
90
+ }
91
+ $('refill').oninput = (e) => { refill = +e.target.value; $('refillV').textContent = `${refill}/s`; $('rateLabel').textContent = `+${refill} fichas/s`; };
92
+ $('load').oninput = (e) => { load = +e.target.value; $('loadV').textContent = `${load} req/s`; };
93
+ drawCoins();
94
+ if (still) { tick(performance.now() + 16); } else requestAnimationFrame(tick);
95
+ }
96
+ </script>
97
+ </body>
98
+ </html>