mol_vary 0.0.21 → 0.0.23

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/node.mjs CHANGED
@@ -117,27 +117,27 @@ var $;
117
117
  var $;
118
118
  (function ($) {
119
119
  function $mol_charset_decode_from(buffer, from, count) {
120
- let res = '';
120
+ const codes = [];
121
121
  let pos = from;
122
- while (pos < buffer.length && res.length < count) {
122
+ while (pos < buffer.length && codes.length < count) {
123
123
  const byte1 = buffer[pos++];
124
124
  if (byte1 <= 0x7F) {
125
- res += String.fromCharCode(byte1);
125
+ codes.push(byte1);
126
126
  }
127
127
  else if ((byte1 & 0xE0) === 0xC0) {
128
128
  if (pos >= buffer.length)
129
129
  break;
130
130
  const byte2 = buffer[pos++];
131
- let code = ((byte1 & 0x1F) << 6) | (byte2 & 0x3F);
132
- res += String.fromCharCode(code);
131
+ const code = ((byte1 & 0x1F) << 6) | (byte2 & 0x3F);
132
+ codes.push(code);
133
133
  }
134
134
  else if ((byte1 & 0xF0) === 0xE0) {
135
135
  if (pos + 1 >= buffer.length)
136
136
  break;
137
137
  const byte2 = buffer[pos++];
138
138
  const byte3 = buffer[pos++];
139
- let code = ((byte1 & 0x0F) << 12) | ((byte2 & 0x3F) << 6) | (byte3 & 0x3F);
140
- res += String.fromCharCode(code);
139
+ const code = ((byte1 & 0x0F) << 12) | ((byte2 & 0x3F) << 6) | (byte3 & 0x3F);
140
+ codes.push(code);
141
141
  }
142
142
  else if ((byte1 & 0xF8) === 0xF0) {
143
143
  if (pos + 2 >= buffer.length)
@@ -150,21 +150,2115 @@ var $;
150
150
  code -= 0x10000;
151
151
  const hi = 0xD800 + (code >> 10);
152
152
  const lo = 0xDC00 + (code & 0x3FF);
153
- res += String.fromCharCode(hi, lo);
153
+ codes.push(hi, lo);
154
154
  }
155
155
  else {
156
- res += String.fromCharCode(code);
156
+ codes.push(code);
157
157
  }
158
158
  }
159
159
  else {
160
- res += '�';
160
+ codes.push(0xFFFD);
161
161
  }
162
162
  }
163
- return [res, pos - from];
163
+ return [String.fromCharCode(...codes), pos - from];
164
164
  }
165
165
  $.$mol_charset_decode_from = $mol_charset_decode_from;
166
166
  })($ || ($ = {}));
167
167
 
