@fastkit/plugboy-vanilla-extract-plugin 3.2.0 → 4.0.0-next.1
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/css.d.mts +75 -0
- package/dist/css.mjs +89 -119
- package/dist/css.mjs.map +1 -1
- package/dist/plugboy-vanilla-extract-plugin.d.mts +29 -0
- package/dist/plugboy-vanilla-extract-plugin.mjs +222 -86
- package/dist/plugboy-vanilla-extract-plugin.mjs.map +1 -1
- package/package.json +11 -11
- package/dist/css.d.ts +0 -73
- package/dist/plugboy-vanilla-extract-plugin.d.ts +0 -29
package/dist/css.d.mts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { GlobalStyleRule, StyleRule, createGlobalTheme } from "@vanilla-extract/css";
|
|
2
|
+
|
|
3
|
+
//#region src/css/layer.d.ts
|
|
4
|
+
type CustomStyleRules = Record<string, any>;
|
|
5
|
+
type _LayerStyleRules = NonNullable<StyleRule['@layer']>[string];
|
|
6
|
+
type LayerStyleRules<CustomRules extends CustomStyleRules | null = null> = CustomRules extends null ? _LayerStyleRules : _LayerStyleRules & CustomRules;
|
|
7
|
+
type ClassNames = string | ClassNames[];
|
|
8
|
+
type ComplexLayerStyleRule<CustomRules extends CustomStyleRules | null = null> = LayerStyleRules<CustomRules> | (LayerStyleRules<CustomRules> | ClassNames)[];
|
|
9
|
+
type _LayerGlobalStyleRules = NonNullable<GlobalStyleRule['@layer']>[string];
|
|
10
|
+
type LayerGlobalStyleRules<CustomRules extends CustomStyleRules | null = null> = CustomRules extends null ? _LayerGlobalStyleRules : _LayerGlobalStyleRules & CustomRules;
|
|
11
|
+
type AnyStyleRule<CustomRules extends CustomStyleRules | null = null> = LayerStyleRules<CustomRules> | LayerGlobalStyleRules<CustomRules>;
|
|
12
|
+
type LayerStyleHooks<CustomRules extends CustomStyleRules | null = null> = {
|
|
13
|
+
style?: (rule: ComplexLayerStyleRule<CustomRules>, debugId?: string) => void;
|
|
14
|
+
global?: (selector: string, rule: LayerGlobalStyleRules<CustomRules>) => void;
|
|
15
|
+
anyStyle?: (style: AnyStyleRule<CustomRules>) => void;
|
|
16
|
+
};
|
|
17
|
+
interface LayerStyle<CustomRules extends CustomStyleRules | null = null> {
|
|
18
|
+
layerName: string;
|
|
19
|
+
parentLayerName: string | null;
|
|
20
|
+
/**
|
|
21
|
+
* @see {@link style}
|
|
22
|
+
*/
|
|
23
|
+
(rule: ComplexLayerStyleRule<CustomRules>, debugId?: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* @see {@link style}
|
|
26
|
+
*/
|
|
27
|
+
style(rule: ComplexLayerStyleRule<CustomRules>, debugId?: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* @see {@link globalStyle}
|
|
30
|
+
*/
|
|
31
|
+
global(selector: string, rule: LayerGlobalStyleRules<CustomRules>): void;
|
|
32
|
+
/**
|
|
33
|
+
* @see {@link _createGlobalTheme}
|
|
34
|
+
*/
|
|
35
|
+
globalTheme: typeof createGlobalTheme;
|
|
36
|
+
defineNestedLayer(globalNameOrNestedOptions?: string | DefineLayerOptions<CustomRules>): LayerStyle<CustomRules>;
|
|
37
|
+
/**
|
|
38
|
+
* Add global CSS variable with layer
|
|
39
|
+
*
|
|
40
|
+
* @remarks The vanilla-extract API is buggy when handling layered css variables.
|
|
41
|
+
*
|
|
42
|
+
* @param selector - selector
|
|
43
|
+
* @param vars - variables
|
|
44
|
+
*/
|
|
45
|
+
pushGlobalVars(selector: string, vars: Record<string, string>): void;
|
|
46
|
+
/**
|
|
47
|
+
* Output variables accumulated by `pushGlobalVars`.
|
|
48
|
+
*
|
|
49
|
+
* @remarks The vanilla-extract API is buggy when handling layered css variables.
|
|
50
|
+
*/
|
|
51
|
+
dumpGlobalVars(): void;
|
|
52
|
+
hooks: LayerStyleHooks<CustomRules>;
|
|
53
|
+
}
|
|
54
|
+
interface DefineLayerParentOptions {
|
|
55
|
+
parent?: string;
|
|
56
|
+
}
|
|
57
|
+
interface DefineLayerBaseOptions<CustomRules extends CustomStyleRules | null = null> {
|
|
58
|
+
hooks?: LayerStyleHooks<CustomRules>;
|
|
59
|
+
}
|
|
60
|
+
interface DefineLayerScopedOptions<CustomRules extends CustomStyleRules | null = null> extends DefineLayerBaseOptions<CustomRules> {
|
|
61
|
+
/** Debug ID */
|
|
62
|
+
debugId?: string;
|
|
63
|
+
globalName?: never;
|
|
64
|
+
}
|
|
65
|
+
interface DefineLayerGlobalOptions<CustomRules extends CustomStyleRules | null = null> extends DefineLayerBaseOptions<CustomRules> {
|
|
66
|
+
debugId?: never;
|
|
67
|
+
/** Parent layer name */
|
|
68
|
+
globalName: string;
|
|
69
|
+
}
|
|
70
|
+
type DefineLayerOptions<CustomRules extends CustomStyleRules | null = null> = DefineLayerScopedOptions<CustomRules> | DefineLayerGlobalOptions<CustomRules>;
|
|
71
|
+
type DefineNestableLayerOptions<CustomRules extends CustomStyleRules | null = null> = DefineLayerOptions<CustomRules> & DefineLayerParentOptions;
|
|
72
|
+
declare function defineLayerStyle<CustomRules extends CustomStyleRules | null = null>(globalNameOrOptions?: string | DefineNestableLayerOptions<CustomRules>): LayerStyle<CustomRules>;
|
|
73
|
+
//#endregion
|
|
74
|
+
export { DefineLayerBaseOptions, DefineLayerGlobalOptions, DefineLayerOptions, DefineLayerParentOptions, DefineLayerScopedOptions, DefineNestableLayerOptions, LayerStyle, defineLayerStyle };
|
|
75
|
+
//# sourceMappingURL=css.d.mts.map
|
package/dist/css.mjs
CHANGED
|
@@ -1,138 +1,108 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createThemeContract, globalLayer, globalStyle, layer, style } from "@vanilla-extract/css";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
//#region src/css/utils.ts
|
|
4
4
|
function get(obj, path) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
return result;
|
|
5
|
+
let result = obj;
|
|
6
|
+
for (const key of path) {
|
|
7
|
+
if (!(key in result)) throw new Error(`Path ${path.join(" -> ")} does not exist in object`);
|
|
8
|
+
result = result[key];
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
13
11
|
}
|
|
14
12
|
function walkObject(obj, fn, path = []) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
console.warn(
|
|
25
|
-
`Skipping invalid key "${currentPath.join(
|
|
26
|
-
"."
|
|
27
|
-
)}". Should be a string, number, null or object. Received: "${Array.isArray(value) ? "Array" : typeof value}"`
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return clone;
|
|
13
|
+
const clone = obj.constructor();
|
|
14
|
+
for (const key in obj) {
|
|
15
|
+
const value = obj[key];
|
|
16
|
+
const currentPath = [...path, key];
|
|
17
|
+
if (typeof value === "string" || typeof value === "number" || value == null) clone[key] = fn(value, currentPath);
|
|
18
|
+
else if (typeof value === "object" && !Array.isArray(value)) clone[key] = walkObject(value, fn, currentPath);
|
|
19
|
+
else console.warn(`Skipping invalid key "${currentPath.join(".")}". Should be a string, number, null or object. Received: "${Array.isArray(value) ? "Array" : typeof value}"`);
|
|
20
|
+
}
|
|
21
|
+
return clone;
|
|
32
22
|
}
|
|
33
23
|
function assignVars(varContract, tokens) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
const varSetters = {};
|
|
25
|
+
walkObject(tokens, (value, path) => {
|
|
26
|
+
varSetters[get(varContract, path)] = String(value);
|
|
27
|
+
});
|
|
28
|
+
return varSetters;
|
|
39
29
|
}
|
|
40
30
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
vars: assignVars(themeVars, tokens)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
if (shouldCreateVars) {
|
|
54
|
-
return themeVars;
|
|
55
|
-
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/css/theme.ts
|
|
33
|
+
function createGlobalTheme$1(layerName, selector, arg2, arg3) {
|
|
34
|
+
const shouldCreateVars = Boolean(!arg3);
|
|
35
|
+
const themeVars = shouldCreateVars ? createThemeContract(arg2) : arg2;
|
|
36
|
+
const tokens = shouldCreateVars ? arg2 : arg3;
|
|
37
|
+
globalStyle(selector, { "@layer": { [layerName]: { vars: assignVars(themeVars, tokens) } } });
|
|
38
|
+
if (shouldCreateVars) return themeVars;
|
|
56
39
|
}
|
|
57
40
|
|
|
58
|
-
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/css/layer.ts
|
|
59
43
|
function isGlobalOptions(options) {
|
|
60
|
-
|
|
44
|
+
return "globalName" in options;
|
|
61
45
|
}
|
|
62
46
|
function normalizeToObject(source) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
47
|
+
if (!source) return {};
|
|
48
|
+
if (typeof source === "string") return { globalName: source };
|
|
49
|
+
return source;
|
|
66
50
|
}
|
|
67
51
|
function defineLayerStyle(globalNameOrOptions) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
};
|
|
121
|
-
layerStyle.defineNestedLayer = function defineNestedLayer(globalNameOrNestedOptions) {
|
|
122
|
-
const _options = normalizeToObject(globalNameOrNestedOptions);
|
|
123
|
-
const nestedHooks = _options.hooks;
|
|
124
|
-
return defineLayerStyle({
|
|
125
|
-
..._options,
|
|
126
|
-
hooks: {
|
|
127
|
-
...hooks,
|
|
128
|
-
...nestedHooks
|
|
129
|
-
},
|
|
130
|
-
parent: layerName
|
|
131
|
-
});
|
|
132
|
-
};
|
|
133
|
-
return layerStyle;
|
|
52
|
+
const options = normalizeToObject(globalNameOrOptions);
|
|
53
|
+
const { parent, hooks = {} } = options;
|
|
54
|
+
const layerName = isGlobalOptions(options) ? globalLayer({ parent }, options.globalName) : layer({ parent }, options.debugId);
|
|
55
|
+
const layerStyle = function layerStyle(rule, debugId) {
|
|
56
|
+
const rules = Array.isArray(rule) ? rule : [rule];
|
|
57
|
+
const layerAppliedRules = rules.map((_rule) => {
|
|
58
|
+
if (typeof _rule === "string" || Array.isArray(_rule)) return _rule;
|
|
59
|
+
return { "@layer": { [layerName]: _rule } };
|
|
60
|
+
});
|
|
61
|
+
if (hooks.anyStyle) for (const _rule of rules) {
|
|
62
|
+
if (typeof _rule === "string" || Array.isArray(_rule)) continue;
|
|
63
|
+
hooks.anyStyle(_rule);
|
|
64
|
+
}
|
|
65
|
+
hooks.style && hooks.style(rule, debugId);
|
|
66
|
+
return style(layerAppliedRules, debugId);
|
|
67
|
+
};
|
|
68
|
+
layerStyle.layerName = layerName;
|
|
69
|
+
layerStyle.parentLayerName = parent || null;
|
|
70
|
+
layerStyle.style = layerStyle;
|
|
71
|
+
layerStyle.hooks = hooks;
|
|
72
|
+
layerStyle.global = function layerGlobalStyle(selector, rule) {
|
|
73
|
+
hooks.anyStyle && hooks.anyStyle(rule);
|
|
74
|
+
hooks.global && hooks.global(selector, rule);
|
|
75
|
+
return globalStyle(selector, { "@layer": { [layerName]: rule } });
|
|
76
|
+
};
|
|
77
|
+
layerStyle.globalTheme = (...args) => createGlobalTheme$1(layerName, ...args);
|
|
78
|
+
let _varQueues = [];
|
|
79
|
+
layerStyle.pushGlobalVars = function pushGlobalVars(selector, vars) {
|
|
80
|
+
let queue = _varQueues.find((q) => q[0] === selector);
|
|
81
|
+
if (!queue) {
|
|
82
|
+
queue = [selector, {}];
|
|
83
|
+
_varQueues.push(queue);
|
|
84
|
+
}
|
|
85
|
+
Object.assign(queue[1], vars);
|
|
86
|
+
};
|
|
87
|
+
layerStyle.dumpGlobalVars = function dumpGlobalVars() {
|
|
88
|
+
for (const [selector, vars] of _varQueues) layerStyle.global(selector, { vars });
|
|
89
|
+
_varQueues = [];
|
|
90
|
+
};
|
|
91
|
+
layerStyle.defineNestedLayer = function defineNestedLayer(globalNameOrNestedOptions) {
|
|
92
|
+
const _options = normalizeToObject(globalNameOrNestedOptions);
|
|
93
|
+
const nestedHooks = _options.hooks;
|
|
94
|
+
return defineLayerStyle({
|
|
95
|
+
..._options,
|
|
96
|
+
hooks: {
|
|
97
|
+
...hooks,
|
|
98
|
+
...nestedHooks
|
|
99
|
+
},
|
|
100
|
+
parent: layerName
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
return layerStyle;
|
|
134
104
|
}
|
|
135
105
|
|
|
106
|
+
//#endregion
|
|
136
107
|
export { defineLayerStyle };
|
|
137
|
-
//# sourceMappingURL=css.mjs.map
|
|
138
108
|
//# sourceMappingURL=css.mjs.map
|
package/dist/css.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/css/utils.ts","../src/css/theme.ts","../src/css/layer.ts"],"names":["layerStyle","globalStyle"],"mappings":";;;;;AASO,SAAS,GAAA,C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W,kBAAkB,yBAAyB,CAAA;AAC5D,IAAA,MAAM,cAAc,QAAA,CAAS,KAAA;AAE7B,IAAA,OAAO,gBAAA,CAAiB;AAAA,MACtB,GAAG,QAAA;AAAA,MACH,KAAA,EAAO;AAAA,QACL,GAAG,KAAA;AAAA,QACH,GAAG;AAAA,OACL;AAAA,MACA,MAAA,EAAQ;AAAA,KACT,CAAA;AAAA,EACH,CAAA;AAEA,EAAA,OAAO,UAAA;AACT","file":"css.mjs","sourcesContent":["/* eslint-disable no-console */\nimport { Contract, MapLeafNodes, CSSVarFunction } from './types';\n\ntype Primitive = string | number | null | undefined;\n\ntype Walkable = {\n [Key in string | number]: Primitive | Walkable;\n};\n\nexport function get(obj: any, path: Array<string>) {\n let result = obj;\n\n for (const key of path) {\n if (!(key in result)) {\n throw new Error(`Path ${path.join(' -> ')} does not exist in object`);\n }\n result = result[key];\n }\n\n return result;\n}\nexport function walkObject<T extends Walkable, MapTo>(\n obj: T,\n fn: (value: Primitive, path: Array<string>) => MapTo,\n path: Array<string> = [],\n): MapLeafNodes<T, MapTo> {\n const clone = obj.constructor();\n\n for (const key in obj) {\n const value = obj[key];\n const currentPath = [...path, key];\n\n if (\n typeof value === 'string' ||\n typeof value === 'number' ||\n value == null\n ) {\n clone[key] = fn(value as Primitive, currentPath);\n } else if (typeof value === 'object' && !Array.isArray(value)) {\n clone[key] = walkObject(value as Walkable, fn, currentPath);\n } else {\n console.warn(\n `Skipping invalid key \"${currentPath.join(\n '.',\n )}\". Should be a string, number, null or object. Received: \"${\n Array.isArray(value) ? 'Array' : typeof value\n }\"`,\n );\n }\n }\n\n return clone;\n}\n\nexport function assignVars<VarContract extends Contract>(\n varContract: VarContract,\n tokens: MapLeafNodes<VarContract, string>,\n): Record<CSSVarFunction, string> {\n const varSetters: { [cssVarName: string]: string } = {};\n // const { valid, diffString } = validateContract(varContract, tokens);\n\n // if (!valid) {\n // throw new Error(`Tokens don't match contract.\\n${diffString}`);\n // }\n\n walkObject(tokens, (value, path) => {\n varSetters[get(varContract, path)] = String(value);\n });\n\n return varSetters;\n}\n","import { createThemeContract, globalStyle } from '@vanilla-extract/css';\nimport { Tokens, ThemeVars, Contract, MapLeafNodes } from './types';\nimport { assignVars } from './utils';\n\nexport function createGlobalTheme<ThemeTokens extends Tokens>(\n layerName: string,\n selector: string,\n tokens: ThemeTokens,\n): ThemeVars<ThemeTokens>;\nexport function createGlobalTheme<ThemeContract extends Contract>(\n layerName: string,\n selector: string,\n themeContract: ThemeContract,\n tokens: MapLeafNodes<ThemeContract, string>,\n): void;\nexport function createGlobalTheme(\n layerName: string,\n selector: string,\n arg2: any,\n arg3?: any,\n): any {\n const shouldCreateVars = Boolean(!arg3);\n\n const themeVars = shouldCreateVars\n ? createThemeContract(arg2)\n : (arg2 as ThemeVars<any>);\n\n const tokens = shouldCreateVars ? arg2 : arg3;\n\n globalStyle(selector, {\n '@layer': {\n [layerName]: {\n vars: assignVars(themeVars, tokens),\n },\n },\n });\n\n // appendCss(\n // {\n // type: 'global',\n // selector: selector,\n // rule: { vars: assignVars(themeVars, tokens) },\n // },\n // getFileScope(),\n // );\n\n if (shouldCreateVars) {\n return themeVars;\n }\n}\n","import {\n style,\n layer,\n globalLayer,\n StyleRule,\n globalStyle,\n GlobalStyleRule,\n createGlobalTheme as _createGlobalTheme,\n} from '@vanilla-extract/css';\nimport { createGlobalTheme } from './theme';\n\ntype CustomStyleRules = Record<string, any>;\n\ntype _LayerStyleRules = NonNullable<StyleRule['@layer']>[string];\n\ntype LayerStyleRules<CustomRules extends CustomStyleRules | null = null> =\n CustomRules extends null ? _LayerStyleRules : _LayerStyleRules & CustomRules;\n\ntype ClassNames = string | ClassNames[];\n\ntype ComplexLayerStyleRule<CustomRules extends CustomStyleRules | null = null> =\n LayerStyleRules<CustomRules> | (LayerStyleRules<CustomRules> | ClassNames)[];\n\ntype _LayerGlobalStyleRules = NonNullable<GlobalStyleRule['@layer']>[string];\n\ntype LayerGlobalStyleRules<CustomRules extends CustomStyleRules | null = null> =\n CustomRules extends null\n ? _LayerGlobalStyleRules\n : _LayerGlobalStyleRules & CustomRules;\n\ntype AnyStyleRule<CustomRules extends CustomStyleRules | null = null> =\n | LayerStyleRules<CustomRules>\n | LayerGlobalStyleRules<CustomRules>;\n\ntype LayerStyleHooks<CustomRules extends CustomStyleRules | null = null> = {\n style?: (rule: ComplexLayerStyleRule<CustomRules>, debugId?: string) => void;\n global?: (selector: string, rule: LayerGlobalStyleRules<CustomRules>) => void;\n anyStyle?: (style: AnyStyleRule<CustomRules>) => void;\n};\n\nexport interface LayerStyle<\n CustomRules extends CustomStyleRules | null = null,\n> {\n layerName: string;\n parentLayerName: string | null;\n /**\n * @see {@link style}\n */\n (rule: ComplexLayerStyleRule<CustomRules>, debugId?: string): string;\n\n /**\n * @see {@link style}\n */\n style(rule: ComplexLayerStyleRule<CustomRules>, debugId?: string): string;\n\n /**\n * @see {@link globalStyle}\n */\n global(selector: string, rule: LayerGlobalStyleRules<CustomRules>): void;\n\n /**\n * @see {@link _createGlobalTheme}\n */\n globalTheme: typeof _createGlobalTheme;\n\n defineNestedLayer(\n globalNameOrNestedOptions?: string | DefineLayerOptions<CustomRules>,\n ): LayerStyle<CustomRules>;\n\n /**\n * Add global CSS variable with layer\n *\n * @remarks The vanilla-extract API is buggy when handling layered css variables.\n *\n * @param selector - selector\n * @param vars - variables\n */\n pushGlobalVars(selector: string, vars: Record<string, string>): void;\n\n /**\n * Output variables accumulated by `pushGlobalVars`.\n *\n * @remarks The vanilla-extract API is buggy when handling layered css variables.\n */\n dumpGlobalVars(): void;\n hooks: LayerStyleHooks<CustomRules>;\n}\n\nexport interface DefineLayerParentOptions {\n parent?: string;\n}\n\nexport interface DefineLayerBaseOptions<\n CustomRules extends CustomStyleRules | null = null,\n> {\n hooks?: LayerStyleHooks<CustomRules>;\n}\n\nexport interface DefineLayerScopedOptions<\n CustomRules extends CustomStyleRules | null = null,\n> extends DefineLayerBaseOptions<CustomRules> {\n /** Debug ID */\n debugId?: string;\n globalName?: never;\n}\n\nexport interface DefineLayerGlobalOptions<\n CustomRules extends CustomStyleRules | null = null,\n> extends DefineLayerBaseOptions<CustomRules> {\n debugId?: never;\n /** Parent layer name */\n globalName: string;\n}\n\nexport type DefineLayerOptions<\n CustomRules extends CustomStyleRules | null = null,\n> =\n | DefineLayerScopedOptions<CustomRules>\n | DefineLayerGlobalOptions<CustomRules>;\n\nexport type DefineNestableLayerOptions<\n CustomRules extends CustomStyleRules | null = null,\n> = DefineLayerOptions<CustomRules> & DefineLayerParentOptions;\n\nfunction isGlobalOptions(\n options: DefineLayerOptions<any>,\n): options is DefineLayerGlobalOptions {\n return 'globalName' in options;\n}\n\nfunction normalizeToObject<T extends DefineLayerOptions<any>>(\n source?: string | T,\n): T {\n if (!source) return {} as T;\n if (typeof source === 'string') return { globalName: source } as unknown as T;\n return source;\n}\n\nexport function defineLayerStyle<\n CustomRules extends CustomStyleRules | null = null,\n>(\n globalNameOrOptions?: string | DefineNestableLayerOptions<CustomRules>,\n): LayerStyle<CustomRules> {\n const options = normalizeToObject(globalNameOrOptions);\n const { parent, hooks = {} } = options;\n\n const layerName = isGlobalOptions(options)\n ? globalLayer({ parent }, options.globalName)\n : layer({ parent }, options.debugId);\n\n const layerStyle = function layerStyle(rule, debugId) {\n const rules = Array.isArray(rule) ? rule : [rule];\n const layerAppliedRules = rules.map((_rule) => {\n if (typeof _rule === 'string' || Array.isArray(_rule)) return _rule;\n return {\n '@layer': {\n [layerName]: _rule,\n },\n };\n });\n if (hooks.anyStyle) {\n for (const _rule of rules) {\n if (typeof _rule === 'string' || Array.isArray(_rule)) continue;\n hooks.anyStyle(_rule);\n }\n }\n hooks.style && hooks.style(rule, debugId);\n return style(layerAppliedRules, debugId);\n } as LayerStyle<CustomRules>;\n\n layerStyle.layerName = layerName;\n layerStyle.parentLayerName = parent || null;\n layerStyle.style = layerStyle;\n layerStyle.hooks = hooks;\n\n layerStyle.global = function layerGlobalStyle(\n selector: string,\n rule: LayerGlobalStyleRules<CustomRules>,\n ) {\n hooks.anyStyle && hooks.anyStyle(rule);\n hooks.global && hooks.global(selector, rule);\n\n return globalStyle(selector, {\n '@layer': {\n [layerName]: rule,\n },\n });\n };\n\n layerStyle.globalTheme = (...args: any) =>\n (createGlobalTheme as any)(layerName, ...args);\n\n let _varQueues: [string, Record<string, string>][] = [];\n\n layerStyle.pushGlobalVars = function pushGlobalVars(\n selector: string,\n vars: Record<string, string>,\n ) {\n let queue = _varQueues.find((q) => q[0] === selector);\n if (!queue) {\n queue = [selector, {}];\n _varQueues.push(queue);\n }\n Object.assign(queue[1], vars);\n };\n\n layerStyle.dumpGlobalVars = function dumpGlobalVars() {\n for (const [selector, vars] of _varQueues) {\n layerStyle.global(selector, {\n vars,\n } as any);\n }\n _varQueues = [];\n };\n\n layerStyle.defineNestedLayer = function defineNestedLayer(\n globalNameOrNestedOptions?: string | DefineLayerOptions<CustomRules>,\n ) {\n const _options = normalizeToObject(globalNameOrNestedOptions);\n const nestedHooks = _options.hooks;\n\n return defineLayerStyle({\n ..._options,\n hooks: {\n ...hooks,\n ...nestedHooks,\n },\n parent: layerName,\n });\n };\n\n return layerStyle;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"css.mjs","names":["createGlobalTheme","createGlobalTheme"],"sources":["../src/css/utils.ts","../src/css/theme.ts","../src/css/layer.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport { Contract, MapLeafNodes, CSSVarFunction } from './types';\n\ntype Primitive = string | number | null | undefined;\n\ntype Walkable = {\n [Key in string | number]: Primitive | Walkable;\n};\n\nexport function get(obj: any, path: Array<string>) {\n let result = obj;\n\n for (const key of path) {\n if (!(key in result)) {\n throw new Error(`Path ${path.join(' -> ')} does not exist in object`);\n }\n result = result[key];\n }\n\n return result;\n}\nexport function walkObject<T extends Walkable, MapTo>(\n obj: T,\n fn: (value: Primitive, path: Array<string>) => MapTo,\n path: Array<string> = [],\n): MapLeafNodes<T, MapTo> {\n const clone = obj.constructor();\n\n for (const key in obj) {\n const value = obj[key];\n const currentPath = [...path, key];\n\n if (\n typeof value === 'string' ||\n typeof value === 'number' ||\n value == null\n ) {\n clone[key] = fn(value as Primitive, currentPath);\n } else if (typeof value === 'object' && !Array.isArray(value)) {\n clone[key] = walkObject(value as Walkable, fn, currentPath);\n } else {\n console.warn(\n `Skipping invalid key \"${currentPath.join(\n '.',\n )}\". Should be a string, number, null or object. Received: \"${\n Array.isArray(value) ? 'Array' : typeof value\n }\"`,\n );\n }\n }\n\n return clone;\n}\n\nexport function assignVars<VarContract extends Contract>(\n varContract: VarContract,\n tokens: MapLeafNodes<VarContract, string>,\n): Record<CSSVarFunction, string> {\n const varSetters: { [cssVarName: string]: string } = {};\n // const { valid, diffString } = validateContract(varContract, tokens);\n\n // if (!valid) {\n // throw new Error(`Tokens don't match contract.\\n${diffString}`);\n // }\n\n walkObject(tokens, (value, path) => {\n varSetters[get(varContract, path)] = String(value);\n });\n\n return varSetters;\n}\n","import { createThemeContract, globalStyle } from '@vanilla-extract/css';\nimport { Tokens, ThemeVars, Contract, MapLeafNodes } from './types';\nimport { assignVars } from './utils';\n\nexport function createGlobalTheme<ThemeTokens extends Tokens>(\n layerName: string,\n selector: string,\n tokens: ThemeTokens,\n): ThemeVars<ThemeTokens>;\nexport function createGlobalTheme<ThemeContract extends Contract>(\n layerName: string,\n selector: string,\n themeContract: ThemeContract,\n tokens: MapLeafNodes<ThemeContract, string>,\n): void;\nexport function createGlobalTheme(\n layerName: string,\n selector: string,\n arg2: any,\n arg3?: any,\n): any {\n const shouldCreateVars = Boolean(!arg3);\n\n const themeVars = shouldCreateVars\n ? createThemeContract(arg2)\n : (arg2 as ThemeVars<any>);\n\n const tokens = shouldCreateVars ? arg2 : arg3;\n\n globalStyle(selector, {\n '@layer': {\n [layerName]: {\n vars: assignVars(themeVars, tokens),\n },\n },\n });\n\n // appendCss(\n // {\n // type: 'global',\n // selector: selector,\n // rule: { vars: assignVars(themeVars, tokens) },\n // },\n // getFileScope(),\n // );\n\n if (shouldCreateVars) {\n return themeVars;\n }\n}\n","import {\n style,\n layer,\n globalLayer,\n StyleRule,\n globalStyle,\n GlobalStyleRule,\n createGlobalTheme as _createGlobalTheme,\n} from '@vanilla-extract/css';\nimport { createGlobalTheme } from './theme';\n\ntype CustomStyleRules = Record<string, any>;\n\ntype _LayerStyleRules = NonNullable<StyleRule['@layer']>[string];\n\ntype LayerStyleRules<CustomRules extends CustomStyleRules | null = null> =\n CustomRules extends null ? _LayerStyleRules : _LayerStyleRules & CustomRules;\n\ntype ClassNames = string | ClassNames[];\n\ntype ComplexLayerStyleRule<CustomRules extends CustomStyleRules | null = null> =\n LayerStyleRules<CustomRules> | (LayerStyleRules<CustomRules> | ClassNames)[];\n\ntype _LayerGlobalStyleRules = NonNullable<GlobalStyleRule['@layer']>[string];\n\ntype LayerGlobalStyleRules<CustomRules extends CustomStyleRules | null = null> =\n CustomRules extends null\n ? _LayerGlobalStyleRules\n : _LayerGlobalStyleRules & CustomRules;\n\ntype AnyStyleRule<CustomRules extends CustomStyleRules | null = null> =\n | LayerStyleRules<CustomRules>\n | LayerGlobalStyleRules<CustomRules>;\n\ntype LayerStyleHooks<CustomRules extends CustomStyleRules | null = null> = {\n style?: (rule: ComplexLayerStyleRule<CustomRules>, debugId?: string) => void;\n global?: (selector: string, rule: LayerGlobalStyleRules<CustomRules>) => void;\n anyStyle?: (style: AnyStyleRule<CustomRules>) => void;\n};\n\nexport interface LayerStyle<\n CustomRules extends CustomStyleRules | null = null,\n> {\n layerName: string;\n parentLayerName: string | null;\n /**\n * @see {@link style}\n */\n (rule: ComplexLayerStyleRule<CustomRules>, debugId?: string): string;\n\n /**\n * @see {@link style}\n */\n style(rule: ComplexLayerStyleRule<CustomRules>, debugId?: string): string;\n\n /**\n * @see {@link globalStyle}\n */\n global(selector: string, rule: LayerGlobalStyleRules<CustomRules>): void;\n\n /**\n * @see {@link _createGlobalTheme}\n */\n globalTheme: typeof _createGlobalTheme;\n\n defineNestedLayer(\n globalNameOrNestedOptions?: string | DefineLayerOptions<CustomRules>,\n ): LayerStyle<CustomRules>;\n\n /**\n * Add global CSS variable with layer\n *\n * @remarks The vanilla-extract API is buggy when handling layered css variables.\n *\n * @param selector - selector\n * @param vars - variables\n */\n pushGlobalVars(selector: string, vars: Record<string, string>): void;\n\n /**\n * Output variables accumulated by `pushGlobalVars`.\n *\n * @remarks The vanilla-extract API is buggy when handling layered css variables.\n */\n dumpGlobalVars(): void;\n hooks: LayerStyleHooks<CustomRules>;\n}\n\nexport interface DefineLayerParentOptions {\n parent?: string;\n}\n\nexport interface DefineLayerBaseOptions<\n CustomRules extends CustomStyleRules | null = null,\n> {\n hooks?: LayerStyleHooks<CustomRules>;\n}\n\nexport interface DefineLayerScopedOptions<\n CustomRules extends CustomStyleRules | null = null,\n> extends DefineLayerBaseOptions<CustomRules> {\n /** Debug ID */\n debugId?: string;\n globalName?: never;\n}\n\nexport interface DefineLayerGlobalOptions<\n CustomRules extends CustomStyleRules | null = null,\n> extends DefineLayerBaseOptions<CustomRules> {\n debugId?: never;\n /** Parent layer name */\n globalName: string;\n}\n\nexport type DefineLayerOptions<\n CustomRules extends CustomStyleRules | null = null,\n> =\n | DefineLayerScopedOptions<CustomRules>\n | DefineLayerGlobalOptions<CustomRules>;\n\nexport type DefineNestableLayerOptions<\n CustomRules extends CustomStyleRules | null = null,\n> = DefineLayerOptions<CustomRules> & DefineLayerParentOptions;\n\nfunction isGlobalOptions(\n options: DefineLayerOptions<any>,\n): options is DefineLayerGlobalOptions {\n return 'globalName' in options;\n}\n\nfunction normalizeToObject<T extends DefineLayerOptions<any>>(\n source?: string | T,\n): T {\n if (!source) return {} as T;\n if (typeof source === 'string') return { globalName: source } as unknown as T;\n return source;\n}\n\nexport function defineLayerStyle<\n CustomRules extends CustomStyleRules | null = null,\n>(\n globalNameOrOptions?: string | DefineNestableLayerOptions<CustomRules>,\n): LayerStyle<CustomRules> {\n const options = normalizeToObject(globalNameOrOptions);\n const { parent, hooks = {} } = options;\n\n const layerName = isGlobalOptions(options)\n ? globalLayer({ parent }, options.globalName)\n : layer({ parent }, options.debugId);\n\n const layerStyle = function layerStyle(rule, debugId) {\n const rules = Array.isArray(rule) ? rule : [rule];\n const layerAppliedRules = rules.map((_rule) => {\n if (typeof _rule === 'string' || Array.isArray(_rule)) return _rule;\n return {\n '@layer': {\n [layerName]: _rule,\n },\n };\n });\n if (hooks.anyStyle) {\n for (const _rule of rules) {\n if (typeof _rule === 'string' || Array.isArray(_rule)) continue;\n hooks.anyStyle(_rule);\n }\n }\n hooks.style && hooks.style(rule, debugId);\n return style(layerAppliedRules, debugId);\n } as LayerStyle<CustomRules>;\n\n layerStyle.layerName = layerName;\n layerStyle.parentLayerName = parent || null;\n layerStyle.style = layerStyle;\n layerStyle.hooks = hooks;\n\n layerStyle.global = function layerGlobalStyle(\n selector: string,\n rule: LayerGlobalStyleRules<CustomRules>,\n ) {\n hooks.anyStyle && hooks.anyStyle(rule);\n hooks.global && hooks.global(selector, rule);\n\n return globalStyle(selector, {\n '@layer': {\n [layerName]: rule,\n },\n });\n };\n\n layerStyle.globalTheme = (...args: any) =>\n (createGlobalTheme as any)(layerName, ...args);\n\n let _varQueues: [string, Record<string, string>][] = [];\n\n layerStyle.pushGlobalVars = function pushGlobalVars(\n selector: string,\n vars: Record<string, string>,\n ) {\n let queue = _varQueues.find((q) => q[0] === selector);\n if (!queue) {\n queue = [selector, {}];\n _varQueues.push(queue);\n }\n Object.assign(queue[1], vars);\n };\n\n layerStyle.dumpGlobalVars = function dumpGlobalVars() {\n for (const [selector, vars] of _varQueues) {\n layerStyle.global(selector, {\n vars,\n } as any);\n }\n _varQueues = [];\n };\n\n layerStyle.defineNestedLayer = function defineNestedLayer(\n globalNameOrNestedOptions?: string | DefineLayerOptions<CustomRules>,\n ) {\n const _options = normalizeToObject(globalNameOrNestedOptions);\n const nestedHooks = _options.hooks;\n\n return defineLayerStyle({\n ..._options,\n hooks: {\n ...hooks,\n ...nestedHooks,\n },\n parent: layerName,\n });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AAO,SAAS;AACrD,MAAI,CAAC,OAAO;AACV,WAAQ,CAAC,UAAU,EAAE,CAAC;AACtB,cAAW,KAAK,MAAM;;AAExB,SAAO,OAAO,MAAM,IAAI,KAAK;;AAG/B,YAAW,iBAAiB,SAAS,iBAAiB;AACpD,OAAK,MAAM,CAAC,UAAU,SAAS,WAC7B,YAAW,OAAO,UAAU,EAC1B,MACD,CAAQ;AAEX,eAAa,EAAE;;AAGjB,YAAW,oBAAoB,SAAS,kBACtC,2BACA;EACA,MAAM,WAAW,kBAAkB,0BAA0B;EAC7D,MAAM,cAAc,SAAS;AAE7B,SAAO,iBAAiB;GACtB,GAAG;GACH,OAAO;IACL,GAAG;IACH,GAAG;IACJ;GACD,QAAQ;GACT,CAAC;;AAGJ,QAAO"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Plugin } from "@fastkit/plugboy";
|
|
2
|
+
import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
|
|
3
|
+
import { vanillaExtractPlugin as vanillaExtractPlugin$1 } from "@vanilla-extract/rollup-plugin";
|
|
4
|
+
import { Plugin as Plugin$1 } from "vite";
|
|
5
|
+
|
|
6
|
+
//#region src/types.d.ts
|
|
7
|
+
type VanillaExtractPluginOptions = Omit<NonNullable<Parameters<typeof vanillaExtractPlugin$1>[0]>, 'extract'>;
|
|
8
|
+
interface PluginOptions extends Pick<VanillaExtractPluginOptions, 'identifiers' | 'esbuildOptions'> {}
|
|
9
|
+
declare const PLUGIN_NAME = "plugboy-vanilla-extract";
|
|
10
|
+
interface VanillaExtractPlugin extends Plugin {
|
|
11
|
+
name: typeof PLUGIN_NAME;
|
|
12
|
+
_options: PluginOptions;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/plugin.d.ts
|
|
16
|
+
declare module '@fastkit/plugboy' {
|
|
17
|
+
interface WorkspaceMeta {
|
|
18
|
+
hasVanillaExtract: boolean;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
declare function createVanillaExtractPlugin(options?: PluginOptions): Promise<VanillaExtractPlugin>;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/vite.d.ts
|
|
24
|
+
type VanillaExtractVitePluginOptions = NonNullable<Parameters<typeof vanillaExtractPlugin>[0]>;
|
|
25
|
+
interface ViteVanillaExtractPluginOptions extends VanillaExtractVitePluginOptions {}
|
|
26
|
+
declare function ViteVanillaExtractPlugin(options?: ViteVanillaExtractPluginOptions): Promise<Plugin$1[]>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { PLUGIN_NAME, PluginOptions, VanillaExtractPlugin, ViteVanillaExtractPlugin, ViteVanillaExtractPluginOptions, createVanillaExtractPlugin };
|
|
29
|
+
//# sourceMappingURL=plugboy-vanilla-extract-plugin.d.mts.map
|
|
@@ -1,99 +1,235 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { definePlugin, findFile, findProjectPlugin } from "@fastkit/plugboy";
|
|
3
|
+
import { compile, cssFileFilter, getSourceFromVirtualCssFile, processVanillaFile, transform, virtualCssFileFilter } from "@vanilla-extract/integration";
|
|
4
|
+
import { posix } from "node:path";
|
|
5
|
+
import MagicString, { Bundle } from "magic-string";
|
|
6
|
+
import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
+
//#region rolldown:runtime
|
|
9
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const result = [...EXTERNAL_DEFAULTS];
|
|
13
|
-
for (const chunk of chunks) {
|
|
14
|
-
chunk && result.push(...chunk);
|
|
15
|
-
}
|
|
16
|
-
return Array.from(new Set(result));
|
|
17
|
-
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/types.ts
|
|
13
|
+
const PLUGIN_NAME = "plugboy-vanilla-extract";
|
|
18
14
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/_origin/lib.ts
|
|
17
|
+
/** Generate a CSS bundle from Rollup context */
|
|
18
|
+
function generateCssBundle(plugin) {
|
|
19
|
+
const cssBundle = new Bundle();
|
|
20
|
+
const extractedCssIds = /* @__PURE__ */ new Set();
|
|
21
|
+
const cssFiles = {};
|
|
22
|
+
for (const id of plugin.getModuleIds()) if (cssFileFilter.test(id)) cssFiles[id] = buildImportChain(id, plugin);
|
|
23
|
+
for (const id of sortModules(cssFiles)) {
|
|
24
|
+
const { importedIds } = plugin.getModuleInfo(id) ?? {};
|
|
25
|
+
for (const importedId of importedIds ?? []) {
|
|
26
|
+
const resolution = plugin.getModuleInfo(importedId);
|
|
27
|
+
if (resolution?.meta.css && !extractedCssIds.has(resolution.id)) {
|
|
28
|
+
extractedCssIds.add(resolution.id);
|
|
29
|
+
cssBundle.addSource({
|
|
30
|
+
filename: resolution.id,
|
|
31
|
+
content: new MagicString(resolution.meta.css)
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
bundle: cssBundle,
|
|
38
|
+
extractedCssIds
|
|
39
|
+
};
|
|
29
40
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
41
|
+
/** Trace a file back through its importers, building an ordered list */
|
|
42
|
+
function buildImportChain(id, plugin) {
|
|
43
|
+
let mod = plugin.getModuleInfo(id);
|
|
44
|
+
if (!mod) return [];
|
|
45
|
+
/** [id, order] */
|
|
46
|
+
const chain = [[id, -1]];
|
|
47
|
+
while (!mod.isEntry) {
|
|
48
|
+
const { id: currentId, importers } = mod;
|
|
49
|
+
const lastImporterId = importers.at(-1);
|
|
50
|
+
if (!lastImporterId) break;
|
|
51
|
+
if (chain.some(([id]) => id === lastImporterId)) {
|
|
52
|
+
plugin.warn(`Circular import detected. Can’t determine ideal import order of module.\n${chain.reverse().join("\n → ")}`);
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
mod = plugin.getModuleInfo(lastImporterId);
|
|
56
|
+
if (!mod) break;
|
|
57
|
+
chain.push([lastImporterId, mod.importedIds.indexOf(currentId)]);
|
|
58
|
+
}
|
|
59
|
+
return chain.reverse();
|
|
60
|
+
}
|
|
61
|
+
/** Compare import chains to determine a flat ordering for modules */
|
|
62
|
+
function sortModules(modules) {
|
|
63
|
+
const sortedModules = Object.entries(modules);
|
|
64
|
+
sortedModules.sort(([_idA, chainA], [_idB, chainB]) => {
|
|
65
|
+
const shorterChain = Math.min(chainA.length, chainB.length);
|
|
66
|
+
for (let i = 0; i < shorterChain; i++) {
|
|
67
|
+
const [moduleA, orderA] = chainA[i];
|
|
68
|
+
const [moduleB, orderB] = chainB[i];
|
|
69
|
+
if (moduleA === moduleB && orderA === orderB) continue;
|
|
70
|
+
if (orderA !== orderB) return orderA - orderB;
|
|
71
|
+
}
|
|
72
|
+
return 0;
|
|
73
|
+
});
|
|
74
|
+
return sortedModules.map(([id]) => id);
|
|
75
|
+
}
|
|
76
|
+
const SIDE_EFFECT_IMPORT_RE = /^\s*import\s+['"]([^'"]+)['"]\s*;?\s*/gm;
|
|
77
|
+
/** Remove specific side effect imports from JS */
|
|
78
|
+
function stripSideEffectImportsMatching(code, sources) {
|
|
79
|
+
const matches = code.matchAll(SIDE_EFFECT_IMPORT_RE);
|
|
80
|
+
if (!matches) return code;
|
|
81
|
+
let output = code;
|
|
82
|
+
for (const match of matches) {
|
|
83
|
+
if (!match[1] || !sources.includes(match[1])) continue;
|
|
84
|
+
output = output.replace(match[0], "");
|
|
85
|
+
}
|
|
86
|
+
return output;
|
|
35
87
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
88
|
+
async function tryGetPackageName(cwd) {
|
|
89
|
+
try {
|
|
90
|
+
return __require(posix.join(cwd, "package.json"))?.name || null;
|
|
91
|
+
} catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
39
94
|
}
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/_origin/index.ts
|
|
98
|
+
const { relative, normalize, dirname } = posix;
|
|
99
|
+
function vanillaExtractPlugin$1({ identifiers, cwd = process.cwd(), esbuildOptions, extract = false, unstable_injectFilescopes = false } = {}) {
|
|
100
|
+
if (extract === true) extract = {};
|
|
101
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
102
|
+
let extractedCssIds = /* @__PURE__ */ new Set();
|
|
103
|
+
return {
|
|
104
|
+
name: "vanilla-extract",
|
|
105
|
+
buildStart() {
|
|
106
|
+
extractedCssIds = /* @__PURE__ */ new Set();
|
|
107
|
+
},
|
|
108
|
+
async transform(code, id) {
|
|
109
|
+
if (!cssFileFilter.test(id)) return null;
|
|
110
|
+
const identOption = identifiers ?? (isProduction ? "short" : "debug");
|
|
111
|
+
const [filePath] = id.split("?");
|
|
112
|
+
if (unstable_injectFilescopes) return {
|
|
113
|
+
code: await transform({
|
|
114
|
+
source: code,
|
|
115
|
+
filePath: id,
|
|
116
|
+
rootPath: cwd,
|
|
117
|
+
packageName: await tryGetPackageName(cwd) ?? "",
|
|
118
|
+
identOption
|
|
119
|
+
}),
|
|
120
|
+
map: { mappings: "" }
|
|
121
|
+
};
|
|
122
|
+
const { source, watchFiles } = await compile({
|
|
123
|
+
filePath,
|
|
124
|
+
cwd,
|
|
125
|
+
esbuildOptions,
|
|
126
|
+
identOption
|
|
127
|
+
});
|
|
128
|
+
for (const file of watchFiles) this.addWatchFile(file);
|
|
129
|
+
return {
|
|
130
|
+
code: await processVanillaFile({
|
|
131
|
+
source,
|
|
132
|
+
filePath,
|
|
133
|
+
identOption
|
|
134
|
+
}),
|
|
135
|
+
map: { mappings: "" }
|
|
136
|
+
};
|
|
137
|
+
},
|
|
138
|
+
async resolveId(id) {
|
|
139
|
+
if (!virtualCssFileFilter.test(id)) return null;
|
|
140
|
+
const { fileName, source } = await getSourceFromVirtualCssFile(id);
|
|
141
|
+
return {
|
|
142
|
+
id: fileName,
|
|
143
|
+
external: true,
|
|
144
|
+
meta: { css: source }
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
renderChunk(code, chunkInfo) {
|
|
148
|
+
const chunkPath = dirname(chunkInfo.fileName);
|
|
149
|
+
return {
|
|
150
|
+
code: chunkInfo.imports.reduce((codeResult, importPath) => {
|
|
151
|
+
const moduleInfo = this.getModuleInfo(importPath);
|
|
152
|
+
if (!moduleInfo?.meta.css || extract) return codeResult;
|
|
153
|
+
const assetId = this.emitFile({
|
|
154
|
+
type: "asset",
|
|
155
|
+
name: moduleInfo.id,
|
|
156
|
+
source: moduleInfo.meta.css
|
|
157
|
+
});
|
|
158
|
+
const relativeAssetPath = `./${normalize(relative(chunkPath, this.getFileName(assetId)))}`;
|
|
159
|
+
return codeResult.replace(importPath, relativeAssetPath);
|
|
160
|
+
}, code),
|
|
161
|
+
map: null
|
|
162
|
+
};
|
|
163
|
+
},
|
|
164
|
+
async generateBundle(_options, bundle) {
|
|
165
|
+
if (!extract) return;
|
|
166
|
+
for (const chunk of Object.values(bundle)) {
|
|
167
|
+
if (chunk.type !== "chunk" || !chunk.isEntry) continue;
|
|
168
|
+
const jsFileName = chunk.fileName;
|
|
169
|
+
if (/\.d\.(ts|mts|cts)$/.test(jsFileName)) continue;
|
|
170
|
+
const extractName = extract.name || "[name].css";
|
|
171
|
+
const name = jsFileName.replace(/\.(js|mjs)$/, "");
|
|
172
|
+
const cssFileName = typeof extractName === "function" ? extractName(chunk) : extractName.replace("[name]", name);
|
|
173
|
+
const { bundle: cssBundle, extractedCssIds: extractedIds } = generateCssBundle(this);
|
|
174
|
+
extractedCssIds = extractedIds;
|
|
175
|
+
this.emitFile({
|
|
176
|
+
type: "asset",
|
|
177
|
+
fileName: cssFileName,
|
|
178
|
+
source: cssBundle.toString()
|
|
179
|
+
});
|
|
180
|
+
if (extract.sourcemap) {
|
|
181
|
+
const sourcemapName = `${cssFileName}.map`;
|
|
182
|
+
this.emitFile({
|
|
183
|
+
type: "asset",
|
|
184
|
+
name: sourcemapName,
|
|
185
|
+
originalFileName: sourcemapName,
|
|
186
|
+
source: cssBundle.generateMap({
|
|
187
|
+
file: name,
|
|
188
|
+
includeContent: true
|
|
189
|
+
}).toString()
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
await Promise.all(Object.entries(bundle).map(async ([id, chunk]) => {
|
|
194
|
+
if (chunk.type === "chunk" && (id.endsWith(".js") || id.endsWith(".mjs")) && chunk.imports.some((specifier) => extractedCssIds.has(specifier))) chunk.code = await stripSideEffectImportsMatching(chunk.code, [...extractedCssIds]);
|
|
195
|
+
}));
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/plugin.ts
|
|
40
202
|
async function createVanillaExtractPlugin(options = {}) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const code = await fs.readFile(filePath, "utf-8");
|
|
60
|
-
const cleaner = ext === "mjs" ? cleanJS : void 0;
|
|
61
|
-
if (!cleaner) return;
|
|
62
|
-
const replaced = cleaner(code);
|
|
63
|
-
if (code === replaced) return;
|
|
64
|
-
await fs.writeFile(filePath, replaced.trimStart(), "utf-8");
|
|
65
|
-
})
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
esbuildPlugins: [
|
|
70
|
-
(workspace) => {
|
|
71
|
-
if (!workspace.meta.hasVanillaExtract) return;
|
|
72
|
-
return ESBuildVanillaExtract(options);
|
|
73
|
-
}
|
|
74
|
-
]
|
|
75
|
-
});
|
|
203
|
+
return definePlugin({
|
|
204
|
+
name: PLUGIN_NAME,
|
|
205
|
+
_options: options,
|
|
206
|
+
hooks: { async setupWorkspace(ctx) {
|
|
207
|
+
ctx.mergeExternals(/@vanilla-extract/);
|
|
208
|
+
ctx.meta.hasVanillaExtract = !!await findFile(ctx.dirs.src.value, /\.css\.ts$/);
|
|
209
|
+
if (ctx.meta.hasVanillaExtract) {
|
|
210
|
+
const originalPlugin = vanillaExtractPlugin$1({
|
|
211
|
+
...options,
|
|
212
|
+
extract: true
|
|
213
|
+
});
|
|
214
|
+
ctx.config.dts ??= {};
|
|
215
|
+
ctx.config.dts.inline = true;
|
|
216
|
+
ctx.dts.inline = true;
|
|
217
|
+
ctx.plugins.push(originalPlugin);
|
|
218
|
+
}
|
|
219
|
+
} }
|
|
220
|
+
});
|
|
76
221
|
}
|
|
222
|
+
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/vite.ts
|
|
77
225
|
async function ViteVanillaExtractPlugin(options = {}) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return vanillaExtractPlugin({
|
|
84
|
-
identifiers: baseIdentifiers,
|
|
85
|
-
...options
|
|
86
|
-
// esbuildOptions: {
|
|
87
|
-
// ...baseEsbuildOptions,
|
|
88
|
-
// ...esbuildOptions,
|
|
89
|
-
// external: mergeExternal(
|
|
90
|
-
// baseEsbuildOptions.external,
|
|
91
|
-
// esbuildOptions.external,
|
|
92
|
-
// ),
|
|
93
|
-
// },
|
|
94
|
-
});
|
|
226
|
+
const { identifiers: baseIdentifiers } = (await findProjectPlugin(PLUGIN_NAME))?._options || {};
|
|
227
|
+
return vanillaExtractPlugin({
|
|
228
|
+
identifiers: baseIdentifiers,
|
|
229
|
+
...options
|
|
230
|
+
});
|
|
95
231
|
}
|
|
96
232
|
|
|
233
|
+
//#endregion
|
|
97
234
|
export { PLUGIN_NAME, ViteVanillaExtractPlugin, createVanillaExtractPlugin };
|
|
98
|
-
//# sourceMappingURL=plugboy-vanilla-extract-plugin.mjs.map
|
|
99
235
|
//# sourceMappingURL=plugboy-vanilla-extract-plugin.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts","../src/utils.ts","../src/esbuild.ts","../src/plugin.ts","../src/vite.ts"],"names":["vanillaExtractPlugin"],"mappings":";;;;;;;;AAaO,IAAM,WAAA,GAAc;;;ACb3B,IAAM,iBAAA,GAAoB,CAAC,QAAQ,CAAA;AAE5B,SAAS,iBAAiB,MAAA,EAA4C;AAC3E,EAAA,MAAM,MAAA,GAAmB,CAAC,GAAG,iBAAiB,CAAA;AAC9C,EAAA,KAAA,MAAW,SAAS,MAAA,EAAQ;AAC1B,IAAA,KAAA,IAAS,MAAA,CAAO,IAAA,CAAK,GAAG,KAAK,CAAA;AAAA,EAC/B;AACA,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAI,GAAA,CAAI,MAAM,CAAC,CAAA;AACnC;;;ACHO,SAAS,qBAAA,CACd,OAAA,GAAyB,EAAC,EACX;AACf,EAAA,MAAM,EAAE,cAAA,GAAiB,EAAC,EAAE,GAAI,OAAA;AAEhC,EAAA,OAAOA,sBAAA,CAAqB;AAAA,IAC1B,GAAG,OAAA;AAAA,IACH,cAAA,EAAgB;AAAA,MACd,GAAG,cAAA;AAAA,MACH,QAAA,EAAU,aAAA,CAAc,cAAA,CAAe,QAAQ;AAAA;AACjD,GACD,CAAA;AACH;;;ACNA,IAAM,UAAA,GAAa,cAAA;AAEnB,SAAS,WAAW,QAAA,EAAkB;AACpC,EAAA,OAAO,QAAA,CAAS,KAAA,CAAM,UAAU,CAAA,GAAI,CAAC,CAAA;AACvC;AAEA,IAAM,oBAAA,GAAuB,yCAAA;AAE7B,SAAS,QAAQ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,EAAU,QAAA,CAAS,SAAA,IAAa,OAAO,CAAA;AAAA,UAC5D,CAAC;AAAA,SACH;AAAA,MACF;AAAA,KACF;AAAA,IACA,cAAA,EAAgB;AAAA,MACd,CAAC,SAAA,KAAc;AACb,QAAA,IAAI,CAAC,SAAA,CAAU,IAAA,CAAK,iBAAA,EAAmB;AACvC,QAAA,OAAO,sBAAsB,OAAO,CAAA;AAAA,MACtC;AAAA;AACF,GACD,CAAA;AACH;AClDA,eAAsB,wBAAA,CACpB,OAAA,GAA2C,EAAC,EACrB;AACvB,EAAA,MAAM,MAAA,GAAS,MAAM,iBAAA,CAAwC,WAAW,CAAA;AACxE,EAAA,MAAM;AAAA,IACJ,WAAA,EAAa;AAAA;AAAA,GAEf,GAAI,MAAA,EAAQ,OAAA,IAAW,EAAC;AAIxB,EAAA,OAAOA,oBAAAA,CAAqB;AAAA,IAC1B,WAAA,EAAa,eAAA;AAAA,IACb,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GASJ,CAAA;AACH","file":"plugboy-vanilla-extract-plugin.mjs","sourcesContent":["import { Plugin } from '@fastkit/plugboy';\nimport type { vanillaExtractPlugin as esbuildPlugin } from '@vanilla-extract/esbuild-plugin';\n\ntype VanillaExtractPluginOptions = NonNullable<\n Parameters<typeof esbuildPlugin>[0]\n>;\n\nexport interface VanillaExtractEsbuildOptions\n extends NonNullable<VanillaExtractPluginOptions['esbuildOptions']> {}\n\nexport interface PluginOptions\n extends Pick<VanillaExtractPluginOptions, 'identifiers' | 'esbuildOptions'> {}\n\nexport const PLUGIN_NAME = 'plugboy-vanilla-extract';\n\nexport interface VanillaExtractPlugin extends Plugin {\n name: typeof PLUGIN_NAME;\n options: PluginOptions;\n}\n","const EXTERNAL_DEFAULTS = ['node:*'];\n\nexport function mergeExternal(...chunks: (string[] | undefined)[]): string[] {\n const result: string[] = [...EXTERNAL_DEFAULTS];\n for (const chunk of chunks) {\n chunk && result.push(...chunk);\n }\n return Array.from(new Set(result));\n}\n","import { ESBuildPlugin } from '@fastkit/plugboy';\nimport { vanillaExtractPlugin } from '@vanilla-extract/esbuild-plugin';\nimport { PluginOptions } from './types';\nimport { mergeExternal } from './utils';\n\nexport function ESBuildVanillaExtract(\n options: PluginOptions = {},\n): ESBuildPlugin {\n const { esbuildOptions = {} } = options;\n\n return vanillaExtractPlugin({\n ...options,\n esbuildOptions: {\n ...esbuildOptions,\n external: mergeExternal(esbuildOptions.external),\n },\n }) as any;\n}\n","import { definePlugin, findFile } from '@fastkit/plugboy';\nimport fs from 'node:fs/promises';\nimport { ESBuildVanillaExtract } from './esbuild';\nimport { VanillaExtractPlugin, PluginOptions, PLUGIN_NAME } from './types';\n\ndeclare module '@fastkit/plugboy' {\n export interface WorkspaceMeta {\n hasVanillaExtract: boolean;\n }\n}\n\nconst extMatchRe = /\\.(mjs|css)$/;\n\nfunction extractExt(filePath: string) {\n return filePath.match(extMatchRe)?.[1] as 'mjs' | 'css' | undefined;\n}\n\nconst emptyVanillaImportRe = /(^|\\n)import '@vanilla-extract\\/css';?/g;\n\nfunction cleanJS(code: string) {\n return code.replace(emptyVanillaImportRe, '');\n}\n\nexport async function createVanillaExtractPlugin(options: PluginOptions = {}) {\n return definePlugin<VanillaExtractPlugin>({\n name: PLUGIN_NAME,\n options,\n hooks: {\n async setupWorkspace(ctx) {\n const { external = [] } = ctx.config;\n\n ctx.config.external = [...external, /@vanilla-extract/];\n\n ctx.meta.hasVanillaExtract = await !!findFile(\n ctx.dirs.src.value,\n /\\.css\\.ts$/,\n );\n },\n async onSuccess(builder, files) {\n if (!builder.workspace.meta.hasVanillaExtract) return;\n await Promise.all(\n files.map(async ({ path: filePath }) => {\n const ext = extractExt(filePath);\n if (!ext) return;\n\n const code = await fs.readFile(filePath, 'utf-8');\n const cleaner = ext === 'mjs' ? cleanJS : undefined;\n if (!cleaner) return;\n const replaced = cleaner(code);\n if (code === replaced) return;\n\n await fs.writeFile(filePath, replaced.trimStart(), 'utf-8');\n }),\n );\n },\n },\n esbuildPlugins: [\n (workspace) => {\n if (!workspace.meta.hasVanillaExtract) return;\n return ESBuildVanillaExtract(options);\n },\n ],\n });\n}\n","import { findProjectPlugin } from '@fastkit/plugboy';\nimport { Plugin as VitePlugin } from 'vite';\nimport { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';\nimport { PLUGIN_NAME, VanillaExtractPlugin } from './types';\n// import { mergeExternal } from './utils';\n\ntype VanillaExtractVitePluginOptions = NonNullable<\n Parameters<typeof vanillaExtractPlugin>[0]\n>;\n\nexport interface ViteVanillaExtractPluginOptions\n extends VanillaExtractVitePluginOptions {}\n\nexport async function ViteVanillaExtractPlugin(\n options: ViteVanillaExtractPluginOptions = {},\n): Promise<VitePlugin[]> {\n const plugin = await findProjectPlugin<VanillaExtractPlugin>(PLUGIN_NAME);\n const {\n identifiers: baseIdentifiers,\n // esbuildOptions: baseEsbuildOptions = {},\n } = plugin?.options || {};\n\n // const { esbuildOptions = {} } = options;\n\n return vanillaExtractPlugin({\n identifiers: baseIdentifiers,\n ...options,\n // esbuildOptions: {\n // ...baseEsbuildOptions,\n // ...esbuildOptions,\n // external: mergeExternal(\n // baseEsbuildOptions.external,\n // esbuildOptions.external,\n // ),\n // },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"plugboy-vanilla-extract-plugin.mjs","names":["MagicStringBundle","vanillaExtractPlugin","vanillaExtractPlugin"],"sources":["../src/types.ts","../src/_origin/lib.ts","../src/_origin/index.ts","../src/plugin.ts","../src/vite.ts"],"sourcesContent":["import { Plugin } from '@fastkit/plugboy';\nimport type { vanillaExtractPlugin as rollupPlugin } from '@vanilla-extract/rollup-plugin';\n\ntype VanillaExtractPluginOptions = Omit<\n NonNullable<Parameters<typeof rollupPlugin>[0]>,\n 'extract'\n>;\n\nexport interface PluginOptions\n extends Pick<VanillaExtractPluginOptions, 'identifiers' | 'esbuildOptions'> {}\n\nexport const PLUGIN_NAME = 'plugboy-vanilla-extract';\n\nexport interface VanillaExtractPlugin extends Plugin {\n name: typeof PLUGIN_NAME;\n _options: PluginOptions;\n}\n","import { cssFileFilter } from '@vanilla-extract/integration';\nimport MagicString, { Bundle as MagicStringBundle } from 'magic-string';\nimport type { ModuleInfo, PluginContext } from 'rolldown';\nimport { posix } from 'node:path';\n\n/** Generate a CSS bundle from Rollup context */\nexport function generateCssBundle(\n plugin: Pick<PluginContext, 'getModuleIds' | 'getModuleInfo' | 'warn'>,\n): {\n bundle: MagicStringBundle;\n extractedCssIds: Set<string>;\n} {\n const cssBundle = new MagicStringBundle();\n const extractedCssIds = new Set<string>();\n\n // 1. identify CSS files to bundle\n const cssFiles: Record<string, ImportChain> = {};\n for (const id of plugin.getModuleIds()) {\n if (cssFileFilter.test(id)) {\n cssFiles[id] = buildImportChain(id, plugin);\n }\n }\n\n // 2. build bundle from import order\n for (const id of sortModules(cssFiles)) {\n const { importedIds } = plugin.getModuleInfo(id) ?? {};\n for (const importedId of importedIds ?? []) {\n const resolution = plugin.getModuleInfo(importedId);\n if (resolution?.meta.css && !extractedCssIds.has(resolution.id)) {\n extractedCssIds.add(resolution.id);\n cssBundle.addSource({\n filename: resolution.id,\n content: new MagicString(resolution.meta.css),\n });\n }\n }\n }\n\n return { bundle: cssBundle, extractedCssIds };\n}\n\n/** [id, order] tuple meant for ordering imports */\nexport type ImportChain = [id: string, order: number][];\n\n/** Trace a file back through its importers, building an ordered list */\nexport function buildImportChain(\n id: string,\n plugin: Pick<PluginContext, 'getModuleInfo' | 'warn'>,\n): ImportChain {\n let mod: ModuleInfo | null = plugin.getModuleInfo(id)!;\n if (!mod) {\n return [];\n }\n /** [id, order] */\n const chain: ImportChain = [[id, -1]];\n // resolve upwards to root entry\n while (!mod.isEntry) {\n const { id: currentId, importers } = mod;\n const lastImporterId = importers.at(-1);\n if (!lastImporterId) {\n break;\n }\n if (chain.some(([id]) => id === lastImporterId)) {\n plugin.warn(\n `Circular import detected. Can’t determine ideal import order of module.\\n${chain\n .reverse()\n .join('\\n → ')}`,\n );\n break;\n }\n mod = plugin.getModuleInfo(lastImporterId);\n if (!mod) {\n break;\n }\n // importedIds preserves the import order within each module\n chain.push([lastImporterId, mod.importedIds.indexOf(currentId)]);\n }\n return chain.reverse();\n}\n\n/** Compare import chains to determine a flat ordering for modules */\nexport function sortModules(modules: Record<string, ImportChain>): string[] {\n const sortedModules = Object.entries(modules);\n\n // 2. sort CSS by import order\n sortedModules.sort(([_idA, chainA], [_idB, chainB]) => {\n const shorterChain = Math.min(chainA.length, chainB.length);\n for (let i = 0; i < shorterChain; i++) {\n const [moduleA, orderA] = chainA[i];\n const [moduleB, orderB] = chainB[i];\n // on same node, continue to next one\n if (moduleA === moduleB && orderA === orderB) {\n continue;\n }\n if (orderA !== orderB) {\n return orderA - orderB;\n }\n }\n return 0;\n });\n\n return sortedModules.map(([id]) => id);\n}\n\nconst SIDE_EFFECT_IMPORT_RE = /^\\s*import\\s+['\"]([^'\"]+)['\"]\\s*;?\\s*/gm;\n\n/** Remove specific side effect imports from JS */\nexport function stripSideEffectImportsMatching(\n code: string,\n sources: string[],\n): string {\n const matches = code.matchAll(SIDE_EFFECT_IMPORT_RE);\n if (!matches) {\n return code;\n }\n let output = code;\n for (const match of matches) {\n if (!match[1] || !sources.includes(match[1])) {\n continue;\n }\n output = output.replace(match[0], '');\n }\n return output;\n}\n\nexport async function tryGetPackageName(cwd: string): Promise<string | null> {\n try {\n const packageJson = require(posix.join(cwd, 'package.json'));\n\n return packageJson?.name || null;\n } catch {\n return null;\n }\n}\n","import type { Plugin, OutputChunk } from 'rolldown';\nimport {\n cssFileFilter,\n processVanillaFile,\n compile,\n type IdentifierOption,\n getSourceFromVirtualCssFile,\n virtualCssFileFilter,\n transform,\n type CompileOptions,\n} from '@vanilla-extract/integration';\nimport { posix } from 'node:path';\nimport {\n generateCssBundle,\n stripSideEffectImportsMatching,\n tryGetPackageName,\n} from './lib';\n\nconst { relative, normalize, dirname } = posix;\n\nexport interface Options {\n /**\n * Different formatting of identifiers (e.g. class names, keyframes, CSS Vars, etc) can be configured by selecting from the following options:\n * - \"short\": 7+ character hash. e.g. hnw5tz3\n * - \"debug\": human readable prefixes representing the owning filename and a potential rule level debug name. e.g. myfile_mystyle_hnw5tz3\n * - custom function: takes an object parameter with `hash`, `filePath`, `debugId`, and `packageName`, and returns a customized identifier.\n * @default \"short\"\n * @example ({ hash }) => `prefix_${hash}`\n */\n identifiers?: IdentifierOption;\n /**\n * Current working directory\n * @default process.cwd()\n */\n cwd?: string;\n /**\n * Options forwarded to esbuild\n * @see https://esbuild.github.io/\n */\n esbuildOptions?: CompileOptions['esbuildOptions'];\n /**\n * Extract .css bundle to a specified filename\n * @default false\n */\n extract?:\n | {\n /**\n * Name of emitted .css file.\n * @default \"bundle.css\"\n */\n name?: string | ((chunk: OutputChunk) => string);\n /**\n * Generate a .css.map file?\n * @default false\n */\n sourcemap?: boolean;\n }\n | boolean;\n\n /**\n * Inject filescopes into Vanilla Extract modules instead of generating CSS.\n * Useful for utility or component libraries that prefer their consumers to\n * process Vanilla Extract files instead of bundling CSS.\n *\n * Only works with `preserveModules: true`.\n *\n * @default false\n */\n unstable_injectFilescopes?: boolean;\n}\n\nexport function vanillaExtractPlugin({\n identifiers,\n cwd = process.cwd(),\n esbuildOptions,\n extract = false,\n unstable_injectFilescopes = false,\n}: Options = {}): Plugin {\n if (extract === true) {\n extract = {};\n }\n const isProduction = process.env.NODE_ENV === 'production';\n\n let extractedCssIds = new Set<string>(); // only for `extract`\n\n return {\n name: 'vanilla-extract',\n\n buildStart() {\n extractedCssIds = new Set(); // refresh every build\n },\n\n // Transform .css.js to .js\n async transform(code, id) {\n if (!cssFileFilter.test(id)) {\n return null;\n }\n\n const identOption = identifiers ?? (isProduction ? 'short' : 'debug');\n const [filePath] = id.split('?');\n\n if (unstable_injectFilescopes) {\n const packageName = await tryGetPackageName(cwd);\n const transformedCode = await transform({\n source: code,\n filePath: id,\n rootPath: cwd,\n packageName: packageName ?? '',\n identOption,\n });\n\n return {\n code: transformedCode,\n map: { mappings: '' },\n };\n }\n\n const { source, watchFiles } = await compile({\n filePath,\n cwd,\n esbuildOptions,\n identOption,\n });\n\n for (const file of watchFiles) {\n this.addWatchFile(file);\n }\n\n const output = await processVanillaFile({\n source,\n filePath,\n identOption,\n });\n return {\n code: output,\n map: { mappings: '' },\n };\n },\n\n // Resolve .css to external module\n async resolveId(id) {\n if (!virtualCssFileFilter.test(id)) {\n return null;\n }\n const { fileName, source } = await getSourceFromVirtualCssFile(id);\n return {\n id: fileName,\n external: true,\n meta: {\n css: source,\n },\n };\n },\n // Emit .css assets and replace .css import paths with relative paths to emitted css files\n renderChunk(code, chunkInfo) {\n const chunkPath = dirname(chunkInfo.fileName);\n const output = chunkInfo.imports.reduce((codeResult, importPath) => {\n const moduleInfo = this.getModuleInfo(importPath);\n if (!moduleInfo?.meta.css || extract) {\n return codeResult;\n }\n\n const assetId = this.emitFile({\n type: 'asset',\n name: moduleInfo.id,\n source: moduleInfo.meta.css,\n });\n const assetPath = this.getFileName(assetId);\n const relativeAssetPath = `./${normalize(\n relative(chunkPath, assetPath),\n )}`;\n return codeResult.replace(importPath, relativeAssetPath);\n }, code);\n\n return {\n code: output,\n map: null,\n };\n },\n\n // Remove side effect imports (if extracting)\n async generateBundle(_options, bundle) {\n if (!extract) {\n return;\n }\n\n for (const chunk of Object.values(bundle)) {\n if (chunk.type !== 'chunk' || !chunk.isEntry) continue;\n\n const jsFileName = chunk.fileName; // index.js / index.mjs\n // Skip DTS files\n if (/\\.d\\.(ts|mts|cts)$/.test(jsFileName)) continue;\n\n const extractName = extract.name || '[name].css';\n const name = jsFileName.replace(/\\.(js|mjs)$/, '');\n const cssFileName =\n typeof extractName === 'function'\n ? extractName(chunk)\n : extractName.replace('[name]', name);\n\n const { bundle: cssBundle, extractedCssIds: extractedIds } =\n generateCssBundle(this);\n extractedCssIds = extractedIds;\n // const name = extract.name || 'bundle.css';\n this.emitFile({\n type: 'asset',\n fileName: cssFileName,\n source: cssBundle.toString(),\n });\n\n if (extract.sourcemap) {\n const sourcemapName = `${cssFileName}.map`;\n this.emitFile({\n type: 'asset',\n name: sourcemapName,\n originalFileName: sourcemapName,\n source: cssBundle\n .generateMap({ file: name, includeContent: true })\n .toString(),\n });\n }\n }\n\n await Promise.all(\n Object.entries(bundle).map(async ([id, chunk]) => {\n if (\n chunk.type === 'chunk' &&\n (id.endsWith('.js') || id.endsWith('.mjs')) &&\n chunk.imports.some((specifier) => extractedCssIds.has(specifier))\n ) {\n chunk.code = await stripSideEffectImportsMatching(chunk.code, [\n ...extractedCssIds,\n ]);\n }\n }),\n );\n },\n };\n}\n","import { definePlugin, findFile } from '@fastkit/plugboy';\nimport { vanillaExtractPlugin } from './_origin';\nimport { VanillaExtractPlugin, PluginOptions, PLUGIN_NAME } from './types';\n\ndeclare module '@fastkit/plugboy' {\n export interface WorkspaceMeta {\n hasVanillaExtract: boolean;\n }\n}\n\nexport async function createVanillaExtractPlugin(options: PluginOptions = {}) {\n return definePlugin<VanillaExtractPlugin>({\n name: PLUGIN_NAME,\n _options: options,\n hooks: {\n async setupWorkspace(ctx) {\n ctx.mergeExternals(/@vanilla-extract/);\n\n ctx.meta.hasVanillaExtract = !!(await findFile(\n ctx.dirs.src.value,\n /\\.css\\.ts$/,\n ));\n\n if (ctx.meta.hasVanillaExtract) {\n const originalPlugin = vanillaExtractPlugin({\n ...options,\n extract: true,\n });\n\n // @TODO\n // rolldown-plugin-dts cannot handle vanilla-extract correctly\n // https://github.com/sxzz/rolldown-plugin-dts/issues/136\n ctx.config.dts ??= {};\n ctx.config.dts.inline = true;\n ctx.dts.inline = true;\n\n ctx.plugins.push(originalPlugin);\n }\n },\n },\n });\n}\n","import { findProjectPlugin } from '@fastkit/plugboy';\nimport { Plugin as VitePlugin } from 'vite';\nimport { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';\nimport { PLUGIN_NAME, VanillaExtractPlugin } from './types';\n\ntype VanillaExtractVitePluginOptions = NonNullable<\n Parameters<typeof vanillaExtractPlugin>[0]\n>;\n\nexport interface ViteVanillaExtractPluginOptions\n extends VanillaExtractVitePluginOptions {}\n\nexport async function ViteVanillaExtractPlugin(\n options: ViteVanillaExtractPluginOptions = {},\n): Promise<VitePlugin[]> {\n const plugin = await findProjectPlugin<VanillaExtractPlugin>(PLUGIN_NAME);\n const { identifiers: baseIdentifiers } = plugin?._options || {};\n\n return vanillaExtractPlugin({\n identifiers: baseIdentifiers,\n ...options,\n });\n}\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,cAAc;;;;;ACL3B,SAAgB,kBACd,QAIA;CACA,MAAM,YAAY,IAAIA,QAAmB;CACzC,MAAM,kCAAkB,IAAI,KAAa;CAGzC,MAAM,WAAwC,EAAE;AAChD,MAAK,MAAM,MAAM,OAAO,cAAc,CACpC,KAAI,cAAc,KAAK,GAAG,CACxB,UAAS,MAAM,iBAAiB,IAAI,OAAO;AAK/C,MAAK,MAAM,MAAM,YAAY,SAAS,EAAE;EACtC,MAAM,EAAE,gBAAgB,OAAO,cAAc,GAAG,IAAI,EAAE;AACtD,OAAK,MAAM,cAAc,eAAe,EAAE,EAAE;GAC1C,MAAM,aAAa,OAAO,cAAc,WAAW;AACnD,OAAI,YAAY,KAAK,OAAO,CAAC,gBAAgB,IAAI,WAAW,GAAG,EAAE;AAC/D,oBAAgB,IAAI,WAAW,GAAG;AAClC,cAAU,UAAU;KAClB,UAAU,WAAW;KACrB,SAAS,IAAI,YAAY,WAAW,KAAK,IAAI;KAC9C,CAAC;;;;AAKR,QAAO;EAAE,QAAQ;EAAW;EAAiB;;;AAO/C,SAAgB,iBACd,IACA,QACa;CACb,IAAI,MAAyB,OAAO,cAAc,GAAG;AACrD,KAAI,CAAC,IACH,QAAO,EAAE;;CAGX,MAAM,QAAqB,CAAC,CAAC,IAAI,GAAG,CAAC;AAErC,QAAO,CAAC,IAAI,SAAS;EACnB,MAAM,EAAE,IAAI,WAAW,cAAc;EACrC,MAAM,iBAAiB,UAAU,GAAG,GAAG;AACv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EJ;;;;;ACnOH,eAAsB,2BAA2B,UAAyB,EAAE,EAAE;AAC5E,QAAO,aAAmC;EACxC,MAAM;EACN,UAAU;EACV,OAAO,EACL,MAAM,eAAe,KAAK;AACxB,OAAI,eAAe,mBAAmB;AAEtC,OAAI,KAAK,oBAAoB,CAAC,CAAE,MAAM,SACpC,IAAI,KAAK,IAAI,OACb,aACD;AAED,OAAI,IAAI,KAAK,mBAAmB;IAC9B,MAAM,iBAAiBC,uBAAqB;KAC1C,GAAG;KACH,SAAS;KACV,CAAC;AAKF,QAAI,OAAO,QAAQ,EAAE;AACrB,QAAI,OAAO,IAAI,SAAS;AACxB,QAAI,IAAI,SAAS;AAEjB,QAAI,QAAQ,KAAK,eAAe;;KAGrC;EACF,CAAC;;;;;AC5BJ,eAAsB,yBACpB,UAA2C,EAAE,EACtB;CAEvB,MAAM,EAAE,aAAa,qBADN,MAAM,kBAAwC,YAAY,GACxB,YAAY,EAAE;AAE/D,QAAO,qBAAqB;EAC1B,aAAa;EACb,GAAG;EACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastkit/plugboy-vanilla-extract-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-next.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"repository": {
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"exports": {
|
|
14
14
|
"./package.json": "./package.json",
|
|
15
15
|
".": {
|
|
16
|
-
"types": "./dist/plugboy-vanilla-extract-plugin.d.
|
|
16
|
+
"types": "./dist/plugboy-vanilla-extract-plugin.d.mts",
|
|
17
17
|
"import": {
|
|
18
18
|
"default": "./dist/plugboy-vanilla-extract-plugin.mjs"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"./css": {
|
|
22
|
-
"types": "./dist/css.d.
|
|
22
|
+
"types": "./dist/css.d.mts",
|
|
23
23
|
"import": {
|
|
24
24
|
"default": "./dist/css.mjs"
|
|
25
25
|
}
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"./*": "./dist/*"
|
|
28
28
|
},
|
|
29
29
|
"main": "./dist/plugboy-vanilla-extract-plugin.mjs",
|
|
30
|
-
"types": "./dist/plugboy-vanilla-extract-plugin.d.
|
|
30
|
+
"types": "./dist/plugboy-vanilla-extract-plugin.d.mts",
|
|
31
31
|
"typesVersions": {
|
|
32
32
|
"*": {
|
|
33
33
|
".": [
|
|
34
|
-
"./dist/plugboy-vanilla-extract-plugin.d.
|
|
34
|
+
"./dist/plugboy-vanilla-extract-plugin.d.mts"
|
|
35
35
|
],
|
|
36
36
|
"css": [
|
|
37
|
-
"./dist/css.d.
|
|
37
|
+
"./dist/css.d.mts"
|
|
38
38
|
]
|
|
39
39
|
}
|
|
40
40
|
},
|
|
@@ -42,17 +42,17 @@
|
|
|
42
42
|
"dist"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@vanilla-extract/css": "^1.
|
|
46
|
-
"@vanilla-extract/
|
|
47
|
-
"@vanilla-extract/vite-plugin": "^5.1.
|
|
45
|
+
"@vanilla-extract/css": "^1.18.0",
|
|
46
|
+
"@vanilla-extract/rollup-plugin": "^1.5.1",
|
|
47
|
+
"@vanilla-extract/vite-plugin": "^5.1.4"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"vite": "^7.1.9",
|
|
51
|
-
"@fastkit/plugboy": "^0.
|
|
51
|
+
"@fastkit/plugboy": "^1.0.0-next.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
55
|
-
"@fastkit/plugboy": "^0.
|
|
55
|
+
"@fastkit/plugboy": "^1.0.0-next.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"@vanilla-extract/vite-plugin": {
|
package/dist/css.d.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { StyleRule, GlobalStyleRule, createGlobalTheme } from '@vanilla-extract/css';
|
|
2
|
-
|
|
3
|
-
type CustomStyleRules = Record<string, any>;
|
|
4
|
-
type _LayerStyleRules = NonNullable<StyleRule['@layer']>[string];
|
|
5
|
-
type LayerStyleRules<CustomRules extends CustomStyleRules | null = null> = CustomRules extends null ? _LayerStyleRules : _LayerStyleRules & CustomRules;
|
|
6
|
-
type ClassNames = string | ClassNames[];
|
|
7
|
-
type ComplexLayerStyleRule<CustomRules extends CustomStyleRules | null = null> = LayerStyleRules<CustomRules> | (LayerStyleRules<CustomRules> | ClassNames)[];
|
|
8
|
-
type _LayerGlobalStyleRules = NonNullable<GlobalStyleRule['@layer']>[string];
|
|
9
|
-
type LayerGlobalStyleRules<CustomRules extends CustomStyleRules | null = null> = CustomRules extends null ? _LayerGlobalStyleRules : _LayerGlobalStyleRules & CustomRules;
|
|
10
|
-
type AnyStyleRule<CustomRules extends CustomStyleRules | null = null> = LayerStyleRules<CustomRules> | LayerGlobalStyleRules<CustomRules>;
|
|
11
|
-
type LayerStyleHooks<CustomRules extends CustomStyleRules | null = null> = {
|
|
12
|
-
style?: (rule: ComplexLayerStyleRule<CustomRules>, debugId?: string) => void;
|
|
13
|
-
global?: (selector: string, rule: LayerGlobalStyleRules<CustomRules>) => void;
|
|
14
|
-
anyStyle?: (style: AnyStyleRule<CustomRules>) => void;
|
|
15
|
-
};
|
|
16
|
-
interface LayerStyle<CustomRules extends CustomStyleRules | null = null> {
|
|
17
|
-
layerName: string;
|
|
18
|
-
parentLayerName: string | null;
|
|
19
|
-
/**
|
|
20
|
-
* @see {@link style}
|
|
21
|
-
*/
|
|
22
|
-
(rule: ComplexLayerStyleRule<CustomRules>, debugId?: string): string;
|
|
23
|
-
/**
|
|
24
|
-
* @see {@link style}
|
|
25
|
-
*/
|
|
26
|
-
style(rule: ComplexLayerStyleRule<CustomRules>, debugId?: string): string;
|
|
27
|
-
/**
|
|
28
|
-
* @see {@link globalStyle}
|
|
29
|
-
*/
|
|
30
|
-
global(selector: string, rule: LayerGlobalStyleRules<CustomRules>): void;
|
|
31
|
-
/**
|
|
32
|
-
* @see {@link _createGlobalTheme}
|
|
33
|
-
*/
|
|
34
|
-
globalTheme: typeof createGlobalTheme;
|
|
35
|
-
defineNestedLayer(globalNameOrNestedOptions?: string | DefineLayerOptions<CustomRules>): LayerStyle<CustomRules>;
|
|
36
|
-
/**
|
|
37
|
-
* Add global CSS variable with layer
|
|
38
|
-
*
|
|
39
|
-
* @remarks The vanilla-extract API is buggy when handling layered css variables.
|
|
40
|
-
*
|
|
41
|
-
* @param selector - selector
|
|
42
|
-
* @param vars - variables
|
|
43
|
-
*/
|
|
44
|
-
pushGlobalVars(selector: string, vars: Record<string, string>): void;
|
|
45
|
-
/**
|
|
46
|
-
* Output variables accumulated by `pushGlobalVars`.
|
|
47
|
-
*
|
|
48
|
-
* @remarks The vanilla-extract API is buggy when handling layered css variables.
|
|
49
|
-
*/
|
|
50
|
-
dumpGlobalVars(): void;
|
|
51
|
-
hooks: LayerStyleHooks<CustomRules>;
|
|
52
|
-
}
|
|
53
|
-
interface DefineLayerParentOptions {
|
|
54
|
-
parent?: string;
|
|
55
|
-
}
|
|
56
|
-
interface DefineLayerBaseOptions<CustomRules extends CustomStyleRules | null = null> {
|
|
57
|
-
hooks?: LayerStyleHooks<CustomRules>;
|
|
58
|
-
}
|
|
59
|
-
interface DefineLayerScopedOptions<CustomRules extends CustomStyleRules | null = null> extends DefineLayerBaseOptions<CustomRules> {
|
|
60
|
-
/** Debug ID */
|
|
61
|
-
debugId?: string;
|
|
62
|
-
globalName?: never;
|
|
63
|
-
}
|
|
64
|
-
interface DefineLayerGlobalOptions<CustomRules extends CustomStyleRules | null = null> extends DefineLayerBaseOptions<CustomRules> {
|
|
65
|
-
debugId?: never;
|
|
66
|
-
/** Parent layer name */
|
|
67
|
-
globalName: string;
|
|
68
|
-
}
|
|
69
|
-
type DefineLayerOptions<CustomRules extends CustomStyleRules | null = null> = DefineLayerScopedOptions<CustomRules> | DefineLayerGlobalOptions<CustomRules>;
|
|
70
|
-
type DefineNestableLayerOptions<CustomRules extends CustomStyleRules | null = null> = DefineLayerOptions<CustomRules> & DefineLayerParentOptions;
|
|
71
|
-
declare function defineLayerStyle<CustomRules extends CustomStyleRules | null = null>(globalNameOrOptions?: string | DefineNestableLayerOptions<CustomRules>): LayerStyle<CustomRules>;
|
|
72
|
-
|
|
73
|
-
export { type DefineLayerBaseOptions, type DefineLayerGlobalOptions, type DefineLayerOptions, type DefineLayerParentOptions, type DefineLayerScopedOptions, type DefineNestableLayerOptions, type LayerStyle, defineLayerStyle };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Plugin } from '@fastkit/plugboy';
|
|
2
|
-
import { vanillaExtractPlugin } from '@vanilla-extract/esbuild-plugin';
|
|
3
|
-
import { Plugin as Plugin$1 } from 'vite';
|
|
4
|
-
import { vanillaExtractPlugin as vanillaExtractPlugin$1 } from '@vanilla-extract/vite-plugin';
|
|
5
|
-
|
|
6
|
-
type VanillaExtractPluginOptions = NonNullable<Parameters<typeof vanillaExtractPlugin>[0]>;
|
|
7
|
-
interface VanillaExtractEsbuildOptions extends NonNullable<VanillaExtractPluginOptions['esbuildOptions']> {
|
|
8
|
-
}
|
|
9
|
-
interface PluginOptions extends Pick<VanillaExtractPluginOptions, 'identifiers' | 'esbuildOptions'> {
|
|
10
|
-
}
|
|
11
|
-
declare const PLUGIN_NAME = "plugboy-vanilla-extract";
|
|
12
|
-
interface VanillaExtractPlugin extends Plugin {
|
|
13
|
-
name: typeof PLUGIN_NAME;
|
|
14
|
-
options: PluginOptions;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
declare module '@fastkit/plugboy' {
|
|
18
|
-
interface WorkspaceMeta {
|
|
19
|
-
hasVanillaExtract: boolean;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
declare function createVanillaExtractPlugin(options?: PluginOptions): Promise<VanillaExtractPlugin>;
|
|
23
|
-
|
|
24
|
-
type VanillaExtractVitePluginOptions = NonNullable<Parameters<typeof vanillaExtractPlugin$1>[0]>;
|
|
25
|
-
interface ViteVanillaExtractPluginOptions extends VanillaExtractVitePluginOptions {
|
|
26
|
-
}
|
|
27
|
-
declare function ViteVanillaExtractPlugin(options?: ViteVanillaExtractPluginOptions): Promise<Plugin$1[]>;
|
|
28
|
-
|
|
29
|
-
export { PLUGIN_NAME, type PluginOptions, type VanillaExtractEsbuildOptions, type VanillaExtractPlugin, ViteVanillaExtractPlugin, type ViteVanillaExtractPluginOptions, createVanillaExtractPlugin };
|