@gild-ui/react-native 0.0.0-stage → 0.1.0-alpha.0

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 (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +79 -2
  3. package/dist/Button.cjs +193 -0
  4. package/dist/Button.d.cts +3 -0
  5. package/dist/Button.d.mts +3 -0
  6. package/dist/Button.mjs +192 -0
  7. package/dist/Button.types-Bb9gBlbS.d.mts +1402 -0
  8. package/dist/Flex.cjs +18 -0
  9. package/dist/Flex.d.cts +2 -0
  10. package/dist/Flex.d.mts +2 -0
  11. package/dist/Flex.mjs +17 -0
  12. package/dist/Modal.cjs +56 -0
  13. package/dist/Modal.d.cts +7 -0
  14. package/dist/Modal.d.mts +7 -0
  15. package/dist/Modal.mjs +55 -0
  16. package/dist/TextInput.cjs +169 -0
  17. package/dist/TextInput.d.cts +3 -0
  18. package/dist/TextInput.d.mts +3 -0
  19. package/dist/TextInput.mjs +169 -0
  20. package/dist/ThemeProvider-BgTIjOfL.mjs +49 -0
  21. package/dist/ThemeProvider-CsfZi16_.cjs +53 -0
  22. package/dist/ThemeProvider.cjs +3 -0
  23. package/dist/ThemeProvider.d.cts +2 -0
  24. package/dist/ThemeProvider.d.mts +2 -0
  25. package/dist/ThemeProvider.mjs +1 -0
  26. package/dist/Typography.cjs +68 -0
  27. package/dist/Typography.d.cts +3 -0
  28. package/dist/Typography.d.mts +3 -0
  29. package/dist/Typography.mjs +68 -0
  30. package/dist/View-B1PzjpDr.cjs +76 -0
  31. package/dist/View-tHL6rDa8.mjs +65 -0
  32. package/dist/View.cjs +3 -0
  33. package/dist/View.d.cts +2 -0
  34. package/dist/View.d.mts +2 -0
  35. package/dist/View.mjs +1 -0
  36. package/dist/bridge-B_MGN7QY.d.mts +10 -0
  37. package/dist/bridge-CH-RnxIe.d.cts +10 -0
  38. package/dist/engine-CpEhmg4W.mjs +38 -0
  39. package/dist/engine-D9Z9l9JU.cjs +42 -0
  40. package/dist/engine.cjs +49 -0
  41. package/dist/engine.d.cts +66 -0
  42. package/dist/engine.d.mts +66 -0
  43. package/dist/engine.mjs +19 -0
  44. package/dist/exact-DOxXx2ZR.d.cts +9 -0
  45. package/dist/exact-DOxXx2ZR.d.mts +9 -0
  46. package/dist/index-BqhozwWy.d.mts +41 -0
  47. package/dist/index-DcHJkXar.d.cts +41 -0
  48. package/dist/index.cjs +67 -0
  49. package/dist/index.d.cts +14 -0
  50. package/dist/index.d.mts +14 -0
  51. package/dist/index.mjs +5 -0
  52. package/dist/phoneTheme-RIafDzgw.mjs +12 -0
  53. package/dist/phoneTheme-kvZTk6l5.cjs +29 -0
  54. package/dist/styled-CmWGOVKb.cjs +174 -0
  55. package/dist/styled-k66N0ABX.mjs +163 -0
  56. package/dist/themes-DK6h0IiW.d.cts +1402 -0
  57. package/dist/themes-rGHVhV5e.mjs +8 -0
  58. package/dist/useDefaultProps-1josiKIp.mjs +13 -0
  59. package/dist/useDefaultProps-DzaUOADT.cjs +18 -0
  60. package/dist/useTheme.cjs +8 -0
  61. package/dist/useTheme.d.cts +3 -0
  62. package/dist/useTheme.d.mts +3 -0
  63. package/dist/useTheme.mjs +1 -0
  64. package/package.json +172 -3
@@ -0,0 +1,41 @@
1
+ import "./bridge-B_MGN7QY.mjs";
2
+ import { d as AppTheme, m as Theme$1 } from "./Button.types-Bb9gBlbS.mjs";
3
+ import { t as Exact } from "./exact-DOxXx2ZR.mjs";
4
+ import { Register, ThemeDefaults } from "@gild-ui/core/theme";
5
+ import { ReactElement, ReactNode } from "react";
6
+ interface ThemeProviderOwnProps<T> {
7
+ children?: ReactNode;
8
+ /**
9
+ * The active theme. Bring one theme, or as many as you like - switching
10
+ * between them is your state, not the provider's. Defaults to the built-in
11
+ * `baseTheme`.
12
+ */
13
+ theme?: T & Exact<T, AppTheme>;
14
+ /**
15
+ * Optional component default token/variant keys, merged into the theme
16
+ * (e.g. `{ size: 'compact' }` makes every sized component default to your key).
17
+ * Two objects with the same contents give the same theme, so an inline literal is fine.
18
+ */
19
+ defaults?: ThemeDefaults;
20
+ }
21
+ /** The props once the app registers its themes: it has no built-in theme to fall back to, so `theme` is required. */
22
+ interface RegisteredThemeProviderProps<T> {
23
+ children?: ReactNode;
24
+ /** The active theme: one of the registered themes. Switching between them is your state, not the provider's. */
25
+ theme: T & Exact<T, AppTheme>;
26
+ /**
27
+ * Optional component default token/variant keys, merged into the theme
28
+ * (e.g. `{ size: 'compact' }` makes every sized component default to your key).
29
+ * Two objects with the same contents give the same theme, so an inline literal is fine.
30
+ */
31
+ defaults?: ThemeDefaults;
32
+ }
33
+ type ThemeProviderProps<T = Theme$1> = Register extends {
34
+ themes: unknown;
35
+ } ? RegisteredThemeProviderProps<T> : ThemeProviderOwnProps<T>;
36
+ /**
37
+ * The theme of the subtree: the same props as `@gild-ui/react`'s provider, over the binding for
38
+ * phones. It renders no element, so there is nothing to server-render and no class to hydrate.
39
+ */
40
+ declare function ThemeProvider<T extends Theme$1 = Theme$1>(props: Readonly<ThemeProviderProps<T>>): ReactElement;
41
+ export { ThemeProvider as t };
@@ -0,0 +1,41 @@
1
+ import "./bridge-CH-RnxIe.cjs";
2
+ import { i as Theme$1, t as AppTheme } from "./themes-DK6h0IiW.cjs";
3
+ import { t as Exact } from "./exact-DOxXx2ZR.cjs";
4
+ import { Register, ThemeDefaults } from "@gild-ui/core/theme";
5
+ import { ReactElement, ReactNode } from "react";
6
+ interface ThemeProviderOwnProps<T> {
7
+ children?: ReactNode;
8
+ /**
9
+ * The active theme. Bring one theme, or as many as you like - switching
10
+ * between them is your state, not the provider's. Defaults to the built-in
11
+ * `baseTheme`.
12
+ */
13
+ theme?: T & Exact<T, AppTheme>;
14
+ /**
15
+ * Optional component default token/variant keys, merged into the theme
16
+ * (e.g. `{ size: 'compact' }` makes every sized component default to your key).
17
+ * Two objects with the same contents give the same theme, so an inline literal is fine.
18
+ */
19
+ defaults?: ThemeDefaults;
20
+ }
21
+ /** The props once the app registers its themes: it has no built-in theme to fall back to, so `theme` is required. */
22
+ interface RegisteredThemeProviderProps<T> {
23
+ children?: ReactNode;
24
+ /** The active theme: one of the registered themes. Switching between them is your state, not the provider's. */
25
+ theme: T & Exact<T, AppTheme>;
26
+ /**
27
+ * Optional component default token/variant keys, merged into the theme
28
+ * (e.g. `{ size: 'compact' }` makes every sized component default to your key).
29
+ * Two objects with the same contents give the same theme, so an inline literal is fine.
30
+ */
31
+ defaults?: ThemeDefaults;
32
+ }
33
+ type ThemeProviderProps<T = Theme$1> = Register extends {
34
+ themes: unknown;
35
+ } ? RegisteredThemeProviderProps<T> : ThemeProviderOwnProps<T>;
36
+ /**
37
+ * The theme of the subtree: the same props as `@gild-ui/react`'s provider, over the binding for
38
+ * phones. It renders no element, so there is nothing to server-render and no class to hydrate.
39
+ */
40
+ declare function ThemeProvider<T extends Theme$1 = Theme$1>(props: Readonly<ThemeProviderProps<T>>): ReactElement;
41
+ export { ThemeProvider as t };
package/dist/index.cjs ADDED
@@ -0,0 +1,67 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_ThemeProvider = require("./ThemeProvider-CsfZi16_.cjs");
3
+ require("./useTheme.cjs");
4
+ const require_useDefaultProps = require("./useDefaultProps-DzaUOADT.cjs");
5
+ let _umber_style_react_native = require("@umber-style/react-native");
6
+ Object.defineProperty(exports, "StyleSheet", {
7
+ enumerable: true,
8
+ get: function() {
9
+ return _umber_style_react_native.StyleSheet;
10
+ }
11
+ });
12
+ exports.ThemeProvider = require_ThemeProvider.ThemeProvider;
13
+ Object.defineProperty(exports, "alpha", {
14
+ enumerable: true,
15
+ get: function() {
16
+ return _umber_style_react_native.alpha;
17
+ }
18
+ });
19
+ Object.defineProperty(exports, "css", {
20
+ enumerable: true,
21
+ get: function() {
22
+ return _umber_style_react_native.css;
23
+ }
24
+ });
25
+ Object.defineProperty(exports, "keyframes", {
26
+ enumerable: true,
27
+ get: function() {
28
+ return _umber_style_react_native.keyframes;
29
+ }
30
+ });
31
+ Object.defineProperty(exports, "negate", {
32
+ enumerable: true,
33
+ get: function() {
34
+ return _umber_style_react_native.negate;
35
+ }
36
+ });
37
+ exports.useDefaultProps = require_useDefaultProps.useDefaultProps;
38
+ Object.defineProperty(exports, "useMediaQuery", {
39
+ enumerable: true,
40
+ get: function() {
41
+ return _umber_style_react_native.useMediaQuery;
42
+ }
43
+ });
44
+ Object.defineProperty(exports, "useStyle", {
45
+ enumerable: true,
46
+ get: function() {
47
+ return _umber_style_react_native.useStyle;
48
+ }
49
+ });
50
+ Object.defineProperty(exports, "useTheme", {
51
+ enumerable: true,
52
+ get: function() {
53
+ return _umber_style_react_native.useTheme;
54
+ }
55
+ });
56
+ Object.defineProperty(exports, "withStyle", {
57
+ enumerable: true,
58
+ get: function() {
59
+ return _umber_style_react_native.withStyle;
60
+ }
61
+ });
62
+ Object.defineProperty(exports, "withTheme", {
63
+ enumerable: true,
64
+ get: function() {
65
+ return _umber_style_react_native.withTheme;
66
+ }
67
+ });
@@ -0,0 +1,14 @@
1
+ import { t as ThemeProvider } from "./index-DcHJkXar.cjs";
2
+ import { useTheme } from "./useTheme.cjs";
3
+ import { a as ThemeComponents, n as ComponentConfig, nt as SlotProps, rt as StyleOverride, tt as SlotOverride } from "./themes-DK6h0IiW.cjs";
4
+ import { StyleSheet, alpha, css, keyframes, negate, useMediaQuery, useStyle, withStyle, withTheme } from "@umber-style/react-native";
5
+ type DefaultPropsOf<N extends keyof ThemeComponents> = Partial<NonNullable<NonNullable<ThemeComponents[N]>['$owner']>>;
6
+ /**
7
+ * The theme-contributed default prop values for a component
8
+ * (`theme.components[name].defaultProps`), or an empty object.
9
+ *
10
+ * Components apply it as one step of the default-resolution chain:
11
+ * explicit prop → group context → `useDefaultProps` → `theme.defaults.*` → literal fallback.
12
+ */
13
+ export declare function useDefaultProps<N extends keyof ThemeComponents>(name: N): DefaultPropsOf<N>;
14
+ export { type ComponentConfig, type SlotOverride, type SlotProps, type StyleOverride, StyleSheet, type ThemeComponents, ThemeProvider, alpha, css, keyframes, negate, useMediaQuery, useStyle, useTheme, withStyle, withTheme };
@@ -0,0 +1,14 @@
1
+ import { t as ThemeProvider } from "./index-BqhozwWy.mjs";
2
+ import { useTheme } from "./useTheme.mjs";
3
+ import { f as ComponentConfig, h as ThemeComponents, it as StyleOverride, nt as SlotOverride, rt as SlotProps } from "./Button.types-Bb9gBlbS.mjs";
4
+ import { StyleSheet, alpha, css, keyframes, negate, useMediaQuery, useStyle, withStyle, withTheme } from "@umber-style/react-native";
5
+ type DefaultPropsOf<N extends keyof ThemeComponents> = Partial<NonNullable<NonNullable<ThemeComponents[N]>['$owner']>>;
6
+ /**
7
+ * The theme-contributed default prop values for a component
8
+ * (`theme.components[name].defaultProps`), or an empty object.
9
+ *
10
+ * Components apply it as one step of the default-resolution chain:
11
+ * explicit prop → group context → `useDefaultProps` → `theme.defaults.*` → literal fallback.
12
+ */
13
+ export declare function useDefaultProps<N extends keyof ThemeComponents>(name: N): DefaultPropsOf<N>;
14
+ export { type ComponentConfig, type SlotOverride, type SlotProps, type StyleOverride, StyleSheet, type ThemeComponents, ThemeProvider, alpha, css, keyframes, negate, useMediaQuery, useStyle, useTheme, withStyle, withTheme };
package/dist/index.mjs ADDED
@@ -0,0 +1,5 @@
1
+ import { t as ThemeProvider } from "./ThemeProvider-BgTIjOfL.mjs";
2
+ import { useTheme } from "./useTheme.mjs";
3
+ import { t as useDefaultProps } from "./useDefaultProps-1josiKIp.mjs";
4
+ import { StyleSheet, alpha, css, keyframes, negate, useMediaQuery, useStyle, withStyle, withTheme } from "@umber-style/react-native";
5
+ export { StyleSheet, ThemeProvider, alpha, css, keyframes, negate, useDefaultProps, useMediaQuery, useStyle, useTheme, withStyle, withTheme };
@@ -0,0 +1,12 @@
1
+ // src/phoneTheme.ts
2
+ const EM_POINTS = 16;
3
+ const inPoints = (spacing) => /\dem$/.test(spacing) ? `${Number.parseFloat(spacing) * EM_POINTS}px` : spacing;
4
+ /** The theme as a phone reads it: the same, with its letter spacings in points instead of em. */
5
+ const phoneTheme = (theme) => ({
6
+ ...theme,
7
+ letterSpacings: {
8
+ ...theme.letterSpacings,
9
+ ...Object.fromEntries(Object.entries(theme.letterSpacings).map(([name, spacing]) => [name, inPoints(spacing)]))
10
+ }
11
+ });
12
+ export { phoneTheme as t };
@@ -0,0 +1,29 @@
1
+ // ../react/src/theme/themes.ts
2
+ /**
3
+ * The core's base theme, typed as this package's `Theme` - the same object. `createTheme(baseTheme, ...)`
4
+ * then accepts and returns `theme.components` too.
5
+ */
6
+ const baseTheme = require("@gild-ui/core/theme").baseTheme;
7
+ // src/phoneTheme.ts
8
+ const EM_POINTS = 16;
9
+ const inPoints = (spacing) => /\dem$/.test(spacing) ? `${Number.parseFloat(spacing) * EM_POINTS}px` : spacing;
10
+ /** The theme as a phone reads it: the same, with its letter spacings in points instead of em. */
11
+ const phoneTheme = (theme) => ({
12
+ ...theme,
13
+ letterSpacings: {
14
+ ...theme.letterSpacings,
15
+ ...Object.fromEntries(Object.entries(theme.letterSpacings).map(([name, spacing]) => [name, inPoints(spacing)]))
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "baseTheme", {
19
+ enumerable: true,
20
+ get: function() {
21
+ return baseTheme;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "phoneTheme", {
25
+ enumerable: true,
26
+ get: function() {
27
+ return phoneTheme;
28
+ }
29
+ });
@@ -0,0 +1,174 @@
1
+ let _umber_style_react_native = require("@umber-style/react-native");
2
+ let react = require("react");
3
+ let react_native = require("react-native");
4
+ let _umber_style_is_prop_valid_react = require("@umber-style/is-prop-valid/react");
5
+ let _umber_style_is_prop_valid_react_native = require("@umber-style/is-prop-valid/react-native");
6
+ let _soroush_tech_styled_system_core = require("@soroush.tech/styled-system/core");
7
+ // src/platform/overrides.ts
8
+ /**
9
+ * Several overrides of one element, merged in order: the later wins. The same as on the web, but typed
10
+ * as an open record: a shared source spreads it into a component typed over the web engine, whose
11
+ * `style` is not the binding's, and what the spread carries is checked where the override is declared.
12
+ */
13
+ function mergeOverrides(...parts) {
14
+ const styles = parts.flatMap((part) => part?.style ? [part.style] : []);
15
+ return {
16
+ ...Object.assign({}, ...parts),
17
+ className: parts.map((part) => part?.className).filter(Boolean).join(" ") || void 0,
18
+ style: styles.length > 1 ? styles : styles[0]
19
+ };
20
+ }
21
+ // src/platform/styled.ts
22
+ const hosts = {
23
+ button: react_native.Pressable,
24
+ img: react_native.Image,
25
+ input: react_native.TextInput,
26
+ textarea: react_native.TextInput,
27
+ p: react_native.Text,
28
+ span: react_native.Text,
29
+ label: react_native.Text,
30
+ a: react_native.Text,
31
+ strong: react_native.Text,
32
+ em: react_native.Text,
33
+ small: react_native.Text,
34
+ code: react_native.Text,
35
+ time: react_native.Text,
36
+ h1: react_native.Text,
37
+ h2: react_native.Text,
38
+ h3: react_native.Text,
39
+ h4: react_native.Text,
40
+ h5: react_native.Text,
41
+ h6: react_native.Text
42
+ };
43
+ const headings = /* @__PURE__ */ new Set([
44
+ "h1",
45
+ "h2",
46
+ "h3",
47
+ "h4",
48
+ "h5",
49
+ "h6"
50
+ ]);
51
+ /** The element a tag stands for; a component stands for itself. */
52
+ const hostOf = (tag) => typeof tag === "string" ? hosts[tag] ?? react_native.View : tag;
53
+ /**
54
+ * Which props reach the element. A component of the web filters its props with the web's list (what
55
+ * `createShouldForwardProp` of the style props does), which has no `testID` and has `className`. On a
56
+ * phone a prop reaches the element when the native views know it, and the filter of the component
57
+ * agrees whenever the web's list knows the prop too; a prop only the phone knows (`testID`,
58
+ * `accessibilityLabel`) is not one the component filters out. `className` and `data-*` are not native
59
+ * props: they are accepted and not passed on.
60
+ */
61
+ const forwardsProp = (filter) => (prop) => (0, _umber_style_is_prop_valid_react_native.isPropValid)(prop) && ((0, _umber_style_is_prop_valid_react.isPropValid)(prop) ? filter?.(prop) ?? true : true);
62
+ const keyboards = {
63
+ email: "email-address",
64
+ number: "numeric",
65
+ tel: "phone-pad",
66
+ url: "url"
67
+ };
68
+ const InText = (0, react.createContext)(false);
69
+ const defaultColor = ({ theme, nestedText }) => nestedText ? {} : { color: theme.text.initial };
70
+ /** What `value` of a text input reads as `event.target.value`, built from the native change event. */
71
+ const webChange = (handler) => typeof handler === "function" ? (event) => {
72
+ const target = { value: event.nativeEvent.text };
73
+ handler({
74
+ ...event,
75
+ target,
76
+ currentTarget: target
77
+ });
78
+ } : void 0;
79
+ /** The props of a text input of the web as the native one takes them. */
80
+ const textInputProps = (tag, { type, rows, disabled, readOnly, onChange }) => ({
81
+ editable: !(disabled || readOnly),
82
+ secureTextEntry: type === "password" || void 0,
83
+ keyboardType: type === void 0 ? void 0 : keyboards[type],
84
+ multiline: tag === "textarea" || void 0,
85
+ numberOfLines: rows === void 0 ? void 0 : Number(rows),
86
+ onChange: webChange(onChange)
87
+ });
88
+ /**
89
+ * What a component of the web writes and a native element reads differently: `as` takes a tag, a
90
+ * heading tag says so to the screen reader, `data-testid` is the one `data-*` attribute that has a
91
+ * native name (`testID`), `onClick` is `onPress`, and a text input takes its props as the native one
92
+ * names them (`textInputProps`).
93
+ */
94
+ function withTags(Styled, tag) {
95
+ const Tagged = ({ as, role, "data-testid": dataTestId, testID = dataTestId, onClick, onPress = onClick, ...props }) => {
96
+ const target = as ?? tag;
97
+ const isInput = hostOf(target) === react_native.TextInput;
98
+ const nestedText = (0, react.useContext)(InText);
99
+ const element = (0, react.createElement)(Styled, {
100
+ ...props,
101
+ nestedText,
102
+ ...isInput && textInputProps(target, props),
103
+ testID,
104
+ onPress,
105
+ as: as === void 0 ? void 0 : hostOf(as),
106
+ role: role ?? (typeof target === "string" && headings.has(target) ? "heading" : void 0)
107
+ });
108
+ return hostOf(target) === react_native.Text ? (0, react.createElement)(InText.Provider, { value: true }, element) : element;
109
+ };
110
+ return Tagged;
111
+ }
112
+ const flat = (value) => Array.isArray(value) ? Object.assign({}, ...value.map(flat)) : value;
113
+ const flattened = (style) => typeof style === "function" ? (...args) => flat(Reflect.apply(style, void 0, args)) : style;
114
+ /** `styled` of the engine's web binding, over the base elements of a phone. */
115
+ const styled$1 = Object.assign((tag, { shouldForwardProp, ...options } = {}) => {
116
+ const create = (0, _umber_style_react_native.styled)(hostOf(tag), {
117
+ ...options,
118
+ shouldForwardProp: forwardsProp(shouldForwardProp)
119
+ });
120
+ const own = hostOf(tag) === react_native.Text ? [defaultColor] : [];
121
+ return (...styles) => withTags(Reflect.apply(create, void 0, [...own, ...styles].map(flattened)), tag);
122
+ }, _umber_style_react_native.styled);
123
+ // ../react/src/style/styled.ts
124
+ const resolveStyle = (style, props) => typeof style === "function" ? style({
125
+ theme: props.theme,
126
+ ownerState: props
127
+ }) : style;
128
+ const matchesProps = (props, matcher) => Object.entries(matcher).every(([key, value]) => props[key] === value);
129
+ const orderedBlocks = /* @__PURE__ */ new WeakMap();
130
+ /** The interpolation that closes the system props of a root; exported for its test. */
131
+ const mediaOrder = ({ theme }) => {
132
+ const breakpoints = theme?.breakpoints;
133
+ if (!breakpoints) return {};
134
+ let blocks = orderedBlocks.get(breakpoints);
135
+ if (!blocks) {
136
+ const widths = Object.fromEntries(Object.entries(breakpoints).map(([name, value]) => [name, String(value)]));
137
+ blocks = Object.fromEntries((0, _soroush_tech_styled_system_core.responsiveQueries)(widths).order.map((query) => [query, {}]));
138
+ orderedBlocks.set(breakpoints, blocks);
139
+ }
140
+ return blocks;
141
+ };
142
+ const createThemedStyled = (tag, options = {}) => {
143
+ const { name, slot = "root", systemProps = [], overridesResolver, ...engineOptions } = options;
144
+ const create = styled$1(tag, engineOptions);
145
+ if (name === void 0) return create;
146
+ const themeStyles = (props) => {
147
+ const config = props.theme.components?.[name];
148
+ if (!config) return null;
149
+ const applied = [];
150
+ if (config.styleOverrides) applied.push(overridesResolver ? overridesResolver(props, config.styleOverrides) : resolveStyle(config.styleOverrides[slot], props));
151
+ if (slot === "root" && config.variants) {
152
+ for (const entry of config.variants) if (matchesProps(props, entry.props)) applied.push(resolveStyle(entry.style, props));
153
+ }
154
+ return applied;
155
+ };
156
+ return (...styles) => create(...styles, themeStyles, ...systemProps, ...systemProps.length > 0 ? [mediaOrder] : []);
157
+ };
158
+ /**
159
+ * The design system's `styled` - the engine's styled plus theme-level component
160
+ * customization (`theme.components[name].styleOverrides` / `.variants`).
161
+ */
162
+ const styled = Object.assign(createThemedStyled, styled$1);
163
+ Object.defineProperty(exports, "mergeOverrides", {
164
+ enumerable: true,
165
+ get: function() {
166
+ return mergeOverrides;
167
+ }
168
+ });
169
+ Object.defineProperty(exports, "styled", {
170
+ enumerable: true,
171
+ get: function() {
172
+ return styled;
173
+ }
174
+ });
@@ -0,0 +1,163 @@
1
+ import { styled as styled$2 } from "@umber-style/react-native";
2
+ import { createContext, createElement, useContext } from "react";
3
+ import { Image, Pressable, Text, TextInput, View } from "react-native";
4
+ import { isPropValid } from "@umber-style/is-prop-valid/react";
5
+ import { isPropValid as isPropValid$1 } from "@umber-style/is-prop-valid/react-native";
6
+ import { responsiveQueries } from "@soroush.tech/styled-system/core";
7
+ // src/platform/overrides.ts
8
+ /**
9
+ * Several overrides of one element, merged in order: the later wins. The same as on the web, but typed
10
+ * as an open record: a shared source spreads it into a component typed over the web engine, whose
11
+ * `style` is not the binding's, and what the spread carries is checked where the override is declared.
12
+ */
13
+ function mergeOverrides(...parts) {
14
+ const styles = parts.flatMap((part) => part?.style ? [part.style] : []);
15
+ return {
16
+ ...Object.assign({}, ...parts),
17
+ className: parts.map((part) => part?.className).filter(Boolean).join(" ") || void 0,
18
+ style: styles.length > 1 ? styles : styles[0]
19
+ };
20
+ }
21
+ // src/platform/styled.ts
22
+ const hosts = {
23
+ button: Pressable,
24
+ img: Image,
25
+ input: TextInput,
26
+ textarea: TextInput,
27
+ p: Text,
28
+ span: Text,
29
+ label: Text,
30
+ a: Text,
31
+ strong: Text,
32
+ em: Text,
33
+ small: Text,
34
+ code: Text,
35
+ time: Text,
36
+ h1: Text,
37
+ h2: Text,
38
+ h3: Text,
39
+ h4: Text,
40
+ h5: Text,
41
+ h6: Text
42
+ };
43
+ const headings = /* @__PURE__ */ new Set([
44
+ "h1",
45
+ "h2",
46
+ "h3",
47
+ "h4",
48
+ "h5",
49
+ "h6"
50
+ ]);
51
+ /** The element a tag stands for; a component stands for itself. */
52
+ const hostOf = (tag) => typeof tag === "string" ? hosts[tag] ?? View : tag;
53
+ /**
54
+ * Which props reach the element. A component of the web filters its props with the web's list (what
55
+ * `createShouldForwardProp` of the style props does), which has no `testID` and has `className`. On a
56
+ * phone a prop reaches the element when the native views know it, and the filter of the component
57
+ * agrees whenever the web's list knows the prop too; a prop only the phone knows (`testID`,
58
+ * `accessibilityLabel`) is not one the component filters out. `className` and `data-*` are not native
59
+ * props: they are accepted and not passed on.
60
+ */
61
+ const forwardsProp = (filter) => (prop) => isPropValid$1(prop) && (isPropValid(prop) ? filter?.(prop) ?? true : true);
62
+ const keyboards = {
63
+ email: "email-address",
64
+ number: "numeric",
65
+ tel: "phone-pad",
66
+ url: "url"
67
+ };
68
+ const InText = createContext(false);
69
+ const defaultColor = ({ theme, nestedText }) => nestedText ? {} : { color: theme.text.initial };
70
+ /** What `value` of a text input reads as `event.target.value`, built from the native change event. */
71
+ const webChange = (handler) => typeof handler === "function" ? (event) => {
72
+ const target = { value: event.nativeEvent.text };
73
+ handler({
74
+ ...event,
75
+ target,
76
+ currentTarget: target
77
+ });
78
+ } : void 0;
79
+ /** The props of a text input of the web as the native one takes them. */
80
+ const textInputProps = (tag, { type, rows, disabled, readOnly, onChange }) => ({
81
+ editable: !(disabled || readOnly),
82
+ secureTextEntry: type === "password" || void 0,
83
+ keyboardType: type === void 0 ? void 0 : keyboards[type],
84
+ multiline: tag === "textarea" || void 0,
85
+ numberOfLines: rows === void 0 ? void 0 : Number(rows),
86
+ onChange: webChange(onChange)
87
+ });
88
+ /**
89
+ * What a component of the web writes and a native element reads differently: `as` takes a tag, a
90
+ * heading tag says so to the screen reader, `data-testid` is the one `data-*` attribute that has a
91
+ * native name (`testID`), `onClick` is `onPress`, and a text input takes its props as the native one
92
+ * names them (`textInputProps`).
93
+ */
94
+ function withTags(Styled, tag) {
95
+ const Tagged = ({ as, role, "data-testid": dataTestId, testID = dataTestId, onClick, onPress = onClick, ...props }) => {
96
+ const target = as ?? tag;
97
+ const isInput = hostOf(target) === TextInput;
98
+ const nestedText = useContext(InText);
99
+ const element = createElement(Styled, {
100
+ ...props,
101
+ nestedText,
102
+ ...isInput && textInputProps(target, props),
103
+ testID,
104
+ onPress,
105
+ as: as === void 0 ? void 0 : hostOf(as),
106
+ role: role ?? (typeof target === "string" && headings.has(target) ? "heading" : void 0)
107
+ });
108
+ return hostOf(target) === Text ? createElement(InText.Provider, { value: true }, element) : element;
109
+ };
110
+ return Tagged;
111
+ }
112
+ const flat = (value) => Array.isArray(value) ? Object.assign({}, ...value.map(flat)) : value;
113
+ const flattened = (style) => typeof style === "function" ? (...args) => flat(Reflect.apply(style, void 0, args)) : style;
114
+ /** `styled` of the engine's web binding, over the base elements of a phone. */
115
+ const styled$1 = Object.assign((tag, { shouldForwardProp, ...options } = {}) => {
116
+ const create = styled$2(hostOf(tag), {
117
+ ...options,
118
+ shouldForwardProp: forwardsProp(shouldForwardProp)
119
+ });
120
+ const own = hostOf(tag) === Text ? [defaultColor] : [];
121
+ return (...styles) => withTags(Reflect.apply(create, void 0, [...own, ...styles].map(flattened)), tag);
122
+ }, styled$2);
123
+ // ../react/src/style/styled.ts
124
+ const resolveStyle = (style, props) => typeof style === "function" ? style({
125
+ theme: props.theme,
126
+ ownerState: props
127
+ }) : style;
128
+ const matchesProps = (props, matcher) => Object.entries(matcher).every(([key, value]) => props[key] === value);
129
+ const orderedBlocks = /* @__PURE__ */ new WeakMap();
130
+ /** The interpolation that closes the system props of a root; exported for its test. */
131
+ const mediaOrder = ({ theme }) => {
132
+ const breakpoints = theme?.breakpoints;
133
+ if (!breakpoints) return {};
134
+ let blocks = orderedBlocks.get(breakpoints);
135
+ if (!blocks) {
136
+ const widths = Object.fromEntries(Object.entries(breakpoints).map(([name, value]) => [name, String(value)]));
137
+ blocks = Object.fromEntries(responsiveQueries(widths).order.map((query) => [query, {}]));
138
+ orderedBlocks.set(breakpoints, blocks);
139
+ }
140
+ return blocks;
141
+ };
142
+ const createThemedStyled = (tag, options = {}) => {
143
+ const { name, slot = "root", systemProps = [], overridesResolver, ...engineOptions } = options;
144
+ const create = styled$1(tag, engineOptions);
145
+ if (name === void 0) return create;
146
+ const themeStyles = (props) => {
147
+ const config = props.theme.components?.[name];
148
+ if (!config) return null;
149
+ const applied = [];
150
+ if (config.styleOverrides) applied.push(overridesResolver ? overridesResolver(props, config.styleOverrides) : resolveStyle(config.styleOverrides[slot], props));
151
+ if (slot === "root" && config.variants) {
152
+ for (const entry of config.variants) if (matchesProps(props, entry.props)) applied.push(resolveStyle(entry.style, props));
153
+ }
154
+ return applied;
155
+ };
156
+ return (...styles) => create(...styles, themeStyles, ...systemProps, ...systemProps.length > 0 ? [mediaOrder] : []);
157
+ };
158
+ /**
159
+ * The design system's `styled` - the engine's styled plus theme-level component
160
+ * customization (`theme.components[name].styleOverrides` / `.variants`).
161
+ */
162
+ const styled = Object.assign(createThemedStyled, styled$1);
163
+ export { mergeOverrides as n, styled as t };