168
+ ;
169
+ "use strict";
170
+ var $;
171
+ (function ($) {
172
+ })($ || ($ = {}));
173
+
174
+ ;
175
+ "use strict";
176
+
177
+ ;
178
+ "use strict";
179
+ var $;
180
+ (function ($) {
181
+ function $mol_promise_like(val) {
182
+ try {
183
+ return val && typeof val === 'object' && 'then' in val && typeof val.then === 'function';
184
+ }
185
+ catch {
186
+ return false;
187
+ }
188
+ }
189
+ $.$mol_promise_like = $mol_promise_like;
190
+ })($ || ($ = {}));
191
+
192
+ ;
193
+ "use strict";
194
+ var $;
195
+ (function ($) {
196
+ function $mol_fail_hidden(error) {
197
+ throw error;
198
+ }
199
+ $.$mol_fail_hidden = $mol_fail_hidden;
200
+ })($ || ($ = {}));
201
+
202
+ ;
203
+ "use strict";
204
+ var $;
205
+ (function ($) {
206
+ const catched = new WeakMap();
207
+ function $mol_fail_catch(error) {
208
+ if (typeof error !== 'object')
209
+ return false;
210
+ if ($mol_promise_like(error))
211
+ $mol_fail_hidden(error);
212
+ if (catched.get(error))
213
+ return false;
214
+ catched.set(error, true);
215
+ return true;
216
+ }
217
+ $.$mol_fail_catch = $mol_fail_catch;
218
+ })($ || ($ = {}));
219
+
220
+ ;
221
+ "use strict";
222
+ var $;
223
+ (function ($) {
224
+ function $mol_try(handler) {
225
+ try {
226
+ return handler();
227
+ }
228
+ catch (error) {
229
+ return error;
230
+ }
231
+ }
232
+ $.$mol_try = $mol_try;
233
+ })($ || ($ = {}));
234
+
235
+ ;
236
+ "use strict";
237
+ var $;
238
+ (function ($) {
239
+ function $mol_fail_log(error) {
240
+ if ($mol_promise_like(error))
241
+ return false;
242
+ if (!$mol_fail_catch(error))
243
+ return false;
244
+ $mol_try(() => { $mol_fail_hidden(error); });
245
+ return true;
246
+ }
247
+ $.$mol_fail_log = $mol_fail_log;
248
+ })($ || ($ = {}));
249
+
250
+ ;
251
+ "use strict";
252
+ var $node = new Proxy({ require }, {
253
+ get(target, name, wrapper) {
254
+ if (target[name])
255
+ return target[name];
256
+ if (name.startsWith('node:'))
257
+ return target.require(name);
258
+ if (name[0] === '.')
259
+ return target.require(name);
260
+ const mod = target.require('module');
261
+ if (mod.builtinModules.indexOf(name) >= 0)
262
+ return target.require(name);
263
+ try {
264
+ target.require.resolve(name);
265
+ }
266
+ catch {
267
+ const $$ = $;
268
+ $$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
269
+ try {
270
+ $$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
271
+ }
272
+ catch (e) {
273
+ if ($$.$mol_fail_catch(e)) {
274
+ $$.$mol_fail_log(e);
275
+ }
276
+ }
277
+ }
278
+ try {
279
+ return target.require(name);
280
+ }
281
+ catch (error) {
282
+ if ($.$mol_fail_catch(error) && error.code === 'ERR_REQUIRE_ESM') {
283
+ const module = cache.get(name);
284
+ if (module)
285
+ return module;
286
+ throw Object.assign(import(name).then(module => cache.set(name, module)), { cause: error });
287
+ }
288
+ $.$mol_fail_log(error);
289
+ return null;
290
+ }
291
+ },
292
+ set(target, name, value) {
293
+ target[name] = value;
294
+ return true;
295
+ },
296
+ });
297
+ const cache = new Map();
298
+ require = (req => Object.assign(function require(name) {
299
+ return $node[name];
300
+ }, req))(require);
301
+
302
+ ;
303
+ "use strict";
304
+ var $;
305
+ (function ($) {
306
+ const named = new WeakSet();
307
+ function $mol_func_name(func) {
308
+ let name = func.name;
309
+ if (name?.length > 1)
310
+ return name;
311
+ if (named.has(func))
312
+ return name;
313
+ for (let key in this) {
314
+ try {
315
+ if (this[key] !== func)
316
+ continue;
317
+ name = key;
318
+ Object.defineProperty(func, 'name', { value: name });
319
+ break;
320
+ }
321
+ catch { }
322
+ }
323
+ named.add(func);
324
+ return name;
325
+ }
326
+ $.$mol_func_name = $mol_func_name;
327
+ function $mol_func_name_from(target, source) {
328
+ Object.defineProperty(target, 'name', { value: source.name });
329
+ return target;
330
+ }
331
+ $.$mol_func_name_from = $mol_func_name_from;
332
+ })($ || ($ = {}));
333
+
334
+ ;
335
+ "use strict";
336
+ var $;
337
+ (function ($) {
338
+ function cause_serialize(cause) {
339
+ return JSON.stringify(cause, null, ' ')
340
+ .replace(/\(/, '<')
341
+ .replace(/\)/, ' >');
342
+ }
343
+ function frame_normalize(frame) {
344
+ return (typeof frame === 'string' ? frame : cause_serialize(frame))
345
+ .trim()
346
+ .replace(/at /gm, ' at ')
347
+ .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)');
348
+ }
349
+ class $mol_error_mix extends AggregateError {
350
+ cause;
351
+ name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
352
+ constructor(message, cause = {}, ...errors) {
353
+ super(errors, message, { cause });
354
+ this.cause = cause;
355
+ const desc = Object.getOwnPropertyDescriptor(this, 'stack');
356
+ const stack_get = () => desc?.get?.() ?? super.stack ?? desc?.value ?? this.message;
357
+ Object.defineProperty(this, 'stack', {
358
+ get: () => stack_get() + '\n' + [
359
+ this.cause ?? 'no cause',
360
+ ...this.errors.flatMap(e => [
361
+ String(e.stack),
362
+ ...e instanceof $mol_error_mix || !e.cause ? [] : [e.cause]
363
+ ])
364
+ ].map(frame_normalize).join('\n')
365
+ });
366
+ Object.defineProperty(this, 'cause', {
367
+ get: () => cause
368
+ });
369
+ }
370
+ static [Symbol.toPrimitive]() {
371
+ return this.toString();
372
+ }
373
+ static toString() {
374
+ return $$.$mol_func_name(this);
375
+ }
376
+ static make(...params) {
377
+ return new this(...params);
378
+ }
379
+ }
380
+ $.$mol_error_mix = $mol_error_mix;
381
+ })($ || ($ = {}));
382
+
383
+ ;
384
+ "use strict";
385
+ var $;
386
+ (function ($) {
387
+ $.$mol_ambient_ref = Symbol('$mol_ambient_ref');
388
+ function $mol_ambient(overrides) {
389
+ return Object.setPrototypeOf(overrides, this || $);
390
+ }
391
+ $.$mol_ambient = $mol_ambient;
392
+ })($ || ($ = {}));
393
+
394
+ ;
395
+ "use strict";
396
+ var $;
397
+ (function ($) {
398
+ const instances = new WeakSet();
399
+ function $mol_delegate(proto, target) {
400
+ const proxy = new Proxy(proto, {
401
+ get: (_, field) => {
402
+ const obj = target();
403
+ let val = Reflect.get(obj, field);
404
+ if (typeof val === 'function') {
405
+ val = val.bind(obj);
406
+ }
407
+ return val;
408
+ },
409
+ has: (_, field) => Reflect.has(target(), field),
410
+ set: (_, field, value) => Reflect.set(target(), field, value),
411
+ getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
412
+ ownKeys: () => Reflect.ownKeys(target()),
413
+ getPrototypeOf: () => Reflect.getPrototypeOf(target()),
414
+ setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
415
+ isExtensible: () => Reflect.isExtensible(target()),
416
+ preventExtensions: () => Reflect.preventExtensions(target()),
417
+ apply: (_, self, args) => Reflect.apply(target(), self, args),
418
+ construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
419
+ defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
420
+ deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
421
+ });
422
+ instances.add(proxy);
423
+ return proxy;
424
+ }
425
+ $.$mol_delegate = $mol_delegate;
426
+ Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
427
+ value: (obj) => instances.has(obj),
428
+ });
429
+ })($ || ($ = {}));
430
+
431
+ ;
432
+ "use strict";
433
+ var $;
434
+ (function ($) {
435
+ $.$mol_owning_map = new WeakMap();
436
+ function $mol_owning_allow(having) {
437
+ try {
438
+ if (!having)
439
+ return false;
440
+ if (typeof having !== 'object' && typeof having !== 'function')
441
+ return false;
442
+ if (having instanceof $mol_delegate)
443
+ return false;
444
+ if (typeof having['destructor'] !== 'function')
445
+ return false;
446
+ return true;
447
+ }
448
+ catch {
449
+ return false;
450
+ }
451
+ }
452
+ $.$mol_owning_allow = $mol_owning_allow;
453
+ function $mol_owning_get(having, Owner) {
454
+ if (!$mol_owning_allow(having))
455
+ return null;
456
+ while (true) {
457
+ const owner = $.$mol_owning_map.get(having);
458
+ if (!owner)
459
+ return owner;
460
+ if (!Owner)
461
+ return owner;
462
+ if (owner instanceof Owner)
463
+ return owner;
464
+ having = owner;
465
+ }
466
+ }
467
+ $.$mol_owning_get = $mol_owning_get;
468
+ function $mol_owning_check(owner, having) {
469
+ if (!$mol_owning_allow(having))
470
+ return false;
471
+ if ($.$mol_owning_map.get(having) !== owner)
472
+ return false;
473
+ return true;
474
+ }
475
+ $.$mol_owning_check = $mol_owning_check;
476
+ function $mol_owning_catch(owner, having) {
477
+ if (!$mol_owning_allow(having))
478
+ return false;
479
+ if ($.$mol_owning_map.get(having))
480
+ return false;
481
+ $.$mol_owning_map.set(having, owner);
482
+ return true;
483
+ }
484
+ $.$mol_owning_catch = $mol_owning_catch;
485
+ })($ || ($ = {}));
486
+
487
+ ;
488
+ "use strict";
489
+
490
+ ;
491
+ "use strict";
492
+ var $;
493
+ (function ($) {
494
+ class $mol_object2 {
495
+ static $ = $;
496
+ [Symbol.toStringTag];
497
+ [$mol_ambient_ref] = null;
498
+ get $() {
499
+ if (this[$mol_ambient_ref])
500
+ return this[$mol_ambient_ref];
501
+ const owner = $mol_owning_get(this);
502
+ return this[$mol_ambient_ref] = owner?.$ || this.constructor.$ || $mol_object2.$;
503
+ }
504
+ set $(next) {
505
+ if (this[$mol_ambient_ref])
506
+ $mol_fail_hidden(new Error('Context already defined'));
507
+ this[$mol_ambient_ref] = next;
508
+ }
509
+ static create(init) {
510
+ const obj = new this;
511
+ if (init)
512
+ init(obj);
513
+ return obj;
514
+ }
515
+ static [Symbol.toPrimitive]() {
516
+ return this.toString();
517
+ }
518
+ static toString() {
519
+ return this[Symbol.toStringTag] || this.$.$mol_func_name(this);
520
+ }
521
+ static toJSON() {
522
+ return this.toString();
523
+ }
524
+ destructor() { }
525
+ static destructor() { }
526
+ toString() {
527
+ return this[Symbol.toStringTag] || this.constructor.name + '<>';
528
+ }
529
+ }
530
+ $.$mol_object2 = $mol_object2;
531
+ })($ || ($ = {}));
532
+
533
+ ;
534
+ "use strict";
535
+ var $;
536
+ (function ($_1) {
537
+ let $$;
538
+ (function ($$) {
539
+ let $;
540
+ })($$ = $_1.$$ || ($_1.$$ = {}));
541
+ $_1.$mol_object_field = Symbol('$mol_object_field');
542
+ class $mol_object extends $mol_object2 {
543
+ static make(config) {
544
+ return super.create(obj => {
545
+ for (let key in config)
546
+ obj[key] = config[key];
547
+ });
548
+ }
549
+ }
550
+ $_1.$mol_object = $mol_object;
551
+ })($ || ($ = {}));
552
+
553
+ ;
554
+ "use strict";
555
+ var $;
556
+ (function ($) {
557
+ function $mol_env() {
558
+ return {};
559
+ }
560
+ $.$mol_env = $mol_env;
561
+ })($ || ($ = {}));
562
+
563
+ ;
564
+ "use strict";
565
+ var $;
566
+ (function ($) {
567
+ $.$mol_env = function $mol_env() {
568
+ return this.process.env;
569
+ };
570
+ })($ || ($ = {}));
571
+
572
+ ;
573
+ "use strict";
574
+ var $;
575
+ (function ($) {
576
+ function $mol_guid(length = 8, exists = () => false) {
577
+ for (;;) {
578
+ let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
579
+ if (exists(id))
580
+ continue;
581
+ return id;
582
+ }
583
+ }
584
+ $.$mol_guid = $mol_guid;
585
+ })($ || ($ = {}));
586
+
587
+ ;
588
+ "use strict";
589
+ var $;
590
+ (function ($) {
591
+ let $mol_wire_cursor;
592
+ (function ($mol_wire_cursor) {
593
+ $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
594
+ $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
595
+ $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
596
+ $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
597
+ })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
598
+ })($ || ($ = {}));
599
+
600
+ ;
601
+ "use strict";
602
+ var $;
603
+ (function ($) {
604
+ class $mol_wire_pub extends Object {
605
+ constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
606
+ super();
607
+ this[Symbol.toStringTag] = id;
608
+ }
609
+ [Symbol.toStringTag];
610
+ data = [];
611
+ static get [Symbol.species]() {
612
+ return Array;
613
+ }
614
+ sub_from = 0;
615
+ get sub_list() {
616
+ const res = [];
617
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
618
+ res.push(this.data[i]);
619
+ }
620
+ return res;
621
+ }
622
+ get sub_empty() {
623
+ return this.sub_from === this.data.length;
624
+ }
625
+ sub_on(sub, pub_pos) {
626
+ const pos = this.data.length;
627
+ this.data.push(sub, pub_pos);
628
+ return pos;
629
+ }
630
+ sub_off(sub_pos) {
631
+ if (!(sub_pos < this.data.length)) {
632
+ $mol_fail(new Error(`Wrong pos ${sub_pos}`));
633
+ }
634
+ const end = this.data.length - 2;
635
+ if (sub_pos !== end) {
636
+ this.peer_move(end, sub_pos);
637
+ }
638
+ this.data.length = end;
639
+ if (end === this.sub_from)
640
+ this.reap();
641
+ }
642
+ reap() { }
643
+ promote() {
644
+ $mol_wire_auto()?.track_next(this);
645
+ }
646
+ fresh() { }
647
+ complete() { }
648
+ get incompleted() {
649
+ return false;
650
+ }
651
+ emit(quant = $mol_wire_cursor.stale) {
652
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
653
+ ;
654
+ this.data[i].absorb(quant, this.data[i + 1]);
655
+ }
656
+ }
657
+ peer_move(from_pos, to_pos) {
658
+ const peer = this.data[from_pos];
659
+ const self_pos = this.data[from_pos + 1];
660
+ this.data[to_pos] = peer;
661
+ this.data[to_pos + 1] = self_pos;
662
+ peer.peer_repos(self_pos, to_pos);
663
+ }
664
+ peer_repos(peer_pos, self_pos) {
665
+ this.data[peer_pos + 1] = self_pos;
666
+ }
667
+ }
668
+ $.$mol_wire_pub = $mol_wire_pub;
669
+ })($ || ($ = {}));
670
+
671
+ ;
672
+ "use strict";
673
+
674
+ ;
675
+ "use strict";
676
+ var $;
677
+ (function ($) {
678
+ $.$mol_wire_auto_sub = null;
679
+ function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
680
+ return $.$mol_wire_auto_sub = next;
681
+ }
682
+ $.$mol_wire_auto = $mol_wire_auto;
683
+ $.$mol_wire_affected = [];
684
+ })($ || ($ = {}));
685
+
686
+ ;
687
+ "use strict";
688
+ var $;
689
+ (function ($) {
690
+ $['devtoolsFormatters'] ||= [];
691
+ function $mol_dev_format_register(config) {
692
+ $['devtoolsFormatters'].push(config);
693
+ }
694
+ $.$mol_dev_format_register = $mol_dev_format_register;
695
+ $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
696
+ $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
697
+ function $mol_dev_format_button(label, click) {
698
+ return $mol_dev_format_auto({
699
+ [$.$mol_dev_format_head]() {
700
+ return $.$mol_dev_format_span({ color: 'cornflowerblue' }, label);
701
+ },
702
+ [$.$mol_dev_format_body]() {
703
+ Promise.resolve().then(click);
704
+ return $.$mol_dev_format_span({});
705
+ }
706
+ });
707
+ }
708
+ $mol_dev_format_register({
709
+ header: (val, config = false) => {
710
+ if (config)
711
+ return null;
712
+ if (!val)
713
+ return null;
714
+ if ($.$mol_dev_format_head in val) {
715
+ try {
716
+ return val[$.$mol_dev_format_head]();
717
+ }
718
+ catch (error) {
719
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
720
+ }
721
+ }
722
+ if (typeof val === 'function') {
723
+ return $mol_dev_format_native(val);
724
+ }
725
+ if (val instanceof Error) {
726
+ return $.$mol_dev_format_span({}, $mol_dev_format_native(val), ' ', $mol_dev_format_button('throw', () => $mol_fail_hidden(val)));
727
+ }
728
+ if (val instanceof Promise) {
729
+ return $.$mol_dev_format_shade($mol_dev_format_native(val), ' ', val[Symbol.toStringTag] ?? '');
730
+ }
731
+ if (Symbol.toStringTag in val) {
732
+ return $mol_dev_format_native(val);
733
+ }
734
+ return null;
735
+ },
736
+ hasBody: (val, config = false) => {
737
+ if (config)
738
+ return false;
739
+ if (!val)
740
+ return false;
741
+ if (val[$.$mol_dev_format_body])
742
+ return true;
743
+ return false;
744
+ },
745
+ body: (val, config = false) => {
746
+ if (config)
747
+ return null;
748
+ if (!val)
749
+ return null;
750
+ if ($.$mol_dev_format_body in val) {
751
+ try {
752
+ return val[$.$mol_dev_format_body]();
753
+ }
754
+ catch (error) {
755
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
756
+ }
757
+ }
758
+ return null;
759
+ },
760
+ });
761
+ function $mol_dev_format_native(obj) {
762
+ if (typeof obj === 'undefined')
763
+ return $.$mol_dev_format_shade('undefined');
764
+ return [
765
+ 'object',
766
+ {
767
+ object: obj,
768
+ config: true,
769
+ },
770
+ ];
771
+ }
772
+ $.$mol_dev_format_native = $mol_dev_format_native;
773
+ function $mol_dev_format_auto(obj) {
774
+ if (obj == null)
775
+ return $.$mol_dev_format_shade(String(obj));
776
+ return [
777
+ 'object',
778
+ {
779
+ object: obj,
780
+ config: false,
781
+ },
782
+ ];
783
+ }
784
+ $.$mol_dev_format_auto = $mol_dev_format_auto;
785
+ function $mol_dev_format_element(element, style, ...content) {
786
+ const styles = [];
787
+ for (let key in style)
788
+ styles.push(`${key} : ${style[key]}`);
789
+ return [
790
+ element,
791
+ {
792
+ style: styles.join(' ; '),
793
+ },
794
+ ...content,
795
+ ];
796
+ }
797
+ $.$mol_dev_format_element = $mol_dev_format_element;
798
+ $.$mol_dev_format_span = $mol_dev_format_element.bind(null, 'span');
799
+ $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
800
+ $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
801
+ $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
802
+ $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
803
+ $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
804
+ $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
805
+ $.$mol_dev_format_accent = $.$mol_dev_format_span.bind(null, {
806
+ 'color': 'magenta',
807
+ });
808
+ $.$mol_dev_format_strong = $.$mol_dev_format_span.bind(null, {
809
+ 'font-weight': 'bold',
810
+ });
811
+ $.$mol_dev_format_string = $.$mol_dev_format_span.bind(null, {
812
+ 'color': 'green',
813
+ });
814
+ $.$mol_dev_format_shade = $.$mol_dev_format_span.bind(null, {
815
+ 'color': 'gray',
816
+ });
817
+ $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
818
+ 'margin-left': '13px'
819
+ });
820
+ class Stack extends Array {
821
+ toString() {
822
+ return this.join('\n');
823
+ }
824
+ }
825
+ class Call extends Object {
826
+ type;
827
+ function;
828
+ method;
829
+ eval;
830
+ source;
831
+ offset;
832
+ pos;
833
+ object;
834
+ flags;
835
+ [Symbol.toStringTag];
836
+ constructor(call) {
837
+ super();
838
+ this.type = call.getTypeName() ?? '';
839
+ this.function = call.getFunctionName() ?? '';
840
+ this.method = call.getMethodName() ?? '';
841
+ if (this.method === this.function)
842
+ this.method = '';
843
+ this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
844
+ this.eval = call.getEvalOrigin() ?? '';
845
+ this.source = call.getScriptNameOrSourceURL() ?? '';
846
+ this.object = call.getThis();
847
+ this.offset = call.getPosition();
848
+ const flags = [];
849
+ if (call.isAsync())
850
+ flags.push('async');
851
+ if (call.isConstructor())
852
+ flags.push('constructor');
853
+ if (call.isEval())
854
+ flags.push('eval');
855
+ if (call.isNative())
856
+ flags.push('native');
857
+ if (call.isPromiseAll())
858
+ flags.push('PromiseAll');
859
+ if (call.isToplevel())
860
+ flags.push('top');
861
+ this.flags = flags;
862
+ const type = this.type ? this.type + '.' : '';
863
+ const func = this.function || '<anon>';
864
+ const method = this.method ? ' [' + this.method + '] ' : '';
865
+ this[Symbol.toStringTag] = `${type}${func}${method}`;
866
+ }
867
+ [Symbol.toPrimitive]() {
868
+ return this.toString();
869
+ }
870
+ toString() {
871
+ const object = this.object || '';
872
+ const label = this[Symbol.toStringTag];
873
+ const source = `${this.source}:${this.pos.join(':')} #${this.offset}`;
874
+ return `\tat ${object}${label} (${source})`;
875
+ }
876
+ [$.$mol_dev_format_head]() {
877
+ return $.$mol_dev_format_div({}, $mol_dev_format_native(this), $.$mol_dev_format_shade(' '), ...this.object ? [
878
+ $mol_dev_format_native(this.object),
879
+ ] : [], ...this.method ? [$.$mol_dev_format_shade(' ', ' [', this.method, ']')] : [], $.$mol_dev_format_shade(' ', this.flags.join(', ')));
880
+ }
881
+ }
882
+ Error.prepareStackTrace ??= (error, stack) => new Stack(...stack.map(call => new Call(call)));
883
+ })($ || ($ = {}));
884
+
885
+ ;
886
+ "use strict";
887
+ var $;
888
+ (function ($) {
889
+ class $mol_wire_pub_sub extends $mol_wire_pub {
890
+ pub_from = 0;
891
+ cursor = $mol_wire_cursor.stale;
892
+ get temp() {
893
+ return false;
894
+ }
895
+ get pub_list() {
896
+ const res = [];
897
+ const max = this.cursor >= 0 ? this.cursor : this.sub_from;
898
+ for (let i = this.pub_from; i < max; i += 2) {
899
+ if (this.data[i])
900
+ res.push(this.data[i]);
901
+ }
902
+ return res;
903
+ }
904
+ track_on() {
905
+ this.cursor = this.pub_from;
906
+ const sub = $mol_wire_auto();
907
+ $mol_wire_auto(this);
908
+ return sub;
909
+ }
910
+ promote() {
911
+ if (this.cursor >= this.pub_from) {
912
+ $mol_fail(new Error('Circular subscription'));
913
+ }
914
+ super.promote();
915
+ }
916
+ track_next(pub) {
917
+ if (this.cursor < 0)
918
+ $mol_fail(new Error('Promo to non begun sub'));
919
+ if (this.cursor < this.sub_from) {
920
+ const next = this.data[this.cursor];
921
+ if (pub === undefined)
922
+ return next ?? null;
923
+ if (next === pub) {
924
+ this.cursor += 2;
925
+ return next;
926
+ }
927
+ if (next) {
928
+ if (this.sub_from < this.data.length) {
929
+ this.peer_move(this.sub_from, this.data.length);
930
+ }
931
+ this.peer_move(this.cursor, this.sub_from);
932
+ this.sub_from += 2;
933
+ }
934
+ }
935
+ else {
936
+ if (pub === undefined)
937
+ return null;
938
+ if (this.sub_from < this.data.length) {
939
+ this.peer_move(this.sub_from, this.data.length);
940
+ }
941
+ this.sub_from += 2;
942
+ }
943
+ this.data[this.cursor] = pub;
944
+ this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
945
+ this.cursor += 2;
946
+ return pub;
947
+ }
948
+ track_off(sub) {
949
+ $mol_wire_auto(sub);
950
+ if (this.cursor < 0) {
951
+ $mol_fail(new Error('End of non begun sub'));
952
+ }
953
+ for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
954
+ const pub = this.data[cursor];
955
+ pub.fresh();
956
+ }
957
+ this.cursor = $mol_wire_cursor.fresh;
958
+ }
959
+ pub_off(sub_pos) {
960
+ this.data[sub_pos] = undefined;
961
+ this.data[sub_pos + 1] = undefined;
962
+ }
963
+ destructor() {
964
+ for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
965
+ const sub = this.data[cursor];
966
+ const pos = this.data[cursor + 1];
967
+ sub.pub_off(pos);
968
+ }
969
+ this.data.length = this.sub_from;
970
+ this.cursor = this.pub_from;
971
+ this.track_cut();
972
+ this.cursor = $mol_wire_cursor.stale;
973
+ }
974
+ track_cut() {
975
+ if (this.cursor < this.pub_from) {
976
+ $mol_fail(new Error('Cut of non begun sub'));
977
+ }
978
+ let end = this.data.length;
979
+ for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
980
+ const pub = this.data[cursor];
981
+ pub?.sub_off(this.data[cursor + 1]);
982
+ end -= 2;
983
+ if (this.sub_from <= end)
984
+ this.peer_move(end, cursor);
985
+ }
986
+ this.data.length = end;
987
+ this.sub_from = this.cursor;
988
+ }
989
+ complete() { }
990
+ complete_pubs() {
991
+ const limit = this.cursor < 0 ? this.sub_from : this.cursor;
992
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
993
+ const pub = this.data[cursor];
994
+ if (pub?.incompleted)
995
+ return;
996
+ }
997
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
998
+ const pub = this.data[cursor];
999
+ pub?.complete();
1000
+ }
1001
+ }
1002
+ absorb(quant = $mol_wire_cursor.stale, pos = -1) {
1003
+ if (this.cursor === $mol_wire_cursor.final)
1004
+ return;
1005
+ if (this.cursor >= quant)
1006
+ return;
1007
+ this.cursor = quant;
1008
+ this.emit($mol_wire_cursor.doubt);
1009
+ }
1010
+ [$mol_dev_format_head]() {
1011
+ return $mol_dev_format_native(this);
1012
+ }
1013
+ get pub_empty() {
1014
+ return this.sub_from === this.pub_from;
1015
+ }
1016
+ }
1017
+ $.$mol_wire_pub_sub = $mol_wire_pub_sub;
1018
+ })($ || ($ = {}));
1019
+
1020
+ ;
1021
+ "use strict";
1022
+ var $;
1023
+ (function ($) {
1024
+ class $mol_after_tick extends $mol_object2 {
1025
+ task;
1026
+ static promise = null;
1027
+ cancelled = false;
1028
+ constructor(task) {
1029
+ super();
1030
+ this.task = task;
1031
+ if (!$mol_after_tick.promise)
1032
+ $mol_after_tick.promise = Promise.resolve().then(() => {
1033
+ $mol_after_tick.promise = null;
1034
+ });
1035
+ $mol_after_tick.promise.then(() => {
1036
+ if (this.cancelled)
1037
+ return;
1038
+ task();
1039
+ });
1040
+ }
1041
+ destructor() {
1042
+ this.cancelled = true;
1043
+ }
1044
+ }
1045
+ $.$mol_after_tick = $mol_after_tick;
1046
+ })($ || ($ = {}));
1047
+
1048
+ ;
1049
+ "use strict";
1050
+ var $;
1051
+ (function ($) {
1052
+ const wrappers = new WeakMap();
1053
+ class $mol_wire_fiber extends $mol_wire_pub_sub {
1054
+ task;
1055
+ host;
1056
+ static warm = true;
1057
+ static planning = new Set();
1058
+ static reaping = new Set();
1059
+ static plan_task = null;
1060
+ static plan() {
1061
+ if (this.plan_task)
1062
+ return;
1063
+ this.plan_task = new $mol_after_tick(() => {
1064
+ try {
1065
+ this.sync();
1066
+ }
1067
+ finally {
1068
+ $mol_wire_fiber.plan_task = null;
1069
+ }
1070
+ });
1071
+ }
1072
+ static sync() {
1073
+ while (this.planning.size) {
1074
+ for (const fiber of this.planning) {
1075
+ this.planning.delete(fiber);
1076
+ if (fiber.cursor >= 0)
1077
+ continue;
1078
+ if (fiber.cursor === $mol_wire_cursor.final)
1079
+ continue;
1080
+ fiber.fresh();
1081
+ }
1082
+ }
1083
+ while (this.reaping.size) {
1084
+ const fibers = this.reaping;
1085
+ this.reaping = new Set;
1086
+ for (const fiber of fibers) {
1087
+ if (!fiber.sub_empty)
1088
+ continue;
1089
+ fiber.destructor();
1090
+ }
1091
+ }
1092
+ }
1093
+ cache = undefined;
1094
+ get args() {
1095
+ return this.data.slice(0, this.pub_from);
1096
+ }
1097
+ result() {
1098
+ if ($mol_promise_like(this.cache))
1099
+ return;
1100
+ if (this.cache instanceof Error)
1101
+ return;
1102
+ return this.cache;
1103
+ }
1104
+ get incompleted() {
1105
+ return $mol_promise_like(this.cache);
1106
+ }
1107
+ field() {
1108
+ return this.task.name + '()';
1109
+ }
1110
+ constructor(id, task, host, args) {
1111
+ super(id);
1112
+ this.task = task;
1113
+ this.host = host;
1114
+ if (args)
1115
+ this.data.push(...args);
1116
+ this.pub_from = this.sub_from = args?.length ?? 0;
1117
+ }
1118
+ plan() {
1119
+ $mol_wire_fiber.planning.add(this);
1120
+ $mol_wire_fiber.plan();
1121
+ return this;
1122
+ }
1123
+ reap() {
1124
+ $mol_wire_fiber.reaping.add(this);
1125
+ $mol_wire_fiber.plan();
1126
+ }
1127
+ toString() {
1128
+ return this[Symbol.toStringTag];
1129
+ }
1130
+ toJSON() {
1131
+ return this[Symbol.toStringTag];
1132
+ }
1133
+ [$mol_dev_format_head]() {
1134
+ const cursor = {
1135
+ [$mol_wire_cursor.stale]: '🔴',
1136
+ [$mol_wire_cursor.doubt]: '🟡',
1137
+ [$mol_wire_cursor.fresh]: '🟢',
1138
+ [$mol_wire_cursor.final]: '🔵',
1139
+ }[this.cursor] ?? this.cursor.toString();
1140
+ return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
1141
+ ? $mol_dev_format_shade(cursor)
1142
+ : $mol_dev_format_shade(this[Symbol.toStringTag], cursor), $mol_dev_format_auto(this.cache));
1143
+ }
1144
+ [$mol_dev_format_body]() { return null; }
1145
+ get $() {
1146
+ return (this.host ?? this.task)['$'];
1147
+ }
1148
+ emit(quant = $mol_wire_cursor.stale) {
1149
+ if (this.sub_empty)
1150
+ this.plan();
1151
+ else
1152
+ super.emit(quant);
1153
+ }
1154
+ fresh() {
1155
+ if (this.cursor === $mol_wire_cursor.fresh)
1156
+ return;
1157
+ if (this.cursor === $mol_wire_cursor.final)
1158
+ return;
1159
+ check: if (this.cursor === $mol_wire_cursor.doubt) {
1160
+ for (let i = this.pub_from; i < this.sub_from; i += 2) {
1161
+ ;
1162
+ this.data[i]?.fresh();
1163
+ if (this.cursor !== $mol_wire_cursor.doubt)
1164
+ break check;
1165
+ }
1166
+ this.cursor = $mol_wire_cursor.fresh;
1167
+ return;
1168
+ }
1169
+ const bu = this.track_on();
1170
+ let result;
1171
+ try {
1172
+ switch (this.pub_from) {
1173
+ case 0:
1174
+ result = this.task.call(this.host);
1175
+ break;
1176
+ case 1:
1177
+ result = this.task.call(this.host, this.data[0]);
1178
+ break;
1179
+ default:
1180
+ result = this.task.call(this.host, ...this.args);
1181
+ break;
1182
+ }
1183
+ if ($mol_promise_like(result)) {
1184
+ if (wrappers.has(result)) {
1185
+ result = wrappers.get(result).then(a => a);
1186
+ }
1187
+ else {
1188
+ const put = (res) => {
1189
+ if (this.cache === result)
1190
+ this.put(res);
1191
+ return res;
1192
+ };
1193
+ wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
1194
+ wrappers.set(result, result);
1195
+ const error = new Error(`Promise in ${this}`);
1196
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
1197
+ }
1198
+ }
1199
+ }
1200
+ catch (error) {
1201
+ if (error instanceof Error || $mol_promise_like(error)) {
1202
+ result = error;
1203
+ }
1204
+ else {
1205
+ result = new Error(String(error), { cause: error });
1206
+ }
1207
+ if ($mol_promise_like(result)) {
1208
+ if (wrappers.has(result)) {
1209
+ result = wrappers.get(result);
1210
+ }
1211
+ else {
1212
+ const put = (v) => {
1213
+ if (this.cache === result)
1214
+ this.absorb();
1215
+ return v;
1216
+ };
1217
+ wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
1218
+ const error = new Error(`Promise in ${this}`);
1219
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
1220
+ }
1221
+ }
1222
+ }
1223
+ if (!$mol_promise_like(result)) {
1224
+ this.track_cut();
1225
+ }
1226
+ this.track_off(bu);
1227
+ this.put(result);
1228
+ return this;
1229
+ }
1230
+ refresh() {
1231
+ this.cursor = $mol_wire_cursor.stale;
1232
+ this.fresh();
1233
+ }
1234
+ sync() {
1235
+ if (!$mol_wire_fiber.warm) {
1236
+ return this.result();
1237
+ }
1238
+ this.promote();
1239
+ this.fresh();
1240
+ if (this.cache instanceof Error) {
1241
+ return $mol_fail_hidden(this.cache);
1242
+ }
1243
+ if ($mol_promise_like(this.cache)) {
1244
+ return $mol_fail_hidden(this.cache);
1245
+ }
1246
+ return this.cache;
1247
+ }
1248
+ async async_raw() {
1249
+ while (true) {
1250
+ this.fresh();
1251
+ if (this.cache instanceof Error) {
1252
+ $mol_fail_hidden(this.cache);
1253
+ }
1254
+ if (!$mol_promise_like(this.cache))
1255
+ return this.cache;
1256
+ await Promise.race([this.cache, this.step()]);
1257
+ if (!$mol_promise_like(this.cache))
1258
+ return this.cache;
1259
+ if (this.cursor === $mol_wire_cursor.final) {
1260
+ await new Promise(() => { });
1261
+ }
1262
+ }
1263
+ }
1264
+ async() {
1265
+ const promise = this.async_raw();
1266
+ if (!promise.destructor)
1267
+ promise.destructor = () => this.destructor();
1268
+ return promise;
1269
+ }
1270
+ step() {
1271
+ return new Promise(done => {
1272
+ const sub = new $mol_wire_pub_sub;
1273
+ const prev = sub.track_on();
1274
+ sub.track_next(this);
1275
+ sub.track_off(prev);
1276
+ sub.absorb = () => {
1277
+ done(null);
1278
+ setTimeout(() => sub.destructor());
1279
+ };
1280
+ });
1281
+ }
1282
+ destructor() {
1283
+ super.destructor();
1284
+ $mol_wire_fiber.planning.delete(this);
1285
+ if (!$mol_owning_check(this, this.cache))
1286
+ return;
1287
+ try {
1288
+ this.cache.destructor();
1289
+ }
1290
+ catch (result) {
1291
+ if ($mol_promise_like(result)) {
1292
+ const error = new Error(`Promise in ${this}.destructor()`);
1293
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
1294
+ }
1295
+ $mol_fail_hidden(result);
1296
+ }
1297
+ }
1298
+ }
1299
+ $.$mol_wire_fiber = $mol_wire_fiber;
1300
+ })($ || ($ = {}));
1301
+
1302
+ ;
1303
+ "use strict";
1304
+ var $;
1305
+ (function ($) {
1306
+ $.$mol_compare_deep_cache = new WeakMap();
1307
+ function $mol_compare_deep(left, right) {
1308
+ if (Object.is(left, right))
1309
+ return true;
1310
+ if (left === null)
1311
+ return false;
1312
+ if (right === null)
1313
+ return false;
1314
+ if (typeof left !== 'object')
1315
+ return false;
1316
+ if (typeof right !== 'object')
1317
+ return false;
1318
+ const left_proto = Reflect.getPrototypeOf(left);
1319
+ const right_proto = Reflect.getPrototypeOf(right);
1320
+ if (left_proto !== right_proto)
1321
+ return false;
1322
+ if (left instanceof Boolean)
1323
+ return Object.is(left.valueOf(), right['valueOf']());
1324
+ if (left instanceof Number)
1325
+ return Object.is(left.valueOf(), right['valueOf']());
1326
+ if (left instanceof String)
1327
+ return Object.is(left.valueOf(), right['valueOf']());
1328
+ if (left instanceof Date)
1329
+ return Object.is(left.valueOf(), right['valueOf']());
1330
+ if (left instanceof RegExp)
1331
+ return left.source === right.source && left.flags === right.flags;
1332
+ if (left instanceof Error)
1333
+ return left.message === right.message && $mol_compare_deep(left.stack, right.stack);
1334
+ let left_cache = $.$mol_compare_deep_cache.get(left);
1335
+ if (left_cache) {
1336
+ const right_cache = left_cache.get(right);
1337
+ if (typeof right_cache === 'boolean')
1338
+ return right_cache;
1339
+ }
1340
+ else {
1341
+ left_cache = new WeakMap();
1342
+ $.$mol_compare_deep_cache.set(left, left_cache);
1343
+ }
1344
+ left_cache.set(right, true);
1345
+ let result;
1346
+ try {
1347
+ if (!left_proto)
1348
+ result = compare_pojo(left, right);
1349
+ else if (!Reflect.getPrototypeOf(left_proto))
1350
+ result = compare_pojo(left, right);
1351
+ else if (Symbol.toPrimitive in left)
1352
+ result = compare_primitive(left, right);
1353
+ else if (Array.isArray(left))
1354
+ result = compare_array(left, right);
1355
+ else if (left instanceof Set)
1356
+ result = compare_set(left, right);
1357
+ else if (left instanceof Map)
1358
+ result = compare_map(left, right);
1359
+ else if (ArrayBuffer.isView(left))
1360
+ result = compare_buffer(left, right);
1361
+ else if (Symbol.iterator in left)
1362
+ result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
1363
+ else
1364
+ result = false;
1365
+ }
1366
+ finally {
1367
+ left_cache.set(right, result);
1368
+ }
1369
+ return result;
1370
+ }
1371
+ $.$mol_compare_deep = $mol_compare_deep;
1372
+ function compare_array(left, right) {
1373
+ const len = left.length;
1374
+ if (len !== right.length)
1375
+ return false;
1376
+ for (let i = 0; i < len; ++i) {
1377
+ if (!$mol_compare_deep(left[i], right[i]))
1378
+ return false;
1379
+ }
1380
+ return true;
1381
+ }
1382
+ function compare_buffer(left, right) {
1383
+ const len = left.byteLength;
1384
+ if (len !== right.byteLength)
1385
+ return false;
1386
+ if (left instanceof DataView)
1387
+ return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, right.byteOffset, right.byteLength));
1388
+ for (let i = 0; i < len; ++i) {
1389
+ if (left[i] !== right[i])
1390
+ return false;
1391
+ }
1392
+ return true;
1393
+ }
1394
+ function compare_iterator(left, right) {
1395
+ while (true) {
1396
+ const left_next = left.next();
1397
+ const right_next = right.next();
1398
+ if (left_next.done !== right_next.done)
1399
+ return false;
1400
+ if (left_next.done)
1401
+ break;
1402
+ if (!$mol_compare_deep(left_next.value, right_next.value))
1403
+ return false;
1404
+ }
1405
+ return true;
1406
+ }
1407
+ function compare_set(left, right) {
1408
+ if (left.size !== right.size)
1409
+ return false;
1410
+ return compare_iterator(left.values(), right.values());
1411
+ }
1412
+ function compare_map(left, right) {
1413
+ if (left.size !== right.size)
1414
+ return false;
1415
+ return compare_iterator(left.keys(), right.keys())
1416
+ && compare_iterator(left.values(), right.values());
1417
+ }
1418
+ function compare_pojo(left, right) {
1419
+ const left_keys = Object.getOwnPropertyNames(left);
1420
+ const right_keys = Object.getOwnPropertyNames(right);
1421
+ if (!compare_array(left_keys, right_keys))
1422
+ return false;
1423
+ for (let key of left_keys) {
1424
+ if (!$mol_compare_deep(left[key], right[key]))
1425
+ return false;
1426
+ }
1427
+ const left_syms = Object.getOwnPropertySymbols(left);
1428
+ const right_syms = Object.getOwnPropertySymbols(right);
1429
+ if (!compare_array(left_syms, right_syms))
1430
+ return false;
1431
+ for (let key of left_syms) {
1432
+ if (!$mol_compare_deep(left[key], right[key]))
1433
+ return false;
1434
+ }
1435
+ return true;
1436
+ }
1437
+ function compare_primitive(left, right) {
1438
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
1439
+ }
1440
+ })($ || ($ = {}));
1441
+
1442
+ ;
1443
+ "use strict";
1444
+ var $;
1445
+ (function ($) {
1446
+ function $mol_log3_area_lazy(event) {
1447
+ const self = this.$;
1448
+ const stack = self.$mol_log3_stack;
1449
+ const deep = stack.length;
1450
+ let logged = false;
1451
+ stack.push(() => {
1452
+ logged = true;
1453
+ self.$mol_log3_area.call(self, event);
1454
+ });
1455
+ return () => {
1456
+ if (logged)
1457
+ self.console.groupEnd();
1458
+ if (stack.length > deep)
1459
+ stack.length = deep;
1460
+ };
1461
+ }
1462
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1463
+ $.$mol_log3_stack = [];
1464
+ })($ || ($ = {}));
1465
+
1466
+ ;
1467
+ "use strict";
1468
+ var $;
1469
+ (function ($) {
1470
+ class $mol_span extends $mol_object2 {
1471
+ uri;
1472
+ source;
1473
+ row;
1474
+ col;
1475
+ length;
1476
+ constructor(uri, source, row, col, length) {
1477
+ super();
1478
+ this.uri = uri;
1479
+ this.source = source;
1480
+ this.row = row;
1481
+ this.col = col;
1482
+ this.length = length;
1483
+ this[Symbol.toStringTag] = this.uri + ('#' + this.row + ':' + this.col + '/' + this.length);
1484
+ }
1485
+ static unknown = $mol_span.begin('?');
1486
+ static begin(uri, source = '') {
1487
+ return new $mol_span(uri, source, 1, 1, 0);
1488
+ }
1489
+ static end(uri, source) {
1490
+ return new $mol_span(uri, source, 1, source.length + 1, 0);
1491
+ }
1492
+ static entire(uri, source) {
1493
+ return new $mol_span(uri, source, 1, 1, source.length);
1494
+ }
1495
+ toString() {
1496
+ return this[Symbol.toStringTag];
1497
+ }
1498
+ toJSON() {
1499
+ return {
1500
+ uri: this.uri,
1501
+ row: this.row,
1502
+ col: this.col,
1503
+ length: this.length
1504
+ };
1505
+ }
1506
+ error(message, Class = Error) {
1507
+ return new Class(`${message} (${this})`);
1508
+ }
1509
+ span(row, col, length) {
1510
+ return new $mol_span(this.uri, this.source, row, col, length);
1511
+ }
1512
+ after(length = 0) {
1513
+ return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
1514
+ }
1515
+ slice(begin, end = -1) {
1516
+ let len = this.length;
1517
+ if (begin < 0)
1518
+ begin += len;
1519
+ if (end < 0)
1520
+ end += len;
1521
+ if (begin < 0 || begin > len)
1522
+ this.$.$mol_fail(this.error(`Begin value '${begin}' out of range`, RangeError));
1523
+ if (end < 0 || end > len)
1524
+ this.$.$mol_fail(this.error(`End value '${end}' out of range`, RangeError));
1525
+ if (end < begin)
1526
+ this.$.$mol_fail(this.error(`End value '${end}' can't be less than begin value`, RangeError));
1527
+ return this.span(this.row, this.col + begin, end - begin);
1528
+ }
1529
+ }
1530
+ $.$mol_span = $mol_span;
1531
+ })($ || ($ = {}));
1532
+
1533
+ ;
1534
+ "use strict";
1535
+ var $;
1536
+ (function ($) {
1537
+ function $mol_tree2_to_string(tree) {
1538
+ let output = [];
1539
+ function dump(tree, prefix = '') {
1540
+ if (tree.type.length) {
1541
+ if (!prefix.length) {
1542
+ prefix = "\t";
1543
+ }
1544
+ output.push(tree.type);
1545
+ if (tree.kids.length == 1) {
1546
+ output.push(' ');
1547
+ dump(tree.kids[0], prefix);
1548
+ return;
1549
+ }
1550
+ output.push("\n");
1551
+ }
1552
+ else if (tree.value.length || prefix.length) {
1553
+ output.push("\\" + tree.value + "\n");
1554
+ }
1555
+ for (const kid of tree.kids) {
1556
+ output.push(prefix);
1557
+ dump(kid, prefix + "\t");
1558
+ }
1559
+ }
1560
+ dump(tree);
1561
+ return output.join('');
1562
+ }
1563
+ $.$mol_tree2_to_string = $mol_tree2_to_string;
1564
+ })($ || ($ = {}));
1565
+
1566
+ ;
1567
+ "use strict";
1568
+ var $;
1569
+ (function ($) {
1570
+ function $mol_maybe(value) {
1571
+ return (value == null) ? [] : [value];
1572
+ }
1573
+ $.$mol_maybe = $mol_maybe;
1574
+ })($ || ($ = {}));
1575
+
1576
+ ;
1577
+ "use strict";
1578
+ var $;
1579
+ (function ($) {
1580
+ class $mol_tree2 extends Object {
1581
+ type;
1582
+ value;
1583
+ kids;
1584
+ span;
1585
+ constructor(type, value, kids, span) {
1586
+ super();
1587
+ this.type = type;
1588
+ this.value = value;
1589
+ this.kids = kids;
1590
+ this.span = span;
1591
+ this[Symbol.toStringTag] = type || '\\' + value;
1592
+ }
1593
+ static list(kids, span = $mol_span.unknown) {
1594
+ return new $mol_tree2('', '', kids, span);
1595
+ }
1596
+ list(kids) {
1597
+ return $mol_tree2.list(kids, this.span);
1598
+ }
1599
+ static data(value, kids = [], span = $mol_span.unknown) {
1600
+ const chunks = value.split('\n');
1601
+ if (chunks.length > 1) {
1602
+ let kid_span = span.span(span.row, span.col, 0);
1603
+ const data = chunks.map(chunk => {
1604
+ kid_span = kid_span.after(chunk.length);
1605
+ return new $mol_tree2('', chunk, [], kid_span);
1606
+ });
1607
+ kids = [...data, ...kids];
1608
+ value = '';
1609
+ }
1610
+ return new $mol_tree2('', value, kids, span);
1611
+ }
1612
+ data(value, kids = []) {
1613
+ return $mol_tree2.data(value, kids, this.span);
1614
+ }
1615
+ static struct(type, kids = [], span = $mol_span.unknown) {
1616
+ if (/[ \n\t\\]/.test(type)) {
1617
+ $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
1618
+ }
1619
+ return new $mol_tree2(type, '', kids, span);
1620
+ }
1621
+ struct(type, kids = []) {
1622
+ return $mol_tree2.struct(type, kids, this.span);
1623
+ }
1624
+ clone(kids, span = this.span) {
1625
+ return new $mol_tree2(this.type, this.value, kids, span);
1626
+ }
1627
+ text() {
1628
+ var values = [];
1629
+ for (var kid of this.kids) {
1630
+ if (kid.type)
1631
+ continue;
1632
+ values.push(kid.value);
1633
+ }
1634
+ return this.value + values.join('\n');
1635
+ }
1636
+ static fromString(str, uri = 'unknown') {
1637
+ return $$.$mol_tree2_from_string(str, uri);
1638
+ }
1639
+ toString() {
1640
+ return $$.$mol_tree2_to_string(this);
1641
+ }
1642
+ insert(value, ...path) {
1643
+ return this.update($mol_maybe(value), ...path)[0];
1644
+ }
1645
+ update(value, ...path) {
1646
+ if (path.length === 0)
1647
+ return value;
1648
+ const type = path[0];
1649
+ if (typeof type === 'string') {
1650
+ let replaced = false;
1651
+ const sub = this.kids.flatMap((item, index) => {
1652
+ if (item.type !== type)
1653
+ return item;
1654
+ replaced = true;
1655
+ return item.update(value, ...path.slice(1));
1656
+ }).filter(Boolean);
1657
+ if (!replaced && value) {
1658
+ sub.push(...this.struct(type, []).update(value, ...path.slice(1)));
1659
+ }
1660
+ return [this.clone(sub)];
1661
+ }
1662
+ else if (typeof type === 'number') {
1663
+ const ins = (this.kids[type] || this.list([]))
1664
+ .update(value, ...path.slice(1));
1665
+ return [this.clone([
1666
+ ...this.kids.slice(0, type),
1667
+ ...ins,
1668
+ ...this.kids.slice(type + 1),
1669
+ ])];
1670
+ }
1671
+ else {
1672
+ const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
1673
+ .flatMap(item => item.update(value, ...path.slice(1)));
1674
+ return [this.clone(kids)];
1675
+ }
1676
+ }
1677
+ select(...path) {
1678
+ let next = [this];
1679
+ for (const type of path) {
1680
+ if (!next.length)
1681
+ break;
1682
+ const prev = next;
1683
+ next = [];
1684
+ for (var item of prev) {
1685
+ switch (typeof (type)) {
1686
+ case 'string':
1687
+ for (var child of item.kids) {
1688
+ if (child.type == type) {
1689
+ next.push(child);
1690
+ }
1691
+ }
1692
+ break;
1693
+ case 'number':
1694
+ if (type < item.kids.length)
1695
+ next.push(item.kids[type]);
1696
+ break;
1697
+ default: next.push(...item.kids);
1698
+ }
1699
+ }
1700
+ }
1701
+ return this.list(next);
1702
+ }
1703
+ filter(path, value) {
1704
+ const sub = this.kids.filter(item => {
1705
+ var found = item.select(...path);
1706
+ if (value === undefined) {
1707
+ return Boolean(found.kids.length);
1708
+ }
1709
+ else {
1710
+ return found.kids.some(child => child.value == value);
1711
+ }
1712
+ });
1713
+ return this.clone(sub);
1714
+ }
1715
+ hack_self(belt, context = {}) {
1716
+ let handle = belt[this.type] || belt[''];
1717
+ if (!handle || handle === Object.prototype[this.type]) {
1718
+ handle = (input, belt, context) => [
1719
+ input.clone(input.hack(belt, context), context.span)
1720
+ ];
1721
+ }
1722
+ try {
1723
+ return handle(this, belt, context);
1724
+ }
1725
+ catch (error) {
1726
+ error.message += `\n${this.clone([])}${this.span}`;
1727
+ $mol_fail_hidden(error);
1728
+ }
1729
+ }
1730
+ hack(belt, context = {}) {
1731
+ return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
1732
+ }
1733
+ error(message, Class = Error) {
1734
+ return this.span.error(`${message}\n${this.clone([])}`, Class);
1735
+ }
1736
+ }
1737
+ $.$mol_tree2 = $mol_tree2;
1738
+ class $mol_tree2_empty extends $mol_tree2 {
1739
+ constructor() {
1740
+ super('', '', [], $mol_span.unknown);
1741
+ }
1742
+ }
1743
+ $.$mol_tree2_empty = $mol_tree2_empty;
1744
+ })($ || ($ = {}));
1745
+
1746
+ ;
1747
+ "use strict";
1748
+ var $;
1749
+ (function ($) {
1750
+ class $mol_error_syntax extends SyntaxError {
1751
+ reason;
1752
+ line;
1753
+ span;
1754
+ constructor(reason, line, span) {
1755
+ super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
1756
+ this.reason = reason;
1757
+ this.line = line;
1758
+ this.span = span;
1759
+ }
1760
+ }
1761
+ $.$mol_error_syntax = $mol_error_syntax;
1762
+ })($ || ($ = {}));
1763
+
1764
+ ;
1765
+ "use strict";
1766
+ var $;
1767
+ (function ($) {
1768
+ function $mol_tree2_from_string(str, uri = '?') {
1769
+ const span = $mol_span.entire(uri, str);
1770
+ var root = $mol_tree2.list([], span);
1771
+ var stack = [root];
1772
+ var pos = 0, row = 0, min_indent = 0;
1773
+ while (str.length > pos) {
1774
+ var indent = 0;
1775
+ var line_start = pos;
1776
+ row++;
1777
+ while (str.length > pos && str[pos] == '\t') {
1778
+ indent++;
1779
+ pos++;
1780
+ }
1781
+ if (!root.kids.length) {
1782
+ min_indent = indent;
1783
+ }
1784
+ indent -= min_indent;
1785
+ if (indent < 0 || indent >= stack.length) {
1786
+ const sp = span.span(row, 1, pos - line_start);
1787
+ while (str.length > pos && str[pos] != '\n') {
1788
+ pos++;
1789
+ }
1790
+ if (indent < 0) {
1791
+ if (str.length > pos) {
1792
+ this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
1793
+ }
1794
+ }
1795
+ else {
1796
+ this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
1797
+ }
1798
+ }
1799
+ stack.length = indent + 1;
1800
+ var parent = stack[indent];
1801
+ while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
1802
+ var error_start = pos;
1803
+ while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
1804
+ pos++;
1805
+ }
1806
+ if (pos > error_start) {
1807
+ let line_end = str.indexOf('\n', pos);
1808
+ if (line_end === -1)
1809
+ line_end = str.length;
1810
+ const sp = span.span(row, error_start - line_start + 1, pos - error_start);
1811
+ this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
1812
+ }
1813
+ var type_start = pos;
1814
+ while (str.length > pos &&
1815
+ str[pos] != '\\' &&
1816
+ str[pos] != ' ' &&
1817
+ str[pos] != '\t' &&
1818
+ str[pos] != '\n') {
1819
+ pos++;
1820
+ }
1821
+ if (pos > type_start) {
1822
+ let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
1823
+ const parent_kids = parent.kids;
1824
+ parent_kids.push(next);
1825
+ parent = next;
1826
+ }
1827
+ if (str.length > pos && str[pos] == ' ') {
1828
+ pos++;
1829
+ }
1830
+ }
1831
+ if (str.length > pos && str[pos] == '\\') {
1832
+ var data_start = pos;
1833
+ while (str.length > pos && str[pos] != '\n') {
1834
+ pos++;
1835
+ }
1836
+ let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
1837
+ const parent_kids = parent.kids;
1838
+ parent_kids.push(next);
1839
+ parent = next;
1840
+ }
1841
+ if (str.length === pos && stack.length > 0) {
1842
+ const sp = span.span(row, pos - line_start + 1, 1);
1843
+ this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
1844
+ }
1845
+ stack.push(parent);
1846
+ pos++;
1847
+ }
1848
+ return root;
1849
+ }
1850
+ $.$mol_tree2_from_string = $mol_tree2_from_string;
1851
+ })($ || ($ = {}));
1852
+
1853
+ ;
1854
+ "use strict";
1855
+ var $;
1856
+ (function ($) {
1857
+ function $mol_tree2_from_json(json, span = $mol_span.unknown) {
1858
+ if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
1859
+ return new $mol_tree2(String(json), '', [], span);
1860
+ }
1861
+ if (typeof json === 'string') {
1862
+ return $mol_tree2.data(json, [], span);
1863
+ }
1864
+ if (typeof json.toJSON === 'function') {
1865
+ return $mol_tree2_from_json(json.toJSON());
1866
+ }
1867
+ if (Array.isArray(json)) {
1868
+ const sub = json.map(json => $mol_tree2_from_json(json, span));
1869
+ return new $mol_tree2('/', '', sub, span);
1870
+ }
1871
+ if (ArrayBuffer.isView(json)) {
1872
+ const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
1873
+ return $mol_tree2.data(String.fromCharCode(...buf), [], span);
1874
+ }
1875
+ if (json instanceof Date) {
1876
+ return new $mol_tree2('', json.toISOString(), [], span);
1877
+ }
1878
+ if (json.toString !== Object.prototype.toString) {
1879
+ return $mol_tree2.data(json.toString(), [], span);
1880
+ }
1881
+ if (json instanceof Error) {
1882
+ const { name, message, stack } = json;
1883
+ json = { ...json, name, message, stack };
1884
+ }
1885
+ const sub = [];
1886
+ for (var key in json) {
1887
+ const val = json[key];
1888
+ if (val === undefined)
1889
+ continue;
1890
+ const subsub = $mol_tree2_from_json(val, span);
1891
+ if (/^[^\n\t\\ ]+$/.test(key)) {
1892
+ sub.push(new $mol_tree2(key, '', [subsub], span));
1893
+ }
1894
+ else {
1895
+ sub.push($mol_tree2.data(key, [subsub], span));
1896
+ }
1897
+ }
1898
+ return new $mol_tree2('*', '', sub, span);
1899
+ }
1900
+ $.$mol_tree2_from_json = $mol_tree2_from_json;
1901
+ })($ || ($ = {}));
1902
+
1903
+ ;
1904
+ "use strict";
1905
+ var $;
1906
+ (function ($) {
1907
+ class $mol_term_color {
1908
+ static reset = this.ansi(0, 0);
1909
+ static bold = this.ansi(1, 22);
1910
+ static italic = this.ansi(3, 23);
1911
+ static underline = this.ansi(4, 24);
1912
+ static inverse = this.ansi(7, 27);
1913
+ static hidden = this.ansi(8, 28);
1914
+ static strike = this.ansi(9, 29);
1915
+ static gray = this.ansi(90, 39);
1916
+ static red = this.ansi(91, 39);
1917
+ static green = this.ansi(92, 39);
1918
+ static yellow = this.ansi(93, 39);
1919
+ static blue = this.ansi(94, 39);
1920
+ static magenta = this.ansi(95, 39);
1921
+ static cyan = this.ansi(96, 39);
1922
+ static Gray = (str) => this.inverse(this.gray(str));
1923
+ static Red = (str) => this.inverse(this.red(str));
1924
+ static Green = (str) => this.inverse(this.green(str));
1925
+ static Yellow = (str) => this.inverse(this.yellow(str));
1926
+ static Blue = (str) => this.inverse(this.blue(str));
1927
+ static Magenta = (str) => this.inverse(this.magenta(str));
1928
+ static Cyan = (str) => this.inverse(this.cyan(str));
1929
+ static ansi(open, close) {
1930
+ if (typeof process === 'undefined')
1931
+ return String;
1932
+ if (!process.stdout.isTTY)
1933
+ return String;
1934
+ const prefix = `\x1b[${open}m`;
1935
+ const postfix = `\x1b[${close}m`;
1936
+ const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
1937
+ return function colorer(str) {
1938
+ str = String(str);
1939
+ if (str === '')
1940
+ return str;
1941
+ const suffix = str.replace(suffix_regexp, prefix);
1942
+ return prefix + suffix + postfix;
1943
+ };
1944
+ }
1945
+ }
1946
+ $.$mol_term_color = $mol_term_color;
1947
+ })($ || ($ = {}));
1948
+
1949
+ ;
1950
+ "use strict";
1951
+ var $;
1952
+ (function ($) {
1953
+ function $mol_log3_node_make(level, output, type, color) {
1954
+ return function $mol_log3_logger(event) {
1955
+ if (!event.time)
1956
+ event = { time: new Date().toISOString(), ...event };
1957
+ let tree = this.$mol_tree2_from_json(event);
1958
+ tree = tree.struct(type, tree.kids);
1959
+ let str = color(tree.toString());
1960
+ this.console[level](str);
1961
+ const self = this;
1962
+ return () => self.console.groupEnd();
1963
+ };
1964
+ }
1965
+ $.$mol_log3_node_make = $mol_log3_node_make;
1966
+ $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
1967
+ $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
1968
+ $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
1969
+ $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
1970
+ $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
1971
+ $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
1972
+ })($ || ($ = {}));
1973
+
1974
+ ;
1975
+ "use strict";
1976
+ var $;
1977
+ (function ($) {
1978
+ class $mol_wire_task extends $mol_wire_fiber {
1979
+ static getter(task) {
1980
+ return function $mol_wire_task_get(host, args) {
1981
+ const sub = $mol_wire_auto();
1982
+ const existen = sub?.track_next();
1983
+ let cause = '';
1984
+ reuse: if (existen) {
1985
+ if (!existen.temp)
1986
+ break reuse;
1987
+ if (existen.task !== task) {
1988
+ cause = 'task';
1989
+ break reuse;
1990
+ }
1991
+ if (existen.host !== host) {
1992
+ cause = 'host';
1993
+ break reuse;
1994
+ }
1995
+ if (!$mol_compare_deep(existen.args, args)) {
1996
+ cause = 'args';
1997
+ break reuse;
1998
+ }
1999
+ return existen;
2000
+ }
2001
+ const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
2002
+ const next = new $mol_wire_task(key, task, host, args);
2003
+ if (existen?.temp) {
2004
+ $$.$mol_log3_warn({
2005
+ place: '$mol_wire_task',
2006
+ message: `Different ${cause} on restart`,
2007
+ sub,
2008
+ prev: existen,
2009
+ next,
2010
+ hint: 'Maybe required additional memoization',
2011
+ });
2012
+ }
2013
+ return next;
2014
+ };
2015
+ }
2016
+ get temp() {
2017
+ return true;
2018
+ }
2019
+ complete() {
2020
+ if ($mol_promise_like(this.cache))
2021
+ return;
2022
+ this.destructor();
2023
+ }
2024
+ put(next) {
2025
+ const prev = this.cache;
2026
+ this.cache = next;
2027
+ if ($mol_promise_like(next)) {
2028
+ this.cursor = $mol_wire_cursor.fresh;
2029
+ if (next !== prev)
2030
+ this.emit();
2031
+ if ($mol_owning_catch(this, next)) {
2032
+ try {
2033
+ next[Symbol.toStringTag] = this[Symbol.toStringTag];
2034
+ }
2035
+ catch {
2036
+ Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
2037
+ }
2038
+ }
2039
+ return next;
2040
+ }
2041
+ this.cursor = $mol_wire_cursor.final;
2042
+ if (this.sub_empty)
2043
+ this.destructor();
2044
+ else if (next !== prev)
2045
+ this.emit();
2046
+ return next;
2047
+ }
2048
+ destructor() {
2049
+ super.destructor();
2050
+ this.cursor = $mol_wire_cursor.final;
2051
+ }
2052
+ }
2053
+ $.$mol_wire_task = $mol_wire_task;
2054
+ })($ || ($ = {}));
2055
+
2056
+ ;
2057
+ "use strict";
2058
+ var $;
2059
+ (function ($) {
2060
+ const factories = new WeakMap();
2061
+ function factory(val) {
2062
+ let make = factories.get(val);
2063
+ if (make)
2064
+ return make;
2065
+ make = $mol_func_name_from((...args) => new val(...args), val);
2066
+ factories.set(val, make);
2067
+ return make;
2068
+ }
2069
+ const getters = new WeakMap();
2070
+ function get_prop(host, field) {
2071
+ let props = getters.get(host);
2072
+ let get_val = props?.[field];
2073
+ if (get_val)
2074
+ return get_val;
2075
+ get_val = (next) => {
2076
+ if (next !== undefined)
2077
+ host[field] = next;
2078
+ return host[field];
2079
+ };
2080
+ Object.defineProperty(get_val, 'name', { value: field });
2081
+ if (!props) {
2082
+ props = {};
2083
+ getters.set(host, props);
2084
+ }
2085
+ props[field] = get_val;
2086
+ return get_val;
2087
+ }
2088
+ function $mol_wire_sync(obj) {
2089
+ return new Proxy(obj, {
2090
+ get(obj, field) {
2091
+ let val = obj[field];
2092
+ const temp = $mol_wire_task.getter(typeof val === 'function' ? val : get_prop(obj, field));
2093
+ if (typeof val !== 'function')
2094
+ return temp(obj, []).sync();
2095
+ return function $mol_wire_sync(...args) {
2096
+ const fiber = temp(obj, args);
2097
+ return fiber.sync();
2098
+ };
2099
+ },
2100
+ set(obj, field, next) {
2101
+ const temp = $mol_wire_task.getter(get_prop(obj, field));
2102
+ temp(obj, [next]).sync();
2103
+ return true;
2104
+ },
2105
+ construct(obj, args) {
2106
+ const temp = $mol_wire_task.getter(factory(obj));
2107
+ return temp(obj, args).sync();
2108
+ },
2109
+ apply(obj, self, args) {
2110
+ const temp = $mol_wire_task.getter(obj);
2111
+ return temp(self, args).sync();
2112
+ },
2113
+ });
2114
+ }
2115
+ $.$mol_wire_sync = $mol_wire_sync;
2116
+ })($ || ($ = {}));
2117
+
2118
+ ;
2119
+ "use strict";
2120
+ var $;
2121
+ (function ($) {
2122
+ class $mol_run_error extends $mol_error_mix {
2123
+ }
2124
+ $.$mol_run_error = $mol_run_error;
2125
+ $.$mol_run_spawn = (...args) => $node['child_process'].spawn(...args);
2126
+ $.$mol_run_spawn_sync = (...args) => $node['child_process'].spawnSync(...args);
2127
+ class $mol_run extends $mol_object {
2128
+ static async_enabled() {
2129
+ return Boolean(this.$.$mol_env()['MOL_RUN_ASYNC']);
2130
+ }
2131
+ static spawn(options) {
2132
+ const sync = !this.async_enabled() || !Boolean($mol_wire_auto());
2133
+ const env = options.env ?? this.$.$mol_env();
2134
+ return $mol_wire_sync(this).spawn_async({ ...options, sync, env });
2135
+ }
2136
+ static spawn_async({ dir, sync, timeout, command, env }) {
2137
+ const args_raw = typeof command === 'string' ? command.split(' ') : command;
2138
+ const [app, ...args] = args_raw;
2139
+ const opts = { shell: true, cwd: dir, env };
2140
+ const log_object = {
2141
+ place: `${this}.spawn()`,
2142
+ message: 'Run',
2143
+ command: args_raw.join(' '),
2144
+ dir: $node.path.relative('', dir),
2145
+ };
2146
+ if (sync) {
2147
+ this.$.$mol_log3_come({
2148
+ hint: 'Run inside fiber',
2149
+ ...log_object
2150
+ });
2151
+ let error;
2152
+ let res;
2153
+ try {
2154
+ res = this.$.$mol_run_spawn_sync(app, args, opts);
2155
+ error = res.error;
2156
+ }
2157
+ catch (err) {
2158
+ error = err;
2159
+ }
2160
+ if (!res || error || res.status) {
2161
+ throw new $mol_run_error(this.error_message(res), { ...log_object, status: res?.status, signal: res?.signal }, ...(error ? [error] : []));
2162
+ }
2163
+ return res;
2164
+ }
2165
+ let sub;
2166
+ try {
2167
+ sub = this.$.$mol_run_spawn(app, args, {
2168
+ ...opts,
2169
+ stdio: ['pipe', 'inherit', 'inherit'],
2170
+ });
2171
+ }
2172
+ catch (error) {
2173
+ throw new $mol_run_error(this.error_message(undefined), log_object, error);
2174
+ }
2175
+ const pid = sub.pid ?? 0;
2176
+ this.$.$mol_log3_come({
2177
+ ...log_object,
2178
+ pid,
2179
+ });
2180
+ let timeout_kill = false;
2181
+ let timer;
2182
+ const std_data = [];
2183
+ const error_data = [];
2184
+ const add = (std_chunk, error_chunk) => {
2185
+ if (std_chunk)
2186
+ std_data.push(std_chunk);
2187
+ if (error_chunk)
2188
+ error_data.push(error_chunk);
2189
+ if (!timeout)
2190
+ return;
2191
+ clearTimeout(timer);
2192
+ timer = setTimeout(() => {
2193
+ const signal = timeout_kill ? 'SIGKILL' : 'SIGTERM';
2194
+ timeout_kill = true;
2195
+ add();
2196
+ sub.kill(signal);
2197
+ }, timeout);
2198
+ };
2199
+ add();
2200
+ sub.stdout?.on('data', data => add(data));
2201
+ sub.stderr?.on('data', data => add(undefined, data));
2202
+ const result_promise = new Promise((done, fail) => {
2203
+ const close = (error, status = null, signal = null) => {
2204
+ if (!timer && timeout)
2205
+ return;
2206
+ clearTimeout(timer);
2207
+ timer = undefined;
2208
+ const res = {
2209
+ pid,
2210
+ signal,
2211
+ get stdout() { return Buffer.concat(std_data); },
2212
+ get stderr() { return Buffer.concat(error_data); }
2213
+ };
2214
+ if (error || status || timeout_kill)
2215
+ return fail(new $mol_run_error(this.error_message(res) + (timeout_kill ? ', timeout' : ''), { ...log_object, pid, status, signal, timeout_kill }, ...error ? [error] : []));
2216
+ this.$.$mol_log3_done({
2217
+ ...log_object,
2218
+ pid,
2219
+ });
2220
+ done(res);
2221
+ };
2222
+ sub.on('disconnect', () => close(new Error('Disconnected')));
2223
+ sub.on('error', err => close(err));
2224
+ sub.on('exit', (status, signal) => close(null, status, signal));
2225
+ });
2226
+ return Object.assign(result_promise, { destructor: () => {
2227
+ clearTimeout(timer);
2228
+ sub.kill('SIGKILL');
2229
+ } });
2230
+ }
2231
+ static error_message(res) {
2232
+ return res?.stderr.toString() || res?.stdout.toString() || 'Run error';
2233
+ }
2234
+ }
2235
+ $.$mol_run = $mol_run;
2236
+ })($ || ($ = {}));
2237
+
2238
+ ;
2239
+ "use strict";
2240
+ var $;
2241
+ (function ($) {
2242
+ function $mol_exec(dir, command, ...args) {
2243
+ return this.$mol_run.spawn({ command: [command, ...args], dir });
2244
+ }
2245
+ $.$mol_exec = $mol_exec;
2246
+ })($ || ($ = {}));
2247
+
2248
+ ;
2249
+ "use strict";
2250
+ var $;
2251
+ (function ($) {
2252
+ $.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
2253
+ })($ || ($ = {}));
2254
+
2255
+ ;
2256
+ "use strict";
2257
+ var $;
2258
+ (function ($) {
2259
+ $.$mol_dom = $mol_dom_context;
2260
+ })($ || ($ = {}));
2261
+
168
2262
  ;
