@vizejs/vite-plugin-musea 0.268.0 → 0.270.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/README.md +14 -0
- package/dist/gallery/assets/{MonacoEditor-D6vHGjOV.js → MonacoEditor-CaEpEUhO.js} +2 -2
- package/dist/gallery/assets/{cssMode-COwrxII5.js → cssMode-CdtUUFyi.js} +1 -1
- package/dist/gallery/assets/{editor.api2-CJZ9tF6K.js → editor.api2-DZBCMTPp.js} +1 -1
- package/dist/gallery/assets/{editor.main-Dt6-6pas.js → editor.main-Bmw0213t.js} +2 -2
- package/dist/gallery/assets/{freemarker2-Dnb1g0Jo.js → freemarker2-Bv3x1gTk.js} +1 -1
- package/dist/gallery/assets/{handlebars-DOmT_A6M.js → handlebars-D11b15L3.js} +1 -1
- package/dist/gallery/assets/{html-Qempe7xt.js → html-DM26Zsuc.js} +1 -1
- package/dist/gallery/assets/{htmlMode-CKgIR73L.js → htmlMode-DYNh3Pzf.js} +1 -1
- package/dist/gallery/assets/{index-Dtsku8dI.js → index-Bc4LRCXi.js} +3 -3
- package/dist/gallery/assets/{index-D67uewr9.css → index-Bwb5j7qQ.css} +1 -1
- package/dist/gallery/assets/{javascript-o8yJHIsv.js → javascript-CfNzBMkj.js} +1 -1
- package/dist/gallery/assets/{jsonMode-DDj5uiry.js → jsonMode-B-ArV4k8.js} +1 -1
- package/dist/gallery/assets/{liquid-GihPC2aI.js → liquid-Ba5jhpVp.js} +1 -1
- package/dist/gallery/assets/{lspLanguageFeatures-Cj9PuIZx.js → lspLanguageFeatures-C_kQMLR7.js} +1 -1
- package/dist/gallery/assets/{mdx-B0KQLOVD.js → mdx-zpKixrPp.js} +1 -1
- package/dist/gallery/assets/{monaco.contribution-BUitKtul.js → monaco.contribution-9GtnssPq.js} +2 -2
- package/dist/gallery/assets/{python-DaeXews5.js → python-BltZt2Jw.js} +1 -1
- package/dist/gallery/assets/{razor-D7eowHXw.js → razor-BKXZq7zE.js} +1 -1
- package/dist/gallery/assets/{tsMode-DAcic1g_.js → tsMode-CQVoafwv.js} +1 -1
- package/dist/gallery/assets/{typescript-DZzujlOz.js → typescript-DLdg7jpK.js} +1 -1
- package/dist/gallery/assets/{workers-M0x9Vvdl.js → workers-BaJgi0mc.js} +1 -1
- package/dist/gallery/assets/{xml-CaKMy0Ek.js → xml-B7Ykttus.js} +1 -1
- package/dist/gallery/assets/{yaml-Cop9p_yY.js → yaml-uYtSD5pX.js} +1 -1
- package/dist/gallery/index.html +2 -2
- package/dist/{gallery-DIBlUrB6.mjs → gallery-qM8Q_21C.mjs} +30 -5
- package/dist/gallery-qM8Q_21C.mjs.map +1 -0
- package/dist/index.d.mts +111 -70
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +149 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/dist/gallery-DIBlUrB6.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,111 @@ import { c as AnalysisApiResponse, l as PaletteApiResponse, n as MuseaA11yRunner
|
|
|
3
3
|
import { AutogenOptions, AutogenOutput, GeneratedVariant, PropDefinition, generateArtFile, writeArtFile } from "./autogen/index.mjs";
|
|
4
4
|
import { Plugin } from "vite";
|
|
5
5
|
|
|
6
|
+
//#region src/tokens/parser.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Token parsing utilities for Style Dictionary integration.
|
|
9
|
+
*
|
|
10
|
+
* Thin native binding for design token files (JSON) and directories.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Design token value.
|
|
14
|
+
*/
|
|
15
|
+
interface DesignToken {
|
|
16
|
+
value: string | number;
|
|
17
|
+
type?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
attributes?: Record<string, unknown>;
|
|
20
|
+
$tier?: "primitive" | "semantic";
|
|
21
|
+
$reference?: string;
|
|
22
|
+
$resolvedValue?: string | number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Token category (e.g., colors, spacing, typography).
|
|
26
|
+
*/
|
|
27
|
+
interface TokenCategory {
|
|
28
|
+
name: string;
|
|
29
|
+
tokens: Record<string, DesignToken>;
|
|
30
|
+
subcategories?: TokenCategory[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Style Dictionary output format.
|
|
34
|
+
*/
|
|
35
|
+
interface StyleDictionaryOutput {
|
|
36
|
+
categories: TokenCategory[];
|
|
37
|
+
metadata: {
|
|
38
|
+
name: string;
|
|
39
|
+
version?: string;
|
|
40
|
+
generatedAt: string;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Configuration for Style Dictionary integration.
|
|
45
|
+
*/
|
|
46
|
+
interface StyleDictionaryConfig {
|
|
47
|
+
/**
|
|
48
|
+
* Path to tokens JSON file/directory or Tailwind CSS theme file.
|
|
49
|
+
*/
|
|
50
|
+
tokensPath: string;
|
|
51
|
+
/**
|
|
52
|
+
* Output format for documentation.
|
|
53
|
+
* @default 'html'
|
|
54
|
+
*/
|
|
55
|
+
outputFormat?: "html" | "json" | "markdown";
|
|
56
|
+
/**
|
|
57
|
+
* Output directory for generated documentation.
|
|
58
|
+
* @default '.vize/tokens'
|
|
59
|
+
*/
|
|
60
|
+
outputDir?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Custom token transformations.
|
|
63
|
+
*/
|
|
64
|
+
transforms?: TokenTransform[];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Token transformation function.
|
|
68
|
+
*/
|
|
69
|
+
type TokenTransform = (token: DesignToken, path: string[]) => DesignToken;
|
|
70
|
+
/**
|
|
71
|
+
* Parse Style Dictionary tokens file/directory or Tailwind CSS theme variables.
|
|
72
|
+
*/
|
|
73
|
+
declare function parseTokens(tokensPath: string): Promise<TokenCategory[]>;
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/tokens/preview.d.ts
|
|
76
|
+
type MuseaTokenPreviewKind = "color" | "spacing" | "fontSize" | "fontWeight" | "lineHeight" | "shadow" | "radius" | "opacity" | "zIndex" | "generic";
|
|
77
|
+
interface MuseaTokenPreviewRule {
|
|
78
|
+
kind: MuseaTokenPreviewKind;
|
|
79
|
+
type?: string | string[];
|
|
80
|
+
pathIncludes?: string | string[];
|
|
81
|
+
nameIncludes?: string | string[];
|
|
82
|
+
referencePathIncludes?: string | string[];
|
|
83
|
+
}
|
|
84
|
+
interface MuseaTokenPreviewConfig {
|
|
85
|
+
/**
|
|
86
|
+
* User rules are evaluated before Musea's built-in token preview heuristics.
|
|
87
|
+
* Use `kind: "generic"` to intentionally suppress a preview for matching tokens.
|
|
88
|
+
*/
|
|
89
|
+
rules?: MuseaTokenPreviewRule[];
|
|
90
|
+
/** Disable selected preview kinds after custom and built-in rules are evaluated. */
|
|
91
|
+
disabledKinds?: MuseaTokenPreviewKind[];
|
|
92
|
+
}
|
|
93
|
+
interface ResolvedTokenPreview {
|
|
94
|
+
kind: MuseaTokenPreviewKind;
|
|
95
|
+
value: string | number;
|
|
96
|
+
tokenPath: string;
|
|
97
|
+
reference?: {
|
|
98
|
+
path: string;
|
|
99
|
+
token?: DesignToken;
|
|
100
|
+
value?: string | number;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
interface ResolveTokenPreviewInput {
|
|
104
|
+
tokenPath: string;
|
|
105
|
+
token: DesignToken;
|
|
106
|
+
tokenMap?: Record<string, DesignToken>;
|
|
107
|
+
config?: MuseaTokenPreviewConfig;
|
|
108
|
+
}
|
|
109
|
+
declare function resolveTokenPreview(input: ResolveTokenPreviewInput): ResolvedTokenPreview;
|
|
110
|
+
//#endregion
|
|
6
111
|
//#region src/types/plugin.d.ts
|
|
7
112
|
type MuseaVueVersion = 0.11 | 1 | 2 | "2.7" | 3 | "legacy";
|
|
8
113
|
/**
|
|
@@ -86,6 +191,11 @@ interface MuseaOptions {
|
|
|
86
191
|
* @example 'src/tokens.json', 'src/tokens/', or 'src/styles/main.css'
|
|
87
192
|
*/
|
|
88
193
|
tokensPath?: string;
|
|
194
|
+
/**
|
|
195
|
+
* Design token preview rules for the gallery.
|
|
196
|
+
* Custom rules run before Musea's built-in previews.
|
|
197
|
+
*/
|
|
198
|
+
tokenPreviews?: MuseaTokenPreviewConfig;
|
|
89
199
|
/**
|
|
90
200
|
* Project root that should be treated as the outer boundary for path resolution
|
|
91
201
|
* (notably `tokensPath`). When set, sibling directories of the Vite root that
|
|
@@ -137,75 +247,6 @@ interface MuseaOptions {
|
|
|
137
247
|
//#region src/plugin/index.d.ts
|
|
138
248
|
declare function musea(options?: MuseaOptions): Plugin[];
|
|
139
249
|
//#endregion
|
|
140
|
-
//#region src/tokens/parser.d.ts
|
|
141
|
-
/**
|
|
142
|
-
* Token parsing utilities for Style Dictionary integration.
|
|
143
|
-
*
|
|
144
|
-
* Thin native binding for design token files (JSON) and directories.
|
|
145
|
-
*/
|
|
146
|
-
/**
|
|
147
|
-
* Design token value.
|
|
148
|
-
*/
|
|
149
|
-
interface DesignToken {
|
|
150
|
-
value: string | number;
|
|
151
|
-
type?: string;
|
|
152
|
-
description?: string;
|
|
153
|
-
attributes?: Record<string, unknown>;
|
|
154
|
-
$tier?: "primitive" | "semantic";
|
|
155
|
-
$reference?: string;
|
|
156
|
-
$resolvedValue?: string | number;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Token category (e.g., colors, spacing, typography).
|
|
160
|
-
*/
|
|
161
|
-
interface TokenCategory {
|
|
162
|
-
name: string;
|
|
163
|
-
tokens: Record<string, DesignToken>;
|
|
164
|
-
subcategories?: TokenCategory[];
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Style Dictionary output format.
|
|
168
|
-
*/
|
|
169
|
-
interface StyleDictionaryOutput {
|
|
170
|
-
categories: TokenCategory[];
|
|
171
|
-
metadata: {
|
|
172
|
-
name: string;
|
|
173
|
-
version?: string;
|
|
174
|
-
generatedAt: string;
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Configuration for Style Dictionary integration.
|
|
179
|
-
*/
|
|
180
|
-
interface StyleDictionaryConfig {
|
|
181
|
-
/**
|
|
182
|
-
* Path to tokens JSON file/directory or Tailwind CSS theme file.
|
|
183
|
-
*/
|
|
184
|
-
tokensPath: string;
|
|
185
|
-
/**
|
|
186
|
-
* Output format for documentation.
|
|
187
|
-
* @default 'html'
|
|
188
|
-
*/
|
|
189
|
-
outputFormat?: "html" | "json" | "markdown";
|
|
190
|
-
/**
|
|
191
|
-
* Output directory for generated documentation.
|
|
192
|
-
* @default '.vize/tokens'
|
|
193
|
-
*/
|
|
194
|
-
outputDir?: string;
|
|
195
|
-
/**
|
|
196
|
-
* Custom token transformations.
|
|
197
|
-
*/
|
|
198
|
-
transforms?: TokenTransform[];
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Token transformation function.
|
|
202
|
-
*/
|
|
203
|
-
type TokenTransform = (token: DesignToken, path: string[]) => DesignToken;
|
|
204
|
-
/**
|
|
205
|
-
* Parse Style Dictionary tokens file/directory or Tailwind CSS theme variables.
|
|
206
|
-
*/
|
|
207
|
-
declare function parseTokens(tokensPath: string): Promise<TokenCategory[]>;
|
|
208
|
-
//#endregion
|
|
209
250
|
//#region src/tokens/usage.d.ts
|
|
210
251
|
/**
|
|
211
252
|
* Scan art file sources for token value matches in `<style>` blocks.
|
|
@@ -264,5 +305,5 @@ declare function generateTokensMarkdown(categories: TokenCategory[]): string;
|
|
|
264
305
|
*/
|
|
265
306
|
declare function processStyleDictionary(config: StyleDictionaryConfig): Promise<StyleDictionaryOutput>;
|
|
266
307
|
//#endregion
|
|
267
|
-
export { type A11yOptions, type A11yResult, type A11ySummary, type AnalysisApiResponse, type ArtFileInfo, type ArtMetadata, type ArtVariant, type AutogenOptions, type AutogenOutput, type CaptureConfig, type CiConfig, type ComparisonConfig, type CsfOutput, type DesignToken, type GeneratedVariant, MuseaA11yRunner, type MuseaOptions, type MuseaTheme, type MuseaThemeColors, MuseaVrtRunner, type PaletteApiResponse, type PropDefinition, type StyleDictionaryConfig, type StyleDictionaryOutput, type TokenCategory, type TokenUsageMap, type ViewportConfig, type VrtOptions, type VrtResult, type VrtSummary, buildTokenMap, musea as default, musea, generateArtFile, generateTokensHtml, generateTokensMarkdown, generateVrtJsonReport, generateVrtReport, parseTokens, processStyleDictionary, resolveReferences, scanTokenUsage, writeArtFile };
|
|
308
|
+
export { type A11yOptions, type A11yResult, type A11ySummary, type AnalysisApiResponse, type ArtFileInfo, type ArtMetadata, type ArtVariant, type AutogenOptions, type AutogenOutput, type CaptureConfig, type CiConfig, type ComparisonConfig, type CsfOutput, type DesignToken, type GeneratedVariant, MuseaA11yRunner, type MuseaOptions, type MuseaTheme, type MuseaThemeColors, type MuseaTokenPreviewConfig, type MuseaTokenPreviewKind, type MuseaTokenPreviewRule, MuseaVrtRunner, type PaletteApiResponse, type PropDefinition, type ResolvedTokenPreview, type StyleDictionaryConfig, type StyleDictionaryOutput, type TokenCategory, type TokenUsageMap, type ViewportConfig, type VrtOptions, type VrtResult, type VrtSummary, buildTokenMap, musea as default, musea, generateArtFile, generateTokensHtml, generateTokensMarkdown, generateVrtJsonReport, generateVrtReport, parseTokens, processStyleDictionary, resolveReferences, resolveTokenPreview, scanTokenUsage, writeArtFile };
|
|
268
309
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/tokens/parser.ts","../src/tokens/preview.ts","../src/types/plugin.ts","../src/plugin/index.ts","../src/tokens/usage.ts","../src/tokens/resolver.ts","../src/tokens/generator.ts"],"mappings":";;;;;;;;;;;;AAYA;;UAAiB,WAAA;EACf,KAAA;EACA,IAAA;EACA,WAAA;EACA,UAAA,GAAa,MAAA;EACb,KAAA;EACA,UAAA;EACA,cAAA;AAAA;;;;UAMe,aAAA;EACf,I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
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as
|
|
1
|
+
import { _ as validateDevApiRequest, a as generateDevGlobalsScript, c as HttpError, d as decodeUrlComponent, f as parseJsonBody, g as serializeScriptValue, h as resolveUrlPathInside, i as generateGalleryScript, l as collectRequestBody, m as resolveInsideAny, n as generateGalleryModule, o as generateGalleryGlobalsScript, p as resolveInside, r as generateGalleryBody, u as createDevSessionToken } from "./gallery-qM8Q_21C.mjs";
|
|
2
2
|
import { i as MuseaVrtRunner, n as generateVrtJsonReport, r as generateVrtReport } from "./vrt-Cv1PK1EF.mjs";
|
|
3
3
|
import { t as MuseaA11yRunner } from "./a11y-62l8G1tr.mjs";
|
|
4
4
|
import { n as writeArtFile, t as generateArtFile } from "./autogen-B7_TO0n5.mjs";
|
|
@@ -1405,11 +1405,7 @@ function resolveGallerySourceDir() {
|
|
|
1405
1405
|
function toViteFsPath(filePath) {
|
|
1406
1406
|
return encodeURI(`/@fs${filePath.split(path.sep).join("/")}`);
|
|
1407
1407
|
}
|
|
1408
|
-
function
|
|
1409
|
-
const themeScript = themeConfig ? `window.__MUSEA_THEME_CONFIG__=${serializeScriptValue(themeConfig)};` : "";
|
|
1410
|
-
return `window.__MUSEA_BASE_PATH__=${serializeScriptValue(basePath)};window.__MUSEA_SESSION_TOKEN__=${serializeScriptValue(devSessionToken)};${themeScript}`;
|
|
1411
|
-
}
|
|
1412
|
-
async function tryLoadSourceGalleryHtml(devServer, url, basePath, devSessionToken, themeConfig) {
|
|
1408
|
+
async function tryLoadSourceGalleryHtml(devServer, url, basePath, devSessionToken, themeConfig, tokenPreviewConfig) {
|
|
1413
1409
|
const gallerySourceDir = resolveGallerySourceDir();
|
|
1414
1410
|
const indexHtmlPath = path.join(gallerySourceDir, "index.html");
|
|
1415
1411
|
try {
|
|
@@ -1420,12 +1416,12 @@ async function tryLoadSourceGalleryHtml(devServer, url, basePath, devSessionToke
|
|
|
1420
1416
|
const sourceEntryPath = toViteFsPath(path.join(gallerySourceDir, "main.ts"));
|
|
1421
1417
|
let html = await fs.promises.readFile(indexHtmlPath, "utf-8");
|
|
1422
1418
|
html = html.replace("src=\"./main.ts\"", `src="${sourceEntryPath}"`);
|
|
1423
|
-
html = html.replace("</head>", `<script>${generateDevGlobalsScript(basePath, devSessionToken, themeConfig)}<\/script></head>`);
|
|
1419
|
+
html = html.replace("</head>", `<script>${generateDevGlobalsScript(basePath, devSessionToken, themeConfig, tokenPreviewConfig)}<\/script></head>`);
|
|
1424
1420
|
return devServer.transformIndexHtml(url, html);
|
|
1425
1421
|
}
|
|
1426
|
-
async function generateFallbackGalleryHtml(basePath, devSessionToken, themeConfig) {
|
|
1427
|
-
const { generateGalleryHtml } = await import("./gallery-
|
|
1428
|
-
return generateGalleryHtml(basePath, devSessionToken, themeConfig);
|
|
1422
|
+
async function generateFallbackGalleryHtml(basePath, devSessionToken, themeConfig, tokenPreviewConfig) {
|
|
1423
|
+
const { generateGalleryHtml } = await import("./gallery-qM8Q_21C.mjs").then((n) => n.t);
|
|
1424
|
+
return generateGalleryHtml(basePath, devSessionToken, themeConfig, tokenPreviewConfig);
|
|
1429
1425
|
}
|
|
1430
1426
|
async function serveGalleryAsset(galleryDistDir, requestUrl, res) {
|
|
1431
1427
|
try {
|
|
@@ -1458,7 +1454,7 @@ async function serveGalleryAsset(galleryDistDir, requestUrl, res) {
|
|
|
1458
1454
|
* - Art module route
|
|
1459
1455
|
*/
|
|
1460
1456
|
function registerMiddleware(devServer, ctx) {
|
|
1461
|
-
const { basePath, devSessionToken, themeConfig, artFiles } = ctx;
|
|
1457
|
+
const { basePath, devSessionToken, themeConfig, tokenPreviewConfig, artFiles } = ctx;
|
|
1462
1458
|
devServer.middlewares.use(basePath, async (req, res, next) => {
|
|
1463
1459
|
const url = req.url || "/";
|
|
1464
1460
|
if (url === "/" || url === "/index.html" || url.startsWith("/tokens") || url.startsWith("/component/") || url.startsWith("/tests")) {
|
|
@@ -1467,18 +1463,18 @@ function registerMiddleware(devServer, ctx) {
|
|
|
1467
1463
|
try {
|
|
1468
1464
|
await fs.promises.access(indexHtmlPath);
|
|
1469
1465
|
let html = await fs.promises.readFile(indexHtmlPath, "utf-8");
|
|
1470
|
-
html = html.replace("</head>", `<script>${generateDevGlobalsScript(basePath, devSessionToken, themeConfig)}<\/script></head>`);
|
|
1466
|
+
html = html.replace("</head>", `<script>${generateDevGlobalsScript(basePath, devSessionToken, themeConfig, tokenPreviewConfig)}<\/script></head>`);
|
|
1471
1467
|
res.setHeader("Content-Type", "text/html");
|
|
1472
1468
|
res.end(html);
|
|
1473
1469
|
return;
|
|
1474
1470
|
} catch {
|
|
1475
|
-
const sourceHtml = await tryLoadSourceGalleryHtml(devServer, url, basePath, devSessionToken, themeConfig);
|
|
1471
|
+
const sourceHtml = await tryLoadSourceGalleryHtml(devServer, url, basePath, devSessionToken, themeConfig, tokenPreviewConfig);
|
|
1476
1472
|
if (sourceHtml) {
|
|
1477
1473
|
res.setHeader("Content-Type", "text/html");
|
|
1478
1474
|
res.end(sourceHtml);
|
|
1479
1475
|
return;
|
|
1480
1476
|
}
|
|
1481
|
-
const html = await generateFallbackGalleryHtml(basePath, devSessionToken, themeConfig);
|
|
1477
|
+
const html = await generateFallbackGalleryHtml(basePath, devSessionToken, themeConfig, tokenPreviewConfig);
|
|
1482
1478
|
res.setHeader("Content-Type", "text/html");
|
|
1483
1479
|
res.end(html);
|
|
1484
1480
|
return;
|
|
@@ -2274,6 +2270,133 @@ async function processStyleDictionary(config) {
|
|
|
2274
2270
|
};
|
|
2275
2271
|
}
|
|
2276
2272
|
//#endregion
|
|
2273
|
+
//#region src/tokens/preview.ts
|
|
2274
|
+
function resolveTokenPreview(input) {
|
|
2275
|
+
const reference = resolveReference(input.token, input.tokenMap);
|
|
2276
|
+
const value = input.token.$resolvedValue ?? reference?.value ?? input.token.value;
|
|
2277
|
+
const candidates = buildCandidates(input.tokenPath, input.token, reference);
|
|
2278
|
+
const kind = resolveCustomKind(candidates, reference?.path, input.config?.rules) ?? inferPreviewKind(candidates, value);
|
|
2279
|
+
return {
|
|
2280
|
+
kind: new Set(input.config?.disabledKinds ?? []).has(kind) ? "generic" : kind,
|
|
2281
|
+
value,
|
|
2282
|
+
tokenPath: input.tokenPath,
|
|
2283
|
+
reference
|
|
2284
|
+
};
|
|
2285
|
+
}
|
|
2286
|
+
function resolveReference(token, tokenMap) {
|
|
2287
|
+
if (!token.$reference) return void 0;
|
|
2288
|
+
const referencedToken = tokenMap?.[token.$reference];
|
|
2289
|
+
return {
|
|
2290
|
+
path: token.$reference,
|
|
2291
|
+
token: referencedToken,
|
|
2292
|
+
value: referencedToken ? referencedToken.$resolvedValue ?? referencedToken.value : void 0
|
|
2293
|
+
};
|
|
2294
|
+
}
|
|
2295
|
+
function buildCandidates(tokenPath, token, reference) {
|
|
2296
|
+
const candidates = [{
|
|
2297
|
+
tokenPath,
|
|
2298
|
+
name: pathName(tokenPath),
|
|
2299
|
+
token
|
|
2300
|
+
}];
|
|
2301
|
+
if (reference?.token) candidates.push({
|
|
2302
|
+
tokenPath: reference.path,
|
|
2303
|
+
name: pathName(reference.path),
|
|
2304
|
+
token: reference.token
|
|
2305
|
+
});
|
|
2306
|
+
return candidates;
|
|
2307
|
+
}
|
|
2308
|
+
function resolveCustomKind(candidates, referencePath, rules) {
|
|
2309
|
+
for (const rule of rules ?? []) if (matchesRule(rule, candidates, referencePath)) return rule.kind;
|
|
2310
|
+
}
|
|
2311
|
+
function matchesRule(rule, candidates, referencePath) {
|
|
2312
|
+
const checks = [];
|
|
2313
|
+
if (rule.type !== void 0) checks.push(candidates.some((candidate) => typeMatches(candidate, rule.type)));
|
|
2314
|
+
if (rule.pathIncludes !== void 0) checks.push(candidates.some((candidate) => includesAny(candidate.tokenPath, rule.pathIncludes)));
|
|
2315
|
+
if (rule.nameIncludes !== void 0) checks.push(candidates.some((candidate) => includesAny(candidate.name, rule.nameIncludes)));
|
|
2316
|
+
if (rule.referencePathIncludes !== void 0) checks.push(referencePath !== void 0 && includesAny(referencePath, rule.referencePathIncludes));
|
|
2317
|
+
return checks.length > 0 && checks.every(Boolean);
|
|
2318
|
+
}
|
|
2319
|
+
function inferPreviewKind(candidates, value) {
|
|
2320
|
+
if (hasType(candidates, ["color"]) || isColorValue(value)) return "color";
|
|
2321
|
+
if (hasType(candidates, ["shadow", "box-shadow"]) || hasSignal(candidates, ["shadow", "box-shadow"])) return "shadow";
|
|
2322
|
+
if (hasType(candidates, [
|
|
2323
|
+
"z-index",
|
|
2324
|
+
"zindex",
|
|
2325
|
+
"zIndex"
|
|
2326
|
+
]) || hasSignal(candidates, [
|
|
2327
|
+
"z-index",
|
|
2328
|
+
"zindex",
|
|
2329
|
+
"stacking-order"
|
|
2330
|
+
])) return "zIndex";
|
|
2331
|
+
if (hasType(candidates, ["opacity"]) || hasSignal(candidates, ["opacity", "alpha"])) return "opacity";
|
|
2332
|
+
if (hasType(candidates, [
|
|
2333
|
+
"border-radius",
|
|
2334
|
+
"borderradius",
|
|
2335
|
+
"radius"
|
|
2336
|
+
]) || hasSignal(candidates, [
|
|
2337
|
+
"border-radius",
|
|
2338
|
+
"borderradius",
|
|
2339
|
+
"radius",
|
|
2340
|
+
"round",
|
|
2341
|
+
"rounded"
|
|
2342
|
+
])) return "radius";
|
|
2343
|
+
if (hasType(candidates, ["spacing", "space"]) || hasSignal(candidates, [
|
|
2344
|
+
"spacing",
|
|
2345
|
+
"spasing",
|
|
2346
|
+
"space",
|
|
2347
|
+
"gap",
|
|
2348
|
+
"padding",
|
|
2349
|
+
"margin",
|
|
2350
|
+
"inset"
|
|
2351
|
+
])) return "spacing";
|
|
2352
|
+
if (hasSignal(candidates, [
|
|
2353
|
+
"font-size",
|
|
2354
|
+
"fontsize",
|
|
2355
|
+
"text-size"
|
|
2356
|
+
])) return "fontSize";
|
|
2357
|
+
if (hasType(candidates, ["fontweight", "font-weight"]) || hasSignal(candidates, [
|
|
2358
|
+
"font-weight",
|
|
2359
|
+
"fontweight",
|
|
2360
|
+
"weight"
|
|
2361
|
+
])) return "fontWeight";
|
|
2362
|
+
if (hasType(candidates, ["lineheight", "line-height"]) || hasSignal(candidates, ["line-height", "lineheight"])) return "lineHeight";
|
|
2363
|
+
return "generic";
|
|
2364
|
+
}
|
|
2365
|
+
function hasType(candidates, terms) {
|
|
2366
|
+
return candidates.some((candidate) => typeMatches(candidate, terms));
|
|
2367
|
+
}
|
|
2368
|
+
function hasSignal(candidates, terms) {
|
|
2369
|
+
return candidates.some((candidate) => includesAny(candidate.tokenPath, terms) || includesAny(candidate.name, terms) || candidate.token.type !== void 0 && includesAny(candidate.token.type, terms));
|
|
2370
|
+
}
|
|
2371
|
+
function typeMatches(candidate, expected) {
|
|
2372
|
+
if (!candidate.token.type) return false;
|
|
2373
|
+
return toArray(expected).some((term) => normalize(candidate.token.type) === normalize(term));
|
|
2374
|
+
}
|
|
2375
|
+
function includesAny(value, expected) {
|
|
2376
|
+
const normalizedValue = normalize(value);
|
|
2377
|
+
const compactValue = compact(normalizedValue);
|
|
2378
|
+
return toArray(expected).some((term) => {
|
|
2379
|
+
const normalizedTerm = normalize(term);
|
|
2380
|
+
return normalizedValue.includes(normalizedTerm) || compactValue.includes(compact(normalizedTerm));
|
|
2381
|
+
});
|
|
2382
|
+
}
|
|
2383
|
+
function isColorValue(value) {
|
|
2384
|
+
if (typeof value !== "string") return false;
|
|
2385
|
+
return /^(#|rgb\(|rgba\(|hsl\(|hsla\(|oklch\(|oklab\(|lab\(|lch\(|color\()/i.test(value.trim());
|
|
2386
|
+
}
|
|
2387
|
+
function pathName(tokenPath) {
|
|
2388
|
+
return tokenPath.split(".").at(-1) ?? tokenPath;
|
|
2389
|
+
}
|
|
2390
|
+
function normalize(value) {
|
|
2391
|
+
return value.trim().toLowerCase().replace(/[_\s]+/g, "-");
|
|
2392
|
+
}
|
|
2393
|
+
function compact(value) {
|
|
2394
|
+
return value.replace(/[-.]/g, "");
|
|
2395
|
+
}
|
|
2396
|
+
function toArray(value) {
|
|
2397
|
+
return Array.isArray(value) ? value : [value];
|
|
2398
|
+
}
|
|
2399
|
+
//#endregion
|
|
2277
2400
|
//#region src/api-tokens.ts
|
|
2278
2401
|
function resolveTokensPath(ctx) {
|
|
2279
2402
|
const allowedRoots = [ctx.config.root, ...ctx.scanRoots];
|
|
@@ -3423,8 +3546,12 @@ function generateStaticPreviewHtml(art, variantName, previewId, basePath, runtim
|
|
|
3423
3546
|
</html>`;
|
|
3424
3547
|
}
|
|
3425
3548
|
function injectStaticGlobals(html, ctx, payload) {
|
|
3426
|
-
const
|
|
3427
|
-
|
|
3549
|
+
const script = `<script>${generateGalleryGlobalsScript({
|
|
3550
|
+
basePath: ctx.basePath,
|
|
3551
|
+
staticPreviews: payload.previews,
|
|
3552
|
+
themeConfig: ctx.themeConfig,
|
|
3553
|
+
tokenPreviewConfig: ctx.tokenPreviewConfig
|
|
3554
|
+
})}<\/script>`;
|
|
3428
3555
|
return html.includes("</head>") ? html.replace("</head>", `${script}</head>`) : `${script}${html}`;
|
|
3429
3556
|
}
|
|
3430
3557
|
function rewriteGalleryBase(html, basePath) {
|
|
@@ -3631,6 +3758,7 @@ function musea(options = {}) {
|
|
|
3631
3758
|
const storybookOutDir = options.storybookOutDir ?? ".storybook/stories";
|
|
3632
3759
|
let inlineArt = options.inlineArt ?? false;
|
|
3633
3760
|
const tokensPath = options.tokensPath;
|
|
3761
|
+
let tokenPreviewConfig = options.tokenPreviews;
|
|
3634
3762
|
const projectRootOption = options.projectRoot;
|
|
3635
3763
|
const themeConfig = buildThemeConfig(options.theme);
|
|
3636
3764
|
const previewCss = options.previewCss ?? [];
|
|
@@ -3684,6 +3812,7 @@ function musea(options = {}) {
|
|
|
3684
3812
|
if (!options.basePath && mc.basePath) basePath = mc.basePath;
|
|
3685
3813
|
if (options.storybookCompat === void 0 && mc.storybookCompat !== void 0) storybookCompat = mc.storybookCompat;
|
|
3686
3814
|
if (options.inlineArt === void 0 && mc.inlineArt !== void 0) inlineArt = mc.inlineArt;
|
|
3815
|
+
if (options.tokenPreviews === void 0 && mc.tokenPreviews !== void 0) tokenPreviewConfig = mc.tokenPreviews;
|
|
3687
3816
|
}
|
|
3688
3817
|
vueVersion = resolveStaticPreviewVueVersion(vueVersion, resolvedConfig.plugins);
|
|
3689
3818
|
virtualState.basePath = basePath;
|
|
@@ -3699,6 +3828,7 @@ function musea(options = {}) {
|
|
|
3699
3828
|
basePath,
|
|
3700
3829
|
devSessionToken,
|
|
3701
3830
|
themeConfig,
|
|
3831
|
+
tokenPreviewConfig,
|
|
3702
3832
|
artFiles,
|
|
3703
3833
|
scanRoots,
|
|
3704
3834
|
resolvedPreviewCss,
|
|
@@ -3797,7 +3927,8 @@ function musea(options = {}) {
|
|
|
3797
3927
|
resolvedPreviewCss,
|
|
3798
3928
|
resolvedPreviewSetup,
|
|
3799
3929
|
devSessionToken,
|
|
3800
|
-
themeConfig
|
|
3930
|
+
themeConfig,
|
|
3931
|
+
tokenPreviewConfig
|
|
3801
3932
|
});
|
|
3802
3933
|
},
|
|
3803
3934
|
async transform(code, id) {
|
|
@@ -3826,6 +3957,6 @@ function resolveProjectRoot(projectRoot, viteRoot) {
|
|
|
3826
3957
|
//#region src/index.ts
|
|
3827
3958
|
var src_default = musea;
|
|
3828
3959
|
//#endregion
|
|
3829
|
-
export { MuseaA11yRunner, MuseaVrtRunner, buildTokenMap, src_default as default, generateArtFile, generateTokensHtml, generateTokensMarkdown, generateVrtJsonReport, generateVrtReport, musea, parseTokens, processStyleDictionary, resolveReferences, scanTokenUsage, writeArtFile };
|
|
3960
|
+
export { MuseaA11yRunner, MuseaVrtRunner, buildTokenMap, src_default as default, generateArtFile, generateTokensHtml, generateTokensMarkdown, generateVrtJsonReport, generateVrtReport, musea, parseTokens, processStyleDictionary, resolveReferences, resolveTokenPreview, scanTokenUsage, writeArtFile };
|
|
3830
3961
|
|
|
3831
3962
|
//# sourceMappingURL=index.mjs.map
|