@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,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BRIDGE_SOURCE,
|
|
3
|
+
installIframeReceiver,
|
|
4
|
+
isBridgeMessage,
|
|
5
|
+
onIframeReady,
|
|
6
|
+
sendApplyCssVars,
|
|
7
|
+
sendClearCssVars
|
|
8
|
+
} from "./iframe-css-vars-bridge.js";
|
|
9
|
+
import {
|
|
10
|
+
applyPreviewVars,
|
|
11
|
+
clearPreviewVars,
|
|
12
|
+
registerPreviewIframe,
|
|
13
|
+
unregisterPreviewIframe
|
|
14
|
+
} from "./preview-iframe-registry.js";
|
|
15
|
+
import {
|
|
16
|
+
PREVIEW_TOKEN_PANEL_TOGGLE_EVENT,
|
|
17
|
+
createPreviewTokenPanelConfig
|
|
18
|
+
} from "./preview-token-panel-config.js";
|
|
19
|
+
import { drainPrehydrationToggle, installOwnerConsoleHelpers, loadZdtp } from "./token-panel-native-bootstrap.js";
|
|
20
|
+
export {
|
|
21
|
+
BRIDGE_SOURCE,
|
|
22
|
+
PREVIEW_TOKEN_PANEL_TOGGLE_EVENT,
|
|
23
|
+
applyPreviewVars,
|
|
24
|
+
clearPreviewVars,
|
|
25
|
+
createPreviewTokenPanelConfig,
|
|
26
|
+
drainPrehydrationToggle,
|
|
27
|
+
installIframeReceiver,
|
|
28
|
+
installOwnerConsoleHelpers,
|
|
29
|
+
isBridgeMessage,
|
|
30
|
+
loadZdtp,
|
|
31
|
+
onIframeReady,
|
|
32
|
+
registerPreviewIframe,
|
|
33
|
+
sendApplyCssVars,
|
|
34
|
+
sendClearCssVars,
|
|
35
|
+
unregisterPreviewIframe
|
|
36
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type CssVarPair } from "./iframe-css-vars-bridge.js";
|
|
2
|
+
/**
|
|
3
|
+
* Push overrides to every registered preview iframe (sink/relay API). Upserts
|
|
4
|
+
* each pair into the current-override map so it is replayed to iframes that
|
|
5
|
+
* register or re-mount later.
|
|
6
|
+
*/
|
|
7
|
+
export declare function applyPreviewVars(pairs: ReadonlyArray<CssVarPair>): void;
|
|
8
|
+
/**
|
|
9
|
+
* Remove overrides from every registered preview iframe (sink/relay API).
|
|
10
|
+
* Deletes each name from the current-override map so it is no longer replayed.
|
|
11
|
+
*/
|
|
12
|
+
export declare function clearPreviewVars(names: ReadonlyArray<string>): void;
|
|
13
|
+
/** Register a preview iframe so future token tweaks are pushed to it. Idempotent. */
|
|
14
|
+
export declare function registerPreviewIframe(iframe: HTMLIFrameElement): void;
|
|
15
|
+
/** Stop pushing token tweaks to an iframe (on unmount). Idempotent. */
|
|
16
|
+
export declare function unregisterPreviewIframe(iframe: HTMLIFrameElement): void;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
sendApplyCssVars,
|
|
3
|
+
sendClearCssVars,
|
|
4
|
+
onIframeReady
|
|
5
|
+
} from "./iframe-css-vars-bridge.js";
|
|
6
|
+
const registered = /* @__PURE__ */ new Set();
|
|
7
|
+
const readyTeardowns = /* @__PURE__ */ new Map();
|
|
8
|
+
const previewOverrides = /* @__PURE__ */ new Map();
|
|
9
|
+
function overridePairs() {
|
|
10
|
+
return [...previewOverrides].map(([name, value]) => [name, value]);
|
|
11
|
+
}
|
|
12
|
+
function replaySinkOverrides(iframe) {
|
|
13
|
+
const pairs = overridePairs();
|
|
14
|
+
if (pairs.length > 0) sendApplyCssVars(iframe, pairs);
|
|
15
|
+
}
|
|
16
|
+
function applyPreviewVars(pairs) {
|
|
17
|
+
if (pairs.length === 0) return;
|
|
18
|
+
for (const [name, value] of pairs) previewOverrides.set(name, value);
|
|
19
|
+
for (const iframe of registered) sendApplyCssVars(iframe, pairs);
|
|
20
|
+
}
|
|
21
|
+
function clearPreviewVars(names) {
|
|
22
|
+
if (names.length === 0) return;
|
|
23
|
+
for (const name of names) previewOverrides.delete(name);
|
|
24
|
+
for (const iframe of registered) sendClearCssVars(iframe, names);
|
|
25
|
+
}
|
|
26
|
+
function registerPreviewIframe(iframe) {
|
|
27
|
+
if (registered.has(iframe)) return;
|
|
28
|
+
registered.add(iframe);
|
|
29
|
+
const teardown = onIframeReady(iframe.contentWindow, () => {
|
|
30
|
+
replaySinkOverrides(iframe);
|
|
31
|
+
});
|
|
32
|
+
readyTeardowns.set(iframe, teardown);
|
|
33
|
+
replaySinkOverrides(iframe);
|
|
34
|
+
}
|
|
35
|
+
function unregisterPreviewIframe(iframe) {
|
|
36
|
+
registered.delete(iframe);
|
|
37
|
+
const teardown = readyTeardowns.get(iframe);
|
|
38
|
+
if (teardown) {
|
|
39
|
+
teardown();
|
|
40
|
+
readyTeardowns.delete(iframe);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
applyPreviewVars,
|
|
45
|
+
clearPreviewVars,
|
|
46
|
+
registerPreviewIframe,
|
|
47
|
+
unregisterPreviewIframe
|
|
48
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { applyEndpoint, applyRouting, tabs } from "virtual:zudo-sg-preview-token-panel";
|
|
3
|
+
import { bootstrapPreviewTokenPanel } from "./bootstrap-preview-token-panel.js";
|
|
4
|
+
import { createPreviewTokenPanelConfig } from "./preview-token-panel-config.js";
|
|
5
|
+
let config;
|
|
6
|
+
function getConfig() {
|
|
7
|
+
config ??= createPreviewTokenPanelConfig({ tabs: tabs ?? [] }, { applyEndpoint, applyRouting });
|
|
8
|
+
return config;
|
|
9
|
+
}
|
|
10
|
+
function PreviewTokenPanelBootstrap() {
|
|
11
|
+
if (tabs) bootstrapPreviewTokenPanel(getConfig);
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
PreviewTokenPanelBootstrap.displayName = "PreviewTokenPanelBootstrap";
|
|
15
|
+
export {
|
|
16
|
+
PreviewTokenPanelBootstrap as default
|
|
17
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* zdtp PanelConfig factory for the PREVIEW design-token panel instance.
|
|
3
|
+
*
|
|
4
|
+
* This panel tweaks the host's target-website tokens (the component
|
|
5
|
+
* package's CSS, e.g. @zudo-sg/demo-ui) and pushes them to the styleguide preview
|
|
6
|
+
* iframes via the sink API. It is intentionally distinct from the host-owned
|
|
7
|
+
* doc-chrome panel (`sg-doc-tweak`):
|
|
8
|
+
*
|
|
9
|
+
* - Distinct `storagePrefix` ("sg-preview-tweak") so localStorage keys never
|
|
10
|
+
* collide with the doc-chrome panel ("sg-doc-tweak").
|
|
11
|
+
* - Distinct `consoleNamespace` ("sgPreview") so `window.sgPreview.*` commands
|
|
12
|
+
* target only this instance.
|
|
13
|
+
* - Distinct `modalClassPrefix` ("sg-preview-design-token-panel-modal") for
|
|
14
|
+
* independent BEM class namespacing.
|
|
15
|
+
* - Distinct `toggleEvent` ("toggle-preview-token-panel") so dispatching the
|
|
16
|
+
* doc-chrome toggle does NOT open the preview panel, and vice-versa.
|
|
17
|
+
* - `applySink` wired to `applyPreviewVars` / `clearPreviewVars` from the
|
|
18
|
+
* preview-iframe-registry, so slider drags flow to iframes rather than
|
|
19
|
+
* modifying the host `:root`.
|
|
20
|
+
*
|
|
21
|
+
* Tab data comes from the host: the tabs are derived from the host's generated
|
|
22
|
+
* token manifest, so the factory takes them as input instead of importing a
|
|
23
|
+
* host module. The apply endpoint/routing come from the
|
|
24
|
+
* `@takazudo/zudo-sg/plugins/zdtp-apply-proxy` plugin's virtual module and are
|
|
25
|
+
* `undefined` outside `zfb dev`.
|
|
26
|
+
*
|
|
27
|
+
* zdtp is a required peer; this factory imports its types only so creating
|
|
28
|
+
* the configuration does not eagerly load the panel runtime.
|
|
29
|
+
*/
|
|
30
|
+
import type { PanelConfig, TabConfig } from "@takazudo/zdtp";
|
|
31
|
+
/** The host's manifest-derived tab set for the preview panel. */
|
|
32
|
+
export interface PreviewTokenPanelManifest {
|
|
33
|
+
readonly tabs: readonly TabConfig[];
|
|
34
|
+
}
|
|
35
|
+
export interface PreviewTokenPanelConfigOptions {
|
|
36
|
+
/** Same-origin apply endpoint (dev only). */
|
|
37
|
+
applyEndpoint?: PanelConfig["applyEndpoint"];
|
|
38
|
+
/** Token-prefix → CSS file routing map (dev only). */
|
|
39
|
+
applyRouting?: PanelConfig["applyRouting"];
|
|
40
|
+
}
|
|
41
|
+
export declare const PREVIEW_TOKEN_PANEL_TOGGLE_EVENT = "toggle-preview-token-panel";
|
|
42
|
+
export declare function createPreviewTokenPanelConfig(manifest: PreviewTokenPanelManifest, options?: PreviewTokenPanelConfigOptions): PanelConfig;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { applyPreviewVars, clearPreviewVars } from "./preview-iframe-registry.js";
|
|
2
|
+
const PREVIEW_TOKEN_PANEL_TOGGLE_EVENT = "toggle-preview-token-panel";
|
|
3
|
+
function createPreviewTokenPanelConfig(manifest, options = {}) {
|
|
4
|
+
return {
|
|
5
|
+
// Distinct from the doc-chrome panel ("sg-doc-tweak") — prevents localStorage
|
|
6
|
+
// key collisions when both panels are active on the same page.
|
|
7
|
+
storagePrefix: "sg-preview-tweak",
|
|
8
|
+
consoleNamespace: "sgPreview",
|
|
9
|
+
modalClassPrefix: "sg-preview-design-token-panel-modal",
|
|
10
|
+
// Distinct from the doc-chrome panel's schema ("zudo-design-tokens/v3") so
|
|
11
|
+
// exports never cross-import between the two panels.
|
|
12
|
+
schemaId: "sg-preview-design-tokens/v1",
|
|
13
|
+
exportFilenameBase: "sg-preview-design-tokens",
|
|
14
|
+
toggleEvent: PREVIEW_TOKEN_PANEL_TOGGLE_EVENT,
|
|
15
|
+
// Public site: the tokens page dispatches the toggle for every visitor, so
|
|
16
|
+
// the default `true` would arm owner-mode autoload for anyone (zdtp README §10.1).
|
|
17
|
+
autoRememberOnOpen: false,
|
|
18
|
+
tabs: manifest.tabs,
|
|
19
|
+
// `colorPresets` only feeds the reserved 'color' ColorTab's "Scheme…"
|
|
20
|
+
// dropdown; this panel has no such tab (a generic color tab + the reserved
|
|
21
|
+
// 'palette' tab), so an empty map is the honest value.
|
|
22
|
+
colorPresets: {},
|
|
23
|
+
applySink: {
|
|
24
|
+
apply: applyPreviewVars,
|
|
25
|
+
clear: clearPreviewVars
|
|
26
|
+
},
|
|
27
|
+
// Apply pipeline (zdtp README §3). The pinned zdtp (>=0.4.7) coalesces a
|
|
28
|
+
// mixed Apply by resolved target file; downgrading below 0.4.7 reintroduces
|
|
29
|
+
// the same-file clobber hazard.
|
|
30
|
+
applyEndpoint: options.applyEndpoint,
|
|
31
|
+
applyRouting: options.applyRouting
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
PREVIEW_TOKEN_PANEL_TOGGLE_EVENT,
|
|
36
|
+
createPreviewTokenPanelConfig
|
|
37
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "preact/jsx-runtime";
|
|
3
|
+
function PreviewTokensButton() {
|
|
4
|
+
return /* @__PURE__ */ jsx(
|
|
5
|
+
"button",
|
|
6
|
+
{
|
|
7
|
+
type: "button",
|
|
8
|
+
class: "inline-flex items-center gap-hsp-2xs px-hsp-xs py-vsp-3xs border border-border rounded text-small text-muted hover:text-fg transition-colors cursor-pointer",
|
|
9
|
+
onClick: () => window.dispatchEvent(new CustomEvent("toggle-preview-token-panel")),
|
|
10
|
+
children: "Preview tokens \u2192"
|
|
11
|
+
}
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
PreviewTokensButton.displayName = "PreviewTokensButton";
|
|
15
|
+
export {
|
|
16
|
+
PreviewTokensButton as default
|
|
17
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PanelConfig } from "@takazudo/zdtp";
|
|
2
|
+
type ZdtpModule = typeof import("@takazudo/zdtp");
|
|
3
|
+
/**
|
|
4
|
+
* Loads the required `@takazudo/zdtp` peer lazily. A failed import resolves
|
|
5
|
+
* `null` with a console warning so owner console helpers never surface an
|
|
6
|
+
* unhandled rejection.
|
|
7
|
+
*/
|
|
8
|
+
export declare function loadZdtp(importer?: () => Promise<ZdtpModule>): Promise<ZdtpModule | null>;
|
|
9
|
+
/**
|
|
10
|
+
* Drain the first toggle captured by the SSR script before this island mounted.
|
|
11
|
+
* State lives on the script element, not in a window-global queue, so two
|
|
12
|
+
* panel instances cannot overwrite each other's bootstrap channel.
|
|
13
|
+
*/
|
|
14
|
+
export declare function drainPrehydrationToggle(scriptId: string, toggleEvent: string): void;
|
|
15
|
+
/** Preserve the owner-autoload console helpers without eagerly importing zdtp. */
|
|
16
|
+
export declare function installOwnerConsoleHelpers(getConfig: () => PanelConfig, importer?: () => Promise<ZdtpModule>): void;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
async function loadZdtp(importer = () => import("@takazudo/zdtp")) {
|
|
2
|
+
try {
|
|
3
|
+
return await importer();
|
|
4
|
+
} catch (error) {
|
|
5
|
+
console.warn(
|
|
6
|
+
"[zudo-sg] @takazudo/zdtp is not available; the preview token panel is disabled.",
|
|
7
|
+
error
|
|
8
|
+
);
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function drainPrehydrationToggle(scriptId, toggleEvent) {
|
|
13
|
+
if (typeof document === "undefined" || typeof window === "undefined") return;
|
|
14
|
+
const script = document.getElementById(scriptId);
|
|
15
|
+
const listener = script?.__zdtpPrehydrateListener;
|
|
16
|
+
if (!script || !listener) return;
|
|
17
|
+
window.removeEventListener(toggleEvent, listener);
|
|
18
|
+
window.removeEventListener("toggle-design-token-panel", listener);
|
|
19
|
+
delete script.__zdtpPrehydrateListener;
|
|
20
|
+
const pending = Number(script.dataset.pending ?? "0");
|
|
21
|
+
delete script.dataset.pending;
|
|
22
|
+
if (Number.isFinite(pending) && pending % 2 === 1) {
|
|
23
|
+
window.dispatchEvent(new CustomEvent(toggleEvent));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function installOwnerConsoleHelpers(getConfig, importer) {
|
|
27
|
+
if (typeof window === "undefined") return;
|
|
28
|
+
const config = getConfig();
|
|
29
|
+
const target = window;
|
|
30
|
+
target[config.consoleNamespace] = {
|
|
31
|
+
...target[config.consoleNamespace],
|
|
32
|
+
enableAutoload: async () => {
|
|
33
|
+
const zdtp = await loadZdtp(importer);
|
|
34
|
+
if (!zdtp) return;
|
|
35
|
+
zdtp.configurePanel(getConfig());
|
|
36
|
+
zdtp.enableAutoload(getConfig());
|
|
37
|
+
},
|
|
38
|
+
disableAutoload: async () => {
|
|
39
|
+
const zdtp = await loadZdtp(importer);
|
|
40
|
+
if (!zdtp) return;
|
|
41
|
+
zdtp.disableAutoload(getConfig());
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
drainPrehydrationToggle,
|
|
47
|
+
installOwnerConsoleHelpers,
|
|
48
|
+
loadZdtp
|
|
49
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@takazudo/zudo-sg",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "zudo-sg styleguide engine — story registry, catalog routes and preview machinery for zfb + zudo-doc hosts.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Takeshi Takatsudo",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/Takazudo/zudo-sg.git",
|
|
11
|
+
"directory": "packages/styleguide"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./host-paths": {
|
|
19
|
+
"types": "./dist/host-paths.d.ts",
|
|
20
|
+
"default": "./dist/host-paths.js"
|
|
21
|
+
},
|
|
22
|
+
"./sg-routes": {
|
|
23
|
+
"types": "./dist/sg-routes.d.ts",
|
|
24
|
+
"default": "./dist/sg-routes.js"
|
|
25
|
+
},
|
|
26
|
+
"./stories": {
|
|
27
|
+
"types": "./dist/stories/index.d.ts",
|
|
28
|
+
"default": "./dist/stories/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./registry": {
|
|
31
|
+
"types": "./dist/registry/index.d.ts",
|
|
32
|
+
"default": "./dist/registry/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./token-dashboard": {
|
|
35
|
+
"types": "./dist/token-dashboard/index.d.ts",
|
|
36
|
+
"default": "./dist/token-dashboard/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./cli": {
|
|
39
|
+
"types": "./dist/cli/bin.d.ts",
|
|
40
|
+
"default": "./dist/cli/bin.js"
|
|
41
|
+
},
|
|
42
|
+
"./catalog": {
|
|
43
|
+
"types": "./dist/catalog/index.d.ts",
|
|
44
|
+
"default": "./dist/catalog/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./chrome": {
|
|
47
|
+
"types": "./dist/chrome/index.d.ts",
|
|
48
|
+
"default": "./dist/chrome/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./chrome/panel-contract": {
|
|
51
|
+
"types": "./dist/chrome/panel-contract.d.ts",
|
|
52
|
+
"default": "./dist/chrome/panel-contract.js"
|
|
53
|
+
},
|
|
54
|
+
"./search": {
|
|
55
|
+
"types": "./dist/search/index.d.ts",
|
|
56
|
+
"default": "./dist/search/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./preview": {
|
|
59
|
+
"types": "./dist/preview/index.d.ts",
|
|
60
|
+
"default": "./dist/preview/index.js"
|
|
61
|
+
},
|
|
62
|
+
"./code-panel": {
|
|
63
|
+
"types": "./dist/code-panel/index.d.ts",
|
|
64
|
+
"default": "./dist/code-panel/index.js"
|
|
65
|
+
},
|
|
66
|
+
"./token-tweak": {
|
|
67
|
+
"types": "./dist/token-tweak/index.d.ts",
|
|
68
|
+
"default": "./dist/token-tweak/index.js"
|
|
69
|
+
},
|
|
70
|
+
"./token-tweak/preview-token-panel-bootstrap": {
|
|
71
|
+
"types": "./dist/token-tweak/preview-token-panel-bootstrap.d.ts",
|
|
72
|
+
"default": "./dist/token-tweak/preview-token-panel-bootstrap.js"
|
|
73
|
+
},
|
|
74
|
+
"./token-tweak/preview-tokens-button": {
|
|
75
|
+
"types": "./dist/token-tweak/preview-tokens-button.d.ts",
|
|
76
|
+
"default": "./dist/token-tweak/preview-tokens-button.js"
|
|
77
|
+
},
|
|
78
|
+
"./plugins/zdtp-apply-proxy": {
|
|
79
|
+
"types": "./dist/plugins/zdtp-apply-proxy.d.ts",
|
|
80
|
+
"default": "./dist/plugins/zdtp-apply-proxy.js"
|
|
81
|
+
},
|
|
82
|
+
"./preview-css": {
|
|
83
|
+
"types": "./dist/preview-css/index.d.ts",
|
|
84
|
+
"default": "./dist/preview-css/index.js"
|
|
85
|
+
},
|
|
86
|
+
"./sg-context": {
|
|
87
|
+
"types": "./dist/sg-context.d.ts",
|
|
88
|
+
"default": "./dist/sg-context.js"
|
|
89
|
+
},
|
|
90
|
+
"./plugins/routes": {
|
|
91
|
+
"types": "./dist/plugins/routes.d.ts",
|
|
92
|
+
"default": "./dist/plugins/routes.js"
|
|
93
|
+
},
|
|
94
|
+
"./config": {
|
|
95
|
+
"types": "./dist/config/index.d.ts",
|
|
96
|
+
"default": "./dist/config/index.js"
|
|
97
|
+
},
|
|
98
|
+
"./islands": {
|
|
99
|
+
"types": "./dist/islands.d.ts",
|
|
100
|
+
"default": "./dist/islands.js"
|
|
101
|
+
},
|
|
102
|
+
"./routes-src/*": "./routes-src/*",
|
|
103
|
+
"./virtual-modules.d.ts": "./virtual-modules.d.ts",
|
|
104
|
+
"./plugins/preview-css": {
|
|
105
|
+
"types": "./dist/plugins/preview-css.d.ts",
|
|
106
|
+
"default": "./dist/plugins/preview-css.js"
|
|
107
|
+
},
|
|
108
|
+
"./styles.css": "./styles.css",
|
|
109
|
+
"./safelist.css": "./dist/safelist.css",
|
|
110
|
+
"./package.json": "./package.json"
|
|
111
|
+
},
|
|
112
|
+
"bin": {
|
|
113
|
+
"zudo-sg": "./bin/zudo-sg.js"
|
|
114
|
+
},
|
|
115
|
+
"publishConfig": {
|
|
116
|
+
"access": "public",
|
|
117
|
+
"provenance": true
|
|
118
|
+
},
|
|
119
|
+
"files": [
|
|
120
|
+
"dist",
|
|
121
|
+
"bin",
|
|
122
|
+
"routes-src",
|
|
123
|
+
"virtual-modules.d.ts",
|
|
124
|
+
"styles.css",
|
|
125
|
+
"CHANGELOG.md",
|
|
126
|
+
"README.md"
|
|
127
|
+
],
|
|
128
|
+
"dependencies": {
|
|
129
|
+
"preact-render-to-string": "^6.6.6",
|
|
130
|
+
"@codemirror/commands": "^6.0.0",
|
|
131
|
+
"@codemirror/lang-css": "^6.0.0",
|
|
132
|
+
"@codemirror/lang-javascript": "^6.0.0",
|
|
133
|
+
"@codemirror/state": "^6.0.0",
|
|
134
|
+
"@codemirror/theme-one-dark": "^6.0.0",
|
|
135
|
+
"@codemirror/view": "^6.0.0",
|
|
136
|
+
"postcss": "^8.5.15",
|
|
137
|
+
"@tailwindcss/node": "^4.2.0",
|
|
138
|
+
"@tailwindcss/oxide": "^4.2.0"
|
|
139
|
+
},
|
|
140
|
+
"peerDependencies": {
|
|
141
|
+
"@takazudo/zfb": "^2.17.0",
|
|
142
|
+
"@takazudo/zdtp": "^0.8.0",
|
|
143
|
+
"@takazudo/zudo-doc": "^5.24.0",
|
|
144
|
+
"preact": "^10.29.1"
|
|
145
|
+
},
|
|
146
|
+
"devDependencies": {
|
|
147
|
+
"@takazudo/zdtp": "0.8.0",
|
|
148
|
+
"@takazudo/zfb": "2.17.0",
|
|
149
|
+
"@takazudo/zudo-doc": "5.24.0",
|
|
150
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
151
|
+
"@testing-library/preact": "^3.2.4",
|
|
152
|
+
"@types/culori": "^4.0.1",
|
|
153
|
+
"@types/node": "^22.0.0",
|
|
154
|
+
"culori": "^4.0.2",
|
|
155
|
+
"happy-dom": "^16.8.1",
|
|
156
|
+
"preact": "^10.29.1",
|
|
157
|
+
"tsup": "^8.5.0",
|
|
158
|
+
"typescript": "^5.9.0",
|
|
159
|
+
"vitest": "^4.1.9"
|
|
160
|
+
},
|
|
161
|
+
"scripts": {
|
|
162
|
+
"build": "tsup && tsc -p tsconfig.build.json",
|
|
163
|
+
"typecheck": "tsc --noEmit",
|
|
164
|
+
"test": "vitest run --config vitest.config.ts",
|
|
165
|
+
"check:no-host-alias": "node scripts/check-no-host-alias.mjs",
|
|
166
|
+
"check:package-shape": "node scripts/check-package-shape.mjs",
|
|
167
|
+
"check:routes-src": "node scripts/check-routes-src.mjs",
|
|
168
|
+
"check:virtual-modules": "node scripts/check-virtual-modules.mjs",
|
|
169
|
+
"check:package-safelist": "node scripts/check-package-safelist.mjs",
|
|
170
|
+
"check": "pnpm run check:no-host-alias && pnpm run typecheck && pnpm run build && pnpm run check:package-shape && pnpm run check:routes-src && pnpm run check:virtual-modules && pnpm run check:package-safelist && pnpm run test"
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/** @jsxRuntime automatic */
|
|
2
|
+
/** @jsxImportSource preact */
|
|
3
|
+
// zudo-doc chrome reconstruction for the engine routes (ADR
|
|
4
|
+
// docs/adr/styleguide-engine.md decision 10). Model: zudo-doc's
|
|
5
|
+
// routes/_chrome.tsx. Sole importer of `virtual:zudo-doc-route-context` and
|
|
6
|
+
// `virtual:zudo-doc-chrome-bindings` (both registered by
|
|
7
|
+
// `@takazudo/zudo-doc/plugins/routes`, which the engine routes plugin requires).
|
|
8
|
+
//
|
|
9
|
+
// The host's `chromeBindings` are spread verbatim, so its BodyEndIslands
|
|
10
|
+
// override (doc-chrome token panel, preview token panel, enlarge islands)
|
|
11
|
+
// mounts on the engine routes exactly as on the zudo-doc doc routes.
|
|
12
|
+
|
|
13
|
+
import type { JSX } from "preact";
|
|
14
|
+
import { routeContext } from "virtual:zudo-doc-route-context";
|
|
15
|
+
import { chromeBindings } from "virtual:zudo-doc-chrome-bindings";
|
|
16
|
+
import { createRouteContext, type RouteContextPayload } from "@takazudo/zudo-doc/route-context";
|
|
17
|
+
import { createChrome } from "@takazudo/zudo-doc/chrome";
|
|
18
|
+
import type { StyleguideLayoutProps } from "@takazudo/zudo-sg/chrome";
|
|
19
|
+
import { buildNavNodes } from "@takazudo/zudo-sg/registry";
|
|
20
|
+
import { ctx, withBase } from "./_context.js";
|
|
21
|
+
import { registry } from "./_registry.js";
|
|
22
|
+
|
|
23
|
+
export const routeCtx = createRouteContext(routeContext as unknown as RouteContextPayload);
|
|
24
|
+
export const settings = routeCtx.settings;
|
|
25
|
+
export const locale = routeCtx.defaultLocale;
|
|
26
|
+
|
|
27
|
+
const chrome = createChrome(routeCtx, chromeBindings);
|
|
28
|
+
export const { composeMetaTitle } = chrome;
|
|
29
|
+
|
|
30
|
+
/** The styleguide sidebar tree, built once and shared by every engine route. */
|
|
31
|
+
export const navNodes = buildNavNodes(registry, { withBase, routes: ctx.routes });
|
|
32
|
+
|
|
33
|
+
export interface ChromeSlotOptions {
|
|
34
|
+
/** Raw page title — HeadWithDefaults composes "<title> | <siteName>". */
|
|
35
|
+
pageTitle: string;
|
|
36
|
+
/** Root-absolute route path before the base prefix. */
|
|
37
|
+
path: string;
|
|
38
|
+
/** Extra `<head>` content appended after HeadWithDefaults. */
|
|
39
|
+
extraHead?: JSX.Element;
|
|
40
|
+
/** Active styleguide slug; with `hideSidebar` unset it also scopes the mobile drawer. */
|
|
41
|
+
activeSlug?: string;
|
|
42
|
+
/** Standalone page (e.g. /tokens): the mobile drawer keeps the root menu. */
|
|
43
|
+
hideSidebar?: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type ChromeProps = Pick<
|
|
47
|
+
StyleguideLayoutProps,
|
|
48
|
+
"title" | "lang" | "head" | "header" | "footer" | "bodyEnd" | "navNodes" | "sidebarToggle" | "enableClientRouter" | "noindex"
|
|
49
|
+
>;
|
|
50
|
+
|
|
51
|
+
/** Every StyleguideLayout prop that comes from the doc chrome and the site settings. */
|
|
52
|
+
export function chromeProps({ pageTitle, path, extraHead, activeSlug, hideSidebar = false }: ChromeSlotOptions): ChromeProps {
|
|
53
|
+
const { HeadWithDefaults, HeaderWithDefaults, FooterWithDefaults, BodyEndIslands } = chrome;
|
|
54
|
+
const head = <HeadWithDefaults title={pageTitle} />;
|
|
55
|
+
// `sidebarNodesOverride` is not part of zudo-doc's HeaderWithDefaultsProps:
|
|
56
|
+
// createChrome forwards every prop to the host's `Header` chrome binding when
|
|
57
|
+
// one is bound (a host header that feeds its mobile drawer from it), while
|
|
58
|
+
// the package default header ignores it and its drawer shows the root menu.
|
|
59
|
+
const headerProps = {
|
|
60
|
+
lang: locale,
|
|
61
|
+
currentPath: withBase(path),
|
|
62
|
+
...(hideSidebar ? {} : { sidebarNodesOverride: navNodes, currentSlug: activeSlug }),
|
|
63
|
+
} as Parameters<typeof HeaderWithDefaults>[0];
|
|
64
|
+
return {
|
|
65
|
+
title: composeMetaTitle(pageTitle),
|
|
66
|
+
lang: locale,
|
|
67
|
+
head: extraHead ? (
|
|
68
|
+
<>
|
|
69
|
+
{head}
|
|
70
|
+
{extraHead}
|
|
71
|
+
</>
|
|
72
|
+
) : (
|
|
73
|
+
head
|
|
74
|
+
),
|
|
75
|
+
header: <HeaderWithDefaults {...headerProps} />,
|
|
76
|
+
footer: <FooterWithDefaults lang={locale} />,
|
|
77
|
+
bodyEnd: <BodyEndIslands basePath={ctx.base} />,
|
|
78
|
+
navNodes,
|
|
79
|
+
sidebarToggle: Boolean(settings.sidebarToggle),
|
|
80
|
+
enableClientRouter: Boolean(settings.dynamicPageTransition),
|
|
81
|
+
noindex: Boolean(settings.noindex),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Sole importer of `virtual:zudo-sg-context` (ADR docs/adr/styleguide-engine.md
|
|
2
|
+
// decision 10). Route entrypoints read host data through `ctx` and build every
|
|
3
|
+
// internal href with `withBase`, never from literals.
|
|
4
|
+
//
|
|
5
|
+
// No `node:` imports anywhere in this graph: route entrypoints render inside
|
|
6
|
+
// zfb's SSR bundle, so `withBase` is inlined instead of reusing host-paths.ts.
|
|
7
|
+
|
|
8
|
+
import { sgContext } from "virtual:zudo-sg-context";
|
|
9
|
+
|
|
10
|
+
export const ctx = sgContext;
|
|
11
|
+
|
|
12
|
+
/** Prefixes a root-absolute URL path with the site base (`"/docs/"` + `"/tokens"` → `"/docs/tokens"`). */
|
|
13
|
+
export function withBase(path: string): string {
|
|
14
|
+
return ctx.base.replace(/\/+$/, "") + path;
|
|
15
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
/** @jsxRuntime automatic */
|
|
3
|
+
/** @jsxImportSource preact */
|
|
4
|
+
// No-props island wrapper for the engine's preview app (ADR
|
|
5
|
+
// docs/adr/styleguide-engine.md decision 10 "Preview island").
|
|
6
|
+
//
|
|
7
|
+
// zfb serializes island props to JSON (`data-props`), so the story registry —
|
|
8
|
+
// whose variants carry `render()` closures — cannot ride as props. This
|
|
9
|
+
// wrapper takes NO props and imports the registry in-bundle (through
|
|
10
|
+
// `_registry.ts` → `virtual:zudo-sg-registry`), which puts every story closure
|
|
11
|
+
// into the islands chunk. `components-preview.tsx` imports it statically so
|
|
12
|
+
// `zfb build` registers it; `@takazudo/zudo-sg/islands` imports it too so
|
|
13
|
+
// `zfb dev` (which scans host `pages/` only) registers it (ADR finding 4).
|
|
14
|
+
//
|
|
15
|
+
// The design-token bridge receiver is installed here, not inside PreviewApp,
|
|
16
|
+
// so the engine's preview component stays free of the token-tweak feature.
|
|
17
|
+
//
|
|
18
|
+
// Keep the combined `export default function Name() {}` form: zfb's island
|
|
19
|
+
// scanner matches the SSR marker against the exported function name.
|
|
20
|
+
|
|
21
|
+
import type { JSX } from "preact";
|
|
22
|
+
import { useEffect } from "preact/hooks";
|
|
23
|
+
import { PreviewApp } from "@takazudo/zudo-sg/preview";
|
|
24
|
+
import { installIframeReceiver } from "@takazudo/zudo-sg/token-tweak";
|
|
25
|
+
import { registry } from "./_registry.js";
|
|
26
|
+
|
|
27
|
+
export default function ConfiguredPreviewApp(): JSX.Element {
|
|
28
|
+
useEffect(() => installIframeReceiver(window), []);
|
|
29
|
+
return <PreviewApp registry={registry} />;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
ConfiguredPreviewApp.displayName = "ConfiguredPreviewApp";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Sole importer of `virtual:zudo-sg-registry` (ADR docs/adr/styleguide-engine.md
|
|
2
|
+
// decision 10): builds the host registry once; every entrypoint and the preview
|
|
3
|
+
// wrapper import `registry` from here.
|
|
4
|
+
|
|
5
|
+
import { storyExportOrder, storyModules } from "virtual:zudo-sg-registry";
|
|
6
|
+
import { createRegistry } from "@takazudo/zudo-sg/registry";
|
|
7
|
+
import { ctx } from "./_context.js";
|
|
8
|
+
|
|
9
|
+
export const registry = createRegistry(storyModules, {
|
|
10
|
+
categoryOrder: ctx.categoryOrder,
|
|
11
|
+
storyExportOrder,
|
|
12
|
+
});
|