@rootnative/web 0.0.0-alpha.4 → 0.0.0-alpha.5

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,15 @@ 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.5] - 2026-11-15
8
+
9
+ Two changes make each render after the first one cheaper. On one app, the runtime's own script time while a menu or a dialog opens and closes is about half of what it was in `0.0.0-alpha.4`. The first load doesn't change.
10
+
11
+ ### Changed
12
+
13
+ - **A render of `View`, `Text`, `TextInput`, and `Image` is faster.** Each render resolved the default style of the component again, and then didn't use the result. Now it resolves once. On one app, a menu opens 16 % faster and a dialog 8 % faster.
14
+ - **A style object that you make during a render,** such as `{ color: theme.text }` or `[styles.row, { opacity }]`, now compiles once for each set of values. Before, only a style from `StyleSheet.create` did, and any other style compiled again on each render. On the same app, a dialog opens 7 % faster again. A style with a `transform`, or with another value that isn't a string or a number, still compiles each time. The cache uses a little memory: about 2 % more heap on that app.
15
+
7
16
  ## [0.0.0-alpha.4] - 2026-11-15
8
17
 
9
18
  ### Added
@@ -132,7 +141,8 @@ The first alpha. It runs a React Native app in the browser with the components a
132
141
  - There's no Vite plugin yet. Set the `react-native` alias by hand, as [Installation](https://rootnative.github.io/web/installation) shows.
133
142
  - The tests run in Chromium. Firefox and Safari aren't in the test run yet.
134
143
 
135
- [unreleased]: https://github.com/rootnative/web/compare/web@0.0.0-alpha.4...HEAD
144
+ [unreleased]: https://github.com/rootnative/web/compare/web@0.0.0-alpha.5...HEAD
145
+ [0.0.0-alpha.5]: https://github.com/rootnative/web/releases/tag/web@0.0.0-alpha.5
136
146
  [0.0.0-alpha.4]: https://github.com/rootnative/web/releases/tag/web@0.0.0-alpha.4
137
147
  [0.0.0-alpha.3]: https://github.com/rootnative/web/releases/tag/web@0.0.0-alpha.3
138
148
  [0.0.0-alpha.2]: https://github.com/rootnative/web/releases/tag/web@0.0.0-alpha.2
@@ -23,50 +23,80 @@ const pointerEventsStyle = Object.freeze({
23
23
  "box-none": Object.freeze({ pointerEvents: "box-none" }),
24
24
  "box-only": Object.freeze({ pointerEvents: "box-only" })
25
25
  });
