@kbach/react 0.6.14 → 0.6.16
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 +90 -262
- package/dist/{chunk-HCRWLOJE.mjs → chunk-GJSZUC6Q.mjs} +83 -48
- package/dist/{chunk-7DHBNCL5.mjs → chunk-YUX2JPTM.mjs} +12 -10
- package/dist/index.js +143 -65
- package/dist/index.mjs +67 -18
- package/dist/jsx-dev-runtime.js +84 -60
- package/dist/jsx-dev-runtime.mjs +2 -2
- package/dist/jsx-runtime.js +84 -60
- package/dist/jsx-runtime.mjs +2 -2
- package/dist/vite-plugin.js +25 -29
- package/dist/vite-plugin.mjs +25 -29
- package/package.json +1 -1
package/dist/jsx-dev-runtime.js
CHANGED
|
@@ -856,25 +856,6 @@ function resolveColor(value, colors, isArbitrary) {
|
|
|
856
856
|
}
|
|
857
857
|
}
|
|
858
858
|
}
|
|
859
|
-
if (hex && !hex.startsWith("#") && !hex.startsWith("rgb") && hex !== "transparent" && hex !== "currentColor") {
|
|
860
|
-
if (hex in colors) {
|
|
861
|
-
const alias = colors[hex];
|
|
862
|
-
if (typeof alias === "string") hex = alias;
|
|
863
|
-
else if (typeof alias === "object" && "6" in alias) hex = alias["6"] ?? hex;
|
|
864
|
-
} else {
|
|
865
|
-
const aliasLastDash = hex.lastIndexOf("-");
|
|
866
|
-
if (aliasLastDash > 0) {
|
|
867
|
-
const aliasColorName = hex.slice(0, aliasLastDash);
|
|
868
|
-
const aliasShade = hex.slice(aliasLastDash + 1);
|
|
869
|
-
const aliasScale = colors[aliasColorName];
|
|
870
|
-
if (aliasScale && typeof aliasScale === "object") {
|
|
871
|
-
hex = aliasScale[aliasShade] ?? null;
|
|
872
|
-
} else if (typeof aliasScale === "string") {
|
|
873
|
-
hex = aliasScale;
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
859
|
if (!hex) return null;
|
|
879
860
|
if (!opacityPart) {
|
|
880
861
|
if (!getEffectiveIsWeb() && hex.startsWith("#") && hex.length === 9) {
|
|
@@ -890,6 +871,8 @@ function resolveColor(value, colors, isArbitrary) {
|
|
|
890
871
|
alpha = parseFloat(opacityPart) / 100;
|
|
891
872
|
}
|
|
892
873
|
if (isNaN(alpha)) return hex;
|
|
874
|
+
if (alpha < 0) alpha = 0;
|
|
875
|
+
else if (alpha > 1) alpha = 1;
|
|
893
876
|
return hexToRgba(hex, alpha);
|
|
894
877
|
}
|
|
895
878
|
function parseHexRgb(hex) {
|
|
@@ -2408,7 +2391,7 @@ var RESOLVERS = {
|
|
|
2408
2391
|
"translate-x": ({ value, negative, isArbitrary }, { spacing }) => {
|
|
2409
2392
|
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
2410
2393
|
if (v === null) return null;
|
|
2411
|
-
if (getEffectiveIsWeb()) return { transform: `translateX(${v})` };
|
|
2394
|
+
if (getEffectiveIsWeb()) return { transform: `translateX(${typeof v === "number" ? `${v}px` : v})` };
|
|
2412
2395
|
if (typeof v === "string") {
|
|
2413
2396
|
const n = parseFloat(v);
|
|
2414
2397
|
return isNaN(n) ? null : { transform: [{ translateX: n }] };
|
|
@@ -2418,7 +2401,7 @@ var RESOLVERS = {
|
|
|
2418
2401
|
"translate-y": ({ value, negative, isArbitrary }, { spacing }) => {
|
|
2419
2402
|
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
2420
2403
|
if (v === null) return null;
|
|
2421
|
-
if (getEffectiveIsWeb()) return { transform: `translateY(${v})` };
|
|
2404
|
+
if (getEffectiveIsWeb()) return { transform: `translateY(${typeof v === "number" ? `${v}px` : v})` };
|
|
2422
2405
|
if (typeof v === "string") {
|
|
2423
2406
|
const n = parseFloat(v);
|
|
2424
2407
|
return isNaN(n) ? null : { transform: [{ translateY: n }] };
|
|
@@ -2587,6 +2570,14 @@ function getBuiltinStandaloneNames() {
|
|
|
2587
2570
|
}
|
|
2588
2571
|
|
|
2589
2572
|
// src/core/parser.ts
|
|
2573
|
+
var UNSAFE_ARBITRARY_VALUE = /[{};\\]|\/\*|\*\//;
|
|
2574
|
+
function isSafeArbitraryValue(value) {
|
|
2575
|
+
if (!UNSAFE_ARBITRARY_VALUE.test(value)) return true;
|
|
2576
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2577
|
+
kbachWarn(`Unsafe arbitrary value rejected: "${value}"`);
|
|
2578
|
+
}
|
|
2579
|
+
return false;
|
|
2580
|
+
}
|
|
2590
2581
|
function parseClass(className) {
|
|
2591
2582
|
const trimmed = className.trim();
|
|
2592
2583
|
if (!trimmed) return null;
|
|
@@ -2625,6 +2616,7 @@ function parseClass(className) {
|
|
|
2625
2616
|
if (bracketStart > 0 && remaining[bracketStart - 1] === "-" && remaining.endsWith("]")) {
|
|
2626
2617
|
const utility = remaining.slice(0, bracketStart - 1);
|
|
2627
2618
|
const value = remaining.slice(bracketStart + 1, -1).replace(/_/g, " ");
|
|
2619
|
+
if (!isSafeArbitraryValue(value)) return null;
|
|
2628
2620
|
return { original: trimmed, modifiers, negative, important, utility, value, isArbitrary: true };
|
|
2629
2621
|
}
|
|
2630
2622
|
if (remaining.endsWith("]") && bracketStart === -1) {
|
|
@@ -2634,6 +2626,7 @@ function parseClass(className) {
|
|
|
2634
2626
|
}
|
|
2635
2627
|
if (remaining.startsWith("[") && remaining.endsWith("]")) {
|
|
2636
2628
|
const value = remaining.slice(1, -1).replace(/_/g, " ");
|
|
2629
|
+
if (!isSafeArbitraryValue(value)) return null;
|
|
2637
2630
|
return { original: trimmed, modifiers, negative, important, utility: "", value, isArbitrary: true };
|
|
2638
2631
|
}
|
|
2639
2632
|
if (getBuiltinStandaloneNames().has(remaining)) {
|
|
@@ -2788,17 +2781,20 @@ function getDefaultFontFamily() {
|
|
|
2788
2781
|
return globalThis[FONT_KEY];
|
|
2789
2782
|
}
|
|
2790
2783
|
var _styleEl = null;
|
|
2784
|
+
var _ruleIndexByKey = /* @__PURE__ */ new Map();
|
|
2791
2785
|
function evictInjectedRule(rule) {
|
|
2786
|
+
const idx = _ruleIndexByKey.get(rule);
|
|
2787
|
+
_ruleIndexByKey.delete(rule);
|
|
2788
|
+
if (idx === void 0) return;
|
|
2792
2789
|
const sheet = _styleEl?.sheet;
|
|
2793
2790
|
if (!sheet) return;
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
}
|
|
2791
|
+
try {
|
|
2792
|
+
sheet.deleteRule(idx);
|
|
2793
|
+
} catch {
|
|
2794
|
+
return;
|
|
2795
|
+
}
|
|
2796
|
+
for (const [key, i] of _ruleIndexByKey) {
|
|
2797
|
+
if (i > idx) _ruleIndexByKey.set(key, i - 1);
|
|
2802
2798
|
}
|
|
2803
2799
|
}
|
|
2804
2800
|
var _injectedRules = new LRUCache(5e4, evictInjectedRule);
|
|
@@ -2815,11 +2811,15 @@ function getStyleEl() {
|
|
|
2815
2811
|
}
|
|
2816
2812
|
function injectRule(rule) {
|
|
2817
2813
|
if (isRuntimeCSSDisabled()) return;
|
|
2818
|
-
if (_injectedRules.
|
|
2819
|
-
_injectedRules.set(rule, true);
|
|
2814
|
+
if (_injectedRules.get(rule)) return;
|
|
2820
2815
|
try {
|
|
2821
2816
|
const sheet = getStyleEl().sheet;
|
|
2822
|
-
if (sheet)
|
|
2817
|
+
if (sheet) {
|
|
2818
|
+
const idx = sheet.cssRules.length;
|
|
2819
|
+
sheet.insertRule(rule, idx);
|
|
2820
|
+
_ruleIndexByKey.set(rule, idx);
|
|
2821
|
+
_injectedRules.set(rule, true);
|
|
2822
|
+
}
|
|
2823
2823
|
} catch {
|
|
2824
2824
|
}
|
|
2825
2825
|
}
|
|
@@ -3295,17 +3295,19 @@ var useSyncExternalStore = import_react.default.useSyncExternalStore ?? function
|
|
|
3295
3295
|
};
|
|
3296
3296
|
|
|
3297
3297
|
// src/useGlobalDarkMode.ts
|
|
3298
|
-
|
|
3298
|
+
var NOOP_SUB = (_) => () => {
|
|
3299
|
+
};
|
|
3300
|
+
var FALSE_SNAP = () => false;
|
|
3301
|
+
function useConditionalGlobalDarkMode(active) {
|
|
3299
3302
|
return useSyncExternalStore(
|
|
3300
|
-
subscribeGlobalDarkMode,
|
|
3301
|
-
getGlobalDarkMode,
|
|
3302
|
-
|
|
3303
|
-
// SSR: default light
|
|
3303
|
+
active ? subscribeGlobalDarkMode : NOOP_SUB,
|
|
3304
|
+
active ? getGlobalDarkMode : FALSE_SNAP,
|
|
3305
|
+
FALSE_SNAP
|
|
3304
3306
|
);
|
|
3305
3307
|
}
|
|
3306
3308
|
|
|
3307
3309
|
// src/useGlobalWidth.ts
|
|
3308
|
-
var
|
|
3310
|
+
var NOOP_SUB2 = (_) => () => {
|
|
3309
3311
|
};
|
|
3310
3312
|
var ZERO_SNAP = () => 0;
|
|
3311
3313
|
var EMPTY_BREAKPOINTS = /* @__PURE__ */ new Set();
|
|
@@ -3339,7 +3341,7 @@ function getWebWidth() {
|
|
|
3339
3341
|
}
|
|
3340
3342
|
function useConditionalWidth(active) {
|
|
3341
3343
|
return useSyncExternalStore(
|
|
3342
|
-
active ? isWeb ? subscribeWebWidth : subscribeGlobalWidth :
|
|
3344
|
+
active ? isWeb ? subscribeWebWidth : subscribeGlobalWidth : NOOP_SUB2,
|
|
3343
3345
|
active ? isWeb ? getWebWidth : getGlobalWidth : ZERO_SNAP,
|
|
3344
3346
|
ZERO_SNAP
|
|
3345
3347
|
);
|
|
@@ -3412,27 +3414,48 @@ var InteractiveWrapper = (0, import_react2.forwardRef)(
|
|
|
3412
3414
|
onBlur,
|
|
3413
3415
|
...rest
|
|
3414
3416
|
}, ref) {
|
|
3415
|
-
const
|
|
3417
|
+
const isWebPlatform = getEffectiveIsWeb();
|
|
3418
|
+
const isDark = useConditionalGlobalDarkMode(!isWebPlatform);
|
|
3416
3419
|
const needsWidth = hasResponsiveBuckets(resolvedStyle);
|
|
3417
|
-
const width = useConditionalWidth(needsWidth);
|
|
3420
|
+
const width = useConditionalWidth(needsWidth && !isWebPlatform);
|
|
3418
3421
|
const breakpoints = needsWidth ? getActiveBreakpoints(width) : EMPTY_BREAKPOINTS;
|
|
3419
3422
|
const [pressed, setPressed] = (0, import_react2.useState)(false);
|
|
3420
3423
|
const [hovered, setHovered] = (0, import_react2.useState)(false);
|
|
3421
3424
|
const [focused, setFocused] = (0, import_react2.useState)(false);
|
|
3422
|
-
const handlePressIn = (0, import_react2.useCallback)(chain(onPressIn, () =>
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
const
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
const
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
const
|
|
3425
|
+
const handlePressIn = (0, import_react2.useCallback)(chain(onPressIn, () => {
|
|
3426
|
+
if (!isWebPlatform) setPressed(true);
|
|
3427
|
+
}), [onPressIn, isWebPlatform]);
|
|
3428
|
+
const handlePressOut = (0, import_react2.useCallback)(chain(onPressOut, () => {
|
|
3429
|
+
if (!isWebPlatform) setPressed(false);
|
|
3430
|
+
}), [onPressOut, isWebPlatform]);
|
|
3431
|
+
const handlePointerDown = (0, import_react2.useCallback)(chain(onPointerDown, () => {
|
|
3432
|
+
if (!isWebPlatform) setPressed(true);
|
|
3433
|
+
}), [onPointerDown, isWebPlatform]);
|
|
3434
|
+
const handlePointerUp = (0, import_react2.useCallback)(chain(onPointerUp, () => {
|
|
3435
|
+
if (!isWebPlatform) setPressed(false);
|
|
3436
|
+
}), [onPointerUp, isWebPlatform]);
|
|
3437
|
+
const handlePointerLeave = (0, import_react2.useCallback)(chain(onPointerLeave, () => {
|
|
3438
|
+
if (!isWebPlatform) setPressed(false);
|
|
3439
|
+
}), [onPointerLeave, isWebPlatform]);
|
|
3440
|
+
const handlePointerCancel = (0, import_react2.useCallback)(chain(onPointerCancel, () => {
|
|
3441
|
+
if (!isWebPlatform) setPressed(false);
|
|
3442
|
+
}), [onPointerCancel, isWebPlatform]);
|
|
3443
|
+
const handleMouseEnter = (0, import_react2.useCallback)(chain(onMouseEnter, () => {
|
|
3444
|
+
if (!isWebPlatform) setHovered(true);
|
|
3445
|
+
}), [onMouseEnter, isWebPlatform]);
|
|
3446
|
+
const handleMouseLeave = (0, import_react2.useCallback)(chain(onMouseLeave, () => {
|
|
3447
|
+
if (!isWebPlatform) setHovered(false);
|
|
3448
|
+
}), [onMouseLeave, isWebPlatform]);
|
|
3449
|
+
const handleFocus = (0, import_react2.useCallback)(chain(onFocus, () => {
|
|
3450
|
+
if (!isWebPlatform) setFocused(true);
|
|
3451
|
+
}), [onFocus, isWebPlatform]);
|
|
3452
|
+
const handleBlur = (0, import_react2.useCallback)(chain(onBlur, () => {
|
|
3453
|
+
if (!isWebPlatform) setFocused(false);
|
|
3454
|
+
}), [onBlur, isWebPlatform]);
|
|
3432
3455
|
const { children, disabled, checked, ...restForComponent } = rest;
|
|
3433
3456
|
const computedStyle = (0, import_react2.useMemo)(
|
|
3434
3457
|
() => {
|
|
3435
|
-
if (
|
|
3458
|
+
if (isWebPlatform) return {};
|
|
3436
3459
|
const s = flatten(resolvedStyle, isDark, { pressed, hover: hovered, focus: focused, disabled: !!disabled, checked: !!checked }, breakpoints);
|
|
3437
3460
|
stripInternalMarkers(s);
|
|
3438
3461
|
if (typeof Component !== "string") stripWebOnlyProps(s);
|
|
@@ -3440,7 +3463,7 @@ var InteractiveWrapper = (0, import_react2.forwardRef)(
|
|
|
3440
3463
|
},
|
|
3441
3464
|
[resolvedStyle, isDark, pressed, hovered, focused, width, disabled, checked]
|
|
3442
3465
|
);
|
|
3443
|
-
const skipComputedInline =
|
|
3466
|
+
const skipComputedInline = isWebPlatform;
|
|
3444
3467
|
const finalStyle = skipComputedInline ? styleProp ?? void 0 : styleProp ? Array.isArray(styleProp) ? Object.assign({}, computedStyle, ...styleProp) : { ...computedStyle, ...styleProp } : computedStyle;
|
|
3445
3468
|
const componentProps = {
|
|
3446
3469
|
ref,
|
|
@@ -3482,20 +3505,21 @@ InteractiveWrapper.displayName = "Kbach.InteractiveWrapper";
|
|
|
3482
3505
|
var import_react3 = __toESM(require("react"));
|
|
3483
3506
|
var DarkWrapper = import_react3.default.forwardRef(
|
|
3484
3507
|
function DarkWrapper2({ Component, resolvedStyle, style: styleProp, children, ...rest }, ref) {
|
|
3485
|
-
const
|
|
3508
|
+
const isWebPlatform = getEffectiveIsWeb();
|
|
3509
|
+
const isDark = useConditionalGlobalDarkMode(!isWebPlatform);
|
|
3486
3510
|
const needsWidth = hasResponsiveBuckets(resolvedStyle);
|
|
3487
|
-
const width = useConditionalWidth(needsWidth);
|
|
3511
|
+
const width = useConditionalWidth(needsWidth && !isWebPlatform);
|
|
3488
3512
|
const breakpoints = needsWidth ? getActiveBreakpoints(width) : EMPTY_BREAKPOINTS;
|
|
3489
3513
|
const screens = getGlobalScreens();
|
|
3490
3514
|
const isNonStringComponent = typeof Component !== "string";
|
|
3491
3515
|
const computedStyle = (0, import_react3.useMemo)(() => {
|
|
3492
|
-
if (
|
|
3516
|
+
if (isWebPlatform) return {};
|
|
3493
3517
|
const s = flatten(resolvedStyle, isDark, {}, breakpoints);
|
|
3494
3518
|
stripInternalMarkers(s);
|
|
3495
3519
|
if (isNonStringComponent) stripWebOnlyProps(s);
|
|
3496
3520
|
return s;
|
|
3497
3521
|
}, [resolvedStyle, isDark, width, screens, isNonStringComponent]);
|
|
3498
|
-
const skipComputedInline =
|
|
3522
|
+
const skipComputedInline = isWebPlatform;
|
|
3499
3523
|
const finalStyle = skipComputedInline ? styleProp ?? void 0 : styleProp ? Array.isArray(styleProp) ? Object.assign({}, computedStyle, ...styleProp) : { ...computedStyle, ...styleProp } : computedStyle;
|
|
3500
3524
|
const props = { ref, ...rest, style: finalStyle };
|
|
3501
3525
|
return Array.isArray(children) ? import_react3.default.createElement(Component, props, ...children) : import_react3.default.createElement(Component, props, children);
|
|
@@ -3832,7 +3856,7 @@ function makeElement(isStaticChildren, type, props, key) {
|
|
|
3832
3856
|
}
|
|
3833
3857
|
function processElement(type, rawProps, key, isStaticChildren) {
|
|
3834
3858
|
if (type === null || typeof type === "symbol") return makeElement(isStaticChildren, type, rawProps ?? {}, key);
|
|
3835
|
-
const webTag =
|
|
3859
|
+
const webTag = getEffectiveIsWeb() ? getWebTag(type, rawProps ?? void 0) : null;
|
|
3836
3860
|
const effectiveType = webTag ?? type;
|
|
3837
3861
|
const originalName = webTag ? type?.displayName ?? type?.name : void 0;
|
|
3838
3862
|
if (!rawProps) return (0, import_jsx_runtime.jsx)(effectiveType, null, key);
|
|
@@ -3856,7 +3880,7 @@ function processElement(type, rawProps, key, isStaticChildren) {
|
|
|
3856
3880
|
}, key);
|
|
3857
3881
|
}
|
|
3858
3882
|
if (!classStr && !__kbachStyles) {
|
|
3859
|
-
if (
|
|
3883
|
+
if (getEffectiveIsWeb()) return makeElement(isStaticChildren, effectiveType, omitConsumed(workingProps), key);
|
|
3860
3884
|
const defaultFont = getCachedDefaultFont();
|
|
3861
3885
|
if (!defaultFont) return makeElement(isStaticChildren, effectiveType, workingProps, key);
|
|
3862
3886
|
const { style: userStyle2, ...passProps2 } = omitConsumed(workingProps);
|
|
@@ -3885,7 +3909,7 @@ function processElement(type, rawProps, key, isStaticChildren) {
|
|
|
3885
3909
|
...passProps
|
|
3886
3910
|
}, key);
|
|
3887
3911
|
}
|
|
3888
|
-
const skipComputedInline =
|
|
3912
|
+
const skipComputedInline = getEffectiveIsWeb();
|
|
3889
3913
|
let finalStyle;
|
|
3890
3914
|
if (!skipComputedInline) {
|
|
3891
3915
|
const computedStyle = flatten(resolved, false);
|
package/dist/jsx-dev-runtime.mjs
CHANGED
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
Fragment,
|
|
4
4
|
jsx,
|
|
5
5
|
jsxs
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-YUX2JPTM.mjs";
|
|
7
|
+
import "./chunk-GJSZUC6Q.mjs";
|
|
8
8
|
|
|
9
9
|
// src/jsx-dev-runtime.tsx
|
|
10
10
|
function jsxDEV(type, props, key, isStaticChildren, source, self) {
|
package/dist/jsx-runtime.js
CHANGED
|
@@ -857,25 +857,6 @@ function resolveColor(value, colors, isArbitrary) {
|
|
|
857
857
|
}
|
|
858
858
|
}
|
|
859
859
|
}
|
|
860
|
-
if (hex && !hex.startsWith("#") && !hex.startsWith("rgb") && hex !== "transparent" && hex !== "currentColor") {
|
|
861
|
-
if (hex in colors) {
|
|
862
|
-
const alias = colors[hex];
|
|
863
|
-
if (typeof alias === "string") hex = alias;
|
|
864
|
-
else if (typeof alias === "object" && "6" in alias) hex = alias["6"] ?? hex;
|
|
865
|
-
} else {
|
|
866
|
-
const aliasLastDash = hex.lastIndexOf("-");
|
|
867
|
-
if (aliasLastDash > 0) {
|
|
868
|
-
const aliasColorName = hex.slice(0, aliasLastDash);
|
|
869
|
-
const aliasShade = hex.slice(aliasLastDash + 1);
|
|
870
|
-
const aliasScale = colors[aliasColorName];
|
|
871
|
-
if (aliasScale && typeof aliasScale === "object") {
|
|
872
|
-
hex = aliasScale[aliasShade] ?? null;
|
|
873
|
-
} else if (typeof aliasScale === "string") {
|
|
874
|
-
hex = aliasScale;
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
860
|
if (!hex) return null;
|
|
880
861
|
if (!opacityPart) {
|
|
881
862
|
if (!getEffectiveIsWeb() && hex.startsWith("#") && hex.length === 9) {
|
|
@@ -891,6 +872,8 @@ function resolveColor(value, colors, isArbitrary) {
|
|
|
891
872
|
alpha = parseFloat(opacityPart) / 100;
|
|
892
873
|
}
|
|
893
874
|
if (isNaN(alpha)) return hex;
|
|
875
|
+
if (alpha < 0) alpha = 0;
|
|
876
|
+
else if (alpha > 1) alpha = 1;
|
|
894
877
|
return hexToRgba(hex, alpha);
|
|
895
878
|
}
|
|
896
879
|
function parseHexRgb(hex) {
|
|
@@ -2409,7 +2392,7 @@ var RESOLVERS = {
|
|
|
2409
2392
|
"translate-x": ({ value, negative, isArbitrary }, { spacing }) => {
|
|
2410
2393
|
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
2411
2394
|
if (v === null) return null;
|
|
2412
|
-
if (getEffectiveIsWeb()) return { transform: `translateX(${v})` };
|
|
2395
|
+
if (getEffectiveIsWeb()) return { transform: `translateX(${typeof v === "number" ? `${v}px` : v})` };
|
|
2413
2396
|
if (typeof v === "string") {
|
|
2414
2397
|
const n = parseFloat(v);
|
|
2415
2398
|
return isNaN(n) ? null : { transform: [{ translateX: n }] };
|
|
@@ -2419,7 +2402,7 @@ var RESOLVERS = {
|
|
|
2419
2402
|
"translate-y": ({ value, negative, isArbitrary }, { spacing }) => {
|
|
2420
2403
|
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
2421
2404
|
if (v === null) return null;
|
|
2422
|
-
if (getEffectiveIsWeb()) return { transform: `translateY(${v})` };
|
|
2405
|
+
if (getEffectiveIsWeb()) return { transform: `translateY(${typeof v === "number" ? `${v}px` : v})` };
|
|
2423
2406
|
if (typeof v === "string") {
|
|
2424
2407
|
const n = parseFloat(v);
|
|
2425
2408
|
return isNaN(n) ? null : { transform: [{ translateY: n }] };
|
|
@@ -2588,6 +2571,14 @@ function getBuiltinStandaloneNames() {
|
|
|
2588
2571
|
}
|
|
2589
2572
|
|
|
2590
2573
|
// src/core/parser.ts
|
|
2574
|
+
var UNSAFE_ARBITRARY_VALUE = /[{};\\]|\/\*|\*\//;
|
|
2575
|
+
function isSafeArbitraryValue(value) {
|
|
2576
|
+
if (!UNSAFE_ARBITRARY_VALUE.test(value)) return true;
|
|
2577
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2578
|
+
kbachWarn(`Unsafe arbitrary value rejected: "${value}"`);
|
|
2579
|
+
}
|
|
2580
|
+
return false;
|
|
2581
|
+
}
|
|
2591
2582
|
function parseClass(className) {
|
|
2592
2583
|
const trimmed = className.trim();
|
|
2593
2584
|
if (!trimmed) return null;
|
|
@@ -2626,6 +2617,7 @@ function parseClass(className) {
|
|
|
2626
2617
|
if (bracketStart > 0 && remaining[bracketStart - 1] === "-" && remaining.endsWith("]")) {
|
|
2627
2618
|
const utility = remaining.slice(0, bracketStart - 1);
|
|
2628
2619
|
const value = remaining.slice(bracketStart + 1, -1).replace(/_/g, " ");
|
|
2620
|
+
if (!isSafeArbitraryValue(value)) return null;
|
|
2629
2621
|
return { original: trimmed, modifiers, negative, important, utility, value, isArbitrary: true };
|
|
2630
2622
|
}
|
|
2631
2623
|
if (remaining.endsWith("]") && bracketStart === -1) {
|
|
@@ -2635,6 +2627,7 @@ function parseClass(className) {
|
|
|
2635
2627
|
}
|
|
2636
2628
|
if (remaining.startsWith("[") && remaining.endsWith("]")) {
|
|
2637
2629
|
const value = remaining.slice(1, -1).replace(/_/g, " ");
|
|
2630
|
+
if (!isSafeArbitraryValue(value)) return null;
|
|
2638
2631
|
return { original: trimmed, modifiers, negative, important, utility: "", value, isArbitrary: true };
|
|
2639
2632
|
}
|
|
2640
2633
|
if (getBuiltinStandaloneNames().has(remaining)) {
|
|
@@ -2789,17 +2782,20 @@ function getDefaultFontFamily() {
|
|
|
2789
2782
|
return globalThis[FONT_KEY];
|
|
2790
2783
|
}
|
|
2791
2784
|
var _styleEl = null;
|
|
2785
|
+
var _ruleIndexByKey = /* @__PURE__ */ new Map();
|
|
2792
2786
|
function evictInjectedRule(rule) {
|
|
2787
|
+
const idx = _ruleIndexByKey.get(rule);
|
|
2788
|
+
_ruleIndexByKey.delete(rule);
|
|
2789
|
+
if (idx === void 0) return;
|
|
2793
2790
|
const sheet = _styleEl?.sheet;
|
|
2794
2791
|
if (!sheet) return;
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
}
|
|
2792
|
+
try {
|
|
2793
|
+
sheet.deleteRule(idx);
|
|
2794
|
+
} catch {
|
|
2795
|
+
return;
|
|
2796
|
+
}
|
|
2797
|
+
for (const [key, i] of _ruleIndexByKey) {
|
|
2798
|
+
if (i > idx) _ruleIndexByKey.set(key, i - 1);
|
|
2803
2799
|
}
|
|
2804
2800
|
}
|
|
2805
2801
|
var _injectedRules = new LRUCache(5e4, evictInjectedRule);
|
|
@@ -2816,11 +2812,15 @@ function getStyleEl() {
|
|
|
2816
2812
|
}
|
|
2817
2813
|
function injectRule(rule) {
|
|
2818
2814
|
if (isRuntimeCSSDisabled()) return;
|
|
2819
|
-
if (_injectedRules.
|
|
2820
|
-
_injectedRules.set(rule, true);
|
|
2815
|
+
if (_injectedRules.get(rule)) return;
|
|
2821
2816
|
try {
|
|
2822
2817
|
const sheet = getStyleEl().sheet;
|
|
2823
|
-
if (sheet)
|
|
2818
|
+
if (sheet) {
|
|
2819
|
+
const idx = sheet.cssRules.length;
|
|
2820
|
+
sheet.insertRule(rule, idx);
|
|
2821
|
+
_ruleIndexByKey.set(rule, idx);
|
|
2822
|
+
_injectedRules.set(rule, true);
|
|
2823
|
+
}
|
|
2824
2824
|
} catch {
|
|
2825
2825
|
}
|
|
2826
2826
|
}
|
|
@@ -3296,17 +3296,19 @@ var useSyncExternalStore = import_react.default.useSyncExternalStore ?? function
|
|
|
3296
3296
|
};
|
|
3297
3297
|
|
|
3298
3298
|
// src/useGlobalDarkMode.ts
|
|
3299
|
-
|
|
3299
|
+
var NOOP_SUB = (_) => () => {
|
|
3300
|
+
};
|
|
3301
|
+
var FALSE_SNAP = () => false;
|
|
3302
|
+
function useConditionalGlobalDarkMode(active) {
|
|
3300
3303
|
return useSyncExternalStore(
|
|
3301
|
-
subscribeGlobalDarkMode,
|
|
3302
|
-
getGlobalDarkMode,
|
|
3303
|
-
|
|
3304
|
-
// SSR: default light
|
|
3304
|
+
active ? subscribeGlobalDarkMode : NOOP_SUB,
|
|
3305
|
+
active ? getGlobalDarkMode : FALSE_SNAP,
|
|
3306
|
+
FALSE_SNAP
|
|
3305
3307
|
);
|
|
3306
3308
|
}
|
|
3307
3309
|
|
|
3308
3310
|
// src/useGlobalWidth.ts
|
|
3309
|
-
var
|
|
3311
|
+
var NOOP_SUB2 = (_) => () => {
|
|
3310
3312
|
};
|
|
3311
3313
|
var ZERO_SNAP = () => 0;
|
|
3312
3314
|
var EMPTY_BREAKPOINTS = /* @__PURE__ */ new Set();
|
|
@@ -3340,7 +3342,7 @@ function getWebWidth() {
|
|
|
3340
3342
|
}
|
|
3341
3343
|
function useConditionalWidth(active) {
|
|
3342
3344
|
return useSyncExternalStore(
|
|
3343
|
-
active ? isWeb ? subscribeWebWidth : subscribeGlobalWidth :
|
|
3345
|
+
active ? isWeb ? subscribeWebWidth : subscribeGlobalWidth : NOOP_SUB2,
|
|
3344
3346
|
active ? isWeb ? getWebWidth : getGlobalWidth : ZERO_SNAP,
|
|
3345
3347
|
ZERO_SNAP
|
|
3346
3348
|
);
|
|
@@ -3413,27 +3415,48 @@ var InteractiveWrapper = (0, import_react2.forwardRef)(
|
|
|
3413
3415
|
onBlur,
|
|
3414
3416
|
...rest
|
|
3415
3417
|
}, ref) {
|
|
3416
|
-
const
|
|
3418
|
+
const isWebPlatform = getEffectiveIsWeb();
|
|
3419
|
+
const isDark = useConditionalGlobalDarkMode(!isWebPlatform);
|
|
3417
3420
|
const needsWidth = hasResponsiveBuckets(resolvedStyle);
|
|
3418
|
-
const width = useConditionalWidth(needsWidth);
|
|
3421
|
+
const width = useConditionalWidth(needsWidth && !isWebPlatform);
|
|
3419
3422
|
const breakpoints = needsWidth ? getActiveBreakpoints(width) : EMPTY_BREAKPOINTS;
|
|
3420
3423
|
const [pressed, setPressed] = (0, import_react2.useState)(false);
|
|
3421
3424
|
const [hovered, setHovered] = (0, import_react2.useState)(false);
|
|
3422
3425
|
const [focused, setFocused] = (0, import_react2.useState)(false);
|
|
3423
|
-
const handlePressIn = (0, import_react2.useCallback)(chain(onPressIn, () =>
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
const
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
const
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
const
|
|
3426
|
+
const handlePressIn = (0, import_react2.useCallback)(chain(onPressIn, () => {
|
|
3427
|
+
if (!isWebPlatform) setPressed(true);
|
|
3428
|
+
}), [onPressIn, isWebPlatform]);
|
|
3429
|
+
const handlePressOut = (0, import_react2.useCallback)(chain(onPressOut, () => {
|
|
3430
|
+
if (!isWebPlatform) setPressed(false);
|
|
3431
|
+
}), [onPressOut, isWebPlatform]);
|
|
3432
|
+
const handlePointerDown = (0, import_react2.useCallback)(chain(onPointerDown, () => {
|
|
3433
|
+
if (!isWebPlatform) setPressed(true);
|
|
3434
|
+
}), [onPointerDown, isWebPlatform]);
|
|
3435
|
+
const handlePointerUp = (0, import_react2.useCallback)(chain(onPointerUp, () => {
|
|
3436
|
+
if (!isWebPlatform) setPressed(false);
|
|
3437
|
+
}), [onPointerUp, isWebPlatform]);
|
|
3438
|
+
const handlePointerLeave = (0, import_react2.useCallback)(chain(onPointerLeave, () => {
|
|
3439
|
+
if (!isWebPlatform) setPressed(false);
|
|
3440
|
+
}), [onPointerLeave, isWebPlatform]);
|
|
3441
|
+
const handlePointerCancel = (0, import_react2.useCallback)(chain(onPointerCancel, () => {
|
|
3442
|
+
if (!isWebPlatform) setPressed(false);
|
|
3443
|
+
}), [onPointerCancel, isWebPlatform]);
|
|
3444
|
+
const handleMouseEnter = (0, import_react2.useCallback)(chain(onMouseEnter, () => {
|
|
3445
|
+
if (!isWebPlatform) setHovered(true);
|
|
3446
|
+
}), [onMouseEnter, isWebPlatform]);
|
|
3447
|
+
const handleMouseLeave = (0, import_react2.useCallback)(chain(onMouseLeave, () => {
|
|
3448
|
+
if (!isWebPlatform) setHovered(false);
|
|
3449
|
+
}), [onMouseLeave, isWebPlatform]);
|
|
3450
|
+
const handleFocus = (0, import_react2.useCallback)(chain(onFocus, () => {
|
|
3451
|
+
if (!isWebPlatform) setFocused(true);
|
|
3452
|
+
}), [onFocus, isWebPlatform]);
|
|
3453
|
+
const handleBlur = (0, import_react2.useCallback)(chain(onBlur, () => {
|
|
3454
|
+
if (!isWebPlatform) setFocused(false);
|
|
3455
|
+
}), [onBlur, isWebPlatform]);
|
|
3433
3456
|
const { children, disabled, checked, ...restForComponent } = rest;
|
|
3434
3457
|
const computedStyle = (0, import_react2.useMemo)(
|
|
3435
3458
|
() => {
|
|
3436
|
-
if (
|
|
3459
|
+
if (isWebPlatform) return {};
|
|
3437
3460
|
const s = flatten(resolvedStyle, isDark, { pressed, hover: hovered, focus: focused, disabled: !!disabled, checked: !!checked }, breakpoints);
|
|
3438
3461
|
stripInternalMarkers(s);
|
|
3439
3462
|
if (typeof Component !== "string") stripWebOnlyProps(s);
|
|
@@ -3441,7 +3464,7 @@ var InteractiveWrapper = (0, import_react2.forwardRef)(
|
|
|
3441
3464
|
},
|
|
3442
3465
|
[resolvedStyle, isDark, pressed, hovered, focused, width, disabled, checked]
|
|
3443
3466
|
);
|
|
3444
|
-
const skipComputedInline =
|
|
3467
|
+
const skipComputedInline = isWebPlatform;
|
|
3445
3468
|
const finalStyle = skipComputedInline ? styleProp ?? void 0 : styleProp ? Array.isArray(styleProp) ? Object.assign({}, computedStyle, ...styleProp) : { ...computedStyle, ...styleProp } : computedStyle;
|
|
3446
3469
|
const componentProps = {
|
|
3447
3470
|
ref,
|
|
@@ -3483,20 +3506,21 @@ InteractiveWrapper.displayName = "Kbach.InteractiveWrapper";
|
|
|
3483
3506
|
var import_react3 = __toESM(require("react"));
|
|
3484
3507
|
var DarkWrapper = import_react3.default.forwardRef(
|
|
3485
3508
|
function DarkWrapper2({ Component, resolvedStyle, style: styleProp, children, ...rest }, ref) {
|
|
3486
|
-
const
|
|
3509
|
+
const isWebPlatform = getEffectiveIsWeb();
|
|
3510
|
+
const isDark = useConditionalGlobalDarkMode(!isWebPlatform);
|
|
3487
3511
|
const needsWidth = hasResponsiveBuckets(resolvedStyle);
|
|
3488
|
-
const width = useConditionalWidth(needsWidth);
|
|
3512
|
+
const width = useConditionalWidth(needsWidth && !isWebPlatform);
|
|
3489
3513
|
const breakpoints = needsWidth ? getActiveBreakpoints(width) : EMPTY_BREAKPOINTS;
|
|
3490
3514
|
const screens = getGlobalScreens();
|
|
3491
3515
|
const isNonStringComponent = typeof Component !== "string";
|
|
3492
3516
|
const computedStyle = (0, import_react3.useMemo)(() => {
|
|
3493
|
-
if (
|
|
3517
|
+
if (isWebPlatform) return {};
|
|
3494
3518
|
const s = flatten(resolvedStyle, isDark, {}, breakpoints);
|
|
3495
3519
|
stripInternalMarkers(s);
|
|
3496
3520
|
if (isNonStringComponent) stripWebOnlyProps(s);
|
|
3497
3521
|
return s;
|
|
3498
3522
|
}, [resolvedStyle, isDark, width, screens, isNonStringComponent]);
|
|
3499
|
-
const skipComputedInline =
|
|
3523
|
+
const skipComputedInline = isWebPlatform;
|
|
3500
3524
|
const finalStyle = skipComputedInline ? styleProp ?? void 0 : styleProp ? Array.isArray(styleProp) ? Object.assign({}, computedStyle, ...styleProp) : { ...computedStyle, ...styleProp } : computedStyle;
|
|
3501
3525
|
const props = { ref, ...rest, style: finalStyle };
|
|
3502
3526
|
return Array.isArray(children) ? import_react3.default.createElement(Component, props, ...children) : import_react3.default.createElement(Component, props, children);
|
|
@@ -3838,7 +3862,7 @@ function makeElement(isStaticChildren, type, props, key) {
|
|
|
3838
3862
|
}
|
|
3839
3863
|
function processElement(type, rawProps, key, isStaticChildren) {
|
|
3840
3864
|
if (type === null || typeof type === "symbol") return makeElement(isStaticChildren, type, rawProps ?? {}, key);
|
|
3841
|
-
const webTag =
|
|
3865
|
+
const webTag = getEffectiveIsWeb() ? getWebTag(type, rawProps ?? void 0) : null;
|
|
3842
3866
|
const effectiveType = webTag ?? type;
|
|
3843
3867
|
const originalName = webTag ? type?.displayName ?? type?.name : void 0;
|
|
3844
3868
|
if (!rawProps) return (0, import_jsx_runtime.jsx)(effectiveType, null, key);
|
|
@@ -3862,7 +3886,7 @@ function processElement(type, rawProps, key, isStaticChildren) {
|
|
|
3862
3886
|
}, key);
|
|
3863
3887
|
}
|
|
3864
3888
|
if (!classStr && !__kbachStyles) {
|
|
3865
|
-
if (
|
|
3889
|
+
if (getEffectiveIsWeb()) return makeElement(isStaticChildren, effectiveType, omitConsumed(workingProps), key);
|
|
3866
3890
|
const defaultFont = getCachedDefaultFont();
|
|
3867
3891
|
if (!defaultFont) return makeElement(isStaticChildren, effectiveType, workingProps, key);
|
|
3868
3892
|
const { style: userStyle2, ...passProps2 } = omitConsumed(workingProps);
|
|
@@ -3891,7 +3915,7 @@ function processElement(type, rawProps, key, isStaticChildren) {
|
|
|
3891
3915
|
...passProps
|
|
3892
3916
|
}, key);
|
|
3893
3917
|
}
|
|
3894
|
-
const skipComputedInline =
|
|
3918
|
+
const skipComputedInline = getEffectiveIsWeb();
|
|
3895
3919
|
let finalStyle;
|
|
3896
3920
|
if (!skipComputedInline) {
|
|
3897
3921
|
const computedStyle = flatten(resolved, false);
|
package/dist/jsx-runtime.mjs
CHANGED
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
_invalidateDefaultFontCache,
|
|
5
5
|
jsx,
|
|
6
6
|
jsxs
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-YUX2JPTM.mjs";
|
|
8
8
|
import {
|
|
9
9
|
registerWebElement
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-GJSZUC6Q.mjs";
|
|
11
11
|
export {
|
|
12
12
|
Fragment,
|
|
13
13
|
_invalidateDefaultFontCache,
|