@pandacss/generator 0.0.0-dev-20230414155738 → 0.0.0-dev-20230415084325

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.ts CHANGED
@@ -42,6 +42,7 @@ declare const getEngine: (conf: LoadConfigResult) => {
42
42
  props: string[];
43
43
  baseName: string;
44
44
  jsx: (string | RegExp)[];
45
+ match: RegExp;
45
46
  }[];
46
47
  recipes: Record<string, _pandacss_types.AnyRecipeConfig>;
47
48
  getConfig: (name: string) => _pandacss_types.AnyRecipeConfig | undefined;
@@ -157,6 +158,7 @@ declare const createGenerator: (conf: LoadConfigResult) => {
157
158
  props: string[];
158
159
  baseName: string;
159
160
  jsx: (string | RegExp)[];
161
+ match: RegExp;
160
162
  }[];
161
163
  recipes: Record<string, _pandacss_types.AnyRecipeConfig>;
162
164
  getConfig: (name: string) => _pandacss_types.AnyRecipeConfig | undefined;
@@ -265,6 +267,7 @@ declare const createGenerator: (conf: LoadConfigResult) => {
265
267
  props: string[];
266
268
  baseName: string;
267
269
  jsx: (string | RegExp)[];
270
+ match: RegExp;
268
271
  })[];
269
272
  };
270
273
  getRecipeName: (jsx: string) => string;
package/dist/index.js CHANGED
@@ -498,27 +498,14 @@ function generateCvaFn(ctx) {
498
498
 
499
499
  function resolve(props) {
500
500
  const computedVariants = { ...defaultVariants, ...compact(props) }
501
- let result = { ...base }
501
+ let variantCss = { ...base }
502
502
  for (const [key, value] of Object.entries(computedVariants)) {
503
503
  if (variants[key]?.[value]) {
504
- result = mergeCss(result, variants[key][value])
504
+ variantCss = mergeCss(variantCss, variants[key][value])
505
505
  }
506
506
  }
507
-
508
- compoundVariants.forEach((compoundVariant) => {
509
- const isMatching = Object.entries(compoundVariant).every(([key, value]) => {
510
- if (key === 'css') return true
511
-
512
- const values = Array.isArray(value) ? value : [value]
513
- return values.some((value) => computedVariants[key] === value)
514
- })
515
-
516
- if (isMatching) {
517
- result = mergeCss(result, compoundVariant.css)
518
- }
519
- })
520
-
521
- return result
507
+ const compoundVariantCss = getCompoundVariantCss(compoundVariants, computedVariants)
508
+ return mergeCss(variantCss, compoundVariantCss)
522
509
  }
523
510
 
524
511
  function cvaFn(props) {
@@ -532,6 +519,33 @@ function generateCvaFn(ctx) {
532
519
  config,
533
520
  })
534
521
  }
