@penpair/web 0.1.3 → 0.3.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 +38 -237
- package/docs/adapters.md +83 -0
- package/docs/approvals.md +19 -0
- package/docs/artifacts.md +13 -0
- package/docs/audits.md +13 -0
- package/docs/backup.md +54 -0
- package/docs/branch-review.md +59 -0
- package/docs/build-kit.md +59 -0
- package/docs/command-contract.md +27 -0
- package/docs/compatibility.md +46 -0
- package/docs/conventions/README.md +63 -0
- package/docs/conventions/completion-2026-10-22.md +73 -0
- package/docs/conventions/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
- package/docs/conventions/plugin-code.md +23 -0
- package/docs/conventions/structure.md +48 -0
- package/docs/conventions/templates/adapter-command.ts +28 -0
- package/docs/conventions/templates/conventions.test.ts +81 -0
- package/docs/conventions/templates/frame-inspection.ts +27 -0
- package/docs/conventions/templates/frame-label.ts +15 -0
- package/docs/conventions/tsconfig.json +13 -0
- package/docs/conventions/typescript.md +59 -0
- package/docs/conventions/vitest.config.ts +11 -0
- package/docs/cookbook.md +25 -0
- package/docs/coverage.md +50 -0
- package/docs/credentials.md +27 -0
- package/docs/design-workflow.md +13 -0
- package/docs/extensions-trust.md +13 -0
- package/docs/fixtures/browser-capture-2026-10-22.json +217 -0
- package/docs/fixtures/feedback-reproductions.md +12 -0
- package/docs/fixtures/feedback-scratch.template.json +9 -0
- package/docs/formats.md +22 -0
- package/docs/getting-started.md +12 -2
- package/docs/guide.md +83 -9
- package/docs/handoff.md +34 -0
- package/docs/improvements.md +1217 -0
- package/docs/inspection.md +38 -0
- package/docs/layout-settling.md +13 -0
- package/docs/marwes-components.md +34 -0
- package/docs/marwes-tokens.md +59 -2
- package/docs/marwes.md +9 -0
- package/docs/mcp.md +40 -0
- package/docs/mode-verification.md +35 -0
- package/docs/plans/registry-polling-fix.md +101 -0
- package/docs/plans/tradient-feedback-0.2.0.md +209 -0
- package/docs/plans/tradient-feedback-review.md +83 -0
- package/docs/pr-improvements.md +57 -0
- package/docs/recovery.md +33 -0
- package/docs/releasing.md +172 -22
- package/docs/run-file.md +71 -0
- package/docs/shots.md +15 -0
- package/docs/skill-installation.md +16 -0
- package/docs/snapshots.md +20 -0
- package/docs/status.md +7 -0
- package/docs/team.md +17 -0
- package/docs/theme-previews.md +18 -0
- package/docs/token-editing.md +22 -0
- package/docs/tradient-followups.md +77 -0
- package/docs/trials/report-template.json +76 -0
- package/docs/trials.md +41 -0
- package/docs/troubleshooting.md +26 -0
- package/docs/upstream/marwes-1.11.0-evidence.json +15 -0
- package/docs/upstream/marwes-requests.md +35 -0
- package/examples/component-pilot/renderer.mjs +100 -0
- package/examples/coverage-matrix.json +126 -0
- package/examples/hello-card/README.md +18 -0
- package/examples/hello-card/build.js +24 -0
- package/examples/hello-card/helpers.js +27 -0
- package/examples/hello-card/inspect.js +4 -0
- package/examples/hello-card/readback.js +3 -0
- package/examples/reflection-browser/README.md +49 -0
- package/examples/reflection-browser/capture.mjs +311 -0
- package/examples/reflection-browser/fixture/Abel-Regular.ttf +0 -0
- package/examples/reflection-browser/fixture/OFL.txt +93 -0
- package/examples/reflection-browser/fixture/index.html +11 -0
- package/examples/reflection-browser/fixture-hooks.mjs +24 -0
- package/examples/reflection-browser/provider.mjs +90 -0
- package/examples/reflection-browser/serve.mjs +37 -0
- package/examples/theme-preview/README.md +21 -0
- package/examples/theme-preview/apply.js +8 -0
- package/examples/theme-preview/helpers.js +12 -0
- package/examples/theme-preview/inspect.js +3 -0
- package/examples/theme-preview/readback.js +7 -0
- package/examples/trials/hold-inspect.js +5 -0
- package/examples/trials/hold-readback.js +8 -0
- package/examples/trials/hold-writer.js +16 -0
- package/examples/trials/recovery-build.js +23 -0
- package/examples/trials/recovery-inspect.js +10 -0
- package/examples/trials/recovery-readback.js +7 -0
- package/examples/trials/wrong-file-read.js +3 -0
- package/package.json +3 -2
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Real browser comparison starter
|
|
2
|
+
|
|
3
|
+
Copy `capture.mjs` and `provider.mjs` into the adopting project, or use the shipped copies under `node_modules/@penpair/web/examples/reflection-browser/`. This is a starting provider for the existing `ImplementationProvider.runCase` contract. It does not install a browser, change your application or approve a design.
|
|
4
|
+
|
|
5
|
+
Use your project's pinned Playwright and matching browser installation. A copied provider resolves `@penpair/core` from its project; declare it at the same version as the other Penpair packages, or pass its three IO helpers explicitly as `io`. Keep all Penpair versions aligned. Do not use the fixture hooks as application evidence.
|
|
6
|
+
|
|
7
|
+
In your trusted project provider:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import { chromium } from 'playwright'; // the adopter's pinned version
|
|
11
|
+
import { createBrowserProvider } from './provider.mjs';
|
|
12
|
+
import { hooks } from './project-hooks.mjs';
|
|
13
|
+
export async function runCase(test) {
|
|
14
|
+
const browser = await chromium.launch();
|
|
15
|
+
try {
|
|
16
|
+
return await createBrowserProvider({ browser, baseURL: 'http://127.0.0.1:5173', projectRoot: process.cwd(), hooks }).runCase(test);
|
|
17
|
+
} finally { await browser.close(); }
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Required hooks:
|
|
22
|
+
|
|
23
|
+
| Hook | Contract |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| `route(test)` | Return the exact intended route; must match `test.route` on the configured app origin. |
|
|
26
|
+
| `setup(page, test)` | Explicitly establish application fixture, theme and state using your app's controls or test APIs. |
|
|
27
|
+
| `observe(page, test)` | Independently read **actual** `{theme,state,fixture}` from rendered DOM/application evidence. Never return the requested fields directly. |
|
|
28
|
+
| `captureRoot(test)` | Return one unique CSS selector for the design region. |
|
|
29
|
+
| `expectedFonts(test)` | Return explicit webfont `{family,weight,style}` faces; each must be observed loaded in `document.fonts`. System-font fallback cannot stand in for webfont evidence. |
|
|
30
|
+
| `prepareCapture(page, test, root)` | Optional explicit scroll/sticky setup after automatic scroll. Use it when a shell would cover the root. Occlusion checks refuse covered captures; the starter does not hide your shell. |
|
|
31
|
+
|
|
32
|
+
The provider measures the viewport and device scale (default 1), waits for font faces/weights and three equal root boxes, parks the pointer outside the viewport, checks hover and sampled occlusion, and rounds the document box **outward to whole CSS pixels**. It captures that clip against the full document so viewport trimming cannot silently remove a pixel. Root dimensions must match the design case. It never resizes a screenshot to improve the comparison. Metadata retains root/clip, browser version, actual fonts, scroll, pointer and layout evidence. Occlusion checks sample points; inspect images for unsampled overlays and animation differences.
|
|
33
|
+
|
|
34
|
+
The comparison uses exact decoded RGBA pixel differences in a browser canvas. The numeric ratio is evidence; inspect image differences and retain `owner-review-required`. Baseline hashes, paths and PNG dimensions are still independently checked by the adapter. Old schema-1 providers remain readable; this starter requires its complete capture metadata.
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
penpair reflection plan --map design/implementation-cases.json
|
|
38
|
+
penpair reflection check --map design/implementation-cases.json --provider design/browser/run.mjs
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
These commands require registered `@penpair/reflection-check` and current exact approved design cases. See [adapter setup](../../docs/adapters.md). `runCase` must close its browser/context as above. Do not store credentials in hooks or evidence.
|
|
42
|
+
|
|
43
|
+
## Local plumbing trial
|
|
44
|
+
|
|
45
|
+
From this repository, run `pnpm smoke:browser` using a locally installed pinned Playwright and browser. Optional `PENPAIR_PLAYWRIGHT_MODULE` selects an absolute module path; `PENPAIR_BROWSER_EXECUTABLE` or `PENPAIR_BROWSER_CHANNEL` selects an existing test browser. No absolute machine paths are committed to the example.
|
|
46
|
+
|
|
47
|
+
The script starts/stops a loopback fixture, captures desktop/mobile × light/dark × loaded/empty, tests wrong theme, missing face/weight, delayed font loading, scale mismatch, hover and sticky occlusion, and verifies unchanged baseline bytes. Its browser references are deliberately **unapproved synthetic fixtures**. They exercise plumbing; they are not Penpot acceptance or owner-approved design baselines.
|
|
48
|
+
|
|
49
|
+
The fixture's Abel Regular font is redistributed under [SIL OFL](fixture/OFL.txt), retrieved from [Google Fonts](https://github.com/google/fonts/tree/main/ofl/abel), SHA-256 `8809dcad25318225052f88333e208c5aad4adcb7b2c934c135735ec19aa410b4`. Browser APIs follow [Playwright screenshot documentation](https://playwright.dev/docs/api/class-page#page-screenshot) and [font-loading evidence](https://developer.mozilla.org/en-US/docs/Web/API/FontFaceSet).
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/** Browser plumbing only. Project hooks supply real setup and independent DOM readback. */
|
|
2
|
+
export function outwardClip(box) {
|
|
3
|
+
if (
|
|
4
|
+
!box ||
|
|
5
|
+
![
|
|
6
|
+
box.x,
|
|
7
|
+
box.y,
|
|
8
|
+
box.width,
|
|
9
|
+
box.height,
|
|
10
|
+
].every(Number.isFinite) ||
|
|
11
|
+
box.x < 0 ||
|
|
12
|
+
box.y < 0 ||
|
|
13
|
+
box.width <= 0 ||
|
|
14
|
+
box.height <= 0
|
|
15
|
+
) {
|
|
16
|
+
throw new Error("Capture root needs a finite, positive document box");
|
|
17
|
+
}
|
|
18
|
+
const x = Math.floor(box.x);
|
|
19
|
+
const y = Math.floor(box.y);
|
|
20
|
+
return {
|
|
21
|
+
x,
|
|
22
|
+
y,
|
|
23
|
+
width: Math.ceil(box.x + box.width) - x,
|
|
24
|
+
height: Math.ceil(box.y + box.height) - y,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export async function captureCase(page, test, hooks, { timeoutMs = 10000 } = {}) {
|
|
28
|
+
for (const name of [
|
|
29
|
+
"setup",
|
|
30
|
+
"observe",
|
|
31
|
+
"captureRoot",
|
|
32
|
+
"expectedFonts",
|
|
33
|
+
]) {
|
|
34
|
+
if (typeof hooks[name] !== "function") {
|
|
35
|
+
throw new Error(`Required project hook: ${name}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
page.setDefaultTimeout(timeoutMs);
|
|
39
|
+
await hooks.setup(page, test);
|
|
40
|
+
const selector = await hooks.captureRoot(test);
|
|
41
|
+
const root = page.locator(selector);
|
|
42
|
+
if ((await root.count()) !== 1) {
|
|
43
|
+
throw new Error("Capture root must resolve uniquely");
|
|
44
|
+
}
|
|
45
|
+
const expectedFonts = await hooks.expectedFonts(test);
|
|
46
|
+
if (
|
|
47
|
+
!Array.isArray(expectedFonts) ||
|
|
48
|
+
!expectedFonts.length ||
|
|
49
|
+
expectedFonts.some((font) => !font.family || !font.weight || !font.style)
|
|
50
|
+
) {
|
|
51
|
+
throw new Error("Explicit font family/weight/style evidence is required");
|
|
52
|
+
}
|
|
53
|
+
await page.waitForFunction(
|
|
54
|
+
(fonts) => {
|
|
55
|
+
const clean = (value) => value.replace(/["']/g, "");
|
|
56
|
+
return (
|
|
57
|
+
document.fonts.status === "loaded" &&
|
|
58
|
+
fonts.every((wanted) =>
|
|
59
|
+
[
|
|
60
|
+
...document.fonts,
|
|
61
|
+
].some(
|
|
62
|
+
(face) =>
|
|
63
|
+
clean(face.family) === wanted.family &&
|
|
64
|
+
face.weight === wanted.weight &&
|
|
65
|
+
face.style === wanted.style &&
|
|
66
|
+
face.status === "loaded",
|
|
67
|
+
),
|
|
68
|
+
)
|
|
69
|
+
);
|
|
70
|
+
},
|
|
71
|
+
expectedFonts,
|
|
72
|
+
{
|
|
73
|
+
timeout: timeoutMs,
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
await root.scrollIntoViewIfNeeded();
|
|
77
|
+
if (hooks.prepareCapture) {
|
|
78
|
+
await hooks.prepareCapture(page, test, root);
|
|
79
|
+
}
|
|
80
|
+
// Observe three complete stable boxes across animation frames, after scroll/sticky layout.
|
|
81
|
+
const rootBox = await root.evaluate(async (element, timeout) => {
|
|
82
|
+
let previous;
|
|
83
|
+
let equal = 0;
|
|
84
|
+
const deadline = performance.now() + timeout;
|
|
85
|
+
for (let count = 0; count < 120; count++) {
|
|
86
|
+
await new Promise((resolve, reject) => {
|
|
87
|
+
const timer = setTimeout(
|
|
88
|
+
() => reject(new Error("Capture layout deadline exceeded")),
|
|
89
|
+
Math.max(1, deadline - performance.now()),
|
|
90
|
+
);
|
|
91
|
+
requestAnimationFrame(() => {
|
|
92
|
+
clearTimeout(timer);
|
|
93
|
+
resolve();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
const rect = element.getBoundingClientRect();
|
|
97
|
+
const box = {
|
|
98
|
+
x: rect.x + scrollX,
|
|
99
|
+
y: rect.y + scrollY,
|
|
100
|
+
width: rect.width,
|
|
101
|
+
height: rect.height,
|
|
102
|
+
};
|
|
103
|
+
const current = JSON.stringify(box);
|
|
104
|
+
equal = current === previous ? equal + 1 : 1;
|
|
105
|
+
if (equal === 3) {
|
|
106
|
+
return box;
|
|
107
|
+
}
|
|
108
|
+
previous = current;
|
|
109
|
+
}
|
|
110
|
+
throw new Error("Capture root did not settle");
|
|
111
|
+
}, timeoutMs);
|
|
112
|
+
const clip = outwardClip(rootBox);
|
|
113
|
+
const occlusion = await root.evaluate((element) => {
|
|
114
|
+
const r = element.getBoundingClientRect();
|
|
115
|
+
const left = Math.max(0, r.left);
|
|
116
|
+
const top = Math.max(0, r.top);
|
|
117
|
+
const right = Math.min(innerWidth, r.right);
|
|
118
|
+
const bottom = Math.min(innerHeight, r.bottom);
|
|
119
|
+
if (right - left < 2 || bottom - top < 2) {
|
|
120
|
+
throw new Error("Capture root has no observable viewport area");
|
|
121
|
+
}
|
|
122
|
+
const points = [
|
|
123
|
+
[
|
|
124
|
+
left + 1,
|
|
125
|
+
top + 1,
|
|
126
|
+
],
|
|
127
|
+
[
|
|
128
|
+
right - 1,
|
|
129
|
+
top + 1,
|
|
130
|
+
],
|
|
131
|
+
[
|
|
132
|
+
(left + right) / 2,
|
|
133
|
+
(top + bottom) / 2,
|
|
134
|
+
],
|
|
135
|
+
[
|
|
136
|
+
left + 1,
|
|
137
|
+
bottom - 1,
|
|
138
|
+
],
|
|
139
|
+
[
|
|
140
|
+
right - 1,
|
|
141
|
+
bottom - 1,
|
|
142
|
+
],
|
|
143
|
+
];
|
|
144
|
+
return {
|
|
145
|
+
samples: points.length,
|
|
146
|
+
blocked: points.filter(([x, y]) => {
|
|
147
|
+
const hit = document.elementFromPoint(x, y);
|
|
148
|
+
return !hit || !element.contains(hit);
|
|
149
|
+
}).length,
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
if (occlusion.blocked) {
|
|
153
|
+
throw new Error(
|
|
154
|
+
"Capture root is occluded by sticky shell or external content; use prepareCapture to establish the intended scroll state",
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
// Move outside the viewport; a corner inside a full-screen root is not a safe parking place.
|
|
158
|
+
await page.mouse.move(-10, -10);
|
|
159
|
+
const pointer = await root.evaluate((element) => ({
|
|
160
|
+
x: -10,
|
|
161
|
+
y: -10,
|
|
162
|
+
outsideRoot: !element.matches(":hover"),
|
|
163
|
+
hoveredControls: element.querySelectorAll(
|
|
164
|
+
"button:hover,a:hover,input:hover,select:hover,textarea:hover,[role=button]:hover",
|
|
165
|
+
).length,
|
|
166
|
+
}));
|
|
167
|
+
if (!pointer.outsideRoot || pointer.hoveredControls !== 0) {
|
|
168
|
+
throw new Error("Hover contamination in capture root");
|
|
169
|
+
}
|
|
170
|
+
const observed = await hooks.observe(page, test);
|
|
171
|
+
const measured = await page.evaluate(() => ({
|
|
172
|
+
viewport: {
|
|
173
|
+
width: innerWidth,
|
|
174
|
+
height: innerHeight,
|
|
175
|
+
},
|
|
176
|
+
deviceScaleFactor: devicePixelRatio,
|
|
177
|
+
scroll: {
|
|
178
|
+
x: scrollX,
|
|
179
|
+
y: scrollY,
|
|
180
|
+
},
|
|
181
|
+
fonts: [
|
|
182
|
+
...document.fonts,
|
|
183
|
+
]
|
|
184
|
+
.filter((face) => face.status === "loaded")
|
|
185
|
+
.map((face) => ({
|
|
186
|
+
family: face.family.replace(/["']/g, ""),
|
|
187
|
+
weight: face.weight,
|
|
188
|
+
style: face.style,
|
|
189
|
+
status: face.status,
|
|
190
|
+
})),
|
|
191
|
+
}));
|
|
192
|
+
const actual = {
|
|
193
|
+
viewport: measured.viewport,
|
|
194
|
+
theme: observed.theme,
|
|
195
|
+
state: observed.state,
|
|
196
|
+
fixture: observed.fixture,
|
|
197
|
+
};
|
|
198
|
+
const desired = {
|
|
199
|
+
viewport: test.intent.viewport,
|
|
200
|
+
theme: test.intent.theme,
|
|
201
|
+
state: test.intent.state,
|
|
202
|
+
fixture: test.intent.fixture,
|
|
203
|
+
};
|
|
204
|
+
if (JSON.stringify(actual) !== JSON.stringify(desired)) {
|
|
205
|
+
throw new Error("Observed browser state/theme/fixture/viewport differs from requested case");
|
|
206
|
+
}
|
|
207
|
+
if (
|
|
208
|
+
clip.width !== desired.viewport.width ||
|
|
209
|
+
clip.height !== desired.viewport.height ||
|
|
210
|
+
measured.deviceScaleFactor !== test.baseline.scale
|
|
211
|
+
) {
|
|
212
|
+
throw new Error(
|
|
213
|
+
"Rounded root dimensions or device scale differ from design case; do not resize the image",
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
const screenshot = await page.screenshot({
|
|
217
|
+
type: "png",
|
|
218
|
+
fullPage: true,
|
|
219
|
+
clip,
|
|
220
|
+
scale: "device",
|
|
221
|
+
animations: "disabled",
|
|
222
|
+
caret: "hide",
|
|
223
|
+
});
|
|
224
|
+
const after = await hooks.observe(page, test);
|
|
225
|
+
const afterBox = await root.boundingBox();
|
|
226
|
+
if (
|
|
227
|
+
JSON.stringify(after) !== JSON.stringify(observed) ||
|
|
228
|
+
!afterBox ||
|
|
229
|
+
JSON.stringify(
|
|
230
|
+
outwardClip({
|
|
231
|
+
...afterBox,
|
|
232
|
+
x: afterBox.x + measured.scroll.x,
|
|
233
|
+
y: afterBox.y + measured.scroll.y,
|
|
234
|
+
}),
|
|
235
|
+
) !== JSON.stringify(clip)
|
|
236
|
+
) {
|
|
237
|
+
throw new Error("Browser source changed during capture");
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
screenshot,
|
|
241
|
+
observed: actual,
|
|
242
|
+
fonts: [
|
|
243
|
+
...new Set(measured.fonts.map((font) => font.family)),
|
|
244
|
+
],
|
|
245
|
+
fontsReady: true,
|
|
246
|
+
capture: {
|
|
247
|
+
schemaVersion: 1,
|
|
248
|
+
root: selector,
|
|
249
|
+
rootBox,
|
|
250
|
+
clip,
|
|
251
|
+
rounding: "outward-css-pixels",
|
|
252
|
+
deviceScaleFactor: measured.deviceScaleFactor,
|
|
253
|
+
browser: {
|
|
254
|
+
name: page.context().browser().browserType().name(),
|
|
255
|
+
version: page.context().browser().version(),
|
|
256
|
+
},
|
|
257
|
+
fonts: measured.fonts,
|
|
258
|
+
pointer,
|
|
259
|
+
occlusion,
|
|
260
|
+
scroll: measured.scroll,
|
|
261
|
+
layoutSamples: 3,
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** Exact decoded RGBA pixel difference, without resizing or threshold-based approval. */
|
|
267
|
+
export async function comparePng(page, baseline, screenshot) {
|
|
268
|
+
return page.evaluate(
|
|
269
|
+
async (images) => {
|
|
270
|
+
const decode = async (base64) => {
|
|
271
|
+
const image = new Image();
|
|
272
|
+
image.src = "data:image/png;base64," + base64;
|
|
273
|
+
await image.decode();
|
|
274
|
+
return image;
|
|
275
|
+
};
|
|
276
|
+
const [before, after] = await Promise.all(images.map(decode));
|
|
277
|
+
if (before.width !== after.width || before.height !== after.height) {
|
|
278
|
+
throw new Error("Comparison dimensions differ");
|
|
279
|
+
}
|
|
280
|
+
const canvas = document.createElement("canvas");
|
|
281
|
+
canvas.width = before.width;
|
|
282
|
+
canvas.height = before.height;
|
|
283
|
+
const context = canvas.getContext("2d", {
|
|
284
|
+
willReadFrequently: true,
|
|
285
|
+
});
|
|
286
|
+
context.drawImage(before, 0, 0);
|
|
287
|
+
const a = context.getImageData(0, 0, canvas.width, canvas.height).data;
|
|
288
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
289
|
+
context.drawImage(after, 0, 0);
|
|
290
|
+
const b = context.getImageData(0, 0, canvas.width, canvas.height).data;
|
|
291
|
+
let changed = 0;
|
|
292
|
+
for (let index = 0; index < a.length; index += 4) {
|
|
293
|
+
if (
|
|
294
|
+
[
|
|
295
|
+
0,
|
|
296
|
+
1,
|
|
297
|
+
2,
|
|
298
|
+
3,
|
|
299
|
+
].some((channel) => a[index + channel] !== b[index + channel])
|
|
300
|
+
) {
|
|
301
|
+
changed++;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return changed / (canvas.width * canvas.height);
|
|
305
|
+
},
|
|
306
|
+
[
|
|
307
|
+
baseline.toString("base64"),
|
|
308
|
+
screenshot.toString("base64"),
|
|
309
|
+
],
|
|
310
|
+
);
|
|
311
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright (c) 2011, Matthew Desmond (http://www.madtype.com | mattdesmond@gmail.com),with Reserved Font Name Abel.
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
http://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<!doctype html><html lang="en"><meta charset="utf-8"><title>Comparison capture fixture</title>
|
|
2
|
+
<style>
|
|
3
|
+
@font-face{font-family:Fixture;src:url('./Abel-Regular.ttf');font-style:normal;font-weight:400;font-display:swap}
|
|
4
|
+
*{box-sizing:border-box}html,body{margin:0;font-family:Fixture,sans-serif}header{height:64px;position:sticky;top:0;background:#163e3c;color:white;padding:20px;z-index:2}main{position:relative;margin-left:.25px;width:calc(100vw - .5px);height:calc(100vh - .5px);padding:30px;background:#f2f5f3;color:#152c2a}html[data-theme=dark] main{background:#152c2a;color:#f2f5f3}button{font:inherit;padding:12px;border:1px solid #71928a;background:transparent;color:inherit}button:hover{background:magenta}h1{font-size:32px;font-weight:400;margin:0 0 16px}section{padding:20px 0}p{margin:12px 0}
|
|
5
|
+
</style>
|
|
6
|
+
<header>Application shell — excluded from capture</header><main id="capture"><h1>Workspace</h1><p id="state"></p><section><button>New item</button><p id="items"></p></section></main>
|
|
7
|
+
<script>
|
|
8
|
+
const query=new URLSearchParams(location.search),theme=query.get('theme')||'light',state=query.get('state')||'loaded';
|
|
9
|
+
document.documentElement.dataset.theme=theme;document.querySelector('main').dataset.state=state;document.querySelector('main').dataset.fixture=state==='empty'?'no-items':'sample-items';
|
|
10
|
+
document.querySelector('#state').textContent=state==='empty'?'Your workspace is ready for its first item.':'Recent activity';document.querySelector('#items').textContent=state==='empty'?'No items yet.':'First item · Second item · Third item';
|
|
11
|
+
</script></html>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const hooks = {
|
|
2
|
+
route: (test) => test.route,
|
|
3
|
+
async setup(page) {
|
|
4
|
+
await page.locator("#capture").scrollIntoViewIfNeeded();
|
|
5
|
+
},
|
|
6
|
+
async prepareCapture(page) {
|
|
7
|
+
await page.evaluate(() => window.scrollTo(0, 0));
|
|
8
|
+
},
|
|
9
|
+
async observe(page) {
|
|
10
|
+
return page.evaluate(() => ({
|
|
11
|
+
theme: document.documentElement.dataset.theme,
|
|
12
|
+
state: document.querySelector("main").dataset.state,
|
|
13
|
+
fixture: document.querySelector("main").dataset.fixture,
|
|
14
|
+
}));
|
|
15
|
+
},
|
|
16
|
+
captureRoot: () => "#capture",
|
|
17
|
+
expectedFonts: () => [
|
|
18
|
+
{
|
|
19
|
+
family: "Fixture",
|
|
20
|
+
weight: "400",
|
|
21
|
+
style: "normal",
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdir, readFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { captureCase, comparePng } from "./capture.mjs";
|
|
5
|
+
|
|
6
|
+
/** Pass a browser from the adopting project's pinned Playwright; this example installs nothing. */
|
|
7
|
+
export function createBrowserProvider({
|
|
8
|
+
browser,
|
|
9
|
+
baseURL,
|
|
10
|
+
projectRoot,
|
|
11
|
+
hooks,
|
|
12
|
+
deviceScaleFactor = 1,
|
|
13
|
+
timeoutMs = 10000,
|
|
14
|
+
io,
|
|
15
|
+
}) {
|
|
16
|
+
if (!browser || !projectRoot || !baseURL || typeof hooks?.route !== "function") {
|
|
17
|
+
throw new Error("Browser, project root, app origin and explicit route hook required");
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
async runCase(test) {
|
|
21
|
+
const { atomicWriteFile, resolveProjectInput, resolveProjectOutput } =
|
|
22
|
+
io ?? (await import("@penpair/core"));
|
|
23
|
+
const target = new URL(await hooks.route(test), baseURL);
|
|
24
|
+
const expected = new URL(test.route, baseURL);
|
|
25
|
+
if (target.origin !== new URL(baseURL).origin || target.href !== expected.href) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
"Route hook must open the exact intended route on the configured app origin",
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
const before = await readFile(await resolveProjectInput(projectRoot, test.baseline.path));
|
|
31
|
+
const hash = createHash("sha256").update(before).digest("hex");
|
|
32
|
+
if (hash !== test.baseline.sha256) {
|
|
33
|
+
throw new Error("Baseline hash changed");
|
|
34
|
+
}
|
|
35
|
+
const context = await browser.newContext({
|
|
36
|
+
viewport: test.intent.viewport,
|
|
37
|
+
deviceScaleFactor,
|
|
38
|
+
});
|
|
39
|
+
try {
|
|
40
|
+
const page = await context.newPage();
|
|
41
|
+
await page.goto(target.href, {
|
|
42
|
+
waitUntil: "domcontentloaded",
|
|
43
|
+
timeout: timeoutMs,
|
|
44
|
+
});
|
|
45
|
+
const capture = await captureCase(page, test, hooks, {
|
|
46
|
+
timeoutMs,
|
|
47
|
+
});
|
|
48
|
+
if (page.url() !== target.href) {
|
|
49
|
+
throw new Error("Application navigated away from the intended route");
|
|
50
|
+
}
|
|
51
|
+
const diffPixelRatio = await comparePng(page, before, capture.screenshot);
|
|
52
|
+
const screenshot = path.join(
|
|
53
|
+
".penpair/reflection",
|
|
54
|
+
createHash("sha256")
|
|
55
|
+
.update(test.id + ":" + test.setup)
|
|
56
|
+
.digest("hex") + ".png",
|
|
57
|
+
);
|
|
58
|
+
const output = await resolveProjectOutput(projectRoot, screenshot);
|
|
59
|
+
if (output === (await resolveProjectInput(projectRoot, test.baseline.path))) {
|
|
60
|
+
throw new Error("Capture cannot overwrite its baseline");
|
|
61
|
+
}
|
|
62
|
+
await mkdir(path.dirname(output), {
|
|
63
|
+
recursive: true,
|
|
64
|
+
});
|
|
65
|
+
await atomicWriteFile(output, capture.screenshot, {
|
|
66
|
+
replace: true,
|
|
67
|
+
});
|
|
68
|
+
return {
|
|
69
|
+
schemaVersion: 1,
|
|
70
|
+
id: test.id,
|
|
71
|
+
route: test.route,
|
|
72
|
+
setup: test.setup,
|
|
73
|
+
baselineHash: hash,
|
|
74
|
+
observed: capture.observed,
|
|
75
|
+
fonts: capture.fonts,
|
|
76
|
+
fontsReady: capture.fontsReady,
|
|
77
|
+
screenshot,
|
|
78
|
+
diffPixelRatio,
|
|
79
|
+
capture: capture.capture,
|
|
80
|
+
provider: {
|
|
81
|
+
name: "penpair-browser-starter-rgba-exact",
|
|
82
|
+
version: "1",
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
} finally {
|
|
86
|
+
await context.close();
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
const files = new Map([
|
|
4
|
+
[
|
|
5
|
+
"/",
|
|
6
|
+
[
|
|
7
|
+
"index.html",
|
|
8
|
+
"text/html",
|
|
9
|
+
],
|
|
10
|
+
],
|
|
11
|
+
[
|
|
12
|
+
"/Abel-Regular.ttf",
|
|
13
|
+
[
|
|
14
|
+
"Abel-Regular.ttf",
|
|
15
|
+
"font/ttf",
|
|
16
|
+
],
|
|
17
|
+
],
|
|
18
|
+
]);
|
|
19
|
+
const server = createServer(async (request, response) => {
|
|
20
|
+
const entry = files.get(new URL(request.url, "http://localhost").pathname);
|
|
21
|
+
if (!entry) {
|
|
22
|
+
response.writeHead(404).end();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
response.writeHead(200, {
|
|
27
|
+
"Content-Type": entry[1],
|
|
28
|
+
"Cache-Control": "no-store",
|
|
29
|
+
});
|
|
30
|
+
response.end(await readFile(new URL(`fixture/${entry[0]}`, import.meta.url)));
|
|
31
|
+
} catch {
|
|
32
|
+
response.writeHead(500).end();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
server.listen(Number(process.env.PENPAIR_EXAMPLE_PORT ?? 4174), "127.0.0.1", () =>
|
|
36
|
+
console.log(`Browser fixture: http://127.0.0.1:${server.address().port}`),
|
|
37
|
+
);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Projected theme scratch example
|
|
2
|
+
|
|
3
|
+
Generate independent light/dark artifacts with `penpair marwes tokens preview --from SNAPSHOT --theme NAME --out NEW_FILE`. The selected theme is resolved offline; no active flags are changed. Inspect each artifact's `complete`, `unknowns`, source hash, theme and ordered sets first.
|
|
4
|
+
|
|
5
|
+
These reviewed example bodies accept literal `CFG.preview` JSON, `CFG.color` token name, `CFG.rootId` and `CFG.marker`. Each target must already be a confirmed disposable, owned scratch root with `getSharedPluginData("penpair","owner") === marker`. Do not adopt an existing design root implicitly. Prepare separate light and dark roots and inspect/pin the source before any apply.
|
|
6
|
+
|
|
7
|
+
Use the normal `prepareFileScript`/`runFileScript` API with:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
const prepared = await prepareFileScript(projectRoot, 'preview/apply.js', {
|
|
11
|
+
page: 'Scratch', include: ['preview/helpers.js'],
|
|
12
|
+
inspect: 'preview/inspect.js', readback: 'preview/readback.js',
|
|
13
|
+
params: { preview: JSON.stringify(previewArtifact), color: 'surface', rootId, marker },
|
|
14
|
+
});
|
|
15
|
+
await runFileScript(client, prepared); // review inspection first
|
|
16
|
+
// Within the authorized scratch scope, apply once with a private journal and independently verify.
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The example sets one opaque projected fill directly and records `kind`, source hash, theme/sets and projected property provenance under a separate `projection` metadata key. This **removes any fill binding** and must not be reported as native per-frame theme binding. Typography/spacing/radius bindings remain real, independently inspected bindings. The example refuses unsupported colors and partial projections; it does not guess gradients, opacity or token semantics.
|
|
20
|
+
|
|
21
|
+
After applying, compare catalog definitions/order, global theme/set selections and unrelated objects against the pinned pre-write inspection. Look at two stable exports. Repeating must preserve IDs, bindings outside fill and the same provenance. Live acceptance of this example remains pending; it is covered by sandbox-body tests only.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// penpair: write
|
|
2
|
+
// penpair: idempotent
|
|
3
|
+
const input = previewInput();
|
|
4
|
+
if (!CFG.inspection || CFG.inspection.rootId !== input.root.id || CFG.inspection.provenance !== input.provenance || CFG.inspection.preserved !== input.preserved) throw new Error("Projection inputs or preserved bindings changed since inspection");
|
|
5
|
+
const fills = [{ fillColor: input.value, fillOpacity: 1 }];
|
|
6
|
+
if (JSON.stringify(input.root.fills) !== JSON.stringify(fills)) input.root.fills = fills;
|
|
7
|
+
if (input.root.getSharedPluginData("penpair", "projection") !== input.provenance) input.root.setSharedPluginData("penpair", "projection", input.provenance);
|
|
8
|
+
return {ok:true,rootId:input.root.id};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// penpair: read
|
|
2
|
+
const previewInput = () => {
|
|
3
|
+
const preview = JSON.parse(CFG.preview);
|
|
4
|
+
if (preview.schemaVersion !== 1 || preview.kind !== "projected-theme-preview" || preview.nativeBindings !== false || !/^[a-f0-9]{64}$/.test(preview.sourceHash) || !preview.complete || !Array.isArray(preview.resolved) || !Array.isArray(preview.unknowns) || preview.unknowns.length) throw new Error("Complete explicit projected preview required");
|
|
5
|
+
const matches = preview.resolved.filter(token => token.name === CFG.color && token.type === "color");
|
|
6
|
+
if (matches.length !== 1 || typeof matches[0].value !== "string" || !/^#[a-f0-9]{6}$/i.test(matches[0].value)) throw new Error("Example requires one literal opaque hex color");
|
|
7
|
+
const root = penpot.currentPage.getShapeById(CFG.rootId);
|
|
8
|
+
if (!root || !CFG.marker || root.getSharedPluginData("penpair", "owner") !== CFG.marker) throw new Error("Authorized owned scratch root required");
|
|
9
|
+
const preserved = JSON.stringify(Object.fromEntries(Object.entries(root.tokens || {}).filter(([property]) => property !== "fill")));
|
|
10
|
+
const provenance = JSON.stringify({ kind: preview.kind, sourceHash: preview.sourceHash, theme: preview.theme, sets: preview.sets, projectedProperties: { fill: CFG.color }, preservedBindings: preserved, nativeBindings: false });
|
|
11
|
+
return { root, value: matches[0].value, provenance, preserved };
|
|
12
|
+
};
|