@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.
- package/CHANGELOG.md +62 -0
- package/README.md +59 -61
- package/dist/catalog/catalog-thumb.d.ts +1 -6
- package/dist/catalog/catalog-thumb.js +1 -2
- package/dist/catalog/component-thumb.d.ts +1 -6
- package/dist/catalog/component-thumb.js +8 -7
- package/dist/catalog/descriptor-thumb.d.ts +1 -6
- package/dist/catalog/descriptor-thumb.js +1 -2
- package/dist/chrome/_styleguide-layout.d.ts +8 -9
- package/dist/chrome/_styleguide-layout.js +3 -6
- package/dist/chrome/panel-scripts.d.ts +1 -3
- package/dist/chrome/panel-scripts.js +3 -3
- package/dist/cli/scaffold/component-scaffold.js +35 -16
- package/dist/code-panel/code-panel.d.ts +2 -8
- package/dist/code-panel/code-panel.js +34 -35
- package/dist/code-panel/copy-button.d.ts +1 -7
- package/dist/code-panel/copy-button.js +31 -48
- package/dist/code-panel/copy-text.d.ts +1 -0
- package/dist/code-panel/copy-text.js +26 -0
- package/dist/code-panel/editor-setup.d.ts +3 -0
- package/dist/code-panel/editor-setup.js +15 -3
- package/dist/code-panel/editor-theme.d.ts +2 -0
- package/dist/code-panel/editor-theme.js +54 -0
- package/dist/code-panel/source-editor.d.ts +10 -2
- package/dist/code-panel/source-editor.js +20 -19
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +6 -1
- package/dist/config/wind.d.ts +265 -0
- package/dist/config/wind.js +133 -0
- package/dist/plugins/preview-css.d.ts +9 -7
- package/dist/plugins/preview-css.js +58 -37
- package/dist/preview/detail-workbench.d.ts +2 -6
- package/dist/preview/detail-workbench.js +100 -65
- package/dist/preview/index.d.ts +4 -2
- package/dist/preview/index.js +7 -7
- package/dist/preview/preview-app.d.ts +2 -5
- package/dist/preview/preview-app.js +76 -46
- package/dist/preview/variant-frame-config.d.ts +47 -0
- package/dist/preview/variant-frame-config.js +50 -0
- package/dist/preview/variant-frame.d.ts +9 -53
- package/dist/preview/variant-frame.js +158 -149
- package/dist/preview-css/compile.d.ts +15 -29
- package/dist/preview-css/compile.js +183 -31
- package/dist/search/catalog-filter.d.ts +2 -6
- package/dist/search/catalog-filter.js +50 -42
- package/dist/stories/types.d.ts +5 -3
- package/dist/token-dashboard/create-token-dashboards.d.ts +3 -5
- package/dist/token-dashboard/create-token-dashboards.js +14 -44
- package/dist/token-dashboard/dashboard-inventory.d.ts +1 -1
- package/dist/token-dashboard/token-dashboard-adapter.d.ts +2 -0
- package/dist/token-dashboard/token-dashboard-adapter.js +9 -0
- package/dist/token-dashboard/token-dashboard-mount.d.ts +6 -0
- package/dist/token-dashboard/token-dashboard-mount.js +33 -0
- package/dist/token-tweak/preview-token-panel-bootstrap.d.ts +1 -6
- package/dist/token-tweak/preview-token-panel-bootstrap.js +4 -2
- package/dist/token-tweak/preview-tokens-button.d.ts +1 -5
- package/dist/token-tweak/preview-tokens-button.js +5 -4
- package/dist/wind.json +119 -0
- package/package.json +16 -19
- package/routes-src/_chrome.tsx +1 -3
- package/routes-src/_preview-app.tsx +3 -8
- package/routes-src/components-index.tsx +5 -10
- package/routes-src/components-preview.tsx +3 -9
- package/routes-src/components-slug.tsx +21 -24
- package/routes-src/tokens.tsx +4 -9
- package/styles.css +36 -11
- package/dist/safelist.css +0 -2
|
@@ -1,63 +1,22 @@
|
|
|
1
|
-
import type { JSX } from "preact";
|
|
2
1
|
import type { StoryControl } from "../stories/index.js";
|
|
3
|
-
import { type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
id: ViewportId;
|
|
7
|
-
label: string;
|
|
8
|
-
width: string;
|
|
9
|
-
}
|
|
10
|
-
export declare const VIEWPORTS: Viewport[];
|
|
11
|
-
/** Fluid width — the fixed presets are opt-in. */
|
|
12
|
-
export declare const DEFAULT_VIEWPORT_ID: ViewportId;
|
|
13
|
-
export type ThemeMode = "follow" | PreviewTheme;
|
|
14
|
-
export interface ThemeOption {
|
|
15
|
-
id: ThemeMode;
|
|
16
|
-
label: string;
|
|
17
|
-
}
|
|
18
|
-
export declare const THEME_OPTIONS: ThemeOption[];
|
|
19
|
-
export declare const DEFAULT_THEME_MODE: ThemeMode;
|
|
20
|
-
/**
|
|
21
|
-
* What a stage does about theme. `"none"` hands theme to the host (#883): the
|
|
22
|
-
* stage never posts `sg:setTheme`, so a preview document that picks its own
|
|
23
|
-
* theme (e.g. from a `previewParams` entry) is never overridden.
|
|
24
|
-
*/
|
|
25
|
-
export type FrameThemeMode = ThemeMode | "none";
|
|
26
|
-
/** Query keys the stage owns; `previewParams` entries using them are ignored. */
|
|
27
|
-
export declare const RESERVED_PREVIEW_PARAMS: readonly string[];
|
|
28
|
-
/**
|
|
29
|
-
* The preview document URL for one variant: `slug` and `variant` first, then
|
|
30
|
-
* every `previewParams` entry URL-encoded in insertion order. A reserved key
|
|
31
|
-
* in `previewParams` is dropped rather than thrown on — the identity pair must
|
|
32
|
-
* stay authoritative, and throwing from an island would blank the whole page.
|
|
33
|
-
*/
|
|
34
|
-
export declare function buildPreviewSrc(previewUrl: string, slug: string, exportName: string, previewParams?: Readonly<Record<string, string>>): string;
|
|
35
|
-
/**
|
|
36
|
-
* `allow-forms` is required by `packages/demo-ui/src/forms/` stories: #499 saw
|
|
37
|
-
* Chromium block submission without it (the submit listener did not fire and
|
|
38
|
-
* the frame did not navigate), while with it the listener fired and the frame
|
|
39
|
-
* navigated to the real action. The catalog form stories omit their enhancer
|
|
40
|
-
* islands, so `contact-form.stories.tsx` cannot show this: it renders
|
|
41
|
-
* `<ContactForm />` alone; `ContactFormEnhancer` lives at previewRoute
|
|
42
|
-
* `/preview/contact`, which the detail page links out to instead of rendering
|
|
43
|
-
* in a preview iframe.
|
|
44
|
-
*/
|
|
45
|
-
export declare const DEFAULT_FRAME_SANDBOX: readonly string[];
|
|
2
|
+
import { type FrameThemeMode, type ViewportId } from "./variant-frame-config.js";
|
|
3
|
+
import { type ReadonlySignal, type Description } from "@takazudo/zfb/zudo-react";
|
|
4
|
+
type Live<T> = T | ReadonlySignal<T>;
|
|
46
5
|
export interface VariantFrameProps {
|
|
47
6
|
slug: string;
|
|
48
7
|
/** Story export name (e.g. "Variants"). */
|
|
49
|
-
exportName: string
|
|
8
|
+
exportName: Live<string>;
|
|
50
9
|
/** Human label shown above the preview. */
|
|
51
|
-
name: string
|
|
10
|
+
name: Live<string>;
|
|
52
11
|
/** Declarative control descriptors (metadata only). */
|
|
53
|
-
controls?: StoryControl[]
|
|
12
|
+
controls?: Live<StoryControl[] | undefined>;
|
|
54
13
|
/**
|
|
55
14
|
* Toolbar-owned theme mode. "follow" tracks the catalog's `data-theme`;
|
|
56
15
|
* "none" never posts `sg:setTheme` (host-controlled theme).
|
|
57
16
|
*/
|
|
58
|
-
themeMode: FrameThemeMode
|
|
17
|
+
themeMode: Live<FrameThemeMode>;
|
|
59
18
|
/** Toolbar-owned viewport preset. */
|
|
60
|
-
viewportId: ViewportId
|
|
19
|
+
viewportId: Live<ViewportId>;
|
|
61
20
|
/**
|
|
62
21
|
* Base-prefixed URL of the preview route (the host's `withBase` applied to
|
|
63
22
|
* `routes.componentsPreview`). Defaults to the unprefixed PREVIEW_ROUTE_PATH.
|
|
@@ -83,8 +42,5 @@ export interface VariantFrameProps {
|
|
|
83
42
|
*/
|
|
84
43
|
fixedHeight?: number;
|
|
85
44
|
}
|
|
86
|
-
declare function VariantFrame(props: VariantFrameProps):
|
|
87
|
-
declare namespace VariantFrame {
|
|
88
|
-
var displayName: string;
|
|
89
|
-
}
|
|
45
|
+
declare function VariantFrame(props: VariantFrameProps): Description;
|
|
90
46
|
export default VariantFrame;
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx, jsxs } from "
|
|
3
|
-
import {
|
|
4
|
-
useEffect,
|
|
5
|
-
useLayoutEffect,
|
|
6
|
-
useRef,
|
|
7
|
-
useState
|
|
8
|
-
} from "preact/hooks";
|
|
2
|
+
import { jsx, jsxs } from "@takazudo/zfb/zudo-react/jsx-runtime";
|
|
9
3
|
import { onAfterNavigate } from "@takazudo/zudo-doc/transitions";
|
|
10
4
|
import {
|
|
11
5
|
MSG_REQUEST_READY,
|
|
@@ -21,44 +15,23 @@ import {
|
|
|
21
15
|
registerPreviewIframe,
|
|
22
16
|
unregisterPreviewIframe
|
|
23
17
|
} from "../token-tweak/preview-iframe-registry.js";
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
if (previewParams) {
|
|
41
|
-
for (const [key, value] of Object.entries(previewParams)) {
|
|
42
|
-
if (RESERVED_PREVIEW_PARAMS.includes(key)) continue;
|
|
43
|
-
src += `&${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return src;
|
|
47
|
-
}
|
|
48
|
-
function viewportWidth(id) {
|
|
49
|
-
const preset = VIEWPORTS.find((v) => v.id === id) ?? VIEWPORTS.at(-1);
|
|
50
|
-
return preset?.width ?? "100%";
|
|
51
|
-
}
|
|
52
|
-
function readCatalogTheme() {
|
|
53
|
-
const theme = document.documentElement.getAttribute("data-theme");
|
|
54
|
-
return theme === "light" || theme === "dark" ? theme : null;
|
|
18
|
+
import {
|
|
19
|
+
buildPreviewSrc,
|
|
20
|
+
DEFAULT_FRAME_SANDBOX,
|
|
21
|
+
INITIAL_FRAME_HEIGHT,
|
|
22
|
+
viewportWidth,
|
|
23
|
+
readCatalogTheme
|
|
24
|
+
} from "./variant-frame-config.js";
|
|
25
|
+
import {
|
|
26
|
+
computed,
|
|
27
|
+
signal,
|
|
28
|
+
getScope,
|
|
29
|
+
Show,
|
|
30
|
+
For
|
|
31
|
+
} from "@takazudo/zfb/zudo-react";
|
|
32
|
+
function read(value) {
|
|
33
|
+
return typeof value === "object" && value !== null && "value" in value ? value.value : value;
|
|
55
34
|
}
|
|
56
|
-
const INITIAL_FRAME_HEIGHT = 180;
|
|
57
|
-
const DEFAULT_FRAME_SANDBOX = [
|
|
58
|
-
"allow-same-origin",
|
|
59
|
-
"allow-scripts",
|
|
60
|
-
"allow-forms"
|
|
61
|
-
];
|
|
62
35
|
function VariantFrame(props) {
|
|
63
36
|
const {
|
|
64
37
|
slug,
|
|
@@ -73,16 +46,21 @@ function VariantFrame(props) {
|
|
|
73
46
|
previewParams,
|
|
74
47
|
fixedHeight
|
|
75
48
|
} = props;
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
49
|
+
const scope = getScope();
|
|
50
|
+
const iframeRef = { current: null };
|
|
51
|
+
let ready = false;
|
|
52
|
+
const height = signal(INITIAL_FRAME_HEIGHT);
|
|
53
|
+
const src = computed(
|
|
54
|
+
() => buildPreviewSrc(previewUrl, slug, read(exportName), previewParams)
|
|
55
|
+
);
|
|
56
|
+
let committedSrc = src.value;
|
|
57
|
+
scope.effect(() => {
|
|
58
|
+
const next = src.value;
|
|
59
|
+
if (next === committedSrc) return;
|
|
60
|
+
committedSrc = next;
|
|
61
|
+
ready = false;
|
|
62
|
+
height.value = INITIAL_FRAME_HEIGHT;
|
|
63
|
+
});
|
|
86
64
|
function post(message) {
|
|
87
65
|
const origin = window.location.origin;
|
|
88
66
|
if (origin === "null") return;
|
|
@@ -91,46 +69,45 @@ function VariantFrame(props) {
|
|
|
91
69
|
function sendTheme(theme) {
|
|
92
70
|
post({ type: MSG_SET_THEME, v: PROTOCOL_VERSION, theme });
|
|
93
71
|
}
|
|
94
|
-
const committedSrcRef = useRef(src);
|
|
95
|
-
useLayoutEffect(() => {
|
|
96
|
-
if (committedSrcRef.current === src) return;
|
|
97
|
-
committedSrcRef.current = src;
|
|
98
|
-
readyRef.current = false;
|
|
99
|
-
setHeight(INITIAL_FRAME_HEIGHT);
|
|
100
|
-
}, [src]);
|
|
101
72
|
function syncTheme() {
|
|
102
|
-
if (!
|
|
103
|
-
const mode =
|
|
73
|
+
if (!ready) return;
|
|
74
|
+
const mode = read(themeMode);
|
|
104
75
|
if (mode === "none") return;
|
|
105
76
|
const theme = mode === "follow" ? readCatalogTheme() : mode;
|
|
106
77
|
if (theme) sendTheme(theme);
|
|
107
78
|
}
|
|
108
|
-
|
|
79
|
+
scope.onActivate(() => {
|
|
109
80
|
function onMessage(e) {
|
|
110
81
|
if (e.origin !== window.location.origin) return;
|
|
111
82
|
if (e.source !== iframeRef.current?.contentWindow) return;
|
|
112
83
|
if (isReadyMessage(e.data)) {
|
|
113
|
-
if (!matchesPreviewIdentity(e.data,
|
|
114
|
-
|
|
84
|
+
if (!matchesPreviewIdentity(e.data, { slug, variant: read(exportName) }))
|
|
85
|
+
return;
|
|
86
|
+
ready = true;
|
|
115
87
|
syncTheme();
|
|
116
88
|
return;
|
|
117
89
|
}
|
|
118
90
|
if (isHeightMessage(e.data)) {
|
|
119
|
-
if (!matchesPreviewIdentity(e.data,
|
|
120
|
-
|
|
121
|
-
|
|
91
|
+
if (!matchesPreviewIdentity(e.data, { slug, variant: read(exportName) }))
|
|
92
|
+
return;
|
|
93
|
+
if (fixedHeight !== void 0) return;
|
|
94
|
+
height.value = Math.max(80, Math.ceil(e.data.height));
|
|
122
95
|
}
|
|
123
96
|
}
|
|
124
97
|
window.addEventListener("message", onMessage);
|
|
125
98
|
post({ type: MSG_REQUEST_READY, v: PROTOCOL_VERSION });
|
|
126
99
|
return () => window.removeEventListener("message", onMessage);
|
|
127
|
-
}
|
|
128
|
-
|
|
100
|
+
});
|
|
101
|
+
let previousThemeMode = read(themeMode);
|
|
102
|
+
scope.effect(() => {
|
|
103
|
+
const next = read(themeMode);
|
|
104
|
+
if (next === previousThemeMode) return;
|
|
105
|
+
previousThemeMode = next;
|
|
129
106
|
syncTheme();
|
|
130
|
-
}
|
|
131
|
-
|
|
107
|
+
});
|
|
108
|
+
scope.onActivate(() => {
|
|
132
109
|
const observer = new MutationObserver((records) => {
|
|
133
|
-
if (records.some((record) => record.attributeName === "data-theme") &&
|
|
110
|
+
if (records.some((record) => record.attributeName === "data-theme") && read(themeMode) === "follow") {
|
|
134
111
|
syncTheme();
|
|
135
112
|
}
|
|
136
113
|
});
|
|
@@ -139,54 +116,67 @@ function VariantFrame(props) {
|
|
|
139
116
|
attributeFilter: ["data-theme"]
|
|
140
117
|
});
|
|
141
118
|
const unsubscribeAfterNavigate = onAfterNavigate(() => {
|
|
142
|
-
if (
|
|
119
|
+
if (read(themeMode) === "follow") syncTheme();
|
|
143
120
|
});
|
|
144
121
|
return () => {
|
|
145
122
|
observer.disconnect();
|
|
146
123
|
unsubscribeAfterNavigate();
|
|
147
124
|
};
|
|
148
|
-
}
|
|
149
|
-
|
|
125
|
+
});
|
|
126
|
+
scope.onActivate(() => {
|
|
150
127
|
const iframe = iframeRef.current;
|
|
151
128
|
if (!iframe) return;
|
|
152
129
|
registerPreviewIframe(iframe);
|
|
153
130
|
return () => unregisterPreviewIframe(iframe);
|
|
154
|
-
}
|
|
131
|
+
});
|
|
155
132
|
function sendProps(props2) {
|
|
156
133
|
post({ type: MSG_UPDATE_PROPS, v: PROTOCOL_VERSION, props: props2 });
|
|
157
134
|
}
|
|
158
|
-
return /* @__PURE__ */ jsxs("section", { class: "border border-
|
|
159
|
-
/* @__PURE__ */ jsx("div", { class: "px-hsp-md py-vsp-2xs border-b border-
|
|
135
|
+
return /* @__PURE__ */ jsxs("section", { class: "border border-sg-border rounded-md overflow-hidden bg-sg-surface", children: [
|
|
136
|
+
/* @__PURE__ */ jsx("div", { class: "px-hsp-md py-vsp-2xs border-b border-sg-border bg-sg-surface-2", children: /* @__PURE__ */ jsx("span", { class: "text-caption leading-normal font-medium text-sg-fg", children: computed(() => read(name)) }) }),
|
|
160
137
|
/* @__PURE__ */ jsx(
|
|
161
138
|
"div",
|
|
162
139
|
{
|
|
163
140
|
role: "region",
|
|
164
141
|
"aria-label": "Preview viewport canvas",
|
|
165
|
-
|
|
166
|
-
class: "flex overflow-x-auto bg-
|
|
167
|
-
children: /* @__PURE__ */ jsx(
|
|
168
|
-
"
|
|
142
|
+
tabindex: 0,
|
|
143
|
+
class: "flex overflow-x-auto bg-sg-bg p-hsp-md focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-sg-focus",
|
|
144
|
+
children: /* @__PURE__ */ jsx(
|
|
145
|
+
"div",
|
|
169
146
|
{
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
147
|
+
class: "mx-auto shrink-0",
|
|
148
|
+
style: computed(() => ({ width: viewportWidth(read(viewportId)) })),
|
|
149
|
+
children: /* @__PURE__ */ jsx(
|
|
150
|
+
"iframe",
|
|
151
|
+
{
|
|
152
|
+
ref: iframeRef,
|
|
153
|
+
src,
|
|
154
|
+
title: computed(() => `${slug} \u2014 ${read(name)}`),
|
|
155
|
+
loading: "lazy",
|
|
156
|
+
sandbox: frameSandbox.join(" "),
|
|
157
|
+
allow: frameAllow ? frameAllow.join("; ") : void 0,
|
|
158
|
+
style: computed(() => ({
|
|
159
|
+
width: "100%",
|
|
160
|
+
height: `${fixedHeight ?? height.value}px`,
|
|
161
|
+
// An iframe's layout viewport is its content box. Keep the
|
|
162
|
+
// border at zero so a 1280px preset reaches the 1280px
|
|
163
|
+
// breakpoint; a visible border belongs on the wrapper.
|
|
164
|
+
border: "0",
|
|
165
|
+
display: "block"
|
|
166
|
+
}))
|
|
167
|
+
}
|
|
168
|
+
)
|
|
185
169
|
}
|
|
186
|
-
)
|
|
170
|
+
)
|
|
187
171
|
}
|
|
188
172
|
),
|
|
189
|
-
controls
|
|
173
|
+
/* @__PURE__ */ jsx(Show, { when: computed(() => (read(controls) ?? []).length > 0), children: () => /* @__PURE__ */ jsx("div", { class: "border-t border-sg-border px-hsp-md py-vsp-xs", children: /* @__PURE__ */ jsx(For, { each: computed(() => [src.value]), by: (value) => value, children: () => /* @__PURE__ */ jsx(
|
|
174
|
+
ControlsPanel,
|
|
175
|
+
{
|
|
176
|
+
controls: read(controls) ?? [],
|
|
177
|
+
onChange: sendProps
|
|
178
|
+
}
|
|
179
|
+
) }) }) })
|
|
190
180
|
] });
|
|
191
181
|
}
|
|
192
182
|
function seedState(controls) {
|
|
@@ -206,16 +196,38 @@ function ControlsPanel({
|
|
|
206
196
|
controls,
|
|
207
197
|
onChange
|
|
208
198
|
}) {
|
|
209
|
-
const
|
|
210
|
-
|
|
199
|
+
const values = signal(seedState(controls));
|
|
200
|
+
const open = signal(true);
|
|
201
|
+
const fields = Object.fromEntries(
|
|
202
|
+
controls.map((control) => [
|
|
203
|
+
control.prop,
|
|
204
|
+
signal(String(control.defaultValue))
|
|
205
|
+
])
|
|
206
|
+
);
|
|
207
|
+
const fieldRefs = Object.fromEntries(
|
|
208
|
+
controls.map((control) => [
|
|
209
|
+
control.prop,
|
|
210
|
+
{ current: null }
|
|
211
|
+
])
|
|
212
|
+
);
|
|
213
|
+
const checks = Object.fromEntries(
|
|
214
|
+
controls.map((control) => [
|
|
215
|
+
control.prop,
|
|
216
|
+
signal(Boolean(control.defaultValue))
|
|
217
|
+
])
|
|
211
218
|
);
|
|
212
|
-
const [open, setOpen] = useState(true);
|
|
213
219
|
function apply(next) {
|
|
214
|
-
|
|
220
|
+
values.value = next;
|
|
221
|
+
for (const control of controls) {
|
|
222
|
+
fields[control.prop].value = String(next[control.prop]);
|
|
223
|
+
checks[control.prop].value = Boolean(next[control.prop]);
|
|
224
|
+
const field = fieldRefs[control.prop].current;
|
|
225
|
+
if (field) field.value = String(next[control.prop]);
|
|
226
|
+
}
|
|
215
227
|
onChange(next);
|
|
216
228
|
}
|
|
217
229
|
function set(prop, value) {
|
|
218
|
-
apply({ ...values, [prop]: value });
|
|
230
|
+
apply({ ...values.value, [prop]: value });
|
|
219
231
|
}
|
|
220
232
|
function reset() {
|
|
221
233
|
apply(seedState(controls));
|
|
@@ -226,33 +238,35 @@ function ControlsPanel({
|
|
|
226
238
|
"button",
|
|
227
239
|
{
|
|
228
240
|
type: "button",
|
|
229
|
-
|
|
241
|
+
"on:click": () => {
|
|
242
|
+
open.value = !open.value;
|
|
243
|
+
},
|
|
230
244
|
"aria-expanded": open,
|
|
231
|
-
class: "flex items-center gap-hsp-2xs text-caption leading-normal uppercase tracking-wide text-
|
|
245
|
+
class: "flex items-center gap-hsp-2xs text-caption leading-normal uppercase tracking-wide text-sg-muted hover:text-sg-fg cursor-pointer",
|
|
232
246
|
children: [
|
|
233
|
-
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: open ? "\u25BC" : "\u25B6" }),
|
|
247
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: computed(() => open.value ? "\u25BC" : "\u25B6") }),
|
|
234
248
|
"Controls"
|
|
235
249
|
]
|
|
236
250
|
}
|
|
237
251
|
),
|
|
238
|
-
open
|
|
252
|
+
/* @__PURE__ */ jsx(Show, { when: open, children: () => /* @__PURE__ */ jsx(
|
|
239
253
|
"button",
|
|
240
254
|
{
|
|
241
255
|
type: "button",
|
|
242
|
-
|
|
243
|
-
class: "text-caption leading-normal rounded-sm border border-
|
|
256
|
+
"on:click": reset,
|
|
257
|
+
class: "text-caption leading-normal rounded-sm border border-sg-border px-hsp-xs py-vsp-3xs text-sg-muted hover:text-sg-fg transition-colors cursor-pointer",
|
|
244
258
|
children: "Reset"
|
|
245
259
|
}
|
|
246
|
-
)
|
|
260
|
+
) })
|
|
247
261
|
] }),
|
|
248
|
-
open
|
|
249
|
-
/* @__PURE__ */ jsx("span", { class: "text-
|
|
262
|
+
/* @__PURE__ */ jsx(Show, { when: open, children: () => /* @__PURE__ */ jsx("div", { class: "flex flex-wrap gap-hsp-md", children: controls.map((control) => /* @__PURE__ */ jsxs("label", { class: "flex items-center gap-hsp-2xs text-small text-sg-fg", children: [
|
|
263
|
+
/* @__PURE__ */ jsx("span", { class: "text-sg-muted", children: control.label }),
|
|
250
264
|
control.type === "select" && /* @__PURE__ */ jsx(
|
|
251
265
|
"select",
|
|
252
266
|
{
|
|
253
|
-
class: "border border-
|
|
254
|
-
|
|
255
|
-
|
|
267
|
+
class: "border border-sg-border rounded-sm bg-sg-surface px-hsp-2xs py-vsp-3xs text-small",
|
|
268
|
+
modelValue: fields[control.prop],
|
|
269
|
+
"on:change": (e) => set(control.prop, e.currentTarget.value),
|
|
256
270
|
children: control.options.map((opt) => /* @__PURE__ */ jsx("option", { value: opt, children: opt }))
|
|
257
271
|
}
|
|
258
272
|
),
|
|
@@ -260,31 +274,32 @@ function ControlsPanel({
|
|
|
260
274
|
"input",
|
|
261
275
|
{
|
|
262
276
|
type: "checkbox",
|
|
263
|
-
|
|
264
|
-
|
|
277
|
+
modelChecked: checks[control.prop],
|
|
278
|
+
"on:change": (e) => set(control.prop, e.currentTarget.checked)
|
|
265
279
|
}
|
|
266
280
|
),
|
|
267
281
|
control.type === "text" && /* @__PURE__ */ jsx(
|
|
268
282
|
"input",
|
|
269
283
|
{
|
|
270
284
|
type: "text",
|
|
271
|
-
|
|
272
|
-
class: "border border-
|
|
273
|
-
|
|
285
|
+
modelValue: fields[control.prop],
|
|
286
|
+
class: "border border-sg-border rounded-sm bg-sg-surface px-hsp-2xs py-vsp-3xs text-small",
|
|
287
|
+
"on:input": (e) => set(control.prop, e.currentTarget.value)
|
|
274
288
|
}
|
|
275
289
|
),
|
|
276
290
|
control.type === "number" && (control.ui === "input" ? /* @__PURE__ */ jsx(
|
|
277
291
|
"input",
|
|
278
292
|
{
|
|
279
293
|
type: "number",
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
294
|
+
ref: fieldRefs[control.prop],
|
|
295
|
+
value: String(values.value[control.prop]),
|
|
296
|
+
min: control.min === void 0 ? void 0 : String(control.min),
|
|
297
|
+
max: control.max === void 0 ? void 0 : String(control.max),
|
|
298
|
+
step: control.step === void 0 ? void 0 : String(control.step),
|
|
299
|
+
class: "w-[5rem] border border-sg-border rounded-sm bg-sg-surface px-hsp-2xs py-vsp-3xs text-small",
|
|
300
|
+
"on:input": (e) => set(
|
|
286
301
|
control.prop,
|
|
287
|
-
coerceNumber(e.
|
|
302
|
+
coerceNumber(e.currentTarget.value, control)
|
|
288
303
|
)
|
|
289
304
|
}
|
|
290
305
|
) : /* @__PURE__ */ jsxs("span", { class: "flex items-center gap-hsp-2xs", children: [
|
|
@@ -292,39 +307,33 @@ function ControlsPanel({
|
|
|
292
307
|
"input",
|
|
293
308
|
{
|
|
294
309
|
type: "range",
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
310
|
+
ref: fieldRefs[control.prop],
|
|
311
|
+
value: String(values.value[control.prop]),
|
|
312
|
+
min: control.min === void 0 ? void 0 : String(control.min),
|
|
313
|
+
max: control.max === void 0 ? void 0 : String(control.max),
|
|
314
|
+
step: control.step === void 0 ? void 0 : String(control.step),
|
|
315
|
+
"on:input": (e) => set(
|
|
300
316
|
control.prop,
|
|
301
|
-
coerceNumber(e.
|
|
317
|
+
coerceNumber(e.currentTarget.value, control)
|
|
302
318
|
)
|
|
303
319
|
}
|
|
304
320
|
),
|
|
305
|
-
/* @__PURE__ */ jsx("span", { class: "text-
|
|
321
|
+
/* @__PURE__ */ jsx("span", { class: "text-sg-muted tabular-nums w-[2.5rem] text-right", children: computed(() => String(values.value[control.prop])) })
|
|
306
322
|
] })),
|
|
307
323
|
control.type === "color" && /* @__PURE__ */ jsx(
|
|
308
324
|
"input",
|
|
309
325
|
{
|
|
310
326
|
type: "color",
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
327
|
+
ref: fieldRefs[control.prop],
|
|
328
|
+
value: String(values.value[control.prop]),
|
|
329
|
+
class: "h-[1.5rem] w-[2.5rem] border border-sg-border rounded-sm bg-sg-surface",
|
|
330
|
+
"on:input": (e) => set(control.prop, e.currentTarget.value)
|
|
314
331
|
}
|
|
315
332
|
)
|
|
316
|
-
] })) })
|
|
333
|
+
] })) }) })
|
|
317
334
|
] });
|
|
318
335
|
}
|
|
319
|
-
VariantFrame.displayName = "VariantFrame";
|
|
320
336
|
var variant_frame_default = VariantFrame;
|
|
321
337
|
export {
|
|
322
|
-
DEFAULT_FRAME_SANDBOX,
|
|
323
|
-
DEFAULT_THEME_MODE,
|
|
324
|
-
DEFAULT_VIEWPORT_ID,
|
|
325
|
-
RESERVED_PREVIEW_PARAMS,
|
|
326
|
-
THEME_OPTIONS,
|
|
327
|
-
VIEWPORTS,
|
|
328
|
-
buildPreviewSrc,
|
|
329
338
|
variant_frame_default as default
|
|
330
339
|
};
|
|
@@ -1,40 +1,26 @@
|
|
|
1
|
-
/** Attribute carried by the preview document's `<html>`. */
|
|
2
1
|
export declare const PREVIEW_DOC_ATTRIBUTE = "data-sg-preview-doc";
|
|
3
2
|
export interface CompilePreviewCssOptions {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
projectRoot?: string;
|
|
4
|
+
wind?: Record<string, unknown>;
|
|
5
|
+
sources?: string[];
|
|
6
6
|
}
|
|
7
7
|
export interface CompilePreviewCssResult {
|
|
8
|
-
/** The compiled, rescoped, optimized stylesheet. */
|
|
9
8
|
css: string;
|
|
10
|
-
/**
|
|
11
|
-
* Absolute forward-slash paths of every CSS/JS file the compile read: the
|
|
12
|
-
* entry first, then each `onDependency` file (imports, plugins, configs).
|
|
13
|
-
* Deduplicated. A change to any of these requires a recompile.
|
|
14
|
-
*/
|
|
15
9
|
dependencies: string[];
|
|
16
|
-
/**
|
|
17
|
-
* Absolute forward-slash paths of the content files the candidate scan
|
|
18
|
-
* read (the `@source` globs). Editing one can add/remove utilities, so a
|
|
19
|
-
* dev watcher should treat them as recompile triggers as well.
|
|
20
|
-
*/
|
|
21
10
|
sourceFiles: string[];
|
|
22
|
-
/**
|
|
11
|
+
/** The public CSS CLI does not expose a candidate count; always zero. */
|
|
23
12
|
candidateCount: number;
|
|
24
13
|
}
|
|
25
|
-
/**
|
|
26
|
-
* zfb injects the host's global stylesheet into every route AFTER the preview
|
|
27
|
-
* `<link>` with no per-route opt-out, and both worlds define colliding
|
|
28
|
-
* `--color-*` tokens. Rescoping the preview world's token roots to
|
|
29
|
-
* `:root[data-sg-preview-doc]` (specificity 0,1,1 vs 0,1,0) keeps the preview
|
|
30
|
-
* tokens winning regardless of link order. Must run on the unminified
|
|
31
|
-
* `build()` output — `optimize` collapses the whitespace these patterns match.
|
|
32
|
-
*/
|
|
33
14
|
export declare function scopeTokensToPreviewDoc(css: string): string;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
15
|
+
export declare function resolveZfbCli(projectRoot: string): {
|
|
16
|
+
cli: string;
|
|
17
|
+
packageJson: string;
|
|
18
|
+
};
|
|
19
|
+
/** Reject values that JSON would silently omit/change in the child snapshot. */
|
|
20
|
+
export declare function snapshotWind(wind?: Record<string, unknown>): string;
|
|
21
|
+
export declare function resolveInput(spec: string, from: string): string | undefined;
|
|
22
|
+
export declare function inputGraph(entries: string[]): string[];
|
|
23
|
+
/** Re-enumerate every root, including empty and nested directories. */
|
|
24
|
+
export declare function sourceInputs(projectRoot: string, sources: string[], includeNodeModules?: boolean): string[];
|
|
25
|
+
export declare function contentStamp(paths: readonly string[], data?: string): string;
|
|
40
26
|
export declare function compilePreviewCss(entryAbsPath: string, options?: CompilePreviewCssOptions): Promise<CompilePreviewCssResult>;
|