@rootnative/web 0.0.0-alpha.3 → 0.0.0-alpha.5
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 +31 -1
- package/dist/apis/AccessibilityInfo/index.d.ts +30 -0
- package/dist/apis/AccessibilityInfo/index.js +84 -0
- package/dist/apis/AccessibilityInfo/index.js.map +1 -0
- package/dist/apis/Alert/index.d.ts +22 -0
- package/dist/apis/Alert/index.js +141 -0
- package/dist/apis/Alert/index.js.map +1 -0
- package/dist/apis/AppState/index.d.ts +21 -0
- package/dist/apis/AppState/index.js +86 -0
- package/dist/apis/AppState/index.js.map +1 -0
- package/dist/apis/Appearance/index.d.ts +14 -0
- package/dist/apis/Appearance/index.js +39 -0
- package/dist/apis/Appearance/index.js.map +1 -0
- package/dist/apis/BackHandler/index.d.ts +10 -0
- package/dist/apis/BackHandler/index.js +16 -0
- package/dist/apis/BackHandler/index.js.map +1 -0
- package/dist/apis/Clipboard/index.d.ts +9 -0
- package/dist/apis/Clipboard/index.js +45 -0
- package/dist/apis/Clipboard/index.js.map +1 -0
- package/dist/apis/Dimensions/index.d.ts +19 -0
- package/dist/apis/Dimensions/index.js +66 -0
- package/dist/apis/Dimensions/index.js.map +1 -0
- package/dist/apis/I18nManager/index.d.ts +14 -0
- package/dist/apis/I18nManager/index.js +33 -0
- package/dist/apis/I18nManager/index.js.map +1 -0
- package/dist/apis/Keyboard/index.d.ts +36 -0
- package/dist/apis/Keyboard/index.js +149 -0
- package/dist/apis/Keyboard/index.js.map +1 -0
- package/dist/apis/Linking/index.d.ts +29 -0
- package/dist/apis/Linking/index.js +86 -0
- package/dist/apis/Linking/index.js.map +1 -0
- package/dist/apis/PanResponder/index.d.ts +50 -0
- package/dist/apis/PanResponder/index.js +239 -0
- package/dist/apis/PanResponder/index.js.map +1 -0
- package/dist/apis/PixelRatio/index.d.ts +8 -0
- package/dist/apis/PixelRatio/index.js +15 -0
- package/dist/apis/PixelRatio/index.js.map +1 -0
- package/dist/apis/Platform/index.d.ts +4 -0
- package/dist/apis/Platform/index.js +28 -0
- package/dist/apis/Platform/index.js.map +1 -0
- package/dist/apis/Platform/types.d.ts +19 -0
- package/dist/apis/Share/index.d.ts +30 -0
- package/dist/apis/Share/index.js +34 -0
- package/dist/apis/Share/index.js.map +1 -0
- package/dist/apis/StyleSheet/index.d.ts +23 -0
- package/dist/apis/StyleSheet/index.js +29 -0
- package/dist/apis/StyleSheet/index.js.map +1 -0
- package/dist/apis/StyleSheet/types.d.ts +328 -0
- package/dist/apis/Vibration/index.d.ts +9 -0
- package/dist/apis/Vibration/index.js +40 -0
- package/dist/apis/Vibration/index.js.map +1 -0
- package/dist/apis/processColor/index.d.ts +3 -0
- package/dist/apis/processColor/index.js +12 -0
- package/dist/apis/processColor/index.js.map +1 -0
- package/dist/apis/useColorScheme/index.d.ts +3 -0
- package/dist/apis/useColorScheme/index.js +13 -0
- package/dist/apis/useColorScheme/index.js.map +1 -0
- package/dist/apis/useWindowDimensions/index.d.ts +3 -0
- package/dist/apis/useWindowDimensions/index.js +19 -0
- package/dist/apis/useWindowDimensions/index.js.map +1 -0
- package/dist/bundler/index.js +30 -0
- package/dist/bundler/index.js.map +1 -0
- package/dist/bundler/inlinePlatformOS.js +121 -0
- package/dist/bundler/inlinePlatformOS.js.map +1 -0
- package/dist/bundler/worklets.js +61 -0
- package/dist/bundler/worklets.js.map +1 -0
- package/dist/compat/TurboModuleRegistry/index.d.ts +16 -0
- package/dist/compat/TurboModuleRegistry/index.js +14 -0
- package/dist/compat/TurboModuleRegistry/index.js.map +1 -0
- package/dist/compat/createElement/index.d.ts +9 -0
- package/dist/compat/createElement/index.js +40 -0
- package/dist/compat/createElement/index.js.map +1 -0
- package/dist/compat/findNodeHandle/index.d.ts +7 -0
- package/dist/compat/findNodeHandle/index.js +19 -0
- package/dist/compat/findNodeHandle/index.js.map +1 -0
- package/dist/components/ActivityIndicator/index.d.ts +5 -0
- package/dist/components/ActivityIndicator/index.js +74 -0
- package/dist/components/ActivityIndicator/index.js.map +1 -0
- package/dist/components/ActivityIndicator/types.d.ts +8 -0
- package/dist/components/Button/index.d.ts +5 -0
- package/dist/components/Button/index.js +48 -0
- package/dist/components/Button/index.js.map +1 -0
- package/dist/components/Button/types.d.ts +31 -0
- package/dist/components/FlatList/index.d.ts +5 -0
- package/dist/components/FlatList/index.js +433 -0
- package/dist/components/FlatList/index.js.map +1 -0
- package/dist/components/FlatList/types.d.ts +138 -0
- package/dist/components/FlatList/viewability.js +86 -0
- package/dist/components/FlatList/viewability.js.map +1 -0
- package/dist/components/Image/index.d.ts +7 -0
- package/dist/components/Image/index.js +301 -0
- package/dist/components/Image/index.js.map +1 -0
- package/dist/components/Image/source.js +97 -0
- package/dist/components/Image/source.js.map +1 -0
- package/dist/components/Image/types.d.ts +96 -0
- package/dist/components/KeyboardAvoidingView/index.d.ts +10 -0
- package/dist/components/KeyboardAvoidingView/index.js +118 -0
- package/dist/components/KeyboardAvoidingView/index.js.map +1 -0
- package/dist/components/KeyboardAvoidingView/types.d.ts +14 -0
- package/dist/components/Modal/index.d.ts +9 -0
- package/dist/components/Modal/index.js +271 -0
- package/dist/components/Modal/index.js.map +1 -0
- package/dist/components/Modal/types.d.ts +29 -0
- package/dist/components/Pressable/index.d.ts +5 -0
- package/dist/components/Pressable/index.js +106 -0
- package/dist/components/Pressable/index.js.map +1 -0
- package/dist/components/Pressable/types.d.ts +44 -0
- package/dist/components/RefreshControl/index.d.ts +5 -0
- package/dist/components/RefreshControl/index.js +176 -0
- package/dist/components/RefreshControl/index.js.map +1 -0
- package/dist/components/RefreshControl/pull.js +16 -0
- package/dist/components/RefreshControl/pull.js.map +1 -0
- package/dist/components/RefreshControl/types.d.ts +14 -0
- package/dist/components/ScrollView/index.d.ts +5 -0
- package/dist/components/ScrollView/index.js +318 -0
- package/dist/components/ScrollView/index.js.map +1 -0
- package/dist/components/ScrollView/snap.js +38 -0
- package/dist/components/ScrollView/snap.js.map +1 -0
- package/dist/components/ScrollView/types.d.ts +115 -0
- package/dist/components/StatusBar/index.d.ts +26 -0
- package/dist/components/StatusBar/index.js +113 -0
- package/dist/components/StatusBar/index.js.map +1 -0
- package/dist/components/Switch/index.d.ts +5 -0
- package/dist/components/Switch/index.js +89 -0
- package/dist/components/Switch/index.js.map +1 -0
- package/dist/components/Switch/types.d.ts +25 -0
- package/dist/components/Text/TextAncestorContext.d.ts +3 -0
- package/dist/components/Text/TextAncestorContext.js +6 -0
- package/dist/components/Text/TextAncestorContext.js.map +1 -0
- package/dist/components/Text/index.d.ts +6 -0
- package/dist/components/Text/index.js +133 -0
- package/dist/components/Text/index.js.map +1 -0
- package/dist/components/Text/types.d.ts +38 -0
- package/dist/components/TextInput/autocomplete.js +102 -0
- package/dist/components/TextInput/autocomplete.js.map +1 -0
- package/dist/components/TextInput/index.d.ts +8 -0
- package/dist/components/TextInput/index.js +290 -0
- package/dist/components/TextInput/index.js.map +1 -0
- package/dist/components/TextInput/types.d.ts +130 -0
- package/dist/components/TouchableHighlight/index.d.ts +5 -0
- package/dist/components/TouchableHighlight/index.js +109 -0
- package/dist/components/TouchableHighlight/index.js.map +1 -0
- package/dist/components/TouchableHighlight/types.d.ts +15 -0
- package/dist/components/TouchableNativeFeedback/index.d.ts +11 -0
- package/dist/components/TouchableNativeFeedback/index.js +29 -0
- package/dist/components/TouchableNativeFeedback/index.js.map +1 -0
- package/dist/components/TouchableNativeFeedback/types.d.ts +19 -0
- package/dist/components/TouchableOpacity/index.d.ts +5 -0
- package/dist/components/TouchableOpacity/index.js +122 -0
- package/dist/components/TouchableOpacity/index.js.map +1 -0
- package/dist/components/TouchableOpacity/types.d.ts +11 -0
- package/dist/components/TouchableWithoutFeedback/index.d.ts +5 -0
- package/dist/components/TouchableWithoutFeedback/index.js +70 -0
- package/dist/components/TouchableWithoutFeedback/index.js.map +1 -0
- package/dist/components/TouchableWithoutFeedback/types.d.ts +40 -0
- package/dist/components/View/index.d.ts +5 -0
- package/dist/components/View/index.js +50 -0
- package/dist/components/View/index.js.map +1 -0
- package/dist/components/View/types.d.ts +98 -0
- package/dist/dom/Head.d.ts +21 -0
- package/dist/dom/Head.js +53 -0
- package/dist/dom/Head.js.map +1 -0
- package/dist/dom/index.d.ts +2 -22
- package/dist/dom/index.js +1 -53
- package/dist/events/press/Pressability.d.ts +2 -0
- package/dist/events/press/Pressability.js +366 -0
- package/dist/events/press/Pressability.js.map +1 -0
- package/dist/events/press/cursorStyle.js +5 -0
- package/dist/events/press/cursorStyle.js.map +1 -0
- package/dist/events/press/index.d.ts +4 -0
- package/dist/events/press/mergeHandlers.js +30 -0
- package/dist/events/press/mergeHandlers.js.map +1 -0
- package/dist/events/press/types.d.ts +48 -0
- package/dist/events/press/usePressability.d.ts +4 -0
- package/dist/events/press/usePressability.js +18 -0
- package/dist/events/press/usePressability.js.map +1 -0
- package/dist/events/responderEvent.js +50 -0
- package/dist/events/responderEvent.js.map +1 -0
- package/dist/events/types.d.ts +33 -0
- package/dist/index.d.ts +66 -1597
- package/dist/index.js +42 -4864
- package/dist/reactNativeVersion.d.ts +7 -0
- package/dist/reactNativeVersion.js +10 -0
- package/dist/reactNativeVersion.js.map +1 -0
- package/dist/render/domProps.js +66 -0
- package/dist/render/domProps.js.map +1 -0
- package/dist/render/hitSlop.js +21 -0
- package/dist/render/hitSlop.js.map +1 -0
- package/dist/render/hostMethods.js +44 -0
- package/dist/render/hostMethods.js.map +1 -0
- package/dist/render/resolveTag.js +64 -0
- package/dist/render/resolveTag.js.map +1 -0
- package/dist/render/useElementLayout.js +25 -0
- package/dist/render/useElementLayout.js.map +1 -0
- package/dist/server/index.d.ts +2 -27
- package/dist/server/index.js +2 -2
- package/dist/{StyleRegistryContext-ROsMlY4O.js → style/StyleRegistryContext.js} +3 -3
- package/dist/style/StyleRegistryContext.js.map +1 -0
- package/dist/style/color.js +16 -0
- package/dist/style/color.js.map +1 -0
- package/dist/style/compile.js +102 -0
- package/dist/style/compile.js.map +1 -0
- package/dist/style/direction.js +33 -0
- package/dist/style/direction.js.map +1 -0
- package/dist/style/index.d.ts +1 -1
- package/dist/style/index.js +5 -2
- package/dist/style/index.js.map +1 -1
- package/dist/style/registry.d.ts +28 -0
- package/dist/{registry-Aa_Od5m0.js → style/registry.js} +6 -3
- package/dist/style/registry.js.map +1 -0
- package/dist/style/resolveStyle.js +181 -0
- package/dist/style/resolveStyle.js.map +1 -0
- package/dist/style/shadow.js +87 -0
- package/dist/style/shadow.js.map +1 -0
- package/dist/style/splitLayoutProps.js +52 -0
- package/dist/style/splitLayoutProps.js.map +1 -0
- package/dist/style/transform.js +35 -0
- package/dist/style/transform.js.map +1 -0
- package/dist/style/types.d.ts +4 -0
- package/dist/style/units.js +21 -0
- package/dist/style/units.js.map +1 -0
- package/dist/style/webStyle.js +9 -0
- package/dist/style/webStyle.js.map +1 -0
- package/dist/{env-DK5Mt9yX.js → utils/env.js} +2 -2
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/scrollLock.js +28 -0
- package/dist/utils/scrollLock.js.map +1 -0
- package/dist/utils/warn.js +11 -0
- package/dist/utils/warn.js.map +1 -0
- package/dist/vite/index.js +4 -202
- package/dist/vite/index.js.map +1 -1
- package/llms.txt +20 -0
- package/package.json +4 -3
- package/dist/StyleRegistryContext-ROsMlY4O.js.map +0 -1
- package/dist/compile-CVUjQrR9.js +0 -400
- package/dist/compile-CVUjQrR9.js.map +0 -1
- package/dist/dom/index.js.map +0 -1
- package/dist/env-DK5Mt9yX.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/registry-Aa_Od5m0.js.map +0 -1
- package/dist/types-BxTWbdj9.d.ts +0 -5
package/dist/vite/index.js
CHANGED
|
@@ -1,205 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const LINE_BREAK = /[\n\r\u2028\u2029]/;
|
|
6
|
-
const isNode = (value) => typeof value === "object" && value !== null && typeof value.type === "string";
|
|
7
|
-
const identifierName = (node) => isNode(node) && node.type === "Identifier" && typeof node.name === "string" ? node.name : void 0;
|
|
8
|
-
const nodes = (value) => Array.isArray(value) ? value.filter(isNode) : isNode(value) ? [value] : [];
|
|
9
|
-
const collectBindings = (pattern, names) => {
|
|
10
|
-
if (!isNode(pattern)) return;
|
|
11
|
-
switch (pattern.type) {
|
|
12
|
-
case "Identifier": {
|
|
13
|
-
const name = identifierName(pattern);
|
|
14
|
-
if (name !== void 0) names.add(name);
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
case "ObjectPattern":
|
|
18
|
-
for (const property of nodes(pattern.properties)) collectBindings(property.type === "RestElement" ? property.argument : property.value, names);
|
|
19
|
-
return;
|
|
20
|
-
case "ArrayPattern":
|
|
21
|
-
for (const element of nodes(pattern.elements)) collectBindings(element, names);
|
|
22
|
-
return;
|
|
23
|
-
case "RestElement":
|
|
24
|
-
collectBindings(pattern.argument, names);
|
|
25
|
-
return;
|
|
26
|
-
case "AssignmentPattern": collectBindings(pattern.left, names);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
const isWriteTarget = (parent, key, grandparent) => {
|
|
30
|
-
switch (parent.type) {
|
|
31
|
-
case "AssignmentExpression":
|
|
32
|
-
case "AssignmentPattern":
|
|
33
|
-
case "ForInStatement":
|
|
34
|
-
case "ForOfStatement": return key === "left";
|
|
35
|
-
case "UpdateExpression":
|
|
36
|
-
case "ArrayPattern":
|
|
37
|
-
case "RestElement": return true;
|
|
38
|
-
case "UnaryExpression": return parent.operator === "delete";
|
|
39
|
-
case "Property": return key === "value" && grandparent?.type === "ObjectPattern";
|
|
40
|
-
default: return false;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
const platformRead = (node) => {
|
|
44
|
-
if (node.computed === true || identifierName(node.property) !== "OS") return void 0;
|
|
45
|
-
const name = identifierName(node.object);
|
|
46
|
-
if (name !== void 0) return {
|
|
47
|
-
name,
|
|
48
|
-
namespace: false
|
|
49
|
-
};
|
|
50
|
-
const object = node.object;
|
|
51
|
-
if (isNode(object) && object.type === "MemberExpression" && object.computed !== true && identifierName(object.property) === "Platform") {
|
|
52
|
-
const namespace = identifierName(object.object);
|
|
53
|
-
if (namespace !== void 0) return {
|
|
54
|
-
name: namespace,
|
|
55
|
-
namespace: true
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Replaces each read of `Platform.OS` with `"web"`, so a minifier can drop the branches of the
|
|
61
|
-
* other platforms. Only a `Platform` imported from `react-native` or `@rootnative/web` counts.
|
|
62
|
-
* Takes the ESTree program of `code`, with `start` and `end` offsets. Returns `null` when
|
|
63
|
-
* nothing changes.
|
|
64
|
-
*/
|
|
65
|
-
const inlinePlatformOS = (code, program) => {
|
|
66
|
-
if (!isNode(program)) return null;
|
|
67
|
-
const named = /* @__PURE__ */ new Set();
|
|
68
|
-
const namespaces = /* @__PURE__ */ new Set();
|
|
69
|
-
const declared = /* @__PURE__ */ new Set();
|
|
70
|
-
const reads = [];
|
|
71
|
-
const visit = (node, parent, key, grandparent) => {
|
|
72
|
-
switch (node.type) {
|
|
73
|
-
case "ImportDeclaration": {
|
|
74
|
-
const source = isNode(node.source) ? node.source.value : void 0;
|
|
75
|
-
if (typeof source !== "string" || !SOURCES.has(source)) break;
|
|
76
|
-
for (const specifier of nodes(node.specifiers)) {
|
|
77
|
-
const local = identifierName(specifier.local);
|
|
78
|
-
if (local === void 0) continue;
|
|
79
|
-
if (specifier.type === "ImportNamespaceSpecifier") namespaces.add(local);
|
|
80
|
-
const imported = isNode(specifier.imported) ? identifierName(specifier.imported) ?? specifier.imported.value : void 0;
|
|
81
|
-
if (specifier.type === "ImportSpecifier" && imported === "Platform") named.add(local);
|
|
82
|
-
}
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
case "VariableDeclarator":
|
|
86
|
-
collectBindings(node.id, declared);
|
|
87
|
-
break;
|
|
88
|
-
case "FunctionDeclaration":
|
|
89
|
-
case "FunctionExpression":
|
|
90
|
-
case "ArrowFunctionExpression":
|
|
91
|
-
collectBindings(node.id, declared);
|
|
92
|
-
for (const param of nodes(node.params)) collectBindings(param, declared);
|
|
93
|
-
break;
|
|
94
|
-
case "ClassDeclaration":
|
|
95
|
-
case "ClassExpression":
|
|
96
|
-
collectBindings(node.id, declared);
|
|
97
|
-
break;
|
|
98
|
-
case "CatchClause":
|
|
99
|
-
collectBindings(node.param, declared);
|
|
100
|
-
break;
|
|
101
|
-
case "MemberExpression": {
|
|
102
|
-
const read = platformRead(node);
|
|
103
|
-
if (read !== void 0 && (parent === void 0 || !isWriteTarget(parent, key, grandparent))) reads.push({
|
|
104
|
-
...read,
|
|
105
|
-
start: node.start,
|
|
106
|
-
end: node.end
|
|
107
|
-
});
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
for (const childKey of Object.keys(node)) for (const child of nodes(node[childKey])) visit(child, node, childKey, parent);
|
|
112
|
-
};
|
|
113
|
-
visit(program, void 0, "", void 0);
|
|
114
|
-
const edits = reads.filter((read) => (read.namespace ? namespaces : named).has(read.name) && !declared.has(read.name) && read.end - read.start >= 5 && !LINE_BREAK.test(code.slice(read.start, read.end)));
|
|
115
|
-
if (edits.length === 0) return null;
|
|
116
|
-
let output = code;
|
|
117
|
-
for (const { start, end } of edits) output = output.slice(0, start) + REPLACEMENT.padEnd(end - start) + output.slice(end);
|
|
118
|
-
return output;
|
|
119
|
-
};
|
|
120
|
-
// src/bundler/worklets.ts
|
|
121
|
-
/**
|
|
122
|
-
* The source of a file that can hold a worklet: a `'worklet'` directive, an import of
|
|
123
|
-
* Reanimated or Worklets, or a call that the Worklets Babel plugin turns into a worklet.
|
|
124
|
-
*/
|
|
125
|
-
const WORKLET_CODE = /worklet|reanimated|useAnimated|useDerivedValue|useFrameCallback|runOnUI|scheduleOnUI|with(?:Timing|Spring|Decay|Repeat)\b/;
|
|
126
|
-
const SCRIPT_FILE = /\.[cm]?[jt]sx?$/;
|
|
127
|
-
const missing = (name) => /* @__PURE__ */ new Error(`[@rootnative/web] The \`worklets\` option needs \`${name}\`, and the app doesn't have it. Install it, or remove the option.`);
|
|
128
|
-
const loadTools = async (root) => {
|
|
129
|
-
const { createRequire } = await import("node:module");
|
|
130
|
-
const { resolve } = await import("node:path");
|
|
131
|
-
const fromRoot = createRequire(resolve(root, "package.json"));
|
|
132
|
-
let plugin;
|
|
133
|
-
let workletsManifest;
|
|
134
|
-
try {
|
|
135
|
-
plugin = fromRoot.resolve("react-native-worklets/plugin");
|
|
136
|
-
workletsManifest = fromRoot.resolve("react-native-worklets/package.json");
|
|
137
|
-
} catch {
|
|
138
|
-
throw missing("react-native-worklets");
|
|
139
|
-
}
|
|
140
|
-
for (const load of [fromRoot, createRequire(workletsManifest)]) try {
|
|
141
|
-
return {
|
|
142
|
-
babel: load("@babel/core"),
|
|
143
|
-
plugin
|
|
144
|
-
};
|
|
145
|
-
} catch {}
|
|
146
|
-
throw missing("@babel/core");
|
|
147
|
-
};
|
|
148
|
-
/**
|
|
149
|
-
* Makes the transform that runs the Worklets Babel plugin on one file, as the Babel preset of a
|
|
150
|
-
* React Native app does. It finds the plugin and Babel from the root of the app, on the first
|
|
151
|
-
* file that needs them.
|
|
152
|
-
*/
|
|
153
|
-
const createWorkletTransform = (root) => {
|
|
154
|
-
let tools;
|
|
155
|
-
return async (code, id) => {
|
|
156
|
-
const file = id.split("?")[0];
|
|
157
|
-
if (file.startsWith("\0") || !SCRIPT_FILE.test(file) || !WORKLET_CODE.test(code)) return null;
|
|
158
|
-
tools ??= loadTools(root);
|
|
159
|
-
const { babel, plugin } = await tools;
|
|
160
|
-
const syntax = [];
|
|
161
|
-
if (/\.[cm]?tsx?$/.test(file)) syntax.push("typescript");
|
|
162
|
-
if (/\.[jt]sx$/.test(file)) syntax.push("jsx");
|
|
163
|
-
const result = await babel.transformAsync(code, {
|
|
164
|
-
filename: file,
|
|
165
|
-
babelrc: false,
|
|
166
|
-
configFile: false,
|
|
167
|
-
sourceMaps: true,
|
|
168
|
-
parserOpts: { plugins: syntax },
|
|
169
|
-
plugins: [plugin]
|
|
170
|
-
});
|
|
171
|
-
if (result?.code == null) return null;
|
|
172
|
-
return {
|
|
173
|
-
code: result.code,
|
|
174
|
-
map: result.map == null ? null : JSON.stringify(result.map)
|
|
175
|
-
};
|
|
176
|
-
};
|
|
177
|
-
};
|
|
178
|
-
// src/bundler/index.ts
|
|
179
|
-
/** Module names that resolve to this package. Each one matches the exact name only. */
|
|
180
|
-
const ALIASES = {
|
|
181
|
-
"react-native": "@rootnative/web",
|
|
182
|
-
"@react-native/assets-registry/registry": "@rootnative/web/assets-registry",
|
|
183
|
-
"react-native-web/dist/cjs/exports/StyleSheet/compiler/createReactDOMStyle.js": "@rootnative/web/style",
|
|
184
|
-
"react-native-web/dist/cjs/exports/StyleSheet/preprocess.js": "@rootnative/web/style"
|
|
185
|
-
};
|
|
186
|
-
/**
|
|
187
|
-
* The globals that React Native code expects from its bundler, each as the code that replaces
|
|
188
|
-
* the name. `__DEV__` is `true` in a development build and `false` in a production build.
|
|
189
|
-
* `global` is React Native's name for the global object, which a browser doesn't have.
|
|
190
|
-
*/
|
|
191
|
-
const globalDefines = (production) => ({
|
|
192
|
-
__DEV__: JSON.stringify(!production),
|
|
193
|
-
global: "globalThis"
|
|
194
|
-
});
|
|
195
|
-
/**
|
|
196
|
-
* Puts a `.web` variant of each extension first, as Metro does for the web platform. An
|
|
197
|
-
* import of `./Button` then finds `Button.web.tsx` before `Button.tsx`.
|
|
198
|
-
*/
|
|
199
|
-
const webExtensions = (extensions) => {
|
|
200
|
-
const web = extensions.map((extension) => extension.startsWith(".web.") ? extension : `.web${extension}`);
|
|
201
|
-
return [.../* @__PURE__ */ new Set([...web, ...extensions])];
|
|
202
|
-
};
|
|
1
|
+
import { ALIASES, globalDefines, webExtensions } from "../bundler/index.js";
|
|
2
|
+
import { inlinePlatformOS } from "../bundler/inlinePlatformOS.js";
|
|
3
|
+
import { WORKLET_CODE, createWorkletTransform } from "../bundler/worklets.js";
|
|
4
|
+
import { isProductionEnv } from "../utils/env.js";
|
|
203
5
|
// src/vite/index.ts
|
|
204
6
|
const VITE_DEFAULT_EXTENSIONS = [
|
|
205
7
|
".mjs",
|
package/dist/vite/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/bundler/inlinePlatformOS.ts","../../src/bundler/worklets.ts","../../src/bundler/index.ts","../../src/vite/index.ts"],"sourcesContent":["interface AstNode {\n type: string\n start: number\n end: number\n [key: string]: unknown\n}\n\ninterface PlatformRead {\n start: number\n end: number\n name: string\n namespace: boolean\n}\n\nconst SOURCES = new Set(['react-native', '@rootnative/web'])\nconst REPLACEMENT = '\"web\"'\nconst LINE_BREAK = /[\\n\\r\\u2028\\u2029]/\n\nconst isNode = (value: unknown): value is AstNode =>\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { type?: unknown }).type === 'string'\n\nconst identifierName = (node: unknown): string | undefined =>\n isNode(node) && node.type === 'Identifier' && typeof node.name === 'string'\n ? node.name\n : undefined\n\nconst nodes = (value: unknown): AstNode[] =>\n Array.isArray(value) ? value.filter(isNode) : isNode(value) ? [value] : []\n\nconst collectBindings = (pattern: unknown, names: Set<string>): void => {\n if (!isNode(pattern)) return\n switch (pattern.type) {\n case 'Identifier': {\n const name = identifierName(pattern)\n if (name !== undefined) names.add(name)\n return\n }\n case 'ObjectPattern':\n for (const property of nodes(pattern.properties)) {\n collectBindings(property.type === 'RestElement' ? property.argument : property.value, names)\n }\n return\n case 'ArrayPattern':\n for (const element of nodes(pattern.elements)) collectBindings(element, names)\n return\n case 'RestElement':\n collectBindings(pattern.argument, names)\n return\n case 'AssignmentPattern':\n collectBindings(pattern.left, names)\n }\n}\n\nconst isWriteTarget = (parent: AstNode, key: string, grandparent: AstNode | undefined): boolean => {\n switch (parent.type) {\n case 'AssignmentExpression':\n case 'AssignmentPattern':\n case 'ForInStatement':\n case 'ForOfStatement':\n return key === 'left'\n case 'UpdateExpression':\n case 'ArrayPattern':\n case 'RestElement':\n return true\n case 'UnaryExpression':\n return parent.operator === 'delete'\n case 'Property':\n return key === 'value' && grandparent?.type === 'ObjectPattern'\n default:\n return false\n }\n}\n\nconst platformRead = (node: AstNode): Omit<PlatformRead, 'start' | 'end'> | undefined => {\n if (node.computed === true || identifierName(node.property) !== 'OS') return undefined\n const name = identifierName(node.object)\n if (name !== undefined) return { name, namespace: false }\n const object = node.object\n if (\n isNode(object) &&\n object.type === 'MemberExpression' &&\n object.computed !== true &&\n identifierName(object.property) === 'Platform'\n ) {\n const namespace = identifierName(object.object)\n if (namespace !== undefined) return { name: namespace, namespace: true }\n }\n return undefined\n}\n\n/**\n * Replaces each read of `Platform.OS` with `\"web\"`, so a minifier can drop the branches of the\n * other platforms. Only a `Platform` imported from `react-native` or `@rootnative/web` counts.\n * Takes the ESTree program of `code`, with `start` and `end` offsets. Returns `null` when\n * nothing changes.\n */\nexport const inlinePlatformOS = (code: string, program: object): string | null => {\n if (!isNode(program)) return null\n\n const named = new Set<string>()\n const namespaces = new Set<string>()\n const declared = new Set<string>()\n const reads: PlatformRead[] = []\n\n const visit = (\n node: AstNode,\n parent: AstNode | undefined,\n key: string,\n grandparent: AstNode | undefined,\n ): void => {\n switch (node.type) {\n case 'ImportDeclaration': {\n const source = isNode(node.source) ? node.source.value : undefined\n if (typeof source !== 'string' || !SOURCES.has(source)) break\n for (const specifier of nodes(node.specifiers)) {\n const local = identifierName(specifier.local)\n if (local === undefined) continue\n if (specifier.type === 'ImportNamespaceSpecifier') namespaces.add(local)\n const imported = isNode(specifier.imported)\n ? (identifierName(specifier.imported) ?? specifier.imported.value)\n : undefined\n if (specifier.type === 'ImportSpecifier' && imported === 'Platform') named.add(local)\n }\n break\n }\n case 'VariableDeclarator':\n collectBindings(node.id, declared)\n break\n case 'FunctionDeclaration':\n case 'FunctionExpression':\n case 'ArrowFunctionExpression':\n collectBindings(node.id, declared)\n for (const param of nodes(node.params)) collectBindings(param, declared)\n break\n case 'ClassDeclaration':\n case 'ClassExpression':\n collectBindings(node.id, declared)\n break\n case 'CatchClause':\n collectBindings(node.param, declared)\n break\n case 'MemberExpression': {\n const read = platformRead(node)\n if (\n read !== undefined &&\n (parent === undefined || !isWriteTarget(parent, key, grandparent))\n ) {\n reads.push({ ...read, start: node.start, end: node.end })\n }\n break\n }\n }\n for (const childKey of Object.keys(node)) {\n for (const child of nodes(node[childKey])) visit(child, node, childKey, parent)\n }\n }\n visit(program, undefined, '', undefined)\n\n // A local binding with the same name may shadow the import in some scope. Without scope\n // analysis, skip that name in the whole module.\n const edits = reads.filter(\n (read) =>\n (read.namespace ? namespaces : named).has(read.name) &&\n !declared.has(read.name) &&\n // The replacement keeps the length and the lines of the original, so every later column\n // stays put and the source map stays exact. A shorter or a multi-line read keeps its code.\n read.end - read.start >= REPLACEMENT.length &&\n !LINE_BREAK.test(code.slice(read.start, read.end)),\n )\n if (edits.length === 0) return null\n\n // Each edit keeps its length, so the offsets of the others stay valid in any order.\n let output = code\n for (const { start, end } of edits) {\n output = output.slice(0, start) + REPLACEMENT.padEnd(end - start) + output.slice(end)\n }\n return output\n}\n","/**\n * The source of a file that can hold a worklet: a `'worklet'` directive, an import of\n * Reanimated or Worklets, or a call that the Worklets Babel plugin turns into a worklet.\n */\nexport const WORKLET_CODE: RegExp =\n /worklet|reanimated|useAnimated|useDerivedValue|useFrameCallback|runOnUI|scheduleOnUI|with(?:Timing|Spring|Decay|Repeat)\\b/\n\nconst SCRIPT_FILE = /\\.[cm]?[jt]sx?$/\n\n// The map is JSON text, which every bundler takes.\nexport type WorkletTransformResult = { code: string; map: string | null }\n\nexport type WorkletTransform = (code: string, id: string) => Promise<WorkletTransformResult | null>\n\ntype BabelCore = {\n transformAsync: (\n code: string,\n options: Record<string, unknown>,\n ) => Promise<{ code?: string | null; map?: object | null } | null>\n}\n\ntype Require = ((id: string) => unknown) & { resolve: (id: string) => string }\n\ntype Tools = { babel: BabelCore; plugin: string }\n\nconst missing = (name: string): Error =>\n new Error(\n `[@rootnative/web] The \\`worklets\\` option needs \\`${name}\\`, and the app doesn't have it. ` +\n `Install it, or remove the option.`,\n )\n\nconst loadTools = async (root: string): Promise<Tools> => {\n // Only Node runs this file. A dynamic import keeps the browser entries free of it.\n const { createRequire } = await import('node:module')\n const { resolve } = await import('node:path')\n const fromRoot = createRequire(resolve(root, 'package.json')) as Require\n\n let plugin: string\n let workletsManifest: string\n try {\n plugin = fromRoot.resolve('react-native-worklets/plugin')\n workletsManifest = fromRoot.resolve('react-native-worklets/package.json')\n } catch {\n throw missing('react-native-worklets')\n }\n\n // Babel is a peer of Worklets. A strict package layout links it beside Worklets, not in the app.\n for (const load of [fromRoot, createRequire(workletsManifest) as Require]) {\n try {\n return { babel: load('@babel/core') as BabelCore, plugin }\n } catch {\n // Try the next place.\n }\n }\n throw missing('@babel/core')\n}\n\n/**\n * Makes the transform that runs the Worklets Babel plugin on one file, as the Babel preset of a\n * React Native app does. It finds the plugin and Babel from the root of the app, on the first\n * file that needs them.\n */\nexport const createWorkletTransform = (root: string): WorkletTransform => {\n let tools: Promise<Tools> | undefined\n\n return async (code, id) => {\n const file = id.split('?')[0] as string\n if (file.startsWith('\\0') || !SCRIPT_FILE.test(file) || !WORKLET_CODE.test(code)) return null\n\n tools ??= loadTools(root)\n const { babel, plugin } = await tools\n\n // A library can ship TypeScript or JSX source. Babel reads the syntax and keeps it.\n const syntax: string[] = []\n if (/\\.[cm]?tsx?$/.test(file)) syntax.push('typescript')\n if (/\\.[jt]sx$/.test(file)) syntax.push('jsx')\n\n const result = await babel.transformAsync(code, {\n filename: file,\n babelrc: false,\n configFile: false,\n sourceMaps: true,\n parserOpts: { plugins: syntax },\n plugins: [plugin],\n })\n if (result?.code == null) return null\n return { code: result.code, map: result.map == null ? null : JSON.stringify(result.map) }\n }\n}\n","export { inlinePlatformOS } from './inlinePlatformOS'\nexport {\n createWorkletTransform,\n WORKLET_CODE,\n type WorkletTransform,\n type WorkletTransformResult,\n} from './worklets'\n\n/** Module names that resolve to this package. Each one matches the exact name only. */\nexport const ALIASES: Readonly<Record<string, string>> = {\n 'react-native': '@rootnative/web',\n // Libraries import it on the web, and the real module is Flow source that no web bundler reads.\n '@react-native/assets-registry/registry': '@rootnative/web/assets-registry',\n // Reanimated 4 reads its web style helpers from these react-native-web internal files.\n 'react-native-web/dist/cjs/exports/StyleSheet/compiler/createReactDOMStyle.js':\n '@rootnative/web/style',\n 'react-native-web/dist/cjs/exports/StyleSheet/preprocess.js': '@rootnative/web/style',\n}\n\n/**\n * The globals that React Native code expects from its bundler, each as the code that replaces\n * the name. `__DEV__` is `true` in a development build and `false` in a production build.\n * `global` is React Native's name for the global object, which a browser doesn't have.\n */\nexport const globalDefines = (production: boolean): Record<string, string> => ({\n __DEV__: JSON.stringify(!production),\n global: 'globalThis',\n})\n\n/**\n * Puts a `.web` variant of each extension first, as Metro does for the web platform. An\n * import of `./Button` then finds `Button.web.tsx` before `Button.tsx`.\n */\nexport const webExtensions = (extensions: readonly string[]): string[] => {\n const web = extensions.map((extension) =>\n extension.startsWith('.web.') ? extension : `.web${extension}`,\n )\n return [...new Set([...web, ...extensions])]\n}\n","import type { Alias, AliasOptions, Plugin } from 'vite'\n\nimport {\n ALIASES,\n createWorkletTransform,\n globalDefines,\n inlinePlatformOS,\n WORKLET_CODE,\n webExtensions,\n type WorkletTransform,\n} from '../bundler'\nimport { isProductionEnv } from '../utils/env'\n\n// Vite's default `resolve.extensions`. A config that sets the option replaces this list, so the\n// plugin starts from the same one.\nconst VITE_DEFAULT_EXTENSIONS = ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json']\n\nconst SCRIPT_ID = /\\.[cm]?[jt]sx?(?:$|\\?)/\n\nconst escapeRegExp = (value: string): string => value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n\nconst isAliasArray = (alias: AliasOptions): alias is readonly Alias[] => Array.isArray(alias)\n\nconst aliasArray = (alias: AliasOptions | undefined): Alias[] => {\n if (alias === undefined) return []\n if (isAliasArray(alias)) return [...alias]\n return Object.entries(alias).map(([find, replacement]) => ({ find, replacement }))\n}\n\nconst defineCode = (value: unknown): string =>\n typeof value === 'string' ? value : JSON.stringify(value)\n\nconst PLATFORM_CODE = /\\bPlatform\\b/\n\nexport type RootnativeOptions = {\n /**\n * Runs the Babel plugin of `react-native-worklets` on your code and on the libraries that\n * have worklets. Reanimated needs it, and so does a library built on Reanimated. The app\n * must have `react-native-worklets` and `@babel/core`. Default: `false`.\n */\n worklets?: boolean | undefined\n}\n\n/**\n * The Vite plugin. It points `react-native` at `@rootnative/web`, resolves `.web.*` files\n * first, defines `__DEV__`, and replaces `Platform.OS` with `'web'`.\n */\nexport const rootnative = (options: RootnativeOptions = {}): Plugin => {\n let workletize: WorkletTransform | undefined\n\n return {\n name: '@rootnative/web',\n\n // Edits the config in place, so the app's own values win. A returned partial config would\n // append the lists after the app's entries and override its defines.\n config(config) {\n if (options.worklets === true) {\n const transform = createWorkletTransform(config.root ?? process.cwd())\n workletize = transform\n // The dev server pre-bundles the libraries, and a `transform` hook of a Vite plugin\n // never sees their files. The optimizer takes its own plugin.\n config.optimizeDeps ??= {}\n config.optimizeDeps.rolldownOptions ??= {}\n const rolldownOptions = config.optimizeDeps.rolldownOptions\n rolldownOptions.plugins = [\n rolldownOptions.plugins,\n {\n name: '@rootnative/web:worklets',\n transform: { filter: { id: SCRIPT_ID, code: WORKLET_CODE }, handler: transform },\n },\n ] as typeof rolldownOptions.plugins\n }\n\n config.resolve ??= {}\n // Last, so an alias in the app's config wins. The first matching alias resolves an import.\n config.resolve.alias = [\n ...aliasArray(config.resolve.alias),\n ...Object.entries(ALIASES).map(([name, replacement]) => ({\n find: new RegExp(`^${escapeRegExp(name)}$`),\n replacement,\n })),\n ]\n const extensions = webExtensions(config.resolve.extensions ?? VITE_DEFAULT_EXTENSIONS)\n config.resolve.extensions = extensions\n\n // Vite has set NODE_ENV before this hook runs, so `__DEV__` follows React's development mode.\n const defines = Object.fromEntries(\n Object.entries(globalDefines(isProductionEnv())).map(([name, code]) => [\n name,\n config.define?.[name] === undefined ? code : defineCode(config.define[name]),\n ]),\n )\n config.define = { ...config.define, ...defines }\n // The dep optimizer applies only its own defines, so a pre-bundled library gets them here.\n config.optimizeDeps ??= {}\n config.optimizeDeps.rolldownOptions ??= {}\n config.optimizeDeps.rolldownOptions.transform ??= {}\n config.optimizeDeps.rolldownOptions.transform.define = {\n ...defines,\n ...config.optimizeDeps.rolldownOptions.transform.define,\n }\n // The dep optimizer resolves a relative import inside a library with its own list. Without\n // the `.web` variants there, a library loads its native file, not its `.web.js` file.\n config.optimizeDeps.rolldownOptions.resolve ??= {}\n config.optimizeDeps.rolldownOptions.resolve.extensions ??= extensions\n },\n\n transform: {\n filter: {\n id: SCRIPT_ID,\n code: options.worklets === true ? [PLATFORM_CODE, WORKLET_CODE] : PLATFORM_CODE,\n },\n async handler(code, id) {\n // The Worklets step comes first, as the last plugin of the Babel preset does on native:\n // it reads the functions that the other transforms made.\n const worklets = workletize === undefined ? null : await workletize(code, id)\n const current = worklets?.code ?? code\n if (!PLATFORM_CODE.test(current)) return worklets\n\n let program: object\n try {\n program = this.parse(current)\n } catch {\n // Not plain JavaScript yet. The module keeps its code, and a later step reports a real\n // syntax error.\n return worklets\n }\n const inlined = inlinePlatformOS(current, program)\n if (inlined === null) return worklets\n // The replaced reads change only columns on their own lines, so the map of the\n // Worklets step stays close.\n return { code: inlined, map: worklets?.map ?? null }\n },\n },\n }\n}\n"],"mappings":";;AAcA,MAAM,0BAAU,IAAI,IAAI,CAAC,gBAAgB,iBAAiB,CAAC;AAC3D,MAAM,cAAc;AACpB,MAAM,aAAa;AAEnB,MAAM,UAAU,UACd,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA6B,SAAS;AAEhD,MAAM,kBAAkB,SACtB,OAAO,IAAI,KAAK,KAAK,SAAS,gBAAgB,OAAO,KAAK,SAAS,WAC/D,KAAK,OACL,KAAA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,QAAQ,aAAa;GAG5B,MAAM,UAAU,OAAO,YACrB,OAAO,QAAQ,cAAc,gBAAgB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,UAAU,CACrE,MACA,OAAO,SAAS,UAAU,KAAA,IAAY,OAAO,WAAW,OAAO,OAAO,KAAK,CAC7E,CAAC,CACH;GACA,OAAO,SAAS;IAAE,GAAG,OAAO;IAAQ,GAAG;GAAQ;GAE/C,OAAO,iBAAiB,CAAC;GACzB,OAAO,aAAa,oBAAoB,CAAC;GACzC,OAAO,aAAa,gBAAgB,cAAc,CAAC;GACnD,OAAO,aAAa,gBAAgB,UAAU,SAAS;IACrD,GAAG;IACH,GAAG,OAAO,aAAa,gBAAgB,UAAU;GACnD;GAGA,OAAO,aAAa,gBAAgB,YAAY,CAAC;GACjD,OAAO,aAAa,gBAAgB,QAAQ,eAAe;EAC7D;EAEA,WAAW;GACT,QAAQ;IACN,IAAI;IACJ,MAAM,QAAQ,aAAa,OAAO,CAAC,eAAe,YAAY,IAAI;GACpE;GACA,MAAM,QAAQ,MAAM,IAAI;IAGtB,MAAM,WAAW,eAAe,KAAA,IAAY,OAAO,MAAM,WAAW,MAAM,EAAE;IAC5E,MAAM,UAAU,UAAU,QAAQ;IAClC,IAAI,CAAC,cAAc,KAAK,OAAO,GAAG,OAAO;IAEzC,IAAI;IACJ,IAAI;KACF,UAAU,KAAK,MAAM,OAAO;IAC9B,QAAQ;KAGN,OAAO;IACT;IACA,MAAM,UAAU,iBAAiB,SAAS,OAAO;IACjD,IAAI,YAAY,MAAM,OAAO;IAG7B,OAAO;KAAE,MAAM;KAAS,KAAK,UAAU,OAAO;IAAK;GACrD;EACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/vite/index.ts"],"sourcesContent":["import type { Alias, AliasOptions, Plugin } from 'vite'\n\nimport {\n ALIASES,\n createWorkletTransform,\n globalDefines,\n inlinePlatformOS,\n WORKLET_CODE,\n webExtensions,\n type WorkletTransform,\n} from '../bundler'\nimport { isProductionEnv } from '../utils/env'\n\n// Vite's default `resolve.extensions`. A config that sets the option replaces this list, so the\n// plugin starts from the same one.\nconst VITE_DEFAULT_EXTENSIONS = ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json']\n\nconst SCRIPT_ID = /\\.[cm]?[jt]sx?(?:$|\\?)/\n\nconst escapeRegExp = (value: string): string => value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n\nconst isAliasArray = (alias: AliasOptions): alias is readonly Alias[] => Array.isArray(alias)\n\nconst aliasArray = (alias: AliasOptions | undefined): Alias[] => {\n if (alias === undefined) return []\n if (isAliasArray(alias)) return [...alias]\n return Object.entries(alias).map(([find, replacement]) => ({ find, replacement }))\n}\n\nconst defineCode = (value: unknown): string =>\n typeof value === 'string' ? value : JSON.stringify(value)\n\nconst PLATFORM_CODE = /\\bPlatform\\b/\n\nexport type RootnativeOptions = {\n /**\n * Runs the Babel plugin of `react-native-worklets` on your code and on the libraries that\n * have worklets. Reanimated needs it, and so does a library built on Reanimated. The app\n * must have `react-native-worklets` and `@babel/core`. Default: `false`.\n */\n worklets?: boolean | undefined\n}\n\n/**\n * The Vite plugin. It points `react-native` at `@rootnative/web`, resolves `.web.*` files\n * first, defines `__DEV__`, and replaces `Platform.OS` with `'web'`.\n */\nexport const rootnative = (options: RootnativeOptions = {}): Plugin => {\n let workletize: WorkletTransform | undefined\n\n return {\n name: '@rootnative/web',\n\n // Edits the config in place, so the app's own values win. A returned partial config would\n // append the lists after the app's entries and override its defines.\n config(config) {\n if (options.worklets === true) {\n const transform = createWorkletTransform(config.root ?? process.cwd())\n workletize = transform\n // The dev server pre-bundles the libraries, and a `transform` hook of a Vite plugin\n // never sees their files. The optimizer takes its own plugin.\n config.optimizeDeps ??= {}\n config.optimizeDeps.rolldownOptions ??= {}\n const rolldownOptions = config.optimizeDeps.rolldownOptions\n rolldownOptions.plugins = [\n rolldownOptions.plugins,\n {\n name: '@rootnative/web:worklets',\n transform: { filter: { id: SCRIPT_ID, code: WORKLET_CODE }, handler: transform },\n },\n ] as typeof rolldownOptions.plugins\n }\n\n config.resolve ??= {}\n // Last, so an alias in the app's config wins. The first matching alias resolves an import.\n config.resolve.alias = [\n ...aliasArray(config.resolve.alias),\n ...Object.entries(ALIASES).map(([name, replacement]) => ({\n find: new RegExp(`^${escapeRegExp(name)}$`),\n replacement,\n })),\n ]\n const extensions = webExtensions(config.resolve.extensions ?? VITE_DEFAULT_EXTENSIONS)\n config.resolve.extensions = extensions\n\n // Vite has set NODE_ENV before this hook runs, so `__DEV__` follows React's development mode.\n const defines = Object.fromEntries(\n Object.entries(globalDefines(isProductionEnv())).map(([name, code]) => [\n name,\n config.define?.[name] === undefined ? code : defineCode(config.define[name]),\n ]),\n )\n config.define = { ...config.define, ...defines }\n // The dep optimizer applies only its own defines, so a pre-bundled library gets them here.\n config.optimizeDeps ??= {}\n config.optimizeDeps.rolldownOptions ??= {}\n config.optimizeDeps.rolldownOptions.transform ??= {}\n config.optimizeDeps.rolldownOptions.transform.define = {\n ...defines,\n ...config.optimizeDeps.rolldownOptions.transform.define,\n }\n // The dep optimizer resolves a relative import inside a library with its own list. Without\n // the `.web` variants there, a library loads its native file, not its `.web.js` file.\n config.optimizeDeps.rolldownOptions.resolve ??= {}\n config.optimizeDeps.rolldownOptions.resolve.extensions ??= extensions\n },\n\n transform: {\n filter: {\n id: SCRIPT_ID,\n code: options.worklets === true ? [PLATFORM_CODE, WORKLET_CODE] : PLATFORM_CODE,\n },\n async handler(code, id) {\n // The Worklets step comes first, as the last plugin of the Babel preset does on native:\n // it reads the functions that the other transforms made.\n const worklets = workletize === undefined ? null : await workletize(code, id)\n const current = worklets?.code ?? code\n if (!PLATFORM_CODE.test(current)) return worklets\n\n let program: object\n try {\n program = this.parse(current)\n } catch {\n // Not plain JavaScript yet. The module keeps its code, and a later step reports a real\n // syntax error.\n return worklets\n }\n const inlined = inlinePlatformOS(current, program)\n if (inlined === null) return worklets\n // The replaced reads change only columns on their own lines, so the map of the\n // Worklets step stays close.\n return { code: inlined, map: worklets?.map ?? null }\n },\n },\n }\n}\n"],"mappings":";;;;;AAeA,MAAM,0BAA0B;CAAC;CAAQ;CAAO;CAAQ;CAAO;CAAQ;CAAQ;AAAO;AAEtF,MAAM,YAAY;AAElB,MAAM,gBAAgB,UAA0B,MAAM,QAAQ,uBAAuB,MAAM;AAE3F,MAAM,gBAAgB,UAAmD,MAAM,QAAQ,KAAK;AAE5F,MAAM,cAAc,UAA6C;CAC/D,IAAI,UAAU,KAAA,GAAW,OAAO,CAAC;CACjC,IAAI,aAAa,KAAK,GAAG,OAAO,CAAC,GAAG,KAAK;CACzC,OAAO,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,kBAAkB;EAAE;EAAM;CAAY,EAAE;AACnF;AAEA,MAAM,cAAc,UAClB,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,KAAK;AAE1D,MAAM,gBAAgB;;;;;AAetB,MAAa,cAAc,UAA6B,CAAC,MAAc;CACrE,IAAI;CAEJ,OAAO;EACL,MAAM;EAIN,OAAO,QAAQ;GACb,IAAI,QAAQ,aAAa,MAAM;IAC7B,MAAM,YAAY,uBAAuB,OAAO,QAAQ,QAAQ,IAAI,CAAC;IACrE,aAAa;IAGb,OAAO,iBAAiB,CAAC;IACzB,OAAO,aAAa,oBAAoB,CAAC;IACzC,MAAM,kBAAkB,OAAO,aAAa;IAC5C,gBAAgB,UAAU,CACxB,gBAAgB,SAChB;KACE,MAAM;KACN,WAAW;MAAE,QAAQ;OAAE,IAAI;OAAW,MAAM;MAAa;MAAG,SAAS;KAAU;IACjF,CACF;GACF;GAEA,OAAO,YAAY,CAAC;GAEpB,OAAO,QAAQ,QAAQ,CACrB,GAAG,WAAW,OAAO,QAAQ,KAAK,GAClC,GAAG,OAAO,QAAQ,OAAO,CAAC,CAAC,KAAK,CAAC,MAAM,kBAAkB;IACvD,MAAM,IAAI,OAAO,IAAI,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|
|
61
61
|
dependency that Vite leaves to Node gets no __DEV__ and throws a
|
|
62
62
|
ReferenceError. Add it to ssr.noExternal.
|
|
63
63
|
|
|
64
|
+
## Expo
|
|
65
|
+
|
|
66
|
+
An Expo app (no Expo Router) runs on @rootnative/web through
|
|
67
|
+
@rootnative/web-expo, installed under the name react-native-web:
|
|
68
|
+
npm install react-native-web@npm:@rootnative/web-expo
|
|
69
|
+
Restart the dev server with --clear. The app code, the Babel preset, and the
|
|
70
|
+
react-native types stay. Expo's Babel preset rewrites each react-native import
|
|
71
|
+
to react-native-web/dist/exports/<Name>; the package has those files, and each
|
|
72
|
+
one loads only its own module of @rootnative/web, so the bundle has only the
|
|
73
|
+
components the app imports. It also gives Expo AppRegistry and the page reset
|
|
74
|
+
(body margin 0). Works: the dev server, expo export --platform web with
|
|
75
|
+
web.output 'single', Reanimated 4 (the preset adds the Worklets plugin), image
|
|
76
|
+
imports, react-native-svg. web-expo depends on the exact same version of
|
|
77
|
+
@rootnative/web: install that version if the app imports @rootnative/web too.
|
|
78
|
+
A name that @rootnative/web lacks (Animated, Easing, LayoutAnimation,
|
|
79
|
+
SectionList, VirtualizedList, ImageBackground, SafeAreaView, and more) loads
|
|
80
|
+
as a stub that throws "<Name> is not in @rootnative/web yet" on use;
|
|
81
|
+
node_modules/react-native-web/expo-exports.json lists them under "missing".
|
|
82
|
+
Expo Router needs Animated, so it doesn't work yet.
|
|
83
|
+
|
|
64
84
|
## Entry points
|
|
65
85
|
|
|
66
86
|
- @rootnative/web: the React Native components and APIs. Import it as
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rootnative/web",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.5",
|
|
4
4
|
"description": "A standalone web runtime for React Native apps",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://rootnative.github.io/web/",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"./server": "./dist/server/index.js",
|
|
38
38
|
"./style": "./dist/style/index.js",
|
|
39
39
|
"./vite": "./dist/vite/index.js",
|
|
40
|
+
"./internal/*.js": "./dist/*.js",
|
|
40
41
|
"./package.json": "./package.json"
|
|
41
42
|
},
|
|
42
43
|
"scripts": {
|
|
@@ -75,8 +76,8 @@
|
|
|
75
76
|
"@vitest/browser": "5.0.5",
|
|
76
77
|
"@vitest/browser-playwright": "5.0.5",
|
|
77
78
|
"playwright": "1.64.1",
|
|
78
|
-
"react": "19.3.
|
|
79
|
-
"react-dom": "19.3.
|
|
79
|
+
"react": "19.3.0",
|
|
80
|
+
"react-dom": "19.3.0",
|
|
80
81
|
"react-native": "0.88.1",
|
|
81
82
|
"react-native-worklets": "0.13.0",
|
|
82
83
|
"tsdown": "0.23.4",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StyleRegistryContext-ROsMlY4O.js","names":[],"sources":["../src/style/StyleRegistryContext.ts"],"sourcesContent":["import { createContext, useContext, type Context } from 'react'\n\nimport { getStyleRegistry, type StyleRegistry } from './registry'\n\nexport const StyleRegistryContext: Context<StyleRegistry | null> =\n createContext<StyleRegistry | null>(null)\n\nexport const useStyleRegistry = (): StyleRegistry =>\n useContext(StyleRegistryContext) ?? getStyleRegistry()\n"],"mappings":";;;AAIA,MAAa,uBACX,cAAoC,IAAI;AAE1C,MAAa,yBACX,WAAW,oBAAoB,KAAK,iBAAiB"}
|