169
2263
  "use strict";
170
2264
  var $;
@@ -276,7 +2370,7 @@ var $;
276
2370
  pos += 8;
277
2371
  }
278
2372
  else {
279
- $mol_fail(new Error('Number too high', { cause: val }));
2373
+ $mol_fail(new Error('Number too high', { cause: { val } }));
280
2374
  }
281
2375
  };
282
2376
  const dump_string = (val) => {
@@ -347,10 +2441,8 @@ var $;
347
2441
  const offset = offsets.get(val);
348
2442
  if (offset !== undefined)
349
2443
  return dump_unum($mol_vary_tip.link, offset);
350
- const proto = Reflect.getPrototypeOf(val);
351
- const lean = this.leanes.get(proto);
352
- const keys = lean ? this.keys.get(proto) : Object.keys(val);
353
- const vals = lean ? lean(val) : Object.values(val);
2444
+ const keys = val[$.$mol_vary_keys] ?? Object.keys(val);
2445
+ const vals = val[$.$mol_vary_lean]?.(val) ?? Object.values(val);
354
2446
  dump_unum($mol_vary_tip.tupl, vals.length);
355
2447
  acquire(vals.length * 2 * 9);
356
2448
  for (const item of keys)
@@ -589,22 +2681,34 @@ var $;
589
2681
  };
