@takazudo/zudo-sg 0.4.0 → 0.5.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 (67) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/README.md +59 -61
  3. package/dist/catalog/catalog-thumb.d.ts +1 -6
  4. package/dist/catalog/catalog-thumb.js +1 -2
  5. package/dist/catalog/component-thumb.d.ts +1 -6
  6. package/dist/catalog/component-thumb.js +8 -7
  7. package/dist/catalog/descriptor-thumb.d.ts +1 -6
  8. package/dist/catalog/descriptor-thumb.js +1 -2
  9. package/dist/chrome/_styleguide-layout.d.ts +8 -9
  10. package/dist/chrome/_styleguide-layout.js +3 -6
  11. package/dist/chrome/panel-scripts.d.ts +1 -3
  12. package/dist/chrome/panel-scripts.js +3 -3
  13. package/dist/cli/scaffold/component-scaffold.js +35 -16
  14. package/dist/code-panel/code-panel.d.ts +2 -8
  15. package/dist/code-panel/code-panel.js +34 -35
  16. package/dist/code-panel/copy-button.d.ts +1 -7
  17. package/dist/code-panel/copy-button.js +31 -48
  18. package/dist/code-panel/copy-text.d.ts +1 -0
  19. package/dist/code-panel/copy-text.js +26 -0
  20. package/dist/code-panel/editor-setup.d.ts +3 -0
  21. package/dist/code-panel/editor-setup.js +15 -3
  22. package/dist/code-panel/editor-theme.d.ts +2 -0
  23. package/dist/code-panel/editor-theme.js +54 -0
  24. package/dist/code-panel/source-editor.d.ts +10 -2
  25. package/dist/code-panel/source-editor.js +20 -19
  26. package/dist/config/index.d.ts +2 -0
  27. package/dist/config/index.js +6 -1
  28. package/dist/config/wind.d.ts +265 -0
  29. package/dist/config/wind.js +133 -0
  30. package/dist/plugins/preview-css.d.ts +9 -7
  31. package/dist/plugins/preview-css.js +58 -37
  32. package/dist/preview/detail-workbench.d.ts +2 -6
  33. package/dist/preview/detail-workbench.js +100 -65
  34. package/dist/preview/index.d.ts +4 -2
  35. package/dist/preview/index.js +7 -7
  36. package/dist/preview/preview-app.d.ts +2 -5
  37. package/dist/preview/preview-app.js +76 -46
  38. package/dist/preview/variant-frame-config.d.ts +47 -0
  39. package/dist/preview/variant-frame-config.js +50 -0
  40. package/dist/preview/variant-frame.d.ts +9 -53
  41. package/dist/preview/variant-frame.js +158 -149
  42. package/dist/preview-css/compile.d.ts +15 -29
  43. package/dist/preview-css/compile.js +183 -31
  44. package/dist/search/catalog-filter.d.ts +2 -6
  45. package/dist/search/catalog-filter.js +50 -42
  46. package/dist/stories/types.d.ts +5 -3
  47. package/dist/token-dashboard/create-token-dashboards.d.ts +3 -5
  48. package/dist/token-dashboard/create-token-dashboards.js +14 -44
  49. package/dist/token-dashboard/dashboard-inventory.d.ts +1 -1
  50. package/dist/token-dashboard/token-dashboard-adapter.d.ts +2 -0
  51. package/dist/token-dashboard/token-dashboard-adapter.js +9 -0
  52. package/dist/token-dashboard/token-dashboard-mount.d.ts +6 -0
  53. package/dist/token-dashboard/token-dashboard-mount.js +33 -0
  54. package/dist/token-tweak/preview-token-panel-bootstrap.d.ts +1 -6
  55. package/dist/token-tweak/preview-token-panel-bootstrap.js +4 -2
  56. package/dist/token-tweak/preview-tokens-button.d.ts +1 -5
  57. package/dist/token-tweak/preview-tokens-button.js +5 -4
  58. package/dist/wind.json +119 -0
  59. package/package.json +16 -19
  60. package/routes-src/_chrome.tsx +1 -3
  61. package/routes-src/_preview-app.tsx +3 -8
  62. package/routes-src/components-index.tsx +5 -10
  63. package/routes-src/components-preview.tsx +3 -9
  64. package/routes-src/components-slug.tsx +21 -24
  65. package/routes-src/tokens.tsx +4 -9
  66. package/styles.css +36 -11
  67. package/dist/safelist.css +0 -2
