@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,89 @@
1
+ let react = require("react");
2
+ const require_mediaQuery = require("./mediaQuery.cjs");
3
+ const require_warnStyle = require("./warnStyle.cjs");
4
+ let react_native = require("react-native");
5
+ // src/windowState.ts
6
+ /**
7
+ * Whether the system asks for reduced motion. The platform answers asynchronously, so this is false (no
8
+ * preference, the platform's default) until it does: the answer is asked for when the first component
9
+ * subscribes, and a change re-renders the components whose queries it changes.
10
+ */
11
+ let isReducedMotion = false;
12
+ const listeners = /* @__PURE__ */ new Set();
13
+ const subscriptions = [];
14
+ /** Tells every subscriber that the window or a system setting changed. */
15
+ function notify() {
16
+ for (const listener of listeners) listener();
17
+ }
18
+ function setReducedMotion(value) {
19
+ if (value === isReducedMotion) return;
20
+ isReducedMotion = value;
21
+ notify();
22
+ }
23
+ /** The window and the system settings now: the size and the color scheme are read from the platform, reduced motion is the last answer. */
24
+ function readWindowState() {
25
+ const { width, height } = react_native.Dimensions.get("window");
26
+ return {
27
+ width,
28
+ height,
29
+ colorScheme: react_native.Appearance.getColorScheme(),
30
+ isReducedMotion
31
+ };
32
+ }
33
+ /**
34
+ * Subscribes `listener` to the changes of the window size, the system color scheme and reduced motion.
35
+ * The binding listens to the platform once, for all its subscribers, while it has any.
36
+ */
37
+ function subscribeToWindow(listener) {
38
+ listeners.add(listener);
39
+ if (listeners.size === 1) {
40
+ subscriptions.push(react_native.Dimensions.addEventListener("change", notify), react_native.Appearance.addChangeListener(notify), react_native.AccessibilityInfo.addEventListener("reduceMotionChanged", setReducedMotion));
41
+ react_native.AccessibilityInfo.isReduceMotionEnabled().then(setReducedMotion);
42
+ }
43
+ return () => {
44
+ listeners.delete(listener);
45
+ if (listeners.size === 0) for (const subscription of subscriptions.splice(0)) subscription.remove();
46
+ };
47
+ }
48
+ const subscribeToNothing = () => () => {};
49
+ const readNothing = () => "";
50
+ /**
51
+ * The key of what `queries` give now: one character for each, `1` where it matches, then the system
52
+ * color scheme when `hasScheme` (for a `whenScheme()` key that no provider decides). Two renders with
53
+ * the same key resolve the same style.
54
+ */
55
+ function readMediaKey(queries, hasScheme, remBase) {
56
+ let key = "";
57
+ if (queries.length > 0) {
58
+ const state = readWindowState();
59
+ for (const query of queries) key += require_mediaQuery.readMediaQuery(query).matches(state, remBase) ? "1" : "0";
60
+ }
61
+ return hasScheme ? `${key}:${String(react_native.Appearance.getColorScheme())}` : key;
62
+ }
63
+ /**
64
+ * `readMediaKey` in a component, which renders again when the key changes, not when the width changes
65
+ * inside the same set of matching queries. With no query and no scheme it subscribes to nothing.
66
+ */
67
+ function useMediaKey(queries, hasScheme, remBase) {
68
+ const read = queries.length > 0 || hasScheme ? createKeyReader(queries, hasScheme, remBase) : readNothing;
69
+ return (0, react.useSyncExternalStore)(read === readNothing ? subscribeToNothing : subscribeToWindow, read, read);
70
+ }
71
+ /** `readMediaKey` of these arguments; made apart, so that a component that watches nothing makes no function. */
72
+ function createKeyReader(queries, hasScheme, remBase) {
73
+ return () => readMediaKey(queries, hasScheme, remBase);
74
+ }
75
+ /**
76
+ * Whether the media query `query` matches the window, on the store and the parser of the media keys of
77
+ * styles; the component renders again when the answer changes. A query the binding cannot evaluate is
78
+ * false, with a development warning. A render to a string gives `defaultMatches`.
79
+ */
80
+ function useMediaMatch(query, options, remBase) {
81
+ const { matches, problem } = require_mediaQuery.readMediaQuery(query);
82
+ if (problem !== void 0) require_warnStyle.warnAboutQuery(query, problem);
83
+ return (0, react.useSyncExternalStore)(problem === void 0 ? subscribeToWindow : subscribeToNothing, () => matches(readWindowState(), remBase), () => options.defaultMatches ?? false);
84
+ }
85
+ exports.readMediaKey = readMediaKey;
86
+ exports.readWindowState = readWindowState;
87
+ exports.subscribeToWindow = subscribeToWindow;
88
+ exports.useMediaKey = useMediaKey;
89
+ exports.useMediaMatch = useMediaMatch;
@@ -0,0 +1,6 @@
1
+ import "./mediaQuery.cjs";
2
+ /** The options of `useMediaQuery`. */
3
+ export interface MediaQueryOptions {
4
+ /** The answer of a render to a string, where there is no window. Default false. */
5
+ defaultMatches?: boolean;
6
+ }
@@ -0,0 +1,5 @@
1
+ /** The options of `useMediaQuery`. */
2
+ export interface MediaQueryOptions {
3
+ /** The answer of a render to a string, where there is no window. Default false. */
4
+ defaultMatches?: boolean;
5
+ }
@@ -0,0 +1,85 @@
1
+ import { useSyncExternalStore } from "react";
2
+ import { readMediaQuery } from "./mediaQuery.mjs";
3
+ import { platformAccessibility, platformAppearance, platformDimensions } from "./platform.mjs";
4
+ import { warnAboutQuery } from "./warnStyle.mjs";
5
+ // src/windowState.ts
6
+ /**
7
+ * Whether the system asks for reduced motion. The platform answers asynchronously, so this is false (no
8
+ * preference, the platform's default) until it does: the answer is asked for when the first component
9
+ * subscribes, and a change re-renders the components whose queries it changes.
10
+ */
11
+ let isReducedMotion = false;
12
+ const listeners = /* @__PURE__ */ new Set();
13
+ const subscriptions = [];
14
+ /** Tells every subscriber that the window or a system setting changed. */
15
+ function notify() {
16
+ for (const listener of listeners) listener();
17
+ }
18
+ function setReducedMotion(value) {
19
+ if (value === isReducedMotion) return;
20
+ isReducedMotion = value;
21
+ notify();
22
+ }
23
+ /** The window and the system settings now: the size and the color scheme are read from the platform, reduced motion is the last answer. */
24
+ function readWindowState() {
25
+ const { width, height } = platformDimensions.get("window");
26
+ return {
27
+ width,
28
+ height,
29
+ colorScheme: platformAppearance.getColorScheme(),
30
+ isReducedMotion
31
+ };
32
+ }
33
+ /**
34
+ * Subscribes `listener` to the changes of the window size, the system color scheme and reduced motion.
35
+ * The binding listens to the platform once, for all its subscribers, while it has any.
36
+ */
37
+ function subscribeToWindow(listener) {
38
+ listeners.add(listener);
39
+ if (listeners.size === 1) {
40
+ subscriptions.push(platformDimensions.addEventListener("change", notify), platformAppearance.addChangeListener(notify), platformAccessibility.addEventListener("reduceMotionChanged", setReducedMotion));
41
+ platformAccessibility.isReduceMotionEnabled().then(setReducedMotion);
42
+ }
43
+ return () => {
44
+ listeners.delete(listener);
45
+ if (listeners.size === 0) for (const subscription of subscriptions.splice(0)) subscription.remove();
46
+ };
47
+ }
48
+ const subscribeToNothing = () => () => {};
49
+ const readNothing = () => "";
50
+ /**
51
+ * The key of what `queries` give now: one character for each, `1` where it matches, then the system
52
+ * color scheme when `hasScheme` (for a `whenScheme()` key that no provider decides). Two renders with
53
+ * the same key resolve the same style.
54
+ */
55
+ function readMediaKey(queries, hasScheme, remBase) {
56
+ let key = "";
57
+ if (queries.length > 0) {
58
+ const state = readWindowState();
59
+ for (const query of queries) key += readMediaQuery(query).matches(state, remBase) ? "1" : "0";
60
+ }
61
+ return hasScheme ? `${key}:${String(platformAppearance.getColorScheme())}` : key;
62
+ }
63
+ /**
64
+ * `readMediaKey` in a component, which renders again when the key changes, not when the width changes
65
+ * inside the same set of matching queries. With no query and no scheme it subscribes to nothing.
66
+ */
67
+ function useMediaKey(queries, hasScheme, remBase) {
68
+ const read = queries.length > 0 || hasScheme ? createKeyReader(queries, hasScheme, remBase) : readNothing;
69
+ return useSyncExternalStore(read === readNothing ? subscribeToNothing : subscribeToWindow, read, read);
70
+ }
71
+ /** `readMediaKey` of these arguments; made apart, so that a component that watches nothing makes no function. */
72
+ function createKeyReader(queries, hasScheme, remBase) {
73
+ return () => readMediaKey(queries, hasScheme, remBase);
74
+ }
75
+ /**
76
+ * Whether the media query `query` matches the window, on the store and the parser of the media keys of
77
+ * styles; the component renders again when the answer changes. A query the binding cannot evaluate is
78
+ * false, with a development warning. A render to a string gives `defaultMatches`.
79
+ */
80
+ function useMediaMatch(query, options, remBase) {
81
+ const { matches, problem } = readMediaQuery(query);
82
+ if (problem !== void 0) warnAboutQuery(query, problem);
83
+ return useSyncExternalStore(problem === void 0 ? subscribeToWindow : subscribeToNothing, () => matches(readWindowState(), remBase), () => options.defaultMatches ?? false);
84
+ }
85
+ export { readMediaKey, readWindowState, subscribeToWindow, useMediaKey, useMediaMatch };
package/package.json CHANGED
@@ -1,10 +1,82 @@
1
1
  {
2
2
  "name": "@umber-style/react-native",
3
- "version": "0.0.0",
4
- "description": "Placeholder. The first release is on its way.",
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "UmberStyle for React Native: the same names as the React binding, over the real theme values.",
5
+ "keywords": [
6
+ "styling",
7
+ "theme",
8
+ "design-tokens",
9
+ "react-native",
10
+ "typescript"
11
+ ],
5
12
  "license": "MIT",
13
+ "author": "Masoud Soroush <masoud@soroush.tech>",
14
+ "homepage": "https://umber-style.soroush.design",
6
15
  "repository": {
7
16
  "type": "git",
8
- "url": "git+https://github.com/soroush-tech/umber-style.git"
9
- }
10
- }
17
+ "url": "git+https://github.com/soroush-tech/umber-style.git",
18
+ "directory": "packages/react-native"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/soroush-tech/umber-style/issues"
22
+ },
23
+ "type": "module",
24
+ "sideEffects": false,
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "exports": {
29
+ ".": {
30
+ "import": {
31
+ "types": "./dist/index.d.mts",
32
+ "default": "./dist/index.mjs"
33
+ },
34
+ "require": {
35
+ "types": "./dist/index.d.cts",
36
+ "default": "./dist/index.cjs"
37
+ }
38
+ }
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "dependencies": {
44
+ "@umber-style/core": "0.1.0-alpha.4"
45
+ },
46
+ "peerDependencies": {
47
+ "react": "^19.2.8",
48
+ "react-native": ">=0.76.0"
49
+ },
50
+ "peerDependenciesMeta": {
51
+ "react-native": {
52
+ "optional": true
53
+ }
54
+ },
55
+ "devDependencies": {
56
+ "@soroush.tech/bench": "^2.2.3",
57
+ "@testing-library/react": "^16.3.3",
58
+ "@types/node": "^26.6.6",
59
+ "@types/react": "^19.3.0",
60
+ "@types/react-dom": "^19.3.0",
61
+ "@vitest/coverage-v8": "^5.1.0",
62
+ "jsdom": "^31.0.0",
63
+ "oxlint": "^1.93.0",
64
+ "react": "^19.3.1",
65
+ "react-dom": "^19.3.1",
66
+ "react-native": "^0.88.1",
67
+ "tsdown": "^0.23.7",
68
+ "typescript": "~7.0.2",
69
+ "vitest": "^5.1.0",
70
+ "@umber-style/eslint-config": "0.0.0"
71
+ },
72
+ "scripts": {
73
+ "build": "tsdown",
74
+ "lint": "oxlint --deny-warnings",
75
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.augmentation.json && tsc --noEmit -p tsconfig.defaultStyle.json",
76
+ "test": "vitest run",
77
+ "test:coverage": "vitest run --coverage"
78
+ },
79
+ "main": "./dist/index.cjs",
80
+ "module": "./dist/index.mjs",
81
+ "types": "./dist/index.d.mts"
82
+ }