tailwind-styled-v4 5.0.8 → 5.0.9
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/CHANGELOG.md +184 -410
- package/README.md +45 -15
- package/dist/index.d.mts +26 -8
- package/dist/index.d.ts +26 -8
- package/dist/index.js +72 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -19
- package/dist/index.mjs.map +1 -1
- package/dist/next.d.mts +10 -4
- package/dist/next.d.ts +10 -4
- package/dist/next.js +13 -7
- package/dist/next.js.map +1 -1
- package/dist/next.mjs +13 -7
- package/dist/next.mjs.map +1 -1
- package/dist/turbopackLoader.js +5 -2
- package/dist/turbopackLoader.js.map +1 -1
- package/dist/turbopackLoader.mjs +5 -2
- package/dist/turbopackLoader.mjs.map +1 -1
- package/dist/webpackLoader.js +4 -0
- package/dist/webpackLoader.js.map +1 -1
- package/dist/webpackLoader.mjs +4 -0
- package/dist/webpackLoader.mjs.map +1 -1
- package/native/tailwind-styled-native.node +0 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -335,28 +335,44 @@ function getStateRegistry() {
|
|
|
335
335
|
|
|
336
336
|
// packages/domain/core/src/createComponent.ts
|
|
337
337
|
var ALWAYS_BLOCKED = /* @__PURE__ */ new Set(["base", "_ref", "state", "container", "containerName"]);
|
|
338
|
-
function
|
|
339
|
-
const
|
|
340
|
-
|
|
338
|
+
function parseSubComponentBlocks(template) {
|
|
339
|
+
const map = /* @__PURE__ */ new Map();
|
|
340
|
+
const re = /(?:\[([a-zA-Z][a-zA-Z0-9_-]*)\]|([a-zA-Z][a-zA-Z0-9_-]*))\s*\{([^}]*)\}/g;
|
|
341
|
+
let m;
|
|
342
|
+
while ((m = re.exec(template)) !== null) {
|
|
343
|
+
const name = m[1] ?? m[2];
|
|
344
|
+
const classes = m[3].trim().replace(/\s+/g, " ");
|
|
345
|
+
if (classes) map.set(name, classes);
|
|
346
|
+
}
|
|
347
|
+
return map;
|
|
341
348
|
}
|
|
342
349
|
function extractBaseClasses(template) {
|
|
343
|
-
return template.replace(
|
|
350
|
+
return template.replace(/(?:\[[a-zA-Z][a-zA-Z0-9_-]*\]|[a-zA-Z][a-zA-Z0-9_-]*)\s*\{[^}]*\}/g, "").replace(/\s+/g, " ").trim();
|
|
344
351
|
}
|
|
345
|
-
function createSubComponentAccessor(parentDisplayName, name) {
|
|
352
|
+
function createSubComponentAccessor(parentDisplayName, name, classes) {
|
|
346
353
|
const SubComponent = ({
|
|
347
354
|
children,
|
|
348
355
|
className
|
|
349
|
-
}) => React3.createElement(
|
|
356
|
+
}) => React3.createElement(
|
|
357
|
+
"span",
|
|
358
|
+
{ className: className ? `${classes} ${className}` : classes },
|
|
359
|
+
children
|
|
360
|
+
);
|
|
350
361
|
SubComponent.displayName = `${parentDisplayName}[${name}]`;
|
|
351
362
|
return SubComponent;
|
|
352
363
|
}
|
|
353
|
-
function registerSubComponents(component, template) {
|
|
354
|
-
const names = parseSubComponentNames(template);
|
|
364
|
+
function registerSubComponents(component, template, configSub) {
|
|
355
365
|
const displayName = component.displayName ?? "tw";
|
|
356
366
|
const map = component;
|
|
357
|
-
|
|
367
|
+
if (configSub) {
|
|
368
|
+
for (const [name, classes] of Object.entries(configSub)) {
|
|
369
|
+
map[name] = createSubComponentAccessor(displayName, name, classes.trim().replace(/\s+/g, " "));
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
const blocks = parseSubComponentBlocks(template);
|
|
373
|
+
for (const [name, classes] of blocks) {
|
|
358
374
|
if (!(name in map)) {
|
|
359
|
-
map[name] = createSubComponentAccessor(displayName, name);
|
|
375
|
+
map[name] = createSubComponentAccessor(displayName, name, classes);
|
|
360
376
|
}
|
|
361
377
|
}
|
|
362
378
|
}
|
|
@@ -407,13 +423,21 @@ function carryOverSubComponents(target, source) {
|
|
|
407
423
|
function attachExtend(component, originalTag, base, config) {
|
|
408
424
|
function extendWithClasses(stringsOrConfig) {
|
|
409
425
|
if (Array.isArray(stringsOrConfig) && "raw" in stringsOrConfig) {
|
|
410
|
-
const
|
|
411
|
-
const merged2 = twMerge(extractBaseClasses(base),
|
|
426
|
+
const rawExtra = stringsOrConfig.raw.join("").trim().replace(/\s+/g, " ");
|
|
427
|
+
const merged2 = twMerge(extractBaseClasses(base), extractBaseClasses(rawExtra));
|
|
412
428
|
const extended2 = createComponent(
|
|
413
429
|
originalTag,
|
|
414
430
|
typeof config === "string" ? merged2 : { ...config, base: merged2 }
|
|
415
431
|
);
|
|
416
432
|
carryOverSubComponents(extended2, component);
|
|
433
|
+
const extendSubBlocks = parseSubComponentBlocks(rawExtra);
|
|
434
|
+
if (extendSubBlocks.size > 0) {
|
|
435
|
+
const extComp = extended2;
|
|
436
|
+
const displayName = extended2.displayName ?? "tw";
|
|
437
|
+
for (const [subName, subClasses] of extendSubBlocks) {
|
|
438
|
+
extComp[subName] = createSubComponentAccessor(displayName, subName, subClasses);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
417
441
|
return extended2;
|
|
418
442
|
}
|
|
419
443
|
const extCfg = stringsOrConfig;
|
|
@@ -471,6 +495,7 @@ function createComponent(tag, config) {
|
|
|
471
495
|
const stateConfig = typeof config === "string" ? void 0 : config.state;
|
|
472
496
|
const containerConfig = typeof config === "string" ? void 0 : config.container;
|
|
473
497
|
const containerName = typeof config === "string" ? void 0 : config.containerName;
|
|
498
|
+
const configSub = typeof config === "string" ? void 0 : config.sub;
|
|
474
499
|
const stateResult = stateConfig ? processState(typeof tag === "string" ? tag : "component", stateConfig) : null;
|
|
475
500
|
const containerResult = containerConfig ? processContainer(typeof tag === "string" ? tag : "component", containerConfig, containerName) : null;
|
|
476
501
|
const engineClasses = [stateResult?.stateClass, containerResult?.containerClass].filter(Boolean).join(" ");
|
|
@@ -489,8 +514,8 @@ function createComponent(tag, config) {
|
|
|
489
514
|
const component2 = baseComponent2;
|
|
490
515
|
component2.displayName = `tw.${tagLabel}`;
|
|
491
516
|
const result2 = attachExtend(component2, tag, base, config);
|
|
492
|
-
registerSubComponents(result2, base);
|
|
493
|
-
return result2;
|
|
517
|
+
registerSubComponents(result2, base, configSub);
|
|
518
|
+
return wrapWithSubProxy(result2, tagLabel);
|
|
494
519
|
}
|
|
495
520
|
const baseComponent = React3.forwardRef((props, ref) => {
|
|
496
521
|
const { className, ...rest } = props;
|
|
@@ -506,8 +531,36 @@ function createComponent(tag, config) {
|
|
|
506
531
|
const component = baseComponent;
|
|
507
532
|
component.displayName = `tw.${tagLabel}`;
|
|
508
533
|
const result = attachExtend(component, tag, base, config);
|
|
509
|
-
registerSubComponents(result, base);
|
|
510
|
-
return result;
|
|
534
|
+
registerSubComponents(result, base, configSub);
|
|
535
|
+
return wrapWithSubProxy(result, tagLabel);
|
|
536
|
+
}
|
|
537
|
+
var SKIP_PROXY_KEYS = /* @__PURE__ */ new Set([
|
|
538
|
+
"extend",
|
|
539
|
+
"withVariants",
|
|
540
|
+
"animate",
|
|
541
|
+
"withSub",
|
|
542
|
+
"displayName",
|
|
543
|
+
"$$typeof",
|
|
544
|
+
"render",
|
|
545
|
+
"prototype",
|
|
546
|
+
"__esModule",
|
|
547
|
+
"then"
|
|
548
|
+
]);
|
|
549
|
+
function wrapWithSubProxy(component, tagLabel) {
|
|
550
|
+
return new Proxy(component, {
|
|
551
|
+
get(target, prop) {
|
|
552
|
+
const value = target[prop];
|
|
553
|
+
if (value !== void 0) return value;
|
|
554
|
+
if (typeof prop === "symbol") return value;
|
|
555
|
+
if (SKIP_PROXY_KEYS.has(prop)) return value;
|
|
556
|
+
const Fallback = ({
|
|
557
|
+
children,
|
|
558
|
+
className
|
|
559
|
+
}) => React3.createElement("span", { className }, children);
|
|
560
|
+
Fallback.displayName = `tw.${tagLabel}.${prop}(fallback)`;
|
|
561
|
+
return Fallback;
|
|
562
|
+
}
|
|
563
|
+
});
|
|
511
564
|
}
|
|
512
565
|
var __generatedRegistry = {};
|
|
513
566
|
function lookupGenerated(componentId, props, defaultVariants) {
|
|
@@ -1002,7 +1055,7 @@ function createStyledSystem(config) {
|
|
|
1002
1055
|
tokens
|
|
1003
1056
|
});
|
|
1004
1057
|
}
|
|
1005
|
-
var SUB_RE =
|
|
1058
|
+
var SUB_RE = /(?:\[([a-zA-Z][a-zA-Z0-9_-]*)\]|([a-zA-Z][a-zA-Z0-9_-]*))\s*\{([^}]*)\}/g;
|
|
1006
1059
|
var COMMENT_RE = /\/\/[^\n]*/g;
|
|
1007
1060
|
function parseTemplate(strings, exprs) {
|
|
1008
1061
|
const raw = strings.raw.reduce((acc, str, i) => {
|
|
@@ -1015,8 +1068,8 @@ function parseTemplate(strings, exprs) {
|
|
|
1015
1068
|
let match;
|
|
1016
1069
|
SUB_RE.lastIndex = 0;
|
|
1017
1070
|
while ((match = SUB_RE.exec(raw)) !== null) {
|
|
1018
|
-
const name = match[1];
|
|
1019
|
-
const inner = match[
|
|
1071
|
+
const name = match[1] ?? match[2];
|
|
1072
|
+
const inner = match[3].replace(COMMENT_RE, "").split("\n").map((l) => l.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim();
|
|
1020
1073
|
subs[name] = inner;
|
|
1021
1074
|
base = base.replace(match[0], "");
|
|
1022
1075
|
}
|