@@ -0,0 +1,265 @@
1
+ export declare const engineWindTokens: {
2
+ colors: {
3
+ bg: string;
4
+ fg: string;
5
+ muted: string;
6
+ "sg-bg": string;
7
+ "sg-fg": string;
8
+ "sg-surface": string;
9
+ "sg-surface-2": string;
10
+ "sg-border": string;
11
+ "sg-border-strong": string;
12
+ "sg-muted": string;
13
+ "sg-accent": string;
14
+ "sg-on-accent": string;
15
+ "sg-focus": string;
16
+ "sg-success": string;
17
+ };
18
+ spacing: {
19
+ "hsp-2xs": string;
20
+ "hsp-xs": string;
21
+ "hsp-sm": string;
22
+ "hsp-md": string;
23
+ "hsp-lg": string;
24
+ "hsp-xl": string;
25
+ "hsp-2xl": string;
26
+ "vsp-3xs": string;
27
+ "vsp-2xs": string;
28
+ "vsp-10": string;
29
+ "vsp-xs": string;
30
+ "vsp-sm": string;
31
+ "vsp-md": string;
32
+ "vsp-lg": string;
33
+ "vsp-xl": string;
34
+ "vsp-2xl": string;
35
+ };
36
+ fontSizes: {
37
+ xs: {
38
+ size: string;
39
+ lineHeight: string;
40
+ };
41
+ sm: {
42
+ size: string;
43
+ lineHeight: string;
44
+ };
45
+ base: {
46
+ size: string;
47
+ lineHeight: string;
48
+ };
49
+ lg: {
50
+ size: string;
51
+ lineHeight: string;
52
+ };
53
+ xl: {
54
+ size: string;
55
+ lineHeight: string;
56
+ };
57
+ "2xl": {
58
+ size: string;
59
+ lineHeight: string;
60
+ };
61
+ micro: {
62
+ size: string;
63
+ };
64
+ caption: {
65
+ size: string;
66
+ };
67
+ small: {
68
+ size: string;
69
+ };
70
+ body: {
71
+ size: string;
72
+ };
73
+ title: {
74
+ size: string;
75
+ };
76
+ heading: {
77
+ size: string;
78
+ };
79
+ display: {
80
+ size: string;
81
+ };
82
+ };
83
+ fontFamilies: {
84
+ sans: string;
85
+ mono: string;
86
+ };
87
+ fontWeights: {
88
+ normal: string;
89
+ medium: string;
90
+ semibold: string;
91
+ bold: string;
92
+ };
93
+ lineHeights: {
94
+ tight: string;
95
+ snug: string;
96
+ normal: string;
97
+ relaxed: string;
98
+ };
99
+ letterSpacings: {
100
+ wide: string;
101
+ };
102
+ radii: {
103
+ default: string;
104
+ sm: string;
105
+ md: string;
106
+ lg: string;
107
+ };
108
+ shadows: {
109
+ card: string;
110
+ raised: string;
111
+ overlay: string;
112
+ };
113
+ zIndices: {
114
+ "ui-base": string;
115
+ "ui-sticky": string;
116
+ "ui-dropdown": string;
117
+ "ui-overlay": string;
118
+ "ui-modal": string;
119
+ "ui-toast": string;
120
+ };
121
+ };
122
+ export declare const engineWindDefaults: {
123
+ tokens: {
124
+ colors: {
125
+ bg: string;
126
+ fg: string;
127
+ muted: string;
128
+ "sg-bg": string;
129
+ "sg-fg": string;
130
+ "sg-surface": string;
131
+ "sg-surface-2": string;
132
+ "sg-border": string;
133
+ "sg-border-strong": string;
134
+ "sg-muted": string;
135
+ "sg-accent": string;
136
+ "sg-on-accent": string;
137
+ "sg-focus": string;
138
+ "sg-success": string;
139
+ };
140
+ spacing: {
141
+ "hsp-2xs": string;
142
+ "hsp-xs": string;
143
+ "hsp-sm": string;
144
+ "hsp-md": string;
145
+ "hsp-lg": string;
146
+ "hsp-xl": string;
147
+ "hsp-2xl": string;
148
+ "vsp-3xs": string;
149
+ "vsp-2xs": string;
150
+ "vsp-10": string;
151
+ "vsp-xs": string;
152
+ "vsp-sm": string;
153
+ "vsp-md": string;
154
+ "vsp-lg": string;
155
+ "vsp-xl": string;
156
+ "vsp-2xl": string;
157
+ };
158
+ fontSizes: {
159
+ xs: {
160
+ size: string;
161
+ lineHeight: string;
162
+ };
163
+ sm: {
164
+ size: string;
165
+ lineHeight: string;
166
+ };
167
+ base: {
168
+ size: string;
169
+ lineHeight: string;
170
+ };
171
+ lg: {
172
+ size: string;
173
+ lineHeight: string;
174
+ };
175
+ xl: {
176
+ size: string;
177
+ lineHeight: string;
178
+ };
179
+ "2xl": {
180
+ size: string;
181
+ lineHeight: string;
182
+ };
183
+ micro: {
184
+ size: string;
185
+ };
186
+ caption: {
187
+ size: string;
188
+ };
189
+ small: {
190
+ size: string;
191
+ };
192
+ body: {
193
+ size: string;
194
+ };
195
+ title: {
196
+ size: string;
197
+ };
198
+ heading: {
199
+ size: string;
200
+ };
201
+ display: {
202
+ size: string;
203
+ };
204
+ };
205
+ fontFamilies: {
206
+ sans: string;
207
+ mono: string;
208
+ };
209
+ fontWeights: {
210
+ normal: string;
211
+ medium: string;
212
+ semibold: string;
213
+ bold: string;
214
+ };
215
+ lineHeights: {
216
+ tight: string;
217
+ snug: string;
218
+ normal: string;
219
+ relaxed: string;
220
+ };
221
+ letterSpacings: {
222
+ wide: string;
223
+ };
224
+ radii: {
225
+ default: string;
226
+ sm: string;
227
+ md: string;
228
+ lg: string;
229
+ };
230
+ shadows: {
231
+ card: string;
232
+ raised: string;
233
+ overlay: string;
234
+ };
235
+ zIndices: {
236
+ "ui-base": string;
237
+ "ui-sticky": string;
238
+ "ui-dropdown": string;
239
+ "ui-overlay": string;
240
+ "ui-modal": string;
241
+ "ui-toast": string;
242
+ };
243
+ };
244
+ breakpoints: {
245
+ sm: {
246
+ minWidthPx: number;
247
+ };
248
+ md: {
249
+ minWidthPx: number;
250
+ };
251
+ lg: {
252
+ minWidthPx: number;
253
+ };
254
+ xl: {
255
+ minWidthPx: number;
256
+ };
257
+ };
258
+ strict: boolean;
259
+ dark: boolean;
260
+ reset: string;
261
+ utilities: {
262
+ placement: string;
263
+ };
264
+ };
265
+ export declare function mergeWind(base: Record<string, unknown>, host: Record<string, unknown>): Record<string, unknown>;
@@ -0,0 +1,133 @@
1
+ const engineWindTokens = {
2
+ "colors": {
3
+ "bg": "var(--color-bg)",
4
+ "fg": "var(--color-fg)",
5
+ "muted": "var(--color-muted)",
6
+ "sg-bg": "var(--sg-bg)",
7
+ "sg-fg": "var(--sg-fg)",
8
+ "sg-surface": "var(--sg-surface)",
9
+ "sg-surface-2": "var(--sg-surface-2)",
10
+ "sg-border": "var(--sg-border)",
11
+ "sg-border-strong": "var(--sg-border-strong)",
12
+ "sg-muted": "var(--sg-muted)",
13
+ "sg-accent": "var(--sg-accent)",
14
+ "sg-on-accent": "var(--sg-on-accent)",
15
+ "sg-focus": "var(--sg-focus)",
16
+ "sg-success": "var(--sg-success)"
17
+ },
18
+ "spacing": {
19
+ "hsp-2xs": "var(--spacing-hsp-2xs)",
20
+ "hsp-xs": "var(--spacing-hsp-xs)",
21
+ "hsp-sm": "var(--spacing-hsp-sm)",
22
+ "hsp-md": "var(--spacing-hsp-md)",
23
+ "hsp-lg": "var(--spacing-hsp-lg)",
24
+ "hsp-xl": "var(--spacing-hsp-xl)",
25
+ "hsp-2xl": "var(--spacing-hsp-2xl)",
26
+ "vsp-3xs": "var(--spacing-vsp-3xs)",
27
+ "vsp-2xs": "var(--spacing-vsp-2xs)",
28
+ "vsp-10": "var(--spacing-vsp-10)",
29
+ "vsp-xs": "var(--spacing-vsp-xs)",
30
+ "vsp-sm": "var(--spacing-vsp-sm)",
31
+ "vsp-md": "var(--spacing-vsp-md)",
32
+ "vsp-lg": "var(--spacing-vsp-lg)",
33
+ "vsp-xl": "var(--spacing-vsp-xl)",
34
+ "vsp-2xl": "var(--spacing-vsp-2xl)"
35
+ },
36
+ "fontSizes": {
37
+ "xs": {
38
+ "size": "var(--text-xs)",
39
+ "lineHeight": "var(--text-xs--line-height)"
40
+ },
41
+ "sm": {
42
+ "size": "var(--text-sm)",
43
+ "lineHeight": "var(--text-sm--line-height)"
44
+ },
45
+ "base": {
46
+ "size": "var(--text-base)",
47
+ "lineHeight": "var(--text-base--line-height)"
48
+ },
49
+ "lg": {
50
+ "size": "var(--text-lg)",
51
+ "lineHeight": "var(--text-lg--line-height)"
52
+ },
53
+ "xl": {
54
+ "size": "var(--text-xl)",
55
+ "lineHeight": "var(--text-xl--line-height)"
56
+ },
57
+ "2xl": {
58
+ "size": "var(--text-2xl)",
59
+ "lineHeight": "var(--text-2xl--line-height)"
60
+ },
61
+ "micro": {
62
+ "size": "var(--text-micro)"
63
+ },
64
+ "caption": {
65
+ "size": "var(--text-caption)"
66
+ },
67
+ "small": {
68
+ "size": "var(--text-small)"
69
+ },
70
+ "body": {
71
+ "size": "var(--text-body)"
72
+ },
73
+ "title": {
74
+ "size": "var(--text-title)"
75
+ },
76
+ "heading": {
77
+ "size": "var(--text-heading)"
78
+ },
79
+ "display": {
80
+ "size": "var(--text-display)"
81
+ }
82
+ },
83
+ "fontFamilies": {
84
+ "sans": "var(--font-sans)",
85
+ "mono": "var(--font-mono)"
86
+ },
87
+ "fontWeights": {
88
+ "normal": "var(--font-weight-normal)",
89
+ "medium": "var(--font-weight-medium)",
90
+ "semibold": "var(--font-weight-semibold)",
91
+ "bold": "var(--font-weight-bold)"
92
+ },
93
+ "lineHeights": {
94
+ "tight": "var(--leading-tight)",
95
+ "snug": "var(--leading-snug)",
96
+ "normal": "var(--leading-normal)",
97
+ "relaxed": "var(--leading-relaxed)"
98
+ },
99
+ "letterSpacings": { "wide": "0.025em" },
100
+ "radii": {
101
+ "default": "var(--radius-DEFAULT)",
102
+ "sm": "var(--radius-sm)",
103
+ "md": "var(--radius-md)",
104
+ "lg": "var(--radius-lg)"
105
+ },
106
+ "shadows": {
107
+ "card": "var(--shadow-card)",
108
+ "raised": "var(--shadow-raised)",
109
+ "overlay": "var(--shadow-overlay)"
110
+ },
111
+ "zIndices": {
112
+ "ui-base": "var(--z-index-ui-base)",
113
+ "ui-sticky": "var(--z-index-ui-sticky)",
114
+ "ui-dropdown": "var(--z-index-ui-dropdown)",
115
+ "ui-overlay": "var(--z-index-ui-overlay)",
116
+ "ui-modal": "var(--z-index-ui-modal)",
117
+ "ui-toast": "var(--z-index-ui-toast)"
118
+ }
119
+ };
120
+ const engineWindDefaults = { tokens: engineWindTokens, breakpoints: { sm: { minWidthPx: 640 }, md: { minWidthPx: 768 }, lg: { minWidthPx: 1024 }, xl: { minWidthPx: 1280 } }, strict: true, dark: false, reset: "owned-v1", utilities: { placement: "before-authored" } };
121
+ function mergeWind(base, host) {
122
+ const result = { ...base };
123
+ for (const [key, value] of Object.entries(host)) {
124
+ const prior = result[key];
125
+ result[key] = prior && value && typeof prior === "object" && typeof value === "object" && !Array.isArray(prior) && !Array.isArray(value) ? mergeWind(prior, value) : value;
126
+ }
127
+ return result;
128
+ }
129
+ export {
130
+ engineWindDefaults,
131
+ engineWindTokens,
132
+ mergeWind
133
+ };
@@ -1,5 +1,5 @@
1
1
  import type { ZfbDevMiddlewareHandler, ZfbPlugin, ZfbPluginLogger } from "@takazudo/zfb/plugins";
