@pandacss/generator 0.0.0-dev-20230813121817 → 0.0.0-dev-20230814191147

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -654,13 +654,13 @@ function generateCssFn(ctx) {
654
654
  return result;
655
655
  }).join(",")}"
656
656
 
657
- const classNames = new Map()
657
+ const classNameByProp = new Map()
658
658
  ${utility.hasShorthand ? import_outdent4.outdent`
659
659
  const shorthands = new Map()
660
660
  utilities.split(',').forEach((utility) => {
661
661
  const [prop, meta] = utility.split(':')
662
662
  const [className, ...shorthandList] = meta.split('/')
663
- classNames.set(prop, className)
663
+ classNameByProp.set(prop, className)
664
664
  if (shorthandList.length) {
665
665
  shorthandList.forEach((shorthand) => {
666
666
  shorthands.set(shorthand === '1' ? className : shorthand, prop)
@@ -672,7 +672,7 @@ function generateCssFn(ctx) {
672
672
  ` : import_outdent4.outdent`
673
673
  utilities.split(',').forEach((utility) => {
674
674
  const [prop, className] = utility.split(':')
675
- classNames.set(prop, className)
675
+ classNameByProp.set(prop, className)
676
676
  })
677
677
  `}
678
678
 
@@ -687,15 +687,21 @@ function generateCssFn(ctx) {
687
687
  ${prefix ? "prefix: " + JSON.stringify(prefix) + "," : ""}
688
688
  transform: ${utility.hasShorthand ? `(prop, value) => {
689
689
  const key = resolveShorthand(prop)
690
- const propKey = classNames.get(key) || hypenateProperty(key)
690
+ const propKey = classNameByProp.get(key) || hypenateProperty(key)
691
691
  return { className: \`\${propKey}${separator}\${withoutSpace(value)}\` }
692
- }` : `(key, value) => ({ className: \`\${classNames.get(key) || hypenateProperty(key)}${separator}\${withoutSpace(value)}\` })`},
692
+ }` : `(key, value) => ({ className: \`\${classNameByProp.get(key) || hypenateProperty(key)}${separator}\${withoutSpace(value)}\` })`},
693
693
  ${utility.hasShorthand ? "hasShorthand: true," : ""}
694
694
  resolveShorthand: ${utility.hasShorthand ? "resolveShorthand" : "prop => prop"},
695
695
  }
696
696
  }
697
697
 
698
- export const css = createCss(context)
698
+ const cssFn = createCss(context)
699
+ export const cssCache = new Map()
700
+ export const css = (styles) => {
701
+ const classNames = cssFn(styles)
702
+ cssCache.set(classNames, styles)
703
+ return classNames
704
+ }
699
705
  css.raw = (styles) => styles
700
706
 
701
707
  export const { mergeCss, assignCss } = createMergeCss(context)
