@xaui/native 0.2.5 → 0.2.6

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.
@@ -4,10 +4,211 @@
4
4
 
5
5
  var _chunk7UFBLUMVcjs = require('../chunk-7UFBLUMV.cjs');
6
6
 
7
- // src/components/view/column/column.tsx
7
+ // src/components/view/container/container.tsx
8
8
  var _react = require('react'); var _react2 = _interopRequireDefault(_react);
9
9
  var _reactnative = require('react-native');
10
10
 
11
+ // src/components/view/container/container.utils.ts
12
+ var resolveEdgeInsets = (value, prefix) => {
13
+ if (typeof value === "number") {
14
+ return prefix === "padding" ? { padding: value } : { margin: value };
15
+ }
16
+ const style = {};
17
+ if (prefix === "padding") {
18
+ if (value.horizontal !== void 0) style.paddingHorizontal = value.horizontal;
19
+ if (value.vertical !== void 0) style.paddingVertical = value.vertical;
20
+ if (value.top !== void 0) style.paddingTop = value.top;
21
+ if (value.bottom !== void 0) style.paddingBottom = value.bottom;
22
+ if (value.left !== void 0) style.paddingLeft = value.left;
23
+ if (value.right !== void 0) style.paddingRight = value.right;
24
+ } else {
25
+ if (value.horizontal !== void 0) style.marginHorizontal = value.horizontal;
26
+ if (value.vertical !== void 0) style.marginVertical = value.vertical;
27
+ if (value.top !== void 0) style.marginTop = value.top;
28
+ if (value.bottom !== void 0) style.marginBottom = value.bottom;
29
+ if (value.left !== void 0) style.marginLeft = value.left;
30
+ if (value.right !== void 0) style.marginRight = value.right;
31
+ }
32
+ return style;
33
+ };
34
+ var ALIGNMENT_MAP = {
35
+ topLeft: { justifyContent: "flex-start", alignItems: "flex-start" },
36
+ topCenter: { justifyContent: "flex-start", alignItems: "center" },
37
+ topRight: { justifyContent: "flex-start", alignItems: "flex-end" },
38
+ centerLeft: { justifyContent: "center", alignItems: "flex-start" },
39
+ center: { justifyContent: "center", alignItems: "center" },
40
+ centerRight: { justifyContent: "center", alignItems: "flex-end" },
41
+ bottomLeft: { justifyContent: "flex-end", alignItems: "flex-start" },
42
+ bottomCenter: { justifyContent: "flex-end", alignItems: "center" },
43
+ bottomRight: { justifyContent: "flex-end", alignItems: "flex-end" }
44
+ };
45
+ var toFlexPosition = (v) => {
46
+ if (v <= 0) return "flex-start";
47
+ if (v >= 1) return "flex-end";
48
+ return "center";
49
+ };
50
+ var resolveAlignment = (value) => {
51
+ if (typeof value === "object") {
52
+ return {
53
+ justifyContent: toFlexPosition(value.y),
54
+ alignItems: toFlexPosition(value.x)
55
+ };
56
+ }
57
+ return _nullishCoalesce(ALIGNMENT_MAP[value], () => ( {
58
+ justifyContent: "flex-start",
59
+ alignItems: "flex-start"
60
+ }));
61
+ };
62
+ var resolveBorderRadius = (value) => {
63
+ if (typeof value === "number") {
64
+ return { borderRadius: value };
65
+ }
66
+ const style = {};
67
+ if (value.topLeft !== void 0) style.borderTopLeftRadius = value.topLeft;
68
+ if (value.topRight !== void 0) style.borderTopRightRadius = value.topRight;
69
+ if (value.bottomLeft !== void 0) style.borderBottomLeftRadius = value.bottomLeft;
70
+ if (value.bottomRight !== void 0)
71
+ style.borderBottomRightRadius = value.bottomRight;
72
+ return style;
73
+ };
74
+ var resolveBorderSide = (side, position) => {
75
+ const style = {};
76
+ if (position === "") {
77
+ if (side.width !== void 0) style.borderWidth = side.width;
78
+ if (side.color !== void 0) style.borderColor = side.color;
79
+ if (side.style !== void 0) style.borderStyle = side.style;
80
+ return style;
81
+ }
82
+ if (position === "Top") {
83
+ if (side.width !== void 0) style.borderTopWidth = side.width;
84
+ if (side.color !== void 0) style.borderTopColor = side.color;
85
+ } else if (position === "Bottom") {
86
+ if (side.width !== void 0) style.borderBottomWidth = side.width;
87
+ if (side.color !== void 0) style.borderBottomColor = side.color;
88
+ } else if (position === "Left") {
89
+ if (side.width !== void 0) style.borderLeftWidth = side.width;
90
+ if (side.color !== void 0) style.borderLeftColor = side.color;
91
+ } else {
92
+ if (side.width !== void 0) style.borderRightWidth = side.width;
93
+ if (side.color !== void 0) style.borderRightColor = side.color;
94
+ }
95
+ return style;
96
+ };
97
+ var resolveBorder = (value) => {
98
+ const dir = value;
99
+ if (dir.top !== void 0 || dir.bottom !== void 0 || dir.left !== void 0 || dir.right !== void 0) {
100
+ return {
101
+ ...dir.top ? resolveBorderSide(dir.top, "Top") : {},
102
+ ...dir.bottom ? resolveBorderSide(dir.bottom, "Bottom") : {},
103
+ ...dir.left ? resolveBorderSide(dir.left, "Left") : {},
104
+ ...dir.right ? resolveBorderSide(dir.right, "Right") : {}
105
+ };
106
+ }
107
+ return resolveBorderSide(value, "");
108
+ };
109
+ var resolveShadow = (value) => ({
110
+ shadowColor: _nullishCoalesce(value.color, () => ( "#000000")),
111
+ shadowOffset: {
112
+ width: _nullishCoalesce(_optionalChain([value, 'access', _2 => _2.offset, 'optionalAccess', _3 => _3.x]), () => ( 0)),
113
+ height: _nullishCoalesce(_optionalChain([value, 'access', _4 => _4.offset, 'optionalAccess', _5 => _5.y]), () => ( 4))
114
+ },
115
+ shadowOpacity: _nullishCoalesce(value.opacity, () => ( 0.1)),
116
+ shadowRadius: _nullishCoalesce(value.blur, () => ( 4)),
117
+ elevation: _nullishCoalesce(value.elevation, () => ( 2))
118
+ });
119
+ var resolveTransform = (value) => {
120
+ const transforms = [];
121
+ if (value.rotate !== void 0) transforms.push({ rotate: value.rotate });
122
+ if (value.rotateX !== void 0) transforms.push({ rotateX: value.rotateX });
123
+ if (value.rotateY !== void 0) transforms.push({ rotateY: value.rotateY });
124
+ if (value.scale !== void 0) transforms.push({ scale: value.scale });
125
+ if (value.scaleX !== void 0) transforms.push({ scaleX: value.scaleX });
126
+ if (value.scaleY !== void 0) transforms.push({ scaleY: value.scaleY });
127
+ if (value.translateX !== void 0)
128
+ transforms.push({ translateX: value.translateX });
129
+ if (value.translateY !== void 0)
130
+ transforms.push({ translateY: value.translateY });
131
+ if (value.skewX !== void 0) transforms.push({ skewX: value.skewX });
132
+ if (value.skewY !== void 0) transforms.push({ skewY: value.skewY });
133
+ return transforms;
134
+ };
135
+
136
+ // src/components/view/container/container.tsx
137
+ var buildStyle = (props) => ({
138
+ ...props.width !== void 0 && { width: props.width },
139
+ ...props.height !== void 0 && { height: props.height },
140
+ ...props.minWidth !== void 0 && { minWidth: props.minWidth },
141
+ ...props.maxWidth !== void 0 && { maxWidth: props.maxWidth },
142
+ ...props.minHeight !== void 0 && { minHeight: props.minHeight },
143
+ ...props.maxHeight !== void 0 && { maxHeight: props.maxHeight },
144
+ ...props.aspectRatio !== void 0 && { aspectRatio: props.aspectRatio },
145
+ ...props.flex !== void 0 && { flex: props.flex },
146
+ ...props.color !== void 0 && { backgroundColor: props.color },
147
+ ...props.clip && { overflow: "hidden" },
148
+ ...props.opacity !== void 0 && { opacity: props.opacity },
149
+ ...props.padding !== void 0 && resolveEdgeInsets(props.padding, "padding"),
150
+ ...props.margin !== void 0 && resolveEdgeInsets(props.margin, "margin"),
151
+ ...props.alignment !== void 0 && resolveAlignment(props.alignment),
152
+ ...props.borderRadius !== void 0 && resolveBorderRadius(props.borderRadius),
153
+ ...props.border !== void 0 && resolveBorder(props.border),
154
+ ...props.shadow !== void 0 && resolveShadow(props.shadow),
155
+ ...props.transform !== void 0 && { transform: resolveTransform(props.transform) }
156
+ });
157
+ var Container = (props) => {
158
+ const {
159
+ children,
160
+ onPress,
161
+ onLongPress,
162
+ onPressIn,
163
+ onPressOut,
164
+ disabled = false,
165
+ accessibilityLabel,
166
+ accessibilityRole,
167
+ accessibilityState,
168
+ accessible,
169
+ testID,
170
+ style
171
+ } = props;
172
+ const containerStyle = buildStyle(props);
173
+ const isInteractive = !!(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(onPress, () => ( onLongPress)), () => ( onPressIn)), () => ( onPressOut)));
174
+ if (isInteractive) {
175
+ return /* @__PURE__ */ _react2.default.createElement(
176
+ _reactnative.Pressable,
177
+ {
178
+ onPress: disabled ? void 0 : onPress,
179
+ onLongPress: disabled ? void 0 : onLongPress,
180
+ onPressIn: disabled ? void 0 : onPressIn,
181
+ onPressOut: disabled ? void 0 : onPressOut,
182
+ disabled,
183
+ accessibilityLabel,
184
+ accessibilityRole,
185
+ accessibilityState,
186
+ accessible,
187
+ testID,
188
+ style: [containerStyle, style]
189
+ },
190
+ children
191
+ );
192
+ }
193
+ return /* @__PURE__ */ _react2.default.createElement(
194
+ _reactnative.View,
195
+ {
196
+ accessibilityLabel,
197
+ accessibilityRole,
198
+ accessibilityState,
199
+ accessible,
200
+ testID,
201
+ style: [containerStyle, style]
202
+ },
203
+ children
204
+ );
205
+ };
206
+ Container.displayName = "Container";
207
+
208
+ // src/components/view/column/column.tsx
209
+
210
+
211
+
11
212
  // src/components/view/layout-utils.ts
