@bamboocss/generator 1.26.0 → 1.28.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.cjs CHANGED
@@ -852,7 +852,7 @@ function generateCreateRecipe(ctx) {
852
852
  const withPrefix = ${prefix.className ? `(className) => className ? ${JSON.stringify(prefix.className)} + '-' + className : ${JSON.stringify(prefix.className)}` : `(className) => className`}
853
853
  export const formatRecipeClass = ${hash.className ? `(className) => withPrefix((${utility.toHash})([className], toHash))` : `withPrefix`}
854
854
 
855
- export const createRecipe = (name, defaultVariants, compoundVariants) => {
855
+ export const createRecipe = (name, defaultVariants, compoundVariants, variantMap) => {
856
856
  const getVariantProps = (variants) => {
857
857
  return {
858
858
  [name]: '__ignore__',
@@ -889,7 +889,28 @@ function generateCreateRecipe(ctx) {
889
889
  }
890
890
  })
891
891
 
892
- const recipeStyles = getVariantProps(variants)
892
+ // Only what the config declares names a class.
893
+ //
894
+ // Without this the transform named one for *any* prop it was handed — the build emits
895
+ // rules only for declared values, so the element carried a class nothing backed. It also
896
+ // disagreed with \`cva\`, which skips an undeclared value, leaving the two recipe kinds
897
+ // with different class strings for the same call.
898
+ //
899
+ // Filtered here rather than in \`getVariantProps\`, which is public and is what compound
900
+ // variants are matched against.
901
+ const declared = getVariantProps(variants)
902
+ const recipeStyles = variantMap
903
+ ? Object.fromEntries(
904
+ Object.entries(declared).filter(([prop, value]) => {
905
+ if (prop === name) return true
906
+ // A conditional or responsive value is an object of leaves, and the leaves are
907
+ // what name classes: createCss walks them and calls transform per condition.
908
+ // Only a scalar can be judged here.
909
+ if (value === null || typeof value === 'object') return true
910
+ return Object.hasOwn(variantMap, prop) && variantMap[prop].includes(String(value))
911
+ }),
912
+ )
913
+ : declared
893
914
 
894
915
  // No class for the compound variants. Their rule selects on the variant classes
895
916
  // \`recipeCss\` just named — \`.btn--size_sm.btn--tone_a\` — so it applies on its own,
@@ -981,7 +1002,7 @@ function generateRecipes(ctx, filters) {
981
1002
  * carries, so that slot's class is a constant and nothing has to reach it at runtime.
982
1003
  */
983
1004
  const ${baseName}Anchors = ${JSON.stringify(anchors)}
984
- const ${baseName}AnchorFns = /* @__PURE__ */ ${baseName}Anchors.map((slotName) => [slotName, createRecipe(\`${config.className}__\${slotName}\`, ${baseName}DefaultVariants, getSlotCompoundVariant(${baseName}CompoundVariants, slotName))])
1005
+ const ${baseName}AnchorFns = /* @__PURE__ */ ${baseName}Anchors.map((slotName) => [slotName, createRecipe(\`${config.className}__\${slotName}\`, ${baseName}DefaultVariants, getSlotCompoundVariant(${baseName}CompoundVariants, slotName), ${stringify$2(variantKeyMap)})])
985
1006
  const ${baseName}StaticSlots = /* @__PURE__ */ Object.fromEntries(
986
1007
  ${baseName}SlotNames.filter(([slotName]) => !${baseName}Anchors.includes(slotName)),
987
1008
  )
@@ -1002,7 +1023,7 @@ function generateRecipes(ctx, filters) {
1002
1023
  * against a stylesheet emitting \`.bam-menu__trigger\` — which is easy to miss, since
1003
1024
  * the obvious reading is that this is a hashing problem.
1004
1025
  */
1005
- const ${baseName}SlotFns = /* @__PURE__ */ ${baseName}SlotNames.map(([slotName]) => [slotName, createRecipe(\`${config.className}__\${slotName}\`, ${baseName}DefaultVariants, getSlotCompoundVariant(${baseName}CompoundVariants, slotName))])
1026
+ const ${baseName}SlotFns = /* @__PURE__ */ ${baseName}SlotNames.map(([slotName]) => [slotName, createRecipe(\`${config.className}__\${slotName}\`, ${baseName}DefaultVariants, getSlotCompoundVariant(${baseName}CompoundVariants, slotName), ${stringify$2(variantKeyMap)})])
1006
1027
 
1007
1028
  const ${baseName}Fn = memo((props = {}) => {
1008
1029
  return Object.fromEntries(${baseName}SlotFns.map(([slotName, slotFn]) => [slotName, slotFn.recipeFn(props)]))
@@ -1037,10 +1058,10 @@ function generateRecipes(ctx, filters) {
1037
1058
  ${ctx.file.import("memo, splitProps", "../helpers")}
1038
1059
  ${ctx.file.import("createRecipe, mergeRecipes", "./create-recipe")}
1039
1060
 
1040
- const ${baseName}Fn = /* @__PURE__ */ createRecipe('${config.className}', ${stringify$2(defaultVariants ?? {})}, ${stringify$2(compoundVariants ?? [])})
1041
-
1042
1061
  const ${baseName}VariantMap = ${stringify$2(variantKeyMap)}
1043
1062
 
1063
+ const ${baseName}Fn = /* @__PURE__ */ createRecipe('${config.className}', ${stringify$2(defaultVariants ?? {})}, ${stringify$2(compoundVariants ?? [])}, ${baseName}VariantMap)
1064
+
1044
1065
  const ${baseName}VariantKeys = Object.keys(${baseName}VariantMap)
1045
1066
 
1046
1067
  export const ${baseName} = /* @__PURE__ */ Object.assign(memo(${baseName}Fn.recipeFn), {
package/dist/index.mjs CHANGED
@@ -826,7 +826,7 @@ function generateCreateRecipe(ctx) {
826
826
  const withPrefix = ${prefix.className ? `(className) => className ? ${JSON.stringify(prefix.className)} + '-' + className : ${JSON.stringify(prefix.className)}` : `(className) => className`}
827
827
  export const formatRecipeClass = ${hash.className ? `(className) => withPrefix((${utility.toHash})([className], toHash))` : `withPrefix`}
828
828
 
829
- export const createRecipe = (name, defaultVariants, compoundVariants) => {
829
+ export const createRecipe = (name, defaultVariants, compoundVariants, variantMap) => {
830
830
  const getVariantProps = (variants) => {
831
831
  return {
832
832
  [name]: '__ignore__',
@@ -863,7 +863,28 @@ function generateCreateRecipe(ctx) {
863
863
  }
864
864
  })
865
865
 
866
- const recipeStyles = getVariantProps(variants)
866
+ // Only what the config declares names a class.
867
+ //
868
+ // Without this the transform named one for *any* prop it was handed — the build emits
869
+ // rules only for declared values, so the element carried a class nothing backed. It also
870
+ // disagreed with \`cva\`, which skips an undeclared value, leaving the two recipe kinds
871
+ // with different class strings for the same call.
872
+ //
873
+ // Filtered here rather than in \`getVariantProps\`, which is public and is what compound
874
+ // variants are matched against.
875
+ const declared = getVariantProps(variants)
876
+ const recipeStyles = variantMap
877
+ ? Object.fromEntries(
878
+ Object.entries(declared).filter(([prop, value]) => {
879
+ if (prop === name) return true
880
+ // A conditional or responsive value is an object of leaves, and the leaves are
881
+ // what name classes: createCss walks them and calls transform per condition.
882
+ // Only a scalar can be judged here.
883
+ if (value === null || typeof value === 'object') return true
884
+ return Object.hasOwn(variantMap, prop) && variantMap[prop].includes(String(value))
885
+ }),
886
+ )
887
+ : declared
867
888
 
868
889
  // No class for the compound variants. Their rule selects on the variant classes
869
890
  // \`recipeCss\` just named — \`.btn--size_sm.btn--tone_a\` — so it applies on its own,
@@ -955,7 +976,7 @@ function generateRecipes(ctx, filters) {
955
976
  * carries, so that slot's class is a constant and nothing has to reach it at runtime.
956
977
  */
957
978
  const ${baseName}Anchors = ${JSON.stringify(anchors)}
958
- const ${baseName}AnchorFns = /* @__PURE__ */ ${baseName}Anchors.map((slotName) => [slotName, createRecipe(\`${config.className}__\${slotName}\`, ${baseName}DefaultVariants, getSlotCompoundVariant(${baseName}CompoundVariants, slotName))])
979
+ const ${baseName}AnchorFns = /* @__PURE__ */ ${baseName}Anchors.map((slotName) => [slotName, createRecipe(\`${config.className}__\${slotName}\`, ${baseName}DefaultVariants, getSlotCompoundVariant(${baseName}CompoundVariants, slotName), ${stringify$2(variantKeyMap)})])
959
980
  const ${baseName}StaticSlots = /* @__PURE__ */ Object.fromEntries(
960
981
  ${baseName}SlotNames.filter(([slotName]) => !${baseName}Anchors.includes(slotName)),
961
982
  )
@@ -976,7 +997,7 @@ function generateRecipes(ctx, filters) {
976
997
  * against a stylesheet emitting \`.bam-menu__trigger\` — which is easy to miss, since
977
998
  * the obvious reading is that this is a hashing problem.
978
999
  */
979
- const ${baseName}SlotFns = /* @__PURE__ */ ${baseName}SlotNames.map(([slotName]) => [slotName, createRecipe(\`${config.className}__\${slotName}\`, ${baseName}DefaultVariants, getSlotCompoundVariant(${baseName}CompoundVariants, slotName))])
1000
+ const ${baseName}SlotFns = /* @__PURE__ */ ${baseName}SlotNames.map(([slotName]) => [slotName, createRecipe(\`${config.className}__\${slotName}\`, ${baseName}DefaultVariants, getSlotCompoundVariant(${baseName}CompoundVariants, slotName), ${stringify$2(variantKeyMap)})])
980
1001
 
981
1002
  const ${baseName}Fn = memo((props = {}) => {
982
1003
  return Object.fromEntries(${baseName}SlotFns.map(([slotName, slotFn]) => [slotName, slotFn.recipeFn(props)]))
@@ -1011,10 +1032,10 @@ function generateRecipes(ctx, filters) {
1011
1032
  ${ctx.file.import("memo, splitProps", "../helpers")}
1012
1033
  ${ctx.file.import("createRecipe, mergeRecipes", "./create-recipe")}
1013
1034
 
1014
- const ${baseName}Fn = /* @__PURE__ */ createRecipe('${config.className}', ${stringify$2(defaultVariants ?? {})}, ${stringify$2(compoundVariants ?? [])})
1015
-
1016
1035
  const ${baseName}VariantMap = ${stringify$2(variantKeyMap)}
1017
1036
 
1037
+ const ${baseName}Fn = /* @__PURE__ */ createRecipe('${config.className}', ${stringify$2(defaultVariants ?? {})}, ${stringify$2(compoundVariants ?? [])}, ${baseName}VariantMap)
1038
+
1018
1039
  const ${baseName}VariantKeys = Object.keys(${baseName}VariantMap)
1019
1040
 
1020
1041
  export const ${baseName} = /* @__PURE__ */ Object.assign(memo(${baseName}Fn.recipeFn), {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bamboocss/generator",
3
- "version": "1.26.0",
3
+ "version": "1.28.0",
4
4
  "description": "The css generator for css bamboo",
5
5
  "homepage": "https://bamboocss.com",
6
6
  "license": "MIT",
@@ -38,12 +38,12 @@
38
38
  "pluralize": "8.0.0",
39
39
  "postcss": "8.5.26",
40
40
  "ts-pattern": "5.9.0",
41
- "@bamboocss/core": "1.26.0",
42
- "@bamboocss/is-valid-prop": "^1.26.0",
43
- "@bamboocss/logger": "1.26.0",
44
- "@bamboocss/shared": "1.26.0",
45
- "@bamboocss/token-dictionary": "1.26.0",
46
- "@bamboocss/types": "1.26.0"
41
+ "@bamboocss/core": "1.28.0",
42
+ "@bamboocss/is-valid-prop": "^1.28.0",
43
+ "@bamboocss/logger": "1.28.0",
44
+ "@bamboocss/shared": "1.28.0",
45
+ "@bamboocss/token-dictionary": "1.28.0",
46
+ "@bamboocss/types": "1.28.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/pluralize": "0.0.33"