@rootnative/web 0.0.0-alpha.0 → 0.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,26 @@ All notable changes to `@rootnative/web` are in this file. The format follows [K
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.0.0-alpha.1] - 2026-11-10
8
+
9
+ ### Added
10
+
11
+ - **Vite plugin** from `@rootnative/web/vite`. Add `rootnative()` to `plugins` in `vite.config.ts`. It needs Vite 8, an optional peer dependency. The plugin:
12
+ - resolves `react-native` to `@rootnative/web`,
13
+ - resolves `Button.web.tsx` before `Button.tsx`,
14
+ - defines `__DEV__`,
15
+ - puts `'web'` in place of each `Platform.OS` read, so the minifier drops the code of the other platforms.
16
+ - **`__DEV__`**, the React Native global: `true` in a development build, `false` in a production build. The Vite plugin defines it, also for pre-bundled dependencies, and the package types declare it.
17
+
18
+ ### Changed
19
+
20
+ - The package README and `llms.txt` set up an app with the Vite plugin.
21
+
22
+ ### Notes
23
+
24
+ - The hand-written `react-native` alias from `0.0.0-alpha.0` still works. To use the plugin, remove the alias and add `rootnative()`. [Vite plugin](https://rootnative.github.io/web/vite-plugin) also shows a setup without the plugin.
25
+ - In server rendering, a dependency that Vite leaves to Node gets no `__DEV__` and throws a `ReferenceError`. Add that dependency to `ssr.noExternal`.
26
+
7
27
  ## [0.0.0-alpha.0] - 2026-11-10
8
28
 
9
29
  The first alpha. It runs a React Native app in the browser with the components and APIs below. [Status](https://rootnative.github.io/web/status) lists what's planned and what's out of scope.
@@ -25,5 +45,6 @@ The first alpha. It runs a React Native app in the browser with the components a
25
45
  - There's no Vite plugin yet. Set the `react-native` alias by hand, as [Installation](https://rootnative.github.io/web/installation) shows.
26
46
  - The tests run in Chromium. Firefox and Safari aren't in the test run yet.
27
47
 
28
- [unreleased]: https://github.com/rootnative/web/compare/web@0.0.0-alpha.0...HEAD
48
+ [unreleased]: https://github.com/rootnative/web/compare/web@0.0.0-alpha.1...HEAD
49
+ [0.0.0-alpha.1]: https://github.com/rootnative/web/releases/tag/web@0.0.0-alpha.1
29
50
  [0.0.0-alpha.0]: https://github.com/rootnative/web/releases/tag/web@0.0.0-alpha.0
package/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # @rootnative/web
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/@rootnative/web.svg)](https://www.npmjs.com/package/@rootnative/web)
4
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/rootnative/web/blob/main/LICENSE)
5
+
3
6
  A standalone web runtime for React Native apps. You write `react-native`. It runs in the browser as a real web app, with semantic HTML, atomic CSS, server rendering, and SEO tags.
4
7
 
