@pandacss/generator 1.9.1 → 1.11.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/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +148 -21
- package/dist/index.mjs +144 -17
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -49,7 +49,7 @@ declare class Generator extends Context {
|
|
|
49
49
|
*/
|
|
50
50
|
getSplitCssArtifacts: (sheet: Stylesheet) => SplitCssResult;
|
|
51
51
|
getSpec: () => SpecFile[];
|
|
52
|
-
getSpecOfType: <T extends SpecType>(type: T) => T extends "color-palette" ? SpecTypeMap[T] | undefined : SpecTypeMap[T];
|
|
52
|
+
getSpecOfType: <T extends SpecType>(type: T) => T extends "color-palette" | "themes" ? SpecTypeMap[T] | undefined : SpecTypeMap[T];
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ declare class Generator extends Context {
|
|
|
49
49
|
*/
|
|
50
50
|
getSplitCssArtifacts: (sheet: Stylesheet) => SplitCssResult;
|
|
51
51
|
getSpec: () => SpecFile[];
|
|
52
|
-
getSpecOfType: <T extends SpecType>(type: T) => T extends "color-palette" ? SpecTypeMap[T] | undefined : SpecTypeMap[T];
|
|
52
|
+
getSpecOfType: <T extends SpecType>(type: T) => T extends "color-palette" | "themes" ? SpecTypeMap[T] | undefined : SpecTypeMap[T];
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/**
|
package/dist/index.js
CHANGED
|
@@ -37,7 +37,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
37
37
|
|
|
38
38
|
// src/generator.ts
|
|
39
39
|
var import_core5 = require("@pandacss/core");
|
|
40
|
-
var
|
|
40
|
+
var import_shared18 = require("@pandacss/shared");
|
|
41
41
|
var import_ts_pattern14 = require("ts-pattern");
|
|
42
42
|
|
|
43
43
|
// src/artifacts/setup-artifacts.ts
|
|
@@ -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
|
|
|
@@ -5043,16 +5051,51 @@ function stringifyVars(options) {
|
|
|
5043
5051
|
const keys = conditionKey.split(":");
|
|
5044
5052
|
if (keys.some((key) => !conditions.get(key))) return;
|
|
5045
5053
|
const css = (0, import_core2.stringify)(varsObj);
|
|
5046
|
-
const
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5054
|
+
const altsPerKey = keys.map((key) => getSelectorPaths(conditions.get(key)));
|
|
5055
|
+
if (altsPerKey.some((alts) => alts.length === 0)) return;
|
|
5056
|
+
let combos = [[]];
|
|
5057
|
+
for (const alts of altsPerKey) {
|
|
5058
|
+
const next = [];
|
|
5059
|
+
for (const partial of combos) {
|
|
5060
|
+
for (const alt of alts) {
|
|
5061
|
+
next.push([...partial, ...alt]);
|
|
5062
|
+
}
|
|
5063
|
+
}
|
|
5064
|
+
combos = next;
|
|
5065
|
+
}
|
|
5066
|
+
const rules = combos.map((segments) => {
|
|
5067
|
+
const transformed = segments.map(transformSegment).filter(Boolean);
|
|
5068
|
+
const rule = getDeepestRule(root, transformed);
|
|
5069
|
+
if (!rule) return;
|
|
5070
|
+
getDeepestNode(rule)?.append(css);
|
|
5071
|
+
return (0, import_core2.expandNestedCss)(rule.toString());
|
|
5051
5072
|
}).filter(Boolean);
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5073
|
+
return rules.length ? rules.join("\n\n") : void 0;
|
|
5074
|
+
}
|
|
5075
|
+
function getSelectorPaths(condition) {
|
|
5076
|
+
if (condition == null) return [];
|
|
5077
|
+
if (typeof condition === "string") return [[condition]];
|
|
5078
|
+
if (Array.isArray(condition)) {
|
|
5079
|
+
const last = condition.at(-1);
|
|
5080
|
+
return last ? [[last]] : [];
|
|
5081
|
+
}
|
|
5082
|
+
const paths = [];
|
|
5083
|
+
const walk = (node, path) => {
|
|
5084
|
+
for (const [key, value] of Object.entries(node)) {
|
|
5085
|
+
if (value === "@slot") {
|
|
5086
|
+
paths.push([...path, key]);
|
|
5087
|
+
} else if (typeof value === "object" && value !== null) {
|
|
5088
|
+
walk(value, [...path, key]);
|
|
5089
|
+
}
|
|
5090
|
+
}
|
|
5091
|
+
};
|
|
5092
|
+
walk(condition, []);
|
|
5093
|
+
return paths;
|
|
5094
|
+
}
|
|
5095
|
+
function transformSegment(seg) {
|
|
5096
|
+
if (seg.startsWith("@")) return seg;
|
|
5097
|
+
const parent = (0, import_core2.extractParentSelectors)(seg);
|
|
5098
|
+
return parent ? `&${parent}` : seg;
|
|
5056
5099
|
}
|
|
5057
5100
|
function getDeepestRule(root, selectors) {
|
|
5058
5101
|
const rule = import_postcss.default.rule({ selector: "" });
|
|
@@ -5080,6 +5123,8 @@ var parse = (str) => {
|
|
|
5080
5123
|
} catch (error) {
|
|
5081
5124
|
if (error instanceof import_postcss.CssSyntaxError) {
|
|
5082
5125
|
import_logger.logger.error("tokens:process", error.showSourceCode(true));
|
|
5126
|
+
} else {
|
|
5127
|
+
import_logger.logger.caughtError("tokens:process", "Failed to parse token CSS", error);
|
|
5083
5128
|
}
|
|
5084
5129
|
}
|
|
5085
5130
|
};
|
|
@@ -5664,8 +5709,8 @@ var generateParserCss = (ctx, decoder) => {
|
|
|
5664
5709
|
try {
|
|
5665
5710
|
const css = sheet.toCss({ minify });
|
|
5666
5711
|
return css;
|
|
5667
|
-
} catch (
|
|
5668
|
-
import_logger2.logger.
|
|
5712
|
+
} catch (error) {
|
|
5713
|
+
import_logger2.logger.caughtError("serializer:css", "Failed to serialize CSS", error);
|
|
5669
5714
|
return "";
|
|
5670
5715
|
}
|
|
5671
5716
|
};
|
|
@@ -5928,11 +5973,25 @@ var generateConditionJsxExamples = (conditionName, jsxStyleProps2 = "all") => {
|
|
|
5928
5973
|
}
|
|
5929
5974
|
return [];
|
|
5930
5975
|
};
|
|
5976
|
+
var formatObjectCondition = (raw) => {
|
|
5977
|
+
const blocks = [];
|
|
5978
|
+
const walk = (node, path) => {
|
|
5979
|
+
for (const [key, value] of Object.entries(node)) {
|
|
5980
|
+
if (value === "@slot") {
|
|
5981
|
+
blocks.push([...path, key].join(" "));
|
|
5982
|
+
} else if (typeof value === "object" && value !== null) {
|
|
5983
|
+
walk(value, [...path, key]);
|
|
5984
|
+
}
|
|
5985
|
+
}
|
|
5986
|
+
};
|
|
5987
|
+
walk(raw, []);
|
|
5988
|
+
return blocks.join("; ");
|
|
5989
|
+
};
|
|
5931
5990
|
var generateConditionsSpec = (ctx) => {
|
|
5932
5991
|
const jsxStyleProps2 = ctx.config.jsxStyleProps;
|
|
5933
5992
|
const breakpointKeys = new Set(Object.keys(ctx.conditions.breakpoints.conditions));
|
|
5934
5993
|
const conditions = Object.entries(ctx.conditions.values).map(([name, detail]) => {
|
|
5935
|
-
const value = Array.isArray(detail.raw) ? detail.raw.join(", ") : detail.raw;
|
|
5994
|
+
const value = Array.isArray(detail.raw) ? detail.raw.join(", ") : typeof detail.raw === "string" ? detail.raw : formatObjectCondition(detail.raw);
|
|
5936
5995
|
const nameWithoutUnderscore = name.startsWith("_") ? name.slice(1) : name;
|
|
5937
5996
|
const isBreakpoint = breakpointKeys.has(name) || breakpointKeys.has(nameWithoutUnderscore);
|
|
5938
5997
|
const conditionName = isBreakpoint ? nameWithoutUnderscore : name;
|
|
@@ -6101,8 +6160,10 @@ var generateTextStylesSpec = (ctx) => {
|
|
|
6101
6160
|
return generateCompositionStyleSpec("text-styles", ctx.config.theme, ctx.config.jsxStyleProps);
|
|
6102
6161
|
};
|
|
6103
6162
|
|
|
6104
|
-
// src/spec/
|
|
6105
|
-
var
|
|
6163
|
+
// src/spec/themes.ts
|
|
6164
|
+
var import_shared16 = require("@pandacss/shared");
|
|
6165
|
+
|
|
6166
|
+
// src/spec/token-examples.ts
|
|
6106
6167
|
var CATEGORY_PROPERTY_MAP = {
|
|
6107
6168
|
colors: "color",
|
|
6108
6169
|
spacing: "padding",
|
|
@@ -6144,6 +6205,66 @@ var generateTokenExamples = (token, jsxStyleProps2 = "all") => {
|
|
|
6144
6205
|
}
|
|
6145
6206
|
return { functionExamples, tokenFunctionExamples, jsxExamples };
|
|
6146
6207
|
};
|
|
6208
|
+
|
|
6209
|
+
// src/spec/themes.ts
|
|
6210
|
+
var generateThemeTokenGroups = (ctx, themeName, filterFn) => {
|
|
6211
|
+
const jsxStyleProps2 = ctx.config.jsxStyleProps;
|
|
6212
|
+
const condName = "_theme" + (0, import_shared16.capitalize)(themeName);
|
|
6213
|
+
const themeTokens = ctx.tokens.allTokens.filter(
|
|
6214
|
+
(token) => token.extensions.isVirtual && token.extensions.theme === themeName && filterFn(token)
|
|
6215
|
+
);
|
|
6216
|
+
const byCategory = /* @__PURE__ */ new Map();
|
|
6217
|
+
for (const token of themeTokens) {
|
|
6218
|
+
const category = token.extensions.category;
|
|
6219
|
+
if (!category) continue;
|
|
6220
|
+
if (!byCategory.has(category)) byCategory.set(category, []);
|
|
6221
|
+
byCategory.get(category).push(token);
|
|
6222
|
+
}
|
|
6223
|
+
return Array.from(byCategory.entries()).map(([category, typeTokens]) => {
|
|
6224
|
+
if (!typeTokens.length) return null;
|
|
6225
|
+
const firstToken = typeTokens[0];
|
|
6226
|
+
const { functionExamples, tokenFunctionExamples, jsxExamples } = generateTokenExamples(firstToken, jsxStyleProps2);
|
|
6227
|
+
const values = typeTokens.map((token) => {
|
|
6228
|
+
const conditions = [];
|
|
6229
|
+
(0, import_shared16.walkObject)(token.extensions.rawValue, (value, path) => {
|
|
6230
|
+
conditions.push({
|
|
6231
|
+
value,
|
|
6232
|
+
condition: path.map((p) => p === condName ? themeName : p.replace(/^_/, "")).join(".")
|
|
6233
|
+
});
|
|
6234
|
+
});
|
|
6235
|
+
return {
|
|
6236
|
+
name: token.extensions.prop || token.name,
|
|
6237
|
+
values: conditions,
|
|
6238
|
+
description: token.description,
|
|
6239
|
+
deprecated: token.deprecated,
|
|
6240
|
+
cssVar: token.extensions.varRef
|
|
6241
|
+
};
|
|
6242
|
+
});
|
|
6243
|
+
return {
|
|
6244
|
+
type: category,
|
|
6245
|
+
values,
|
|
6246
|
+
tokenFunctionExamples,
|
|
6247
|
+
functionExamples,
|
|
6248
|
+
jsxExamples
|
|
6249
|
+
};
|
|
6250
|
+
}).filter(Boolean);
|
|
6251
|
+
};
|
|
6252
|
+
var generateThemesSpec = (ctx) => {
|
|
6253
|
+
const themes = ctx.config.themes;
|
|
6254
|
+
if (!themes || Object.keys(themes).length === 0) return void 0;
|
|
6255
|
+
const data = Object.keys(themes).map((themeName) => {
|
|
6256
|
+
const tokens = generateThemeTokenGroups(ctx, themeName, (token) => !token.extensions.isSemantic);
|
|
6257
|
+
const semanticTokens = generateThemeTokenGroups(ctx, themeName, (token) => token.extensions.isSemantic);
|
|
6258
|
+
return { name: themeName, tokens, semanticTokens };
|
|
6259
|
+
});
|
|
6260
|
+
return {
|
|
6261
|
+
type: "themes",
|
|
6262
|
+
data
|
|
6263
|
+
};
|
|
6264
|
+
};
|
|
6265
|
+
|
|
6266
|
+
// src/spec/tokens.ts
|
|
6267
|
+
var import_shared17 = require("@pandacss/shared");
|
|
6147
6268
|
var generateTokensSpec = (ctx) => {
|
|
6148
6269
|
const jsxStyleProps2 = ctx.config.jsxStyleProps;
|
|
6149
6270
|
const groupedData = Array.from(ctx.tokens.view.categoryMap.entries()).map(([category, tokenMap]) => {
|
|
@@ -6184,7 +6305,7 @@ var generateSemanticTokensSpec = (ctx) => {
|
|
|
6184
6305
|
const { functionExamples, tokenFunctionExamples, jsxExamples } = generateTokenExamples(firstToken, jsxStyleProps2);
|
|
6185
6306
|
const values = typeTokens.map((token) => {
|
|
6186
6307
|
const conditions = [];
|
|
6187
|
-
(0,
|
|
6308
|
+
(0, import_shared17.walkObject)(token.extensions.rawValue, (value, path) => {
|
|
6188
6309
|
conditions.push({ value, condition: path.map((p) => p.replace(/^_/, "")).join(".") });
|
|
6189
6310
|
});
|
|
6190
6311
|
return {
|
|
@@ -6219,7 +6340,7 @@ var Generator = class extends import_core5.Context {
|
|
|
6219
6340
|
};
|
|
6220
6341
|
appendCssOfType = (type, sheet) => {
|
|
6221
6342
|
(0, import_ts_pattern14.match)(type).with("preflight", () => generateResetCss(this, sheet)).with("tokens", () => generateTokenCss(this, sheet)).with("static", () => generateStaticCss(this, sheet)).with("global", () => generateGlobalCss(this, sheet)).with("keyframes", () => generateKeyframeCss(this, sheet)).otherwise(() => {
|
|
6222
|
-
throw new
|
|
6343
|
+
throw new import_shared18.PandaError(
|
|
6223
6344
|
"UNKNOWN_ARTIFACT",
|
|
6224
6345
|
`Unknown CSS artifact type: "${type}". Expected one of: preflight, tokens, static, global, keyframes`
|
|
6225
6346
|
);
|
|
@@ -6300,7 +6421,7 @@ var Generator = class extends import_core5.Context {
|
|
|
6300
6421
|
recipes.push({
|
|
6301
6422
|
type: "recipe",
|
|
6302
6423
|
name: recipeName,
|
|
6303
|
-
file: `${(0,
|
|
6424
|
+
file: `${(0, import_shared18.dashCase)(recipeName)}.css`,
|
|
6304
6425
|
code,
|
|
6305
6426
|
dir: "recipes"
|
|
6306
6427
|
});
|
|
@@ -6314,7 +6435,7 @@ var Generator = class extends import_core5.Context {
|
|
|
6314
6435
|
themes.push({
|
|
6315
6436
|
type: "theme",
|
|
6316
6437
|
name: themeName,
|
|
6317
|
-
file: `${(0,
|
|
6438
|
+
file: `${(0, import_shared18.dashCase)(themeName)}.css`,
|
|
6318
6439
|
code: `@layer ${layerNames.tokens} {
|
|
6319
6440
|
${css}
|
|
6320
6441
|
}`,
|
|
@@ -6356,6 +6477,10 @@ ${css}
|
|
|
6356
6477
|
if (colorPaletteSpec) {
|
|
6357
6478
|
specs.push(colorPaletteSpec);
|
|
6358
6479
|
}
|
|
6480
|
+
const themesSpec = generateThemesSpec(this);
|
|
6481
|
+
if (themesSpec) {
|
|
6482
|
+
specs.push(themesSpec);
|
|
6483
|
+
}
|
|
6359
6484
|
return specs;
|
|
6360
6485
|
};
|
|
6361
6486
|
getSpecOfType = (type) => {
|
|
@@ -6381,6 +6506,8 @@ ${css}
|
|
|
6381
6506
|
return generateAnimationStylesSpec(this);
|
|
6382
6507
|
case "color-palette":
|
|
6383
6508
|
return generateColorPaletteSpec(this) ?? void 0;
|
|
6509
|
+
case "themes":
|
|
6510
|
+
return generateThemesSpec(this) ?? void 0;
|
|
6384
6511
|
}
|
|
6385
6512
|
})();
|
|
6386
6513
|
return spec;
|
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
|
|
|
@@ -5006,16 +5014,51 @@ function stringifyVars(options) {
|
|
|
5006
5014
|
const keys = conditionKey.split(":");
|
|
5007
5015
|
if (keys.some((key) => !conditions.get(key))) return;
|
|
5008
5016
|
const css = stringify3(varsObj);
|
|
5009
|
-
const
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5017
|
+
const altsPerKey = keys.map((key) => getSelectorPaths(conditions.get(key)));
|
|
5018
|
+
if (altsPerKey.some((alts) => alts.length === 0)) return;
|
|
5019
|
+
let combos = [[]];
|
|
5020
|
+
for (const alts of altsPerKey) {
|
|
5021
|
+
const next = [];
|
|
5022
|
+
for (const partial of combos) {
|
|
5023
|
+
for (const alt of alts) {
|
|
5024
|
+
next.push([...partial, ...alt]);
|
|
5025
|
+
}
|
|
5026
|
+
}
|
|
5027
|
+
combos = next;
|
|
5028
|
+
}
|
|
5029
|
+
const rules = combos.map((segments) => {
|
|
5030
|
+
const transformed = segments.map(transformSegment).filter(Boolean);
|
|
5031
|
+
const rule = getDeepestRule(root, transformed);
|
|
5032
|
+
if (!rule) return;
|
|
5033
|
+
getDeepestNode(rule)?.append(css);
|
|
5034
|
+
return expandNestedCss(rule.toString());
|
|
5014
5035
|
}).filter(Boolean);
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5036
|
+
return rules.length ? rules.join("\n\n") : void 0;
|
|
5037
|
+
}
|
|
5038
|
+
function getSelectorPaths(condition) {
|
|
5039
|
+
if (condition == null) return [];
|
|
5040
|
+
if (typeof condition === "string") return [[condition]];
|
|
5041
|
+
if (Array.isArray(condition)) {
|
|
5042
|
+
const last = condition.at(-1);
|
|
5043
|
+
return last ? [[last]] : [];
|
|
5044
|
+
}
|
|
5045
|
+
const paths = [];
|
|
5046
|
+
const walk = (node, path) => {
|
|
5047
|
+
for (const [key, value] of Object.entries(node)) {
|
|
5048
|
+
if (value === "@slot") {
|
|
5049
|
+
paths.push([...path, key]);
|
|
5050
|
+
} else if (typeof value === "object" && value !== null) {
|
|
5051
|
+
walk(value, [...path, key]);
|
|
5052
|
+
}
|
|
5053
|
+
}
|
|
5054
|
+
};
|
|
5055
|
+
walk(condition, []);
|
|
5056
|
+
return paths;
|
|
5057
|
+
}
|
|
5058
|
+
function transformSegment(seg) {
|
|
5059
|
+
if (seg.startsWith("@")) return seg;
|
|
5060
|
+
const parent = extractParentSelectors(seg);
|
|
5061
|
+
return parent ? `&${parent}` : seg;
|
|
5019
5062
|
}
|
|
5020
5063
|
function getDeepestRule(root, selectors) {
|
|
5021
5064
|
const rule = postcss.rule({ selector: "" });
|
|
@@ -5043,6 +5086,8 @@ var parse = (str) => {
|
|
|
5043
5086
|
} catch (error) {
|
|
5044
5087
|
if (error instanceof CssSyntaxError) {
|
|
5045
5088
|
logger.error("tokens:process", error.showSourceCode(true));
|
|
5089
|
+
} else {
|
|
5090
|
+
logger.caughtError("tokens:process", "Failed to parse token CSS", error);
|
|
5046
5091
|
}
|
|
5047
5092
|
}
|
|
5048
5093
|
};
|
|
@@ -5627,8 +5672,8 @@ var generateParserCss = (ctx, decoder) => {
|
|
|
5627
5672
|
try {
|
|
5628
5673
|
const css = sheet.toCss({ minify });
|
|
5629
5674
|
return css;
|
|
5630
|
-
} catch (
|
|
5631
|
-
logger2.
|
|
5675
|
+
} catch (error) {
|
|
5676
|
+
logger2.caughtError("serializer:css", "Failed to serialize CSS", error);
|
|
5632
5677
|
return "";
|
|
5633
5678
|
}
|
|
5634
5679
|
};
|
|
@@ -5891,11 +5936,25 @@ var generateConditionJsxExamples = (conditionName, jsxStyleProps2 = "all") => {
|
|
|
5891
5936
|
}
|
|
5892
5937
|
return [];
|
|
5893
5938
|
};
|
|
5939
|
+
var formatObjectCondition = (raw) => {
|
|
5940
|
+
const blocks = [];
|
|
5941
|
+
const walk = (node, path) => {
|
|
5942
|
+
for (const [key, value] of Object.entries(node)) {
|
|
5943
|
+
if (value === "@slot") {
|
|
5944
|
+
blocks.push([...path, key].join(" "));
|
|
5945
|
+
} else if (typeof value === "object" && value !== null) {
|
|
5946
|
+
walk(value, [...path, key]);
|
|
5947
|
+
}
|
|
5948
|
+
}
|
|
5949
|
+
};
|
|
5950
|
+
walk(raw, []);
|
|
5951
|
+
return blocks.join("; ");
|
|
5952
|
+
};
|
|
5894
5953
|
var generateConditionsSpec = (ctx) => {
|
|
5895
5954
|
const jsxStyleProps2 = ctx.config.jsxStyleProps;
|
|
5896
5955
|
const breakpointKeys = new Set(Object.keys(ctx.conditions.breakpoints.conditions));
|
|
5897
5956
|
const conditions = Object.entries(ctx.conditions.values).map(([name, detail]) => {
|
|
5898
|
-
const value = Array.isArray(detail.raw) ? detail.raw.join(", ") : detail.raw;
|
|
5957
|
+
const value = Array.isArray(detail.raw) ? detail.raw.join(", ") : typeof detail.raw === "string" ? detail.raw : formatObjectCondition(detail.raw);
|
|
5899
5958
|
const nameWithoutUnderscore = name.startsWith("_") ? name.slice(1) : name;
|
|
5900
5959
|
const isBreakpoint = breakpointKeys.has(name) || breakpointKeys.has(nameWithoutUnderscore);
|
|
5901
5960
|
const conditionName = isBreakpoint ? nameWithoutUnderscore : name;
|
|
@@ -6064,8 +6123,10 @@ var generateTextStylesSpec = (ctx) => {
|
|
|
6064
6123
|
return generateCompositionStyleSpec("text-styles", ctx.config.theme, ctx.config.jsxStyleProps);
|
|
6065
6124
|
};
|
|
6066
6125
|
|
|
6067
|
-
// src/spec/
|
|
6068
|
-
import { walkObject as walkObject2 } from "@pandacss/shared";
|
|
6126
|
+
// src/spec/themes.ts
|
|
6127
|
+
import { capitalize as capitalize2, walkObject as walkObject2 } from "@pandacss/shared";
|
|
6128
|
+
|
|
6129
|
+
// src/spec/token-examples.ts
|
|
6069
6130
|
var CATEGORY_PROPERTY_MAP = {
|
|
6070
6131
|
colors: "color",
|
|
6071
6132
|
spacing: "padding",
|
|
@@ -6107,6 +6168,66 @@ var generateTokenExamples = (token, jsxStyleProps2 = "all") => {
|
|
|
6107
6168
|
}
|
|
6108
6169
|
return { functionExamples, tokenFunctionExamples, jsxExamples };
|
|
6109
6170
|
};
|
|
6171
|
+
|
|
6172
|
+
// src/spec/themes.ts
|
|
6173
|
+
var generateThemeTokenGroups = (ctx, themeName, filterFn) => {
|
|
6174
|
+
const jsxStyleProps2 = ctx.config.jsxStyleProps;
|
|
6175
|
+
const condName = "_theme" + capitalize2(themeName);
|
|
6176
|
+
const themeTokens = ctx.tokens.allTokens.filter(
|
|
6177
|
+
(token) => token.extensions.isVirtual && token.extensions.theme === themeName && filterFn(token)
|
|
6178
|
+
);
|
|
6179
|
+
const byCategory = /* @__PURE__ */ new Map();
|
|
6180
|
+
for (const token of themeTokens) {
|
|
6181
|
+
const category = token.extensions.category;
|
|
6182
|
+
if (!category) continue;
|
|
6183
|
+
if (!byCategory.has(category)) byCategory.set(category, []);
|
|
6184
|
+
byCategory.get(category).push(token);
|
|
6185
|
+
}
|
|
6186
|
+
return Array.from(byCategory.entries()).map(([category, typeTokens]) => {
|
|
6187
|
+
if (!typeTokens.length) return null;
|
|
6188
|
+
const firstToken = typeTokens[0];
|
|
6189
|
+
const { functionExamples, tokenFunctionExamples, jsxExamples } = generateTokenExamples(firstToken, jsxStyleProps2);
|
|
6190
|
+
const values = typeTokens.map((token) => {
|
|
6191
|
+
const conditions = [];
|
|
6192
|
+
walkObject2(token.extensions.rawValue, (value, path) => {
|
|
6193
|
+
conditions.push({
|
|
6194
|
+
value,
|
|
6195
|
+
condition: path.map((p) => p === condName ? themeName : p.replace(/^_/, "")).join(".")
|
|
6196
|
+
});
|
|
6197
|
+
});
|
|
6198
|
+
return {
|
|
6199
|
+
name: token.extensions.prop || token.name,
|
|
6200
|
+
values: conditions,
|
|
6201
|
+
description: token.description,
|
|
6202
|
+
deprecated: token.deprecated,
|
|
6203
|
+
cssVar: token.extensions.varRef
|
|
6204
|
+
};
|
|
6205
|
+
});
|
|
6206
|
+
return {
|
|
6207
|
+
type: category,
|
|
6208
|
+
values,
|
|
6209
|
+
tokenFunctionExamples,
|
|
6210
|
+
functionExamples,
|
|
6211
|
+
jsxExamples
|
|
6212
|
+
};
|
|
6213
|
+
}).filter(Boolean);
|
|
6214
|
+
};
|
|
6215
|
+
var generateThemesSpec = (ctx) => {
|
|
6216
|
+
const themes = ctx.config.themes;
|
|
6217
|
+
if (!themes || Object.keys(themes).length === 0) return void 0;
|
|
6218
|
+
const data = Object.keys(themes).map((themeName) => {
|
|
6219
|
+
const tokens = generateThemeTokenGroups(ctx, themeName, (token) => !token.extensions.isSemantic);
|
|
6220
|
+
const semanticTokens = generateThemeTokenGroups(ctx, themeName, (token) => token.extensions.isSemantic);
|
|
6221
|
+
return { name: themeName, tokens, semanticTokens };
|
|
6222
|
+
});
|
|
6223
|
+
return {
|
|
6224
|
+
type: "themes",
|
|
6225
|
+
data
|
|
6226
|
+
};
|
|
6227
|
+
};
|
|
6228
|
+
|
|
6229
|
+
// src/spec/tokens.ts
|
|
6230
|
+
import { walkObject as walkObject3 } from "@pandacss/shared";
|
|
6110
6231
|
var generateTokensSpec = (ctx) => {
|
|
6111
6232
|
const jsxStyleProps2 = ctx.config.jsxStyleProps;
|
|
6112
6233
|
const groupedData = Array.from(ctx.tokens.view.categoryMap.entries()).map(([category, tokenMap]) => {
|
|
@@ -6147,7 +6268,7 @@ var generateSemanticTokensSpec = (ctx) => {
|
|
|
6147
6268
|
const { functionExamples, tokenFunctionExamples, jsxExamples } = generateTokenExamples(firstToken, jsxStyleProps2);
|
|
6148
6269
|
const values = typeTokens.map((token) => {
|
|
6149
6270
|
const conditions = [];
|
|
6150
|
-
|
|
6271
|
+
walkObject3(token.extensions.rawValue, (value, path) => {
|
|
6151
6272
|
conditions.push({ value, condition: path.map((p) => p.replace(/^_/, "")).join(".") });
|
|
6152
6273
|
});
|
|
6153
6274
|
return {
|
|
@@ -6319,6 +6440,10 @@ ${css}
|
|
|
6319
6440
|
if (colorPaletteSpec) {
|
|
6320
6441
|
specs.push(colorPaletteSpec);
|
|
6321
6442
|
}
|
|
6443
|
+
const themesSpec = generateThemesSpec(this);
|
|
6444
|
+
if (themesSpec) {
|
|
6445
|
+
specs.push(themesSpec);
|
|
6446
|
+
}
|
|
6322
6447
|
return specs;
|
|
6323
6448
|
};
|
|
6324
6449
|
getSpecOfType = (type) => {
|
|
@@ -6344,6 +6469,8 @@ ${css}
|
|
|
6344
6469
|
return generateAnimationStylesSpec(this);
|
|
6345
6470
|
case "color-palette":
|
|
6346
6471
|
return generateColorPaletteSpec(this) ?? void 0;
|
|
6472
|
+
case "themes":
|
|
6473
|
+
return generateThemesSpec(this) ?? void 0;
|
|
6347
6474
|
}
|
|
6348
6475
|
})();
|
|
6349
6476
|
return spec;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/generator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "The css generator for css panda",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"pluralize": "8.0.0",
|
|
39
39
|
"postcss": "8.5.6",
|
|
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.0",
|
|
42
|
+
"@pandacss/is-valid-prop": "^1.11.0",
|
|
43
|
+
"@pandacss/logger": "1.11.0",
|
|
44
|
+
"@pandacss/shared": "1.11.0",
|
|
45
|
+
"@pandacss/token-dictionary": "1.11.0",
|
|
46
|
+
"@pandacss/types": "1.11.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/pluralize": "0.0.33"
|