@rootnative/web 0.0.0-alpha.2 → 0.0.0-alpha.3

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/llms.txt CHANGED
@@ -22,9 +22,17 @@ Peers: react ^19.0.0, react-dom ^19.0.0. ESM only.
22
22
  1. Add the Vite plugin (Vite 8) to vite.config.ts:
23
23
  import { rootnative } from '@rootnative/web/vite'
24
24
  plugins: [react(), rootnative()]
25
+ With Reanimated, or a library built on it: rootnative({ worklets: true }).
26
+ It runs the Babel plugin of react-native-worklets on the app code and the
27
+ libraries. The app needs react-native-worklets and @babel/core.
25
28
  It resolves react-native to @rootnative/web (the exact name only), resolves
26
29
  .web.* files first, defines __DEV__ (true on the dev server, false in a
27
30
  production build, from NODE_ENV), and puts 'web' in place of Platform.OS.
31
+ It also defines global as globalThis, resolves
32
+ @react-native/assets-registry/registry to @rootnative/web/assets-registry,
33
+ resolves the two react-native-web style files that Reanimated 4 imports to
34
+ @rootnative/web/style, and gives pre-bundled dependencies the .web.*
35
+ extensions.
28
36
  An alias or a __DEV__ define in your own config wins.
29
37
  2. Add src/react-native.d.ts (in a folder that tsconfig.json includes):
30
38
  declare module 'react-native' { export * from '@rootnative/web' }
@@ -43,9 +51,11 @@ Browsers: Chrome 95, Edge 95, Firefox 93, Safari 15.1, iOS Safari 15.1.
43
51
 
44
52
  Without the plugin (another bundler): alias the exact name react-native to
45
53
  @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.
54
+ __DEV__ and global (as globalThis). In Vite, set the defines in define and in
55
+ optimizeDeps.rolldownOptions.transform.define, and the extensions in
56
+ resolve.extensions and optimizeDeps.rolldownOptions.resolve.extensions: the
57
+ dependency optimizer has its own. Add the compat aliases that a library
58
+ needs. Platform.OS then stays a read at run time.
49
59
 
50
60
  Server rendering with Vite: the plugin applies to app code on the server. A
51
61
  dependency that Vite leaves to Node gets no __DEV__ and throws a
@@ -60,29 +70,45 @@ ReferenceError. Add it to ssr.noExternal.
60
70
  renderStyleTags, styleTagsHTML, StyleRegistry.
61
71
  - @rootnative/web/vite: rootnative(), the Vite plugin. Only in vite.config.ts.
62
72
 
73
+ Libraries: react-native-svg, react-native-safe-area-context, and
74
+ @react-native-async-storage/async-storage need nothing more. Reanimated and
75
+ libraries on it need rootnative({ worklets: true }). An icon set of
76
+ @react-native-vector-icons needs its font from the app: import the .ttf of
77
+ the package with ?url, then document.fonts.add(new FontFace(name, url)).
78
+ Set skipLibCheck: true, because the type files of a native library import
79
+ the real react-native types.
80
+
63
81
  Import /dom and /server only in code that runs on the web.
64
82
 
65
83
  ## What ships
66
84
 
67
85
  Components: View, Text, Image, Pressable, TouchableHighlight,
68
86
  TouchableNativeFeedback, TouchableOpacity, TouchableWithoutFeedback, Button,
69
- ScrollView, FlatList, TextInput, Switch, ActivityIndicator, StatusBar.
87
+ ScrollView, FlatList, RefreshControl, TextInput, Switch, ActivityIndicator,
88
+ Modal, KeyboardAvoidingView, StatusBar.
70
89
 
71
90
  APIs: StyleSheet, Platform, Dimensions, useWindowDimensions, Appearance,
72
- useColorScheme, AccessibilityInfo, I18nManager, BackHandler, PixelRatio,
73
- processColor, PanResponder, usePressability.
91
+ useColorScheme, AppState, Keyboard, Linking, Alert, Share, Vibration, Clipboard,
92
+ AccessibilityInfo, I18nManager, BackHandler, PixelRatio, processColor,
93
+ PanResponder, usePressability.
94
+
95
+ Compat, for libraries only, do not call in app code: unstable_createElement,
96
+ findNodeHandle, TurboModuleRegistry.
74
97
 
