chaincss 2.0.7 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/CODE_OF_CONDUCT.md +21 -0
- package/CONTRIBUTING.md +28 -0
- package/README.md +455 -226
- package/demo/demo/node_modules/caniuse-db/fulldata-json/data-2.0.json +1 -0
- package/demo/index.html +16 -0
- package/demo/package.json +20 -0
- package/demo/src/App.tsx +117 -0
- package/demo/src/chaincss-barrel.ts +9 -0
- package/demo/src/main.tsx +8 -0
- package/demo/src/styles.chain.ts +300 -0
- package/demo/vite.config.ts +46 -0
- package/dist/cli/commands/build.d.ts +0 -1
- package/dist/cli/commands/cache.d.ts +1 -0
- package/dist/cli/commands/init.d.ts +6 -3
- package/dist/cli/commands/timeline.d.ts +0 -1
- package/dist/cli/commands/watch.d.ts +0 -1
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +3213 -5296
- package/dist/cli/types.d.ts +51 -20
- package/dist/cli/utils/config-loader.d.ts +0 -1
- package/dist/cli/utils/file-utils.d.ts +27 -3
- package/dist/cli/utils/logger.d.ts +0 -1
- package/dist/compiler/Chain.d.ts +215 -0
- package/dist/compiler/animations.d.ts +76 -0
- package/dist/compiler/atomic-optimizer.d.ts +47 -12
- package/dist/compiler/breakpoints.d.ts +46 -0
- package/dist/compiler/btt.d.ts +36 -60
- package/dist/compiler/cache-manager.d.ts +58 -4
- package/dist/compiler/commonProps.d.ts +0 -1
- package/dist/compiler/content-addressable-cache.d.ts +78 -0
- package/dist/compiler/helpers.d.ts +54 -0
- package/dist/compiler/index.d.ts +16 -9
- package/dist/compiler/index.js +4450 -4316
- package/dist/compiler/prefixer.d.ts +17 -1
- package/dist/compiler/shorthands.d.ts +28 -0
- package/dist/compiler/suggestions.d.ts +43 -0
- package/dist/compiler/theme-contract.d.ts +16 -27
- package/dist/compiler/token-resolver.d.ts +69 -0
- package/dist/compiler/tokens.d.ts +33 -8
- package/dist/core/auto-detector.d.ts +34 -0
- package/dist/core/common-utils.d.ts +97 -0
- package/dist/core/compiler.d.ts +63 -23
- package/dist/core/constants.d.ts +137 -36
- package/dist/core/smart-chain.d.ts +3 -0
- package/dist/core/types.d.ts +122 -15
- package/dist/core/utils.d.ts +134 -17
- package/dist/index.d.ts +52 -8
- package/dist/index.js +7090 -5578
- package/dist/plugins/vite.d.ts +7 -5
- package/dist/plugins/vite.js +2964 -25641
- package/dist/plugins/webpack.d.ts +24 -1
- package/dist/plugins/webpack.js +209 -72
- package/dist/runtime/Chain.d.ts +32 -0
- package/dist/runtime/auto-hooks.d.ts +11 -0
- package/dist/runtime/hmr.d.ts +22 -2
- package/dist/runtime/index.d.ts +3 -2
- package/dist/runtime/index.js +3648 -301
- package/dist/runtime/injector.d.ts +39 -72
- package/dist/runtime/react.d.ts +17 -12
- package/dist/runtime/svelte.d.ts +15 -0
- package/dist/runtime/types.d.ts +126 -4
- package/dist/runtime/utils.d.ts +0 -1
- package/dist/runtime/vue.d.ts +34 -14
- package/package.json +59 -66
- package/src/cli/commands/build.ts +133 -0
- package/src/cli/commands/cache.ts +371 -0
- package/src/cli/commands/init.ts +230 -0
- package/src/cli/commands/timeline.ts +435 -0
- package/src/cli/commands/watch.ts +211 -0
- package/src/cli/index.ts +226 -0
- package/src/cli/types.ts +100 -0
- package/src/cli/utils/config-loader.ts +174 -0
- package/src/cli/utils/file-utils.ts +139 -0
- package/src/cli/utils/logger.ts +74 -0
- package/src/compiler/Chain.ts +831 -0
- package/src/compiler/animations.ts +517 -0
- package/src/compiler/atomic-optimizer.ts +786 -0
- package/src/compiler/breakpoints.ts +347 -0
- package/src/compiler/btt.ts +1147 -0
- package/src/compiler/cache-manager.ts +446 -0
- package/src/compiler/commonProps.ts +18 -0
- package/src/compiler/content-addressable-cache.ts +478 -0
- package/src/compiler/helpers.ts +407 -0
- package/src/compiler/index.ts +72 -0
- package/src/compiler/prefixer.ts +724 -0
- package/src/compiler/shorthands.ts +558 -0
- package/src/compiler/suggestions.ts +436 -0
- package/src/compiler/theme-contract.ts +197 -0
- package/src/compiler/token-resolver.ts +241 -0
- package/src/compiler/tokens.ts +612 -0
- package/src/core/auto-detector.ts +187 -0
- package/src/core/common-utils.ts +423 -0
- package/src/core/compiler.ts +835 -0
- package/src/core/constants.ts +424 -0
- package/src/core/index.ts +107 -0
- package/src/core/smart-chain.ts +163 -0
- package/src/core/types.ts +257 -0
- package/src/core/utils.ts +598 -0
- package/src/index.ts +208 -0
- package/src/plugins/vite.d.ts +316 -0
- package/src/plugins/vite.ts +424 -0
- package/src/plugins/webpack.d.ts +289 -0
- package/src/plugins/webpack.ts +416 -0
- package/src/runtime/Chain.ts +242 -0
- package/src/runtime/auto-hooks.tsx +127 -0
- package/src/runtime/auto-vue.ts +72 -0
- package/src/runtime/hmr.ts +212 -0
- package/src/runtime/index.ts +82 -0
- package/src/runtime/injector.ts +273 -0
- package/src/runtime/react.tsx +269 -0
- package/src/runtime/svelte.ts +15 -0
- package/src/runtime/types.ts +256 -0
- package/src/runtime/utils.ts +128 -0
- package/src/runtime/vite-env.d.ts +120 -0
- package/src/runtime/vue.ts +231 -0
- package/tsconfig.build.json +41 -0
- package/tsconfig.json +25 -0
- package/tsconfig.runtimes.json +18 -0
- package/dist/cli/cli.cjs +0 -7
- package/dist/cli/commands/build.d.ts.map +0 -1
- package/dist/cli/commands/compile.d.ts +0 -3
- package/dist/cli/commands/compile.d.ts.map +0 -1
- package/dist/cli/commands/init.d.ts.map +0 -1
- package/dist/cli/commands/timeline.d.ts.map +0 -1
- package/dist/cli/commands/watch.d.ts.map +0 -1
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/types.d.ts.map +0 -1
- package/dist/cli/utils/config-loader.d.ts.map +0 -1
- package/dist/cli/utils/file-utils.d.ts.map +0 -1
- package/dist/cli/utils/logger.d.ts.map +0 -1
- package/dist/compiler/atomic-optimizer.d.ts.map +0 -1
- package/dist/compiler/btt.d.ts.map +0 -1
- package/dist/compiler/cache-manager.d.ts.map +0 -1
- package/dist/compiler/commonProps.d.ts.map +0 -1
- package/dist/compiler/index.d.ts.map +0 -1
- package/dist/compiler/prefixer.d.ts.map +0 -1
- package/dist/compiler/theme-contract.d.ts.map +0 -1
- package/dist/compiler/tokens.d.ts.map +0 -1
- package/dist/compiler/types.d.ts +0 -57
- package/dist/compiler/types.d.ts.map +0 -1
- package/dist/core/compiler.d.ts.map +0 -1
- package/dist/core/constants.d.ts.map +0 -1
- package/dist/core/index.d.ts +0 -4
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/utils.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/plugins/vite.d.ts.map +0 -1
- package/dist/plugins/webpack.d.ts.map +0 -1
- package/dist/runtime/hmr.d.ts.map +0 -1
- package/dist/runtime/index.d.ts.map +0 -1
- package/dist/runtime/injector.d.ts.map +0 -1
- package/dist/runtime/react.d.ts.map +0 -1
- package/dist/runtime/react.js +0 -324
- package/dist/runtime/types.d.ts.map +0 -1
- package/dist/runtime/utils.d.ts.map +0 -1
- package/dist/runtime/vue.d.ts.map +0 -1
- package/dist/runtime/vue.js +0 -286
|
@@ -29,12 +29,36 @@ export interface ChainCSSLoaderOptions {
|
|
|
29
29
|
* @default false
|
|
30
30
|
*/
|
|
31
31
|
verbose?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Enable CSS extraction to separate file
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
extractCSS?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Enable Hot Module Replacement
|
|
39
|
+
* @default true in development
|
|
40
|
+
*/
|
|
41
|
+
hmr?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Custom cache key for compilation
|
|
44
|
+
*/
|
|
45
|
+
cacheKey?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Framework to generate components for
|
|
48
|
+
* @default 'auto'
|
|
49
|
+
*/
|
|
50
|
+
framework?: 'react' | 'vue' | 'svelte' | 'solid' | 'auto';
|
|
32
51
|
}
|
|
33
52
|
interface LoaderContext {
|
|
34
53
|
async: () => (err: Error | null, code?: string) => void;
|
|
35
54
|
getOptions: () => ChainCSSLoaderOptions;
|
|
36
55
|
resourcePath: string;
|
|
37
56
|
context: string;
|
|
57
|
+
cacheable: (flag: boolean) => void;
|
|
58
|
+
addDependency: (file: string) => void;
|
|
59
|
+
emitFile: (name: string, content: string, sourceMap?: any) => void;
|
|
60
|
+
emitWarning: (warning: Error) => void;
|
|
61
|
+
emitError: (error: Error) => void;
|
|
38
62
|
}
|
|
39
63
|
/**
|
|
40
64
|
* Webpack loader for ChainCSS
|
|
@@ -42,4 +66,3 @@ interface LoaderContext {
|
|
|
42
66
|
*/
|
|
43
67
|
export default function chaincssLoader(this: LoaderContext, source: string): void;
|
|
44
68
|
export {};
|
|
45
|
-
//# sourceMappingURL=webpack.d.ts.map
|
package/dist/plugins/webpack.js
CHANGED
|
@@ -1,106 +1,243 @@
|
|
|
1
1
|
// src/plugins/webpack.ts
|
|
2
2
|
import path from "path";
|
|
3
|
-
import {
|
|
3
|
+
import { spawn } from "child_process";
|
|
4
4
|
import fs from "fs";
|
|
5
5
|
import { fileURLToPath } from "url";
|
|
6
|
+
import crypto from "crypto";
|
|
6
7
|
var __filename = fileURLToPath(import.meta.url);
|
|
7
8
|
var __dirname = path.dirname(__filename);
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
function generateHash(content) {
|
|
10
|
+
return crypto.createHash("md5").update(content).digest("hex").slice(0, 8);
|
|
11
|
+
}
|
|
12
|
+
function extractStyleExports(source) {
|
|
13
|
+
const exports = [];
|
|
14
|
+
const constRegex = /const\s+(\w+)\s*=\s*(?:chain|\$)\(\s*\)\s*(?:\.\w+\([^)]*\)\s*)*\.\$el\(['"`]([^'"`]+)['"`]\)/g;
|
|
15
|
+
let match;
|
|
16
|
+
while ((match = constRegex.exec(source)) !== null) {
|
|
17
|
+
exports.push({
|
|
18
|
+
name: match[1],
|
|
19
|
+
className: match[2]
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const exportRegex = /export\s+const\s+(\w+)\s*=\s*(?:chain|\$)\(\s*\)\s*(?:\.\w+\([^)]*\)\s*)*\.\$el\(['"`]([^'"`]+)['"`]\)/g;
|
|
23
|
+
while ((match = exportRegex.exec(source)) !== null) {
|
|
24
|
+
exports.push({
|
|
25
|
+
name: match[1],
|
|
26
|
+
className: match[2]
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return exports;
|
|
30
|
+
}
|
|
31
|
+
function generateRuntimeCode(source, styleExports, resourcePath, options) {
|
|
32
|
+
const styleNames = styleExports.map((e) => e.name).join(", ");
|
|
33
|
+
const hmrEnabled = options.hmr !== false && process.env.NODE_ENV !== "production";
|
|
34
|
+
const classMapping = styleExports.map((exp) => ` ${exp.name}: '${exp.className}'`).join(",\n");
|
|
35
|
+
return `
|
|
36
|
+
// Generated by ChainCSS Webpack Loader (Runtime Mode)
|
|
37
|
+
// Source: ${path.basename(resourcePath)}
|
|
38
|
+
|
|
39
|
+
import { chain, enableDebug } from 'chaincss/runtime';
|
|
40
|
+
|
|
41
|
+
${hmrEnabled ? `// Enable debug in development
|
|
42
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
43
|
+
enableDebug(${options.verbose || false});
|
|
44
|
+
}` : ""}
|
|
45
|
+
|
|
46
|
+
// Original source for reference
|
|
47
|
+
${source}
|
|
48
|
+
|
|
49
|
+
// Compiled style exports
|
|
50
|
+
export const styles = {
|
|
51
|
+
${classMapping}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default styles;
|
|
55
|
+
|
|
56
|
+
${hmrEnabled ? `
|
|
57
|
+
// HMR Support
|
|
58
|
+
if (module.hot) {
|
|
59
|
+
module.hot.accept();
|
|
60
|
+
module.hot.dispose(() => {
|
|
61
|
+
// Cleanup on reload
|
|
62
|
+
const styleId = 'chaincss-${generateHash(resourcePath)}';
|
|
63
|
+
const style = document.getElementById(styleId);
|
|
64
|
+
if (style) style.remove();
|
|
65
|
+
});
|
|
15
66
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
67
|
+
` : ""}
|
|
68
|
+
`;
|
|
69
|
+
}
|
|
70
|
+
function generateProductionCode(css, styleExports, resourcePath, options) {
|
|
71
|
+
const styleNames = styleExports.map((e) => e.name).join(", ");
|
|
72
|
+
const classMapping = styleExports.map((exp) => ` ${exp.name}: '${exp.className}'`).join(",\n");
|
|
73
|
+
const escapedCSS = css.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$/g, "\\$");
|
|
74
|
+
if (options.extractCSS) {
|
|
75
|
+
return `
|
|
76
|
+
// Generated by ChainCSS Webpack Loader (Build Mode - Extracted)
|
|
77
|
+
// Source: ${path.basename(resourcePath)}
|
|
78
|
+
|
|
79
|
+
export const styles = {
|
|
80
|
+
${classMapping}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export default styles;
|
|
84
|
+
`;
|
|
85
|
+
} else {
|
|
86
|
+
return `
|
|
87
|
+
// Generated by ChainCSS Webpack Loader (Build Mode - Injected)
|
|
88
|
+
// Source: ${path.basename(resourcePath)}
|
|
89
|
+
|
|
90
|
+
export const styles = {
|
|
91
|
+
${classMapping}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Inject CSS
|
|
95
|
+
const css = \`${escapedCSS}\`;
|
|
96
|
+
if (typeof document !== 'undefined' && css && css.trim()) {
|
|
97
|
+
const styleId = 'chaincss-${generateHash(resourcePath)}';
|
|
98
|
+
let style = document.getElementById(styleId);
|
|
99
|
+
if (!style) {
|
|
100
|
+
style = document.createElement('style');
|
|
101
|
+
style.id = styleId;
|
|
102
|
+
style.setAttribute('data-chaincss', 'true');
|
|
103
|
+
style.setAttribute('data-source', ${JSON.stringify(path.basename(resourcePath))});
|
|
104
|
+
document.head.appendChild(style);
|
|
105
|
+
}
|
|
106
|
+
style.textContent = css;
|
|
107
|
+
}
|
|
108
|
+
|
|
23
109
|
export default styles;
|
|
24
110
|
`;
|
|
25
|
-
callback(null, code);
|
|
26
|
-
return;
|
|
27
111
|
}
|
|
112
|
+
}
|
|
113
|
+
async function compileChainCSS(source, filePath, options, context) {
|
|
114
|
+
const tempFile = path.join(context.context, `.temp.${generateHash(source)}.chain.js`);
|
|
115
|
+
const outputDir = options.outputDir || path.join(process.cwd(), ".chaincss-cache");
|
|
116
|
+
const baseName = path.basename(filePath, path.extname(filePath));
|
|
28
117
|
try {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const tempFile = path.join(this.context, `.temp.${Date.now()}.chain.js`);
|
|
33
|
-
const outputDir = options.outputDir || path.join(process.cwd(), ".chaincss-cache");
|
|
34
|
-
if (!fs.existsSync(path.dirname(tempFile))) {
|
|
35
|
-
fs.mkdirSync(path.dirname(tempFile), { recursive: true });
|
|
118
|
+
const tempDir = path.dirname(tempFile);
|
|
119
|
+
if (!fs.existsSync(tempDir)) {
|
|
120
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
36
121
|
}
|
|
37
122
|
fs.writeFileSync(tempFile, source, "utf8");
|
|
123
|
+
context.addDependency(tempFile);
|
|
38
124
|
if (!fs.existsSync(outputDir)) {
|
|
39
125
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
40
126
|
}
|
|
41
127
|
const chaincssCli = path.join(__dirname, "../cli/index.js");
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
cmd += " --atomic";
|
|
128
|
+
if (!fs.existsSync(chaincssCli)) {
|
|
129
|
+
throw new Error(`ChainCSS CLI not found at ${chaincssCli}. Please ensure chaincss is built.`);
|
|
45
130
|
}
|
|
46
|
-
|
|
47
|
-
|
|
131
|
+
const args = [
|
|
132
|
+
chaincssCli,
|
|
133
|
+
"compile",
|
|
134
|
+
tempFile,
|
|
135
|
+
outputDir,
|
|
136
|
+
"--framework",
|
|
137
|
+
options.framework || "auto"
|
|
138
|
+
];
|
|
139
|
+
if (options.atomic) args.push("--atomic");
|
|
140
|
+
if (options.minify) args.push("--minify");
|
|
141
|
+
if (options.sourceMap) args.push("--source-map");
|
|
142
|
+
if (options.verbose) args.push("--verbose");
|
|
143
|
+
if (options.verbose) {
|
|
144
|
+
console.log(`[chaincss-loader] Executing: node ${args.join(" ")}`);
|
|
48
145
|
}
|
|
49
|
-
|
|
50
|
-
|
|
146
|
+
const result = await new Promise((resolve, reject) => {
|
|
147
|
+
const proc = spawn("node", args, {
|
|
148
|
+
cwd: process.cwd(),
|
|
149
|
+
timeout: 3e4
|
|
150
|
+
});
|
|
151
|
+
let stdout = "";
|
|
152
|
+
let stderr = "";
|
|
153
|
+
proc.stdout.on("data", (data) => {
|
|
154
|
+
stdout += data.toString();
|
|
155
|
+
});
|
|
156
|
+
proc.stderr.on("data", (data) => {
|
|
157
|
+
stderr += data.toString();
|
|
158
|
+
});
|
|
159
|
+
proc.on("close", (code) => {
|
|
160
|
+
if (code === 0) {
|
|
161
|
+
resolve({ stdout, stderr });
|
|
162
|
+
} else {
|
|
163
|
+
reject(new Error(`Compilation failed with code ${code}: ${stderr}`));
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
proc.on("error", reject);
|
|
167
|
+
});
|
|
168
|
+
if (options.verbose && result.stdout) {
|
|
169
|
+
console.log(result.stdout);
|
|
51
170
|
}
|
|
52
|
-
if (
|
|
53
|
-
|
|
171
|
+
if (result.stderr) {
|
|
172
|
+
context.emitWarning(new Error(result.stderr));
|
|
54
173
|
}
|
|
55
|
-
execSync(cmd, { stdio: options.verbose ? "inherit" : "pipe" });
|
|
56
|
-
const baseName = path.basename(this.resourcePath, path.extname(this.resourcePath));
|
|
57
174
|
const cssPath = path.join(outputDir, `${baseName}.css`);
|
|
58
|
-
const jsPath = path.join(outputDir, `${baseName}.js`);
|
|
59
175
|
let css = "";
|
|
60
176
|
if (fs.existsSync(cssPath)) {
|
|
61
177
|
css = fs.readFileSync(cssPath, "utf8");
|
|
178
|
+
if (options.verbose) {
|
|
179
|
+
console.log(`[chaincss-loader] Read CSS: ${css.length} bytes from ${cssPath}`);
|
|
180
|
+
}
|
|
62
181
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
182
|
+
const classMapPath = path.join(outputDir, `${baseName}.class.js`);
|
|
183
|
+
let classMap = {};
|
|
184
|
+
if (fs.existsSync(classMapPath)) {
|
|
185
|
+
const classMapContent = fs.readFileSync(classMapPath, "utf8");
|
|
186
|
+
const exportMatch = classMapContent.match(/export const (\w+) = '([^']+)'/g);
|
|
187
|
+
if (exportMatch) {
|
|
188
|
+
exportMatch.forEach((line) => {
|
|
189
|
+
const match = line.match(/export const (\w+) = '([^']+)'/);
|
|
190
|
+
if (match) {
|
|
191
|
+
classMap[match[1]] = match[2];
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
66
195
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
${classExports}
|
|
73
|
-
|
|
74
|
-
const css = ${JSON.stringify(css)};
|
|
75
|
-
if (typeof document !== 'undefined') {
|
|
76
|
-
const styleId = 'chaincss-${baseName}';
|
|
77
|
-
let style = document.getElementById(styleId);
|
|
78
|
-
if (!style) {
|
|
79
|
-
style = document.createElement('style');
|
|
80
|
-
style.id = styleId;
|
|
81
|
-
style.setAttribute('data-chaincss', ${JSON.stringify(this.resourcePath)});
|
|
82
|
-
document.head.appendChild(style);
|
|
83
|
-
}
|
|
84
|
-
style.textContent = css;
|
|
196
|
+
return { css, classMap };
|
|
197
|
+
} finally {
|
|
198
|
+
try {
|
|
199
|
+
if (fs.existsSync(tempFile)) {
|
|
200
|
+
fs.unlinkSync(tempFile);
|
|
85
201
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
202
|
+
} catch (e) {
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function chaincssLoader(source) {
|
|
207
|
+
const callback = this.async();
|
|
208
|
+
const options = this.getOptions() || {};
|
|
209
|
+
this.cacheable(true);
|
|
210
|
+
const mode = options.mode || (process.env.NODE_ENV === "production" ? "build" : "runtime");
|
|
211
|
+
const styleExports = extractStyleExports(source);
|
|
212
|
+
if (options.verbose) {
|
|
213
|
+
console.log(`[chaincss-loader] Processing ${path.basename(this.resourcePath)} in ${mode} mode`);
|
|
214
|
+
console.log(`[chaincss-loader] Found exports: ${styleExports.map((e) => e.name).join(", ")}`);
|
|
215
|
+
}
|
|
216
|
+
if (mode === "runtime") {
|
|
217
|
+
const code = generateRuntimeCode(source, styleExports, this.resourcePath, options);
|
|
218
|
+
callback(null, code);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
compileChainCSS(source, this.resourcePath, options, this).then(({ css, classMap }) => {
|
|
222
|
+
if (options.extractCSS && css) {
|
|
223
|
+
const cssFileName = `${path.basename(this.resourcePath, path.extname(this.resourcePath))}.css`;
|
|
224
|
+
this.emitFile(cssFileName, css);
|
|
225
|
+
if (options.verbose) {
|
|
226
|
+
console.log(`[chaincss-loader] Emitted CSS: ${cssFileName} (${css.length} bytes)`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const code = generateProductionCode(css, styleExports, this.resourcePath, options);
|
|
230
|
+
if (options.verbose) {
|
|
231
|
+
console.log(`[chaincss-loader] \u2713 Compiled ${path.basename(this.resourcePath)}`);
|
|
232
|
+
console.log(`[chaincss-loader] CSS size: ${css.length} bytes`);
|
|
233
|
+
console.log(`[chaincss-loader] Exports: ${styleExports.length}`);
|
|
234
|
+
}
|
|
89
235
|
callback(null, code);
|
|
90
|
-
}
|
|
236
|
+
}).catch((err) => {
|
|
91
237
|
console.error(`[chaincss-loader] Error compiling ${this.resourcePath}:`, err.message);
|
|
238
|
+
this.emitError(err);
|
|
92
239
|
callback(err);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
function extractStyleNames(source) {
|
|
96
|
-
const matches = source.match(/const\s+(\w+)\s*=\s*\$\(/g);
|
|
97
|
-
if (!matches)
|
|
98
|
-
return "";
|
|
99
|
-
const names = matches.map((m) => {
|
|
100
|
-
const match = m.match(/const\s+(\w+)/);
|
|
101
|
-
return match ? match[1] : "";
|
|
102
|
-
}).filter(Boolean);
|
|
103
|
-
return names.join(", ");
|
|
240
|
+
});
|
|
104
241
|
}
|
|
105
242
|
export {
|
|
106
243
|
chaincssLoader as default
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare function enableDebug(enabled?: boolean): void;
|
|
2
|
+
export declare const setManifest: (manifest: any) => void;
|
|
3
|
+
export declare const setTokens: (tokens: any) => void;
|
|
4
|
+
export declare class RuntimeChain {
|
|
5
|
+
private useTokens;
|
|
6
|
+
private catcher;
|
|
7
|
+
private componentName;
|
|
8
|
+
proxy: any;
|
|
9
|
+
constructor(useTokens?: boolean);
|
|
10
|
+
use(plugin: any): any;
|
|
11
|
+
hover(): any;
|
|
12
|
+
/**
|
|
13
|
+
* Set the component name for class generation
|
|
14
|
+
*/
|
|
15
|
+
$name(name: string): this;
|
|
16
|
+
/**
|
|
17
|
+
* Finalizes the chain. Returns the style object and resets the catcher.
|
|
18
|
+
*/
|
|
19
|
+
$el(name?: string): Record<string, any>;
|
|
20
|
+
end(name?: string): Record<string, any>;
|
|
21
|
+
/**
|
|
22
|
+
* Get the current catcher (for debugging)
|
|
23
|
+
*/
|
|
24
|
+
getCatcher(): Record<string, any>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* --- EXPORTS ---
|
|
28
|
+
*/
|
|
29
|
+
export declare const $: () => any;
|
|
30
|
+
export declare const $t: () => any;
|
|
31
|
+
export declare const chain: (useTokens?: boolean) => any;
|
|
32
|
+
export default chain;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface UseSmartStylesOptions {
|
|
3
|
+
debug?: boolean;
|
|
4
|
+
ssr?: boolean;
|
|
5
|
+
moduleId?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function useSmartStyles<T extends Record<string, any>>(styleBuilder: (chain: any) => any, deps?: any[], options?: UseSmartStylesOptions): Record<string, string>;
|
|
8
|
+
export declare function createSmartComponent<P extends Record<string, any>>(Component: React.ComponentType<P>, baseStyles?: (chain: any) => any): React.FC<P & {
|
|
9
|
+
className?: string;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function withSmartStyles<P extends Record<string, any>>(WrappedComponent: React.ComponentType<P>, styles: (chain: any) => any): React.FC<P>;
|
package/dist/runtime/hmr.d.ts
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
1
|
export declare function setupHMR(): void;
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Register a module for HMR updates
|
|
4
|
+
* @param moduleId - Unique identifier for the module
|
|
5
|
+
* @param styles - Current styles object (optional)
|
|
6
|
+
* @param callback - Callback when module updates (optional)
|
|
7
|
+
*/
|
|
8
|
+
export declare function registerForHMR(moduleId: string, styles?: Record<string, any>, callback?: (newStyles: Record<string, any>) => void): void;
|
|
9
|
+
/**
|
|
10
|
+
* Get HMR status
|
|
11
|
+
*/
|
|
12
|
+
export declare function isHMRSupported(): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Get current HMR environment
|
|
15
|
+
*/
|
|
16
|
+
export declare function getHMRType(): string;
|
|
17
|
+
declare const _default: {
|
|
18
|
+
setupHMR: typeof setupHMR;
|
|
19
|
+
registerForHMR: typeof registerForHMR;
|
|
20
|
+
isHMRSupported: typeof isHMRSupported;
|
|
21
|
+
getHMRType: typeof getHMRType;
|
|
22
|
+
};
|
|
23
|
+
export default _default;
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
* WARNING: Importing from this module adds ~3.2KB to your bundle.
|
|
5
5
|
* For production, use build-time compilation with chaincss/plugin/vite instead.
|
|
6
6
|
*/
|
|
7
|
-
export {
|
|
7
|
+
export { compileRuntime as compile, runRuntime as run, styleInjector } from './injector.js';
|
|
8
|
+
export { $, $t, chain, setManifest } from './Chain.js';
|
|
8
9
|
export { useChainStyles, useDynamicChainStyles, useThemeChainStyles, ChainCSSGlobal, cx, withChainStyles, enableChainCSSDebug, disableChainCSSDebug, isDebugEnabled, createStyledComponent, useComputedStyles } from './react.js';
|
|
9
10
|
export { useAtomicClasses, ChainCSSGlobal as ChainCSSGlobalVue, createStyledComponent as createStyledVueComponent, // This is fine - it renames
|
|
10
11
|
createStyledComponents as createStyledVueComponents, useComputedStyles as useComputedStylesVue, // This renames useComputedStyles
|
|
11
12
|
provideStyleContext, injectStyleContext } from './vue.js';
|
|
13
|
+
export { useAtomicClasses as useAtomicClassesSvelte, cx as cxSvelte, ChainCSSGlobal as ChainCSSGlobalSvelte, createStyledComponent as createStyledSvelteComponent, createStyledComponents as createStyledSvelteComponents, useComputedStyles as useComputedStylesSvelte, provideStyleContext as provideStyleContextSvelte, injectStyleContext as injectStyleContextSvelte, chainStyles } from './svelte.js';
|
|
12
14
|
export { setupHMR, registerForHMR } from './hmr.js';
|
|
13
15
|
export { generateStyleId, hashString, kebabCase, isBrowser, isDevelopment, isProduction, debounce, memoize, cn as cnUtils, devWarn, devLog, logError, createDebugger } from './utils.js';
|
|
14
16
|
export type { RuntimeStyleDefinition, UseChainStylesOptions, RuntimeCompiledResult, StyleInjector, UseAtomicClassesReturn, HMRPayload, ChainCSSDebugger } from './types.js';
|
|
15
|
-
//# sourceMappingURL=index.d.ts.map
|