12
213
  var MAIN_AXIS_JUSTIFY_MAP = {
13
214
  start: "flex-start",
@@ -118,81 +319,13 @@ Spacer.displayName = "Spacer";
118
319
  // src/components/view/padding/padding.tsx
119
320
 
120
321
 
121
- var Padding = ({
122
- children,
123
- all,
124
- horizontal,
125
- vertical,
126
- top,
127
- right,
128
- bottom,
129
- left,
130
- fullWidth,
131
- style,
132
- noGrowth = false
133
- }) => {
134
- const fullWidthStyle = fullWidth ? { width: "100%" } : void 0;
135
- return /* @__PURE__ */ _react2.default.createElement(
136
- _reactnative.View,
137
- {
138
- style: [
139
- {
140
- flex: noGrowth ? void 0 : 1,
141
- padding: all,
142
- paddingHorizontal: horizontal,
143
- paddingVertical: vertical,
144
- paddingTop: top,
145
- paddingRight: right,
146
- paddingBottom: bottom,
147
- paddingLeft: left
148
- },
149
- fullWidthStyle,
150
- style
151
- ]
152
- },
153
- children
154
- );
155
- };
322
+ var Padding = ({ children, padding, style }) => /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { style: [resolveEdgeInsets(padding, "padding"), style] }, children);
156
323
  Padding.displayName = "Padding";