522
+
523
+ export function getCompoundVariantCss(compoundVariants, variantMap) {
524
+ let result = {}
525
+ compoundVariants.forEach((compoundVariant) => {
526
+ const isMatching = Object.entries(compoundVariant).every(([key, value]) => {
527
+ if (key === 'css') return true
528
+
529
+ const values = Array.isArray(value) ? value : [value]
530
+ return values.some((value) => variantMap[key] === value)
531
+ })
532
+
533
+ if (isMatching) {
534
+ result = mergeCss(result, compoundVariant.css)
535
+ }
536
+ })
537
+
538
+ return result
539
+ }
540
+
541
+ export function assertCompoundVariant(name, compoundVariants, variants, prop) {
542
+ if (compoundVariants.length > 0 && typeof variants[prop] === 'object') {
543
+ throw new Error(
544
+ \`[recipe:\${name}:\${prop}] Conditions are not supported when using compound variants.\`,
545
+ )
546
+ }
547
+ }
548
+
535
549
  `,
536
550
  dts: import_outdent5.outdent`
537
551
  import type { RecipeCreatorFn } from '../types/recipe'
@@ -698,18 +712,15 @@ function generateRecipes(ctx) {
698
712
  name: "create-recipe",
699
713
  dts: "",
700
714
  js: import_outdent9.outdent`
701
- ${ctx.file.import("css, mergeCss", "../css/css")}
715
+ ${ctx.file.import("css", "../css/css")}
716
+ ${ctx.file.import("assertCompoundVariant, getCompoundVariantCss", "../css/cva")}
702
717
  ${ctx.file.import("cx", "../css/cx")}
703
- ${ctx.file.import("createCss, withoutSpace, compact", "../helpers")}
718
+ ${ctx.file.import("compact, createCss, withoutSpace", "../helpers")}
704
719
 
705
720
  export const createRecipe = (name, defaultVariants, compoundVariants) => {
706
721
  return (variants) => {
707
722
  const transform = (prop, value) => {
708
- if (compoundVariants.length > 0 && typeof variants[prop] === 'object') {
709
- throw new Error(
710
- \`[recipe:\${name}:\${prop}:\${value}] Conditions are not supported when using compound variants.\`,
711
- )
712
- }
723
+ assertCompoundVariant(name, compoundVariants, variants, prop)
713
724
 
714
725
  if (value === '__ignore__') {
715
726
  return { className: name }
@@ -719,36 +730,23 @@ function generateRecipes(ctx) {
719
730
  return { className: \`\${name}--\${prop}${separator}\${value}\` }
720
731
  }
721
732
 
722
- const context = {
733
+ const recipeCss = createCss({
723
734
  hash: ${hash ? "true" : "false"},
724
735
  utility: {
725
736
  prefix: ${prefix ? JSON.stringify(prefix) : void 0},
726
737
  transform,
727
738
  }
728
- }
739
+ })
729
740
 
730
- const recipeCss = createCss(context)
731
741
  const recipeStyles = {
732
742
  [name]: '__ignore__',
733
743
  ...defaultVariants,
734
744
  ...compact(variants),
735
745
  }
736
746
 
737
- let result = {}
738
- compoundVariants.forEach((compoundVariant) => {
739
- const isMatching = Object.entries(compoundVariant).every(([key, value]) => {
740
- if (key === 'css') return true
741
-
742
- const values = Array.isArray(value) ? value : [value]
743
- return values.some((value) => recipeStyles[key] === value)
744
- })
745
-
746
- if (isMatching) {
747
- result = mergeCss(result, compoundVariant.css)
748
- }
749
- })
747
+ const compoundVariantStyles = getCompoundVariantCss(compoundVariants, recipeStyles)
750
748
 
751
- return cx(recipeCss(recipeStyles), css(result))
749
+ return cx(recipeCss(recipeStyles), css(compoundVariantStyles))
752
750
  }
753
751
  }
754
752
  `
@@ -2289,7 +2287,8 @@ var generateParserCss = (ctx) => (result) => (0, import_func.pipe)(
2289
2287
  for (const pattern of patternSet) {
2290
2288
  (0, import_ts_pattern5.match)(pattern).with({ type: "jsx-pattern", name: import_ts_pattern5.P.string }, ({ name: name2 }) => {
2291
2289
  pattern.data.forEach((data) => {
2292
- const styleProps = patterns.transform(name2, flattenStyles(data));
2290
+ const fnName = patterns.getFnName(name2);
2291
+ const styleProps = patterns.transform(fnName, flattenStyles(data));
2293
2292
  sheet.processAtomic(styleProps);
2294
2293
  });
2295
2294
  }).otherwise(() => {
@@ -2444,6 +2443,10 @@ var getPatternEngine = (config) => {
2444
2443
  // src/engines/recipe.ts
2445
2444
  var import_shared7 = require("@pandacss/shared");
2446
2445
  var import_lil_fp3 = require("lil-fp");
2446
+ var mergeRegex = (item) => {
2447
+ const regex = item.map((item2) => typeof item2 === "string" ? item2 : item2.source).join("|");
2448
+ return new RegExp(regex);
2449
+ };
2447
2450
  var getRecipeEngine = (config) => {
2448
2451
  return (0, import_lil_fp3.pipe)(
2449
2452
  { recipes: config.theme?.recipes ?? {} },
@@ -2458,27 +2461,28 @@ var getRecipeEngine = (config) => {
2458
2461
  });
2459
2462
  }),
2460
2463
  import_lil_fp3.Obj.bind("nodes", ({ recipes }) => {
2461
- return Object.entries(recipes).map(([name, recipe]) => ({
2462
- type: "recipe",
2463
- name: (0, import_shared7.capitalize)(name),
2464
- props: Object.keys(recipe.variants ?? {}),
2465
- baseName: name,
2466
- jsx: recipe.jsx ?? [(0, import_shared7.capitalize)(name)]
2467
- }));
2464
+ return Object.entries(recipes).map(([name, recipe]) => {
2465
+ const jsx = recipe.jsx ?? [(0, import_shared7.capitalize)(name)];
2466
+ const match6 = mergeRegex(jsx);
2467
+ return {
2468
+ type: "recipe",
2469
+ name: (0, import_shared7.capitalize)(name),
2470
+ props: Object.keys(recipe.variants ?? {}),
2471
+ baseName: name,
2472
+ jsx,
2473
+ match: match6
2474
+ };
2475
+ });
2468
2476
  }),
2469
2477
  import_lil_fp3.Obj.bind("getFnName", ({ nodes }) => {
2470
2478
  return (jsx) => {
2471
- const recipe = nodes.find((node) => {
2472
- return node.jsx.some((tag) => typeof tag === "string" ? tag === jsx : tag.test(jsx));
2473
- });
2479
+ const recipe = nodes.find((node) => node.match.test(jsx));
2474
2480
  return recipe?.baseName ?? (0, import_shared7.uncapitalize)(jsx);
2475
2481
  };
2476
2482
  }),
2477
2483
  import_lil_fp3.Obj.bind("splitProps", ({ nodes }) => {
2478
2484
  return (name, props) => {
2479
- const recipe = nodes.find((node) => {
2480
- return node.jsx.some((tag) => typeof tag === "string" ? tag === name : tag.test(name));
2481
- });
2485
+ const recipe = nodes.find((node) => node.match.test(name));
2482
2486
  if (!recipe)
2483
2487
  return [{}, props];
2484
2488
  return (0, import_shared7.splitProps)(props, recipe.props);
package/dist/index.mjs CHANGED
@@ -467,27 +467,14 @@ function generateCvaFn(ctx) {
467
467
 
468
468
  function resolve(props) {
469
469
  const computedVariants = { ...defaultVariants, ...compact(props) }
470
- let result = { ...base }
470
+ let variantCss = { ...base }
471
471
  for (const [key, value] of Object.entries(computedVariants)) {
472
472
  if (variants[key]?.[value]) {
473
- result = mergeCss(result, variants[key][value])
473
+ variantCss = mergeCss(variantCss, variants[key][value])
474
474
  }
475
475
  }
476
-
477
- compoundVariants.forEach((compoundVariant) => {
478
- const isMatching = Object.entries(compoundVariant).every(([key, value]) => {
479
- if (key === 'css') return true
480
-
481
- const values = Array.isArray(value) ? value : [value]
482
- return values.some((value) => computedVariants[key] === value)
483
- })
484
-
485
- if (isMatching) {
486
- result = mergeCss(result, compoundVariant.css)
487
- }
488
- })
489
-
490
- return result
476
+ const compoundVariantCss = getCompoundVariantCss(compoundVariants, computedVariants)
477
+ return mergeCss(variantCss, compoundVariantCss)
491
478
  }
492
479
 
493
480
  function cvaFn(props) {
@@ -501,6 +488,33 @@ function generateCvaFn(ctx) {
501
488
  config,
502
489
  })
503
490
  }
491
+
492
+ export function getCompoundVariantCss(compoundVariants, variantMap) {
493
+ let result = {}
494
+ compoundVariants.forEach((compoundVariant) => {
495
+ const isMatching = Object.entries(compoundVariant).every(([key, value]) => {
496
+ if (key === 'css') return true
497
+
498
+ const values = Array.isArray(value) ? value : [value]
499
+ return values.some((value) => variantMap[key] === value)
500
+ })
501
+
502
+ if (isMatching) {
503
+ result = mergeCss(result, compoundVariant.css)
504
+ }
505
+ })
506
+
507
+ return result
508
+ }
509
+
510
+ export function assertCompoundVariant(name, compoundVariants, variants, prop) {
511
+ if (compoundVariants.length > 0 && typeof variants[prop] === 'object') {
512
+ throw new Error(
513
+ \`[recipe:\${name}:\${prop}] Conditions are not supported when using compound variants.\`,
514
+ )
515
+ }
516
+ }
517
+
504
518
  `,
505
519
  dts: outdent5`
506
520
  import type { RecipeCreatorFn } from '../types/recipe'
@@ -667,18 +681,15 @@ function generateRecipes(ctx) {
667
681
  name: "create-recipe",
668
682
  dts: "",
669
683
  js: outdent9`
670
- ${ctx.file.import("css, mergeCss", "../css/css")}
684
+ ${ctx.file.import("css", "../css/css")}
685
+ ${ctx.file.import("assertCompoundVariant, getCompoundVariantCss", "../css/cva")}
671
686
  ${ctx.file.import("cx", "../css/cx")}
672
- ${ctx.file.import("createCss, withoutSpace, compact", "../helpers")}
687
+ ${ctx.file.import("compact, createCss, withoutSpace", "../helpers")}
673
688
 
674
689
  export const createRecipe = (name, defaultVariants, compoundVariants) => {
675
690
  return (variants) => {
676
691
  const transform = (prop, value) => {
677
- if (compoundVariants.length > 0 && typeof variants[prop] === 'object') {
678
- throw new Error(
679
- \`[recipe:\${name}:\${prop}:\${value}] Conditions are not supported when using compound variants.\`,
680
- )
681
- }
692
+ assertCompoundVariant(name, compoundVariants, variants, prop)
682
693
 
683
694
  if (value === '__ignore__') {
684
695
  return { className: name }
@@ -688,36 +699,23 @@ function generateRecipes(ctx) {
688
699
  return { className: \`\${name}--\${prop}${separator}\${value}\` }
689
700
  }
690
701
 
691
- const context = {
702
+ const recipeCss = createCss({
692
703
  hash: ${hash ? "true" : "false"},
693
704
  utility: {
694
705
  prefix: ${prefix ? JSON.stringify(prefix) : void 0},
695
706
  transform,
696
707
  }
697
- }
708
+ })
698
709
 
699
- const recipeCss = createCss(context)
700
710
  const recipeStyles = {
701
711
  [name]: '__ignore__',
702
712
  ...defaultVariants,
703
713
  ...compact(variants),
704
714
  }
705
715
 
706
- let result = {}
707
- compoundVariants.forEach((compoundVariant) => {
708
- const isMatching = Object.entries(compoundVariant).every(([key, value]) => {
709
- if (key === 'css') return true
710
-
711
- const values = Array.isArray(value) ? value : [value]
712
- return values.some((value) => recipeStyles[key] === value)
713
- })
714
-
715
- if (isMatching) {
716
- result = mergeCss(result, compoundVariant.css)
717
- }
718
- })
716
+ const compoundVariantStyles = getCompoundVariantCss(compoundVariants, recipeStyles)
719
717
 
720
- return cx(recipeCss(recipeStyles), css(result))
718
+ return cx(recipeCss(recipeStyles), css(compoundVariantStyles))
721
719
  }
722
720
  }
723
721
  `
@@ -2258,7 +2256,8 @@ var generateParserCss = (ctx) => (result) => pipe(
2258
2256
  for (const pattern of patternSet) {
2259
2257
  match5(pattern).with({ type: "jsx-pattern", name: P.string }, ({ name: name2 }) => {
2260
2258
  pattern.data.forEach((data) => {
2261
- const styleProps = patterns.transform(name2, flattenStyles(data));
2259
+ const fnName = patterns.getFnName(name2);
2260
+ const styleProps = patterns.transform(fnName, flattenStyles(data));
2262
2261
  sheet.processAtomic(styleProps);
2263
2262
  });
2264
2263
  }).otherwise(() => {
@@ -2413,6 +2412,10 @@ var getPatternEngine = (config) => {
2413
2412
  // src/engines/recipe.ts
2414
2413
  import { capitalize as capitalize4, dashCase as dashCase2, splitProps, uncapitalize as uncapitalize2 } from "@pandacss/shared";
2415
2414
  import { Obj as Obj3, pipe as pipe4 } from "lil-fp";
2415
+ var mergeRegex = (item) => {
2416
+ const regex = item.map((item2) => typeof item2 === "string" ? item2 : item2.source).join("|");
2417
+ return new RegExp(regex);
2418
+ };
2416
2419
  var getRecipeEngine = (config) => {
2417
2420
  return pipe4(
2418
2421
  { recipes: config.theme?.recipes ?? {} },
@@ -2427,27 +2430,28 @@ var getRecipeEngine = (config) => {
2427
2430
  });
2428
2431
  }),
2429
2432
  Obj3.bind("nodes", ({ recipes }) => {
2430
- return Object.entries(recipes).map(([name, recipe]) => ({
2431
- type: "recipe",
2432
- name: capitalize4(name),
2433
- props: Object.keys(recipe.variants ?? {}),
2434
- baseName: name,
2435
- jsx: recipe.jsx ?? [capitalize4(name)]
2436
- }));
2433
+ return Object.entries(recipes).map(([name, recipe]) => {
2434
+ const jsx = recipe.jsx ?? [capitalize4(name)];
2435
+ const match6 = mergeRegex(jsx);
2436
+ return {
2437
+ type: "recipe",
2438
+ name: capitalize4(name),
2439
+ props: Object.keys(recipe.variants ?? {}),
2440
+ baseName: name,
2441
+ jsx,
2442
+ match: match6
2443
+ };
2444
+ });
2437
2445
  }),
2438
2446
  Obj3.bind("getFnName", ({ nodes }) => {
2439
2447
  return (jsx) => {
2440
- const recipe = nodes.find((node) => {
2441
- return node.jsx.some((tag) => typeof tag === "string" ? tag === jsx : tag.test(jsx));
2442
- });
2448
+ const recipe = nodes.find((node) => node.match.test(jsx));
2443
2449
  return recipe?.baseName ?? uncapitalize2(jsx);
2444
2450
  };
2445
2451
  }),
2446
2452
  Obj3.bind("splitProps", ({ nodes }) => {
2447
2453
  return (name, props) => {
2448
- const recipe = nodes.find((node) => {
2449
- return node.jsx.some((tag) => typeof tag === "string" ? tag === name : tag.test(name));
2450
- });
2454
+ const recipe = nodes.find((node) => node.match.test(name));
2451
2455
  if (!recipe)
2452
2456
  return [{}, props];
2453
2457
  return splitProps(props, recipe.props);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/generator",
3
- "version": "0.0.0-dev-20230414155738",
3
+ "version": "0.0.0-dev-20230415084325",
4
4
  "description": "The css generator for css panda",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -20,16 +20,16 @@
20
20
  "pluralize": "8.0.0",
21
21
  "postcss": "8.4.21",
22
22
  "ts-pattern": "4.2.2",
23
- "@pandacss/core": "0.0.0-dev-20230414155738",
24
- "@pandacss/logger": "0.0.0-dev-20230414155738",
25
- "@pandacss/is-valid-prop": "0.0.0-dev-20230414155738",
26
- "@pandacss/shared": "0.0.0-dev-20230414155738",
27
- "@pandacss/types": "0.0.0-dev-20230414155738",
28
- "@pandacss/token-dictionary": "0.0.0-dev-20230414155738"
23
+ "@pandacss/core": "0.0.0-dev-20230415084325",
24
+ "@pandacss/logger": "0.0.0-dev-20230415084325",
25
+ "@pandacss/is-valid-prop": "0.0.0-dev-20230415084325",
26
+ "@pandacss/shared": "0.0.0-dev-20230415084325",
27
+ "@pandacss/types": "0.0.0-dev-20230415084325",
28
+ "@pandacss/token-dictionary": "0.0.0-dev-20230415084325"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/pluralize": "0.0.29",
32
- "@pandacss/fixture": "0.0.0-dev-20230414155738"
32
+ "@pandacss/fixture": "0.0.0-dev-20230415084325"
33
33
  },
34
34
  "scripts": {
35
35
  "prebuild": "tsx scripts/prebuild.ts",