75
98
  NOT IMPLEMENTED, do not import:
76
- - RefreshControl, Modal.
77
- - Alert, AppState, Linking, Share, Vibration, Clipboard.
78
99
  - SectionList, VirtualizedList, Animated, LayoutAnimation.
79
100
  - A Next.js plugin, and templates for a Vite app with and without server
80
101
  rendering.
81
102
 
82
103
  Out of scope: Expo, Metro, React 18, CommonJS, Flow.
83
104
 
84
- A component ref is the DOM element. View has no measure, measureInWindow,
85
- measureLayout, or setNativeProps: use onLayout or getBoundingClientRect().
105
+ A component ref is the DOM element, typed HostInstance (ViewInstance,
106
+ TextInstance, ImageInstance, PressableInstance). It has measure(callback),
107
+ measureInWindow(callback), measureLayout(ancestor, onSuccess, onFail), and
108
+ setNativeProps({ style }). Each one calls its callback at once, with CSS
109
+ pixels from getBoundingClientRect(). The window is the visible area.
110
+ setNativeProps writes an inline style, and any other prop has no effect.
111
+ Type a ref as useRef<ViewInstance>(null), not useRef<HTMLElement>(null).
86
112
  ScrollView, FlatList, and TextInput add the methods listed below.
87
113
 
88
114
  ## Semantic HTML
@@ -127,18 +153,27 @@ only). Any other prop that isn't a React Native prop is dropped.
127
153
  aspectRatio, and fontWeight stay unitless. Strings pass through.
128
154
  - Colors use the React Native parser. A color it can't parse is dropped.
129
155
  - flex: 1 is 1 1 0%. flex: 0 is 0 0 auto. flex: -1 is 0 1 auto.
130
- - A longhand wins over a shorthand, whatever the key order.
156
+ - Any style wins over a default (flex: 1 beats the default flexShrink 0). A
157
+ longhand wins over a shorthand, whatever the key order.
131
158
  - Start and end props (marginStart, paddingEnd, start, end, borderStartWidth,
132
159
  borderTopStartRadius, ...) become logical CSS and flip in right-to-left.
133
- - marginLeft, paddingLeft, left, and their right partners stay physical in a
134
- right-to-left layout. Native swaps them by default. Use start and end props
135
- for anything that must follow the direction.
160
+ - marginLeft, paddingLeft, left, the left and right borders and corners, and
161
+ their right partners swap sides in a right-to-left layout, as on native.
162
+ They compile to logical CSS. I18nManager.swapLeftAndRightInRTL(false)
163
+ before the first render keeps them physical. A start or end style wins
164
+ over a left or right style of the same side.
136
165
  - transform, boxShadow, and filter take the React Native array or a CSS
137
166
  string. shadow* props become box-shadow when boxShadow isn't set.
138
167
  textShadow* props become text-shadow.
139
168
  - fontFamily 'System' is the browser's system font stack. Named font weights
140
169
  become numbers.
141
170
  - elevation, borderCurve, includeFontPadding, overlayColor: no web effect.
171
+ - Types: the style props take React Native 0.88's ViewStyle, TextStyle, and
172
+ ImageStyle, and StyleSheet.create checks each key and value. touchAction is
173
+ the one web-only key. transform takes no Animated value, and resizeMode has
174
+ no 'none' yet. Any other CSS property passes through at runtime but needs a
175
+ cast: { transition: '...' } as ViewStyle, or as unknown as ViewStyle for a
176
+ value that React Native's type doesn't allow.
142
177
 
143
178
  ## Components
144
179
 
@@ -187,6 +222,9 @@ Pressable
187
222
  130 ms, as on native.
188
223
  - onPress gets the pointer up event, or the click event for a keyboard or
189
224
  assistive technology press. preventDefault() on it cancels the click.
225
+ - The click that follows a tap stops when it lands outside the pressed
226
+ element, for example on a modal that the press opened. A click on the
227
+ pressed element goes through.
190
228
  - hitSlop grows the hit area with a ::before box. A parent with overflow