157
324
 
158
325
  // src/components/view/margin/margin.tsx
159
326
 
160
327
 
161
- var Margin = ({
162
- children,
163
- all,
164
- horizontal,
165
- vertical,
166
- top,
167
- right,
168
- bottom,
169
- left,
170
- fullWidth,
171
- style,
172
- noGrowth = false
173
- }) => {
174
- const fullWidthStyle = fullWidth ? { width: "100%" } : void 0;
175
- return /* @__PURE__ */ _react2.default.createElement(
176
- _reactnative.View,
177
- {
178
- style: [
179
- {
180
- flex: noGrowth ? void 0 : 1,
181
- margin: all,
182
- marginHorizontal: horizontal,
183
- marginVertical: vertical,
184
- marginTop: top,
185
- marginRight: right,
186
- marginBottom: bottom,
187
- marginLeft: left
188
- },
189
- fullWidthStyle,
190
- style
191
- ]
192
- },
193
- children
194
- );
195
- };
328
+ var Margin = ({ children, margin, style }) => /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { style: [resolveEdgeInsets(margin, "margin"), style] }, children);
196
329
  Margin.displayName = "Margin";
197
330
 
198
331
  // src/components/view/sized-box/sized-box.tsx
@@ -202,27 +335,66 @@ var SizedBox = ({
202
335
  children,
203
336
  width,
204
337
  height,
205
- fullWidth,
206
- style
338
+ expand,
339
+ shrink,
340
+ style,
341
+ testID
207
342
  }) => {
208
- const fullWidthStyle = fullWidth ? { width: "100%" } : void 0;
209
- return /* @__PURE__ */ _react2.default.createElement(
210
- _reactnative.View,
211
- {
212
- style: [
213
- {
214
- width,
215
- height
216
- },
217
- fullWidthStyle,
218
- style
219
- ]
220
- },
221
- children
222
- );
343
+ if (shrink) {
344
+ return /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { testID, style: [{ width: 0, height: 0, overflow: "hidden" }, style] }, children);
345
+ }
346
+ if (expand) {
347
+ return /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { testID, style: [{ flex: 1, alignSelf: "stretch" }, style] }, children);
348
+ }
349
+ return /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { testID, style: [{ width, height }, style] }, children);
223
350
  };