5
- > **Early alpha.** The API can change between releases. [Status](https://rootnative.github.io/web/status) lists what ships today.
8
+ > **Early alpha.** The API can change between releases. [Status](https://rootnative.github.io/web/status) lists what ships today, and the [changelog](https://github.com/rootnative/web/blob/main/packages/web/CHANGELOG.md) lists the changes in each release.
6
9
 
7
10
  **Docs: https://rootnative.github.io/web/**
8
11
 
@@ -12,17 +15,15 @@ A standalone web runtime for React Native apps. You write `react-native`. It run
12
15
  npm install @rootnative/web
13
16
  ```
14
17
 
15
- React 19 and React DOM 19 are peer dependencies. Point `react-native` at the package in `vite.config.ts`:
18
+ React 19 and React DOM 19 are peer dependencies. Add the Vite plugin to `vite.config.ts`. It resolves `react-native` to the package:
16
19
 
17
20
  ```ts
21
+ import { rootnative } from '@rootnative/web/vite'
18
22
  import react from '@vitejs/plugin-react'
19
23
  import { defineConfig } from 'vite'
20
24
 
21
25
  export default defineConfig({
22
- plugins: [react()],
23
- resolve: {
24
- alias: { 'react-native': '@rootnative/web' },
25
- },
26
+ plugins: [react(), rootnative()],
26
27
  })
27
28
  ```
28
29
 
@@ -1,10 +1,5 @@
1
+ import { t as hasDOM } from "./env-BQE0B2yw.js";
1
2
  import { createContext, useContext } from "react";
2
- // src/utils/env.ts
3
- const nodeEnv = () => typeof process !== "undefined" ? "development" : import.meta.env?.MODE;
4
- const isTestEnv = () => nodeEnv() === "test";
5
- const isProductionEnv = () => nodeEnv() === "production";
6
- const hasDOM = () => typeof window !== "undefined" && typeof document !== "undefined";
7
- const matchesMedia = (query) => hasDOM() && typeof window.matchMedia === "function" && window.matchMedia(query).matches;
8
3
  // src/style/registry.ts
9
4
  const SHORTHAND_STYLE_ID = "rootnative-style-shorthand";
10
5
  const LONGHAND_STYLE_ID = "rootnative-style-longhand";
@@ -124,6 +119,6 @@ const domSheet = (id) => {
124
119
  // src/style/StyleRegistryContext.ts
125
120
  const StyleRegistryContext = createContext(null);
126
121
  const useStyleRegistry = () => useContext(StyleRegistryContext) ?? getStyleRegistry();
127
- export { StyleRegistry as a, isProductionEnv as c, SHORTHAND_STYLE_ID as i, isTestEnv as l, useStyleRegistry as n, getStyleRegistry as o, LONGHAND_STYLE_ID as r, hasDOM as s, StyleRegistryContext as t, matchesMedia as u };
122
+ export { StyleRegistry as a, SHORTHAND_STYLE_ID as i, useStyleRegistry as n, getStyleRegistry as o, LONGHAND_STYLE_ID as r, StyleRegistryContext as t };
128
123
 
129
- //# sourceMappingURL=StyleRegistryContext-ButsUd8D.js.map
124
+ //# sourceMappingURL=StyleRegistryContext-D6yDrZk0.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StyleRegistryContext-D6yDrZk0.js","names":[],"sources":["../src/style/registry.ts","../src/style/StyleRegistryContext.ts"],"sourcesContent":["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":";;;AAKA,MAAa,qBAAqB;AAClC,MAAa,oBAAoB;AAEjC,MAAM,sCAA2C,IAAI,IAAI;CACvD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;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O;CACnC;CACA,OAAO,QAAQ;AACjB;;AChJA,MAAa,uBACX,cAAoC,IAAI;AAE1C,MAAa,yBACX,WAAW,oBAAoB,KAAK,iBAAiB"}
@@ -0,0 +1,9 @@
1
+ // src/utils/env.ts
2
+ const nodeEnv = () => typeof process !== "undefined" ? "development" : import.meta.env?.MODE;
3
+ const isTestEnv = () => nodeEnv() === "test";
4
+ const isProductionEnv = () => nodeEnv() === "production";
5
+ const hasDOM = () => typeof window !== "undefined" && typeof document !== "undefined";
6
+ const matchesMedia = (query) => hasDOM() && typeof window.matchMedia === "function" && window.matchMedia(query).matches;
7
+ export { matchesMedia as i, isProductionEnv as n, isTestEnv as r, hasDOM as t };
8
+
9
+ //# sourceMappingURL=env-BQE0B2yw.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-BQE0B2yw.js","names":[],"sources":["../src/utils/env.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"],"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"}
package/dist/index.d.ts CHANGED
@@ -871,5 +871,12 @@ export declare const TextInput: typeof TextInputComponent & {
871
871
  export declare function View(props: ViewProps): ReactElement;
872
872
  export declare function usePressability(config: PressabilityConfig): PressabilityEventHandlers;
873
873
  export declare function usePressability(config: PressabilityConfig | null | undefined): PressabilityEventHandlers | null;
874
+ declare global {
875
+ /**
876
+ * `true` in a development build and `false` in a production build, as in React Native. The
877
+ * bundler sets it: the plugin from `@rootnative/web/vite` does, or a `define` in your config.
878
+ */
879
+ const __DEV__: boolean;
880
+ }
874
881
  export type { AbsoluteFillStyle, AccessibilityAnnouncementFinishedEvent, AccessibilityChangeEvent, AccessibilityChangeEventName, AccessibilityEventSubscription, AccessibilityProps, AccessibilityState, AccessibilityValue, AppearanceListener, AppearancePreferences, BackHandlerSubscription, BackPressHandler, BlurEvent, CellRendererProps, ColorSchemeName, DOMEventHandlers, DimensionsChangeHandler, DimensionsValue, EmitterSubscription, EnterKeyHint, FlatListInstance, FlatListProps, FocusEvent, GestureResponderEvent, GestureResponderHandlers, I18nManagerConstants, ImageErrorEvent, ImageLoadEvent, ImageLoadEventData, ImageProgressEvent, ImageProps, ImageResizeMode, ImageResolvedAssetSource, ImageSize, ImageSource, ImageStatics, ImageURISource, InputMode, Insets, KeyboardType, LayoutChangeEvent, LayoutRectangle, ListRenderItem, ListRenderItemInfo, ListSeparatorComponent, ListSeparatorProps, ListSeparators, MouseEvent, NativeEventSubscription, NativeScrollEvent, NativeScrollPoint, NativeScrollRectangle, NativeScrollSize, NativeSyntheticEvent, NativeTouchEvent, PanResponderCallbacks, PanResponderGestureState, PanResponderInstance, PlatformOSType, PlatformSelectSpec, PlatformType, PressEvent, PressabilityConfig, PressabilityEventHandlers, PressableAndroidRippleConfig, PressableInstance, PressableProps, PressableStateCallbackType, ProcessedColorValue, ReturnKeyType, Role, ScaledSize, ScrollEvent, ScrollToIndexParams, ScrollToItemParams, ScrollToOffsetParams, ScrollToOptions, ScrollViewInstance, ScrollViewProps, StatusBarAnimation, StatusBarProps, StatusBarStatics, StatusBarStyle, StyleProp, SubmitBehavior, TextInputChangeEvent, TextInputChangeEventData, TextInputContentSizeChangeEvent, TextInputEndEditingEvent, TextInputFocusEvent, TextInputInstance, TextInputKeyPressEvent, TextInputProps, TextInputScrollEvent, TextInputSelection, TextInputSelectionChangeEvent, TextInputState, TextInputSubmitEditingEvent, TextProps, ViewProps, ViewToken, ViewabilityConfig, ViewabilityConfigCallbackPair, ViewabilityConfigCallbackPairs, ViewableItemsChangedInfo };
875
882
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
- import { c as isProductionEnv, l as isTestEnv, n as useStyleRegistry, o as getStyleRegistry, s as hasDOM, u as matchesMedia } from "./StyleRegistryContext-ButsUd8D.js";
1
+ import { i as matchesMedia, n as isProductionEnv, r as isTestEnv, t as hasDOM } from "./env-BQE0B2yw.js";
2
+ import { n as useStyleRegistry, o as getStyleRegistry } from "./StyleRegistryContext-D6yDrZk0.js";
2
3
  import normalizeColor from "@react-native/normalize-colors";
3
4
  import { Children, Fragment, cloneElement, createContext, createElement, isValidElement, memo, useCallback, useContext, useEffect, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
4
5
  import { jsx, jsxs } from "react/jsx-runtime";