@umber-style/react-native 0.0.0 → 0.1.0-alpha.1

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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -1
  3. package/dist/CacheProvider.cjs +7 -0
  4. package/dist/CacheProvider.d.cts +4 -0
  5. package/dist/CacheProvider.d.mts +4 -0
  6. package/dist/CacheProvider.mjs +7 -0
  7. package/dist/ThemeValue.cjs +68 -0
  8. package/dist/ThemeValue.mjs +68 -0
  9. package/dist/alpha.cjs +16 -0
  10. package/dist/alpha.d.cts +8 -0
  11. package/dist/alpha.d.mts +8 -0
  12. package/dist/alpha.mjs +16 -0
  13. package/dist/calc.cjs +90 -0
  14. package/dist/calc.d.cts +24 -0
  15. package/dist/calc.d.mts +24 -0
  16. package/dist/calc.mjs +86 -0
  17. package/dist/conditions.cjs +29 -0
  18. package/dist/conditions.mjs +27 -0
  19. package/dist/createStyle.cjs +183 -0
  20. package/dist/createStyle.d.cts +8 -0
  21. package/dist/createStyle.d.mts +8 -0
  22. package/dist/createStyle.mjs +182 -0
  23. package/dist/defaultStyle.cjs +69 -0
  24. package/dist/defaultStyle.d.cts +34 -0
  25. package/dist/defaultStyle.d.mts +34 -0
  26. package/dist/defaultStyle.mjs +69 -0
  27. package/dist/index.cjs +41 -0
  28. package/dist/index.d.cts +21 -0
  29. package/dist/index.d.mts +21 -0
  30. package/dist/index.mjs +8 -0
  31. package/dist/mediaQuery.cjs +179 -0
  32. package/dist/mediaQuery.d.cts +1 -0
  33. package/dist/mediaQuery.mjs +178 -0
  34. package/dist/nativeStyle.d.cts +32 -0
  35. package/dist/nativeStyle.d.mts +32 -0
  36. package/dist/nativeTheme.cjs +51 -0
  37. package/dist/nativeTheme.d.cts +15 -0
  38. package/dist/nativeTheme.d.mts +15 -0
  39. package/dist/nativeTheme.mjs +50 -0
  40. package/dist/platform.d.cts +2 -0
  41. package/dist/platform.d.mts +2 -0
  42. package/dist/platform.mjs +1 -0
  43. package/dist/styled.cjs +120 -0
  44. package/dist/styled.mjs +120 -0
  45. package/dist/toNativeStyle.cjs +88 -0
  46. package/dist/toNativeStyle.mjs +87 -0
  47. package/dist/types.d.cts +130 -0
  48. package/dist/types.d.mts +130 -0
  49. package/dist/units.cjs +137 -0
  50. package/dist/units.mjs +133 -0
  51. package/dist/warnStyle.cjs +97 -0
  52. package/dist/warnStyle.mjs +95 -0
  53. package/dist/windowState.cjs +89 -0
  54. package/dist/windowState.d.cts +6 -0
  55. package/dist/windowState.d.mts +5 -0
  56. package/dist/windowState.mjs +85 -0
  57. package/package.json +77 -5
