@kbach/react-native 1.0.0-beta.13 → 1.0.0-beta.15
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 +50 -0
- package/dist/chunk-AXGAYOQ7.mjs +192 -0
- package/dist/{chunk-4DQXTAM3.mjs → chunk-EMZ47OSG.mjs} +43 -6
- package/dist/{chunk-GU6DH6UE.mjs → chunk-UNZ6PQVO.mjs} +1 -1
- package/dist/{chunk-6QFPLRSP.mjs → chunk-VD233W3L.mjs} +1 -1
- package/dist/darkModeStore.js +112 -0
- package/dist/index.js +36 -448
- package/dist/index.web.js +34 -447
- package/dist/index.web.mjs +1 -1
- package/dist/jsx-dev-runtime.js +48 -408
- package/dist/jsx-dev-runtime.mjs +2 -2
- package/dist/jsx-dev-runtime.web.js +7 -396
- package/dist/jsx-dev-runtime.web.mjs +3 -3
- package/dist/jsx-runtime.js +48 -408
- package/dist/jsx-runtime.mjs +2 -2
- package/dist/jsx-runtime.web.js +4 -354
- package/dist/jsx-runtime.web.mjs +2 -2
- package/dist/theme.js +396 -0
- package/package.json +3 -3
- package/dist/chunk-ZB2UU6EO.mjs +0 -192
- package/dist/index.d.ts +0 -83
- package/dist/index.web.d.ts +0 -15
- package/dist/jsx-dev-runtime.d.ts +0 -10
- package/dist/jsx-dev-runtime.web.d.ts +0 -10
- package/dist/jsx-runtime.d.ts +0 -7
- package/dist/jsx-runtime.web.d.ts +0 -7
- package/dist/useColors-C6jyCLuG.d.ts +0 -239
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
getGlobalDarkMode
|
|
2
|
+
getGlobalDarkMode,
|
|
3
|
+
subscribeGlobalDarkMode
|
|
3
4
|
} from "./chunk-RBJXE32L.mjs";
|
|
5
|
+
import {
|
|
6
|
+
getTheme
|
|
7
|
+
} from "./chunk-HK6PDJJK.mjs";
|
|
4
8
|
|
|
5
9
|
// src/jsxRuntimeCore.ts
|
|
6
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
-
import { Fragment } from "react";
|
|
8
|
-
import { Pressable } from "react-native";
|
|
11
|
+
import { Fragment, useSyncExternalStore } from "react";
|
|
12
|
+
import { Pressable, useWindowDimensions } from "react-native";
|
|
9
13
|
function makeElement(isStaticChildren, type, props, key) {
|
|
10
14
|
return (isStaticChildren ? _jsxs : _jsx)(type, props, key);
|
|
11
15
|
}
|
|
@@ -20,9 +24,37 @@ function resolvedStyleFor(resolveStyle, classStrRaw, userStyle, pressed) {
|
|
|
20
24
|
return [resolved, userStyle];
|
|
21
25
|
}
|
|
22
26
|
var DARK_MODIFIER_RE = /(^|\s)dark:/;
|
|
27
|
+
var BREAKPOINT_MODIFIER_RE = /(^|\s)(sm|md|lg|xl|2xl):/;
|
|
28
|
+
var BREAKPOINT_MODIFIER_MATCH_RE = /(?:^|\s)(sm|md|lg|xl|2xl):/g;
|
|
23
29
|
function darkModeKeySuffix(classStrRaw) {
|
|
24
30
|
return DARK_MODIFIER_RE.test(classStrRaw) ? `:kb-dark-${getGlobalDarkMode()}` : "";
|
|
25
31
|
}
|
|
32
|
+
function breakpointKeySuffix(classStrRaw, width) {
|
|
33
|
+
const matches = classStrRaw.match(BREAKPOINT_MODIFIER_MATCH_RE);
|
|
34
|
+
if (!matches) {
|
|
35
|
+
return "";
|
|
36
|
+
}
|
|
37
|
+
const screens = getTheme().screens;
|
|
38
|
+
const present = Array.from(new Set(matches.map((m) => m.trim().slice(0, -1))));
|
|
39
|
+
const state = present.map((name) => screens[name] !== void 0 && width >= screens[name] ? "1" : "0").join("");
|
|
40
|
+
return `:kb-bp-${state}`;
|
|
41
|
+
}
|
|
42
|
+
function ReactiveElement({
|
|
43
|
+
hostType,
|
|
44
|
+
hostRest,
|
|
45
|
+
classStrRaw,
|
|
46
|
+
userStyle,
|
|
47
|
+
resolveStyle,
|
|
48
|
+
elementKey,
|
|
49
|
+
isStaticChildren
|
|
50
|
+
}) {
|
|
51
|
+
useSyncExternalStore(subscribeGlobalDarkMode, getGlobalDarkMode);
|
|
52
|
+
const { width } = useWindowDimensions();
|
|
53
|
+
const finalStyle = hostType === Pressable ? (state) => resolvedStyleFor(resolveStyle, classStrRaw, userStyle, state.pressed) : resolvedStyleFor(resolveStyle, classStrRaw, userStyle, false);
|
|
54
|
+
const suffix = darkModeKeySuffix(classStrRaw) + breakpointKeySuffix(classStrRaw, width);
|
|
55
|
+
const finalKey = suffix ? `${elementKey ?? ""}${suffix}` : elementKey;
|
|
56
|
+
return makeElement(isStaticChildren, hostType, { ...hostRest, style: finalStyle }, finalKey);
|
|
57
|
+
}
|
|
26
58
|
function processElement(resolveStyle, type, rawProps, key, isStaticChildren) {
|
|
27
59
|
if (type === null || typeof type === "symbol" || !rawProps) {
|
|
28
60
|
return makeElement(isStaticChildren, type, rawProps ?? {}, key);
|
|
@@ -31,10 +63,15 @@ function processElement(resolveStyle, type, rawProps, key, isStaticChildren) {
|
|
|
31
63
|
if (typeof classStrRaw !== "string") {
|
|
32
64
|
return makeElement(isStaticChildren, type, rawProps, key);
|
|
33
65
|
}
|
|
66
|
+
if (DARK_MODIFIER_RE.test(classStrRaw) || BREAKPOINT_MODIFIER_RE.test(classStrRaw)) {
|
|
67
|
+
return _jsx(
|
|
68
|
+
ReactiveElement,
|
|
69
|
+
{ hostType: type, hostRest: rest, classStrRaw, userStyle, resolveStyle, elementKey: key, isStaticChildren },
|
|
70
|
+
key
|
|
71
|
+
);
|
|
72
|
+
}
|
|
34
73
|
const finalStyle = type === Pressable ? (state) => resolvedStyleFor(resolveStyle, classStrRaw, userStyle, state.pressed) : resolvedStyleFor(resolveStyle, classStrRaw, userStyle, false);
|
|
35
|
-
|
|
36
|
-
const finalKey = suffix ? `${key ?? ""}${suffix}` : key;
|
|
37
|
-
return makeElement(isStaticChildren, type, { ...rest, style: finalStyle }, finalKey);
|
|
74
|
+
return makeElement(isStaticChildren, type, { ...rest, style: finalStyle }, key);
|
|
38
75
|
}
|
|
39
76
|
function createJsxFunctions(resolveStyle) {
|
|
40
77
|
function jsx(type, props, key) {
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/darkModeStore.ts
|
|
21
|
+
var darkModeStore_exports = {};
|
|
22
|
+
__export(darkModeStore_exports, {
|
|
23
|
+
_resetForTests: () => _resetForTests,
|
|
24
|
+
_unsubscribeForTests: () => _unsubscribeForTests,
|
|
25
|
+
getGlobalDarkMode: () => getGlobalDarkMode,
|
|
26
|
+
getGlobalThemeMode: () => getGlobalThemeMode,
|
|
27
|
+
seedDefaultMode: () => seedDefaultMode,
|
|
28
|
+
setGlobalThemeMode: () => setGlobalThemeMode,
|
|
29
|
+
subscribeGlobalDarkMode: () => subscribeGlobalDarkMode,
|
|
30
|
+
toggleGlobalDarkMode: () => toggleGlobalDarkMode
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(darkModeStore_exports);
|
|
33
|
+
var import_react_native = require("react-native");
|
|
34
|
+
var import_theme = require("./theme");
|
|
35
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
36
|
+
function systemPrefersDark() {
|
|
37
|
+
return import_react_native.Appearance.getColorScheme() === "dark";
|
|
38
|
+
}
|
|
39
|
+
function resolveIsDark(m) {
|
|
40
|
+
return m === "system" ? systemPrefersDark() : m === "dark";
|
|
41
|
+
}
|
|
42
|
+
function applyToDom(dark) {
|
|
43
|
+
if (typeof document === "undefined") return;
|
|
44
|
+
const root = document.documentElement;
|
|
45
|
+
const strategy = (0, import_theme.getTheme)().darkMode;
|
|
46
|
+
if (strategy === "class") {
|
|
47
|
+
root.classList.toggle("dark", dark);
|
|
48
|
+
root.classList.toggle("light", !dark);
|
|
49
|
+
} else if (strategy === "attribute") {
|
|
50
|
+
root.setAttribute("data-theme", dark ? "dark" : "light");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
var mode = "system";
|
|
54
|
+
var isDark = resolveIsDark(mode);
|
|
55
|
+
applyToDom(isDark);
|
|
56
|
+
var hasExplicitChoice = false;
|
|
57
|
+
var subscription = import_react_native.Appearance.addChangeListener(({ colorScheme }) => {
|
|
58
|
+
if (mode !== "system") return;
|
|
59
|
+
isDark = colorScheme === "dark";
|
|
60
|
+
applyToDom(isDark);
|
|
61
|
+
notify();
|
|
62
|
+
});
|
|
63
|
+
function notify() {
|
|
64
|
+
for (const listener of listeners) listener();
|
|
65
|
+
}
|
|
66
|
+
function getGlobalDarkMode() {
|
|
67
|
+
return isDark;
|
|
68
|
+
}
|
|
69
|
+
function getGlobalThemeMode() {
|
|
70
|
+
return mode;
|
|
71
|
+
}
|
|
72
|
+
function setGlobalThemeMode(nextMode) {
|
|
73
|
+
mode = nextMode;
|
|
74
|
+
isDark = resolveIsDark(nextMode);
|
|
75
|
+
hasExplicitChoice = true;
|
|
76
|
+
applyToDom(isDark);
|
|
77
|
+
notify();
|
|
78
|
+
}
|
|
79
|
+
function toggleGlobalDarkMode() {
|
|
80
|
+
setGlobalThemeMode(isDark ? "light" : "dark");
|
|
81
|
+
}
|
|
82
|
+
function subscribeGlobalDarkMode(listener) {
|
|
83
|
+
listeners.add(listener);
|
|
84
|
+
return () => listeners.delete(listener);
|
|
85
|
+
}
|
|
86
|
+
function seedDefaultMode(fallback) {
|
|
87
|
+
if (hasExplicitChoice || mode === fallback) return;
|
|
88
|
+
mode = fallback;
|
|
89
|
+
isDark = resolveIsDark(fallback);
|
|
90
|
+
applyToDom(isDark);
|
|
91
|
+
notify();
|
|
92
|
+
}
|
|
93
|
+
function _resetForTests() {
|
|
94
|
+
mode = "system";
|
|
95
|
+
isDark = resolveIsDark(mode);
|
|
96
|
+
hasExplicitChoice = false;
|
|
97
|
+
listeners.clear();
|
|
98
|
+
}
|
|
99
|
+
function _unsubscribeForTests() {
|
|
100
|
+
subscription.remove();
|
|
101
|
+
}
|
|
102
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
+
0 && (module.exports = {
|
|
104
|
+
_resetForTests,
|
|
105
|
+
_unsubscribeForTests,
|
|
106
|
+
getGlobalDarkMode,
|
|
107
|
+
getGlobalThemeMode,
|
|
108
|
+
seedDefaultMode,
|
|
109
|
+
setGlobalThemeMode,
|
|
110
|
+
subscribeGlobalDarkMode,
|
|
111
|
+
toggleGlobalDarkMode
|
|
112
|
+
});
|