@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/dist/studio.js ADDED
@@ -0,0 +1,396 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useMemo, useRef, useState } from "react";
3
+ import { createRoot } from "react-dom/client";
4
+ import "./studio.css";
5
+ const icons = {
6
+ frame: (_jsx(_Fragment, { children: _jsx("path", { d: "M6 3 4 17M12 3l-2 14M3 8h13M2 12h13" }) })),
7
+ project: _jsx("path", { d: "M2 6h6l2 2h8v8H2z" }),
8
+ page: (_jsxs(_Fragment, { children: [_jsx("path", { d: "M6 5V3h9v11h-2" }), _jsx("rect", { x: "3", y: "6", width: "9", height: "11", rx: "1" })] })),
9
+ minus: _jsx("path", { d: "M4 10h12" }),
10
+ plus: _jsx("path", { d: "M4 10h12m-6-6v12" }),
11
+ fit: _jsx("path", { d: "M3 7V3h4m6 0h4v4m0 6v4h-4m-6 0H3v-4" }),
12
+ export: _jsx("path", { d: "M10 3v10M6 9l4 4 4-4M4 14v3h12v-3" }),
13
+ warning: (_jsx("path", { d: "M10 5v5m0 3v1M9 2 2 15a1 1 0 0 0 1 2h14a1 1 0 0 0 1-2L11 2a1 1 0 0 0-2 0Z" })),
14
+ };
15
+ function Icon({ name }) {
16
+ return (_jsx("svg", { "aria-hidden": "true", viewBox: "0 0 20 20", width: "16", height: "16", fill: "none", stroke: "currentColor", strokeWidth: "1.45", strokeLinecap: "round", strokeLinejoin: "round", children: icons[name] }));
17
+ }
18
+ function useFrameState(ref, enabled, onState) {
19
+ const callback = useRef(onState);
20
+ useEffect(() => {
21
+ callback.current = onState;
22
+ }, [onState]);
23
+ useEffect(() => {
24
+ if (!enabled)
25
+ return;
26
+ const start = performance.now();
27
+ const interval = window.setInterval(() => {
28
+ try {
29
+ const state = ref.current?.contentWindow?.designkitRender;
30
+ if (state && state.status !== "loading") {
31
+ callback.current(state);
32
+ window.clearInterval(interval);
33
+ return;
34
+ }
35
+ if (performance.now() - start > 20_000) {
36
+ callback.current({
37
+ status: "error",
38
+ error: "The render did not become ready within 20 seconds.",
39
+ });
40
+ window.clearInterval(interval);
41
+ }
42
+ }
43
+ catch {
44
+ callback.current({
45
+ status: "error",
46
+ error: "The render document could not be read.",
47
+ });
48
+ window.clearInterval(interval);
49
+ }
50
+ }, 100);
51
+ return () => window.clearInterval(interval);
52
+ }, [enabled, ref]);
53
+ }
54
+ function placements(frames) {
55
+ const gap = 96;
56
+ const columns = Math.min(3, Math.max(1, Math.ceil(Math.sqrt(frames.length))));
57
+ const widths = Array.from({ length: columns }, (_, column) => Math.max(0, ...frames
58
+ .filter((_, i) => i % columns === column)
59
+ .map((frame) => frame.width)));
60
+ let y = 0;
61
+ let rowHeight = 0;
62
+ return frames.map((frame, i) => {
63
+ const column = i % columns;
64
+ if (!column && i) {
65
+ y += rowHeight + gap;
66
+ rowHeight = 0;
67
+ }
68
+ rowHeight = Math.max(rowHeight, frame.height);
69
+ const x = widths
70
+ .slice(0, column)
71
+ .reduce((sum, width) => sum + width + gap, 0);
72
+ return { frame, x: frame.x ?? x, y: frame.y ?? y };
73
+ });
74
+ }
75
+ function boundsOf({ frame, x, y }, nested) {
76
+ if (!nested)
77
+ return { x, y, width: frame.width, height: frame.height };
78
+ return {
79
+ x: x + nested.x,
80
+ y: y + nested.y,
81
+ width: nested.width,
82
+ height: nested.height,
83
+ };
84
+ }
85
+ function pageBounds(positions) {
86
+ const x = Math.min(...positions.map((position) => position.x));
87
+ const y = Math.min(...positions.map((position) => position.y));
88
+ return {
89
+ x,
90
+ y,
91
+ width: Math.max(...positions.map(({ x, frame }) => x + frame.width)) - x,
92
+ height: Math.max(...positions.map(({ y, frame }) => y + frame.height)) - y,
93
+ };
94
+ }
95
+ function scaleInRange(value) {
96
+ return Math.min(8, Math.max(0.002, value));
97
+ }
98
+ function zoomAt(previous, factor, point) {
99
+ const scale = scaleInRange(previous.scale * factor);
100
+ const ratio = scale / previous.scale;
101
+ return {
102
+ scale,
103
+ x: point.x - (point.x - previous.x) * ratio,
104
+ y: point.y - (point.y - previous.y) * ratio,
105
+ };
106
+ }
107
+ function scaledDimensions(width, height) {
108
+ return `${Number(width.toFixed(2))} × ${Number(height.toFixed(2))}`;
109
+ }
110
+ function Preview({ page, placement, active, selectedNested, state, onState, }) {
111
+ const ref = useRef(null);
112
+ const [loaded, setLoaded] = useState(false);
113
+ const { frame, x, y } = placement;
114
+ const selector = `${page.projectId}/${page.id}/${frame.id}`;
115
+ useFrameState(ref, loaded || active, onState);
116
+ const path = `/render/${selector}`;
117
+ return (_jsxs("div", { className: active ? "dk-artboard is-active" : "dk-artboard", style: { left: x, top: y, width: frame.width, height: frame.height }, "data-artboard": frame.id, children: [_jsxs("div", { className: "dk-artboard-label", "aria-hidden": "true", children: [frame.name, " \u00B7 ", scaledDimensions(frame.width, frame.height)] }), _jsx("iframe", { ref: ref, title: frame.name, src: path, loading: active ? "eager" : "lazy", onLoad: () => setLoaded(true), tabIndex: -1, width: frame.width, height: frame.height }), selectedNested && (_jsx("div", { className: "dk-nested-outline", style: {
118
+ left: selectedNested.x,
119
+ top: selectedNested.y,
120
+ width: selectedNested.width,
121
+ height: selectedNested.height,
122
+ } })), state?.status === "error" && (_jsx("div", { className: "dk-preview-error", "aria-hidden": "true", children: _jsx(Icon, { name: "warning" }) }))] }));
123
+ }
124
+ function Inspector({ page, frame, nested, state, exportFormat, }) {
125
+ const [format, setFormat] = useState("");
126
+ const [scale, setScale] = useState("1");
127
+ const [overwrite, setOverwrite] = useState(false);
128
+ const [busy, setBusy] = useState(false);
129
+ const [result, setResult] = useState();
130
+ const selected = nested ?? frame;
131
+ const selector = page &&
132
+ frame &&
133
+ [page.projectId, page.id, frame.id, nested?.id].filter(Boolean).join("/");
134
+ const error = state?.error ?? nested?.exportError;
135
+ const canExport = selector && state?.status === "ready" && !error && !busy;
136
+ async function submit(event) {
137
+ event.preventDefault();
138
+ if (!canExport)
139
+ return;
140
+ setBusy(true);
141
+ setResult(undefined);
142
+ const token = document.querySelector('meta[name="designkit-token"]')?.content;
143
+ try {
144
+ const response = await fetch("/api/export", {
145
+ method: "POST",
146
+ headers: {
147
+ "Content-Type": "application/json",
148
+ "x-designkit-token": token ?? "",
149
+ },
150
+ body: JSON.stringify({
151
+ selector,
152
+ overwrite,
153
+ ...(format ? { format, scale: Number(scale) } : {}),
154
+ }),
155
+ });
156
+ const data = (await response.json());
157
+ const files = data.files?.map((file) => file.path) ?? [];
158
+ const errors = data.errors?.map((item) => item.message) ?? [];
159
+ if (!response.ok && !errors.length)
160
+ errors.push(`Export failed (HTTP ${response.status}).`);
161
+ setResult({ files, errors });
162
+ }
163
+ catch (error) {
164
+ setResult({
165
+ files: [],
166
+ errors: [error instanceof Error ? error.message : String(error)],
167
+ });
168
+ }
169
+ finally {
170
+ setBusy(false);
171
+ }
172
+ }
173
+ return (_jsx("aside", { className: "dk-inspector", "aria-label": "Inspector", children: !selected ? (_jsx("p", { className: "dk-empty", children: "Select a frame to view its details." })) : (_jsxs(_Fragment, { children: [_jsxs("section", { className: "dk-inspector-section", children: [_jsx("h2", { className: "dk-panel-title", children: nested ? "Nested frame" : "Frame" }), _jsx("h3", { children: selected.name }), _jsxs("dl", { className: "dk-properties", children: [_jsxs("div", { children: [_jsx("dt", { children: "Dimensions" }), _jsxs("dd", { className: "dk-dimensions", children: [_jsxs("span", { children: [_jsx("abbr", { title: "Width", children: "W" }), " ", selected.width] }), _jsxs("span", { children: [_jsx("abbr", { title: "Height", children: "H" }), " ", selected.height] })] })] }), _jsxs("div", { children: [_jsx("dt", { children: "Selector" }), _jsx("dd", { children: _jsx("code", { children: selector }) })] }), _jsxs("div", { children: [_jsx("dt", { children: "Presets" }), _jsx("dd", { children: selected.exports?.length
174
+ ? selected.exports
175
+ .map((preset) => `${preset.format.toUpperCase()} ${preset.scale}×`)
176
+ .join(", ")
177
+ : "Project default" })] })] }), error && (_jsx("p", { className: "dk-error", role: "alert", children: error })), state?.status !== "ready" && !error && (_jsx("p", { className: "dk-muted", children: "Loading frame\u2026" }))] }), _jsxs("form", { className: "dk-inspector-section dk-export", onSubmit: submit, children: [_jsx("h3", { children: "Export" }), _jsxs("div", { className: "dk-export-settings", children: [_jsxs("label", { children: ["Format", _jsxs("select", { ref: exportFormat, value: format, onChange: (event) => {
178
+ const value = event.target.value;
179
+ if (value === "" ||
180
+ value === "png" ||
181
+ value === "jpeg" ||
182
+ value === "webp")
183
+ setFormat(value);
184
+ }, children: [_jsx("option", { value: "", children: "Presets" }), _jsx("option", { value: "png", children: "PNG" }), _jsx("option", { value: "jpeg", children: "JPEG" }), _jsx("option", { value: "webp", children: "WebP" })] })] }), _jsxs("label", { children: ["Scale", _jsxs("select", { disabled: !format, value: scale, onChange: (event) => setScale(event.target.value), children: [_jsx("option", { value: "1", children: "1\u00D7" }), _jsx("option", { value: "2", children: "2\u00D7" }), _jsx("option", { value: "3", children: "3\u00D7" }), _jsx("option", { value: "4", children: "4\u00D7" })] })] })] }), _jsxs("label", { className: "dk-checkbox", children: [_jsx("input", { type: "checkbox", checked: overwrite, onChange: (event) => setOverwrite(event.target.checked) }), " ", "Replace existing exports"] }), _jsxs("button", { className: "dk-export-button", disabled: !canExport, children: [_jsx(Icon, { name: "export" }), busy ? "Exporting…" : "Export selected"] }), result && (_jsxs("div", { className: "dk-export-result", role: "status", children: [result.files.map((path) => (_jsx("code", { children: path }, path))), result.errors.map((message, i) => (_jsx("p", { className: "dk-error", children: message }, i)))] }))] }), _jsxs("section", { className: "dk-inspector-section dk-source", children: [_jsx("h2", { className: "dk-panel-title", children: "Source" }), _jsx("code", { children: page?.source })] })] })) }));
185
+ }
186
+ function Studio() {
187
+ const registry = useRef(null);
188
+ const canvas = useRef(null);
189
+ const exportFormat = useRef(null);
190
+ const [report, setReport] = useState();
191
+ const [renders, setRenders] = useState({});
192
+ const [selection, setSelection] = useState(() => new URLSearchParams(location.search).get("frame") ?? "");
193
+ const [view, setView] = useState({ x: 0, y: 0, scale: 1 });
194
+ const [isDragging, setDragging] = useState(false);
195
+ const initialFit = useRef(false);
196
+ const drag = useRef(null);
197
+ const projects = report?.registry?.projects ?? [];
198
+ const [projectId, pageId, frameId, nestedId] = selection.split("/");
199
+ const project = projects.find((item) => item.id === projectId) ?? projects[0];
200
+ const pages = project?.pages ?? [];
201
+ const page = pages.find((item) => item.id === pageId) ?? pages[0];
202
+ const positions = useMemo(() => placements(page?.frames ?? []), [page]);
203
+ const requestedRoot = page?.projectId === projectId && page.id === pageId ? frameId : undefined;
204
+ const active = positions.find(({ frame }) => frame.id === requestedRoot) ?? positions[0];
205
+ const activeKey = page && active && `${page.projectId}/${page.id}/${active.frame.id}`;
206
+ const activeState = activeKey ? renders[activeKey] : undefined;
207
+ const selectedNested = active?.frame.id === requestedRoot
208
+ ? activeState?.nested?.find(({ id }) => id === nestedId)
209
+ : undefined;
210
+ useFrameState(registry, true, setReport);
211
+ function fit(bounds, alignTopLeft = false) {
212
+ const element = canvas.current;
213
+ if (!element || bounds.width <= 0 || bounds.height <= 0)
214
+ return;
215
+ const scale = scaleInRange(Math.min((element.clientWidth - 52) / bounds.width, (element.clientHeight - 114) / bounds.height, 1));
216
+ setView({
217
+ scale,
218
+ x: (alignTopLeft ? 26 : (element.clientWidth - bounds.width * scale) / 2) -
219
+ bounds.x * scale,
220
+ y: (alignTopLeft
221
+ ? 62
222
+ : (element.clientHeight - bounds.height * scale) / 2 - 10) -
223
+ bounds.y * scale,
224
+ });
225
+ }
226
+ useEffect(() => {
227
+ if (active && !initialFit.current) {
228
+ initialFit.current = true;
229
+ if (requestedRoot)
230
+ fit(boundsOf(active));
231
+ else
232
+ fit(pageBounds(positions), true);
233
+ }
234
+ }, [active, positions, requestedRoot]);
235
+ function navigate(selector) {
236
+ setSelection(selector);
237
+ const url = new URL(location.href);
238
+ url.searchParams.set("frame", selector);
239
+ history.replaceState(null, "", url);
240
+ }
241
+ function select(nextPage, position, nested, fitFrame = true) {
242
+ navigate([nextPage.projectId, nextPage.id, position?.frame.id, nested?.id]
243
+ .filter(Boolean)
244
+ .join("/"));
245
+ if (fitFrame && position)
246
+ fit(boundsOf(position, nested));
247
+ }
248
+ function zoom(factor) {
249
+ const point = {
250
+ x: (canvas.current?.clientWidth ?? 0) / 2,
251
+ y: (canvas.current?.clientHeight ?? 0) / 2,
252
+ };
253
+ setView((previous) => zoomAt(previous, factor, point));
254
+ }
255
+ useEffect(() => {
256
+ const element = canvas.current;
257
+ if (!element)
258
+ return;
259
+ const handleWheel = (event) => {
260
+ if (event.ctrlKey || event.metaKey) {
261
+ event.preventDefault();
262
+ const { left, top } = element.getBoundingClientRect();
263
+ const point = { x: event.clientX - left, y: event.clientY - top };
264
+ const factor = Math.exp(-event.deltaY * 0.006);
265
+ setView((previous) => zoomAt(previous, factor, point));
266
+ }
267
+ else {
268
+ const unit = event.deltaMode === 1
269
+ ? 16
270
+ : event.deltaMode === 2
271
+ ? element.clientHeight
272
+ : 1;
273
+ setView((previous) => ({
274
+ ...previous,
275
+ x: previous.x - event.deltaX * unit,
276
+ y: previous.y - event.deltaY * unit,
277
+ }));
278
+ }
279
+ };
280
+ element.addEventListener("wheel", handleWheel, { passive: false });
281
+ return () => element.removeEventListener("wheel", handleWheel);
282
+ }, []);
283
+ function fitSelection() {
284
+ if (active)
285
+ fit(boundsOf(active, selectedNested));
286
+ }
287
+ function keyDown(event) {
288
+ if (event.target !== event.currentTarget)
289
+ return;
290
+ const pan = event.shiftKey ? 110 : 45;
291
+ switch (event.key) {
292
+ case "+":
293
+ case "=":
294
+ zoom(1.2);
295
+ break;
296
+ case "-":
297
+ zoom(1 / 1.2);
298
+ break;
299
+ case "0":
300
+ fitSelection();
301
+ break;
302
+ case "ArrowLeft":
303
+ setView((previous) => ({ ...previous, x: previous.x + pan }));
304
+ break;
305
+ case "ArrowRight":
306
+ setView((previous) => ({ ...previous, x: previous.x - pan }));
307
+ break;
308
+ case "ArrowUp":
309
+ setView((previous) => ({ ...previous, y: previous.y + pan }));
310
+ break;
311
+ case "ArrowDown":
312
+ setView((previous) => ({ ...previous, y: previous.y - pan }));
313
+ break;
314
+ default:
315
+ return;
316
+ }
317
+ event.preventDefault();
318
+ }
319
+ function startDrag(event) {
320
+ if (event.button !== 0 && event.button !== 1)
321
+ return;
322
+ const target = event.target;
323
+ if (target.closest("button"))
324
+ return;
325
+ event.currentTarget.focus({ preventScroll: true });
326
+ event.currentTarget.setPointerCapture(event.pointerId);
327
+ drag.current = {
328
+ x: event.clientX,
329
+ y: event.clientY,
330
+ view,
331
+ moved: false,
332
+ frame: target.closest("[data-artboard]")?.dataset.artboard,
333
+ };
334
+ }
335
+ function moveDrag(event) {
336
+ const start = drag.current;
337
+ if (!start)
338
+ return;
339
+ const dx = event.clientX - start.x;
340
+ const dy = event.clientY - start.y;
341
+ if (!start.moved && Math.hypot(dx, dy) < 4)
342
+ return;
343
+ start.moved = true;
344
+ setDragging(true);
345
+ setView({
346
+ scale: start.view.scale,
347
+ x: start.view.x + dx,
348
+ y: start.view.y + dy,
349
+ });
350
+ }
351
+ function endDrag(event) {
352
+ const start = drag.current;
353
+ drag.current = null;
354
+ setDragging(false);
355
+ if (event.type === "pointerup" && page && start?.frame && !start.moved) {
356
+ const position = positions.find(({ frame }) => frame.id === start.frame);
357
+ if (position)
358
+ select(page, position, undefined, false);
359
+ }
360
+ }
361
+ return (_jsxs("div", { className: "dk-shell", children: [_jsx("iframe", { ref: registry, src: "/registry", title: "Design registry", hidden: true }), _jsxs("header", { className: "dk-topbar", children: [_jsxs("div", { className: "dk-wordmark", children: [_jsxs("span", { "aria-hidden": "true", className: "dk-logo", children: [_jsx("i", {}), _jsx("i", {}), _jsx("i", {}), _jsx("i", {})] }), "Designkit"] }), _jsxs("div", { className: "dk-breadcrumb", children: [_jsx("span", { "aria-hidden": "true", children: "/" }), " ", project?.name ?? "Studio", page && (_jsxs(_Fragment, { children: [" ", _jsx("span", { "aria-hidden": "true", children: "/" }), " ", page.name] }))] }), _jsx("button", { className: "dk-header-export dk-export-button", type: "button", disabled: !active, onClick: () => exportFormat.current?.focus(), children: "Export" })] }), _jsxs("nav", { className: "dk-navigation", "aria-label": "Design navigation", children: [_jsx("h2", { className: "dk-panel-title", children: "Projects" }), _jsx("ul", { className: "dk-nav-list", children: projects.map((item) => (_jsx("li", { children: _jsxs("button", { className: "dk-nav-button", "aria-current": item.id === project?.id ? "true" : undefined, onClick: () => {
362
+ navigate(item.id);
363
+ const nextPositions = placements(item.pages[0]?.frames ?? []);
364
+ if (nextPositions.length)
365
+ fit(pageBounds(nextPositions), true);
366
+ }, children: [_jsx(Icon, { name: "project" }), _jsx("span", { children: item.name })] }) }, item.id))) }), project && (_jsxs(_Fragment, { children: [_jsx("h2", { className: "dk-panel-title dk-frames-title", children: "Pages" }), _jsx("ul", { className: "dk-nav-list", children: pages.map((item) => (_jsx("li", { children: _jsxs("button", { className: "dk-nav-button", "aria-current": item.id === page?.id ? "page" : undefined, onClick: () => {
367
+ const nextPositions = placements(item.frames);
368
+ select(item);
369
+ if (nextPositions.length)
370
+ fit(pageBounds(nextPositions), true);
371
+ }, children: [_jsx(Icon, { name: "page" }), _jsx("span", { children: item.name })] }) }, item.id))) })] })), report?.registry?.errors.map((error, i) => (_jsxs("p", { className: "dk-error dk-nav-error", role: "alert", children: [error.source && _jsx("strong", { children: error.source }), error.message] }, i))), report?.error && (_jsx("p", { className: "dk-error dk-nav-error", role: "alert", children: report.error })), page && (_jsxs(_Fragment, { children: [_jsx("h2", { className: "dk-panel-title dk-frames-title", children: "Frames" }), _jsx("ul", { className: "dk-nav-list", children: positions.map((position) => {
372
+ const { frame } = position;
373
+ const state = renders[`${page.projectId}/${page.id}/${frame.id}`];
374
+ const isActive = frame.id === active?.frame.id;
375
+ return (_jsxs("li", { children: [_jsxs("button", { className: "dk-nav-button", "aria-current": isActive && !selectedNested ? "true" : undefined, onClick: () => select(page, position), children: [_jsx(Icon, { name: state?.status === "error" ? "warning" : "frame" }), _jsx("span", { children: frame.name })] }), state?.nested?.length ? (_jsx("ul", { className: "dk-nav-list dk-nested-list", children: state.nested.map((nested) => (_jsx("li", { children: _jsxs("button", { className: "dk-nav-button", "aria-current": isActive && selectedNested?.id === nested.id
376
+ ? "true"
377
+ : undefined, onClick: () => select(page, position, nested), children: [_jsx(Icon, { name: "frame" }), _jsx("span", { children: nested.name })] }) }, nested.id))) })) : null] }, frame.id));
378
+ }) })] }))] }), _jsxs("main", { className: "dk-workspace", children: [_jsx("div", { className: "dk-canvas", ref: canvas, tabIndex: 0, role: "region", "aria-label": "Design canvas. Arrow keys pan, plus and minus zoom, and zero fits the selected frame.", "data-dragging": isDragging || undefined, onKeyDown: keyDown, onPointerDown: startDrag, onPointerMove: moveDrag, onPointerUp: endDrag, onPointerCancel: endDrag, children: page && positions.length ? (_jsx("div", { className: "dk-world", style: {
379
+ transform: `translate(${view.x}px, ${view.y}px) scale(${view.scale})`,
380
+ "--canvas-scale": view.scale,
381
+ "--artboard-outline": `${1.5 / view.scale}px`,
382
+ }, children: positions.map((position) => {
383
+ const key = `${page.projectId}/${page.id}/${position.frame.id}`;
384
+ const isActive = key === activeKey;
385
+ return (_jsx(Preview, { page: page, placement: position, active: isActive, state: renders[key], selectedNested: isActive ? selectedNested : undefined, onState: (state) => setRenders((previous) => ({ ...previous, [key]: state })) }, key));
386
+ }) })) : (_jsx("div", { className: "dk-canvas-empty", children: !report
387
+ ? "Loading designs…"
388
+ : report.status === "error"
389
+ ? "Registry unavailable"
390
+ : page
391
+ ? "No frames on this page"
392
+ : project
393
+ ? "No pages in this project"
394
+ : "No designs found" })) }), _jsxs("div", { className: "dk-canvas-toolbar", "aria-label": "Canvas controls", children: [_jsx("button", { type: "button", title: "Zoom out (\u2212)", "aria-label": "Zoom out", onClick: () => zoom(1 / 1.2), disabled: !active, children: _jsx(Icon, { name: "minus" }) }), _jsxs("output", { "aria-label": "Zoom level", children: [Number((view.scale * 100).toFixed(1)), "%"] }), _jsx("button", { type: "button", title: "Zoom in (+)", "aria-label": "Zoom in", onClick: () => zoom(1.2), disabled: !active, children: _jsx(Icon, { name: "plus" }) }), _jsx("button", { type: "button", title: "Fit selected frame (0)", "aria-label": "Fit selected frame", onClick: fitSelection, disabled: !active, children: _jsx(Icon, { name: "fit" }) })] })] }), _jsx(Inspector, { page: page, frame: active?.frame, nested: selectedNested, state: activeState, exportFormat: exportFormat }, `${activeKey}/${selectedNested?.id}`)] }));
395
+ }
396
+ createRoot(document.getElementById("app")).render(_jsx(Studio, {}));
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "@sashaangelm/designkit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "engines": {
7
+ "node": ">=22.17.0"
8
+ },
9
+ "files": [
10
+ "dist",
11
+ "template",
12
+ "LICENSE",
13
+ "README.md",
14
+ "THIRD_PARTY_NOTICES.md"
15
+ ],
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ },
21
+ "./scaffold": {
22
+ "types": "./dist/scaffold.d.ts",
23
+ "default": "./dist/scaffold.js"
24
+ }
25
+ },
26
+ "peerDependencies": {
27
+ "react": "^19.3.1",
28
+ "react-dom": "^19.3.1"
29
+ },
30
+ "dependencies": {
31
+ "commander": "15.1.0",
32
+ "playwright": "1.65.1",
33
+ "sharp": "0.35.5",
34
+ "vite": "8.4.0",
35
+ "zod": "4.6.7"
36
+ },
37
+ "devDependencies": {
38
+ "@types/react": "19.2.7",
39
+ "@types/react-dom": "19.2.3",
40
+ "react": "19.3.1",
41
+ "react-dom": "19.3.1"
42
+ },
43
+ "bin": {
44
+ "designkit": "./dist/cli.js"
45
+ },
46
+ "description": "Create graphics with React and CSS and export images from the command line.",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/SASHAANGELM/designkit.git",
50
+ "directory": "packages/designkit"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ },
55
+ "scripts": {
56
+ "build": "tsc && node build-assets.mjs",
57
+ "typecheck": "tsc --noEmit"
58
+ }
6
59
  }
