@agimon-ai/style-system 0.1.4 → 0.1.5
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/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +92 -1
- package/dist/index.d.cts +56 -2
- package/dist/index.d.mts +56 -2
- package/dist/index.mjs +91 -2
- package/dist/{stdio-BDcQDFR-.mjs → stdio-VllEe0CI.mjs} +17 -5
- package/dist/{stdio-DSao01TL.cjs → stdio-WGt31vrr.cjs} +28 -4
- package/package.json +2 -2
package/dist/cli.cjs
CHANGED
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { A as STYLE_SYSTEM_TYPES, C as getAppDesignSystemConfig, L as log, N as DEFAULT_STYLE_SYSTEM_CONFIG, P as TailwindCSSClassesService, a as STYLE_SYSTEM_CLI_NAME, b as getBundlerServiceFromConfig, i as createServer, k as resolveStyleSystemThemePath, o as STYLE_SYSTEM_VERSION, r as generateRestrictedClassesConfig, s as createContainer, t as StdioTransportHandler } from "./stdio-VllEe0CI.mjs";
|
|
3
3
|
import { promises } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { registerManagedProcess } from "@agimon-ai/foundation-exec";
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,95 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_stdio = require("./stdio-
|
|
2
|
+
const require_stdio = require("./stdio-WGt31vrr.cjs");
|
|
3
|
+
let node_fs = require("node:fs");
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
node_path = require_stdio.__toESM(node_path, 1);
|
|
6
|
+
let node_crypto = require("node:crypto");
|
|
7
|
+
//#region src/services/StoryPreviewService/StoryPreviewService.ts
|
|
8
|
+
const STORY_FILE_PATTERN = /\.stories\.(?:ts|tsx)$/;
|
|
9
|
+
const STORY_EXPORT_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
10
|
+
const UTF8_ENCODING = "utf8";
|
|
11
|
+
function isContained(root, candidate) {
|
|
12
|
+
const relative = node_path.default.relative(root, candidate);
|
|
13
|
+
return relative === "" || !relative.startsWith(`..${node_path.default.sep}`) && relative !== ".." && !node_path.default.isAbsolute(relative);
|
|
14
|
+
}
|
|
15
|
+
/** Builds and owns disposable, self-contained HTML previews for exact story exports. */
|
|
16
|
+
var StoryPreviewService = class {
|
|
17
|
+
workspaceRoot;
|
|
18
|
+
storiesIndexFactory;
|
|
19
|
+
configLoader;
|
|
20
|
+
bundlerFactory;
|
|
21
|
+
previews = /* @__PURE__ */ new Map();
|
|
22
|
+
constructor(options = {}) {
|
|
23
|
+
this.workspaceRoot = node_path.default.resolve(options.workspaceRoot ?? require_stdio.TemplatesManagerService.getWorkspaceRootSync());
|
|
24
|
+
this.storiesIndexFactory = options.storiesIndexFactory ?? ((workspaceRoot, storyFilePath) => new require_stdio.StoriesIndexService({
|
|
25
|
+
workspaceRoot,
|
|
26
|
+
storyFiles: [storyFilePath],
|
|
27
|
+
searchRoots: []
|
|
28
|
+
}));
|
|
29
|
+
this.configLoader = options.configLoader ?? require_stdio.getAppDesignSystemConfig;
|
|
30
|
+
this.bundlerFactory = options.bundlerFactory ?? ((config) => config.bundler ? require_stdio.getBundlerService(config.bundler) : require_stdio.createDefaultBundlerService());
|
|
31
|
+
}
|
|
32
|
+
async build(input) {
|
|
33
|
+
if (!STORY_EXPORT_PATTERN.test(input.storyExport)) throw new Error("storyExport must be an exact JavaScript named export");
|
|
34
|
+
const workspaceRoot = await node_fs.promises.realpath(this.workspaceRoot);
|
|
35
|
+
const appPath = await this.resolveContainedPath(workspaceRoot, input.appPath, "appPath");
|
|
36
|
+
const storyFilePath = await this.resolveContainedPath(workspaceRoot, input.storyFilePath, "storyFilePath");
|
|
37
|
+
if (!STORY_FILE_PATTERN.test(storyFilePath)) throw new Error("storyFilePath must name a .stories.ts or .stories.tsx file");
|
|
38
|
+
const index = this.storiesIndexFactory(workspaceRoot, storyFilePath);
|
|
39
|
+
await index.initialize();
|
|
40
|
+
const component = index.getComponentByFilePath(storyFilePath);
|
|
41
|
+
if (!component) throw new Error(`Story file was not indexed: ${node_path.default.relative(workspaceRoot, storyFilePath)}`);
|
|
42
|
+
if (!component.storyExports.includes(input.storyExport)) throw new Error(`Story export "${input.storyExport}" was not found. Available exports: ${component.storyExports.join(", ")}`);
|
|
43
|
+
const [source, config] = await Promise.all([node_fs.promises.readFile(storyFilePath, UTF8_ENCODING), this.configLoader(appPath)]);
|
|
44
|
+
const result = await this.bundlerFactory(config).prerenderComponent({
|
|
45
|
+
componentPath: storyFilePath,
|
|
46
|
+
storyName: input.storyExport,
|
|
47
|
+
args: input.args,
|
|
48
|
+
darkMode: input.darkMode,
|
|
49
|
+
appPath,
|
|
50
|
+
themePath: config.themeProvider,
|
|
51
|
+
cssFiles: config.cssFiles,
|
|
52
|
+
rootComponent: config.rootComponent,
|
|
53
|
+
unistylesConfig: config.unistylesConfig
|
|
54
|
+
});
|
|
55
|
+
const htmlFilePath = await node_fs.promises.realpath(result.htmlFilePath);
|
|
56
|
+
const artifactDirectory = node_path.default.dirname(htmlFilePath);
|
|
57
|
+
if (!isContained(node_path.default.join(appPath, ".tmp"), artifactDirectory)) throw new Error("Bundler returned a preview artifact outside the project temporary directory");
|
|
58
|
+
const handle = (0, node_crypto.randomUUID)();
|
|
59
|
+
const html = await node_fs.promises.readFile(htmlFilePath, UTF8_ENCODING);
|
|
60
|
+
this.previews.set(handle, { artifactDirectory });
|
|
61
|
+
return {
|
|
62
|
+
handle,
|
|
63
|
+
identity: {
|
|
64
|
+
storyFilePath: node_path.default.relative(workspaceRoot, storyFilePath),
|
|
65
|
+
storyExport: input.storyExport
|
|
66
|
+
},
|
|
67
|
+
sourceFingerprint: (0, node_crypto.createHash)("sha256").update(source).digest("hex"),
|
|
68
|
+
html
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
async dispose(handle) {
|
|
72
|
+
const preview = this.previews.get(handle);
|
|
73
|
+
if (!preview) return false;
|
|
74
|
+
this.previews.delete(handle);
|
|
75
|
+
await node_fs.promises.rm(preview.artifactDirectory, {
|
|
76
|
+
recursive: true,
|
|
77
|
+
force: true
|
|
78
|
+
});
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
async disposeAll() {
|
|
82
|
+
await Promise.all([...this.previews.keys()].map((handle) => this.dispose(handle)));
|
|
83
|
+
}
|
|
84
|
+
async resolveContainedPath(root, inputPath, field) {
|
|
85
|
+
if (!inputPath) throw new Error(`${field} is required`);
|
|
86
|
+
const candidate = node_path.default.isAbsolute(inputPath) ? inputPath : node_path.default.resolve(root, inputPath);
|
|
87
|
+
const canonical = await node_fs.promises.realpath(candidate);
|
|
88
|
+
if (!isContained(root, canonical)) throw new Error(`${field} must remain inside the workspace root`);
|
|
89
|
+
return canonical;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
//#endregion
|
|
3
93
|
exports.BaseBundlerService = require_stdio.BaseBundlerService;
|
|
4
94
|
exports.BaseCSSClassesService = require_stdio.BaseCSSClassesService;
|
|
5
95
|
Object.defineProperty(exports, "CSSClassesServiceFactory", {
|
|
@@ -60,6 +150,7 @@ Object.defineProperty(exports, "StoriesIndexService", {
|
|
|
60
150
|
return require_stdio.StoriesIndexService;
|
|
61
151
|
}
|
|
62
152
|
});
|
|
153
|
+
exports.StoryPreviewService = StoryPreviewService;
|
|
63
154
|
Object.defineProperty(exports, "StyleSystemConfigLoader", {
|
|
64
155
|
enumerable: true,
|
|
65
156
|
get: function() {
|
package/dist/index.d.cts
CHANGED
|
@@ -201,8 +201,10 @@ interface ComponentInfo {
|
|
|
201
201
|
fileHash: string;
|
|
202
202
|
/** Tags from story meta */
|
|
203
203
|
tags: string[];
|
|
204
|
-
/**
|
|
204
|
+
/** Display names of exported stories */
|
|
205
205
|
stories: string[];
|
|
206
|
+
/** Exact named exports available in the story module */
|
|
207
|
+
storyExports: string[];
|
|
206
208
|
/** Full story meta object */
|
|
207
209
|
meta: StoryMeta;
|
|
208
210
|
/** Component description extracted from file header JSDoc or meta.parameters.docs.description */
|
|
@@ -260,6 +262,7 @@ interface InitializationResult {
|
|
|
260
262
|
}
|
|
261
263
|
declare class StoriesIndexService {
|
|
262
264
|
private componentIndex;
|
|
265
|
+
private componentFileIndex;
|
|
263
266
|
private monorepoRoot;
|
|
264
267
|
private initialized;
|
|
265
268
|
/** Last initialization result for error reporting */
|
|
@@ -289,6 +292,7 @@ declare class StoriesIndexService {
|
|
|
289
292
|
* parse is shared by content hash across service instances and concurrent rules.
|
|
290
293
|
*/
|
|
291
294
|
private indexStoryFile;
|
|
295
|
+
private storeComponent;
|
|
292
296
|
private parseStoryFile;
|
|
293
297
|
/**
|
|
294
298
|
* Extract component description from file header JSDoc or meta.parameters.docs.description.
|
|
@@ -330,6 +334,8 @@ declare class StoriesIndexService {
|
|
|
330
334
|
* @returns True if file was updated, false if unchanged
|
|
331
335
|
*/
|
|
332
336
|
refreshFile(filePath: string): Promise<boolean>;
|
|
337
|
+
/** Get one indexed component by its canonical story file path. */
|
|
338
|
+
getComponentByFilePath(filePath: string): ComponentInfo | undefined;
|
|
333
339
|
/**
|
|
334
340
|
* Get all indexed components
|
|
335
341
|
* @returns Array of all component info objects
|
|
@@ -1036,6 +1042,54 @@ declare class GetUiComponentService {
|
|
|
1036
1042
|
private readStoryFile;
|
|
1037
1043
|
}
|
|
1038
1044
|
//#endregion
|
|
1045
|
+
//#region src/services/StoryPreviewService/types.d.ts
|
|
1046
|
+
interface StoryPreviewInput {
|
|
1047
|
+
/** Project directory, relative to the workspace root or absolute. */
|
|
1048
|
+
appPath: string;
|
|
1049
|
+
/** Story file, relative to the workspace root or absolute. */
|
|
1050
|
+
storyFilePath: string;
|
|
1051
|
+
/** Exact named export to render. */
|
|
1052
|
+
storyExport: string;
|
|
1053
|
+
args?: Record<string, unknown>;
|
|
1054
|
+
darkMode?: boolean;
|
|
1055
|
+
}
|
|
1056
|
+
interface StoryPreviewIdentity {
|
|
1057
|
+
/** Canonical workspace-relative story file path. */
|
|
1058
|
+
storyFilePath: string;
|
|
1059
|
+
/** Exact named export rendered from the story file. */
|
|
1060
|
+
storyExport: string;
|
|
1061
|
+
}
|
|
1062
|
+
interface StoryPreviewResult {
|
|
1063
|
+
/** Opaque identifier used to dispose this owned artifact. */
|
|
1064
|
+
handle: string;
|
|
1065
|
+
identity: StoryPreviewIdentity;
|
|
1066
|
+
/** SHA-256 fingerprint of the story source used for this build. */
|
|
1067
|
+
sourceFingerprint: string;
|
|
1068
|
+
/** Self-contained HTML produced by the configured style-system bundler. */
|
|
1069
|
+
html: string;
|
|
1070
|
+
}
|
|
1071
|
+
interface StoryPreviewServiceOptions {
|
|
1072
|
+
workspaceRoot?: string;
|
|
1073
|
+
storiesIndexFactory?: (workspaceRoot: string, storyFilePath: string) => StoriesIndexService;
|
|
1074
|
+
configLoader?: (appPath: string) => Promise<DesignSystemConfig>;
|
|
1075
|
+
bundlerFactory?: (config: DesignSystemConfig) => BaseBundlerService;
|
|
1076
|
+
}
|
|
1077
|
+
//#endregion
|
|
1078
|
+
//#region src/services/StoryPreviewService/StoryPreviewService.d.ts
|
|
1079
|
+
/** Builds and owns disposable, self-contained HTML previews for exact story exports. */
|
|
1080
|
+
declare class StoryPreviewService {
|
|
1081
|
+
private readonly workspaceRoot;
|
|
1082
|
+
private readonly storiesIndexFactory;
|
|
1083
|
+
private readonly configLoader;
|
|
1084
|
+
private readonly bundlerFactory;
|
|
1085
|
+
private readonly previews;
|
|
1086
|
+
constructor(options?: StoryPreviewServiceOptions);
|
|
1087
|
+
build(input: StoryPreviewInput): Promise<StoryPreviewResult>;
|
|
1088
|
+
dispose(handle: string): Promise<boolean>;
|
|
1089
|
+
disposeAll(): Promise<void>;
|
|
1090
|
+
private resolveContainedPath;
|
|
1091
|
+
}
|
|
1092
|
+
//#endregion
|
|
1039
1093
|
//#region src/services/ThemeService/types.d.ts
|
|
1040
1094
|
/**
|
|
1041
1095
|
* ThemeService Types
|
|
@@ -1956,4 +2010,4 @@ declare class StdioTransportHandler {
|
|
|
1956
2010
|
stop(): Promise<void>;
|
|
1957
2011
|
}
|
|
1958
2012
|
//#endregion
|
|
1959
|
-
export { BaseBundlerService, BaseCSSClassesService, type CSSClassCategory, type CSSClassValue, type CSSClassesResult, CSSClassesServiceFactory, ComponentRendererService, DEFAULT_STYLE_SYSTEM_CONFIG, type DesignSystemConfig, GetCSSClassesTool, GetComponentVisualTool, GetUiComponentService, ListAppComponentsTool, ListSharedComponentsTool, ListThemesTool, type OxlintRestrictedClassPattern, type OxlintRestrictedClassesConfig, PolishComponentTool, type ResolvedDesignSystemConfig, STYLE_SYSTEM_TYPES, StdioTransportHandler, StoriesIndexService, type StyleSystemConfig, StyleSystemConfigLoader, type StyleSystemModuleOptions, TailwindCSSClassesService, ThemeService, type Tool, type ToolDefinition, ViteReactBundlerService, createContainer, createDefaultBundlerService, createServer, createStyleSystemModule, extractCustomTokenNames, generateRestrictedClassesConfig, getAppDesignSystemConfig, getBundlerServiceFromConfig, getSharedComponentTags, hasStyleSystemProjectConfig, resetStyleSystemConfigCache, resolveAppDesignSystemConfig, resolveStyleSystemThemePath };
|
|
2013
|
+
export { BaseBundlerService, BaseCSSClassesService, type CSSClassCategory, type CSSClassValue, type CSSClassesResult, CSSClassesServiceFactory, ComponentRendererService, DEFAULT_STYLE_SYSTEM_CONFIG, type DesignSystemConfig, GetCSSClassesTool, GetComponentVisualTool, GetUiComponentService, ListAppComponentsTool, ListSharedComponentsTool, ListThemesTool, type OxlintRestrictedClassPattern, type OxlintRestrictedClassesConfig, PolishComponentTool, type ResolvedDesignSystemConfig, STYLE_SYSTEM_TYPES, StdioTransportHandler, StoriesIndexService, type StoryPreviewIdentity, type StoryPreviewInput, type StoryPreviewResult, StoryPreviewService, type StoryPreviewServiceOptions, type StyleSystemConfig, StyleSystemConfigLoader, type StyleSystemModuleOptions, TailwindCSSClassesService, ThemeService, type Tool, type ToolDefinition, ViteReactBundlerService, createContainer, createDefaultBundlerService, createServer, createStyleSystemModule, extractCustomTokenNames, generateRestrictedClassesConfig, getAppDesignSystemConfig, getBundlerServiceFromConfig, getSharedComponentTags, hasStyleSystemProjectConfig, resetStyleSystemConfigCache, resolveAppDesignSystemConfig, resolveStyleSystemThemePath };
|
package/dist/index.d.mts
CHANGED
|
@@ -201,8 +201,10 @@ interface ComponentInfo {
|
|
|
201
201
|
fileHash: string;
|
|
202
202
|
/** Tags from story meta */
|
|
203
203
|
tags: string[];
|
|
204
|
-
/**
|
|
204
|
+
/** Display names of exported stories */
|
|
205
205
|
stories: string[];
|
|
206
|
+
/** Exact named exports available in the story module */
|
|
207
|
+
storyExports: string[];
|
|
206
208
|
/** Full story meta object */
|
|
207
209
|
meta: StoryMeta;
|
|
208
210
|
/** Component description extracted from file header JSDoc or meta.parameters.docs.description */
|
|
@@ -260,6 +262,7 @@ interface InitializationResult {
|
|
|
260
262
|
}
|
|
261
263
|
declare class StoriesIndexService {
|
|
262
264
|
private componentIndex;
|
|
265
|
+
private componentFileIndex;
|
|
263
266
|
private monorepoRoot;
|
|
264
267
|
private initialized;
|
|
265
268
|
/** Last initialization result for error reporting */
|
|
@@ -289,6 +292,7 @@ declare class StoriesIndexService {
|
|
|
289
292
|
* parse is shared by content hash across service instances and concurrent rules.
|
|
290
293
|
*/
|
|
291
294
|
private indexStoryFile;
|
|
295
|
+
private storeComponent;
|
|
292
296
|
private parseStoryFile;
|
|
293
297
|
/**
|
|
294
298
|
* Extract component description from file header JSDoc or meta.parameters.docs.description.
|
|
@@ -330,6 +334,8 @@ declare class StoriesIndexService {
|
|
|
330
334
|
* @returns True if file was updated, false if unchanged
|
|
331
335
|
*/
|
|
332
336
|
refreshFile(filePath: string): Promise<boolean>;
|
|
337
|
+
/** Get one indexed component by its canonical story file path. */
|
|
338
|
+
getComponentByFilePath(filePath: string): ComponentInfo | undefined;
|
|
333
339
|
/**
|
|
334
340
|
* Get all indexed components
|
|
335
341
|
* @returns Array of all component info objects
|
|
@@ -1036,6 +1042,54 @@ declare class GetUiComponentService {
|
|
|
1036
1042
|
private readStoryFile;
|
|
1037
1043
|
}
|
|
1038
1044
|
//#endregion
|
|
1045
|
+
//#region src/services/StoryPreviewService/types.d.ts
|
|
1046
|
+
interface StoryPreviewInput {
|
|
1047
|
+
/** Project directory, relative to the workspace root or absolute. */
|
|
1048
|
+
appPath: string;
|
|
1049
|
+
/** Story file, relative to the workspace root or absolute. */
|
|
1050
|
+
storyFilePath: string;
|
|
1051
|
+
/** Exact named export to render. */
|
|
1052
|
+
storyExport: string;
|
|
1053
|
+
args?: Record<string, unknown>;
|
|
1054
|
+
darkMode?: boolean;
|
|
1055
|
+
}
|
|
1056
|
+
interface StoryPreviewIdentity {
|
|
1057
|
+
/** Canonical workspace-relative story file path. */
|
|
1058
|
+
storyFilePath: string;
|
|
1059
|
+
/** Exact named export rendered from the story file. */
|
|
1060
|
+
storyExport: string;
|
|
1061
|
+
}
|
|
1062
|
+
interface StoryPreviewResult {
|
|
1063
|
+
/** Opaque identifier used to dispose this owned artifact. */
|
|
1064
|
+
handle: string;
|
|
1065
|
+
identity: StoryPreviewIdentity;
|
|
1066
|
+
/** SHA-256 fingerprint of the story source used for this build. */
|
|
1067
|
+
sourceFingerprint: string;
|
|
1068
|
+
/** Self-contained HTML produced by the configured style-system bundler. */
|
|
1069
|
+
html: string;
|
|
1070
|
+
}
|
|
1071
|
+
interface StoryPreviewServiceOptions {
|
|
1072
|
+
workspaceRoot?: string;
|
|
1073
|
+
storiesIndexFactory?: (workspaceRoot: string, storyFilePath: string) => StoriesIndexService;
|
|
1074
|
+
configLoader?: (appPath: string) => Promise<DesignSystemConfig>;
|
|
1075
|
+
bundlerFactory?: (config: DesignSystemConfig) => BaseBundlerService;
|
|
1076
|
+
}
|
|
1077
|
+
//#endregion
|
|
1078
|
+
//#region src/services/StoryPreviewService/StoryPreviewService.d.ts
|
|
1079
|
+
/** Builds and owns disposable, self-contained HTML previews for exact story exports. */
|
|
1080
|
+
declare class StoryPreviewService {
|
|
1081
|
+
private readonly workspaceRoot;
|
|
1082
|
+
private readonly storiesIndexFactory;
|
|
1083
|
+
private readonly configLoader;
|
|
1084
|
+
private readonly bundlerFactory;
|
|
1085
|
+
private readonly previews;
|
|
1086
|
+
constructor(options?: StoryPreviewServiceOptions);
|
|
1087
|
+
build(input: StoryPreviewInput): Promise<StoryPreviewResult>;
|
|
1088
|
+
dispose(handle: string): Promise<boolean>;
|
|
1089
|
+
disposeAll(): Promise<void>;
|
|
1090
|
+
private resolveContainedPath;
|
|
1091
|
+
}
|
|
1092
|
+
//#endregion
|
|
1039
1093
|
//#region src/services/ThemeService/types.d.ts
|
|
1040
1094
|
/**
|
|
1041
1095
|
* ThemeService Types
|
|
@@ -1956,4 +2010,4 @@ declare class StdioTransportHandler {
|
|
|
1956
2010
|
stop(): Promise<void>;
|
|
1957
2011
|
}
|
|
1958
2012
|
//#endregion
|
|
1959
|
-
export { BaseBundlerService, BaseCSSClassesService, type CSSClassCategory, type CSSClassValue, type CSSClassesResult, CSSClassesServiceFactory, ComponentRendererService, DEFAULT_STYLE_SYSTEM_CONFIG, type DesignSystemConfig, GetCSSClassesTool, GetComponentVisualTool, GetUiComponentService, ListAppComponentsTool, ListSharedComponentsTool, ListThemesTool, type OxlintRestrictedClassPattern, type OxlintRestrictedClassesConfig, PolishComponentTool, type ResolvedDesignSystemConfig, STYLE_SYSTEM_TYPES, StdioTransportHandler, StoriesIndexService, type StyleSystemConfig, StyleSystemConfigLoader, type StyleSystemModuleOptions, TailwindCSSClassesService, ThemeService, type Tool, type ToolDefinition, ViteReactBundlerService, createContainer, createDefaultBundlerService, createServer, createStyleSystemModule, extractCustomTokenNames, generateRestrictedClassesConfig, getAppDesignSystemConfig, getBundlerServiceFromConfig, getSharedComponentTags, hasStyleSystemProjectConfig, resetStyleSystemConfigCache, resolveAppDesignSystemConfig, resolveStyleSystemThemePath };
|
|
2013
|
+
export { BaseBundlerService, BaseCSSClassesService, type CSSClassCategory, type CSSClassValue, type CSSClassesResult, CSSClassesServiceFactory, ComponentRendererService, DEFAULT_STYLE_SYSTEM_CONFIG, type DesignSystemConfig, GetCSSClassesTool, GetComponentVisualTool, GetUiComponentService, ListAppComponentsTool, ListSharedComponentsTool, ListThemesTool, type OxlintRestrictedClassPattern, type OxlintRestrictedClassesConfig, PolishComponentTool, type ResolvedDesignSystemConfig, STYLE_SYSTEM_TYPES, StdioTransportHandler, StoriesIndexService, type StoryPreviewIdentity, type StoryPreviewInput, type StoryPreviewResult, StoryPreviewService, type StoryPreviewServiceOptions, type StyleSystemConfig, StyleSystemConfigLoader, type StyleSystemModuleOptions, TailwindCSSClassesService, ThemeService, type Tool, type ToolDefinition, ViteReactBundlerService, createContainer, createDefaultBundlerService, createServer, createStyleSystemModule, extractCustomTokenNames, generateRestrictedClassesConfig, getAppDesignSystemConfig, getBundlerServiceFromConfig, getSharedComponentTags, hasStyleSystemProjectConfig, resetStyleSystemConfigCache, resolveAppDesignSystemConfig, resolveStyleSystemThemePath };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,91 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
|
|
1
|
+
import { A as STYLE_SYSTEM_TYPES, C as getAppDesignSystemConfig, D as resolveAppDesignSystemConfig, E as resetStyleSystemConfigCache, F as BaseCSSClassesService, I as TemplatesManagerService, M as CSSClassesServiceFactory, N as DEFAULT_STYLE_SYSTEM_CONFIG, O as StyleSystemConfigLoader, P as TailwindCSSClassesService, S as BaseBundlerService, T as hasStyleSystemProjectConfig, _ as ThemeService, b as getBundlerServiceFromConfig, c as createStyleSystemModule, d as ListSharedComponentsTool, f as GetComponentVisualTool, g as ComponentRendererService, h as GetUiComponentService, i as createServer, j as StoriesIndexService, k as resolveStyleSystemThemePath, l as PolishComponentTool, m as ListThemesTool, n as extractCustomTokenNames, p as GetCSSClassesTool, r as generateRestrictedClassesConfig, s as createContainer, t as StdioTransportHandler, u as ListAppComponentsTool, v as createDefaultBundlerService, w as getSharedComponentTags, x as ViteReactBundlerService, y as getBundlerService } from "./stdio-VllEe0CI.mjs";
|
|
2
|
+
import { promises } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
5
|
+
//#region src/services/StoryPreviewService/StoryPreviewService.ts
|
|
6
|
+
const STORY_FILE_PATTERN = /\.stories\.(?:ts|tsx)$/;
|
|
7
|
+
const STORY_EXPORT_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
8
|
+
const UTF8_ENCODING = "utf8";
|
|
9
|
+
function isContained(root, candidate) {
|
|
10
|
+
const relative = path.relative(root, candidate);
|
|
11
|
+
return relative === "" || !relative.startsWith(`..${path.sep}`) && relative !== ".." && !path.isAbsolute(relative);
|
|
12
|
+
}
|
|
13
|
+
/** Builds and owns disposable, self-contained HTML previews for exact story exports. */
|
|
14
|
+
var StoryPreviewService = class {
|
|
15
|
+
workspaceRoot;
|
|
16
|
+
storiesIndexFactory;
|
|
17
|
+
configLoader;
|
|
18
|
+
bundlerFactory;
|
|
19
|
+
previews = /* @__PURE__ */ new Map();
|
|
20
|
+
constructor(options = {}) {
|
|
21
|
+
this.workspaceRoot = path.resolve(options.workspaceRoot ?? TemplatesManagerService.getWorkspaceRootSync());
|
|
22
|
+
this.storiesIndexFactory = options.storiesIndexFactory ?? ((workspaceRoot, storyFilePath) => new StoriesIndexService({
|
|
23
|
+
workspaceRoot,
|
|
24
|
+
storyFiles: [storyFilePath],
|
|
25
|
+
searchRoots: []
|
|
26
|
+
}));
|
|
27
|
+
this.configLoader = options.configLoader ?? getAppDesignSystemConfig;
|
|
28
|
+
this.bundlerFactory = options.bundlerFactory ?? ((config) => config.bundler ? getBundlerService(config.bundler) : createDefaultBundlerService());
|
|
29
|
+
}
|
|
30
|
+
async build(input) {
|
|
31
|
+
if (!STORY_EXPORT_PATTERN.test(input.storyExport)) throw new Error("storyExport must be an exact JavaScript named export");
|
|
32
|
+
const workspaceRoot = await promises.realpath(this.workspaceRoot);
|
|
33
|
+
const appPath = await this.resolveContainedPath(workspaceRoot, input.appPath, "appPath");
|
|
34
|
+
const storyFilePath = await this.resolveContainedPath(workspaceRoot, input.storyFilePath, "storyFilePath");
|
|
35
|
+
if (!STORY_FILE_PATTERN.test(storyFilePath)) throw new Error("storyFilePath must name a .stories.ts or .stories.tsx file");
|
|
36
|
+
const index = this.storiesIndexFactory(workspaceRoot, storyFilePath);
|
|
37
|
+
await index.initialize();
|
|
38
|
+
const component = index.getComponentByFilePath(storyFilePath);
|
|
39
|
+
if (!component) throw new Error(`Story file was not indexed: ${path.relative(workspaceRoot, storyFilePath)}`);
|
|
40
|
+
if (!component.storyExports.includes(input.storyExport)) throw new Error(`Story export "${input.storyExport}" was not found. Available exports: ${component.storyExports.join(", ")}`);
|
|
41
|
+
const [source, config] = await Promise.all([promises.readFile(storyFilePath, UTF8_ENCODING), this.configLoader(appPath)]);
|
|
42
|
+
const result = await this.bundlerFactory(config).prerenderComponent({
|
|
43
|
+
componentPath: storyFilePath,
|
|
44
|
+
storyName: input.storyExport,
|
|
45
|
+
args: input.args,
|
|
46
|
+
darkMode: input.darkMode,
|
|
47
|
+
appPath,
|
|
48
|
+
themePath: config.themeProvider,
|
|
49
|
+
cssFiles: config.cssFiles,
|
|
50
|
+
rootComponent: config.rootComponent,
|
|
51
|
+
unistylesConfig: config.unistylesConfig
|
|
52
|
+
});
|
|
53
|
+
const htmlFilePath = await promises.realpath(result.htmlFilePath);
|
|
54
|
+
const artifactDirectory = path.dirname(htmlFilePath);
|
|
55
|
+
if (!isContained(path.join(appPath, ".tmp"), artifactDirectory)) throw new Error("Bundler returned a preview artifact outside the project temporary directory");
|
|
56
|
+
const handle = randomUUID();
|
|
57
|
+
const html = await promises.readFile(htmlFilePath, UTF8_ENCODING);
|
|
58
|
+
this.previews.set(handle, { artifactDirectory });
|
|
59
|
+
return {
|
|
60
|
+
handle,
|
|
61
|
+
identity: {
|
|
62
|
+
storyFilePath: path.relative(workspaceRoot, storyFilePath),
|
|
63
|
+
storyExport: input.storyExport
|
|
64
|
+
},
|
|
65
|
+
sourceFingerprint: createHash("sha256").update(source).digest("hex"),
|
|
66
|
+
html
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
async dispose(handle) {
|
|
70
|
+
const preview = this.previews.get(handle);
|
|
71
|
+
if (!preview) return false;
|
|
72
|
+
this.previews.delete(handle);
|
|
73
|
+
await promises.rm(preview.artifactDirectory, {
|
|
74
|
+
recursive: true,
|
|
75
|
+
force: true
|
|
76
|
+
});
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
async disposeAll() {
|
|
80
|
+
await Promise.all([...this.previews.keys()].map((handle) => this.dispose(handle)));
|
|
81
|
+
}
|
|
82
|
+
async resolveContainedPath(root, inputPath, field) {
|
|
83
|
+
if (!inputPath) throw new Error(`${field} is required`);
|
|
84
|
+
const candidate = path.isAbsolute(inputPath) ? inputPath : path.resolve(root, inputPath);
|
|
85
|
+
const canonical = await promises.realpath(candidate);
|
|
86
|
+
if (!isContained(root, canonical)) throw new Error(`${field} must remain inside the workspace root`);
|
|
87
|
+
return canonical;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
//#endregion
|
|
91
|
+
export { BaseBundlerService, BaseCSSClassesService, CSSClassesServiceFactory, ComponentRendererService, DEFAULT_STYLE_SYSTEM_CONFIG, GetCSSClassesTool, GetComponentVisualTool, GetUiComponentService, ListAppComponentsTool, ListSharedComponentsTool, ListThemesTool, PolishComponentTool, STYLE_SYSTEM_TYPES, StdioTransportHandler, StoriesIndexService, StoryPreviewService, StyleSystemConfigLoader, TailwindCSSClassesService, ThemeService, ViteReactBundlerService, createContainer, createDefaultBundlerService, createServer, createStyleSystemModule, extractCustomTokenNames, generateRestrictedClassesConfig, getAppDesignSystemConfig, getBundlerServiceFromConfig, getSharedComponentTags, hasStyleSystemProjectConfig, resetStyleSystemConfigCache, resolveAppDesignSystemConfig, resolveStyleSystemThemePath };
|
|
@@ -863,6 +863,7 @@ const storyParseCache = /* @__PURE__ */ new Map();
|
|
|
863
863
|
const storyParseInFlight = /* @__PURE__ */ new Map();
|
|
864
864
|
let StoriesIndexService = class StoriesIndexService {
|
|
865
865
|
componentIndex = /* @__PURE__ */ new Map();
|
|
866
|
+
componentFileIndex = /* @__PURE__ */ new Map();
|
|
866
867
|
monorepoRoot;
|
|
867
868
|
initialized = false;
|
|
868
869
|
/** Last initialization result for error reporting */
|
|
@@ -956,7 +957,7 @@ let StoriesIndexService = class StoriesIndexService {
|
|
|
956
957
|
const fileHash = this.hashContent(content);
|
|
957
958
|
const cached = storyParseCache.get(filePath);
|
|
958
959
|
if (cached?.fileHash === fileHash) {
|
|
959
|
-
if (cached.component) this.
|
|
960
|
+
if (cached.component) this.storeComponent(cached.component);
|
|
960
961
|
return;
|
|
961
962
|
}
|
|
962
963
|
const inFlightKey = `${filePath}\u0000${fileHash}`;
|
|
@@ -976,7 +977,11 @@ let StoriesIndexService = class StoriesIndexService {
|
|
|
976
977
|
fileHash,
|
|
977
978
|
component
|
|
978
979
|
});
|
|
979
|
-
if (component) this.
|
|
980
|
+
if (component) this.storeComponent(component);
|
|
981
|
+
}
|
|
982
|
+
storeComponent(component) {
|
|
983
|
+
this.componentIndex.set(component.title, component);
|
|
984
|
+
this.componentFileIndex.set(path.resolve(component.filePath), component);
|
|
980
985
|
}
|
|
981
986
|
parseStoryFile(filePath, content, fileHash) {
|
|
982
987
|
const csf = loadCsf(content, {
|
|
@@ -989,6 +994,7 @@ let StoriesIndexService = class StoriesIndexService {
|
|
|
989
994
|
return null;
|
|
990
995
|
}
|
|
991
996
|
const stories = csf.stories.map((story) => story.name).filter((name) => !!name);
|
|
997
|
+
const storyExports = Object.keys(csf._storyExports);
|
|
992
998
|
const tags = Array.isArray(csf.meta.tags) ? csf.meta.tags.filter((tag) => typeof tag === "string") : [];
|
|
993
999
|
const description = this.extractDescription(content, csf.meta);
|
|
994
1000
|
const meta = {
|
|
@@ -1001,6 +1007,7 @@ let StoriesIndexService = class StoriesIndexService {
|
|
|
1001
1007
|
fileHash,
|
|
1002
1008
|
tags,
|
|
1003
1009
|
stories,
|
|
1010
|
+
storyExports,
|
|
1004
1011
|
meta,
|
|
1005
1012
|
description
|
|
1006
1013
|
};
|
|
@@ -1078,18 +1085,23 @@ let StoriesIndexService = class StoriesIndexService {
|
|
|
1078
1085
|
await this.indexStoryFile(filePath);
|
|
1079
1086
|
return true;
|
|
1080
1087
|
}
|
|
1088
|
+
/** Get one indexed component by its canonical story file path. */
|
|
1089
|
+
getComponentByFilePath(filePath) {
|
|
1090
|
+
return this.componentFileIndex.get(path.resolve(filePath));
|
|
1091
|
+
}
|
|
1081
1092
|
/**
|
|
1082
1093
|
* Get all indexed components
|
|
1083
1094
|
* @returns Array of all component info objects
|
|
1084
1095
|
*/
|
|
1085
1096
|
getAllComponents() {
|
|
1086
|
-
return Array.from(this.
|
|
1097
|
+
return Array.from(this.componentFileIndex.values());
|
|
1087
1098
|
}
|
|
1088
1099
|
/**
|
|
1089
1100
|
* Clear the index (useful for testing)
|
|
1090
1101
|
*/
|
|
1091
1102
|
clear() {
|
|
1092
1103
|
this.componentIndex.clear();
|
|
1104
|
+
this.componentFileIndex.clear();
|
|
1093
1105
|
this.initialized = false;
|
|
1094
1106
|
this.lastInitResult = null;
|
|
1095
1107
|
}
|
|
@@ -5017,7 +5029,7 @@ function createContainer(options) {
|
|
|
5017
5029
|
}
|
|
5018
5030
|
//#endregion
|
|
5019
5031
|
//#region package.json
|
|
5020
|
-
var version = "0.1.
|
|
5032
|
+
var version = "0.1.4";
|
|
5021
5033
|
//#endregion
|
|
5022
5034
|
//#region src/metadata.ts
|
|
5023
5035
|
const STYLE_SYSTEM_CLI_NAME = "style-system";
|
|
@@ -5285,4 +5297,4 @@ var StdioTransportHandler = class {
|
|
|
5285
5297
|
}
|
|
5286
5298
|
};
|
|
5287
5299
|
//#endregion
|
|
5288
|
-
export {
|
|
5300
|
+
export { STYLE_SYSTEM_TYPES as A, getAppDesignSystemConfig as C, resolveAppDesignSystemConfig as D, resetStyleSystemConfigCache as E, BaseCSSClassesService as F, TemplatesManagerService as I, log as L, CSSClassesServiceFactory as M, DEFAULT_STYLE_SYSTEM_CONFIG as N, StyleSystemConfigLoader as O, TailwindCSSClassesService as P, BaseBundlerService as S, hasStyleSystemProjectConfig as T, ThemeService as _, STYLE_SYSTEM_CLI_NAME as a, getBundlerServiceFromConfig as b, createStyleSystemModule as c, ListSharedComponentsTool as d, GetComponentVisualTool as f, ComponentRendererService as g, GetUiComponentService as h, createServer as i, StoriesIndexService as j, resolveStyleSystemThemePath as k, PolishComponentTool as l, ListThemesTool as m, extractCustomTokenNames as n, STYLE_SYSTEM_VERSION as o, GetCSSClassesTool as p, generateRestrictedClassesConfig as r, createContainer as s, StdioTransportHandler as t, ListAppComponentsTool as u, createDefaultBundlerService as v, getSharedComponentTags as w, ViteReactBundlerService as x, getBundlerService as y };
|
|
@@ -889,6 +889,7 @@ const storyParseCache = /* @__PURE__ */ new Map();
|
|
|
889
889
|
const storyParseInFlight = /* @__PURE__ */ new Map();
|
|
890
890
|
let StoriesIndexService = class StoriesIndexService {
|
|
891
891
|
componentIndex = /* @__PURE__ */ new Map();
|
|
892
|
+
componentFileIndex = /* @__PURE__ */ new Map();
|
|
892
893
|
monorepoRoot;
|
|
893
894
|
initialized = false;
|
|
894
895
|
/** Last initialization result for error reporting */
|
|
@@ -982,7 +983,7 @@ let StoriesIndexService = class StoriesIndexService {
|
|
|
982
983
|
const fileHash = this.hashContent(content);
|
|
983
984
|
const cached = storyParseCache.get(filePath);
|
|
984
985
|
if (cached?.fileHash === fileHash) {
|
|
985
|
-
if (cached.component) this.
|
|
986
|
+
if (cached.component) this.storeComponent(cached.component);
|
|
986
987
|
return;
|
|
987
988
|
}
|
|
988
989
|
const inFlightKey = `${filePath}\u0000${fileHash}`;
|
|
@@ -1002,7 +1003,11 @@ let StoriesIndexService = class StoriesIndexService {
|
|
|
1002
1003
|
fileHash,
|
|
1003
1004
|
component
|
|
1004
1005
|
});
|
|
1005
|
-
if (component) this.
|
|
1006
|
+
if (component) this.storeComponent(component);
|
|
1007
|
+
}
|
|
1008
|
+
storeComponent(component) {
|
|
1009
|
+
this.componentIndex.set(component.title, component);
|
|
1010
|
+
this.componentFileIndex.set(node_path.default.resolve(component.filePath), component);
|
|
1006
1011
|
}
|
|
1007
1012
|
parseStoryFile(filePath, content, fileHash) {
|
|
1008
1013
|
const csf = (0, storybook_internal_csf_tools.loadCsf)(content, {
|
|
@@ -1015,6 +1020,7 @@ let StoriesIndexService = class StoriesIndexService {
|
|
|
1015
1020
|
return null;
|
|
1016
1021
|
}
|
|
1017
1022
|
const stories = csf.stories.map((story) => story.name).filter((name) => !!name);
|
|
1023
|
+
const storyExports = Object.keys(csf._storyExports);
|
|
1018
1024
|
const tags = Array.isArray(csf.meta.tags) ? csf.meta.tags.filter((tag) => typeof tag === "string") : [];
|
|
1019
1025
|
const description = this.extractDescription(content, csf.meta);
|
|
1020
1026
|
const meta = {
|
|
@@ -1027,6 +1033,7 @@ let StoriesIndexService = class StoriesIndexService {
|
|
|
1027
1033
|
fileHash,
|
|
1028
1034
|
tags,
|
|
1029
1035
|
stories,
|
|
1036
|
+
storyExports,
|
|
1030
1037
|
meta,
|
|
1031
1038
|
description
|
|
1032
1039
|
};
|
|
@@ -1104,18 +1111,23 @@ let StoriesIndexService = class StoriesIndexService {
|
|
|
1104
1111
|
await this.indexStoryFile(filePath);
|
|
1105
1112
|
return true;
|
|
1106
1113
|
}
|
|
1114
|
+
/** Get one indexed component by its canonical story file path. */
|
|
1115
|
+
getComponentByFilePath(filePath) {
|
|
1116
|
+
return this.componentFileIndex.get(node_path.default.resolve(filePath));
|
|
1117
|
+
}
|
|
1107
1118
|
/**
|
|
1108
1119
|
* Get all indexed components
|
|
1109
1120
|
* @returns Array of all component info objects
|
|
1110
1121
|
*/
|
|
1111
1122
|
getAllComponents() {
|
|
1112
|
-
return Array.from(this.
|
|
1123
|
+
return Array.from(this.componentFileIndex.values());
|
|
1113
1124
|
}
|
|
1114
1125
|
/**
|
|
1115
1126
|
* Clear the index (useful for testing)
|
|
1116
1127
|
*/
|
|
1117
1128
|
clear() {
|
|
1118
1129
|
this.componentIndex.clear();
|
|
1130
|
+
this.componentFileIndex.clear();
|
|
1119
1131
|
this.initialized = false;
|
|
1120
1132
|
this.lastInitResult = null;
|
|
1121
1133
|
}
|
|
@@ -5043,7 +5055,7 @@ function createContainer(options) {
|
|
|
5043
5055
|
}
|
|
5044
5056
|
//#endregion
|
|
5045
5057
|
//#region package.json
|
|
5046
|
-
var version = "0.1.
|
|
5058
|
+
var version = "0.1.4";
|
|
5047
5059
|
//#endregion
|
|
5048
5060
|
//#region src/metadata.ts
|
|
5049
5061
|
const STYLE_SYSTEM_CLI_NAME = "style-system";
|
|
@@ -5425,6 +5437,12 @@ Object.defineProperty(exports, "TailwindCSSClassesService", {
|
|
|
5425
5437
|
return TailwindCSSClassesService;
|
|
5426
5438
|
}
|
|
5427
5439
|
});
|
|
5440
|
+
Object.defineProperty(exports, "TemplatesManagerService", {
|
|
5441
|
+
enumerable: true,
|
|
5442
|
+
get: function() {
|
|
5443
|
+
return TemplatesManagerService;
|
|
5444
|
+
}
|
|
5445
|
+
});
|
|
5428
5446
|
Object.defineProperty(exports, "ThemeService", {
|
|
5429
5447
|
enumerable: true,
|
|
5430
5448
|
get: function() {
|
|
@@ -5485,6 +5503,12 @@ Object.defineProperty(exports, "getAppDesignSystemConfig", {
|
|
|
5485
5503
|
return getAppDesignSystemConfig;
|
|
5486
5504
|
}
|
|
5487
5505
|
});
|
|
5506
|
+
Object.defineProperty(exports, "getBundlerService", {
|
|
5507
|
+
enumerable: true,
|
|
5508
|
+
get: function() {
|
|
5509
|
+
return getBundlerService;
|
|
5510
|
+
}
|
|
5511
|
+
});
|
|
5488
5512
|
Object.defineProperty(exports, "getBundlerServiceFromConfig", {
|
|
5489
5513
|
enumerable: true,
|
|
5490
5514
|
get: function() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agimon-ai/style-system",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "MCP server for exploring themes, Tailwind CSS classes, and UI components from Storybook with standalone component rendering capabilities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"design-system",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"tailwindcss": "4.3.3",
|
|
61
61
|
"vite": "8.1.5",
|
|
62
62
|
"vite-plugin-singlefile": "^2.3.3",
|
|
63
|
-
"@agimon-ai/foundation-exec": "0.26.
|
|
63
|
+
"@agimon-ai/foundation-exec": "0.26.27"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@babel/parser": "8.0.0",
|