tailwind-styled-v4 5.0.8 → 5.0.10

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.
Files changed (140) hide show
  1. package/CHANGELOG.md +204 -416
  2. package/README.md +45 -15
  3. package/dist/{analyzeWorkspace-DuJKh7Ty.d.mts → analyzeWorkspace-BS5O4rhC.d.mts} +47 -2
  4. package/dist/{analyzeWorkspace-Ct_NTAWt.d.ts → analyzeWorkspace-DDOQdzzI.d.ts} +47 -2
  5. package/dist/analyzer.d.mts +5 -3
  6. package/dist/analyzer.d.ts +5 -3
  7. package/dist/analyzer.js +563 -468
  8. package/dist/analyzer.js.map +1 -1
  9. package/dist/analyzer.mjs +562 -467
  10. package/dist/analyzer.mjs.map +1 -1
  11. package/dist/animate.d.mts +4 -7
  12. package/dist/animate.d.ts +4 -7
  13. package/dist/animate.js +171 -265
  14. package/dist/animate.js.map +1 -1
  15. package/dist/animate.mjs +165 -264
  16. package/dist/animate.mjs.map +1 -1
  17. package/dist/atomic.d.mts +22 -1
  18. package/dist/atomic.d.ts +22 -1
  19. package/dist/atomic.js +221 -165
  20. package/dist/atomic.js.map +1 -1
  21. package/dist/atomic.mjs +200 -165
  22. package/dist/atomic.mjs.map +1 -1
  23. package/dist/cli.d.mts +60 -1
  24. package/dist/cli.d.ts +60 -1
  25. package/dist/cli.js +1261 -1517
  26. package/dist/cli.js.map +1 -1
  27. package/dist/cli.mjs +1238 -1513
  28. package/dist/cli.mjs.map +1 -1
  29. package/dist/compiler.d.mts +38 -7
  30. package/dist/compiler.d.ts +38 -7
  31. package/dist/compiler.js +174 -197
  32. package/dist/compiler.js.map +1 -1
  33. package/dist/compiler.mjs +151 -194
  34. package/dist/compiler.mjs.map +1 -1
  35. package/dist/devtools.js +7 -31
  36. package/dist/devtools.js.map +1 -1
  37. package/dist/devtools.mjs +7 -31
  38. package/dist/devtools.mjs.map +1 -1
  39. package/dist/engine.d.mts +134 -63
  40. package/dist/engine.d.ts +134 -63
  41. package/dist/engine.js +2863 -2482
  42. package/dist/engine.js.map +1 -1
  43. package/dist/engine.mjs +2852 -2485
  44. package/dist/engine.mjs.map +1 -1
  45. package/dist/{index-eWAocnD2.d.mts → index-NDINUhLN.d.mts} +3 -1
  46. package/dist/{index-eWAocnD2.d.ts → index-NDINUhLN.d.ts} +3 -1
  47. package/dist/index.d.mts +63 -32
  48. package/dist/index.d.ts +63 -32
  49. package/dist/index.js +335 -169
  50. package/dist/index.js.map +1 -1
  51. package/dist/index.mjs +315 -169
  52. package/dist/index.mjs.map +1 -1
  53. package/dist/{liveTokenEngine-DSUk88P6.d.ts → liveTokenEngine-CN9ian1R.d.ts} +1 -1
  54. package/dist/{liveTokenEngine-CX5_0c4q.d.mts → liveTokenEngine-DKoWRtqH.d.mts} +1 -1
  55. package/dist/next.d.mts +10 -4
  56. package/dist/next.d.ts +10 -4
  57. package/dist/next.js +32 -45
  58. package/dist/next.js.map +1 -1
  59. package/dist/next.mjs +30 -43
  60. package/dist/next.mjs.map +1 -1
  61. package/dist/plugin-api.d.mts +8 -2
  62. package/dist/plugin-api.d.ts +8 -2
  63. package/dist/plugin-api.js +14 -2
  64. package/dist/plugin-api.js.map +1 -1
  65. package/dist/plugin-api.mjs +14 -3
  66. package/dist/plugin-api.mjs.map +1 -1
  67. package/dist/plugin-registry.js +51 -11
  68. package/dist/plugin-registry.js.map +1 -1
  69. package/dist/plugin-registry.mjs +51 -11
  70. package/dist/plugin-registry.mjs.map +1 -1
  71. package/dist/plugin.d.mts +5 -7
  72. package/dist/plugin.d.ts +5 -7
  73. package/dist/plugin.js +16 -15
  74. package/dist/plugin.js.map +1 -1
  75. package/dist/plugin.mjs +16 -16
  76. package/dist/plugin.mjs.map +1 -1
  77. package/dist/rspack.js +17 -38
  78. package/dist/rspack.js.map +1 -1
  79. package/dist/rspack.mjs +15 -36
  80. package/dist/rspack.mjs.map +1 -1
  81. package/dist/runtime.d.mts +2 -2
  82. package/dist/runtime.d.ts +2 -2
  83. package/dist/scanner.d.mts +10 -1
  84. package/dist/scanner.d.ts +10 -1
  85. package/dist/scanner.js +298 -124
  86. package/dist/scanner.js.map +1 -1
  87. package/dist/scanner.mjs +296 -124
  88. package/dist/scanner.mjs.map +1 -1
  89. package/dist/shared.d.mts +1 -1
  90. package/dist/shared.d.ts +1 -1
  91. package/dist/shared.js +104 -176
  92. package/dist/shared.js.map +1 -1
  93. package/dist/shared.mjs +85 -176
  94. package/dist/shared.mjs.map +1 -1
  95. package/dist/storybook-addon.d.mts +1 -1
  96. package/dist/storybook-addon.d.ts +1 -1
  97. package/dist/svelte.d.mts +1 -1
  98. package/dist/svelte.d.ts +1 -1
  99. package/dist/svelte.js +166 -3
  100. package/dist/svelte.js.map +1 -1
  101. package/dist/svelte.mjs +143 -1
  102. package/dist/svelte.mjs.map +1 -1
  103. package/dist/syntax.js +21 -21
  104. package/dist/syntax.js.map +1 -1
  105. package/dist/syntax.mjs +21 -21
  106. package/dist/syntax.mjs.map +1 -1
  107. package/dist/testing.js +9 -1
  108. package/dist/testing.js.map +1 -1
  109. package/dist/testing.mjs +9 -1
  110. package/dist/testing.mjs.map +1 -1
  111. package/dist/theme.d.mts +2 -2
  112. package/dist/theme.d.ts +2 -2
  113. package/dist/theme.js +40 -112
  114. package/dist/theme.js.map +1 -1
  115. package/dist/theme.mjs +37 -110
  116. package/dist/theme.mjs.map +1 -1
  117. package/dist/turbopackLoader.js +84 -126
  118. package/dist/turbopackLoader.js.map +1 -1
  119. package/dist/turbopackLoader.mjs +68 -124
  120. package/dist/turbopackLoader.mjs.map +1 -1
  121. package/dist/tw.js +1256 -1517
  122. package/dist/tw.js.map +1 -1
  123. package/dist/tw.mjs +1236 -1513
  124. package/dist/tw.mjs.map +1 -1
  125. package/dist/vite.js +1783 -823
  126. package/dist/vite.js.map +1 -1
  127. package/dist/vite.mjs +1767 -821
  128. package/dist/vite.mjs.map +1 -1
  129. package/dist/vue.d.mts +1 -1
  130. package/dist/vue.d.ts +1 -1
  131. package/dist/vue.js +165 -4
  132. package/dist/vue.js.map +1 -1
  133. package/dist/vue.mjs +141 -1
  134. package/dist/vue.mjs.map +1 -1
  135. package/dist/webpackLoader.js +69 -108
  136. package/dist/webpackLoader.js.map +1 -1
  137. package/dist/webpackLoader.mjs +49 -104
  138. package/dist/webpackLoader.mjs.map +1 -1
  139. package/native/tailwind-styled-native.node +0 -0
  140. package/package.json +22 -24
