mol_jsx_lib 0.0.1102 → 0.0.1104

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.test.js CHANGED
@@ -208,30 +208,6 @@ var $;
208
208
  $.$mol_error_mix = $mol_error_mix;
209
209
  })($ || ($ = {}));
210
210
 
211
- ;
212
- "use strict";
213
- var $;
214
- (function ($) {
215
- function $mol_log3_area_lazy(event) {
216
- const self = this;
217
- const stack = self.$mol_log3_stack;
218
- const deep = stack.length;
219
- let logged = false;
220
- stack.push(() => {
221
- logged = true;
222
- self.$mol_log3_area.call(self, event);
223
- });
224
- return () => {
225
- if (logged)
226
- self.console.groupEnd();
227
- if (stack.length > deep)
228
- stack.length = deep;
229
- };
230
- }
231
- $.$mol_log3_area_lazy = $mol_log3_area_lazy;
232
- $.$mol_log3_stack = [];
233
- })($ || ($ = {}));
234
-
235
211
  ;
236
212
  "use strict";
237
213
  var $;
@@ -385,656 +361,183 @@ var $;
385
361
  ;
386
362
  "use strict";
387
363
  var $;
388
- (function ($) {
389
- class $mol_span extends $mol_object2 {
390
- uri;
391
- source;
392
- row;
393
- col;
394
- length;
395
- constructor(uri, source, row, col, length) {
396
- super();
397
- this.uri = uri;
398
- this.source = source;
399
- this.row = row;
400
- this.col = col;
401
- this.length = length;
402
- this[Symbol.toStringTag] = this.uri + ('#' + this.row + ':' + this.col + '/' + this.length);
403
- }
404
- static unknown = $mol_span.begin('?');
405
- static begin(uri, source = '') {
406
- return new $mol_span(uri, source, 1, 1, 0);
407
- }
408
- static end(uri, source) {
409
- return new $mol_span(uri, source, 1, source.length + 1, 0);
410
- }
411
- static entire(uri, source) {
412
- return new $mol_span(uri, source, 1, 1, source.length);
413
- }
414
- toString() {
415
- return this[Symbol.toStringTag];
416
- }
417
- toJSON() {
418
- return {
419
- uri: this.uri,
420
- row: this.row,
421
- col: this.col,
422
- length: this.length
423
- };
424
- }
425
- error(message, Class = Error) {
426
- return new Class(`${message} (${this})`);
427
- }
428
- span(row, col, length) {
429
- return new $mol_span(this.uri, this.source, row, col, length);
430
- }
431
- after(length = 0) {
432
- return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
433
- }
434
- slice(begin, end = -1) {
435
- let len = this.length;
436
- if (begin < 0)
437
- begin += len;
438
- if (end < 0)
439
- end += len;
440
- if (begin < 0 || begin > len)
441
- this.$.$mol_fail(this.error(`Begin value '${begin}' out of range`, RangeError));
442
- if (end < 0 || end > len)
443
- this.$.$mol_fail(this.error(`End value '${end}' out of range`, RangeError));
444
- if (end < begin)
445
- this.$.$mol_fail(this.error(`End value '${end}' can't be less than begin value`, RangeError));
446
- return this.span(this.row, this.col + begin, end - begin);
364
+ (function ($_1) {
365
+ let $$;
366
+ (function ($$) {
367
+ let $;
368
+ })($$ = $_1.$$ || ($_1.$$ = {}));
369
+ $_1.$mol_object_field = Symbol('$mol_object_field');
370
+ class $mol_object extends $mol_object2 {
371
+ static make(config) {
372
+ return super.create(obj => {
373
+ for (let key in config)
374
+ obj[key] = config[key];
375
+ });
447
376
  }
448
377
  }
449
- $.$mol_span = $mol_span;
378
+ $_1.$mol_object = $mol_object;
450
379
  })($ || ($ = {}));
451
380
 
452
381
  ;
453
382
  "use strict";
454
383
  var $;
455
384
  (function ($) {
456
- function $mol_tree2_to_string(tree) {
457
- let output = [];
458
- function dump(tree, prefix = '') {
459
- if (tree.type.length) {
460
- if (!prefix.length) {
461
- prefix = "\t";
462
- }
463
- output.push(tree.type);
464
- if (tree.kids.length == 1) {
465
- output.push(' ');
466
- dump(tree.kids[0], prefix);
467
- return;
468
- }
469
- output.push("\n");
470
- }
471
- else if (tree.value.length || prefix.length) {
472
- output.push("\\" + tree.value + "\n");
473
- }
474
- for (const kid of tree.kids) {
475
- output.push(prefix);
476
- dump(kid, prefix + "\t");
477
- }
478
- }
479
- dump(tree);
480
- return output.join('');
385
+ function $mol_env() {
386
+ return {};
481
387
  }
482
- $.$mol_tree2_to_string = $mol_tree2_to_string;
388
+ $.$mol_env = $mol_env;
483
389
  })($ || ($ = {}));
484
390
 
485
391
  ;
486
392
  "use strict";
487
393
  var $;
488
394
  (function ($) {
489
- class $mol_tree2 extends Object {
490
- type;
491
- value;
492
- kids;
493
- span;
494
- constructor(type, value, kids, span) {
495
- super();
496
- this.type = type;
497
- this.value = value;
498
- this.kids = kids;
499
- this.span = span;
500
- this[Symbol.toStringTag] = type || '\\' + value;
501
- }
502
- static list(kids, span = $mol_span.unknown) {
503
- return new $mol_tree2('', '', kids, span);
504
- }
505
- list(kids) {
506
- return $mol_tree2.list(kids, this.span);
395
+ $.$mol_env = function $mol_env() {
396
+ return this.process.env;
397
+ };
398
+ })($ || ($ = {}));
399
+
400
+ ;
401
+ "use strict";
402
+ var $;
403
+ (function ($) {
404
+ let $mol_wire_cursor;
405
+ (function ($mol_wire_cursor) {
406
+ $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
407
+ $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
408
+ $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
409
+ $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
410
+ })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
411
+ })($ || ($ = {}));
412
+
413
+ ;
414
+ "use strict";
415
+ var $;
416
+ (function ($) {
417
+ class $mol_wire_pub extends Object {
418
+ data = [];
419
+ static get [Symbol.species]() {
420
+ return Array;
507
421
  }
508
- static data(value, kids = [], span = $mol_span.unknown) {
509
- const chunks = value.split('\n');
510
- if (chunks.length > 1) {
511
- let kid_span = span.span(span.row, span.col, 0);
512
- const data = chunks.map(chunk => {
513
- kid_span = kid_span.after(chunk.length);
514
- return new $mol_tree2('', chunk, [], kid_span);
515
- });
516
- kids = [...data, ...kids];
517
- value = '';
422
+ sub_from = 0;
423
+ get sub_list() {
424
+ const res = [];
425
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
426
+ res.push(this.data[i]);
518
427
  }
519
- return new $mol_tree2('', value, kids, span);
428
+ return res;
520
429
  }
521
- data(value, kids = []) {
522
- return $mol_tree2.data(value, kids, this.span);
430
+ get sub_empty() {
431
+ return this.sub_from === this.data.length;
523
432
  }
524
- static struct(type, kids = [], span = $mol_span.unknown) {
525
- if (/[ \n\t\\]/.test(type)) {
526
- $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
433
+ sub_on(sub, pub_pos) {
434
+ const pos = this.data.length;
435
+ this.data.push(sub, pub_pos);
436
+ return pos;
437
+ }
438
+ sub_off(sub_pos) {
439
+ if (!(sub_pos < this.data.length)) {
440
+ $mol_fail(new Error(`Wrong pos ${sub_pos}`));
527
441
  }
528
- return new $mol_tree2(type, '', kids, span);
442
+ const end = this.data.length - 2;
443
+ if (sub_pos !== end) {
444
+ this.peer_move(end, sub_pos);
445
+ }
446
+ this.data.pop();
447
+ this.data.pop();
448
+ if (this.data.length === this.sub_from)
449
+ this.reap();
529
450
  }
530
- struct(type, kids = []) {
531
- return $mol_tree2.struct(type, kids, this.span);
451
+ reap() { }
452
+ promote() {
453
+ $mol_wire_auto()?.track_next(this);
532
454
  }
533
- clone(kids, span = this.span) {
534
- return new $mol_tree2(this.type, this.value, kids, span);
455
+ fresh() { }
456
+ complete() { }
457
+ get incompleted() {
458
+ return false;
535
459
  }
536
- text() {
537
- var values = [];
538
- for (var kid of this.kids) {
539
- if (kid.type)
540
- continue;
541
- values.push(kid.value);
460
+ emit(quant = $mol_wire_cursor.stale) {
461
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
462
+ ;
463
+ this.data[i].absorb(quant);
542
464
  }
543
- return this.value + values.join('\n');
544
465
  }
545
- static fromString(str, uri = 'unknown') {
546
- return $$.$mol_tree2_from_string(str, uri);
466
+ peer_move(from_pos, to_pos) {
467
+ const peer = this.data[from_pos];
468
+ const self_pos = this.data[from_pos + 1];
469
+ this.data[to_pos] = peer;
470
+ this.data[to_pos + 1] = self_pos;
471
+ peer.peer_repos(self_pos, to_pos);
547
472
  }
548
- toString() {
549
- return $$.$mol_tree2_to_string(this);
550
- }
551
- insert(value, ...path) {
552
- if (path.length === 0)
553
- return value;
554
- const type = path[0];
555
- if (typeof type === 'string') {
556
- let replaced = false;
557
- const sub = this.kids.map((item, index) => {
558
- if (item.type !== type)
559
- return item;
560
- replaced = true;
561
- return item.insert(value, ...path.slice(1));
562
- }).filter(Boolean);
563
- if (!replaced && value) {
564
- sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
565
- }
566
- return this.clone(sub);
567
- }
568
- else if (typeof type === 'number') {
569
- const sub = this.kids.slice();
570
- sub[type] = (sub[type] || this.list([]))
571
- .insert(value, ...path.slice(1));
572
- return this.clone(sub.filter(Boolean));
573
- }
574
- else {
575
- const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
576
- .map(item => item.insert(value, ...path.slice(1)))
577
- .filter(Boolean);
578
- return this.clone(kids);
579
- }
580
- }
581
- select(...path) {
582
- let next = [this];
583
- for (const type of path) {
584
- if (!next.length)
585
- break;
586
- const prev = next;
587
- next = [];
588
- for (var item of prev) {
589
- switch (typeof (type)) {
590
- case 'string':
591
- for (var child of item.kids) {
592
- if (child.type == type) {
593
- next.push(child);
594
- }
595
- }
596
- break;
597
- case 'number':
598
- if (type < item.kids.length)
599
- next.push(item.kids[type]);
600
- break;
601
- default: next.push(...item.kids);
602
- }
603
- }
604
- }
605
- return this.list(next);
606
- }
607
- filter(path, value) {
608
- const sub = this.kids.filter(item => {
609
- var found = item.select(...path);
610
- if (value === undefined) {
611
- return Boolean(found.kids.length);
612
- }
613
- else {
614
- return found.kids.some(child => child.value == value);
615
- }
616
- });
617
- return this.clone(sub);
618
- }
619
- hack_self(belt, context = {}) {
620
- let handle = belt[this.type] || belt[''];
621
- if (!handle || handle === Object.prototype[this.type]) {
622
- handle = (input, belt, context) => [
623
- input.clone(input.hack(belt, context), context.span)
624
- ];
625
- }
626
- try {
627
- return handle(this, belt, context);
628
- }
629
- catch (error) {
630
- error.message += `\n${this.clone([])}${this.span}`;
631
- $mol_fail_hidden(error);
632
- }
633
- }
634
- hack(belt, context = {}) {
635
- return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
636
- }
637
- error(message, Class = Error) {
638
- return this.span.error(`${message}\n${this.clone([])}`, Class);
639
- }
640
- }
641
- $.$mol_tree2 = $mol_tree2;
642
- class $mol_tree2_empty extends $mol_tree2 {
643
- constructor() {
644
- super('', '', [], $mol_span.unknown);
473
+ peer_repos(peer_pos, self_pos) {
474
+ this.data[peer_pos + 1] = self_pos;
645
475
  }
646
476
  }
647
- $.$mol_tree2_empty = $mol_tree2_empty;
477
+ $.$mol_wire_pub = $mol_wire_pub;
648
478
  })($ || ($ = {}));
649
479
 
480
+ ;
481
+ "use strict";
482
+
650
483
  ;
651
484
  "use strict";
652
485
  var $;
653
486
  (function ($) {
654
- class $mol_error_syntax extends SyntaxError {
655
- reason;
656
- line;
657
- span;
658
- constructor(reason, line, span) {
659
- super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
660
- this.reason = reason;
661
- this.line = line;
662
- this.span = span;
663
- }
487
+ $.$mol_wire_auto_sub = null;
488
+ function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
489
+ return $.$mol_wire_auto_sub = next;
664
490
  }
665
- $.$mol_error_syntax = $mol_error_syntax;
491
+ $.$mol_wire_auto = $mol_wire_auto;
492
+ $.$mol_wire_affected = [];
666
493
  })($ || ($ = {}));
667
494
 
668
495
  ;
669
496
  "use strict";
670
497
  var $;
671
498
  (function ($) {
672
- function $mol_tree2_from_string(str, uri = '?') {
673
- const span = $mol_span.entire(uri, str);
674
- var root = $mol_tree2.list([], span);
675
- var stack = [root];
676
- var pos = 0, row = 0, min_indent = 0;
677
- while (str.length > pos) {
678
- var indent = 0;
679
- var line_start = pos;
680
- row++;
681
- while (str.length > pos && str[pos] == '\t') {
682
- indent++;
683
- pos++;
684
- }
685
- if (!root.kids.length) {
686
- min_indent = indent;
687
- }
688
- indent -= min_indent;
689
- if (indent < 0 || indent >= stack.length) {
690
- const sp = span.span(row, 1, pos - line_start);
691
- while (str.length > pos && str[pos] != '\n') {
692
- pos++;
693
- }
694
- if (indent < 0) {
695
- if (str.length > pos) {
696
- this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
697
- }
698
- }
699
- else {
700
- this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
701
- }
702
- }
703
- stack.length = indent + 1;
704
- var parent = stack[indent];
705
- while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
706
- var error_start = pos;
707
- while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
708
- pos++;
709
- }
710
- if (pos > error_start) {
711
- let line_end = str.indexOf('\n', pos);
712
- if (line_end === -1)
713
- line_end = str.length;
714
- const sp = span.span(row, error_start - line_start + 1, pos - error_start);
715
- this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
716
- }
717
- var type_start = pos;
718
- while (str.length > pos &&
719
- str[pos] != '\\' &&
720
- str[pos] != ' ' &&
721
- str[pos] != '\t' &&
722
- str[pos] != '\n') {
723
- pos++;
724
- }
725
- if (pos > type_start) {
726
- let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
727
- const parent_kids = parent.kids;
728
- parent_kids.push(next);
729
- parent = next;
499
+ $['devtoolsFormatters'] ||= [];
500
+ function $mol_dev_format_register(config) {
501
+ $['devtoolsFormatters'].push(config);
502
+ }
503
+ $.$mol_dev_format_register = $mol_dev_format_register;
504
+ $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
505
+ $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
506
+ $mol_dev_format_register({
507
+ header: (val, config = false) => {
508
+ if (config)
509
+ return null;
510
+ if (!val)
511
+ return null;
512
+ if ($.$mol_dev_format_head in val) {
513
+ try {
514
+ return val[$.$mol_dev_format_head]();
730
515
  }
731
- if (str.length > pos && str[pos] == ' ') {
732
- pos++;
516
+ catch (error) {
517
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
733
518
  }
734
519
  }
735
- if (str.length > pos && str[pos] == '\\') {
736
- var data_start = pos;
737
- while (str.length > pos && str[pos] != '\n') {
738
- pos++;
739
- }
740
- let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
741
- const parent_kids = parent.kids;
742
- parent_kids.push(next);
743
- parent = next;
520
+ if (typeof val === 'function') {
521
+ return $mol_dev_format_native(val);
744
522
  }
745
- if (str.length === pos && stack.length > 0) {
746
- const sp = span.span(row, pos - line_start + 1, 1);
747
- this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
523
+ if (Symbol.toStringTag in val) {
524
+ return $mol_dev_format_native(val);
748
525
  }
749
- stack.push(parent);
750
- pos++;
751
- }
752
- return root;
753
- }
754
- $.$mol_tree2_from_string = $mol_tree2_from_string;
755
- })($ || ($ = {}));
756
-
757
- ;
758
- "use strict";
759
- var $;
760
- (function ($) {
761
- function $mol_tree2_from_json(json, span = $mol_span.unknown) {
762
- if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
763
- return new $mol_tree2(String(json), '', [], span);
764
- }
765
- if (typeof json === 'string') {
766
- return $mol_tree2.data(json, [], span);
767
- }
768
- if (typeof json.toJSON === 'function') {
769
- return $mol_tree2_from_json(json.toJSON());
770
- }
771
- if (Array.isArray(json)) {
772
- const sub = json.map(json => $mol_tree2_from_json(json, span));
773
- return new $mol_tree2('/', '', sub, span);
774
- }
775
- if (ArrayBuffer.isView(json)) {
776
- const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
777
- return $mol_tree2.data(String.fromCharCode(...buf), [], span);
778
- }
779
- if (json instanceof Date) {
780
- return new $mol_tree2('', json.toISOString(), [], span);
781
- }
782
- if (json.toString !== Object.prototype.toString) {
783
- return $mol_tree2.data(json.toString(), [], span);
784
- }
785
- if (json instanceof Error) {
786
- const { name, message, stack } = json;
787
- json = { ...json, name, message, stack };
788
- }
789
- const sub = [];
790
- for (var key in json) {
791
- const val = json[key];
792
- if (val === undefined)
793
- continue;
794
- const subsub = $mol_tree2_from_json(val, span);
795
- if (/^[^\n\t\\ ]+$/.test(key)) {
796
- sub.push(new $mol_tree2(key, '', [subsub], span));
797
- }
798
- else {
799
- sub.push($mol_tree2.data(key, [subsub], span));
800
- }
801
- }
802
- return new $mol_tree2('*', '', sub, span);
803
- }
804
- $.$mol_tree2_from_json = $mol_tree2_from_json;
805
- })($ || ($ = {}));
806
-
807
- ;
808
- "use strict";
809
- var $;
810
- (function ($) {
811
- class $mol_term_color {
812
- static reset = this.ansi(0, 0);
813
- static bold = this.ansi(1, 22);
814
- static italic = this.ansi(3, 23);
815
- static underline = this.ansi(4, 24);
816
- static inverse = this.ansi(7, 27);
817
- static hidden = this.ansi(8, 28);
818
- static strike = this.ansi(9, 29);
819
- static gray = this.ansi(90, 39);
820
- static red = this.ansi(91, 39);
821
- static green = this.ansi(92, 39);
822
- static yellow = this.ansi(93, 39);
823
- static blue = this.ansi(94, 39);
824
- static magenta = this.ansi(95, 39);
825
- static cyan = this.ansi(96, 39);
826
- static Gray = (str) => this.inverse(this.gray(str));
827
- static Red = (str) => this.inverse(this.red(str));
828
- static Green = (str) => this.inverse(this.green(str));
829
- static Yellow = (str) => this.inverse(this.yellow(str));
830
- static Blue = (str) => this.inverse(this.blue(str));
831
- static Magenta = (str) => this.inverse(this.magenta(str));
832
- static Cyan = (str) => this.inverse(this.cyan(str));
833
- static ansi(open, close) {
834
- if (typeof process === 'undefined')
835
- return String;
836
- if (!process.stdout.isTTY)
837
- return String;
838
- const prefix = `\x1b[${open}m`;
839
- const postfix = `\x1b[${close}m`;
840
- const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
841
- return function colorer(str) {
842
- str = String(str);
843
- if (str === '')
844
- return str;
845
- const suffix = str.replace(suffix_regexp, prefix);
846
- return prefix + suffix + postfix;
847
- };
848
- }
849
- }
850
- $.$mol_term_color = $mol_term_color;
851
- })($ || ($ = {}));
852
-
853
- ;
854
- "use strict";
855
- var $;
856
- (function ($) {
857
- function $mol_log3_node_make(level, output, type, color) {
858
- return function $mol_log3_logger(event) {
859
- if (!event.time)
860
- event = { time: new Date().toISOString(), ...event };
861
- let tree = this.$mol_tree2_from_json(event);
862
- tree = tree.struct(type, tree.kids);
863
- let str = color(tree.toString());
864
- this.console[level](str);
865
- const self = this;
866
- return () => self.console.groupEnd();
867
- };
868
- }
869
- $.$mol_log3_node_make = $mol_log3_node_make;
870
- $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
871
- $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
872
- $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
873
- $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
874
- $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
875
- $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
876
- })($ || ($ = {}));
877
-
878
- ;
879
- "use strict";
880
- var $;
881
- (function ($) {
882
- function $mol_env() {
883
- return {};
884
- }
885
- $.$mol_env = $mol_env;
886
- })($ || ($ = {}));
887
-
888
- ;
889
- "use strict";
890
- var $;
891
- (function ($) {
892
- $.$mol_env = function $mol_env() {
893
- return this.process.env;
894
- };
895
- })($ || ($ = {}));
896
-
897
- ;
898
- "use strict";
899
- var $;
900
- (function ($) {
901
- let $mol_wire_cursor;
902
- (function ($mol_wire_cursor) {
903
- $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
904
- $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
905
- $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
906
- $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
907
- })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
908
- })($ || ($ = {}));
909
-
910
- ;
911
- "use strict";
912
- var $;
913
- (function ($) {
914
- class $mol_wire_pub extends Object {
915
- data = [];
916
- static get [Symbol.species]() {
917
- return Array;
918
- }
919
- sub_from = 0;
920
- get sub_list() {
921
- const res = [];
922
- for (let i = this.sub_from; i < this.data.length; i += 2) {
923
- res.push(this.data[i]);
924
- }
925
- return res;
926
- }
927
- get sub_empty() {
928
- return this.sub_from === this.data.length;
929
- }
930
- sub_on(sub, pub_pos) {
931
- const pos = this.data.length;
932
- this.data.push(sub, pub_pos);
933
- return pos;
934
- }
935
- sub_off(sub_pos) {
936
- if (!(sub_pos < this.data.length)) {
937
- $mol_fail(new Error(`Wrong pos ${sub_pos}`));
938
- }
939
- const end = this.data.length - 2;
940
- if (sub_pos !== end) {
941
- this.peer_move(end, sub_pos);
942
- }
943
- this.data.pop();
944
- this.data.pop();
945
- if (this.data.length === this.sub_from)
946
- this.reap();
947
- }
948
- reap() { }
949
- promote() {
950
- $mol_wire_auto()?.track_next(this);
951
- }
952
- fresh() { }
953
- complete() { }
954
- get incompleted() {
955
- return false;
956
- }
957
- emit(quant = $mol_wire_cursor.stale) {
958
- for (let i = this.sub_from; i < this.data.length; i += 2) {
959
- ;
960
- this.data[i].absorb(quant);
961
- }
962
- }
963
- peer_move(from_pos, to_pos) {
964
- const peer = this.data[from_pos];
965
- const self_pos = this.data[from_pos + 1];
966
- this.data[to_pos] = peer;
967
- this.data[to_pos + 1] = self_pos;
968
- peer.peer_repos(self_pos, to_pos);
969
- }
970
- peer_repos(peer_pos, self_pos) {
971
- this.data[peer_pos + 1] = self_pos;
972
- }
973
- }
974
- $.$mol_wire_pub = $mol_wire_pub;
975
- })($ || ($ = {}));
976
-
977
- ;
978
- "use strict";
979
-
980
- ;
981
- "use strict";
982
- var $;
983
- (function ($) {
984
- $.$mol_wire_auto_sub = null;
985
- function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
986
- return $.$mol_wire_auto_sub = next;
987
- }
988
- $.$mol_wire_auto = $mol_wire_auto;
989
- $.$mol_wire_affected = [];
990
- })($ || ($ = {}));
991
-
992
- ;
993
- "use strict";
994
- var $;
995
- (function ($) {
996
- $['devtoolsFormatters'] ||= [];
997
- function $mol_dev_format_register(config) {
998
- $['devtoolsFormatters'].push(config);
999
- }
1000
- $.$mol_dev_format_register = $mol_dev_format_register;
1001
- $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
1002
- $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
1003
- $mol_dev_format_register({
1004
- header: (val, config = false) => {
1005
- if (config)
1006
- return null;
1007
- if (!val)
1008
- return null;
1009
- if ($.$mol_dev_format_head in val) {
1010
- try {
1011
- return val[$.$mol_dev_format_head]();
1012
- }
1013
- catch (error) {
1014
- return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
1015
- }
1016
- }
1017
- if (typeof val === 'function') {
1018
- return $mol_dev_format_native(val);
1019
- }
1020
- if (Symbol.toStringTag in val) {
1021
- return $mol_dev_format_native(val);
1022
- }
1023
- return null;
1024
- },
1025
- hasBody: val => val[$.$mol_dev_format_body],
1026
- body: val => val[$.$mol_dev_format_body](),
1027
- });
1028
- function $mol_dev_format_native(obj) {
1029
- if (typeof obj === 'undefined')
1030
- return $.$mol_dev_format_shade('undefined');
1031
- return [
1032
- 'object',
1033
- {
1034
- object: obj,
1035
- config: true,
1036
- },
1037
- ];
526
+ return null;
527
+ },
528
+ hasBody: val => val[$.$mol_dev_format_body],
529
+ body: val => val[$.$mol_dev_format_body](),
530
+ });
531
+ function $mol_dev_format_native(obj) {
532
+ if (typeof obj === 'undefined')
533
+ return $.$mol_dev_format_shade('undefined');
534
+ return [
535
+ 'object',
536
+ {
537
+ object: obj,
538
+ config: true,
539
+ },
540
+ ];
1038
541
  }
1039
542
  $.$mol_dev_format_native = $mol_dev_format_native;
1040
543
  function $mol_dev_format_auto(obj) {
@@ -1169,484 +672,1001 @@ var $;
1169
672
  this.data[sub_pos] = undefined;
1170
673
  this.data[sub_pos + 1] = undefined;
1171
674
  }
1172
- destructor() {
1173
- for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
1174
- const sub = this.data[cursor];
1175
- const pos = this.data[cursor + 1];
1176
- sub.pub_off(pos);
1177
- this.data.pop();
1178
- this.data.pop();
1179
- }
1180
- this.cursor = this.pub_from;
1181
- this.track_cut();
1182
- this.cursor = $mol_wire_cursor.final;
675
+ destructor() {
676
+ for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
677
+ const sub = this.data[cursor];
678
+ const pos = this.data[cursor + 1];
679
+ sub.pub_off(pos);
680
+ this.data.pop();
681
+ this.data.pop();
682
+ }
683
+ this.cursor = this.pub_from;
684
+ this.track_cut();
685
+ this.cursor = $mol_wire_cursor.final;
686
+ }
687
+ track_cut() {
688
+ if (this.cursor < this.pub_from) {
689
+ $mol_fail(new Error('Cut of non begun sub'));
690
+ }
691
+ let tail = 0;
692
+ for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
693
+ const pub = this.data[cursor];
694
+ pub?.sub_off(this.data[cursor + 1]);
695
+ if (this.sub_from < this.data.length) {
696
+ this.peer_move(this.data.length - 2, cursor);
697
+ this.data.pop();
698
+ this.data.pop();
699
+ }
700
+ else {
701
+ ++tail;
702
+ }
703
+ }
704
+ for (; tail; --tail) {
705
+ this.data.pop();
706
+ this.data.pop();
707
+ }
708
+ this.sub_from = this.cursor;
709
+ }
710
+ complete() { }
711
+ complete_pubs() {
712
+ const limit = this.cursor < 0 ? this.sub_from : this.cursor;
713
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
714
+ const pub = this.data[cursor];
715
+ if (pub?.incompleted)
716
+ return;
717
+ }
718
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
719
+ const pub = this.data[cursor];
720
+ pub?.complete();
721
+ }
722
+ }
723
+ absorb(quant = $mol_wire_cursor.stale) {
724
+ if (this.cursor === $mol_wire_cursor.final)
725
+ return;
726
+ if (this.cursor >= quant)
727
+ return;
728
+ this.cursor = quant;
729
+ this.emit($mol_wire_cursor.doubt);
730
+ }
731
+ [$mol_dev_format_head]() {
732
+ return $mol_dev_format_native(this);
733
+ }
734
+ get pub_empty() {
735
+ return this.sub_from === this.pub_from;
736
+ }
737
+ }
738
+ $.$mol_wire_pub_sub = $mol_wire_pub_sub;
739
+ })($ || ($ = {}));
740
+
741
+ ;
742
+ "use strict";
743
+ var $;
744
+ (function ($) {
745
+ class $mol_after_tick extends $mol_object2 {
746
+ task;
747
+ static promise = null;
748
+ cancelled = false;
749
+ constructor(task) {
750
+ super();
751
+ this.task = task;
752
+ if (!$mol_after_tick.promise)
753
+ $mol_after_tick.promise = Promise.resolve().then(() => {
754
+ $mol_after_tick.promise = null;
755
+ });
756
+ $mol_after_tick.promise.then(() => {
757
+ if (this.cancelled)
758
+ return;
759
+ task();
760
+ });
761
+ }
762
+ destructor() {
763
+ this.cancelled = true;
764
+ }
765
+ }
766
+ $.$mol_after_tick = $mol_after_tick;
767
+ })($ || ($ = {}));
768
+
769
+ ;
770
+ "use strict";
771
+ var $;
772
+ (function ($) {
773
+ const wrappers = new WeakMap();
774
+ class $mol_wire_fiber extends $mol_wire_pub_sub {
775
+ task;
776
+ host;
777
+ static warm = true;
778
+ static planning = new Set();
779
+ static reaping = new Set();
780
+ static plan_task = null;
781
+ static plan() {
782
+ if (this.plan_task)
783
+ return;
784
+ this.plan_task = new $mol_after_tick(() => {
785
+ try {
786
+ this.sync();
787
+ }
788
+ finally {
789
+ $mol_wire_fiber.plan_task = null;
790
+ }
791
+ });
792
+ }
793
+ static sync() {
794
+ while (this.planning.size) {
795
+ for (const fiber of this.planning) {
796
+ this.planning.delete(fiber);
797
+ if (fiber.cursor >= 0)
798
+ continue;
799
+ if (fiber.cursor === $mol_wire_cursor.final)
800
+ continue;
801
+ fiber.fresh();
802
+ }
803
+ }
804
+ while (this.reaping.size) {
805
+ const fibers = this.reaping;
806
+ this.reaping = new Set;
807
+ for (const fiber of fibers) {
808
+ if (!fiber.sub_empty)
809
+ continue;
810
+ fiber.destructor();
811
+ }
812
+ }
813
+ }
814
+ [Symbol.toStringTag];
815
+ cache = undefined;
816
+ get args() {
817
+ return this.data.slice(0, this.pub_from);
818
+ }
819
+ result() {
820
+ if ($mol_promise_like(this.cache))
821
+ return;
822
+ if (this.cache instanceof Error)
823
+ return;
824
+ return this.cache;
825
+ }
826
+ get incompleted() {
827
+ return $mol_promise_like(this.cache);
828
+ }
829
+ field() {
830
+ return this.task.name + '<>';
831
+ }
832
+ constructor(id, task, host, args) {
833
+ super();
834
+ this.task = task;
835
+ this.host = host;
836
+ if (args)
837
+ this.data.push(...args);
838
+ this.pub_from = this.sub_from = args?.length ?? 0;
839
+ this[Symbol.toStringTag] = id;
840
+ }
841
+ plan() {
842
+ $mol_wire_fiber.planning.add(this);
843
+ $mol_wire_fiber.plan();
844
+ return this;
845
+ }
846
+ reap() {
847
+ $mol_wire_fiber.reaping.add(this);
848
+ $mol_wire_fiber.plan();
849
+ }
850
+ toString() {
851
+ return this[Symbol.toStringTag];
852
+ }
853
+ toJSON() {
854
+ return this[Symbol.toStringTag];
855
+ }
856
+ [$mol_dev_format_head]() {
857
+ const cursor = {
858
+ [$mol_wire_cursor.stale]: '🔴',
859
+ [$mol_wire_cursor.doubt]: '🟡',
860
+ [$mol_wire_cursor.fresh]: '🟢',
861
+ [$mol_wire_cursor.final]: '🔵',
862
+ }[this.cursor] ?? this.cursor.toString();
863
+ return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
864
+ ? $mol_dev_format_auto({
865
+ [$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
866
+ [$mol_dev_format_body]: () => $mol_dev_format_native(this),
867
+ })
868
+ : $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
869
+ }
870
+ get $() {
871
+ return (this.host ?? this.task)['$'];
872
+ }
873
+ emit(quant = $mol_wire_cursor.stale) {
874
+ if (this.sub_empty)
875
+ this.plan();
876
+ else
877
+ super.emit(quant);
878
+ }
879
+ fresh() {
880
+ if (this.cursor === $mol_wire_cursor.fresh)
881
+ return;
882
+ if (this.cursor === $mol_wire_cursor.final)
883
+ return;
884
+ check: if (this.cursor === $mol_wire_cursor.doubt) {
885
+ for (let i = this.pub_from; i < this.sub_from; i += 2) {
886
+ ;
887
+ this.data[i]?.fresh();
888
+ if (this.cursor !== $mol_wire_cursor.doubt)
889
+ break check;
890
+ }
891
+ this.cursor = $mol_wire_cursor.fresh;
892
+ return;
893
+ }
894
+ const bu = this.track_on();
895
+ let result;
896
+ try {
897
+ switch (this.pub_from) {
898
+ case 0:
899
+ result = this.task.call(this.host);
900
+ break;
901
+ case 1:
902
+ result = this.task.call(this.host, this.data[0]);
903
+ break;
904
+ default:
905
+ result = this.task.call(this.host, ...this.args);
906
+ break;
907
+ }
908
+ if ($mol_promise_like(result)) {
909
+ if (wrappers.has(result)) {
910
+ result = wrappers.get(result).then(a => a);
911
+ }
912
+ else {
913
+ const put = (res) => {
914
+ if (this.cache === result)
915
+ this.put(res);
916
+ return res;
917
+ };
918
+ wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
919
+ wrappers.set(result, result);
920
+ const error = new Error(`Promise in ${this}`);
921
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
922
+ }
923
+ }
924
+ }
925
+ catch (error) {
926
+ if (error instanceof Error || $mol_promise_like(error)) {
927
+ result = error;
928
+ }
929
+ else {
930
+ result = new Error(String(error), { cause: error });
931
+ }
932
+ if ($mol_promise_like(result)) {
933
+ if (wrappers.has(result)) {
934
+ result = wrappers.get(result);
935
+ }
936
+ else {
937
+ wrappers.set(result, result = Object.assign(result.finally(() => {
938
+ if (this.cache === result)
939
+ this.absorb();
940
+ }), { destructor: result.destructor || (() => { }) }));
941
+ const error = new Error(`Promise in ${this}`);
942
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
943
+ }
944
+ }
945
+ }
946
+ if (!$mol_promise_like(result)) {
947
+ this.track_cut();
948
+ }
949
+ this.track_off(bu);
950
+ this.put(result);
951
+ return this;
952
+ }
953
+ refresh() {
954
+ this.cursor = $mol_wire_cursor.stale;
955
+ this.fresh();
956
+ }
957
+ sync() {
958
+ if (!$mol_wire_fiber.warm) {
959
+ return this.result();
960
+ }
961
+ this.promote();
962
+ this.fresh();
963
+ if (this.cache instanceof Error) {
964
+ return $mol_fail_hidden(this.cache);
965
+ }
966
+ if ($mol_promise_like(this.cache)) {
967
+ return $mol_fail_hidden(this.cache);
968
+ }
969
+ return this.cache;
970
+ }
971
+ async async_raw() {
972
+ while (true) {
973
+ this.fresh();
974
+ if (this.cache instanceof Error) {
975
+ $mol_fail_hidden(this.cache);
976
+ }
977
+ if (!$mol_promise_like(this.cache))
978
+ return this.cache;
979
+ await Promise.race([this.cache, this.step()]);
980
+ if (!$mol_promise_like(this.cache))
981
+ return this.cache;
982
+ if (this.cursor === $mol_wire_cursor.final) {
983
+ await new Promise(() => { });
984
+ }
985
+ }
986
+ }
987
+ async() {
988
+ const promise = this.async_raw();
989
+ if (!promise.destructor)
990
+ promise.destructor = () => this.destructor();
991
+ return promise;
992
+ }
993
+ step() {
994
+ return new Promise(done => {
995
+ const sub = new $mol_wire_pub_sub;
996
+ const prev = sub.track_on();
997
+ sub.track_next(this);
998
+ sub.track_off(prev);
999
+ sub.absorb = () => {
1000
+ done(null);
1001
+ setTimeout(() => sub.destructor());
1002
+ };
1003
+ });
1004
+ }
1005
+ destructor() {
1006
+ super.destructor();
1007
+ if ($mol_owning_check(this, this.cache)) {
1008
+ this.cache.destructor();
1009
+ }
1010
+ }
1011
+ }
1012
+ $.$mol_wire_fiber = $mol_wire_fiber;
1013
+ })($ || ($ = {}));
1014
+
1015
+ ;
1016
+ "use strict";
1017
+ var $;
1018
+ (function ($) {
1019
+ $.$mol_compare_deep_cache = new WeakMap();
1020
+ function $mol_compare_deep(left, right) {
1021
+ if (Object.is(left, right))
1022
+ return true;
1023
+ if (left === null)
1024
+ return false;
1025
+ if (right === null)
1026
+ return false;
1027
+ if (typeof left !== 'object')
1028
+ return false;
1029
+ if (typeof right !== 'object')
1030
+ return false;
1031
+ const left_proto = Reflect.getPrototypeOf(left);
1032
+ const right_proto = Reflect.getPrototypeOf(right);
1033
+ if (left_proto !== right_proto)
1034
+ return false;
1035
+ if (left instanceof Boolean)
1036
+ return Object.is(left.valueOf(), right['valueOf']());
1037
+ if (left instanceof Number)
1038
+ return Object.is(left.valueOf(), right['valueOf']());
1039
+ if (left instanceof String)
1040
+ return Object.is(left.valueOf(), right['valueOf']());
1041
+ if (left instanceof Date)
1042
+ return Object.is(left.valueOf(), right['valueOf']());
1043
+ if (left instanceof RegExp)
1044
+ return left.source === right.source && left.flags === right.flags;
1045
+ if (left instanceof Error)
1046
+ return left.message === right.message && left.stack === right.stack;
1047
+ let left_cache = $.$mol_compare_deep_cache.get(left);
1048
+ if (left_cache) {
1049
+ const right_cache = left_cache.get(right);
1050
+ if (typeof right_cache === 'boolean')
1051
+ return right_cache;
1052
+ }
1053
+ else {
1054
+ left_cache = new WeakMap();
1055
+ $.$mol_compare_deep_cache.set(left, left_cache);
1056
+ }
1057
+ left_cache.set(right, true);
1058
+ let result;
1059
+ try {
1060
+ if (!left_proto)
1061
+ result = compare_pojo(left, right);
1062
+ else if (!Reflect.getPrototypeOf(left_proto))
1063
+ result = compare_pojo(left, right);
1064
+ else if (Symbol.toPrimitive in left)
1065
+ result = compare_primitive(left, right);
1066
+ else if (Array.isArray(left))
1067
+ result = compare_array(left, right);
1068
+ else if (left instanceof Set)
1069
+ result = compare_set(left, right);
1070
+ else if (left instanceof Map)
1071
+ result = compare_map(left, right);
1072
+ else if (ArrayBuffer.isView(left))
1073
+ result = compare_buffer(left, right);
1074
+ else if (Symbol.iterator in left)
1075
+ result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
1076
+ else
1077
+ result = false;
1078
+ }
1079
+ finally {
1080
+ left_cache.set(right, result);
1183
1081
  }
1184
- track_cut() {
1185
- if (this.cursor < this.pub_from) {
1186
- $mol_fail(new Error('Cut of non begun sub'));
1187
- }
1188
- let tail = 0;
1189
- for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
1190
- const pub = this.data[cursor];
1191
- pub?.sub_off(this.data[cursor + 1]);
1192
- if (this.sub_from < this.data.length) {
1193
- this.peer_move(this.data.length - 2, cursor);
1194
- this.data.pop();
1195
- this.data.pop();
1196
- }
1197
- else {
1198
- ++tail;
1199
- }
1200
- }
1201
- for (; tail; --tail) {
1202
- this.data.pop();
1203
- this.data.pop();
1204
- }
1205
- this.sub_from = this.cursor;
1082
+ return result;
1083
+ }
1084
+ $.$mol_compare_deep = $mol_compare_deep;
1085
+ function compare_array(left, right) {
1086
+ const len = left.length;
1087
+ if (len !== right.length)
1088
+ return false;
1089
+ for (let i = 0; i < len; ++i) {
1090
+ if (!$mol_compare_deep(left[i], right[i]))
1091
+ return false;
1206
1092
  }
1207
- complete() { }
1208
- complete_pubs() {
1209
- const limit = this.cursor < 0 ? this.sub_from : this.cursor;
1210
- for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1211
- const pub = this.data[cursor];
1212
- if (pub?.incompleted)
1213
- return;
1214
- }
1215
- for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1216
- const pub = this.data[cursor];
1217
- pub?.complete();
1218
- }
1093
+ return true;
1094
+ }
1095
+ function compare_buffer(left, right) {
1096
+ const len = left.byteLength;
1097
+ if (len !== right.byteLength)
1098
+ return false;
1099
+ if (left instanceof DataView)
1100
+ return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
1101
+ for (let i = 0; i < len; ++i) {
1102
+ if (left[i] !== right[i])
1103
+ return false;
1219
1104
  }
1220
- absorb(quant = $mol_wire_cursor.stale) {
1221
- if (this.cursor === $mol_wire_cursor.final)
1222
- return;
1223
- if (this.cursor >= quant)
1224
- return;
1225
- this.cursor = quant;
1226
- this.emit($mol_wire_cursor.doubt);
1105
+ return true;
1106
+ }
1107
+ function compare_iterator(left, right) {
1108
+ while (true) {
1109
+ const left_next = left.next();
1110
+ const right_next = right.next();
1111
+ if (left_next.done !== right_next.done)
1112
+ return false;
1113
+ if (left_next.done)
1114
+ break;
1115
+ if (!$mol_compare_deep(left_next.value, right_next.value))
1116
+ return false;
1227
1117
  }
1228
- [$mol_dev_format_head]() {
1229
- return $mol_dev_format_native(this);
1118
+ return true;
1119
+ }
1120
+ function compare_set(left, right) {
1121
+ if (left.size !== right.size)
1122
+ return false;
1123
+ return compare_iterator(left.values(), right.values());
1124
+ }
1125
+ function compare_map(left, right) {
1126
+ if (left.size !== right.size)
1127
+ return false;
1128
+ return compare_iterator(left.keys(), right.keys())
1129
+ && compare_iterator(left.values(), right.values());
1130
+ }
1131
+ function compare_pojo(left, right) {
1132
+ const left_keys = Object.getOwnPropertyNames(left);
1133
+ const right_keys = Object.getOwnPropertyNames(right);
1134
+ if (!compare_array(left_keys, right_keys))
1135
+ return false;
1136
+ for (let key of left_keys) {
1137
+ if (!$mol_compare_deep(left[key], right[key]))
1138
+ return false;
1230
1139
  }
1231
- get pub_empty() {
1232
- return this.sub_from === this.pub_from;
1140
+ const left_syms = Object.getOwnPropertySymbols(left);
1141
+ const right_syms = Object.getOwnPropertySymbols(right);
1142
+ if (!compare_array(left_syms, right_syms))
1143
+ return false;
1144
+ for (let key of left_syms) {
1145
+ if (!$mol_compare_deep(left[key], right[key]))
1146
+ return false;
1233
1147
  }
1148
+ return true;
1149
+ }
1150
+ function compare_primitive(left, right) {
1151
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
1234
1152
  }
1235
- $.$mol_wire_pub_sub = $mol_wire_pub_sub;
1236
1153
  })($ || ($ = {}));
1237
1154
 
1238
1155
  ;
1239
1156
  "use strict";
1240
1157
  var $;
1241
1158
  (function ($) {
1242
- class $mol_after_tick extends $mol_object2 {
1243
- task;
1244
- static promise = null;
1245
- cancelled = false;
1246
- constructor(task) {
1159
+ function $mol_log3_area_lazy(event) {
1160
+ const self = this;
1161
+ const stack = self.$mol_log3_stack;
1162
+ const deep = stack.length;
1163
+ let logged = false;
1164
+ stack.push(() => {
1165
+ logged = true;
1166
+ self.$mol_log3_area.call(self, event);
1167
+ });
1168
+ return () => {
1169
+ if (logged)
1170
+ self.console.groupEnd();
1171
+ if (stack.length > deep)
1172
+ stack.length = deep;
1173
+ };
1174
+ }
1175
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1176
+ $.$mol_log3_stack = [];
1177
+ })($ || ($ = {}));
1178
+
1179
+ ;
1180
+ "use strict";
1181
+ var $;
1182
+ (function ($) {
1183
+ class $mol_span extends $mol_object2 {
1184
+ uri;
1185
+ source;
1186
+ row;
1187
+ col;
1188
+ length;
1189
+ constructor(uri, source, row, col, length) {
1247
1190
  super();
1248
- this.task = task;
1249
- if (!$mol_after_tick.promise)
1250
- $mol_after_tick.promise = Promise.resolve().then(() => {
1251
- $mol_after_tick.promise = null;
1252
- });
1253
- $mol_after_tick.promise.then(() => {
1254
- if (this.cancelled)
1255
- return;
1256
- task();
1257
- });
1191
+ this.uri = uri;
1192
+ this.source = source;
1193
+ this.row = row;
1194
+ this.col = col;
1195
+ this.length = length;
1196
+ this[Symbol.toStringTag] = this.uri + ('#' + this.row + ':' + this.col + '/' + this.length);
1258
1197
  }
1259
- destructor() {
1260
- this.cancelled = true;
1198
+ static unknown = $mol_span.begin('?');
1199
+ static begin(uri, source = '') {
1200
+ return new $mol_span(uri, source, 1, 1, 0);
1201
+ }
1202
+ static end(uri, source) {
1203
+ return new $mol_span(uri, source, 1, source.length + 1, 0);
1204
+ }
1205
+ static entire(uri, source) {
1206
+ return new $mol_span(uri, source, 1, 1, source.length);
1207
+ }
1208
+ toString() {
1209
+ return this[Symbol.toStringTag];
1210
+ }
1211
+ toJSON() {
1212
+ return {
1213
+ uri: this.uri,
1214
+ row: this.row,
1215
+ col: this.col,
1216
+ length: this.length
1217
+ };
1218
+ }
1219
+ error(message, Class = Error) {
1220
+ return new Class(`${message} (${this})`);
1221
+ }
1222
+ span(row, col, length) {
1223
+ return new $mol_span(this.uri, this.source, row, col, length);
1224
+ }
1225
+ after(length = 0) {
1226
+ return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
1227
+ }
1228
+ slice(begin, end = -1) {
1229
+ let len = this.length;
1230
+ if (begin < 0)
1231
+ begin += len;
1232
+ if (end < 0)
1233
+ end += len;
1234
+ if (begin < 0 || begin > len)
1235
+ this.$.$mol_fail(this.error(`Begin value '${begin}' out of range`, RangeError));
1236
+ if (end < 0 || end > len)
1237
+ this.$.$mol_fail(this.error(`End value '${end}' out of range`, RangeError));
1238
+ if (end < begin)
1239
+ this.$.$mol_fail(this.error(`End value '${end}' can't be less than begin value`, RangeError));
1240
+ return this.span(this.row, this.col + begin, end - begin);
1261
1241
  }
1262
1242
  }
1263
- $.$mol_after_tick = $mol_after_tick;
1243
+ $.$mol_span = $mol_span;
1264
1244
  })($ || ($ = {}));
1265
1245
 
1266
1246
  ;
1267
1247
  "use strict";
1268
1248
  var $;
1269
- (function ($) {
1270
- const wrappers = new WeakMap();
1271
- class $mol_wire_fiber extends $mol_wire_pub_sub {
1272
- task;
1273
- host;
1274
- static warm = true;
1275
- static planning = new Set();
1276
- static reaping = new Set();
1277
- static plan_task = null;
1278
- static plan() {
1279
- if (this.plan_task)
1280
- return;
1281
- this.plan_task = new $mol_after_tick(() => {
1282
- try {
1283
- this.sync();
1284
- }
1285
- finally {
1286
- $mol_wire_fiber.plan_task = null;
1287
- }
1288
- });
1289
- }
1290
- static sync() {
1291
- while (this.planning.size) {
1292
- for (const fiber of this.planning) {
1293
- this.planning.delete(fiber);
1294
- if (fiber.cursor >= 0)
1295
- continue;
1296
- if (fiber.cursor === $mol_wire_cursor.final)
1297
- continue;
1298
- fiber.fresh();
1249
+ (function ($) {
1250
+ function $mol_tree2_to_string(tree) {
1251
+ let output = [];
1252
+ function dump(tree, prefix = '') {
1253
+ if (tree.type.length) {
1254
+ if (!prefix.length) {
1255
+ prefix = "\t";
1299
1256
  }
1300
- }
1301
- while (this.reaping.size) {
1302
- const fibers = this.reaping;
1303
- this.reaping = new Set;
1304
- for (const fiber of fibers) {
1305
- if (!fiber.sub_empty)
1306
- continue;
1307
- fiber.destructor();
1257
+ output.push(tree.type);
1258
+ if (tree.kids.length == 1) {
1259
+ output.push(' ');
1260
+ dump(tree.kids[0], prefix);
1261
+ return;
1308
1262
  }
1263
+ output.push("\n");
1264
+ }
1265
+ else if (tree.value.length || prefix.length) {
1266
+ output.push("\\" + tree.value + "\n");
1267
+ }
1268
+ for (const kid of tree.kids) {
1269
+ output.push(prefix);
1270
+ dump(kid, prefix + "\t");
1309
1271
  }
1310
1272
  }
1311
- [Symbol.toStringTag];
1312
- cache = undefined;
1313
- get args() {
1314
- return this.data.slice(0, this.pub_from);
1315
- }
1316
- result() {
1317
- if ($mol_promise_like(this.cache))
1318
- return;
1319
- if (this.cache instanceof Error)
1320
- return;
1321
- return this.cache;
1273
+ dump(tree);
1274
+ return output.join('');
1275
+ }
1276
+ $.$mol_tree2_to_string = $mol_tree2_to_string;
1277
+ })($ || ($ = {}));
1278
+
1279
+ ;
1280
+ "use strict";
1281
+ var $;
1282
+ (function ($) {
1283
+ class $mol_tree2 extends Object {
1284
+ type;
1285
+ value;
1286
+ kids;
1287
+ span;
1288
+ constructor(type, value, kids, span) {
1289
+ super();
1290
+ this.type = type;
1291
+ this.value = value;
1292
+ this.kids = kids;
1293
+ this.span = span;
1294
+ this[Symbol.toStringTag] = type || '\\' + value;
1322
1295
  }
1323
- get incompleted() {
1324
- return $mol_promise_like(this.cache);
1296
+ static list(kids, span = $mol_span.unknown) {
1297
+ return new $mol_tree2('', '', kids, span);
1325
1298
  }
1326
- field() {
1327
- return this.task.name + '<>';
1299
+ list(kids) {
1300
+ return $mol_tree2.list(kids, this.span);
1328
1301
  }
1329
- constructor(id, task, host, args) {
1330
- super();
1331
- this.task = task;
1332
- this.host = host;
1333
- if (args)
1334
- this.data.push(...args);
1335
- this.pub_from = this.sub_from = args?.length ?? 0;
1336
- this[Symbol.toStringTag] = id;
1302
+ static data(value, kids = [], span = $mol_span.unknown) {
1303
+ const chunks = value.split('\n');
1304
+ if (chunks.length > 1) {
1305
+ let kid_span = span.span(span.row, span.col, 0);
1306
+ const data = chunks.map(chunk => {
1307
+ kid_span = kid_span.after(chunk.length);
1308
+ return new $mol_tree2('', chunk, [], kid_span);
1309
+ });
1310
+ kids = [...data, ...kids];
1311
+ value = '';
1312
+ }
1313
+ return new $mol_tree2('', value, kids, span);
1337
1314
  }
1338
- plan() {
1339
- $mol_wire_fiber.planning.add(this);
1340
- $mol_wire_fiber.plan();
1341
- return this;
1315
+ data(value, kids = []) {
1316
+ return $mol_tree2.data(value, kids, this.span);
1342
1317
  }
1343
- reap() {
1344
- $mol_wire_fiber.reaping.add(this);
1345
- $mol_wire_fiber.plan();
1318
+ static struct(type, kids = [], span = $mol_span.unknown) {
1319
+ if (/[ \n\t\\]/.test(type)) {
1320
+ $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
1321
+ }
1322
+ return new $mol_tree2(type, '', kids, span);
1346
1323
  }
1347
- toString() {
1348
- return this[Symbol.toStringTag];
1324
+ struct(type, kids = []) {
1325
+ return $mol_tree2.struct(type, kids, this.span);
1349
1326
  }
1350
- toJSON() {
1351
- return this[Symbol.toStringTag];
1327
+ clone(kids, span = this.span) {
1328
+ return new $mol_tree2(this.type, this.value, kids, span);
1352
1329
  }
1353
- [$mol_dev_format_head]() {
1354
- const cursor = {
1355
- [$mol_wire_cursor.stale]: '🔴',
1356
- [$mol_wire_cursor.doubt]: '🟡',
1357
- [$mol_wire_cursor.fresh]: '🟢',
1358
- [$mol_wire_cursor.final]: '🔵',
1359
- }[this.cursor] ?? this.cursor.toString();
1360
- return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
1361
- ? $mol_dev_format_auto({
1362
- [$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
1363
- [$mol_dev_format_body]: () => $mol_dev_format_native(this),
1364
- })
1365
- : $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
1330
+ text() {
1331
+ var values = [];
1332
+ for (var kid of this.kids) {
1333
+ if (kid.type)
1334
+ continue;
1335
+ values.push(kid.value);
1336
+ }
1337
+ return this.value + values.join('\n');
1366
1338
  }
1367
- get $() {
1368
- return (this.host ?? this.task)['$'];
1339
+ static fromString(str, uri = 'unknown') {
1340
+ return $$.$mol_tree2_from_string(str, uri);
1369
1341
  }
1370
- emit(quant = $mol_wire_cursor.stale) {
1371
- if (this.sub_empty)
1372
- this.plan();
1373
- else
1374
- super.emit(quant);
1342
+ toString() {
1343
+ return $$.$mol_tree2_to_string(this);
1375
1344
  }
1376
- fresh() {
1377
- if (this.cursor === $mol_wire_cursor.fresh)
1378
- return;
1379
- if (this.cursor === $mol_wire_cursor.final)
1380
- return;
1381
- check: if (this.cursor === $mol_wire_cursor.doubt) {
1382
- for (let i = this.pub_from; i < this.sub_from; i += 2) {
1383
- ;
1384
- this.data[i]?.fresh();
1385
- if (this.cursor !== $mol_wire_cursor.doubt)
1386
- break check;
1345
+ insert(value, ...path) {
1346
+ if (path.length === 0)
1347
+ return value;
1348
+ const type = path[0];
1349
+ if (typeof type === 'string') {
1350
+ let replaced = false;
1351
+ const sub = this.kids.map((item, index) => {
1352
+ if (item.type !== type)
1353
+ return item;
1354
+ replaced = true;
1355
+ return item.insert(value, ...path.slice(1));
1356
+ }).filter(Boolean);
1357
+ if (!replaced && value) {
1358
+ sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
1387
1359
  }
1388
- this.cursor = $mol_wire_cursor.fresh;
1389
- return;
1360
+ return this.clone(sub);
1390
1361
  }
1391
- const bu = this.track_on();
1392
- let result;
1393
- try {
1394
- switch (this.pub_from) {
1395
- case 0:
1396
- result = this.task.call(this.host);
1397
- break;
1398
- case 1:
1399
- result = this.task.call(this.host, this.data[0]);
1400
- break;
1401
- default:
1402
- result = this.task.call(this.host, ...this.args);
1403
- break;
1404
- }
1405
- if ($mol_promise_like(result)) {
1406
- if (wrappers.has(result)) {
1407
- result = wrappers.get(result).then(a => a);
1408
- }
1409
- else {
1410
- const put = (res) => {
1411
- if (this.cache === result)
1412
- this.put(res);
1413
- return res;
1414
- };
1415
- wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
1416
- wrappers.set(result, result);
1417
- const error = new Error(`Promise in ${this}`);
1418
- Object.defineProperty(result, 'stack', { get: () => error.stack });
1362
+ else if (typeof type === 'number') {
1363
+ const sub = this.kids.slice();
1364
+ sub[type] = (sub[type] || this.list([]))
1365
+ .insert(value, ...path.slice(1));
1366
+ return this.clone(sub.filter(Boolean));
1367
+ }
1368
+ else {
1369
+ const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
1370
+ .map(item => item.insert(value, ...path.slice(1)))
1371
+ .filter(Boolean);
1372
+ return this.clone(kids);
1373
+ }
1374
+ }
1375
+ select(...path) {
1376
+ let next = [this];
1377
+ for (const type of path) {
1378
+ if (!next.length)
1379
+ break;
1380
+ const prev = next;
1381
+ next = [];
1382
+ for (var item of prev) {
1383
+ switch (typeof (type)) {
1384
+ case 'string':
1385
+ for (var child of item.kids) {
1386
+ if (child.type == type) {
1387
+ next.push(child);
1388
+ }
1389
+ }
1390
+ break;
1391
+ case 'number':
1392
+ if (type < item.kids.length)
1393
+ next.push(item.kids[type]);
1394
+ break;
1395
+ default: next.push(...item.kids);
1419
1396
  }
1420
1397
  }
1421
1398
  }
1422
- catch (error) {
1423
- if (error instanceof Error || $mol_promise_like(error)) {
1424
- result = error;
1425
- }
1426
- else {
1427
- result = new Error(String(error), { cause: error });
1428
- }
1429
- if ($mol_promise_like(result)) {
1430
- if (wrappers.has(result)) {
1431
- result = wrappers.get(result);
1432
- }
1433
- else {
1434
- wrappers.set(result, result = Object.assign(result.finally(() => {
1435
- if (this.cache === result)
1436
- this.absorb();
1437
- }), { destructor: result.destructor || (() => { }) }));
1438
- const error = new Error(`Promise in ${this}`);
1439
- Object.defineProperty(result, 'stack', { get: () => error.stack });
1440
- }
1399
+ return this.list(next);
1400
+ }
1401
+ filter(path, value) {
1402
+ const sub = this.kids.filter(item => {
1403
+ var found = item.select(...path);
1404
+ if (value === undefined) {
1405
+ return Boolean(found.kids.length);
1406
+ }
1407
+ else {
1408
+ return found.kids.some(child => child.value == value);
1441
1409
  }
1410
+ });
1411
+ return this.clone(sub);
1412
+ }
1413
+ hack_self(belt, context = {}) {
1414
+ let handle = belt[this.type] || belt[''];
1415
+ if (!handle || handle === Object.prototype[this.type]) {
1416
+ handle = (input, belt, context) => [
1417
+ input.clone(input.hack(belt, context), context.span)
1418
+ ];
1442
1419
  }
1443
- if (!$mol_promise_like(result)) {
1444
- this.track_cut();
1420
+ try {
1421
+ return handle(this, belt, context);
1422
+ }
1423
+ catch (error) {
1424
+ error.message += `\n${this.clone([])}${this.span}`;
1425
+ $mol_fail_hidden(error);
1445
1426
  }
1446
- this.track_off(bu);
1447
- this.put(result);
1448
- return this;
1449
1427
  }
1450
- refresh() {
1451
- this.cursor = $mol_wire_cursor.stale;
1452
- this.fresh();
1428
+ hack(belt, context = {}) {
1429
+ return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
1453
1430
  }
1454
- sync() {
1455
- if (!$mol_wire_fiber.warm) {
1456
- return this.result();
1431
+ error(message, Class = Error) {
1432
+ return this.span.error(`${message}\n${this.clone([])}`, Class);
1433
+ }
1434
+ }
1435
+ $.$mol_tree2 = $mol_tree2;
1436
+ class $mol_tree2_empty extends $mol_tree2 {
1437
+ constructor() {
1438
+ super('', '', [], $mol_span.unknown);
1439
+ }
1440
+ }
1441
+ $.$mol_tree2_empty = $mol_tree2_empty;
1442
+ })($ || ($ = {}));
1443
+
1444
+ ;
1445
+ "use strict";
1446
+ var $;
1447
+ (function ($) {
1448
+ class $mol_error_syntax extends SyntaxError {
1449
+ reason;
1450
+ line;
1451
+ span;
1452
+ constructor(reason, line, span) {
1453
+ super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
1454
+ this.reason = reason;
1455
+ this.line = line;
1456
+ this.span = span;
1457
+ }
1458
+ }
1459
+ $.$mol_error_syntax = $mol_error_syntax;
1460
+ })($ || ($ = {}));
1461
+
1462
+ ;
1463
+ "use strict";
1464
+ var $;
1465
+ (function ($) {
1466
+ function $mol_tree2_from_string(str, uri = '?') {
1467
+ const span = $mol_span.entire(uri, str);
1468
+ var root = $mol_tree2.list([], span);
1469
+ var stack = [root];
1470
+ var pos = 0, row = 0, min_indent = 0;
1471
+ while (str.length > pos) {
1472
+ var indent = 0;
1473
+ var line_start = pos;
1474
+ row++;
1475
+ while (str.length > pos && str[pos] == '\t') {
1476
+ indent++;
1477
+ pos++;
1457
1478
  }
1458
- this.promote();
1459
- this.fresh();
1460
- if (this.cache instanceof Error) {
1461
- return $mol_fail_hidden(this.cache);
1479
+ if (!root.kids.length) {
1480
+ min_indent = indent;
1462
1481
  }
1463
- if ($mol_promise_like(this.cache)) {
1464
- return $mol_fail_hidden(this.cache);
1482
+ indent -= min_indent;
1483
+ if (indent < 0 || indent >= stack.length) {
1484
+ const sp = span.span(row, 1, pos - line_start);
1485
+ while (str.length > pos && str[pos] != '\n') {
1486
+ pos++;
1487
+ }
1488
+ if (indent < 0) {
1489
+ if (str.length > pos) {
1490
+ this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
1491
+ }
1492
+ }
1493
+ else {
1494
+ this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
1495
+ }
1465
1496
  }
1466
- return this.cache;
1467
- }
1468
- async async_raw() {
1469
- while (true) {
1470
- this.fresh();
1471
- if (this.cache instanceof Error) {
1472
- $mol_fail_hidden(this.cache);
1497
+ stack.length = indent + 1;
1498
+ var parent = stack[indent];
1499
+ while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
1500
+ var error_start = pos;
1501
+ while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
1502
+ pos++;
1473
1503
  }
1474
- if (!$mol_promise_like(this.cache))
1475
- return this.cache;
1476
- await Promise.race([this.cache, this.step()]);
1477
- if (!$mol_promise_like(this.cache))
1478
- return this.cache;
1479
- if (this.cursor === $mol_wire_cursor.final) {
1480
- await new Promise(() => { });
1504
+ if (pos > error_start) {
1505
+ let line_end = str.indexOf('\n', pos);
1506
+ if (line_end === -1)
1507
+ line_end = str.length;
1508
+ const sp = span.span(row, error_start - line_start + 1, pos - error_start);
1509
+ this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
1510
+ }
1511
+ var type_start = pos;
1512
+ while (str.length > pos &&
1513
+ str[pos] != '\\' &&
1514
+ str[pos] != ' ' &&
1515
+ str[pos] != '\t' &&
1516
+ str[pos] != '\n') {
1517
+ pos++;
1518
+ }
1519
+ if (pos > type_start) {
1520
+ let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
1521
+ const parent_kids = parent.kids;
1522
+ parent_kids.push(next);
1523
+ parent = next;
1524
+ }
1525
+ if (str.length > pos && str[pos] == ' ') {
1526
+ pos++;
1481
1527
  }
1482
1528
  }
1483
- }
1484
- async() {
1485
- const promise = this.async_raw();
1486
- if (!promise.destructor)
1487
- promise.destructor = () => this.destructor();
1488
- return promise;
1489
- }
1490
- step() {
1491
- return new Promise(done => {
1492
- const sub = new $mol_wire_pub_sub;
1493
- const prev = sub.track_on();
1494
- sub.track_next(this);
1495
- sub.track_off(prev);
1496
- sub.absorb = () => {
1497
- done(null);
1498
- setTimeout(() => sub.destructor());
1499
- };
1500
- });
1501
- }
1502
- destructor() {
1503
- super.destructor();
1504
- if ($mol_owning_check(this, this.cache)) {
1505
- this.cache.destructor();
1529
+ if (str.length > pos && str[pos] == '\\') {
1530
+ var data_start = pos;
1531
+ while (str.length > pos && str[pos] != '\n') {
1532
+ pos++;
1533
+ }
1534
+ let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
1535
+ const parent_kids = parent.kids;
1536
+ parent_kids.push(next);
1537
+ parent = next;
1538
+ }
1539
+ if (str.length === pos && stack.length > 0) {
1540
+ const sp = span.span(row, pos - line_start + 1, 1);
1541
+ this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
1506
1542
  }
1543
+ stack.push(parent);
1544
+ pos++;
1507
1545
  }
1546
+ return root;
1508
1547
  }
1509
- $.$mol_wire_fiber = $mol_wire_fiber;
1548
+ $.$mol_tree2_from_string = $mol_tree2_from_string;
1510
1549
  })($ || ($ = {}));
1511
1550
 
1512
1551
  ;
1513
1552
  "use strict";
1514
1553
  var $;
1515
1554
  (function ($) {
1516
- $.$mol_compare_deep_cache = new WeakMap();
1517
- function $mol_compare_deep(left, right) {
1518
- if (Object.is(left, right))
1519
- return true;
1520
- if (left === null)
1521
- return false;
1522
- if (right === null)
1523
- return false;
1524
- if (typeof left !== 'object')
1525
- return false;
1526
- if (typeof right !== 'object')
1527
- return false;
1528
- const left_proto = Reflect.getPrototypeOf(left);
1529
- const right_proto = Reflect.getPrototypeOf(right);
1530
- if (left_proto !== right_proto)
1531
- return false;
1532
- if (left instanceof Boolean)
1533
- return Object.is(left.valueOf(), right['valueOf']());
1534
- if (left instanceof Number)
1535
- return Object.is(left.valueOf(), right['valueOf']());
1536
- if (left instanceof String)
1537
- return Object.is(left.valueOf(), right['valueOf']());
1538
- if (left instanceof Date)
1539
- return Object.is(left.valueOf(), right['valueOf']());
1540
- if (left instanceof RegExp)
1541
- return left.source === right.source && left.flags === right.flags;
1542
- if (left instanceof Error)
1543
- return left.message === right.message && left.stack === right.stack;
1544
- let left_cache = $.$mol_compare_deep_cache.get(left);
1545
- if (left_cache) {
1546
- const right_cache = left_cache.get(right);
1547
- if (typeof right_cache === 'boolean')
1548
- return right_cache;
1555
+ function $mol_tree2_from_json(json, span = $mol_span.unknown) {
1556
+ if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
1557
+ return new $mol_tree2(String(json), '', [], span);
1549
1558
  }
1550
- else {
1551
- left_cache = new WeakMap();
1552
- $.$mol_compare_deep_cache.set(left, left_cache);
1559
+ if (typeof json === 'string') {
1560
+ return $mol_tree2.data(json, [], span);
1553
1561
  }
1554
- left_cache.set(right, true);
1555
- let result;
1556
- try {
1557
- if (!left_proto)
1558
- result = compare_pojo(left, right);
1559
- else if (!Reflect.getPrototypeOf(left_proto))
1560
- result = compare_pojo(left, right);
1561
- else if (Symbol.toPrimitive in left)
1562
- result = compare_primitive(left, right);
1563
- else if (Array.isArray(left))
1564
- result = compare_array(left, right);
1565
- else if (left instanceof Set)
1566
- result = compare_set(left, right);
1567
- else if (left instanceof Map)
1568
- result = compare_map(left, right);
1569
- else if (ArrayBuffer.isView(left))
1570
- result = compare_buffer(left, right);
1571
- else if (Symbol.iterator in left)
1572
- result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
1573
- else
1574
- result = false;
1562
+ if (typeof json.toJSON === 'function') {
1563
+ return $mol_tree2_from_json(json.toJSON());
1564
+ }
1565
+ if (Array.isArray(json)) {
1566
+ const sub = json.map(json => $mol_tree2_from_json(json, span));
1567
+ return new $mol_tree2('/', '', sub, span);
1568
+ }
1569
+ if (ArrayBuffer.isView(json)) {
1570
+ const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
1571
+ return $mol_tree2.data(String.fromCharCode(...buf), [], span);
1575
1572
  }
1576
- finally {
1577
- left_cache.set(right, result);
1573
+ if (json instanceof Date) {
1574
+ return new $mol_tree2('', json.toISOString(), [], span);
1578
1575
  }
1579
- return result;
1580
- }
1581
- $.$mol_compare_deep = $mol_compare_deep;
1582
- function compare_array(left, right) {
1583
- const len = left.length;
1584
- if (len !== right.length)
1585
- return false;
1586
- for (let i = 0; i < len; ++i) {
1587
- if (!$mol_compare_deep(left[i], right[i]))
1588
- return false;
1576
+ if (json.toString !== Object.prototype.toString) {
1577
+ return $mol_tree2.data(json.toString(), [], span);
1589
1578
  }
1590
- return true;
1591
- }
1592
- function compare_buffer(left, right) {
1593
- const len = left.byteLength;
1594
- if (len !== right.byteLength)
1595
- return false;
1596
- if (left instanceof DataView)
1597
- return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
1598
- for (let i = 0; i < len; ++i) {
1599
- if (left[i] !== right[i])
1600
- return false;
1579
+ if (json instanceof Error) {
1580
+ const { name, message, stack } = json;
1581
+ json = { ...json, name, message, stack };
1601
1582
  }
1602
- return true;
1603
- }
1604
- function compare_iterator(left, right) {
1605
- while (true) {
1606
- const left_next = left.next();
1607
- const right_next = right.next();
1608
- if (left_next.done !== right_next.done)
1609
- return false;
1610
- if (left_next.done)
1611
- break;
1612
- if (!$mol_compare_deep(left_next.value, right_next.value))
1613
- return false;
1583
+ const sub = [];
1584
+ for (var key in json) {
1585
+ const val = json[key];
1586
+ if (val === undefined)
1587
+ continue;
1588
+ const subsub = $mol_tree2_from_json(val, span);
1589
+ if (/^[^\n\t\\ ]+$/.test(key)) {
1590
+ sub.push(new $mol_tree2(key, '', [subsub], span));
1591
+ }
1592
+ else {
1593
+ sub.push($mol_tree2.data(key, [subsub], span));
1594
+ }
1614
1595
  }
1615
- return true;
1616
- }
1617
- function compare_set(left, right) {
1618
- if (left.size !== right.size)
1619
- return false;
1620
- return compare_iterator(left.values(), right.values());
1621
- }
1622
- function compare_map(left, right) {
1623
- if (left.size !== right.size)
1624
- return false;
1625
- return compare_iterator(left.keys(), right.keys())
1626
- && compare_iterator(left.values(), right.values());
1596
+ return new $mol_tree2('*', '', sub, span);
1627
1597
  }
1628
- function compare_pojo(left, right) {
1629
- const left_keys = Object.getOwnPropertyNames(left);
1630
- const right_keys = Object.getOwnPropertyNames(right);
1631
- if (!compare_array(left_keys, right_keys))
1632
- return false;
1633
- for (let key of left_keys) {
1634
- if (!$mol_compare_deep(left[key], right[key]))
1635
- return false;
1636
- }
1637
- const left_syms = Object.getOwnPropertySymbols(left);
1638
- const right_syms = Object.getOwnPropertySymbols(right);
1639
- if (!compare_array(left_syms, right_syms))
1640
- return false;
1641
- for (let key of left_syms) {
1642
- if (!$mol_compare_deep(left[key], right[key]))
1643
- return false;
1598
+ $.$mol_tree2_from_json = $mol_tree2_from_json;
1599
+ })($ || ($ = {}));
1600
+
1601
+ ;
1602
+ "use strict";
1603
+ var $;
1604
+ (function ($) {
1605
+ class $mol_term_color {
1606
+ static reset = this.ansi(0, 0);
1607
+ static bold = this.ansi(1, 22);
1608
+ static italic = this.ansi(3, 23);
1609
+ static underline = this.ansi(4, 24);
1610
+ static inverse = this.ansi(7, 27);
1611
+ static hidden = this.ansi(8, 28);
1612
+ static strike = this.ansi(9, 29);
1613
+ static gray = this.ansi(90, 39);
1614
+ static red = this.ansi(91, 39);
1615
+ static green = this.ansi(92, 39);
1616
+ static yellow = this.ansi(93, 39);
1617
+ static blue = this.ansi(94, 39);
1618
+ static magenta = this.ansi(95, 39);
1619
+ static cyan = this.ansi(96, 39);
1620
+ static Gray = (str) => this.inverse(this.gray(str));
1621
+ static Red = (str) => this.inverse(this.red(str));
1622
+ static Green = (str) => this.inverse(this.green(str));
1623
+ static Yellow = (str) => this.inverse(this.yellow(str));
1624
+ static Blue = (str) => this.inverse(this.blue(str));
1625
+ static Magenta = (str) => this.inverse(this.magenta(str));
1626
+ static Cyan = (str) => this.inverse(this.cyan(str));
1627
+ static ansi(open, close) {
1628
+ if (typeof process === 'undefined')
1629
+ return String;
1630
+ if (!process.stdout.isTTY)
1631
+ return String;
1632
+ const prefix = `\x1b[${open}m`;
1633
+ const postfix = `\x1b[${close}m`;
1634
+ const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
1635
+ return function colorer(str) {
1636
+ str = String(str);
1637
+ if (str === '')
1638
+ return str;
1639
+ const suffix = str.replace(suffix_regexp, prefix);
1640
+ return prefix + suffix + postfix;
1641
+ };
1644
1642
  }
1645
- return true;
1646
1643
  }
1647
- function compare_primitive(left, right) {
1648
- return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
1644
+ $.$mol_term_color = $mol_term_color;
1645
+ })($ || ($ = {}));
1646
+
1647
+ ;
1648
+ "use strict";
1649
+ var $;
1650
+ (function ($) {
1651
+ function $mol_log3_node_make(level, output, type, color) {
1652
+ return function $mol_log3_logger(event) {
1653
+ if (!event.time)
1654
+ event = { time: new Date().toISOString(), ...event };
1655
+ let tree = this.$mol_tree2_from_json(event);
1656
+ tree = tree.struct(type, tree.kids);
1657
+ let str = color(tree.toString());
1658
+ this.console[level](str);
1659
+ const self = this;
1660
+ return () => self.console.groupEnd();
1661
+ };
1649
1662
  }
1663
+ $.$mol_log3_node_make = $mol_log3_node_make;
1664
+ $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
1665
+ $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
1666
+ $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
1667
+ $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
1668
+ $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
1669
+ $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
1650
1670
  })($ || ($ = {}));
1651
1671
 
1652
1672
  ;
@@ -1765,97 +1785,115 @@ var $;
1765
1785
  class $mol_run_error extends $mol_error_mix {
1766
1786
  }
1767
1787
  $.$mol_run_error = $mol_run_error;
1768
- const child_process = $node['child_process'];
1769
- $.$mol_run_spawn = child_process.spawn.bind(child_process);
1770
- $.$mol_run_spawn_sync = child_process.spawnSync.bind(child_process);
1771
- function $mol_run_async({ dir, timeout, command, env }) {
1772
- const args_raw = typeof command === 'string' ? command.split(' ') : command;
1773
- const [app, ...args] = args_raw;
1774
- if (!env?.MOL_RUN_ASYNC) {
1775
- this.$mol_log3_come({
1776
- place: '$mol_run_sync',
1788
+ $.$mol_run_spawn = (...args) => $node['child_process'].spawn(...args);
1789
+ $.$mol_run_spawn_sync = (...args) => $node['child_process'].spawnSync(...args);
1790
+ class $mol_run extends $mol_object {
1791
+ static async_enabled() {
1792
+ return Boolean(this.$.$mol_env()['MOL_RUN_ASYNC']);
1793
+ }
1794
+ static spawn(options) {
1795
+ const sync = !this.async_enabled() || !Boolean($mol_wire_auto());
1796
+ const env = options.env ?? this.$.$mol_env();
1797
+ return $mol_wire_sync(this).spawn_async({ ...options, sync, env });
1798
+ }
1799
+ static spawn_async({ dir, sync, timeout, command, env }) {
1800
+ const args_raw = typeof command === 'string' ? command.split(' ') : command;
1801
+ const [app, ...args] = args_raw;
1802
+ const opts = { shell: true, cwd: dir, env };
1803
+ const log_object = {
1804
+ place: `${this}.spawn()`,
1777
1805
  message: 'Run',
1778
1806
  command: args_raw.join(' '),
1779
1807
  dir: $node.path.relative('', dir),
1808
+ };
1809
+ if (sync) {
1810
+ this.$.$mol_log3_come({
1811
+ hint: 'Run inside fiber',
1812
+ ...log_object
1813
+ });
1814
+ let error;
1815
+ let res;
1816
+ try {
1817
+ res = this.$.$mol_run_spawn_sync(app, args, opts);
1818
+ error = res.error;
1819
+ }
1820
+ catch (err) {
1821
+ error = err;
1822
+ }
1823
+ if (!res || error || res.status) {
1824
+ throw new $mol_run_error(this.error_message(res), { ...log_object, status: res?.status, signal: res?.signal }, ...(error ? [error] : []));
1825
+ }
1826
+ return res;
1827
+ }
1828
+ let sub;
1829
+ try {
1830
+ sub = this.$.$mol_run_spawn(app, args, {
1831
+ ...opts,
1832
+ stdio: ['pipe', 'inherit', 'inherit'],
1833
+ });
1834
+ }
1835
+ catch (error) {
1836
+ throw new $mol_run_error(this.error_message(undefined), log_object, error);
1837
+ }
1838
+ const pid = sub.pid ?? 0;
1839
+ this.$.$mol_log3_come({
1840
+ ...log_object,
1841
+ pid,
1780
1842
  });
1781
- const res = this.$mol_run_spawn_sync(app, args, { shell: true, cwd: dir, env });
1782
- if (res.status)
1783
- $mol_fail(new Error(res.stderr.toString() || 'Exit(' + res.status + ')'));
1784
- return res;
1785
- }
1786
- const sub = this.$mol_run_spawn(app, args, {
1787
- shell: true,
1788
- cwd: dir,
1789
- env
1790
- });
1791
- this.$mol_log3_come({
1792
- place: '$mol_run_async',
1793
- pid: sub.pid,
1794
- message: 'Run',
1795
- command: args_raw.join(' '),
1796
- dir: $node.path.relative('', dir),
1797
- });
1798
- let killed = false;
1799
- let timer;
1800
- const std_data = [];
1801
- const error_data = [];
1802
- const add = (std_chunk, error_chunk) => {
1803
- if (std_chunk)
1804
- std_data.push(std_chunk);
1805
- if (error_chunk)
1806
- error_data.push(error_chunk);
1807
- if (!timeout)
1808
- return;
1809
- clearTimeout(timer);
1810
- timer = setTimeout(() => {
1811
- const signal = killed ? 'SIGKILL' : 'SIGTERM';
1812
- killed = true;
1813
- add();
1814
- sub.kill(signal);
1815
- }, timeout);
1816
- };
1817
- add();
1818
- sub.stdout?.on('data', data => add(data));
1819
- sub.stderr?.on('data', data => add(undefined, data));
1820
- const promise = new Promise((done, fail) => {
1821
- const close = (error, status = null, signal = null) => {
1822
- if (!timer && timeout)
1843
+ let timeout_kill = false;
1844
+ let timer;
1845
+ const std_data = [];
1846
+ const error_data = [];
1847
+ const add = (std_chunk, error_chunk) => {
1848
+ if (std_chunk)
1849
+ std_data.push(std_chunk);
1850
+ if (error_chunk)
1851
+ error_data.push(error_chunk);
1852
+ if (!timeout)
1823
1853
  return;
1824
1854
  clearTimeout(timer);
1825
- timer = undefined;
1826
- const res = {
1827
- pid: sub.pid,
1828
- status,
1829
- signal,
1830
- get stdout() { return Buffer.concat(std_data); },
1831
- get stderr() { return Buffer.concat(error_data); }
1832
- };
1833
- this.$mol_log3_done({
1834
- place: '$mol_run_async',
1835
- pid: sub.pid,
1836
- message: 'Run',
1837
- status,
1838
- command: args_raw.join(' '),
1839
- dir: $node.path.relative('', dir),
1840
- });
1841
- if (error || status || killed)
1842
- return fail(new $mol_run_error((res.stderr.toString() || res.stdout.toString() || 'Run error') + (killed ? ', timeout' : ''), { signal, timeout: killed }, ...error ? [error] : []));
1843
- done(res);
1855
+ timer = setTimeout(() => {
1856
+ const signal = timeout_kill ? 'SIGKILL' : 'SIGTERM';
1857
+ timeout_kill = true;
1858
+ add();
1859
+ sub.kill(signal);
1860
+ }, timeout);
1844
1861
  };
1845
- sub.on('disconnect', () => close(new Error('Disconnected')));
1846
- sub.on('error', err => close(err));
1847
- sub.on('exit', (status, signal) => close(null, status, signal));
1848
- });
1849
- return Object.assign(promise, { destructor: () => {
1850
- clearTimeout(timer);
1851
- sub.kill('SIGKILL');
1852
- } });
1853
- }
1854
- $.$mol_run_async = $mol_run_async;
1855
- function $mol_run(options) {
1856
- if (!options.env)
1857
- options = { ...options, env: this.$mol_env() };
1858
- return $mol_wire_sync(this).$mol_run_async(options);
1862
+ add();
1863
+ sub.stdout?.on('data', data => add(data));
1864
+ sub.stderr?.on('data', data => add(undefined, data));
1865
+ const result_promise = new Promise((done, fail) => {
1866
+ const close = (error, status = null, signal = null) => {
1867
+ if (!timer && timeout)
1868
+ return;
1869
+ clearTimeout(timer);
1870
+ timer = undefined;
1871
+ const res = {
1872
+ pid,
1873
+ signal,
1874
+ get stdout() { return Buffer.concat(std_data); },
1875
+ get stderr() { return Buffer.concat(error_data); }
1876
+ };
1877
+ if (error || status || timeout_kill)
1878
+ return fail(new $mol_run_error(this.error_message(res) + (timeout_kill ? ', timeout' : ''), { ...log_object, pid, status, signal, timeout_kill }, ...error ? [error] : []));
1879
+ this.$.$mol_log3_done({
1880
+ ...log_object,
1881
+ pid,
1882
+ });
1883
+ done(res);
1884
+ };
1885
+ sub.on('disconnect', () => close(new Error('Disconnected')));
1886
+ sub.on('error', err => close(err));
1887
+ sub.on('exit', (status, signal) => close(null, status, signal));
1888
+ });
1889
+ return Object.assign(result_promise, { destructor: () => {
1890
+ clearTimeout(timer);
1891
+ sub.kill('SIGKILL');
1892
+ } });
1893
+ }
1894
+ static error_message(res) {
1895
+ return res?.stderr.toString() || res?.stdout.toString() || 'Run error';
1896
+ }
1859
1897
  }
1860
1898
  $.$mol_run = $mol_run;
1861
1899
  })($ || ($ = {}));
@@ -1865,7 +1903,7 @@ var $;
1865
1903
  var $;
1866
1904
  (function ($) {
1867
1905
  function $mol_exec(dir, command, ...args) {
1868
- return this.$mol_run({ command: [command, ...args], dir });
1906
+ return this.$mol_run.spawn({ command: [command, ...args], dir });
1869
1907
  }
1870
1908
  $.$mol_exec = $mol_exec;
1871
1909
  })($ || ($ = {}));
@@ -2611,26 +2649,6 @@ var $;
2611
2649
  $.$mol_wire_race = $mol_wire_race;
2612
2650
  })($ || ($ = {}));
2613
2651
 
2614
- ;
2615
- "use strict";
2616
- var $;
2617
- (function ($_1) {
2618
- let $$;
2619
- (function ($$) {
2620
- let $;
2621
- })($$ = $_1.$$ || ($_1.$$ = {}));
2622
- $_1.$mol_object_field = Symbol('$mol_object_field');
2623
- class $mol_object extends $mol_object2 {
2624
- static make(config) {
2625
- return super.create(obj => {
2626
- for (let key in config)
2627
- obj[key] = config[key];
2628
- });
2629
- }
2630
- }
2631
- $_1.$mol_object = $mol_object;
2632
- })($ || ($ = {}));
2633
-
2634
2652
  ;
2635
2653
  "use strict";
2636
2654
  var $;
@@ -3516,6 +3534,25 @@ var $;
3516
3534
  });
3517
3535
  })($ || ($ = {}));
3518
3536
 
3537
+ ;
3538
+ "use strict";
3539
+ var $;
3540
+ (function ($) {
3541
+ $mol_test({
3542
+ 'init with overload'() {
3543
+ class X extends $mol_object {
3544
+ foo() {
3545
+ return 1;
3546
+ }
3547
+ }
3548
+ var x = X.make({
3549
+ foo: () => 2,
3550
+ });
3551
+ $mol_assert_equal(x.foo(), 2);
3552
+ },
3553
+ });
3554
+ })($ || ($ = {}));
3555
+
3519
3556
  ;
3520
3557
  "use strict";
3521
3558
  var $;
@@ -3900,23 +3937,49 @@ var $;
3900
3937
  $mol_test({
3901
3938
  async 'exec timeout auto kill child process'($) {
3902
3939
  let close_mock = () => { };
3903
- const context_mock = $.$mol_ambient({
3904
- $mol_run_spawn: () => ({
3940
+ const error_message = 'Run error, timeout';
3941
+ function mol_run_spawn_sync_mock() {
3942
+ return {
3943
+ output: [],
3944
+ stdout: error_message,
3945
+ stderr: '',
3946
+ status: 0,
3947
+ signal: null,
3948
+ pid: 123,
3949
+ };
3950
+ }
3951
+ function mol_run_spawn_mock() {
3952
+ return {
3905
3953
  on(name, cb) {
3906
3954
  if (name === 'exit')
3907
3955
  close_mock = cb;
3908
3956
  },
3909
3957
  kill() { close_mock(); }
3910
- })
3958
+ };
3959
+ }
3960
+ const context_mock = $.$mol_ambient({
3961
+ $mol_run_spawn_sync: mol_run_spawn_sync_mock,
3962
+ $mol_run_spawn: mol_run_spawn_mock
3911
3963
  });
3964
+ class $mol_run_mock extends $mol_run {
3965
+ static get $() { return context_mock; }
3966
+ static async_enabled() {
3967
+ return true;
3968
+ }
3969
+ }
3912
3970
  let message = '';
3913
3971
  try {
3914
- const res = await $mol_wire_async(context_mock).$mol_run({ command: 'sleep 10', dir: '.', timeout: 10, env: { 'MOL_RUN_ASYNC': '1' } });
3972
+ const res = await $mol_wire_async($mol_run_mock).spawn({
3973
+ command: 'sleep 10',
3974
+ dir: '.',
3975
+ timeout: 10,
3976
+ env: { 'MOL_RUN_ASYNC': '1' }
3977
+ });
3915
3978
  }
3916
3979
  catch (e) {
3917
3980
  message = e.message;
3918
3981
  }
3919
- $mol_assert_equal(message, 'Run error, timeout');
3982
+ $mol_assert_equal(message, error_message);
3920
3983
  }
3921
3984
  });
3922
3985
  })($ || ($ = {}));
@@ -5320,25 +5383,6 @@ var $;
5320
5383
  });
5321
5384
  })($ || ($ = {}));
5322
5385
 
5323
- ;
5324
- "use strict";
5325
- var $;
5326
- (function ($) {
5327
- $mol_test({
5328
- 'init with overload'() {
5329
- class X extends $mol_object {
5330
- foo() {
5331
- return 1;
5332
- }
5333
- }
5334
- var x = X.make({
5335
- foo: () => 2,
5336
- });
5337
- $mol_assert_equal(x.foo(), 2);
5338
- },
5339
- });
5340
- })($ || ($ = {}));
5341
-
5342
5386
  ;
5343
5387
  "use strict";
5344
5388