react-native-boost 0.5.7 → 0.6.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.
@@ -174,9 +174,9 @@ function processProps(
174
174
  // Set up the accessibility import
175
175
  const normalizeIdentifier = addFileImportHint({
176
176
  file,
177
- nameHint: 'normalizeAccessibilityProps',
177
+ nameHint: 'processAccessibilityProps',
178
178
  path,
179
- importName: 'normalizeAccessibilityProps',
179
+ importName: 'processAccessibilityProps',
180
180
  moduleName: RUNTIME_MODULE_NAME,
181
181
  });
182
182
  const accessibilityObject = buildPropertiesFromAttributes(accessibilityAttributes);
@@ -185,9 +185,9 @@ function processProps(
185
185
  // Set up the style import
186
186
  const flattenIdentifier = addFileImportHint({
187
187
  file,
188
- nameHint: 'flattenTextStyle',
188
+ nameHint: 'processTextStyle',
189
189
  path,
190
- importName: 'flattenTextStyle',
190
+ importName: 'processTextStyle',
191
191
  moduleName: RUNTIME_MODULE_NAME,
192
192
  });
193
193
  const flattenedStyleExpr = t.callExpression(t.identifier(flattenIdentifier.name), [styleExpr]);
@@ -198,9 +198,9 @@ function processProps(
198
198
  // Only style attribute is present
199
199
  const flattenIdentifier = addFileImportHint({
200
200
  file,
201
- nameHint: 'flattenTextStyle',
201
+ nameHint: 'processTextStyle',
202
202
  path,
203
- importName: 'flattenTextStyle',
203
+ importName: 'processTextStyle',
204
204
  moduleName: RUNTIME_MODULE_NAME,
205
205
  });
206
206
  const flattened = t.callExpression(t.identifier(flattenIdentifier.name), [styleExpr]);
@@ -209,9 +209,9 @@ function processProps(
209
209
  // Only accessibility properties are present
210
210
  const normalizeIdentifier = addFileImportHint({
211
211
  file,
212
- nameHint: 'normalizeAccessibilityProps',
212
+ nameHint: 'processAccessibilityProps',
213
213
  path,
214
- importName: 'normalizeAccessibilityProps',
214
+ importName: 'processAccessibilityProps',
215
215
  moduleName: RUNTIME_MODULE_NAME,
216
216
  });
217
217
  const propsObject = buildPropertiesFromAttributes(originalAttributes);
@@ -42,12 +42,12 @@ export type HubFile = t.File & {
42
42
  */
43
43
  export interface FileImportOptions {
44
44
  file: HubFile;
45
- /** The name hint which also acts as the cache key to ensure the import is only added once (e.g. 'normalizeAccessibilityProps') */
45
+ /** The name hint which also acts as the cache key to ensure the import is only added once (e.g. 'processAccessibilityProps') */
46
46
  nameHint: string;
47
47
  /** The current Babel NodePath */
48
48
  path: NodePath;
49
49
  /**
50
- * The named import string (e.g. 'normalizeAccessibilityProps'). Ignored if importType is "default".
50
+ * The named import string (e.g. 'processAccessibilityProps'). Ignored if importType is "default".
51
51
  */
52
52
  importName: string;
53
53
  /** The module to import from (e.g. 'react-native-boost/runtime') */
@@ -8,9 +8,9 @@ import { RUNTIME_MODULE_NAME } from '../constants';
8
8
  *
9
9
  * @param opts - Object containing the function arguments:
10
10
  * - file: The Babel file object (e.g. HubFile)
11
- * - nameHint: The name hint which also acts as the cache key to ensure the import is only added once (e.g. 'normalizeAccessibilityProps')
11
+ * - nameHint: The name hint which also acts as the cache key to ensure the import is only added once (e.g. 'processAccessibilityProps')
12
12
  * - path: The current Babel NodePath
13
- * - importName: The named import string (e.g. 'normalizeAccessibilityProps'), used when importType is 'named'
13
+ * - importName: The named import string (e.g. 'processAccessibilityProps'), used when importType is 'named'
14
14
  * - moduleName: The module to import from (e.g. 'react-native-boost/runtime')
15
15
  * - importType: Either 'named' (default) or 'default' to determine the type of import to use.
16
16
  *
@@ -1,10 +1,11 @@
1
- import { TextStyle } from 'react-native';
1
+ import { TextProps, TextStyle } from 'react-native';
2
2
  import flattenStyle from 'react-native/Libraries/StyleSheet/flattenStyle';
3
3
  import { GenericStyleProp } from './types';
4
+ import { userSelectToSelectableMap, verticalAlignToTextAlignVerticalMap } from './utils/constants';
4
5
 
5
6
  const propsCache = new WeakMap();
6
7
 
7
- export function flattenTextStyle(style: GenericStyleProp<TextStyle>) {
8
+ export function processTextStyle(style: GenericStyleProp<TextStyle>): Partial<TextProps> {
8
9
  if (!style) return {};
9
10
 
10
11
  // Cache the computed props
@@ -38,31 +39,8 @@ export function flattenTextStyle(style: GenericStyleProp<TextStyle>) {
38
39
  return props;
39
40
  }
40
41
 
41
- // Maps the `userSelect` prop to the native `selectable` prop
42
- export const userSelectToSelectableMap = {
43
- auto: true,
44
- text: true,
45
- none: false,
46
- contain: true,
47
- all: true,
48
- };
49
-
50
- // Maps the `verticalAlign` prop to the native `textAlignVertical` prop
51
- export const verticalAlignToTextAlignVerticalMap = {
52
- auto: 'auto',
53
- top: 'top',
54
- bottom: 'bottom',
55
- middle: 'center',
56
- };
57
-
58
- /**
59
- * Normalizes accessibility props.
60
- *
61
- * @param props - The props to normalize.
62
- * @returns The normalized props.
63
- */
64
42
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
- export function normalizeAccessibilityProperties(props: Record<string, any>): Record<string, any> {
43
+ export function processAccessibilityProps(props: Record<string, any>): Record<string, any> {
66
44
  const {
67
45
  accessibilityLabel,
68
46
  ['aria-label']: ariaLabel,
@@ -112,5 +90,6 @@ export function normalizeAccessibilityProperties(props: Record<string, any>): Re
112
90
  }
113
91
 
114
92
  export * from './types';
93
+ export * from './utils/constants';
115
94
  export * from './components/native-text';
116
95
  export * from './components/native-view';
@@ -0,0 +1,21 @@
1
+ // This is a dummy file to ensure that nothing breaks when using the runtime in a web environment.
2
+
3
+ import { TextProps, TextStyle } from 'react-native';
4
+ import { GenericStyleProp } from './types';
5
+
6
+ export const processTextStyle = (style: GenericStyleProp<TextStyle>) => ({ style }) as Partial<TextProps>;
7
+
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ export function processAccessibilityProps(props: Record<string, any>): Record<string, any> {
10
+ return props;
11
+ }
12
+
13
+ export * from './types';
14
+ export * from './utils/constants';
15
+
16
+ // On Web, the native components are not available, so we use the standard components that'll be replaced by their DOM
17
+ // equivalents by react-native-web.
18
+ /* eslint-disable @typescript-eslint/no-require-imports,unicorn/prefer-module */
19
+ export const NativeText = require('react-native').Text;
20
+ export const NativeView = require('react-native').View;
21
+ /* eslint-enable @typescript-eslint/no-require-imports,unicorn/prefer-module */
@@ -0,0 +1,16 @@
1
+ // Maps the `userSelect` prop to the native `selectable` prop
2
+ export const userSelectToSelectableMap = {
3
+ auto: true,
4
+ text: true,
5
+ none: false,
6
+ contain: true,
7
+ all: true,
8
+ };
9
+
10
+ // Maps the `verticalAlign` prop to the native `textAlignVertical` prop
11
+ export const verticalAlignToTextAlignVerticalMap = {
12
+ auto: 'auto',
13
+ top: 'top',
14
+ bottom: 'bottom',
15
+ middle: 'center',
16
+ };
@@ -1,84 +0,0 @@
1
- import flattenStyle from 'react-native/Libraries/StyleSheet/flattenStyle';
2
- import { Platform } from 'react-native';
3
-
4
- const NativeText = Platform.OS === "web" ? require("react-native").Text : require("react-native/Libraries/Text/TextNativeComponent").NativeText;
5
-
6
- const NativeView = Platform.OS === "web" ? require("react-native").View : require("react-native/Libraries/Components/View/ViewNativeComponent").default;
7
-
8
- const propsCache = /* @__PURE__ */ new WeakMap();
9
- function flattenTextStyle(style) {
10
- if (!style) return {};
11
- let props = propsCache.get(style);
12
- if (props) return props;
13
- props = {};
14
- propsCache.set(style, props);
15
- style = flattenStyle(style);
16
- if (!style) return {};
17
- if (typeof (style == null ? void 0 : style.fontWeight) === "number") {
18
- style.fontWeight = style.fontWeight.toString();
19
- }
20
- if ((style == null ? void 0 : style.userSelect) != null) {
21
- props.selectable = userSelectToSelectableMap[style.userSelect];
22
- delete style.userSelect;
23
- }
24
- if ((style == null ? void 0 : style.verticalAlign) != null) {
25
- style.textAlignVertical = verticalAlignToTextAlignVerticalMap[style.verticalAlign];
26
- delete style.verticalAlign;
27
- }
28
- props.style = style;
29
- return props;
30
- }
31
- const userSelectToSelectableMap = {
32
- auto: true,
33
- text: true,
34
- none: false,
35
- contain: true,
36
- all: true
37
- };
38
- const verticalAlignToTextAlignVerticalMap = {
39
- auto: "auto",
40
- top: "top",
41
- bottom: "bottom",
42
- middle: "center"
43
- };
44
- function normalizeAccessibilityProperties(props) {
45
- const {
46
- accessibilityLabel,
47
- ["aria-label"]: ariaLabel,
48
- accessibilityState,
49
- ["aria-busy"]: ariaBusy,
50
- ["aria-checked"]: ariaChecked,
51
- ["aria-disabled"]: ariaDisabled,
52
- ["aria-expanded"]: ariaExpanded,
53
- ["aria-selected"]: ariaSelected,
54
- accessible,
55
- ...restProperties
56
- } = props;
57
- const normalizedLabel = ariaLabel != null ? ariaLabel : accessibilityLabel;
58
- let normalizedState = accessibilityState;
59
- if (ariaBusy != null || ariaChecked != null || ariaDisabled != null || ariaExpanded != null || ariaSelected != null) {
60
- normalizedState = normalizedState == null ? {
61
- busy: ariaBusy,
62
- checked: ariaChecked,
63
- disabled: ariaDisabled,
64
- expanded: ariaExpanded,
65
- selected: ariaSelected
66
- } : {
67
- busy: ariaBusy != null ? ariaBusy : normalizedState.busy,
68
- checked: ariaChecked != null ? ariaChecked : normalizedState.checked,
69
- disabled: ariaDisabled != null ? ariaDisabled : normalizedState.disabled,
70
- expanded: ariaExpanded != null ? ariaExpanded : normalizedState.expanded,
71
- selected: ariaSelected != null ? ariaSelected : normalizedState.selected
72
- };
73
- }
74
- const normalizedAccessible = accessible == null ? true : accessible;
75
- return {
76
- ...restProperties,
77
- accessibilityLabel: normalizedLabel,
78
- accessibilityState: normalizedState,
79
- accessible: normalizedAccessible
80
- };
81
- }
82
-
83
- export { NativeText, NativeView, flattenTextStyle, normalizeAccessibilityProperties, userSelectToSelectableMap, verticalAlignToTextAlignVerticalMap };
84
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sources":["../../src/runtime/components/native-text.tsx","../../src/runtime/components/native-view.tsx","../../src/runtime/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-require-imports,unicorn/prefer-module */\nimport { Platform } from 'react-native';\n\nexport const NativeText =\n Platform.OS === 'web'\n ? require('react-native').Text\n : require('react-native/Libraries/Text/TextNativeComponent').NativeText;\n","/* eslint-disable @typescript-eslint/no-require-imports,unicorn/prefer-module */\nimport { Platform } from 'react-native';\n\nexport const NativeView =\n Platform.OS === 'web'\n ? require('react-native').View\n : require('react-native/Libraries/Components/View/ViewNativeComponent').default;\n","import { TextStyle } from 'react-native';\nimport flattenStyle from 'react-native/Libraries/StyleSheet/flattenStyle';\nimport { GenericStyleProp } from './types';\n\nconst propsCache = new WeakMap();\n\nexport function flattenTextStyle(style: GenericStyleProp<TextStyle>) {\n if (!style) return {};\n\n // Cache the computed props\n let props = propsCache.get(style);\n if (props) return props;\n\n props = {};\n propsCache.set(style, props);\n\n style = flattenStyle(style);\n\n if (!style) return {};\n\n if (typeof style?.fontWeight === 'number') {\n style.fontWeight = style.fontWeight.toString() as TextStyle['fontWeight'];\n }\n\n if (style?.userSelect != null) {\n props.selectable = userSelectToSelectableMap[style.userSelect];\n delete style.userSelect;\n }\n\n if (style?.verticalAlign != null) {\n style.textAlignVertical = verticalAlignToTextAlignVerticalMap[\n style.verticalAlign\n ] as TextStyle['textAlignVertical'];\n delete style.verticalAlign;\n }\n\n props.style = style;\n return props;\n}\n\n// Maps the `userSelect` prop to the native `selectable` prop\nexport const userSelectToSelectableMap = {\n auto: true,\n text: true,\n none: false,\n contain: true,\n all: true,\n};\n\n// Maps the `verticalAlign` prop to the native `textAlignVertical` prop\nexport const verticalAlignToTextAlignVerticalMap = {\n auto: 'auto',\n top: 'top',\n bottom: 'bottom',\n middle: 'center',\n};\n\n/**\n * Normalizes accessibility props.\n *\n * @param props - The props to normalize.\n * @returns The normalized props.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function normalizeAccessibilityProperties(props: Record<string, any>): Record<string, any> {\n const {\n accessibilityLabel,\n ['aria-label']: ariaLabel,\n accessibilityState,\n ['aria-busy']: ariaBusy,\n ['aria-checked']: ariaChecked,\n ['aria-disabled']: ariaDisabled,\n ['aria-expanded']: ariaExpanded,\n ['aria-selected']: ariaSelected,\n accessible,\n ...restProperties\n } = props;\n\n // Merge label props: prefer the aria-label if defined.\n const normalizedLabel = ariaLabel ?? accessibilityLabel;\n\n // Merge the accessibilityState with any provided ARIA properties.\n let normalizedState = accessibilityState;\n if (ariaBusy != null || ariaChecked != null || ariaDisabled != null || ariaExpanded != null || ariaSelected != null) {\n normalizedState =\n normalizedState == null\n ? {\n busy: ariaBusy,\n checked: ariaChecked,\n disabled: ariaDisabled,\n expanded: ariaExpanded,\n selected: ariaSelected,\n }\n : {\n busy: ariaBusy ?? normalizedState.busy,\n checked: ariaChecked ?? normalizedState.checked,\n disabled: ariaDisabled ?? normalizedState.disabled,\n expanded: ariaExpanded ?? normalizedState.expanded,\n selected: ariaSelected ?? normalizedState.selected,\n };\n }\n\n // For the accessible prop, if not provided, default to `true`\n const normalizedAccessible = accessible == null ? true : accessible;\n\n return {\n ...restProperties,\n accessibilityLabel: normalizedLabel,\n accessibilityState: normalizedState,\n accessible: normalizedAccessible,\n };\n}\n\nexport * from './types';\nexport * from './components/native-text';\nexport * from './components/native-view';\n"],"names":[],"mappings":";;;AAGa,MAAA,UAAA,GACX,QAAS,CAAA,EAAA,KAAO,KACZ,GAAA,OAAA,CAAQ,cAAc,CAAE,CAAA,IAAA,GACxB,OAAQ,CAAA,iDAAiD,CAAE,CAAA;;ACHpD,MAAA,UAAA,GACX,QAAS,CAAA,EAAA,KAAO,KACZ,GAAA,OAAA,CAAQ,cAAc,CAAE,CAAA,IAAA,GACxB,OAAQ,CAAA,4DAA4D,CAAE,CAAA;;ACF5E,MAAM,UAAA,uBAAiB,OAAQ,EAAA;AAExB,SAAS,iBAAiB,KAAoC,EAAA;AACnE,EAAI,IAAA,CAAC,KAAO,EAAA,OAAO,EAAC;AAGpB,EAAI,IAAA,KAAA,GAAQ,UAAW,CAAA,GAAA,CAAI,KAAK,CAAA;AAChC,EAAA,IAAI,OAAc,OAAA,KAAA;AAElB,EAAA,KAAA,GAAQ,EAAC;AACT,EAAW,UAAA,CAAA,GAAA,CAAI,OAAO,KAAK,CAAA;AAE3B,EAAA,KAAA,GA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adonlyArray<GenericStyleProp<T>>;
4
-
5
- declare const NativeText: any;
6
-
7
- declare const NativeView: any;
8
-
9
- declare function flattenTextStyle(style: GenericStyleProp<TextStyle>): any;
10
- declare const userSelectToSelectableMap: {
11
- auto: boolean;
12
- text: boolean;
13
- none: boolean;
14
- contain: boolean;
15
- all: boolean;
16
- };
17
- declare const verticalAlignToTextAlignVerticalMap: {
18
- auto: string;
19
- top: string;
20
- bottom: string;
21
- middle: string;
22
- };
23
- /**
24
- * Normalizes accessibility props.
25
- *
26
- * @param props - The props to normalize.
27
- * @returns The normalized props.
28
- */
29
- declare function normalizeAccessibilityProperties(props: Record<string, any>): Record<string, any>;
30
-
31
- export { type GenericStyleProp, NativeText, NativeView, flattenTextStyle, normalizeAccessibilityProperties, userSelectToSelectableMap, verticalAlignToTextAlignVerticalMap };
package/dist/index.js DELETED
@@ -1,91 +0,0 @@
1
- 'use strict';
2
-
3
- var flattenStyle = require('react-native/Libraries/StyleSheet/flattenStyle');
4
- var reactNative = require('react-native');
5
-
6
- const NativeText = reactNative.Platform.OS === "web" ? require("react-native").Text : require("react-native/Libraries/Text/TextNativeComponent").NativeText;
7
-
8
- const NativeView = reactNative.Platform.OS === "web" ? require("react-native").View : require("react-native/Libraries/Components/View/ViewNativeComponent").default;
9
-
10
- const propsCache = /* @__PURE__ */ new WeakMap();
11
- function flattenTextStyle(style) {
12
- if (!style) return {};
13
- let props = propsCache.get(style);
14
- if (props) return props;
15
- props = {};
16
- propsCache.set(style, props);
17
- style = flattenStyle(style);
18
- if (!style) return {};
19
- if (typeof (style == null ? void 0 : style.fontWeight) === "number") {
20
- style.fontWeight = style.fontWeight.toString();
21
- }
22
- if ((style == null ? void 0 : style.userSelect) != null) {
23
- props.selectable = userSelectToSelectableMap[style.userSelect];
24
- delete style.userSelect;
25
- }
26
- if ((style == null ? void 0 : style.verticalAlign) != null) {
27
- style.textAlignVertical = verticalAlignToTextAlignVerticalMap[style.verticalAlign];
28
- delete style.verticalAlign;
29
- }
30
- props.style = style;
31
- return props;
32
- }
33
- const userSelectToSelectableMap = {
34
- auto: true,
35
- text: true,
36
- none: false,
37
- contain: true,
38
- all: true
39
- };
40
- const verticalAlignToTextAlignVerticalMap = {
41
- auto: "auto",
42
- top: "top",
43
- bottom: "bottom",
44
- middle: "center"
45
- };
46
- function normalizeAccessibilityProperties(props) {
47
- const {
48
- accessibilityLabel,
49
- ["aria-label"]: ariaLabel,
50
- accessibilityState,
51
- ["aria-busy"]: ariaBusy,
52
- ["aria-checked"]: ariaChecked,
53
- ["aria-disabled"]: ariaDisabled,
54
- ["aria-expanded"]: ariaExpanded,
55
- ["aria-selected"]: ariaSelected,
56
- accessible,
57
- ...restProperties
58
- } = props;
59
- const normalizedLabel = ariaLabel != null ? ariaLabel : accessibilityLabel;
60
- let normalizedState = accessibilityState;
61
- if (ariaBusy != null || ariaChecked != null || ariaDisabled != null || ariaExpanded != null || ariaSelected != null) {
62
- normalizedState = normalizedState == null ? {
63
- busy: ariaBusy,
64
- checked: ariaChecked,
65
- disabled: ariaDisabled,
66
- expanded: ariaExpanded,
67
- selected: ariaSelected
68
- } : {
69
- busy: ariaBusy != null ? ariaBusy : normalizedState.busy,
70
- checked: ariaChecked != null ? ariaChecked : normalizedState.checked,
71
- disabled: ariaDisabled != null ? ariaDisabled : normalizedState.disabled,
72
- expanded: ariaExpanded != null ? ariaExpanded : normalizedState.expanded,
73
- selected: ariaSelected != null ? ariaSelected : normalizedState.selected
74
- };
75
- }
76
- const normalizedAccessible = accessible == null ? true : accessible;
77
- return {
78
- ...restProperties,
79
- accessibilityLabel: normalizedLabel,
80
- accessibilityState: normalizedState,
81
- accessible: normalizedAccessible
82
- };
83
- }
84
-
85
- exports.NativeText = NativeText;
86
- exports.NativeView = NativeView;
87
- exports.flattenTextStyle = flattenTextStyle;
88
- exports.normalizeAccessibilityProperties = normalizeAccessibilityProperties;
89
- exports.userSelectToSelectableMap = userSelectToSelectableMap;
90
- exports.verticalAlignToTextAlignVerticalMap = verticalAlignToTextAlignVerticalMap;
91
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../src/runtime/components/native-text.tsx","../src/runtime/components/native-view.tsx","../src/runtime/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-require-imports,unicorn/prefer-module */\nimport { Platform } from 'react-native';\n\nexport const NativeText =\n Platform.OS === 'web'\n ? require('react-native').Text\n : require('react-native/Libraries/Text/TextNativeComponent').NativeText;\n","/* eslint-disable @typescript-eslint/no-require-imports,unicorn/prefer-module */\nimport { Platform } from 'react-native';\n\nexport const NativeView =\n Platform.OS === 'web'\n ? require('react-native').View\n : require('react-native/Libraries/Components/View/ViewNativeComponent').default;\n","import { TextStyle } from 'react-native';\nimport flattenStyle from 'react-native/Libraries/StyleSheet/flattenStyle';\nimport { GenericStyleProp } from './types';\n\nconst propsCache = new WeakMap();\n\nexport function flattenTextStyle(style: GenericStyleProp<TextStyle>) {\n if (!style) return {};\n\n // Cache the computed props\n let props = propsCache.get(style);\n if (props) return props;\n\n props = {};\n propsCache.set(style, props);\n\n style = flattenStyle(style);\n\n if (!style) return {};\n\n if (typeof style?.fontWeight === 'number') {\n style.fontWeight = style.fontWeight.toString() as TextStyle['fontWeight'];\n }\n\n if (style?.userSelect != null) {\n props.selectable = userSelectToSelectableMap[style.userSelect];\n delete style.userSelect;\n }\n\n if (style?.verticalAlign != null) {\n style.textAlignVertical = verticalAlignToTextAlignVerticalMap[\n style.verticalAlign\n ] as TextStyle['textAlignVertical'];\n delete style.verticalAlign;\n }\n\n props.style = style;\n return props;\n}\n\n// Maps the `userSelect` prop to the native `selectable` prop\nexport const userSelectToSelectableMap = {\n auto: true,\n text: true,\n none: false,\n contain: true,\n all: true,\n};\n\n// Maps the `verticalAlign` prop to the native `textAlignVertical` prop\nexport const verticalAlignToTextAlignVerticalMap = {\n auto: 'auto',\n top: 'top',\n bottom: 'bottom',\n middle: 'center',\n};\n\n/**\n * Normalizes accessibility props.\n *\n * @param props - The props to normalize.\n * @returns The normalized props.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function normalizeAccessibilityProperties(props: Record<string, any>): Record<string, any> {\n const {\n accessibilityLabel,\n ['aria-label']: ariaLabel,\n accessibilityState,\n ['aria-busy']: ariaBusy,\n ['aria-checked']: ariaChecked,\n ['aria-disabled']: ariaDisabled,\n ['aria-expanded']: ariaExpanded,\n ['aria-selected']: ariaSelected,\n accessible,\n ...restProperties\n } = props;\n\n // Merge label props: prefer the aria-label if defined.\n const normalizedLabel = ariaLabel ?? accessibilityLabel;\n\n // Merge the accessibilityState with any provided ARIA properties.\n let normalizedState = accessibilityState;\n if (ariaBusy != null || ariaChecked != null || ariaDisabled != null || ariaExpanded != null || ariaSelected != null) {\n normalizedState =\n normalizedState == null\n ? {\n busy: ariaBusy,\n checked: ariaChecked,\n disabled: ariaDisabled,\n expanded: ariaExpanded,\n selected: ariaSelected,\n }\n : {\n busy: ariaBusy ?? normalizedState.busy,\n checked: ariaChecked ?? normalizedState.checked,\n disabled: ariaDisabled ?? normalizedState.disabled,\n expanded: ariaExpanded ?? normalizedState.expanded,\n selected: ariaSelected ?? normalizedState.selected,\n };\n }\n\n // For the accessible prop, if not provided, default to `true`\n const normalizedAccessible = accessible == null ? true : accessible;\n\n return {\n ...restProperties,\n accessibilityLabel: normalizedLabel,\n accessibilityState: normalizedState,\n accessible: normalizedAccessible,\n };\n}\n\nexport * from './types';\nexport * from './components/native-text';\nexport * from './components/native-view';\n"],"names":["Platform"],"mappings":";;;;;AAGa,MAAA,UAAA,GACXA,oBAAS,CAAA,EAAA,KAAO,KACZ,GAAA,OAAA,CAAQ,cAAc,CAAE,CAAA,IAAA,GACxB,OAAQ,CAAA,iDAAiD,CAAE,CAAA;;ACHpD,MAAA,UAAA,GACXA,oBAAS,CAAA,EAAA,KAAO,KACZ,GAAA,OAAA,CAAQ,cAAc,CAAE,CAAA,IAAA,GACxB,OAAQ,CAAA,4D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