@pandacss/generator 1.10.0 → 1.11.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/index.js +89 -13
- package/dist/index.mjs +89 -13
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -45,6 +45,15 @@ var import_outdent48 = __toESM(require("outdent"));
|
|
|
45
45
|
|
|
46
46
|
// src/artifacts/js/conditions.ts
|
|
47
47
|
var import_outdent = __toESM(require("outdent"));
|
|
48
|
+
function formatConditionJsDoc(raw) {
|
|
49
|
+
if (!raw) return "";
|
|
50
|
+
if (typeof raw === "string") return `/** \`${raw}\` */
|
|
51
|
+
`;
|
|
52
|
+
if (Array.isArray(raw)) return `/** \`${raw.join(" ")}\` */
|
|
53
|
+
`;
|
|
54
|
+
return `/** Multi-block condition */
|
|
55
|
+
`;
|
|
56
|
+
}
|
|
48
57
|
function generateConditions(ctx) {
|
|
49
58
|
const keys = Object.keys(ctx.conditions.values).concat("base");
|
|
50
59
|
return {
|
|
@@ -92,8 +101,7 @@ function generateConditions(ctx) {
|
|
|
92
101
|
export interface Conditions {
|
|
93
102
|
${keys.map(
|
|
94
103
|
(key) => ` ${key === "base" ? `/** The base (=no conditions) styles to apply */
|
|
95
|
-
` : ctx.conditions.get(key)
|
|
96
|
-
` : ""} ${JSON.stringify(key)}: string`
|
|
104
|
+
` : formatConditionJsDoc(ctx.conditions.get(key))} ${JSON.stringify(key)}: string`
|
|
97
105
|
).join("\n")}
|
|
98
106
|
}
|
|
99
107
|
|
|
@@ -253,7 +261,26 @@ function generateStringLiteralCssFn(ctx) {
|
|
|
253
261
|
const { separator } = utility;
|
|
254
262
|
return {
|
|
255
263
|
dts: import_outdent4.outdent`
|
|
256
|
-
|
|
264
|
+
${ctx.file.importType("SystemStyleObject", "../types/index")}
|
|
265
|
+
|
|
266
|
+
type Styles =
|
|
267
|
+
| { raw: readonly string[] | ArrayLike<string> }
|
|
268
|
+
| SystemStyleObject
|
|
269
|
+
| boolean
|
|
270
|
+
| null
|
|
271
|
+
| undefined
|
|
272
|
+
|
|
273
|
+
interface CssRawFunction {
|
|
274
|
+
(...styles: Styles[]): SystemStyleObject
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
interface CssFunction {
|
|
278
|
+
(...styles: Styles[]): string
|
|
279
|
+
|
|
280
|
+
raw: CssRawFunction
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export declare const css: CssFunction;
|
|
257
284
|
`,
|
|
258
285
|
js: import_outdent4.outdent`
|
|
259
286
|
${ctx.file.import("astish, createCss, isObject, mergeProps, withoutSpace", "../helpers")}
|
|
@@ -5043,16 +5070,51 @@ function stringifyVars(options) {
|
|
|
5043
5070
|
const keys = conditionKey.split(":");
|
|
5044
5071
|
if (keys.some((key) => !conditions.get(key))) return;
|
|
5045
5072
|
const css = (0, import_core2.stringify)(varsObj);
|
|
5046
|
-
const
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5073
|
+
const altsPerKey = keys.map((key) => getSelectorPaths(conditions.get(key)));
|
|
5074
|
+
if (altsPerKey.some((alts) => alts.length === 0)) return;
|
|
5075
|
+
let combos = [[]];
|
|
5076
|
+
for (const alts of altsPerKey) {
|
|
5077
|
+
const next = [];
|
|
5078
|
+
for (const partial of combos) {
|
|
5079
|
+
for (const alt of alts) {
|
|
5080
|
+
next.push([...partial, ...alt]);
|
|
5081
|
+
}
|
|
5082
|
+
}
|
|
5083
|
+
combos = next;
|
|
5084
|
+
}
|
|
5085
|
+
const rules = combos.map((segments) => {
|
|
5086
|
+
const transformed = segments.map(transformSegment).filter(Boolean);
|
|
5087
|
+
const rule = getDeepestRule(root, transformed);
|
|
5088
|
+
if (!rule) return;
|
|
5089
|
+
getDeepestNode(rule)?.append(css);
|
|
5090
|
+
return (0, import_core2.expandNestedCss)(rule.toString());
|
|
5051
5091
|
}).filter(Boolean);
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5092
|
+
return rules.length ? rules.join("\n\n") : void 0;
|
|
5093
|
+
}
|
|
5094
|
+
function getSelectorPaths(condition) {
|
|
5095
|
+
if (condition == null) return [];
|
|
5096
|
+
if (typeof condition === "string") return [[condition]];
|
|
5097
|
+
if (Array.isArray(condition)) {
|
|
5098
|
+
const last = condition.at(-1);
|
|
5099
|
+
return last ? [[last]] : [];
|
|
5100
|
+
}
|
|
5101
|
+
const paths = [];
|
|
5102
|
+
const walk = (node, path) => {
|
|
5103
|
+
for (const [key, value] of Object.entries(node)) {
|
|
5104
|
+
if (value === "@slot") {
|
|
5105
|
+
paths.push([...path, key]);
|
|
5106
|
+
} else if (typeof value === "object" && value !== null) {
|
|
5107
|
+
walk(value, [...path, key]);
|
|
5108
|
+
}
|
|
5109
|
+
}
|
|
5110
|
+
};
|
|
5111
|
+
walk(condition, []);
|
|
5112
|
+
return paths;
|
|
5113
|
+
}
|
|
5114
|
+
function transformSegment(seg) {
|
|
5115
|
+
if (seg.startsWith("@")) return seg;
|
|
5116
|
+
const parent = (0, import_core2.extractParentSelectors)(seg);
|
|
5117
|
+
return parent ? `&${parent}` : seg;
|
|
5056
5118
|
}
|
|
5057
5119
|
function getDeepestRule(root, selectors) {
|
|
5058
5120
|
const rule = import_postcss.default.rule({ selector: "" });
|
|
@@ -5930,11 +5992,25 @@ var generateConditionJsxExamples = (conditionName, jsxStyleProps2 = "all") => {
|
|
|
5930
5992
|
}
|
|
5931
5993
|
return [];
|
|
5932
5994
|
};
|
|
5995
|
+
var formatObjectCondition = (raw) => {
|
|
5996
|
+
const blocks = [];
|
|
5997
|
+
const walk = (node, path) => {
|
|
5998
|
+
for (const [key, value] of Object.entries(node)) {
|
|
5999
|
+
if (value === "@slot") {
|
|
6000
|
+
blocks.push([...path, key].join(" "));
|
|
6001
|
+
} else if (typeof value === "object" && value !== null) {
|
|
6002
|
+
walk(value, [...path, key]);
|
|
6003
|
+
}
|
|
6004
|
+
}
|
|
6005
|
+
};
|
|
6006
|
+
walk(raw, []);
|
|
6007
|
+
return blocks.join("; ");
|
|
6008
|
+
};
|
|
5933
6009
|
var generateConditionsSpec = (ctx) => {
|
|
5934
6010
|
const jsxStyleProps2 = ctx.config.jsxStyleProps;
|
|
5935
6011
|
const breakpointKeys = new Set(Object.keys(ctx.conditions.breakpoints.conditions));
|
|
5936
6012
|
const conditions = Object.entries(ctx.conditions.values).map(([name, detail]) => {
|
|
5937
|
-
const value = Array.isArray(detail.raw) ? detail.raw.join(", ") : detail.raw;
|
|
6013
|
+
const value = Array.isArray(detail.raw) ? detail.raw.join(", ") : typeof detail.raw === "string" ? detail.raw : formatObjectCondition(detail.raw);
|
|
5938
6014
|
const nameWithoutUnderscore = name.startsWith("_") ? name.slice(1) : name;
|
|
5939
6015
|
const isBreakpoint = breakpointKeys.has(name) || breakpointKeys.has(nameWithoutUnderscore);
|
|
5940
6016
|
const conditionName = isBreakpoint ? nameWithoutUnderscore : name;
|
package/dist/index.mjs
CHANGED
|
@@ -8,6 +8,15 @@ import outdent48 from "outdent";
|
|
|
8
8
|
|
|
9
9
|
// src/artifacts/js/conditions.ts
|
|
10
10
|
import outdent from "outdent";
|
|
11
|
+
function formatConditionJsDoc(raw) {
|
|
12
|
+
if (!raw) return "";
|
|
13
|
+
if (typeof raw === "string") return `/** \`${raw}\` */
|
|
14
|
+
`;
|
|
15
|
+
if (Array.isArray(raw)) return `/** \`${raw.join(" ")}\` */
|
|
16
|
+
`;
|
|
17
|
+
return `/** Multi-block condition */
|
|
18
|
+
`;
|
|
19
|
+
}
|
|
11
20
|
function generateConditions(ctx) {
|
|
12
21
|
const keys = Object.keys(ctx.conditions.values).concat("base");
|
|
13
22
|
return {
|
|
@@ -55,8 +64,7 @@ function generateConditions(ctx) {
|
|
|
55
64
|
export interface Conditions {
|
|
56
65
|
${keys.map(
|
|
57
66
|
(key) => ` ${key === "base" ? `/** The base (=no conditions) styles to apply */
|
|
58
|
-
` : ctx.conditions.get(key)
|
|
59
|
-
` : ""} ${JSON.stringify(key)}: string`
|
|
67
|
+
` : formatConditionJsDoc(ctx.conditions.get(key))} ${JSON.stringify(key)}: string`
|
|
60
68
|
).join("\n")}
|
|
61
69
|
}
|
|
62
70
|
|
|
@@ -216,7 +224,26 @@ function generateStringLiteralCssFn(ctx) {
|
|
|
216
224
|
const { separator } = utility;
|
|
217
225
|
return {
|
|
218
226
|
dts: outdent4`
|
|
219
|
-
|
|
227
|
+
${ctx.file.importType("SystemStyleObject", "../types/index")}
|
|
228
|
+
|
|
229
|
+
type Styles =
|
|
230
|
+
| { raw: readonly string[] | ArrayLike<string> }
|
|
231
|
+
| SystemStyleObject
|
|
232
|
+
| boolean
|
|
233
|
+
| null
|
|
234
|
+
| undefined
|
|
235
|
+
|
|
236
|
+
interface CssRawFunction {
|
|
237
|
+
(...styles: Styles[]): SystemStyleObject
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
interface CssFunction {
|
|
241
|
+
(...styles: Styles[]): string
|
|
242
|
+
|
|
243
|
+
raw: CssRawFunction
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export declare const css: CssFunction;
|
|
220
247
|
`,
|
|
221
248
|
js: outdent4`
|
|
222
249
|
${ctx.file.import("astish, createCss, isObject, mergeProps, withoutSpace", "../helpers")}
|
|
@@ -5006,16 +5033,51 @@ function stringifyVars(options) {
|
|
|
5006
5033
|
const keys = conditionKey.split(":");
|
|
5007
5034
|
if (keys.some((key) => !conditions.get(key))) return;
|
|
5008
5035
|
const css = stringify3(varsObj);
|
|
5009
|
-
const
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5036
|
+
const altsPerKey = keys.map((key) => getSelectorPaths(conditions.get(key)));
|
|
5037
|
+
if (altsPerKey.some((alts) => alts.length === 0)) return;
|
|
5038
|
+
let combos = [[]];
|
|
5039
|
+
for (const alts of altsPerKey) {
|
|
5040
|
+
const next = [];
|
|
5041
|
+
for (const partial of combos) {
|
|
5042
|
+
for (const alt of alts) {
|
|
5043
|
+
next.push([...partial, ...alt]);
|
|
5044
|
+
}
|
|
5045
|
+
}
|
|
5046
|
+
combos = next;
|
|
5047
|
+
}
|
|
5048
|
+
const rules = combos.map((segments) => {
|
|
5049
|
+
const transformed = segments.map(transformSegment).filter(Boolean);
|
|
5050
|
+
const rule = getDeepestRule(root, transformed);
|
|
5051
|
+
if (!rule) return;
|
|
5052
|
+
getDeepestNode(rule)?.append(css);
|
|
5053
|
+
return expandNestedCss(rule.toString());
|
|
5014
5054
|
}).filter(Boolean);
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5055
|
+
return rules.length ? rules.join("\n\n") : void 0;
|
|
5056
|
+
}
|
|
5057
|
+
function getSelectorPaths(condition) {
|
|
5058
|
+
if (condition == null) return [];
|
|
5059
|
+
if (typeof condition === "string") return [[condition]];
|
|
5060
|
+
if (Array.isArray(condition)) {
|
|
5061
|
+
const last = condition.at(-1);
|
|
5062
|
+
return last ? [[last]] : [];
|
|
5063
|
+
}
|
|
5064
|
+
const paths = [];
|
|
5065
|
+
const walk = (node, path) => {
|
|
5066
|
+
for (const [key, value] of Object.entries(node)) {
|
|
5067
|
+
if (value === "@slot") {
|
|
5068
|
+
paths.push([...path, key]);
|
|
5069
|
+
} else if (typeof value === "object" && value !== null) {
|
|
5070
|
+
walk(value, [...path, key]);
|
|
5071
|
+
}
|
|
5072
|
+
}
|
|
5073
|
+
};
|
|
5074
|
+
walk(condition, []);
|
|
5075
|
+
return paths;
|
|
5076
|
+
}
|
|
5077
|
+
function transformSegment(seg) {
|
|
5078
|
+
if (seg.startsWith("@")) return seg;
|
|
5079
|
+
const parent = extractParentSelectors(seg);
|
|
5080
|
+
return parent ? `&${parent}` : seg;
|
|
5019
5081
|
}
|
|
5020
5082
|
function getDeepestRule(root, selectors) {
|
|
5021
5083
|
const rule = postcss.rule({ selector: "" });
|
|
@@ -5893,11 +5955,25 @@ var generateConditionJsxExamples = (conditionName, jsxStyleProps2 = "all") => {
|
|
|
5893
5955
|
}
|
|
5894
5956
|
return [];
|
|
5895
5957
|
};
|
|
5958
|
+
var formatObjectCondition = (raw) => {
|
|
5959
|
+
const blocks = [];
|
|
5960
|
+
const walk = (node, path) => {
|
|
5961
|
+
for (const [key, value] of Object.entries(node)) {
|
|
5962
|
+
if (value === "@slot") {
|
|
5963
|
+
blocks.push([...path, key].join(" "));
|
|
5964
|
+
} else if (typeof value === "object" && value !== null) {
|
|
5965
|
+
walk(value, [...path, key]);
|
|
5966
|
+
}
|
|
5967
|
+
}
|
|
5968
|
+
};
|
|
5969
|
+
walk(raw, []);
|
|
5970
|
+
return blocks.join("; ");
|
|
5971
|
+
};
|
|
5896
5972
|
var generateConditionsSpec = (ctx) => {
|
|
5897
5973
|
const jsxStyleProps2 = ctx.config.jsxStyleProps;
|
|
5898
5974
|
const breakpointKeys = new Set(Object.keys(ctx.conditions.breakpoints.conditions));
|
|
5899
5975
|
const conditions = Object.entries(ctx.conditions.values).map(([name, detail]) => {
|
|
5900
|
-
const value = Array.isArray(detail.raw) ? detail.raw.join(", ") : detail.raw;
|
|
5976
|
+
const value = Array.isArray(detail.raw) ? detail.raw.join(", ") : typeof detail.raw === "string" ? detail.raw : formatObjectCondition(detail.raw);
|
|
5901
5977
|
const nameWithoutUnderscore = name.startsWith("_") ? name.slice(1) : name;
|
|
5902
5978
|
const isBreakpoint = breakpointKeys.has(name) || breakpointKeys.has(nameWithoutUnderscore);
|
|
5903
5979
|
const conditionName = isBreakpoint ? nameWithoutUnderscore : name;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/generator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.1",
|
|
4
4
|
"description": "The css generator for css panda",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
"javascript-stringify": "2.1.0",
|
|
37
37
|
"outdent": " ^0.8.0",
|
|
38
38
|
"pluralize": "8.0.0",
|
|
39
|
-
"postcss": "8.5.
|
|
39
|
+
"postcss": "8.5.14",
|
|
40
40
|
"ts-pattern": "5.9.0",
|
|
41
|
-
"@pandacss/core": "1.
|
|
42
|
-
"@pandacss/is-valid-prop": "^1.
|
|
43
|
-
"@pandacss/logger": "1.
|
|
44
|
-
"@pandacss/shared": "1.
|
|
45
|
-
"@pandacss/token-dictionary": "1.
|
|
46
|
-
"@pandacss/types": "1.
|
|
41
|
+
"@pandacss/core": "1.11.1",
|
|
42
|
+
"@pandacss/is-valid-prop": "^1.11.1",
|
|
43
|
+
"@pandacss/logger": "1.11.1",
|
|
44
|
+
"@pandacss/shared": "1.11.1",
|
|
45
|
+
"@pandacss/token-dictionary": "1.11.1",
|
|
46
|
+
"@pandacss/types": "1.11.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/pluralize": "0.0.33"
|