@c9up/orbit 0.0.0-stage → 0.1.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/Cargo.lock +139 -0
- package/Cargo.toml +20 -0
- package/LICENSE +21 -0
- package/README.md +320 -2
- package/android/orbit.cmake +31 -0
- package/android/src/main/cpp/NativeOrbit.cpp +309 -0
- package/android/src/main/cpp/NativeOrbit.h +35 -0
- package/android/src/main/cpp/orbit_host.h +34 -0
- package/android/src/main/java/com/c9up/orbit/OrbitEffects.kt +286 -0
- package/android/src/main/java/com/c9up/orbit/OrbitHost.kt +258 -0
- package/android/src/main/java/com/c9up/orbit/OrbitImage.kt +346 -0
- package/android/src/main/java/com/c9up/orbit/OrbitInput.kt +161 -0
- package/android/src/main/java/com/c9up/orbit/OrbitPress.kt +110 -0
- package/android/src/main/java/com/c9up/orbit/OrbitVector.kt +115 -0
- package/android/src/main/java/com/c9up/orbit/OrbitViews.kt +362 -0
- package/crates/orbit-host/Cargo.toml +14 -0
- package/crates/orbit-host/src/gesture.rs +561 -0
- package/crates/orbit-host/src/lib.rs +2042 -0
- package/crates/orbit-host/src/motion.rs +328 -0
- package/crates/orbit-host/src/vector.rs +1173 -0
- package/dist/color.d.ts +10 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +62 -0
- package/dist/color.js.map +1 -0
- package/dist/commit.d.ts +77 -0
- package/dist/commit.d.ts.map +1 -0
- package/dist/commit.js +302 -0
- package/dist/commit.js.map +1 -0
- package/dist/errors.d.ts +76 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +89 -0
- package/dist/errors.js.map +1 -0
- package/dist/host.d.ts +49 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +20 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/motion.d.ts +18 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +67 -0
- package/dist/motion.js.map +1 -0
- package/dist/node.d.ts +46 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +110 -0
- package/dist/node.js.map +1 -0
- package/dist/pages.d.ts +56 -0
- package/dist/pages.d.ts.map +1 -0
- package/dist/pages.js +157 -0
- package/dist/pages.js.map +1 -0
- package/dist/react-native/index.d.ts +33 -0
- package/dist/react-native/index.d.ts.map +1 -0
- package/dist/react-native/index.js +71 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/report.d.ts +13 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +22 -0
- package/dist/report.js.map +1 -0
- package/dist/server.d.ts +109 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +290 -0
- package/dist/server.js.map +1 -0
- package/dist/stack.d.ts +117 -0
- package/dist/stack.d.ts.map +1 -0
- package/dist/stack.js +299 -0
- package/dist/stack.js.map +1 -0
- package/dist/styles.d.ts +138 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +920 -0
- package/dist/styles.js.map +1 -0
- package/dist/template.d.ts +27 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +1436 -0
- package/dist/template.js.map +1 -0
- package/dist/textDecoder.d.ts +29 -0
- package/dist/textDecoder.d.ts.map +1 -0
- package/dist/textDecoder.js +149 -0
- package/dist/textDecoder.js.map +1 -0
- package/dist/url.d.ts +45 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/url.js +303 -0
- package/dist/url.js.map +1 -0
- package/package.json +96 -3
- package/scripts/build-android.sh +27 -0
- package/scripts/test-styles.mjs +31 -0
- package/specs/NativeOrbit.ts +34 -0
- package/src/color.ts +68 -0
- package/src/commit.ts +373 -0
- package/src/errors.ts +178 -0
- package/src/host.ts +91 -0
- package/src/index.ts +64 -0
- package/src/motion.ts +88 -0
- package/src/node.ts +133 -0
- package/src/pages.ts +207 -0
- package/src/react-native/index.ts +115 -0
- package/src/react-native/react-native.d.ts +39 -0
- package/src/report.ts +25 -0
- package/src/server.ts +395 -0
- package/src/stack.ts +428 -0
- package/src/styles.ts +1021 -0
- package/src/template.ts +1681 -0
- package/src/textDecoder.ts +162 -0
- package/src/url.ts +333 -0
package/dist/styles.js
ADDED
|
@@ -0,0 +1,920 @@
|
|
|
1
|
+
import { signal } from "@c9up/aurora/core";
|
|
2
|
+
import { E_ORBIT_STYLE_TABLE } from "./errors.js";
|
|
3
|
+
let selfRules = new Map();
|
|
4
|
+
let elementRules = new Map();
|
|
5
|
+
let relatedRules = new Map();
|
|
6
|
+
let known = new Set();
|
|
7
|
+
let properties = {};
|
|
8
|
+
/** Classes an element asked for that the app's stylesheet does not have. */
|
|
9
|
+
export const unknownClasses = new Set();
|
|
10
|
+
/** The scheme `dark:` and the theme's dark values follow. */
|
|
11
|
+
export const colorScheme = signal("light");
|
|
12
|
+
/** The viewport, for `sm:` / `md:` and `vw` / `vh` (set by `mount`). */
|
|
13
|
+
export const viewportSize = signal({
|
|
14
|
+
width: 0,
|
|
15
|
+
height: 0,
|
|
16
|
+
});
|
|
17
|
+
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
18
|
+
function isRule(v) {
|
|
19
|
+
return (isObject(v) &&
|
|
20
|
+
(typeof v.class === "string" || typeof v.element === "string") &&
|
|
21
|
+
typeof v.specificity === "number" &&
|
|
22
|
+
Array.isArray(v.declarations));
|
|
23
|
+
}
|
|
24
|
+
/** A table `ream css:compile` wrote, checked rather than trusted (it is a file read at run time). */
|
|
25
|
+
export function isStyleTable(v) {
|
|
26
|
+
return (isObject(v) &&
|
|
27
|
+
v.version === 1 &&
|
|
28
|
+
isObject(v.properties) &&
|
|
29
|
+
Array.isArray(v.rules) &&
|
|
30
|
+
v.rules.every(isRule) &&
|
|
31
|
+
Array.isArray(v.inert));
|
|
32
|
+
}
|
|
33
|
+
/** Give orbit the app's style table (`ream android:*` does it before the app runs). */
|
|
34
|
+
export function useStyles(table) {
|
|
35
|
+
if (!isStyleTable(table)) {
|
|
36
|
+
throw new E_ORBIT_STYLE_TABLE();
|
|
37
|
+
}
|
|
38
|
+
selfRules = new Map();
|
|
39
|
+
relatedRules = new Map();
|
|
40
|
+
elementRules = new Map();
|
|
41
|
+
known = new Set(table.inert);
|
|
42
|
+
properties = table.properties;
|
|
43
|
+
table.rules.forEach((rule, order) => {
|
|
44
|
+
if (rule.class === undefined) {
|
|
45
|
+
const tag = rule.element ?? "*";
|
|
46
|
+
const list = elementRules.get(tag) ?? [];
|
|
47
|
+
list.push({ rule, order });
|
|
48
|
+
elementRules.set(tag, list);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
known.add(rule.class);
|
|
52
|
+
const into = rule.target === undefined ||
|
|
53
|
+
rule.target === "self" ||
|
|
54
|
+
!("relation" in rule.target)
|
|
55
|
+
? selfRules
|
|
56
|
+
: relatedRules;
|
|
57
|
+
const list = into.get(rule.class) ?? [];
|
|
58
|
+
list.push({ rule, order });
|
|
59
|
+
into.set(rule.class, list);
|
|
60
|
+
});
|
|
61
|
+
unknownClasses.clear();
|
|
62
|
+
}
|
|
63
|
+
// ─── Matching ────────────────────────────────────────────────────────
|
|
64
|
+
function matches(el, rel) {
|
|
65
|
+
const classes = el.classes();
|
|
66
|
+
return (rel.classes.every((c) => classes.includes(c)) &&
|
|
67
|
+
rel.when.every((cond) => holds(cond, el)));
|
|
68
|
+
}
|
|
69
|
+
function holds(cond, el) {
|
|
70
|
+
if ("attribute" in cond) {
|
|
71
|
+
const value = cond.attribute === "class"
|
|
72
|
+
? el.classes().join(" ")
|
|
73
|
+
: el.attribute(cond.attribute);
|
|
74
|
+
if ("operator" in cond) {
|
|
75
|
+
if (value === null)
|
|
76
|
+
return false;
|
|
77
|
+
switch (cond.operator) {
|
|
78
|
+
case "*":
|
|
79
|
+
return value.includes(cond.value);
|
|
80
|
+
case "^":
|
|
81
|
+
return value.startsWith(cond.value);
|
|
82
|
+
case "$":
|
|
83
|
+
return value.endsWith(cond.value);
|
|
84
|
+
case "~":
|
|
85
|
+
return value.split(/\s+/).includes(cond.value);
|
|
86
|
+
default:
|
|
87
|
+
return value === cond.value || value.startsWith(`${cond.value}-`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return cond.equals === null ? value !== null : value === cond.equals;
|
|
91
|
+
}
|
|
92
|
+
if ("scheme" in cond)
|
|
93
|
+
return colorScheme() === cond.scheme;
|
|
94
|
+
if ("class" in cond)
|
|
95
|
+
return el.classes().includes(cond.class);
|
|
96
|
+
if ("not" in cond)
|
|
97
|
+
return !cond.not.every((c) => holds(c, el));
|
|
98
|
+
if ("any" in cond)
|
|
99
|
+
return cond.any.some((c) => holds(c, el));
|
|
100
|
+
if ("all" in cond)
|
|
101
|
+
return cond.all.every((c) => holds(c, el));
|
|
102
|
+
if ("ancestor" in cond) {
|
|
103
|
+
for (let a = el.parent; a; a = a.parent)
|
|
104
|
+
if (matches(a, cond.ancestor))
|
|
105
|
+
return true;
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if ("parent" in cond)
|
|
109
|
+
return el.parent !== null && matches(el.parent, cond.parent);
|
|
110
|
+
if ("previous" in cond) {
|
|
111
|
+
for (let p = el.previous; p; p = p.previous)
|
|
112
|
+
if (matches(p, cond.previous))
|
|
113
|
+
return true;
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
if ("previousAdjacent" in cond)
|
|
117
|
+
return el.previous !== null && matches(el.previous, cond.previousAdjacent);
|
|
118
|
+
if ("dir" in cond)
|
|
119
|
+
return cond.dir === "ltr";
|
|
120
|
+
// A touch screen is never hovered; orbit does not see :has() or positions yet.
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
function mediaHolds(media) {
|
|
124
|
+
if (!media)
|
|
125
|
+
return true;
|
|
126
|
+
const { width } = viewportSize();
|
|
127
|
+
if (media.minWidth !== undefined && width < media.minWidth)
|
|
128
|
+
return false;
|
|
129
|
+
if (media.maxWidth !== undefined && width > media.maxWidth)
|
|
130
|
+
return false;
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
/** The rules that apply to `el`, in cascade order. */
|
|
134
|
+
function hits(el) {
|
|
135
|
+
const out = [];
|
|
136
|
+
// The base layer's element rules: `*`, the tag, and html / body at the root.
|
|
137
|
+
const tags = el.root ? ["*", el.tag, "html", "body"] : ["*", el.tag];
|
|
138
|
+
for (const tag of tags) {
|
|
139
|
+
for (const { rule, order } of elementRules.get(tag) ?? []) {
|
|
140
|
+
if (!(rule.when ?? []).every((c) => holds(c, el)))
|
|
141
|
+
continue;
|
|
142
|
+
const pseudo = typeof rule.target === "object" &&
|
|
143
|
+
"pseudo" in rule.target &&
|
|
144
|
+
!("relation" in rule.target)
|
|
145
|
+
? rule.target.pseudo
|
|
146
|
+
: null;
|
|
147
|
+
out.push({
|
|
148
|
+
specificity: rule.specificity,
|
|
149
|
+
order,
|
|
150
|
+
declarations: rule.declarations,
|
|
151
|
+
pseudo,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
for (const cls of el.classes()) {
|
|
156
|
+
const list = selfRules.get(cls);
|
|
157
|
+
if (!list) {
|
|
158
|
+
if (!known.has(cls))
|
|
159
|
+
unknownClasses.add(cls);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
for (const { rule, order } of list) {
|
|
163
|
+
if (!mediaHolds(rule.media))
|
|
164
|
+
continue;
|
|
165
|
+
if (!(rule.when ?? []).every((c) => holds(c, el)))
|
|
166
|
+
continue;
|
|
167
|
+
const pseudo = typeof rule.target === "object" &&
|
|
168
|
+
"pseudo" in rule.target &&
|
|
169
|
+
!("relation" in rule.target)
|
|
170
|
+
? rule.target.pseudo
|
|
171
|
+
: null;
|
|
172
|
+
out.push({
|
|
173
|
+
specificity: rule.specificity,
|
|
174
|
+
order,
|
|
175
|
+
declarations: rule.declarations,
|
|
176
|
+
pseudo,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// Rules an ancestor's class aims at its children or descendants (`[&_svg]:`, `*:`).
|
|
181
|
+
for (let a = el.parent, depth = 0; a; a = a.parent, depth++) {
|
|
182
|
+
for (const cls of a.classes()) {
|
|
183
|
+
for (const { rule, order } of relatedRules.get(cls) ?? []) {
|
|
184
|
+
const target = rule.target;
|
|
185
|
+
if (typeof target !== "object" || !("relation" in target))
|
|
186
|
+
continue;
|
|
187
|
+
if (target.relation === "child" && depth > 0)
|
|
188
|
+
continue;
|
|
189
|
+
if (target.tag !== null && target.tag !== el.tag)
|
|
190
|
+
continue;
|
|
191
|
+
if (!mediaHolds(rule.media))
|
|
192
|
+
continue;
|
|
193
|
+
if (!target.when.every((c) => holds(c, el)))
|
|
194
|
+
continue;
|
|
195
|
+
if (!(rule.when ?? []).every((c) => holds(c, a)))
|
|
196
|
+
continue;
|
|
197
|
+
out.push({
|
|
198
|
+
specificity: rule.specificity,
|
|
199
|
+
order,
|
|
200
|
+
declarations: rule.declarations,
|
|
201
|
+
pseudo: target.pseudo,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
out.sort((x, y) => x.specificity - y.specificity || x.order - y.order);
|
|
207
|
+
return out;
|
|
208
|
+
}
|
|
209
|
+
// ─── Values ──────────────────────────────────────────────────────────
|
|
210
|
+
function pick(value) {
|
|
211
|
+
return typeof value === "string" ? value : value[colorScheme()];
|
|
212
|
+
}
|
|
213
|
+
/** `)` matching the `(` before `from`. */
|
|
214
|
+
function closing(s, from) {
|
|
215
|
+
let depth = 1;
|
|
216
|
+
for (let i = from; i < s.length; i++) {
|
|
217
|
+
if (s[i] === "(")
|
|
218
|
+
depth++;
|
|
219
|
+
else if (s[i] === ")" && --depth === 0)
|
|
220
|
+
return i;
|
|
221
|
+
}
|
|
222
|
+
return -1;
|
|
223
|
+
}
|
|
224
|
+
/** Substitute `var()`; null when one resolves to nothing (invalid at computed time). */
|
|
225
|
+
function substitute(value, lookup, depth = 0) {
|
|
226
|
+
if (depth > 16)
|
|
227
|
+
return null;
|
|
228
|
+
let out = "";
|
|
229
|
+
let rest = value;
|
|
230
|
+
for (;;) {
|
|
231
|
+
const at = rest.indexOf("var(");
|
|
232
|
+
if (at < 0)
|
|
233
|
+
return out + rest;
|
|
234
|
+
const end = closing(rest, at + 4);
|
|
235
|
+
if (end < 0)
|
|
236
|
+
return null;
|
|
237
|
+
out += rest.slice(0, at);
|
|
238
|
+
const inner = rest.slice(at + 4, end);
|
|
239
|
+
const comma = inner.indexOf(",");
|
|
240
|
+
const name = (comma < 0 ? inner : inner.slice(0, comma)).trim();
|
|
241
|
+
const own = lookup(name);
|
|
242
|
+
const raw = own ?? (comma < 0 ? null : inner.slice(comma + 1));
|
|
243
|
+
if (raw === null)
|
|
244
|
+
return null;
|
|
245
|
+
const resolved = substitute(raw, lookup, depth + 1);
|
|
246
|
+
if (resolved === null)
|
|
247
|
+
return null;
|
|
248
|
+
out += resolved;
|
|
249
|
+
rest = rest.slice(end + 1);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/** `calc()` over px, % and numbers, once `var()`s are gone. */
|
|
253
|
+
function evaluateCalc(value) {
|
|
254
|
+
let rest = value;
|
|
255
|
+
let at = rest.indexOf("calc(");
|
|
256
|
+
while (at >= 0) {
|
|
257
|
+
const end = closing(rest, at + 5);
|
|
258
|
+
if (end < 0)
|
|
259
|
+
return rest;
|
|
260
|
+
const result = arithmetic(rest.slice(at + 5, end));
|
|
261
|
+
const text = result === null ? `calc(${rest.slice(at + 5, end)})` : result;
|
|
262
|
+
rest = rest.slice(0, at) + text + rest.slice(end + 1);
|
|
263
|
+
at = rest.indexOf("calc(", at + (result === null ? 5 : text.length));
|
|
264
|
+
}
|
|
265
|
+
return rest;
|
|
266
|
+
}
|
|
267
|
+
function arithmetic(expr) {
|
|
268
|
+
const tokens = expr.match(/-?\d*\.?\d+(?:e-?\d+)?(?:px|%)?|[-+*/()]/g);
|
|
269
|
+
if (!tokens)
|
|
270
|
+
return null;
|
|
271
|
+
let pos = 0;
|
|
272
|
+
const atom = () => {
|
|
273
|
+
const t = tokens[pos++];
|
|
274
|
+
if (t === undefined)
|
|
275
|
+
return null;
|
|
276
|
+
if (t === "(") {
|
|
277
|
+
const q = sum();
|
|
278
|
+
pos++;
|
|
279
|
+
return q;
|
|
280
|
+
}
|
|
281
|
+
const m = /^(-?\d*\.?\d+(?:e-?\d+)?)(px|%)?$/.exec(t);
|
|
282
|
+
return m ? { n: Number(m[1]), unit: m[2] ?? "" } : null;
|
|
283
|
+
};
|
|
284
|
+
const product = () => {
|
|
285
|
+
let q = atom();
|
|
286
|
+
while (q && (tokens[pos] === "*" || tokens[pos] === "/")) {
|
|
287
|
+
const op = tokens[pos++];
|
|
288
|
+
const r = atom();
|
|
289
|
+
if (!r)
|
|
290
|
+
return null;
|
|
291
|
+
if (op === "*")
|
|
292
|
+
q = { n: q.n * r.n, unit: q.unit || r.unit };
|
|
293
|
+
else if (r.unit === "" && r.n !== 0)
|
|
294
|
+
q = { n: q.n / r.n, unit: q.unit };
|
|
295
|
+
else
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
return q;
|
|
299
|
+
};
|
|
300
|
+
const sum = () => {
|
|
301
|
+
let q = product();
|
|
302
|
+
while (q && (tokens[pos] === "+" || tokens[pos] === "-")) {
|
|
303
|
+
const op = tokens[pos++];
|
|
304
|
+
const r = product();
|
|
305
|
+
if (!r)
|
|
306
|
+
return null;
|
|
307
|
+
const unit = q.unit === r.unit || r.n === 0 ? q.unit : q.n === 0 ? r.unit : null;
|
|
308
|
+
if (unit === null)
|
|
309
|
+
return null;
|
|
310
|
+
q = { n: op === "+" ? q.n + r.n : q.n - r.n, unit };
|
|
311
|
+
}
|
|
312
|
+
return q;
|
|
313
|
+
};
|
|
314
|
+
const q = sum();
|
|
315
|
+
if (!q || pos !== tokens.length)
|
|
316
|
+
return null;
|
|
317
|
+
return `${Math.round(q.n * 10000) / 10000}${q.unit}`;
|
|
318
|
+
}
|
|
319
|
+
/** Split at top-level commas or spaces. */
|
|
320
|
+
function split(value, by) {
|
|
321
|
+
const out = [];
|
|
322
|
+
let depth = 0;
|
|
323
|
+
let start = 0;
|
|
324
|
+
for (let i = 0; i < value.length; i++) {
|
|
325
|
+
const c = value[i];
|
|
326
|
+
if (c === "(")
|
|
327
|
+
depth++;
|
|
328
|
+
else if (c === ")")
|
|
329
|
+
depth--;
|
|
330
|
+
else if (depth === 0 && (by === "," ? c === "," : /\s/.test(c ?? ""))) {
|
|
331
|
+
const part = value.slice(start, i).trim();
|
|
332
|
+
if (part)
|
|
333
|
+
out.push(part);
|
|
334
|
+
start = i + 1;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
const last = value.slice(start).trim();
|
|
338
|
+
if (last)
|
|
339
|
+
out.push(last);
|
|
340
|
+
return out;
|
|
341
|
+
}
|
|
342
|
+
const isColor = (v) => /^#[0-9a-f]{8}$/i.test(v) || v === "currentcolor";
|
|
343
|
+
/** `#rrggbbaa` to the `#rrggbb` / `rgba()` orbit's colour reader takes. */
|
|
344
|
+
function cssColor(v, current) {
|
|
345
|
+
if (v === "currentcolor")
|
|
346
|
+
return current;
|
|
347
|
+
// What the build could not mix: the text colour faded over transparent
|
|
348
|
+
// (`color-mix(in oklab, currentcolor 50%, transparent)`).
|
|
349
|
+
const mix = /^color-mix\(in [a-z]+,\s*(currentcolor|#[0-9a-f]{8})\s+([\d.]+)%,\s*#00000000\)$/i.exec(v);
|
|
350
|
+
if (mix) {
|
|
351
|
+
const base = mix[1] === "currentcolor" ? current : cssColor(mix[1] ?? "", current);
|
|
352
|
+
if (base === undefined)
|
|
353
|
+
return undefined;
|
|
354
|
+
return withAlpha(base, Number(mix[2]) / 100);
|
|
355
|
+
}
|
|
356
|
+
const m = /^#([0-9a-f]{6})([0-9a-f]{2})$/i.exec(v);
|
|
357
|
+
if (!m)
|
|
358
|
+
return undefined;
|
|
359
|
+
const alpha = Number.parseInt(m[2] ?? "ff", 16) / 255;
|
|
360
|
+
if (alpha >= 1)
|
|
361
|
+
return `#${m[1]}`;
|
|
362
|
+
const n = Number.parseInt(m[1] ?? "0", 16);
|
|
363
|
+
return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${Math.round(alpha * 1000) / 1000})`;
|
|
364
|
+
}
|
|
365
|
+
/** A colour orbit writes (`#rrggbb` or `rgba()`) with its alpha scaled. */
|
|
366
|
+
function withAlpha(css, factor) {
|
|
367
|
+
let r = 0;
|
|
368
|
+
let g = 0;
|
|
369
|
+
let b = 0;
|
|
370
|
+
let a = 1;
|
|
371
|
+
const hex = /^#([0-9a-f]{6})$/i.exec(css);
|
|
372
|
+
const rgba = /^rgba?\(([\d.]+),\s*([\d.]+),\s*([\d.]+)(?:,\s*([\d.]+))?\)$/.exec(css);
|
|
373
|
+
if (hex) {
|
|
374
|
+
const n = Number.parseInt(hex[1] ?? "0", 16);
|
|
375
|
+
[r, g, b] = [(n >> 16) & 255, (n >> 8) & 255, n & 255];
|
|
376
|
+
}
|
|
377
|
+
else if (rgba) {
|
|
378
|
+
[r, g, b] = [Number(rgba[1]), Number(rgba[2]), Number(rgba[3])];
|
|
379
|
+
a = rgba[4] === undefined ? 1 : Number(rgba[4]);
|
|
380
|
+
}
|
|
381
|
+
return `rgba(${r}, ${g}, ${b}, ${Math.round(a * factor * 1000) / 1000})`;
|
|
382
|
+
}
|
|
383
|
+
function length(v, fontSize) {
|
|
384
|
+
if (v === "auto")
|
|
385
|
+
return "auto";
|
|
386
|
+
if (v.endsWith("%"))
|
|
387
|
+
return v;
|
|
388
|
+
const m = /^(-?\d*\.?\d+(?:e-?\d+)?)(px|em|vw|vh|dvh|svh|lvh)?$/.exec(v);
|
|
389
|
+
if (!m)
|
|
390
|
+
return undefined;
|
|
391
|
+
const n = Number(m[1]);
|
|
392
|
+
switch (m[2]) {
|
|
393
|
+
case undefined:
|
|
394
|
+
case "px":
|
|
395
|
+
return n;
|
|
396
|
+
case "em":
|
|
397
|
+
return n * fontSize;
|
|
398
|
+
case "vw":
|
|
399
|
+
return (n / 100) * viewportSize().width;
|
|
400
|
+
default:
|
|
401
|
+
return (n / 100) * viewportSize().height;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
const ALIGN = {
|
|
405
|
+
start: "flex-start",
|
|
406
|
+
"flex-start": "flex-start",
|
|
407
|
+
end: "flex-end",
|
|
408
|
+
"flex-end": "flex-end",
|
|
409
|
+
center: "center",
|
|
410
|
+
stretch: "stretch",
|
|
411
|
+
baseline: "baseline",
|
|
412
|
+
normal: "stretch",
|
|
413
|
+
"space-between": "space-between",
|
|
414
|
+
"space-around": "space-around",
|
|
415
|
+
"space-evenly": "space-evenly",
|
|
416
|
+
};
|
|
417
|
+
const SIDES = ["Top", "Right", "Bottom", "Left"];
|
|
418
|
+
/** `a`, `a b`, `a b c` or `a b c d` → top, right, bottom, left. */
|
|
419
|
+
function fourSides(values) {
|
|
420
|
+
const [a, b = a, c = a, d = b] = values;
|
|
421
|
+
return a === undefined ||
|
|
422
|
+
b === undefined ||
|
|
423
|
+
c === undefined ||
|
|
424
|
+
d === undefined
|
|
425
|
+
? null
|
|
426
|
+
: [a, b, c, d];
|
|
427
|
+
}
|
|
428
|
+
const TEXT_KEYS = new Set([
|
|
429
|
+
"color",
|
|
430
|
+
"fontSize",
|
|
431
|
+
"fontWeight",
|
|
432
|
+
"fontStyle",
|
|
433
|
+
"fontFamily",
|
|
434
|
+
"textAlign",
|
|
435
|
+
"lineHeight",
|
|
436
|
+
"letterSpacing",
|
|
437
|
+
]);
|
|
438
|
+
/** One declaration into the host's keys (`out`); what orbit does not draw is skipped. */
|
|
439
|
+
function apply(prop, v, out, state) {
|
|
440
|
+
const len = (x) => length(x, state.fontSize);
|
|
441
|
+
const set = (key, x) => {
|
|
442
|
+
if (x !== undefined)
|
|
443
|
+
out[key] = x;
|
|
444
|
+
};
|
|
445
|
+
const sides = (prefix, suffix, value) => {
|
|
446
|
+
const four = fourSides(split(value, " "));
|
|
447
|
+
if (!four)
|
|
448
|
+
return;
|
|
449
|
+
four.forEach((x, i) => {
|
|
450
|
+
set(`${prefix}${SIDES[i]}${suffix}`, len(x));
|
|
451
|
+
});
|
|
452
|
+
};
|
|
453
|
+
switch (prop) {
|
|
454
|
+
case "display":
|
|
455
|
+
// The host lays every box out as flex; only `none` is sent.
|
|
456
|
+
if (v === "none")
|
|
457
|
+
out.display = "none";
|
|
458
|
+
else
|
|
459
|
+
delete out.display;
|
|
460
|
+
state.flex = v === "flex" || v === "inline-flex";
|
|
461
|
+
return;
|
|
462
|
+
case "width":
|
|
463
|
+
case "height":
|
|
464
|
+
case "min-width":
|
|
465
|
+
case "min-height":
|
|
466
|
+
case "max-width":
|
|
467
|
+
case "max-height": {
|
|
468
|
+
if (v === "none" || /content$/.test(v))
|
|
469
|
+
return;
|
|
470
|
+
const key = prop.replace(/-(\w)/, (_, c) => c.toUpperCase());
|
|
471
|
+
set(key, len(v));
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
case "padding":
|
|
475
|
+
case "margin":
|
|
476
|
+
sides(prop, "", v);
|
|
477
|
+
return;
|
|
478
|
+
case "padding-inline":
|
|
479
|
+
case "margin-inline":
|
|
480
|
+
case "padding-block":
|
|
481
|
+
case "margin-block": {
|
|
482
|
+
const [a, b = a] = split(v, " ");
|
|
483
|
+
const base = prop.startsWith("padding") ? "padding" : "margin";
|
|
484
|
+
const [x, y] = prop.endsWith("inline")
|
|
485
|
+
? ["Left", "Right"]
|
|
486
|
+
: ["Top", "Bottom"];
|
|
487
|
+
if (a !== undefined && b !== undefined) {
|
|
488
|
+
set(`${base}${x}`, len(a));
|
|
489
|
+
set(`${base}${y}`, len(b));
|
|
490
|
+
}
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
case "padding-block-start":
|
|
494
|
+
case "padding-block-end":
|
|
495
|
+
case "padding-inline-start":
|
|
496
|
+
case "padding-inline-end":
|
|
497
|
+
case "margin-block-start":
|
|
498
|
+
case "margin-block-end":
|
|
499
|
+
case "margin-inline-start":
|
|
500
|
+
case "margin-inline-end":
|
|
501
|
+
case "padding-top":
|
|
502
|
+
case "padding-right":
|
|
503
|
+
case "padding-bottom":
|
|
504
|
+
case "padding-left":
|
|
505
|
+
case "margin-top":
|
|
506
|
+
case "margin-right":
|
|
507
|
+
case "margin-bottom":
|
|
508
|
+
case "margin-left": {
|
|
509
|
+
const [base = "", ...rest] = prop.split("-");
|
|
510
|
+
const where = rest.join("-");
|
|
511
|
+
const side = {
|
|
512
|
+
"block-start": "Top",
|
|
513
|
+
"block-end": "Bottom",
|
|
514
|
+
"inline-start": "Left",
|
|
515
|
+
"inline-end": "Right",
|
|
516
|
+
}[where] ?? `${where.charAt(0).toUpperCase()}${where.slice(1)}`;
|
|
517
|
+
set(`${base}${side}`, len(v));
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
case "inset":
|
|
521
|
+
sides("", "", v);
|
|
522
|
+
for (const s of SIDES) {
|
|
523
|
+
const k = s;
|
|
524
|
+
if (out[k] !== undefined) {
|
|
525
|
+
out[k.toLowerCase()] = out[k];
|
|
526
|
+
delete out[k];
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return;
|
|
530
|
+
case "inset-inline":
|
|
531
|
+
case "inset-block": {
|
|
532
|
+
const [a, b = a] = split(v, " ");
|
|
533
|
+
const [x, y] = prop === "inset-inline" ? ["left", "right"] : ["top", "bottom"];
|
|
534
|
+
if (a !== undefined && b !== undefined) {
|
|
535
|
+
set(x, len(a));
|
|
536
|
+
set(y, len(b));
|
|
537
|
+
}
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
case "top":
|
|
541
|
+
case "right":
|
|
542
|
+
case "bottom":
|
|
543
|
+
case "left":
|
|
544
|
+
set(prop, len(v));
|
|
545
|
+
return;
|
|
546
|
+
case "inset-inline-start":
|
|
547
|
+
set("left", len(v));
|
|
548
|
+
return;
|
|
549
|
+
case "inset-inline-end":
|
|
550
|
+
set("right", len(v));
|
|
551
|
+
return;
|
|
552
|
+
case "gap":
|
|
553
|
+
case "row-gap":
|
|
554
|
+
case "column-gap": {
|
|
555
|
+
const [a, b = a] = split(v, " ");
|
|
556
|
+
if (prop === "gap" && a !== undefined && b !== undefined) {
|
|
557
|
+
set("rowGap", len(a));
|
|
558
|
+
set("columnGap", len(b));
|
|
559
|
+
}
|
|
560
|
+
else
|
|
561
|
+
set(prop === "row-gap" ? "rowGap" : "columnGap", len(v));
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
case "flex": {
|
|
565
|
+
const parts = split(v, " ");
|
|
566
|
+
if (v === "none")
|
|
567
|
+
Object.assign(out, { flexGrow: 0, flexShrink: 0, flexBasis: "auto" });
|
|
568
|
+
else if (v === "auto")
|
|
569
|
+
Object.assign(out, { flexGrow: 1, flexShrink: 1, flexBasis: "auto" });
|
|
570
|
+
else {
|
|
571
|
+
const [grow, shrink = "1", basis = "0%"] = parts;
|
|
572
|
+
set("flexGrow", Number(grow));
|
|
573
|
+
set("flexShrink", Number(shrink));
|
|
574
|
+
set("flexBasis", len(basis));
|
|
575
|
+
}
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
case "flex-grow":
|
|
579
|
+
set("flexGrow", Number(v));
|
|
580
|
+
return;
|
|
581
|
+
case "flex-shrink":
|
|
582
|
+
set("flexShrink", Number(v));
|
|
583
|
+
return;
|
|
584
|
+
case "flex-basis":
|
|
585
|
+
set("flexBasis", len(v));
|
|
586
|
+
return;
|
|
587
|
+
case "flex-direction":
|
|
588
|
+
set("flexDirection", v);
|
|
589
|
+
return;
|
|
590
|
+
case "flex-wrap":
|
|
591
|
+
set("flexWrap", v);
|
|
592
|
+
return;
|
|
593
|
+
case "align-items":
|
|
594
|
+
case "align-self":
|
|
595
|
+
case "align-content":
|
|
596
|
+
case "justify-content": {
|
|
597
|
+
const key = prop.replace(/-(\w)/, (_, c) => c.toUpperCase());
|
|
598
|
+
set(key, ALIGN[v.replace(/^safe /, "")]);
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
case "position":
|
|
602
|
+
set("position", v === "absolute" || v === "fixed" ? "absolute" : "relative");
|
|
603
|
+
return;
|
|
604
|
+
case "overflow":
|
|
605
|
+
case "overflow-y":
|
|
606
|
+
case "overflow-x":
|
|
607
|
+
if (v === "auto" || v === "scroll") {
|
|
608
|
+
if (prop !== "overflow-x")
|
|
609
|
+
state.scroll = true;
|
|
610
|
+
}
|
|
611
|
+
else if (v === "hidden" || v === "clip")
|
|
612
|
+
out.overflow = "hidden";
|
|
613
|
+
return;
|
|
614
|
+
case "aspect-ratio": {
|
|
615
|
+
const [a, b] = v.split("/").map((x) => Number(x.trim()));
|
|
616
|
+
if (a !== undefined && Number.isFinite(a))
|
|
617
|
+
set("aspectRatio", b !== undefined && b > 0 ? a / b : a);
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
case "border-width":
|
|
621
|
+
sides("border", "Width", v);
|
|
622
|
+
if (new Set(SIDES.map((s) => out[`border${s}Width`])).size === 1)
|
|
623
|
+
for (const s of SIDES) {
|
|
624
|
+
out.borderWidth = out[`border${s}Width`] ?? 0;
|
|
625
|
+
delete out[`border${s}Width`];
|
|
626
|
+
}
|
|
627
|
+
return;
|
|
628
|
+
case "border-top-width":
|
|
629
|
+
case "border-right-width":
|
|
630
|
+
case "border-bottom-width":
|
|
631
|
+
case "border-left-width": {
|
|
632
|
+
const side = prop.split("-")[1] ?? "";
|
|
633
|
+
set(`border${side.charAt(0).toUpperCase()}${side.slice(1)}Width`, len(v));
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
case "border-style":
|
|
637
|
+
if (v === "none" || v === "hidden")
|
|
638
|
+
out.borderStyleNone = 1;
|
|
639
|
+
else
|
|
640
|
+
delete out.borderStyleNone;
|
|
641
|
+
return;
|
|
642
|
+
case "border-color":
|
|
643
|
+
case "border-top-color":
|
|
644
|
+
case "border-bottom-color":
|
|
645
|
+
case "border-left-color":
|
|
646
|
+
case "border-right-color": {
|
|
647
|
+
const [first] = split(v, " ");
|
|
648
|
+
if (first !== undefined)
|
|
649
|
+
set("borderColor", cssColor(first, state.color));
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
case "border-radius": {
|
|
653
|
+
const [first] = split(v, " ");
|
|
654
|
+
if (first !== undefined)
|
|
655
|
+
set("borderRadius", len(first));
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
case "background-color":
|
|
659
|
+
set("backgroundColor", cssColor(v, state.color));
|
|
660
|
+
return;
|
|
661
|
+
case "color": {
|
|
662
|
+
const c = cssColor(v, state.color);
|
|
663
|
+
if (c) {
|
|
664
|
+
out.color = c;
|
|
665
|
+
state.color = c;
|
|
666
|
+
}
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
case "opacity":
|
|
670
|
+
set("opacity", v.endsWith("%") ? Number(v.slice(0, -1)) / 100 : Number(v));
|
|
671
|
+
return;
|
|
672
|
+
case "font-size": {
|
|
673
|
+
const n = len(v);
|
|
674
|
+
if (typeof n === "number") {
|
|
675
|
+
out.fontSize = n;
|
|
676
|
+
state.fontSize = n;
|
|
677
|
+
}
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
case "font-weight": {
|
|
681
|
+
// bolder / lighter: CSS's relative weights, from the inherited one.
|
|
682
|
+
const w = state.weight;
|
|
683
|
+
const weight = v === "bold"
|
|
684
|
+
? 700
|
|
685
|
+
: v === "normal"
|
|
686
|
+
? 400
|
|
687
|
+
: v === "bolder"
|
|
688
|
+
? w < 350
|
|
689
|
+
? 400
|
|
690
|
+
: w < 550
|
|
691
|
+
? 700
|
|
692
|
+
: 900
|
|
693
|
+
: v === "lighter"
|
|
694
|
+
? w < 550
|
|
695
|
+
? 100
|
|
696
|
+
: w < 750
|
|
697
|
+
? 400
|
|
698
|
+
: 700
|
|
699
|
+
: Number(v);
|
|
700
|
+
if (Number.isFinite(weight)) {
|
|
701
|
+
out.fontWeight = String(weight);
|
|
702
|
+
state.weight = weight;
|
|
703
|
+
}
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
case "font-style":
|
|
707
|
+
set("fontStyle", v);
|
|
708
|
+
return;
|
|
709
|
+
case "font-family":
|
|
710
|
+
if (/mono/.test(v))
|
|
711
|
+
out.fontFamily = "monospace";
|
|
712
|
+
return;
|
|
713
|
+
case "line-height": {
|
|
714
|
+
// Unitless: a multiple of the font size, kept so it follows a size set later.
|
|
715
|
+
if (/^\d*\.?\d+$/.test(v))
|
|
716
|
+
set("lineHeight", `${v}x`);
|
|
717
|
+
else
|
|
718
|
+
set("lineHeight", len(v));
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
case "letter-spacing":
|
|
722
|
+
set("letterSpacing", len(v));
|
|
723
|
+
return;
|
|
724
|
+
case "text-align":
|
|
725
|
+
set("textAlign", v === "start" ? "left" : v === "end" ? "right" : v);
|
|
726
|
+
return;
|
|
727
|
+
case "object-fit":
|
|
728
|
+
set("objectFit", v);
|
|
729
|
+
return;
|
|
730
|
+
case "field-sizing":
|
|
731
|
+
set("fieldSizing", v);
|
|
732
|
+
return;
|
|
733
|
+
case "backdrop-filter": {
|
|
734
|
+
const m = /blur\(([\d.]+)px\)/.exec(v);
|
|
735
|
+
if (m)
|
|
736
|
+
set("backdropBlur", Number(m[1]));
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
case "box-shadow":
|
|
740
|
+
shadow(v, out, state.color);
|
|
741
|
+
return;
|
|
742
|
+
default:
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
/** The first visible outer shadow of a `box-shadow` list (orbit draws one). */
|
|
747
|
+
function shadow(v, out, current) {
|
|
748
|
+
for (const layer of split(v, ",")) {
|
|
749
|
+
const parts = split(layer, " ");
|
|
750
|
+
if (parts.includes("inset"))
|
|
751
|
+
continue;
|
|
752
|
+
const color = parts.find(isColor);
|
|
753
|
+
const numbers = parts.filter((p) => !isColor(p)).map((p) => length(p, 16));
|
|
754
|
+
if (!color || numbers.some((n) => typeof n !== "number"))
|
|
755
|
+
continue;
|
|
756
|
+
const [x = 0, y = 0, blur = 0, spread = 0] = numbers.map(Number);
|
|
757
|
+
const css = cssColor(color, current);
|
|
758
|
+
if (!css || (/^#[0-9a-f]{8}$/i.test(color) && color.endsWith("00")))
|
|
759
|
+
continue;
|
|
760
|
+
if (x === 0 && y === 0 && blur === 0 && spread === 0)
|
|
761
|
+
continue;
|
|
762
|
+
Object.assign(out, {
|
|
763
|
+
shadowX: x,
|
|
764
|
+
shadowY: y,
|
|
765
|
+
shadowBlur: blur,
|
|
766
|
+
shadowSpread: spread,
|
|
767
|
+
shadowColor: css,
|
|
768
|
+
});
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Equal sides back into one key (`padding`, `marginHorizontal`, `gap`), and
|
|
774
|
+
* nothing the host already assumes (a zero margin or padding, a border colour
|
|
775
|
+
* without a border): the base layer sets those on every element.
|
|
776
|
+
*/
|
|
777
|
+
function compact(style) {
|
|
778
|
+
for (const [key, value] of Object.entries(style))
|
|
779
|
+
if (value === 0 && /^(margin|padding)/.test(key))
|
|
780
|
+
delete style[key];
|
|
781
|
+
const bordered = [
|
|
782
|
+
"borderWidth",
|
|
783
|
+
"borderTopWidth",
|
|
784
|
+
"borderRightWidth",
|
|
785
|
+
"borderBottomWidth",
|
|
786
|
+
"borderLeftWidth",
|
|
787
|
+
].some((k) => typeof style[k] === "number" && style[k] !== 0);
|
|
788
|
+
if (!bordered)
|
|
789
|
+
delete style.borderColor;
|
|
790
|
+
for (const base of ["padding", "margin"]) {
|
|
791
|
+
const [t, r, b, l] = SIDES.map((side) => style[`${base}${side}`]);
|
|
792
|
+
if (t !== undefined && t === r && r === b && b === l) {
|
|
793
|
+
for (const side of SIDES)
|
|
794
|
+
delete style[`${base}${side}`];
|
|
795
|
+
style[base] = t;
|
|
796
|
+
continue;
|
|
797
|
+
}
|
|
798
|
+
if (l !== undefined && l === r) {
|
|
799
|
+
delete style[`${base}Left`];
|
|
800
|
+
delete style[`${base}Right`];
|
|
801
|
+
style[`${base}Horizontal`] = l;
|
|
802
|
+
}
|
|
803
|
+
if (t !== undefined && t === b) {
|
|
804
|
+
delete style[`${base}Top`];
|
|
805
|
+
delete style[`${base}Bottom`];
|
|
806
|
+
style[`${base}Vertical`] = t;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
if (style.rowGap !== undefined && style.rowGap === style.columnGap) {
|
|
810
|
+
style.gap = style.rowGap;
|
|
811
|
+
delete style.rowGap;
|
|
812
|
+
delete style.columnGap;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* `el`'s style: the table's rules cascaded, custom properties resolved, read
|
|
817
|
+
* into the host's keys. `inherited` is the text style it inherits (and its
|
|
818
|
+
* colour, for `currentcolor`).
|
|
819
|
+
*/
|
|
820
|
+
export function computeStyle(el, inherited) {
|
|
821
|
+
const own = new Map();
|
|
822
|
+
const declared = [];
|
|
823
|
+
const placeholder = [];
|
|
824
|
+
for (const hit of hits(el)) {
|
|
825
|
+
for (const [prop, value] of hit.declarations) {
|
|
826
|
+
const v = pick(value);
|
|
827
|
+
if (hit.pseudo === "placeholder")
|
|
828
|
+
placeholder.push([prop, v]);
|
|
829
|
+
else if (hit.pseudo !== null)
|
|
830
|
+
continue;
|
|
831
|
+
else if (prop.startsWith("--"))
|
|
832
|
+
own.set(prop, v);
|
|
833
|
+
else
|
|
834
|
+
declared.push([prop, v]);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
const parentVars = el.parent?.vars;
|
|
838
|
+
const resolving = new Set();
|
|
839
|
+
const lookup = (name) => {
|
|
840
|
+
const mine = own.get(name);
|
|
841
|
+
if (mine !== undefined) {
|
|
842
|
+
if (resolving.has(name))
|
|
843
|
+
return null;
|
|
844
|
+
resolving.add(name);
|
|
845
|
+
const r = substitute(mine, lookup);
|
|
846
|
+
resolving.delete(name);
|
|
847
|
+
return r;
|
|
848
|
+
}
|
|
849
|
+
const registered = properties[name];
|
|
850
|
+
if (!registered || registered.inherits) {
|
|
851
|
+
const up = parentVars?.get(name);
|
|
852
|
+
if (up !== undefined)
|
|
853
|
+
return up;
|
|
854
|
+
}
|
|
855
|
+
return registered?.initial ?? null;
|
|
856
|
+
};
|
|
857
|
+
const vars = new Map();
|
|
858
|
+
for (const name of own.keys()) {
|
|
859
|
+
const r = lookup(name);
|
|
860
|
+
if (r !== null)
|
|
861
|
+
vars.set(name, r);
|
|
862
|
+
}
|
|
863
|
+
if (parentVars) {
|
|
864
|
+
for (const [name, value] of parentVars) {
|
|
865
|
+
const registered = properties[name];
|
|
866
|
+
if (!vars.has(name) && (!registered || registered.inherits))
|
|
867
|
+
vars.set(name, value);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
const inheritedSize = inherited.fontSize;
|
|
871
|
+
const inheritedColor = inherited.color;
|
|
872
|
+
const inheritedWeight = Number(inherited.fontWeight ?? 400);
|
|
873
|
+
const state = {
|
|
874
|
+
flex: false,
|
|
875
|
+
scroll: false,
|
|
876
|
+
fontSize: typeof inheritedSize === "number" ? inheritedSize : 16,
|
|
877
|
+
weight: Number.isFinite(inheritedWeight) ? inheritedWeight : 400,
|
|
878
|
+
color: typeof inheritedColor === "string" ? inheritedColor : undefined,
|
|
879
|
+
};
|
|
880
|
+
const style = {};
|
|
881
|
+
// font-size, color and font-weight first: em lengths, currentcolor and
|
|
882
|
+
// bolder read them.
|
|
883
|
+
const first = (p) => p === "font-size" || p === "color" || p === "font-weight";
|
|
884
|
+
const ordered = [
|
|
885
|
+
...declared.filter(([p]) => first(p)),
|
|
886
|
+
...declared.filter(([p]) => !first(p)),
|
|
887
|
+
];
|
|
888
|
+
for (const [prop, raw] of ordered) {
|
|
889
|
+
const v = substitute(raw, lookup);
|
|
890
|
+
if (v === null)
|
|
891
|
+
continue;
|
|
892
|
+
apply(prop, evaluateCalc(v).trim(), style, state);
|
|
893
|
+
}
|
|
894
|
+
compact(style);
|
|
895
|
+
if (style.borderStyleNone !== undefined) {
|
|
896
|
+
delete style.borderStyleNone;
|
|
897
|
+
style.borderWidth = 0;
|
|
898
|
+
}
|
|
899
|
+
const box = {};
|
|
900
|
+
const text = {};
|
|
901
|
+
for (const [key, value] of Object.entries(style)) {
|
|
902
|
+
(TEXT_KEYS.has(key) ? text : box)[key] = value;
|
|
903
|
+
}
|
|
904
|
+
if (state.flex && box.flexDirection === undefined)
|
|
905
|
+
box.flexDirection = "row";
|
|
906
|
+
const computed = {
|
|
907
|
+
box,
|
|
908
|
+
text,
|
|
909
|
+
flex: state.flex,
|
|
910
|
+
scroll: state.scroll,
|
|
911
|
+
vars,
|
|
912
|
+
};
|
|
913
|
+
for (const [prop, raw] of placeholder) {
|
|
914
|
+
const v = substitute(raw, lookup);
|
|
915
|
+
if (prop === "color" && v !== null)
|
|
916
|
+
computed.placeholder = cssColor(v.trim(), state.color);
|
|
917
|
+
}
|
|
918
|
+
return computed;
|
|
919
|
+
}
|
|
920
|
+
//# sourceMappingURL=styles.js.map
|