mol_wire_dom 0.0.1721 → 0.0.1723

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.js CHANGED
@@ -32,6 +32,7 @@ $.$$ = $
32
32
  "use strict";
33
33
  var $;
34
34
  (function ($) {
35
+ /** Generates unique identifier. */
35
36
  function $mol_guid(length = 8, exists = () => false) {
36
37
  for (;;) {
37
38
  let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
@@ -57,11 +58,16 @@ var $;
57
58
  "use strict";
58
59
  var $;
59
60
  (function ($) {
61
+ /** Special status statuses. */
60
62
  let $mol_wire_cursor;
61
63
  (function ($mol_wire_cursor) {
64
+ /** Update required. */
62
65
  $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
66
+ /** Some of (transitive) pub update required. */
63
67
  $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
68
+ /** Actual state but may be dropped. */
64
69
  $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
70
+ /** State will never be changed. */
65
71
  $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
66
72
  })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
67
73
  })($ || ($ = {}));
@@ -70,6 +76,9 @@ var $;
70
76
  "use strict";
71
77
  var $;
72
78
  (function ($) {
79
+ /**
80
+ * Collects subscribers in compact array. 28B
81
+ */
73
82
  class $mol_wire_pub extends Object {
74
83
  constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
75
84
  super();
@@ -77,10 +86,17 @@ var $;
77
86
  }
78
87
  [Symbol.toStringTag];
79
88
  data = [];
89
+ // Derived objects should be Arrays.
80
90
  static get [Symbol.species]() {
81
91
  return Array;
82
92
  }
83
- sub_from = 0;
93
+ /**
94
+ * Index of first subscriber.
95
+ */
96
+ sub_from = 0; // 4B
97
+ /**
98
+ * All current subscribers.
99
+ */
84
100
  get sub_list() {
85
101
  const res = [];
86
102
  for (let i = this.sub_from; i < this.data.length; i += 2) {
@@ -88,14 +104,23 @@ var $;
88
104
  }
89
105
  return res;
90
106
  }
107
+ /**
108
+ * Has any subscribers or not.
109
+ */
91
110
  get sub_empty() {
92
111
  return this.sub_from === this.data.length;
93
112
  }
113
+ /**
114
+ * Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.
115
+ */
94
116
  sub_on(sub, pub_pos) {
95
117
  const pos = this.data.length;
96
118
  this.data.push(sub, pub_pos);
97
119
  return pos;
98
120
  }
121
+ /**
122
+ * Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.
123
+ */
99
124
  sub_off(sub_pos) {
100
125
  if (!(sub_pos < this.data.length)) {
101
126
  $mol_fail(new Error(`Wrong pos ${sub_pos}`));
@@ -108,21 +133,39 @@ var $;
108
133
  if (end === this.sub_from)
109
134
  this.reap();
110
135
  }
136
+ /**
137
+ * Called when last sub was unsubscribed.
138
+ **/
111
139
  reap() { }
140
+ /**
141
+ * Autowire this publisher with current subscriber.
142
+ **/
112
143
  promote() {
113
144
  $mol_wire_auto()?.track_next(this);
114
145
  }
146
+ /**
147
+ * Enforce actualization. Should not throw errors.
148
+ */
115
149
  fresh() { }
150
+ /**
151
+ * Allow to put data to caches in the subtree.
152
+ */
116
153
  complete() { }
117
154
  get incompleted() {
118
155
  return false;
119
156
  }
157
+ /**
158
+ * Notify subscribers about self changes.
159
+ */
120
160
  emit(quant = $mol_wire_cursor.stale) {
121
161
  for (let i = this.sub_from; i < this.data.length; i += 2) {
122
162
  ;
123
163
  this.data[i].absorb(quant, this.data[i + 1]);
124
164
  }
125
165
  }
166
+ /**
167
+ * Moves peer from one position to another. Doesn't clear data at old position!
168
+ */
126
169
  peer_move(from_pos, to_pos) {
127
170
  const peer = this.data[from_pos];
128
171
  const self_pos = this.data[from_pos + 1];
@@ -130,6 +173,9 @@ var $;
130
173
  this.data[to_pos + 1] = self_pos;
131
174
  peer.peer_repos(self_pos, to_pos);
132
175
  }
176
+ /**
177
+ * Updates self position in the peer.
178
+ */
133
179
  peer_repos(peer_pos, self_pos) {
134
180
  this.data[peer_pos + 1] = self_pos;
135
181
  }
@@ -145,10 +191,16 @@ var $;
145
191
  var $;
146
192
  (function ($) {
147
193
  $.$mol_wire_auto_sub = null;
194
+ /**
195
+ * When fulfilled, all publishers are promoted to this subscriber on access to its.
196
+ */
148
197
  function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
149
198
  return $.$mol_wire_auto_sub = next;
150
199
  }
151
200
  $.$mol_wire_auto = $mol_wire_auto;
201
+ /**
202
+ * Affection queue. Used to prevent accidental stack overflow on emit.
203
+ */
152
204
  $.$mol_wire_affected = [];
153
205
  })($ || ($ = {}));
154
206
 
@@ -157,7 +209,7 @@ var $;
157
209
  var $;
158
210
  (function ($) {
159
211
  function $mol_fail_hidden(error) {
160
- throw error;
212
+ throw error; /// Use 'Never Pause Here' breakpoint in DevTools or simply blackbox this script
161
213
  }
162
214
  $.$mol_fail_hidden = $mol_fail_hidden;
163
215
  })($ || ($ = {}));
@@ -166,6 +218,7 @@ var $;
166
218
  "use strict";
167
219
  var $;
168
220
  (function ($) {
221
+ // https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview#
169
222
  $['devtoolsFormatters'] ||= [];
170
223
  function $mol_dev_format_register(config) {
171
224
  $['devtoolsFormatters'].push(config);
@@ -217,6 +270,7 @@ var $;
217
270
  return false;
218
271
  if (!val)
219
272
  return false;
273
+ // if( Error.isError( val ) ) true
220
274
  if (val[$.$mol_dev_format_body])
221
275
  return true;
222
276
  return false;
@@ -234,12 +288,16 @@ var $;
234
288
  return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
235
289
  }
236
290
  }
291
+ // if( Error.isError( val ) ) {
292
+ // return $mol_dev_format_native( val )
293
+ // }
237
294
  return null;
238
295
  },
239
296
  });
240
297
  function $mol_dev_format_native(obj) {
241
298
  if (typeof obj === 'undefined')
242
299
  return $.$mol_dev_format_shade('undefined');
300
+ // if( ![ 'object', 'function', 'symbol' ].includes( typeof obj ) ) return obj
243
301
  return [
244
302
  'object',
245
303
  {
@@ -297,6 +355,9 @@ var $;
297
355
  'margin-left': '13px'
298
356
  });
299
357
  class Stack extends Array {
358
+ // [ Symbol.toPrimitive ]() {
359
+ // return this.toString()
360
+ // }
300
361
  toString() {
301
362
  return this.join('\n');
302
363
  }
@@ -319,6 +380,7 @@ var $;
319
380
  this.method = call.getMethodName() ?? '';
320
381
  if (this.method === this.function)
321
382
  this.method = '';
383
+ // const func = c.getFunction()
322
384
  this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
323
385
  this.eval = call.getEvalOrigin() ?? '';
324
386
  this.source = call.getScriptNameOrSourceURL() ?? '';
@@ -365,9 +427,16 @@ var $;
365
427
  "use strict";
366
428
  var $;
367
429
  (function ($) {
430
+ /**
431
+ * Publisher that can auto collect other publishers. 32B
432
+ *
433
+ * P1 P2 P3 P4 S1 S2 S3
434
+ * ^ ^
435
+ * pubs_from subs_from
436
+ */
368
437
  class $mol_wire_pub_sub extends $mol_wire_pub {
369
- pub_from = 0;
370
- cursor = $mol_wire_cursor.stale;
438
+ pub_from = 0; // 4B
439
+ cursor = $mol_wire_cursor.stale; // 4B
371
440
  get temp() {
372
441
  return false;
373
442
  }
@@ -485,10 +554,27 @@ var $;
485
554
  return;
486
555
  this.cursor = quant;
487
556
  this.emit($mol_wire_cursor.doubt);
557
+ // if( pos >= 0 && pos < this.sub_from - 2 ) {
558
+ // const pub = this.data[ pos ] as $mol_wire_pub
559
+ // if( pub instanceof $mol_wire_task ) return
560
+ // for(
561
+ // let cursor = this.pub_from;
562
+ // cursor < this.sub_from;
563
+ // cursor += 2
564
+ // ) {
565
+ // const pub = this.data[ cursor ] as $mol_wire_pub
566
+ // if( pub instanceof $mol_wire_task ) {
567
+ // pub.destructor()
568
+ // }
569
+ // }
570
+ // }
488
571
  }
489
572
  [$mol_dev_format_head]() {
490
573
  return $mol_dev_format_native(this);
491
574
  }
575
+ /**
576
+ * Is subscribed to any publisher or not.
577
+ */
492
578
  get pub_empty() {
493
579
  return this.sub_from === this.pub_from;
494
580
  }
@@ -512,6 +598,11 @@ var $;
512
598
  var $;
513
599
  (function ($) {
514
600
  const instances = new WeakSet();
601
+ /**
602
+ * Proxy that delegates all to lazy returned target.
603
+ *
604
+ * $mol_delegate( Array.prototype , ()=> fetch_array() )
605
+ */
515
606
  function $mol_delegate(proto, target) {
516
607
  const proxy = new Proxy(proto, {
517
608
  get: (_, field) => {
@@ -687,6 +778,9 @@ var $;
687
778
  [Symbol.dispose]() {
688
779
  this.destructor();
689
780
  }
781
+ //[ Symbol.toPrimitive ]( hint: string ) {
782
+ // return hint === 'number' ? this.valueOf() : this.toString()
783
+ //}
690
784
  toString() {
691
785
  return this[Symbol.toStringTag] || this.constructor.name + '<>';
692
786
  }
@@ -742,6 +836,13 @@ var $;
742
836
  var $;
743
837
  (function ($) {
744
838
  const wrappers = new WeakMap();
839
+ /**
840
+ * Suspendable task with support both sync/async api.
841
+ *
842
+ * A1 A2 A3 A4 P1 P2 P3 P4 S1 S2 S3
843
+ * ^ ^ ^
844
+ * args_from pubs_from subs_from
845
+ **/
745
846
  class $mol_wire_fiber extends $mol_wire_pub_sub {
746
847
  task;
747
848
  host;
@@ -762,6 +863,7 @@ var $;
762
863
  });
763
864
  }
764
865
  static sync() {
866
+ // Sync whole fiber graph
765
867
  while (this.planning.size) {
766
868
  for (const fiber of this.planning) {
767
869
  this.planning.delete(fiber);
@@ -772,6 +874,7 @@ var $;
772
874
  fiber.fresh();
773
875
  }
774
876
  }
877
+ // Collect garbage
775
878
  while (this.reaping.size) {
776
879
  const fibers = this.reaping;
777
880
  this.reaping = new Set;
@@ -923,6 +1026,10 @@ var $;
923
1026
  this.cursor = $mol_wire_cursor.stale;
924
1027
  this.fresh();
925
1028
  }
1029
+ /**
1030
+ * Synchronous execution. Throws Promise when waits async task (SuspenseAPI provider).
1031
+ * Should be called inside SuspenseAPI consumer (ie fiber).
1032
+ */
926
1033
  sync() {
927
1034
  if (!$mol_wire_fiber.warm) {
928
1035
  return this.result();
@@ -937,6 +1044,10 @@ var $;
937
1044
  }
938
1045
  return this.cache;
939
1046
  }
1047
+ /**
1048
+ * Asynchronous execution.
1049
+ * It's SuspenseAPI consumer. So SuspenseAPI providers can be called inside.
1050
+ */
940
1051
  async async_raw() {
941
1052
  while (true) {
942
1053
  this.fresh();
@@ -949,6 +1060,7 @@ var $;
949
1060
  if (!$mol_promise_like(this.cache))
950
1061
  return this.cache;
951
1062
  if (this.cursor === $mol_wire_cursor.final) {
1063
+ // never ends on destructed fiber
952
1064
  await new Promise(() => { });
953
1065
  }
954
1066
  }
@@ -996,6 +1108,7 @@ var $;
996
1108
  var $;
997
1109
  (function ($) {
998
1110
  const TypedArray = Object.getPrototypeOf(Uint8Array);
1111
+ /** Returns string key for any value. */
999
1112
  function $mol_key(value) {
1000
1113
  primitives: {
1001
1114
  if (typeof value === 'bigint')
@@ -1003,9 +1116,9 @@ var $;
1003
1116
  if (typeof value === 'symbol')
1004
1117
  return `Symbol(${value.description})`;
1005
1118
  if (!value)
1006
- return JSON.stringify(value);
1119
+ return JSON.stringify(value); // 0, null, ""
1007
1120
  if (typeof value !== 'object' && typeof value !== 'function')
1008
- return JSON.stringify(value);
1121
+ return JSON.stringify(value); // boolean, number, string
1009
1122
  }
1010
1123
  caching: {
1011
1124
  let key = $mol_key_store.get(value);
@@ -1083,6 +1196,10 @@ var $;
1083
1196
  var $;
1084
1197
  (function ($) {
1085
1198
  $.$mol_compare_deep_cache = new WeakMap();
1199
+ /**
1200
+ * Deeply compares two values. Returns true if equal.
1201
+ * Define `Symbol.toPrimitive` to customize.
1202
+ */
1086
1203
  function $mol_compare_deep(left, right) {
1087
1204
  if (Object.is(left, right))
1088
1205
  return true;
@@ -1222,6 +1339,7 @@ var $;
1222
1339
  "use strict";
1223
1340
  var $;
1224
1341
  (function ($) {
1342
+ /** Log begin of collapsed group only when some logged inside, returns func to close group */
1225
1343
  function $mol_log3_area_lazy(event) {
1226
1344
  const self = this.$;
1227
1345
  const stack = self.$mol_log3_stack;
@@ -1246,6 +1364,7 @@ var $;
1246
1364
  "use strict";
1247
1365
  var $;
1248
1366
  (function ($) {
1367
+ /** Position in any resource. */
1249
1368
  class $mol_span extends $mol_object2 {
1250
1369
  uri;
1251
1370
  source;
@@ -1261,13 +1380,17 @@ var $;
1261
1380
  this.length = length;
1262
1381
  this[Symbol.toStringTag] = this.uri + ('#' + this.row + ':' + this.col + '/' + this.length);
1263
1382
  }
1383
+ /** Span for begin of unknown resource */
1264
1384
  static unknown = $mol_span.begin('?');
1385
+ /** Makes new span for begin of resource. */
1265
1386
  static begin(uri, source = '') {
1266
1387
  return new $mol_span(uri, source, 1, 1, 0);
1267
1388
  }
1389
+ /** Makes new span for end of resource. */
1268
1390
  static end(uri, source) {
1269
1391
  return new $mol_span(uri, source, 1, source.length + 1, 0);
1270
1392
  }
1393
+ /** Makes new span for entire resource. */
1271
1394
  static entire(uri, source) {
1272
1395
  return new $mol_span(uri, source, 1, 1, source.length);
1273
1396
  }
@@ -1282,15 +1405,19 @@ var $;
1282
1405
  length: this.length
1283
1406
  };
1284
1407
  }
1408
+ /** Makes new error for this span. */
1285
1409
  error(message, Class = Error) {
1286
1410
  return new Class(`${message} (${this})`);
1287
1411
  }
1412
+ /** Makes new span for same uri. */
1288
1413
  span(row, col, length) {
1289
1414
  return new $mol_span(this.uri, this.source, row, col, length);
1290
1415
  }
1416
+ /** Makes new span after end of this. */
1291
1417
  after(length = 0) {
1292
1418
  return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
1293
1419
  }
1420
+ /** Makes new span between begin and end. */
1294
1421
  slice(begin, end = -1) {
1295
1422
  let len = this.length;
1296
1423
  if (begin < 0)
@@ -1313,6 +1440,7 @@ var $;
1313
1440
  "use strict";
1314
1441
  var $;
1315
1442
  (function ($) {
1443
+ /** Serializes tree to string in tree format. */
1316
1444
  function $mol_tree2_to_string(tree) {
1317
1445
  let output = [];
1318
1446
  function dump(tree, prefix = '') {
@@ -1356,12 +1484,25 @@ var $;
1356
1484
  "use strict";
1357
1485
  var $;
1358
1486
  (function ($) {
1487
+ /**
1488
+ * Abstract Syntax Tree with human readable serialization.
1489
+ * Avoid direct instantiation. Use static factories instead.
1490
+ * @see https://github.com/nin-jin/tree.d
1491
+ */
1359
1492
  class $mol_tree2 extends Object {
1360
1493
  type;
1361
1494
  value;
1362
1495
  kids;
1363
1496
  span;
1364
- constructor(type, value, kids, span) {
1497
+ constructor(
1498
+ /** Type of structural node, `value` should be empty */
1499
+ type,
1500
+ /** Content of data node, `type` should be empty */
1501
+ value,
1502
+ /** Child nodes */
1503
+ kids,
1504
+ /** Position in most far source resource */
1505
+ span) {
1365
1506
  super();
1366
1507
  this.type = type;
1367
1508
  this.value = value;
@@ -1369,12 +1510,15 @@ var $;
1369
1510
  this.span = span;
1370
1511
  this[Symbol.toStringTag] = type || '\\' + value;
1371
1512
  }
1513
+ /** Makes collection node. */
1372
1514
  static list(kids, span = $mol_span.unknown) {
1373
1515
  return new $mol_tree2('', '', kids, span);
1374
1516
  }
1517
+ /** Makes new derived collection node. */
1375
1518
  list(kids) {
1376
1519
  return $mol_tree2.list(kids, this.span);
1377
1520
  }
1521
+ /** Makes data node for any string. */
1378
1522
  static data(value, kids = [], span = $mol_span.unknown) {
1379
1523
  const chunks = value.split('\n');
1380
1524
  if (chunks.length > 1) {
@@ -1388,21 +1532,26 @@ var $;
1388
1532
  }
1389
1533
  return new $mol_tree2('', value, kids, span);
1390
1534
  }
1535
+ /** Makes new derived data node. */
1391
1536
  data(value, kids = []) {
1392
1537
  return $mol_tree2.data(value, kids, this.span);
1393
1538
  }
1539
+ /** Makes struct node. */
1394
1540
  static struct(type, kids = [], span = $mol_span.unknown) {
1395
1541
  if (/[ \n\t\\]/.test(type)) {
1396
1542
  $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
1397
1543
  }
1398
1544
  return new $mol_tree2(type, '', kids, span);
1399
1545
  }
1546
+ /** Makes new derived structural node. */
1400
1547
  struct(type, kids = []) {
1401
1548
  return $mol_tree2.struct(type, kids, this.span);
1402
1549
  }
1550
+ /** Makes new derived node with different kids id defined. */
1403
1551
  clone(kids, span = this.span) {
1404
1552
  return new $mol_tree2(this.type, this.value, kids, span);
1405
1553
  }
1554
+ /** Returns multiline text content. */
1406
1555
  text() {
1407
1556
  var values = [];
1408
1557
  for (var kid of this.kids) {
@@ -1412,15 +1561,20 @@ var $;
1412
1561
  }
1413
1562
  return this.value + values.join('\n');
1414
1563
  }
1564
+ /** Parses tree format. */
1565
+ /** @deprecated Use $mol_tree2_from_string */
1415
1566
  static fromString(str, uri = 'unknown') {
1416
1567
  return $$.$mol_tree2_from_string(str, uri);
1417
1568
  }
1569
+ /** Serializes to tree format. */
1418
1570
  toString() {
1419
1571
  return $$.$mol_tree2_to_string(this);
1420
1572
  }
1573
+ /** Makes new tree with node overrided by path. */
1421
1574
  insert(value, ...path) {
1422
1575
  return this.update($mol_maybe(value), ...path)[0];
1423
1576
  }
1577
+ /** Makes new tree with node overrided by path. */
1424
1578
  update(value, ...path) {
1425
1579
  if (path.length === 0)
1426
1580
  return value;
@@ -1453,6 +1607,7 @@ var $;
1453
1607
  return [this.clone(kids)];
1454
1608
  }
1455
1609
  }
1610
+ /** Query nodes by path. */
1456
1611
  select(...path) {
1457
1612
  let next = [this];
1458
1613
  for (const type of path) {
@@ -1479,6 +1634,7 @@ var $;
1479
1634
  }
1480
1635
  return this.list(next);
1481
1636
  }
1637
+ /** Filter kids by path or value. */
1482
1638
  filter(path, value) {
1483
1639
  const sub = this.kids.filter(item => {
1484
1640
  var found = item.select(...path);
@@ -1506,9 +1662,11 @@ var $;
1506
1662
  $mol_fail_hidden(error);
1507
1663
  }
1508
1664
  }
1665
+ /** Transform tree through context with transformers */
1509
1666
  hack(belt, context = {}) {
1510
1667
  return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
1511
1668
  }
1669
+ /** Makes Error with node coordinates. */
1512
1670
  error(message, Class = Error) {
1513
1671
  return this.span.error(`${message}\n${this.clone([])}`, Class);
1514
1672
  }
@@ -1526,6 +1684,7 @@ var $;
1526
1684
  "use strict";
1527
1685
  var $;
1528
1686
  (function ($) {
1687
+ /** Syntax error with cordinates and source line snippet. */
1529
1688
  class $mol_error_syntax extends SyntaxError {
1530
1689
  reason;
1531
1690
  line;
@@ -1544,6 +1703,7 @@ var $;
1544
1703
  "use strict";
1545
1704
  var $;
1546
1705
  (function ($) {
1706
+ /** Parses tree format from string. */
1547
1707
  function $mol_tree2_from_string(str, uri = '?') {
1548
1708
  const span = $mol_span.entire(uri, str);
1549
1709
  var root = $mol_tree2.list([], span);
@@ -1553,6 +1713,7 @@ var $;
1553
1713
  var indent = 0;
1554
1714
  var line_start = pos;
1555
1715
  row++;
1716
+ // read indent
1556
1717
  while (str.length > pos && str[pos] == '\t') {
1557
1718
  indent++;
1558
1719
  pos++;
@@ -1561,8 +1722,10 @@ var $;
1561
1722
  min_indent = indent;
1562
1723
  }
1563
1724
  indent -= min_indent;
1725
+ // invalid tab size
1564
1726
  if (indent < 0 || indent >= stack.length) {
1565
1727
  const sp = span.span(row, 1, pos - line_start);
1728
+ // skip error line
1566
1729
  while (str.length > pos && str[pos] != '\n') {
1567
1730
  pos++;
1568
1731
  }
@@ -1577,7 +1740,9 @@ var $;
1577
1740
  }
1578
1741
  stack.length = indent + 1;
1579
1742
  var parent = stack[indent];
1743
+ // parse types
1580
1744
  while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
1745
+ // type can not contain space and tab
1581
1746
  var error_start = pos;
1582
1747
  while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
1583
1748
  pos++;
@@ -1589,6 +1754,7 @@ var $;
1589
1754
  const sp = span.span(row, error_start - line_start + 1, pos - error_start);
1590
1755
  this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
1591
1756
  }
1757
+ // read type
1592
1758
  var type_start = pos;
1593
1759
  while (str.length > pos &&
1594
1760
  str[pos] != '\\' &&
@@ -1603,10 +1769,12 @@ var $;
1603
1769
  parent_kids.push(next);
1604
1770
  parent = next;
1605
1771
  }
1772
+ // read one space if exists
1606
1773
  if (str.length > pos && str[pos] == ' ') {
1607
1774
  pos++;
1608
1775
  }
1609
1776
  }
1777
+ // read data
1610
1778
  if (str.length > pos && str[pos] == '\\') {
1611
1779
  var data_start = pos;
1612
1780
  while (str.length > pos && str[pos] != '\n') {
@@ -1617,6 +1785,7 @@ var $;
1617
1785
  parent_kids.push(next);
1618
1786
  parent = next;
1619
1787
  }
1788
+ // now must be end of text
1620
1789
  if (str.length === pos && stack.length > 0) {
1621
1790
  const sp = span.span(row, pos - line_start + 1, 1);
1622
1791
  this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
@@ -1709,6 +1878,7 @@ var $;
1709
1878
  "use strict";
1710
1879
  var $;
1711
1880
  (function ($) {
1881
+ /** Module for working with terminal. Text coloring when output in terminal */
1712
1882
  class $mol_term_color {
1713
1883
  static reset = this.ansi(0, 0);
1714
1884
  static bold = this.ansi(1, 22);
@@ -1780,6 +1950,7 @@ var $;
1780
1950
  "use strict";
1781
1951
  var $;
1782
1952
  (function ($) {
1953
+ /** One-shot fiber */
1783
1954
  class $mol_wire_task extends $mol_wire_fiber {
1784
1955
  static getter(task) {
1785
1956
  return function $mol_wire_task_get(host, args) {
@@ -1805,6 +1976,7 @@ var $;
1805
1976
  }
1806
1977
  const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
1807
1978
  const next = new $mol_wire_task(key, task, host, args);
1979
+ // Disabled because non-idempotency is required for try-catch
1808
1980
  if (existen?.temp) {
1809
1981
  $$.$mol_log3_warn({
1810
1982
  place: '$mol_wire_task',
@@ -1837,7 +2009,7 @@ var $;
1837
2009
  try {
1838
2010
  next[Symbol.toStringTag] = this[Symbol.toStringTag];
1839
2011
  }
1840
- catch {
2012
+ catch { // Promises throw in strict mode
1841
2013
  Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
1842
2014
  }
1843
2015
  }
@@ -1862,6 +2034,9 @@ var $;
1862
2034
  "use strict";
1863
2035
  var $;
1864
2036
  (function ($) {
2037
+ /**
2038
+ * Decorates method to fiber to ensure it is executed only once inside other fiber.
2039
+ */
1865
2040
  function $mol_wire_method(host, field, descr) {
1866
2041
  if (!descr)
1867
2042
  descr = Reflect.getOwnPropertyDescriptor(host, field);
@@ -1943,6 +2118,7 @@ var $;
1943
2118
  "use strict";
1944
2119
  var $;
1945
2120
  (function ($) {
2121
+ /** Long-living fiber. */
1946
2122
  class $mol_wire_atom extends $mol_wire_fiber {
1947
2123
  static solo(host, task) {
1948
2124
  const field = task.name + '()';
@@ -1993,7 +2169,11 @@ var $;
1993
2169
  }
1994
2170
  $mol_wire_atom.watching.add(this);
1995
2171
  }
2172
+ /**
2173
+ * Update atom value through another temp fiber.
2174
+ */
1996
2175
  resync(args) {
2176
+ // enforce pulling tasks abort
1997
2177
  for (let cursor = this.pub_from; cursor < this.sub_from; cursor += 2) {
1998
2178
  const pub = this.data[cursor];
1999
2179
  if (pub && pub instanceof $mol_wire_task) {
@@ -2054,7 +2234,7 @@ var $;
2054
2234
  try {
2055
2235
  next[Symbol.toStringTag] = this[Symbol.toStringTag];
2056
2236
  }
2057
- catch {
2237
+ catch { // Promises throw in strict mode
2058
2238
  Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
2059
2239
  }
2060
2240
  }
@@ -2091,7 +2271,7 @@ var $;
2091
2271
  "use strict";
2092
2272
  var $;
2093
2273
  (function ($) {
2094
- const mod = require('module');
2274
+ const mod = require /****/('module');
2095
2275
  const internals = mod.builtinModules;
2096
2276
  function $node_internal_check(name) {
2097
2277
  if (name.startsWith('node:'))
@@ -2105,8 +2285,8 @@ var $;
2105
2285
  "use strict";
2106
2286
  var $;
2107
2287
  (function ($) {
2108
- const path = require('path');
2109
- const mod = require('module');
2288
+ const path = require /****/('path');
2289
+ const mod = require /****/('module');
2110
2290
  const localRequire = mod.createRequire(path.join(process.cwd(), 'package.json'));
2111
2291
  function $node_autoinstall(name) {
2112
2292
  try {
@@ -2181,6 +2361,7 @@ var $;
2181
2361
  ])
2182
2362
  ].map(frame_normalize).join('\n')
2183
2363
  });
2364
+ // в nodejs, что б не дублировалось cause в консоли
2184
2365
  Object.defineProperty(this, 'cause', {
2185
2366
  get: () => cause
2186
2367
  });
@@ -2269,6 +2450,10 @@ var $;
2269
2450
  props[field] = get_val;
2270
2451
  return get_val;
2271
2452
  }
2453
+ /**
2454
+ * Convert asynchronous (promise-based) API to synchronous by wrapping function and method calls in a fiber.
2455
+ * @see https://mol.hyoo.ru/#!section=docs/=1fcpsq_1wh0h2
2456
+ */
2272
2457
  function $mol_wire_sync(obj) {
2273
2458
  return new Proxy(obj, {
2274
2459
  get(obj, field) {
@@ -2625,6 +2810,7 @@ var $;
2625
2810
  ;
2626
2811
  $mol_wire_dom(this)[field] = getter;
2627
2812
  }
2813
+ /** Polyfill makes DOM reactive. */
2628
2814
  function $mol_wire_dom(el) {
2629
2815
  if (el.__defineGetter__ === redefine)
2630
2816
  return el;