@pandacss/generator 0.0.0-dev-20230212121547 → 0.0.0-dev-20230212134223

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
@@ -51,6 +51,9 @@ declare const getEngine: (conf: LoadConfigResult) => {
51
51
  };
52
52
  details: {
53
53
  config: _pandacss_types.RecipeConfig<_pandacss_types.RecipeVariantRecord>;
54
+ variantKeyMap: {
55
+ [k: string]: string[];
56
+ };
54
57
  upperName: string;
55
58
  dashName: string;
56
59
  jsxName: string;
@@ -59,11 +62,6 @@ declare const getEngine: (conf: LoadConfigResult) => {
59
62
  splitProps: (name: string, props: Record<string, any>) => {
60
63
  [x: string]: unknown;
61
64
  }[];
62
- variantKeys: {
63
- [x: string]: {
64
- [x: string]: string[];
65
- }[];
66
- }[];
67
65
  isEmpty: () => boolean;
68
66
  };
69
67
  jsx: {
@@ -169,6 +167,9 @@ declare const createGenerator: (conf: LoadConfigResult) => {
169
167
  };
170
168
  details: {
171
169
  config: _pandacss_types.RecipeConfig<_pandacss_types.RecipeVariantRecord>;
170
+ variantKeyMap: {
171
+ [k: string]: string[];
172
+ };
172
173
  upperName: string;
173
174
  dashName: string;
174
175
  jsxName: string;
@@ -177,11 +178,6 @@ declare const createGenerator: (conf: LoadConfigResult) => {
177
178
  splitProps: (name: string, props: Record<string, any>) => {
178
179
  [x: string]: unknown;
179
180
  }[];
180
- variantKeys: {
181
- [x: string]: {
182
- [x: string]: string[];
183
- }[];
184
- }[];
185
181
  isEmpty: () => boolean;
186
182
  };
187
183
  patterns: {
package/dist/index.js CHANGED
@@ -604,7 +604,7 @@ function generatePattern(ctx) {
604
604
  import type { Properties } from '../types/csstype'
605
605
  import type { Tokens } from '../types/token'
606
606
 
607
- export type ${(0, import_shared.capitalize)(name)}Properties = {
607
+ export type ${upperName}Properties = {
608
608
  ${Object.keys(properties ?? {}).map((key) => {
609
609
  const value = properties[key];
610
610
  return (0, import_ts_pattern.match)(value).with({ type: "property" }, (value2) => {
@@ -656,11 +656,13 @@ function generateRecipes(ctx) {
656
656
  } = ctx;
657
657
  if (recipes.isEmpty())
658
658
  return;
659
- const js = [
660
- import_outdent8.outdent`
659
+ const createRecipeFn = {
660
+ name: "create-recipe",
661
+ dts: "",
662
+ js: import_outdent8.outdent`
661
663
  ${ctx.file.import("createCss, withoutSpace, compact", "../helpers")}
662
664
 
663
- const createRecipe = (name, defaultVariants) => {
665
+ export const createRecipe = (name, defaultVariants) => {
664
666
  return (variants) => {
665
667
  const transform = (prop, value) => {
666
668
  if (value === '__ignore__') {
@@ -689,35 +691,43 @@ function generateRecipes(ctx) {
689
691
  }
690
692
  }
691
693
  `
692
- ];
693
- const dts = [
694
- import_outdent8.outdent`
695
- import type { ConditionalValue } from '../types'
696
- `
697
- ];
698
- recipes.details.forEach(({ config, upperName }) => {
699
- const { name, description, defaultVariants, variants } = config;
700
- js.push(import_outdent8.outdent`
701
- export const ${name} = createRecipe('${name}', ${JSON.stringify(defaultVariants ?? {})})
702
- ${name}.variants = ${JSON.stringify(Object.keys(variants ?? {}))}
703
- `);
704
- dts.push(import_outdent8.outdent`
705
- export type ${upperName}Variants = {
706
- ${Object.keys(variants ?? {}).map((key) => {
707
- const value = variants[key];
708
- const keys = Object.keys(value);
709
- return `${key}?: ConditionalValue<${(0, import_shared2.unionType)(keys)}>`;
710
- }).join("\n")}
711
- }
712
-
713
- ${description ? `/** ${description} */` : ""}
714
- export declare function ${name}(variants?: ${upperName}Variants): string & { variants: string[] }
715
- `);
716
- });
717
- return {
718
- js: import_outdent8.outdent.string(js.join("\n\n")),
719
- dts: import_outdent8.outdent.string(dts.join("\n\n"))
720
694
  };
695
+ return [
696
+ createRecipeFn,
697
+ ...ctx.recipes.details.map((recipe) => {
698
+ const { config, upperName, variantKeyMap, dashName } = recipe;
699
+ const { name, description, defaultVariants } = config;
700
+ return {
701
+ name: dashName,
702
+ js: import_outdent8.outdent`
703
+ ${ctx.file.import("createRecipe", "./create-recipe")}
704
+
705
+ export const ${name} = createRecipe('${name}', ${JSON.stringify(defaultVariants ?? {})})
706
+ ${name}.variants = ${JSON.stringify(variantKeyMap)}
707
+ `,
708
+ dts: import_outdent8.outdent`
709
+ import type { ConditionalValue } from '../types'
710
+
711
+ type ${upperName}Variant = {
712
+ ${Object.keys(variantKeyMap).map((key) => `${key}: ${(0, import_shared2.unionType)(variantKeyMap[key])}`).join("\n")}
713
+ }
714
+
715
+ type ${upperName}VariantMap = {
716
+ [key in keyof ${upperName}Variant]: Array<${upperName}Variant[key]>
717
+ }
718
+
719
+ export type ${upperName}Variants = {
720
+ [key in keyof ${upperName}Variant]?: ConditionalValue<${upperName}Variant[key]>
721
+ }
722
+
723
+ ${description ? `/** ${description} */` : ""}
724
+ export declare function ${name}(variants?: ${upperName}Variants): string & {
725
+ variants: ${upperName}VariantMap
726
+ }
727
+ `
728
+ };
729
+ })
730
+ ];
721
731
  }
722
732
 
723
733
  // src/artifacts/js/token.ts
@@ -2047,14 +2057,21 @@ function setupCx(ctx) {
2047
2057
  };
2048
2058
  }
2049
2059
  function setupRecipes(ctx) {
2050
- const code = generateRecipes(ctx);
2051
- if (!code)
2060
+ const files = generateRecipes(ctx);
2061
+ if (!files)
2052
2062
  return;
2063
+ const indexFiles = files.filter((file) => !file.name.includes("create-recipe"));
2064
+ const index = {
2065
+ js: import_outdent29.default.string(indexFiles.map((file) => ctx.file.export(`./${file.name}`)).join("\n")),
2066
+ dts: import_outdent29.default.string(indexFiles.map((file) => `export * from './${file.name}'`).join("\n"))
2067
+ };
2053
2068
  return {
2054
2069
  dir: ctx.paths.recipe,
2055
2070
  files: [
2056
- { file: ctx.file.ext("index"), code: code.js },
2057
- { file: "index.d.ts", code: code.dts }
2071
+ ...files.map((file) => ({ file: ctx.file.ext(file.name), code: file.js })),
2072
+ ...files.map((file) => ({ file: `${file.name}.d.ts`, code: file.dts })),
2073
+ { file: ctx.file.ext("index"), code: index.js },
2074
+ { file: "index.d.ts", code: index.dts }
2058
2075
  ]
2059
2076
  };
2060
2077
  }
@@ -2429,14 +2446,10 @@ var getRecipeEngine = (config) => {
2429
2446
  import_lil_fp3.Obj.bind("details", ({ getNames, recipes }) => {
2430
2447
  return Object.entries(recipes).map(([name, recipe]) => ({
2431
2448
  ...getNames(name),
2432
- config: recipe
2433
- }));
2434
- }),
2435
- import_lil_fp3.Obj.bind("variantKeys", ({ recipes }) => {
2436
- return Object.entries(recipes).map(([name, recipe]) => ({
2437
- [name]: Object.entries(recipe.variants ?? {}).map(([key, value]) => ({
2438
- [key]: Object.keys(value)
2439
- }))
2449
+ config: recipe,
2450
+ variantKeyMap: Object.fromEntries(
2451
+ Object.entries(recipe.variants ?? {}).map(([key, value]) => [key, Object.keys(value)])
2452
+ )
2440
2453
  }));
2441
2454
  }),
2442
2455
  import_lil_fp3.Obj.bind("isEmpty", ({ recipes }) => {
package/dist/index.mjs CHANGED
@@ -555,7 +555,7 @@ function generateisValidProp(ctx) {
555
555
  }
556
556
 
557
557
  // src/artifacts/js/pattern.ts
558
- import { capitalize, unionType } from "@pandacss/shared";
558
+ import { unionType } from "@pandacss/shared";
559
559
  import { stringify as stringify2 } from "javascript-stringify";
560
560
  import { outdent as outdent7 } from "outdent";
561
561
  import { match } from "ts-pattern";
@@ -573,7 +573,7 @@ function generatePattern(ctx) {
573
573
  import type { Properties } from '../types/csstype'
574
574
  import type { Tokens } from '../types/token'
575
575
 
576
- export type ${capitalize(name)}Properties = {
576
+ export type ${upperName}Properties = {
577
577
  ${Object.keys(properties ?? {}).map((key) => {
578
578
  const value = properties[key];
579
579
  return match(value).with({ type: "property" }, (value2) => {
@@ -625,11 +625,13 @@ function generateRecipes(ctx) {
625
625
  } = ctx;
626
626
  if (recipes.isEmpty())
627
627
  return;
628
- const js = [
629
- outdent8`
628
+ const createRecipeFn = {
629
+ name: "create-recipe",
630
+ dts: "",
631
+ js: outdent8`
630
632
  ${ctx.file.import("createCss, withoutSpace, compact", "../helpers")}
631
633
 
632
- const createRecipe = (name, defaultVariants) => {
634
+ export const createRecipe = (name, defaultVariants) => {
633
635
  return (variants) => {
634
636
  const transform = (prop, value) => {
635
637
  if (value === '__ignore__') {
@@ -658,35 +660,43 @@ function generateRecipes(ctx) {
658
660
  }
659
661
  }
660
662
  `
661
- ];
662
- const dts = [
663
- outdent8`
664
- import type { ConditionalValue } from '../types'
665
- `
666
- ];
667
- recipes.details.forEach(({ config, upperName }) => {
668
- const { name, description, defaultVariants, variants } = config;
669
- js.push(outdent8`
670
- export const ${name} = createRecipe('${name}', ${JSON.stringify(defaultVariants ?? {})})
671
- ${name}.variants = ${JSON.stringify(Object.keys(variants ?? {}))}
672
- `);
673
- dts.push(outdent8`
674
- export type ${upperName}Variants = {
675
- ${Object.keys(variants ?? {}).map((key) => {
676
- const value = variants[key];
677
- const keys = Object.keys(value);
678
- return `${key}?: ConditionalValue<${unionType2(keys)}>`;
679
- }).join("\n")}
680
- }
681
-
682
- ${description ? `/** ${description} */` : ""}
683
- export declare function ${name}(variants?: ${upperName}Variants): string & { variants: string[] }
684
- `);
685
- });
686
- return {
687
- js: outdent8.string(js.join("\n\n")),
688
- dts: outdent8.string(dts.join("\n\n"))
689
663
  };
664
+ return [
665
+ createRecipeFn,
666
+ ...ctx.recipes.details.map((recipe) => {
667
+ const { config, upperName, variantKeyMap, dashName } = recipe;
668
+ const { name, description, defaultVariants } = config;
669
+ return {
670
+ name: dashName,
671
+ js: outdent8`
672
+ ${ctx.file.import("createRecipe", "./create-recipe")}
673
+
674
+ export const ${name} = createRecipe('${name}', ${JSON.stringify(defaultVariants ?? {})})
675
+ ${name}.variants = ${JSON.stringify(variantKeyMap)}
676
+ `,
677
+ dts: outdent8`
678
+ import type { ConditionalValue } from '../types'
679
+
680
+ type ${upperName}Variant = {
681
+ ${Object.keys(variantKeyMap).map((key) => `${key}: ${unionType2(variantKeyMap[key])}`).join("\n")}
682
+ }
683
+
684
+ type ${upperName}VariantMap = {
685
+ [key in keyof ${upperName}Variant]: Array<${upperName}Variant[key]>
686
+ }
687
+
688
+ export type ${upperName}Variants = {
689
+ [key in keyof ${upperName}Variant]?: ConditionalValue<${upperName}Variant[key]>
690
+ }
691
+
692
+ ${description ? `/** ${description} */` : ""}
693
+ export declare function ${name}(variants?: ${upperName}Variants): string & {
694
+ variants: ${upperName}VariantMap
695
+ }
696
+ `
697
+ };
698
+ })
699
+ ];
690
700
  }
691
701
 
692
702
  // src/artifacts/js/token.ts
@@ -1840,7 +1850,7 @@ function generateStyleProps(ctx) {
1840
1850
  }
1841
1851
 
1842
1852
  // src/artifacts/types/token-types.ts
1843
- import { capitalize as capitalize2, unionType as unionType3 } from "@pandacss/shared";
1853
+ import { capitalize, unionType as unionType3 } from "@pandacss/shared";
1844
1854
  import { outdent as outdent28 } from "outdent";
1845
1855
  import pluralize from "pluralize";
1846
1856
  function generateTokenTypes(ctx) {
@@ -1852,7 +1862,7 @@ function generateTokenTypes(ctx) {
1852
1862
  result.add("[token: string]: string");
1853
1863
  } else {
1854
1864
  for (const [key, value] of tokens.categoryMap.entries()) {
1855
- const typeName = capitalize2(pluralize.singular(key));
1865
+ const typeName = capitalize(pluralize.singular(key));
1856
1866
  set.add(`export type ${typeName} = ${unionType3(value.keys())}`);
1857
1867
  set.add(`export type ColorPalette = ${unionType3(Object.keys(tokens.colorPalettes))}`);
1858
1868
  result.add(` ${key}: ${typeName}`);
@@ -2016,14 +2026,21 @@ function setupCx(ctx) {
2016
2026
  };
2017
2027
  }
2018
2028
  function setupRecipes(ctx) {
2019
- const code = generateRecipes(ctx);
2020
- if (!code)
2029
+ const files = generateRecipes(ctx);
2030
+ if (!files)
2021
2031
  return;
2032
+ const indexFiles = files.filter((file) => !file.name.includes("create-recipe"));
2033
+ const index = {
2034
+ js: outdent29.string(indexFiles.map((file) => ctx.file.export(`./${file.name}`)).join("\n")),
2035
+ dts: outdent29.string(indexFiles.map((file) => `export * from './${file.name}'`).join("\n"))
2036
+ };
2022
2037
  return {
2023
2038
  dir: ctx.paths.recipe,
2024
2039
  files: [
2025
- { file: ctx.file.ext("index"), code: code.js },
2026
- { file: "index.d.ts", code: code.dts }
2040
+ ...files.map((file) => ({ file: ctx.file.ext(file.name), code: file.js })),
2041
+ ...files.map((file) => ({ file: `${file.name}.d.ts`, code: file.dts })),
2042
+ { file: ctx.file.ext("index"), code: index.js },
2043
+ { file: "index.d.ts", code: index.dts }
2027
2044
  ]
2028
2045
  };
2029
2046
  }
@@ -2281,14 +2298,14 @@ var getBaseEngine = (conf) => pipe2(
2281
2298
  );
2282
2299
 
2283
2300
  // src/engines/jsx.ts
2284
- import { capitalize as capitalize3 } from "@pandacss/shared";
2301
+ import { capitalize as capitalize2 } from "@pandacss/shared";
2285
2302
  var getJsxEngine = (config) => {
2286
2303
  const { jsxFactory, jsxFramework } = config;
2287
2304
  return {
2288
2305
  factoryName: jsxFactory,
2289
- upperName: capitalize3(jsxFactory),
2290
- typeName: `HTML${capitalize3(jsxFactory)}Props`,
2291
- componentName: `${capitalize3(jsxFactory)}Component`,
2306
+ upperName: capitalize2(jsxFactory),
2307
+ typeName: `HTML${capitalize2(jsxFactory)}Props`,
2308
+ componentName: `${capitalize2(jsxFactory)}Component`,
2292
2309
  framework: jsxFramework
2293
2310
  };
2294
2311
  };
@@ -2311,7 +2328,7 @@ var getPathEngine = ({ cwd, emitPackage, outdir }) => {
2311
2328
  };
2312
2329
 
2313
2330
  // src/engines/pattern.ts
2314
- import { capitalize as capitalize4, dashCase, mapObject as mapObject2, uncapitalize } from "@pandacss/shared";
2331
+ import { capitalize as capitalize3, dashCase, mapObject as mapObject2, uncapitalize } from "@pandacss/shared";
2315
2332
  import { Obj as Obj2, pipe as pipe3 } from "lil-fp";
2316
2333
  var helpers2 = { map: mapObject2 };
2317
2334
  var getPatternEngine = (config) => {
@@ -2326,7 +2343,7 @@ var getPatternEngine = (config) => {
2326
2343
  };
2327
2344
  }),
2328
2345
  Obj2.bind("getNames", ({ getConfig }) => (name) => {
2329
- const upperName = capitalize4(name);
2346
+ const upperName = capitalize3(name);
2330
2347
  return {
2331
2348
  name,
2332
2349
  upperName,
@@ -2346,7 +2363,7 @@ var getPatternEngine = (config) => {
2346
2363
  Obj2.bind("nodes", ({ patterns }) => {
2347
2364
  return Object.entries(patterns).map(([name, pattern]) => ({
2348
2365
  type: "pattern",
2349
- name: pattern.jsx ?? capitalize4(name),
2366
+ name: pattern.jsx ?? capitalize3(name),
2350
2367
  props: Object.keys(pattern.properties),
2351
2368
  baseName: name
2352
2369
  }));
@@ -2361,7 +2378,7 @@ var getPatternEngine = (config) => {
2361
2378
  };
2362
2379
 
2363
2380
  // src/engines/recipe.ts
2364
- import { capitalize as capitalize5, dashCase as dashCase2, splitProps, uncapitalize as uncapitalize2 } from "@pandacss/shared";
2381
+ import { capitalize as capitalize4, dashCase as dashCase2, splitProps, uncapitalize as uncapitalize2 } from "@pandacss/shared";
2365
2382
  import { Obj as Obj3, pipe as pipe4 } from "lil-fp";
2366
2383
  var getRecipeEngine = (config) => {
2367
2384
  return pipe4(
@@ -2371,15 +2388,15 @@ var getRecipeEngine = (config) => {
2371
2388
  }),
2372
2389
  Obj3.bind("getNames", ({ getConfig }) => {
2373
2390
  return (name) => ({
2374
- upperName: capitalize5(name),
2391
+ upperName: capitalize4(name),
2375
2392
  dashName: dashCase2(name),
2376
- jsxName: getConfig(name)?.jsx ?? capitalize5(name)
2393
+ jsxName: getConfig(name)?.jsx ?? capitalize4(name)
2377
2394
  });
2378
2395
  }),
2379
2396
  Obj3.bind("nodes", ({ recipes }) => {
2380
2397
  return Object.entries(recipes).map(([name, recipe]) => ({
2381
2398
  type: "recipe",
2382
- name: recipe.jsx ?? capitalize5(name),
2399
+ name: recipe.jsx ?? capitalize4(name),
2383
2400
  props: Object.keys(recipe.variants ?? {}),
2384
2401
  baseName: name
2385
2402
  }));
@@ -2398,14 +2415,10 @@ var getRecipeEngine = (config) => {
2398
2415
  Obj3.bind("details", ({ getNames, recipes }) => {
2399
2416
  return Object.entries(recipes).map(([name, recipe]) => ({
2400
2417
  ...getNames(name),
2401
- config: recipe
2402
- }));
2403
- }),
2404
- Obj3.bind("variantKeys", ({ recipes }) => {
2405
- return Object.entries(recipes).map(([name, recipe]) => ({
2406
- [name]: Object.entries(recipe.variants ?? {}).map(([key, value]) => ({
2407
- [key]: Object.keys(value)
2408
- }))
2418
+ config: recipe,
2419
+ variantKeyMap: Object.fromEntries(
2420
+ Object.entries(recipe.variants ?? {}).map(([key, value]) => [key, Object.keys(value)])
2421
+ )
2409
2422
  }));
2410
2423
  }),
2411
2424
  Obj3.bind("isEmpty", ({ recipes }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/generator",
3
- "version": "0.0.0-dev-20230212121547",
3
+ "version": "0.0.0-dev-20230212134223",
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.1.4",
23
- "@pandacss/core": "0.0.0-dev-20230212121547",
24
- "@pandacss/logger": "0.0.0-dev-20230212121547",
25
- "@pandacss/is-valid-prop": "0.0.0-dev-20230212121547",
26
- "@pandacss/shared": "0.0.0-dev-20230212121547",
27
- "@pandacss/types": "0.0.0-dev-20230212121547",
28
- "@pandacss/token-dictionary": "0.0.0-dev-20230212121547"
23
+ "@pandacss/core": "0.0.0-dev-20230212134223",
24
+ "@pandacss/logger": "0.0.0-dev-20230212134223",
25
+ "@pandacss/is-valid-prop": "0.0.0-dev-20230212134223",
26
+ "@pandacss/shared": "0.0.0-dev-20230212134223",
27
+ "@pandacss/types": "0.0.0-dev-20230212134223",
28
+ "@pandacss/token-dictionary": "0.0.0-dev-20230212134223"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/pluralize": "0.0.29",
32
- "@pandacss/fixture": "0.0.0-dev-20230212121547"
32
+ "@pandacss/fixture": "0.0.0-dev-20230212134223"
33
33
  },
34
34
  "scripts": {
35
35
  "prebuild": "tsx scripts/prebuild.ts",