191
229
  hidden clips it.
192
230
  - pressRetentionOffset defaults to 20 on three sides and 30 at the bottom.
@@ -261,8 +299,9 @@ ScrollView
261
299
  - scrollEnabled={false} hides the overflow.
262
300
  - snapToInterval, snapToOffsets, pagingEnabled snap after the scroll settles.
263
301
  - stickyHeaderIndices: vertical only. keyboardDismissMode: on-drag works.
264
- - refreshControl wraps the scroller. RefreshControl isn't in the package, so
265
- pass your own component.
302
+ - refreshControl wraps the scroller and gets the style props that place the
303
+ box (margins, flex, sizes, position, transform, gaps), as on Android. The
304
+ scroller fills it and keeps the rest of the style.
266
305
  - Ref: the scroll element plus scrollTo({ x, y, animated }) (animated defaults
267
306
  to true), scrollToEnd({ animated }), getScrollableNode(),
268
307
  getInnerViewNode(). flashScrollIndicators() does nothing.
@@ -271,6 +310,22 @@ ScrollView
271
310
  - Native-only props (bounces, decelerationRate, contentInset, the zoom props,
272
311
  ...) are ignored.
273
312
 
313
+ RefreshControl
314
+ - Pass it to ScrollView as refreshControl, or give FlatList onRefresh and
315
+ refreshing. Pull to refresh with TOUCH ONLY: mouse, pen, and keyboard have
316
+ no pull, so add a refresh button too.
317
+ - A pull starts at the top of the list when the finger first moves down. The
318
+ indicator moves half the finger distance. A release after 128 px of finger
319
+ calls onRefresh. onRefresh must set refreshing to true at once, or the
320
+ indicator goes back. No pull while refreshing or with enabled={false}.
321
+ - In a flipped scroller (an inverted FlatList), the indicator sits at the
322
+ bottom and the pull goes up, as on native.
323
+ - Android's look: an arc on a white disc (40 px, size="large" 56 px), at rest
324
+ 64 px under progressViewOffset minus the disc. colors[0], else tintColor,
325
+ else black, is the arc. progressBackgroundColor is the disc.
326
+ - title is the accessible name; no visible text. titleColor: no effect.
327
+ - View props and the ref go to the wrapper, which has aria-busy.
328
+
274
329
  FlatList
275
330
  - NO VIRTUALIZER. It renders every item. Load a long list in pages with
276
331
  onEndReached.
@@ -285,7 +340,10 @@ FlatList
285
340
  stickyHeaderIndices, and the ScrollView props.
286
341
  - onEndReached fires once per content length. The default threshold is 2 px.
287
342
  A list shorter than its viewport fires it after mount.
288
- - onRefresh and refreshing show no indicator. Pass refreshControl instead.
343
+ - onRefresh and refreshing wrap the scroller in a RefreshControl, with
344
+ progressViewOffset, as on native. With onRefresh, refreshing must be a
345
+ boolean, or the list throws. A refreshControl prop wins.
346
+ renderScrollComponent gets the three props and adds its own control.
289
347
  - Ref: scrollToOffset, scrollToIndex (a row index with numColumns),
290
348
  scrollToItem, scrollToEnd, recordInteraction, getScrollableNode.
291
349
  onScrollToIndexFailed never fires.
@@ -305,7 +363,7 @@ TextInput
305
363
  values map (name-given to given-name, sms-otp to one-time-code).
306
364
  - A value with no change handler stays fixed, with no React warning.
307
365
  - Ref: the element plus clear(), isFocused(), getNativeRef(),
308
- setNativeProps({ text }). TextInput.State has currentlyFocusedInput(),
366
+ setNativeProps({ text, style }). TextInput.State has currentlyFocusedInput(),
309
367
  focusTextInput(element), blurTextInput(element).
310
368
 
311
369
  Switch
@@ -335,6 +393,35 @@ ActivityIndicator
335
393
  centers the indicator. The ref and the other props go to the indicator.
336
394
  - It turns also with prefers-reduced-motion.
337
395
 
