@supersuit/components 0.0.0-stage → 0.2.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/CHANGELOG.md +46 -0
- package/LICENSE +21 -0
- package/README.md +250 -2
- package/bin/supersuit-theme.mjs +116 -0
- package/dist/check/depth/bar.d.ts +27 -0
- package/dist/check/depth/bar.js +40 -0
- package/dist/check/depth/check.d.ts +40 -0
- package/dist/check/depth/check.js +50 -0
- package/dist/check/depth/crop.d.ts +24 -0
- package/dist/check/depth/crop.js +126 -0
- package/dist/check/depth/index.d.ts +3 -0
- package/dist/check/depth/index.js +5 -0
- package/dist/check/depth/measure.d.ts +42 -0
- package/dist/check/depth/measure.js +141 -0
- package/dist/check/depth/parts-page.d.ts +6 -0
- package/dist/check/depth/parts-page.js +69 -0
- package/dist/check/depth/playwright.d.ts +4 -0
- package/dist/check/depth/playwright.js +10 -0
- package/dist/check/depth/png.d.ts +3 -0
- package/dist/check/depth/png.js +12 -0
- package/dist/check/depth/shoot.d.ts +37 -0
- package/dist/check/depth/shoot.js +30 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +11 -0
- package/dist/sound/engine.d.ts +59 -0
- package/dist/sound/engine.js +325 -0
- package/dist/sound/index.d.ts +18 -0
- package/dist/sound/index.js +10 -0
- package/dist/sound/synth.d.ts +24 -0
- package/dist/sound/synth.js +139 -0
- package/dist/theme/color.d.ts +29 -0
- package/dist/theme/color.js +116 -0
- package/dist/theme/compile.d.ts +23 -0
- package/dist/theme/compile.js +138 -0
- package/dist/theme/index.d.ts +3 -0
- package/dist/theme/index.js +4 -0
- package/dist/theme/record.d.ts +90 -0
- package/dist/theme/record.js +222 -0
- package/dist/voice-field/box-trace.d.ts +18 -0
- package/dist/voice-field/box-trace.js +87 -0
- package/dist/voice-field/index.d.ts +8 -0
- package/dist/voice-field/index.js +10 -0
- package/dist/voice-field/recorder.d.ts +71 -0
- package/dist/voice-field/recorder.js +211 -0
- package/dist/voice-field/rules.d.ts +27 -0
- package/dist/voice-field/rules.js +62 -0
- package/dist/voice-field/saved-take.d.ts +7 -0
- package/dist/voice-field/saved-take.js +66 -0
- package/dist/voice-field/store.d.ts +27 -0
- package/dist/voice-field/store.js +40 -0
- package/dist/voice-field/styles.css +161 -0
- package/dist/voice-field/toast.d.ts +13 -0
- package/dist/voice-field/toast.js +26 -0
- package/dist/voice-field/voice-field.d.ts +80 -0
- package/dist/voice-field/voice-field.js +259 -0
- package/dist/voice-field/words.d.ts +37 -0
- package/dist/voice-field/words.js +33 -0
- package/package.json +106 -4
- package/specs/brand-theme/v1/SPEC.md +130 -0
- package/specs/brand-theme/v1/default-bar.json +1196 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// The before and after crop check. For a theme it draws the button row and a card twice, flat (round 1:
|
|
2
|
+
// the record with every depth setting at zero) on the left and as compiled on the right, at the page's
|
|
3
|
+
// device scale (3 on the depth device), writes `depth-compare-<theme>.png`, and measures how much the two
|
|
4
|
+
// differ: the mean OKLab distance (x100) between the halves, in the 12 px band around each part.
|
|
5
|
+
// This is the picture Gary approved on 2026-12-01, made by code instead of by hand (the vibe check's
|
|
6
|
+
// tools/compare.py read round 1's bounds by hand).
|
|
7
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import { toOklab } from "../../theme/color.js";
|
|
10
|
+
import { compileTheme } from "../../theme/compile.js";
|
|
11
|
+
import { utilityRules } from "../../theme/compile.js";
|
|
12
|
+
import { decodePng, encodePng } from "./png.js";
|
|
13
|
+
import { readRects } from "./shoot.js";
|
|
14
|
+
export const CROP_BAND = 12;
|
|
15
|
+
const GUTTER = 16;
|
|
16
|
+
/** One half: a label, the button row and an Awaiting you card, drawn with the theme's depth classes. */
|
|
17
|
+
export function comparePage(themeCss, o) {
|
|
18
|
+
return `<!doctype html>
|
|
19
|
+
<html class="theme-${o.theme}" data-theme="${o.theme}" lang="en">
|
|
20
|
+
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
21
|
+
<style>
|
|
22
|
+
${themeCss}
|
|
23
|
+
${utilityRules('.')}
|
|
24
|
+
html, body { margin: 0; background: var(--background); color: var(--foreground); }
|
|
25
|
+
body { padding: 20px 24px 48px; font: 400 16px/1.35 var(--font-text); -webkit-font-smoothing: antialiased; }
|
|
26
|
+
.label { font: 600 13px/1 system-ui, sans-serif; letter-spacing: 0.02em; color: var(--muted-foreground); margin-bottom: 20px; }
|
|
27
|
+
.row { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 40px; }
|
|
28
|
+
.btn { height: 44px; padding: 0 20px; border: 0; border-radius: var(--radius); font: 500 16px/1 var(--font-text); display: inline-flex; align-items: center; justify-content: center; }
|
|
29
|
+
.p-primary { background-color: var(--primary); color: var(--primary-foreground); }
|
|
30
|
+
.p-secondary { background-color: var(--secondary); color: var(--secondary-foreground); }
|
|
31
|
+
.p-outline { background-color: var(--raised); color: var(--foreground); }
|
|
32
|
+
.card { border-radius: var(--radius); background-color: var(--card); color: var(--card-foreground); overflow: hidden; }
|
|
33
|
+
.card .body { padding: 16px 18px 18px; }
|
|
34
|
+
.chip { display: inline-block; padding: 4px 10px; border-radius: 999px; background: var(--secondary); color: var(--secondary-foreground); font-size: 13px; }
|
|
35
|
+
.when { margin-left: 8px; font-size: 13px; color: var(--muted-foreground); }
|
|
36
|
+
.title { margin: 10px 0 6px; font-family: var(--font-display); font-weight: var(--display-weight); letter-spacing: var(--display-tracking); font-size: 24px; line-height: 1.15; }
|
|
37
|
+
.text { margin: 0; color: var(--muted-foreground); font-size: 15px; }
|
|
38
|
+
.foot { display: flex; gap: 12px; padding: 16px 18px; border-top: 1px solid var(--border); }
|
|
39
|
+
.foot .btn { flex: 1; }
|
|
40
|
+
</style></head>
|
|
41
|
+
<body>
|
|
42
|
+
<div class="label">${o.label}</div>
|
|
43
|
+
<div class="row">
|
|
44
|
+
<button data-crop="primary" class="btn p-primary sheen-primary elev-primary">Main action</button>
|
|
45
|
+
<button data-crop="secondary" class="btn p-secondary sheen-tint elev-btn">Second</button>
|
|
46
|
+
<button data-crop="outline" class="btn p-outline sheen-quiet elev-btn">Outline</button>
|
|
47
|
+
</div>
|
|
48
|
+
<div data-crop="card" class="card elev-1 sheen-surface">
|
|
49
|
+
<div class="body">
|
|
50
|
+
<span class="chip">Awaiting you</span><span class="when">2 hours</span>
|
|
51
|
+
<p class="title">Send the pilot recap to the Harbor team</p>
|
|
52
|
+
<p class="text">Pluma drafted it from Tuesday's call. Four lines, the price, and the start date.</p>
|
|
53
|
+
</div>
|
|
54
|
+
<div class="foot">
|
|
55
|
+
<button class="btn p-primary sheen-primary elev-primary">Pluma sends it</button>
|
|
56
|
+
<button class="btn p-outline sheen-quiet elev-btn">Gary edits it</button>
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
</body></html>
|
|
60
|
+
`;
|
|
61
|
+
}
|
|
62
|
+
async function shootHalf(page, css, theme, label) {
|
|
63
|
+
await page.setContent(comparePage(css, { theme, label }), { waitUntil: 'load' });
|
|
64
|
+
await page.evaluate(() => document.fonts.ready.then(() => undefined));
|
|
65
|
+
const rects = await page.evaluate(() => {
|
|
66
|
+
const out = {};
|
|
67
|
+
document.querySelectorAll('[data-crop]').forEach((el) => {
|
|
68
|
+
const r = el.getBoundingClientRect();
|
|
69
|
+
out[el.getAttribute('data-crop')] = { x: r.x + window.scrollX, y: r.y + window.scrollY, width: r.width, height: r.height };
|
|
70
|
+
});
|
|
71
|
+
return out;
|
|
72
|
+
});
|
|
73
|
+
const { scale } = await readRects(page);
|
|
74
|
+
const img = decodePng(await page.screenshot({ fullPage: true, type: 'png', animations: 'disabled' }));
|
|
75
|
+
return { img, rects, scale };
|
|
76
|
+
}
|
|
77
|
+
/** Mean OKLab distance (x100) between two pictures over the 12 px band around each rect (CSS px). */
|
|
78
|
+
export function bandDiff(a, b, rects, scale, band = CROP_BAND) {
|
|
79
|
+
let sum = 0, n = 0;
|
|
80
|
+
for (const r of rects) {
|
|
81
|
+
const x0 = Math.max(0, Math.floor((r.x - band) * scale)), x1 = Math.min(a.width, b.width, Math.ceil((r.x + r.width + band) * scale));
|
|
82
|
+
const y0 = Math.max(0, Math.floor((r.y - band) * scale)), y1 = Math.min(a.height, b.height, Math.ceil((r.y + r.height + band) * scale));
|
|
83
|
+
const ix0 = (r.x + band) * scale, ix1 = (r.x + r.width - band) * scale, iy0 = (r.y + band) * scale, iy1 = (r.y + r.height - band) * scale;
|
|
84
|
+
for (let y = y0; y < y1; y++)
|
|
85
|
+
for (let x = x0; x < x1; x++) {
|
|
86
|
+
if (x >= ix0 && x < ix1 && y >= iy0 && y < iy1)
|
|
87
|
+
continue; // inside the face, away from its edge
|
|
88
|
+
const i = (y * a.width + x) * 4, j = (y * b.width + x) * 4;
|
|
89
|
+
const p = toOklab({ r: a.data[i], g: a.data[i + 1], b: a.data[i + 2] });
|
|
90
|
+
const q = toOklab({ r: b.data[j], g: b.data[j + 1], b: b.data[j + 2] });
|
|
91
|
+
sum += Math.hypot(p[0] - q[0], p[1] - q[1], p[2] - q[2]);
|
|
92
|
+
n++;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return n ? Math.round((sum / n) * 100 * 100) / 100 : 0;
|
|
96
|
+
}
|
|
97
|
+
/** Two pictures side by side with a white gutter. */
|
|
98
|
+
export function sideBySide(a, b, gutter) {
|
|
99
|
+
const width = a.width + gutter + b.width, height = Math.max(a.height, b.height);
|
|
100
|
+
const data = new Uint8ClampedArray(width * height * 4).fill(255);
|
|
101
|
+
for (const [img, ox] of [[a, 0], [b, a.width + gutter]])
|
|
102
|
+
for (let y = 0; y < img.height; y++)
|
|
103
|
+
data.set(img.data.subarray(y * img.width * 4, (y + 1) * img.width * 4), (y * width + ox) * 4);
|
|
104
|
+
return { width, height, data };
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Draw `record` flat beside itself compiled, write `<outDir>/depth-compare-<id>.png`, and return the
|
|
108
|
+
* difference. `right: 'flat'` draws flat on both sides (the check's own failing fixture) and writes
|
|
109
|
+
* `depth-compare-<id>-flat-flat.png`.
|
|
110
|
+
*/
|
|
111
|
+
export async function depthCompare(page, record, outDir, o = {}) {
|
|
112
|
+
const right = o.right ?? 'compiled';
|
|
113
|
+
const left = await shootHalf(page, compileTheme(record, { flat: true }).css, record.id, 'Round 1 (flat)');
|
|
114
|
+
const rightHalf = await shootHalf(page, compileTheme(record, { flat: right === 'flat' }).css, record.id, right === 'flat' ? 'Round 1 (flat)' : 'As compiled (depth)');
|
|
115
|
+
const diff = bandDiff(left.img, rightHalf.img, Object.values(left.rects), left.scale);
|
|
116
|
+
mkdirSync(outDir, { recursive: true });
|
|
117
|
+
const file = join(outDir, `depth-compare-${record.id}${right === 'flat' ? '-flat-flat' : ''}.png`);
|
|
118
|
+
// The picture ends 48 px under the lowest part (the page is at least a phone screen tall).
|
|
119
|
+
const bottom = Math.max(...Object.values(left.rects).map((r) => r.y + r.height)) + 48;
|
|
120
|
+
const cut = (img) => {
|
|
121
|
+
const height = Math.min(img.height, Math.ceil(bottom * left.scale));
|
|
122
|
+
return { width: img.width, height, data: img.data.subarray(0, img.width * height * 4) };
|
|
123
|
+
};
|
|
124
|
+
writeFileSync(file, encodePng(sideBySide(cut(left.img), cut(rightHalf.img), GUTTER * left.scale)));
|
|
125
|
+
return { file, diff };
|
|
126
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// @supersuit/components/check/depth: the measured depth check. PNG decoding (png.ts) and the Playwright
|
|
2
|
+
// helpers are not exported here, so this subpath needs no decoder and no browser.
|
|
3
|
+
export * from "./measure.js";
|
|
4
|
+
export * from "./check.js";
|
|
5
|
+
export * from "./parts-page.js";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type Img = {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
data: Uint8Array | Uint8ClampedArray;
|
|
5
|
+
};
|
|
6
|
+
export type Rect = {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
};
|
|
12
|
+
export type MeasureName = 'ledge' | 'drop' | 'top' | 'raise' | 'well' | 'pressMove' | 'pressLedge';
|
|
13
|
+
export type PartMeasures = Partial<Record<MeasureName, number>> & {
|
|
14
|
+
skipped?: Partial<Record<MeasureName, string>>;
|
|
15
|
+
};
|
|
16
|
+
export type Measures = Record<string, PartMeasures>;
|
|
17
|
+
export type PartKind = 'button' | 'quiet' | 'surface' | 'field';
|
|
18
|
+
/**
|
|
19
|
+
* Which measures a part takes. A name not listed is a filled button. A filled or tinted face (primary,
|
|
20
|
+
* a hand-drawn bg-primary button, destructive's red tint) is lit by its own colour, so `raise` is not
|
|
21
|
+
* asked of it; quiet buttons and surfaces are neutral faces raised off the page.
|
|
22
|
+
*/
|
|
23
|
+
export declare const PART_KINDS: Record<string, PartKind>;
|
|
24
|
+
export declare const kindOf: (part: string, kinds?: Record<string, PartKind>) => PartKind;
|
|
25
|
+
/** Which measures each kind takes (`raise` is judged on dark grounds only). */
|
|
26
|
+
export declare const KIND_MEASURES: Record<PartKind, MeasureName[]>;
|
|
27
|
+
/** In CSS px. Rows below the face's bottom edge, or inside the field's top edge. */
|
|
28
|
+
export declare const GEOMETRY: {
|
|
29
|
+
readonly ledgeRow: readonly [1, 2];
|
|
30
|
+
readonly ledgeGround: 12;
|
|
31
|
+
readonly dropBand: readonly [3, 10];
|
|
32
|
+
readonly dropGround: 24;
|
|
33
|
+
readonly wellRows: readonly [1, 4];
|
|
34
|
+
readonly faceSides: readonly [readonly [0.06, 0.14], readonly [0.86, 0.94]];
|
|
35
|
+
readonly lightLimit: 99.5;
|
|
36
|
+
};
|
|
37
|
+
/** The median OKLab L (0-100) of the pixels in a CSS px box. NaN when the box is off the picture. */
|
|
38
|
+
export declare function bandL(img: Img, x0: number, x1: number, y0: number, y1: number, scale: number): number;
|
|
39
|
+
/** Measure every part in `rects` (CSS px) on `img` (device px at `scale`). */
|
|
40
|
+
export declare function measureParts(img: Img, rects: Record<string, Rect | Rect[]>, scale: number, o?: {
|
|
41
|
+
kinds?: Record<string, PartKind>;
|
|
42
|
+
}): Measures;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// The depth measures, read from a screenshot's pixels, because the eye sees pixels, not CSS.
|
|
2
|
+
// Imports nothing but the colour arithmetic, so an app can vendor src/check/depth with src/theme/color.ts.
|
|
3
|
+
//
|
|
4
|
+
// Conventions:
|
|
5
|
+
// - `img` is RGBA, device pixels (a 3x screenshot of a 390 px page is 1170 px wide).
|
|
6
|
+
// - A Rect is in CSS px, as getBoundingClientRect gives it (so it includes a transform), and `scale` is the
|
|
7
|
+
// device scale. A part is keyed by its name (`primary`, `card`, ...); its pressed twin is keyed
|
|
8
|
+
// `<name>@pressed`. On a parts page that is `[data-part="<name>"]` and `[data-part="<name>"][data-pressed]`.
|
|
9
|
+
// - The pressed twin must share its resting part's layout top (side by side, aligned to the top), so the
|
|
10
|
+
// difference of the two rects' tops is the press move.
|
|
11
|
+
// - A part drawn several times takes Rect[]; each measure keeps its worst value.
|
|
12
|
+
// - An optional `ground` rect is a patch of bare page. When it is given, drop and raise read the page there;
|
|
13
|
+
// without it they read the ground 24 px below the part.
|
|
14
|
+
//
|
|
15
|
+
// What the first calibration (2026-11-30) taught, each a fix to the measure, never to a threshold:
|
|
16
|
+
// - The face is read in its side padding (6-14% and 86-94% of the width, middle row), never the middle
|
|
17
|
+
// third, where the label or icon sits: "Delete" in Chromium's font covered the middle third's middle row
|
|
18
|
+
// and read as a dark face.
|
|
19
|
+
// - The ledge is the second pixel row under the face (1 to 2 px), so the 1px hairline ring every flat or
|
|
20
|
+
// pressed part has is not read as a ledge; and it counts either way (absolute), because on a dark ground
|
|
21
|
+
// a bronze button's ledge is lighter than the page and still plainly visible.
|
|
22
|
+
// - A face already at the light limit (L 99.5 or more, white on white) cannot show a top light: `top` is
|
|
23
|
+
// skipped for it, and the skip is named.
|
|
24
|
+
// - Drop reads the bare page, not the ground 24 px away, when the page gives a ground patch: a menu's
|
|
25
|
+
// level 3 shadow still darkens the page 24 px below it, which made the menu read shallower than a card.
|
|
26
|
+
import { toOklab } from "../../theme/color.js";
|
|
27
|
+
/**
|
|
28
|
+
* Which measures a part takes. A name not listed is a filled button. A filled or tinted face (primary,
|
|
29
|
+
* a hand-drawn bg-primary button, destructive's red tint) is lit by its own colour, so `raise` is not
|
|
30
|
+
* asked of it; quiet buttons and surfaces are neutral faces raised off the page.
|
|
31
|
+
*/
|
|
32
|
+
export const PART_KINDS = {
|
|
33
|
+
primary: 'button', 'hand-drawn': 'button', destructive: 'button',
|
|
34
|
+
secondary: 'quiet', outline: 'quiet', mic: 'quiet',
|
|
35
|
+
card: 'surface', menu: 'surface',
|
|
36
|
+
field: 'field',
|
|
37
|
+
};
|
|
38
|
+
export const kindOf = (part, kinds = PART_KINDS) => kinds[part] ?? 'button';
|
|
39
|
+
/** Which measures each kind takes (`raise` is judged on dark grounds only). */
|
|
40
|
+
export const KIND_MEASURES = {
|
|
41
|
+
button: ['ledge', 'drop', 'top', 'pressMove', 'pressLedge'],
|
|
42
|
+
quiet: ['ledge', 'drop', 'top', 'raise', 'pressMove', 'pressLedge'],
|
|
43
|
+
surface: ['drop', 'top', 'raise'],
|
|
44
|
+
field: ['well'],
|
|
45
|
+
};
|
|
46
|
+
/** In CSS px. Rows below the face's bottom edge, or inside the field's top edge. */
|
|
47
|
+
export const GEOMETRY = { ledgeRow: [1, 2], ledgeGround: 12, dropBand: [3, 10], dropGround: 24, wellRows: [1, 4], faceSides: [[0.06, 0.14], [0.86, 0.94]], lightLimit: 99.5 };
|
|
48
|
+
function median(xs) {
|
|
49
|
+
if (!xs.length)
|
|
50
|
+
return NaN;
|
|
51
|
+
const s = [...xs].sort((a, b) => a - b);
|
|
52
|
+
const m = s.length >> 1;
|
|
53
|
+
return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2;
|
|
54
|
+
}
|
|
55
|
+
function lightness(img, x0, x1, y0, y1, scale, into) {
|
|
56
|
+
const ys = Math.max(0, Math.floor(y0 * scale)), ye = Math.min(img.height, Math.ceil(y1 * scale));
|
|
57
|
+
const xs = Math.max(0, Math.floor(x0 * scale)), xe = Math.min(img.width, Math.ceil(x1 * scale));
|
|
58
|
+
for (let y = ys; y < ye; y++)
|
|
59
|
+
for (let x = xs; x < xe; x++) {
|
|
60
|
+
const i = (y * img.width + x) * 4;
|
|
61
|
+
into.push(toOklab({ r: img.data[i], g: img.data[i + 1], b: img.data[i + 2] })[0] * 100);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** The median OKLab L (0-100) of the pixels in a CSS px box. NaN when the box is off the picture. */
|
|
65
|
+
export function bandL(img, x0, x1, y0, y1, scale) {
|
|
66
|
+
const ls = [];
|
|
67
|
+
lightness(img, x0, x1, y0, y1, scale, ls);
|
|
68
|
+
return median(ls);
|
|
69
|
+
}
|
|
70
|
+
const r2 = (v) => Math.round(v * 100) / 100;
|
|
71
|
+
const num = (v) => (Number.isFinite(v) ? r2(v) : undefined);
|
|
72
|
+
function measureOne(img, r, s, kind, pageL) {
|
|
73
|
+
const x0 = r.x + r.width / 3, x1 = r.x + (2 * r.width) / 3;
|
|
74
|
+
const row = (y0, y1) => bandL(img, x0, x1, y0, y1, s);
|
|
75
|
+
const B = r.y + r.height;
|
|
76
|
+
const mid = r.y + r.height / 2;
|
|
77
|
+
const side = [];
|
|
78
|
+
for (const [a, b] of GEOMETRY.faceSides)
|
|
79
|
+
lightness(img, r.x + a * r.width, r.x + b * r.width, mid - 0.5, mid + 0.5, s, side);
|
|
80
|
+
const face = median(side);
|
|
81
|
+
const ground = pageL ?? row(B + GEOMETRY.dropGround, B + GEOMETRY.dropGround + 1);
|
|
82
|
+
const m = {};
|
|
83
|
+
const want = KIND_MEASURES[kind];
|
|
84
|
+
if (want.includes('ledge'))
|
|
85
|
+
m.ledge = num(Math.abs(row(B + GEOMETRY.ledgeGround, B + GEOMETRY.ledgeGround + 1) - row(B + GEOMETRY.ledgeRow[0], B + GEOMETRY.ledgeRow[1])));
|
|
86
|
+
if (want.includes('drop'))
|
|
87
|
+
m.drop = num(ground - row(B + GEOMETRY.dropBand[0], B + GEOMETRY.dropBand[1]));
|
|
88
|
+
if (want.includes('top')) {
|
|
89
|
+
if (face >= GEOMETRY.lightLimit)
|
|
90
|
+
m.skipped = { ...m.skipped, top: `the face is at L ${r2(face)}, white: no room for a top light` };
|
|
91
|
+
else
|
|
92
|
+
m.top = num(row(r.y, r.y + 1) - face);
|
|
93
|
+
}
|
|
94
|
+
if (want.includes('raise'))
|
|
95
|
+
m.raise = num(face - ground);
|
|
96
|
+
if (want.includes('well'))
|
|
97
|
+
m.well = num(face - row(r.y + GEOMETRY.wellRows[0], r.y + GEOMETRY.wellRows[1]));
|
|
98
|
+
return m;
|
|
99
|
+
}
|
|
100
|
+
const HIGHER_IS_WORSE = ['pressLedge'];
|
|
101
|
+
function worst(a, b) {
|
|
102
|
+
const out = { ...a };
|
|
103
|
+
for (const [k, v] of Object.entries(b)) {
|
|
104
|
+
if (k === 'skipped') {
|
|
105
|
+
out.skipped = { ...out.skipped, ...v };
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (typeof v !== 'number')
|
|
109
|
+
continue;
|
|
110
|
+
const have = out[k];
|
|
111
|
+
out[k] = have === undefined ? v : HIGHER_IS_WORSE.includes(k) ? Math.max(have, v) : Math.min(have, v);
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
/** Measure every part in `rects` (CSS px) on `img` (device px at `scale`). */
|
|
116
|
+
export function measureParts(img, rects, scale, o = {}) {
|
|
117
|
+
const list = (v) => (v === undefined ? [] : Array.isArray(v) ? v : [v]);
|
|
118
|
+
const g = list(rects.ground)[0];
|
|
119
|
+
const pageL = g ? num(bandL(img, g.x, g.x + g.width, g.y, g.y + g.height, scale)) : undefined;
|
|
120
|
+
const out = {};
|
|
121
|
+
for (const [name, value] of Object.entries(rects)) {
|
|
122
|
+
if (name === 'ground' || name.endsWith('@pressed'))
|
|
123
|
+
continue;
|
|
124
|
+
const kind = kindOf(name, o.kinds);
|
|
125
|
+
const rest = list(value);
|
|
126
|
+
const pressed = list(rects[`${name}@pressed`]);
|
|
127
|
+
let m;
|
|
128
|
+
rest.forEach((r, i) => {
|
|
129
|
+
const one = measureOne(img, r, scale, kind, pageL);
|
|
130
|
+
const p = pressed[i];
|
|
131
|
+
if (p && KIND_MEASURES[kind].includes('pressMove')) {
|
|
132
|
+
one.pressMove = r2(p.y - r.y);
|
|
133
|
+
one.pressLedge = measureOne(img, p, scale, 'button', pageL).ledge;
|
|
134
|
+
}
|
|
135
|
+
m = m ? worst(m, one) : one;
|
|
136
|
+
});
|
|
137
|
+
if (m)
|
|
138
|
+
out[name] = m;
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const PAGE_PARTS: readonly ["primary", "secondary", "outline", "destructive", "mic", "field", "card", "menu"];
|
|
2
|
+
export declare function partsPage(themeCss: string, o: {
|
|
3
|
+
theme: string;
|
|
4
|
+
ground: 'light' | 'dark';
|
|
5
|
+
parts?: readonly string[];
|
|
6
|
+
}): string;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// partsPage: one self-contained page that draws each raised part on its theme's ground, so a theme's
|
|
2
|
+
// depth can be measured with no Tailwind build. It inlines the compiled theme CSS and the depth utilities
|
|
3
|
+
// as plain classes (the same variables the @utility rules apply), and draws each part with the classes the
|
|
4
|
+
// vibe check's round 3 gave it (own-the-components-depth*.py):
|
|
5
|
+
// primary bg-primary sheen-primary elev-primary
|
|
6
|
+
// secondary bg-secondary sheen-tint elev-btn
|
|
7
|
+
// outline bg-raised sheen-quiet elev-btn
|
|
8
|
+
// destructive bg mix(destructive 12%, raised) sheen-tint elev-btn
|
|
9
|
+
// mic bg-raised sheen-quiet elev-btn
|
|
10
|
+
// card bg-card elev-1 sheen-surface
|
|
11
|
+
// field bg-field well, a 1px input border
|
|
12
|
+
// menu bg-popover elev-3 sheen-popover
|
|
13
|
+
// Each button and the mic has a pressed twin beside it, top-aligned: [data-part="<name>"][data-pressed="true"].
|
|
14
|
+
// `[data-ground]` is a patch of bare page.
|
|
15
|
+
import { utilityRules } from "../../theme/compile.js";
|
|
16
|
+
export const PAGE_PARTS = ['primary', 'secondary', 'outline', 'destructive', 'mic', 'field', 'card', 'menu'];
|
|
17
|
+
const PRESSABLE = new Set(['primary', 'secondary', 'outline', 'destructive', 'mic']);
|
|
18
|
+
const MIC = '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><rect x="9" y="3" width="6" height="11" rx="3"/><path d="M5 11a7 7 0 0 0 14 0M12 18v3"/></svg>';
|
|
19
|
+
function part(name, pressed) {
|
|
20
|
+
const attrs = `data-part="${name}"${pressed ? ' data-pressed="true"' : ''}`;
|
|
21
|
+
const press = pressed ? ' pressed' : '';
|
|
22
|
+
switch (name) {
|
|
23
|
+
case 'primary': return `<button ${attrs} class="btn p-primary sheen-primary elev-primary${press}">Main action</button>`;
|
|
24
|
+
case 'secondary': return `<button ${attrs} class="btn p-secondary sheen-tint elev-btn${press}">Second</button>`;
|
|
25
|
+
case 'outline': return `<button ${attrs} class="btn p-outline sheen-quiet elev-btn${press}">Outline</button>`;
|
|
26
|
+
case 'destructive': return `<button ${attrs} class="btn p-destructive sheen-tint elev-btn${press}">Delete</button>`;
|
|
27
|
+
case 'mic': return `<button ${attrs} class="btn p-mic sheen-quiet elev-btn${press}" aria-label="Record">${MIC}</button>`;
|
|
28
|
+
case 'card': return `<div ${attrs} class="p-card elev-1 sheen-surface"><span class="chip">Awaiting you</span></div>`;
|
|
29
|
+
case 'field': return `<div ${attrs} class="p-field well" role="textbox" aria-label="Message"></div>`;
|
|
30
|
+
case 'menu': return `<div ${attrs} class="p-menu elev-3 sheen-popover"><div class="item">Rename</div></div>`;
|
|
31
|
+
default: throw new Error(`unknown part ${name}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function partsPage(themeCss, o) {
|
|
35
|
+
const parts = o.parts ?? PAGE_PARTS;
|
|
36
|
+
const rows = parts.map((p) => `<div class="row row-${p}">${part(p, false)}${PRESSABLE.has(p) ? part(p, true) : ''}</div>`).join('\n');
|
|
37
|
+
return `<!doctype html>
|
|
38
|
+
<html class="theme-${o.theme}" data-theme="${o.theme}" lang="en">
|
|
39
|
+
<head>
|
|
40
|
+
<meta charset="utf-8">
|
|
41
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
42
|
+
<title>Depth parts: ${o.theme}</title>
|
|
43
|
+
<style>
|
|
44
|
+
${themeCss}
|
|
45
|
+
${utilityRules('.')}
|
|
46
|
+
html, body { margin: 0; background: var(--background); color: var(--foreground); }
|
|
47
|
+
body { padding: 0 24px 200px; font: 500 16px/1.2 var(--font-text); -webkit-font-smoothing: antialiased; }
|
|
48
|
+
[data-ground] { height: 48px; margin: 0 -24px 24px; }
|
|
49
|
+
.row { display: flex; align-items: flex-start; gap: 40px; margin-bottom: 96px; }
|
|
50
|
+
.btn { height: 44px; padding: 0 20px; border: 0; border-radius: var(--radius); font: inherit; display: inline-flex; align-items: center; justify-content: center; }
|
|
51
|
+
.p-primary { background-color: var(--primary); color: var(--primary-foreground); }
|
|
52
|
+
.p-secondary { background-color: var(--secondary); color: var(--secondary-foreground); }
|
|
53
|
+
.p-outline { background-color: var(--raised); color: var(--foreground); }
|
|
54
|
+
.p-destructive { background-color: color-mix(in oklab, var(--destructive) 12%, var(--raised)); color: var(--destructive); }
|
|
55
|
+
.p-mic { width: 44px; padding: 0; background-color: var(--raised); color: var(--foreground); }
|
|
56
|
+
.p-card { box-sizing: border-box; width: 100%; height: 120px; padding: 14px 16px; border-radius: var(--radius); background-color: var(--card); color: var(--card-foreground); }
|
|
57
|
+
.chip { font-size: 13px; }
|
|
58
|
+
.p-field { box-sizing: border-box; width: 100%; height: 48px; border: 1px solid var(--input); border-radius: var(--radius); background-color: var(--field); }
|
|
59
|
+
.p-menu { box-sizing: border-box; width: 220px; height: 140px; padding: 10px 14px; border-radius: var(--radius); background-color: var(--popover); color: var(--popover-foreground); }
|
|
60
|
+
.row-card { margin-bottom: 120px; }
|
|
61
|
+
</style>
|
|
62
|
+
</head>
|
|
63
|
+
<body>
|
|
64
|
+
<div data-ground></div>
|
|
65
|
+
${rows}
|
|
66
|
+
</body>
|
|
67
|
+
</html>
|
|
68
|
+
`;
|
|
69
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @supersuit/components/check/depth/playwright: the tools that drive a browser page for the depth check.
|
|
2
|
+
// shootParts draws a theme's parts page and reads back the picture and the rects; depthCompare writes the
|
|
3
|
+
// flat-beside-compiled crop picture; decodePng and encodePng read and write PNGs; the bar math turns
|
|
4
|
+
// measured round 1 and round 3 values into thresholds. They take any page with Playwright's setContent,
|
|
5
|
+
// evaluate and screenshot, so nothing here imports Playwright. The PNG helpers need `pngjs`, an optional
|
|
6
|
+
// peer: install it to use this subpath. `@supersuit/components/check/depth` needs neither.
|
|
7
|
+
export * from "./shoot.js";
|
|
8
|
+
export * from "./crop.js";
|
|
9
|
+
export * from "./png.js";
|
|
10
|
+
export * from "./bar.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// PNG decoding for the depth check's own Playwright helpers and tests. Kept apart from measure.ts and
|
|
2
|
+
// check.ts so an app can vendor those two without a PNG decoder.
|
|
3
|
+
import { PNG } from 'pngjs';
|
|
4
|
+
export function decodePng(buf) {
|
|
5
|
+
const png = PNG.sync.read(Buffer.from(buf));
|
|
6
|
+
return { width: png.width, height: png.height, data: png.data };
|
|
7
|
+
}
|
|
8
|
+
export function encodePng(img) {
|
|
9
|
+
const png = new PNG({ width: img.width, height: img.height });
|
|
10
|
+
png.data.set(img.data);
|
|
11
|
+
return PNG.sync.write(png);
|
|
12
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Rect } from './measure.ts';
|
|
2
|
+
/** Where depth is measured: a phone, 390 px wide, device scale 3, touch on (Chromium and WebKit). */
|
|
3
|
+
export declare const DEPTH_DEVICE: {
|
|
4
|
+
readonly viewport: {
|
|
5
|
+
readonly width: 390;
|
|
6
|
+
readonly height: 844;
|
|
7
|
+
};
|
|
8
|
+
readonly deviceScaleFactor: 3;
|
|
9
|
+
readonly isMobile: true;
|
|
10
|
+
readonly hasTouch: true;
|
|
11
|
+
};
|
|
12
|
+
export type PageLike = {
|
|
13
|
+
setContent(html: string, o?: {
|
|
14
|
+
waitUntil?: 'load' | 'domcontentloaded' | 'networkidle';
|
|
15
|
+
}): Promise<unknown>;
|
|
16
|
+
evaluate<R>(fn: () => R | Promise<R>): Promise<R>;
|
|
17
|
+
screenshot(o: {
|
|
18
|
+
fullPage?: boolean;
|
|
19
|
+
type?: 'png';
|
|
20
|
+
animations?: 'disabled';
|
|
21
|
+
clip?: Rect;
|
|
22
|
+
}): Promise<Uint8Array>;
|
|
23
|
+
};
|
|
24
|
+
/** The rects of every `[data-part]` (pressed twins as `<part>@pressed`) and `[data-ground]`, in CSS px. */
|
|
25
|
+
export declare function readRects(page: PageLike): Promise<{
|
|
26
|
+
rects: Record<string, Rect[]>;
|
|
27
|
+
scale: number;
|
|
28
|
+
}>;
|
|
29
|
+
export declare function shootParts(page: PageLike, themeCss: string, o: {
|
|
30
|
+
theme: string;
|
|
31
|
+
ground: 'light' | 'dark';
|
|
32
|
+
parts?: readonly string[];
|
|
33
|
+
}): Promise<{
|
|
34
|
+
png: Uint8Array<ArrayBufferLike>;
|
|
35
|
+
rects: Record<string, Rect[]>;
|
|
36
|
+
scale: number;
|
|
37
|
+
}>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// shootParts: draw a theme's parts page in a browser page and read back the picture and the rects.
|
|
2
|
+
// Takes any page with Playwright's setContent / evaluate / screenshot, so it needs no Playwright import.
|
|
3
|
+
import { partsPage } from "./parts-page.js";
|
|
4
|
+
/** Where depth is measured: a phone, 390 px wide, device scale 3, touch on (Chromium and WebKit). */
|
|
5
|
+
export const DEPTH_DEVICE = { viewport: { width: 390, height: 844 }, deviceScaleFactor: 3, isMobile: true, hasTouch: true };
|
|
6
|
+
/** The rects of every `[data-part]` (pressed twins as `<part>@pressed`) and `[data-ground]`, in CSS px. */
|
|
7
|
+
export async function readRects(page) {
|
|
8
|
+
return page.evaluate(() => {
|
|
9
|
+
const rects = {};
|
|
10
|
+
const add = (key, el) => {
|
|
11
|
+
const r = el.getBoundingClientRect();
|
|
12
|
+
(rects[key] ??= []).push({ x: r.x + window.scrollX, y: r.y + window.scrollY, width: r.width, height: r.height });
|
|
13
|
+
};
|
|
14
|
+
document.querySelectorAll('[data-part]').forEach((el) => {
|
|
15
|
+
const name = el.getAttribute('data-part');
|
|
16
|
+
add(el.hasAttribute('data-pressed') ? `${name}@pressed` : name, el);
|
|
17
|
+
});
|
|
18
|
+
const g = document.querySelector('[data-ground]');
|
|
19
|
+
if (g)
|
|
20
|
+
add('ground', g);
|
|
21
|
+
return { rects, scale: window.devicePixelRatio };
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export async function shootParts(page, themeCss, o) {
|
|
25
|
+
await page.setContent(partsPage(themeCss, o), { waitUntil: 'load' });
|
|
26
|
+
await page.evaluate(() => document.fonts.ready.then(() => undefined));
|
|
27
|
+
const { rects, scale } = await readRects(page);
|
|
28
|
+
const png = await page.screenshot({ fullPage: true, type: 'png', animations: 'disabled' });
|
|
29
|
+
return { png, rects, scale };
|
|
30
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @supersuit/components: the Supersuit component library. Each component is its own subpath, so an app
|
|
2
|
+
// that imports one gets only that one:
|
|
3
|
+
// import { VoiceField } from '@supersuit/components/voice-field'
|
|
4
|
+
// import '@supersuit/components/voice-field/styles.css'
|
|
5
|
+
// The root imports no component on purpose. It names the components this version ships.
|
|
6
|
+
export const components = ['voice-field'];
|
|
7
|
+
// The modules: shared behaviour with no part of its own (no spec, no mockup), each its own subpath too.
|
|
8
|
+
// import { sound } from '@supersuit/components/sound'
|
|
9
|
+
// import { compileTheme } from '@supersuit/components/theme'
|
|
10
|
+
// import { checkDepth } from '@supersuit/components/check/depth'
|
|
11
|
+
export const modules = ['sound', 'theme', 'check/depth'];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type SoundName, type SoundRecipe } from './synth.js';
|
|
2
|
+
export type SoundSetting = 'sounds' | 'pressSounds' | 'haptics';
|
|
3
|
+
export declare const SETTING_DEFAULTS: Record<SoundSetting, boolean>;
|
|
4
|
+
export declare const settingKey: (key: SoundSetting) => string;
|
|
5
|
+
/** The primary faces Supertools draws as buttons ("BUTTONS LOOK LIKE BUTTONS"), and a card's recommended answer:
|
|
6
|
+
* feel.ts's PRIMARY, kept until the raw-control baseline reaches zero. A switch, a radio, a tab or a pressed chip
|
|
7
|
+
* is a choice, not a button. `data-feel="tap"` opts any other control in. */
|
|
8
|
+
export declare const PRIMARY: string;
|
|
9
|
+
/** Android patterns, in milliseconds (vibrate, pause, vibrate ...). */
|
|
10
|
+
export declare const PATTERNS: Record<SoundName, number[]>;
|
|
11
|
+
/** iPhone ticks: one for a tap, two for success, three for an error, one for the rest. */
|
|
12
|
+
export declare const TICKS: Record<SoundName, number>;
|
|
13
|
+
/** The gap between iPhone ticks. A later tick goes only while the browser still counts the tap as active. */
|
|
14
|
+
export declare const TICK_GAP_MS = 90;
|
|
15
|
+
interface UserActivation {
|
|
16
|
+
isActive: boolean;
|
|
17
|
+
hasBeenActive: boolean;
|
|
18
|
+
}
|
|
19
|
+
type Nav = {
|
|
20
|
+
vibrate?: (p: number | number[]) => boolean;
|
|
21
|
+
userActivation?: UserActivation;
|
|
22
|
+
};
|
|
23
|
+
type Ctx = Pick<AudioContext, 'state' | 'currentTime' | 'destination' | 'resume' | 'createBuffer' | 'createBufferSource'> & {
|
|
24
|
+
sampleRate?: number;
|
|
25
|
+
};
|
|
26
|
+
export interface SoundEnv {
|
|
27
|
+
win: (Pick<Window, 'matchMedia' | 'setTimeout'> & Partial<Pick<Window, 'requestAnimationFrame'>> & {
|
|
28
|
+
AudioContext?: new () => Ctx;
|
|
29
|
+
webkitAudioContext?: new () => Ctx;
|
|
30
|
+
}) | null;
|
|
31
|
+
doc: Document | null;
|
|
32
|
+
nav: Nav | null;
|
|
33
|
+
storage: Pick<Storage, 'getItem' | 'setItem'> | null;
|
|
34
|
+
now(): number;
|
|
35
|
+
}
|
|
36
|
+
export interface InstallOptions {
|
|
37
|
+
/** Which elements make a tap (sound and haptic). Default: PRIMARY. */
|
|
38
|
+
selectors?: {
|
|
39
|
+
tap?: string;
|
|
40
|
+
};
|
|
41
|
+
/** The brand's sound recipe. Default: Maison. */
|
|
42
|
+
recipe?: SoundRecipe;
|
|
43
|
+
}
|
|
44
|
+
export declare function makeSoundEngine(envOf?: () => SoundEnv): {
|
|
45
|
+
play: (name: SoundName) => void;
|
|
46
|
+
setting: (key: SoundSetting) => boolean;
|
|
47
|
+
setSetting: (key: SoundSetting, on: boolean) => void;
|
|
48
|
+
soundFor: (target: Element, opts?: {
|
|
49
|
+
tap?: string;
|
|
50
|
+
}) => SoundName | null;
|
|
51
|
+
install: (doc?: Document | null, opts?: InstallOptions) => () => void;
|
|
52
|
+
haptic: (name: SoundName) => void;
|
|
53
|
+
haptics: () => "vibrate" | "switch" | null;
|
|
54
|
+
unlock: () => void;
|
|
55
|
+
/** for tests */
|
|
56
|
+
reset(): void;
|
|
57
|
+
};
|
|
58
|
+
export type SoundEngine = ReturnType<typeof makeSoundEngine>;
|
|
59
|
+
export {};
|