@sashaangelm/designkit 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +22 -2
  3. package/THIRD_PARTY_NOTICES.md +33 -0
  4. package/dist/browser.d.ts +17 -0
  5. package/dist/browser.js +108 -0
  6. package/dist/catalog.d.ts +22 -0
  7. package/dist/catalog.js +33 -0
  8. package/dist/cli.d.ts +2 -0
  9. package/dist/cli.js +222 -0
  10. package/dist/definitions.d.ts +37 -0
  11. package/dist/definitions.js +39 -0
  12. package/dist/exporter.d.ts +24 -0
  13. package/dist/exporter.js +342 -0
  14. package/dist/index.d.ts +7 -0
  15. package/dist/index.js +3 -0
  16. package/dist/nested.d.ts +2 -0
  17. package/dist/nested.js +60 -0
  18. package/dist/output.d.ts +3 -0
  19. package/dist/output.js +52 -0
  20. package/dist/primitives.d.ts +34 -0
  21. package/dist/primitives.js +60 -0
  22. package/dist/project.d.ts +27 -0
  23. package/dist/project.js +60 -0
  24. package/dist/render-types.d.ts +51 -0
  25. package/dist/render-types.js +1 -0
  26. package/dist/render.d.ts +1 -0
  27. package/dist/render.js +129 -0
  28. package/dist/scaffold.d.ts +8 -0
  29. package/dist/scaffold.js +71 -0
  30. package/dist/selection.d.ts +16 -0
  31. package/dist/selection.js +39 -0
  32. package/dist/server.d.ts +26 -0
  33. package/dist/server.js +123 -0
  34. package/dist/studio-server.d.ts +22 -0
  35. package/dist/studio-server.js +170 -0
  36. package/dist/studio.css +470 -0
  37. package/dist/studio.d.ts +1 -0
  38. package/dist/studio.js +396 -0
  39. package/package.json +56 -3
  40. package/template/AGENTS.md +6 -0
  41. package/template/README.md +21 -0
  42. package/template/assets/README.md +5 -0
  43. package/template/assets/designkit-starter-MIT.txt +21 -0
  44. package/template/assets/orbit.svg +33 -0
  45. package/template/assets/space-grotesk-OFL.txt +93 -0
  46. package/template/assets/space-grotesk-latin-700-normal.woff2 +0 -0
  47. package/template/designkit.config.ts +7 -0
  48. package/template/designkit.root.tsx +30 -0
  49. package/template/designs/assets.d.ts +6 -0
  50. package/template/designs/social.design.tsx +46 -0
  51. package/template/gitignore.txt +3 -0
  52. package/template/package.json +27 -0
  53. package/template/styles/social.css +53 -0
  54. package/template/tsconfig.json +19 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Designkit contributors
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.
package/README.md CHANGED
@@ -1,3 +1,23 @@
1
- # Temporary Holding Version
1
+ # @sashaangelm/designkit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Build visual assets with React, TypeScript and CSS. Use the local Studio to inspect designs or headless Chromium to export PNG, JPEG and WebP.
4
+
5
+ Use Node.js 22.17 or newer. To create a project with an example design and local assets, run:
6
+
7
+ ```sh
8
+ npm create @sashaangelm/designkit@latest my-designs
9
+ cd my-designs
10
+ npm install
11
+ npm run setup
12
+ ```
13
+
14
+ In an existing React project, run `npm install @sashaangelm/designkit`, `npx designkit init`, and `npx designkit setup`. Setup installs the Chromium version used for exports.
15
+
16
+ ```sh
17
+ npx designkit list --json
18
+ npx designkit check
19
+ npx designkit export --frame field-notes/social/launch --scale 2
20
+ npx designkit studio
21
+ ```
22
+
23
+ The installed runtime works offline with local project assets. Run Designkit in repositories you trust. [Repository README](https://github.com/SASHAANGELM/designkit#readme) · [SDK reference](https://github.com/SASHAANGELM/designkit/blob/HEAD/docs/SDK.md)
@@ -0,0 +1,33 @@
1
+ # Third-party notices
2
+
3
+ Designkit's original code is MIT licensed. Dependencies, native libraries, the browser and the bundled font carry their own terms. Retain the notices that ship with those artifacts when redistributing them.
4
+
5
+ ## Direct dependencies
6
+
7
+ These versions match the workspace lockfile. Projects supply React and React DOM as peer dependencies. The workspace and sample use the listed versions.
8
+
9
+ | Package | Version | License | Upstream |
10
+ | ---------- | ------- | ---------- | ----------------------------------------------------- |
11
+ | React | 19.3.1 | MIT | [React](https://github.com/facebook/react) |
12
+ | React DOM | 19.3.1 | MIT | [React](https://github.com/facebook/react) |
13
+ | Commander | 15.1.0 | MIT | [Commander.js](https://github.com/tj/commander.js) |
14
+ | Playwright | 1.65.1 | Apache-2.0 | [Playwright](https://github.com/microsoft/playwright) |
15
+ | Sharp | 0.35.5 | Apache-2.0 | [Sharp](https://github.com/lovell/sharp) |
16
+ | Vite | 8.4.0 | MIT | [Vite](https://github.com/vitejs/vite) |
17
+ | Zod | 4.6.7 | MIT | [Zod](https://github.com/colinhacks/zod) |
18
+
19
+ The workspace and authoring tools also use TypeScript 5.9.3 (Apache-2.0), ESLint 9.39.5, typescript-eslint 8.74.0, Prettier 3.10.1, Vitest 5.1.2, pnpm 12.14.0 and the Node and React type declarations (all MIT except TypeScript).
20
+
21
+ ## Installed dependencies and native components
22
+
23
+ The installed production JavaScript dependency tree includes MIT, Apache-2.0, MPL-2.0, ISC, and BSD-3-Clause software. On every supported package target, consult the platform's actual resolved tree and its shipped notices. The current target's JavaScript inventory is available from `pnpm --filter @sashaangelm/designkit licenses list --prod`, with additional notices in the optional native packages selected by the package manager.
24
+
25
+ Among the native packages checked on Darwin arm64, the Rolldown 1.3.4 binding uses MIT, the Lightning CSS 1.33.0 package and its matching native binding use MPL-2.0, and the Sharp 0.35.5 binding uses Apache-2.0. The Sharp libvips bundle `@img/sharp-libvips-darwin-arm64@1.3.4` identifies as LGPL-3.0-or-later and includes libvips 8.18.7 plus platform-specific libraries. The bundle includes a licensing table in its README and the component versions in `versions.json`. [Rolldown](https://github.com/rolldown/rolldown) · [Lightning CSS](https://github.com/parcel-bundler/lightningcss) · [Sharp libvips](https://github.com/lovell/sharp-libvips)
26
+
27
+ ## Chromium
28
+
29
+ The npm tarball installs Playwright as a dependency. The explicit `designkit setup` command obtains Playwright 1.65.1's pinned Chromium headless shell (browser version 159.0.8154.6, Playwright revision 1255). Chromium has a BSD-style license and contains components with additional notices. Keep the browser distribution's notices and consult Chromium's published credits when redistributing a browser copy. [Playwright browser downloads](https://playwright.dev/docs/browsers) · [Chromium license](https://chromium.googlesource.com/chromium/src/+/main/LICENSE) · [Chromium third-party credits policy](https://chromium.googlesource.com/chromium/src/+/main/docs/adding_to_third_party.md)
30
+
31
+ ## Example assets
32
+
33
+ The bundled file `assets/space-grotesk-latin-700-normal.woff2` is the Latin Space Grotesk 700 face from `@fontsource/space-grotesk@5.3.0`. Copyright 2020 The Space Grotesk Project Authors. It is licensed under the SIL Open Font License 1.1, included alongside the file as `space-grotesk-OFL.txt`. The example's `orbit.svg` is original Designkit artwork under the project's MIT license. [Fontsource package](https://www.npmjs.com/package/@fontsource/space-grotesk/v/5.3.0) · [Space Grotesk OFL](https://github.com/floriankarsten/space-grotesk/blob/master/OFL.txt)
@@ -0,0 +1,17 @@
1
+ import type { Browser, BrowserContext, Page } from "playwright";
2
+ import type { RenderState } from "./render-types.js";
3
+ export declare function setupBrowser(): Promise<void>;
4
+ export declare function launchBrowser(): Promise<Browser>;
5
+ export declare function createContext(browser: Browser, origin: string, viewport: {
6
+ width: number;
7
+ height: number;
8
+ }, scale?: number): Promise<BrowserContext>;
9
+ export declare function watchResources(page: Page): {
10
+ errors: string[];
11
+ settle(): Promise<void>;
12
+ };
13
+ export declare function readState(context: BrowserContext, url: string): Promise<{
14
+ page: Page;
15
+ state: RenderState;
16
+ errors: string[];
17
+ }>;
@@ -0,0 +1,108 @@
1
+ import { spawn } from "node:child_process";
2
+ import { createRequire } from "node:module";
3
+ import { dirname, join } from "node:path";
4
+ import { chromium } from "playwright";
5
+ export async function setupBrowser() {
6
+ const require = createRequire(import.meta.url);
7
+ const cli = join(dirname(require.resolve("playwright/package.json")), "cli.js");
8
+ await new Promise((resolve, reject) => {
9
+ const child = spawn(process.execPath, [cli, "install", "--only-shell", "chromium"], { stdio: "inherit" });
10
+ child.once("error", reject);
11
+ child.once("exit", (code) => {
12
+ if (code === 0)
13
+ resolve();
14
+ else
15
+ reject(new Error("Chromium setup failed. On Linux, Playwright may require additional system libraries. See https://playwright.dev/docs/browsers#install-system-dependencies."));
16
+ });
17
+ });
18
+ }
19
+ export async function launchBrowser() {
20
+ try {
21
+ return await chromium.launch({ chromiumSandbox: true });
22
+ }
23
+ catch (error) {
24
+ if (String(error).includes("Executable doesn't exist")) {
25
+ throw new Error("Pinned Chromium is missing. Run designkit setup.", {
26
+ cause: error,
27
+ });
28
+ }
29
+ throw error;
30
+ }
31
+ }
32
+ export async function createContext(browser, origin, viewport, scale = 1) {
33
+ const context = await browser.newContext({
34
+ viewport,
35
+ deviceScaleFactor: scale,
36
+ locale: "en-US",
37
+ timezoneId: "UTC",
38
+ reducedMotion: "reduce",
39
+ serviceWorkers: "block",
40
+ });
41
+ try {
42
+ await context.route("**/*", (route) => {
43
+ if (new URL(route.request().url()).origin === origin)
44
+ return route.continue();
45
+ return route.abort("blockedbyclient");
46
+ });
47
+ await context.routeWebSocket("**/*", (socket) => socket.close());
48
+ return context;
49
+ }
50
+ catch (error) {
51
+ await context.close();
52
+ throw error;
53
+ }
54
+ }
55
+ export function watchResources(page) {
56
+ const errors = [];
57
+ const assets = new Set(["script", "stylesheet", "image", "font", "media"]);
58
+ const pending = new Set();
59
+ page.on("request", (request) => {
60
+ if (assets.has(request.resourceType()))
61
+ pending.add(request);
62
+ });
63
+ page.on("requestfinished", (request) => pending.delete(request));
64
+ page.on("requestfailed", (request) => {
65
+ pending.delete(request);
66
+ if (assets.has(request.resourceType()))
67
+ errors.push(`${request.url()}: ${request.failure()?.errorText}`);
68
+ });
69
+ page.on("response", (response) => {
70
+ if (response.status() >= 400 &&
71
+ assets.has(response.request().resourceType())) {
72
+ errors.push(`${response.url()}: HTTP ${response.status()}`);
73
+ }
74
+ });
75
+ page.on("pageerror", (error) => errors.push(error.message));
76
+ return {
77
+ errors,
78
+ async settle() {
79
+ const deadline = Date.now() + 15_000;
80
+ while (pending.size && !errors.length && Date.now() < deadline) {
81
+ await new Promise((resolve) => setTimeout(resolve, 25));
82
+ }
83
+ if (pending.size && !errors.length) {
84
+ errors.push("Timed out loading resources: " +
85
+ [...pending].map((request) => request.url()).join(", "));
86
+ }
87
+ },
88
+ };
89
+ }
90
+ export async function readState(context, url) {
91
+ const page = await context.newPage();
92
+ const { errors, settle } = watchResources(page);
93
+ await page.goto(url, { waitUntil: "domcontentloaded", timeout: 15_000 });
94
+ try {
95
+ await page.waitForFunction(() => window.designkitRender?.status !== undefined &&
96
+ window.designkitRender.status !== "loading", undefined, { timeout: 15_000 });
97
+ }
98
+ catch (error) {
99
+ throw new Error(errors.join("\n") ||
100
+ `Render did not become ready within 15 seconds: ${new URL(url).pathname}`, { cause: error });
101
+ }
102
+ const state = (await page.evaluate(() => window.designkitRender));
103
+ if (state.status === "error")
104
+ throw new Error(state.error);
105
+ if (!state.registry)
106
+ await settle();
107
+ return { page, state, errors };
108
+ }
@@ -0,0 +1,22 @@
1
+ import type { ReactNode } from "react";
2
+ type Runtime = {
3
+ selection?: {
4
+ project: string;
5
+ page: string;
6
+ frame: string;
7
+ };
8
+ scope: "entry" | "root" | "project" | "page" | "artwork";
9
+ };
10
+ export declare const CatalogContext: import("react").Context<Runtime | null>;
11
+ export interface RootProps {
12
+ children?: ReactNode;
13
+ }
14
+ export interface ProjectProps extends RootProps {
15
+ id: string;
16
+ name: string;
17
+ }
18
+ export type PageProps = ProjectProps;
19
+ export declare function Root({ children }: RootProps): import("react/jsx-runtime").JSX.Element;
20
+ export declare function Project({ children, ...props }: ProjectProps): import("react/jsx-runtime").JSX.Element | null;
21
+ export declare function Page({ children, ...props }: PageProps): import("react/jsx-runtime").JSX.Element | null;
22
+ export {};
@@ -0,0 +1,33 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext } from "react";
3
+ import { namedSchema } from "./definitions.js";
4
+ export const CatalogContext = createContext(null);
5
+ export function Root({ children }) {
6
+ const runtime = useContext(CatalogContext);
7
+ if (!runtime)
8
+ return _jsx(_Fragment, { children: children });
9
+ if (runtime.scope !== "entry") {
10
+ throw new Error("Declare one <Root> in the DesignKit entry component.");
11
+ }
12
+ return (_jsx(CatalogContext.Provider, { value: { ...runtime, scope: "root" }, children: runtime.selection ? (children) : (_jsx("div", { "data-designkit-catalog": true, children: children })) }));
13
+ }
14
+ export function Project({ children, ...props }) {
15
+ const runtime = useContext(CatalogContext);
16
+ if (!runtime || runtime.scope !== "root") {
17
+ throw new Error("Place <Project> inside <Root>.");
18
+ }
19
+ const project = namedSchema.parse(props);
20
+ if (runtime.selection && runtime.selection.project !== project.id)
21
+ return null;
22
+ return (_jsx(CatalogContext.Provider, { value: { ...runtime, scope: "project" }, children: runtime.selection ? (children) : (_jsx("div", { "data-designkit-project": JSON.stringify(project), children: children })) }));
23
+ }
24
+ export function Page({ children, ...props }) {
25
+ const runtime = useContext(CatalogContext);
26
+ if (!runtime || runtime.scope !== "project") {
27
+ throw new Error("Place <Page> inside <Project>.");
28
+ }
29
+ const page = namedSchema.parse(props);
30
+ if (runtime.selection && runtime.selection.page !== page.id)
31
+ return null;
32
+ return (_jsx(CatalogContext.Provider, { value: { ...runtime, scope: "page" }, children: runtime.selection ? (children) : (_jsx("div", { "data-designkit-page": JSON.stringify(page), children: children })) }));
33
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,222 @@
1
+ #!/usr/bin/env node
2
+ import { Command, InvalidArgumentError } from "commander";
3
+ import { launchBrowser, setupBrowser } from "./browser.js";
4
+ import { exportProject, inspectProject } from "./exporter.js";
5
+ import { loadProject } from "./project.js";
6
+ import { scaffoldProject } from "./scaffold.js";
7
+ import { resolvePreset, validateSelection } from "./selection.js";
8
+ import { openBrowser, startStudio } from "./studio-server.js";
9
+ const args = process.argv.slice(2);
10
+ const json = args.includes("--json") &&
11
+ !args.some((arg) => ["-h", "--help", "-V", "--version"].includes(arg));
12
+ const writeReport = process.stdout.write.bind(process.stdout);
13
+ if (json)
14
+ process.stdout.write = process.stderr.write.bind(process.stderr);
15
+ function report(command, result, code = result.errors.length ? 1 : 0) {
16
+ if (json) {
17
+ writeReport(JSON.stringify({ version: 2, command, ok: code === 0, ...result }) + "\n");
18
+ }
19
+ else {
20
+ for (const error of result.errors) {
21
+ const location = [error.source, error.selector].filter(Boolean).join(" ");
22
+ console.error(`[${error.code}]${location ? " " + location + ":" : ""} ${error.message}`);
23
+ }
24
+ }
25
+ process.exitCode = code;
26
+ }
27
+ const program = new Command();
28
+ let parserError = "";
29
+ program
30
+ .name("designkit")
31
+ .description("Render React designs locally")
32
+ .version("0.1.0")
33
+ .exitOverride()
34
+ .configureOutput({
35
+ writeErr: (message) => {
36
+ parserError += message;
37
+ if (!json)
38
+ process.stderr.write(message);
39
+ },
40
+ });
41
+ function numeric(value) {
42
+ if (!/^(?:\d+\.?\d*|\.\d+)$/.test(value))
43
+ throw new InvalidArgumentError("Expected a number.");
44
+ return Number(value);
45
+ }
46
+ function format(value) {
47
+ if (value === "png" || value === "jpeg" || value === "webp")
48
+ return value;
49
+ throw new InvalidArgumentError("Use png, jpeg, or webp.");
50
+ }
51
+ program
52
+ .command("setup")
53
+ .description("Install pinned Chromium")
54
+ .action(setupBrowser);
55
+ program
56
+ .command("init")
57
+ .description("Add an example and missing Designkit files to the current project")
58
+ .action(async () => {
59
+ const result = await scaffoldProject(process.cwd(), { mode: "init" });
60
+ console.log(`Designkit project: ${result.root}`);
61
+ for (const path of result.created)
62
+ console.log(` Added ${path}`);
63
+ for (const path of result.skipped)
64
+ console.log(` Kept ${path}`);
65
+ if (result.skipped.includes("package.json")) {
66
+ console.log("Install @sashaangelm/designkit in this project if needed. Run npx designkit setup, then npx designkit check.");
67
+ }
68
+ else {
69
+ console.log("Install the Designkit tarball, then run npm run setup and npm run check.");
70
+ }
71
+ });
72
+ program
73
+ .command("studio")
74
+ .description("Open the local read-only Studio")
75
+ .option("--port <port>", "Local port", (value) => {
76
+ const port = numeric(value);
77
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
78
+ throw new InvalidArgumentError("Use an integer port from 1 to 65535.");
79
+ }
80
+ return port;
81
+ })
82
+ .option("--no-open", "Print the Studio URL without opening a browser")
83
+ .action(async ({ port, open }) => {
84
+ const { server, origin } = await startStudio(process.cwd(), port);
85
+ console.log(`Designkit Studio: ${origin}`);
86
+ const close = async () => {
87
+ process.off("SIGINT", close);
88
+ process.off("SIGTERM", close);
89
+ await server.close();
90
+ };
91
+ process.once("SIGINT", close);
92
+ process.once("SIGTERM", close);
93
+ if (open)
94
+ openBrowser(origin);
95
+ });
96
+ for (const command of ["list", "check"]) {
97
+ program
98
+ .command(command)
99
+ .option("--json", "Output a JSON report")
100
+ .action(async () => {
101
+ const result = await inspectProject(process.cwd(), command === "check");
102
+ if (!json) {
103
+ for (const project of result.projects) {
104
+ console.log(project.name);
105
+ for (const page of project.pages) {
106
+ console.log(` ${page.name} (${page.source})`);
107
+ for (const root of page.frames) {
108
+ const selector = `${project.id}/${page.id}/${root.id}`;
109
+ console.log(` ${selector} ${root.width}×${root.height}`);
110
+ for (const nested of root.nested ?? [])
111
+ console.log(` ${selector}/${nested.id} ${nested.width}×${nested.height}`);
112
+ }
113
+ }
114
+ }
115
+ }
116
+ report(command, result);
117
+ });
118
+ }
119
+ program
120
+ .command("doctor")
121
+ .option("--json", "Output a JSON report")
122
+ .action(async () => {
123
+ const errors = [];
124
+ let chromium = null;
125
+ try {
126
+ const browser = await launchBrowser();
127
+ try {
128
+ chromium = browser.version();
129
+ }
130
+ finally {
131
+ await browser.close();
132
+ }
133
+ }
134
+ catch (error) {
135
+ errors.push({
136
+ code: "BROWSER_UNAVAILABLE",
137
+ message: error instanceof Error ? error.message : String(error),
138
+ });
139
+ }
140
+ const result = {
141
+ node: process.version,
142
+ chromium,
143
+ platform: process.platform,
144
+ arch: process.arch,
145
+ errors,
146
+ };
147
+ if (!json)
148
+ console.log(`Node ${result.node} • ${result.platform}/${result.arch} • Chromium ${chromium ?? "unavailable"}`);
149
+ report("doctor", result);
150
+ });
151
+ program
152
+ .command("export")
153
+ .description("Export designs to image files")
154
+ .option("--all", "Export the default batch")
155
+ .option("--project <id>", "Export one project")
156
+ .option("--page <selector>", "Export one page (project/page)")
157
+ .option("--frame <selector>", "Export a frame (repeatable)", (value, previous) => [...previous, value], [])
158
+ .option("--format <format>", "png, jpeg, or webp", format)
159
+ .option("--scale <scale>", "Device pixel ratio", numeric)
160
+ .option("--quality <quality>", "JPEG or WebP quality", numeric)
161
+ .option("--transparent", "Preserve alpha for PNG/WebP")
162
+ .option("--no-transparent", "Composite against white")
163
+ .option("--overwrite", "Replace existing exports")
164
+ .option("--json", "Output a JSON report")
165
+ .action(async (options) => {
166
+ const project = process.cwd();
167
+ try {
168
+ validateSelection(options);
169
+ }
170
+ catch (error) {
171
+ report("export", {
172
+ errors: [
173
+ { code: "INVALID_USAGE", message: error.message },
174
+ ],
175
+ }, 2);
176
+ return;
177
+ }
178
+ const config = await loadProject(project);
179
+ try {
180
+ resolvePreset(options, config.export);
181
+ }
182
+ catch (error) {
183
+ report("export", {
184
+ errors: [
185
+ { code: "INVALID_USAGE", message: error.message },
186
+ ],
187
+ }, 2);
188
+ return;
189
+ }
190
+ const result = await exportProject(project, options, undefined, config);
191
+ if (!json)
192
+ for (const file of result.files)
193
+ console.log(`${file.path} (${file.width}×${file.height})`);
194
+ report("export", result);
195
+ });
196
+ try {
197
+ await program.parseAsync();
198
+ }
199
+ catch (error) {
200
+ const command = args[0] ?? "designkit";
201
+ if (error &&
202
+ typeof error === "object" &&
203
+ "exitCode" in error &&
204
+ typeof error.exitCode === "number") {
205
+ if (error.exitCode === 0)
206
+ process.exitCode = 0;
207
+ else if (json)
208
+ report(command, { errors: [{ code: "INVALID_USAGE", message: parserError.trim() }] }, 2);
209
+ else
210
+ process.exitCode = 2;
211
+ }
212
+ else {
213
+ report(command, {
214
+ errors: [
215
+ {
216
+ code: "RUNTIME_FAILED",
217
+ message: error instanceof Error ? error.message : String(error),
218
+ },
219
+ ],
220
+ });
221
+ }
222
+ }
@@ -0,0 +1,37 @@
1
+ import { z } from "zod";
2
+ export declare const idSchema: z.ZodString;
3
+ export declare const exportPresetSchema: z.ZodObject<{
4
+ format: z.ZodEnum<{
5
+ png: "png";
6
+ jpeg: "jpeg";
7
+ webp: "webp";
8
+ }>;
9
+ scale: z.ZodDefault<z.ZodNumber>;
10
+ quality: z.ZodOptional<z.ZodNumber>;
11
+ transparent: z.ZodOptional<z.ZodBoolean>;
12
+ }, z.core.$strict>;
13
+ export type ExportPreset = z.output<typeof exportPresetSchema>;
14
+ export type ExportPresetInput = z.input<typeof exportPresetSchema>;
15
+ export declare const namedSchema: z.ZodObject<{
16
+ id: z.ZodString;
17
+ name: z.ZodString;
18
+ }, z.core.$strip>;
19
+ export declare const frameSchema: z.ZodObject<{
20
+ id: z.ZodString;
21
+ name: z.ZodString;
22
+ width: z.ZodNumber;
23
+ height: z.ZodNumber;
24
+ background: z.ZodOptional<z.ZodString>;
25
+ x: z.ZodOptional<z.ZodNumber>;
26
+ y: z.ZodOptional<z.ZodNumber>;
27
+ exports: z.ZodOptional<z.ZodArray<z.ZodObject<{
28
+ format: z.ZodEnum<{
29
+ png: "png";
30
+ jpeg: "jpeg";
31
+ webp: "webp";
32
+ }>;
33
+ scale: z.ZodDefault<z.ZodNumber>;
34
+ quality: z.ZodOptional<z.ZodNumber>;
35
+ transparent: z.ZodOptional<z.ZodBoolean>;
36
+ }, z.core.$strict>>>;
37
+ }, z.core.$strip>;
@@ -0,0 +1,39 @@
1
+ import { z } from "zod";
2
+ export const idSchema = z
3
+ .string()
4
+ .regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/, "Use a letter or number first, followed by letters, numbers, underscores or hyphens");
5
+ export const exportPresetSchema = z
6
+ .strictObject({
7
+ format: z.enum(["png", "jpeg", "webp"]),
8
+ scale: z.number().positive().max(8).default(1),
9
+ quality: z.number().int().min(1).max(100).optional(),
10
+ transparent: z.boolean().optional(),
11
+ })
12
+ .superRefine((preset, context) => {
13
+ if (preset.format === "png" && preset.quality !== undefined) {
14
+ context.addIssue({
15
+ code: "custom",
16
+ path: ["quality"],
17
+ message: "Quality applies to JPEG and WebP",
18
+ });
19
+ }
20
+ if (preset.format === "jpeg" && preset.transparent) {
21
+ context.addIssue({
22
+ code: "custom",
23
+ path: ["transparent"],
24
+ message: "JPEG requires an opaque background",
25
+ });
26
+ }
27
+ });
28
+ export const namedSchema = z.object({
29
+ id: idSchema,
30
+ name: z.string().min(1),
31
+ });
32
+ export const frameSchema = namedSchema.extend({
33
+ width: z.number().int().positive(),
34
+ height: z.number().int().positive(),
35
+ background: z.string().optional(),
36
+ x: z.number().optional(),
37
+ y: z.number().optional(),
38
+ exports: z.array(exportPresetSchema).optional(),
39
+ });
@@ -0,0 +1,24 @@
1
+ import type { Browser } from "playwright";
2
+ import type { ExportOptions } from "./selection.js";
3
+ import { startServer } from "./server.js";
4
+ import type { Diagnostic, PageInfo, RegistryReport, RootInfo } from "./render-types.js";
5
+ type Session = Awaited<ReturnType<typeof startServer>>;
6
+ type Runtime = Session & {
7
+ browser: Browser;
8
+ };
9
+ export interface ExportedFile {
10
+ selector: string;
11
+ path: string;
12
+ width: number;
13
+ height: number;
14
+ format: string;
15
+ scale: number;
16
+ }
17
+ export interface ExportReport {
18
+ files: ExportedFile[];
19
+ errors: Diagnostic[];
20
+ }
21
+ export declare function renderUrl(origin: string, page: PageInfo, frame: RootInfo, capture?: boolean): string;
22
+ export declare function inspectProject(project: string, check?: boolean): Promise<RegistryReport>;
23
+ export declare function exportProject(project: string, options: ExportOptions, existing?: Session, config?: Runtime["config"]): Promise<ExportReport>;
24
+ export {};