mol_plot_all 1.2.1488 → 1.2.1490

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/web.mjs CHANGED
@@ -32,2497 +32,2638 @@ $.$$ = $
32
32
  "use strict";
33
33
  var $;
34
34
  (function ($) {
35
- $.$mol_ambient_ref = Symbol('$mol_ambient_ref');
36
- function $mol_ambient(overrides) {
37
- return Object.setPrototypeOf(overrides, this || $);
38
- }
39
- $.$mol_ambient = $mol_ambient;
40
35
  })($ || ($ = {}));
41
36
 
42
37
  ;
43
38
  "use strict";
44
39
  var $;
45
40
  (function ($) {
46
- const instances = new WeakSet();
47
- function $mol_delegate(proto, target) {
48
- const proxy = new Proxy(proto, {
49
- get: (_, field) => {
50
- const obj = target();
51
- let val = Reflect.get(obj, field);
52
- if (typeof val === 'function') {
53
- val = val.bind(obj);
54
- }
55
- return val;
56
- },
57
- has: (_, field) => Reflect.has(target(), field),
58
- set: (_, field, value) => Reflect.set(target(), field, value),
59
- getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
60
- ownKeys: () => Reflect.ownKeys(target()),
61
- getPrototypeOf: () => Reflect.getPrototypeOf(target()),
62
- setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
63
- isExtensible: () => Reflect.isExtensible(target()),
64
- preventExtensions: () => Reflect.preventExtensions(target()),
65
- apply: (_, self, args) => Reflect.apply(target(), self, args),
66
- construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
67
- defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
68
- deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
69
- });
70
- instances.add(proxy);
71
- return proxy;
72
- }
73
- $.$mol_delegate = $mol_delegate;
74
- Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
75
- value: (obj) => instances.has(obj),
76
- });
41
+ $.$mol_dom_context = self;
77
42
  })($ || ($ = {}));
78
43
 
79
44
  ;
80
45
  "use strict";
81
46
  var $;
82
47
  (function ($) {
83
- $.$mol_owning_map = new WeakMap();
84
- function $mol_owning_allow(having) {
85
- try {
86
- if (!having)
87
- return false;
88
- if (typeof having !== 'object' && typeof having !== 'function')
89
- return false;
90
- if (having instanceof $mol_delegate)
91
- return false;
92
- if (typeof having['destructor'] !== 'function')
93
- return false;
94
- return true;
95
- }
96
- catch {
97
- return false;
98
- }
99
- }
100
- $.$mol_owning_allow = $mol_owning_allow;
101
- function $mol_owning_get(having, Owner) {
102
- if (!$mol_owning_allow(having))
103
- return null;
104
- while (true) {
105
- const owner = $.$mol_owning_map.get(having);
106
- if (!owner)
107
- return owner;
108
- if (!Owner)
109
- return owner;
110
- if (owner instanceof Owner)
111
- return owner;
112
- having = owner;
113
- }
114
- }
115
- $.$mol_owning_get = $mol_owning_get;
116
- function $mol_owning_check(owner, having) {
117
- if (!$mol_owning_allow(having))
118
- return false;
119
- if ($.$mol_owning_map.get(having) !== owner)
120
- return false;
121
- return true;
122
- }
123
- $.$mol_owning_check = $mol_owning_check;
124
- function $mol_owning_catch(owner, having) {
125
- if (!$mol_owning_allow(having))
126
- return false;
127
- if ($.$mol_owning_map.get(having))
128
- return false;
129
- $.$mol_owning_map.set(having, owner);
130
- return true;
131
- }
132
- $.$mol_owning_catch = $mol_owning_catch;
48
+ $.$mol_dom = $mol_dom_context;
133
49
  })($ || ($ = {}));
134
50
 
135
51
  ;
136
52
  "use strict";
137
53
  var $;
