@takazudo/zudo-sg 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/LICENSE +21 -0
- package/README.md +99 -0
- package/bin/zudo-sg.js +6 -0
- package/dist/catalog/component-thumb.d.ts +78 -0
- package/dist/catalog/component-thumb.js +110 -0
- package/dist/catalog/index.d.ts +4 -0
- package/dist/catalog/index.js +40 -0
- package/dist/catalog/tile-size.d.ts +28 -0
- package/dist/catalog/tile-size.js +42 -0
- package/dist/chrome/_styleguide-layout.d.ts +59 -0
- package/dist/chrome/_styleguide-layout.js +69 -0
- package/dist/chrome/index.d.ts +4 -0
- package/dist/chrome/index.js +39 -0
- package/dist/chrome/panel-contract.d.ts +15 -0
- package/dist/chrome/panel-contract.js +65 -0
- package/dist/chrome/panel-scripts-source.d.ts +2 -0
- package/dist/chrome/panel-scripts-source.js +121 -0
- package/dist/chrome/panel-scripts.d.ts +5 -0
- package/dist/chrome/panel-scripts.js +12 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +74 -0
- package/dist/cli/config.d.ts +54 -0
- package/dist/cli/config.js +14 -0
- package/dist/cli/registry/build-registry-source.d.ts +27 -0
- package/dist/cli/registry/build-registry-source.js +77 -0
- package/dist/cli/registry/discover-stories.d.ts +36 -0
- package/dist/cli/registry/discover-stories.js +61 -0
- package/dist/cli/registry/gen-registry.d.ts +23 -0
- package/dist/cli/registry/gen-registry.js +74 -0
- package/dist/cli/scaffold/component-scaffold.d.ts +64 -0
- package/dist/cli/scaffold/component-scaffold.js +233 -0
- package/dist/cli/scaffold/new-component.d.ts +17 -0
- package/dist/cli/scaffold/new-component.js +119 -0
- package/dist/cli/token-manifest/css-var-parser.d.ts +9 -0
- package/dist/cli/token-manifest/css-var-parser.js +23 -0
- package/dist/cli/token-manifest/gen-token-manifest.d.ts +16 -0
- package/dist/cli/token-manifest/gen-token-manifest.js +49 -0
- package/dist/cli/token-manifest/ui-token-manifest.d.ts +78 -0
- package/dist/cli/token-manifest/ui-token-manifest.js +340 -0
- package/dist/code-panel/code-panel.d.ts +18 -0
- package/dist/code-panel/code-panel.js +76 -0
- package/dist/code-panel/copy-button.d.ts +15 -0
- package/dist/code-panel/copy-button.js +92 -0
- package/dist/code-panel/css-injection.d.ts +6 -0
- package/dist/code-panel/css-injection.js +37 -0
- package/dist/code-panel/editor-setup.d.ts +10 -0
- package/dist/code-panel/editor-setup.js +33 -0
- package/dist/code-panel/index.d.ts +6 -0
- package/dist/code-panel/index.js +10 -0
- package/dist/code-panel/source-editor.d.ts +8 -0
- package/dist/code-panel/source-editor.js +39 -0
- package/dist/config/index.d.ts +73 -0
- package/dist/config/index.js +68 -0
- package/dist/host-paths.d.ts +19 -0
- package/dist/host-paths.js +41 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +18 -0
- package/dist/islands.d.ts +2 -0
- package/dist/islands.js +6 -0
- package/dist/plugins/preview-css.d.ts +53 -0
- package/dist/plugins/preview-css.js +183 -0
- package/dist/plugins/routes.d.ts +84 -0
- package/dist/plugins/routes.js +237 -0
- package/dist/plugins/zdtp-apply-proxy.d.ts +58 -0
- package/dist/plugins/zdtp-apply-proxy.js +171 -0
- package/dist/preview/detail-workbench.d.ts +22 -0
- package/dist/preview/detail-workbench.js +179 -0
- package/dist/preview/index.d.ts +8 -0
- package/dist/preview/index.js +21 -0
- package/dist/preview/messages.d.ts +34 -0
- package/dist/preview/messages.js +32 -0
- package/dist/preview/preview-app.d.ts +11 -0
- package/dist/preview/preview-app.js +87 -0
- package/dist/preview/route.d.ts +1 -0
- package/dist/preview/route.js +5 -0
- package/dist/preview/variant-frame.d.ts +42 -0
- package/dist/preview/variant-frame.js +289 -0
- package/dist/preview-css/compile.d.ts +40 -0
- package/dist/preview-css/compile.js +42 -0
- package/dist/preview-css/index.d.ts +2 -0
- package/dist/preview-css/index.js +10 -0
- package/dist/registry/component-docs.d.ts +38 -0
- package/dist/registry/component-docs.js +34 -0
- package/dist/registry/index.d.ts +6 -0
- package/dist/registry/index.js +28 -0
- package/dist/registry/nav-nodes.d.ts +22 -0
- package/dist/registry/nav-nodes.js +36 -0
- package/dist/registry/registry.d.ts +68 -0
- package/dist/registry/registry.js +91 -0
- package/dist/safelist.css +2 -0
- package/dist/search/catalog-filter.d.ts +12 -0
- package/dist/search/catalog-filter.js +175 -0
- package/dist/search/index.d.ts +2 -0
- package/dist/search/index.js +4 -0
- package/dist/sg-context.d.ts +24 -0
- package/dist/sg-context.js +6 -0
- package/dist/sg-routes.d.ts +12 -0
- package/dist/sg-routes.js +17 -0
- package/dist/stories/index.d.ts +2 -0
- package/dist/stories/index.js +4 -0
- package/dist/stories/types.d.ts +164 -0
- package/dist/stories/types.js +6 -0
- package/dist/token-dashboard/create-token-dashboards.d.ts +24 -0
- package/dist/token-dashboard/create-token-dashboards.js +57 -0
- package/dist/token-dashboard/dashboard-inventory.d.ts +11 -0
- package/dist/token-dashboard/dashboard-inventory.js +13 -0
- package/dist/token-dashboard/index.d.ts +5 -0
- package/dist/token-dashboard/index.js +20 -0
- package/dist/token-dashboard/ui-token-tabs.d.ts +53 -0
- package/dist/token-dashboard/ui-token-tabs.js +159 -0
- package/dist/token-tweak/bootstrap-preview-token-panel.d.ts +12 -0
- package/dist/token-tweak/bootstrap-preview-token-panel.js +18 -0
- package/dist/token-tweak/iframe-css-vars-bridge.d.ts +35 -0
- package/dist/token-tweak/iframe-css-vars-bridge.js +73 -0
- package/dist/token-tweak/index.d.ts +6 -0
- package/dist/token-tweak/index.js +36 -0
- package/dist/token-tweak/preview-iframe-registry.d.ts +16 -0
- package/dist/token-tweak/preview-iframe-registry.js +48 -0
- package/dist/token-tweak/preview-token-panel-bootstrap.d.ts +6 -0
- package/dist/token-tweak/preview-token-panel-bootstrap.js +17 -0
- package/dist/token-tweak/preview-token-panel-config.d.ts +42 -0
- package/dist/token-tweak/preview-token-panel-config.js +37 -0
- package/dist/token-tweak/preview-tokens-button.d.ts +5 -0
- package/dist/token-tweak/preview-tokens-button.js +17 -0
- package/dist/token-tweak/token-panel-native-bootstrap.d.ts +17 -0
- package/dist/token-tweak/token-panel-native-bootstrap.js +49 -0
- package/package.json +172 -0
- package/routes-src/_chrome.tsx +83 -0
- package/routes-src/_context.ts +15 -0
- package/routes-src/_preview-app.tsx +32 -0
- package/routes-src/_registry.ts +12 -0
- package/routes-src/components-index.tsx +95 -0
- package/routes-src/components-preview.tsx +55 -0
- package/routes-src/components-slug.tsx +145 -0
- package/routes-src/tokens.tsx +76 -0
- package/styles.css +612 -0
- package/virtual-modules.d.ts +25 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @takazudo/zudo-sg — story-authoring contract
|
|
3
|
+
*
|
|
4
|
+
* The shape every `*.stories.tsx` module satisfies so the engine's registry
|
|
5
|
+
* (`@takazudo/zudo-sg/registry`) can discover and render stories. Exported as
|
|
6
|
+
* `@takazudo/zudo-sg/stories`; host component packages (e.g.
|
|
7
|
+
* `packages/demo-ui/src/stories/types.ts`) re-export it rather than copy it.
|
|
8
|
+
*/
|
|
9
|
+
import type { ComponentChildren } from "preact";
|
|
10
|
+
/**
|
|
11
|
+
* `StoryMeta.category` is an OPEN string — any value is valid, so a host
|
|
12
|
+
* extending the catalog can introduce a new category without touching this
|
|
13
|
+
* contract. Group order is data owned by the host (`categoryOrder`), not a
|
|
14
|
+
* type: the engine's `createRegistry` (`@takazudo/zudo-sg/registry`) renders
|
|
15
|
+
* the listed categories first and appends every unlisted one alphabetically.
|
|
16
|
+
*/
|
|
17
|
+
export type StoryCategory = string;
|
|
18
|
+
/**
|
|
19
|
+
* Per-file metadata. Default-exported from each `*.stories.tsx`.
|
|
20
|
+
* `title` is the component's display name; `category` buckets it in the nav.
|
|
21
|
+
*/
|
|
22
|
+
export interface StoryMeta {
|
|
23
|
+
/** Display name, e.g. "Button". Unique within a category. */
|
|
24
|
+
title: string;
|
|
25
|
+
/** Sidebar bucket. */
|
|
26
|
+
category: StoryCategory;
|
|
27
|
+
/** One-sentence description shown under the title. */
|
|
28
|
+
description: string;
|
|
29
|
+
/**
|
|
30
|
+
* Short usage snippet (import + minimal JSX) shown in the catalog's "Usage"
|
|
31
|
+
* block. Authored as a plain string so the catalog can render it verbatim in
|
|
32
|
+
* a code block without parsing the component source.
|
|
33
|
+
*/
|
|
34
|
+
usage: string;
|
|
35
|
+
/**
|
|
36
|
+
* Optional ordering hint within a category (lower = earlier). Defaults to
|
|
37
|
+
* alphabetical by `title` when omitted.
|
|
38
|
+
*/
|
|
39
|
+
order?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Optional link to a REAL page route (e.g. "/preview/dialog-with-fetch")
|
|
42
|
+
* that demos this component live — a separate mechanism from `render` and
|
|
43
|
+
* from the catalog's own `/components/preview` variant iframe
|
|
44
|
+
* (`PREVIEW_ROUTE_PATH`). Request mocking (MSW or otherwise) is permitted
|
|
45
|
+
* only inside the page this points to, never in `render` or component
|
|
46
|
+
* source. When set, the catalog shows it as a "Live demo" link. See
|
|
47
|
+
* STORIES.md §6 → "The `previewRoute` escape hatch".
|
|
48
|
+
*/
|
|
49
|
+
previewRoute?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* One renderable variant. `render` returns the preview node; `name` labels it.
|
|
53
|
+
*
|
|
54
|
+
* Generic over the driving component's props `P` so a variant's `controls`
|
|
55
|
+
* (see `StoryControl<P>` below) are checked against real prop names — and,
|
|
56
|
+
* where the prop's own type is informative (e.g. a string-literal union),
|
|
57
|
+
* against real prop values too. `P` defaults to `Record<string, unknown>`, so
|
|
58
|
+
* the bare `Story` name is a compatible alias for variants that have no
|
|
59
|
+
* controls to check (or whose `render` composes more than one component's
|
|
60
|
+
* props) — migrating a file to `Story<SomeProps>` is opt-in, one file at a
|
|
61
|
+
* time.
|
|
62
|
+
*
|
|
63
|
+
* `controls` is an OPTIONAL, declarative description of the knobs the catalog
|
|
64
|
+
* exposes for live editing. The catalog seeds each control's `defaultValue`
|
|
65
|
+
* into the render args and pushes live edits over the `sg:updateProps` channel,
|
|
66
|
+
* so `render(args)` re-renders with the tweaked props. A control-bearing
|
|
67
|
+
* variant should render a SINGLE arg-driven instance (not a multi-variant
|
|
68
|
+
* showcase) so the knobs visibly drive the preview.
|
|
69
|
+
*
|
|
70
|
+
* `source` is the OPTIONAL exact JSX string for this variant. When present the
|
|
71
|
+
* catalog shows it verbatim (the contract's "explicit source" path). When
|
|
72
|
+
* absent the catalog falls back to its own extraction (see STORIES.md →
|
|
73
|
+
* "Source extraction"). Co-locating `source` is recommended for variants whose
|
|
74
|
+
* `render` body is non-obvious.
|
|
75
|
+
*/
|
|
76
|
+
export interface Story<P = Record<string, unknown>> {
|
|
77
|
+
/** Variant label, e.g. "Primary". */
|
|
78
|
+
name: string;
|
|
79
|
+
/**
|
|
80
|
+
* Returns the preview node. Must be pure + synchronous.
|
|
81
|
+
*
|
|
82
|
+
* Receives the merged render args — control defaults overlaid with any live
|
|
83
|
+
* overrides from the controls panel — typed as a partial `P` so `args.foo`
|
|
84
|
+
* reads as `foo`'s real prop type with no `as` cast. The parameter is
|
|
85
|
+
* optional/defaulted so non-control variants (which ignore `args`) still
|
|
86
|
+
* render with no arguments.
|
|
87
|
+
*/
|
|
88
|
+
render: (args?: Partial<P>) => ComponentChildren;
|
|
89
|
+
/** Optional live-control descriptors that drive `render(args)`. */
|
|
90
|
+
controls?: StoryControl<P>[];
|
|
91
|
+
/** Optional verbatim JSX source string for the code panel. */
|
|
92
|
+
source?: string;
|
|
93
|
+
}
|
|
94
|
+
/** Narrows to `T` when it's a string, else falls back to plain `string` (e.g. under the untyped `Record<string, unknown>` default). */
|
|
95
|
+
type StringPropValue<T> = T extends string ? T : string;
|
|
96
|
+
/** Same fallback shape as `StringPropValue`, for boolean-valued props. */
|
|
97
|
+
type BooleanPropValue<T> = T extends boolean ? T : boolean;
|
|
98
|
+
/** Same fallback shape as `StringPropValue`, for number-valued props. */
|
|
99
|
+
type NumberPropValue<T> = T extends number ? T : number;
|
|
100
|
+
/**
|
|
101
|
+
* A single live-control descriptor, discriminated by `type` and keyed to a
|
|
102
|
+
* real prop of `P` (`prop: keyof P & string` — renaming that prop breaks every
|
|
103
|
+
* control naming it). `defaultValue` (and `options`, for `select`) narrow to
|
|
104
|
+
* that prop's own value type where `P` is informative — e.g. a `select` on a
|
|
105
|
+
* prop typed as a string-literal union restricts `options`/`defaultValue` to
|
|
106
|
+
* that union — so a value only a former version of the prop accepted also
|
|
107
|
+
* fails to typecheck.
|
|
108
|
+
*/
|
|
109
|
+
export type StoryControl<P = Record<string, unknown>> = {
|
|
110
|
+
[K in keyof P & string]: {
|
|
111
|
+
type: "select";
|
|
112
|
+
/** Prop name this control drives, e.g. "variant". */
|
|
113
|
+
prop: K;
|
|
114
|
+
label: string;
|
|
115
|
+
options: StringPropValue<NonNullable<P[K]>>[];
|
|
116
|
+
defaultValue: StringPropValue<NonNullable<P[K]>>;
|
|
117
|
+
} | {
|
|
118
|
+
type: "boolean";
|
|
119
|
+
prop: K;
|
|
120
|
+
label: string;
|
|
121
|
+
defaultValue: BooleanPropValue<NonNullable<P[K]>>;
|
|
122
|
+
} | {
|
|
123
|
+
type: "text";
|
|
124
|
+
prop: K;
|
|
125
|
+
label: string;
|
|
126
|
+
defaultValue: StringPropValue<NonNullable<P[K]>>;
|
|
127
|
+
} | {
|
|
128
|
+
type: "number";
|
|
129
|
+
prop: K;
|
|
130
|
+
label: string;
|
|
131
|
+
defaultValue: NumberPropValue<NonNullable<P[K]>>;
|
|
132
|
+
min?: number;
|
|
133
|
+
max?: number;
|
|
134
|
+
step?: number;
|
|
135
|
+
/**
|
|
136
|
+
* Editor widget. `range` (default) renders a slider with a numeric
|
|
137
|
+
* readout when min/max are present; `input` renders a plain numeric box.
|
|
138
|
+
*/
|
|
139
|
+
ui?: "range" | "input";
|
|
140
|
+
} | {
|
|
141
|
+
type: "color";
|
|
142
|
+
prop: K;
|
|
143
|
+
label: string;
|
|
144
|
+
/** CSS color string, e.g. "#2563eb". */
|
|
145
|
+
defaultValue: StringPropValue<NonNullable<P[K]>>;
|
|
146
|
+
};
|
|
147
|
+
}[keyof P & string];
|
|
148
|
+
/**
|
|
149
|
+
* The shape `import.meta.glob` yields per module: a default `meta` plus an
|
|
150
|
+
* index signature of named `Story` exports. The registry iterates own
|
|
151
|
+
* enumerable keys, skips `default`, and treats the rest as stories.
|
|
152
|
+
*/
|
|
153
|
+
export interface StoryModule {
|
|
154
|
+
default: StoryMeta;
|
|
155
|
+
[exportName: string]: StoryMeta | Story;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Authoring helper — identity function that pins a value to `Story<P>` so
|
|
159
|
+
* editors autocomplete `name`/`render`/`controls`/`source` (and check
|
|
160
|
+
* `controls` against `P`). Using it is optional; a plain object literal that
|
|
161
|
+
* satisfies `Story<P>` is equally valid.
|
|
162
|
+
*/
|
|
163
|
+
export declare function defineStory<P = Record<string, unknown>>(story: Story<P>): Story<P>;
|
|
164
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** @jsxRuntime automatic */
|
|
2
|
+
/** @jsxImportSource preact */
|
|
3
|
+
import type { TabConfig } from "@takazudo/zdtp";
|
|
4
|
+
import type { JSX } from "preact";
|
|
5
|
+
import type { UiDesignTokensManifest } from "./ui-token-tabs.js";
|
|
6
|
+
export interface CreateTokenDashboardsOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Inline CSS custom properties applied to the wrapping `<section>` — e.g. a
|
|
9
|
+
* host's per-mode chrome colors (`--zdtp-dashboard-{light,dark}-{bg,fg}`)
|
|
10
|
+
* resolved from its own color-scheme settings. Chrome-color resolution is
|
|
11
|
+
* host-specific (site theme config), so this package never computes it
|
|
12
|
+
* itself; omit to render without a chrome color override.
|
|
13
|
+
*/
|
|
14
|
+
chromeStyle?: JSX.CSSProperties;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Static declared values; kept outside the live playground's copy boundary.
|
|
18
|
+
*
|
|
19
|
+
* Takes the host's generated design-token manifest and the shared tab config
|
|
20
|
+
* built from it (`buildUiTokenTabs(manifest)`, reused as-is from the host's
|
|
21
|
+
* runtime preview panel so both stay in sync) as plain data props — this
|
|
22
|
+
* component has no host import of its own.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createTokenDashboards(manifest: UiDesignTokensManifest, tabs: readonly TabConfig[], options?: CreateTokenDashboardsOptions): JSX.Element;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { jsx, jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { TokenDashboard } from "@takazudo/zdtp/dashboard";
|
|
3
|
+
import { buildDashboardPreviewOverrides, UI_DASHBOARD_PREVIEW_TEXT } from "./ui-token-tabs.js";
|
|
4
|
+
function createTokenDashboards(manifest, tabs, options = {}) {
|
|
5
|
+
const dashboardPreviewOverrides = buildDashboardPreviewOverrides(manifest);
|
|
6
|
+
return /* @__PURE__ */ jsxs("section", { class: "mb-vsp-xl flex flex-col gap-vsp-lg", style: options.chromeStyle, children: [
|
|
7
|
+
/* @__PURE__ */ jsxs("div", { class: "max-w-[56rem]", children: [
|
|
8
|
+
/* @__PURE__ */ jsx("h2", { class: "mb-vsp-2xs text-xl font-semibold text-fg", children: "Declared defaults" }),
|
|
9
|
+
/* @__PURE__ */ jsxs("p", { class: "text-muted", children: [
|
|
10
|
+
"These are the declared defaults of the design-token manifest, shown as light, dark, and shared token references. The light and dark frames show only tokens whose declared value differs by mode (",
|
|
11
|
+
/* @__PURE__ */ jsx("code", { children: "light-dark()" }),
|
|
12
|
+
" pairs and rows that reference them); the shared frame lists every other token once and follows the site theme. Samples are isolated from the live panels and anything saved in them. Nothing here is clickable or editable."
|
|
13
|
+
] })
|
|
14
|
+
] }),
|
|
15
|
+
/* @__PURE__ */ jsx(
|
|
16
|
+
TokenDashboard,
|
|
17
|
+
{
|
|
18
|
+
id: "ui-defaults-light",
|
|
19
|
+
mode: "light",
|
|
20
|
+
chrome: "light",
|
|
21
|
+
include: "mode-dependent",
|
|
22
|
+
title: "UI tokens \u2014 mode-dependent defaults (light)",
|
|
23
|
+
tabs,
|
|
24
|
+
previewOverrides: dashboardPreviewOverrides,
|
|
25
|
+
previewText: UI_DASHBOARD_PREVIEW_TEXT
|
|
26
|
+
}
|
|
27
|
+
),
|
|
28
|
+
/* @__PURE__ */ jsx(
|
|
29
|
+
TokenDashboard,
|
|
30
|
+
{
|
|
31
|
+
id: "ui-defaults-dark",
|
|
32
|
+
mode: "dark",
|
|
33
|
+
chrome: "dark",
|
|
34
|
+
include: "mode-dependent",
|
|
35
|
+
title: "UI tokens \u2014 mode-dependent defaults (dark)",
|
|
36
|
+
tabs,
|
|
37
|
+
previewOverrides: dashboardPreviewOverrides,
|
|
38
|
+
previewText: UI_DASHBOARD_PREVIEW_TEXT
|
|
39
|
+
}
|
|
40
|
+
),
|
|
41
|
+
/* @__PURE__ */ jsx(
|
|
42
|
+
TokenDashboard,
|
|
43
|
+
{
|
|
44
|
+
id: "ui-defaults-shared",
|
|
45
|
+
chrome: "host",
|
|
46
|
+
include: "mode-independent",
|
|
47
|
+
title: "UI tokens \u2014 shared defaults (mode-independent)",
|
|
48
|
+
tabs,
|
|
49
|
+
previewOverrides: dashboardPreviewOverrides,
|
|
50
|
+
previewText: UI_DASHBOARD_PREVIEW_TEXT
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
] });
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
createTokenDashboards
|
|
57
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Measured SSR inventory for the three declared-defaults dashboards.
|
|
3
|
+
*
|
|
4
|
+
* Keep these values in sync with the rows emitted by zdtp's `include` filters
|
|
5
|
+
* for the host's UI design-token manifest. They are shared by the dashboard
|
|
6
|
+
* unit test and the host's tokens-dashboard e2e so those checks use one
|
|
7
|
+
* measured source of truth.
|
|
8
|
+
*/
|
|
9
|
+
export declare const UI_DASHBOARD_TOKEN_COUNT = 102;
|
|
10
|
+
export declare const UI_DASHBOARD_MODE_DEPENDENT_COUNT = 15;
|
|
11
|
+
export declare const UI_DASHBOARD_MODE_INDEPENDENT_COUNT = 87;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const UI_DASHBOARD_TOKEN_COUNT = 102;
|
|
2
|
+
const UI_DASHBOARD_MODE_DEPENDENT_COUNT = 15;
|
|
3
|
+
const UI_DASHBOARD_MODE_INDEPENDENT_COUNT = 87;
|
|
4
|
+
if (UI_DASHBOARD_MODE_DEPENDENT_COUNT + UI_DASHBOARD_MODE_INDEPENDENT_COUNT !== UI_DASHBOARD_TOKEN_COUNT) {
|
|
5
|
+
throw new Error(
|
|
6
|
+
"UI dashboard inventory counts must add up to the total token count"
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
UI_DASHBOARD_MODE_DEPENDENT_COUNT,
|
|
11
|
+
UI_DASHBOARD_MODE_INDEPENDENT_COUNT,
|
|
12
|
+
UI_DASHBOARD_TOKEN_COUNT
|
|
13
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createTokenDashboards } from "./create-token-dashboards.js";
|
|
2
|
+
export type { CreateTokenDashboardsOptions } from "./create-token-dashboards.js";
|
|
3
|
+
export { buildUiTokenTabs, buildDashboardPreviewOverrides, UI_DASHBOARD_PREVIEW_TEXT, } from "./ui-token-tabs.js";
|
|
4
|
+
export type { PaletteColor, UiDesignTokensManifest } from "./ui-token-tabs.js";
|
|
5
|
+
export { UI_DASHBOARD_TOKEN_COUNT, UI_DASHBOARD_MODE_DEPENDENT_COUNT, UI_DASHBOARD_MODE_INDEPENDENT_COUNT, } from "./dashboard-inventory.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createTokenDashboards } from "./create-token-dashboards.js";
|
|
2
|
+
import {
|
|
3
|
+
buildUiTokenTabs,
|
|
4
|
+
buildDashboardPreviewOverrides,
|
|
5
|
+
UI_DASHBOARD_PREVIEW_TEXT
|
|
6
|
+
} from "./ui-token-tabs.js";
|
|
7
|
+
import {
|
|
8
|
+
UI_DASHBOARD_TOKEN_COUNT,
|
|
9
|
+
UI_DASHBOARD_MODE_DEPENDENT_COUNT,
|
|
10
|
+
UI_DASHBOARD_MODE_INDEPENDENT_COUNT
|
|
11
|
+
} from "./dashboard-inventory.js";
|
|
12
|
+
export {
|
|
13
|
+
UI_DASHBOARD_MODE_DEPENDENT_COUNT,
|
|
14
|
+
UI_DASHBOARD_MODE_INDEPENDENT_COUNT,
|
|
15
|
+
UI_DASHBOARD_PREVIEW_TEXT,
|
|
16
|
+
UI_DASHBOARD_TOKEN_COUNT,
|
|
17
|
+
buildDashboardPreviewOverrides,
|
|
18
|
+
buildUiTokenTabs,
|
|
19
|
+
createTokenDashboards
|
|
20
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build-safe zdtp tab data for a host's UI design-token manifest.
|
|
3
|
+
*
|
|
4
|
+
* This module is shared by a host's runtime preview panel and its static
|
|
5
|
+
* token dashboard (via `createTokenDashboards`). It deliberately contains
|
|
6
|
+
* only data-shaping code — no manifest import, no browser/dev-server/panel-
|
|
7
|
+
* runtime dependencies — so a host can call it from plain Node during a
|
|
8
|
+
* build. The host's generated manifest (e.g. `ui-design-tokens-manifest.ts`,
|
|
9
|
+
* written by `zudo-sg gen-token-manifest`) is passed in, shaped as
|
|
10
|
+
* `UiDesignTokensManifest`, so this module never depends on any specific
|
|
11
|
+
* host's token set.
|
|
12
|
+
*/
|
|
13
|
+
import type { TabConfig, TokenDef } from "@takazudo/zdtp";
|
|
14
|
+
import type { DashboardPreviewKind } from "@takazudo/zdtp/dashboard";
|
|
15
|
+
/**
|
|
16
|
+
* Tier-1 raw palette color — a plain name/value descriptor (NOT `TokenDef`)
|
|
17
|
+
* because zdtp's `TokenDef.control` has no `"color"` option; this module
|
|
18
|
+
* builds palette entries into `{ kind: "color" }` TierItems inline.
|
|
19
|
+
*/
|
|
20
|
+
export interface PaletteColor {
|
|
21
|
+
/** Palette key without the `--palette-` prefix, e.g. "neutral-2". */
|
|
22
|
+
name: string;
|
|
23
|
+
/** Raw color value (e.g. an oklch() string). */
|
|
24
|
+
value: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The shape a host's generated design-token manifest must provide. A host
|
|
28
|
+
* assembles this from its own generated manifest module (whatever that
|
|
29
|
+
* module's export names are) before calling `buildUiTokenTabs` /
|
|
30
|
+
* `buildDashboardPreviewOverrides` / `createTokenDashboards`.
|
|
31
|
+
*/
|
|
32
|
+
export interface UiDesignTokensManifest {
|
|
33
|
+
paletteColors: readonly PaletteColor[];
|
|
34
|
+
colorTokens: readonly TokenDef[];
|
|
35
|
+
spacingTokens: readonly TokenDef[];
|
|
36
|
+
fontTokens: readonly TokenDef[];
|
|
37
|
+
sizeTokens: readonly TokenDef[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Shared tab data consumed by both a host's runtime preview panel and its
|
|
41
|
+
* static dashboard. Callers should build this ONCE per manifest and reuse
|
|
42
|
+
* the same array reference for both consumers, so their identities,
|
|
43
|
+
* ordering, defaults, and preview metadata cannot drift apart.
|
|
44
|
+
*/
|
|
45
|
+
export declare function buildUiTokenTabs(manifest: UiDesignTokensManifest): TabConfig[];
|
|
46
|
+
/**
|
|
47
|
+
* Explicit dashboard samples for manifest rows whose editor kind cannot
|
|
48
|
+
* describe the desired read-only sample: light-dark() text rows need color
|
|
49
|
+
* swatches, and shadow declarations need shadow samples.
|
|
50
|
+
*/
|
|
51
|
+
export declare function buildDashboardPreviewOverrides(manifest: UiDesignTokensManifest): Readonly<Record<string, DashboardPreviewKind>>;
|
|
52
|
+
/** Fixed specimen text shared by the light and dark dashboard instances. */
|
|
53
|
+
export declare const UI_DASHBOARD_PREVIEW_TEXT: string;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
function toTierItem(t, opts) {
|
|
2
|
+
let kind;
|
|
3
|
+
if (t.control === "select") {
|
|
4
|
+
kind = { kind: "select", options: t.options ?? [] };
|
|
5
|
+
} else if (t.control === "text") {
|
|
6
|
+
kind = { kind: "text" };
|
|
7
|
+
} else if (opts?.numberKind) {
|
|
8
|
+
kind = { kind: "number", step: t.step, unit: t.unit };
|
|
9
|
+
} else {
|
|
10
|
+
kind = {
|
|
11
|
+
kind: "length",
|
|
12
|
+
step: t.step,
|
|
13
|
+
unit: t.unit
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const item = {
|
|
17
|
+
id: t.id,
|
|
18
|
+
cssVar: t.cssVar,
|
|
19
|
+
label: t.label,
|
|
20
|
+
default: t.default,
|
|
21
|
+
type: kind
|
|
22
|
+
};
|
|
23
|
+
if (t.pill) item.pill = t.pill;
|
|
24
|
+
if (t.readonly) item.readonly = true;
|
|
25
|
+
return item;
|
|
26
|
+
}
|
|
27
|
+
function tierFromGroup(tokens, groupId, label, opts) {
|
|
28
|
+
return {
|
|
29
|
+
id: groupId,
|
|
30
|
+
label,
|
|
31
|
+
items: tokens.filter((t) => t.group === groupId).map((t) => toTierItem(t, opts))
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function splitPaletteName(name) {
|
|
35
|
+
const lineMatch = /^(line-[^-]+)-(.+)$/.exec(name);
|
|
36
|
+
if (lineMatch) return { family: lineMatch[1], step: lineMatch[2] };
|
|
37
|
+
const stateMatch = /^state-(.+)$/.exec(name);
|
|
38
|
+
if (stateMatch) return { family: "state", step: stateMatch[1] ?? null };
|
|
39
|
+
const match = /^(.+)-(\d+)$/.exec(name);
|
|
40
|
+
if (!match) return { family: name, step: null };
|
|
41
|
+
const [, family, step] = match;
|
|
42
|
+
return { family: family ?? name, step: step ?? null };
|
|
43
|
+
}
|
|
44
|
+
function buildPaletteTiers(paletteColors) {
|
|
45
|
+
const families = /* @__PURE__ */ new Map();
|
|
46
|
+
for (const { name, value } of paletteColors) {
|
|
47
|
+
const { family } = splitPaletteName(name);
|
|
48
|
+
const items = families.get(family) ?? [];
|
|
49
|
+
items.push({
|
|
50
|
+
id: `palette-${name}`,
|
|
51
|
+
cssVar: `--palette-${name}`,
|
|
52
|
+
label: `palette-${name}`,
|
|
53
|
+
default: value,
|
|
54
|
+
type: { kind: "color", format: "oklch" }
|
|
55
|
+
});
|
|
56
|
+
families.set(family, items);
|
|
57
|
+
}
|
|
58
|
+
return Array.from(families.entries()).map(([family, items]) => ({
|
|
59
|
+
id: `palette-${family}`,
|
|
60
|
+
label: family.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" \xB7 "),
|
|
61
|
+
items
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
function buildPaletteTab(paletteColors) {
|
|
65
|
+
return {
|
|
66
|
+
id: "palette",
|
|
67
|
+
label: "Palette",
|
|
68
|
+
tiers: buildPaletteTiers(paletteColors)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function buildColorTab(colorTokens) {
|
|
72
|
+
return {
|
|
73
|
+
id: "ui-color",
|
|
74
|
+
label: "Color",
|
|
75
|
+
tiers: [
|
|
76
|
+
tierFromGroup(colorTokens, "surface", "Surface"),
|
|
77
|
+
tierFromGroup(colorTokens, "text", "Text"),
|
|
78
|
+
tierFromGroup(colorTokens, "accent", "Accent"),
|
|
79
|
+
tierFromGroup(colorTokens, "rail", "Rail"),
|
|
80
|
+
tierFromGroup(colorTokens, "state", "State")
|
|
81
|
+
]
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function buildSpacingTab(spacingTokens) {
|
|
85
|
+
return {
|
|
86
|
+
id: "spacing",
|
|
87
|
+
label: "Spacing",
|
|
88
|
+
tiers: [
|
|
89
|
+
{ ...tierFromGroup(spacingTokens, "hsp", "Horizontal spacing"), preview: "bar" },
|
|
90
|
+
{ ...tierFromGroup(spacingTokens, "vsp", "Vertical spacing"), preview: "bar" }
|
|
91
|
+
]
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function buildFontTab(fontTokens) {
|
|
95
|
+
return {
|
|
96
|
+
id: "font",
|
|
97
|
+
label: "Font",
|
|
98
|
+
tiers: [
|
|
99
|
+
{ ...tierFromGroup(fontTokens, "font-size", "Font size"), preview: "size" },
|
|
100
|
+
{
|
|
101
|
+
...tierFromGroup(fontTokens, "font-size-lh", "Font size / line height", {
|
|
102
|
+
numberKind: true
|
|
103
|
+
}),
|
|
104
|
+
preview: "line-height",
|
|
105
|
+
// Tier-level base is a compromise for the per-size leading rows.
|
|
106
|
+
previewBase: "--text-base"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
...tierFromGroup(fontTokens, "font-weight", "Font weight"),
|
|
110
|
+
preview: "weight"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
...tierFromGroup(fontTokens, "line-height", "Line height", {
|
|
114
|
+
numberKind: true
|
|
115
|
+
}),
|
|
116
|
+
preview: "line-height",
|
|
117
|
+
previewBase: "--text-base"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
...tierFromGroup(fontTokens, "font-family", "Font family"),
|
|
121
|
+
preview: "family"
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function buildSizeTab(sizeTokens) {
|
|
127
|
+
return {
|
|
128
|
+
id: "size",
|
|
129
|
+
label: "Size",
|
|
130
|
+
tiers: [
|
|
131
|
+
{ ...tierFromGroup(sizeTokens, "radius", "Radius"), preview: "radius" },
|
|
132
|
+
// No preview: free-text tier, no matching preview kind applies.
|
|
133
|
+
tierFromGroup(sizeTokens, "shadow", "Shadow")
|
|
134
|
+
]
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function buildUiTokenTabs(manifest) {
|
|
138
|
+
return [
|
|
139
|
+
buildColorTab(manifest.colorTokens),
|
|
140
|
+
buildPaletteTab(manifest.paletteColors),
|
|
141
|
+
buildSpacingTab(manifest.spacingTokens),
|
|
142
|
+
buildFontTab(manifest.fontTokens),
|
|
143
|
+
buildSizeTab(manifest.sizeTokens)
|
|
144
|
+
];
|
|
145
|
+
}
|
|
146
|
+
function buildDashboardPreviewOverrides(manifest) {
|
|
147
|
+
const overrides = {};
|
|
148
|
+
for (const token of manifest.colorTokens) overrides[token.cssVar] = "color";
|
|
149
|
+
for (const token of manifest.sizeTokens) {
|
|
150
|
+
if (token.group === "shadow") overrides[token.cssVar] = "shadow";
|
|
151
|
+
}
|
|
152
|
+
return overrides;
|
|
153
|
+
}
|
|
154
|
+
const UI_DASHBOARD_PREVIEW_TEXT = "Design tokens give an interface a shared rhythm across pages and themes. This specimen keeps the declared values visible while you compare scale, color, and shape (102 entries). \u30C7\u30B6\u30A4\u30F3\u30C8\u30FC\u30AF\u30F3\u306F\u3001\u753B\u9762\u306E\u30EA\u30BA\u30E0\u3068\u8AAD\u307F\u3084\u3059\u3055\u3092\u652F\u3048\u307E\u3059\u3002\n\nThe light and dark views are isolated from panel edits, so saved tweaks never change this reference. \u6570\u5B57\u306E 0\u30011\u30012\u30013\u30014 \u3082\u5BA3\u8A00\u3055\u308C\u305F\u5024\u306E\u4E00\u90E8\u3068\u3057\u3066\u78BA\u8A8D\u3067\u304D\u307E\u3059\u3002";
|
|
155
|
+
export {
|
|
156
|
+
UI_DASHBOARD_PREVIEW_TEXT,
|
|
157
|
+
buildDashboardPreviewOverrides,
|
|
158
|
+
buildUiTokenTabs
|
|
159
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Production bootstrap for the preview zdtp panel instance.
|
|
3
|
+
*
|
|
4
|
+
* zudo-doc's native bootstrap owns the lazy zdtp boundary (on-demand
|
|
5
|
+
* `import()`, retry, persisted-state probe), so nothing here imports zdtp
|
|
6
|
+
* eagerly. zdtp self-injects its stylesheet at mount time; no CSS import is
|
|
7
|
+
* needed.
|
|
8
|
+
*/
|
|
9
|
+
import type { PanelConfig } from "@takazudo/zdtp";
|
|
10
|
+
/** Id of the host's SSR pre-hydration toggle-capture `<script>`. */
|
|
11
|
+
export declare const PREVIEW_TOKEN_PANEL_PREHYDRATE_SCRIPT_ID = "zdtp-preview-prehydrate";
|
|
12
|
+
export declare function bootstrapPreviewTokenPanel(getConfig: () => PanelConfig): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { bootstrapDesignTokenPanel } from "@takazudo/zudo-doc/design-token-panel-bootstrap";
|
|
2
|
+
import { PREVIEW_TOKEN_PANEL_TOGGLE_EVENT } from "./preview-token-panel-config.js";
|
|
3
|
+
import { drainPrehydrationToggle, installOwnerConsoleHelpers } from "./token-panel-native-bootstrap.js";
|
|
4
|
+
const PREVIEW_TOKEN_PANEL_PREHYDRATE_SCRIPT_ID = "zdtp-preview-prehydrate";
|
|
5
|
+
let bootstrapped = false;
|
|
6
|
+
function bootstrapPreviewTokenPanel(getConfig) {
|
|
7
|
+
if (typeof window === "undefined") return;
|
|
8
|
+
if (!bootstrapped) {
|
|
9
|
+
bootstrapped = true;
|
|
10
|
+
bootstrapDesignTokenPanel(getConfig);
|
|
11
|
+
installOwnerConsoleHelpers(getConfig);
|
|
12
|
+
}
|
|
13
|
+
drainPrehydrationToggle(PREVIEW_TOKEN_PANEL_PREHYDRATE_SCRIPT_ID, PREVIEW_TOKEN_PANEL_TOGGLE_EVENT);
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
PREVIEW_TOKEN_PANEL_PREHYDRATE_SCRIPT_ID,
|
|
17
|
+
bootstrapPreviewTokenPanel
|
|
18
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Envelope `source` tag. Part of the wire contract (e2e/preview-token-panel.spec.ts mirrors it). */
|
|
2
|
+
export declare const BRIDGE_SOURCE: "zudo-sg-token-tweak-bridge";
|
|
3
|
+
export type CssVarPair = readonly [name: string, value: string];
|
|
4
|
+
export interface ApplyCssVarsMessage {
|
|
5
|
+
source: typeof BRIDGE_SOURCE;
|
|
6
|
+
type: "apply-css-vars";
|
|
7
|
+
vars: ReadonlyArray<CssVarPair>;
|
|
8
|
+
}
|
|
9
|
+
export interface ClearCssVarsMessage {
|
|
10
|
+
source: typeof BRIDGE_SOURCE;
|
|
11
|
+
type: "clear-css-vars";
|
|
12
|
+
names: ReadonlyArray<string>;
|
|
13
|
+
}
|
|
14
|
+
export interface ReadyMessage {
|
|
15
|
+
source: typeof BRIDGE_SOURCE;
|
|
16
|
+
type: "ready";
|
|
17
|
+
}
|
|
18
|
+
export type BridgeMessage = ApplyCssVarsMessage | ClearCssVarsMessage | ReadyMessage;
|
|
19
|
+
/** Type guard. Accepts any postMessage payload and confirms it is a bridge envelope. */
|
|
20
|
+
export declare function isBridgeMessage(value: unknown): value is BridgeMessage;
|
|
21
|
+
/** Send `apply-css-vars` to the iframe. No-op when the iframe has not loaded. */
|
|
22
|
+
export declare function sendApplyCssVars(iframe: HTMLIFrameElement | null, vars: ReadonlyArray<CssVarPair>): void;
|
|
23
|
+
/** Send `clear-css-vars` to the iframe so it removes inline overrides. */
|
|
24
|
+
export declare function sendClearCssVars(iframe: HTMLIFrameElement | null, names: ReadonlyArray<string>): void;
|
|
25
|
+
/**
|
|
26
|
+
* Install a message listener inside the preview iframe document that applies
|
|
27
|
+
* any incoming CSS-var batches onto `documentElement.style`. Returns a
|
|
28
|
+
* teardown function. Intended to be called once at iframe boot.
|
|
29
|
+
*/
|
|
30
|
+
export declare function installIframeReceiver(target?: Window): () => void;
|
|
31
|
+
/**
|
|
32
|
+
* Install a `ready` listener on the panel side so callers can defer the
|
|
33
|
+
* initial CSS-var sync until the iframe document has booted.
|
|
34
|
+
*/
|
|
35
|
+
export declare function onIframeReady(expectedSource: Window | null, callback: () => void): () => void;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const BRIDGE_SOURCE = "zudo-sg-token-tweak-bridge";
|
|
2
|
+
function isBridgeMessage(value) {
|
|
3
|
+
if (!value || typeof value !== "object") return false;
|
|
4
|
+
const v = value;
|
|
5
|
+
if (v.source !== BRIDGE_SOURCE) return false;
|
|
6
|
+
switch (v.type) {
|
|
7
|
+
case "apply-css-vars":
|
|
8
|
+
return Array.isArray(v.vars) && v.vars.every(isCssVarPair);
|
|
9
|
+
case "clear-css-vars":
|
|
10
|
+
return Array.isArray(v.names) && v.names.every((name) => typeof name === "string");
|
|
11
|
+
case "ready":
|
|
12
|
+
return true;
|
|
13
|
+
default:
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function isCssVarPair(value) {
|
|
18
|
+
return Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "string";
|
|
19
|
+
}
|
|
20
|
+
function sendApplyCssVars(iframe, vars) {
|
|
21
|
+
const win = iframe?.contentWindow;
|
|
22
|
+
if (!win) return;
|
|
23
|
+
const message = { source: BRIDGE_SOURCE, type: "apply-css-vars", vars };
|
|
24
|
+
win.postMessage(message, window.location.origin);
|
|
25
|
+
}
|
|
26
|
+
function sendClearCssVars(iframe, names) {
|
|
27
|
+
const win = iframe?.contentWindow;
|
|
28
|
+
if (!win) return;
|
|
29
|
+
const message = { source: BRIDGE_SOURCE, type: "clear-css-vars", names };
|
|
30
|
+
win.postMessage(message, window.location.origin);
|
|
31
|
+
}
|
|
32
|
+
function installIframeReceiver(target = window) {
|
|
33
|
+
function handler(event) {
|
|
34
|
+
if (event.origin !== target.location.origin) return;
|
|
35
|
+
const data = event.data;
|
|
36
|
+
if (!isBridgeMessage(data)) return;
|
|
37
|
+
if (data.type === "apply-css-vars") {
|
|
38
|
+
const root = target.document.documentElement;
|
|
39
|
+
for (const [name, value] of data.vars) root.style.setProperty(name, value);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (data.type === "clear-css-vars") {
|
|
43
|
+
const root = target.document.documentElement;
|
|
44
|
+
for (const name of data.names) root.style.removeProperty(name);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
target.addEventListener("message", handler);
|
|
49
|
+
const parent = target.parent;
|
|
50
|
+
if (parent && parent !== target) {
|
|
51
|
+
const ready = { source: BRIDGE_SOURCE, type: "ready" };
|
|
52
|
+
parent.postMessage(ready, target.location.origin);
|
|
53
|
+
}
|
|
54
|
+
return () => target.removeEventListener("message", handler);
|
|
55
|
+
}
|
|
56
|
+
function onIframeReady(expectedSource, callback) {
|
|
57
|
+
function handler(event) {
|
|
58
|
+
if (event.origin !== window.location.origin) return;
|
|
59
|
+
if (expectedSource && event.source !== expectedSource) return;
|
|
60
|
+
if (!isBridgeMessage(event.data)) return;
|
|
61
|
+
if (event.data.type === "ready") callback();
|
|
62
|
+
}
|
|
63
|
+
window.addEventListener("message", handler);
|
|
64
|
+
return () => window.removeEventListener("message", handler);
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
BRIDGE_SOURCE,
|
|
68
|
+
installIframeReceiver,
|
|
69
|
+
isBridgeMessage,
|
|
70
|
+
onIframeReady,
|
|
71
|
+
sendApplyCssVars,
|
|
72
|
+
sendClearCssVars
|
|
73
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { BRIDGE_SOURCE, installIframeReceiver, isBridgeMessage, onIframeReady, sendApplyCssVars, sendClearCssVars, } from "./iframe-css-vars-bridge.js";
|
|
2
|
+
export type { ApplyCssVarsMessage, BridgeMessage, ClearCssVarsMessage, CssVarPair, ReadyMessage, } from "./iframe-css-vars-bridge.js";
|
|
3
|
+
export { applyPreviewVars, clearPreviewVars, registerPreviewIframe, unregisterPreviewIframe, } from "./preview-iframe-registry.js";
|
|
4
|
+
export { PREVIEW_TOKEN_PANEL_TOGGLE_EVENT, createPreviewTokenPanelConfig, } from "./preview-token-panel-config.js";
|
|
5
|
+
export type { PreviewTokenPanelConfigOptions, PreviewTokenPanelManifest, } from "./preview-token-panel-config.js";
|
|
6
|
+
export { drainPrehydrationToggle, installOwnerConsoleHelpers, loadZdtp } from "./token-panel-native-bootstrap.js";
|