@razorwind/sandpack 0.0.2
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 +201 -0
- package/README.md +342 -0
- package/dist/index.cjs +66 -0
- package/dist/index.d.cts +328 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +328 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +67 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +80 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { flattenTokens, formatTokenValue, resolveTokenSets, toCssVar } from "@razorwind/core/utils";
|
|
2
|
+
import { GeneratorFunctionResult } from "@power-plant/core";
|
|
3
|
+
import { Component, ComponentUsage, Components, Schema, Tokens } from "@razorwind/core/schema";
|
|
4
|
+
import { TokenType } from "@power-plant/dtcg-schema";
|
|
5
|
+
//#region src/types.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* A flattened design token ready for Sandpack theme mapping.
|
|
8
|
+
*/
|
|
9
|
+
interface FlatToken {
|
|
10
|
+
/** Dot-separated token path (e.g. `color.primary`). */
|
|
11
|
+
path: string;
|
|
12
|
+
/** DTCG `$type`, when known. */
|
|
13
|
+
type?: TokenType | string;
|
|
14
|
+
/** Raw `$value` from the token document. */
|
|
15
|
+
value: unknown;
|
|
16
|
+
/** CSS-friendly string form of {@link value}. */
|
|
17
|
+
cssValue: string;
|
|
18
|
+
/** Optional DTCG `$description`. */
|
|
19
|
+
description?: string;
|
|
20
|
+
/** Theme / set id when tokens are a `Record<string, Tokens>`. */
|
|
21
|
+
theme?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Syntax style token for Sandpack themes.
|
|
25
|
+
*
|
|
26
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
27
|
+
*/
|
|
28
|
+
interface SandpackSyntaxStyle {
|
|
29
|
+
color?: string;
|
|
30
|
+
fontStyle?: "normal" | "italic";
|
|
31
|
+
fontWeight?: "normal" | "bold" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900";
|
|
32
|
+
textDecoration?: "none" | "underline" | "line-through" | "underline line-through";
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Sandpack UI color tokens (`theme.colors`).
|
|
36
|
+
*
|
|
37
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
38
|
+
*/
|
|
39
|
+
interface SandpackThemeColors {
|
|
40
|
+
surface1?: string;
|
|
41
|
+
surface2?: string;
|
|
42
|
+
surface3?: string;
|
|
43
|
+
disabled?: string;
|
|
44
|
+
base?: string;
|
|
45
|
+
clickable?: string;
|
|
46
|
+
hover?: string;
|
|
47
|
+
accent?: string;
|
|
48
|
+
error?: string;
|
|
49
|
+
errorSurface?: string;
|
|
50
|
+
warning?: string;
|
|
51
|
+
warningSurface?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Sandpack syntax highlight tokens (`theme.syntax`).
|
|
55
|
+
*
|
|
56
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
57
|
+
*/
|
|
58
|
+
interface SandpackThemeSyntax {
|
|
59
|
+
plain?: string | SandpackSyntaxStyle;
|
|
60
|
+
comment?: string | SandpackSyntaxStyle;
|
|
61
|
+
keyword?: string | SandpackSyntaxStyle;
|
|
62
|
+
definition?: string | SandpackSyntaxStyle;
|
|
63
|
+
punctuation?: string | SandpackSyntaxStyle;
|
|
64
|
+
property?: string | SandpackSyntaxStyle;
|
|
65
|
+
tag?: string | SandpackSyntaxStyle;
|
|
66
|
+
static?: string | SandpackSyntaxStyle;
|
|
67
|
+
string?: string | SandpackSyntaxStyle;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Sandpack typography tokens (`theme.font`).
|
|
71
|
+
*
|
|
72
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
73
|
+
*/
|
|
74
|
+
interface SandpackThemeFont {
|
|
75
|
+
body?: string;
|
|
76
|
+
mono?: string;
|
|
77
|
+
size?: string;
|
|
78
|
+
lineHeight?: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Sandpack custom theme document.
|
|
82
|
+
*
|
|
83
|
+
* Pass the emitted JSON (minus Razorwind `name` / `displayName`) to
|
|
84
|
+
* `<Sandpack theme={...} />`. Partial objects override the default light theme.
|
|
85
|
+
*
|
|
86
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
87
|
+
*/
|
|
88
|
+
interface SandpackTheme {
|
|
89
|
+
/** Stable theme id — used for the theme file name. */
|
|
90
|
+
name: string;
|
|
91
|
+
/** Human-readable label for INSTALL.md. Defaults to {@link name}. */
|
|
92
|
+
displayName?: string;
|
|
93
|
+
colors?: SandpackThemeColors;
|
|
94
|
+
syntax?: SandpackThemeSyntax;
|
|
95
|
+
font?: SandpackThemeFont;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Map extracted design tokens to one or more Sandpack theme documents.
|
|
99
|
+
*
|
|
100
|
+
* Return a single theme, an array, or a record keyed by theme id.
|
|
101
|
+
*/
|
|
102
|
+
type GenerateSandpackTheme = (tokens: Tokens | Record<string, Tokens>) => SandpackTheme | SandpackTheme[] | Record<string, SandpackTheme>;
|
|
103
|
+
/**
|
|
104
|
+
* A single Sandpack file entry for the `files` prop.
|
|
105
|
+
*
|
|
106
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
107
|
+
*/
|
|
108
|
+
interface SandpackFile {
|
|
109
|
+
code: string;
|
|
110
|
+
hidden?: boolean;
|
|
111
|
+
active?: boolean;
|
|
112
|
+
readOnly?: boolean;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Sandpack `files` prop — path keys map to source strings or file objects.
|
|
116
|
+
*
|
|
117
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
118
|
+
*/
|
|
119
|
+
type SandpackFiles = Record<string, string | SandpackFile>;
|
|
120
|
+
/**
|
|
121
|
+
* A component usage demo ready for `<Sandpack files={...} />`.
|
|
122
|
+
*
|
|
123
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
124
|
+
*/
|
|
125
|
+
interface SandpackUsage {
|
|
126
|
+
/** Stable demo id — used for the usage file name. */
|
|
127
|
+
name: string;
|
|
128
|
+
/** Human-readable label for INSTALL.md. Defaults to {@link name}. */
|
|
129
|
+
displayName?: string;
|
|
130
|
+
/** Component id this demo belongs to. */
|
|
131
|
+
component?: string;
|
|
132
|
+
title?: string;
|
|
133
|
+
description?: string;
|
|
134
|
+
/**
|
|
135
|
+
* Sandpack template preset.
|
|
136
|
+
*
|
|
137
|
+
* @defaultValue `"react"`
|
|
138
|
+
*/
|
|
139
|
+
template?: string;
|
|
140
|
+
/** Sandpack `files` prop payload. */
|
|
141
|
+
files: SandpackFiles;
|
|
142
|
+
/**
|
|
143
|
+
* Theme id matching a generated theme `name`, or an inline theme payload
|
|
144
|
+
* (without Razorwind `name` / `displayName`).
|
|
145
|
+
*/
|
|
146
|
+
theme?: string | Omit<SandpackTheme, "name" | "displayName">;
|
|
147
|
+
/** Extra npm dependencies for `customSetup.dependencies`. */
|
|
148
|
+
dependencies?: Record<string, string>;
|
|
149
|
+
/** Optional sandbox entry path (`customSetup.entry`). */
|
|
150
|
+
entry?: string;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Map extracted components (and tokens) to Sandpack usage demos.
|
|
154
|
+
*
|
|
155
|
+
* Return a single demo, an array, or a record keyed by demo id.
|
|
156
|
+
* When omitted, demos are built from `schema.components[].usage`.
|
|
157
|
+
*/
|
|
158
|
+
type GenerateSandpackFiles = (components: Components, tokens: Tokens | Record<string, Tokens>) => SandpackUsage | SandpackUsage[] | Record<string, SandpackUsage>;
|
|
159
|
+
/**
|
|
160
|
+
* Options for the Razorwind Sandpack theme / usage generator.
|
|
161
|
+
*
|
|
162
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
163
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
164
|
+
*/
|
|
165
|
+
interface SandpackPluginOptions {
|
|
166
|
+
/**
|
|
167
|
+
* Directory (relative to the execution cwd) for generated theme and usage
|
|
168
|
+
* files.
|
|
169
|
+
*
|
|
170
|
+
* @defaultValue `"sandpack"`
|
|
171
|
+
*/
|
|
172
|
+
outputPath?: string;
|
|
173
|
+
/**
|
|
174
|
+
* Map extracted tokens to Sandpack theme document(s).
|
|
175
|
+
*
|
|
176
|
+
* Required — without a mapping there is nothing to emit for themes.
|
|
177
|
+
*/
|
|
178
|
+
mapTheme: GenerateSandpackTheme;
|
|
179
|
+
/**
|
|
180
|
+
* Map extracted components to Sandpack usage demos (`files` prop payloads).
|
|
181
|
+
*
|
|
182
|
+
* When omitted and {@link includeUsage} is not `false`, demos are derived
|
|
183
|
+
* from `schema.components[].usage`.
|
|
184
|
+
*/
|
|
185
|
+
mapFiles?: GenerateSandpackFiles;
|
|
186
|
+
/**
|
|
187
|
+
* Emit component usage demos under `usage/`.
|
|
188
|
+
*
|
|
189
|
+
* @defaultValue `true`
|
|
190
|
+
*/
|
|
191
|
+
includeUsage?: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Default Sandpack template for auto-built usage demos.
|
|
194
|
+
*
|
|
195
|
+
* @defaultValue `"react"`
|
|
196
|
+
*/
|
|
197
|
+
template?: string;
|
|
198
|
+
/**
|
|
199
|
+
* Override body for generated `INSTALL.md`. When omitted, Sandpack install
|
|
200
|
+
* steps are written (import theme / files into `<Sandpack />`).
|
|
201
|
+
*/
|
|
202
|
+
installGuide?: string;
|
|
203
|
+
/**
|
|
204
|
+
* Restrict flattened helper tokens to these DTCG `$type` values.
|
|
205
|
+
* Does not filter what {@link mapTheme} receives.
|
|
206
|
+
*/
|
|
207
|
+
includeTypes?: TokenType[];
|
|
208
|
+
}
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region src/install.d.ts
|
|
211
|
+
/**
|
|
212
|
+
* Build Sandpack INSTALL.md for generated theme and usage files.
|
|
213
|
+
*
|
|
214
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
215
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
216
|
+
*/
|
|
217
|
+
declare function renderInstallMd(options: {
|
|
218
|
+
themes: Array<{
|
|
219
|
+
name: string;
|
|
220
|
+
displayName: string;
|
|
221
|
+
fileName: string;
|
|
222
|
+
}>;
|
|
223
|
+
usages: Array<{
|
|
224
|
+
name: string;
|
|
225
|
+
displayName: string;
|
|
226
|
+
fileName: string;
|
|
227
|
+
component?: string;
|
|
228
|
+
}>;
|
|
229
|
+
}): string;
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/generate.d.ts
|
|
232
|
+
/**
|
|
233
|
+
* Normalize {@link SandpackPluginOptions.mapTheme} results into a theme list.
|
|
234
|
+
*/
|
|
235
|
+
declare function normalizeThemes(result: SandpackTheme | SandpackTheme[] | Record<string, SandpackTheme>): SandpackTheme[];
|
|
236
|
+
/**
|
|
237
|
+
* Normalize {@link SandpackPluginOptions.mapFiles} results into a usage list.
|
|
238
|
+
*/
|
|
239
|
+
declare function normalizeUsages(result: SandpackUsage | SandpackUsage[] | Record<string, SandpackUsage>): SandpackUsage[];
|
|
240
|
+
/**
|
|
241
|
+
* Serialize a Sandpack theme document for `themes/*.json`.
|
|
242
|
+
*
|
|
243
|
+
* Emits only Sandpack `theme` prop fields (`colors`, `syntax`, `font`).
|
|
244
|
+
*
|
|
245
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
246
|
+
*/
|
|
247
|
+
declare function renderThemeJson(theme: SandpackTheme): string;
|
|
248
|
+
/**
|
|
249
|
+
* Serialize a Sandpack usage demo for `usage/*.json`.
|
|
250
|
+
*
|
|
251
|
+
* Shape is ready to feed `<Sandpack files={...} template={...} />`.
|
|
252
|
+
*
|
|
253
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
254
|
+
*/
|
|
255
|
+
declare function renderUsageJson(usage: SandpackUsage): string;
|
|
256
|
+
/**
|
|
257
|
+
* Generate Sandpack theme JSON and component usage demos from a Razorwind
|
|
258
|
+
* schema.
|
|
259
|
+
*
|
|
260
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
261
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
262
|
+
*/
|
|
263
|
+
declare function generateSandpackTheme(spec: Schema, options: SandpackPluginOptions): GeneratorFunctionResult<Schema, SandpackPluginOptions>;
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region src/usage.d.ts
|
|
266
|
+
/**
|
|
267
|
+
* Build Sandpack `files` for a single component usage example.
|
|
268
|
+
*
|
|
269
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
270
|
+
*/
|
|
271
|
+
declare function usageToSandpackFiles(usage: ComponentUsage, component: Component): SandpackFiles | undefined;
|
|
272
|
+
/**
|
|
273
|
+
* Derive Sandpack usage demos from extracted `schema.components[].usage`.
|
|
274
|
+
*
|
|
275
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
276
|
+
*/
|
|
277
|
+
declare function buildUsageFromComponents(components: Components, options?: {
|
|
278
|
+
template?: string;
|
|
279
|
+
}): SandpackUsage[];
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/index.d.ts
|
|
282
|
+
/**
|
|
283
|
+
* Razorwind plugin that turns design tokens into Sandpack themes and component
|
|
284
|
+
* usage demos (`files` prop payloads).
|
|
285
|
+
*
|
|
286
|
+
* Provide {@link SandpackPluginOptions.mapTheme} to map extracted tokens to one
|
|
287
|
+
* or more theme documents. Component `usage` examples are emitted as Sandpack
|
|
288
|
+
* `files` JSON under `usage/` (override with {@link SandpackPluginOptions.mapFiles}).
|
|
289
|
+
*
|
|
290
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
291
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```ts
|
|
295
|
+
* import { defineConfig } from "@razorwind/core";
|
|
296
|
+
* import sandpack, { flattenTokens } from "@razorwind/sandpack";
|
|
297
|
+
*
|
|
298
|
+
* export default defineConfig({
|
|
299
|
+
* plugins: [
|
|
300
|
+
* sandpack({
|
|
301
|
+
* mapTheme: tokens => {
|
|
302
|
+
* const flat = flattenTokens(tokens);
|
|
303
|
+
* const color = (path: string) =>
|
|
304
|
+
* flat.find(t => t.path === path)?.cssValue ?? "#000000";
|
|
305
|
+
*
|
|
306
|
+
* return {
|
|
307
|
+
* name: "my-theme",
|
|
308
|
+
* colors: {
|
|
309
|
+
* surface1: color("color.bg"),
|
|
310
|
+
* base: color("color.fg"),
|
|
311
|
+
* accent: color("color.accent")
|
|
312
|
+
* },
|
|
313
|
+
* syntax: {
|
|
314
|
+
* plain: color("color.fg"),
|
|
315
|
+
* comment: color("color.muted"),
|
|
316
|
+
* string: color("color.accent")
|
|
317
|
+
* }
|
|
318
|
+
* };
|
|
319
|
+
* }
|
|
320
|
+
* })
|
|
321
|
+
* ]
|
|
322
|
+
* });
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
declare const _default: (options?: SandpackPluginOptions | undefined) => import("@razorwind/core/plugin").Plugin;
|
|
326
|
+
//#endregion
|
|
327
|
+
export { type FlatToken, type GenerateSandpackFiles, type GenerateSandpackTheme, type SandpackFile, type SandpackFiles, type SandpackPluginOptions, type SandpackSyntaxStyle, type SandpackTheme, type SandpackThemeColors, type SandpackThemeFont, type SandpackThemeSyntax, type SandpackUsage, buildUsageFromComponents, _default as default, flattenTokens, formatTokenValue, generateSandpackTheme, normalizeThemes, normalizeUsages, renderInstallMd, renderThemeJson, renderUsageJson, resolveTokenSets, toCssVar, usageToSandpackFiles };
|
|
328
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/install.ts","../src/generate.ts","../src/usage.ts","../src/index.ts"],"mappings":";;;;;;;;UAwBiB;;EAEf;;EAEA,OAAO;;EAEP;;EAEA;;EAEA;;EAEA;;;;;;;UAQe;EACf;EACA;EACA;EAYA;;;;;;;UAYe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;;UAQe;EACf,iBAAiB;EACjB,mBAAmB;EACnB,mBAAmB;EACnB,sBAAsB;EACtB,uBAAuB;EACvB,oBAAoB;EACpB,eAAe;EACf,kBAAkB;EAClB,kBAAkB;;;;;;;UAQH;EACf;EACA;EACA;EACA;;;;;;;;;;UAWe;;EAEf;;EAEA;EACA,SAAS;EACT,SAAS;EACT,OAAO;;;;;;;KAQG,yBACV,QAAQ,SAAS,eAAe,YAC7B,gBAAgB,kBAAkB,eAAe;;;;;;UAOrC;EACf;EACA;EACA;EACA;;;;;;;KAQU,gBAAgB,wBAAwB;;;;;;UAOnC;;EAEf;;EAEA;;EAEA;EACA;EACA;;;;;;EAMA;;EAEA,OAAO;;;;;EAKP,iBAAiB,KAAK;;EAEtB,eAAe;;EAEf;;;;;;;;KASU,yBACV,YAAY,YACZ,QAAQ,SAAS,eAAe,YAC7B,gBAAgB,kBAAkB,eAAe;;;;;;;UAQrC;;;;;;;EAOf;;;;;;EAOA,UAAU;;;;;;;EAQV,WAAW;;;;;;EAOX;;;;;;EAOA;;;;;EAMA;;;;;EAMA,eAAe;;;;;;;;;;iBCxOD,gBAAgB;EAC9B,QAAQ;IAAQ;IAAc;IAAqB;;EACnD,QAAQ;IACN;IACA;IACA;IACA;;;;;;;;iBC8DY,gBACd,QAAQ,gBAAgB,kBAAkB,eAAe,iBACxD;;;;iBAsCa,gBACd,QAAQ,gBAAgB,kBAAkB,eAAe,iBACxD;;;;;;;;iBAgFa,gBAAgB,OAAO;;;;;;;;iBAuBvB,gBAAgB,OAAO;;;;;;;;iBAyCvB,sBACd,MAAM,QACN,SAAS,wBACR,wBAAwB,QAAQ;;;;;;;;iBCjMnB,qBACd,OAAO,gBACP,WAAW,YACV;;;;;;iBA+Ca,yBACd,YAAY,YACZ;EAAW;IACV"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { flattenTokens, formatTokenValue, resolveTokenSets, toCssVar } from "@razorwind/core/utils";
|
|
2
|
+
import { GeneratorFunctionResult } from "@power-plant/core";
|
|
3
|
+
import { Component, ComponentUsage, Components, Schema, Tokens } from "@razorwind/core/schema";
|
|
4
|
+
import { TokenType } from "@power-plant/dtcg-schema";
|
|
5
|
+
//#region src/types.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* A flattened design token ready for Sandpack theme mapping.
|
|
8
|
+
*/
|
|
9
|
+
interface FlatToken {
|
|
10
|
+
/** Dot-separated token path (e.g. `color.primary`). */
|
|
11
|
+
path: string;
|
|
12
|
+
/** DTCG `$type`, when known. */
|
|
13
|
+
type?: TokenType | string;
|
|
14
|
+
/** Raw `$value` from the token document. */
|
|
15
|
+
value: unknown;
|
|
16
|
+
/** CSS-friendly string form of {@link value}. */
|
|
17
|
+
cssValue: string;
|
|
18
|
+
/** Optional DTCG `$description`. */
|
|
19
|
+
description?: string;
|
|
20
|
+
/** Theme / set id when tokens are a `Record<string, Tokens>`. */
|
|
21
|
+
theme?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Syntax style token for Sandpack themes.
|
|
25
|
+
*
|
|
26
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
27
|
+
*/
|
|
28
|
+
interface SandpackSyntaxStyle {
|
|
29
|
+
color?: string;
|
|
30
|
+
fontStyle?: "normal" | "italic";
|
|
31
|
+
fontWeight?: "normal" | "bold" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900";
|
|
32
|
+
textDecoration?: "none" | "underline" | "line-through" | "underline line-through";
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Sandpack UI color tokens (`theme.colors`).
|
|
36
|
+
*
|
|
37
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
38
|
+
*/
|
|
39
|
+
interface SandpackThemeColors {
|
|
40
|
+
surface1?: string;
|
|
41
|
+
surface2?: string;
|
|
42
|
+
surface3?: string;
|
|
43
|
+
disabled?: string;
|
|
44
|
+
base?: string;
|
|
45
|
+
clickable?: string;
|
|
46
|
+
hover?: string;
|
|
47
|
+
accent?: string;
|
|
48
|
+
error?: string;
|
|
49
|
+
errorSurface?: string;
|
|
50
|
+
warning?: string;
|
|
51
|
+
warningSurface?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Sandpack syntax highlight tokens (`theme.syntax`).
|
|
55
|
+
*
|
|
56
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
57
|
+
*/
|
|
58
|
+
interface SandpackThemeSyntax {
|
|
59
|
+
plain?: string | SandpackSyntaxStyle;
|
|
60
|
+
comment?: string | SandpackSyntaxStyle;
|
|
61
|
+
keyword?: string | SandpackSyntaxStyle;
|
|
62
|
+
definition?: string | SandpackSyntaxStyle;
|
|
63
|
+
punctuation?: string | SandpackSyntaxStyle;
|
|
64
|
+
property?: string | SandpackSyntaxStyle;
|
|
65
|
+
tag?: string | SandpackSyntaxStyle;
|
|
66
|
+
static?: string | SandpackSyntaxStyle;
|
|
67
|
+
string?: string | SandpackSyntaxStyle;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Sandpack typography tokens (`theme.font`).
|
|
71
|
+
*
|
|
72
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
73
|
+
*/
|
|
74
|
+
interface SandpackThemeFont {
|
|
75
|
+
body?: string;
|
|
76
|
+
mono?: string;
|
|
77
|
+
size?: string;
|
|
78
|
+
lineHeight?: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Sandpack custom theme document.
|
|
82
|
+
*
|
|
83
|
+
* Pass the emitted JSON (minus Razorwind `name` / `displayName`) to
|
|
84
|
+
* `<Sandpack theme={...} />`. Partial objects override the default light theme.
|
|
85
|
+
*
|
|
86
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
87
|
+
*/
|
|
88
|
+
interface SandpackTheme {
|
|
89
|
+
/** Stable theme id — used for the theme file name. */
|
|
90
|
+
name: string;
|
|
91
|
+
/** Human-readable label for INSTALL.md. Defaults to {@link name}. */
|
|
92
|
+
displayName?: string;
|
|
93
|
+
colors?: SandpackThemeColors;
|
|
94
|
+
syntax?: SandpackThemeSyntax;
|
|
95
|
+
font?: SandpackThemeFont;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Map extracted design tokens to one or more Sandpack theme documents.
|
|
99
|
+
*
|
|
100
|
+
* Return a single theme, an array, or a record keyed by theme id.
|
|
101
|
+
*/
|
|
102
|
+
type GenerateSandpackTheme = (tokens: Tokens | Record<string, Tokens>) => SandpackTheme | SandpackTheme[] | Record<string, SandpackTheme>;
|
|
103
|
+
/**
|
|
104
|
+
* A single Sandpack file entry for the `files` prop.
|
|
105
|
+
*
|
|
106
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
107
|
+
*/
|
|
108
|
+
interface SandpackFile {
|
|
109
|
+
code: string;
|
|
110
|
+
hidden?: boolean;
|
|
111
|
+
active?: boolean;
|
|
112
|
+
readOnly?: boolean;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Sandpack `files` prop — path keys map to source strings or file objects.
|
|
116
|
+
*
|
|
117
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
118
|
+
*/
|
|
119
|
+
type SandpackFiles = Record<string, string | SandpackFile>;
|
|
120
|
+
/**
|
|
121
|
+
* A component usage demo ready for `<Sandpack files={...} />`.
|
|
122
|
+
*
|
|
123
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
124
|
+
*/
|
|
125
|
+
interface SandpackUsage {
|
|
126
|
+
/** Stable demo id — used for the usage file name. */
|
|
127
|
+
name: string;
|
|
128
|
+
/** Human-readable label for INSTALL.md. Defaults to {@link name}. */
|
|
129
|
+
displayName?: string;
|
|
130
|
+
/** Component id this demo belongs to. */
|
|
131
|
+
component?: string;
|
|
132
|
+
title?: string;
|
|
133
|
+
description?: string;
|
|
134
|
+
/**
|
|
135
|
+
* Sandpack template preset.
|
|
136
|
+
*
|
|
137
|
+
* @defaultValue `"react"`
|
|
138
|
+
*/
|
|
139
|
+
template?: string;
|
|
140
|
+
/** Sandpack `files` prop payload. */
|
|
141
|
+
files: SandpackFiles;
|
|
142
|
+
/**
|
|
143
|
+
* Theme id matching a generated theme `name`, or an inline theme payload
|
|
144
|
+
* (without Razorwind `name` / `displayName`).
|
|
145
|
+
*/
|
|
146
|
+
theme?: string | Omit<SandpackTheme, "name" | "displayName">;
|
|
147
|
+
/** Extra npm dependencies for `customSetup.dependencies`. */
|
|
148
|
+
dependencies?: Record<string, string>;
|
|
149
|
+
/** Optional sandbox entry path (`customSetup.entry`). */
|
|
150
|
+
entry?: string;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Map extracted components (and tokens) to Sandpack usage demos.
|
|
154
|
+
*
|
|
155
|
+
* Return a single demo, an array, or a record keyed by demo id.
|
|
156
|
+
* When omitted, demos are built from `schema.components[].usage`.
|
|
157
|
+
*/
|
|
158
|
+
type GenerateSandpackFiles = (components: Components, tokens: Tokens | Record<string, Tokens>) => SandpackUsage | SandpackUsage[] | Record<string, SandpackUsage>;
|
|
159
|
+
/**
|
|
160
|
+
* Options for the Razorwind Sandpack theme / usage generator.
|
|
161
|
+
*
|
|
162
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
163
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
164
|
+
*/
|
|
165
|
+
interface SandpackPluginOptions {
|
|
166
|
+
/**
|
|
167
|
+
* Directory (relative to the execution cwd) for generated theme and usage
|
|
168
|
+
* files.
|
|
169
|
+
*
|
|
170
|
+
* @defaultValue `"sandpack"`
|
|
171
|
+
*/
|
|
172
|
+
outputPath?: string;
|
|
173
|
+
/**
|
|
174
|
+
* Map extracted tokens to Sandpack theme document(s).
|
|
175
|
+
*
|
|
176
|
+
* Required — without a mapping there is nothing to emit for themes.
|
|
177
|
+
*/
|
|
178
|
+
mapTheme: GenerateSandpackTheme;
|
|
179
|
+
/**
|
|
180
|
+
* Map extracted components to Sandpack usage demos (`files` prop payloads).
|
|
181
|
+
*
|
|
182
|
+
* When omitted and {@link includeUsage} is not `false`, demos are derived
|
|
183
|
+
* from `schema.components[].usage`.
|
|
184
|
+
*/
|
|
185
|
+
mapFiles?: GenerateSandpackFiles;
|
|
186
|
+
/**
|
|
187
|
+
* Emit component usage demos under `usage/`.
|
|
188
|
+
*
|
|
189
|
+
* @defaultValue `true`
|
|
190
|
+
*/
|
|
191
|
+
includeUsage?: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Default Sandpack template for auto-built usage demos.
|
|
194
|
+
*
|
|
195
|
+
* @defaultValue `"react"`
|
|
196
|
+
*/
|
|
197
|
+
template?: string;
|
|
198
|
+
/**
|
|
199
|
+
* Override body for generated `INSTALL.md`. When omitted, Sandpack install
|
|
200
|
+
* steps are written (import theme / files into `<Sandpack />`).
|
|
201
|
+
*/
|
|
202
|
+
installGuide?: string;
|
|
203
|
+
/**
|
|
204
|
+
* Restrict flattened helper tokens to these DTCG `$type` values.
|
|
205
|
+
* Does not filter what {@link mapTheme} receives.
|
|
206
|
+
*/
|
|
207
|
+
includeTypes?: TokenType[];
|
|
208
|
+
}
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region src/install.d.ts
|
|
211
|
+
/**
|
|
212
|
+
* Build Sandpack INSTALL.md for generated theme and usage files.
|
|
213
|
+
*
|
|
214
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
215
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
216
|
+
*/
|
|
217
|
+
declare function renderInstallMd(options: {
|
|
218
|
+
themes: Array<{
|
|
219
|
+
name: string;
|
|
220
|
+
displayName: string;
|
|
221
|
+
fileName: string;
|
|
222
|
+
}>;
|
|
223
|
+
usages: Array<{
|
|
224
|
+
name: string;
|
|
225
|
+
displayName: string;
|
|
226
|
+
fileName: string;
|
|
227
|
+
component?: string;
|
|
228
|
+
}>;
|
|
229
|
+
}): string;
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/generate.d.ts
|
|
232
|
+
/**
|
|
233
|
+
* Normalize {@link SandpackPluginOptions.mapTheme} results into a theme list.
|
|
234
|
+
*/
|
|
235
|
+
declare function normalizeThemes(result: SandpackTheme | SandpackTheme[] | Record<string, SandpackTheme>): SandpackTheme[];
|
|
236
|
+
/**
|
|
237
|
+
* Normalize {@link SandpackPluginOptions.mapFiles} results into a usage list.
|
|
238
|
+
*/
|
|
239
|
+
declare function normalizeUsages(result: SandpackUsage | SandpackUsage[] | Record<string, SandpackUsage>): SandpackUsage[];
|
|
240
|
+
/**
|
|
241
|
+
* Serialize a Sandpack theme document for `themes/*.json`.
|
|
242
|
+
*
|
|
243
|
+
* Emits only Sandpack `theme` prop fields (`colors`, `syntax`, `font`).
|
|
244
|
+
*
|
|
245
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
246
|
+
*/
|
|
247
|
+
declare function renderThemeJson(theme: SandpackTheme): string;
|
|
248
|
+
/**
|
|
249
|
+
* Serialize a Sandpack usage demo for `usage/*.json`.
|
|
250
|
+
*
|
|
251
|
+
* Shape is ready to feed `<Sandpack files={...} template={...} />`.
|
|
252
|
+
*
|
|
253
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
254
|
+
*/
|
|
255
|
+
declare function renderUsageJson(usage: SandpackUsage): string;
|
|
256
|
+
/**
|
|
257
|
+
* Generate Sandpack theme JSON and component usage demos from a Razorwind
|
|
258
|
+
* schema.
|
|
259
|
+
*
|
|
260
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
261
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
262
|
+
*/
|
|
263
|
+
declare function generateSandpackTheme(spec: Schema, options: SandpackPluginOptions): GeneratorFunctionResult<Schema, SandpackPluginOptions>;
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region src/usage.d.ts
|
|
266
|
+
/**
|
|
267
|
+
* Build Sandpack `files` for a single component usage example.
|
|
268
|
+
*
|
|
269
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
270
|
+
*/
|
|
271
|
+
declare function usageToSandpackFiles(usage: ComponentUsage, component: Component): SandpackFiles | undefined;
|
|
272
|
+
/**
|
|
273
|
+
* Derive Sandpack usage demos from extracted `schema.components[].usage`.
|
|
274
|
+
*
|
|
275
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
276
|
+
*/
|
|
277
|
+
declare function buildUsageFromComponents(components: Components, options?: {
|
|
278
|
+
template?: string;
|
|
279
|
+
}): SandpackUsage[];
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/index.d.ts
|
|
282
|
+
/**
|
|
283
|
+
* Razorwind plugin that turns design tokens into Sandpack themes and component
|
|
284
|
+
* usage demos (`files` prop payloads).
|
|
285
|
+
*
|
|
286
|
+
* Provide {@link SandpackPluginOptions.mapTheme} to map extracted tokens to one
|
|
287
|
+
* or more theme documents. Component `usage` examples are emitted as Sandpack
|
|
288
|
+
* `files` JSON under `usage/` (override with {@link SandpackPluginOptions.mapFiles}).
|
|
289
|
+
*
|
|
290
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/themes#custom-theme
|
|
291
|
+
* @see https://sandpack.codesandbox.io/docs/getting-started/usage#files
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```ts
|
|
295
|
+
* import { defineConfig } from "@razorwind/core";
|
|
296
|
+
* import sandpack, { flattenTokens } from "@razorwind/sandpack";
|
|
297
|
+
*
|
|
298
|
+
* export default defineConfig({
|
|
299
|
+
* plugins: [
|
|
300
|
+
* sandpack({
|
|
301
|
+
* mapTheme: tokens => {
|
|
302
|
+
* const flat = flattenTokens(tokens);
|
|
303
|
+
* const color = (path: string) =>
|
|
304
|
+
* flat.find(t => t.path === path)?.cssValue ?? "#000000";
|
|
305
|
+
*
|
|
306
|
+
* return {
|
|
307
|
+
* name: "my-theme",
|
|
308
|
+
* colors: {
|
|
309
|
+
* surface1: color("color.bg"),
|
|
310
|
+
* base: color("color.fg"),
|
|
311
|
+
* accent: color("color.accent")
|
|
312
|
+
* },
|
|
313
|
+
* syntax: {
|
|
314
|
+
* plain: color("color.fg"),
|
|
315
|
+
* comment: color("color.muted"),
|
|
316
|
+
* string: color("color.accent")
|
|
317
|
+
* }
|
|
318
|
+
* };
|
|
319
|
+
* }
|
|
320
|
+
* })
|
|
321
|
+
* ]
|
|
322
|
+
* });
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
declare const _default: (options?: SandpackPluginOptions | undefined) => import("@razorwind/core/plugin").Plugin;
|
|
326
|
+
//#endregion
|
|
327
|
+
export { type FlatToken, type GenerateSandpackFiles, type GenerateSandpackTheme, type SandpackFile, type SandpackFiles, type SandpackPluginOptions, type SandpackSyntaxStyle, type SandpackTheme, type SandpackThemeColors, type SandpackThemeFont, type SandpackThemeSyntax, type SandpackUsage, buildUsageFromComponents, _default as default, flattenTokens, formatTokenValue, generateSandpackTheme, normalizeThemes, normalizeUsages, renderInstallMd, renderThemeJson, renderUsageJson, resolveTokenSets, toCssVar, usageToSandpackFiles };
|
|
328
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/install.ts","../src/generate.ts","../src/usage.ts","../src/index.ts"],"mappings":""}
|