mol_text_distance 0.0.1491 → 0.0.1493

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
@@ -100,7 +100,7 @@ var $;
100
100
  var $;
101
101
  (function ($) {
102
102
  function $mol_fail_hidden(error) {
103
- throw error;
103
+ throw error; /// Use 'Never Pause Here' breakpoint in DevTools or simply blackbox this script
104
104
  }
105
105
  $.$mol_fail_hidden = $mol_fail_hidden;
106
106
  })($ || ($ = {}));
@@ -215,7 +215,7 @@ var $;
215
215
  "use strict";
216
216
  var $;
217
217
  (function ($) {
218
- const mod = require('module');
218
+ const mod = require /****/('module');
219
219
  const internals = mod.builtinModules;
220
220
  function $node_internal_check(name) {
221
221
  if (name.startsWith('node:'))
@@ -229,8 +229,8 @@ var $;
229
229
  "use strict";
230
230
  var $;
231
231
  (function ($) {
232
- const path = require('path');
233
- const mod = require('module');
232
+ const path = require /****/('path');
233
+ const mod = require /****/('module');
234
234
  const localRequire = mod.createRequire(path.join(process.cwd(), 'package.json'));
235
235
  function $node_autoinstall(name) {
236
236
  try {
@@ -351,6 +351,7 @@ var $;
351
351
  ])
352
352
  ].map(frame_normalize).join('\n')
353
353
  });
354
+ // в nodejs, что б не дублировалось cause в консоли
354
355
  Object.defineProperty(this, 'cause', {
355
356
  get: () => cause
356
357
  });
@@ -541,6 +542,9 @@ var $;
541
542
  [Symbol.dispose]() {
542
543
  this.destructor();
543
544
  }
545
+ //[ Symbol.toPrimitive ]( hint: string ) {
546
+ // return hint === 'number' ? this.valueOf() : this.toString()
547
+ //}
544
548
  toString() {
545
549
  return this[Symbol.toStringTag] || this.constructor.name + '<>';
546
550
  }
@@ -617,6 +621,7 @@ var $;
617
621
  "use strict";
618
622
  var $;
619
623
  (function ($) {
624
+ /** Generates unique identifier. */
620
625
  function $mol_guid(length = 8, exists = () => false) {
621
626
  for (;;) {
622
627
  let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
@@ -632,11 +637,16 @@ var $;
632
637
  "use strict";
633
638
  var $;
634
639
  (function ($) {
640
+ /** Special status statuses. */
635
641
  let $mol_wire_cursor;
636
642
  (function ($mol_wire_cursor) {
643
+ /** Update required. */
637
644
  $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
645
+ /** Some of (transitive) pub update required. */
638
646
  $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
647
+ /** Actual state but may be dropped. */
639
648
  $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
649
+ /** State will never be changed. */
640
650
  $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
641
651
  })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
642
652
  })($ || ($ = {}));
@@ -645,6 +655,9 @@ var $;
645
655
  "use strict";
646
656
  var $;
647
657
  (function ($) {
658
+ /**
659
+ * Collects subscribers in compact array. 28B
660
+ */
648
661
  class $mol_wire_pub extends Object {
649
662
  constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
650
663
  super();
@@ -652,10 +665,17 @@ var $;
652
665
  }
653
666
  [Symbol.toStringTag];
654
667
  data = [];
668
+ // Derived objects should be Arrays.
655
669
  static get [Symbol.species]() {
656
670
  return Array;
657
671
  }
658
- sub_from = 0;
672
+ /**
673
+ * Index of first subscriber.
674
+ */
675
+ sub_from = 0; // 4B
676
+ /**
677
+ * All current subscribers.
678
+ */
659
679
  get sub_list() {
660
680
  const res = [];
661
681
  for (let i = this.sub_from; i < this.data.length; i += 2) {
@@ -663,14 +683,23 @@ var $;
663
683
  }
664
684
  return res;
665
685
  }
686
+ /**
687
+ * Has any subscribers or not.
688
+ */
666
689
  get sub_empty() {
667
690
  return this.sub_from === this.data.length;
668
691
  }
692
+ /**
693
+ * Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.
694
+ */
669
695
  sub_on(sub, pub_pos) {
670
696
  const pos = this.data.length;
671
697
  this.data.push(sub, pub_pos);
672
698
  return pos;
673
699
  }
700
+ /**
701
+ * Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.
702
+ */
674
703
  sub_off(sub_pos) {
675
704
  if (!(sub_pos < this.data.length)) {
676
705
  $mol_fail(new Error(`Wrong pos ${sub_pos}`));
@@ -683,21 +712,39 @@ var $;
683
712
  if (end === this.sub_from)
684
713
  this.reap();
685
714
  }
715
+ /**
716
+ * Called when last sub was unsubscribed.
717
+ **/
686
718
  reap() { }
719
+ /**
720
+ * Autowire this publisher with current subscriber.
721
+ **/
687
722
  promote() {
688
723
  $mol_wire_auto()?.track_next(this);
689
724
  }
725
+ /**
726
+ * Enforce actualization. Should not throw errors.
727
+ */
690
728
  fresh() { }
729
+ /**
730
+ * Allow to put data to caches in the subtree.
731
+ */
691
732
  complete() { }
692
733
  get incompleted() {
693
734
  return false;
694
735
  }
736
+ /**
737
+ * Notify subscribers about self changes.
738
+ */
695
739
  emit(quant = $mol_wire_cursor.stale) {
696
740
  for (let i = this.sub_from; i < this.data.length; i += 2) {
697
741
  ;
698
742
  this.data[i].absorb(quant, this.data[i + 1]);
699
743
  }
700
744
  }
745
+ /**
746
+ * Moves peer from one position to another. Doesn't clear data at old position!
747
+ */
701
748
  peer_move(from_pos, to_pos) {
702
749
  const peer = this.data[from_pos];
703
750
  const self_pos = this.data[from_pos + 1];
@@ -705,6 +752,9 @@ var $;
705
752
  this.data[to_pos + 1] = self_pos;
706
753
  peer.peer_repos(self_pos, to_pos);
707
754
  }
755
+ /**
756
+ * Updates self position in the peer.
757
+ */
708
758
  peer_repos(peer_pos, self_pos) {
709
759
  this.data[peer_pos + 1] = self_pos;
710
760
  }
@@ -720,10 +770,16 @@ var $;
720
770
  var $;
721
771
  (function ($) {
722
772
  $.$mol_wire_auto_sub = null;
773
+ /**
774
+ * When fulfilled, all publishers are promoted to this subscriber on access to its.
775
+ */
723
776
  function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
724
777
  return $.$mol_wire_auto_sub = next;
725
778
  }
726
779
  $.$mol_wire_auto = $mol_wire_auto;
780
+ /**
781
+ * Affection queue. Used to prevent accidental stack overflow on emit.
782
+ */
727
783
  $.$mol_wire_affected = [];
728
784
  })($ || ($ = {}));
729
785
 
@@ -731,6 +787,7 @@ var $;
731
787
  "use strict";
732
788
  var $;
733
789
  (function ($) {
790
+ // https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview#
734
791
  $['devtoolsFormatters'] ||= [];
735
792
  function $mol_dev_format_register(config) {
736
793
  $['devtoolsFormatters'].push(config);
@@ -782,6 +839,7 @@ var $;
782
839
  return false;
783
840
  if (!val)
784
841
  return false;
842
+ // if( Error.isError( val ) ) true
785
843
  if (val[$.$mol_dev_format_body])
786
844
  return true;
787
845
  return false;
@@ -799,12 +857,16 @@ var $;
799
857
  return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
800
858
  }
801
859
  }
860
+ // if( Error.isError( val ) ) {
861
+ // return $mol_dev_format_native( val )
862
+ // }
802
863
  return null;
803
864
  },
804
865
  });
805
866
  function $mol_dev_format_native(obj) {
806
867
  if (typeof obj === 'undefined')
807
868
  return $.$mol_dev_format_shade('undefined');
869
+ // if( ![ 'object', 'function', 'symbol' ].includes( typeof obj ) ) return obj
808
870
  return [
809
871
  'object',
810
872
  {
@@ -862,6 +924,9 @@ var $;
862
924
  'margin-left': '13px'
863
925
  });
864
926
  class Stack extends Array {
927
+ // [ Symbol.toPrimitive ]() {
928
+ // return this.toString()
929
+ // }
865
930
  toString() {
866
931
  return this.join('\n');
867
932
  }
@@ -884,6 +949,7 @@ var $;
884
949
  this.method = call.getMethodName() ?? '';
885
950
  if (this.method === this.function)
886
951
  this.method = '';
952
+ // const func = c.getFunction()
887
953
  this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
888
954
  this.eval = call.getEvalOrigin() ?? '';
889
955
  this.source = call.getScriptNameOrSourceURL() ?? '';
@@ -930,9 +996,16 @@ var $;
930
996
  "use strict";
931
997
  var $;
932
998
  (function ($) {
999
+ /**
1000
+ * Publisher that can auto collect other publishers. 32B
1001
+ *
1002
+ * P1 P2 P3 P4 S1 S2 S3
1003
+ * ^ ^
1004
+ * pubs_from subs_from
1005
+ */
933
1006
  class $mol_wire_pub_sub extends $mol_wire_pub {
934
- pub_from = 0;
935
- cursor = $mol_wire_cursor.stale;
1007
+ pub_from = 0; // 4B
1008
+ cursor = $mol_wire_cursor.stale; // 4B
936
1009
  get temp() {
937
1010
  return false;
938
1011
  }
@@ -1050,10 +1123,27 @@ var $;
1050
1123
  return;
1051
1124
  this.cursor = quant;
1052
1125
  this.emit($mol_wire_cursor.doubt);
1126
+ // if( pos >= 0 && pos < this.sub_from - 2 ) {
1127
+ // const pub = this.data[ pos ] as $mol_wire_pub
1128
+ // if( pub instanceof $mol_wire_task ) return
1129
+ // for(
1130
+ // let cursor = this.pub_from;
1131
+ // cursor < this.sub_from;
1132
+ // cursor += 2
1133
+ // ) {
1134
+ // const pub = this.data[ cursor ] as $mol_wire_pub
1135
+ // if( pub instanceof $mol_wire_task ) {
1136
+ // pub.destructor()
1137
+ // }
1138
+ // }
1139
+ // }
1053
1140
  }
1054
1141
  [$mol_dev_format_head]() {
1055
1142
  return $mol_dev_format_native(this);
1056
1143
  }
1144
+ /**
1145
+ * Is subscribed to any publisher or not.
1146
+ */
1057
1147
  get pub_empty() {
1058
1148
  return this.sub_from === this.pub_from;
1059
1149
  }
@@ -1123,6 +1213,7 @@ var $;
1123
1213
  "use strict";
1124
1214
  var $;
1125
1215
  (function ($) {
1216
+ /// @todo right orderinng
1126
1217
  $.$mol_after_mock_queue = [];
1127
1218
  function $mol_after_mock_warp() {
1128
1219
  const queue = $.$mol_after_mock_queue.splice(0);
@@ -1199,6 +1290,13 @@ var $;
1199
1290
  var $;
1200
1291
  (function ($) {
1201
1292
  const wrappers = new WeakMap();
1293
+ /**
1294
+ * Suspendable task with support both sync/async api.
1295
+ *
1296
+ * A1 A2 A3 A4 P1 P2 P3 P4 S1 S2 S3
1297
+ * ^ ^ ^
1298
+ * args_from pubs_from subs_from
1299
+ **/
1202
1300
  class $mol_wire_fiber extends $mol_wire_pub_sub {
1203
1301
  task;
1204
1302
  host;
@@ -1219,6 +1317,7 @@ var $;
1219
1317
  });
1220
1318
  }
1221
1319
  static sync() {
1320
+ // Sync whole fiber graph
1222
1321
  while (this.planning.size) {
1223
1322
  for (const fiber of this.planning) {
1224
1323
  this.planning.delete(fiber);
@@ -1229,6 +1328,7 @@ var $;
1229
1328
  fiber.fresh();
1230
1329
  }
1231
1330
  }
1331
+ // Collect garbage
1232
1332
  while (this.reaping.size) {
1233
1333
  const fibers = this.reaping;
1234
1334
  this.reaping = new Set;
@@ -1380,6 +1480,10 @@ var $;
1380
1480
  this.cursor = $mol_wire_cursor.stale;
1381
1481
  this.fresh();
1382
1482
  }
1483
+ /**
1484
+ * Synchronous execution. Throws Promise when waits async task (SuspenseAPI provider).
1485
+ * Should be called inside SuspenseAPI consumer (ie fiber).
1486
+ */
1383
1487
  sync() {
1384
1488
  if (!$mol_wire_fiber.warm) {
1385
1489
  return this.result();
@@ -1394,6 +1498,10 @@ var $;
1394
1498
  }
1395
1499
  return this.cache;
1396
1500
  }
1501
+ /**
1502
+ * Asynchronous execution.
1503
+ * It's SuspenseAPI consumer. So SuspenseAPI providers can be called inside.
1504
+ */
1397
1505
  async async_raw() {
1398
1506
  while (true) {
1399
1507
  this.fresh();
@@ -1406,6 +1514,7 @@ var $;
1406
1514
  if (!$mol_promise_like(this.cache))
1407
1515
  return this.cache;
1408
1516
  if (this.cursor === $mol_wire_cursor.final) {
1517
+ // never ends on destructed fiber
1409
1518
  await new Promise(() => { });
1410
1519
  }
1411
1520
  }
@@ -1534,6 +1643,7 @@ var $;
1534
1643
  "use strict";
1535
1644
  var $;
1536
1645
  (function ($) {
1646
+ /** Log begin of collapsed group only when some logged inside, returns func to close group */
1537
1647
  function $mol_log3_area_lazy(event) {
1538
1648
  const self = this.$;
1539
1649
  const stack = self.$mol_log3_stack;
@@ -1558,6 +1668,7 @@ var $;
1558
1668
  "use strict";
1559
1669
  var $;
1560
1670
  (function ($) {
1671
+ /** Module for working with terminal. Text coloring when output in terminal */
1561
1672
  class $mol_term_color {
1562
1673
  static reset = this.ansi(0, 0);
1563
1674
  static bold = this.ansi(1, 22);
@@ -1643,6 +1754,7 @@ var $;
1643
1754
  "use strict";
1644
1755
  var $;
1645
1756
  (function ($) {
1757
+ /** One-shot fiber */
1646
1758
  class $mol_wire_task extends $mol_wire_fiber {
1647
1759
  static getter(task) {
1648
1760
  return function $mol_wire_task_get(host, args) {
@@ -1668,6 +1780,7 @@ var $;
1668
1780
  }
1669
1781
  const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
1670
1782
  const next = new $mol_wire_task(key, task, host, args);
1783
+ // Disabled because non-idempotency is required for try-catch
1671
1784
  if (existen?.temp) {
1672
1785
  $$.$mol_log3_warn({
1673
1786
  place: '$mol_wire_task',
@@ -1700,7 +1813,7 @@ var $;
1700
1813
  try {
1701
1814
  next[Symbol.toStringTag] = this[Symbol.toStringTag];
1702
1815
  }
1703
- catch {
1816
+ catch { // Promises throw in strict mode
1704
1817
  Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
1705
1818
  }
1706
1819
  }
@@ -1725,6 +1838,9 @@ var $;
1725
1838
  "use strict";
1726
1839
  var $;
1727
1840
  (function ($) {
1841
+ /**
1842
+ * Decorates method to fiber to ensure it is executed only once inside other fiber.
1843
+ */
1728
1844
  function $mol_wire_method(host, field, descr) {
1729
1845
  if (!descr)
1730
1846
  descr = Reflect.getOwnPropertyDescriptor(host, field);
@@ -1751,6 +1867,7 @@ var $;
1751
1867
  "use strict";
1752
1868
  var $;
1753
1869
  (function ($) {
1870
+ /** Convert a pseudo-synchronous (Suspense API) API to an explicit asynchronous one (for integrating with external systems). */
1754
1871
  function $mol_wire_async(obj) {
1755
1872
  let fiber;
1756
1873
  const temp = $mol_wire_task.getter(obj);
@@ -1862,6 +1979,10 @@ var $;
1862
1979
  props[field] = get_val;
1863
1980
  return get_val;
1864
1981
  }
1982
+ /**
1983
+ * Convert asynchronous (promise-based) API to synchronous by wrapping function and method calls in a fiber.
1984
+ * @see https://mol.hyoo.ru/#!section=docs/=1fcpsq_1wh0h2
1985
+ */
1865
1986
  function $mol_wire_sync(obj) {
1866
1987
  return new Proxy(obj, {
1867
1988
  get(obj, field) {
@@ -2363,6 +2484,12 @@ var $;
2363
2484
  createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
2364
2485
  };
2365
2486
  $.$mol_jsx_frag = '';
2487
+ /**
2488
+ * JSX adapter that makes DOM tree.
2489
+ * Generates global unique ids for every DOM-element by components tree with ids.
2490
+ * Ensures all local ids are unique.
2491
+ * Can reuse an existing nodes by GUIDs when used inside [`mol_jsx_attach`](https://github.com/hyoo-ru/mam_mol/tree/master/jsx/attach).
2492
+ */
2366
2493
  function $mol_jsx(Elem, props, ...childNodes) {
2367
2494
  const id = props && props.id || '';
2368
2495
  const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
@@ -2473,6 +2600,8 @@ var $;
2473
2600
 
2474
2601
  ;
2475
2602
  "use strict";
2603
+ /** @jsx $mol_jsx */
2604
+ /** @jsxFrag $mol_jsx_frag */
2476
2605
  var $;
2477
2606
  (function ($) {
2478
2607
  $mol_test({
@@ -2578,6 +2707,7 @@ var $;
2578
2707
  "use strict";
2579
2708
  var $;
2580
2709
  (function ($) {
2710
+ /** Lazy computed lists with native Array interface. $mol_range2_array is mutable but all derived ranges are immutable. */
2581
2711
  function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
2582
2712
  const source = typeof item === 'function' ? new $mol_range2_array() : item;
2583
2713
  if (typeof item !== 'function') {
@@ -2626,6 +2756,7 @@ var $;
2626
2756
  }
2627
2757
  $.$mol_range2 = $mol_range2;
2628
2758
  class $mol_range2_array extends Array {
2759
+ // Lazy
2629
2760
  concat(...tail) {
2630
2761
  if (tail.length === 0)
2631
2762
  return this;
@@ -2637,6 +2768,7 @@ var $;
2637
2768
  }
2638
2769
  return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
2639
2770
  }
2771
+ // Lazy
2640
2772
  filter(check, context) {
2641
2773
  const filtered = [];
2642
2774
  let cursor = -1;
@@ -2649,13 +2781,16 @@ var $;
2649
2781
  return filtered[index];
2650
2782
  }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
2651
2783
  }
2784
+ // Diligent
2652
2785
  forEach(proceed, context) {
2653
2786
  for (let [key, value] of this.entries())
2654
2787
  proceed.call(context, value, key, this);
2655
2788
  }
2789
+ // Lazy
2656
2790
  map(proceed, context) {
2657
2791
  return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
2658
2792
  }
2793
+ // Diligent
2659
2794
  reduce(merge, result) {
2660
2795
  let index = 0;
2661
2796
  if (arguments.length === 1) {
@@ -2666,12 +2801,15 @@ var $;
2666
2801
  }
2667
2802
  return result;
2668
2803
  }
2804
+ // Lazy
2669
2805
  toReversed() {
2670
2806
  return $mol_range2(index => this[this.length - 1 - index], () => this.length);
2671
2807
  }
2808
+ // Lazy
2672
2809
  slice(from = 0, to = this.length) {
2673
2810
  return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
2674
2811
  }
2812
+ // Lazy
2675
2813
  some(check, context) {
2676
2814
  for (let index = 0; index < this.length; ++index) {
2677
2815
  if (check.call(context, this[index], index, this))
@@ -2867,6 +3005,10 @@ var $;
2867
3005
  var $;
2868
3006
  (function ($) {
2869
3007
  $.$mol_compare_deep_cache = new WeakMap();
3008
+ /**
3009
+ * Deeply compares two values. Returns true if equal.
3010
+ * Define `Symbol.toPrimitive` to customize.
3011
+ */
2870
3012
  function $mol_compare_deep(left, right) {
2871
3013
  if (Object.is(left, right))
2872
3014
  return true;
@@ -3004,6 +3146,7 @@ var $;
3004
3146
 
3005
3147
  ;
3006
3148
  "use strict";
3149
+ /** @jsx $mol_jsx */
3007
3150
  var $;
3008
3151
  (function ($) {
3009
3152
  $mol_test({
@@ -3065,6 +3208,7 @@ var $;
3065
3208
  const obj3_copy = { test: 3, obj2: obj2_copy };
3066
3209
  obj1.obj3 = obj3;
3067
3210
  obj1_copy.obj3 = obj3_copy;
3211
+ // warmup cache
3068
3212
  $mol_assert_not($mol_compare_deep(obj1, {}));
3069
3213
  $mol_assert_not($mol_compare_deep(obj2, {}));
3070
3214
  $mol_assert_not($mol_compare_deep(obj3, {}));
@@ -3134,18 +3278,34 @@ var $;
3134
3278
  "use strict";
3135
3279
  var $;
3136
3280
  (function ($) {
3281
+ /**
3282
+ * Argument must be Truthy
3283
+ * @deprecated use $mol_assert_equal instead
3284
+ */
3137
3285
  function $mol_assert_ok(value) {
3138
3286
  if (value)
3139
3287
  return;
3140
3288
  $mol_fail(new Error(`${value} ≠ true`));
3141
3289
  }
3142
3290
  $.$mol_assert_ok = $mol_assert_ok;
3291
+ /**
3292
+ * Argument must be Falsy
3293
+ * @deprecated use $mol_assert_equal instead
3294
+ */
3143
3295
  function $mol_assert_not(value) {
3144
3296
  if (!value)
3145
3297
  return;
3146
3298
  $mol_fail(new Error(`${value} ≠ false`));
3147
3299
  }
3148
3300
  $.$mol_assert_not = $mol_assert_not;
3301
+ /**
3302
+ * Handler must throw an error.
3303
+ * @example
3304
+ * $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } ) // Passes because throws error
3305
+ * $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , 'Parse error' ) // Passes because throws right message
3306
+ * $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , Error ) // Passes because throws right class
3307
+ * @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
3308
+ */
3149
3309
  function $mol_assert_fail(handler, ErrorRight) {
3150
3310
  const fail = $.$mol_fail;
3151
3311
  try {
@@ -3168,10 +3328,18 @@ var $;
3168
3328
  $mol_fail(new Error('Not failed', { cause: { expect: ErrorRight } }));
3169
3329
  }
3170
3330
  $.$mol_assert_fail = $mol_assert_fail;
3331
+ /** @deprecated Use $mol_assert_equal */
3171
3332
  function $mol_assert_like(...args) {
3172
3333
  $mol_assert_equal(...args);
3173
3334
  }
3174
3335
  $.$mol_assert_like = $mol_assert_like;
3336
+ /**
3337
+ * All arguments must not be structural equal to each other.
3338
+ * @example
3339
+ * $mol_assert_unique( 1 , 2 , 3 ) // Passes
3340
+ * $mol_assert_unique( 1 , 1 , 2 ) // Fails because 1 === 1
3341
+ * @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
3342
+ */
3175
3343
  function $mol_assert_unique(...args) {
3176
3344
  for (let i = 0; i < args.length; ++i) {
3177
3345
  for (let j = 0; j < args.length; ++j) {
@@ -3184,6 +3352,13 @@ var $;
3184
3352
  }
3185
3353
  }
3186
3354
  $.$mol_assert_unique = $mol_assert_unique;
3355
+ /**
3356
+ * All arguments must be structural equal each other.
3357
+ * @example
3358
+ * $mol_assert_like( [1] , [1] , [1] ) // Passes
3359
+ * $mol_assert_like( [1] , [1] , [2] ) // Fails because 1 !== 2
3360
+ * @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
3361
+ */
3187
3362
  function $mol_assert_equal(...args) {
3188
3363
  for (let i = 1; i < args.length; ++i) {
3189
3364
  if ($mol_compare_deep(args[0], args[i]))
@@ -3237,6 +3412,11 @@ var $;
3237
3412
  var $;
3238
3413
  (function ($) {
3239
3414
  const instances = new WeakSet();
3415
+ /**
3416
+ * Proxy that delegates all to lazy returned target.
3417
+ *
3418
+ * $mol_delegate( Array.prototype , ()=> fetch_array() )
3419
+ */
3240
3420
  function $mol_delegate(proto, target) {
3241
3421
  const proxy = new Proxy(proto, {
3242
3422
  get: (_, field) => {
@@ -3336,6 +3516,7 @@ var $;
3336
3516
  "use strict";
3337
3517
  var $;
3338
3518
  (function ($) {
3519
+ /** Position in any resource. */
3339
3520
  class $mol_span extends $mol_object2 {
3340
3521
  uri;
3341
3522
  source;
@@ -3351,13 +3532,17 @@ var $;
3351
3532
  this.length = length;
3352
3533
  this[Symbol.toStringTag] = this.uri + ('#' + this.row + ':' + this.col + '/' + this.length);
3353
3534
  }
3535
+ /** Span for begin of unknown resource */
3354
3536
  static unknown = $mol_span.begin('?');
3537
+ /** Makes new span for begin of resource. */
3355
3538
  static begin(uri, source = '') {
3356
3539
  return new $mol_span(uri, source, 1, 1, 0);
3357
3540
  }
3541
+ /** Makes new span for end of resource. */
3358
3542
  static end(uri, source) {
3359
3543
  return new $mol_span(uri, source, 1, source.length + 1, 0);
3360
3544
  }
3545
+ /** Makes new span for entire resource. */
3361
3546
  static entire(uri, source) {
3362
3547
  return new $mol_span(uri, source, 1, 1, source.length);
3363
3548
  }
@@ -3372,15 +3557,19 @@ var $;
3372
3557
  length: this.length
3373
3558
  };
3374
3559
  }
3560
+ /** Makes new error for this span. */
3375
3561
  error(message, Class = Error) {
3376
3562
  return new Class(`${message} (${this})`);
3377
3563
  }
3564
+ /** Makes new span for same uri. */
3378
3565
  span(row, col, length) {
3379
3566
  return new $mol_span(this.uri, this.source, row, col, length);
3380
3567
  }
3568
+ /** Makes new span after end of this. */
3381
3569
  after(length = 0) {
3382
3570
  return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
3383
3571
  }
3572
+ /** Makes new span between begin and end. */
3384
3573
  slice(begin, end = -1) {
3385
3574
  let len = this.length;
3386
3575
  if (begin < 0)
@@ -3455,6 +3644,7 @@ var $;
3455
3644
  "use strict";
3456
3645
  var $;
3457
3646
  (function ($) {
3647
+ /** Serializes tree to string in tree format. */
3458
3648
  function $mol_tree2_to_string(tree) {
3459
3649
  let output = [];
3460
3650
  function dump(tree, prefix = '') {
@@ -3514,12 +3704,25 @@ var $;
3514
3704
  "use strict";
3515
3705
  var $;
3516
3706
  (function ($) {
3707
+ /**
3708
+ * Abstract Syntax Tree with human readable serialization.
3709
+ * Avoid direct instantiation. Use static factories instead.
3710
+ * @see https://github.com/nin-jin/tree.d
3711
+ */
3517
3712
  class $mol_tree2 extends Object {
3518
3713
  type;
3519
3714
  value;
3520
3715
  kids;
3521
3716
  span;
3522
- constructor(type, value, kids, span) {
3717
+ constructor(
3718
+ /** Type of structural node, `value` should be empty */
3719
+ type,
3720
+ /** Content of data node, `type` should be empty */
3721
+ value,
3722
+ /** Child nodes */
3723
+ kids,
3724
+ /** Position in most far source resource */
3725
+ span) {
3523
3726
  super();
3524
3727
  this.type = type;
3525
3728
  this.value = value;
@@ -3527,12 +3730,15 @@ var $;
3527
3730
  this.span = span;
3528
3731
  this[Symbol.toStringTag] = type || '\\' + value;
3529
3732
  }
3733
+ /** Makes collection node. */
3530
3734
  static list(kids, span = $mol_span.unknown) {
3531
3735
  return new $mol_tree2('', '', kids, span);
3532
3736
  }
3737
+ /** Makes new derived collection node. */
3533
3738
  list(kids) {
3534
3739
  return $mol_tree2.list(kids, this.span);
3535
3740
  }
3741
+ /** Makes data node for any string. */
3536
3742
  static data(value, kids = [], span = $mol_span.unknown) {
3537
3743
  const chunks = value.split('\n');
3538
3744
  if (chunks.length > 1) {
@@ -3546,21 +3752,26 @@ var $;
3546
3752
  }
3547
3753
  return new $mol_tree2('', value, kids, span);
3548
3754
  }
3755
+ /** Makes new derived data node. */
3549
3756
  data(value, kids = []) {
3550
3757
  return $mol_tree2.data(value, kids, this.span);
3551
3758
  }
3759
+ /** Makes struct node. */
3552
3760
  static struct(type, kids = [], span = $mol_span.unknown) {
3553
3761
  if (/[ \n\t\\]/.test(type)) {
3554
3762
  $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
3555
3763
  }
3556
3764
  return new $mol_tree2(type, '', kids, span);
3557
3765
  }
3766
+ /** Makes new derived structural node. */
3558
3767
  struct(type, kids = []) {
3559
3768
  return $mol_tree2.struct(type, kids, this.span);
3560
3769
  }
3770
+ /** Makes new derived node with different kids id defined. */
3561
3771
  clone(kids, span = this.span) {
3562
3772
  return new $mol_tree2(this.type, this.value, kids, span);
3563
3773
  }
3774
+ /** Returns multiline text content. */
3564
3775
  text() {
3565
3776
  var values = [];
3566
3777
  for (var kid of this.kids) {
@@ -3570,15 +3781,20 @@ var $;
3570
3781
  }
3571
3782
  return this.value + values.join('\n');
3572
3783
  }
3784
+ /** Parses tree format. */
3785
+ /** @deprecated Use $mol_tree2_from_string */
3573
3786
  static fromString(str, uri = 'unknown') {
3574
3787
  return $$.$mol_tree2_from_string(str, uri);
3575
3788
  }
3789
+ /** Serializes to tree format. */
3576
3790
  toString() {
3577
3791
  return $$.$mol_tree2_to_string(this);
3578
3792
  }
3793
+ /** Makes new tree with node overrided by path. */
3579
3794
  insert(value, ...path) {
3580
3795
  return this.update($mol_maybe(value), ...path)[0];
3581
3796
  }
3797
+ /** Makes new tree with node overrided by path. */
3582
3798
  update(value, ...path) {
3583
3799
  if (path.length === 0)
3584
3800
  return value;
@@ -3611,6 +3827,7 @@ var $;
3611
3827
  return [this.clone(kids)];
3612
3828
  }
3613
3829
  }
3830
+ /** Query nodes by path. */
3614
3831
  select(...path) {
3615
3832
  let next = [this];
3616
3833
  for (const type of path) {
@@ -3637,6 +3854,7 @@ var $;
3637
3854
  }
3638
3855
  return this.list(next);
3639
3856
  }
3857
+ /** Filter kids by path or value. */
3640
3858
  filter(path, value) {
3641
3859
  const sub = this.kids.filter(item => {
3642
3860
  var found = item.select(...path);
@@ -3664,9 +3882,11 @@ var $;
3664
3882
  $mol_fail_hidden(error);
3665
3883
  }
3666
3884
  }
3885
+ /** Transform tree through context with transformers */
3667
3886
  hack(belt, context = {}) {
3668
3887
  return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
3669
3888
  }
3889
+ /** Makes Error with node coordinates. */
3670
3890
  error(message, Class = Error) {
3671
3891
  return this.span.error(`${message}\n${this.clone([])}`, Class);
3672
3892
  }
@@ -3822,6 +4042,7 @@ var $;
3822
4042
  "use strict";
3823
4043
  var $;
3824
4044
  (function ($) {
4045
+ /** Syntax error with cordinates and source line snippet. */
3825
4046
  class $mol_error_syntax extends SyntaxError {
3826
4047
  reason;
3827
4048
  line;
@@ -3840,6 +4061,7 @@ var $;
3840
4061
  "use strict";
3841
4062
  var $;
3842
4063
  (function ($) {
4064
+ /** Parses tree format from string. */
3843
4065
  function $mol_tree2_from_string(str, uri = '?') {
3844
4066
  const span = $mol_span.entire(uri, str);
3845
4067
  var root = $mol_tree2.list([], span);
@@ -3849,6 +4071,7 @@ var $;
3849
4071
  var indent = 0;
3850
4072
  var line_start = pos;
3851
4073
  row++;
4074
+ // read indent
3852
4075
  while (str.length > pos && str[pos] == '\t') {
3853
4076
  indent++;
3854
4077
  pos++;
@@ -3857,8 +4080,10 @@ var $;
3857
4080
  min_indent = indent;
3858
4081
  }
3859
4082
  indent -= min_indent;
4083
+ // invalid tab size
3860
4084
  if (indent < 0 || indent >= stack.length) {
3861
4085
  const sp = span.span(row, 1, pos - line_start);
4086
+ // skip error line
3862
4087
  while (str.length > pos && str[pos] != '\n') {
3863
4088
  pos++;
3864
4089
  }
@@ -3873,7 +4098,9 @@ var $;
3873
4098
  }
3874
4099
  stack.length = indent + 1;
3875
4100
  var parent = stack[indent];
4101
+ // parse types
3876
4102
  while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
4103
+ // type can not contain space and tab
3877
4104
  var error_start = pos;
3878
4105
  while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
3879
4106
  pos++;
@@ -3885,6 +4112,7 @@ var $;
3885
4112
  const sp = span.span(row, error_start - line_start + 1, pos - error_start);
3886
4113
  this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
3887
4114
  }
4115
+ // read type
3888
4116
  var type_start = pos;
3889
4117
  while (str.length > pos &&
3890
4118
  str[pos] != '\\' &&
@@ -3899,10 +4127,12 @@ var $;
3899
4127
  parent_kids.push(next);
3900
4128
  parent = next;
3901
4129
  }
4130
+ // read one space if exists
3902
4131
  if (str.length > pos && str[pos] == ' ') {
3903
4132
  pos++;
3904
4133
  }
3905
4134
  }
4135
+ // read data
3906
4136
  if (str.length > pos && str[pos] == '\\') {
3907
4137
  var data_start = pos;
3908
4138
  while (str.length > pos && str[pos] != '\n') {
@@ -3913,6 +4143,7 @@ var $;
3913
4143
  parent_kids.push(next);
3914
4144
  parent = next;
3915
4145
  }
4146
+ // now must be end of text
3916
4147
  if (str.length === pos && stack.length > 0) {
3917
4148
  const sp = span.span(row, pos - line_start + 1, 1);
3918
4149
  this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
@@ -4105,6 +4336,12 @@ var $;
4105
4336
  'return result without errors'() {
4106
4337
  $mol_assert_equal($mol_try(() => false), false);
4107
4338
  },
4339
+ //'return error if thrown'() {
4340
+ //
4341
+ // const error = new Error( '$mol_try test error' )
4342
+ // $mol_assert_equal( $mol_try( ()=> { throw error } ) , error )
4343
+ //
4344
+ //} ,
4108
4345
  });
4109
4346
  })($ || ($ = {}));
4110
4347