chaincss 2.1.2 → 2.1.4
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/cli/index.js +4 -1
- package/dist/compiler/index.js +4 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +14 -591
- package/dist/plugins/vite.js +4 -1
- package/package.json +1 -1
- package/src/compiler/prefixer.ts +10 -4
- package/src/index.ts +2 -1
package/dist/cli/index.js
CHANGED
|
@@ -1407,6 +1407,9 @@ ${rules}}
|
|
|
1407
1407
|
});
|
|
1408
1408
|
|
|
1409
1409
|
// src/compiler/prefixer.ts
|
|
1410
|
+
function __import__(name) {
|
|
1411
|
+
return new Function("name", "return import(name)")(name);
|
|
1412
|
+
}
|
|
1410
1413
|
async function loadPostcss() {
|
|
1411
1414
|
if (postcss) return postcss;
|
|
1412
1415
|
if (loadingPromises.has("postcss")) return loadingPromises.get("postcss");
|
|
@@ -1433,7 +1436,7 @@ async function loadAutoprefixer() {
|
|
|
1433
1436
|
const promise = (async () => {
|
|
1434
1437
|
if (!autoprefixerLoaded) {
|
|
1435
1438
|
try {
|
|
1436
|
-
const module =
|
|
1439
|
+
const module = __import__("autoprefixer");
|
|
1437
1440
|
autoprefixer = module.default || module;
|
|
1438
1441
|
} catch (err) {
|
|
1439
1442
|
if (process.env.DEBUG) {
|
package/dist/compiler/index.js
CHANGED
|
@@ -3980,6 +3980,9 @@ ${rules}}
|
|
|
3980
3980
|
|
|
3981
3981
|
// src/compiler/prefixer.ts
|
|
3982
3982
|
var postcss = null;
|
|
3983
|
+
function __import__(name) {
|
|
3984
|
+
return new Function("name", "return import(name)")(name);
|
|
3985
|
+
}
|
|
3983
3986
|
var autoprefixer = null;
|
|
3984
3987
|
var postcssLoaded = false;
|
|
3985
3988
|
var autoprefixerLoaded = false;
|
|
@@ -4010,7 +4013,7 @@ async function loadAutoprefixer() {
|
|
|
4010
4013
|
const promise = (async () => {
|
|
4011
4014
|
if (!autoprefixerLoaded) {
|
|
4012
4015
|
try {
|
|
4013
|
-
const module =
|
|
4016
|
+
const module = __import__("autoprefixer");
|
|
4014
4017
|
autoprefixer = module.default || module;
|
|
4015
4018
|
} catch (err) {
|
|
4016
4019
|
if (process.env.DEBUG) {
|
package/dist/index.d.ts
CHANGED
|
@@ -38,7 +38,6 @@ export type { ChainCSSConfig, CompileResult, ChainCSSPlugin } from './core/types
|
|
|
38
38
|
export type { Chain } from './compiler/Chain.js';
|
|
39
39
|
export type { AnimationConfig, KeyframeDefinition } from './compiler/animations.js';
|
|
40
40
|
export type { BreakpointsMap, ResponsiveStyle } from './compiler/breakpoints.js';
|
|
41
|
-
export * from './runtime/index.js';
|
|
42
41
|
export declare const VERSION = "3.0.0";
|
|
43
42
|
import { chain } from './compiler/Chain.js';
|
|
44
43
|
export default chain;
|
package/dist/index.js
CHANGED
|
@@ -2046,8 +2046,8 @@ var helpers = {
|
|
|
2046
2046
|
rgba: (r, g, b, a = 1) => {
|
|
2047
2047
|
return `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
2048
2048
|
},
|
|
2049
|
-
hsla: (
|
|
2050
|
-
return `hsla(${
|
|
2049
|
+
hsla: (h, s, l, a = 1) => {
|
|
2050
|
+
return `hsla(${h}, ${s}%, ${l}%, ${a})`;
|
|
2051
2051
|
},
|
|
2052
2052
|
// String helpers
|
|
2053
2053
|
url: (path6) => {
|
|
@@ -2655,18 +2655,6 @@ var chain = (useTokens = true) => createChain(useTokens);
|
|
|
2655
2655
|
var debugMode2 = false;
|
|
2656
2656
|
var runtimeMacros = { ...macros };
|
|
2657
2657
|
var globalManifest = {};
|
|
2658
|
-
var setManifest = (manifest) => {
|
|
2659
|
-
if (manifest.atomicMap) {
|
|
2660
|
-
globalManifest = manifest.atomicMap;
|
|
2661
|
-
} else if (manifest.atomicClasses) {
|
|
2662
|
-
globalManifest = manifest.atomicClasses;
|
|
2663
|
-
} else {
|
|
2664
|
-
globalManifest = manifest || {};
|
|
2665
|
-
}
|
|
2666
|
-
if (debugMode2) {
|
|
2667
|
-
console.log("[ChainCSS] Manifest loaded with", Object.keys(globalManifest).length, "entries");
|
|
2668
|
-
}
|
|
2669
|
-
};
|
|
2670
2658
|
var RuntimeChain = class _RuntimeChain {
|
|
2671
2659
|
constructor(useTokens = false) {
|
|
2672
2660
|
this.useTokens = useTokens;
|
|
@@ -2808,7 +2796,6 @@ var RuntimeChain = class _RuntimeChain {
|
|
|
2808
2796
|
return { ...this.catcher };
|
|
2809
2797
|
}
|
|
2810
2798
|
};
|
|
2811
|
-
var $t = () => new RuntimeChain(true).proxy;
|
|
2812
2799
|
|
|
2813
2800
|
// src/core/auto-detector.ts
|
|
2814
2801
|
var AutoDetector = class _AutoDetector {
|
|
@@ -3364,43 +3351,7 @@ ${rules}}
|
|
|
3364
3351
|
}
|
|
3365
3352
|
};
|
|
3366
3353
|
var styleInjector = new StyleInjector();
|
|
3367
|
-
var setTokens = (t) => styleInjector.setTokens(t);
|
|
3368
3354
|
var compileRuntime = (s, moduleId) => styleInjector.injectMultiple(s, moduleId);
|
|
3369
|
-
var removeRuntimeModule = (moduleId) => styleInjector.removeModule(moduleId);
|
|
3370
|
-
function runRuntime(...styles) {
|
|
3371
|
-
let css = "";
|
|
3372
|
-
for (const style of styles) {
|
|
3373
|
-
if (style.selectors && style.selectors.length > 0) {
|
|
3374
|
-
const combinedSelector = style.selectors.join(", ");
|
|
3375
|
-
const mainBody = processStyleObject(style, styleInjector["tokenStore"], { useTokens: true, debug: false });
|
|
3376
|
-
if (mainBody && Object.keys(mainBody).length > 0) {
|
|
3377
|
-
let rules = "";
|
|
3378
|
-
for (const [prop, val] of Object.entries(mainBody)) {
|
|
3379
|
-
rules += ` ${prop}: ${val};
|
|
3380
|
-
`;
|
|
3381
|
-
}
|
|
3382
|
-
css += `${combinedSelector} {
|
|
3383
|
-
${rules}}
|
|
3384
|
-
`;
|
|
3385
|
-
}
|
|
3386
|
-
if (style.hover) {
|
|
3387
|
-
const hoverBody = processStyleObject(style.hover, styleInjector["tokenStore"], { useTokens: true, debug: false });
|
|
3388
|
-
if (hoverBody && Object.keys(hoverBody).length > 0) {
|
|
3389
|
-
let rules = "";
|
|
3390
|
-
for (const [prop, val] of Object.entries(hoverBody)) {
|
|
3391
|
-
rules += ` ${prop}: ${val};
|
|
3392
|
-
`;
|
|
3393
|
-
}
|
|
3394
|
-
css += `${combinedSelector}:hover {
|
|
3395
|
-
${rules}}
|
|
3396
|
-
`;
|
|
3397
|
-
}
|
|
3398
|
-
}
|
|
3399
|
-
}
|
|
3400
|
-
}
|
|
3401
|
-
styleInjector.writeToDOM(css);
|
|
3402
|
-
return css;
|
|
3403
|
-
}
|
|
3404
3355
|
|
|
3405
3356
|
// src/runtime/auto-hooks.tsx
|
|
3406
3357
|
function useSmartStyles(styleBuilder, deps = [], options = {}) {
|
|
@@ -3454,8 +3405,8 @@ function useSmartStyles(styleBuilder, deps = [], options = {}) {
|
|
|
3454
3405
|
}
|
|
3455
3406
|
function createSmartComponent(Component, baseStyles) {
|
|
3456
3407
|
const SmartComponent = (props) => {
|
|
3457
|
-
const styles = useSmartStyles((
|
|
3458
|
-
let instance =
|
|
3408
|
+
const styles = useSmartStyles((chain2) => {
|
|
3409
|
+
let instance = chain2();
|
|
3459
3410
|
if (baseStyles) {
|
|
3460
3411
|
instance = baseStyles(instance);
|
|
3461
3412
|
}
|
|
@@ -4989,6 +4940,9 @@ ${rules}}
|
|
|
4989
4940
|
|
|
4990
4941
|
// src/compiler/prefixer.ts
|
|
4991
4942
|
var postcss = null;
|
|
4943
|
+
function __import__(name) {
|
|
4944
|
+
return new Function("name", "return import(name)")(name);
|
|
4945
|
+
}
|
|
4992
4946
|
var autoprefixer = null;
|
|
4993
4947
|
var postcssLoaded = false;
|
|
4994
4948
|
var autoprefixerLoaded = false;
|
|
@@ -4999,8 +4953,8 @@ async function loadPostcss() {
|
|
|
4999
4953
|
const promise = (async () => {
|
|
5000
4954
|
if (!postcssLoaded) {
|
|
5001
4955
|
try {
|
|
5002
|
-
const
|
|
5003
|
-
postcss =
|
|
4956
|
+
const module = await import("postcss");
|
|
4957
|
+
postcss = module.default || module;
|
|
5004
4958
|
} catch (err) {
|
|
5005
4959
|
if (process.env.DEBUG) {
|
|
5006
4960
|
console.warn("postcss not installed, using lightweight prefixing");
|
|
@@ -5019,8 +4973,8 @@ async function loadAutoprefixer() {
|
|
|
5019
4973
|
const promise = (async () => {
|
|
5020
4974
|
if (!autoprefixerLoaded) {
|
|
5021
4975
|
try {
|
|
5022
|
-
const
|
|
5023
|
-
autoprefixer =
|
|
4976
|
+
const module = __import__("autoprefixer");
|
|
4977
|
+
autoprefixer = module.default || module;
|
|
5024
4978
|
} catch (err) {
|
|
5025
4979
|
if (process.env.DEBUG) {
|
|
5026
4980
|
console.warn("autoprefixer not installed");
|
|
@@ -5868,9 +5822,9 @@ var CacheManager = class {
|
|
|
5868
5822
|
if (cached !== void 0) {
|
|
5869
5823
|
return cached;
|
|
5870
5824
|
}
|
|
5871
|
-
const
|
|
5872
|
-
this.set(key,
|
|
5873
|
-
return
|
|
5825
|
+
const computed = await compute();
|
|
5826
|
+
this.set(key, computed, ttl);
|
|
5827
|
+
return computed;
|
|
5874
5828
|
}
|
|
5875
5829
|
};
|
|
5876
5830
|
|
|
@@ -6988,490 +6942,6 @@ function createTheme(contract, themeValues) {
|
|
|
6988
6942
|
return new Theme(tokens3);
|
|
6989
6943
|
}
|
|
6990
6944
|
|
|
6991
|
-
// src/runtime/react.tsx
|
|
6992
|
-
import React2, { useMemo, useRef as useRef2, useState as useState2, useEffect as useEffect2 } from "react";
|
|
6993
|
-
import { Fragment, jsx } from "react/jsx-runtime";
|
|
6994
|
-
function hashStyleObject(obj) {
|
|
6995
|
-
const str = JSON.stringify(obj);
|
|
6996
|
-
let hash = 0;
|
|
6997
|
-
for (let i = 0; i < str.length; i++) {
|
|
6998
|
-
const char = str.charCodeAt(i);
|
|
6999
|
-
hash = (hash << 5) - hash + char;
|
|
7000
|
-
hash = hash & hash;
|
|
7001
|
-
}
|
|
7002
|
-
return Math.abs(hash).toString(36);
|
|
7003
|
-
}
|
|
7004
|
-
function useChainStyles(styles, deps = [], options = {}) {
|
|
7005
|
-
const { namespace = "c", debug = false, ssr = false } = options;
|
|
7006
|
-
const instanceId = useRef2(Math.random().toString(36).substring(2, 7));
|
|
7007
|
-
const moduleId = useRef2(`chaincss-module-${instanceId.current}`);
|
|
7008
|
-
const [forceUpdate, setForceUpdate] = useState2(0);
|
|
7009
|
-
useEffect2(() => {
|
|
7010
|
-
return () => {
|
|
7011
|
-
if (!ssr && moduleId.current) {
|
|
7012
|
-
removeRuntimeModule(moduleId.current);
|
|
7013
|
-
if (debug) {
|
|
7014
|
-
console.log(`[ChainCSS] Cleaned up module: ${moduleId.current}`);
|
|
7015
|
-
}
|
|
7016
|
-
}
|
|
7017
|
-
};
|
|
7018
|
-
}, [ssr]);
|
|
7019
|
-
return useMemo(() => {
|
|
7020
|
-
const finalClassMap = {};
|
|
7021
|
-
const injectionBundle = {};
|
|
7022
|
-
for (const [key, styleDef] of Object.entries(styles)) {
|
|
7023
|
-
let styleObject = {};
|
|
7024
|
-
if (styleDef && typeof styleDef.$el === "function") {
|
|
7025
|
-
styleObject = styleDef.$el();
|
|
7026
|
-
if (debug) {
|
|
7027
|
-
console.log(`[ChainCSS] Processing style: ${key}`, styleObject);
|
|
7028
|
-
}
|
|
7029
|
-
} else if (styleDef && typeof styleDef === "object") {
|
|
7030
|
-
styleObject = { ...styleDef };
|
|
7031
|
-
}
|
|
7032
|
-
const staticClasses = Array.isArray(styleObject._classes) ? styleObject._classes : [];
|
|
7033
|
-
const internalKeys = ["catcher", "proxy", "useTokens", "componentName", "_isChain", "_classes", "_name"];
|
|
7034
|
-
internalKeys.forEach((k) => delete styleObject[k]);
|
|
7035
|
-
const hash = hashStyleObject(styleObject);
|
|
7036
|
-
const dynamicClassName = `${namespace}-${key}-${hash}`;
|
|
7037
|
-
const hasStyles = Object.keys(styleObject).length > 0;
|
|
7038
|
-
if (!ssr && hasStyles) {
|
|
7039
|
-
injectionBundle[dynamicClassName] = styleObject;
|
|
7040
|
-
}
|
|
7041
|
-
const classParts = [...staticClasses];
|
|
7042
|
-
if (hasStyles) {
|
|
7043
|
-
classParts.push(dynamicClassName);
|
|
7044
|
-
}
|
|
7045
|
-
finalClassMap[key] = classParts.join(" ").trim();
|
|
7046
|
-
}
|
|
7047
|
-
if (!ssr && Object.keys(injectionBundle).length > 0) {
|
|
7048
|
-
compileRuntime(injectionBundle, moduleId.current);
|
|
7049
|
-
if (debug) {
|
|
7050
|
-
console.log(`[ChainCSS] Injected ${Object.keys(injectionBundle).length} styles for module ${moduleId.current}`);
|
|
7051
|
-
}
|
|
7052
|
-
}
|
|
7053
|
-
return finalClassMap;
|
|
7054
|
-
}, [forceUpdate, ...deps]);
|
|
7055
|
-
}
|
|
7056
|
-
function useDynamicChainStyles(styleFactory, deps = [], options) {
|
|
7057
|
-
const styles = useMemo(() => styleFactory(), deps);
|
|
7058
|
-
return useChainStyles(styles, deps, options);
|
|
7059
|
-
}
|
|
7060
|
-
function useThemeChainStyles(styles, theme, options) {
|
|
7061
|
-
const themedStyles = useMemo(() => {
|
|
7062
|
-
if (typeof styles === "function") return styles(theme);
|
|
7063
|
-
return styles;
|
|
7064
|
-
}, [styles, theme]);
|
|
7065
|
-
return useChainStyles(themedStyles, [theme], options);
|
|
7066
|
-
}
|
|
7067
|
-
function ChainCSSGlobal({ styles, tokens: tokens3, children }) {
|
|
7068
|
-
if (tokens3) {
|
|
7069
|
-
setTokens(tokens3);
|
|
7070
|
-
}
|
|
7071
|
-
if (styles) {
|
|
7072
|
-
useChainStyles(styles, [], { watch: true });
|
|
7073
|
-
}
|
|
7074
|
-
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
7075
|
-
}
|
|
7076
|
-
function cx(...classes) {
|
|
7077
|
-
const result = [];
|
|
7078
|
-
for (const cls of classes) {
|
|
7079
|
-
if (!cls) continue;
|
|
7080
|
-
if (typeof cls === "string") {
|
|
7081
|
-
result.push(cls);
|
|
7082
|
-
} else if (typeof cls === "object") {
|
|
7083
|
-
for (const [key, value] of Object.entries(cls)) {
|
|
7084
|
-
if (value) result.push(key);
|
|
7085
|
-
}
|
|
7086
|
-
}
|
|
7087
|
-
}
|
|
7088
|
-
return result.join(" ");
|
|
7089
|
-
}
|
|
7090
|
-
function withChainStyles(styles, options) {
|
|
7091
|
-
return function WrappedComponent(props) {
|
|
7092
|
-
const styleProps = typeof styles === "function" ? styles(props) : styles;
|
|
7093
|
-
const classNames = useChainStyles(styleProps, [], options);
|
|
7094
|
-
const Component = props.component || props.wrappedComponent;
|
|
7095
|
-
return /* @__PURE__ */ jsx(Component, { ...props, chainStyles: classNames });
|
|
7096
|
-
};
|
|
7097
|
-
}
|
|
7098
|
-
function createStyledComponent(elementType, styles, options) {
|
|
7099
|
-
const StyledComponent = (props) => {
|
|
7100
|
-
const { className: additionalClassName, ...rest } = props;
|
|
7101
|
-
const styleDef = typeof styles === "function" ? styles() : styles;
|
|
7102
|
-
const classNames = useChainStyles({ root: styleDef }, [], options);
|
|
7103
|
-
const combinedClassName = cx(classNames.root, additionalClassName);
|
|
7104
|
-
return React2.createElement(elementType, {
|
|
7105
|
-
...rest,
|
|
7106
|
-
className: combinedClassName
|
|
7107
|
-
});
|
|
7108
|
-
};
|
|
7109
|
-
const displayName = typeof elementType === "string" ? elementType : elementType.displayName || "Component";
|
|
7110
|
-
StyledComponent.displayName = `ChainCSS.${displayName}`;
|
|
7111
|
-
return StyledComponent;
|
|
7112
|
-
}
|
|
7113
|
-
function useComputedStyles(styles, props, deps = [], options) {
|
|
7114
|
-
const computedStyles = useMemo(() => styles(props), [props, ...deps]);
|
|
7115
|
-
return useChainStyles(computedStyles, deps, options);
|
|
7116
|
-
}
|
|
7117
|
-
var debugEnabled = false;
|
|
7118
|
-
function enableChainCSSDebug() {
|
|
7119
|
-
debugEnabled = true;
|
|
7120
|
-
if (typeof window !== "undefined") {
|
|
7121
|
-
window.__CHAINCSS_DEBUG__ = true;
|
|
7122
|
-
console.log("\u{1F50D} ChainCSS Debug Mode Enabled");
|
|
7123
|
-
}
|
|
7124
|
-
}
|
|
7125
|
-
function disableChainCSSDebug() {
|
|
7126
|
-
debugEnabled = false;
|
|
7127
|
-
if (typeof window !== "undefined") {
|
|
7128
|
-
window.__CHAINCSS_DEBUG__ = false;
|
|
7129
|
-
console.log("\u{1F50D} ChainCSS Debug Mode Disabled");
|
|
7130
|
-
}
|
|
7131
|
-
}
|
|
7132
|
-
function isDebugEnabled() {
|
|
7133
|
-
return debugEnabled || typeof window !== "undefined" && window.__CHAINCSS_DEBUG__;
|
|
7134
|
-
}
|
|
7135
|
-
|
|
7136
|
-
// src/runtime/vue.ts
|
|
7137
|
-
import { ref, computed, watch, onUnmounted, inject, provide, h } from "vue";
|
|
7138
|
-
var CHAIN_CSS_KEY = /* @__PURE__ */ Symbol("chaincss");
|
|
7139
|
-
function useAtomicClasses(styles, options = {}) {
|
|
7140
|
-
const { atomic = true, global = false, debug = false } = options;
|
|
7141
|
-
const id = `chain-${Math.random().toString(36).substring(2, 11)}`;
|
|
7142
|
-
const moduleId = `chaincss-vue-module-${id}`;
|
|
7143
|
-
const classMap = ref({});
|
|
7144
|
-
onUnmounted(() => {
|
|
7145
|
-
removeRuntimeModule(moduleId);
|
|
7146
|
-
if (debug) {
|
|
7147
|
-
console.log(`[ChainCSS Vue] Cleaned up module: ${moduleId}`);
|
|
7148
|
-
}
|
|
7149
|
-
});
|
|
7150
|
-
const compileStyles = () => {
|
|
7151
|
-
const resolvedStyles = typeof styles === "function" ? styles() : styles?.value || styles;
|
|
7152
|
-
if (!resolvedStyles) return {};
|
|
7153
|
-
const compiledStyles = {};
|
|
7154
|
-
const classNames = {};
|
|
7155
|
-
for (const [key, styleDef] of Object.entries(resolvedStyles)) {
|
|
7156
|
-
const className = `${key}-${id}`;
|
|
7157
|
-
const styleObj = typeof styleDef === "function" ? styleDef() : styleDef;
|
|
7158
|
-
classNames[key] = className;
|
|
7159
|
-
compiledStyles[`${key}_${id}`] = {
|
|
7160
|
-
selectors: [`.${className}`],
|
|
7161
|
-
...styleObj
|
|
7162
|
-
};
|
|
7163
|
-
}
|
|
7164
|
-
const result = compileRuntime(compiledStyles, moduleId);
|
|
7165
|
-
if (debug) {
|
|
7166
|
-
console.log(`[ChainCSS Vue] Compiled ${Object.keys(classNames).length} styles for module ${moduleId}`);
|
|
7167
|
-
}
|
|
7168
|
-
classMap.value = classNames;
|
|
7169
|
-
return result;
|
|
7170
|
-
};
|
|
7171
|
-
if (typeof styles === "object" && styles !== null && "value" in styles) {
|
|
7172
|
-
watch(styles, () => {
|
|
7173
|
-
compileStyles();
|
|
7174
|
-
}, { deep: true });
|
|
7175
|
-
}
|
|
7176
|
-
compileStyles();
|
|
7177
|
-
return {
|
|
7178
|
-
classes: computed(() => classMap.value),
|
|
7179
|
-
cx: (name) => classMap.value[name] || "",
|
|
7180
|
-
cn: (...names) => names.map((name) => classMap.value[name]).filter(Boolean).join(" "),
|
|
7181
|
-
inject: (newStyles) => {
|
|
7182
|
-
const injectedId = `chaincss-injected-${Date.now()}`;
|
|
7183
|
-
compileRuntime(newStyles, injectedId);
|
|
7184
|
-
if (debug) {
|
|
7185
|
-
console.log(`[ChainCSS Vue] Injected additional styles: ${injectedId}`);
|
|
7186
|
-
}
|
|
7187
|
-
}
|
|
7188
|
-
};
|
|
7189
|
-
}
|
|
7190
|
-
var ChainCSSGlobal2 = {
|
|
7191
|
-
name: "ChainCSSGlobal",
|
|
7192
|
-
props: {
|
|
7193
|
-
styles: {
|
|
7194
|
-
type: Object,
|
|
7195
|
-
required: false,
|
|
7196
|
-
default: () => ({})
|
|
7197
|
-
},
|
|
7198
|
-
tokens: {
|
|
7199
|
-
type: Object,
|
|
7200
|
-
required: false,
|
|
7201
|
-
default: () => ({})
|
|
7202
|
-
},
|
|
7203
|
-
debug: {
|
|
7204
|
-
type: Boolean,
|
|
7205
|
-
default: false
|
|
7206
|
-
}
|
|
7207
|
-
},
|
|
7208
|
-
setup(props) {
|
|
7209
|
-
if (props.tokens && Object.keys(props.tokens).length > 0) {
|
|
7210
|
-
styleInjector.setTokens(props.tokens);
|
|
7211
|
-
}
|
|
7212
|
-
if (props.styles && Object.keys(props.styles).length > 0) {
|
|
7213
|
-
useAtomicClasses(props.styles, { debug: props.debug });
|
|
7214
|
-
}
|
|
7215
|
-
return () => null;
|
|
7216
|
-
}
|
|
7217
|
-
};
|
|
7218
|
-
function createStyledComponent2(styles, tag = "div", options = {}) {
|
|
7219
|
-
return {
|
|
7220
|
-
name: "ChainCSSStyledComponent",
|
|
7221
|
-
props: {
|
|
7222
|
-
className: { type: String, default: "" },
|
|
7223
|
-
as: { type: String, default: tag }
|
|
7224
|
-
},
|
|
7225
|
-
setup(props, { slots, attrs }) {
|
|
7226
|
-
const resolvedStyles = typeof styles === "function" ? styles() : styles;
|
|
7227
|
-
const { classes } = useAtomicClasses({ root: resolvedStyles }, options);
|
|
7228
|
-
const combinedClass = computed(() => {
|
|
7229
|
-
const rootClass = classes.value?.root || "";
|
|
7230
|
-
return [rootClass, props.className].filter(Boolean).join(" ");
|
|
7231
|
-
});
|
|
7232
|
-
return () => {
|
|
7233
|
-
return h(props.as || tag, {
|
|
7234
|
-
class: combinedClass.value,
|
|
7235
|
-
...attrs
|
|
7236
|
-
}, slots.default?.());
|
|
7237
|
-
};
|
|
7238
|
-
}
|
|
7239
|
-
};
|
|
7240
|
-
}
|
|
7241
|
-
function createStyledComponents(components, options) {
|
|
7242
|
-
const result = {};
|
|
7243
|
-
for (const [name, config] of Object.entries(components)) {
|
|
7244
|
-
const { element = "div", styles } = config;
|
|
7245
|
-
result[name] = createStyledComponent2(styles, element, options);
|
|
7246
|
-
}
|
|
7247
|
-
return result;
|
|
7248
|
-
}
|
|
7249
|
-
function useComputedStyles2(styles, props, options) {
|
|
7250
|
-
const computedStyles = computed(() => ({ root: styles(props) }));
|
|
7251
|
-
const { classes } = useAtomicClasses(computedStyles, options);
|
|
7252
|
-
return {
|
|
7253
|
-
classes,
|
|
7254
|
-
rootClass: computed(() => classes.value?.root || "")
|
|
7255
|
-
};
|
|
7256
|
-
}
|
|
7257
|
-
function provideStyleContext(theme) {
|
|
7258
|
-
const themeRef = ref(theme);
|
|
7259
|
-
provide(CHAIN_CSS_KEY, themeRef);
|
|
7260
|
-
return themeRef;
|
|
7261
|
-
}
|
|
7262
|
-
function injectStyleContext() {
|
|
7263
|
-
return inject(CHAIN_CSS_KEY, ref({}));
|
|
7264
|
-
}
|
|
7265
|
-
|
|
7266
|
-
// src/runtime/svelte.ts
|
|
7267
|
-
function useAtomicClasses2() {
|
|
7268
|
-
return { subscribe: () => {
|
|
7269
|
-
}, get: () => ({}) };
|
|
7270
|
-
}
|
|
7271
|
-
function cx2(...args) {
|
|
7272
|
-
return args.filter(Boolean).join(" ");
|
|
7273
|
-
}
|
|
7274
|
-
function ChainCSSGlobal3() {
|
|
7275
|
-
return null;
|
|
7276
|
-
}
|
|
7277
|
-
function createStyledComponent3() {
|
|
7278
|
-
return () => null;
|
|
7279
|
-
}
|
|
7280
|
-
function createStyledComponents2() {
|
|
7281
|
-
return {};
|
|
7282
|
-
}
|
|
7283
|
-
function useComputedStyles3() {
|
|
7284
|
-
return { subscribe: () => {
|
|
7285
|
-
}, get: () => "" };
|
|
7286
|
-
}
|
|
7287
|
-
function provideStyleContext2() {
|
|
7288
|
-
}
|
|
7289
|
-
function injectStyleContext2() {
|
|
7290
|
-
return {};
|
|
7291
|
-
}
|
|
7292
|
-
function chainStyles() {
|
|
7293
|
-
return {};
|
|
7294
|
-
}
|
|
7295
|
-
|
|
7296
|
-
// src/runtime/hmr.ts
|
|
7297
|
-
function getHMREnvironment() {
|
|
7298
|
-
if (typeof window === "undefined") return "none";
|
|
7299
|
-
if (typeof import.meta !== "undefined" && import.meta.hot) {
|
|
7300
|
-
return "vite";
|
|
7301
|
-
}
|
|
7302
|
-
if (module.hot) {
|
|
7303
|
-
return "webpack";
|
|
7304
|
-
}
|
|
7305
|
-
return "none";
|
|
7306
|
-
}
|
|
7307
|
-
function setupHMR() {
|
|
7308
|
-
const env = getHMREnvironment();
|
|
7309
|
-
if (env === "vite") {
|
|
7310
|
-
setupViteHMR();
|
|
7311
|
-
} else if (env === "webpack") {
|
|
7312
|
-
setupWebpackHMR();
|
|
7313
|
-
}
|
|
7314
|
-
}
|
|
7315
|
-
function setupViteHMR() {
|
|
7316
|
-
if (typeof window === "undefined") return;
|
|
7317
|
-
const hot = import.meta.hot;
|
|
7318
|
-
if (!hot) return;
|
|
7319
|
-
hot.on("chaincss:update", (payload) => {
|
|
7320
|
-
console.log(`[ChainCSS HMR] \u{1F504} Updating styles for ${payload.file}`);
|
|
7321
|
-
if (payload.css) {
|
|
7322
|
-
const styleId = "chaincss-hmr-styles";
|
|
7323
|
-
let styleElement = document.getElementById(styleId);
|
|
7324
|
-
if (!styleElement) {
|
|
7325
|
-
styleElement = document.createElement("style");
|
|
7326
|
-
styleElement.id = styleId;
|
|
7327
|
-
styleElement.setAttribute("data-chaincss", "hmr");
|
|
7328
|
-
document.head.appendChild(styleElement);
|
|
7329
|
-
}
|
|
7330
|
-
styleElement.textContent = payload.css;
|
|
7331
|
-
console.log(`[ChainCSS HMR] \u2705 Injected ${payload.css.length} bytes of CSS`);
|
|
7332
|
-
}
|
|
7333
|
-
if (payload.map) {
|
|
7334
|
-
if (typeof window !== "undefined") {
|
|
7335
|
-
window.__CHAINCSS_MANIFEST__ = payload.map;
|
|
7336
|
-
}
|
|
7337
|
-
console.log(`[ChainCSS HMR] \u2705 Updated manifest with ${Object.keys(payload.map).length} entries`);
|
|
7338
|
-
}
|
|
7339
|
-
if (payload.styles) {
|
|
7340
|
-
const moduleId = `hmr-${payload.file}-${payload.timestamp || Date.now()}`;
|
|
7341
|
-
const result = compileRuntime(payload.styles, moduleId);
|
|
7342
|
-
console.log(`[ChainCSS HMR] \u2705 Recompiled ${Object.keys(result).length} styles`);
|
|
7343
|
-
}
|
|
7344
|
-
});
|
|
7345
|
-
hot.on("vite:beforeUpdate", () => {
|
|
7346
|
-
console.log("[ChainCSS HMR] \u{1F9F9} Clearing runtime styles before update");
|
|
7347
|
-
styleInjector.removeAll();
|
|
7348
|
-
});
|
|
7349
|
-
console.log("[ChainCSS HMR] \u2705 Vite HMR setup complete");
|
|
7350
|
-
}
|
|
7351
|
-
function setupWebpackHMR() {
|
|
7352
|
-
if (typeof window === "undefined") return;
|
|
7353
|
-
const hot = module.hot;
|
|
7354
|
-
if (!hot) return;
|
|
7355
|
-
hot.accept((err) => {
|
|
7356
|
-
if (err) {
|
|
7357
|
-
console.error("[ChainCSS HMR] \u274C Update failed:", err);
|
|
7358
|
-
return;
|
|
7359
|
-
}
|
|
7360
|
-
console.log("[ChainCSS HMR] \u{1F504} Webpack HMR update");
|
|
7361
|
-
styleInjector.removeAll();
|
|
7362
|
-
});
|
|
7363
|
-
hot.dispose(() => {
|
|
7364
|
-
console.log("[ChainCSS HMR] \u{1F9F9} Cleaning up styles");
|
|
7365
|
-
styleInjector.removeAll();
|
|
7366
|
-
});
|
|
7367
|
-
console.log("[ChainCSS HMR] \u2705 Webpack HMR setup complete");
|
|
7368
|
-
}
|
|
7369
|
-
function registerForHMR(moduleId, styles, callback) {
|
|
7370
|
-
const env = getHMREnvironment();
|
|
7371
|
-
if (env === "vite") {
|
|
7372
|
-
registerViteHMR(moduleId, styles, callback);
|
|
7373
|
-
} else if (env === "webpack") {
|
|
7374
|
-
registerWebpackHMR(moduleId, styles, callback);
|
|
7375
|
-
}
|
|
7376
|
-
}
|
|
7377
|
-
function registerViteHMR(moduleId, styles, callback) {
|
|
7378
|
-
const hot = import.meta.hot;
|
|
7379
|
-
if (!hot) return;
|
|
7380
|
-
hot.accept(() => {
|
|
7381
|
-
console.log(`[ChainCSS HMR] \u{1F504} Accepting update for ${moduleId}`);
|
|
7382
|
-
styleInjector.removeModule(moduleId);
|
|
7383
|
-
if (callback && styles) {
|
|
7384
|
-
callback(styles);
|
|
7385
|
-
}
|
|
7386
|
-
});
|
|
7387
|
-
hot.dispose(() => {
|
|
7388
|
-
console.log(`[ChainCSS HMR] \u{1F9F9} Disposing module: ${moduleId}`);
|
|
7389
|
-
styleInjector.removeModule(moduleId);
|
|
7390
|
-
});
|
|
7391
|
-
}
|
|
7392
|
-
function registerWebpackHMR(moduleId, styles, callback) {
|
|
7393
|
-
const hot = module.hot;
|
|
7394
|
-
if (!hot) return;
|
|
7395
|
-
hot.accept(() => {
|
|
7396
|
-
console.log(`[ChainCSS HMR] \u{1F504} Webpack HMR accept for ${moduleId}`);
|
|
7397
|
-
if (callback && styles) {
|
|
7398
|
-
callback(styles);
|
|
7399
|
-
}
|
|
7400
|
-
});
|
|
7401
|
-
hot.dispose(() => {
|
|
7402
|
-
console.log(`[ChainCSS HMR] \u{1F9F9} Webpack HMR dispose for ${moduleId}`);
|
|
7403
|
-
styleInjector.removeModule(moduleId);
|
|
7404
|
-
});
|
|
7405
|
-
}
|
|
7406
|
-
if (typeof window !== "undefined") {
|
|
7407
|
-
setupHMR();
|
|
7408
|
-
}
|
|
7409
|
-
|
|
7410
|
-
// src/runtime/utils.ts
|
|
7411
|
-
function generateStyleId(prefix = "chain") {
|
|
7412
|
-
const random = Math.random().toString(36).substring(2, 10);
|
|
7413
|
-
const timestamp = Date.now().toString(36);
|
|
7414
|
-
return `${prefix}-${timestamp}-${random}`;
|
|
7415
|
-
}
|
|
7416
|
-
function hashString2(str) {
|
|
7417
|
-
let hash = 0;
|
|
7418
|
-
for (let i = 0; i < str.length; i++) {
|
|
7419
|
-
hash = (hash << 5) - hash + str.charCodeAt(i);
|
|
7420
|
-
hash |= 0;
|
|
7421
|
-
}
|
|
7422
|
-
return Math.abs(hash).toString(36);
|
|
7423
|
-
}
|
|
7424
|
-
function kebabCase2(str) {
|
|
7425
|
-
return str.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
7426
|
-
}
|
|
7427
|
-
var isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
7428
|
-
var isDevelopment = process.env.NODE_ENV === "development";
|
|
7429
|
-
var isProduction = process.env.NODE_ENV === "production";
|
|
7430
|
-
function debounce(fn, delay) {
|
|
7431
|
-
let timeoutId;
|
|
7432
|
-
return (...args) => {
|
|
7433
|
-
clearTimeout(timeoutId);
|
|
7434
|
-
timeoutId = setTimeout(() => fn(...args), delay);
|
|
7435
|
-
};
|
|
7436
|
-
}
|
|
7437
|
-
function memoize(fn) {
|
|
7438
|
-
const cache = /* @__PURE__ */ new Map();
|
|
7439
|
-
const memoized = ((...args) => {
|
|
7440
|
-
const key = JSON.stringify(args);
|
|
7441
|
-
if (cache.has(key)) {
|
|
7442
|
-
return cache.get(key);
|
|
7443
|
-
}
|
|
7444
|
-
const result = fn(...args);
|
|
7445
|
-
cache.set(key, result);
|
|
7446
|
-
return result;
|
|
7447
|
-
});
|
|
7448
|
-
memoized.cache = cache;
|
|
7449
|
-
return memoized;
|
|
7450
|
-
}
|
|
7451
|
-
function cn(...classes) {
|
|
7452
|
-
return classes.filter(Boolean).join(" ");
|
|
7453
|
-
}
|
|
7454
|
-
function devWarn(message, ...args) {
|
|
7455
|
-
if (isDevelopment) {
|
|
7456
|
-
console.warn(`[ChainCSS] ${message}`, ...args);
|
|
7457
|
-
}
|
|
7458
|
-
}
|
|
7459
|
-
function devLog(message, ...args) {
|
|
7460
|
-
if (isDevelopment) {
|
|
7461
|
-
console.log(`[ChainCSS] ${message}`, ...args);
|
|
7462
|
-
}
|
|
7463
|
-
}
|
|
7464
|
-
function logError(message, error) {
|
|
7465
|
-
console.error(`[ChainCSS] ${message}`, error || "");
|
|
7466
|
-
}
|
|
7467
|
-
function createDebugger(module2) {
|
|
7468
|
-
return {
|
|
7469
|
-
log: (...args) => devLog(`[${module2}]`, ...args),
|
|
7470
|
-
warn: (...args) => devWarn(`[${module2}]`, ...args),
|
|
7471
|
-
error: (...args) => logError(`[${module2}]`, ...args)
|
|
7472
|
-
};
|
|
7473
|
-
}
|
|
7474
|
-
|
|
7475
6945
|
// src/index.ts
|
|
7476
6946
|
var VERSION2 = "3.0.0";
|
|
7477
6947
|
var index_default = chain;
|
|
@@ -7484,14 +6954,10 @@ if (typeof process !== "undefined" && process.env?.NODE_ENV !== "test") {
|
|
|
7484
6954
|
}
|
|
7485
6955
|
export {
|
|
7486
6956
|
chain as $,
|
|
7487
|
-
$t,
|
|
7488
6957
|
AtomicOptimizer,
|
|
7489
6958
|
AutoDetector,
|
|
7490
6959
|
CacheManager,
|
|
7491
6960
|
ChainCSSCompiler,
|
|
7492
|
-
ChainCSSGlobal,
|
|
7493
|
-
ChainCSSGlobal3 as ChainCSSGlobalSvelte,
|
|
7494
|
-
ChainCSSGlobal2 as ChainCSSGlobalVue,
|
|
7495
6961
|
ChainCSSPrefixer,
|
|
7496
6962
|
DesignTokens,
|
|
7497
6963
|
PersistentCache,
|
|
@@ -7501,38 +6967,21 @@ export {
|
|
|
7501
6967
|
autoDetector,
|
|
7502
6968
|
buildChain,
|
|
7503
6969
|
chain,
|
|
7504
|
-
chainStyles,
|
|
7505
6970
|
smartChain as chainV3,
|
|
7506
6971
|
clearTimeline,
|
|
7507
|
-
cn as cnUtils,
|
|
7508
|
-
compileRuntime as compile,
|
|
7509
6972
|
compileChainCSS,
|
|
7510
6973
|
configureAtomic,
|
|
7511
6974
|
createAnimation,
|
|
7512
|
-
createDebugger,
|
|
7513
6975
|
createTokens as createDesignTokens,
|
|
7514
6976
|
createSmartComponent,
|
|
7515
|
-
createStyledComponent,
|
|
7516
|
-
createStyledComponent3 as createStyledSvelteComponent,
|
|
7517
|
-
createStyledComponents2 as createStyledSvelteComponents,
|
|
7518
|
-
createStyledComponent2 as createStyledVueComponent,
|
|
7519
|
-
createStyledComponents as createStyledVueComponents,
|
|
7520
6977
|
createTheme,
|
|
7521
6978
|
createThemeContract,
|
|
7522
6979
|
createTokens2 as createTokens,
|
|
7523
|
-
cx,
|
|
7524
|
-
cx2 as cxSvelte,
|
|
7525
|
-
debounce,
|
|
7526
6980
|
index_default as default,
|
|
7527
|
-
devLog,
|
|
7528
|
-
devWarn,
|
|
7529
|
-
disableChainCSSDebug,
|
|
7530
|
-
enableChainCSSDebug,
|
|
7531
6981
|
enableDebug,
|
|
7532
6982
|
enableTimeline,
|
|
7533
6983
|
expandShorthand,
|
|
7534
6984
|
exportTimeline,
|
|
7535
|
-
generateStyleId,
|
|
7536
6985
|
getAnimationPreset,
|
|
7537
6986
|
getAnimationPresetNames,
|
|
7538
6987
|
getAvailableShorthands,
|
|
@@ -7545,42 +6994,16 @@ export {
|
|
|
7545
6994
|
getSuggestions,
|
|
7546
6995
|
handleShorthand,
|
|
7547
6996
|
hasAnimationPreset,
|
|
7548
|
-
hashString2 as hashString,
|
|
7549
6997
|
helpers,
|
|
7550
|
-
injectStyleContext,
|
|
7551
|
-
injectStyleContext2 as injectStyleContextSvelte,
|
|
7552
|
-
isBrowser,
|
|
7553
|
-
isDebugEnabled,
|
|
7554
|
-
isDevelopment,
|
|
7555
|
-
isProduction,
|
|
7556
6998
|
isShorthand,
|
|
7557
|
-
kebabCase2 as kebabCase,
|
|
7558
|
-
logError,
|
|
7559
6999
|
macros,
|
|
7560
|
-
memoize,
|
|
7561
|
-
provideStyleContext,
|
|
7562
|
-
provideStyleContext2 as provideStyleContextSvelte,
|
|
7563
7000
|
recipe,
|
|
7564
|
-
registerForHMR,
|
|
7565
|
-
runRuntime as run,
|
|
7566
7001
|
runtimeChain,
|
|
7567
7002
|
setBreakpoints,
|
|
7568
|
-
setManifest,
|
|
7569
|
-
setupHMR,
|
|
7570
7003
|
shorthandMap,
|
|
7571
7004
|
smartChain,
|
|
7572
|
-
styleInjector,
|
|
7573
7005
|
tokens2 as tokens,
|
|
7574
|
-
useAtomicClasses,
|
|
7575
|
-
useAtomicClasses2 as useAtomicClassesSvelte,
|
|
7576
|
-
useChainStyles,
|
|
7577
|
-
useComputedStyles,
|
|
7578
|
-
useComputedStyles3 as useComputedStylesSvelte,
|
|
7579
|
-
useComputedStyles2 as useComputedStylesVue,
|
|
7580
|
-
useDynamicChainStyles,
|
|
7581
7006
|
useSmartStyles,
|
|
7582
|
-
useThemeChainStyles,
|
|
7583
7007
|
validateTheme,
|
|
7584
|
-
withChainStyles,
|
|
7585
7008
|
withSmartStyles
|
|
7586
7009
|
};
|
package/dist/plugins/vite.js
CHANGED
|
@@ -1357,6 +1357,9 @@ ${rules}}
|
|
|
1357
1357
|
|
|
1358
1358
|
// src/compiler/prefixer.ts
|
|
1359
1359
|
var postcss = null;
|
|
1360
|
+
function __import__(name) {
|
|
1361
|
+
return new Function("name", "return import(name)")(name);
|
|
1362
|
+
}
|
|
1360
1363
|
var autoprefixer = null;
|
|
1361
1364
|
var postcssLoaded = false;
|
|
1362
1365
|
var autoprefixerLoaded = false;
|
|
@@ -1387,7 +1390,7 @@ async function loadAutoprefixer() {
|
|
|
1387
1390
|
const promise = (async () => {
|
|
1388
1391
|
if (!autoprefixerLoaded) {
|
|
1389
1392
|
try {
|
|
1390
|
-
const module =
|
|
1393
|
+
const module = __import__("autoprefixer");
|
|
1391
1394
|
autoprefixer = module.default || module;
|
|
1392
1395
|
} catch (err) {
|
|
1393
1396
|
if (process.env.DEBUG) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chaincss",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"description": "ChainCSS v3.0 - The first CSS-in-JS library with true auto-detection mixed mode. Zero runtime by default, dynamic when you need it.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
package/src/compiler/prefixer.ts
CHANGED
|
@@ -23,6 +23,12 @@ type Autoprefixer = any;
|
|
|
23
23
|
|
|
24
24
|
// Declare variables for optional dependencies (initially null)
|
|
25
25
|
let postcss: PostCSS | null = null;
|
|
26
|
+
|
|
27
|
+
// Helper to load optional deps without Vite static analysis
|
|
28
|
+
function __import__(name: string): Promise<any> {
|
|
29
|
+
return new Function("name", "return import(name)")(name);
|
|
30
|
+
}
|
|
31
|
+
|
|
26
32
|
let browserslist: Browserslist | null = null;
|
|
27
33
|
let caniuse: any = null;
|
|
28
34
|
let autoprefixer: Autoprefixer | null = null;
|
|
@@ -65,8 +71,8 @@ async function loadBrowserslist() {
|
|
|
65
71
|
const promise = (async () => {
|
|
66
72
|
if (!browserslistLoaded) {
|
|
67
73
|
try {
|
|
68
|
-
const module =
|
|
69
|
-
browserslist = module.default || module;
|
|
74
|
+
const module = __import__('browserslist');
|
|
75
|
+
browserslist = (module as any).default || module;
|
|
70
76
|
} catch (err) {
|
|
71
77
|
browserslist = null;
|
|
72
78
|
}
|
|
@@ -109,8 +115,8 @@ async function loadAutoprefixer() {
|
|
|
109
115
|
if (!autoprefixerLoaded) {
|
|
110
116
|
try {
|
|
111
117
|
// @ts-ignore - autoprefixer is optional
|
|
112
|
-
const module =
|
|
113
|
-
autoprefixer = module.default || module;
|
|
118
|
+
const module = __import__('autoprefixer');
|
|
119
|
+
autoprefixer = (module as any).default || module;
|
|
114
120
|
} catch (err) {
|
|
115
121
|
if (process.env.DEBUG) {
|
|
116
122
|
console.warn('autoprefixer not installed');
|
package/src/index.ts
CHANGED
|
@@ -153,7 +153,8 @@ export type { BreakpointsMap, ResponsiveStyle } from './compiler/breakpoints.js'
|
|
|
153
153
|
// ============================================================================
|
|
154
154
|
// Runtime Exports (for runtime mode) - unchanged
|
|
155
155
|
// ============================================================================
|
|
156
|
-
|
|
156
|
+
// Runtime available via separate import: "chaincss/runtime"
|
|
157
|
+
// export * from './runtime/index.js';
|
|
157
158
|
|
|
158
159
|
// ============================================================================
|
|
159
160
|
// Version - UPDATE to 3.0.0
|