590
2682
  return read_vary();
591
2683
  }
592
- static leanes = new Map();
593
- static keys = new Map();
594
2684
  static riches = new Map();
595
- static type(keys, rich, lean) {
596
- const obj = rich();
597
- const proto = Reflect.getPrototypeOf(obj);
598
- const shape = JSON.stringify(keys);
599
- this.leanes.set(proto, lean);
600
- this.keys.set(proto, keys);
601
- this.riches.set(shape, rich);
2685
+ static type(Class, keys, lean, rich) {
2686
+ this.riches.set(JSON.stringify(keys), rich);
2687
+ Class.prototype[$.$mol_vary_lean] = lean;
2688
+ Class.prototype[$.$mol_vary_keys] = keys;
602
2689
  }
603
2690
  }
604
2691
  $.$mol_vary = $mol_vary;
605
- $mol_vary.type(['keys', 'vals'], (keys = [], vals = []) => new Map(keys.map((k, i) => [k, vals[i]])), obj => [[...obj.keys()], [...obj.values()]]);
606
- $mol_vary.type(['set'], (vals = []) => new Set(vals), obj => [[...obj.values()]]);
607
- $mol_vary.type(['unix_time'], (ts = 0) => new Date(ts * 1000), obj => [obj.valueOf() / 1000]);
2692
+ $.$mol_vary_lean = Symbol.for('$mol_vary_lean');
2693
+ $.$mol_vary_keys = Symbol.for('$mol_vary_keys');
2694
+ $mol_vary.type(Map, ['keys', 'vals'], obj => [[...obj.keys()], [...obj.values()]], (keys, vals) => new Map(keys.map((k, i) => [k, vals[i]])));
2695
+ $mol_vary.type(Set, ['set'], obj => [[...obj.values()]], vals => new Set(vals));
2696
+ $mol_vary.type(Date, ['unix_time'], obj => [obj.valueOf() / 1000], ts => new Date(ts * 1000));
2697
+ $mol_vary.type($mol_dom.Element, ['elem', 'keys', 'vals', 'kids'], node => {
2698
+ const attrs = [...node.attributes];
2699
+ const kids = [...node.childNodes].map(kid => kid instanceof $mol_dom.Text ? kid.nodeValue : kid);
2700
+ return [node.nodeName, attrs.map(attr => attr.nodeName), attrs.map(attr => attr.nodeValue), kids];
2701
+ }, (name, keys, vals, kids) => {
2702
+ const el = $mol_dom.document.createElement(name);
2703
+ for (let i = 0; i < keys.length; ++i)
2704
+ el.setAttribute(keys[i], vals[i]);
2705
+ for (let kid of kids) {
2706
+ if (typeof kid === 'string')
2707
+ kid = $mol_dom.document.createTextNode(kid);
2708
+ el.appendChild(kid);
2709
+ }
2710
+ return el;
2711
+ });
608
2712
  })($ || ($ = {}));
609
2713
 
610
2714