tailwind-to-style 3.2.2 → 4.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.
- package/README.md +221 -666
- package/dist/animations/index.cjs +9391 -0
- package/dist/animations/index.d.ts +58 -0
- package/dist/animations/index.esm.js +9385 -0
- package/dist/animations/index.esm.js.map +1 -0
- package/dist/className/index.cjs +9080 -0
- package/dist/className/index.esm.js +9075 -0
- package/dist/className/index.esm.js.map +1 -0
- package/dist/core/tws.cjs +136 -114
- package/dist/core/tws.cjs.map +1 -0
- package/dist/core/tws.esm.js +136 -114
- package/dist/core/tws.esm.js.map +1 -1
- package/dist/core/twsx.cjs +2442 -4245
- package/dist/core/twsx.esm.js +2442 -4245
- package/dist/core/twsx.esm.js.map +1 -1
- package/dist/core/twsxVariants.cjs +2470 -4262
- package/dist/core/twsxVariants.esm.js +2470 -4262
- package/dist/core/twsxVariants.esm.js.map +1 -1
- package/dist/cx.cjs +2 -2
- package/dist/cx.cjs.map +1 -0
- package/dist/cx.esm.js +2 -2
- package/dist/index.cjs +5128 -6057
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +993 -1
- package/dist/index.esm.js +5124 -6022
- package/dist/index.esm.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/react/index.cjs +10177 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.ts +69 -0
- package/dist/react/index.esm.js +10173 -0
- package/dist/react/index.esm.js.map +1 -0
- package/dist/styled/index.cjs +9094 -0
- package/dist/styled/index.cjs.map +1 -0
- package/dist/styled/index.d.ts +17 -0
- package/dist/styled/index.esm.js +9087 -0
- package/dist/styled/index.esm.js.map +1 -0
- package/dist/tokens/index.cjs +359 -0
- package/dist/tokens/index.d.ts +33 -0
- package/dist/tokens/index.esm.js +355 -0
- package/dist/tokens/index.esm.js.map +1 -0
- package/dist/utils/index.cjs +313 -297
- package/dist/utils/index.esm.js +313 -297
- package/dist/utils/index.esm.js.map +1 -1
- package/package.json +38 -24
- package/types/animations/index.d.ts +58 -0
- package/types/className/index.d.ts +41 -0
- package/types/index.d.ts +993 -1
- package/types/react/index.d.ts +69 -0
- package/types/tokens/index.d.ts +33 -0
- package/types/v4.d.ts +191 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tailwind-to-style v4.0.0
|
|
3
|
+
* Zero-build runtime Tailwind CSS engine
|
|
4
|
+
*
|
|
5
|
+
* @author Bigetion
|
|
6
|
+
* @license MIT
|
|
7
|
+
*/
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
function _arrayLikeToArray(r, a) {
|
|
11
|
+
(null == a || a > r.length) && (a = r.length);
|
|
12
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
13
|
+
return n;
|
|
14
|
+
}
|
|
15
|
+
function _arrayWithHoles(r) {
|
|
16
|
+
if (Array.isArray(r)) return r;
|
|
17
|
+
}
|
|
18
|
+
function _defineProperty(e, r, t) {
|
|
19
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
20
|
+
value: t,
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true
|
|
24
|
+
}) : e[r] = t, e;
|
|
25
|
+
}
|
|
26
|
+
function _iterableToArrayLimit(r, l) {
|
|
27
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
28
|
+
if (null != t) {
|
|
29
|
+
var e,
|
|
30
|
+
n,
|
|
31
|
+
i,
|
|
32
|
+
u,
|
|
33
|
+
a = [],
|
|
34
|
+
f = true,
|
|
35
|
+
o = false;
|
|
36
|
+
try {
|
|
37
|
+
if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
38
|
+
} catch (r) {
|
|
39
|
+
o = true, n = r;
|
|
40
|
+
} finally {
|
|
41
|
+
try {
|
|
42
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
43
|
+
} finally {
|
|
44
|
+
if (o) throw n;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return a;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function _nonIterableRest() {
|
|
51
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
52
|
+
}
|
|
53
|
+
function ownKeys(e, r) {
|
|
54
|
+
var t = Object.keys(e);
|
|
55
|
+
if (Object.getOwnPropertySymbols) {
|
|
56
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
57
|
+
r && (o = o.filter(function (r) {
|
|
58
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
59
|
+
})), t.push.apply(t, o);
|
|
60
|
+
}
|
|
61
|
+
return t;
|
|
62
|
+
}
|
|
63
|
+
function _objectSpread2(e) {
|
|
64
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
65
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
66
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
67
|
+
_defineProperty(e, r, t[r]);
|
|
68
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
69
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return e;
|
|
73
|
+
}
|
|
74
|
+
function _slicedToArray(r, e) {
|
|
75
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
76
|
+
}
|
|
77
|
+
function _toPrimitive(t, r) {
|
|
78
|
+
if ("object" != typeof t || !t) return t;
|
|
79
|
+
var e = t[Symbol.toPrimitive];
|
|
80
|
+
if (void 0 !== e) {
|
|
81
|
+
var i = e.call(t, r);
|
|
82
|
+
if ("object" != typeof i) return i;
|
|
83
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
84
|
+
}
|
|
85
|
+
return ("string" === r ? String : Number)(t);
|
|
86
|
+
}
|
|
87
|
+
function _toPropertyKey(t) {
|
|
88
|
+
var i = _toPrimitive(t, "string");
|
|
89
|
+
return "symbol" == typeof i ? i : i + "";
|
|
90
|
+
}
|
|
91
|
+
function _unsupportedIterableToArray(r, a) {
|
|
92
|
+
if (r) {
|
|
93
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
94
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
95
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* tailwind-to-style/tokens — Design Token System
|
|
101
|
+
*
|
|
102
|
+
* Provides CSS variable-based theming with a globalThis singleton registry.
|
|
103
|
+
* Tokens are injected as CSS custom properties on :root.
|
|
104
|
+
*
|
|
105
|
+
* @module tailwind-to-style/tokens
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
// ============================================================================
|
|
109
|
+
// Singleton Registry (globalThis)
|
|
110
|
+
// ============================================================================
|
|
111
|
+
|
|
112
|
+
const REGISTRY_KEY = '__TWS_TOKEN_REGISTRY__';
|
|
113
|
+
function getRegistry() {
|
|
114
|
+
if (!globalThis[REGISTRY_KEY]) {
|
|
115
|
+
globalThis[REGISTRY_KEY] = {
|
|
116
|
+
tokens: {},
|
|
117
|
+
themes: {},
|
|
118
|
+
activeTheme: null,
|
|
119
|
+
subscribers: new Set(),
|
|
120
|
+
styleElement: null
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return globalThis[REGISTRY_KEY];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ============================================================================
|
|
127
|
+
// Token Registry API
|
|
128
|
+
// ============================================================================
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The token registry — get, set, subscribe to token changes.
|
|
132
|
+
*/
|
|
133
|
+
const tokenRegistry = {
|
|
134
|
+
/**
|
|
135
|
+
* Get a token value by path (dot notation).
|
|
136
|
+
* @param {string} path - Token path, e.g. "colors.primary"
|
|
137
|
+
* @returns {string|undefined} Token value
|
|
138
|
+
*/
|
|
139
|
+
get(path) {
|
|
140
|
+
const registry = getRegistry();
|
|
141
|
+
const keys = path.split('.');
|
|
142
|
+
let current = registry.tokens;
|
|
143
|
+
for (const key of keys) {
|
|
144
|
+
if (current === undefined || current === null) return undefined;
|
|
145
|
+
current = current[key];
|
|
146
|
+
}
|
|
147
|
+
return current;
|
|
148
|
+
},
|
|
149
|
+
/**
|
|
150
|
+
* Set a token value by path. Triggers subscribers and updates CSS.
|
|
151
|
+
* @param {string} path - Token path, e.g. "colors.primary"
|
|
152
|
+
* @param {string} value - Token value
|
|
153
|
+
*/
|
|
154
|
+
set(path, value) {
|
|
155
|
+
const registry = getRegistry();
|
|
156
|
+
const keys = path.split('.');
|
|
157
|
+
let current = registry.tokens;
|
|
158
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
159
|
+
if (!(keys[i] in current) || typeof current[keys[i]] !== 'object') {
|
|
160
|
+
current[keys[i]] = {};
|
|
161
|
+
}
|
|
162
|
+
current = current[keys[i]];
|
|
163
|
+
}
|
|
164
|
+
current[keys[keys.length - 1]] = value;
|
|
165
|
+
notifySubscribers();
|
|
166
|
+
injectTokenCSS();
|
|
167
|
+
},
|
|
168
|
+
/**
|
|
169
|
+
* Subscribe to token changes.
|
|
170
|
+
* @param {Function} callback - Called when tokens change
|
|
171
|
+
* @returns {Function} Unsubscribe function
|
|
172
|
+
*/
|
|
173
|
+
subscribe(callback) {
|
|
174
|
+
const registry = getRegistry();
|
|
175
|
+
registry.subscribers.add(callback);
|
|
176
|
+
return () => registry.subscribers.delete(callback);
|
|
177
|
+
},
|
|
178
|
+
/**
|
|
179
|
+
* Get all tokens as a flat CSS custom properties string.
|
|
180
|
+
* @returns {string} CSS string with custom properties
|
|
181
|
+
*/
|
|
182
|
+
toCSS() {
|
|
183
|
+
const registry = getRegistry();
|
|
184
|
+
const vars = flattenTokens(registry.tokens, '--tws');
|
|
185
|
+
if (vars.length === 0) return '';
|
|
186
|
+
return ":root {\n".concat(vars.map(_ref => {
|
|
187
|
+
let _ref2 = _slicedToArray(_ref, 2),
|
|
188
|
+
k = _ref2[0],
|
|
189
|
+
v = _ref2[1];
|
|
190
|
+
return " ".concat(k, ": ").concat(v, ";");
|
|
191
|
+
}).join('\n'), "\n}");
|
|
192
|
+
},
|
|
193
|
+
/**
|
|
194
|
+
* Get all registered tokens as a plain object.
|
|
195
|
+
* @returns {Object} Token tree
|
|
196
|
+
*/
|
|
197
|
+
getAll() {
|
|
198
|
+
return _objectSpread2({}, getRegistry().tokens);
|
|
199
|
+
},
|
|
200
|
+
/**
|
|
201
|
+
* Clear all tokens.
|
|
202
|
+
*/
|
|
203
|
+
clear() {
|
|
204
|
+
const registry = getRegistry();
|
|
205
|
+
registry.tokens = {};
|
|
206
|
+
registry.activeTheme = null;
|
|
207
|
+
notifySubscribers();
|
|
208
|
+
injectTokenCSS();
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
// ============================================================================
|
|
213
|
+
// createTheme()
|
|
214
|
+
// ============================================================================
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Create and activate a theme by injecting CSS custom properties.
|
|
218
|
+
*
|
|
219
|
+
* @param {Object} tokens - Token definition object (nested)
|
|
220
|
+
* @param {Object} [options] - Options
|
|
221
|
+
* @param {string} [options.name] - Theme name for reference
|
|
222
|
+
* @param {string} [options.selector] - CSS selector to scope theme (default: ":root")
|
|
223
|
+
* @returns {Object} Theme object with name and token values
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* createTheme({
|
|
227
|
+
* colors: { primary: '#3b82f6', secondary: '#8b5cf6' },
|
|
228
|
+
* spacing: { sm: '0.5rem', md: '1rem', lg: '1.5rem' },
|
|
229
|
+
* radius: { sm: '0.25rem', md: '0.5rem' },
|
|
230
|
+
* });
|
|
231
|
+
* // Injects: --tws-colors-primary: #3b82f6; --tws-colors-secondary: #8b5cf6; ...
|
|
232
|
+
*/
|
|
233
|
+
function createTheme(tokens) {
|
|
234
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
235
|
+
const _options$name = options.name,
|
|
236
|
+
name = _options$name === void 0 ? 'default' : _options$name,
|
|
237
|
+
_options$selector = options.selector,
|
|
238
|
+
selector = _options$selector === void 0 ? ':root' : _options$selector;
|
|
239
|
+
const registry = getRegistry();
|
|
240
|
+
|
|
241
|
+
// Merge tokens into registry
|
|
242
|
+
deepMerge(registry.tokens, tokens);
|
|
243
|
+
registry.activeTheme = name;
|
|
244
|
+
registry.themes[name] = {
|
|
245
|
+
tokens: _objectSpread2({}, tokens),
|
|
246
|
+
selector
|
|
247
|
+
};
|
|
248
|
+
notifySubscribers();
|
|
249
|
+
injectTokenCSS(selector);
|
|
250
|
+
return {
|
|
251
|
+
name,
|
|
252
|
+
tokens,
|
|
253
|
+
selector,
|
|
254
|
+
/** Get a CSS variable reference for use in styles */
|
|
255
|
+
var(path) {
|
|
256
|
+
return "var(--tws-".concat(path.replace(/\./g, '-'), ")");
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Switch to a previously defined theme.
|
|
263
|
+
* @param {string} name - Theme name
|
|
264
|
+
*/
|
|
265
|
+
function activateTheme(name) {
|
|
266
|
+
const registry = getRegistry();
|
|
267
|
+
const theme = registry.themes[name];
|
|
268
|
+
if (!theme) {
|
|
269
|
+
throw new Error("[tailwind-to-style/tokens] Theme \"".concat(name, "\" not found."));
|
|
270
|
+
}
|
|
271
|
+
registry.tokens = _objectSpread2({}, theme.tokens);
|
|
272
|
+
registry.activeTheme = name;
|
|
273
|
+
notifySubscribers();
|
|
274
|
+
injectTokenCSS(theme.selector);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Get a CSS variable reference string for a token path.
|
|
279
|
+
* @param {string} path - Token path (dot notation)
|
|
280
|
+
* @param {string} [fallback] - Fallback value
|
|
281
|
+
* @returns {string} CSS var() expression
|
|
282
|
+
*/
|
|
283
|
+
function token(path, fallback) {
|
|
284
|
+
const varName = "--tws-".concat(path.replace(/\./g, '-'));
|
|
285
|
+
return fallback ? "var(".concat(varName, ", ").concat(fallback, ")") : "var(".concat(varName, ")");
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// ============================================================================
|
|
289
|
+
// Internal Helpers
|
|
290
|
+
// ============================================================================
|
|
291
|
+
|
|
292
|
+
function flattenTokens(obj, prefix) {
|
|
293
|
+
const result = [];
|
|
294
|
+
for (const _ref3 of Object.entries(obj)) {
|
|
295
|
+
var _ref4 = _slicedToArray(_ref3, 2);
|
|
296
|
+
const key = _ref4[0];
|
|
297
|
+
const value = _ref4[1];
|
|
298
|
+
const varName = "".concat(prefix, "-").concat(key);
|
|
299
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
300
|
+
result.push(...flattenTokens(value, varName));
|
|
301
|
+
} else {
|
|
302
|
+
result.push([varName, value]);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
function deepMerge(target, source) {
|
|
308
|
+
for (const _ref5 of Object.entries(source)) {
|
|
309
|
+
var _ref6 = _slicedToArray(_ref5, 2);
|
|
310
|
+
const key = _ref6[0];
|
|
311
|
+
const value = _ref6[1];
|
|
312
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value) && typeof target[key] === 'object' && target[key] !== null) {
|
|
313
|
+
deepMerge(target[key], value);
|
|
314
|
+
} else {
|
|
315
|
+
// Deep clone objects to avoid mutating the source
|
|
316
|
+
target[key] = typeof value === 'object' && value !== null && !Array.isArray(value) ? deepMerge({}, value) : value;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return target;
|
|
320
|
+
}
|
|
321
|
+
function notifySubscribers() {
|
|
322
|
+
const registry = getRegistry();
|
|
323
|
+
for (const fn of registry.subscribers) {
|
|
324
|
+
try {
|
|
325
|
+
fn(registry.tokens);
|
|
326
|
+
} catch (e) {
|
|
327
|
+
// Ignore subscriber errors
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function injectTokenCSS() {
|
|
332
|
+
let selector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ':root';
|
|
333
|
+
if (typeof document === 'undefined') return;
|
|
334
|
+
const registry = getRegistry();
|
|
335
|
+
const vars = flattenTokens(registry.tokens, '--tws');
|
|
336
|
+
if (vars.length === 0) {
|
|
337
|
+
if (registry.styleElement) {
|
|
338
|
+
registry.styleElement.textContent = '';
|
|
339
|
+
}
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
const css = "".concat(selector, " {\n").concat(vars.map(_ref7 => {
|
|
343
|
+
let _ref8 = _slicedToArray(_ref7, 2),
|
|
344
|
+
k = _ref8[0],
|
|
345
|
+
v = _ref8[1];
|
|
346
|
+
return " ".concat(k, ": ").concat(v, ";");
|
|
347
|
+
}).join('\n'), "\n}");
|
|
348
|
+
if (!registry.styleElement) {
|
|
349
|
+
registry.styleElement = document.createElement('style');
|
|
350
|
+
registry.styleElement.setAttribute('data-tws-tokens', '');
|
|
351
|
+
document.head.appendChild(registry.styleElement);
|
|
352
|
+
}
|
|
353
|
+
registry.styleElement.textContent = css;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
exports.activateTheme = activateTheme;
|
|
357
|
+
exports.createTheme = createTheme;
|
|
358
|
+
exports.token = token;
|
|
359
|
+
exports.tokenRegistry = tokenRegistry;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Type definitions for tailwind-to-style/tokens
|
|
2
|
+
|
|
3
|
+
export interface TokenRegistry {
|
|
4
|
+
get(path: string): string | undefined;
|
|
5
|
+
set(path: string, value: string): void;
|
|
6
|
+
subscribe(callback: (tokens: Record<string, any>) => void): () => void;
|
|
7
|
+
toCSS(): string;
|
|
8
|
+
getAll(): Record<string, any>;
|
|
9
|
+
clear(): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ThemeResult {
|
|
13
|
+
name: string;
|
|
14
|
+
tokens: Record<string, any>;
|
|
15
|
+
selector: string;
|
|
16
|
+
var(path: string): string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface CreateThemeOptions {
|
|
20
|
+
name?: string;
|
|
21
|
+
selector?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export declare const tokenRegistry: TokenRegistry;
|
|
25
|
+
|
|
26
|
+
export declare function createTheme(
|
|
27
|
+
tokens: Record<string, any>,
|
|
28
|
+
options?: CreateThemeOptions
|
|
29
|
+
): ThemeResult;
|
|
30
|
+
|
|
31
|
+
export declare function activateTheme(name: string): void;
|
|
32
|
+
|
|
33
|
+
export declare function token(path: string, fallback?: string): string;
|