@@ -0,0 +1,21 @@
1
+ import { DefaultStyleOptions, createDefaultStyle } from "./defaultStyle.mjs";
2
+ import { NativeLength, NativeTheme } from "./nativeTheme.mjs";
3
+ import { CacheProviderProps, GlobalProps, NativeCssArgument, NativeCssFunction, NativeStyle, NativeStyleSheet, SheetDefinition, StyleOptions, StyleProp, Styled, StyledComponent, StyledOptions, ThemeProviderProps, ThemeScopeProps } from "./types.mjs";
4
+ import { NativeObjectSheet, NativeSheetInput, NativeSheetStyles, NativeStyleFunction, NativeStyleInput, NativeStyleObject, NativeStyleResult } from "./nativeStyle.mjs";
5
+ import { MediaQueryOptions } from "./windowState.mjs";
6
+ import { at } from "@umber-style/core";
7
+ import { CacheProvider } from "./CacheProvider.mjs";
8
+ import { alpha } from "./alpha.mjs";
9
+ import { Operand, Percent, add, divide, multiply, negate, subtract } from "./calc.mjs";
10
+ import { createStyle } from "./createStyle.mjs";
11
+ export declare const configure: (options: DefaultStyleOptions) => void, styled: Styled<NativeTheme<import("@umber-style/core").Theme>>, StyleSheet: NativeStyleSheet<NativeTheme<import("@umber-style/core").Theme>>, useStyle: {
12
+ <K extends string>(sheet: { readonly [P in K]: NativeStyleObject; }): { readonly [P in K]: NativeStyleObject; };
13
+ <S extends NativeSheetStyles>(sheet: SheetDefinition<S, NativeStyleObject>): { [K in keyof S]: NativeStyleObject; };
14
+ }, useTheme: () => NativeTheme<import("@umber-style/core").Theme>, ThemeProvider: (props: ThemeProviderProps<import("@umber-style/core").Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, ThemeScope: (props: ThemeScopeProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, useThemeClass: () => string | undefined, useMediaQuery: (query: string, options?: MediaQueryOptions) => boolean, ThemeContext: import("react").Context<NativeTheme<import("@umber-style/core").Theme> | undefined>, apply: (...entries: (NativeStyleObject | null | undefined | false)[]) => {
15
+ style: NativeStyleObject[];
16
+ }, css: NativeCssFunction, themeClass: (theme: {
17
+ readonly _theme?: never;
18
+ }, colorScheme?: import("@umber-style/core").ColorScheme) => string, when: (theme: {
19
+ readonly _theme?: never;
20
+ }, colorScheme?: import("@umber-style/core").ColorScheme) => import("@umber-style/core").ThemeKey, whenScheme: (scheme: import("@umber-style/core").SchemeName) => import("@umber-style/core").SchemeKey, keyframes: (steps: import("@umber-style/core").KeyframesInput<import("@umber-style/core").Theme>, options?: import("@umber-style/core").KeyframesOptions) => string, globalStyles: (styles: import("@umber-style/core").GlobalStylesInput<import("@umber-style/core").Theme>) => import("@umber-style/core").GlobalStyles<import("@umber-style/core").Theme>, Global: (props: GlobalProps<import("@umber-style/core").Theme>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
21
+ export { CacheProvider, CacheProviderProps, DefaultStyleOptions, GlobalProps, type MediaQueryOptions, NativeCssArgument, NativeCssFunction, type NativeLength, NativeObjectSheet, NativeSheetInput, NativeSheetStyles, NativeStyle, NativeStyleFunction, NativeStyleInput, NativeStyleObject, NativeStyleResult, NativeStyleSheet, type NativeTheme, Operand, Percent, SheetDefinition, StyleOptions, StyleProp, Styled, StyledComponent, StyledOptions, ThemeProviderProps, ThemeScopeProps, add, alpha, at, createDefaultStyle, createStyle, divide, multiply, negate, subtract };
package/dist/index.mjs ADDED
@@ -0,0 +1,8 @@
1
+ import { createDefaultStyle } from "./defaultStyle.mjs";
2
+ import { at } from "@umber-style/core";
3
+ import { CacheProvider } from "./CacheProvider.mjs";
4
+ import { alpha } from "./alpha.mjs";
5
+ import { add, divide, multiply, negate, subtract } from "./calc.mjs";
6
+ import { createStyle } from "./createStyle.mjs";
7
+ const { configure, styled, StyleSheet, useStyle, useTheme, ThemeProvider, ThemeScope, useThemeClass, useMediaQuery, ThemeContext, apply, css, themeClass, when, whenScheme, keyframes, globalStyles, Global } = createDefaultStyle();
8
+ export { CacheProvider, Global, StyleSheet, ThemeContext, ThemeProvider, ThemeScope, add, alpha, apply, at, configure, createDefaultStyle, createStyle, css, divide, globalStyles, keyframes, multiply, negate, styled, subtract, themeClass, useMediaQuery, useStyle, useTheme, useThemeClass, when, whenScheme };
@@ -0,0 +1,179 @@
1
+ // src/mediaQuery.ts
2
+ /** A part of a query that the binding cannot evaluate: what to name in the warning. */
3
+ var Unsupported = class {
4
+ problem;
5
+ constructor(problem) {
6
+ this.problem = problem;
7
+ }
8
+ };
9
+ /** A key that is a media query: `@media` and then white space or a parenthesis. */
10
+ const MEDIA_KEY = /^@media(?=[\s(])/i;
11
+ /** `@media` in front of a query, with any white space before it. */
12
+ const MEDIA_PREFIX = /^\s*@media(?![a-z-])/i;
13
+ /** A feature in parentheses, a word, or any other character. */
14
+ const TOKEN = /\([^()]*\)|[a-z-]+|\S/g;
15
+ /** A number and its unit. */
16
+ const LENGTH = /^(-?(?:\d+(?:\.\d*)?|\.\d+))([a-z%]*)$/;
17
+ /** An operator of the range form. The white space around it is trimmed off the parts: a pattern that took it in would try each run of white space once for each of its characters. */
18
+ const RANGE = /(<=|>=|<|>|=)/;
19
+ /** The name of a feature, `min-` or `max-` and all. */
20
+ const NAME = /^[a-z-]+$/;
21
+ const SIZE = /^(min-|max-)?(width|height)$/;
22
+ const SIZE_FEATURES = /* @__PURE__ */ new Set(["width", "height"]);
23
+ const FLIPPED = {
24
+ "<": ">",
25
+ "<=": ">=",
26
+ ">": "<",
27
+ ">=": "<=",
28
+ "=": "="
29
+ };
30
+ /** The features that take a keyword, and the test of each keyword. */
31
+ const KEYWORD_FEATURES = /* @__PURE__ */ new Map([
32
+ ["orientation", /* @__PURE__ */ new Map([["portrait", (state) => state.height >= state.width], ["landscape", (state) => state.height < state.width]])],
33
+ ["prefers-color-scheme", /* @__PURE__ */ new Map([["light", (state) => state.colorScheme !== "dark"], ["dark", (state) => state.colorScheme === "dark"]])],
34
+ ["prefers-reduced-motion", /* @__PURE__ */ new Map([["reduce", (state) => state.isReducedMotion], ["no-preference", (state) => !state.isReducedMotion]])]
35
+ ]);
36
+ const matchNever = () => false;
37
+ /** Whether `key` is a media query key: `@media (...)`. */
38
+ function isMediaKey(key) {
39
+ return MEDIA_KEY.test(key);
40
+ }
41
+ /** `left` compared with `right` by `operator`. */
42
+ function compare(left, operator, right) {
43
+ switch (operator) {
44
+ case "<": return left < right;
45
+ case "<=": return left <= right;
46
+ case ">": return left > right;
47
+ case ">=": return left >= right;
48
+ default: return left === right;
49
+ }
50
+ }
51
+ /** The length `text` for a `remBase`: `px` and no unit are pixels, `rem` and `em` are `remBase` times their number. */
52
+ function readLength(text) {
53
+ const match = LENGTH.exec(text);
54
+ if (match === null) return new Unsupported(`the value "${text}"`);
55
+ const value = Number.parseFloat(match[1]);
56
+ const unit = match[2];
57
+ if (unit === "" || unit === "px") return () => value;
58
+ if (unit === "rem" || unit === "em") return (remBase) => value * remBase;
59
+ return new Unsupported(`the unit "${unit}"`);
60
+ }
61
+ /** The test of `feature operator text`: the width or the height of the window compared with a length. */
62
+ function compareSize(feature, operator, text) {
63
+ const length = readLength(text);
64
+ if (length instanceof Unsupported) return length;
65
+ return feature === "width" ? (state, remBase) => compare(state.width, operator, length(remBase)) : (state, remBase) => compare(state.height, operator, length(remBase));
66
+ }
67
+ /** The operator of a size feature with the prefix `bound`: `min-` is `>=`, `max-` is `<=`, none is `=`. */
68
+ function readBoundOperator(bound) {
69
+ if (bound === "min-") return ">=";
70
+ return bound === "max-" ? "<=" : "=";
71
+ }
72
+ /** The test of `(name: value)`. */
73
+ function readPlainFeature(name, value) {
74
+ const size = SIZE.exec(name);
75
+ if (size !== null) return compareSize(size[2], readBoundOperator(size[1]), value);
76
+ const keywords = KEYWORD_FEATURES.get(name);
77
+ if (keywords === void 0) return new Unsupported(`the media feature "${name}"`);
78
+ return keywords.get(value) ?? new Unsupported(`the value "${value}" of ${name}`);
79
+ }
80
+ /** The test of a comparison, `width >= 600px` or `600px <= width`; undefined when neither side is a size feature. */
81
+ function readComparison([left, operator, right]) {
82
+ if (SIZE_FEATURES.has(left)) return compareSize(left, operator, right);
83
+ if (SIZE_FEATURES.has(right)) return compareSize(right, FLIPPED[operator], left);
84
+ }
85
+ /** The test of a size between two lengths, `400px <= width < 800px`; undefined unless both operators point the same way: `<` and `<=`, or `>` and `>=`. */
86
+ function readBetween([low, first, feature, second, high]) {
87
+ if (first === "=" || second === "=" || first.startsWith("<") !== second.startsWith("<")) return;
88
+ const above = compareSize(feature, FLIPPED[first], low);
89
+ const below = compareSize(feature, second, high);
90
+ if (above instanceof Unsupported) return above;
91
+ if (below instanceof Unsupported) return below;
92
+ return (state, remBase) => above(state, remBase) && below(state, remBase);
93
+ }
94
+ /** The test of a range: `width >= 600px`, `600px <= width`, `400px <= width < 800px`. */
95
+ function readRange(parts) {
96
+ let read;
97
+ if (parts.length === 3) read = readComparison(parts);
98
+ else if (parts.length === 5 && SIZE_FEATURES.has(parts[2])) read = readBetween(parts);
99
+ if (read !== void 0) return read;
100
+ const name = parts.find((part) => NAME.test(part) && !SIZE_FEATURES.has(part));
101
+ return new Unsupported(name === void 0 ? `the range "${parts.join(" ")}"` : `the media feature "${name}"`);
102
+ }
103
+ /** The test of the text inside one pair of parentheses. */
104
+ function readFeature(text) {
105
+ const colon = text.indexOf(":");
106
+ if (colon >= 0) return readPlainFeature(text.slice(0, colon).trim(), text.slice(colon + 1).trim());
107
+ const parts = text.split(RANGE).map((part) => part.trim());
108
+ if (parts.length > 1) return readRange(parts);
109
+ return new Unsupported(NAME.test(text) ? `the media feature "${text}"` : `the text "(${text})"`);
110
+ }
111
+ /** Whether `token` is a feature in parentheses. */
112
+ const isFeature = (token) => token !== void 0 && token.length > 1 && token.startsWith("(");
113
+ /** The tests of the features of `tokens` from `start`, joined by `and`; `invalid` when the tokens are not that, or what the binding cannot evaluate in a feature. */
114
+ function readFeatures(tokens, start, invalid) {
115
+ const tests = [];
116
+ let index = start;
117
+ for (;;) {
118
+ const token = tokens[index++];
119
+ if (!isFeature(token)) return invalid;
120
+ const test = readFeature(token.slice(1, -1).trim());
121
+ if (test instanceof Unsupported) return test;
122
+ tests.push(test);
123
+ if (index === tokens.length) return tests;
124
+ if (tokens[index++] !== "and") return invalid;
125
+ }
126
+ }
127
+ /** The tests of a query whose media type is at `index` of `tokens`: none for the type alone, else those of the features after its `and`. */
128
+ function readTypedFeatures(tokens, index, invalid) {
129
+ const type = tokens[index];
130
+ if (type !== "all" && type !== "screen") return new Unsupported(`the media type "${type}"`);
131
+ if (index + 1 === tokens.length) return [];
132
+ if (tokens[index + 1] !== "and") return invalid;
133
+ return readFeatures(tokens, index + 2, invalid);
134
+ }
135
+ /** The test of one query of a list: `not` or `only`, a media type, and features joined by `and`. */
136
+ function readQuery(text) {
137
+ const tokens = text.match(TOKEN) ?? [];
138
+ const invalid = new Unsupported(`the text "${text}"`);
139
+ const isNegated = tokens[0] === "not";
140
+ const index = isNegated || tokens[0] === "only" ? 1 : 0;
141
+ const type = tokens[index];
142
+ const tests = type !== void 0 && NAME.test(type) ? readTypedFeatures(tokens, index, invalid) : readFeatures(tokens, index, invalid);
143
+ if (tests instanceof Unsupported) return tests;
144
+ return (state, remBase) => tests.every((test) => test(state, remBase)) !== isNegated;
145
+ }
146
+ /** `text` read as a media query list, with or without `@media` in front. */
147
+ function parseMediaQuery(text) {
148
+ const list = text.replace(MEDIA_PREFIX, "").trim().toLowerCase();
149
+ const tests = [];
150
+ for (const part of list.split(",")) {
151
+ const test = readQuery(part.trim());
152
+ if (test instanceof Unsupported) return {
153
+ matches: matchNever,
154
+ problem: test.problem
155
+ };
156
+ tests.push(test);
157
+ }
158
+ return { matches: (state, remBase) => tests.some((test) => test(state, remBase)) };
159
+ }
160
+ const queries = /* @__PURE__ */ new Map();
161
+ /**
162
+ * The media query `text` (a key `@media (...)`, or the query alone, as `matchMedia` takes it), read once
163
+ * for each text. The subset: `width`, `height` and their `min-` and `max-` forms, the range forms
164
+ * (`width >= 600px`, `600px <= width`, `400px <= width < 800px`), `orientation`, `prefers-color-scheme`
165
+ * and `prefers-reduced-motion`, joined by `and`, in a comma list (any one matches), after `not` or
166
+ * `only` and the media type `all` or `screen`. A length is in `px` or has no unit (one pixel is one
167
+ * density-independent pixel), or is in `rem` or `em` (`remBase` pixels). A query with anything else
168
+ * never matches, and has a `problem` that names it.
169
+ */
170
+ function readMediaQuery(text) {
171
+ let query = queries.get(text);
172
+ if (query === void 0) {
173
+ query = parseMediaQuery(text);
174
+ queries.set(text, query);
175
+ }
176
+ return query;
177
+ }
178
+ exports.isMediaKey = isMediaKey;
179
+ exports.readMediaQuery = readMediaQuery;
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,178 @@
1
+ // src/mediaQuery.ts
2
+ /** A part of a query that the binding cannot evaluate: what to name in the warning. */
3
+ var Unsupported = class {
4
+ problem;
5
+ constructor(problem) {
6
+ this.problem = problem;
7
+ }
8
+ };
9
+ /** A key that is a media query: `@media` and then white space or a parenthesis. */
10
+ const MEDIA_KEY = /^@media(?=[\s(])/i;
11
+ /** `@media` in front of a query, with any white space before it. */
12
+ const MEDIA_PREFIX = /^\s*@media(?![a-z-])/i;
13
+ /** A feature in parentheses, a word, or any other character. */
14
+ const TOKEN = /\([^()]*\)|[a-z-]+|\S/g;
15
+ /** A number and its unit. */
16
+ const LENGTH = /^(-?(?:\d+(?:\.\d*)?|\.\d+))([a-z%]*)$/;
17
+ /** An operator of the range form. The white space around it is trimmed off the parts: a pattern that took it in would try each run of white space once for each of its characters. */
18
+ const RANGE = /(<=|>=|<|>|=)/;
19
+ /** The name of a feature, `min-` or `max-` and all. */
20
+ const NAME = /^[a-z-]+$/;
21
+ const SIZE = /^(min-|max-)?(width|height)$/;
22
+ const SIZE_FEATURES = /* @__PURE__ */ new Set(["width", "height"]);
23
+ const FLIPPED = {
24
+ "<": ">",
25
+ "<=": ">=",
26
+ ">": "<",
27
+ ">=": "<=",
28
+ "=": "="
29
+ };
30
+ /** The features that take a keyword, and the test of each keyword. */
31
+ const KEYWORD_FEATURES = /* @__PURE__ */ new Map([
32
+ ["orientation", /* @__PURE__ */ new Map([["portrait", (state) => state.height >= state.width], ["landscape", (state) => state.height < state.width]])],
33
+ ["prefers-color-scheme", /* @__PURE__ */ new Map([["light", (state) => state.colorScheme !== "dark"], ["dark", (state) => state.colorScheme === "dark"]])],
34
+ ["prefers-reduced-motion", /* @__PURE__ */ new Map([["reduce", (state) => state.isReducedMotion], ["no-preference", (state) => !state.isReducedMotion]])]
35
+ ]);
36
+ const matchNever = () => false;
37
+ /** Whether `key` is a media query key: `@media (...)`. */
38
+ function isMediaKey(key) {
39
+ return MEDIA_KEY.test(key);
40
+ }
41
+ /** `left` compared with `right` by `operator`. */
42
+ function compare(left, operator, right) {
43
+ switch (operator) {
44
+ case "<": return left < right;
45
+ case "<=": return left <= right;
46
+ case ">": return left > right;
47
+ case ">=": return left >= right;
48
+ default: return left === right;
49
+ }
50
+ }
51
+ /** The length `text` for a `remBase`: `px` and no unit are pixels, `rem` and `em` are `remBase` times their number. */
52
+ function readLength(text) {
53
+ const match = LENGTH.exec(text);
54
+ if (match === null) return new Unsupported(`the value "${text}"`);
55
+ const value = Number.parseFloat(match[1]);
56
+ const unit = match[2];
57
+ if (unit === "" || unit === "px") return () => value;
58
+ if (unit === "rem" || unit === "em") return (remBase) => value * remBase;
59
+ return new Unsupported(`the unit "${unit}"`);
60
+ }
61
+ /** The test of `feature operator text`: the width or the height of the window compared with a length. */
62
+ function compareSize(feature, operator, text) {
63
+ const length = readLength(text);
64
+ if (length instanceof Unsupported) return length;
65
+ return feature === "width" ? (state, remBase) => compare(state.width, operator, length(remBase)) : (state, remBase) => compare(state.height, operator, length(remBase));
66
+ }
67
+ /** The operator of a size feature with the prefix `bound`: `min-` is `>=`, `max-` is `<=`, none is `=`. */
68
+ function readBoundOperator(bound) {
69
+ if (bound === "min-") return ">=";
70
+ return bound === "max-" ? "<=" : "=";
71
+ }
72
+ /** The test of `(name: value)`. */
73
+ function readPlainFeature(name, value) {
74
+ const size = SIZE.exec(name);
75
+ if (size !== null) return compareSize(size[2], readBoundOperator(size[1]), value);
76
+ const keywords = KEYWORD_FEATURES.get(name);
77
+ if (keywords === void 0) return new Unsupported(`the media feature "${name}"`);
78
+ return keywords.get(value) ?? new Unsupported(`the value "${value}" of ${name}`);
79
+ }
80
+ /** The test of a comparison, `width >= 600px` or `600px <= width`; undefined when neither side is a size feature. */
81
+ function readComparison([left, operator, right]) {
82
+ if (SIZE_FEATURES.has(left)) return compareSize(left, operator, right);
83
+ if (SIZE_FEATURES.has(right)) return compareSize(right, FLIPPED[operator], left);
84
+ }
85
+ /** The test of a size between two lengths, `400px <= width < 800px`; undefined unless both operators point the same way: `<` and `<=`, or `>` and `>=`. */
86
+ function readBetween([low, first, feature, second, high]) {
87
+ if (first === "=" || second === "=" || first.startsWith("<") !== second.startsWith("<")) return;
88
+ const above = compareSize(feature, FLIPPED[first], low);
89
+ const below = compareSize(feature, second, high);
90
+ if (above instanceof Unsupported) return above;
91
+ if (below instanceof Unsupported) return below;
92
+ return (state, remBase) => above(state, remBase) && below(state, remBase);
93
+ }
94
+ /** The test of a range: `width >= 600px`, `600px <= width`, `400px <= width < 800px`. */
95
+ function readRange(parts) {
96
+ let read;
97
+ if (parts.length === 3) read = readComparison(parts);
98
+ else if (parts.length === 5 && SIZE_FEATURES.has(parts[2])) read = readBetween(parts);
99
+ if (read !== void 0) return read;
100
+ const name = parts.find((part) => NAME.test(part) && !SIZE_FEATURES.has(part));
101
+ return new Unsupported(name === void 0 ? `the range "${parts.join(" ")}"` : `the media feature "${name}"`);
102
+ }
103
+ /** The test of the text inside one pair of parentheses. */
104
+ function readFeature(text) {
105
+ const colon = text.indexOf(":");
106
+ if (colon >= 0) return readPlainFeature(text.slice(0, colon).trim(), text.slice(colon + 1).trim());
107
+ const parts = text.split(RANGE).map((part) => part.trim());
108
+ if (parts.length > 1) return readRange(parts);
109
+ return new Unsupported(NAME.test(text) ? `the media feature "${text}"` : `the text "(${text})"`);
110
+ }
111
+ /** Whether `token` is a feature in parentheses. */
112
+ const isFeature = (token) => token !== void 0 && token.length > 1 && token.startsWith("(");
113
+ /** The tests of the features of `tokens` from `start`, joined by `and`; `invalid` when the tokens are not that, or what the binding cannot evaluate in a feature. */
114
+ function readFeatures(tokens, start, invalid) {
115
+ const tests = [];
116
+ let index = start;
117
+ for (;;) {
118
+ const token = tokens[index++];
119
+ if (!isFeature(token)) return invalid;
120
+ const test = readFeature(token.slice(1, -1).trim());
121
+ if (test instanceof Unsupported) return test;
122
+ tests.push(test);
123
+ if (index === tokens.length) return tests;
124
+ if (tokens[index++] !== "and") return invalid;
125
+ }
126
+ }
127
+ /** The tests of a query whose media type is at `index` of `tokens`: none for the type alone, else those of the features after its `and`. */
128
+ function readTypedFeatures(tokens, index, invalid) {
129
+ const type = tokens[index];
130
+ if (type !== "all" && type !== "screen") return new Unsupported(`the media type "${type}"`);
131
+ if (index + 1 === tokens.length) return [];
132
+ if (tokens[index + 1] !== "and") return invalid;
133
+ return readFeatures(tokens, index + 2, invalid);
134
+ }
135
+ /** The test of one query of a list: `not` or `only`, a media type, and features joined by `and`. */
136
+ function readQuery(text) {
137
+ const tokens = text.match(TOKEN) ?? [];
138
+ const invalid = new Unsupported(`the text "${text}"`);
139
+ const isNegated = tokens[0] === "not";
140
+ const index = isNegated || tokens[0] === "only" ? 1 : 0;
141
+ const type = tokens[index];
142
+ const tests = type !== void 0 && NAME.test(type) ? readTypedFeatures(tokens, index, invalid) : readFeatures(tokens, index, invalid);
143
+ if (tests instanceof Unsupported) return tests;
144
+ return (state, remBase) => tests.every((test) => test(state, remBase)) !== isNegated;
145
+ }
146
+ /** `text` read as a media query list, with or without `@media` in front. */
147
+ function parseMediaQuery(text) {
148
+ const list = text.replace(MEDIA_PREFIX, "").trim().toLowerCase();
149
+ const tests = [];
150
+ for (const part of list.split(",")) {
151
+ const test = readQuery(part.trim());
152
+ if (test instanceof Unsupported) return {
153
+ matches: matchNever,
154
+ problem: test.problem
155
+ };
156
+ tests.push(test);
157
+ }
158
+ return { matches: (state, remBase) => tests.some((test) => test(state, remBase)) };
159
+ }
160
+ const queries = /* @__PURE__ */ new Map();
161
+ /**
162
+ * The media query `text` (a key `@media (...)`, or the query alone, as `matchMedia` takes it), read once
163
+ * for each text. The subset: `width`, `height` and their `min-` and `max-` forms, the range forms
164
+ * (`width >= 600px`, `600px <= width`, `400px <= width < 800px`), `orientation`, `prefers-color-scheme`
165
+ * and `prefers-reduced-motion`, joined by `and`, in a comma list (any one matches), after `not` or
166
+ * `only` and the media type `all` or `screen`. A length is in `px` or has no unit (one pixel is one
167
+ * density-independent pixel), or is in `rem` or `em` (`remBase` pixels). A query with anything else
168
+ * never matches, and has a `problem` that names it.
169
+ */
170
+ function readMediaQuery(text) {
171
+ let query = queries.get(text);
172
+ if (query === void 0) {
173
+ query = parseMediaQuery(text);
174
+ queries.set(text, query);
175
+ }
176
+ return query;
177
+ }
178
+ export { isMediaKey, readMediaQuery };
@@ -0,0 +1,32 @@
1
+ import { ImageStyle, TextStyle, ViewStyle } from "react-native";
2
+ /** What a style of any one component takes: a view, a text or an image. */
3
+ type ComponentStyle = ViewStyle | TextStyle | ImageStyle;
4
+ type KeyOf<S> = S extends unknown ? keyof S : never;
5
+ /** The type of `K` in the members of `S` that have it. */
6
+ type ValueOf<S, K extends PropertyKey> = S extends unknown ? K extends keyof S ? S[K] : never : never;
7
+ /**
8
+ * A style for React Native: the keys of the platform's view, text and image styles, each with the value
9
+ * type of the platform. Nothing is nested, and there is no `label`: a key that is not the platform's is
10
+ * an error in an object literal.
11
+ */
12
+ export type NativeStyleObject = { [K in KeyOf<ComponentStyle>]?: ValueOf<ComponentStyle, K>; };
13
+ /** A set of named native styles. */
14
+ export type NativeSheetStyles = Record<string, NativeStyleObject>;
15
+ /** What a style function may return on React Native. */
16
+ export type NativeStyleResult = NativeStyleObject | null | undefined | false;
17
+ /** A native style that is computed from the props and the theme. */
18
+ export type NativeStyleFunction<T, P> = (props: P & {
19
+ theme: T;
20
+ }) => NativeStyleResult;
21
+ /** A native style object, or a function of the props and the theme; the defaults accept any function. */
22
+ export type NativeStyleInput<T = never, P = never> = NativeStyleObject | NativeStyleFunction<T, P>;
23
+ /**
24
+ * A native sheet given as an object: one style for each name. It is a record of styles with a function
25
+ * left out, so that a function of the theme is not taken for one (the compiler tries the object form first).
26
+ */
27
+ export type NativeObjectSheet<K extends string> = Record<K, NativeStyleObject> & {
28
+ call?: never;
29
+ };
30
+ /** What a native sheet is made from: one style for each name, or a function of the theme that returns them. */
31
+ export type NativeSheetInput<K extends string, T> = Record<K, NativeStyleObject> | ((theme: T) => Record<K, NativeStyleObject>);
32
+ export {};
@@ -0,0 +1,32 @@
1
+ import { ImageStyle, TextStyle, ViewStyle } from "react-native";
2
+ /** What a style of any one component takes: a view, a text or an image. */
3
+ type ComponentStyle = ViewStyle | TextStyle | ImageStyle;
4
+ type KeyOf<S> = S extends unknown ? keyof S : never;
5
+ /** The type of `K` in the members of `S` that have it. */
6
+ type ValueOf<S, K extends PropertyKey> = S extends unknown ? K extends keyof S ? S[K] : never : never;
7
+ /**
8
+ * A style for React Native: the keys of the platform's view, text and image styles, each with the value
9
+ * type of the platform. Nothing is nested, and there is no `label`: a key that is not the platform's is
10
+ * an error in an object literal.
11
+ */
12
+ export type NativeStyleObject = { [K in KeyOf<ComponentStyle>]?: ValueOf<ComponentStyle, K>; };
13
+ /** A set of named native styles. */
14
+ export type NativeSheetStyles = Record<string, NativeStyleObject>;
15
+ /** What a style function may return on React Native. */
16
+ export type NativeStyleResult = NativeStyleObject | null | undefined | false;
17
+ /** A native style that is computed from the props and the theme. */
18
+ export type NativeStyleFunction<T, P> = (props: P & {
19
+ theme: T;
20
+ }) => NativeStyleResult;
21
+ /** A native style object, or a function of the props and the theme; the defaults accept any function. */
22
+ export type NativeStyleInput<T = never, P = never> = NativeStyleObject | NativeStyleFunction<T, P>;
23
+ /**
24
+ * A native sheet given as an object: one style for each name. It is a record of styles with a function
25
+ * left out, so that a function of the theme is not taken for one (the compiler tries the object form first).
26
+ */
27
+ export type NativeObjectSheet<K extends string> = Record<K, NativeStyleObject> & {
28
+ call?: never;
29
+ };
30
+ /** What a native sheet is made from: one style for each name, or a function of the theme that returns them. */
31
+ export type NativeSheetInput<K extends string, T> = Record<K, NativeStyleObject> | ((theme: T) => Record<K, NativeStyleObject>);
32
+ export {};
@@ -0,0 +1,51 @@
1
+ let _umber_style_core = require("@umber-style/core");
2
+ const require_units = require("./units.cjs");
3
+ // src/nativeTheme.ts
4
+ /** The top-level theme keys whose values are lengths when no `lengthKeys` option is given: the default of the web. */
5
+ const DEFAULT_LENGTH_KEYS = [
6
+ "space",
7
+ "sizes",
8
+ "radii",
9
+ "fontSizes",
10
+ "borderWidths"
11
+ ];
12
+ /** Whether `value` is an object made by a literal, not a class instance. */
13
+ function isPlainObject(value) {
14
+ if (typeof value !== "object" || value === null) return false;
15
+ const prototype = Object.getPrototypeOf(value);
16
+ return prototype === Object.prototype || prototype === null;
17
+ }
18
+ /** `node` with each string that is a length (`px`, `rem` or no unit) a number; `node` itself when nothing changes. */
19
+ function convertLengths(node, remBase) {
20
+ if (typeof node === "string") return require_units.toLength(node, remBase) ?? node;
21
+ const isArray = Array.isArray(node);
22
+ if (!isArray && !isPlainObject(node)) return node;
23
+ const source = node;
24
+ let copy;
25
+ for (const key of Object.keys(source)) {
26
+ const value = source[key];
27
+ const converted = convertLengths(value, remBase);
28
+ if (converted === value) continue;
29
+ copy ??= Object.assign(isArray ? [] : {}, source);
30
+ copy[key] = converted;
31
+ }
32
+ return copy ?? node;
33
+ }
34
+ /**
35
+ * `theme` as React Native holds it: under each of `lengthKeys` (top-level keys), every string that is a
36
+ * length becomes a number, `rem` times `remBase`. Nothing else is touched (`breakpoints` and its helper
37
+ * functions included), and a theme with nothing to convert is returned as it is.
38
+ */
39
+ function toNativeTheme(theme, lengthKeys, remBase) {
40
+ const source = theme;
41
+ let changes;
42
+ for (const key of lengthKeys) {
43
+ const converted = convertLengths(source[key], remBase);
44
+ if (converted === source[key]) continue;
45
+ changes ??= {};
46
+ changes[key] = converted;
47
+ }
48
+ return changes ? (0, _umber_style_core.mergeDeep)(theme, changes) : theme;
49
+ }
50
+ exports.DEFAULT_LENGTH_KEYS = DEFAULT_LENGTH_KEYS;
51
+ exports.toNativeTheme = toNativeTheme;
@@ -0,0 +1,15 @@
1
+ /** The top-level theme keys whose values are lengths when no `lengthKeys` option is given: the default of the web. */
2
+ export declare const DEFAULT_LENGTH_KEYS: readonly ['space', 'sizes', 'radii', 'fontSizes', 'borderWidths'];
3
+ /** One of the default length keys of a theme. */
4
+ export type DefaultLengthKey = (typeof DEFAULT_LENGTH_KEYS)[number];
5
+ /**
6
+ * A theme value under a length key as React Native holds it: a string type that is a length (`'8px'`,
7
+ * `'1rem'`, `'8'`) is `number`, a plain `string` may have become one (`string | number`), any other
8
+ * string (`'50%'`, `'auto'`) and a function stay, and objects and arrays are mapped member by member.
9
+ */
10
+ export type NativeLength<V> = V extends `${number}px` | `${number}rem` | `${number}` ? number : V extends string ? string extends V ? string | number : V : V extends ((...args: never[]) => unknown) ? V : V extends object ? { [K in keyof V]: NativeLength<V[K]>; } : V;
11
+ /**
12
+ * The theme `T` as React Native holds it: the values under the default length keys (`space`, `sizes`,
13
+ * `radii`, `fontSizes`, `borderWidths`) are numbers where they were lengths, the rest is `T` itself.
14
+ */
15
+ export type NativeTheme<T> = { [K in keyof T]: K extends DefaultLengthKey ? NativeLength<T[K]> : T[K]; };
@@ -0,0 +1,15 @@
1
+ /** The top-level theme keys whose values are lengths when no `lengthKeys` option is given: the default of the web. */
2
+ export declare const DEFAULT_LENGTH_KEYS: readonly ['space', 'sizes', 'radii', 'fontSizes', 'borderWidths'];
3
+ /** One of the default length keys of a theme. */
4
+ export type DefaultLengthKey = (typeof DEFAULT_LENGTH_KEYS)[number];
5
+ /**
6
+ * A theme value under a length key as React Native holds it: a string type that is a length (`'8px'`,
7
+ * `'1rem'`, `'8'`) is `number`, a plain `string` may have become one (`string | number`), any other
8
+ * string (`'50%'`, `'auto'`) and a function stay, and objects and arrays are mapped member by member.
9
+ */
10
+ export type NativeLength<V> = V extends `${number}px` | `${number}rem` | `${number}` ? number : V extends string ? string extends V ? string | number : V : V extends ((...args: never[]) => unknown) ? V : V extends object ? { [K in keyof V]: NativeLength<V[K]>; } : V;
11
+ /**
12
+ * The theme `T` as React Native holds it: the values under the default length keys (`space`, `sizes`,
13
+ * `radii`, `fontSizes`, `borderWidths`) are numbers where they were lengths, the rest is `T` itself.
14
+ */
15
+ export type NativeTheme<T> = { [K in keyof T]: K extends DefaultLengthKey ? NativeLength<T[K]> : T[K]; };
@@ -0,0 +1,50 @@
1
+ import { mergeDeep } from "@umber-style/core";
2
+ import { toLength } from "./units.mjs";
3
+ // src/nativeTheme.ts
4
+ /** The top-level theme keys whose values are lengths when no `lengthKeys` option is given: the default of the web. */
5
+ const DEFAULT_LENGTH_KEYS = [
6
+ "space",
7
+ "sizes",
8
+ "radii",
9
+ "fontSizes",
10
+ "borderWidths"
11
+ ];
12
+ /** Whether `value` is an object made by a literal, not a class instance. */
13
+ function isPlainObject(value) {
14
+ if (typeof value !== "object" || value === null) return false;
15
+ const prototype = Object.getPrototypeOf(value);
16
+ return prototype === Object.prototype || prototype === null;
17
+ }
18
+ /** `node` with each string that is a length (`px`, `rem` or no unit) a number; `node` itself when nothing changes. */
19
+ function convertLengths(node, remBase) {
20
+ if (typeof node === "string") return toLength(node, remBase) ?? node;
21
+ const isArray = Array.isArray(node);
22
+ if (!isArray && !isPlainObject(node)) return node;
23
+ const source = node;
24
+ let copy;
25
+ for (const key of Object.keys(source)) {
26
+ const value = source[key];
27
+ const converted = convertLengths(value, remBase);
28
+ if (converted === value) continue;
29
+ copy ??= Object.assign(isArray ? [] : {}, source);
30
+ copy[key] = converted;
31
+ }
32
+ return copy ?? node;
33
+ }
34
+ /**
35
+ * `theme` as React Native holds it: under each of `lengthKeys` (top-level keys), every string that is a
36
+ * length becomes a number, `rem` times `remBase`. Nothing else is touched (`breakpoints` and its helper
37
+ * functions included), and a theme with nothing to convert is returned as it is.
38
+ */
39
+ function toNativeTheme(theme, lengthKeys, remBase) {
40
+ const source = theme;
41
+ let changes;
42
+ for (const key of lengthKeys) {
43
+ const converted = convertLengths(source[key], remBase);
44
+ if (converted === source[key]) continue;
45
+ changes ??= {};
46
+ changes[key] = converted;
47
+ }
48
+ return changes ? mergeDeep(theme, changes) : theme;
49
+ }
50
+ export { DEFAULT_LENGTH_KEYS, toNativeTheme };
@@ -0,0 +1,2 @@
1
+ import { StyleSheet as platformStyleSheet } from "react-native";
2
+ export { platformStyleSheet };
@@ -0,0 +1,2 @@
1
+ import { StyleSheet as platformStyleSheet } from "react-native";
2
+ export { platformStyleSheet };
@@ -0,0 +1 @@
1
+ export { AccessibilityInfo as platformAccessibility, Appearance as platformAppearance, Dimensions as platformDimensions, StyleSheet as platformStyleSheet } from "react-native";