@rootnative/web 0.0.0-alpha.0
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 +29 -0
- package/LICENSE +21 -0
- package/README.md +69 -0
- package/dist/StyleRegistryContext-ButsUd8D.js +129 -0
- package/dist/StyleRegistryContext-ButsUd8D.js.map +1 -0
- package/dist/dom/index.d.ts +22 -0
- package/dist/dom/index.js +53 -0
- package/dist/dom/index.js.map +1 -0
- package/dist/index.d.ts +875 -0
- package/dist/index.js +3374 -0
- package/dist/index.js.map +1 -0
- package/dist/server/index.d.ts +32 -0
- package/dist/server/index.js +25 -0
- package/dist/server/index.js.map +1 -0
- package/dist/types-BxTWbdj9.d.ts +5 -0
- package/llms.txt +328 -0
- package/package.json +68 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@rootnative/web` are in this file. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Before `1.0.0`, any release can have breaking changes. Each release lists them.
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
## [0.0.0-alpha.0] - 2026-11-10
|
|
8
|
+
|
|
9
|
+
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.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **Components:** `View`, `Text`, `Image`, `Pressable`, `ScrollView`, `FlatList`, `TextInput`, and `StatusBar`.
|
|
14
|
+
- **APIs:** `StyleSheet`, `Platform`, `Dimensions`, `useWindowDimensions`, `Appearance`, `useColorScheme`, `AccessibilityInfo`, `I18nManager`, `BackHandler`, `PixelRatio`, `processColor`, `PanResponder`, and `usePressability`.
|
|
15
|
+
- **Semantic HTML.** The `role` prop picks the HTML element, so a React Native tree renders as landmarks, headings, lists, and links. `href` on a `View` or a `Text` renders a link.
|
|
16
|
+
- **Atomic CSS.** Each style declaration becomes one shared CSS class, with the React Native defaults, units, flex rules, and shorthand order.
|
|
17
|
+
- **Server rendering** from `@rootnative/web/server`. One style registry per request collects the CSS, and the browser adopts that CSS when it hydrates.
|
|
18
|
+
- **SEO** with `Head` from `@rootnative/web/dom`: the title, meta tags, Open Graph tags, and JSON-LD.
|
|
19
|
+
- **`llms.txt`** in the package. It describes the API of this version for AI agents.
|
|
20
|
+
|
|
21
|
+
### Notes
|
|
22
|
+
|
|
23
|
+
- `FlatList` renders every item. It has no virtualizer yet, so load a long list in pages with `onEndReached`.
|
|
24
|
+
- `marginLeft`, `paddingLeft`, `left`, and their right partners don't swap in a right-to-left layout, as they do on native. Use the start and end props.
|
|
25
|
+
- There's no Vite plugin yet. Set the `react-native` alias by hand, as [Installation](https://rootnative.github.io/web/installation) shows.
|
|
26
|
+
- The tests run in Chromium. Firefox and Safari aren't in the test run yet.
|
|
27
|
+
|
|
28
|
+
[unreleased]: https://github.com/rootnative/web/compare/web@0.0.0-alpha.0...HEAD
|
|
29
|
+
[0.0.0-alpha.0]: https://github.com/rootnative/web/releases/tag/web@0.0.0-alpha.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 rootnative
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# @rootnative/web
|
|
2
|
+
|
|
3
|
+
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
|
+
|
|
5
|
+
> **Early alpha.** The API can change between releases. [Status](https://rootnative.github.io/web/status) lists what ships today.
|
|
6
|
+
|
|
7
|
+
**Docs: https://rootnative.github.io/web/**
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @rootnative/web
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
React 19 and React DOM 19 are peer dependencies. Point `react-native` at the package in `vite.config.ts`:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import react from '@vitejs/plugin-react'
|
|
19
|
+
import { defineConfig } from 'vite'
|
|
20
|
+
|
|
21
|
+
export default defineConfig({
|
|
22
|
+
plugins: [react()],
|
|
23
|
+
resolve: {
|
|
24
|
+
alias: { 'react-native': '@rootnative/web' },
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Give TypeScript the same mapping in `src/react-native.d.ts`:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
declare module 'react-native' {
|
|
33
|
+
export * from '@rootnative/web'
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
[Installation](https://rootnative.github.io/web/installation) shows how to mount the app, so that `flex: 1` fills the window.
|
|
38
|
+
|
|
39
|
+
## Example
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
import { StyleSheet, Text, View } from 'react-native'
|
|
43
|
+
|
|
44
|
+
export function App() {
|
|
45
|
+
return (
|
|
46
|
+
<View role="main" style={styles.screen}>
|
|
47
|
+
<Text role="heading" aria-level={1} style={styles.title}>
|
|
48
|
+
Hello from React Native
|
|
49
|
+
</Text>
|
|
50
|
+
<Text href="/about">About</Text>
|
|
51
|
+
</View>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const styles = StyleSheet.create({
|
|
56
|
+
screen: { flex: 1, alignItems: 'center', justifyContent: 'center', gap: 8 },
|
|
57
|
+
title: { fontSize: 24 },
|
|
58
|
+
})
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
In the browser, this is a `<main>` with an `<h1>` and an `<a href="/about">`, styled with atomic CSS classes. The same code runs on iOS and Android.
|
|
62
|
+
|
|
63
|
+
## For AI agents
|
|
64
|
+
|
|
65
|
+
This package ships `llms.txt`. `node_modules/@rootnative/web/llms.txt` describes the API of the version you installed. The docs site has [llms-full.txt](https://rootnative.github.io/web/llms-full.txt) with every page.
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
[MIT](https://github.com/rootnative/web/blob/main/LICENSE)
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
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
|
+
// src/style/registry.ts
|
|
9
|
+
const SHORTHAND_STYLE_ID = "rootnative-style-shorthand";
|
|
10
|
+
const LONGHAND_STYLE_ID = "rootnative-style-longhand";
|
|
11
|
+
const shorthandProperties = /* @__PURE__ */ new Set([
|
|
12
|
+
"border",
|
|
13
|
+
"borderBlock",
|
|
14
|
+
"borderColor",
|
|
15
|
+
"borderInline",
|
|
16
|
+
"borderRadius",
|
|
17
|
+
"borderStyle",
|
|
18
|
+
"borderWidth",
|
|
19
|
+
"flex",
|
|
20
|
+
"flexFlow",
|
|
21
|
+
"gap",
|
|
22
|
+
"inset",
|
|
23
|
+
"insetBlock",
|
|
24
|
+
"insetInline",
|
|
25
|
+
"margin",
|
|
26
|
+
"marginBlock",
|
|
27
|
+
"marginInline",
|
|
28
|
+
"outline",
|
|
29
|
+
"overflow",
|
|
30
|
+
"padding",
|
|
31
|
+
"paddingBlock",
|
|
32
|
+
"paddingInline",
|
|
33
|
+
"textDecoration"
|
|
34
|
+
]);
|
|
35
|
+
const toKebab = (name) => name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
36
|
+
const hash = (input) => {
|
|
37
|
+
let h = 2166136261;
|
|
38
|
+
for (let i = 0; i < input.length; i++) {
|
|
39
|
+
h ^= input.charCodeAt(i);
|
|
40
|
+
h = Math.imul(h, 16777619);
|
|
41
|
+
}
|
|
42
|
+
return (h >>> 0).toString(36);
|
|
43
|
+
};
|
|
44
|
+
var StyleRegistry = class {
|
|
45
|
+
constructor(sheets = {
|
|
46
|
+
shorthand: null,
|
|
47
|
+
longhand: null
|
|
48
|
+
}) {
|
|
49
|
+
this.classNames = /* @__PURE__ */ new Map();
|
|
50
|
+
this.adopted = /* @__PURE__ */ new Set();
|
|
51
|
+
this.shorthandRules = [];
|
|
52
|
+
this.longhandRules = [];
|
|
53
|
+
this.sheets = sheets;
|
|
54
|
+
this.adopt(sheets.shorthand);
|
|
55
|
+
this.adopt(sheets.longhand);
|
|
56
|
+
}
|
|
57
|
+
classFor(property, value) {
|
|
58
|
+
const key = `${property}:${value}`;
|
|
59
|
+
const known = this.classNames.get(key);
|
|
60
|
+
if (known !== void 0) return known;
|
|
61
|
+
const className = `rn-${hash(key)}`;
|
|
62
|
+
this.classNames.set(key, className);
|
|
63
|
+
const shorthand = shorthandProperties.has(property);
|
|
64
|
+
const rule = `.${className}{${toKebab(property)}:${value}}`;
|
|
65
|
+
(shorthand ? this.shorthandRules : this.longhandRules).push(rule);
|
|
66
|
+
if (!this.adopted.has(className)) {
|
|
67
|
+
const sheet = shorthand ? this.sheets.shorthand : this.sheets.longhand;
|
|
68
|
+
sheet?.insertRule(rule, sheet.cssRules.length);
|
|
69
|
+
}
|
|
70
|
+
return className;
|
|
71
|
+
}
|
|
72
|
+
classesFor(declarations) {
|
|
73
|
+
const names = [];
|
|
74
|
+
for (const property in declarations) names.push(this.classFor(property, declarations[property]));
|
|
75
|
+
return names.join(" ");
|
|
76
|
+
}
|
|
77
|
+
staticClass(className, rules) {
|
|
78
|
+
if (this.classNames.has(className)) return className;
|
|
79
|
+
this.classNames.set(className, className);
|
|
80
|
+
for (const rule of rules) {
|
|
81
|
+
this.longhandRules.push(rule);
|
|
82
|
+
if (!this.adopted.has(className)) {
|
|
83
|
+
const sheet = this.sheets.longhand;
|
|
84
|
+
sheet?.insertRule(rule, sheet.cssRules.length);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return className;
|
|
88
|
+
}
|
|
89
|
+
cssText() {
|
|
90
|
+
return {
|
|
91
|
+
shorthand: this.shorthandRules.join("\n"),
|
|
92
|
+
longhand: this.longhandRules.join("\n")
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
get ruleCount() {
|
|
96
|
+
return this.shorthandRules.length + this.longhandRules.length;
|
|
97
|
+
}
|
|
98
|
+
adopt(sheet) {
|
|
99
|
+
if (sheet === null) return;
|
|
100
|
+
for (const rule of Array.from(sheet.cssRules)) if (rule instanceof CSSStyleRule) this.adopted.add(rule.selectorText.slice(1));
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
let defaultRegistry = null;
|
|
104
|
+
const getStyleRegistry = () => {
|
|
105
|
+
if (defaultRegistry !== null) return defaultRegistry;
|
|
106
|
+
defaultRegistry = new StyleRegistry(hasDOM() ? {
|
|
107
|
+
shorthand: domSheet(SHORTHAND_STYLE_ID),
|
|
108
|
+
longhand: domSheet(LONGHAND_STYLE_ID)
|
|
109
|
+
} : {
|
|
110
|
+
shorthand: null,
|
|
111
|
+
longhand: null
|
|
112
|
+
});
|
|
113
|
+
return defaultRegistry;
|
|
114
|
+
};
|
|
115
|
+
const domSheet = (id) => {
|
|
116
|
+
let element = document.getElementById(id);
|
|
117
|
+
if (element === null) {
|
|
118
|
+
element = document.createElement("style");
|
|
119
|
+
element.id = id;
|
|
120
|
+
document.head.appendChild(element);
|
|
121
|
+
}
|
|
122
|
+
return element.sheet;
|
|
123
|
+
};
|
|
124
|
+
// src/style/StyleRegistryContext.ts
|
|
125
|
+
const StyleRegistryContext = createContext(null);
|
|
126
|
+
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 };
|
|
128
|
+
|
|
129
|
+
//# sourceMappingURL=StyleRegistryContext-ButsUd8D.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,UAA0B;CACtC,IAAI,IAAI;CACR,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACrC,KAAK,MAAM,WAAW,CAAC;EACvB,IAAI,KAAK,KAAK,GAAG,QAAU;CAC7B;CACA,QAAQ,MAAM,EAAA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C,KAAK,QAAQ,IAAI,SAAS,GAAG;IAChC,MAAM,QAAQ,KAAK,OAAO;IAC1B,OAAO,WAAW,MAAM,MAAM,SAAS,MAAM;GAC/C;EACF;EACA,OAAO;CACT;CAGA,UAAmD;EACjD,OAAO;GAAE,WAAW,KAAK,eAAe,KAAK,IAAI;GAAG,UAAU,KAAK,cAAc,KAAK,IAAI;EAAE;CAC9F;CAEA,IAAI,YAAoB;EACtB,OAAO,KAAK,eAAe,SAAS,KAAK,cAAc;CACzD;CAGA,MAAc,OAAmC;EAC/C,IAAI,UAAU,MAAM;EACpB,KAAK,MAAM,QAAQ,MAAM,KAAK,MAAM,QAAQ,GAC1C,IAAI,gBAAgB,cAAc,KAAK,QAAQ,IAAI,KAAK,aAAa,MAAM,CAAC,CAAC;CAEjF;AACF;AAEA,IAAI,kBAAwC;AAE5C,MAAa,yBAAwC;CACnD,IAAI,oBAAoB,MAAM,OAAO;CACrC,kBAAkB,IAAI,cACpB,OAAO,IACH;EAAE,WAAW,SAAS,kBAAkB;EAAG,UAAU,SAAS,iBAAiB;CAAE,IACjF;EAAE,WAAW;EAAM,UAAU;CAAK,CACxC;CACA,OAAO;AACT;AAUA,MAAM,YAAY,OAA8B;CAC9C,IAAI,UAAU,SAAS,eAAe,EAAE;CACxC,IAAI,YAAY,MAAM;EACpB,UAAU,SAAS,cAAc,OAAO;EACxC,QAAQ,KAAK;EACb,SAAS,KAAK,YAAY,OAAO;CACnC;CACA,OAAO,QAAQ;AACjB;;AChJA,MAAa,uBACX,cAAoC,IAAI;AAE1C,MAAa,yBACX,WAAW,oBAAoB,KAAK,iBAAiB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ReactElement, ReactNode } from "react";
|
|
2
|
+
type OpenGraph = {
|
|
3
|
+
title?: string | undefined;
|
|
4
|
+
description?: string | undefined;
|
|
5
|
+
image?: string | undefined;
|
|
6
|
+
url?: string | undefined;
|
|
7
|
+
type?: string | undefined;
|
|
8
|
+
siteName?: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
type HeadProps = {
|
|
11
|
+
title?: string | undefined;
|
|
12
|
+
description?: string | undefined;
|
|
13
|
+
canonical?: string | undefined;
|
|
14
|
+
robots?: string | undefined;
|
|
15
|
+
themeColor?: string | undefined;
|
|
16
|
+
openGraph?: OpenGraph | undefined;
|
|
17
|
+
jsonLd?: Record<string, unknown> | ReadonlyArray<Record<string, unknown>> | undefined;
|
|
18
|
+
children?: ReactNode;
|
|
19
|
+
};
|
|
20
|
+
export declare function Head(props: HeadProps): ReactElement;
|
|
21
|
+
export type { HeadProps, OpenGraph };
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Fragment, createElement } from "react";
|
|
2
|
+
// src/dom/Head.tsx
|
|
3
|
+
const openGraphKeys = [
|
|
4
|
+
["title", "og:title"],
|
|
5
|
+
["description", "og:description"],
|
|
6
|
+
["image", "og:image"],
|
|
7
|
+
["url", "og:url"],
|
|
8
|
+
["type", "og:type"],
|
|
9
|
+
["siteName", "og:site_name"]
|
|
10
|
+
];
|
|
11
|
+
const escapeJSON = (json) => json.replace(/</g, "\\u003c");
|
|
12
|
+
function Head(props) {
|
|
13
|
+
const { canonical, children, description, jsonLd, openGraph, robots, themeColor, title } = props;
|
|
14
|
+
const nodes = [];
|
|
15
|
+
if (title !== void 0) nodes.push(createElement("title", { key: "title" }, title));
|
|
16
|
+
if (description !== void 0) nodes.push(createElement("meta", {
|
|
17
|
+
key: "description",
|
|
18
|
+
name: "description",
|
|
19
|
+
content: description
|
|
20
|
+
}));
|
|
21
|
+
if (robots !== void 0) nodes.push(createElement("meta", {
|
|
22
|
+
key: "robots",
|
|
23
|
+
name: "robots",
|
|
24
|
+
content: robots
|
|
25
|
+
}));
|
|
26
|
+
if (themeColor !== void 0) nodes.push(createElement("meta", {
|
|
27
|
+
key: "theme-color",
|
|
28
|
+
name: "theme-color",
|
|
29
|
+
content: themeColor
|
|
30
|
+
}));
|
|
31
|
+
if (canonical !== void 0) nodes.push(createElement("link", {
|
|
32
|
+
key: "canonical",
|
|
33
|
+
rel: "canonical",
|
|
34
|
+
href: canonical
|
|
35
|
+
}));
|
|
36
|
+
if (openGraph !== void 0) for (const [key, property] of openGraphKeys) {
|
|
37
|
+
const content = openGraph[key];
|
|
38
|
+
if (content !== void 0) nodes.push(createElement("meta", {
|
|
39
|
+
key: property,
|
|
40
|
+
property,
|
|
41
|
+
content
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
if (jsonLd !== void 0) nodes.push(createElement("script", {
|
|
45
|
+
key: "json-ld",
|
|
46
|
+
type: "application/ld+json",
|
|
47
|
+
dangerouslySetInnerHTML: { __html: escapeJSON(JSON.stringify(jsonLd)) }
|
|
48
|
+
}));
|
|
49
|
+
return createElement(Fragment, null, ...nodes, children);
|
|
50
|
+
}
|
|
51
|
+
export { Head };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/dom/Head.tsx"],"sourcesContent":["import { createElement, Fragment, type ReactElement, type ReactNode } from 'react'\n\nexport type OpenGraph = {\n title?: string | undefined\n description?: string | undefined\n image?: string | undefined\n url?: string | undefined\n type?: string | undefined\n siteName?: string | undefined\n}\n\nexport type HeadProps = {\n title?: string | undefined\n description?: string | undefined\n canonical?: string | undefined\n robots?: string | undefined\n themeColor?: string | undefined\n openGraph?: OpenGraph | undefined\n // One or more schema.org objects, rendered as JSON-LD.\n jsonLd?: Record<string, unknown> | ReadonlyArray<Record<string, unknown>> | undefined\n // Extra head elements: <meta>, <link>, <title>. React moves them into <head>.\n children?: ReactNode\n}\n\nconst openGraphKeys: ReadonlyArray<[keyof OpenGraph, string]> = [\n ['title', 'og:title'],\n ['description', 'og:description'],\n ['image', 'og:image'],\n ['url', 'og:url'],\n ['type', 'og:type'],\n ['siteName', 'og:site_name'],\n]\n\n// A closing tag inside a script would end it early.\nconst escapeJSON = (json: string): string => json.replace(/</g, '\\\\u003c')\n\n// Use one Head per page. React 19 hoists <title>, <meta>, and <link> into <head> on the\n// server and the client, but it does not merge two Heads.\nexport function Head(props: HeadProps): ReactElement {\n const { canonical, children, description, jsonLd, openGraph, robots, themeColor, title } = props\n const nodes: ReactNode[] = []\n\n if (title !== undefined) nodes.push(createElement('title', { key: 'title' }, title))\n if (description !== undefined) {\n nodes.push(\n createElement('meta', { key: 'description', name: 'description', content: description }),\n )\n }\n if (robots !== undefined) {\n nodes.push(createElement('meta', { key: 'robots', name: 'robots', content: robots }))\n }\n if (themeColor !== undefined) {\n nodes.push(\n createElement('meta', { key: 'theme-color', name: 'theme-color', content: themeColor }),\n )\n }\n if (canonical !== undefined) {\n nodes.push(createElement('link', { key: 'canonical', rel: 'canonical', href: canonical }))\n }\n if (openGraph !== undefined) {\n for (const [key, property] of openGraphKeys) {\n const content = openGraph[key]\n if (content !== undefined)\n nodes.push(createElement('meta', { key: property, property, content }))\n }\n }\n if (jsonLd !== undefined) {\n nodes.push(\n createElement('script', {\n key: 'json-ld',\n type: 'application/ld+json',\n dangerouslySetInnerHTML: { __html: escapeJSON(JSON.stringify(jsonLd)) },\n }),\n )\n }\n\n return createElement(Fragment, null, ...nodes, children)\n}\n"],"mappings":";;AAwBA,MAAM,gBAA0D;CAC9D,CAAC,SAAS,UAAU;CACpB,CAAC,eAAe,gBAAgB;CAChC,CAAC,SAAS,UAAU;CACpB,CAAC,OAAO,QAAQ;CAChB,CAAC,QAAQ,SAAS;CAClB,CAAC,YAAY,cAAc;AAC7B;AAGA,MAAM,cAAc,SAAyB,KAAK,QAAQ,MAAM,SAAS;AAIzE,SAAgB,KAAK,OAAgC;CACnD,MAAM,EAAE,WAAW,UAAU,aAAa,QAAQ,WAAW,QAAQ,YAAY,UAAU;CAC3F,MAAM,QAAqB,CAAC;CAE5B,IAAI,UAAU,KAAA,GAAW,MAAM,KAAK,cAAc,SAAS,EAAE,KAAK,Q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