tailwind-styled-v4 1.0.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/animate.cjs +771 -0
  2. package/dist/animate.cjs.map +1 -0
  3. package/dist/animate.d.cts +73 -0
  4. package/dist/animate.d.ts +73 -0
  5. package/dist/animate.js +752 -0
  6. package/dist/animate.js.map +1 -0
  7. package/dist/chunk-VZEJV27B.js +11 -0
  8. package/dist/chunk-VZEJV27B.js.map +1 -0
  9. package/dist/chunk-Y5D3E72P.cjs +13 -0
  10. package/dist/chunk-Y5D3E72P.cjs.map +1 -0
  11. package/dist/css.cjs +121 -0
  12. package/dist/css.cjs.map +1 -0
  13. package/dist/css.d.cts +30 -0
  14. package/dist/css.d.ts +30 -0
  15. package/dist/css.js +112 -0
  16. package/dist/css.js.map +1 -0
  17. package/dist/devtools.cjs +1071 -0
  18. package/dist/devtools.cjs.map +1 -0
  19. package/dist/devtools.d.cts +22 -0
  20. package/dist/devtools.d.ts +22 -0
  21. package/dist/devtools.js +1064 -0
  22. package/dist/devtools.js.map +1 -0
  23. package/dist/index.cjs +1353 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +655 -0
  26. package/dist/index.d.ts +508 -968
  27. package/dist/index.js +1304 -3
  28. package/dist/index.js.map +1 -1
  29. package/dist/next.cjs +248 -0
  30. package/dist/next.cjs.map +1 -0
  31. package/dist/next.d.cts +54 -0
  32. package/dist/next.d.ts +54 -0
  33. package/dist/next.js +241 -0
  34. package/dist/next.js.map +1 -0
  35. package/dist/preset.cjs +423 -0
  36. package/dist/preset.cjs.map +1 -0
  37. package/dist/preset.d.cts +276 -0
  38. package/dist/preset.d.ts +276 -0
  39. package/dist/preset.js +416 -0
  40. package/dist/preset.js.map +1 -0
  41. package/dist/turbopackLoader.cjs +37 -0
  42. package/dist/turbopackLoader.cjs.map +1 -0
  43. package/dist/turbopackLoader.d.cts +12 -0
  44. package/dist/turbopackLoader.d.ts +12 -0
  45. package/dist/turbopackLoader.js +35 -0
  46. package/dist/turbopackLoader.js.map +1 -0
  47. package/dist/vite.cjs +138 -0
  48. package/dist/vite.cjs.map +1 -0
  49. package/dist/vite.d.cts +51 -0
  50. package/dist/vite.d.ts +51 -0
  51. package/dist/vite.js +128 -0
  52. package/dist/vite.js.map +1 -0
  53. package/dist/webpackLoader.cjs +51 -0
  54. package/dist/webpackLoader.cjs.map +1 -0
  55. package/dist/webpackLoader.d.cts +17 -0
  56. package/dist/webpackLoader.d.ts +17 -0
  57. package/dist/webpackLoader.js +49 -0
  58. package/dist/webpackLoader.js.map +1 -0
  59. package/package.json +65 -32
  60. package/CHANGELOG.md +0 -75
  61. package/LICENSE +0 -21
  62. package/README.md +0 -608
  63. package/dist/cli/init.js +0 -208
  64. package/dist/compiler/index.d.mts +0 -214
  65. package/dist/compiler/index.d.ts +0 -214
  66. package/dist/compiler/index.js +0 -546
  67. package/dist/compiler/index.js.map +0 -1
  68. package/dist/compiler/index.mjs +0 -504
  69. package/dist/compiler/index.mjs.map +0 -1
  70. package/dist/index.d.mts +0 -1115
  71. package/dist/index.mjs +0 -4
  72. package/dist/index.mjs.map +0 -1
  73. package/dist/turbopack-loader.js +0 -232
  74. package/dist/webpack-loader.js +0 -213