224
351
  SizedBox.displayName = "SizedBox";
225
352
 
353
+ // src/components/view/constrained-box/constrained-box.tsx
354
+
355
+
356
+ var ConstrainedBox = ({
357
+ children,
358
+ constraints,
359
+ style,
360
+ testID
361
+ }) => /* @__PURE__ */ _react2.default.createElement(
362
+ _reactnative.View,
363
+ {
364
+ testID,
365
+ style: [
366
+ {
367
+ minWidth: constraints.minWidth,
368
+ maxWidth: constraints.maxWidth,
369
+ minHeight: constraints.minHeight,
370
+ maxHeight: constraints.maxHeight
371
+ },
372
+ style
373
+ ]
374
+ },
375
+ children
376
+ );
377
+ ConstrainedBox.displayName = "ConstrainedBox";
378
+
379
+ // src/components/view/fractionally-sized-box/fractionally-sized-box.tsx
380
+
381
+
382
+ var FractionallySizedBox = ({
383
+ children,
384
+ widthFactor,
385
+ heightFactor,
386
+ alignment,
387
+ style,
388
+ testID
389
+ }) => {
390
+ const sizedStyle = {};
391
+ if (widthFactor !== void 0) sizedStyle.width = `${widthFactor * 100}%`;
392
+ if (heightFactor !== void 0) sizedStyle.height = `${heightFactor * 100}%`;
393
+ const alignStyle = alignment ? resolveAlignment(alignment) : {};
394
+ return /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { testID, style: [sizedStyle, alignStyle, style] }, children);
395
+ };
396
+ FractionallySizedBox.displayName = "FractionallySizedBox";
397
+
226
398
  // src/components/view/positioned-view/positioned-view.tsx
227
399
 
228
400
 
