@relo-ui/web 0.0.0-stage → 0.1.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -2
- package/dist/LICENSE +202 -0
- package/dist/NOTICE +5 -0
- package/dist/core/contracts.d.ts +72 -0
- package/dist/core/contracts.js +76 -0
- package/dist/core/document.d.ts +16 -0
- package/dist/core/document.js +21 -0
- package/dist/core/engine.d.ts +8 -0
- package/dist/core/engine.js +28 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.js +7 -0
- package/dist/core/runtime.d.ts +23 -0
- package/dist/core/runtime.js +46 -0
- package/dist/core/schema.d.ts +56 -0
- package/dist/core/schema.js +72 -0
- package/dist/core/session.d.ts +88 -0
- package/dist/core/session.js +520 -0
- package/dist/core/value.d.ts +18 -0
- package/dist/core/value.js +118 -0
- package/dist/dom/accessibility.d.ts +2 -0
- package/dist/dom/accessibility.js +69 -0
- package/dist/dom/icons.d.ts +1 -0
- package/dist/dom/icons.js +21 -0
- package/dist/dom/images.d.ts +59 -0
- package/dist/dom/images.js +406 -0
- package/dist/dom/index.d.ts +3 -0
- package/dist/dom/index.js +2 -0
- package/dist/dom/inputs.d.ts +5 -0
- package/dist/dom/inputs.js +85 -0
- package/dist/dom/lists.d.ts +7 -0
- package/dist/dom/lists.js +48 -0
- package/dist/dom/measurement.d.ts +16 -0
- package/dist/dom/measurement.js +67 -0
- package/dist/dom/motion-lifecycle.d.ts +17 -0
- package/dist/dom/motion-lifecycle.js +28 -0
- package/dist/dom/motion-plan.d.ts +44 -0
- package/dist/dom/motion-plan.js +31 -0
- package/dist/dom/motion.d.ts +73 -0
- package/dist/dom/motion.js +817 -0
- package/dist/dom/mount-plan.d.ts +15 -0
- package/dist/dom/mount-plan.js +58 -0
- package/dist/dom/presentation.d.ts +11 -0
- package/dist/dom/presentation.js +331 -0
- package/dist/dom/primitives.d.ts +16 -0
- package/dist/dom/primitives.js +378 -0
- package/dist/dom/range.d.ts +9 -0
- package/dist/dom/range.js +120 -0
- package/dist/dom/renderer.d.ts +99 -0
- package/dist/dom/renderer.js +1041 -0
- package/dist/dom/scroll.d.ts +7 -0
- package/dist/dom/scroll.js +167 -0
- package/dist/dom/shared-layout.d.ts +40 -0
- package/dist/dom/shared-layout.js +440 -0
- package/dist/dom/style.d.ts +35 -0
- package/dist/dom/style.js +337 -0
- package/dist/dom/text-motion.d.ts +17 -0
- package/dist/dom/text-motion.js +185 -0
- package/dist/dom/theme.d.ts +13 -0
- package/dist/dom/theme.js +65 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +18 -0
- package/dist/licenses/Rust-COPYRIGHT-library.html +29357 -0
- package/dist/licenses/archery-1.2.3/LICENSE.md +21 -0
- package/dist/licenses/bytemuck-1.25.2/LICENSE-APACHE +61 -0
- package/dist/licenses/bytemuck-1.25.2/LICENSE-MIT +9 -0
- package/dist/licenses/bytemuck-1.25.2/LICENSE-ZLIB +11 -0
- package/dist/licenses/cargo.json +340 -0
- package/dist/licenses/cfg-if-1.0.5/LICENSE-APACHE +201 -0
- package/dist/licenses/cfg-if-1.0.5/LICENSE-MIT +25 -0
- package/dist/licenses/equivalent-1.0.2/LICENSE-APACHE +201 -0
- package/dist/licenses/equivalent-1.0.2/LICENSE-MIT +25 -0
- package/dist/licenses/futures-core-0.3.34/LICENSE-APACHE +202 -0
- package/dist/licenses/futures-core-0.3.34/LICENSE-MIT +26 -0
- package/dist/licenses/futures-task-0.3.34/LICENSE-APACHE +202 -0
- package/dist/licenses/futures-task-0.3.34/LICENSE-MIT +26 -0
- package/dist/licenses/futures-util-0.3.34/LICENSE-APACHE +202 -0
- package/dist/licenses/futures-util-0.3.34/LICENSE-MIT +26 -0
- package/dist/licenses/imbl-7.0.2/LICENCE.md +355 -0
- package/dist/licenses/imbl-sized-chunks-0.2.0/LICENCE.md +355 -0
- package/dist/licenses/itoa-1.0.18/LICENSE-APACHE +176 -0
- package/dist/licenses/itoa-1.0.18/LICENSE-MIT +23 -0
- package/dist/licenses/js-sys-0.3.106/LICENSE-APACHE +201 -0
- package/dist/licenses/js-sys-0.3.106/LICENSE-MIT +25 -0
- package/dist/licenses/memchr-2.8.3/COPYING +3 -0
- package/dist/licenses/memchr-2.8.3/LICENSE-MIT +21 -0
- package/dist/licenses/once_cell-1.21.4/LICENSE-APACHE +201 -0
- package/dist/licenses/once_cell-1.21.4/LICENSE-MIT +23 -0
- package/dist/licenses/pin-project-lite-0.2.17/LICENSE-APACHE +177 -0
- package/dist/licenses/pin-project-lite-0.2.17/LICENSE-MIT +23 -0
- package/dist/licenses/rand_core-0.9.5/COPYRIGHT +12 -0
- package/dist/licenses/rand_core-0.9.5/LICENSE-APACHE +187 -0
- package/dist/licenses/rand_core-0.9.5/LICENSE-MIT +26 -0
- package/dist/licenses/rand_xoshiro-0.7.0/COPYRIGHT +12 -0
- package/dist/licenses/rand_xoshiro-0.7.0/LICENSE-APACHE +176 -0
- package/dist/licenses/rand_xoshiro-0.7.0/LICENSE-MIT +25 -0
- package/dist/licenses/roxmltree-0.21.1/LICENSE-APACHE +201 -0
- package/dist/licenses/roxmltree-0.21.1/LICENSE-MIT +21 -0
- package/dist/licenses/safe_arch-0.7.4/LICENSE-APACHE.md +61 -0
- package/dist/licenses/safe_arch-0.7.4/LICENSE-MIT.md +9 -0
- package/dist/licenses/safe_arch-0.7.4/LICENSE-ZLIB.md +11 -0
- package/dist/licenses/serde-1.0.229/LICENSE-APACHE +176 -0
- package/dist/licenses/serde-1.0.229/LICENSE-MIT +23 -0
- package/dist/licenses/serde_core-1.0.229/LICENSE-APACHE +176 -0
- package/dist/licenses/serde_core-1.0.229/LICENSE-MIT +23 -0
- package/dist/licenses/serde_json-1.0.151/LICENSE-APACHE +176 -0
- package/dist/licenses/serde_json-1.0.151/LICENSE-MIT +23 -0
- package/dist/licenses/slab-0.4.12/LICENSE +25 -0
- package/dist/licenses/slotmap-1.1.1/LICENSE +19 -0
- package/dist/licenses/smallvec-1.16.3/LICENSE-APACHE +201 -0
- package/dist/licenses/smallvec-1.16.3/LICENSE-MIT +25 -0
- package/dist/licenses/taffy-0.15.0/taffy-0.15.0-LICENSE +22 -0
- package/dist/licenses/unicode-ident-1.0.26/LICENSE-APACHE +176 -0
- package/dist/licenses/unicode-ident-1.0.26/LICENSE-MIT +23 -0
- package/dist/licenses/unicode-ident-1.0.26/LICENSE-UNICODE +39 -0
- package/dist/licenses/wasm-bindgen-0.2.129/LICENSE-APACHE +201 -0
- package/dist/licenses/wasm-bindgen-0.2.129/LICENSE-MIT +25 -0
- package/dist/licenses/wasm-bindgen-shared-0.2.129/LICENSE-APACHE +201 -0
- package/dist/licenses/wasm-bindgen-shared-0.2.129/LICENSE-MIT +25 -0
- package/dist/licenses/web-time-1.1.0/LICENSE-APACHE +201 -0
- package/dist/licenses/web-time-1.1.0/LICENSE-MIT +21 -0
- package/dist/licenses/wide-0.7.33/LICENSE-ZLIB.md +11 -0
- package/dist/licenses/zmij-1.0.23/LICENSE-MIT +23 -0
- package/dist/wasm/relo_wasm.d.ts +179 -0
- package/dist/wasm/relo_wasm.js +1228 -0
- package/dist/wasm/relo_wasm_bg.wasm +0 -0
- package/dist/wasm/relo_wasm_bg.wasm.d.ts +65 -0
- package/package.json +25 -4
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { RenderNode } from '../core/session.js';
|
|
2
|
+
/** Inset shadows preserve fractional stroke widths without changing layout. */
|
|
3
|
+
export declare function chromeShadow(border: number, borderColor: string, shadow: number): string;
|
|
4
|
+
export interface Length {
|
|
5
|
+
fixed?: number;
|
|
6
|
+
fraction?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface LayoutStyle {
|
|
9
|
+
horizontal: boolean | null;
|
|
10
|
+
reverse: boolean;
|
|
11
|
+
wrap: boolean;
|
|
12
|
+
wrapReverse: boolean;
|
|
13
|
+
grow: number;
|
|
14
|
+
shrink: number;
|
|
15
|
+
basis: Length | null;
|
|
16
|
+
width: Length | null;
|
|
17
|
+
height: Length | null;
|
|
18
|
+
aspect: number | null;
|
|
19
|
+
minWidth: Length | null;
|
|
20
|
+
minHeight: Length | null;
|
|
21
|
+
maxWidth: Length | null;
|
|
22
|
+
maxHeight: Length | null;
|
|
23
|
+
gapX: number;
|
|
24
|
+
gapY: number;
|
|
25
|
+
align: string;
|
|
26
|
+
self: string | null;
|
|
27
|
+
justify: string;
|
|
28
|
+
content: string;
|
|
29
|
+
stretchLines: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare function layoutStyle(classes: string): LayoutStyle;
|
|
32
|
+
export declare function length(value: Length | null, limit?: number): number | undefined;
|
|
33
|
+
export declare function color(node: RenderNode, name: string, dark: boolean): string;
|
|
34
|
+
export declare function paint(element: HTMLElement, control: HTMLElement | SVGElement | undefined, node: RenderNode, dark: boolean, focused?: boolean, pressed?: boolean, reduced?: boolean): string;
|
|
35
|
+
export declare const surfaceCSS = "\n.relo-surface{position:relative;isolation:isolate;color-scheme:light dark;font:15px/1.4 system-ui,sans-serif;min-width:0}\n.relo-surface .relo-box{position:absolute;box-sizing:border-box;margin:0;min-width:0;min-height:0}\n.relo-surface .relo-control{box-sizing:border-box;display:block;margin:0;max-width:100%;font:inherit;color:inherit}\n.relo-surface button.relo-control{cursor:pointer;min-height:44px;padding:8px 12px;border:1px solid #aaa;border-radius:6px;background:transparent}\n.relo-surface input.relo-control:not([type=checkbox]),.relo-surface textarea.relo-control{min-height:44px;padding:8px;border:1px solid #aaa;border-radius:6px;background:transparent;width:100%}\n.relo-surface [data-relo-activation]{position:relative;cursor:pointer;isolation:isolate;user-select:none;-webkit-user-select:none;touch-action:manipulation}\n.relo-surface [data-relo-activation]::after,.relo-surface button.relo-control::after{content:'';position:absolute;top:50%;left:50%;width:max(100%,48px);height:max(100%,48px);transform:translate(-50%,-50%);z-index:-1}\n.relo-surface .relo-control:focus-visible{outline:2px solid currentColor;outline-offset:2px}\n.relo-surface .relo-box[hidden]{display:none!important}\n.relo-surface .relo-scroll{position:relative;width:100%;height:100%;overflow:auto;overscroll-behavior:auto contain;scrollbar-width:thin;scrollbar-color:#8886 transparent}\n.relo-surface .relo-scroll::-webkit-scrollbar{width:6px;height:6px}\n.relo-surface .relo-scroll::-webkit-scrollbar-track,.relo-surface .relo-scroll::-webkit-scrollbar-corner{background:transparent}\n.relo-surface .relo-scroll::-webkit-scrollbar-thumb{background:#8886;border-radius:999px}\n.relo-surface .relo-scroll::-webkit-scrollbar-thumb:hover{background:#888a}\n.relo-surface .relo-scrollbar{appearance:none;background:transparent;border:0!important;padding:0!important}\n.relo-surface .relo-scrollbar::-webkit-slider-runnable-track{background:#8883;width:var(--relo-track-width,100%);height:var(--relo-track-height,4px);border-radius:2px}\n.relo-surface .relo-scrollbar::-webkit-slider-thumb{appearance:none;width:var(--relo-thumb-width,20%);height:var(--relo-thumb-height,4px);transform:translate(var(--relo-scrollbar-x,0px),var(--relo-scrollbar-y,0px));background:currentColor;border-radius:2px}\n.relo-surface .relo-scrollbar::-moz-range-track{background:#8883;width:var(--relo-track-width,100%);height:var(--relo-track-height,4px);border-radius:2px}\n.relo-surface .relo-scrollbar::-moz-range-thumb{width:var(--relo-thumb-width,20%);height:var(--relo-thumb-height,4px);transform:translate(var(--relo-scrollbar-x,0px),var(--relo-scrollbar-y,0px));background:currentColor;border:0;border-radius:2px}\n";
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { getEngine } from '../core/engine.js';
|
|
2
|
+
import { motionPlan, usesPaintedBorder } from './motion-plan.js';
|
|
3
|
+
/** Inset shadows preserve fractional stroke widths without changing layout. */
|
|
4
|
+
export function chromeShadow(border, borderColor, shadow) {
|
|
5
|
+
return ([
|
|
6
|
+
border > 0 ? `inset 0 0 0 ${border}px ${borderColor}` : '',
|
|
7
|
+
shadow > 0 ? `0 1px 3px rgba(0,0,0,${0.14 * shadow})` : '',
|
|
8
|
+
]
|
|
9
|
+
.filter(Boolean)
|
|
10
|
+
.join(', ') || 'none');
|
|
11
|
+
}
|
|
12
|
+
const cache = new Map();
|
|
13
|
+
let cacheBytes = 0;
|
|
14
|
+
export function layoutStyle(classes) {
|
|
15
|
+
let value = cache.get(classes);
|
|
16
|
+
if (value) {
|
|
17
|
+
cache.delete(classes);
|
|
18
|
+
cache.set(classes, value);
|
|
19
|
+
}
|
|
20
|
+
if (!value) {
|
|
21
|
+
value = JSON.parse(getEngine().layout_style(classes));
|
|
22
|
+
const bytes = classes.length * 2 + 1024;
|
|
23
|
+
if (bytes <= 1024 * 1024) {
|
|
24
|
+
// Match native's style working set, with an additional byte bound.
|
|
25
|
+
while (cache.size && (cache.size >= 512 || cacheBytes + bytes > 1024 * 1024)) {
|
|
26
|
+
const oldest = cache.keys().next().value;
|
|
27
|
+
cacheBytes -= oldest.length * 2 + 1024;
|
|
28
|
+
cache.delete(oldest);
|
|
29
|
+
}
|
|
30
|
+
cacheBytes += bytes;
|
|
31
|
+
cache.set(classes, value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
export function length(value, limit) {
|
|
37
|
+
return (value?.fixed ??
|
|
38
|
+
(limit !== undefined && value?.fraction !== undefined ? limit * value.fraction : undefined));
|
|
39
|
+
}
|
|
40
|
+
// Tailwind's default zinc/blue/red/green/amber palette (sRGB hex equivalents).
|
|
41
|
+
const colors = {
|
|
42
|
+
foreground: '#18181b',
|
|
43
|
+
primary: '#18181b',
|
|
44
|
+
background: '#fafafa',
|
|
45
|
+
surface: '#ffffff',
|
|
46
|
+
card: '#ffffff',
|
|
47
|
+
'card-foreground': '#18181b',
|
|
48
|
+
muted: '#f4f4f5',
|
|
49
|
+
secondary: '#71717a',
|
|
50
|
+
'muted-foreground': '#71717a',
|
|
51
|
+
'secondary-foreground': '#18181b',
|
|
52
|
+
border: '#e4e4e7',
|
|
53
|
+
separator: '#e4e4e7',
|
|
54
|
+
input: '#e4e4e7',
|
|
55
|
+
ring: '#155dfb',
|
|
56
|
+
accent: '#155dfb',
|
|
57
|
+
'accent-foreground': '#ffffff',
|
|
58
|
+
'on-accent': '#ffffff',
|
|
59
|
+
'primary-foreground': '#fafafa',
|
|
60
|
+
danger: '#e7000b',
|
|
61
|
+
destructive: '#e7000b',
|
|
62
|
+
'on-danger': '#ffffff',
|
|
63
|
+
'destructive-foreground': '#ffffff',
|
|
64
|
+
'surface-disabled': '#f4f4f5',
|
|
65
|
+
disabled: '#71717a',
|
|
66
|
+
success: '#008236',
|
|
67
|
+
'on-success': '#ffffff',
|
|
68
|
+
warning: '#a65f00',
|
|
69
|
+
};
|
|
70
|
+
const darkColors = {
|
|
71
|
+
foreground: '#fafafa',
|
|
72
|
+
primary: '#fafafa',
|
|
73
|
+
background: '#09090b',
|
|
74
|
+
surface: '#18181b',
|
|
75
|
+
card: '#18181b',
|
|
76
|
+
'card-foreground': '#fafafa',
|
|
77
|
+
muted: '#27272a',
|
|
78
|
+
secondary: '#a1a1aa',
|
|
79
|
+
'muted-foreground': '#a1a1aa',
|
|
80
|
+
border: '#3f3f46',
|
|
81
|
+
separator: '#3f3f46',
|
|
82
|
+
input: '#3f3f46',
|
|
83
|
+
accent: '#51a2ff',
|
|
84
|
+
ring: '#51a2ff',
|
|
85
|
+
'primary-foreground': '#09090b',
|
|
86
|
+
'on-accent': '#162456',
|
|
87
|
+
'accent-foreground': '#162456',
|
|
88
|
+
'secondary-foreground': '#fafafa',
|
|
89
|
+
'surface-disabled': '#27272a',
|
|
90
|
+
disabled: '#a1a1aa',
|
|
91
|
+
danger: '#ff6467',
|
|
92
|
+
destructive: '#ff6467',
|
|
93
|
+
'on-danger': '#460809',
|
|
94
|
+
'destructive-foreground': '#460809',
|
|
95
|
+
success: '#7bf1a8',
|
|
96
|
+
'on-success': '#032e15',
|
|
97
|
+
warning: '#ffd230',
|
|
98
|
+
};
|
|
99
|
+
export function color(node, name, dark) {
|
|
100
|
+
const scoped = node.theme.colors[name];
|
|
101
|
+
return (scoped?.[dark ? 'dark' : 'light'] ??
|
|
102
|
+
scoped?.light ??
|
|
103
|
+
scoped?.dark ??
|
|
104
|
+
(dark ? darkColors[name] : undefined) ??
|
|
105
|
+
colors[name] ??
|
|
106
|
+
'transparent');
|
|
107
|
+
}
|
|
108
|
+
const themeExpansions = new WeakMap();
|
|
109
|
+
function expandTheme(node, control) {
|
|
110
|
+
let entries = themeExpansions.get(node.theme);
|
|
111
|
+
if (!entries) {
|
|
112
|
+
entries = new Map();
|
|
113
|
+
themeExpansions.set(node.theme, entries);
|
|
114
|
+
}
|
|
115
|
+
const key = `${control}|${node.classes}`;
|
|
116
|
+
const cached = entries.get(key);
|
|
117
|
+
if (cached !== undefined)
|
|
118
|
+
return cached;
|
|
119
|
+
const expanded = getEngine().expand_theme(JSON.stringify(node.theme), node.classes, control);
|
|
120
|
+
// Bound retained classes per live theme; themes themselves are weakly held.
|
|
121
|
+
if (key.length + expanded.length <= 16_384) {
|
|
122
|
+
if (entries.size >= 128)
|
|
123
|
+
entries.delete(entries.keys().next().value);
|
|
124
|
+
entries.set(key, expanded);
|
|
125
|
+
}
|
|
126
|
+
return expanded;
|
|
127
|
+
}
|
|
128
|
+
export function paint(element, control, node, dark, focused = false, pressed = false, reduced = false) {
|
|
129
|
+
const style = element.style, target = control?.style ?? style;
|
|
130
|
+
const expanded = expandTheme(node, !!control);
|
|
131
|
+
const bits = (node.props.selected ? 1 : 0) |
|
|
132
|
+
(node.props.expanded ? 2 : 0) |
|
|
133
|
+
(pressed ? 4 : 0) |
|
|
134
|
+
(focused ? 8 : 0) |
|
|
135
|
+
(node.props.validationMessage ? 16 : 0) |
|
|
136
|
+
(node.props.enabled === false ? 32 : 0);
|
|
137
|
+
const plan = motionPlan(expanded, bits, reduced);
|
|
138
|
+
const styles = plan.style;
|
|
139
|
+
style.padding = '0px';
|
|
140
|
+
style.border = '0 solid transparent';
|
|
141
|
+
style.borderRadius = '0';
|
|
142
|
+
style.boxShadow = 'none';
|
|
143
|
+
style.overflow = 'visible';
|
|
144
|
+
style.opacity = '1';
|
|
145
|
+
style.backgroundColor = 'transparent';
|
|
146
|
+
style.color = color(node, 'foreground', dark);
|
|
147
|
+
const scale = node.theme.textScale ?? 1;
|
|
148
|
+
style.font = `${(15 * scale) / 16}rem/1.4 system-ui, sans-serif`;
|
|
149
|
+
style.textDecoration = 'none';
|
|
150
|
+
style.textAlign = 'start';
|
|
151
|
+
const tokens = styles.split(/\s+/);
|
|
152
|
+
const input = ['TextField', 'TextArea'].includes(node.type);
|
|
153
|
+
style.setProperty('--relo-danger', color(node, 'danger', dark));
|
|
154
|
+
style.setProperty('--relo-accent', color(node, 'accent', dark));
|
|
155
|
+
style.setProperty('--relo-input-background', color(node, tokens.includes('input-filled') ? 'muted' : 'card', dark));
|
|
156
|
+
style.setProperty('--relo-input-border', color(node, node.props.validationMessage ? 'danger' : focused ? 'ring' : 'input', dark));
|
|
157
|
+
style.setProperty('--relo-input-border-width', focused ? '2px' : '1px');
|
|
158
|
+
style.setProperty('--relo-input-radius', `${node.theme.radii.control ?? 8}px`);
|
|
159
|
+
if (node.type === 'Button') {
|
|
160
|
+
style.fontSize = `${((node.theme.fonts.button ?? 14) * scale) / 16}rem`;
|
|
161
|
+
style.fontWeight = '700';
|
|
162
|
+
style.padding = '10px 16px';
|
|
163
|
+
style.borderRadius = `${node.theme.radii.control ?? 8}px`;
|
|
164
|
+
if (tokens.includes('button-prominent')) {
|
|
165
|
+
style.backgroundColor = color(node, 'accent', dark);
|
|
166
|
+
style.color = color(node, 'on-accent', dark);
|
|
167
|
+
}
|
|
168
|
+
if (tokens.includes('button-bordered')) {
|
|
169
|
+
style.backgroundColor = color(node, 'card', dark);
|
|
170
|
+
style.border = `1px solid ${color(node, 'border', dark)}`;
|
|
171
|
+
}
|
|
172
|
+
if (node.props.enabled === false) {
|
|
173
|
+
style.backgroundColor = color(node, 'surface-disabled', dark);
|
|
174
|
+
style.color = color(node, 'disabled', dark);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const priority = (token) => Math.max(0, ...token
|
|
178
|
+
.split(':')
|
|
179
|
+
.slice(0, -1)
|
|
180
|
+
.map((part) => ['selected', 'expanded', 'pressed', 'focused', 'invalid', 'disabled'].indexOf(part) + 1));
|
|
181
|
+
for (const token of tokens.sort((a, b) => priority(a) - priority(b))) {
|
|
182
|
+
const parts = token.split(':');
|
|
183
|
+
const utility = parts.pop();
|
|
184
|
+
if (parts.some((part) => part === 'dark'
|
|
185
|
+
? !dark
|
|
186
|
+
: part === 'focus' || part === 'focused'
|
|
187
|
+
? !focused
|
|
188
|
+
: part === 'pressed'
|
|
189
|
+
? !pressed
|
|
190
|
+
: part === 'expanded'
|
|
191
|
+
? !node.props.expanded
|
|
192
|
+
: part === 'disabled'
|
|
193
|
+
? node.props.enabled !== false
|
|
194
|
+
: part === 'selected'
|
|
195
|
+
? !node.props.selected
|
|
196
|
+
: part === 'invalid'
|
|
197
|
+
? !node.props.validationMessage
|
|
198
|
+
: part === 'rtl'
|
|
199
|
+
? element.closest('[dir]')?.getAttribute('dir') !== 'rtl'
|
|
200
|
+
: true))
|
|
201
|
+
continue;
|
|
202
|
+
const spacing = /^p([xytsbelr]?)-(\d+(?:\.5)?)$/.exec(utility);
|
|
203
|
+
if (spacing) {
|
|
204
|
+
const size = `${Number(spacing[2]) * 4}px`;
|
|
205
|
+
const sides = {
|
|
206
|
+
'': ['Top', 'Right', 'Bottom', 'Left'],
|
|
207
|
+
x: ['Left', 'Right'],
|
|
208
|
+
y: ['Top', 'Bottom'],
|
|
209
|
+
t: ['Top'],
|
|
210
|
+
b: ['Bottom'],
|
|
211
|
+
l: ['Left'],
|
|
212
|
+
r: ['Right'],
|
|
213
|
+
s: ['InlineStart'],
|
|
214
|
+
e: ['InlineEnd'],
|
|
215
|
+
};
|
|
216
|
+
for (const side of sides[spacing[1]])
|
|
217
|
+
style[`padding${side}`] = size;
|
|
218
|
+
}
|
|
219
|
+
else if (utility.startsWith('bg-')) {
|
|
220
|
+
const value = color(node, utility.slice(3), dark);
|
|
221
|
+
if (input)
|
|
222
|
+
style.setProperty('--relo-input-background', value);
|
|
223
|
+
else
|
|
224
|
+
style.backgroundColor = value;
|
|
225
|
+
}
|
|
226
|
+
else if (utility.startsWith('border-') && !/^border-\d/.test(utility)) {
|
|
227
|
+
style.borderColor = color(node, utility.slice(7), dark);
|
|
228
|
+
if (input)
|
|
229
|
+
style.setProperty('--relo-input-border', style.borderColor);
|
|
230
|
+
}
|
|
231
|
+
else if (utility === 'border' || /^border-[02]$/.test(utility)) {
|
|
232
|
+
style.borderStyle = 'solid';
|
|
233
|
+
style.borderWidth = `${utility === 'border' ? 1 : Number(utility.slice(7))}px`;
|
|
234
|
+
if (input)
|
|
235
|
+
style.setProperty('--relo-input-border-width', style.borderWidth);
|
|
236
|
+
}
|
|
237
|
+
else if (utility.startsWith('rounded-')) {
|
|
238
|
+
const radius = utility.slice(8), scoped = node.theme.radii[radius];
|
|
239
|
+
style.borderRadius = `${scoped ?? { none: 0, sm: 4, md: 6, lg: 8, xl: 12, '2xl': 16, card: 12, control: 8, full: 9999 }[radius] ?? 0}px`;
|
|
240
|
+
}
|
|
241
|
+
else if (/^opacity-/.test(utility))
|
|
242
|
+
style.opacity = String(Number(utility.slice(8)) / 100);
|
|
243
|
+
else if (utility === 'overflow-hidden')
|
|
244
|
+
style.overflow = 'hidden';
|
|
245
|
+
else if (utility === 'shadow-none')
|
|
246
|
+
style.boxShadow = 'none';
|
|
247
|
+
else if (utility === 'shadow-sm')
|
|
248
|
+
style.boxShadow = '0 1px 3px #0002';
|
|
249
|
+
else if (utility === 'underline' || utility === 'line-through')
|
|
250
|
+
style.textDecoration = utility;
|
|
251
|
+
else if (utility.startsWith('text-')) {
|
|
252
|
+
const role = utility.slice(5);
|
|
253
|
+
const size = {
|
|
254
|
+
'large-title': 34,
|
|
255
|
+
title: 28,
|
|
256
|
+
headline: 18,
|
|
257
|
+
body: 15,
|
|
258
|
+
callout: 14,
|
|
259
|
+
caption: 12,
|
|
260
|
+
button: 14,
|
|
261
|
+
}[role];
|
|
262
|
+
if (size !== undefined)
|
|
263
|
+
style.fontSize = `${(size * scale) / 16}rem`;
|
|
264
|
+
else if (['left', 'right', 'center', 'start', 'end'].includes(role))
|
|
265
|
+
style.textAlign = role;
|
|
266
|
+
else
|
|
267
|
+
style.color = color(node, role, dark);
|
|
268
|
+
}
|
|
269
|
+
else if (utility.startsWith('font-')) {
|
|
270
|
+
const role = utility.slice(5);
|
|
271
|
+
const weight = { normal: '400', medium: '500', semibold: '600', bold: '700' }[role];
|
|
272
|
+
if (weight)
|
|
273
|
+
style.fontWeight = weight;
|
|
274
|
+
else {
|
|
275
|
+
const size = node.theme.fonts[role] ??
|
|
276
|
+
{
|
|
277
|
+
'large-title': 34,
|
|
278
|
+
title: 28,
|
|
279
|
+
headline: 18,
|
|
280
|
+
body: 15,
|
|
281
|
+
callout: 14,
|
|
282
|
+
caption: 12,
|
|
283
|
+
button: 14,
|
|
284
|
+
}[role];
|
|
285
|
+
if (size)
|
|
286
|
+
style.fontSize = `${(size * scale) / 16}rem`;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (node.type === 'Button' && control) {
|
|
291
|
+
Object.assign(target, {
|
|
292
|
+
padding: '0',
|
|
293
|
+
border: '0',
|
|
294
|
+
background: 'transparent',
|
|
295
|
+
borderRadius: 'inherit',
|
|
296
|
+
width: '100%',
|
|
297
|
+
minHeight: '0',
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
target.color = 'inherit';
|
|
301
|
+
target.font = 'inherit';
|
|
302
|
+
target.textAlign = 'inherit';
|
|
303
|
+
if (control)
|
|
304
|
+
target.textDecoration = 'inherit';
|
|
305
|
+
// Keep authored targets separate from sampled paint. CSS used border widths
|
|
306
|
+
// round to device pixels, and capsule radii are represented by a sentinel.
|
|
307
|
+
style.setProperty('--relo-radius-target', style.borderRadius);
|
|
308
|
+
style.setProperty('--relo-border-target', style.borderWidth);
|
|
309
|
+
const shadow = style.boxShadow === 'none' ? 0 : 1;
|
|
310
|
+
style.setProperty('--relo-shadow-target', String(shadow));
|
|
311
|
+
if (usesPaintedBorder(plan)) {
|
|
312
|
+
style.boxShadow = chromeShadow(parseFloat(style.borderWidth) || 0, style.borderColor, shadow);
|
|
313
|
+
style.borderWidth = '0px';
|
|
314
|
+
}
|
|
315
|
+
return expanded;
|
|
316
|
+
}
|
|
317
|
+
export const surfaceCSS = `
|
|
318
|
+
.relo-surface{position:relative;isolation:isolate;color-scheme:light dark;font:15px/1.4 system-ui,sans-serif;min-width:0}
|
|
319
|
+
.relo-surface .relo-box{position:absolute;box-sizing:border-box;margin:0;min-width:0;min-height:0}
|
|
320
|
+
.relo-surface .relo-control{box-sizing:border-box;display:block;margin:0;max-width:100%;font:inherit;color:inherit}
|
|
321
|
+
.relo-surface button.relo-control{cursor:pointer;min-height:44px;padding:8px 12px;border:1px solid #aaa;border-radius:6px;background:transparent}
|
|
322
|
+
.relo-surface input.relo-control:not([type=checkbox]),.relo-surface textarea.relo-control{min-height:44px;padding:8px;border:1px solid #aaa;border-radius:6px;background:transparent;width:100%}
|
|
323
|
+
.relo-surface [data-relo-activation]{position:relative;cursor:pointer;isolation:isolate;user-select:none;-webkit-user-select:none;touch-action:manipulation}
|
|
324
|
+
.relo-surface [data-relo-activation]::after,.relo-surface button.relo-control::after{content:'';position:absolute;top:50%;left:50%;width:max(100%,48px);height:max(100%,48px);transform:translate(-50%,-50%);z-index:-1}
|
|
325
|
+
.relo-surface .relo-control:focus-visible{outline:2px solid currentColor;outline-offset:2px}
|
|
326
|
+
.relo-surface .relo-box[hidden]{display:none!important}
|
|
327
|
+
.relo-surface .relo-scroll{position:relative;width:100%;height:100%;overflow:auto;overscroll-behavior:auto contain;scrollbar-width:thin;scrollbar-color:#8886 transparent}
|
|
328
|
+
.relo-surface .relo-scroll::-webkit-scrollbar{width:6px;height:6px}
|
|
329
|
+
.relo-surface .relo-scroll::-webkit-scrollbar-track,.relo-surface .relo-scroll::-webkit-scrollbar-corner{background:transparent}
|
|
330
|
+
.relo-surface .relo-scroll::-webkit-scrollbar-thumb{background:#8886;border-radius:999px}
|
|
331
|
+
.relo-surface .relo-scroll::-webkit-scrollbar-thumb:hover{background:#888a}
|
|
332
|
+
.relo-surface .relo-scrollbar{appearance:none;background:transparent;border:0!important;padding:0!important}
|
|
333
|
+
.relo-surface .relo-scrollbar::-webkit-slider-runnable-track{background:#8883;width:var(--relo-track-width,100%);height:var(--relo-track-height,4px);border-radius:2px}
|
|
334
|
+
.relo-surface .relo-scrollbar::-webkit-slider-thumb{appearance:none;width:var(--relo-thumb-width,20%);height:var(--relo-thumb-height,4px);transform:translate(var(--relo-scrollbar-x,0px),var(--relo-scrollbar-y,0px));background:currentColor;border-radius:2px}
|
|
335
|
+
.relo-surface .relo-scrollbar::-moz-range-track{background:#8883;width:var(--relo-track-width,100%);height:var(--relo-track-height,4px);border-radius:2px}
|
|
336
|
+
.relo-surface .relo-scrollbar::-moz-range-thumb{width:var(--relo-thumb-width,20%);height:var(--relo-thumb-height,4px);transform:translate(var(--relo-scrollbar-x,0px),var(--relo-scrollbar-y,0px));background:currentColor;border:0;border-radius:2px}
|
|
337
|
+
`;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Mounted } from './renderer.js';
|
|
2
|
+
export interface TextCapture {
|
|
3
|
+
image: HTMLElement;
|
|
4
|
+
signature: string;
|
|
5
|
+
pixels: number;
|
|
6
|
+
}
|
|
7
|
+
/** Inert DOM copies freeze browser-shaped text while real layout keeps running. */
|
|
8
|
+
export declare class TextMotion {
|
|
9
|
+
private readonly effects;
|
|
10
|
+
private capture;
|
|
11
|
+
before(nodes: Iterable<Mounted>): Map<string, TextCapture>;
|
|
12
|
+
after(captures: Map<string, TextCapture>, nodes: Iterable<Mounted>, now: number): void;
|
|
13
|
+
private release;
|
|
14
|
+
sample(now: number, layoutActive: boolean): void;
|
|
15
|
+
get active(): boolean;
|
|
16
|
+
clear(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { getEngine } from '../core/engine.js';
|
|
2
|
+
import { motionPlan } from './motion-plan.js';
|
|
3
|
+
const typography = [
|
|
4
|
+
'font',
|
|
5
|
+
'color',
|
|
6
|
+
'letter-spacing',
|
|
7
|
+
'word-spacing',
|
|
8
|
+
'white-space',
|
|
9
|
+
'text-align',
|
|
10
|
+
'text-decoration',
|
|
11
|
+
'text-transform',
|
|
12
|
+
'direction',
|
|
13
|
+
'overflow-wrap',
|
|
14
|
+
'word-break',
|
|
15
|
+
'line-height',
|
|
16
|
+
'display',
|
|
17
|
+
'-webkit-line-clamp',
|
|
18
|
+
'-webkit-box-orient',
|
|
19
|
+
'overflow',
|
|
20
|
+
];
|
|
21
|
+
/** Inert DOM copies freeze browser-shaped text while real layout keeps running. */
|
|
22
|
+
export class TextMotion {
|
|
23
|
+
effects = new Map();
|
|
24
|
+
capture(node, blend) {
|
|
25
|
+
const content = node.content, box = content.getBoundingClientRect(), css = getComputedStyle(content), pixels = box.width * box.height;
|
|
26
|
+
if (!box.width ||
|
|
27
|
+
!box.height ||
|
|
28
|
+
pixels > 1_000_000 ||
|
|
29
|
+
box.bottom < 0 ||
|
|
30
|
+
box.top > innerHeight ||
|
|
31
|
+
box.right < 0 ||
|
|
32
|
+
box.left > innerWidth ||
|
|
33
|
+
node.element.closest('[hidden],[inert]'))
|
|
34
|
+
return;
|
|
35
|
+
const existing = blend ? this.effects.get(node.node.id) : undefined;
|
|
36
|
+
const image = existing
|
|
37
|
+
? existing.layer.cloneNode(true)
|
|
38
|
+
: content.cloneNode(true);
|
|
39
|
+
// Repeated reversals have a bounded presentation history, just as raster captures do.
|
|
40
|
+
if (image.querySelectorAll('*').length > 128 || (image.textContent?.length ?? 0) > 65_536)
|
|
41
|
+
return;
|
|
42
|
+
image.removeAttribute('id');
|
|
43
|
+
image.removeAttribute('role');
|
|
44
|
+
image.removeAttribute('data-relo-text-crossfade');
|
|
45
|
+
image
|
|
46
|
+
.querySelectorAll('[data-relo-text-crossfade]')
|
|
47
|
+
.forEach((element) => element.removeAttribute('data-relo-text-crossfade'));
|
|
48
|
+
image.querySelectorAll('[id]').forEach((element) => element.removeAttribute('id'));
|
|
49
|
+
if (!existing) {
|
|
50
|
+
for (const property of typography)
|
|
51
|
+
image.style.setProperty(property, css.getPropertyValue(property));
|
|
52
|
+
Object.assign(image.style, {
|
|
53
|
+
position: 'absolute',
|
|
54
|
+
left: `${content.offsetLeft}px`,
|
|
55
|
+
top: `${content.offsetTop}px`,
|
|
56
|
+
width: `${box.width}px`,
|
|
57
|
+
height: `${box.height}px`,
|
|
58
|
+
opacity: '1',
|
|
59
|
+
margin: '0',
|
|
60
|
+
pointerEvents: 'none',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
image,
|
|
65
|
+
pixels: existing ? existing.pixels : pixels,
|
|
66
|
+
signature: `${content.textContent}|${box.width}|${box.height}|${typography.map((key) => css.getPropertyValue(key)).join('|')}`,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
before(nodes) {
|
|
70
|
+
const captures = new Map();
|
|
71
|
+
// Resolve inherited opt-in once per branch. Rewalking every text leaf's
|
|
72
|
+
// ancestry repeatedly compiled/looked up the same plans in large screens.
|
|
73
|
+
// Keep this local: parentage and classes can change on the next commit.
|
|
74
|
+
const inherited = new Map();
|
|
75
|
+
const opted = (node) => {
|
|
76
|
+
const cached = inherited.get(node);
|
|
77
|
+
if (cached !== undefined)
|
|
78
|
+
return cached;
|
|
79
|
+
const plan = motionPlan(node.extra.expanded ?? node.node.classes, 0, false);
|
|
80
|
+
const value = !!(plan.mask & 192) || !!(node.parent && opted(node.parent));
|
|
81
|
+
inherited.set(node, value);
|
|
82
|
+
return value;
|
|
83
|
+
};
|
|
84
|
+
let pixels = 0;
|
|
85
|
+
for (const node of nodes) {
|
|
86
|
+
if (node.node.type !== 'Text' ||
|
|
87
|
+
node.node.theme.motion !== 'system' ||
|
|
88
|
+
!opted(node) ||
|
|
89
|
+
captures.size >= 64)
|
|
90
|
+
continue;
|
|
91
|
+
const capture = this.capture(node, true);
|
|
92
|
+
if (capture && pixels + capture.pixels <= 4_000_000) {
|
|
93
|
+
captures.set(node.node.id, capture);
|
|
94
|
+
pixels += capture.pixels;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return captures;
|
|
98
|
+
}
|
|
99
|
+
after(captures, nodes, now) {
|
|
100
|
+
const retained = new Set();
|
|
101
|
+
let pixels = [...this.effects.values()].reduce((sum, effect) => sum + effect.pixels, 0);
|
|
102
|
+
for (const node of nodes) {
|
|
103
|
+
retained.add(node.node.id);
|
|
104
|
+
const old = captures.get(node.node.id);
|
|
105
|
+
if (!old)
|
|
106
|
+
continue;
|
|
107
|
+
const next = this.capture(node, false);
|
|
108
|
+
const previous = this.effects.get(node.node.id);
|
|
109
|
+
// During a reversal the live layout can already match the destination,
|
|
110
|
+
// while the visible blended layer still contains the previous target.
|
|
111
|
+
if (!next || (!previous && old.signature === next.signature))
|
|
112
|
+
continue;
|
|
113
|
+
if (previous?.signature === next.signature)
|
|
114
|
+
continue;
|
|
115
|
+
if (previous) {
|
|
116
|
+
pixels -= previous.pixels;
|
|
117
|
+
this.release(previous);
|
|
118
|
+
this.effects.delete(node.node.id);
|
|
119
|
+
}
|
|
120
|
+
if (this.effects.size >= 64 || pixels + old.pixels + next.pixels > 4_000_000)
|
|
121
|
+
continue;
|
|
122
|
+
const layer = document.createElement('span');
|
|
123
|
+
layer.dataset.reloTextCrossfade = '';
|
|
124
|
+
layer.inert = true;
|
|
125
|
+
layer.setAttribute('aria-hidden', 'true');
|
|
126
|
+
layer.style.cssText = 'position:absolute;left:0;top:0;pointer-events:none;overflow:visible';
|
|
127
|
+
const row = new Float64Array(32);
|
|
128
|
+
row[2] = row[3] = 0;
|
|
129
|
+
row[9] = 1;
|
|
130
|
+
row[10] = 0.15;
|
|
131
|
+
row[11] = 0;
|
|
132
|
+
row[13] = 0.001;
|
|
133
|
+
row[14] = 0.01;
|
|
134
|
+
row[16] = 1;
|
|
135
|
+
getEngine().motion_retarget(row, 1, now, true);
|
|
136
|
+
const content = node.content;
|
|
137
|
+
const effect = {
|
|
138
|
+
node,
|
|
139
|
+
layer,
|
|
140
|
+
signature: next.signature,
|
|
141
|
+
old: old.image,
|
|
142
|
+
next: next.image,
|
|
143
|
+
opacity: content.style.opacity,
|
|
144
|
+
row,
|
|
145
|
+
pixels: old.pixels + next.pixels,
|
|
146
|
+
};
|
|
147
|
+
content.style.opacity = '0';
|
|
148
|
+
next.image.style.opacity = '0';
|
|
149
|
+
layer.append(old.image, next.image);
|
|
150
|
+
node.element.append(layer);
|
|
151
|
+
this.effects.set(node.node.id, effect);
|
|
152
|
+
pixels += effect.pixels;
|
|
153
|
+
}
|
|
154
|
+
for (const [id, effect] of this.effects)
|
|
155
|
+
if (!retained.has(id) ||
|
|
156
|
+
!effect.node.node.shown ||
|
|
157
|
+
effect.node.element.closest('[hidden],[inert]')) {
|
|
158
|
+
this.release(effect);
|
|
159
|
+
this.effects.delete(id);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
release(effect) {
|
|
163
|
+
effect.node.content.style.opacity = effect.opacity;
|
|
164
|
+
effect.layer.remove();
|
|
165
|
+
}
|
|
166
|
+
sample(now, layoutActive) {
|
|
167
|
+
for (const [id, effect] of this.effects) {
|
|
168
|
+
getEngine().motion_sample(effect.row, now);
|
|
169
|
+
effect.old.style.opacity = String(1 - effect.row[0]);
|
|
170
|
+
effect.next.style.opacity = String(effect.row[0]);
|
|
171
|
+
if (!effect.row[17] && !layoutActive) {
|
|
172
|
+
this.release(effect);
|
|
173
|
+
this.effects.delete(id);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
get active() {
|
|
178
|
+
return this.effects.size > 0;
|
|
179
|
+
}
|
|
180
|
+
clear() {
|
|
181
|
+
for (const effect of this.effects.values())
|
|
182
|
+
this.release(effect);
|
|
183
|
+
this.effects.clear();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RenderNode } from '../core/session.js';
|
|
2
|
+
export interface RemoteTheme {
|
|
3
|
+
colors?: Readonly<Record<string, string | {
|
|
4
|
+
light?: string;
|
|
5
|
+
dark?: string;
|
|
6
|
+
}>>;
|
|
7
|
+
radii?: Readonly<Record<string, number>>;
|
|
8
|
+
fonts?: Readonly<Record<string, number>>;
|
|
9
|
+
/** User/browser text scaling multiplier; pixels remain logical browser units. */
|
|
10
|
+
textScale?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function validateTheme(theme?: RemoteTheme): RemoteTheme;
|
|
13
|
+
export declare function themedNode(node: RenderNode, host: RemoteTheme): RenderNode;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { fail, snapshot } from '../core/value.js';
|
|
2
|
+
export function validateTheme(theme = {}) {
|
|
3
|
+
const result = snapshot(theme);
|
|
4
|
+
if (Object.keys(result).some((key) => !['colors', 'radii', 'fonts', 'textScale'].includes(key)))
|
|
5
|
+
fail('Unknown host theme family');
|
|
6
|
+
for (const [family, entries] of Object.entries(result)) {
|
|
7
|
+
if (family === 'textScale') {
|
|
8
|
+
if (typeof entries !== 'number' || !Number.isFinite(entries) || entries < 0.5 || entries > 4)
|
|
9
|
+
fail('Invalid text scale');
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
if (!entries ||
|
|
13
|
+
typeof entries !== 'object' ||
|
|
14
|
+
Array.isArray(entries) ||
|
|
15
|
+
Object.keys(entries).length > 128)
|
|
16
|
+
fail('Invalid host theme');
|
|
17
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
18
|
+
if (!/^[a-z][a-z0-9-]{0,63}$/.test(key))
|
|
19
|
+
fail('Invalid host theme token');
|
|
20
|
+
if (family === 'colors') {
|
|
21
|
+
const variants = typeof value === 'string' ? { light: value, dark: value } : value;
|
|
22
|
+
if (!variants ||
|
|
23
|
+
typeof variants !== 'object' ||
|
|
24
|
+
Array.isArray(variants) ||
|
|
25
|
+
!Object.keys(variants).length ||
|
|
26
|
+
Object.entries(variants).some(([key, color]) => !['light', 'dark'].includes(key) ||
|
|
27
|
+
typeof color !== 'string' ||
|
|
28
|
+
!/^#[\da-f]{6}(?:[\da-f]{2})?$/i.test(color)))
|
|
29
|
+
fail('Invalid host color');
|
|
30
|
+
}
|
|
31
|
+
else if (typeof value !== 'number' ||
|
|
32
|
+
!Number.isFinite(value) ||
|
|
33
|
+
value < (family === 'fonts' ? 8 : 0) ||
|
|
34
|
+
value > 256)
|
|
35
|
+
fail('Invalid host geometry');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
const mergedThemes = new WeakMap();
|
|
41
|
+
export function themedNode(node, host) {
|
|
42
|
+
if (!Object.keys(host).length)
|
|
43
|
+
return node;
|
|
44
|
+
let entries = mergedThemes.get(host);
|
|
45
|
+
if (!entries) {
|
|
46
|
+
entries = new WeakMap();
|
|
47
|
+
mergedThemes.set(host, entries);
|
|
48
|
+
}
|
|
49
|
+
const cached = entries.get(node.theme);
|
|
50
|
+
if (cached)
|
|
51
|
+
return { ...node, theme: cached };
|
|
52
|
+
const colors = Object.fromEntries(Object.entries(host.colors ?? {}).map(([key, value]) => [
|
|
53
|
+
key,
|
|
54
|
+
typeof value === 'string' ? { light: value, dark: value } : value,
|
|
55
|
+
]));
|
|
56
|
+
const theme = {
|
|
57
|
+
...node.theme,
|
|
58
|
+
colors: { ...colors, ...node.theme.colors },
|
|
59
|
+
radii: { ...host.radii, ...node.theme.radii },
|
|
60
|
+
fonts: { ...host.fonts, ...node.theme.fonts },
|
|
61
|
+
textScale: host.textScale ?? 1,
|
|
62
|
+
};
|
|
63
|
+
entries.set(node.theme, theme);
|
|
64
|
+
return { ...node, theme };
|
|
65
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReloRuntime } from './core/runtime.js';
|
|
2
|
+
import { type EngineOptions } from './core/engine.js';
|
|
3
|
+
import { RemoteSurface, type MountOptions } from './dom/renderer.js';
|
|
4
|
+
export * from './core/index.js';
|
|
5
|
+
export * from './dom/index.js';
|
|
6
|
+
export declare class ReloUI extends ReloRuntime {
|
|
7
|
+
constructor();
|
|
8
|
+
static create(options?: EngineOptions): Promise<ReloUI>;
|
|
9
|
+
mount(container: HTMLElement, options: MountOptions): RemoteSurface;
|
|
10
|
+
}
|