@pandacss/generator 1.10.0 → 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.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) ? `/** \`${[].concat(ctx.conditions.get(key) ?? "").join(" ")}\` */
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 mapped = keys.map((key) => conditions.get(key)).map((condition) => {
5047
- const lastSegment = Array.isArray(condition) ? condition.at(-1) : condition;
5048
- if (!lastSegment) return;
5049
- const parent = (0, import_core2.extractParentSelectors)(lastSegment);
5050
- return parent ? `&${parent}` : lastSegment;
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
- const rule = getDeepestRule(root, mapped);
5053
- if (!rule) return;
5054
- getDeepestNode(rule)?.append(css);
5055
- return (0, import_core2.expandNestedCss)(rule.toString());
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: "" });
@@ -5930,11 +5973,25 @@ var generateConditionJsxExamples = (conditionName, jsxStyleProps2 = "all") => {
5930
5973
  }
5931
5974
  return [];
5932
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
+ };
5933
5990
  var generateConditionsSpec = (ctx) => {
5934
5991
  const jsxStyleProps2 = ctx.config.jsxStyleProps;
5935
5992
  const breakpointKeys = new Set(Object.keys(ctx.conditions.breakpoints.conditions));
5936
5993
  const conditions = Object.entries(ctx.conditions.values).map(([name, detail]) => {
5937
- 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);
5938
5995
  const nameWithoutUnderscore = name.startsWith("_") ? name.slice(1) : name;
5939
5996
  const isBreakpoint = breakpointKeys.has(name) || breakpointKeys.has(nameWithoutUnderscore);
5940
5997
  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) ? `/** \`${[].concat(ctx.conditions.get(key) ?? "").join(" ")}\` */
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 mapped = keys.map((key) => conditions.get(key)).map((condition) => {
5010
- const lastSegment = Array.isArray(condition) ? condition.at(-1) : condition;
5011
- if (!lastSegment) return;
5012
- const parent = extractParentSelectors(lastSegment);
5013
- return parent ? `&${parent}` : lastSegment;
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
- const rule = getDeepestRule(root, mapped);
5016
- if (!rule) return;
5017
- getDeepestNode(rule)?.append(css);
5018
- return expandNestedCss(rule.toString());
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: "" });
@@ -5893,11 +5936,25 @@ var generateConditionJsxExamples = (conditionName, jsxStyleProps2 = "all") => {
5893
5936
  }
5894
5937
  return [];
5895
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
+ };
5896
5953
  var generateConditionsSpec = (ctx) => {
5897
5954
  const jsxStyleProps2 = ctx.config.jsxStyleProps;
5898
5955
  const breakpointKeys = new Set(Object.keys(ctx.conditions.breakpoints.conditions));
5899
5956
  const conditions = Object.entries(ctx.conditions.values).map(([name, detail]) => {
5900
- 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);
5901
5958
  const nameWithoutUnderscore = name.startsWith("_") ? name.slice(1) : name;
5902
5959
  const isBreakpoint = breakpointKeys.has(name) || breakpointKeys.has(nameWithoutUnderscore);
5903
5960
  const conditionName = isBreakpoint ? nameWithoutUnderscore : name;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/generator",
3
- "version": "1.10.0",
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.10.0",
42
- "@pandacss/is-valid-prop": "^1.10.0",
43
- "@pandacss/logger": "1.10.0",
44
- "@pandacss/shared": "1.10.0",
45
- "@pandacss/token-dictionary": "1.10.0",
46
- "@pandacss/types": "1.10.0"
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"