mol_plot_all 1.2.1690 → 1.2.1692

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.js CHANGED
@@ -275,136 +275,69 @@ var $;
275
275
  $.$mol_style_prop = $mol_style_prop;
276
276
  })($ || ($ = {}));
277
277
 
278
- ;
279
- "use strict";
280
-
281
278
  ;
282
279
  "use strict";
283
280
  var $;
284
281
  (function ($) {
285
- $.$mol_ambient_ref = Symbol('$mol_ambient_ref');
286
- function $mol_ambient(overrides) {
287
- return Object.setPrototypeOf(overrides, this || $);
288
- }
289
- $.$mol_ambient = $mol_ambient;
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
+ ]);
290
297
  })($ || ($ = {}));
291
298
 
292
299
  ;
293
300
  "use strict";
294
301
  var $;
295
302
  (function ($) {
296
- const instances = new WeakSet();
297
- function $mol_delegate(proto, target) {
298
- const proxy = new Proxy(proto, {
299
- get: (_, field) => {
300
- const obj = target();
301
- let val = Reflect.get(obj, field);
302
- if (typeof val === 'function') {
303
- val = val.bind(obj);
304
- }
305
- return val;
306
- },
307
- has: (_, field) => Reflect.has(target(), field),
308
- set: (_, field, value) => Reflect.set(target(), field, value),
309
- getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
310
- ownKeys: () => Reflect.ownKeys(target()),
311
- getPrototypeOf: () => Reflect.getPrototypeOf(target()),
312
- setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
313
- isExtensible: () => Reflect.isExtensible(target()),
314
- preventExtensions: () => Reflect.preventExtensions(target()),
315
- apply: (_, self, args) => Reflect.apply(target(), self, args),
316
- construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
317
- defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
318
- deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
319
- });
320
- instances.add(proxy);
321
- return proxy;
322
- }
323
- $.$mol_delegate = $mol_delegate;
324
- Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
325
- value: (obj) => instances.has(obj),
326
- });
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:root, :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( 50% 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");
327
304
  })($ || ($ = {}));
328
305
 
306
+ ;
307
+ "use strict";
308
+
329
309
  ;
330
310
  "use strict";
331
311
  var $;
332
312
  (function ($) {
333
- $.$mol_owning_map = new WeakMap();
334
- function $mol_owning_allow(having) {
335
- try {
336
- if (!having)
337
- return false;
338
- if (typeof having !== 'object' && typeof having !== 'function')
339
- return false;
340
- if (having instanceof $mol_delegate)
341
- return false;
342
- if (typeof having['destructor'] !== 'function')
343
- return false;
344
- return true;
345
- }
346
- catch {
347
- return false;
348
- }
349
- }
350
- $.$mol_owning_allow = $mol_owning_allow;
351
- function $mol_owning_get(having, Owner) {
352
- if (!$mol_owning_allow(having))
353
- return null;
354
- while (true) {
355
- const owner = $.$mol_owning_map.get(having);
356
- if (!owner)
357
- return owner;
358
- if (!Owner)
359
- return owner;
360
- if (owner instanceof Owner)
361
- return owner;
362
- having = owner;
363
- }
364
- }
365
- $.$mol_owning_get = $mol_owning_get;
366
- function $mol_owning_check(owner, having) {
367
- if (!$mol_owning_allow(having))
368
- return false;
369
- if ($.$mol_owning_map.get(having) !== owner)
370
- return false;
371
- return true;
372
- }
373
- $.$mol_owning_check = $mol_owning_check;
374
- function $mol_owning_catch(owner, having) {
375
- if (!$mol_owning_allow(having))
376
- return false;
377
- if ($.$mol_owning_map.get(having))
378
- return false;
379
- $.$mol_owning_map.set(having, owner);
380
- return true;
381
- }
382
- $.$mol_owning_catch = $mol_owning_catch;
313
+ $.$mol_gap = $mol_style_prop('mol_gap', [
314
+ 'page',
315
+ 'block',
316
+ 'text',
317
+ 'emoji',
318
+ 'round',
319
+ 'space',
320
+ 'blur',
321
+ ]);
383
322
  })($ || ($ = {}));
384
323
 
385
324
  ;
386
325
  "use strict";
387
326
  var $;
388
327
  (function ($) {
389
- function $mol_fail(error) {
390
- throw error;
391
- }
392
- $.$mol_fail = $mol_fail;
328
+ $mol_style_attach("mol/gap/gap.css", ":root {\n\t--mol_gap_page: 3rem;\n\t--mol_gap_block: .75rem;\n\t--mol_gap_text: .5rem .75rem;\n\t--mol_gap_emoji: .5rem;\n\t--mol_gap_round: .25rem;\n\t--mol_gap_space: .25rem;\n\t--mol_gap_blur: .5rem;\n}\n");
393
329
  })($ || ($ = {}));
394
330
 
395
331
  ;
396
332
  "use strict";
397
333
  var $;