396
+ Modal
397
+ - A <dialog> opened with showModal(), in a portal on <body>: the top layer,
398
+ above every zIndex. The rest of the page is inert and doesn't scroll.
399
+ - visible decides (default true). Escape, and the back gesture of Chrome on
400
+ Android, call onRequestClose: hide the modal there. While visible is true,
401
+ the modal stays open.
402
+ - onShow fires once per show, when the enter animation ends. onDismiss fires
403
+ after visible becomes false and the exit animation ends, not on unmount.
404
+ - The focus moves into the modal (the first control, or the dialog itself),
405
+ and back to the opener when it hides.
406
+ - The modal stays in place when the keyboard opens: it undoes the move of the
407
+ page that Safari on iOS makes for a focused field. Use a
408
+ KeyboardAvoidingView inside it.
409
+ - A press inside doesn't reach a Pressable around the Modal. A nested modal
410
+ goes on top, and Escape closes the top one first.
411
+ - The children go in a box that fills the viewport: white, backdropColor, or
412
+ clear with transparent. style goes to the box. ref and modalRef are the
413
+ <dialog>. testID, aria props, and DOM handlers go to the <dialog>.
414
+ - Renders nothing on the server. It shows after hydration.
415
+ - animationType: slide (up from the bottom) or fade, 200 ms with the curves
416
+ of the Android modal; none (default) is instant. The modal stays until its
417
+ exit animation ends and takes no presses then; a nested modal closes at
418
+ once. Reduced motion: instant.
419
+ - presentationStyle, supportedOrientations, onOrientationChange,
420
+ allowSwipeDismissal, hardwareAccelerated, statusBarTranslucent,
421
+ navigationBarTranslucent: ignored.
422
+ - Firefox before 98 and Safari before 15.4 have no showModal(): a fixed box
423
+ on top, Escape works, the page isn't inert.
424
+
338
425
  StatusBar
339
426
  - backgroundColor writes <meta name="theme-color"> in the browser, after
340
427
  mount, so the server HTML doesn't have it. The last mounted StatusBar wins.
@@ -360,6 +447,62 @@ StatusBar
360
447
  prefers-color-scheme. setColorScheme('light' | 'dark') overrides it for the
361
448
  app and sets color-scheme on <html>. null or 'unspecified' clears it.
362
449
  addChangeListener(fn) returns { remove() }.
