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

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.
@@ -1,32 +0,0 @@
1
- import { t as CSSDeclarations } from "../types-BxTWbdj9.js";
2
- import { ReactElement, ReactNode } from "react";
3
- type StyleSheets = {
4
- shorthand: CSSStyleSheet | null;
5
- longhand: CSSStyleSheet | null;
6
- };
7
- export declare class StyleRegistry {
8
- private readonly classNames;
9
- private readonly adopted;
10
- private readonly shorthandRules;
11
- private readonly longhandRules;
12
- private readonly sheets;
13
- constructor(sheets?: StyleSheets);
14
- classFor(property: string, value: string): string;
15
- classesFor(declarations: CSSDeclarations): string;
16
- staticClass(className: string, rules: ReadonlyArray<string>): string;
17
- cssText(): {
18
- shorthand: string;
19
- longhand: string;
20
- };
21
- get ruleCount(): number;
22
- private adopt;
23
- }
24
- export declare const createStyleRegistry: () => StyleRegistry;
25
- export declare function StyleRegistryProvider(props: {
26
- registry: StyleRegistry;
27
- children?: ReactNode;
28
- }): ReactElement;
29
- export declare const renderStyleTags: (registry: StyleRegistry) => ReactElement;
30
- export declare const styleTagsHTML: (registry: StyleRegistry) => string;
31
- export {};
32
- //# sourceMappingURL=index.d.ts.map
@@ -1,25 +0,0 @@
1
- import { a as StyleRegistry, i as SHORTHAND_STYLE_ID, r as LONGHAND_STYLE_ID, t as StyleRegistryContext } from "../StyleRegistryContext-ButsUd8D.js";
2
- import { Fragment, createElement } from "react";
3
- // src/server/index.ts
4
- const createStyleRegistry = () => new StyleRegistry();
5
- function StyleRegistryProvider(props) {
6
- return createElement(StyleRegistryContext.Provider, { value: props.registry }, props.children);
7
- }
8
- const escapeCSS = (css) => css.replace(/<\//g, "<\\/");
9
- const renderStyleTags = (registry) => {
10
- const { shorthand, longhand } = registry.cssText();
11
- return createElement(Fragment, null, createElement("style", {
12
- id: SHORTHAND_STYLE_ID,
13
- dangerouslySetInnerHTML: { __html: escapeCSS(shorthand) }
14
- }), createElement("style", {
15
- id: LONGHAND_STYLE_ID,
16
- dangerouslySetInnerHTML: { __html: escapeCSS(longhand) }
17
- }));
18
- };
19
- const styleTagsHTML = (registry) => {
20
- const { shorthand, longhand } = registry.cssText();
21
- return `<style id="${SHORTHAND_STYLE_ID}">${escapeCSS(shorthand)}</style><style id="${LONGHAND_STYLE_ID}">${escapeCSS(longhand)}</style>`;
22
- };
23
- export { StyleRegistry, StyleRegistryProvider, createStyleRegistry, renderStyleTags, styleTagsHTML };
24
-
25
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/server/index.ts"],"sourcesContent":["import { createElement, Fragment, type ReactElement, type ReactNode } from 'react'\n\nimport { LONGHAND_STYLE_ID, SHORTHAND_STYLE_ID, StyleRegistry } from '../style/registry'\nimport { StyleRegistryContext } from '../style/StyleRegistryContext'\n\nexport { StyleRegistry } from '../style/registry'\n\n// One registry per request, so concurrent renders never share CSS.\nexport const createStyleRegistry = (): StyleRegistry => new StyleRegistry()\n\nexport function StyleRegistryProvider(props: {\n registry: StyleRegistry\n children?: ReactNode\n}): ReactElement {\n return createElement(StyleRegistryContext.Provider, { value: props.registry }, props.children)\n}\n\n// A closing tag inside CSS text would end the style element early.\nconst escapeCSS = (css: string): string => css.replace(/<\\//g, '<\\\\/')\n\n// The two style elements the client adopts on hydration. Render them in <head>.\nexport const renderStyleTags = (registry: StyleRegistry): ReactElement => {\n const { shorthand, longhand } = registry.cssText()\n return createElement(\n Fragment,\n null,\n createElement('style', {\n id: SHORTHAND_STYLE_ID,\n dangerouslySetInnerHTML: { __html: escapeCSS(shorthand) },\n }),\n createElement('style', {\n id: LONGHAND_STYLE_ID,\n dangerouslySetInnerHTML: { __html: escapeCSS(longhand) },\n }),\n )\n}\n\n// The same two elements as an HTML string, for a template.\nexport const styleTagsHTML = (registry: StyleRegistry): string => {\n const { shorthand, longhand } = registry.cssText()\n return (\n `<style id=\"${SHORTHAND_STYLE_ID}\">${escapeCSS(shorthand)}</style>` +\n `<style id=\"${LONGHAND_STYLE_ID}\">${escapeCSS(longhand)}</style>`\n )\n}\n"],"mappings":";;;AAQA,MAAa,4BAA2C,IAAI,cAAc;AAE1E,SAAgB,sBAAsB,OAGrB;CACf,OAAO,cAAc,qBAAqB,UAAU,EAAE,OAAO,MAAM,SAAS,GAAG,MAAM,QAAQ;AAC/F;AAGA,MAAM,aAAa,QAAwB,IAAI,QAAQ,QAAQ,MAAM;AAGrE,MAAa,mBAAmB,aAA0C;CACxE,MAAM,EAAE,WAAW,aAAa,SAAS,QAAQ;CACjD,OAAO,cACL,UACA,MACA,cAAc,SAAS;EACrB,IAAI;EACJ,yBAAyB,EAAE,QAAQ,UAAU,SAAS,EAAE;CAC1D,CAAC,GACD,cAAc,SAAS;EACrB,IAAI;EACJ,yBAAyB,EAAE,QAAQ,UAAU,QAAQ,EAAE;CACzD,CAAC,CACH;AACF;AAGA,MAAa,iBAAiB,aAAoC;CAChE,MAAM,EAAE,WAAW,aAAa,SAAS,QAAQ;CACjD,OACE,cAAc,mBAAmB,IAAI,UAAU,SAAS,EAAE,qBAC5C,kBAAkB,IAAI,UAAU,QAAQ,EAAE;AAE5D"}
@@ -1,5 +0,0 @@
1
- type FlatStyle = Readonly<Record<string, unknown>>;
2
- type StyleProp<T> = T | ReadonlyArray<StyleProp<T>> | null | undefined | false | "";
3
- type CSSDeclarations = Record<string, string>;
4
- export { FlatStyle as n, StyleProp as r, CSSDeclarations as t };
5
- //# sourceMappingURL=types-BxTWbdj9.d.ts.map
package/llms.txt DELETED
@@ -1,328 +0,0 @@
1
- # @rootnative/web
2
-
3
- > A standalone web runtime for React Native apps. The app imports
4
- > react-native, a bundler alias maps that name to @rootnative/web, and the app
5
- > runs in the browser as a real web app: semantic HTML, atomic CSS, server
6
- > rendering, and SEO tags. It doesn't use react-native-web.
7
-
8
- Status: early alpha. The API can change between releases. Every component and
9
- API has tests that run in a real Chromium browser. Firefox and Safari aren't in
10
- the test run yet.
11
-
12
- Docs: https://rootnative.github.io/web/
13
- Full: https://rootnative.github.io/web/llms-full.txt
14
- Source: https://github.com/rootnative/web
15
-
16
- ## Install
17
-
18
- npm install @rootnative/web
19
-
20
- Peers: react ^19.0.0, react-dom ^19.0.0. ESM only.
21
-
22
- 1. Alias react-native in vite.config.ts:
23
- resolve: { alias: { 'react-native': '@rootnative/web' } }
24
- Server code needs the same alias.
25
- 2. Add src/react-native.d.ts (in a folder that tsconfig.json includes):
26
- declare module 'react-native' { export * from '@rootnative/web' }
27
- The file must have no top-level import or export line. With one,
28
- TypeScript reports "Cannot find module 'react-native'". Don't map the name
29
- with tsconfig "paths": the package has no main or types field.
30
- 3. Give the page a full-height flex root:
31
- html, body, #root { height: 100%; margin: 0 }
32
- #root { display: flex; flex-direction: column }
33
- Then createRoot(document.getElementById('root')!).render(<App />).
34
- flex: 1 on the root View fills the window, as on iOS and Android.
35
-
36
- Browsers: Chrome 95, Edge 95, Firefox 93, Safari 15.1, iOS Safari 15.1.
37
-
38
- ## Entry points
39
-
40
- - @rootnative/web: the React Native components and APIs. Import it as
41
- react-native through the alias.
42
- - @rootnative/web/dom: web-only features. Head.
43
- - @rootnative/web/server: createStyleRegistry, StyleRegistryProvider,
44
- renderStyleTags, styleTagsHTML, StyleRegistry.
45
-
46
- Import /dom and /server only in code that runs on the web.
47
-
48
- ## What ships
49
-
50
- Components: View, Text, Image, Pressable, ScrollView, FlatList, TextInput,
51
- StatusBar.
52
-
53
- APIs: StyleSheet, Platform, Dimensions, useWindowDimensions, Appearance,
54
- useColorScheme, AccessibilityInfo, I18nManager, BackHandler, PixelRatio,
55
- processColor, PanResponder, usePressability.
56
-
57
- NOT IMPLEMENTED, do not import:
58
- - Button, ActivityIndicator, Switch, RefreshControl, Modal, TouchableOpacity,
59
- TouchableHighlight, TouchableWithoutFeedback, TouchableNativeFeedback.
60
- - Alert, AppState, Linking, Share, Vibration, Clipboard.
61
- - SectionList, VirtualizedList, Animated, LayoutAnimation.
62
- - onPressIn, onPressOut, onLongPress on Text. onPress on Text works.
63
- - A Vite plugin. Set the alias by hand.
64
-
65
- Out of scope: Expo, Metro, React 18, CommonJS, Flow.
66
-
67
- A component ref is the DOM element. View has no measure, measureInWindow,
68
- measureLayout, or setNativeProps: use onLayout or getBoundingClientRect().
69
- ScrollView, FlatList, and TextInput add the methods listed below.
70
-
71
- ## Semantic HTML
72
-
73
- The role prop picks the element:
74
- - article, figure, form, main: the element of the same name.
75
- - banner: header. complementary: aside. contentinfo: footer.
76
- navigation: nav. list: ul. listitem: li.
77
- - button: <button type="button">, so it never submits a form.
78
- - heading: h1 to h6 from aria-level. The default level is 2.
79
- - link with href: a.
80
- - separator: hr. With children: a div with the role.
81
- - Any other role, and the table roles: the default element (div for View,
82
- span for Text) with a role attribute.
83
-
84
- href on a View or a Text renders an <a> (web only). On Text, target, rel,
85
- download, and lang pass to the element (web only).
86
-
87
- accessibilityRole works. role wins when both are set. Old names map: header to
88
- heading, image to img, imagebutton to button, summary to region, adjustable to
89
- slider, search to searchbox, text and keyboardkey to none.
90
-
91
- Accessibility props become ARIA attributes: accessibilityLabel is aria-label,
92
- accessibilityHint is aria-description, accessibilityLiveRegion is aria-live,
93
- accessibilityState and accessibilityValue are aria-* states,
94
- accessibilityViewIsModal is aria-modal, accessibilityElementsHidden is
95
- aria-hidden. nativeID is id. testID is data-testid. focusable is tabIndex 0,
96
- or -1 for false. tabIndex wins.
97
-
98
- aria-* and data-* props pass through. An aria-* prop wins over the mapped
99
- prop. DOM event handlers (onClick, onKeyDown, ...) pass to the element (web
100
- only). Any other prop that isn't a React Native prop is dropped.
101
-
102
- ## Styles
103
-
104
- - StyleSheet.create freezes the objects, and a frozen style compiles to atomic
105
- CSS once. An inline style object compiles again on each render.
106
- - View defaults: display flex, flexDirection column, alignItems stretch,
107
- flexShrink 0, position relative, border box. Text defaults: 14 px, black,
108
- system font, spaces and line breaks kept.
109
- - Numbers get px, lineHeight too. flex, flexGrow, flexShrink, opacity, zIndex,
110
- aspectRatio, and fontWeight stay unitless. Strings pass through.
111
- - Colors use the React Native parser. A color it can't parse is dropped.
112
- - flex: 1 is 1 1 0%. flex: 0 is 0 0 auto. flex: -1 is 0 1 auto.
113
- - A longhand wins over a shorthand, whatever the key order.
114
- - Start and end props (marginStart, paddingEnd, start, end, borderStartWidth,
115
- borderTopStartRadius, ...) become logical CSS and flip in right-to-left.
116
- - marginLeft, paddingLeft, left, and their right partners stay physical in a
117
- right-to-left layout. Native swaps them by default. Use start and end props
118
- for anything that must follow the direction.
119
- - transform, boxShadow, and filter take the React Native array or a CSS
120
- string. shadow* props become box-shadow when boxShadow isn't set.
121
- textShadow* props become text-shadow.
122
- - fontFamily 'System' is the browser's system font stack. Named font weights
123
- become numbers.
124
- - elevation, borderCurve, includeFontPadding, overlayColor: no web effect.
125
-
126
- ## Components
127
-
128
- View
129
- - onLayout comes from a ResizeObserver. It fires after mount and after each
130
- size change. A move with no size change doesn't fire it.
131
- - pointerEvents: none, auto, box-none, box-only.
132
-
133
- Text
134
- - numberOfLines 1 ends the line with an ellipsis. A larger number clamps.
135
- - ellipsizeMode: tail and clip. head and middle show the ellipsis at the end.
136
- - selectable is true by default on the web (false on native).
137
- - onPress gets the DOM click event. onClick runs first, and preventDefault()
138
- in it stops onPress. disabled sets aria-disabled and stops onPress.
139
- - A Text with onPress is a span that a keyboard can't focus. Use href to go to
140
- a page, or wrap it in a Pressable with role="button" for an action.
141
-
142
- Image
143
- - Renders a div box with an <img> inside. The style sizes the box. With no
144
- size in the style or the source, it's 0 x 0, as on native.
145
- - source: { uri }; an array with scale (srcset x) or width (srcset w);
146
- { uri, headers } with method and body (loads with fetch); a URL string from
147
- a bundler import (web only). A number from require() loads nothing and
148
- warns once.
149
- - resizeMode: cover (default), contain, stretch, center, repeat.
150
- - tintColor, blurRadius, defaultSource work. onProgress never fires.
151
- - loading, fetchPriority, decoding: web only, passed to the <img>.
152
- - Statics: getSize (rejects on the server), getSizeWithHeaders, prefetch
153
- (resolves true), queryCache (resolves {}), resolveAssetSource (null for a
154
- number).
155
-
156
- Pressable
157
- - role="button" renders <button type="button">. Without a role, a focusable
158
- div. Give an action role="button".
159
- - style and children can be functions of { pressed, hovered, focused }.
160
- hovered (web only) is a mouse or pen, never touch. focused (web only) is
161
- keyboard focus.
162
- - Mouse, pen, touch: primary button only. Keyboard: Enter or Space.
163
- - onLongPress after delayLongPress, 500 ms by default. A press shows at least
164
- 130 ms, as on native.
165
- - onPress gets the pointer up event, or the click event for a keyboard or
166
- assistive technology press. preventDefault() on it cancels the click.
167
- - hitSlop grows the hit area with a ::before box. A parent with overflow
168
- hidden clips it.
169
- - pressRetentionOffset defaults to 20 on three sides and 30 at the bottom.
170
- - cancelable={false} sets touch-action: none.
171
- - disabled sets aria-disabled, leaves the tab order, and stops every press.
172
- - android_ripple, android_disableSound, blockNativeResponder: ignored.
173
-
174
- ScrollView
175
- - Scrolls its own box, not the document. On a phone, the browser's address
176
- bar doesn't hide as it scrolls.
177
- - onScroll: one event per frame. nativeEvent has contentOffset, contentSize,
178
- layoutMeasurement. No velocity. scrollEventThrottle isn't needed.
179
- - A scroll while a pointer is down is a drag. A scroll after the release, or
180
- with no pointer (wheel, keyboard, scrollTo), is momentum. The scroll ends at
181
- scrollend, or 150 ms after the last scroll event.
182
- - scrollEnabled={false} hides the overflow.
183
- - snapToInterval, snapToOffsets, pagingEnabled snap after the scroll settles.
184
- - stickyHeaderIndices: vertical only. keyboardDismissMode: on-drag works.
185
- - refreshControl wraps the scroller. RefreshControl isn't in the package, so
186
- pass your own component.
187
- - Ref: the scroll element plus scrollTo({ x, y, animated }) (animated defaults
188
- to true), scrollToEnd({ animated }), getScrollableNode(),
189
- getInnerViewNode(). flashScrollIndicators() does nothing.
190
- - scrollTo(y, x), the old positional form, doesn't work: the DOM
191
- scrollTo(x, y) takes the arguments in the other order.
192
- - Native-only props (bounces, decelerationRate, contentInset, the zoom props,
193
- ...) are ignored.
194
-
195
- FlatList
196
- - NO VIRTUALIZER. It renders every item. Load a long list in pages with
197
- onEndReached.
198
- - Ignored: initialNumToRender, maxToRenderPerBatch, windowSize,
199
- updateCellsBatchingPeriod, removeClippedSubviews, disableVirtualization,
200
- extraData, getItemLayout.
201
- - Works as on native: data, renderItem, keyExtractor, ItemSeparatorComponent,
202
- ListHeaderComponent, ListFooterComponent, ListEmptyComponent, numColumns,
203
- columnWrapperStyle, horizontal, inverted, initialScrollIndex,
204
- onViewableItemsChanged, viewabilityConfig, viewabilityConfigCallbackPairs,
205
- onStartReached, CellRendererComponent, renderScrollComponent,
206
- stickyHeaderIndices, and the ScrollView props.
207
- - onEndReached fires once per content length. The default threshold is 2 px.
208
- A list shorter than its viewport fires it after mount.
209
- - onRefresh and refreshing show no indicator. Pass refreshControl instead.
210
- - Ref: scrollToOffset, scrollToIndex (a row index with numColumns),
211
- scrollToItem, scrollToEnd, recordInteraction, getScrollableNode.
212
- onScrollToIndexFailed never fires.
213
-
214
- TextInput
215
- - An <input type="text">, or a <textarea> with multiline. No border, padding,
216
- or background, as on iOS.
217
- - multiline grows with the text. numberOfLines is the minimum row count.
218
- - Enter in a single-line field calls onSubmitEditing, then blurs. Inside a
219
- <form>, the form submits too. In a multiline field, Enter adds a line unless
220
- submitBehavior is submit or blurAndSubmit. Shift+Enter always adds a line.
221
- - keyboardType becomes inputmode, and the type stays text, so the browser adds
222
- no validation. returnKeyType becomes enterkeyhint. secureTextEntry is
223
- type="password". showSoftInputOnFocus={false} is inputmode="none".
224
- - editable={false} is readonly, not disabled.
225
- - autoComplete and textContentType use the HTML tokens. React Native-only
226
- values map (name-given to given-name, sms-otp to one-time-code).
227
- - A value with no change handler stays fixed, with no React warning.
228
- - Ref: the element plus clear(), isFocused(), getNativeRef(),
229
- setNativeProps({ text }). TextInput.State has currentlyFocusedInput(),
230
- focusTextInput(element), blurTextInput(element).
231
-
232
- StatusBar
233
- - backgroundColor writes <meta name="theme-color"> in the browser, after
234
- mount, so the server HTML doesn't have it. The last mounted StatusBar wins.
235
- - barStyle, hidden, translucent: no web effect. StatusBar.currentHeight is
236
- null.
237
- - Head themeColor writes the same tag. Use one of the two.
238
-
239
- ## APIs
240
-
241
- - Platform: OS is 'web'. select() uses web, then default. A native key
242
- doesn't apply. Version is the user agent ('' on the server).
243
- constants.reactNativeVersion is 0.88.1. isTV is false. isTesting is true when
244
- NODE_ENV is test. isDisableAnimations follows prefers-reduced-motion.
245
- - StyleSheet: create, flatten, compose, absoluteFill, absoluteFillObject.
246
- hairlineWidth is 1.
247
- - Dimensions: window is innerWidth and innerHeight. screen is the display.
248
- scale is devicePixelRatio. fontScale is the root font size divided by 16.
249
- get('window' | 'screen'). addEventListener('change', fn) returns
250
- { remove() }.
251
- - Appearance: getColorScheme() returns the override, else
252
- prefers-color-scheme. setColorScheme('light' | 'dark') overrides it for the
253
- app and sets color-scheme on <html>. null or 'unspecified' clears it.
254
- addChangeListener(fn) returns { remove() }.
255
- - AccessibilityInfo: reduce motion, reduce transparency, invert colors, and
256
- high contrast read live media queries, with change events.
257
- isScreenReaderEnabled, isAccessibilityServiceEnabled, isBoldTextEnabled, and
258
- isGrayscaleEnabled are ALWAYS false on the web. Don't gate a feature on them.
259
- announceForAccessibility writes to an aria-live="polite" region;
260
- announceForAccessibilityWithOptions with { queue: false } uses assertive.
261
- setAccessibilityFocus takes the element, not a node handle. Give a View
262
- tabIndex={-1} so that it can take focus.
263
- - I18nManager: isRTL reads the dir of <html> each time. forceRTL sets dir on
264
- <html> at once. allowRTL(false) changes only what isRTL reports.
265
- swapLeftAndRightInRTL stores the flag and has no effect on styles. isRTL is
266
- false on the server.
267
- - BackHandler: listeners register and never fire. exitApp() does nothing. Use
268
- the history API of your router.
269
- - PixelRatio: get() is devicePixelRatio. getFontScale() is the root font size
270
- divided by 16. Both are 1 on the server. getPixelSizeForLayoutSize and
271
- roundToNearestPixel work.
272
- - processColor: an unsigned 32-bit ARGB integer, as on iOS. null for a color
273
- it can't parse.
274
- - PanResponder: runs on pointer events. panHandlers are six pointer handlers;
275
- spread them on a View. Set touchAction: 'none' in the style (or 'pan-y' for
276
- a horizontal drag in a vertical scroll), or the browser scrolls instead.
277
- The element captures the pointer at the grant. Negotiation works as on
278
- native. dx and dy are CSS pixels; vx and vy are pixels per millisecond.
279
- onShouldBlockNativeResponder is ignored. getInteractionHandle() is null.
280
- - usePressability(config): returns pointer, keyboard, and focus handlers, not
281
- the native responder handlers. Spread them on a View. Memoize the config.
282
- A null config returns null. hitSlop doesn't grow the hit area. Set
283
- touchAction yourself for cancelable={false}.
284
-
285
- ## Server rendering
286
-
287
- Render the whole <html> document with React, not only the app:
288
-
289
- const registry = createStyleRegistry()
290
- const html = renderToString(
291
- <html lang="en">
292
- <head>...</head>
293
- <body>
294
- <div id="root">
295
- <StyleRegistryProvider registry={registry}><App /></StyleRegistryProvider>
296
- </div>
297
- <script type="module" src="/client.js" />
298
- </body>
299
- </html>,
300
- )
301
- const page = `<!doctype html>${html.replace('</head>', `${styleTagsHTML(registry)}</head>`)}`
302
-
303
- - One registry per request.
304
- - Write the style tags after the render ends.
305
- - Render <head> with React, so the tags of Head land in it. Pasted into a
306
- template, they land at the start of <body>.
307
- - renderStyleTags(registry) returns the same two <style> elements as React
308
- elements.
309
- - The client calls hydrateRoot(root, <App />) with no provider. It adopts the
310
- server's <style> elements, so it inserts no rule twice.
311
-
312
- On the server and during hydration, useWindowDimensions() returns
313
- { width: 0, height: 0, scale: 1, fontScale: 1 } and useColorScheme() returns
314
- 'light'. The real values arrive after hydration. Dimensions.get() and
315
- Appearance.getColorScheme() return the real value in the browser at once, so
316
- don't read them in render: the first render won't match the server HTML.
317
-
318
- ## Head
319
-
320
- import { Head } from '@rootnative/web/dom'
321
-
322
- Props: title, description, canonical, robots, themeColor, openGraph (title,
323
- description, image, url, type, siteName), jsonLd (one schema.org object or an
324
- array), children (extra meta, link, and title elements).
325
-
326
- - Use one Head per page. React doesn't merge two.
327
- - Its tags go away when it unmounts.
328
- - The JSON-LD script stays in the body. A < in the data is escaped.