26
- const caches = [/* @__PURE__ */ new WeakMap(), /* @__PURE__ */ new WeakMap()];
27
- const collectFrozen = (style, out) => {
28
- if (style === null || style === void 0 || style === false || style === "") return true;
26
+ const newNode = () => ({
27
+ classes: void 0,
28
+ frozen: void 0,
29
+ values: void 0
30
+ });
31
+ let caches = [/* @__PURE__ */ new WeakMap(), /* @__PURE__ */ new WeakMap()];
32
+ const MAX_VALUE_NODES = 1e4;
33
+ let valueNodes = 0;
34
+ const walk = (style, node) => {
35
+ if (style === null || style === void 0 || style === false || style === "") return node;
29
36
  if (Array.isArray(style)) {
30
- for (const entry of style) if (!collectFrozen(entry, out)) return false;
31
- return true;
37
+ let current = node;
38
+ for (const entry of style) {
39
+ current = walk(entry, current);
40
+ if (current === void 0) return void 0;
41
+ }
42
+ return current;
43
+ }
44
+ if (typeof style !== "object") return void 0;
45
+ if (Object.isFrozen(style)) {
46
+ const frozen = node.frozen ??= /* @__PURE__ */ new WeakMap();
47
+ let next = frozen.get(style);
48
+ if (next === void 0) {
49
+ next = newNode();
50
+ frozen.set(style, next);
51
+ }
52
+ return next;
53
+ }
54
+ let current = node;
55
+ for (const name in style) {
56
+ if (!Object.hasOwn(style, name)) continue;
57
+ const value = style[name];
58
+ const type = typeof value;
59
+ if (type === "object" && value !== null || type === "function") return void 0;
60
+ const values = current.values ??= /* @__PURE__ */ new Map();
61
+ let byValue = values.get(name);
62
+ if (byValue === void 0) {
63
+ byValue = /* @__PURE__ */ new Map();
64
+ values.set(name, byValue);
65
+ }
66
+ let next = byValue.get(value);
67
+ if (next === void 0) {
68
+ next = newNode();
69
+ byValue.set(value, next);
70
+ valueNodes += 1;
71
+ }
72
+ current = next;
32
73
  }
33
- if (typeof style !== "object" || !Object.isFrozen(style)) return false;
34
- out.push(style);
35
- return true;
74
+ return current;
36
75
  };
37
76
  const compileFlat = (flat, registry) => flat === void 0 ? "" : joinClassNames(registry.classesFor(resolveStyle(flat)), boxPointerEventsClass(flat["pointerEvents"], registry));
38
77
  const compileStyle = (style, registry = getStyleRegistry()) => {
39
- const frozen = [];
40
- if (!collectFrozen(style, frozen)) return compileFlat(flattenStyle(style), registry);
41
- if (frozen.length === 0) return "";
42
- const cache = caches[getLeftAndRightSwap() ? 1 : 0];
43
- let level = cache.get(registry);
44
- if (level === void 0) {
45
- level = /* @__PURE__ */ new WeakMap();
46
- cache.set(registry, level);
78
+ if (style === null || style === void 0 || style === false || style === "") return "";
79
+ if (valueNodes > 1e4) {
80
+ caches = [/* @__PURE__ */ new WeakMap(), /* @__PURE__ */ new WeakMap()];
81
+ valueNodes = 0;
47
82
  }
48
- let node;
49
- for (const object of frozen) {
50
- if (node !== void 0) level = node.next ??= /* @__PURE__ */ new WeakMap();
51
- node = level.get(object);
52
- if (node === void 0) {
53
- node = {
54
- classes: void 0,
55
- next: void 0
56
- };
57
- level.set(object, node);
58
- }
83
+ const cache = caches[getLeftAndRightSwap() ? 1 : 0];
84
+ let root = cache.get(registry);
85
+ if (root === void 0) {
86
+ root = newNode();
87
+ cache.set(registry, root);
59
88
  }
60
- const leaf = node;
61
- leaf.classes ??= compileFlat(frozen.length === 1 ? frozen[0] : flattenStyle(frozen), registry);
89
+ const leaf = walk(style, root);
90
+ if (leaf === void 0) return compileFlat(flattenStyle(style), registry);
91
+ leaf.classes ??= compileFlat(flattenStyle(style), registry);
62
92
  return leaf.classes;
63
93
  };
64
94
  /**
65
95
  * The class of a component's default style, in the reset sheet. Any style of the app beats it,
66
96
  * as any style beats the defaults of native layout.
67
97
  */
68
- const compileReset = (className, style, registry = getStyleRegistry()) => registry.resetClass(className, resolveStyle(style));
98
+ const compileReset = (className, style, registry = getStyleRegistry()) => registry.hasClass(className) ? className : registry.resetClass(className, resolveStyle(style));
69
99
  const joinClassNames = (...names) => names.filter((name) => typeof name === "string" && name !== "").join(" ");
70
- export { compileReset, compileStyle, flattenStyle, joinClassNames, pointerEventsStyle };
100
+ export { MAX_VALUE_NODES, compileReset, compileStyle, flattenStyle, joinClassNames, pointerEventsStyle };
71
101
 
72
102
  //# sourceMappingURL=compile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"compile.js","names":[],"sources":["../../src/style/compile.ts"],"sourcesContent":["import { getLeftAndRightSwap } from './direction'\nimport { getStyleRegistry, type StyleRegistry } from './registry'\nimport { resolveStyle } from './resolveStyle'\nimport type { FlatStyle, StyleProp } from './types'\n\nexport const flattenStyle = <T extends object>(style: StyleProp<T>): T | undefined => {\n if (style === null || style === undefined || style === false || style === '') return undefined\n if (!Array.isArray(style)) return style as T\n\n let result: object | undefined\n for (const entry of style as ReadonlyArray<StyleProp<T>>) {\n const flat = flattenStyle(entry)\n if (flat === undefined) continue\n result = result === undefined ? { ...flat } : Object.assign(result, flat)\n }\n return result as T | undefined\n}\n\n// A child selector can't be an atomic class. The child rule of `box-none` has no specificity, so\n// a child with its own `pointerEvents` keeps it. The children of `box-only` are never a target.\nconst boxPointerEventsClass = (value: unknown, registry: StyleRegistry): string | undefined => {\n if (value === 'box-none') {\n return registry.staticClass('rn-pe-box-none', [\n '.rn-pe-box-none{pointer-events:none}',\n ':where(.rn-pe-box-none)>*{pointer-events:auto}',\n ])\n }\n if (value === 'box-only') {\n return registry.staticClass('rn-pe-box-only', [\n '.rn-pe-box-only{pointer-events:auto}',\n '.rn-pe-box-only>*{pointer-events:none!important}',\n ])\n }\n return undefined\n}\n\n// The `pointerEvents` prop as a style. The prop wins over the same key of `style`.\nexport const pointerEventsStyle: Readonly<\n Record<'auto' | 'none' | 'box-none' | 'box-only', FlatStyle>\n> = Object.freeze({\n auto: Object.freeze({ pointerEvents: 'auto' }),\n none: Object.freeze({ pointerEvents: 'none' }),\n 'box-none': Object.freeze({ pointerEvents: 'box-none' }),\n 'box-only': Object.freeze({ pointerEvents: 'box-only' }),\n})\n\n// A path through the cache, one frozen style object for each step. The classes of a node are the\n// classes of the objects on its path, flattened in that order.\ntype CacheNode = { classes: string | undefined; next: WeakMap<FlatStyle, CacheNode> | undefined }\n\n// One cache for each value of the left and right swap, because the classes of a style differ.\nconst caches = [\n new WeakMap<StyleRegistry, WeakMap<FlatStyle, CacheNode>>(),\n new WeakMap<StyleRegistry, WeakMap<FlatStyle, CacheNode>>(),\n] as const\n\n// Static objects from StyleSheet.create are frozen, so they can be cache keys. Returns false at\n// the first entry that isn't a frozen object. `Object.isFrozen` is true for a number, and a\n// WeakMap throws on it.\nconst collectFrozen = (style: StyleProp<object>, out: FlatStyle[]): boolean => {\n if (style === null || style === undefined || style === false || style === '') return true\n if (Array.isArray(style)) {\n for (const entry of style as ReadonlyArray<StyleProp<object>>) {\n if (!collectFrozen(entry, out)) return false\n }\n return true\n }\n if (typeof style !== 'object' || !Object.isFrozen(style)) return false\n out.push(style as FlatStyle)\n return true\n}\n\nconst compileFlat = (flat: FlatStyle | undefined, registry: StyleRegistry): string =>\n flat === undefined\n ? ''\n : joinClassNames(\n registry.classesFor(resolveStyle(flat)),\n boxPointerEventsClass(flat['pointerEvents'], registry),\n )\n\nexport const compileStyle = (\n style: StyleProp<object>,\n registry: StyleRegistry = getStyleRegistry(),\n): string => {\n const frozen: FlatStyle[] = []\n if (!collectFrozen(style, frozen)) {\n return compileFlat(flattenStyle(style) as FlatStyle | undefined, registry)\n }\n if (frozen.length === 0) return ''\n\n const cache = caches[getLeftAndRightSwap() ? 1 : 0]\n let level = cache.get(registry)\n if (level === undefined) {\n level = new WeakMap()\n cache.set(registry, level)\n }\n let node: CacheNode | undefined\n for (const object of frozen) {\n if (node !== undefined) level = node.next ??= new WeakMap()\n node = level.get(object)\n if (node === undefined) {\n node = { classes: undefined, next: undefined }\n level.set(object, node)\n }\n }\n const leaf = node as CacheNode\n leaf.classes ??= compileFlat(\n frozen.length === 1 ? frozen[0] : flattenStyle<FlatStyle>(frozen),\n registry,\n )\n return leaf.classes\n}\n\n/**\n * The class of a component's default style, in the reset sheet. Any style of the app beats it,\n * as any style beats the defaults of native layout.\n */\nexport const compileReset = (\n className: string,\n style: FlatStyle,\n registry: StyleRegistry = getStyleRegistry(),\n): string => registry.resetClass(className, resolveStyle(style))\n\n// Joins class names and skips the empty ones.\nexport const joinClassNames = (...names: ReadonlyArray<string | false | undefined>): string =>\n names.filter((name) => typeof name === 'string' && name !== '').join(' ')\n"],"mappings":";;;;AAKA,MAAa,gBAAkC,UAAuC;CACpF,IAAI,UAAU,QAAQ,UAAU,KAAA,KAAa,UAAU,SAAS,UAAU,IAAI,OAAO,KAAA;CACrF,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO;CAElC,IAAI;CACJ,KAAK,MAAM,SAAS,OAAsC;EACxD,MAAM,OAAO,aAAa,KAAK;EAC/B,IAAI,SAAS,KAAA,GAAW;EACxB,SAAS,WAAW,KAAA,IAAY,EAAE,GAAG,KAAK,IAAI,OAAO,OAAO,QAAQ,IAAI;CAC1E;CACA,OAAO;AACT;AAIA,MAAM,yBAAyB,OAAgB,aAAgD;CAC7F,IAAI,UAAU,YACZ,OAAO,SAAS,YAAY,kBAAkB,CAC5C,wCACA,gDACF,CAAC;CAEH,IAAI,UAAU,YACZ,OAAO,SAAS,YAAY,kBAAkB,CAC5C,wCACA,kDACF,CAAC;AAGL;AAGA,MAAa,qBAET,OAAO,OAAO;CAChB,MAAM,OAAO,OAAO,EAAE,eAAe,OAAO,CAAC;CAC7C,MAAM,OAAO,OAAO,EAAE,eAAe,OAAO,CAAC;CAC7C,YAAY,OAAO,OAAO,EAAE,eAAe,WAAW,CAAC;CACvD,YAAY,OAAO,OAAO,EAAE,eAAe,WAAW,CAAC;AACzD,CAAC;AAOD,MAAM,SAAS,iBACb,IAAI,QAAsD,mBAC1D,IAAI,QAAsD,CAC5D;AAKA,MAAM,iBAAiB,OAA0B,QAA8B;CAC7E,IAAI,UAAU,QAAQ,U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AW,aAAa,KAAK,CAAC;AAG/D,MAAa,kBAAkB,GAAG,UAChC,MAAM,QAAQ,SAAS,OAAO,SAAS,YAAY,SAAS,EAAE,CAAC,CAAC,KAAK,GAAG"}
1
+ {"version":3,"file":"compile.js","names":[],"sources":["../../src/style/compile.ts"],"sourcesContent":["import { getLeftAndRightSwap } from './direction'\nimport { getStyleRegistry, type StyleRegistry } from './registry'\nimport { resolveStyle } from './resolveStyle'\nimport type { FlatStyle, StyleProp } from './types'\n\nexport const flattenStyle = <T extends object>(style: StyleProp<T>): T | undefined => {\n if (style === null || style === undefined || style === false || style === '') return undefined\n if (!Array.isArray(style)) return style as T\n\n let result: object | undefined\n for (const entry of style as ReadonlyArray<StyleProp<T>>) {\n const flat = flattenStyle(entry)\n if (flat === undefined) continue\n result = result === undefined ? { ...flat } : Object.assign(result, flat)\n }\n return result as T | undefined\n}\n\n// A child selector can't be an atomic class. The child rule of `box-none` has no specificity, so\n// a child with its own `pointerEvents` keeps it. The children of `box-only` are never a target.\nconst boxPointerEventsClass = (value: unknown, registry: StyleRegistry): string | undefined => {\n if (value === 'box-none') {\n return registry.staticClass('rn-pe-box-none', [\n '.rn-pe-box-none{pointer-events:none}',\n ':where(.rn-pe-box-none)>*{pointer-events:auto}',\n ])\n }\n if (value === 'box-only') {\n return registry.staticClass('rn-pe-box-only', [\n '.rn-pe-box-only{pointer-events:auto}',\n '.rn-pe-box-only>*{pointer-events:none!important}',\n ])\n }\n return undefined\n}\n\n// The `pointerEvents` prop as a style. The prop wins over the same key of `style`.\nexport const pointerEventsStyle: Readonly<\n Record<'auto' | 'none' | 'box-none' | 'box-only', FlatStyle>\n> = Object.freeze({\n auto: Object.freeze({ pointerEvents: 'auto' }),\n none: Object.freeze({ pointerEvents: 'none' }),\n 'box-none': Object.freeze({ pointerEvents: 'box-none' }),\n 'box-only': Object.freeze({ pointerEvents: 'box-only' }),\n})\n\n// A path through the cache. A frozen object, as from StyleSheet.create, is one step by identity.\n// Any other object is one step for each of its declarations, by name and value: a component\n// that makes a new style object on each render still makes the same declarations. The classes\n// of a node are the classes of the steps on its path, flattened in that order.\ntype CacheNode = {\n classes: string | undefined\n frozen: WeakMap<FlatStyle, CacheNode> | undefined\n values: Map<string, Map<unknown, CacheNode>> | undefined\n}\n\nconst newNode = (): CacheNode => ({ classes: undefined, frozen: undefined, values: undefined })\n\n// One cache for each value of the left and right swap, because the classes of a style differ.\nlet caches: readonly [WeakMap<StyleRegistry, CacheNode>, WeakMap<StyleRegistry, CacheNode>] = [\n new WeakMap(),\n new WeakMap(),\n]\n\n// A value that changes on each render, such as an animated width, makes a new node each time.\n// Past this number of such nodes, the cache starts again.\nexport const MAX_VALUE_NODES = 10_000\nlet valueNodes = 0\n\n// The node at the end of the path of `style`, from `node`. Undefined for a style with no path:\n// a value that isn't a primitive, such as a transform, or an entry that isn't an object.\nconst walk = (style: StyleProp<object>, node: CacheNode): CacheNode | undefined => {\n if (style === null || style === undefined || style === false || style === '') return node\n if (Array.isArray(style)) {\n let current: CacheNode | undefined = node\n for (const entry of style as ReadonlyArray<StyleProp<object>>) {\n current = walk(entry, current)\n if (current === undefined) return undefined\n }\n return current\n }\n // `Object.isFrozen` is true for a number, and a WeakMap throws on it.\n if (typeof style !== 'object') return undefined\n\n if (Object.isFrozen(style)) {\n const frozen = (node.frozen ??= new WeakMap())\n let next = frozen.get(style as FlatStyle)\n if (next === undefined) {\n next = newNode()\n frozen.set(style as FlatStyle, next)\n }\n return next\n }\n\n let current = node\n for (const name in style) {\n if (!Object.hasOwn(style, name)) continue\n const value = (style as FlatStyle)[name]\n const type = typeof value\n if ((type === 'object' && value !== null) || type === 'function') return undefined\n const values = (current.values ??= new Map())\n let byValue = values.get(name)\n if (byValue === undefined) {\n byValue = new Map()\n values.set(name, byValue)\n }\n let next = byValue.get(value)\n if (next === undefined) {\n next = newNode()\n byValue.set(value, next)\n valueNodes += 1\n }\n current = next\n }\n return current\n}\n\nconst compileFlat = (flat: FlatStyle | undefined, registry: StyleRegistry): string =>\n flat === undefined\n ? ''\n : joinClassNames(\n registry.classesFor(resolveStyle(flat)),\n boxPointerEventsClass(flat['pointerEvents'], registry),\n )\n\nexport const compileStyle = (\n style: StyleProp<object>,\n registry: StyleRegistry = getStyleRegistry(),\n): string => {\n if (style === null || style === undefined || style === false || style === '') return ''\n if (valueNodes > MAX_VALUE_NODES) {\n caches = [new WeakMap(), new WeakMap()]\n valueNodes = 0\n }\n\n const cache = caches[getLeftAndRightSwap() ? 1 : 0]\n let root = cache.get(registry)\n if (root === undefined) {\n root = newNode()\n cache.set(registry, root)\n }\n const leaf = walk(style, root)\n if (leaf === undefined) {\n return compileFlat(flattenStyle(style) as FlatStyle | undefined, registry)\n }\n leaf.classes ??= compileFlat(flattenStyle(style) as FlatStyle | undefined, registry)\n return leaf.classes\n}\n\n/**\n * The class of a component's default style, in the reset sheet. Any style of the app beats it,\n * as any style beats the defaults of native layout.\n */\nexport const compileReset = (\n className: string,\n style: FlatStyle,\n registry: StyleRegistry = getStyleRegistry(),\n): string =>\n // Each render of each component calls this, so the style resolves only for a new class.\n registry.hasClass(className) ? className : registry.resetClass(className, resolveStyle(style))\n\n// Joins class names and skips the empty ones.\nexport const joinClassNames = (...names: ReadonlyArray<string | false | undefined>): string =>\n names.filter((name) => typeof name === 'string' && name !== '').join(' ')\n"],"mappings":";;;;AAKA,MAAa,gBAAkC,UAAuC;CACpF,IAAI,UAAU,QAAQ,UAAU,KAAA,KAAa,UAAU,SAAS,UAAU,IAAI,OAAO,KAAA;CACrF,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO;CAElC,IAAI;CACJ,KAAK,MAAM,SAAS,OAAsC;EACxD,MAAM,OAAO,aAAa,KAAK;EAC/B,IAAI,SAAS,KAAA,GAAW;EACxB,SAAS,WAAW,KAAA,IAAY,EAAE,GAAG,KAAK,IAAI,OAAO,OAAO,QAAQ,IAAI;CAC1E;CACA,OAAO;AACT;AAIA,MAAM,yBAAyB,OAAgB,aAAgD;CAC7F,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,SAAS,WAAW,WAAW,aAAa,KAAK,CAAC;AAG/F,MAAa,kBAAkB,GAAG,UAChC,MAAM,QAAQ,SAAS,OAAO,SAAS,YAAY,SAAS,EAAE,CAAC,CAAC,KAAK,GAAG"}
@@ -15,6 +15,7 @@ export declare class StyleRegistry {
15
15
  classFor(property: string, value: string): string;
16
16
  classesFor(declarations: CSSDeclarations): string;
17
17
  staticClass(className: string, rules: ReadonlyArray<string>): string;
18
+ hasClass(className: string): boolean;
18
19
  resetClass(className: string, declarations: CSSDeclarations): string;
19
20
  cssText(): {
20
21
  reset: string;
@@ -90,6 +90,9 @@ var StyleRegistry = class {
90
90
  }
91
91
  return className;
92
92
  }
93
+ hasClass(className) {
94
+ return this.classNames.has(className);
95
+ }
93
96
  resetClass(className, declarations) {
94
97
  if (this.classNames.has(className)) return className;
95
98
  this.classNames.set(className, className);
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","names":[],"sources":["../../src/style/registry.ts"],"sourcesContent":["import { hasDOM } from '../utils/env'\nimport type { CSSDeclarations } from './types'\n\n// Three style elements, and with equal specificity the later sheet wins:\n// - the reset rules of the components, which stand for the defaults of native layout,\n// - the shorthand rules of the app's styles,\n// - the longhand rules of the app's styles.\n// So any style of the app beats a default, and a longhand always beats a shorthand, as on native.\nexport const RESET_STYLE_ID = 'rootnative-style-reset'\nexport const SHORTHAND_STYLE_ID = 'rootnative-style-shorthand'\nexport const LONGHAND_STYLE_ID = 'rootnative-style-longhand'\n\nconst SHEET_ORDER = [RESET_STYLE_ID, SHORTHAND_STYLE_ID, LONGHAND_STYLE_ID] as const\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\nexport const isShorthandProperty = (name: string): boolean => shorthandProperties.has(name)\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 = {\n reset: CSSStyleSheet | null\n shorthand: CSSStyleSheet | null\n longhand: CSSStyleSheet | null\n}\n\nexport class StyleRegistry {\n private readonly classNames = new Map<string, string>()\n private readonly adopted = new Set<string>()\n private readonly resetRules: string[] = []\n private readonly shorthandRules: string[] = []\n private readonly longhandRules: string[] = []\n private readonly sheets: StyleSheets\n\n constructor(sheets: StyleSheets = { reset: null, shorthand: null, longhand: null }) {\n this.sheets = sheets\n this.adopt(sheets.reset)\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 = isShorthandProperty(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 // Inserts the default style of a component as one rule in the reset sheet, once. Its class\n // name is its own, never an atomic one, so a style of the app with the same declaration\n // still gets an atomic class that beats the default.\n resetClass(className: string, declarations: CSSDeclarations): string {\n if (this.classNames.has(className)) return className\n this.classNames.set(className, className)\n const body = Object.entries(declarations)\n .map(([property, value]) => `${toKebab(property)}:${value}`)\n .join(';')\n const rule = `.${className}{${body}}`\n this.resetRules.push(rule)\n if (!this.adopted.has(className)) {\n const sheet = this.sheets.reset\n sheet?.insertRule(rule, sheet.cssRules.length)\n }\n return className\n }\n\n // The rules of each sheet, for server rendering.\n cssText(): { reset: string; shorthand: string; longhand: string } {\n return {\n reset: this.resetRules.join('\\n'),\n shorthand: this.shorthandRules.join('\\n'),\n longhand: this.longhandRules.join('\\n'),\n }\n }\n\n get ruleCount(): number {\n return this.resetRules.length + 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 ? {\n reset: domSheet(RESET_STYLE_ID),\n shorthand: domSheet(SHORTHAND_STYLE_ID),\n longhand: domSheet(LONGHAND_STYLE_ID),\n }\n : { reset: null, 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 for (const id of SHEET_ORDER) document.getElementById(id)?.remove()\n}\n\n// A new style element goes before the sheets that must come after it. A page from an older\n// server can have the other two sheets already.\nconst domSheet = (id: (typeof SHEET_ORDER)[number]): CSSStyleSheet => {\n let element = document.getElementById(id) as HTMLStyleElement | null\n if (element === null) {\n element = document.createElement('style')\n element.id = id\n const later = SHEET_ORDER.slice(SHEET_ORDER.indexOf(id) + 1)\n .map((name) => document.getElementById(name))\n .find((found) => found !== null)\n if (later === undefined || later === null) document.head.appendChild(element)\n else later.before(element)\n }\n return element.sheet as CSSStyleSheet\n}\n"],"mappings":";;AAQA,MAAa,iBAAiB;AAC9B,MAAa,qBAAqB;AAClC,MAAa,oBAAoB;AAEjC,MAAM,cAAc;CAAC;CAAgB;CAAoB;AAAiB;AAE1E,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,MAAa,uBAAuB,SAA0B,oBAAoB,IAAI,IAAI;AAE1F,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,CAAG,SAAS,EAAE;AAC9B;AAQA,IAAa,gBAAb,MAA2B;CAQzB,YAAY,SAAsB;EAAE,OAAO;EAAM,WAAW;EAAM,UAAU;CAAK,GAAG;EAPpF,KAAiB,6BAAa,IAAI,IAAoB;EACtD,KAAiB,0BAAU,IAAI,IAAY;EAC3C,KAAiB,aAAuB,CAAC;EACzC,KAAiB,iBAA2B,CAAC;EAC7C,KAAiB,gBAA0B,CAAC;EAI1C,KAAK,SAAS;EACd,KAAK,MAAM,OAAO,KAAK;EACvB,KAAK,MAAM,OAAO,SAAS;EAC3B,KAAK,MAAM,OAAO,QAAQ;CAC5B;CAEA,SAAS,UAAk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UAAU,MAAM,SAAS,KAAK,YAAY,OAAO;OACvE,MAAM,OAAO,OAAO;CAC3B;CACA,OAAO,QAAQ;AACjB"}
1
+ {"version":3,"file":"registry.js","names":[],"sources":["../../src/style/registry.ts"],"sourcesContent":["import { hasDOM } from '../utils/env'\nimport type { CSSDeclarations } from './types'\n\n// Three style elements, and with equal specificity the later sheet wins:\n// - the reset rules of the components, which stand for the defaults of native layout,\n// - the shorthand rules of the app's styles,\n// - the longhand rules of the app's styles.\n// So any style of the app beats a default, and a longhand always beats a shorthand, as on native.\nexport const RESET_STYLE_ID = 'rootnative-style-reset'\nexport const SHORTHAND_STYLE_ID = 'rootnative-style-shorthand'\nexport const LONGHAND_STYLE_ID = 'rootnative-style-longhand'\n\nconst SHEET_ORDER = [RESET_STYLE_ID, SHORTHAND_STYLE_ID, LONGHAND_STYLE_ID] as const\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\nexport const isShorthandProperty = (name: string): boolean => shorthandProperties.has(name)\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 = {\n reset: CSSStyleSheet | null\n shorthand: CSSStyleSheet | null\n longhand: CSSStyleSheet | null\n}\n\nexport class StyleRegistry {\n private readonly classNames = new Map<string, string>()\n private readonly adopted = new Set<string>()\n private readonly resetRules: string[] = []\n private readonly shorthandRules: string[] = []\n private readonly longhandRules: string[] = []\n private readonly sheets: StyleSheets\n\n constructor(sheets: StyleSheets = { reset: null, shorthand: null, longhand: null }) {\n this.sheets = sheets\n this.adopt(sheets.reset)\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 = isShorthandProperty(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 // True for a class of `staticClass` or `resetClass` that this registry already has.\n hasClass(className: string): boolean {\n return this.classNames.has(className)\n }\n\n // Inserts the default style of a component as one rule in the reset sheet, once. Its class\n // name is its own, never an atomic one, so a style of the app with the same declaration\n // still gets an atomic class that beats the default.\n resetClass(className: string, declarations: CSSDeclarations): string {\n if (this.classNames.has(className)) return className\n this.classNames.set(className, className)\n const body = Object.entries(declarations)\n .map(([property, value]) => `${toKebab(property)}:${value}`)\n .join(';')\n const rule = `.${className}{${body}}`\n this.resetRules.push(rule)\n if (!this.adopted.has(className)) {\n const sheet = this.sheets.reset\n sheet?.insertRule(rule, sheet.cssRules.length)\n }\n return className\n }\n\n // The rules of each sheet, for server rendering.\n cssText(): { reset: string; shorthand: string; longhand: string } {\n return {\n reset: this.resetRules.join('\\n'),\n shorthand: this.shorthandRules.join('\\n'),\n longhand: this.longhandRules.join('\\n'),\n }\n }\n\n get ruleCount(): number {\n return this.resetRules.length + 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 ? {\n reset: domSheet(RESET_STYLE_ID),\n shorthand: domSheet(SHORTHAND_STYLE_ID),\n longhand: domSheet(LONGHAND_STYLE_ID),\n }\n : { reset: null, 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 for (const id of SHEET_ORDER) document.getElementById(id)?.remove()\n}\n\n// A new style element goes before the sheets that must come after it. A page from an older\n// server can have the other two sheets already.\nconst domSheet = (id: (typeof SHEET_ORDER)[number]): CSSStyleSheet => {\n let element = document.getElementById(id) as HTMLStyleElement | null\n if (element === null) {\n element = document.createElement('style')\n element.id = id\n const later = SHEET_ORDER.slice(SHEET_ORDER.indexOf(id) + 1)\n .map((name) => document.getElementById(name))\n .find((found) => found !== null)\n if (later === undefined || later === null) document.head.appendChild(element)\n else later.before(element)\n }\n return element.sheet as CSSStyleSheet\n}\n"],"mappings":";;AAQA,MAAa,iBAAiB;AAC9B,MAAa,qBAAqB;AAClC,MAAa,oBAAoB;AAEjC,MAAM,cAAc;CAAC;CAAgB;CAAoB;AAAiB;AAE1E,MAAM,sCAA2C,IAAI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AK,eAAe,KAAK,IAAI;GACxC,UAAU,KAAK,cAAc,KAAK,IAAI;EACxC;CACF;CAEA,IAAI,YAAoB;EACtB,OAAO,KAAK,WAAW,SAAS,KAAK,eAAe,SAAS,KAAK,cAAc;CAClF;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;EACE,OAAO,SAAS,cAAc;EAC9B,WAAW,SAAS,kBAAkB;EACtC,UAAU,SAAS,iBAAiB;CACtC,IACA;EAAE,OAAO;EAAM,WAAW;EAAM,UAAU;CAAK,CACrD;CACA,OAAO;AACT;AAWA,MAAM,YAAY,OAAoD;CACpE,IAAI,UAAU,SAAS,eAAe,EAAE;CACxC,IAAI,YAAY,MAAM;EACpB,UAAU,SAAS,cAAc,OAAO;EACxC,QAAQ,KAAK;EACb,MAAM,QAAQ,YAAY,MAAM,YAAY,QAAQ,EAAE,IAAI,CAAC,CAAC,CACzD,KAAK,SAAS,SAAS,eAAe,IAAI,CAAC,CAAC,CAC5C,MAAM,UAAU,UAAU,IAAI;EACjC,IAAI,UAAU,KAAA,KAAa,UAAU,MAAM,SAAS,KAAK,YAAY,OAAO;OACvE,MAAM,OAAO,OAAO;CAC3B;CACA,OAAO,QAAQ;AACjB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rootnative/web",
3
- "version": "0.0.0-alpha.4",
3
+ "version": "0.0.0-alpha.5",
4
4
  "description": "A standalone web runtime for React Native apps",
5
5
  "license": "MIT",
6
6
  "homepage": "https://rootnative.github.io/web/",