@@ -0,0 +1,6 @@
1
+ # Design project instructions
2
+
3
+ - Find artboards with `npm run list -- --json`. Declare them with `<Root>`, `<Project>`, `<Page>`, and `<Frame>` in the app rooted at `designkit.root.tsx`. Put reusable React components in `components/` and CSS or assets in the corresponding project directories.
4
+ - Keep project, page, and frame IDs stable. Root selectors use `project/page/frame` and identified nested frames use `project/page/frame/nested`. Use local assets and keep any font and asset notices.
5
+ - Run `npm run typecheck` and `npm run check -- --json` after editing. Export the selected design with `npm run export -- --frame field-notes/social/launch --json` and inspect the image. Use `--overwrite` only when replacing that output is intended.
6
+ - The source files are authoritative. View the same artboards in Studio with `npm run studio`. Keep generated images in `output/`.
@@ -0,0 +1,21 @@
1
+ # My designs
2
+
3
+ Node 22.17 or newer is required. Install dependencies and run the browser setup once. The sample uses a bundled font and SVG and can render offline after setup.
4
+
5
+ ```sh
6
+ npm install
7
+ npm run setup
8
+ ```
9
+
10
+ ```sh
11
+ npm run list -- --json
12
+ npm run check
13
+ npm run export -- --frame field-notes/social/launch --scale 2
14
+ npm run studio
15
+ ```
16
+
17
+ The export command creates `output/field-notes/social/launch@2x.png` at 2160 × 2160 pixels. Pass `--overwrite` to replace an existing export. Press Ctrl+C to stop Studio.
18
+
19
+ Edit `designs/social.design.tsx` and `styles/social.css` to customize the sample. Open `designkit.root.tsx` to add projects and pages, or import page components from other files. Use `npm run typecheck` to check TypeScript.
20
+
21
+ The starter files and font have separate license notices in [assets](assets/README.md).
@@ -0,0 +1,5 @@
1
+ # Sample assets
2
+
3
+ The Latin Space Grotesk 700 WOFF2 is from [Fontsource Space Grotesk 5.3.0](https://www.npmjs.com/package/@fontsource/space-grotesk/v/5.3.0). The copyright and terms are in [space-grotesk-OFL.txt](space-grotesk-OFL.txt).
4
+
5
+ The included SVG and other original starter files use the [Designkit starter MIT license](designkit-starter-MIT.txt).
@@ -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.
@@ -0,0 +1,33 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 850 720">
2
+ <defs>
3
+ <pattern id="grid" width="36" height="36" patternUnits="userSpaceOnUse">
4
+ <path d="M 0 36 V 0 H 36" fill="none" stroke="#527b64" stroke-opacity=".48"/>
5
+ </pattern>
6
+ <radialGradient id="fade">
7
+ <stop stop-color="white"/>
8
+ <stop offset="1" stop-color="white" stop-opacity="0"/>
9
+ </radialGradient>
10
+ <mask id="grid-fade">
11
+ <rect width="850" height="720" fill="url(#fade)"/>
12
+ </mask>
13
+ </defs>
14
+ <rect width="850" height="720" fill="url(#grid)" mask="url(#grid-fade)"/>
15
+ <g transform="translate(455 344) rotate(-33)">
16
+ <g fill="none" stroke="#8cc68b" stroke-width="1.4">
17
+ <ellipse rx="298" ry="220"/>
18
+ <ellipse rx="298" ry="177"/>
19
+ <ellipse rx="298" ry="122"/>
20
+ <ellipse rx="298" ry="62"/>
21
+ <ellipse rx="253" ry="220"/>
22
+ <ellipse rx="184" ry="220"/>
23
+ <ellipse rx="101" ry="220"/>
24
+ <path d="M-298 0H298M0-220V220"/>
25
+ </g>
26
+ <g fill="#d3fba1">
27
+ <circle cx="-298" r="8"/>
28
+ <circle cx="184" r="8"/>
29
+ <circle cy="-220" r="7"/>
30
+ <circle cx="234" cy="105" r="6"/>
31
+ </g>
32
+ </g>
33
+ </svg>
@@ -0,0 +1,93 @@
1
+ Copyright 2020 The Space Grotesk Project Authors (https://github.com/floriankarsten/space-grotesk)
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.