@pandacss/generator 0.7.0 → 0.9.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.mjs CHANGED
@@ -388,7 +388,7 @@ var generateStaticCss = (ctx) => {
388
388
  return [];
389
389
  return Object.keys(values);
390
390
  },
391
- getRecipeKeys: (recipe) => recipes.details.find((detail) => detail.config.name === recipe)?.variantKeyMap ?? {}
391
+ getRecipeKeys: (recipe) => recipes.details.find((detail) => detail.baseName === recipe)?.variantKeyMap ?? {}
392
392
  });
393
393
  results.css.forEach((css2) => {
394
394
  sheet.processAtomic(css2);
@@ -398,7 +398,7 @@ var generateStaticCss = (ctx) => {
398
398
  const recipeConfig = recipes.getConfig(name);
399
399
  if (!recipeConfig)
400
400
  return;
401
- sheet.processRecipe(recipeConfig, value);
401
+ sheet.processRecipe(name, recipeConfig, value);
402
402
  });
403
403
  });
404
404
  const output = sheet.toCss({ optimize });
@@ -593,16 +593,22 @@ function generateCssFn(ctx) {
593
593
  return {
594
594
  dts: outdent4`
595
595
  import type { SystemStyleObject } from '../types'
596
- export declare function css(styles: SystemStyleObject): string
596
+
597
+ interface CssFunction {
598
+ (styles: SystemStyleObject): string
599
+ raw: (styles: SystemStyleObject) => SystemStyleObject
600
+ }
601
+
602
+ export declare const css: CssFunction;
597
603
  `,
598
604
  js: outdent4`
599
605
  ${ctx.file.import("createCss, createMergeCss, hypenateProperty, withoutSpace", "../helpers")}
600
606
  ${ctx.file.import("sortConditions, finalizeConditions", "./conditions")}
601
607
 
602
608
  const classNameMap = ${stringify(utility.entries())}
603
-
609
+
604
610
  const shorthands = ${stringify(utility.shorthands)}
605
-
611
+
606
612
  const breakpointKeys = ${JSON.stringify(conditions.breakpoints.keys)}
607
613
 
608
614
  const hasShorthand = ${utility.hasShorthand ? "true" : "false"}
@@ -632,6 +638,7 @@ function generateCssFn(ctx) {
632
638
  }
633
639
 
634
640
  export const css = createCss(context)
641
+ css.raw = (styles) => styles
635
642
 
636
643
  export const { mergeCss, assignCss } = createMergeCss(context)
637
644
  `
@@ -855,7 +862,7 @@ function generatePattern(ctx) {
855
862
  if (ctx.patterns.isEmpty())
856
863
  return;
857
864
  return ctx.patterns.details.map((pattern) => {
858
- const { name, config, dashName, upperName, styleFnName, blocklistType } = pattern;
865
+ const { baseName, config, dashName, upperName, styleFnName, blocklistType } = pattern;
859
866
  const { properties, transform, strict, description } = config;
860
867
  const transformFn = stringify2({ transform }) ?? "";
861
868
  const helperImports = ["mapObject"];
@@ -891,12 +898,17 @@ function generatePattern(ctx) {
891
898
  }).join("\n ")}
892
899
  }
893
900
 
894
- ${strict ? outdent10`export declare function ${name}(options: ${upperName}Properties): string` : outdent10`
901
+ ${strict ? outdent10`export declare function ${baseName}(options: ${upperName}Properties): string` : outdent10`
895
902
 
896
903
  type ${upperName}Options = ${upperName}Properties & Omit<SystemStyleObject, keyof ${upperName}Properties ${blocklistType}>
897
904
 
905
+ interface ${upperName}PatternFn {
906
+ (options?: ${upperName}Options): string
907
+ raw: (options: ${upperName}Options) => ${upperName}Options
908
+ }
909
+
898
910
  ${description ? `/** ${description} */` : ""}
899
- export declare function ${name}(options?: ${upperName}Options): string
911
+ export declare const ${baseName}: ${upperName}PatternFn;
900
912
  `}
901
913
 
902
914
  `,
@@ -904,12 +916,13 @@ function generatePattern(ctx) {
904
916
  ${ctx.file.import(helperImports.join(", "), "../helpers")}
905
917
  ${ctx.file.import("css", "../css/index")}
906
918
 
907
- const ${name}Config = ${transformFn.replace(`{transform`, `{
919
+ const ${baseName}Config = ${transformFn.replace(`{transform`, `{
908
920
  transform`)}
909
921
 
910
- export const ${styleFnName} = (styles = {}) => ${name}Config.transform(styles, { map: mapObject })
922
+ export const ${styleFnName} = (styles = {}) => ${baseName}Config.transform(styles, { map: mapObject })
911
923
 
912
- export const ${name} = (styles) => css(${styleFnName}(styles))
924
+ export const ${baseName} = (styles) => css(${styleFnName}(styles))
925
+ ${baseName}.raw = (styles) => styles
913
926
  `
914
927
  };
915
928
  });
@@ -974,29 +987,26 @@ function generateRecipes(ctx) {
974
987
  return [
975
988
  createRecipeFn,
976
989
  ...ctx.recipes.details.map((recipe) => {
977
- const { config, upperName, variantKeyMap, dashName } = recipe;
978
- const { name, description, defaultVariants, compoundVariants } = config;
990
+ const { baseName, config, upperName, variantKeyMap, dashName } = recipe;
991
+ const { description, defaultVariants, compoundVariants } = config;
979
992
  return {
980
993
  name: dashName,
981
994
  js: outdent11`
982
995
  ${ctx.file.import("splitProps", "../helpers")}
983
996
  ${ctx.file.import("createRecipe", "./create-recipe")}
984
997
 
985
- const ${name}Fn = createRecipe('${name}', ${stringify3(defaultVariants ?? {})}, ${stringify3(
998
+ const ${baseName}Fn = createRecipe('${baseName}', ${stringify3(defaultVariants ?? {})}, ${stringify3(
986
999
  compoundVariants ?? []
987
1000
  )})
988
1001
 
989
- const variantKeys = ${stringify3(Object.keys(variantKeyMap))}
990
-
991
- function splitVariantProps(props) {
992
- return splitProps(props, variantKeys)
993
- }
994
-
995
- export const ${name} = Object.assign(${name}Fn, {
1002
+ export const ${baseName} = Object.assign(${baseName}Fn, {
996
1003
  __recipe__: true,
997
- variantKeys,
1004
+ raw: (props) => props,
1005
+ variantKeys: ${stringify3(Object.keys(variantKeyMap))},
998
1006
  variantMap: ${stringify3(variantKeyMap)},
999
- splitVariantProps,
1007
+ splitVariantProps(props) {
1008
+ return splitProps(props, ${stringify3(Object.keys(variantKeyMap))})
1009
+ },
1000
1010
  })
1001
1011
  `,
1002
1012
  dts: outdent11`
@@ -1023,13 +1033,14 @@ function generateRecipes(ctx) {
1023
1033
  interface ${upperName}Recipe {
1024
1034
  __type: ${upperName}VariantProps
1025
1035
  (props?: ${upperName}VariantProps): string
1036
+ raw: (props?: ${upperName}VariantProps) => ${upperName}VariantProps
1026
1037
  variantMap: ${upperName}VariantMap
1027
1038
  variantKeys: Array<keyof ${upperName}Variant>
1028
1039
  splitVariantProps<Props extends ${upperName}VariantProps>(props: Props): [${upperName}VariantProps, Pretty<Omit<Props, keyof ${upperName}VariantProps>>]
1029
1040
  }
1030
1041
 
1031
1042
  ${description ? `/** ${description} */` : ""}
1032
- export declare const ${name}: ${upperName}Recipe
1043
+ export declare const ${baseName}: ${upperName}Recipe
1033
1044
  `
1034
1045
  };
1035
1046
  })
@@ -1710,12 +1721,16 @@ import { ${upperName} } from '../types/jsx'
1710
1721
  export declare const ${factoryName}: ${upperName}
1711
1722
  `,
1712
1723
  jsxType: outdent25`
1713
- import type { ComponentProps, ElementType } from 'react'
1724
+ import type { ComponentPropsWithoutRef, ElementType, ElementRef, Ref } from 'react'
1714
1725
  import type { Assign, JsxStyleProps, JsxHTMLProps } from './system-types'
1715
1726
  import type { RecipeDefinition, RecipeSelection, RecipeVariantRecord } from './recipe'
1716
1727
 
1717
1728
  type Dict = Record<string, unknown>
1718
1729
 
1730
+ type ComponentProps<T extends ElementType> = Omit<ComponentPropsWithoutRef<T>, 'ref'> & {
1731
+ ref?: Ref<ElementRef<T>>
1732
+ }
1733
+
1719
1734
  export type ${componentName}<T extends ElementType, P extends Dict = {}> = {
1720
1735
  (props: JsxHTMLProps<ComponentProps<T>, Assign<JsxStyleProps, P>>): JSX.Element
1721
1736
  displayName?: string
@@ -1801,10 +1816,14 @@ import { ${upperName} } from '../types/jsx'
1801
1816
  export declare const ${factoryName}: ${upperName}
1802
1817
  `,
1803
1818
  jsxType: outdent27`
1804
- import type { ComponentProps, ElementType } from 'react'
1819
+ import type { ComponentPropsWithoutRef, ElementType, ElementRef, Ref } from 'react'
1805
1820
 
1806
1821
  type Dict = Record<string, unknown>
1807
1822
 
1823
+ type ComponentProps<T extends ElementType> = Omit<ComponentPropsWithoutRef<T>, 'ref'> & {
1824
+ ref?: Ref<ElementRef<T>>
1825
+ }
1826
+
1808
1827
  export type ${componentName}<T extends ElementType> = {
1809
1828
  (args: { raw: readonly string[] | ArrayLike<string> }): (props: ComponentProps<T>) => JSX.Element
1810
1829
  displayName?: string
@@ -2636,38 +2655,38 @@ function generateJsxPatterns(ctx) {
2636
2655
  // src/artifacts/pkg-json.ts
2637
2656
  function generatePackageJson(ctx) {
2638
2657
  const {
2639
- config: { outdir }
2658
+ config: { outdir, outExtension: ext = "mjs" }
2640
2659
  } = ctx;
2641
2660
  const pkg = {
2642
2661
  name: outdir,
2643
- description: "This package is auto-generated by CSS Panda",
2662
+ description: "This package is auto-generated by Panda CSS",
2644
2663
  version: `0.0.0-${performance.now()}`,
2645
2664
  type: "module",
2646
2665
  exports: {
2647
2666
  "./css": {
2648
2667
  types: "./css/index.d.ts",
2649
- require: "./css/index.mjs",
2650
- import: "./css/index.mjs"
2668
+ require: `./css/index.${ext}`,
2669
+ import: `./css/index.${ext}`
2651
2670
  },
2652
2671
  "./jsx": {
2653
2672
  types: "./jsx/index.d.ts",
2654
- require: "./jsx/index.mjs",
2655
- import: "./jsx/index.mjs"
2673
+ require: `./jsx/index.${ext}`,
2674
+ import: `./jsx/index.${ext}`
2656
2675
  },
2657
2676
  "./patterns": {
2658
2677
  types: "./patterns/index.d.ts",
2659
- require: "./patterns/index.mjs",
2660
- import: "./patterns/index.mjs"
2678
+ require: `./patterns/index.${ext}`,
2679
+ import: `./patterns/index.${ext}`
2661
2680
  },
2662
2681
  "./recipes": {
2663
2682
  types: "./recipes/index.d.ts",
2664
- require: "./recipes/index.mjs",
2665
- import: "./recipes/index.mjs"
2683
+ require: `./recipes/index.${ext}`,
2684
+ import: `./recipes/index.${ext}`
2666
2685
  },
2667
2686
  "./tokens": {
2668
2687
  types: "./tokens/index.d.ts",
2669
- require: "./tokens/index.mjs",
2670
- import: "./tokens/index.mjs"
2688
+ require: `./tokens/index.${ext}`,
2689
+ import: `./tokens/index.${ext}`
2671
2690
  },
2672
2691
  "./types": {
2673
2692
  types: "./types/index.d.ts"
@@ -2695,12 +2714,12 @@ var composition_d_ts_default = {
2695
2714
 
2696
2715
  // src/artifacts/generated/recipe.d.ts.json
2697
2716
  var recipe_d_ts_default = {
2698
- content: "import type { SystemStyleObject } from './system-types'\n\ntype Pretty<T> = T extends infer U ? { [K in keyof U]: U[K] } : never\n\ntype StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T\n\nexport type RecipeVariantRecord = Record<any, Record<any, SystemStyleObject>>\n\nexport type RecipeSelection<T extends RecipeVariantRecord> = keyof any extends keyof T\n ? {}\n : {\n [K in keyof T]?: StringToBoolean<keyof T[K]>\n }\n\nexport type RecipeVariantFn<T extends RecipeVariantRecord> = (props?: RecipeSelection<T>) => string\n\nexport type RecipeVariantProps<T extends RecipeVariantFn<RecipeVariantRecord>> = Pretty<Parameters<T>[0]>\n\ntype RecipeVariantMap<T extends RecipeVariantRecord> = {\n [K in keyof T]: Array<keyof T[K]>\n}\n\nexport type RecipeRuntimeFn<T extends RecipeVariantRecord> = RecipeVariantFn<T> & {\n __type: RecipeSelection<T>\n variantKeys: (keyof T)[]\n variantMap: RecipeVariantMap<T>\n resolve: (props: RecipeSelection<T>) => SystemStyleObject\n config: RecipeConfig<T>\n splitVariantProps<Props extends RecipeSelection<T>>(props: Props): [RecipeSelection<T>, Pretty<Omit<Props, keyof T>>]\n}\n\nexport type RecipeCompoundSelection<T extends RecipeVariantRecord> = {\n [K in keyof T]?: StringToBoolean<keyof T[K]> | Array<StringToBoolean<keyof T[K]>>\n}\n\nexport type RecipeCompoundVariant<T extends RecipeVariantRecord> = RecipeCompoundSelection<T> & {\n css: SystemStyleObject\n}\n\nexport type RecipeDefinition<T extends RecipeVariantRecord> = {\n /**\n * The base styles of the recipe.\n */\n base?: SystemStyleObject\n /**\n * The multi-variant styles of the recipe.\n */\n variants?: T | RecipeVariantRecord\n /**\n * The default variants of the recipe.\n */\n defaultVariants?: RecipeSelection<T>\n /**\n * The styles to apply when a combination of variants is selected.\n */\n compoundVariants?: Array<RecipeCompoundVariant<T>>\n}\n\nexport type RecipeCreatorFn = <T extends RecipeVariantRecord>(config: RecipeDefinition<T>) => RecipeRuntimeFn<T>\n\nexport type RecipeConfig<T extends RecipeVariantRecord = RecipeVariantRecord> = RecipeDefinition<T> & {\n /**\n * The name of the recipe.\n */\n name: string\n /**\n * The description of the recipe. This will be used in the JSDoc comment.\n */\n description?: string\n /**\n * The jsx elements to track for this recipe. Can be string or Regexp.\n *\n * @default capitalize(recipe.name)\n * @example ['Button', 'Link', /Button$/]\n */\n jsx?: Array<string | RegExp>\n}\n"
2717
+ content: "import type { SystemStyleObject } from './system-types'\n\ntype Pretty<T> = T extends infer U ? { [K in keyof U]: U[K] } : never\n\ntype StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T\n\nexport type RecipeVariantRecord = Record<any, Record<any, SystemStyleObject>>\n\nexport type RecipeSelection<T extends RecipeVariantRecord> = keyof any extends keyof T\n ? {}\n : {\n [K in keyof T]?: StringToBoolean<keyof T[K]>\n }\n\nexport type RecipeVariantFn<T extends RecipeVariantRecord> = (props?: RecipeSelection<T>) => string\n\nexport type RecipeVariantProps<T extends RecipeVariantFn<RecipeVariantRecord>> = Pretty<Parameters<T>[0]>\n\ntype RecipeVariantMap<T extends RecipeVariantRecord> = {\n [K in keyof T]: Array<keyof T[K]>\n}\n\nexport type RecipeRuntimeFn<T extends RecipeVariantRecord> = RecipeVariantFn<T> & {\n __type: RecipeSelection<T>\n variantKeys: (keyof T)[]\n variantMap: RecipeVariantMap<T>\n resolve: (props: RecipeSelection<T>) => SystemStyleObject\n config: RecipeConfig<T>\n splitVariantProps<Props extends RecipeSelection<T>>(props: Props): [RecipeSelection<T>, Pretty<Omit<Props, keyof T>>]\n}\n\nexport type RecipeCompoundSelection<T extends RecipeVariantRecord> = {\n [K in keyof T]?: StringToBoolean<keyof T[K]> | Array<StringToBoolean<keyof T[K]>>\n}\n\nexport type RecipeCompoundVariant<T extends RecipeVariantRecord> = RecipeCompoundSelection<T> & {\n css: SystemStyleObject\n}\n\nexport type RecipeDefinition<T extends RecipeVariantRecord> = {\n /**\n * The base styles of the recipe.\n */\n base?: SystemStyleObject\n /**\n * The multi-variant styles of the recipe.\n */\n variants?: T | RecipeVariantRecord\n /**\n * The default variants of the recipe.\n */\n defaultVariants?: RecipeSelection<T>\n /**\n * The styles to apply when a combination of variants is selected.\n */\n compoundVariants?: Array<RecipeCompoundVariant<T>>\n}\n\nexport type RecipeCreatorFn = <T extends RecipeVariantRecord>(config: RecipeDefinition<T>) => RecipeRuntimeFn<T>\n\nexport type RecipeConfig<T extends RecipeVariantRecord = RecipeVariantRecord> = RecipeDefinition<T> & {\n /**\n * The name of the recipe.\n */\n className: string\n /**\n * The description of the recipe. This will be used in the JSDoc comment.\n */\n description?: string\n /**\n * The jsx elements to track for this recipe. Can be string or Regexp.\n *\n * @default capitalize(recipe.name)\n * @example ['Button', 'Link', /Button$/]\n */\n jsx?: Array<string | RegExp>\n}\n"
2699
2718
  };
2700
2719
 
2701
2720
  // src/artifacts/generated/pattern.d.ts.json
2702
2721
  var pattern_d_ts_default = {
2703
- content: "import type { CssProperty, SystemStyleObject } from './system-types'\nimport type { TokenCategory } from '../tokens'\n\ntype Primitive = string | number | boolean | null | undefined\ntype LiteralUnion<T, K extends Primitive = string> = T | (K & Record<never, never>)\n\nexport type PatternProperty =\n | { type: 'property'; value: CssProperty }\n | { type: 'enum'; value: string[] }\n | { type: 'token'; value: TokenCategory; property?: CssProperty }\n | { type: 'string' | 'boolean' | 'number' }\n\nexport type PatternHelpers = {\n map: (value: any, fn: (value: string) => string | undefined) => any\n}\n\nexport type PatternProperties = Record<string, PatternProperty>\n\ntype Props<T> = Record<LiteralUnion<keyof T>, any>\n\nexport type PatternConfig<T extends PatternProperties = PatternProperties> = {\n /**\n * The description of the pattern. This will be used in the JSDoc comment.\n */\n description?: string\n /**\n * The JSX element rendered by the pattern\n * @default 'div'\n */\n jsxElement?: string\n /**\n * The properties of the pattern.\n */\n properties?: T\n /**\n * The css object this pattern will generate.\n */\n transform?: (props: Props<T>, helpers: PatternHelpers) => SystemStyleObject\n /**\n * The jsx element name this pattern will generate.\n */\n jsx?: string\n /**\n * Whether to only generate types for the specified properties.\n * This will disallow css properties\n */\n strict?: boolean\n /**\n * @experimental\n * Disallow certain css properties for this pattern\n */\n blocklist?: LiteralUnion<CssProperty>[]\n}\n"
2722
+ content: "import type { CssProperty, SystemStyleObject } from './system-types'\nimport type { TokenCategory } from '../tokens'\n\ntype Primitive = string | number | boolean | null | undefined\ntype LiteralUnion<T, K extends Primitive = string> = T | (K & Record<never, never>)\n\nexport type PatternProperty =\n | { type: 'property'; value: CssProperty }\n | { type: 'enum'; value: string[] }\n | { type: 'token'; value: TokenCategory; property?: CssProperty }\n | { type: 'string' | 'boolean' | 'number' }\n\nexport type PatternHelpers = {\n map: (value: any, fn: (value: string) => string | undefined) => any\n}\n\nexport type PatternProperties = Record<string, PatternProperty>\n\ntype Props<T> = Record<LiteralUnion<keyof T>, any>\n\nexport type PatternConfig<T extends PatternProperties = PatternProperties> = {\n /**\n * The description of the pattern. This will be used in the JSDoc comment.\n */\n description?: string\n /**\n * The JSX element rendered by the pattern\n * @default 'div'\n */\n jsxElement?: string\n /**\n * The properties of the pattern.\n */\n properties?: T\n /**\n * The css object this pattern will generate.\n */\n transform?: (props: Props<T>, helpers: PatternHelpers) => SystemStyleObject\n /**\n * The jsx element name this pattern will generate.\n */\n jsxName?: string\n /**\n * The jsx elements to track for this pattern. Can be string or Regexp.\n *\n * @default capitalize(pattern.name)\n * @example ['Button', 'Link', /Button$/]\n */\n jsx?: Array<string | RegExp>\n /**\n * Whether to only generate types for the specified properties.\n * This will disallow css properties\n */\n strict?: boolean\n /**\n * @experimental\n * Disallow certain css properties for this pattern\n */\n blocklist?: LiteralUnion<CssProperty>[]\n}\n"
2704
2723
  };
2705
2724
 
2706
2725
  // src/artifacts/generated/parts.d.ts.json
@@ -3154,21 +3173,21 @@ var generateParserCss = (ctx) => (result) => pipe(
3154
3173
  sheet.processStyleProps(data);
3155
3174
  });
3156
3175
  });
3157
- result2.recipe.forEach((recipeSet, name) => {
3176
+ result2.recipe.forEach((recipeSet, recipeName) => {
3158
3177
  try {
3159
3178
  for (const recipe of recipeSet) {
3160
- const recipeConfig = recipes.getConfig(name);
3179
+ const recipeConfig = recipes.getConfig(recipeName);
3161
3180
  if (!recipeConfig)
3162
3181
  continue;
3163
- match6(recipe).with({ type: "jsx-recipe", name: P.string }, ({ name: name2 }) => {
3182
+ match6(recipe).with({ type: "jsx-recipe" }, () => {
3164
3183
  recipe.data.forEach((data) => {
3165
- const [recipeProps, styleProps] = recipes.splitProps(name2, data);
3184
+ const [recipeProps, styleProps] = recipes.splitProps(recipeName, data);
3166
3185
  sheet.processStyleProps(styleProps);
3167
- sheet.processRecipe(recipeConfig, recipeProps);
3186
+ sheet.processRecipe(recipeName, recipeConfig, recipeProps);
3168
3187
  });
3169
3188
  }).otherwise(() => {
3170
3189
  recipe.data.forEach((data) => {
3171
- sheet.processRecipe(recipeConfig, data);
3190
+ sheet.processRecipe(recipeName, recipeConfig, data);
3172
3191
  });
3173
3192
  });
3174
3193
  }
@@ -3179,9 +3198,9 @@ var generateParserCss = (ctx) => (result) => pipe(
3179
3198
  result2.pattern.forEach((patternSet, name) => {
3180
3199
  try {
3181
3200
  for (const pattern of patternSet) {
3182
- match6(pattern).with({ type: "jsx-pattern", name: P.string }, ({ name: name2 }) => {
3201
+ match6(pattern).with({ type: "jsx-pattern", name: P.string }, ({ name: jsxName }) => {
3183
3202
  pattern.data.forEach((data) => {
3184
- const fnName = patterns.getFnName(name2);
3203
+ const fnName = patterns.getFnName(jsxName);
3185
3204
  const styleProps = patterns.transform(fnName, data);
3186
3205
  sheet.processStyleProps(styleProps);
3187
3206
  });
@@ -3336,53 +3355,52 @@ var getPathEngine = ({ cwd, emitPackage, outdir }) => {
3336
3355
  };
3337
3356
 
3338
3357
  // src/engines/pattern.ts
3339
- import { capitalize as capitalize3, dashCase, mapObject as mapObject2, uncapitalize } from "@pandacss/shared";
3340
- import { Obj, pipe as pipe2 } from "lil-fp";
3358
+ import { capitalize as capitalize3, dashCase, mapObject as mapObject2, memo as memo2, uncapitalize } from "@pandacss/shared";
3341
3359
  var helpers2 = { map: mapObject2 };
3360
+ var createRegex = (item) => {
3361
+ const regex = item.map((item2) => typeof item2 === "string" ? item2 : item2.source).join("|");
3362
+ return new RegExp(`^${regex}$`);
3363
+ };
3342
3364
  var getPatternEngine = (config) => {
3343
- return pipe2(
3344
- { patterns: config.patterns ?? {} },
3345
- Obj.bind("getConfig", ({ patterns }) => {
3346
- return (name) => patterns[name];
3347
- }),
3348
- Obj.bind("transform", ({ getConfig }) => {
3349
- return (name, data) => {
3350
- return getConfig(name)?.transform?.(data, helpers2) ?? {};
3351
- };
3352
- }),
3353
- Obj.bind("getNames", ({ getConfig }) => (name) => {
3354
- const upperName = capitalize3(name);
3355
- return {
3356
- name,
3357
- upperName,
3358
- dashName: dashCase(name),
3359
- styleFnName: `get${upperName}Style`,
3360
- jsxName: getConfig(name)?.jsx ?? upperName
3361
- };
3362
- }),
3363
- Obj.bind("details", ({ getNames, patterns }) => {
3364
- return Object.entries(patterns).map(([name, pattern]) => ({
3365
- ...getNames(name),
3366
- props: Object.keys(pattern?.properties ?? {}),
3367
- blocklistType: pattern?.blocklist ? `| '${pattern.blocklist.join("' | '")}'` : "",
3368
- config: pattern
3369
- }));
3370
- }),
3371
- Obj.bind("nodes", ({ patterns }) => {
3372
- return Object.entries(patterns).map(([name, pattern]) => ({
3373
- type: "pattern",
3374
- name: pattern.jsx ?? capitalize3(name),
3375
- props: Object.keys(pattern?.properties ?? {}),
3376
- baseName: name
3377
- }));
3365
+ const patterns = config.patterns ?? {};
3366
+ const getNames = (name) => {
3367
+ const upperName = capitalize3(name);
3368
+ return {
3369
+ upperName,
3370
+ baseName: name,
3371
+ dashName: dashCase(name),
3372
+ styleFnName: `get${upperName}Style`,
3373
+ jsxName: patterns[name]?.jsxName ?? upperName
3374
+ };
3375
+ };
3376
+ const details = Object.entries(patterns).map(([name, pattern]) => {
3377
+ const names = getNames(name);
3378
+ const jsx = (pattern.jsx ?? []).concat([names.jsxName]);
3379
+ return {
3380
+ ...names,
3381
+ props: Object.keys(pattern?.properties ?? {}),
3382
+ blocklistType: pattern?.blocklist ? `| '${pattern.blocklist.join("' | '")}'` : "",
3383
+ config: pattern,
3384
+ type: "pattern",
3385
+ match: createRegex(jsx),
3386
+ jsx
3387
+ };
3388
+ });
3389
+ return {
3390
+ getConfig: (name) => patterns[name],
3391
+ transform: (name, data) => {
3392
+ return patterns[name]?.transform?.(data, helpers2) ?? {};
3393
+ },
3394
+ getNames,
3395
+ details,
3396
+ getFnName: memo2((jsxName) => {
3397
+ return details.find((node) => node.jsxName === jsxName)?.baseName ?? uncapitalize(jsxName);
3378
3398
  }),
3379
- Obj.bind("getFnName", ({ nodes }) => (jsx) => {
3380
- return nodes.find((node) => node.name === jsx)?.baseName ?? uncapitalize(jsx);
3399
+ filter: memo2((jsxName) => {
3400
+ return details.filter((node) => node.match.test(jsxName));
3381
3401
  }),
3382
- Obj.bind("isEmpty", ({ patterns }) => {
3383
- return () => Object.keys(patterns).length === 0;
3384
- })
3385
- );
3402
+ isEmpty: () => Object.keys(patterns).length === 0
3403
+ };
3386
3404
  };
3387
3405
 
3388
3406
  // src/engines/index.ts
@@ -3417,10 +3435,10 @@ var defaults = (conf) => ({
3417
3435
  }
3418
3436
  });
3419
3437
  var getImportMap = (outdir) => ({
3420
- css: `${outdir}/css`,
3421
- recipe: `${outdir}/recipes`,
3422
- pattern: `${outdir}/patterns`,
3423
- jsx: `${outdir}/jsx`
3438
+ css: [outdir, "css"],
3439
+ recipe: [outdir, "recipes"],
3440
+ pattern: [outdir, "patterns"],
3441
+ jsx: [outdir, "jsx"]
3424
3442
  });
3425
3443
  var createGenerator = (conf) => {
3426
3444
  const ctx = getEngine(defaults(conf));
@@ -3428,7 +3446,7 @@ var createGenerator = (conf) => {
3428
3446
  const compilerOptions = conf.tsconfig?.compilerOptions ?? {};
3429
3447
  const baseUrl = compilerOptions.baseUrl ?? "";
3430
3448
  const cwd = conf.config.cwd;
3431
- const relativeBaseUrl = baseUrl ? baseUrl.replace(cwd, "").slice(1) + "/" : cwd;
3449
+ const relativeBaseUrl = baseUrl !== cwd ? baseUrl.replace(cwd, "").slice(1) : cwd;
3432
3450
  return {
3433
3451
  ...ctx,
3434
3452
  getArtifacts: generateArtifacts(ctx),
@@ -3440,9 +3458,12 @@ var createGenerator = (conf) => {
3440
3458
  jsx: {
3441
3459
  factory: jsx.factoryName,
3442
3460
  isStyleProp: isValidProperty,
3443
- nodes: [...patterns.nodes, ...recipes.nodes]
3461
+ nodes: [...patterns.details, ...recipes.details]
3444
3462
  },
3445
- getRecipesByJsxName: recipes.filter
3463
+ getRecipesByJsxName: recipes.filter,
3464
+ getPatternsByJsxName: patterns.filter,
3465
+ compilerOptions,
3466
+ tsOptions: conf.tsOptions
3446
3467
  }
3447
3468
  };
3448
3469
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/generator",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "The css generator for css panda",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -19,18 +19,18 @@
19
19
  "outdent": " ^0.8.0",
20
20
  "pluralize": "8.0.0",
21
21
  "postcss": "8.4.25",
22
- "ts-pattern": "5.0.1",
23
- "@pandacss/core": "0.7.0",
24
- "@pandacss/is-valid-prop": "0.7.0",
25
- "@pandacss/logger": "0.7.0",
26
- "@pandacss/shared": "0.7.0",
27
- "@pandacss/token-dictionary": "0.7.0",
28
- "@pandacss/types": "0.7.0"
22
+ "ts-pattern": "5.0.4",
23
+ "@pandacss/core": "0.9.0",
24
+ "@pandacss/is-valid-prop": "0.9.0",
25
+ "@pandacss/logger": "0.9.0",
26
+ "@pandacss/shared": "0.9.0",
27
+ "@pandacss/token-dictionary": "0.9.0",
28
+ "@pandacss/types": "0.9.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/pluralize": "0.0.30",
32
32
  "hookable": "5.5.3",
33
- "@pandacss/fixture": "0.7.0"
33
+ "@pandacss/fixture": "0.9.0"
34
34
  },
35
35
  "scripts": {
36
36
  "prebuild": "tsx scripts/prebuild.ts",