tailwind-styled-v4 5.0.11 → 5.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{analyzeWorkspace-DDOQdzzI.d.ts → analyzeWorkspace-CopJNGmi.d.ts} +2 -0
- package/dist/{analyzeWorkspace-BS5O4rhC.d.mts → analyzeWorkspace-DpVPccjz.d.mts} +2 -0
- package/dist/analyzer.d.mts +4 -4
- package/dist/analyzer.d.ts +4 -4
- package/dist/analyzer.js +34 -69
- package/dist/analyzer.js.map +1 -1
- package/dist/analyzer.mjs +33 -68
- package/dist/analyzer.mjs.map +1 -1
- package/dist/animate.js +11 -11
- package/dist/animate.js.map +1 -1
- package/dist/animate.mjs +11 -11
- package/dist/animate.mjs.map +1 -1
- package/dist/atomic.js +16 -7
- package/dist/atomic.js.map +1 -1
- package/dist/atomic.mjs +16 -7
- package/dist/atomic.mjs.map +1 -1
- package/dist/cli.js +262 -190
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +259 -187
- package/dist/cli.mjs.map +1 -1
- package/dist/compiler.d.mts +2543 -109
- package/dist/compiler.d.ts +2543 -109
- package/dist/compiler.js +1962 -435
- package/dist/compiler.js.map +1 -1
- package/dist/compiler.mjs +1816 -382
- package/dist/compiler.mjs.map +1 -1
- package/dist/devtools.js +17 -4
- package/dist/devtools.js.map +1 -1
- package/dist/devtools.mjs +17 -4
- package/dist/devtools.mjs.map +1 -1
- package/dist/engine.d.mts +11 -470
- package/dist/engine.d.ts +11 -470
- package/dist/engine.js +1442 -417
- package/dist/engine.js.map +1 -1
- package/dist/engine.mjs +1442 -417
- package/dist/engine.mjs.map +1 -1
- package/dist/index-BDQw13kn.d.ts +464 -0
- package/dist/index-DJv28Uzq.d.mts +464 -0
- package/dist/index.browser.mjs +143 -255
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.d.mts +23 -39
- package/dist/index.d.ts +23 -39
- package/dist/index.js +6000 -1463
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5995 -1458
- package/dist/index.mjs.map +1 -1
- package/dist/next.d.mts +44 -1
- package/dist/next.d.ts +44 -1
- package/dist/next.js +3197 -1128
- package/dist/next.js.map +1 -1
- package/dist/next.mjs +3196 -1129
- package/dist/next.mjs.map +1 -1
- package/dist/rspack.d.mts +9 -0
- package/dist/rspack.d.ts +9 -0
- package/dist/rspack.js +99 -61
- package/dist/rspack.js.map +1 -1
- package/dist/rspack.mjs +99 -61
- package/dist/rspack.mjs.map +1 -1
- package/dist/runtime-css.d.mts +8 -0
- package/dist/runtime-css.d.ts +8 -0
- package/dist/runtime-css.js +23 -7
- package/dist/runtime-css.js.map +1 -1
- package/dist/runtime-css.mjs +23 -7
- package/dist/runtime-css.mjs.map +1 -1
- package/dist/scanner.js +16 -37
- package/dist/scanner.js.map +1 -1
- package/dist/scanner.mjs +15 -36
- package/dist/scanner.mjs.map +1 -1
- package/dist/shared.d.mts +107 -1
- package/dist/shared.d.ts +107 -1
- package/dist/shared.js +1627 -376
- package/dist/shared.js.map +1 -1
- package/dist/shared.mjs +1620 -354
- package/dist/shared.mjs.map +1 -1
- package/dist/svelte.js +39 -35
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +38 -34
- package/dist/svelte.mjs.map +1 -1
- package/dist/theme.js +85 -76
- package/dist/theme.js.map +1 -1
- package/dist/theme.mjs +83 -74
- package/dist/theme.mjs.map +1 -1
- package/dist/turbopackLoader.js +943 -76
- package/dist/turbopackLoader.js.map +1 -1
- package/dist/turbopackLoader.mjs +943 -76
- package/dist/turbopackLoader.mjs.map +1 -1
- package/dist/tw.js +262 -190
- package/dist/tw.js.map +1 -1
- package/dist/tw.mjs +259 -187
- package/dist/tw.mjs.map +1 -1
- package/dist/vite.js +1336 -296
- package/dist/vite.js.map +1 -1
- package/dist/vite.mjs +1336 -296
- package/dist/vite.mjs.map +1 -1
- package/dist/vue.js +39 -35
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +38 -34
- package/dist/vue.mjs.map +1 -1
- package/dist/webpackLoader.js +140 -34
- package/dist/webpackLoader.js.map +1 -1
- package/dist/webpackLoader.mjs +140 -34
- package/dist/webpackLoader.mjs.map +1 -1
- package/native/index.node +0 -0
- package/native/tailwind-styled-native.node +0 -0
- package/native/tailwind-styled-native.win32-x64-msvc.node +0 -0
- package/package.json +9 -4
- package/CHANGELOG.md +0 -285
package/dist/turbopackLoader.mjs
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
|
-
import * as
|
|
3
|
-
import
|
|
4
|
-
import * as
|
|
5
|
-
import
|
|
2
|
+
import * as fs4 from 'fs';
|
|
3
|
+
import fs4__default from 'fs';
|
|
4
|
+
import * as path4 from 'path';
|
|
5
|
+
import path4__default from 'path';
|
|
6
6
|
import 'crypto';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
8
|
|
|
9
9
|
/* tailwind-styled-v4 v5.0.4 | MIT | https://github.com/dictionar32/tailwind-styled-v4 */
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
12
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
14
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
12
15
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
13
16
|
}) : x)(function(x) {
|
|
@@ -17,6 +20,19 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
17
20
|
var __esm = (fn, res) => function __init() {
|
|
18
21
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
19
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);
|
|
20
36
|
function platformKey() {
|
|
21
37
|
if (isBrowser) return "browser";
|
|
22
38
|
return `${process.platform}-${process.arch}`;
|
|
@@ -27,12 +43,12 @@ function resolveNativeBinary(runtimeDir) {
|
|
|
27
43
|
if (isBrowser) {
|
|
28
44
|
return { path: null, source: "not-found", platform, tried: ["not available in browser"] };
|
|
29
45
|
}
|
|
30
|
-
if (process.env.TWS_DISABLE_NATIVE === "1") {
|
|
46
|
+
if (process.env.TWS_NO_NATIVE === "1" || process.env.TWS_DISABLE_NATIVE === "1") {
|
|
31
47
|
return { path: null, source: "not-found", platform, tried: [] };
|
|
32
48
|
}
|
|
33
49
|
const envPath = process.env.TW_NATIVE_PATH?.trim();
|
|
34
50
|
if (envPath) {
|
|
35
|
-
if (
|
|
51
|
+
if (fs4.existsSync(envPath)) {
|
|
36
52
|
return { path: envPath, source: "env", platform, tried };
|
|
37
53
|
}
|
|
38
54
|
tried.push(`env:${envPath} (not found)`);
|
|
@@ -41,7 +57,7 @@ function resolveNativeBinary(runtimeDir) {
|
|
|
41
57
|
for (const pkg of prebuiltPkgs) {
|
|
42
58
|
try {
|
|
43
59
|
const candidate = _require.resolve(`${pkg}/tailwind_styled_parser.node`);
|
|
44
|
-
if (
|
|
60
|
+
if (fs4.existsSync(candidate)) {
|
|
45
61
|
return { path: candidate, source: "prebuilt", platform, tried };
|
|
46
62
|
}
|
|
47
63
|
tried.push(`prebuilt:${pkg} (resolved but missing)`);
|
|
@@ -52,13 +68,13 @@ function resolveNativeBinary(runtimeDir) {
|
|
|
52
68
|
const napiPlatform = platform === "linux-x64" ? "linux-x64-gnu" : platform === "linux-arm64" ? "linux-arm64-gnu" : platform;
|
|
53
69
|
const BINARY_NAMES_SELF = ["tailwind-styled-native", "tailwind_styled_parser"];
|
|
54
70
|
if (runtimeDir) {
|
|
55
|
-
for (const depth of ["..",
|
|
56
|
-
const pkgRoot =
|
|
71
|
+
for (const depth of ["..", path4.join("..", ".."), path4.join("..", "..", "..")]) {
|
|
72
|
+
const pkgRoot = path4.resolve(runtimeDir, depth);
|
|
57
73
|
for (const bin of BINARY_NAMES_SELF) {
|
|
58
74
|
for (const suffix of ["", `.${platform}`, `.${napiPlatform}`]) {
|
|
59
|
-
const candidate =
|
|
75
|
+
const candidate = path4.resolve(pkgRoot, "native", `${bin}${suffix}.node`);
|
|
60
76
|
tried.push(`self-bundled:${candidate}`);
|
|
61
|
-
if (
|
|
77
|
+
if (fs4.existsSync(candidate)) {
|
|
62
78
|
return { path: candidate, source: "prebuilt", platform, tried };
|
|
63
79
|
}
|
|
64
80
|
}
|
|
@@ -70,29 +86,29 @@ function resolveNativeBinary(runtimeDir) {
|
|
|
70
86
|
const BINARY_NAMES = ["tailwind-styled-native", "tailwind_styled_parser"];
|
|
71
87
|
const localCandidates = [];
|
|
72
88
|
for (const bin of BINARY_NAMES) {
|
|
73
|
-
localCandidates.push(
|
|
74
|
-
localCandidates.push(
|
|
75
|
-
localCandidates.push(
|
|
76
|
-
localCandidates.push(
|
|
89
|
+
localCandidates.push(path4.resolve(base, `${bin}.node`));
|
|
90
|
+
localCandidates.push(path4.resolve(base, "..", `${bin}.node`));
|
|
91
|
+
localCandidates.push(path4.resolve(base, `${bin}.${platform}.node`));
|
|
92
|
+
localCandidates.push(path4.resolve(base, `${bin}.${napiPlatform}.node`));
|
|
77
93
|
}
|
|
78
94
|
for (const startDir of [cwd, base]) {
|
|
79
95
|
let dir = startDir;
|
|
80
96
|
for (let i = 0; i < 6; i++) {
|
|
81
|
-
const nativeDir =
|
|
97
|
+
const nativeDir = path4.resolve(dir, "native");
|
|
82
98
|
for (const bin of BINARY_NAMES) {
|
|
83
|
-
localCandidates.push(
|
|
84
|
-
localCandidates.push(
|
|
85
|
-
localCandidates.push(
|
|
86
|
-
localCandidates.push(
|
|
99
|
+
localCandidates.push(path4.resolve(nativeDir, `${bin}.node`));
|
|
100
|
+
localCandidates.push(path4.resolve(nativeDir, `${bin}.${platform}.node`));
|
|
101
|
+
localCandidates.push(path4.resolve(nativeDir, `${bin}.${napiPlatform}.node`));
|
|
102
|
+
localCandidates.push(path4.resolve(nativeDir, "target", "release", `${bin}.node`));
|
|
87
103
|
}
|
|
88
|
-
const parent =
|
|
104
|
+
const parent = path4.resolve(dir, "..");
|
|
89
105
|
if (parent === dir) break;
|
|
90
106
|
dir = parent;
|
|
91
107
|
}
|
|
92
108
|
}
|
|
93
109
|
for (const candidate of localCandidates) {
|
|
94
110
|
tried.push(`local:${candidate}`);
|
|
95
|
-
if (
|
|
111
|
+
if (fs4.existsSync(candidate)) {
|
|
96
112
|
return { path: candidate, source: "local", platform, tried };
|
|
97
113
|
}
|
|
98
114
|
}
|
|
@@ -115,7 +131,7 @@ var init_native_resolution = __esm({
|
|
|
115
131
|
});
|
|
116
132
|
function resolveRuntimeDir(dir, importMetaUrl) {
|
|
117
133
|
try {
|
|
118
|
-
return
|
|
134
|
+
return path4__default.dirname(fileURLToPath(importMetaUrl));
|
|
119
135
|
} catch {
|
|
120
136
|
return process.cwd();
|
|
121
137
|
}
|
|
@@ -128,11 +144,11 @@ var init_src = __esm({
|
|
|
128
144
|
});
|
|
129
145
|
|
|
130
146
|
// packages/domain/compiler/src/nativeBridge.ts
|
|
131
|
-
var _loadNative, log, NATIVE_UNAVAILABLE_MESSAGE, nativeBridge, bridgeLoadAttempted, bridgeLoadError, isValidNativeBridge, getNativeBridge;
|
|
147
|
+
var _loadNative, log, NATIVE_UNAVAILABLE_MESSAGE, nativeBridge, bridgeLoadAttempted, bridgeLoadError, isValidNativeBridge, getNativeBridge, adaptNativeResult;
|
|
132
148
|
var init_nativeBridge = __esm({
|
|
133
149
|
"packages/domain/compiler/src/nativeBridge.ts"() {
|
|
134
150
|
init_src();
|
|
135
|
-
_loadNative = (
|
|
151
|
+
_loadNative = (path5) => __require(path5);
|
|
136
152
|
log = (...args) => {
|
|
137
153
|
if (process.env.DEBUG?.includes("compiler:native")) {
|
|
138
154
|
console.log("[compiler:native]", ...args);
|
|
@@ -181,6 +197,15 @@ Tried paths: ${result.tried.join("\n")}`);
|
|
|
181
197
|
throw bridgeLoadError;
|
|
182
198
|
}
|
|
183
199
|
};
|
|
200
|
+
adaptNativeResult = (raw) => {
|
|
201
|
+
return {
|
|
202
|
+
code: raw.code ?? "",
|
|
203
|
+
classes: raw.classes ?? [],
|
|
204
|
+
changed: raw.changed ?? false,
|
|
205
|
+
rsc: raw.rscJson ? JSON.parse(raw.rscJson) : void 0,
|
|
206
|
+
metadata: raw.metadataJson ? JSON.parse(raw.metadataJson) : void 0
|
|
207
|
+
};
|
|
208
|
+
};
|
|
184
209
|
if (typeof process !== "undefined" && !bridgeLoadAttempted) {
|
|
185
210
|
try {
|
|
186
211
|
getNativeBridge();
|
|
@@ -190,30 +215,852 @@ Tried paths: ${result.tried.join("\n")}`);
|
|
|
190
215
|
}
|
|
191
216
|
});
|
|
192
217
|
|
|
193
|
-
// packages/domain/compiler/src/
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
218
|
+
// packages/domain/compiler/src/tailwindEngine.ts
|
|
219
|
+
var tailwindEngine_exports = {};
|
|
220
|
+
__export(tailwindEngine_exports, {
|
|
221
|
+
clearCache: () => clearCache,
|
|
222
|
+
generateRawCss: () => generateRawCss,
|
|
223
|
+
getCacheStats: () => getCacheStats,
|
|
224
|
+
processTailwindCssWithTargets: () => processTailwindCssWithTargets,
|
|
225
|
+
runCssPipeline: () => runCssPipeline,
|
|
226
|
+
runCssPipelineSync: () => runCssPipelineSync
|
|
227
|
+
});
|
|
228
|
+
function _getCacheKey(classes, minify, cssEntry, root) {
|
|
229
|
+
const sorted = [...classes].sort().join(",");
|
|
230
|
+
const flags = `${minify ? "1" : "0"}${cssEntry ? "1" : "0"}${root ? "1" : "0"}`;
|
|
231
|
+
return `${sorted}|${flags}`;
|
|
232
|
+
}
|
|
233
|
+
function _evictOldestIfNeeded() {
|
|
234
|
+
if (_cssCache.size >= MAX_CACHE_SIZE) {
|
|
235
|
+
const firstKey = _cssCache.keys().next().value;
|
|
236
|
+
if (firstKey !== void 0) {
|
|
237
|
+
_cssCache.delete(firstKey);
|
|
238
|
+
}
|
|
199
239
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
240
|
+
}
|
|
241
|
+
function getCacheStats() {
|
|
242
|
+
const total = _cacheHits + _cacheMisses;
|
|
243
|
+
return {
|
|
244
|
+
hits: _cacheHits,
|
|
245
|
+
misses: _cacheMisses,
|
|
246
|
+
hitRate: total > 0 ? _cacheHits / total : 0,
|
|
247
|
+
size: _cssCache.size,
|
|
248
|
+
maxSize: MAX_CACHE_SIZE
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function clearCache() {
|
|
252
|
+
_cssCache.clear();
|
|
253
|
+
_cacheHits = 0;
|
|
254
|
+
_cacheMisses = 0;
|
|
255
|
+
}
|
|
256
|
+
function loadTailwindEngine() {
|
|
257
|
+
if (_twEngine) return _twEngine;
|
|
258
|
+
if (_twEngineError) throw _twEngineError;
|
|
259
|
+
try {
|
|
260
|
+
const tw = require2("tailwindcss");
|
|
261
|
+
if (typeof tw.compile !== "function") {
|
|
262
|
+
throw new Error("tailwindcss v4 not found \u2014 compile() API missing. Check tailwindcss version >= 4.");
|
|
263
|
+
}
|
|
264
|
+
_twEngine = tw;
|
|
265
|
+
return _twEngine;
|
|
266
|
+
} catch (e) {
|
|
267
|
+
_twEngineError = e instanceof Error ? e : new Error(String(e));
|
|
268
|
+
throw _twEngineError;
|
|
203
269
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const
|
|
208
|
-
const
|
|
270
|
+
}
|
|
271
|
+
async function generateRawCss(classes, cssEntryContent, root) {
|
|
272
|
+
if (classes.length === 0) return "";
|
|
273
|
+
const tw = loadTailwindEngine();
|
|
274
|
+
const input = cssEntryContent ?? "@import 'tailwindcss';";
|
|
275
|
+
const { readFileSync, existsSync: existsSync2 } = await import('fs');
|
|
276
|
+
const { dirname, resolve: resolve2 } = await import('path');
|
|
277
|
+
const projectRoot = root ?? process.cwd();
|
|
278
|
+
const req = createRequire(resolve2(projectRoot, "package.json"));
|
|
279
|
+
const loadStylesheet = async (id, base) => {
|
|
280
|
+
try {
|
|
281
|
+
const cssId = id === "tailwindcss" ? "tailwindcss/index.css" : id === "tailwindcss/preflight" ? "tailwindcss/preflight.css" : id === "tailwindcss/utilities" ? "tailwindcss/utilities.css" : id === "tailwindcss/theme" ? "tailwindcss/theme.css" : id;
|
|
282
|
+
const pkgPath = req.resolve(cssId);
|
|
283
|
+
return { content: readFileSync(pkgPath, "utf-8"), base: dirname(pkgPath) };
|
|
284
|
+
} catch {
|
|
285
|
+
try {
|
|
286
|
+
const absPath = resolve2(base, id);
|
|
287
|
+
if (existsSync2(absPath)) {
|
|
288
|
+
return { content: readFileSync(absPath, "utf-8"), base: dirname(absPath) };
|
|
289
|
+
}
|
|
290
|
+
} catch {
|
|
291
|
+
}
|
|
292
|
+
return { content: "", base };
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
const compiler = await Promise.resolve(tw.compile(input, { loadStylesheet }));
|
|
296
|
+
return compiler.build(classes);
|
|
297
|
+
}
|
|
298
|
+
function getThemeConfig() {
|
|
209
299
|
return {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
300
|
+
colors: {
|
|
301
|
+
slate: {
|
|
302
|
+
"50": "#f8fafc",
|
|
303
|
+
"100": "#f1f5f9",
|
|
304
|
+
"200": "#e2e8f0",
|
|
305
|
+
"300": "#cbd5e1",
|
|
306
|
+
"400": "#94a3b8",
|
|
307
|
+
"500": "#64748b",
|
|
308
|
+
"600": "#475569",
|
|
309
|
+
"700": "#334155",
|
|
310
|
+
"800": "#1e293b",
|
|
311
|
+
"900": "#0f172a"
|
|
312
|
+
},
|
|
313
|
+
gray: {
|
|
314
|
+
"50": "#f9fafb",
|
|
315
|
+
"100": "#f3f4f6",
|
|
316
|
+
"200": "#e5e7eb",
|
|
317
|
+
"300": "#d1d5db",
|
|
318
|
+
"400": "#9ca3af",
|
|
319
|
+
"500": "#6b7280",
|
|
320
|
+
"600": "#4b5563",
|
|
321
|
+
"700": "#374151",
|
|
322
|
+
"800": "#1f2937",
|
|
323
|
+
"900": "#111827"
|
|
324
|
+
},
|
|
325
|
+
white: "#ffffff",
|
|
326
|
+
black: "#000000",
|
|
327
|
+
red: {
|
|
328
|
+
"500": "#ef4444",
|
|
329
|
+
"600": "#dc2626"
|
|
330
|
+
},
|
|
331
|
+
blue: {
|
|
332
|
+
"500": "#3b82f6",
|
|
333
|
+
"600": "#1e40af"
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
spacing: {
|
|
337
|
+
"0": "0px",
|
|
338
|
+
"1": "0.25rem",
|
|
339
|
+
"2": "0.5rem",
|
|
340
|
+
"3": "0.75rem",
|
|
341
|
+
"4": "1rem",
|
|
342
|
+
"5": "1.25rem",
|
|
343
|
+
"6": "1.5rem",
|
|
344
|
+
"8": "2rem",
|
|
345
|
+
"10": "2.5rem",
|
|
346
|
+
"12": "3rem",
|
|
347
|
+
"16": "4rem",
|
|
348
|
+
"20": "5rem",
|
|
349
|
+
"24": "6rem"
|
|
350
|
+
},
|
|
351
|
+
breakpoints: {
|
|
352
|
+
"sm": "640px",
|
|
353
|
+
"md": "768px",
|
|
354
|
+
"lg": "1024px",
|
|
355
|
+
"xl": "1280px",
|
|
356
|
+
"2xl": "1536px"
|
|
357
|
+
}
|
|
213
358
|
};
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
359
|
+
}
|
|
360
|
+
function postProcessWithLightning(rawCss) {
|
|
361
|
+
if (!rawCss) return "";
|
|
362
|
+
const native = getNativeBridge();
|
|
363
|
+
if (!native?.processTailwindCssLightning) {
|
|
364
|
+
throw new Error("FATAL: Native binding 'processTailwindCssLightning' is required but not available.");
|
|
365
|
+
}
|
|
366
|
+
const result = native.processTailwindCssLightning(rawCss);
|
|
367
|
+
if (!result?.css) {
|
|
368
|
+
throw new Error("FATAL: processTailwindCssLightning returned null");
|
|
369
|
+
}
|
|
370
|
+
return result.css;
|
|
371
|
+
}
|
|
372
|
+
async function runCssPipeline(classes, cssEntryContent, root, minify = true) {
|
|
373
|
+
const filtered = classes.filter(Boolean);
|
|
374
|
+
const uniqueMap = /* @__PURE__ */ new Map();
|
|
375
|
+
filtered.forEach((cls) => uniqueMap.set(cls, cls));
|
|
376
|
+
const unique = Array.from(uniqueMap.values());
|
|
377
|
+
if (unique.length === 0) {
|
|
378
|
+
return { css: "", classes: [], sizeBytes: 0, optimized: false };
|
|
379
|
+
}
|
|
380
|
+
const cacheKey = _getCacheKey(unique, minify, cssEntryContent, root);
|
|
381
|
+
const cached = _cssCache.get(cacheKey);
|
|
382
|
+
if (cached) {
|
|
383
|
+
_cacheHits++;
|
|
384
|
+
if (process.env.DEBUG?.includes("compiler")) {
|
|
385
|
+
console.log(
|
|
386
|
+
`[Compiler] Cache HIT: ${unique.length} classes (hit rate: ${(getCacheStats().hitRate * 100).toFixed(1)}%)`
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
return cached;
|
|
390
|
+
}
|
|
391
|
+
_cacheMisses++;
|
|
392
|
+
let rawCss;
|
|
393
|
+
let usedRustCompiler = false;
|
|
394
|
+
try {
|
|
395
|
+
const theme = getThemeConfig();
|
|
396
|
+
rawCss = await generateCssNative(unique, {
|
|
397
|
+
theme,
|
|
398
|
+
fallbackToJs: true,
|
|
399
|
+
logFallback: process.env.DEBUG?.includes("compiler") === true
|
|
400
|
+
});
|
|
401
|
+
usedRustCompiler = true;
|
|
402
|
+
} catch (error) {
|
|
403
|
+
if (process.env.DEBUG?.includes("compiler")) {
|
|
404
|
+
console.warn("[Compiler] Rust compiler failed, using JavaScript Tailwind:", error);
|
|
405
|
+
}
|
|
406
|
+
rawCss = await generateRawCss(unique, cssEntryContent, root);
|
|
407
|
+
}
|
|
408
|
+
const finalCss = minify ? postProcessWithLightning(rawCss) : rawCss;
|
|
409
|
+
if (process.env.DEBUG?.includes("compiler")) {
|
|
410
|
+
console.log(
|
|
411
|
+
`[Compiler] Generated CSS from ${unique.length} classes (${usedRustCompiler ? "Rust" : "JavaScript"})`,
|
|
412
|
+
`Size: ${finalCss.length} bytes`
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
const result = {
|
|
416
|
+
css: finalCss,
|
|
417
|
+
classes: unique,
|
|
418
|
+
sizeBytes: finalCss.length,
|
|
419
|
+
optimized: minify
|
|
420
|
+
};
|
|
421
|
+
_evictOldestIfNeeded();
|
|
422
|
+
_cssCache.set(cacheKey, result);
|
|
423
|
+
return result;
|
|
424
|
+
}
|
|
425
|
+
function runCssPipelineSync(_classes) {
|
|
426
|
+
return { css: "", classes: [], sizeBytes: 0, optimized: false };
|
|
427
|
+
}
|
|
428
|
+
function processTailwindCssWithTargets(css, targets) {
|
|
429
|
+
const native = getNativeBridge();
|
|
430
|
+
if (!native?.processTailwindCssWithTargets) {
|
|
431
|
+
throw new Error("FATAL: Native binding 'processTailwindCssWithTargets' is required but not available.");
|
|
432
|
+
}
|
|
433
|
+
const result = native.processTailwindCssWithTargets(css, targets ?? null);
|
|
434
|
+
if (!result?.css) {
|
|
435
|
+
throw new Error("FATAL: processTailwindCssWithTargets returned null");
|
|
436
|
+
}
|
|
437
|
+
return result.css;
|
|
438
|
+
}
|
|
439
|
+
var require2, _cssCache, _cacheHits, _cacheMisses, MAX_CACHE_SIZE, _twEngine, _twEngineError;
|
|
440
|
+
var init_tailwindEngine = __esm({
|
|
441
|
+
"packages/domain/compiler/src/tailwindEngine.ts"() {
|
|
442
|
+
init_nativeBridge();
|
|
443
|
+
init_cssGeneratorNative();
|
|
444
|
+
require2 = createRequire(import.meta.url);
|
|
445
|
+
_cssCache = /* @__PURE__ */ new Map();
|
|
446
|
+
_cacheHits = 0;
|
|
447
|
+
_cacheMisses = 0;
|
|
448
|
+
MAX_CACHE_SIZE = 100;
|
|
449
|
+
_twEngine = null;
|
|
450
|
+
_twEngineError = null;
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
// packages/domain/compiler/src/cssGeneratorNative.ts
|
|
455
|
+
async function generateCssNative(classes, options) {
|
|
456
|
+
const {
|
|
457
|
+
theme,
|
|
458
|
+
fallbackToJs = true,
|
|
459
|
+
logFallback = false
|
|
460
|
+
} = options;
|
|
461
|
+
try {
|
|
462
|
+
const native = getNativeBridge();
|
|
463
|
+
if (!native?.generateCssNative) {
|
|
464
|
+
throw new Error("generateCssNative not available in native binding");
|
|
465
|
+
}
|
|
466
|
+
const themeJson = JSON.stringify(theme);
|
|
467
|
+
const css = native.generateCssNative(classes, themeJson);
|
|
468
|
+
return css;
|
|
469
|
+
} catch (error) {
|
|
470
|
+
if (!fallbackToJs) {
|
|
471
|
+
throw error;
|
|
472
|
+
}
|
|
473
|
+
if (logFallback) {
|
|
474
|
+
console.warn(
|
|
475
|
+
"[CSS Compiler] Rust CSS generator unavailable, falling back to JavaScript Tailwind",
|
|
476
|
+
error instanceof Error ? error.message : String(error)
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
return generateRawCss(classes);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
var init_cssGeneratorNative = __esm({
|
|
483
|
+
"packages/domain/compiler/src/cssGeneratorNative.ts"() {
|
|
484
|
+
init_nativeBridge();
|
|
485
|
+
init_tailwindEngine();
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
function _layoutClassesToCss(classes) {
|
|
489
|
+
const native = getNativeBridge();
|
|
490
|
+
if (!native?.layoutClassesToCss) {
|
|
491
|
+
throw new Error("FATAL: Native binding 'layoutClassesToCss' is required but not available.");
|
|
492
|
+
}
|
|
493
|
+
return native.layoutClassesToCss(classes);
|
|
494
|
+
}
|
|
495
|
+
function _hashContainer(tag, containerJson, name) {
|
|
496
|
+
const sortedKey = tag + (name ?? "") + containerJson;
|
|
497
|
+
const native = getNativeBridge();
|
|
498
|
+
if (!native?.hashContent) {
|
|
499
|
+
throw new Error("FATAL: Native binding 'hashContent' is required but not available.");
|
|
500
|
+
}
|
|
501
|
+
return `tw-cq-${native.hashContent(sortedKey, "fnv", 6)}`;
|
|
502
|
+
}
|
|
503
|
+
function extractContainerCssFromSource(source) {
|
|
504
|
+
const native = getNativeBridge();
|
|
505
|
+
if (!native?.extractTwContainerConfigs) {
|
|
506
|
+
throw new Error("FATAL: Native binding 'extractTwContainerConfigs' is required but not available.");
|
|
507
|
+
}
|
|
508
|
+
const configs = native.extractTwContainerConfigs(source);
|
|
509
|
+
const rules = [];
|
|
510
|
+
for (const cfg of configs) {
|
|
511
|
+
const id = _hashContainer(cfg.tag, cfg.containerJson, cfg.containerName);
|
|
512
|
+
for (const { key, classes } of cfg.breakpoints) {
|
|
513
|
+
const minWidth = _CONTAINER_BREAKPOINTS[key] ?? key;
|
|
514
|
+
const css = _layoutClassesToCss(classes);
|
|
515
|
+
if (!css) continue;
|
|
516
|
+
const query = cfg.containerName ? `@container ${cfg.containerName} (min-width: ${minWidth})` : `@container (min-width: ${minWidth})`;
|
|
517
|
+
rules.push(`${query}{.${id}{${css}}}`);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return rules.join("\n");
|
|
521
|
+
}
|
|
522
|
+
var transformSource, hasTwUsage, isAlreadyTransformed, shouldProcess, compileCssFromClasses, buildStyleTag, compileCssNative, generateCssForClasses, extractAllClasses, extractClassesFromSource, astExtractClasses, parseClasses, normalizeClasses, mergeClassesStatic, normalizeAndDedupClasses, eliminateDeadCss, findDeadVariants, runElimination, optimizeCss, scanProjectUsage, extractComponentUsage, diffClassLists, batchExtractClasses, checkAgainstSafelist, hoistComponents, compileVariantTable, compileVariants, classifyAndSortClasses, mergeCssDeclarations, analyzeClassUsage, analyzeRsc, analyzeFile, analyzeVariantUsage, injectClientDirective, injectServerOnlyComment, analyzeClasses, generateSafelist, loadSafelist, loadTailwindConfig, getContentPaths, _CONTAINER_BREAKPOINTS, runLoaderTransform, shouldSkipFile, fileToRoute, getAllRoutes, getRouteClasses, registerFileClasses, registerGlobalClasses, _incrementalEngineInstance, getIncrementalEngine, resetIncrementalEngine, IncrementalEngine, getBucketEngine, resetBucketEngine, classifyNode, detectConflicts, bucketSort, extractTwStateConfigs, generateStaticStateCss, extractAndGenerateStateCss;
|
|
523
|
+
var init_src2 = __esm({
|
|
524
|
+
"packages/domain/compiler/src/index.ts"() {
|
|
525
|
+
init_nativeBridge();
|
|
526
|
+
transformSource = (source, opts) => {
|
|
527
|
+
const native = getNativeBridge();
|
|
528
|
+
if (!native?.transformSource) {
|
|
529
|
+
throw new Error("FATAL: Native binding 'transformSource' is required but not available.");
|
|
530
|
+
}
|
|
531
|
+
const result = native.transformSource(source, opts);
|
|
532
|
+
if (!result) {
|
|
533
|
+
throw new Error("FATAL: transformSource returned null");
|
|
534
|
+
}
|
|
535
|
+
return result;
|
|
536
|
+
};
|
|
537
|
+
hasTwUsage = (source) => {
|
|
538
|
+
const native = getNativeBridge();
|
|
539
|
+
if (!native?.hasTwUsage) {
|
|
540
|
+
throw new Error("FATAL: Native binding 'hasTwUsage' is required but not available.");
|
|
541
|
+
}
|
|
542
|
+
return native.hasTwUsage(source);
|
|
543
|
+
};
|
|
544
|
+
isAlreadyTransformed = (source) => {
|
|
545
|
+
const native = getNativeBridge();
|
|
546
|
+
if (!native?.isAlreadyTransformed) {
|
|
547
|
+
throw new Error("FATAL: Native binding 'isAlreadyTransformed' is required but not available.");
|
|
548
|
+
}
|
|
549
|
+
return native.isAlreadyTransformed(source);
|
|
550
|
+
};
|
|
551
|
+
shouldProcess = (source) => {
|
|
552
|
+
return hasTwUsage(source) && !isAlreadyTransformed(source);
|
|
553
|
+
};
|
|
554
|
+
compileCssFromClasses = (classes, prefix) => {
|
|
555
|
+
const native = getNativeBridge();
|
|
556
|
+
if (!native?.transformSource) {
|
|
557
|
+
throw new Error("FATAL: Native binding 'transformSource' is required but not available.");
|
|
558
|
+
}
|
|
559
|
+
const result = native.transformSource(classes.join(" "), { prefix: prefix ?? "" });
|
|
560
|
+
if (!result) {
|
|
561
|
+
throw new Error("FATAL: transformSource returned null");
|
|
562
|
+
}
|
|
563
|
+
return result;
|
|
564
|
+
};
|
|
565
|
+
buildStyleTag = (classes) => {
|
|
566
|
+
const result = compileCssFromClasses(classes);
|
|
567
|
+
return result?.code ? `<style data-tailwind-styled>${result.code}</style>` : "";
|
|
568
|
+
};
|
|
569
|
+
compileCssNative = (classes, prefix = null) => {
|
|
570
|
+
return compileCssFromClasses(classes, prefix);
|
|
571
|
+
};
|
|
572
|
+
generateCssForClasses = async (classes, _tailwindConfig, root, cssEntryContent, minify = false) => {
|
|
573
|
+
const { runCssPipeline: runCssPipeline2 } = await Promise.resolve().then(() => (init_tailwindEngine(), tailwindEngine_exports));
|
|
574
|
+
const result = await runCssPipeline2(classes, cssEntryContent, root, minify);
|
|
575
|
+
return result.css;
|
|
576
|
+
};
|
|
577
|
+
extractAllClasses = (source) => {
|
|
578
|
+
const native = getNativeBridge();
|
|
579
|
+
if (!native?.extractAllClasses) {
|
|
580
|
+
throw new Error("FATAL: Native binding 'extractAllClasses' is required but not available.");
|
|
581
|
+
}
|
|
582
|
+
return native.extractAllClasses(source) || [];
|
|
583
|
+
};
|
|
584
|
+
extractClassesFromSource = (source) => {
|
|
585
|
+
const native = getNativeBridge();
|
|
586
|
+
if (!native?.extractClassesFromSource) {
|
|
587
|
+
throw new Error("FATAL: Native binding 'extractClassesFromSource' is required but not available.");
|
|
588
|
+
}
|
|
589
|
+
const result = native.extractClassesFromSource(source);
|
|
590
|
+
return Array.isArray(result) ? result.join(" ") : String(result || "");
|
|
591
|
+
};
|
|
592
|
+
astExtractClasses = (source, _filename) => {
|
|
593
|
+
const native = getNativeBridge();
|
|
594
|
+
if (!native?.extractClassesFromSource) {
|
|
595
|
+
throw new Error("FATAL: Native binding 'extractClassesFromSource' is required but not available.");
|
|
596
|
+
}
|
|
597
|
+
return native.extractClassesFromSource(source) || [];
|
|
598
|
+
};
|
|
599
|
+
parseClasses = (raw) => {
|
|
600
|
+
const native = getNativeBridge();
|
|
601
|
+
if (!native?.parseClasses) {
|
|
602
|
+
throw new Error("FATAL: Native binding 'parseClasses' is required but not available.");
|
|
603
|
+
}
|
|
604
|
+
return native.parseClasses(raw) || [];
|
|
605
|
+
};
|
|
606
|
+
normalizeClasses = (raw) => {
|
|
607
|
+
const result = normalizeAndDedupClasses(raw);
|
|
608
|
+
return result?.normalized || "";
|
|
609
|
+
};
|
|
610
|
+
mergeClassesStatic = (classes) => {
|
|
611
|
+
const result = normalizeAndDedupClasses(classes);
|
|
612
|
+
return result?.normalized || "";
|
|
613
|
+
};
|
|
614
|
+
normalizeAndDedupClasses = (raw) => {
|
|
615
|
+
const native = getNativeBridge();
|
|
616
|
+
if (!native?.normalizeAndDedupClasses) {
|
|
617
|
+
throw new Error("FATAL: Native binding 'normalizeAndDedupClasses' is required but not available.");
|
|
618
|
+
}
|
|
619
|
+
const result = native.normalizeAndDedupClasses(raw);
|
|
620
|
+
return result || { normalized: "", duplicatesRemoved: 0, uniqueCount: 0 };
|
|
621
|
+
};
|
|
622
|
+
eliminateDeadCss = (css, deadClasses) => {
|
|
623
|
+
const native = getNativeBridge();
|
|
624
|
+
if (!native?.eliminateDeadCss) {
|
|
625
|
+
throw new Error("FATAL: Native binding 'eliminateDeadCss' is required but not available.");
|
|
626
|
+
}
|
|
627
|
+
return native.eliminateDeadCss(css, Array.from(deadClasses));
|
|
628
|
+
};
|
|
629
|
+
findDeadVariants = (variantConfig, usage) => {
|
|
630
|
+
const unused = [];
|
|
631
|
+
const configs = Array.isArray(variantConfig) ? variantConfig : [{ name: "__root__", variants: variantConfig }];
|
|
632
|
+
for (const component of configs) {
|
|
633
|
+
const componentUsage = usage[component.name] ?? /* @__PURE__ */ new Set();
|
|
634
|
+
const variants = component.variants;
|
|
635
|
+
for (const [key, values] of Object.entries(variants)) {
|
|
636
|
+
for (const [value] of Object.entries(values)) {
|
|
637
|
+
if (!componentUsage.has(`${key}:${value}`)) {
|
|
638
|
+
unused.push(`${component.name !== "__root__" ? `${component.name}/` : ""}${key}:${value}`);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
return { unusedCount: unused.length, unused };
|
|
644
|
+
};
|
|
645
|
+
runElimination = (css, scanResult) => {
|
|
646
|
+
const native = getNativeBridge();
|
|
647
|
+
if (!native?.detectDeadCode) {
|
|
648
|
+
throw new Error("FATAL: Native binding 'detectDeadCode' is required but not available.");
|
|
649
|
+
}
|
|
650
|
+
const dead = native.detectDeadCode(JSON.stringify(scanResult), css);
|
|
651
|
+
return eliminateDeadCss(css, new Set(dead.deadInCss ?? []));
|
|
652
|
+
};
|
|
653
|
+
optimizeCss = (css) => {
|
|
654
|
+
const native = getNativeBridge();
|
|
655
|
+
if (!native?.optimizeCss) {
|
|
656
|
+
throw new Error("FATAL: Native binding 'optimizeCss' is required but not available.");
|
|
657
|
+
}
|
|
658
|
+
return native.optimizeCss(css);
|
|
659
|
+
};
|
|
660
|
+
scanProjectUsage = (dirs, cwd) => {
|
|
661
|
+
const files = dirs.map((dir) => path4__default.resolve(cwd, dir));
|
|
662
|
+
const results = batchExtractClasses(files) || [];
|
|
663
|
+
const combined = {};
|
|
664
|
+
for (const result of results) {
|
|
665
|
+
if (result.ok && result.classes) {
|
|
666
|
+
for (const cls of result.classes) {
|
|
667
|
+
if (!combined[cls]) combined[cls] = {};
|
|
668
|
+
combined[cls][result.file] = /* @__PURE__ */ new Set([cls]);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return combined;
|
|
673
|
+
};
|
|
674
|
+
extractComponentUsage = (source) => {
|
|
675
|
+
const native = getNativeBridge();
|
|
676
|
+
if (!native?.extractComponentUsage) {
|
|
677
|
+
throw new Error("FATAL: Native binding 'extractComponentUsage' is required but not available.");
|
|
678
|
+
}
|
|
679
|
+
return native.extractComponentUsage(source) || [];
|
|
680
|
+
};
|
|
681
|
+
diffClassLists = (previous, current) => {
|
|
682
|
+
const native = getNativeBridge();
|
|
683
|
+
if (!native?.diffClassLists) {
|
|
684
|
+
throw new Error("FATAL: Native binding 'diffClassLists' is required but not available.");
|
|
685
|
+
}
|
|
686
|
+
return native.diffClassLists(previous, current) || { added: [], removed: [], unchanged: [], hasChanges: false };
|
|
687
|
+
};
|
|
688
|
+
batchExtractClasses = (filePaths) => {
|
|
689
|
+
const native = getNativeBridge();
|
|
690
|
+
if (!native?.batchExtractClasses) {
|
|
691
|
+
throw new Error("FATAL: Native binding 'batchExtractClasses' is required but not available.");
|
|
692
|
+
}
|
|
693
|
+
return native.batchExtractClasses(filePaths) || [];
|
|
694
|
+
};
|
|
695
|
+
checkAgainstSafelist = (classes, safelist) => {
|
|
696
|
+
const native = getNativeBridge();
|
|
697
|
+
if (!native?.checkAgainstSafelist) {
|
|
698
|
+
throw new Error("FATAL: Native binding 'checkAgainstSafelist' is required but not available.");
|
|
699
|
+
}
|
|
700
|
+
return native.checkAgainstSafelist(classes, safelist) || { matched: [], unmatched: [], safelistSize: 0 };
|
|
701
|
+
};
|
|
702
|
+
hoistComponents = (source) => {
|
|
703
|
+
const native = getNativeBridge();
|
|
704
|
+
if (!native?.hoistComponents) {
|
|
705
|
+
throw new Error("FATAL: Native binding 'hoistComponents' is required but not available.");
|
|
706
|
+
}
|
|
707
|
+
return native.hoistComponents(source) || { code: source, hoisted: [], warnings: [] };
|
|
708
|
+
};
|
|
709
|
+
compileVariantTable = (configJson) => {
|
|
710
|
+
const native = getNativeBridge();
|
|
711
|
+
if (!native?.compileVariantTable) {
|
|
712
|
+
throw new Error("FATAL: Native binding 'compileVariantTable' is required but not available.");
|
|
713
|
+
}
|
|
714
|
+
return native.compileVariantTable(configJson) || { id: "", tableJson: "{}", keys: [], defaultKey: "", combinations: 0 };
|
|
715
|
+
};
|
|
716
|
+
compileVariants = (componentId, config) => {
|
|
717
|
+
return compileVariantTable(JSON.stringify({ componentId, ...config }));
|
|
718
|
+
};
|
|
719
|
+
classifyAndSortClasses = (classes) => {
|
|
720
|
+
const native = getNativeBridge();
|
|
721
|
+
if (!native?.classifyAndSortClasses) {
|
|
722
|
+
throw new Error("FATAL: Native binding 'classifyAndSortClasses' is required but not available.");
|
|
723
|
+
}
|
|
724
|
+
return native.classifyAndSortClasses(classes) || [];
|
|
725
|
+
};
|
|
726
|
+
mergeCssDeclarations = (cssChunks) => {
|
|
727
|
+
const native = getNativeBridge();
|
|
728
|
+
if (!native?.mergeCssDeclarations) {
|
|
729
|
+
throw new Error("FATAL: Native binding 'mergeCssDeclarations' is required but not available.");
|
|
730
|
+
}
|
|
731
|
+
return native.mergeCssDeclarations(cssChunks) || { declarationsJson: "{}", declarationString: "", count: 0 };
|
|
732
|
+
};
|
|
733
|
+
analyzeClassUsage = (classes, scanResultJson, css) => {
|
|
734
|
+
const native = getNativeBridge();
|
|
735
|
+
if (!native?.analyzeClassUsage) {
|
|
736
|
+
throw new Error("FATAL: Native binding 'analyzeClassUsage' is required but not available.");
|
|
737
|
+
}
|
|
738
|
+
return native.analyzeClassUsage(classes, scanResultJson, css) || [];
|
|
739
|
+
};
|
|
740
|
+
analyzeRsc = (source, filename) => {
|
|
741
|
+
const native = getNativeBridge();
|
|
742
|
+
if (!native?.analyzeRsc) {
|
|
743
|
+
throw new Error("FATAL: Native binding 'analyzeRsc' is required but not available.");
|
|
744
|
+
}
|
|
745
|
+
return native.analyzeRsc(source, filename) || { isServer: true, needsClientDirective: false, clientReasons: [] };
|
|
746
|
+
};
|
|
747
|
+
analyzeFile = (source, filename) => {
|
|
748
|
+
const rsc = analyzeRsc(source, filename);
|
|
749
|
+
return {
|
|
750
|
+
isServer: rsc?.isServer ?? true,
|
|
751
|
+
needsClientDirective: rsc?.needsClientDirective ?? false,
|
|
752
|
+
clientReasons: rsc?.clientReasons ?? [],
|
|
753
|
+
interactiveClasses: [],
|
|
754
|
+
canStaticResolveVariants: true
|
|
755
|
+
};
|
|
756
|
+
};
|
|
757
|
+
analyzeVariantUsage = (_source, _componentName, _variantKeys) => {
|
|
758
|
+
return { resolved: {}, dynamic: [] };
|
|
759
|
+
};
|
|
760
|
+
injectClientDirective = (source) => {
|
|
761
|
+
if (!source.includes('"use client"') && !source.includes("'use client'")) {
|
|
762
|
+
return '"use client";\n' + source;
|
|
763
|
+
}
|
|
764
|
+
return source;
|
|
765
|
+
};
|
|
766
|
+
injectServerOnlyComment = (source) => {
|
|
767
|
+
return `/* @server-only */
|
|
768
|
+
${source}`;
|
|
769
|
+
};
|
|
770
|
+
analyzeClasses = (filesJson, cwd, flags) => {
|
|
771
|
+
const native = getNativeBridge();
|
|
772
|
+
if (!native?.analyzeClasses) {
|
|
773
|
+
throw new Error("FATAL: Native binding 'analyzeClasses' is required but not available.");
|
|
774
|
+
}
|
|
775
|
+
return native.analyzeClasses(filesJson, cwd, flags);
|
|
776
|
+
};
|
|
777
|
+
generateSafelist = (scanDirs, outputPath, cwd) => {
|
|
778
|
+
const classes = scanProjectUsage(scanDirs, cwd || process.cwd());
|
|
779
|
+
const allClasses = Object.keys(classes).sort();
|
|
780
|
+
if (outputPath) {
|
|
781
|
+
fs4__default.writeFileSync(outputPath, JSON.stringify(allClasses, null, 2));
|
|
782
|
+
}
|
|
783
|
+
return allClasses;
|
|
784
|
+
};
|
|
785
|
+
loadSafelist = (safelistPath) => {
|
|
786
|
+
try {
|
|
787
|
+
const content = fs4__default.readFileSync(safelistPath, "utf-8");
|
|
788
|
+
return JSON.parse(content);
|
|
789
|
+
} catch {
|
|
790
|
+
return [];
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
loadTailwindConfig = (cwd = process.cwd()) => {
|
|
794
|
+
const configFiles = [
|
|
795
|
+
"tailwind.config.ts",
|
|
796
|
+
"tailwind.config.js",
|
|
797
|
+
"tailwind.config.mjs",
|
|
798
|
+
"tailwind.config.cjs"
|
|
799
|
+
];
|
|
800
|
+
for (const file of configFiles) {
|
|
801
|
+
const fullPath = path4__default.join(cwd, file);
|
|
802
|
+
if (fs4__default.existsSync(fullPath)) {
|
|
803
|
+
const mod = __require(fullPath);
|
|
804
|
+
return mod.default || mod;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
return {};
|
|
808
|
+
};
|
|
809
|
+
getContentPaths = (cwd = process.cwd()) => {
|
|
810
|
+
return {
|
|
811
|
+
content: [
|
|
812
|
+
path4__default.join(cwd, "src/**/*.{js,ts,jsx,tsx}"),
|
|
813
|
+
path4__default.join(cwd, "app/**/*.{js,ts,jsx,tsx}"),
|
|
814
|
+
path4__default.join(cwd, "pages/**/*.{js,ts,jsx,tsx}")
|
|
815
|
+
]
|
|
816
|
+
};
|
|
817
|
+
};
|
|
818
|
+
_CONTAINER_BREAKPOINTS = {
|
|
819
|
+
xs: "240px",
|
|
820
|
+
sm: "320px",
|
|
821
|
+
md: "640px",
|
|
822
|
+
lg: "1024px",
|
|
823
|
+
xl: "1280px",
|
|
824
|
+
"2xl": "1536px"
|
|
825
|
+
};
|
|
826
|
+
runLoaderTransform = (ctx) => {
|
|
827
|
+
const { filepath, source, options } = ctx;
|
|
828
|
+
const result = transformSource(source, { filename: filepath, ...options });
|
|
829
|
+
let staticCss;
|
|
830
|
+
try {
|
|
831
|
+
const cssChunks = [];
|
|
832
|
+
const stateRules = extractAndGenerateStateCss(source, filepath);
|
|
833
|
+
if (stateRules.length > 0) {
|
|
834
|
+
cssChunks.push(stateRules.map((r) => r.cssRule).join("\n"));
|
|
835
|
+
}
|
|
836
|
+
const containerCss = extractContainerCssFromSource(source);
|
|
837
|
+
if (containerCss) cssChunks.push(containerCss);
|
|
838
|
+
const combined = cssChunks.join("\n").trim();
|
|
839
|
+
if (combined) staticCss = combined;
|
|
840
|
+
} catch {
|
|
841
|
+
}
|
|
842
|
+
return {
|
|
843
|
+
code: result?.code || "",
|
|
844
|
+
changed: result?.changed || false,
|
|
845
|
+
classes: result?.classes || [],
|
|
846
|
+
staticCss
|
|
847
|
+
};
|
|
848
|
+
};
|
|
849
|
+
shouldSkipFile = (filepath) => {
|
|
850
|
+
const SKIP_PATHS = ["node_modules", ".next", ".rspack-dist", ".turbo", "dist/", "out/"];
|
|
851
|
+
const skipExtensions = [".css", ".json", ".md", ".txt", ".yaml", ".yml"];
|
|
852
|
+
for (const p of SKIP_PATHS) {
|
|
853
|
+
if (filepath.includes(p)) return true;
|
|
854
|
+
}
|
|
855
|
+
for (const ext of skipExtensions) {
|
|
856
|
+
if (filepath.endsWith(ext)) return true;
|
|
857
|
+
}
|
|
858
|
+
return false;
|
|
859
|
+
};
|
|
860
|
+
fileToRoute = (filepath) => {
|
|
861
|
+
const normalized = filepath.replace(/\\/g, "/");
|
|
862
|
+
if (normalized.includes("/layout.") || normalized.includes("/loading.") || normalized.includes("/error.")) {
|
|
863
|
+
return "__global";
|
|
864
|
+
}
|
|
865
|
+
const pageMatch = normalized.match(/\/app\/(.+?)\/page\.[tj]sx?$/);
|
|
866
|
+
if (pageMatch) return `/${pageMatch[1]}`;
|
|
867
|
+
const rootPage = normalized.match(/\/app\/page\.[tj]sx?$/);
|
|
868
|
+
if (rootPage) return "/";
|
|
869
|
+
return null;
|
|
870
|
+
};
|
|
871
|
+
getAllRoutes = () => {
|
|
872
|
+
const native = getNativeBridge();
|
|
873
|
+
if (!native?.analyzeClasses) {
|
|
874
|
+
throw new Error("FATAL: Native binding 'analyzeClasses' is required but not available.");
|
|
875
|
+
}
|
|
876
|
+
return ["/", "__global"];
|
|
877
|
+
};
|
|
878
|
+
getRouteClasses = (_route) => /* @__PURE__ */ new Set();
|
|
879
|
+
registerFileClasses = (_filepath, _classes) => {
|
|
880
|
+
};
|
|
881
|
+
registerGlobalClasses = (_classes) => {
|
|
882
|
+
};
|
|
883
|
+
_incrementalEngineInstance = null;
|
|
884
|
+
getIncrementalEngine = () => {
|
|
885
|
+
if (!_incrementalEngineInstance) {
|
|
886
|
+
_incrementalEngineInstance = new IncrementalEngine();
|
|
887
|
+
}
|
|
888
|
+
return _incrementalEngineInstance;
|
|
889
|
+
};
|
|
890
|
+
resetIncrementalEngine = () => {
|
|
891
|
+
_incrementalEngineInstance = null;
|
|
892
|
+
};
|
|
893
|
+
IncrementalEngine = class {
|
|
894
|
+
compile(source) {
|
|
895
|
+
return transformSource(source);
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
getBucketEngine = () => {
|
|
899
|
+
const native = getNativeBridge();
|
|
900
|
+
if (!native?.classifyAndSortClasses) {
|
|
901
|
+
throw new Error("FATAL: Native binding 'classifyAndSortClasses' is required but not available.");
|
|
902
|
+
}
|
|
903
|
+
return {
|
|
904
|
+
add: (className) => className,
|
|
905
|
+
get: (_bucket) => []
|
|
906
|
+
};
|
|
907
|
+
};
|
|
908
|
+
resetBucketEngine = () => {
|
|
909
|
+
};
|
|
910
|
+
classifyNode = (_node) => {
|
|
911
|
+
const native = getNativeBridge();
|
|
912
|
+
if (!native?.classifyAndSortClasses) {
|
|
913
|
+
throw new Error("FATAL: Native binding 'classifyAndSortClasses' is required but not available.");
|
|
914
|
+
}
|
|
915
|
+
return "unknown";
|
|
916
|
+
};
|
|
917
|
+
detectConflicts = (_classes) => {
|
|
918
|
+
const native = getNativeBridge();
|
|
919
|
+
if (!native?.analyzeClassUsage) {
|
|
920
|
+
throw new Error("FATAL: Native binding 'analyzeClassUsage' is required but not available.");
|
|
921
|
+
}
|
|
922
|
+
return [];
|
|
923
|
+
};
|
|
924
|
+
bucketSort = (classes) => {
|
|
925
|
+
return classifyAndSortClasses(classes).map((c) => c.raw ?? c);
|
|
926
|
+
};
|
|
927
|
+
extractTwStateConfigs = (source, filename) => {
|
|
928
|
+
const native = getNativeBridge();
|
|
929
|
+
if (!native?.extractTwStateConfigs) {
|
|
930
|
+
throw new Error("FATAL: Native binding 'extractTwStateConfigs' is required but not available.");
|
|
931
|
+
}
|
|
932
|
+
return native.extractTwStateConfigs(source, filename);
|
|
933
|
+
};
|
|
934
|
+
generateStaticStateCss = (inputs, resolvedCss = null) => {
|
|
935
|
+
const native = getNativeBridge();
|
|
936
|
+
if (!native?.generateStaticStateCss) {
|
|
937
|
+
throw new Error("FATAL: Native binding 'generateStaticStateCss' is required but not available.");
|
|
938
|
+
}
|
|
939
|
+
return native.generateStaticStateCss(inputs, resolvedCss);
|
|
940
|
+
};
|
|
941
|
+
extractAndGenerateStateCss = (source, filename) => {
|
|
942
|
+
const native = getNativeBridge();
|
|
943
|
+
if (!native?.extractAndGenerateStateCss) {
|
|
944
|
+
const configs = extractTwStateConfigs(source, filename);
|
|
945
|
+
if (configs.length === 0) return [];
|
|
946
|
+
return generateStaticStateCss(
|
|
947
|
+
configs.map((c) => ({ tag: c.tag, componentName: c.componentName, statesJson: c.statesJson }))
|
|
948
|
+
);
|
|
949
|
+
}
|
|
950
|
+
return native.extractAndGenerateStateCss(source, filename);
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
|
|
955
|
+
// packages/domain/compiler/src/internal.ts
|
|
956
|
+
var internal_exports = {};
|
|
957
|
+
__export(internal_exports, {
|
|
958
|
+
adaptNativeResult: () => adaptNativeResult,
|
|
959
|
+
analyzeClassUsage: () => analyzeClassUsage,
|
|
960
|
+
analyzeClasses: () => analyzeClasses,
|
|
961
|
+
analyzeFile: () => analyzeFile,
|
|
962
|
+
analyzeRsc: () => analyzeRsc,
|
|
963
|
+
analyzeVariantUsage: () => analyzeVariantUsage,
|
|
964
|
+
astExtractClasses: () => astExtractClasses,
|
|
965
|
+
batchExtractClasses: () => batchExtractClasses,
|
|
966
|
+
bucketSort: () => bucketSort,
|
|
967
|
+
buildStyleTag: () => buildStyleTag,
|
|
968
|
+
checkAgainstSafelist: () => checkAgainstSafelist,
|
|
969
|
+
classifyAndSortClasses: () => classifyAndSortClasses,
|
|
970
|
+
classifyNode: () => classifyNode,
|
|
971
|
+
clearCache: () => clearCache,
|
|
972
|
+
compileCssFromClasses: () => compileCssFromClasses,
|
|
973
|
+
compileCssNative: () => compileCssNative,
|
|
974
|
+
compileVariantTable: () => compileVariantTable,
|
|
975
|
+
compileVariants: () => compileVariants,
|
|
976
|
+
detectConflicts: () => detectConflicts,
|
|
977
|
+
diffClassLists: () => diffClassLists,
|
|
978
|
+
eliminateDeadCss: () => eliminateDeadCss,
|
|
979
|
+
extractAllClasses: () => extractAllClasses,
|
|
980
|
+
extractAndGenerateStateCss: () => extractAndGenerateStateCss,
|
|
981
|
+
extractClassesFromSource: () => extractClassesFromSource,
|
|
982
|
+
extractComponentUsage: () => extractComponentUsage,
|
|
983
|
+
extractContainerCssFromSource: () => extractContainerCssFromSource,
|
|
984
|
+
extractTwStateConfigs: () => extractTwStateConfigs,
|
|
985
|
+
fileToRoute: () => fileToRoute,
|
|
986
|
+
findDeadVariants: () => findDeadVariants,
|
|
987
|
+
generateCssForClasses: () => generateCssForClasses,
|
|
988
|
+
generateRawCss: () => generateRawCss,
|
|
989
|
+
generateSafelist: () => generateSafelist,
|
|
990
|
+
generateStaticStateCss: () => generateStaticStateCss,
|
|
991
|
+
getAllRoutes: () => getAllRoutes,
|
|
992
|
+
getBucketEngine: () => getBucketEngine,
|
|
993
|
+
getCacheStats: () => getCacheStats,
|
|
994
|
+
getContentPaths: () => getContentPaths,
|
|
995
|
+
getIncrementalEngine: () => getIncrementalEngine,
|
|
996
|
+
getNativeBridge: () => getNativeBridge,
|
|
997
|
+
getRouteClasses: () => getRouteClasses,
|
|
998
|
+
hasTwUsage: () => hasTwUsage,
|
|
999
|
+
hoistComponents: () => hoistComponents,
|
|
1000
|
+
injectClientDirective: () => injectClientDirective,
|
|
1001
|
+
injectServerOnlyComment: () => injectServerOnlyComment,
|
|
1002
|
+
isAlreadyTransformed: () => isAlreadyTransformed,
|
|
1003
|
+
loadSafelist: () => loadSafelist,
|
|
1004
|
+
loadTailwindConfig: () => loadTailwindConfig,
|
|
1005
|
+
mergeClassesStatic: () => mergeClassesStatic,
|
|
1006
|
+
mergeCssDeclarations: () => mergeCssDeclarations,
|
|
1007
|
+
normalizeAndDedupClasses: () => normalizeAndDedupClasses,
|
|
1008
|
+
normalizeClasses: () => normalizeClasses,
|
|
1009
|
+
optimizeCss: () => optimizeCss,
|
|
1010
|
+
parseClasses: () => parseClasses,
|
|
1011
|
+
registerFileClasses: () => registerFileClasses,
|
|
1012
|
+
registerGlobalClasses: () => registerGlobalClasses,
|
|
1013
|
+
resetBucketEngine: () => resetBucketEngine,
|
|
1014
|
+
resetIncrementalEngine: () => resetIncrementalEngine,
|
|
1015
|
+
runCssPipeline: () => runCssPipeline,
|
|
1016
|
+
runCssPipelineSync: () => runCssPipelineSync,
|
|
1017
|
+
runElimination: () => runElimination,
|
|
1018
|
+
runLoaderTransform: () => runLoaderTransform,
|
|
1019
|
+
scanProjectUsage: () => scanProjectUsage,
|
|
1020
|
+
shouldProcess: () => shouldProcess,
|
|
1021
|
+
shouldSkipFile: () => shouldSkipFile,
|
|
1022
|
+
transformSource: () => transformSource
|
|
1023
|
+
});
|
|
1024
|
+
var init_internal = __esm({
|
|
1025
|
+
"packages/domain/compiler/src/internal.ts"() {
|
|
1026
|
+
init_src2();
|
|
1027
|
+
init_tailwindEngine();
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
|
|
1031
|
+
// packages/presentation/next/src/turbopackLoader.ts
|
|
1032
|
+
init_internal();
|
|
1033
|
+
var _writtenRules = /* @__PURE__ */ new Set();
|
|
1034
|
+
function appendStaticCssToFile(staticCss, safelistPath) {
|
|
1035
|
+
if (!staticCss.trim() || !safelistPath) return;
|
|
1036
|
+
const stateFilePath = path4__default.join(path4__default.dirname(safelistPath), "_tw-state-static.css");
|
|
1037
|
+
const newRules = [];
|
|
1038
|
+
for (const chunk of staticCss.split(/(?<=\})\s*/)) {
|
|
1039
|
+
const rule = chunk.trim();
|
|
1040
|
+
if (rule && !_writtenRules.has(rule)) {
|
|
1041
|
+
_writtenRules.add(rule);
|
|
1042
|
+
newRules.push(rule);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
if (newRules.length === 0) return;
|
|
1046
|
+
try {
|
|
1047
|
+
fs4__default.mkdirSync(path4__default.dirname(stateFilePath), { recursive: true });
|
|
1048
|
+
if (!fs4__default.existsSync(stateFilePath)) {
|
|
1049
|
+
fs4__default.writeFileSync(
|
|
1050
|
+
stateFilePath,
|
|
1051
|
+
`/* _tw-state-static.css \u2014 Auto-generated by tailwind-styled-v4. DO NOT EDIT.
|
|
1052
|
+
* Import di globals.css: @import "./_tw-state-static.css";
|
|
1053
|
+
* Berisi: state CSS (.tw-s-*[data-*="true"]) + container queries (@container .tw-cq-*).
|
|
1054
|
+
*/
|
|
1055
|
+
|
|
1056
|
+
`,
|
|
1057
|
+
"utf-8"
|
|
1058
|
+
);
|
|
1059
|
+
}
|
|
1060
|
+
fs4__default.appendFileSync(stateFilePath, newRules.join("\n") + "\n", "utf-8");
|
|
1061
|
+
} catch {
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
217
1064
|
function parseBool(val, fallback = false) {
|
|
218
1065
|
if (typeof val === "boolean") return val;
|
|
219
1066
|
if (typeof val === "string") return val === "true" || val === "1";
|
|
@@ -249,11 +1096,11 @@ var CYCLE_SENTINEL = "_cycle.txt";
|
|
|
249
1096
|
var START_SENTINEL = "_start.txt";
|
|
250
1097
|
var _workerCache = /* @__PURE__ */ new Map();
|
|
251
1098
|
function getTwClassesDir(safelistPath) {
|
|
252
|
-
return
|
|
1099
|
+
return path4__default.join(path4__default.dirname(safelistPath), "tw-classes");
|
|
253
1100
|
}
|
|
254
1101
|
function readSentinel(filePath) {
|
|
255
1102
|
try {
|
|
256
|
-
return
|
|
1103
|
+
return fs4__default.readFileSync(filePath, "utf-8").trim();
|
|
257
1104
|
} catch {
|
|
258
1105
|
return "";
|
|
259
1106
|
}
|
|
@@ -263,36 +1110,36 @@ function clearAndMarkCycle(twClassesDir, startId) {
|
|
|
263
1110
|
if (_clearLock) return;
|
|
264
1111
|
_clearLock = true;
|
|
265
1112
|
try {
|
|
266
|
-
if (
|
|
1113
|
+
if (fs4__default.existsSync(twClassesDir)) {
|
|
267
1114
|
const tempDir = `${twClassesDir}_clearing_${Date.now()}`;
|
|
268
1115
|
try {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const startFile =
|
|
272
|
-
if (
|
|
273
|
-
|
|
1116
|
+
fs4__default.renameSync(twClassesDir, tempDir);
|
|
1117
|
+
fs4__default.mkdirSync(twClassesDir, { recursive: true });
|
|
1118
|
+
const startFile = path4__default.join(tempDir, START_SENTINEL);
|
|
1119
|
+
if (fs4__default.existsSync(startFile)) {
|
|
1120
|
+
fs4__default.copyFileSync(startFile, path4__default.join(twClassesDir, START_SENTINEL));
|
|
274
1121
|
}
|
|
275
|
-
const mergedFile =
|
|
276
|
-
if (
|
|
277
|
-
|
|
1122
|
+
const mergedFile = path4__default.join(tempDir, "_webpack-merged.css");
|
|
1123
|
+
if (fs4__default.existsSync(mergedFile)) {
|
|
1124
|
+
fs4__default.copyFileSync(mergedFile, path4__default.join(twClassesDir, "_webpack-merged.css"));
|
|
278
1125
|
}
|
|
279
|
-
|
|
1126
|
+
fs4__default.writeFileSync(path4__default.join(twClassesDir, CYCLE_SENTINEL), startId, "utf-8");
|
|
280
1127
|
_workerCache.set(twClassesDir, startId);
|
|
281
|
-
|
|
1128
|
+
fs4__default.rmSync(tempDir, { recursive: true, force: true });
|
|
282
1129
|
} catch {
|
|
283
|
-
for (const file of
|
|
1130
|
+
for (const file of fs4__default.readdirSync(twClassesDir)) {
|
|
284
1131
|
if (file === START_SENTINEL || file === "_webpack-merged.css") continue;
|
|
285
1132
|
try {
|
|
286
|
-
|
|
1133
|
+
fs4__default.unlinkSync(path4__default.join(twClassesDir, file));
|
|
287
1134
|
} catch {
|
|
288
1135
|
}
|
|
289
1136
|
}
|
|
290
|
-
|
|
1137
|
+
fs4__default.writeFileSync(path4__default.join(twClassesDir, CYCLE_SENTINEL), startId, "utf-8");
|
|
291
1138
|
_workerCache.set(twClassesDir, startId);
|
|
292
1139
|
}
|
|
293
1140
|
} else {
|
|
294
|
-
|
|
295
|
-
|
|
1141
|
+
fs4__default.mkdirSync(twClassesDir, { recursive: true });
|
|
1142
|
+
fs4__default.writeFileSync(path4__default.join(twClassesDir, CYCLE_SENTINEL), startId, "utf-8");
|
|
296
1143
|
_workerCache.set(twClassesDir, startId);
|
|
297
1144
|
}
|
|
298
1145
|
} catch {
|
|
@@ -303,41 +1150,41 @@ function clearAndMarkCycle(twClassesDir, startId) {
|
|
|
303
1150
|
function getPerFileSafelistPath(safelistDir, resourcePath) {
|
|
304
1151
|
const normalized = resourcePath.replace(/\\/g, "/");
|
|
305
1152
|
const slug = normalized.replace(/^.*\/src\//, "").replace(/\.[tj]sx?$/, "").replace(/[^a-zA-Z0-9]/g, "_").slice(0, 80);
|
|
306
|
-
return
|
|
1153
|
+
return path4__default.join(safelistDir, `${slug}.css`);
|
|
307
1154
|
}
|
|
308
1155
|
function writePerFileSafelist(safelistPath, resourcePath, classes) {
|
|
309
1156
|
if (!safelistPath || classes.length === 0) return;
|
|
310
1157
|
try {
|
|
311
1158
|
const twClassesDir = getTwClassesDir(safelistPath);
|
|
312
|
-
const startId = readSentinel(
|
|
313
|
-
const cachedCycle = _workerCache.get(twClassesDir) ?? readSentinel(
|
|
1159
|
+
const startId = readSentinel(path4__default.join(twClassesDir, START_SENTINEL));
|
|
1160
|
+
const cachedCycle = _workerCache.get(twClassesDir) ?? readSentinel(path4__default.join(twClassesDir, CYCLE_SENTINEL));
|
|
314
1161
|
if (startId && cachedCycle !== startId) {
|
|
315
1162
|
clearAndMarkCycle(twClassesDir, startId);
|
|
316
|
-
} else if (!
|
|
317
|
-
|
|
1163
|
+
} else if (!fs4__default.existsSync(twClassesDir)) {
|
|
1164
|
+
fs4__default.mkdirSync(twClassesDir, { recursive: true });
|
|
318
1165
|
}
|
|
319
1166
|
const outPath = getPerFileSafelistPath(twClassesDir, resourcePath);
|
|
320
1167
|
const sorted = [...new Set(classes)].sort();
|
|
321
1168
|
const css = [
|
|
322
|
-
`/* tw-safelist: ${
|
|
1169
|
+
`/* tw-safelist: ${path4__default.basename(resourcePath)} \u2014 auto-generated */`,
|
|
323
1170
|
"@layer utilities {",
|
|
324
1171
|
sorted.map((cls) => `.${cls.replace(/([^a-zA-Z0-9_-])/g, "\\$1")} {}`).join("\n"),
|
|
325
1172
|
"}"
|
|
326
1173
|
].join("\n");
|
|
327
1174
|
try {
|
|
328
|
-
if (
|
|
1175
|
+
if (fs4__default.readFileSync(outPath, "utf-8") === css) return;
|
|
329
1176
|
} catch {
|
|
330
1177
|
}
|
|
331
1178
|
const tmpPath = `${outPath}.tmp`;
|
|
332
1179
|
try {
|
|
333
|
-
|
|
334
|
-
|
|
1180
|
+
fs4__default.writeFileSync(tmpPath, css, "utf-8");
|
|
1181
|
+
fs4__default.renameSync(tmpPath, outPath);
|
|
335
1182
|
} catch {
|
|
336
1183
|
try {
|
|
337
|
-
|
|
1184
|
+
fs4__default.unlinkSync(tmpPath);
|
|
338
1185
|
} catch {
|
|
339
1186
|
}
|
|
340
|
-
|
|
1187
|
+
fs4__default.writeFileSync(outPath, css, "utf-8");
|
|
341
1188
|
}
|
|
342
1189
|
} catch {
|
|
343
1190
|
}
|
|
@@ -347,7 +1194,7 @@ function turbopackLoader(source, options = {}) {
|
|
|
347
1194
|
const router = detectRouter(this.resourcePath);
|
|
348
1195
|
const nextMajor = parseNum(options.nextMajor);
|
|
349
1196
|
const debug = parseBool(options.debug);
|
|
350
|
-
const filename =
|
|
1197
|
+
const filename = path4__default.basename(this.resourcePath);
|
|
351
1198
|
const effective = {
|
|
352
1199
|
addDataAttr: parseBool(options.addDataAttr),
|
|
353
1200
|
// App Router: selalu auto-detect client boundary
|
|
@@ -362,22 +1209,42 @@ function turbopackLoader(source, options = {}) {
|
|
|
362
1209
|
console.debug(`[tw-loader] ${filename}: router=${router} nextMajor=${nextMajor ?? "unknown"}`);
|
|
363
1210
|
}
|
|
364
1211
|
const { directive, stripped } = extractDirective(source);
|
|
1212
|
+
let processedSource = stripped;
|
|
1213
|
+
try {
|
|
1214
|
+
const compilerMod = (init_internal(), __toCommonJS(internal_exports));
|
|
1215
|
+
if (typeof compilerMod?.injectStateHash === "function" && stripped.includes("states:")) {
|
|
1216
|
+
const hashResult = compilerMod.injectStateHash(stripped, this.resourcePath);
|
|
1217
|
+
if (hashResult.changed) {
|
|
1218
|
+
processedSource = hashResult.code;
|
|
1219
|
+
if (debug) {
|
|
1220
|
+
console.debug(`[tw-loader] ${filename}: injected __hash for ${hashResult.injectedCount} component(s)`);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
} catch {
|
|
1225
|
+
}
|
|
365
1226
|
try {
|
|
366
1227
|
const output = runLoaderTransform({
|
|
367
1228
|
filepath: this.resourcePath,
|
|
368
|
-
source:
|
|
1229
|
+
source: processedSource,
|
|
369
1230
|
options: effective
|
|
370
1231
|
});
|
|
371
1232
|
if (!output.changed) {
|
|
372
1233
|
if (output.classes.length > 0) {
|
|
373
1234
|
writePerFileSafelist(options.safelistPath, this.resourcePath, output.classes);
|
|
374
1235
|
}
|
|
1236
|
+
if (output.staticCss && options.safelistPath) {
|
|
1237
|
+
appendStaticCssToFile(output.staticCss, options.safelistPath);
|
|
1238
|
+
}
|
|
375
1239
|
return source;
|
|
376
1240
|
}
|
|
377
1241
|
if (output.classes.length > 0) {
|
|
378
1242
|
registerFileClasses(this.resourcePath, output.classes);
|
|
379
1243
|
writePerFileSafelist(options.safelistPath, this.resourcePath, output.classes);
|
|
380
1244
|
}
|
|
1245
|
+
if (output.staticCss && options.safelistPath) {
|
|
1246
|
+
appendStaticCssToFile(output.staticCss, options.safelistPath);
|
|
1247
|
+
}
|
|
381
1248
|
if (!directive) return output.code;
|
|
382
1249
|
const clean = output.code.replace(/^\s*["'](use client|use server)["']\s*;?\s*\n?/, "");
|
|
383
1250
|
return directive + clean;
|