tailwind-styled-v4 4.0.0 → 5.0.1
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 +398 -0
- package/LICENSE +21 -0
- package/README.md +532 -0
- package/dist/analyzer.d.mts +114 -0
- package/dist/analyzer.d.ts +114 -0
- package/dist/analyzer.js +1555 -0
- package/dist/analyzer.js.map +1 -0
- package/dist/analyzer.mjs +1544 -0
- package/dist/analyzer.mjs.map +1 -0
- package/dist/animate.d.mts +46 -0
- package/dist/animate.d.ts +41 -112
- package/dist/animate.js +792 -235
- package/dist/animate.js.map +1 -1
- package/dist/animate.mjs +782 -0
- package/dist/animate.mjs.map +1 -0
- package/dist/atomic.d.mts +18 -0
- package/dist/atomic.d.ts +18 -0
- package/dist/atomic.js +191 -0
- package/dist/atomic.js.map +1 -0
- package/dist/atomic.mjs +185 -0
- package/dist/atomic.mjs.map +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +6063 -0
- package/dist/cli.js.map +1 -0
- package/dist/cli.mjs +6053 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/{compiler.d.cts → compiler.d.mts} +503 -210
- package/dist/compiler.d.ts +503 -210
- package/dist/compiler.js +1549 -566
- package/dist/compiler.js.map +1 -1
- package/dist/{compiler.cjs → compiler.mjs} +1476 -627
- package/dist/compiler.mjs.map +1 -0
- package/dist/dashboard.d.mts +272 -0
- package/dist/dashboard.d.ts +272 -0
- package/dist/dashboard.js +249 -0
- package/dist/dashboard.js.map +1 -0
- package/dist/dashboard.mjs +239 -0
- package/dist/dashboard.mjs.map +1 -0
- package/dist/devtools.js +336 -211
- package/dist/devtools.js.map +1 -1
- package/dist/{devtools.cjs → devtools.mjs} +331 -220
- package/dist/devtools.mjs.map +1 -0
- package/dist/engine.d.mts +84 -0
- package/dist/engine.d.ts +84 -0
- package/dist/engine.js +3014 -0
- package/dist/engine.js.map +1 -0
- package/dist/engine.mjs +3005 -0
- package/dist/engine.mjs.map +1 -0
- package/dist/{index.d.cts → index.d.mts} +75 -4
- package/dist/index.d.ts +75 -4
- package/dist/index.js +1341 -149
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2162 -0
- package/dist/index.mjs.map +1 -0
- package/dist/liveTokenEngine-DYN3Zale.d.mts +34 -0
- package/dist/liveTokenEngine-DYN3Zale.d.ts +34 -0
- package/dist/next.d.mts +55 -0
- package/dist/next.d.ts +30 -20
- package/dist/next.js +6947 -149
- package/dist/next.js.map +1 -1
- package/dist/next.mjs +7050 -0
- package/dist/next.mjs.map +1 -0
- package/dist/plugin.d.mts +90 -0
- package/dist/plugin.d.ts +90 -0
- package/dist/plugin.js +185 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plugin.mjs +174 -0
- package/dist/plugin.mjs.map +1 -0
- package/dist/pluginRegistry.d.mts +83 -0
- package/dist/pluginRegistry.d.ts +83 -0
- package/dist/pluginRegistry.js +303 -0
- package/dist/pluginRegistry.js.map +1 -0
- package/dist/pluginRegistry.mjs +298 -0
- package/dist/pluginRegistry.mjs.map +1 -0
- package/dist/{preset.d.cts → preset.d.mts} +29 -2
- package/dist/preset.d.ts +29 -2
- package/dist/preset.js +318 -21
- package/dist/preset.js.map +1 -1
- package/dist/preset.mjs +414 -0
- package/dist/preset.mjs.map +1 -0
- package/dist/rspack.d.mts +33 -0
- package/dist/rspack.d.ts +33 -0
- package/dist/rspack.js +55 -0
- package/dist/rspack.js.map +1 -0
- package/dist/rspack.mjs +45 -0
- package/dist/rspack.mjs.map +1 -0
- package/dist/runtime.d.mts +62 -0
- package/dist/runtime.d.ts +62 -0
- package/dist/runtime.js +207 -0
- package/dist/runtime.js.map +1 -0
- package/dist/runtime.mjs +188 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/runtimeCss.d.mts +65 -0
- package/dist/runtimeCss.d.ts +65 -0
- package/dist/runtimeCss.js +188 -0
- package/dist/runtimeCss.js.map +1 -0
- package/dist/runtimeCss.mjs +173 -0
- package/dist/runtimeCss.mjs.map +1 -0
- package/dist/scanner.d.mts +25 -0
- package/dist/scanner.d.ts +25 -0
- package/dist/scanner.js +717 -0
- package/dist/scanner.js.map +1 -0
- package/dist/scanner.mjs +703 -0
- package/dist/scanner.mjs.map +1 -0
- package/dist/shared.d.mts +85 -0
- package/dist/shared.d.ts +85 -0
- package/dist/shared.js +255 -0
- package/dist/shared.js.map +1 -0
- package/dist/shared.mjs +233 -0
- package/dist/shared.mjs.map +1 -0
- package/dist/storybookAddon.d.mts +108 -0
- package/dist/storybookAddon.d.ts +108 -0
- package/dist/storybookAddon.js +95 -0
- package/dist/storybookAddon.js.map +1 -0
- package/dist/storybookAddon.mjs +88 -0
- package/dist/storybookAddon.mjs.map +1 -0
- package/dist/svelte.d.mts +114 -0
- package/dist/svelte.d.ts +114 -0
- package/dist/svelte.js +67 -0
- package/dist/svelte.js.map +1 -0
- package/dist/svelte.mjs +59 -0
- package/dist/svelte.mjs.map +1 -0
- package/dist/testing.d.mts +185 -0
- package/dist/testing.d.ts +185 -0
- package/dist/testing.js +173 -0
- package/dist/testing.js.map +1 -0
- package/dist/testing.mjs +158 -0
- package/dist/testing.mjs.map +1 -0
- package/dist/{theme.d.cts → theme.d.mts} +18 -11
- package/dist/theme.d.ts +18 -11
- package/dist/theme.js +205 -19
- package/dist/theme.js.map +1 -1
- package/dist/theme.mjs +311 -0
- package/dist/theme.mjs.map +1 -0
- package/dist/types-DXr2PmGP.d.mts +31 -0
- package/dist/types-DXr2PmGP.d.ts +31 -0
- package/dist/vite.d.mts +51 -0
- package/dist/vite.d.ts +35 -6
- package/dist/vite.js +4254 -57
- package/dist/vite.js.map +1 -1
- package/dist/vite.mjs +4281 -0
- package/dist/vite.mjs.map +1 -0
- package/dist/vue.d.mts +89 -0
- package/dist/vue.d.ts +89 -0
- package/dist/vue.js +104 -0
- package/dist/vue.js.map +1 -0
- package/dist/vue.mjs +96 -0
- package/dist/vue.mjs.map +1 -0
- package/package.json +173 -67
- package/dist/animate.cjs +0 -252
- package/dist/animate.cjs.map +0 -1
- package/dist/animate.d.cts +0 -117
- package/dist/astTransform-ua-eapqs.d.cts +0 -41
- package/dist/astTransform-ua-eapqs.d.ts +0 -41
- package/dist/compiler.cjs.map +0 -1
- package/dist/css.cjs +0 -71
- package/dist/css.cjs.map +0 -1
- package/dist/css.d.cts +0 -45
- package/dist/css.d.ts +0 -45
- package/dist/css.js +0 -62
- package/dist/css.js.map +0 -1
- package/dist/devtools.cjs.map +0 -1
- package/dist/index.cjs +0 -1058
- package/dist/index.cjs.map +0 -1
- package/dist/next.cjs +0 -268
- package/dist/next.cjs.map +0 -1
- package/dist/next.d.cts +0 -45
- package/dist/plugins.cjs +0 -396
- package/dist/plugins.cjs.map +0 -1
- package/dist/plugins.d.cts +0 -231
- package/dist/plugins.d.ts +0 -231
- package/dist/plugins.js +0 -381
- package/dist/plugins.js.map +0 -1
- package/dist/preset.cjs +0 -129
- package/dist/preset.cjs.map +0 -1
- package/dist/theme.cjs +0 -154
- package/dist/theme.cjs.map +0 -1
- package/dist/turbopackLoader.cjs +0 -2689
- package/dist/turbopackLoader.cjs.map +0 -1
- package/dist/turbopackLoader.d.cts +0 -22
- package/dist/turbopackLoader.d.ts +0 -22
- package/dist/turbopackLoader.js +0 -2681
- package/dist/turbopackLoader.js.map +0 -1
- package/dist/vite.cjs +0 -105
- package/dist/vite.cjs.map +0 -1
- package/dist/vite.d.cts +0 -22
- package/dist/webpackLoader.cjs +0 -2670
- package/dist/webpackLoader.cjs.map +0 -1
- package/dist/webpackLoader.d.cts +0 -24
- package/dist/webpackLoader.d.ts +0 -24
- package/dist/webpackLoader.js +0 -2662
- package/dist/webpackLoader.js.map +0 -1
- /package/dist/{devtools.d.cts → devtools.d.mts} +0 -0
package/dist/engine.mjs
ADDED
|
@@ -0,0 +1,3005 @@
|
|
|
1
|
+
import { twMerge } from 'tailwind-merge';
|
|
2
|
+
import fs3 from 'fs';
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
import path8 from 'path';
|
|
6
|
+
import { pathToFileURL, fileURLToPath } from 'url';
|
|
7
|
+
import { Worker } from 'worker_threads';
|
|
8
|
+
|
|
9
|
+
/* tailwind-styled-v4 v5.0.1 | MIT | https://github.com/dictionar32/tailwind-styled-v4 */
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
15
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
16
|
+
}) : x)(function(x) {
|
|
17
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
18
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
19
|
+
});
|
|
20
|
+
var __esm = (fn, res) => function __init() {
|
|
21
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
22
|
+
};
|
|
23
|
+
var __export = (target, all) => {
|
|
24
|
+
for (var name in all)
|
|
25
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
|
+
};
|
|
27
|
+
var __copyProps = (to, from, except, desc) => {
|
|
28
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
+
for (let key of __getOwnPropNames(from))
|
|
30
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
function mergeClassesStatic(classes) {
|
|
37
|
+
return twMerge(classes);
|
|
38
|
+
}
|
|
39
|
+
var init_classMerger = __esm({
|
|
40
|
+
"packages/compiler/src/classMerger.ts"() {
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
function getPlatformExtension() {
|
|
44
|
+
const platform = os.platform();
|
|
45
|
+
switch (platform) {
|
|
46
|
+
case "win32":
|
|
47
|
+
return ".node";
|
|
48
|
+
case "darwin":
|
|
49
|
+
return ".dylib";
|
|
50
|
+
case "linux":
|
|
51
|
+
return ".so";
|
|
52
|
+
default:
|
|
53
|
+
return ".node";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function formatErrorMessage(error) {
|
|
57
|
+
return error instanceof Error ? error.message : String(error);
|
|
58
|
+
}
|
|
59
|
+
function resolveRuntimeDir(dirnameValue, moduleImportUrl) {
|
|
60
|
+
if (typeof dirnameValue === "string" && dirnameValue.length > 0) return dirnameValue;
|
|
61
|
+
return path8.dirname(fileURLToPath(moduleImportUrl));
|
|
62
|
+
}
|
|
63
|
+
function resolveNativeBindingCandidates(options) {
|
|
64
|
+
const out = [];
|
|
65
|
+
const envVarNames = options.envVarNames ?? ["TWS_NATIVE_PATH"];
|
|
66
|
+
for (const envVarName of envVarNames) {
|
|
67
|
+
const raw = process.env[envVarName]?.trim();
|
|
68
|
+
if (!raw) continue;
|
|
69
|
+
const resolved = path8.resolve(raw);
|
|
70
|
+
if (options.enforceNodeExtensionForEnvPath) {
|
|
71
|
+
if (path8.extname(resolved).toLowerCase() !== ".node") {
|
|
72
|
+
throw new Error(
|
|
73
|
+
`Invalid native binding path from ${envVarName}="${raw}". Expected a .node file.`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
out.push(resolved);
|
|
78
|
+
}
|
|
79
|
+
if (options.includeDefaultCandidates !== false) {
|
|
80
|
+
const ext = options.platformExtension ?? getPlatformExtension();
|
|
81
|
+
const defaultBindingName = `tailwind_styled_parser${ext}`;
|
|
82
|
+
out.push(path8.resolve(process.cwd(), "native", defaultBindingName));
|
|
83
|
+
out.push(path8.resolve(options.runtimeDir, "..", "..", "..", "native", defaultBindingName));
|
|
84
|
+
}
|
|
85
|
+
return Array.from(new Set(out));
|
|
86
|
+
}
|
|
87
|
+
function parseDebugToken(namespace, token) {
|
|
88
|
+
if (token === "*" || token === namespace || token === "tailwind-styled:*") return true;
|
|
89
|
+
return token.endsWith("*") && namespace.startsWith(token.slice(0, -1));
|
|
90
|
+
}
|
|
91
|
+
function isDebugNamespaceEnabled(namespace) {
|
|
92
|
+
if (process.env.TWS_DEBUG === "1" || process.env.TAILWIND_STYLED_DEBUG === "1") return true;
|
|
93
|
+
const raw = process.env.DEBUG;
|
|
94
|
+
if (!raw) return false;
|
|
95
|
+
return raw.split(",").map((token) => token.trim()).some((token) => parseDebugToken(namespace, token));
|
|
96
|
+
}
|
|
97
|
+
function createDebugLogger(namespace, label = namespace) {
|
|
98
|
+
const debugEnabled = isDebugNamespaceEnabled(namespace);
|
|
99
|
+
return (message) => {
|
|
100
|
+
if (!debugEnabled) return;
|
|
101
|
+
console.debug(`[${label}] ${message}`);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function loadNativeBinding(options) {
|
|
105
|
+
const req = createRequire(path8.join(options.runtimeDir, "noop.cjs"));
|
|
106
|
+
const loadErrors = [];
|
|
107
|
+
for (const candidate of options.candidates) {
|
|
108
|
+
if (!fs3.existsSync(candidate)) continue;
|
|
109
|
+
try {
|
|
110
|
+
const mod = req(candidate);
|
|
111
|
+
if (options.isValid(mod)) {
|
|
112
|
+
return {
|
|
113
|
+
binding: mod,
|
|
114
|
+
loadedPath: candidate,
|
|
115
|
+
loadErrors
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
loadErrors.push({
|
|
119
|
+
path: candidate,
|
|
120
|
+
message: options.invalidExportMessage
|
|
121
|
+
});
|
|
122
|
+
} catch (error) {
|
|
123
|
+
loadErrors.push({
|
|
124
|
+
path: candidate,
|
|
125
|
+
message: formatErrorMessage(error)
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
binding: null,
|
|
131
|
+
loadedPath: null,
|
|
132
|
+
loadErrors
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
var init_nativeBinding = __esm({
|
|
136
|
+
"packages/shared/src/nativeBinding.ts"() {
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// packages/shared/src/logger.ts
|
|
141
|
+
function getEnvLevel() {
|
|
142
|
+
const env = process.env.TWS_LOG_LEVEL?.toLowerCase();
|
|
143
|
+
if (env && env in LEVELS) return env;
|
|
144
|
+
return process.env.TWS_DEBUG_SCANNER === "1" ? "debug" : "info";
|
|
145
|
+
}
|
|
146
|
+
function createLogger(prefix, level) {
|
|
147
|
+
let currentLevel = getEnvLevel();
|
|
148
|
+
const log5 = (msgLevel, stream, args) => {
|
|
149
|
+
if (LEVELS[msgLevel] > LEVELS[currentLevel]) return;
|
|
150
|
+
const line = `[${prefix}] ${args.map(String).join(" ")}
|
|
151
|
+
`;
|
|
152
|
+
process[stream].write(line);
|
|
153
|
+
};
|
|
154
|
+
return {
|
|
155
|
+
error: (...a) => log5("error", "stderr", a),
|
|
156
|
+
warn: (...a) => log5("warn", "stderr", a),
|
|
157
|
+
info: (...a) => log5("info", "stdout", a),
|
|
158
|
+
debug: (...a) => log5("debug", "stderr", a),
|
|
159
|
+
setLevel: (l) => {
|
|
160
|
+
currentLevel = l;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
var LEVELS;
|
|
165
|
+
var init_logger = __esm({
|
|
166
|
+
"packages/shared/src/logger.ts"() {
|
|
167
|
+
LEVELS = { silent: 0, error: 1, warn: 2, info: 3, debug: 4 };
|
|
168
|
+
createLogger("tailwind-styled");
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// packages/shared/src/index.ts
|
|
173
|
+
var init_src = __esm({
|
|
174
|
+
"packages/shared/src/index.ts"() {
|
|
175
|
+
init_nativeBinding();
|
|
176
|
+
init_logger();
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// packages/compiler/src/nativeBridge.ts
|
|
181
|
+
var nativeBridge_exports = {};
|
|
182
|
+
__export(nativeBridge_exports, {
|
|
183
|
+
adaptNativeResult: () => adaptNativeResult,
|
|
184
|
+
getNativeBridge: () => getNativeBridge,
|
|
185
|
+
resetNativeBridgeCache: () => resetNativeBridgeCache
|
|
186
|
+
});
|
|
187
|
+
function tryRequire(id) {
|
|
188
|
+
try {
|
|
189
|
+
const mod = requireFromRuntime(id);
|
|
190
|
+
return mod ?? null;
|
|
191
|
+
} catch (error) {
|
|
192
|
+
log.debug(
|
|
193
|
+
`native bridge load miss ${id}: ${error instanceof Error ? error.message : String(error)}`
|
|
194
|
+
);
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function getNativeBridge() {
|
|
199
|
+
if (cachedBridge !== void 0) {
|
|
200
|
+
if (cachedBridge === null) {
|
|
201
|
+
throw new Error(
|
|
202
|
+
`[tailwind-styled/compiler v5] Native binding is required but not available.
|
|
203
|
+
Please ensure:
|
|
204
|
+
1. The native module is properly installed
|
|
205
|
+
2. You have run: npm run build:native (or use prebuilt binary)
|
|
206
|
+
3. TWS_NO_NATIVE environment variable is not set
|
|
207
|
+
|
|
208
|
+
For help, see: https://tailwind-styled.dev/docs/install`
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
return cachedBridge;
|
|
212
|
+
}
|
|
213
|
+
if (process.env.TWS_NO_NATIVE === "1" || process.env.TWS_NO_RUST === "1") {
|
|
214
|
+
cachedBridge = null;
|
|
215
|
+
throw new Error(
|
|
216
|
+
`[tailwind-styled/compiler v5] Native binding is required.
|
|
217
|
+
The TWS_NO_NATIVE or TWS_NO_RUST environment variable is set, which disables native binding.
|
|
218
|
+
Please unset this environment variable to use the native compiler.`
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
const candidates = [
|
|
222
|
+
"@tailwind-styled/native",
|
|
223
|
+
path8.resolve(process.cwd(), "native", "index.mjs"),
|
|
224
|
+
path8.resolve(runtimeDir, "..", "..", "native", "index.mjs"),
|
|
225
|
+
path8.resolve(runtimeDir, "..", "..", "..", "native", "index.mjs"),
|
|
226
|
+
path8.resolve(process.cwd(), "native", "index.node"),
|
|
227
|
+
path8.resolve(runtimeDir, "..", "..", "native", "index.node"),
|
|
228
|
+
path8.resolve(runtimeDir, "..", "..", "..", "native", "index.node")
|
|
229
|
+
];
|
|
230
|
+
for (const candidate of candidates) {
|
|
231
|
+
const bridge = tryRequire(candidate);
|
|
232
|
+
if (bridge) {
|
|
233
|
+
log.debug(`native bridge loaded from ${candidate}`);
|
|
234
|
+
cachedBridge = bridge;
|
|
235
|
+
return cachedBridge;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
cachedBridge = null;
|
|
239
|
+
throw new Error(
|
|
240
|
+
`[tailwind-styled/compiler v5] Native binding not found.
|
|
241
|
+
Tried loading from:
|
|
242
|
+
` + candidates.map((c) => ` - ${c}`).join("\n") + `
|
|
243
|
+
|
|
244
|
+
Please build the native module:
|
|
245
|
+
npm run build:native
|
|
246
|
+
|
|
247
|
+
Or install a prebuilt binary for your platform.`
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
function resetNativeBridgeCache() {
|
|
251
|
+
cachedBridge = void 0;
|
|
252
|
+
}
|
|
253
|
+
function adaptNativeResult(raw) {
|
|
254
|
+
let rsc;
|
|
255
|
+
if (raw.rscJson) {
|
|
256
|
+
try {
|
|
257
|
+
const parsed = JSON.parse(raw.rscJson);
|
|
258
|
+
rsc = {
|
|
259
|
+
isServer: parsed.isServer,
|
|
260
|
+
needsClientDirective: parsed.needsClientDirective,
|
|
261
|
+
clientReasons: []
|
|
262
|
+
};
|
|
263
|
+
} catch {
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
let metadata;
|
|
267
|
+
if (raw.metadataJson) {
|
|
268
|
+
try {
|
|
269
|
+
metadata = JSON.parse(raw.metadataJson);
|
|
270
|
+
} catch {
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
code: raw.code,
|
|
275
|
+
classes: raw.classes,
|
|
276
|
+
changed: raw.changed,
|
|
277
|
+
rsc,
|
|
278
|
+
metadata
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
var runtimeDir, requireFromRuntime, cachedBridge, log;
|
|
282
|
+
var init_nativeBridge = __esm({
|
|
283
|
+
"packages/compiler/src/nativeBridge.ts"() {
|
|
284
|
+
init_src();
|
|
285
|
+
runtimeDir = typeof __dirname === "string" && __dirname.length > 0 ? __dirname : process.cwd();
|
|
286
|
+
requireFromRuntime = typeof module !== "undefined" && typeof module.require === "function" ? module.require.bind(module) : createRequire(path8.join(runtimeDir, "noop.cjs"));
|
|
287
|
+
log = createLogger("compiler:native");
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
// packages/compiler/src/twDetector.ts
|
|
292
|
+
var TEMPLATE_RE, OBJECT_RE, EXTEND_RE;
|
|
293
|
+
var init_twDetector = __esm({
|
|
294
|
+
"packages/compiler/src/twDetector.ts"() {
|
|
295
|
+
TEMPLATE_RE = /\btw\.(server\.)?(\w+)`((?:[^`\\]|\\.)*)`/g;
|
|
296
|
+
OBJECT_RE = /\btw\.(server\.)?(\w+)\(\s*(\{[\s\S]*?\})\s*\)/g;
|
|
297
|
+
EXTEND_RE = /(\w+)\.extend`((?:[^`\\]|\\.)*)`/g;
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
// packages/compiler/src/cssCompiler.ts
|
|
302
|
+
var cssCompiler_exports = {};
|
|
303
|
+
__export(cssCompiler_exports, {
|
|
304
|
+
buildStyleTag: () => buildStyleTag,
|
|
305
|
+
compileCssFromClasses: () => compileCssFromClasses
|
|
306
|
+
});
|
|
307
|
+
function getBinding() {
|
|
308
|
+
if (_binding !== void 0) {
|
|
309
|
+
if (_binding === null) {
|
|
310
|
+
throw new Error(
|
|
311
|
+
`[tailwind-styled/compiler v5] Native CSS binding is required but not available.
|
|
312
|
+
Please ensure the native module is properly built.`
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
return _binding;
|
|
316
|
+
}
|
|
317
|
+
if (process.env.TWS_NO_NATIVE === "1") {
|
|
318
|
+
_binding = null;
|
|
319
|
+
throw new Error(
|
|
320
|
+
`[tailwind-styled/compiler v5] Native binding is required.
|
|
321
|
+
The TWS_NO_NATIVE environment variable is set, which disables native binding.`
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
const req = typeof __require === "function" ? __require : createRequire(import.meta.url);
|
|
325
|
+
const candidates = [
|
|
326
|
+
path8.resolve(process.cwd(), "native", "tailwind_styled_parser.node"),
|
|
327
|
+
path8.resolve(__dirname, "..", "..", "..", "..", "native", "tailwind_styled_parser.node")
|
|
328
|
+
];
|
|
329
|
+
for (const c of candidates) {
|
|
330
|
+
try {
|
|
331
|
+
const mod = req(c);
|
|
332
|
+
if (mod?.compileCss) {
|
|
333
|
+
_binding = mod;
|
|
334
|
+
return _binding;
|
|
335
|
+
}
|
|
336
|
+
} catch {
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
_binding = null;
|
|
340
|
+
throw new Error(
|
|
341
|
+
`[tailwind-styled/compiler v5] Native CSS binding not found.
|
|
342
|
+
Tried loading from:
|
|
343
|
+
` + candidates.map((c) => ` - ${c}`).join("\n") + `
|
|
344
|
+
|
|
345
|
+
Please build the native module.`
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
function compileCssFromClasses(classes, options = {}) {
|
|
349
|
+
const binding = getBinding();
|
|
350
|
+
const prefix = options.prefix ?? null;
|
|
351
|
+
const r = binding.compileCss(classes, prefix);
|
|
352
|
+
return {
|
|
353
|
+
css: r.css,
|
|
354
|
+
resolvedClasses: r.resolvedClasses,
|
|
355
|
+
unknownClasses: r.unknownClasses,
|
|
356
|
+
sizeBytes: r.sizeBytes,
|
|
357
|
+
engine: "rust"
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function buildStyleTag(classes) {
|
|
361
|
+
const { css } = compileCssFromClasses(classes);
|
|
362
|
+
return css ? `<style data-tailwind-styled>${css}</style>` : "";
|
|
363
|
+
}
|
|
364
|
+
var _binding;
|
|
365
|
+
var init_cssCompiler = __esm({
|
|
366
|
+
"packages/compiler/src/cssCompiler.ts"() {
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
// packages/compiler/src/classExtractor.ts
|
|
371
|
+
function extractAllClasses(source) {
|
|
372
|
+
const { getNativeBridge: getNativeBridge2 } = (init_nativeBridge(), __toCommonJS(nativeBridge_exports));
|
|
373
|
+
const native = getNativeBridge2();
|
|
374
|
+
if (!native?.extractClassesFromSourceNative) {
|
|
375
|
+
throw new Error(
|
|
376
|
+
`[tailwind-styled/compiler v5] extractClassesFromSourceNative is required but not available.
|
|
377
|
+
Please ensure the native module is properly built.`
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
const result = native.extractClassesFromSourceNative(source);
|
|
381
|
+
if (!result || result.length < 0) {
|
|
382
|
+
throw new Error(
|
|
383
|
+
`[tailwind-styled/compiler v5] extractClassesFromSourceNative returned invalid result.`
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
return result.sort();
|
|
387
|
+
}
|
|
388
|
+
var init_classExtractor = __esm({
|
|
389
|
+
"packages/compiler/src/classExtractor.ts"() {
|
|
390
|
+
init_twDetector();
|
|
391
|
+
new RegExp(TEMPLATE_RE.source, "g");
|
|
392
|
+
new RegExp(OBJECT_RE.source, "g");
|
|
393
|
+
new RegExp(EXTEND_RE.source, "g");
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
// packages/compiler/src/atomicCss.ts
|
|
398
|
+
var atomicCss_exports = {};
|
|
399
|
+
__export(atomicCss_exports, {
|
|
400
|
+
clearAtomicRegistry: () => clearAtomicRegistry,
|
|
401
|
+
generateAtomicCss: () => generateAtomicCss,
|
|
402
|
+
getAtomicRegistry: () => getAtomicRegistry,
|
|
403
|
+
parseAtomicClass: () => parseAtomicClass,
|
|
404
|
+
toAtomicClasses: () => toAtomicClasses
|
|
405
|
+
});
|
|
406
|
+
function sizeValue(v) {
|
|
407
|
+
const num = Number(v);
|
|
408
|
+
if (!Number.isNaN(num)) return `${num * 0.25}rem`;
|
|
409
|
+
const special = {
|
|
410
|
+
full: "100%",
|
|
411
|
+
screen: "100vw",
|
|
412
|
+
auto: "auto",
|
|
413
|
+
min: "min-content",
|
|
414
|
+
max: "max-content",
|
|
415
|
+
fit: "fit-content",
|
|
416
|
+
svw: "100svw",
|
|
417
|
+
svh: "100svh"
|
|
418
|
+
};
|
|
419
|
+
return special[v] ?? v;
|
|
420
|
+
}
|
|
421
|
+
function textSize(v) {
|
|
422
|
+
const map = {
|
|
423
|
+
xs: "0.75rem",
|
|
424
|
+
sm: "0.875rem",
|
|
425
|
+
base: "1rem",
|
|
426
|
+
lg: "1.125rem",
|
|
427
|
+
xl: "1.25rem",
|
|
428
|
+
"2xl": "1.5rem",
|
|
429
|
+
"3xl": "1.875rem",
|
|
430
|
+
"4xl": "2.25rem",
|
|
431
|
+
"5xl": "3rem",
|
|
432
|
+
"6xl": "3.75rem",
|
|
433
|
+
"7xl": "4.5rem",
|
|
434
|
+
"8xl": "6rem",
|
|
435
|
+
"9xl": "8rem"
|
|
436
|
+
};
|
|
437
|
+
return map[v] ?? v;
|
|
438
|
+
}
|
|
439
|
+
function fontWeight(v) {
|
|
440
|
+
const map = {
|
|
441
|
+
thin: "100",
|
|
442
|
+
extralight: "200",
|
|
443
|
+
light: "300",
|
|
444
|
+
normal: "400",
|
|
445
|
+
medium: "500",
|
|
446
|
+
semibold: "600",
|
|
447
|
+
bold: "700",
|
|
448
|
+
extrabold: "800",
|
|
449
|
+
black: "900"
|
|
450
|
+
};
|
|
451
|
+
return map[v] ?? v;
|
|
452
|
+
}
|
|
453
|
+
function leadingValue(v) {
|
|
454
|
+
const map = {
|
|
455
|
+
none: "1",
|
|
456
|
+
tight: "1.25",
|
|
457
|
+
snug: "1.375",
|
|
458
|
+
normal: "1.5",
|
|
459
|
+
relaxed: "1.625",
|
|
460
|
+
loose: "2"
|
|
461
|
+
};
|
|
462
|
+
return map[v] ?? v;
|
|
463
|
+
}
|
|
464
|
+
function roundedValue(v) {
|
|
465
|
+
const map = {
|
|
466
|
+
"": "0.25rem",
|
|
467
|
+
sm: "0.125rem",
|
|
468
|
+
md: "0.375rem",
|
|
469
|
+
lg: "0.5rem",
|
|
470
|
+
xl: "0.75rem",
|
|
471
|
+
"2xl": "1rem",
|
|
472
|
+
"3xl": "1.5rem",
|
|
473
|
+
full: "9999px",
|
|
474
|
+
none: "0"
|
|
475
|
+
};
|
|
476
|
+
return map[v] ?? `${v}rem`;
|
|
477
|
+
}
|
|
478
|
+
function sanitizeClassName(cls) {
|
|
479
|
+
return cls.replace(/[/:[\].!%]/g, "_");
|
|
480
|
+
}
|
|
481
|
+
function parseAtomicClass(twClass) {
|
|
482
|
+
if (REGISTRY.has(twClass)) return REGISTRY.get(twClass);
|
|
483
|
+
const colonIdx = twClass.lastIndexOf(":");
|
|
484
|
+
const modifier = colonIdx > -1 ? twClass.slice(0, colonIdx) : void 0;
|
|
485
|
+
const base = colonIdx > -1 ? twClass.slice(colonIdx + 1) : twClass;
|
|
486
|
+
const dashIdx = base.indexOf("-");
|
|
487
|
+
if (dashIdx === -1) return null;
|
|
488
|
+
const prefix = base.slice(0, dashIdx);
|
|
489
|
+
const value = base.slice(dashIdx + 1);
|
|
490
|
+
const mapping = TW_PROPERTY_MAP[prefix];
|
|
491
|
+
if (!mapping) return null;
|
|
492
|
+
const cssValue = mapping.transform ? mapping.transform(value) : value;
|
|
493
|
+
const atomicName = `_tw_${sanitizeClassName(twClass)}`;
|
|
494
|
+
const rule = {
|
|
495
|
+
twClass,
|
|
496
|
+
atomicName,
|
|
497
|
+
property: mapping.prop,
|
|
498
|
+
value: cssValue,
|
|
499
|
+
modifier
|
|
500
|
+
};
|
|
501
|
+
REGISTRY.set(twClass, rule);
|
|
502
|
+
return rule;
|
|
503
|
+
}
|
|
504
|
+
function generateAtomicCss(rules) {
|
|
505
|
+
const lines = [];
|
|
506
|
+
for (const rule of rules) {
|
|
507
|
+
const selector = `.${rule.atomicName}`;
|
|
508
|
+
if (rule.modifier) {
|
|
509
|
+
const breakpoints = {
|
|
510
|
+
sm: "640px",
|
|
511
|
+
md: "768px",
|
|
512
|
+
lg: "1024px",
|
|
513
|
+
xl: "1280px",
|
|
514
|
+
"2xl": "1536px"
|
|
515
|
+
};
|
|
516
|
+
if (breakpoints[rule.modifier]) {
|
|
517
|
+
lines.push(
|
|
518
|
+
`@media (min-width: ${breakpoints[rule.modifier]}) {`,
|
|
519
|
+
` ${selector} { ${rule.property}: ${rule.value}; }`,
|
|
520
|
+
`}`
|
|
521
|
+
);
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
lines.push(`${selector}:${rule.modifier} { ${rule.property}: ${rule.value}; }`);
|
|
525
|
+
} else {
|
|
526
|
+
lines.push(`${selector} { ${rule.property}: ${rule.value}; }`);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return lines.join("\n");
|
|
530
|
+
}
|
|
531
|
+
function toAtomicClasses(twClasses) {
|
|
532
|
+
const parts = twClasses.split(/\s+/).filter(Boolean);
|
|
533
|
+
const atomicNames = [];
|
|
534
|
+
const rules = [];
|
|
535
|
+
const unknownClasses = [];
|
|
536
|
+
for (const cls of parts) {
|
|
537
|
+
const rule = parseAtomicClass(cls);
|
|
538
|
+
if (rule) {
|
|
539
|
+
atomicNames.push(rule.atomicName);
|
|
540
|
+
rules.push(rule);
|
|
541
|
+
} else {
|
|
542
|
+
unknownClasses.push(cls);
|
|
543
|
+
atomicNames.push(cls);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
return {
|
|
547
|
+
atomicClasses: atomicNames.join(" "),
|
|
548
|
+
rules,
|
|
549
|
+
unknownClasses
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
function getAtomicRegistry() {
|
|
553
|
+
return REGISTRY;
|
|
554
|
+
}
|
|
555
|
+
function clearAtomicRegistry() {
|
|
556
|
+
REGISTRY.clear();
|
|
557
|
+
}
|
|
558
|
+
var REGISTRY, TW_PROPERTY_MAP;
|
|
559
|
+
var init_atomicCss = __esm({
|
|
560
|
+
"packages/compiler/src/atomicCss.ts"() {
|
|
561
|
+
REGISTRY = /* @__PURE__ */ new Map();
|
|
562
|
+
TW_PROPERTY_MAP = {
|
|
563
|
+
// Spacing
|
|
564
|
+
p: { prop: "padding", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
565
|
+
px: { prop: "padding-inline", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
566
|
+
py: { prop: "padding-block", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
567
|
+
pt: { prop: "padding-top", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
568
|
+
pb: { prop: "padding-bottom", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
569
|
+
pl: { prop: "padding-left", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
570
|
+
pr: { prop: "padding-right", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
571
|
+
m: { prop: "margin", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
572
|
+
mx: { prop: "margin-inline", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
573
|
+
my: { prop: "margin-block", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
574
|
+
mt: { prop: "margin-top", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
575
|
+
mb: { prop: "margin-bottom", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
576
|
+
ml: { prop: "margin-left", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
577
|
+
mr: { prop: "margin-right", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
578
|
+
gap: { prop: "gap", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
579
|
+
// Sizing
|
|
580
|
+
w: { prop: "width", transform: sizeValue },
|
|
581
|
+
h: { prop: "height", transform: sizeValue },
|
|
582
|
+
// Typography
|
|
583
|
+
text: { prop: "font-size", transform: textSize },
|
|
584
|
+
font: { prop: "font-weight", transform: fontWeight },
|
|
585
|
+
leading: { prop: "line-height", transform: leadingValue },
|
|
586
|
+
// Misc
|
|
587
|
+
opacity: { prop: "opacity", transform: (v) => String(Number(v) / 100) },
|
|
588
|
+
z: { prop: "z-index" },
|
|
589
|
+
rounded: { prop: "border-radius", transform: (v) => roundedValue(v) }
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
// packages/preset/src/defaultPreset.ts
|
|
595
|
+
var defaultPreset_exports = {};
|
|
596
|
+
__export(defaultPreset_exports, {
|
|
597
|
+
defaultGlobalCss: () => defaultGlobalCss,
|
|
598
|
+
defaultPreset: () => defaultPreset,
|
|
599
|
+
defaultThemeCss: () => defaultThemeCss,
|
|
600
|
+
designTokens: () => designTokens,
|
|
601
|
+
generateTailwindConfig: () => generateTailwindConfig,
|
|
602
|
+
generateTailwindCss: () => generateTailwindCss
|
|
603
|
+
});
|
|
604
|
+
function generateTailwindCss(contentPaths = STANDARD_CONTENT_PATHS) {
|
|
605
|
+
return `@import "tailwindcss";
|
|
606
|
+
|
|
607
|
+
@theme {
|
|
608
|
+
/* colors */
|
|
609
|
+
--color-primary: #3b82f6;
|
|
610
|
+
--color-primary-hover: #2563eb;
|
|
611
|
+
--color-primary-active: #1d4ed8;
|
|
612
|
+
--color-primary-foreground: #ffffff;
|
|
613
|
+
--color-secondary: #6366f1;
|
|
614
|
+
--color-secondary-hover: #4f46e5;
|
|
615
|
+
--color-secondary-active: #4338ca;
|
|
616
|
+
--color-secondary-foreground: #ffffff;
|
|
617
|
+
--color-accent: #f59e0b;
|
|
618
|
+
--color-accent-hover: #d97706;
|
|
619
|
+
--color-accent-active: #b45309;
|
|
620
|
+
--color-accent-foreground: #000000;
|
|
621
|
+
--color-success: #10b981;
|
|
622
|
+
--color-success-foreground: #ffffff;
|
|
623
|
+
--color-warning: #f59e0b;
|
|
624
|
+
--color-warning-foreground: #000000;
|
|
625
|
+
--color-danger: #ef4444;
|
|
626
|
+
--color-danger-foreground: #ffffff;
|
|
627
|
+
--color-info: #3b82f6;
|
|
628
|
+
--color-info-foreground: #ffffff;
|
|
629
|
+
--color-surface: #18181b;
|
|
630
|
+
--color-border: #27272a;
|
|
631
|
+
--color-muted: #71717a;
|
|
632
|
+
--color-subtle: #3f3f46;
|
|
633
|
+
|
|
634
|
+
/* fonts */
|
|
635
|
+
--font-sans: InterVariable, Inter, system-ui, sans-serif;
|
|
636
|
+
--font-mono: JetBrains Mono, Fira Code, Consolas, monospace;
|
|
637
|
+
|
|
638
|
+
/* spacing */
|
|
639
|
+
--spacing-1: 0.25rem;
|
|
640
|
+
--spacing-2: 0.5rem;
|
|
641
|
+
--spacing-3: 0.75rem;
|
|
642
|
+
--spacing-4: 1rem;
|
|
643
|
+
--spacing-5: 1.25rem;
|
|
644
|
+
--spacing-6: 1.5rem;
|
|
645
|
+
--spacing-8: 2rem;
|
|
646
|
+
--spacing-10: 2.5rem;
|
|
647
|
+
--spacing-12: 3rem;
|
|
648
|
+
--spacing-16: 4rem;
|
|
649
|
+
|
|
650
|
+
/* breakpoints */
|
|
651
|
+
--breakpoint-sm: 40rem;
|
|
652
|
+
--breakpoint-md: 48rem;
|
|
653
|
+
--breakpoint-lg: 64rem;
|
|
654
|
+
--breakpoint-xl: 80rem;
|
|
655
|
+
--breakpoint-2xl: 96rem;
|
|
656
|
+
|
|
657
|
+
/* border radius */
|
|
658
|
+
--radius-sm: 0.25rem;
|
|
659
|
+
--radius-md: 0.5rem;
|
|
660
|
+
--radius-lg: 0.75rem;
|
|
661
|
+
--radius-xl: 1rem;
|
|
662
|
+
--radius-2xl: 1.5rem;
|
|
663
|
+
--radius-full: 9999px;
|
|
664
|
+
|
|
665
|
+
/* animations */
|
|
666
|
+
--animate-fade-in: fadeIn 0.2s ease-out;
|
|
667
|
+
--animate-fade-out: fadeOut 0.2s ease-in;
|
|
668
|
+
--animate-slide-up: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
|
|
669
|
+
--animate-slide-down: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
|
|
670
|
+
--animate-scale-in: scaleIn 0.2s ease-out;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
@keyframes fadeIn {
|
|
674
|
+
from { opacity: 0; }
|
|
675
|
+
to { opacity: 1; }
|
|
676
|
+
}
|
|
677
|
+
@keyframes fadeOut {
|
|
678
|
+
from { opacity: 1; }
|
|
679
|
+
to { opacity: 0; }
|
|
680
|
+
}
|
|
681
|
+
@keyframes slideUp {
|
|
682
|
+
from { transform: translateY(8px); opacity: 0; }
|
|
683
|
+
to { transform: translateY(0); opacity: 1; }
|
|
684
|
+
}
|
|
685
|
+
@keyframes slideDown {
|
|
686
|
+
from { transform: translateY(-8px); opacity: 0; }
|
|
687
|
+
to { transform: translateY(0); opacity: 1; }
|
|
688
|
+
}
|
|
689
|
+
@keyframes scaleIn {
|
|
690
|
+
from { transform: scale(0.95); opacity: 0; }
|
|
691
|
+
to { transform: scale(1); opacity: 1; }
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
@source ${contentPaths.join("\n@source ")}
|
|
695
|
+
`;
|
|
696
|
+
}
|
|
697
|
+
function generateTailwindConfig(safelistPath = ".tailwind-styled-safelist.json", contentPaths = STANDARD_CONTENT_PATHS) {
|
|
698
|
+
return `import type { Config } from "tailwindcss"
|
|
699
|
+
import { defaultPreset } from "tailwind-styled-v4/preset"
|
|
700
|
+
|
|
701
|
+
// Auto-generated safelist dari tailwind-styled-v4 compiler
|
|
702
|
+
const safelist = (() => {
|
|
703
|
+
try { return require(${JSON.stringify(safelistPath)}) as string[] }
|
|
704
|
+
catch { return [] }
|
|
705
|
+
})()
|
|
706
|
+
|
|
707
|
+
export default {
|
|
708
|
+
presets: [defaultPreset],
|
|
709
|
+
content: ${JSON.stringify(contentPaths, null, 2)},
|
|
710
|
+
safelist,
|
|
711
|
+
} satisfies Config
|
|
712
|
+
`;
|
|
713
|
+
}
|
|
714
|
+
var STANDARD_CONTENT_PATHS, designTokens, defaultPreset, defaultThemeCss, defaultGlobalCss;
|
|
715
|
+
var init_defaultPreset = __esm({
|
|
716
|
+
"packages/preset/src/defaultPreset.ts"() {
|
|
717
|
+
STANDARD_CONTENT_PATHS = [
|
|
718
|
+
// Next.js App Router
|
|
719
|
+
"./src/**/*.{tsx,ts,jsx,js,mdx}",
|
|
720
|
+
"./app/**/*.{tsx,ts,jsx,js,mdx}",
|
|
721
|
+
"./pages/**/*.{tsx,ts,jsx,js,mdx}",
|
|
722
|
+
"./components/**/*.{tsx,ts,jsx,js,mdx}",
|
|
723
|
+
// Vite / React
|
|
724
|
+
"./src/**/*.{tsx,ts,jsx,js}",
|
|
725
|
+
"./index.html",
|
|
726
|
+
// Monorepo
|
|
727
|
+
"../../packages/**/src/**/*.{tsx,ts,jsx,js}"
|
|
728
|
+
];
|
|
729
|
+
designTokens = {
|
|
730
|
+
colors: {
|
|
731
|
+
primary: { DEFAULT: "#3b82f6", hover: "#2563eb", active: "#1d4ed8", foreground: "#ffffff" },
|
|
732
|
+
secondary: { DEFAULT: "#6366f1", hover: "#4f46e5", active: "#4338ca", foreground: "#ffffff" },
|
|
733
|
+
accent: { DEFAULT: "#f59e0b", hover: "#d97706", active: "#b45309", foreground: "#000000" },
|
|
734
|
+
success: { DEFAULT: "#10b981", foreground: "#ffffff" },
|
|
735
|
+
warning: { DEFAULT: "#f59e0b", foreground: "#000000" },
|
|
736
|
+
danger: { DEFAULT: "#ef4444", foreground: "#ffffff" },
|
|
737
|
+
info: { DEFAULT: "#3b82f6", foreground: "#ffffff" },
|
|
738
|
+
surface: "#18181b",
|
|
739
|
+
border: "#27272a",
|
|
740
|
+
muted: "#71717a",
|
|
741
|
+
subtle: "#3f3f46"
|
|
742
|
+
},
|
|
743
|
+
spacing: {
|
|
744
|
+
1: "0.25rem",
|
|
745
|
+
2: "0.5rem",
|
|
746
|
+
3: "0.75rem",
|
|
747
|
+
4: "1rem",
|
|
748
|
+
5: "1.25rem",
|
|
749
|
+
6: "1.5rem",
|
|
750
|
+
8: "2rem",
|
|
751
|
+
10: "2.5rem",
|
|
752
|
+
12: "3rem",
|
|
753
|
+
16: "4rem"
|
|
754
|
+
},
|
|
755
|
+
breakpoints: {
|
|
756
|
+
sm: "40rem",
|
|
757
|
+
md: "48rem",
|
|
758
|
+
lg: "64rem",
|
|
759
|
+
xl: "80rem",
|
|
760
|
+
"2xl": "96rem"
|
|
761
|
+
},
|
|
762
|
+
fontWeight: {
|
|
763
|
+
normal: "400",
|
|
764
|
+
medium: "500",
|
|
765
|
+
semibold: "600",
|
|
766
|
+
bold: "700"
|
|
767
|
+
},
|
|
768
|
+
fontFamily: {
|
|
769
|
+
sans: ["InterVariable", "Inter", "system-ui", "sans-serif"],
|
|
770
|
+
mono: ["JetBrains Mono", "Fira Code", "Consolas", "monospace"]
|
|
771
|
+
},
|
|
772
|
+
borderRadius: {
|
|
773
|
+
sm: "0.25rem",
|
|
774
|
+
DEFAULT: "0.5rem",
|
|
775
|
+
md: "0.5rem",
|
|
776
|
+
lg: "0.75rem",
|
|
777
|
+
xl: "1rem",
|
|
778
|
+
"2xl": "1.5rem",
|
|
779
|
+
full: "9999px"
|
|
780
|
+
},
|
|
781
|
+
animation: {
|
|
782
|
+
"fade-in": "fadeIn 0.2s ease-out",
|
|
783
|
+
"fade-out": "fadeOut 0.2s ease-in",
|
|
784
|
+
"slide-up": "slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1)",
|
|
785
|
+
"slide-down": "slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1)",
|
|
786
|
+
"scale-in": "scaleIn 0.2s ease-out"
|
|
787
|
+
},
|
|
788
|
+
keyframes: {
|
|
789
|
+
fadeIn: { from: { opacity: "0" }, to: { opacity: "1" } },
|
|
790
|
+
fadeOut: { from: { opacity: "1" }, to: { opacity: "0" } },
|
|
791
|
+
slideUp: {
|
|
792
|
+
from: { transform: "translateY(8px)", opacity: "0" },
|
|
793
|
+
to: { transform: "translateY(0)", opacity: "1" }
|
|
794
|
+
},
|
|
795
|
+
slideDown: {
|
|
796
|
+
from: { transform: "translateY(-8px)", opacity: "0" },
|
|
797
|
+
to: { transform: "translateY(0)", opacity: "1" }
|
|
798
|
+
},
|
|
799
|
+
scaleIn: {
|
|
800
|
+
from: { transform: "scale(0.95)", opacity: "0" },
|
|
801
|
+
to: { transform: "scale(1)", opacity: "1" }
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
defaultPreset = {
|
|
806
|
+
content: STANDARD_CONTENT_PATHS,
|
|
807
|
+
darkMode: "class",
|
|
808
|
+
theme: {
|
|
809
|
+
extend: {
|
|
810
|
+
colors: designTokens.colors,
|
|
811
|
+
fontFamily: designTokens.fontFamily,
|
|
812
|
+
borderRadius: designTokens.borderRadius,
|
|
813
|
+
animation: designTokens.animation,
|
|
814
|
+
keyframes: designTokens.keyframes
|
|
815
|
+
}
|
|
816
|
+
},
|
|
817
|
+
plugins: []
|
|
818
|
+
};
|
|
819
|
+
defaultThemeCss = `@import "tailwindcss";
|
|
820
|
+
|
|
821
|
+
@theme {
|
|
822
|
+
/* colors */
|
|
823
|
+
--color-primary: #3b82f6;
|
|
824
|
+
--color-primary-hover: #2563eb;
|
|
825
|
+
--color-primary-active: #1d4ed8;
|
|
826
|
+
--color-primary-foreground: #ffffff;
|
|
827
|
+
--color-secondary: #6366f1;
|
|
828
|
+
--color-secondary-hover: #4f46e5;
|
|
829
|
+
--color-secondary-active: #4338ca;
|
|
830
|
+
--color-secondary-foreground: #ffffff;
|
|
831
|
+
--color-accent: #f59e0b;
|
|
832
|
+
--color-accent-hover: #d97706;
|
|
833
|
+
--color-accent-active: #b45309;
|
|
834
|
+
--color-accent-foreground: #000000;
|
|
835
|
+
--color-success: #10b981;
|
|
836
|
+
--color-success-foreground: #ffffff;
|
|
837
|
+
--color-warning: #f59e0b;
|
|
838
|
+
--color-warning-foreground: #000000;
|
|
839
|
+
--color-danger: #ef4444;
|
|
840
|
+
--color-danger-foreground: #ffffff;
|
|
841
|
+
--color-info: #3b82f6;
|
|
842
|
+
--color-info-foreground: #ffffff;
|
|
843
|
+
--color-surface: #18181b;
|
|
844
|
+
--color-border: #27272a;
|
|
845
|
+
--color-muted: #71717a;
|
|
846
|
+
--color-subtle: #3f3f46;
|
|
847
|
+
|
|
848
|
+
/* fonts */
|
|
849
|
+
--font-sans: InterVariable, Inter, system-ui, sans-serif;
|
|
850
|
+
--font-mono: JetBrains Mono, Fira Code, Consolas, monospace;
|
|
851
|
+
|
|
852
|
+
/* spacing */
|
|
853
|
+
--spacing-1: 0.25rem;
|
|
854
|
+
--spacing-2: 0.5rem;
|
|
855
|
+
--spacing-3: 0.75rem;
|
|
856
|
+
--spacing-4: 1rem;
|
|
857
|
+
--spacing-5: 1.25rem;
|
|
858
|
+
--spacing-6: 1.5rem;
|
|
859
|
+
--spacing-8: 2rem;
|
|
860
|
+
--spacing-10: 2.5rem;
|
|
861
|
+
--spacing-12: 3rem;
|
|
862
|
+
--spacing-16: 4rem;
|
|
863
|
+
|
|
864
|
+
/* breakpoints */
|
|
865
|
+
--breakpoint-sm: 40rem;
|
|
866
|
+
--breakpoint-md: 48rem;
|
|
867
|
+
--breakpoint-lg: 64rem;
|
|
868
|
+
--breakpoint-xl: 80rem;
|
|
869
|
+
--breakpoint-2xl: 96rem;
|
|
870
|
+
|
|
871
|
+
/* border radius */
|
|
872
|
+
--radius-sm: 0.25rem;
|
|
873
|
+
--radius-md: 0.5rem;
|
|
874
|
+
--radius-lg: 0.75rem;
|
|
875
|
+
--radius-xl: 1rem;
|
|
876
|
+
--radius-2xl: 1.5rem;
|
|
877
|
+
--radius-full: 9999px;
|
|
878
|
+
|
|
879
|
+
/* animations */
|
|
880
|
+
--animate-fade-in: fadeIn 0.2s ease-out;
|
|
881
|
+
--animate-fade-out: fadeOut 0.2s ease-in;
|
|
882
|
+
--animate-slide-up: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
|
|
883
|
+
--animate-slide-down: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
|
|
884
|
+
--animate-scale-in: scaleIn 0.2s ease-out;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
@keyframes fadeIn {
|
|
888
|
+
from { opacity: 0; }
|
|
889
|
+
to { opacity: 1; }
|
|
890
|
+
}
|
|
891
|
+
@keyframes fadeOut {
|
|
892
|
+
from { opacity: 1; }
|
|
893
|
+
to { opacity: 0; }
|
|
894
|
+
}
|
|
895
|
+
@keyframes slideUp {
|
|
896
|
+
from { transform: translateY(8px); opacity: 0; }
|
|
897
|
+
to { transform: translateY(0); opacity: 1; }
|
|
898
|
+
}
|
|
899
|
+
@keyframes slideDown {
|
|
900
|
+
from { transform: translateY(-8px); opacity: 0; }
|
|
901
|
+
to { transform: translateY(0); opacity: 1; }
|
|
902
|
+
}
|
|
903
|
+
@keyframes scaleIn {
|
|
904
|
+
from { transform: scale(0.95); opacity: 0; }
|
|
905
|
+
to { transform: scale(1); opacity: 1; }
|
|
906
|
+
}`;
|
|
907
|
+
defaultGlobalCss = `@import "tailwindcss";
|
|
908
|
+
|
|
909
|
+
@theme {
|
|
910
|
+
/* colors */
|
|
911
|
+
--color-primary: #3b82f6;
|
|
912
|
+
--color-primary-hover: #2563eb;
|
|
913
|
+
--color-primary-active: #1d4ed8;
|
|
914
|
+
--color-primary-foreground: #ffffff;
|
|
915
|
+
--color-secondary: #6366f1;
|
|
916
|
+
--color-secondary-hover: #4f46e5;
|
|
917
|
+
--color-secondary-active: #4338ca;
|
|
918
|
+
--color-secondary-foreground: #ffffff;
|
|
919
|
+
--color-accent: #f59e0b;
|
|
920
|
+
--color-accent-hover: #d97706;
|
|
921
|
+
--color-accent-active: #b45309;
|
|
922
|
+
--color-accent-foreground: #000000;
|
|
923
|
+
--color-success: #10b981;
|
|
924
|
+
--color-success-foreground: #ffffff;
|
|
925
|
+
--color-warning: #f59e0b;
|
|
926
|
+
--color-warning-foreground: #000000;
|
|
927
|
+
--color-danger: #ef4444;
|
|
928
|
+
--color-danger-foreground: #ffffff;
|
|
929
|
+
--color-info: #3b82f6;
|
|
930
|
+
--color-info-foreground: #ffffff;
|
|
931
|
+
--color-surface: #18181b;
|
|
932
|
+
--color-border: #27272a;
|
|
933
|
+
--color-muted: #71717a;
|
|
934
|
+
--color-subtle: #3f3f46;
|
|
935
|
+
|
|
936
|
+
/* fonts */
|
|
937
|
+
--font-sans: InterVariable, Inter, system-ui, sans-serif;
|
|
938
|
+
--font-mono: JetBrains Mono, Fira Code, Consolas, monospace;
|
|
939
|
+
|
|
940
|
+
/* spacing */
|
|
941
|
+
--spacing-1: 0.25rem;
|
|
942
|
+
--spacing-2: 0.5rem;
|
|
943
|
+
--spacing-3: 0.75rem;
|
|
944
|
+
--spacing-4: 1rem;
|
|
945
|
+
--spacing-5: 1.25rem;
|
|
946
|
+
--spacing-6: 1.5rem;
|
|
947
|
+
--spacing-8: 2rem;
|
|
948
|
+
--spacing-10: 2.5rem;
|
|
949
|
+
--spacing-12: 3rem;
|
|
950
|
+
--spacing-16: 4rem;
|
|
951
|
+
|
|
952
|
+
/* breakpoints */
|
|
953
|
+
--breakpoint-sm: 40rem;
|
|
954
|
+
--breakpoint-md: 48rem;
|
|
955
|
+
--breakpoint-lg: 64rem;
|
|
956
|
+
--breakpoint-xl: 80rem;
|
|
957
|
+
--breakpoint-2xl: 96rem;
|
|
958
|
+
|
|
959
|
+
/* border radius */
|
|
960
|
+
--radius-sm: 0.25rem;
|
|
961
|
+
--radius-md: 0.5rem;
|
|
962
|
+
--radius-lg: 0.75rem;
|
|
963
|
+
--radius-xl: 1rem;
|
|
964
|
+
--radius-2xl: 1.5rem;
|
|
965
|
+
--radius-full: 9999px;
|
|
966
|
+
|
|
967
|
+
/* animations */
|
|
968
|
+
--animate-fade-in: fadeIn 0.2s ease-out;
|
|
969
|
+
--animate-fade-out: fadeOut 0.2s ease-in;
|
|
970
|
+
--animate-slide-up: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
|
|
971
|
+
--animate-slide-down: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
|
|
972
|
+
--animate-scale-in: scaleIn 0.2s ease-out;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
@keyframes fadeIn {
|
|
976
|
+
from { opacity: 0; }
|
|
977
|
+
to { opacity: 1; }
|
|
978
|
+
}
|
|
979
|
+
@keyframes fadeOut {
|
|
980
|
+
from { opacity: 1; }
|
|
981
|
+
to { opacity: 0; }
|
|
982
|
+
}
|
|
983
|
+
@keyframes slideUp {
|
|
984
|
+
from { transform: translateY(8px); opacity: 0; }
|
|
985
|
+
to { transform: translateY(0); opacity: 1; }
|
|
986
|
+
}
|
|
987
|
+
@keyframes slideDown {
|
|
988
|
+
from { transform: translateY(-8px); opacity: 0; }
|
|
989
|
+
to { transform: translateY(0); opacity: 1; }
|
|
990
|
+
}
|
|
991
|
+
@keyframes scaleIn {
|
|
992
|
+
from { transform: scale(0.95); opacity: 0; }
|
|
993
|
+
to { transform: scale(1); opacity: 1; }
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/* tailwind-styled-v4 \u2014 zero-config base styles */
|
|
997
|
+
*, *::before, *::after {
|
|
998
|
+
box-sizing: border-box;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
html {
|
|
1002
|
+
-webkit-font-smoothing: antialiased;
|
|
1003
|
+
-moz-osx-font-smoothing: grayscale;
|
|
1004
|
+
text-rendering: optimizeLegibility;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
body {
|
|
1008
|
+
margin: 0;
|
|
1009
|
+
font-family: var(--font-sans, system-ui, sans-serif);
|
|
1010
|
+
background: var(--color-surface, #18181b);
|
|
1011
|
+
color: var(--color-foreground, #fafafa);
|
|
1012
|
+
}
|
|
1013
|
+
`;
|
|
1014
|
+
}
|
|
1015
|
+
});
|
|
1016
|
+
function loadTailwindConfig(cwd = process.cwd()) {
|
|
1017
|
+
if (_cachedConfig && _cachedCwd === cwd) return _cachedConfig;
|
|
1018
|
+
_cachedCwd = cwd;
|
|
1019
|
+
for (const file of CONFIG_FILES) {
|
|
1020
|
+
const fullPath = path8.join(cwd, file);
|
|
1021
|
+
if (fs3.existsSync(fullPath)) {
|
|
1022
|
+
try {
|
|
1023
|
+
const mod = __require(fullPath);
|
|
1024
|
+
const config = mod.default ?? mod;
|
|
1025
|
+
_cachedConfig = config;
|
|
1026
|
+
console.log(`[tailwind-styled-v4] Using config: ${file}`);
|
|
1027
|
+
return config;
|
|
1028
|
+
} catch {
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
console.log("[tailwind-styled-v4] No tailwind config found \u2192 using built-in preset");
|
|
1033
|
+
const { defaultPreset: defaultPreset2 } = (init_defaultPreset(), __toCommonJS(defaultPreset_exports));
|
|
1034
|
+
_cachedConfig = defaultPreset2;
|
|
1035
|
+
return defaultPreset2;
|
|
1036
|
+
}
|
|
1037
|
+
var CONFIG_FILES, _cachedConfig, _cachedCwd;
|
|
1038
|
+
var init_loadTailwindConfig = __esm({
|
|
1039
|
+
"packages/compiler/src/loadTailwindConfig.ts"() {
|
|
1040
|
+
CONFIG_FILES = [
|
|
1041
|
+
"tailwind.config.ts",
|
|
1042
|
+
"tailwind.config.js",
|
|
1043
|
+
"tailwind.config.mjs",
|
|
1044
|
+
"tailwind.config.cjs"
|
|
1045
|
+
];
|
|
1046
|
+
_cachedConfig = null;
|
|
1047
|
+
_cachedCwd = "";
|
|
1048
|
+
}
|
|
1049
|
+
});
|
|
1050
|
+
async function generateCssForClasses(classes, config, cwd = process.cwd()) {
|
|
1051
|
+
try {
|
|
1052
|
+
const { compileCssFromClasses: compileCssFromClasses2 } = (init_cssCompiler(), __toCommonJS(cssCompiler_exports));
|
|
1053
|
+
const result = compileCssFromClasses2(classes);
|
|
1054
|
+
if (result?.css && result.resolvedClasses.length > 0) {
|
|
1055
|
+
const resolveRate = result.resolvedClasses.length / classes.length;
|
|
1056
|
+
if (resolveRate >= 0.5) return result.css;
|
|
1057
|
+
}
|
|
1058
|
+
} catch {
|
|
1059
|
+
}
|
|
1060
|
+
const twConfig = config ?? loadTailwindConfig(cwd);
|
|
1061
|
+
try {
|
|
1062
|
+
return await generateViaTailwindV4(classes, twConfig, cwd);
|
|
1063
|
+
} catch {
|
|
1064
|
+
}
|
|
1065
|
+
return generateManualCss(classes);
|
|
1066
|
+
}
|
|
1067
|
+
async function generateViaTailwindV4(classes, _config, cwd) {
|
|
1068
|
+
const virtualCss = [
|
|
1069
|
+
`@import "tailwindcss";`,
|
|
1070
|
+
`@layer utilities {`,
|
|
1071
|
+
` /* Generated by tailwind-styled-v4 */`,
|
|
1072
|
+
`}`
|
|
1073
|
+
].join("\n");
|
|
1074
|
+
const postcss = __require("postcss");
|
|
1075
|
+
const tailwindcss = __require("@tailwindcss/postcss");
|
|
1076
|
+
const result = await postcss([
|
|
1077
|
+
tailwindcss({
|
|
1078
|
+
optimize: { minify: false }
|
|
1079
|
+
})
|
|
1080
|
+
]).process(virtualCss, {
|
|
1081
|
+
from: path8.join(cwd, "virtual.css")
|
|
1082
|
+
});
|
|
1083
|
+
return filterCssForClasses(result.css, classes);
|
|
1084
|
+
}
|
|
1085
|
+
function generateManualCss(classes) {
|
|
1086
|
+
const { generateAtomicCss: generateAtomicCss2, parseAtomicClass: parseAtomicClass2 } = (init_atomicCss(), __toCommonJS(atomicCss_exports));
|
|
1087
|
+
const rules = classes.map((c) => parseAtomicClass2(c)).filter(Boolean);
|
|
1088
|
+
if (rules.length === 0) return "";
|
|
1089
|
+
const header = `/* Generated by tailwind-styled-v4 \u2014 ${(/* @__PURE__ */ new Date()).toISOString()} */
|
|
1090
|
+
`;
|
|
1091
|
+
return header + generateAtomicCss2(rules);
|
|
1092
|
+
}
|
|
1093
|
+
function filterCssForClasses(fullCss, classes) {
|
|
1094
|
+
new Set(classes);
|
|
1095
|
+
const lines = fullCss.split("\n");
|
|
1096
|
+
const kept = [];
|
|
1097
|
+
let inBlock = false;
|
|
1098
|
+
let keepBlock = false;
|
|
1099
|
+
let braceDepth = 0;
|
|
1100
|
+
for (const line of lines) {
|
|
1101
|
+
if (line.includes("@layer base") || line.includes("*, *::before")) {
|
|
1102
|
+
kept.push(line);
|
|
1103
|
+
continue;
|
|
1104
|
+
}
|
|
1105
|
+
if (!inBlock) {
|
|
1106
|
+
const isOurClass = classes.some((cls) => {
|
|
1107
|
+
const escaped = cls.replace(/[:/[\].!%]/g, "\\$&");
|
|
1108
|
+
return line.includes(`.${escaped}`) || line.includes(`.${cls}`);
|
|
1109
|
+
});
|
|
1110
|
+
if (isOurClass) {
|
|
1111
|
+
keepBlock = true;
|
|
1112
|
+
inBlock = true;
|
|
1113
|
+
braceDepth = 0;
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
if (inBlock) {
|
|
1117
|
+
if (keepBlock) kept.push(line);
|
|
1118
|
+
if (line.includes("{")) braceDepth++;
|
|
1119
|
+
if (line.includes("}")) {
|
|
1120
|
+
braceDepth--;
|
|
1121
|
+
if (braceDepth <= 0) {
|
|
1122
|
+
inBlock = false;
|
|
1123
|
+
keepBlock = false;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
return kept.join("\n");
|
|
1129
|
+
}
|
|
1130
|
+
var init_tailwindEngine = __esm({
|
|
1131
|
+
"packages/compiler/src/tailwindEngine.ts"() {
|
|
1132
|
+
init_loadTailwindConfig();
|
|
1133
|
+
}
|
|
1134
|
+
});
|
|
1135
|
+
|
|
1136
|
+
// packages/compiler/src/index.ts
|
|
1137
|
+
var init_src2 = __esm({
|
|
1138
|
+
"packages/compiler/src/index.ts"() {
|
|
1139
|
+
init_classExtractor();
|
|
1140
|
+
init_classMerger();
|
|
1141
|
+
init_tailwindEngine();
|
|
1142
|
+
}
|
|
1143
|
+
});
|
|
1144
|
+
|
|
1145
|
+
// packages/scanner/src/native-bridge.ts
|
|
1146
|
+
var native_bridge_exports = {};
|
|
1147
|
+
__export(native_bridge_exports, {
|
|
1148
|
+
cachePriorityNative: () => cachePriorityNative,
|
|
1149
|
+
cacheReadNative: () => cacheReadNative,
|
|
1150
|
+
cacheWriteNative: () => cacheWriteNative,
|
|
1151
|
+
extractClassesNative: () => extractClassesNative,
|
|
1152
|
+
hasNativeScannerBinding: () => hasNativeScannerBinding,
|
|
1153
|
+
hashContentNative: () => hashContentNative,
|
|
1154
|
+
isRustCacheAvailable: () => isRustCacheAvailable,
|
|
1155
|
+
scanWorkspaceNative: () => scanWorkspaceNative
|
|
1156
|
+
});
|
|
1157
|
+
function getBinding2() {
|
|
1158
|
+
if (_binding2 !== void 0) {
|
|
1159
|
+
if (_binding2 === null) {
|
|
1160
|
+
throwNativeBindingError();
|
|
1161
|
+
}
|
|
1162
|
+
return _binding2;
|
|
1163
|
+
}
|
|
1164
|
+
if (process.env.TWS_NO_NATIVE === "1" || process.env.TWS_NO_RUST === "1") {
|
|
1165
|
+
_loadError = "Native loading is disabled by TWS_NO_NATIVE or TWS_NO_RUST environment variable.";
|
|
1166
|
+
_binding2 = null;
|
|
1167
|
+
_candidatePaths = [];
|
|
1168
|
+
throwNativeBindingError();
|
|
1169
|
+
}
|
|
1170
|
+
const runtimeDir2 = typeof __dirname === "string" ? __dirname : process.cwd();
|
|
1171
|
+
_candidatePaths = [
|
|
1172
|
+
path8.resolve(process.cwd(), "native", "tailwind_styled_parser.node"),
|
|
1173
|
+
path8.resolve(runtimeDir2, "..", "..", "..", "native", "tailwind_styled_parser.node")
|
|
1174
|
+
];
|
|
1175
|
+
const req = typeof __require === "function" ? __require : createRequire(path8.join(runtimeDir2, "noop.cjs"));
|
|
1176
|
+
for (const c of _candidatePaths) {
|
|
1177
|
+
try {
|
|
1178
|
+
const mod = req(c);
|
|
1179
|
+
if (mod?.scanWorkspace || mod?.extractClassesFromSource || mod?.hashFileContent || mod?.cacheRead || mod?.cacheWrite) {
|
|
1180
|
+
_binding2 = mod;
|
|
1181
|
+
return _binding2;
|
|
1182
|
+
}
|
|
1183
|
+
} catch (error) {
|
|
1184
|
+
_loadError = error instanceof Error ? error.message : String(error);
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
_binding2 = null;
|
|
1188
|
+
throwNativeBindingError();
|
|
1189
|
+
}
|
|
1190
|
+
function throwNativeBindingError() {
|
|
1191
|
+
const lines = [
|
|
1192
|
+
"FATAL: Native scanner binding not found.",
|
|
1193
|
+
"",
|
|
1194
|
+
"This package requires the Rust native binding 'tailwind_styled_parser.node'.",
|
|
1195
|
+
"The binding was not found in any of these paths:",
|
|
1196
|
+
..._candidatePaths.map((p) => ` - ${p}`),
|
|
1197
|
+
""
|
|
1198
|
+
];
|
|
1199
|
+
if (_loadError) {
|
|
1200
|
+
lines.push("Load error:", ` ${_loadError}`, "");
|
|
1201
|
+
}
|
|
1202
|
+
lines.push(
|
|
1203
|
+
"To fix this, run:",
|
|
1204
|
+
" npm run build:rust",
|
|
1205
|
+
"",
|
|
1206
|
+
"This will build the native Rust module from the 'native/' directory.",
|
|
1207
|
+
"If you're using this package in a CI/CD environment, ensure Rust toolchain is installed",
|
|
1208
|
+
"and 'npm run build:rust' is executed before running tests or building."
|
|
1209
|
+
);
|
|
1210
|
+
throw new Error(lines.join("\n"));
|
|
1211
|
+
}
|
|
1212
|
+
function scanWorkspaceNative(root, extensions) {
|
|
1213
|
+
return getBinding2().scanWorkspace(root, extensions ?? null);
|
|
1214
|
+
}
|
|
1215
|
+
function extractClassesNative(source) {
|
|
1216
|
+
const result = getBinding2().extractClassesFromSource?.(source);
|
|
1217
|
+
if (result === null || result === void 0) {
|
|
1218
|
+
throw new Error("Native extractClassesFromSource returned null/undefined");
|
|
1219
|
+
}
|
|
1220
|
+
return result;
|
|
1221
|
+
}
|
|
1222
|
+
function hashContentNative(content) {
|
|
1223
|
+
const result = getBinding2().hashFileContent?.(content);
|
|
1224
|
+
if (result === null || result === void 0) {
|
|
1225
|
+
throw new Error("Native hashFileContent returned null/undefined");
|
|
1226
|
+
}
|
|
1227
|
+
return result;
|
|
1228
|
+
}
|
|
1229
|
+
function isRustCacheAvailable() {
|
|
1230
|
+
return true;
|
|
1231
|
+
}
|
|
1232
|
+
function hasNativeScannerBinding() {
|
|
1233
|
+
try {
|
|
1234
|
+
getBinding2();
|
|
1235
|
+
return true;
|
|
1236
|
+
} catch {
|
|
1237
|
+
return false;
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
function cacheReadNative(cachePath) {
|
|
1241
|
+
const result = getBinding2().cacheRead?.(cachePath);
|
|
1242
|
+
if (result === null || result === void 0) {
|
|
1243
|
+
throw new Error("Native cacheRead returned null/undefined");
|
|
1244
|
+
}
|
|
1245
|
+
return result;
|
|
1246
|
+
}
|
|
1247
|
+
function cacheWriteNative(cachePath, entries) {
|
|
1248
|
+
const result = getBinding2().cacheWrite?.(cachePath, entries);
|
|
1249
|
+
if (result === null || result === void 0) {
|
|
1250
|
+
throw new Error("Native cacheWrite returned null/undefined");
|
|
1251
|
+
}
|
|
1252
|
+
return result;
|
|
1253
|
+
}
|
|
1254
|
+
function cachePriorityNative(mtimeMs, size, cachedMtimeMs, cachedSize, cachedHitCount, cachedLastSeenMs, nowMs = Date.now()) {
|
|
1255
|
+
const result = getBinding2().cachePriority?.(
|
|
1256
|
+
mtimeMs,
|
|
1257
|
+
size,
|
|
1258
|
+
cachedMtimeMs,
|
|
1259
|
+
cachedSize,
|
|
1260
|
+
cachedHitCount,
|
|
1261
|
+
cachedLastSeenMs,
|
|
1262
|
+
nowMs
|
|
1263
|
+
);
|
|
1264
|
+
if (result === null || result === void 0) {
|
|
1265
|
+
throw new Error("Native cachePriority returned null/undefined");
|
|
1266
|
+
}
|
|
1267
|
+
return result;
|
|
1268
|
+
}
|
|
1269
|
+
var _binding2, _loadError, _candidatePaths;
|
|
1270
|
+
var init_native_bridge = __esm({
|
|
1271
|
+
"packages/scanner/src/native-bridge.ts"() {
|
|
1272
|
+
_binding2 = void 0;
|
|
1273
|
+
_loadError = null;
|
|
1274
|
+
_candidatePaths = [];
|
|
1275
|
+
}
|
|
1276
|
+
});
|
|
1277
|
+
function defaultCachePath(rootDir, cacheDir) {
|
|
1278
|
+
const dir = cacheDir ? path8.resolve(rootDir, cacheDir) : path8.join(process.cwd(), ".cache", "tailwind-styled");
|
|
1279
|
+
return path8.join(dir, "scanner-cache.json");
|
|
1280
|
+
}
|
|
1281
|
+
function readCache(rootDir, cacheDir) {
|
|
1282
|
+
const cachePath = defaultCachePath(rootDir, cacheDir);
|
|
1283
|
+
const result = cacheReadNative(cachePath);
|
|
1284
|
+
return result.entries.map((e) => ({
|
|
1285
|
+
file: e.file,
|
|
1286
|
+
classes: e.classes,
|
|
1287
|
+
hash: e.hash,
|
|
1288
|
+
mtimeMs: e.mtimeMs,
|
|
1289
|
+
size: e.size,
|
|
1290
|
+
hitCount: e.hitCount
|
|
1291
|
+
}));
|
|
1292
|
+
}
|
|
1293
|
+
function writeCache(rootDir, entries, cacheDir) {
|
|
1294
|
+
const cachePath = defaultCachePath(rootDir, cacheDir);
|
|
1295
|
+
const success = cacheWriteNative(cachePath, entries);
|
|
1296
|
+
if (!success) {
|
|
1297
|
+
throw new Error(
|
|
1298
|
+
"Native cacheWrite failed. Run 'npm run build:rust' to rebuild native bindings."
|
|
1299
|
+
);
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
function filePriority(mtimeMs, size, cached, nowMs = Date.now()) {
|
|
1303
|
+
return cachePriorityNative(
|
|
1304
|
+
mtimeMs,
|
|
1305
|
+
size,
|
|
1306
|
+
cached?.mtimeMs ?? 0,
|
|
1307
|
+
cached?.size ?? 0,
|
|
1308
|
+
cached?.hitCount ?? 0,
|
|
1309
|
+
cached?.lastSeenMs ?? 0,
|
|
1310
|
+
nowMs
|
|
1311
|
+
);
|
|
1312
|
+
}
|
|
1313
|
+
var init_cache_native = __esm({
|
|
1314
|
+
"packages/scanner/src/cache-native.ts"() {
|
|
1315
|
+
init_native_bridge();
|
|
1316
|
+
}
|
|
1317
|
+
});
|
|
1318
|
+
function canUseCjsRequire() {
|
|
1319
|
+
return typeof __require === "function";
|
|
1320
|
+
}
|
|
1321
|
+
function debugNative(message) {
|
|
1322
|
+
log2.debug(`[native] ${message}`);
|
|
1323
|
+
}
|
|
1324
|
+
function loadNativeParserBinding() {
|
|
1325
|
+
if (nativeParserBinding !== void 0) return nativeParserBinding;
|
|
1326
|
+
if (!canUseCjsRequire()) {
|
|
1327
|
+
nativeParserBinding = null;
|
|
1328
|
+
nativeParserInitError = "require is unavailable in current module format";
|
|
1329
|
+
debugNative(`fallback to JS: ${nativeParserInitError}`);
|
|
1330
|
+
return nativeParserBinding;
|
|
1331
|
+
}
|
|
1332
|
+
const candidates = [
|
|
1333
|
+
path8.resolve(process.cwd(), "native/tailwind_styled_parser.node"),
|
|
1334
|
+
path8.resolve(process.cwd(), "native/build/Release/tailwind_styled_parser.node")
|
|
1335
|
+
];
|
|
1336
|
+
for (const fullPath of candidates) {
|
|
1337
|
+
if (!fs3.existsSync(fullPath)) continue;
|
|
1338
|
+
try {
|
|
1339
|
+
const required = __require(fullPath);
|
|
1340
|
+
if (required && typeof required.parse_classes === "function") {
|
|
1341
|
+
nativeParserBinding = required;
|
|
1342
|
+
debugNative(`using native parser from ${fullPath}`);
|
|
1343
|
+
return nativeParserBinding;
|
|
1344
|
+
}
|
|
1345
|
+
} catch (error) {
|
|
1346
|
+
nativeParserInitError = error instanceof Error ? error.message : String(error);
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
nativeParserBinding = null;
|
|
1350
|
+
if (!nativeParserInitError) {
|
|
1351
|
+
nativeParserInitError = "native .node binding not found";
|
|
1352
|
+
}
|
|
1353
|
+
debugNative(`fallback to JS: ${nativeParserInitError}`);
|
|
1354
|
+
return nativeParserBinding;
|
|
1355
|
+
}
|
|
1356
|
+
function normalizeWithNativeParser(tokens) {
|
|
1357
|
+
const binding = loadNativeParserBinding();
|
|
1358
|
+
if (!binding || typeof binding.parse_classes !== "function") {
|
|
1359
|
+
throw new Error(
|
|
1360
|
+
"Native parser binding is required but not available. Run 'npm run build:rust' to build it."
|
|
1361
|
+
);
|
|
1362
|
+
}
|
|
1363
|
+
try {
|
|
1364
|
+
const parsed = binding.parse_classes(tokens.join(" "));
|
|
1365
|
+
const normalized = parsed.map((item) => item.raw?.trim() ?? "").filter(Boolean);
|
|
1366
|
+
return Array.from(new Set(normalized));
|
|
1367
|
+
} catch (error) {
|
|
1368
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1369
|
+
throw new Error(`Native parser failed: ${errorMessage}. Run 'npm run build:rust' to rebuild.`);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
function resolveScannerWorkerModulePath() {
|
|
1373
|
+
const runtimeDir2 = typeof __dirname === "string" && __dirname.length > 0 ? __dirname : path8.dirname(fileURLToPath(import.meta.url));
|
|
1374
|
+
const candidates = [
|
|
1375
|
+
path8.resolve(runtimeDir2, "index.cjs"),
|
|
1376
|
+
path8.resolve(runtimeDir2, "index.js"),
|
|
1377
|
+
path8.resolve(runtimeDir2, "index.ts")
|
|
1378
|
+
];
|
|
1379
|
+
for (const candidate of candidates) {
|
|
1380
|
+
if (fs3.existsSync(candidate)) return candidate;
|
|
1381
|
+
}
|
|
1382
|
+
return null;
|
|
1383
|
+
}
|
|
1384
|
+
function scanWorkspaceInWorker(rootDir, options) {
|
|
1385
|
+
const modulePath = resolveScannerWorkerModulePath();
|
|
1386
|
+
if (!modulePath) {
|
|
1387
|
+
return Promise.reject(new Error("scanner worker module path could not be resolved"));
|
|
1388
|
+
}
|
|
1389
|
+
return new Promise((resolve, reject) => {
|
|
1390
|
+
let settled = false;
|
|
1391
|
+
const worker = new Worker(SCAN_WORKER_BOOTSTRAP, {
|
|
1392
|
+
eval: true,
|
|
1393
|
+
workerData: { modulePath, rootDir, options }
|
|
1394
|
+
});
|
|
1395
|
+
const timeout = setTimeout(() => {
|
|
1396
|
+
if (settled) return;
|
|
1397
|
+
settled = true;
|
|
1398
|
+
void worker.terminate();
|
|
1399
|
+
reject(new Error(`scanner worker timed out after ${SCAN_WORKER_TIMEOUT_MS}ms`));
|
|
1400
|
+
}, SCAN_WORKER_TIMEOUT_MS);
|
|
1401
|
+
const finish = (callback) => {
|
|
1402
|
+
if (settled) return;
|
|
1403
|
+
settled = true;
|
|
1404
|
+
clearTimeout(timeout);
|
|
1405
|
+
callback();
|
|
1406
|
+
};
|
|
1407
|
+
worker.once("message", (payload) => {
|
|
1408
|
+
const message = payload;
|
|
1409
|
+
finish(() => {
|
|
1410
|
+
if (message?.ok) {
|
|
1411
|
+
resolve(message.result);
|
|
1412
|
+
return;
|
|
1413
|
+
}
|
|
1414
|
+
reject(new Error(message?.error ?? "scanner worker failed without an error message"));
|
|
1415
|
+
});
|
|
1416
|
+
});
|
|
1417
|
+
worker.once("error", (error) => {
|
|
1418
|
+
finish(() => reject(error));
|
|
1419
|
+
});
|
|
1420
|
+
worker.once("exit", (code) => {
|
|
1421
|
+
if (code !== 0) {
|
|
1422
|
+
finish(() => reject(new Error(`scanner worker exited with code ${code}`)));
|
|
1423
|
+
}
|
|
1424
|
+
});
|
|
1425
|
+
});
|
|
1426
|
+
}
|
|
1427
|
+
function buildExtensionSet(includeExtensions) {
|
|
1428
|
+
return new Set(includeExtensions);
|
|
1429
|
+
}
|
|
1430
|
+
function collectCandidates(rootDir, ignoreDirectories, extensionSet) {
|
|
1431
|
+
const candidates = [];
|
|
1432
|
+
const directories = [rootDir];
|
|
1433
|
+
while (directories.length > 0) {
|
|
1434
|
+
const currentDir = directories.pop();
|
|
1435
|
+
if (!currentDir) continue;
|
|
1436
|
+
let entries = [];
|
|
1437
|
+
try {
|
|
1438
|
+
entries = fs3.readdirSync(currentDir, { withFileTypes: true });
|
|
1439
|
+
} catch {
|
|
1440
|
+
continue;
|
|
1441
|
+
}
|
|
1442
|
+
for (const entry of entries) {
|
|
1443
|
+
const fullPath = path8.join(currentDir, entry.name);
|
|
1444
|
+
if (entry.isDirectory()) {
|
|
1445
|
+
if (!ignoreDirectories.has(entry.name)) directories.push(fullPath);
|
|
1446
|
+
continue;
|
|
1447
|
+
}
|
|
1448
|
+
if (!entry.isFile()) continue;
|
|
1449
|
+
if (!extensionSet.has(path8.extname(entry.name))) continue;
|
|
1450
|
+
candidates.push(fullPath);
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
return candidates;
|
|
1454
|
+
}
|
|
1455
|
+
function toCacheSize(size) {
|
|
1456
|
+
if (!Number.isFinite(size)) return 0;
|
|
1457
|
+
const normalized = Math.max(0, Math.trunc(size));
|
|
1458
|
+
return Math.min(normalized, 4294967295);
|
|
1459
|
+
}
|
|
1460
|
+
function extractClassesJs(source) {
|
|
1461
|
+
return extractAllClasses(source);
|
|
1462
|
+
}
|
|
1463
|
+
function scanSource(source) {
|
|
1464
|
+
const nativeBinding = loadNativeParserBinding();
|
|
1465
|
+
if (nativeBinding && typeof nativeBinding.parse_classes === "function") {
|
|
1466
|
+
try {
|
|
1467
|
+
const baseClasses = extractClassesJs(source);
|
|
1468
|
+
const nativeNormalized = normalizeWithNativeParser(baseClasses);
|
|
1469
|
+
return nativeNormalized;
|
|
1470
|
+
} catch (error) {
|
|
1471
|
+
throw error;
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
throw new Error(
|
|
1475
|
+
"Native parser binding is required but not available. Run 'npm run build:rust' to build it."
|
|
1476
|
+
);
|
|
1477
|
+
}
|
|
1478
|
+
function isScannableFile(filePath, includeExtensions = DEFAULT_EXTENSIONS) {
|
|
1479
|
+
return includeExtensions.includes(path8.extname(filePath));
|
|
1480
|
+
}
|
|
1481
|
+
function scanFile(filePath) {
|
|
1482
|
+
const source = fs3.readFileSync(filePath, "utf8");
|
|
1483
|
+
const hash = hashContentNative(source) ?? void 0;
|
|
1484
|
+
return {
|
|
1485
|
+
file: filePath,
|
|
1486
|
+
classes: scanSource(source),
|
|
1487
|
+
...hash ? { hash } : {}
|
|
1488
|
+
};
|
|
1489
|
+
}
|
|
1490
|
+
function scanWorkspace(rootDir, options = {}) {
|
|
1491
|
+
const includeExtensions = options.includeExtensions ?? DEFAULT_EXTENSIONS;
|
|
1492
|
+
const extensionSet = buildExtensionSet(includeExtensions);
|
|
1493
|
+
const ignoreDirectories = new Set(options.ignoreDirectories ?? DEFAULT_IGNORES);
|
|
1494
|
+
const useCache = options.useCache ?? true;
|
|
1495
|
+
options.smartInvalidation ?? true;
|
|
1496
|
+
const files = [];
|
|
1497
|
+
const unique = /* @__PURE__ */ new Set();
|
|
1498
|
+
const candidates = collectCandidates(rootDir, ignoreDirectories, extensionSet);
|
|
1499
|
+
const processResult = (result) => {
|
|
1500
|
+
files.push(result);
|
|
1501
|
+
for (const cls of result.classes) unique.add(cls);
|
|
1502
|
+
};
|
|
1503
|
+
const { scanWorkspaceNative: scanWorkspaceNative2 } = (init_native_bridge(), __toCommonJS(native_bridge_exports));
|
|
1504
|
+
if (!options.cacheDir && !useCache) {
|
|
1505
|
+
const nativeResult = scanWorkspaceNative2(rootDir, includeExtensions);
|
|
1506
|
+
if (nativeResult) {
|
|
1507
|
+
return {
|
|
1508
|
+
files: nativeResult.files.map((f) => ({
|
|
1509
|
+
file: f.file,
|
|
1510
|
+
classes: f.classes
|
|
1511
|
+
})),
|
|
1512
|
+
totalFiles: nativeResult.totalFiles,
|
|
1513
|
+
uniqueClasses: nativeResult.uniqueClasses
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
if (useCache && isRustCacheAvailable()) {
|
|
1518
|
+
let cacheEntries = [];
|
|
1519
|
+
try {
|
|
1520
|
+
cacheEntries = readCache(rootDir, options.cacheDir);
|
|
1521
|
+
} catch (error) {
|
|
1522
|
+
cacheEntries = [];
|
|
1523
|
+
log2.debug(
|
|
1524
|
+
`cache read failed, continuing without persisted cache: ${error instanceof Error ? error.message : String(error)}`
|
|
1525
|
+
);
|
|
1526
|
+
}
|
|
1527
|
+
const cacheMap = new Map(cacheEntries.map((entry) => [entry.file, entry]));
|
|
1528
|
+
const nowMs = Date.now();
|
|
1529
|
+
const ranked = [];
|
|
1530
|
+
for (const filePath of candidates) {
|
|
1531
|
+
let stat;
|
|
1532
|
+
try {
|
|
1533
|
+
stat = fs3.statSync(filePath);
|
|
1534
|
+
} catch {
|
|
1535
|
+
continue;
|
|
1536
|
+
}
|
|
1537
|
+
const size = toCacheSize(stat.size);
|
|
1538
|
+
const cached = cacheMap.get(filePath);
|
|
1539
|
+
const priority = filePriority(
|
|
1540
|
+
stat.mtimeMs,
|
|
1541
|
+
size,
|
|
1542
|
+
cached ? {
|
|
1543
|
+
mtimeMs: cached.mtimeMs,
|
|
1544
|
+
size: cached.size,
|
|
1545
|
+
hitCount: cached.hitCount,
|
|
1546
|
+
lastSeenMs: 0
|
|
1547
|
+
} : void 0,
|
|
1548
|
+
nowMs
|
|
1549
|
+
);
|
|
1550
|
+
ranked.push({ filePath, stat, size, cached, priority });
|
|
1551
|
+
}
|
|
1552
|
+
ranked.sort((a, b) => b.priority - a.priority);
|
|
1553
|
+
const updatedEntries = [];
|
|
1554
|
+
for (const { filePath, stat, size, cached } of ranked) {
|
|
1555
|
+
let content;
|
|
1556
|
+
try {
|
|
1557
|
+
content = fs3.readFileSync(filePath, "utf8");
|
|
1558
|
+
} catch {
|
|
1559
|
+
continue;
|
|
1560
|
+
}
|
|
1561
|
+
const hash = hashContentNative(content);
|
|
1562
|
+
if (cached && cached.hash === hash && cached.mtimeMs === stat.mtimeMs && cached.size === size) {
|
|
1563
|
+
log2.debug(`cache HIT ${filePath}`);
|
|
1564
|
+
processResult({ file: filePath, classes: cached.classes });
|
|
1565
|
+
updatedEntries.push({
|
|
1566
|
+
file: filePath,
|
|
1567
|
+
classes: cached.classes,
|
|
1568
|
+
hash: cached.hash,
|
|
1569
|
+
mtimeMs: stat.mtimeMs,
|
|
1570
|
+
size,
|
|
1571
|
+
hitCount: (cached.hitCount ?? 0) + 1
|
|
1572
|
+
});
|
|
1573
|
+
continue;
|
|
1574
|
+
}
|
|
1575
|
+
log2.debug(`cache MISS ${filePath}`);
|
|
1576
|
+
const classes = scanSource(content);
|
|
1577
|
+
processResult({ file: filePath, classes });
|
|
1578
|
+
updatedEntries.push({
|
|
1579
|
+
file: filePath,
|
|
1580
|
+
classes,
|
|
1581
|
+
hash,
|
|
1582
|
+
mtimeMs: stat.mtimeMs,
|
|
1583
|
+
size,
|
|
1584
|
+
hitCount: 1
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
try {
|
|
1588
|
+
writeCache(rootDir, updatedEntries, options.cacheDir);
|
|
1589
|
+
} catch (error) {
|
|
1590
|
+
log2.debug(`cache write failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1591
|
+
}
|
|
1592
|
+
return {
|
|
1593
|
+
files,
|
|
1594
|
+
totalFiles: files.length,
|
|
1595
|
+
uniqueClasses: Array.from(unique).sort()
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
for (const filePath of candidates) {
|
|
1599
|
+
processResult(scanFile(filePath));
|
|
1600
|
+
}
|
|
1601
|
+
return {
|
|
1602
|
+
files,
|
|
1603
|
+
totalFiles: files.length,
|
|
1604
|
+
uniqueClasses: Array.from(unique).sort()
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
async function scanWorkspaceAsync(rootDir, options = {}) {
|
|
1608
|
+
if (process.env.TWS_DISABLE_SCANNER_WORKER === "1") {
|
|
1609
|
+
return scanWorkspace(rootDir, options);
|
|
1610
|
+
}
|
|
1611
|
+
try {
|
|
1612
|
+
return await scanWorkspaceInWorker(rootDir, options);
|
|
1613
|
+
} catch (error) {
|
|
1614
|
+
log2.debug(
|
|
1615
|
+
`worker scan failed, falling back to sync scanner: ${error instanceof Error ? error.message : String(error)}`
|
|
1616
|
+
);
|
|
1617
|
+
return scanWorkspace(rootDir, options);
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
var log2, SCAN_WORKER_TIMEOUT_MS, SCAN_WORKER_BOOTSTRAP, nativeParserBinding, nativeParserInitError, DEFAULT_EXTENSIONS, DEFAULT_IGNORES;
|
|
1621
|
+
var init_src3 = __esm({
|
|
1622
|
+
"packages/scanner/src/index.ts"() {
|
|
1623
|
+
init_src2();
|
|
1624
|
+
init_src();
|
|
1625
|
+
init_cache_native();
|
|
1626
|
+
init_native_bridge();
|
|
1627
|
+
log2 = createLogger("scanner");
|
|
1628
|
+
SCAN_WORKER_TIMEOUT_MS = 12e4;
|
|
1629
|
+
SCAN_WORKER_BOOTSTRAP = `
|
|
1630
|
+
const { parentPort, workerData } = require("node:worker_threads")
|
|
1631
|
+
try {
|
|
1632
|
+
const scanner = require(workerData.modulePath)
|
|
1633
|
+
const result = scanner.scanWorkspace(workerData.rootDir, workerData.options ?? {})
|
|
1634
|
+
parentPort.postMessage({ ok: true, result })
|
|
1635
|
+
} catch (error) {
|
|
1636
|
+
parentPort.postMessage({
|
|
1637
|
+
ok: false,
|
|
1638
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1639
|
+
})
|
|
1640
|
+
}
|
|
1641
|
+
`;
|
|
1642
|
+
nativeParserInitError = null;
|
|
1643
|
+
DEFAULT_EXTENSIONS = [".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1644
|
+
DEFAULT_IGNORES = ["node_modules", ".git", ".next", "dist", "out", ".turbo", ".cache"];
|
|
1645
|
+
}
|
|
1646
|
+
});
|
|
1647
|
+
function formatErrorMessage2(error) {
|
|
1648
|
+
return error instanceof Error ? error.message : String(error);
|
|
1649
|
+
}
|
|
1650
|
+
function isRecord(value) {
|
|
1651
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1652
|
+
const proto = Object.getPrototypeOf(value);
|
|
1653
|
+
return proto === Object.prototype || proto === null;
|
|
1654
|
+
}
|
|
1655
|
+
async function pathExists(filePath) {
|
|
1656
|
+
try {
|
|
1657
|
+
await fs3.promises.access(filePath, fs3.constants.F_OK);
|
|
1658
|
+
return true;
|
|
1659
|
+
} catch {
|
|
1660
|
+
return false;
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
function sanitizeTopLimit(value) {
|
|
1664
|
+
if (!Number.isFinite(value)) return DEFAULT_TOP_LIMIT;
|
|
1665
|
+
return Math.max(1, Math.trunc(value));
|
|
1666
|
+
}
|
|
1667
|
+
function sanitizeFrequentThreshold(value) {
|
|
1668
|
+
if (!Number.isFinite(value)) return DEFAULT_FREQUENT_THRESHOLD;
|
|
1669
|
+
return Math.max(1, Math.trunc(value));
|
|
1670
|
+
}
|
|
1671
|
+
var DEFAULT_TOP_LIMIT, DEFAULT_FREQUENT_THRESHOLD, DEBUG_NAMESPACE, debugLog;
|
|
1672
|
+
var init_utils = __esm({
|
|
1673
|
+
"packages/analyzer/src/utils.ts"() {
|
|
1674
|
+
init_src();
|
|
1675
|
+
DEFAULT_TOP_LIMIT = 10;
|
|
1676
|
+
DEFAULT_FREQUENT_THRESHOLD = 2;
|
|
1677
|
+
DEBUG_NAMESPACE = "tailwind-styled:analyzer";
|
|
1678
|
+
debugLog = createDebugLogger(DEBUG_NAMESPACE, "tailwind-styled/analyzer");
|
|
1679
|
+
}
|
|
1680
|
+
});
|
|
1681
|
+
|
|
1682
|
+
// packages/analyzer/src/binding.ts
|
|
1683
|
+
function isAnalyzerModule(module2) {
|
|
1684
|
+
const candidate = module2;
|
|
1685
|
+
return typeof candidate?.analyzeClasses === "function";
|
|
1686
|
+
}
|
|
1687
|
+
function getNativeBinding() {
|
|
1688
|
+
if (bindingCache !== void 0) return bindingCache;
|
|
1689
|
+
if (process.env.TWS_NO_NATIVE === "1" || process.env.TWS_NO_RUST === "1") {
|
|
1690
|
+
bindingCandidateCache = [];
|
|
1691
|
+
bindingLoadErrorsCache = [];
|
|
1692
|
+
loadedBindingPathCache = null;
|
|
1693
|
+
debugLog("native binding disabled by TWS_NO_NATIVE/TWS_NO_RUST");
|
|
1694
|
+
bindingCache = null;
|
|
1695
|
+
return bindingCache;
|
|
1696
|
+
}
|
|
1697
|
+
const runtimeDir2 = resolveRuntimeDir(
|
|
1698
|
+
typeof __dirname === "string" ? __dirname : void 0,
|
|
1699
|
+
import.meta.url
|
|
1700
|
+
);
|
|
1701
|
+
const candidates = resolveNativeBindingCandidates({
|
|
1702
|
+
runtimeDir: runtimeDir2,
|
|
1703
|
+
envVarNames: ["TWS_NATIVE_PATH"]
|
|
1704
|
+
});
|
|
1705
|
+
const { binding, loadErrors, loadedPath } = loadNativeBinding({
|
|
1706
|
+
runtimeDir: runtimeDir2,
|
|
1707
|
+
candidates,
|
|
1708
|
+
isValid: isAnalyzerModule,
|
|
1709
|
+
invalidExportMessage: "Module loaded but missing `analyzeClasses` export."
|
|
1710
|
+
});
|
|
1711
|
+
bindingCandidateCache = candidates;
|
|
1712
|
+
bindingLoadErrorsCache = loadErrors;
|
|
1713
|
+
loadedBindingPathCache = loadedPath;
|
|
1714
|
+
if (binding) {
|
|
1715
|
+
debugLog(`native binding loaded from: ${loadedPath}`);
|
|
1716
|
+
bindingCache = binding;
|
|
1717
|
+
return bindingCache;
|
|
1718
|
+
}
|
|
1719
|
+
if (bindingLoadErrorsCache.length > 0) {
|
|
1720
|
+
debugLog(
|
|
1721
|
+
`native binding load failed for ${bindingLoadErrorsCache.length} candidate(s): ${bindingLoadErrorsCache.map((entry) => `${entry.path} (${entry.message})`).join("; ")}`
|
|
1722
|
+
);
|
|
1723
|
+
} else {
|
|
1724
|
+
debugLog("native binding not found in any candidate path");
|
|
1725
|
+
}
|
|
1726
|
+
bindingCache = null;
|
|
1727
|
+
return bindingCache;
|
|
1728
|
+
}
|
|
1729
|
+
function requireNativeBinding() {
|
|
1730
|
+
const binding = getNativeBinding();
|
|
1731
|
+
if (binding?.analyzeClasses) return binding;
|
|
1732
|
+
const lines = [
|
|
1733
|
+
"Native analyzer binding not found. Ensure `tailwind_styled_parser.node` is built."
|
|
1734
|
+
];
|
|
1735
|
+
if (process.env.TWS_NO_NATIVE === "1" || process.env.TWS_NO_RUST === "1") {
|
|
1736
|
+
lines.push("Native loading is disabled by TWS_NO_NATIVE/TWS_NO_RUST.");
|
|
1737
|
+
} else {
|
|
1738
|
+
lines.push("Checked paths:");
|
|
1739
|
+
for (const candidate of bindingCandidateCache) lines.push(`- ${candidate}`);
|
|
1740
|
+
if (bindingLoadErrorsCache.length > 0) {
|
|
1741
|
+
lines.push("Load errors:");
|
|
1742
|
+
for (const failure of bindingLoadErrorsCache) {
|
|
1743
|
+
lines.push(`- ${failure.path}: ${failure.message}`);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
throw new Error(lines.join("\n"));
|
|
1748
|
+
}
|
|
1749
|
+
function requireNativeCssCompiler() {
|
|
1750
|
+
const binding = requireNativeBinding();
|
|
1751
|
+
if (typeof binding.compileCss === "function") return binding;
|
|
1752
|
+
const loadedPathText = loadedBindingPathCache ? ` (${loadedBindingPathCache})` : "";
|
|
1753
|
+
throw new Error(`Native analyzer compileCss binding is missing in v5${loadedPathText}.`);
|
|
1754
|
+
}
|
|
1755
|
+
var bindingCache, bindingCandidateCache, bindingLoadErrorsCache, loadedBindingPathCache;
|
|
1756
|
+
var init_binding = __esm({
|
|
1757
|
+
"packages/analyzer/src/binding.ts"() {
|
|
1758
|
+
init_src();
|
|
1759
|
+
init_utils();
|
|
1760
|
+
bindingCandidateCache = [];
|
|
1761
|
+
bindingLoadErrorsCache = [];
|
|
1762
|
+
loadedBindingPathCache = null;
|
|
1763
|
+
}
|
|
1764
|
+
});
|
|
1765
|
+
function splitVariantAndBase(className) {
|
|
1766
|
+
const parts = className.split(":");
|
|
1767
|
+
if (parts.length <= 1) return { variantKey: "", base: className };
|
|
1768
|
+
const base = parts.pop() ?? className;
|
|
1769
|
+
return { variantKey: parts.join(":"), base };
|
|
1770
|
+
}
|
|
1771
|
+
function isArbitraryUtility(baseClass) {
|
|
1772
|
+
return baseClass.includes("[") && baseClass.includes("]");
|
|
1773
|
+
}
|
|
1774
|
+
function resolveConflictGroup(base) {
|
|
1775
|
+
if (isArbitraryUtility(base)) return null;
|
|
1776
|
+
if (["block", "inline", "inline-block", "inline-flex", "flex", "grid", "hidden"].includes(base))
|
|
1777
|
+
return "display";
|
|
1778
|
+
if (base.startsWith("bg-")) return "bg";
|
|
1779
|
+
if (base.startsWith("text-")) return "text";
|
|
1780
|
+
if (base.startsWith("font-")) return "font";
|
|
1781
|
+
if (base.startsWith("rounded")) return "rounded";
|
|
1782
|
+
if (base.startsWith("shadow")) return "shadow";
|
|
1783
|
+
if (base.startsWith("border-")) return "border";
|
|
1784
|
+
if (base.startsWith("opacity-")) return "opacity";
|
|
1785
|
+
if (base.startsWith("w-") || base.startsWith("min-w-") || base.startsWith("max-w-"))
|
|
1786
|
+
return "width";
|
|
1787
|
+
if (base.startsWith("h-") || base.startsWith("min-h-") || base.startsWith("max-h-"))
|
|
1788
|
+
return "height";
|
|
1789
|
+
if (base.startsWith("p-") || base.startsWith("px-") || base.startsWith("py-")) return "padding";
|
|
1790
|
+
if (base.startsWith("m-") || base.startsWith("mx-") || base.startsWith("my-")) return "margin";
|
|
1791
|
+
return null;
|
|
1792
|
+
}
|
|
1793
|
+
function detectConflicts(usages) {
|
|
1794
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
1795
|
+
for (const usage of usages) {
|
|
1796
|
+
const { variantKey, base } = splitVariantAndBase(usage.name);
|
|
1797
|
+
const group = resolveConflictGroup(base);
|
|
1798
|
+
if (!group) continue;
|
|
1799
|
+
const key = `${variantKey}::${group}`;
|
|
1800
|
+
const bucket = buckets.get(key) ?? {
|
|
1801
|
+
variantKey,
|
|
1802
|
+
group,
|
|
1803
|
+
classes: /* @__PURE__ */ new Set()
|
|
1804
|
+
};
|
|
1805
|
+
bucket.classes.add(usage.name);
|
|
1806
|
+
buckets.set(key, bucket);
|
|
1807
|
+
}
|
|
1808
|
+
const conflicts = [];
|
|
1809
|
+
const conflictedClassNames = /* @__PURE__ */ new Set();
|
|
1810
|
+
for (const bucket of buckets.values()) {
|
|
1811
|
+
if (bucket.classes.size <= 1) continue;
|
|
1812
|
+
const classes = Array.from(bucket.classes).sort();
|
|
1813
|
+
for (const className of classes) conflictedClassNames.add(className);
|
|
1814
|
+
const variantLabel = bucket.variantKey.length > 0 ? bucket.variantKey : "base";
|
|
1815
|
+
conflicts.push({
|
|
1816
|
+
className: bucket.group,
|
|
1817
|
+
variants: bucket.variantKey.length > 0 ? bucket.variantKey.split(":") : [],
|
|
1818
|
+
classes,
|
|
1819
|
+
message: `Multiple ${bucket.group} utilities detected for "${variantLabel}".`
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
conflicts.sort((left, right) => {
|
|
1823
|
+
if (right.classes.length !== left.classes.length)
|
|
1824
|
+
return right.classes.length - left.classes.length;
|
|
1825
|
+
return left.className.localeCompare(right.className);
|
|
1826
|
+
});
|
|
1827
|
+
return { conflicts, conflictedClassNames };
|
|
1828
|
+
}
|
|
1829
|
+
function isSupportedTailwindConfigPath(configPath) {
|
|
1830
|
+
return SUPPORTED_TAILWIND_CONFIG_EXTENSIONS.has(path8.extname(configPath).toLowerCase());
|
|
1831
|
+
}
|
|
1832
|
+
async function resolveTailwindConfigPath(root, explicitPath) {
|
|
1833
|
+
if (explicitPath) {
|
|
1834
|
+
const resolved = path8.resolve(root, explicitPath);
|
|
1835
|
+
if (!await pathExists(resolved)) return null;
|
|
1836
|
+
return resolved;
|
|
1837
|
+
}
|
|
1838
|
+
const candidates = [
|
|
1839
|
+
"tailwind.config.ts",
|
|
1840
|
+
"tailwind.config.js",
|
|
1841
|
+
"tailwind.config.cjs",
|
|
1842
|
+
"tailwind.config.mjs"
|
|
1843
|
+
];
|
|
1844
|
+
for (const candidate of candidates) {
|
|
1845
|
+
const fullPath = path8.resolve(root, candidate);
|
|
1846
|
+
if (await pathExists(fullPath)) return fullPath;
|
|
1847
|
+
}
|
|
1848
|
+
return null;
|
|
1849
|
+
}
|
|
1850
|
+
function collectSafelistFromConfig(config) {
|
|
1851
|
+
const raw = config.safelist;
|
|
1852
|
+
if (!Array.isArray(raw)) return [];
|
|
1853
|
+
const out = /* @__PURE__ */ new Set();
|
|
1854
|
+
for (const entry of raw) {
|
|
1855
|
+
if (typeof entry === "string" && entry.length > 0) {
|
|
1856
|
+
out.add(entry);
|
|
1857
|
+
continue;
|
|
1858
|
+
}
|
|
1859
|
+
if (!entry || typeof entry !== "object") continue;
|
|
1860
|
+
const pattern = entry.pattern;
|
|
1861
|
+
if (typeof pattern === "string" && pattern.length > 0) {
|
|
1862
|
+
out.add(pattern);
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
return Array.from(out);
|
|
1866
|
+
}
|
|
1867
|
+
function collectCustomUtilities(config) {
|
|
1868
|
+
const out = /* @__PURE__ */ new Set();
|
|
1869
|
+
const theme = config.theme;
|
|
1870
|
+
if (!theme || typeof theme !== "object") return out;
|
|
1871
|
+
const extend = theme.extend;
|
|
1872
|
+
if (!extend || typeof extend !== "object") return out;
|
|
1873
|
+
for (const [section, value] of Object.entries(extend)) {
|
|
1874
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) continue;
|
|
1875
|
+
for (const key of Object.keys(value)) {
|
|
1876
|
+
out.add(`${section}-${key}`);
|
|
1877
|
+
if (section === "colors") {
|
|
1878
|
+
out.add(`bg-${key}`);
|
|
1879
|
+
out.add(`text-${key}`);
|
|
1880
|
+
out.add(`border-${key}`);
|
|
1881
|
+
} else if (section === "spacing") {
|
|
1882
|
+
out.add(`p-${key}`);
|
|
1883
|
+
out.add(`m-${key}`);
|
|
1884
|
+
out.add(`gap-${key}`);
|
|
1885
|
+
out.add(`w-${key}`);
|
|
1886
|
+
out.add(`h-${key}`);
|
|
1887
|
+
} else if (section === "fontSize") {
|
|
1888
|
+
out.add(`text-${key}`);
|
|
1889
|
+
} else if (section === "borderRadius") {
|
|
1890
|
+
out.add(`rounded-${key}`);
|
|
1891
|
+
} else if (section === "boxShadow") {
|
|
1892
|
+
out.add(`shadow-${key}`);
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
return out;
|
|
1897
|
+
}
|
|
1898
|
+
async function collectSafelistFromSource(configPath) {
|
|
1899
|
+
const source = await fs3.promises.readFile(configPath, "utf8");
|
|
1900
|
+
const safelistBlock = source.match(/safelist\s*:\s*\[([\s\S]*?)\]/m)?.[1];
|
|
1901
|
+
if (!safelistBlock) return [];
|
|
1902
|
+
const out = /* @__PURE__ */ new Set();
|
|
1903
|
+
const tokenRegex = /["'`]([^"'`]+)["'`]/g;
|
|
1904
|
+
let token = tokenRegex.exec(safelistBlock);
|
|
1905
|
+
while (token) {
|
|
1906
|
+
const value = token[1].trim();
|
|
1907
|
+
if (value.length > 0) out.add(value);
|
|
1908
|
+
token = tokenRegex.exec(safelistBlock);
|
|
1909
|
+
}
|
|
1910
|
+
return Array.from(out);
|
|
1911
|
+
}
|
|
1912
|
+
async function loadTailwindConfig2(root, semanticOption) {
|
|
1913
|
+
const startMs = Date.now();
|
|
1914
|
+
const configPath = await resolveTailwindConfigPath(root, semanticOption?.tailwindConfigPath);
|
|
1915
|
+
if (!configPath) return null;
|
|
1916
|
+
if (!isSupportedTailwindConfigPath(configPath)) {
|
|
1917
|
+
return {
|
|
1918
|
+
path: configPath,
|
|
1919
|
+
loaded: false,
|
|
1920
|
+
warning: `Unsupported Tailwind config extension at "${configPath}". Supported extensions: .ts, .js, .cjs, .mjs.`,
|
|
1921
|
+
safelist: /* @__PURE__ */ new Set(),
|
|
1922
|
+
customUtilities: /* @__PURE__ */ new Set()
|
|
1923
|
+
};
|
|
1924
|
+
}
|
|
1925
|
+
const configStat = await fs3.promises.stat(configPath).catch(() => null);
|
|
1926
|
+
if (configStat) {
|
|
1927
|
+
const cached = tailwindConfigCache.get(configPath);
|
|
1928
|
+
if (cached && cached.mtimeMs === configStat.mtimeMs && cached.size === configStat.size) {
|
|
1929
|
+
debugLog(
|
|
1930
|
+
`tailwind config cache hit: ${configPath} (${cached.config.safelist.size} safelist entries)`
|
|
1931
|
+
);
|
|
1932
|
+
return cached.config;
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
let config = null;
|
|
1936
|
+
let warning;
|
|
1937
|
+
try {
|
|
1938
|
+
const cacheBustToken = Math.trunc(configStat?.mtimeMs ?? Date.now());
|
|
1939
|
+
const imported = await import(`${pathToFileURL(configPath).href}?tws_mtime=${cacheBustToken}`);
|
|
1940
|
+
const candidate = imported.default ?? imported;
|
|
1941
|
+
if (isRecord(candidate)) {
|
|
1942
|
+
config = candidate;
|
|
1943
|
+
} else if (typeof candidate === "function") {
|
|
1944
|
+
const evaluated = candidate();
|
|
1945
|
+
if (isRecord(evaluated)) {
|
|
1946
|
+
config = evaluated;
|
|
1947
|
+
} else {
|
|
1948
|
+
warning = "Tailwind config export function must return an object.";
|
|
1949
|
+
}
|
|
1950
|
+
} else {
|
|
1951
|
+
warning = "Tailwind config export must be an object or a function returning an object.";
|
|
1952
|
+
}
|
|
1953
|
+
} catch (error) {
|
|
1954
|
+
warning = formatErrorMessage2(error);
|
|
1955
|
+
}
|
|
1956
|
+
const safelist = /* @__PURE__ */ new Set();
|
|
1957
|
+
const customUtilities = /* @__PURE__ */ new Set();
|
|
1958
|
+
if (config) {
|
|
1959
|
+
for (const item of collectSafelistFromConfig(config)) safelist.add(item);
|
|
1960
|
+
for (const item of collectCustomUtilities(config)) customUtilities.add(item);
|
|
1961
|
+
}
|
|
1962
|
+
if (safelist.size === 0) {
|
|
1963
|
+
try {
|
|
1964
|
+
for (const item of await collectSafelistFromSource(configPath)) safelist.add(item);
|
|
1965
|
+
} catch (error) {
|
|
1966
|
+
debugLog(
|
|
1967
|
+
`failed to parse safelist from source at "${configPath}": ${formatErrorMessage2(error)}`
|
|
1968
|
+
);
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
const loaded = {
|
|
1972
|
+
path: configPath,
|
|
1973
|
+
loaded: config !== null,
|
|
1974
|
+
warning,
|
|
1975
|
+
safelist,
|
|
1976
|
+
customUtilities
|
|
1977
|
+
};
|
|
1978
|
+
if (configStat) {
|
|
1979
|
+
tailwindConfigCache.set(configPath, {
|
|
1980
|
+
mtimeMs: configStat.mtimeMs,
|
|
1981
|
+
size: configStat.size,
|
|
1982
|
+
config: loaded
|
|
1983
|
+
});
|
|
1984
|
+
}
|
|
1985
|
+
debugLog(
|
|
1986
|
+
`tailwind config loaded from "${configPath}" in ${Date.now() - startMs}ms (loaded=${loaded.loaded}, safelist=${loaded.safelist.size}, custom=${loaded.customUtilities.size})`
|
|
1987
|
+
);
|
|
1988
|
+
return loaded;
|
|
1989
|
+
}
|
|
1990
|
+
function utilityPrefix(baseClass) {
|
|
1991
|
+
const normalized = baseClass.startsWith("-") ? baseClass.slice(1) : baseClass;
|
|
1992
|
+
if (normalized.includes("[") && normalized.includes("]")) return "arbitrary";
|
|
1993
|
+
if (normalized.startsWith("min-w-")) return "min-w";
|
|
1994
|
+
if (normalized.startsWith("max-w-")) return "max-w";
|
|
1995
|
+
if (normalized.startsWith("min-h-")) return "min-h";
|
|
1996
|
+
if (normalized.startsWith("max-h-")) return "max-h";
|
|
1997
|
+
if (normalized.startsWith("space-x-")) return "space-x";
|
|
1998
|
+
if (normalized.startsWith("space-y-")) return "space-y";
|
|
1999
|
+
if (normalized.startsWith("inline-")) return "inline";
|
|
2000
|
+
if (normalized.startsWith("border-")) return "border";
|
|
2001
|
+
if (normalized.startsWith("text-")) return "text";
|
|
2002
|
+
if (normalized.startsWith("bg-")) return "bg";
|
|
2003
|
+
if (normalized.startsWith("rounded")) return "rounded";
|
|
2004
|
+
if (normalized.startsWith("shadow")) return "shadow";
|
|
2005
|
+
const hyphen = normalized.indexOf("-");
|
|
2006
|
+
if (hyphen < 0) return normalized;
|
|
2007
|
+
return normalized.slice(0, hyphen);
|
|
2008
|
+
}
|
|
2009
|
+
function isKnownTailwindClass(className, safelist, customUtilities) {
|
|
2010
|
+
if (safelist.has(className) || customUtilities.has(className)) return true;
|
|
2011
|
+
const { base } = splitVariantAndBase(className);
|
|
2012
|
+
if (customUtilities.has(base)) return true;
|
|
2013
|
+
const prefix = utilityPrefix(base);
|
|
2014
|
+
return KNOWN_UTILITY_PREFIXES.has(prefix);
|
|
2015
|
+
}
|
|
2016
|
+
async function buildSemanticReport(usages, root, semanticOption) {
|
|
2017
|
+
const loadedConfig = await loadTailwindConfig2(root, semanticOption);
|
|
2018
|
+
const safelist = loadedConfig?.safelist ?? /* @__PURE__ */ new Set();
|
|
2019
|
+
const customUtilities = loadedConfig?.customUtilities ?? /* @__PURE__ */ new Set();
|
|
2020
|
+
const usageNames = new Set(usages.map((usage) => usage.name));
|
|
2021
|
+
const unusedClasses = Array.from(safelist).filter((className) => !usageNames.has(className)).sort().map((className) => ({ name: className, count: 0, isUnused: true }));
|
|
2022
|
+
const unknownClasses = usages.filter((usage) => !isKnownTailwindClass(usage.name, safelist, customUtilities)).map((usage) => ({ ...usage, isUnused: true }));
|
|
2023
|
+
const { conflicts } = detectConflicts(usages);
|
|
2024
|
+
return {
|
|
2025
|
+
unusedClasses,
|
|
2026
|
+
unknownClasses,
|
|
2027
|
+
conflicts,
|
|
2028
|
+
...loadedConfig ? {
|
|
2029
|
+
tailwindConfig: {
|
|
2030
|
+
path: loadedConfig.path,
|
|
2031
|
+
loaded: loadedConfig.loaded,
|
|
2032
|
+
safelistCount: loadedConfig.safelist.size,
|
|
2033
|
+
customUtilityCount: loadedConfig.customUtilities.size,
|
|
2034
|
+
...loadedConfig.warning ? { warning: loadedConfig.warning } : {}
|
|
2035
|
+
}
|
|
2036
|
+
} : {}
|
|
2037
|
+
};
|
|
2038
|
+
}
|
|
2039
|
+
var SUPPORTED_TAILWIND_CONFIG_EXTENSIONS, KNOWN_UTILITY_PREFIXES, tailwindConfigCache;
|
|
2040
|
+
var init_semantic = __esm({
|
|
2041
|
+
"packages/analyzer/src/semantic.ts"() {
|
|
2042
|
+
init_utils();
|
|
2043
|
+
SUPPORTED_TAILWIND_CONFIG_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".js", ".cjs", ".mjs"]);
|
|
2044
|
+
KNOWN_UTILITY_PREFIXES = /* @__PURE__ */ new Set([
|
|
2045
|
+
"absolute",
|
|
2046
|
+
"align",
|
|
2047
|
+
"animate",
|
|
2048
|
+
"arbitrary",
|
|
2049
|
+
"aspect",
|
|
2050
|
+
"backdrop",
|
|
2051
|
+
"basis",
|
|
2052
|
+
"bg",
|
|
2053
|
+
"block",
|
|
2054
|
+
"border",
|
|
2055
|
+
"bottom",
|
|
2056
|
+
"col",
|
|
2057
|
+
"container",
|
|
2058
|
+
"contents",
|
|
2059
|
+
"cursor",
|
|
2060
|
+
"dark",
|
|
2061
|
+
"display",
|
|
2062
|
+
"divide",
|
|
2063
|
+
"fill",
|
|
2064
|
+
"fixed",
|
|
2065
|
+
"flex",
|
|
2066
|
+
"float",
|
|
2067
|
+
"font",
|
|
2068
|
+
"from",
|
|
2069
|
+
"gap",
|
|
2070
|
+
"grid",
|
|
2071
|
+
"grow",
|
|
2072
|
+
"h",
|
|
2073
|
+
"hidden",
|
|
2074
|
+
"inset",
|
|
2075
|
+
"inline",
|
|
2076
|
+
"isolate",
|
|
2077
|
+
"items",
|
|
2078
|
+
"justify",
|
|
2079
|
+
"left",
|
|
2080
|
+
"leading",
|
|
2081
|
+
"line",
|
|
2082
|
+
"list",
|
|
2083
|
+
"m",
|
|
2084
|
+
"max-h",
|
|
2085
|
+
"max-w",
|
|
2086
|
+
"mb",
|
|
2087
|
+
"min-h",
|
|
2088
|
+
"min-w",
|
|
2089
|
+
"ml",
|
|
2090
|
+
"mr",
|
|
2091
|
+
"mt",
|
|
2092
|
+
"mx",
|
|
2093
|
+
"my",
|
|
2094
|
+
"object",
|
|
2095
|
+
"opacity",
|
|
2096
|
+
"order",
|
|
2097
|
+
"origin",
|
|
2098
|
+
"outline",
|
|
2099
|
+
"overflow",
|
|
2100
|
+
"overscroll",
|
|
2101
|
+
"p",
|
|
2102
|
+
"pb",
|
|
2103
|
+
"pe",
|
|
2104
|
+
"perspective",
|
|
2105
|
+
"place",
|
|
2106
|
+
"pl",
|
|
2107
|
+
"pointer",
|
|
2108
|
+
"position",
|
|
2109
|
+
"pr",
|
|
2110
|
+
"ps",
|
|
2111
|
+
"pt",
|
|
2112
|
+
"px",
|
|
2113
|
+
"py",
|
|
2114
|
+
"relative",
|
|
2115
|
+
"right",
|
|
2116
|
+
"ring",
|
|
2117
|
+
"rotate",
|
|
2118
|
+
"rounded",
|
|
2119
|
+
"row",
|
|
2120
|
+
"scale",
|
|
2121
|
+
"shadow",
|
|
2122
|
+
"shrink",
|
|
2123
|
+
"size",
|
|
2124
|
+
"skew",
|
|
2125
|
+
"snap",
|
|
2126
|
+
"space-x",
|
|
2127
|
+
"space-y",
|
|
2128
|
+
"sr",
|
|
2129
|
+
"start",
|
|
2130
|
+
"static",
|
|
2131
|
+
"sticky",
|
|
2132
|
+
"stroke",
|
|
2133
|
+
"table",
|
|
2134
|
+
"text",
|
|
2135
|
+
"to",
|
|
2136
|
+
"top",
|
|
2137
|
+
"touch",
|
|
2138
|
+
"tracking",
|
|
2139
|
+
"transform",
|
|
2140
|
+
"transition",
|
|
2141
|
+
"translate",
|
|
2142
|
+
"truncate",
|
|
2143
|
+
"underline",
|
|
2144
|
+
"via",
|
|
2145
|
+
"visible",
|
|
2146
|
+
"w",
|
|
2147
|
+
"whitespace",
|
|
2148
|
+
"z"
|
|
2149
|
+
]);
|
|
2150
|
+
tailwindConfigCache = /* @__PURE__ */ new Map();
|
|
2151
|
+
}
|
|
2152
|
+
});
|
|
2153
|
+
function normalizeScan(scan, includeClass) {
|
|
2154
|
+
if (!includeClass) return scan;
|
|
2155
|
+
const filteredFiles = scan.files.map((file) => ({
|
|
2156
|
+
file: file.file,
|
|
2157
|
+
classes: file.classes.filter((className) => includeClass(className))
|
|
2158
|
+
}));
|
|
2159
|
+
const unique = /* @__PURE__ */ new Set();
|
|
2160
|
+
for (const file of filteredFiles) {
|
|
2161
|
+
for (const className of file.classes) unique.add(className);
|
|
2162
|
+
}
|
|
2163
|
+
return {
|
|
2164
|
+
files: filteredFiles,
|
|
2165
|
+
totalFiles: scan.totalFiles,
|
|
2166
|
+
uniqueClasses: Array.from(unique).sort()
|
|
2167
|
+
};
|
|
2168
|
+
}
|
|
2169
|
+
function collectClassCounts(scan) {
|
|
2170
|
+
const counts = /* @__PURE__ */ new Map();
|
|
2171
|
+
for (const file of scan.files) {
|
|
2172
|
+
for (const className of file.classes) {
|
|
2173
|
+
counts.set(className, (counts.get(className) ?? 0) + 1);
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
return counts;
|
|
2177
|
+
}
|
|
2178
|
+
function buildClassUsage(counts) {
|
|
2179
|
+
return Array.from(counts.entries()).map(([name, count]) => ({ name, count })).sort((left, right) => {
|
|
2180
|
+
if (right.count !== left.count) return right.count - left.count;
|
|
2181
|
+
return left.name.localeCompare(right.name);
|
|
2182
|
+
});
|
|
2183
|
+
}
|
|
2184
|
+
function buildDistribution(usages) {
|
|
2185
|
+
const distribution = {
|
|
2186
|
+
"1": 0,
|
|
2187
|
+
"2-3": 0,
|
|
2188
|
+
"4-7": 0,
|
|
2189
|
+
"8+": 0
|
|
2190
|
+
};
|
|
2191
|
+
for (const usage of usages) {
|
|
2192
|
+
if (usage.count === 1) {
|
|
2193
|
+
distribution["1"] += 1;
|
|
2194
|
+
continue;
|
|
2195
|
+
}
|
|
2196
|
+
if (usage.count <= 3) {
|
|
2197
|
+
distribution["2-3"] += 1;
|
|
2198
|
+
continue;
|
|
2199
|
+
}
|
|
2200
|
+
if (usage.count <= 7) {
|
|
2201
|
+
distribution["4-7"] += 1;
|
|
2202
|
+
continue;
|
|
2203
|
+
}
|
|
2204
|
+
distribution["8+"] += 1;
|
|
2205
|
+
}
|
|
2206
|
+
return distribution;
|
|
2207
|
+
}
|
|
2208
|
+
async function analyzeWorkspace(root, options = {}) {
|
|
2209
|
+
const startedAtMs = Date.now();
|
|
2210
|
+
const resolvedRoot = path8.resolve(root);
|
|
2211
|
+
const scanStartedAtMs = Date.now();
|
|
2212
|
+
let scan;
|
|
2213
|
+
try {
|
|
2214
|
+
scan = await scanWorkspaceAsync(resolvedRoot, options.scanner);
|
|
2215
|
+
} catch (error) {
|
|
2216
|
+
throw new Error(`Failed to scan workspace at "${resolvedRoot}": ${formatErrorMessage2(error)}`, {
|
|
2217
|
+
cause: error
|
|
2218
|
+
});
|
|
2219
|
+
}
|
|
2220
|
+
debugLog(
|
|
2221
|
+
`scanWorkspaceAsync processed ${scan.totalFiles} files in ${Date.now() - scanStartedAtMs}ms`
|
|
2222
|
+
);
|
|
2223
|
+
const normalizedScan = normalizeScan(scan, options.includeClass);
|
|
2224
|
+
const topLimit = sanitizeTopLimit(options.classStats?.top);
|
|
2225
|
+
const frequentThreshold = sanitizeFrequentThreshold(options.classStats?.frequentThreshold);
|
|
2226
|
+
const binding = requireNativeBinding();
|
|
2227
|
+
const filesJson = JSON.stringify(
|
|
2228
|
+
normalizedScan.files.map((file) => ({ file: file.file, classes: file.classes }))
|
|
2229
|
+
);
|
|
2230
|
+
let nativeReport = null;
|
|
2231
|
+
try {
|
|
2232
|
+
nativeReport = binding.analyzeClasses(filesJson, resolvedRoot, topLimit);
|
|
2233
|
+
} catch (error) {
|
|
2234
|
+
throw new Error(`Native analyzer failed for "${resolvedRoot}": ${formatErrorMessage2(error)}`, {
|
|
2235
|
+
cause: error
|
|
2236
|
+
});
|
|
2237
|
+
}
|
|
2238
|
+
if (!nativeReport) {
|
|
2239
|
+
throw new Error(`Native analyzer returned no report for "${resolvedRoot}".`);
|
|
2240
|
+
}
|
|
2241
|
+
const counts = collectClassCounts(normalizedScan);
|
|
2242
|
+
let all = buildClassUsage(counts);
|
|
2243
|
+
let semanticReport;
|
|
2244
|
+
if (options.semantic) {
|
|
2245
|
+
const semanticOption = typeof options.semantic === "object" ? options.semantic : void 0;
|
|
2246
|
+
const semanticStartedAtMs = Date.now();
|
|
2247
|
+
try {
|
|
2248
|
+
semanticReport = await buildSemanticReport(all, resolvedRoot, semanticOption);
|
|
2249
|
+
} catch (error) {
|
|
2250
|
+
throw new Error(
|
|
2251
|
+
`Failed to build semantic report for "${resolvedRoot}": ${formatErrorMessage2(error)}`,
|
|
2252
|
+
{ cause: error }
|
|
2253
|
+
);
|
|
2254
|
+
}
|
|
2255
|
+
debugLog(`semantic report built in ${Date.now() - semanticStartedAtMs}ms`);
|
|
2256
|
+
if (semanticReport.conflicts.length > 0) {
|
|
2257
|
+
const conflicted = new Set(semanticReport.conflicts.flatMap((conflict) => conflict.classes));
|
|
2258
|
+
all = all.map(
|
|
2259
|
+
(usage) => conflicted.has(usage.name) ? { ...usage, isConflict: true } : usage
|
|
2260
|
+
);
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
const top = all.slice(0, topLimit);
|
|
2264
|
+
const frequent = all.filter((usage) => usage.count >= frequentThreshold).slice(0, topLimit);
|
|
2265
|
+
const unique = all.filter((usage) => usage.count === 1);
|
|
2266
|
+
const totalClassOccurrences = all.reduce((sum, usage) => sum + usage.count, 0);
|
|
2267
|
+
debugLog(
|
|
2268
|
+
`analyzeWorkspace completed in ${Date.now() - startedAtMs}ms (files=${normalizedScan.totalFiles}, uniqueClasses=${all.length})`
|
|
2269
|
+
);
|
|
2270
|
+
return {
|
|
2271
|
+
root: nativeReport.root || resolvedRoot,
|
|
2272
|
+
totalFiles: nativeReport.totalFiles,
|
|
2273
|
+
uniqueClassCount: all.length,
|
|
2274
|
+
totalClassOccurrences,
|
|
2275
|
+
classStats: {
|
|
2276
|
+
all,
|
|
2277
|
+
top,
|
|
2278
|
+
frequent,
|
|
2279
|
+
unique,
|
|
2280
|
+
distribution: buildDistribution(all)
|
|
2281
|
+
},
|
|
2282
|
+
safelist: all.map((usage) => usage.name),
|
|
2283
|
+
...semanticReport ? { semantic: semanticReport } : {}
|
|
2284
|
+
};
|
|
2285
|
+
}
|
|
2286
|
+
var init_analyzeWorkspace = __esm({
|
|
2287
|
+
"packages/analyzer/src/analyzeWorkspace.ts"() {
|
|
2288
|
+
init_src3();
|
|
2289
|
+
init_binding();
|
|
2290
|
+
init_semantic();
|
|
2291
|
+
init_utils();
|
|
2292
|
+
}
|
|
2293
|
+
});
|
|
2294
|
+
|
|
2295
|
+
// packages/analyzer/src/classToCss.ts
|
|
2296
|
+
function normalizeClassInput(input) {
|
|
2297
|
+
if (typeof input === "string") {
|
|
2298
|
+
return input.split(/\s+/).map((item) => item.trim()).filter((item) => item.length > 0);
|
|
2299
|
+
}
|
|
2300
|
+
if (!Array.isArray(input)) {
|
|
2301
|
+
throw new TypeError("classToCss input must be a string or an array of strings.");
|
|
2302
|
+
}
|
|
2303
|
+
const out = [];
|
|
2304
|
+
for (const item of input) {
|
|
2305
|
+
if (typeof item !== "string") {
|
|
2306
|
+
throw new TypeError("classToCss input array must contain only strings.");
|
|
2307
|
+
}
|
|
2308
|
+
const value = item.trim();
|
|
2309
|
+
if (value.length > 0) out.push(value);
|
|
2310
|
+
}
|
|
2311
|
+
return out;
|
|
2312
|
+
}
|
|
2313
|
+
function normalizeClassToCssOptions(options) {
|
|
2314
|
+
if (!options || typeof options !== "object" || Array.isArray(options)) {
|
|
2315
|
+
throw new TypeError("classToCss options must be an object.");
|
|
2316
|
+
}
|
|
2317
|
+
const strict = options.strict ?? false;
|
|
2318
|
+
if (typeof strict !== "boolean") {
|
|
2319
|
+
throw new TypeError("classToCss options.strict must be a boolean when provided.");
|
|
2320
|
+
}
|
|
2321
|
+
const prefix = options.prefix ?? null;
|
|
2322
|
+
if (prefix !== null && typeof prefix !== "string") {
|
|
2323
|
+
throw new TypeError("classToCss options.prefix must be a string or null when provided.");
|
|
2324
|
+
}
|
|
2325
|
+
return { prefix, strict };
|
|
2326
|
+
}
|
|
2327
|
+
function mergeDeclarationMap(target, css) {
|
|
2328
|
+
const ruleRegex = /\{([^}]*)\}/g;
|
|
2329
|
+
let ruleMatch = ruleRegex.exec(css);
|
|
2330
|
+
while (ruleMatch) {
|
|
2331
|
+
const body = ruleMatch[1];
|
|
2332
|
+
for (const raw of body.split(";")) {
|
|
2333
|
+
const declaration = raw.trim();
|
|
2334
|
+
if (declaration.length === 0) continue;
|
|
2335
|
+
const colonIndex = declaration.indexOf(":");
|
|
2336
|
+
if (colonIndex <= 0) continue;
|
|
2337
|
+
const property = declaration.slice(0, colonIndex).trim();
|
|
2338
|
+
const value = declaration.slice(colonIndex + 1).trim();
|
|
2339
|
+
if (property.length === 0 || value.length === 0) continue;
|
|
2340
|
+
if (target.has(property)) target.delete(property);
|
|
2341
|
+
target.set(property, value);
|
|
2342
|
+
}
|
|
2343
|
+
ruleMatch = ruleRegex.exec(css);
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
function declarationMapToString(declarationMap) {
|
|
2347
|
+
return Array.from(declarationMap.entries()).map(([property, value]) => `${property}: ${value}`).join("; ");
|
|
2348
|
+
}
|
|
2349
|
+
async function classToCss(input, options = {}) {
|
|
2350
|
+
const inputClasses = normalizeClassInput(input);
|
|
2351
|
+
const normalizedOptions = normalizeClassToCssOptions(options);
|
|
2352
|
+
if (inputClasses.length === 0) {
|
|
2353
|
+
return {
|
|
2354
|
+
inputClasses: [],
|
|
2355
|
+
css: "",
|
|
2356
|
+
declarations: "",
|
|
2357
|
+
resolvedClasses: [],
|
|
2358
|
+
unknownClasses: [],
|
|
2359
|
+
sizeBytes: 0
|
|
2360
|
+
};
|
|
2361
|
+
}
|
|
2362
|
+
const binding = requireNativeCssCompiler();
|
|
2363
|
+
const prefix = normalizedOptions.prefix;
|
|
2364
|
+
const cssChunks = [];
|
|
2365
|
+
const resolvedClasses = [];
|
|
2366
|
+
const unknownClasses = [];
|
|
2367
|
+
let sizeBytes = 0;
|
|
2368
|
+
const declarationMap = /* @__PURE__ */ new Map();
|
|
2369
|
+
for (const className of inputClasses) {
|
|
2370
|
+
let compiled = null;
|
|
2371
|
+
try {
|
|
2372
|
+
compiled = binding.compileCss([className], prefix);
|
|
2373
|
+
} catch (error) {
|
|
2374
|
+
throw new Error(
|
|
2375
|
+
`Native analyzer failed while compiling class "${className}": ${formatErrorMessage2(error)}`,
|
|
2376
|
+
{ cause: error }
|
|
2377
|
+
);
|
|
2378
|
+
}
|
|
2379
|
+
if (!compiled) {
|
|
2380
|
+
throw new Error(`Native analyzer returned no result for class "${className}".`);
|
|
2381
|
+
}
|
|
2382
|
+
cssChunks.push(compiled.css);
|
|
2383
|
+
resolvedClasses.push(...compiled.resolvedClasses);
|
|
2384
|
+
unknownClasses.push(...compiled.unknownClasses);
|
|
2385
|
+
sizeBytes += compiled.sizeBytes;
|
|
2386
|
+
mergeDeclarationMap(declarationMap, compiled.css);
|
|
2387
|
+
}
|
|
2388
|
+
const uniqueUnknown = Array.from(new Set(unknownClasses));
|
|
2389
|
+
if (normalizedOptions.strict && uniqueUnknown.length > 0) {
|
|
2390
|
+
throw new Error(`Unknown Tailwind classes: ${uniqueUnknown.join(", ")}`);
|
|
2391
|
+
}
|
|
2392
|
+
return {
|
|
2393
|
+
inputClasses,
|
|
2394
|
+
css: cssChunks.filter((chunk) => chunk.length > 0).join("\n"),
|
|
2395
|
+
declarations: declarationMapToString(declarationMap),
|
|
2396
|
+
resolvedClasses: Array.from(new Set(resolvedClasses)),
|
|
2397
|
+
unknownClasses: uniqueUnknown,
|
|
2398
|
+
sizeBytes
|
|
2399
|
+
};
|
|
2400
|
+
}
|
|
2401
|
+
var init_classToCss = __esm({
|
|
2402
|
+
"packages/analyzer/src/classToCss.ts"() {
|
|
2403
|
+
init_binding();
|
|
2404
|
+
init_utils();
|
|
2405
|
+
}
|
|
2406
|
+
});
|
|
2407
|
+
|
|
2408
|
+
// packages/analyzer/src/index.ts
|
|
2409
|
+
var src_exports = {};
|
|
2410
|
+
__export(src_exports, {
|
|
2411
|
+
__internal: () => __internal,
|
|
2412
|
+
analyzeWorkspace: () => analyzeWorkspace,
|
|
2413
|
+
classToCss: () => classToCss
|
|
2414
|
+
});
|
|
2415
|
+
var __internal;
|
|
2416
|
+
var init_src4 = __esm({
|
|
2417
|
+
"packages/analyzer/src/index.ts"() {
|
|
2418
|
+
init_analyzeWorkspace();
|
|
2419
|
+
init_classToCss();
|
|
2420
|
+
init_semantic();
|
|
2421
|
+
__internal = {
|
|
2422
|
+
normalizeClassInput,
|
|
2423
|
+
splitVariantAndBase,
|
|
2424
|
+
resolveConflictGroup,
|
|
2425
|
+
collectClassCounts,
|
|
2426
|
+
buildDistribution,
|
|
2427
|
+
utilityPrefix
|
|
2428
|
+
};
|
|
2429
|
+
}
|
|
2430
|
+
});
|
|
2431
|
+
|
|
2432
|
+
// packages/engine/src/index.ts
|
|
2433
|
+
init_src2();
|
|
2434
|
+
init_src3();
|
|
2435
|
+
init_src();
|
|
2436
|
+
|
|
2437
|
+
// packages/engine/src/incremental.ts
|
|
2438
|
+
init_src3();
|
|
2439
|
+
init_src();
|
|
2440
|
+
var _binding3 = void 0;
|
|
2441
|
+
var _loadError2 = null;
|
|
2442
|
+
var _candidatePaths2 = [];
|
|
2443
|
+
function getNativeEngineBinding() {
|
|
2444
|
+
if (_binding3 !== void 0) {
|
|
2445
|
+
if (_binding3 === null) {
|
|
2446
|
+
throwNativeBindingError2();
|
|
2447
|
+
}
|
|
2448
|
+
return _binding3;
|
|
2449
|
+
}
|
|
2450
|
+
if (process.env.TWS_NO_NATIVE === "1" || process.env.TWS_NO_RUST === "1") {
|
|
2451
|
+
_loadError2 = "Native loading is disabled by TWS_NO_NATIVE or TWS_NO_RUST environment variable.";
|
|
2452
|
+
_binding3 = null;
|
|
2453
|
+
_candidatePaths2 = [];
|
|
2454
|
+
throwNativeBindingError2();
|
|
2455
|
+
}
|
|
2456
|
+
const runtimeDir2 = typeof __dirname === "string" ? __dirname : process.cwd();
|
|
2457
|
+
_candidatePaths2 = [
|
|
2458
|
+
path8.resolve(process.cwd(), "native", "tailwind_styled_parser.node"),
|
|
2459
|
+
path8.resolve(runtimeDir2, "..", "..", "..", "native", "tailwind_styled_parser.node")
|
|
2460
|
+
];
|
|
2461
|
+
const req = typeof __require === "function" ? __require : createRequire(path8.join(runtimeDir2, "noop.cjs"));
|
|
2462
|
+
for (const c of _candidatePaths2) {
|
|
2463
|
+
try {
|
|
2464
|
+
const mod = req(c);
|
|
2465
|
+
if (mod?.computeIncrementalDiff || mod?.processFileChange || mod?.hashFileContent) {
|
|
2466
|
+
_binding3 = mod;
|
|
2467
|
+
return _binding3;
|
|
2468
|
+
}
|
|
2469
|
+
} catch (error) {
|
|
2470
|
+
_loadError2 = error instanceof Error ? error.message : String(error);
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
_binding3 = null;
|
|
2474
|
+
throwNativeBindingError2();
|
|
2475
|
+
}
|
|
2476
|
+
function throwNativeBindingError2() {
|
|
2477
|
+
const lines = [
|
|
2478
|
+
"FATAL: Native engine binding not found.",
|
|
2479
|
+
"",
|
|
2480
|
+
"This package requires the Rust native binding 'tailwind_styled_parser.node'.",
|
|
2481
|
+
"The binding was not found in any of these paths:",
|
|
2482
|
+
..._candidatePaths2.map((p) => ` - ${p}`),
|
|
2483
|
+
""
|
|
2484
|
+
];
|
|
2485
|
+
if (_loadError2) {
|
|
2486
|
+
lines.push("Load error:", ` ${_loadError2}`, "");
|
|
2487
|
+
}
|
|
2488
|
+
lines.push(
|
|
2489
|
+
"To fix this, run:",
|
|
2490
|
+
" npm run build:rust",
|
|
2491
|
+
"",
|
|
2492
|
+
"This will build the native Rust module from the 'native/' directory.",
|
|
2493
|
+
"If you're using this package in a CI/CD environment, ensure Rust toolchain is installed",
|
|
2494
|
+
"and 'npm run build:rust' is executed before running tests or building."
|
|
2495
|
+
);
|
|
2496
|
+
throw new Error(lines.join("\n"));
|
|
2497
|
+
}
|
|
2498
|
+
|
|
2499
|
+
// packages/engine/src/incremental.ts
|
|
2500
|
+
var DEFAULT_EXTENSIONS2 = [".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
2501
|
+
var log3 = createLogger("engine:incremental");
|
|
2502
|
+
function rebuildWorkspaceResult(byFile) {
|
|
2503
|
+
const files = Array.from(byFile.values());
|
|
2504
|
+
const unique = /* @__PURE__ */ new Set();
|
|
2505
|
+
for (const file of files) {
|
|
2506
|
+
for (const cls of file.classes) unique.add(cls);
|
|
2507
|
+
}
|
|
2508
|
+
return {
|
|
2509
|
+
files,
|
|
2510
|
+
totalFiles: files.length,
|
|
2511
|
+
uniqueClasses: Array.from(unique).sort()
|
|
2512
|
+
};
|
|
2513
|
+
}
|
|
2514
|
+
function applyClassDiff(existing, added, removed) {
|
|
2515
|
+
const next = new Set(existing);
|
|
2516
|
+
for (const cls of added) next.add(cls);
|
|
2517
|
+
for (const cls of removed) next.delete(cls);
|
|
2518
|
+
return Array.from(next);
|
|
2519
|
+
}
|
|
2520
|
+
function areClassSetsEqual(a, b) {
|
|
2521
|
+
if (a.length !== b.length) return false;
|
|
2522
|
+
const bSet = new Set(b);
|
|
2523
|
+
for (const cls of a) {
|
|
2524
|
+
if (!bSet.has(cls)) return false;
|
|
2525
|
+
}
|
|
2526
|
+
return true;
|
|
2527
|
+
}
|
|
2528
|
+
function applyIncrementalChange(previous, filePath, type, scanner) {
|
|
2529
|
+
const includeExtensions = scanner?.includeExtensions ?? DEFAULT_EXTENSIONS2;
|
|
2530
|
+
if (!isScannableFile(filePath, includeExtensions)) return previous;
|
|
2531
|
+
const byFile = new Map(previous.files.map((f) => [path8.resolve(f.file), f]));
|
|
2532
|
+
const normalizedPath = path8.resolve(filePath);
|
|
2533
|
+
const native = getNativeEngineBinding();
|
|
2534
|
+
if (native?.processFileChange) {
|
|
2535
|
+
try {
|
|
2536
|
+
if (type === "unlink") {
|
|
2537
|
+
const existing2 = byFile.get(normalizedPath);
|
|
2538
|
+
log3.debug(`native unlink ${normalizedPath}`);
|
|
2539
|
+
native.processFileChange(normalizedPath, existing2?.classes ?? [], null);
|
|
2540
|
+
byFile.delete(normalizedPath);
|
|
2541
|
+
return rebuildWorkspaceResult(byFile);
|
|
2542
|
+
}
|
|
2543
|
+
log3.debug(`native change ${normalizedPath}`);
|
|
2544
|
+
const scanned = scanFile(normalizedPath);
|
|
2545
|
+
const content = fs3.readFileSync(normalizedPath, "utf8");
|
|
2546
|
+
const diff = native.processFileChange(normalizedPath, scanned.classes, content);
|
|
2547
|
+
const existing = byFile.get(normalizedPath);
|
|
2548
|
+
if (diff && existing) {
|
|
2549
|
+
log3.debug(`native diff ${normalizedPath} +${diff.added.length} -${diff.removed.length}`);
|
|
2550
|
+
const diffApplied = applyClassDiff(existing.classes, diff.added, diff.removed);
|
|
2551
|
+
const classes = areClassSetsEqual(diffApplied, scanned.classes) ? diffApplied : scanned.classes;
|
|
2552
|
+
byFile.set(normalizedPath, { file: normalizedPath, classes });
|
|
2553
|
+
} else {
|
|
2554
|
+
log3.debug(`native diff cold-sync ${normalizedPath}`);
|
|
2555
|
+
byFile.set(normalizedPath, { file: normalizedPath, classes: scanned.classes });
|
|
2556
|
+
}
|
|
2557
|
+
return rebuildWorkspaceResult(byFile);
|
|
2558
|
+
} catch (error) {
|
|
2559
|
+
log3.warn(
|
|
2560
|
+
"native processFileChange failed, using JS fallback:",
|
|
2561
|
+
error instanceof Error ? error.message : String(error)
|
|
2562
|
+
);
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
log3.debug(`js fallback ${type} ${normalizedPath}`);
|
|
2566
|
+
if (type === "unlink") {
|
|
2567
|
+
byFile.delete(normalizedPath);
|
|
2568
|
+
} else {
|
|
2569
|
+
byFile.set(normalizedPath, scanFile(normalizedPath));
|
|
2570
|
+
}
|
|
2571
|
+
return rebuildWorkspaceResult(byFile);
|
|
2572
|
+
}
|
|
2573
|
+
|
|
2574
|
+
// packages/engine/src/metrics.ts
|
|
2575
|
+
var EngineMetricsCollector = class {
|
|
2576
|
+
constructor() {
|
|
2577
|
+
this.eventsReceived = 0;
|
|
2578
|
+
this.eventsProcessed = 0;
|
|
2579
|
+
this.batchesProcessed = 0;
|
|
2580
|
+
this.incrementalUpdates = 0;
|
|
2581
|
+
this.fullRescans = 0;
|
|
2582
|
+
this.skippedLargeFiles = 0;
|
|
2583
|
+
this.queueMaxSize = 0;
|
|
2584
|
+
this.lastBuildMs = 0;
|
|
2585
|
+
this.totalBuildMs = 0;
|
|
2586
|
+
}
|
|
2587
|
+
markEventReceived(queueSize) {
|
|
2588
|
+
this.eventsReceived += 1;
|
|
2589
|
+
if (queueSize > this.queueMaxSize) this.queueMaxSize = queueSize;
|
|
2590
|
+
}
|
|
2591
|
+
markBatchProcessed(batchSize) {
|
|
2592
|
+
this.batchesProcessed += 1;
|
|
2593
|
+
this.eventsProcessed += batchSize;
|
|
2594
|
+
}
|
|
2595
|
+
markIncremental() {
|
|
2596
|
+
this.incrementalUpdates += 1;
|
|
2597
|
+
}
|
|
2598
|
+
markFullRescan() {
|
|
2599
|
+
this.fullRescans += 1;
|
|
2600
|
+
}
|
|
2601
|
+
markSkippedLargeFile() {
|
|
2602
|
+
this.skippedLargeFiles += 1;
|
|
2603
|
+
}
|
|
2604
|
+
markBuildDuration(ms) {
|
|
2605
|
+
this.lastBuildMs = ms;
|
|
2606
|
+
this.totalBuildMs += ms;
|
|
2607
|
+
}
|
|
2608
|
+
snapshot() {
|
|
2609
|
+
const avgBuildMs = this.batchesProcessed > 0 ? this.totalBuildMs / this.batchesProcessed : 0;
|
|
2610
|
+
return {
|
|
2611
|
+
eventsReceived: this.eventsReceived,
|
|
2612
|
+
eventsProcessed: this.eventsProcessed,
|
|
2613
|
+
batchesProcessed: this.batchesProcessed,
|
|
2614
|
+
incrementalUpdates: this.incrementalUpdates,
|
|
2615
|
+
fullRescans: this.fullRescans,
|
|
2616
|
+
skippedLargeFiles: this.skippedLargeFiles,
|
|
2617
|
+
queueMaxSize: this.queueMaxSize,
|
|
2618
|
+
lastBuildMs: this.lastBuildMs,
|
|
2619
|
+
avgBuildMs
|
|
2620
|
+
};
|
|
2621
|
+
}
|
|
2622
|
+
};
|
|
2623
|
+
|
|
2624
|
+
// packages/engine/src/plugin-api.ts
|
|
2625
|
+
async function runBeforeScan(plugins, context) {
|
|
2626
|
+
for (const plugin of plugins) {
|
|
2627
|
+
await plugin.beforeScan?.(context);
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
async function runAfterScan(plugins, scan, context) {
|
|
2631
|
+
let current = scan;
|
|
2632
|
+
for (const plugin of plugins) {
|
|
2633
|
+
const next = await plugin.afterScan?.(current, context);
|
|
2634
|
+
if (next !== void 0) current = next;
|
|
2635
|
+
}
|
|
2636
|
+
return current;
|
|
2637
|
+
}
|
|
2638
|
+
async function runTransformClasses(plugins, classes, context) {
|
|
2639
|
+
let current = classes;
|
|
2640
|
+
for (const plugin of plugins) {
|
|
2641
|
+
const next = await plugin.transformClasses?.(current, context);
|
|
2642
|
+
if (next !== void 0) current = next;
|
|
2643
|
+
}
|
|
2644
|
+
return current;
|
|
2645
|
+
}
|
|
2646
|
+
async function runBeforeBuild(plugins, scan, context) {
|
|
2647
|
+
for (const plugin of plugins) {
|
|
2648
|
+
await plugin.beforeBuild?.(scan, context);
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
async function runAfterBuild(plugins, result, context) {
|
|
2652
|
+
let current = result;
|
|
2653
|
+
for (const plugin of plugins) {
|
|
2654
|
+
const next = await plugin.afterBuild?.(current, context);
|
|
2655
|
+
if (next !== void 0) current = next;
|
|
2656
|
+
}
|
|
2657
|
+
return current;
|
|
2658
|
+
}
|
|
2659
|
+
async function runOnError(plugins, error, context) {
|
|
2660
|
+
for (const plugin of plugins) {
|
|
2661
|
+
await plugin.onError?.(error, context);
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
async function runBeforeWatch(plugins, context) {
|
|
2665
|
+
for (const plugin of plugins) {
|
|
2666
|
+
await plugin.beforeWatch?.(context);
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
async function runAfterWatch(plugins, context) {
|
|
2670
|
+
for (const plugin of plugins) {
|
|
2671
|
+
await plugin.afterWatch?.(context);
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
var DEFAULT_IGNORES2 = ["node_modules", ".git", ".next", "dist", "out", ".turbo", ".cache"];
|
|
2675
|
+
function watchWorkspace(rootDir, onEvent, options = {}) {
|
|
2676
|
+
const ignoreDirectories = new Set(options.ignoreDirectories ?? DEFAULT_IGNORES2);
|
|
2677
|
+
const watchers = /* @__PURE__ */ new Map();
|
|
2678
|
+
const restartTimers = /* @__PURE__ */ new Map();
|
|
2679
|
+
const debounceMs = options.debounceMs ?? 100;
|
|
2680
|
+
const pending = /* @__PURE__ */ new Map();
|
|
2681
|
+
const shouldIgnore = (targetPath) => {
|
|
2682
|
+
const parts = targetPath.split(path8.sep);
|
|
2683
|
+
return parts.some((part) => ignoreDirectories.has(part));
|
|
2684
|
+
};
|
|
2685
|
+
const enqueue = (event) => {
|
|
2686
|
+
const key = `${event.type}:${event.filePath}`;
|
|
2687
|
+
const existing = pending.get(key);
|
|
2688
|
+
if (existing) clearTimeout(existing);
|
|
2689
|
+
const timer = setTimeout(() => {
|
|
2690
|
+
pending.delete(key);
|
|
2691
|
+
onEvent(event);
|
|
2692
|
+
}, debounceMs);
|
|
2693
|
+
pending.set(key, timer);
|
|
2694
|
+
};
|
|
2695
|
+
const safeUnwatch = (dir) => {
|
|
2696
|
+
const watcher = watchers.get(dir);
|
|
2697
|
+
if (!watcher) return;
|
|
2698
|
+
try {
|
|
2699
|
+
watcher.close();
|
|
2700
|
+
} catch {
|
|
2701
|
+
}
|
|
2702
|
+
watchers.delete(dir);
|
|
2703
|
+
};
|
|
2704
|
+
const scheduleRestart = (dir) => {
|
|
2705
|
+
const previous = restartTimers.get(dir);
|
|
2706
|
+
if (previous) clearTimeout(previous);
|
|
2707
|
+
const timer = setTimeout(() => {
|
|
2708
|
+
restartTimers.delete(dir);
|
|
2709
|
+
watchDir(dir);
|
|
2710
|
+
}, 250);
|
|
2711
|
+
restartTimers.set(dir, timer);
|
|
2712
|
+
};
|
|
2713
|
+
const watchDir = (dir) => {
|
|
2714
|
+
if (watchers.has(dir) || shouldIgnore(dir) || !fs3.existsSync(dir)) return;
|
|
2715
|
+
try {
|
|
2716
|
+
const stat = fs3.lstatSync(dir);
|
|
2717
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) return;
|
|
2718
|
+
} catch {
|
|
2719
|
+
return;
|
|
2720
|
+
}
|
|
2721
|
+
const watcher = fs3.watch(dir, { persistent: true }, (_eventType, fileName) => {
|
|
2722
|
+
if (!fileName) return;
|
|
2723
|
+
const fullPath = path8.join(dir, fileName.toString());
|
|
2724
|
+
if (shouldIgnore(fullPath)) return;
|
|
2725
|
+
if (fs3.existsSync(fullPath)) {
|
|
2726
|
+
try {
|
|
2727
|
+
const stat = fs3.lstatSync(fullPath);
|
|
2728
|
+
if (stat.isSymbolicLink()) return;
|
|
2729
|
+
if (stat.isDirectory()) {
|
|
2730
|
+
watchDir(fullPath);
|
|
2731
|
+
return;
|
|
2732
|
+
}
|
|
2733
|
+
enqueue({ type: "change", filePath: fullPath });
|
|
2734
|
+
return;
|
|
2735
|
+
} catch {
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
enqueue({ type: "unlink", filePath: fullPath });
|
|
2739
|
+
});
|
|
2740
|
+
watcher.on("error", (error) => {
|
|
2741
|
+
safeUnwatch(dir);
|
|
2742
|
+
const watcherError = error instanceof Error ? error : new Error(String(error));
|
|
2743
|
+
options.onError?.(watcherError, dir);
|
|
2744
|
+
scheduleRestart(dir);
|
|
2745
|
+
});
|
|
2746
|
+
watchers.set(dir, watcher);
|
|
2747
|
+
for (const entry of fs3.readdirSync(dir, { withFileTypes: true })) {
|
|
2748
|
+
if (!entry.isDirectory()) continue;
|
|
2749
|
+
watchDir(path8.join(dir, entry.name));
|
|
2750
|
+
}
|
|
2751
|
+
};
|
|
2752
|
+
watchDir(path8.resolve(rootDir));
|
|
2753
|
+
return {
|
|
2754
|
+
close() {
|
|
2755
|
+
for (const timer of pending.values()) clearTimeout(timer);
|
|
2756
|
+
pending.clear();
|
|
2757
|
+
for (const timer of restartTimers.values()) clearTimeout(timer);
|
|
2758
|
+
restartTimers.clear();
|
|
2759
|
+
for (const watcher of watchers.values()) watcher.close();
|
|
2760
|
+
watchers.clear();
|
|
2761
|
+
}
|
|
2762
|
+
};
|
|
2763
|
+
}
|
|
2764
|
+
|
|
2765
|
+
// packages/engine/src/index.ts
|
|
2766
|
+
var DEFAULT_LARGE_FILE_THRESHOLD_BYTES = 10 * 1024 * 1024;
|
|
2767
|
+
var DEFAULT_FLUSH_DEBOUNCE_MS = 100;
|
|
2768
|
+
var DEFAULT_MAX_EVENTS_PER_FLUSH = 100;
|
|
2769
|
+
var log4 = createLogger("engine");
|
|
2770
|
+
async function loadTailwindConfigFromPath(root, tailwindConfigPath) {
|
|
2771
|
+
if (!tailwindConfigPath) return void 0;
|
|
2772
|
+
const configPath = path8.resolve(root, tailwindConfigPath);
|
|
2773
|
+
if (!fs3.existsSync(configPath)) {
|
|
2774
|
+
throw new Error(`tailwindConfigPath not found: ${configPath}`);
|
|
2775
|
+
}
|
|
2776
|
+
const imported = await import(pathToFileURL(configPath).href);
|
|
2777
|
+
const config = imported.default ?? imported;
|
|
2778
|
+
return config;
|
|
2779
|
+
}
|
|
2780
|
+
async function tryRunAnalyzer(root, scan) {
|
|
2781
|
+
try {
|
|
2782
|
+
const { __internal: __internal2 } = await Promise.resolve().then(() => (init_src4(), src_exports));
|
|
2783
|
+
const counts = __internal2.collectClassCounts(scan);
|
|
2784
|
+
const classUsage = {};
|
|
2785
|
+
for (const [name, count] of counts) {
|
|
2786
|
+
classUsage[name] = count;
|
|
2787
|
+
}
|
|
2788
|
+
return {
|
|
2789
|
+
unusedClasses: Array.from(counts.keys()).filter((c) => counts.get(c) === 0),
|
|
2790
|
+
classConflicts: [],
|
|
2791
|
+
classUsage
|
|
2792
|
+
};
|
|
2793
|
+
} catch (e) {
|
|
2794
|
+
log4.warn("Analyzer not available:", String(e));
|
|
2795
|
+
return void 0;
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
async function buildFromScan(scan, root, options, tailwindConfig) {
|
|
2799
|
+
const plugins = options.plugins ?? [];
|
|
2800
|
+
const context = { root, timestamp: Date.now() };
|
|
2801
|
+
await runBeforeBuild(plugins, scan, context);
|
|
2802
|
+
const transformedClasses = await runTransformClasses(plugins, scan.uniqueClasses, context);
|
|
2803
|
+
const mergedClassList = mergeClassesStatic(transformedClasses.join(" "));
|
|
2804
|
+
let css = "";
|
|
2805
|
+
if (options.compileCss !== false && mergedClassList.length > 0) {
|
|
2806
|
+
css = await generateCssForClasses(
|
|
2807
|
+
mergedClassList.split(/\s+/).filter(Boolean),
|
|
2808
|
+
tailwindConfig,
|
|
2809
|
+
root
|
|
2810
|
+
);
|
|
2811
|
+
}
|
|
2812
|
+
let analysis;
|
|
2813
|
+
if (options.analyze) {
|
|
2814
|
+
analysis = await tryRunAnalyzer(root, scan);
|
|
2815
|
+
}
|
|
2816
|
+
const result = {
|
|
2817
|
+
scan,
|
|
2818
|
+
mergedClassList,
|
|
2819
|
+
css,
|
|
2820
|
+
analysis
|
|
2821
|
+
};
|
|
2822
|
+
return runAfterBuild(plugins, result, context);
|
|
2823
|
+
}
|
|
2824
|
+
async function createEngine(options = {}) {
|
|
2825
|
+
const root = options.root ?? process.cwd();
|
|
2826
|
+
const resolvedRoot = path8.resolve(root);
|
|
2827
|
+
const plugins = options.plugins ?? [];
|
|
2828
|
+
let cachedTailwindConfig;
|
|
2829
|
+
let tailwindConfigLoaded = false;
|
|
2830
|
+
const getTailwindConfig = async () => {
|
|
2831
|
+
if (tailwindConfigLoaded) return cachedTailwindConfig;
|
|
2832
|
+
cachedTailwindConfig = await loadTailwindConfigFromPath(
|
|
2833
|
+
resolvedRoot,
|
|
2834
|
+
options.tailwindConfigPath
|
|
2835
|
+
);
|
|
2836
|
+
tailwindConfigLoaded = true;
|
|
2837
|
+
return cachedTailwindConfig;
|
|
2838
|
+
};
|
|
2839
|
+
const reportEngineError = async (error) => {
|
|
2840
|
+
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
2841
|
+
const context = { root: resolvedRoot, timestamp: Date.now() };
|
|
2842
|
+
try {
|
|
2843
|
+
await runOnError(plugins, normalized, context);
|
|
2844
|
+
} catch (pluginError) {
|
|
2845
|
+
log4.error(
|
|
2846
|
+
"plugin onError hook failed:",
|
|
2847
|
+
pluginError instanceof Error ? pluginError.message : String(pluginError)
|
|
2848
|
+
);
|
|
2849
|
+
}
|
|
2850
|
+
log4.error(normalized.message);
|
|
2851
|
+
return normalized;
|
|
2852
|
+
};
|
|
2853
|
+
const doScan = async () => {
|
|
2854
|
+
try {
|
|
2855
|
+
const context = { root: resolvedRoot, timestamp: Date.now() };
|
|
2856
|
+
await runBeforeScan(plugins, context);
|
|
2857
|
+
const scan = await scanWorkspaceAsync(resolvedRoot, options.scanner);
|
|
2858
|
+
return await runAfterScan(plugins, scan, context);
|
|
2859
|
+
} catch (error) {
|
|
2860
|
+
throw await reportEngineError(error);
|
|
2861
|
+
}
|
|
2862
|
+
};
|
|
2863
|
+
return {
|
|
2864
|
+
scan: doScan,
|
|
2865
|
+
async build() {
|
|
2866
|
+
const scan = await doScan();
|
|
2867
|
+
try {
|
|
2868
|
+
return await buildFromScan(scan, resolvedRoot, options, await getTailwindConfig());
|
|
2869
|
+
} catch (error) {
|
|
2870
|
+
throw await reportEngineError(error);
|
|
2871
|
+
}
|
|
2872
|
+
},
|
|
2873
|
+
async watch(onEvent, watchOptions = {}) {
|
|
2874
|
+
const flushDebounceMs = watchOptions.debounceMs ?? DEFAULT_FLUSH_DEBOUNCE_MS;
|
|
2875
|
+
const maxEventsPerFlush = watchOptions.maxEventsPerFlush ?? DEFAULT_MAX_EVENTS_PER_FLUSH;
|
|
2876
|
+
const largeFileThreshold = watchOptions.largeFileThreshold ?? DEFAULT_LARGE_FILE_THRESHOLD_BYTES;
|
|
2877
|
+
const tailwindConfig = await getTailwindConfig();
|
|
2878
|
+
const watchContext = { root: resolvedRoot, timestamp: Date.now() };
|
|
2879
|
+
await runBeforeWatch(plugins, watchContext);
|
|
2880
|
+
let currentScan = await doScan();
|
|
2881
|
+
try {
|
|
2882
|
+
onEvent({
|
|
2883
|
+
type: "initial",
|
|
2884
|
+
result: await buildFromScan(currentScan, resolvedRoot, options, tailwindConfig)
|
|
2885
|
+
});
|
|
2886
|
+
} catch (error) {
|
|
2887
|
+
const normalized = await reportEngineError(error);
|
|
2888
|
+
onEvent({ type: "error", error: normalized.message });
|
|
2889
|
+
throw normalized;
|
|
2890
|
+
}
|
|
2891
|
+
let timer = null;
|
|
2892
|
+
const queue = [];
|
|
2893
|
+
const metrics = new EngineMetricsCollector();
|
|
2894
|
+
const scheduleFlush = () => {
|
|
2895
|
+
if (timer) return;
|
|
2896
|
+
timer = setTimeout(() => {
|
|
2897
|
+
timer = null;
|
|
2898
|
+
void flushBatch();
|
|
2899
|
+
}, flushDebounceMs);
|
|
2900
|
+
};
|
|
2901
|
+
const shouldForceFullRescan = (event) => {
|
|
2902
|
+
if (event.type === "unlink") return false;
|
|
2903
|
+
try {
|
|
2904
|
+
const stat = fs3.statSync(event.filePath);
|
|
2905
|
+
if (stat.size > largeFileThreshold) {
|
|
2906
|
+
metrics.markSkippedLargeFile();
|
|
2907
|
+
return true;
|
|
2908
|
+
}
|
|
2909
|
+
} catch {
|
|
2910
|
+
return false;
|
|
2911
|
+
}
|
|
2912
|
+
return false;
|
|
2913
|
+
};
|
|
2914
|
+
const flushBatch = async () => {
|
|
2915
|
+
if (queue.length === 0) return;
|
|
2916
|
+
const batch = queue.splice(0, maxEventsPerFlush);
|
|
2917
|
+
metrics.markBatchProcessed(batch.length);
|
|
2918
|
+
let forceRescan = false;
|
|
2919
|
+
for (const event of batch) {
|
|
2920
|
+
if (shouldForceFullRescan(event)) {
|
|
2921
|
+
forceRescan = true;
|
|
2922
|
+
break;
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
const lastEvent = batch[batch.length - 1];
|
|
2926
|
+
let emittedType = lastEvent.type;
|
|
2927
|
+
try {
|
|
2928
|
+
if (forceRescan) {
|
|
2929
|
+
currentScan = await doScan();
|
|
2930
|
+
metrics.markFullRescan();
|
|
2931
|
+
emittedType = "full-rescan";
|
|
2932
|
+
} else {
|
|
2933
|
+
for (const event of batch) {
|
|
2934
|
+
currentScan = applyIncrementalChange(
|
|
2935
|
+
currentScan,
|
|
2936
|
+
event.filePath,
|
|
2937
|
+
event.type,
|
|
2938
|
+
options.scanner
|
|
2939
|
+
);
|
|
2940
|
+
metrics.markIncremental();
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2943
|
+
} catch (error) {
|
|
2944
|
+
const normalized = await reportEngineError(error);
|
|
2945
|
+
log4.warn("incremental path failed, forcing full rescan:", normalized.message);
|
|
2946
|
+
currentScan = await doScan();
|
|
2947
|
+
metrics.markFullRescan();
|
|
2948
|
+
emittedType = "full-rescan";
|
|
2949
|
+
}
|
|
2950
|
+
try {
|
|
2951
|
+
const started = Date.now();
|
|
2952
|
+
const result = await buildFromScan(currentScan, resolvedRoot, options, tailwindConfig);
|
|
2953
|
+
metrics.markBuildDuration(Date.now() - started);
|
|
2954
|
+
onEvent({
|
|
2955
|
+
type: emittedType,
|
|
2956
|
+
filePath: lastEvent.filePath,
|
|
2957
|
+
result,
|
|
2958
|
+
metrics: metrics.snapshot()
|
|
2959
|
+
});
|
|
2960
|
+
} catch (error) {
|
|
2961
|
+
const normalized = await reportEngineError(error);
|
|
2962
|
+
onEvent({
|
|
2963
|
+
type: "error",
|
|
2964
|
+
filePath: lastEvent.filePath,
|
|
2965
|
+
error: normalized.message,
|
|
2966
|
+
metrics: metrics.snapshot()
|
|
2967
|
+
});
|
|
2968
|
+
}
|
|
2969
|
+
if (queue.length > 0) scheduleFlush();
|
|
2970
|
+
};
|
|
2971
|
+
const watcher = watchWorkspace(
|
|
2972
|
+
resolvedRoot,
|
|
2973
|
+
(event) => {
|
|
2974
|
+
queue.push(event);
|
|
2975
|
+
metrics.markEventReceived(queue.length);
|
|
2976
|
+
scheduleFlush();
|
|
2977
|
+
},
|
|
2978
|
+
{
|
|
2979
|
+
ignoreDirectories: options.scanner?.ignoreDirectories,
|
|
2980
|
+
debounceMs: flushDebounceMs,
|
|
2981
|
+
onError: (error, directory) => {
|
|
2982
|
+
void reportEngineError(error);
|
|
2983
|
+
onEvent({
|
|
2984
|
+
type: "error",
|
|
2985
|
+
filePath: directory,
|
|
2986
|
+
error: error.message,
|
|
2987
|
+
metrics: metrics.snapshot()
|
|
2988
|
+
});
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
);
|
|
2992
|
+
return {
|
|
2993
|
+
async close() {
|
|
2994
|
+
if (timer) clearTimeout(timer);
|
|
2995
|
+
watcher.close();
|
|
2996
|
+
await runAfterWatch(plugins, watchContext);
|
|
2997
|
+
}
|
|
2998
|
+
};
|
|
2999
|
+
}
|
|
3000
|
+
};
|
|
3001
|
+
}
|
|
3002
|
+
|
|
3003
|
+
export { createEngine };
|
|
3004
|
+
//# sourceMappingURL=engine.mjs.map
|
|
3005
|
+
//# sourceMappingURL=engine.mjs.map
|