chaincss 2.1.30 → 2.1.31

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.
@@ -1,6 +1,5 @@
1
1
  // src/compiler/btt.ts
2
2
  import https from "https";
3
- import chalk2 from "chalk";
4
3
 
5
4
  // src/compiler/tokens.ts
6
5
  var defaultTokens = {
@@ -2801,7 +2800,7 @@ function createChain(useTokens = true) {
2801
2800
  }
2802
2801
  var chain = (useTokens = true) => createChain(useTokens);
2803
2802
 
2804
- // src/compiler/btt.ts
2803
+ // src/compiler/timeline.ts
2805
2804
  var styleHistory = [];
2806
2805
  var styleChanges = [];
2807
2806
  var timelineEnabled = false;
@@ -2814,10 +2813,10 @@ function enableTimeline(enable = true) {
2814
2813
  }
2815
2814
  }
2816
2815
  function getStyleHistory() {
2817
- return styleHistory;
2816
+ return [...styleHistory];
2818
2817
  }
2819
2818
  function getStyleChanges() {
2820
- return styleChanges;
2819
+ return [...styleChanges];
2821
2820
  }
2822
2821
  function getStyleDiff(snapshotId1, snapshotId2) {
2823
2822
  const snapshot1 = styleHistory.find((s) => s.id === snapshotId1);
@@ -2825,19 +2824,12 @@ function getStyleDiff(snapshotId1, snapshotId2) {
2825
2824
  if (!snapshot1 || !snapshot2) {
2826
2825
  return { error: "Snapshot not found" };
2827
2826
  }
2828
- const diff = {
2829
- added: {},
2830
- removed: {},
2831
- modified: {}
2832
- };
2827
+ const diff = { added: {}, removed: {}, modified: {} };
2833
2828
  for (const [key, value] of Object.entries(snapshot2.styles)) {
2834
2829
  if (!(key in snapshot1.styles)) {
2835
2830
  diff.added[key] = value;
2836
2831
  } else if (JSON.stringify(snapshot1.styles[key]) !== JSON.stringify(value)) {
2837
- diff.modified[key] = {
2838
- old: snapshot1.styles[key],
2839
- new: value
2840
- };
2832
+ diff.modified[key] = { old: snapshot1.styles[key], new: value };
2841
2833
  }
2842
2834
  }
2843
2835
  for (const [key, value] of Object.entries(snapshot1.styles)) {
@@ -2853,22 +2845,13 @@ function takeSnapshot(selector, styles, source) {
2853
2845
  const existing = styleHistory.find((s) => s.selector === selector && s.hash === hash);
2854
2846
  if (existing) return existing.id;
2855
2847
  const id = `snapshot_${currentSnapshotId++}`;
2856
- const snapshot = {
2857
- id,
2858
- timestamp: Date.now(),
2859
- selector,
2860
- styles: { ...styles },
2861
- source,
2862
- hash
2863
- };
2864
- styleHistory.push(snapshot);
2865
- const previousSnapshot = styleHistory.slice(-2)[0];
2866
- if (previousSnapshot && previousSnapshot.selector === selector) {
2848
+ styleHistory.push({ id, timestamp: Date.now(), selector, styles: { ...styles }, source, hash });
2849
+ const previous = styleHistory[styleHistory.length - 2];
2850
+ if (previous && previous.selector === selector) {
2867
2851
  for (const [key, value] of Object.entries(styles)) {
2868
- const oldValue = previousSnapshot.styles[key];
2869
- if (!(key in previousSnapshot.styles)) {
2852
+ if (!(key in previous.styles)) {
2870
2853
  styleChanges.push({
2871
- id: `change_${Date.now()}_${Math.random()}`,
2854
+ id: `change_${Date.now()}_${Math.random().toString(36).slice(2)}`,
2872
2855
  timestamp: Date.now(),
2873
2856
  selector,
2874
2857
  property: key,
@@ -2876,26 +2859,26 @@ function takeSnapshot(selector, styles, source) {
2876
2859
  newValue: value,
2877
2860
  type: "add"
2878
2861
  });
2879
- } else if (JSON.stringify(oldValue) !== JSON.stringify(value)) {
2862
+ } else if (JSON.stringify(previous.styles[key]) !== JSON.stringify(value)) {
2880
2863
  styleChanges.push({
2881
- id: `change_${Date.now()}_${Math.random()}`,
2864
+ id: `change_${Date.now()}_${Math.random().toString(36).slice(2)}`,
2882
2865
  timestamp: Date.now(),
2883
2866
  selector,
2884
2867
  property: key,
2885
- oldValue,
2868
+ oldValue: previous.styles[key],
2886
2869
  newValue: value,
2887
2870
  type: "modify"
2888
2871
  });
2889
2872
  }
2890
2873
  }
2891
- for (const [key] of Object.entries(previousSnapshot.styles)) {
2874
+ for (const [key] of Object.entries(previous.styles)) {
2892
2875
  if (!(key in styles)) {
2893
2876
  styleChanges.push({
2894
- id: `change_${Date.now()}_${Math.random()}`,
2877
+ id: `change_${Date.now()}_${Math.random().toString(36).slice(2)}`,
2895
2878
  timestamp: Date.now(),
2896
2879
  selector,
2897
2880
  property: key,
2898
- oldValue: previousSnapshot.styles[key],
2881
+ oldValue: previous.styles[key],
2899
2882
  newValue: void 0,
2900
2883
  type: "remove"
2901
2884
  });
@@ -2905,31 +2888,128 @@ function takeSnapshot(selector, styles, source) {
2905
2888
  return id;
2906
2889
  }
2907
2890
  function exportTimeline() {
2908
- return JSON.stringify({
2909
- history: styleHistory,
2910
- changes: styleChanges,
2911
- exportedAt: Date.now()
2912
- }, null, 2);
2891
+ return JSON.stringify({ history: styleHistory, changes: styleChanges, exportedAt: Date.now() }, null, 2);
2913
2892
  }
2914
2893
  function clearTimeline() {
2915
2894
  styleHistory = [];
2916
2895
  styleChanges = [];
2917
2896
  currentSnapshotId = 0;
2918
2897
  }
2898
+ function isTimelineEnabled() {
2899
+ return timelineEnabled;
2900
+ }
2901
+
2902
+ // src/compiler/recipe.ts
2903
+ function recipe(options) {
2904
+ const { base, variants = {}, defaultVariants = {}, compoundVariants = [] } = options;
2905
+ const baseStyle = typeof base === "function" ? base() : base;
2906
+ const variantStyles = {};
2907
+ for (const [variantName, variantMap] of Object.entries(variants)) {
2908
+ variantStyles[variantName] = {};
2909
+ for (const [variantKey, variantStyle] of Object.entries(variantMap)) {
2910
+ variantStyles[variantName][variantKey] = typeof variantStyle === "function" ? variantStyle() : variantStyle;
2911
+ }
2912
+ }
2913
+ const compoundStyles = compoundVariants.map((cv) => ({
2914
+ condition: cv.variants || cv,
2915
+ style: typeof cv.style === "function" ? cv.style() : cv.style
2916
+ }));
2917
+ function mergeStyles(...styles) {
2918
+ const merged = { selectors: [] };
2919
+ for (const style of styles) {
2920
+ if (!style) continue;
2921
+ for (const [key, value] of Object.entries(style)) {
2922
+ if (key === "selectors") {
2923
+ const newSelectors = Array.isArray(value) ? value : [value];
2924
+ merged.selectors = [.../* @__PURE__ */ new Set([...merged.selectors || [], ...newSelectors])];
2925
+ } else if (key === "hover" && typeof value === "object") {
2926
+ if (!merged.hover) merged.hover = {};
2927
+ Object.assign(merged.hover, value);
2928
+ } else if (key !== "selectors") {
2929
+ merged[key] = value;
2930
+ }
2931
+ }
2932
+ }
2933
+ return merged;
2934
+ }
2935
+ function pick(variantSelection = {}) {
2936
+ const selected = { ...defaultVariants, ...variantSelection };
2937
+ const stylesToMerge = [];
2938
+ if (baseStyle) stylesToMerge.push(baseStyle);
2939
+ for (const [variantName, variantValue] of Object.entries(selected)) {
2940
+ const variantStyle = variantStyles[variantName]?.[variantValue];
2941
+ if (variantStyle) stylesToMerge.push(variantStyle);
2942
+ }
2943
+ for (const cv of compoundStyles) {
2944
+ if (Object.entries(cv.condition).every(([key, value]) => selected[key] === value) && cv.style) {
2945
+ stylesToMerge.push(cv.style);
2946
+ }
2947
+ }
2948
+ const merged = mergeStyles(...stylesToMerge);
2949
+ let styleBuilder = chain();
2950
+ for (const [prop, value] of Object.entries(merged)) {
2951
+ if (prop === "selectors" || prop === "hover") continue;
2952
+ if (styleBuilder[prop]) styleBuilder = styleBuilder[prop](value);
2953
+ }
2954
+ if (merged.hover) {
2955
+ styleBuilder = styleBuilder.hover();
2956
+ for (const [hoverProp, hoverValue] of Object.entries(merged.hover)) {
2957
+ if (styleBuilder[hoverProp]) styleBuilder = styleBuilder[hoverProp](hoverValue);
2958
+ }
2959
+ styleBuilder = styleBuilder.end();
2960
+ }
2961
+ return styleBuilder.$el(...merged.selectors || []);
2962
+ }
2963
+ pick.variants = variants;
2964
+ pick.defaultVariants = defaultVariants;
2965
+ pick.base = baseStyle;
2966
+ pick.getAllVariants = () => {
2967
+ const result = [];
2968
+ const variantKeys = Object.keys(variants);
2969
+ function generate(current, index) {
2970
+ if (index === variantKeys.length) {
2971
+ result.push({ ...current });
2972
+ return;
2973
+ }
2974
+ for (const v of Object.keys(variants[variantKeys[index]])) {
2975
+ current[variantKeys[index]] = v;
2976
+ generate(current, index + 1);
2977
+ }
2978
+ }
2979
+ generate({}, 0);
2980
+ return result;
2981
+ };
2982
+ pick.getVariantClassNames = () => {
2983
+ const classNames = {};
2984
+ for (const variant of pick.getAllVariants()) {
2985
+ const key = Object.entries(variant).map(([k, v]) => `${k}-${v}`).join("_");
2986
+ const def = pick(variant);
2987
+ if (def.selectors?.[0]) classNames[key] = def.selectors[0].replace(/^\./, "");
2988
+ }
2989
+ return classNames;
2990
+ };
2991
+ pick.compileAll = () => {
2992
+ const all = pick.getAllVariants();
2993
+ const styles = [];
2994
+ if (baseStyle?.selectors) styles.push(baseStyle);
2995
+ for (const v of all) {
2996
+ const d = pick(v);
2997
+ if (d?.selectors) styles.push(d);
2998
+ }
2999
+ return run(...styles);
3000
+ };
3001
+ return pick;
3002
+ }
3003
+
3004
+ // src/compiler/btt.ts
2919
3005
  var enableSourceComments = true;
2920
3006
  function getSourceLocation() {
2921
3007
  if (!enableSourceComments) return null;
2922
3008
  const stack = new Error().stack;
2923
3009
  if (!stack) return null;
2924
- const stackLines = stack.split("\n");
2925
- for (let i = 0; i < stackLines.length; i++) {
2926
- const line = stackLines[i];
3010
+ for (const line of stack.split("\n")) {
2927
3011
  const match = line.match(/([^/]+\.chain\.js):(\d+):\d+/);
2928
- if (match) {
2929
- const fileName = match[1];
2930
- const lineNumber = match[2];
2931
- return `${fileName}:${lineNumber}`;
2932
- }
3012
+ if (match) return `${match[1]}:${match[2]}`;
2933
3013
  }
2934
3014
  return null;
2935
3015
  }
@@ -2966,9 +3046,7 @@ var fetchWithHttps = (url) => {
2966
3046
  });
2967
3047
  };
2968
3048
  var loadCSSProperties = async () => {
2969
- if (chains.cachedValidProperties !== null && chains.cachedValidProperties.length > 0) {
2970
- return chains.cachedValidProperties;
2971
- }
3049
+ if (chains.cachedValidProperties?.length > 0) return chains.cachedValidProperties;
2972
3050
  try {
2973
3051
  const url = "https://raw.githubusercontent.com/mdn/data/main/css/properties.json";
2974
3052
  let data;
@@ -2982,14 +3060,9 @@ var loadCSSProperties = async () => {
2982
3060
  data = await fetchWithHttps(url);
2983
3061
  }
2984
3062
  const allProperties = Object.keys(data);
2985
- const baseProperties = /* @__PURE__ */ new Set();
2986
- allProperties.forEach((prop) => {
2987
- const baseProp = prop.replace(/^-(webkit|moz|ms|o)-/, "");
2988
- baseProperties.add(baseProp);
2989
- });
2990
- chains.cachedValidProperties = Array.from(baseProperties).sort();
3063
+ chains.cachedValidProperties = allProperties.map((p) => p.replace(/^-(webkit|moz|ms|o)-/, "")).filter((v, i, a) => a.indexOf(v) === i).sort();
2991
3064
  return chains.cachedValidProperties;
2992
- } catch (error) {
3065
+ } catch {
2993
3066
  chains.cachedValidProperties = COMMON_CSS_PROPERTIES;
2994
3067
  return chains.cachedValidProperties;
2995
3068
  }
@@ -3000,11 +3073,8 @@ var chains = {
3000
3073
  classMap: {},
3001
3074
  atomicStats: null,
3002
3075
  async initializeProperties() {
3003
- if (this.cachedValidProperties && this.cachedValidProperties.length > 0) {
3004
- return;
3005
- }
3006
- const properties = await loadCSSProperties();
3007
- this.cachedValidProperties = properties;
3076
+ if (this.cachedValidProperties?.length > 0) return;
3077
+ this.cachedValidProperties = await loadCSSProperties();
3008
3078
  },
3009
3079
  getCachedProperties() {
3010
3080
  return this.cachedValidProperties;
@@ -3015,9 +3085,7 @@ function setAtomicOptimizer(optimizer) {
3015
3085
  atomicOptimizer = optimizer;
3016
3086
  }
3017
3087
  function configureAtomic(opts) {
3018
- if (atomicOptimizer) {
3019
- Object.assign(atomicOptimizer.options, opts);
3020
- }
3088
+ if (atomicOptimizer) Object.assign(atomicOptimizer.options, opts);
3021
3089
  }
3022
3090
  var tokens2 = tokens;
3023
3091
  function createTokens2(tokenValues) {
@@ -3032,21 +3100,13 @@ function processAtRule(rule, parentSelectors = null) {
3032
3100
  output = `@media ${rule.query} {
3033
3101
  `;
3034
3102
  if (rule.styles && typeof rule.styles === "object") {
3035
- let ruleBody = "";
3036
- for (const prop in rule.styles) {
3037
- const kebabKey = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
3038
- ruleBody += ` ${kebabKey}: ${rule.styles[prop]};
3103
+ let body = "";
3104
+ for (const prop in rule.styles) body += ` ${prop.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${rule.styles[prop]};
3039
3105
  `;
3040
- }
3041
- if (ruleBody.trim()) {
3042
- const selector = parentSelectors && parentSelectors.length > 0 ? parentSelectors.join(", ") : ".unknown-selector";
3043
- const sourceLocation = getSourceLocation();
3044
- if (enableSourceComments && sourceLocation) {
3045
- output += ` /* Generated from: ${sourceLocation} */
3046
- `;
3047
- }
3048
- output += ` ${selector} {
3049
- ${ruleBody} }
3106
+ if (body.trim()) {
3107
+ const sel = parentSelectors?.length ? parentSelectors.join(", ") : ".unknown-selector";
3108
+ output += ` ${sel} {
3109
+ ${body} }
3050
3110
  `;
3051
3111
  }
3052
3112
  }
@@ -3059,11 +3119,8 @@ ${ruleBody} }
3059
3119
  output += ` ${step} {
3060
3120
  `;
3061
3121
  for (const prop in rule.steps[step]) {
3062
- if (prop !== "selectors") {
3063
- const kebabKey = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
3064
- output += ` ${kebabKey}: ${rule.steps[step][prop]};
3122
+ if (prop !== "selectors") output += ` ${prop.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${rule.steps[step][prop]};
3065
3123
  `;
3066
- }
3067
3124
  }
3068
3125
  output += " }\n";
3069
3126
  }
@@ -3072,23 +3129,17 @@ ${ruleBody} }
3072
3129
  case "font-face":
3073
3130
  output = "@font-face {\n";
3074
3131
  for (const prop in rule.properties) {
3075
- if (prop !== "selectors") {
3076
- const kebabKey = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
3077
- output += ` ${kebabKey}: ${rule.properties[prop]};
3132
+ if (prop !== "selectors") output += ` ${prop.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${rule.properties[prop]};
3078
3133
  `;
3079
- }
3080
3134
  }
3081
3135
  output += "}\n";
3082
3136
  break;
3083
- default:
3084
- output = "";
3085
- break;
3086
3137
  }
3087
3138
  return output;
3088
3139
  }
3089
3140
  var run = (...args) => {
3090
3141
  if (args.length === 0) return "";
3091
- const validStyles = args.filter((value) => value && typeof value === "object");
3142
+ const validStyles = args.filter((v) => v && typeof v === "object");
3092
3143
  if (validStyles.length === 0) return "";
3093
3144
  let cssOutput = "";
3094
3145
  const styleObjs = [];
@@ -3099,77 +3150,47 @@ var run = (...args) => {
3099
3150
  cssOutput += processAtRule(value) + "\n";
3100
3151
  return;
3101
3152
  }
3102
- if (value.selectors) {
3103
- let mainRuleBody = "";
3104
- let subRulesOutput = "";
3105
- for (const key in value) {
3106
- if (!value.hasOwnProperty(key)) continue;
3107
- if ([
3108
- "selectors",
3109
- "atRules",
3110
- "hover",
3111
- "nestedRules",
3112
- "use",
3113
- "nest",
3114
- "themes",
3115
- "_componentName",
3116
- "_generateComponent",
3117
- "_framework",
3118
- "_propsDefinition"
3119
- ].includes(key)) continue;
3120
- if (key === "atRules" && Array.isArray(value[key])) {
3121
- value[key].forEach((rule) => {
3122
- subRulesOutput += processAtRule(rule, value.selectors);
3123
- });
3124
- continue;
3125
- }
3126
- if (key === "nestedRules" && Array.isArray(value[key])) {
3127
- value[key].forEach((rule) => {
3128
- let nestedBody = "";
3129
- for (const prop in rule.styles) {
3130
- const kebabKey2 = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
3131
- nestedBody += ` ${kebabKey2}: ${rule.styles[prop]};
3132
- `;
3133
- }
3134
- if (nestedBody) {
3135
- subRulesOutput += `${value.selectors.join(", ")} ${rule.selector} {
3136
- ${nestedBody} }
3153
+ if (!value.selectors) return;
3154
+ let mainBody = "", subOutput = "";
3155
+ for (const key in value) {
3156
+ if (!value.hasOwnProperty(key)) continue;
3157
+ if (["selectors", "atRules", "hover", "nestedRules", "use", "nest", "themes", "_componentName", "_generateComponent", "_framework", "_propsDefinition"].includes(key)) continue;
3158
+ if (key === "atRules" && Array.isArray(value[key])) {
3159
+ value[key].forEach((r) => {
3160
+ subOutput += processAtRule(r, value.selectors);
3161
+ });
3162
+ continue;
3163
+ }
3164
+ if (key === "nestedRules" && Array.isArray(value[key])) {
3165
+ value[key].forEach((r) => {
3166
+ let nb = "";
3167
+ for (const p in r.styles) nb += ` ${p.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${r.styles[p]};
3137
3168
  `;
3138
- }
3139
- });
3140
- continue;
3141
- }
3142
- if (key === "hover" && typeof value[key] === "object") {
3143
- let hoverBody = "";
3144
- for (const hoverKey in value[key]) {
3145
- const kebabKey2 = hoverKey.replace(/([A-Z])/g, "-$1").toLowerCase();
3146
- hoverBody += ` ${kebabKey2}: ${value[key][hoverKey]};
3169
+ if (nb) subOutput += `${value.selectors.join(", ")} ${r.selector} {
3170
+ ${nb} }
3147
3171
  `;
3148
- }
3149
- if (hoverBody) {
3150
- subRulesOutput += `${value.selectors.join(", ")}:hover {
3151
- ${hoverBody}}
3172
+ });
3173
+ continue;
3174
+ }
3175
+ if (key === "hover" && typeof value[key] === "object") {
3176
+ let hb = "";
3177
+ for (const hk in value[key]) hb += ` ${hk.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${value[key][hk]};
3152
3178
  `;
3153
- }
3154
- continue;
3155
- }
3156
- const kebabKey = key.replace(/([A-Z])/g, "-$1").toLowerCase();
3157
- mainRuleBody += ` ${kebabKey}: ${value[key]};
3179
+ if (hb) subOutput += `${value.selectors.join(", ")}:hover {
3180
+ ${hb}}
3158
3181
  `;
3182
+ continue;
3159
3183
  }
3160
- if (mainRuleBody.trim()) {
3161
- cssOutput += `${value.selectors.join(", ")} {
3162
- ${mainRuleBody}}
3184
+ mainBody += ` ${key.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${value[key]};
3163
3185
  `;
3164
- }
3165
- cssOutput += subRulesOutput;
3166
3186
  }
3187
+ if (mainBody.trim()) cssOutput += `${value.selectors.join(", ")} {
3188
+ ${mainBody}}
3189
+ `;
3190
+ cssOutput += subOutput;
3167
3191
  });
3168
3192
  cssOutput = cssOutput.replace(/\n{3,}/g, "\n\n").trim();
3169
- if (atomicOptimizer && atomicOptimizer.options.enabled) {
3170
- const result = atomicOptimizer.optimize(styleObjs);
3171
- return result.css;
3172
- }
3193
+ if (atomicOptimizer?.options.enabled) return atomicOptimizer.optimize(styleObjs).css;
3173
3194
  return cssOutput;
3174
3195
  };
3175
3196
  var compile = (obj) => {
@@ -3180,25 +3201,20 @@ var compile = (obj) => {
3180
3201
  if (!obj.hasOwnProperty(key)) continue;
3181
3202
  const element = obj[key];
3182
3203
  if (element && element.variants && typeof element.compileAll === "function") {
3183
- const cleanKey = key.includes("_") ? key.split("_").pop() : key;
3184
- const recipeOutput = element.compileAll(cleanKey);
3185
- cssString += recipeOutput + "\n";
3204
+ cssString += element.compileAll(key.includes("_") ? key.split("_").pop() : key) + "\n";
3186
3205
  continue;
3187
3206
  }
3188
- if (!element || !element.selectors || !element.selectors[0]) continue;
3207
+ if (!element?.selectors?.[0]) continue;
3189
3208
  const selectorKey = element.selectors.join(",");
3190
3209
  if (processedSelectors.has(selectorKey)) continue;
3191
3210
  processedSelectors.add(selectorKey);
3192
3211
  collected.push(element);
3193
3212
  const sourceLocation = getSourceLocation();
3194
- let elementCSS = "";
3195
- let subRulesCSS = "";
3196
- if (timelineEnabled) {
3213
+ let elementCSS = "", subRulesCSS = "";
3214
+ if (isTimelineEnabled()) {
3197
3215
  const styles = {};
3198
3216
  for (const prop in element) {
3199
- if (!["selectors", "atRules", "hover", "nestedRules", "use", "nest", "themes"].includes(prop)) {
3200
- styles[prop] = element[prop];
3201
- }
3217
+ if (!["selectors", "atRules", "hover", "nestedRules", "use", "nest", "themes"].includes(prop)) styles[prop] = element[prop];
3202
3218
  }
3203
3219
  takeSnapshot(element.selectors[0], styles, sourceLocation || "unknown");
3204
3220
  }
@@ -3208,41 +3224,25 @@ var compile = (obj) => {
3208
3224
  if (prop.startsWith("_") || !element.hasOwnProperty(prop)) continue;
3209
3225
  const value = element[prop];
3210
3226
  if (value === void 0 || value === null) continue;
3211
- const kebabKey = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
3212
- elementCSS += ` ${kebabKey}: ${value};
3227
+ elementCSS += ` ${prop.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${value};
3213
3228
  `;
3214
3229
  }
3215
- if (elementCSS.trim()) {
3216
- let block = `${element.selectors.join(", ")} {
3230
+ if (elementCSS.trim()) cssString += addSourceComment(`${element.selectors.join(", ")} {
3217
3231
  ${elementCSS}}
3218
- `;
3219
- cssString += addSourceComment(block, sourceLocation);
3220
- }
3232
+ `, sourceLocation);
3221
3233
  if (element.hover && typeof element.hover === "object") {
3222
- let hoverBody = "";
3223
- for (const hProp in element.hover) {
3224
- const hKebab = hProp.replace(/([A-Z])/g, "-$1").toLowerCase();
3225
- hoverBody += ` ${hKebab}: ${element.hover[hProp]};
3226
- `;
3227
- }
3228
- if (hoverBody) {
3229
- let block = `${element.selectors.join(", ")}:hover {
3230
- ${hoverBody}}
3234
+ let hb = "";
3235
+ for (const hp in element.hover) hb += ` ${hp.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${element.hover[hp]};
3231
3236
  `;
3232
- cssString += addSourceComment(block, sourceLocation);
3233
- }
3237
+ if (hb) cssString += addSourceComment(`${element.selectors.join(", ")}:hover {
3238
+ ${hb}}
3239
+ `, sourceLocation);
3234
3240
  }
3235
3241
  for (const prop in element) {
3236
3242
  if ((prop.startsWith(".") || prop.startsWith("&")) && typeof element[prop] === "object") {
3237
- const subElement = element[prop];
3238
- const parentSelector = element.selectors[0];
3239
- const subSelector = prop.startsWith("&") ? prop.replace("&", parentSelector) : `${parentSelector} ${prop}`;
3240
- cssString += compile({
3241
- [subSelector]: {
3242
- selectors: [subSelector],
3243
- ...subElement
3244
- }
3245
- }) + "\n";
3243
+ const parentSel = element.selectors[0];
3244
+ const subSel = prop.startsWith("&") ? prop.replace("&", parentSel) : `${parentSel} ${prop}`;
3245
+ cssString += compile({ [subSel]: { selectors: [subSel], ...element[prop] } }) + "\n";
3246
3246
  }
3247
3247
  }
3248
3248
  if (element.atRules && Array.isArray(element.atRules)) {
@@ -3253,25 +3253,21 @@ ${hoverBody}}
3253
3253
  if (element.themes && Array.isArray(element.themes)) {
3254
3254
  element.themes.forEach((theme) => {
3255
3255
  if (theme.styles) {
3256
- let themeCSS = "";
3257
- for (const tProp in theme.styles) {
3258
- if (tProp === "selectors") continue;
3259
- const tKebab = tProp.replace(/([A-Z])/g, "-$1").toLowerCase();
3260
- themeCSS += ` ${tKebab}: ${theme.styles[tProp]};
3256
+ let tc = "";
3257
+ for (const tp in theme.styles) {
3258
+ if (tp === "selectors") continue;
3259
+ tc += ` ${tp.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${theme.styles[tp]};
3261
3260
  `;
3262
3261
  }
3263
- if (themeCSS) {
3264
- let block = `${theme.styles.selectors?.join(", ") || element.selectors.join(", ")} {
3265
- ${themeCSS}}
3266
- `;
3267
- subRulesCSS += addSourceComment(block, sourceLocation);
3268
- }
3262
+ if (tc) subRulesCSS += addSourceComment(`${theme.styles.selectors?.join(", ") || element.selectors.join(", ")} {
3263
+ ${tc}}
3264
+ `, sourceLocation);
3269
3265
  }
3270
3266
  });
3271
3267
  }
3272
3268
  cssString += subRulesCSS;
3273
3269
  }
3274
- if (atomicOptimizer && atomicOptimizer.options.enabled) {
3270
+ if (atomicOptimizer?.options.enabled) {
3275
3271
  const result = atomicOptimizer.optimize(collected);
3276
3272
  chains.cssOutput = result.css;
3277
3273
  return result.css;
@@ -3279,137 +3275,8 @@ ${themeCSS}}
3279
3275
  chains.cssOutput = cssString.trim();
3280
3276
  return chains.cssOutput;
3281
3277
  };
3282
- function recipe(options) {
3283
- const {
3284
- base,
3285
- variants = {},
3286
- defaultVariants = {},
3287
- compoundVariants = []
3288
- } = options;
3289
- const baseStyle = typeof base === "function" ? base() : base;
3290
- const variantStyles = {};
3291
- for (const [variantName, variantMap] of Object.entries(variants)) {
3292
- variantStyles[variantName] = {};
3293
- for (const [variantKey, variantStyle] of Object.entries(variantMap)) {
3294
- variantStyles[variantName][variantKey] = typeof variantStyle === "function" ? variantStyle() : variantStyle;
3295
- }
3296
- }
3297
- const compoundStyles = compoundVariants.map((cv) => ({
3298
- condition: cv.variants || cv,
3299
- style: typeof cv.style === "function" ? cv.style() : cv.style
3300
- }));
3301
- function mergeStyles(...styles) {
3302
- const merged = { selectors: [] };
3303
- for (const style of styles) {
3304
- if (!style) continue;
3305
- for (const [key, value] of Object.entries(style)) {
3306
- if (key === "selectors") {
3307
- const newSelectors = Array.isArray(value) ? value : [value];
3308
- merged.selectors = [.../* @__PURE__ */ new Set([...merged.selectors || [], ...newSelectors])];
3309
- } else if (key === "hover" && typeof value === "object") {
3310
- if (!merged.hover) merged.hover = {};
3311
- Object.assign(merged.hover, value);
3312
- } else if (key !== "selectors") {
3313
- merged[key] = value;
3314
- }
3315
- }
3316
- }
3317
- return merged;
3318
- }
3319
- function pick(variantSelection = {}) {
3320
- const selected = { ...defaultVariants, ...variantSelection };
3321
- const stylesToMerge = [];
3322
- if (baseStyle) stylesToMerge.push(baseStyle);
3323
- for (const [variantName, variantValue] of Object.entries(selected)) {
3324
- const variantStyle = variantStyles[variantName]?.[variantValue];
3325
- if (variantStyle) stylesToMerge.push(variantStyle);
3326
- }
3327
- for (const cv of compoundStyles) {
3328
- const matches = Object.entries(cv.condition).every(
3329
- ([key, value]) => selected[key] === value
3330
- );
3331
- if (matches && cv.style) stylesToMerge.push(cv.style);
3332
- }
3333
- const merged = mergeStyles(...stylesToMerge);
3334
- let styleBuilder = chain();
3335
- for (const [prop, value] of Object.entries(merged)) {
3336
- if (prop === "selectors" || prop === "hover") continue;
3337
- if (styleBuilder[prop]) {
3338
- styleBuilder = styleBuilder[prop](value);
3339
- }
3340
- }
3341
- if (merged.hover) {
3342
- styleBuilder = styleBuilder.hover();
3343
- for (const [hoverProp, hoverValue] of Object.entries(merged.hover)) {
3344
- if (styleBuilder[hoverProp]) {
3345
- styleBuilder = styleBuilder[hoverProp](hoverValue);
3346
- }
3347
- }
3348
- styleBuilder = styleBuilder.end();
3349
- }
3350
- const selectors = merged.selectors || [];
3351
- return styleBuilder.$el(...selectors);
3352
- }
3353
- pick.variants = variants;
3354
- pick.defaultVariants = defaultVariants;
3355
- pick.base = baseStyle;
3356
- pick.getAllVariants = () => {
3357
- const result = [];
3358
- const variantKeys = Object.keys(variants);
3359
- function generate(current, index) {
3360
- if (index === variantKeys.length) {
3361
- result.push({ ...current });
3362
- return;
3363
- }
3364
- const variantName = variantKeys[index];
3365
- for (const variantValue of Object.keys(variants[variantName])) {
3366
- current[variantName] = variantValue;
3367
- generate(current, index + 1);
3368
- }
3369
- }
3370
- generate({}, 0);
3371
- return result;
3372
- };
3373
- pick.getVariantClassNames = () => {
3374
- const allVariants = pick.getAllVariants();
3375
- const classNames = {};
3376
- for (const variant of allVariants) {
3377
- const variantKey = Object.entries(variant).map(([k, v]) => `${k}-${v}`).join("_");
3378
- const styleDef = pick(variant);
3379
- if (styleDef.selectors && styleDef.selectors[0]) {
3380
- classNames[variantKey] = styleDef.selectors[0].replace(/^\./, "");
3381
- }
3382
- }
3383
- return classNames;
3384
- };
3385
- pick.compileAll = () => {
3386
- const allVariants = pick.getAllVariants();
3387
- const styles = [];
3388
- if (baseStyle && baseStyle.selectors) {
3389
- styles.push(baseStyle);
3390
- }
3391
- for (const variant of allVariants) {
3392
- const styleDef = pick(variant);
3393
- if (styleDef && styleDef.selectors) {
3394
- styles.push(styleDef);
3395
- }
3396
- }
3397
- for (const variantName of Object.keys(variants)) {
3398
- for (const variantKey of Object.keys(variants[variantName])) {
3399
- const variantStyle = variantStyles[variantName]?.[variantKey];
3400
- if (variantStyle && variantStyle.selectors) {
3401
- styles.push(variantStyle);
3402
- }
3403
- }
3404
- }
3405
- return run(...styles);
3406
- };
3407
- return pick;
3408
- }
3409
3278
  chains.initializeProperties().catch((err) => {
3410
- if (process.env.DEBUG) {
3411
- console.error("Failed to load CSS properties:", err.message);
3412
- }
3279
+ if (process.env.DEBUG) console.error("Failed to load CSS properties:", err.message);
3413
3280
  });
3414
3281
 
3415
3282
  // src/compiler/atomic-optimizer.ts