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