iso-explainer 1.0.0 → 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.
- package/README.md +17 -8
- package/README.pt-BR.md +14 -13
- package/package.json +1 -1
- package/skills/iso-explainer/SKILL.md +24 -17
- package/skills/iso-explainer/assets/figure/figure.mjs +93 -0
- package/skills/iso-explainer/assets/runtime/ANATOMY-LICENSE.txt +21 -0
- package/skills/iso-explainer/assets/runtime/app.js +60 -20
- package/skills/iso-explainer/assets/runtime/engine.js +113 -66
- package/skills/iso-explainer/assets/runtime/kit.js +676 -0
- package/skills/iso-explainer/assets/runtime/looks-core.js +162 -0
- package/skills/iso-explainer/assets/runtime/looks.js +508 -0
- package/skills/iso-explainer/assets/runtime/styles.css +461 -447
- package/skills/iso-explainer/assets/templates/starter.course.json +6 -6
- package/skills/iso-explainer/examples/arquitetura-pedidos.docs.json +12 -10
- package/skills/iso-explainer/examples/catalogo-looks.course.json +599 -0
- package/skills/iso-explainer/examples/engenharia-na-pratica.course.json +11 -6
- package/skills/iso-explainer/examples/figures/token-bucket.build.mjs +111 -0
- package/skills/iso-explainer/examples/figures/token-bucket.html +959 -95
- package/skills/iso-explainer/examples/historia-pedidos.story.json +12 -10
- package/skills/iso-explainer/references/engine.md +1 -1
- package/skills/iso-explainer/references/entities.md +5 -3
- package/skills/iso-explainer/references/figure-craft.md +62 -0
- package/skills/iso-explainer/references/inside.md +20 -10
- package/skills/iso-explainer/references/layout.md +12 -0
- package/skills/iso-explainer/references/looks.md +60 -0
- package/skills/iso-explainer/references/story-mode.md +2 -2
- package/skills/iso-explainer/scripts/build.mjs +5 -3
- package/skills/iso-explainer/scripts/lib/layout.mjs +111 -0
- package/skills/iso-explainer/scripts/lib/resolve.mjs +20 -2
- package/skills/iso-explainer/scripts/snapshot.mjs +159 -97
- package/skills/iso-explainer/scripts/validate.mjs +33 -16
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// iso-explainer · looks-core.js
|
|
2
|
+
// "Looks": each block can be drawn as a small physical object whose working IS what the
|
|
3
|
+
// component does (a boom gate for a gateway, a conveyor for a queue…), in the anatomy style:
|
|
4
|
+
// many small precise solids, four-tone faces, painter's order, lines that end on something,
|
|
5
|
+
// exactly one lit part, calm motion driven by the scene (packets, cpu, failures).
|
|
6
|
+
// Geometry comes from the vendored anatomy kit (kit.js); colours are emitted as hex so the
|
|
7
|
+
// engine's dark-theme remap (themed) works unchanged.
|
|
8
|
+
import { cameraOf, depthOf, slabOf, insetPlan, planOutline, pathOf, corners, pointsAt } from './kit.js';
|
|
9
|
+
|
|
10
|
+
/* ── camera: kit projection that lands exactly on engine iso() ──
|
|
11
|
+
engine: iso(x,y,z) = [14(x+y), 7(x−y) − z] (grid units, z in px)
|
|
12
|
+
kit: azimuth 45°, elevation 30°, world y flipped, W world units per grid unit. */
|
|
13
|
+
export const W = 20;
|
|
14
|
+
const K = 14 / (Math.SQRT1_2 * W);
|
|
15
|
+
export const lookP = (origin = [0, 0]) => ({ origin, scale: K / Math.sqrt(1.6), azimuth: 45, elevation: 30 });
|
|
16
|
+
export const PX_PER_Z = cameraOf(lookP()).cosE * K; // screen px per world z unit
|
|
17
|
+
export const toWorld = (dx, dy, hpx = 0) => [dx * W, -dy * W, hpx / PX_PER_Z]; // engine grid offset → world
|
|
18
|
+
|
|
19
|
+
/* ── tones ── */
|
|
20
|
+
export const NEUTRAL = { top: '#fbf7f0', shade: ['#d6cabb', '#e1d7ca', '#ebe3d7', '#f3ede4'] };
|
|
21
|
+
export const LINE = { hi: ['#484139', 1], mid: ['#6f6559', 0.85], lo: ['#9a8f81', 0.8], faint: ['#c4b8a7', 0.65] };
|
|
22
|
+
export const toneOf = (pal) => (pal ? { top: pal.top[0], shade: [pal.side[1], pal.side[0], pal.top[1], pal.top[0]] } : NEUTRAL);
|
|
23
|
+
export const solidTone = (hex) => ({ top: hex, shade: [hex, hex, hex, hex] });
|
|
24
|
+
|
|
25
|
+
/* ── painters ── */
|
|
26
|
+
export function solid(p, tone = NEUTRAL, { line = 'hi', crease = 'faint', inner = '', flat = false } = {}) {
|
|
27
|
+
const [lc, lw] = LINE[line], [cc, cw] = LINE[crease] || []; // crease "none" draws no inner lines
|
|
28
|
+
let s = `<path d="${p.fill}" fill="${tone.shade[1]}"/>`;
|
|
29
|
+
if (!flat) {
|
|
30
|
+
p.shades.forEach((d, i) => { if (d) s += `<path d="${d}" fill="${tone.shade[i]}"/>`; });
|
|
31
|
+
s += `<path d="${p.top}" fill="${tone.top}"/>`;
|
|
32
|
+
}
|
|
33
|
+
if (cc && p.crease) s += `<path d="${p.crease}" fill="none" stroke="${cc}" stroke-width="${cw}" stroke-linecap="round"/>`;
|
|
34
|
+
if (cc && p.bevel) s += `<path d="${p.bevel}" fill="none" stroke="${cc}" stroke-width="${cw}" stroke-linecap="round"/>`;
|
|
35
|
+
return `${s}${inner}<path d="${p.outline}" fill="none" stroke="${lc}" stroke-width="${lw}" stroke-linejoin="round" stroke-linecap="round"/>`;
|
|
36
|
+
}
|
|
37
|
+
export const line = (d, tone = 'mid', w) => (d ? `<path d="${d}" fill="none" stroke="${LINE[tone][0]}" stroke-width="${w ?? LINE[tone][1]}" stroke-linecap="round" stroke-linejoin="round"/>` : '');
|
|
38
|
+
export const fillPath = (d, fill, tone = 'hi') => `<path d="${d}" fill="${fill}" stroke="${LINE[tone][0]}" stroke-width="${LINE[tone][1]}" stroke-linejoin="round"/>`;
|
|
39
|
+
export const dots = (pts, r = 0.9, fill = LINE.hi[0]) => pts.map(([x, y]) => `<circle cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" r="${r}" fill="${fill}"/>`).join('');
|
|
40
|
+
export const screw = (P, x, y, z) => { const [[sx, sy]] = pointsAt([[x, y, z]], P); return `<circle cx="${sx.toFixed(1)}" cy="${sy.toFixed(1)}" r="1.25" fill="none" stroke="${LINE.lo[0]}" stroke-width=".55"/><circle cx="${sx.toFixed(1)}" cy="${sy.toFixed(1)}" r=".55" fill="${LINE.hi[0]}"/>`; };
|
|
41
|
+
|
|
42
|
+
export const sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
43
|
+
export const add = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
|
|
44
|
+
export const mul = (a, k) => [a[0] * k, a[1] * k, a[2] * k];
|
|
45
|
+
export const cross3 = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
46
|
+
export const norm = (a) => { const l = Math.hypot(...a) || 1; return mul(a, 1 / l); };
|
|
47
|
+
export function hull(pts) {
|
|
48
|
+
const s = [...pts].sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
49
|
+
const c = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
|
|
50
|
+
const lo = [], up = [];
|
|
51
|
+
for (const p of s) { while (lo.length >= 2 && c(lo[lo.length - 2], lo[lo.length - 1], p) <= 0) lo.pop(); lo.push(p); }
|
|
52
|
+
for (let i = s.length - 1; i >= 0; i--) { const p = s[i]; while (up.length >= 2 && c(up[up.length - 2], up[up.length - 1], p) <= 0) up.pop(); up.push(p); }
|
|
53
|
+
return [...lo.slice(0, -1), ...up.slice(0, -1)];
|
|
54
|
+
}
|
|
55
|
+
// A box along any direction: from a to b, `wide` across `side`, `thick` across the other normal.
|
|
56
|
+
// Used for parts that tilt or rotate (boom arms, levers, press rams).
|
|
57
|
+
export function beam(a, b, side, wide, thick, P, tone = NEUTRAL, { line: ln = 'hi' } = {}) {
|
|
58
|
+
const d = norm(sub(b, a)), u = norm(side), n = norm(cross3(d, u));
|
|
59
|
+
const C = [];
|
|
60
|
+
for (const p of [a, b]) for (const su of [-1, 1]) for (const sn of [-1, 1]) C.push(add(add(p, mul(u, su * wide / 2)), mul(n, sn * thick / 2)));
|
|
61
|
+
const idx = (pa, su, sn) => pa * 4 + (su > 0 ? 2 : 0) + (sn > 0 ? 1 : 0);
|
|
62
|
+
const faces = [
|
|
63
|
+
{ n: mul(d, -1), q: [idx(0, -1, -1), idx(0, 1, -1), idx(0, 1, 1), idx(0, -1, 1)] },
|
|
64
|
+
{ n: d, q: [idx(1, -1, -1), idx(1, -1, 1), idx(1, 1, 1), idx(1, 1, -1)] },
|
|
65
|
+
{ n: u, q: [idx(0, 1, -1), idx(1, 1, -1), idx(1, 1, 1), idx(0, 1, 1)] },
|
|
66
|
+
{ n: mul(u, -1), q: [idx(0, -1, -1), idx(0, -1, 1), idx(1, -1, 1), idx(1, -1, -1)] },
|
|
67
|
+
{ n, q: [idx(0, -1, 1), idx(0, 1, 1), idx(1, 1, 1), idx(1, -1, 1)] },
|
|
68
|
+
{ n: mul(n, -1), q: [idx(0, -1, -1), idx(1, -1, -1), idx(1, 1, -1), idx(0, 1, -1)] },
|
|
69
|
+
];
|
|
70
|
+
const S = pointsAt(C, P), { sinA, cosA } = cameraOf(P);
|
|
71
|
+
let out = '';
|
|
72
|
+
for (const f of faces) {
|
|
73
|
+
if (depthOf(f.n, P) <= 1e-6) continue;
|
|
74
|
+
const up = f.n[2] > 0.7, lit = (f.n[0] * -sinA + -f.n[1] * cosA + 1) / 2; // y is flipped in the plan light
|
|
75
|
+
const fill = up ? tone.top : tone.shade[Math.min(3, Math.max(0, Math.floor(lit * 4)))];
|
|
76
|
+
out += `<path d="${pathOf(f.q.map((i) => S[i]), true)}" fill="${fill}" stroke="${LINE.faint[0]}" stroke-width=".5" stroke-linejoin="round"/>`;
|
|
77
|
+
}
|
|
78
|
+
return out + `<path d="${pathOf(hull(S), true)}" fill="none" stroke="${LINE[ln][0]}" stroke-width="${LINE[ln][1]}" stroke-linejoin="round"/>`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* ── shared parts ── */
|
|
82
|
+
// The plinth: the entity's colour, a groove, corner screws. Every look stands on one.
|
|
83
|
+
export function plinth(P, hx, hy, z, tone) {
|
|
84
|
+
const plan = { x: -hx, y: -hy, w: hx * 2, d: hy * 2, r: Math.min(9, hx * 0.22) };
|
|
85
|
+
const s = slabOf(plan, 0, z, P, 8, 1.2);
|
|
86
|
+
let out = solid(s, tone, { crease: 'lo' }) + line(planOutline(insetPlan(plan, 4.5), z, P), 'lo', 0.7);
|
|
87
|
+
for (const [x, y] of corners(plan, 7.5)) out += screw(P, x, y, z);
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
export const env = (hx, hy, top) => ({ hx, hy, top }); // envelope: half sizes + top z (world units)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
// The usual start of a look: half sizes, a scale u (the catalogue is drawn for a ±40 footprint),
|
|
94
|
+
// the plinth top z0, point/plan helpers, and the plinth itself.
|
|
95
|
+
export function rig(e, P, pal, plinthZ = 6) {
|
|
96
|
+
const d = e.d ?? e.s ?? (e.r ?? 2) * 2, w = e.w ?? e.s ?? (e.r ?? 2) * 2;
|
|
97
|
+
const hx = (d * W) / 2, hy = (w * W) / 2, u = Math.min(hx, hy) / 40, z0 = plinthZ * u;
|
|
98
|
+
return {
|
|
99
|
+
hx, hy, u, z0,
|
|
100
|
+
at: (x, y, z) => [x * u, y * u, z0 + z * u],
|
|
101
|
+
pl: (x, y, w2, d2, r = 1) => ({ x: x * u, y: y * u, w: w2 * u, d: d2 * u, r: r * u }),
|
|
102
|
+
base: plinth(P, hx, hy, z0, toneOf(pal)),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// Polygons drawn in a vertical plane: y = const (the front-left face) or x = const (the front-right face).
|
|
106
|
+
// pts are [a, z] pairs: a runs along x (for planeY) or y (for planeX).
|
|
107
|
+
export const planeY = (y, pts, P, closed = true) => pathOf(pointsAt(pts.map(([x, z]) => [x, y, z]), P), closed);
|
|
108
|
+
export const planeX = (x, pts, P, closed = true) => pathOf(pointsAt(pts.map(([y, z]) => [x, y, z]), P), closed);
|
|
109
|
+
// A spur gear outline (2D, around [ca, cz]) with `teeth`, turned by `rot` radians.
|
|
110
|
+
export function gear(ca, cz, r, teeth, rot = 0) {
|
|
111
|
+
const pts = [], n = teeth * 4;
|
|
112
|
+
for (let i = 0; i < n; i++) {
|
|
113
|
+
const a = rot + (i / n) * Math.PI * 2, rr = (i % 4 < 2 ? r : r * 0.8);
|
|
114
|
+
pts.push([ca + Math.cos(a) * rr, cz + Math.sin(a) * rr]);
|
|
115
|
+
}
|
|
116
|
+
return pts;
|
|
117
|
+
}
|
|
118
|
+
export const circle2 = (ca, cz, r, steps = 24) => Array.from({ length: steps }, (_, i) => [ca + Math.cos((i / steps) * Math.PI * 2) * r, cz + Math.sin((i / steps) * Math.PI * 2) * r]);
|
|
119
|
+
|
|
120
|
+
// A stroke in any colour (screens, hands), and a glass body (outline + faint fill).
|
|
121
|
+
// Colour rule (same as the stage): lowercase hex follows the theme; UPPERCASE hex never changes, so
|
|
122
|
+
// intrinsically dark materials (rubber, chip packages, openings, screens) stay dark in the dark theme.
|
|
123
|
+
export const stroke = (d, color, w = 1) => (d ? `<path d="${d}" fill="none" stroke="${color}" stroke-width="${w}" stroke-linecap="round" stroke-linejoin="round"/>` : '');
|
|
124
|
+
export const glass = (p) => `<path d="${p.fill}" fill="#ffffff" opacity=".28"/>` + line(p.crease, 'faint') + line(p.outline, 'hi');
|
|
125
|
+
|
|
126
|
+
/* Dark theme: every lowercase hex in generated SVG is remapped in HSL.
|
|
127
|
+
- near-neutral warm colours invert lightness (paper → charcoal, ink → cream)
|
|
128
|
+
- light pastels become deep, low-saturation tones
|
|
129
|
+
- mid tones stay, dark tones become light.
|
|
130
|
+
UPPERCASE hex is never remapped (use it for colours that must stay fixed). */
|
|
131
|
+
const hexToHsl = (hex) => {
|
|
132
|
+
const n = parseInt(hex.length === 4 ? hex.slice(1).replace(/./g, '$&$&') : hex.slice(1), 16);
|
|
133
|
+
const r = ((n >> 16) & 255) / 255, g = ((n >> 8) & 255) / 255, b = (n & 255) / 255;
|
|
134
|
+
const max = Math.max(r, g, b), min = Math.min(r, g, b), c = max - min, l = (max + min) / 2;
|
|
135
|
+
let h = 0;
|
|
136
|
+
if (c) {
|
|
137
|
+
h = max === r ? ((g - b) / c) % 6 : max === g ? (b - r) / c + 2 : (r - g) / c + 4;
|
|
138
|
+
h *= 60; if (h < 0) h += 360;
|
|
139
|
+
}
|
|
140
|
+
const s = c ? c / (1 - Math.abs(2 * l - 1)) : 0;
|
|
141
|
+
return { h, s, l, c };
|
|
142
|
+
};
|
|
143
|
+
const hslToHex = (h, s, l) => {
|
|
144
|
+
const c = (1 - Math.abs(2 * l - 1)) * s, x = c * (1 - Math.abs(((h / 60) % 2) - 1)), m = l - c / 2;
|
|
145
|
+
const [r, g, b] = h < 60 ? [c, x, 0] : h < 120 ? [x, c, 0] : h < 180 ? [0, c, x] : h < 240 ? [0, x, c] : h < 300 ? [x, 0, c] : [c, 0, x];
|
|
146
|
+
const t = (v) => Math.round(Math.max(0, Math.min(1, v + m)) * 255).toString(16).padStart(2, '0');
|
|
147
|
+
return `#${t(r)}${t(g)}${t(b)}`;
|
|
148
|
+
};
|
|
149
|
+
const darkCache = new Map();
|
|
150
|
+
export function darkHex(hex) {
|
|
151
|
+
if (darkCache.has(hex)) return darkCache.get(hex);
|
|
152
|
+
const { h, s, l, c } = hexToHsl(hex);
|
|
153
|
+
let out;
|
|
154
|
+
if (c < 0.05 || (c < 0.14 && h >= 10 && h <= 64)) {
|
|
155
|
+
const L = l >= 0.88 ? 0.11 + (l - 0.9) * 0.9 : 1 - l;
|
|
156
|
+
out = hslToHex(c < 0.02 ? 34 : h, 0.12, Math.max(0.06, Math.min(0.93, L)));
|
|
157
|
+
} else if (l >= 0.66) out = hslToHex(h, Math.min(s, 0.5) * 0.62, 0.17 + (l - 0.66) * 0.55);
|
|
158
|
+
else if (l >= 0.36) out = hex;
|
|
159
|
+
else out = hslToHex(h, Math.min(s, 0.6), 0.8);
|
|
160
|
+
darkCache.set(hex, out);
|
|
161
|
+
return out;
|
|
162
|
+
}
|