package/dist/scanner.mjs CHANGED
@@ -1,8 +1,10 @@
1
- import path3 from 'path';
1
+ import 'crypto';
2
+ import fs3 from 'fs';
3
+ import path5 from 'path';
2
4
  import { fileURLToPath } from 'url';
3
- import fs from 'fs';
4
5
  import { createRequire } from 'module';
5
- import { Worker } from 'worker_threads';
6
+ import { isMainThread, parentPort, workerData, Worker } from 'worker_threads';
7
+ import { availableParallelism } from 'os';
6
8
  import { z } from 'zod';
7
9
 
8
10
  /* tailwind-styled-v4 v5.0.4 | MIT | https://github.com/dictionar32/tailwind-styled-v4 */
@@ -10,12 +12,6 @@ var __defProp = Object.defineProperty;
10
12
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
13
  var __getOwnPropNames = Object.getOwnPropertyNames;
12
14
  var __hasOwnProp = Object.prototype.hasOwnProperty;
13
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
14
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
15
- }) : x)(function(x) {
16
- if (typeof require !== "undefined") return require.apply(this, arguments);
17
- throw Error('Dynamic require of "' + x + '" is not supported');
18
- });
19
15
  var __esm = (fn, res) => function __init() {
20
16
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
21
17
  };
@@ -32,34 +28,6 @@ var __copyProps = (to, from, except, desc) => {
32
28
  return to;
33
29
  };
34
30
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
-
36
- // packages/domain/shared/src/index.ts
37
- function getNodeModuleRef() {
38
- if (isBrowser) return null;
39
- if (nodeModuleRef !== null) return nodeModuleRef;
40
- try {
41
- const test = typeof __require === "function" ? __require("module") : null;
42
- nodeModuleRef = test;
43
- return test;
44
- } catch {
45
- nodeModuleRef = null;
46
- return null;
47
- }
48
- }
49
- function getNodeFs() {
50
- if (isBrowser) throw new Error("node:fs not available in browser");
51
- const nodeRequire = getNodeModuleRef();
52
- if (!nodeRequire) throw new Error("require not available");
53
- if (!_nodeFs) _nodeFs = nodeRequire.createRequire(import.meta.url)("node:fs");
54
- return _nodeFs;
55
- }
56
- function getNodePath() {
57
- if (isBrowser) throw new Error("node:path not available in browser");
58
- const nodeRequire = getNodeModuleRef();
59
- if (!nodeRequire) throw new Error("require not available");
60
- if (!_nodePath) _nodePath = nodeRequire.createRequire(import.meta.url)("node:path");
61
- return _nodePath;
62
- }
63
31
  function createLogger(namespace) {
64
32
  const prefix = `[${namespace}]`;
65
33
  return {
@@ -89,24 +57,19 @@ function createDebugLogger(namespace, label) {
89
57
  }
90
58
  };
91
59
  }
