@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,39 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "preact/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef, useState } from "preact/hooks";
|
|
4
|
+
function SourceEditor({
|
|
5
|
+
value,
|
|
6
|
+
language,
|
|
7
|
+
editable = false,
|
|
8
|
+
onChange
|
|
9
|
+
}) {
|
|
10
|
+
const containerRef = useRef(null);
|
|
11
|
+
const viewRef = useRef(null);
|
|
12
|
+
const [loaded, setLoaded] = useState(false);
|
|
13
|
+
const onChangeRef = useRef(onChange);
|
|
14
|
+
onChangeRef.current = onChange;
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
let disposed = false;
|
|
17
|
+
void import("./editor-setup.js").then(({ createEditorView }) => {
|
|
18
|
+
if (disposed || !containerRef.current) return;
|
|
19
|
+
viewRef.current = createEditorView(value, containerRef.current, {
|
|
20
|
+
language,
|
|
21
|
+
editable,
|
|
22
|
+
onChange: (v) => onChangeRef.current?.(v)
|
|
23
|
+
});
|
|
24
|
+
setLoaded(true);
|
|
25
|
+
});
|
|
26
|
+
return () => {
|
|
27
|
+
disposed = true;
|
|
28
|
+
viewRef.current?.destroy();
|
|
29
|
+
viewRef.current = null;
|
|
30
|
+
};
|
|
31
|
+
}, []);
|
|
32
|
+
return /* @__PURE__ */ jsxs("div", { class: "relative text-small", children: [
|
|
33
|
+
!loaded && /* @__PURE__ */ jsx("pre", { class: "m-0 overflow-auto rounded-md bg-surface-2 p-hsp-sm text-xs text-muted", children: /* @__PURE__ */ jsx("code", { children: value }) }),
|
|
34
|
+
/* @__PURE__ */ jsx("div", { ref: containerRef, class: loaded ? "" : "hidden" })
|
|
35
|
+
] });
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
SourceEditor as default
|
|
39
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { componentDocsCollectionName } from "../registry/component-docs.js";
|
|
2
|
+
import type { SgRoutes } from "../sg-routes.js";
|
|
3
|
+
export declare const ROUTES_PLUGIN_NAME = "@takazudo/zudo-sg/plugins/routes";
|
|
4
|
+
export declare const PREVIEW_CSS_PLUGIN_NAME = "@takazudo/zudo-sg/plugins/preview-css";
|
|
5
|
+
export declare const ZDTP_APPLY_PROXY_PLUGIN_NAME = "@takazudo/zudo-sg/plugins/zdtp-apply-proxy";
|
|
6
|
+
/** Collection name of `componentsRoots[0]`; later roots append their index. */
|
|
7
|
+
export declare const COMPONENT_DOCS_COLLECTION_BASE = "componentDocs";
|
|
8
|
+
export { componentDocsCollectionName };
|
|
9
|
+
export interface ZudoSgPluginDescriptor {
|
|
10
|
+
name: string;
|
|
11
|
+
options?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
export interface ZudoSgCollection {
|
|
14
|
+
name: string;
|
|
15
|
+
path: string;
|
|
16
|
+
include: string[];
|
|
17
|
+
}
|
|
18
|
+
export interface ZudoSgComposeOptions {
|
|
19
|
+
/** Story corpora; one `componentDocs*` collection is registered per `dir`. */
|
|
20
|
+
componentsRoots: ReadonlyArray<{
|
|
21
|
+
dir: string;
|
|
22
|
+
importBase?: string;
|
|
23
|
+
}>;
|
|
24
|
+
/** Project-root-relative generated registry (the routes plugin's `registryModule`). */
|
|
25
|
+
registryOut: string;
|
|
26
|
+
categoryOrder?: string[];
|
|
27
|
+
uiPackageName?: string;
|
|
28
|
+
/** Project-root-relative preview stylesheet entry (the preview-css plugin's input). */
|
|
29
|
+
previewStyles: string;
|
|
30
|
+
/** Default `/_zudo-sg/preview.css`. */
|
|
31
|
+
previewCssUrl?: string;
|
|
32
|
+
routes?: Partial<SgRoutes>;
|
|
33
|
+
catalog?: {
|
|
34
|
+
title?: string;
|
|
35
|
+
intro?: string;
|
|
36
|
+
};
|
|
37
|
+
/** `tokens.manifestOut` feeds the `/tokens` route's dashboards (routes plugin `tokensManifestModule`). */
|
|
38
|
+
tokens?: {
|
|
39
|
+
manifestOut?: string;
|
|
40
|
+
cssFiles?: readonly string[];
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* `@takazudo/zudo-sg/plugins/zdtp-apply-proxy` options
|
|
44
|
+
* (`{ routingFile, writeRoot, tabsModule? }`). Omitted → the plugin is still
|
|
45
|
+
* listed (the engine's preview token panel island imports its virtual
|
|
46
|
+
* module) but runs disabled: no tabs, no Apply endpoint.
|
|
47
|
+
*/
|
|
48
|
+
zdtpApplyProxy?: {
|
|
49
|
+
routingFile: string;
|
|
50
|
+
writeRoot: string;
|
|
51
|
+
tabsModule?: string;
|
|
52
|
+
};
|
|
53
|
+
/** Extra keys of `zudo-sg.config.mjs` (e.g. `barrelIndex`) are CLI-only and ignored here. */
|
|
54
|
+
[key: string]: unknown;
|
|
55
|
+
}
|
|
56
|
+
export interface ZudoSgFragment {
|
|
57
|
+
plugins: ZudoSgPluginDescriptor[];
|
|
58
|
+
collections: ZudoSgCollection[];
|
|
59
|
+
}
|
|
60
|
+
/** Returns the engine's zfb plugin descriptors and content collections. */
|
|
61
|
+
export declare function zudoSg(options: ZudoSgComposeOptions): ZudoSgFragment;
|
|
62
|
+
/**
|
|
63
|
+
* Merges the engine into a zudo-doc preset fragment: engine plugins and
|
|
64
|
+
* collections are appended AFTER the preset's (the routes plugin requires the
|
|
65
|
+
* zudo-doc routes descriptor to be present).
|
|
66
|
+
*/
|
|
67
|
+
export declare function withZudoSg<P extends {
|
|
68
|
+
plugins?: ReadonlyArray<unknown>;
|
|
69
|
+
collections?: ReadonlyArray<unknown>;
|
|
70
|
+
}>(presetFragment: P, options: ZudoSgComposeOptions): Omit<P, "plugins" | "collections"> & {
|
|
71
|
+
plugins: Array<NonNullable<P["plugins"]>[number] | ZudoSgPluginDescriptor>;
|
|
72
|
+
collections: Array<NonNullable<P["collections"]>[number] | ZudoSgCollection>;
|
|
73
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
COMPONENT_DOCS_COLLECTION,
|
|
3
|
+
componentDocsCollectionName,
|
|
4
|
+
componentDocsRoots
|
|
5
|
+
} from "../registry/component-docs.js";
|
|
6
|
+
import { DEFAULT_PREVIEW_CSS_URL } from "../sg-context.js";
|
|
7
|
+
const ROUTES_PLUGIN_NAME = "@takazudo/zudo-sg/plugins/routes";
|
|
8
|
+
const PREVIEW_CSS_PLUGIN_NAME = "@takazudo/zudo-sg/plugins/preview-css";
|
|
9
|
+
const ZDTP_APPLY_PROXY_PLUGIN_NAME = "@takazudo/zudo-sg/plugins/zdtp-apply-proxy";
|
|
10
|
+
const COMPONENT_DOCS_COLLECTION_BASE = COMPONENT_DOCS_COLLECTION;
|
|
11
|
+
function definedOnly(record) {
|
|
12
|
+
return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== void 0));
|
|
13
|
+
}
|
|
14
|
+
function zudoSg(options) {
|
|
15
|
+
if (!options || typeof options !== "object") {
|
|
16
|
+
throw new Error("[zudo-sg] zudoSg(options) requires an options object (the zudo-sg.config.mjs shape)");
|
|
17
|
+
}
|
|
18
|
+
const roots = Array.isArray(options.componentsRoots) ? options.componentsRoots : [];
|
|
19
|
+
const previewCssUrl = options.previewCssUrl ?? DEFAULT_PREVIEW_CSS_URL;
|
|
20
|
+
const plugins = [
|
|
21
|
+
{
|
|
22
|
+
name: ROUTES_PLUGIN_NAME,
|
|
23
|
+
options: definedOnly({
|
|
24
|
+
registryModule: options.registryOut,
|
|
25
|
+
routes: options.routes,
|
|
26
|
+
categoryOrder: options.categoryOrder,
|
|
27
|
+
uiPackageName: options.uiPackageName,
|
|
28
|
+
previewCssUrl,
|
|
29
|
+
catalog: options.catalog,
|
|
30
|
+
tokensManifestModule: options.tokens?.manifestOut,
|
|
31
|
+
// Pairs each root's registry key prefix with its collection below, so the
|
|
32
|
+
// detail route resolves a story's doc from the root its key belongs to.
|
|
33
|
+
componentDocs: componentDocsRoots(roots)
|
|
34
|
+
})
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: PREVIEW_CSS_PLUGIN_NAME,
|
|
38
|
+
options: definedOnly({ previewStyles: options.previewStyles, previewCssUrl })
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: ZDTP_APPLY_PROXY_PLUGIN_NAME,
|
|
42
|
+
options: options.zdtpApplyProxy ? definedOnly({ ...options.zdtpApplyProxy }) : {}
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
const collections = roots.map((root, i) => ({
|
|
46
|
+
name: componentDocsCollectionName(i),
|
|
47
|
+
path: root.dir,
|
|
48
|
+
include: ["**/*.mdx"]
|
|
49
|
+
}));
|
|
50
|
+
return { plugins, collections };
|
|
51
|
+
}
|
|
52
|
+
function withZudoSg(presetFragment, options) {
|
|
53
|
+
const sg = zudoSg(options);
|
|
54
|
+
return {
|
|
55
|
+
...presetFragment,
|
|
56
|
+
plugins: [...presetFragment.plugins ?? [], ...sg.plugins],
|
|
57
|
+
collections: [...presetFragment.collections ?? [], ...sg.collections]
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
COMPONENT_DOCS_COLLECTION_BASE,
|
|
62
|
+
PREVIEW_CSS_PLUGIN_NAME,
|
|
63
|
+
ROUTES_PLUGIN_NAME,
|
|
64
|
+
ZDTP_APPLY_PROXY_PLUGIN_NAME,
|
|
65
|
+
componentDocsCollectionName,
|
|
66
|
+
withZudoSg,
|
|
67
|
+
zudoSg
|
|
68
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface ResolveHostModuleOptions {
|
|
2
|
+
/** Throw when the option is absent (`undefined` / `null`). */
|
|
3
|
+
required?: boolean;
|
|
4
|
+
/** Example value quoted in the "is required" error, e.g. `./src/styleguide/sg-registry.ts`. */
|
|
5
|
+
example?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Converts a native path to forward slashes (`C:\a\b` → `C:/a/b`). */
|
|
8
|
+
export declare function toForwardSlash(path: string): string;
|
|
9
|
+
export declare function resolveHostModule(projectRoot: string, optionName: string, value: string | null | undefined, options: ResolveHostModuleOptions & {
|
|
10
|
+
required: true;
|
|
11
|
+
}): string;
|
|
12
|
+
export declare function resolveHostModule(projectRoot: string, optionName: string, value: string | null | undefined, options?: ResolveHostModuleOptions): string | undefined;
|
|
13
|
+
/** Removes every trailing `/` (`"/docs/"` → `"/docs"`, `"/"` → `""`). */
|
|
14
|
+
export declare function stripTrailingSlash(base: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Prefixes a root-absolute URL path with the site base:
|
|
17
|
+
* `withBaseUrl("/docs/", "/_zudo-sg/preview.css")` → `"/docs/_zudo-sg/preview.css"`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function withBaseUrl(base: string, path: string): string;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { statSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, resolve } from "node:path";
|
|
3
|
+
function toForwardSlash(path) {
|
|
4
|
+
return path.replace(/\\/g, "/");
|
|
5
|
+
}
|
|
6
|
+
function isFile(absPath) {
|
|
7
|
+
try {
|
|
8
|
+
return statSync(absPath).isFile();
|
|
9
|
+
} catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function resolveHostModule(projectRoot, optionName, value, options = {}) {
|
|
14
|
+
if (value === void 0 || value === null) {
|
|
15
|
+
if (!options.required) return void 0;
|
|
16
|
+
const example = options.example ?? "./path/to/file";
|
|
17
|
+
throw new Error(
|
|
18
|
+
`[zudo-sg] option "${optionName}" is required (project-root-relative path, e.g. "${example}")`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
const root = toForwardSlash(resolve(projectRoot));
|
|
22
|
+
const abs = toForwardSlash(isAbsolute(value) ? resolve(value) : resolve(projectRoot, value));
|
|
23
|
+
if (value === "" || !isFile(abs)) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`[zudo-sg] option "${optionName}" = "${value}" resolved to ${abs} (relative to projectRoot ${root}), which is not a file`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
return abs;
|
|
29
|
+
}
|
|
30
|
+
function stripTrailingSlash(base) {
|
|
31
|
+
return base.replace(/\/+$/, "");
|
|
32
|
+
}
|
|
33
|
+
function withBaseUrl(base, path) {
|
|
34
|
+
return stripTrailingSlash(base) + path;
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
resolveHostModule,
|
|
38
|
+
stripTrailingSlash,
|
|
39
|
+
toForwardSlash,
|
|
40
|
+
withBaseUrl
|
|
41
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createRegistry, buildNavNodes, OVERVIEW_SLUG, TOKENS_SLUG, } from "./registry/index.js";
|
|
2
|
+
export type { CategoryGroup, NavNode, Registry, StoryEntry, VariantEntry, } from "./registry/index.js";
|
|
3
|
+
export { defineStory } from "./stories/index.js";
|
|
4
|
+
export type { Story, StoryControl, StoryMeta, StoryModule } from "./stories/index.js";
|
|
5
|
+
export { DEFAULT_SG_ROUTES, resolveSgRoutes, componentHref } from "./sg-routes.js";
|
|
6
|
+
export type { SgRoutes } from "./sg-routes.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createRegistry,
|
|
3
|
+
buildNavNodes,
|
|
4
|
+
OVERVIEW_SLUG,
|
|
5
|
+
TOKENS_SLUG
|
|
6
|
+
} from "./registry/index.js";
|
|
7
|
+
import { defineStory } from "./stories/index.js";
|
|
8
|
+
import { DEFAULT_SG_ROUTES, resolveSgRoutes, componentHref } from "./sg-routes.js";
|
|
9
|
+
export {
|
|
10
|
+
DEFAULT_SG_ROUTES,
|
|
11
|
+
OVERVIEW_SLUG,
|
|
12
|
+
TOKENS_SLUG,
|
|
13
|
+
buildNavNodes,
|
|
14
|
+
componentHref,
|
|
15
|
+
createRegistry,
|
|
16
|
+
defineStory,
|
|
17
|
+
resolveSgRoutes
|
|
18
|
+
};
|
package/dist/islands.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import "./preview/detail-workbench.js";
|
|
2
|
+
import "./code-panel/code-panel.js";
|
|
3
|
+
import "./search/catalog-filter.js";
|
|
4
|
+
import "./token-tweak/preview-tokens-button.js";
|
|
5
|
+
import "./token-tweak/preview-token-panel-bootstrap.js";
|
|
6
|
+
import "../routes-src/_preview-app.tsx";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ZfbDevMiddlewareHandler, ZfbPlugin, ZfbPluginLogger } from "@takazudo/zfb/plugins";
|
|
2
|
+
import { type CompilePreviewCssResult } from "../preview-css/compile.js";
|
|
3
|
+
import { DEFAULT_PREVIEW_CSS_URL } from "../sg-context.js";
|
|
4
|
+
export declare const PLUGIN_NAME = "@takazudo/zudo-sg/plugins/preview-css";
|
|
5
|
+
export { DEFAULT_PREVIEW_CSS_URL };
|
|
6
|
+
export interface PreviewCssPluginOptions {
|
|
7
|
+
/** Project-root-relative preview stylesheet entry (e.g. `./src/styles/preview-entry.css`). */
|
|
8
|
+
previewStyles: string;
|
|
9
|
+
/** Root-absolute URL path, before the base prefix. Default `/_zudo-sg/preview.css`. */
|
|
10
|
+
previewCssUrl?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ResolvedPreviewCssPluginOptions {
|
|
13
|
+
/** Forward-slash absolute path of the entry file. */
|
|
14
|
+
previewStyles: string;
|
|
15
|
+
previewCssUrl: string;
|
|
16
|
+
}
|
|
17
|
+
export type PreviewCssCompiler = (entryAbsPath: string) => Promise<CompilePreviewCssResult>;
|
|
18
|
+
type Logger = Pick<ZfbPluginLogger, "info" | "error">;
|
|
19
|
+
/** Validates the options block and resolves `previewStyles`; throws `[zudo-sg] …` on invalid input. */
|
|
20
|
+
export declare function resolvePreviewCssPluginOptions(projectRoot: string, options: Record<string, unknown>): ResolvedPreviewCssPluginOptions;
|
|
21
|
+
/** The full URL zfb must match: `"/"` → `/_zudo-sg/preview.css`, `"/spike/"` → `/spike/_zudo-sg/preview.css`. */
|
|
22
|
+
export declare function previewCssRoute(base: string | undefined, previewCssUrl: string): string;
|
|
23
|
+
/** `<outDir><previewCssUrl>` — the base segment is deliberately NOT part of the on-disk path. */
|
|
24
|
+
export declare function previewCssOutputPath(outDir: string, previewCssUrl: string): string;
|
|
25
|
+
/** Every path whose mtime decides freshness: dependencies, scanned files and their directories. */
|
|
26
|
+
export declare function watchedPaths(result: Pick<CompilePreviewCssResult, "dependencies" | "sourceFiles">): string[];
|
|
27
|
+
/** `<path>:<mtimeMs>` joined; a missing file stamps as `<path>:missing`. */
|
|
28
|
+
export declare function computeStamp(paths: readonly string[]): string;
|
|
29
|
+
export interface PreviewCssCache {
|
|
30
|
+
/** Returns the current stylesheet, compiling only when an input changed. */
|
|
31
|
+
get(): Promise<string>;
|
|
32
|
+
}
|
|
33
|
+
export declare function createPreviewCssCache(entry: string, compile?: PreviewCssCompiler, logger?: Logger): PreviewCssCache;
|
|
34
|
+
export interface PreviewCssHandlerOptions {
|
|
35
|
+
/** Full URL (base included) — see `previewCssRoute`. */
|
|
36
|
+
route: string;
|
|
37
|
+
cache: PreviewCssCache;
|
|
38
|
+
logger?: Logger;
|
|
39
|
+
}
|
|
40
|
+
/** Answers exactly `route` (query string ignored); anything else under the prefix falls through. */
|
|
41
|
+
export declare function createPreviewCssHandler({ route, cache, logger }: PreviewCssHandlerOptions): ZfbDevMiddlewareHandler;
|
|
42
|
+
/**
|
|
43
|
+
* Removes any previous file at the target, then writes through a unique temp
|
|
44
|
+
* file + rename so a concurrent reader (or a second build into the same
|
|
45
|
+
* outDir) never observes a partially written stylesheet.
|
|
46
|
+
*/
|
|
47
|
+
export declare function writePreviewCss(outDir: string, previewCssUrl: string, css: string): Promise<string>;
|
|
48
|
+
export interface CreatePreviewCssPluginOptions {
|
|
49
|
+
compile?: PreviewCssCompiler;
|
|
50
|
+
}
|
|
51
|
+
export declare function createPreviewCssPlugin({ compile }?: CreatePreviewCssPluginOptions): ZfbPlugin;
|
|
52
|
+
declare const _default: ZfbPlugin;
|
|
53
|
+
export default _default;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { mkdir, rename, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { statSync } from "node:fs";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { resolveHostModule, toForwardSlash, withBaseUrl } from "../host-paths.js";
|
|
6
|
+
import { compilePreviewCss } from "../preview-css/compile.js";
|
|
7
|
+
import { DEFAULT_PREVIEW_CSS_URL } from "../sg-context.js";
|
|
8
|
+
const PLUGIN_NAME = "@takazudo/zudo-sg/plugins/preview-css";
|
|
9
|
+
const OPTION_KEYS = /* @__PURE__ */ new Set(["previewStyles", "previewCssUrl"]);
|
|
10
|
+
function fail(message) {
|
|
11
|
+
throw new Error(`[zudo-sg] ${message}`);
|
|
12
|
+
}
|
|
13
|
+
function resolvePreviewCssPluginOptions(projectRoot, options) {
|
|
14
|
+
for (const key of Object.keys(options)) {
|
|
15
|
+
if (!OPTION_KEYS.has(key)) {
|
|
16
|
+
fail(`unknown option "${key}" for ${PLUGIN_NAME} (expected one of ${[...OPTION_KEYS].join(", ")})`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const stylesValue = options.previewStyles;
|
|
20
|
+
if (stylesValue !== void 0 && stylesValue !== null && typeof stylesValue !== "string") {
|
|
21
|
+
fail(`option "previewStyles" must be a string (project-root-relative path)`);
|
|
22
|
+
}
|
|
23
|
+
const previewStyles = resolveHostModule(projectRoot, "previewStyles", stylesValue, {
|
|
24
|
+
required: true,
|
|
25
|
+
example: "./src/styles/preview-entry.css"
|
|
26
|
+
});
|
|
27
|
+
const urlValue = options.previewCssUrl;
|
|
28
|
+
let previewCssUrl = DEFAULT_PREVIEW_CSS_URL;
|
|
29
|
+
if (urlValue !== void 0 && urlValue !== null) {
|
|
30
|
+
if (typeof urlValue !== "string" || urlValue === "") fail(`option "previewCssUrl" must be a non-empty string`);
|
|
31
|
+
if (!urlValue.startsWith("/") || urlValue.endsWith("/") || /[?#]/.test(urlValue)) {
|
|
32
|
+
fail(`option "previewCssUrl" = "${urlValue}" must be a root-absolute file URL path (e.g. "${DEFAULT_PREVIEW_CSS_URL}")`);
|
|
33
|
+
}
|
|
34
|
+
if (urlValue.split("/").some((segment) => segment === "." || segment === "..")) {
|
|
35
|
+
fail(`option "previewCssUrl" = "${urlValue}" must not contain "." or ".." segments`);
|
|
36
|
+
}
|
|
37
|
+
previewCssUrl = urlValue;
|
|
38
|
+
}
|
|
39
|
+
return { previewStyles, previewCssUrl };
|
|
40
|
+
}
|
|
41
|
+
function previewCssRoute(base, previewCssUrl) {
|
|
42
|
+
return withBaseUrl(base ?? "/", previewCssUrl);
|
|
43
|
+
}
|
|
44
|
+
function previewCssOutputPath(outDir, previewCssUrl) {
|
|
45
|
+
return join(outDir, ...previewCssUrl.split("/").filter(Boolean));
|
|
46
|
+
}
|
|
47
|
+
function mtimeOf(path) {
|
|
48
|
+
try {
|
|
49
|
+
return statSync(path).mtimeMs;
|
|
50
|
+
} catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function watchedPaths(result) {
|
|
55
|
+
const files = [...result.dependencies, ...result.sourceFiles];
|
|
56
|
+
return [.../* @__PURE__ */ new Set([...files, ...files.map((file) => toForwardSlash(dirname(file)))])];
|
|
57
|
+
}
|
|
58
|
+
function computeStamp(paths) {
|
|
59
|
+
return paths.map((path) => `${path}:${mtimeOf(path) ?? "missing"}`).join("\n");
|
|
60
|
+
}
|
|
61
|
+
function createPreviewCssCache(entry, compile = compilePreviewCss, logger) {
|
|
62
|
+
let cached;
|
|
63
|
+
let inflight;
|
|
64
|
+
const recompile = async () => {
|
|
65
|
+
const startedAt = Date.now();
|
|
66
|
+
const result = await compile(entry);
|
|
67
|
+
const paths = watchedPaths(result);
|
|
68
|
+
const stamp = computeStamp(paths);
|
|
69
|
+
const touchedDuringCompile = paths.some((path) => (mtimeOf(path) ?? 0) >= startedAt);
|
|
70
|
+
cached = { css: result.css, paths, stamp: touchedDuringCompile ? "" : stamp };
|
|
71
|
+
logger?.info(
|
|
72
|
+
`preview css compiled (${result.candidateCount} candidates, ${result.dependencies.length} deps, ${result.sourceFiles.length} source files)`
|
|
73
|
+
);
|
|
74
|
+
return result.css;
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
get() {
|
|
78
|
+
if (inflight) return inflight;
|
|
79
|
+
if (cached && computeStamp(cached.paths) === cached.stamp) return Promise.resolve(cached.css);
|
|
80
|
+
inflight = recompile().finally(() => {
|
|
81
|
+
inflight = void 0;
|
|
82
|
+
});
|
|
83
|
+
return inflight;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const CSS_HEADERS = {
|
|
88
|
+
"content-type": "text/css; charset=utf-8",
|
|
89
|
+
"cache-control": "no-store"
|
|
90
|
+
};
|
|
91
|
+
function createPreviewCssHandler({ route, cache, logger }) {
|
|
92
|
+
return async function handlePreviewCssRequest(req) {
|
|
93
|
+
const pathname = new URL(req.url, "http://127.0.0.1").pathname;
|
|
94
|
+
if (pathname !== route) return void 0;
|
|
95
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
96
|
+
return { status: 405, headers: { allow: "GET, HEAD" }, body: "Method Not Allowed" };
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const css = await cache.get();
|
|
100
|
+
return {
|
|
101
|
+
status: 200,
|
|
102
|
+
headers: { ...CSS_HEADERS },
|
|
103
|
+
body: req.method === "HEAD" ? "" : css,
|
|
104
|
+
bodyEncoding: "utf8"
|
|
105
|
+
};
|
|
106
|
+
} catch (error) {
|
|
107
|
+
const message = `[zudo-sg] preview css compile failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
108
|
+
logger?.error(message);
|
|
109
|
+
return {
|
|
110
|
+
status: 500,
|
|
111
|
+
headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" },
|
|
112
|
+
body: message,
|
|
113
|
+
bodyEncoding: "utf8"
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
async function writePreviewCss(outDir, previewCssUrl, css) {
|
|
119
|
+
const target = previewCssOutputPath(outDir, previewCssUrl);
|
|
120
|
+
await rm(target, { force: true });
|
|
121
|
+
await mkdir(dirname(target), { recursive: true });
|
|
122
|
+
const temp = `${target}.${process.pid}-${randomBytes(6).toString("hex")}.tmp`;
|
|
123
|
+
try {
|
|
124
|
+
await writeFile(temp, css, "utf8");
|
|
125
|
+
await rename(temp, target);
|
|
126
|
+
} catch (error) {
|
|
127
|
+
await rm(temp, { force: true });
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
return target;
|
|
131
|
+
}
|
|
132
|
+
function createPreviewCssPlugin({ compile = compilePreviewCss } = {}) {
|
|
133
|
+
const caches = /* @__PURE__ */ new Map();
|
|
134
|
+
const cacheFor = (entry, logger) => {
|
|
135
|
+
let cache = caches.get(entry);
|
|
136
|
+
if (!cache) {
|
|
137
|
+
cache = createPreviewCssCache(entry, compile, logger);
|
|
138
|
+
caches.set(entry, cache);
|
|
139
|
+
}
|
|
140
|
+
return cache;
|
|
141
|
+
};
|
|
142
|
+
const registerHandler = (ctx) => {
|
|
143
|
+
const resolved = resolvePreviewCssPluginOptions(ctx.projectRoot, ctx.options);
|
|
144
|
+
const route = previewCssRoute(ctx.config.base, resolved.previewCssUrl);
|
|
145
|
+
ctx.register(
|
|
146
|
+
route,
|
|
147
|
+
createPreviewCssHandler({ route, cache: cacheFor(resolved.previewStyles, ctx.logger), logger: ctx.logger })
|
|
148
|
+
);
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
name: PLUGIN_NAME,
|
|
152
|
+
setup(ctx) {
|
|
153
|
+
resolvePreviewCssPluginOptions(ctx.projectRoot, ctx.options);
|
|
154
|
+
},
|
|
155
|
+
devMiddleware: registerHandler,
|
|
156
|
+
previewMiddleware: registerHandler,
|
|
157
|
+
async postBuild(ctx) {
|
|
158
|
+
const resolved = resolvePreviewCssPluginOptions(ctx.projectRoot, ctx.options);
|
|
159
|
+
const target = previewCssOutputPath(ctx.outDir, resolved.previewCssUrl);
|
|
160
|
+
await rm(target, { force: true });
|
|
161
|
+
const result = await compile(resolved.previewStyles);
|
|
162
|
+
await writePreviewCss(ctx.outDir, resolved.previewCssUrl, result.css);
|
|
163
|
+
ctx.logger.info(
|
|
164
|
+
`preview css written to ${toForwardSlash(target)} (${Buffer.byteLength(result.css)} bytes, ${result.candidateCount} candidates)`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
var preview_css_default = createPreviewCssPlugin();
|
|
170
|
+
export {
|
|
171
|
+
DEFAULT_PREVIEW_CSS_URL,
|
|
172
|
+
PLUGIN_NAME,
|
|
173
|
+
computeStamp,
|
|
174
|
+
createPreviewCssCache,
|
|
175
|
+
createPreviewCssHandler,
|
|
176
|
+
createPreviewCssPlugin,
|
|
177
|
+
preview_css_default as default,
|
|
178
|
+
previewCssOutputPath,
|
|
179
|
+
previewCssRoute,
|
|
180
|
+
resolvePreviewCssPluginOptions,
|
|
181
|
+
watchedPaths,
|
|
182
|
+
writePreviewCss
|
|
183
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { ZfbPlugin, ZfbSetupContext } from "@takazudo/zfb/plugins";
|
|
2
|
+
import type { ComponentDocsRoot } from "../registry/component-docs.js";
|
|
3
|
+
import { type SgCatalogText, type SgContext } from "../sg-context.js";
|
|
4
|
+
import { type SgRoutes } from "../sg-routes.js";
|
|
5
|
+
export declare const PLUGIN_NAME = "@takazudo/zudo-sg/plugins/routes";
|
|
6
|
+
/** The zudo-doc plugin whose virtual modules the engine routes import. */
|
|
7
|
+
export declare const ZUDO_DOC_ROUTES_PLUGIN_NAME = "@takazudo/zudo-doc/plugins/routes";
|
|
8
|
+
export declare const CONTEXT_MODULE_ID = "virtual:zudo-sg-context";
|
|
9
|
+
export declare const REGISTRY_MODULE_ID = "virtual:zudo-sg-registry";
|
|
10
|
+
export declare const TOKENS_MODULE_ID = "virtual:zudo-sg-tokens";
|
|
11
|
+
/**
|
|
12
|
+
* Named exports of a `zudo-sg gen-token-manifest` output file, keyed by the
|
|
13
|
+
* `UiDesignTokensManifest` field each one fills (see
|
|
14
|
+
* cli/token-manifest/ui-token-manifest.ts).
|
|
15
|
+
*/
|
|
16
|
+
export declare const TOKENS_MANIFEST_EXPORTS: Readonly<Record<string, string>>;
|
|
17
|
+
/** Route key → `routes-src/` entrypoint file (ADR decision 6). */
|
|
18
|
+
export declare const ROUTE_ENTRYPOINTS: Readonly<Record<keyof SgRoutes, string>>;
|
|
19
|
+
export interface RoutesPluginOptions {
|
|
20
|
+
/** Project-root-relative path to the generated host registry (`zudo-sg.config.mjs` `registryOut`). */
|
|
21
|
+
registryModule: string;
|
|
22
|
+
routes?: Partial<SgRoutes>;
|
|
23
|
+
categoryOrder?: string[];
|
|
24
|
+
uiPackageName?: string;
|
|
25
|
+
previewCssUrl?: string;
|
|
26
|
+
catalog?: {
|
|
27
|
+
title?: string;
|
|
28
|
+
intro?: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Project-root-relative generated token manifest (`zudo-sg.config.mjs`
|
|
32
|
+
* `tokens.manifestOut`). Addition beyond the ADR's locked option list: the
|
|
33
|
+
* `/tokens` route has no other channel to the host manifest. Omitted → the
|
|
34
|
+
* route renders without dashboards.
|
|
35
|
+
*/
|
|
36
|
+
tokensManifestModule?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Per components root: its `storyModules` key prefix (e.g. `"ui/src"`) and
|
|
39
|
+
* the content collection holding its MDX docs. `zudoSg()` fills this from
|
|
40
|
+
* `componentsRoots`; omitted → detail pages render no component docs.
|
|
41
|
+
*/
|
|
42
|
+
componentDocs?: ComponentDocsRoot[];
|
|
43
|
+
}
|
|
44
|
+
export interface ResolvedRoutesPluginOptions {
|
|
45
|
+
/** Forward-slash absolute path of the host registry file. */
|
|
46
|
+
registryModule: string;
|
|
47
|
+
routes: SgRoutes;
|
|
48
|
+
categoryOrder: string[];
|
|
49
|
+
uiPackageName: string | null;
|
|
50
|
+
previewCssUrl: string;
|
|
51
|
+
catalog: SgCatalogText;
|
|
52
|
+
/** Forward-slash absolute path of the host token manifest, or `null`. */
|
|
53
|
+
tokensManifestModule: string | null;
|
|
54
|
+
componentDocs: ComponentDocsRoot[];
|
|
55
|
+
}
|
|
56
|
+
export interface RouteInjection {
|
|
57
|
+
key: keyof SgRoutes;
|
|
58
|
+
pattern: string;
|
|
59
|
+
/** Forward-slash absolute path of the `routes-src/*.tsx` entrypoint. */
|
|
60
|
+
entrypoint: string;
|
|
61
|
+
}
|
|
62
|
+
/** Validates the options block and resolves `registryModule`; throws `[zudo-sg] …` on invalid input. */
|
|
63
|
+
export declare function resolveRoutesPluginOptions(projectRoot: string, options: Record<string, unknown>): ResolvedRoutesPluginOptions;
|
|
64
|
+
/** Throws unless the zfb config lists the zudo-doc routes plugin descriptor. */
|
|
65
|
+
export declare function assertZudoDocRoutesPlugin(config: ZfbSetupContext["config"]): void;
|
|
66
|
+
/** Builds the JSON-only `sgContext` payload. */
|
|
67
|
+
export declare function buildSgContext(base: string | undefined, resolved: ResolvedRoutesPluginOptions): SgContext;
|
|
68
|
+
export declare function buildContextModuleSource(context: SgContext): string;
|
|
69
|
+
export declare function buildRegistryModuleSource(registryModule: string): string;
|
|
70
|
+
export declare function buildTokensModuleSource(tokensManifestModule: string | null): string;
|
|
71
|
+
/**
|
|
72
|
+
* This package's own root realpath — the workspace dir or
|
|
73
|
+
* `node_modules/.pnpm/…/@takazudo/zudo-sg`, whichever the plugin loaded from.
|
|
74
|
+
*/
|
|
75
|
+
export declare function resolvePackageRoot(): string;
|
|
76
|
+
/** Pairs every route pattern with its `routes-src/` entrypoint under `packageRoot`. */
|
|
77
|
+
export declare function deriveRouteInjections(routes: SgRoutes, packageRoot: string): RouteInjection[];
|
|
78
|
+
export interface CreateRoutesPluginOptions {
|
|
79
|
+
/** Test seam: overrides the package realpath lookup. */
|
|
80
|
+
packageRoot?: () => string;
|
|
81
|
+
}
|
|
82
|
+
export declare function createRoutesPlugin({ packageRoot }?: CreateRoutesPluginOptions): ZfbPlugin;
|
|
83
|
+
declare const _default: ZfbPlugin;
|
|
84
|
+
export default _default;
|