398
334
  (function ($) {
399
- function $mol_fail_hidden(error) {
335
+ function $mol_fail(error) {
400
336
  throw error;
401
337
  }
402
- $.$mol_fail_hidden = $mol_fail_hidden;
338
+ $.$mol_fail = $mol_fail;
403
339
  })($ || ($ = {}));
404
340
 
405
- ;
406
- "use strict";
407
-
408
341
  ;
409
342
  "use strict";
410
343
  var $;
@@ -441,2202 +374,1823 @@ var $;
441
374
  "use strict";
442
375
  var $;
443
376
  (function ($) {
444
- $.$mol_key_handle = Symbol.for('$mol_key_handle');
445
- $.$mol_key_store = new WeakMap();
446
- })($ || ($ = {}));
447
-
448
- ;
449
- "use strict";
450
- var $;
451
- (function ($) {
452
- if (!Symbol.dispose)
453
- Symbol.dispose = Symbol('Symbol.dispose');
454
- class $mol_object2 {
455
- static $ = $;
456
- [Symbol.toStringTag];
457
- [$mol_ambient_ref] = null;
458
- get $() {
459
- if (this[$mol_ambient_ref])
460
- return this[$mol_ambient_ref];
461
- const owner = $mol_owning_get(this);
462
- return this[$mol_ambient_ref] = owner?.$ || this.constructor.$ || $mol_object2.$;
463
- }
464
- set $(next) {
465
- if (this[$mol_ambient_ref])
466
- $mol_fail_hidden(new Error('Context already defined'));
467
- this[$mol_ambient_ref] = next;
468
- }
469
- static create(init) {
470
- const obj = new this;
471
- if (init)
472
- init(obj);
473
- return obj;
474
- }
475
- static [Symbol.toPrimitive]() {
476
- return this.toString();
477
- }
478
- static toString() {
479
- return this[Symbol.toStringTag] || this.$.$mol_func_name(this);
480
- }
481
- static toJSON() {
482
- return this.toString();
483
- }
484
- static [$mol_key_handle]() {
485
- return this.toString();
486
- }
487
- destructor() { }
488
- static destructor() { }
489
- [Symbol.dispose]() {
490
- this.destructor();
491
- }
492
- toString() {
493
- return this[Symbol.toStringTag] || this.constructor.name + '<>';
377
+ function $mol_dom_render_children(el, childNodes) {
378
+ const node_set = new Set(childNodes);
379
+ let nextNode = el.firstChild;
380
+ for (let view of childNodes) {
381
+ if (view == null)
382
+ continue;
383
+ if (view instanceof $mol_dom_context.Node) {
384
+ while (true) {
385
+ if (!nextNode) {
386
+ el.appendChild(view);
387
+ break;
388
+ }
389
+ if (nextNode == view) {
390
+ nextNode = nextNode.nextSibling;
391
+ break;
392
+ }
393
+ else {
394
+ if (node_set.has(nextNode)) {
395
+ el.insertBefore(view, nextNode);
396
+ break;
397
+ }
398
+ else {
399
+ const nn = nextNode.nextSibling;
400
+ el.removeChild(nextNode);
401
+ nextNode = nn;
402
+ }
403
+ }
404
+ }
405
+ }
406
+ else {
407
+ if (nextNode && nextNode.nodeName === '#text') {
408
+ const str = String(view);
409
+ if (nextNode.nodeValue !== str)
410
+ nextNode.nodeValue = str;
411
+ nextNode = nextNode.nextSibling;
412
+ }
413
+ else {
414
+ const textNode = $mol_dom_context.document.createTextNode(String(view));
415
+ el.insertBefore(textNode, nextNode);
416
+ }
417
+ }
494
418
  }
495
- }
496
- $.$mol_object2 = $mol_object2;
497
- })($ || ($ = {}));
498
-
499
- ;
500
- "use strict";
501
- var $;
502
- (function ($_1) {
503
- let $$;
504
- (function ($$) {
505
- let $;
506
- })($$ = $_1.$$ || ($_1.$$ = {}));
507
- $_1.$mol_object_field = Symbol('$mol_object_field');
508
- class $mol_object extends $mol_object2 {
509
- static make(config) {
510
- return super.create(obj => {
511
- for (let key in config)
512
- obj[key] = config[key];
513
- });
419
+ while (nextNode) {
420
+ const currNode = nextNode;
421
+ nextNode = currNode.nextSibling;
422
+ el.removeChild(currNode);
514
423
  }
515
424
  }
516
- $_1.$mol_object = $mol_object;
425
+ $.$mol_dom_render_children = $mol_dom_render_children;
517
426
  })($ || ($ = {}));
518
427
 
519
428
  ;
520
429
  "use strict";
521
- var $;
522
- (function ($) {
523
- function $mol_guid(length = 8, exists = () => false) {
524
- for (;;) {
525
- let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
526
- if (exists(id))
527
- continue;
528
- return id;
529
- }
530
- }
531
- $.$mol_guid = $mol_guid;
532
- })($ || ($ = {}));
533
430
 
534
431
  ;
535
432
  "use strict";
536
433
  var $;
537
434
  (function ($) {
538
- let $mol_wire_cursor;
539
- (function ($mol_wire_cursor) {
540
- $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
541
- $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
542
- $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
543
- $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
544
- })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
545
- })($ || ($ = {}));
546
-
547
- ;
548
- "use strict";
549
- var $;
550
- (function ($) {
551
- class $mol_wire_pub extends Object {
552
- constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
553
- super();
554
- this[Symbol.toStringTag] = id;
555
- }
556
- [Symbol.toStringTag];
557
- data = [];
558
- static get [Symbol.species]() {
559
- return Array;
560
- }
561
- sub_from = 0;
562
- get sub_list() {
563
- const res = [];
564
- for (let i = this.sub_from; i < this.data.length; i += 2) {
565
- res.push(this.data[i]);
435
+ $.$mol_jsx_prefix = '';
436
+ $.$mol_jsx_crumbs = '';
437
+ $.$mol_jsx_booked = null;
438
+ $.$mol_jsx_document = {
439
+ getElementById: () => null,
440
+ createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
441
+ createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
442
+ };
443
+ $.$mol_jsx_frag = '';
444
+ function $mol_jsx(Elem, props, ...childNodes) {
445
+ const id = props && props.id || '';
446
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
447
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
448
+ if (Elem && $.$mol_jsx_booked) {
449
+ if ($.$mol_jsx_booked.has(id)) {
450
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
451
+ }
452
+ else {
453
+ $.$mol_jsx_booked.add(id);
566
454
  }
567
- return res;
568
- }
569
- get sub_empty() {
570
- return this.sub_from === this.data.length;
571
455
  }
572
- sub_on(sub, pub_pos) {
573
- const pos = this.data.length;
574
- this.data.push(sub, pub_pos);
575
- return pos;
456
+ let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
457
+ if ($.$mol_jsx_prefix) {
458
+ const prefix_ext = $.$mol_jsx_prefix;
459
+ const booked_ext = $.$mol_jsx_booked;
460
+ const crumbs_ext = $.$mol_jsx_crumbs;
461
+ for (const field in props) {
462
+ const func = props[field];
463
+ if (typeof func !== 'function')
464
+ continue;
465
+ const wrapper = function (...args) {
466
+ const prefix = $.$mol_jsx_prefix;
467
+ const booked = $.$mol_jsx_booked;
468
+ const crumbs = $.$mol_jsx_crumbs;
469
+ try {
470
+ $.$mol_jsx_prefix = prefix_ext;
471
+ $.$mol_jsx_booked = booked_ext;
472
+ $.$mol_jsx_crumbs = crumbs_ext;
473
+ return func.call(this, ...args);
474
+ }
475
+ finally {
476
+ $.$mol_jsx_prefix = prefix;
477
+ $.$mol_jsx_booked = booked;
478
+ $.$mol_jsx_crumbs = crumbs;
479
+ }
480
+ };
481
+ $mol_func_name_from(wrapper, func);
482
+ props[field] = wrapper;
483
+ }
576
484
  }
577
- sub_off(sub_pos) {
578
- if (!(sub_pos < this.data.length)) {
579
- $mol_fail(new Error(`Wrong pos ${sub_pos}`));
485
+ if (typeof Elem !== 'string') {
486
+ if ('prototype' in Elem) {
487
+ const view = node && node[String(Elem)] || new Elem;
488
+ Object.assign(view, props);
489
+ view[Symbol.toStringTag] = guid;
490
+ view.childNodes = childNodes;
491
+ if (!view.ownerDocument)
492
+ view.ownerDocument = $.$mol_jsx_document;
493
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
494
+ node = view.valueOf();
495
+ node[String(Elem)] = view;
496
+ return node;
580
497
  }
581
- const end = this.data.length - 2;
582
- if (sub_pos !== end) {
583
- this.peer_move(end, sub_pos);
498
+ else {
499
+ const prefix = $.$mol_jsx_prefix;
500
+ const booked = $.$mol_jsx_booked;
501
+ const crumbs = $.$mol_jsx_crumbs;
502
+ try {
503
+ $.$mol_jsx_prefix = guid;
504
+ $.$mol_jsx_booked = new Set;
505
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
506
+ return Elem(props, ...childNodes);
507
+ }
508
+ finally {
509
+ $.$mol_jsx_prefix = prefix;
510
+ $.$mol_jsx_booked = booked;
511
+ $.$mol_jsx_crumbs = crumbs;
512
+ }
584
513
  }
585
- this.data.length = end;
586
- if (end === this.sub_from)
587
- this.reap();
588
- }
589
- reap() { }
590
- promote() {
591
- $mol_wire_auto()?.track_next(this);
592
514
  }
593
- fresh() { }
594
- complete() { }
595
- get incompleted() {
596
- return false;
515
+ if (!node) {
516
+ node = Elem
517
+ ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
518
+ : $.$mol_jsx_document.createDocumentFragment();
597
519
  }
598
- emit(quant = $mol_wire_cursor.stale) {
599
- for (let i = this.sub_from; i < this.data.length; i += 2) {
600
- ;
601
- this.data[i].absorb(quant, this.data[i + 1]);
520
+ $mol_dom_render_children(node, [].concat(...childNodes));
521
+ if (!Elem)
522
+ return node;
523
+ if (guid)
524
+ node.id = guid;
525
+ for (const key in props) {
526
+ if (key === 'id')
527
+ continue;
528
+ if (typeof props[key] === 'string') {
529
+ if (typeof node[key] === 'string')
530
+ node[key] = props[key];
531
+ node.setAttribute(key, props[key]);
532
+ }
533
+ else if (props[key] &&
534
+ typeof props[key] === 'object' &&
535
+ Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
536
+ if (typeof node[key] === 'object') {
537
+ Object.assign(node[key], props[key]);
538
+ continue;
539
+ }
540
+ }
541
+ else {
542
+ node[key] = props[key];
602
543
  }
603
544
  }
604
- peer_move(from_pos, to_pos) {
605
- const peer = this.data[from_pos];
606
- const self_pos = this.data[from_pos + 1];
607
- this.data[to_pos] = peer;
608
- this.data[to_pos + 1] = self_pos;
609
- peer.peer_repos(self_pos, to_pos);
610
- }
611
- peer_repos(peer_pos, self_pos) {
612
- this.data[peer_pos + 1] = self_pos;
613
- }
545
+ if ($.$mol_jsx_crumbs)
546
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
547
+ return node;
614
548
  }
615
- $.$mol_wire_pub = $mol_wire_pub;
549
+ $.$mol_jsx = $mol_jsx;
616
550
  })($ || ($ = {}));
617
551
 
618
552
  ;
619
553
  "use strict";
554
+ var $;
555
+ (function ($) {
556
+ $.$mol_ambient_ref = Symbol('$mol_ambient_ref');
557
+ function $mol_ambient(overrides) {
558
+ return Object.setPrototypeOf(overrides, this || $);
559
+ }
560
+ $.$mol_ambient = $mol_ambient;
561
+ })($ || ($ = {}));
620
562
 
621
563
  ;
622
564
  "use strict";
623
565
  var $;
624
566
  (function ($) {
625
- $.$mol_wire_auto_sub = null;
626
- function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
627
- return $.$mol_wire_auto_sub = next;
567
+ const instances = new WeakSet();
568
+ function $mol_delegate(proto, target) {
569
+ const proxy = new Proxy(proto, {
570
+ get: (_, field) => {
571
+ const obj = target();
572
+ let val = Reflect.get(obj, field);
573
+ if (typeof val === 'function') {
574
+ val = val.bind(obj);
575
+ }
576
+ return val;
577
+ },
578
+ has: (_, field) => Reflect.has(target(), field),
579
+ set: (_, field, value) => Reflect.set(target(), field, value),
580
+ getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
581
+ ownKeys: () => Reflect.ownKeys(target()),
582
+ getPrototypeOf: () => Reflect.getPrototypeOf(target()),
583
+ setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
584
+ isExtensible: () => Reflect.isExtensible(target()),
585
+ preventExtensions: () => Reflect.preventExtensions(target()),
586
+ apply: (_, self, args) => Reflect.apply(target(), self, args),
587
+ construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
588
+ defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
589
+ deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
590
+ });
591
+ instances.add(proxy);
592
+ return proxy;
628
593
  }
629
- $.$mol_wire_auto = $mol_wire_auto;
630
- $.$mol_wire_affected = [];
594
+ $.$mol_delegate = $mol_delegate;
595
+ Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
596
+ value: (obj) => instances.has(obj),
597
+ });
631
598
  })($ || ($ = {}));
632
599
 
633
600
  ;
634
601
  "use strict";
635
602
  var $;
636
603
  (function ($) {
637
- $['devtoolsFormatters'] ||= [];
638
- function $mol_dev_format_register(config) {
639
- $['devtoolsFormatters'].push(config);
640
- }
641
- $.$mol_dev_format_register = $mol_dev_format_register;
642
- $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
643
- $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
644
- function $mol_dev_format_button(label, click) {
645
- return $mol_dev_format_auto({
646
- [$.$mol_dev_format_head]() {
647
- return $.$mol_dev_format_span({ color: 'cornflowerblue' }, label);
648
- },
649
- [$.$mol_dev_format_body]() {
650
- Promise.resolve().then(click);
651
- return $.$mol_dev_format_span({});
652
- }
653
- });
604
+ $.$mol_owning_map = new WeakMap();
605
+ function $mol_owning_allow(having) {
606
+ try {
607
+ if (!having)
608
+ return false;
609
+ if (typeof having !== 'object' && typeof having !== 'function')
610
+ return false;
611
+ if (having instanceof $mol_delegate)
612
+ return false;
613
+ if (typeof having['destructor'] !== 'function')
614
+ return false;
615
+ return true;
616
+ }
617
+ catch {
618
+ return false;
619
+ }
654
620
  }
655
- $mol_dev_format_register({
656
- header: (val, config = false) => {
657
- if (config)
658
- return null;
659
- if (!val)
660
- return null;
661
- if ($.$mol_dev_format_head in val) {
662
- try {
663
- return val[$.$mol_dev_format_head]();
664
- }
665
- catch (error) {
666
- return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
667
- }
668
- }
669
- if (typeof val === 'function') {
670
- return $mol_dev_format_native(val);
671
- }
672
- if (val instanceof Error) {
673
- return $.$mol_dev_format_span({}, $mol_dev_format_native(val), ' ', $mol_dev_format_button('throw', () => $mol_fail_hidden(val)));
674
- }
675
- if (val instanceof Promise) {
676
- return $.$mol_dev_format_shade($mol_dev_format_native(val), ' ', val[Symbol.toStringTag] ?? '');
677
- }
678
- if (Symbol.toStringTag in val) {
679
- return $mol_dev_format_native(val);
680
- }
681
- return null;
682
- },
683
- hasBody: (val, config = false) => {
684
- if (config)
685
- return false;
686
- if (!val)
687
- return false;
688
- if (val[$.$mol_dev_format_body])
689
- return true;
690
- return false;
691
- },
692
- body: (val, config = false) => {
693
- if (config)
694
- return null;
695
- if (!val)
696
- return null;
697
- if ($.$mol_dev_format_body in val) {
698
- try {
699
- return val[$.$mol_dev_format_body]();
700
- }
701
- catch (error) {
702
- return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
703
- }
704
- }
621
+ $.$mol_owning_allow = $mol_owning_allow;
622
+ function $mol_owning_get(having, Owner) {
623
+ if (!$mol_owning_allow(having))
705
624
  return null;
706
- },
707
- });
708
- function $mol_dev_format_native(obj) {
709
- if (typeof obj === 'undefined')
710
- return $.$mol_dev_format_shade('undefined');
711
- return [
712
- 'object',
713
- {
714
- object: obj,
715
- config: true,
716
- },
717
- ];
625
+ while (true) {
626
+ const owner = $.$mol_owning_map.get(having);
627
+ if (!owner)
628
+ return owner;
629
+ if (!Owner)
630
+ return owner;
631
+ if (owner instanceof Owner)
632
+ return owner;
633
+ having = owner;
634
+ }
718
635
  }
719
- $.$mol_dev_format_native = $mol_dev_format_native;
720
- function $mol_dev_format_auto(obj) {
721
- if (obj == null)
722
- return $.$mol_dev_format_shade(String(obj));
723
- return [
724
- 'object',
725
- {
726
- object: obj,
727
- config: false,
728
- },
729
- ];
636
+ $.$mol_owning_get = $mol_owning_get;
637
+ function $mol_owning_check(owner, having) {
638
+ if (!$mol_owning_allow(having))
639
+ return false;
640
+ if ($.$mol_owning_map.get(having) !== owner)
641
+ return false;
642
+ return true;
730
643
  }
731
- $.$mol_dev_format_auto = $mol_dev_format_auto;
732
- function $mol_dev_format_element(element, style, ...content) {
733
- const styles = [];
734
- for (let key in style)
735
- styles.push(`${key} : ${style[key]}`);
736
- return [
737
- element,
738
- {
739
- style: styles.join(' ; '),
740
- },
741
- ...content,
742
- ];
644
+ $.$mol_owning_check = $mol_owning_check;
645
+ function $mol_owning_catch(owner, having) {
646
+ if (!$mol_owning_allow(having))
647
+ return false;
648
+ if ($.$mol_owning_map.get(having))
649
+ return false;
650
+ $.$mol_owning_map.set(having, owner);
651
+ return true;
743
652
  }
744
- $.$mol_dev_format_element = $mol_dev_format_element;
745
- $.$mol_dev_format_span = $mol_dev_format_element.bind(null, 'span');
746
- $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
747
- $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
748
- $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
749
- $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
750
- $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
751
- $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
752
- $.$mol_dev_format_accent = $.$mol_dev_format_span.bind(null, {
753
- 'color': 'magenta',
754
- });
755
- $.$mol_dev_format_strong = $.$mol_dev_format_span.bind(null, {
756
- 'font-weight': 'bold',
757
- });
758
- $.$mol_dev_format_string = $.$mol_dev_format_span.bind(null, {
759
- 'color': 'green',
760
- });
761
- $.$mol_dev_format_shade = $.$mol_dev_format_span.bind(null, {
762
- 'color': 'gray',
763
- });
764
- $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
765
- 'margin-left': '13px'
766
- });
767
- class Stack extends Array {
768
- toString() {
769
- return this.join('\n');
770
- }
653
+ $.$mol_owning_catch = $mol_owning_catch;
654
+ })($ || ($ = {}));
655
+
656
+ ;
657
+ "use strict";
658
+ var $;
659
+ (function ($) {
660
+ function $mol_fail_hidden(error) {
661
+ throw error;
771
662
  }
772
- class Call extends Object {
773
- type;
774
- function;
775
- method;
776
- eval;
777
- source;
778
- offset;
779
- pos;
780
- object;
781
- flags;
663
+ $.$mol_fail_hidden = $mol_fail_hidden;
664
+ })($ || ($ = {}));
665
+
666
+ ;
667
+ "use strict";
668
+
669
+ ;
670
+ "use strict";
671
+ var $;
672
+ (function ($) {
673
+ $.$mol_key_handle = Symbol.for('$mol_key_handle');
674
+ $.$mol_key_store = new WeakMap();
675
+ })($ || ($ = {}));
676
+
677
+ ;
678
+ "use strict";
679
+ var $;
680
+ (function ($) {
681
+ if (!Symbol.dispose)
682
+ Symbol.dispose = Symbol('Symbol.dispose');
683
+ class $mol_object2 {
684
+ static $ = $;
782
685
  [Symbol.toStringTag];
783
- constructor(call) {
784
- super();
785
- this.type = call.getTypeName() ?? '';
786
- this.function = call.getFunctionName() ?? '';
787
- this.method = call.getMethodName() ?? '';
788
- if (this.method === this.function)
789
- this.method = '';
790
- this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
791
- this.eval = call.getEvalOrigin() ?? '';
792
- this.source = call.getScriptNameOrSourceURL() ?? '';
793
- this.object = call.getThis();
794
- this.offset = call.getPosition();
795
- const flags = [];
796
- if (call.isAsync())
797
- flags.push('async');
798
- if (call.isConstructor())
799
- flags.push('constructor');
800
- if (call.isEval())
801
- flags.push('eval');
802
- if (call.isNative())
803
- flags.push('native');
804
- if (call.isPromiseAll())
805
- flags.push('PromiseAll');
806
- if (call.isToplevel())
807
- flags.push('top');
808
- this.flags = flags;
809
- const type = this.type ? this.type + '.' : '';
810
- const func = this.function || '<anon>';
811
- const method = this.method ? ' [' + this.method + '] ' : '';
812
- this[Symbol.toStringTag] = `${type}${func}${method}`;
686
+ [$mol_ambient_ref] = null;
687
+ get $() {
688
+ if (this[$mol_ambient_ref])
689
+ return this[$mol_ambient_ref];
690
+ const owner = $mol_owning_get(this);
691
+ return this[$mol_ambient_ref] = owner?.$ || this.constructor.$ || $mol_object2.$;
813
692
  }
814
- [Symbol.toPrimitive]() {
693
+ set $(next) {
694
+ if (this[$mol_ambient_ref])
695
+ $mol_fail_hidden(new Error('Context already defined'));
696
+ this[$mol_ambient_ref] = next;
697
+ }
698
+ static create(init) {
699
+ const obj = new this;
700
+ if (init)
701
+ init(obj);
702
+ return obj;
703
+ }
704
+ static [Symbol.toPrimitive]() {
815
705
  return this.toString();
816
706
  }
817
- toString() {
818
- const object = this.object || '';
819
- const label = this[Symbol.toStringTag];
820
- const source = `${this.source}:${this.pos.join(':')} #${this.offset}`;
821
- return `\tat ${object}${label} (${source})`;
707
+ static toString() {
708
+ return this[Symbol.toStringTag] || this.$.$mol_func_name(this);
822
709
  }
823
- [$.$mol_dev_format_head]() {
824
- return $.$mol_dev_format_div({}, $mol_dev_format_native(this), $.$mol_dev_format_shade(' '), ...this.object ? [
825
- $mol_dev_format_native(this.object),
826
- ] : [], ...this.method ? [$.$mol_dev_format_shade(' ', ' [', this.method, ']')] : [], $.$mol_dev_format_shade(' ', this.flags.join(', ')));
710
+ static toJSON() {
711
+ return this.toString();
712
+ }
713
+ static [$mol_key_handle]() {
714
+ return this.toString();
715
+ }
716
+ destructor() { }
717
+ static destructor() { }
718
+ [Symbol.dispose]() {
719
+ this.destructor();
720
+ }
721
+ toString() {
722
+ return this[Symbol.toStringTag] || this.constructor.name + '<>';
827
723
  }
828
724
  }
829
- Error.prepareStackTrace ??= (error, stack) => new Stack(...stack.map(call => new Call(call)));
725
+ $.$mol_object2 = $mol_object2;
830
726
  })($ || ($ = {}));
831
727
 
832
728
  ;
833
729
  "use strict";
834
730
  var $;
835
- (function ($) {
836
- class $mol_wire_pub_sub extends $mol_wire_pub {
837
- pub_from = 0;
838
- cursor = $mol_wire_cursor.stale;
839
- get temp() {
840
- return false;
841
- }
842
- get pub_list() {
843
- const res = [];
844
- const max = this.cursor >= 0 ? this.cursor : this.sub_from;
845
- for (let i = this.pub_from; i < max; i += 2) {
846
- if (this.data[i])
847
- res.push(this.data[i]);
848
- }
849
- return res;
731
+ (function ($_1) {
732
+ let $$;
733
+ (function ($$) {
734
+ let $;
735
+ })($$ = $_1.$$ || ($_1.$$ = {}));
736
+ $_1.$mol_object_field = Symbol('$mol_object_field');
737
+ class $mol_object extends $mol_object2 {
738
+ static make(config) {
739
+ return super.create(obj => {
740
+ for (let key in config)
741
+ obj[key] = config[key];
742
+ });
850
743
  }
851
- track_on() {
852
- this.cursor = this.pub_from;
853
- const sub = $mol_wire_auto();
854
- $mol_wire_auto(this);
855
- return sub;
744
+ }
745
+ $_1.$mol_object = $mol_object;
746
+ })($ || ($ = {}));
747
+
748
+ ;
749
+ "use strict";
750
+ var $;
751
+ (function ($) {
752
+ function $mol_guid(length = 8, exists = () => false) {
753
+ for (;;) {
754
+ let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
755
+ if (exists(id))
756
+ continue;
757
+ return id;
856
758
  }
857
- promote() {
858
- if (this.cursor >= this.pub_from) {
859
- $mol_fail(new Error('Circular subscription'));
860
- }
861
- super.promote();
759
+ }
760
+ $.$mol_guid = $mol_guid;
761
+ })($ || ($ = {}));
762
+
763
+ ;
764
+ "use strict";
765
+ var $;
766
+ (function ($) {
767
+ let $mol_wire_cursor;
768
+ (function ($mol_wire_cursor) {
769
+ $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
770
+ $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
771
+ $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
772
+ $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
773
+ })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
774
+ })($ || ($ = {}));
775
+
776
+ ;
777
+ "use strict";
778
+ var $;
779
+ (function ($) {
780
+ class $mol_wire_pub extends Object {
781
+ constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
782
+ super();
783
+ this[Symbol.toStringTag] = id;
862
784
  }
863
- track_next(pub) {
864
- if (this.cursor < 0)
865
- $mol_fail(new Error('Promo to non begun sub'));
866
- if (this.cursor < this.sub_from) {
867
- const next = this.data[this.cursor];
868
- if (pub === undefined)
869
- return next ?? null;
870
- if (next === pub) {
871
- this.cursor += 2;
872
- return next;
873
- }
874
- if (next) {
875
- if (this.sub_from < this.data.length) {
876
- this.peer_move(this.sub_from, this.data.length);
877
- }
878
- this.peer_move(this.cursor, this.sub_from);
879
- this.sub_from += 2;
880
- }
881
- }
882
- else {
883
- if (pub === undefined)
884
- return null;
885
- if (this.sub_from < this.data.length) {
886
- this.peer_move(this.sub_from, this.data.length);
887
- }
888
- this.sub_from += 2;
889
- }
890
- this.data[this.cursor] = pub;
891
- this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
892
- this.cursor += 2;
893
- return pub;
785
+ [Symbol.toStringTag];
786
+ data = [];
787
+ static get [Symbol.species]() {
788
+ return Array;
894
789
  }
895
- track_off(sub) {
896
- $mol_wire_auto(sub);
897
- if (this.cursor < 0) {
898
- $mol_fail(new Error('End of non begun sub'));
899
- }
900
- for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
901
- const pub = this.data[cursor];
902
- pub.fresh();
790
+ sub_from = 0;
791
+ get sub_list() {
792
+ const res = [];
793
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
794
+ res.push(this.data[i]);
903
795
  }
904
- this.cursor = $mol_wire_cursor.fresh;
796
+ return res;
905
797
  }
906
- pub_off(sub_pos) {
907
- this.data[sub_pos] = undefined;
908
- this.data[sub_pos + 1] = undefined;
798
+ get sub_empty() {
799
+ return this.sub_from === this.data.length;
909
800
  }
910
- destructor() {
911
- for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
912
- const sub = this.data[cursor];
913
- const pos = this.data[cursor + 1];
914
- sub.pub_off(pos);
915
- }
916
- this.data.length = this.sub_from;
917
- this.cursor = this.pub_from;
918
- this.track_cut();
919
- this.cursor = $mol_wire_cursor.stale;
801
+ sub_on(sub, pub_pos) {
802
+ const pos = this.data.length;
803
+ this.data.push(sub, pub_pos);
804
+ return pos;
920
805
  }
921
- track_cut() {
922
- if (this.cursor < this.pub_from) {
923
- $mol_fail(new Error('Cut of non begun sub'));
806
+ sub_off(sub_pos) {
807
+ if (!(sub_pos < this.data.length)) {
808
+ $mol_fail(new Error(`Wrong pos ${sub_pos}`));
924
809
  }
925
- let end = this.data.length;
926
- for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
927
- const pub = this.data[cursor];
928
- pub?.sub_off(this.data[cursor + 1]);
929
- end -= 2;
930
- if (this.sub_from <= end)
931
- this.peer_move(end, cursor);
810
+ const end = this.data.length - 2;
811
+ if (sub_pos !== end) {
812
+ this.peer_move(end, sub_pos);
932
813
  }
933
814
  this.data.length = end;
934
- this.sub_from = this.cursor;
815
+ if (end === this.sub_from)
816
+ this.reap();
817
+ }
818
+ reap() { }
819
+ promote() {
820
+ $mol_wire_auto()?.track_next(this);
935
821
  }
822
+ fresh() { }
936
823
  complete() { }
937
- complete_pubs() {
938
- const limit = this.cursor < 0 ? this.sub_from : this.cursor;
939
- for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
940
- const pub = this.data[cursor];
941
- if (pub?.incompleted)
942
- return;
943
- }
944
- for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
945
- const pub = this.data[cursor];
946
- pub?.complete();
947
- }
824
+ get incompleted() {
825
+ return false;
948
826
  }
949
- absorb(quant = $mol_wire_cursor.stale, pos = -1) {
950
- if (this.cursor === $mol_wire_cursor.final)
951
- return;
952
- if (this.cursor >= quant)
953
- return;
954
- this.cursor = quant;
955
- this.emit($mol_wire_cursor.doubt);
827
+ emit(quant = $mol_wire_cursor.stale) {
828
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
829
+ ;
830
+ this.data[i].absorb(quant, this.data[i + 1]);
831
+ }
956
832
  }
957
- [$mol_dev_format_head]() {
958
- return $mol_dev_format_native(this);
833
+ peer_move(from_pos, to_pos) {
834
+ const peer = this.data[from_pos];
835
+ const self_pos = this.data[from_pos + 1];
836
+ this.data[to_pos] = peer;
837
+ this.data[to_pos + 1] = self_pos;
838
+ peer.peer_repos(self_pos, to_pos);
959
839
  }
960
- get pub_empty() {
961
- return this.sub_from === this.pub_from;
840
+ peer_repos(peer_pos, self_pos) {
841
+ this.data[peer_pos + 1] = self_pos;
962
842
  }
963
843
  }
964
- $.$mol_wire_pub_sub = $mol_wire_pub_sub;
844
+ $.$mol_wire_pub = $mol_wire_pub;
965
845
  })($ || ($ = {}));
966
846
 
967
847
  ;
968
848
  "use strict";
969
- var $;
970
- (function ($) {
971
- class $mol_after_tick extends $mol_object2 {
972
- task;
973
- static promise = null;
974
- cancelled = false;
975
- constructor(task) {
976
- super();
977
- this.task = task;
978
- if (!$mol_after_tick.promise)
979
- $mol_after_tick.promise = Promise.resolve().then(() => {
980
- $mol_after_tick.promise = null;
981
- });
982
- $mol_after_tick.promise.then(() => {
983
- if (this.cancelled)
984
- return;
985
- task();
986
- });
987
- }
988
- destructor() {
989
- this.cancelled = true;
990
- }
991
- }
992
- $.$mol_after_tick = $mol_after_tick;
993
- })($ || ($ = {}));
994
849
 
995
850
  ;
996
851
  "use strict";
997
852
  var $;
998
853
  (function ($) {
999
- function $mol_promise_like(val) {
1000
- try {
1001
- return val && typeof val === 'object' && 'then' in val && typeof val.then === 'function';
1002
- }
1003
- catch {
1004
- return false;
1005
- }
854
+ $.$mol_wire_auto_sub = null;
855
+ function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
856
+ return $.$mol_wire_auto_sub = next;
1006
857
  }
1007
- $.$mol_promise_like = $mol_promise_like;
858
+ $.$mol_wire_auto = $mol_wire_auto;
859
+ $.$mol_wire_affected = [];
1008
860
  })($ || ($ = {}));
1009
861
 
1010
862
  ;
1011
863
  "use strict";
1012
864
  var $;
1013
865
  (function ($) {
1014
- const wrappers = new WeakMap();
1015
- class $mol_wire_fiber extends $mol_wire_pub_sub {
1016
- task;
1017
- host;
1018
- static warm = true;
1019
- static planning = new Set();
1020
- static reaping = new Set();
1021
- static plan_task = null;
1022
- static plan() {
1023
- if (this.plan_task)
1024
- return;
1025
- this.plan_task = new $mol_after_tick(() => {
1026
- try {
1027
- this.sync();
1028
- }
1029
- finally {
1030
- $mol_wire_fiber.plan_task = null;
1031
- }
1032
- });
1033
- }
1034
- static sync() {
1035
- while (this.planning.size) {
1036
- for (const fiber of this.planning) {
1037
- this.planning.delete(fiber);
1038
- if (fiber.cursor >= 0)
1039
- continue;
1040
- if (fiber.cursor === $mol_wire_cursor.final)
1041
- continue;
1042
- fiber.fresh();
1043
- }
1044
- }
1045
- while (this.reaping.size) {
1046
- const fibers = this.reaping;
1047
- this.reaping = new Set;
1048
- for (const fiber of fibers) {
1049
- if (!fiber.sub_empty)
1050
- continue;
1051
- fiber.destructor();
1052
- }
1053
- }
1054
- }
1055
- cache = undefined;
1056
- get args() {
1057
- return this.data.slice(0, this.pub_from);
1058
- }
1059
- result() {
1060
- if ($mol_promise_like(this.cache))
1061
- return;
1062
- if (this.cache instanceof Error)
1063
- return;
1064
- return this.cache;
1065
- }
1066
- get incompleted() {
1067
- return $mol_promise_like(this.cache);
1068
- }
1069
- field() {
1070
- return this.task.name + '()';
1071
- }
1072
- constructor(id, task, host, args) {
1073
- super(id);
1074
- this.task = task;
1075
- this.host = host;
1076
- if (args)
1077
- this.data.push(...args);
1078
- this.pub_from = this.sub_from = args?.length ?? 0;
1079
- }
1080
- plan() {
1081
- $mol_wire_fiber.planning.add(this);
1082
- $mol_wire_fiber.plan();
1083
- return this;
1084
- }
1085
- reap() {
1086
- $mol_wire_fiber.reaping.add(this);
1087
- $mol_wire_fiber.plan();
1088
- }
1089
- toString() {
1090
- return this[Symbol.toStringTag];
1091
- }
1092
- toJSON() {
1093
- return this[Symbol.toStringTag];
1094
- }
1095
- [$mol_dev_format_head]() {
1096
- const cursor = {
1097
- [$mol_wire_cursor.stale]: '🔴',
1098
- [$mol_wire_cursor.doubt]: '🟡',
1099
- [$mol_wire_cursor.fresh]: '🟢',
1100
- [$mol_wire_cursor.final]: '🔵',
1101
- }[this.cursor] ?? this.cursor.toString();
1102
- return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
1103
- ? $mol_dev_format_shade(cursor)
1104
- : $mol_dev_format_shade(this[Symbol.toStringTag], cursor), $mol_dev_format_auto(this.cache));
1105
- }
1106
- [$mol_dev_format_body]() { return null; }
1107
- get $() {
1108
- return (this.host ?? this.task)['$'];
1109
- }
1110
- emit(quant = $mol_wire_cursor.stale) {
1111
- if (this.sub_empty)
1112
- this.plan();
1113
- else
1114
- super.emit(quant);
1115
- }
1116
- fresh() {
1117
- if (this.cursor === $mol_wire_cursor.fresh)
1118
- return;
1119
- if (this.cursor === $mol_wire_cursor.final)
1120
- return;
1121
- check: if (this.cursor === $mol_wire_cursor.doubt) {
1122
- for (let i = this.pub_from; i < this.sub_from; i += 2) {
1123
- ;
1124
- this.data[i]?.fresh();
1125
- if (this.cursor !== $mol_wire_cursor.doubt)
1126
- break check;
1127
- }
1128
- this.cursor = $mol_wire_cursor.fresh;
1129
- return;
1130
- }
1131
- const bu = this.track_on();
1132
- let result;
1133
- try {
1134
- switch (this.pub_from) {
1135
- case 0:
1136
- result = this.task.call(this.host);
1137
- break;
1138
- case 1:
1139
- result = this.task.call(this.host, this.data[0]);
1140
- break;
1141
- default:
1142
- result = this.task.call(this.host, ...this.args);
1143
- break;
1144
- }
1145
- if ($mol_promise_like(result)) {
1146
- if (wrappers.has(result)) {
1147
- result = wrappers.get(result).then(a => a);
1148
- }
1149
- else {
1150
- const put = (res) => {
1151
- if (this.cache === result)
1152
- this.put(res);
1153
- return res;
1154
- };
1155
- wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
1156
- wrappers.set(result, result);
1157
- const error = new Error(`Promise in ${this}`);
1158
- Object.defineProperty(result, 'stack', { get: () => error.stack });
1159
- }
1160
- }
866
+ $['devtoolsFormatters'] ||= [];
867
+ function $mol_dev_format_register(config) {
868
+ $['devtoolsFormatters'].push(config);
869
+ }
870
+ $.$mol_dev_format_register = $mol_dev_format_register;
871
+ $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
872
+ $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
873
+ function $mol_dev_format_button(label, click) {
874
+ return $mol_dev_format_auto({
875
+ [$.$mol_dev_format_head]() {
876
+ return $.$mol_dev_format_span({ color: 'cornflowerblue' }, label);
877
+ },
878
+ [$.$mol_dev_format_body]() {
879
+ Promise.resolve().then(click);
880
+ return $.$mol_dev_format_span({});
1161
881
  }
1162
- catch (error) {
1163
- if (error instanceof Error || $mol_promise_like(error)) {
1164
- result = error;
1165
- }
1166
- else {
1167
- result = new Error(String(error), { cause: error });
882
+ });
883
+ }
884
+ $mol_dev_format_register({
885
+ header: (val, config = false) => {
886
+ if (config)
887
+ return null;
888
+ if (!val)
889
+ return null;
890
+ if ($.$mol_dev_format_head in val) {
891
+ try {
892
+ return val[$.$mol_dev_format_head]();
1168
893
  }
1169
- if ($mol_promise_like(result)) {
1170
- if (wrappers.has(result)) {
1171
- result = wrappers.get(result);
1172
- }
1173
- else {
1174
- const put = (v) => {
1175
- if (this.cache === result)
1176
- this.absorb();
1177
- return v;
1178
- };
1179
- wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
1180
- const error = new Error(`Promise in ${this}`);
1181
- Object.defineProperty(result, 'stack', { get: () => error.stack });
1182
- }
894
+ catch (error) {
895
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
1183
896
  }
1184
897
  }
1185
- if (!$mol_promise_like(result)) {
1186
- this.track_cut();
898
+ if (typeof val === 'function') {
899
+ return $mol_dev_format_native(val);
1187
900
  }
1188
- this.track_off(bu);
1189
- this.put(result);
1190
- return this;
1191
- }
1192
- refresh() {
1193
- this.cursor = $mol_wire_cursor.stale;
1194
- this.fresh();
1195
- }
1196
- sync() {
1197
- if (!$mol_wire_fiber.warm) {
1198
- return this.result();
901
+ if (val instanceof Error) {
902
+ return $.$mol_dev_format_span({}, $mol_dev_format_native(val), ' ', $mol_dev_format_button('throw', () => $mol_fail_hidden(val)));
1199
903
  }
1200
- this.promote();
1201
- this.fresh();
1202
- if (this.cache instanceof Error) {
1203
- return $mol_fail_hidden(this.cache);
904
+ if (val instanceof Promise) {
905
+ return $.$mol_dev_format_shade($mol_dev_format_native(val), ' ', val[Symbol.toStringTag] ?? '');
1204
906
  }
1205
- if ($mol_promise_like(this.cache)) {
1206
- return $mol_fail_hidden(this.cache);
907
+ if (Symbol.toStringTag in val) {
908
+ return $mol_dev_format_native(val);
1207
909
  }
1208
- return this.cache;
1209
- }
1210
- async async_raw() {
1211
- while (true) {
1212
- this.fresh();
1213
- if (this.cache instanceof Error) {
1214
- $mol_fail_hidden(this.cache);
910
+ return null;
911
+ },
912
+ hasBody: (val, config = false) => {
913
+ if (config)
914
+ return false;
915
+ if (!val)
916
+ return false;
917
+ if (val[$.$mol_dev_format_body])
918
+ return true;
919
+ return false;
920
+ },
921
+ body: (val, config = false) => {
922
+ if (config)
923
+ return null;
924
+ if (!val)
925
+ return null;
926
+ if ($.$mol_dev_format_body in val) {
927
+ try {
928
+ return val[$.$mol_dev_format_body]();
1215
929
  }
1216
- if (!$mol_promise_like(this.cache))
1217
- return this.cache;
1218
- await Promise.race([this.cache, this.step()]);
1219
- if (!$mol_promise_like(this.cache))
1220
- return this.cache;
1221
- if (this.cursor === $mol_wire_cursor.final) {
1222
- await new Promise(() => { });
930
+ catch (error) {
931
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
1223
932
  }
1224
933
  }
1225
- }
1226
- async() {
1227
- const promise = this.async_raw();
1228
- if (!promise.destructor)
1229
- promise.destructor = () => this.destructor();
1230
- return promise;
1231
- }
1232
- step() {
1233
- return new Promise(done => {
1234
- const sub = new $mol_wire_pub_sub;
1235
- const prev = sub.track_on();
1236
- sub.track_next(this);
1237
- sub.track_off(prev);
1238
- sub.absorb = () => {
1239
- done(null);
1240
- setTimeout(() => sub.destructor());
1241
- };
1242
- });
1243
- }
1244
- destructor() {
1245
- super.destructor();
1246
- $mol_wire_fiber.planning.delete(this);
1247
- if (!$mol_owning_check(this, this.cache))
1248
- return;
1249
- try {
1250
- this.cache.destructor();
1251
- }
1252
- catch (result) {
1253
- if ($mol_promise_like(result)) {
1254
- const error = new Error(`Promise in ${this}.destructor()`);
1255
- Object.defineProperty(result, 'stack', { get: () => error.stack });
1256
- }
1257
- $mol_fail_hidden(result);
1258
- }
1259
- }
1260
- }
1261
- $.$mol_wire_fiber = $mol_wire_fiber;
1262
- })($ || ($ = {}));
1263
-
1264
- ;
1265
- "use strict";
1266
- var $;
1267
- (function ($) {
1268
- const TypedArray = Object.getPrototypeOf(Uint8Array);
1269
- function $mol_key(value) {
1270
- primitives: {
1271
- if (typeof value === 'bigint')
1272
- return value.toString() + 'n';
1273
- if (typeof value === 'symbol')
1274
- return `Symbol(${value.description})`;
1275
- if (!value)
1276
- return JSON.stringify(value);
1277
- if (typeof value !== 'object' && typeof value !== 'function')
1278
- return JSON.stringify(value);
1279
- }
1280
- caching: {
1281
- let key = $mol_key_store.get(value);
1282
- if (key)
1283
- return key;
1284
- }
1285
- objects: {
1286
- if (value instanceof TypedArray) {
1287
- return `${value[Symbol.toStringTag]}([${[...value].map(v => $mol_key(v))}])`;
1288
- }
1289
- if (Array.isArray(value))
1290
- return `[${value.map(v => $mol_key(v))}]`;
1291
- if (value instanceof RegExp)
1292
- return value.toString();
1293
- if (value instanceof Date)
1294
- return `Date(${value.valueOf()})`;
1295
- }
1296
- structures: {
1297
- const proto = Reflect.getPrototypeOf(value);
1298
- if (!proto || !Reflect.getPrototypeOf(proto)) {
1299
- return `{${Object.entries(value).map(([k, v]) => JSON.stringify(k) + ':' + $mol_key(v))}}`;
1300
- }
1301
- }
1302
- handlers: {
1303
- if ($mol_key_handle in value) {
1304
- return value[$mol_key_handle]();
1305
- }
1306
- }
1307
- containers: {
1308
- const key = JSON.stringify('#' + $mol_guid());
1309
- $mol_key_store.set(value, key);
1310
- return key;
1311
- }
934
+ return null;
935
+ },
936
+ });
937
+ function $mol_dev_format_native(obj) {
938
+ if (typeof obj === 'undefined')
939
+ return $.$mol_dev_format_shade('undefined');
940
+ return [
941
+ 'object',
942
+ {
943
+ object: obj,
944
+ config: true,
945
+ },
946
+ ];
1312
947
  }
1313
- $.$mol_key = $mol_key;
1314
- })($ || ($ = {}));
1315
-
1316
- ;
1317
- "use strict";
1318
- var $;
1319
- (function ($) {
1320
- class $mol_after_frame extends $mol_object2 {
1321
- task;
1322
- static _promise = null;
1323
- static get promise() {
1324
- if (this._promise)
1325
- return this._promise;
1326
- return this._promise = new Promise(done => {
1327
- const complete = () => {
1328
- this._promise = null;
1329
- done();
1330
- };
1331
- if (typeof requestAnimationFrame === 'function') {
1332
- requestAnimationFrame(complete);
1333
- }
1334
- else {
1335
- setTimeout(complete, 16);
1336
- }
1337
- });
1338
- }
1339
- cancelled = false;
1340
- promise;
1341
- constructor(task) {
1342
- super();
1343
- this.task = task;
1344
- this.promise = $mol_after_frame.promise.then(() => {
1345
- if (this.cancelled)
1346
- return;
1347
- task();
1348
- });
1349
- }
1350
- destructor() {
1351
- this.cancelled = true;
1352
- }
948
+ $.$mol_dev_format_native = $mol_dev_format_native;
949
+ function $mol_dev_format_auto(obj) {
950
+ if (obj == null)
951
+ return $.$mol_dev_format_shade(String(obj));
952
+ return [
953
+ 'object',
954
+ {
955
+ object: obj,
956
+ config: false,
957
+ },
958
+ ];
1353
959
  }
1354
- $.$mol_after_frame = $mol_after_frame;
1355
- })($ || ($ = {}));
1356
-
1357
- ;
1358
- "use strict";
1359
- var $;
1360
- (function ($) {
1361
- $.$mol_compare_deep_cache = new WeakMap();
1362
- function $mol_compare_deep(left, right) {
1363
- if (Object.is(left, right))
1364
- return true;
1365
- if (left === null)
1366
- return false;
1367
- if (right === null)
1368
- return false;
1369
- if (typeof left !== 'object')
1370
- return false;
1371
- if (typeof right !== 'object')
1372
- return false;
1373
- const left_proto = Reflect.getPrototypeOf(left);
1374
- const right_proto = Reflect.getPrototypeOf(right);
1375
- if (left_proto !== right_proto)
1376
- return false;
1377
- if (left instanceof Boolean)
1378
- return Object.is(left.valueOf(), right['valueOf']());
1379
- if (left instanceof Number)
1380
- return Object.is(left.valueOf(), right['valueOf']());
1381
- if (left instanceof String)
1382
- return Object.is(left.valueOf(), right['valueOf']());
1383
- if (left instanceof Date)
1384
- return Object.is(left.valueOf(), right['valueOf']());
1385
- if (left instanceof RegExp)
1386
- return left.source === right.source && left.flags === right.flags;
1387
- if (left instanceof Error)
1388
- return left.message === right.message && $mol_compare_deep(left.stack, right.stack);
1389
- let left_cache = $.$mol_compare_deep_cache.get(left);
1390
- if (left_cache) {
1391
- const right_cache = left_cache.get(right);
1392
- if (typeof right_cache === 'boolean')
1393
- return right_cache;
1394
- }
1395
- else {
1396
- left_cache = new WeakMap();
1397
- $.$mol_compare_deep_cache.set(left, left_cache);
1398
- }
1399
- left_cache.set(right, true);
1400
- let result;
1401
- try {
1402
- if (!left_proto)
1403
- result = compare_pojo(left, right);
1404
- else if (!Reflect.getPrototypeOf(left_proto))
1405
- result = compare_pojo(left, right);
1406
- else if (Symbol.toPrimitive in left)
1407
- result = compare_primitive(left, right);
1408
- else if (Array.isArray(left))
1409
- result = compare_array(left, right);
1410
- else if (left instanceof Set)
1411
- result = compare_set(left, right);
1412
- else if (left instanceof Map)
1413
- result = compare_map(left, right);
1414
- else if (ArrayBuffer.isView(left))
1415
- result = compare_buffer(left, right);
1416
- else if (Symbol.iterator in left)
1417
- result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
1418
- else
1419
- result = false;
1420
- }
1421
- finally {
1422
- left_cache.set(right, result);
1423
- }
1424
- return result;
960
+ $.$mol_dev_format_auto = $mol_dev_format_auto;
961
+ function $mol_dev_format_element(element, style, ...content) {
962
+ const styles = [];
963
+ for (let key in style)
964
+ styles.push(`${key} : ${style[key]}`);
965
+ return [
966
+ element,
967
+ {
968
+ style: styles.join(' ; '),
969
+ },
970
+ ...content,
971
+ ];
1425
972
  }
1426
- $.$mol_compare_deep = $mol_compare_deep;
1427
- function compare_array(left, right) {
1428
- const len = left.length;
1429
- if (len !== right.length)
1430
- return false;
1431
- for (let i = 0; i < len; ++i) {
1432
- if (!$mol_compare_deep(left[i], right[i]))
1433
- return false;
973
+ $.$mol_dev_format_element = $mol_dev_format_element;
974
+ $.$mol_dev_format_span = $mol_dev_format_element.bind(null, 'span');
975
+ $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
976
+ $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
977
+ $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
978
+ $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
979
+ $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
980
+ $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
981
+ $.$mol_dev_format_accent = $.$mol_dev_format_span.bind(null, {
982
+ 'color': 'magenta',
983
+ });
984
+ $.$mol_dev_format_strong = $.$mol_dev_format_span.bind(null, {
985
+ 'font-weight': 'bold',
986
+ });
987
+ $.$mol_dev_format_string = $.$mol_dev_format_span.bind(null, {
988
+ 'color': 'green',
989
+ });
990
+ $.$mol_dev_format_shade = $.$mol_dev_format_span.bind(null, {
991
+ 'color': 'gray',
992
+ });
993
+ $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
994
+ 'margin-left': '13px'
995
+ });
996
+ class Stack extends Array {
997
+ toString() {
998
+ return this.join('\n');
1434
999
  }
1435
- return true;
1436
1000
  }
1437
- function compare_buffer(left, right) {
1438
- const len = left.byteLength;
1439
- if (len !== right.byteLength)
1440
- return false;
1441
- if (left instanceof DataView)
1442
- return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, right.byteOffset, right.byteLength));
1443
- for (let i = 0; i < len; ++i) {
1444
- if (left[i] !== right[i])
1445
- return false;
1001
+ class Call extends Object {
1002
+ type;
1003
+ function;
1004
+ method;
1005
+ eval;
1006
+ source;
1007
+ offset;
1008
+ pos;
1009
+ object;
1010
+ flags;
1011
+ [Symbol.toStringTag];
1012
+ constructor(call) {
1013
+ super();
1014
+ this.type = call.getTypeName() ?? '';
1015
+ this.function = call.getFunctionName() ?? '';
1016
+ this.method = call.getMethodName() ?? '';
1017
+ if (this.method === this.function)
1018
+ this.method = '';
1019
+ this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
1020
+ this.eval = call.getEvalOrigin() ?? '';
1021
+ this.source = call.getScriptNameOrSourceURL() ?? '';
1022
+ this.object = call.getThis();
1023
+ this.offset = call.getPosition();
1024
+ const flags = [];
1025
+ if (call.isAsync())
1026
+ flags.push('async');
1027
+ if (call.isConstructor())
1028
+ flags.push('constructor');
1029
+ if (call.isEval())
1030
+ flags.push('eval');
1031
+ if (call.isNative())
1032
+ flags.push('native');
1033
+ if (call.isPromiseAll())
1034
+ flags.push('PromiseAll');
1035
+ if (call.isToplevel())
1036
+ flags.push('top');
1037
+ this.flags = flags;
1038
+ const type = this.type ? this.type + '.' : '';
1039
+ const func = this.function || '<anon>';
1040
+ const method = this.method ? ' [' + this.method + '] ' : '';
1041
+ this[Symbol.toStringTag] = `${type}${func}${method}`;
1446
1042
  }
1447
- return true;
1448
- }
1449
- function compare_iterator(left, right) {
1450
- while (true) {
1451
- const left_next = left.next();
1452
- const right_next = right.next();
1453
- if (left_next.done !== right_next.done)
1454
- return false;
1455
- if (left_next.done)
1456
- break;
1457
- if (!$mol_compare_deep(left_next.value, right_next.value))
1458
- return false;
1043
+ [Symbol.toPrimitive]() {
1044
+ return this.toString();
1459
1045
  }
1460
- return true;
1461
- }
1462
- function compare_set(left, right) {
1463
- if (left.size !== right.size)
1464
- return false;
1465
- return compare_iterator(left.values(), right.values());
1466
- }
1467
- function compare_map(left, right) {
1468
- if (left.size !== right.size)
1469
- return false;
1470
- return compare_iterator(left.keys(), right.keys())
1471
- && compare_iterator(left.values(), right.values());
1472
- }
1473
- function compare_pojo(left, right) {
1474
- const left_keys = Object.getOwnPropertyNames(left);
1475
- const right_keys = Object.getOwnPropertyNames(right);
1476
- if (!compare_array(left_keys, right_keys))
1477
- return false;
1478
- for (let key of left_keys) {
1479
- if (!$mol_compare_deep(left[key], right[key]))
1480
- return false;
1046
+ toString() {
1047
+ const object = this.object || '';
1048
+ const label = this[Symbol.toStringTag];
1049
+ const source = `${this.source}:${this.pos.join(':')} #${this.offset}`;
1050
+ return `\tat ${object}${label} (${source})`;
1481
1051
  }
1482
- const left_syms = Object.getOwnPropertySymbols(left);
1483
- const right_syms = Object.getOwnPropertySymbols(right);
1484
- if (!compare_array(left_syms, right_syms))
1485
- return false;
1486
- for (let key of left_syms) {
1487
- if (!$mol_compare_deep(left[key], right[key]))
1488
- return false;
1052
+ [$.$mol_dev_format_head]() {
1053
+ return $.$mol_dev_format_div({}, $mol_dev_format_native(this), $.$mol_dev_format_shade(' '), ...this.object ? [
1054
+ $mol_dev_format_native(this.object),
1055
+ ] : [], ...this.method ? [$.$mol_dev_format_shade(' ', ' [', this.method, ']')] : [], $.$mol_dev_format_shade(' ', this.flags.join(', ')));
1489
1056
  }
1490
- return true;
1491
- }
1492
- function compare_primitive(left, right) {
1493
- return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
1494
- }
1495
- })($ || ($ = {}));
1496
-
1497
- ;
1498
- "use strict";
1499
- var $;
1500
- (function ($) {
1501
- function $mol_log3_area_lazy(event) {
1502
- const self = this.$;
1503
- const stack = self.$mol_log3_stack;
1504
- const deep = stack.length;
1505
- let logged = false;
1506
- stack.push(() => {
1507
- logged = true;
1508
- self.$mol_log3_area.call(self, event);
1509
- });
1510
- return () => {
1511
- if (logged)
1512
- self.console.groupEnd();
1513
- if (stack.length > deep)
1514
- stack.length = deep;
1515
- };
1516
1057
  }
1517
- $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1518
- $.$mol_log3_stack = [];
1058
+ Error.prepareStackTrace ??= (error, stack) => new Stack(...stack.map(call => new Call(call)));
1519
1059
  })($ || ($ = {}));
1520
1060
 
1521
- ;
1522
- "use strict";
1523
-
1524
1061
  ;
1525
1062
  "use strict";
1526
1063
  var $;
1527
1064
  (function ($) {
1528
- function $mol_log3_web_make(level, color) {
1529
- return function $mol_log3_logger(event) {
1530
- const pending = this.$mol_log3_stack.pop();
1531
- if (pending)
1532
- pending();
1533
- let tpl = '%c';
1534
- const chunks = Object.entries(event);
1535
- for (let i = 0; i < chunks.length; ++i) {
1536
- tpl += (typeof chunks[i][1] === 'string') ? '%s: %s\n' : '%s: %o\n';
1065
+ class $mol_wire_pub_sub extends $mol_wire_pub {
1066
+ pub_from = 0;
1067
+ cursor = $mol_wire_cursor.stale;
1068
+ get temp() {
1069
+ return false;
1070
+ }
1071
+ get pub_list() {
1072
+ const res = [];
1073
+ const max = this.cursor >= 0 ? this.cursor : this.sub_from;
1074
+ for (let i = this.pub_from; i < max; i += 2) {
1075
+ if (this.data[i])
1076
+ res.push(this.data[i]);
1537
1077
  }
1538
- const style = `color:${color};font-weight:bolder`;
1539
- this.console[level](tpl.trim(), style, ...[].concat(...chunks));
1540
- const self = this;
1541
- return () => self.console.groupEnd();
1542
- };
1543
- }
1544
- $.$mol_log3_web_make = $mol_log3_web_make;
1545
- $.$mol_log3_come = $mol_log3_web_make('info', 'royalblue');
1546
- $.$mol_log3_done = $mol_log3_web_make('info', 'forestgreen');
1547
- $.$mol_log3_fail = $mol_log3_web_make('error', 'orangered');
1548
- $.$mol_log3_warn = $mol_log3_web_make('warn', 'goldenrod');
1549
- $.$mol_log3_rise = $mol_log3_web_make('log', 'magenta');
1550
- $.$mol_log3_area = $mol_log3_web_make('group', 'cyan');
1551
- })($ || ($ = {}));
1552
-
1553
- ;
1554
- "use strict";
1555
- var $;
1556
- (function ($) {
1557
- class $mol_wire_task extends $mol_wire_fiber {
1558
- static getter(task) {
1559
- return function $mol_wire_task_get(host, args) {
1560
- const sub = $mol_wire_auto();
1561
- const existen = sub?.track_next();
1562
- let cause = '';
1563
- reuse: if (existen) {
1564
- if (!existen.temp)
1565
- break reuse;
1566
- if (existen.task !== task) {
1567
- cause = 'task';
1568
- break reuse;
1569
- }
1570
- if (existen.host !== host) {
1571
- cause = 'host';
1572
- break reuse;
1573
- }
1574
- if (!$mol_compare_deep(existen.args, args)) {
1575
- cause = 'args';
1576
- break reuse;
1078
+ return res;
1079
+ }
1080
+ track_on() {
1081
+ this.cursor = this.pub_from;
1082
+ const sub = $mol_wire_auto();
1083
+ $mol_wire_auto(this);
1084
+ return sub;
1085
+ }
1086
+ promote() {
1087
+ if (this.cursor >= this.pub_from) {
1088
+ $mol_fail(new Error('Circular subscription'));
1089
+ }
1090
+ super.promote();
1091
+ }
1092
+ track_next(pub) {
1093
+ if (this.cursor < 0)
1094
+ $mol_fail(new Error('Promo to non begun sub'));
1095
+ if (this.cursor < this.sub_from) {
1096
+ const next = this.data[this.cursor];
1097
+ if (pub === undefined)
1098
+ return next ?? null;
1099
+ if (next === pub) {
1100
+ this.cursor += 2;
1101
+ return next;
1102
+ }
1103
+ if (next) {
1104
+ if (this.sub_from < this.data.length) {
1105
+ this.peer_move(this.sub_from, this.data.length);
1577
1106
  }
1578
- return existen;
1107
+ this.peer_move(this.cursor, this.sub_from);
1108
+ this.sub_from += 2;
1579
1109
  }
1580
- const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
1581
- const next = new $mol_wire_task(key, task, host, args);
1582
- if (existen?.temp) {
1583
- $$.$mol_log3_warn({
1584
- place: '$mol_wire_task',
1585
- message: `Different ${cause} on restart`,
1586
- sub,
1587
- prev: existen,
1588
- next,
1589
- hint: 'Maybe required additional memoization',
1590
- });
1110
+ }
1111
+ else {
1112
+ if (pub === undefined)
1113
+ return null;
1114
+ if (this.sub_from < this.data.length) {
1115
+ this.peer_move(this.sub_from, this.data.length);
1591
1116
  }
1592
- return next;
1593
- };
1117
+ this.sub_from += 2;
1118
+ }
1119
+ this.data[this.cursor] = pub;
1120
+ this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
1121
+ this.cursor += 2;
1122
+ return pub;
1123
+ }
1124
+ track_off(sub) {
1125
+ $mol_wire_auto(sub);
1126
+ if (this.cursor < 0) {
1127
+ $mol_fail(new Error('End of non begun sub'));
1128
+ }
1129
+ for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
1130
+ const pub = this.data[cursor];
1131
+ pub.fresh();
1132
+ }
1133
+ this.cursor = $mol_wire_cursor.fresh;
1134
+ }
1135
+ pub_off(sub_pos) {
1136
+ this.data[sub_pos] = undefined;
1137
+ this.data[sub_pos + 1] = undefined;
1138
+ }
1139
+ destructor() {
1140
+ for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
1141
+ const sub = this.data[cursor];
1142
+ const pos = this.data[cursor + 1];
1143
+ sub.pub_off(pos);
1144
+ }
1145
+ this.data.length = this.sub_from;
1146
+ this.cursor = this.pub_from;
1147
+ this.track_cut();
1148
+ this.cursor = $mol_wire_cursor.stale;
1149
+ }
1150
+ track_cut() {
1151
+ if (this.cursor < this.pub_from) {
1152
+ $mol_fail(new Error('Cut of non begun sub'));
1153
+ }
1154
+ let end = this.data.length;
1155
+ for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
1156
+ const pub = this.data[cursor];
1157
+ pub?.sub_off(this.data[cursor + 1]);
1158
+ end -= 2;
1159
+ if (this.sub_from <= end)
1160
+ this.peer_move(end, cursor);
1161
+ }
1162
+ this.data.length = end;
1163
+ this.sub_from = this.cursor;
1594
1164
  }
1595
- get temp() {
1596
- return true;
1165
+ complete() { }
1166
+ complete_pubs() {
1167
+ const limit = this.cursor < 0 ? this.sub_from : this.cursor;
1168
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1169
+ const pub = this.data[cursor];
1170
+ if (pub?.incompleted)
1171
+ return;
1172
+ }
1173
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1174
+ const pub = this.data[cursor];
1175
+ pub?.complete();
1176
+ }
1597
1177
  }
1598
- complete() {
1599
- if ($mol_promise_like(this.cache))
1178
+ absorb(quant = $mol_wire_cursor.stale, pos = -1) {
1179
+ if (this.cursor === $mol_wire_cursor.final)
1600
1180
  return;
1601
- this.destructor();
1181
+ if (this.cursor >= quant)
1182
+ return;
1183
+ this.cursor = quant;
1184
+ this.emit($mol_wire_cursor.doubt);
1602
1185
  }
1603
- put(next) {
1604
- const prev = this.cache;
1605
- this.cache = next;
1606
- if ($mol_promise_like(next)) {
1607
- this.cursor = $mol_wire_cursor.fresh;
1608
- if (next !== prev)
1609
- this.emit();
1610
- if ($mol_owning_catch(this, next)) {
1611
- try {
1612
- next[Symbol.toStringTag] = this[Symbol.toStringTag];
1613
- }
1614
- catch {
1615
- Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
1616
- }
1617
- }
1618
- return next;
1619
- }
1620
- this.cursor = $mol_wire_cursor.final;
1621
- if (this.sub_empty)
1622
- this.destructor();
1623
- else if (next !== prev)
1624
- this.emit();
1625
- return next;
1186
+ [$mol_dev_format_head]() {
1187
+ return $mol_dev_format_native(this);
1626
1188
  }
1627
- destructor() {
1628
- super.destructor();
1629
- this.cursor = $mol_wire_cursor.final;
1189
+ get pub_empty() {
1190
+ return this.sub_from === this.pub_from;
1630
1191
  }
1631
1192
  }
1632
- $.$mol_wire_task = $mol_wire_task;
1193
+ $.$mol_wire_pub_sub = $mol_wire_pub_sub;
1633
1194
  })($ || ($ = {}));
1634
1195
 
1635
1196
  ;
1636
1197
  "use strict";
1637
1198
  var $;
1638
1199
  (function ($) {
1639
- function $mol_wire_method(host, field, descr) {
1640
- if (!descr)
1641
- descr = Reflect.getOwnPropertyDescriptor(host, field);
1642
- const orig = descr?.value ?? host[field];
1643
- const sup = Reflect.getPrototypeOf(host);
1644
- if (typeof sup[field] === 'function') {
1645
- Object.defineProperty(orig, 'name', { value: sup[field].name });
1200
+ class $mol_after_tick extends $mol_object2 {
1201
+ task;
1202
+ static promise = null;
1203
+ cancelled = false;
1204
+ constructor(task) {
1205
+ super();
1206
+ this.task = task;
1207
+ if (!$mol_after_tick.promise)
1208
+ $mol_after_tick.promise = Promise.resolve().then(() => {
1209
+ $mol_after_tick.promise = null;
1210
+ });
1211
+ $mol_after_tick.promise.then(() => {
1212
+ if (this.cancelled)
1213
+ return;
1214
+ task();
1215
+ });
1216
+ }
1217
+ destructor() {
1218
+ this.cancelled = true;
1646
1219
  }
1647
- const temp = $mol_wire_task.getter(orig);
1648
- const value = function (...args) {
1649
- const fiber = temp(this ?? null, args);
1650
- return fiber.sync();
1651
- };
1652
- Object.defineProperty(value, 'name', { value: orig.name + ' ' });
1653
- Object.assign(value, { orig });
1654
- const descr2 = { ...descr, value };
1655
- Reflect.defineProperty(host, field, descr2);
1656
- return descr2;
1657
- }
1658
- $.$mol_wire_method = $mol_wire_method;
1659
- })($ || ($ = {}));
1660
-
1661
- ;
1662
- "use strict";
1663
-
1664
- ;
1665
- "use strict";
1666
-
1667
- ;
1668
- "use strict";
1669
- var $;
1670
- (function ($) {
1671
- const catched = new WeakSet();
1672
- function $mol_fail_catch(error) {
1673
- if (typeof error !== 'object')
1674
- return false;
1675
- if ($mol_promise_like(error))
1676
- $mol_fail_hidden(error);
1677
- if (catched.has(error))
1678
- return false;
1679
- catched.add(error);
1680
- return true;
1681
1220
  }
1682
- $.$mol_fail_catch = $mol_fail_catch;
1221
+ $.$mol_after_tick = $mol_after_tick;
1683
1222
  })($ || ($ = {}));
1684
1223
 
1685
1224
  ;
1686
1225
  "use strict";
1687
1226
  var $;
1688
1227
  (function ($) {
1689
- function $mol_try(handler) {
1228
+ function $mol_promise_like(val) {
1690
1229
  try {
1691
- return handler();
1692
- }
1693
- catch (error) {
1694
- console.error(error);
1695
- return error;
1230
+ return val && typeof val === 'object' && 'then' in val && typeof val.then === 'function';
1696
1231
  }
1697
- }
1698
- $.$mol_try = $mol_try;
1699
- })($ || ($ = {}));
1700
-
1701
- ;
1702
- "use strict";
1703
- var $;
1704
- (function ($) {
1705
- let error;
1706
- let result;
1707
- let handler;
1708
- function $mol_try_web(handler2) {
1709
- handler = handler2;
1710
- error = undefined;
1711
- result = undefined;
1712
- window.dispatchEvent(new Event('$mol_try'));
1713
- const error2 = error;
1714
- const result2 = result;
1715
- error = undefined;
1716
- result = undefined;
1717
- return error2 || result2;
1718
- }
1719
- $.$mol_try_web = $mol_try_web;
1720
- $.$mol_try = $mol_try_web;
1721
- self.addEventListener('$mol_try', (event) => {
1722
- result = handler();
1723
- }, true);
1724
- self.addEventListener('error', (event) => {
1725
- error = event.error;
1726
- }, true);
1727
- })($ || ($ = {}));
1728
-
1729
- ;
1730
- "use strict";
1731
- var $;
1732
- (function ($) {
1733
- function $mol_fail_log(error) {
1734
- if ($mol_promise_like(error))
1735
- return false;
1736
- if (!$mol_fail_catch(error))
1232
+ catch {
1737
1233
  return false;
1738
- $mol_try(() => { $mol_fail_hidden(error); });
1739
- return true;
1234
+ }
1740
1235
  }
1741
- $.$mol_fail_log = $mol_fail_log;
1236
+ $.$mol_promise_like = $mol_promise_like;
1742
1237
  })($ || ($ = {}));
1743
1238
 
1744
1239
  ;
1745
1240
  "use strict";
1746
1241
  var $;
1747
1242
  (function ($) {
1748
- class $mol_wire_atom extends $mol_wire_fiber {
1749
- static solo(host, task) {
1750
- const field = task.name + '()';
1751
- const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1752
- if (existen)
1753
- return existen;
1754
- const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1755
- const key = prefix + ('.' + task.name + '<>');
1756
- const fiber = new $mol_wire_atom(key, task, host, []);
1757
- (host ?? task)[field] = fiber;
1758
- return fiber;
1759
- }
1760
- static plex(host, task, key) {
1761
- const field = task.name + '()';
1762
- let dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1763
- const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1764
- const key_str = $mol_key(key);
1765
- if (dict) {
1766
- const existen = dict.get(key_str);
1767
- if (existen)
1768
- return existen;
1769
- }
1770
- else {
1771
- dict = (host ?? task)[field] = new Map();
1772
- }
1773
- const id = prefix + ('.' + task.name) + ('<' + key_str.replace(/^"|"$/g, "'") + '>');
1774
- const fiber = new $mol_wire_atom(id, task, host, [key]);
1775
- dict.set(key_str, fiber);
1776
- return fiber;
1243
+ const wrappers = new WeakMap();
1244
+ class $mol_wire_fiber extends $mol_wire_pub_sub {
1245
+ task;
1246
+ host;
1247
+ static warm = true;
1248
+ static planning = new Set();
1249
+ static reaping = new Set();
1250
+ static plan_task = null;
1251
+ static plan() {
1252
+ if (this.plan_task)
1253
+ return;
1254
+ this.plan_task = new $mol_after_tick(() => {
1255
+ try {
1256
+ this.sync();
1257
+ }
1258
+ finally {
1259
+ $mol_wire_fiber.plan_task = null;
1260
+ }
1261
+ });
1777
1262
  }
1778
- static watching = new Set();
1779
- static watcher = null;
1780
- static watch() {
1781
- $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
1782
- for (const atom of $mol_wire_atom.watching) {
1783
- if (atom.cursor === $mol_wire_cursor.final) {
1784
- $mol_wire_atom.watching.delete(atom);
1263
+ static sync() {
1264
+ while (this.planning.size) {
1265
+ for (const fiber of this.planning) {
1266
+ this.planning.delete(fiber);
1267
+ if (fiber.cursor >= 0)
1268
+ continue;
1269
+ if (fiber.cursor === $mol_wire_cursor.final)
1270
+ continue;
1271
+ fiber.fresh();
1785
1272
  }
1786
- else {
1787
- atom.cursor = $mol_wire_cursor.stale;
1788
- atom.fresh();
1273
+ }
1274
+ while (this.reaping.size) {
1275
+ const fibers = this.reaping;
1276
+ this.reaping = new Set;
1277
+ for (const fiber of fibers) {
1278
+ if (!fiber.sub_empty)
1279
+ continue;
1280
+ fiber.destructor();
1789
1281
  }
1790
1282
  }
1791
1283
  }
1792
- watch() {
1793
- if (!$mol_wire_atom.watcher) {
1794
- $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
1795
- }
1796
- $mol_wire_atom.watching.add(this);
1284
+ cache = undefined;
1285
+ get args() {
1286
+ return this.data.slice(0, this.pub_from);
1797
1287
  }
1798
- resync(args) {
1799
- for (let cursor = this.pub_from; cursor < this.sub_from; cursor += 2) {
1800
- const pub = this.data[cursor];
1801
- if (pub && pub instanceof $mol_wire_task) {
1802
- pub.destructor();
1803
- }
1804
- }
1805
- return this.put(this.task.call(this.host, ...args));
1288
+ result() {
1289
+ if ($mol_promise_like(this.cache))
1290
+ return;
1291
+ if (this.cache instanceof Error)
1292
+ return;
1293
+ return this.cache;
1806
1294
  }
1807
- once() {
1808
- return this.sync();
1295
+ get incompleted() {
1296
+ return $mol_promise_like(this.cache);
1809
1297
  }
1810
- channel() {
1811
- return Object.assign((next) => {
1812
- if (next !== undefined)
1813
- return this.resync([...this.args, next]);
1814
- if (!$mol_wire_fiber.warm)
1815
- return this.result();
1816
- if ($mol_wire_auto()?.temp) {
1817
- return this.once();
1298
+ field() {
1299
+ return this.task.name + '()';
1300
+ }
1301
+ constructor(id, task, host, args) {
1302
+ super(id);
1303
+ this.task = task;
1304
+ this.host = host;
1305
+ if (args)
1306
+ this.data.push(...args);
1307
+ this.pub_from = this.sub_from = args?.length ?? 0;
1308
+ }
1309
+ plan() {
1310
+ $mol_wire_fiber.planning.add(this);
1311
+ $mol_wire_fiber.plan();
1312
+ return this;
1313
+ }
1314
+ reap() {
1315
+ $mol_wire_fiber.reaping.add(this);
1316
+ $mol_wire_fiber.plan();
1317
+ }
1318
+ toString() {
1319
+ return this[Symbol.toStringTag];
1320
+ }
1321
+ toJSON() {
1322
+ return this[Symbol.toStringTag];
1323
+ }
1324
+ [$mol_dev_format_head]() {
1325
+ const cursor = {
1326
+ [$mol_wire_cursor.stale]: '🔴',
1327
+ [$mol_wire_cursor.doubt]: '🟡',
1328
+ [$mol_wire_cursor.fresh]: '🟢',
1329
+ [$mol_wire_cursor.final]: '🔵',
1330
+ }[this.cursor] ?? this.cursor.toString();
1331
+ return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
1332
+ ? $mol_dev_format_shade(cursor)
1333
+ : $mol_dev_format_shade(this[Symbol.toStringTag], cursor), $mol_dev_format_auto(this.cache));
1334
+ }
1335
+ [$mol_dev_format_body]() { return null; }
1336
+ get $() {
1337
+ return (this.host ?? this.task)['$'];
1338
+ }
1339
+ emit(quant = $mol_wire_cursor.stale) {
1340
+ if (this.sub_empty)
1341
+ this.plan();
1342
+ else
1343
+ super.emit(quant);
1344
+ }
1345
+ fresh() {
1346
+ if (this.cursor === $mol_wire_cursor.fresh)
1347
+ return;
1348
+ if (this.cursor === $mol_wire_cursor.final)
1349
+ return;
1350
+ check: if (this.cursor === $mol_wire_cursor.doubt) {
1351
+ for (let i = this.pub_from; i < this.sub_from; i += 2) {
1352
+ ;
1353
+ this.data[i]?.fresh();
1354
+ if (this.cursor !== $mol_wire_cursor.doubt)
1355
+ break check;
1356
+ }
1357
+ this.cursor = $mol_wire_cursor.fresh;
1358
+ return;
1359
+ }
1360
+ const bu = this.track_on();
1361
+ let result;
1362
+ try {
1363
+ switch (this.pub_from) {
1364
+ case 0:
1365
+ result = this.task.call(this.host);
1366
+ break;
1367
+ case 1:
1368
+ result = this.task.call(this.host, this.data[0]);
1369
+ break;
1370
+ default:
1371
+ result = this.task.call(this.host, ...this.args);
1372
+ break;
1373
+ }
1374
+ if ($mol_promise_like(result)) {
1375
+ if (wrappers.has(result)) {
1376
+ result = wrappers.get(result).then(a => a);
1377
+ }
1378
+ else {
1379
+ const put = (res) => {
1380
+ if (this.cache === result)
1381
+ this.put(res);
1382
+ return res;
1383
+ };
1384
+ wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
1385
+ wrappers.set(result, result);
1386
+ const error = new Error(`Promise in ${this}`);
1387
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
1388
+ }
1389
+ }
1390
+ }
1391
+ catch (error) {
1392
+ if (error instanceof Error || $mol_promise_like(error)) {
1393
+ result = error;
1818
1394
  }
1819
1395
  else {
1820
- return this.sync();
1396
+ result = new Error(String(error), { cause: error });
1821
1397
  }
1822
- }, { atom: this });
1398
+ if ($mol_promise_like(result)) {
1399
+ if (wrappers.has(result)) {
1400
+ result = wrappers.get(result);
1401
+ }
1402
+ else {
1403
+ const put = (v) => {
1404
+ if (this.cache === result)
1405
+ this.absorb();
1406
+ return v;
1407
+ };
1408
+ wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
1409
+ const error = new Error(`Promise in ${this}`);
1410
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
1411
+ }
1412
+ }
1413
+ }
1414
+ if (!$mol_promise_like(result)) {
1415
+ this.track_cut();
1416
+ }
1417
+ this.track_off(bu);
1418
+ this.put(result);
1419
+ return this;
1823
1420
  }
1824
- destructor() {
1825
- super.destructor();
1826
- if (this.pub_from === 0) {
1827
- ;
1828
- (this.host ?? this.task)[this.field()] = null;
1421
+ refresh() {
1422
+ this.cursor = $mol_wire_cursor.stale;
1423
+ this.fresh();
1424
+ }
1425
+ sync() {
1426
+ if (!$mol_wire_fiber.warm) {
1427
+ return this.result();
1829
1428
  }
1830
- else {
1831
- const key = $mol_key(this.args[0]);
1832
- const map = (this.host ?? this.task)[this.field()];
1833
- if (!map.has(key))
1834
- this.$.$mol_log3_warn({
1835
- place: this,
1836
- message: 'Absent key on destruction',
1837
- hint: 'Check for $mol_key(key) is not changed',
1838
- });
1839
- map.delete(key);
1429
+ this.promote();
1430
+ this.fresh();
1431
+ if (this.cache instanceof Error) {
1432
+ return $mol_fail_hidden(this.cache);
1433
+ }
1434
+ if ($mol_promise_like(this.cache)) {
1435
+ return $mol_fail_hidden(this.cache);
1840
1436
  }
1437
+ return this.cache;
1841
1438
  }
1842
- put(next) {
1843
- const prev = this.cache;
1844
- update: if (next !== prev) {
1845
- try {
1846
- if ($mol_compare_deep(prev, next))
1847
- break update;
1848
- }
1849
- catch (error) {
1850
- $mol_fail_log(error);
1851
- }
1852
- if ($mol_owning_check(this, prev)) {
1853
- prev.destructor();
1439
+ async async_raw() {
1440
+ while (true) {
1441
+ this.fresh();
1442
+ if (this.cache instanceof Error) {
1443
+ $mol_fail_hidden(this.cache);
1854
1444
  }
1855
- if ($mol_owning_catch(this, next)) {
1856
- try {
1857
- next[Symbol.toStringTag] = this[Symbol.toStringTag];
1858
- }
1859
- catch {
1860
- Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
1861
- }
1445
+ if (!$mol_promise_like(this.cache))
1446
+ return this.cache;
1447
+ await Promise.race([this.cache, this.step()]);
1448
+ if (!$mol_promise_like(this.cache))
1449
+ return this.cache;
1450
+ if (this.cursor === $mol_wire_cursor.final) {
1451
+ await new Promise(() => { });
1862
1452
  }
1863
- if (!this.sub_empty)
1864
- this.emit();
1865
1453
  }
1866
- this.cache = next;
1867
- this.cursor = $mol_wire_cursor.fresh;
1868
- if ($mol_promise_like(next))
1869
- return next;
1870
- this.complete_pubs();
1871
- return next;
1872
1454
  }
1873
- }
1874
- __decorate([
1875
- $mol_wire_method
1876
- ], $mol_wire_atom.prototype, "resync", null);
1877
- __decorate([
1878
- $mol_wire_method
1879
- ], $mol_wire_atom.prototype, "once", null);
1880
- $.$mol_wire_atom = $mol_wire_atom;
1881
- })($ || ($ = {}));
1882
-
1883
- ;
1884
- "use strict";
1885
- var $;
1886
- (function ($) {
1887
- function $mol_wire_solo(host, field, descr) {
1888
- if (!descr)
1889
- descr = Reflect.getOwnPropertyDescriptor(host, field);
1890
- const orig = descr?.value ?? host[field];
1891
- const sup = Reflect.getPrototypeOf(host);
1892
- if (typeof sup[field] === 'function') {
1893
- Object.defineProperty(orig, 'name', { value: sup[field].name });
1455
+ async() {
1456
+ const promise = this.async_raw();
1457
+ if (!promise.destructor)
1458
+ promise.destructor = () => this.destructor();
1459
+ return promise;
1460
+ }
1461
+ step() {
1462
+ return new Promise(done => {
1463
+ const sub = new $mol_wire_pub_sub;
1464
+ const prev = sub.track_on();
1465
+ sub.track_next(this);
1466
+ sub.track_off(prev);
1467
+ sub.absorb = () => {
1468
+ done(null);
1469
+ setTimeout(() => sub.destructor());
1470
+ };
1471
+ });
1894
1472
  }
1895
- const descr2 = {
1896
- ...descr,
1897
- value: function (...args) {
1898
- let atom = $mol_wire_atom.solo(this, orig);
1899
- if ((args.length === 0) || (args[0] === undefined)) {
1900
- if (!$mol_wire_fiber.warm)
1901
- return atom.result();
1902
- if ($mol_wire_auto()?.temp) {
1903
- return atom.once();
1904
- }
1905
- else {
1906
- return atom.sync();
1907
- }
1473
+ destructor() {
1474
+ super.destructor();
1475
+ $mol_wire_fiber.planning.delete(this);
1476
+ if (!$mol_owning_check(this, this.cache))
1477
+ return;
1478
+ try {
1479
+ this.cache.destructor();
1480
+ }
1481
+ catch (result) {
1482
+ if ($mol_promise_like(result)) {
1483
+ const error = new Error(`Promise in ${this}.destructor()`);
1484
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
1908
1485
  }
1909
- return atom.resync(args);
1486
+ $mol_fail_hidden(result);
1910
1487
  }
1911
- };
1912
- Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
1913
- Reflect.defineProperty(descr2.value, 'length', { value: orig.length });
1914
- Object.assign(descr2.value, { orig });
1915
- Reflect.defineProperty(host, field, descr2);
1916
- return descr2;
1488
+ }
1917
1489
  }
1918
- $.$mol_wire_solo = $mol_wire_solo;
1490
+ $.$mol_wire_fiber = $mol_wire_fiber;
1919
1491
  })($ || ($ = {}));
1920
1492
 
1921
1493
  ;
1922
1494
  "use strict";
1923
1495
  var $;
1924
1496
  (function ($) {
1925
- function $mol_wire_plex(host, field, descr) {
1926
- if (!descr)
1927
- descr = Reflect.getOwnPropertyDescriptor(host, field);
1928
- const orig = descr?.value ?? host[field];
1929
- const sup = Reflect.getPrototypeOf(host);
1930
- if (typeof sup[field] === 'function') {
1931
- Object.defineProperty(orig, 'name', { value: sup[field].name });
1497
+ const TypedArray = Object.getPrototypeOf(Uint8Array);
1498
+ function $mol_key(value) {
1499
+ primitives: {
1500
+ if (typeof value === 'bigint')
1501
+ return value.toString() + 'n';
1502
+ if (typeof value === 'symbol')
1503
+ return `Symbol(${value.description})`;
1504
+ if (!value)
1505
+ return JSON.stringify(value);
1506
+ if (typeof value !== 'object' && typeof value !== 'function')
1507
+ return JSON.stringify(value);
1932
1508
  }
1933
- const descr2 = {
1934
- ...descr,
1935
- value: function (...args) {
1936
- let atom = $mol_wire_atom.plex(this, orig, args[0]);
1937
- if ((args.length === 1) || (args[1] === undefined)) {
1938
- if (!$mol_wire_fiber.warm)
1939
- return atom.result();
1940
- if ($mol_wire_auto()?.temp) {
1941
- return atom.once();
1942
- }
1943
- else {
1944
- return atom.sync();
1945
- }
1946
- }
1947
- return atom.resync(args);
1509
+ caching: {
1510
+ let key = $mol_key_store.get(value);
1511
+ if (key)
1512
+ return key;
1513
+ }
1514
+ objects: {
1515
+ if (value instanceof TypedArray) {
1516
+ return `${value[Symbol.toStringTag]}([${[...value].map(v => $mol_key(v))}])`;
1948
1517
  }
1949
- };
1950
- Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
1951
- Reflect.defineProperty(descr2.value, 'length', { value: orig.length });
1952
- Object.assign(descr2.value, { orig });
1953
- Reflect.defineProperty(host, field, descr2);
1954
- return descr2;
1518
+ if (Array.isArray(value))
1519
+ return `[${value.map(v => $mol_key(v))}]`;
1520
+ if (value instanceof RegExp)
1521
+ return value.toString();
1522
+ if (value instanceof Date)
1523
+ return `Date(${value.valueOf()})`;
1524
+ }
1525
+ structures: {
1526
+ const proto = Reflect.getPrototypeOf(value);
1527
+ if (!proto || !Reflect.getPrototypeOf(proto)) {
1528
+ return `{${Object.entries(value).map(([k, v]) => JSON.stringify(k) + ':' + $mol_key(v))}}`;
1529
+ }
1530
+ }
1531
+ handlers: {
1532
+ if ($mol_key_handle in value) {
1533
+ return value[$mol_key_handle]();
1534
+ }
1535
+ }
1536
+ containers: {
1537
+ const key = JSON.stringify('#' + $mol_guid());
1538
+ $mol_key_store.set(value, key);
1539
+ return key;
1540
+ }
1955
1541
  }
1956
- $.$mol_wire_plex = $mol_wire_plex;
1957
- })($ || ($ = {}));
1958
-
1959
- ;
1960
- "use strict";
1961
- var $;
1962
- (function ($) {
1963
- $.$mol_mem = $mol_wire_solo;
1964
- $.$mol_mem_key = $mol_wire_plex;
1542
+ $.$mol_key = $mol_key;
1965
1543
  })($ || ($ = {}));
1966
1544
 
1967
1545
  ;
1968
1546
  "use strict";
1969
1547
  var $;
1970
1548
  (function ($) {
1971
- $.$mol_action = $mol_wire_method;
1549
+ class $mol_after_frame extends $mol_object2 {
1550
+ task;
1551
+ static _promise = null;
1552
+ static get promise() {
1553
+ if (this._promise)
1554
+ return this._promise;
1555
+ return this._promise = new Promise(done => {
1556
+ const complete = () => {
1557
+ this._promise = null;
1558
+ done();
1559
+ };
1560
+ if (typeof requestAnimationFrame === 'function') {
1561
+ requestAnimationFrame(complete);
1562
+ }
1563
+ else {
1564
+ setTimeout(complete, 16);
1565
+ }
1566
+ });
1567
+ }
1568
+ cancelled = false;
1569
+ promise;
1570
+ constructor(task) {
1571
+ super();
1572
+ this.task = task;
1573
+ this.promise = $mol_after_frame.promise.then(() => {
1574
+ if (this.cancelled)
1575
+ return;
1576
+ task();
1577
+ });
1578
+ }
1579
+ destructor() {
1580
+ this.cancelled = true;
1581
+ }
1582
+ }
1583
+ $.$mol_after_frame = $mol_after_frame;
1972
1584
  })($ || ($ = {}));
1973
1585
 
1974
1586
  ;
1975
1587
  "use strict";
1976
1588
  var $;
1977
1589
  (function ($) {
1978
- class $mol_state_arg extends $mol_object {
1979
- prefix;
1980
- static href(next) {
1981
- if (next === undefined) {
1982
- next = $mol_dom.location.href;
1983
- }
1984
- else if (!/^about:srcdoc/.test(next)) {
1985
- new $mol_after_frame(() => {
1986
- const next = this.href();
1987
- const prev = $mol_dom.location.href;
1988
- if (next === prev)
1989
- return;
1990
- const history = $mol_dom.history;
1991
- history.replaceState(history.state, $mol_dom.document.title, next);
1992
- });
1993
- }
1994
- if ($mol_dom.parent && ($mol_dom.parent !== $mol_dom.self)) {
1995
- $mol_dom.parent.postMessage(['hashchange', next], '*');
1996
- }
1997
- return next;
1998
- }
1999
- static href_normal() {
2000
- return this.link({});
2001
- }
2002
- static href_absolute() {
2003
- return new URL(this.href(), $mol_dom.location.href).toString();
2004
- }
2005
- static dict(next) {
2006
- var href = this.href(next && this.make_link(next)).split(/#!?/)[1] || '';
2007
- var chunks = href.split(this.separator);
2008
- var params = {};
2009
- chunks.forEach(chunk => {
2010
- if (!chunk)
2011
- return;
2012
- var vals = chunk.split('=').map(decodeURIComponent);
2013
- params[vals.shift()] = vals.join('=');
2014
- });
2015
- return params;
2016
- }
2017
- static dict_cut(except) {
2018
- const dict = this.dict();
2019
- const cut = {};
2020
- for (const key in dict) {
2021
- if (except.indexOf(key) >= 0)
2022
- break;
2023
- cut[key] = dict[key];
2024
- }
2025
- return cut;
2026
- }
2027
- static value(key, next) {
2028
- const nextDict = (next === void 0) ? void 0 : { ...this.dict(), [key]: next };
2029
- const next2 = this.dict(nextDict)[key];
2030
- return (next2 == null) ? null : next2;
2031
- }
2032
- static link(next) {
2033
- return this.make_link({
2034
- ...this.dict_cut(Object.keys(next)),
2035
- ...next,
2036
- });
2037
- }
2038
- static prolog = '!';
2039
- static separator = '/';
2040
- static make_link(next) {
2041
- const chunks = [];
2042
- for (let key in next) {
2043
- if (null == next[key])
2044
- continue;
2045
- const val = next[key];
2046
- chunks.push([key].concat(val ? [val] : []).map(this.encode).join('='));
2047
- }
2048
- return new URL('#' + this.prolog + chunks.join(this.separator), this.href_absolute()).toString();
2049
- }
2050
- static commit() {
2051
- $mol_dom.history.pushState($mol_dom.history.state, $mol_dom.document.title, this.href());
2052
- }
2053
- static go(next) {
2054
- $mol_dom.location.href = this.link(next);
2055
- }
2056
- static encode(str) {
2057
- return encodeURIComponent(str).replace(/\(/g, '%28').replace(/\)/g, '%29');
2058
- }
2059
- constructor(prefix = '') {
2060
- super();
2061
- this.prefix = prefix;
2062
- }
2063
- value(key, next) {
2064
- return this.constructor.value(this.prefix + key, next);
1590
+ $.$mol_compare_deep_cache = new WeakMap();
1591
+ function $mol_compare_deep(left, right) {
1592
+ if (Object.is(left, right))
1593
+ return true;
1594
+ if (left === null)
1595
+ return false;
1596
+ if (right === null)
1597
+ return false;
1598
+ if (typeof left !== 'object')
1599
+ return false;
1600
+ if (typeof right !== 'object')
1601
+ return false;
1602
+ const left_proto = Reflect.getPrototypeOf(left);
1603
+ const right_proto = Reflect.getPrototypeOf(right);
1604
+ if (left_proto !== right_proto)
1605
+ return false;
1606
+ if (left instanceof Boolean)
1607
+ return Object.is(left.valueOf(), right['valueOf']());
1608
+ if (left instanceof Number)
1609
+ return Object.is(left.valueOf(), right['valueOf']());
1610
+ if (left instanceof String)
1611
+ return Object.is(left.valueOf(), right['valueOf']());
1612
+ if (left instanceof Date)
1613
+ return Object.is(left.valueOf(), right['valueOf']());
1614
+ if (left instanceof RegExp)
1615
+ return left.source === right.source && left.flags === right.flags;
1616
+ if (left instanceof Error)
1617
+ return left.message === right.message && $mol_compare_deep(left.stack, right.stack);
1618
+ let left_cache = $.$mol_compare_deep_cache.get(left);
1619
+ if (left_cache) {
1620
+ const right_cache = left_cache.get(right);
1621
+ if (typeof right_cache === 'boolean')
1622
+ return right_cache;
2065
1623
  }
2066
- sub(postfix) {
2067
- return new this.constructor(this.prefix + postfix + '.');
1624
+ else {
1625
+ left_cache = new WeakMap();
1626
+ $.$mol_compare_deep_cache.set(left, left_cache);
2068
1627
  }
2069
- link(next) {
2070
- var prefix = this.prefix;
2071
- var dict = {};
2072
- for (var key in next) {
2073
- dict[prefix + key] = next[key];
2074
- }
2075
- return this.constructor.link(dict);
1628
+ left_cache.set(right, true);
1629
+ let result;
1630
+ try {
1631
+ if (!left_proto)
1632
+ result = compare_pojo(left, right);
1633
+ else if (!Reflect.getPrototypeOf(left_proto))
1634
+ result = compare_pojo(left, right);
1635
+ else if (Symbol.toPrimitive in left)
1636
+ result = compare_primitive(left, right);
1637
+ else if (Array.isArray(left))
1638
+ result = compare_array(left, right);
1639
+ else if (left instanceof Set)
1640
+ result = compare_set(left, right);
1641
+ else if (left instanceof Map)
1642
+ result = compare_map(left, right);
1643
+ else if (ArrayBuffer.isView(left))
1644
+ result = compare_buffer(left, right);
1645
+ else if (Symbol.iterator in left)
1646
+ result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
1647
+ else
1648
+ result = false;
2076
1649
  }
1650
+ finally {
1651
+ left_cache.set(right, result);
1652
+ }
1653
+ return result;
2077
1654
  }
2078
- __decorate([
2079
- $mol_mem
2080
- ], $mol_state_arg, "href", null);
2081
- __decorate([
2082
- $mol_mem
2083
- ], $mol_state_arg, "href_normal", null);
2084
- __decorate([
2085
- $mol_mem
2086
- ], $mol_state_arg, "href_absolute", null);
2087
- __decorate([
2088
- $mol_mem
2089
- ], $mol_state_arg, "dict", null);
2090
- __decorate([
2091
- $mol_mem_key
2092
- ], $mol_state_arg, "dict_cut", null);
2093
- __decorate([
2094
- $mol_mem_key
2095
- ], $mol_state_arg, "value", null);
2096
- __decorate([
2097
- $mol_mem_key
2098
- ], $mol_state_arg, "make_link", null);
2099
- __decorate([
2100
- $mol_action
2101
- ], $mol_state_arg, "commit", null);
2102
- __decorate([
2103
- $mol_action
2104
- ], $mol_state_arg, "go", null);
2105
- $.$mol_state_arg = $mol_state_arg;
2106
- function $mol_state_arg_change() {
2107
- $mol_state_arg.href($mol_dom.location.href);
2108
- }
2109
- self.addEventListener('hashchange', $mol_state_arg_change);
2110
- })($ || ($ = {}));
2111
-
2112
- ;
2113
- "use strict";
2114
- var $;
2115
- (function ($) {
2116
- class $mol_media extends $mol_object2 {
2117
- static match(query, next) {
2118
- if (next !== undefined)
2119
- return next;
2120
- const res = this.$.$mol_dom_context.matchMedia?.(query) ?? {};
2121
- res.onchange = () => this.match(query, res.matches);
2122
- return res.matches;
1655
+ $.$mol_compare_deep = $mol_compare_deep;
1656
+ function compare_array(left, right) {
1657
+ const len = left.length;
1658
+ if (len !== right.length)
1659
+ return false;
1660
+ for (let i = 0; i < len; ++i) {
1661
+ if (!$mol_compare_deep(left[i], right[i]))
1662
+ return false;
2123
1663
  }
1664
+ return true;
2124
1665
  }
2125
- __decorate([
2126
- $mol_mem_key
2127
- ], $mol_media, "match", null);
2128
- $.$mol_media = $mol_media;
2129
- })($ || ($ = {}));
2130
-
2131
- ;
2132
- "use strict";
2133
- var $;
2134
- (function ($) {
2135
- function $mol_wire_solid() {
2136
- let current = $mol_wire_auto();
2137
- if (current.temp)
2138
- current = current.host;
2139
- if (current.reap !== nothing) {
2140
- current?.sub_on(sub, sub.data.length);
1666
+ function compare_buffer(left, right) {
1667
+ const len = left.byteLength;
1668
+ if (len !== right.byteLength)
1669
+ return false;
1670
+ if (left instanceof DataView)
1671
+ return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, right.byteOffset, right.byteLength));
1672
+ for (let i = 0; i < len; ++i) {
1673
+ if (left[i] !== right[i])
1674
+ return false;
2141
1675
  }
2142
- current.reap = nothing;
1676
+ return true;
2143
1677
  }
2144
- $.$mol_wire_solid = $mol_wire_solid;
2145
- const nothing = () => { };
2146
- const sub = new $mol_wire_pub_sub;
2147
- })($ || ($ = {}));
2148
-
2149
- ;
2150
- "use strict";
2151
- var $;
2152
- (function ($) {
2153
- $.$mol_mem_persist = $mol_wire_solid;
2154
- })($ || ($ = {}));
2155
-
2156
- ;
2157
- "use strict";
2158
- var $;
2159
- (function ($) {
2160
- function $mol_wire_probe(task, def) {
2161
- const warm = $mol_wire_fiber.warm;
2162
- try {
2163
- $mol_wire_fiber.warm = false;
2164
- const res = task();
2165
- if (res === undefined)
2166
- return def;
2167
- return res;
1678
+ function compare_iterator(left, right) {
1679
+ while (true) {
1680
+ const left_next = left.next();
1681
+ const right_next = right.next();
1682
+ if (left_next.done !== right_next.done)
1683
+ return false;
1684
+ if (left_next.done)
1685
+ break;
1686
+ if (!$mol_compare_deep(left_next.value, right_next.value))
1687
+ return false;
2168
1688
  }
2169
- finally {
2170
- $mol_wire_fiber.warm = warm;
1689
+ return true;
1690
+ }
1691
+ function compare_set(left, right) {
1692
+ if (left.size !== right.size)
1693
+ return false;
1694
+ return compare_iterator(left.values(), right.values());
1695
+ }
1696
+ function compare_map(left, right) {
1697
+ if (left.size !== right.size)
1698
+ return false;
1699
+ return compare_iterator(left.keys(), right.keys())
1700
+ && compare_iterator(left.values(), right.values());
1701
+ }
1702
+ function compare_pojo(left, right) {
1703
+ const left_keys = Object.getOwnPropertyNames(left);
1704
+ const right_keys = Object.getOwnPropertyNames(right);
1705
+ if (!compare_array(left_keys, right_keys))
1706
+ return false;
1707
+ for (let key of left_keys) {
1708
+ if (!$mol_compare_deep(left[key], right[key]))
1709
+ return false;
1710
+ }
1711
+ const left_syms = Object.getOwnPropertySymbols(left);
1712
+ const right_syms = Object.getOwnPropertySymbols(right);
1713
+ if (!compare_array(left_syms, right_syms))
1714
+ return false;
1715
+ for (let key of left_syms) {
1716
+ if (!$mol_compare_deep(left[key], right[key]))
1717
+ return false;
2171
1718
  }
1719
+ return true;
1720
+ }
1721
+ function compare_primitive(left, right) {
1722
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
2172
1723
  }
2173
- $.$mol_wire_probe = $mol_wire_probe;
2174
- })($ || ($ = {}));
2175
-
2176
- ;
2177
- "use strict";
2178
- var $;
2179
- (function ($) {
2180
- $.$mol_mem_cached = $mol_wire_probe;
2181
1724
  })($ || ($ = {}));
2182
1725
 
2183
1726
  ;
2184
1727
  "use strict";
2185
1728
  var $;
2186
1729
  (function ($) {
2187
- const factories = new WeakMap();
2188
- function factory(val) {
2189
- let make = factories.get(val);
2190
- if (make)
2191
- return make;
2192
- make = $mol_func_name_from((...args) => new val(...args), val);
2193
- factories.set(val, make);
2194
- return make;
2195
- }
2196
- const getters = new WeakMap();
2197
- function get_prop(host, field) {
2198
- let props = getters.get(host);
2199
- let get_val = props?.[field];
2200
- if (get_val)
2201
- return get_val;
2202
- get_val = (next) => {
2203
- if (next !== undefined)
2204
- host[field] = next;
2205
- return host[field];
2206
- };
2207
- Object.defineProperty(get_val, 'name', { value: field });
2208
- if (!props) {
2209
- props = {};
2210
- getters.set(host, props);
2211
- }
2212
- props[field] = get_val;
2213
- return get_val;
2214
- }
2215
- function $mol_wire_sync(obj) {
2216
- return new Proxy(obj, {
2217
- get(obj, field) {
2218
- let val = obj[field];
2219
- const temp = $mol_wire_task.getter(typeof val === 'function' ? val : get_prop(obj, field));
2220
- if (typeof val !== 'function')
2221
- return temp(obj, []).sync();
2222
- return function $mol_wire_sync(...args) {
2223
- const fiber = temp(obj, args);
2224
- return fiber.sync();
2225
- };
2226
- },
2227
- set(obj, field, next) {
2228
- const temp = $mol_wire_task.getter(get_prop(obj, field));
2229
- temp(obj, [next]).sync();
2230
- return true;
2231
- },
2232
- construct(obj, args) {
2233
- const temp = $mol_wire_task.getter(factory(obj));
2234
- return temp(obj, args).sync();
2235
- },
2236
- apply(obj, self, args) {
2237
- const temp = $mol_wire_task.getter(obj);
2238
- return temp(self, args).sync();
2239
- },
1730
+ function $mol_log3_area_lazy(event) {
1731
+ const self = this.$;
1732
+ const stack = self.$mol_log3_stack;
1733
+ const deep = stack.length;
1734
+ let logged = false;
1735
+ stack.push(() => {
1736
+ logged = true;
1737
+ self.$mol_log3_area.call(self, event);
2240
1738
  });
1739
+ return () => {
1740
+ if (logged)
1741
+ self.console.groupEnd();
1742
+ if (stack.length > deep)
1743
+ stack.length = deep;
1744
+ };
2241
1745
  }
2242
- $.$mol_wire_sync = $mol_wire_sync;
1746
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1747
+ $.$mol_log3_stack = [];
2243
1748
  })($ || ($ = {}));
2244
1749
 
2245
1750
  ;
2246
1751
  "use strict";
2247
- var $;
2248
- (function ($) {
2249
- function $mol_wait_user_async() {
2250
- return new Promise(done => $mol_dom.addEventListener('click', function onclick() {
2251
- $mol_dom.removeEventListener('click', onclick);
2252
- done(null);
2253
- }));
2254
- }
2255
- $.$mol_wait_user_async = $mol_wait_user_async;
2256
- function $mol_wait_user() {
2257
- return this.$mol_wire_sync(this).$mol_wait_user_async();
2258
- }
2259
- $.$mol_wait_user = $mol_wait_user;
2260
- })($ || ($ = {}));
2261
1752
 
2262
1753
  ;
2263
1754
  "use strict";
2264
1755
  var $;
2265
1756
  (function ($) {
2266
- class $mol_storage extends $mol_object2 {
2267
- static native() {
2268
- return this.$.$mol_dom_context.navigator.storage ?? {
2269
- persisted: async () => false,
2270
- persist: async () => false,
2271
- estimate: async () => ({}),
2272
- getDirectory: async () => null,
2273
- };
2274
- }
2275
- static persisted(next, cache) {
2276
- $mol_mem_persist();
2277
- if (cache)
2278
- return Boolean(next);
2279
- const native = this.native();
2280
- if (next && !$mol_mem_cached(() => this.persisted())) {
2281
- this.$.$mol_wait_user_async()
2282
- .then(() => native.persist())
2283
- .then(actual => {
2284
- setTimeout(() => this.persisted(actual, 'cache'), 5000);
2285
- if (actual)
2286
- this.$.$mol_log3_done({ place: `$mol_storage`, message: `Persist: Yes` });
2287
- else
2288
- this.$.$mol_log3_fail({ place: `$mol_storage`, message: `Persist: No` });
2289
- });
1757
+ function $mol_log3_web_make(level, color) {
1758
+ return function $mol_log3_logger(event) {
1759
+ const pending = this.$mol_log3_stack.pop();
1760
+ if (pending)
1761
+ pending();
1762
+ let tpl = '%c';
1763
+ const chunks = Object.entries(event);
1764
+ for (let i = 0; i < chunks.length; ++i) {
1765
+ tpl += (typeof chunks[i][1] === 'string') ? '%s: %s\n' : '%s: %o\n';
2290
1766
  }
2291
- return next ?? $mol_wire_sync(native).persisted();
2292
- }
2293
- static estimate() {
2294
- return $mol_wire_sync(this.native() ?? {}).estimate();
2295
- }
2296
- static dir() {
2297
- return $mol_wire_sync(this.native()).getDirectory();
2298
- }
1767
+ const style = `color:${color};font-weight:bolder`;
1768
+ this.console[level](tpl.trim(), style, ...[].concat(...chunks));
1769
+ const self = this;
1770
+ return () => self.console.groupEnd();
1771
+ };
2299
1772
  }
2300
- __decorate([
2301
- $mol_mem
2302
- ], $mol_storage, "native", null);
2303
- __decorate([
2304
- $mol_mem
2305
- ], $mol_storage, "persisted", null);
2306
- $.$mol_storage = $mol_storage;
1773
+ $.$mol_log3_web_make = $mol_log3_web_make;
1774
+ $.$mol_log3_come = $mol_log3_web_make('info', 'royalblue');
1775
+ $.$mol_log3_done = $mol_log3_web_make('info', 'forestgreen');
1776
+ $.$mol_log3_fail = $mol_log3_web_make('error', 'orangered');
1777
+ $.$mol_log3_warn = $mol_log3_web_make('warn', 'goldenrod');
1778
+ $.$mol_log3_rise = $mol_log3_web_make('log', 'magenta');
1779
+ $.$mol_log3_area = $mol_log3_web_make('group', 'cyan');
2307
1780
  })($ || ($ = {}));
2308
1781
 
2309
1782
  ;
2310
1783
  "use strict";
2311
1784
  var $;
2312
1785
  (function ($) {
2313
- class $mol_state_local extends $mol_object {
2314
- static 'native()';
2315
- static native() {
2316
- if (this['native()'])
2317
- return this['native()'];
2318
- check: try {
2319
- const native = $mol_dom_context.localStorage;
2320
- if (!native)
2321
- break check;
2322
- native.setItem('', '');
2323
- native.removeItem('');
2324
- return this['native()'] = native;
2325
- }
2326
- catch (error) {
2327
- console.warn(error);
2328
- }
2329
- return this['native()'] = {
2330
- getItem(key) {
2331
- return this[':' + key];
2332
- },
2333
- setItem(key, value) {
2334
- this[':' + key] = value;
2335
- },
2336
- removeItem(key) {
2337
- this[':' + key] = void 0;
1786
+ class $mol_wire_task extends $mol_wire_fiber {
1787
+ static getter(task) {
1788
+ return function $mol_wire_task_get(host, args) {
1789
+ const sub = $mol_wire_auto();
1790
+ const existen = sub?.track_next();
1791
+ let cause = '';
1792
+ reuse: if (existen) {
1793
+ if (!existen.temp)
1794
+ break reuse;
1795
+ if (existen.task !== task) {
1796
+ cause = 'task';
1797
+ break reuse;
1798
+ }
1799
+ if (existen.host !== host) {
1800
+ cause = 'host';
1801
+ break reuse;
1802
+ }
1803
+ if (!$mol_compare_deep(existen.args, args)) {
1804
+ cause = 'args';
1805
+ break reuse;
1806
+ }
1807
+ return existen;
1808
+ }
1809
+ const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
1810
+ const next = new $mol_wire_task(key, task, host, args);
1811
+ if (existen?.temp) {
1812
+ $$.$mol_log3_warn({
1813
+ place: '$mol_wire_task',
1814
+ message: `Different ${cause} on restart`,
1815
+ sub,
1816
+ prev: existen,
1817
+ next,
1818
+ hint: 'Maybe required additional memoization',
1819
+ });
2338
1820
  }
1821
+ return next;
2339
1822
  };
2340
1823
  }
2341
- static changes(next) { return next; }
2342
- static value(key, next) {
2343
- this.changes();
2344
- if (next === void 0)
2345
- return JSON.parse(this.native().getItem(key) || 'null');
2346
- if (next === null) {
2347
- this.native().removeItem(key);
2348
- }
2349
- else {
2350
- this.native().setItem(key, JSON.stringify(next));
2351
- this.$.$mol_storage.persisted(true);
1824
+ get temp() {
1825
+ return true;
1826
+ }
1827
+ complete() {
1828
+ if ($mol_promise_like(this.cache))
1829
+ return;
1830
+ this.destructor();
1831
+ }
1832
+ put(next) {
1833
+ const prev = this.cache;
1834
+ this.cache = next;
1835
+ if ($mol_promise_like(next)) {
1836
+ this.cursor = $mol_wire_cursor.fresh;
1837
+ if (next !== prev)
1838
+ this.emit();
1839
+ if ($mol_owning_catch(this, next)) {
1840
+ try {
1841
+ next[Symbol.toStringTag] = this[Symbol.toStringTag];
1842
+ }
1843
+ catch {
1844
+ Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
1845
+ }
1846
+ }
1847
+ return next;
2352
1848
  }
1849
+ this.cursor = $mol_wire_cursor.final;
1850
+ if (this.sub_empty)
1851
+ this.destructor();
1852
+ else if (next !== prev)
1853
+ this.emit();
2353
1854
  return next;
2354
1855
  }
2355
- prefix() { return ''; }
2356
- value(key, next) {
2357
- return $mol_state_local.value(this.prefix() + '.' + key, next);
1856
+ destructor() {
1857
+ super.destructor();
1858
+ this.cursor = $mol_wire_cursor.final;
2358
1859
  }
2359
1860
  }
2360
- __decorate([
2361
- $mol_mem
2362
- ], $mol_state_local, "changes", null);
2363
- __decorate([
2364
- $mol_mem_key
2365
- ], $mol_state_local, "value", null);
2366
- $.$mol_state_local = $mol_state_local;
1861
+ $.$mol_wire_task = $mol_wire_task;
2367
1862
  })($ || ($ = {}));
2368
1863
 
2369
1864
  ;
2370
1865
  "use strict";
2371
1866
  var $;
2372
1867
  (function ($) {
2373
- self.addEventListener('storage', event => $.$mol_state_local.changes(event));
1868
+ function $mol_wire_method(host, field, descr) {
1869
+ if (!descr)
1870
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
1871
+ const orig = descr?.value ?? host[field];
1872
+ const sup = Reflect.getPrototypeOf(host);
1873
+ if (typeof sup[field] === 'function') {
1874
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
1875
+ }
1876
+ const temp = $mol_wire_task.getter(orig);
1877
+ const value = function (...args) {
1878
+ const fiber = temp(this ?? null, args);
1879
+ return fiber.sync();
1880
+ };
1881
+ Object.defineProperty(value, 'name', { value: orig.name + ' ' });
1882
+ Object.assign(value, { orig });
1883
+ const descr2 = { ...descr, value };
1884
+ Reflect.defineProperty(host, field, descr2);
1885
+ return descr2;
1886
+ }
1887
+ $.$mol_wire_method = $mol_wire_method;
2374
1888
  })($ || ($ = {}));
2375
1889
 
2376
1890
  ;
2377
1891
  "use strict";
2378
- var $;
2379
- (function ($) {
2380
- function parse(theme) {
2381
- if (theme === 'true')
2382
- return true;
2383
- if (theme === 'false')
2384
- return false;
2385
- return null;
2386
- }
2387
- function $mol_lights(next) {
2388
- const arg = parse(this.$mol_state_arg.value('mol_lights'));
2389
- const base = this.$mol_media.match('(prefers-color-scheme: light)');
2390
- if (next === undefined) {
2391
- return arg ?? this.$mol_state_local.value('$mol_lights') ?? base;
2392
- }
2393
- else {
2394
- if (arg === null) {
2395
- this.$mol_state_local.value('$mol_lights', next === base ? null : next);
2396
- }
2397
- else {
2398
- this.$mol_state_arg.value('mol_lights', String(next));
2399
- }
2400
- return next;
2401
- }
2402
- }
2403
- $.$mol_lights = $mol_lights;
2404
- })($ || ($ = {}));
2405
1892
 
2406
1893
  ;
2407
1894
  "use strict";
2408
- var $;
2409
- (function ($) {
2410
- $.$mol_theme = $mol_style_prop('mol_theme', [
2411
- 'back',
2412
- 'hover',
2413
- 'card',
2414
- 'current',
2415
- 'special',
2416
- 'text',
2417
- 'control',
2418
- 'shade',
2419
- 'line',
2420
- 'focus',
2421
- 'field',
2422
- 'image',
2423
- 'spirit',
2424
- ]);
2425
- })($ || ($ = {}));
2426
1895
 
2427
1896
  ;
2428
1897
  "use strict";
2429
1898
  var $;
2430
1899
  (function ($) {
2431
- $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( 50% 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");
1900
+ const catched = new WeakSet();
1901
+ function $mol_fail_catch(error) {
1902
+ if (typeof error !== 'object')
1903
+ return false;
1904
+ if ($mol_promise_like(error))
1905
+ $mol_fail_hidden(error);
1906
+ if (catched.has(error))
1907
+ return false;
1908
+ catched.add(error);
1909
+ return true;
1910
+ }
1911
+ $.$mol_fail_catch = $mol_fail_catch;
2432
1912
  })($ || ($ = {}));
2433
1913
 
2434
1914
  ;
2435
1915
  "use strict";
2436
1916
  var $;
2437
1917
  (function ($) {
2438
- $mol_style_attach('$mol_theme_lights', `:root { --mol_theme_back: oklch( ${$$.$mol_lights() ? 92 : 20}% .01 var(--mol_theme_hue) ) }`);
1918
+ function $mol_try(handler) {
1919
+ try {
1920
+ return handler();
1921
+ }
1922
+ catch (error) {
1923
+ console.error(error);
1924
+ return error;
1925
+ }
1926
+ }
1927
+ $.$mol_try = $mol_try;
2439
1928
  })($ || ($ = {}));
2440
1929
 
2441
1930
  ;
2442
1931
  "use strict";
2443
1932
  var $;
2444
1933
  (function ($) {
2445
- $.$mol_gap = $mol_style_prop('mol_gap', [
2446
- 'page',
2447
- 'block',
2448
- 'text',
2449
- 'emoji',
2450
- 'round',
2451
- 'space',
2452
- 'blur',
2453
- ]);
1934
+ let error;
1935
+ let result;
1936
+ let handler;
1937
+ function $mol_try_web(handler2) {
1938
+ handler = handler2;
1939
+ error = undefined;
1940
+ result = undefined;
1941
+ window.dispatchEvent(new Event('$mol_try'));
1942
+ const error2 = error;
1943
+ const result2 = result;
1944
+ error = undefined;
1945
+ result = undefined;
1946
+ return error2 || result2;
1947
+ }
1948
+ $.$mol_try_web = $mol_try_web;
1949
+ $.$mol_try = $mol_try_web;
1950
+ self.addEventListener('$mol_try', (event) => {
1951
+ result = handler();
1952
+ }, true);
1953
+ self.addEventListener('error', (event) => {
1954
+ error = event.error;
1955
+ }, true);
2454
1956
  })($ || ($ = {}));
2455
1957
 
2456
1958
  ;
2457
1959
  "use strict";
2458
1960
  var $;
2459
1961
  (function ($) {
2460
- $mol_style_attach("mol/gap/gap.css", ":root {\n\t--mol_gap_page: 3rem;\n\t--mol_gap_block: .75rem;\n\t--mol_gap_text: .5rem .75rem;\n\t--mol_gap_emoji: .5rem;\n\t--mol_gap_round: .25rem;\n\t--mol_gap_space: .25rem;\n\t--mol_gap_blur: .5rem;\n}\n");
1962
+ function $mol_fail_log(error) {
1963
+ if ($mol_promise_like(error))
1964
+ return false;
1965
+ if (!$mol_fail_catch(error))
1966
+ return false;
1967
+ $mol_try(() => { $mol_fail_hidden(error); });
1968
+ return true;
1969
+ }
1970
+ $.$mol_fail_log = $mol_fail_log;
2461
1971
  })($ || ($ = {}));
2462
1972
 
2463
1973
  ;
2464
1974
  "use strict";
2465
1975
  var $;
2466
1976
  (function ($) {
2467
- function $mol_dom_render_children(el, childNodes) {
2468
- const node_set = new Set(childNodes);
2469
- let nextNode = el.firstChild;
2470
- for (let view of childNodes) {
2471
- if (view == null)
2472
- continue;
2473
- if (view instanceof $mol_dom_context.Node) {
2474
- while (true) {
2475
- if (!nextNode) {
2476
- el.appendChild(view);
2477
- break;
2478
- }
2479
- if (nextNode == view) {
2480
- nextNode = nextNode.nextSibling;
2481
- break;
2482
- }
2483
- else {
2484
- if (node_set.has(nextNode)) {
2485
- el.insertBefore(view, nextNode);
2486
- break;
2487
- }
2488
- else {
2489
- const nn = nextNode.nextSibling;
2490
- el.removeChild(nextNode);
2491
- nextNode = nn;
2492
- }
2493
- }
1977
+ class $mol_wire_atom extends $mol_wire_fiber {
1978
+ static solo(host, task) {
1979
+ const field = task.name + '()';
1980
+ const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1981
+ if (existen)
1982
+ return existen;
1983
+ const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1984
+ const key = prefix + ('.' + task.name + '<>');
1985
+ const fiber = new $mol_wire_atom(key, task, host, []);
1986
+ (host ?? task)[field] = fiber;
1987
+ return fiber;
1988
+ }
1989
+ static plex(host, task, key) {
1990
+ const field = task.name + '()';
1991
+ let dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1992
+ const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1993
+ const key_str = $mol_key(key);
1994
+ if (dict) {
1995
+ const existen = dict.get(key_str);
1996
+ if (existen)
1997
+ return existen;
1998
+ }
1999
+ else {
2000
+ dict = (host ?? task)[field] = new Map();
2001
+ }
2002
+ const id = prefix + ('.' + task.name) + ('<' + key_str.replace(/^"|"$/g, "'") + '>');
2003
+ const fiber = new $mol_wire_atom(id, task, host, [key]);
2004
+ dict.set(key_str, fiber);
2005
+ return fiber;
2006
+ }
2007
+ static watching = new Set();
2008
+ static watcher = null;
2009
+ static watch() {
2010
+ $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
2011
+ for (const atom of $mol_wire_atom.watching) {
2012
+ if (atom.cursor === $mol_wire_cursor.final) {
2013
+ $mol_wire_atom.watching.delete(atom);
2014
+ }
2015
+ else {
2016
+ atom.cursor = $mol_wire_cursor.stale;
2017
+ atom.fresh();
2018
+ }
2019
+ }
2020
+ }
2021
+ watch() {
2022
+ if (!$mol_wire_atom.watcher) {
2023
+ $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
2024
+ }
2025
+ $mol_wire_atom.watching.add(this);
2026
+ }
2027
+ resync(args) {
2028
+ for (let cursor = this.pub_from; cursor < this.sub_from; cursor += 2) {
2029
+ const pub = this.data[cursor];
2030
+ if (pub && pub instanceof $mol_wire_task) {
2031
+ pub.destructor();
2032
+ }
2033
+ }
2034
+ return this.put(this.task.call(this.host, ...args));
2035
+ }
2036
+ once() {
2037
+ return this.sync();
2038
+ }
2039
+ channel() {
2040
+ return Object.assign((next) => {
2041
+ if (next !== undefined)
2042
+ return this.resync([...this.args, next]);
2043
+ if (!$mol_wire_fiber.warm)
2044
+ return this.result();
2045
+ if ($mol_wire_auto()?.temp) {
2046
+ return this.once();
2494
2047
  }
2048
+ else {
2049
+ return this.sync();
2050
+ }
2051
+ }, { atom: this });
2052
+ }
2053
+ destructor() {
2054
+ super.destructor();
2055
+ if (this.pub_from === 0) {
2056
+ ;
2057
+ (this.host ?? this.task)[this.field()] = null;
2495
2058
  }
2496
2059
  else {
2497
- if (nextNode && nextNode.nodeName === '#text') {
2498
- const str = String(view);
2499
- if (nextNode.nodeValue !== str)
2500
- nextNode.nodeValue = str;
2501
- nextNode = nextNode.nextSibling;
2060
+ const key = $mol_key(this.args[0]);
2061
+ const map = (this.host ?? this.task)[this.field()];
2062
+ if (!map.has(key))
2063
+ this.$.$mol_log3_warn({
2064
+ place: this,
2065
+ message: 'Absent key on destruction',
2066
+ hint: 'Check for $mol_key(key) is not changed',
2067
+ });
2068
+ map.delete(key);
2069
+ }
2070
+ }
2071
+ put(next) {
2072
+ const prev = this.cache;
2073
+ update: if (next !== prev) {
2074
+ try {
2075
+ if ($mol_compare_deep(prev, next))
2076
+ break update;
2077
+ }
2078
+ catch (error) {
2079
+ $mol_fail_log(error);
2080
+ }
2081
+ if ($mol_owning_check(this, prev)) {
2082
+ prev.destructor();
2502
2083
  }
2503
- else {
2504
- const textNode = $mol_dom_context.document.createTextNode(String(view));
2505
- el.insertBefore(textNode, nextNode);
2084
+ if ($mol_owning_catch(this, next)) {
2085
+ try {
2086
+ next[Symbol.toStringTag] = this[Symbol.toStringTag];
2087
+ }
2088
+ catch {
2089
+ Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
2090
+ }
2506
2091
  }
2092
+ if (!this.sub_empty)
2093
+ this.emit();
2507
2094
  }
2508
- }
2509
- while (nextNode) {
2510
- const currNode = nextNode;
2511
- nextNode = currNode.nextSibling;
2512
- el.removeChild(currNode);
2095
+ this.cache = next;
2096
+ this.cursor = $mol_wire_cursor.fresh;
2097
+ if ($mol_promise_like(next))
2098
+ return next;
2099
+ this.complete_pubs();
2100
+ return next;
2513
2101
  }
2514
2102
  }
2515
- $.$mol_dom_render_children = $mol_dom_render_children;
2103
+ __decorate([
2104
+ $mol_wire_method
2105
+ ], $mol_wire_atom.prototype, "resync", null);
2106
+ __decorate([
2107
+ $mol_wire_method
2108
+ ], $mol_wire_atom.prototype, "once", null);
2109
+ $.$mol_wire_atom = $mol_wire_atom;
2516
2110
  })($ || ($ = {}));
2517
2111
 
2518
- ;
2519
- "use strict";
2520
-
2521
2112
  ;
2522
2113
  "use strict";
2523
2114
  var $;
2524
2115
  (function ($) {
2525
- $.$mol_jsx_prefix = '';
2526
- $.$mol_jsx_crumbs = '';
2527
- $.$mol_jsx_booked = null;
2528
- $.$mol_jsx_document = {
2529
- getElementById: () => null,
2530
- createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
2531
- createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
2532
- };
2533
- $.$mol_jsx_frag = '';
2534
- function $mol_jsx(Elem, props, ...childNodes) {
2535
- const id = props && props.id || '';
2536
- const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
2537
- const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
2538
- if (Elem && $.$mol_jsx_booked) {
2539
- if ($.$mol_jsx_booked.has(id)) {
2540
- $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
2541
- }
2542
- else {
2543
- $.$mol_jsx_booked.add(id);
2544
- }
2116
+ function $mol_wire_solo(host, field, descr) {
2117
+ if (!descr)
2118
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
2119
+ const orig = descr?.value ?? host[field];
2120
+ const sup = Reflect.getPrototypeOf(host);
2121
+ if (typeof sup[field] === 'function') {
2122
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
2545
2123
  }
2546
- let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
2547
- if ($.$mol_jsx_prefix) {
2548
- const prefix_ext = $.$mol_jsx_prefix;
2549
- const booked_ext = $.$mol_jsx_booked;
2550
- const crumbs_ext = $.$mol_jsx_crumbs;
2551
- for (const field in props) {
2552
- const func = props[field];
2553
- if (typeof func !== 'function')
2554
- continue;
2555
- const wrapper = function (...args) {
2556
- const prefix = $.$mol_jsx_prefix;
2557
- const booked = $.$mol_jsx_booked;
2558
- const crumbs = $.$mol_jsx_crumbs;
2559
- try {
2560
- $.$mol_jsx_prefix = prefix_ext;
2561
- $.$mol_jsx_booked = booked_ext;
2562
- $.$mol_jsx_crumbs = crumbs_ext;
2563
- return func.call(this, ...args);
2124
+ const descr2 = {
2125
+ ...descr,
2126
+ value: function (...args) {
2127
+ let atom = $mol_wire_atom.solo(this, orig);
2128
+ if ((args.length === 0) || (args[0] === undefined)) {
2129
+ if (!$mol_wire_fiber.warm)
2130
+ return atom.result();
2131
+ if ($mol_wire_auto()?.temp) {
2132
+ return atom.once();
2564
2133
  }
2565
- finally {
2566
- $.$mol_jsx_prefix = prefix;
2567
- $.$mol_jsx_booked = booked;
2568
- $.$mol_jsx_crumbs = crumbs;
2134
+ else {
2135
+ return atom.sync();
2569
2136
  }
2570
- };
2571
- $mol_func_name_from(wrapper, func);
2572
- props[field] = wrapper;
2573
- }
2574
- }
2575
- if (typeof Elem !== 'string') {
2576
- if ('prototype' in Elem) {
2577
- const view = node && node[String(Elem)] || new Elem;
2578
- Object.assign(view, props);
2579
- view[Symbol.toStringTag] = guid;
2580
- view.childNodes = childNodes;
2581
- if (!view.ownerDocument)
2582
- view.ownerDocument = $.$mol_jsx_document;
2583
- view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
2584
- node = view.valueOf();
2585
- node[String(Elem)] = view;
2586
- return node;
2587
- }
2588
- else {
2589
- const prefix = $.$mol_jsx_prefix;
2590
- const booked = $.$mol_jsx_booked;
2591
- const crumbs = $.$mol_jsx_crumbs;
2592
- try {
2593
- $.$mol_jsx_prefix = guid;
2594
- $.$mol_jsx_booked = new Set;
2595
- $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
2596
- return Elem(props, ...childNodes);
2597
- }
2598
- finally {
2599
- $.$mol_jsx_prefix = prefix;
2600
- $.$mol_jsx_booked = booked;
2601
- $.$mol_jsx_crumbs = crumbs;
2602
2137
  }
2138
+ return atom.resync(args);
2603
2139
  }
2140
+ };
2141
+ Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
2142
+ Reflect.defineProperty(descr2.value, 'length', { value: orig.length });
2143
+ Object.assign(descr2.value, { orig });
2144
+ Reflect.defineProperty(host, field, descr2);
2145
+ return descr2;
2146
+ }
2147
+ $.$mol_wire_solo = $mol_wire_solo;
2148
+ })($ || ($ = {}));
2149
+
2150
+ ;
2151
+ "use strict";
2152
+ var $;
2153
+ (function ($) {
2154
+ function $mol_wire_plex(host, field, descr) {
2155
+ if (!descr)
2156
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
2157
+ const orig = descr?.value ?? host[field];
2158
+ const sup = Reflect.getPrototypeOf(host);
2159
+ if (typeof sup[field] === 'function') {
2160
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
2604
2161
  }
2605
- if (!node) {
2606
- node = Elem
2607
- ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
2608
- : $.$mol_jsx_document.createDocumentFragment();
2609
- }
2610
- $mol_dom_render_children(node, [].concat(...childNodes));
2611
- if (!Elem)
2612
- return node;
2613
- if (guid)
2614
- node.id = guid;
2615
- for (const key in props) {
2616
- if (key === 'id')
2617
- continue;
2618
- if (typeof props[key] === 'string') {
2619
- if (typeof node[key] === 'string')
2620
- node[key] = props[key];
2621
- node.setAttribute(key, props[key]);
2622
- }
2623
- else if (props[key] &&
2624
- typeof props[key] === 'object' &&
2625
- Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
2626
- if (typeof node[key] === 'object') {
2627
- Object.assign(node[key], props[key]);
2628
- continue;
2162
+ const descr2 = {
2163
+ ...descr,
2164
+ value: function (...args) {
2165
+ let atom = $mol_wire_atom.plex(this, orig, args[0]);
2166
+ if ((args.length === 1) || (args[1] === undefined)) {
2167
+ if (!$mol_wire_fiber.warm)
2168
+ return atom.result();
2169
+ if ($mol_wire_auto()?.temp) {
2170
+ return atom.once();
2171
+ }
2172
+ else {
2173
+ return atom.sync();
2174
+ }
2629
2175
  }
2176
+ return atom.resync(args);
2630
2177
  }
2631
- else {
2632
- node[key] = props[key];
2633
- }
2634
- }
2635
- if ($.$mol_jsx_crumbs)
2636
- node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
2637
- return node;
2178
+ };
2179
+ Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
2180
+ Reflect.defineProperty(descr2.value, 'length', { value: orig.length });
2181
+ Object.assign(descr2.value, { orig });
2182
+ Reflect.defineProperty(host, field, descr2);
2183
+ return descr2;
2638
2184
  }
2639
- $.$mol_jsx = $mol_jsx;
2185
+ $.$mol_wire_plex = $mol_wire_plex;
2186
+ })($ || ($ = {}));
2187
+
2188
+ ;
2189
+ "use strict";
2190
+ var $;
2191
+ (function ($) {
2192
+ $.$mol_mem = $mol_wire_solo;
2193
+ $.$mol_mem_key = $mol_wire_plex;
2640
2194
  })($ || ($ = {}));
2641
2195
 
2642
2196
  ;
@@ -2968,6 +2522,26 @@ var $;
2968
2522
  $.$mol_dom_qname = $mol_dom_qname;
2969
2523
  })($ || ($ = {}));
2970
2524
 
2525
+ ;
2526
+ "use strict";
2527
+ var $;
2528
+ (function ($) {
2529
+ function $mol_wire_probe(task, def) {
2530
+ const warm = $mol_wire_fiber.warm;
2531
+ try {
2532
+ $mol_wire_fiber.warm = false;
2533
+ const res = task();
2534
+ if (res === undefined)
2535
+ return def;
2536
+ return res;
2537
+ }
2538
+ finally {
2539
+ $mol_wire_fiber.warm = warm;
2540
+ }
2541
+ }
2542
+ $.$mol_wire_probe = $mol_wire_probe;
2543
+ })($ || ($ = {}));
2544
+
2971
2545
  ;
2972
2546
  "use strict";
2973
2547
  var $;
@@ -2998,6 +2572,24 @@ var $;
2998
2572
  $.$mol_const = $mol_const;
2999
2573
  })($ || ($ = {}));
3000
2574
 
2575
+ ;
2576
+ "use strict";
2577
+ var $;
2578
+ (function ($) {
2579
+ function $mol_wire_solid() {
2580
+ let current = $mol_wire_auto();
2581
+ if (current.temp)
2582
+ current = current.host;
2583
+ if (current.reap !== nothing) {
2584
+ current?.sub_on(sub, sub.data.length);
2585
+ }
2586
+ current.reap = nothing;
2587
+ }
2588
+ $.$mol_wire_solid = $mol_wire_solid;
2589
+ const nothing = () => { };
2590
+ const sub = new $mol_wire_pub_sub;
2591
+ })($ || ($ = {}));
2592
+
3001
2593
  ;
3002
2594
  "use strict";
3003
2595
  var $;
@@ -4517,6 +4109,13 @@ var $;
4517
4109
  ($mol_mem(($.$mol_plot_pane.prototype), "dimensions_viewport"));
4518
4110
 
4519
4111
 
4112
+ ;
4113
+ "use strict";
4114
+ var $;
4115
+ (function ($) {
4116
+ $.$mol_mem_cached = $mol_wire_probe;
4117
+ })($ || ($ = {}));
4118
+
4520
4119
  ;
4521
4120
  ($.$mol_svg_group) = class $mol_svg_group extends ($.$mol_svg) {
4522
4121
  dom_name(){