2
- import { type CompilePreviewCssResult } from "../preview-css/compile.js";
2
+ import { type CompilePreviewCssResult, type CompilePreviewCssOptions } from "../preview-css/compile.js";
3
3
  import { DEFAULT_PREVIEW_CSS_URL } from "../sg-context.js";
4
4
  export declare const PLUGIN_NAME = "@takazudo/zudo-sg/plugins/preview-css";
5
5
  export { DEFAULT_PREVIEW_CSS_URL };
@@ -8,13 +8,17 @@ export interface PreviewCssPluginOptions {
8
8
  previewStyles: string;
9
9
  /** Root-absolute URL path, before the base prefix. Default `/_zudo-sg/preview.css`. */
10
10
  previewCssUrl?: string;
11
+ wind?: Record<string, unknown>;
12
+ componentsRoots?: ReadonlyArray<{
13
+ dir: string;
14
+ }>;
11
15
  }
12
16
  export interface ResolvedPreviewCssPluginOptions {
13
17
  /** Forward-slash absolute path of the entry file. */
14
18
  previewStyles: string;
15
19
  previewCssUrl: string;
16
20
  }
17
- export type PreviewCssCompiler = (entryAbsPath: string) => Promise<CompilePreviewCssResult>;
21
+ export type PreviewCssCompiler = (entryAbsPath: string, options?: CompilePreviewCssOptions) => Promise<CompilePreviewCssResult>;
18
22
  type Logger = Pick<ZfbPluginLogger, "info" | "error">;
