@salty-css/core 0.1.0-alpha.26 → 0.1.0-alpha.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +126 -0
- package/{class-name-generator-BIYysuhW.cjs → class-name-generator-DZcz_NT4.cjs} +1 -1
- package/{class-name-generator-B2LriwKm.js → class-name-generator-zQ8zLbPI.js} +1 -1
- package/compiler/resolve-import.d.ts +17 -0
- package/compiler/salty-compiler.cjs +104 -25
- package/compiler/salty-compiler.d.ts +1 -0
- package/compiler/salty-compiler.js +106 -26
- package/config/index.cjs +2 -0
- package/config/index.js +3 -1
- package/css/dynamic-styles.cjs +1 -1
- package/css/dynamic-styles.js +1 -1
- package/css/keyframes.cjs +1 -1
- package/css/keyframes.js +1 -1
- package/factories/define-import.d.ts +14 -0
- package/factories/index.cjs +16 -0
- package/factories/index.d.ts +1 -0
- package/factories/index.js +16 -0
- package/generators/index.cjs +1 -1
- package/generators/index.js +2 -2
- package/instances/classname-instance.cjs +1 -1
- package/instances/classname-instance.js +1 -1
- package/package.json +1 -1
- package/{parse-styles-jPtMfgXH.cjs → parse-styles-BFoV7HiL.cjs} +187 -6
- package/{parse-styles--vHKY6Mw.js → parse-styles-CtA-RKqt.js} +187 -6
- package/parsers/index.cjs +80 -3
- package/parsers/index.js +81 -4
- package/parsers/parse-templates.d.ts +10 -0
- package/parsers/resolve-template-variants.d.ts +21 -0
- package/runtime/index.cjs +1 -1
- package/runtime/index.js +1 -1
- package/types/config-types.d.ts +32 -1
package/config/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FontFactory, GlobalStylesFactory, VariablesFactory, defineFont, defineGlobalStyles, defineMediaQuery, defineVariables } from "../factories/index.js";
|
|
1
|
+
import { FontFactory, GlobalStylesFactory, ImportFactory, VariablesFactory, defineFont, defineGlobalStyles, defineImport, defineMediaQuery, defineVariables } from "../factories/index.js";
|
|
2
2
|
import { T, a, d } from "../define-templates-CVhhgPnd.js";
|
|
3
3
|
const defineConfig = (config) => {
|
|
4
4
|
return config;
|
|
@@ -6,12 +6,14 @@ const defineConfig = (config) => {
|
|
|
6
6
|
export {
|
|
7
7
|
FontFactory,
|
|
8
8
|
GlobalStylesFactory,
|
|
9
|
+
ImportFactory,
|
|
9
10
|
T as TemplateFactory,
|
|
10
11
|
a as TemplatesFactory,
|
|
11
12
|
VariablesFactory,
|
|
12
13
|
defineConfig,
|
|
13
14
|
defineFont,
|
|
14
15
|
defineGlobalStyles,
|
|
16
|
+
defineImport,
|
|
15
17
|
defineMediaQuery,
|
|
16
18
|
d as defineTemplates,
|
|
17
19
|
defineVariables
|
package/css/dynamic-styles.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const parseStyles = require("../parse-styles-
|
|
3
|
+
const parseStyles = require("../parse-styles-BFoV7HiL.cjs");
|
|
4
4
|
const toHash = require("../to-hash-C05Y906F.cjs");
|
|
5
5
|
const cache_resolveDynamicConfigCache = require("../cache/resolve-dynamic-config-cache.cjs");
|
|
6
6
|
const getDynamicStylesClassName = (styles) => {
|
package/css/dynamic-styles.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as parseStyles } from "../parse-styles
|
|
1
|
+
import { a as parseStyles } from "../parse-styles-CtA-RKqt.js";
|
|
2
2
|
import { t as toHash } from "../to-hash-DAN2LcHK.js";
|
|
3
3
|
import { resolveDynamicConfigCache } from "../cache/resolve-dynamic-config-cache.js";
|
|
4
4
|
const getDynamicStylesClassName = (styles) => {
|
package/css/keyframes.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const parseStyles = require("../parse-styles-
|
|
3
|
+
const parseStyles = require("../parse-styles-BFoV7HiL.cjs");
|
|
4
4
|
const toHash = require("../to-hash-C05Y906F.cjs");
|
|
5
5
|
const keyframes = ({ animationName: _name, params: _params, appendInitialStyles, ...keyframes2 }) => {
|
|
6
6
|
const modifyKeyframes = async (params = {}) => {
|
package/css/keyframes.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { p as parseAndJoinStyles } from "../parse-styles
|
|
1
|
+
import { p as parseAndJoinStyles } from "../parse-styles-CtA-RKqt.js";
|
|
2
2
|
import { t as toHash } from "../to-hash-DAN2LcHK.js";
|
|
3
3
|
const keyframes = ({ animationName: _name, params: _params, appendInitialStyles, ...keyframes2 }) => {
|
|
4
4
|
const modifyKeyframes = async (params = {}) => {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ImportSpecOptions {
|
|
2
|
+
url: string;
|
|
3
|
+
media?: string;
|
|
4
|
+
supports?: string;
|
|
5
|
+
}
|
|
6
|
+
export type ImportSpec = string | ImportSpecOptions;
|
|
7
|
+
export declare class ImportFactory {
|
|
8
|
+
_current: ImportSpec[];
|
|
9
|
+
_path?: string;
|
|
10
|
+
constructor(_current: ImportSpec[]);
|
|
11
|
+
get isDefineImport(): boolean;
|
|
12
|
+
_setPath(path: string): this;
|
|
13
|
+
}
|
|
14
|
+
export declare const defineImport: (...specs: ImportSpec[]) => ImportFactory;
|
package/factories/index.cjs
CHANGED
|
@@ -136,6 +136,20 @@ class GlobalStylesFactory {
|
|
|
136
136
|
const defineGlobalStyles = (styles) => {
|
|
137
137
|
return new GlobalStylesFactory(styles);
|
|
138
138
|
};
|
|
139
|
+
class ImportFactory {
|
|
140
|
+
constructor(_current) {
|
|
141
|
+
__publicField(this, "_path");
|
|
142
|
+
this._current = _current;
|
|
143
|
+
}
|
|
144
|
+
get isDefineImport() {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
_setPath(path) {
|
|
148
|
+
this._path = path;
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const defineImport = (...specs) => new ImportFactory(specs);
|
|
139
153
|
const defineMediaQuery = (mediaFactory) => {
|
|
140
154
|
return mediaFactory(css_media.media);
|
|
141
155
|
};
|
|
@@ -155,8 +169,10 @@ exports.TemplatesFactory = defineTemplates.TemplatesFactory;
|
|
|
155
169
|
exports.defineTemplates = defineTemplates.defineTemplates;
|
|
156
170
|
exports.FontFactory = FontFactory;
|
|
157
171
|
exports.GlobalStylesFactory = GlobalStylesFactory;
|
|
172
|
+
exports.ImportFactory = ImportFactory;
|
|
158
173
|
exports.VariablesFactory = VariablesFactory;
|
|
159
174
|
exports.defineFont = defineFont;
|
|
160
175
|
exports.defineGlobalStyles = defineGlobalStyles;
|
|
176
|
+
exports.defineImport = defineImport;
|
|
161
177
|
exports.defineMediaQuery = defineMediaQuery;
|
|
162
178
|
exports.defineVariables = defineVariables;
|
package/factories/index.d.ts
CHANGED
package/factories/index.js
CHANGED
|
@@ -134,6 +134,20 @@ class GlobalStylesFactory {
|
|
|
134
134
|
const defineGlobalStyles = (styles) => {
|
|
135
135
|
return new GlobalStylesFactory(styles);
|
|
136
136
|
};
|
|
137
|
+
class ImportFactory {
|
|
138
|
+
constructor(_current) {
|
|
139
|
+
__publicField(this, "_path");
|
|
140
|
+
this._current = _current;
|
|
141
|
+
}
|
|
142
|
+
get isDefineImport() {
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
_setPath(path) {
|
|
146
|
+
this._path = path;
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const defineImport = (...specs) => new ImportFactory(specs);
|
|
137
151
|
const defineMediaQuery = (mediaFactory) => {
|
|
138
152
|
return mediaFactory(media);
|
|
139
153
|
};
|
|
@@ -151,11 +165,13 @@ const defineVariables = (variables) => {
|
|
|
151
165
|
export {
|
|
152
166
|
FontFactory,
|
|
153
167
|
GlobalStylesFactory,
|
|
168
|
+
ImportFactory,
|
|
154
169
|
T as TemplateFactory,
|
|
155
170
|
a as TemplatesFactory,
|
|
156
171
|
VariablesFactory,
|
|
157
172
|
defineFont,
|
|
158
173
|
defineGlobalStyles,
|
|
174
|
+
defineImport,
|
|
159
175
|
defineMediaQuery,
|
|
160
176
|
d as defineTemplates,
|
|
161
177
|
defineVariables
|
package/generators/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const classNameGenerator = require("../class-name-generator-
|
|
3
|
+
const classNameGenerator = require("../class-name-generator-DZcz_NT4.cjs");
|
|
4
4
|
const dashCase = require("../dash-case-DIwKaYgE.cjs");
|
|
5
5
|
class StyledGenerator extends classNameGenerator.StylesGenerator {
|
|
6
6
|
constructor(tagName, _params) {
|
package/generators/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as StylesGenerator } from "../class-name-generator-
|
|
2
|
-
import { C } from "../class-name-generator-
|
|
1
|
+
import { S as StylesGenerator } from "../class-name-generator-zQ8zLbPI.js";
|
|
2
|
+
import { C } from "../class-name-generator-zQ8zLbPI.js";
|
|
3
3
|
import { d as dashCase } from "../dash-case-DblXvymC.js";
|
|
4
4
|
class StyledGenerator extends StylesGenerator {
|
|
5
5
|
constructor(tagName, _params) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const classNameGenerator = require("../class-name-generator-
|
|
3
|
+
const classNameGenerator = require("../class-name-generator-DZcz_NT4.cjs");
|
|
4
4
|
const classNameInstance = (params) => {
|
|
5
5
|
const generator = new classNameGenerator.ClassNameGenerator(params);
|
|
6
6
|
const createClass = (classNameStr) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ClassNameGenerator } from "../class-name-generator-
|
|
1
|
+
import { C as ClassNameGenerator } from "../class-name-generator-zQ8zLbPI.js";
|
|
2
2
|
const classNameInstance = (params) => {
|
|
3
3
|
const generator = new ClassNameGenerator(params);
|
|
4
4
|
const createClass = (classNameStr) => {
|
package/package.json
CHANGED
|
@@ -94,6 +94,170 @@ const reportParserIssue = (strict, message) => {
|
|
|
94
94
|
const pseudoTypoRegex = /^&(hover|focus(-(visible|within))?|active|visited|checked|disabled|enabled|empty|target|first-child|last-child|first-of-type|last-of-type|placeholder|placeholder-shown|root)\b/;
|
|
95
95
|
const templateLiteralLeftoverRegex = /\$\{[^}]+\}/;
|
|
96
96
|
const bareAtRuleRegex = /^@(media|supports|container|layer)\s*$/;
|
|
97
|
+
const isRichTemplateNode = (node) => {
|
|
98
|
+
if (!node || typeof node !== "object") return false;
|
|
99
|
+
if (Array.isArray(node)) return false;
|
|
100
|
+
const keys = Object.keys(node);
|
|
101
|
+
return keys.includes("base") || keys.includes("variants");
|
|
102
|
+
};
|
|
103
|
+
const parseTemplateCallSite = (value) => {
|
|
104
|
+
if (typeof value === "string") {
|
|
105
|
+
const [rawPath, rawQuery] = value.split("@", 2);
|
|
106
|
+
const path = rawPath.split(".").filter(Boolean);
|
|
107
|
+
if (!path.length) return void 0;
|
|
108
|
+
const variants = {};
|
|
109
|
+
if (rawQuery) {
|
|
110
|
+
for (const segment of rawQuery.split("&")) {
|
|
111
|
+
if (!segment) continue;
|
|
112
|
+
const eq = segment.indexOf("=");
|
|
113
|
+
if (eq === -1) {
|
|
114
|
+
variants[segment.trim()] = true;
|
|
115
|
+
} else {
|
|
116
|
+
const axis = segment.slice(0, eq).trim();
|
|
117
|
+
const raw = segment.slice(eq + 1).trim();
|
|
118
|
+
if (!axis) continue;
|
|
119
|
+
if (raw === "true") variants[axis] = true;
|
|
120
|
+
else if (raw === "false") variants[axis] = false;
|
|
121
|
+
else variants[axis] = raw;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return { path, variants };
|
|
126
|
+
}
|
|
127
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
128
|
+
const obj = value;
|
|
129
|
+
const name = obj["name"];
|
|
130
|
+
if (typeof name !== "string") return void 0;
|
|
131
|
+
const path = name.split(".").filter(Boolean);
|
|
132
|
+
if (!path.length) return void 0;
|
|
133
|
+
const variants = {};
|
|
134
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
135
|
+
if (k === "name") continue;
|
|
136
|
+
if (typeof v === "string" || typeof v === "boolean") variants[k] = v;
|
|
137
|
+
}
|
|
138
|
+
return { path, variants };
|
|
139
|
+
}
|
|
140
|
+
return void 0;
|
|
141
|
+
};
|
|
142
|
+
const normalizeAxisValue = (v) => {
|
|
143
|
+
if (v === void 0) return void 0;
|
|
144
|
+
return typeof v === "boolean" ? String(v) : v;
|
|
145
|
+
};
|
|
146
|
+
const buildPathStack = (root, path) => {
|
|
147
|
+
const stack = [{ node: root, isRich: isRichTemplateNode(root) }];
|
|
148
|
+
let cursor = root;
|
|
149
|
+
for (const segment of path) {
|
|
150
|
+
if (cursor == null || typeof cursor !== "object") return void 0;
|
|
151
|
+
const next = cursor[segment];
|
|
152
|
+
if (next === void 0) return void 0;
|
|
153
|
+
stack.push({ node: next, isRich: isRichTemplateNode(next) });
|
|
154
|
+
cursor = next;
|
|
155
|
+
}
|
|
156
|
+
return stack;
|
|
157
|
+
};
|
|
158
|
+
const pathHasRichNode = (root, path) => {
|
|
159
|
+
const stack = buildPathStack(root, path);
|
|
160
|
+
if (!stack) return false;
|
|
161
|
+
return stack.some((entry) => entry.isRich);
|
|
162
|
+
};
|
|
163
|
+
const matchesAll = (entry, effective) => {
|
|
164
|
+
for (const [axis, raw] of Object.entries(entry)) {
|
|
165
|
+
if (axis === "css") continue;
|
|
166
|
+
if (effective[axis] !== normalizeAxisValue(raw)) return false;
|
|
167
|
+
}
|
|
168
|
+
return true;
|
|
169
|
+
};
|
|
170
|
+
const matchesAny = (entry, effective) => {
|
|
171
|
+
let any = false;
|
|
172
|
+
for (const [axis, raw] of Object.entries(entry)) {
|
|
173
|
+
if (axis === "css") continue;
|
|
174
|
+
any = true;
|
|
175
|
+
if (effective[axis] === normalizeAxisValue(raw)) return true;
|
|
176
|
+
}
|
|
177
|
+
return !any;
|
|
178
|
+
};
|
|
179
|
+
const resolveRichTemplate = (root, path, callSiteVariants, templateName) => {
|
|
180
|
+
var _a, _b, _c, _d;
|
|
181
|
+
const stack = buildPathStack(root, path);
|
|
182
|
+
if (!stack) return void 0;
|
|
183
|
+
const rich = stack.map((entry) => {
|
|
184
|
+
if (entry.isRich) return entry.node;
|
|
185
|
+
if (entry.node && typeof entry.node === "object" && !Array.isArray(entry.node)) {
|
|
186
|
+
const onlyChildKeys = Object.keys(entry.node).every((k) => entry.node[k] && typeof entry.node[k] === "object" && !isRichTemplateNode(entry.node[k]));
|
|
187
|
+
return onlyChildKeys ? {} : { base: entry.node };
|
|
188
|
+
}
|
|
189
|
+
return {};
|
|
190
|
+
});
|
|
191
|
+
const declaredAxes = /* @__PURE__ */ new Set();
|
|
192
|
+
for (const r of rich) {
|
|
193
|
+
if (r.variants) for (const k of Object.keys(r.variants)) declaredAxes.add(k);
|
|
194
|
+
}
|
|
195
|
+
for (const r of rich) {
|
|
196
|
+
if (r.defaultVariants) for (const k of Object.keys(r.defaultVariants)) declaredAxes.add(k);
|
|
197
|
+
}
|
|
198
|
+
const effective = {};
|
|
199
|
+
for (const axis of declaredAxes) {
|
|
200
|
+
if (axis in callSiteVariants) {
|
|
201
|
+
effective[axis] = normalizeAxisValue(callSiteVariants[axis]);
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
for (let i = rich.length - 1; i >= 0; i--) {
|
|
205
|
+
const d = (_a = rich[i].defaultVariants) == null ? void 0 : _a[axis];
|
|
206
|
+
if (d !== void 0) {
|
|
207
|
+
effective[axis] = normalizeAxisValue(d);
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
for (const [axis, raw] of Object.entries(callSiteVariants)) {
|
|
213
|
+
if (!declaredAxes.has(axis)) {
|
|
214
|
+
console.warn(`Template "${templateName}" path "${path.join(".")}" has no variant axis "${axis}"; ignored.`);
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
const wanted = normalizeAxisValue(raw);
|
|
218
|
+
let found = false;
|
|
219
|
+
for (const r of rich) {
|
|
220
|
+
if (((_b = r.variants) == null ? void 0 : _b[axis]) && wanted !== void 0 && wanted in r.variants[axis]) {
|
|
221
|
+
found = true;
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (!found && wanted !== void 0) {
|
|
226
|
+
const anyBundle = rich.some((r) => r.variants && axis in r.variants);
|
|
227
|
+
if (anyBundle) {
|
|
228
|
+
console.warn(`Template "${templateName}" axis "${axis}" has no value "${wanted}" on path "${path.join(".")}"; ignored.`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const acc = {};
|
|
233
|
+
for (const r of rich) {
|
|
234
|
+
if (r.base) Object.assign(acc, r.base);
|
|
235
|
+
}
|
|
236
|
+
for (const axis of Object.keys(effective)) {
|
|
237
|
+
const value = effective[axis];
|
|
238
|
+
if (value === void 0) continue;
|
|
239
|
+
for (let i = rich.length - 1; i >= 0; i--) {
|
|
240
|
+
const bundle = (_d = (_c = rich[i].variants) == null ? void 0 : _c[axis]) == null ? void 0 : _d[value];
|
|
241
|
+
if (bundle) {
|
|
242
|
+
Object.assign(acc, bundle);
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
for (const r of rich) {
|
|
248
|
+
if (r.compoundVariants) {
|
|
249
|
+
for (const entry of r.compoundVariants) {
|
|
250
|
+
if (matchesAll(entry, effective) && entry.css) Object.assign(acc, entry.css);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (r.anyOfVariants) {
|
|
254
|
+
for (const entry of r.anyOfVariants) {
|
|
255
|
+
if (matchesAny(entry, effective) && entry.css) Object.assign(acc, entry.css);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return acc;
|
|
260
|
+
};
|
|
97
261
|
const parseStyles = async (styles, currentScope = "", config, omitTemplates = false) => {
|
|
98
262
|
if (!styles) throw new Error("No styles provided to parseStyles function!");
|
|
99
263
|
const cssStyles = /* @__PURE__ */ new Set();
|
|
@@ -137,13 +301,29 @@ const parseStyles = async (styles, currentScope = "", config, omitTemplates = fa
|
|
|
137
301
|
}
|
|
138
302
|
if ((config == null ? void 0 : config.templates) && config.templates[_key]) {
|
|
139
303
|
if (omitTemplates) return void 0;
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
if (
|
|
143
|
-
const
|
|
144
|
-
|
|
304
|
+
const root = config.templates[_key];
|
|
305
|
+
const callSite = parseTemplateCallSite(value);
|
|
306
|
+
if (callSite) {
|
|
307
|
+
const { path, variants } = callSite;
|
|
308
|
+
const hasCallSiteVariants = Object.keys(variants).length > 0;
|
|
309
|
+
if (hasCallSiteVariants || pathHasRichNode(root, path)) {
|
|
310
|
+
const resolved2 = resolveRichTemplate(root, path, variants, _key);
|
|
311
|
+
if (resolved2) {
|
|
312
|
+
const [result] = await parseStyles(resolved2, "");
|
|
313
|
+
return result;
|
|
314
|
+
}
|
|
315
|
+
console.warn(`Template "${_key}" with path of "${path.join(".")}" was not found in config!`);
|
|
316
|
+
return void 0;
|
|
317
|
+
}
|
|
318
|
+
const templateStyles = path.reduce((acc, key2) => acc == null ? void 0 : acc[key2], root);
|
|
319
|
+
if (templateStyles) {
|
|
320
|
+
const [result] = await parseStyles(templateStyles, "");
|
|
321
|
+
return result;
|
|
322
|
+
}
|
|
323
|
+
console.warn(`Template "${_key}" with path of "${path.join(".")}" was not found in config!`);
|
|
324
|
+
return void 0;
|
|
145
325
|
}
|
|
146
|
-
console.warn(`Template "${_key}"
|
|
326
|
+
console.warn(`Template "${_key}" received an unsupported call-site value.`);
|
|
147
327
|
return void 0;
|
|
148
328
|
}
|
|
149
329
|
const isVariantArrayKey = _key === "compoundVariants" || _key === "anyOfVariants";
|
|
@@ -323,6 +503,7 @@ const combineSelectors = (currentScope, key) => {
|
|
|
323
503
|
}
|
|
324
504
|
return combos.join(", ");
|
|
325
505
|
};
|
|
506
|
+
exports.isRichTemplateNode = isRichTemplateNode;
|
|
326
507
|
exports.parseAndJoinStyles = parseAndJoinStyles;
|
|
327
508
|
exports.parseStyles = parseStyles;
|
|
328
509
|
exports.parseValueModifiers = parseValueModifiers;
|
|
@@ -93,6 +93,170 @@ const reportParserIssue = (strict, message) => {
|
|
|
93
93
|
const pseudoTypoRegex = /^&(hover|focus(-(visible|within))?|active|visited|checked|disabled|enabled|empty|target|first-child|last-child|first-of-type|last-of-type|placeholder|placeholder-shown|root)\b/;
|
|
94
94
|
const templateLiteralLeftoverRegex = /\$\{[^}]+\}/;
|
|
95
95
|
const bareAtRuleRegex = /^@(media|supports|container|layer)\s*$/;
|
|
96
|
+
const isRichTemplateNode = (node) => {
|
|
97
|
+
if (!node || typeof node !== "object") return false;
|
|
98
|
+
if (Array.isArray(node)) return false;
|
|
99
|
+
const keys = Object.keys(node);
|
|
100
|
+
return keys.includes("base") || keys.includes("variants");
|
|
101
|
+
};
|
|
102
|
+
const parseTemplateCallSite = (value) => {
|
|
103
|
+
if (typeof value === "string") {
|
|
104
|
+
const [rawPath, rawQuery] = value.split("@", 2);
|
|
105
|
+
const path = rawPath.split(".").filter(Boolean);
|
|
106
|
+
if (!path.length) return void 0;
|
|
107
|
+
const variants = {};
|
|
108
|
+
if (rawQuery) {
|
|
109
|
+
for (const segment of rawQuery.split("&")) {
|
|
110
|
+
if (!segment) continue;
|
|
111
|
+
const eq = segment.indexOf("=");
|
|
112
|
+
if (eq === -1) {
|
|
113
|
+
variants[segment.trim()] = true;
|
|
114
|
+
} else {
|
|
115
|
+
const axis = segment.slice(0, eq).trim();
|
|
116
|
+
const raw = segment.slice(eq + 1).trim();
|
|
117
|
+
if (!axis) continue;
|
|
118
|
+
if (raw === "true") variants[axis] = true;
|
|
119
|
+
else if (raw === "false") variants[axis] = false;
|
|
120
|
+
else variants[axis] = raw;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return { path, variants };
|
|
125
|
+
}
|
|
126
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
127
|
+
const obj = value;
|
|
128
|
+
const name = obj["name"];
|
|
129
|
+
if (typeof name !== "string") return void 0;
|
|
130
|
+
const path = name.split(".").filter(Boolean);
|
|
131
|
+
if (!path.length) return void 0;
|
|
132
|
+
const variants = {};
|
|
133
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
134
|
+
if (k === "name") continue;
|
|
135
|
+
if (typeof v === "string" || typeof v === "boolean") variants[k] = v;
|
|
136
|
+
}
|
|
137
|
+
return { path, variants };
|
|
138
|
+
}
|
|
139
|
+
return void 0;
|
|
140
|
+
};
|
|
141
|
+
const normalizeAxisValue = (v) => {
|
|
142
|
+
if (v === void 0) return void 0;
|
|
143
|
+
return typeof v === "boolean" ? String(v) : v;
|
|
144
|
+
};
|
|
145
|
+
const buildPathStack = (root, path) => {
|
|
146
|
+
const stack = [{ node: root, isRich: isRichTemplateNode(root) }];
|
|
147
|
+
let cursor = root;
|
|
148
|
+
for (const segment of path) {
|
|
149
|
+
if (cursor == null || typeof cursor !== "object") return void 0;
|
|
150
|
+
const next = cursor[segment];
|
|
151
|
+
if (next === void 0) return void 0;
|
|
152
|
+
stack.push({ node: next, isRich: isRichTemplateNode(next) });
|
|
153
|
+
cursor = next;
|
|
154
|
+
}
|
|
155
|
+
return stack;
|
|
156
|
+
};
|
|
157
|
+
const pathHasRichNode = (root, path) => {
|
|
158
|
+
const stack = buildPathStack(root, path);
|
|
159
|
+
if (!stack) return false;
|
|
160
|
+
return stack.some((entry) => entry.isRich);
|
|
161
|
+
};
|
|
162
|
+
const matchesAll = (entry, effective) => {
|
|
163
|
+
for (const [axis, raw] of Object.entries(entry)) {
|
|
164
|
+
if (axis === "css") continue;
|
|
165
|
+
if (effective[axis] !== normalizeAxisValue(raw)) return false;
|
|
166
|
+
}
|
|
167
|
+
return true;
|
|
168
|
+
};
|
|
169
|
+
const matchesAny = (entry, effective) => {
|
|
170
|
+
let any = false;
|
|
171
|
+
for (const [axis, raw] of Object.entries(entry)) {
|
|
172
|
+
if (axis === "css") continue;
|
|
173
|
+
any = true;
|
|
174
|
+
if (effective[axis] === normalizeAxisValue(raw)) return true;
|
|
175
|
+
}
|
|
176
|
+
return !any;
|
|
177
|
+
};
|
|
178
|
+
const resolveRichTemplate = (root, path, callSiteVariants, templateName) => {
|
|
179
|
+
var _a, _b, _c, _d;
|
|
180
|
+
const stack = buildPathStack(root, path);
|
|
181
|
+
if (!stack) return void 0;
|
|
182
|
+
const rich = stack.map((entry) => {
|
|
183
|
+
if (entry.isRich) return entry.node;
|
|
184
|
+
if (entry.node && typeof entry.node === "object" && !Array.isArray(entry.node)) {
|
|
185
|
+
const onlyChildKeys = Object.keys(entry.node).every((k) => entry.node[k] && typeof entry.node[k] === "object" && !isRichTemplateNode(entry.node[k]));
|
|
186
|
+
return onlyChildKeys ? {} : { base: entry.node };
|
|
187
|
+
}
|
|
188
|
+
return {};
|
|
189
|
+
});
|
|
190
|
+
const declaredAxes = /* @__PURE__ */ new Set();
|
|
191
|
+
for (const r of rich) {
|
|
192
|
+
if (r.variants) for (const k of Object.keys(r.variants)) declaredAxes.add(k);
|
|
193
|
+
}
|
|
194
|
+
for (const r of rich) {
|
|
195
|
+
if (r.defaultVariants) for (const k of Object.keys(r.defaultVariants)) declaredAxes.add(k);
|
|
196
|
+
}
|
|
197
|
+
const effective = {};
|
|
198
|
+
for (const axis of declaredAxes) {
|
|
199
|
+
if (axis in callSiteVariants) {
|
|
200
|
+
effective[axis] = normalizeAxisValue(callSiteVariants[axis]);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
for (let i = rich.length - 1; i >= 0; i--) {
|
|
204
|
+
const d = (_a = rich[i].defaultVariants) == null ? void 0 : _a[axis];
|
|
205
|
+
if (d !== void 0) {
|
|
206
|
+
effective[axis] = normalizeAxisValue(d);
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
for (const [axis, raw] of Object.entries(callSiteVariants)) {
|
|
212
|
+
if (!declaredAxes.has(axis)) {
|
|
213
|
+
console.warn(`Template "${templateName}" path "${path.join(".")}" has no variant axis "${axis}"; ignored.`);
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
const wanted = normalizeAxisValue(raw);
|
|
217
|
+
let found = false;
|
|
218
|
+
for (const r of rich) {
|
|
219
|
+
if (((_b = r.variants) == null ? void 0 : _b[axis]) && wanted !== void 0 && wanted in r.variants[axis]) {
|
|
220
|
+
found = true;
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (!found && wanted !== void 0) {
|
|
225
|
+
const anyBundle = rich.some((r) => r.variants && axis in r.variants);
|
|
226
|
+
if (anyBundle) {
|
|
227
|
+
console.warn(`Template "${templateName}" axis "${axis}" has no value "${wanted}" on path "${path.join(".")}"; ignored.`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const acc = {};
|
|
232
|
+
for (const r of rich) {
|
|
233
|
+
if (r.base) Object.assign(acc, r.base);
|
|
234
|
+
}
|
|
235
|
+
for (const axis of Object.keys(effective)) {
|
|
236
|
+
const value = effective[axis];
|
|
237
|
+
if (value === void 0) continue;
|
|
238
|
+
for (let i = rich.length - 1; i >= 0; i--) {
|
|
239
|
+
const bundle = (_d = (_c = rich[i].variants) == null ? void 0 : _c[axis]) == null ? void 0 : _d[value];
|
|
240
|
+
if (bundle) {
|
|
241
|
+
Object.assign(acc, bundle);
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
for (const r of rich) {
|
|
247
|
+
if (r.compoundVariants) {
|
|
248
|
+
for (const entry of r.compoundVariants) {
|
|
249
|
+
if (matchesAll(entry, effective) && entry.css) Object.assign(acc, entry.css);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (r.anyOfVariants) {
|
|
253
|
+
for (const entry of r.anyOfVariants) {
|
|
254
|
+
if (matchesAny(entry, effective) && entry.css) Object.assign(acc, entry.css);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return acc;
|
|
259
|
+
};
|
|
96
260
|
const parseStyles = async (styles, currentScope = "", config, omitTemplates = false) => {
|
|
97
261
|
if (!styles) throw new Error("No styles provided to parseStyles function!");
|
|
98
262
|
const cssStyles = /* @__PURE__ */ new Set();
|
|
@@ -136,13 +300,29 @@ const parseStyles = async (styles, currentScope = "", config, omitTemplates = fa
|
|
|
136
300
|
}
|
|
137
301
|
if ((config == null ? void 0 : config.templates) && config.templates[_key]) {
|
|
138
302
|
if (omitTemplates) return void 0;
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
if (
|
|
142
|
-
const
|
|
143
|
-
|
|
303
|
+
const root = config.templates[_key];
|
|
304
|
+
const callSite = parseTemplateCallSite(value);
|
|
305
|
+
if (callSite) {
|
|
306
|
+
const { path, variants } = callSite;
|
|
307
|
+
const hasCallSiteVariants = Object.keys(variants).length > 0;
|
|
308
|
+
if (hasCallSiteVariants || pathHasRichNode(root, path)) {
|
|
309
|
+
const resolved2 = resolveRichTemplate(root, path, variants, _key);
|
|
310
|
+
if (resolved2) {
|
|
311
|
+
const [result] = await parseStyles(resolved2, "");
|
|
312
|
+
return result;
|
|
313
|
+
}
|
|
314
|
+
console.warn(`Template "${_key}" with path of "${path.join(".")}" was not found in config!`);
|
|
315
|
+
return void 0;
|
|
316
|
+
}
|
|
317
|
+
const templateStyles = path.reduce((acc, key2) => acc == null ? void 0 : acc[key2], root);
|
|
318
|
+
if (templateStyles) {
|
|
319
|
+
const [result] = await parseStyles(templateStyles, "");
|
|
320
|
+
return result;
|
|
321
|
+
}
|
|
322
|
+
console.warn(`Template "${_key}" with path of "${path.join(".")}" was not found in config!`);
|
|
323
|
+
return void 0;
|
|
144
324
|
}
|
|
145
|
-
console.warn(`Template "${_key}"
|
|
325
|
+
console.warn(`Template "${_key}" received an unsupported call-site value.`);
|
|
146
326
|
return void 0;
|
|
147
327
|
}
|
|
148
328
|
const isVariantArrayKey = _key === "compoundVariants" || _key === "anyOfVariants";
|
|
@@ -327,6 +507,7 @@ export {
|
|
|
327
507
|
parseVariableTokens as b,
|
|
328
508
|
parseValueModifiers as c,
|
|
329
509
|
parseValueTokens as d,
|
|
510
|
+
isRichTemplateNode as i,
|
|
330
511
|
parseAndJoinStyles as p,
|
|
331
512
|
reportParserIssue as r
|
|
332
513
|
};
|