138
54
  (function ($) {
139
- function $mol_fail(error) {
140
- throw error;
55
+ function $mol_style_attach(id, text) {
56
+ const doc = $mol_dom_context.document;
57
+ if (!doc)
58
+ return null;
59
+ const elid = `$mol_style_attach:${id}`;
60
+ let el = doc.getElementById(elid);
61
+ if (!el) {
62
+ el = doc.createElement('style');
63
+ el.id = elid;
64
+ doc.head.appendChild(el);
65
+ }
66
+ if (el.innerHTML != text)
67
+ el.innerHTML = text;
68
+ return el;
141
69
  }
142
- $.$mol_fail = $mol_fail;
70
+ $.$mol_style_attach = $mol_style_attach;
143
71
  })($ || ($ = {}));
144
72
 
145
73
  ;
146
74
  "use strict";
147
75
  var $;
148
76
  (function ($) {
149
- function $mol_fail_hidden(error) {
150
- throw error;
77
+ class $mol_promise extends Promise {
78
+ done;
79
+ fail;
80
+ constructor(executor) {
81
+ let done;
82
+ let fail;
83
+ super((d, f) => {
84
+ done = d;
85
+ fail = f;
86
+ executor?.(d, f);
87
+ });
88
+ this.done = done;
89
+ this.fail = fail;
90
+ }
151
91
  }
152
- $.$mol_fail_hidden = $mol_fail_hidden;
92
+ $.$mol_promise = $mol_promise;
153
93
  })($ || ($ = {}));
154
94
 
155
- ;
156
- "use strict";
157
-
158
95
  ;
159
96
  "use strict";
160
97
  var $;
161
98
  (function ($) {
162
- const named = new WeakSet();
163
- function $mol_func_name(func) {
164
- let name = func.name;
165
- if (name?.length > 1)
166
- return name;
167
- if (named.has(func))
168
- return name;
169
- for (let key in this) {
170
- try {
171
- if (this[key] !== func)
172
- continue;
173
- name = key;
174
- Object.defineProperty(func, 'name', { value: name });
175
- break;
176
- }
177
- catch { }
178
- }
179
- named.add(func);
180
- return name;
181
- }
182
- $.$mol_func_name = $mol_func_name;
183
- function $mol_func_name_from(target, source) {
184
- Object.defineProperty(target, 'name', { value: source.name });
185
- return target;
99
+ class $mol_promise_blocker extends $mol_promise {
100
+ static [Symbol.toStringTag] = '$mol_promise_blocker';
186
101
  }
187
- $.$mol_func_name_from = $mol_func_name_from;
102
+ $.$mol_promise_blocker = $mol_promise_blocker;
188
103
  })($ || ($ = {}));
189
104
 
190
105
  ;
191
106
  "use strict";
192
107
  var $;
193
108
  (function ($) {
194
- class $mol_object2 {
195
- static $ = $;
196
- [Symbol.toStringTag];
197
- [$mol_ambient_ref] = null;
198
- get $() {
199
- if (this[$mol_ambient_ref])
200
- return this[$mol_ambient_ref];
201
- const owner = $mol_owning_get(this);
202
- return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
203
- }
204
- set $(next) {
205
- if (this[$mol_ambient_ref])
206
- $mol_fail_hidden(new Error('Context already defined'));
207
- this[$mol_ambient_ref] = next;
208
- }
209
- static create(init) {
210
- const obj = new this;
211
- if (init)
212
- init(obj);
213
- return obj;
214
- }
215
- static [Symbol.toPrimitive]() {
216
- return this.toString();
217
- }
218
- static toString() {
219
- return this[Symbol.toStringTag] || this.$.$mol_func_name(this);
220
- }
221
- static toJSON() {
222
- return this.toString();
109
+ class $mol_decor {
110
+ value;
111
+ constructor(value) {
112
+ this.value = value;
223
113
  }
224
- destructor() { }
225
- static destructor() { }
114
+ prefix() { return ''; }
115
+ valueOf() { return this.value; }
116
+ postfix() { return ''; }
226
117
  toString() {
227
- return this[Symbol.toStringTag] || this.constructor.name + '<>';
118
+ return `${this.prefix()}${this.valueOf()}${this.postfix()}`;
228
119
  }
229
120
  }
230
- $.$mol_object2 = $mol_object2;
121
+ $.$mol_decor = $mol_decor;
231
122
  })($ || ($ = {}));
232
123
 
233
124
  ;
234
125
  "use strict";
235
126
  var $;
236
- (function ($_1) {
237
- let $$;
238
- (function ($$) {
239
- let $;
240
- })($$ = $_1.$$ || ($_1.$$ = {}));
241
- $_1.$mol_object_field = Symbol('$mol_object_field');
242
- class $mol_object extends $mol_object2 {
243
- static make(config) {
244
- return super.create(obj => {
245
- for (let key in config)
246
- obj[key] = config[key];
247
- });
127
+ (function ($) {
128
+ class $mol_style_unit extends $mol_decor {
129
+ literal;
130
+ constructor(value, literal) {
131
+ super(value);
132
+ this.literal = literal;
133
+ }
134
+ postfix() {
135
+ return this.literal;
248
136
  }
137
+ static per(value) { return `${value}%`; }
138
+ static px(value) { return `${value}px`; }
139
+ static mm(value) { return `${value}mm`; }
140
+ static cm(value) { return `${value}cm`; }
141
+ static Q(value) { return `${value}Q`; }
142
+ static in(value) { return `${value}in`; }
143
+ static pc(value) { return `${value}pc`; }
144
+ static pt(value) { return `${value}pt`; }
145
+ static cap(value) { return `${value}cap`; }
146
+ static ch(value) { return `${value}ch`; }
147
+ static em(value) { return `${value}em`; }
148
+ static rem(value) { return `${value}rem`; }
149
+ static ex(value) { return `${value}ex`; }
150
+ static ic(value) { return `${value}ic`; }
151
+ static lh(value) { return `${value}lh`; }
152
+ static rlh(value) { return `${value}rlh`; }
153
+ static vh(value) { return `${value}vh`; }
154
+ static vw(value) { return `${value}vw`; }
155
+ static vi(value) { return `${value}vi`; }
156
+ static vb(value) { return `${value}vb`; }
157
+ static vmin(value) { return `${value}vmin`; }
158
+ static vmax(value) { return `${value}vmax`; }
159
+ static deg(value) { return `${value}deg`; }
160
+ static rad(value) { return `${value}rad`; }
161
+ static grad(value) { return `${value}grad`; }
162
+ static turn(value) { return `${value}turn`; }
163
+ static s(value) { return `${value}s`; }
164
+ static ms(value) { return `${value}ms`; }
249
165
  }
250
- $_1.$mol_object = $mol_object;
166
+ $.$mol_style_unit = $mol_style_unit;
251
167
  })($ || ($ = {}));
252
168
 
253
169
  ;
254
170
  "use strict";
255
171
  var $;
256
172
  (function ($) {
257
- function $mol_guid(length = 8, exists = () => false) {
258
- for (;;) {
259
- let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
260
- if (exists(id))
261
- continue;
262
- return id;
263
- }
264
- }
265
- $.$mol_guid = $mol_guid;
266
- })($ || ($ = {}));
267
-
268
- ;
269
- "use strict";
270
- var $;
271
- (function ($) {
272
- let $mol_wire_cursor;
273
- (function ($mol_wire_cursor) {
274
- $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
275
- $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
276
- $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
277
- $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
278
- })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
279
- })($ || ($ = {}));
280
-
281
- ;
282
- "use strict";
283
- var $;
284
- (function ($) {
285
- class $mol_wire_pub extends Object {
286
- constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
287
- super();
288
- this[Symbol.toStringTag] = id;
173
+ const { per } = $mol_style_unit;
174
+ class $mol_style_func extends $mol_decor {
175
+ name;
176
+ constructor(name, value) {
177
+ super(value);
178
+ this.name = name;
289
179
  }
290
- [Symbol.toStringTag];
291
- data = [];
292
- static get [Symbol.species]() {
293
- return Array;
180
+ prefix() { return this.name + '('; }
181
+ postfix() { return ')'; }
182
+ static linear_gradient(value) {
183
+ return new $mol_style_func('linear-gradient', value);
294
184
  }
295
- sub_from = 0;
296
- get sub_list() {
297
- const res = [];
298
- for (let i = this.sub_from; i < this.data.length; i += 2) {
299
- res.push(this.data[i]);
300
- }
301
- return res;
185
+ static radial_gradient(value) {
186
+ return new $mol_style_func('radial-gradient', value);
302
187
  }
303
- get sub_empty() {
304
- return this.sub_from === this.data.length;
188
+ static calc(value) {
189
+ return new $mol_style_func('calc', value);
305
190
  }
306
- sub_on(sub, pub_pos) {
307
- const pos = this.data.length;
308
- this.data.push(sub, pub_pos);
309
- return pos;
191
+ static vary(name, defaultValue) {
192
+ return new $mol_style_func('var', defaultValue ? [name, defaultValue] : name);
310
193
  }
311
- sub_off(sub_pos) {
312
- if (!(sub_pos < this.data.length)) {
313
- $mol_fail(new Error(`Wrong pos ${sub_pos}`));
314
- }
315
- const end = this.data.length - 2;
316
- if (sub_pos !== end) {
317
- this.peer_move(end, sub_pos);
318
- }
319
- this.data.length = end;
320
- if (end === this.sub_from)
321
- this.reap();
194
+ static url(href) {
195
+ return new $mol_style_func('url', JSON.stringify(href));
322
196
  }
323
- reap() { }
324
- promote() {
325
- $mol_wire_auto()?.track_next(this);
197
+ static hsla(hue, saturation, lightness, alpha) {
198
+ return new $mol_style_func('hsla', [hue, per(saturation), per(lightness), alpha]);
326
199
  }
327
- fresh() { }
328
- complete() { }
329
- get incompleted() {
330
- return false;
200
+ static clamp(min, mid, max) {
201
+ return new $mol_style_func('clamp', [min, mid, max]);
331
202
  }
332
- emit(quant = $mol_wire_cursor.stale) {
333
- for (let i = this.sub_from; i < this.data.length; i += 2) {
334
- ;
335
- this.data[i].absorb(quant, this.data[i + 1]);
336
- }
203
+ static rgba(red, green, blue, alpha) {
204
+ return new $mol_style_func('rgba', [red, green, blue, alpha]);
337
205
  }
338
- peer_move(from_pos, to_pos) {
339
- const peer = this.data[from_pos];
340
- const self_pos = this.data[from_pos + 1];
341
- this.data[to_pos] = peer;
342
- this.data[to_pos + 1] = self_pos;
343
- peer.peer_repos(self_pos, to_pos);
206
+ static scale(zoom) {
207
+ return new $mol_style_func('scale', [zoom]);
344
208
  }
345
- peer_repos(peer_pos, self_pos) {
346
- this.data[peer_pos + 1] = self_pos;
209
+ static linear(...breakpoints) {
210
+ return new $mol_style_func("linear", breakpoints.map((e) => Array.isArray(e)
211
+ ? String(e[0]) +
212
+ " " +
213
+ (typeof e[1] === "number" ? e[1] + "%" : e[1].toString())
214
+ : String(e)));
215
+ }
216
+ static cubic_bezier(x1, y1, x2, y2) {
217
+ return new $mol_style_func('cubic-bezier', [x1, y1, x2, y2]);
218
+ }
219
+ static steps(value, step_position) {
220
+ return new $mol_style_func('steps', [value, step_position]);
221
+ }
222
+ static blur(value) {
223
+ return new $mol_style_func('blur', value ?? "");
224
+ }
225
+ static brightness(value) {
226
+ return new $mol_style_func('brightness', value ?? "");
227
+ }
228
+ static contrast(value) {
229
+ return new $mol_style_func('contrast', value ?? "");
230
+ }
231
+ static drop_shadow(color, x_offset, y_offset, blur_radius) {
232
+ return new $mol_style_func("drop-shadow", blur_radius
233
+ ? [color, x_offset, y_offset, blur_radius]
234
+ : [color, x_offset, y_offset]);
235
+ }
236
+ static grayscale(value) {
237
+ return new $mol_style_func('grayscale', value ?? "");
238
+ }
239
+ static hue_rotate(value) {
240
+ return new $mol_style_func('hue-rotate', value ?? "");
241
+ }
242
+ static invert(value) {
243
+ return new $mol_style_func('invert', value ?? "");
244
+ }
245
+ static opacity(value) {
246
+ return new $mol_style_func('opacity', value ?? "");
247
+ }
248
+ static sepia(value) {
249
+ return new $mol_style_func('sepia', value ?? "");
250
+ }
251
+ static saturate(value) {
252
+ return new $mol_style_func('saturate', value ?? "");
347
253
  }
348
254
  }
349
- $.$mol_wire_pub = $mol_wire_pub;
255
+ $.$mol_style_func = $mol_style_func;
350
256
  })($ || ($ = {}));
351
257
 
352
258
  ;
353
259
  "use strict";
354
260
 
261
+ ;
262
+ "use strict";
263
+
355
264
  ;
356
265
  "use strict";
357
266
  var $;
358
267
  (function ($) {
359
- $.$mol_wire_auto_sub = null;
360
- function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
361
- return $.$mol_wire_auto_sub = next;
268
+ function $mol_style_prop(prefix, keys) {
269
+ const record = keys.reduce((rec, key) => {
270
+ rec[key] = $mol_style_func.vary(`--${prefix}_${key}`);
271
+ return rec;
272
+ }, {});
273
+ return record;
362
274
  }
363
- $.$mol_wire_auto = $mol_wire_auto;
364
- $.$mol_wire_affected = [];
275
+ $.$mol_style_prop = $mol_style_prop;
365
276
  })($ || ($ = {}));
366
277
 
367
278
  ;
368
279
  "use strict";
369
280
  var $;
370
281
  (function ($) {
371
- $['devtoolsFormatters'] ||= [];
372
- function $mol_dev_format_register(config) {
373
- $['devtoolsFormatters'].push(config);
282
+ $.$mol_theme = $mol_style_prop('mol_theme', [
283
+ 'back',
284
+ 'hover',
285
+ 'card',
286
+ 'current',
287
+ 'special',
288
+ 'text',
289
+ 'control',
290
+ 'shade',
291
+ 'line',
292
+ 'focus',
293
+ 'field',
294
+ 'image',
295
+ 'spirit',
296
+ ]);
297
+ })($ || ($ = {}));
298
+
299
+ ;
300
+ "use strict";
301
+ var $;
302
+ (function ($) {
303
+ $mol_style_attach("mol/theme/theme.css", ":root {\n\t--mol_theme_hue: 240deg;\n\t--mol_theme_hue_spread: 90deg;\n\tcolor-scheme: dark light;\n}\n\n:where([mol_theme]) {\n\tcolor: var(--mol_theme_text);\n\tfill: var(--mol_theme_text);\n\tbackground-color: var(--mol_theme_back);\n}\n\t\n:root, [mol_theme=\"$mol_theme_dark\"], :where([mol_theme=\"$mol_theme_dark\"]) [mol_theme] {\n\n\t--mol_theme_luma: -1;\n\t--mol_theme_image: invert(1) hue-rotate( 180deg );\n\t--mol_theme_spirit: hsl( 0deg, 0%, 0%, .75 );\n\n\t--mol_theme_back: hsl( var(--mol_theme_hue), 20%, 10% );\n\t--mol_theme_card: hsl( var(--mol_theme_hue), 50%, 20%, .25 );\n\t--mol_theme_field: hsl( var(--mol_theme_hue), 50%, 8%, .25 );\n\t--mol_theme_hover: hsl( var(--mol_theme_hue), 0%, 50%, .1 );\n\t\n\t--mol_theme_text: hsl( var(--mol_theme_hue), 0%, 80% );\n\t--mol_theme_shade: hsl( var(--mol_theme_hue), 0%, 60%, 1 );\n\t--mol_theme_line: hsl( var(--mol_theme_hue), 0%, 50%, .25 );\n\t--mol_theme_focus: hsl( calc( var(--mol_theme_hue) + 180deg ), 100%, 65% );\n\t\n\t--mol_theme_control: hsl( var(--mol_theme_hue), 60%, 65% );\n\t--mol_theme_current: hsl( calc( var(--mol_theme_hue) - var(--mol_theme_hue_spread) ), 60%, 65% );\n\t--mol_theme_special: hsl( calc( var(--mol_theme_hue) + var(--mol_theme_hue_spread) ), 60%, 65% );\n\n} @supports( color: oklch( 0% 0 0deg ) ) {\n:root, [mol_theme=\"$mol_theme_dark\"], :where([mol_theme=\"$mol_theme_dark\"]) [mol_theme] {\n\t\n\t--mol_theme_back: oklch( 20% .03 var(--mol_theme_hue) );\n\t--mol_theme_card: oklch( 30% .05 var(--mol_theme_hue) / .25 );\n\t--mol_theme_field: oklch( 15% 0 var(--mol_theme_hue) / .25 );\n\t--mol_theme_hover: oklch( 70% 0 var(--mol_theme_hue) / .1 );\n\t\n\t--mol_theme_text: oklch( 80% 0 var(--mol_theme_hue) );\n\t--mol_theme_shade: oklch( 60% 0 var(--mol_theme_hue) );\n\t--mol_theme_line: oklch( 60% 0 var(--mol_theme_hue) / .25 );\n\t--mol_theme_focus: oklch( 80% .2 calc( var(--mol_theme_hue) + 180deg ) );\n\t\n\t--mol_theme_control: oklch( 70% .1 var(--mol_theme_hue) );\n\t--mol_theme_current: oklch( 70% .2 calc( var(--mol_theme_hue) - var(--mol_theme_hue_spread) ) );\n\t--mol_theme_special: oklch( 70% .2 calc( var(--mol_theme_hue) + var(--mol_theme_hue_spread) ) );\n\n} }\n\n[mol_theme=\"$mol_theme_light\"], :where([mol_theme=\"$mol_theme_light\"]) [mol_theme] {\n\t\n\t--mol_theme_luma: 1;\n\t--mol_theme_image: none;\n\t--mol_theme_spirit: hsl( 0deg, 0%, 100%, .75 );\n\t\n\t--mol_theme_back: hsl( var(--mol_theme_hue), 20%, 92% );\n\t--mol_theme_card: hsl( var(--mol_theme_hue), 50%, 100%, .5 );\n\t--mol_theme_field: hsl( var(--mol_theme_hue), 50%, 100%, .75 );\n\t--mol_theme_hover: hsl( var(--mol_theme_hue), 0%, 50%, .1 );\n\t\n\t--mol_theme_text: hsl( var(--mol_theme_hue), 0%, 0% );\n\t--mol_theme_shade: hsl( var(--mol_theme_hue), 0%, 40%, 1 );\n\t--mol_theme_line: hsl( var(--mol_theme_hue), 0%, 50%, .25 );\n\t--mol_theme_focus: hsl( calc( var(--mol_theme_hue) + 180deg ), 100%, 40% );\n\t\n\t--mol_theme_control: hsl( var(--mol_theme_hue), 80%, 30% );\n\t--mol_theme_current: hsl( calc( var(--mol_theme_hue) - var(--mol_theme_hue_spread) ), 80%, 30% );\n\t--mol_theme_special: hsl( calc( var(--mol_theme_hue) + var(--mol_theme_hue_spread) ), 80%, 30% );\n\n} @supports( color: oklch( 0% 0 0deg ) ) {\n[mol_theme=\"$mol_theme_light\"], :where([mol_theme=\"$mol_theme_light\"]) [mol_theme] {\n\t--mol_theme_back: oklch( 92% .01 var(--mol_theme_hue) );\n\t--mol_theme_card: oklch( 99% .01 var(--mol_theme_hue) / .5 );\n\t--mol_theme_field: oklch( 100% 0 var(--mol_theme_hue) / .5 );\n\t--mol_theme_hover: oklch( 70% 0 var(--mol_theme_hue) / .1 );\n\t\n\t--mol_theme_text: oklch( 20% 0 var(--mol_theme_hue) );\n\t--mol_theme_shade: oklch( 60% 0 var(--mol_theme_hue) );\n\t--mol_theme_line: oklch( 50% 0 var(--mol_theme_hue) / .25 );\n\t--mol_theme_focus: oklch( 60% .2 calc( var(--mol_theme_hue) + 180deg ) );\n\t\n\t--mol_theme_control: oklch( 40% .15 var(--mol_theme_hue) );\n\t--mol_theme_current: oklch( 50% .2 calc( var(--mol_theme_hue) - var(--mol_theme_hue_spread) ) );\n\t--mol_theme_special: oklch( 50% .2 calc( var(--mol_theme_hue) + var(--mol_theme_hue_spread) ) );\n\n} }\n\n:where( :root, [mol_theme=\"$mol_theme_dark\"] ) [mol_theme=\"$mol_theme_base\"] {\n\t--mol_theme_back: oklch( 25% .075 var(--mol_theme_hue) );\n\t--mol_theme_card: oklch( 35% .1 var(--mol_theme_hue) / .25 );\n}\n:where( [mol_theme=\"$mol_theme_light\"] ) [mol_theme=\"$mol_theme_base\"] {\n\t--mol_theme_back: oklch( 85% .075 var(--mol_theme_hue) );\n\t--mol_theme_card: oklch( 98% .03 var(--mol_theme_hue) / .25 );\n}\n\n:where( :root, [mol_theme=\"$mol_theme_dark\"] ) [mol_theme=\"$mol_theme_current\"] {\n\t--mol_theme_back: oklch( 25% .05 calc( var(--mol_theme_hue) - var(--mol_theme_hue_spread) ) );\n\t--mol_theme_card: oklch( 35% .1 calc( var(--mol_theme_hue) - var(--mol_theme_hue_spread) ) / .25 );\n}\n:where( [mol_theme=\"$mol_theme_light\"] ) [mol_theme=\"$mol_theme_current\"] {\n\t--mol_theme_back: oklch( 85% .05 calc( var(--mol_theme_hue) - var(--mol_theme_hue_spread) ) );\n\t--mol_theme_card: oklch( 98% .03 calc( var(--mol_theme_hue) - var(--mol_theme_hue_spread) ) / .25 );\n}\n\n:where( :root, [mol_theme=\"$mol_theme_dark\"] ) [mol_theme=\"$mol_theme_special\"] {\n\t--mol_theme_back: oklch( 25% .05 calc( var(--mol_theme_hue) + var(--mol_theme_hue_spread) ) );\n\t--mol_theme_card: oklch( 35% .1 calc( var(--mol_theme_hue) + var(--mol_theme_hue_spread) ) / .25 );\n}\n:where( [mol_theme=\"$mol_theme_light\"] ) [mol_theme=\"$mol_theme_special\"] {\n\t--mol_theme_back: oklch( 85% .05 calc( var(--mol_theme_hue) + var(--mol_theme_hue_spread) ) );\n\t--mol_theme_card: oklch( 98% .03 calc( var(--mol_theme_hue) + var(--mol_theme_hue_spread) ) / .25 );\n}\n\n:where( :root, [mol_theme=\"$mol_theme_dark\"] ) [mol_theme=\"$mol_theme_accent\"] {\n\t--mol_theme_back: oklch( 35% .1 calc( var(--mol_theme_hue) + 180deg ) );\n\t--mol_theme_card: oklch( 45% .15 calc( var(--mol_theme_hue) + 180deg ) / .25 );\n}\n:where( [mol_theme=\"$mol_theme_light\"] ) [mol_theme=\"$mol_theme_accent\"] {\n\t--mol_theme_back: oklch( 83% .1 calc( var(--mol_theme_hue) + 180deg ) );\n\t--mol_theme_card: oklch( 98% .03 calc( var(--mol_theme_hue) + 180deg ) / .25 );\n}\n\n");
304
+ })($ || ($ = {}));
305
+
306
+ ;
307
+ "use strict";
308
+ var $;
309
+ (function ($) {
310
+ $.$mol_gap = $mol_style_prop('mol_gap', [
311
+ 'block',
312
+ 'text',
313
+ 'round',
314
+ 'space',
315
+ 'blur',
316
+ ]);
317
+ })($ || ($ = {}));
318
+
319
+ ;
320
+ "use strict";
321
+ var $;
322
+ (function ($) {
323
+ $mol_style_attach("mol/gap/gap.css", ":root {\n\t--mol_gap_block: .75rem;\n\t--mol_gap_text: .5rem .75rem;\n\t--mol_gap_round: .25rem;\n\t--mol_gap_space: .25rem;\n\t--mol_gap_blur: .5rem;\n}\n");
324
+ })($ || ($ = {}));
325
+
326
+ ;
327
+ "use strict";
328
+ var $;
329
+ (function ($) {
330
+ function $mol_fail(error) {
331
+ throw error;
374
332
  }
375
- $.$mol_dev_format_register = $mol_dev_format_register;
376
- $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
377
- $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
378
- function $mol_dev_format_button(label, click) {
379
- return $mol_dev_format_auto({
380
- [$.$mol_dev_format_head]() {
381
- return $.$mol_dev_format_span({ color: 'cornflowerblue' }, label);
382
- },
383
- [$.$mol_dev_format_body]() {
384
- Promise.resolve().then(click);
385
- return $.$mol_dev_format_span({});
333
+ $.$mol_fail = $mol_fail;
334
+ })($ || ($ = {}));
335
+
336
+ ;
337
+ "use strict";
338
+ var $;
339
+ (function ($) {
340
+ const named = new WeakSet();
341
+ function $mol_func_name(func) {
342
+ let name = func.name;
343
+ if (name?.length > 1)
344
+ return name;
345
+ if (named.has(func))
346
+ return name;
347
+ for (let key in this) {
348
+ try {
349
+ if (this[key] !== func)
350
+ continue;
351
+ name = key;
352
+ Object.defineProperty(func, 'name', { value: name });
353
+ break;
386
354
  }
387
- });
355
+ catch { }
356
+ }
357
+ named.add(func);
358
+ return name;
388
359
  }
389
- $mol_dev_format_register({
390
- header: (val, config = false) => {
391
- if (config)
392
- return null;
393
- if (!val)
394
- return null;
395
- if ($.$mol_dev_format_head in val) {
396
- try {
397
- return val[$.$mol_dev_format_head]();
398
- }
399
- catch (error) {
400
- return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
360
+ $.$mol_func_name = $mol_func_name;
361
+ function $mol_func_name_from(target, source) {
362
+ Object.defineProperty(target, 'name', { value: source.name });
363
+ return target;
364
+ }
365
+ $.$mol_func_name_from = $mol_func_name_from;
366
+ })($ || ($ = {}));
367
+
368
+ ;
369
+ "use strict";
370
+ var $;
371
+ (function ($) {
372
+ function $mol_dom_render_children(el, childNodes) {
373
+ const node_set = new Set(childNodes);
374
+ let nextNode = el.firstChild;
375
+ for (let view of childNodes) {
376
+ if (view == null)
377
+ continue;
378
+ if (view instanceof $mol_dom_context.Node) {
379
+ while (true) {
380
+ if (!nextNode) {
381
+ el.appendChild(view);
382
+ break;
383
+ }
384
+ if (nextNode == view) {
385
+ nextNode = nextNode.nextSibling;
386
+ break;
387
+ }
388
+ else {
389
+ if (node_set.has(nextNode)) {
390
+ el.insertBefore(view, nextNode);
391
+ break;
392
+ }
393
+ else {
394
+ const nn = nextNode.nextSibling;
395
+ el.removeChild(nextNode);
396
+ nextNode = nn;
397
+ }
398
+ }
401
399
  }
402
400
  }
403
- if (typeof val === 'function') {
404
- return $mol_dev_format_native(val);
401
+ else {
402
+ if (nextNode && nextNode.nodeName === '#text') {
403
+ const str = String(view);
404
+ if (nextNode.nodeValue !== str)
405
+ nextNode.nodeValue = str;
406
+ nextNode = nextNode.nextSibling;
407
+ }
408
+ else {
409
+ const textNode = $mol_dom_context.document.createTextNode(String(view));
410
+ el.insertBefore(textNode, nextNode);
411
+ }
405
412
  }
406
- if (val instanceof Error) {
407
- return $.$mol_dev_format_span({}, $mol_dev_format_native(val), ' ', $mol_dev_format_button('throw', () => $mol_fail_hidden(val)));
413
+ }
414
+ while (nextNode) {
415
+ const currNode = nextNode;
416
+ nextNode = currNode.nextSibling;
417
+ el.removeChild(currNode);
418
+ }
419
+ }
420
+ $.$mol_dom_render_children = $mol_dom_render_children;
421
+ })($ || ($ = {}));
422
+
423
+ ;
424
+ "use strict";
425
+
426
+ ;
427
+ "use strict";
428
+ var $;
429
+ (function ($) {
430
+ $.$mol_jsx_prefix = '';
431
+ $.$mol_jsx_crumbs = '';
432
+ $.$mol_jsx_booked = null;
433
+ $.$mol_jsx_document = {
434
+ getElementById: () => null,
435
+ createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
436
+ createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
437
+ };
438
+ $.$mol_jsx_frag = '';
439
+ function $mol_jsx(Elem, props, ...childNodes) {
440
+ const id = props && props.id || '';
441
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
442
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
443
+ if (Elem && $.$mol_jsx_booked) {
444
+ if ($.$mol_jsx_booked.has(id)) {
445
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
408
446
  }
409
- if (val instanceof Promise) {
410
- return $.$mol_dev_format_shade($mol_dev_format_native(val), ' ', val[Symbol.toStringTag] ?? '');
447
+ else {
448
+ $.$mol_jsx_booked.add(id);
411
449
  }
412
- if (Symbol.toStringTag in val) {
413
- return $mol_dev_format_native(val);
450
+ }
451
+ let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
452
+ if ($.$mol_jsx_prefix) {
453
+ const prefix_ext = $.$mol_jsx_prefix;
454
+ const booked_ext = $.$mol_jsx_booked;
455
+ const crumbs_ext = $.$mol_jsx_crumbs;
456
+ for (const field in props) {
457
+ const func = props[field];
458
+ if (typeof func !== 'function')
459
+ continue;
460
+ const wrapper = function (...args) {
461
+ const prefix = $.$mol_jsx_prefix;
462
+ const booked = $.$mol_jsx_booked;
463
+ const crumbs = $.$mol_jsx_crumbs;
464
+ try {
465
+ $.$mol_jsx_prefix = prefix_ext;
466
+ $.$mol_jsx_booked = booked_ext;
467
+ $.$mol_jsx_crumbs = crumbs_ext;
468
+ return func.call(this, ...args);
469
+ }
470
+ finally {
471
+ $.$mol_jsx_prefix = prefix;
472
+ $.$mol_jsx_booked = booked;
473
+ $.$mol_jsx_crumbs = crumbs;
474
+ }
475
+ };
476
+ $mol_func_name_from(wrapper, func);
477
+ props[field] = wrapper;
478
+ }
479
+ }
480
+ if (typeof Elem !== 'string') {
481
+ if ('prototype' in Elem) {
482
+ const view = node && node[String(Elem)] || new Elem;
483
+ Object.assign(view, props);
484
+ view[Symbol.toStringTag] = guid;
485
+ view.childNodes = childNodes;
486
+ if (!view.ownerDocument)
487
+ view.ownerDocument = $.$mol_jsx_document;
488
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
489
+ node = view.valueOf();
490
+ node[String(Elem)] = view;
491
+ return node;
414
492
  }
415
- return null;
416
- },
417
- hasBody: (val, config = false) => {
418
- if (config)
419
- return false;
420
- if (!val)
421
- return false;
422
- if (val[$.$mol_dev_format_body])
423
- return true;
424
- return false;
425
- },
426
- body: (val, config = false) => {
427
- if (config)
428
- return null;
429
- if (!val)
430
- return null;
431
- if ($.$mol_dev_format_body in val) {
493
+ else {
494
+ const prefix = $.$mol_jsx_prefix;
495
+ const booked = $.$mol_jsx_booked;
496
+ const crumbs = $.$mol_jsx_crumbs;
432
497
  try {
433
- return val[$.$mol_dev_format_body]();
498
+ $.$mol_jsx_prefix = guid;
499
+ $.$mol_jsx_booked = new Set;
500
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
501
+ return Elem(props, ...childNodes);
434
502
  }
435
- catch (error) {
436
- return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
503
+ finally {
504
+ $.$mol_jsx_prefix = prefix;
505
+ $.$mol_jsx_booked = booked;
506
+ $.$mol_jsx_crumbs = crumbs;
437
507
  }
438
508
  }
439
- return null;
440
- },
441
- });
442
- function $mol_dev_format_native(obj) {
443
- if (typeof obj === 'undefined')
444
- return $.$mol_dev_format_shade('undefined');
445
- return [
446
- 'object',
447
- {
448
- object: obj,
449
- config: true,
450
- },
451
- ];
452
- }
453
- $.$mol_dev_format_native = $mol_dev_format_native;
454
- function $mol_dev_format_auto(obj) {
455
- if (obj == null)
456
- return $.$mol_dev_format_shade(String(obj));
457
- return [
458
- 'object',
459
- {
460
- object: obj,
461
- config: false,
462
- },
463
- ];
464
- }
465
- $.$mol_dev_format_auto = $mol_dev_format_auto;
466
- function $mol_dev_format_element(element, style, ...content) {
467
- const styles = [];
468
- for (let key in style)
469
- styles.push(`${key} : ${style[key]}`);
470
- return [
471
- element,
472
- {
473
- style: styles.join(' ; '),
474
- },
475
- ...content,
476
- ];
477
- }
478
- $.$mol_dev_format_element = $mol_dev_format_element;
479
- $.$mol_dev_format_span = $mol_dev_format_element.bind(null, 'span');
480
- $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
481
- $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
482
- $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
483
- $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
484
- $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
485
- $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
486
- $.$mol_dev_format_accent = $.$mol_dev_format_span.bind(null, {
487
- 'color': 'magenta',
488
- });
489
- $.$mol_dev_format_strong = $.$mol_dev_format_span.bind(null, {
490
- 'font-weight': 'bold',
491
- });
492
- $.$mol_dev_format_string = $.$mol_dev_format_span.bind(null, {
493
- 'color': 'green',
494
- });
495
- $.$mol_dev_format_shade = $.$mol_dev_format_span.bind(null, {
496
- 'color': 'gray',
497
- });
498
- $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
499
- 'margin-left': '13px'
500
- });
501
- class Stack extends Array {
502
- toString() {
503
- return this.join('\n');
504
- }
505
- }
506
- class Call extends Object {
507
- type;
508
- function;
509
- method;
510
- eval;
511
- source;
512
- offset;
513
- pos;
514
- object;
515
- flags;
516
- [Symbol.toStringTag];
517
- constructor(call) {
518
- super();
519
- this.type = call.getTypeName() ?? '';
520
- this.function = call.getFunctionName() ?? '';
521
- this.method = call.getMethodName() ?? '';
522
- if (this.method === this.function)
523
- this.method = '';
524
- this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
525
- this.eval = call.getEvalOrigin() ?? '';
526
- this.source = call.getScriptNameOrSourceURL() ?? '';
527
- this.object = call.getThis();
528
- this.offset = call.getPosition();
529
- const flags = [];
530
- if (call.isAsync())
531
- flags.push('async');
532
- if (call.isConstructor())
533
- flags.push('constructor');
534
- if (call.isEval())
535
- flags.push('eval');
536
- if (call.isNative())
537
- flags.push('native');
538
- if (call.isPromiseAll())
539
- flags.push('PromiseAll');
540
- if (call.isToplevel())
541
- flags.push('top');
542
- this.flags = flags;
543
- const type = this.type ? this.type + '.' : '';
544
- const func = this.function || '<anon>';
545
- const method = this.method ? ' [' + this.method + '] ' : '';
546
- this[Symbol.toStringTag] = `${type}${func}${method}`;
547
- }
548
- [Symbol.toPrimitive]() {
549
- return this.toString();
550
509
  }
551
- toString() {
552
- const object = this.object || '';
553
- const label = this[Symbol.toStringTag];
554
- const source = `${this.source}:${this.pos.join(':')} #${this.offset}`;
555
- return `\tat ${object}${label} (${source})`;
510
+ if (!node) {
511
+ node = Elem
512
+ ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
513
+ : $.$mol_jsx_document.createDocumentFragment();
556
514
  }
557
- [$.$mol_dev_format_head]() {
558
- return $.$mol_dev_format_div({}, $mol_dev_format_native(this), $.$mol_dev_format_shade(' '), ...this.object ? [
559
- $mol_dev_format_native(this.object),
560
- ] : [], ...this.method ? [$.$mol_dev_format_shade(' ', ' [', this.method, ']')] : [], $.$mol_dev_format_shade(' ', this.flags.join(', ')));
515
+ $mol_dom_render_children(node, [].concat(...childNodes));
516
+ if (!Elem)
517
+ return node;
518
+ if (guid)
519
+ node.id = guid;
520
+ for (const key in props) {
521
+ if (key === 'id')
522
+ continue;
523
+ if (typeof props[key] === 'string') {
524
+ if (typeof node[key] === 'string')
525
+ node[key] = props[key];
526
+ node.setAttribute(key, props[key]);
527
+ }
528
+ else if (props[key] &&
529
+ typeof props[key] === 'object' &&
530
+ Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
531
+ if (typeof node[key] === 'object') {
532
+ Object.assign(node[key], props[key]);
533
+ continue;
534
+ }
535
+ }
536
+ else {
537
+ node[key] = props[key];
538
+ }
561
539
  }
540
+ if ($.$mol_jsx_crumbs)
541
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
542
+ return node;
562
543
  }
563
- Error.prepareStackTrace ??= (error, stack) => new Stack(...stack.map(call => new Call(call)));
544
+ $.$mol_jsx = $mol_jsx;
564
545
  })($ || ($ = {}));
565
546
 
566
547
  ;
567
548
  "use strict";
568
549
  var $;
569
550
  (function ($) {
570
- class $mol_wire_pub_sub extends $mol_wire_pub {
571
- pub_from = 0;
572
- cursor = $mol_wire_cursor.stale;
573
- get temp() {
574
- return false;
575
- }
576
- get pub_list() {
577
- const res = [];
578
- const max = this.cursor >= 0 ? this.cursor : this.sub_from;
579
- for (let i = this.pub_from; i < max; i += 2) {
580
- if (this.data[i])
581
- res.push(this.data[i]);
582
- }
583
- return res;
584
- }
585
- track_on() {
586
- this.cursor = this.pub_from;
587
- const sub = $mol_wire_auto();
588
- $mol_wire_auto(this);
589
- return sub;
590
- }
591
- promote() {
592
- if (this.cursor >= this.pub_from) {
593
- $mol_fail(new Error('Circular subscription'));
594
- }
595
- super.promote();
596
- }
597
- track_next(pub) {
598
- if (this.cursor < 0)
599
- $mol_fail(new Error('Promo to non begun sub'));
600
- if (this.cursor < this.sub_from) {
601
- const next = this.data[this.cursor];
602
- if (pub === undefined)
603
- return next ?? null;
604
- if (next === pub) {
605
- this.cursor += 2;
606
- return next;
607
- }
608
- if (next) {
609
- if (this.sub_from < this.data.length) {
610
- this.peer_move(this.sub_from, this.data.length);
611
- }
612
- this.peer_move(this.cursor, this.sub_from);
613
- this.sub_from += 2;
614
- }
615
- }
616
- else {
617
- if (pub === undefined)
618
- return null;
619
- if (this.sub_from < this.data.length) {
620
- this.peer_move(this.sub_from, this.data.length);
621
- }
622
- this.sub_from += 2;
623
- }
624
- this.data[this.cursor] = pub;
625
- this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
626
- this.cursor += 2;
627
- return pub;
628
- }
629
- track_off(sub) {
630
- $mol_wire_auto(sub);
631
- if (this.cursor < 0) {
632
- $mol_fail(new Error('End of non begun sub'));
633
- }
634
- for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
635
- const pub = this.data[cursor];
636
- pub.fresh();
637
- }
638
- this.cursor = $mol_wire_cursor.fresh;
639
- }
640
- pub_off(sub_pos) {
641
- this.data[sub_pos] = undefined;
642
- this.data[sub_pos + 1] = undefined;
643
- }
644
- destructor() {
645
- for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
646
- const sub = this.data[cursor];
647
- const pos = this.data[cursor + 1];
648
- sub.pub_off(pos);
649
- }
650
- this.data.length = this.sub_from;
651
- this.cursor = this.pub_from;
652
- this.track_cut();
653
- this.cursor = $mol_wire_cursor.final;
654
- }
655
- track_cut() {
656
- if (this.cursor < this.pub_from) {
657
- $mol_fail(new Error('Cut of non begun sub'));
658
- }
659
- let end = this.data.length;
660
- for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
661
- const pub = this.data[cursor];
662
- pub?.sub_off(this.data[cursor + 1]);
663
- end -= 2;
664
- if (this.sub_from <= end)
665
- this.peer_move(end, cursor);
666
- }
667
- this.data.length = end;
668
- this.sub_from = this.cursor;
669
- }
670
- complete() { }
671
- complete_pubs() {
672
- const limit = this.cursor < 0 ? this.sub_from : this.cursor;
673
- for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
674
- const pub = this.data[cursor];
675
- if (pub?.incompleted)
676
- return;
677
- }
678
- for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
679
- const pub = this.data[cursor];
680
- pub?.complete();
681
- }
682
- }
683
- absorb(quant = $mol_wire_cursor.stale, pos = -1) {
684
- if (this.cursor === $mol_wire_cursor.final)
685
- return;
686
- if (this.cursor >= quant)
687
- return;
688
- this.cursor = quant;
689
- this.emit($mol_wire_cursor.doubt);
690
- }
691
- [$mol_dev_format_head]() {
692
- return $mol_dev_format_native(this);
693
- }
694
- get pub_empty() {
695
- return this.sub_from === this.pub_from;
696
- }
551
+ $.$mol_ambient_ref = Symbol('$mol_ambient_ref');
552
+ function $mol_ambient(overrides) {
553
+ return Object.setPrototypeOf(overrides, this || $);
697
554
  }
698
- $.$mol_wire_pub_sub = $mol_wire_pub_sub;
555
+ $.$mol_ambient = $mol_ambient;
699
556
  })($ || ($ = {}));
700
557
 
701
558
  ;
702
559
  "use strict";
703
560
  var $;
704
561
  (function ($) {
705
- class $mol_after_tick extends $mol_object2 {
706
- task;
707
- static promise = null;
708
- cancelled = false;
709
- constructor(task) {
710
- super();
711
- this.task = task;
712
- if (!$mol_after_tick.promise)
713
- $mol_after_tick.promise = Promise.resolve().then(() => {
714
- $mol_after_tick.promise = null;
715
- });
716
- $mol_after_tick.promise.then(() => {
717
- if (this.cancelled)
718
- return;
719
- task();
720
- });
721
- }
722
- destructor() {
723
- this.cancelled = true;
724
- }
562
+ const instances = new WeakSet();
563
+ function $mol_delegate(proto, target) {
564
+ const proxy = new Proxy(proto, {
565
+ get: (_, field) => {
566
+ const obj = target();
567
+ let val = Reflect.get(obj, field);
568
+ if (typeof val === 'function') {
569
+ val = val.bind(obj);
570
+ }
571
+ return val;
572
+ },
573
+ has: (_, field) => Reflect.has(target(), field),
574
+ set: (_, field, value) => Reflect.set(target(), field, value),
575
+ getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
576
+ ownKeys: () => Reflect.ownKeys(target()),
577
+ getPrototypeOf: () => Reflect.getPrototypeOf(target()),
578
+ setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
579
+ isExtensible: () => Reflect.isExtensible(target()),
580
+ preventExtensions: () => Reflect.preventExtensions(target()),
581
+ apply: (_, self, args) => Reflect.apply(target(), self, args),
582
+ construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
583
+ defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
584
+ deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
585
+ });
586
+ instances.add(proxy);
587
+ return proxy;
725
588
  }
726
- $.$mol_after_tick = $mol_after_tick;
589
+ $.$mol_delegate = $mol_delegate;
590
+ Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
591
+ value: (obj) => instances.has(obj),
592
+ });
727
593
  })($ || ($ = {}));
728
594
 
729
595
  ;
730
596
  "use strict";
731
597
  var $;
732
598
  (function ($) {
733
- function $mol_promise_like(val) {
599
+ $.$mol_owning_map = new WeakMap();
600
+ function $mol_owning_allow(having) {
734
601
  try {
735
- return val && typeof val === 'object' && 'then' in val && typeof val.then === 'function';
602
+ if (!having)
603
+ return false;
604
+ if (typeof having !== 'object' && typeof having !== 'function')
605
+ return false;
606
+ if (having instanceof $mol_delegate)
607
+ return false;
608
+ if (typeof having['destructor'] !== 'function')
609
+ return false;
610
+ return true;
736
611
  }
737
612
  catch {
738
613
  return false;
739
614
  }
740
615
  }
741
- $.$mol_promise_like = $mol_promise_like;
616
+ $.$mol_owning_allow = $mol_owning_allow;
617
+ function $mol_owning_get(having, Owner) {
618
+ if (!$mol_owning_allow(having))
619
+ return null;
620
+ while (true) {
621
+ const owner = $.$mol_owning_map.get(having);
622
+ if (!owner)
623
+ return owner;
624
+ if (!Owner)
625
+ return owner;
626
+ if (owner instanceof Owner)
627
+ return owner;
628
+ having = owner;
629
+ }
630
+ }
631
+ $.$mol_owning_get = $mol_owning_get;
632
+ function $mol_owning_check(owner, having) {
633
+ if (!$mol_owning_allow(having))
634
+ return false;
635
+ if ($.$mol_owning_map.get(having) !== owner)
636
+ return false;
637
+ return true;
638
+ }
639
+ $.$mol_owning_check = $mol_owning_check;
640
+ function $mol_owning_catch(owner, having) {
641
+ if (!$mol_owning_allow(having))
642
+ return false;
643
+ if ($.$mol_owning_map.get(having))
644
+ return false;
645
+ $.$mol_owning_map.set(having, owner);
646
+ return true;
647
+ }
648
+ $.$mol_owning_catch = $mol_owning_catch;
742
649
  })($ || ($ = {}));
743
650
 
744
651
  ;
745
652
  "use strict";
746
653
  var $;
747
654
  (function ($) {
748
- const wrappers = new WeakMap();
749
- class $mol_wire_fiber extends $mol_wire_pub_sub {
750
- task;
751
- host;
752
- static warm = true;
753
- static planning = new Set();
754
- static reaping = new Set();
755
- static plan_task = null;
756
- static plan() {
757
- if (this.plan_task)
758
- return;
759
- this.plan_task = new $mol_after_tick(() => {
760
- try {
761
- this.sync();
762
- }
763
- finally {
764
- $mol_wire_fiber.plan_task = null;
765
- }
766
- });
655
+ function $mol_fail_hidden(error) {
656
+ throw error;
657
+ }
658
+ $.$mol_fail_hidden = $mol_fail_hidden;
659
+ })($ || ($ = {}));
660
+
661
+ ;
662
+ "use strict";
663
+
664
+ ;
665
+ "use strict";
666
+ var $;
667
+ (function ($) {
668
+ class $mol_object2 {
669
+ static $ = $;
670
+ [Symbol.toStringTag];
671
+ [$mol_ambient_ref] = null;
672
+ get $() {
673
+ if (this[$mol_ambient_ref])
674
+ return this[$mol_ambient_ref];
675
+ const owner = $mol_owning_get(this);
676
+ return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
767
677
  }
768
- static sync() {
769
- while (this.planning.size) {
770
- for (const fiber of this.planning) {
771
- this.planning.delete(fiber);
772
- if (fiber.cursor >= 0)
773
- continue;
774
- if (fiber.cursor === $mol_wire_cursor.final)
775
- continue;
776
- fiber.fresh();
777
- }
778
- }
779
- while (this.reaping.size) {
780
- const fibers = this.reaping;
781
- this.reaping = new Set;
782
- for (const fiber of fibers) {
783
- if (!fiber.sub_empty)
784
- continue;
785
- fiber.destructor();
786
- }
787
- }
678
+ set $(next) {
679
+ if (this[$mol_ambient_ref])
680
+ $mol_fail_hidden(new Error('Context already defined'));
681
+ this[$mol_ambient_ref] = next;
788
682
  }
789
- cache = undefined;
790
- get args() {
791
- return this.data.slice(0, this.pub_from);
683
+ static create(init) {
684
+ const obj = new this;
685
+ if (init)
686
+ init(obj);
687
+ return obj;
792
688
  }
793
- result() {
794
- if ($mol_promise_like(this.cache))
795
- return;
796
- if (this.cache instanceof Error)
797
- return;
798
- return this.cache;
689
+ static [Symbol.toPrimitive]() {
690
+ return this.toString();
799
691
  }
800
- get incompleted() {
801
- return $mol_promise_like(this.cache);
692
+ static toString() {
693
+ return this[Symbol.toStringTag] || this.$.$mol_func_name(this);
802
694
  }
803
- field() {
804
- return this.task.name + '()';
695
+ static toJSON() {
696
+ return this.toString();
805
697
  }
806
- constructor(id, task, host, args) {
807
- super(id);
808
- this.task = task;
809
- this.host = host;
810
- if (args)
811
- this.data.push(...args);
812
- this.pub_from = this.sub_from = args?.length ?? 0;
698
+ destructor() { }
699
+ static destructor() { }
700
+ toString() {
701
+ return this[Symbol.toStringTag] || this.constructor.name + '<>';
813
702
  }
814
- plan() {
815
- $mol_wire_fiber.planning.add(this);
816
- $mol_wire_fiber.plan();
817
- return this;
703
+ }
704
+ $.$mol_object2 = $mol_object2;
705
+ })($ || ($ = {}));
706
+
707
+ ;
708
+ "use strict";
709
+ var $;
710
+ (function ($_1) {
711
+ let $$;
712
+ (function ($$) {
713
+ let $;
714
+ })($$ = $_1.$$ || ($_1.$$ = {}));
715
+ $_1.$mol_object_field = Symbol('$mol_object_field');
716
+ class $mol_object extends $mol_object2 {
717
+ static make(config) {
718
+ return super.create(obj => {
719
+ for (let key in config)
720
+ obj[key] = config[key];
721
+ });
818
722
  }
819
- reap() {
820
- $mol_wire_fiber.reaping.add(this);
821
- $mol_wire_fiber.plan();
723
+ }
724
+ $_1.$mol_object = $mol_object;
725
+ })($ || ($ = {}));
726
+
727
+ ;
728
+ "use strict";
729
+ var $;
730
+ (function ($) {
731
+ function $mol_guid(length = 8, exists = () => false) {
732
+ for (;;) {
733
+ let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
734
+ if (exists(id))
735
+ continue;
736
+ return id;
822
737
  }
823
- toString() {
824
- return this[Symbol.toStringTag];
738
+ }
739
+ $.$mol_guid = $mol_guid;
740
+ })($ || ($ = {}));
741
+
742
+ ;
743
+ "use strict";
744
+ var $;
745
+ (function ($) {
746
+ let $mol_wire_cursor;
747
+ (function ($mol_wire_cursor) {
748
+ $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
749
+ $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
750
+ $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
751
+ $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
752
+ })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
753
+ })($ || ($ = {}));
754
+
755
+ ;
756
+ "use strict";
757
+ var $;
758
+ (function ($) {
759
+ class $mol_wire_pub extends Object {
760
+ constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
761
+ super();
762
+ this[Symbol.toStringTag] = id;
825
763
  }
826
- toJSON() {
827
- return this[Symbol.toStringTag];
764
+ [Symbol.toStringTag];
765
+ data = [];
766
+ static get [Symbol.species]() {
767
+ return Array;
828
768
  }
829
- [$mol_dev_format_head]() {
830
- const cursor = {
831
- [$mol_wire_cursor.stale]: '🔴',
832
- [$mol_wire_cursor.doubt]: '🟡',
833
- [$mol_wire_cursor.fresh]: '🟢',
834
- [$mol_wire_cursor.final]: '🔵',
835
- }[this.cursor] ?? this.cursor.toString();
836
- return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
837
- ? $mol_dev_format_auto({
838
- [$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
839
- [$mol_dev_format_body]: () => $mol_dev_format_native(this),
840
- })
841
- : $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
769
+ sub_from = 0;
770
+ get sub_list() {
771
+ const res = [];
772
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
773
+ res.push(this.data[i]);
774
+ }
775
+ return res;
842
776
  }
843
- get $() {
844
- return (this.host ?? this.task)['$'];
777
+ get sub_empty() {
778
+ return this.sub_from === this.data.length;
845
779
  }
846
- emit(quant = $mol_wire_cursor.stale) {
847
- if (this.sub_empty)
848
- this.plan();
849
- else
850
- super.emit(quant);
780
+ sub_on(sub, pub_pos) {
781
+ const pos = this.data.length;
782
+ this.data.push(sub, pub_pos);
783
+ return pos;
851
784
  }
852
- fresh() {
853
- if (this.cursor === $mol_wire_cursor.fresh)
854
- return;
855
- if (this.cursor === $mol_wire_cursor.final)
856
- return;
857
- check: if (this.cursor === $mol_wire_cursor.doubt) {
858
- for (let i = this.pub_from; i < this.sub_from; i += 2) {
859
- ;
860
- this.data[i]?.fresh();
861
- if (this.cursor !== $mol_wire_cursor.doubt)
862
- break check;
863
- }
864
- this.cursor = $mol_wire_cursor.fresh;
865
- return;
866
- }
867
- const bu = this.track_on();
868
- let result;
869
- try {
870
- switch (this.pub_from) {
871
- case 0:
872
- result = this.task.call(this.host);
873
- break;
874
- case 1:
875
- result = this.task.call(this.host, this.data[0]);
876
- break;
877
- default:
878
- result = this.task.call(this.host, ...this.args);
879
- break;
880
- }
881
- if ($mol_promise_like(result)) {
882
- if (wrappers.has(result)) {
883
- result = wrappers.get(result).then(a => a);
884
- }
885
- else {
886
- const put = (res) => {
887
- if (this.cache === result)
888
- this.put(res);
889
- return res;
890
- };
891
- wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
892
- wrappers.set(result, result);
893
- const error = new Error(`Promise in ${this}`);
894
- Object.defineProperty(result, 'stack', { get: () => error.stack });
895
- }
896
- }
897
- }
898
- catch (error) {
899
- if (error instanceof Error || $mol_promise_like(error)) {
900
- result = error;
901
- }
902
- else {
903
- result = new Error(String(error), { cause: error });
904
- }
905
- if ($mol_promise_like(result)) {
906
- if (wrappers.has(result)) {
907
- result = wrappers.get(result);
908
- }
909
- else {
910
- wrappers.set(result, result = Object.assign(result.finally(() => {
911
- if (this.cache === result)
912
- this.absorb();
913
- }), { destructor: result.destructor || (() => { }) }));
914
- const error = new Error(`Promise in ${this}`);
915
- Object.defineProperty(result, 'stack', { get: () => error.stack });
916
- }
917
- }
785
+ sub_off(sub_pos) {
786
+ if (!(sub_pos < this.data.length)) {
787
+ $mol_fail(new Error(`Wrong pos ${sub_pos}`));
918
788
  }
919
- if (!$mol_promise_like(result)) {
920
- this.track_cut();
789
+ const end = this.data.length - 2;
790
+ if (sub_pos !== end) {
791
+ this.peer_move(end, sub_pos);
921
792
  }
922
- this.track_off(bu);
923
- this.put(result);
924
- return this;
793
+ this.data.length = end;
794
+ if (end === this.sub_from)
795
+ this.reap();
925
796
  }
926
- refresh() {
927
- this.cursor = $mol_wire_cursor.stale;
928
- this.fresh();
797
+ reap() { }
798
+ promote() {
799
+ $mol_wire_auto()?.track_next(this);
929
800
  }
930
- sync() {
931
- if (!$mol_wire_fiber.warm) {
932
- return this.result();
933
- }
934
- this.promote();
935
- this.fresh();
936
- if (this.cache instanceof Error) {
937
- return $mol_fail_hidden(this.cache);
938
- }
939
- if ($mol_promise_like(this.cache)) {
940
- return $mol_fail_hidden(this.cache);
941
- }
942
- return this.cache;
801
+ fresh() { }
802
+ complete() { }
803
+ get incompleted() {
804
+ return false;
943
805
  }
944
- async async_raw() {
945
- while (true) {
946
- this.fresh();
947
- if (this.cache instanceof Error) {
948
- $mol_fail_hidden(this.cache);
949
- }
950
- if (!$mol_promise_like(this.cache))
951
- return this.cache;
952
- await Promise.race([this.cache, this.step()]);
953
- if (!$mol_promise_like(this.cache))
954
- return this.cache;
955
- if (this.cursor === $mol_wire_cursor.final) {
956
- await new Promise(() => { });
957
- }
806
+ emit(quant = $mol_wire_cursor.stale) {
807
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
808
+ ;
809
+ this.data[i].absorb(quant, this.data[i + 1]);
958
810
  }
959
811
  }
960
- async() {
961
- const promise = this.async_raw();
962
- if (!promise.destructor)
963
- promise.destructor = () => this.destructor();
964
- return promise;
965
- }
966
- step() {
967
- return new Promise(done => {
968
- const sub = new $mol_wire_pub_sub;
969
- const prev = sub.track_on();
970
- sub.track_next(this);
971
- sub.track_off(prev);
972
- sub.absorb = () => {
973
- done(null);
974
- setTimeout(() => sub.destructor());
975
- };
976
- });
812
+ peer_move(from_pos, to_pos) {
813
+ const peer = this.data[from_pos];
814
+ const self_pos = this.data[from_pos + 1];
815
+ this.data[to_pos] = peer;
816
+ this.data[to_pos + 1] = self_pos;
817
+ peer.peer_repos(self_pos, to_pos);
977
818
  }
978
- destructor() {
979
- super.destructor();
980
- if (!$mol_owning_check(this, this.cache))
981
- return;
982
- try {
983
- this.cache.destructor();
984
- }
985
- catch (result) {
986
- if ($mol_promise_like(result)) {
987
- const error = new Error(`Promise in ${this}.destructor()`);
988
- Object.defineProperty(result, 'stack', { get: () => error.stack });
989
- }
990
- $mol_fail_hidden(result);
991
- }
819
+ peer_repos(peer_pos, self_pos) {
820
+ this.data[peer_pos + 1] = self_pos;
992
821
  }
993
822
  }
994
- $.$mol_wire_fiber = $mol_wire_fiber;
823
+ $.$mol_wire_pub = $mol_wire_pub;
995
824
  })($ || ($ = {}));
996
825
 
997
826
  ;
998
827
  "use strict";
999
- var $;
1000
- (function ($) {
1001
- $.$mol_key_store = new WeakMap();
1002
- const TypedArray = Object.getPrototypeOf(Uint8Array);
1003
- function $mol_key(value) {
1004
- if (typeof value === 'bigint')
1005
- return value.toString() + 'n';
1006
- if (typeof value === 'symbol')
1007
- return value.description;
1008
- if (!value)
1009
- return JSON.stringify(value);
1010
- if (typeof value !== 'object' && typeof value !== 'function')
1011
- return JSON.stringify(value);
1012
- return JSON.stringify(value, (field, value) => {
1013
- if (typeof value === 'bigint')
1014
- return value.toString() + 'n';
1015
- if (typeof value === 'symbol')
1016
- return value.description;
1017
- if (!value)
1018
- return value;
1019
- if (typeof value !== 'object' && typeof value !== 'function')
1020
- return value;
1021
- if (Array.isArray(value))
1022
- return value;
1023
- const proto = Reflect.getPrototypeOf(value);
1024
- if (!proto)
1025
- return value;
1026
- if (Reflect.getPrototypeOf(proto) === null)
1027
- return value;
1028
- if ('toJSON' in value)
1029
- return value;
1030
- if (value instanceof RegExp)
1031
- return value.toString();
1032
- if (value instanceof TypedArray)
1033
- return [...value];
1034
- let key = $.$mol_key_store.get(value);
1035
- if (key)
1036
- return key;
1037
- key = $mol_guid();
1038
- $.$mol_key_store.set(value, key);
1039
- return key;
1040
- });
1041
- }
1042
- $.$mol_key = $mol_key;
1043
- })($ || ($ = {}));
1044
828
 
1045
829
  ;
1046
830
  "use strict";
1047
831
  var $;
1048
832
  (function ($) {
1049
- class $mol_after_frame extends $mol_object2 {
1050
- task;
1051
- static _promise = null;
1052
- static get promise() {
1053
- if (this._promise)
1054
- return this._promise;
1055
- return this._promise = new Promise(done => {
1056
- const complete = () => {
1057
- this._promise = null;
1058
- done();
1059
- };
1060
- if (typeof requestAnimationFrame === 'function') {
1061
- requestAnimationFrame(complete);
1062
- }
1063
- else {
1064
- setTimeout(complete, 16);
1065
- }
1066
- });
1067
- }
1068
- cancelled = false;
1069
- promise;
1070
- constructor(task) {
1071
- super();
1072
- this.task = task;
1073
- this.promise = $mol_after_frame.promise.then(() => {
1074
- if (this.cancelled)
1075
- return;
1076
- task();
1077
- });
1078
- }
1079
- destructor() {
1080
- this.cancelled = true;
1081
- }
833
+ $.$mol_wire_auto_sub = null;
834
+ function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
835
+ return $.$mol_wire_auto_sub = next;
1082
836
  }
1083
- $.$mol_after_frame = $mol_after_frame;
837
+ $.$mol_wire_auto = $mol_wire_auto;
838
+ $.$mol_wire_affected = [];
1084
839
  })($ || ($ = {}));
1085
840
 
1086
841
  ;
1087
842
  "use strict";
1088
843
  var $;
1089
844
  (function ($) {
1090
- $.$mol_compare_deep_cache = new WeakMap();
1091
- function $mol_compare_deep(left, right) {
1092
- if (Object.is(left, right))
1093
- return true;
1094
- if (left === null)
1095
- return false;
1096
- if (right === null)
1097
- return false;
1098
- if (typeof left !== 'object')
1099
- return false;
1100
- if (typeof right !== 'object')
1101
- return false;
1102
- const left_proto = Reflect.getPrototypeOf(left);
1103
- const right_proto = Reflect.getPrototypeOf(right);
1104
- if (left_proto !== right_proto)
1105
- return false;
1106
- if (left instanceof Boolean)
1107
- return Object.is(left.valueOf(), right['valueOf']());
1108
- if (left instanceof Number)
1109
- return Object.is(left.valueOf(), right['valueOf']());
1110
- if (left instanceof String)
1111
- return Object.is(left.valueOf(), right['valueOf']());
1112
- if (left instanceof Date)
1113
- return Object.is(left.valueOf(), right['valueOf']());
1114
- if (left instanceof RegExp)
1115
- return left.source === right.source && left.flags === right.flags;
1116
- if (left instanceof Error)
1117
- return left.message === right.message && $mol_compare_deep(left.stack, right.stack);
1118
- let left_cache = $.$mol_compare_deep_cache.get(left);
1119
- if (left_cache) {
1120
- const right_cache = left_cache.get(right);
1121
- if (typeof right_cache === 'boolean')
1122
- return right_cache;
1123
- }
1124
- else {
1125
- left_cache = new WeakMap();
1126
- $.$mol_compare_deep_cache.set(left, left_cache);
1127
- }
1128
- left_cache.set(right, true);
1129
- let result;
1130
- try {
1131
- if (!left_proto)
1132
- result = compare_pojo(left, right);
1133
- else if (!Reflect.getPrototypeOf(left_proto))
1134
- result = compare_pojo(left, right);
1135
- else if (Symbol.toPrimitive in left)
1136
- result = compare_primitive(left, right);
1137
- else if (Array.isArray(left))
1138
- result = compare_array(left, right);
1139
- else if (left instanceof Set)
1140
- result = compare_set(left, right);
1141
- else if (left instanceof Map)
1142
- result = compare_map(left, right);
1143
- else if (ArrayBuffer.isView(left))
1144
- result = compare_buffer(left, right);
1145
- else if (Symbol.iterator in left)
1146
- result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
1147
- else
1148
- result = false;
1149
- }
1150
- finally {
1151
- left_cache.set(right, result);
1152
- }
1153
- return result;
1154
- }
1155
- $.$mol_compare_deep = $mol_compare_deep;
1156
- function compare_array(left, right) {
1157
- const len = left.length;
1158
- if (len !== right.length)
1159
- return false;
1160
- for (let i = 0; i < len; ++i) {
1161
- if (!$mol_compare_deep(left[i], right[i]))
1162
- return false;
1163
- }
1164
- return true;
845
+ $['devtoolsFormatters'] ||= [];
846
+ function $mol_dev_format_register(config) {
847
+ $['devtoolsFormatters'].push(config);
1165
848
  }
1166
- function compare_buffer(left, right) {
1167
- const len = left.byteLength;
1168
- if (len !== right.byteLength)
1169
- return false;
1170
- if (left instanceof DataView)
1171
- return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, right.byteOffset, right.byteLength));
1172
- for (let i = 0; i < len; ++i) {
1173
- if (left[i] !== right[i])
1174
- return false;
1175
- }
1176
- return true;
849
+ $.$mol_dev_format_register = $mol_dev_format_register;
850
+ $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
851
+ $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
852
+ function $mol_dev_format_button(label, click) {
853
+ return $mol_dev_format_auto({
854
+ [$.$mol_dev_format_head]() {
855
+ return $.$mol_dev_format_span({ color: 'cornflowerblue' }, label);
856
+ },
857
+ [$.$mol_dev_format_body]() {
858
+ Promise.resolve().then(click);
859
+ return $.$mol_dev_format_span({});
860
+ }
861
+ });
1177
862
  }
1178
- function compare_iterator(left, right) {
1179
- while (true) {
1180
- const left_next = left.next();
1181
- const right_next = right.next();
1182
- if (left_next.done !== right_next.done)
863
+ $mol_dev_format_register({
864
+ header: (val, config = false) => {
865
+ if (config)
866
+ return null;
867
+ if (!val)
868
+ return null;
869
+ if ($.$mol_dev_format_head in val) {
870
+ try {
871
+ return val[$.$mol_dev_format_head]();
872
+ }
873
+ catch (error) {
874
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
875
+ }
876
+ }
877
+ if (typeof val === 'function') {
878
+ return $mol_dev_format_native(val);
879
+ }
880
+ if (val instanceof Error) {
881
+ return $.$mol_dev_format_span({}, $mol_dev_format_native(val), ' ', $mol_dev_format_button('throw', () => $mol_fail_hidden(val)));
882
+ }
883
+ if (val instanceof Promise) {
884
+ return $.$mol_dev_format_shade($mol_dev_format_native(val), ' ', val[Symbol.toStringTag] ?? '');
885
+ }
886
+ if (Symbol.toStringTag in val) {
887
+ return $mol_dev_format_native(val);
888
+ }
889
+ return null;
890
+ },
891
+ hasBody: (val, config = false) => {
892
+ if (config)
1183
893
  return false;
1184
- if (left_next.done)
1185
- break;
1186
- if (!$mol_compare_deep(left_next.value, right_next.value))
894
+ if (!val)
1187
895
  return false;
1188
- }
1189
- return true;
1190
- }
1191
- function compare_set(left, right) {
1192
- if (left.size !== right.size)
896
+ if (val[$.$mol_dev_format_body])
897
+ return true;
1193
898
  return false;
1194
- return compare_iterator(left.values(), right.values());
899
+ },
900
+ body: (val, config = false) => {
901
+ if (config)
902
+ return null;
903
+ if (!val)
904
+ return null;
905
+ if ($.$mol_dev_format_body in val) {
906
+ try {
907
+ return val[$.$mol_dev_format_body]();
908
+ }
909
+ catch (error) {
910
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
911
+ }
912
+ }
913
+ return null;
914
+ },
915
+ });
916
+ function $mol_dev_format_native(obj) {
917
+ if (typeof obj === 'undefined')
918
+ return $.$mol_dev_format_shade('undefined');
919
+ return [
920
+ 'object',
921
+ {
922
+ object: obj,
923
+ config: true,
924
+ },
925
+ ];
1195
926
  }
1196
- function compare_map(left, right) {
1197
- if (left.size !== right.size)
1198
- return false;
1199
- return compare_iterator(left.keys(), right.keys())
1200
- && compare_iterator(left.values(), right.values());
927
+ $.$mol_dev_format_native = $mol_dev_format_native;
928
+ function $mol_dev_format_auto(obj) {
929
+ if (obj == null)
930
+ return $.$mol_dev_format_shade(String(obj));
931
+ return [
932
+ 'object',
933
+ {
934
+ object: obj,
935
+ config: false,
936
+ },
937
+ ];
1201
938
  }
1202
- function compare_pojo(left, right) {
1203
- const left_keys = Object.getOwnPropertyNames(left);
1204
- const right_keys = Object.getOwnPropertyNames(right);
1205
- if (!compare_array(left_keys, right_keys))
1206
- return false;
1207
- for (let key of left_keys) {
1208
- if (!$mol_compare_deep(left[key], right[key]))
1209
- return false;
1210
- }
1211
- const left_syms = Object.getOwnPropertySymbols(left);
1212
- const right_syms = Object.getOwnPropertySymbols(right);
1213
- if (!compare_array(left_syms, right_syms))
1214
- return false;
1215
- for (let key of left_syms) {
1216
- if (!$mol_compare_deep(left[key], right[key]))
1217
- return false;
1218
- }
1219
- return true;
939
+ $.$mol_dev_format_auto = $mol_dev_format_auto;
940
+ function $mol_dev_format_element(element, style, ...content) {
941
+ const styles = [];
942
+ for (let key in style)
943
+ styles.push(`${key} : ${style[key]}`);
944
+ return [
945
+ element,
946
+ {
947
+ style: styles.join(' ; '),
948
+ },
949
+ ...content,
950
+ ];
1220
951
  }
1221
- function compare_primitive(left, right) {
1222
- return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
952
+ $.$mol_dev_format_element = $mol_dev_format_element;
953
+ $.$mol_dev_format_span = $mol_dev_format_element.bind(null, 'span');
954
+ $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
955
+ $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
956
+ $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
957
+ $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
958
+ $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
959
+ $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
960
+ $.$mol_dev_format_accent = $.$mol_dev_format_span.bind(null, {
961
+ 'color': 'magenta',
962
+ });
963
+ $.$mol_dev_format_strong = $.$mol_dev_format_span.bind(null, {
964
+ 'font-weight': 'bold',
965
+ });
966
+ $.$mol_dev_format_string = $.$mol_dev_format_span.bind(null, {
967
+ 'color': 'green',
968
+ });
969
+ $.$mol_dev_format_shade = $.$mol_dev_format_span.bind(null, {
970
+ 'color': 'gray',
971
+ });
972
+ $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
973
+ 'margin-left': '13px'
974
+ });
975
+ class Stack extends Array {
976
+ toString() {
977
+ return this.join('\n');
978
+ }
1223
979
  }
1224
- })($ || ($ = {}));
1225
-
1226
- ;
1227
- "use strict";
1228
- var $;
1229
- (function ($) {
1230
- function $mol_log3_area_lazy(event) {
1231
- const self = this.$;
1232
- const stack = self.$mol_log3_stack;
1233
- const deep = stack.length;
1234
- let logged = false;
1235
- stack.push(() => {
1236
- logged = true;
1237
- self.$mol_log3_area.call(self, event);
1238
- });
1239
- return () => {
1240
- if (logged)
1241
- self.console.groupEnd();
1242
- if (stack.length > deep)
1243
- stack.length = deep;
1244
- };
980
+ class Call extends Object {
981
+ type;
982
+ function;
983
+ method;
984
+ eval;
985
+ source;
986
+ offset;
987
+ pos;
988
+ object;
989
+ flags;
990
+ [Symbol.toStringTag];
991
+ constructor(call) {
992
+ super();
993
+ this.type = call.getTypeName() ?? '';
994
+ this.function = call.getFunctionName() ?? '';
995
+ this.method = call.getMethodName() ?? '';
996
+ if (this.method === this.function)
997
+ this.method = '';
998
+ this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
999
+ this.eval = call.getEvalOrigin() ?? '';
1000
+ this.source = call.getScriptNameOrSourceURL() ?? '';
1001
+ this.object = call.getThis();
1002
+ this.offset = call.getPosition();
1003
+ const flags = [];
1004
+ if (call.isAsync())
1005
+ flags.push('async');
1006
+ if (call.isConstructor())
1007
+ flags.push('constructor');
1008
+ if (call.isEval())
1009
+ flags.push('eval');
1010
+ if (call.isNative())
1011
+ flags.push('native');
1012
+ if (call.isPromiseAll())
1013
+ flags.push('PromiseAll');
1014
+ if (call.isToplevel())
1015
+ flags.push('top');
1016
+ this.flags = flags;
1017
+ const type = this.type ? this.type + '.' : '';
1018
+ const func = this.function || '<anon>';
1019
+ const method = this.method ? ' [' + this.method + '] ' : '';
1020
+ this[Symbol.toStringTag] = `${type}${func}${method}`;
1021
+ }
1022
+ [Symbol.toPrimitive]() {
1023
+ return this.toString();
1024
+ }
1025
+ toString() {
1026
+ const object = this.object || '';
1027
+ const label = this[Symbol.toStringTag];
1028
+ const source = `${this.source}:${this.pos.join(':')} #${this.offset}`;
1029
+ return `\tat ${object}${label} (${source})`;
1030
+ }
1031
+ [$.$mol_dev_format_head]() {
1032
+ return $.$mol_dev_format_div({}, $mol_dev_format_native(this), $.$mol_dev_format_shade(' '), ...this.object ? [
1033
+ $mol_dev_format_native(this.object),
1034
+ ] : [], ...this.method ? [$.$mol_dev_format_shade(' ', ' [', this.method, ']')] : [], $.$mol_dev_format_shade(' ', this.flags.join(', ')));
1035
+ }
1245
1036
  }
1246
- $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1247
- $.$mol_log3_stack = [];
1037
+ Error.prepareStackTrace ??= (error, stack) => new Stack(...stack.map(call => new Call(call)));
1248
1038
  })($ || ($ = {}));
1249
1039
 
1250
- ;
1251
- "use strict";
1252
-
1253
1040
  ;
1254
1041
  "use strict";
1255
1042
  var $;
1256
1043
  (function ($) {
1257
- function $mol_log3_web_make(level, color) {
1258
- return function $mol_log3_logger(event) {
1259
- const pending = this.$mol_log3_stack.pop();
1260
- if (pending)
1261
- pending();
1262
- let tpl = '%c';
1263
- const chunks = Object.entries(event);
1264
- for (let i = 0; i < chunks.length; ++i) {
1265
- tpl += (typeof chunks[i][1] === 'string') ? '%s: %s\n' : '%s: %o\n';
1044
+ class $mol_wire_pub_sub extends $mol_wire_pub {
1045
+ pub_from = 0;
1046
+ cursor = $mol_wire_cursor.stale;
1047
+ get temp() {
1048
+ return false;
1049
+ }
1050
+ get pub_list() {
1051
+ const res = [];
1052
+ const max = this.cursor >= 0 ? this.cursor : this.sub_from;
1053
+ for (let i = this.pub_from; i < max; i += 2) {
1054
+ if (this.data[i])
1055
+ res.push(this.data[i]);
1266
1056
  }
1267
- const style = `color:${color};font-weight:bolder`;
1268
- this.console[level](tpl.trim(), style, ...[].concat(...chunks));
1269
- const self = this;
1270
- return () => self.console.groupEnd();
1271
- };
1272
- }
1273
- $.$mol_log3_web_make = $mol_log3_web_make;
1274
- $.$mol_log3_come = $mol_log3_web_make('info', 'royalblue');
1275
- $.$mol_log3_done = $mol_log3_web_make('info', 'forestgreen');
1276
- $.$mol_log3_fail = $mol_log3_web_make('error', 'orangered');
1277
- $.$mol_log3_warn = $mol_log3_web_make('warn', 'goldenrod');
1278
- $.$mol_log3_rise = $mol_log3_web_make('log', 'magenta');
1279
- $.$mol_log3_area = $mol_log3_web_make('group', 'cyan');
1280
- })($ || ($ = {}));
1281
-
1282
- ;
1283
- "use strict";
1284
- var $;
1285
- (function ($) {
1286
- class $mol_wire_task extends $mol_wire_fiber {
1287
- static getter(task) {
1288
- return function $mol_wire_task_get(host, args) {
1289
- const sub = $mol_wire_auto();
1290
- const existen = sub?.track_next();
1291
- let cause = '';
1292
- reuse: if (existen) {
1293
- if (!existen.temp)
1294
- break reuse;
1295
- if (existen.task !== task) {
1296
- cause = 'task';
1297
- break reuse;
1298
- }
1299
- if (existen.host !== host) {
1300
- cause = 'host';
1301
- break reuse;
1302
- }
1303
- if (!$mol_compare_deep(existen.args, args)) {
1304
- cause = 'args';
1305
- break reuse;
1057
+ return res;
1058
+ }
1059
+ track_on() {
1060
+ this.cursor = this.pub_from;
1061
+ const sub = $mol_wire_auto();
1062
+ $mol_wire_auto(this);
1063
+ return sub;
1064
+ }
1065
+ promote() {
1066
+ if (this.cursor >= this.pub_from) {
1067
+ $mol_fail(new Error('Circular subscription'));
1068
+ }
1069
+ super.promote();
1070
+ }
1071
+ track_next(pub) {
1072
+ if (this.cursor < 0)
1073
+ $mol_fail(new Error('Promo to non begun sub'));
1074
+ if (this.cursor < this.sub_from) {
1075
+ const next = this.data[this.cursor];
1076
+ if (pub === undefined)
1077
+ return next ?? null;
1078
+ if (next === pub) {
1079
+ this.cursor += 2;
1080
+ return next;
1081
+ }
1082
+ if (next) {
1083
+ if (this.sub_from < this.data.length) {
1084
+ this.peer_move(this.sub_from, this.data.length);
1306
1085
  }
1307
- return existen;
1086
+ this.peer_move(this.cursor, this.sub_from);
1087
+ this.sub_from += 2;
1308
1088
  }
1309
- const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
1310
- const next = new $mol_wire_task(key, task, host, args);
1311
- if (existen?.temp) {
1312
- $$.$mol_log3_warn({
1313
- place: '$mol_wire_task',
1314
- message: `Different ${cause} on restart`,
1315
- sub,
1316
- prev: existen,
1317
- next,
1318
- hint: 'Maybe required additional memoization',
1319
- });
1089
+ }
1090
+ else {
1091
+ if (pub === undefined)
1092
+ return null;
1093
+ if (this.sub_from < this.data.length) {
1094
+ this.peer_move(this.sub_from, this.data.length);
1320
1095
  }
1321
- return next;
1322
- };
1096
+ this.sub_from += 2;
1097
+ }
1098
+ this.data[this.cursor] = pub;
1099
+ this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
1100
+ this.cursor += 2;
1101
+ return pub;
1323
1102
  }
1324
- get temp() {
1325
- return true;
1103
+ track_off(sub) {
1104
+ $mol_wire_auto(sub);
1105
+ if (this.cursor < 0) {
1106
+ $mol_fail(new Error('End of non begun sub'));
1107
+ }
1108
+ for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
1109
+ const pub = this.data[cursor];
1110
+ pub.fresh();
1111
+ }
1112
+ this.cursor = $mol_wire_cursor.fresh;
1326
1113
  }
1327
- complete() {
1328
- if ($mol_promise_like(this.cache))
1329
- return;
1330
- this.destructor();
1114
+ pub_off(sub_pos) {
1115
+ this.data[sub_pos] = undefined;
1116
+ this.data[sub_pos + 1] = undefined;
1331
1117
  }
1332
- put(next) {
1333
- const prev = this.cache;
1334
- this.cache = next;
1335
- if ($mol_promise_like(next)) {
1336
- this.cursor = $mol_wire_cursor.fresh;
1337
- if (next !== prev)
1338
- this.emit();
1339
- if ($mol_owning_catch(this, next)) {
1340
- try {
1341
- next[Symbol.toStringTag] = this[Symbol.toStringTag];
1342
- }
1343
- catch {
1344
- Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
1345
- }
1346
- }
1347
- return next;
1118
+ destructor() {
1119
+ for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
1120
+ const sub = this.data[cursor];
1121
+ const pos = this.data[cursor + 1];
1122
+ sub.pub_off(pos);
1348
1123
  }
1124
+ this.data.length = this.sub_from;
1125
+ this.cursor = this.pub_from;
1126
+ this.track_cut();
1349
1127
  this.cursor = $mol_wire_cursor.final;
1350
- if (this.sub_empty)
1351
- this.destructor();
1352
- else if (next !== prev)
1353
- this.emit();
1354
- return next;
1128
+ }
1129
+ track_cut() {
1130
+ if (this.cursor < this.pub_from) {
1131
+ $mol_fail(new Error('Cut of non begun sub'));
1132
+ }
1133
+ let end = this.data.length;
1134
+ for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
1135
+ const pub = this.data[cursor];
1136
+ pub?.sub_off(this.data[cursor + 1]);
1137
+ end -= 2;
1138
+ if (this.sub_from <= end)
1139
+ this.peer_move(end, cursor);
1140
+ }
1141
+ this.data.length = end;
1142
+ this.sub_from = this.cursor;
1143
+ }
1144
+ complete() { }
1145
+ complete_pubs() {
1146
+ const limit = this.cursor < 0 ? this.sub_from : this.cursor;
1147
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1148
+ const pub = this.data[cursor];
1149
+ if (pub?.incompleted)
1150
+ return;
1151
+ }
1152
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1153
+ const pub = this.data[cursor];
1154
+ pub?.complete();
1155
+ }
1156
+ }
1157
+ absorb(quant = $mol_wire_cursor.stale, pos = -1) {
1158
+ if (this.cursor === $mol_wire_cursor.final)
1159
+ return;
1160
+ if (this.cursor >= quant)
1161
+ return;
1162
+ this.cursor = quant;
1163
+ this.emit($mol_wire_cursor.doubt);
1164
+ }
1165
+ [$mol_dev_format_head]() {
1166
+ return $mol_dev_format_native(this);
1167
+ }
1168
+ get pub_empty() {
1169
+ return this.sub_from === this.pub_from;
1355
1170
  }
1356
1171
  }
1357
- $.$mol_wire_task = $mol_wire_task;
1172
+ $.$mol_wire_pub_sub = $mol_wire_pub_sub;
1358
1173
  })($ || ($ = {}));
1359
1174
 
1360
1175
  ;
1361
1176
  "use strict";
1362
1177
  var $;
1363
1178
  (function ($) {
1364
- function $mol_wire_method(host, field, descr) {
1365
- if (!descr)
1366
- descr = Reflect.getOwnPropertyDescriptor(host, field);
1367
- const orig = descr?.value ?? host[field];
1368
- const sup = Reflect.getPrototypeOf(host);
1369
- if (typeof sup[field] === 'function') {
1370
- Object.defineProperty(orig, 'name', { value: sup[field].name });
1179
+ class $mol_after_tick extends $mol_object2 {
1180
+ task;
1181
+ static promise = null;
1182
+ cancelled = false;
1183
+ constructor(task) {
1184
+ super();
1185
+ this.task = task;
1186
+ if (!$mol_after_tick.promise)
1187
+ $mol_after_tick.promise = Promise.resolve().then(() => {
1188
+ $mol_after_tick.promise = null;
1189
+ });
1190
+ $mol_after_tick.promise.then(() => {
1191
+ if (this.cancelled)
1192
+ return;
1193
+ task();
1194
+ });
1195
+ }
1196
+ destructor() {
1197
+ this.cancelled = true;
1371
1198
  }
1372
- const temp = $mol_wire_task.getter(orig);
1373
- const value = function (...args) {
1374
- const fiber = temp(this ?? null, args);
1375
- return fiber.sync();
1376
- };
1377
- Object.defineProperty(value, 'name', { value: orig.name + ' ' });
1378
- Object.assign(value, { orig });
1379
- const descr2 = { ...descr, value };
1380
- Reflect.defineProperty(host, field, descr2);
1381
- return descr2;
1382
1199
  }
1383
- $.$mol_wire_method = $mol_wire_method;
1200
+ $.$mol_after_tick = $mol_after_tick;
1384
1201
  })($ || ($ = {}));
1385
1202
 
1386
- ;
1387
- "use strict";
1388
-
1389
- ;
1390
- "use strict";
1391
-
1392
1203
  ;
1393
1204
  "use strict";
1394
1205
  var $;
1395
1206
  (function ($) {
1396
- const catched = new WeakMap();
1397
- function $mol_fail_catch(error) {
1398
- if (typeof error !== 'object')
1399
- return false;
1400
- if ($mol_promise_like(error))
1401
- $mol_fail_hidden(error);
1402
- if (catched.get(error))
1207
+ function $mol_promise_like(val) {
1208
+ try {
1209
+ return val && typeof val === 'object' && 'then' in val && typeof val.then === 'function';
1210
+ }
1211
+ catch {
1403
1212
  return false;
1404
- catched.set(error, true);
1405
- return true;
1213
+ }
1406
1214
  }
1407
- $.$mol_fail_catch = $mol_fail_catch;
1215
+ $.$mol_promise_like = $mol_promise_like;
1408
1216
  })($ || ($ = {}));
1409
1217
 
1410
1218
  ;
1411
1219
  "use strict";
1412
1220
  var $;
1413
1221
  (function ($) {
1414
- let error;
1415
- let result;
1416
- let handler;
1417
- function $mol_try(handler2) {
1418
- handler = handler2;
1419
- error = undefined;
1420
- result = undefined;
1421
- window.dispatchEvent(new Event('$mol_try'));
1422
- const error2 = error;
1423
- const result2 = result;
1424
- error = undefined;
1425
- result = undefined;
1426
- return error2 || result2;
1427
- }
1428
- $.$mol_try = $mol_try;
1429
- self.addEventListener('$mol_try', (event) => {
1430
- result = handler();
1431
- }, true);
1432
- self.addEventListener('error', (event) => {
1433
- error = event.error;
1434
- }, true);
1435
- })($ || ($ = {}));
1436
-
1437
- ;
1438
- "use strict";
1439
- var $;
1440
- (function ($) {
1441
- function $mol_fail_log(error) {
1442
- if ($mol_promise_like(error))
1443
- return false;
1444
- if (!$mol_fail_catch(error))
1445
- return false;
1446
- $mol_try(() => { $mol_fail_hidden(error); });
1447
- return true;
1448
- }
1449
- $.$mol_fail_log = $mol_fail_log;
1450
- })($ || ($ = {}));
1451
-
1452
- ;
1453
- "use strict";
1454
- var $;
1455
- (function ($) {
1456
- class $mol_wire_atom extends $mol_wire_fiber {
1457
- static solo(host, task) {
1458
- const field = task.name + '()';
1459
- const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1460
- if (existen)
1461
- return existen;
1462
- const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1463
- const key = prefix + ('.' + task.name + '<>');
1464
- const fiber = new $mol_wire_atom(key, task, host, []);
1465
- (host ?? task)[field] = fiber;
1466
- return fiber;
1467
- }
1468
- static plex(host, task, key) {
1469
- const field = task.name + '()';
1470
- let dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1471
- const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1472
- const key_str = $mol_key(key);
1473
- if (dict) {
1474
- const existen = dict.get(key_str);
1475
- if (existen)
1476
- return existen;
1477
- }
1478
- else {
1479
- dict = (host ?? task)[field] = new Map();
1480
- }
1481
- const id = prefix + ('.' + task.name) + ('<' + key_str.replace(/^"|"$/g, "'") + '>');
1482
- const fiber = new $mol_wire_atom(id, task, host, [key]);
1483
- dict.set(key_str, fiber);
1484
- return fiber;
1222
+ const wrappers = new WeakMap();
1223
+ class $mol_wire_fiber extends $mol_wire_pub_sub {
1224
+ task;
1225
+ host;
1226
+ static warm = true;
1227
+ static planning = new Set();
1228
+ static reaping = new Set();
1229
+ static plan_task = null;
1230
+ static plan() {
1231
+ if (this.plan_task)
1232
+ return;
1233
+ this.plan_task = new $mol_after_tick(() => {
1234
+ try {
1235
+ this.sync();
1236
+ }
1237
+ finally {
1238
+ $mol_wire_fiber.plan_task = null;
1239
+ }
1240
+ });
1485
1241
  }
1486
- static watching = new Set();
1487
- static watcher = null;
1488
- static watch() {
1489
- $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
1490
- for (const atom of $mol_wire_atom.watching) {
1491
- if (atom.cursor === $mol_wire_cursor.final) {
1492
- $mol_wire_atom.watching.delete(atom);
1242
+ static sync() {
1243
+ while (this.planning.size) {
1244
+ for (const fiber of this.planning) {
1245
+ this.planning.delete(fiber);
1246
+ if (fiber.cursor >= 0)
1247
+ continue;
1248
+ if (fiber.cursor === $mol_wire_cursor.final)
1249
+ continue;
1250
+ fiber.fresh();
1493
1251
  }
1494
- else {
1495
- atom.cursor = $mol_wire_cursor.stale;
1496
- atom.fresh();
1252
+ }
1253
+ while (this.reaping.size) {
1254
+ const fibers = this.reaping;
1255
+ this.reaping = new Set;
1256
+ for (const fiber of fibers) {
1257
+ if (!fiber.sub_empty)
1258
+ continue;
1259
+ fiber.destructor();
1497
1260
  }
1498
1261
  }
1499
1262
  }
1500
- watch() {
1501
- if (!$mol_wire_atom.watcher) {
1502
- $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
1503
- }
1504
- $mol_wire_atom.watching.add(this);
1263
+ cache = undefined;
1264
+ get args() {
1265
+ return this.data.slice(0, this.pub_from);
1505
1266
  }
1506
- resync(args) {
1507
- return this.put(this.task.call(this.host, ...args));
1267
+ result() {
1268
+ if ($mol_promise_like(this.cache))
1269
+ return;
1270
+ if (this.cache instanceof Error)
1271
+ return;
1272
+ return this.cache;
1508
1273
  }
1509
- once() {
1510
- return this.sync();
1274
+ get incompleted() {
1275
+ return $mol_promise_like(this.cache);
1511
1276
  }
1512
- channel() {
1513
- return Object.assign((next) => {
1514
- if (next !== undefined)
1515
- return this.resync([...this.args, next]);
1516
- if (!$mol_wire_fiber.warm)
1517
- return this.result();
1518
- if ($mol_wire_auto()?.temp) {
1519
- return this.once();
1520
- }
1521
- else {
1522
- return this.sync();
1523
- }
1524
- }, { atom: this });
1277
+ field() {
1278
+ return this.task.name + '()';
1525
1279
  }
1526
- destructor() {
1527
- super.destructor();
1528
- if (this.pub_from === 0) {
1529
- ;
1530
- (this.host ?? this.task)[this.field()] = null;
1531
- }
1532
- else {
1533
- ;
1534
- (this.host ?? this.task)[this.field()].delete($mol_key(this.args[0]));
1535
- }
1280
+ constructor(id, task, host, args) {
1281
+ super(id);
1282
+ this.task = task;
1283
+ this.host = host;
1284
+ if (args)
1285
+ this.data.push(...args);
1286
+ this.pub_from = this.sub_from = args?.length ?? 0;
1536
1287
  }
1537
- put(next) {
1538
- const prev = this.cache;
1539
- update: if (next !== prev) {
1540
- try {
1541
- if ($mol_compare_deep(prev, next))
1542
- break update;
1543
- }
1544
- catch (error) {
1545
- $mol_fail_log(error);
1288
+ plan() {
1289
+ $mol_wire_fiber.planning.add(this);
1290
+ $mol_wire_fiber.plan();
1291
+ return this;
1292
+ }
1293
+ reap() {
1294
+ $mol_wire_fiber.reaping.add(this);
1295
+ $mol_wire_fiber.plan();
1296
+ }
1297
+ toString() {
1298
+ return this[Symbol.toStringTag];
1299
+ }
1300
+ toJSON() {
1301
+ return this[Symbol.toStringTag];
1302
+ }
1303
+ [$mol_dev_format_head]() {
1304
+ const cursor = {
1305
+ [$mol_wire_cursor.stale]: '🔴',
1306
+ [$mol_wire_cursor.doubt]: '🟡',
1307
+ [$mol_wire_cursor.fresh]: '🟢',
1308
+ [$mol_wire_cursor.final]: '🔵',
1309
+ }[this.cursor] ?? this.cursor.toString();
1310
+ return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
1311
+ ? $mol_dev_format_auto({
1312
+ [$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
1313
+ [$mol_dev_format_body]: () => $mol_dev_format_native(this),
1314
+ })
1315
+ : $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
1316
+ }
1317
+ get $() {
1318
+ return (this.host ?? this.task)['$'];
1319
+ }
1320
+ emit(quant = $mol_wire_cursor.stale) {
1321
+ if (this.sub_empty)
1322
+ this.plan();
1323
+ else
1324
+ super.emit(quant);
1325
+ }
1326
+ fresh() {
1327
+ if (this.cursor === $mol_wire_cursor.fresh)
1328
+ return;
1329
+ if (this.cursor === $mol_wire_cursor.final)
1330
+ return;
1331
+ check: if (this.cursor === $mol_wire_cursor.doubt) {
1332
+ for (let i = this.pub_from; i < this.sub_from; i += 2) {
1333
+ ;
1334
+ this.data[i]?.fresh();
1335
+ if (this.cursor !== $mol_wire_cursor.doubt)
1336
+ break check;
1546
1337
  }
1547
- if ($mol_owning_check(this, prev)) {
1548
- prev.destructor();
1338
+ this.cursor = $mol_wire_cursor.fresh;
1339
+ return;
1340
+ }
1341
+ const bu = this.track_on();
1342
+ let result;
1343
+ try {
1344
+ switch (this.pub_from) {
1345
+ case 0:
1346
+ result = this.task.call(this.host);
1347
+ break;
1348
+ case 1:
1349
+ result = this.task.call(this.host, this.data[0]);
1350
+ break;
1351
+ default:
1352
+ result = this.task.call(this.host, ...this.args);
1353
+ break;
1549
1354
  }
1550
- if ($mol_owning_catch(this, next)) {
1551
- try {
1552
- next[Symbol.toStringTag] = this[Symbol.toStringTag];
1355
+ if ($mol_promise_like(result)) {
1356
+ if (wrappers.has(result)) {
1357
+ result = wrappers.get(result).then(a => a);
1553
1358
  }
1554
- catch {
1555
- Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
1359
+ else {
1360
+ const put = (res) => {
1361
+ if (this.cache === result)
1362
+ this.put(res);
1363
+ return res;
1364
+ };
1365
+ wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
1366
+ wrappers.set(result, result);
1367
+ const error = new Error(`Promise in ${this}`);
1368
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
1556
1369
  }
1557
1370
  }
1558
- if (!this.sub_empty)
1559
- this.emit();
1560
1371
  }
1561
- this.cache = next;
1562
- this.cursor = $mol_wire_cursor.fresh;
1563
- if ($mol_promise_like(next))
1564
- return next;
1565
- this.complete_pubs();
1566
- return next;
1567
- }
1568
- }
1569
- __decorate([
1570
- $mol_wire_method
1571
- ], $mol_wire_atom.prototype, "resync", null);
1572
- __decorate([
1573
- $mol_wire_method
1574
- ], $mol_wire_atom.prototype, "once", null);
1575
- $.$mol_wire_atom = $mol_wire_atom;
1576
- })($ || ($ = {}));
1577
-
1578
- ;
1579
- "use strict";
1580
- var $;
1581
- (function ($) {
1582
- function $mol_wire_solo(host, field, descr) {
1583
- if (!descr)
1584
- descr = Reflect.getOwnPropertyDescriptor(host, field);
1585
- const orig = descr?.value ?? host[field];
1586
- const sup = Reflect.getPrototypeOf(host);
1587
- if (typeof sup[field] === 'function') {
1588
- Object.defineProperty(orig, 'name', { value: sup[field].name });
1589
- }
1590
- const descr2 = {
1591
- ...descr,
1592
- value: function (...args) {
1593
- let atom = $mol_wire_atom.solo(this, orig);
1594
- if ((args.length === 0) || (args[0] === undefined)) {
1595
- if (!$mol_wire_fiber.warm)
1596
- return atom.result();
1597
- if ($mol_wire_auto()?.temp) {
1598
- return atom.once();
1372
+ catch (error) {
1373
+ if (error instanceof Error || $mol_promise_like(error)) {
1374
+ result = error;
1375
+ }
1376
+ else {
1377
+ result = new Error(String(error), { cause: error });
1378
+ }
1379
+ if ($mol_promise_like(result)) {
1380
+ if (wrappers.has(result)) {
1381
+ result = wrappers.get(result);
1599
1382
  }
1600
1383
  else {
1601
- return atom.sync();
1384
+ wrappers.set(result, result = Object.assign(result.finally(() => {
1385
+ if (this.cache === result)
1386
+ this.absorb();
1387
+ }), { destructor: result.destructor || (() => { }) }));
1388
+ const error = new Error(`Promise in ${this}`);
1389
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
1602
1390
  }
1603
1391
  }
1604
- return atom.resync(args);
1605
1392
  }
1606
- };
1607
- Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
1608
- Reflect.defineProperty(descr2.value, 'length', { value: orig.length });
1609
- Object.assign(descr2.value, { orig });
1610
- Reflect.defineProperty(host, field, descr2);
1611
- return descr2;
1393
+ if (!$mol_promise_like(result)) {
1394
+ this.track_cut();
1395
+ }
1396
+ this.track_off(bu);
1397
+ this.put(result);
1398
+ return this;
1399
+ }
1400
+ refresh() {
1401
+ this.cursor = $mol_wire_cursor.stale;
1402
+ this.fresh();
1403
+ }
1404
+ sync() {
1405
+ if (!$mol_wire_fiber.warm) {
1406
+ return this.result();
1407
+ }
1408
+ this.promote();
1409
+ this.fresh();
1410
+ if (this.cache instanceof Error) {
1411
+ return $mol_fail_hidden(this.cache);
1412
+ }
1413
+ if ($mol_promise_like(this.cache)) {
1414
+ return $mol_fail_hidden(this.cache);
1415
+ }
1416
+ return this.cache;
1417
+ }
1418
+ async async_raw() {
1419
+ while (true) {
1420
+ this.fresh();
1421
+ if (this.cache instanceof Error) {
1422
+ $mol_fail_hidden(this.cache);
1423
+ }
1424
+ if (!$mol_promise_like(this.cache))
1425
+ return this.cache;
1426
+ await Promise.race([this.cache, this.step()]);
1427
+ if (!$mol_promise_like(this.cache))
1428
+ return this.cache;
1429
+ if (this.cursor === $mol_wire_cursor.final) {
1430
+ await new Promise(() => { });
1431
+ }
1432
+ }
1433
+ }
1434
+ async() {
1435
+ const promise = this.async_raw();
1436
+ if (!promise.destructor)
1437
+ promise.destructor = () => this.destructor();
1438
+ return promise;
1439
+ }
1440
+ step() {
1441
+ return new Promise(done => {
1442
+ const sub = new $mol_wire_pub_sub;
1443
+ const prev = sub.track_on();
1444
+ sub.track_next(this);
1445
+ sub.track_off(prev);
1446
+ sub.absorb = () => {
1447
+ done(null);
1448
+ setTimeout(() => sub.destructor());
1449
+ };
1450
+ });
1451
+ }
1452
+ destructor() {
1453
+ super.destructor();
1454
+ if (!$mol_owning_check(this, this.cache))
1455
+ return;
1456
+ try {
1457
+ this.cache.destructor();
1458
+ }
1459
+ catch (result) {
1460
+ if ($mol_promise_like(result)) {
1461
+ const error = new Error(`Promise in ${this}.destructor()`);
1462
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
1463
+ }
1464
+ $mol_fail_hidden(result);
1465
+ }
1466
+ }
1612
1467
  }
1613
- $.$mol_wire_solo = $mol_wire_solo;
1468
+ $.$mol_wire_fiber = $mol_wire_fiber;
1614
1469
  })($ || ($ = {}));
1615
1470
 
1616
1471
  ;
1617
1472
  "use strict";
1618
1473
  var $;
1619
1474
  (function ($) {
1620
- function $mol_wire_plex(host, field, descr) {
1621
- if (!descr)
1622
- descr = Reflect.getOwnPropertyDescriptor(host, field);
1623
- const orig = descr?.value ?? host[field];
1624
- const sup = Reflect.getPrototypeOf(host);
1625
- if (typeof sup[field] === 'function') {
1626
- Object.defineProperty(orig, 'name', { value: sup[field].name });
1627
- }
1628
- const descr2 = {
1629
- ...descr,
1630
- value: function (...args) {
1631
- let atom = $mol_wire_atom.plex(this, orig, args[0]);
1632
- if ((args.length === 1) || (args[1] === undefined)) {
1633
- if (!$mol_wire_fiber.warm)
1634
- return atom.result();
1635
- if ($mol_wire_auto()?.temp) {
1636
- return atom.once();
1637
- }
1638
- else {
1639
- return atom.sync();
1640
- }
1641
- }
1642
- return atom.resync(args);
1643
- }
1644
- };
1645
- Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
1646
- Reflect.defineProperty(descr2.value, 'length', { value: orig.length });
1647
- Object.assign(descr2.value, { orig });
1648
- Reflect.defineProperty(host, field, descr2);
1649
- return descr2;
1475
+ $.$mol_key_store = new WeakMap();
1476
+ const TypedArray = Object.getPrototypeOf(Uint8Array);
1477
+ function $mol_key(value) {
1478
+ if (typeof value === 'bigint')
1479
+ return value.toString() + 'n';
1480
+ if (typeof value === 'symbol')
1481
+ return value.description;
1482
+ if (!value)
1483
+ return JSON.stringify(value);
1484
+ if (typeof value !== 'object' && typeof value !== 'function')
1485
+ return JSON.stringify(value);
1486
+ return JSON.stringify(value, (field, value) => {
1487
+ if (typeof value === 'bigint')
1488
+ return value.toString() + 'n';
1489
+ if (typeof value === 'symbol')
1490
+ return value.description;
1491
+ if (!value)
1492
+ return value;
1493
+ if (typeof value !== 'object' && typeof value !== 'function')
1494
+ return value;
1495
+ if (Array.isArray(value))
1496
+ return value;
1497
+ const proto = Reflect.getPrototypeOf(value);
1498
+ if (!proto)
1499
+ return value;
1500
+ if (Reflect.getPrototypeOf(proto) === null)
1501
+ return value;
1502
+ if ('toJSON' in value)
1503
+ return value;
1504
+ if (value instanceof RegExp)
1505
+ return value.toString();
1506
+ if (value instanceof TypedArray)
1507
+ return [...value];
1508
+ let key = $.$mol_key_store.get(value);
1509
+ if (key)
1510
+ return key;
1511
+ key = $mol_guid();
1512
+ $.$mol_key_store.set(value, key);
1513
+ return key;
1514
+ });
1650
1515
  }
1651
- $.$mol_wire_plex = $mol_wire_plex;
1516
+ $.$mol_key = $mol_key;
1652
1517
  })($ || ($ = {}));
1653
1518
 
1654
1519
  ;
1655
1520
  "use strict";
1656
1521
  var $;
1657
1522
  (function ($) {
1658
- $.$mol_mem = $mol_wire_solo;
1659
- $.$mol_mem_key = $mol_wire_plex;
1523
+ class $mol_after_frame extends $mol_object2 {
1524
+ task;
1525
+ static _promise = null;
1526
+ static get promise() {
1527
+ if (this._promise)
1528
+ return this._promise;
1529
+ return this._promise = new Promise(done => {
1530
+ const complete = () => {
1531
+ this._promise = null;
1532
+ done();
1533
+ };
1534
+ if (typeof requestAnimationFrame === 'function') {
1535
+ requestAnimationFrame(complete);
1536
+ }
1537
+ else {
1538
+ setTimeout(complete, 16);
1539
+ }
1540
+ });
1541
+ }
1542
+ cancelled = false;
1543
+ promise;
1544
+ constructor(task) {
1545
+ super();
1546
+ this.task = task;
1547
+ this.promise = $mol_after_frame.promise.then(() => {
1548
+ if (this.cancelled)
1549
+ return;
1550
+ task();
1551
+ });
1552
+ }
1553
+ destructor() {
1554
+ this.cancelled = true;
1555
+ }
1556
+ }
1557
+ $.$mol_after_frame = $mol_after_frame;
1660
1558
  })($ || ($ = {}));
1661
1559
 
1662
1560
  ;
1663
1561
  "use strict";
1664
1562
  var $;
1665
1563
  (function ($) {
1666
- class $mol_window extends $mol_object {
1667
- static size() {
1668
- this.resizes();
1669
- return {
1670
- width: self.innerWidth,
1671
- height: self.innerHeight,
1672
- };
1673
- }
1674
- static resizes(next) { return next; }
1675
- }
1676
- __decorate([
1677
- $mol_mem
1678
- ], $mol_window, "size", null);
1679
- __decorate([
1680
- $mol_mem
1681
- ], $mol_window, "resizes", null);
1682
- $.$mol_window = $mol_window;
1683
- self.addEventListener('resize', event => $mol_window.resizes(event));
1684
- })($ || ($ = {}));
1685
-
1686
- ;
1687
- "use strict";
1688
- var $;
1689
- (function ($) {
1690
- })($ || ($ = {}));
1691
-
1692
- ;
1693
- "use strict";
1694
- var $;
1695
- (function ($) {
1696
- $.$mol_dom_context = self;
1697
- })($ || ($ = {}));
1698
-
1699
- ;
1700
- "use strict";
1701
- var $;
1702
- (function ($) {
1703
- class $mol_view_selection extends $mol_object {
1704
- static focused(next, notify) {
1705
- const parents = [];
1706
- let element = next?.[0] ?? $mol_dom_context.document.activeElement;
1707
- while (element?.shadowRoot) {
1708
- element = element.shadowRoot.activeElement;
1709
- }
1710
- while (element) {
1711
- parents.push(element);
1712
- const parent = element.parentNode;
1713
- if (parent instanceof ShadowRoot)
1714
- element = parent.host;
1715
- else
1716
- element = parent;
1717
- }
1718
- if (!next || notify)
1719
- return parents;
1720
- new $mol_after_tick(() => {
1721
- const element = this.focused()[0];
1722
- if (element)
1723
- element.focus();
1724
- else
1725
- $mol_dom_context.blur();
1726
- });
1727
- return parents;
1564
+ $.$mol_compare_deep_cache = new WeakMap();
1565
+ function $mol_compare_deep(left, right) {
1566
+ if (Object.is(left, right))
1567
+ return true;
1568
+ if (left === null)
1569
+ return false;
1570
+ if (right === null)
1571
+ return false;
1572
+ if (typeof left !== 'object')
1573
+ return false;
1574
+ if (typeof right !== 'object')
1575
+ return false;
1576
+ const left_proto = Reflect.getPrototypeOf(left);
1577
+ const right_proto = Reflect.getPrototypeOf(right);
1578
+ if (left_proto !== right_proto)
1579
+ return false;
1580
+ if (left instanceof Boolean)
1581
+ return Object.is(left.valueOf(), right['valueOf']());
1582
+ if (left instanceof Number)
1583
+ return Object.is(left.valueOf(), right['valueOf']());
1584
+ if (left instanceof String)
1585
+ return Object.is(left.valueOf(), right['valueOf']());
1586
+ if (left instanceof Date)
1587
+ return Object.is(left.valueOf(), right['valueOf']());
1588
+ if (left instanceof RegExp)
1589
+ return left.source === right.source && left.flags === right.flags;
1590
+ if (left instanceof Error)
1591
+ return left.message === right.message && $mol_compare_deep(left.stack, right.stack);
1592
+ let left_cache = $.$mol_compare_deep_cache.get(left);
1593
+ if (left_cache) {
1594
+ const right_cache = left_cache.get(right);
1595
+ if (typeof right_cache === 'boolean')
1596
+ return right_cache;
1597
+ }
1598
+ else {
1599
+ left_cache = new WeakMap();
1600
+ $.$mol_compare_deep_cache.set(left, left_cache);
1601
+ }
1602
+ left_cache.set(right, true);
1603
+ let result;
1604
+ try {
1605
+ if (!left_proto)
1606
+ result = compare_pojo(left, right);
1607
+ else if (!Reflect.getPrototypeOf(left_proto))
1608
+ result = compare_pojo(left, right);
1609
+ else if (Symbol.toPrimitive in left)
1610
+ result = compare_primitive(left, right);
1611
+ else if (Array.isArray(left))
1612
+ result = compare_array(left, right);
1613
+ else if (left instanceof Set)
1614
+ result = compare_set(left, right);
1615
+ else if (left instanceof Map)
1616
+ result = compare_map(left, right);
1617
+ else if (ArrayBuffer.isView(left))
1618
+ result = compare_buffer(left, right);
1619
+ else if (Symbol.iterator in left)
1620
+ result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
1621
+ else
1622
+ result = false;
1728
1623
  }
1624
+ finally {
1625
+ left_cache.set(right, result);
1626
+ }
1627
+ return result;
1729
1628
  }
1730
- __decorate([
1731
- $mol_mem
1732
- ], $mol_view_selection, "focused", null);
1733
- $.$mol_view_selection = $mol_view_selection;
1734
- })($ || ($ = {}));
1735
-
1736
- ;
1737
- "use strict";
1738
- var $;
1739
- (function ($) {
1740
- function $mol_maybe(value) {
1741
- return (value == null) ? [] : [value];
1629
+ $.$mol_compare_deep = $mol_compare_deep;
1630
+ function compare_array(left, right) {
1631
+ const len = left.length;
1632
+ if (len !== right.length)
1633
+ return false;
1634
+ for (let i = 0; i < len; ++i) {
1635
+ if (!$mol_compare_deep(left[i], right[i]))
1636
+ return false;
1637
+ }
1638
+ return true;
1639
+ }
1640
+ function compare_buffer(left, right) {
1641
+ const len = left.byteLength;
1642
+ if (len !== right.byteLength)
1643
+ return false;
1644
+ if (left instanceof DataView)
1645
+ return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, right.byteOffset, right.byteLength));
1646
+ for (let i = 0; i < len; ++i) {
1647
+ if (left[i] !== right[i])
1648
+ return false;
1649
+ }
1650
+ return true;
1651
+ }
1652
+ function compare_iterator(left, right) {
1653
+ while (true) {
1654
+ const left_next = left.next();
1655
+ const right_next = right.next();
1656
+ if (left_next.done !== right_next.done)
1657
+ return false;
1658
+ if (left_next.done)
1659
+ break;
1660
+ if (!$mol_compare_deep(left_next.value, right_next.value))
1661
+ return false;
1662
+ }
1663
+ return true;
1664
+ }
1665
+ function compare_set(left, right) {
1666
+ if (left.size !== right.size)
1667
+ return false;
1668
+ return compare_iterator(left.values(), right.values());
1669
+ }
1670
+ function compare_map(left, right) {
1671
+ if (left.size !== right.size)
1672
+ return false;
1673
+ return compare_iterator(left.keys(), right.keys())
1674
+ && compare_iterator(left.values(), right.values());
1675
+ }
1676
+ function compare_pojo(left, right) {
1677
+ const left_keys = Object.getOwnPropertyNames(left);
1678
+ const right_keys = Object.getOwnPropertyNames(right);
1679
+ if (!compare_array(left_keys, right_keys))
1680
+ return false;
1681
+ for (let key of left_keys) {
1682
+ if (!$mol_compare_deep(left[key], right[key]))
1683
+ return false;
1684
+ }
1685
+ const left_syms = Object.getOwnPropertySymbols(left);
1686
+ const right_syms = Object.getOwnPropertySymbols(right);
1687
+ if (!compare_array(left_syms, right_syms))
1688
+ return false;
1689
+ for (let key of left_syms) {
1690
+ if (!$mol_compare_deep(left[key], right[key]))
1691
+ return false;
1692
+ }
1693
+ return true;
1694
+ }
1695
+ function compare_primitive(left, right) {
1696
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
1742
1697
  }
1743
- $.$mol_maybe = $mol_maybe;
1744
- })($ || ($ = {}));
1745
-
1746
- ;
1747
- "use strict";
1748
- var $;
1749
- (function ($) {
1750
- $.$mol_dom = $mol_dom_context;
1751
- })($ || ($ = {}));
1752
-
1753
- ;
1754
- "use strict";
1755
- var $;
1756
- (function ($) {
1757
- let $mol_keyboard_code;
1758
- (function ($mol_keyboard_code) {
1759
- $mol_keyboard_code[$mol_keyboard_code["backspace"] = 8] = "backspace";
1760
- $mol_keyboard_code[$mol_keyboard_code["tab"] = 9] = "tab";
1761
- $mol_keyboard_code[$mol_keyboard_code["enter"] = 13] = "enter";
1762
- $mol_keyboard_code[$mol_keyboard_code["shift"] = 16] = "shift";
1763
- $mol_keyboard_code[$mol_keyboard_code["ctrl"] = 17] = "ctrl";
1764
- $mol_keyboard_code[$mol_keyboard_code["alt"] = 18] = "alt";
1765
- $mol_keyboard_code[$mol_keyboard_code["pause"] = 19] = "pause";
1766
- $mol_keyboard_code[$mol_keyboard_code["capsLock"] = 20] = "capsLock";
1767
- $mol_keyboard_code[$mol_keyboard_code["escape"] = 27] = "escape";
1768
- $mol_keyboard_code[$mol_keyboard_code["space"] = 32] = "space";
1769
- $mol_keyboard_code[$mol_keyboard_code["pageUp"] = 33] = "pageUp";
1770
- $mol_keyboard_code[$mol_keyboard_code["pageDown"] = 34] = "pageDown";
1771
- $mol_keyboard_code[$mol_keyboard_code["end"] = 35] = "end";
1772
- $mol_keyboard_code[$mol_keyboard_code["home"] = 36] = "home";
1773
- $mol_keyboard_code[$mol_keyboard_code["left"] = 37] = "left";
1774
- $mol_keyboard_code[$mol_keyboard_code["up"] = 38] = "up";
1775
- $mol_keyboard_code[$mol_keyboard_code["right"] = 39] = "right";
1776
- $mol_keyboard_code[$mol_keyboard_code["down"] = 40] = "down";
1777
- $mol_keyboard_code[$mol_keyboard_code["insert"] = 45] = "insert";
1778
- $mol_keyboard_code[$mol_keyboard_code["delete"] = 46] = "delete";
1779
- $mol_keyboard_code[$mol_keyboard_code["key0"] = 48] = "key0";
1780
- $mol_keyboard_code[$mol_keyboard_code["key1"] = 49] = "key1";
1781
- $mol_keyboard_code[$mol_keyboard_code["key2"] = 50] = "key2";
1782
- $mol_keyboard_code[$mol_keyboard_code["key3"] = 51] = "key3";
1783
- $mol_keyboard_code[$mol_keyboard_code["key4"] = 52] = "key4";
1784
- $mol_keyboard_code[$mol_keyboard_code["key5"] = 53] = "key5";
1785
- $mol_keyboard_code[$mol_keyboard_code["key6"] = 54] = "key6";
1786
- $mol_keyboard_code[$mol_keyboard_code["key7"] = 55] = "key7";
1787
- $mol_keyboard_code[$mol_keyboard_code["key8"] = 56] = "key8";
1788
- $mol_keyboard_code[$mol_keyboard_code["key9"] = 57] = "key9";
1789
- $mol_keyboard_code[$mol_keyboard_code["A"] = 65] = "A";
1790
- $mol_keyboard_code[$mol_keyboard_code["B"] = 66] = "B";
1791
- $mol_keyboard_code[$mol_keyboard_code["C"] = 67] = "C";
1792
- $mol_keyboard_code[$mol_keyboard_code["D"] = 68] = "D";
1793
- $mol_keyboard_code[$mol_keyboard_code["E"] = 69] = "E";
1794
- $mol_keyboard_code[$mol_keyboard_code["F"] = 70] = "F";
1795
- $mol_keyboard_code[$mol_keyboard_code["G"] = 71] = "G";
1796
- $mol_keyboard_code[$mol_keyboard_code["H"] = 72] = "H";
1797
- $mol_keyboard_code[$mol_keyboard_code["I"] = 73] = "I";
1798
- $mol_keyboard_code[$mol_keyboard_code["J"] = 74] = "J";
1799
- $mol_keyboard_code[$mol_keyboard_code["K"] = 75] = "K";
1800
- $mol_keyboard_code[$mol_keyboard_code["L"] = 76] = "L";
1801
- $mol_keyboard_code[$mol_keyboard_code["M"] = 77] = "M";
1802
- $mol_keyboard_code[$mol_keyboard_code["N"] = 78] = "N";
1803
- $mol_keyboard_code[$mol_keyboard_code["O"] = 79] = "O";
1804
- $mol_keyboard_code[$mol_keyboard_code["P"] = 80] = "P";
1805
- $mol_keyboard_code[$mol_keyboard_code["Q"] = 81] = "Q";
1806
- $mol_keyboard_code[$mol_keyboard_code["R"] = 82] = "R";
1807
- $mol_keyboard_code[$mol_keyboard_code["S"] = 83] = "S";
1808
- $mol_keyboard_code[$mol_keyboard_code["T"] = 84] = "T";
1809
- $mol_keyboard_code[$mol_keyboard_code["U"] = 85] = "U";
1810
- $mol_keyboard_code[$mol_keyboard_code["V"] = 86] = "V";
1811
- $mol_keyboard_code[$mol_keyboard_code["W"] = 87] = "W";
1812
- $mol_keyboard_code[$mol_keyboard_code["X"] = 88] = "X";
1813
- $mol_keyboard_code[$mol_keyboard_code["Y"] = 89] = "Y";
1814
- $mol_keyboard_code[$mol_keyboard_code["Z"] = 90] = "Z";
1815
- $mol_keyboard_code[$mol_keyboard_code["metaLeft"] = 91] = "metaLeft";
1816
- $mol_keyboard_code[$mol_keyboard_code["metaRight"] = 92] = "metaRight";
1817
- $mol_keyboard_code[$mol_keyboard_code["select"] = 93] = "select";
1818
- $mol_keyboard_code[$mol_keyboard_code["numpad0"] = 96] = "numpad0";
1819
- $mol_keyboard_code[$mol_keyboard_code["numpad1"] = 97] = "numpad1";
1820
- $mol_keyboard_code[$mol_keyboard_code["numpad2"] = 98] = "numpad2";
1821
- $mol_keyboard_code[$mol_keyboard_code["numpad3"] = 99] = "numpad3";
1822
- $mol_keyboard_code[$mol_keyboard_code["numpad4"] = 100] = "numpad4";
1823
- $mol_keyboard_code[$mol_keyboard_code["numpad5"] = 101] = "numpad5";
1824
- $mol_keyboard_code[$mol_keyboard_code["numpad6"] = 102] = "numpad6";
1825
- $mol_keyboard_code[$mol_keyboard_code["numpad7"] = 103] = "numpad7";
1826
- $mol_keyboard_code[$mol_keyboard_code["numpad8"] = 104] = "numpad8";
1827
- $mol_keyboard_code[$mol_keyboard_code["numpad9"] = 105] = "numpad9";
1828
- $mol_keyboard_code[$mol_keyboard_code["multiply"] = 106] = "multiply";
1829
- $mol_keyboard_code[$mol_keyboard_code["add"] = 107] = "add";
1830
- $mol_keyboard_code[$mol_keyboard_code["subtract"] = 109] = "subtract";
1831
- $mol_keyboard_code[$mol_keyboard_code["decimal"] = 110] = "decimal";
1832
- $mol_keyboard_code[$mol_keyboard_code["divide"] = 111] = "divide";
1833
- $mol_keyboard_code[$mol_keyboard_code["F1"] = 112] = "F1";
1834
- $mol_keyboard_code[$mol_keyboard_code["F2"] = 113] = "F2";
1835
- $mol_keyboard_code[$mol_keyboard_code["F3"] = 114] = "F3";
1836
- $mol_keyboard_code[$mol_keyboard_code["F4"] = 115] = "F4";
1837
- $mol_keyboard_code[$mol_keyboard_code["F5"] = 116] = "F5";
1838
- $mol_keyboard_code[$mol_keyboard_code["F6"] = 117] = "F6";
1839
- $mol_keyboard_code[$mol_keyboard_code["F7"] = 118] = "F7";
1840
- $mol_keyboard_code[$mol_keyboard_code["F8"] = 119] = "F8";
1841
- $mol_keyboard_code[$mol_keyboard_code["F9"] = 120] = "F9";
1842
- $mol_keyboard_code[$mol_keyboard_code["F10"] = 121] = "F10";
1843
- $mol_keyboard_code[$mol_keyboard_code["F11"] = 122] = "F11";
1844
- $mol_keyboard_code[$mol_keyboard_code["F12"] = 123] = "F12";
1845
- $mol_keyboard_code[$mol_keyboard_code["numLock"] = 144] = "numLock";
1846
- $mol_keyboard_code[$mol_keyboard_code["scrollLock"] = 145] = "scrollLock";
1847
- $mol_keyboard_code[$mol_keyboard_code["semicolon"] = 186] = "semicolon";
1848
- $mol_keyboard_code[$mol_keyboard_code["equals"] = 187] = "equals";
1849
- $mol_keyboard_code[$mol_keyboard_code["comma"] = 188] = "comma";
1850
- $mol_keyboard_code[$mol_keyboard_code["dash"] = 189] = "dash";
1851
- $mol_keyboard_code[$mol_keyboard_code["period"] = 190] = "period";
1852
- $mol_keyboard_code[$mol_keyboard_code["forwardSlash"] = 191] = "forwardSlash";
1853
- $mol_keyboard_code[$mol_keyboard_code["graveAccent"] = 192] = "graveAccent";
1854
- $mol_keyboard_code[$mol_keyboard_code["bracketOpen"] = 219] = "bracketOpen";
1855
- $mol_keyboard_code[$mol_keyboard_code["slashBack"] = 220] = "slashBack";
1856
- $mol_keyboard_code[$mol_keyboard_code["slashBackLeft"] = 226] = "slashBackLeft";
1857
- $mol_keyboard_code[$mol_keyboard_code["bracketClose"] = 221] = "bracketClose";
1858
- $mol_keyboard_code[$mol_keyboard_code["quoteSingle"] = 222] = "quoteSingle";
1859
- })($mol_keyboard_code = $.$mol_keyboard_code || ($.$mol_keyboard_code = {}));
1860
1698
  })($ || ($ = {}));
1861
1699
 
1862
1700
  ;
1863
1701
  "use strict";
1864
1702
  var $;
1865
1703
  (function ($) {
1866
- if ($mol_dom_context.document) {
1867
- function focus(event) {
1868
- const target = event.target;
1869
- if (target?.shadowRoot)
1870
- watch(target.shadowRoot);
1871
- $mol_view_selection.focused($mol_maybe(target), 'notify');
1872
- }
1873
- function watch(root) {
1874
- root.removeEventListener('focus', focus, true);
1875
- root.addEventListener('focus', focus, true);
1876
- }
1877
- watch($mol_dom_context.document);
1878
- $mol_dom.document.addEventListener('keydown', event => {
1879
- if (!event.altKey)
1880
- return;
1881
- const self = $mol_view_selection.focused()[0];
1882
- if (!self)
1883
- return;
1884
- switch (event.keyCode) {
1885
- case $mol_keyboard_code.down:
1886
- var vert = 1, hor = 0;
1887
- break;
1888
- case $mol_keyboard_code.up:
1889
- var vert = -1, hor = 0;
1890
- break;
1891
- case $mol_keyboard_code.left:
1892
- var hor = -1, vert = 0;
1893
- break;
1894
- case $mol_keyboard_code.right:
1895
- var hor = 1, vert = 0;
1896
- break;
1897
- default: return;
1898
- }
1899
- event.preventDefault();
1900
- const self_rect = self.getBoundingClientRect();
1901
- const center_hor = (self_rect.left + self_rect.right) / 2;
1902
- const center_vert = (self_rect.top + self_rect.bottom) / 2;
1903
- const all = [...$mol_dom.document.querySelectorAll(':where( [role="button"], [role="checkbox"], input, button, a ):not([disabled])')]
1904
- .map(el => {
1905
- const rect = el.getBoundingClientRect();
1906
- const dist = (Math.max(0, center_hor - rect.right) + Math.max(0, rect.left - center_hor)) * vert * vert
1907
- + (Math.max(0, center_vert - rect.bottom) + Math.max(0, rect.top - center_vert)) * hor * hor;
1908
- return [el, rect, dist];
1909
- })
1910
- .filter(([el, rect]) => {
1911
- if (el === self)
1912
- return false;
1913
- if (vert > 0 && rect.top < self_rect.bottom)
1914
- return false;
1915
- if (vert < 0 && rect.bottom > self_rect.top)
1916
- return false;
1917
- if (hor > 0 && rect.left < self_rect.right)
1918
- return false;
1919
- if (hor < 0 && rect.right > self_rect.left)
1920
- return false;
1921
- return true;
1922
- })
1923
- .sort(([, one, dist1], [, two, dist2]) => {
1924
- return (dist1 - dist2) || ((one.top - two.top) * vert + (one.left - two.left) * hor);
1925
- });
1926
- const target = all[0]?.[0];
1927
- target?.focus();
1704
+ function $mol_log3_area_lazy(event) {
1705
+ const self = this.$;
1706
+ const stack = self.$mol_log3_stack;
1707
+ const deep = stack.length;
1708
+ let logged = false;
1709
+ stack.push(() => {
1710
+ logged = true;
1711
+ self.$mol_log3_area.call(self, event);
1928
1712
  });
1713
+ return () => {
1714
+ if (logged)
1715
+ self.console.groupEnd();
1716
+ if (stack.length > deep)
1717
+ stack.length = deep;
1718
+ };
1929
1719
  }
1720
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1721
+ $.$mol_log3_stack = [];
1930
1722
  })($ || ($ = {}));
1931
1723
 
1724
+ ;
1725
+ "use strict";
1726
+
1932
1727
  ;
1933
1728
  "use strict";
1934
1729
  var $;
1935
1730
  (function ($) {
1936
- class $mol_wrapper extends $mol_object2 {
1937
- static wrap;
1938
- static run(task) {
1939
- return this.func(task)();
1731
+ function $mol_log3_web_make(level, color) {
1732
+ return function $mol_log3_logger(event) {
1733
+ const pending = this.$mol_log3_stack.pop();
1734
+ if (pending)
1735
+ pending();
1736
+ let tpl = '%c';
1737
+ const chunks = Object.entries(event);
1738
+ for (let i = 0; i < chunks.length; ++i) {
1739
+ tpl += (typeof chunks[i][1] === 'string') ? '%s: %s\n' : '%s: %o\n';
1740
+ }
1741
+ const style = `color:${color};font-weight:bolder`;
1742
+ this.console[level](tpl.trim(), style, ...[].concat(...chunks));
1743
+ const self = this;
1744
+ return () => self.console.groupEnd();
1745
+ };
1746
+ }
1747
+ $.$mol_log3_web_make = $mol_log3_web_make;
1748
+ $.$mol_log3_come = $mol_log3_web_make('info', 'royalblue');
1749
+ $.$mol_log3_done = $mol_log3_web_make('info', 'forestgreen');
1750
+ $.$mol_log3_fail = $mol_log3_web_make('error', 'orangered');
1751
+ $.$mol_log3_warn = $mol_log3_web_make('warn', 'goldenrod');
1752
+ $.$mol_log3_rise = $mol_log3_web_make('log', 'magenta');
1753
+ $.$mol_log3_area = $mol_log3_web_make('group', 'cyan');
1754
+ })($ || ($ = {}));
1755
+
1756
+ ;
1757
+ "use strict";
1758
+ var $;
1759
+ (function ($) {
1760
+ class $mol_wire_task extends $mol_wire_fiber {
1761
+ static getter(task) {
1762
+ return function $mol_wire_task_get(host, args) {
1763
+ const sub = $mol_wire_auto();
1764
+ const existen = sub?.track_next();
1765
+ let cause = '';
1766
+ reuse: if (existen) {
1767
+ if (!existen.temp)
1768
+ break reuse;
1769
+ if (existen.task !== task) {
1770
+ cause = 'task';
1771
+ break reuse;
1772
+ }
1773
+ if (existen.host !== host) {
1774
+ cause = 'host';
1775
+ break reuse;
1776
+ }
1777
+ if (!$mol_compare_deep(existen.args, args)) {
1778
+ cause = 'args';
1779
+ break reuse;
1780
+ }
1781
+ return existen;
1782
+ }
1783
+ const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
1784
+ const next = new $mol_wire_task(key, task, host, args);
1785
+ if (existen?.temp) {
1786
+ $$.$mol_log3_warn({
1787
+ place: '$mol_wire_task',
1788
+ message: `Different ${cause} on restart`,
1789
+ sub,
1790
+ prev: existen,
1791
+ next,
1792
+ hint: 'Maybe required additional memoization',
1793
+ });
1794
+ }
1795
+ return next;
1796
+ };
1940
1797
  }
1941
- static func(func) {
1942
- return this.wrap(func);
1798
+ get temp() {
1799
+ return true;
1943
1800
  }
1944
- static get class() {
1945
- return (Class) => {
1946
- const construct = (target, args) => new Class(...args);
1947
- const handler = {
1948
- construct: this.func(construct)
1949
- };
1950
- handler[Symbol.toStringTag] = Class.name + '#';
1951
- return new Proxy(Class, handler);
1952
- };
1801
+ complete() {
1802
+ if ($mol_promise_like(this.cache))
1803
+ return;
1804
+ this.destructor();
1953
1805
  }
1954
- static get method() {
1955
- return (obj, name, descr) => {
1956
- descr.value = this.func(descr.value);
1957
- return descr;
1958
- };
1806
+ put(next) {
1807
+ const prev = this.cache;
1808
+ this.cache = next;
1809
+ if ($mol_promise_like(next)) {
1810
+ this.cursor = $mol_wire_cursor.fresh;
1811
+ if (next !== prev)
1812
+ this.emit();
1813
+ if ($mol_owning_catch(this, next)) {
1814
+ try {
1815
+ next[Symbol.toStringTag] = this[Symbol.toStringTag];
1816
+ }
1817
+ catch {
1818
+ Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
1819
+ }
1820
+ }
1821
+ return next;
1822
+ }
1823
+ this.cursor = $mol_wire_cursor.final;
1824
+ if (this.sub_empty)
1825
+ this.destructor();
1826
+ else if (next !== prev)
1827
+ this.emit();
1828
+ return next;
1959
1829
  }
1960
- static get field() {
1961
- return (obj, name, descr) => {
1962
- descr.get = descr.set = this.func(descr.get);
1963
- return descr;
1964
- };
1830
+ }
1831
+ $.$mol_wire_task = $mol_wire_task;
1832
+ })($ || ($ = {}));
1833
+
1834
+ ;
1835
+ "use strict";
1836
+ var $;
1837
+ (function ($) {
1838
+ function $mol_wire_method(host, field, descr) {
1839
+ if (!descr)
1840
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
1841
+ const orig = descr?.value ?? host[field];
1842
+ const sup = Reflect.getPrototypeOf(host);
1843
+ if (typeof sup[field] === 'function') {
1844
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
1965
1845
  }
1846
+ const temp = $mol_wire_task.getter(orig);
1847
+ const value = function (...args) {
1848
+ const fiber = temp(this ?? null, args);
1849
+ return fiber.sync();
1850
+ };
1851
+ Object.defineProperty(value, 'name', { value: orig.name + ' ' });
1852
+ Object.assign(value, { orig });
1853
+ const descr2 = { ...descr, value };
1854
+ Reflect.defineProperty(host, field, descr2);
1855
+ return descr2;
1856
+ }
1857
+ $.$mol_wire_method = $mol_wire_method;
1858
+ })($ || ($ = {}));
1859
+
1860
+ ;
1861
+ "use strict";
1862
+
1863
+ ;
1864
+ "use strict";
1865
+
1866
+ ;
1867
+ "use strict";
1868
+ var $;
1869
+ (function ($) {
1870
+ const catched = new WeakMap();
1871
+ function $mol_fail_catch(error) {
1872
+ if (typeof error !== 'object')
1873
+ return false;
1874
+ if ($mol_promise_like(error))
1875
+ $mol_fail_hidden(error);
1876
+ if (catched.get(error))
1877
+ return false;
1878
+ catched.set(error, true);
1879
+ return true;
1966
1880
  }
1967
- $.$mol_wrapper = $mol_wrapper;
1881
+ $.$mol_fail_catch = $mol_fail_catch;
1968
1882
  })($ || ($ = {}));
1969
1883
 
1970
1884
  ;
1971
1885
  "use strict";
1972
1886
  var $;
1973
1887
  (function ($) {
1974
- class $mol_memo extends $mol_wrapper {
1975
- static wrap(task) {
1976
- const store = new WeakMap();
1977
- const fun = function (next) {
1978
- if (next === undefined && store.has(this))
1979
- return store.get(this);
1980
- const val = task.call(this, next) ?? next;
1981
- store.set(this, val);
1982
- return val;
1983
- };
1984
- Reflect.defineProperty(fun, 'name', { value: task.name + ' ' });
1985
- return fun;
1986
- }
1888
+ let error;
1889
+ let result;
1890
+ let handler;
1891
+ function $mol_try(handler2) {
1892
+ handler = handler2;
1893
+ error = undefined;
1894
+ result = undefined;
1895
+ window.dispatchEvent(new Event('$mol_try'));
1896
+ const error2 = error;
1897
+ const result2 = result;
1898
+ error = undefined;
1899
+ result = undefined;
1900
+ return error2 || result2;
1987
1901
  }
1988
- $.$mol_memo = $mol_memo;
1902
+ $.$mol_try = $mol_try;
1903
+ self.addEventListener('$mol_try', (event) => {
1904
+ result = handler();
1905
+ }, true);
1906
+ self.addEventListener('error', (event) => {
1907
+ error = event.error;
1908
+ }, true);
1989
1909
  })($ || ($ = {}));
1990
1910
 
1991
1911
  ;
1992
1912
  "use strict";
1993
1913
  var $;
1994
1914
  (function ($) {
1995
- function $mol_dom_qname(name) {
1996
- return name.replace(/\W/g, '').replace(/^(?=\d+)/, '_');
1915
+ function $mol_fail_log(error) {
1916
+ if ($mol_promise_like(error))
1917
+ return false;
1918
+ if (!$mol_fail_catch(error))
1919
+ return false;
1920
+ $mol_try(() => { $mol_fail_hidden(error); });
1921
+ return true;
1997
1922
  }
1998
- $.$mol_dom_qname = $mol_dom_qname;
1923
+ $.$mol_fail_log = $mol_fail_log;
1999
1924
  })($ || ($ = {}));
2000
1925
 
2001
1926
  ;
2002
1927
  "use strict";
2003
1928
  var $;
2004
1929
  (function ($) {
2005
- function $mol_wire_probe(task, def) {
2006
- const warm = $mol_wire_fiber.warm;
2007
- try {
2008
- $mol_wire_fiber.warm = false;
2009
- const res = task();
2010
- if (res === undefined)
2011
- return def;
2012
- return res;
1930
+ class $mol_wire_atom extends $mol_wire_fiber {
1931
+ static solo(host, task) {
1932
+ const field = task.name + '()';
1933
+ const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1934
+ if (existen)
1935
+ return existen;
1936
+ const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1937
+ const key = prefix + ('.' + task.name + '<>');
1938
+ const fiber = new $mol_wire_atom(key, task, host, []);
1939
+ (host ?? task)[field] = fiber;
1940
+ return fiber;
2013
1941
  }
2014
- finally {
2015
- $mol_wire_fiber.warm = warm;
1942
+ static plex(host, task, key) {
1943
+ const field = task.name + '()';
1944
+ let dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1945
+ const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1946
+ const key_str = $mol_key(key);
1947
+ if (dict) {
1948
+ const existen = dict.get(key_str);
1949
+ if (existen)
1950
+ return existen;
1951
+ }
1952
+ else {
1953
+ dict = (host ?? task)[field] = new Map();
1954
+ }
1955
+ const id = prefix + ('.' + task.name) + ('<' + key_str.replace(/^"|"$/g, "'") + '>');
1956
+ const fiber = new $mol_wire_atom(id, task, host, [key]);
1957
+ dict.set(key_str, fiber);
1958
+ return fiber;
1959
+ }
1960
+ static watching = new Set();
1961
+ static watcher = null;
1962
+ static watch() {
1963
+ $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
1964
+ for (const atom of $mol_wire_atom.watching) {
1965
+ if (atom.cursor === $mol_wire_cursor.final) {
1966
+ $mol_wire_atom.watching.delete(atom);
1967
+ }
1968
+ else {
1969
+ atom.cursor = $mol_wire_cursor.stale;
1970
+ atom.fresh();
1971
+ }
1972
+ }
1973
+ }
1974
+ watch() {
1975
+ if (!$mol_wire_atom.watcher) {
1976
+ $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
1977
+ }
1978
+ $mol_wire_atom.watching.add(this);
1979
+ }
1980
+ resync(args) {
1981
+ return this.put(this.task.call(this.host, ...args));
1982
+ }
1983
+ once() {
1984
+ return this.sync();
1985
+ }
1986
+ channel() {
1987
+ return Object.assign((next) => {
1988
+ if (next !== undefined)
1989
+ return this.resync([...this.args, next]);
1990
+ if (!$mol_wire_fiber.warm)
1991
+ return this.result();
1992
+ if ($mol_wire_auto()?.temp) {
1993
+ return this.once();
1994
+ }
1995
+ else {
1996
+ return this.sync();
1997
+ }
1998
+ }, { atom: this });
1999
+ }
2000
+ destructor() {
2001
+ super.destructor();
2002
+ if (this.pub_from === 0) {
2003
+ ;
2004
+ (this.host ?? this.task)[this.field()] = null;
2005
+ }
2006
+ else {
2007
+ ;
2008
+ (this.host ?? this.task)[this.field()].delete($mol_key(this.args[0]));
2009
+ }
2010
+ }
2011
+ put(next) {
2012
+ const prev = this.cache;
2013
+ update: if (next !== prev) {
2014
+ try {
2015
+ if ($mol_compare_deep(prev, next))
2016
+ break update;
2017
+ }
2018
+ catch (error) {
2019
+ $mol_fail_log(error);
2020
+ }
2021
+ if ($mol_owning_check(this, prev)) {
2022
+ prev.destructor();
2023
+ }
2024
+ if ($mol_owning_catch(this, next)) {
2025
+ try {
2026
+ next[Symbol.toStringTag] = this[Symbol.toStringTag];
2027
+ }
2028
+ catch {
2029
+ Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
2030
+ }
2031
+ }
2032
+ if (!this.sub_empty)
2033
+ this.emit();
2034
+ }
2035
+ this.cache = next;
2036
+ this.cursor = $mol_wire_cursor.fresh;
2037
+ if ($mol_promise_like(next))
2038
+ return next;
2039
+ this.complete_pubs();
2040
+ return next;
2016
2041
  }
2017
2042
  }
2018
- $.$mol_wire_probe = $mol_wire_probe;
2043
+ __decorate([
2044
+ $mol_wire_method
2045
+ ], $mol_wire_atom.prototype, "resync", null);
2046
+ __decorate([
2047
+ $mol_wire_method
2048
+ ], $mol_wire_atom.prototype, "once", null);
2049
+ $.$mol_wire_atom = $mol_wire_atom;
2019
2050
  })($ || ($ = {}));
2020
2051
 
2021
2052
  ;
2022
2053
  "use strict";
2023
2054
  var $;
2024
2055
  (function ($) {
2025
- function $mol_wire_watch() {
2026
- const atom = $mol_wire_auto();
2027
- if (atom instanceof $mol_wire_atom) {
2028
- atom.watch();
2029
- }
2030
- else {
2031
- $mol_fail(new Error('Atom is required for watching'));
2056
+ function $mol_wire_solo(host, field, descr) {
2057
+ if (!descr)
2058
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
2059
+ const orig = descr?.value ?? host[field];
2060
+ const sup = Reflect.getPrototypeOf(host);
2061
+ if (typeof sup[field] === 'function') {
2062
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
2032
2063
  }
2064
+ const descr2 = {
2065
+ ...descr,
2066
+ value: function (...args) {
2067
+ let atom = $mol_wire_atom.solo(this, orig);
2068
+ if ((args.length === 0) || (args[0] === undefined)) {
2069
+ if (!$mol_wire_fiber.warm)
2070
+ return atom.result();
2071
+ if ($mol_wire_auto()?.temp) {
2072
+ return atom.once();
2073
+ }
2074
+ else {
2075
+ return atom.sync();
2076
+ }
2077
+ }
2078
+ return atom.resync(args);
2079
+ }
2080
+ };
2081
+ Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
2082
+ Reflect.defineProperty(descr2.value, 'length', { value: orig.length });
2083
+ Object.assign(descr2.value, { orig });
2084
+ Reflect.defineProperty(host, field, descr2);
2085
+ return descr2;
2033
2086
  }
2034
- $.$mol_wire_watch = $mol_wire_watch;
2087
+ $.$mol_wire_solo = $mol_wire_solo;
2035
2088
  })($ || ($ = {}));
2036
2089
 
2037
2090
  ;
2038
2091
  "use strict";
2039
2092
  var $;
2040
2093
  (function ($) {
2041
- function $mol_const(value) {
2042
- const getter = (() => value);
2043
- getter['()'] = value;
2044
- getter[Symbol.toStringTag] = value;
2045
- getter[$mol_dev_format_head] = () => $mol_dev_format_span({}, '()=> ', $mol_dev_format_auto(value));
2046
- return getter;
2094
+ function $mol_wire_plex(host, field, descr) {
2095
+ if (!descr)
2096
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
2097
+ const orig = descr?.value ?? host[field];
2098
+ const sup = Reflect.getPrototypeOf(host);
2099
+ if (typeof sup[field] === 'function') {
2100
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
2101
+ }
2102
+ const descr2 = {
2103
+ ...descr,
2104
+ value: function (...args) {
2105
+ let atom = $mol_wire_atom.plex(this, orig, args[0]);
2106
+ if ((args.length === 1) || (args[1] === undefined)) {
2107
+ if (!$mol_wire_fiber.warm)
2108
+ return atom.result();
2109
+ if ($mol_wire_auto()?.temp) {
2110
+ return atom.once();
2111
+ }
2112
+ else {
2113
+ return atom.sync();
2114
+ }
2115
+ }
2116
+ return atom.resync(args);
2117
+ }
2118
+ };
2119
+ Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
2120
+ Reflect.defineProperty(descr2.value, 'length', { value: orig.length });
2121
+ Object.assign(descr2.value, { orig });
2122
+ Reflect.defineProperty(host, field, descr2);
2123
+ return descr2;
2047
2124
  }
2048
- $.$mol_const = $mol_const;
2125
+ $.$mol_wire_plex = $mol_wire_plex;
2049
2126
  })($ || ($ = {}));
2050
2127
 
2051
2128
  ;
2052
2129
  "use strict";
2053
2130
  var $;
2054
2131
  (function ($) {
2055
- function $mol_wire_solid() {
2056
- let current = $mol_wire_auto();
2057
- if (current.temp)
2058
- current = current.host;
2059
- if (current.reap !== nothing) {
2060
- current?.sub_on(sub, sub.data.length);
2061
- }
2062
- current.reap = nothing;
2063
- }
2064
- $.$mol_wire_solid = $mol_wire_solid;
2065
- const nothing = () => { };
2066
- const sub = new $mol_wire_pub_sub;
2132
+ $.$mol_mem = $mol_wire_solo;
2133
+ $.$mol_mem_key = $mol_wire_plex;
2067
2134
  })($ || ($ = {}));
2068
2135
 
2069
2136
  ;
2070
2137
  "use strict";
2071
2138
  var $;
2072
2139
  (function ($) {
2073
- function $mol_dom_render_attributes(el, attrs) {
2074
- for (let name in attrs) {
2075
- let val = attrs[name];
2076
- if (val === undefined) {
2077
- continue;
2078
- }
2079
- else if (val === null || val === false) {
2080
- if (!el.hasAttribute(name))
2081
- continue;
2082
- el.removeAttribute(name);
2083
- }
2084
- else {
2085
- const str = String(val);
2086
- if (el.getAttribute(name) === str)
2087
- continue;
2088
- el.setAttribute(name, str);
2089
- }
2140
+ class $mol_window extends $mol_object {
2141
+ static size() {
2142
+ this.resizes();
2143
+ return {
2144
+ width: self.innerWidth,
2145
+ height: self.innerHeight,
2146
+ };
2090
2147
  }
2148
+ static resizes(next) { return next; }
2091
2149
  }
2092
- $.$mol_dom_render_attributes = $mol_dom_render_attributes;
2150
+ __decorate([
2151
+ $mol_mem
2152
+ ], $mol_window, "size", null);
2153
+ __decorate([
2154
+ $mol_mem
2155
+ ], $mol_window, "resizes", null);
2156
+ $.$mol_window = $mol_window;
2157
+ self.addEventListener('resize', event => $mol_window.resizes(event));
2093
2158
  })($ || ($ = {}));
2094
2159
 
2095
2160
  ;
2096
2161
  "use strict";
2097
2162
  var $;
2098
2163
  (function ($) {
2099
- function $mol_dom_render_events(el, events, passive = false) {
2100
- for (let name in events) {
2101
- el.addEventListener(name, events[name], { passive });
2102
- }
2164
+ function $mol_guard_defined(value) {
2165
+ return value !== null && value !== undefined;
2103
2166
  }
2104
- $.$mol_dom_render_events = $mol_dom_render_events;
2167
+ $.$mol_guard_defined = $mol_guard_defined;
2105
2168
  })($ || ($ = {}));
2106
2169
 
2107
2170
  ;
2108
2171
  "use strict";
2109
2172
  var $;
2110
2173
  (function ($) {
2111
- function $mol_dom_render_styles(el, styles) {
2112
- for (let name in styles) {
2113
- let val = styles[name];
2114
- const style = el.style;
2115
- const kebab = (name) => name.replace(/[A-Z]/g, letter => '-' + letter.toLowerCase());
2116
- if (typeof val === 'number') {
2117
- style.setProperty(kebab(name), `${val}px`);
2174
+ class $mol_view_selection extends $mol_object {
2175
+ static focused(next, notify) {
2176
+ const parents = [];
2177
+ let element = next?.[0] ?? $mol_dom_context.document.activeElement;
2178
+ while (element?.shadowRoot) {
2179
+ element = element.shadowRoot.activeElement;
2118
2180
  }
2119
- else {
2120
- style.setProperty(kebab(name), val);
2181
+ while (element) {
2182
+ parents.push(element);
2183
+ const parent = element.parentNode;
2184
+ if (parent instanceof ShadowRoot)
2185
+ element = parent.host;
2186
+ else
2187
+ element = parent;
2121
2188
  }
2189
+ if (!next || notify)
2190
+ return parents;
2191
+ new $mol_after_tick(() => {
2192
+ const element = this.focused()[0];
2193
+ if (element)
2194
+ element.focus();
2195
+ else
2196
+ $mol_dom_context.blur();
2197
+ });
2198
+ return parents;
2122
2199
  }
2123
2200
  }
2124
- $.$mol_dom_render_styles = $mol_dom_render_styles;
2201
+ __decorate([
2202
+ $mol_mem
2203
+ ], $mol_view_selection, "focused", null);
2204
+ $.$mol_view_selection = $mol_view_selection;
2125
2205
  })($ || ($ = {}));
2126
2206
 
2127
2207
  ;
2128
2208
  "use strict";
2129
2209
  var $;
2130
2210
  (function ($) {
2131
- function $mol_dom_render_children(el, childNodes) {
2132
- const node_set = new Set(childNodes);
2133
- let nextNode = el.firstChild;
2134
- for (let view of childNodes) {
2135
- if (view == null)
2136
- continue;
2137
- if (view instanceof $mol_dom_context.Node) {
2138
- while (true) {
2139
- if (!nextNode) {
2140
- el.appendChild(view);
2141
- break;
2142
- }
2143
- if (nextNode == view) {
2144
- nextNode = nextNode.nextSibling;
2145
- break;
2146
- }
2147
- else {
2148
- if (node_set.has(nextNode)) {
2149
- el.insertBefore(view, nextNode);
2150
- break;
2151
- }
2152
- else {
2153
- const nn = nextNode.nextSibling;
2154
- el.removeChild(nextNode);
2155
- nextNode = nn;
2156
- }
2157
- }
2158
- }
2159
- }
2160
- else {
2161
- if (nextNode && nextNode.nodeName === '#text') {
2162
- const str = String(view);
2163
- if (nextNode.nodeValue !== str)
2164
- nextNode.nodeValue = str;
2165
- nextNode = nextNode.nextSibling;
2166
- }
2167
- else {
2168
- const textNode = $mol_dom_context.document.createTextNode(String(view));
2169
- el.insertBefore(textNode, nextNode);
2170
- }
2171
- }
2172
- }
2173
- while (nextNode) {
2174
- const currNode = nextNode;
2175
- nextNode = currNode.nextSibling;
2176
- el.removeChild(currNode);
2177
- }
2211
+ function $mol_maybe(value) {
2212
+ return (value == null) ? [] : [value];
2178
2213
  }
2179
- $.$mol_dom_render_children = $mol_dom_render_children;
2214
+ $.$mol_maybe = $mol_maybe;
2180
2215
  })($ || ($ = {}));
2181
2216
 
2182
2217
  ;
2183
2218
  "use strict";
2184
2219
  var $;
2185
2220
  (function ($) {
2186
- function $mol_dom_render_fields(el, fields) {
2187
- for (let key in fields) {
2188
- const val = fields[key];
2189
- if (val === undefined)
2190
- continue;
2191
- if (val === el[key])
2192
- continue;
2193
- el[key] = val;
2194
- }
2195
- }
2196
- $.$mol_dom_render_fields = $mol_dom_render_fields;
2221
+ let $mol_keyboard_code;
2222
+ (function ($mol_keyboard_code) {
2223
+ $mol_keyboard_code[$mol_keyboard_code["backspace"] = 8] = "backspace";
2224
+ $mol_keyboard_code[$mol_keyboard_code["tab"] = 9] = "tab";
2225
+ $mol_keyboard_code[$mol_keyboard_code["enter"] = 13] = "enter";
2226
+ $mol_keyboard_code[$mol_keyboard_code["shift"] = 16] = "shift";
2227
+ $mol_keyboard_code[$mol_keyboard_code["ctrl"] = 17] = "ctrl";
2228
+ $mol_keyboard_code[$mol_keyboard_code["alt"] = 18] = "alt";
2229
+ $mol_keyboard_code[$mol_keyboard_code["pause"] = 19] = "pause";
2230
+ $mol_keyboard_code[$mol_keyboard_code["capsLock"] = 20] = "capsLock";
2231
+ $mol_keyboard_code[$mol_keyboard_code["escape"] = 27] = "escape";
2232
+ $mol_keyboard_code[$mol_keyboard_code["space"] = 32] = "space";
2233
+ $mol_keyboard_code[$mol_keyboard_code["pageUp"] = 33] = "pageUp";
2234
+ $mol_keyboard_code[$mol_keyboard_code["pageDown"] = 34] = "pageDown";
2235
+ $mol_keyboard_code[$mol_keyboard_code["end"] = 35] = "end";
2236
+ $mol_keyboard_code[$mol_keyboard_code["home"] = 36] = "home";
2237
+ $mol_keyboard_code[$mol_keyboard_code["left"] = 37] = "left";
2238
+ $mol_keyboard_code[$mol_keyboard_code["up"] = 38] = "up";
2239
+ $mol_keyboard_code[$mol_keyboard_code["right"] = 39] = "right";
2240
+ $mol_keyboard_code[$mol_keyboard_code["down"] = 40] = "down";
2241
+ $mol_keyboard_code[$mol_keyboard_code["insert"] = 45] = "insert";
2242
+ $mol_keyboard_code[$mol_keyboard_code["delete"] = 46] = "delete";
2243
+ $mol_keyboard_code[$mol_keyboard_code["key0"] = 48] = "key0";
2244
+ $mol_keyboard_code[$mol_keyboard_code["key1"] = 49] = "key1";
2245
+ $mol_keyboard_code[$mol_keyboard_code["key2"] = 50] = "key2";
2246
+ $mol_keyboard_code[$mol_keyboard_code["key3"] = 51] = "key3";
2247
+ $mol_keyboard_code[$mol_keyboard_code["key4"] = 52] = "key4";
2248
+ $mol_keyboard_code[$mol_keyboard_code["key5"] = 53] = "key5";
2249
+ $mol_keyboard_code[$mol_keyboard_code["key6"] = 54] = "key6";
2250
+ $mol_keyboard_code[$mol_keyboard_code["key7"] = 55] = "key7";
2251
+ $mol_keyboard_code[$mol_keyboard_code["key8"] = 56] = "key8";
2252
+ $mol_keyboard_code[$mol_keyboard_code["key9"] = 57] = "key9";
2253
+ $mol_keyboard_code[$mol_keyboard_code["A"] = 65] = "A";
2254
+ $mol_keyboard_code[$mol_keyboard_code["B"] = 66] = "B";
2255
+ $mol_keyboard_code[$mol_keyboard_code["C"] = 67] = "C";
2256
+ $mol_keyboard_code[$mol_keyboard_code["D"] = 68] = "D";
2257
+ $mol_keyboard_code[$mol_keyboard_code["E"] = 69] = "E";
2258
+ $mol_keyboard_code[$mol_keyboard_code["F"] = 70] = "F";
2259
+ $mol_keyboard_code[$mol_keyboard_code["G"] = 71] = "G";
2260
+ $mol_keyboard_code[$mol_keyboard_code["H"] = 72] = "H";
2261
+ $mol_keyboard_code[$mol_keyboard_code["I"] = 73] = "I";
2262
+ $mol_keyboard_code[$mol_keyboard_code["J"] = 74] = "J";
2263
+ $mol_keyboard_code[$mol_keyboard_code["K"] = 75] = "K";
2264
+ $mol_keyboard_code[$mol_keyboard_code["L"] = 76] = "L";
2265
+ $mol_keyboard_code[$mol_keyboard_code["M"] = 77] = "M";
2266
+ $mol_keyboard_code[$mol_keyboard_code["N"] = 78] = "N";
2267
+ $mol_keyboard_code[$mol_keyboard_code["O"] = 79] = "O";
2268
+ $mol_keyboard_code[$mol_keyboard_code["P"] = 80] = "P";
2269
+ $mol_keyboard_code[$mol_keyboard_code["Q"] = 81] = "Q";
2270
+ $mol_keyboard_code[$mol_keyboard_code["R"] = 82] = "R";
2271
+ $mol_keyboard_code[$mol_keyboard_code["S"] = 83] = "S";
2272
+ $mol_keyboard_code[$mol_keyboard_code["T"] = 84] = "T";
2273
+ $mol_keyboard_code[$mol_keyboard_code["U"] = 85] = "U";
2274
+ $mol_keyboard_code[$mol_keyboard_code["V"] = 86] = "V";
2275
+ $mol_keyboard_code[$mol_keyboard_code["W"] = 87] = "W";
2276
+ $mol_keyboard_code[$mol_keyboard_code["X"] = 88] = "X";
2277
+ $mol_keyboard_code[$mol_keyboard_code["Y"] = 89] = "Y";
2278
+ $mol_keyboard_code[$mol_keyboard_code["Z"] = 90] = "Z";
2279
+ $mol_keyboard_code[$mol_keyboard_code["metaLeft"] = 91] = "metaLeft";
2280
+ $mol_keyboard_code[$mol_keyboard_code["metaRight"] = 92] = "metaRight";
2281
+ $mol_keyboard_code[$mol_keyboard_code["select"] = 93] = "select";
2282
+ $mol_keyboard_code[$mol_keyboard_code["numpad0"] = 96] = "numpad0";
2283
+ $mol_keyboard_code[$mol_keyboard_code["numpad1"] = 97] = "numpad1";
2284
+ $mol_keyboard_code[$mol_keyboard_code["numpad2"] = 98] = "numpad2";
2285
+ $mol_keyboard_code[$mol_keyboard_code["numpad3"] = 99] = "numpad3";
2286
+ $mol_keyboard_code[$mol_keyboard_code["numpad4"] = 100] = "numpad4";
2287
+ $mol_keyboard_code[$mol_keyboard_code["numpad5"] = 101] = "numpad5";
2288
+ $mol_keyboard_code[$mol_keyboard_code["numpad6"] = 102] = "numpad6";
2289
+ $mol_keyboard_code[$mol_keyboard_code["numpad7"] = 103] = "numpad7";
2290
+ $mol_keyboard_code[$mol_keyboard_code["numpad8"] = 104] = "numpad8";
2291
+ $mol_keyboard_code[$mol_keyboard_code["numpad9"] = 105] = "numpad9";
2292
+ $mol_keyboard_code[$mol_keyboard_code["multiply"] = 106] = "multiply";
2293
+ $mol_keyboard_code[$mol_keyboard_code["add"] = 107] = "add";
2294
+ $mol_keyboard_code[$mol_keyboard_code["subtract"] = 109] = "subtract";
2295
+ $mol_keyboard_code[$mol_keyboard_code["decimal"] = 110] = "decimal";
2296
+ $mol_keyboard_code[$mol_keyboard_code["divide"] = 111] = "divide";
2297
+ $mol_keyboard_code[$mol_keyboard_code["F1"] = 112] = "F1";
2298
+ $mol_keyboard_code[$mol_keyboard_code["F2"] = 113] = "F2";
2299
+ $mol_keyboard_code[$mol_keyboard_code["F3"] = 114] = "F3";
2300
+ $mol_keyboard_code[$mol_keyboard_code["F4"] = 115] = "F4";
2301
+ $mol_keyboard_code[$mol_keyboard_code["F5"] = 116] = "F5";
2302
+ $mol_keyboard_code[$mol_keyboard_code["F6"] = 117] = "F6";
2303
+ $mol_keyboard_code[$mol_keyboard_code["F7"] = 118] = "F7";
2304
+ $mol_keyboard_code[$mol_keyboard_code["F8"] = 119] = "F8";
2305
+ $mol_keyboard_code[$mol_keyboard_code["F9"] = 120] = "F9";
2306
+ $mol_keyboard_code[$mol_keyboard_code["F10"] = 121] = "F10";
2307
+ $mol_keyboard_code[$mol_keyboard_code["F11"] = 122] = "F11";
2308
+ $mol_keyboard_code[$mol_keyboard_code["F12"] = 123] = "F12";
2309
+ $mol_keyboard_code[$mol_keyboard_code["numLock"] = 144] = "numLock";
2310
+ $mol_keyboard_code[$mol_keyboard_code["scrollLock"] = 145] = "scrollLock";
2311
+ $mol_keyboard_code[$mol_keyboard_code["semicolon"] = 186] = "semicolon";
2312
+ $mol_keyboard_code[$mol_keyboard_code["equals"] = 187] = "equals";
2313
+ $mol_keyboard_code[$mol_keyboard_code["comma"] = 188] = "comma";
2314
+ $mol_keyboard_code[$mol_keyboard_code["dash"] = 189] = "dash";
2315
+ $mol_keyboard_code[$mol_keyboard_code["period"] = 190] = "period";
2316
+ $mol_keyboard_code[$mol_keyboard_code["forwardSlash"] = 191] = "forwardSlash";
2317
+ $mol_keyboard_code[$mol_keyboard_code["graveAccent"] = 192] = "graveAccent";
2318
+ $mol_keyboard_code[$mol_keyboard_code["bracketOpen"] = 219] = "bracketOpen";
2319
+ $mol_keyboard_code[$mol_keyboard_code["slashBack"] = 220] = "slashBack";
2320
+ $mol_keyboard_code[$mol_keyboard_code["slashBackLeft"] = 226] = "slashBackLeft";
2321
+ $mol_keyboard_code[$mol_keyboard_code["bracketClose"] = 221] = "bracketClose";
2322
+ $mol_keyboard_code[$mol_keyboard_code["quoteSingle"] = 222] = "quoteSingle";
2323
+ })($mol_keyboard_code = $.$mol_keyboard_code || ($.$mol_keyboard_code = {}));
2197
2324
  })($ || ($ = {}));
2198
2325
 
2199
2326
  ;
2200
2327
  "use strict";
2201
2328
  var $;
2202
2329
  (function ($) {
2203
- function $mol_wire_async(obj) {
2204
- let fiber;
2205
- const temp = $mol_wire_task.getter(obj);
2206
- return new Proxy(obj, {
2207
- get(obj, field) {
2208
- const val = obj[field];
2209
- if (typeof val !== 'function')
2210
- return val;
2211
- let fiber;
2212
- const temp = $mol_wire_task.getter(val);
2213
- return function $mol_wire_async(...args) {
2214
- fiber?.destructor();
2215
- fiber = temp(obj, args);
2216
- return fiber.async();
2217
- };
2218
- },
2219
- apply(obj, self, args) {
2220
- fiber?.destructor();
2221
- fiber = temp(self, args);
2222
- return fiber.async();
2223
- },
2330
+ if ($mol_dom_context.document) {
2331
+ function focus(event) {
2332
+ const target = event.target;
2333
+ if (target?.shadowRoot)
2334
+ watch(target.shadowRoot);
2335
+ $mol_view_selection.focused($mol_maybe(target), 'notify');
2336
+ }
2337
+ function watch(root) {
2338
+ root.removeEventListener('focus', focus, true);
2339
+ root.addEventListener('focus', focus, true);
2340
+ }
2341
+ watch($mol_dom_context.document);
2342
+ $mol_dom.document.addEventListener('keydown', event => {
2343
+ if (!event.altKey)
2344
+ return;
2345
+ const self = $mol_view_selection.focused()[0];
2346
+ if (!self)
2347
+ return;
2348
+ switch (event.keyCode) {
2349
+ case $mol_keyboard_code.down:
2350
+ var vert = 1, hor = 0;
2351
+ break;
2352
+ case $mol_keyboard_code.up:
2353
+ var vert = -1, hor = 0;
2354
+ break;
2355
+ case $mol_keyboard_code.left:
2356
+ var hor = -1, vert = 0;
2357
+ break;
2358
+ case $mol_keyboard_code.right:
2359
+ var hor = 1, vert = 0;
2360
+ break;
2361
+ default: return;
2362
+ }
2363
+ event.preventDefault();
2364
+ const self_rect = self.getBoundingClientRect();
2365
+ const center_hor = (self_rect.left + self_rect.right) / 2;
2366
+ const center_vert = (self_rect.top + self_rect.bottom) / 2;
2367
+ const all = [...$mol_dom.document.querySelectorAll(':where( [role="button"], [role="checkbox"], input, button, a ):not([disabled])')]
2368
+ .map(el => {
2369
+ const rect = el.getBoundingClientRect();
2370
+ const dist = (Math.max(0, center_hor - rect.right) + Math.max(0, rect.left - center_hor)) * vert * vert
2371
+ + (Math.max(0, center_vert - rect.bottom) + Math.max(0, rect.top - center_vert)) * hor * hor;
2372
+ return [el, rect, dist];
2373
+ })
2374
+ .filter(([el, rect]) => {
2375
+ if (el === self)
2376
+ return false;
2377
+ if (vert > 0 && rect.top < self_rect.bottom)
2378
+ return false;
2379
+ if (vert < 0 && rect.bottom > self_rect.top)
2380
+ return false;
2381
+ if (hor > 0 && rect.left < self_rect.right)
2382
+ return false;
2383
+ if (hor < 0 && rect.right > self_rect.left)
2384
+ return false;
2385
+ return true;
2386
+ })
2387
+ .sort(([, one, dist1], [, two, dist2]) => {
2388
+ return (dist1 - dist2) || ((one.top - two.top) * vert + (one.left - two.left) * hor);
2389
+ });
2390
+ const target = all[0]?.[0];
2391
+ target?.focus();
2224
2392
  });
2225
2393
  }
2226
- $.$mol_wire_async = $mol_wire_async;
2227
2394
  })($ || ($ = {}));
2228
2395
 
2229
2396
  ;
2230
2397
  "use strict";
2231
2398
  var $;
2232
2399
  (function ($) {
2233
- class $mol_after_timeout extends $mol_object2 {
2234
- delay;
2235
- task;
2236
- id;
2237
- constructor(delay, task) {
2238
- super();
2239
- this.delay = delay;
2240
- this.task = task;
2241
- this.id = setTimeout(task, delay);
2400
+ class $mol_wrapper extends $mol_object2 {
2401
+ static wrap;
2402
+ static run(task) {
2403
+ return this.func(task)();
2242
2404
  }
2243
- destructor() {
2244
- clearTimeout(this.id);
2405
+ static func(func) {
2406
+ return this.wrap(func);
2407
+ }
2408
+ static get class() {
2409
+ return (Class) => {
2410
+ const construct = (target, args) => new Class(...args);
2411
+ const handler = {
2412
+ construct: this.func(construct)
2413
+ };
2414
+ handler[Symbol.toStringTag] = Class.name + '#';
2415
+ return new Proxy(Class, handler);
2416
+ };
2417
+ }
2418
+ static get method() {
2419
+ return (obj, name, descr) => {
2420
+ descr.value = this.func(descr.value);
2421
+ return descr;
2422
+ };
2423
+ }
2424
+ static get field() {
2425
+ return (obj, name, descr) => {
2426
+ descr.get = descr.set = this.func(descr.get);
2427
+ return descr;
2428
+ };
2245
2429
  }
2246
2430
  }
2247
- $.$mol_after_timeout = $mol_after_timeout;
2431
+ $.$mol_wrapper = $mol_wrapper;
2248
2432
  })($ || ($ = {}));
2249
2433
 
2250
- ;
2251
- "use strict";
2252
-
2253
2434
  ;
2254
2435
  "use strict";
2255
2436
  var $;
2256
2437
  (function ($) {
2257
- function $mol_style_attach(id, text) {
2258
- const doc = $mol_dom_context.document;
2259
- if (!doc)
2260
- return null;
2261
- const elid = `$mol_style_attach:${id}`;
2262
- let el = doc.getElementById(elid);
2263
- if (!el) {
2264
- el = doc.createElement('style');
2265
- el.id = elid;
2266
- doc.head.appendChild(el);
2438
+ class $mol_memo extends $mol_wrapper {
2439
+ static wrap(task) {
2440
+ const store = new WeakMap();
2441
+ const fun = function (next) {
2442
+ if (next === undefined && store.has(this))
2443
+ return store.get(this);
2444
+ const val = task.call(this, next) ?? next;
2445
+ store.set(this, val);
2446
+ return val;
2447
+ };
2448
+ Reflect.defineProperty(fun, 'name', { value: task.name + ' ' });
2449
+ return fun;
2267
2450
  }
2268
- if (el.innerHTML != text)
2269
- el.innerHTML = text;
2270
- return el;
2271
2451
  }
2272
- $.$mol_style_attach = $mol_style_attach;
2452
+ $.$mol_memo = $mol_memo;
2273
2453
  })($ || ($ = {}));
2274
2454
 
2275
2455
  ;
2276
2456
  "use strict";
2277
2457
  var $;
2278
2458
  (function ($) {
2279
- class $mol_promise extends Promise {
2280
- done;
2281
- fail;
2282
- constructor(executor) {
2283
- let done;
2284
- let fail;
2285
- super((d, f) => {
2286
- done = d;
2287
- fail = f;
2288
- executor?.(d, f);
2289
- });
2290
- this.done = done;
2291
- this.fail = fail;
2292
- }
2459
+ function $mol_dom_qname(name) {
2460
+ return name.replace(/\W/g, '').replace(/^(?=\d+)/, '_');
2293
2461
  }
2294
- $.$mol_promise = $mol_promise;
2462
+ $.$mol_dom_qname = $mol_dom_qname;
2295
2463
  })($ || ($ = {}));
2296
2464
 
2297
2465
  ;
2298
2466
  "use strict";
2299
2467
  var $;
2300
2468
  (function ($) {
2301
- class $mol_promise_blocker extends $mol_promise {
2302
- static [Symbol.toStringTag] = '$mol_promise_blocker';
2469
+ function $mol_wire_probe(task, def) {
2470
+ const warm = $mol_wire_fiber.warm;
2471
+ try {
2472
+ $mol_wire_fiber.warm = false;
2473
+ const res = task();
2474
+ if (res === undefined)
2475
+ return def;
2476
+ return res;
2477
+ }
2478
+ finally {
2479
+ $mol_wire_fiber.warm = warm;
2480
+ }
2303
2481
  }
2304
- $.$mol_promise_blocker = $mol_promise_blocker;
2482
+ $.$mol_wire_probe = $mol_wire_probe;
2305
2483
  })($ || ($ = {}));
2306
2484
 
2307
2485
  ;
2308
2486
  "use strict";
2309
2487
  var $;
2310
2488
  (function ($) {
2311
- class $mol_decor {
2312
- value;
2313
- constructor(value) {
2314
- this.value = value;
2489
+ function $mol_wire_watch() {
2490
+ const atom = $mol_wire_auto();
2491
+ if (atom instanceof $mol_wire_atom) {
2492
+ atom.watch();
2315
2493
  }
2316
- prefix() { return ''; }
2317
- valueOf() { return this.value; }
2318
- postfix() { return ''; }
2319
- toString() {
2320
- return `${this.prefix()}${this.valueOf()}${this.postfix()}`;
2494
+ else {
2495
+ $mol_fail(new Error('Atom is required for watching'));
2321
2496
  }
2322
2497
  }
2323
- $.$mol_decor = $mol_decor;
2498
+ $.$mol_wire_watch = $mol_wire_watch;
2324
2499
  })($ || ($ = {}));
2325
2500
 
2326
2501
  ;
2327
2502
  "use strict";
2328
2503
  var $;
2329
2504
  (function ($) {
2330
- class $mol_style_unit extends $mol_decor {
2331
- literal;
2332
- constructor(value, literal) {
2333
- super(value);
2334
- this.literal = literal;
2335
- }
2336
- postfix() {
2337
- return this.literal;
2338
- }
2339
- static per(value) { return `${value}%`; }
2340
- static px(value) { return `${value}px`; }
2341
- static mm(value) { return `${value}mm`; }
2342
- static cm(value) { return `${value}cm`; }
2343
- static Q(value) { return `${value}Q`; }
2344
- static in(value) { return `${value}in`; }
2345
- static pc(value) { return `${value}pc`; }
2346
- static pt(value) { return `${value}pt`; }
2347
- static cap(value) { return `${value}cap`; }
2348
- static ch(value) { return `${value}ch`; }
2349
- static em(value) { return `${value}em`; }
2350
- static rem(value) { return `${value}rem`; }
2351
- static ex(value) { return `${value}ex`; }
2352
- static ic(value) { return `${value}ic`; }
2353
- static lh(value) { return `${value}lh`; }
2354
- static rlh(value) { return `${value}rlh`; }
2355
- static vh(value) { return `${value}vh`; }
2356
- static vw(value) { return `${value}vw`; }
2357
- static vi(value) { return `${value}vi`; }
2358
- static vb(value) { return `${value}vb`; }
2359
- static vmin(value) { return `${value}vmin`; }
2360
- static vmax(value) { return `${value}vmax`; }
2361
- static deg(value) { return `${value}deg`; }
2362
- static rad(value) { return `${value}rad`; }
2363
- static grad(value) { return `${value}grad`; }
2364
- static turn(value) { return `${value}turn`; }
2365
- static s(value) { return `${value}s`; }
2366
- static ms(value) { return `${value}ms`; }
2505
+ function $mol_const(value) {
2506
+ const getter = (() => value);
2507
+ getter['()'] = value;
2508
+ getter[Symbol.toStringTag] = value;
2509
+ getter[$mol_dev_format_head] = () => $mol_dev_format_span({}, '()=> ', $mol_dev_format_auto(value));
2510
+ return getter;
2367
2511
  }
2368
- $.$mol_style_unit = $mol_style_unit;
2512
+ $.$mol_const = $mol_const;
2369
2513
  })($ || ($ = {}));
2370
2514
 
2371
2515
  ;
2372
2516
  "use strict";
2373
2517
  var $;
2374
2518
  (function ($) {
2375
- const { per } = $mol_style_unit;
2376
- class $mol_style_func extends $mol_decor {
2377
- name;
2378
- constructor(name, value) {
2379
- super(value);
2380
- this.name = name;
2381
- }
2382
- prefix() { return this.name + '('; }
2383
- postfix() { return ')'; }
2384
- static linear_gradient(value) {
2385
- return new $mol_style_func('linear-gradient', value);
2386
- }
2387
- static radial_gradient(value) {
2388
- return new $mol_style_func('radial-gradient', value);
2389
- }
2390
- static calc(value) {
2391
- return new $mol_style_func('calc', value);
2392
- }
2393
- static vary(name, defaultValue) {
2394
- return new $mol_style_func('var', defaultValue ? [name, defaultValue] : name);
2395
- }
2396
- static url(href) {
2397
- return new $mol_style_func('url', JSON.stringify(href));
2398
- }
2399
- static hsla(hue, saturation, lightness, alpha) {
2400
- return new $mol_style_func('hsla', [hue, per(saturation), per(lightness), alpha]);
2401
- }
2402
- static clamp(min, mid, max) {
2403
- return new $mol_style_func('clamp', [min, mid, max]);
2404
- }
2405
- static rgba(red, green, blue, alpha) {
2406
- return new $mol_style_func('rgba', [red, green, blue, alpha]);
2407
- }
2408
- static scale(zoom) {
2409
- return new $mol_style_func('scale', [zoom]);
2410
- }
2411
- static linear(...breakpoints) {
2412
- return new $mol_style_func("linear", breakpoints.map((e) => Array.isArray(e)
2413
- ? String(e[0]) +
2414
- " " +
2415
- (typeof e[1] === "number" ? e[1] + "%" : e[1].toString())
2416
- : String(e)));
2417
- }
2418
- static cubic_bezier(x1, y1, x2, y2) {
2419
- return new $mol_style_func('cubic-bezier', [x1, y1, x2, y2]);
2420
- }
2421
- static steps(value, step_position) {
2422
- return new $mol_style_func('steps', [value, step_position]);
2423
- }
2424
- static blur(value) {
2425
- return new $mol_style_func('blur', value ?? "");
2426
- }
2427
- static brightness(value) {
2428
- return new $mol_style_func('brightness', value ?? "");
2429
- }
2430
- static contrast(value) {
2431
- return new $mol_style_func('contrast', value ?? "");
2432
- }
2433
- static drop_shadow(color, x_offset, y_offset, blur_radius) {
2434
- return new $mol_style_func("drop-shadow", blur_radius
2435
- ? [color, x_offset, y_offset, blur_radius]
2436
- : [color, x_offset, y_offset]);
2437
- }
2438
- static grayscale(value) {
2439
- return new $mol_style_func('grayscale', value ?? "");
2440
- }
2441
- static hue_rotate(value) {
2442
- return new $mol_style_func('hue-rotate', value ?? "");
2443
- }
2444
- static invert(value) {
2445
- return new $mol_style_func('invert', value ?? "");
2446
- }
2447
- static opacity(value) {
2448
- return new $mol_style_func('opacity', value ?? "");
2449
- }
2450
- static sepia(value) {
2451
- return new $mol_style_func('sepia', value ?? "");
2452
- }
2453
- static saturate(value) {
2454
- return new $mol_style_func('saturate', value ?? "");
2519
+ function $mol_wire_solid() {
2520
+ let current = $mol_wire_auto();
2521
+ if (current.temp)
2522
+ current = current.host;
2523
+ if (current.reap !== nothing) {
2524
+ current?.sub_on(sub, sub.data.length);
2455
2525
  }
2526
+ current.reap = nothing;
2456
2527
  }
2457
- $.$mol_style_func = $mol_style_func;
2528
+ $.$mol_wire_solid = $mol_wire_solid;
2529
+ const nothing = () => { };
2530
+ const sub = new $mol_wire_pub_sub;
2458
2531
  })($ || ($ = {}));
2459
2532
 
2460
2533
  ;
2461
2534
  "use strict";
2535
+ var $;
2536
+ (function ($) {
2537
+ function $mol_dom_render_attributes(el, attrs) {
2538
+ for (let name in attrs) {
2539
+ let val = attrs[name];
2540
+ if (val === undefined) {
2541
+ continue;
2542
+ }
2543
+ else if (val === null || val === false) {
2544
+ if (!el.hasAttribute(name))
2545
+ continue;
2546
+ el.removeAttribute(name);
2547
+ }
2548
+ else {
2549
+ const str = String(val);
2550
+ if (el.getAttribute(name) === str)
2551
+ continue;
2552
+ el.setAttribute(name, str);
2553
+ }
2554
+ }
2555
+ }
2556
+ $.$mol_dom_render_attributes = $mol_dom_render_attributes;
2557
+ })($ || ($ = {}));
2462
2558
 
2463
2559
  ;
2464
2560
  "use strict";
2561
+ var $;
2562
+ (function ($) {
2563
+ function $mol_dom_render_events(el, events, passive = false) {
2564
+ for (let name in events) {
2565
+ el.addEventListener(name, events[name], { passive });
2566
+ }
2567
+ }
2568
+ $.$mol_dom_render_events = $mol_dom_render_events;
2569
+ })($ || ($ = {}));
2465
2570
 
2466
2571
  ;
2467
2572
  "use strict";
2468
2573
  var $;
2469
2574
  (function ($) {
2470
- function $mol_style_prop(prefix, keys) {
2471
- const record = keys.reduce((rec, key) => {
2472
- rec[key] = $mol_style_func.vary(`--${prefix}_${key}`);
2473
- return rec;
2474
- }, {});
2475
- return record;
2575
+ function $mol_dom_render_styles(el, styles) {
2576
+ for (let name in styles) {
2577
+ let val = styles[name];
2578
+ const style = el.style;
2579
+ const kebab = (name) => name.replace(/[A-Z]/g, letter => '-' + letter.toLowerCase());
2580
+ if (typeof val === 'number') {
2581
+ style.setProperty(kebab(name), `${val}px`);
2582
+ }
2583
+ else {
2584
+ style.setProperty(kebab(name), val);
2585
+ }
2586
+ }
2476
2587
  }
2477
- $.$mol_style_prop = $mol_style_prop;
2588
+ $.$mol_dom_render_styles = $mol_dom_render_styles;
2478
2589
  })($ || ($ = {}));
2479
2590
 
2480
2591
  ;
2481
2592
  "use strict";
2482
2593
  var $;
2483
2594
  (function ($) {
2484
- $.$mol_theme = $mol_style_prop('mol_theme', [
2485
- 'back',
2486
- 'hover',
2487
- 'card',
2488
- 'current',
2489
- 'special',
2490
- 'text',
2491
- 'control',
2492
- 'shade',
2493
- 'line',
2494
- 'focus',
2495
- 'field',
2496
- 'image',
2497
- 'spirit',
2498
- ]);
2595
+ function $mol_dom_render_fields(el, fields) {
2596
+ for (let key in fields) {
2597
+ const val = fields[key];
2598
+ if (val === undefined)
2599
+ continue;
2600
+ if (val === el[key])
2601
+ continue;
2602
+ el[key] = val;
2603
+ }
2604
+ }
2605
+ $.$mol_dom_render_fields = $mol_dom_render_fields;
2499
2606
  })($ || ($ = {}));
2500
2607
 
2501
2608
  ;
2502
2609
  "use strict";
2503
2610
  var $;
2504
2611
  (function ($) {
2505
- $mol_style_attach("mol/theme/theme.css", ":root {\n\t--mol_theme_hue: 240deg;\n\t--mol_theme_hue_spread: 90deg;\n\tcolor-scheme: dark light;\n}\n\n:where([mol_theme]) {\n\tcolor: var(--mol_theme_text);\n\tfill: var(--mol_theme_text);\n\tbackground-color: var(--mol_theme_back);\n}\n\t\n:root, [mol_theme=\"$mol_theme_dark\"], :where([mol_theme=\"$mol_theme_dark\"]) [mol_theme] {\n\n\t--mol_theme_luma: -1;\n\t--mol_theme_image: invert(1) hue-rotate( 180deg );\n\t--mol_theme_spirit: hsl( 0deg, 0%, 0%, .75 );\n\n\t--mol_theme_back: hsl( var(--mol_theme_hue), 20%, 10% );\n\t--mol_theme_card: hsl( var(--mol_theme_hue), 50%, 20%, .25 );\n\t--mol_theme_field: hsl( var(--mol_theme_hue), 50%, 8%, .25 );\n\t--mol_theme_hover: hsl( var(--mol_theme_hue), 0%, 50%, .1 );\n\t\n\t--mol_theme_text: hsl( var(--mol_theme_hue), 0%, 80% );\n\t--mol_theme_shade: hsl( var(--mol_theme_hue), 0%, 60%, 1 );\n\t--mol_theme_line: hsl( var(--mol_theme_hue), 0%, 50%, .25 );\n\t--mol_theme_focus: hsl( calc( var(--mol_theme_hue) + 180deg ), 100%, 65% );\n\t\n\t--mol_theme_control: hsl( var(--mol_theme_hue), 60%, 65% );\n\t--mol_theme_current: hsl( calc( var(--mol_theme_hue) - var(--mol_theme_hue_spread) ), 60%, 65% );\n\t--mol_theme_special: hsl( calc( var(--mol_theme_hue) + var(--mol_theme_hue_spread) ), 60%, 65% );\n\n} @supports( color: oklch( 0% 0 0deg ) ) {\n:root, [mol_theme=\"$mol_theme_dark\"], :where([mol_theme=\"$mol_theme_dark\"]) [mol_theme] {\n\t\n\t--mol_theme_back: oklch( 20% .03 var(--mol_theme_hue) );\n\t--mol_theme_card: oklch( 30% .05 var(--mol_theme_hue) / .25 );\n\t--mol_theme_field: oklch( 15% 0 var(--mol_theme_hue) / .25 );\n\t--mol_theme_hover: oklch( 70% 0 var(--mol_theme_hue) / .1 );\n\t\n\t--mol_theme_text: oklch( 80% 0 var(--mol_theme_hue) );\n\t--mol_theme_shade: oklch( 60% 0 var(--mol_theme_hue) );\n\t--mol_theme_line: oklch( 60% 0 var(--mol_theme_hue) / .25 );\n\t--mol_theme_focus: oklch( 80% .2 calc( var(--mol_theme_hue) + 180deg ) );\n\t\n\t--mol_theme_control: oklch( 70% .1 var(--mol_theme_hue) );\n\t--mol_theme_current: oklch( 70% .2 calc( var(--mol_theme_hue) - var(--mol_theme_hue_spread) ) );\n\t--mol_theme_special: oklch( 70% .2 calc( var(--mol_theme_hue) + var(--mol_theme_hue_spread) ) );\n\n} }\n\n[mol_theme=\"$mol_theme_light\"], :where([mol_theme=\"$mol_theme_light\"]) [mol_theme] {\n\t\n\t--mol_theme_luma: 1;\n\t--mol_theme_image: none;\n\t--mol_theme_spirit: hsl( 0deg, 0%, 100%, .75 );\n\t\n\t--mol_theme_back: hsl( var(--mol_theme_hue), 20%, 92% );\n\t--mol_theme_card: hsl( var(--mol_theme_hue), 50%, 100%, .5 );\n\t--mol_theme_field: hsl( var(--mol_theme_hue), 50%, 100%, .75 );\n\t--mol_theme_hover: hsl( var(--mol_theme_hue), 0%, 50%, .1 );\n\t\n\t--mol_theme_text: hsl( var(--mol_theme_hue), 0%, 0% );\n\t--mol_theme_shade: hsl( var(--mol_theme_hue), 0%, 40%, 1 );\n\t--mol_theme_line: hsl( var(--mol_theme_hue), 0%, 50%, .25 );\n\t--mol_theme_focus: hsl( calc( var(--mol_theme_hue) + 180deg ), 100%, 40% );\n\t\n\t--mol_theme_control: hsl( var(--mol_theme_hue), 80%, 30% );\n\t--mol_theme_current: hsl( calc( var(--mol_theme_hue) - var(--mol_theme_hue_spread) ), 80%, 30% );\n\t--mol_theme_special: hsl( calc( var(--mol_theme_hue) + var(--mol_theme_hue_spread) ), 80%, 30% );\n\n} @supports( color: oklch( 0% 0 0deg ) ) {\n[mol_theme=\"$mol_theme_light\"], :where([mol_theme=\"$mol_theme_light\"]) [mol_theme] {\n\t--mol_theme_back: oklch( 92% .01 var(--mol_theme_hue) );\n\t--mol_theme_card: oklch( 99% .01 var(--mol_theme_hue) / .5 );\n\t--mol_theme_field: oklch( 100% 0 var(--mol_theme_hue) / .5 );\n\t--mol_theme_hover: oklch( 70% 0 var(--mol_theme_hue) / .1 );\n\t\n\t--mol_theme_text: oklch( 20% 0 var(--mol_theme_hue) );\n\t--mol_theme_shade: oklch( 60% 0 var(--mol_theme_hue) );\n\t--mol_theme_line: oklch( 50% 0 var(--mol_theme_hue) / .25 );\n\t--mol_theme_focus: oklch( 60% .2 calc( var(--mol_theme_hue) + 180deg ) );\n\t\n\t--mol_theme_control: oklch( 40% .15 var(--mol_theme_hue) );\n\t--mol_theme_current: oklch( 50% .2 calc( var(--mol_theme_hue) - var(--mol_theme_hue_spread) ) );\n\t--mol_theme_special: oklch( 50% .2 calc( var(--mol_theme_hue) + var(--mol_theme_hue_spread) ) );\n\n} }\n\n:where( :root, [mol_theme=\"$mol_theme_dark\"] ) [mol_theme=\"$mol_theme_base\"] {\n\t--mol_theme_back: oklch( 25% .075 var(--mol_theme_hue) );\n\t--mol_theme_card: oklch( 35% .1 var(--mol_theme_hue) / .25 );\n}\n:where( [mol_theme=\"$mol_theme_light\"] ) [mol_theme=\"$mol_theme_base\"] {\n\t--mol_theme_back: oklch( 85% .075 var(--mol_theme_hue) );\n\t--mol_theme_card: oklch( 98% .03 var(--mol_theme_hue) / .25 );\n}\n\n:where( :root, [mol_theme=\"$mol_theme_dark\"] ) [mol_theme=\"$mol_theme_current\"] {\n\t--mol_theme_back: oklch( 25% .05 calc( var(--mol_theme_hue) - var(--mol_theme_hue_spread) ) );\n\t--mol_theme_card: oklch( 35% .1 calc( var(--mol_theme_hue) - var(--mol_theme_hue_spread) ) / .25 );\n}\n:where( [mol_theme=\"$mol_theme_light\"] ) [mol_theme=\"$mol_theme_current\"] {\n\t--mol_theme_back: oklch( 85% .05 calc( var(--mol_theme_hue) - var(--mol_theme_hue_spread) ) );\n\t--mol_theme_card: oklch( 98% .03 calc( var(--mol_theme_hue) - var(--mol_theme_hue_spread) ) / .25 );\n}\n\n:where( :root, [mol_theme=\"$mol_theme_dark\"] ) [mol_theme=\"$mol_theme_special\"] {\n\t--mol_theme_back: oklch( 25% .05 calc( var(--mol_theme_hue) + var(--mol_theme_hue_spread) ) );\n\t--mol_theme_card: oklch( 35% .1 calc( var(--mol_theme_hue) + var(--mol_theme_hue_spread) ) / .25 );\n}\n:where( [mol_theme=\"$mol_theme_light\"] ) [mol_theme=\"$mol_theme_special\"] {\n\t--mol_theme_back: oklch( 85% .05 calc( var(--mol_theme_hue) + var(--mol_theme_hue_spread) ) );\n\t--mol_theme_card: oklch( 98% .03 calc( var(--mol_theme_hue) + var(--mol_theme_hue_spread) ) / .25 );\n}\n\n:where( :root, [mol_theme=\"$mol_theme_dark\"] ) [mol_theme=\"$mol_theme_accent\"] {\n\t--mol_theme_back: oklch( 35% .1 calc( var(--mol_theme_hue) + 180deg ) );\n\t--mol_theme_card: oklch( 45% .15 calc( var(--mol_theme_hue) + 180deg ) / .25 );\n}\n:where( [mol_theme=\"$mol_theme_light\"] ) [mol_theme=\"$mol_theme_accent\"] {\n\t--mol_theme_back: oklch( 83% .1 calc( var(--mol_theme_hue) + 180deg ) );\n\t--mol_theme_card: oklch( 98% .03 calc( var(--mol_theme_hue) + 180deg ) / .25 );\n}\n\n");
2612
+ function $mol_wire_async(obj) {
2613
+ let fiber;
2614
+ const temp = $mol_wire_task.getter(obj);
2615
+ return new Proxy(obj, {
2616
+ get(obj, field) {
2617
+ const val = obj[field];
2618
+ if (typeof val !== 'function')
2619
+ return val;
2620
+ let fiber;
2621
+ const temp = $mol_wire_task.getter(val);
2622
+ return function $mol_wire_async(...args) {
2623
+ fiber?.destructor();
2624
+ fiber = temp(obj, args);
2625
+ return fiber.async();
2626
+ };
2627
+ },
2628
+ apply(obj, self, args) {
2629
+ fiber?.destructor();
2630
+ fiber = temp(self, args);
2631
+ return fiber.async();
2632
+ },
2633
+ });
2634
+ }
2635
+ $.$mol_wire_async = $mol_wire_async;
2506
2636
  })($ || ($ = {}));
2507
2637
 
2508
2638
  ;
2509
2639
  "use strict";
2510
2640
  var $;
2511
2641
  (function ($) {
2512
- $.$mol_gap = $mol_style_prop('mol_gap', [
2513
- 'block',
2514
- 'text',
2515
- 'round',
2516
- 'space',
2517
- 'blur',
2518
- ]);
2642
+ class $mol_after_timeout extends $mol_object2 {
2643
+ delay;
2644
+ task;
2645
+ id;
2646
+ constructor(delay, task) {
2647
+ super();
2648
+ this.delay = delay;
2649
+ this.task = task;
2650
+ this.id = setTimeout(task, delay);
2651
+ }
2652
+ destructor() {
2653
+ clearTimeout(this.id);
2654
+ }
2655
+ }
2656
+ $.$mol_after_timeout = $mol_after_timeout;
2519
2657
  })($ || ($ = {}));
2520
2658
 
2659
+ ;
2660
+ "use strict";
2661
+
2521
2662
  ;
2522
2663
  "use strict";
2523
2664
  var $;
2524
2665
  (function ($) {
2525
- $mol_style_attach("mol/gap/gap.css", ":root {\n\t--mol_gap_block: .75rem;\n\t--mol_gap_text: .5rem .75rem;\n\t--mol_gap_round: .25rem;\n\t--mol_gap_space: .25rem;\n\t--mol_gap_blur: .5rem;\n}\n");
2666
+ $mol_style_attach("mol/view/view/view.css", "[mol_view] {\n\ttransition-property: height, width, min-height, min-width, max-width, max-height, transform;\n\ttransition-duration: .2s;\n\ttransition-timing-function: ease-out;\n\t-webkit-appearance: none;\n\tbox-sizing: border-box;\n\tdisplay: flex;\n\tflex-shrink: 0;\n\tcontain: style;\n\tscrollbar-color: var(--mol_theme_line) transparent;\n\tscrollbar-width: thin;\n}\t\n\n[mol_view]::selection {\n\tbackground: var(--mol_theme_line);\n}\t\n\n[mol_view]::-webkit-scrollbar {\n\twidth: .25rem;\n\theight: .25rem;\n}\n\n[mol_view]::-webkit-scrollbar-corner {\n\tbackground-color: var(--mol_theme_line);\n}\n\n[mol_view]::-webkit-scrollbar-track {\n\tbackground-color: transparent;\n}\n\n[mol_view]::-webkit-scrollbar-thumb {\n\tbackground-color: var(--mol_theme_line);\n\tborder-radius: var(--mol_gap_round);\n}\n\n[mol_view] > * {\n\tword-break: inherit;\n}\n\n[mol_view_root] {\n\tmargin: 0;\n\tpadding: 0;\n\twidth: 100%;\n\theight: 100%;\n\tbox-sizing: border-box;\n\tfont-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;\n\tfont-size: 1rem;\n\tline-height: 1.5rem;\n\tbackground: var(--mol_theme_back);\n\tcolor: var(--mol_theme_text);\n\tcontain: unset; /** Fixes bg ignoring when applied to body on Chrome */\n\ttab-size: 4;\n\toverscroll-behavior: contain; /** Disable navigation gestures **/\n}\n\n@media print {\n\t[mol_view_root] {\n\t\theight: auto;\n\t}\n}\n[mol_view][mol_view_error]:not([mol_view_error=\"Promise\"], [mol_view_error=\"$mol_promise_blocker\"]) {\n\tbackground-image: repeating-linear-gradient(\n\t\t-45deg,\n\t\t#f92323,\n\t\t#f92323 .5rem,\n\t\t#ff3d3d .5rem,\n\t\t#ff3d3d 1.5rem\n\t);\n\tcolor: black;\n\talign-items: center;\n\tjustify-content: center;\n}\n\n@keyframes mol_view_wait {\n\tfrom {\n\t\topacity: .25;\n\t}\n\t20% {\n\t\topacity: .75;\n\t}\n\tto {\n\t\topacity: .25;\n\t}\n}\n\n:where([mol_view][mol_view_error=\"$mol_promise_blocker\"]),\n:where([mol_view][mol_view_error=\"Promise\"]) {\n\tbackground: var(--mol_theme_hover);\n}\n\n[mol_view][mol_view_error=\"Promise\"] {\n\tanimation: mol_view_wait 1s steps(20,end) infinite;\n}\n");
2526
2667
  })($ || ($ = {}));
2527
2668
 
2528
2669
  ;
@@ -2545,32 +2686,58 @@ var $;
2545
2686
  static Root(id) {
2546
2687
  return new this;
2547
2688
  }
2548
- autorun() {
2689
+ static roots() {
2690
+ return [...$mol_dom.document.querySelectorAll('[mol_view_root]:not([mol_view_root=""])')].map((node, index) => {
2691
+ const name = node.getAttribute('mol_view_root');
2692
+ const View = this.$[name];
2693
+ if (!View) {
2694
+ $mol_fail_log(new Error(`Autobind unknown view class`, { cause: { name } }));
2695
+ return null;
2696
+ }
2697
+ const view = View.Root(index);
2698
+ view.dom_node(node);
2699
+ return view;
2700
+ }).filter($mol_guard_defined);
2701
+ }
2702
+ static auto() {
2703
+ const roots = this.roots();
2704
+ if (!roots.length)
2705
+ return;
2706
+ for (const root of roots) {
2707
+ try {
2708
+ root.dom_tree();
2709
+ }
2710
+ catch (error) {
2711
+ $mol_fail_log(error);
2712
+ }
2713
+ }
2549
2714
  try {
2550
- this.dom_tree();
2551
- document.title = this.title();
2715
+ document.title = roots[0].title();
2552
2716
  }
2553
2717
  catch (error) {
2554
2718
  $mol_fail_log(error);
2555
2719
  }
2556
- }
2557
- static autobind() {
2558
- const nodes = $mol_dom_context.document.querySelectorAll('[mol_view_root]:not([mol_view_root=""])');
2559
- for (let i = nodes.length - 1; i >= 0; --i) {
2560
- const name = nodes.item(i).getAttribute('mol_view_root');
2561
- const View = $[name];
2562
- if (!View) {
2563
- console.error(`Can not attach view. Class not found: ${name}`);
2564
- continue;
2565
- }
2566
- const view = View.Root(i);
2567
- view.dom_node(nodes.item(i));
2568
- view.autorun();
2720
+ descr: try {
2721
+ const descr = roots[0].hint();
2722
+ if (!descr)
2723
+ break descr;
2724
+ const head = $mol_dom.document.head;
2725
+ let node = head.querySelector('meta[name="description"]');
2726
+ if (node)
2727
+ node.content = descr;
2728
+ else
2729
+ head.append($mol_jsx("meta", { name: "description", content: descr }));
2730
+ }
2731
+ catch (error) {
2732
+ $mol_fail_log(error);
2569
2733
  }
2570
2734
  }
2571
2735
  title() {
2572
2736
  return this.toString().match(/.*\.(\w+)/)?.[1] ?? this.toString();
2573
2737
  }
2738
+ hint() {
2739
+ return '';
2740
+ }
2574
2741
  focused(next) {
2575
2742
  let node = this.dom_node();
2576
2743
  const value = $mol_view_selection.focused(next === undefined ? undefined : (next ? [node] : []));
@@ -2902,9 +3069,6 @@ var $;
2902
3069
  }
2903
3070
  }
2904
3071
  }
2905
- __decorate([
2906
- $mol_mem
2907
- ], $mol_view.prototype, "autorun", null);
2908
3072
  __decorate([
2909
3073
  $mol_mem
2910
3074
  ], $mol_view.prototype, "title", null);
@@ -2958,7 +3122,10 @@ var $;
2958
3122
  ], $mol_view, "Root", null);
2959
3123
  __decorate([
2960
3124
  $mol_mem
2961
- ], $mol_view, "autobind", null);
3125
+ ], $mol_view, "roots", null);
3126
+ __decorate([
3127
+ $mol_mem
3128
+ ], $mol_view, "auto", null);
2962
3129
  __decorate([
2963
3130
  $mol_memo.method
2964
3131
  ], $mol_view, "view_classes", null);
@@ -2969,14 +3136,7 @@ var $;
2969
3136
  "use strict";
2970
3137
  var $;
2971
3138
  (function ($) {
2972
- $mol_style_attach("mol/view/view/view.css", "[mol_view] {\n\ttransition-property: height, width, min-height, min-width, max-width, max-height, transform;\n\ttransition-duration: .2s;\n\ttransition-timing-function: ease-out;\n\t-webkit-appearance: none;\n\tbox-sizing: border-box;\n\tdisplay: flex;\n\tflex-shrink: 0;\n\tcontain: style;\n\tscrollbar-color: var(--mol_theme_line) transparent;\n\tscrollbar-width: thin;\n}\t\n\n[mol_view]::selection {\n\tbackground: var(--mol_theme_line);\n}\t\n\n[mol_view]::-webkit-scrollbar {\n\twidth: .25rem;\n\theight: .25rem;\n}\n\n[mol_view]::-webkit-scrollbar-corner {\n\tbackground-color: var(--mol_theme_line);\n}\n\n[mol_view]::-webkit-scrollbar-track {\n\tbackground-color: transparent;\n}\n\n[mol_view]::-webkit-scrollbar-thumb {\n\tbackground-color: var(--mol_theme_line);\n\tborder-radius: var(--mol_gap_round);\n}\n\n[mol_view] > * {\n\tword-break: inherit;\n}\n\n[mol_view_root] {\n\tmargin: 0;\n\tpadding: 0;\n\twidth: 100%;\n\theight: 100%;\n\tbox-sizing: border-box;\n\tfont-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;\n\tfont-size: 1rem;\n\tline-height: 1.5rem;\n\tbackground: var(--mol_theme_back);\n\tcolor: var(--mol_theme_text);\n\tcontain: unset; /** Fixes bg ignoring when applied to body on Chrome */\n\ttab-size: 4;\n\toverscroll-behavior: contain; /** Disable navigation gestures **/\n}\n\n@media print {\n\t[mol_view_root] {\n\t\theight: auto;\n\t}\n}\n[mol_view][mol_view_error]:not([mol_view_error=\"Promise\"], [mol_view_error=\"$mol_promise_blocker\"]) {\n\tbackground-image: repeating-linear-gradient(\n\t\t-45deg,\n\t\t#f92323,\n\t\t#f92323 .5rem,\n\t\t#ff3d3d .5rem,\n\t\t#ff3d3d 1.5rem\n\t);\n\tcolor: black;\n\talign-items: center;\n\tjustify-content: center;\n}\n\n@keyframes mol_view_wait {\n\tfrom {\n\t\topacity: .25;\n\t}\n\t20% {\n\t\topacity: .75;\n\t}\n\tto {\n\t\topacity: .25;\n\t}\n}\n\n:where([mol_view][mol_view_error=\"$mol_promise_blocker\"]),\n:where([mol_view][mol_view_error=\"Promise\"]) {\n\tbackground: var(--mol_theme_hover);\n}\n\n[mol_view][mol_view_error=\"Promise\"] {\n\tanimation: mol_view_wait 1s steps(20,end) infinite;\n}\n");
2973
- })($ || ($ = {}));
2974
-
2975
- ;
2976
- "use strict";
2977
- var $;
2978
- (function ($) {
2979
- $mol_dom_context.document?.addEventListener('DOMContentLoaded', () => $mol_view.autobind(), { once: true });
3139
+ $mol_dom_context.document?.addEventListener('DOMContentLoaded', () => $mol_view.auto(), { once: true });
2980
3140
  })($ || ($ = {}));
2981
3141
 
2982
3142
  ;