450
+ - AppState: currentState is 'active' while the page is visible, else
451
+ 'background' ('active' on the server). No 'inactive'. addEventListener:
452
+ 'change' (visibilitychange, and 'background' on pagehide), 'blur' and
453
+ 'focus' (the browser window, as on Android), 'memoryWarning' (never fires).
454
+ Returns { remove() }. An unknown event throws.
455
+ - Linking: openURL opens a URL of this site in this tab, a URL of another
456
+ site in a new tab (no opener; rejects when the browser blocks it, so call
457
+ it from a press handler), and mailto:, tel:, sms:, and other schemes from
458
+ this tab. javascript: and data: reject. A URL that isn't a string or is
459
+ empty throws at once. canOpenURL is true for each URL that openURL tries.
460
+ getInitialURL is the URL that the page loaded with (null on the server).
461
+ The 'url' event NEVER fires on the web: the router owns the URL. emit,
462
+ addListener, removeAllListeners, listenerCount work. openSettings rejects.
463
+ sendIntent rejects with 'Unsupported'. For a link that the user clicks,
464
+ prefer href on Text or View.
465
+ - Alert.alert(title, message?, buttons?, options?): a <dialog
466
+ role="alertdialog"> with showModal(), outside the React tree, with the look
467
+ of Android's alert (teal text buttons; dark gray card in the dark scheme,
468
+ from Appearance or userInterfaceStyle). All buttons show, in order; with
469
+ three, the first sits at the start. No buttons or [] give OK. A press closes
470
+ the alert, then calls onPress(). style 'destructive' is red text. Focus:
471
+ isPreferred, else the cancel button, else the first.
472
+ - Alert: Escape (and Chrome's Android back gesture) presses the style
473
+ 'cancel' button. Without one, Escape and a click outside close the alert
474
+ only with cancelable: true, then onDismiss runs. A new alert goes on top.
475
+ Alert.prompt does nothing yet (dev warning). On the server, nothing.
476
+ - Keyboard: as on Android. keyboardDidShow fires when the on-screen keyboard
477
+ shows and when its height changes, keyboardDidHide when it hides. The Will
478
+ and ChangeFrame events never fire. The keyboard comes from the visual
479
+ viewport, which shrinks by it, and counts only while a text field has the
480
+ focus; with navigator.virtualKeyboard.overlaysContent, from its rectangle.
481
+ Events: duration 0, easing 'keyboard', endCoordinates in CSS px (screenY =
482
+ top of the keyboard from the window top). dismiss() blurs the focused text
483
+ field. isVisible(), metrics(). scheduleLayoutAnimation does nothing. No
484
+ event on a desktop or with a hardware keyboard.
485
+ - KeyboardAvoidingView: React Native 0.88 math. behavior 'padding'
486
+ (paddingBottom), 'height' (first height less the covered part, flex: 0),
487
+ 'position' (inner view with contentContainerStyle, moved by bottom), none
488
+ (plain View). The frame comes from onLayout, so y is relative to the
489
+ parent: pass the distance to the window top in keyboardVerticalOffset, as on
490
+ native. No animation.
491
+ - Share: share({ title, message, url }) calls navigator.share with title,
492
+ text (the message), and url. Resolves { action: 'sharedAction' |
493
+ 'dismissedAction', activityType: null }; a closed sheet is dismissedAction.
494
+ REJECTS with 'Unsupported platform' where the browser has no share sheet
495
+ (for example Firefox on a desktop, or a page on plain http). Call it from a press handler. options
496
+ have no effect.
497
+ - Vibration: navigator.vibrate with Android's rules. A number is
498
+ milliseconds (default 400). An array is [wait, vibrate, wait, ...]. repeat
499
+ plays an array again until cancel(). Does nothing where the browser has no
500
+ Vibration API (Safari, iOS, most desktops).
501
+ - Clipboard (deprecated in React Native): setString writes with
502
+ navigator.clipboard.writeText, or a hidden textarea and
503
+ execCommand('copy') on a page with no Clipboard API. A refused write only
504
+ warns in development. getString reads with readText and REJECTS when the
505
+ browser refuses. Call both from a press handler.
363
506
  - AccessibilityInfo: reduce motion, reduce transparency, invert colors, and
364
507
  high contrast read live media queries, with change events.
365
508
  isScreenReaderEnabled, isAccessibilityServiceEnabled, isBoldTextEnabled, and
@@ -370,7 +513,7 @@ StatusBar
370
513
  tabIndex={-1} so that it can take focus.
371
514
  - I18nManager: isRTL reads the dir of <html> each time. forceRTL sets dir on
372
515
  <html> at once. allowRTL(false) changes only what isRTL reports.
373
- swapLeftAndRightInRTL stores the flag and has no effect on styles. isRTL is
516
+ swapLeftAndRightInRTL(false) keeps left and right styles physical. isRTL is
374
517
  false on the server.
375
518
  - BackHandler: listeners register and never fire. exitApp() does nothing. Use
376
519
  the history API of your router.
@@ -380,8 +523,10 @@ StatusBar
380
523
  - processColor: an unsigned 32-bit ARGB integer, as on iOS. null for a color
381
524
  it can't parse.
382
525
  - PanResponder: runs on pointer events. panHandlers are six pointer handlers;
383
- spread them on a View. Set touchAction: 'none' in the style (or 'pan-y' for
384
- a horizontal drag in a vertical scroll), or the browser scrolls instead.
526
+ spread them on a View. While a responder holds the gesture, the page
527
+ doesn't scroll (onShouldBlockNativeResponder false lets it scroll). A
528
+ responder that takes the gesture on a move needs touchAction: 'none' in
529
+ the style (or 'pan-y' for a horizontal drag in a vertical scroll).
385
530
  The element captures the pointer at the grant. Negotiation works as on
386
531
  native. dx and dy are CSS pixels; vx and vy are pixels per millisecond.
387
532
  onShouldBlockNativeResponder is ignored. getInteractionHandle() is null.
@@ -389,6 +534,22 @@ StatusBar
389
534
  the native responder handlers. Spread them on a View. Memoize the config.
390
535
  A null config returns null. hitSlop doesn't grow the hit area. Set
391
536
  touchAction yourself for cancelable={false}.
537
+ - unstable_createElement(type, props): compat, not in React Native. Renders an
538
+ element from React Native props: style compiles to class names, the
539
+ accessibility props become ARIA attributes, onPress and the responder
540
+ handlers are dropped, every other prop goes to the element. No style reset.
541
+ - findNodeHandle(value): compat. Returns the DOM element of a ref, of an
542
+ element, or of a ScrollView ref. A number comes back as it is. null for a
543
+ class component instance.
544
+ - TurboModuleRegistry: compat. get() returns null, getEnforcing() throws.
545
+ - @rootnative/web/assets-registry: compat entry with registerAsset and
546
+ getAssetByID. The Vite plugin aliases @react-native/assets-registry/registry
547
+ to it. Empty unless your code registers an asset.
548
+ - @rootnative/web/style: compat entry for Reanimated 4. createReactDOMStyle
549
+ (also the default export) gives inline DOM style values, shorthands first.
550
+ createTransformValue and createTextShadowValue give CSS values. Without the
551
+ Worklets Babel plugin, pass the shared values as a dependency array to each
552
+ Reanimated hook.
392
553
 
393
554
  ## Server rendering
394
555
 
@@ -412,7 +573,7 @@ Render the whole <html> document with React, not only the app:
412
573
  - Write the style tags after the render ends.
413
574
  - Render <head> with React, so the tags of Head land in it. Pasted into a
414
575
  template, they land at the start of <body>.
415
- - renderStyleTags(registry) returns the same two <style> elements as React
576
+ - renderStyleTags(registry) returns the same three <style> elements as React
416
577
  elements.
417
578
  - The client calls hydrateRoot(root, <App />) with no provider. It adopts the
418
579
  server's <style> elements, so it inserts no rule twice.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rootnative/web",
3
- "version": "0.0.0-alpha.2",
3
+ "version": "0.0.0-alpha.3",
4
4
  "description": "A standalone web runtime for React Native apps",
5
5
  "license": "MIT",
6
6
  "homepage": "https://rootnative.github.io/web/",
@@ -32,8 +32,10 @@
32
32
  ],