@@ -385,10 +557,29 @@ var RoundedView = ({
385
557
  var AspectRatio = ({
386
558
  children,
387
559
  ratio,
388
- style
560
+ alignment,
561
+ clip,
562
+ style,
563
+ testID
389
564
  }) => {
390
- return /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { style: [{ aspectRatio: ratio }, style] }, children);
565
+ const alignStyle = alignment ? resolveAlignment(alignment) : {};
566
+ return /* @__PURE__ */ _react2.default.createElement(
567
+ _reactnative.View,
568
+ {
569
+ testID,
570
+ style: [
571
+ {
572
+ aspectRatio: ratio,
573
+ overflow: clip ? "hidden" : "visible"
574
+ },
575
+ alignStyle,
576
+ style
577
+ ]
578
+ },
579
+ children
580
+ );
391
581
  };
582
+ AspectRatio.displayName = "AspectRatio";
392
583
 
393
584
  // src/components/view/surface/surface.tsx
394
585
 
@@ -451,32 +642,15 @@ var Screen = ({
451
642
  };
452
643
  Screen.displayName = "Screen";
453
644
 
454
- // src/components/view/center/center.tsx
645
+ // src/components/view/align/align.tsx
455
646
 
456
647
 
457
- var Center = ({
458
- children,
459
- fullWidth,
460
- style,
461
- noGrowth = false
462
- }) => {
463
- const fullWidthStyle = fullWidth ? { width: "100%" } : void 0;
464
- return /* @__PURE__ */ _react2.default.createElement(
465
- _reactnative.View,
466
- {
467
- style: [
468
- {
469
- flex: noGrowth ? void 0 : 1,
470
- alignItems: "center",
471
- justifyContent: "center"
472
- },
473
- fullWidthStyle,
474
- style
475
- ]
476
- },
477
- children
478
- );
479
- };
648
+ var Align = ({ children, alignment, style }) => /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { style: [{ flex: 1 }, resolveAlignment(alignment), style] }, children);
649
+ Align.displayName = "Align";
650
+
651
+ // src/components/view/center/center.tsx
652
+
653
+ var Center = ({ children, style }) => /* @__PURE__ */ _react2.default.createElement(Align, { alignment: "center", style }, children);
480
654
  Center.displayName = "Center";
481
655
 
482
656
  // src/components/view/grid/grid.tsx
@@ -815,7 +989,7 @@ var runConditionalViewAnimation = ({
815
989
  ]);
816
990
  animation.start(({ finished }) => {
817
991
  if (finished) {
818
- _optionalChain([onComplete, 'optionalCall', _2 => _2()]);
992
+ _optionalChain([onComplete, 'optionalCall', _6 => _6()]);
819
993
  }
820
994
  });
821
995
  return animation;
@@ -869,7 +1043,7 @@ var ConditionalView = ({
869
1043
  }
870
1044
  return;
871
1045
  }
872
- _optionalChain([animationRef, 'access', _3 => _3.current, 'optionalAccess', _4 => _4.stop, 'call', _5 => _5()]);
1046
+ _optionalChain([animationRef, 'access', _7 => _7.current, 'optionalAccess', _8 => _8.stop, 'call', _9 => _9()]);
873
1047
  animationRef.current = runConditionalViewAnimation({
874
1048
  opacity,
875
1049
  scale,
@@ -1056,10 +1230,10 @@ var MasonryGridBuilder = ({
1056
1230
  const lastEndReachedHeight = _react.useRef.call(void 0, 0);
1057
1231
  if (!resolvedRenderer) return null;
1058
1232
  const handleScroll = (event) => {
1059
- _optionalChain([onScroll, 'optionalCall', _6 => _6(event)]);
1233
+ _optionalChain([onScroll, 'optionalCall', _10 => _10(event)]);
1060
1234
  if (!onEndReached) return;
1061
1235
  const { layoutMeasurement, contentOffset, contentSize } = event.nativeEvent;
1062
- if (!_optionalChain([layoutMeasurement, 'optionalAccess', _7 => _7.height])) return;
1236
+ if (!_optionalChain([layoutMeasurement, 'optionalAccess', _11 => _11.height])) return;
1063
1237
  const distanceFromEnd = contentSize.height - (layoutMeasurement.height + contentOffset.y);
1064
1238
  const threshold = onEndReachedThreshold * layoutMeasurement.height;
1065
1239
  if (distanceFromEnd <= threshold && contentSize.height !== lastEndReachedHeight.current) {
@@ -1116,4 +1290,8 @@ MasonryGridBuilder.displayName = "MasonryGridBuilder";
1116
1290
 
1117
1291
 
1118
1292
 
1119
- exports.AspectRatio = AspectRatio; exports.BlurView = BlurView; exports.Center = Center; exports.Column = Column; exports.ConditionalView = ConditionalView; exports.Grid = Grid; exports.GridBuilder = GridBuilder; exports.GridItem = GridItem; exports.Margin = Margin; exports.MasonryGrid = MasonryGrid; exports.MasonryGridBuilder = MasonryGridBuilder; exports.MasonryGridItem = MasonryGridItem; exports.Padding = Padding; exports.PositionedView = PositionedView; exports.RoundedView = RoundedView; exports.Row = Row; exports.Screen = Screen; exports.SizedBox = SizedBox; exports.Spacer = Spacer; exports.Surface = Surface;
1293
+
1294
+
1295
+
1296
+
1297
+ exports.Align = Align; exports.AspectRatio = AspectRatio; exports.BlurView = BlurView; exports.Center = Center; exports.Column = Column; exports.ConditionalView = ConditionalView; exports.ConstrainedBox = ConstrainedBox; exports.Container = Container; exports.FractionallySizedBox = FractionallySizedBox; exports.Grid = Grid; exports.GridBuilder = GridBuilder; exports.GridItem = GridItem; exports.Margin = Margin; exports.MasonryGrid = MasonryGrid; exports.MasonryGridBuilder = MasonryGridBuilder; exports.MasonryGridItem = MasonryGridItem; exports.Padding = Padding; exports.PositionedView = PositionedView; exports.RoundedView = RoundedView; exports.Row = Row; exports.Screen = Screen; exports.SizedBox = SizedBox; exports.Spacer = Spacer; exports.Surface = Surface;