chaincss 2.1.29 → 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.
package/dist/index.js CHANGED
@@ -3436,8 +3436,8 @@ function useSmartStyles(styleBuilder, deps = [], options = {}) {
3436
3436
  }
3437
3437
  function createSmartComponent(Component, baseStyles) {
3438
3438
  const SmartComponent = (props) => {
3439
- const styles = useSmartStyles((chain2) => {
3440
- let instance = chain2();
3439
+ const styles = useSmartStyles((chain3) => {
3440
+ let instance = chain3();
3441
3441
  if (baseStyles) {
3442
3442
  instance = baseStyles(instance);
3443
3443
  }
@@ -3467,7 +3467,7 @@ function withSmartStyles(WrappedComponent, styles) {
3467
3467
  import fs6 from "fs";
3468
3468
  import path5 from "path";
3469
3469
  import crypto4 from "crypto";
3470
- import chalk3 from "chalk";
3470
+ import chalk2 from "chalk";
3471
3471
  import { fileURLToPath, pathToFileURL } from "url";
3472
3472
 
3473
3473
  // src/core/constants.ts
@@ -3669,9 +3669,7 @@ function formatCSS(css, minify = false) {
3669
3669
  var currentLogLevel = process.env.DEBUG ? "debug" : "info";
3670
3670
 
3671
3671
  // src/compiler/btt.ts
3672
- import fs2 from "fs";
3673
3672
  import https from "https";
3674
- import chalk2 from "chalk";
3675
3673
 
3676
3674
  // src/compiler/commonProps.ts
3677
3675
  var COMMON_CSS_PROPERTIES2 = [
@@ -3754,7 +3752,7 @@ var COMMON_CSS_PROPERTIES2 = [
3754
3752
  "z-index"
3755
3753
  ];
3756
3754
 
3757
- // src/compiler/btt.ts
3755
+ // src/compiler/timeline.ts
3758
3756
  var styleHistory = [];
3759
3757
  var styleChanges = [];
3760
3758
  var timelineEnabled = false;
@@ -3767,10 +3765,10 @@ function enableTimeline(enable = true) {
3767
3765
  }
3768
3766
  }
3769
3767
  function getStyleHistory() {
3770
- return styleHistory;
3768
+ return [...styleHistory];
3771
3769
  }
3772
3770
  function getStyleChanges() {
3773
- return styleChanges;
3771
+ return [...styleChanges];
3774
3772
  }
3775
3773
  function getStyleDiff(snapshotId1, snapshotId2) {
3776
3774
  const snapshot1 = styleHistory.find((s) => s.id === snapshotId1);
@@ -3778,19 +3776,12 @@ function getStyleDiff(snapshotId1, snapshotId2) {
3778
3776
  if (!snapshot1 || !snapshot2) {
3779
3777
  return { error: "Snapshot not found" };
3780
3778
  }
3781
- const diff = {
3782
- added: {},
3783
- removed: {},
3784
- modified: {}
3785
- };
3779
+ const diff = { added: {}, removed: {}, modified: {} };
3786
3780
  for (const [key, value] of Object.entries(snapshot2.styles)) {
3787
3781
  if (!(key in snapshot1.styles)) {
3788
3782
  diff.added[key] = value;
3789
3783
  } else if (JSON.stringify(snapshot1.styles[key]) !== JSON.stringify(value)) {
3790
- diff.modified[key] = {
3791
- old: snapshot1.styles[key],
3792
- new: value
3793
- };
3784
+ diff.modified[key] = { old: snapshot1.styles[key], new: value };
3794
3785
  }
3795
3786
  }
3796
3787
  for (const [key, value] of Object.entries(snapshot1.styles)) {
@@ -3806,22 +3797,13 @@ function takeSnapshot(selector, styles, source) {
3806
3797
  const existing = styleHistory.find((s) => s.selector === selector && s.hash === hash);
3807
3798
  if (existing) return existing.id;
3808
3799
  const id = `snapshot_${currentSnapshotId++}`;
3809
- const snapshot = {
3810
- id,
3811
- timestamp: Date.now(),
3812
- selector,
3813
- styles: { ...styles },
3814
- source,
3815
- hash
3816
- };
3817
- styleHistory.push(snapshot);
3818
- const previousSnapshot = styleHistory.slice(-2)[0];
3819
- if (previousSnapshot && previousSnapshot.selector === selector) {
3800
+ styleHistory.push({ id, timestamp: Date.now(), selector, styles: { ...styles }, source, hash });
3801
+ const previous = styleHistory[styleHistory.length - 2];
3802
+ if (previous && previous.selector === selector) {
3820
3803
  for (const [key, value] of Object.entries(styles)) {
3821
- const oldValue = previousSnapshot.styles[key];
3822
- if (!(key in previousSnapshot.styles)) {
3804
+ if (!(key in previous.styles)) {
3823
3805
  styleChanges.push({
3824
- id: `change_${Date.now()}_${Math.random()}`,
3806
+ id: `change_${Date.now()}_${Math.random().toString(36).slice(2)}`,
3825
3807
  timestamp: Date.now(),
3826
3808
  selector,
3827
3809
  property: key,
@@ -3829,26 +3811,26 @@ function takeSnapshot(selector, styles, source) {
3829
3811
  newValue: value,
3830
3812
  type: "add"
3831
3813
  });
3832
- } else if (JSON.stringify(oldValue) !== JSON.stringify(value)) {
3814
+ } else if (JSON.stringify(previous.styles[key]) !== JSON.stringify(value)) {
3833
3815
  styleChanges.push({
3834
- id: `change_${Date.now()}_${Math.random()}`,
3816
+ id: `change_${Date.now()}_${Math.random().toString(36).slice(2)}`,
3835
3817
  timestamp: Date.now(),
3836
3818
  selector,
3837
3819
  property: key,
3838
- oldValue,
3820
+ oldValue: previous.styles[key],
3839
3821
  newValue: value,
3840
3822
  type: "modify"
3841
3823
  });
3842
3824
  }
3843
3825
  }
3844
- for (const [key] of Object.entries(previousSnapshot.styles)) {
3826
+ for (const [key] of Object.entries(previous.styles)) {
3845
3827
  if (!(key in styles)) {
3846
3828
  styleChanges.push({
3847
- id: `change_${Date.now()}_${Math.random()}`,
3829
+ id: `change_${Date.now()}_${Math.random().toString(36).slice(2)}`,
3848
3830
  timestamp: Date.now(),
3849
3831
  selector,
3850
3832
  property: key,
3851
- oldValue: previousSnapshot.styles[key],
3833
+ oldValue: previous.styles[key],
3852
3834
  newValue: void 0,
3853
3835
  type: "remove"
3854
3836
  });
@@ -3858,31 +3840,156 @@ function takeSnapshot(selector, styles, source) {
3858
3840
  return id;
3859
3841
  }
3860
3842
  function exportTimeline() {
3861
- return JSON.stringify({
3862
- history: styleHistory,
3863
- changes: styleChanges,
3864
- exportedAt: Date.now()
3865
- }, null, 2);
3843
+ return JSON.stringify({ history: styleHistory, changes: styleChanges, exportedAt: Date.now() }, null, 2);
3866
3844
  }
3867
3845
  function clearTimeline() {
3868
3846
  styleHistory = [];
3869
3847
  styleChanges = [];
3870
3848
  currentSnapshotId = 0;
3871
3849
  }
3850
+ function isTimelineEnabled() {
3851
+ return timelineEnabled;
3852
+ }
3853
+
3854
+ // src/compiler/scanner.ts
3855
+ import fs2 from "fs";
3856
+ function scanFileForStyles(filePath, optimizer, source = null) {
3857
+ const errors = [];
3858
+ let foundCount = 0;
3859
+ try {
3860
+ const content = source !== null ? source : fs2.readFileSync(filePath, "utf8");
3861
+ if (!content || content.trim().length === 0) return { foundCount: 0, errors };
3862
+ const styleRegex = /(?:chain|smartChain|\$)\(((?:[^()]|\([^()]*\))*)\)/g;
3863
+ let match;
3864
+ while ((match = styleRegex.exec(content)) !== null) {
3865
+ try {
3866
+ const styleBody = match[1].trim();
3867
+ const cleanBody = styleBody.replace(/^['"\`]|['"\`]$/g, "");
3868
+ if (cleanBody && optimizer && typeof optimizer.trackStyles === "function") {
3869
+ optimizer.trackStyles([{ selectors: { "&": cleanBody } }]);
3870
+ foundCount++;
3871
+ }
3872
+ } catch (parseError) {
3873
+ errors.push(parseError);
3874
+ }
3875
+ }
3876
+ } catch (err) {
3877
+ errors.push(err);
3878
+ }
3879
+ return { foundCount, errors };
3880
+ }
3881
+
3882
+ // src/compiler/recipe.ts
3883
+ function recipe(options) {
3884
+ const { base, variants = {}, defaultVariants = {}, compoundVariants = [] } = options;
3885
+ const baseStyle = typeof base === "function" ? base() : base;
3886
+ const variantStyles = {};
3887
+ for (const [variantName, variantMap] of Object.entries(variants)) {
3888
+ variantStyles[variantName] = {};
3889
+ for (const [variantKey, variantStyle] of Object.entries(variantMap)) {
3890
+ variantStyles[variantName][variantKey] = typeof variantStyle === "function" ? variantStyle() : variantStyle;
3891
+ }
3892
+ }
3893
+ const compoundStyles = compoundVariants.map((cv) => ({
3894
+ condition: cv.variants || cv,
3895
+ style: typeof cv.style === "function" ? cv.style() : cv.style
3896
+ }));
3897
+ function mergeStyles(...styles) {
3898
+ const merged = { selectors: [] };
3899
+ for (const style of styles) {
3900
+ if (!style) continue;
3901
+ for (const [key, value] of Object.entries(style)) {
3902
+ if (key === "selectors") {
3903
+ const newSelectors = Array.isArray(value) ? value : [value];
3904
+ merged.selectors = [.../* @__PURE__ */ new Set([...merged.selectors || [], ...newSelectors])];
3905
+ } else if (key === "hover" && typeof value === "object") {
3906
+ if (!merged.hover) merged.hover = {};
3907
+ Object.assign(merged.hover, value);
3908
+ } else if (key !== "selectors") {
3909
+ merged[key] = value;
3910
+ }
3911
+ }
3912
+ }
3913
+ return merged;
3914
+ }
3915
+ function pick(variantSelection = {}) {
3916
+ const selected = { ...defaultVariants, ...variantSelection };
3917
+ const stylesToMerge = [];
3918
+ if (baseStyle) stylesToMerge.push(baseStyle);
3919
+ for (const [variantName, variantValue] of Object.entries(selected)) {
3920
+ const variantStyle = variantStyles[variantName]?.[variantValue];
3921
+ if (variantStyle) stylesToMerge.push(variantStyle);
3922
+ }
3923
+ for (const cv of compoundStyles) {
3924
+ if (Object.entries(cv.condition).every(([key, value]) => selected[key] === value) && cv.style) {
3925
+ stylesToMerge.push(cv.style);
3926
+ }
3927
+ }
3928
+ const merged = mergeStyles(...stylesToMerge);
3929
+ let styleBuilder = chain();
3930
+ for (const [prop, value] of Object.entries(merged)) {
3931
+ if (prop === "selectors" || prop === "hover") continue;
3932
+ if (styleBuilder[prop]) styleBuilder = styleBuilder[prop](value);
3933
+ }
3934
+ if (merged.hover) {
3935
+ styleBuilder = styleBuilder.hover();
3936
+ for (const [hoverProp, hoverValue] of Object.entries(merged.hover)) {
3937
+ if (styleBuilder[hoverProp]) styleBuilder = styleBuilder[hoverProp](hoverValue);
3938
+ }
3939
+ styleBuilder = styleBuilder.end();
3940
+ }
3941
+ return styleBuilder.$el(...merged.selectors || []);
3942
+ }
3943
+ pick.variants = variants;
3944
+ pick.defaultVariants = defaultVariants;
3945
+ pick.base = baseStyle;
3946
+ pick.getAllVariants = () => {
3947
+ const result = [];
3948
+ const variantKeys = Object.keys(variants);
3949
+ function generate(current, index) {
3950
+ if (index === variantKeys.length) {
3951
+ result.push({ ...current });
3952
+ return;
3953
+ }
3954
+ for (const v of Object.keys(variants[variantKeys[index]])) {
3955
+ current[variantKeys[index]] = v;
3956
+ generate(current, index + 1);
3957
+ }
3958
+ }
3959
+ generate({}, 0);
3960
+ return result;
3961
+ };
3962
+ pick.getVariantClassNames = () => {
3963
+ const classNames = {};
3964
+ for (const variant of pick.getAllVariants()) {
3965
+ const key = Object.entries(variant).map(([k, v]) => `${k}-${v}`).join("_");
3966
+ const def = pick(variant);
3967
+ if (def.selectors?.[0]) classNames[key] = def.selectors[0].replace(/^\./, "");
3968
+ }
3969
+ return classNames;
3970
+ };
3971
+ pick.compileAll = () => {
3972
+ const all = pick.getAllVariants();
3973
+ const styles = [];
3974
+ if (baseStyle?.selectors) styles.push(baseStyle);
3975
+ for (const v of all) {
3976
+ const d = pick(v);
3977
+ if (d?.selectors) styles.push(d);
3978
+ }
3979
+ return run(...styles);
3980
+ };
3981
+ return pick;
3982
+ }
3983
+
3984
+ // src/compiler/btt.ts
3872
3985
  var enableSourceComments = true;
3873
3986
  function getSourceLocation() {
3874
3987
  if (!enableSourceComments) return null;
3875
3988
  const stack = new Error().stack;
3876
3989
  if (!stack) return null;
3877
- const stackLines = stack.split("\n");
3878
- for (let i = 0; i < stackLines.length; i++) {
3879
- const line = stackLines[i];
3990
+ for (const line of stack.split("\n")) {
3880
3991
  const match = line.match(/([^/]+\.chain\.js):(\d+):\d+/);
3881
- if (match) {
3882
- const fileName = match[1];
3883
- const lineNumber = match[2];
3884
- return `${fileName}:${lineNumber}`;
3885
- }
3992
+ if (match) return `${match[1]}:${match[2]}`;
3886
3993
  }
3887
3994
  return null;
3888
3995
  }
@@ -3919,9 +4026,7 @@ var fetchWithHttps = (url) => {
3919
4026
  });
3920
4027
  };
3921
4028
  var loadCSSProperties = async () => {
3922
- if (chains.cachedValidProperties !== null && chains.cachedValidProperties.length > 0) {
3923
- return chains.cachedValidProperties;
3924
- }
4029
+ if (chains.cachedValidProperties?.length > 0) return chains.cachedValidProperties;
3925
4030
  try {
3926
4031
  const url = "https://raw.githubusercontent.com/mdn/data/main/css/properties.json";
3927
4032
  let data;
@@ -3935,14 +4040,9 @@ var loadCSSProperties = async () => {
3935
4040
  data = await fetchWithHttps(url);
3936
4041
  }
3937
4042
  const allProperties = Object.keys(data);
3938
- const baseProperties = /* @__PURE__ */ new Set();
3939
- allProperties.forEach((prop) => {
3940
- const baseProp = prop.replace(/^-(webkit|moz|ms|o)-/, "");
3941
- baseProperties.add(baseProp);
3942
- });
3943
- chains.cachedValidProperties = Array.from(baseProperties).sort();
4043
+ chains.cachedValidProperties = allProperties.map((p) => p.replace(/^-(webkit|moz|ms|o)-/, "")).filter((v, i, a) => a.indexOf(v) === i).sort();
3944
4044
  return chains.cachedValidProperties;
3945
- } catch (error) {
4045
+ } catch {
3946
4046
  chains.cachedValidProperties = COMMON_CSS_PROPERTIES2;
3947
4047
  return chains.cachedValidProperties;
3948
4048
  }
@@ -3953,11 +4053,8 @@ var chains = {
3953
4053
  classMap: {},
3954
4054
  atomicStats: null,
3955
4055
  async initializeProperties() {
3956
- if (this.cachedValidProperties && this.cachedValidProperties.length > 0) {
3957
- return;
3958
- }
3959
- const properties = await loadCSSProperties();
3960
- this.cachedValidProperties = properties;
4056
+ if (this.cachedValidProperties?.length > 0) return;
4057
+ this.cachedValidProperties = await loadCSSProperties();
3961
4058
  },
3962
4059
  getCachedProperties() {
3963
4060
  return this.cachedValidProperties;
@@ -3968,9 +4065,7 @@ function setAtomicOptimizer(optimizer) {
3968
4065
  atomicOptimizer = optimizer;
3969
4066
  }
3970
4067
  function configureAtomic(opts) {
3971
- if (atomicOptimizer) {
3972
- Object.assign(atomicOptimizer.options, opts);
3973
- }
4068
+ if (atomicOptimizer) Object.assign(atomicOptimizer.options, opts);
3974
4069
  }
3975
4070
  var tokens2 = tokens;
3976
4071
  function createTokens2(tokenValues) {
@@ -3985,21 +4080,13 @@ function processAtRule(rule, parentSelectors = null) {
3985
4080
  output = `@media ${rule.query} {
3986
4081
  `;
3987
4082
  if (rule.styles && typeof rule.styles === "object") {
3988
- let ruleBody = "";
3989
- for (const prop in rule.styles) {
3990
- const kebabKey = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
3991
- ruleBody += ` ${kebabKey}: ${rule.styles[prop]};
4083
+ let body = "";
4084
+ for (const prop in rule.styles) body += ` ${prop.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${rule.styles[prop]};
3992
4085
  `;
3993
- }
3994
- if (ruleBody.trim()) {
3995
- const selector = parentSelectors && parentSelectors.length > 0 ? parentSelectors.join(", ") : ".unknown-selector";
3996
- const sourceLocation = getSourceLocation();
3997
- if (enableSourceComments && sourceLocation) {
3998
- output += ` /* Generated from: ${sourceLocation} */
3999
- `;
4000
- }
4001
- output += ` ${selector} {
4002
- ${ruleBody} }
4086
+ if (body.trim()) {
4087
+ const sel = parentSelectors?.length ? parentSelectors.join(", ") : ".unknown-selector";
4088
+ output += ` ${sel} {
4089
+ ${body} }
4003
4090
  `;
4004
4091
  }
4005
4092
  }
@@ -4012,11 +4099,8 @@ ${ruleBody} }
4012
4099
  output += ` ${step} {
4013
4100
  `;
4014
4101
  for (const prop in rule.steps[step]) {
4015
- if (prop !== "selectors") {
4016
- const kebabKey = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
4017
- output += ` ${kebabKey}: ${rule.steps[step][prop]};
4102
+ if (prop !== "selectors") output += ` ${prop.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${rule.steps[step][prop]};
4018
4103
  `;
4019
- }
4020
4104
  }
4021
4105
  output += " }\n";
4022
4106
  }
@@ -4025,23 +4109,17 @@ ${ruleBody} }
4025
4109
  case "font-face":
4026
4110
  output = "@font-face {\n";
4027
4111
  for (const prop in rule.properties) {
4028
- if (prop !== "selectors") {
4029
- const kebabKey = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
4030
- output += ` ${kebabKey}: ${rule.properties[prop]};
4112
+ if (prop !== "selectors") output += ` ${prop.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${rule.properties[prop]};
4031
4113
  `;
4032
- }
4033
4114
  }
4034
4115
  output += "}\n";
4035
4116
  break;
4036
- default:
4037
- output = "";
4038
- break;
4039
4117
  }
4040
4118
  return output;
4041
4119
  }
4042
4120
  var run = (...args) => {
4043
4121
  if (args.length === 0) return "";
4044
- const validStyles = args.filter((value) => value && typeof value === "object");
4122
+ const validStyles = args.filter((v) => v && typeof v === "object");
4045
4123
  if (validStyles.length === 0) return "";
4046
4124
  let cssOutput = "";
4047
4125
  const styleObjs = [];
@@ -4052,77 +4130,47 @@ var run = (...args) => {
4052
4130
  cssOutput += processAtRule(value) + "\n";
4053
4131
  return;
4054
4132
  }
4055
- if (value.selectors) {
4056
- let mainRuleBody = "";
4057
- let subRulesOutput = "";
4058
- for (const key in value) {
4059
- if (!value.hasOwnProperty(key)) continue;
4060
- if ([
4061
- "selectors",
4062
- "atRules",
4063
- "hover",
4064
- "nestedRules",
4065
- "use",
4066
- "nest",
4067
- "themes",
4068
- "_componentName",
4069
- "_generateComponent",
4070
- "_framework",
4071
- "_propsDefinition"
4072
- ].includes(key)) continue;
4073
- if (key === "atRules" && Array.isArray(value[key])) {
4074
- value[key].forEach((rule) => {
4075
- subRulesOutput += processAtRule(rule, value.selectors);
4076
- });
4077
- continue;
4078
- }
4079
- if (key === "nestedRules" && Array.isArray(value[key])) {
4080
- value[key].forEach((rule) => {
4081
- let nestedBody = "";
4082
- for (const prop in rule.styles) {
4083
- const kebabKey2 = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
4084
- nestedBody += ` ${kebabKey2}: ${rule.styles[prop]};
4085
- `;
4086
- }
4087
- if (nestedBody) {
4088
- subRulesOutput += `${value.selectors.join(", ")} ${rule.selector} {
4089
- ${nestedBody} }
4133
+ if (!value.selectors) return;
4134
+ let mainBody = "", subOutput = "";
4135
+ for (const key in value) {
4136
+ if (!value.hasOwnProperty(key)) continue;
4137
+ if (["selectors", "atRules", "hover", "nestedRules", "use", "nest", "themes", "_componentName", "_generateComponent", "_framework", "_propsDefinition"].includes(key)) continue;
4138
+ if (key === "atRules" && Array.isArray(value[key])) {
4139
+ value[key].forEach((r) => {
4140
+ subOutput += processAtRule(r, value.selectors);
4141
+ });
4142
+ continue;
4143
+ }
4144
+ if (key === "nestedRules" && Array.isArray(value[key])) {
4145
+ value[key].forEach((r) => {
4146
+ let nb = "";
4147
+ for (const p in r.styles) nb += ` ${p.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${r.styles[p]};
4090
4148
  `;
4091
- }
4092
- });
4093
- continue;
4094
- }
4095
- if (key === "hover" && typeof value[key] === "object") {
4096
- let hoverBody = "";
4097
- for (const hoverKey in value[key]) {
4098
- const kebabKey2 = hoverKey.replace(/([A-Z])/g, "-$1").toLowerCase();
4099
- hoverBody += ` ${kebabKey2}: ${value[key][hoverKey]};
4149
+ if (nb) subOutput += `${value.selectors.join(", ")} ${r.selector} {
4150
+ ${nb} }
4100
4151
  `;
4101
- }
4102
- if (hoverBody) {
4103
- subRulesOutput += `${value.selectors.join(", ")}:hover {
4104
- ${hoverBody}}
4152
+ });
4153
+ continue;
4154
+ }
4155
+ if (key === "hover" && typeof value[key] === "object") {
4156
+ let hb = "";
4157
+ for (const hk in value[key]) hb += ` ${hk.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${value[key][hk]};
4105
4158
  `;
4106
- }
4107
- continue;
4108
- }
4109
- const kebabKey = key.replace(/([A-Z])/g, "-$1").toLowerCase();
4110
- mainRuleBody += ` ${kebabKey}: ${value[key]};
4159
+ if (hb) subOutput += `${value.selectors.join(", ")}:hover {
4160
+ ${hb}}
4111
4161
  `;
4162
+ continue;
4112
4163
  }
4113
- if (mainRuleBody.trim()) {
4114
- cssOutput += `${value.selectors.join(", ")} {
4115
- ${mainRuleBody}}
4164
+ mainBody += ` ${key.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${value[key]};
4116
4165
  `;
4117
- }
4118
- cssOutput += subRulesOutput;
4119
4166
  }
4167
+ if (mainBody.trim()) cssOutput += `${value.selectors.join(", ")} {
4168
+ ${mainBody}}
4169
+ `;
4170
+ cssOutput += subOutput;
4120
4171
  });
4121
4172
  cssOutput = cssOutput.replace(/\n{3,}/g, "\n\n").trim();
4122
- if (atomicOptimizer && atomicOptimizer.options.enabled) {
4123
- const result = atomicOptimizer.optimize(styleObjs);
4124
- return result.css;
4125
- }
4173
+ if (atomicOptimizer?.options.enabled) return atomicOptimizer.optimize(styleObjs).css;
4126
4174
  return cssOutput;
4127
4175
  };
4128
4176
  var compile = (obj) => {
@@ -4133,25 +4181,20 @@ var compile = (obj) => {
4133
4181
  if (!obj.hasOwnProperty(key)) continue;
4134
4182
  const element = obj[key];
4135
4183
  if (element && element.variants && typeof element.compileAll === "function") {
4136
- const cleanKey = key.includes("_") ? key.split("_").pop() : key;
4137
- const recipeOutput = element.compileAll(cleanKey);
4138
- cssString += recipeOutput + "\n";
4184
+ cssString += element.compileAll(key.includes("_") ? key.split("_").pop() : key) + "\n";
4139
4185
  continue;
4140
4186
  }
4141
- if (!element || !element.selectors || !element.selectors[0]) continue;
4187
+ if (!element?.selectors?.[0]) continue;
4142
4188
  const selectorKey = element.selectors.join(",");
4143
4189
  if (processedSelectors.has(selectorKey)) continue;
4144
4190
  processedSelectors.add(selectorKey);
4145
4191
  collected.push(element);
4146
4192
  const sourceLocation = getSourceLocation();
4147
- let elementCSS = "";
4148
- let subRulesCSS = "";
4149
- if (timelineEnabled) {
4193
+ let elementCSS = "", subRulesCSS = "";
4194
+ if (isTimelineEnabled()) {
4150
4195
  const styles = {};
4151
4196
  for (const prop in element) {
4152
- if (!["selectors", "atRules", "hover", "nestedRules", "use", "nest", "themes"].includes(prop)) {
4153
- styles[prop] = element[prop];
4154
- }
4197
+ if (!["selectors", "atRules", "hover", "nestedRules", "use", "nest", "themes"].includes(prop)) styles[prop] = element[prop];
4155
4198
  }
4156
4199
  takeSnapshot(element.selectors[0], styles, sourceLocation || "unknown");
4157
4200
  }
@@ -4161,41 +4204,25 @@ var compile = (obj) => {
4161
4204
  if (prop.startsWith("_") || !element.hasOwnProperty(prop)) continue;
4162
4205
  const value = element[prop];
4163
4206
  if (value === void 0 || value === null) continue;
4164
- const kebabKey = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
4165
- elementCSS += ` ${kebabKey}: ${value};
4207
+ elementCSS += ` ${prop.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${value};
4166
4208
  `;
4167
4209
  }
4168
- if (elementCSS.trim()) {
4169
- let block = `${element.selectors.join(", ")} {
4210
+ if (elementCSS.trim()) cssString += addSourceComment(`${element.selectors.join(", ")} {
4170
4211
  ${elementCSS}}
4171
- `;
4172
- cssString += addSourceComment(block, sourceLocation);
4173
- }
4212
+ `, sourceLocation);
4174
4213
  if (element.hover && typeof element.hover === "object") {
4175
- let hoverBody = "";
4176
- for (const hProp in element.hover) {
4177
- const hKebab = hProp.replace(/([A-Z])/g, "-$1").toLowerCase();
4178
- hoverBody += ` ${hKebab}: ${element.hover[hProp]};
4179
- `;
4180
- }
4181
- if (hoverBody) {
4182
- let block = `${element.selectors.join(", ")}:hover {
4183
- ${hoverBody}}
4214
+ let hb = "";
4215
+ for (const hp in element.hover) hb += ` ${hp.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${element.hover[hp]};
4184
4216
  `;
4185
- cssString += addSourceComment(block, sourceLocation);
4186
- }
4217
+ if (hb) cssString += addSourceComment(`${element.selectors.join(", ")}:hover {
4218
+ ${hb}}
4219
+ `, sourceLocation);
4187
4220
  }
4188
4221
  for (const prop in element) {
4189
4222
  if ((prop.startsWith(".") || prop.startsWith("&")) && typeof element[prop] === "object") {
4190
- const subElement = element[prop];
4191
- const parentSelector = element.selectors[0];
4192
- const subSelector = prop.startsWith("&") ? prop.replace("&", parentSelector) : `${parentSelector} ${prop}`;
4193
- cssString += compile({
4194
- [subSelector]: {
4195
- selectors: [subSelector],
4196
- ...subElement
4197
- }
4198
- }) + "\n";
4223
+ const parentSel = element.selectors[0];
4224
+ const subSel = prop.startsWith("&") ? prop.replace("&", parentSel) : `${parentSel} ${prop}`;
4225
+ cssString += compile({ [subSel]: { selectors: [subSel], ...element[prop] } }) + "\n";
4199
4226
  }
4200
4227
  }
4201
4228
  if (element.atRules && Array.isArray(element.atRules)) {
@@ -4206,25 +4233,21 @@ ${hoverBody}}
4206
4233
  if (element.themes && Array.isArray(element.themes)) {
4207
4234
  element.themes.forEach((theme) => {
4208
4235
  if (theme.styles) {
4209
- let themeCSS = "";
4210
- for (const tProp in theme.styles) {
4211
- if (tProp === "selectors") continue;
4212
- const tKebab = tProp.replace(/([A-Z])/g, "-$1").toLowerCase();
4213
- themeCSS += ` ${tKebab}: ${theme.styles[tProp]};
4214
- `;
4215
- }
4216
- if (themeCSS) {
4217
- let block = `${theme.styles.selectors?.join(", ") || element.selectors.join(", ")} {
4218
- ${themeCSS}}
4236
+ let tc = "";
4237
+ for (const tp in theme.styles) {
4238
+ if (tp === "selectors") continue;
4239
+ tc += ` ${tp.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${theme.styles[tp]};
4219
4240
  `;
4220
- subRulesCSS += addSourceComment(block, sourceLocation);
4221
4241
  }
4242
+ if (tc) subRulesCSS += addSourceComment(`${theme.styles.selectors?.join(", ") || element.selectors.join(", ")} {
4243
+ ${tc}}
4244
+ `, sourceLocation);
4222
4245
  }
4223
4246
  });
4224
4247
  }
4225
4248
  cssString += subRulesCSS;
4226
4249
  }
4227
- if (atomicOptimizer && atomicOptimizer.options.enabled) {
4250
+ if (atomicOptimizer?.options.enabled) {
4228
4251
  const result = atomicOptimizer.optimize(collected);
4229
4252
  chains.cssOutput = result.css;
4230
4253
  return result.css;
@@ -4232,175 +4255,8 @@ ${themeCSS}}
4232
4255
  chains.cssOutput = cssString.trim();
4233
4256
  return chains.cssOutput;
4234
4257
  };
4235
- function recipe(options) {
4236
- const {
4237
- base,
4238
- variants = {},
4239
- defaultVariants = {},
4240
- compoundVariants = []
4241
- } = options;
4242
- const baseStyle = typeof base === "function" ? base() : base;
4243
- const variantStyles = {};
4244
- for (const [variantName, variantMap] of Object.entries(variants)) {
4245
- variantStyles[variantName] = {};
4246
- for (const [variantKey, variantStyle] of Object.entries(variantMap)) {
4247
- variantStyles[variantName][variantKey] = typeof variantStyle === "function" ? variantStyle() : variantStyle;
4248
- }
4249
- }
4250
- const compoundStyles = compoundVariants.map((cv) => ({
4251
- condition: cv.variants || cv,
4252
- style: typeof cv.style === "function" ? cv.style() : cv.style
4253
- }));
4254
- function mergeStyles(...styles) {
4255
- const merged = { selectors: [] };
4256
- for (const style of styles) {
4257
- if (!style) continue;
4258
- for (const [key, value] of Object.entries(style)) {
4259
- if (key === "selectors") {
4260
- const newSelectors = Array.isArray(value) ? value : [value];
4261
- merged.selectors = [.../* @__PURE__ */ new Set([...merged.selectors || [], ...newSelectors])];
4262
- } else if (key === "hover" && typeof value === "object") {
4263
- if (!merged.hover) merged.hover = {};
4264
- Object.assign(merged.hover, value);
4265
- } else if (key !== "selectors") {
4266
- merged[key] = value;
4267
- }
4268
- }
4269
- }
4270
- return merged;
4271
- }
4272
- function pick(variantSelection = {}) {
4273
- const selected = { ...defaultVariants, ...variantSelection };
4274
- const stylesToMerge = [];
4275
- if (baseStyle) stylesToMerge.push(baseStyle);
4276
- for (const [variantName, variantValue] of Object.entries(selected)) {
4277
- const variantStyle = variantStyles[variantName]?.[variantValue];
4278
- if (variantStyle) stylesToMerge.push(variantStyle);
4279
- }
4280
- for (const cv of compoundStyles) {
4281
- const matches = Object.entries(cv.condition).every(
4282
- ([key, value]) => selected[key] === value
4283
- );
4284
- if (matches && cv.style) stylesToMerge.push(cv.style);
4285
- }
4286
- const merged = mergeStyles(...stylesToMerge);
4287
- let styleBuilder = chain();
4288
- for (const [prop, value] of Object.entries(merged)) {
4289
- if (prop === "selectors" || prop === "hover") continue;
4290
- if (styleBuilder[prop]) {
4291
- styleBuilder = styleBuilder[prop](value);
4292
- }
4293
- }
4294
- if (merged.hover) {
4295
- styleBuilder = styleBuilder.hover();
4296
- for (const [hoverProp, hoverValue] of Object.entries(merged.hover)) {
4297
- if (styleBuilder[hoverProp]) {
4298
- styleBuilder = styleBuilder[hoverProp](hoverValue);
4299
- }
4300
- }
4301
- styleBuilder = styleBuilder.end();
4302
- }
4303
- const selectors = merged.selectors || [];
4304
- return styleBuilder.$el(...selectors);
4305
- }
4306
- pick.variants = variants;
4307
- pick.defaultVariants = defaultVariants;
4308
- pick.base = baseStyle;
4309
- pick.getAllVariants = () => {
4310
- const result = [];
4311
- const variantKeys = Object.keys(variants);
4312
- function generate(current, index) {
4313
- if (index === variantKeys.length) {
4314
- result.push({ ...current });
4315
- return;
4316
- }
4317
- const variantName = variantKeys[index];
4318
- for (const variantValue of Object.keys(variants[variantName])) {
4319
- current[variantName] = variantValue;
4320
- generate(current, index + 1);
4321
- }
4322
- }
4323
- generate({}, 0);
4324
- return result;
4325
- };
4326
- pick.getVariantClassNames = () => {
4327
- const allVariants = pick.getAllVariants();
4328
- const classNames = {};
4329
- for (const variant of allVariants) {
4330
- const variantKey = Object.entries(variant).map(([k, v]) => `${k}-${v}`).join("_");
4331
- const styleDef = pick(variant);
4332
- if (styleDef.selectors && styleDef.selectors[0]) {
4333
- classNames[variantKey] = styleDef.selectors[0].replace(/^\./, "");
4334
- }
4335
- }
4336
- return classNames;
4337
- };
4338
- pick.compileAll = () => {
4339
- const allVariants = pick.getAllVariants();
4340
- const styles = [];
4341
- if (baseStyle && baseStyle.selectors) {
4342
- styles.push(baseStyle);
4343
- }
4344
- for (const variant of allVariants) {
4345
- const styleDef = pick(variant);
4346
- if (styleDef && styleDef.selectors) {
4347
- styles.push(styleDef);
4348
- }
4349
- }
4350
- for (const variantName of Object.keys(variants)) {
4351
- for (const variantKey of Object.keys(variants[variantName])) {
4352
- const variantStyle = variantStyles[variantName]?.[variantKey];
4353
- if (variantStyle && variantStyle.selectors) {
4354
- styles.push(variantStyle);
4355
- }
4356
- }
4357
- }
4358
- return run(...styles);
4359
- };
4360
- return pick;
4361
- }
4362
- function scanFileForStyles(filePath, optimizer, source = null) {
4363
- const errors = [];
4364
- let foundCount = 0;
4365
- try {
4366
- const content = source !== null ? source : fs2.readFileSync(filePath, "utf8");
4367
- if (!content || content.trim().length === 0) {
4368
- return { foundCount: 0, errors };
4369
- }
4370
- const styleRegex = /(?:chain|\$)\(((?:[^()]|\([^()]*\))*)\)/g;
4371
- let match;
4372
- while ((match = styleRegex.exec(content)) !== null) {
4373
- try {
4374
- const styleBody = match[1].trim();
4375
- const cleanBody = styleBody.replace(/^['"`]|['"`]$/g, "");
4376
- if (cleanBody) {
4377
- if (optimizer && typeof optimizer.trackStyles === "function") {
4378
- optimizer.trackStyles([{ selectors: { "&": cleanBody } }]);
4379
- }
4380
- foundCount++;
4381
- }
4382
- } catch (parseError) {
4383
- errors.push(parseError);
4384
- if (process.env.DEBUG) {
4385
- console.error(`[Scanner] Parse error in ${filePath}:`, parseError);
4386
- }
4387
- }
4388
- }
4389
- if (foundCount > 0 && process.env.DEBUG) {
4390
- console.log(chalk2.magenta(`[Scanner] Found ${foundCount} styles in ${filePath}`));
4391
- }
4392
- } catch (err) {
4393
- errors.push(err);
4394
- if (process.env.DEBUG) {
4395
- console.error(`[Scanner] Error processing ${filePath}:`, err);
4396
- }
4397
- }
4398
- return { foundCount, errors };
4399
- }
4400
4258
  chains.initializeProperties().catch((err) => {
4401
- if (process.env.DEBUG) {
4402
- console.error("Failed to load CSS properties:", err.message);
4403
- }
4259
+ if (process.env.DEBUG) console.error("Failed to load CSS properties:", err.message);
4404
4260
  });
4405
4261
 
4406
4262
  // src/compiler/atomic-optimizer.ts
@@ -6333,7 +6189,7 @@ var ChainCSSCompiler = class {
6333
6189
  if (oldest) {
6334
6190
  this.styleCache.delete(oldest);
6335
6191
  if (this.config.verbose) {
6336
- console.log(chalk3.gray(` \u{1F9F9} Cache evicted: ${oldest.slice(0, 8)}...`));
6192
+ console.log(chalk2.gray(` \u{1F9F9} Cache evicted: ${oldest.slice(0, 8)}...`));
6337
6193
  }
6338
6194
  }
6339
6195
  }
@@ -6353,7 +6209,7 @@ var ChainCSSCompiler = class {
6353
6209
  console.log(` \u2514\u2500 Processed ${processedCount} chain() styles from ${id.split("/").pop()}`);
6354
6210
  }
6355
6211
  } catch (error) {
6356
- console.error(chalk3.red(` \u274C Error compiling source ${id}: ${error}`));
6212
+ console.error(chalk2.red(` \u274C Error compiling source ${id}: ${error}`));
6357
6213
  }
6358
6214
  }
6359
6215
  /**
@@ -6378,7 +6234,7 @@ var ChainCSSCompiler = class {
6378
6234
  }
6379
6235
  } catch (err) {
6380
6236
  if (this.config.verbose) {
6381
- console.warn(chalk3.yellow(` \u26A0\uFE0F Failed to parse style body: ${input.substring(0, 100)}...`));
6237
+ console.warn(chalk2.yellow(` \u26A0\uFE0F Failed to parse style body: ${input.substring(0, 100)}...`));
6382
6238
  }
6383
6239
  }
6384
6240
  return {};
@@ -6587,7 +6443,7 @@ var ChainCSSCompiler = class {
6587
6443
  if (this.atomicOptimizer) this.atomicOptimizer.reset();
6588
6444
  this.accumulatedCSS = "";
6589
6445
  if (!this.config.silent) {
6590
- console.log(chalk3.blue("\n\u{1F50D} Phase 1: Scanning & Usage Analysis..."));
6446
+ console.log(chalk2.blue("\n\u{1F50D} Phase 1: Scanning & Usage Analysis..."));
6591
6447
  }
6592
6448
  const BATCH_SIZE = PERFORMANCE.BATCH_SIZE || 10;
6593
6449
  const errors = [];
@@ -6612,7 +6468,7 @@ var ChainCSSCompiler = class {
6612
6468
  }
6613
6469
  } catch (err) {
6614
6470
  if (this.config.verbose) {
6615
- console.warn(chalk3.yellow(` \u26A0\uFE0F Scanning fallback for ${path5.basename(file)}`));
6471
+ console.warn(chalk2.yellow(` \u26A0\uFE0F Scanning fallback for ${path5.basename(file)}`));
6616
6472
  }
6617
6473
  const result = scanFileForStyles(file, this.atomicOptimizer);
6618
6474
  if (result.errors.length > 0) {
@@ -6623,14 +6479,14 @@ var ChainCSSCompiler = class {
6623
6479
  });
6624
6480
  await Promise.allSettled(batchPromises);
6625
6481
  if (this.config.verbose && i % (BATCH_SIZE * 5) === 0) {
6626
- console.log(chalk3.gray(` \u{1F4CA} Processed ${Math.min(i + BATCH_SIZE, components.length)}/${components.length} files`));
6482
+ console.log(chalk2.gray(` \u{1F4CA} Processed ${Math.min(i + BATCH_SIZE, components.length)}/${components.length} files`));
6627
6483
  }
6628
6484
  }
6629
6485
  if (errors.length > 0 && this.config.verbose) {
6630
- console.warn(chalk3.yellow(` \u26A0\uFE0F ${errors.length} scanning errors occurred`));
6486
+ console.warn(chalk2.yellow(` \u26A0\uFE0F ${errors.length} scanning errors occurred`));
6631
6487
  }
6632
6488
  if (!this.config.silent) {
6633
- console.log(chalk3.blue("\n\u{1F3D7}\uFE0F Phase 2: Generating Component Styles..."));
6489
+ console.log(chalk2.blue("\n\u{1F3D7}\uFE0F Phase 2: Generating Component Styles..."));
6634
6490
  }
6635
6491
  const publicDir = path5.resolve(process.cwd(), "public");
6636
6492
  const manifestDir = path5.resolve(process.cwd(), ".chaincss", "manifest");
@@ -6661,7 +6517,7 @@ var ChainCSSCompiler = class {
6661
6517
  const result = this.compileStyle(name, style);
6662
6518
  if (this.config.verbose) {
6663
6519
  const className2 = Object.values(result.classMap)[0];
6664
- console.log(chalk3.gray(` \u{1F4DD} ${name} \u2192 ${className2 || "(empty)"}`));
6520
+ console.log(chalk2.gray(` \u{1F4DD} ${name} \u2192 ${className2 || "(empty)"}`));
6665
6521
  }
6666
6522
  const className = Object.values(result.classMap)[0];
6667
6523
  if (className) {
@@ -6687,21 +6543,21 @@ var ChainCSSCompiler = class {
6687
6543
  }
6688
6544
  processedComponents++;
6689
6545
  if (this.config.verbose) {
6690
- console.log(chalk3.green(` \u2728 ${baseName} \u2192 ${path5.relative(process.cwd(), classFilePath)}`));
6546
+ console.log(chalk2.green(` \u2728 ${baseName} \u2192 ${path5.relative(process.cwd(), classFilePath)}`));
6691
6547
  }
6692
6548
  }
6693
6549
  } catch (error) {
6694
- console.error(chalk3.red(` \u274C Failed to process ${baseName}: ${error.message}`));
6550
+ console.error(chalk2.red(` \u274C Failed to process ${baseName}: ${error.message}`));
6695
6551
  }
6696
6552
  }
6697
6553
  if (!this.config.silent) {
6698
- console.log(chalk3.blue("\n\u{1F30D} Phase 3: Finalizing Global Assets..."));
6554
+ console.log(chalk2.blue("\n\u{1F30D} Phase 3: Finalizing Global Assets..."));
6699
6555
  }
6700
6556
  const finalAtomicCSS = this.atomicOptimizer ? this.atomicOptimizer.generateAtomicCSS() : "";
6701
6557
  const globalCssPath = path5.join(publicDir, "global.css");
6702
6558
  fs6.writeFileSync(globalCssPath, formatCSS(finalAtomicCSS, this.config.output.minify));
6703
6559
  if (this.config.verbose) {
6704
- console.log(chalk3.blue(` \u{1F4E6} Global CSS \u2192 ${path5.relative(process.cwd(), globalCssPath)} (${finalAtomicCSS.length} bytes)`));
6560
+ console.log(chalk2.blue(` \u{1F4E6} Global CSS \u2192 ${path5.relative(process.cwd(), globalCssPath)} (${finalAtomicCSS.length} bytes)`));
6705
6561
  }
6706
6562
  const manifestData = {
6707
6563
  version: VERSION,
@@ -6713,25 +6569,25 @@ var ChainCSSCompiler = class {
6713
6569
  const manifestPath = path5.join(manifestDir, "manifest.json");
6714
6570
  fs6.writeFileSync(manifestPath, JSON.stringify(manifestData, null, 2));
6715
6571
  if (this.config.verbose) {
6716
- console.log(chalk3.blue(` \u{1F4E6} Manifest \u2192 ${path5.relative(process.cwd(), manifestPath)}`));
6572
+ console.log(chalk2.blue(` \u{1F4E6} Manifest \u2192 ${path5.relative(process.cwd(), manifestPath)}`));
6717
6573
  }
6718
6574
  if (!this.config.silent) {
6719
- console.log(chalk3.green(`
6575
+ console.log(chalk2.green(`
6720
6576
  \u2705 Build Complete!`));
6721
- console.log(chalk3.gray(` \u{1F4C1} Components processed: ${processedComponents}`));
6722
- console.log(chalk3.gray(` \u{1F4C1} Class files generated: ${generatedClassFiles.length}`));
6723
- console.log(chalk3.gray(` \u{1F4C1} Global CSS: ${path5.relative(process.cwd(), globalCssPath)}`));
6724
- console.log(chalk3.gray(` \u{1F4C1} Manifest: ${path5.relative(process.cwd(), manifestPath)}`));
6577
+ console.log(chalk2.gray(` \u{1F4C1} Components processed: ${processedComponents}`));
6578
+ console.log(chalk2.gray(` \u{1F4C1} Class files generated: ${generatedClassFiles.length}`));
6579
+ console.log(chalk2.gray(` \u{1F4C1} Global CSS: ${path5.relative(process.cwd(), globalCssPath)}`));
6580
+ console.log(chalk2.gray(` \u{1F4C1} Manifest: ${path5.relative(process.cwd(), manifestPath)}`));
6725
6581
  if (this.atomicOptimizer) {
6726
6582
  const atomicCount = Object.keys(this.atomicOptimizer.atomicMap).length;
6727
6583
  const stats = this.atomicOptimizer.getStats();
6728
- console.log(chalk3.cyan(`
6584
+ console.log(chalk2.cyan(`
6729
6585
  \u{1F4CA} Optimization Stats:`));
6730
- console.log(chalk3.gray(` Atomic Rules: ${atomicCount}`));
6731
- console.log(chalk3.gray(` Total Styles: ${stats.totalStyles}`));
6732
- console.log(chalk3.gray(` Unique Properties: ${stats.uniqueProperties}`));
6586
+ console.log(chalk2.gray(` Atomic Rules: ${atomicCount}`));
6587
+ console.log(chalk2.gray(` Total Styles: ${stats.totalStyles}`));
6588
+ console.log(chalk2.gray(` Unique Properties: ${stats.uniqueProperties}`));
6733
6589
  if (stats.savings) {
6734
- console.log(chalk3.green(` CSS Savings: ${stats.savings}`));
6590
+ console.log(chalk2.green(` CSS Savings: ${stats.savings}`));
6735
6591
  }
6736
6592
  }
6737
6593
  }