19
23
  /** Validates the options block and resolves `previewStyles`; throws `[zudo-sg] …` on invalid input. */
20
24
  export declare function resolvePreviewCssPluginOptions(projectRoot: string, options: Record<string, unknown>): ResolvedPreviewCssPluginOptions;
@@ -22,17 +26,15 @@ export declare function resolvePreviewCssPluginOptions(projectRoot: string, opti
22
26
  export declare function previewCssRoute(base: string | undefined, previewCssUrl: string): string;
23
27
  /** `<outDir><previewCssUrl>` — the base segment is deliberately NOT part of the on-disk path. */
24
28
  export declare function previewCssOutputPath(outDir: string, previewCssUrl: string): string;
25
- /** Every path whose mtime decides freshness: dependencies, scanned files and their directories. */
29
+ /** Include parent roots to discover nested additions and removals. */
26
30
  export declare function watchedPaths(result: Pick<CompilePreviewCssResult, "dependencies" | "sourceFiles">): string[];
27
- /** `<path>:<mtimeMs>` joined; a missing file stamps as `<path>:missing`. */
28
31
  export declare function computeStamp(paths: readonly string[]): string;
29
32
  export interface PreviewCssCache {
30
- /** Returns the current stylesheet, compiling only when an input changed. */
31
33
  get(): Promise<string>;
32
34
  }
33
- export declare function createPreviewCssCache(entry: string, compile?: PreviewCssCompiler, logger?: Logger): PreviewCssCache;
35
+ export declare function createPreviewCssCache(entry: string, compile?: PreviewCssCompiler, logger?: Logger, options?: CompilePreviewCssOptions): PreviewCssCache;
34
36
  export interface PreviewCssHandlerOptions {
35
- /** Full URL (base included) — see `previewCssRoute`. */
37
+ /** Unprefixed middleware URL; zfb strips the mount base before dispatch. */
36
38
  route: string;
37
39
  cache: PreviewCssCache;
38
40
  logger?: Logger;
@@ -1,12 +1,11 @@
1
1
  import { randomBytes } from "node:crypto";
2
2
  import { mkdir, rename, rm, writeFile } from "node:fs/promises";
3
- import { statSync } from "node:fs";
4
- import { dirname, join } from "node:path";
3
+ import { dirname, isAbsolute, join, resolve } from "node:path";
5
4
  import { resolveHostModule, toForwardSlash, withBaseUrl } from "../host-paths.js";
6
- import { compilePreviewCss } from "../preview-css/compile.js";
5
+ import { compilePreviewCss, contentStamp, inputGraph, sourceInputs, snapshotWind, resolveZfbCli, resolveInput } from "../preview-css/compile.js";
7
6
  import { DEFAULT_PREVIEW_CSS_URL } from "../sg-context.js";
8
7
  const PLUGIN_NAME = "@takazudo/zudo-sg/plugins/preview-css";
9
- const OPTION_KEYS = /* @__PURE__ */ new Set(["previewStyles", "previewCssUrl"]);
8
+ const OPTION_KEYS = /* @__PURE__ */ new Set(["previewStyles", "previewCssUrl", "wind", "componentsRoots"]);
10
9
  function fail(message) {
11
10
  throw new Error(`[zudo-sg] ${message}`);
12
11
  }
@@ -44,40 +43,58 @@ function previewCssRoute(base, previewCssUrl) {
44
43
  function previewCssOutputPath(outDir, previewCssUrl) {
45
44
  return join(outDir, ...previewCssUrl.split("/").filter(Boolean));
46
45
  }
47
- function mtimeOf(path) {
48
- try {
49
- return statSync(path).mtimeMs;
50
- } catch {
51
- return null;
52
- }
53
- }
54
46
  function watchedPaths(result) {
55
47
  const files = [...result.dependencies, ...result.sourceFiles];
56
- return [.../* @__PURE__ */ new Set([...files, ...files.map((file) => toForwardSlash(dirname(file)))])];
48
+ return [.../* @__PURE__ */ new Set([...files, ...files.map(dirname)])];
57
49
  }
58
50
  function computeStamp(paths) {
59
- return paths.map((path) => `${path}:${mtimeOf(path) ?? "missing"}`).join("\n");
51
+ return contentStamp(paths);
60
52
  }
61
- function createPreviewCssCache(entry, compile = compilePreviewCss, logger) {
53
+ function createPreviewCssCache(entry, compile = compilePreviewCss, logger, options = {}) {
54
+ const root = options.projectRoot ?? dirname(entry);
55
+ const wind = options.wind ?? {};
56
+ const packageRoot = (name) => dirname(resolveInput(`${name}/package.json`, join(root, "package.json")) ?? resolve(root, "node_modules", name, "package.json"));
57
+ const sourcesConfig = wind.sources;
58
+ const sourceAnchor = sourcesConfig?.__zfb_source_package ? packageRoot(sourcesConfig.__zfb_source_package) : root;
59
+ const sources = [
60
+ ...(options.sources ?? []).map((p) => resolve(root, p)),
61
+ ...(sourcesConfig?.roots ?? []).map((p) => resolve(sourceAnchor, p))
62
+ ];
63
+ const packageSources = (sourcesConfig?.packageRoots ?? []).map((p) => p.startsWith(".") || isAbsolute(p) ? resolve(sourceAnchor, p) : packageRoot(p));
64
+ const manifests = Object.values(wind.manifests ?? {}).map((m) => {
65
+ const anchor = m.__zfb_source_package ? packageRoot(m.__zfb_source_package) : root;
66
+ return resolveInput(m.path, join(anchor, "package.json")) ?? resolve(anchor, m.path);
67
+ });
68
+ const configEntries = ["zfb.config.ts", "zfb.config.js", "zfb.config.mjs"].map((p) => resolve(root, p));
69
+ const configPaths = () => inputGraph(configEntries);
70
+ const initialConfig = contentStamp(configPaths());
71
+ let previousPaths = [entry];
72
+ const paths = () => [...inputGraph([entry]), ...previousPaths, ...sourceInputs(root, sources), ...sourceInputs(root, packageSources, true), ...inputGraph(manifests)];
73
+ let compilerIdentity = "injected";
74
+ if (compile === compilePreviewCss) {
75
+ const compiler = resolveZfbCli(root);
76
+ previousPaths.push(compiler.packageJson, compiler.cli);
77
+ compilerIdentity = contentStamp([compiler.packageJson, compiler.cli]);
78
+ }
79
+ const data = JSON.stringify({ root, sources, packageSources, wind: snapshotWind(wind), compilerIdentity });
80
+ const stamp = () => contentStamp(paths(), data);
62
81
  let cached;
63
82
  let inflight;
64
- const recompile = async () => {
65
- const startedAt = Date.now();
66
- const result = await compile(entry);
67
- const paths = watchedPaths(result);
68
- const stamp = computeStamp(paths);
69
- const touchedDuringCompile = paths.some((path) => (mtimeOf(path) ?? 0) >= startedAt);
70
- cached = { css: result.css, paths, stamp: touchedDuringCompile ? "" : stamp };
71
- logger?.info(
72
- `preview css compiled (${result.candidateCount} candidates, ${result.dependencies.length} deps, ${result.sourceFiles.length} source files)`
73
- );
74
- return result.css;
75
- };
76
83
  return {
77
84
  get() {
85
+ if (contentStamp(configPaths()) !== initialConfig) return Promise.reject(new Error("[zudo-sg] host config changed; reload/restart zfb to resolve fresh wind config"));
78
86
  if (inflight) return inflight;
79
- if (cached && computeStamp(cached.paths) === cached.stamp) return Promise.resolve(cached.css);
80
- inflight = recompile().finally(() => {
87
+ const before = stamp();
88
+ if (cached?.stamp === before) return Promise.resolve(cached.css);
89
+ inflight = (async () => {
90
+ cached = void 0;
91
+ const result = await compile(entry, options);
92
+ const afterOriginal = stamp();
93
+ previousPaths = [.../* @__PURE__ */ new Set([...previousPaths, ...watchedPaths(result)])];
94
+ cached = { css: result.css, stamp: before === afterOriginal ? stamp() : "" };
95
+ logger?.info(`preview css compiled (${result.dependencies.length} deps, ${result.sourceFiles.length} source inputs)`);
96
+ return result.css;
97
+ })().finally(() => {
81
98
  inflight = void 0;
82
99
  });
83
100
  return inflight;
@@ -117,7 +134,6 @@ function createPreviewCssHandler({ route, cache, logger }) {
117
134
  }
118
135
  async function writePreviewCss(outDir, previewCssUrl, css) {
119
136
  const target = previewCssOutputPath(outDir, previewCssUrl);
120
- await rm(target, { force: true });
121
137
  await mkdir(dirname(target), { recursive: true });
122
138
  const temp = `${target}.${process.pid}-${randomBytes(6).toString("hex")}.tmp`;
123
139
  try {
@@ -129,22 +145,27 @@ async function writePreviewCss(outDir, previewCssUrl, css) {
129
145
  }
130
146
  return target;
131
147
  }
148
+ function compilerOptions(ctx) {
149
+ const wind = ctx.config.wind ?? ctx.options.wind;
150
+ return { projectRoot: ctx.projectRoot, wind, sources: (ctx.options.componentsRoots ?? []).map((r) => r.dir) };
151
+ }
132
152
  function createPreviewCssPlugin({ compile = compilePreviewCss } = {}) {
133
153
  const caches = /* @__PURE__ */ new Map();
134
- const cacheFor = (entry, logger) => {
135
- let cache = caches.get(entry);
154
+ const cacheFor = (entry, logger, options) => {
155
+ const key = JSON.stringify([entry, options]);
156
+ let cache = caches.get(key);
136
157
  if (!cache) {
137
- cache = createPreviewCssCache(entry, compile, logger);
138
- caches.set(entry, cache);
158
+ cache = createPreviewCssCache(entry, compile, logger, options);
159
+ caches.set(key, cache);
139
160
  }
140
161
  return cache;
141
162
  };
142
163
  const registerHandler = (ctx) => {
143
164
  const resolved = resolvePreviewCssPluginOptions(ctx.projectRoot, ctx.options);
144
- const route = previewCssRoute(ctx.config.base, resolved.previewCssUrl);
165
+ const route = resolved.previewCssUrl;
145
166
  ctx.register(
146
167
  route,
147
- createPreviewCssHandler({ route, cache: cacheFor(resolved.previewStyles, ctx.logger), logger: ctx.logger })
168
+ createPreviewCssHandler({ route, cache: cacheFor(resolved.previewStyles, ctx.logger, compilerOptions(ctx)), logger: ctx.logger })
148
169
  );
149
170
  };
150
171
  return {
@@ -158,10 +179,10 @@ function createPreviewCssPlugin({ compile = compilePreviewCss } = {}) {
158
179
  const resolved = resolvePreviewCssPluginOptions(ctx.projectRoot, ctx.options);
159
180
  const target = previewCssOutputPath(ctx.outDir, resolved.previewCssUrl);
160
181
  await rm(target, { force: true });
161
- const result = await compile(resolved.previewStyles);
182
+ const result = await compile(resolved.previewStyles, compilerOptions(ctx));
162
183
  await writePreviewCss(ctx.outDir, resolved.previewCssUrl, result.css);
163
184
  ctx.logger.info(
164
- `preview css written to ${toForwardSlash(target)} (${Buffer.byteLength(result.css)} bytes, ${result.candidateCount} candidates)`
185
+ `preview css written to ${toForwardSlash(target)} (${Buffer.byteLength(result.css)} bytes)`
165
186
  );
166
187
  }
167
188
  };
@@ -1,4 +1,4 @@
1
- import type { JSX } from "preact";
1
+ import { type Description } from "@takazudo/zfb/zudo-react";
2
2
  import type { StoryControl } from "../stories/index.js";
3
3
  /** One variant, flattened to the JSON-serializable shape an island can take. */
4
4
  export interface WorkbenchVariant {
@@ -77,8 +77,4 @@ export interface DetailWorkbenchProps {
77
77
  /** Which toolbar groups render. */
78
78
  toolbar?: WorkbenchToolbar;
79
79
  }
80
- declare function DetailWorkbench({ slug, variants, previewUrl, frameSandbox, frameAllow, selection, theme, previewParams, sizing, toolbar, }: DetailWorkbenchProps): JSX.Element;
81
- declare namespace DetailWorkbench {
82
- var displayName: string;
83
- }
84
- export default DetailWorkbench;
80
+ export default function DetailWorkbench({ slug, variants, previewUrl, frameSandbox, frameAllow, selection, theme, previewParams, sizing, toolbar, }: DetailWorkbenchProps): Description;