@kbach/react 0.6.0 → 0.6.2
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 +49 -0
- package/dist/{chunk-6NED62DB.mjs → chunk-GRZ6MVIL.mjs} +659 -179
- package/dist/{chunk-AAAI37Y4.mjs → chunk-NWW57Q5Q.mjs} +12 -71
- package/dist/index.d.mts +142 -3
- package/dist/index.d.ts +142 -3
- package/dist/index.js +345 -395
- package/dist/index.mjs +69 -98
- package/dist/jsx-dev-runtime.js +205 -289
- package/dist/jsx-dev-runtime.mjs +4 -4
- package/dist/jsx-runtime.js +204 -288
- package/dist/jsx-runtime.mjs +3 -3
- package/dist/vite-plugin.d.mts +102 -1
- package/dist/vite-plugin.d.ts +102 -1
- package/dist/vite-plugin.js +139 -163
- package/dist/vite-plugin.mjs +2883 -12
- package/jsx-dev-runtime.js +1 -0
- package/jsx-runtime.js +1 -0
- package/kbach-react.md +7 -0
- package/package.json +3 -3
- package/dist/chunk-D4LJICWZ.mjs +0 -524
- package/dist/types-BESBQANS.d.mts +0 -131
- package/dist/types-BESBQANS.d.ts +0 -131
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
"use strict";
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
@@ -34,6 +35,7 @@ __export(index_exports, {
|
|
|
34
35
|
ThemeContext: () => ThemeContext,
|
|
35
36
|
ThemeProvider: () => ThemeProvider,
|
|
36
37
|
buildConfig: () => buildConfig,
|
|
38
|
+
clearCache: () => clearCache,
|
|
37
39
|
cx: () => cx,
|
|
38
40
|
defaultColors: () => defaultColors,
|
|
39
41
|
defaultTheme: () => defaultTheme,
|
|
@@ -47,6 +49,7 @@ __export(index_exports, {
|
|
|
47
49
|
parseClasses: () => parseClasses,
|
|
48
50
|
registerWebElement: () => registerWebElement,
|
|
49
51
|
resolve: () => resolve,
|
|
52
|
+
setResolveTarget: () => setResolveTarget,
|
|
50
53
|
splitClassTokens: () => splitClassTokens,
|
|
51
54
|
styled: () => styled,
|
|
52
55
|
updateConfig: () => updateConfig,
|
|
@@ -80,76 +83,6 @@ function useIsDark() {
|
|
|
80
83
|
|
|
81
84
|
// src/useColors.ts
|
|
82
85
|
var import_react2 = require("react");
|
|
83
|
-
function applyOpacity(color, opacity) {
|
|
84
|
-
const a = Math.max(0, Math.min(1, opacity / 100));
|
|
85
|
-
if (color.startsWith("#")) {
|
|
86
|
-
const h = color.slice(1);
|
|
87
|
-
let rs, gs, bs;
|
|
88
|
-
if (h.length === 3 || h.length === 4) {
|
|
89
|
-
rs = h[0] + h[0];
|
|
90
|
-
gs = h[1] + h[1];
|
|
91
|
-
bs = h[2] + h[2];
|
|
92
|
-
} else if (h.length === 8) {
|
|
93
|
-
rs = h.slice(0, 2);
|
|
94
|
-
gs = h.slice(2, 4);
|
|
95
|
-
bs = h.slice(4, 6);
|
|
96
|
-
} else {
|
|
97
|
-
rs = h.slice(0, 2);
|
|
98
|
-
gs = h.slice(2, 4);
|
|
99
|
-
bs = h.slice(4, 6);
|
|
100
|
-
}
|
|
101
|
-
return `rgba(${parseInt(rs, 16)},${parseInt(gs, 16)},${parseInt(bs, 16)},${a})`;
|
|
102
|
-
}
|
|
103
|
-
if (color.startsWith("rgb(")) return color.replace("rgb(", "rgba(").replace(")", `,${a})`);
|
|
104
|
-
if (color.startsWith("rgba(")) return color.replace(/,\s*[\d.]+\)$/, `,${a})`);
|
|
105
|
-
return color;
|
|
106
|
-
}
|
|
107
|
-
function makeShadeProxy(shades) {
|
|
108
|
-
return new Proxy(shades, {
|
|
109
|
-
get(target, prop) {
|
|
110
|
-
const key = String(prop);
|
|
111
|
-
if (key === "then") return void 0;
|
|
112
|
-
if (key.includes("/")) {
|
|
113
|
-
const slash = key.indexOf("/");
|
|
114
|
-
const shade = key.slice(0, slash);
|
|
115
|
-
const op = Number(key.slice(slash + 1));
|
|
116
|
-
const color = target[shade];
|
|
117
|
-
return typeof color === "string" ? applyOpacity(color, op) : void 0;
|
|
118
|
-
}
|
|
119
|
-
return target[key];
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
function wrapColors(rawColors) {
|
|
124
|
-
const cache = /* @__PURE__ */ new Map();
|
|
125
|
-
const alpha = (color, opacity) => opacity === void 0 ? color : applyOpacity(color, opacity);
|
|
126
|
-
return new Proxy({ alpha }, {
|
|
127
|
-
get(_, prop) {
|
|
128
|
-
const key = String(prop);
|
|
129
|
-
if (key === "then") return void 0;
|
|
130
|
-
if (key === "alpha") return alpha;
|
|
131
|
-
if (key.includes("/")) {
|
|
132
|
-
const slash = key.indexOf("/");
|
|
133
|
-
const name = key.slice(0, slash);
|
|
134
|
-
const op = Number(key.slice(slash + 1));
|
|
135
|
-
const entry2 = rawColors[name];
|
|
136
|
-
return typeof entry2 === "string" ? applyOpacity(entry2, op) : void 0;
|
|
137
|
-
}
|
|
138
|
-
const entry = rawColors[key];
|
|
139
|
-
if (entry === void 0) return void 0;
|
|
140
|
-
if (typeof entry === "string") return entry;
|
|
141
|
-
if (!cache.has(key)) cache.set(key, makeShadeProxy(entry));
|
|
142
|
-
return cache.get(key);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
function useColors() {
|
|
147
|
-
const { config } = useTheme();
|
|
148
|
-
return (0, import_react2.useMemo)(() => wrapColors(config.theme.colors), [config.theme.colors]);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// src/ThemeProvider.tsx
|
|
152
|
-
var import_react3 = require("react");
|
|
153
86
|
|
|
154
87
|
// src/core/theme.ts
|
|
155
88
|
var defaultColors = {
|
|
@@ -693,10 +626,11 @@ var defaultTheme = {
|
|
|
693
626
|
|
|
694
627
|
// src/core/cache.ts
|
|
695
628
|
var LRUCache = class {
|
|
696
|
-
constructor(capacity = 1e4) {
|
|
629
|
+
constructor(capacity = 1e4, onEvict) {
|
|
697
630
|
this.capacity = capacity;
|
|
698
631
|
if (capacity <= 0) throw new Error("LRUCache: capacity must be a positive integer");
|
|
699
632
|
this.cache = /* @__PURE__ */ new Map();
|
|
633
|
+
this.onEvict = onEvict;
|
|
700
634
|
}
|
|
701
635
|
get(key) {
|
|
702
636
|
if (!this.cache.has(key)) return void 0;
|
|
@@ -709,7 +643,10 @@ var LRUCache = class {
|
|
|
709
643
|
if (this.cache.has(key)) {
|
|
710
644
|
this.cache.delete(key);
|
|
711
645
|
} else if (this.cache.size >= this.capacity) {
|
|
712
|
-
this.cache.
|
|
646
|
+
const oldestKey = this.cache.keys().next().value;
|
|
647
|
+
const oldestValue = this.cache.get(oldestKey);
|
|
648
|
+
this.cache.delete(oldestKey);
|
|
649
|
+
this.onEvict?.(oldestKey, oldestValue);
|
|
713
650
|
}
|
|
714
651
|
this.cache.set(key, value);
|
|
715
652
|
return this;
|
|
@@ -731,9 +668,13 @@ var LRUCache = class {
|
|
|
731
668
|
// src/core/platform.ts
|
|
732
669
|
var isWeb = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
|
|
733
670
|
var isNative = !isWeb && (typeof globalThis.HermesInternal !== "undefined" || typeof globalThis.__fbBatchedBridge !== "undefined" || typeof navigator !== "undefined" && navigator.product === "ReactNative" || typeof globalThis.__REACT_NATIVE__ !== "undefined");
|
|
734
|
-
var
|
|
671
|
+
var _resolveTargetOverride = null;
|
|
672
|
+
function setResolveTarget(target) {
|
|
673
|
+
_resolveTargetOverride = target;
|
|
674
|
+
}
|
|
735
675
|
function getEffectiveIsWeb() {
|
|
736
|
-
|
|
676
|
+
if (_resolveTargetOverride) return _resolveTargetOverride === "web";
|
|
677
|
+
return isWeb || !isNative;
|
|
737
678
|
}
|
|
738
679
|
function toNativeValue(raw) {
|
|
739
680
|
if (/^-?\d+(\.\d+)?px$/.test(raw)) return parseFloat(raw);
|
|
@@ -914,18 +855,28 @@ function resolveColor(value, colors, isArbitrary) {
|
|
|
914
855
|
if (isNaN(alpha)) return hex;
|
|
915
856
|
return hexToRgba(hex, alpha);
|
|
916
857
|
}
|
|
917
|
-
function
|
|
858
|
+
function parseHexRgb(hex) {
|
|
918
859
|
const h = hex.replace("#", "");
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
r = parseInt(h.slice(0, 2), 16);
|
|
926
|
-
g = parseInt(h.slice(2, 4), 16);
|
|
927
|
-
b = parseInt(h.slice(4, 6), 16);
|
|
860
|
+
if (h.length === 3 || h.length === 4) {
|
|
861
|
+
return [
|
|
862
|
+
parseInt(h[0] + h[0], 16),
|
|
863
|
+
parseInt(h[1] + h[1], 16),
|
|
864
|
+
parseInt(h[2] + h[2], 16)
|
|
865
|
+
];
|
|
928
866
|
}
|
|
867
|
+
if (h.length === 6 || h.length === 8) {
|
|
868
|
+
return [
|
|
869
|
+
parseInt(h.slice(0, 2), 16),
|
|
870
|
+
parseInt(h.slice(2, 4), 16),
|
|
871
|
+
parseInt(h.slice(4, 6), 16)
|
|
872
|
+
];
|
|
873
|
+
}
|
|
874
|
+
return null;
|
|
875
|
+
}
|
|
876
|
+
function hexToRgba(hex, alpha) {
|
|
877
|
+
const rgb = parseHexRgb(hex);
|
|
878
|
+
if (!rgb) return hex;
|
|
879
|
+
const [r, g, b] = rgb;
|
|
929
880
|
return `rgba(${r},${g},${b},${alpha})`;
|
|
930
881
|
}
|
|
931
882
|
function resolveSpacing(value, negative, spacing, isArbitrary) {
|
|
@@ -969,8 +920,8 @@ function resolveFontSize(value, fontSizes, isArbitrary) {
|
|
|
969
920
|
if (isArbitrary) return getEffectiveIsWeb() ? value : toNativeValue(value);
|
|
970
921
|
return fontSizes[value] ?? null;
|
|
971
922
|
}
|
|
972
|
-
var FILTER_COMPOSE = "var(--
|
|
973
|
-
var BACKDROP_FILTER_COMPOSE = "var(--
|
|
923
|
+
var FILTER_COMPOSE = "var(--kb-blur,) var(--kb-brightness,) var(--kb-contrast,) var(--kb-grayscale,) var(--kb-hue-rotate,) var(--kb-invert,) var(--kb-saturate,) var(--kb-sepia,) var(--kb-drop-shadow,)";
|
|
924
|
+
var BACKDROP_FILTER_COMPOSE = "var(--kb-backdrop-blur,) var(--kb-backdrop-brightness,) var(--kb-backdrop-contrast,) var(--kb-backdrop-grayscale,) var(--kb-backdrop-hue-rotate,) var(--kb-backdrop-invert,) var(--kb-backdrop-opacity,) var(--kb-backdrop-saturate,) var(--kb-backdrop-sepia,)";
|
|
974
925
|
var _standalone = null;
|
|
975
926
|
function buildStandalone() {
|
|
976
927
|
const web = getEffectiveIsWeb();
|
|
@@ -1232,9 +1183,9 @@ function buildStandalone() {
|
|
|
1232
1183
|
"backface-visible": { backfaceVisibility: "visible" },
|
|
1233
1184
|
"backface-hidden": { backfaceVisibility: "hidden" },
|
|
1234
1185
|
// CSS filters — standalone = default/full effect (web-only)
|
|
1235
|
-
grayscale: web ? { "--
|
|
1236
|
-
invert: web ? { "--
|
|
1237
|
-
sepia: web ? { "--
|
|
1186
|
+
grayscale: web ? { "--kb-grayscale": "grayscale(100%)", filter: FILTER_COMPOSE } : null,
|
|
1187
|
+
invert: web ? { "--kb-invert": "invert(100%)", filter: FILTER_COMPOSE } : null,
|
|
1188
|
+
sepia: web ? { "--kb-sepia": "sepia(100%)", filter: FILTER_COMPOSE } : null,
|
|
1238
1189
|
// Divide none
|
|
1239
1190
|
"divide-none": web ? { __divideX: 0, __divideY: 0 } : null,
|
|
1240
1191
|
// Group / peer markers (no-op: no style emitted; just ensures isKnownUtility returns true)
|
|
@@ -1319,6 +1270,48 @@ function getStandalone() {
|
|
|
1319
1270
|
if (!_standalone) _standalone = buildStandalone();
|
|
1320
1271
|
return _standalone;
|
|
1321
1272
|
}
|
|
1273
|
+
function makeSpacingResolver(prop) {
|
|
1274
|
+
return ({ value, negative, isArbitrary }, { spacing }) => {
|
|
1275
|
+
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
1276
|
+
return v !== null ? { [prop]: v } : null;
|
|
1277
|
+
};
|
|
1278
|
+
}
|
|
1279
|
+
var PADDING_MARGIN_PROPS = {
|
|
1280
|
+
p: "padding",
|
|
1281
|
+
px: "paddingHorizontal",
|
|
1282
|
+
py: "paddingVertical",
|
|
1283
|
+
pt: "paddingTop",
|
|
1284
|
+
pr: "paddingRight",
|
|
1285
|
+
pb: "paddingBottom",
|
|
1286
|
+
pl: "paddingLeft",
|
|
1287
|
+
m: "margin",
|
|
1288
|
+
mx: "marginHorizontal",
|
|
1289
|
+
my: "marginVertical",
|
|
1290
|
+
mt: "marginTop",
|
|
1291
|
+
mr: "marginRight",
|
|
1292
|
+
mb: "marginBottom",
|
|
1293
|
+
ml: "marginLeft"
|
|
1294
|
+
};
|
|
1295
|
+
function makeBorderSideResolver(widthProp, colorProp) {
|
|
1296
|
+
return ({ value, isArbitrary }, { colors, borderWidth }) => {
|
|
1297
|
+
if (!value) return { [widthProp]: 1 };
|
|
1298
|
+
if (isArbitrary) {
|
|
1299
|
+
const w2 = toNativeValue(value);
|
|
1300
|
+
if (typeof w2 === "number") return { [widthProp]: w2 };
|
|
1301
|
+
return { [colorProp]: value };
|
|
1302
|
+
}
|
|
1303
|
+
const color = resolveColor(value, colors, false);
|
|
1304
|
+
if (color) return { [colorProp]: color };
|
|
1305
|
+
const w = borderWidth[value];
|
|
1306
|
+
return w !== void 0 ? { [widthProp]: w } : null;
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
var BORDER_SIDE_PROPS = {
|
|
1310
|
+
"border-t": ["borderTopWidth", "borderTopColor"],
|
|
1311
|
+
"border-r": ["borderRightWidth", "borderRightColor"],
|
|
1312
|
+
"border-b": ["borderBottomWidth", "borderBottomColor"],
|
|
1313
|
+
"border-l": ["borderLeftWidth", "borderLeftColor"]
|
|
1314
|
+
};
|
|
1322
1315
|
var RESOLVERS = {
|
|
1323
1316
|
// ── Background ─────────────────────────────────────────────────────────────
|
|
1324
1317
|
bg: ({ value, isArbitrary }, { colors }) => {
|
|
@@ -1352,64 +1345,8 @@ var RESOLVERS = {
|
|
|
1352
1345
|
const v = isArbitrary ? n > 1 ? n / 100 : n : n / 100;
|
|
1353
1346
|
return { "--text-opacity": v };
|
|
1354
1347
|
},
|
|
1355
|
-
// ── Padding
|
|
1356
|
-
|
|
1357
|
-
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
1358
|
-
return v !== null ? { padding: v } : null;
|
|
1359
|
-
},
|
|
1360
|
-
px: ({ value, negative, isArbitrary }, { spacing }) => {
|
|
1361
|
-
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
1362
|
-
return v !== null ? { paddingHorizontal: v } : null;
|
|
1363
|
-
},
|
|
1364
|
-
py: ({ value, negative, isArbitrary }, { spacing }) => {
|
|
1365
|
-
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
1366
|
-
return v !== null ? { paddingVertical: v } : null;
|
|
1367
|
-
},
|
|
1368
|
-
pt: ({ value, negative, isArbitrary }, { spacing }) => {
|
|
1369
|
-
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
1370
|
-
return v !== null ? { paddingTop: v } : null;
|
|
1371
|
-
},
|
|
1372
|
-
pr: ({ value, negative, isArbitrary }, { spacing }) => {
|
|
1373
|
-
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
1374
|
-
return v !== null ? { paddingRight: v } : null;
|
|
1375
|
-
},
|
|
1376
|
-
pb: ({ value, negative, isArbitrary }, { spacing }) => {
|
|
1377
|
-
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
1378
|
-
return v !== null ? { paddingBottom: v } : null;
|
|
1379
|
-
},
|
|
1380
|
-
pl: ({ value, negative, isArbitrary }, { spacing }) => {
|
|
1381
|
-
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
1382
|
-
return v !== null ? { paddingLeft: v } : null;
|
|
1383
|
-
},
|
|
1384
|
-
// ── Margin ─────────────────────────────────────────────────────────────────
|
|
1385
|
-
m: ({ value, negative, isArbitrary }, { spacing }) => {
|
|
1386
|
-
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
1387
|
-
return v !== null ? { margin: v } : null;
|
|
1388
|
-
},
|
|
1389
|
-
mx: ({ value, negative, isArbitrary }, { spacing }) => {
|
|
1390
|
-
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
1391
|
-
return v !== null ? { marginHorizontal: v } : null;
|
|
1392
|
-
},
|
|
1393
|
-
my: ({ value, negative, isArbitrary }, { spacing }) => {
|
|
1394
|
-
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
1395
|
-
return v !== null ? { marginVertical: v } : null;
|
|
1396
|
-
},
|
|
1397
|
-
mt: ({ value, negative, isArbitrary }, { spacing }) => {
|
|
1398
|
-
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
1399
|
-
return v !== null ? { marginTop: v } : null;
|
|
1400
|
-
},
|
|
1401
|
-
mr: ({ value, negative, isArbitrary }, { spacing }) => {
|
|
1402
|
-
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
1403
|
-
return v !== null ? { marginRight: v } : null;
|
|
1404
|
-
},
|
|
1405
|
-
mb: ({ value, negative, isArbitrary }, { spacing }) => {
|
|
1406
|
-
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
1407
|
-
return v !== null ? { marginBottom: v } : null;
|
|
1408
|
-
},
|
|
1409
|
-
ml: ({ value, negative, isArbitrary }, { spacing }) => {
|
|
1410
|
-
const v = resolveSpacing(value, negative, spacing, isArbitrary);
|
|
1411
|
-
return v !== null ? { marginLeft: v } : null;
|
|
1412
|
-
},
|
|
1348
|
+
// ── Padding & margin ───────────────────────────────────────────────────────
|
|
1349
|
+
// Generated below via makeSpacingResolver() — see PADDING_MARGIN_PROPS.
|
|
1413
1350
|
// ── Sizing ─────────────────────────────────────────────────────────────────
|
|
1414
1351
|
w: ({ value, isArbitrary }, { spacing }) => {
|
|
1415
1352
|
const v = resolveSizing(value, spacing, isArbitrary);
|
|
@@ -1453,54 +1390,7 @@ var RESOLVERS = {
|
|
|
1453
1390
|
}
|
|
1454
1391
|
return null;
|
|
1455
1392
|
},
|
|
1456
|
-
|
|
1457
|
-
if (!value) return { borderTopWidth: 1 };
|
|
1458
|
-
if (isArbitrary) {
|
|
1459
|
-
const w2 = toNativeValue(value);
|
|
1460
|
-
if (typeof w2 === "number") return { borderTopWidth: w2 };
|
|
1461
|
-
return { borderTopColor: value };
|
|
1462
|
-
}
|
|
1463
|
-
const color = resolveColor(value, colors, false);
|
|
1464
|
-
if (color) return { borderTopColor: color };
|
|
1465
|
-
const w = borderWidth[value];
|
|
1466
|
-
return w !== void 0 ? { borderTopWidth: w } : null;
|
|
1467
|
-
},
|
|
1468
|
-
"border-r": ({ value, isArbitrary }, { colors, borderWidth }) => {
|
|
1469
|
-
if (!value) return { borderRightWidth: 1 };
|
|
1470
|
-
if (isArbitrary) {
|
|
1471
|
-
const w2 = toNativeValue(value);
|
|
1472
|
-
if (typeof w2 === "number") return { borderRightWidth: w2 };
|
|
1473
|
-
return { borderRightColor: value };
|
|
1474
|
-
}
|
|
1475
|
-
const color = resolveColor(value, colors, false);
|
|
1476
|
-
if (color) return { borderRightColor: color };
|
|
1477
|
-
const w = borderWidth[value];
|
|
1478
|
-
return w !== void 0 ? { borderRightWidth: w } : null;
|
|
1479
|
-
},
|
|
1480
|
-
"border-b": ({ value, isArbitrary }, { colors, borderWidth }) => {
|
|
1481
|
-
if (!value) return { borderBottomWidth: 1 };
|
|
1482
|
-
if (isArbitrary) {
|
|
1483
|
-
const w2 = toNativeValue(value);
|
|
1484
|
-
if (typeof w2 === "number") return { borderBottomWidth: w2 };
|
|
1485
|
-
return { borderBottomColor: value };
|
|
1486
|
-
}
|
|
1487
|
-
const color = resolveColor(value, colors, false);
|
|
1488
|
-
if (color) return { borderBottomColor: color };
|
|
1489
|
-
const w = borderWidth[value];
|
|
1490
|
-
return w !== void 0 ? { borderBottomWidth: w } : null;
|
|
1491
|
-
},
|
|
1492
|
-
"border-l": ({ value, isArbitrary }, { colors, borderWidth }) => {
|
|
1493
|
-
if (!value) return { borderLeftWidth: 1 };
|
|
1494
|
-
if (isArbitrary) {
|
|
1495
|
-
const w2 = toNativeValue(value);
|
|
1496
|
-
if (typeof w2 === "number") return { borderLeftWidth: w2 };
|
|
1497
|
-
return { borderLeftColor: value };
|
|
1498
|
-
}
|
|
1499
|
-
const color = resolveColor(value, colors, false);
|
|
1500
|
-
if (color) return { borderLeftColor: color };
|
|
1501
|
-
const w = borderWidth[value];
|
|
1502
|
-
return w !== void 0 ? { borderLeftWidth: w } : null;
|
|
1503
|
-
},
|
|
1393
|
+
// border-t/-r/-b/-l generated below via makeBorderSideResolver() — see BORDER_SIDE_PROPS.
|
|
1504
1394
|
// ── Border radius ──────────────────────────────────────────────────────────
|
|
1505
1395
|
rounded: ({ value, isArbitrary }, { borderRadius }) => {
|
|
1506
1396
|
const r = resolveRadius(value, borderRadius, isArbitrary);
|
|
@@ -1732,49 +1622,49 @@ var RESOLVERS = {
|
|
|
1732
1622
|
"2xl": "blur(40px)",
|
|
1733
1623
|
"3xl": "blur(64px)"
|
|
1734
1624
|
};
|
|
1735
|
-
if (value === "none") return { "--
|
|
1625
|
+
if (value === "none") return { "--kb-blur": "", filter: FILTER_COMPOSE };
|
|
1736
1626
|
const v = isArbitrary ? `blur(${value})` : sizes[value];
|
|
1737
|
-
return v !== void 0 ? { "--
|
|
1627
|
+
return v !== void 0 ? { "--kb-blur": v, filter: FILTER_COMPOSE } : null;
|
|
1738
1628
|
},
|
|
1739
1629
|
brightness: ({ value, isArbitrary }) => {
|
|
1740
1630
|
if (!getEffectiveIsWeb()) return null;
|
|
1741
1631
|
const v = isArbitrary ? `brightness(${value})` : `brightness(${parseFloat(value) / 100})`;
|
|
1742
|
-
return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--
|
|
1632
|
+
return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--kb-brightness": v, filter: FILTER_COMPOSE };
|
|
1743
1633
|
},
|
|
1744
1634
|
contrast: ({ value, isArbitrary }) => {
|
|
1745
1635
|
if (!getEffectiveIsWeb()) return null;
|
|
1746
1636
|
const v = isArbitrary ? `contrast(${value})` : `contrast(${parseFloat(value) / 100})`;
|
|
1747
|
-
return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--
|
|
1637
|
+
return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--kb-contrast": v, filter: FILTER_COMPOSE };
|
|
1748
1638
|
},
|
|
1749
1639
|
grayscale: ({ value }) => {
|
|
1750
1640
|
if (!getEffectiveIsWeb()) return null;
|
|
1751
1641
|
const v = value === "0" ? "grayscale(0)" : "grayscale(100%)";
|
|
1752
|
-
return { "--
|
|
1642
|
+
return { "--kb-grayscale": v, filter: FILTER_COMPOSE };
|
|
1753
1643
|
},
|
|
1754
1644
|
"hue-rotate": ({ value, negative, isArbitrary }) => {
|
|
1755
1645
|
if (!getEffectiveIsWeb()) return null;
|
|
1756
1646
|
const deg = isArbitrary ? value : `${(negative ? -1 : 1) * parseFloat(value)}deg`;
|
|
1757
1647
|
if (isNaN(parseFloat(deg)) && !isArbitrary) return null;
|
|
1758
|
-
return { "--
|
|
1648
|
+
return { "--kb-hue-rotate": `hue-rotate(${deg})`, filter: FILTER_COMPOSE };
|
|
1759
1649
|
},
|
|
1760
1650
|
invert: ({ value }) => {
|
|
1761
1651
|
if (!getEffectiveIsWeb()) return null;
|
|
1762
1652
|
const v = value === "0" ? "invert(0)" : "invert(100%)";
|
|
1763
|
-
return { "--
|
|
1653
|
+
return { "--kb-invert": v, filter: FILTER_COMPOSE };
|
|
1764
1654
|
},
|
|
1765
1655
|
saturate: ({ value, isArbitrary }) => {
|
|
1766
1656
|
if (!getEffectiveIsWeb()) return null;
|
|
1767
1657
|
const v = isArbitrary ? `saturate(${value})` : `saturate(${parseFloat(value) / 100})`;
|
|
1768
|
-
return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--
|
|
1658
|
+
return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--kb-saturate": v, filter: FILTER_COMPOSE };
|
|
1769
1659
|
},
|
|
1770
1660
|
sepia: ({ value }) => {
|
|
1771
1661
|
if (!getEffectiveIsWeb()) return null;
|
|
1772
1662
|
const v = value === "0" ? "sepia(0)" : "sepia(100%)";
|
|
1773
|
-
return { "--
|
|
1663
|
+
return { "--kb-sepia": v, filter: FILTER_COMPOSE };
|
|
1774
1664
|
},
|
|
1775
1665
|
"drop-shadow": ({ value, isArbitrary }) => {
|
|
1776
1666
|
if (!getEffectiveIsWeb()) return null;
|
|
1777
|
-
if (isArbitrary) return { "--
|
|
1667
|
+
if (isArbitrary) return { "--kb-drop-shadow": `drop-shadow(${value.replace(/_/g, " ")})`, filter: FILTER_COMPOSE };
|
|
1778
1668
|
const presets = {
|
|
1779
1669
|
"": "drop-shadow(0 1px 2px rgb(0 0 0/0.1)) drop-shadow(0 1px 1px rgb(0 0 0/0.06))",
|
|
1780
1670
|
sm: "drop-shadow(0 1px 1px rgb(0 0 0/0.05))",
|
|
@@ -1785,7 +1675,7 @@ var RESOLVERS = {
|
|
|
1785
1675
|
none: "drop-shadow(0 0 #0000)"
|
|
1786
1676
|
};
|
|
1787
1677
|
const v = presets[value];
|
|
1788
|
-
return v !== void 0 ? { "--
|
|
1678
|
+
return v !== void 0 ? { "--kb-drop-shadow": v, filter: FILTER_COMPOSE } : null;
|
|
1789
1679
|
},
|
|
1790
1680
|
// Arbitrary full filter string: filter-[blur(4px)_grayscale(1)]
|
|
1791
1681
|
filter: ({ value, isArbitrary }) => {
|
|
@@ -1806,47 +1696,47 @@ var RESOLVERS = {
|
|
|
1806
1696
|
"2xl": "blur(40px)",
|
|
1807
1697
|
"3xl": "blur(64px)"
|
|
1808
1698
|
};
|
|
1809
|
-
if (value === "none") return { "--
|
|
1699
|
+
if (value === "none") return { "--kb-backdrop-blur": "", backdropFilter: BACKDROP_FILTER_COMPOSE };
|
|
1810
1700
|
const v = isArbitrary ? `blur(${value})` : sizes[value];
|
|
1811
|
-
return v !== void 0 ? { "--
|
|
1701
|
+
return v !== void 0 ? { "--kb-backdrop-blur": v, backdropFilter: BACKDROP_FILTER_COMPOSE } : null;
|
|
1812
1702
|
},
|
|
1813
1703
|
"backdrop-brightness": ({ value, isArbitrary }) => {
|
|
1814
1704
|
if (!getEffectiveIsWeb()) return null;
|
|
1815
1705
|
const v = isArbitrary ? `brightness(${value})` : `brightness(${parseFloat(value) / 100})`;
|
|
1816
|
-
return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--
|
|
1706
|
+
return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--kb-backdrop-brightness": v, backdropFilter: BACKDROP_FILTER_COMPOSE };
|
|
1817
1707
|
},
|
|
1818
1708
|
"backdrop-contrast": ({ value, isArbitrary }) => {
|
|
1819
1709
|
if (!getEffectiveIsWeb()) return null;
|
|
1820
1710
|
const v = isArbitrary ? `contrast(${value})` : `contrast(${parseFloat(value) / 100})`;
|
|
1821
|
-
return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--
|
|
1711
|
+
return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--kb-backdrop-contrast": v, backdropFilter: BACKDROP_FILTER_COMPOSE };
|
|
1822
1712
|
},
|
|
1823
1713
|
"backdrop-grayscale": ({ value }) => {
|
|
1824
1714
|
if (!getEffectiveIsWeb()) return null;
|
|
1825
|
-
return { "--
|
|
1715
|
+
return { "--kb-backdrop-grayscale": value === "0" ? "grayscale(0)" : "grayscale(100%)", backdropFilter: BACKDROP_FILTER_COMPOSE };
|
|
1826
1716
|
},
|
|
1827
1717
|
"backdrop-hue-rotate": ({ value, negative, isArbitrary }) => {
|
|
1828
1718
|
if (!getEffectiveIsWeb()) return null;
|
|
1829
1719
|
const deg = isArbitrary ? value : `${(negative ? -1 : 1) * parseFloat(value)}deg`;
|
|
1830
1720
|
if (isNaN(parseFloat(deg)) && !isArbitrary) return null;
|
|
1831
|
-
return { "--
|
|
1721
|
+
return { "--kb-backdrop-hue-rotate": `hue-rotate(${deg})`, backdropFilter: BACKDROP_FILTER_COMPOSE };
|
|
1832
1722
|
},
|
|
1833
1723
|
"backdrop-invert": ({ value }) => {
|
|
1834
1724
|
if (!getEffectiveIsWeb()) return null;
|
|
1835
|
-
return { "--
|
|
1725
|
+
return { "--kb-backdrop-invert": value === "0" ? "invert(0)" : "invert(100%)", backdropFilter: BACKDROP_FILTER_COMPOSE };
|
|
1836
1726
|
},
|
|
1837
1727
|
"backdrop-opacity": ({ value, isArbitrary }) => {
|
|
1838
1728
|
if (!getEffectiveIsWeb()) return null;
|
|
1839
1729
|
const v = isArbitrary ? `opacity(${value})` : `opacity(${parseFloat(value) / 100})`;
|
|
1840
|
-
return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--
|
|
1730
|
+
return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--kb-backdrop-opacity": v, backdropFilter: BACKDROP_FILTER_COMPOSE };
|
|
1841
1731
|
},
|
|
1842
1732
|
"backdrop-saturate": ({ value, isArbitrary }) => {
|
|
1843
1733
|
if (!getEffectiveIsWeb()) return null;
|
|
1844
1734
|
const v = isArbitrary ? `saturate(${value})` : `saturate(${parseFloat(value) / 100})`;
|
|
1845
|
-
return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--
|
|
1735
|
+
return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--kb-backdrop-saturate": v, backdropFilter: BACKDROP_FILTER_COMPOSE };
|
|
1846
1736
|
},
|
|
1847
1737
|
"backdrop-sepia": ({ value }) => {
|
|
1848
1738
|
if (!getEffectiveIsWeb()) return null;
|
|
1849
|
-
return { "--
|
|
1739
|
+
return { "--kb-backdrop-sepia": value === "0" ? "sepia(0)" : "sepia(100%)", backdropFilter: BACKDROP_FILTER_COMPOSE };
|
|
1850
1740
|
},
|
|
1851
1741
|
"backdrop-filter": ({ value, isArbitrary }) => {
|
|
1852
1742
|
if (!getEffectiveIsWeb()) return null;
|
|
@@ -1870,7 +1760,7 @@ var RESOLVERS = {
|
|
|
1870
1760
|
const dir = directions[value];
|
|
1871
1761
|
if (!dir) return null;
|
|
1872
1762
|
return {
|
|
1873
|
-
backgroundImage: `linear-gradient(${dir}, var(--
|
|
1763
|
+
backgroundImage: `linear-gradient(${dir}, var(--kb-gradient-from, transparent), var(--kb-gradient-stops, transparent))`
|
|
1874
1764
|
};
|
|
1875
1765
|
},
|
|
1876
1766
|
from: ({ value, isArbitrary }, { colors }) => {
|
|
@@ -1878,8 +1768,8 @@ var RESOLVERS = {
|
|
|
1878
1768
|
const color = resolveColor(value, colors, isArbitrary);
|
|
1879
1769
|
if (!color) return null;
|
|
1880
1770
|
return {
|
|
1881
|
-
"--
|
|
1882
|
-
"--
|
|
1771
|
+
"--kb-gradient-from": color,
|
|
1772
|
+
"--kb-gradient-stops": `var(--kb-gradient-from), var(--kb-gradient-to, transparent)`
|
|
1883
1773
|
};
|
|
1884
1774
|
},
|
|
1885
1775
|
via: ({ value, isArbitrary }, { colors }) => {
|
|
@@ -1887,15 +1777,15 @@ var RESOLVERS = {
|
|
|
1887
1777
|
const color = resolveColor(value, colors, isArbitrary);
|
|
1888
1778
|
if (!color) return null;
|
|
1889
1779
|
return {
|
|
1890
|
-
"--
|
|
1891
|
-
"--
|
|
1780
|
+
"--kb-gradient-via": color,
|
|
1781
|
+
"--kb-gradient-stops": `var(--kb-gradient-from), var(--kb-gradient-via), var(--kb-gradient-to, transparent)`
|
|
1892
1782
|
};
|
|
1893
1783
|
},
|
|
1894
1784
|
to: ({ value, isArbitrary }, { colors }) => {
|
|
1895
1785
|
if (!getEffectiveIsWeb()) return null;
|
|
1896
1786
|
const color = resolveColor(value, colors, isArbitrary);
|
|
1897
1787
|
if (!color) return null;
|
|
1898
|
-
return { "--
|
|
1788
|
+
return { "--kb-gradient-to": color };
|
|
1899
1789
|
},
|
|
1900
1790
|
// ── Transform extras (web-only) ───────────────────────────────────────────
|
|
1901
1791
|
"skew-x": ({ value, negative, isArbitrary }) => {
|
|
@@ -2499,6 +2389,12 @@ var RESOLVERS = {
|
|
|
2499
2389
|
return { rowGap: v };
|
|
2500
2390
|
}
|
|
2501
2391
|
};
|
|
2392
|
+
for (const [utility, prop] of Object.entries(PADDING_MARGIN_PROPS)) {
|
|
2393
|
+
RESOLVERS[utility] = makeSpacingResolver(prop);
|
|
2394
|
+
}
|
|
2395
|
+
for (const [utility, [widthProp, colorProp]] of Object.entries(BORDER_SIDE_PROPS)) {
|
|
2396
|
+
RESOLVERS[utility] = makeBorderSideResolver(widthProp, colorProp);
|
|
2397
|
+
}
|
|
2502
2398
|
function resolveUtility(parsed, theme) {
|
|
2503
2399
|
if (!parsed.value) {
|
|
2504
2400
|
if (parsed.utility in PLUGIN_STANDALONE) return PLUGIN_STANDALONE[parsed.utility] ?? null;
|
|
@@ -2769,7 +2665,20 @@ function getDefaultFontFamily() {
|
|
|
2769
2665
|
return globalThis[FONT_KEY];
|
|
2770
2666
|
}
|
|
2771
2667
|
var _styleEl = null;
|
|
2772
|
-
|
|
2668
|
+
function evictInjectedRule(rule) {
|
|
2669
|
+
const sheet = _styleEl?.sheet;
|
|
2670
|
+
if (!sheet) return;
|
|
2671
|
+
for (let i = 0; i < sheet.cssRules.length; i++) {
|
|
2672
|
+
if (sheet.cssRules[i].cssText === rule) {
|
|
2673
|
+
try {
|
|
2674
|
+
sheet.deleteRule(i);
|
|
2675
|
+
} catch {
|
|
2676
|
+
}
|
|
2677
|
+
return;
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
var _injectedRules = new LRUCache(5e4, evictInjectedRule);
|
|
2773
2682
|
var _CSS_DISABLED_KEY = "__kbach_runtime_css_disabled__";
|
|
2774
2683
|
function disableRuntimeCSS() {
|
|
2775
2684
|
globalThis[_CSS_DISABLED_KEY] = true;
|
|
@@ -2806,8 +2715,7 @@ function injectGlobalStyles(theme) {
|
|
|
2806
2715
|
if (typeof document === "undefined" || isRuntimeCSSDisabled()) return;
|
|
2807
2716
|
const rules = [BASE_RESET];
|
|
2808
2717
|
const ff = theme.fontFamily;
|
|
2809
|
-
if (
|
|
2810
|
-
if (ff.sans && ff.sans !== "System") {
|
|
2718
|
+
if (ff?.sans && ff.sans !== "System") {
|
|
2811
2719
|
const family = Array.isArray(ff.sans) ? ff.sans.join(", ") : ff.sans;
|
|
2812
2720
|
rules.push(`body { font-family: ${family}; }`);
|
|
2813
2721
|
}
|
|
@@ -2970,7 +2878,7 @@ function buildClassCSSRules(cls, bucketKey, styles, darkMode, important, screens
|
|
|
2970
2878
|
else rule = `[data-theme="dark"] ${selector} { ${decls} }`;
|
|
2971
2879
|
} else if (darkScheme === "light") {
|
|
2972
2880
|
if (darkMode === "media") rule = `@media (prefers-color-scheme: light) { ${selector} { ${decls} } }`;
|
|
2973
|
-
else if (darkMode === "class") rule =
|
|
2881
|
+
else if (darkMode === "class") rule = `.light ${selector} { ${decls} }`;
|
|
2974
2882
|
else rule = `[data-theme="light"] ${selector} { ${decls} }`;
|
|
2975
2883
|
} else {
|
|
2976
2884
|
rule = `${selector} { ${decls} }`;
|
|
@@ -3101,11 +3009,14 @@ function getConfig() {
|
|
|
3101
3009
|
return store.resolved;
|
|
3102
3010
|
}
|
|
3103
3011
|
function resolveOneRef(ref, colors) {
|
|
3104
|
-
const
|
|
3105
|
-
if (
|
|
3106
|
-
const
|
|
3012
|
+
const lastDash = ref.lastIndexOf("-");
|
|
3013
|
+
if (lastDash <= 0) return null;
|
|
3014
|
+
const name = ref.slice(0, lastDash);
|
|
3015
|
+
const shade = ref.slice(lastDash + 1);
|
|
3016
|
+
if (!/^\d+$/.test(shade)) return null;
|
|
3017
|
+
const entry = colors[name];
|
|
3107
3018
|
if (!entry || typeof entry !== "object") return null;
|
|
3108
|
-
return entry[
|
|
3019
|
+
return entry[shade] ?? null;
|
|
3109
3020
|
}
|
|
3110
3021
|
function resolveColorRefs(colors) {
|
|
3111
3022
|
const MAX_DEPTH = 5;
|
|
@@ -3135,7 +3046,7 @@ function resolveColorRefs(colors) {
|
|
|
3135
3046
|
function buildConfig(userConfig) {
|
|
3136
3047
|
let theme = { ...defaultTheme };
|
|
3137
3048
|
if (userConfig.theme) {
|
|
3138
|
-
theme =
|
|
3049
|
+
theme = { ...theme, ...userConfig.theme };
|
|
3139
3050
|
}
|
|
3140
3051
|
if (userConfig.extend) {
|
|
3141
3052
|
const extendConfig = userConfig.extend;
|
|
@@ -3284,6 +3195,74 @@ function subscribeGlobalDarkMode(callback) {
|
|
|
3284
3195
|
return () => store.subscribers.delete(callback);
|
|
3285
3196
|
}
|
|
3286
3197
|
|
|
3198
|
+
// src/useColors.ts
|
|
3199
|
+
function applyOpacity(color, opacity) {
|
|
3200
|
+
const a = Math.max(0, Math.min(1, opacity / 100));
|
|
3201
|
+
if (color.startsWith("#")) {
|
|
3202
|
+
const rgb = parseHexRgb(color);
|
|
3203
|
+
if (!rgb) return color;
|
|
3204
|
+
const [r, g, b] = rgb;
|
|
3205
|
+
return `rgba(${r},${g},${b},${a})`;
|
|
3206
|
+
}
|
|
3207
|
+
if (color.startsWith("rgb(")) return color.replace("rgb(", "rgba(").replace(")", `,${a})`);
|
|
3208
|
+
if (color.startsWith("rgba(")) return color.replace(/,\s*[\d.]+\)$/, `,${a})`);
|
|
3209
|
+
return color;
|
|
3210
|
+
}
|
|
3211
|
+
function makeShadeProxy(shades) {
|
|
3212
|
+
return new Proxy(shades, {
|
|
3213
|
+
get(target, prop) {
|
|
3214
|
+
const key = String(prop);
|
|
3215
|
+
if (key === "then") return void 0;
|
|
3216
|
+
if (key.includes("/")) {
|
|
3217
|
+
const slash = key.indexOf("/");
|
|
3218
|
+
const shade = key.slice(0, slash);
|
|
3219
|
+
const op = Number(key.slice(slash + 1));
|
|
3220
|
+
const color = target[shade];
|
|
3221
|
+
return typeof color === "string" ? applyOpacity(color, op) : void 0;
|
|
3222
|
+
}
|
|
3223
|
+
return target[key];
|
|
3224
|
+
}
|
|
3225
|
+
});
|
|
3226
|
+
}
|
|
3227
|
+
function wrapColors(rawColors) {
|
|
3228
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3229
|
+
const alpha = (color, opacity) => opacity === void 0 ? color : applyOpacity(color, opacity);
|
|
3230
|
+
return new Proxy({ alpha }, {
|
|
3231
|
+
get(_, prop) {
|
|
3232
|
+
const key = String(prop);
|
|
3233
|
+
if (key === "then") return void 0;
|
|
3234
|
+
if (key === "alpha") return alpha;
|
|
3235
|
+
if (key.includes("/")) {
|
|
3236
|
+
const slash = key.indexOf("/");
|
|
3237
|
+
const name = key.slice(0, slash);
|
|
3238
|
+
const op = Number(key.slice(slash + 1));
|
|
3239
|
+
const entry2 = rawColors[name];
|
|
3240
|
+
return typeof entry2 === "string" ? applyOpacity(entry2, op) : void 0;
|
|
3241
|
+
}
|
|
3242
|
+
const entry = rawColors[key];
|
|
3243
|
+
if (entry === void 0) return void 0;
|
|
3244
|
+
if (typeof entry === "string") return entry;
|
|
3245
|
+
if (!cache.has(key)) cache.set(key, makeShadeProxy(entry));
|
|
3246
|
+
return cache.get(key);
|
|
3247
|
+
}
|
|
3248
|
+
});
|
|
3249
|
+
}
|
|
3250
|
+
function useColors() {
|
|
3251
|
+
const { config } = useTheme();
|
|
3252
|
+
return (0, import_react2.useMemo)(() => wrapColors(config.theme.colors), [config.theme.colors]);
|
|
3253
|
+
}
|
|
3254
|
+
|
|
3255
|
+
// src/ThemeProvider.tsx
|
|
3256
|
+
var import_react4 = require("react");
|
|
3257
|
+
|
|
3258
|
+
// src/useSyncExternalStoreShim.ts
|
|
3259
|
+
var import_react3 = __toESM(require("react"));
|
|
3260
|
+
var useSyncExternalStore = import_react3.default.useSyncExternalStore ?? function useSyncExternalStoreFallback(subscribe, getSnapshot, _getServerSnapshot) {
|
|
3261
|
+
const [, forceUpdate] = import_react3.default.useReducer((n) => n + 1, 0);
|
|
3262
|
+
import_react3.default.useEffect(() => subscribe(forceUpdate), [subscribe]);
|
|
3263
|
+
return getSnapshot();
|
|
3264
|
+
};
|
|
3265
|
+
|
|
3287
3266
|
// src/ThemeProvider.tsx
|
|
3288
3267
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
3289
3268
|
var STORAGE_KEY = "kbach-theme";
|
|
@@ -3301,6 +3280,22 @@ function persistMode(mode) {
|
|
|
3301
3280
|
} catch {
|
|
3302
3281
|
}
|
|
3303
3282
|
}
|
|
3283
|
+
function subscribeSystemScheme(callback) {
|
|
3284
|
+
if (!isWeb || typeof window === "undefined") return () => {
|
|
3285
|
+
};
|
|
3286
|
+
const mq = window.matchMedia?.("(prefers-color-scheme: dark)");
|
|
3287
|
+
if (!mq) return () => {
|
|
3288
|
+
};
|
|
3289
|
+
mq.addEventListener("change", callback);
|
|
3290
|
+
return () => mq.removeEventListener("change", callback);
|
|
3291
|
+
}
|
|
3292
|
+
function getSystemScheme() {
|
|
3293
|
+
if (!isWeb || typeof window === "undefined") return "light";
|
|
3294
|
+
return window.matchMedia?.("(prefers-color-scheme: dark)")?.matches ? "dark" : "light";
|
|
3295
|
+
}
|
|
3296
|
+
function getSystemSchemeServerSnapshot() {
|
|
3297
|
+
return "light";
|
|
3298
|
+
}
|
|
3304
3299
|
function applyWebTheme(resolvedMode, strategy) {
|
|
3305
3300
|
if (!isWeb) return;
|
|
3306
3301
|
const root = document.documentElement;
|
|
@@ -3319,35 +3314,34 @@ function ThemeProvider({
|
|
|
3319
3314
|
config: configOverride,
|
|
3320
3315
|
disablePersistence = false
|
|
3321
3316
|
}) {
|
|
3322
|
-
const [resolvedConfig, setResolvedConfig] = (0,
|
|
3317
|
+
const [resolvedConfig, setResolvedConfig] = (0, import_react4.useState)(
|
|
3323
3318
|
() => configOverride ? buildConfig(configOverride) : getConfig()
|
|
3324
3319
|
);
|
|
3325
|
-
const [webWidth, setWebWidth] = (0,
|
|
3326
|
-
() => isWeb && typeof window !== "undefined" ? window.innerWidth : 0
|
|
3327
|
-
);
|
|
3320
|
+
const [webWidth, setWebWidth] = (0, import_react4.useState)(0);
|
|
3328
3321
|
const effectiveWidth = windowWidthProp ?? (isWeb ? webWidth : 0);
|
|
3329
|
-
const numericScreens = (0,
|
|
3322
|
+
const numericScreens = (0, import_react4.useMemo)(() => {
|
|
3330
3323
|
const out = {};
|
|
3331
3324
|
for (const [k, v] of Object.entries(resolvedConfig.theme.screens ?? {})) {
|
|
3332
3325
|
out[k] = typeof v === "number" ? v : parseInt(String(v), 10);
|
|
3333
3326
|
}
|
|
3334
3327
|
return out;
|
|
3335
3328
|
}, [resolvedConfig.theme.screens]);
|
|
3336
|
-
const _prevWidthRef = (0,
|
|
3329
|
+
const _prevWidthRef = (0, import_react4.useRef)(-1);
|
|
3337
3330
|
if (_prevWidthRef.current !== effectiveWidth) {
|
|
3338
3331
|
_prevWidthRef.current = effectiveWidth;
|
|
3339
3332
|
syncGlobalWidth(effectiveWidth);
|
|
3340
3333
|
}
|
|
3341
|
-
const _prevScreensRef = (0,
|
|
3334
|
+
const _prevScreensRef = (0, import_react4.useRef)(null);
|
|
3342
3335
|
if (_prevScreensRef.current !== numericScreens) {
|
|
3343
3336
|
_prevScreensRef.current = numericScreens;
|
|
3344
3337
|
syncGlobalScreens(numericScreens);
|
|
3345
3338
|
}
|
|
3346
|
-
(0,
|
|
3339
|
+
(0, import_react4.useEffect)(() => {
|
|
3347
3340
|
setGlobalWidth(effectiveWidth);
|
|
3348
3341
|
}, [effectiveWidth]);
|
|
3349
|
-
(0,
|
|
3342
|
+
(0, import_react4.useEffect)(() => {
|
|
3350
3343
|
if (!isWeb || typeof window === "undefined") return;
|
|
3344
|
+
setWebWidth(window.innerWidth);
|
|
3351
3345
|
let raf = 0;
|
|
3352
3346
|
const update = () => {
|
|
3353
3347
|
cancelAnimationFrame(raf);
|
|
@@ -3363,52 +3357,38 @@ function ThemeProvider({
|
|
|
3363
3357
|
cancelAnimationFrame(raf);
|
|
3364
3358
|
};
|
|
3365
3359
|
}, []);
|
|
3366
|
-
const
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
});
|
|
3360
|
+
const webScheme = useSyncExternalStore(
|
|
3361
|
+
subscribeSystemScheme,
|
|
3362
|
+
getSystemScheme,
|
|
3363
|
+
getSystemSchemeServerSnapshot
|
|
3364
|
+
);
|
|
3372
3365
|
const systemScheme = isWeb ? webScheme : colorScheme === "dark" ? "dark" : "light";
|
|
3373
|
-
const [mode, _setMode] = (0,
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
const setMode = (0, import_react3.useCallback)((next) => {
|
|
3366
|
+
const [mode, _setMode] = (0, import_react4.useState)(defaultMode);
|
|
3367
|
+
(0, import_react4.useEffect)(() => {
|
|
3368
|
+
if (disablePersistence) return;
|
|
3369
|
+
const persisted = loadPersistedMode();
|
|
3370
|
+
if (persisted) _setMode(persisted);
|
|
3371
|
+
}, []);
|
|
3372
|
+
const setMode = (0, import_react4.useCallback)((next) => {
|
|
3381
3373
|
_setMode(next);
|
|
3382
3374
|
if (!disablePersistence) persistMode(next);
|
|
3383
3375
|
}, [disablePersistence]);
|
|
3384
|
-
const toggle = (0,
|
|
3376
|
+
const toggle = (0, import_react4.useCallback)(() => {
|
|
3385
3377
|
setMode(mode === "dark" || mode === "system" && systemScheme === "dark" ? "light" : "dark");
|
|
3386
3378
|
}, [mode, systemScheme, setMode]);
|
|
3387
3379
|
const resolvedMode = mode === "system" ? systemScheme : mode;
|
|
3388
3380
|
const isDark = resolvedMode === "dark";
|
|
3389
3381
|
syncGlobalDarkMode(isDark);
|
|
3390
|
-
(0,
|
|
3382
|
+
(0, import_react4.useEffect)(() => {
|
|
3391
3383
|
applyWebTheme(resolvedMode, resolvedConfig.darkMode);
|
|
3392
3384
|
setGlobalDarkMode(isDark);
|
|
3393
3385
|
}, [isDark, resolvedMode, resolvedConfig.darkMode]);
|
|
3394
|
-
|
|
3395
|
-
setWebSchemeRef.current = setWebScheme;
|
|
3396
|
-
(0, import_react3.useEffect)(() => {
|
|
3397
|
-
if (!isWeb || typeof window === "undefined") return;
|
|
3398
|
-
const mq = window.matchMedia?.("(prefers-color-scheme: dark)");
|
|
3399
|
-
if (!mq) return;
|
|
3400
|
-
const handler = (e) => {
|
|
3401
|
-
setWebSchemeRef.current(e.matches ? "dark" : "light");
|
|
3402
|
-
};
|
|
3403
|
-
mq.addEventListener("change", handler);
|
|
3404
|
-
return () => mq.removeEventListener("change", handler);
|
|
3405
|
-
}, []);
|
|
3406
|
-
(0, import_react3.useEffect)(() => {
|
|
3386
|
+
(0, import_react4.useEffect)(() => {
|
|
3407
3387
|
if (!configOverride) return;
|
|
3408
3388
|
updateConfig(configOverride);
|
|
3409
3389
|
setResolvedConfig(getConfig());
|
|
3410
3390
|
}, [configOverride]);
|
|
3411
|
-
(0,
|
|
3391
|
+
(0, import_react4.useEffect)(() => {
|
|
3412
3392
|
if (configOverride) return;
|
|
3413
3393
|
let mounted = true;
|
|
3414
3394
|
const unsub = onConfigChange((config) => {
|
|
@@ -3419,7 +3399,7 @@ function ThemeProvider({
|
|
|
3419
3399
|
unsub();
|
|
3420
3400
|
};
|
|
3421
3401
|
}, [configOverride]);
|
|
3422
|
-
const contextValue = (0,
|
|
3402
|
+
const contextValue = (0, import_react4.useMemo)(
|
|
3423
3403
|
() => ({ mode, resolvedMode, isDark, setMode, toggle, config: resolvedConfig }),
|
|
3424
3404
|
[mode, resolvedMode, isDark, setMode, toggle, resolvedConfig]
|
|
3425
3405
|
);
|
|
@@ -3427,15 +3407,9 @@ function ThemeProvider({
|
|
|
3427
3407
|
}
|
|
3428
3408
|
|
|
3429
3409
|
// src/styled.tsx
|
|
3430
|
-
var
|
|
3410
|
+
var import_react5 = __toESM(require("react"));
|
|
3431
3411
|
|
|
3432
3412
|
// src/useGlobalDarkMode.ts
|
|
3433
|
-
var import_react4 = __toESM(require("react"));
|
|
3434
|
-
var useSyncExternalStore = import_react4.default.useSyncExternalStore ?? function useSyncExternalStoreFallback(subscribe, getSnapshot, _getServerSnapshot) {
|
|
3435
|
-
const [, forceUpdate] = import_react4.default.useReducer((n) => n + 1, 0);
|
|
3436
|
-
import_react4.default.useEffect(() => subscribe(forceUpdate), [subscribe]);
|
|
3437
|
-
return getSnapshot();
|
|
3438
|
-
};
|
|
3439
3413
|
function useGlobalDarkMode() {
|
|
3440
3414
|
return useSyncExternalStore(
|
|
3441
3415
|
subscribeGlobalDarkMode,
|
|
@@ -3446,12 +3420,6 @@ function useGlobalDarkMode() {
|
|
|
3446
3420
|
}
|
|
3447
3421
|
|
|
3448
3422
|
// src/useGlobalWidth.ts
|
|
3449
|
-
var import_react5 = __toESM(require("react"));
|
|
3450
|
-
var useSyncExternalStore2 = import_react5.default.useSyncExternalStore ?? function useSyncExternalStoreFallback2(subscribe, getSnapshot, _getServerSnapshot) {
|
|
3451
|
-
const [, forceUpdate] = import_react5.default.useReducer((n) => n + 1, 0);
|
|
3452
|
-
import_react5.default.useEffect(() => subscribe(forceUpdate), [subscribe]);
|
|
3453
|
-
return getSnapshot();
|
|
3454
|
-
};
|
|
3455
3423
|
var NOOP_SUB = (_) => () => {
|
|
3456
3424
|
};
|
|
3457
3425
|
var ZERO_SNAP = () => 0;
|
|
@@ -3485,14 +3453,14 @@ function getWebWidth() {
|
|
|
3485
3453
|
return typeof window !== "undefined" ? window.innerWidth : 0;
|
|
3486
3454
|
}
|
|
3487
3455
|
function useGlobalWidth() {
|
|
3488
|
-
return
|
|
3456
|
+
return useSyncExternalStore(
|
|
3489
3457
|
isWeb ? subscribeWebWidth : subscribeGlobalWidth,
|
|
3490
3458
|
isWeb ? getWebWidth : getGlobalWidth,
|
|
3491
3459
|
ZERO_SNAP
|
|
3492
3460
|
);
|
|
3493
3461
|
}
|
|
3494
3462
|
function useConditionalWidth(active) {
|
|
3495
|
-
return
|
|
3463
|
+
return useSyncExternalStore(
|
|
3496
3464
|
active ? isWeb ? subscribeWebWidth : subscribeGlobalWidth : NOOP_SUB,
|
|
3497
3465
|
active ? isWeb ? getWebWidth : getGlobalWidth : ZERO_SNAP,
|
|
3498
3466
|
ZERO_SNAP
|
|
@@ -3520,6 +3488,42 @@ function hasInteractiveBuckets(resolved) {
|
|
|
3520
3488
|
}
|
|
3521
3489
|
return false;
|
|
3522
3490
|
}
|
|
3491
|
+
function chain(original, extra) {
|
|
3492
|
+
return (...args) => {
|
|
3493
|
+
original?.(...args);
|
|
3494
|
+
extra();
|
|
3495
|
+
};
|
|
3496
|
+
}
|
|
3497
|
+
function stripInternalMarkers(s) {
|
|
3498
|
+
delete s.__divideX;
|
|
3499
|
+
delete s.__divideY;
|
|
3500
|
+
delete s.__divideColor;
|
|
3501
|
+
delete s.__divideStyle;
|
|
3502
|
+
delete s.__keyframe;
|
|
3503
|
+
}
|
|
3504
|
+
function stripWebOnlyProps(s) {
|
|
3505
|
+
if (s.display === "grid" || s.display === "inline-grid") delete s.display;
|
|
3506
|
+
delete s.gridTemplateColumns;
|
|
3507
|
+
delete s.gridTemplateRows;
|
|
3508
|
+
delete s.gridColumn;
|
|
3509
|
+
delete s.gridRow;
|
|
3510
|
+
delete s.gridArea;
|
|
3511
|
+
delete s.gridColumnStart;
|
|
3512
|
+
delete s.gridColumnEnd;
|
|
3513
|
+
delete s.gridRowStart;
|
|
3514
|
+
delete s.gridRowEnd;
|
|
3515
|
+
delete s.gridAutoFlow;
|
|
3516
|
+
delete s.gridAutoColumns;
|
|
3517
|
+
delete s.gridAutoRows;
|
|
3518
|
+
delete s.placeItems;
|
|
3519
|
+
delete s.placeContent;
|
|
3520
|
+
delete s.justifyItems;
|
|
3521
|
+
delete s.placeSelf;
|
|
3522
|
+
delete s.justifySelf;
|
|
3523
|
+
if (s.position === "sticky" || s.position === "fixed" || s.position === "static") {
|
|
3524
|
+
delete s.position;
|
|
3525
|
+
}
|
|
3526
|
+
}
|
|
3523
3527
|
|
|
3524
3528
|
// src/web-substitute.ts
|
|
3525
3529
|
var _rnToHtml = {
|
|
@@ -3769,13 +3773,11 @@ function transformToWebProps(originalName, tag, props) {
|
|
|
3769
3773
|
continue;
|
|
3770
3774
|
}
|
|
3771
3775
|
if (k === "resizeMode") {
|
|
3772
|
-
|
|
3773
|
-
out.style = { ...existing, objectFit: _resizeModeMap[v] ?? "cover" };
|
|
3776
|
+
pendingStyle = { ...pendingStyle ?? {}, objectFit: _resizeModeMap[v] ?? "cover" };
|
|
3774
3777
|
continue;
|
|
3775
3778
|
}
|
|
3776
3779
|
if (k === "contentFit") {
|
|
3777
|
-
|
|
3778
|
-
out.style = { ...existing, objectFit: v };
|
|
3780
|
+
pendingStyle = { ...pendingStyle ?? {}, objectFit: v };
|
|
3779
3781
|
continue;
|
|
3780
3782
|
}
|
|
3781
3783
|
if (k === "defaultSource") continue;
|
|
@@ -3800,7 +3802,7 @@ function transformToWebProps(originalName, tag, props) {
|
|
|
3800
3802
|
|
|
3801
3803
|
// src/styled.tsx
|
|
3802
3804
|
function styled(Component, baseClasses = "") {
|
|
3803
|
-
const Styled = (0,
|
|
3805
|
+
const Styled = (0, import_react5.forwardRef)(
|
|
3804
3806
|
(props, ref) => {
|
|
3805
3807
|
const {
|
|
3806
3808
|
kb: extraClasses,
|
|
@@ -3810,6 +3812,7 @@ function styled(Component, baseClasses = "") {
|
|
|
3810
3812
|
onPointerDown,
|
|
3811
3813
|
onPointerUp,
|
|
3812
3814
|
onPointerLeave,
|
|
3815
|
+
onPointerCancel,
|
|
3813
3816
|
onMouseEnter,
|
|
3814
3817
|
onMouseLeave,
|
|
3815
3818
|
onFocus,
|
|
@@ -3820,52 +3823,26 @@ function styled(Component, baseClasses = "") {
|
|
|
3820
3823
|
const checked = !!props.checked;
|
|
3821
3824
|
const { config } = useTheme();
|
|
3822
3825
|
const isDark = useGlobalDarkMode();
|
|
3823
|
-
const [pressed, setPressed] = (0,
|
|
3824
|
-
const [hovered, setHovered] = (0,
|
|
3825
|
-
const [focused, setFocused] = (0,
|
|
3826
|
-
const handlePressIn = (0,
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
const
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
const
|
|
3835
|
-
|
|
3836
|
-
onPointerDown?.(e);
|
|
3837
|
-
}, [onPointerDown]);
|
|
3838
|
-
const handlePointerUp = (0, import_react6.useCallback)((e) => {
|
|
3839
|
-
setPressed(false);
|
|
3840
|
-
onPointerUp?.(e);
|
|
3841
|
-
}, [onPointerUp]);
|
|
3842
|
-
const handlePointerLeave = (0, import_react6.useCallback)((e) => {
|
|
3843
|
-
setPressed(false);
|
|
3844
|
-
onPointerLeave?.(e);
|
|
3845
|
-
}, [onPointerLeave]);
|
|
3846
|
-
const handleMouseEnter = (0, import_react6.useCallback)((e) => {
|
|
3847
|
-
setHovered(true);
|
|
3848
|
-
onMouseEnter?.(e);
|
|
3849
|
-
}, [onMouseEnter]);
|
|
3850
|
-
const handleMouseLeave = (0, import_react6.useCallback)((e) => {
|
|
3851
|
-
setHovered(false);
|
|
3852
|
-
onMouseLeave?.(e);
|
|
3853
|
-
}, [onMouseLeave]);
|
|
3854
|
-
const handleFocus = (0, import_react6.useCallback)((e) => {
|
|
3855
|
-
setFocused(true);
|
|
3856
|
-
onFocus?.(e);
|
|
3857
|
-
}, [onFocus]);
|
|
3858
|
-
const handleBlur = (0, import_react6.useCallback)((e) => {
|
|
3859
|
-
setFocused(false);
|
|
3860
|
-
onBlur?.(e);
|
|
3861
|
-
}, [onBlur]);
|
|
3826
|
+
const [pressed, setPressed] = (0, import_react5.useState)(false);
|
|
3827
|
+
const [hovered, setHovered] = (0, import_react5.useState)(false);
|
|
3828
|
+
const [focused, setFocused] = (0, import_react5.useState)(false);
|
|
3829
|
+
const handlePressIn = (0, import_react5.useCallback)(chain(onPressIn, () => setPressed(true)), [onPressIn]);
|
|
3830
|
+
const handlePressOut = (0, import_react5.useCallback)(chain(onPressOut, () => setPressed(false)), [onPressOut]);
|
|
3831
|
+
const handlePointerDown = (0, import_react5.useCallback)(chain(onPointerDown, () => setPressed(true)), [onPointerDown]);
|
|
3832
|
+
const handlePointerUp = (0, import_react5.useCallback)(chain(onPointerUp, () => setPressed(false)), [onPointerUp]);
|
|
3833
|
+
const handlePointerLeave = (0, import_react5.useCallback)(chain(onPointerLeave, () => setPressed(false)), [onPointerLeave]);
|
|
3834
|
+
const handlePointerCancel = (0, import_react5.useCallback)(chain(onPointerCancel, () => setPressed(false)), [onPointerCancel]);
|
|
3835
|
+
const handleMouseEnter = (0, import_react5.useCallback)(chain(onMouseEnter, () => setHovered(true)), [onMouseEnter]);
|
|
3836
|
+
const handleMouseLeave = (0, import_react5.useCallback)(chain(onMouseLeave, () => setHovered(false)), [onMouseLeave]);
|
|
3837
|
+
const handleFocus = (0, import_react5.useCallback)(chain(onFocus, () => setFocused(true)), [onFocus]);
|
|
3838
|
+
const handleBlur = (0, import_react5.useCallback)(chain(onBlur, () => setFocused(false)), [onBlur]);
|
|
3862
3839
|
const combined = extraClasses ? `${baseClasses} ${extraClasses}` : baseClasses;
|
|
3863
|
-
const resolved = (0,
|
|
3864
|
-
const hasInteractive = (0,
|
|
3840
|
+
const resolved = (0, import_react5.useMemo)(() => resolve(combined, config.theme, config.darkMode), [combined, config.theme, config.darkMode]);
|
|
3841
|
+
const hasInteractive = (0, import_react5.useMemo)(() => hasInteractiveBuckets(resolved), [resolved]);
|
|
3865
3842
|
const needsWidth = hasResponsiveBuckets(resolved);
|
|
3866
3843
|
const width = useConditionalWidth(needsWidth);
|
|
3867
3844
|
const breakpoints = needsWidth ? getActiveBreakpoints(width) : EMPTY_BREAKPOINTS;
|
|
3868
|
-
const computedStyle = (0,
|
|
3845
|
+
const computedStyle = (0, import_react5.useMemo)(
|
|
3869
3846
|
() => isWeb ? {} : flatten(resolved, isDark, { pressed, hover: hovered, focus: focused, disabled, checked }, breakpoints),
|
|
3870
3847
|
[resolved, isDark, pressed, hovered, focused, disabled, checked, width]
|
|
3871
3848
|
// eslint-disable-line react-hooks/exhaustive-deps
|
|
@@ -3876,7 +3853,7 @@ function styled(Component, baseClasses = "") {
|
|
|
3876
3853
|
const effectiveComponent = webTag ?? Component;
|
|
3877
3854
|
const componentName2 = Component.displayName ?? Component.name ?? "";
|
|
3878
3855
|
const effectiveRest = webTag && componentName2 ? transformToWebProps(componentName2, webTag, rest) : rest;
|
|
3879
|
-
return
|
|
3856
|
+
return import_react5.default.createElement(effectiveComponent, {
|
|
3880
3857
|
ref,
|
|
3881
3858
|
...effectiveRest,
|
|
3882
3859
|
style: finalStyle,
|
|
@@ -3886,7 +3863,7 @@ function styled(Component, baseClasses = "") {
|
|
|
3886
3863
|
// Always forward user-provided handlers to avoid silently swallowing them.
|
|
3887
3864
|
// onPressIn/onPressOut are forwarded on web too (not just native) since
|
|
3888
3865
|
// react-native-web components rely on receiving them directly.
|
|
3889
|
-
...isWeb ? hasInteractive ? { onPointerDown: handlePointerDown, onPointerUp: handlePointerUp, onPointerLeave: handlePointerLeave, onPointerCancel:
|
|
3866
|
+
...isWeb ? hasInteractive ? { onPointerDown: handlePointerDown, onPointerUp: handlePointerUp, onPointerLeave: handlePointerLeave, onPointerCancel: handlePointerCancel, onPressIn, onPressOut } : { onPointerDown, onPointerUp, onPointerLeave, onPointerCancel, onPressIn, onPressOut } : hasInteractive ? { onPressIn: handlePressIn, onPressOut: handlePressOut } : { onPressIn, onPressOut },
|
|
3890
3867
|
onMouseEnter: hasInteractive ? handleMouseEnter : onMouseEnter,
|
|
3891
3868
|
onMouseLeave: hasInteractive ? handleMouseLeave : onMouseLeave,
|
|
3892
3869
|
onFocus: hasInteractive ? handleFocus : onFocus,
|
|
@@ -3900,12 +3877,12 @@ function styled(Component, baseClasses = "") {
|
|
|
3900
3877
|
}
|
|
3901
3878
|
|
|
3902
3879
|
// src/useStyles.ts
|
|
3903
|
-
var
|
|
3880
|
+
var import_react6 = require("react");
|
|
3904
3881
|
function useStyles(classString, state = {}) {
|
|
3905
3882
|
const { isDark, config } = useTheme();
|
|
3906
3883
|
const width = useGlobalWidth();
|
|
3907
3884
|
const normalised = Array.isArray(classString) ? classString.join(" ") : classString;
|
|
3908
|
-
return (0,
|
|
3885
|
+
return (0, import_react6.useMemo)(() => {
|
|
3909
3886
|
const resolved = resolve(normalised, config.theme, config.darkMode);
|
|
3910
3887
|
const breakpoints = getActiveBreakpoints(width);
|
|
3911
3888
|
return flatten(resolved, isDark, state, breakpoints);
|
|
@@ -3914,20 +3891,20 @@ function useStyles(classString, state = {}) {
|
|
|
3914
3891
|
function useResolvedStyle(classString) {
|
|
3915
3892
|
const { config } = useTheme();
|
|
3916
3893
|
const normalised = Array.isArray(classString) ? classString.join(" ") : classString;
|
|
3917
|
-
return (0,
|
|
3894
|
+
return (0, import_react6.useMemo)(
|
|
3918
3895
|
() => resolve(normalised, config.theme, config.darkMode),
|
|
3919
3896
|
[normalised, config]
|
|
3920
3897
|
);
|
|
3921
3898
|
}
|
|
3922
3899
|
|
|
3923
3900
|
// src/useBreakpoint.ts
|
|
3924
|
-
var
|
|
3901
|
+
var import_react7 = require("react");
|
|
3925
3902
|
function useBreakpoint() {
|
|
3926
3903
|
const { config } = useTheme();
|
|
3927
3904
|
const width = useGlobalWidth();
|
|
3928
3905
|
const screens = config.theme.screens;
|
|
3929
|
-
const sorted = (0,
|
|
3930
|
-
() => Object.entries(screens).
|
|
3906
|
+
const sorted = (0, import_react7.useMemo)(
|
|
3907
|
+
() => Object.entries(screens).map(([name, v]) => [name, typeof v === "number" ? v : parseInt(String(v), 10)]).filter(([, minW]) => !Number.isNaN(minW)).sort(([, a], [, b]) => b - a),
|
|
3931
3908
|
[screens]
|
|
3932
3909
|
);
|
|
3933
3910
|
for (const [name, minW] of sorted) {
|
|
@@ -3939,24 +3916,19 @@ function useResponsive() {
|
|
|
3939
3916
|
const { config } = useTheme();
|
|
3940
3917
|
const width = useGlobalWidth();
|
|
3941
3918
|
const screens = config.theme.screens;
|
|
3942
|
-
return (0,
|
|
3919
|
+
return (0, import_react7.useMemo)(() => {
|
|
3943
3920
|
const result = {};
|
|
3944
|
-
for (const [name,
|
|
3945
|
-
|
|
3921
|
+
for (const [name, v] of Object.entries(screens)) {
|
|
3922
|
+
const minW = typeof v === "number" ? v : parseInt(String(v), 10);
|
|
3923
|
+
if (!Number.isNaN(minW)) result[name] = width >= minW;
|
|
3946
3924
|
}
|
|
3947
3925
|
return result;
|
|
3948
3926
|
}, [screens, width]);
|
|
3949
3927
|
}
|
|
3950
3928
|
|
|
3951
3929
|
// src/InteractiveWrapper.tsx
|
|
3952
|
-
var
|
|
3953
|
-
|
|
3954
|
-
return (...args) => {
|
|
3955
|
-
original?.(...args);
|
|
3956
|
-
extra();
|
|
3957
|
-
};
|
|
3958
|
-
}
|
|
3959
|
-
var InteractiveWrapper = (0, import_react9.forwardRef)(
|
|
3930
|
+
var import_react8 = __toESM(require("react"));
|
|
3931
|
+
var InteractiveWrapper = (0, import_react8.forwardRef)(
|
|
3960
3932
|
function InteractiveWrapper2({
|
|
3961
3933
|
Component,
|
|
3962
3934
|
resolvedStyle,
|
|
@@ -3967,6 +3939,7 @@ var InteractiveWrapper = (0, import_react9.forwardRef)(
|
|
|
3967
3939
|
onPointerDown,
|
|
3968
3940
|
onPointerUp,
|
|
3969
3941
|
onPointerLeave,
|
|
3942
|
+
onPointerCancel,
|
|
3970
3943
|
onMouseEnter,
|
|
3971
3944
|
onMouseLeave,
|
|
3972
3945
|
onFocus,
|
|
@@ -3977,51 +3950,26 @@ var InteractiveWrapper = (0, import_react9.forwardRef)(
|
|
|
3977
3950
|
const needsWidth = hasResponsiveBuckets(resolvedStyle);
|
|
3978
3951
|
const width = useConditionalWidth(needsWidth);
|
|
3979
3952
|
const breakpoints = needsWidth ? getActiveBreakpoints(width) : EMPTY_BREAKPOINTS;
|
|
3980
|
-
const [pressed, setPressed] = (0,
|
|
3981
|
-
const [hovered, setHovered] = (0,
|
|
3982
|
-
const [focused, setFocused] = (0,
|
|
3983
|
-
const handlePressIn = (0,
|
|
3984
|
-
const handlePressOut = (0,
|
|
3985
|
-
const handlePointerDown = (0,
|
|
3986
|
-
const handlePointerUp = (0,
|
|
3987
|
-
const handlePointerLeave = (0,
|
|
3988
|
-
const
|
|
3989
|
-
const
|
|
3990
|
-
const
|
|
3991
|
-
const
|
|
3953
|
+
const [pressed, setPressed] = (0, import_react8.useState)(false);
|
|
3954
|
+
const [hovered, setHovered] = (0, import_react8.useState)(false);
|
|
3955
|
+
const [focused, setFocused] = (0, import_react8.useState)(false);
|
|
3956
|
+
const handlePressIn = (0, import_react8.useCallback)(chain(onPressIn, () => setPressed(true)), [onPressIn]);
|
|
3957
|
+
const handlePressOut = (0, import_react8.useCallback)(chain(onPressOut, () => setPressed(false)), [onPressOut]);
|
|
3958
|
+
const handlePointerDown = (0, import_react8.useCallback)(chain(onPointerDown, () => setPressed(true)), [onPointerDown]);
|
|
3959
|
+
const handlePointerUp = (0, import_react8.useCallback)(chain(onPointerUp, () => setPressed(false)), [onPointerUp]);
|
|
3960
|
+
const handlePointerLeave = (0, import_react8.useCallback)(chain(onPointerLeave, () => setPressed(false)), [onPointerLeave]);
|
|
3961
|
+
const handlePointerCancel = (0, import_react8.useCallback)(chain(onPointerCancel, () => setPressed(false)), [onPointerCancel]);
|
|
3962
|
+
const handleMouseEnter = (0, import_react8.useCallback)(chain(onMouseEnter, () => setHovered(true)), [onMouseEnter]);
|
|
3963
|
+
const handleMouseLeave = (0, import_react8.useCallback)(chain(onMouseLeave, () => setHovered(false)), [onMouseLeave]);
|
|
3964
|
+
const handleFocus = (0, import_react8.useCallback)(chain(onFocus, () => setFocused(true)), [onFocus]);
|
|
3965
|
+
const handleBlur = (0, import_react8.useCallback)(chain(onBlur, () => setFocused(false)), [onBlur]);
|
|
3992
3966
|
const { children, disabled, checked, ...restForComponent } = rest;
|
|
3993
|
-
const computedStyle = (0,
|
|
3967
|
+
const computedStyle = (0, import_react8.useMemo)(
|
|
3994
3968
|
() => {
|
|
3995
3969
|
if (isWeb) return {};
|
|
3996
3970
|
const s = flatten(resolvedStyle, isDark, { pressed, hover: hovered, focus: focused, disabled: !!disabled, checked: !!checked }, breakpoints);
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
delete s.__divideColor;
|
|
4000
|
-
delete s.__divideStyle;
|
|
4001
|
-
delete s.__keyframe;
|
|
4002
|
-
if (typeof Component !== "string") {
|
|
4003
|
-
if (s.display === "grid" || s.display === "inline-grid") delete s.display;
|
|
4004
|
-
delete s.gridTemplateColumns;
|
|
4005
|
-
delete s.gridTemplateRows;
|
|
4006
|
-
delete s.gridColumn;
|
|
4007
|
-
delete s.gridRow;
|
|
4008
|
-
delete s.gridArea;
|
|
4009
|
-
delete s.gridColumnStart;
|
|
4010
|
-
delete s.gridColumnEnd;
|
|
4011
|
-
delete s.gridRowStart;
|
|
4012
|
-
delete s.gridRowEnd;
|
|
4013
|
-
delete s.gridAutoFlow;
|
|
4014
|
-
delete s.gridAutoColumns;
|
|
4015
|
-
delete s.gridAutoRows;
|
|
4016
|
-
delete s.placeItems;
|
|
4017
|
-
delete s.placeContent;
|
|
4018
|
-
delete s.justifyItems;
|
|
4019
|
-
delete s.placeSelf;
|
|
4020
|
-
delete s.justifySelf;
|
|
4021
|
-
if (s.position === "sticky" || s.position === "fixed" || s.position === "static") {
|
|
4022
|
-
delete s.position;
|
|
4023
|
-
}
|
|
4024
|
-
}
|
|
3971
|
+
stripInternalMarkers(s);
|
|
3972
|
+
if (typeof Component !== "string") stripWebOnlyProps(s);
|
|
4025
3973
|
return s;
|
|
4026
3974
|
},
|
|
4027
3975
|
[resolvedStyle, isDark, pressed, hovered, focused, width, disabled, checked]
|
|
@@ -4038,13 +3986,13 @@ var InteractiveWrapper = (0, import_react9.forwardRef)(
|
|
|
4038
3986
|
// On web, onPointerDown/Up drive the wrapper's own pressed state (covers mouse + touch),
|
|
4039
3987
|
// but onPressIn/onPressOut are still forwarded unchanged — react-native-web components
|
|
4040
3988
|
// (and any component that accepts both prop names) depend on receiving them directly.
|
|
4041
|
-
...!isNative ? { onPointerDown: handlePointerDown, onPointerUp: handlePointerUp, onPointerLeave: handlePointerLeave, onPointerCancel:
|
|
3989
|
+
...!isNative ? { onPointerDown: handlePointerDown, onPointerUp: handlePointerUp, onPointerLeave: handlePointerLeave, onPointerCancel: handlePointerCancel, onPressIn, onPressOut } : { onPressIn: handlePressIn, onPressOut: handlePressOut },
|
|
4042
3990
|
onMouseEnter: handleMouseEnter,
|
|
4043
3991
|
onMouseLeave: handleMouseLeave,
|
|
4044
3992
|
onFocus: handleFocus,
|
|
4045
3993
|
onBlur: handleBlur
|
|
4046
3994
|
};
|
|
4047
|
-
return Array.isArray(children) ?
|
|
3995
|
+
return Array.isArray(children) ? import_react8.default.createElement(Component, componentProps, ...children) : import_react8.default.createElement(Component, componentProps, children);
|
|
4048
3996
|
}
|
|
4049
3997
|
);
|
|
4050
3998
|
InteractiveWrapper.displayName = "Kbach.InteractiveWrapper";
|
|
@@ -4067,6 +4015,7 @@ function cx(...classes) {
|
|
|
4067
4015
|
ThemeContext,
|
|
4068
4016
|
ThemeProvider,
|
|
4069
4017
|
buildConfig,
|
|
4018
|
+
clearCache,
|
|
4070
4019
|
cx,
|
|
4071
4020
|
defaultColors,
|
|
4072
4021
|
defaultTheme,
|
|
@@ -4080,6 +4029,7 @@ function cx(...classes) {
|
|
|
4080
4029
|
parseClasses,
|
|
4081
4030
|
registerWebElement,
|
|
4082
4031
|
resolve,
|
|
4032
|
+
setResolveTarget,
|
|
4083
4033
|
splitClassTokens,
|
|
4084
4034
|
styled,
|
|
4085
4035
|
updateConfig,
|