33
33
  "exports": {
34
34
  ".": "./dist/index.js",
35
+ "./assets-registry": "./dist/assets-registry/index.js",
35
36
  "./dom": "./dist/dom/index.js",
36
37
  "./server": "./dist/server/index.js",
38
+ "./style": "./dist/style/index.js",
37
39
  "./vite": "./dist/vite/index.js",
38
40
  "./package.json": "./package.json"
39
41
  },
@@ -50,14 +52,23 @@
50
52
  "peerDependencies": {
51
53
  "react": "^19.0.0",
52
54
  "react-dom": "^19.0.0",
55
+ "@babel/core": "^7.0.0",
56
+ "react-native-worklets": ">=0.5.0",
53
57
  "vite": "^8.0.0"
54
58
  },
55
59
  "peerDependenciesMeta": {
60
+ "@babel/core": {
61
+ "optional": true
62
+ },
63
+ "react-native-worklets": {
64
+ "optional": true
65
+ },
56
66
  "vite": {
57
67
  "optional": true
58
68
  }
59
69
  },
60
70
  "devDependencies": {
71
+ "@babel/core": "7.29.13",
61
72
  "@types/react": "19.3.0",
62
73
  "@types/react-dom": "19.3.0",
63
74
  "@vitejs/plugin-react": "6.1.2",
@@ -67,6 +78,7 @@
67
78
  "react": "19.3.1",
68
79
  "react-dom": "19.3.1",
69
80
  "react-native": "0.88.1",
81
+ "react-native-worklets": "0.13.0",
70
82
  "tsdown": "0.23.4",
71
83
  "vite": "8.3.5",
72
84
  "vitest": "5.0.5"
@@ -1 +0,0 @@
1
- {"version":3,"file":"StyleRegistryContext-CAD45r4n.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 = ():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