@@ -833,23 +839,34 @@ function generateCvaFn(ctx) {
833
839
 
834
840
  // src/artifacts/js/cx.ts
835
841
  var import_outdent7 = __toESM(require("outdent"));
836
- function generateCx() {
842
+ function generateCx(ctx) {
837
843
  return {
838
844
  js: import_outdent7.default`
845
+ ${ctx.file.import("cssCache, css, mergeCss", "./css")}
846
+
839
847
  function cx() {
848
+ const objs = []
840
849
  let str = '',
841
850
  i = 0,
842
851
  arg
843
-
852
+
844
853
  for (; i < arguments.length; ) {
845
- if ((arg = arguments[i++]) && typeof arg === 'string') {
846
- str && (str += ' ')
847
- str += arg
854
+ arg = arguments[i++]
855
+ if (!arg || typeof arg !== 'string') continue
856
+
857
+ if (cssCache.has(arg)) {
858
+ objs.push(cssCache.get(arg))
859
+ continue
848
860
  }
861
+
862
+ str && (str += ' ')
863
+ str += arg.toString()
849
864
  }
850
- return str
865
+
866
+ const merged = mergeCss(...objs)
867
+ return [css(merged), str].join(' ')
851
868
  }
852
-
869
+
853
870
  export { cx }
854
871
  `,
855
872
  dts: import_outdent7.default`
@@ -3168,7 +3185,7 @@ function setupSva(ctx) {
3168
3185
  };
3169
3186
  }
3170
3187
  function setupCx(ctx) {
3171
- const code = generateCx();
3188
+ const code = generateCx(ctx);
3172
3189
  return {
3173
3190
  dir: ctx.paths.css,
3174
3191
  files: [
package/dist/index.mjs CHANGED
@@ -623,13 +623,13 @@ function generateCssFn(ctx) {
623
623
  return result;
624
624
  }).join(",")}"
625
625
 
626
- const classNames = new Map()
626
+ const classNameByProp = new Map()
627
627
  ${utility.hasShorthand ? outdent4`
628
628
  const shorthands = new Map()
629
629
  utilities.split(',').forEach((utility) => {
630
630
  const [prop, meta] = utility.split(':')
631
631
  const [className, ...shorthandList] = meta.split('/')
632
- classNames.set(prop, className)
632
+ classNameByProp.set(prop, className)
633
633
  if (shorthandList.length) {
634
634
  shorthandList.forEach((shorthand) => {
635
635
  shorthands.set(shorthand === '1' ? className : shorthand, prop)
@@ -641,7 +641,7 @@ function generateCssFn(ctx) {
641
641
  ` : outdent4`
642
642
  utilities.split(',').forEach((utility) => {
643
643
  const [prop, className] = utility.split(':')
644
- classNames.set(prop, className)
644
+ classNameByProp.set(prop, className)
645
645
  })
646
646
  `}
647
647
 
@@ -656,15 +656,21 @@ function generateCssFn(ctx) {
656
656
  ${prefix ? "prefix: " + JSON.stringify(prefix) + "," : ""}
657
657
  transform: ${utility.hasShorthand ? `(prop, value) => {
658
658
  const key = resolveShorthand(prop)
659
- const propKey = classNames.get(key) || hypenateProperty(key)
659
+ const propKey = classNameByProp.get(key) || hypenateProperty(key)
660
660
  return { className: \`\${propKey}${separator}\${withoutSpace(value)}\` }
661
- }` : `(key, value) => ({ className: \`\${classNames.get(key) || hypenateProperty(key)}${separator}\${withoutSpace(value)}\` })`},
661
+ }` : `(key, value) => ({ className: \`\${classNameByProp.get(key) || hypenateProperty(key)}${separator}\${withoutSpace(value)}\` })`},
662
662
  ${utility.hasShorthand ? "hasShorthand: true," : ""}
663
663
  resolveShorthand: ${utility.hasShorthand ? "resolveShorthand" : "prop => prop"},
664
664
  }
665
665
  }
666
666
 
667
- export const css = createCss(context)
667
+ const cssFn = createCss(context)
668
+ export const cssCache = new Map()
669
+ export const css = (styles) => {
670
+ const classNames = cssFn(styles)
671
+ cssCache.set(classNames, styles)
672
+ return classNames
673
+ }
668
674
  css.raw = (styles) => styles
669
675
 
670
676
  export const { mergeCss, assignCss } = createMergeCss(context)
@@ -802,23 +808,34 @@ function generateCvaFn(ctx) {
802
808
 
803
809
  // src/artifacts/js/cx.ts
804
810
  import outdent7 from "outdent";
805
- function generateCx() {
811
+ function generateCx(ctx) {
806
812
  return {
807
813
  js: outdent7`
814
+ ${ctx.file.import("cssCache, css, mergeCss", "./css")}
815
+
808
816
  function cx() {
817
+ const objs = []
809
818
  let str = '',
810
819
  i = 0,
811
820
  arg
812
-
821
+
813
822
  for (; i < arguments.length; ) {
814
- if ((arg = arguments[i++]) && typeof arg === 'string') {
815
- str && (str += ' ')
816
- str += arg
823
+ arg = arguments[i++]
824
+ if (!arg || typeof arg !== 'string') continue
825
+
826
+ if (cssCache.has(arg)) {
827
+ objs.push(cssCache.get(arg))
828
+ continue
817
829
  }
830
+
831
+ str && (str += ' ')
832
+ str += arg.toString()
818
833
  }
819
- return str
834
+
835
+ const merged = mergeCss(...objs)
836
+ return [css(merged), str].join(' ')
820
837
  }
821
-
838
+
822
839
  export { cx }
823
840
  `,
824
841
  dts: outdent7`
@@ -3137,7 +3154,7 @@ function setupSva(ctx) {
3137
3154
  };
3138
3155
  }
3139
3156
  function setupCx(ctx) {
3140
- const code = generateCx();
3157
+ const code = generateCx(ctx);
3141
3158
  return {
3142
3159
  dir: ctx.paths.css,
3143
3160
  files: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/generator",
3
- "version": "0.0.0-dev-20230813121817",
3
+ "version": "0.0.0-dev-20230814191147",
4
4
  "description": "The css generator for css panda",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -20,17 +20,17 @@
20
20
  "pluralize": "8.0.0",
21
21
  "postcss": "8.4.27",
22
22
  "ts-pattern": "5.0.4",
23
- "@pandacss/core": "0.0.0-dev-20230813121817",
24
- "@pandacss/is-valid-prop": "0.0.0-dev-20230813121817",
25
- "@pandacss/logger": "0.0.0-dev-20230813121817",
26
- "@pandacss/shared": "0.0.0-dev-20230813121817",
27
- "@pandacss/token-dictionary": "0.0.0-dev-20230813121817",
28
- "@pandacss/types": "0.0.0-dev-20230813121817"
23
+ "@pandacss/core": "0.0.0-dev-20230814191147",
24
+ "@pandacss/is-valid-prop": "0.0.0-dev-20230814191147",
25
+ "@pandacss/logger": "0.0.0-dev-20230814191147",
26
+ "@pandacss/shared": "0.0.0-dev-20230814191147",
27
+ "@pandacss/token-dictionary": "0.0.0-dev-20230814191147",
28
+ "@pandacss/types": "0.0.0-dev-20230814191147"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/pluralize": "0.0.30",
32
32
  "hookable": "5.5.3",
33
- "@pandacss/fixture": "0.0.0-dev-20230813121817"
33
+ "@pandacss/fixture": "0.0.0-dev-20230814191147"
34
34
  },
35
35
  "scripts": {
36
36
  "prebuild": "tsx scripts/prebuild.ts",