@rootnative/web 0.0.0-alpha.0 → 0.0.0-alpha.2
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 +47 -1
- package/README.md +7 -6
- package/dist/{StyleRegistryContext-ButsUd8D.js → StyleRegistryContext-CAD45r4n.js} +3 -8
- package/dist/StyleRegistryContext-CAD45r4n.js.map +1 -0
- package/dist/env-DK5Mt9yX.js +9 -0
- package/dist/env-DK5Mt9yX.js.map +1 -0
- package/dist/index.d.ts +191 -49
- package/dist/index.js +2149 -1651
- package/dist/index.js.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/vite/index.d.ts +7 -0
- package/dist/vite/index.js +206 -0
- package/dist/vite/index.js.map +1 -0
- package/llms.txt +128 -20
- package/package.json +18 -9
- package/dist/StyleRegistryContext-ButsUd8D.js.map +0 -1
package/dist/server/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as StyleRegistry, i as SHORTHAND_STYLE_ID, r as LONGHAND_STYLE_ID, t as StyleRegistryContext } from "../StyleRegistryContext-
|
|
1
|
+
import { a as StyleRegistry, i as SHORTHAND_STYLE_ID, r as LONGHAND_STYLE_ID, t as StyleRegistryContext } from "../StyleRegistryContext-CAD45r4n.js";
|
|
2
2
|
import { Fragment, createElement } from "react";
|
|
3
3
|
// src/server/index.ts
|
|
4
4
|
const createStyleRegistry = () => new StyleRegistry();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
/**
|
|
3
|
+
* The Vite plugin. It points `react-native` at `@rootnative/web`, resolves `.web.*` files
|
|
4
|
+
* first, defines `__DEV__`, and replaces `Platform.OS` with `'web'`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const rootnative: () => Plugin;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { n as isProductionEnv } from "../env-DK5Mt9yX.js";
|
|
2
|
+
// src/bundler/inlinePlatformOS.ts
|
|
3
|
+
const SOURCES = /* @__PURE__ */ new Set(["react-native", "@rootnative/web"]);
|
|
4
|
+
const REPLACEMENT = "\"web\"";
|
|
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/index.ts
|
|
121
|
+
/** Module names that resolve to this package. Each one matches the exact name only. */
|
|
122
|
+
const ALIASES = { "react-native": "@rootnative/web" };
|
|
123
|
+
/**
|
|
124
|
+
* The globals that React Native code expects from its bundler, each as the code that replaces
|
|
125
|
+
* the name. `__DEV__` is `true` in a development build and `false` in a production build.
|
|
126
|
+
*/
|
|
127
|
+
const globalDefines = (production) => ({ __DEV__: JSON.stringify(!production) });
|
|
128
|
+
/**
|
|
129
|
+
* Puts a `.web` variant of each extension first, as Metro does for the web platform. An
|
|
130
|
+
* import of `./Button` then finds `Button.web.tsx` before `Button.tsx`.
|
|
131
|
+
*/
|
|
132
|
+
const webExtensions = (extensions) => {
|
|
133
|
+
const web = extensions.map((extension) => extension.startsWith(".web.") ? extension : `.web${extension}`);
|
|
134
|
+
return [.../* @__PURE__ */ new Set([...web, ...extensions])];
|
|
135
|
+
};
|
|
136
|
+
// src/vite/index.ts
|
|
137
|
+
const VITE_DEFAULT_EXTENSIONS = [
|
|
138
|
+
".mjs",
|
|
139
|
+
".js",
|
|
140
|
+
".mts",
|
|
141
|
+
".ts",
|
|
142
|
+
".jsx",
|
|
143
|
+
".tsx",
|
|
144
|
+
".json"
|
|
145
|
+
];
|
|
146
|
+
const SCRIPT_ID = /\.[cm]?[jt]sx?(?:$|\?)/;
|
|
147
|
+
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
148
|
+
const isAliasArray = (alias) => Array.isArray(alias);
|
|
149
|
+
const aliasArray = (alias) => {
|
|
150
|
+
if (alias === void 0) return [];
|
|
151
|
+
if (isAliasArray(alias)) return [...alias];
|
|
152
|
+
return Object.entries(alias).map(([find, replacement]) => ({
|
|
153
|
+
find,
|
|
154
|
+
replacement
|
|
155
|
+
}));
|
|
156
|
+
};
|
|
157
|
+
const defineCode = (value) => typeof value === "string" ? value : JSON.stringify(value);
|
|
158
|
+
/**
|
|
159
|
+
* The Vite plugin. It points `react-native` at `@rootnative/web`, resolves `.web.*` files
|
|
160
|
+
* first, defines `__DEV__`, and replaces `Platform.OS` with `'web'`.
|
|
161
|
+
*/
|
|
162
|
+
const rootnative = () => ({
|
|
163
|
+
name: "@rootnative/web",
|
|
164
|
+
config(config) {
|
|
165
|
+
config.resolve ??= {};
|
|
166
|
+
config.resolve.alias = [...aliasArray(config.resolve.alias), ...Object.entries(ALIASES).map(([name, replacement]) => ({
|
|
167
|
+
find: new RegExp(`^${escapeRegExp(name)}$`),
|
|
168
|
+
replacement
|
|
169
|
+
}))];
|
|
170
|
+
config.resolve.extensions = webExtensions(config.resolve.extensions ?? VITE_DEFAULT_EXTENSIONS);
|
|
171
|
+
const defines = Object.fromEntries(Object.entries(globalDefines(isProductionEnv())).map(([name, code]) => [name, config.define?.[name] === void 0 ? code : defineCode(config.define[name])]));
|
|
172
|
+
config.define = {
|
|
173
|
+
...config.define,
|
|
174
|
+
...defines
|
|
175
|
+
};
|
|
176
|
+
config.optimizeDeps ??= {};
|
|
177
|
+
config.optimizeDeps.rolldownOptions ??= {};
|
|
178
|
+
config.optimizeDeps.rolldownOptions.transform ??= {};
|
|
179
|
+
config.optimizeDeps.rolldownOptions.transform.define = {
|
|
180
|
+
...defines,
|
|
181
|
+
...config.optimizeDeps.rolldownOptions.transform.define
|
|
182
|
+
};
|
|
183
|
+
},
|
|
184
|
+
transform: {
|
|
185
|
+
filter: {
|
|
186
|
+
id: SCRIPT_ID,
|
|
187
|
+
code: /\bPlatform\b/
|
|
188
|
+
},
|
|
189
|
+
handler(code) {
|
|
190
|
+
let program;
|
|
191
|
+
try {
|
|
192
|
+
program = this.parse(code);
|
|
193
|
+
} catch {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
const inlined = inlinePlatformOS(code, program);
|
|
197
|
+
return inlined === null ? null : {
|
|
198
|
+
code: inlined,
|
|
199
|
+
map: null
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
export { rootnative };
|
|
205
|
+
|
|
206
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/bundler/inlinePlatformOS.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","export { inlinePlatformOS } from './inlinePlatformOS'\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}\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 */\nexport const globalDefines = (production: boolean): Record<string, string> => ({\n __DEV__: JSON.stringify(!production),\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 { ALIASES, globalDefines, inlinePlatformOS, webExtensions } 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\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 = (): Plugin => ({\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 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 config.resolve.extensions = webExtensions(config.resolve.extensions ?? VITE_DEFAULT_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 },\n\n transform: {\n filter: { id: SCRIPT_ID, code: /\\bPlatform\\b/ },\n handler(code) {\n let program: object\n try {\n program = this.parse(code)\n } catch {\n // Not plain JavaScript yet. The module keeps its code, and a later step reports a real\n // syntax error.\n return null\n }\n const inlined = inlinePlatformOS(code, program)\n return inlined === null ? null : { code: inlined, map: null }\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;AAEN,MAAM,SAAS,UACb,MAAM,QAAQ,KAAK,IAAI,MAAM,OAAO,MAAM,IAAI,OAAO,KAAK,IAAI,CAAC,KAAK,IAAI,CAAC;AAE3E,MAAM,mBAAmB,SAAkB,UAA6B;CACtE,IAAI,CAAC,OAAO,OAAO,GAAG;CACtB,QAAQ,QAAQ,MAAhB;EACE,KAAK,cAAc;GACjB,MAAM,OAAO,eAAe,OAAO;GACnC,IAAI,SAAS,KAAA,GAAW,MAAM,IAAI,IAAI;GACtC;EACF;EACA,KAAK;GACH,KAAK,MAAM,YAAY,MAAM,QAAQ,UAAU,GAC7C,gBAAgB,SAAS,SAAS,gBAAgB,SAAS,WAAW,SAAS,OAAO,KAAK;GAE7F;EACF,KAAK;GACH,KAAK,MAAM,WAAW,MAAM,QAAQ,QAAQ,GAAG,gBAAgB,SAAS,KAAK;GAC7E;EACF,KAAK;GACH,gBAAgB,QAAQ,UAAU,KAAK;GACvC;EACF,KAAK,qBACH,gBAAgB,QAAQ,MAAM,KAAK;CACvC;AACF;AAEA,MAAM,iBAAiB,QAAiB,KAAa,gBAA8C;CACjG,QAAQ,OAAO,MAAf;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,kBACH,OAAO,QAAQ;EACjB,KAAK;EACL,KAAK;EACL,KAAK,eAC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CACrE,MACA,OAAO,SAAS,UAAU,KAAA,IAAY,OAAO,WAAW,OAAO,OAAO,KAAK,CAC7E,CAAC,CACH;EACA,OAAO,SAAS;GAAE,GAAG,OAAO;GAAQ,GAAG;EAAQ;EAE/C,OAAO,iBAAiB,CAAC;EACzB,OAAO,aAAa,oBAAoB,CAAC;EACzC,OAAO,aAAa,gBAAgB,cAAc,CAAC;EACnD,OAAO,aAAa,gBAAgB,UAAU,SAAS;GACrD,GAAG;GACH,GAAG,OAAO,aAAa,gBAAgB,UAAU;EACnD;CACF;CAEA,WAAW;EACT,QAAQ;GAAE,IAAI;GAAW,MAAM;EAAe;EAC9C,QAAQ,MAAM;GACZ,IAAI;GACJ,IAAI;IACF,UAAU,KAAK,MAAM,IAAI;GAC3B,QAAQ;IAGN,OAAO;GACT;GACA,MAAM,UAAU,iBAAiB,MAAM,OAAO;GAC9C,OAAO,YAAY,OAAO,OAAO;IAAE,MAAM;IAAS,KAAK;GAAK;EAC9D;CACF;AACF"}
|
package/llms.txt
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# @rootnative/web
|
|
2
2
|
|
|
3
3
|
> A standalone web runtime for React Native apps. The app imports
|
|
4
|
-
> react-native,
|
|
5
|
-
> runs in the browser as a real web app: semantic HTML, atomic CSS, server
|
|
4
|
+
> react-native, the Vite plugin resolves that name to @rootnative/web, and the
|
|
5
|
+
> app runs in the browser as a real web app: semantic HTML, atomic CSS, server
|
|
6
6
|
> rendering, and SEO tags. It doesn't use react-native-web.
|
|
7
7
|
|
|
8
8
|
Status: early alpha. The API can change between releases. Every component and
|
|
9
|
-
API has tests that run in
|
|
10
|
-
|
|
9
|
+
API has tests that run in real browsers: Chromium, Firefox, and WebKit, the
|
|
10
|
+
engine of Safari.
|
|
11
11
|
|
|
12
12
|
Docs: https://rootnative.github.io/web/
|
|
13
13
|
Full: https://rootnative.github.io/web/llms-full.txt
|
|
@@ -19,14 +19,20 @@ npm install @rootnative/web
|
|
|
19
19
|
|
|
20
20
|
Peers: react ^19.0.0, react-dom ^19.0.0. ESM only.
|
|
21
21
|
|
|
22
|
-
1.
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
1. Add the Vite plugin (Vite 8) to vite.config.ts:
|
|
23
|
+
import { rootnative } from '@rootnative/web/vite'
|
|
24
|
+
plugins: [react(), rootnative()]
|
|
25
|
+
It resolves react-native to @rootnative/web (the exact name only), resolves
|
|
26
|
+
.web.* files first, defines __DEV__ (true on the dev server, false in a
|
|
27
|
+
production build, from NODE_ENV), and puts 'web' in place of Platform.OS.
|
|
28
|
+
An alias or a __DEV__ define in your own config wins.
|
|
25
29
|
2. Add src/react-native.d.ts (in a folder that tsconfig.json includes):
|
|
26
30
|
declare module 'react-native' { export * from '@rootnative/web' }
|
|
27
31
|
The file must have no top-level import or export line. With one,
|
|
28
32
|
TypeScript reports "Cannot find module 'react-native'". Don't map the name
|
|
29
|
-
with tsconfig "paths": the package has no main or types field.
|
|
33
|
+
with tsconfig "paths": the package has no main or types field. The file
|
|
34
|
+
also gives the type of __DEV__. For .web.tsx files, add
|
|
35
|
+
"moduleSuffixes": [".web", ""] to tsconfig.json.
|
|
30
36
|
3. Give the page a full-height flex root:
|
|
31
37
|
html, body, #root { height: 100%; margin: 0 }
|
|
32
38
|
#root { display: flex; flex-direction: column }
|
|
@@ -35,32 +41,43 @@ Peers: react ^19.0.0, react-dom ^19.0.0. ESM only.
|
|
|
35
41
|
|
|
36
42
|
Browsers: Chrome 95, Edge 95, Firefox 93, Safari 15.1, iOS Safari 15.1.
|
|
37
43
|
|
|
44
|
+
Without the plugin (another bundler): alias the exact name react-native to
|
|
45
|
+
@rootnative/web, put a .web variant of each extension first, and define
|
|
46
|
+
__DEV__. In Vite, define it in define and in
|
|
47
|
+
optimizeDeps.rolldownOptions.transform.define: the dependency optimizer
|
|
48
|
+
doesn't apply define. Platform.OS then stays a read at run time.
|
|
49
|
+
|
|
50
|
+
Server rendering with Vite: the plugin applies to app code on the server. A
|
|
51
|
+
dependency that Vite leaves to Node gets no __DEV__ and throws a
|
|
52
|
+
ReferenceError. Add it to ssr.noExternal.
|
|
53
|
+
|
|
38
54
|
## Entry points
|
|
39
55
|
|
|
40
56
|
- @rootnative/web: the React Native components and APIs. Import it as
|
|
41
|
-
react-native through the
|
|
57
|
+
react-native through the plugin.
|
|
42
58
|
- @rootnative/web/dom: web-only features. Head.
|
|
43
59
|
- @rootnative/web/server: createStyleRegistry, StyleRegistryProvider,
|
|
44
60
|
renderStyleTags, styleTagsHTML, StyleRegistry.
|
|
61
|
+
- @rootnative/web/vite: rootnative(), the Vite plugin. Only in vite.config.ts.
|
|
45
62
|
|
|
46
63
|
Import /dom and /server only in code that runs on the web.
|
|
47
64
|
|
|
48
65
|
## What ships
|
|
49
66
|
|
|
50
|
-
Components: View, Text, Image, Pressable,
|
|
51
|
-
|
|
67
|
+
Components: View, Text, Image, Pressable, TouchableHighlight,
|
|
68
|
+
TouchableNativeFeedback, TouchableOpacity, TouchableWithoutFeedback, Button,
|
|
69
|
+
ScrollView, FlatList, TextInput, Switch, ActivityIndicator, StatusBar.
|
|
52
70
|
|
|
53
71
|
APIs: StyleSheet, Platform, Dimensions, useWindowDimensions, Appearance,
|
|
54
72
|
useColorScheme, AccessibilityInfo, I18nManager, BackHandler, PixelRatio,
|
|
55
73
|
processColor, PanResponder, usePressability.
|
|
56
74
|
|
|
57
75
|
NOT IMPLEMENTED, do not import:
|
|
58
|
-
-
|
|
59
|
-
TouchableHighlight, TouchableWithoutFeedback, TouchableNativeFeedback.
|
|
76
|
+
- RefreshControl, Modal.
|
|
60
77
|
- Alert, AppState, Linking, Share, Vibration, Clipboard.
|
|
61
78
|
- SectionList, VirtualizedList, Animated, LayoutAnimation.
|
|
62
|
-
-
|
|
63
|
-
|
|
79
|
+
- A Next.js plugin, and templates for a Vite app with and without server
|
|
80
|
+
rendering.
|
|
64
81
|
|
|
65
82
|
Out of scope: Expo, Metro, React 18, CommonJS, Flow.
|
|
66
83
|
|
|
@@ -134,10 +151,16 @@ Text
|
|
|
134
151
|
- numberOfLines 1 ends the line with an ellipsis. A larger number clamps.
|
|
135
152
|
- ellipsizeMode: tail and clip. head and middle show the ellipsis at the end.
|
|
136
153
|
- selectable is true by default on the web (false on native).
|
|
137
|
-
- onPress
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
154
|
+
- onPress, onPressIn, onPressOut, onLongPress, and pressRetentionOffset work
|
|
155
|
+
as on Pressable. The event is a GestureResponderEvent. As on native, only
|
|
156
|
+
onPress or onLongPress makes a Text pressable. suppressHighlighting is
|
|
157
|
+
ignored, as on Android.
|
|
158
|
+
- A pressable Text with no role has role="link", is in the tab order, and
|
|
159
|
+
Enter or Space presses it. With href it renders an <a>. role="button"
|
|
160
|
+
renders a <button>. disabled sets aria-disabled, and the Text isn't
|
|
161
|
+
pressable, so a pressable parent gets the press.
|
|
162
|
+
- On a pressable Text, onClick and the other DOM handlers run before the press
|
|
163
|
+
handlers, and both run.
|
|
141
164
|
|
|
142
165
|
Image
|
|
143
166
|
- Renders a div box with an <img> inside. The style sizes the box. With no
|
|
@@ -171,6 +194,62 @@ Pressable
|
|
|
171
194
|
- disabled sets aria-disabled, leaves the tab order, and stops every press.
|
|
172
195
|
- android_ripple, android_disableSound, blockNativeResponder: ignored.
|
|
173
196
|
|
|
197
|
+
TouchableHighlight
|
|
198
|
+
- The press handling of Pressable, with no minimum press duration. A div
|
|
199
|
+
around one child that takes a style. role="button" renders a button.
|
|
200
|
+
- While pressed: underlayColor (default black) as the background, and
|
|
201
|
+
activeOpacity (default 0.85) on the child. After onPress, the underlay
|
|
202
|
+
stays for delayPressOut ms, so a short tap shows it. No press handler, no
|
|
203
|
+
underlay. testOnly_pressed shows it. onShowUnderlay, onHideUnderlay.
|
|
204
|
+
- Give the child an opaque background color, or the underlay shows at full
|
|
205
|
+
strength.
|
|
206
|
+
- In the tab order only with onPress. onFocus and onBlur fire.
|
|
207
|
+
rejectResponderTermination sets touch-action: none.
|
|
208
|
+
|
|
209
|
+
TouchableNativeFeedback
|
|
210
|
+
- Works as TouchableWithoutFeedback, with no ripple, as on iOS. background
|
|
211
|
+
and useForeground are ignored.
|
|
212
|
+
- SelectableBackground(), SelectableBackgroundBorderless(), and Ripple(color,
|
|
213
|
+
borderless, rippleRadius) return the objects of React Native.
|
|
214
|
+
canUseNativeForeground() is false. Call Ripple outside a component: the
|
|
215
|
+
React Compiler lint reads a capitalized call as a component.
|
|
216
|
+
|
|
217
|
+
TouchableOpacity
|
|
218
|
+
- The press handling of Pressable, with no minimum press duration.
|
|
219
|
+
role="button" renders <button type="button">. Without a role, a div.
|
|
220
|
+
- Dims to activeOpacity (default 0.2) at once when a press starts, and over
|
|
221
|
+
150 ms when the pointer comes back into the press area. Fades back to the
|
|
222
|
+
style's opacity over 250 ms when the press ends or the pointer leaves, and
|
|
223
|
+
when disabled or the style's opacity changes. Easing.inOut(Easing.quad),
|
|
224
|
+
through the Web Animations API, with no new render.
|
|
225
|
+
- In the tab order only with onPress, as on native. onFocus and onBlur fire
|
|
226
|
+
(native doesn't call them). rejectResponderTermination sets touch-action:
|
|
227
|
+
none. hitSlop and pressRetentionOffset as on Pressable.
|
|
228
|
+
- touchSoundDisabled, hasTVPreferredFocus, nextFocus*: ignored.
|
|
229
|
+
|
|
230
|
+
TouchableWithoutFeedback
|
|
231
|
+
- No element of its own. Its only child gets the press handlers (the child's
|
|
232
|
+
own DOM handlers run first), the accessibility props, role, testID,
|
|
233
|
+
nativeID, id, and onLayout. style stays out, as on native.
|
|
234
|
+
- onFocus and onBlur replace the child's. Without them, the child keeps its
|
|
235
|
+
own. The child is in the tab order only with onPress and not disabled.
|
|
236
|
+
- hitSlop goes to the child, but a View doesn't grow its hit area yet.
|
|
237
|
+
rejectResponderTermination is ignored.
|
|
238
|
+
|
|
239
|
+
Button
|
|
240
|
+
- <button type="button"> with the title in a Text, on TouchableOpacity: it
|
|
241
|
+
dims to 0.2 while pressed. title must be a string, or Button throws.
|
|
242
|
+
- The look of the Android button: background #2196F3, white text, weight 500,
|
|
243
|
+
radius 2, 8 px around the title. color sets the background. The title keeps
|
|
244
|
+
its case (Android makes it uppercase). No elevation.
|
|
245
|
+
- disabled (or aria-disabled, or accessibilityState.disabled): background
|
|
246
|
+
#dfdfdf, text #a1a1a1, aria-disabled, out of the tab order, no press.
|
|
247
|
+
- Takes only the props of React Native's Button: no style, no children. For
|
|
248
|
+
another look, use Pressable with role="button".
|
|
249
|
+
- accessibilityLanguage sets lang. accessibilityActions,
|
|
250
|
+
onAccessibilityAction, touchSoundDisabled, hasTVPreferredFocus, nextFocus*:
|
|
251
|
+
ignored. Ref: the button element.
|
|
252
|
+
|
|
174
253
|
ScrollView
|
|
175
254
|
- Scrolls its own box, not the document. On a phone, the browser's address
|
|
176
255
|
bar doesn't hide as it scrolls.
|
|
@@ -229,6 +308,33 @@ TextInput
|
|
|
229
308
|
setNativeProps({ text }). TextInput.State has currentlyFocusedInput(),
|
|
230
309
|
focusTextInput(element), blurTextInput(element).
|
|
231
310
|
|
|
311
|
+
Switch
|
|
312
|
+
- <input type="checkbox" role="switch">, transparent, over a drawn track and
|
|
313
|
+
thumb. The browser gives the press, Space, the focus, and <label for>.
|
|
314
|
+
- Controlled, as on native: it shows value (only true is on). A press calls
|
|
315
|
+
onChange (nativeEvent.value, nativeEvent.target), then onValueChange(value).
|
|
316
|
+
When value doesn't change, the switch goes back.
|
|
317
|
+
- The look of the Android switch: 40 by 20 px, track #939393 off and #A3D3CF
|
|
318
|
+
on, thumb #FAFAFA off and #009688 on. trackColor={{ false, true }} and
|
|
319
|
+
thumbColor replace them. The thumb moves over 150 ms, not with
|
|
320
|
+
prefers-reduced-motion. Right-to-left puts the on position at the left.
|
|
321
|
+
- disabled (or accessibilityState.disabled): the input is disabled, and the
|
|
322
|
+
switch has an opacity of 0.5.
|
|
323
|
+
- style, onLayout, and pointerEvents go to the root element, which has
|
|
324
|
+
alignSelf: flex-start. A width and height in style change the size. The
|
|
325
|
+
ref, id, testID, and the accessibility props go to the input.
|
|
326
|
+
- ios_backgroundColor, onTintColor, tintColor, thumbTintColor: ignored.
|
|
327
|
+
|
|
328
|
+
ActivityIndicator
|
|
329
|
+
- A spinner: an SVG that turns once each 0.75 s, in an element with
|
|
330
|
+
role="progressbar". size: small (20 px, the default), large (36 px), or a
|
|
331
|
+
number. color: the default is #999999.
|
|
332
|
+
- animating={false} stops and hides it, and it keeps its space.
|
|
333
|
+
hidesWhenStopped={false} keeps a stopped indicator visible.
|
|
334
|
+
- Two elements, as on native: style and onLayout go to a container that
|
|
335
|
+
centers the indicator. The ref and the other props go to the indicator.
|
|
336
|
+
- It turns also with prefers-reduced-motion.
|
|
337
|
+
|
|
232
338
|
StatusBar
|
|
233
339
|
- backgroundColor writes <meta name="theme-color"> in the browser, after
|
|
234
340
|
mount, so the server HTML doesn't have it. The last mounted StatusBar wins.
|
|
@@ -241,7 +347,9 @@ StatusBar
|
|
|
241
347
|
- Platform: OS is 'web'. select() uses web, then default. A native key
|
|
242
348
|
doesn't apply. Version is the user agent ('' on the server).
|
|
243
349
|
constants.reactNativeVersion is 0.88.1. isTV is false. isTesting is true when
|
|
244
|
-
NODE_ENV is test. isDisableAnimations follows prefers-reduced-motion.
|
|
350
|
+
NODE_ENV is test. isDisableAnimations follows prefers-reduced-motion. The
|
|
351
|
+
Vite plugin puts 'web' in place of each Platform.OS read at build time.
|
|
352
|
+
Platform.select keeps its code.
|
|
245
353
|
- StyleSheet: create, flatten, compose, absoluteFill, absoluteFillObject.
|
|
246
354
|
hairlineWidth is 1.
|
|
247
355
|
- Dimensions: window is innerWidth and innerHeight. screen is the display.
|
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.2",
|
|
4
4
|
"description": "A standalone web runtime for React Native apps",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://rootnative.github.io/web/",
|
|
@@ -34,14 +34,28 @@
|
|
|
34
34
|
".": "./dist/index.js",
|
|
35
35
|
"./dom": "./dist/dom/index.js",
|
|
36
36
|
"./server": "./dist/server/index.js",
|
|
37
|
+
"./vite": "./dist/vite/index.js",
|
|
37
38
|
"./package.json": "./package.json"
|
|
38
39
|
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsdown",
|
|
42
|
+
"dev": "tsdown --watch",
|
|
43
|
+
"prepack": "tsdown",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:watch": "vitest"
|
|
46
|
+
},
|
|
39
47
|
"dependencies": {
|
|
40
48
|
"@react-native/normalize-colors": "0.88.1"
|
|
41
49
|
},
|
|
42
50
|
"peerDependencies": {
|
|
43
51
|
"react": "^19.0.0",
|
|
44
|
-
"react-dom": "^19.0.0"
|
|
52
|
+
"react-dom": "^19.0.0",
|
|
53
|
+
"vite": "^8.0.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependenciesMeta": {
|
|
56
|
+
"vite": {
|
|
57
|
+
"optional": true
|
|
58
|
+
}
|
|
45
59
|
},
|
|
46
60
|
"devDependencies": {
|
|
47
61
|
"@types/react": "19.3.0",
|
|
@@ -52,17 +66,12 @@
|
|
|
52
66
|
"playwright": "1.64.1",
|
|
53
67
|
"react": "19.3.1",
|
|
54
68
|
"react-dom": "19.3.1",
|
|
69
|
+
"react-native": "0.88.1",
|
|
55
70
|
"tsdown": "0.23.4",
|
|
56
71
|
"vite": "8.3.5",
|
|
57
72
|
"vitest": "5.0.5"
|
|
58
73
|
},
|
|
59
74
|
"publishConfig": {
|
|
60
75
|
"access": "public"
|
|
61
|
-
},
|
|
62
|
-
"scripts": {
|
|
63
|
-
"build": "tsdown",
|
|
64
|
-
"dev": "tsdown --watch",
|
|
65
|
-
"test": "vitest run",
|
|
66
|
-
"test:watch": "vitest"
|
|
67
76
|
}
|
|
68
|
-
}
|
|
77
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StyleRegistryContext-ButsUd8D.js","names":[],"sources":["../src/utils/env.ts","../src/style/registry.ts","../src/style/StyleRegistryContext.ts"],"sourcesContent":["declare const process: { env: { NODE_ENV?: string } } | undefined\n\ndeclare global {\n interface ImportMeta {\n env?: { MODE?: string }\n }\n}\n\nconst nodeEnv = (): string | undefined =>\n typeof process !== 'undefined' ? process.env.NODE_ENV : import.meta.env?.MODE\n\nexport const isTestEnv = (): boolean => nodeEnv() === 'test'\n\nexport const isProductionEnv = (): boolean => nodeEnv() === 'production'\n\nexport const hasDOM = (): boolean =>\n typeof window !== 'undefined' && typeof document !== 'undefined'\n\nexport const matchesMedia = (query: string): boolean =>\n hasDOM() && typeof window.matchMedia === 'function' && window.matchMedia(query).matches\n","import { hasDOM } from '../utils/env'\nimport type { CSSDeclarations } from './types'\n\n// Two style elements: shorthand rules first, longhand rules after them. With equal\n// specificity the later sheet wins, so a longhand always beats a shorthand, as on native.\nexport const SHORTHAND_STYLE_ID = 'rootnative-style-shorthand'\nexport const LONGHAND_STYLE_ID = 'rootnative-style-longhand'\n\nconst shorthandProperties: ReadonlySet<string> = new Set([\n 'border',\n 'borderBlock',\n 'borderColor',\n 'borderInline',\n 'borderRadius',\n 'borderStyle',\n 'borderWidth',\n 'flex',\n 'flexFlow',\n 'gap',\n 'inset',\n 'insetBlock',\n 'insetInline',\n 'margin',\n 'marginBlock',\n 'marginInline',\n 'outline',\n 'overflow',\n 'padding',\n 'paddingBlock',\n 'paddingInline',\n 'textDecoration',\n])\n\nconst toKebab = (name: string): string => name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)\n\nconst hash = (input: string): string => {\n let h = 0x811c9dc5\n for (let i = 0; i < input.length; i++) {\n h ^= input.charCodeAt(i)\n h = Math.imul(h, 0x01000193)\n }\n return (h >>> 0).toString(36)\n}\n\nexport type StyleSheets = { shorthand: CSSStyleSheet | null; longhand: CSSStyleSheet | null }\n\nexport class StyleRegistry {\n private readonly classNames = new Map<string, string>()\n private readonly adopted = new Set<string>()\n private readonly shorthandRules: string[] = []\n private readonly longhandRules: string[] = []\n private readonly sheets: StyleSheets\n\n constructor(sheets: StyleSheets = { shorthand: null, longhand: null }) {\n this.sheets = sheets\n this.adopt(sheets.shorthand)\n this.adopt(sheets.longhand)\n }\n\n classFor(property: string, value: string): string {\n const key = `${property}:${value}`\n const known = this.classNames.get(key)\n if (known !== undefined) return known\n\n const className = `rn-${hash(key)}`\n this.classNames.set(key, className)\n\n const shorthand = shorthandProperties.has(property)\n const rule = `.${className}{${toKebab(property)}:${value}}`\n const rules = shorthand ? this.shorthandRules : this.longhandRules\n rules.push(rule)\n\n if (!this.adopted.has(className)) {\n const sheet = shorthand ? this.sheets.shorthand : this.sheets.longhand\n sheet?.insertRule(rule, sheet.cssRules.length)\n }\n return className\n }\n\n classesFor(declarations: CSSDeclarations): string {\n const names: string[] = []\n for (const property in declarations) {\n names.push(this.classFor(property, declarations[property] as string))\n }\n return names.join(' ')\n }\n\n // Inserts a fixed set of rules under one class name, once. For rules an atomic\n // declaration cannot express, for example a child selector.\n staticClass(className: string, rules: ReadonlyArray<string>): string {\n if (this.classNames.has(className)) return className\n this.classNames.set(className, className)\n for (const rule of rules) {\n this.longhandRules.push(rule)\n if (!this.adopted.has(className)) {\n const sheet = this.sheets.longhand\n sheet?.insertRule(rule, sheet.cssRules.length)\n }\n }\n return className\n }\n\n // The rules of each sheet, for server rendering.\n cssText(): { shorthand: string; longhand: string } {\n return { shorthand: this.shorthandRules.join('\\n'), longhand: this.longhandRules.join('\\n') }\n }\n\n get ruleCount(): number {\n return this.shorthandRules.length + this.longhandRules.length\n }\n\n // Remembers the class names the server already rendered, so the client does not insert them again.\n private adopt(sheet: CSSStyleSheet | null): void {\n if (sheet === null) return\n for (const rule of Array.from(sheet.cssRules)) {\n if (rule instanceof CSSStyleRule) this.adopted.add(rule.selectorText.slice(1))\n }\n }\n}\n\nlet defaultRegistry: StyleRegistry | null = null\n\nexport const getStyleRegistry = (): StyleRegistry => {\n if (defaultRegistry !== null) return defaultRegistry\n defaultRegistry = new StyleRegistry(\n hasDOM()\n ? { shorthand: domSheet(SHORTHAND_STYLE_ID), longhand: domSheet(LONGHAND_STYLE_ID) }\n : { shorthand: null, longhand: null },\n )\n return defaultRegistry\n}\n\n// For tests, so each file starts with an empty registry.\nexport const resetStyleRegistry = (): void => {\n defaultRegistry = null\n if (!hasDOM()) return\n document.getElementById(SHORTHAND_STYLE_ID)?.remove()\n document.getElementById(LONGHAND_STYLE_ID)?.remove()\n}\n\nconst domSheet = (id: string): CSSStyleSheet => {\n let element = document.getElementById(id) as HTMLStyleElement | null\n if (element === null) {\n element = document.createElement('style')\n element.id = id\n document.head.appendChild(element)\n }\n return element.sheet as CSSStyleSheet\n}\n","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":";;AAQA,MAAM,gBACJ,OAAO,YAAY,cAAA,gBAAqC,YAAY,KAAK;AAE3E,MAAa,kBAA2B,QAAQ,MAAM;AAEtD,MAAa,wBAAiC,QAAQ,MAAM;AAE5D,MAAa,eACX,OAAO,WAAW,eAAe,OAAO,aAAa;AAEvD,MAAa,gBAAgB,UAC3B,OAAO,KAAK,OAAO,OAAO,eAAe,cAAc,OAAO,WAAW,KAAK,CAAC,CAAC;;ACdlF,MAAa,qBAAqB;AAClC,MAAa,oBAAoB;AAEjC,MAAM,sCAA2C,IAAI,IAAI;CACvD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,WAAW,SAAyB,KAAK,QAAQ,WAAW,MAAM,IAAI,EAAE,YAAY,GAAG;AAE7F,MAAM,QAAQ,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