@@ -0,0 +1,771 @@
1
+ 'use strict';
2
+
3
+ require('./chunk-Y5D3E72P.cjs');
4
+ var fs = require('fs');
5
+ var module$1 = require('module');
6
+ var path = require('path');
7
+ var url = require('url');
8
+ require('crypto');
9
+ require('@tailwind-styled/scanner');
10
+
11
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
12
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
+
14
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
15
+ var path__default = /*#__PURE__*/_interopDefault(path);
16
+
17
+ /* tailwind-styled-v4 v4 | MIT | https://github.com/dictionar32/tailwind-styled-v4 */
18
+ var LRUCache = class {
19
+ constructor(max = 256, ttlMs = null) {
20
+ this.map = /* @__PURE__ */ new Map();
21
+ this.max = max;
22
+ this.ttlMs = ttlMs;
23
+ }
24
+ get(key) {
25
+ const entry = this.map.get(key);
26
+ if (!entry) return void 0;
27
+ if (this.ttlMs !== null && Date.now() - entry.ts > this.ttlMs) {
28
+ this.map.delete(key);
29
+ return void 0;
30
+ }
31
+ this.map.delete(key);
32
+ this.map.set(key, entry);
33
+ return entry.value;
34
+ }
35
+ set(key, value) {
36
+ if (this.map.has(key)) this.map.delete(key);
37
+ else if (this.map.size >= this.max) {
38
+ this.map.delete(this.map.keys().next().value);
39
+ }
40
+ this.map.set(key, { value, ts: Date.now() });
41
+ }
42
+ has(key) {
43
+ return this.get(key) !== void 0;
44
+ }
45
+ delete(key) {
46
+ this.map.delete(key);
47
+ }
48
+ clear() {
49
+ this.map.clear();
50
+ }
51
+ get size() {
52
+ return this.map.size;
53
+ }
54
+ keys() {
55
+ return this.map.keys();
56
+ }
57
+ *values() {
58
+ for (const entry of this.map.values()) {
59
+ yield entry.value;
60
+ }
61
+ }
62
+ *entries() {
63
+ for (const [key, entry] of this.map.entries()) {
64
+ yield [key, entry.value];
65
+ }
66
+ }
67
+ };
68
+ function formatErrorMessage(error) {
69
+ return error instanceof Error ? error.message : String(error);
70
+ }
71
+ function resolveRuntimeDir(dirnameValue, moduleImportUrl) {
72
+ if (typeof dirnameValue === "string" && dirnameValue.length > 0) return dirnameValue;
73
+ return path__default.default.dirname(url.fileURLToPath(moduleImportUrl));
74
+ }
75
+ function resolveNativeBindingCandidates(options) {
76
+ const out = [];
77
+ const envVarNames = options.envVarNames ?? [];
78
+ for (const envVarName of envVarNames) {
79
+ const raw = process.env[envVarName]?.trim();
80
+ if (!raw) continue;
81
+ const resolved = path__default.default.resolve(raw);
82
+ if (options.enforceNodeExtensionForEnvPath) {
83
+ if (path__default.default.extname(resolved).toLowerCase() !== ".node") {
84
+ throw new Error(
85
+ `Invalid native binding path from ${envVarName}="${raw}". Expected a .node file.`
86
+ );
87
+ }
88
+ }
89
+ out.push(resolved);
90
+ }
91
+ if (options.includeDefaultCandidates !== false) {
92
+ out.push(path__default.default.resolve(process.cwd(), "native", "tailwind_styled_parser.node"));
93
+ out.push(path__default.default.resolve(options.runtimeDir, "..", "..", "..", "native", "tailwind_styled_parser.node"));
94
+ }
95
+ return Array.from(new Set(out));
96
+ }
97
+ function parseDebugToken(namespace, token) {
98
+ if (token === "*" || token === namespace || token === "tailwind-styled:*") return true;
99
+ return token.endsWith("*") && namespace.startsWith(token.slice(0, -1));
100
+ }
101
+ function isDebugNamespaceEnabled(namespace) {
102
+ if (process.env.TWS_DEBUG === "1" || process.env.TAILWIND_STYLED_DEBUG === "1") return true;
103
+ const raw = process.env.DEBUG;
104
+ if (!raw) return false;
105
+ return raw.split(",").map((token) => token.trim()).some((token) => parseDebugToken(namespace, token));
106
+ }
107
+ function createDebugLogger(namespace, label = namespace) {
108
+ const debugEnabled = isDebugNamespaceEnabled(namespace);
109
+ return (message) => {
110
+ if (!debugEnabled) return;
111
+ console.debug(`[${label}] ${message}`);
112
+ };
113
+ }
114
+ function loadNativeBinding(options) {
115
+ const req = module$1.createRequire(path__default.default.join(options.runtimeDir, "noop.cjs"));
116
+ const loadErrors = [];
117
+ for (const candidate of options.candidates) {
118
+ if (!fs__default.default.existsSync(candidate)) continue;
119
+ try {
120
+ const mod = req(candidate);
121
+ if (options.isValid(mod)) {
122
+ return {
123
+ binding: mod,
124
+ loadedPath: candidate,
125
+ loadErrors
126
+ };
127
+ }
128
+ loadErrors.push({
129
+ path: candidate,
130
+ message: options.invalidExportMessage
131
+ });
132
+ } catch (error) {
133
+ loadErrors.push({
134
+ path: candidate,
135
+ message: formatErrorMessage(error)
136
+ });
137
+ }
138
+ }
139
+ return {
140
+ binding: null,
141
+ loadedPath: null,
142
+ loadErrors
143
+ };
144
+ }
145
+ var LEVELS = { silent: 0, error: 1, warn: 2, info: 3, debug: 4 };
146
+ function getEnvLevel() {
147
+ const env = process.env.TWS_LOG_LEVEL?.toLowerCase();
148
+ if (env && env in LEVELS) return env;
149
+ return process.env.TWS_DEBUG_SCANNER === "1" ? "debug" : "info";
150
+ }
151
+ function createLogger(prefix, level) {
152
+ let currentLevel = getEnvLevel();
153
+ const log = (msgLevel, stream, args) => {
154
+ if (LEVELS[msgLevel] > LEVELS[currentLevel]) return;
155
+ const line = `[${prefix}] ${args.map(String).join(" ")}
156
+ `;
157
+ process[stream].write(line);
158
+ };
159
+ return {
160
+ error: (...a) => log("error", "stderr", a),
161
+ warn: (...a) => log("warn", "stderr", a),
162
+ info: (...a) => log("info", "stdout", a),
163
+ debug: (...a) => log("debug", "stderr", a),
164
+ setLevel: (l) => {
165
+ currentLevel = l;
166
+ }
167
+ };
168
+ }
169
+ createLogger("tailwind-styled");
170
+
171
+ // ../animate/src/binding.ts
172
+ var bindingPromise = null;
173
+ var DEBUG_NAMESPACE = "tailwind-styled:animate";
174
+ var debugLog = createDebugLogger(DEBUG_NAMESPACE, "tailwind-styled/animate");
175
+ function isAnimateModule(module) {
176
+ const candidate = module;
177
+ return typeof candidate?.compileAnimation === "function" && typeof candidate?.compileKeyframes === "function";
178
+ }
179
+ function resolveBindingCandidates(runtimeDir) {
180
+ return resolveNativeBindingCandidates({
181
+ runtimeDir,
182
+ envVarNames: ["TWS_ANIMATE_NATIVE_PATH", "TWS_NATIVE_PATH"],
183
+ enforceNodeExtensionForEnvPath: true
184
+ });
185
+ }
186
+ function loadAnimateBinding() {
187
+ if (process.env.TWS_NO_NATIVE === "1" || process.env.TWS_NO_RUST === "1") {
188
+ throw new Error("Native animate backend is required in v5. TWS_NO_NATIVE/TWS_NO_RUST is not supported.");
189
+ }
190
+ const runtimeDir = resolveRuntimeDir(
191
+ typeof __dirname === "string" ? __dirname : void 0,
192
+ (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('animate.cjs', document.baseURI).href))
193
+ );
194
+ const candidates = resolveBindingCandidates(runtimeDir);
195
+ const { binding, loadErrors, loadedPath } = loadNativeBinding({
196
+ runtimeDir,
197
+ candidates,
198
+ isValid: isAnimateModule,
199
+ invalidExportMessage: "Module loaded but missing compileAnimation/compileKeyframes exports."
200
+ });
201
+ if (binding) {
202
+ debugLog(`native animate binding loaded from: ${loadedPath}`);
203
+ return binding;
204
+ }
205
+ if (loadErrors.length > 0) {
206
+ debugLog(
207
+ `native animate binding load failed for ${loadErrors.length} candidate(s): ${loadErrors.map((entry) => `${entry.path} (${entry.message})`).join("; ")}`
208
+ );
209
+ } else {
210
+ debugLog("native animate binding not found in any candidate path");
211
+ }
212
+ const lines = [
213
+ "Native animate backend not found. Ensure `tailwind_styled_parser.node` is built.",
214
+ "Checked paths:",
215
+ ...candidates.map((candidate) => `- ${candidate}`)
216
+ ];
217
+ if (loadErrors.length > 0) {
218
+ lines.push("Load errors:");
219
+ for (const error of loadErrors) lines.push(`- ${error.path}: ${error.message}`);
220
+ }
221
+ throw new Error(lines.join("\n"));
222
+ }
223
+ async function getAnimateBinding() {
224
+ if (!bindingPromise) {
225
+ bindingPromise = Promise.resolve().then(loadAnimateBinding);
226
+ }
227
+ return bindingPromise;
228
+ }
229
+ async function initAnimate() {
230
+ await getAnimateBinding();
231
+ }
232
+
233
+ // ../animate/src/preset.ts
234
+ var DEFAULT_PRESET_CACHE_LIMIT = 32;
235
+ function createAnimationPresets(registry) {
236
+ const cache = new LRUCache(DEFAULT_PRESET_CACHE_LIMIT);
237
+ const withCache = (cacheKey, factory) => async () => {
238
+ const cached = cache.get(cacheKey);
239
+ if (cached) {
240
+ const className = await cached;
241
+ if (registry.has(className)) return className;
242
+ cache.delete(cacheKey);
243
+ }
244
+ const pending = factory();
245
+ cache.set(cacheKey, pending);
246
+ try {
247
+ return await pending;
248
+ } catch (error) {
249
+ cache.delete(cacheKey);
250
+ throw error;
251
+ }
252
+ };
253
+ return {
254
+ fadeIn: withCache(
255
+ "fadeIn",
256
+ async () => (await registry.compileAnimation({ from: "opacity-0", to: "opacity-100", duration: 200 })).className
257
+ ),
258
+ fadeOut: withCache(
259
+ "fadeOut",
260
+ async () => (await registry.compileAnimation({ from: "opacity-100", to: "opacity-0", duration: 200 })).className
261
+ ),
262
+ slideUp: withCache(
263
+ "slideUp",
264
+ async () => (await registry.compileAnimation({
265
+ from: "opacity-0 translate-y-4",
266
+ to: "opacity-100 translate-y-0",
267
+ duration: 300
268
+ })).className
269
+ ),
270
+ slideDown: withCache(
271
+ "slideDown",
272
+ async () => (await registry.compileAnimation({
273
+ from: "opacity-0 -translate-y-4",
274
+ to: "opacity-100 translate-y-0",
275
+ duration: 300
276
+ })).className
277
+ ),
278
+ slideLeft: withCache(
279
+ "slideLeft",
280
+ async () => (await registry.compileAnimation({
281
+ from: "opacity-0 translate-x-4",
282
+ to: "opacity-100 translate-x-0",
283
+ duration: 300
284
+ })).className
285
+ ),
286
+ slideRight: withCache(
287
+ "slideRight",
288
+ async () => (await registry.compileAnimation({
289
+ from: "opacity-0 -translate-x-4",
290
+ to: "opacity-100 translate-x-0",
291
+ duration: 300
292
+ })).className
293
+ ),
294
+ scaleIn: withCache(
295
+ "scaleIn",
296
+ async () => (await registry.compileAnimation({
297
+ from: "opacity-0 scale-95",
298
+ to: "opacity-100 scale-100",
299
+ duration: 200,
300
+ easing: "cubic-bezier(0.16,1,0.3,1)"
301
+ })).className
302
+ ),
303
+ scaleOut: withCache(
304
+ "scaleOut",
305
+ async () => (await registry.compileAnimation({
306
+ from: "opacity-100 scale-100",
307
+ to: "opacity-0 scale-95",
308
+ duration: 150
309
+ })).className
310
+ ),
311
+ blurIn: withCache(
312
+ "blurIn",
313
+ async () => (await registry.compileAnimation({
314
+ from: "opacity-0 blur-sm",
315
+ to: "opacity-100 blur-none",
316
+ duration: 300
317
+ })).className
318
+ ),
319
+ bounceIn: withCache(
320
+ "bounceIn",
321
+ async () => (await registry.compileAnimation({
322
+ from: "opacity-0 scale-50",
323
+ to: "opacity-100 scale-100",
324
+ duration: 400,
325
+ easing: "cubic-bezier(0.34,1.56,0.64,1)"
326
+ })).className
327
+ ),
328
+ spinIn: withCache(
329
+ "spinIn",
330
+ async () => (await registry.compileAnimation({
331
+ from: "opacity-0 rotate-180 scale-50",
332
+ to: "opacity-100 rotate-0 scale-100",
333
+ duration: 400,
334
+ easing: "cubic-bezier(0.16,1,0.3,1)"
335
+ })).className
336
+ )
337
+ };
338
+ }
339
+ var DEBUG_NAMESPACE2 = "tailwind-styled:analyzer";
340
+ function formatErrorMessage2(error) {
341
+ return error instanceof Error ? error.message : String(error);
342
+ }
343
+ var debugLog2 = createDebugLogger(DEBUG_NAMESPACE2, "tailwind-styled/analyzer");
344
+ var bindingCache;
345
+ var bindingCandidateCache = [];
346
+ var bindingLoadErrorsCache = [];
347
+ var loadedBindingPathCache = null;
348
+ function isAnalyzerModule(module) {
349
+ const candidate = module;
350
+ return typeof candidate?.analyzeClasses === "function";
351
+ }
352
+ function getNativeBinding() {
353
+ if (bindingCache !== void 0) return bindingCache;
354
+ if (process.env.TWS_NO_NATIVE === "1" || process.env.TWS_NO_RUST === "1") {
355
+ bindingCandidateCache = [];
356
+ bindingLoadErrorsCache = [];
357
+ loadedBindingPathCache = null;
358
+ debugLog2("native binding disabled by TWS_NO_NATIVE/TWS_NO_RUST");
359
+ bindingCache = null;
360
+ return bindingCache;
361
+ }
362
+ const runtimeDir = resolveRuntimeDir(
363
+ typeof __dirname === "string" ? __dirname : void 0,
364
+ (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('animate.cjs', document.baseURI).href))
365
+ );
366
+ const candidates = resolveNativeBindingCandidates({
367
+ runtimeDir,
368
+ envVarNames: ["TWS_NATIVE_PATH"]
369
+ });
370
+ const { binding, loadErrors, loadedPath } = loadNativeBinding({
371
+ runtimeDir,
372
+ candidates,
373
+ isValid: isAnalyzerModule,
374
+ invalidExportMessage: "Module loaded but missing `analyzeClasses` export."
375
+ });
376
+ bindingCandidateCache = candidates;
377
+ bindingLoadErrorsCache = loadErrors;
378
+ loadedBindingPathCache = loadedPath;
379
+ if (binding) {
380
+ debugLog2(`native binding loaded from: ${loadedPath}`);
381
+ bindingCache = binding;
382
+ return bindingCache;
383
+ }
384
+ if (bindingLoadErrorsCache.length > 0) {
385
+ debugLog2(
386
+ `native binding load failed for ${bindingLoadErrorsCache.length} candidate(s): ${bindingLoadErrorsCache.map((entry) => `${entry.path} (${entry.message})`).join("; ")}`
387
+ );
388
+ } else {
389
+ debugLog2("native binding not found in any candidate path");
390
+ }
391
+ bindingCache = null;
392
+ return bindingCache;
393
+ }
394
+ function requireNativeBinding() {
395
+ const binding = getNativeBinding();
396
+ if (binding?.analyzeClasses) return binding;
397
+ const lines = [
398
+ "Native analyzer binding not found. Ensure `tailwind_styled_parser.node` is built."
399
+ ];
400
+ if (process.env.TWS_NO_NATIVE === "1" || process.env.TWS_NO_RUST === "1") {
401
+ lines.push("Native loading is disabled by TWS_NO_NATIVE/TWS_NO_RUST.");
402
+ } else {
403
+ lines.push("Checked paths:");
404
+ for (const candidate of bindingCandidateCache) lines.push(`- ${candidate}`);
405
+ if (bindingLoadErrorsCache.length > 0) {
406
+ lines.push("Load errors:");
407
+ for (const failure of bindingLoadErrorsCache) {
408
+ lines.push(`- ${failure.path}: ${failure.message}`);
409
+ }
410
+ }
411
+ }
412
+ throw new Error(lines.join("\n"));
413
+ }
414
+ function requireNativeCssCompiler() {
415
+ const binding = requireNativeBinding();
416
+ if (typeof binding.compileCss === "function") return binding;
417
+ const loadedPathText = loadedBindingPathCache ? ` (${loadedBindingPathCache})` : "";
418
+ throw new Error(`Native analyzer compileCss binding is missing in v5${loadedPathText}.`);
419
+ }
420
+ function normalizeClassInput(input) {
421
+ if (typeof input === "string") {
422
+ return input.split(/\s+/).map((item) => item.trim()).filter((item) => item.length > 0);
423
+ }
424
+ if (!Array.isArray(input)) {
425
+ throw new TypeError("classToCss input must be a string or an array of strings.");
426
+ }
427
+ const out = [];
428
+ for (const item of input) {
429
+ if (typeof item !== "string") {
430
+ throw new TypeError("classToCss input array must contain only strings.");
431
+ }
432
+ const value = item.trim();
433
+ if (value.length > 0) out.push(value);
434
+ }
435
+ return out;
436
+ }
437
+ function normalizeClassToCssOptions(options) {
438
+ if (!options || typeof options !== "object" || Array.isArray(options)) {
439
+ throw new TypeError("classToCss options must be an object.");
440
+ }
441
+ const strict = options.strict ?? false;
442
+ if (typeof strict !== "boolean") {
443
+ throw new TypeError("classToCss options.strict must be a boolean when provided.");
444
+ }
445
+ const prefix = options.prefix ?? null;
446
+ if (prefix !== null && typeof prefix !== "string") {
447
+ throw new TypeError("classToCss options.prefix must be a string or null when provided.");
448
+ }
449
+ return { prefix, strict };
450
+ }
451
+ function mergeDeclarationMap(target, css) {
452
+ const ruleRegex = /\{([^}]*)\}/g;
453
+ let ruleMatch = ruleRegex.exec(css);
454
+ while (ruleMatch) {
455
+ const body = ruleMatch[1];
456
+ for (const raw of body.split(";")) {
457
+ const declaration = raw.trim();
458
+ if (declaration.length === 0) continue;
459
+ const colonIndex = declaration.indexOf(":");
460
+ if (colonIndex <= 0) continue;
461
+ const property = declaration.slice(0, colonIndex).trim();
462
+ const value = declaration.slice(colonIndex + 1).trim();
463
+ if (property.length === 0 || value.length === 0) continue;
464
+ if (target.has(property)) target.delete(property);
465
+ target.set(property, value);
466
+ }
467
+ ruleMatch = ruleRegex.exec(css);
468
+ }
469
+ }
470
+ function declarationMapToString(declarationMap) {
471
+ return Array.from(declarationMap.entries()).map(([property, value]) => `${property}: ${value}`).join("; ");
472
+ }
473
+ async function classToCss(input, options = {}) {
474
+ const inputClasses = normalizeClassInput(input);
475
+ const normalizedOptions = normalizeClassToCssOptions(options);
476
+ if (inputClasses.length === 0) {
477
+ return {
478
+ inputClasses: [],
479
+ css: "",
480
+ declarations: "",
481
+ resolvedClasses: [],
482
+ unknownClasses: [],
483
+ sizeBytes: 0
484
+ };
485
+ }
486
+ const binding = requireNativeCssCompiler();
487
+ const prefix = normalizedOptions.prefix;
488
+ const cssChunks = [];
489
+ const resolvedClasses = [];
490
+ const unknownClasses = [];
491
+ let sizeBytes = 0;
492
+ const declarationMap = /* @__PURE__ */ new Map();
493
+ for (const className of inputClasses) {
494
+ let compiled = null;
495
+ try {
496
+ compiled = binding.compileCss([className], prefix);
497
+ } catch (error) {
498
+ throw new Error(
499
+ `Native analyzer failed while compiling class "${className}": ${formatErrorMessage2(error)}`,
500
+ { cause: error }
501
+ );
502
+ }
503
+ if (!compiled) {
504
+ throw new Error(`Native analyzer returned no result for class "${className}".`);
505
+ }
506
+ cssChunks.push(compiled.css);
507
+ resolvedClasses.push(...compiled.resolvedClasses);
508
+ unknownClasses.push(...compiled.unknownClasses);
509
+ sizeBytes += compiled.sizeBytes;
510
+ mergeDeclarationMap(declarationMap, compiled.css);
511
+ }
512
+ const uniqueUnknown = Array.from(new Set(unknownClasses));
513
+ if (normalizedOptions.strict && uniqueUnknown.length > 0) {
514
+ throw new Error(`Unknown Tailwind classes: ${uniqueUnknown.join(", ")}`);
515
+ }
516
+ return {
517
+ inputClasses,
518
+ css: cssChunks.filter((chunk) => chunk.length > 0).join("\n"),
519
+ declarations: declarationMapToString(declarationMap),
520
+ resolvedClasses: Array.from(new Set(resolvedClasses)),
521
+ unknownClasses: uniqueUnknown,
522
+ sizeBytes
523
+ };
524
+ }
525
+
526
+ // ../animate/src/registry.ts
527
+ var DEFAULT_DURATION = 300;
528
+ var DEFAULT_EASING = "ease-out";
529
+ var DEFAULT_DELAY = 0;
530
+ var DEFAULT_FILL = "both";
531
+ var DEFAULT_ITERATIONS = 1;
532
+ var DEFAULT_DIRECTION = "normal";
533
+ var DEFAULT_CACHE_LIMIT = 512;
534
+ function normalizeNumber(value, fallback) {
535
+ if (!Number.isFinite(value)) return fallback;
536
+ return Math.max(0, Math.trunc(value));
537
+ }
538
+ function normalizeCacheLimit(value) {
539
+ if (!Number.isFinite(value)) return DEFAULT_CACHE_LIMIT;
540
+ return Math.max(1, Math.trunc(value));
541
+ }
542
+ function normalizeIterations(value) {
543
+ if (value === "infinite") return "infinite";
544
+ if (!Number.isFinite(value)) return String(DEFAULT_ITERATIONS);
545
+ return String(Math.max(0, Math.trunc(value)));
546
+ }
547
+ function stableKeyframesEntries(stops) {
548
+ return Object.entries(stops).map(([offset, classes]) => ({ offset, classes })).sort((left, right) => left.offset.localeCompare(right.offset));
549
+ }
550
+ function animationCacheKey(opts) {
551
+ const normalized = {
552
+ from: opts.from.trim(),
553
+ to: opts.to.trim(),
554
+ duration: normalizeNumber(opts.duration, DEFAULT_DURATION),
555
+ easing: (opts.easing ?? DEFAULT_EASING).trim(),
556
+ delay: normalizeNumber(opts.delay, DEFAULT_DELAY),
557
+ fill: opts.fill ?? DEFAULT_FILL,
558
+ iterations: normalizeIterations(opts.iterations),
559
+ direction: opts.direction ?? DEFAULT_DIRECTION,
560
+ name: opts.name ?? ""
561
+ };
562
+ return JSON.stringify(normalized);
563
+ }
564
+ function keyframesCacheKey(name, stops) {
565
+ return `${name}::${JSON.stringify(stableKeyframesEntries(stops))}`;
566
+ }
567
+ function splitClasses(classList) {
568
+ return classList.split(/\s+/).map((item) => item.trim()).filter((item) => item.length > 0);
569
+ }
570
+ async function validateTailwindClasses(entries) {
571
+ const binding = await getAnimateBinding();
572
+ const unknownByContext = /* @__PURE__ */ new Map();
573
+ const failures = [];
574
+ for (const entry of entries) {
575
+ const classes = splitClasses(entry.classList);
576
+ if (classes.length === 0) continue;
577
+ try {
578
+ if (typeof binding.compileCss === "function") {
579
+ const compiled = binding.compileCss(classes, null);
580
+ if (!compiled) {
581
+ failures.push(`Animation ${entry.context} failed validation: native compileCss returned no result.`);
582
+ continue;
583
+ }
584
+ if (compiled.unknownClasses.length > 0) {
585
+ const bucket = unknownByContext.get(entry.context) ?? /* @__PURE__ */ new Set();
586
+ for (const className of compiled.unknownClasses) bucket.add(className);
587
+ unknownByContext.set(entry.context, bucket);
588
+ }
589
+ continue;
590
+ }
591
+ const checked = await classToCss(classes, { strict: false });
592
+ if (checked.unknownClasses.length > 0) {
593
+ const bucket = unknownByContext.get(entry.context) ?? /* @__PURE__ */ new Set();
594
+ for (const className of checked.unknownClasses) bucket.add(className);
595
+ unknownByContext.set(entry.context, bucket);
596
+ }
597
+ } catch (error) {
598
+ failures.push(`Animation ${entry.context} failed validation: ${formatErrorMessage(error)}`);
599
+ }
600
+ }
601
+ const issues = [];
602
+ for (const [context, classes] of unknownByContext.entries()) {
603
+ issues.push(`Animation ${context} contains unknown Tailwind classes: ${Array.from(classes).join(", ")}`);
604
+ }
605
+ issues.push(...failures);
606
+ if (issues.length > 0) {
607
+ throw new Error(issues.join("\n"));
608
+ }
609
+ }
610
+ var AnimationRegistry = class {
611
+ constructor(options = {}) {
612
+ const cacheLimit = normalizeCacheLimit(options.cacheLimit);
613
+ this.animations = new LRUCache(cacheLimit);
614
+ this.animationBySignature = new LRUCache(cacheLimit);
615
+ this.keyframesBySignature = new LRUCache(cacheLimit);
616
+ }
617
+ async compileAnimation(opts) {
618
+ const signature = animationCacheKey(opts);
619
+ const existingClassName = this.animationBySignature.get(signature);
620
+ if (existingClassName) {
621
+ const cached = this.animations.get(existingClassName);
622
+ if (cached) return cached;
623
+ this.animationBySignature.delete(signature);
624
+ }
625
+ await validateTailwindClasses([
626
+ { classList: opts.from, context: `"from" in ${opts.name ?? "anonymous animation"}` },
627
+ { classList: opts.to, context: `"to" in ${opts.name ?? "anonymous animation"}` }
628
+ ]);
629
+ const binding = await getAnimateBinding();
630
+ const duration = normalizeNumber(opts.duration, DEFAULT_DURATION);
631
+ const easing = opts.easing ?? DEFAULT_EASING;
632
+ const delay = normalizeNumber(opts.delay, DEFAULT_DELAY);
633
+ const fill = opts.fill ?? DEFAULT_FILL;
634
+ const iterations = normalizeIterations(opts.iterations);
635
+ const direction = opts.direction ?? DEFAULT_DIRECTION;
636
+ const compiled = binding.compileAnimation?.(
637
+ opts.from,
638
+ opts.to,
639
+ opts.name ?? null,
640
+ duration,
641
+ easing,
642
+ delay,
643
+ fill,
644
+ iterations,
645
+ direction
646
+ );
647
+ if (!compiled) {
648
+ throw new Error(
649
+ `Native animate backend failed to compile animation "${opts.name ?? "anonymous animation"}".`
650
+ );
651
+ }
652
+ const result = {
653
+ className: compiled.className,
654
+ keyframesCss: compiled.keyframesCss,
655
+ animationCss: compiled.animationCss
656
+ };
657
+ this.animations.set(result.className, result);
658
+ this.animationBySignature.set(signature, result.className);
659
+ return result;
660
+ }
661
+ async compileKeyframes(name, stops) {
662
+ const signature = keyframesCacheKey(name, stops);
663
+ const existingClassName = this.keyframesBySignature.get(signature);
664
+ if (existingClassName) {
665
+ const cached = this.animations.get(existingClassName);
666
+ if (cached) return cached;
667
+ this.keyframesBySignature.delete(signature);
668
+ }
669
+ await validateTailwindClasses(
670
+ Object.entries(stops).map(([offset, classes]) => ({
671
+ classList: classes,
672
+ context: `"${offset}" stop in keyframes "${name}"`
673
+ }))
674
+ );
675
+ const binding = await getAnimateBinding();
676
+ const stopsJson = JSON.stringify(stableKeyframesEntries(stops));
677
+ const compiled = binding.compileKeyframes?.(name, stopsJson);
678
+ if (!compiled) {
679
+ throw new Error(`Native animate backend failed to compile keyframes "${name}".`);
680
+ }
681
+ const result = {
682
+ className: compiled.className,
683
+ keyframesCss: compiled.keyframesCss,
684
+ animationCss: compiled.animationCss
685
+ };
686
+ this.animations.set(result.className, result);
687
+ this.keyframesBySignature.set(signature, result.className);
688
+ return result;
689
+ }
690
+ extractCss() {
691
+ const lines = [];
692
+ for (const [, compiled] of this.animations.entries()) {
693
+ lines.push(compiled.keyframesCss);
694
+ lines.push(`.${compiled.className} { ${compiled.animationCss} }`);
695
+ }
696
+ return lines.join("\n\n");
697
+ }
698
+ reset() {
699
+ this.animations.clear();
700
+ this.animationBySignature.clear();
701
+ this.keyframesBySignature.clear();
702
+ }
703
+ has(className) {
704
+ return this.animations.has(className);
705
+ }
706
+ };
707
+ function createAnimationRegistry(options = {}) {
708
+ return new AnimationRegistry(options);
709
+ }
710
+
711
+ // ../animate/src/index.ts
712
+ var defaultRegistry = createAnimationRegistry();
713
+ async function initAnimate2() {
714
+ await initAnimate();
715
+ }
716
+ function getDefaultAnimationRegistry() {
717
+ return defaultRegistry;
718
+ }
719
+ async function compileAnimation(opts, registry = defaultRegistry) {
720
+ return registry.compileAnimation(opts);
721
+ }
722
+ async function compileKeyframes(name, stops, registry = defaultRegistry) {
723
+ return registry.compileKeyframes(name, stops);
724
+ }
725
+ async function animate(opts, registry = defaultRegistry) {
726
+ return (await registry.compileAnimation(opts)).className;
727
+ }
728
+ async function keyframes(name, stops, registry = defaultRegistry) {
729
+ return (await registry.compileKeyframes(name, stops)).className;
730
+ }
731
+ function extractAnimationCss(registry = defaultRegistry) {
732
+ return registry.extractCss();
733
+ }
734
+ function resetAnimationRegistry(registry = defaultRegistry) {
735
+ registry.reset();
736
+ }
737
+ function injectAnimationCss(registry = defaultRegistry, options = {}) {
738
+ const targetDocument = options.document ?? (typeof document !== "undefined" ? document : void 0);
739
+ if (!targetDocument) {
740
+ if (options.silent) return;
741
+ throw new Error("injectAnimationCss requires a browser Document.");
742
+ }
743
+ const styleId = options.styleId ?? "__tw_animate_styles__";
744
+ let styleEl = targetDocument.getElementById(styleId);
745
+ if (!styleEl) {
746
+ if (!targetDocument.head) {
747
+ if (options.silent) return;
748
+ throw new Error("injectAnimationCss requires document.head to exist.");
749
+ }
750
+ styleEl = targetDocument.createElement("style");
751
+ styleEl.id = styleId;
752
+ targetDocument.head.appendChild(styleEl);
753
+ }
754
+ styleEl.textContent = registry.extractCss();
755
+ }
756
+ var animations = createAnimationPresets(defaultRegistry);
757
+
758
+ exports.AnimationRegistry = AnimationRegistry;
759
+ exports.animate = animate;
760
+ exports.animations = animations;
761
+ exports.compileAnimation = compileAnimation;
762
+ exports.compileKeyframes = compileKeyframes;
763
+ exports.createAnimationRegistry = createAnimationRegistry;
764
+ exports.extractAnimationCss = extractAnimationCss;
765
+ exports.getDefaultAnimationRegistry = getDefaultAnimationRegistry;
766
+ exports.initAnimate = initAnimate2;
767
+ exports.injectAnimationCss = injectAnimationCss;
768
+ exports.keyframes = keyframes;
769
+ exports.resetAnimationRegistry = resetAnimationRegistry;
770
+ //# sourceMappingURL=animate.cjs.map
771
+ //# sourceMappingURL=animate.cjs.map