@expressive/dom 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.d.ts +37 -40
- package/dist/index.js +196 -161
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,89 +5,23 @@ import { Component, Context, Model, has, map, unbind } from "@expressive/mvc";
|
|
|
5
5
|
import { watch } from "@expressive/mvc/observable";
|
|
6
6
|
import { Fragment as Fragment$1 } from "@expressive/mvc/jsx-runtime";
|
|
7
7
|
|
|
8
|
-
//#region src/style/css.ts
|
|
9
|
-
const unitless = /* @__PURE__ */ new Map();
|
|
10
|
-
let probe;
|
|
11
|
-
/**
|
|
12
|
-
* Does the CSSOM accept a bare number for this property? Probed once with a
|
|
13
|
-
* canonical value; the answer is a property of CSS, not of the value.
|
|
14
|
-
*/
|
|
15
|
-
function bare$1(property) {
|
|
16
|
-
let known = unitless.get(property);
|
|
17
|
-
if (known === void 0) {
|
|
18
|
-
probe ||= document.createElement("div").style;
|
|
19
|
-
probe[property] = "";
|
|
20
|
-
probe[property] = 1;
|
|
21
|
-
unitless.set(property, known = Boolean(probe[property]));
|
|
22
|
-
}
|
|
23
|
-
return known;
|
|
24
|
-
}
|
|
25
|
-
function sized(property, value) {
|
|
26
|
-
if (Array.isArray(value)) return value.map((entry) => sized(property, entry));
|
|
27
|
-
return typeof value == "number" && value !== 0 && !bare$1(property) ? `${value}px` : value;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Web macro pack. Register with `macro(css)` to opt into pixel units for
|
|
31
|
-
* numbers and the `size` shorthand.
|
|
32
|
-
*/
|
|
33
|
-
const css = {
|
|
34
|
-
"*": (value, key) => ({ [key]: sized(key, value) }),
|
|
35
|
-
size: (value) => Array.isArray(value) ? {
|
|
36
|
-
width: value[0],
|
|
37
|
-
height: value[1]
|
|
38
|
-
} : {
|
|
39
|
-
width: value,
|
|
40
|
-
height: value
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/style/units.ts
|
|
46
|
-
function unit(suffix) {
|
|
47
|
-
return (...values) => values.map((value) => value + suffix).join(" ");
|
|
48
|
-
}
|
|
49
|
-
const rem = unit("rem");
|
|
50
|
-
const em = unit("em");
|
|
51
|
-
const px = unit("px");
|
|
52
|
-
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/style/media.ts
|
|
55
|
-
function media(query) {
|
|
56
|
-
return `@media ${Object.entries(query).map(([key, value]) => {
|
|
57
|
-
return `(${key.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`)}: ${typeof value == "number" ? `${value}px` : value})`;
|
|
58
|
-
}).join(" and ")}`;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
//#endregion
|
|
62
8
|
//#region src/style/protocol.ts
|
|
63
9
|
const SUBCOMPONENT = /^_[A-Z]/;
|
|
64
10
|
const registrations = /* @__PURE__ */ new WeakMap();
|
|
65
11
|
const tokens = /* @__PURE__ */ new WeakMap();
|
|
66
|
-
let root;
|
|
67
12
|
let emitter;
|
|
68
|
-
let rendered = false;
|
|
69
13
|
function registerAppearance(type, enter) {
|
|
70
14
|
registrations.set(type, enter);
|
|
71
15
|
}
|
|
72
|
-
function registerAppearanceRoot(factory) {
|
|
73
|
-
root = factory;
|
|
74
|
-
}
|
|
75
16
|
function registerEmitter(emit) {
|
|
76
17
|
emitter = emit;
|
|
77
18
|
}
|
|
78
19
|
function emitClass(block, depth, document) {
|
|
79
20
|
return emitter(block, depth, document);
|
|
80
21
|
}
|
|
81
|
-
function
|
|
82
|
-
rendered = true;
|
|
83
|
-
return root?.();
|
|
84
|
-
}
|
|
85
|
-
/** Has anything rendered yet - global registration is closed after it has. */
|
|
86
|
-
function appearanceSealed() {
|
|
87
|
-
return rendered;
|
|
88
|
-
}
|
|
89
|
-
function enterAppearance(parent, type, key) {
|
|
22
|
+
function enterAppearance(type, key) {
|
|
90
23
|
const chain = [];
|
|
24
|
+
let parent;
|
|
91
25
|
let current = type;
|
|
92
26
|
while (current && current !== Function.prototype) {
|
|
93
27
|
const enter = registrations.get(current);
|
|
@@ -120,9 +54,7 @@ const contexts = /* @__PURE__ */ new WeakMap();
|
|
|
120
54
|
const rootScopes = /* @__PURE__ */ new WeakMap();
|
|
121
55
|
const STYLES = Symbol("@expressive/dom.styles");
|
|
122
56
|
const entered = /* @__PURE__ */ new WeakSet();
|
|
123
|
-
|
|
124
|
-
let globalContext;
|
|
125
|
-
function createStyleScope(parent, value, label, defines) {
|
|
57
|
+
function createStyleScope(parent, value, label, pack) {
|
|
126
58
|
if (!isObject(value)) return parent;
|
|
127
59
|
const cache = parent?.children || rootScopes;
|
|
128
60
|
const cached = cache.get(value);
|
|
@@ -132,56 +64,59 @@ function createStyleScope(parent, value, label, defines) {
|
|
|
132
64
|
const base = {};
|
|
133
65
|
const scopeLabel = label || parent?.label || "style";
|
|
134
66
|
const root = { name: scopeLabel };
|
|
67
|
+
const macros = pack ? Object.create(parent?.macros || null) : parent?.macros || Object.create(null);
|
|
135
68
|
for (const key of Object.keys(value)) {
|
|
136
|
-
const entry = value[key];
|
|
69
|
+
const entry = flatten(value[key], key);
|
|
137
70
|
if (key[0] == "$") throw new Error(`Reserved key "${key}" in style map.`);
|
|
138
71
|
if (SUBCOMPONENT.test(key)) throw new Error(`Subcomponent "${key}" must be at the top of a style() map.`);
|
|
139
72
|
if (key[0] == "_") {
|
|
140
|
-
if (!isObject(entry)) throw new Error(`Rule "${key}" must be an object. Macros are defined
|
|
73
|
+
if (!isObject(entry)) throw new Error(`Rule "${key}" must be an object. Macros are defined on a Style class.`);
|
|
141
74
|
const name = key.slice(1);
|
|
142
75
|
if (!own.includes(name)) own.push(name);
|
|
143
76
|
source[name] = merge(source[name], entry);
|
|
144
|
-
} else if (isCondition(key) && isObject(entry))
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const name = inner.slice(1);
|
|
148
|
-
if (!own.includes(name)) own.push(name);
|
|
149
|
-
for (const when of split(key)) source[name] = merge(source[name], { [hoist(root, when)]: entry[inner] });
|
|
150
|
-
} else rest[inner] = entry[inner];
|
|
151
|
-
base[key] = merge(base[key], rest);
|
|
152
|
-
} else if (defines && typeof entry == "function") {
|
|
153
|
-
own.push(key);
|
|
154
|
-
source[key] = entry;
|
|
155
|
-
} else base[key] = entry;
|
|
77
|
+
} else if (isCondition(key) && isObject(entry)) base[key] = merge(base[key], lift(root, split(key).map((when) => [when]), entry, own, source));
|
|
78
|
+
else if (pack && typeof entry == "function") macros[key] = entry;
|
|
79
|
+
else base[key] = entry;
|
|
156
80
|
}
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
const local = defines ? [] : [...before, ...own.filter((name) => !before.includes(name))];
|
|
81
|
+
const before = parent ? parent.local : [];
|
|
82
|
+
const local = [...before, ...own.filter((name) => !before.includes(name))];
|
|
160
83
|
const rules = Object.create(parent?.rules || null);
|
|
161
84
|
const labels = Object.create(parent?.labels || null);
|
|
162
85
|
for (const name of own) {
|
|
163
86
|
const rule = source[name];
|
|
164
87
|
const inherited = parent?.rules[name];
|
|
165
|
-
rules[name] =
|
|
88
|
+
rules[name] = inherited ? mergeRule(inherited, rule) : rule;
|
|
166
89
|
labels[name] = scopeLabel;
|
|
167
90
|
}
|
|
168
91
|
const scope = {
|
|
169
92
|
children: /* @__PURE__ */ new WeakMap(),
|
|
170
93
|
expansions: /* @__PURE__ */ new Map(),
|
|
171
|
-
globals: parent?.globals,
|
|
172
94
|
label: scopeLabel,
|
|
173
95
|
labels,
|
|
174
96
|
local,
|
|
175
|
-
|
|
97
|
+
macros,
|
|
176
98
|
own: base,
|
|
99
|
+
pack: pack || parent?.pack,
|
|
177
100
|
routes: /* @__PURE__ */ new Map(),
|
|
178
101
|
rules
|
|
179
102
|
};
|
|
180
|
-
if (defines) scope.globals = scope;
|
|
181
103
|
if (root.group) ownGroups.set(scope, root.group);
|
|
182
104
|
cache.set(value, scope);
|
|
183
105
|
return scope;
|
|
184
106
|
}
|
|
107
|
+
function lift(frame, paths, body, own, source) {
|
|
108
|
+
const rest = {};
|
|
109
|
+
for (const key of Object.keys(body)) {
|
|
110
|
+
const entry = flatten(body[key], key);
|
|
111
|
+
if (key[0] == "_") {
|
|
112
|
+
const name = key.slice(1);
|
|
113
|
+
if (!own.includes(name)) own.push(name);
|
|
114
|
+
for (const path of paths) source[name] = merge(source[name], path.reduceRight((rule, when) => ({ [hoist(frame, when)]: rule }), entry));
|
|
115
|
+
} else if (isCondition(key) && isObject(entry)) rest[key] = lift(frame, paths.flatMap((path) => split(key).map((when) => [...path, when])), entry, own, source);
|
|
116
|
+
else rest[key] = entry;
|
|
117
|
+
}
|
|
118
|
+
return rest;
|
|
119
|
+
}
|
|
185
120
|
function createContext(scope) {
|
|
186
121
|
const cached = contexts.get(scope);
|
|
187
122
|
if (cached) return cached;
|
|
@@ -195,12 +130,12 @@ function createContext(scope) {
|
|
|
195
130
|
contexts.set(scope, context);
|
|
196
131
|
return context;
|
|
197
132
|
}
|
|
198
|
-
function extendContext(parent, maps, label,
|
|
133
|
+
function extendContext(parent, maps, label, pack) {
|
|
199
134
|
let scope = parent?.scope;
|
|
200
135
|
const base = { ...scope && bases.get(scope) };
|
|
201
136
|
const anchors = new Set(scope && groups$1.get(scope));
|
|
202
137
|
for (const map of maps) {
|
|
203
|
-
scope = createStyleScope(scope, map, label,
|
|
138
|
+
scope = createStyleScope(scope, map, label, pack);
|
|
204
139
|
Object.assign(base, mergeRule(base, scope.own));
|
|
205
140
|
const own = ownGroups.get(scope);
|
|
206
141
|
if (own) anchors.add(own);
|
|
@@ -215,16 +150,16 @@ function baseToken(scope) {
|
|
|
215
150
|
if (!base && !anchors) return void 0;
|
|
216
151
|
const frame = { name: scope.label };
|
|
217
152
|
const expansion = expand(scope, base, /* @__PURE__ */ new Map(), frame);
|
|
218
|
-
const blocks = [...toBlocks(expansion, frame,
|
|
153
|
+
const blocks = [...toBlocks(expansion, frame, -.5), ...anchors || []];
|
|
219
154
|
const appearance = {};
|
|
220
155
|
if (blocks.length) appearance.blocks = blocks;
|
|
221
156
|
if (expansion.classes.length) appearance.classes = expansion.classes;
|
|
222
157
|
return createAppearanceToken(appearance);
|
|
223
158
|
}
|
|
224
|
-
function style$1(type, rules) {
|
|
159
|
+
function style$1(type, rules, pack) {
|
|
225
160
|
if (entered.has(type)) throw new Error("Cannot add styles after a component has rendered.");
|
|
226
161
|
if (!Object.hasOwn(type, STYLES)) {
|
|
227
|
-
const
|
|
162
|
+
const name = label(type);
|
|
228
163
|
Object.defineProperty(type, STYLES, {
|
|
229
164
|
configurable: true,
|
|
230
165
|
value: {
|
|
@@ -233,29 +168,26 @@ function style$1(type, rules) {
|
|
|
233
168
|
}
|
|
234
169
|
});
|
|
235
170
|
registerAppearance(type, (parent, key) => {
|
|
236
|
-
const { own, subs } = type[STYLES];
|
|
171
|
+
const { own, pack, subs } = type[STYLES];
|
|
237
172
|
entered.add(type);
|
|
238
|
-
|
|
239
|
-
|
|
173
|
+
const maps = key ? subs[key] : own;
|
|
174
|
+
if (!maps) return parent;
|
|
175
|
+
if (pack && (parent?.scope)?.pack !== pack) parent = extendContext(parent, pack.layers, name, pack);
|
|
176
|
+
return extendContext(parent, maps, key ? `${name}_${key}` : name);
|
|
240
177
|
});
|
|
241
178
|
}
|
|
242
|
-
const
|
|
179
|
+
const styles = type[STYLES];
|
|
243
180
|
const rest = {};
|
|
181
|
+
if (pack && styles.pack && styles.pack !== pack) throw new Error(`"${label(type)}" is already styled by another Style class.`);
|
|
182
|
+
styles.pack ||= pack;
|
|
244
183
|
for (const key of Object.keys(rules)) if (SUBCOMPONENT.test(key)) {
|
|
245
|
-
|
|
246
|
-
(
|
|
184
|
+
const body = flatten(rules[key], key);
|
|
185
|
+
if (!isObject(body)) throw new Error(`Subcomponent "${key}" must be an object.`);
|
|
186
|
+
(styles.subs[key.slice(1)] ||= []).push(body);
|
|
247
187
|
} else rest[key] = rules[key];
|
|
248
|
-
own.push(rest);
|
|
188
|
+
styles.own.push(rest);
|
|
249
189
|
return type;
|
|
250
190
|
}
|
|
251
|
-
function macro$1(rules) {
|
|
252
|
-
for (const key of Object.keys(rules)) if (key[0] != "_" && key[0] != "$" && typeof rules[key] != "function") throw new Error(`Macro "${key}" must be a function. Use "_${key}" to register a rule.`);
|
|
253
|
-
if (appearanceSealed()) throw new Error("Cannot add macros after rendering has started.");
|
|
254
|
-
globals.push(rules);
|
|
255
|
-
globalContext = void 0;
|
|
256
|
-
registerAppearanceRoot(() => globalContext ||= extendContext(void 0, globals, "global", true));
|
|
257
|
-
return rules;
|
|
258
|
-
}
|
|
259
191
|
function createAppearanceRoute(scope, props, tag) {
|
|
260
192
|
if (!scope) return void 0;
|
|
261
193
|
const keys = Object.keys(props).filter((key) => key.startsWith("_")).sort();
|
|
@@ -264,14 +196,11 @@ function createAppearanceRoute(scope, props, tag) {
|
|
|
264
196
|
if (cached) return cached;
|
|
265
197
|
const present = new Set(keys.map((key) => key.slice(1)));
|
|
266
198
|
const flags = [];
|
|
267
|
-
for (const name of scope.
|
|
268
|
-
if (!present.has(name) || name == tag) continue;
|
|
269
|
-
if (isObject(scope.rules[name])) flags.push(name);
|
|
270
|
-
}
|
|
199
|
+
for (const name of scope.local) if (present.has(name) && name != tag) flags.push(name);
|
|
271
200
|
const route = {
|
|
272
201
|
flags,
|
|
273
202
|
scope,
|
|
274
|
-
tag: tag &&
|
|
203
|
+
tag: tag && scope.rules[tag] ? tag : void 0
|
|
275
204
|
};
|
|
276
205
|
scope.routes.set(id, route);
|
|
277
206
|
return route;
|
|
@@ -282,7 +211,7 @@ function resolveAppearance(scope, props, tag) {
|
|
|
282
211
|
const parts = [];
|
|
283
212
|
const names = route.tag ? [route.tag] : [];
|
|
284
213
|
for (const name of route.flags) if (props[`_${name}`]) names.push(name);
|
|
285
|
-
for (const name of names)
|
|
214
|
+
for (const name of names) parts.push(expandRule(route.scope, name));
|
|
286
215
|
const blocks = parts.flatMap((part) => part.blocks);
|
|
287
216
|
const classes = parts.flatMap((part) => part.classes);
|
|
288
217
|
let child = route.scope;
|
|
@@ -299,7 +228,7 @@ function expandRule(scope, name) {
|
|
|
299
228
|
if (!expansion) {
|
|
300
229
|
const frame = { name: `${scope.labels[name]}_${name}` };
|
|
301
230
|
expansion = expand(scope, scope.rules[name], /* @__PURE__ */ new Map(), frame);
|
|
302
|
-
expansion.blocks = toBlocks(expansion, frame,
|
|
231
|
+
expansion.blocks = toBlocks(expansion, frame, scope.local.indexOf(name));
|
|
303
232
|
scope.expansions.set(name, expansion);
|
|
304
233
|
}
|
|
305
234
|
return expansion;
|
|
@@ -336,17 +265,6 @@ function hoist(frame, condition) {
|
|
|
336
265
|
});
|
|
337
266
|
return key;
|
|
338
267
|
}
|
|
339
|
-
function shared(scope) {
|
|
340
|
-
return scope.globals ? scope.globals.names.length : 0;
|
|
341
|
-
}
|
|
342
|
-
function ordinal(scope, name) {
|
|
343
|
-
return scope.rules[name] === scope.globals?.rules[name] ? scope.names.indexOf(name) : shared(scope) + scope.local.indexOf(name);
|
|
344
|
-
}
|
|
345
|
-
function expandShadowed(scope, name, parts) {
|
|
346
|
-
const { globals } = scope;
|
|
347
|
-
if (globals && isObject(globals.rules[name]) && globals.rules[name] !== scope.rules[name]) parts.push(expandRule(globals, name));
|
|
348
|
-
parts.push(expandRule(scope, name));
|
|
349
|
-
}
|
|
350
268
|
function handlers(scope, name) {
|
|
351
269
|
let known = chains.get(scope);
|
|
352
270
|
if (!known) chains.set(scope, known = /* @__PURE__ */ new Map());
|
|
@@ -354,9 +272,9 @@ function handlers(scope, name) {
|
|
|
354
272
|
if (!chain) {
|
|
355
273
|
chain = Object.assign([], { named: 0 });
|
|
356
274
|
for (const key of [name, "*"]) {
|
|
357
|
-
for (let
|
|
358
|
-
const own = Object.getOwnPropertyDescriptor(
|
|
359
|
-
if (own
|
|
275
|
+
for (let macros = scope.macros; macros; macros = Object.getPrototypeOf(macros)) {
|
|
276
|
+
const own = Object.getOwnPropertyDescriptor(macros, key);
|
|
277
|
+
if (own) chain.push(own.value);
|
|
360
278
|
}
|
|
361
279
|
if (key == name) chain.named = chain.length;
|
|
362
280
|
}
|
|
@@ -384,7 +302,8 @@ function expand(scope, value, depths, frame) {
|
|
|
384
302
|
value.forEach((entry) => walk(entry, depths));
|
|
385
303
|
return;
|
|
386
304
|
}
|
|
387
|
-
for (const [name,
|
|
305
|
+
for (const [name, raw] of Object.entries(value)) {
|
|
306
|
+
const entry = flatten(raw, name);
|
|
388
307
|
if (name[0] == "_") {
|
|
389
308
|
if (isObject(entry)) nested[name] = merge(nested[name], entry);
|
|
390
309
|
continue;
|
|
@@ -455,9 +374,27 @@ function mergeRule(left, right) {
|
|
|
455
374
|
...left,
|
|
456
375
|
...right
|
|
457
376
|
};
|
|
458
|
-
for (const key of Object.keys(right))
|
|
377
|
+
for (const key of Object.keys(right)) {
|
|
378
|
+
if (key[0] != "_" && !isCondition(key)) continue;
|
|
379
|
+
const before = flatten(left[key], key);
|
|
380
|
+
const after = flatten(right[key], key);
|
|
381
|
+
if (isObject(before) && isObject(after)) output[key] = mergeRule(before, after);
|
|
382
|
+
}
|
|
383
|
+
return output;
|
|
384
|
+
}
|
|
385
|
+
function flatten(value, key) {
|
|
386
|
+
if (!Array.isArray(value) || key[0] != "_" && !isCondition(key)) return value;
|
|
387
|
+
let output = {};
|
|
388
|
+
for (const entry of value) {
|
|
389
|
+
const map = flatten(entry, key);
|
|
390
|
+
if (isObject(map)) output = mergeRule(output, map);
|
|
391
|
+
else if (isPresent(map)) return map;
|
|
392
|
+
}
|
|
459
393
|
return output;
|
|
460
394
|
}
|
|
395
|
+
function label(type) {
|
|
396
|
+
return type.displayName || type.name;
|
|
397
|
+
}
|
|
461
398
|
function isPresent(value) {
|
|
462
399
|
return value !== false && value !== null && value !== void 0;
|
|
463
400
|
}
|
|
@@ -486,17 +423,56 @@ function applyDeclarations(style, declarations, previous = {}) {
|
|
|
486
423
|
|
|
487
424
|
//#endregion
|
|
488
425
|
//#region src/style/stylesheet.ts
|
|
426
|
+
/**
|
|
427
|
+
* Base class for a macro pack. Each method is a macro, layered over the class
|
|
428
|
+
* it extends; `'*'` handles any key no macro owns.
|
|
429
|
+
*/
|
|
430
|
+
var Style = class {
|
|
431
|
+
/** The `style()` for this pack, created once per class. */
|
|
432
|
+
static use() {
|
|
433
|
+
let apply = bound.get(this);
|
|
434
|
+
if (!apply) {
|
|
435
|
+
let pack;
|
|
436
|
+
let built = false;
|
|
437
|
+
apply = (type, ...maps) => {
|
|
438
|
+
if (!built) {
|
|
439
|
+
pack = layers(this);
|
|
440
|
+
built = true;
|
|
441
|
+
}
|
|
442
|
+
return register(type, maps, pack);
|
|
443
|
+
};
|
|
444
|
+
bound.set(this, apply);
|
|
445
|
+
}
|
|
446
|
+
return apply;
|
|
447
|
+
}
|
|
448
|
+
};
|
|
489
449
|
const sheets = /* @__PURE__ */ new WeakMap();
|
|
450
|
+
const bound = /* @__PURE__ */ new WeakMap();
|
|
490
451
|
let groups = 0;
|
|
491
452
|
function style(type, ...maps) {
|
|
492
|
-
|
|
453
|
+
return register(type, maps);
|
|
454
|
+
}
|
|
455
|
+
function register(type, maps, pack) {
|
|
456
|
+
for (const rules of maps) if (rules) style$1(type, rules, pack);
|
|
493
457
|
registerEmitter(emit);
|
|
494
458
|
return type;
|
|
495
459
|
}
|
|
496
|
-
function
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
460
|
+
function layers(type) {
|
|
461
|
+
const instance = new type();
|
|
462
|
+
const maps = [];
|
|
463
|
+
const [field] = Object.keys(instance);
|
|
464
|
+
if (field) throw new Error(`Field "${field}" on ${type.name} is reserved. Define macros as methods.`);
|
|
465
|
+
for (let proto = type.prototype; proto !== Style.prototype; proto = Object.getPrototypeOf(proto)) {
|
|
466
|
+
const map = {};
|
|
467
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
468
|
+
if (key == "constructor") continue;
|
|
469
|
+
const { value } = Object.getOwnPropertyDescriptor(proto, key);
|
|
470
|
+
if (typeof value != "function" || key[0] == "_" || key[0] == "$") throw new Error(`"${key}" on ${type.name} must be a method with a bare name.`);
|
|
471
|
+
map[key] = value.bind(instance);
|
|
472
|
+
}
|
|
473
|
+
maps.unshift(map);
|
|
474
|
+
}
|
|
475
|
+
return maps.length ? { layers: maps } : void 0;
|
|
500
476
|
}
|
|
501
477
|
function emit(block, depth, document) {
|
|
502
478
|
let sheet = sheets.get(document);
|
|
@@ -556,6 +532,80 @@ function serialize(document, declarations) {
|
|
|
556
532
|
return value.cssText;
|
|
557
533
|
}
|
|
558
534
|
|
|
535
|
+
//#endregion
|
|
536
|
+
//#region src/style/css.ts
|
|
537
|
+
const unitless = /* @__PURE__ */ new Map();
|
|
538
|
+
let probe;
|
|
539
|
+
/**
|
|
540
|
+
* Does the CSSOM accept a bare number for this property? Probed once with a
|
|
541
|
+
* canonical value; the answer is a property of CSS, not of the value.
|
|
542
|
+
*/
|
|
543
|
+
function bare$1(property) {
|
|
544
|
+
let known = unitless.get(property);
|
|
545
|
+
if (known === void 0) {
|
|
546
|
+
probe ||= document.createElement("div").style;
|
|
547
|
+
probe[property] = "";
|
|
548
|
+
probe[property] = 1;
|
|
549
|
+
unitless.set(property, known = Boolean(probe[property]));
|
|
550
|
+
}
|
|
551
|
+
return known;
|
|
552
|
+
}
|
|
553
|
+
function sized(property, value) {
|
|
554
|
+
if (Array.isArray(value)) return value.map((entry) => sized(property, entry));
|
|
555
|
+
return typeof value == "number" && value !== 0 && !bare$1(property) ? `${value}px` : value;
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Web macro pack - pixel units for numbers and the `size` shorthand. Extend
|
|
559
|
+
* it, or use it as is with `Css.use()`.
|
|
560
|
+
*/
|
|
561
|
+
var Css = class extends Style {
|
|
562
|
+
"*"(value, key) {
|
|
563
|
+
return { [key]: sized(key, value) };
|
|
564
|
+
}
|
|
565
|
+
size(value) {
|
|
566
|
+
return Array.isArray(value) ? {
|
|
567
|
+
width: value[0],
|
|
568
|
+
height: value[1]
|
|
569
|
+
} : {
|
|
570
|
+
width: value,
|
|
571
|
+
height: value
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
//#endregion
|
|
577
|
+
//#region src/style/units.ts
|
|
578
|
+
function unit(suffix) {
|
|
579
|
+
return (...values) => values.map((value) => value + suffix).join(" ");
|
|
580
|
+
}
|
|
581
|
+
const rem = unit("rem");
|
|
582
|
+
const em = unit("em");
|
|
583
|
+
const px = unit("px");
|
|
584
|
+
|
|
585
|
+
//#endregion
|
|
586
|
+
//#region src/style/media.ts
|
|
587
|
+
const order = [
|
|
588
|
+
"minWidth",
|
|
589
|
+
"maxWidth",
|
|
590
|
+
"minHeight",
|
|
591
|
+
"maxHeight",
|
|
592
|
+
"orientation",
|
|
593
|
+
"hover",
|
|
594
|
+
"pointer",
|
|
595
|
+
"prefersColorScheme",
|
|
596
|
+
"prefersReducedMotion"
|
|
597
|
+
];
|
|
598
|
+
function media(query) {
|
|
599
|
+
const features = [];
|
|
600
|
+
for (const key of order) {
|
|
601
|
+
const value = query[key];
|
|
602
|
+
if (value === void 0) continue;
|
|
603
|
+
const feature = key.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`);
|
|
604
|
+
features.push(`(${feature}: ${typeof value == "number" ? `${value}px` : value})`);
|
|
605
|
+
}
|
|
606
|
+
return `@media ${features.join(" and ")}`;
|
|
607
|
+
}
|
|
608
|
+
|
|
559
609
|
//#endregion
|
|
560
610
|
//#region src/render/commits.ts
|
|
561
611
|
const DETACHED = /* @__PURE__ */ new WeakMap();
|
|
@@ -672,7 +722,6 @@ function componentProps(type, props, appearance) {
|
|
|
672
722
|
return {
|
|
673
723
|
appearance: {
|
|
674
724
|
author,
|
|
675
|
-
context: value.context,
|
|
676
725
|
entries,
|
|
677
726
|
lexical: value.context || context
|
|
678
727
|
},
|
|
@@ -711,8 +760,6 @@ function claim(element, appearance, resolved, className, value) {
|
|
|
711
760
|
tokens: []
|
|
712
761
|
};
|
|
713
762
|
const entries = appearance?.entries || [];
|
|
714
|
-
let context = appearance?.context;
|
|
715
|
-
let reach = -1;
|
|
716
763
|
if (resolved) collect(createAppearanceToken(resolved), collected, 0);
|
|
717
764
|
appendClasses(collected.classes, className);
|
|
718
765
|
collect(value, collected, 0);
|
|
@@ -720,14 +767,10 @@ function claim(element, appearance, resolved, className, value) {
|
|
|
720
767
|
for (const { appearance, doors } of collected.tokens) {
|
|
721
768
|
for (const block of appearance.blocks || []) collected.classes.push(emitClass(block, doors, element.ownerDocument));
|
|
722
769
|
if (appearance.classes) collected.classes.push(...appearance.classes);
|
|
723
|
-
if (appearance.context && doors >= reach) {
|
|
724
|
-
context = appearance.context;
|
|
725
|
-
reach = doors;
|
|
726
|
-
}
|
|
727
770
|
}
|
|
728
771
|
return {
|
|
729
772
|
className: [...new Set(collected.classes)].join(" "),
|
|
730
|
-
context,
|
|
773
|
+
context: resolved?.context || appearance?.context,
|
|
731
774
|
declarations: collected.declarations
|
|
732
775
|
};
|
|
733
776
|
}
|
|
@@ -880,10 +923,9 @@ function renderedAppearance(fiber) {
|
|
|
880
923
|
hops: hops + 1,
|
|
881
924
|
style
|
|
882
925
|
}));
|
|
883
|
-
const inherited = fiber.appearance?.context || appearanceRoot();
|
|
884
926
|
const sub = owner(fiber.type);
|
|
885
|
-
const context = sub ? enterAppearance(
|
|
886
|
-
if (context?.base
|
|
927
|
+
const context = sub ? enterAppearance(latest(sub.owner.constructor), sub.key) : enterAppearance(latest(fiber.type));
|
|
928
|
+
if (context?.base) entries.push({
|
|
887
929
|
hops: 0,
|
|
888
930
|
style: context.base
|
|
889
931
|
});
|
|
@@ -1378,7 +1420,7 @@ function mountOwnedComponent(value, parent, before, context, boundary, appearanc
|
|
|
1378
1420
|
}
|
|
1379
1421
|
function mountComponent(instance, parent, before, context, inherited, appearance, owned = false, key, props = instance.props, place) {
|
|
1380
1422
|
const fiber = range("component", parent, before, context);
|
|
1381
|
-
const childContext = context.push(instance);
|
|
1423
|
+
const childContext = context.push(instance, owned ? () => instance.set(null) : void 0);
|
|
1382
1424
|
const element = owned ? props : {};
|
|
1383
1425
|
const { fallback } = instance;
|
|
1384
1426
|
const ownBoundary = fallback !== void 0 && fallback !== false || element.catch || instance.catch ? {
|
|
@@ -1471,7 +1513,6 @@ function rerun(fiber, run) {
|
|
|
1471
1513
|
}
|
|
1472
1514
|
function unmountComponent(fiber) {
|
|
1473
1515
|
fiber.childContext?.pop();
|
|
1474
|
-
if (fiber.owned && !fiber.instance.get(null)) fiber.instance.set(null);
|
|
1475
1516
|
}
|
|
1476
1517
|
function renderable(value) {
|
|
1477
1518
|
return value instanceof Component;
|
|
@@ -1562,13 +1603,7 @@ function render(node, container) {
|
|
|
1562
1603
|
const context = new Context(Context.root);
|
|
1563
1604
|
const fiber = range("fragment", container, null, context);
|
|
1564
1605
|
try {
|
|
1565
|
-
pass(() =>
|
|
1566
|
-
const appearanceContext = appearanceRoot();
|
|
1567
|
-
reconcile(fiber, node, context, void 0, appearanceContext ? {
|
|
1568
|
-
context: appearanceContext,
|
|
1569
|
-
entries: []
|
|
1570
|
-
} : void 0);
|
|
1571
|
-
});
|
|
1606
|
+
pass(() => reconcile(fiber, node, context, void 0, void 0));
|
|
1572
1607
|
} catch (error) {
|
|
1573
1608
|
unmountFiber(fiber);
|
|
1574
1609
|
context.pop();
|
|
@@ -1630,5 +1665,5 @@ function attempt(fiber, passive, render) {
|
|
|
1630
1665
|
}
|
|
1631
1666
|
|
|
1632
1667
|
//#endregion
|
|
1633
|
-
export { Fragment, Portal,
|
|
1668
|
+
export { Css, Fragment, Portal, Style, createElement, em, media, px, rem, render, style };
|
|
1634
1669
|
//# sourceMappingURL=index.js.map
|