@mgamadeus/ddd-design-studio 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +376 -2
- package/dist/canvas/index.d.ts +18 -0
- package/dist/canvas/index.js +3120 -0
- package/dist/canvas/index.js.map +1 -0
- package/dist/chunk-ICDABLFY.js +197 -0
- package/dist/chunk-ICDABLFY.js.map +1 -0
- package/dist/index.d.ts +866 -0
- package/dist/index.js +468 -0
- package/dist/index.js.map +1 -0
- package/package.json +83 -3
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// src/canvas/designReference.ts
|
|
4
|
+
var DESIGN_REFERENCE_PREFIX = "[design-ref]";
|
|
5
|
+
var oneLine = (text) => text.replace(/\s+/g, " ").trim();
|
|
6
|
+
var buildDesignReference = (input) => {
|
|
7
|
+
const fields = [
|
|
8
|
+
`${DESIGN_REFERENCE_PREFIX} ${oneLine(input.projectName)} \u203A ${oneLine(input.canvasName)} \u203A ${oneLine(input.boardTitle)}`,
|
|
9
|
+
...input.boardCode ? [`code ${oneLine(input.boardCode)}`] : [],
|
|
10
|
+
`file ${input.boardKey}`,
|
|
11
|
+
`canvas ${input.projectKey}/${input.canvasKey}`,
|
|
12
|
+
`v${input.contentHash ? input.contentHash.slice(0, 7) : "?"}`,
|
|
13
|
+
`theme ${input.themeReference || "none"}`
|
|
14
|
+
];
|
|
15
|
+
if (input.region) {
|
|
16
|
+
const { x, y, width, height } = input.region;
|
|
17
|
+
fields.push(`region ${Math.round(x)},${Math.round(y)},${Math.round(width)},${Math.round(height)}`);
|
|
18
|
+
}
|
|
19
|
+
if (input.comment) {
|
|
20
|
+
const position = input.comment.x != null && input.comment.y != null ? ` at ${Math.round(input.comment.x)},${Math.round(input.comment.y)}` : "";
|
|
21
|
+
fields.push(`comment ${input.comment.id}${position}`);
|
|
22
|
+
}
|
|
23
|
+
fields.push(input.url);
|
|
24
|
+
const lines = [fields.join(" \xB7 ")];
|
|
25
|
+
for (const commentLine of input.comment?.lines ?? []) {
|
|
26
|
+
if (commentLine.trim()) lines.push(`comment: ${oneLine(commentLine)}`);
|
|
27
|
+
}
|
|
28
|
+
if (input.note?.trim()) lines.push(`note: ${oneLine(input.note)}`);
|
|
29
|
+
return lines.join("\n");
|
|
30
|
+
};
|
|
31
|
+
var buildBoardDeepLink = (pageUrl, boardKey, themeId, mode, viewport) => {
|
|
32
|
+
const url = new URL(pageUrl);
|
|
33
|
+
url.search = "";
|
|
34
|
+
url.hash = "";
|
|
35
|
+
url.searchParams.set("board", boardKey);
|
|
36
|
+
if (themeId) {
|
|
37
|
+
url.searchParams.set("theme", themeId);
|
|
38
|
+
url.searchParams.set("mode", mode);
|
|
39
|
+
}
|
|
40
|
+
if (viewport) url.searchParams.set("vp", viewport);
|
|
41
|
+
return url.toString().replace(/%2C/gi, ",").replace(/%3A/gi, ":");
|
|
42
|
+
};
|
|
43
|
+
var copyTextToClipboard = async (text) => {
|
|
44
|
+
if (typeof navigator !== "undefined" && navigator.clipboard?.writeText) {
|
|
45
|
+
try {
|
|
46
|
+
await navigator.clipboard.writeText(text);
|
|
47
|
+
return true;
|
|
48
|
+
} catch {
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (typeof document === "undefined") return false;
|
|
52
|
+
const textarea = document.createElement("textarea");
|
|
53
|
+
textarea.value = text;
|
|
54
|
+
textarea.setAttribute("readonly", "");
|
|
55
|
+
textarea.style.position = "fixed";
|
|
56
|
+
textarea.style.opacity = "0";
|
|
57
|
+
document.body.appendChild(textarea);
|
|
58
|
+
textarea.select();
|
|
59
|
+
const isCopied = document.execCommand("copy");
|
|
60
|
+
textarea.remove();
|
|
61
|
+
return isCopied;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/canvas/boardKey.ts
|
|
65
|
+
var boardCodeOf = (boardKey) => boardKey.replace(/(?:\.dc)?\.html$/, "");
|
|
66
|
+
|
|
67
|
+
// src/canvas/boardCode.ts
|
|
68
|
+
var CODE_PARAM = "code";
|
|
69
|
+
var normalizeBoardCode = (code) => code.toUpperCase().replace(/[^A-Z0-9]/g, "");
|
|
70
|
+
var codeParts = (code) => code.trim().toUpperCase().split(/[\s-]+/).filter(Boolean);
|
|
71
|
+
var boardCodeMatches = (typedCode, boardCode) => {
|
|
72
|
+
const typed = normalizeBoardCode(typedCode);
|
|
73
|
+
if (!typed || !boardCode) return false;
|
|
74
|
+
const parts = codeParts(boardCode);
|
|
75
|
+
return parts.some((_, index) => parts.slice(index).join("") === typed);
|
|
76
|
+
};
|
|
77
|
+
var codeBelongsToCanvas = (typedCode, canvasCode) => {
|
|
78
|
+
const typed = normalizeBoardCode(typedCode);
|
|
79
|
+
if (!typed || !canvasCode) return false;
|
|
80
|
+
const parts = codeParts(canvasCode);
|
|
81
|
+
return parts.some((_, index) => {
|
|
82
|
+
const prefix = parts.slice(index).join("");
|
|
83
|
+
return typed.length > prefix.length && typed.startsWith(prefix);
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
var boardCodeUrlValue = (code) => codeParts(code).join("-");
|
|
87
|
+
var buildBoardCodeLink = (canvasPageUrl, code, themeId, mode) => {
|
|
88
|
+
const url = new URL(canvasPageUrl);
|
|
89
|
+
url.search = "";
|
|
90
|
+
url.hash = "";
|
|
91
|
+
url.searchParams.set(CODE_PARAM, boardCodeUrlValue(code));
|
|
92
|
+
if (themeId) {
|
|
93
|
+
url.searchParams.set("theme", themeId);
|
|
94
|
+
url.searchParams.set("mode", mode);
|
|
95
|
+
}
|
|
96
|
+
return url.toString().replace(/%3A/gi, ":");
|
|
97
|
+
};
|
|
98
|
+
var findBoardForCode = (boards, typedCode) => {
|
|
99
|
+
const byCode = boards.filter((board) => boardCodeMatches(typedCode, board.code));
|
|
100
|
+
if (byCode.length > 0) return byCode.length === 1 ? byCode[0] : null;
|
|
101
|
+
const typed = typedCode.trim().toLowerCase();
|
|
102
|
+
const byName = boards.filter((board) => board.boardKey && boardCodeOf(board.boardKey).toLowerCase() === typed);
|
|
103
|
+
return byName.length === 1 ? byName[0] : null;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// src/canvas/designTheme.ts
|
|
107
|
+
var splitThemeReference = (themeReference) => {
|
|
108
|
+
const reference = (themeReference ?? "").trim();
|
|
109
|
+
if (!reference) return null;
|
|
110
|
+
for (const mode of ["light", "dark"]) {
|
|
111
|
+
if (reference.endsWith(`:${mode}`)) return { themeId: reference.slice(0, -(mode.length + 1)), mode };
|
|
112
|
+
}
|
|
113
|
+
return { themeId: reference, mode: "light" };
|
|
114
|
+
};
|
|
115
|
+
var buildThemeReference = (themeId, mode) => mode === "dark" ? `${themeId}:dark` : themeId;
|
|
116
|
+
|
|
117
|
+
// src/provider/texts.ts
|
|
118
|
+
var DEFAULT_DESIGN_STUDIO_TEXTS = {
|
|
119
|
+
referencesCopied: (count) => count > 1 ? `References copied (${count})` : "Reference copied",
|
|
120
|
+
boardsUpdated: (count) => count === 1 ? "1 board updated" : `${count} boards updated`,
|
|
121
|
+
showUpdatedBoard: "Show",
|
|
122
|
+
canvasUpToDate: "Canvas is up to date",
|
|
123
|
+
reload: "Reload (R)",
|
|
124
|
+
thumbnailsFailed: "Thumbnails failed \xB7 try again",
|
|
125
|
+
thumbnailsWaitingForRenderer: (themeLabel) => `Thumbnails for ${themeLabel} are waiting for the renderer`,
|
|
126
|
+
thumbnailsRendering: (themeLabel) => `Thumbnails for ${themeLabel} are being rendered`,
|
|
127
|
+
thumbnailsFallbackThemeLabel: "this look",
|
|
128
|
+
thumbnailsMissing: (count) => count === 1 ? "1 board has no thumbnail in this look yet; it appears as soon as it is rendered." : `${count} boards have no thumbnail in this look yet; they appear as soon as they are rendered.`,
|
|
129
|
+
thumbnailsLastError: (error) => `Last error: ${error}`,
|
|
130
|
+
themeWithoutDarkMode: "This theme has no dark mode",
|
|
131
|
+
thumbnailMissing: "No thumbnail yet",
|
|
132
|
+
referenceNotePlaceholder: "What should change? (optional, goes into the reference)",
|
|
133
|
+
boardCodeNotFound: (code) => `No board has the code ${code}`,
|
|
134
|
+
boardLinkCopied: (code) => `Link to ${code} copied`,
|
|
135
|
+
copyBoardLink: "Copy link"
|
|
136
|
+
};
|
|
137
|
+
var resolveDesignStudioTexts = (texts) => {
|
|
138
|
+
if (!texts) return DEFAULT_DESIGN_STUDIO_TEXTS;
|
|
139
|
+
const defined = Object.fromEntries(Object.entries(texts).filter(([, value]) => value !== void 0));
|
|
140
|
+
return { ...DEFAULT_DESIGN_STUDIO_TEXTS, ...defined };
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// src/provider/DesignStudioProvider.tsx
|
|
144
|
+
import { createContext, useContext, useMemo } from "react";
|
|
145
|
+
import { jsx } from "react/jsx-runtime";
|
|
146
|
+
var DesignStudioContext = createContext(null);
|
|
147
|
+
var DesignStudioProvider = ({ environment, children }) => /* @__PURE__ */ jsx(DesignStudioContext.Provider, { value: environment, children });
|
|
148
|
+
var useDesignStudio = () => {
|
|
149
|
+
const environment = useContext(DesignStudioContext);
|
|
150
|
+
if (!environment) {
|
|
151
|
+
throw new Error("The design studio needs a DesignStudioProvider above it");
|
|
152
|
+
}
|
|
153
|
+
return environment;
|
|
154
|
+
};
|
|
155
|
+
var useDesignStudioApi = () => useDesignStudio().api;
|
|
156
|
+
var useDesignStudioComponents = () => useDesignStudio().components;
|
|
157
|
+
var useDesignStudioRouter = () => useDesignStudio().router;
|
|
158
|
+
var useDesignStudioPaths = () => useDesignStudio().paths;
|
|
159
|
+
var useDesignStudioNotify = () => useDesignStudio().notify;
|
|
160
|
+
var useDesignStudioTexts = () => {
|
|
161
|
+
const { texts } = useDesignStudio();
|
|
162
|
+
return useMemo(() => resolveDesignStudioTexts(texts), [texts]);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// src/utils/cx.ts
|
|
166
|
+
import { clsx } from "clsx";
|
|
167
|
+
import { twMerge } from "tailwind-merge";
|
|
168
|
+
var cx = (...inputs) => twMerge(clsx(inputs));
|
|
169
|
+
|
|
170
|
+
export {
|
|
171
|
+
DESIGN_REFERENCE_PREFIX,
|
|
172
|
+
buildDesignReference,
|
|
173
|
+
buildBoardDeepLink,
|
|
174
|
+
copyTextToClipboard,
|
|
175
|
+
boardCodeOf,
|
|
176
|
+
CODE_PARAM,
|
|
177
|
+
normalizeBoardCode,
|
|
178
|
+
boardCodeMatches,
|
|
179
|
+
codeBelongsToCanvas,
|
|
180
|
+
boardCodeUrlValue,
|
|
181
|
+
buildBoardCodeLink,
|
|
182
|
+
findBoardForCode,
|
|
183
|
+
splitThemeReference,
|
|
184
|
+
buildThemeReference,
|
|
185
|
+
DEFAULT_DESIGN_STUDIO_TEXTS,
|
|
186
|
+
resolveDesignStudioTexts,
|
|
187
|
+
DesignStudioProvider,
|
|
188
|
+
useDesignStudio,
|
|
189
|
+
useDesignStudioApi,
|
|
190
|
+
useDesignStudioComponents,
|
|
191
|
+
useDesignStudioRouter,
|
|
192
|
+
useDesignStudioPaths,
|
|
193
|
+
useDesignStudioNotify,
|
|
194
|
+
useDesignStudioTexts,
|
|
195
|
+
cx
|
|
196
|
+
};
|
|
197
|
+
//# sourceMappingURL=chunk-ICDABLFY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/canvas/designReference.ts","../src/canvas/boardKey.ts","../src/canvas/boardCode.ts","../src/canvas/designTheme.ts","../src/provider/texts.ts","../src/provider/DesignStudioProvider.tsx","../src/utils/cx.ts"],"sourcesContent":["/**\n * Design references for agentic editing (\"send to agent\"): a plain-text block that names one\n * board (and optionally a region of it, a comment, a note) with stable keys, so an agent session can resolve it.\n * Format (one line per board, fields joined by \" · \", the deep link always last; optional\n * extra lines below):\n *\n * [design-ref] App › Onboarding – first run › 2 Welcome · code APP ONB-W2 · file onb-w-2-welcome.dc.html · canvas app/onboarding\n * · v3f9c2ab · theme brand:1:dark · region 24,180,342,220\n * · https://…/app/canvases/onboarding?board=onb-w-2-welcome.dc.html&theme=brand:1&mode=dark\n * note: make the tab bar more compact\n *\n * `code` is the board code (left out when the board has none), `file` the board key (the file name in the canvas folder), `v…` the first 7 characters of the board file's\n * content hash (git blob hash), `theme` the theme reference the board was looked at in (`none` = as authored).\n *\n * Pure functions, no React (tested in designReference.test.ts).\n */\n\nexport const DESIGN_REFERENCE_PREFIX = '[design-ref]';\n\n/** A rectangle on a board in board pixels (independent of the zoom). */\nexport interface BoardRegion {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nexport interface DesignReferenceInput {\n projectName: string;\n canvasName: string;\n projectKey: string;\n canvasKey: string;\n boardTitle: string;\n /** File name of the board in the canvas folder. */\n boardKey: string;\n /** Board code (`APP ONB-W2`), null / absent = the board has none. */\n boardCode?: string | null;\n /** Content hash of the board file (git blob hash); the reference carries its first 7 characters. */\n contentHash: string | null;\n /** Theme reference the board is shown in (`<themeId>` or `<themeId>:dark`), null = as authored. */\n themeReference: string | null;\n /** Deep link to the board on the canvas (with theme and mode). */\n url: string;\n region?: BoardRegion | null;\n /** A comment thread the reference is about (id + pin position). */\n comment?: { id: number | string; x: number | null; y: number | null; lines: string[] } | null;\n /** What should change (free text). */\n note?: string | null;\n}\n\nconst oneLine = (text: string) => text.replace(/\\s+/g, ' ').trim();\n\n/** One reference block (first line + optional `comment:` / `note:` lines). */\nexport const buildDesignReference = (input: DesignReferenceInput): string => {\n const fields = [\n `${DESIGN_REFERENCE_PREFIX} ${oneLine(input.projectName)} › ${oneLine(input.canvasName)} › ${oneLine(input.boardTitle)}`,\n ...(input.boardCode ? [`code ${oneLine(input.boardCode)}`] : []),\n `file ${input.boardKey}`,\n `canvas ${input.projectKey}/${input.canvasKey}`,\n `v${input.contentHash ? input.contentHash.slice(0, 7) : '?'}`,\n `theme ${input.themeReference || 'none'}`,\n ];\n if (input.region) {\n const { x, y, width, height } = input.region;\n fields.push(`region ${Math.round(x)},${Math.round(y)},${Math.round(width)},${Math.round(height)}`);\n }\n if (input.comment) {\n const position =\n input.comment.x != null && input.comment.y != null\n ? ` at ${Math.round(input.comment.x)},${Math.round(input.comment.y)}`\n : '';\n fields.push(`comment ${input.comment.id}${position}`);\n }\n fields.push(input.url);\n const lines = [fields.join(' · ')];\n for (const commentLine of input.comment?.lines ?? []) {\n if (commentLine.trim()) lines.push(`comment: ${oneLine(commentLine)}`);\n }\n if (input.note?.trim()) lines.push(`note: ${oneLine(input.note)}`);\n return lines.join('\\n');\n};\n\n/**\n * Deep link to a board: the current page URL with `board` (the board key), the look (`theme`, `mode`; left out when\n * the board is shown as authored) and, when given, the canvas viewport `vp` (other canvas parameters dropped) — the\n * link reopens the focus view over the same part of the canvas.\n */\nexport const buildBoardDeepLink = (\n pageUrl: string,\n boardKey: string,\n themeId: string | null,\n mode: 'light' | 'dark',\n viewport?: string | null\n): string => {\n const url = new URL(pageUrl);\n url.search = '';\n url.hash = '';\n url.searchParams.set('board', boardKey);\n if (themeId) {\n url.searchParams.set('theme', themeId);\n url.searchParams.set('mode', mode);\n }\n if (viewport) url.searchParams.set('vp', viewport);\n // commas and colons are valid in a query; unescaped, the viewport and the theme stay readable in a pasted reference\n return url.toString().replace(/%2C/gi, ',').replace(/%3A/gi, ':');\n};\n\n/**\n * Copies text: the async Clipboard API, else a hidden textarea + `execCommand('copy')` (older browsers, insecure\n * origins).\n * @returns whether the text reached the clipboard\n */\nexport const copyTextToClipboard = async (text: string): Promise<boolean> => {\n if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) {\n try {\n await navigator.clipboard.writeText(text);\n return true;\n } catch {\n // fall through to the textarea fallback (permission denied, document not focused)\n }\n }\n if (typeof document === 'undefined') return false;\n const textarea = document.createElement('textarea');\n textarea.value = text;\n textarea.setAttribute('readonly', '');\n textarea.style.position = 'fixed';\n textarea.style.opacity = '0';\n document.body.appendChild(textarea);\n textarea.select();\n const isCopied = document.execCommand('copy');\n textarea.remove();\n return isCopied;\n};\n","/**\n * A board's code: its key (the file name in the canvas folder) without the `.html` extension and without an optional\n * `.dc` before it (`welcome.html` and `welcome.dc.html` both give `welcome`). Shown under the title and used as the\n * base name of downloads. A key without `.html` is returned as it is.\n */\nexport const boardCodeOf = (boardKey: string): string => boardKey.replace(/(?:\\.dc)?\\.html$/, '');\n","/**\n * Board codes (`APP ONB-W2`): the short name of a board that people say in a chat or paste into the studio. The\n * backend sets them (project code + canvas code + a board part from the file name or canvas.json); here they are\n * matched and turned into links. A code link opens the canvas on that board: the view moves to it, the board is\n * selected and its side panel shows.\n *\n * Pure functions, no React (tested in boardCode.test.ts).\n */\n\nimport { boardCodeOf } from './boardKey.ts';\n\n/** URL parameter of a code link (`?code=APP-ONB-W2`). */\nexport const CODE_PARAM = 'code';\n\n/** A code for comparisons: upper case, letters and digits only (`app onb-w2` → `APPONBW2`). */\nexport const normalizeBoardCode = (code: string): string => code.toUpperCase().replace(/[^A-Z0-9]/g, '');\n\n/** The parts of a code: `APP ONB-W2` → `['APP', 'ONB', 'W2']`. */\nconst codeParts = (code: string): string[] => code.trim().toUpperCase().split(/[\\s-]+/).filter(Boolean);\n\n/**\n * Whether a typed code names a board on its canvas: the full code, the code without the project part, or the board\n * part alone (`APP ONB-W2`, `ONB-W2`, `w2`) — case, spaces and dashes do not matter, a fragment (`2`, `NBW2`) does not\n * match.\n */\nexport const boardCodeMatches = (typedCode: string, boardCode: string | null | undefined): boolean => {\n const typed = normalizeBoardCode(typedCode);\n if (!typed || !boardCode) return false;\n const parts = codeParts(boardCode);\n return parts.some((_, index) => parts.slice(index).join('') === typed);\n};\n\n/**\n * Whether a typed code belongs to a canvas: it starts with the canvas' code prefix, with or without the project part\n * (`APP ONB-W2` and `ONB-W2` belong to `APP ONB`). Used by the overview to send a pasted code to its canvas.\n */\nexport const codeBelongsToCanvas = (typedCode: string, canvasCode: string | null | undefined): boolean => {\n const typed = normalizeBoardCode(typedCode);\n if (!typed || !canvasCode) return false;\n const parts = codeParts(canvasCode);\n return parts.some((_, index) => {\n const prefix = parts.slice(index).join('');\n return typed.length > prefix.length && typed.startsWith(prefix);\n });\n};\n\n/** A code as a URL value: parts joined by dashes (`APP ONB-W2` → `APP-ONB-W2`), readable in a pasted link. */\nexport const boardCodeUrlValue = (code: string): string => codeParts(code).join('-');\n\n/**\n * Link that opens a canvas on one board by its code: the canvas page URL (other parameters dropped) with `code`,\n * plus the look (`theme`, `mode`) when the board is shown in one.\n */\nexport const buildBoardCodeLink = (\n canvasPageUrl: string,\n code: string,\n themeId: string | null,\n mode: 'light' | 'dark'\n): string => {\n const url = new URL(canvasPageUrl);\n url.search = '';\n url.hash = '';\n url.searchParams.set(CODE_PARAM, boardCodeUrlValue(code));\n if (themeId) {\n url.searchParams.set('theme', themeId);\n url.searchParams.set('mode', mode);\n }\n return url.toString().replace(/%3A/gi, ':');\n};\n\n/**\n * The board a typed code names on a canvas: by its code (`boardCodeMatches`), else by its file name without extension\n * (`onb-w-2-welcome`, for boards without a code). Null when none or more than one board matches.\n */\nexport const findBoardForCode = <Board extends { code?: string | null; boardKey?: string | null }>(\n boards: readonly Board[],\n typedCode: string\n): Board | null => {\n const byCode = boards.filter(board => boardCodeMatches(typedCode, board.code));\n if (byCode.length > 0) return byCode.length === 1 ? byCode[0] : null;\n const typed = typedCode.trim().toLowerCase();\n const byName = boards.filter(board => board.boardKey && boardCodeOf(board.boardKey).toLowerCase() === typed);\n return byName.length === 1 ? byName[0] : null;\n};\n","/**\n * Theme references of the design studio: `<themeId>` or `<themeId>:<mode>` (mode `light` or `dark`), e.g.\n * `brand:1:dark` — the theme id itself may contain colons, only a trailing `:light` / `:dark` is the mode (same rule\n * as `DesignThemeReference::fromString`). Pure functions, no React (tested in designTheme.test.ts).\n */\n\nexport type ThemeMode = 'light' | 'dark';\n\nexport interface ThemeLook {\n themeId: string;\n mode: ThemeMode;\n}\n\n/** Splits a theme reference; null without one (the boards are shown as authored). */\nexport const splitThemeReference = (themeReference: string | null | undefined): ThemeLook | null => {\n const reference = (themeReference ?? '').trim();\n if (!reference) return null;\n for (const mode of ['light', 'dark'] as const) {\n if (reference.endsWith(`:${mode}`)) return { themeId: reference.slice(0, -(mode.length + 1)), mode };\n }\n return { themeId: reference, mode: 'light' };\n};\n\n/** `<themeId>` for light, `<themeId>:dark` for dark. */\nexport const buildThemeReference = (themeId: string, mode: ThemeMode): string =>\n mode === 'dark' ? `${themeId}:dark` : themeId;\n","import type { DesignStudioTexts } from './types';\n\n/** The English defaults of the texts an application can replace through `environment.texts`. */\nexport const DEFAULT_DESIGN_STUDIO_TEXTS: DesignStudioTexts = {\n referencesCopied: count => (count > 1 ? `References copied (${count})` : 'Reference copied'),\n boardsUpdated: count => (count === 1 ? '1 board updated' : `${count} boards updated`),\n showUpdatedBoard: 'Show',\n canvasUpToDate: 'Canvas is up to date',\n reload: 'Reload (R)',\n thumbnailsFailed: 'Thumbnails failed · try again',\n thumbnailsWaitingForRenderer: themeLabel => `Thumbnails for ${themeLabel} are waiting for the renderer`,\n thumbnailsRendering: themeLabel => `Thumbnails for ${themeLabel} are being rendered`,\n thumbnailsFallbackThemeLabel: 'this look',\n thumbnailsMissing: count =>\n count === 1\n ? '1 board has no thumbnail in this look yet; it appears as soon as it is rendered.'\n : `${count} boards have no thumbnail in this look yet; they appear as soon as they are rendered.`,\n thumbnailsLastError: error => `Last error: ${error}`,\n themeWithoutDarkMode: 'This theme has no dark mode',\n thumbnailMissing: 'No thumbnail yet',\n referenceNotePlaceholder: 'What should change? (optional, goes into the reference)',\n boardCodeNotFound: code => `No board has the code ${code}`,\n boardLinkCopied: code => `Link to ${code} copied`,\n copyBoardLink: 'Copy link',\n};\n\n/** The defaults with the application's replacements on top; an entry that is missing or `undefined` keeps its default. */\nexport const resolveDesignStudioTexts = (texts: Partial<DesignStudioTexts> | undefined): DesignStudioTexts => {\n if (!texts) return DEFAULT_DESIGN_STUDIO_TEXTS;\n const defined = Object.fromEntries(Object.entries(texts).filter(([, value]) => value !== undefined));\n return { ...DEFAULT_DESIGN_STUDIO_TEXTS, ...defined };\n};\n","'use client';\n\nimport { createContext, type ReactNode, useContext, useMemo } from 'react';\n\nimport type { DesignStudioApi } from '../api/createDesignStudioApi';\nimport { resolveDesignStudioTexts } from './texts';\nimport type {\n DesignStudioComponents,\n DesignStudioEnvironment,\n DesignStudioNotify,\n DesignStudioPaths,\n DesignStudioRouter,\n DesignStudioTexts,\n} from './types';\n\nconst DesignStudioContext = createContext<DesignStudioEnvironment | null>(null);\n\nexport interface DesignStudioProviderProps {\n /** Keep it referentially stable (a module constant): every studio component reads it. */\n environment: DesignStudioEnvironment;\n children: ReactNode;\n}\n\n/** Hands the application's environment (API, router, UI primitives, …) to the studio's screens below it. */\nexport const DesignStudioProvider = ({ environment, children }: DesignStudioProviderProps) => (\n <DesignStudioContext.Provider value={environment}>{children}</DesignStudioContext.Provider>\n);\n\n/** The whole environment. */\nexport const useDesignStudio = (): DesignStudioEnvironment => {\n const environment = useContext(DesignStudioContext);\n if (!environment) {\n throw new Error('The design studio needs a DesignStudioProvider above it');\n }\n return environment;\n};\n\nexport const useDesignStudioApi = (): DesignStudioApi => useDesignStudio().api;\n\nexport const useDesignStudioComponents = (): DesignStudioComponents => useDesignStudio().components;\n\nexport const useDesignStudioRouter = (): DesignStudioRouter => useDesignStudio().router;\n\nexport const useDesignStudioPaths = (): DesignStudioPaths => useDesignStudio().paths;\n\nexport const useDesignStudioNotify = (): DesignStudioNotify => useDesignStudio().notify;\n\n/** The UI texts: the application's replacements (`environment.texts`) on top of the English defaults. Stable per environment. */\nexport const useDesignStudioTexts = (): DesignStudioTexts => {\n const { texts } = useDesignStudio();\n return useMemo(() => resolveDesignStudioTexts(texts), [texts]);\n};\n","import { type ClassValue, clsx } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\n/** Conditional class names, later Tailwind classes winning over earlier ones (`clsx` + `tailwind-merge`). */\nexport const cx = (...inputs: ClassValue[]): string => twMerge(clsx(inputs));\n"],"mappings":";;;AAiBO,IAAM,0BAA0B;AAiCvC,IAAM,UAAU,CAAC,SAAiB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