iso-explainer 0.0.0-stage → 1.1.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 (48) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +119 -2
  3. package/README.pt-BR.md +89 -0
  4. package/bin/iso-explainer.mjs +75 -0
  5. package/package.json +37 -4
  6. package/skills/iso-explainer/SKILL.md +99 -0
  7. package/skills/iso-explainer/assets/figure/figure.mjs +93 -0
  8. package/skills/iso-explainer/assets/fonts/OFL.txt +93 -0
  9. package/skills/iso-explainer/assets/fonts/jetbrains-mono-latin-400-normal.woff2 +0 -0
  10. package/skills/iso-explainer/assets/fonts/jetbrains-mono-latin-500-normal.woff2 +0 -0
  11. package/skills/iso-explainer/assets/fonts/jetbrains-mono-latin-600-normal.woff2 +0 -0
  12. package/skills/iso-explainer/assets/fonts/jetbrains-mono-latin-700-normal.woff2 +0 -0
  13. package/skills/iso-explainer/assets/fonts/jetbrains-mono-latin-800-normal.woff2 +0 -0
  14. package/skills/iso-explainer/assets/runtime/ANATOMY-LICENSE.txt +21 -0
  15. package/skills/iso-explainer/assets/runtime/LUCIDE-LICENSE.txt +43 -0
  16. package/skills/iso-explainer/assets/runtime/app.js +727 -0
  17. package/skills/iso-explainer/assets/runtime/engine.js +1224 -0
  18. package/skills/iso-explainer/assets/runtime/icons.js +205 -0
  19. package/skills/iso-explainer/assets/runtime/kit.js +676 -0
  20. package/skills/iso-explainer/assets/runtime/looks-core.js +162 -0
  21. package/skills/iso-explainer/assets/runtime/looks.js +508 -0
  22. package/skills/iso-explainer/assets/runtime/styles.css +461 -0
  23. package/skills/iso-explainer/assets/runtime/template.html +29 -0
  24. package/skills/iso-explainer/assets/templates/starter.course.json +134 -0
  25. package/skills/iso-explainer/examples/arquitetura-pedidos.docs.json +1745 -0
  26. package/skills/iso-explainer/examples/catalogo-looks.course.json +599 -0
  27. package/skills/iso-explainer/examples/engenharia-na-pratica.course.json +2079 -0
  28. package/skills/iso-explainer/examples/figures/token-bucket.build.mjs +111 -0
  29. package/skills/iso-explainer/examples/figures/token-bucket.html +962 -0
  30. package/skills/iso-explainer/examples/historia-pedidos.story.json +1874 -0
  31. package/skills/iso-explainer/references/architecture-mode.md +82 -0
  32. package/skills/iso-explainer/references/design-system.md +58 -0
  33. package/skills/iso-explainer/references/engine.md +64 -0
  34. package/skills/iso-explainer/references/entities.md +72 -0
  35. package/skills/iso-explainer/references/figure-craft.md +62 -0
  36. package/skills/iso-explainer/references/flows.md +67 -0
  37. package/skills/iso-explainer/references/inside.md +74 -0
  38. package/skills/iso-explainer/references/layout.md +134 -0
  39. package/skills/iso-explainer/references/looks.md +60 -0
  40. package/skills/iso-explainer/references/schema.md +157 -0
  41. package/skills/iso-explainer/references/story-mode.md +72 -0
  42. package/skills/iso-explainer/references/storytelling.md +56 -0
  43. package/skills/iso-explainer/scripts/build.mjs +82 -0
  44. package/skills/iso-explainer/scripts/harvest.mjs +240 -0
  45. package/skills/iso-explainer/scripts/lib/layout.mjs +111 -0
  46. package/skills/iso-explainer/scripts/lib/resolve.mjs +269 -0
  47. package/skills/iso-explainer/scripts/snapshot.mjs +159 -0
  48. package/skills/iso-explainer/scripts/validate.mjs +58 -0
