vitest-native 0.7.0 → 0.9.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.
- package/CHANGELOG.md +373 -0
- package/README.md +32 -14
- package/dist/cli.cjs +506 -0
- package/dist/cli.d.cts +4 -0
- package/dist/cli.d.mts +4 -0
- package/dist/cli.mjs +502 -0
- package/dist/ecosystem-BIWaVwYL.cjs +294 -0
- package/dist/ecosystem-EFtHnKS9.mjs +256 -0
- package/dist/{index-DbfKy_bm.d.mts → index-CEgRDdhd.d.cts} +22 -3
- package/dist/{index-BgzErxHj.d.cts → index-j-0tueBr.d.mts} +20 -5
- package/dist/index.cjs +345 -200
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +341 -196
- package/dist/jest-compat/setup.mjs +65 -1
- package/dist/native/boundary.mjs +108 -30
- package/dist/native/compile-cache.mjs +45 -0
- package/dist/native/explain.mjs +69 -0
- package/dist/native/hooks.mjs +77 -4
- package/dist/native/loader.mjs +36 -7
- package/dist/native/match.mjs +107 -8
- package/dist/native/registry.mjs +471 -0
- package/dist/native/reset.mjs +18 -12
- package/dist/native/runner.mjs +13 -7
- package/dist/native/setup.mjs +44 -0
- package/dist/native/transform.mjs +88 -19
- package/dist/native/worker.mjs +13 -0
- package/dist/pool-CJmjRgsB.mjs +117 -0
- package/dist/pool-DzsEo9vv.cjs +121 -0
- package/dist/{preset-map-CNBOeqAu.cjs → preset-map-CG4FMtsl.cjs} +5 -1
- package/dist/{preset-map-C1UwEald.mjs → preset-map-CNsZKfvu.mjs} +5 -1
- package/dist/{presets-BTG8fiNF.cjs → presets-C4faM3ds.cjs} +838 -2
- package/dist/{presets-BFuAMwYQ.mjs → presets-CuDrNA_W.mjs} +761 -3
- package/dist/presets.cjs +5 -1
- package/dist/presets.d.cts +2 -2
- package/dist/presets.d.mts +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/setup.cjs +327 -347
- package/dist/setup.mjs +318 -338
- package/docs/hot-default-design.md +129 -0
- package/docs/migrating-from-jest.md +43 -7
- package/docs/migrating-from-vitest-react-native.md +1 -1
- package/docs/release-readiness.md +2 -1
- package/package.json +23 -7
- package/dist/pool-B7LBfcMQ.mjs +0 -67
- package/dist/pool-p54QV1dQ.cjs +0 -69
package/dist/setup.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-CZWwpsFl.cjs");
|
|
2
|
-
const require_preset_map = require("./preset-map-
|
|
3
|
-
const require_presets = require("./presets-
|
|
2
|
+
const require_preset_map = require("./preset-map-CG4FMtsl.cjs");
|
|
3
|
+
const require_presets = require("./presets-C4faM3ds.cjs");
|
|
4
4
|
const require_serializer = require("./serializer.cjs");
|
|
5
5
|
const require_matchers = require("./matchers.cjs");
|
|
6
6
|
let node_path = require("node:path");
|
|
@@ -9,18 +9,6 @@ let node_module = require("node:module");
|
|
|
9
9
|
let vitest = require("vitest");
|
|
10
10
|
let react = require("react");
|
|
11
11
|
react = require_chunk.__toESM(react, 1);
|
|
12
|
-
//#region src/mocks/components/View.ts
|
|
13
|
-
function createViewMock() {
|
|
14
|
-
const View = react.default.forwardRef((props, ref) => {
|
|
15
|
-
return react.default.createElement("View", {
|
|
16
|
-
...props,
|
|
17
|
-
ref
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
View.displayName = "View";
|
|
21
|
-
return View;
|
|
22
|
-
}
|
|
23
|
-
//#endregion
|
|
24
12
|
//#region src/mocks/components/Text.ts
|
|
25
13
|
function createTextMock() {
|
|
26
14
|
const Text = react.default.forwardRef((props, ref) => {
|
|
@@ -68,141 +56,6 @@ function createImageMock() {
|
|
|
68
56
|
return Image;
|
|
69
57
|
}
|
|
70
58
|
//#endregion
|
|
71
|
-
//#region src/mocks/components/TextInput.ts
|
|
72
|
-
function createTextInputMock() {
|
|
73
|
-
const TextInput = react.default.forwardRef((props, ref) => {
|
|
74
|
-
const instanceMethods = {
|
|
75
|
-
focus: vitest.vi.fn(),
|
|
76
|
-
blur: vitest.vi.fn(),
|
|
77
|
-
clear: vitest.vi.fn(),
|
|
78
|
-
isFocused: vitest.vi.fn(() => false),
|
|
79
|
-
setNativeProps: vitest.vi.fn()
|
|
80
|
-
};
|
|
81
|
-
react.default.useImperativeHandle(ref, () => instanceMethods);
|
|
82
|
-
return react.default.createElement("TextInput", {
|
|
83
|
-
...props,
|
|
84
|
-
ref
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
TextInput.displayName = "TextInput";
|
|
88
|
-
return TextInput;
|
|
89
|
-
}
|
|
90
|
-
//#endregion
|
|
91
|
-
//#region src/mocks/components/ScrollView.ts
|
|
92
|
-
function createScrollViewMock() {
|
|
93
|
-
const ScrollView = react.default.forwardRef((props, ref) => {
|
|
94
|
-
const { children, refreshControl, ...rest } = props;
|
|
95
|
-
const instanceMethods = {
|
|
96
|
-
scrollTo: vitest.vi.fn(),
|
|
97
|
-
scrollToEnd: vitest.vi.fn(),
|
|
98
|
-
flashScrollIndicators: vitest.vi.fn(),
|
|
99
|
-
getScrollResponder: vitest.vi.fn(() => ({})),
|
|
100
|
-
getInnerViewNode: vitest.vi.fn(),
|
|
101
|
-
setNativeProps: vitest.vi.fn()
|
|
102
|
-
};
|
|
103
|
-
react.default.useImperativeHandle(ref, () => instanceMethods);
|
|
104
|
-
return react.default.createElement("RCTScrollView", {
|
|
105
|
-
...rest,
|
|
106
|
-
ref
|
|
107
|
-
}, refreshControl, react.default.createElement("View", null, children));
|
|
108
|
-
});
|
|
109
|
-
ScrollView.displayName = "ScrollView";
|
|
110
|
-
return ScrollView;
|
|
111
|
-
}
|
|
112
|
-
//#endregion
|
|
113
|
-
//#region src/mocks/components/FlatList.ts
|
|
114
|
-
function createFlatListMock() {
|
|
115
|
-
const FlatList = react.default.forwardRef((props, ref) => {
|
|
116
|
-
const { data, renderItem, keyExtractor, ListHeaderComponent, ListFooterComponent, ListEmptyComponent, ItemSeparatorComponent, refreshControl, ...rest } = props;
|
|
117
|
-
const instanceMethods = {
|
|
118
|
-
scrollToEnd: vitest.vi.fn(),
|
|
119
|
-
scrollToIndex: vitest.vi.fn(),
|
|
120
|
-
scrollToItem: vitest.vi.fn(),
|
|
121
|
-
scrollToOffset: vitest.vi.fn(),
|
|
122
|
-
recordInteraction: vitest.vi.fn(),
|
|
123
|
-
flashScrollIndicators: vitest.vi.fn(),
|
|
124
|
-
getScrollResponder: vitest.vi.fn(() => ({})),
|
|
125
|
-
getNativeScrollRef: vitest.vi.fn(),
|
|
126
|
-
getScrollableNode: vitest.vi.fn(),
|
|
127
|
-
setNativeProps: vitest.vi.fn()
|
|
128
|
-
};
|
|
129
|
-
react.default.useImperativeHandle(ref, () => instanceMethods);
|
|
130
|
-
const children = [];
|
|
131
|
-
if (ListHeaderComponent) children.push(react.default.createElement("FlatList-Header", { key: "__header" }, typeof ListHeaderComponent === "function" ? react.default.createElement(ListHeaderComponent) : ListHeaderComponent));
|
|
132
|
-
if (data && data.length > 0) data.forEach((item, index) => {
|
|
133
|
-
const key = keyExtractor ? keyExtractor(item, index) : String(index);
|
|
134
|
-
children.push(react.default.createElement(react.default.Fragment, { key }, renderItem({
|
|
135
|
-
item,
|
|
136
|
-
index,
|
|
137
|
-
separators: {
|
|
138
|
-
highlight: vitest.vi.fn(),
|
|
139
|
-
unhighlight: vitest.vi.fn(),
|
|
140
|
-
updateProps: vitest.vi.fn()
|
|
141
|
-
}
|
|
142
|
-
})));
|
|
143
|
-
if (ItemSeparatorComponent && index < data.length - 1) children.push(react.default.createElement(react.default.Fragment, { key: `separator-${index}` }, typeof ItemSeparatorComponent === "function" ? react.default.createElement(ItemSeparatorComponent) : ItemSeparatorComponent));
|
|
144
|
-
});
|
|
145
|
-
else if (ListEmptyComponent) children.push(react.default.createElement("FlatList-Empty", { key: "__empty" }, typeof ListEmptyComponent === "function" ? react.default.createElement(ListEmptyComponent) : ListEmptyComponent));
|
|
146
|
-
if (ListFooterComponent) children.push(react.default.createElement("FlatList-Footer", { key: "__footer" }, typeof ListFooterComponent === "function" ? react.default.createElement(ListFooterComponent) : ListFooterComponent));
|
|
147
|
-
if (refreshControl) children.unshift(refreshControl);
|
|
148
|
-
return react.default.createElement("FlatList", {
|
|
149
|
-
...rest,
|
|
150
|
-
ref
|
|
151
|
-
}, ...children);
|
|
152
|
-
});
|
|
153
|
-
FlatList.displayName = "FlatList";
|
|
154
|
-
return FlatList;
|
|
155
|
-
}
|
|
156
|
-
//#endregion
|
|
157
|
-
//#region src/mocks/components/SectionList.ts
|
|
158
|
-
function createSectionListMock() {
|
|
159
|
-
const SectionList = react.default.forwardRef((props, ref) => {
|
|
160
|
-
const { sections, renderItem, renderSectionHeader, renderSectionFooter, keyExtractor, refreshControl, ListEmptyComponent, ListHeaderComponent, ListFooterComponent, ItemSeparatorComponent, SectionSeparatorComponent, ...rest } = props;
|
|
161
|
-
const instanceMethods = {
|
|
162
|
-
scrollToEnd: vitest.vi.fn(),
|
|
163
|
-
scrollToIndex: vitest.vi.fn(),
|
|
164
|
-
scrollToLocation: vitest.vi.fn(),
|
|
165
|
-
recordInteraction: vitest.vi.fn(),
|
|
166
|
-
flashScrollIndicators: vitest.vi.fn(),
|
|
167
|
-
getScrollResponder: vitest.vi.fn(() => ({})),
|
|
168
|
-
getNativeScrollRef: vitest.vi.fn(),
|
|
169
|
-
getScrollableNode: vitest.vi.fn(),
|
|
170
|
-
setNativeProps: vitest.vi.fn()
|
|
171
|
-
};
|
|
172
|
-
react.default.useImperativeHandle(ref, () => instanceMethods);
|
|
173
|
-
const children = [];
|
|
174
|
-
if (ListHeaderComponent) children.push(react.default.createElement("SectionList-Header", { key: "__header" }, typeof ListHeaderComponent === "function" ? react.default.createElement(ListHeaderComponent) : ListHeaderComponent));
|
|
175
|
-
if (sections) sections.forEach((section, sectionIndex) => {
|
|
176
|
-
if (renderSectionHeader) children.push(react.default.createElement(react.default.Fragment, { key: `header-${sectionIndex}` }, renderSectionHeader({ section })));
|
|
177
|
-
if (SectionSeparatorComponent && sectionIndex > 0) children.push(react.default.createElement(react.default.Fragment, { key: `section-sep-${sectionIndex}` }, typeof SectionSeparatorComponent === "function" ? react.default.createElement(SectionSeparatorComponent) : SectionSeparatorComponent));
|
|
178
|
-
if (section.data) section.data.forEach((item, index) => {
|
|
179
|
-
const key = keyExtractor ? keyExtractor(item, index) : `${sectionIndex}-${index}`;
|
|
180
|
-
children.push(react.default.createElement(react.default.Fragment, { key }, renderItem({
|
|
181
|
-
item,
|
|
182
|
-
index,
|
|
183
|
-
section,
|
|
184
|
-
separators: {
|
|
185
|
-
highlight: vitest.vi.fn(),
|
|
186
|
-
unhighlight: vitest.vi.fn(),
|
|
187
|
-
updateProps: vitest.vi.fn()
|
|
188
|
-
}
|
|
189
|
-
})));
|
|
190
|
-
if (ItemSeparatorComponent && index < section.data.length - 1) children.push(react.default.createElement(react.default.Fragment, { key: `sep-${sectionIndex}-${index}` }, typeof ItemSeparatorComponent === "function" ? react.default.createElement(ItemSeparatorComponent) : ItemSeparatorComponent));
|
|
191
|
-
});
|
|
192
|
-
if (renderSectionFooter) children.push(react.default.createElement(react.default.Fragment, { key: `footer-${sectionIndex}` }, renderSectionFooter({ section })));
|
|
193
|
-
});
|
|
194
|
-
if (ListFooterComponent) children.push(react.default.createElement("SectionList-Footer", { key: "__footer" }, typeof ListFooterComponent === "function" ? react.default.createElement(ListFooterComponent) : ListFooterComponent));
|
|
195
|
-
if (refreshControl) children.unshift(refreshControl);
|
|
196
|
-
if ((!sections || sections.length === 0) && ListEmptyComponent) children.push(react.default.createElement("SectionList-Empty", { key: "__empty" }, typeof ListEmptyComponent === "function" ? react.default.createElement(ListEmptyComponent) : ListEmptyComponent));
|
|
197
|
-
return react.default.createElement("SectionList", {
|
|
198
|
-
...rest,
|
|
199
|
-
ref
|
|
200
|
-
}, ...children);
|
|
201
|
-
});
|
|
202
|
-
SectionList.displayName = "SectionList";
|
|
203
|
-
return SectionList;
|
|
204
|
-
}
|
|
205
|
-
//#endregion
|
|
206
59
|
//#region src/mocks/components/Modal.ts
|
|
207
60
|
function createModalMock() {
|
|
208
61
|
const Modal = react.default.forwardRef((props, ref) => {
|
|
@@ -218,27 +71,6 @@ function createModalMock() {
|
|
|
218
71
|
return Modal;
|
|
219
72
|
}
|
|
220
73
|
//#endregion
|
|
221
|
-
//#region src/mocks/components/TouchableOpacity.ts
|
|
222
|
-
function createTouchableOpacityMock() {
|
|
223
|
-
const TouchableOpacity = react.default.forwardRef((props, ref) => react.default.createElement("TouchableOpacity", require_presets.buildPressableHostProps(props, ref)));
|
|
224
|
-
TouchableOpacity.displayName = "TouchableOpacity";
|
|
225
|
-
return TouchableOpacity;
|
|
226
|
-
}
|
|
227
|
-
//#endregion
|
|
228
|
-
//#region src/mocks/components/TouchableHighlight.ts
|
|
229
|
-
function createTouchableHighlightMock() {
|
|
230
|
-
const TouchableHighlight = react.default.forwardRef((props, ref) => react.default.createElement("TouchableHighlight", require_presets.buildPressableHostProps(props, ref)));
|
|
231
|
-
TouchableHighlight.displayName = "TouchableHighlight";
|
|
232
|
-
return TouchableHighlight;
|
|
233
|
-
}
|
|
234
|
-
//#endregion
|
|
235
|
-
//#region src/mocks/components/TouchableWithoutFeedback.ts
|
|
236
|
-
function createTouchableWithoutFeedbackMock() {
|
|
237
|
-
const TouchableWithoutFeedback = react.default.forwardRef((props, ref) => react.default.createElement("TouchableWithoutFeedback", require_presets.buildPressableHostProps(props, ref)));
|
|
238
|
-
TouchableWithoutFeedback.displayName = "TouchableWithoutFeedback";
|
|
239
|
-
return TouchableWithoutFeedback;
|
|
240
|
-
}
|
|
241
|
-
//#endregion
|
|
242
74
|
//#region src/mocks/components/TouchableNativeFeedback.ts
|
|
243
75
|
function createTouchableNativeFeedbackMock() {
|
|
244
76
|
const TouchableNativeFeedback = react.default.forwardRef((props, ref) => {
|
|
@@ -382,46 +214,6 @@ function createImageBackgroundMock() {
|
|
|
382
214
|
return ImageBackground;
|
|
383
215
|
}
|
|
384
216
|
//#endregion
|
|
385
|
-
//#region src/mocks/components/VirtualizedList.ts
|
|
386
|
-
function createVirtualizedListMock() {
|
|
387
|
-
const VirtualizedList = react.default.forwardRef((props, ref) => {
|
|
388
|
-
const { data, renderItem, keyExtractor, getItemCount, getItem, ListHeaderComponent, ListFooterComponent, ListEmptyComponent, ...rest } = props;
|
|
389
|
-
const instanceMethods = {
|
|
390
|
-
scrollToEnd: vitest.vi.fn(),
|
|
391
|
-
scrollToIndex: vitest.vi.fn(),
|
|
392
|
-
scrollToItem: vitest.vi.fn(),
|
|
393
|
-
scrollToOffset: vitest.vi.fn(),
|
|
394
|
-
recordInteraction: vitest.vi.fn(),
|
|
395
|
-
flashScrollIndicators: vitest.vi.fn(),
|
|
396
|
-
getScrollResponder: vitest.vi.fn(() => ({})),
|
|
397
|
-
getNativeScrollRef: vitest.vi.fn(),
|
|
398
|
-
getScrollableNode: vitest.vi.fn(),
|
|
399
|
-
setNativeProps: vitest.vi.fn()
|
|
400
|
-
};
|
|
401
|
-
react.default.useImperativeHandle(ref, () => instanceMethods);
|
|
402
|
-
const children = [];
|
|
403
|
-
if (ListHeaderComponent) children.push(react.default.createElement("VirtualizedList-Header", { key: "__header" }, typeof ListHeaderComponent === "function" ? react.default.createElement(ListHeaderComponent) : ListHeaderComponent));
|
|
404
|
-
const itemCount = getItemCount ? getItemCount(data) : data ? data.length : 0;
|
|
405
|
-
if (itemCount > 0) for (let index = 0; index < itemCount; index++) {
|
|
406
|
-
const item = getItem ? getItem(data, index) : data[index];
|
|
407
|
-
const key = keyExtractor ? keyExtractor(item, index) : String(index);
|
|
408
|
-
children.push(react.default.createElement(react.default.Fragment, { key }, renderItem({
|
|
409
|
-
item,
|
|
410
|
-
index,
|
|
411
|
-
separators: {}
|
|
412
|
-
})));
|
|
413
|
-
}
|
|
414
|
-
else if (ListEmptyComponent) children.push(react.default.createElement("VirtualizedList-Empty", { key: "__empty" }, typeof ListEmptyComponent === "function" ? react.default.createElement(ListEmptyComponent) : ListEmptyComponent));
|
|
415
|
-
if (ListFooterComponent) children.push(react.default.createElement("VirtualizedList-Footer", { key: "__footer" }, typeof ListFooterComponent === "function" ? react.default.createElement(ListFooterComponent) : ListFooterComponent));
|
|
416
|
-
return react.default.createElement("VirtualizedList", {
|
|
417
|
-
...rest,
|
|
418
|
-
ref
|
|
419
|
-
}, ...children);
|
|
420
|
-
});
|
|
421
|
-
VirtualizedList.displayName = "VirtualizedList";
|
|
422
|
-
return VirtualizedList;
|
|
423
|
-
}
|
|
424
|
-
//#endregion
|
|
425
217
|
//#region src/mocks/components/InputAccessoryView.ts
|
|
426
218
|
function createInputAccessoryViewMock() {
|
|
427
219
|
const InputAccessoryView = react.default.forwardRef((props, ref) => {
|
|
@@ -775,71 +567,152 @@ function checkValidRanges(inputRange, outputRange) {
|
|
|
775
567
|
for (let i = 1; i < inputRange.length; ++i) if (!(inputRange[i] >= inputRange[i - 1])) throw new Error("inputRange must be monotonically non-decreasing " + String(inputRange));
|
|
776
568
|
if (inputRange.length !== outputRange.length) throw new Error("inputRange (" + inputRange.length + ") and outputRange (" + outputRange.length + ") must have the same length");
|
|
777
569
|
}
|
|
778
|
-
var
|
|
779
|
-
_value;
|
|
570
|
+
var AnimatedNode = class {
|
|
780
571
|
_listeners = /* @__PURE__ */ new Map();
|
|
572
|
+
_children = /* @__PURE__ */ new Set();
|
|
781
573
|
_listenerIdCounter = 0;
|
|
782
|
-
_tracking = null;
|
|
783
|
-
constructor(value = 0) {
|
|
784
|
-
this._value = value;
|
|
785
|
-
}
|
|
786
|
-
setValue(value) {
|
|
787
|
-
this._value = value;
|
|
788
|
-
this._listeners.forEach((fn) => fn({ value }));
|
|
789
|
-
}
|
|
790
574
|
getValue() {
|
|
791
|
-
return this.
|
|
575
|
+
return this.__getValue();
|
|
576
|
+
}
|
|
577
|
+
_attachToParents() {}
|
|
578
|
+
_detachFromParents() {}
|
|
579
|
+
_consumerCount() {
|
|
580
|
+
return this._listeners.size + this._children.size;
|
|
792
581
|
}
|
|
793
582
|
addListener(callback) {
|
|
794
583
|
const id = String(++this._listenerIdCounter);
|
|
795
584
|
this._listeners.set(id, callback);
|
|
585
|
+
if (this._consumerCount() === 1) this._attachToParents();
|
|
796
586
|
return id;
|
|
797
587
|
}
|
|
798
588
|
removeListener(id) {
|
|
799
|
-
this._listeners.delete(id);
|
|
589
|
+
if (this._listeners.delete(id) && this._consumerCount() === 0) this._detachFromParents();
|
|
800
590
|
}
|
|
801
591
|
removeAllListeners() {
|
|
592
|
+
const had = this._listeners.size > 0;
|
|
802
593
|
this._listeners.clear();
|
|
594
|
+
if (had && this._consumerCount() === 0) this._detachFromParents();
|
|
803
595
|
}
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
},
|
|
818
|
-
addListener: () => "0",
|
|
819
|
-
removeListener: () => {},
|
|
820
|
-
removeAllListeners: () => {},
|
|
821
|
-
stopAnimation: (cb) => cb?.(compute()),
|
|
822
|
-
resetAnimation: (cb) => cb?.(compute())
|
|
823
|
-
};
|
|
596
|
+
/** Graph edge: `fn` runs whenever this node's value may have changed. */
|
|
597
|
+
__addChild(fn) {
|
|
598
|
+
this._children.add(fn);
|
|
599
|
+
if (this._consumerCount() === 1) this._attachToParents();
|
|
600
|
+
}
|
|
601
|
+
__removeChild(fn) {
|
|
602
|
+
if (this._children.delete(fn) && this._consumerCount() === 0) this._detachFromParents();
|
|
603
|
+
}
|
|
604
|
+
/** Notify consumers with the node's CURRENT (offset-inclusive) value. */
|
|
605
|
+
_notify() {
|
|
606
|
+
if (this._listeners.size > 0) {
|
|
607
|
+
const value = this.__getValue();
|
|
608
|
+
this._listeners.forEach((fn) => fn({ value }));
|
|
824
609
|
}
|
|
825
|
-
|
|
610
|
+
this._children.forEach((fn) => fn());
|
|
611
|
+
}
|
|
612
|
+
interpolate(config) {
|
|
613
|
+
const { inputRange, outputRange } = config || {};
|
|
614
|
+
if (!inputRange || !outputRange || inputRange.length < 2 || outputRange.length < 2) return new AnimatedValue(Number(this.__getValue()) || 0);
|
|
615
|
+
return new AnimatedInterpolation(this, config);
|
|
826
616
|
}
|
|
827
617
|
stopAnimation(callback) {
|
|
828
|
-
callback?.(this.
|
|
618
|
+
callback?.(this.__getValue());
|
|
829
619
|
}
|
|
830
620
|
resetAnimation(callback) {
|
|
831
|
-
callback?.(this.
|
|
621
|
+
callback?.(this.__getValue());
|
|
832
622
|
}
|
|
833
623
|
toJSON() {
|
|
834
|
-
return this.
|
|
624
|
+
return this.__getValue();
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
var AnimatedValue = class extends AnimatedNode {
|
|
628
|
+
_value;
|
|
629
|
+
_offset = 0;
|
|
630
|
+
_tracking = null;
|
|
631
|
+
constructor(value = 0) {
|
|
632
|
+
super();
|
|
633
|
+
this._value = value;
|
|
634
|
+
}
|
|
635
|
+
setValue(value) {
|
|
636
|
+
this._value = value;
|
|
637
|
+
this._notify();
|
|
638
|
+
}
|
|
639
|
+
__getValue() {
|
|
640
|
+
return this._value + this._offset;
|
|
641
|
+
}
|
|
642
|
+
setOffset(offset) {
|
|
643
|
+
this._offset = offset;
|
|
644
|
+
}
|
|
645
|
+
flattenOffset() {
|
|
646
|
+
this._value += this._offset;
|
|
647
|
+
this._offset = 0;
|
|
648
|
+
}
|
|
649
|
+
extractOffset() {
|
|
650
|
+
this._offset += this._value;
|
|
651
|
+
this._value = 0;
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
var AnimatedInterpolation = class extends AnimatedNode {
|
|
655
|
+
_parent;
|
|
656
|
+
_config;
|
|
657
|
+
_preparedString = null;
|
|
658
|
+
constructor(parent, config) {
|
|
659
|
+
super();
|
|
660
|
+
this._parent = parent;
|
|
661
|
+
this._config = config;
|
|
662
|
+
const { inputRange, outputRange } = config;
|
|
663
|
+
checkValidRanges(inputRange, outputRange);
|
|
664
|
+
if (typeof outputRange[0] === "string") this._preparedString = prepareStringInterpolation(outputRange);
|
|
665
|
+
}
|
|
666
|
+
_propagate = () => this._notify();
|
|
667
|
+
_attachToParents() {
|
|
668
|
+
this._parent.__addChild(this._propagate);
|
|
669
|
+
}
|
|
670
|
+
_detachFromParents() {
|
|
671
|
+
this._parent.__removeChild(this._propagate);
|
|
672
|
+
}
|
|
673
|
+
__getValue() {
|
|
674
|
+
const { inputRange, outputRange, extrapolate = "extend", extrapolateLeft, extrapolateRight, easing = IDENTITY_EASING } = this._config;
|
|
675
|
+
const input = Number(this._parent.__getValue());
|
|
676
|
+
if (this._preparedString) return interpolateString(this._preparedString, input, inputRange, extrapolate, extrapolateLeft, extrapolateRight, easing);
|
|
677
|
+
return interpolateNumeric(input, inputRange, outputRange, extrapolate, extrapolateLeft, extrapolateRight, easing);
|
|
678
|
+
}
|
|
679
|
+
interpolate(config) {
|
|
680
|
+
if (this._preparedString) throw new Error("Cannot chain an interpolation off a string-valued interpolation");
|
|
681
|
+
return super.interpolate(config);
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
var AnimatedOp = class extends AnimatedNode {
|
|
685
|
+
_compute;
|
|
686
|
+
_parents;
|
|
687
|
+
_propagate = () => this._notify();
|
|
688
|
+
constructor(inputs, compute) {
|
|
689
|
+
super();
|
|
690
|
+
this._compute = compute;
|
|
691
|
+
this._parents = inputs.filter((i) => i instanceof AnimatedNode);
|
|
692
|
+
}
|
|
693
|
+
_attachToParents() {
|
|
694
|
+
for (const parent of this._parents) parent.__addChild(this._propagate);
|
|
695
|
+
}
|
|
696
|
+
_detachFromParents() {
|
|
697
|
+
for (const parent of this._parents) parent.__removeChild(this._propagate);
|
|
698
|
+
}
|
|
699
|
+
__getValue() {
|
|
700
|
+
return this._compute();
|
|
835
701
|
}
|
|
836
|
-
setOffset(_offset) {}
|
|
837
|
-
flattenOffset() {}
|
|
838
|
-
extractOffset() {}
|
|
839
702
|
};
|
|
703
|
+
/** Numeric value of an operand that may be a node, a number, or junk (→ 0). */
|
|
704
|
+
function operandValue(v) {
|
|
705
|
+
if (v instanceof AnimatedNode) {
|
|
706
|
+
const n = Number(v.__getValue());
|
|
707
|
+
return Number.isNaN(n) ? 0 : n;
|
|
708
|
+
}
|
|
709
|
+
return typeof v === "number" ? v : 0;
|
|
710
|
+
}
|
|
840
711
|
var AnimatedValueXY = class {
|
|
841
712
|
x;
|
|
842
713
|
y;
|
|
714
|
+
_listenerIdCounter = 0;
|
|
715
|
+
_joint = /* @__PURE__ */ new Map();
|
|
843
716
|
constructor(value) {
|
|
844
717
|
this.x = new AnimatedValue(value?.x ?? 0);
|
|
845
718
|
this.y = new AnimatedValue(value?.y ?? 0);
|
|
@@ -848,31 +721,52 @@ var AnimatedValueXY = class {
|
|
|
848
721
|
this.x.setValue(value.x);
|
|
849
722
|
this.y.setValue(value.y);
|
|
850
723
|
}
|
|
851
|
-
setOffset(
|
|
852
|
-
|
|
853
|
-
|
|
724
|
+
setOffset(offset) {
|
|
725
|
+
this.x.setOffset(offset.x);
|
|
726
|
+
this.y.setOffset(offset.y);
|
|
727
|
+
}
|
|
728
|
+
flattenOffset() {
|
|
729
|
+
this.x.flattenOffset();
|
|
730
|
+
this.y.flattenOffset();
|
|
731
|
+
}
|
|
732
|
+
extractOffset() {
|
|
733
|
+
this.x.extractOffset();
|
|
734
|
+
this.y.extractOffset();
|
|
735
|
+
}
|
|
736
|
+
__getValue() {
|
|
737
|
+
return {
|
|
738
|
+
x: this.x.__getValue(),
|
|
739
|
+
y: this.y.__getValue()
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
getValue() {
|
|
743
|
+
return this.__getValue();
|
|
744
|
+
}
|
|
854
745
|
stopAnimation(callback) {
|
|
855
|
-
callback?.(
|
|
856
|
-
x: this.x.getValue(),
|
|
857
|
-
y: this.y.getValue()
|
|
858
|
-
});
|
|
746
|
+
callback?.(this.__getValue());
|
|
859
747
|
}
|
|
860
748
|
resetAnimation(callback) {
|
|
861
|
-
callback?.(
|
|
862
|
-
x: this.x.getValue(),
|
|
863
|
-
y: this.y.getValue()
|
|
864
|
-
});
|
|
749
|
+
callback?.(this.__getValue());
|
|
865
750
|
}
|
|
866
|
-
addListener(
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
751
|
+
addListener(callback) {
|
|
752
|
+
const emit = () => callback(this.__getValue());
|
|
753
|
+
const id = String(++this._listenerIdCounter);
|
|
754
|
+
const pair = {
|
|
755
|
+
x: this.x.addListener(emit),
|
|
756
|
+
y: this.y.addListener(emit)
|
|
870
757
|
};
|
|
758
|
+
this._joint.set(id, pair);
|
|
759
|
+
return pair;
|
|
871
760
|
}
|
|
872
761
|
removeListener(id) {
|
|
873
762
|
this.x.removeListener(id.x);
|
|
874
763
|
this.y.removeListener(id.y);
|
|
875
764
|
}
|
|
765
|
+
removeAllListeners() {
|
|
766
|
+
this.x.removeAllListeners();
|
|
767
|
+
this.y.removeAllListeners();
|
|
768
|
+
this._joint.clear();
|
|
769
|
+
}
|
|
876
770
|
getLayout() {
|
|
877
771
|
return {
|
|
878
772
|
left: this.x,
|
|
@@ -970,26 +864,25 @@ function parseColorString(color) {
|
|
|
970
864
|
1
|
|
971
865
|
];
|
|
972
866
|
}
|
|
973
|
-
var AnimatedColor = class {
|
|
867
|
+
var AnimatedColor = class extends AnimatedNode {
|
|
974
868
|
r;
|
|
975
869
|
g;
|
|
976
870
|
b;
|
|
977
871
|
a;
|
|
978
|
-
_listeners = /* @__PURE__ */ new Map();
|
|
979
|
-
_listenerIdCounter = 0;
|
|
980
872
|
constructor(color) {
|
|
873
|
+
super();
|
|
981
874
|
if (typeof color === "string") {
|
|
982
875
|
const [r, g, b, a] = parseColorString(color);
|
|
983
876
|
this.r = new AnimatedValue(r);
|
|
984
877
|
this.g = new AnimatedValue(g);
|
|
985
878
|
this.b = new AnimatedValue(b);
|
|
986
879
|
this.a = new AnimatedValue(a);
|
|
987
|
-
} else if (color && typeof color === "object"
|
|
880
|
+
} else if (color && typeof color === "object" && color.r instanceof AnimatedValue) {
|
|
988
881
|
this.r = color.r;
|
|
989
882
|
this.g = color.g;
|
|
990
883
|
this.b = color.b;
|
|
991
884
|
this.a = color.a;
|
|
992
|
-
} else if (typeof color.r === "number") {
|
|
885
|
+
} else if (color && typeof color === "object" && typeof color.r === "number") {
|
|
993
886
|
this.r = new AnimatedValue(color.r);
|
|
994
887
|
this.g = new AnimatedValue(color.g ?? 0);
|
|
995
888
|
this.b = new AnimatedValue(color.b ?? 0);
|
|
@@ -1000,12 +893,12 @@ var AnimatedColor = class {
|
|
|
1000
893
|
this.b = new AnimatedValue(0);
|
|
1001
894
|
this.a = new AnimatedValue(1);
|
|
1002
895
|
}
|
|
1003
|
-
|
|
1004
|
-
this.r
|
|
1005
|
-
this.g
|
|
1006
|
-
this.b
|
|
1007
|
-
this.a
|
|
1008
|
-
|
|
896
|
+
for (const channel of [
|
|
897
|
+
this.r,
|
|
898
|
+
this.g,
|
|
899
|
+
this.b,
|
|
900
|
+
this.a
|
|
901
|
+
]) channel.__addChild(() => this._notify());
|
|
1009
902
|
}
|
|
1010
903
|
setValue(value) {
|
|
1011
904
|
if (typeof value === "string") {
|
|
@@ -1020,31 +913,12 @@ var AnimatedColor = class {
|
|
|
1020
913
|
this.b.setValue(value.b ?? 0);
|
|
1021
914
|
this.a.setValue(value.a ?? 1);
|
|
1022
915
|
}
|
|
1023
|
-
const colorStr = this.__getValue();
|
|
1024
|
-
this._listeners.forEach((fn) => fn({ value: colorStr }));
|
|
1025
916
|
}
|
|
1026
917
|
__getValue() {
|
|
1027
918
|
return `rgba(${Math.round(this.r.getValue())}, ${Math.round(this.g.getValue())}, ${Math.round(this.b.getValue())}, ${this.a.getValue()})`;
|
|
1028
919
|
}
|
|
1029
|
-
addListener(callback) {
|
|
1030
|
-
const id = String(++this._listenerIdCounter);
|
|
1031
|
-
this._listeners.set(id, callback);
|
|
1032
|
-
return id;
|
|
1033
|
-
}
|
|
1034
|
-
removeListener(id) {
|
|
1035
|
-
this._listeners.delete(id);
|
|
1036
|
-
}
|
|
1037
|
-
removeAllListeners() {
|
|
1038
|
-
this._listeners.clear();
|
|
1039
|
-
}
|
|
1040
920
|
setOffset(_offset) {}
|
|
1041
921
|
flattenOffset() {}
|
|
1042
|
-
stopAnimation(callback) {
|
|
1043
|
-
callback?.(this.__getValue());
|
|
1044
|
-
}
|
|
1045
|
-
resetAnimation(callback) {
|
|
1046
|
-
callback?.(this.__getValue());
|
|
1047
|
-
}
|
|
1048
922
|
};
|
|
1049
923
|
function createAnimation(onStart) {
|
|
1050
924
|
return {
|
|
@@ -1059,9 +933,9 @@ function createAnimation(onStart) {
|
|
|
1059
933
|
};
|
|
1060
934
|
}
|
|
1061
935
|
function resolveAnimatedLeaf(v) {
|
|
1062
|
-
if (v instanceof
|
|
936
|
+
if (v instanceof AnimatedNode) return v.__getValue();
|
|
1063
937
|
if (v && typeof v === "object" && typeof v.__getValue === "function") return v.__getValue();
|
|
1064
|
-
if (v && typeof v === "object" && typeof v.getValue === "function") return v.getValue();
|
|
938
|
+
if (v && typeof v === "object" && !Array.isArray(v) && typeof v.getValue === "function") return v.getValue();
|
|
1065
939
|
return v;
|
|
1066
940
|
}
|
|
1067
941
|
function resolveAnimatedStyle(style) {
|
|
@@ -1072,16 +946,40 @@ function resolveAnimatedStyle(style) {
|
|
|
1072
946
|
const out = {};
|
|
1073
947
|
for (const key of Object.keys(style)) {
|
|
1074
948
|
const val = style[key];
|
|
1075
|
-
if (key === "transform" && Array.isArray(val)) out[key] = val.map((t) => t && typeof t === "object" && !(t instanceof
|
|
949
|
+
if (key === "transform" && Array.isArray(val)) out[key] = val.map((t) => t && typeof t === "object" && !(t instanceof AnimatedNode) ? Object.fromEntries(Object.keys(t).map((tk) => [tk, resolveAnimatedLeaf(t[tk])])) : resolveAnimatedLeaf(t));
|
|
1076
950
|
else out[key] = resolveAnimatedLeaf(val);
|
|
1077
951
|
}
|
|
1078
952
|
return out;
|
|
1079
953
|
}
|
|
1080
954
|
return style;
|
|
1081
955
|
}
|
|
956
|
+
function collectAnimatedNodes(style, out) {
|
|
957
|
+
if (style instanceof AnimatedNode) {
|
|
958
|
+
out.add(style);
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
if (Array.isArray(style)) {
|
|
962
|
+
for (const s of style) collectAnimatedNodes(s, out);
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
if (style && typeof style === "object") for (const key of Object.keys(style)) collectAnimatedNodes(style[key], out);
|
|
966
|
+
}
|
|
967
|
+
function useAnimatedStyleSubscription(style) {
|
|
968
|
+
const [, force] = react.default.useReducer((n) => n + 1, 0);
|
|
969
|
+
react.default.useEffect(() => {
|
|
970
|
+
const nodes = /* @__PURE__ */ new Set();
|
|
971
|
+
collectAnimatedNodes(style, nodes);
|
|
972
|
+
if (nodes.size === 0) return void 0;
|
|
973
|
+
for (const node of nodes) node.__addChild(force);
|
|
974
|
+
return () => {
|
|
975
|
+
for (const node of nodes) node.__removeChild(force);
|
|
976
|
+
};
|
|
977
|
+
});
|
|
978
|
+
}
|
|
1082
979
|
function createAnimatedWrapper(displayName) {
|
|
1083
980
|
const hostName = displayName.replace(/^Animated\./, "");
|
|
1084
981
|
const Component = react.default.forwardRef((props, ref) => {
|
|
982
|
+
useAnimatedStyleSubscription(props?.style);
|
|
1085
983
|
if (props && props.style !== void 0) {
|
|
1086
984
|
const { style, ...rest } = props;
|
|
1087
985
|
return react.default.createElement(hostName, {
|
|
@@ -1100,7 +998,7 @@ function createAnimatedWrapper(displayName) {
|
|
|
1100
998
|
}
|
|
1101
999
|
function stopTracking(value) {
|
|
1102
1000
|
if (value._tracking) {
|
|
1103
|
-
value._tracking.source.
|
|
1001
|
+
value._tracking.source.__removeChild(value._tracking.child);
|
|
1104
1002
|
value._tracking = null;
|
|
1105
1003
|
}
|
|
1106
1004
|
}
|
|
@@ -1108,14 +1006,32 @@ function startTracking(value, toValue) {
|
|
|
1108
1006
|
stopTracking(value);
|
|
1109
1007
|
if (toValue instanceof AnimatedValue) {
|
|
1110
1008
|
value.setValue(toValue.getValue());
|
|
1009
|
+
const child = () => value.setValue(toValue.__getValue());
|
|
1010
|
+
toValue.__addChild(child);
|
|
1111
1011
|
value._tracking = {
|
|
1112
1012
|
source: toValue,
|
|
1113
|
-
|
|
1114
|
-
value.setValue(v);
|
|
1115
|
-
})
|
|
1013
|
+
child
|
|
1116
1014
|
};
|
|
1117
1015
|
} else value.setValue(toValue);
|
|
1118
1016
|
}
|
|
1017
|
+
var AnimatedDiffClamp = class extends AnimatedNode {
|
|
1018
|
+
_current;
|
|
1019
|
+
constructor(a, min, max) {
|
|
1020
|
+
super();
|
|
1021
|
+
let lastInput = operandValue(a);
|
|
1022
|
+
this._current = Math.min(Math.max(lastInput, min), max);
|
|
1023
|
+
if (a instanceof AnimatedNode) a.__addChild(() => {
|
|
1024
|
+
const value = Number(a.__getValue());
|
|
1025
|
+
const diff = value - lastInput;
|
|
1026
|
+
lastInput = value;
|
|
1027
|
+
this._current = Math.min(Math.max(this._current + diff, min), max);
|
|
1028
|
+
this._notify();
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
__getValue() {
|
|
1032
|
+
return this._current;
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1119
1035
|
function createAnimatedMock() {
|
|
1120
1036
|
return {
|
|
1121
1037
|
Value: AnimatedValue,
|
|
@@ -1280,37 +1196,15 @@ function createAnimatedMock() {
|
|
|
1280
1196
|
delay: vitest.vi.fn((_time) => {
|
|
1281
1197
|
return createAnimation();
|
|
1282
1198
|
}),
|
|
1283
|
-
add: vitest.vi.fn((a, b) =>
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
divide: vitest.vi.fn((a, b) => {
|
|
1293
|
-
const aVal = a instanceof AnimatedValue ? a.getValue() : typeof a === "number" ? a : 0;
|
|
1294
|
-
const bVal = b instanceof AnimatedValue ? b.getValue() : typeof b === "number" ? b : 0;
|
|
1295
|
-
return new AnimatedValue(bVal === 0 ? 0 : aVal / bVal);
|
|
1296
|
-
}),
|
|
1297
|
-
modulo: vitest.vi.fn((a, modulus) => {
|
|
1298
|
-
return new AnimatedValue(((a instanceof AnimatedValue ? a.getValue() : typeof a === "number" ? a : 0) % modulus + modulus) % modulus);
|
|
1299
|
-
}),
|
|
1300
|
-
diffClamp: vitest.vi.fn((a, min, max) => {
|
|
1301
|
-
const result = new AnimatedValue(Math.min(Math.max(a instanceof AnimatedValue ? a.getValue() : 0, min), max));
|
|
1302
|
-
if (a instanceof AnimatedValue) {
|
|
1303
|
-
let lastInput = a.getValue();
|
|
1304
|
-
let current = result.getValue();
|
|
1305
|
-
a.addListener(({ value }) => {
|
|
1306
|
-
const diff = value - lastInput;
|
|
1307
|
-
lastInput = value;
|
|
1308
|
-
current = Math.min(Math.max(current + diff, min), max);
|
|
1309
|
-
result.setValue(current);
|
|
1310
|
-
});
|
|
1311
|
-
}
|
|
1312
|
-
return result;
|
|
1313
|
-
}),
|
|
1199
|
+
add: vitest.vi.fn((a, b) => new AnimatedOp([a, b], () => operandValue(a) + operandValue(b))),
|
|
1200
|
+
subtract: vitest.vi.fn((a, b) => new AnimatedOp([a, b], () => operandValue(a) - operandValue(b))),
|
|
1201
|
+
multiply: vitest.vi.fn((a, b) => new AnimatedOp([a, b], () => operandValue(a) * operandValue(b))),
|
|
1202
|
+
divide: vitest.vi.fn((a, b) => new AnimatedOp([a, b], () => {
|
|
1203
|
+
const divisor = operandValue(b);
|
|
1204
|
+
return divisor === 0 ? 0 : operandValue(a) / divisor;
|
|
1205
|
+
})),
|
|
1206
|
+
modulo: vitest.vi.fn((a, modulus) => new AnimatedOp([a], () => (operandValue(a) % modulus + modulus) % modulus)),
|
|
1207
|
+
diffClamp: vitest.vi.fn((a, min, max) => new AnimatedDiffClamp(a, min, max)),
|
|
1314
1208
|
event: vitest.vi.fn((argMapping, config) => {
|
|
1315
1209
|
const handler = vitest.vi.fn((...args) => {
|
|
1316
1210
|
argMapping.forEach((mapping, index) => {
|
|
@@ -1339,6 +1233,15 @@ function createAnimatedMock() {
|
|
|
1339
1233
|
unforkEvent: vitest.vi.fn(),
|
|
1340
1234
|
createAnimatedComponent: vitest.vi.fn((component) => {
|
|
1341
1235
|
const Wrapper = react.default.forwardRef((props, ref) => {
|
|
1236
|
+
useAnimatedStyleSubscription(props?.style);
|
|
1237
|
+
if (props && props.style !== void 0) {
|
|
1238
|
+
const { style, ...rest } = props;
|
|
1239
|
+
return react.default.createElement(component, {
|
|
1240
|
+
...rest,
|
|
1241
|
+
style: resolveAnimatedStyle(style),
|
|
1242
|
+
ref
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1342
1245
|
return react.default.createElement(component, {
|
|
1343
1246
|
...props,
|
|
1344
1247
|
ref
|
|
@@ -2240,7 +2143,6 @@ function createProcessColorMock() {
|
|
|
2240
2143
|
return (Math.round(parseFloat(a) * 255) << 24) + (r << 16) + (g << 8) + b >>> 0;
|
|
2241
2144
|
}
|
|
2242
2145
|
}
|
|
2243
|
-
return 4278190080;
|
|
2244
2146
|
});
|
|
2245
2147
|
}
|
|
2246
2148
|
function createFindNodeHandleMock() {
|
|
@@ -2310,33 +2212,39 @@ function createTouchableMock() {
|
|
|
2310
2212
|
}
|
|
2311
2213
|
function createUseAnimatedValueMock() {
|
|
2312
2214
|
return vitest.vi.fn((initialValue) => {
|
|
2313
|
-
|
|
2215
|
+
const ref = react.default.useRef(null);
|
|
2216
|
+
if (ref.current == null) ref.current = new AnimatedValue(initialValue);
|
|
2217
|
+
return ref.current;
|
|
2314
2218
|
});
|
|
2315
2219
|
}
|
|
2316
2220
|
function createUseAnimatedValueXYMock() {
|
|
2317
2221
|
return vitest.vi.fn((initialValue) => {
|
|
2318
|
-
|
|
2222
|
+
const ref = react.default.useRef(null);
|
|
2223
|
+
if (ref.current == null) ref.current = new AnimatedValueXY(initialValue);
|
|
2224
|
+
return ref.current;
|
|
2319
2225
|
});
|
|
2320
2226
|
}
|
|
2321
2227
|
function createUseAnimatedColorMock() {
|
|
2322
2228
|
return vitest.vi.fn((initialValue) => {
|
|
2323
|
-
|
|
2229
|
+
const ref = react.default.useRef(null);
|
|
2230
|
+
if (ref.current == null) ref.current = new AnimatedColor(initialValue);
|
|
2231
|
+
return ref.current;
|
|
2324
2232
|
});
|
|
2325
2233
|
}
|
|
2326
2234
|
function buildReactNativeMock(platform = "ios") {
|
|
2327
2235
|
const mock = {
|
|
2328
|
-
View: createViewMock(),
|
|
2236
|
+
View: require_presets.createViewMock(),
|
|
2329
2237
|
Text: createTextMock(),
|
|
2330
2238
|
Image: createImageMock(),
|
|
2331
|
-
TextInput: createTextInputMock(),
|
|
2332
|
-
ScrollView: createScrollViewMock(),
|
|
2333
|
-
FlatList: createFlatListMock(),
|
|
2334
|
-
SectionList: createSectionListMock(),
|
|
2239
|
+
TextInput: require_presets.createTextInputMock(),
|
|
2240
|
+
ScrollView: require_presets.createScrollViewMock(),
|
|
2241
|
+
FlatList: require_presets.createFlatListMock(),
|
|
2242
|
+
SectionList: require_presets.createSectionListMock(),
|
|
2335
2243
|
Modal: createModalMock(),
|
|
2336
2244
|
Pressable: require_presets.createPressableMock(),
|
|
2337
|
-
TouchableOpacity: createTouchableOpacityMock(),
|
|
2338
|
-
TouchableHighlight: createTouchableHighlightMock(),
|
|
2339
|
-
TouchableWithoutFeedback: createTouchableWithoutFeedbackMock(),
|
|
2245
|
+
TouchableOpacity: require_presets.createTouchableOpacityMock(),
|
|
2246
|
+
TouchableHighlight: require_presets.createTouchableHighlightMock(),
|
|
2247
|
+
TouchableWithoutFeedback: require_presets.createTouchableWithoutFeedbackMock(),
|
|
2340
2248
|
TouchableNativeFeedback: createTouchableNativeFeedbackMock(),
|
|
2341
2249
|
ActivityIndicator: createActivityIndicatorMock(),
|
|
2342
2250
|
Button: createButtonMock(),
|
|
@@ -2346,7 +2254,7 @@ function buildReactNativeMock(platform = "ios") {
|
|
|
2346
2254
|
SafeAreaView: createSafeAreaViewMock(),
|
|
2347
2255
|
KeyboardAvoidingView: createKeyboardAvoidingViewMock(),
|
|
2348
2256
|
ImageBackground: createImageBackgroundMock(),
|
|
2349
|
-
VirtualizedList: createVirtualizedListMock(),
|
|
2257
|
+
VirtualizedList: require_presets.createVirtualizedListMock(),
|
|
2350
2258
|
InputAccessoryView: createInputAccessoryViewMock(),
|
|
2351
2259
|
DrawerLayoutAndroid: createDrawerLayoutAndroidMock(),
|
|
2352
2260
|
Platform: createPlatformMock(platform),
|
|
@@ -2488,7 +2396,54 @@ function buildReactNativeMock(platform = "ios") {
|
|
|
2488
2396
|
const VIRTUAL_RN_PATH = "\0vitest-native:react-native";
|
|
2489
2397
|
let originalResolveFilename = null;
|
|
2490
2398
|
let installed = false;
|
|
2399
|
+
let rnMock$1 = null;
|
|
2491
2400
|
const presetRedirects = /* @__PURE__ */ new Map();
|
|
2401
|
+
const presetMocks = /* @__PURE__ */ new Map();
|
|
2402
|
+
const leafModulePaths = /* @__PURE__ */ new Set();
|
|
2403
|
+
/**
|
|
2404
|
+
* The leaf module name a subpath require points at ("pkg/lib/Swipeable" or
|
|
2405
|
+
* ".../Platform.ios.js" → "Platform"). Mirrors native/match.mjs.
|
|
2406
|
+
*/
|
|
2407
|
+
function subpathLeafOf(request) {
|
|
2408
|
+
const base = request.split("/").pop();
|
|
2409
|
+
if (!base) return null;
|
|
2410
|
+
return base.split(".")[0] || null;
|
|
2411
|
+
}
|
|
2412
|
+
/**
|
|
2413
|
+
* Wrap a leaf export in Babel-CJS interop shape: the real compiled deep entry
|
|
2414
|
+
* exports `{ __esModule: true, default: X }`. A live Proxy keeps
|
|
2415
|
+
* direct-property consumers (`require('pkg/Sub').OS`) working too.
|
|
2416
|
+
*/
|
|
2417
|
+
function withDefaultInterop(value) {
|
|
2418
|
+
if (value === null || typeof value !== "object" && typeof value !== "function") return {
|
|
2419
|
+
__esModule: true,
|
|
2420
|
+
default: value
|
|
2421
|
+
};
|
|
2422
|
+
return new Proxy(value, {
|
|
2423
|
+
get: (t, p, r) => p === "default" ? t : p === "__esModule" ? true : Reflect.get(t, p, r),
|
|
2424
|
+
has: (t, p) => p === "default" || p === "__esModule" || Reflect.has(t, p)
|
|
2425
|
+
});
|
|
2426
|
+
}
|
|
2427
|
+
/**
|
|
2428
|
+
* Get or create a synthetic Module._cache entry for a subpath require whose
|
|
2429
|
+
* leaf name matches an export on the mock. Returns its virtual path, or null
|
|
2430
|
+
* when the leaf has no matching export (caller falls back to the root mock).
|
|
2431
|
+
*/
|
|
2432
|
+
function leafModulePath(Module, keyPrefix, mock, request) {
|
|
2433
|
+
const leaf = subpathLeafOf(request);
|
|
2434
|
+
if (!leaf || !Object.prototype.hasOwnProperty.call(mock, leaf)) return null;
|
|
2435
|
+
const virtualPath = `${keyPrefix}:${leaf}`;
|
|
2436
|
+
if (!Module._cache[virtualPath]) {
|
|
2437
|
+
const syntheticModule = new Module(virtualPath);
|
|
2438
|
+
syntheticModule.id = virtualPath;
|
|
2439
|
+
syntheticModule.filename = virtualPath;
|
|
2440
|
+
syntheticModule.loaded = true;
|
|
2441
|
+
syntheticModule.exports = withDefaultInterop(mock[leaf]);
|
|
2442
|
+
Module._cache[virtualPath] = syntheticModule;
|
|
2443
|
+
leafModulePaths.add(virtualPath);
|
|
2444
|
+
}
|
|
2445
|
+
return virtualPath;
|
|
2446
|
+
}
|
|
2492
2447
|
function installCjsBridge(mockObject) {
|
|
2493
2448
|
if (installed) return;
|
|
2494
2449
|
try {
|
|
@@ -2499,16 +2454,36 @@ function installCjsBridge(mockObject) {
|
|
|
2499
2454
|
syntheticModule.loaded = true;
|
|
2500
2455
|
syntheticModule.exports = mockObject;
|
|
2501
2456
|
Module._cache[VIRTUAL_RN_PATH] = syntheticModule;
|
|
2457
|
+
rnMock$1 = mockObject;
|
|
2502
2458
|
originalResolveFilename = Module._resolveFilename;
|
|
2503
2459
|
Module._resolveFilename = function(request, parent, isMain, options) {
|
|
2504
|
-
if (request === "react-native" || request.startsWith("react-native/"))
|
|
2460
|
+
if (request === "react-native" || request.startsWith("react-native/")) {
|
|
2461
|
+
if (request === "react-native/package.json") try {
|
|
2462
|
+
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
2463
|
+
} catch {}
|
|
2464
|
+
else if (request !== "react-native" && rnMock$1) {
|
|
2465
|
+
const leafPath = leafModulePath(Module, VIRTUAL_RN_PATH, rnMock$1, request);
|
|
2466
|
+
if (leafPath) return leafPath;
|
|
2467
|
+
}
|
|
2468
|
+
return VIRTUAL_RN_PATH;
|
|
2469
|
+
}
|
|
2505
2470
|
const exactMatch = presetRedirects.get(request);
|
|
2506
2471
|
if (exactMatch) return exactMatch;
|
|
2507
2472
|
const slashIdx = request.indexOf("/", request.startsWith("@") ? request.indexOf("/") + 1 : 0);
|
|
2508
2473
|
if (slashIdx !== -1) {
|
|
2509
2474
|
const pkg = request.slice(0, slashIdx);
|
|
2510
2475
|
const subpathMatch = presetRedirects.get(pkg);
|
|
2511
|
-
if (subpathMatch)
|
|
2476
|
+
if (subpathMatch) {
|
|
2477
|
+
if (request.endsWith(".json")) try {
|
|
2478
|
+
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
2479
|
+
} catch {}
|
|
2480
|
+
else {
|
|
2481
|
+
const mock = presetMocks.get(pkg);
|
|
2482
|
+
const leafPath = mock && leafModulePath(Module, subpathMatch, mock, request);
|
|
2483
|
+
if (leafPath) return leafPath;
|
|
2484
|
+
}
|
|
2485
|
+
return subpathMatch;
|
|
2486
|
+
}
|
|
2512
2487
|
}
|
|
2513
2488
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
2514
2489
|
};
|
|
@@ -2528,6 +2503,10 @@ function uninstallCjsBridge() {
|
|
|
2528
2503
|
delete Module._cache[VIRTUAL_RN_PATH];
|
|
2529
2504
|
for (const virtualPath of presetRedirects.values()) delete Module._cache[virtualPath];
|
|
2530
2505
|
presetRedirects.clear();
|
|
2506
|
+
presetMocks.clear();
|
|
2507
|
+
for (const virtualPath of leafModulePaths) delete Module._cache[virtualPath];
|
|
2508
|
+
leafModulePaths.clear();
|
|
2509
|
+
rnMock$1 = null;
|
|
2531
2510
|
installed = false;
|
|
2532
2511
|
} catch (e) {
|
|
2533
2512
|
if (process.env.VITEST_NATIVE_DIAGNOSTICS === "true") console.warn(`[vitest-native] CJS bridge uninstall failed: ${e?.message}`);
|
|
@@ -2544,6 +2523,7 @@ function installPresetCjsBridge(moduleName, mockObject) {
|
|
|
2544
2523
|
syntheticModule.exports = mockObject;
|
|
2545
2524
|
Module._cache[virtualPath] = syntheticModule;
|
|
2546
2525
|
presetRedirects.set(moduleName, virtualPath);
|
|
2526
|
+
presetMocks.set(moduleName, mockObject);
|
|
2547
2527
|
} catch (e) {
|
|
2548
2528
|
if (process.env.VITEST_NATIVE_DIAGNOSTICS === "true") console.warn(`[vitest-native] Preset CJS bridge for ${moduleName} failed: ${e?.message}`);
|
|
2549
2529
|
}
|