tailwind-styled-v4 5.0.7 → 5.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +62 -52
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +62 -52
- package/dist/cli.mjs.map +1 -1
- package/dist/compiler.d.mts +8 -3
- package/dist/compiler.d.ts +8 -3
- package/dist/compiler.js +214 -127
- package/dist/compiler.js.map +1 -1
- package/dist/compiler.mjs +195 -103
- package/dist/compiler.mjs.map +1 -1
- package/dist/engine.js +146 -66
- package/dist/engine.js.map +1 -1
- package/dist/engine.mjs +146 -66
- package/dist/engine.mjs.map +1 -1
- package/dist/next.d.mts +3 -37
- package/dist/next.d.ts +3 -37
- package/dist/next.js +14 -313
- package/dist/next.js.map +1 -1
- package/dist/next.mjs +14 -313
- package/dist/next.mjs.map +1 -1
- package/dist/turbopackLoader.js +132 -86
- package/dist/turbopackLoader.js.map +1 -1
- package/dist/turbopackLoader.mjs +132 -86
- package/dist/turbopackLoader.mjs.map +1 -1
- package/dist/tw.js +62 -52
- package/dist/tw.js.map +1 -1
- package/dist/tw.mjs +62 -52
- package/dist/tw.mjs.map +1 -1
- package/dist/vite.js +146 -66
- package/dist/vite.js.map +1 -1
- package/dist/vite.mjs +146 -66
- package/dist/vite.mjs.map +1 -1
- package/dist/webpackLoader.js +88 -83
- package/dist/webpackLoader.js.map +1 -1
- package/dist/webpackLoader.mjs +88 -83
- package/dist/webpackLoader.mjs.map +1 -1
- package/package.json +3 -3
package/dist/webpackLoader.mjs
CHANGED
|
@@ -3,16 +3,18 @@ import path from 'path';
|
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
/* tailwind-styled-v4 v5.0.4 | MIT | https://github.com/dictionar32/tailwind-styled-v4 */
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
7
8
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
8
9
|
}) : x)(function(x) {
|
|
9
10
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
10
11
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
11
12
|
});
|
|
13
|
+
var __esm = (fn, res) => function __init() {
|
|
14
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
15
|
+
};
|
|
12
16
|
|
|
13
17
|
// packages/domain/shared/src/native-resolution.ts
|
|
14
|
-
var isBrowser = typeof window !== "undefined" || typeof document !== "undefined";
|
|
15
|
-
var nodeModuleRef = null;
|
|
16
18
|
function getNodeModuleRef() {
|
|
17
19
|
if (isBrowser) return null;
|
|
18
20
|
if (nodeModuleRef !== null) return nodeModuleRef;
|
|
@@ -25,9 +27,6 @@ function getNodeModuleRef() {
|
|
|
25
27
|
return null;
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
|
-
var _nodeFs = null;
|
|
29
|
-
var _nodePath = null;
|
|
30
|
-
var _require = null;
|
|
31
30
|
function getNodeFs() {
|
|
32
31
|
if (isBrowser) return { existsSync: () => false };
|
|
33
32
|
const nodeRequire = getNodeModuleRef();
|
|
@@ -53,14 +52,6 @@ function getRequire(_importMetaUrl) {
|
|
|
53
52
|
if (!_require) _require = nodeRequire.createRequire(_importMetaUrl);
|
|
54
53
|
return _require;
|
|
55
54
|
}
|
|
56
|
-
var PLATFORM_MAP = {
|
|
57
|
-
"linux-x64": ["@tailwind-styled/native-linux-x64"],
|
|
58
|
-
"linux-arm64": ["@tailwind-styled/native-linux-arm64"],
|
|
59
|
-
"darwin-x64": ["@tailwind-styled/native-darwin-x64"],
|
|
60
|
-
"darwin-arm64": ["@tailwind-styled/native-darwin-arm64"],
|
|
61
|
-
"win32-x64": ["@tailwind-styled/native-win32-x64"],
|
|
62
|
-
"win32-arm64": ["@tailwind-styled/native-win32-arm64"]
|
|
63
|
-
};
|
|
64
55
|
function platformKey() {
|
|
65
56
|
if (isBrowser) return "browser";
|
|
66
57
|
return `${process.platform}-${process.arch}`;
|
|
@@ -114,10 +105,26 @@ function resolveNativeBinary(runtimeDir) {
|
|
|
114
105
|
}
|
|
115
106
|
return { path: null, source: "not-found", platform, tried };
|
|
116
107
|
}
|
|
108
|
+
var isBrowser, nodeModuleRef, _nodeFs, _nodePath, _require, PLATFORM_MAP;
|
|
109
|
+
var init_native_resolution = __esm({
|
|
110
|
+
"packages/domain/shared/src/native-resolution.ts"() {
|
|
111
|
+
isBrowser = typeof window !== "undefined" || typeof document !== "undefined";
|
|
112
|
+
nodeModuleRef = null;
|
|
113
|
+
_nodeFs = null;
|
|
114
|
+
_nodePath = null;
|
|
115
|
+
_require = null;
|
|
116
|
+
PLATFORM_MAP = {
|
|
117
|
+
"linux-x64": ["@tailwind-styled/native-linux-x64"],
|
|
118
|
+
"linux-arm64": ["@tailwind-styled/native-linux-arm64"],
|
|
119
|
+
"darwin-x64": ["@tailwind-styled/native-darwin-x64"],
|
|
120
|
+
"darwin-arm64": ["@tailwind-styled/native-darwin-arm64"],
|
|
121
|
+
"win32-x64": ["@tailwind-styled/native-win32-x64"],
|
|
122
|
+
"win32-arm64": ["@tailwind-styled/native-win32-arm64"]
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
});
|
|
117
126
|
|
|
118
127
|
// packages/domain/shared/src/index.ts
|
|
119
|
-
var isBrowser2 = typeof window !== "undefined" || typeof document !== "undefined";
|
|
120
|
-
var nodeModuleRef2 = null;
|
|
121
128
|
function getNodeModuleRef2() {
|
|
122
129
|
if (isBrowser2) return null;
|
|
123
130
|
if (nodeModuleRef2 !== null) return nodeModuleRef2;
|
|
@@ -130,7 +137,6 @@ function getNodeModuleRef2() {
|
|
|
130
137
|
return null;
|
|
131
138
|
}
|
|
132
139
|
}
|
|
133
|
-
var _nodeUrl = null;
|
|
134
140
|
function getNodeUrl() {
|
|
135
141
|
if (isBrowser2) throw new Error("node:url not available in browser");
|
|
136
142
|
const nodeRequire = getNodeModuleRef2();
|
|
@@ -148,7 +154,6 @@ function getRequire2() {
|
|
|
148
154
|
});
|
|
149
155
|
return nodeRequire.createRequire(import.meta.url);
|
|
150
156
|
}
|
|
151
|
-
getRequire2();
|
|
152
157
|
function resolveRuntimeDir(dir, importMetaUrl) {
|
|
153
158
|
if (isBrowser2) return "";
|
|
154
159
|
try {
|
|
@@ -157,57 +162,80 @@ function resolveRuntimeDir(dir, importMetaUrl) {
|
|
|
157
162
|
return process.cwd();
|
|
158
163
|
}
|
|
159
164
|
}
|
|
160
|
-
var
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
var bridgeLoadError = null;
|
|
169
|
-
var isValidNativeBridge = (mod) => {
|
|
170
|
-
const m = mod;
|
|
171
|
-
return !!(typeof m.transformSource === "function" || typeof m.extractAllClasses === "function" || typeof m.hasTwUsage === "function");
|
|
172
|
-
};
|
|
173
|
-
var getNativeBridge = () => {
|
|
174
|
-
if (nativeBridge) {
|
|
175
|
-
return nativeBridge;
|
|
176
|
-
}
|
|
177
|
-
if (bridgeLoadAttempted) {
|
|
178
|
-
if (bridgeLoadError) {
|
|
179
|
-
throw bridgeLoadError;
|
|
180
|
-
}
|
|
181
|
-
throw new Error(NATIVE_UNAVAILABLE_MESSAGE);
|
|
165
|
+
var isBrowser2, nodeModuleRef2, _nodeUrl;
|
|
166
|
+
var init_src = __esm({
|
|
167
|
+
"packages/domain/shared/src/index.ts"() {
|
|
168
|
+
init_native_resolution();
|
|
169
|
+
isBrowser2 = typeof window !== "undefined" || typeof document !== "undefined";
|
|
170
|
+
nodeModuleRef2 = null;
|
|
171
|
+
_nodeUrl = null;
|
|
172
|
+
getRequire2();
|
|
182
173
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
174
|
+
});
|
|
175
|
+
var log, NATIVE_UNAVAILABLE_MESSAGE, nativeBridge, bridgeLoadAttempted, bridgeLoadError, isValidNativeBridge, getNativeBridge;
|
|
176
|
+
var init_nativeBridge = __esm({
|
|
177
|
+
"packages/domain/compiler/src/nativeBridge.ts"() {
|
|
178
|
+
init_src();
|
|
179
|
+
log = (...args) => {
|
|
180
|
+
if (process.env.DEBUG?.includes("compiler:native")) {
|
|
181
|
+
console.log("[compiler:native]", ...args);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
NATIVE_UNAVAILABLE_MESSAGE = "[tailwind-styled/compiler v5] Native binding is required but not available.\nThis package requires native Rust bindings. There is no JavaScript fallback.\nPlease ensure:\n 1. The native module is properly installed\n 2. You have run: npm run build:rust (or use prebuilt binary)\n\nFor help, see: https://tailwind-styled.dev/docs/install";
|
|
185
|
+
nativeBridge = null;
|
|
186
|
+
bridgeLoadAttempted = false;
|
|
187
|
+
bridgeLoadError = null;
|
|
188
|
+
isValidNativeBridge = (mod) => {
|
|
189
|
+
const m = mod;
|
|
190
|
+
return !!(typeof m.transformSource === "function" || typeof m.extractAllClasses === "function" || typeof m.hasTwUsage === "function");
|
|
191
|
+
};
|
|
192
|
+
getNativeBridge = () => {
|
|
193
|
+
if (nativeBridge) {
|
|
194
|
+
return nativeBridge;
|
|
195
|
+
}
|
|
196
|
+
if (bridgeLoadAttempted) {
|
|
197
|
+
if (bridgeLoadError) {
|
|
198
|
+
throw bridgeLoadError;
|
|
195
199
|
}
|
|
196
|
-
|
|
197
|
-
log("Failed to require native binding:", e);
|
|
200
|
+
throw new Error(NATIVE_UNAVAILABLE_MESSAGE);
|
|
198
201
|
}
|
|
199
|
-
|
|
200
|
-
|
|
202
|
+
bridgeLoadAttempted = true;
|
|
203
|
+
try {
|
|
204
|
+
const runtimeDir = resolveRuntimeDir(void 0, import.meta.url);
|
|
205
|
+
const require2 = createRequire(import.meta.url);
|
|
206
|
+
const result = resolveNativeBinary(runtimeDir);
|
|
207
|
+
if (result.path && result.path.endsWith(".node")) {
|
|
208
|
+
try {
|
|
209
|
+
const binding = require2(result.path);
|
|
210
|
+
if (isValidNativeBridge(binding)) {
|
|
211
|
+
nativeBridge = binding;
|
|
212
|
+
log("Native bridge loaded successfully from:", result.path);
|
|
213
|
+
return nativeBridge;
|
|
214
|
+
}
|
|
215
|
+
} catch (e) {
|
|
216
|
+
log("Failed to require native binding:", e);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
throw new Error(`${NATIVE_UNAVAILABLE_MESSAGE}
|
|
201
220
|
|
|
202
221
|
Tried paths: ${result.tried.join("\n")}`);
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
222
|
+
} catch (err) {
|
|
223
|
+
bridgeLoadError = err instanceof Error ? err : new Error(String(err));
|
|
224
|
+
log("Failed to load native bridge:", bridgeLoadError.message);
|
|
225
|
+
throw bridgeLoadError;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
if (typeof process !== "undefined" && !bridgeLoadAttempted) {
|
|
229
|
+
try {
|
|
230
|
+
getNativeBridge();
|
|
231
|
+
} catch {
|
|
232
|
+
}
|
|
233
|
+
}
|
|
207
234
|
}
|
|
208
|
-
};
|
|
235
|
+
});
|
|
209
236
|
|
|
210
237
|
// packages/domain/compiler/src/index.ts
|
|
238
|
+
init_nativeBridge();
|
|
211
239
|
var transformSource = (source, opts) => {
|
|
212
240
|
const native = getNativeBridge();
|
|
213
241
|
if (!native?.transformSource) {
|
|
@@ -239,30 +267,7 @@ var shouldSkipFile = (filepath) => {
|
|
|
239
267
|
}
|
|
240
268
|
return false;
|
|
241
269
|
};
|
|
242
|
-
var fileToRoute = (filepath) => {
|
|
243
|
-
const normalized = filepath.replace(/\\/g, "/");
|
|
244
|
-
if (normalized.includes("/layout.") || normalized.includes("/loading.") || normalized.includes("/error.")) {
|
|
245
|
-
return "__global";
|
|
246
|
-
}
|
|
247
|
-
const appPageMatch = normalized.match(/\/app\/(.+?)\/page\.[tj]sx?$/);
|
|
248
|
-
if (appPageMatch) return `/${appPageMatch[1]}`;
|
|
249
|
-
const appRootPage = normalized.match(/\/app\/page\.[tj]sx?$/);
|
|
250
|
-
if (appRootPage) return "/";
|
|
251
|
-
const pagesMatch = normalized.match(/\/pages\/(.+?)\.[tj]sx?$/);
|
|
252
|
-
if (pagesMatch) {
|
|
253
|
-
const pagePath = pagesMatch[1];
|
|
254
|
-
if (pagePath.startsWith("_") || pagePath.startsWith("api/")) return "__global";
|
|
255
|
-
return pagePath === "index" ? "/" : `/${pagePath}`;
|
|
256
|
-
}
|
|
257
|
-
return null;
|
|
258
|
-
};
|
|
259
|
-
var _routeClassMap = /* @__PURE__ */ new Map();
|
|
260
270
|
var registerFileClasses = (filepath, classes) => {
|
|
261
|
-
if (!classes.length) return;
|
|
262
|
-
const route = fileToRoute(filepath) ?? "__global";
|
|
263
|
-
const existing = _routeClassMap.get(route) ?? /* @__PURE__ */ new Set();
|
|
264
|
-
for (const cls of classes) existing.add(cls);
|
|
265
|
-
_routeClassMap.set(route, existing);
|
|
266
271
|
};
|
|
267
272
|
var WebpackLoaderOptionsSchema = z.object({
|
|
268
273
|
mode: z.literal("zero-runtime").optional(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../packages/domain/shared/src/native-resolution.ts","../packages/domain/shared/src/index.ts","../packages/domain/compiler/src/nativeBridge.ts","../packages/domain/compiler/src/index.ts","../packages/presentation/next/src/webpackLoader.ts"],"names":["path","isBrowser","nodeModuleRef","getNodeModuleRef","getRequire","require"],"mappings":";;;;;;;;;;;;;AAUA,IAAM,SAAA,GAAY,OAAO,MAAA,KAAW,WAAA,IAAe,OAAO,QAAA,KAAa,WAAA;AAGvE,IAAI,aAAA,GAAqB,IAAA;AACzB,SAAS,gBAAA,GAAmB;AAC1B,EAAA,IAAI,WAAW,OAAO,IAA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AA,KAAa,YAAA,EAAc;AACzC,MAAA,QAAA,CAAS,GAAA,YAAe,QAAQ,GAAA,GAAM,IAAI,MAAM,MAAA,CAAO,GAAG,CAAC,CAAC,CAAA;AAC5D,MAAA;AAAA,IACF;AAEA,IAAA,OAAA,CAAQ,IAAA,CAAK,CAAA,kDAAA,EAAqD,QAAQ,CAAA,CAAA,CAAA,EAAK,GAAG,CAAA;AAClF,IAAA,QAAA,CAAS,MAAM,MAAM,CAAA;AAAA,EACvB;AACF","file":"webpackLoader.mjs","sourcesContent":["/**\r\n * Prebuilt binary resolution untuk native NAPI bindings.\r\n * QA #1: Resolve native binary dari prebuilt packages atau local build.\r\n *\r\n * Prioritas:\r\n * 1. TW_NATIVE_PATH env var (explicit override)\r\n * 2. Prebuilt binary dari platform-specific npm package\r\n * 3. Local build dari source (developer mode)\r\n */\r\n\r\nconst isBrowser = typeof window !== \"undefined\" || typeof document !== \"undefined\"\r\n\r\n// ESM-safe require detection\r\nlet nodeModuleRef: any = null\r\nfunction getNodeModuleRef() {\r\n if (isBrowser) return null\r\n if (nodeModuleRef !== null) return nodeModuleRef\r\n try {\r\n const test = typeof require === 'function' ? require('node:module') : null\r\n nodeModuleRef = test\r\n return test\r\n } catch {\r\n nodeModuleRef = null\r\n return null\r\n }\r\n}\r\n\r\nlet _nodeFs: any = null\r\nlet _nodePath: any = null\r\nlet _nodeModule: any = null\r\nlet _require: any = null\r\n\r\nfunction getNodeFs() {\r\n if (isBrowser) return { existsSync: () => false }\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) return { existsSync: () => false }\r\n if (!_nodeFs) _nodeFs = nodeRequire.createRequire(import.meta.url)(\"node:fs\")\r\n return _nodeFs\r\n}\r\nfunction getNodePath() {\r\n if (isBrowser) return { resolve: () => \"\", dirname: \"\" }\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) return { resolve: () => \"\", dirname: \"\" }\r\n if (!_nodePath) _nodePath = nodeRequire.createRequire(import.meta.url)(\"node:path\")\r\n return _nodePath!\r\n}\r\nfunction getNodeModule() {\r\n if (isBrowser) return { createRequire: () => { throw new Error(\"node:module not available\") } }\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) return { createRequire: () => { throw new Error(\"require not available\") } }\r\n if (!_nodeModule) _nodeModule = nodeRequire\r\n return _nodeModule\r\n}\r\nfunction getRequire(_importMetaUrl: string) {\r\n if (isBrowser) return () => { throw new Error(\"node:module not available\") }\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) return () => { throw new Error(\"require not available\") }\r\n if (!_require) _require = nodeRequire.createRequire(_importMetaUrl)\r\n return _require\r\n}\r\n\r\nexport interface NativeResolutionResult {\r\n path: string | null\r\n source: \"env\" | \"prebuilt\" | \"local\" | \"not-found\"\r\n platform: string\r\n tried: string[]\r\n}\r\n\r\n/** Platform key → prebuilt npm package name */\r\nconst PLATFORM_MAP: Record<string, string[]> = {\r\n \"linux-x64\": [\"@tailwind-styled/native-linux-x64\"],\r\n \"linux-arm64\": [\"@tailwind-styled/native-linux-arm64\"],\r\n \"darwin-x64\": [\"@tailwind-styled/native-darwin-x64\"],\r\n \"darwin-arm64\": [\"@tailwind-styled/native-darwin-arm64\"],\r\n \"win32-x64\": [\"@tailwind-styled/native-win32-x64\"],\r\n \"win32-arm64\": [\"@tailwind-styled/native-win32-arm64\"],\r\n}\r\n\r\nfunction platformKey(): string {\r\n if (isBrowser) return \"browser\"\r\n return `${process.platform}-${process.arch}`\r\n}\r\n\r\n/**\r\n * Resolve native binary path dari semua sumber yang tersedia.\r\n *\r\n * @example\r\n * const result = resolveNativeBinary()\r\n * if (result.path) {\r\n * const binding = require(result.path)\r\n * } else {\r\n * throw new Error(\"Native binding not found — run npm run build:rust\")\r\n * }\r\n */\r\nexport function resolveNativeBinary(runtimeDir?: string): NativeResolutionResult {\r\n const platform = platformKey()\r\n const tried: string[] = []\r\n\r\n if (isBrowser) {\r\n return { path: null, source: \"not-found\", platform, tried: [\"not available in browser\"] }\r\n }\r\n\r\n const fs = getNodeFs()\r\n const path = getNodePath()\r\n const _req = getRequire(import.meta.url)\r\n\r\n // 1. Env var override\r\n const envPath = process.env.TW_NATIVE_PATH?.trim()\r\n if (envPath) {\r\n if (fs.existsSync(envPath)) {\r\n return { path: envPath, source: \"env\", platform, tried }\r\n }\r\n tried.push(`env:${envPath} (not found)`)\r\n }\r\n\r\n // 2. Skip jika disabled\r\n if (\r\n process.env.TWS_NO_NATIVE === \"1\" ||\r\n process.env.TWS_NO_RUST === \"1\" ||\r\n process.env.TWS_DISABLE_NATIVE === \"1\"\r\n ) {\r\n return { path: null, source: \"not-found\", platform, tried: [\"disabled by env\"] }\r\n }\r\n\r\n // 3. Prebuilt binary dari platform-specific npm package\r\n const prebuiltPkgs = PLATFORM_MAP[platform] ?? []\r\n for (const pkg of prebuiltPkgs) {\r\n try {\r\n const candidate = _req.resolve(`${pkg}/tailwind_styled_parser.node`)\r\n if (fs.existsSync(candidate)) {\r\n return { path: candidate, source: \"prebuilt\", platform, tried }\r\n }\r\n tried.push(`prebuilt:${pkg} (resolved but missing)`)\r\n } catch {\r\n tried.push(`prebuilt:${pkg} (not installed)`)\r\n }\r\n }\r\n\r\n // 4. Local build candidates\r\n const cwd = process.cwd()\r\n const base = runtimeDir ?? cwd\r\n const localCandidates = [\r\n path.resolve(base, \"tailwind_styled_parser.node\"),\r\n path.resolve(base, \"..\", \"tailwind_styled_parser.node\"),\r\n path.resolve(cwd, \"native\", \"tailwind_styled_parser.node\"),\r\n path.resolve(cwd, \"native\", \"target\", \"release\", \"tailwind_styled_parser.node\"),\r\n // napi-rs conventional output\r\n path.resolve(base, `tailwind_styled_parser.${platform}.node`),\r\n ]\r\n\r\n for (const candidate of localCandidates) {\r\n tried.push(`local:${candidate}`)\r\n if (fs.existsSync(candidate)) {\r\n return { path: candidate, source: \"local\", platform, tried }\r\n }\r\n }\r\n\r\n return { path: null, source: \"not-found\", platform, tried }\r\n}\r\n\r\n/**\r\n * Format human-readable error untuk \"binary not found\".\r\n */\r\nexport function formatNativeNotFoundError(result: NativeResolutionResult): string {\r\n const lines = [\r\n `[tailwind-styled] Native binding not found for ${result.platform}`,\r\n ``,\r\n `Tried:`,\r\n ...result.tried.map(t => ` - ${t}`),\r\n ``,\r\n `Solutions:`,\r\n ` 1. Build locally: npm run build:rust`,\r\n ` 2. Install prebuilt: npm install @tailwind-styled/native-${result.platform}`,\r\n ` 3. Override path: TW_NATIVE_PATH=/path/to/parser.node`,\r\n ` 4. Disable native: TWS_DISABLE_NATIVE=1 (slower, JS fallback)`,\r\n ]\r\n return lines.join(\"\\n\")\r\n}\r\n","const isBrowser = typeof window !== \"undefined\" || typeof document !== \"undefined\"\r\n\r\n// ESM-safe require detection\r\nlet nodeModuleRef: any = null\r\nfunction getNodeModuleRef() {\r\n if (isBrowser) return null\r\n if (nodeModuleRef !== null) return nodeModuleRef\r\n try {\r\n const test = typeof require === 'function' ? require('node:module') : null\r\n nodeModuleRef = test\r\n return test\r\n } catch {\r\n nodeModuleRef = null\r\n return null\r\n }\r\n}\r\n\r\nlet _nodeCrypto: any = null\r\nlet _nodeFs: any = null\r\nlet _nodeModule: any = null\r\nlet _nodePath: any = null\r\nlet _nodeUrl: any = null\r\n\r\nfunction getNodeCrypto() {\r\n if (isBrowser) throw new Error(\"node:crypto not available in browser\")\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) throw new Error(\"require not available\")\r\n if (!_nodeCrypto) _nodeCrypto = nodeRequire.createRequire(import.meta.url)(\"node:crypto\")\r\n return _nodeCrypto!\r\n}\r\nfunction getNodeFs() {\r\n if (isBrowser) throw new Error(\"node:fs not available in browser\")\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) throw new Error(\"require not available\")\r\n if (!_nodeFs) _nodeFs = nodeRequire.createRequire(import.meta.url)(\"node:fs\")\r\n return _nodeFs!\r\n}\r\nfunction getNodeModule() {\r\n if (isBrowser) throw new Error(\"node:module not available in browser\")\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) throw new Error(\"require not available\")\r\n if (!_nodeModule) _nodeModule = nodeRequire\r\n return _nodeModule!\r\n}\r\nfunction getNodePath() {\r\n if (isBrowser) throw new Error(\"node:path not available in browser\")\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) throw new Error(\"require not available\")\r\n if (!_nodePath) _nodePath = nodeRequire.createRequire(import.meta.url)(\"node:path\")\r\n return _nodePath!\r\n}\r\nfunction getNodeUrl() {\r\n if (isBrowser) throw new Error(\"node:url not available in browser\")\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) throw new Error(\"require not available\")\r\n if (!_nodeUrl) _nodeUrl = nodeRequire.createRequire(import.meta.url)(\"node:url\")\r\n return _nodeUrl!\r\n}\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Types\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport type TokenMap = Record<string, string>\r\n\r\nexport type VariantValue = string | number | boolean | undefined\r\n\r\nexport type VariantProps = Record<string, VariantValue>\r\n\r\nexport type HtmlTagName = keyof HTMLElementTagNameMap\r\n\r\nexport type CompoundCondition = Record<string, string | number | boolean>\r\n\r\nexport type VariantMatrix = Record<string, Array<string | number | boolean>>\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Logging\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport interface Logger {\r\n warn(...args: unknown[]): void\r\n debug(...args: unknown[]): void\r\n error(...args: unknown[]): void\r\n log(...args: unknown[]): void\r\n}\r\n\r\nexport function createLogger(namespace: string): Logger {\r\n const prefix = `[${namespace}]`\r\n return {\r\n warn(...args: unknown[]) {\r\n process.stderr.write(`${prefix} ${args.map(a => typeof a === \"string\" ? a : String(a)).join(\" \")}\\n`)\r\n },\r\n debug(...args: unknown[]) {\r\n process.stderr.write(`${prefix} ${args.map(a => typeof a === \"string\" ? a : String(a)).join(\" \")}\\n`)\r\n },\r\n error(...args: unknown[]) {\r\n process.stderr.write(`${prefix} ${args.map(a => typeof a === \"string\" ? a : String(a)).join(\" \")}\\n`)\r\n },\r\n log(...args: unknown[]) {\r\n process.stderr.write(`${prefix} ${args.map(a => typeof a === \"string\" ? a : String(a)).join(\" \")}\\n`)\r\n },\r\n }\r\n}\r\n\r\nexport function createDebugLogger(namespace: string, label?: string): (msg: string) => void {\r\n const prefix = label ? `[${namespace}:${label}]` : `[${namespace}]`\r\n return (msg: string) => {\r\n if (process.env.DEBUG?.includes(namespace) || process.env.TW_DEBUG) {\r\n console.debug(prefix, msg)\r\n }\r\n }\r\n}\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Error handling\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport type ErrorSource = \"rust\" | \"validation\" | \"compile\" | \"io\" | \"config\" | \"unknown\"\r\n\r\ntype ZodLikeIssue = {\r\n path?: readonly PropertyKey[]\r\n message?: string\r\n}\r\n\r\nfunction formatIssuePath(path?: readonly PropertyKey[]): string {\r\n if (!path || path.length === 0) return \"(root)\"\r\n return path\r\n .map((segment) =>\r\n typeof segment === \"symbol\" ? segment.description ?? segment.toString() : String(segment)\r\n )\r\n .join(\".\")\r\n}\r\n\r\nexport class TwError extends Error {\r\n /** @deprecated Gunakan source */\r\n public readonly domain: string\r\n public readonly source: ErrorSource\r\n public readonly code: string\r\n public readonly originalCause?: unknown\r\n\r\n constructor(domainOrSource: string, code: string, message: string, cause?: unknown) {\r\n super(message)\r\n this.name = \"TwError\"\r\n this.domain = domainOrSource\r\n this.source = domainOrSource as ErrorSource\r\n this.code = code\r\n this.originalCause = cause\r\n if (Error.captureStackTrace) Error.captureStackTrace(this, TwError)\r\n }\r\n\r\n static fromIo(code: string, message: string): TwError {\r\n return new TwError(\"io\", code, message)\r\n }\r\n\r\n static fromCompile(code: string, message: string): TwError {\r\n return new TwError(\"compile\", code, message)\r\n }\r\n\r\n static fromRust(err: { code?: string; message?: string } | Error | unknown): TwError {\r\n if (err instanceof TwError) return err\r\n if (err instanceof Error) return new TwError(\"rust\", \"RUST_ERROR\", err.message, err)\r\n if (err && typeof err === \"object\") {\r\n const e = err as { code?: string; message?: string }\r\n return new TwError(\"rust\", e.code ?? \"RUST_ERROR\", e.message ?? String(err), err)\r\n }\r\n return new TwError(\"rust\", \"RUST_ERROR\", String(err), err)\r\n }\r\n\r\n /** Buat TwError dari ZodError — dukung shape Zod v3 (`errors`) dan v4 (`issues`). */\r\n static fromZod(err: { issues?: ZodLikeIssue[]; errors?: ZodLikeIssue[] }): TwError {\r\n const first = err.issues?.[0] ?? err.errors?.[0]\r\n const path = formatIssuePath(first?.path)\r\n const message = first ? `${path}: ${first.message}` : \"Schema validation failed\"\r\n return new TwError(\"validation\", \"SCHEMA_VALIDATION_FAILED\", message, err)\r\n }\r\n\r\n static wrap(source: string, code: string, err: unknown): TwError {\r\n if (err instanceof TwError) return err\r\n if (err instanceof Error) return new TwError(source, code, err.message, err)\r\n return new TwError(source, code, String(err), err)\r\n }\r\n\r\n override toString(): string {\r\n return `TwError [${this.source}:${this.code}] ${this.message}`\r\n }\r\n\r\n toJSON(): { name: string; source: string; code: string; message: string } {\r\n return { name: this.name, source: this.source, code: this.code, message: this.message }\r\n }\r\n\r\n toCliMessage(): string {\r\n return `[${this.source.toUpperCase()}:${this.code}] ${this.message}`\r\n }\r\n}\r\n\r\nexport function wrapUnknownError(domain: string, code: string, error: unknown): TwError {\r\n return TwError.wrap(domain, code, error)\r\n}\r\n\r\nexport function isTwError(err: unknown): err is TwError {\r\n return err instanceof TwError\r\n}\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Native binding resolution\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport interface LoadNativeBindingOptions<T> {\r\n runtimeDir: string\r\n candidates: string[]\r\n isValid: (module: unknown) => module is T\r\n invalidExportMessage: string\r\n}\r\n\r\nexport interface LoadNativeBindingResult<T> {\r\n binding: T | null\r\n loadErrors: Array<{ path: string; message: string }>\r\n loadedPath?: string\r\n}\r\n\r\nexport function loadNativeBinding<T>(options: LoadNativeBindingOptions<T>): LoadNativeBindingResult<T> {\r\n if (isBrowser) {\r\n return { binding: null, loadErrors: [{ path: \"\", message: \"Native bindings not available in browser\" }] }\r\n }\r\n \r\n const { runtimeDir, candidates, isValid } = options\r\n const loadErrors: Array<{ path: string; message: string }> = []\r\n const path = getNodePath()\r\n const fs = getNodeFs()\r\n\r\n for (const candidate of candidates) {\r\n const candidatePath = path.resolve(runtimeDir, candidate)\r\n try {\r\n if (!fs.existsSync(candidatePath) && !fs.existsSync(candidatePath + \".node\")) {\r\n continue\r\n }\r\n const mod = requireNativeModule(candidatePath)\r\n if (mod && isValid(mod)) {\r\n return { binding: mod, loadErrors, loadedPath: candidatePath }\r\n }\r\n loadErrors.push({ path: candidatePath, message: options.invalidExportMessage })\r\n } catch (e) {\r\n loadErrors.push({ path: candidatePath, message: e instanceof Error ? e.message : String(e) })\r\n }\r\n }\r\n\r\n return { binding: null, loadErrors }\r\n}\r\n\r\nfunction getRequire(): NodeRequire {\r\n if (isBrowser) return (() => { throw new Error(\"require not available in browser\") }) as unknown as NodeRequire\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) return (() => { throw new Error(\"require not available\") }) as unknown as NodeRequire\r\n return nodeRequire.createRequire(import.meta.url)\r\n}\r\n\r\nconst _require = getRequire()\r\n\r\nfunction requireNativeModule(path: string): unknown {\r\n return _require(path)\r\n}\r\n\r\nexport interface ResolveCandidatesOptions {\r\n runtimeDir: string\r\n envVarNames?: string[]\r\n includeDefaultCandidates?: boolean\r\n enforceNodeExtensionForEnvPath?: boolean\r\n}\r\n\r\nexport function resolveNativeBindingCandidates(options: ResolveCandidatesOptions): string[] {\r\n if (isBrowser) return []\r\n \r\n const { runtimeDir, envVarNames = [], includeDefaultCandidates = true, enforceNodeExtensionForEnvPath = false } = options\r\n const candidates: string[] = []\r\n const path = getNodePath()\r\n const fs = getNodeFs()\r\n\r\n for (const envVar of envVarNames) {\r\n const envPath = process.env[envVar]\r\n if (envPath) {\r\n if (enforceNodeExtensionForEnvPath && !envPath.endsWith(\".node\")) {\r\n candidates.push(envPath + \".node\")\r\n } else {\r\n candidates.push(envPath)\r\n }\r\n }\r\n }\r\n\r\n if (!includeDefaultCandidates) return candidates\r\n\r\n if (fs.existsSync(runtimeDir)) {\r\n try {\r\n const entries = fs.readdirSync(runtimeDir)\r\n for (const entry of entries) {\r\n if (entry.endsWith(\".node\")) {\r\n candidates.push(entry)\r\n }\r\n }\r\n } catch {\r\n // ignore read errors\r\n }\r\n }\r\n\r\n const platform = typeof process !== \"undefined\" ? process.platform : \"\"\r\n const ext = platform === \"win32\" ? \".dll\" : platform === \"darwin\" ? \".dylib\" : \".so\"\r\n const defaultBindingName = `tailwind_styled_parser${ext}`\r\n candidates.push(path.resolve(runtimeDir, \"..\", \"..\", \"..\", \"native\", defaultBindingName))\r\n candidates.push(path.resolve(runtimeDir, \"..\", \"..\", \"..\", \"..\", \"native\", defaultBindingName))\r\n candidates.push(path.resolve(process.cwd(), \"native\", defaultBindingName))\r\n\r\n return Array.from(new Set(candidates))\r\n}\r\n\r\nexport function resolveRuntimeDir(dir: string | undefined, importMetaUrl: string): string {\r\n if (isBrowser) return \"\"\r\n \r\n if (dir) return getNodePath().resolve(dir)\r\n try {\r\n return getNodeUrl().fileURLToPath(importMetaUrl)\r\n } catch {\r\n return process.cwd()\r\n }\r\n}\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Hashing\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport function hashContent(content: string, algorithm: string = \"md5\", length?: number): string {\r\n if (isBrowser) {\r\n // Simple hash fallback for browser\r\n let hash = 0\r\n for (let i = 0; i < content.length; i++) {\r\n const char = content.charCodeAt(i)\r\n hash = ((hash << 5) - hash) + char\r\n hash = hash & hash\r\n }\r\n return Math.abs(hash).toString(16).slice(0, length ?? 8)\r\n }\r\n const hash = getNodeCrypto().createHash(algorithm).update(content).digest(\"hex\")\r\n return length ? hash.slice(0, length) : hash\r\n}\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Error formatting\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport function formatErrorMessage(error: unknown): string {\r\n if (error instanceof TwError) return error.toString()\r\n if (error instanceof Error) return error.message\r\n return String(error)\r\n}\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// LRU Cache\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport class LRUCache<K, V> {\r\n private capacity: number\r\n private cache: Map<K, V>\r\n\r\n constructor(capacity: number) {\r\n this.capacity = capacity\r\n this.cache = new Map()\r\n }\r\n\r\n get(key: K): V | undefined {\r\n if (!this.cache.has(key)) return undefined\r\n const value = this.cache.get(key)!\r\n this.cache.delete(key)\r\n this.cache.set(key, value)\r\n return value\r\n }\r\n\r\n set(key: K, value: V): void {\r\n if (this.cache.has(key)) {\r\n this.cache.delete(key)\r\n } else if (this.cache.size >= this.capacity) {\r\n const firstKey = this.cache.keys().next().value\r\n if (firstKey !== undefined) {\r\n this.cache.delete(firstKey)\r\n }\r\n }\r\n this.cache.set(key, value)\r\n }\r\n\r\n delete(key: K): boolean {\r\n return this.cache.delete(key)\r\n }\r\n\r\n has(key: K): boolean {\r\n return this.cache.has(key)\r\n }\r\n\r\n clear(): void {\r\n this.cache.clear()\r\n }\r\n\r\n entries(): IterableIterator<[K, V]> {\r\n return this.cache.entries()\r\n }\r\n\r\n get size(): number {\r\n return this.cache.size\r\n }\r\n}\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Trace Utilities\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport type { TraceSnapshot, TraceSummary } from \"./trace\"\r\nexport {\r\n getHealthColor,\r\n getModeColor,\r\n formatMemory,\r\n formatDuration,\r\n calculateHealth,\r\n getBuildTimeColor,\r\n getMemoryColor,\r\n createTraceSnapshot,\r\n getPipelinePercentages,\r\n} from \"./trace\"\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Performance Telemetry\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\n\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Error Codes\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport type { ErrorCode } from \"./error-codes\"\r\nexport { ERROR_CODES, getSuggestion, formatErrorCode } from \"./error-codes\"\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Tailwind Compatibility\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport type { TailwindInfo } from \"./compatibility\"\r\nexport { detectTailwind, assertTailwindV4, getTailwindVersion, isTailwindV4 } from \"./compatibility\"\r\n\r\n// ── Native binding schemas (Zod boundary validation)\r\nexport {\r\n NativeScanFileSchema, NativeScanResultSchema,\r\n NativeAnalyzerReportSchema, NativeTransformResultSchema,\r\n NativeCssCompileResultSchema, NativeWatchResultSchema,\r\n NativeCacheEntrySchema, NativeCacheReadResultSchema,\r\n safeParseNative, parseNative,\r\n} from './native-schemas'\r\n\r\n// ── ESM-safe runtime helpers ──────────────────────────────────────────────\r\nexport {\r\n createEsmRequire,\r\n getDirname,\r\n getFilename,\r\n resolveFromRoot,\r\n tryRequire,\r\n resolveNativeNodePath,\r\n} from \"./esmHelpers\"\r\n\r\n// ── Performance telemetry ────────────────────────────────────────────────────\r\nexport {\r\n TelemetryCollector,\r\n getGlobalTelemetry,\r\n resetGlobalTelemetry,\r\n createBuildTimer,\r\n type BuildTelemetry,\r\n type TelemetrySummary,\r\n type BuildPhases,\r\n} from \"./telemetry\"\r\n\r\n// ── Config/JSON schema validation ─────────────────────────────────────────────\r\nexport {\r\n ScanCacheSchema,\r\n ScanCacheClassEntrySchema,\r\n TailwindConfigSchema,\r\n RegistryPluginEntrySchema,\r\n RegistryFileSchema,\r\n PackageJsonSchema,\r\n parseJsonWithSchema,\r\n parseJsonFileWithSchema,\r\n type ScanCache,\r\n type ScanCacheClassEntry,\r\n type TailwindConfig,\r\n type RegistryPluginEntry,\r\n type RegistryFile,\r\n type PackageJson,\r\n} from \"./configSchemas\"\r\n\r\n// ── Worker/bootstrap path resolution ─────────────────────────────────────────\r\nexport {\r\n resolveWorkerPath,\r\n resolveLoaderPath,\r\n type WorkerPathOptions,\r\n type WorkerPathResult,\r\n} from \"./workerResolver\"\r\n\r\n// ── Codegen helpers ───────────────────────────────────────────────────────────\r\nexport {\r\n generateComponentCode,\r\n generateStorybookStory,\r\n generateClassRenameCodemod,\r\n generateBarrelFile,\r\n type ComponentCodegenOptions,\r\n} from \"./codegen\"\r\n\r\n// ── Native binary resolution (QA #1) ─────────────────────────────────────────\r\nexport {\r\n resolveNativeBinary,\r\n formatNativeNotFoundError,\r\n type NativeResolutionResult,\r\n} from \"./native-resolution\"\r\n\r\n// ── Shared observability contract ────────────────────────────────────────────\r\nexport {\r\n createObservabilityClient,\r\n type ClassInspection,\r\n type ClassProperty,\r\n type ClassUsageLocation,\r\n type BuildTrace,\r\n type BuildPhaseTrace,\r\n type DashboardMetrics,\r\n type DashboardSummary,\r\n type ObservabilityClient,\r\n} from \"./observability\"\r\n","/**\r\n * tailwind-styled-v5 — Native Bridge Loader\r\n *\r\n * Uses @tailwind-styled/shared for native binding resolution.\r\n * All functions require native Rust binding - no JS fallback.\r\n */\r\n\r\nimport { resolveNativeBinary, resolveRuntimeDir } from \"@tailwind-styled/shared\"\r\nimport { createRequire } from \"node:module\"\r\n\r\nexport interface ComponentMetadata {\r\n component: string\r\n tag: string\r\n baseClass: string\r\n subComponents: Record<string, { tag?: string; class: string }>\r\n}\r\n\r\nexport interface NativeRscResult {\r\n isServer: boolean\r\n needsClientDirective: boolean\r\n clientReasons: string[]\r\n}\r\n\r\nconst log = (...args: unknown[]) => {\r\n if (process.env.DEBUG?.includes(\"compiler:native\")) {\r\n console.log(\"[compiler:native]\", ...args)\r\n }\r\n}\r\n\r\n// ── Type Exports ────────────────────────────────────────────────────────────────\r\n\r\nexport interface NativeBridge {\r\n // Core transform\r\n transformSource?: (source: string, opts?: Record<string, string>) => NativeTransformResult | null\r\n extractClassesFromSource?: (source: string) => string[]\r\n hasTwUsage?: (source: string) => boolean\r\n isAlreadyTransformed?: (source: string) => boolean\r\n // Class Extractor\r\n extractAllClasses?: (source: string) => string[]\r\n parseClasses?: (raw: string) => Array<{ raw: string; type: string }>\r\n // Application functions\r\n extractComponentUsage?: (source: string) => Array<{ component: string; propsJson: string }>\r\n normalizeAndDedupClasses?: (raw: string) => { normalized: string; duplicatesRemoved: number; uniqueCount: number }\r\n diffClassLists?: (previous: string[], current: string[]) => { added: string[]; removed: string[]; unchanged: string[]; hasChanges: boolean }\r\n batchExtractClasses?: (filePaths: string[]) => Array<{ file: string; classes: string[]; contentHash: string; ok: boolean; error?: string }>\r\n checkAgainstSafelist?: (classes: string[], safelist: string[]) => { matched: string[]; unmatched: string[]; safelistSize: number }\r\n // Batch 2\r\n hoistComponents?: (source: string) => { code: string; hoisted: string[]; warnings: string[] }\r\n compileVariantTable?: (configJson: string) => { id: string; tableJson: string; keys: string[]; defaultKey: string; combinations: number }\r\n classifyAndSortClasses?: (classes: string[]) => Array<{ className: string; bucket: string; sortOrder: number }>\r\n mergeCssDeclarations?: (cssChunks: string[]) => { declarationsJson: string; declarationString: string; count: number }\r\n analyzeClassUsage?: (classes: string[], scanResultJson: string, css: string) => Array<{ className: string; usageCount: number; filesJson: string; bundleSizeBytes: number; isDeadCode: boolean }>\r\n analyzeRsc?: (source: string, filename: string) => {\r\n isServer: boolean\r\n needsClientDirective: boolean\r\n clientReasons: string[]\r\n }\r\n analyzeClasses?: (\r\n filesJson: string,\r\n cwd: string,\r\n flags: number\r\n ) => {\r\n css?: string\r\n code: string\r\n classes: string[]\r\n changed: boolean\r\n rscJson?: string\r\n metadataJson?: string\r\n safelist?: string[]\r\n } | null\r\n // CSS compilation\r\n compileCss?: (classes: string[], prefix?: string | null) => { css: string; classes: string[] }\r\n compileCssLightning?: (classes: string[]) => string\r\n}\r\n\r\nexport interface NativeTransformResult {\r\n code: string\r\n classes: string[]\r\n changed: boolean\r\n rscJson?: string\r\n metadataJson?: string\r\n}\r\n\r\nexport interface ClassExtractResult {\r\n classes: string[]\r\n component_names: string[]\r\n has_tw_usage: boolean\r\n has_use_client: boolean\r\n imports: string[]\r\n}\r\n\r\nconst NATIVE_UNAVAILABLE_MESSAGE =\r\n \"[tailwind-styled/compiler v5] Native binding is required but not available.\\n\" +\r\n \"This package requires native Rust bindings. There is no JavaScript fallback.\\n\" +\r\n \"Please ensure:\\n\" +\r\n \" 1. The native module is properly installed\\n\" +\r\n \" 2. You have run: npm run build:rust (or use prebuilt binary)\\n\" +\r\n \"\\n\" +\r\n \"For help, see: https://tailwind-styled.dev/docs/install\"\r\n\r\n// ── Native Bridge - Factory Pattern\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nlet nativeBridge: NativeBridge | null = null\r\nlet bridgeLoadAttempted = false\r\nlet bridgeLoadError: Error | null = null\r\n\r\nconst isValidNativeBridge = (mod: unknown): mod is NativeBridge => {\r\n const m = mod as Partial<NativeBridge>\r\n return !!(\r\n typeof m.transformSource === \"function\" ||\r\n typeof m.extractAllClasses === \"function\" ||\r\n typeof m.hasTwUsage === \"function\"\r\n )\r\n}\r\n\r\nexport const getNativeBridge = (): NativeBridge => {\r\n if (nativeBridge) {\r\n return nativeBridge\r\n }\r\n\r\n if (bridgeLoadAttempted) {\r\n if (bridgeLoadError) {\r\n throw bridgeLoadError\r\n }\r\n throw new Error(NATIVE_UNAVAILABLE_MESSAGE)\r\n }\r\n\r\n bridgeLoadAttempted = true\r\n\r\n try {\r\n const runtimeDir = resolveRuntimeDir(undefined, import.meta.url)\r\n const require = createRequire(import.meta.url)\r\n \r\n // Use shared's native resolution\r\n const result = resolveNativeBinary(runtimeDir)\r\n\r\n if (result.path && result.path.endsWith(\".node\")) {\r\n try {\r\n const binding = require(result.path) as NativeBridge\r\n if (isValidNativeBridge(binding)) {\r\n nativeBridge = binding\r\n log(\"Native bridge loaded successfully from:\", result.path)\r\n return nativeBridge\r\n }\r\n } catch (e) {\r\n log(\"Failed to require native binding:\", e)\r\n }\r\n }\r\n\r\n throw new Error(`${NATIVE_UNAVAILABLE_MESSAGE}\\n\\nTried paths: ${result.tried.join(\"\\n\")}`)\r\n } catch (err) {\r\n bridgeLoadError = err instanceof Error ? err : new Error(String(err))\r\n log(\"Failed to load native bridge:\", bridgeLoadError.message)\r\n throw bridgeLoadError\r\n }\r\n}\r\n\r\nexport const resetNativeBridgeCache = (): void => {\r\n nativeBridge = null\r\n bridgeLoadAttempted = false\r\n bridgeLoadError = null\r\n log(\"Native bridge cache reset\")\r\n}\r\n\r\n// ── Adaptor for native results\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport const adaptNativeResult = (\r\n raw: NativeTransformResult\r\n): {\r\n code: string\r\n classes: string[]\r\n changed: boolean\r\n rsc?: NativeRscResult\r\n metadata?: ComponentMetadata[]\r\n} => {\r\n return {\r\n code: raw.code ?? \"\",\r\n classes: raw.classes ?? [],\r\n changed: raw.changed ?? false,\r\n rsc: raw.rscJson ? JSON.parse(raw.rscJson) : undefined,\r\n metadata: raw.metadataJson ? JSON.parse(raw.metadataJson) : undefined,\r\n }\r\n}\r\n","/**\r\n * tailwind-styled-v5 — Compiler Index\r\n * \r\n * All functions are backed by native Rust bindings.\r\n * No JavaScript fallback - native is required.\r\n */\r\n\r\nimport { getNativeBridge, resetNativeBridgeCache, adaptNativeResult, type NativeBridge, type NativeTransformResult, type ClassExtractResult, type ComponentMetadata, type NativeRscResult } from \"./nativeBridge\"\r\n\r\nexport { getNativeBridge, resetNativeBridgeCache, adaptNativeResult }\r\nexport type { NativeBridge, NativeTransformResult, ClassExtractResult, ComponentMetadata, NativeRscResult }\r\n\r\nexport type LoaderOutput = {\r\n code: string\r\n changed: boolean\r\n classes: string[]\r\n}\r\n\r\n// =============================================================================\r\n// CORE TRANSFORM FUNCTIONS\r\n// =============================================================================\r\n\r\nexport const transformSource = (source: string, opts?: Record<string, unknown>) => {\r\n const native = getNativeBridge()\r\n if (!native?.transformSource) {\r\n throw new Error(\"FATAL: Native binding 'transformSource' is required but not available.\")\r\n }\r\n const result = native.transformSource(source, opts as Record<string, string>)\r\n if (!result) {\r\n throw new Error(\"FATAL: transformSource returned null\")\r\n }\r\n return result\r\n}\r\n\r\nexport const hasTwUsage = (source: string): boolean => {\r\n const native = getNativeBridge()\r\n if (!native?.hasTwUsage) {\r\n throw new Error(\"FATAL: Native binding 'hasTwUsage' is required but not available.\")\r\n }\r\n return native.hasTwUsage(source)\r\n}\r\n\r\nexport const isAlreadyTransformed = (source: string): boolean => {\r\n const native = getNativeBridge()\r\n if (!native?.isAlreadyTransformed) {\r\n throw new Error(\"FATAL: Native binding 'isAlreadyTransformed' is required but not available.\")\r\n }\r\n return native.isAlreadyTransformed(source)\r\n}\r\n\r\nexport const shouldProcess = (source: string): boolean => {\r\n return hasTwUsage(source) && !isAlreadyTransformed(source)\r\n}\r\n\r\n// =============================================================================\r\n// CSS COMPILATION\r\n// =============================================================================\r\n\r\nexport const compileCssFromClasses = (classes: string[], prefix?: string | null) => {\r\n const native = getNativeBridge()\r\n if (!native?.transformSource) {\r\n throw new Error(\"FATAL: Native binding 'transformSource' is required but not available.\")\r\n }\r\n const result = native.transformSource(classes.join(\" \"), { prefix: prefix ?? \"\" })\r\n if (!result) {\r\n throw new Error(\"FATAL: transformSource returned null\")\r\n }\r\n return result\r\n}\r\n\r\nexport const buildStyleTag = (classes: string[]): string => {\r\n const result = compileCssFromClasses(classes)\r\n return result?.code ? `<style data-tailwind-styled>${result.code}</style>` : \"\"\r\n}\r\n\r\nexport const compileCssNative = (classes: string[], prefix: string | null = null) => {\r\n return compileCssFromClasses(classes, prefix)\r\n}\r\n\r\nexport const generateCssForClasses = async (\r\n classes: string[],\r\n _tailwindConfig?: Record<string, unknown>,\r\n _root?: string\r\n): Promise<string> => {\r\n const result = await compileCssFromClasses(classes)\r\n return result?.code || \"\"\r\n}\r\n\r\n// =============================================================================\r\n// CLASS EXTRACTION\r\n// =============================================================================\r\n\r\nexport const extractAllClasses = (source: string): string[] => {\r\n const native = getNativeBridge()\r\n if (!native?.extractAllClasses) {\r\n throw new Error(\"FATAL: Native binding 'extractAllClasses' is required but not available.\")\r\n }\r\n return native.extractAllClasses(source) || []\r\n}\r\n\r\nexport const extractClassesFromSource = (source: string): string => {\r\n const native = getNativeBridge()\r\n if (!native?.extractClassesFromSource) {\r\n throw new Error(\"FATAL: Native binding 'extractClassesFromSource' is required but not available.\")\r\n }\r\n const result = native.extractClassesFromSource(source)\r\n return Array.isArray(result) ? result.join(\" \") : String(result || \"\")\r\n}\r\n\r\nexport const astExtractClasses = (source: string, filename: string) => {\r\n const native = getNativeBridge()\r\n if (!native?.extractClassesFromSource) {\r\n throw new Error(\"FATAL: Native binding 'extractClassesFromSource' is required but not available.\")\r\n }\r\n return native.extractClassesFromSource(source) || []\r\n}\r\n\r\nexport const parseClasses = (raw: string): Array<{ raw: string; type: string }> => {\r\n const native = getNativeBridge()\r\n if (!native?.parseClasses) {\r\n // Fallback to JS implementation\r\n return parseClassesJs(raw)\r\n }\r\n return native.parseClasses(raw) || []\r\n}\r\n\r\nfunction parseClassesJs(raw: string): Array<{ raw: string; type: string }> {\r\n if (!raw || typeof raw !== \"string\") return []\r\n \r\n const classes = raw.split(/\\s+/).filter(Boolean)\r\n return classes.map((cls) => ({\r\n raw: cls,\r\n type: cls.includes(\":\") ? \"variant\" : cls.includes(\"/\") ? \"arbitrary\" : \"utility\",\r\n }))\r\n}\r\n\r\n// =============================================================================\r\n// CLASS NORMALIZATION & MERGING\r\n// =============================================================================\r\n\r\nexport const normalizeClasses = (raw: string): string => {\r\n const result = normalizeAndDedupClasses(raw)\r\n return result?.normalized || \"\"\r\n}\r\n\r\nexport const mergeClassesStatic = (classes: string): string => {\r\n const result = normalizeAndDedupClasses(classes)\r\n return result?.normalized || \"\"\r\n}\r\n\r\nfunction normalizeAndDedupClassesJs(raw: string): { normalized: string; duplicatesRemoved: number; uniqueCount: number } {\r\n const seen = new Set<string>()\r\n const result: string[] = []\r\n let duplicatesRemoved = 0\r\n\r\n for (const token of raw.split(/\\s+/)) {\r\n if (token.length === 0) continue\r\n if (seen.has(token)) {\r\n duplicatesRemoved++\r\n } else {\r\n seen.add(token)\r\n result.push(token)\r\n }\r\n }\r\n\r\n return {\r\n normalized: result.join(\" \"),\r\n duplicatesRemoved,\r\n uniqueCount: result.length,\r\n }\r\n}\r\n\r\nexport const normalizeAndDedupClasses = (raw: string) => {\r\n const native = getNativeBridge()\r\n if (!native?.normalizeAndDedupClasses) {\r\n // Fallback to JS implementation\r\n return normalizeAndDedupClassesJs(raw)\r\n }\r\n const result = native.normalizeAndDedupClasses(raw)\r\n return result || { normalized: \"\", duplicatesRemoved: 0, uniqueCount: 0 }\r\n}\r\n\r\n// =============================================================================\r\n// DEAD STYLE ELIMINATOR\r\n// =============================================================================\r\n\r\nexport const eliminateDeadCss = (css: string, deadClasses: Set<string>): string => {\r\n let result = css\r\n for (const dead of deadClasses) {\r\n result = result.replace(new RegExp(`\\\\.${dead.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}[^{]*\\\\{[^}]*\\\\}`, 'g'), '')\r\n }\r\n return result\r\n}\r\n\r\nexport const findDeadVariants = (variantConfig: Record<string, unknown>, usage: Record<string, Set<string>>) => {\r\n const unused: string[] = []\r\n const variants = variantConfig as Record<string, Record<string, string>>\r\n for (const [key, values] of Object.entries(variants)) {\r\n for (const [value] of Object.entries(values)) {\r\n const keyValue = `${key}:${value}`\r\n if (!usage[key]?.has(value)) {\r\n unused.push(keyValue)\r\n }\r\n }\r\n }\r\n return unused\r\n}\r\n\r\nexport const runElimination = (css: string, scanResult: unknown) => {\r\n const scanJson = JSON.stringify(scanResult)\r\n const classes = extractAllClasses(css)\r\n const usage = analyzeClassUsage(classes, scanJson, css) || []\r\n const deadClasses = new Set((usage as Array<{ isDeadCode: boolean; className: string }>).filter(u => u.isDeadCode).map(u => u.className))\r\n return eliminateDeadCss(css, deadClasses)\r\n}\r\n\r\nexport const optimizeCss = (css: string): string => {\r\n const classes = extractAllClasses(css)\r\n const usage = analyzeClassUsage(classes, \"[]\", css) || []\r\n const usedClasses = new Set((usage as Array<{ isDeadCode: boolean; className: string }>).filter(u => !u.isDeadCode).map(u => u.className))\r\n \r\n let result = css\r\n const classRegex = /\\.([a-zA-Z0-9_-]+)/g\r\n result = result.replace(classRegex, (match, className) => {\r\n return usedClasses.has(className) ? match : ''\r\n })\r\n \r\n result = result.replace(/[^{}]*\\{\\s*\\}/g, '')\r\n return result.trim()\r\n}\r\n\r\nexport const scanProjectUsage = (dirs: string[], cwd: string) => {\r\n const path = require('node:path')\r\n const files = dirs.map(dir => path.resolve(cwd, dir))\r\n const results = batchExtractClasses(files) || []\r\n \r\n const combined: Record<string, Record<string, Set<string>>> = {}\r\n for (const result of results) {\r\n if (result.ok && result.classes) {\r\n for (const cls of result.classes) {\r\n if (!combined[cls]) combined[cls] = {}\r\n combined[cls][result.file] = new Set([cls])\r\n }\r\n }\r\n }\r\n return combined\r\n}\r\n\r\n// =============================================================================\r\n// COMPONENT ANALYSIS\r\n// =============================================================================\r\n\r\nexport const extractComponentUsage = (source: string): Array<{ component: string; propsJson: string }> => {\r\n const native = getNativeBridge()\r\n if (!native?.extractComponentUsage) {\r\n throw new Error(\"FATAL: Native binding 'extractComponentUsage' is required but not available.\")\r\n }\r\n return native.extractComponentUsage(source) || []\r\n}\r\n\r\n// =============================================================================\r\n// DIFF & BATCH OPERATIONS\r\n// =============================================================================\r\n\r\nexport const diffClassLists = (previous: string[], current: string[]) => {\r\n const native = getNativeBridge()\r\n if (!native?.diffClassLists) {\r\n throw new Error(\"FATAL: Native binding 'diffClassLists' is required but not available.\")\r\n }\r\n return native.diffClassLists(previous, current) || { added: [], removed: [], unchanged: [], hasChanges: false }\r\n}\r\n\r\nexport const batchExtractClasses = (filePaths: string[]) => {\r\n const native = getNativeBridge()\r\n if (!native?.batchExtractClasses) {\r\n throw new Error(\"FATAL: Native binding 'batchExtractClasses' is required but not available.\")\r\n }\r\n return native.batchExtractClasses(filePaths) || []\r\n}\r\n\r\nexport const checkAgainstSafelist = (classes: string[], safelist: string[]) => {\r\n const native = getNativeBridge()\r\n if (!native?.checkAgainstSafelist) {\r\n throw new Error(\"FATAL: Native binding 'checkAgainstSafelist' is required but not available.\")\r\n }\r\n return native.checkAgainstSafelist(classes, safelist) || { matched: [], unmatched: [], safelistSize: 0 }\r\n}\r\n\r\n// =============================================================================\r\n// HOISTING\r\n// =============================================================================\r\n\r\nexport const hoistComponents = (source: string) => {\r\n const native = getNativeBridge()\r\n if (!native?.hoistComponents) {\r\n throw new Error(\"FATAL: Native binding 'hoistComponents' is required but not available.\")\r\n }\r\n return native.hoistComponents(source) || { code: source, hoisted: [], warnings: [] }\r\n}\r\n\r\n// =============================================================================\r\n// VARIANT COMPILATION\r\n// =============================================================================\r\n\r\nexport const compileVariantTable = (configJson: string) => {\r\n const native = getNativeBridge()\r\n if (!native?.compileVariantTable) {\r\n throw new Error(\"FATAL: Native binding 'compileVariantTable' is required but not available.\")\r\n }\r\n return native.compileVariantTable(configJson) || { id: \"\", tableJson: \"{}\", keys: [], defaultKey: \"\", combinations: 0 }\r\n}\r\n\r\nexport const compileVariants = (componentId: string, config: Record<string, unknown>) => {\r\n return compileVariantTable(JSON.stringify({ componentId, ...config }))\r\n}\r\n\r\n// =============================================================================\r\n// CSS ANALYSIS\r\n// =============================================================================\r\n\r\nexport const classifyAndSortClasses = (classes: string[]) => {\r\n const native = getNativeBridge()\r\n if (!native?.classifyAndSortClasses) {\r\n throw new Error(\"FATAL: Native binding 'classifyAndSortClasses' is required but not available.\")\r\n }\r\n return native.classifyAndSortClasses(classes) || []\r\n}\r\n\r\nexport const mergeCssDeclarations = (cssChunks: string[]) => {\r\n const native = getNativeBridge()\r\n if (!native?.mergeCssDeclarations) {\r\n throw new Error(\"FATAL: Native binding 'mergeCssDeclarations' is required but not available.\")\r\n }\r\n return native.mergeCssDeclarations(cssChunks) || { declarationsJson: \"{}\", declarationString: \"\", count: 0 }\r\n}\r\n\r\nexport const analyzeClassUsage = (classes: string[], scanResultJson: string, css: string) => {\r\n const native = getNativeBridge()\r\n if (!native?.analyzeClassUsage) {\r\n throw new Error(\"FATAL: Native binding 'analyzeClassUsage' is required but not available.\")\r\n }\r\n return native.analyzeClassUsage(classes, scanResultJson, css) || []\r\n}\r\n\r\n// =============================================================================\r\n// RSC ANALYSIS\r\n// =============================================================================\r\n\r\nexport const analyzeRsc = (source: string, filename: string) => {\r\n const native = getNativeBridge()\r\n if (!native?.analyzeRsc) {\r\n throw new Error(\"FATAL: Native binding 'analyzeRsc' is required but not available.\")\r\n }\r\n return native.analyzeRsc(source, filename) || { isServer: true, needsClientDirective: false, clientReasons: [] }\r\n}\r\n\r\nexport const analyzeFile = (source: string, filename: string) => {\r\n const rsc = analyzeRsc(source, filename)\r\n return {\r\n isServer: rsc?.isServer ?? true,\r\n needsClientDirective: rsc?.needsClientDirective ?? false,\r\n clientReasons: rsc?.clientReasons ?? [],\r\n interactiveClasses: [],\r\n canStaticResolveVariants: true,\r\n }\r\n}\r\n\r\nexport const analyzeVariantUsage = (source: string, componentName: string, variantKeys: string[]) => {\r\n const rsc = analyzeRsc(source, componentName)\r\n return { \r\n resolved: {} as Record<string, string>, \r\n dynamic: [] as string[] \r\n }\r\n}\r\n\r\nexport const injectClientDirective = (source: string): string => {\r\n if (!source.includes('\"use client\"') && !source.includes(\"'use client'\")) {\r\n return '\"use client\";\\n' + source\r\n }\r\n return source\r\n}\r\n\r\nexport const injectServerOnlyComment = (source: string): string => {\r\n return `/* @server-only */\\n${source}`\r\n}\r\n\r\n// =============================================================================\r\n// FULL ANALYSIS\r\n// =============================================================================\r\n\r\nexport const analyzeClasses = (filesJson: string, cwd: string, flags: number) => {\r\n const native = getNativeBridge()\r\n if (!native?.analyzeClasses) {\r\n throw new Error(\"FATAL: Native binding 'analyzeClasses' is required but not available.\")\r\n }\r\n return native.analyzeClasses(filesJson, cwd, flags)\r\n}\r\n\r\n// =============================================================================\r\n// SAFELIST\r\n// =============================================================================\r\n\r\nexport const generateSafelist = (scanDirs: string[], outputPath?: string, cwd?: string) => {\r\n const classes = scanProjectUsage(scanDirs, cwd || process.cwd())\r\n const allClasses = Object.keys(classes).sort()\r\n \r\n if (outputPath) {\r\n const fs = require('node:fs')\r\n fs.writeFileSync(outputPath, JSON.stringify(allClasses, null, 2))\r\n }\r\n \r\n return allClasses\r\n}\r\n\r\nexport const loadSafelist = (safelistPath: string): string[] => {\r\n const fs = require('node:fs')\r\n try {\r\n const content = fs.readFileSync(safelistPath, 'utf-8')\r\n return JSON.parse(content)\r\n } catch {\r\n return []\r\n }\r\n}\r\n\r\n// =============================================================================\r\n// CONFIG LOADING\r\n// =============================================================================\r\n\r\nexport const loadTailwindConfig = (cwd: string = process.cwd()) => {\r\n const fs = require('node:fs')\r\n const path = require('node:path')\r\n \r\n const configFiles = [\r\n 'tailwind.config.ts',\r\n 'tailwind.config.js',\r\n 'tailwind.config.mjs',\r\n 'tailwind.config.cjs',\r\n ]\r\n \r\n for (const file of configFiles) {\r\n const fullPath = path.join(cwd, file)\r\n if (fs.existsSync(fullPath)) {\r\n const mod = require(fullPath)\r\n return mod.default || mod\r\n }\r\n }\r\n \r\n return {}\r\n}\r\n\r\nexport const getContentPaths = (cwd: string = process.cwd()) => {\r\n const path = require('node:path')\r\n return {\r\n content: [\r\n path.join(cwd, 'src/**/*.{js,ts,jsx,tsx}'),\r\n path.join(cwd, 'app/**/*.{js,ts,jsx,tsx}'),\r\n path.join(cwd, 'pages/**/*.{js,ts,jsx,tsx}'),\r\n ],\r\n }\r\n}\r\n\r\n// =============================================================================\r\n// LOADER\r\n// =============================================================================\r\n\r\nexport const runLoaderTransform = (ctx: { filepath: string; source: string; options?: Record<string, unknown> }) => {\r\n const { filepath, source, options } = ctx\r\n const result = transformSource(source, { filename: filepath, ...options })\r\n return {\r\n code: result?.code || \"\",\r\n changed: result?.changed || false,\r\n classes: result?.classes || [],\r\n } as LoaderOutput\r\n}\r\n\r\nexport const shouldSkipFile = (filepath: string): boolean => {\r\n const SKIP_PATHS = ['node_modules', '.next', '.rspack-dist', '.turbo', 'dist/', 'out/']\r\n const skipExtensions = ['.css', '.json', '.md', '.txt', '.yaml', '.yml']\r\n \r\n for (const p of SKIP_PATHS) {\r\n if (filepath.includes(p)) return true\r\n }\r\n for (const ext of skipExtensions) {\r\n if (filepath.endsWith(ext)) return true\r\n }\r\n return false\r\n}\r\n\r\n// =============================================================================\r\n// ROUTE CSS COLLECTOR\r\n// =============================================================================\r\n\r\nexport const fileToRoute = (filepath: string): string | null => {\r\n const normalized = filepath.replace(/\\\\/g, '/')\r\n\r\n // Layout / loading / error — shared across all routes\r\n if (\r\n normalized.includes('/layout.') ||\r\n normalized.includes('/loading.') ||\r\n normalized.includes('/error.')\r\n ) {\r\n return '__global'\r\n }\r\n\r\n // App Router — /app/[...]/page.[tj]sx?\r\n const appPageMatch = normalized.match(/\\/app\\/(.+?)\\/page\\.[tj]sx?$/)\r\n if (appPageMatch) return `/${appPageMatch[1]}`\r\n\r\n const appRootPage = normalized.match(/\\/app\\/page\\.[tj]sx?$/)\r\n if (appRootPage) return '/'\r\n\r\n // Pages Router — /pages/[...].tsx (exclude _app, _document, _error, api/)\r\n const pagesMatch = normalized.match(/\\/pages\\/(.+?)\\.[tj]sx?$/)\r\n if (pagesMatch) {\r\n const pagePath = pagesMatch[1]\r\n if (pagePath.startsWith('_') || pagePath.startsWith('api/')) return '__global'\r\n // /pages/index → /, /pages/about → /about, /pages/blog/[slug] → /blog/[slug]\r\n return pagePath === 'index' ? '/' : `/${pagePath}`\r\n }\r\n\r\n return null\r\n}\r\n\r\nexport const getAllRoutes = (): string[] => {\r\n return Array.from(_routeClassMap.keys())\r\n}\r\n\r\n// In-memory route → classes map (populated by webpack/turbopack loader per file)\r\nconst _routeClassMap = new Map<string, Set<string>>()\r\n\r\nexport const getRouteClasses = (route: string): Set<string> => {\r\n return _routeClassMap.get(route) ?? new Set()\r\n}\r\n\r\nexport const getAllRouteClasses = (): Map<string, Set<string>> => {\r\n return new Map(_routeClassMap)\r\n}\r\n\r\nexport const registerFileClasses = (filepath: string, classes: string[]): void => {\r\n if (!classes.length) return\r\n const route = fileToRoute(filepath) ?? '__global'\r\n const existing = _routeClassMap.get(route) ?? new Set<string>()\r\n for (const cls of classes) existing.add(cls)\r\n _routeClassMap.set(route, existing)\r\n}\r\n\r\nexport const registerGlobalClasses = (classes: string[]): void => {\r\n if (!classes.length) return\r\n const existing = _routeClassMap.get('__global') ?? new Set<string>()\r\n for (const cls of classes) existing.add(cls)\r\n _routeClassMap.set('__global', existing)\r\n}\r\n\r\nexport const clearRouteClasses = (): void => {\r\n _routeClassMap.clear()\r\n}\r\n\r\n// =============================================================================\r\n// INCREMENTAL ENGINE\r\n// =============================================================================\r\n\r\nlet incrementalEngineInstance: unknown = null\r\n\r\nexport const getIncrementalEngine = () => {\r\n if (!incrementalEngineInstance) {\r\n incrementalEngineInstance = {\r\n compile: (source: string) => transformSource(source),\r\n }\r\n }\r\n return incrementalEngineInstance\r\n}\r\n\r\nexport const resetIncrementalEngine = () => {\r\n incrementalEngineInstance = null\r\n}\r\n\r\nexport const IncrementalEngine = class {\r\n compile(source: string) {\r\n return transformSource(source)\r\n }\r\n}\r\n\r\n// =============================================================================\r\n// STYLE BUCKET SYSTEM\r\n// =============================================================================\r\n\r\nlet bucketEngineInstance: unknown = null\r\n\r\nexport const getBucketEngine = () => {\r\n if (!bucketEngineInstance) {\r\n bucketEngineInstance = {\r\n add: (className: string) => className,\r\n get: (bucket: string) => [],\r\n }\r\n }\r\n return bucketEngineInstance\r\n}\r\n\r\nexport const resetBucketEngine = () => {\r\n bucketEngineInstance = null\r\n}\r\n\r\nexport const BucketEngine = class {\r\n add(className: string) {\r\n return className\r\n }\r\n}\r\n\r\nexport const classifyNode = (node: unknown): string => {\r\n return 'unknown'\r\n}\r\n\r\nexport const detectConflicts = (classes: string[]): string[] => {\r\n return []\r\n}\r\n\r\nexport const bucketSort = (classes: string[]): string[] => {\r\n return classes\r\n}","/**\r\n * tailwind-styled-v4 - Webpack Loader\r\n */\r\n\r\nimport {\r\n type LoaderOutput,\r\n runLoaderTransform,\r\n shouldSkipFile,\r\n registerFileClasses,\r\n} from \"@tailwind-styled/compiler/internal\"\r\nimport path from \"node:path\"\r\nimport { z } from \"zod\"\r\n\r\ninterface WebpackLoaderOptions {\r\n mode?: \"zero-runtime\"\r\n autoClientBoundary?: boolean\r\n addDataAttr?: boolean\r\n hoist?: boolean\r\n routeCss?: boolean\r\n incremental?: boolean\r\n verbose?: boolean\r\n preserveImports?: boolean\r\n}\r\n\r\ninterface WebpackContext {\r\n resourcePath: string\r\n getOptions(): WebpackLoaderOptions\r\n async?(): ((err: Error | null, result?: string) => void) | undefined\r\n cacheable?(flag?: boolean): void\r\n}\r\n\r\nconst WebpackLoaderOptionsSchema = z.object({\r\n mode: z.literal(\"zero-runtime\").optional(),\r\n autoClientBoundary: z.boolean().optional(),\r\n addDataAttr: z.boolean().optional(),\r\n hoist: z.boolean().optional(),\r\n routeCss: z.boolean().optional(),\r\n incremental: z.boolean().optional(),\r\n verbose: z.boolean().optional(),\r\n preserveImports: z.boolean().optional(),\r\n})\r\n\r\nconst isNextBuildArtifact = (filepath: string): boolean =>\r\n filepath.includes(`${path.sep}.next${path.sep}`)\r\n\r\nexport default function webpackLoader(this: WebpackContext, source: string): void {\r\n const callback = this.async?.()\r\n if (!callback) {\r\n throw new Error(\"[tailwind-styled] Async loader callback is not available.\")\r\n }\r\n\r\n this.cacheable?.(true)\r\n const filepath = this.resourcePath\r\n\r\n if (shouldSkipFile(filepath) || isNextBuildArtifact(filepath)) {\r\n callback(null, source)\r\n return\r\n }\r\n\r\n try {\r\n const options = WebpackLoaderOptionsSchema.parse(this.getOptions())\r\n\r\n const output: LoaderOutput = runLoaderTransform({\r\n filepath,\r\n source,\r\n options: {\r\n mode: options.mode,\r\n autoClientBoundary: options.autoClientBoundary ?? true,\r\n addDataAttr: options.addDataAttr,\r\n hoist: options.hoist,\r\n filename: filepath,\r\n routeCss: options.routeCss,\r\n incremental: options.incremental,\r\n verbose: options.verbose,\r\n preserveImports: options.preserveImports ?? true,\r\n },\r\n })\r\n\r\n if (typeof output.code !== \"string\") {\r\n throw new TypeError(`[tailwind-styled] Invalid transform output for ${filepath}: code is not a string`)\r\n }\r\n\r\n if (options.verbose && output.changed) {\r\n const rsc = (output as any).rsc\r\n const engine = (output as any).engine ?? \"js\"\r\n const env = rsc?.isServer ? \"server\" : \"client\"\r\n const name = path.basename(filepath)\r\n process.stdout.write(\r\n `[tailwind-styled/webpack] ${name} -> ${output.classes.length} classes (${env}) [${engine}]\\n`\r\n )\r\n }\r\n\r\n // Register classes ke route map untuk TwCssInjector\r\n if (output.classes.length > 0) {\r\n registerFileClasses(filepath, output.classes)\r\n }\r\n\r\n callback(null, output.code)\r\n } catch (err) {\r\n if (process.env.NODE_ENV === \"production\") {\r\n callback(err instanceof Error ? err : new Error(String(err)))\r\n return\r\n }\r\n\r\n console.warn(`[tailwind-styled-v4] Webpack transform failed for ${filepath}:`, err)\r\n callback(null, source)\r\n }\r\n}"]}
|
|
1
|
+
{"version":3,"sources":["../packages/domain/shared/src/native-resolution.ts","../packages/domain/shared/src/index.ts","../packages/domain/compiler/src/nativeBridge.ts","../packages/domain/compiler/src/index.ts","../packages/presentation/next/src/webpackLoader.ts"],"names":["path","getNodeModuleRef","isBrowser","nodeModuleRef","getRequire","require"],"mappings":";;;;;;;;;;;;;;;;;AAcA,SAAS,gBAAA,GAAmB;AAC1B,EAAA,IAAI,WAAW,OAAO,IAAA;AACtB,EAAA,IAAI,aAAA,KAAkB,MAAM,OAAO,aAAA;AACnC,EAAA,IAAI;AACF,IAAA,MAAM,OAAO,OAAO,SAAA,KAAY,UAAA,GAAa,SAAA,CAAQ,QAAa,CAAA,GAAI,IAAA;AACtE,IAAA,aAAA,GAAgB,IAAA;AAChB,IAAA,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,GAAM,GAAA,EAAK,QAAA,GAAW,QAAA,GAAW,QAAA;AACvC,MAAA,MAAM,IAAA,GAAO,IAAA,CAAK,QAAA,CAAS,QAAQ,CAAA;AACnC,MAAA,OAAA,CAAQ,MAAA,CAAO,KAAA;AAAA,QACb,CAAA,0BAAA,EAA6B,IAAI,CAAA,IAAA,EAAO,MAAA,CAAO,QAAQ,MAAM,CAAA,UAAA,EAAa,GAAG,CAAA,GAAA,EAAM,MAAM,CAAA;AAAA;AAAA,OAC3F;AAAA,IACF;AAGA,IAAA,IAAI,MAAA,CAAO,OAAA,CAAQ,MAAA,GAAS,CAAA,EAAG;AAC7B,MAAA,mBAAA,CAAoB,QAAA,EAAU,OAAO,OAAO,CAAA;AAAA,IAC9C;AAEA,IAAA,QAAA,CAAS,IAAA,EAAM,OAAO,IAAI,CAAA;AAAA,EAC5B,SAAS,GAAA,EAAK;AACZ,IAAA,IAAI,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA,EAAc;AACzC,MAAA,QAAA,CAAS,GAAA,YAAe,QAAQ,GAAA,GAAM,IAAI,MAAM,MAAA,CAAO,GAAG,CAAC,CAAC,CAAA;AAC5D,MAAA;AAAA,IACF;AAEA,IAAA,OAAA,CAAQ,IAAA,CAAK,CAAA,kDAAA,EAAqD,QAAQ,CAAA,CAAA,CAAA,EAAK,GAAG,CAAA;AAClF,IAAA,QAAA,CAAS,MAAM,MAAM,CAAA;AAAA,EACvB;AACF","file":"webpackLoader.mjs","sourcesContent":["/**\r\n * Prebuilt binary resolution untuk native NAPI bindings.\r\n * QA #1: Resolve native binary dari prebuilt packages atau local build.\r\n *\r\n * Prioritas:\r\n * 1. TW_NATIVE_PATH env var (explicit override)\r\n * 2. Prebuilt binary dari platform-specific npm package\r\n * 3. Local build dari source (developer mode)\r\n */\r\n\r\nconst isBrowser = typeof window !== \"undefined\" || typeof document !== \"undefined\"\r\n\r\n// ESM-safe require detection\r\nlet nodeModuleRef: any = null\r\nfunction getNodeModuleRef() {\r\n if (isBrowser) return null\r\n if (nodeModuleRef !== null) return nodeModuleRef\r\n try {\r\n const test = typeof require === 'function' ? require('node:module') : null\r\n nodeModuleRef = test\r\n return test\r\n } catch {\r\n nodeModuleRef = null\r\n return null\r\n }\r\n}\r\n\r\nlet _nodeFs: any = null\r\nlet _nodePath: any = null\r\nlet _nodeModule: any = null\r\nlet _require: any = null\r\n\r\nfunction getNodeFs() {\r\n if (isBrowser) return { existsSync: () => false }\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) return { existsSync: () => false }\r\n if (!_nodeFs) _nodeFs = nodeRequire.createRequire(import.meta.url)(\"node:fs\")\r\n return _nodeFs\r\n}\r\nfunction getNodePath() {\r\n if (isBrowser) return { resolve: () => \"\", dirname: \"\" }\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) return { resolve: () => \"\", dirname: \"\" }\r\n if (!_nodePath) _nodePath = nodeRequire.createRequire(import.meta.url)(\"node:path\")\r\n return _nodePath!\r\n}\r\nfunction getNodeModule() {\r\n if (isBrowser) return { createRequire: () => { throw new Error(\"node:module not available\") } }\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) return { createRequire: () => { throw new Error(\"require not available\") } }\r\n if (!_nodeModule) _nodeModule = nodeRequire\r\n return _nodeModule\r\n}\r\nfunction getRequire(_importMetaUrl: string) {\r\n if (isBrowser) return () => { throw new Error(\"node:module not available\") }\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) return () => { throw new Error(\"require not available\") }\r\n if (!_require) _require = nodeRequire.createRequire(_importMetaUrl)\r\n return _require\r\n}\r\n\r\nexport interface NativeResolutionResult {\r\n path: string | null\r\n source: \"env\" | \"prebuilt\" | \"local\" | \"not-found\"\r\n platform: string\r\n tried: string[]\r\n}\r\n\r\n/** Platform key → prebuilt npm package name */\r\nconst PLATFORM_MAP: Record<string, string[]> = {\r\n \"linux-x64\": [\"@tailwind-styled/native-linux-x64\"],\r\n \"linux-arm64\": [\"@tailwind-styled/native-linux-arm64\"],\r\n \"darwin-x64\": [\"@tailwind-styled/native-darwin-x64\"],\r\n \"darwin-arm64\": [\"@tailwind-styled/native-darwin-arm64\"],\r\n \"win32-x64\": [\"@tailwind-styled/native-win32-x64\"],\r\n \"win32-arm64\": [\"@tailwind-styled/native-win32-arm64\"],\r\n}\r\n\r\nfunction platformKey(): string {\r\n if (isBrowser) return \"browser\"\r\n return `${process.platform}-${process.arch}`\r\n}\r\n\r\n/**\r\n * Resolve native binary path dari semua sumber yang tersedia.\r\n *\r\n * @example\r\n * const result = resolveNativeBinary()\r\n * if (result.path) {\r\n * const binding = require(result.path)\r\n * } else {\r\n * throw new Error(\"Native binding not found — run npm run build:rust\")\r\n * }\r\n */\r\nexport function resolveNativeBinary(runtimeDir?: string): NativeResolutionResult {\r\n const platform = platformKey()\r\n const tried: string[] = []\r\n\r\n if (isBrowser) {\r\n return { path: null, source: \"not-found\", platform, tried: [\"not available in browser\"] }\r\n }\r\n\r\n const fs = getNodeFs()\r\n const path = getNodePath()\r\n const _req = getRequire(import.meta.url)\r\n\r\n // 1. Env var override\r\n const envPath = process.env.TW_NATIVE_PATH?.trim()\r\n if (envPath) {\r\n if (fs.existsSync(envPath)) {\r\n return { path: envPath, source: \"env\", platform, tried }\r\n }\r\n tried.push(`env:${envPath} (not found)`)\r\n }\r\n\r\n // 2. Skip jika disabled\r\n if (\r\n process.env.TWS_NO_NATIVE === \"1\" ||\r\n process.env.TWS_NO_RUST === \"1\" ||\r\n process.env.TWS_DISABLE_NATIVE === \"1\"\r\n ) {\r\n return { path: null, source: \"not-found\", platform, tried: [\"disabled by env\"] }\r\n }\r\n\r\n // 3. Prebuilt binary dari platform-specific npm package\r\n const prebuiltPkgs = PLATFORM_MAP[platform] ?? []\r\n for (const pkg of prebuiltPkgs) {\r\n try {\r\n const candidate = _req.resolve(`${pkg}/tailwind_styled_parser.node`)\r\n if (fs.existsSync(candidate)) {\r\n return { path: candidate, source: \"prebuilt\", platform, tried }\r\n }\r\n tried.push(`prebuilt:${pkg} (resolved but missing)`)\r\n } catch {\r\n tried.push(`prebuilt:${pkg} (not installed)`)\r\n }\r\n }\r\n\r\n // 4. Local build candidates\r\n const cwd = process.cwd()\r\n const base = runtimeDir ?? cwd\r\n const localCandidates = [\r\n path.resolve(base, \"tailwind_styled_parser.node\"),\r\n path.resolve(base, \"..\", \"tailwind_styled_parser.node\"),\r\n path.resolve(cwd, \"native\", \"tailwind_styled_parser.node\"),\r\n path.resolve(cwd, \"native\", \"target\", \"release\", \"tailwind_styled_parser.node\"),\r\n // napi-rs conventional output\r\n path.resolve(base, `tailwind_styled_parser.${platform}.node`),\r\n ]\r\n\r\n for (const candidate of localCandidates) {\r\n tried.push(`local:${candidate}`)\r\n if (fs.existsSync(candidate)) {\r\n return { path: candidate, source: \"local\", platform, tried }\r\n }\r\n }\r\n\r\n return { path: null, source: \"not-found\", platform, tried }\r\n}\r\n\r\n/**\r\n * Format human-readable error untuk \"binary not found\".\r\n */\r\nexport function formatNativeNotFoundError(result: NativeResolutionResult): string {\r\n const lines = [\r\n `[tailwind-styled] Native binding not found for ${result.platform}`,\r\n ``,\r\n `Tried:`,\r\n ...result.tried.map(t => ` - ${t}`),\r\n ``,\r\n `Solutions:`,\r\n ` 1. Build locally: npm run build:rust`,\r\n ` 2. Install prebuilt: npm install @tailwind-styled/native-${result.platform}`,\r\n ` 3. Override path: TW_NATIVE_PATH=/path/to/parser.node`,\r\n ` 4. Disable native: TWS_DISABLE_NATIVE=1 (slower, JS fallback)`,\r\n ]\r\n return lines.join(\"\\n\")\r\n}\r\n","const isBrowser = typeof window !== \"undefined\" || typeof document !== \"undefined\"\r\n\r\n// ESM-safe require detection\r\nlet nodeModuleRef: any = null\r\nfunction getNodeModuleRef() {\r\n if (isBrowser) return null\r\n if (nodeModuleRef !== null) return nodeModuleRef\r\n try {\r\n const test = typeof require === 'function' ? require('node:module') : null\r\n nodeModuleRef = test\r\n return test\r\n } catch {\r\n nodeModuleRef = null\r\n return null\r\n }\r\n}\r\n\r\nlet _nodeCrypto: any = null\r\nlet _nodeFs: any = null\r\nlet _nodeModule: any = null\r\nlet _nodePath: any = null\r\nlet _nodeUrl: any = null\r\n\r\nfunction getNodeCrypto() {\r\n if (isBrowser) throw new Error(\"node:crypto not available in browser\")\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) throw new Error(\"require not available\")\r\n if (!_nodeCrypto) _nodeCrypto = nodeRequire.createRequire(import.meta.url)(\"node:crypto\")\r\n return _nodeCrypto!\r\n}\r\nfunction getNodeFs() {\r\n if (isBrowser) throw new Error(\"node:fs not available in browser\")\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) throw new Error(\"require not available\")\r\n if (!_nodeFs) _nodeFs = nodeRequire.createRequire(import.meta.url)(\"node:fs\")\r\n return _nodeFs!\r\n}\r\nfunction getNodeModule() {\r\n if (isBrowser) throw new Error(\"node:module not available in browser\")\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) throw new Error(\"require not available\")\r\n if (!_nodeModule) _nodeModule = nodeRequire\r\n return _nodeModule!\r\n}\r\nfunction getNodePath() {\r\n if (isBrowser) throw new Error(\"node:path not available in browser\")\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) throw new Error(\"require not available\")\r\n if (!_nodePath) _nodePath = nodeRequire.createRequire(import.meta.url)(\"node:path\")\r\n return _nodePath!\r\n}\r\nfunction getNodeUrl() {\r\n if (isBrowser) throw new Error(\"node:url not available in browser\")\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) throw new Error(\"require not available\")\r\n if (!_nodeUrl) _nodeUrl = nodeRequire.createRequire(import.meta.url)(\"node:url\")\r\n return _nodeUrl!\r\n}\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Types\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport type TokenMap = Record<string, string>\r\n\r\nexport type VariantValue = string | number | boolean | undefined\r\n\r\nexport type VariantProps = Record<string, VariantValue>\r\n\r\nexport type HtmlTagName = keyof HTMLElementTagNameMap\r\n\r\nexport type CompoundCondition = Record<string, string | number | boolean>\r\n\r\nexport type VariantMatrix = Record<string, Array<string | number | boolean>>\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Logging\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport interface Logger {\r\n warn(...args: unknown[]): void\r\n debug(...args: unknown[]): void\r\n error(...args: unknown[]): void\r\n log(...args: unknown[]): void\r\n}\r\n\r\nexport function createLogger(namespace: string): Logger {\r\n const prefix = `[${namespace}]`\r\n return {\r\n warn(...args: unknown[]) {\r\n process.stderr.write(`${prefix} ${args.map(a => typeof a === \"string\" ? a : String(a)).join(\" \")}\\n`)\r\n },\r\n debug(...args: unknown[]) {\r\n process.stderr.write(`${prefix} ${args.map(a => typeof a === \"string\" ? a : String(a)).join(\" \")}\\n`)\r\n },\r\n error(...args: unknown[]) {\r\n process.stderr.write(`${prefix} ${args.map(a => typeof a === \"string\" ? a : String(a)).join(\" \")}\\n`)\r\n },\r\n log(...args: unknown[]) {\r\n process.stderr.write(`${prefix} ${args.map(a => typeof a === \"string\" ? a : String(a)).join(\" \")}\\n`)\r\n },\r\n }\r\n}\r\n\r\nexport function createDebugLogger(namespace: string, label?: string): (msg: string) => void {\r\n const prefix = label ? `[${namespace}:${label}]` : `[${namespace}]`\r\n return (msg: string) => {\r\n if (process.env.DEBUG?.includes(namespace) || process.env.TW_DEBUG) {\r\n console.debug(prefix, msg)\r\n }\r\n }\r\n}\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Error handling\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport type ErrorSource = \"rust\" | \"validation\" | \"compile\" | \"io\" | \"config\" | \"unknown\"\r\n\r\ntype ZodLikeIssue = {\r\n path?: readonly PropertyKey[]\r\n message?: string\r\n}\r\n\r\nfunction formatIssuePath(path?: readonly PropertyKey[]): string {\r\n if (!path || path.length === 0) return \"(root)\"\r\n return path\r\n .map((segment) =>\r\n typeof segment === \"symbol\" ? segment.description ?? segment.toString() : String(segment)\r\n )\r\n .join(\".\")\r\n}\r\n\r\nexport class TwError extends Error {\r\n /** @deprecated Gunakan source */\r\n public readonly domain: string\r\n public readonly source: ErrorSource\r\n public readonly code: string\r\n public readonly originalCause?: unknown\r\n\r\n constructor(domainOrSource: string, code: string, message: string, cause?: unknown) {\r\n super(message)\r\n this.name = \"TwError\"\r\n this.domain = domainOrSource\r\n this.source = domainOrSource as ErrorSource\r\n this.code = code\r\n this.originalCause = cause\r\n if (Error.captureStackTrace) Error.captureStackTrace(this, TwError)\r\n }\r\n\r\n static fromIo(code: string, message: string): TwError {\r\n return new TwError(\"io\", code, message)\r\n }\r\n\r\n static fromCompile(code: string, message: string): TwError {\r\n return new TwError(\"compile\", code, message)\r\n }\r\n\r\n static fromRust(err: { code?: string; message?: string } | Error | unknown): TwError {\r\n if (err instanceof TwError) return err\r\n if (err instanceof Error) return new TwError(\"rust\", \"RUST_ERROR\", err.message, err)\r\n if (err && typeof err === \"object\") {\r\n const e = err as { code?: string; message?: string }\r\n return new TwError(\"rust\", e.code ?? \"RUST_ERROR\", e.message ?? String(err), err)\r\n }\r\n return new TwError(\"rust\", \"RUST_ERROR\", String(err), err)\r\n }\r\n\r\n /** Buat TwError dari ZodError — dukung shape Zod v3 (`errors`) dan v4 (`issues`). */\r\n static fromZod(err: { issues?: ZodLikeIssue[]; errors?: ZodLikeIssue[] }): TwError {\r\n const first = err.issues?.[0] ?? err.errors?.[0]\r\n const path = formatIssuePath(first?.path)\r\n const message = first ? `${path}: ${first.message}` : \"Schema validation failed\"\r\n return new TwError(\"validation\", \"SCHEMA_VALIDATION_FAILED\", message, err)\r\n }\r\n\r\n static wrap(source: string, code: string, err: unknown): TwError {\r\n if (err instanceof TwError) return err\r\n if (err instanceof Error) return new TwError(source, code, err.message, err)\r\n return new TwError(source, code, String(err), err)\r\n }\r\n\r\n override toString(): string {\r\n return `TwError [${this.source}:${this.code}] ${this.message}`\r\n }\r\n\r\n toJSON(): { name: string; source: string; code: string; message: string } {\r\n return { name: this.name, source: this.source, code: this.code, message: this.message }\r\n }\r\n\r\n toCliMessage(): string {\r\n return `[${this.source.toUpperCase()}:${this.code}] ${this.message}`\r\n }\r\n}\r\n\r\nexport function wrapUnknownError(domain: string, code: string, error: unknown): TwError {\r\n return TwError.wrap(domain, code, error)\r\n}\r\n\r\nexport function isTwError(err: unknown): err is TwError {\r\n return err instanceof TwError\r\n}\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Native binding resolution\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport interface LoadNativeBindingOptions<T> {\r\n runtimeDir: string\r\n candidates: string[]\r\n isValid: (module: unknown) => module is T\r\n invalidExportMessage: string\r\n}\r\n\r\nexport interface LoadNativeBindingResult<T> {\r\n binding: T | null\r\n loadErrors: Array<{ path: string; message: string }>\r\n loadedPath?: string\r\n}\r\n\r\nexport function loadNativeBinding<T>(options: LoadNativeBindingOptions<T>): LoadNativeBindingResult<T> {\r\n if (isBrowser) {\r\n return { binding: null, loadErrors: [{ path: \"\", message: \"Native bindings not available in browser\" }] }\r\n }\r\n \r\n const { runtimeDir, candidates, isValid } = options\r\n const loadErrors: Array<{ path: string; message: string }> = []\r\n const path = getNodePath()\r\n const fs = getNodeFs()\r\n\r\n for (const candidate of candidates) {\r\n const candidatePath = path.resolve(runtimeDir, candidate)\r\n try {\r\n if (!fs.existsSync(candidatePath) && !fs.existsSync(candidatePath + \".node\")) {\r\n continue\r\n }\r\n const mod = requireNativeModule(candidatePath)\r\n if (mod && isValid(mod)) {\r\n return { binding: mod, loadErrors, loadedPath: candidatePath }\r\n }\r\n loadErrors.push({ path: candidatePath, message: options.invalidExportMessage })\r\n } catch (e) {\r\n loadErrors.push({ path: candidatePath, message: e instanceof Error ? e.message : String(e) })\r\n }\r\n }\r\n\r\n return { binding: null, loadErrors }\r\n}\r\n\r\nfunction getRequire(): NodeRequire {\r\n if (isBrowser) return (() => { throw new Error(\"require not available in browser\") }) as unknown as NodeRequire\r\n const nodeRequire = getNodeModuleRef()\r\n if (!nodeRequire) return (() => { throw new Error(\"require not available\") }) as unknown as NodeRequire\r\n return nodeRequire.createRequire(import.meta.url)\r\n}\r\n\r\nconst _require = getRequire()\r\n\r\nfunction requireNativeModule(path: string): unknown {\r\n return _require(path)\r\n}\r\n\r\nexport interface ResolveCandidatesOptions {\r\n runtimeDir: string\r\n envVarNames?: string[]\r\n includeDefaultCandidates?: boolean\r\n enforceNodeExtensionForEnvPath?: boolean\r\n}\r\n\r\nexport function resolveNativeBindingCandidates(options: ResolveCandidatesOptions): string[] {\r\n if (isBrowser) return []\r\n \r\n const { runtimeDir, envVarNames = [], includeDefaultCandidates = true, enforceNodeExtensionForEnvPath = false } = options\r\n const candidates: string[] = []\r\n const path = getNodePath()\r\n const fs = getNodeFs()\r\n\r\n for (const envVar of envVarNames) {\r\n const envPath = process.env[envVar]\r\n if (envPath) {\r\n if (enforceNodeExtensionForEnvPath && !envPath.endsWith(\".node\")) {\r\n candidates.push(envPath + \".node\")\r\n } else {\r\n candidates.push(envPath)\r\n }\r\n }\r\n }\r\n\r\n if (!includeDefaultCandidates) return candidates\r\n\r\n if (fs.existsSync(runtimeDir)) {\r\n try {\r\n const entries = fs.readdirSync(runtimeDir)\r\n for (const entry of entries) {\r\n if (entry.endsWith(\".node\")) {\r\n candidates.push(entry)\r\n }\r\n }\r\n } catch {\r\n // ignore read errors\r\n }\r\n }\r\n\r\n const platform = typeof process !== \"undefined\" ? process.platform : \"\"\r\n const ext = platform === \"win32\" ? \".dll\" : platform === \"darwin\" ? \".dylib\" : \".so\"\r\n const defaultBindingName = `tailwind_styled_parser${ext}`\r\n candidates.push(path.resolve(runtimeDir, \"..\", \"..\", \"..\", \"native\", defaultBindingName))\r\n candidates.push(path.resolve(runtimeDir, \"..\", \"..\", \"..\", \"..\", \"native\", defaultBindingName))\r\n candidates.push(path.resolve(process.cwd(), \"native\", defaultBindingName))\r\n\r\n return Array.from(new Set(candidates))\r\n}\r\n\r\nexport function resolveRuntimeDir(dir: string | undefined, importMetaUrl: string): string {\r\n if (isBrowser) return \"\"\r\n \r\n if (dir) return getNodePath().resolve(dir)\r\n try {\r\n return getNodeUrl().fileURLToPath(importMetaUrl)\r\n } catch {\r\n return process.cwd()\r\n }\r\n}\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Hashing\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport function hashContent(content: string, algorithm: string = \"md5\", length?: number): string {\r\n if (isBrowser) {\r\n // Simple hash fallback for browser\r\n let hash = 0\r\n for (let i = 0; i < content.length; i++) {\r\n const char = content.charCodeAt(i)\r\n hash = ((hash << 5) - hash) + char\r\n hash = hash & hash\r\n }\r\n return Math.abs(hash).toString(16).slice(0, length ?? 8)\r\n }\r\n const hash = getNodeCrypto().createHash(algorithm).update(content).digest(\"hex\")\r\n return length ? hash.slice(0, length) : hash\r\n}\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Error formatting\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport function formatErrorMessage(error: unknown): string {\r\n if (error instanceof TwError) return error.toString()\r\n if (error instanceof Error) return error.message\r\n return String(error)\r\n}\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// LRU Cache\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport class LRUCache<K, V> {\r\n private capacity: number\r\n private cache: Map<K, V>\r\n\r\n constructor(capacity: number) {\r\n this.capacity = capacity\r\n this.cache = new Map()\r\n }\r\n\r\n get(key: K): V | undefined {\r\n if (!this.cache.has(key)) return undefined\r\n const value = this.cache.get(key)!\r\n this.cache.delete(key)\r\n this.cache.set(key, value)\r\n return value\r\n }\r\n\r\n set(key: K, value: V): void {\r\n if (this.cache.has(key)) {\r\n this.cache.delete(key)\r\n } else if (this.cache.size >= this.capacity) {\r\n const firstKey = this.cache.keys().next().value\r\n if (firstKey !== undefined) {\r\n this.cache.delete(firstKey)\r\n }\r\n }\r\n this.cache.set(key, value)\r\n }\r\n\r\n delete(key: K): boolean {\r\n return this.cache.delete(key)\r\n }\r\n\r\n has(key: K): boolean {\r\n return this.cache.has(key)\r\n }\r\n\r\n clear(): void {\r\n this.cache.clear()\r\n }\r\n\r\n entries(): IterableIterator<[K, V]> {\r\n return this.cache.entries()\r\n }\r\n\r\n get size(): number {\r\n return this.cache.size\r\n }\r\n}\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Trace Utilities\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport type { TraceSnapshot, TraceSummary } from \"./trace\"\r\nexport {\r\n getHealthColor,\r\n getModeColor,\r\n formatMemory,\r\n formatDuration,\r\n calculateHealth,\r\n getBuildTimeColor,\r\n getMemoryColor,\r\n createTraceSnapshot,\r\n getPipelinePercentages,\r\n} from \"./trace\"\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Performance Telemetry\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\n\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Error Codes\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport type { ErrorCode } from \"./error-codes\"\r\nexport { ERROR_CODES, getSuggestion, formatErrorCode } from \"./error-codes\"\r\n\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n// Tailwind Compatibility\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport type { TailwindInfo } from \"./compatibility\"\r\nexport { detectTailwind, assertTailwindV4, getTailwindVersion, isTailwindV4 } from \"./compatibility\"\r\n\r\n// ── Native binding schemas (Zod boundary validation)\r\nexport {\r\n NativeScanFileSchema, NativeScanResultSchema,\r\n NativeAnalyzerReportSchema, NativeTransformResultSchema,\r\n NativeCssCompileResultSchema, NativeWatchResultSchema,\r\n NativeCacheEntrySchema, NativeCacheReadResultSchema,\r\n safeParseNative, parseNative,\r\n} from './native-schemas'\r\n\r\n// ── ESM-safe runtime helpers ──────────────────────────────────────────────\r\nexport {\r\n createEsmRequire,\r\n getDirname,\r\n getFilename,\r\n resolveFromRoot,\r\n tryRequire,\r\n resolveNativeNodePath,\r\n} from \"./esmHelpers\"\r\n\r\n// ── Performance telemetry ────────────────────────────────────────────────────\r\nexport {\r\n TelemetryCollector,\r\n getGlobalTelemetry,\r\n resetGlobalTelemetry,\r\n createBuildTimer,\r\n type BuildTelemetry,\r\n type TelemetrySummary,\r\n type BuildPhases,\r\n} from \"./telemetry\"\r\n\r\n// ── Config/JSON schema validation ─────────────────────────────────────────────\r\nexport {\r\n ScanCacheSchema,\r\n ScanCacheClassEntrySchema,\r\n TailwindConfigSchema,\r\n RegistryPluginEntrySchema,\r\n RegistryFileSchema,\r\n PackageJsonSchema,\r\n parseJsonWithSchema,\r\n parseJsonFileWithSchema,\r\n type ScanCache,\r\n type ScanCacheClassEntry,\r\n type TailwindConfig,\r\n type RegistryPluginEntry,\r\n type RegistryFile,\r\n type PackageJson,\r\n} from \"./configSchemas\"\r\n\r\n// ── Worker/bootstrap path resolution ─────────────────────────────────────────\r\nexport {\r\n resolveWorkerPath,\r\n resolveLoaderPath,\r\n type WorkerPathOptions,\r\n type WorkerPathResult,\r\n} from \"./workerResolver\"\r\n\r\n// ── Codegen helpers ───────────────────────────────────────────────────────────\r\nexport {\r\n generateComponentCode,\r\n generateStorybookStory,\r\n generateClassRenameCodemod,\r\n generateBarrelFile,\r\n type ComponentCodegenOptions,\r\n} from \"./codegen\"\r\n\r\n// ── Native binary resolution (QA #1) ─────────────────────────────────────────\r\nexport {\r\n resolveNativeBinary,\r\n formatNativeNotFoundError,\r\n type NativeResolutionResult,\r\n} from \"./native-resolution\"\r\n\r\n// ── Shared observability contract ────────────────────────────────────────────\r\nexport {\r\n createObservabilityClient,\r\n type ClassInspection,\r\n type ClassProperty,\r\n type ClassUsageLocation,\r\n type BuildTrace,\r\n type BuildPhaseTrace,\r\n type DashboardMetrics,\r\n type DashboardSummary,\r\n type ObservabilityClient,\r\n} from \"./observability\"\r\n","/**\r\n * tailwind-styled-v5 — Native Bridge Loader\r\n *\r\n * Uses @tailwind-styled/shared for native binding resolution.\r\n * All functions require native Rust binding - no JS fallback.\r\n */\r\n\r\nimport { resolveNativeBinary, resolveRuntimeDir } from \"@tailwind-styled/shared\"\r\nimport { createRequire } from \"node:module\"\r\n\r\nexport interface ComponentMetadata {\r\n component: string\r\n tag: string\r\n baseClass: string\r\n subComponents: Record<string, { tag?: string; class: string }>\r\n}\r\n\r\nexport interface NativeRscResult {\r\n isServer: boolean\r\n needsClientDirective: boolean\r\n clientReasons: string[]\r\n}\r\n\r\nconst log = (...args: unknown[]) => {\r\n if (process.env.DEBUG?.includes(\"compiler:native\")) {\r\n console.log(\"[compiler:native]\", ...args)\r\n }\r\n}\r\n\r\n// ── Type Exports ────────────────────────────────────────────────────────────────\r\n\r\nexport interface NativeBridge {\r\n // Core transform\r\n transformSource?: (source: string, opts?: Record<string, string>) => NativeTransformResult | null\r\n extractClassesFromSource?: (source: string) => string[]\r\n hasTwUsage?: (source: string) => boolean\r\n isAlreadyTransformed?: (source: string) => boolean\r\n // Class Extractor\r\n extractAllClasses?: (source: string) => string[]\r\n parseClasses?: (raw: string) => Array<{ raw: string; type: string }>\r\n // Application functions\r\n extractComponentUsage?: (source: string) => Array<{ component: string; propsJson: string }>\r\n normalizeAndDedupClasses?: (raw: string) => { normalized: string; duplicatesRemoved: number; uniqueCount: number }\r\n diffClassLists?: (previous: string[], current: string[]) => { added: string[]; removed: string[]; unchanged: string[]; hasChanges: boolean }\r\n batchExtractClasses?: (filePaths: string[]) => Array<{ file: string; classes: string[]; contentHash: string; ok: boolean; error?: string }>\r\n checkAgainstSafelist?: (classes: string[], safelist: string[]) => { matched: string[]; unmatched: string[]; safelistSize: number }\r\n // Batch 2\r\n hoistComponents?: (source: string) => { code: string; hoisted: string[]; warnings: string[] }\r\n compileVariantTable?: (configJson: string) => { id: string; tableJson: string; keys: string[]; defaultKey: string; combinations: number }\r\n classifyAndSortClasses?: (classes: string[]) => Array<{ className: string; bucket: string; sortOrder: number }>\r\n mergeCssDeclarations?: (cssChunks: string[]) => { declarationsJson: string; declarationString: string; count: number }\r\n analyzeClassUsage?: (classes: string[], scanResultJson: string, css: string) => Array<{ className: string; usageCount: number; filesJson: string; bundleSizeBytes: number; isDeadCode: boolean }>\r\n analyzeRsc?: (source: string, filename: string) => {\r\n isServer: boolean\r\n needsClientDirective: boolean\r\n clientReasons: string[]\r\n }\r\n analyzeClasses?: (\r\n filesJson: string,\r\n cwd: string,\r\n flags: number\r\n ) => {\r\n css?: string\r\n code: string\r\n classes: string[]\r\n changed: boolean\r\n rscJson?: string\r\n metadataJson?: string\r\n safelist?: string[]\r\n } | null\r\n // CSS compilation\r\n compileCss?: (classes: string[], prefix?: string | null) => { css: string; classes: string[] }\r\n compileCssLightning?: (classes: string[]) => string\r\n /** Post-process raw Tailwind-generated CSS dengan LightningCSS di Rust */\r\n processTailwindCssLightning?: (css: string) => { css: string; size_bytes: number; resolved_classes: string[]; unknown_classes: string[] }\r\n}\r\n\r\nexport interface NativeTransformResult {\r\n code: string\r\n classes: string[]\r\n changed: boolean\r\n rscJson?: string\r\n metadataJson?: string\r\n}\r\n\r\nexport interface ClassExtractResult {\r\n classes: string[]\r\n component_names: string[]\r\n has_tw_usage: boolean\r\n has_use_client: boolean\r\n imports: string[]\r\n}\r\n\r\nconst NATIVE_UNAVAILABLE_MESSAGE =\r\n \"[tailwind-styled/compiler v5] Native binding is required but not available.\\n\" +\r\n \"This package requires native Rust bindings. There is no JavaScript fallback.\\n\" +\r\n \"Please ensure:\\n\" +\r\n \" 1. The native module is properly installed\\n\" +\r\n \" 2. You have run: npm run build:rust (or use prebuilt binary)\\n\" +\r\n \"\\n\" +\r\n \"For help, see: https://tailwind-styled.dev/docs/install\"\r\n\r\n// ── Native Bridge - Factory Pattern\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nlet nativeBridge: NativeBridge | null = null\r\nlet bridgeLoadAttempted = false\r\nlet bridgeLoadError: Error | null = null\r\n\r\nconst isValidNativeBridge = (mod: unknown): mod is NativeBridge => {\r\n const m = mod as Partial<NativeBridge>\r\n return !!(\r\n typeof m.transformSource === \"function\" ||\r\n typeof m.extractAllClasses === \"function\" ||\r\n typeof m.hasTwUsage === \"function\"\r\n )\r\n}\r\n\r\nexport const getNativeBridge = (): NativeBridge => {\r\n if (nativeBridge) {\r\n return nativeBridge\r\n }\r\n\r\n if (bridgeLoadAttempted) {\r\n if (bridgeLoadError) {\r\n throw bridgeLoadError\r\n }\r\n throw new Error(NATIVE_UNAVAILABLE_MESSAGE)\r\n }\r\n\r\n bridgeLoadAttempted = true\r\n\r\n try {\r\n const runtimeDir = resolveRuntimeDir(undefined, import.meta.url)\r\n const require = createRequire(import.meta.url)\r\n \r\n // Use shared's native resolution\r\n const result = resolveNativeBinary(runtimeDir)\r\n\r\n if (result.path && result.path.endsWith(\".node\")) {\r\n try {\r\n const binding = require(result.path) as NativeBridge\r\n if (isValidNativeBridge(binding)) {\r\n nativeBridge = binding\r\n log(\"Native bridge loaded successfully from:\", result.path)\r\n return nativeBridge\r\n }\r\n } catch (e) {\r\n log(\"Failed to require native binding:\", e)\r\n }\r\n }\r\n\r\n throw new Error(`${NATIVE_UNAVAILABLE_MESSAGE}\\n\\nTried paths: ${result.tried.join(\"\\n\")}`)\r\n } catch (err) {\r\n bridgeLoadError = err instanceof Error ? err : new Error(String(err))\r\n log(\"Failed to load native bridge:\", bridgeLoadError.message)\r\n throw bridgeLoadError\r\n }\r\n}\r\n\r\nexport const resetNativeBridgeCache = (): void => {\r\n nativeBridge = null\r\n bridgeLoadAttempted = false\r\n bridgeLoadError = null\r\n log(\"Native bridge cache reset\")\r\n}\r\n\r\n// ── Adaptor for native results\r\n// ─────────────────────────────────────────────────────────────────────────────\r\n\r\nexport const adaptNativeResult = (\r\n raw: NativeTransformResult\r\n): {\r\n code: string\r\n classes: string[]\r\n changed: boolean\r\n rsc?: NativeRscResult\r\n metadata?: ComponentMetadata[]\r\n} => {\r\n return {\r\n code: raw.code ?? \"\",\r\n classes: raw.classes ?? [],\r\n changed: raw.changed ?? false,\r\n rsc: raw.rscJson ? JSON.parse(raw.rscJson) : undefined,\r\n metadata: raw.metadataJson ? JSON.parse(raw.metadataJson) : undefined,\r\n }\r\n}\r\n\r\n// ── Eager init — load native bridge saat module dimuat, bukan saat request pertama\r\n// Mencegah crash di Turbopack dev mode karena lazy init mid-request\r\n// ─────────────────────────────────────────────────────────────────────────────\r\nif (typeof process !== \"undefined\" && !bridgeLoadAttempted) {\r\n try {\r\n getNativeBridge()\r\n } catch {\r\n // Sudah di-capture di bridgeLoadError — akan di-throw saat dipanggil pertama kali\r\n }\r\n}","/**\r\n * tailwind-styled-v5 — Compiler Index\r\n * \r\n * All functions are backed by native Rust bindings.\r\n * No JavaScript fallback - native is required.\r\n */\r\n\r\nimport { getNativeBridge, resetNativeBridgeCache, adaptNativeResult, type NativeBridge, type NativeTransformResult, type ClassExtractResult, type ComponentMetadata, type NativeRscResult } from \"./nativeBridge\"\r\n\r\nexport { getNativeBridge, resetNativeBridgeCache, adaptNativeResult }\r\nexport type { NativeBridge, NativeTransformResult, ClassExtractResult, ComponentMetadata, NativeRscResult }\r\n\r\nexport type LoaderOutput = {\r\n code: string\r\n changed: boolean\r\n classes: string[]\r\n}\r\n\r\n// =============================================================================\r\n// CORE TRANSFORM FUNCTIONS\r\n// =============================================================================\r\n\r\nexport const transformSource = (source: string, opts?: Record<string, unknown>) => {\r\n const native = getNativeBridge()\r\n if (!native?.transformSource) {\r\n throw new Error(\"FATAL: Native binding 'transformSource' is required but not available.\")\r\n }\r\n const result = native.transformSource(source, opts as Record<string, string>)\r\n if (!result) {\r\n throw new Error(\"FATAL: transformSource returned null\")\r\n }\r\n return result\r\n}\r\n\r\nexport const hasTwUsage = (source: string): boolean => {\r\n const native = getNativeBridge()\r\n if (!native?.hasTwUsage) {\r\n throw new Error(\"FATAL: Native binding 'hasTwUsage' is required but not available.\")\r\n }\r\n return native.hasTwUsage(source)\r\n}\r\n\r\nexport const isAlreadyTransformed = (source: string): boolean => {\r\n const native = getNativeBridge()\r\n if (!native?.isAlreadyTransformed) {\r\n throw new Error(\"FATAL: Native binding 'isAlreadyTransformed' is required but not available.\")\r\n }\r\n return native.isAlreadyTransformed(source)\r\n}\r\n\r\nexport const shouldProcess = (source: string): boolean => {\r\n return hasTwUsage(source) && !isAlreadyTransformed(source)\r\n}\r\n\r\n// =============================================================================\r\n// CSS COMPILATION\r\n// =============================================================================\r\n\r\nexport const compileCssFromClasses = (classes: string[], prefix?: string | null) => {\r\n const native = getNativeBridge()\r\n if (!native?.transformSource) {\r\n throw new Error(\"FATAL: Native binding 'transformSource' is required but not available.\")\r\n }\r\n const result = native.transformSource(classes.join(\" \"), { prefix: prefix ?? \"\" })\r\n if (!result) {\r\n throw new Error(\"FATAL: transformSource returned null\")\r\n }\r\n return result\r\n}\r\n\r\nexport const buildStyleTag = (classes: string[]): string => {\r\n const result = compileCssFromClasses(classes)\r\n return result?.code ? `<style data-tailwind-styled>${result.code}</style>` : \"\"\r\n}\r\n\r\nexport const compileCssNative = (classes: string[], prefix: string | null = null) => {\r\n return compileCssFromClasses(classes, prefix)\r\n}\r\n\r\nexport const generateCssForClasses = async (\r\n classes: string[],\r\n _tailwindConfig?: Record<string, unknown>,\r\n _root?: string\r\n): Promise<string> => {\r\n const { runCssPipeline } = await import(\"./tailwindEngine\")\r\n const result = await runCssPipeline(classes)\r\n return result.css\r\n}\r\n\r\n// =============================================================================\r\n// CLASS EXTRACTION\r\n// =============================================================================\r\n\r\nexport const extractAllClasses = (source: string): string[] => {\r\n const native = getNativeBridge()\r\n if (!native?.extractAllClasses) {\r\n throw new Error(\"FATAL: Native binding 'extractAllClasses' is required but not available.\")\r\n }\r\n return native.extractAllClasses(source) || []\r\n}\r\n\r\nexport const extractClassesFromSource = (source: string): string => {\r\n const native = getNativeBridge()\r\n if (!native?.extractClassesFromSource) {\r\n throw new Error(\"FATAL: Native binding 'extractClassesFromSource' is required but not available.\")\r\n }\r\n const result = native.extractClassesFromSource(source)\r\n return Array.isArray(result) ? result.join(\" \") : String(result || \"\")\r\n}\r\n\r\nexport const astExtractClasses = (source: string, filename: string) => {\r\n const native = getNativeBridge()\r\n if (!native?.extractClassesFromSource) {\r\n throw new Error(\"FATAL: Native binding 'extractClassesFromSource' is required but not available.\")\r\n }\r\n return native.extractClassesFromSource(source) || []\r\n}\r\n\r\nexport const parseClasses = (raw: string): Array<{ raw: string; type: string }> => {\r\n const native = getNativeBridge()\r\n if (!native?.parseClasses) {\r\n // Fallback to JS implementation\r\n return parseClassesJs(raw)\r\n }\r\n return native.parseClasses(raw) || []\r\n}\r\n\r\nfunction parseClassesJs(raw: string): Array<{ raw: string; type: string }> {\r\n if (!raw || typeof raw !== \"string\") return []\r\n \r\n const classes = raw.split(/\\s+/).filter(Boolean)\r\n return classes.map((cls) => ({\r\n raw: cls,\r\n type: cls.includes(\":\") ? \"variant\" : cls.includes(\"/\") ? \"arbitrary\" : \"utility\",\r\n }))\r\n}\r\n\r\n// =============================================================================\r\n// CLASS NORMALIZATION & MERGING\r\n// =============================================================================\r\n\r\nexport const normalizeClasses = (raw: string): string => {\r\n const result = normalizeAndDedupClasses(raw)\r\n return result?.normalized || \"\"\r\n}\r\n\r\nexport const mergeClassesStatic = (classes: string): string => {\r\n const result = normalizeAndDedupClasses(classes)\r\n return result?.normalized || \"\"\r\n}\r\n\r\nfunction normalizeAndDedupClassesJs(raw: string): { normalized: string; duplicatesRemoved: number; uniqueCount: number } {\r\n const seen = new Set<string>()\r\n const result: string[] = []\r\n let duplicatesRemoved = 0\r\n\r\n for (const token of raw.split(/\\s+/)) {\r\n if (token.length === 0) continue\r\n if (seen.has(token)) {\r\n duplicatesRemoved++\r\n } else {\r\n seen.add(token)\r\n result.push(token)\r\n }\r\n }\r\n\r\n return {\r\n normalized: result.join(\" \"),\r\n duplicatesRemoved,\r\n uniqueCount: result.length,\r\n }\r\n}\r\n\r\nexport const normalizeAndDedupClasses = (raw: string) => {\r\n const native = getNativeBridge()\r\n if (!native?.normalizeAndDedupClasses) {\r\n // Fallback to JS implementation\r\n return normalizeAndDedupClassesJs(raw)\r\n }\r\n const result = native.normalizeAndDedupClasses(raw)\r\n return result || { normalized: \"\", duplicatesRemoved: 0, uniqueCount: 0 }\r\n}\r\n\r\n// =============================================================================\r\n// DEAD STYLE ELIMINATOR\r\n// =============================================================================\r\n\r\nexport const eliminateDeadCss = (css: string, deadClasses: Set<string>): string => {\r\n let result = css\r\n for (const dead of deadClasses) {\r\n result = result.replace(new RegExp(`\\\\.${dead.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}[^{]*\\\\{[^}]*\\\\}`, 'g'), '')\r\n }\r\n return result\r\n}\r\n\r\nexport const findDeadVariants = (variantConfig: Record<string, unknown>, usage: Record<string, Set<string>>) => {\r\n const unused: string[] = []\r\n const variants = variantConfig as Record<string, Record<string, string>>\r\n for (const [key, values] of Object.entries(variants)) {\r\n for (const [value] of Object.entries(values)) {\r\n const keyValue = `${key}:${value}`\r\n if (!usage[key]?.has(value)) {\r\n unused.push(keyValue)\r\n }\r\n }\r\n }\r\n return unused\r\n}\r\n\r\nexport const runElimination = (css: string, scanResult: unknown) => {\r\n const scanJson = JSON.stringify(scanResult)\r\n const classes = extractAllClasses(css)\r\n const usage = analyzeClassUsage(classes, scanJson, css) || []\r\n const deadClasses = new Set((usage as Array<{ isDeadCode: boolean; className: string }>).filter(u => u.isDeadCode).map(u => u.className))\r\n return eliminateDeadCss(css, deadClasses)\r\n}\r\n\r\nexport const optimizeCss = (css: string): string => {\r\n const classes = extractAllClasses(css)\r\n const usage = analyzeClassUsage(classes, \"[]\", css) || []\r\n const usedClasses = new Set((usage as Array<{ isDeadCode: boolean; className: string }>).filter(u => !u.isDeadCode).map(u => u.className))\r\n \r\n let result = css\r\n const classRegex = /\\.([a-zA-Z0-9_-]+)/g\r\n result = result.replace(classRegex, (match, className) => {\r\n return usedClasses.has(className) ? match : ''\r\n })\r\n \r\n result = result.replace(/[^{}]*\\{\\s*\\}/g, '')\r\n return result.trim()\r\n}\r\n\r\nexport const scanProjectUsage = (dirs: string[], cwd: string) => {\r\n const path = require('node:path')\r\n const files = dirs.map(dir => path.resolve(cwd, dir))\r\n const results = batchExtractClasses(files) || []\r\n \r\n const combined: Record<string, Record<string, Set<string>>> = {}\r\n for (const result of results) {\r\n if (result.ok && result.classes) {\r\n for (const cls of result.classes) {\r\n if (!combined[cls]) combined[cls] = {}\r\n combined[cls][result.file] = new Set([cls])\r\n }\r\n }\r\n }\r\n return combined\r\n}\r\n\r\n// =============================================================================\r\n// COMPONENT ANALYSIS\r\n// =============================================================================\r\n\r\nexport const extractComponentUsage = (source: string): Array<{ component: string; propsJson: string }> => {\r\n const native = getNativeBridge()\r\n if (!native?.extractComponentUsage) {\r\n throw new Error(\"FATAL: Native binding 'extractComponentUsage' is required but not available.\")\r\n }\r\n return native.extractComponentUsage(source) || []\r\n}\r\n\r\n// =============================================================================\r\n// DIFF & BATCH OPERATIONS\r\n// =============================================================================\r\n\r\nexport const diffClassLists = (previous: string[], current: string[]) => {\r\n const native = getNativeBridge()\r\n if (!native?.diffClassLists) {\r\n throw new Error(\"FATAL: Native binding 'diffClassLists' is required but not available.\")\r\n }\r\n return native.diffClassLists(previous, current) || { added: [], removed: [], unchanged: [], hasChanges: false }\r\n}\r\n\r\nexport const batchExtractClasses = (filePaths: string[]) => {\r\n const native = getNativeBridge()\r\n if (!native?.batchExtractClasses) {\r\n throw new Error(\"FATAL: Native binding 'batchExtractClasses' is required but not available.\")\r\n }\r\n return native.batchExtractClasses(filePaths) || []\r\n}\r\n\r\nexport const checkAgainstSafelist = (classes: string[], safelist: string[]) => {\r\n const native = getNativeBridge()\r\n if (!native?.checkAgainstSafelist) {\r\n throw new Error(\"FATAL: Native binding 'checkAgainstSafelist' is required but not available.\")\r\n }\r\n return native.checkAgainstSafelist(classes, safelist) || { matched: [], unmatched: [], safelistSize: 0 }\r\n}\r\n\r\n// =============================================================================\r\n// HOISTING\r\n// =============================================================================\r\n\r\nexport const hoistComponents = (source: string) => {\r\n const native = getNativeBridge()\r\n if (!native?.hoistComponents) {\r\n throw new Error(\"FATAL: Native binding 'hoistComponents' is required but not available.\")\r\n }\r\n return native.hoistComponents(source) || { code: source, hoisted: [], warnings: [] }\r\n}\r\n\r\n// =============================================================================\r\n// VARIANT COMPILATION\r\n// =============================================================================\r\n\r\nexport const compileVariantTable = (configJson: string) => {\r\n const native = getNativeBridge()\r\n if (!native?.compileVariantTable) {\r\n throw new Error(\"FATAL: Native binding 'compileVariantTable' is required but not available.\")\r\n }\r\n return native.compileVariantTable(configJson) || { id: \"\", tableJson: \"{}\", keys: [], defaultKey: \"\", combinations: 0 }\r\n}\r\n\r\nexport const compileVariants = (componentId: string, config: Record<string, unknown>) => {\r\n return compileVariantTable(JSON.stringify({ componentId, ...config }))\r\n}\r\n\r\n// =============================================================================\r\n// CSS ANALYSIS\r\n// =============================================================================\r\n\r\nexport const classifyAndSortClasses = (classes: string[]) => {\r\n const native = getNativeBridge()\r\n if (!native?.classifyAndSortClasses) {\r\n throw new Error(\"FATAL: Native binding 'classifyAndSortClasses' is required but not available.\")\r\n }\r\n return native.classifyAndSortClasses(classes) || []\r\n}\r\n\r\nexport const mergeCssDeclarations = (cssChunks: string[]) => {\r\n const native = getNativeBridge()\r\n if (!native?.mergeCssDeclarations) {\r\n throw new Error(\"FATAL: Native binding 'mergeCssDeclarations' is required but not available.\")\r\n }\r\n return native.mergeCssDeclarations(cssChunks) || { declarationsJson: \"{}\", declarationString: \"\", count: 0 }\r\n}\r\n\r\nexport const analyzeClassUsage = (classes: string[], scanResultJson: string, css: string) => {\r\n const native = getNativeBridge()\r\n if (!native?.analyzeClassUsage) {\r\n throw new Error(\"FATAL: Native binding 'analyzeClassUsage' is required but not available.\")\r\n }\r\n return native.analyzeClassUsage(classes, scanResultJson, css) || []\r\n}\r\n\r\n// =============================================================================\r\n// RSC ANALYSIS\r\n// =============================================================================\r\n\r\nexport const analyzeRsc = (source: string, filename: string) => {\r\n const native = getNativeBridge()\r\n if (!native?.analyzeRsc) {\r\n throw new Error(\"FATAL: Native binding 'analyzeRsc' is required but not available.\")\r\n }\r\n return native.analyzeRsc(source, filename) || { isServer: true, needsClientDirective: false, clientReasons: [] }\r\n}\r\n\r\nexport const analyzeFile = (source: string, filename: string) => {\r\n const rsc = analyzeRsc(source, filename)\r\n return {\r\n isServer: rsc?.isServer ?? true,\r\n needsClientDirective: rsc?.needsClientDirective ?? false,\r\n clientReasons: rsc?.clientReasons ?? [],\r\n interactiveClasses: [],\r\n canStaticResolveVariants: true,\r\n }\r\n}\r\n\r\nexport const analyzeVariantUsage = (source: string, componentName: string, variantKeys: string[]) => {\r\n const rsc = analyzeRsc(source, componentName)\r\n return { \r\n resolved: {} as Record<string, string>, \r\n dynamic: [] as string[] \r\n }\r\n}\r\n\r\nexport const injectClientDirective = (source: string): string => {\r\n if (!source.includes('\"use client\"') && !source.includes(\"'use client'\")) {\r\n return '\"use client\";\\n' + source\r\n }\r\n return source\r\n}\r\n\r\nexport const injectServerOnlyComment = (source: string): string => {\r\n return `/* @server-only */\\n${source}`\r\n}\r\n\r\n// =============================================================================\r\n// FULL ANALYSIS\r\n// =============================================================================\r\n\r\nexport const analyzeClasses = (filesJson: string, cwd: string, flags: number) => {\r\n const native = getNativeBridge()\r\n if (!native?.analyzeClasses) {\r\n throw new Error(\"FATAL: Native binding 'analyzeClasses' is required but not available.\")\r\n }\r\n return native.analyzeClasses(filesJson, cwd, flags)\r\n}\r\n\r\n// =============================================================================\r\n// SAFELIST\r\n// =============================================================================\r\n\r\nexport const generateSafelist = (scanDirs: string[], outputPath?: string, cwd?: string) => {\r\n const classes = scanProjectUsage(scanDirs, cwd || process.cwd())\r\n const allClasses = Object.keys(classes).sort()\r\n \r\n if (outputPath) {\r\n const fs = require('node:fs')\r\n fs.writeFileSync(outputPath, JSON.stringify(allClasses, null, 2))\r\n }\r\n \r\n return allClasses\r\n}\r\n\r\nexport const loadSafelist = (safelistPath: string): string[] => {\r\n const fs = require('node:fs')\r\n try {\r\n const content = fs.readFileSync(safelistPath, 'utf-8')\r\n return JSON.parse(content)\r\n } catch {\r\n return []\r\n }\r\n}\r\n\r\n// =============================================================================\r\n// CONFIG LOADING\r\n// =============================================================================\r\n\r\nexport const loadTailwindConfig = (cwd: string = process.cwd()) => {\r\n const fs = require('node:fs')\r\n const path = require('node:path')\r\n \r\n const configFiles = [\r\n 'tailwind.config.ts',\r\n 'tailwind.config.js',\r\n 'tailwind.config.mjs',\r\n 'tailwind.config.cjs',\r\n ]\r\n \r\n for (const file of configFiles) {\r\n const fullPath = path.join(cwd, file)\r\n if (fs.existsSync(fullPath)) {\r\n const mod = require(fullPath)\r\n return mod.default || mod\r\n }\r\n }\r\n \r\n return {}\r\n}\r\n\r\nexport const getContentPaths = (cwd: string = process.cwd()) => {\r\n const path = require('node:path')\r\n return {\r\n content: [\r\n path.join(cwd, 'src/**/*.{js,ts,jsx,tsx}'),\r\n path.join(cwd, 'app/**/*.{js,ts,jsx,tsx}'),\r\n path.join(cwd, 'pages/**/*.{js,ts,jsx,tsx}'),\r\n ],\r\n }\r\n}\r\n\r\n// =============================================================================\r\n// LOADER\r\n// =============================================================================\r\n\r\nexport const runLoaderTransform = (ctx: { filepath: string; source: string; options?: Record<string, unknown> }) => {\r\n const { filepath, source, options } = ctx\r\n const result = transformSource(source, { filename: filepath, ...options })\r\n return {\r\n code: result?.code || \"\",\r\n changed: result?.changed || false,\r\n classes: result?.classes || [],\r\n } as LoaderOutput\r\n}\r\n\r\nexport const shouldSkipFile = (filepath: string): boolean => {\r\n const SKIP_PATHS = ['node_modules', '.next', '.rspack-dist', '.turbo', 'dist/', 'out/']\r\n const skipExtensions = ['.css', '.json', '.md', '.txt', '.yaml', '.yml']\r\n \r\n for (const p of SKIP_PATHS) {\r\n if (filepath.includes(p)) return true\r\n }\r\n for (const ext of skipExtensions) {\r\n if (filepath.endsWith(ext)) return true\r\n }\r\n return false\r\n}\r\n\r\n// =============================================================================\r\n// ROUTE CSS COLLECTOR\r\n// =============================================================================\r\n\r\nexport const fileToRoute = (filepath: string): string | null => {\r\n const normalized = filepath.replace(/\\\\/g, '/')\r\n \r\n if (normalized.includes('/layout.') || normalized.includes('/loading.') || normalized.includes('/error.')) {\r\n return '__global'\r\n }\r\n \r\n const pageMatch = normalized.match(/\\/app\\/(.+?)\\/page\\.[tj]sx?$/)\r\n if (pageMatch) return `/${pageMatch[1]}`\r\n \r\n const rootPage = normalized.match(/\\/app\\/page\\.[tj]sx?$/)\r\n if (rootPage) return '/'\r\n \r\n return null\r\n}\r\n\r\nexport const getAllRoutes = (): string[] => {\r\n return ['/', '__global']\r\n}\r\n\r\nexport const getRouteClasses = (route: string): Set<string> => {\r\n return new Set()\r\n}\r\n\r\nexport const registerFileClasses = (filepath: string, classes: string[]): void => {\r\n // Could be implemented with native\r\n}\r\n\r\nexport const registerGlobalClasses = (classes: string[]): void => {\r\n // Could be implemented with native\r\n}\r\n\r\n// =============================================================================\r\n// INCREMENTAL ENGINE\r\n// =============================================================================\r\n\r\nlet incrementalEngineInstance: unknown = null\r\n\r\nexport const getIncrementalEngine = () => {\r\n if (!incrementalEngineInstance) {\r\n incrementalEngineInstance = {\r\n compile: (source: string) => transformSource(source),\r\n }\r\n }\r\n return incrementalEngineInstance\r\n}\r\n\r\nexport const resetIncrementalEngine = () => {\r\n incrementalEngineInstance = null\r\n}\r\n\r\nexport const IncrementalEngine = class {\r\n compile(source: string) {\r\n return transformSource(source)\r\n }\r\n}\r\n\r\n// =============================================================================\r\n// STYLE BUCKET SYSTEM\r\n// =============================================================================\r\n\r\nlet bucketEngineInstance: unknown = null\r\n\r\nexport const getBucketEngine = () => {\r\n if (!bucketEngineInstance) {\r\n bucketEngineInstance = {\r\n add: (className: string) => className,\r\n get: (bucket: string) => [],\r\n }\r\n }\r\n return bucketEngineInstance\r\n}\r\n\r\nexport const resetBucketEngine = () => {\r\n bucketEngineInstance = null\r\n}\r\n\r\nexport const BucketEngine = class {\r\n add(className: string) {\r\n return className\r\n }\r\n}\r\n\r\nexport const classifyNode = (node: unknown): string => {\r\n return 'unknown'\r\n}\r\n\r\nexport const detectConflicts = (classes: string[]): string[] => {\r\n return []\r\n}\r\n\r\nexport const bucketSort = (classes: string[]): string[] => {\r\n return classes\r\n}","/**\r\n * tailwind-styled-v4 - Webpack Loader\r\n */\r\n\r\nimport {\r\n type LoaderOutput,\r\n runLoaderTransform,\r\n shouldSkipFile,\r\n registerFileClasses,\r\n} from \"@tailwind-styled/compiler/internal\"\r\nimport path from \"node:path\"\r\nimport { z } from \"zod\"\r\n\r\ninterface WebpackLoaderOptions {\r\n mode?: \"zero-runtime\"\r\n autoClientBoundary?: boolean\r\n addDataAttr?: boolean\r\n hoist?: boolean\r\n routeCss?: boolean\r\n incremental?: boolean\r\n verbose?: boolean\r\n preserveImports?: boolean\r\n}\r\n\r\ninterface WebpackContext {\r\n resourcePath: string\r\n getOptions(): WebpackLoaderOptions\r\n async?(): ((err: Error | null, result?: string) => void) | undefined\r\n cacheable?(flag?: boolean): void\r\n}\r\n\r\nconst WebpackLoaderOptionsSchema = z.object({\r\n mode: z.literal(\"zero-runtime\").optional(),\r\n autoClientBoundary: z.boolean().optional(),\r\n addDataAttr: z.boolean().optional(),\r\n hoist: z.boolean().optional(),\r\n routeCss: z.boolean().optional(),\r\n incremental: z.boolean().optional(),\r\n verbose: z.boolean().optional(),\r\n preserveImports: z.boolean().optional(),\r\n})\r\n\r\nconst isNextBuildArtifact = (filepath: string): boolean =>\r\n filepath.includes(`${path.sep}.next${path.sep}`)\r\n\r\nexport default function webpackLoader(this: WebpackContext, source: string): void {\r\n const callback = this.async?.()\r\n if (!callback) {\r\n throw new Error(\"[tailwind-styled] Async loader callback is not available.\")\r\n }\r\n\r\n this.cacheable?.(true)\r\n const filepath = this.resourcePath\r\n\r\n if (shouldSkipFile(filepath) || isNextBuildArtifact(filepath)) {\r\n callback(null, source)\r\n return\r\n }\r\n\r\n try {\r\n const options = WebpackLoaderOptionsSchema.parse(this.getOptions())\r\n\r\n const output: LoaderOutput = runLoaderTransform({\r\n filepath,\r\n source,\r\n options: {\r\n mode: options.mode,\r\n autoClientBoundary: options.autoClientBoundary ?? true,\r\n addDataAttr: options.addDataAttr,\r\n hoist: options.hoist,\r\n filename: filepath,\r\n routeCss: options.routeCss,\r\n incremental: options.incremental,\r\n verbose: options.verbose,\r\n preserveImports: options.preserveImports ?? true,\r\n },\r\n })\r\n\r\n if (typeof output.code !== \"string\") {\r\n throw new TypeError(`[tailwind-styled] Invalid transform output for ${filepath}: code is not a string`)\r\n }\r\n\r\n if (options.verbose && output.changed) {\r\n const rsc = (output as any).rsc\r\n const engine = (output as any).engine ?? \"js\"\r\n const env = rsc?.isServer ? \"server\" : \"client\"\r\n const name = path.basename(filepath)\r\n process.stdout.write(\r\n `[tailwind-styled/webpack] ${name} -> ${output.classes.length} classes (${env}) [${engine}]\\n`\r\n )\r\n }\r\n\r\n // Register classes ke route map untuk TwCssInjector\r\n if (output.classes.length > 0) {\r\n registerFileClasses(filepath, output.classes)\r\n }\r\n\r\n callback(null, output.code)\r\n } catch (err) {\r\n if (process.env.NODE_ENV === \"production\") {\r\n callback(err instanceof Error ? err : new Error(String(err)))\r\n return\r\n }\r\n\r\n console.warn(`[tailwind-styled-v4] Webpack transform failed for ${filepath}:`, err)\r\n callback(null, source)\r\n }\r\n}"]}
|