@umber-style/react-native 0.1.0-alpha.0 → 0.1.0-alpha.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/dist/CacheProvider.cjs +7 -0
- package/dist/CacheProvider.d.cts +4 -0
- package/dist/CacheProvider.d.mts +4 -0
- package/dist/CacheProvider.mjs +7 -0
- package/dist/ThemeValue.cjs +32 -15
- package/dist/ThemeValue.mjs +33 -16
- package/dist/calc.cjs +11 -8
- package/dist/calc.mjs +11 -8
- package/dist/createStyle.cjs +133 -29
- package/dist/createStyle.d.cts +7 -9
- package/dist/createStyle.d.mts +7 -9
- package/dist/createStyle.mjs +136 -32
- package/dist/defaultStyle.cjs +29 -3
- package/dist/defaultStyle.d.cts +15 -4
- package/dist/defaultStyle.d.mts +15 -4
- package/dist/defaultStyle.mjs +30 -4
- package/dist/index.cjs +11 -2
- package/dist/index.d.cts +10 -7
- package/dist/index.d.mts +10 -7
- package/dist/index.mjs +4 -3
- package/dist/mediaQuery.cjs +179 -0
- package/dist/mediaQuery.d.cts +1 -0
- package/dist/mediaQuery.mjs +178 -0
- package/dist/nativeTheme.cjs +51 -0
- package/dist/nativeTheme.d.cts +15 -0
- package/dist/nativeTheme.d.mts +15 -0
- package/dist/nativeTheme.mjs +50 -0
- package/dist/platform.mjs +1 -1
- package/dist/styled.cjs +95 -19
- package/dist/styled.mjs +96 -20
- package/dist/toNativeStyle.cjs +64 -15
- package/dist/toNativeStyle.mjs +65 -16
- package/dist/types.d.cts +78 -10
- package/dist/types.d.mts +78 -10
- package/dist/units.cjs +137 -0
- package/dist/units.mjs +133 -0
- package/dist/warnStyle.cjs +62 -18
- package/dist/warnStyle.mjs +61 -19
- package/dist/windowState.cjs +89 -0
- package/dist/windowState.d.cts +6 -0
- package/dist/windowState.d.mts +5 -0
- package/dist/windowState.mjs +85 -0
- package/package.json +3 -3
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
let react = require("react");
|
|
2
|
+
// src/CacheProvider.ts
|
|
3
|
+
/** `CacheProvider` on React Native: there is no CSS to write, so it renders its children and reads no cache. */
|
|
4
|
+
function CacheProvider({ children }) {
|
|
5
|
+
return (0, react.createElement)(react.Fragment, null, children);
|
|
6
|
+
}
|
|
7
|
+
exports.CacheProvider = CacheProvider;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ReactElement } from "react";
|
|
2
|
+
import { CacheProviderProps } from "./types.cjs";
|
|
3
|
+
/** `CacheProvider` on React Native: there is no CSS to write, so it renders its children and reads no cache. */
|
|
4
|
+
export declare function CacheProvider({ children }: CacheProviderProps): ReactElement;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ReactElement } from "react";
|
|
2
|
+
import { CacheProviderProps } from "./types.mjs";
|
|
3
|
+
/** `CacheProvider` on React Native: there is no CSS to write, so it renders its children and reads no cache. */
|
|
4
|
+
export declare function CacheProvider({ children }: CacheProviderProps): ReactElement;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Fragment, createElement } from "react";
|
|
2
|
+
// src/CacheProvider.ts
|
|
3
|
+
/** `CacheProvider` on React Native: there is no CSS to write, so it renders its children and reads no cache. */
|
|
4
|
+
function CacheProvider({ children }) {
|
|
5
|
+
return createElement(Fragment, null, children);
|
|
6
|
+
}
|
|
7
|
+
export { CacheProvider };
|
package/dist/ThemeValue.cjs
CHANGED
|
@@ -4,19 +4,41 @@ let _umber_style_core = require("@umber-style/core");
|
|
|
4
4
|
const require_conditions = require("./conditions.cjs");
|
|
5
5
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
6
6
|
// src/ThemeValue.tsx
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The contexts of the engine: the real theme values (`ThemeContext`, made here unless given; the base
|
|
9
|
+
* theme of `holder`, else an empty object, where there is no provider), and what a condition is matched
|
|
10
|
+
* against. A theme is held as React Native takes it: `convert` makes that of each theme object once, and
|
|
11
|
+
* the result is remembered for that object. A provider merges, and a function theme receives, the theme
|
|
12
|
+
* as it was given, not the converted one, so that one source does the same on both platforms.
|
|
13
|
+
*/
|
|
14
|
+
function createThemeValue(holder, convert, ThemeContext = (0, react.createContext)(void 0)) {
|
|
10
15
|
const ConditionContext = (0, react.createContext)(void 0);
|
|
16
|
+
const nativeByTheme = /* @__PURE__ */ new WeakMap();
|
|
17
|
+
const themeByNative = /* @__PURE__ */ new WeakMap();
|
|
18
|
+
/** `theme` converted, once for each theme object. */
|
|
19
|
+
const toNative = (theme) => {
|
|
20
|
+
let native = nativeByTheme.get(theme);
|
|
21
|
+
if (native === void 0) {
|
|
22
|
+
native = convert(theme);
|
|
23
|
+
nativeByTheme.set(theme, native);
|
|
24
|
+
themeByNative.set(native, theme);
|
|
25
|
+
}
|
|
26
|
+
return native;
|
|
27
|
+
};
|
|
28
|
+
/** The theme where no provider is above: the base theme, or the empty theme. */
|
|
29
|
+
const readOwnTheme = () => holder.baseTheme ?? _umber_style_core.EMPTY_THEME;
|
|
11
30
|
function ThemeValueProvider({ theme, colorScheme, children }) {
|
|
12
|
-
const
|
|
31
|
+
const above = (0, react.useContext)(ThemeContext);
|
|
32
|
+
const outer = above === void 0 ? holder.baseTheme : themeByNative.get(above) ?? above;
|
|
13
33
|
const outerScheme = (0, react.useContext)(ConditionContext)?.colorScheme;
|
|
14
|
-
const
|
|
34
|
+
const given = (0, react.useMemo)(() => (0, _umber_style_core.resolveThemeInput)(theme, outer ?? _umber_style_core.EMPTY_THEME), [theme, outer]);
|
|
35
|
+
holder.baseTheme ??= given;
|
|
36
|
+
const value = (0, react.useMemo)(() => toNative((0, _umber_style_core.mergeTheme)(outer, given)), [outer, given]);
|
|
15
37
|
const scheme = require_conditions.readSchemeName(colorScheme) ?? outerScheme;
|
|
16
38
|
const condition = (0, react.useMemo)(() => ({
|
|
17
|
-
theme,
|
|
39
|
+
theme: given,
|
|
18
40
|
colorScheme: scheme
|
|
19
|
-
}), [
|
|
41
|
+
}), [given, scheme]);
|
|
20
42
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ThemeContext.Provider, {
|
|
21
43
|
value,
|
|
22
44
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ConditionContext.Provider, {
|
|
@@ -25,14 +47,9 @@ function createThemeValue(holder) {
|
|
|
25
47
|
})
|
|
26
48
|
});
|
|
27
49
|
}
|
|
28
|
-
/** The theme
|
|
29
|
-
function useThemeValue() {
|
|
30
|
-
return (0, react.useContext)(ThemeContext) ?? holder.baseTheme;
|
|
31
|
-
}
|
|
50
|
+
/** The theme of the nearest provider, the base theme, or an empty object, converted. */
|
|
32
51
|
function useTheme() {
|
|
33
|
-
|
|
34
|
-
if (value === void 0) throw new Error(_umber_style_core.NO_THEME_MESSAGE);
|
|
35
|
-
return value;
|
|
52
|
+
return (0, react.useContext)(ThemeContext) ?? toNative(readOwnTheme());
|
|
36
53
|
}
|
|
37
54
|
/** What `when()` and `whenScheme()` keys are matched against: the nearest provider, or the base theme with no color scheme. */
|
|
38
55
|
function useCondition() {
|
|
@@ -42,9 +59,9 @@ function createThemeValue(holder) {
|
|
|
42
59
|
};
|
|
43
60
|
}
|
|
44
61
|
return {
|
|
62
|
+
ThemeContext,
|
|
45
63
|
ThemeValueProvider,
|
|
46
64
|
useTheme,
|
|
47
|
-
useThemeValue,
|
|
48
65
|
useCondition
|
|
49
66
|
};
|
|
50
67
|
}
|
package/dist/ThemeValue.mjs
CHANGED
|
@@ -1,22 +1,44 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { createContext, useContext, useMemo } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { EMPTY_THEME, mergeTheme, resolveThemeInput } from "@umber-style/core";
|
|
4
4
|
import { readSchemeName } from "./conditions.mjs";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
// src/ThemeValue.tsx
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The contexts of the engine: the real theme values (`ThemeContext`, made here unless given; the base
|
|
9
|
+
* theme of `holder`, else an empty object, where there is no provider), and what a condition is matched
|
|
10
|
+
* against. A theme is held as React Native takes it: `convert` makes that of each theme object once, and
|
|
11
|
+
* the result is remembered for that object. A provider merges, and a function theme receives, the theme
|
|
12
|
+
* as it was given, not the converted one, so that one source does the same on both platforms.
|
|
13
|
+
*/
|
|
14
|
+
function createThemeValue(holder, convert, ThemeContext = createContext(void 0)) {
|
|
10
15
|
const ConditionContext = createContext(void 0);
|
|
16
|
+
const nativeByTheme = /* @__PURE__ */ new WeakMap();
|
|
17
|
+
const themeByNative = /* @__PURE__ */ new WeakMap();
|
|
18
|
+
/** `theme` converted, once for each theme object. */
|
|
19
|
+
const toNative = (theme) => {
|
|
20
|
+
let native = nativeByTheme.get(theme);
|
|
21
|
+
if (native === void 0) {
|
|
22
|
+
native = convert(theme);
|
|
23
|
+
nativeByTheme.set(theme, native);
|
|
24
|
+
themeByNative.set(native, theme);
|
|
25
|
+
}
|
|
26
|
+
return native;
|
|
27
|
+
};
|
|
28
|
+
/** The theme where no provider is above: the base theme, or the empty theme. */
|
|
29
|
+
const readOwnTheme = () => holder.baseTheme ?? EMPTY_THEME;
|
|
11
30
|
function ThemeValueProvider({ theme, colorScheme, children }) {
|
|
12
|
-
const
|
|
31
|
+
const above = useContext(ThemeContext);
|
|
32
|
+
const outer = above === void 0 ? holder.baseTheme : themeByNative.get(above) ?? above;
|
|
13
33
|
const outerScheme = useContext(ConditionContext)?.colorScheme;
|
|
14
|
-
const
|
|
34
|
+
const given = useMemo(() => resolveThemeInput(theme, outer ?? EMPTY_THEME), [theme, outer]);
|
|
35
|
+
holder.baseTheme ??= given;
|
|
36
|
+
const value = useMemo(() => toNative(mergeTheme(outer, given)), [outer, given]);
|
|
15
37
|
const scheme = readSchemeName(colorScheme) ?? outerScheme;
|
|
16
38
|
const condition = useMemo(() => ({
|
|
17
|
-
theme,
|
|
39
|
+
theme: given,
|
|
18
40
|
colorScheme: scheme
|
|
19
|
-
}), [
|
|
41
|
+
}), [given, scheme]);
|
|
20
42
|
return /* @__PURE__ */ jsx(ThemeContext.Provider, {
|
|
21
43
|
value,
|
|
22
44
|
children: /* @__PURE__ */ jsx(ConditionContext.Provider, {
|
|
@@ -25,14 +47,9 @@ function createThemeValue(holder) {
|
|
|
25
47
|
})
|
|
26
48
|
});
|
|
27
49
|
}
|
|
28
|
-
/** The theme
|
|
29
|
-
function useThemeValue() {
|
|
30
|
-
return useContext(ThemeContext) ?? holder.baseTheme;
|
|
31
|
-
}
|
|
50
|
+
/** The theme of the nearest provider, the base theme, or an empty object, converted. */
|
|
32
51
|
function useTheme() {
|
|
33
|
-
|
|
34
|
-
if (value === void 0) throw new Error(NO_THEME_MESSAGE);
|
|
35
|
-
return value;
|
|
52
|
+
return useContext(ThemeContext) ?? toNative(readOwnTheme());
|
|
36
53
|
}
|
|
37
54
|
/** What `when()` and `whenScheme()` keys are matched against: the nearest provider, or the base theme with no color scheme. */
|
|
38
55
|
function useCondition() {
|
|
@@ -42,9 +59,9 @@ function createThemeValue(holder) {
|
|
|
42
59
|
};
|
|
43
60
|
}
|
|
44
61
|
return {
|
|
62
|
+
ThemeContext,
|
|
45
63
|
ThemeValueProvider,
|
|
46
64
|
useTheme,
|
|
47
|
-
useThemeValue,
|
|
48
65
|
useCondition
|
|
49
66
|
};
|
|
50
67
|
}
|
package/dist/calc.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
const require_units = require("./units.cjs");
|
|
1
2
|
// src/calc.ts
|
|
2
|
-
const NUMBER_PATTERN = /^(-?(?:\d+(?:\.\d*)?|\.\d+))(px|%)?$/i;
|
|
3
3
|
/** `value` rounded so that float noise (0.1 * 3) does not show; `-0` is `0`. */
|
|
4
4
|
function tidy(value) {
|
|
5
5
|
return Math.round(value * 1e6) / 1e6 + 0;
|
|
6
6
|
}
|
|
7
7
|
/** The error for a `value` that React Native cannot compute: the helper and the value are in the message. */
|
|
8
|
-
function
|
|
8
|
+
function createUnsupportedError(name, value) {
|
|
9
9
|
return /* @__PURE__ */ new TypeError(`@umber-style/react-native: ${name}() cannot compute ${JSON.stringify(value)}; it takes a number, a numeric string ("8", "8px") or a percentage ("50%"), and a percentage cannot be mixed with a number`);
|
|
10
10
|
}
|
|
11
11
|
/** Throws unless `value` is a finite number. */
|
|
@@ -13,7 +13,10 @@ function assertFinite(name, what, value) {
|
|
|
13
13
|
if (typeof value !== "number") throw new TypeError(`@umber-style/react-native: ${name}(): ${what} must be a number, got ${typeof value}`);
|
|
14
14
|
if (!Number.isFinite(value)) throw new RangeError(`@umber-style/react-native: ${name}(): ${what} must be finite, got ${value}`);
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* The number of `operand`, and whether it is a percentage; anything else cannot be computed. A string is
|
|
18
|
+
* read as a style value is converted (`readNumber`), but `rem` is refused: a helper has no base for it.
|
|
19
|
+
*/
|
|
17
20
|
function read(name, operand) {
|
|
18
21
|
if (typeof operand !== "string") {
|
|
19
22
|
assertFinite(name, "a value", operand);
|
|
@@ -22,11 +25,11 @@ function read(name, operand) {
|
|
|
22
25
|
isPercent: false
|
|
23
26
|
};
|
|
24
27
|
}
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
28
|
+
const reading = require_units.readNumber(operand);
|
|
29
|
+
if (reading === void 0 || reading.unit === "rem") throw createUnsupportedError(name, operand);
|
|
27
30
|
return {
|
|
28
|
-
value:
|
|
29
|
-
isPercent:
|
|
31
|
+
value: reading.value,
|
|
32
|
+
isPercent: reading.unit === "%"
|
|
30
33
|
};
|
|
31
34
|
}
|
|
32
35
|
/** `value` as the percentage that a style takes. */
|
|
@@ -51,7 +54,7 @@ function sum(name, terms) {
|
|
|
51
54
|
const isPercent = readings.some((reading) => reading.isPercent);
|
|
52
55
|
let total = 0;
|
|
53
56
|
for (const { operand, sign, value, isPercent: isPercentValue } of readings) {
|
|
54
|
-
if (isPercentValue !== isPercent && operand !== 0) throw
|
|
57
|
+
if (isPercentValue !== isPercent && operand !== 0) throw createUnsupportedError(name, operand);
|
|
55
58
|
total += sign * value;
|
|
56
59
|
}
|
|
57
60
|
return isPercent ? toPercent(total) : tidy(total);
|
package/dist/calc.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { readNumber } from "./units.mjs";
|
|
1
2
|
// src/calc.ts
|
|
2
|
-
const NUMBER_PATTERN = /^(-?(?:\d+(?:\.\d*)?|\.\d+))(px|%)?$/i;
|
|
3
3
|
/** `value` rounded so that float noise (0.1 * 3) does not show; `-0` is `0`. */
|
|
4
4
|
function tidy(value) {
|
|
5
5
|
return Math.round(value * 1e6) / 1e6 + 0;
|
|
6
6
|
}
|
|
7
7
|
/** The error for a `value` that React Native cannot compute: the helper and the value are in the message. */
|
|
8
|
-
function
|
|
8
|
+
function createUnsupportedError(name, value) {
|
|
9
9
|
return /* @__PURE__ */ new TypeError(`@umber-style/react-native: ${name}() cannot compute ${JSON.stringify(value)}; it takes a number, a numeric string ("8", "8px") or a percentage ("50%"), and a percentage cannot be mixed with a number`);
|
|
10
10
|
}
|
|
11
11
|
/** Throws unless `value` is a finite number. */
|
|
@@ -13,7 +13,10 @@ function assertFinite(name, what, value) {
|
|
|
13
13
|
if (typeof value !== "number") throw new TypeError(`@umber-style/react-native: ${name}(): ${what} must be a number, got ${typeof value}`);
|
|
14
14
|
if (!Number.isFinite(value)) throw new RangeError(`@umber-style/react-native: ${name}(): ${what} must be finite, got ${value}`);
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* The number of `operand`, and whether it is a percentage; anything else cannot be computed. A string is
|
|
18
|
+
* read as a style value is converted (`readNumber`), but `rem` is refused: a helper has no base for it.
|
|
19
|
+
*/
|
|
17
20
|
function read(name, operand) {
|
|
18
21
|
if (typeof operand !== "string") {
|
|
19
22
|
assertFinite(name, "a value", operand);
|
|
@@ -22,11 +25,11 @@ function read(name, operand) {
|
|
|
22
25
|
isPercent: false
|
|
23
26
|
};
|
|
24
27
|
}
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
28
|
+
const reading = readNumber(operand);
|
|
29
|
+
if (reading === void 0 || reading.unit === "rem") throw createUnsupportedError(name, operand);
|
|
27
30
|
return {
|
|
28
|
-
value:
|
|
29
|
-
isPercent:
|
|
31
|
+
value: reading.value,
|
|
32
|
+
isPercent: reading.unit === "%"
|
|
30
33
|
};
|
|
31
34
|
}
|
|
32
35
|
/** `value` as the percentage that a style takes. */
|
|
@@ -51,7 +54,7 @@ function sum(name, terms) {
|
|
|
51
54
|
const isPercent = readings.some((reading) => reading.isPercent);
|
|
52
55
|
let total = 0;
|
|
53
56
|
for (const { operand, sign, value, isPercent: isPercentValue } of readings) {
|
|
54
|
-
if (isPercentValue !== isPercent && operand !== 0) throw
|
|
57
|
+
if (isPercentValue !== isPercent && operand !== 0) throw createUnsupportedError(name, operand);
|
|
55
58
|
total += sign * value;
|
|
56
59
|
}
|
|
57
60
|
return isPercent ? toPercent(total) : tidy(total);
|
package/dist/createStyle.cjs
CHANGED
|
@@ -2,32 +2,117 @@ let react = require("react");
|
|
|
2
2
|
const require_conditions = require("./conditions.cjs");
|
|
3
3
|
let _umber_style_core = require("@umber-style/core");
|
|
4
4
|
const require_ThemeValue = require("./ThemeValue.cjs");
|
|
5
|
+
const require_nativeTheme = require("./nativeTheme.cjs");
|
|
5
6
|
const require_styled = require("./styled.cjs");
|
|
6
7
|
const require_toNativeStyle = require("./toNativeStyle.cjs");
|
|
8
|
+
const require_windowState = require("./windowState.cjs");
|
|
7
9
|
let react_native = require("react-native");
|
|
8
10
|
// src/createStyle.ts
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
const NO_QUERIES = [];
|
|
12
|
+
const NO_KEYS = {
|
|
13
|
+
isConditional: false,
|
|
14
|
+
hasScheme: false,
|
|
15
|
+
queries: []
|
|
16
|
+
};
|
|
17
|
+
/** The name of the sheet entry `key` in the development warnings. */
|
|
18
|
+
const toEntryName = (key) => `sheet entry "${key}"`;
|
|
19
|
+
/** Registers `source` with the platform StyleSheet, without the keys that only the web has; a `rem` length is `remBase` times its number. */
|
|
20
|
+
function register(source, remBase) {
|
|
21
|
+
const pairs = Object.entries(source).map(([key, style]) => [key, require_toNativeStyle.toNativeStyle(style, void 0, {
|
|
22
|
+
remBase,
|
|
23
|
+
name: toEntryName(key)
|
|
24
|
+
})]);
|
|
25
|
+
const entries = react_native.StyleSheet.create(Object.fromEntries(pairs));
|
|
26
|
+
let all;
|
|
27
|
+
for (const key in source) all = require_toNativeStyle.collectKeys(source[key], all);
|
|
28
|
+
const keys = {};
|
|
29
|
+
if (all !== void 0) for (const key in source) keys[key] = require_toNativeStyle.collectKeys(source[key]) ?? NO_KEYS;
|
|
12
30
|
return {
|
|
13
|
-
entries
|
|
31
|
+
entries,
|
|
14
32
|
source,
|
|
15
|
-
|
|
33
|
+
keys,
|
|
34
|
+
isConditional: all?.isConditional ?? false,
|
|
35
|
+
queries: all?.queries ?? NO_QUERIES,
|
|
36
|
+
hasScheme: all?.hasScheme ?? false
|
|
16
37
|
};
|
|
17
38
|
}
|
|
18
|
-
/** The entries of `sheet
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
const
|
|
39
|
+
/** The entries of `sheet` for the key of a render, with the ones that depend on the window only resolved and registered once for each set of matching queries. */
|
|
40
|
+
function readWindowEntries(sheet, key, remBase) {
|
|
41
|
+
const { entries, keys, queries, source } = sheet;
|
|
42
|
+
const windowKey = key.slice(0, queries.length);
|
|
43
|
+
const byWindow = sheet.byWindow ??= /* @__PURE__ */ new Map();
|
|
44
|
+
let found = byWindow.get(windowKey);
|
|
45
|
+
if (found === void 0) {
|
|
46
|
+
const state = require_windowState.readWindowState();
|
|
47
|
+
const pairs = Object.entries(source).flatMap(([name, style]) => keys[name].queries.length > 0 && !keys[name].isConditional ? [[name, require_toNativeStyle.toNativeStyle(style, void 0, {
|
|
48
|
+
remBase,
|
|
49
|
+
name: toEntryName(name)
|
|
50
|
+
}, state)]] : []);
|
|
51
|
+
found = {
|
|
52
|
+
...entries,
|
|
53
|
+
...react_native.StyleSheet.create(Object.fromEntries(pairs))
|
|
54
|
+
};
|
|
55
|
+
byWindow.set(windowKey, found);
|
|
56
|
+
}
|
|
57
|
+
return found;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The entries of `sheet` for the key of a render: the ones that depend on the window only as registered
|
|
61
|
+
* for the matching queries, and the ones that have a `when()` or `whenScheme()` key resolved against
|
|
62
|
+
* `condition` and the window (not registered: they change with the providers).
|
|
63
|
+
*/
|
|
64
|
+
function resolveEntries(sheet, condition, key, remBase) {
|
|
65
|
+
const { isConditional, keys, queries, source } = sheet;
|
|
66
|
+
const hasQueries = queries.length > 0;
|
|
67
|
+
const entries = hasQueries ? readWindowEntries(sheet, key, remBase) : sheet.entries;
|
|
68
|
+
if (!isConditional) return entries;
|
|
69
|
+
const state = hasQueries ? require_windowState.readWindowState() : void 0;
|
|
70
|
+
const pairs = Object.entries(source).map(([name, style]) => [name, keys[name].isConditional ? require_toNativeStyle.toNativeStyle(style, condition, {
|
|
71
|
+
remBase,
|
|
72
|
+
name: toEntryName(name)
|
|
73
|
+
}, state) : entries[name]]);
|
|
22
74
|
return Object.fromEntries(pairs);
|
|
23
75
|
}
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
76
|
+
/**
|
|
77
|
+
* `css()` on React Native: the styles (lists flattened, falsy values dropped), or the style of a tagged
|
|
78
|
+
* template read as CSS text, each turned into a native style as a sheet entry is, merged in order with
|
|
79
|
+
* the last key winning. Throws a `TypeError` for a function and for anything else that is not a style.
|
|
80
|
+
*/
|
|
81
|
+
function mergeNativeStyles(args, remBase) {
|
|
82
|
+
const template = (0, _umber_style_core.readStaticTemplate)(args, "css");
|
|
83
|
+
if (!template) (0, _umber_style_core.rejectFunctions)(args, "css");
|
|
84
|
+
const styles = template ? [template] : args.flat(1e400).filter(Boolean);
|
|
85
|
+
const settings = {
|
|
86
|
+
remBase,
|
|
87
|
+
name: "css()"
|
|
88
|
+
};
|
|
89
|
+
const merged = {};
|
|
90
|
+
for (const style of styles) {
|
|
91
|
+
if (typeof style !== "object") throw new TypeError(`css(): ${JSON.stringify(style)} is not a style: give style objects.`);
|
|
92
|
+
Object.assign(merged, require_toNativeStyle.toNativeStyle(style, void 0, settings));
|
|
93
|
+
}
|
|
94
|
+
return merged;
|
|
95
|
+
}
|
|
96
|
+
/** `Global` on React Native: there are no global styles, so it renders nothing and does nothing. */
|
|
97
|
+
function Global(_props) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
/** `ThemeScope` on React Native: there is no wrapper to repeat, and a modal stays inside the tree, so it renders its children. */
|
|
101
|
+
function ThemeScope({ children }) {
|
|
102
|
+
return (0, react.createElement)(react.Fragment, null, children);
|
|
103
|
+
}
|
|
104
|
+
/** `useThemeClass` on React Native: there are no classes. */
|
|
105
|
+
function useThemeClass() {}
|
|
106
|
+
/**
|
|
107
|
+
* Makes the React Native styling over a holder of the base theme; the theme context is made here unless
|
|
108
|
+
* given. Of `options`, `remBase` and `lengthKeys` are used: a theme is converted under `lengthKeys`.
|
|
109
|
+
*/
|
|
110
|
+
function bindHolder(holder, context, options = {}) {
|
|
111
|
+
const { remBase = 16, lengthKeys = require_nativeTheme.DEFAULT_LENGTH_KEYS } = options;
|
|
112
|
+
const { ThemeContext, ThemeValueProvider, useTheme, useCondition } = require_ThemeValue.createThemeValue(holder, (theme) => require_nativeTheme.toNativeTheme(theme, lengthKeys, remBase), context);
|
|
113
|
+
function ThemeProvider({ theme, colorScheme, children }) {
|
|
29
114
|
return (0, react.createElement)(ThemeValueProvider, {
|
|
30
|
-
theme
|
|
115
|
+
theme,
|
|
31
116
|
colorScheme
|
|
32
117
|
}, children);
|
|
33
118
|
}
|
|
@@ -35,45 +120,64 @@ function bindHolder(holder) {
|
|
|
35
120
|
if (typeof styles !== "function") {
|
|
36
121
|
let registered;
|
|
37
122
|
return (0, _umber_style_core.createLazyRecord)(Object.keys(styles), (key) => {
|
|
38
|
-
registered ??= register(styles);
|
|
123
|
+
registered ??= register(styles, remBase);
|
|
39
124
|
return registered.entries[key];
|
|
40
125
|
});
|
|
41
126
|
}
|
|
42
127
|
const byTheme = /* @__PURE__ */ new WeakMap();
|
|
43
|
-
|
|
128
|
+
const prepare = (current) => {
|
|
44
129
|
let sheet = byTheme.get(current);
|
|
45
130
|
if (!sheet) {
|
|
46
|
-
sheet = register(styles(current));
|
|
131
|
+
sheet = register(styles(current), remBase);
|
|
47
132
|
byTheme.set(current, sheet);
|
|
48
133
|
}
|
|
49
|
-
return
|
|
50
|
-
}
|
|
134
|
+
return sheet;
|
|
135
|
+
};
|
|
136
|
+
return {
|
|
137
|
+
prepare,
|
|
138
|
+
resolve(current, condition) {
|
|
139
|
+
const sheet = prepare(current);
|
|
140
|
+
return resolveEntries(sheet, condition, require_windowState.readMediaKey(sheet.queries, false, remBase), remBase);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
51
143
|
}
|
|
52
144
|
const useStyle = ((sheet) => {
|
|
53
|
-
const theme =
|
|
145
|
+
const theme = useTheme();
|
|
54
146
|
const condition = useCondition();
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
147
|
+
const prepared = (0, _umber_style_core.isThemedSheet)(sheet) ? sheet.prepare(theme) : void 0;
|
|
148
|
+
const shouldWatchScheme = !!prepared?.hasScheme && condition.colorScheme === void 0;
|
|
149
|
+
const key = require_windowState.useMediaKey(prepared?.queries ?? NO_QUERIES, shouldWatchScheme, remBase);
|
|
150
|
+
return prepared === void 0 ? sheet : resolveEntries(prepared, condition, key, remBase);
|
|
58
151
|
});
|
|
59
152
|
return {
|
|
60
|
-
styled: require_styled.createStyled(useTheme, useCondition),
|
|
153
|
+
styled: require_styled.createStyled(useTheme, useCondition, remBase),
|
|
61
154
|
StyleSheet: {
|
|
62
155
|
...react_native.StyleSheet,
|
|
63
156
|
create
|
|
64
157
|
},
|
|
65
158
|
useStyle,
|
|
66
159
|
apply: (...entries) => ({ style: entries.filter((entry) => !!entry) }),
|
|
160
|
+
css: ((...args) => mergeNativeStyles(args, remBase)),
|
|
67
161
|
ThemeProvider,
|
|
162
|
+
ThemeScope,
|
|
163
|
+
ThemeContext,
|
|
68
164
|
useTheme,
|
|
165
|
+
useThemeClass,
|
|
69
166
|
themeClass: () => "",
|
|
70
167
|
when: require_conditions.createNativeThemeKey,
|
|
71
|
-
whenScheme: _umber_style_core.createSchemeKey
|
|
168
|
+
whenScheme: _umber_style_core.createSchemeKey,
|
|
169
|
+
keyframes: _umber_style_core.keyframes,
|
|
170
|
+
globalStyles: _umber_style_core.globalStyles,
|
|
171
|
+
Global
|
|
72
172
|
};
|
|
73
173
|
}
|
|
74
|
-
/**
|
|
75
|
-
|
|
76
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Makes the styling of one theme shape for React Native, apart from the default one. The options are
|
|
176
|
+
* those of the web, so that one call runs on both platforms, with `remBase` added; of them only
|
|
177
|
+
* `remBase` and `lengthKeys` are used.
|
|
178
|
+
*/
|
|
179
|
+
function createStyle(theme, options = {}) {
|
|
180
|
+
return bindHolder({ baseTheme: theme }, void 0, options);
|
|
77
181
|
}
|
|
78
182
|
exports.bindHolder = bindHolder;
|
|
79
183
|
exports.createStyle = createStyle;
|
package/dist/createStyle.d.cts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { NativeStyle, StyleOptions } from "./types.cjs";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export declare function createStyle<T extends object>(theme: T, _options?: StyleOptions<T>): NativeStyle<T>;
|
|
10
|
-
export type { StyleOptions };
|
|
2
|
+
import "./nativeTheme.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* Makes the styling of one theme shape for React Native, apart from the default one. The options are
|
|
5
|
+
* those of the web, so that one call runs on both platforms, with `remBase` added; of them only
|
|
6
|
+
* `remBase` and `lengthKeys` are used.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createStyle<T extends object>(theme: T, options?: StyleOptions<T>): NativeStyle<T>;
|
package/dist/createStyle.d.mts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
+
import "react";
|
|
1
2
|
import { NativeStyle, StyleOptions } from "./types.mjs";
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare function
|
|
8
|
-
/** Makes the styling of one theme shape for React Native, apart from the default one; the options are those of the web and are not used. */
|
|
9
|
-
export declare function createStyle<T extends object>(theme: T, _options?: StyleOptions<T>): NativeStyle<T>;
|
|
10
|
-
export type { StyleOptions };
|
|
3
|
+
/**
|
|
4
|
+
* Makes the styling of one theme shape for React Native, apart from the default one. The options are
|
|
5
|
+
* those of the web, so that one call runs on both platforms, with `remBase` added; of them only
|
|
6
|
+
* `remBase` and `lengthKeys` are used.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createStyle<T extends object>(theme: T, options?: StyleOptions<T>): NativeStyle<T>;
|