92
- function formatIssuePath(path4) {
93
- if (!path4 || path4.length === 0) return "(root)";
94
- return path4.map(
60
+ function formatIssuePath(path6) {
61
+ if (!path6 || path6.length === 0) return "(root)";
62
+ return path6.map(
95
63
  (segment) => typeof segment === "symbol" ? segment.description ?? segment.toString() : String(segment)
96
64
  ).join(".");
97
65
  }
98
66
  function loadNativeBinding(options) {
99
- if (isBrowser) {
100
- return { binding: null, loadErrors: [{ path: "", message: "Native bindings not available in browser" }] };
101
- }
102
67
  const { runtimeDir, candidates, isValid } = options;
103
68
  const loadErrors = [];
104
- const path4 = getNodePath();
105
- const fs2 = getNodeFs();
106
69
  for (const candidate of candidates) {
107
- const candidatePath = path4.resolve(runtimeDir, candidate);
70
+ const candidatePath = path5.resolve(runtimeDir, candidate);
108
71
  try {
109
- if (!fs2.existsSync(candidatePath) && !fs2.existsSync(candidatePath + ".node")) {
72
+ if (!fs3.existsSync(candidatePath) && !fs3.existsSync(candidatePath + ".node")) {
110
73
  continue;
111
74
  }
112
75
  const mod = requireNativeModule(candidatePath);
@@ -120,62 +83,48 @@ function loadNativeBinding(options) {
120
83
  }
121
84
  return { binding: null, loadErrors };
122
85
  }
123
- function getRequire() {
124
- if (isBrowser) return (() => {
125
- throw new Error("require not available in browser");
126
- });
127
- const nodeRequire = getNodeModuleRef();
128
- if (!nodeRequire) return (() => {
129
- throw new Error("require not available");
130
- });
131
- return nodeRequire.createRequire(import.meta.url);
132
- }
133
- function requireNativeModule(path4) {
134
- return _require(path4);
86
+ function requireNativeModule(p) {
87
+ return _require(p);
135
88
  }
136
89
  function resolveNativeBindingCandidates(options) {
137
- if (isBrowser) return [];
138
- const { runtimeDir, envVarNames = [], includeDefaultCandidates = true, enforceNodeExtensionForEnvPath = false } = options;
90
+ const {
91
+ envVarNames = ["TW_NATIVE_PATH", "TWS_NATIVE_PATH"],
92
+ includeDefaultCandidates = true,
93
+ enforceNodeExtensionForEnvPath = false
94
+ } = options;
95
+ const runtimeDir = options.runtimeDir || process.cwd();
139
96
  const candidates = [];
140
- const path4 = getNodePath();
141
- const fs2 = getNodeFs();
142
97
  for (const envVar of envVarNames) {
143
98
  const envPath = process.env[envVar];
144
99
  if (envPath) {
145
- if (enforceNodeExtensionForEnvPath && !envPath.endsWith(".node")) {
146
- candidates.push(envPath + ".node");
147
- } else {
148
- candidates.push(envPath);
149
- }
100
+ candidates.push(enforceNodeExtensionForEnvPath && !envPath.endsWith(".node") ? envPath + ".node" : envPath);
150
101
  }
151
102
  }
152
103
  if (!includeDefaultCandidates) return candidates;
153
- if (fs2.existsSync(runtimeDir)) {
104
+ if (fs3.existsSync(runtimeDir)) {
154
105
  try {
155
- const entries = fs2.readdirSync(runtimeDir);
156
- for (const entry of entries) {
157
- if (entry.endsWith(".node")) {
158
- candidates.push(entry);
159
- }
106
+ for (const entry of fs3.readdirSync(runtimeDir)) {
107
+ if (entry.endsWith(".node")) candidates.push(entry);
160
108
  }
161
109
  } catch {
162
110
  }
163
111
  }
164
- const platform = typeof process !== "undefined" ? process.platform : "";
165
- const ext = platform === "win32" ? ".dll" : platform === "darwin" ? ".dylib" : ".so";
166
- const defaultBindingName = `tailwind_styled_parser${ext}`;
167
- candidates.push(path4.resolve(runtimeDir, "..", "..", "..", "native", defaultBindingName));
168
- candidates.push(path4.resolve(runtimeDir, "..", "..", "..", "..", "native", defaultBindingName));
169
- candidates.push(path4.resolve(process.cwd(), "native", defaultBindingName));
112
+ const BINARY_NAMES = ["tailwind-styled-native", "tailwind_styled_parser"];
113
+ const napiPlatform = process.platform === "linux" && process.arch === "x64" ? "linux-x64-gnu" : process.platform === "linux" && process.arch === "arm64" ? "linux-arm64-gnu" : `${process.platform}-${process.arch}`;
114
+ for (const bin of BINARY_NAMES) {
115
+ candidates.push(path5.resolve(runtimeDir, `${bin}.node`));
116
+ candidates.push(path5.resolve(runtimeDir, `${bin}.${napiPlatform}.node`));
117
+ candidates.push(path5.resolve(runtimeDir, "..", "..", "..", "..", "native", `${bin}.node`));
118
+ candidates.push(path5.resolve(runtimeDir, "..", "..", "..", "..", "native", `${bin}.${napiPlatform}.node`));
119
+ candidates.push(path5.resolve(runtimeDir, "..", "..", "..", "native", `${bin}.node`));
120
+ candidates.push(path5.resolve(process.cwd(), "native", `${bin}.node`));
121
+ candidates.push(path5.resolve(process.cwd(), "native", `${bin}.${napiPlatform}.node`));
122
+ }
170
123
  return Array.from(new Set(candidates));
171
124
  }
172
- var isBrowser, nodeModuleRef, _nodeFs, _nodePath, TwError, _require;
125
+ var TwError, _require;
173
126
  var init_src = __esm({
174
127
  "packages/domain/shared/src/index.ts"() {
175
- isBrowser = typeof window !== "undefined" || typeof document !== "undefined";
176
- nodeModuleRef = null;
177
- _nodeFs = null;
178
- _nodePath = null;
179
128
  TwError = class _TwError extends Error {
180
129
  /** @deprecated Gunakan source */
181
130
  domain;
@@ -209,8 +158,8 @@ var init_src = __esm({
209
158
  /** Buat TwError dari ZodError — dukung shape Zod v3 (`errors`) dan v4 (`issues`). */
210
159
  static fromZod(err) {
211
160
  const first = err.issues?.[0] ?? err.errors?.[0];
212
- const path4 = formatIssuePath(first?.path);
213
- const message = first ? `${path4}: ${first.message}` : "Schema validation failed";
161
+ const path6 = formatIssuePath(first?.path);
162
+ const message = first ? `${path6}: ${first.message}` : "Schema validation failed";
214
163
  return new _TwError("validation", "SCHEMA_VALIDATION_FAILED", message, err);
215
164
  }
216
165
  static wrap(source, code, err) {
@@ -228,21 +177,33 @@ var init_src = __esm({
228
177
  return `[${this.source.toUpperCase()}:${this.code}] ${this.message}`;
229
178
  }
230
179
  };
231
- _require = getRequire();
180
+ _require = createRequire(import.meta.url);
232
181
  }
233
182
  });
234
183
 
235
184
  // packages/domain/scanner/src/native-bridge.ts
236
185
  var native_bridge_exports = {};
237
186
  __export(native_bridge_exports, {
187
+ batchExtractClassesNative: () => batchExtractClassesNative,
238
188
  cachePriorityNative: () => cachePriorityNative,
239
189
  cacheReadNative: () => cacheReadNative,
240
190
  cacheWriteNative: () => cacheWriteNative,
191
+ collectFilesNative: () => collectFilesNative,
192
+ computeCacheStatsNative: () => computeCacheStatsNative,
241
193
  extractClassesNative: () => extractClassesNative,
194
+ generateSubComponentTypesNative: () => generateSubComponentTypesNative,
242
195
  hasNativeScannerBinding: () => hasNativeScannerBinding,
243
196
  hashContentNative: () => hashContentNative,
244
197
  isRustCacheAvailable: () => isRustCacheAvailable,
198
+ pruneStaleEntriesNative: () => pruneStaleEntriesNative,
199
+ rebuildWorkspaceResultNative: () => rebuildWorkspaceResultNative,
245
200
  resetScannerBridgeCache: () => resetScannerBridgeCache,
201
+ scanCacheGet: () => scanCacheGet,
202
+ scanCacheInvalidate: () => scanCacheInvalidate,
203
+ scanCachePut: () => scanCachePut,
204
+ scanCacheStats: () => scanCacheStats,
205
+ scanFileNative: () => scanFileNative,
206
+ scanFilesBatchNative: () => scanFilesBatchNative,
246
207
  scanWorkspaceNative: () => scanWorkspaceNative
247
208
  });
248
209
  function getDirname() {
@@ -250,7 +211,7 @@ function getDirname() {
250
211
  return __dirname;
251
212
  }
252
213
  if (typeof import.meta !== "undefined" && import.meta.url) {
253
- return path3.dirname(fileURLToPath(import.meta.url));
214
+ return path5.dirname(fileURLToPath(import.meta.url));
254
215
  }
255
216
  return process.cwd();
256
217
  }
@@ -331,6 +292,95 @@ function cachePriorityNative(mtimeMs, size, cachedMtimeMs, cachedSize, cachedHit
331
292
  }
332
293
  return result;
333
294
  }
295
+ function batchExtractClassesNative(filePaths) {
296
+ const binding = scannerGetBinding();
297
+ if (!binding.batchExtractClasses) {
298
+ throw new Error("FATAL: Native binding 'batchExtractClasses' is required but not available.");
299
+ }
300
+ return binding.batchExtractClasses(filePaths) ?? [];
301
+ }
302
+ function scanCacheGet(filePath, contentHash) {
303
+ const binding = scannerGetBinding();
304
+ if (!binding.scanCacheGet) {
305
+ throw new Error("FATAL: Native binding 'scanCacheGet' is required but not available.");
306
+ }
307
+ return binding.scanCacheGet(filePath, contentHash) ?? null;
308
+ }
309
+ function scanCachePut(filePath, contentHash, classes, mtimeMs, size) {
310
+ const binding = scannerGetBinding();
311
+ if (!binding.scanCachePut) {
312
+ throw new Error("FATAL: Native binding 'scanCachePut' is required but not available.");
313
+ }
314
+ binding.scanCachePut(filePath, contentHash, classes, mtimeMs, size);
315
+ }
316
+ function scanCacheInvalidate(filePath) {
317
+ const binding = scannerGetBinding();
318
+ if (!binding.scanCacheInvalidate) {
319
+ throw new Error("FATAL: Native binding 'scanCacheInvalidate' is required but not available.");
320
+ }
321
+ binding.scanCacheInvalidate(filePath);
322
+ }
323
+ function scanCacheStats() {
324
+ const binding = scannerGetBinding();
325
+ if (!binding.scanCacheStats) {
326
+ throw new Error("FATAL: Native binding 'scanCacheStats' is required but not available.");
327
+ }
328
+ return binding.scanCacheStats();
329
+ }
330
+ function scanFileNative(filePath) {
331
+ const binding = scannerGetBinding();
332
+ if (!binding.scanFile) {
333
+ throw new Error("FATAL: Native binding 'scanFile' is required but not available.");
334
+ }
335
+ return binding.scanFile(filePath);
336
+ }
337
+ function collectFilesNative(root, extensions, ignoreDirs) {
338
+ const binding = scannerGetBinding();
339
+ if (!binding.collectFiles) return null;
340
+ return binding.collectFiles(root, extensions, ignoreDirs);
341
+ }
342
+ function scanFilesBatchNative(filePaths) {
343
+ const binding = scannerGetBinding();
344
+ if (!binding.scanFilesBatch) {
345
+ return filePaths.map((fp) => {
346
+ try {
347
+ const r = binding.scanFile?.(fp);
348
+ return r ? { file: r.file, classes: r.classes, hash: r.hash ?? "" } : { file: fp, classes: [], hash: "" };
349
+ } catch {
350
+ return { file: fp, classes: [], hash: "" };
351
+ }
352
+ });
353
+ }
354
+ return binding.scanFilesBatch(filePaths);
355
+ }
356
+ function generateSubComponentTypesNative(root, outputPath) {
357
+ const binding = scannerGetBinding();
358
+ if (!binding.generateSubComponentTypes) return null;
359
+ return binding.generateSubComponentTypes(root, outputPath ?? null);
360
+ }
361
+ function pruneStaleEntriesNative(entries, maxAgeMs, checkExists) {
362
+ const binding = scannerGetBinding();
363
+ if (!binding.pruneStaleEntries) return null;
364
+ return binding.pruneStaleEntries(
365
+ entries.map((e) => ({ file: e.file, lastSeenMs: e.lastSeenMs ?? 0 })),
366
+ maxAgeMs ?? null,
367
+ checkExists ?? null
368
+ );
369
+ }
370
+ function rebuildWorkspaceResultNative(files) {
371
+ const binding = scannerBridgeLoader.get();
372
+ if (!binding?.rebuildWorkspaceResult) return null;
373
+ try {
374
+ return binding.rebuildWorkspaceResult(files);
375
+ } catch {
376
+ return null;
377
+ }
378
+ }
379
+ function computeCacheStatsNative(filesClasses, sizes, top) {
380
+ const binding = scannerGetBinding();
381
+ if (!binding.computeCacheStats) return null;
382
+ return binding.computeCacheStats(filesClasses, sizes, top ?? null);
383
+ }
334
384
  var log, isValidScannerBinding, createScannerBridgeLoader, scannerBridgeLoader, scannerGetBinding, resetScannerBridgeCache;
335
385
  var init_native_bridge = __esm({
336
386
  "packages/domain/scanner/src/native-bridge.ts"() {
@@ -421,8 +471,8 @@ init_src();
421
471
  // packages/domain/scanner/src/cache-native.ts
422
472
  init_native_bridge();
423
473
  function defaultCachePath(rootDir, cacheDir) {
424
- const dir = cacheDir ? path3.resolve(rootDir, cacheDir) : path3.join(process.cwd(), ".cache", "tailwind-styled");
425
- return path3.join(dir, "scanner-cache.json");
474
+ const dir = cacheDir ? path5.resolve(rootDir, cacheDir) : path5.join(process.cwd(), ".cache", "tailwind-styled");
475
+ return path5.join(dir, "scanner-cache.json");
426
476
  }
427
477
  function readCache(rootDir, cacheDir) {
428
478
  const cachePath = defaultCachePath(rootDir, cacheDir);
@@ -461,15 +511,110 @@ function filePriority(mtimeMs, size, cached, nowMs = Date.now()) {
461
511
 
462
512
  // packages/domain/scanner/src/index.ts
463
513
  init_native_bridge();
514
+ init_native_bridge();
515
+ var PARALLEL_THRESHOLD = 50;
516
+ var DEFAULT_CHUNK_SIZE = 150;
517
+ function collectFiles(rootDir, extensions, ignoreDirs) {
518
+ const native = collectFilesNative(rootDir, extensions, ignoreDirs);
519
+ if (native !== null) return native;
520
+ const files = [];
521
+ function walk(dir) {
522
+ let entries;
523
+ try {
524
+ entries = fs3.readdirSync(dir, { withFileTypes: true });
525
+ } catch {
526
+ return;
527
+ }
528
+ for (const entry of entries) {
529
+ const fullPath = path5.join(dir, entry.name);
530
+ const rel = path5.relative(rootDir, fullPath);
531
+ if (entry.isDirectory()) {
532
+ const ignored = ignoreDirs.some((d) => entry.name === d || rel.startsWith(d + path5.sep));
533
+ if (!ignored) walk(fullPath);
534
+ } else if (isScannableFile(entry.name, extensions)) {
535
+ files.push(fullPath);
536
+ }
537
+ }
538
+ }
539
+ walk(rootDir);
540
+ return files;
541
+ }
542
+ function mergeResults(batchResults) {
543
+ const files = batchResults.map((r) => ({
544
+ file: r.file,
545
+ classes: r.classes,
546
+ hash: r.content_hash
547
+ }));
548
+ const native = rebuildWorkspaceResultNative(files);
549
+ if (native) return native;
550
+ const unique = new Set(files.flatMap((f) => f.classes));
551
+ return { files, totalFiles: files.length, uniqueClasses: Array.from(unique).sort() };
552
+ }
553
+ if (!isMainThread && parentPort) {
554
+ const { filePaths } = workerData;
555
+ try {
556
+ const results = batchExtractClassesNative(filePaths);
557
+ const msg = { ok: true, results };
558
+ parentPort.postMessage(msg);
559
+ } catch (error) {
560
+ const msg = {
561
+ ok: false,
562
+ error: error instanceof Error ? error.message : String(error)
563
+ };
564
+ parentPort.postMessage(msg);
565
+ }
566
+ }
567
+ var _workerFilename = typeof __filename !== "undefined" ? __filename : fileURLToPath(import.meta.url);
568
+ function runChunkInWorker(filePaths) {
569
+ return new Promise((resolve, reject) => {
570
+ const worker = new Worker(_workerFilename, {
571
+ workerData: { filePaths }
572
+ });
573
+ worker.once("message", (payload) => {
574
+ if (payload.ok) {
575
+ resolve(payload.results);
576
+ } else {
577
+ reject(new Error(payload.error ?? "parallel-scanner worker failed"));
578
+ }
579
+ });
580
+ worker.once("error", reject);
581
+ worker.once("exit", (code) => {
582
+ if (code !== 0) reject(new Error(`parallel-scanner worker exited with code ${code}`));
583
+ });
584
+ });
585
+ }
586
+ async function scanWorkspaceParallel(rootDir, options = {}) {
587
+ const {
588
+ extensions = DEFAULT_EXTENSIONS,
589
+ ignoreDirs = DEFAULT_IGNORES,
590
+ maxWorkers = Math.max(1, availableParallelism() - 1),
591
+ chunkSize = DEFAULT_CHUNK_SIZE
592
+ } = options;
593
+ const files = collectFiles(path5.resolve(rootDir), extensions, ignoreDirs);
594
+ if (files.length < PARALLEL_THRESHOLD) {
595
+ return mergeResults(batchExtractClassesNative(files));
596
+ }
597
+ const chunks = [];
598
+ for (let i = 0; i < files.length; i += chunkSize) {
599
+ chunks.push(files.slice(i, i + chunkSize));
600
+ }
601
+ const allResults = [];
602
+ for (let i = 0; i < chunks.length; i += maxWorkers) {
603
+ const batch = chunks.slice(i, i + maxWorkers);
604
+ const batchResults = await Promise.all(batch.map(runChunkInWorker));
605
+ allResults.push(...batchResults.flat());
606
+ }
607
+ return mergeResults(allResults);
608
+ }
464
609
 
465
610
  // packages/domain/scanner/src/schemas.ts
466
611
  init_src();
467
- var formatIssuePath2 = (path4) => path4.length > 0 ? path4.map(
612
+ var formatIssuePath2 = (path6) => path6.length > 0 ? path6.map(
468
613
  (segment) => typeof segment === "symbol" ? segment.description ?? segment.toString() : String(segment)
469
614
  ).join(".") : "<root>";
470
615
  var formatIssues = (error) => error.issues.map((issue) => {
471
- const path4 = formatIssuePath2(issue.path);
472
- return `${path4}: ${issue.message}`;
616
+ const path6 = formatIssuePath2(issue.path);
617
+ return `${path6}: ${issue.message}`;
473
618
  }).join("; ");
474
619
  var parseWithSchema = (schema, data, label) => {
475
620
  const parsed = schema.safeParse(data);
@@ -524,6 +669,7 @@ var parseScanWorkspaceResult = (result) => parseWithSchema(ScanWorkspaceResultSc
524
669
  var parseScannerWorkerMessage = (message) => parseWithSchema(ScannerWorkerMessageSchema, message, "scanner worker message is invalid");
525
670
 
526
671
  // packages/domain/scanner/src/index.ts
672
+ init_native_bridge();
527
673
  var log2 = createLogger("scanner");
528
674
  var SCAN_WORKER_TIMEOUT_MS = 12e4;
529
675
  function getRuntimeDir() {
@@ -531,7 +677,7 @@ function getRuntimeDir() {
531
677
  return __dirname;
532
678
  }
533
679
  if (typeof import.meta !== "undefined" && import.meta.url) {
534
- return path3.dirname(fileURLToPath(import.meta.url));
680
+ return path5.dirname(fileURLToPath(import.meta.url));
535
681
  }
536
682
  return process.cwd();
537
683
  }
@@ -546,12 +692,25 @@ var createNativeParserLoader = () => {
546
692
  const loadNativeParserBinding = () => {
547
693
  if (_state.binding !== void 0) return _state.binding;
548
694
  const runtimeDir = getRuntimeDir();
549
- const req = createRequire(path3.join(runtimeDir, "noop.cjs"));
695
+ const req = createRequire(path5.join(runtimeDir, "noop.cjs"));
550
696
  const candidates = [
551
- path3.resolve(process.cwd(), "native/tailwind_styled_parser.node"),
552
- path3.resolve(process.cwd(), "native/build/Release/tailwind_styled_parser.node"),
553
- path3.resolve(runtimeDir, "..", "..", "..", "native", "tailwind_styled_parser.node"),
554
- path3.resolve(
697
+ // ── binaryName baru: tailwind-styled-native (napi-rs naming) ──
698
+ // cwd = repo root saat run dari root, atau package dir saat workspaces
699
+ path5.resolve(process.cwd(), "native", "tailwind-styled-native.node"),
700
+ path5.resolve(process.cwd(), "native", `tailwind-styled-native.${process.platform}-${process.arch}.node`),
701
+ path5.resolve(process.cwd(), "native", `tailwind-styled-native.${process.platform}-${process.arch}-gnu.node`),
702
+ // runtimeDir = dist/ → naik 4 level ke repo root
703
+ path5.resolve(runtimeDir, "..", "..", "..", "..", "native", "tailwind-styled-native.node"),
704
+ path5.resolve(runtimeDir, "..", "..", "..", "..", "native", `tailwind-styled-native.${process.platform}-${process.arch}-gnu.node`),
705
+ // 3 level fallback (jika package di-nest lebih dangkal)
706
+ path5.resolve(runtimeDir, "..", "..", "..", "native", "tailwind-styled-native.node"),
707
+ path5.resolve(runtimeDir, "..", "..", "..", "native", `tailwind-styled-native.${process.platform}-${process.arch}-gnu.node`),
708
+ // ── binaryName lama: tailwind_styled_parser (backward compat) ──
709
+ path5.resolve(process.cwd(), "native/tailwind_styled_parser.node"),
710
+ path5.resolve(process.cwd(), "native/build/Release/tailwind_styled_parser.node"),
711
+ path5.resolve(runtimeDir, "..", "..", "..", "..", "native", "tailwind_styled_parser.node"),
712
+ path5.resolve(runtimeDir, "..", "..", "..", "native", "tailwind_styled_parser.node"),
713
+ path5.resolve(
555
714
  runtimeDir,
556
715
  "..",
557
716
  "..",
@@ -563,7 +722,7 @@ var createNativeParserLoader = () => {
563
722
  )
564
723
  ];
565
724
  for (const fullPath of candidates) {
566
- if (!fs.existsSync(fullPath)) continue;
725
+ if (!fs3.existsSync(fullPath)) continue;
567
726
  try {
568
727
  const required = req(fullPath);
569
728
  if (required && (typeof required.extractClassesFromSource === "function" || typeof required.parseClasses === "function" || typeof required.parse_classes === "function")) {
@@ -599,17 +758,17 @@ function resolveScannerWorkerModulePath() {
599
758
  return __dirname;
600
759
  }
601
760
  if (typeof import.meta !== "undefined" && import.meta.url) {
602
- return path3.dirname(fileURLToPath(import.meta.url));
761
+ return path5.dirname(fileURLToPath(import.meta.url));
603
762
  }
604
763
  return process.cwd();
605
764
  })();
606
765
  const candidates = [
607
- path3.resolve(runtimeDir, "worker.cjs"),
608
- path3.resolve(runtimeDir, "worker.js"),
609
- path3.resolve(runtimeDir, "worker.ts")
766
+ path5.resolve(runtimeDir, "worker.cjs"),
767
+ path5.resolve(runtimeDir, "worker.js"),
768
+ path5.resolve(runtimeDir, "worker.ts")
610
769
  ];
611
770
  for (const candidate of candidates) {
612
- if (fs.existsSync(candidate)) return candidate;
771
+ if (fs3.existsSync(candidate)) return candidate;
613
772
  }
614
773
  return null;
615
774
  }
@@ -666,19 +825,19 @@ function collectCandidates(rootDir, ignoreDirectories, extensionSet) {
666
825
  if (!currentDir) continue;
667
826
  const entries = (() => {
668
827
  try {
669
- return fs.readdirSync(currentDir, { withFileTypes: true });
828
+ return fs3.readdirSync(currentDir, { withFileTypes: true });
670
829
  } catch {
671
830
  return [];
672
831
  }
673
832
  })();
674
833
  for (const entry of entries) {
675
- const fullPath = path3.join(currentDir, entry.name);
834
+ const fullPath = path5.join(currentDir, entry.name);
676
835
  if (entry.isDirectory()) {
677
836
  if (!ignoreDirectories.has(entry.name)) directories.push(fullPath);
678
837
  continue;
679
838
  }
680
839
  if (!entry.isFile()) continue;
681
- if (!extensionSet.has(path3.extname(entry.name))) continue;
840
+ if (!extensionSet.has(path5.extname(entry.name))) continue;
682
841
  candidates.push(fullPath);
683
842
  }
684
843
  }
@@ -692,9 +851,12 @@ function toCacheSize(size) {
692
851
  function scanSource(source) {
693
852
  const nativeBinding = nativeParserLoader.get();
694
853
  if (nativeBinding?.extractClassesFromSource) {
695
- const classes = nativeBinding.extractClassesFromSource(source);
696
- if (Array.isArray(classes)) {
697
- return Array.from(new Set(classes.filter(Boolean)));
854
+ const result = nativeBinding.extractClassesFromSource(source);
855
+ if (Array.isArray(result)) {
856
+ return Array.from(new Set(result.filter(Boolean)));
857
+ }
858
+ if (result !== null && result !== void 0 && Array.isArray(result.classes)) {
859
+ return Array.from(new Set(result.classes.filter(Boolean)));
698
860
  }
699
861
  }
700
862
  throw new Error(
@@ -702,15 +864,18 @@ function scanSource(source) {
702
864
  );
703
865
  }
704
866
  function isScannableFile(filePath, includeExtensions = DEFAULT_EXTENSIONS) {
705
- return includeExtensions.includes(path3.extname(filePath));
867
+ return includeExtensions.includes(path5.extname(filePath));
706
868
  }
707
869
  function scanFile(filePath) {
708
- const source = fs.readFileSync(filePath, "utf8");
709
- const hash = hashContentNative(source) ?? void 0;
870
+ const { scanFileNative: scanFileNative2 } = (init_native_bridge(), __toCommonJS(native_bridge_exports));
871
+ const result = scanFileNative2(filePath);
872
+ if (!result.ok) {
873
+ throw new Error(`scanFile failed for ${filePath}: ${result.error ?? "unknown error"}`);
874
+ }
710
875
  return {
711
- file: filePath,
712
- classes: scanSource(source),
713
- ...hash ? { hash } : {}
876
+ file: result.file,
877
+ classes: result.classes,
878
+ ...result.hash ? { hash: result.hash } : {}
714
879
  };
715
880
  }
716
881
  function scanWorkspace(rootDir, options = {}) {
@@ -759,7 +924,7 @@ function scanWorkspace(rootDir, options = {}) {
759
924
  for (const filePath of candidates) {
760
925
  const stat = (() => {
761
926
  try {
762
- return fs.statSync(filePath);
927
+ return fs3.statSync(filePath);
763
928
  } catch {
764
929
  return null;
765
930
  }
@@ -785,7 +950,7 @@ function scanWorkspace(rootDir, options = {}) {
785
950
  for (const { filePath, stat, size, cached } of ranked) {
786
951
  const content = (() => {
787
952
  try {
788
- return fs.readFileSync(filePath, "utf8");
953
+ return fs3.readFileSync(filePath, "utf8");
789
954
  } catch {
790
955
  return null;
791
956
  }
@@ -847,19 +1012,26 @@ function scanWorkspace(rootDir, options = {}) {
847
1012
  }
848
1013
  async function scanWorkspaceAsync(rootDir, options = {}) {
849
1014
  const normalizedOptions = parseScanWorkspaceOptions(options);
850
- if (process.env.TWS_DISABLE_SCANNER_WORKER === "1") {
851
- return scanWorkspace(rootDir, normalizedOptions);
1015
+ try {
1016
+ return await scanWorkspaceParallel(rootDir, {
1017
+ extensions: normalizedOptions.includeExtensions,
1018
+ ignoreDirs: normalizedOptions.ignoreDirectories
1019
+ });
1020
+ } catch (parallelError) {
1021
+ log2.debug(
1022
+ `parallel scan failed, retrying with single worker: ${parallelError instanceof Error ? parallelError.message : String(parallelError)}`
1023
+ );
852
1024
  }
853
1025
  try {
854
1026
  return await scanWorkspaceInWorker(rootDir, normalizedOptions);
855
1027
  } catch (error) {
856
1028
  log2.debug(
857
- `worker scan failed, falling back to sync scanner: ${error instanceof Error ? error.message : String(error)}`
1029
+ `worker scan failed, retrying with sync native scanner: ${error instanceof Error ? error.message : String(error)}`
858
1030
  );
859
1031
  return scanWorkspace(rootDir, normalizedOptions);
860
1032
  }
861
1033
  }
862
1034
 
863
- export { DEFAULT_EXTENSIONS, DEFAULT_IGNORES, isScannableFile, parseScanWorkspaceOptions, parseScanWorkspaceResult, parseScannerWorkerMessage, scanFile, scanSource, scanWorkspace, scanWorkspaceAsync };
1035
+ export { DEFAULT_EXTENSIONS, DEFAULT_IGNORES, batchExtractClassesNative, extractClassesNative, isScannableFile, parseScanWorkspaceOptions, parseScanWorkspaceResult, parseScannerWorkerMessage, scanFile, scanSource, scanWorkspace, scanWorkspaceAsync };
864
1036
  //# sourceMappingURL=scanner.mjs.map
865
1037
  //# sourceMappingURL=scanner.mjs.map