@@ -0,0 +1,159 @@
1
+ #!/usr/bin/env node
2
+ // Visual QA: screenshot every step of a built course and audit the layout.
3
+ // node scripts/snapshot.mjs dist/index.html [--out shots] [--lesson id] [--step n]
4
+ // [--viewport desktop|tablet|mobile|all] [--theme light|dark|both] [--wait 2700] [--insides]
5
+ // --insides also opens every drill-down (once per inside per lesson) and shoots it.
6
+ // Writes PNGs + report.json. Exit 1 on console errors or any layout issue (overlap, covers, clipped, hud,
7
+ // blocked); --lenient fails only on errors (console, blocked controls).
8
+ // Needs Playwright + a Chromium (npm i -D playwright && npx playwright install chromium),
9
+ // or an installed Chrome/Edge, or set CHROME_PATH.
10
+ import fs from 'node:fs';
11
+ import path from 'node:path';
12
+ import { pathToFileURL } from 'node:url';
13
+
14
+ let chromium;
15
+ for (const spec of ['playwright', 'playwright-core', ...(process.env.PLAYWRIGHT_PATH ? [process.env.PLAYWRIGHT_PATH] : [])]) {
16
+ try { ({ chromium } = await import(spec)); break; } catch {}
17
+ }
18
+ if (!chromium) { console.error('Playwright not found. Install it: npm i -D playwright && npx playwright install chromium'); process.exit(2); }
19
+
20
+ const args = process.argv.slice(2);
21
+ const opt = (n, d) => { const i = args.indexOf(n); return i >= 0 ? args[i + 1] : d; };
22
+ const BOOL = new Set(['--insides', '--lenient']); // flags without a value
23
+ const file = args.find((a, i) => !a.startsWith('-') && !(args[i - 1]?.startsWith('-') && !BOOL.has(args[i - 1])));
24
+ if (!file) { console.error('usage: node scripts/snapshot.mjs <built.html> [--out dir] [--lesson id] [--step n] [--viewport desktop|tablet|mobile|all] [--theme light|dark|both] [--insides] [--lenient] [--wait ms]'); process.exit(2); }
25
+ const out = path.resolve(opt('--out', 'shots'));
26
+ const wait = +opt('--wait', 2700);
27
+ const VP = { desktop: [1440, 900, 1], tablet: [1024, 768, 1], mobile: [390, 844, 2] };
28
+ const vps = opt('--viewport', 'desktop') === 'all' ? Object.keys(VP) : [opt('--viewport', 'desktop')];
29
+ const themes = opt('--theme', 'light') === 'both' ? ['light', 'dark'] : [opt('--theme', 'light')];
30
+ fs.mkdirSync(out, { recursive: true });
31
+
32
+ // Browser: CHROME_PATH → Playwright's bundled Chromium → installed Chrome/Edge (any OS).
33
+ const launchOpts = [{ executablePath: process.env.CHROME_PATH }, {}, { channel: 'chrome' }, { channel: 'msedge' }]
34
+ .filter((o, i) => i > 0 || o.executablePath).map((o) => ({ ...o, args: ['--no-sandbox'] }));
35
+ let browser;
36
+ for (const o of launchOpts) { try { browser = await chromium.launch(o); break; } catch {} }
37
+ if (!browser) { console.error('No Chromium found. Run: npx playwright install chromium (or set CHROME_PATH).'); process.exit(2); }
38
+ const url = pathToFileURL(path.resolve(file)).href;
39
+ const report = { shots: [], consoleErrors: [], issues: [] };
40
+
41
+ // In-page audit of one stage (the main one, or the mini stage of an open inside view):
42
+ // overlap two labels/pills on top of each other
43
+ // covers a label or pill on top of another entity's body (the object can't be read)
44
+ // clipped a label sticking out of the stage card
45
+ // hud a label under the metric chips, tools or legend
46
+ // blocked a visible control whose centre doesn't receive the click (something is painted over it)
47
+ const audit = (inside) => {
48
+ const root = inside ? document.querySelector('#inspect') : document.querySelector('#stage');
49
+ const svg = (inside ? document.querySelector('#inspect-canvas') : document.querySelector('#canvas'))?.querySelector('svg');
50
+ if (!root || !svg) return [];
51
+ const hud = [...root.querySelectorAll(inside ? '.mini-chip, #inspect-legend span' : '#hud .chip, .stage__tools .tool:not([hidden]), #legend span')].map((n) => n.getBoundingClientRect());
52
+ const visible = (n) => { let o = 1; for (let p = n; p && p !== svg; p = p.parentElement) o *= +(getComputedStyle(p).opacity || 1); return o > 0.72; }; // same rule as the camera: dim ≥ 0.5 is context, which a focus step may cut at the frame
53
+ const items = [...svg.querySelectorAll('.layer-over > g, .layer-hud > g')]
54
+ .flatMap((g) => [...g.querySelectorAll('.pill'), ...(g.closest('.layer-hud') ? [g] : [])])
55
+ .filter(visible)
56
+ .map((n) => ({ r: n.getBoundingClientRect(), text: n.textContent.trim().slice(0, 40), owner: n.closest('g[data-id]')?.dataset.id || null, hudCard: !!n.closest('.layer-hud') }))
57
+ .filter((x) => x.r.width > 2 && x.r.height > 2);
58
+ // entity bodies: the drawn object (look or shape), shrunk so that soft shadows and outlines don't count
59
+ const bodies = [...svg.querySelectorAll('.layer-ents > g[data-id]')].filter((g) => visible(g)).map((g) => {
60
+ const b = (g.querySelector('.look') || g).getBoundingClientRect(), sx = b.width * 0.2, sy = b.height * 0.2;
61
+ return { id: g.dataset.id, r: { left: b.left + sx, right: b.right - sx, top: b.top + sy, bottom: b.bottom - sy } };
62
+ }).filter((x) => x.r.right > x.r.left && x.r.bottom > x.r.top);
63
+ const issues = [];
64
+ const where = inside ? ' (inside)' : '';
65
+ const inter = (a, b) => Math.max(0, Math.min(a.right, b.right) - Math.max(a.left, b.left)) * Math.max(0, Math.min(a.bottom, b.bottom) - Math.max(a.top, b.top));
66
+ for (let i = 0; i < items.length; i++) for (let j = i + 1; j < items.length; j++) {
67
+ const a = items[i], b = items[j], ov = inter(a.r, b.r);
68
+ if (ov > 40) issues.push({ level: 'warn', kind: 'overlap', msg: `"${a.text}" overlaps "${b.text}" (${Math.round(ov)} px²)${where}` });
69
+ }
70
+ for (const x of items) for (const e of bodies) {
71
+ if (e.id === x.owner) continue;
72
+ const ov = inter(x.r, e.r);
73
+ if (ov > 60) issues.push({ level: 'warn', kind: 'covers', msg: `"${x.text}" covers entity "${e.id}" (${Math.round(ov)} px²) — move one of them or the link label (labelAt)${where}` });
74
+ }
75
+ const card = root.getBoundingClientRect();
76
+ for (const x of items) {
77
+ if (x.r.left < card.left - 1 || x.r.right > card.right + 1 || x.r.top < card.top - 1 || x.r.bottom > card.bottom + 1) issues.push({ level: 'warn', kind: 'clipped', msg: `"${x.text}" sticks out of the stage${where}` });
78
+ if (!x.hudCard) for (const h of hud) if (inter(x.r, h) > 60) { issues.push({ level: 'warn', kind: 'hud', msg: `"${x.text}" is under the HUD/tools/legend${where}` }); break; }
79
+ }
80
+ return issues;
81
+ };
82
+ // blocked: a visible control that doesn't receive a real click. elementFromPoint is not enough: Chrome
83
+ // can answer it with the button while the actual pointer event goes to an overflowing SVG on top, so
84
+ // this asks Playwright for a trial click, which checks the element that really gets the event.
85
+ const CONTROLS = { main: '#replay, #pause, #expand, #back, #next, #theme-btn', inside: '#inspect-close, [data-ins-go]' };
86
+ async function blocked(page, inside) {
87
+ const issues = [], where = inside ? ' (inside)' : '';
88
+ for (const loc of await page.locator(inside ? CONTROLS.inside : CONTROLS.main).all()) {
89
+ if (!(await loc.isVisible()) || !(await loc.isEnabled())) continue;
90
+ try { await loc.click({ trial: true, timeout: 1500 }); }
91
+ catch (e) {
92
+ const by = /<(\w+)[^>]*?(?:class="([^"]*)")?[^>]*>[^\n]*intercepts pointer events/.exec(e.message);
93
+ const name = await loc.evaluate((b) => (b.id ? '#' + b.id : b.getAttribute('aria-label') || b.textContent.trim().slice(0, 30)));
94
+ issues.push({ level: 'error', kind: 'blocked', msg: `control ${name} doesn't receive clicks${by ? ` — <${by[1]} class="${by[2] || ''}"> is on top` : ''}${where}` });
95
+ }
96
+ }
97
+ return issues;
98
+ }
99
+
100
+ for (const vp of vps) for (const theme of themes) {
101
+ const [w, h, dpr] = VP[vp];
102
+ const ctx = await browser.newContext({ viewport: { width: w, height: h }, deviceScaleFactor: dpr, reducedMotion: 'no-preference' });
103
+ await ctx.addInitScript((th) => { try { for (const k of Object.keys(localStorage)) if (k.endsWith(':theme')) localStorage.removeItem(k); } catch {} void th; }, theme);
104
+ const page = await ctx.newPage();
105
+ page.on('console', (m) => { if (m.type() === 'error') report.consoleErrors.push(`[${vp}/${theme}] ${m.text()}`); });
106
+ page.on('pageerror', (e) => report.consoleErrors.push(`[${vp}/${theme}] ${e.message}`));
107
+ await page.goto(url);
108
+ await page.waitForTimeout(400);
109
+ const seenInside = new Set();
110
+ const course = await page.evaluate(() => ({ lessons: Object.fromEntries(Object.entries(window.__COURSE__.lessons).map(([k, l]) => [k, l.steps.length])), id: window.__COURSE__.meta.id }));
111
+ if (theme === 'dark') await page.evaluate(() => { if (document.documentElement.dataset.theme !== 'dark') document.querySelector('#theme-btn').click(); });
112
+ for (const [lid, n] of Object.entries(course.lessons)) {
113
+ if (opt('--lesson') && opt('--lesson') !== lid) continue;
114
+ for (let s = 1; s <= n; s++) {
115
+ if (opt('--step') && +opt('--step') !== s) continue;
116
+ await page.evaluate((h) => { location.hash = h; }, `#/${lid}/${s}`);
117
+ await page.waitForTimeout(250);
118
+ await page.waitForFunction(() => window.__isx && !window.__isx.state.animating, null, { timeout: 15000 }).catch(() => {});
119
+ await page.waitForTimeout(Math.max(600, wait - 2000)); // let packets flow so the shot shows traffic
120
+ const name = `${lid}-${String(s).padStart(2, '0')}-${vp}-${theme}.png`;
121
+ await page.screenshot({ path: path.join(out, name) });
122
+ const issues = [...await page.evaluate(audit, false), ...await blocked(page, false)].map((x) => ({ ...x, shot: name }));
123
+ report.issues.push(...issues);
124
+ report.shots.push(name);
125
+ process.stdout.write(`${issues.length ? '!' : '·'}`);
126
+ if (args.includes('--insides')) { // open every drill-down on this step (once per inside per lesson) and shoot it
127
+ const ids = await page.evaluate(() => [...window.__isx.stage.ents.values()].filter((e) => e.cur.inside).map((e) => [e.id, e.cur.inside]));
128
+ for (const [id, key] of ids) {
129
+ if (seenInside.has(`${lid}:${key}`)) continue;
130
+ seenInside.add(`${lid}:${key}`);
131
+ await page.evaluate((h) => { location.hash = h; }, `#/${lid}/${s}/${id}`);
132
+ await page.waitForFunction(() => !document.querySelector('#inspect').hidden, null, { timeout: 5000 }).catch(() => {});
133
+ await page.waitForTimeout(Math.max(1200, wait - 1000));
134
+ const iname = `${lid}-${String(s).padStart(2, '0')}-inside-${key}-${vp}-${theme}.png`;
135
+ await page.screenshot({ path: path.join(out, iname) });
136
+ report.shots.push(iname);
137
+ report.issues.push(...[...await page.evaluate(audit, true), ...await blocked(page, true)].map((x) => ({ ...x, shot: iname })));
138
+ await page.keyboard.press('Escape');
139
+ await page.waitForTimeout(300);
140
+ process.stdout.write('◦');
141
+ }
142
+ }
143
+ }
144
+ }
145
+ await ctx.close();
146
+ }
147
+ await browser.close();
148
+ fs.writeFileSync(path.join(out, 'report.json'), JSON.stringify(report, null, 2));
149
+ console.log(`\n${report.shots.length} screenshots → ${path.relative(process.cwd(), out)}/`);
150
+ for (const e of report.consoleErrors) console.log(`console error ${e}`);
151
+ const byShot = {};
152
+ for (const i of report.issues) (byShot[i.shot] ||= []).push(`${i.kind}: ${i.msg}`);
153
+ for (const [s, l] of Object.entries(byShot)) console.log(`${s}\n ${[...new Set(l)].join('\n ')}`);
154
+ // Any finding fails the run: a deliverable has zero console errors and zero layout issues.
155
+ // --lenient reports them without failing (for exploratory runs).
156
+ const failing = report.consoleErrors.length + (args.includes('--lenient') ? report.issues.filter((i) => i.level === 'error').length : report.issues.length);
157
+ if (failing) console.log(`\n✗ ${report.consoleErrors.length} console error(s), ${report.issues.length} layout issue(s) — fix them and run again`);
158
+ else console.log('\n✓ no console errors, no layout issues');
159
+ process.exit(failing ? 1 : 0);
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env node
2
+ // Validate a course without building. Prints errors/warnings with JSON paths; exit 1 on errors.
3
+ // node scripts/validate.mjs course.json [--json]
4
+ // Also runs geometry checks on every lesson step and every native inside step: overlapping
5
+ // footprints, links too short to hold their label, crowded scenes and too many pills.
6
+ import path from 'node:path';
7
+ import { loadCourse, resolveCourse } from './lib/resolve.mjs';
8
+
9
+ const file = process.argv.slice(2).find((a) => !a.startsWith('-'));
10
+ if (!file) { console.error('usage: node scripts/validate.mjs <course.json|course.mjs> [--json]'); process.exit(2); }
11
+ const { course, errors, warnings } = resolveCourse(await loadCourse(file), { baseDir: path.dirname(path.resolve(file)) });
12
+
13
+ const fp = (e) => {
14
+ if (e.type === 'crowd' || e.type === 'zone') return [e.x0, e.x1, e.y0, e.y1];
15
+ if (e.type === 'device') return [e.x - (e.d ?? 6) / 2, e.x + (e.d ?? 6) / 2, e.y - (e.w ?? 6) / 2, e.y + (e.w ?? 6) / 2];
16
+ if (e.type === 'db') { const r = e.r ?? 1.7; return [e.x - r, e.x + r, e.y - r, e.y + r]; }
17
+ if (e.type === 'queue' || e.type === 'panel' || e.type === 'ghost') return null;
18
+ const hx = (e.d ?? e.s ?? 4) / 2, hy = (e.w ?? e.s ?? 4) / 2;
19
+ return [e.x - hx, e.x + hx, e.y - hy, e.y + hy];
20
+ };
21
+ // Screen geometry (engine projection: 14(x+y), 7(x−y)); labels are 9.5 px JetBrains Mono pills.
22
+ const screen = (x, y) => [14 * (x + y), 7 * (x - y)];
23
+ const halfWidth = (e) => { const f = fp(e); return f ? 7 * ((f[1] - f[0]) + (f[3] - f[2])) : 0; }; // half of the diamond's width
24
+ const labelWidth = (text) => Math.max(...String(text).split('\n').map((l) => l.length)) * 5.8 + 22;
25
+
26
+ const reported = new Set();
27
+ function checkScene(P, scene) {
28
+ const ents = Object.entries(scene.entities).filter(([, e]) => e.type !== 'zone' && e.type !== 'panel');
29
+ for (let i = 0; i < ents.length; i++) for (let j = i + 1; j < ents.length; j++) {
30
+ const a = fp(ents[i][1]), b = fp(ents[j][1]);
31
+ if (!a || !b) continue;
32
+ const ox = Math.min(a[1], b[1]) - Math.max(a[0], b[0]), oy = Math.min(a[3], b[3]) - Math.max(a[2], b[2]);
33
+ if (ox > -1.5 && oy > -1.5) warnings.push(`${P}: "${ents[i][0]}" and "${ents[j][0]}" are ${ox > 0 && oy > 0 ? 'overlapping' : 'touching'} — keep ≥ 3 grid units between footprints (≥ 6 when labels/pills sit between them), or drop x/y and let the layout place them`);
34
+ }
35
+ // A labelled link whose objects nearly touch has nowhere to put its pill (the engine can set a label
36
+ // beside a line, but not beside a line that has no length): it ends up on one of the objects.
37
+ // Calibrated on real cases: below ~32 px of visible line the label lands on an object.
38
+ for (const [id, l] of Object.entries(scene.links || {})) {
39
+ const a = scene.entities[l.from], b = l.to && scene.entities[l.to];
40
+ if (!l.label || !a || !b || l.pts?.length > 2 || typeof a.x !== 'number' || typeof b.x !== 'number') continue;
41
+ const [ax, ay] = screen(a.x, a.y), [bx, by] = screen(b.x, b.y);
42
+ const gap = Math.hypot(bx - ax, by - ay) - halfWidth(a) - halfWidth(b), key = `${P.replace(/\.steps\[\d+\]$/, '')}.links.${id}`;
43
+ if (gap < 32 && !reported.has(key)) { reported.add(key); warnings.push(`${P}.links.${id}: "${l.from}" and "${l.to}" are too close for the label "${l.label}" (~${Math.max(0, Math.round(gap))} px of line; ~${Math.round(labelWidth(l.label))} px label) — it will sit on an object: move them apart, or drop x/y and let the layout place them`); }
44
+ }
45
+ const n = Object.keys(scene.entities).length;
46
+ if (n > 14) warnings.push(`${P}: ${n} entities — a step should show ≤ 12 things`);
47
+ const tags = Object.values(scene.entities).reduce((a, e) => a + (e.tags?.length || 0), 0);
48
+ if (tags > 8) warnings.push(`${P}: ${tags} tag pills — too much text on the diagram; move detail to the body`);
49
+ }
50
+ for (const [lid, L] of Object.entries(course.lessons || {})) L.steps.forEach((s, si) => checkScene(`lessons.${lid}.steps[${si}]`, s.scene));
51
+ for (const [key, ins] of Object.entries(course.insides || {})) (ins.steps || []).forEach((s, si) => checkScene(`insides.${key}.steps[${si}]`, s.scene));
52
+
53
+ if (process.argv.includes('--json')) { console.log(JSON.stringify({ errors, warnings }, null, 2)); process.exit(errors.length ? 1 : 0); }
54
+ for (const w of warnings) console.warn(`warn ${w}`);
55
+ for (const e of errors) console.error(`error ${e}`);
56
+ const lessons = Object.keys(course.lessons || {}).length, steps = Object.values(course.lessons || {}).reduce((a, l) => a + l.steps.length, 0);
57
+ console.log(errors.length ? `✗ ${errors.length} error(s), ${warnings.length} warning(s)` : `✓ valid · ${lessons} lesson(s), ${steps} steps · ${warnings.length} warning(s)`);
58
+ process.exit(errors.length ? 1 : 0);