@pandacss/generator 0.0.0-dev-20240315145057 → 0.0.0-dev-20240315210222

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.
Files changed (3) hide show
  1. package/dist/index.js +262 -121
  2. package/dist/index.mjs +258 -117
  3. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@ var import_core5 = require("@pandacss/core");
39
39
  var import_ts_pattern11 = require("ts-pattern");
40
40
 
41
41
  // src/artifacts/setup-artifacts.ts
42
- var import_outdent43 = __toESM(require("outdent"));
42
+ var import_outdent44 = __toESM(require("outdent"));
43
43
 
44
44
  // src/artifacts/js/conditions.ts
45
45
  var import_outdent = __toESM(require("outdent"));
@@ -2776,6 +2776,11 @@ function generatePackageJson(ctx) {
2776
2776
  require: ctx.file.ext(`./recipes/index`),
2777
2777
  import: ctx.file.ext(`./recipes/index`)
2778
2778
  },
2779
+ "./themes": {
2780
+ types: ctx.file.extDts("./themes/index"),
2781
+ require: ctx.file.ext(`./themes/index`),
2782
+ import: ctx.file.ext(`./themes/index`)
2783
+ },
2779
2784
  "./tokens": {
2780
2785
  types: ctx.file.extDts("./tokens/index"),
2781
2786
  require: ctx.file.ext(`./tokens/index`),
@@ -3515,7 +3520,7 @@ var selectors_d_ts_default = {
3515
3520
 
3516
3521
  // src/artifacts/generated/static-css.d.ts.json
3517
3522
  var static_css_d_ts_default = {
3518
- content: "interface WithConditions {\n /**\n * The css conditions to generate for the rule.\n * @example ['hover', 'focus']\n */\n conditions?: string[]\n responsive?: boolean\n}\n\nexport interface CssRule extends WithConditions {\n /**\n * The css properties to generate utilities for.\n * @example ['margin', 'padding']\n */\n properties: {\n [property: string]: Array<string | number>\n }\n}\n\ninterface RecipeRuleVariants {\n [variant: string]: boolean | string[]\n}\n\nexport type RecipeRule = '*' | (RecipeRuleVariants & WithConditions)\nexport type PatternRule = '*' | CssRule\n\nexport interface StaticCssOptions {\n /**\n * The css utility classes to generate.\n */\n css?: CssRule[]\n /**\n * The css recipes to generate.\n */\n recipes?:\n | '*'\n | {\n [recipe: string]: RecipeRule[]\n }\n /**\n * The css patterns to generate.\n */\n patterns?: {\n [pattern: string]: PatternRule[]\n }\n}\n"
3523
+ content: "interface WithConditions {\n /**\n * The css conditions to generate for the rule.\n * @example ['hover', 'focus']\n */\n conditions?: string[]\n responsive?: boolean\n}\n\nexport interface CssRule extends WithConditions {\n /**\n * The css properties to generate utilities for.\n * @example ['margin', 'padding']\n */\n properties: {\n [property: string]: Array<string | number>\n }\n}\n\ninterface RecipeRuleVariants {\n [variant: string]: boolean | string[]\n}\n\nexport type RecipeRule = '*' | (RecipeRuleVariants & WithConditions)\nexport type PatternRule = '*' | CssRule\n\nexport interface StaticCssOptions {\n /**\n * The css utility classes to generate.\n */\n css?: CssRule[]\n /**\n * The css recipes to generate.\n */\n recipes?:\n | '*'\n | {\n [recipe: string]: RecipeRule[]\n }\n /**\n * The css patterns to generate.\n */\n patterns?: {\n [pattern: string]: PatternRule[]\n }\n /**\n * The CSS themes to generate\n */\n themes?: string[]\n}\n"
3519
3524
  };
3520
3525
 
3521
3526
  // src/artifacts/generated/system-types.d.ts.json
@@ -3839,6 +3844,228 @@ function generateTokenTypes(ctx) {
3839
3844
  return import_outdent42.outdent.string(Array.from(set).join("\n\n"));
3840
3845
  }
3841
3846
 
3847
+ // src/artifacts/js/themes.ts
3848
+ var import_shared5 = require("@pandacss/shared");
3849
+ var import_outdent43 = __toESM(require("outdent"));
3850
+
3851
+ // src/artifacts/css/token-css.ts
3852
+ var import_core2 = require("@pandacss/core");
3853
+ var import_logger = require("@pandacss/logger");
3854
+ var import_postcss = __toESM(require("postcss"));
3855
+ function generateTokenCss(ctx, sheet) {
3856
+ const { config, conditions, tokens } = ctx;
3857
+ const { cssVarRoot, staticCss } = config;
3858
+ const root = cssVarRoot;
3859
+ const results = [];
3860
+ const allowed = staticCss?.themes;
3861
+ let themeVariants = [];
3862
+ if (allowed) {
3863
+ const keys = Object.keys(config.themes ?? {});
3864
+ themeVariants = allowed.includes("*") ? keys : keys.filter((key) => allowed.includes(key));
3865
+ }
3866
+ const themeConds = themeVariants.map((key) => conditions.getThemeName(key));
3867
+ const themePrefix = ctx.conditions.getThemeName("");
3868
+ for (const [key, values] of tokens.view.vars.entries()) {
3869
+ const isThemeSkipped = key.startsWith(themePrefix) && !themeConds.some((condName) => key.startsWith(condName));
3870
+ if (isThemeSkipped) {
3871
+ continue;
3872
+ }
3873
+ const css2 = stringifyVars({ values, conditionKey: key, root, conditions });
3874
+ if (css2) {
3875
+ results.push(css2);
3876
+ }
3877
+ }
3878
+ let css = results.join("\n\n");
3879
+ css = "\n\n" + cleanupSelectors(css, root);
3880
+ if (ctx.hooks["cssgen:done"]) {
3881
+ css = ctx.hooks["cssgen:done"]({ artifact: "tokens", content: css }) ?? css;
3882
+ }
3883
+ sheet.layers.tokens.append(css);
3884
+ }
3885
+ function stringifyVars(options) {
3886
+ const { conditionKey, values, root, conditions } = options;
3887
+ const varsObj = Object.fromEntries(values);
3888
+ if (Object.keys(varsObj).length === 0)
3889
+ return;
3890
+ if (conditionKey === "base") {
3891
+ return (0, import_core2.stringify)({ [root]: varsObj });
3892
+ }
3893
+ const keys = conditionKey.split(":");
3894
+ if (keys.some((key) => !conditions.get(key)))
3895
+ return;
3896
+ const css = (0, import_core2.stringify)(varsObj);
3897
+ const mapped = keys.map((key) => conditions.get(key)).map((condition) => {
3898
+ const lastSegment = Array.isArray(condition) ? condition.at(-1) : condition;
3899
+ if (!lastSegment)
3900
+ return;
3901
+ const parent = (0, import_core2.extractParentSelectors)(lastSegment);
3902
+ return parent ? `&${parent}` : lastSegment;
3903
+ }).filter(Boolean);
3904
+ const rule = getDeepestRule(root, mapped);
3905
+ if (!rule)
3906
+ return;
3907
+ getDeepestNode(rule)?.append(css);
3908
+ return (0, import_core2.expandNestedCss)(rule.toString());
3909
+ }
3910
+ function getDeepestRule(root, selectors) {
3911
+ const rule = import_postcss.default.rule({ selector: "" });
3912
+ for (const selector of selectors) {
3913
+ const last = getDeepestNode(rule);
3914
+ const node = last ?? rule;
3915
+ if (selector.startsWith("@")) {
3916
+ const atRule = import_postcss.default.rule({ selector, nodes: [import_postcss.default.rule({ selector: `${root}&` })] });
3917
+ node.append(atRule);
3918
+ } else {
3919
+ node.append(import_postcss.default.rule({ selector }));
3920
+ }
3921
+ }
3922
+ return rule;
3923
+ }
3924
+ function getDeepestNode(node) {
3925
+ if (node.nodes && node.nodes.length) {
3926
+ return getDeepestNode(node.nodes[node.nodes.length - 1]);
3927
+ }
3928
+ return node;
3929
+ }
3930
+ var parse = (str) => {
3931
+ try {
3932
+ return import_postcss.default.parse(str);
3933
+ } catch (error) {
3934
+ if (error instanceof import_postcss.CssSyntaxError) {
3935
+ import_logger.logger.error("tokens:process", error.showSourceCode(true));
3936
+ }
3937
+ }
3938
+ };
3939
+ function cleanupSelectors(css, varSelector) {
3940
+ const root = parse(css) ?? import_postcss.default.root();
3941
+ root.walkRules((rule) => {
3942
+ const selectors = [];
3943
+ rule.selectors.forEach((selector) => {
3944
+ selectors.push(selector.trim());
3945
+ });
3946
+ const ruleSelector = selectors.join(", ");
3947
+ if (ruleSelector === varSelector) {
3948
+ return;
3949
+ }
3950
+ const trimmedSelector = selectors.join(",");
3951
+ if (trimmedSelector === varSelector) {
3952
+ return;
3953
+ }
3954
+ const selectorsWithoutVarRoot = selectors.map((selector) => {
3955
+ const res = selector.split(varSelector).filter(Boolean);
3956
+ return res.join("");
3957
+ }).filter(Boolean);
3958
+ if (selectorsWithoutVarRoot.length === 0)
3959
+ return;
3960
+ rule.selector = selectorsWithoutVarRoot.join(", ");
3961
+ });
3962
+ return root.toString();
3963
+ }
3964
+
3965
+ // src/artifacts/js/themes.ts
3966
+ var getThemeId = (themeName) => "panda-theme-" + themeName;
3967
+ function generateThemes(ctx) {
3968
+ const { themes } = ctx.config;
3969
+ if (!themes)
3970
+ return;
3971
+ const { tokens, conditions } = ctx;
3972
+ return Object.entries(themes).map(([name, themeVariant]) => {
3973
+ const results = [];
3974
+ const condName = ctx.conditions.getThemeName(name);
3975
+ for (const [key, values] of tokens.view.vars.entries()) {
3976
+ if (key.startsWith(condName)) {
3977
+ const css = stringifyVars({ values, conditionKey: key, root: "", conditions });
3978
+ if (css) {
3979
+ results.push(css);
3980
+ }
3981
+ }
3982
+ }
3983
+ return {
3984
+ name,
3985
+ json: JSON.stringify(
3986
+ (0, import_shared5.compact)({
3987
+ name,
3988
+ id: getThemeId(name),
3989
+ dataAttr: themeVariant.attribute || name,
3990
+ css: results.join("\n\n")
3991
+ }),
3992
+ null,
3993
+ 2
3994
+ )
3995
+ };
3996
+ });
3997
+ }
3998
+ function generateThemesIndex(ctx, files) {
3999
+ const { themes } = ctx.config;
4000
+ if (!themes)
4001
+ return;
4002
+ if (!files)
4003
+ return;
4004
+ const themeName = Object.keys(themes);
4005
+ return [
4006
+ {
4007
+ file: ctx.file.ext("index"),
4008
+ code: import_outdent43.default`
4009
+ export const getTheme = (themeName) => import('./' + themeName + '.json').then((m) => m.default)
4010
+
4011
+ export function injectTheme(el, theme) {
4012
+ const doc = el.ownerDocument || document
4013
+ let sheet = doc.getElementById(theme.id)
4014
+
4015
+ if (!sheet) {
4016
+ sheet = doc.createElement('style')
4017
+ sheet.setAttribute('type', 'text/css')
4018
+ sheet.setAttribute('id', theme.id)
4019
+ }
4020
+
4021
+ const head = doc.head || doc.getElementsByTagName('head')[0]
4022
+ if (!head) {
4023
+ throw new Error('No head found in doc')
4024
+ }
4025
+
4026
+ el.dataset.pandaTheme = theme.dataAttr
4027
+
4028
+ head.appendChild(sheet)
4029
+ sheet.innerHTML = theme.css
4030
+
4031
+ return sheet
4032
+ }
4033
+ `
4034
+ },
4035
+ {
4036
+ file: ctx.file.extDts("index"),
4037
+ code: import_outdent43.default`
4038
+ export type ThemeName = ${themeName.map((name) => `'${name}'`).join(" | ")}
4039
+ export type ThemeByName = {
4040
+ ${files.map((f) => {
4041
+ const theme = JSON.parse(f.json);
4042
+ if (!theme.css)
4043
+ return "";
4044
+ return `'${f.name}': {
4045
+ id: string,
4046
+ name: '${f.name}',
4047
+ dataAttr: '${theme.attribute || f.name}',
4048
+ css: string
4049
+ }`;
4050
+ }).join("\n")}
4051
+ }
4052
+
4053
+ export type Theme<T extends ThemeName> = ThemeByName[T]
4054
+
4055
+ /**
4056
+ * Dynamically import a theme by name
4057
+ */
4058
+ export declare function getTheme<T extends ThemeName>(themeName: T): Promise<ThemeByName[T]>
4059
+
4060
+ /**
4061
+ * Inject a theme stylesheet into the document
4062
+ */
4063
+ export declare function injectTheme(el: HTMLElement, theme: Theme<any>): HTMLStyleElement
4064
+ `
4065
+ }
4066
+ ];
4067
+ }
4068
+
3842
4069
  // src/artifacts/setup-artifacts.ts
3843
4070
  function setupHelpers(ctx) {
3844
4071
  const code = generateHelpers(ctx);
@@ -3994,8 +4221,8 @@ function setupRecipesIndex(ctx) {
3994
4221
  return;
3995
4222
  const fileNames = ctx.recipes.details.map((recipe) => recipe.dashName);
3996
4223
  const index = {
3997
- js: import_outdent43.default.string(fileNames.map((file) => ctx.file.exportStar(`./${file}`)).join("\n")),
3998
- dts: import_outdent43.default.string(fileNames.map((file) => ctx.file.exportTypeStar(`./${file}`)).join("\n"))
4224
+ js: import_outdent44.default.string(fileNames.map((file) => ctx.file.exportStar(`./${file}`)).join("\n")),
4225
+ dts: import_outdent44.default.string(fileNames.map((file) => ctx.file.exportTypeStar(`./${file}`)).join("\n"))
3999
4226
  };
4000
4227
  return {
4001
4228
  id: "recipes-index",
@@ -4026,8 +4253,8 @@ function setupPatternsIndex(ctx) {
4026
4253
  return;
4027
4254
  const fileNames = ctx.patterns.details.map((pattern) => pattern.dashName);
4028
4255
  const index = {
4029
- js: import_outdent43.default.string(fileNames.map((file) => ctx.file.exportStar(`./${file}`)).join("\n")),
4030
- dts: import_outdent43.default.string(fileNames.map((file) => ctx.file.exportTypeStar(`./${file}`)).join("\n"))
4256
+ js: import_outdent44.default.string(fileNames.map((file) => ctx.file.exportStar(`./${file}`)).join("\n")),
4257
+ dts: import_outdent44.default.string(fileNames.map((file) => ctx.file.exportTypeStar(`./${file}`)).join("\n"))
4031
4258
  };
4032
4259
  return {
4033
4260
  id: "patterns-index",
@@ -4117,15 +4344,15 @@ function setupJsxPatternsIndex(ctx) {
4117
4344
  const isStyleProp = !ctx.isTemplateLiteralSyntax;
4118
4345
  const patternNames = ctx.patterns.details.map((pattern) => pattern.dashName);
4119
4346
  const index = {
4120
- js: import_outdent43.default`
4347
+ js: import_outdent44.default`
4121
4348
  ${ctx.file.exportStar("./factory")}
4122
4349
  ${isStyleProp ? ctx.file.exportStar("./is-valid-prop") : ""}
4123
- ${isStyleProp ? import_outdent43.default.string(patternNames.map((file) => ctx.file.exportStar(`./${file}`)).join("\n")) : ""}
4350
+ ${isStyleProp ? import_outdent44.default.string(patternNames.map((file) => ctx.file.exportStar(`./${file}`)).join("\n")) : ""}
4124
4351
  `,
4125
- dts: import_outdent43.default`
4352
+ dts: import_outdent44.default`
4126
4353
  ${ctx.file.exportTypeStar("./factory")}
4127
4354
  ${isStyleProp ? ctx.file.exportTypeStar("./is-valid-prop") : ""}
4128
- ${isStyleProp ? import_outdent43.default.string(patternNames.map((file) => ctx.file.exportTypeStar(`./${file}`)).join("\n")) : ""}
4355
+ ${isStyleProp ? import_outdent44.default.string(patternNames.map((file) => ctx.file.exportTypeStar(`./${file}`)).join("\n")) : ""}
4129
4356
  ${ctx.file.exportType([ctx.jsx.typeName, ctx.jsx.componentName].join(", "), "../types/jsx")}
4130
4357
  `
4131
4358
  };
@@ -4140,13 +4367,13 @@ function setupJsxPatternsIndex(ctx) {
4140
4367
  }
4141
4368
  function setupCssIndex(ctx) {
4142
4369
  const index = {
4143
- js: import_outdent43.default`
4370
+ js: import_outdent44.default`
4144
4371
  ${ctx.file.exportStar("./css")}
4145
4372
  ${ctx.file.exportStar("./cx")}
4146
4373
  ${ctx.isTemplateLiteralSyntax ? "" : ctx.file.exportStar("./cva")}
4147
4374
  ${ctx.isTemplateLiteralSyntax ? "" : ctx.file.exportStar("./sva")}
4148
4375
  `,
4149
- dts: import_outdent43.default`
4376
+ dts: import_outdent44.default`
4150
4377
  ${ctx.file.exportTypeStar("./css")}
4151
4378
  ${ctx.file.exportTypeStar("./cx")}
4152
4379
  ${ctx.isTemplateLiteralSyntax ? "" : ctx.file.exportTypeStar("./cva")}
@@ -4170,6 +4397,19 @@ function setupPackageJson(ctx) {
4170
4397
  files: [{ file: "package.json", code: generatePackageJson(ctx) }]
4171
4398
  };
4172
4399
  }
4400
+ function setupThemes(ctx) {
4401
+ const { themes } = ctx.config;
4402
+ if (!themes)
4403
+ return;
4404
+ const files = generateThemes(ctx);
4405
+ if (!files)
4406
+ return;
4407
+ return {
4408
+ id: "themes",
4409
+ dir: ctx.paths.themes,
4410
+ files: files.flatMap((file) => [{ file: [file.name, "json"].join("."), code: file.json }]).concat(generateThemesIndex(ctx, files) ?? [])
4411
+ };
4412
+ }
4173
4413
  var getAffectedArtifacts = (ids) => {
4174
4414
  if (!ids)
4175
4415
  return;
@@ -4238,7 +4478,8 @@ var entries = [
4238
4478
  ["jsx-patterns", setupJsxPatterns],
4239
4479
  ["jsx-patterns-index", setupJsxPatternsIndex],
4240
4480
  ["css-index", setupCssIndex],
4241
- ["package.json", setupPackageJson]
4481
+ ["package.json", setupPackageJson],
4482
+ ["themes", setupThemes]
4242
4483
  ];
4243
4484
  var getMatchingArtifacts = (ctx, filters) => {
4244
4485
  const ids = filters?.ids;
@@ -4313,14 +4554,14 @@ var generateGlobalCss = (ctx, sheet) => {
4313
4554
  };
4314
4555
 
4315
4556
  // src/artifacts/css/keyframe-css.ts
4316
- var import_core2 = require("@pandacss/core");
4557
+ var import_core3 = require("@pandacss/core");
4317
4558
  function generateKeyframeCss(ctx, sheet) {
4318
4559
  const { keyframes = {} } = ctx.config.theme ?? {};
4319
4560
  const result = {};
4320
4561
  for (const [name, definition] of Object.entries(keyframes)) {
4321
4562
  result[`@keyframes ${name}`] = definition;
4322
4563
  }
4323
- let css = (0, import_core2.stringify)(sheet.serialize(result));
4564
+ let css = (0, import_core3.stringify)(sheet.serialize(result));
4324
4565
  if (ctx.hooks["cssgen:done"]) {
4325
4566
  css = ctx.hooks["cssgen:done"]({ artifact: "keyframes", content: css }) ?? css;
4326
4567
  }
@@ -4328,7 +4569,7 @@ function generateKeyframeCss(ctx, sheet) {
4328
4569
  }
4329
4570
 
4330
4571
  // src/artifacts/css/parser-css.ts
4331
- var import_logger = require("@pandacss/logger");
4572
+ var import_logger2 = require("@pandacss/logger");
4332
4573
  var generateParserCss = (ctx, decoder) => {
4333
4574
  if (!decoder)
4334
4575
  return "";
@@ -4339,17 +4580,17 @@ var generateParserCss = (ctx, decoder) => {
4339
4580
  const css = sheet.toCss({ minify, optimize });
4340
4581
  return css;
4341
4582
  } catch (err) {
4342
- import_logger.logger.error("serializer:css", "Failed to serialize CSS: " + err);
4583
+ import_logger2.logger.error("serializer:css", "Failed to serialize CSS: " + err);
4343
4584
  return "";
4344
4585
  }
4345
4586
  };
4346
4587
 
4347
4588
  // src/artifacts/css/reset-css.ts
4348
- var import_core3 = require("@pandacss/core");
4349
- var import_shared5 = require("@pandacss/shared");
4589
+ var import_core4 = require("@pandacss/core");
4590
+ var import_shared6 = require("@pandacss/shared");
4350
4591
  function generateResetCss(ctx, sheet) {
4351
4592
  const { preflight } = ctx.config;
4352
- const { scope = "", level = "parent" } = (0, import_shared5.isObject)(preflight) ? preflight : {};
4593
+ const { scope = "", level = "parent" } = (0, import_shared6.isObject)(preflight) ? preflight : {};
4353
4594
  let selector = "";
4354
4595
  if (scope && level === "parent") {
4355
4596
  selector = `${scope} `;
@@ -4447,7 +4688,7 @@ function generateResetCss(ctx, sheet) {
4447
4688
  }
4448
4689
  };
4449
4690
  if (level === "element") {
4450
- const modified = (0, import_shared5.mapEntries)(scoped, (k, v) => [k, { [selector]: v }]);
4691
+ const modified = (0, import_shared6.mapEntries)(scoped, (k, v) => [k, { [selector]: v }]);
4451
4692
  Object.assign(reset, modified);
4452
4693
  } else if (selector) {
4453
4694
  reset[selector] = scoped;
@@ -4471,106 +4712,6 @@ var generateStaticCss = (ctx, sheet) => {
4471
4712
  }
4472
4713
  };
4473
4714
 
4474
- // src/artifacts/css/token-css.ts
4475
- var import_core4 = require("@pandacss/core");
4476
- var import_postcss = __toESM(require("postcss"));
4477
- var import_logger2 = require("@pandacss/logger");
4478
- function generateTokenCss(ctx, sheet) {
4479
- const {
4480
- config: { cssVarRoot },
4481
- conditions,
4482
- tokens
4483
- } = ctx;
4484
- const root = cssVarRoot;
4485
- const results = [];
4486
- for (const [key, values] of tokens.view.vars.entries()) {
4487
- const varsObj = Object.fromEntries(values);
4488
- if (Object.keys(varsObj).length === 0)
4489
- continue;
4490
- if (key === "base") {
4491
- const css2 = (0, import_core4.stringify)({ [root]: varsObj });
4492
- results.push(css2);
4493
- } else {
4494
- const keys = key.split(":");
4495
- const css2 = (0, import_core4.stringify)(varsObj);
4496
- const mapped = keys.map((key2) => conditions.get(key2)).filter(Boolean).map((condition) => {
4497
- const lastSegment = Array.isArray(condition) ? condition.at(-1) : condition;
4498
- if (!lastSegment)
4499
- return;
4500
- const parent = (0, import_core4.extractParentSelectors)(lastSegment);
4501
- return parent ? `&${parent}` : lastSegment;
4502
- }).filter(Boolean);
4503
- if (!mapped.length)
4504
- return;
4505
- const rule = getDeepestRule(root, mapped);
4506
- if (!rule)
4507
- continue;
4508
- getDeepestNode(rule)?.append(css2);
4509
- results.push((0, import_core4.expandNestedCss)(rule.toString()));
4510
- }
4511
- }
4512
- let css = results.join("\n\n");
4513
- css = "\n\n" + cleanupSelectors(css, root);
4514
- if (ctx.hooks["cssgen:done"]) {
4515
- css = ctx.hooks["cssgen:done"]({ artifact: "tokens", content: css }) ?? css;
4516
- }
4517
- sheet.layers.tokens.append(css);
4518
- }
4519
- function getDeepestRule(root, selectors) {
4520
- const rule = import_postcss.default.rule({ selector: "" });
4521
- for (const selector of selectors) {
4522
- const last = getDeepestNode(rule);
4523
- const node = last ?? rule;
4524
- if (selector.startsWith("@")) {
4525
- const atRule = import_postcss.default.rule({ selector, nodes: [import_postcss.default.rule({ selector: `${root}&` })] });
4526
- node.append(atRule);
4527
- } else {
4528
- node.append(import_postcss.default.rule({ selector }));
4529
- }
4530
- }
4531
- return rule;
4532
- }
4533
- function getDeepestNode(node) {
4534
- if (node.nodes && node.nodes.length) {
4535
- return getDeepestNode(node.nodes[node.nodes.length - 1]);
4536
- }
4537
- return node;
4538
- }
4539
- var parse = (str) => {
4540
- try {
4541
- return import_postcss.default.parse(str);
4542
- } catch (error) {
4543
- if (error instanceof import_postcss.CssSyntaxError) {
4544
- import_logger2.logger.error("tokens:process", error.showSourceCode(true));
4545
- }
4546
- }
4547
- };
4548
- function cleanupSelectors(css, varSelector) {
4549
- const root = parse(css) ?? import_postcss.default.root();
4550
- root.walkRules((rule) => {
4551
- const selectors = [];
4552
- rule.selectors.forEach((selector) => {
4553
- selectors.push(selector.trim());
4554
- });
4555
- const ruleSelector = selectors.join(", ");
4556
- if (ruleSelector === varSelector) {
4557
- return;
4558
- }
4559
- const trimmedSelector = selectors.join(",");
4560
- if (trimmedSelector === varSelector) {
4561
- return;
4562
- }
4563
- const selectorsWithoutVarRoot = selectors.map((selector) => {
4564
- const res = selector.split(varSelector).filter(Boolean);
4565
- return res.join("");
4566
- }).filter(Boolean);
4567
- if (selectorsWithoutVarRoot.length === 0)
4568
- return;
4569
- rule.selector = selectorsWithoutVarRoot.join(", ");
4570
- });
4571
- return root.toString();
4572
- }
4573
-
4574
4715
  // src/generator.ts
4575
4716
  var Generator = class extends import_core5.Context {
4576
4717
  constructor(conf) {
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import { Context as Context2 } from "@pandacss/core";
3
3
  import { match as match11 } from "ts-pattern";
4
4
 
5
5
  // src/artifacts/setup-artifacts.ts
6
- import outdent43 from "outdent";
6
+ import outdent44 from "outdent";
7
7
 
8
8
  // src/artifacts/js/conditions.ts
9
9
  import outdent from "outdent";
@@ -2740,6 +2740,11 @@ function generatePackageJson(ctx) {
2740
2740
  require: ctx.file.ext(`./recipes/index`),
2741
2741
  import: ctx.file.ext(`./recipes/index`)
2742
2742
  },
2743
+ "./themes": {
2744
+ types: ctx.file.extDts("./themes/index"),
2745
+ require: ctx.file.ext(`./themes/index`),
2746
+ import: ctx.file.ext(`./themes/index`)
2747
+ },
2743
2748
  "./tokens": {
2744
2749
  types: ctx.file.extDts("./tokens/index"),
2745
2750
  require: ctx.file.ext(`./tokens/index`),
@@ -3479,7 +3484,7 @@ var selectors_d_ts_default = {
3479
3484
 
3480
3485
  // src/artifacts/generated/static-css.d.ts.json
3481
3486
  var static_css_d_ts_default = {
3482
- content: "interface WithConditions {\n /**\n * The css conditions to generate for the rule.\n * @example ['hover', 'focus']\n */\n conditions?: string[]\n responsive?: boolean\n}\n\nexport interface CssRule extends WithConditions {\n /**\n * The css properties to generate utilities for.\n * @example ['margin', 'padding']\n */\n properties: {\n [property: string]: Array<string | number>\n }\n}\n\ninterface RecipeRuleVariants {\n [variant: string]: boolean | string[]\n}\n\nexport type RecipeRule = '*' | (RecipeRuleVariants & WithConditions)\nexport type PatternRule = '*' | CssRule\n\nexport interface StaticCssOptions {\n /**\n * The css utility classes to generate.\n */\n css?: CssRule[]\n /**\n * The css recipes to generate.\n */\n recipes?:\n | '*'\n | {\n [recipe: string]: RecipeRule[]\n }\n /**\n * The css patterns to generate.\n */\n patterns?: {\n [pattern: string]: PatternRule[]\n }\n}\n"
3487
+ content: "interface WithConditions {\n /**\n * The css conditions to generate for the rule.\n * @example ['hover', 'focus']\n */\n conditions?: string[]\n responsive?: boolean\n}\n\nexport interface CssRule extends WithConditions {\n /**\n * The css properties to generate utilities for.\n * @example ['margin', 'padding']\n */\n properties: {\n [property: string]: Array<string | number>\n }\n}\n\ninterface RecipeRuleVariants {\n [variant: string]: boolean | string[]\n}\n\nexport type RecipeRule = '*' | (RecipeRuleVariants & WithConditions)\nexport type PatternRule = '*' | CssRule\n\nexport interface StaticCssOptions {\n /**\n * The css utility classes to generate.\n */\n css?: CssRule[]\n /**\n * The css recipes to generate.\n */\n recipes?:\n | '*'\n | {\n [recipe: string]: RecipeRule[]\n }\n /**\n * The css patterns to generate.\n */\n patterns?: {\n [pattern: string]: PatternRule[]\n }\n /**\n * The CSS themes to generate\n */\n themes?: string[]\n}\n"
3483
3488
  };
3484
3489
 
3485
3490
  // src/artifacts/generated/system-types.d.ts.json
@@ -3803,6 +3808,228 @@ function generateTokenTypes(ctx) {
3803
3808
  return outdent42.string(Array.from(set).join("\n\n"));
3804
3809
  }
3805
3810
 
3811
+ // src/artifacts/js/themes.ts
3812
+ import { compact as compact2 } from "@pandacss/shared";
3813
+ import outdent43 from "outdent";
3814
+
3815
+ // src/artifacts/css/token-css.ts
3816
+ import { expandNestedCss, extractParentSelectors, stringify as stringify3 } from "@pandacss/core";
3817
+ import { logger } from "@pandacss/logger";
3818
+ import postcss, { CssSyntaxError } from "postcss";
3819
+ function generateTokenCss(ctx, sheet) {
3820
+ const { config, conditions, tokens } = ctx;
3821
+ const { cssVarRoot, staticCss } = config;
3822
+ const root = cssVarRoot;
3823
+ const results = [];
3824
+ const allowed = staticCss?.themes;
3825
+ let themeVariants = [];
3826
+ if (allowed) {
3827
+ const keys = Object.keys(config.themes ?? {});
3828
+ themeVariants = allowed.includes("*") ? keys : keys.filter((key) => allowed.includes(key));
3829
+ }
3830
+ const themeConds = themeVariants.map((key) => conditions.getThemeName(key));
3831
+ const themePrefix = ctx.conditions.getThemeName("");
3832
+ for (const [key, values] of tokens.view.vars.entries()) {
3833
+ const isThemeSkipped = key.startsWith(themePrefix) && !themeConds.some((condName) => key.startsWith(condName));
3834
+ if (isThemeSkipped) {
3835
+ continue;
3836
+ }
3837
+ const css2 = stringifyVars({ values, conditionKey: key, root, conditions });
3838
+ if (css2) {
3839
+ results.push(css2);
3840
+ }
3841
+ }
3842
+ let css = results.join("\n\n");
3843
+ css = "\n\n" + cleanupSelectors(css, root);
3844
+ if (ctx.hooks["cssgen:done"]) {
3845
+ css = ctx.hooks["cssgen:done"]({ artifact: "tokens", content: css }) ?? css;
3846
+ }
3847
+ sheet.layers.tokens.append(css);
3848
+ }
3849
+ function stringifyVars(options) {
3850
+ const { conditionKey, values, root, conditions } = options;
3851
+ const varsObj = Object.fromEntries(values);
3852
+ if (Object.keys(varsObj).length === 0)
3853
+ return;
3854
+ if (conditionKey === "base") {
3855
+ return stringify3({ [root]: varsObj });
3856
+ }
3857
+ const keys = conditionKey.split(":");
3858
+ if (keys.some((key) => !conditions.get(key)))
3859
+ return;
3860
+ const css = stringify3(varsObj);
3861
+ const mapped = keys.map((key) => conditions.get(key)).map((condition) => {
3862
+ const lastSegment = Array.isArray(condition) ? condition.at(-1) : condition;
3863
+ if (!lastSegment)
3864
+ return;
3865
+ const parent = extractParentSelectors(lastSegment);
3866
+ return parent ? `&${parent}` : lastSegment;
3867
+ }).filter(Boolean);
3868
+ const rule = getDeepestRule(root, mapped);
3869
+ if (!rule)
3870
+ return;
3871
+ getDeepestNode(rule)?.append(css);
3872
+ return expandNestedCss(rule.toString());
3873
+ }
3874
+ function getDeepestRule(root, selectors) {
3875
+ const rule = postcss.rule({ selector: "" });
3876
+ for (const selector of selectors) {
3877
+ const last = getDeepestNode(rule);
3878
+ const node = last ?? rule;
3879
+ if (selector.startsWith("@")) {
3880
+ const atRule = postcss.rule({ selector, nodes: [postcss.rule({ selector: `${root}&` })] });
3881
+ node.append(atRule);
3882
+ } else {
3883
+ node.append(postcss.rule({ selector }));
3884
+ }
3885
+ }
3886
+ return rule;
3887
+ }
3888
+ function getDeepestNode(node) {
3889
+ if (node.nodes && node.nodes.length) {
3890
+ return getDeepestNode(node.nodes[node.nodes.length - 1]);
3891
+ }
3892
+ return node;
3893
+ }
3894
+ var parse = (str) => {
3895
+ try {
3896
+ return postcss.parse(str);
3897
+ } catch (error) {
3898
+ if (error instanceof CssSyntaxError) {
3899
+ logger.error("tokens:process", error.showSourceCode(true));
3900
+ }
3901
+ }
3902
+ };
3903
+ function cleanupSelectors(css, varSelector) {
3904
+ const root = parse(css) ?? postcss.root();
3905
+ root.walkRules((rule) => {
3906
+ const selectors = [];
3907
+ rule.selectors.forEach((selector) => {
3908
+ selectors.push(selector.trim());
3909
+ });
3910
+ const ruleSelector = selectors.join(", ");
3911
+ if (ruleSelector === varSelector) {
3912
+ return;
3913
+ }
3914
+ const trimmedSelector = selectors.join(",");
3915
+ if (trimmedSelector === varSelector) {
3916
+ return;
3917
+ }
3918
+ const selectorsWithoutVarRoot = selectors.map((selector) => {
3919
+ const res = selector.split(varSelector).filter(Boolean);
3920
+ return res.join("");
3921
+ }).filter(Boolean);
3922
+ if (selectorsWithoutVarRoot.length === 0)
3923
+ return;
3924
+ rule.selector = selectorsWithoutVarRoot.join(", ");
3925
+ });
3926
+ return root.toString();
3927
+ }
3928
+
3929
+ // src/artifacts/js/themes.ts
3930
+ var getThemeId = (themeName) => "panda-theme-" + themeName;
3931
+ function generateThemes(ctx) {
3932
+ const { themes } = ctx.config;
3933
+ if (!themes)
3934
+ return;
3935
+ const { tokens, conditions } = ctx;
3936
+ return Object.entries(themes).map(([name, themeVariant]) => {
3937
+ const results = [];
3938
+ const condName = ctx.conditions.getThemeName(name);
3939
+ for (const [key, values] of tokens.view.vars.entries()) {
3940
+ if (key.startsWith(condName)) {
3941
+ const css = stringifyVars({ values, conditionKey: key, root: "", conditions });
3942
+ if (css) {
3943
+ results.push(css);
3944
+ }
3945
+ }
3946
+ }
3947
+ return {
3948
+ name,
3949
+ json: JSON.stringify(
3950
+ compact2({
3951
+ name,
3952
+ id: getThemeId(name),
3953
+ dataAttr: themeVariant.attribute || name,
3954
+ css: results.join("\n\n")
3955
+ }),
3956
+ null,
3957
+ 2
3958
+ )
3959
+ };
3960
+ });
3961
+ }
3962
+ function generateThemesIndex(ctx, files) {
3963
+ const { themes } = ctx.config;
3964
+ if (!themes)
3965
+ return;
3966
+ if (!files)
3967
+ return;
3968
+ const themeName = Object.keys(themes);
3969
+ return [
3970
+ {
3971
+ file: ctx.file.ext("index"),
3972
+ code: outdent43`
3973
+ export const getTheme = (themeName) => import('./' + themeName + '.json').then((m) => m.default)
3974
+
3975
+ export function injectTheme(el, theme) {
3976
+ const doc = el.ownerDocument || document
3977
+ let sheet = doc.getElementById(theme.id)
3978
+
3979
+ if (!sheet) {
3980
+ sheet = doc.createElement('style')
3981
+ sheet.setAttribute('type', 'text/css')
3982
+ sheet.setAttribute('id', theme.id)
3983
+ }
3984
+
3985
+ const head = doc.head || doc.getElementsByTagName('head')[0]
3986
+ if (!head) {
3987
+ throw new Error('No head found in doc')
3988
+ }
3989
+
3990
+ el.dataset.pandaTheme = theme.dataAttr
3991
+
3992
+ head.appendChild(sheet)
3993
+ sheet.innerHTML = theme.css
3994
+
3995
+ return sheet
3996
+ }
3997
+ `
3998
+ },
3999
+ {
4000
+ file: ctx.file.extDts("index"),
4001
+ code: outdent43`
4002
+ export type ThemeName = ${themeName.map((name) => `'${name}'`).join(" | ")}
4003
+ export type ThemeByName = {
4004
+ ${files.map((f) => {
4005
+ const theme = JSON.parse(f.json);
4006
+ if (!theme.css)
4007
+ return "";
4008
+ return `'${f.name}': {
4009
+ id: string,
4010
+ name: '${f.name}',
4011
+ dataAttr: '${theme.attribute || f.name}',
4012
+ css: string
4013
+ }`;
4014
+ }).join("\n")}
4015
+ }
4016
+
4017
+ export type Theme<T extends ThemeName> = ThemeByName[T]
4018
+
4019
+ /**
4020
+ * Dynamically import a theme by name
4021
+ */
4022
+ export declare function getTheme<T extends ThemeName>(themeName: T): Promise<ThemeByName[T]>
4023
+
4024
+ /**
4025
+ * Inject a theme stylesheet into the document
4026
+ */
4027
+ export declare function injectTheme(el: HTMLElement, theme: Theme<any>): HTMLStyleElement
4028
+ `
4029
+ }
4030
+ ];
4031
+ }
4032
+
3806
4033
  // src/artifacts/setup-artifacts.ts
3807
4034
  function setupHelpers(ctx) {
3808
4035
  const code = generateHelpers(ctx);
@@ -3958,8 +4185,8 @@ function setupRecipesIndex(ctx) {
3958
4185
  return;
3959
4186
  const fileNames = ctx.recipes.details.map((recipe) => recipe.dashName);
3960
4187
  const index = {
3961
- js: outdent43.string(fileNames.map((file) => ctx.file.exportStar(`./${file}`)).join("\n")),
3962
- dts: outdent43.string(fileNames.map((file) => ctx.file.exportTypeStar(`./${file}`)).join("\n"))
4188
+ js: outdent44.string(fileNames.map((file) => ctx.file.exportStar(`./${file}`)).join("\n")),
4189
+ dts: outdent44.string(fileNames.map((file) => ctx.file.exportTypeStar(`./${file}`)).join("\n"))
3963
4190
  };
3964
4191
  return {
3965
4192
  id: "recipes-index",
@@ -3990,8 +4217,8 @@ function setupPatternsIndex(ctx) {
3990
4217
  return;
3991
4218
  const fileNames = ctx.patterns.details.map((pattern) => pattern.dashName);
3992
4219
  const index = {
3993
- js: outdent43.string(fileNames.map((file) => ctx.file.exportStar(`./${file}`)).join("\n")),
3994
- dts: outdent43.string(fileNames.map((file) => ctx.file.exportTypeStar(`./${file}`)).join("\n"))
4220
+ js: outdent44.string(fileNames.map((file) => ctx.file.exportStar(`./${file}`)).join("\n")),
4221
+ dts: outdent44.string(fileNames.map((file) => ctx.file.exportTypeStar(`./${file}`)).join("\n"))
3995
4222
  };
3996
4223
  return {
3997
4224
  id: "patterns-index",
@@ -4081,15 +4308,15 @@ function setupJsxPatternsIndex(ctx) {
4081
4308
  const isStyleProp = !ctx.isTemplateLiteralSyntax;
4082
4309
  const patternNames = ctx.patterns.details.map((pattern) => pattern.dashName);
4083
4310
  const index = {
4084
- js: outdent43`
4311
+ js: outdent44`
4085
4312
  ${ctx.file.exportStar("./factory")}
4086
4313
  ${isStyleProp ? ctx.file.exportStar("./is-valid-prop") : ""}
4087
- ${isStyleProp ? outdent43.string(patternNames.map((file) => ctx.file.exportStar(`./${file}`)).join("\n")) : ""}
4314
+ ${isStyleProp ? outdent44.string(patternNames.map((file) => ctx.file.exportStar(`./${file}`)).join("\n")) : ""}
4088
4315
  `,
4089
- dts: outdent43`
4316
+ dts: outdent44`
4090
4317
  ${ctx.file.exportTypeStar("./factory")}
4091
4318
  ${isStyleProp ? ctx.file.exportTypeStar("./is-valid-prop") : ""}
4092
- ${isStyleProp ? outdent43.string(patternNames.map((file) => ctx.file.exportTypeStar(`./${file}`)).join("\n")) : ""}
4319
+ ${isStyleProp ? outdent44.string(patternNames.map((file) => ctx.file.exportTypeStar(`./${file}`)).join("\n")) : ""}
4093
4320
  ${ctx.file.exportType([ctx.jsx.typeName, ctx.jsx.componentName].join(", "), "../types/jsx")}
4094
4321
  `
4095
4322
  };
@@ -4104,13 +4331,13 @@ function setupJsxPatternsIndex(ctx) {
4104
4331
  }
4105
4332
  function setupCssIndex(ctx) {
4106
4333
  const index = {
4107
- js: outdent43`
4334
+ js: outdent44`
4108
4335
  ${ctx.file.exportStar("./css")}
4109
4336
  ${ctx.file.exportStar("./cx")}
4110
4337
  ${ctx.isTemplateLiteralSyntax ? "" : ctx.file.exportStar("./cva")}
4111
4338
  ${ctx.isTemplateLiteralSyntax ? "" : ctx.file.exportStar("./sva")}
4112
4339
  `,
4113
- dts: outdent43`
4340
+ dts: outdent44`
4114
4341
  ${ctx.file.exportTypeStar("./css")}
4115
4342
  ${ctx.file.exportTypeStar("./cx")}
4116
4343
  ${ctx.isTemplateLiteralSyntax ? "" : ctx.file.exportTypeStar("./cva")}
@@ -4134,6 +4361,19 @@ function setupPackageJson(ctx) {
4134
4361
  files: [{ file: "package.json", code: generatePackageJson(ctx) }]
4135
4362
  };
4136
4363
  }
4364
+ function setupThemes(ctx) {
4365
+ const { themes } = ctx.config;
4366
+ if (!themes)
4367
+ return;
4368
+ const files = generateThemes(ctx);
4369
+ if (!files)
4370
+ return;
4371
+ return {
4372
+ id: "themes",
4373
+ dir: ctx.paths.themes,
4374
+ files: files.flatMap((file) => [{ file: [file.name, "json"].join("."), code: file.json }]).concat(generateThemesIndex(ctx, files) ?? [])
4375
+ };
4376
+ }
4137
4377
  var getAffectedArtifacts = (ids) => {
4138
4378
  if (!ids)
4139
4379
  return;
@@ -4202,7 +4442,8 @@ var entries = [
4202
4442
  ["jsx-patterns", setupJsxPatterns],
4203
4443
  ["jsx-patterns-index", setupJsxPatternsIndex],
4204
4444
  ["css-index", setupCssIndex],
4205
- ["package.json", setupPackageJson]
4445
+ ["package.json", setupPackageJson],
4446
+ ["themes", setupThemes]
4206
4447
  ];
4207
4448
  var getMatchingArtifacts = (ctx, filters) => {
4208
4449
  const ids = filters?.ids;
@@ -4277,14 +4518,14 @@ var generateGlobalCss = (ctx, sheet) => {
4277
4518
  };
4278
4519
 
4279
4520
  // src/artifacts/css/keyframe-css.ts
4280
- import { stringify as stringify3 } from "@pandacss/core";
4521
+ import { stringify as stringify4 } from "@pandacss/core";
4281
4522
  function generateKeyframeCss(ctx, sheet) {
4282
4523
  const { keyframes = {} } = ctx.config.theme ?? {};
4283
4524
  const result = {};
4284
4525
  for (const [name, definition] of Object.entries(keyframes)) {
4285
4526
  result[`@keyframes ${name}`] = definition;
4286
4527
  }
4287
- let css = stringify3(sheet.serialize(result));
4528
+ let css = stringify4(sheet.serialize(result));
4288
4529
  if (ctx.hooks["cssgen:done"]) {
4289
4530
  css = ctx.hooks["cssgen:done"]({ artifact: "keyframes", content: css }) ?? css;
4290
4531
  }
@@ -4292,7 +4533,7 @@ function generateKeyframeCss(ctx, sheet) {
4292
4533
  }
4293
4534
 
4294
4535
  // src/artifacts/css/parser-css.ts
4295
- import { logger } from "@pandacss/logger";
4536
+ import { logger as logger2 } from "@pandacss/logger";
4296
4537
  var generateParserCss = (ctx, decoder) => {
4297
4538
  if (!decoder)
4298
4539
  return "";
@@ -4303,7 +4544,7 @@ var generateParserCss = (ctx, decoder) => {
4303
4544
  const css = sheet.toCss({ minify, optimize });
4304
4545
  return css;
4305
4546
  } catch (err) {
4306
- logger.error("serializer:css", "Failed to serialize CSS: " + err);
4547
+ logger2.error("serializer:css", "Failed to serialize CSS: " + err);
4307
4548
  return "";
4308
4549
  }
4309
4550
  };
@@ -4435,106 +4676,6 @@ var generateStaticCss = (ctx, sheet) => {
4435
4676
  }
4436
4677
  };
4437
4678
 
4438
- // src/artifacts/css/token-css.ts
4439
- import { expandNestedCss, extractParentSelectors, stringify as stringify4 } from "@pandacss/core";
4440
- import postcss, { CssSyntaxError } from "postcss";
4441
- import { logger as logger2 } from "@pandacss/logger";
4442
- function generateTokenCss(ctx, sheet) {
4443
- const {
4444
- config: { cssVarRoot },
4445
- conditions,
4446
- tokens
4447
- } = ctx;
4448
- const root = cssVarRoot;
4449
- const results = [];
4450
- for (const [key, values] of tokens.view.vars.entries()) {
4451
- const varsObj = Object.fromEntries(values);
4452
- if (Object.keys(varsObj).length === 0)
4453
- continue;
4454
- if (key === "base") {
4455
- const css2 = stringify4({ [root]: varsObj });
4456
- results.push(css2);
4457
- } else {
4458
- const keys = key.split(":");
4459
- const css2 = stringify4(varsObj);
4460
- const mapped = keys.map((key2) => conditions.get(key2)).filter(Boolean).map((condition) => {
4461
- const lastSegment = Array.isArray(condition) ? condition.at(-1) : condition;
4462
- if (!lastSegment)
4463
- return;
4464
- const parent = extractParentSelectors(lastSegment);
4465
- return parent ? `&${parent}` : lastSegment;
4466
- }).filter(Boolean);
4467
- if (!mapped.length)
4468
- return;
4469
- const rule = getDeepestRule(root, mapped);
4470
- if (!rule)
4471
- continue;
4472
- getDeepestNode(rule)?.append(css2);
4473
- results.push(expandNestedCss(rule.toString()));
4474
- }
4475
- }
4476
- let css = results.join("\n\n");
4477
- css = "\n\n" + cleanupSelectors(css, root);
4478
- if (ctx.hooks["cssgen:done"]) {
4479
- css = ctx.hooks["cssgen:done"]({ artifact: "tokens", content: css }) ?? css;
4480
- }
4481
- sheet.layers.tokens.append(css);
4482
- }
4483
- function getDeepestRule(root, selectors) {
4484
- const rule = postcss.rule({ selector: "" });
4485
- for (const selector of selectors) {
4486
- const last = getDeepestNode(rule);
4487
- const node = last ?? rule;
4488
- if (selector.startsWith("@")) {
4489
- const atRule = postcss.rule({ selector, nodes: [postcss.rule({ selector: `${root}&` })] });
4490
- node.append(atRule);
4491
- } else {
4492
- node.append(postcss.rule({ selector }));
4493
- }
4494
- }
4495
- return rule;
4496
- }
4497
- function getDeepestNode(node) {
4498
- if (node.nodes && node.nodes.length) {
4499
- return getDeepestNode(node.nodes[node.nodes.length - 1]);
4500
- }
4501
- return node;
4502
- }
4503
- var parse = (str) => {
4504
- try {
4505
- return postcss.parse(str);
4506
- } catch (error) {
4507
- if (error instanceof CssSyntaxError) {
4508
- logger2.error("tokens:process", error.showSourceCode(true));
4509
- }
4510
- }
4511
- };
4512
- function cleanupSelectors(css, varSelector) {
4513
- const root = parse(css) ?? postcss.root();
4514
- root.walkRules((rule) => {
4515
- const selectors = [];
4516
- rule.selectors.forEach((selector) => {
4517
- selectors.push(selector.trim());
4518
- });
4519
- const ruleSelector = selectors.join(", ");
4520
- if (ruleSelector === varSelector) {
4521
- return;
4522
- }
4523
- const trimmedSelector = selectors.join(",");
4524
- if (trimmedSelector === varSelector) {
4525
- return;
4526
- }
4527
- const selectorsWithoutVarRoot = selectors.map((selector) => {
4528
- const res = selector.split(varSelector).filter(Boolean);
4529
- return res.join("");
4530
- }).filter(Boolean);
4531
- if (selectorsWithoutVarRoot.length === 0)
4532
- return;
4533
- rule.selector = selectorsWithoutVarRoot.join(", ");
4534
- });
4535
- return root.toString();
4536
- }
4537
-
4538
4679
  // src/generator.ts
4539
4680
  var Generator = class extends Context2 {
4540
4681
  constructor(conf) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/generator",
3
- "version": "0.0.0-dev-20240315145057",
3
+ "version": "0.0.0-dev-20240315210222",
4
4
  "description": "The css generator for css panda",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -37,12 +37,12 @@
37
37
  "pluralize": "8.0.0",
38
38
  "postcss": "8.4.35",
39
39
  "ts-pattern": "5.0.8",
40
- "@pandacss/core": "0.0.0-dev-20240315145057",
41
- "@pandacss/is-valid-prop": "^0.0.0-dev-20240315145057",
42
- "@pandacss/logger": "0.0.0-dev-20240315145057",
43
- "@pandacss/shared": "0.0.0-dev-20240315145057",
44
- "@pandacss/token-dictionary": "0.0.0-dev-20240315145057",
45
- "@pandacss/types": "0.0.0-dev-20240315145057"
40
+ "@pandacss/core": "0.0.0-dev-20240315210222",
41
+ "@pandacss/is-valid-prop": "^0.0.0-dev-20240315210222",
42
+ "@pandacss/logger": "0.0.0-dev-20240315210222",
43
+ "@pandacss/shared": "0.0.0-dev-20240315210222",
44
+ "@pandacss/token-dictionary": "0.0.0-dev-20240315210222",
45
+ "@pandacss/types": "0.0.0-dev-20240315210222"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/pluralize": "0.0.33"