@bamboocss/config 1.11.4 → 1.12.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/dist/diff-config.cjs +186 -2
- package/dist/diff-config.mjs +162 -1
- package/dist/index.cjs +492 -27
- package/dist/index.d.cts +34 -7
- package/dist/index.d.mts +34 -7
- package/dist/index.mjs +447 -5
- package/dist/merge-config.cjs +253 -3
- package/dist/merge-config.d.cts +15 -1
- package/dist/merge-config.d.mts +15 -1
- package/dist/merge-config.mjs +251 -1
- package/dist/resolve-ts-path-pattern.cjs +0 -1
- package/dist/resolve-ts-path-pattern.d.cts +6 -2
- package/dist/resolve-ts-path-pattern.d.mts +6 -2
- package/package.json +6 -6
- package/dist/diff-config-Co_3mDXE.cjs +0 -197
- package/dist/diff-config-KDQWMnQN.mjs +0 -163
- package/dist/merge-config-CcNpHJit.cjs +0 -312
- package/dist/merge-config-DI__LOWx.mjs +0 -270
- package/dist/merge-config-DVOlBQJY.d.cts +0 -16
- package/dist/merge-config-oEiBYbfB.d.mts +0 -16
- package/dist/ts-config-paths-CvGId8kq.d.mts +0 -11
- package/dist/ts-config-paths-wVx39QZ0.d.cts +0 -11
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
//#endregion
|
|
23
|
-
let _bamboocss_shared = require("@bamboocss/shared");
|
|
24
|
-
let microdiff = require("microdiff");
|
|
25
|
-
microdiff = __toESM(microdiff);
|
|
26
|
-
//#region src/create-matcher.ts
|
|
27
|
-
/**
|
|
28
|
-
* Acts like a .gitignore matcher
|
|
29
|
-
* e.g a list of string to search for nested path with glob and exclusion allowed
|
|
30
|
-
* ["outdir", "theme.recipes", '*.css', '!aaa.*.bbb']
|
|
31
|
-
*/
|
|
32
|
-
function createMatcher(id, patterns) {
|
|
33
|
-
if (!patterns?.length) return () => void 0;
|
|
34
|
-
const includePatterns = [];
|
|
35
|
-
const excludePatterns = [];
|
|
36
|
-
new Set(patterns).forEach((pattern) => {
|
|
37
|
-
const regexString = pattern.replace(/\*/g, ".*");
|
|
38
|
-
if (pattern.startsWith("!")) excludePatterns.push(regexString.slice(1));
|
|
39
|
-
else includePatterns.push(regexString);
|
|
40
|
-
});
|
|
41
|
-
const include = new RegExp(includePatterns.join("|"));
|
|
42
|
-
const exclude = new RegExp(excludePatterns.join("|"));
|
|
43
|
-
return (path) => {
|
|
44
|
-
if (excludePatterns.length && exclude.test(path)) return;
|
|
45
|
-
return include.test(path) ? id : void 0;
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region src/config-deps.ts
|
|
50
|
-
const all = [
|
|
51
|
-
"clean",
|
|
52
|
-
"cwd",
|
|
53
|
-
"eject",
|
|
54
|
-
"outdir",
|
|
55
|
-
"forceConsistentTypeExtension",
|
|
56
|
-
"outExtension",
|
|
57
|
-
"emitTokensOnly",
|
|
58
|
-
"presets",
|
|
59
|
-
"plugins",
|
|
60
|
-
"hooks"
|
|
61
|
-
];
|
|
62
|
-
const format = [
|
|
63
|
-
"syntax",
|
|
64
|
-
"hash",
|
|
65
|
-
"prefix",
|
|
66
|
-
"separator",
|
|
67
|
-
"strictTokens",
|
|
68
|
-
"strictPropertyValues",
|
|
69
|
-
"shorthands"
|
|
70
|
-
];
|
|
71
|
-
const tokens = [
|
|
72
|
-
"utilities",
|
|
73
|
-
"conditions",
|
|
74
|
-
"theme.tokens",
|
|
75
|
-
"theme.semanticTokens",
|
|
76
|
-
"theme.breakpoints",
|
|
77
|
-
"theme.containerNames",
|
|
78
|
-
"theme.containerSizes"
|
|
79
|
-
];
|
|
80
|
-
const jsx = [
|
|
81
|
-
"jsxFramework",
|
|
82
|
-
"jsxFactory",
|
|
83
|
-
"jsxStyleProps",
|
|
84
|
-
"syntax"
|
|
85
|
-
];
|
|
86
|
-
const common = tokens.concat(jsx, format);
|
|
87
|
-
const artifactConfigDeps = {
|
|
88
|
-
helpers: ["syntax", "jsxFramework"],
|
|
89
|
-
keyframes: ["theme.keyframes", "layers"],
|
|
90
|
-
"design-tokens": ["layers", "!utilities.*.className"].concat(tokens),
|
|
91
|
-
types: ["!utilities.*.className"].concat(common),
|
|
92
|
-
"css-fn": common,
|
|
93
|
-
cva: ["syntax"],
|
|
94
|
-
sva: ["syntax"],
|
|
95
|
-
cx: [],
|
|
96
|
-
"create-recipe": [
|
|
97
|
-
"separator",
|
|
98
|
-
"prefix",
|
|
99
|
-
"hash"
|
|
100
|
-
],
|
|
101
|
-
"recipes-index": ["theme.recipes", "theme.slotRecipes"],
|
|
102
|
-
recipes: ["theme.recipes", "theme.slotRecipes"],
|
|
103
|
-
"patterns-index": ["syntax", "patterns"],
|
|
104
|
-
patterns: ["syntax", "patterns"],
|
|
105
|
-
"jsx-is-valid-prop": common,
|
|
106
|
-
"jsx-factory": jsx,
|
|
107
|
-
"jsx-helpers": jsx,
|
|
108
|
-
"jsx-patterns": jsx.concat("patterns"),
|
|
109
|
-
"jsx-patterns-index": jsx.concat("patterns"),
|
|
110
|
-
"jsx-create-style-context": jsx,
|
|
111
|
-
"css-index": ["syntax"],
|
|
112
|
-
"package.json": ["forceConsistentTypeExtension", "outExtension"],
|
|
113
|
-
"types-styles": ["shorthands"],
|
|
114
|
-
"types-conditions": ["conditions"],
|
|
115
|
-
"types-jsx": jsx,
|
|
116
|
-
"types-entry": [],
|
|
117
|
-
"types-gen": [],
|
|
118
|
-
"types-gen-system": [],
|
|
119
|
-
themes: ["themes"].concat(tokens),
|
|
120
|
-
"static-css": [
|
|
121
|
-
"staticCss",
|
|
122
|
-
"patterns",
|
|
123
|
-
"theme.recipes",
|
|
124
|
-
"theme.slotRecipes"
|
|
125
|
-
].concat(tokens),
|
|
126
|
-
styles: [],
|
|
127
|
-
"styles.css": []
|
|
128
|
-
};
|
|
129
|
-
const artifactMatchers = Object.entries(artifactConfigDeps).map(([key, paths]) => {
|
|
130
|
-
if (!paths.length) return () => void 0;
|
|
131
|
-
return createMatcher(key, paths.concat(all));
|
|
132
|
-
});
|
|
133
|
-
//#endregion
|
|
134
|
-
//#region src/diff-config.ts
|
|
135
|
-
const runIfFn = (fn) => typeof fn === "function" ? fn() : fn;
|
|
136
|
-
/**
|
|
137
|
-
* Check if recipes were empty before and non-empty now (or vice versa)
|
|
138
|
-
*/
|
|
139
|
-
const hasRecipeStateTransition = (prevConfig, nextConfig) => {
|
|
140
|
-
const prevRecipes = prevConfig.theme?.recipes ?? {};
|
|
141
|
-
const prevSlotRecipes = prevConfig.theme?.slotRecipes ?? {};
|
|
142
|
-
const prevHasRecipes = Object.keys(prevRecipes).length > 0 || Object.keys(prevSlotRecipes).length > 0;
|
|
143
|
-
const nextRecipes = nextConfig.theme?.recipes ?? {};
|
|
144
|
-
const nextSlotRecipes = nextConfig.theme?.slotRecipes ?? {};
|
|
145
|
-
return prevHasRecipes !== (Object.keys(nextRecipes).length > 0 || Object.keys(nextSlotRecipes).length > 0);
|
|
146
|
-
};
|
|
147
|
-
/**
|
|
148
|
-
* Diff the two config objects and return the list of affected properties
|
|
149
|
-
*/
|
|
150
|
-
function diffConfigs(config, prevConfig) {
|
|
151
|
-
const affected = {
|
|
152
|
-
artifacts: /* @__PURE__ */ new Set(),
|
|
153
|
-
hasConfigChanged: false,
|
|
154
|
-
diffs: []
|
|
155
|
-
};
|
|
156
|
-
if (!prevConfig) {
|
|
157
|
-
affected.hasConfigChanged = true;
|
|
158
|
-
return affected;
|
|
159
|
-
}
|
|
160
|
-
const configDiff = (0, microdiff.default)(prevConfig, runIfFn(config));
|
|
161
|
-
if (!configDiff.length) return affected;
|
|
162
|
-
affected.hasConfigChanged = true;
|
|
163
|
-
affected.diffs = configDiff;
|
|
164
|
-
configDiff.forEach((change) => {
|
|
165
|
-
const changePath = change.path.join(".");
|
|
166
|
-
artifactMatchers.forEach((matcher) => {
|
|
167
|
-
const id = matcher(changePath);
|
|
168
|
-
if (!id) return;
|
|
169
|
-
if (id === "recipes") {
|
|
170
|
-
const name = (0, _bamboocss_shared.dashCase)(change.path.slice(1, 3).join("."));
|
|
171
|
-
affected.artifacts.add(name);
|
|
172
|
-
}
|
|
173
|
-
if (id === "patterns") {
|
|
174
|
-
const name = (0, _bamboocss_shared.dashCase)(change.path.slice(0, 2).join("."));
|
|
175
|
-
affected.artifacts.add(name);
|
|
176
|
-
}
|
|
177
|
-
affected.artifacts.add(id);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
if (affected.artifacts.has("recipes") || affected.artifacts.has("recipes-index")) {
|
|
181
|
-
if (hasRecipeStateTransition(prevConfig, runIfFn(config))) affected.artifacts.add("create-recipe");
|
|
182
|
-
}
|
|
183
|
-
return affected;
|
|
184
|
-
}
|
|
185
|
-
//#endregion
|
|
186
|
-
Object.defineProperty(exports, "__toESM", {
|
|
187
|
-
enumerable: true,
|
|
188
|
-
get: function() {
|
|
189
|
-
return __toESM;
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
Object.defineProperty(exports, "diffConfigs", {
|
|
193
|
-
enumerable: true,
|
|
194
|
-
get: function() {
|
|
195
|
-
return diffConfigs;
|
|
196
|
-
}
|
|
197
|
-
});
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { dashCase } from "@bamboocss/shared";
|
|
2
|
-
import microdiff from "microdiff";
|
|
3
|
-
//#region src/create-matcher.ts
|
|
4
|
-
/**
|
|
5
|
-
* Acts like a .gitignore matcher
|
|
6
|
-
* e.g a list of string to search for nested path with glob and exclusion allowed
|
|
7
|
-
* ["outdir", "theme.recipes", '*.css', '!aaa.*.bbb']
|
|
8
|
-
*/
|
|
9
|
-
function createMatcher(id, patterns) {
|
|
10
|
-
if (!patterns?.length) return () => void 0;
|
|
11
|
-
const includePatterns = [];
|
|
12
|
-
const excludePatterns = [];
|
|
13
|
-
new Set(patterns).forEach((pattern) => {
|
|
14
|
-
const regexString = pattern.replace(/\*/g, ".*");
|
|
15
|
-
if (pattern.startsWith("!")) excludePatterns.push(regexString.slice(1));
|
|
16
|
-
else includePatterns.push(regexString);
|
|
17
|
-
});
|
|
18
|
-
const include = new RegExp(includePatterns.join("|"));
|
|
19
|
-
const exclude = new RegExp(excludePatterns.join("|"));
|
|
20
|
-
return (path) => {
|
|
21
|
-
if (excludePatterns.length && exclude.test(path)) return;
|
|
22
|
-
return include.test(path) ? id : void 0;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/config-deps.ts
|
|
27
|
-
const all = [
|
|
28
|
-
"clean",
|
|
29
|
-
"cwd",
|
|
30
|
-
"eject",
|
|
31
|
-
"outdir",
|
|
32
|
-
"forceConsistentTypeExtension",
|
|
33
|
-
"outExtension",
|
|
34
|
-
"emitTokensOnly",
|
|
35
|
-
"presets",
|
|
36
|
-
"plugins",
|
|
37
|
-
"hooks"
|
|
38
|
-
];
|
|
39
|
-
const format = [
|
|
40
|
-
"syntax",
|
|
41
|
-
"hash",
|
|
42
|
-
"prefix",
|
|
43
|
-
"separator",
|
|
44
|
-
"strictTokens",
|
|
45
|
-
"strictPropertyValues",
|
|
46
|
-
"shorthands"
|
|
47
|
-
];
|
|
48
|
-
const tokens = [
|
|
49
|
-
"utilities",
|
|
50
|
-
"conditions",
|
|
51
|
-
"theme.tokens",
|
|
52
|
-
"theme.semanticTokens",
|
|
53
|
-
"theme.breakpoints",
|
|
54
|
-
"theme.containerNames",
|
|
55
|
-
"theme.containerSizes"
|
|
56
|
-
];
|
|
57
|
-
const jsx = [
|
|
58
|
-
"jsxFramework",
|
|
59
|
-
"jsxFactory",
|
|
60
|
-
"jsxStyleProps",
|
|
61
|
-
"syntax"
|
|
62
|
-
];
|
|
63
|
-
const common = tokens.concat(jsx, format);
|
|
64
|
-
const artifactConfigDeps = {
|
|
65
|
-
helpers: ["syntax", "jsxFramework"],
|
|
66
|
-
keyframes: ["theme.keyframes", "layers"],
|
|
67
|
-
"design-tokens": ["layers", "!utilities.*.className"].concat(tokens),
|
|
68
|
-
types: ["!utilities.*.className"].concat(common),
|
|
69
|
-
"css-fn": common,
|
|
70
|
-
cva: ["syntax"],
|
|
71
|
-
sva: ["syntax"],
|
|
72
|
-
cx: [],
|
|
73
|
-
"create-recipe": [
|
|
74
|
-
"separator",
|
|
75
|
-
"prefix",
|
|
76
|
-
"hash"
|
|
77
|
-
],
|
|
78
|
-
"recipes-index": ["theme.recipes", "theme.slotRecipes"],
|
|
79
|
-
recipes: ["theme.recipes", "theme.slotRecipes"],
|
|
80
|
-
"patterns-index": ["syntax", "patterns"],
|
|
81
|
-
patterns: ["syntax", "patterns"],
|
|
82
|
-
"jsx-is-valid-prop": common,
|
|
83
|
-
"jsx-factory": jsx,
|
|
84
|
-
"jsx-helpers": jsx,
|
|
85
|
-
"jsx-patterns": jsx.concat("patterns"),
|
|
86
|
-
"jsx-patterns-index": jsx.concat("patterns"),
|
|
87
|
-
"jsx-create-style-context": jsx,
|
|
88
|
-
"css-index": ["syntax"],
|
|
89
|
-
"package.json": ["forceConsistentTypeExtension", "outExtension"],
|
|
90
|
-
"types-styles": ["shorthands"],
|
|
91
|
-
"types-conditions": ["conditions"],
|
|
92
|
-
"types-jsx": jsx,
|
|
93
|
-
"types-entry": [],
|
|
94
|
-
"types-gen": [],
|
|
95
|
-
"types-gen-system": [],
|
|
96
|
-
themes: ["themes"].concat(tokens),
|
|
97
|
-
"static-css": [
|
|
98
|
-
"staticCss",
|
|
99
|
-
"patterns",
|
|
100
|
-
"theme.recipes",
|
|
101
|
-
"theme.slotRecipes"
|
|
102
|
-
].concat(tokens),
|
|
103
|
-
styles: [],
|
|
104
|
-
"styles.css": []
|
|
105
|
-
};
|
|
106
|
-
const artifactMatchers = Object.entries(artifactConfigDeps).map(([key, paths]) => {
|
|
107
|
-
if (!paths.length) return () => void 0;
|
|
108
|
-
return createMatcher(key, paths.concat(all));
|
|
109
|
-
});
|
|
110
|
-
//#endregion
|
|
111
|
-
//#region src/diff-config.ts
|
|
112
|
-
const runIfFn = (fn) => typeof fn === "function" ? fn() : fn;
|
|
113
|
-
/**
|
|
114
|
-
* Check if recipes were empty before and non-empty now (or vice versa)
|
|
115
|
-
*/
|
|
116
|
-
const hasRecipeStateTransition = (prevConfig, nextConfig) => {
|
|
117
|
-
const prevRecipes = prevConfig.theme?.recipes ?? {};
|
|
118
|
-
const prevSlotRecipes = prevConfig.theme?.slotRecipes ?? {};
|
|
119
|
-
const prevHasRecipes = Object.keys(prevRecipes).length > 0 || Object.keys(prevSlotRecipes).length > 0;
|
|
120
|
-
const nextRecipes = nextConfig.theme?.recipes ?? {};
|
|
121
|
-
const nextSlotRecipes = nextConfig.theme?.slotRecipes ?? {};
|
|
122
|
-
return prevHasRecipes !== (Object.keys(nextRecipes).length > 0 || Object.keys(nextSlotRecipes).length > 0);
|
|
123
|
-
};
|
|
124
|
-
/**
|
|
125
|
-
* Diff the two config objects and return the list of affected properties
|
|
126
|
-
*/
|
|
127
|
-
function diffConfigs(config, prevConfig) {
|
|
128
|
-
const affected = {
|
|
129
|
-
artifacts: /* @__PURE__ */ new Set(),
|
|
130
|
-
hasConfigChanged: false,
|
|
131
|
-
diffs: []
|
|
132
|
-
};
|
|
133
|
-
if (!prevConfig) {
|
|
134
|
-
affected.hasConfigChanged = true;
|
|
135
|
-
return affected;
|
|
136
|
-
}
|
|
137
|
-
const configDiff = microdiff(prevConfig, runIfFn(config));
|
|
138
|
-
if (!configDiff.length) return affected;
|
|
139
|
-
affected.hasConfigChanged = true;
|
|
140
|
-
affected.diffs = configDiff;
|
|
141
|
-
configDiff.forEach((change) => {
|
|
142
|
-
const changePath = change.path.join(".");
|
|
143
|
-
artifactMatchers.forEach((matcher) => {
|
|
144
|
-
const id = matcher(changePath);
|
|
145
|
-
if (!id) return;
|
|
146
|
-
if (id === "recipes") {
|
|
147
|
-
const name = dashCase(change.path.slice(1, 3).join("."));
|
|
148
|
-
affected.artifacts.add(name);
|
|
149
|
-
}
|
|
150
|
-
if (id === "patterns") {
|
|
151
|
-
const name = dashCase(change.path.slice(0, 2).join("."));
|
|
152
|
-
affected.artifacts.add(name);
|
|
153
|
-
}
|
|
154
|
-
affected.artifacts.add(id);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
if (affected.artifacts.has("recipes") || affected.artifacts.has("recipes-index")) {
|
|
158
|
-
if (hasRecipeStateTransition(prevConfig, runIfFn(config))) affected.artifacts.add("create-recipe");
|
|
159
|
-
}
|
|
160
|
-
return affected;
|
|
161
|
-
}
|
|
162
|
-
//#endregion
|
|
163
|
-
export { diffConfigs as t };
|
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
require("./diff-config-Co_3mDXE.cjs");
|
|
2
|
-
let _bamboocss_logger = require("@bamboocss/logger");
|
|
3
|
-
let _bamboocss_shared = require("@bamboocss/shared");
|
|
4
|
-
//#region src/merge-hooks.ts
|
|
5
|
-
const mergeHooks = (plugins) => {
|
|
6
|
-
const hooksFns = {};
|
|
7
|
-
plugins.forEach(({ name, hooks }) => {
|
|
8
|
-
Object.entries(hooks ?? {}).forEach(([key, value]) => {
|
|
9
|
-
if (!hooksFns[key]) hooksFns[key] = [];
|
|
10
|
-
hooksFns[key].push([name, value]);
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
return Object.fromEntries(Object.entries(hooksFns).map(([key, entries]) => {
|
|
14
|
-
const fns = entries.map(([name, fn]) => tryCatch(name, fn));
|
|
15
|
-
const reducer = key in reducers ? reducers[key] : void 0;
|
|
16
|
-
if (reducer) return [key, reducer(fns)];
|
|
17
|
-
return [key, syncHooks.includes(key) ? callAll(...fns) : callAllAsync(...fns)];
|
|
18
|
-
}));
|
|
19
|
-
};
|
|
20
|
-
const createReducer = (reducer) => reducer;
|
|
21
|
-
const reducers = {
|
|
22
|
-
"config:resolved": createReducer((fns) => async (_args) => {
|
|
23
|
-
const args = Object.assign({}, _args);
|
|
24
|
-
const original = _args.config;
|
|
25
|
-
let config = args.config;
|
|
26
|
-
for (const hookFn of fns) {
|
|
27
|
-
const result = await hookFn(Object.assign(args, {
|
|
28
|
-
config,
|
|
29
|
-
original
|
|
30
|
-
}));
|
|
31
|
-
if (result !== void 0) config = result;
|
|
32
|
-
}
|
|
33
|
-
return config;
|
|
34
|
-
}),
|
|
35
|
-
"parser:before": createReducer((fns) => (_args) => {
|
|
36
|
-
const args = Object.assign({}, _args);
|
|
37
|
-
const original = _args.content;
|
|
38
|
-
let content = args.content;
|
|
39
|
-
for (const hookFn of fns) {
|
|
40
|
-
const result = hookFn(Object.assign(args, {
|
|
41
|
-
content,
|
|
42
|
-
original
|
|
43
|
-
}));
|
|
44
|
-
if (result !== void 0) content = result;
|
|
45
|
-
}
|
|
46
|
-
return content;
|
|
47
|
-
}),
|
|
48
|
-
"parser:preprocess": createReducer((fns) => (_args) => {
|
|
49
|
-
const args = Object.assign({}, _args);
|
|
50
|
-
const original = _args.data;
|
|
51
|
-
let data = args.data;
|
|
52
|
-
for (const hookFn of fns) {
|
|
53
|
-
const result = hookFn(Object.assign(args, {
|
|
54
|
-
data,
|
|
55
|
-
original
|
|
56
|
-
}));
|
|
57
|
-
if (result !== void 0) data = result;
|
|
58
|
-
}
|
|
59
|
-
return data;
|
|
60
|
-
}),
|
|
61
|
-
"cssgen:done": createReducer((fns) => (_args) => {
|
|
62
|
-
const args = Object.assign({}, _args);
|
|
63
|
-
const original = _args.content;
|
|
64
|
-
let content = args.content;
|
|
65
|
-
for (const hookFn of fns) {
|
|
66
|
-
const result = hookFn(Object.assign(args, {
|
|
67
|
-
content,
|
|
68
|
-
original
|
|
69
|
-
}));
|
|
70
|
-
if (result !== void 0) content = result;
|
|
71
|
-
}
|
|
72
|
-
return content;
|
|
73
|
-
}),
|
|
74
|
-
"codegen:prepare": createReducer((fns) => async (_args) => {
|
|
75
|
-
const args = Object.assign({}, _args);
|
|
76
|
-
const original = _args.artifacts;
|
|
77
|
-
let artifacts = args.artifacts;
|
|
78
|
-
for (const hookFn of fns) {
|
|
79
|
-
const result = await hookFn(Object.assign(args, {
|
|
80
|
-
artifacts,
|
|
81
|
-
original
|
|
82
|
-
}));
|
|
83
|
-
if (result) artifacts = result;
|
|
84
|
-
}
|
|
85
|
-
return artifacts;
|
|
86
|
-
}),
|
|
87
|
-
"preset:resolved": createReducer((fns) => async (_args) => {
|
|
88
|
-
const args = Object.assign({}, _args);
|
|
89
|
-
const original = _args.preset;
|
|
90
|
-
let preset = args.preset;
|
|
91
|
-
for (const hookFn of fns) {
|
|
92
|
-
const result = await hookFn(Object.assign(args, {
|
|
93
|
-
preset,
|
|
94
|
-
original
|
|
95
|
-
}));
|
|
96
|
-
if (result !== void 0) preset = result;
|
|
97
|
-
}
|
|
98
|
-
return preset;
|
|
99
|
-
}),
|
|
100
|
-
"css:optimize": createReducer((fns) => (_args) => {
|
|
101
|
-
const args = Object.assign({}, _args);
|
|
102
|
-
const original = _args.css;
|
|
103
|
-
let css = args.css;
|
|
104
|
-
for (const hookFn of fns) {
|
|
105
|
-
const result = hookFn(Object.assign(args, {
|
|
106
|
-
css,
|
|
107
|
-
original
|
|
108
|
-
}));
|
|
109
|
-
if (result !== void 0) css = result;
|
|
110
|
-
}
|
|
111
|
-
return css;
|
|
112
|
-
})
|
|
113
|
-
};
|
|
114
|
-
const syncHooks = [
|
|
115
|
-
"context:created",
|
|
116
|
-
"parser:before",
|
|
117
|
-
"parser:preprocess",
|
|
118
|
-
"parser:after",
|
|
119
|
-
"cssgen:done",
|
|
120
|
-
"css:optimize"
|
|
121
|
-
];
|
|
122
|
-
const callAllAsync = (...fns) => async (...a) => {
|
|
123
|
-
for (const fn of fns) await fn?.(...a);
|
|
124
|
-
};
|
|
125
|
-
const callAll = (...fns) => (...a) => {
|
|
126
|
-
fns.forEach((fn) => fn?.(...a));
|
|
127
|
-
};
|
|
128
|
-
const tryCatch = (name, fn) => {
|
|
129
|
-
return (...args) => {
|
|
130
|
-
try {
|
|
131
|
-
return fn(...args);
|
|
132
|
-
} catch (e) {
|
|
133
|
-
_bamboocss_logger.logger.caughtError("hooks", `Error in plugin "${name}"`, e);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
};
|
|
137
|
-
//#endregion
|
|
138
|
-
//#region src/validation/utils.ts
|
|
139
|
-
const REFERENCE_REGEX = /({([^}]*)})/g;
|
|
140
|
-
const curlyBracketRegex = /[{}]/g;
|
|
141
|
-
const isValidToken = (token) => (0, _bamboocss_shared.isObject)(token) && Object.hasOwnProperty.call(token, "value");
|
|
142
|
-
const isTokenReference = (value) => typeof value === "string" && REFERENCE_REGEX.test(value);
|
|
143
|
-
const formatPath = (path) => path;
|
|
144
|
-
function getReferences(value) {
|
|
145
|
-
if (typeof value !== "string") return [];
|
|
146
|
-
const matches = value.match(REFERENCE_REGEX);
|
|
147
|
-
if (!matches) return [];
|
|
148
|
-
return matches.map((match) => match.replace(curlyBracketRegex, "")).map((value) => {
|
|
149
|
-
return value.trim().split("/")[0];
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
const serializeTokenValue = (value) => {
|
|
153
|
-
if ((0, _bamboocss_shared.isString)(value)) return value;
|
|
154
|
-
if ((0, _bamboocss_shared.isObject)(value)) return Object.values(value).map((v) => serializeTokenValue(v)).join(" ");
|
|
155
|
-
if (Array.isArray(value)) return value.map((v) => serializeTokenValue(v)).join(" ");
|
|
156
|
-
return value.toString();
|
|
157
|
-
};
|
|
158
|
-
//#endregion
|
|
159
|
-
//#region src/merge-config.ts
|
|
160
|
-
/**
|
|
161
|
-
* Collect all `extend` properties into an array (to avoid mutation)
|
|
162
|
-
*/
|
|
163
|
-
function getExtends(items) {
|
|
164
|
-
return items.reduce((merged, { extend }) => {
|
|
165
|
-
if (!extend) return merged;
|
|
166
|
-
return (0, _bamboocss_shared.mergeWith)(merged, extend, (originalValue, newValue) => {
|
|
167
|
-
if (newValue === void 0) return originalValue ?? [];
|
|
168
|
-
if (originalValue === void 0) return [newValue];
|
|
169
|
-
if (Array.isArray(originalValue)) return [newValue, ...originalValue];
|
|
170
|
-
return [newValue, originalValue];
|
|
171
|
-
});
|
|
172
|
-
}, {});
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Separate the `extend` properties from the rest of the object
|
|
176
|
-
*/
|
|
177
|
-
function mergeRecords(records) {
|
|
178
|
-
return {
|
|
179
|
-
...records.reduce((acc, record) => (0, _bamboocss_shared.assign)(acc, record), {}),
|
|
180
|
-
extend: getExtends(records)
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Merge all `extend` properties into the rest of the object
|
|
185
|
-
*/
|
|
186
|
-
function mergeExtensions(records) {
|
|
187
|
-
const { extend = [], ...restProps } = mergeRecords(records);
|
|
188
|
-
return (0, _bamboocss_shared.mergeWith)(restProps, extend, (obj, extensions) => {
|
|
189
|
-
return (0, _bamboocss_shared.mergeAndConcat)({}, obj, ...extensions);
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
const isEmptyObject = (obj) => typeof obj === "object" && Object.keys(obj).length === 0;
|
|
193
|
-
const compact = (obj) => {
|
|
194
|
-
return Object.keys(obj).reduce((acc, key) => {
|
|
195
|
-
if (obj[key] !== void 0 && !isEmptyObject(obj[key])) acc[key] = obj[key];
|
|
196
|
-
return acc;
|
|
197
|
-
}, {});
|
|
198
|
-
};
|
|
199
|
-
const tokenKeys = [
|
|
200
|
-
"description",
|
|
201
|
-
"extensions",
|
|
202
|
-
"type",
|
|
203
|
-
"value",
|
|
204
|
-
"deprecated"
|
|
205
|
-
];
|
|
206
|
-
/**
|
|
207
|
-
* Merge all configs into a single config
|
|
208
|
-
*/
|
|
209
|
-
function mergeConfigs(configs) {
|
|
210
|
-
const userConfig = configs.at(-1);
|
|
211
|
-
const pluginHooks = userConfig.plugins ?? [];
|
|
212
|
-
if (userConfig.hooks) pluginHooks.push({
|
|
213
|
-
name: _bamboocss_shared.BAMBOO_CONFIG_NAME,
|
|
214
|
-
hooks: userConfig.hooks
|
|
215
|
-
});
|
|
216
|
-
const reversed = Array.from(configs).reverse();
|
|
217
|
-
const withoutEmpty = compact((0, _bamboocss_shared.assign)({
|
|
218
|
-
conditions: mergeExtensions(reversed.map((config) => config.conditions ?? {})),
|
|
219
|
-
theme: mergeExtensions(reversed.map((config) => config.theme ?? {})),
|
|
220
|
-
patterns: mergeExtensions(reversed.map((config) => config.patterns ?? {})),
|
|
221
|
-
utilities: mergeExtensions(reversed.map((config) => config.utilities ?? {})),
|
|
222
|
-
globalCss: mergeExtensions(reversed.map((config) => config.globalCss ?? {})),
|
|
223
|
-
globalVars: mergeExtensions(reversed.map((config) => config.globalVars ?? {})),
|
|
224
|
-
globalFontface: mergeExtensions(reversed.map((config) => config.globalFontface ?? {})),
|
|
225
|
-
globalPositionTry: mergeExtensions(reversed.map((config) => config.globalPositionTry ?? {})),
|
|
226
|
-
staticCss: mergeExtensions(reversed.map((config) => config.staticCss ?? {})),
|
|
227
|
-
themes: mergeExtensions(reversed.map((config) => config.themes ?? {})),
|
|
228
|
-
hooks: mergeHooks(pluginHooks)
|
|
229
|
-
}, ...reversed));
|
|
230
|
-
/**
|
|
231
|
-
* Properly merge tokens between flat/nested forms by setting the flat form as the default
|
|
232
|
-
* preset:
|
|
233
|
-
* ```
|
|
234
|
-
* tokens: {
|
|
235
|
-
* black: {
|
|
236
|
-
* value: "black"
|
|
237
|
-
* }
|
|
238
|
-
* }
|
|
239
|
-
* // color: "black"
|
|
240
|
-
* ```
|
|
241
|
-
*
|
|
242
|
-
* config:
|
|
243
|
-
* ```
|
|
244
|
-
* tokens: {
|
|
245
|
-
* black: {
|
|
246
|
-
* 0: { value: "black" },
|
|
247
|
-
* 10: { value: "black/10" },
|
|
248
|
-
* 20: { value: "black/20" },
|
|
249
|
-
* // ...
|
|
250
|
-
* }
|
|
251
|
-
* }
|
|
252
|
-
*
|
|
253
|
-
* // color: "black.20"
|
|
254
|
-
* ```
|
|
255
|
-
*/
|
|
256
|
-
if (withoutEmpty.theme?.tokens) (0, _bamboocss_shared.walkObject)(withoutEmpty.theme.tokens, (args) => args, { stop(token) {
|
|
257
|
-
if (!isValidToken(token)) return false;
|
|
258
|
-
if (Object.keys(token).filter((k) => !tokenKeys.includes(k)).length > 0) {
|
|
259
|
-
token.DEFAULT ||= {};
|
|
260
|
-
tokenKeys.forEach((key) => {
|
|
261
|
-
if (token[key] == null) return;
|
|
262
|
-
token.DEFAULT[key] ||= token[key];
|
|
263
|
-
delete token[key];
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
return true;
|
|
267
|
-
} });
|
|
268
|
-
return withoutEmpty;
|
|
269
|
-
}
|
|
270
|
-
//#endregion
|
|
271
|
-
Object.defineProperty(exports, "formatPath", {
|
|
272
|
-
enumerable: true,
|
|
273
|
-
get: function() {
|
|
274
|
-
return formatPath;
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
Object.defineProperty(exports, "getReferences", {
|
|
278
|
-
enumerable: true,
|
|
279
|
-
get: function() {
|
|
280
|
-
return getReferences;
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
Object.defineProperty(exports, "isTokenReference", {
|
|
284
|
-
enumerable: true,
|
|
285
|
-
get: function() {
|
|
286
|
-
return isTokenReference;
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
Object.defineProperty(exports, "isValidToken", {
|
|
290
|
-
enumerable: true,
|
|
291
|
-
get: function() {
|
|
292
|
-
return isValidToken;
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
Object.defineProperty(exports, "mergeConfigs", {
|
|
296
|
-
enumerable: true,
|
|
297
|
-
get: function() {
|
|
298
|
-
return mergeConfigs;
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
Object.defineProperty(exports, "mergeHooks", {
|
|
302
|
-
enumerable: true,
|
|
303
|
-
get: function() {
|
|
304
|
-
return mergeHooks;
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
Object.defineProperty(exports, "serializeTokenValue", {
|
|
308
|
-
enumerable: true,
|
|
309
|
-
get: function() {
|
|
310
|
-
return serializeTokenValue;
|
|
311
|
-
}
|
|
312
|
-
});
|