@spectastic/render 0.1.0-pre.25

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Brian Corbin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The Playwright-backed `Renderer` port implementation (spec 106-visual-render,
3
+ * T-113, FR-003/NFR-001).
4
+ *
5
+ * This is the only file in the repo that knows what a browser is —
6
+ * `@spectastic/core` declares the `Renderer` shape (`packages/core/src/types.ts`)
7
+ * and never imports this package, enforced by the `no-core-to-render`
8
+ * dependency-cruiser rule. This file re-declares the same shape structurally
9
+ * rather than importing `@spectastic/core`, so this package builds and tests
10
+ * standalone with no core in its dependency graph — the same boundary the
11
+ * ports-and-adapters decision (design.html D-003) calls for.
12
+ *
13
+ * NFR-001: at most one browser process per run — `render()` launches
14
+ * Chromium exactly once and captures every labelled artboard from that one
15
+ * session, however many the source declares.
16
+ */
17
+ interface RenderCapture {
18
+ /** The artboard's own declared label, unmodified — naming/slugging is the
19
+ * caller's job (render-naming.ts), not this port's. */
20
+ label: string;
21
+ bytes: Uint8Array;
22
+ consoleErrors: string[];
23
+ }
24
+ interface RenderRunResult {
25
+ captures: RenderCapture[];
26
+ }
27
+ interface Renderer {
28
+ checkEgress(): Promise<boolean>;
29
+ render(location: string): Promise<RenderRunResult>;
30
+ }
31
+ declare function playwrightRenderer(): Renderer;
32
+
33
+ export { type RenderCapture, type RenderRunResult, type Renderer, playwrightRenderer };
package/dist/index.js ADDED
@@ -0,0 +1,59 @@
1
+ import { chromium } from 'playwright';
2
+
3
+ // src/index.ts
4
+ var RUNTIME_CDN = "https://unpkg.com";
5
+ async function reachable(url, timeoutMs = 5e3) {
6
+ const controller = new AbortController();
7
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
8
+ try {
9
+ const response = await fetch(url, { method: "HEAD", signal: controller.signal });
10
+ return response.status < 500;
11
+ } catch {
12
+ return false;
13
+ } finally {
14
+ clearTimeout(timer);
15
+ }
16
+ }
17
+ var ARTBOARD_SELECTOR = "[data-screen-label]";
18
+ function playwrightRenderer() {
19
+ return {
20
+ async checkEgress() {
21
+ return reachable(RUNTIME_CDN);
22
+ },
23
+ async render(location) {
24
+ const browser = await chromium.launch();
25
+ try {
26
+ const page = await browser.newPage();
27
+ let pending = [];
28
+ page.on("console", (msg) => {
29
+ if (msg.type() === "error") pending.push(msg.text());
30
+ });
31
+ page.on("pageerror", (err) => {
32
+ pending.push(String(err));
33
+ });
34
+ await page.goto(location, { waitUntil: "networkidle" });
35
+ const artboards = page.locator(ARTBOARD_SELECTOR);
36
+ const labels = await artboards.evaluateAll(
37
+ (elements) => elements.map((el) => el.getAttribute("data-screen-label") ?? "")
38
+ );
39
+ const captures = [];
40
+ for (let i = 0; i < labels.length; i++) {
41
+ pending = [];
42
+ const bytes = await artboards.nth(i).screenshot();
43
+ captures.push({
44
+ label: labels[i],
45
+ bytes: new Uint8Array(bytes),
46
+ consoleErrors: [...pending]
47
+ });
48
+ }
49
+ return { captures };
50
+ } finally {
51
+ await browser.close();
52
+ }
53
+ }
54
+ };
55
+ }
56
+
57
+ export { playwrightRenderer };
58
+ //# sourceMappingURL=index.js.map
59
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AA4CA,IAAM,WAAA,GAAc,mBAAA;AAEpB,eAAe,SAAA,CAAU,GAAA,EAAa,SAAA,GAAY,GAAA,EAAwB;AACxE,EAAA,MAAM,UAAA,GAAa,IAAI,eAAA,EAAgB;AACvC,EAAA,MAAM,QAAQ,UAAA,CAAW,MAAM,UAAA,CAAW,KAAA,IAAS,SAAS,CAAA;AAC5D,EAAA,IAAI;AACF,IAAA,MAAM,QAAA,GAAW,MAAM,KAAA,CAAM,GAAA,EAAK,EAAE,QAAQ,MAAA,EAAQ,MAAA,EAAQ,UAAA,CAAW,MAAA,EAAQ,CAAA;AAG/E,IAAA,OAAO,SAAS,MAAA,GAAS,GAAA;AAAA,EAC3B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,KAAA;AAAA,EACT,CAAA,SAAE;AACA,IAAA,YAAA,CAAa,KAAK,CAAA;AAAA,EACpB;AACF;AAMA,IAAM,iBAAA,GAAoB,qBAAA;AAEnB,SAAS,kBAAA,GAA+B;AAC7C,EAAA,OAAO;AAAA,IACL,MAAM,WAAA,GAAc;AAClB,MAAA,OAAO,UAAU,WAAW,CAAA;AAAA,IAC9B,CAAA;AAAA,IAEA,MAAM,OAAO,QAAA,EAA4C;AACvD,MAAA,MAAM,OAAA,GAAU,MAAM,QAAA,CAAS,MAAA,EAAO;AACtC,MAAA,IAAI;AACF,QAAA,MAAM,IAAA,GAAO,MAAM,OAAA,CAAQ,OAAA,EAAQ;AAMnC,QAAA,IAAI,UAAoB,EAAC;AACzB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F;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * The Playwright-backed `Renderer` port implementation (spec 106-visual-render,\n * T-113, FR-003/NFR-001).\n *\n * This is the only file in the repo that knows what a browser is —\n * `@spectastic/core` declares the `Renderer` shape (`packages/core/src/types.ts`)\n * and never imports this package, enforced by the `no-core-to-render`\n * dependency-cruiser rule. This file re-declares the same shape structurally\n * rather than importing `@spectastic/core`, so this package builds and tests\n * standalone with no core in its dependency graph — the same boundary the\n * ports-and-adapters decision (design.html D-003) calls for.\n *\n * NFR-001: at most one browser process per run — `render()` launches\n * Chromium exactly once and captures every labelled artboard from that one\n * session, however many the source declares.\n */\n\nimport { chromium } from 'playwright';\n\nexport interface RenderCapture {\n /** The artboard's own declared label, unmodified — naming/slugging is the\n * caller's job (render-naming.ts), not this port's. */\n label: string;\n bytes: Uint8Array;\n consoleErrors: string[];\n}\n\nexport interface RenderRunResult {\n captures: RenderCapture[];\n}\n\nexport interface Renderer {\n checkEgress(): Promise<boolean>;\n render(location: string): Promise<RenderRunResult>;\n}\n\n/**\n * The CDN a Claude Design export's own runtime loads from. Named here\n * because design.html D-001's spike found a blocked `unpkg.com` yields four\n * unexpanded template labels rather than a clean failure — a healthy-looking\n * page that lied. Hard-coding it is a recorded tradeoff (design.html\n * Consequences): it is the design tool's own choice of host, not this\n * verb's, and could change under us.\n */\nconst RUNTIME_CDN = 'https://unpkg.com';\n\nasync function reachable(url: string, timeoutMs = 5000): Promise<boolean> {\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n try {\n const response = await fetch(url, { method: 'HEAD', signal: controller.signal });\n // Any response at all (even a 4xx from a HEAD the CDN doesn't like) means\n // the host was reached — only a network failure means it wasn't.\n return response.status < 500;\n } catch {\n return false;\n } finally {\n clearTimeout(timer);\n }\n}\n\n/** Selector every artboard declares itself under — the same\n * `[data-screen-label]` convention the two-artboards fixture\n * (packages/render/test/fixtures/two-artboards.html) and design.html §9\n * name. */\nconst ARTBOARD_SELECTOR = '[data-screen-label]';\n\nexport function playwrightRenderer(): Renderer {\n return {\n async checkEgress() {\n return reachable(RUNTIME_CDN);\n },\n\n async render(location: string): Promise<RenderRunResult> {\n const browser = await chromium.launch();\n try {\n const page = await browser.newPage();\n\n // Errors are attributed to the artboard capturing when they fire —\n // reset before each capture, read after it. FR-009's manifest wiring\n // (T-310/T-311) is what actually reports these; this port's job is\n // only to not let them fall on the floor between browser and caller.\n let pending: string[] = [];\n page.on('console', (msg) => {\n if (msg.type() === 'error') pending.push(msg.text());\n });\n page.on('pageerror', (err) => {\n pending.push(String(err));\n });\n\n // 'networkidle' rather than 'load': design.html's own grounding row\n // (\"Artboards exist only after the runtime executes\") found a design\n // export's labels are template placeholders until its own script has\n // run and settled, which 'load' alone does not wait for.\n await page.goto(location, { waitUntil: 'networkidle' });\n\n const artboards = page.locator(ARTBOARD_SELECTOR);\n const labels = await artboards.evaluateAll((elements) =>\n elements.map((el) => el.getAttribute('data-screen-label') ?? ''),\n );\n\n const captures: RenderCapture[] = [];\n for (let i = 0; i < labels.length; i++) {\n pending = [];\n // Each artboard's OWN bounds, never the page (FR-003) — a locator\n // screenshot crops to the matched element's box.\n const bytes = await artboards.nth(i).screenshot();\n captures.push({\n label: labels[i]!,\n bytes: new Uint8Array(bytes),\n consoleErrors: [...pending],\n });\n }\n\n return { captures };\n } finally {\n await browser.close();\n }\n },\n };\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@spectastic/render",
3
+ "version": "0.1.0-pre.25",
4
+ "description": "Playwright-backed Renderer port implementation for spectastic's visual render verb. Isolates the browser dependency behind a package boundary so @spectastic/core never imports one.",
5
+ "keywords": [
6
+ "spectastic",
7
+ "playwright",
8
+ "render",
9
+ "screenshot"
10
+ ],
11
+ "license": "MIT",
12
+ "engines": {
13
+ "node": ">=20"
14
+ },
15
+ "homepage": "https://github.com/spectastic/spectastic#readme",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/spectastic/spectastic.git",
19
+ "directory": "packages/render"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/spectastic/spectastic/issues"
23
+ },
24
+ "type": "module",
25
+ "main": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "exports": {
28
+ "./package.json": "./package.json",
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "README.md"
37
+ ],
38
+ "dependencies": {
39
+ "playwright": "1.62.1"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "scripts": {
45
+ "build": "tsup",
46
+ "test": "vitest run"
47
+ }
48
+ }