mol_jsx_lib 0.0.840 → 0.0.841

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
@@ -42,341 +42,131 @@ var $;
42
42
  "use strict";
43
43
  var $;
44
44
  (function ($) {
45
- let $mol_wire_cursor;
46
- (function ($mol_wire_cursor) {
47
- $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
48
- $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
49
- $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
50
- $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
51
- })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
45
+ function $mol_promise_like(val) {
46
+ return val && typeof val === 'object' && 'then' in val && typeof val.then === 'function';
47
+ }
48
+ $.$mol_promise_like = $mol_promise_like;
52
49
  })($ || ($ = {}));
53
50
 
54
51
  ;
55
52
  "use strict";
56
53
  var $;
57
54
  (function ($) {
58
- class $mol_wire_pub extends Object {
59
- data = [];
60
- static get [Symbol.species]() {
61
- return Array;
62
- }
63
- sub_from = 0;
64
- get sub_list() {
65
- const res = [];
66
- for (let i = this.sub_from; i < this.data.length; i += 2) {
67
- res.push(this.data[i]);
68
- }
69
- return res;
70
- }
71
- get sub_empty() {
72
- return this.sub_from === this.data.length;
73
- }
74
- sub_on(sub, pub_pos) {
75
- const pos = this.data.length;
76
- this.data.push(sub, pub_pos);
77
- return pos;
78
- }
79
- sub_off(sub_pos) {
80
- if (!(sub_pos < this.data.length)) {
81
- $mol_fail(new Error(`Wrong pos ${sub_pos}`));
82
- }
83
- const end = this.data.length - 2;
84
- if (sub_pos !== end) {
85
- this.peer_move(end, sub_pos);
86
- }
87
- this.data.pop();
88
- this.data.pop();
89
- if (this.data.length === this.sub_from)
90
- this.reap();
91
- }
92
- reap() { }
93
- promote() {
94
- $mol_wire_auto()?.track_next(this);
95
- }
96
- fresh() { }
97
- complete() { }
98
- get incompleted() {
99
- return false;
100
- }
101
- emit(quant = $mol_wire_cursor.stale) {
102
- for (let i = this.sub_from; i < this.data.length; i += 2) {
103
- ;
104
- this.data[i].absorb(quant);
105
- }
106
- }
107
- peer_move(from_pos, to_pos) {
108
- const peer = this.data[from_pos];
109
- const self_pos = this.data[from_pos + 1];
110
- this.data[to_pos] = peer;
111
- this.data[to_pos + 1] = self_pos;
112
- peer.peer_repos(self_pos, to_pos);
113
- }
114
- peer_repos(peer_pos, self_pos) {
115
- this.data[peer_pos + 1] = self_pos;
116
- }
55
+ function $mol_fail_hidden(error) {
56
+ throw error;
117
57
  }
118
- $.$mol_wire_pub = $mol_wire_pub;
58
+ $.$mol_fail_hidden = $mol_fail_hidden;
119
59
  })($ || ($ = {}));
120
60
 
121
- ;
122
- "use strict";
123
-
124
61
  ;
125
62
  "use strict";
126
63
  var $;
127
64
  (function ($) {
128
- $.$mol_wire_auto_sub = null;
129
- function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
130
- return $.$mol_wire_auto_sub = next;
65
+ const catched = new WeakMap();
66
+ function $mol_fail_catch(error) {
67
+ if (typeof error !== 'object')
68
+ return false;
69
+ if ($mol_promise_like(error))
70
+ $mol_fail_hidden(error);
71
+ if (catched.get(error))
72
+ return false;
73
+ catched.set(error, true);
74
+ return true;
131
75
  }
132
- $.$mol_wire_auto = $mol_wire_auto;
133
- $.$mol_wire_affected = [];
76
+ $.$mol_fail_catch = $mol_fail_catch;
134
77
  })($ || ($ = {}));
135
78
 
136
79
  ;
137
80
  "use strict";
138
81
  var $;
139
82
  (function ($) {
140
- $['devtoolsFormatters'] ||= [];
141
- function $mol_dev_format_register(config) {
142
- $['devtoolsFormatters'].push(config);
83
+ function $mol_fail_log(error) {
84
+ if ($mol_promise_like(error))
85
+ return false;
86
+ if (!$mol_fail_catch(error))
87
+ return false;
88
+ console.error(error);
89
+ return true;
143
90
  }
144
- $.$mol_dev_format_register = $mol_dev_format_register;
145
- $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
146
- $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
147
- $mol_dev_format_register({
148
- header: (val, config = false) => {
149
- if (config)
150
- return null;
151
- if (!val)
152
- return null;
153
- if ($.$mol_dev_format_head in val) {
91
+ $.$mol_fail_log = $mol_fail_log;
92
+ })($ || ($ = {}));
93
+
94
+ ;
95
+ "use strict";
96
+ var $node = new Proxy({ require }, {
97
+ get(target, name, wrapper) {
98
+ if (target[name])
99
+ return target[name];
100
+ const mod = target.require('module');
101
+ if (mod.builtinModules.indexOf(name) >= 0)
102
+ return target.require(name);
103
+ if (name[0] === '.')
104
+ return target.require(name);
105
+ const path = target.require('path');
106
+ const fs = target.require('fs');
107
+ let dir = path.resolve('.');
108
+ const suffix = `./node_modules/${name}`;
109
+ const $$ = $;
110
+ while (!fs.existsSync(path.join(dir, suffix))) {
111
+ const parent = path.resolve(dir, '..');
112
+ if (parent === dir) {
113
+ $$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
154
114
  try {
155
- return val[$.$mol_dev_format_head]();
156
- }
157
- catch (error) {
158
- return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
115
+ $$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
159
116
  }
117
+ catch { }
118
+ break;
160
119
  }
161
- if (typeof val === 'function') {
162
- return $mol_dev_format_native(val);
120
+ else {
121
+ dir = parent;
163
122
  }
164
- if (Symbol.toStringTag in val) {
165
- return $mol_dev_format_native(val);
123
+ }
124
+ try {
125
+ return target.require(name);
126
+ }
127
+ catch (error) {
128
+ if (error.code === 'ERR_REQUIRE_ESM') {
129
+ const module = cache.get(name);
130
+ if (module)
131
+ return module;
132
+ throw import(name).then(module => cache.set(name, module));
166
133
  }
134
+ $.$mol_fail_log(error);
167
135
  return null;
168
- },
169
- hasBody: val => val[$.$mol_dev_format_body],
170
- body: val => val[$.$mol_dev_format_body](),
171
- });
172
- function $mol_dev_format_native(obj) {
173
- if (typeof obj === 'undefined')
174
- return $.$mol_dev_format_shade('undefined');
175
- return [
176
- 'object',
177
- {
178
- object: obj,
179
- config: true,
180
- },
181
- ];
182
- }
183
- $.$mol_dev_format_native = $mol_dev_format_native;
184
- function $mol_dev_format_auto(obj) {
185
- if (obj == null)
186
- return $.$mol_dev_format_shade(String(obj));
187
- return [
188
- 'object',
189
- {
190
- object: obj,
191
- config: false,
192
- },
193
- ];
194
- }
195
- $.$mol_dev_format_auto = $mol_dev_format_auto;
196
- function $mol_dev_format_element(element, style, ...content) {
197
- const styles = [];
198
- for (let key in style)
199
- styles.push(`${key} : ${style[key]}`);
200
- return [
201
- element,
202
- {
203
- style: styles.join(' ; '),
204
- },
205
- ...content,
206
- ];
207
- }
208
- $.$mol_dev_format_element = $mol_dev_format_element;
209
- function $mol_dev_format_span(style, ...content) {
210
- return $mol_dev_format_element('span', {
211
- ...style,
212
- }, ...content);
136
+ }
137
+ },
138
+ set(target, name, value) {
139
+ target[name] = value;
140
+ return true;
141
+ },
142
+ });
143
+ const cache = new Map();
144
+ require = (req => Object.assign(function require(name) {
145
+ return $node[name];
146
+ }, req))(require);
147
+
148
+ ;
149
+ "use strict";
150
+ var $;
151
+ (function ($) {
152
+ function $mol_log3_area_lazy(event) {
153
+ const self = this;
154
+ const stack = self.$mol_log3_stack;
155
+ const deep = stack.length;
156
+ let logged = false;
157
+ stack.push(() => {
158
+ logged = true;
159
+ self.$mol_log3_area.call(self, event);
160
+ });
161
+ return () => {
162
+ if (logged)
163
+ self.console.groupEnd();
164
+ if (stack.length > deep)
165
+ stack.length = deep;
166
+ };
213
167
  }
214
- $.$mol_dev_format_span = $mol_dev_format_span;
215
- $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
216
- $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
217
- $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
218
- $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
219
- $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
220
- $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
221
- $.$mol_dev_format_accent = $mol_dev_format_span.bind(null, {
222
- 'color': 'magenta',
223
- });
224
- $.$mol_dev_format_strong = $mol_dev_format_span.bind(null, {
225
- 'font-weight': 'bold',
226
- });
227
- $.$mol_dev_format_string = $mol_dev_format_span.bind(null, {
228
- 'color': 'green',
229
- });
230
- $.$mol_dev_format_shade = $mol_dev_format_span.bind(null, {
231
- 'color': 'gray',
232
- });
233
- $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
234
- 'margin-left': '13px'
235
- });
236
- })($ || ($ = {}));
237
-
238
- ;
239
- "use strict";
240
- var $;
241
- (function ($) {
242
- class $mol_wire_pub_sub extends $mol_wire_pub {
243
- pub_from = 0;
244
- cursor = $mol_wire_cursor.stale;
245
- get temp() {
246
- return false;
247
- }
248
- get pub_list() {
249
- const res = [];
250
- const max = this.cursor >= 0 ? this.cursor : this.sub_from;
251
- for (let i = this.pub_from; i < max; i += 2) {
252
- if (this.data[i])
253
- res.push(this.data[i]);
254
- }
255
- return res;
256
- }
257
- track_on() {
258
- this.cursor = this.pub_from;
259
- const sub = $mol_wire_auto();
260
- $mol_wire_auto(this);
261
- return sub;
262
- }
263
- promote() {
264
- if (this.cursor >= this.pub_from) {
265
- $mol_fail(new Error('Circular subscription'));
266
- }
267
- super.promote();
268
- }
269
- track_next(pub) {
270
- if (this.cursor < 0)
271
- $mol_fail(new Error('Promo to non begun sub'));
272
- if (this.cursor < this.sub_from) {
273
- const next = this.data[this.cursor];
274
- if (pub === undefined)
275
- return next ?? null;
276
- if (next === pub) {
277
- this.cursor += 2;
278
- return next;
279
- }
280
- if (next) {
281
- if (this.sub_from < this.data.length) {
282
- this.peer_move(this.sub_from, this.data.length);
283
- }
284
- this.peer_move(this.cursor, this.sub_from);
285
- this.sub_from += 2;
286
- }
287
- }
288
- else {
289
- if (pub === undefined)
290
- return null;
291
- if (this.sub_from < this.data.length) {
292
- this.peer_move(this.sub_from, this.data.length);
293
- }
294
- this.sub_from += 2;
295
- }
296
- this.data[this.cursor] = pub;
297
- this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
298
- this.cursor += 2;
299
- return pub;
300
- }
301
- track_off(sub) {
302
- $mol_wire_auto(sub);
303
- if (this.cursor < 0) {
304
- $mol_fail(new Error('End of non begun sub'));
305
- }
306
- for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
307
- const pub = this.data[cursor];
308
- pub.fresh();
309
- }
310
- this.cursor = $mol_wire_cursor.fresh;
311
- }
312
- pub_off(sub_pos) {
313
- this.data[sub_pos] = undefined;
314
- this.data[sub_pos + 1] = undefined;
315
- }
316
- destructor() {
317
- for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
318
- const sub = this.data[cursor];
319
- const pos = this.data[cursor + 1];
320
- sub.pub_off(pos);
321
- this.data.pop();
322
- this.data.pop();
323
- }
324
- this.cursor = this.pub_from;
325
- this.track_cut();
326
- this.cursor = $mol_wire_cursor.final;
327
- }
328
- track_cut() {
329
- if (this.cursor < this.pub_from) {
330
- $mol_fail(new Error('Cut of non begun sub'));
331
- }
332
- let tail = 0;
333
- for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
334
- const pub = this.data[cursor];
335
- pub?.sub_off(this.data[cursor + 1]);
336
- if (this.sub_from < this.data.length) {
337
- this.peer_move(this.data.length - 2, cursor);
338
- this.data.pop();
339
- this.data.pop();
340
- }
341
- else {
342
- ++tail;
343
- }
344
- }
345
- for (; tail; --tail) {
346
- this.data.pop();
347
- this.data.pop();
348
- }
349
- this.sub_from = this.cursor;
350
- }
351
- complete() { }
352
- complete_pubs() {
353
- const limit = this.cursor < 0 ? this.sub_from : this.cursor;
354
- for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
355
- const pub = this.data[cursor];
356
- if (pub?.incompleted)
357
- return;
358
- }
359
- for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
360
- const pub = this.data[cursor];
361
- pub?.complete();
362
- }
363
- }
364
- absorb(quant = $mol_wire_cursor.stale) {
365
- if (this.cursor === $mol_wire_cursor.final)
366
- return;
367
- if (this.cursor >= quant)
368
- return;
369
- this.cursor = quant;
370
- this.emit($mol_wire_cursor.doubt);
371
- }
372
- [$mol_dev_format_head]() {
373
- return $mol_dev_format_native(this);
374
- }
375
- get pub_empty() {
376
- return this.sub_from === this.pub_from;
377
- }
378
- }
379
- $.$mol_wire_pub_sub = $mol_wire_pub_sub;
168
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
169
+ $.$mol_log3_stack = [];
380
170
  })($ || ($ = {}));
381
171
 
382
172
  ;
@@ -483,16 +273,6 @@ var $;
483
273
  $.$mol_owning_catch = $mol_owning_catch;
484
274
  })($ || ($ = {}));
485
275
 
486
- ;
487
- "use strict";
488
- var $;
489
- (function ($) {
490
- function $mol_fail_hidden(error) {
491
- throw error;
492
- }
493
- $.$mol_fail_hidden = $mol_fail_hidden;
494
- })($ || ($ = {}));
495
-
496
276
  ;
497
277
  "use strict";
498
278
 
@@ -575,1362 +355,1358 @@ var $;
575
355
  "use strict";
576
356
  var $;
577
357
  (function ($) {
578
- class $mol_after_timeout extends $mol_object2 {
579
- delay;
580
- task;
581
- id;
582
- constructor(delay, task) {
358
+ class $mol_span extends $mol_object2 {
359
+ uri;
360
+ source;
361
+ row;
362
+ col;
363
+ length;
364
+ constructor(uri, source, row, col, length) {
583
365
  super();
584
- this.delay = delay;
585
- this.task = task;
586
- this.id = setTimeout(task, delay);
366
+ this.uri = uri;
367
+ this.source = source;
368
+ this.row = row;
369
+ this.col = col;
370
+ this.length = length;
371
+ this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
587
372
  }
588
- destructor() {
589
- clearTimeout(this.id);
373
+ static unknown = $mol_span.begin('?');
374
+ static begin(uri, source = '') {
375
+ return new $mol_span(uri, source, 1, 1, 0);
376
+ }
377
+ static end(uri, source) {
378
+ return new $mol_span(uri, source, 1, source.length + 1, 0);
379
+ }
380
+ static entire(uri, source) {
381
+ return new $mol_span(uri, source, 1, 1, source.length);
382
+ }
383
+ toString() {
384
+ return this[Symbol.toStringTag];
385
+ }
386
+ toJSON() {
387
+ return {
388
+ uri: this.uri,
389
+ row: this.row,
390
+ col: this.col,
391
+ length: this.length
392
+ };
393
+ }
394
+ error(message, Class = Error) {
395
+ return new Class(`${message} (${this})`);
396
+ }
397
+ span(row, col, length) {
398
+ return new $mol_span(this.uri, this.source, row, col, length);
399
+ }
400
+ after(length = 0) {
401
+ return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
402
+ }
403
+ slice(begin, end = -1) {
404
+ let len = this.length;
405
+ if (begin < 0)
406
+ begin += len;
407
+ if (end < 0)
408
+ end += len;
409
+ if (begin < 0 || begin > len)
410
+ this.$.$mol_fail(this.error(`Begin value '${begin}' out of range`, RangeError));
411
+ if (end < 0 || end > len)
412
+ this.$.$mol_fail(this.error(`End value '${end}' out of range`, RangeError));
413
+ if (end < begin)
414
+ this.$.$mol_fail(this.error(`End value '${end}' can't be less than begin value`, RangeError));
415
+ return this.span(this.row, this.col + begin, end - begin);
590
416
  }
591
417
  }
592
- $.$mol_after_timeout = $mol_after_timeout;
418
+ $.$mol_span = $mol_span;
593
419
  })($ || ($ = {}));
594
420
 
595
421
  ;
596
422
  "use strict";
597
423
  var $;
598
424
  (function ($) {
599
- class $mol_after_frame extends $mol_after_timeout {
600
- task;
601
- constructor(task) {
602
- super(16, task);
603
- this.task = task;
425
+ function $mol_tree2_to_string(tree) {
426
+ let output = [];
427
+ function dump(tree, prefix = '') {
428
+ if (tree.type.length) {
429
+ if (!prefix.length) {
430
+ prefix = "\t";
431
+ }
432
+ output.push(tree.type);
433
+ if (tree.kids.length == 1) {
434
+ output.push(' ');
435
+ dump(tree.kids[0], prefix);
436
+ return;
437
+ }
438
+ output.push("\n");
439
+ }
440
+ else if (tree.value.length || prefix.length) {
441
+ output.push("\\" + tree.value + "\n");
442
+ }
443
+ for (const kid of tree.kids) {
444
+ output.push(prefix);
445
+ dump(kid, prefix + "\t");
446
+ }
604
447
  }
448
+ dump(tree);
449
+ return output.join('');
605
450
  }
606
- $.$mol_after_frame = $mol_after_frame;
451
+ $.$mol_tree2_to_string = $mol_tree2_to_string;
607
452
  })($ || ($ = {}));
608
453
 
609
454
  ;
610
455
  "use strict";
611
456
  var $;
612
457
  (function ($) {
613
- function $mol_promise_like(val) {
614
- return val && typeof val === 'object' && 'then' in val && typeof val.then === 'function';
615
- }
616
- $.$mol_promise_like = $mol_promise_like;
617
- })($ || ($ = {}));
618
-
619
- ;
620
- "use strict";
621
- var $;
622
- (function ($) {
623
- const handled = new WeakSet();
624
- class $mol_wire_fiber extends $mol_wire_pub_sub {
625
- task;
626
- host;
627
- static warm = true;
628
- static planning = new Set();
629
- static reaping = new Set();
630
- static plan_task = null;
631
- static plan() {
632
- if (this.plan_task)
633
- return;
634
- this.plan_task = new $mol_after_frame(() => {
635
- try {
636
- this.sync();
637
- }
638
- finally {
639
- $mol_wire_fiber.plan_task = null;
640
- }
641
- });
642
- }
643
- static sync() {
644
- while (this.planning.size) {
645
- for (const fiber of this.planning) {
646
- this.planning.delete(fiber);
647
- if (fiber.cursor >= 0)
648
- continue;
649
- if (fiber.cursor === $mol_wire_cursor.final)
650
- continue;
651
- fiber.fresh();
652
- }
653
- }
654
- while (this.reaping.size) {
655
- const fibers = this.reaping;
656
- this.reaping = new Set;
657
- for (const fiber of fibers) {
658
- if (!fiber.sub_empty)
659
- continue;
660
- fiber.destructor();
661
- }
662
- }
663
- }
664
- [Symbol.toStringTag];
665
- cache = undefined;
666
- get args() {
667
- return this.data.slice(0, this.pub_from);
668
- }
669
- result() {
670
- if ($mol_promise_like(this.cache))
671
- return;
672
- if (this.cache instanceof Error)
673
- return;
674
- return this.cache;
458
+ class $mol_tree2 extends Object {
459
+ type;
460
+ value;
461
+ kids;
462
+ span;
463
+ constructor(type, value, kids, span) {
464
+ super();
465
+ this.type = type;
466
+ this.value = value;
467
+ this.kids = kids;
468
+ this.span = span;
469
+ this[Symbol.toStringTag] = type || '\\' + value;
675
470
  }
676
- get incompleted() {
677
- return $mol_promise_like(this.cache);
471
+ static list(kids, span = $mol_span.unknown) {
472
+ return new $mol_tree2('', '', kids, span);
678
473
  }
679
- field() {
680
- return this.task.name + '<>';
474
+ list(kids) {
475
+ return $mol_tree2.list(kids, this.span);
681
476
  }
682
- constructor(id, task, host, args) {
683
- super();
684
- this.task = task;
685
- this.host = host;
686
- if (args)
687
- this.data.push(...args);
688
- this.pub_from = this.sub_from = args?.length ?? 0;
689
- this[Symbol.toStringTag] = id;
477
+ static data(value, kids = [], span = $mol_span.unknown) {
478
+ const chunks = value.split('\n');
479
+ if (chunks.length > 1) {
480
+ let kid_span = span.span(span.row, span.col, 0);
481
+ const data = chunks.map(chunk => {
482
+ kid_span = kid_span.after(chunk.length);
483
+ return new $mol_tree2('', chunk, [], kid_span);
484
+ });
485
+ kids = [...data, ...kids];
486
+ value = '';
487
+ }
488
+ return new $mol_tree2('', value, kids, span);
690
489
  }
691
- plan() {
692
- $mol_wire_fiber.planning.add(this);
693
- $mol_wire_fiber.plan();
490
+ data(value, kids = []) {
491
+ return $mol_tree2.data(value, kids, this.span);
694
492
  }
695
- reap() {
696
- $mol_wire_fiber.reaping.add(this);
697
- $mol_wire_fiber.plan();
493
+ static struct(type, kids = [], span = $mol_span.unknown) {
494
+ if (/[ \n\t\\]/.test(type)) {
495
+ $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
496
+ }
497
+ return new $mol_tree2(type, '', kids, span);
698
498
  }
699
- toString() {
700
- return this[Symbol.toStringTag];
499
+ struct(type, kids = []) {
500
+ return $mol_tree2.struct(type, kids, this.span);
701
501
  }
702
- toJSON() {
703
- return this[Symbol.toStringTag];
502
+ clone(kids, span = this.span) {
503
+ return new $mol_tree2(this.type, this.value, kids, span);
704
504
  }
705
- [$mol_dev_format_head]() {
706
- const cursor = {
707
- [$mol_wire_cursor.stale]: '🔴',
708
- [$mol_wire_cursor.doubt]: '🟡',
709
- [$mol_wire_cursor.fresh]: '🟢',
710
- [$mol_wire_cursor.final]: '🔵',
711
- }[this.cursor] ?? this.cursor.toString();
712
- return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
713
- ? $mol_dev_format_auto({
714
- [$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
715
- [$mol_dev_format_body]: () => $mol_dev_format_native(this),
716
- })
717
- : $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
505
+ text() {
506
+ var values = [];
507
+ for (var kid of this.kids) {
508
+ if (kid.type)
509
+ continue;
510
+ values.push(kid.value);
511
+ }
512
+ return this.value + values.join('\n');
718
513
  }
719
- get $() {
720
- return (this.host ?? this.task)['$'];
514
+ static fromString(str, uri = 'unknown') {
515
+ return $$.$mol_tree2_from_string(str, uri);
721
516
  }
722
- emit(quant = $mol_wire_cursor.stale) {
723
- if (this.sub_empty)
724
- this.plan();
725
- else
726
- super.emit(quant);
517
+ toString() {
518
+ return $$.$mol_tree2_to_string(this);
727
519
  }
728
- fresh() {
729
- if (this.cursor === $mol_wire_cursor.fresh)
730
- return;
731
- if (this.cursor === $mol_wire_cursor.final)
732
- return;
733
- check: if (this.cursor === $mol_wire_cursor.doubt) {
734
- for (let i = this.pub_from; i < this.sub_from; i += 2) {
735
- ;
736
- this.data[i]?.fresh();
737
- if (this.cursor !== $mol_wire_cursor.doubt)
738
- break check;
520
+ insert(value, ...path) {
521
+ if (path.length === 0)
522
+ return value;
523
+ const type = path[0];
524
+ if (typeof type === 'string') {
525
+ let replaced = false;
526
+ const sub = this.kids.map((item, index) => {
527
+ if (item.type !== type)
528
+ return item;
529
+ replaced = true;
530
+ return item.insert(value, ...path.slice(1));
531
+ }).filter(Boolean);
532
+ if (!replaced && value) {
533
+ sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
739
534
  }
740
- this.cursor = $mol_wire_cursor.fresh;
741
- return;
535
+ return this.clone(sub);
742
536
  }
743
- const bu = this.track_on();
744
- let result;
745
- try {
746
- switch (this.pub_from) {
747
- case 0:
748
- result = this.task.call(this.host);
749
- break;
750
- case 1:
751
- result = this.task.call(this.host, this.data[0]);
752
- break;
753
- default:
754
- result = this.task.call(this.host, ...this.args);
755
- break;
756
- }
757
- if ($mol_promise_like(result) && !handled.has(result)) {
758
- const put = (res) => {
759
- if (this.cache === result)
760
- this.put(res);
761
- return res;
762
- };
763
- result = result.then(put, put);
537
+ else if (typeof type === 'number') {
538
+ const sub = this.kids.slice();
539
+ sub[type] = (sub[type] || this.list([]))
540
+ .insert(value, ...path.slice(1));
541
+ return this.clone(sub.filter(Boolean));
542
+ }
543
+ else {
544
+ const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
545
+ .map(item => item.insert(value, ...path.slice(1)))
546
+ .filter(Boolean);
547
+ return this.clone(kids);
548
+ }
549
+ }
550
+ select(...path) {
551
+ let next = [this];
552
+ for (const type of path) {
553
+ if (!next.length)
554
+ break;
555
+ const prev = next;
556
+ next = [];
557
+ for (var item of prev) {
558
+ switch (typeof (type)) {
559
+ case 'string':
560
+ for (var child of item.kids) {
561
+ if (child.type == type) {
562
+ next.push(child);
563
+ }
564
+ }
565
+ break;
566
+ case 'number':
567
+ if (type < item.kids.length)
568
+ next.push(item.kids[type]);
569
+ break;
570
+ default: next.push(...item.kids);
571
+ }
764
572
  }
765
573
  }
766
- catch (error) {
767
- if (error instanceof Error || $mol_promise_like(error)) {
768
- result = error;
574
+ return this.list(next);
575
+ }
576
+ filter(path, value) {
577
+ const sub = this.kids.filter(item => {
578
+ var found = item.select(...path);
579
+ if (value === undefined) {
580
+ return Boolean(found.kids.length);
769
581
  }
770
582
  else {
771
- result = new Error(String(error), { cause: error });
772
- }
773
- if ($mol_promise_like(result) && !handled.has(result)) {
774
- result = result.finally(() => {
775
- if (this.cache === result)
776
- this.absorb();
777
- });
583
+ return found.kids.some(child => child.value == value);
778
584
  }
585
+ });
586
+ return this.clone(sub);
587
+ }
588
+ hack_self(belt, context = {}) {
589
+ let handle = belt[this.type] || belt[''];
590
+ if (!handle || handle === Object.prototype[this.type]) {
591
+ handle = (input, belt, context) => [
592
+ input.clone(input.hack(belt, context), context.span)
593
+ ];
779
594
  }
780
- if ($mol_promise_like(result) && !handled.has(result)) {
781
- result = Object.assign(result, {
782
- destructor: result['destructor'] ?? (() => { })
783
- });
784
- handled.add(result);
785
- const error = new Error(`Promise in ${this}`);
786
- Object.defineProperty(result, 'stack', { get: () => error.stack });
595
+ try {
596
+ return handle(this, belt, context);
787
597
  }
788
- if (!$mol_promise_like(result)) {
789
- this.track_cut();
598
+ catch (error) {
599
+ error.message += `\n${this.clone([])}${this.span}`;
600
+ $mol_fail_hidden(error);
790
601
  }
791
- this.track_off(bu);
792
- this.put(result);
793
602
  }
794
- refresh() {
795
- this.cursor = $mol_wire_cursor.stale;
796
- this.fresh();
603
+ hack(belt, context = {}) {
604
+ return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
797
605
  }
798
- sync() {
799
- if (!$mol_wire_fiber.warm) {
800
- return this.result();
606
+ error(message, Class = Error) {
607
+ return this.span.error(`${message}\n${this.clone([])}`, Class);
608
+ }
609
+ }
610
+ $.$mol_tree2 = $mol_tree2;
611
+ class $mol_tree2_empty extends $mol_tree2 {
612
+ constructor() {
613
+ super('', '', [], $mol_span.unknown);
614
+ }
615
+ }
616
+ $.$mol_tree2_empty = $mol_tree2_empty;
617
+ })($ || ($ = {}));
618
+
619
+ ;
620
+ "use strict";
621
+ var $;
622
+ (function ($) {
623
+ class $mol_error_syntax extends SyntaxError {
624
+ reason;
625
+ line;
626
+ span;
627
+ constructor(reason, line, span) {
628
+ super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
629
+ this.reason = reason;
630
+ this.line = line;
631
+ this.span = span;
632
+ }
633
+ }
634
+ $.$mol_error_syntax = $mol_error_syntax;
635
+ })($ || ($ = {}));
636
+
637
+ ;
638
+ "use strict";
639
+ var $;
640
+ (function ($) {
641
+ function $mol_tree2_from_string(str, uri = '?') {
642
+ const span = $mol_span.entire(uri, str);
643
+ var root = $mol_tree2.list([], span);
644
+ var stack = [root];
645
+ var pos = 0, row = 0, min_indent = 0;
646
+ while (str.length > pos) {
647
+ var indent = 0;
648
+ var line_start = pos;
649
+ row++;
650
+ while (str.length > pos && str[pos] == '\t') {
651
+ indent++;
652
+ pos++;
801
653
  }
802
- this.promote();
803
- this.fresh();
804
- if (this.cache instanceof Error) {
805
- return $mol_fail_hidden(this.cache);
654
+ if (!root.kids.length) {
655
+ min_indent = indent;
806
656
  }
807
- if ($mol_promise_like(this.cache)) {
808
- return $mol_fail_hidden(this.cache);
657
+ indent -= min_indent;
658
+ if (indent < 0 || indent >= stack.length) {
659
+ const sp = span.span(row, 1, pos - line_start);
660
+ while (str.length > pos && str[pos] != '\n') {
661
+ pos++;
662
+ }
663
+ if (indent < 0) {
664
+ if (str.length > pos) {
665
+ this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
666
+ }
667
+ }
668
+ else {
669
+ this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
670
+ }
809
671
  }
810
- return this.cache;
811
- }
812
- async async() {
813
- while (true) {
814
- this.fresh();
815
- if (this.cache instanceof Error) {
816
- $mol_fail_hidden(this.cache);
672
+ stack.length = indent + 1;
673
+ var parent = stack[indent];
674
+ while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
675
+ var error_start = pos;
676
+ while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
677
+ pos++;
817
678
  }
818
- if (!$mol_promise_like(this.cache))
819
- return this.cache;
820
- await Promise.race([this.cache, this.step()]);
821
- if (!$mol_promise_like(this.cache))
822
- return this.cache;
823
- if (this.cursor === $mol_wire_cursor.final) {
824
- await new Promise(() => { });
679
+ if (pos > error_start) {
680
+ let line_end = str.indexOf('\n', pos);
681
+ if (line_end === -1)
682
+ line_end = str.length;
683
+ const sp = span.span(row, error_start - line_start + 1, pos - error_start);
684
+ this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
685
+ }
686
+ var type_start = pos;
687
+ while (str.length > pos &&
688
+ str[pos] != '\\' &&
689
+ str[pos] != ' ' &&
690
+ str[pos] != '\t' &&
691
+ str[pos] != '\n') {
692
+ pos++;
693
+ }
694
+ if (pos > type_start) {
695
+ let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
696
+ const parent_kids = parent.kids;
697
+ parent_kids.push(next);
698
+ parent = next;
699
+ }
700
+ if (str.length > pos && str[pos] == ' ') {
701
+ pos++;
825
702
  }
826
703
  }
704
+ if (str.length > pos && str[pos] == '\\') {
705
+ var data_start = pos;
706
+ while (str.length > pos && str[pos] != '\n') {
707
+ pos++;
708
+ }
709
+ let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
710
+ const parent_kids = parent.kids;
711
+ parent_kids.push(next);
712
+ parent = next;
713
+ }
714
+ if (str.length === pos && stack.length > 0) {
715
+ const sp = span.span(row, pos - line_start + 1, 1);
716
+ this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
717
+ }
718
+ stack.push(parent);
719
+ pos++;
827
720
  }
828
- step() {
829
- return new Promise(done => {
830
- const sub = new $mol_wire_pub_sub;
831
- const prev = sub.track_on();
832
- sub.track_next(this);
833
- sub.track_off(prev);
834
- sub.absorb = () => {
835
- done(null);
836
- sub.destructor();
837
- };
838
- });
839
- }
721
+ return root;
840
722
  }
841
- $.$mol_wire_fiber = $mol_wire_fiber;
723
+ $.$mol_tree2_from_string = $mol_tree2_from_string;
842
724
  })($ || ($ = {}));
843
725
 
844
726
  ;
845
727
  "use strict";
846
728
  var $;
847
729
  (function ($) {
848
- $.$mol_compare_deep_cache = new WeakMap();
849
- function $mol_compare_deep(left, right) {
850
- if (Object.is(left, right))
851
- return true;
852
- if (left === null)
853
- return false;
854
- if (right === null)
855
- return false;
856
- if (typeof left !== 'object')
857
- return false;
858
- if (typeof right !== 'object')
859
- return false;
860
- const left_proto = Reflect.getPrototypeOf(left);
861
- const right_proto = Reflect.getPrototypeOf(right);
862
- if (left_proto !== right_proto)
863
- return false;
864
- if (left instanceof Boolean)
865
- return Object.is(left.valueOf(), right['valueOf']());
866
- if (left instanceof Number)
867
- return Object.is(left.valueOf(), right['valueOf']());
868
- if (left instanceof String)
869
- return Object.is(left.valueOf(), right['valueOf']());
870
- if (left instanceof Date)
871
- return Object.is(left.valueOf(), right['valueOf']());
872
- if (left instanceof RegExp)
873
- return left.source === right.source && left.flags === right.flags;
874
- if (left instanceof Error)
875
- return left.message === right.message && left.stack === right.stack;
876
- let left_cache = $.$mol_compare_deep_cache.get(left);
877
- if (left_cache) {
878
- const right_cache = left_cache.get(right);
879
- if (typeof right_cache === 'boolean')
880
- return right_cache;
730
+ function $mol_tree2_from_json(json, span = $mol_span.unknown) {
731
+ if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
732
+ return new $mol_tree2(String(json), '', [], span);
881
733
  }
882
- else {
883
- left_cache = new WeakMap([[right, true]]);
884
- $.$mol_compare_deep_cache.set(left, left_cache);
734
+ if (typeof json === 'string') {
735
+ return $mol_tree2.data(json, [], span);
885
736
  }
886
- let result;
887
- try {
888
- if (!left_proto)
889
- result = compare_pojo(left, right);
890
- else if (!Reflect.getPrototypeOf(left_proto))
891
- result = compare_pojo(left, right);
892
- else if (Symbol.toPrimitive in left)
893
- result = compare_primitive(left, right);
894
- else if (Array.isArray(left))
895
- result = compare_array(left, right);
896
- else if (left instanceof Set)
897
- result = compare_set(left, right);
898
- else if (left instanceof Map)
899
- result = compare_map(left, right);
900
- else if (ArrayBuffer.isView(left))
901
- result = compare_buffer(left, right);
902
- else if (Symbol.iterator in left)
903
- result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
904
- else
905
- result = false;
737
+ if (Array.isArray(json)) {
738
+ const sub = json.map(json => $mol_tree2_from_json(json, span));
739
+ return new $mol_tree2('/', '', sub, span);
906
740
  }
907
- finally {
908
- left_cache.set(right, result);
741
+ if (ArrayBuffer.isView(json)) {
742
+ const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
743
+ return $mol_tree2.data(String.fromCharCode(...buf), [], span);
909
744
  }
910
- return result;
911
- }
912
- $.$mol_compare_deep = $mol_compare_deep;
913
- function compare_array(left, right) {
914
- const len = left.length;
915
- if (len !== right.length)
916
- return false;
917
- for (let i = 0; i < len; ++i) {
918
- if (!$mol_compare_deep(left[i], right[i]))
919
- return false;
745
+ if (json instanceof Date) {
746
+ return new $mol_tree2('', json.toISOString(), [], span);
920
747
  }
921
- return true;
922
- }
923
- function compare_buffer(left, right) {
924
- const len = left.byteLength;
925
- if (len !== right.byteLength)
926
- return false;
927
- if (left instanceof DataView)
928
- return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
929
- for (let i = 0; i < len; ++i) {
930
- if (left[i] !== right[i])
931
- return false;
748
+ if (typeof json.toJSON === 'function') {
749
+ return $mol_tree2_from_json(json.toJSON());
932
750
  }
933
- return true;
934
- }
935
- function compare_iterator(left, right) {
936
- while (true) {
937
- const left_next = left.next();
938
- const right_next = right.next();
939
- if (left_next.done !== right_next.done)
940
- return false;
941
- if (left_next.done)
942
- break;
943
- if (!$mol_compare_deep(left_next.value, right_next.value))
944
- return false;
751
+ if (json.toString !== Object.prototype.toString) {
752
+ return $mol_tree2.data(json.toString(), [], span);
945
753
  }
946
- return true;
947
- }
948
- function compare_set(left, right) {
949
- if (left.size !== right.size)
950
- return false;
951
- return compare_iterator(left.values(), right.values());
952
- }
953
- function compare_map(left, right) {
954
- if (left.size !== right.size)
955
- return false;
956
- return compare_iterator(left.keys(), right.keys())
957
- && compare_iterator(left.values(), right.values());
958
- }
959
- function compare_pojo(left, right) {
960
- const left_keys = Object.getOwnPropertyNames(left);
961
- const right_keys = Object.getOwnPropertyNames(right);
962
- if (!compare_array(left_keys, right_keys))
963
- return false;
964
- for (let key of left_keys) {
965
- if (!$mol_compare_deep(left[key], right[key]))
966
- return false;
754
+ if (json instanceof Error) {
755
+ const { name, message, stack } = json;
756
+ json = { ...json, name, message, stack };
967
757
  }
968
- const left_syms = Object.getOwnPropertySymbols(left);
969
- const right_syms = Object.getOwnPropertySymbols(right);
970
- if (!compare_array(left_syms, right_syms))
971
- return false;
972
- for (let key of left_syms) {
973
- if (!$mol_compare_deep(left[key], right[key]))
974
- return false;
758
+ const sub = [];
759
+ for (var key in json) {
760
+ const val = json[key];
761
+ if (val === undefined)
762
+ continue;
763
+ const subsub = $mol_tree2_from_json(val, span);
764
+ if (/^[^\n\t\\ ]+$/.test(key)) {
765
+ sub.push(new $mol_tree2(key, '', [subsub], span));
766
+ }
767
+ else {
768
+ sub.push($mol_tree2.data(key, [subsub], span));
769
+ }
770
+ }
771
+ return new $mol_tree2('*', '', sub, span);
772
+ }
773
+ $.$mol_tree2_from_json = $mol_tree2_from_json;
774
+ })($ || ($ = {}));
775
+
776
+ ;
777
+ "use strict";
778
+ var $;
779
+ (function ($) {
780
+ class $mol_term_color {
781
+ static reset = this.ansi(0, 0);
782
+ static bold = this.ansi(1, 22);
783
+ static italic = this.ansi(3, 23);
784
+ static underline = this.ansi(4, 24);
785
+ static inverse = this.ansi(7, 27);
786
+ static hidden = this.ansi(8, 28);
787
+ static strike = this.ansi(9, 29);
788
+ static gray = this.ansi(90, 39);
789
+ static red = this.ansi(91, 39);
790
+ static green = this.ansi(92, 39);
791
+ static yellow = this.ansi(93, 39);
792
+ static blue = this.ansi(94, 39);
793
+ static magenta = this.ansi(95, 39);
794
+ static cyan = this.ansi(96, 39);
795
+ static Gray = (str) => this.inverse(this.gray(str));
796
+ static Red = (str) => this.inverse(this.red(str));
797
+ static Green = (str) => this.inverse(this.green(str));
798
+ static Yellow = (str) => this.inverse(this.yellow(str));
799
+ static Blue = (str) => this.inverse(this.blue(str));
800
+ static Magenta = (str) => this.inverse(this.magenta(str));
801
+ static Cyan = (str) => this.inverse(this.cyan(str));
802
+ static ansi(open, close) {
803
+ if (typeof process === 'undefined')
804
+ return String;
805
+ if (!process.stdout.isTTY)
806
+ return String;
807
+ const prefix = `\x1b[${open}m`;
808
+ const postfix = `\x1b[${close}m`;
809
+ const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
810
+ return function colorer(str) {
811
+ str = String(str);
812
+ if (str === '')
813
+ return str;
814
+ const suffix = str.replace(suffix_regexp, prefix);
815
+ return prefix + suffix + postfix;
816
+ };
975
817
  }
976
- return true;
977
- }
978
- function compare_primitive(left, right) {
979
- return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
980
818
  }
819
+ $.$mol_term_color = $mol_term_color;
981
820
  })($ || ($ = {}));
982
821
 
983
822
  ;
984
823
  "use strict";
985
824
  var $;
986
825
  (function ($) {
987
- function $mol_log3_area_lazy(event) {
988
- const self = this;
989
- const stack = self.$mol_log3_stack;
990
- const deep = stack.length;
991
- let logged = false;
992
- stack.push(() => {
993
- logged = true;
994
- self.$mol_log3_area.call(self, event);
995
- });
996
- return () => {
997
- if (logged)
998
- self.console.groupEnd();
999
- if (stack.length > deep)
1000
- stack.length = deep;
826
+ function $mol_log3_node_make(level, output, type, color) {
827
+ return function $mol_log3_logger(event) {
828
+ if (!event.time)
829
+ event = { time: new Date().toISOString(), ...event };
830
+ let tree = this.$mol_tree2_from_json(event);
831
+ tree = tree.struct(type, tree.kids);
832
+ let str = color(tree.toString());
833
+ this.console[level](str);
834
+ const self = this;
835
+ return () => self.console.groupEnd();
1001
836
  };
1002
837
  }
1003
- $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1004
- $.$mol_log3_stack = [];
838
+ $.$mol_log3_node_make = $mol_log3_node_make;
839
+ $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
840
+ $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
841
+ $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
842
+ $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
843
+ $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
844
+ $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
1005
845
  })($ || ($ = {}));
1006
846
 
1007
847
  ;
1008
848
  "use strict";
1009
849
  var $;
1010
850
  (function ($) {
1011
- class $mol_span extends $mol_object2 {
1012
- uri;
1013
- source;
1014
- row;
1015
- col;
1016
- length;
1017
- constructor(uri, source, row, col, length) {
1018
- super();
1019
- this.uri = uri;
1020
- this.source = source;
1021
- this.row = row;
1022
- this.col = col;
1023
- this.length = length;
1024
- this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
1025
- }
1026
- static unknown = $mol_span.begin('?');
1027
- static begin(uri, source = '') {
1028
- return new $mol_span(uri, source, 1, 1, 0);
1029
- }
1030
- static end(uri, source) {
1031
- return new $mol_span(uri, source, 1, source.length + 1, 0);
1032
- }
1033
- static entire(uri, source) {
1034
- return new $mol_span(uri, source, 1, 1, source.length);
1035
- }
1036
- toString() {
1037
- return this[Symbol.toStringTag];
1038
- }
1039
- toJSON() {
1040
- return {
1041
- uri: this.uri,
1042
- row: this.row,
1043
- col: this.col,
1044
- length: this.length
1045
- };
1046
- }
1047
- error(message, Class = Error) {
1048
- return new Class(`${message} (${this})`);
1049
- }
1050
- span(row, col, length) {
1051
- return new $mol_span(this.uri, this.source, row, col, length);
1052
- }
1053
- after(length = 0) {
1054
- return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
1055
- }
1056
- slice(begin, end = -1) {
1057
- let len = this.length;
1058
- if (begin < 0)
1059
- begin += len;
1060
- if (end < 0)
1061
- end += len;
1062
- if (begin < 0 || begin > len)
1063
- this.$.$mol_fail(this.error(`Begin value '${begin}' out of range`, RangeError));
1064
- if (end < 0 || end > len)
1065
- this.$.$mol_fail(this.error(`End value '${end}' out of range`, RangeError));
1066
- if (end < begin)
1067
- this.$.$mol_fail(this.error(`End value '${end}' can't be less than begin value`, RangeError));
1068
- return this.span(this.row, this.col + begin, end - begin);
1069
- }
851
+ function $mol_env() {
852
+ return {};
1070
853
  }
1071
- $.$mol_span = $mol_span;
854
+ $.$mol_env = $mol_env;
1072
855
  })($ || ($ = {}));
1073
856
 
1074
857
  ;
1075
858
  "use strict";
1076
859
  var $;
1077
860
  (function ($) {
1078
- function $mol_tree2_to_string(tree) {
1079
- let output = [];
1080
- function dump(tree, prefix = '') {
1081
- if (tree.type.length) {
1082
- if (!prefix.length) {
1083
- prefix = "\t";
1084
- }
1085
- output.push(tree.type);
1086
- if (tree.kids.length == 1) {
1087
- output.push(' ');
1088
- dump(tree.kids[0], prefix);
1089
- return;
1090
- }
1091
- output.push("\n");
1092
- }
1093
- else if (tree.value.length || prefix.length) {
1094
- output.push("\\" + tree.value + "\n");
1095
- }
1096
- for (const kid of tree.kids) {
1097
- output.push(prefix);
1098
- dump(kid, prefix + "\t");
1099
- }
1100
- }
1101
- dump(tree);
1102
- return output.join('');
1103
- }
1104
- $.$mol_tree2_to_string = $mol_tree2_to_string;
861
+ $.$mol_env = function $mol_env() {
862
+ return this.process.env;
863
+ };
1105
864
  })($ || ($ = {}));
1106
865
 
1107
866
  ;
1108
867
  "use strict";
1109
868
  var $;
1110
869
  (function ($) {
1111
- class $mol_tree2 extends Object {
1112
- type;
1113
- value;
1114
- kids;
1115
- span;
1116
- constructor(type, value, kids, span) {
1117
- super();
1118
- this.type = type;
1119
- this.value = value;
1120
- this.kids = kids;
1121
- this.span = span;
1122
- this[Symbol.toStringTag] = type || '\\' + value;
1123
- }
1124
- static list(kids, span = $mol_span.unknown) {
1125
- return new $mol_tree2('', '', kids, span);
1126
- }
1127
- list(kids) {
1128
- return $mol_tree2.list(kids, this.span);
1129
- }
1130
- static data(value, kids = [], span = $mol_span.unknown) {
1131
- const chunks = value.split('\n');
1132
- if (chunks.length > 1) {
1133
- let kid_span = span.span(span.row, span.col, 0);
1134
- const data = chunks.map(chunk => {
1135
- kid_span = kid_span.after(chunk.length);
1136
- return new $mol_tree2('', chunk, [], kid_span);
1137
- });
1138
- kids = [...data, ...kids];
1139
- value = '';
1140
- }
1141
- return new $mol_tree2('', value, kids, span);
1142
- }
1143
- data(value, kids = []) {
1144
- return $mol_tree2.data(value, kids, this.span);
1145
- }
1146
- static struct(type, kids = [], span = $mol_span.unknown) {
1147
- if (/[ \n\t\\]/.test(type)) {
1148
- $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
1149
- }
1150
- return new $mol_tree2(type, '', kids, span);
1151
- }
1152
- struct(type, kids = []) {
1153
- return $mol_tree2.struct(type, kids, this.span);
1154
- }
1155
- clone(kids, span = this.span) {
1156
- return new $mol_tree2(this.type, this.value, kids, span);
1157
- }
1158
- text() {
1159
- var values = [];
1160
- for (var kid of this.kids) {
1161
- if (kid.type)
1162
- continue;
1163
- values.push(kid.value);
1164
- }
1165
- return this.value + values.join('\n');
1166
- }
1167
- static fromString(str, uri = 'unknown') {
1168
- return $$.$mol_tree2_from_string(str, uri);
1169
- }
1170
- toString() {
1171
- return $$.$mol_tree2_to_string(this);
1172
- }
1173
- insert(value, ...path) {
1174
- if (path.length === 0)
1175
- return value;
1176
- const type = path[0];
1177
- if (typeof type === 'string') {
1178
- let replaced = false;
1179
- const sub = this.kids.map((item, index) => {
1180
- if (item.type !== type)
1181
- return item;
1182
- replaced = true;
1183
- return item.insert(value, ...path.slice(1));
1184
- }).filter(Boolean);
1185
- if (!replaced && value) {
1186
- sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
1187
- }
1188
- return this.clone(sub);
1189
- }
1190
- else if (typeof type === 'number') {
1191
- const sub = this.kids.slice();
1192
- sub[type] = (sub[type] || this.list([]))
1193
- .insert(value, ...path.slice(1));
1194
- return this.clone(sub.filter(Boolean));
1195
- }
1196
- else {
1197
- const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
1198
- .map(item => item.insert(value, ...path.slice(1)))
1199
- .filter(Boolean);
1200
- return this.clone(kids);
1201
- }
870
+ function $mol_exec(dir, command, ...args) {
871
+ let [app, ...args0] = command.split(' ');
872
+ args = [...args0, ...args];
873
+ this.$mol_log3_come({
874
+ place: '$mol_exec',
875
+ dir: $node.path.relative('', dir),
876
+ message: 'Run',
877
+ command: `${app} ${args.join(' ')}`,
878
+ });
879
+ var res = $node['child_process'].spawnSync(app, args, {
880
+ cwd: $node.path.resolve(dir),
881
+ shell: true,
882
+ env: this.$mol_env(),
883
+ });
884
+ if (res.status || res.error) {
885
+ return $mol_fail(res.error || new Error(res.stderr.toString(), { cause: res.stdout }));
1202
886
  }
1203
- select(...path) {
1204
- let next = [this];
1205
- for (const type of path) {
1206
- if (!next.length)
1207
- break;
1208
- const prev = next;
1209
- next = [];
1210
- for (var item of prev) {
1211
- switch (typeof (type)) {
1212
- case 'string':
1213
- for (var child of item.kids) {
1214
- if (child.type == type) {
1215
- next.push(child);
1216
- }
1217
- }
1218
- break;
1219
- case 'number':
1220
- if (type < item.kids.length)
1221
- next.push(item.kids[type]);
887
+ if (!res.stdout)
888
+ res.stdout = Buffer.from([]);
889
+ return res;
890
+ }
891
+ $.$mol_exec = $mol_exec;
892
+ })($ || ($ = {}));
893
+
894
+ ;
895
+ "use strict";
896
+ var $;
897
+ (function ($) {
898
+ $.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
899
+ })($ || ($ = {}));
900
+
901
+ ;
902
+ "use strict";
903
+ var $;
904
+ (function ($) {
905
+ function $mol_dom_render_children(el, childNodes) {
906
+ const node_set = new Set(childNodes);
907
+ let nextNode = el.firstChild;
908
+ for (let view of childNodes) {
909
+ if (view == null)
910
+ continue;
911
+ if (view instanceof $mol_dom_context.Node) {
912
+ while (true) {
913
+ if (!nextNode) {
914
+ el.appendChild(view);
915
+ break;
916
+ }
917
+ if (nextNode == view) {
918
+ nextNode = nextNode.nextSibling;
919
+ break;
920
+ }
921
+ else {
922
+ if (node_set.has(nextNode)) {
923
+ el.insertBefore(view, nextNode);
1222
924
  break;
1223
- default: next.push(...item.kids);
925
+ }
926
+ else {
927
+ const nn = nextNode.nextSibling;
928
+ el.removeChild(nextNode);
929
+ nextNode = nn;
930
+ }
1224
931
  }
1225
932
  }
1226
933
  }
1227
- return this.list(next);
1228
- }
1229
- filter(path, value) {
1230
- const sub = this.kids.filter(item => {
1231
- var found = item.select(...path);
1232
- if (value === undefined) {
1233
- return Boolean(found.kids.length);
934
+ else {
935
+ if (nextNode && nextNode.nodeName === '#text') {
936
+ const str = String(view);
937
+ if (nextNode.nodeValue !== str)
938
+ nextNode.nodeValue = str;
939
+ nextNode = nextNode.nextSibling;
1234
940
  }
1235
941
  else {
1236
- return found.kids.some(child => child.value == value);
942
+ const textNode = $mol_dom_context.document.createTextNode(String(view));
943
+ el.insertBefore(textNode, nextNode);
1237
944
  }
1238
- });
1239
- return this.clone(sub);
1240
- }
1241
- hack_self(belt, context = {}) {
1242
- let handle = belt[this.type] || belt[''];
1243
- if (!handle || handle === Object.prototype[this.type]) {
1244
- handle = (input, belt, context) => [
1245
- input.clone(input.hack(belt, context), context.span)
1246
- ];
1247
945
  }
1248
- try {
1249
- return handle(this, belt, context);
1250
- }
1251
- catch (error) {
1252
- error.message += `\n${this.clone([])}${this.span}`;
1253
- $mol_fail_hidden(error);
1254
- }
1255
- }
1256
- hack(belt, context = {}) {
1257
- return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
1258
- }
1259
- error(message, Class = Error) {
1260
- return this.span.error(`${message}\n${this.clone([])}`, Class);
1261
946
  }
1262
- }
1263
- $.$mol_tree2 = $mol_tree2;
1264
- class $mol_tree2_empty extends $mol_tree2 {
1265
- constructor() {
1266
- super('', '', [], $mol_span.unknown);
947
+ while (nextNode) {
948
+ const currNode = nextNode;
949
+ nextNode = currNode.nextSibling;
950
+ el.removeChild(currNode);
1267
951
  }
1268
952
  }
1269
- $.$mol_tree2_empty = $mol_tree2_empty;
953
+ $.$mol_dom_render_children = $mol_dom_render_children;
1270
954
  })($ || ($ = {}));
1271
955
 
1272
956
  ;
1273
957
  "use strict";
1274
- var $;
1275
- (function ($) {
1276
- class $mol_error_syntax extends SyntaxError {
1277
- reason;
1278
- line;
1279
- span;
1280
- constructor(reason, line, span) {
1281
- super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
1282
- this.reason = reason;
1283
- this.line = line;
1284
- this.span = span;
1285
- }
1286
- }
1287
- $.$mol_error_syntax = $mol_error_syntax;
1288
- })($ || ($ = {}));
1289
958
 
1290
959
  ;
1291
960
  "use strict";
1292
961
  var $;
1293
962
  (function ($) {
1294
- function $mol_tree2_from_string(str, uri = '?') {
1295
- const span = $mol_span.entire(uri, str);
1296
- var root = $mol_tree2.list([], span);
1297
- var stack = [root];
1298
- var pos = 0, row = 0, min_indent = 0;
1299
- while (str.length > pos) {
1300
- var indent = 0;
1301
- var line_start = pos;
1302
- row++;
1303
- while (str.length > pos && str[pos] == '\t') {
1304
- indent++;
1305
- pos++;
963
+ $.$mol_jsx_prefix = '';
964
+ $.$mol_jsx_crumbs = '';
965
+ $.$mol_jsx_booked = null;
966
+ $.$mol_jsx_document = {
967
+ getElementById: () => null,
968
+ createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
969
+ createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
970
+ };
971
+ $.$mol_jsx_frag = '';
972
+ function $mol_jsx(Elem, props, ...childNodes) {
973
+ const id = props && props.id || '';
974
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
975
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
976
+ if (Elem && $.$mol_jsx_booked) {
977
+ if ($.$mol_jsx_booked.has(id)) {
978
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
1306
979
  }
1307
- if (!root.kids.length) {
1308
- min_indent = indent;
980
+ else {
981
+ $.$mol_jsx_booked.add(id);
1309
982
  }
1310
- indent -= min_indent;
1311
- if (indent < 0 || indent >= stack.length) {
1312
- const sp = span.span(row, 1, pos - line_start);
1313
- while (str.length > pos && str[pos] != '\n') {
1314
- pos++;
1315
- }
1316
- if (indent < 0) {
1317
- if (str.length > pos) {
1318
- this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
983
+ }
984
+ let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
985
+ if ($.$mol_jsx_prefix) {
986
+ const prefix_ext = $.$mol_jsx_prefix;
987
+ const booked_ext = $.$mol_jsx_booked;
988
+ const crumbs_ext = $.$mol_jsx_crumbs;
989
+ for (const field in props) {
990
+ const func = props[field];
991
+ if (typeof func !== 'function')
992
+ continue;
993
+ const wrapper = function (...args) {
994
+ const prefix = $.$mol_jsx_prefix;
995
+ const booked = $.$mol_jsx_booked;
996
+ const crumbs = $.$mol_jsx_crumbs;
997
+ try {
998
+ $.$mol_jsx_prefix = prefix_ext;
999
+ $.$mol_jsx_booked = booked_ext;
1000
+ $.$mol_jsx_crumbs = crumbs_ext;
1001
+ return func.call(this, ...args);
1319
1002
  }
1320
- }
1321
- else {
1322
- this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
1323
- }
1003
+ finally {
1004
+ $.$mol_jsx_prefix = prefix;
1005
+ $.$mol_jsx_booked = booked;
1006
+ $.$mol_jsx_crumbs = crumbs;
1007
+ }
1008
+ };
1009
+ $mol_func_name_from(wrapper, func);
1010
+ props[field] = wrapper;
1324
1011
  }
1325
- stack.length = indent + 1;
1326
- var parent = stack[indent];
1327
- while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
1328
- var error_start = pos;
1329
- while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
1330
- pos++;
1331
- }
1332
- if (pos > error_start) {
1333
- let line_end = str.indexOf('\n', pos);
1334
- if (line_end === -1)
1335
- line_end = str.length;
1336
- const sp = span.span(row, error_start - line_start + 1, pos - error_start);
1337
- this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
1338
- }
1339
- var type_start = pos;
1340
- while (str.length > pos &&
1341
- str[pos] != '\\' &&
1342
- str[pos] != ' ' &&
1343
- str[pos] != '\t' &&
1344
- str[pos] != '\n') {
1345
- pos++;
1346
- }
1347
- if (pos > type_start) {
1348
- let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
1349
- const parent_kids = parent.kids;
1350
- parent_kids.push(next);
1351
- parent = next;
1352
- }
1353
- if (str.length > pos && str[pos] == ' ') {
1354
- pos++;
1355
- }
1012
+ }
1013
+ if (typeof Elem !== 'string') {
1014
+ if ('prototype' in Elem) {
1015
+ const view = node && node[String(Elem)] || new Elem;
1016
+ Object.assign(view, props);
1017
+ view[Symbol.toStringTag] = guid;
1018
+ view.childNodes = childNodes;
1019
+ if (!view.ownerDocument)
1020
+ view.ownerDocument = $.$mol_jsx_document;
1021
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
1022
+ node = view.valueOf();
1023
+ node[String(Elem)] = view;
1024
+ return node;
1356
1025
  }
1357
- if (str.length > pos && str[pos] == '\\') {
1358
- var data_start = pos;
1359
- while (str.length > pos && str[pos] != '\n') {
1360
- pos++;
1026
+ else {
1027
+ const prefix = $.$mol_jsx_prefix;
1028
+ const booked = $.$mol_jsx_booked;
1029
+ const crumbs = $.$mol_jsx_crumbs;
1030
+ try {
1031
+ $.$mol_jsx_prefix = guid;
1032
+ $.$mol_jsx_booked = new Set;
1033
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
1034
+ return Elem(props, ...childNodes);
1035
+ }
1036
+ finally {
1037
+ $.$mol_jsx_prefix = prefix;
1038
+ $.$mol_jsx_booked = booked;
1039
+ $.$mol_jsx_crumbs = crumbs;
1361
1040
  }
1362
- let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
1363
- const parent_kids = parent.kids;
1364
- parent_kids.push(next);
1365
- parent = next;
1366
- }
1367
- if (str.length === pos && stack.length > 0) {
1368
- const sp = span.span(row, pos - line_start + 1, 1);
1369
- this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
1370
1041
  }
1371
- stack.push(parent);
1372
- pos++;
1373
- }
1374
- return root;
1375
- }
1376
- $.$mol_tree2_from_string = $mol_tree2_from_string;
1377
- })($ || ($ = {}));
1378
-
1379
- ;
1380
- "use strict";
1381
- var $;
1382
- (function ($) {
1383
- function $mol_tree2_from_json(json, span = $mol_span.unknown) {
1384
- if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
1385
- return new $mol_tree2(String(json), '', [], span);
1386
- }
1387
- if (typeof json === 'string') {
1388
- return $mol_tree2.data(json, [], span);
1389
- }
1390
- if (Array.isArray(json)) {
1391
- const sub = json.map(json => $mol_tree2_from_json(json, span));
1392
- return new $mol_tree2('/', '', sub, span);
1393
- }
1394
- if (ArrayBuffer.isView(json)) {
1395
- const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
1396
- return $mol_tree2.data(String.fromCharCode(...buf), [], span);
1397
- }
1398
- if (json instanceof Date) {
1399
- return new $mol_tree2('', json.toISOString(), [], span);
1400
- }
1401
- if (typeof json.toJSON === 'function') {
1402
- return $mol_tree2_from_json(json.toJSON());
1403
- }
1404
- if (json.toString !== Object.prototype.toString) {
1405
- return $mol_tree2.data(json.toString(), [], span);
1406
1042
  }
1407
- if (json instanceof Error) {
1408
- const { name, message, stack } = json;
1409
- json = { ...json, name, message, stack };
1043
+ if (!node) {
1044
+ node = Elem
1045
+ ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
1046
+ : $.$mol_jsx_document.createDocumentFragment();
1410
1047
  }
1411
- const sub = [];
1412
- for (var key in json) {
1413
- const val = json[key];
1414
- if (val === undefined)
1048
+ $mol_dom_render_children(node, [].concat(...childNodes));
1049
+ if (!Elem)
1050
+ return node;
1051
+ if (guid)
1052
+ node.id = guid;
1053
+ for (const key in props) {
1054
+ if (key === 'id')
1415
1055
  continue;
1416
- const subsub = $mol_tree2_from_json(val, span);
1417
- if (/^[^\n\t\\ ]+$/.test(key)) {
1418
- sub.push(new $mol_tree2(key, '', [subsub], span));
1056
+ if (typeof props[key] === 'string') {
1057
+ if (typeof node[key] === 'string')
1058
+ node[key] = props[key];
1059
+ node.setAttribute(key, props[key]);
1060
+ }
1061
+ else if (props[key] &&
1062
+ typeof props[key] === 'object' &&
1063
+ Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
1064
+ if (typeof node[key] === 'object') {
1065
+ Object.assign(node[key], props[key]);
1066
+ continue;
1067
+ }
1419
1068
  }
1420
1069
  else {
1421
- sub.push($mol_tree2.data(key, [subsub], span));
1070
+ node[key] = props[key];
1422
1071
  }
1423
1072
  }
1424
- return new $mol_tree2('*', '', sub, span);
1073
+ if ($.$mol_jsx_crumbs)
1074
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
1075
+ return node;
1425
1076
  }
1426
- $.$mol_tree2_from_json = $mol_tree2_from_json;
1077
+ $.$mol_jsx = $mol_jsx;
1427
1078
  })($ || ($ = {}));
1428
1079
 
1429
1080
  ;
1430
1081
  "use strict";
1431
1082
  var $;
1432
1083
  (function ($) {
1433
- class $mol_term_color {
1434
- static reset = this.ansi(0, 0);
1435
- static bold = this.ansi(1, 22);
1436
- static italic = this.ansi(3, 23);
1437
- static underline = this.ansi(4, 24);
1438
- static inverse = this.ansi(7, 27);
1439
- static hidden = this.ansi(8, 28);
1440
- static strike = this.ansi(9, 29);
1441
- static gray = this.ansi(90, 39);
1442
- static red = this.ansi(91, 39);
1443
- static green = this.ansi(92, 39);
1444
- static yellow = this.ansi(93, 39);
1445
- static blue = this.ansi(94, 39);
1446
- static magenta = this.ansi(95, 39);
1447
- static cyan = this.ansi(96, 39);
1448
- static Gray = (str) => this.inverse(this.gray(str));
1449
- static Red = (str) => this.inverse(this.red(str));
1450
- static Green = (str) => this.inverse(this.green(str));
1451
- static Yellow = (str) => this.inverse(this.yellow(str));
1452
- static Blue = (str) => this.inverse(this.blue(str));
1453
- static Magenta = (str) => this.inverse(this.magenta(str));
1454
- static Cyan = (str) => this.inverse(this.cyan(str));
1455
- static ansi(open, close) {
1456
- if (typeof process === 'undefined')
1457
- return String;
1458
- if (!process.stdout.isTTY)
1459
- return String;
1460
- const prefix = `\x1b[${open}m`;
1461
- const postfix = `\x1b[${close}m`;
1462
- const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
1463
- return function colorer(str) {
1464
- str = String(str);
1465
- if (str === '')
1466
- return str;
1467
- const suffix = str.replace(suffix_regexp, prefix);
1468
- return prefix + suffix + postfix;
1469
- };
1084
+ function $mol_jsx_attach(next, action) {
1085
+ const prev = $mol_jsx_document;
1086
+ try {
1087
+ $mol_jsx_document = next;
1088
+ return action();
1089
+ }
1090
+ finally {
1091
+ $mol_jsx_document = prev;
1470
1092
  }
1471
1093
  }
1472
- $.$mol_term_color = $mol_term_color;
1094
+ $.$mol_jsx_attach = $mol_jsx_attach;
1473
1095
  })($ || ($ = {}));
1474
1096
 
1475
1097
  ;
1476
1098
  "use strict";
1477
1099
  var $;
1478
1100
  (function ($) {
1479
- function $mol_log3_node_make(level, output, type, color) {
1480
- return function $mol_log3_logger(event) {
1481
- if (!event.time)
1482
- event = { time: new Date().toISOString(), ...event };
1483
- let tree = this.$mol_tree2_from_json(event);
1484
- tree = tree.struct(type, tree.kids);
1485
- let str = color(tree.toString());
1486
- this.console[level](str);
1487
- const self = this;
1488
- return () => self.console.groupEnd();
1489
- };
1490
- }
1491
- $.$mol_log3_node_make = $mol_log3_node_make;
1492
- $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
1493
- $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
1494
- $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
1495
- $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
1496
- $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
1497
- $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
1101
+ let $mol_wire_cursor;
1102
+ (function ($mol_wire_cursor) {
1103
+ $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
1104
+ $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
1105
+ $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
1106
+ $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
1107
+ })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
1498
1108
  })($ || ($ = {}));
1499
1109
 
1500
1110
  ;
1501
1111
  "use strict";
1502
1112
  var $;
1503
1113
  (function ($) {
1504
- class $mol_wire_task extends $mol_wire_fiber {
1505
- static getter(task) {
1506
- return function $mol_wire_task_get(host, args) {
1507
- const sub = $mol_wire_auto();
1508
- const existen = sub?.track_next();
1509
- reuse: if (existen) {
1510
- if (!existen.temp)
1511
- break reuse;
1512
- if (existen.host !== host)
1513
- break reuse;
1514
- if (existen.task !== task)
1515
- break reuse;
1516
- if (!$mol_compare_deep(existen.args, args))
1517
- break reuse;
1518
- return existen;
1519
- }
1520
- const next = new $mol_wire_task(`${host?.[Symbol.toStringTag] ?? host}.${task.name}<#>`, task, host, args);
1521
- if (existen?.temp) {
1522
- $$.$mol_log3_warn({
1523
- place: '$mol_wire_task',
1524
- message: `Non idempotency`,
1525
- existen,
1526
- next,
1527
- hint: 'Ignore it',
1528
- });
1529
- }
1530
- return next;
1531
- };
1114
+ class $mol_wire_pub extends Object {
1115
+ data = [];
1116
+ static get [Symbol.species]() {
1117
+ return Array;
1532
1118
  }
1533
- get temp() {
1534
- return true;
1119
+ sub_from = 0;
1120
+ get sub_list() {
1121
+ const res = [];
1122
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
1123
+ res.push(this.data[i]);
1124
+ }
1125
+ return res;
1535
1126
  }
1536
- complete() {
1537
- if ($mol_promise_like(this.cache))
1538
- return;
1539
- this.destructor();
1127
+ get sub_empty() {
1128
+ return this.sub_from === this.data.length;
1540
1129
  }
1541
- put(next) {
1542
- const prev = this.cache;
1543
- this.cache = next;
1544
- if ($mol_promise_like(next)) {
1545
- this.cursor = $mol_wire_cursor.fresh;
1546
- if (next !== prev)
1547
- this.emit();
1548
- return next;
1130
+ sub_on(sub, pub_pos) {
1131
+ const pos = this.data.length;
1132
+ this.data.push(sub, pub_pos);
1133
+ return pos;
1134
+ }
1135
+ sub_off(sub_pos) {
1136
+ if (!(sub_pos < this.data.length)) {
1137
+ $mol_fail(new Error(`Wrong pos ${sub_pos}`));
1549
1138
  }
1550
- this.cursor = $mol_wire_cursor.final;
1551
- if (this.sub_empty)
1552
- this.destructor();
1553
- else if (next !== prev)
1554
- this.emit();
1555
- return next;
1139
+ const end = this.data.length - 2;
1140
+ if (sub_pos !== end) {
1141
+ this.peer_move(end, sub_pos);
1142
+ }
1143
+ this.data.pop();
1144
+ this.data.pop();
1145
+ if (this.data.length === this.sub_from)
1146
+ this.reap();
1147
+ }
1148
+ reap() { }
1149
+ promote() {
1150
+ $mol_wire_auto()?.track_next(this);
1151
+ }
1152
+ fresh() { }
1153
+ complete() { }
1154
+ get incompleted() {
1155
+ return false;
1156
+ }
1157
+ emit(quant = $mol_wire_cursor.stale) {
1158
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
1159
+ ;
1160
+ this.data[i].absorb(quant);
1161
+ }
1162
+ }
1163
+ peer_move(from_pos, to_pos) {
1164
+ const peer = this.data[from_pos];
1165
+ const self_pos = this.data[from_pos + 1];
1166
+ this.data[to_pos] = peer;
1167
+ this.data[to_pos + 1] = self_pos;
1168
+ peer.peer_repos(self_pos, to_pos);
1169
+ }
1170
+ peer_repos(peer_pos, self_pos) {
1171
+ this.data[peer_pos + 1] = self_pos;
1556
1172
  }
1557
1173
  }
1558
- $.$mol_wire_task = $mol_wire_task;
1174
+ $.$mol_wire_pub = $mol_wire_pub;
1559
1175
  })($ || ($ = {}));
1560
1176
 
1177
+ ;
1178
+ "use strict";
1179
+
1561
1180
  ;
1562
1181
  "use strict";
1563
1182
  var $;
1564
1183
  (function ($) {
1565
- function $mol_wire_sync(obj) {
1566
- return new Proxy(obj, {
1567
- get(obj, field) {
1568
- const val = obj[field];
1569
- if (typeof val !== 'function')
1570
- return val;
1571
- const temp = $mol_wire_task.getter(val);
1572
- return function $mol_wire_sync(...args) {
1573
- const fiber = temp(obj, args);
1574
- return fiber.sync();
1575
- };
1576
- },
1577
- apply(obj, self, args) {
1578
- const temp = $mol_wire_task.getter(obj);
1579
- const fiber = temp(self, args);
1580
- return fiber.sync();
1581
- },
1582
- });
1184
+ $.$mol_wire_auto_sub = null;
1185
+ function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
1186
+ return $.$mol_wire_auto_sub = next;
1583
1187
  }
1584
- $.$mol_wire_sync = $mol_wire_sync;
1188
+ $.$mol_wire_auto = $mol_wire_auto;
1189
+ $.$mol_wire_affected = [];
1585
1190
  })($ || ($ = {}));
1586
1191
 
1587
1192
  ;
1588
1193
  "use strict";
1589
1194
  var $;
1590
1195
  (function ($) {
1591
- const catched = new WeakMap();
1592
- function $mol_fail_catch(error) {
1593
- if (typeof error !== 'object')
1594
- return false;
1595
- if ($mol_promise_like(error))
1596
- $mol_fail_hidden(error);
1597
- if (catched.get(error))
1598
- return false;
1599
- catched.set(error, true);
1600
- return true;
1196
+ $['devtoolsFormatters'] ||= [];
1197
+ function $mol_dev_format_register(config) {
1198
+ $['devtoolsFormatters'].push(config);
1601
1199
  }
1602
- $.$mol_fail_catch = $mol_fail_catch;
1200
+ $.$mol_dev_format_register = $mol_dev_format_register;
1201
+ $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
1202
+ $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
1203
+ $mol_dev_format_register({
1204
+ header: (val, config = false) => {
1205
+ if (config)
1206
+ return null;
1207
+ if (!val)
1208
+ return null;
1209
+ if ($.$mol_dev_format_head in val) {
1210
+ try {
1211
+ return val[$.$mol_dev_format_head]();
1212
+ }
1213
+ catch (error) {
1214
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
1215
+ }
1216
+ }
1217
+ if (typeof val === 'function') {
1218
+ return $mol_dev_format_native(val);
1219
+ }
1220
+ if (Symbol.toStringTag in val) {
1221
+ return $mol_dev_format_native(val);
1222
+ }
1223
+ return null;
1224
+ },
1225
+ hasBody: val => val[$.$mol_dev_format_body],
1226
+ body: val => val[$.$mol_dev_format_body](),
1227
+ });
1228
+ function $mol_dev_format_native(obj) {
1229
+ if (typeof obj === 'undefined')
1230
+ return $.$mol_dev_format_shade('undefined');
1231
+ return [
1232
+ 'object',
1233
+ {
1234
+ object: obj,
1235
+ config: true,
1236
+ },
1237
+ ];
1238
+ }
1239
+ $.$mol_dev_format_native = $mol_dev_format_native;
1240
+ function $mol_dev_format_auto(obj) {
1241
+ if (obj == null)
1242
+ return $.$mol_dev_format_shade(String(obj));
1243
+ return [
1244
+ 'object',
1245
+ {
1246
+ object: obj,
1247
+ config: false,
1248
+ },
1249
+ ];
1250
+ }
1251
+ $.$mol_dev_format_auto = $mol_dev_format_auto;
1252
+ function $mol_dev_format_element(element, style, ...content) {
1253
+ const styles = [];
1254
+ for (let key in style)
1255
+ styles.push(`${key} : ${style[key]}`);
1256
+ return [
1257
+ element,
1258
+ {
1259
+ style: styles.join(' ; '),
1260
+ },
1261
+ ...content,
1262
+ ];
1263
+ }
1264
+ $.$mol_dev_format_element = $mol_dev_format_element;
1265
+ function $mol_dev_format_span(style, ...content) {
1266
+ return $mol_dev_format_element('span', {
1267
+ ...style,
1268
+ }, ...content);
1269
+ }
1270
+ $.$mol_dev_format_span = $mol_dev_format_span;
1271
+ $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
1272
+ $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
1273
+ $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
1274
+ $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
1275
+ $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
1276
+ $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
1277
+ $.$mol_dev_format_accent = $mol_dev_format_span.bind(null, {
1278
+ 'color': 'magenta',
1279
+ });
1280
+ $.$mol_dev_format_strong = $mol_dev_format_span.bind(null, {
1281
+ 'font-weight': 'bold',
1282
+ });
1283
+ $.$mol_dev_format_string = $mol_dev_format_span.bind(null, {
1284
+ 'color': 'green',
1285
+ });
1286
+ $.$mol_dev_format_shade = $mol_dev_format_span.bind(null, {
1287
+ 'color': 'gray',
1288
+ });
1289
+ $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
1290
+ 'margin-left': '13px'
1291
+ });
1603
1292
  })($ || ($ = {}));
1604
1293
 
1605
1294
  ;
1606
1295
  "use strict";
1607
1296
  var $;
1608
1297
  (function ($) {
1609
- function $mol_fail_log(error) {
1610
- if ($mol_promise_like(error))
1611
- return false;
1612
- if (!$mol_fail_catch(error))
1613
- return false;
1614
- console.error(error);
1615
- return true;
1298
+ function $mol_const(value) {
1299
+ const getter = (() => value);
1300
+ getter['()'] = value;
1301
+ getter[Symbol.toStringTag] = value;
1302
+ getter[$mol_dev_format_head] = () => $mol_dev_format_span({}, '()=> ', $mol_dev_format_auto(value));
1303
+ return getter;
1616
1304
  }
1617
- $.$mol_fail_log = $mol_fail_log;
1305
+ $.$mol_const = $mol_const;
1618
1306
  })($ || ($ = {}));
1619
1307
 
1620
1308
  ;
1621
1309
  "use strict";
1622
- var $node = new Proxy({ require }, {
1623
- get(target, name, wrapper) {
1624
- if (target[name])
1625
- return target[name];
1626
- const mod = target.require('module');
1627
- if (mod.builtinModules.indexOf(name) >= 0)
1628
- return target.require(name);
1629
- if (name[0] === '.')
1630
- return target.require(name);
1631
- const path = target.require('path');
1632
- const fs = target.require('fs');
1633
- let dir = path.resolve('.');
1634
- const suffix = `./node_modules/${name}`;
1635
- const $$ = $;
1636
- while (!fs.existsSync(path.join(dir, suffix))) {
1637
- const parent = path.resolve(dir, '..');
1638
- if (parent === dir) {
1639
- $$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
1640
- try {
1641
- $$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
1310
+ var $;
1311
+ (function ($) {
1312
+ class $mol_wire_pub_sub extends $mol_wire_pub {
1313
+ pub_from = 0;
1314
+ cursor = $mol_wire_cursor.stale;
1315
+ get temp() {
1316
+ return false;
1317
+ }
1318
+ get pub_list() {
1319
+ const res = [];
1320
+ const max = this.cursor >= 0 ? this.cursor : this.sub_from;
1321
+ for (let i = this.pub_from; i < max; i += 2) {
1322
+ if (this.data[i])
1323
+ res.push(this.data[i]);
1324
+ }
1325
+ return res;
1326
+ }
1327
+ track_on() {
1328
+ this.cursor = this.pub_from;
1329
+ const sub = $mol_wire_auto();
1330
+ $mol_wire_auto(this);
1331
+ return sub;
1332
+ }
1333
+ promote() {
1334
+ if (this.cursor >= this.pub_from) {
1335
+ $mol_fail(new Error('Circular subscription'));
1336
+ }
1337
+ super.promote();
1338
+ }
1339
+ track_next(pub) {
1340
+ if (this.cursor < 0)
1341
+ $mol_fail(new Error('Promo to non begun sub'));
1342
+ if (this.cursor < this.sub_from) {
1343
+ const next = this.data[this.cursor];
1344
+ if (pub === undefined)
1345
+ return next ?? null;
1346
+ if (next === pub) {
1347
+ this.cursor += 2;
1348
+ return next;
1349
+ }
1350
+ if (next) {
1351
+ if (this.sub_from < this.data.length) {
1352
+ this.peer_move(this.sub_from, this.data.length);
1353
+ }
1354
+ this.peer_move(this.cursor, this.sub_from);
1355
+ this.sub_from += 2;
1356
+ }
1357
+ }
1358
+ else {
1359
+ if (pub === undefined)
1360
+ return null;
1361
+ if (this.sub_from < this.data.length) {
1362
+ this.peer_move(this.sub_from, this.data.length);
1363
+ }
1364
+ this.sub_from += 2;
1365
+ }
1366
+ this.data[this.cursor] = pub;
1367
+ this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
1368
+ this.cursor += 2;
1369
+ return pub;
1370
+ }
1371
+ track_off(sub) {
1372
+ $mol_wire_auto(sub);
1373
+ if (this.cursor < 0) {
1374
+ $mol_fail(new Error('End of non begun sub'));
1375
+ }
1376
+ for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
1377
+ const pub = this.data[cursor];
1378
+ pub.fresh();
1379
+ }
1380
+ this.cursor = $mol_wire_cursor.fresh;
1381
+ }
1382
+ pub_off(sub_pos) {
1383
+ this.data[sub_pos] = undefined;
1384
+ this.data[sub_pos + 1] = undefined;
1385
+ }
1386
+ destructor() {
1387
+ for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
1388
+ const sub = this.data[cursor];
1389
+ const pos = this.data[cursor + 1];
1390
+ sub.pub_off(pos);
1391
+ this.data.pop();
1392
+ this.data.pop();
1393
+ }
1394
+ this.cursor = this.pub_from;
1395
+ this.track_cut();
1396
+ this.cursor = $mol_wire_cursor.final;
1397
+ }
1398
+ track_cut() {
1399
+ if (this.cursor < this.pub_from) {
1400
+ $mol_fail(new Error('Cut of non begun sub'));
1401
+ }
1402
+ let tail = 0;
1403
+ for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
1404
+ const pub = this.data[cursor];
1405
+ pub?.sub_off(this.data[cursor + 1]);
1406
+ if (this.sub_from < this.data.length) {
1407
+ this.peer_move(this.data.length - 2, cursor);
1408
+ this.data.pop();
1409
+ this.data.pop();
1410
+ }
1411
+ else {
1412
+ ++tail;
1642
1413
  }
1643
- catch { }
1644
- break;
1645
1414
  }
1646
- else {
1647
- dir = parent;
1415
+ for (; tail; --tail) {
1416
+ this.data.pop();
1417
+ this.data.pop();
1648
1418
  }
1419
+ this.sub_from = this.cursor;
1649
1420
  }
1650
- try {
1651
- return $.$mol_wire_sync(target).require(name);
1652
- }
1653
- catch (error) {
1654
- if (error.code === 'ERR_REQUIRE_ESM') {
1655
- return importSync(name);
1421
+ complete() { }
1422
+ complete_pubs() {
1423
+ const limit = this.cursor < 0 ? this.sub_from : this.cursor;
1424
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1425
+ const pub = this.data[cursor];
1426
+ if (pub?.incompleted)
1427
+ return;
1428
+ }
1429
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1430
+ const pub = this.data[cursor];
1431
+ pub?.complete();
1656
1432
  }
1657
- $.$mol_fail_log(error);
1658
- return null;
1659
1433
  }
1660
- },
1661
- set(target, name, value) {
1662
- target[name] = value;
1663
- return true;
1664
- },
1665
- });
1666
- const importAsync = async (uri) => import(uri);
1667
- const importSync = $.$mol_wire_sync(importAsync);
1668
- require = (req => Object.assign(function require(name) {
1669
- return $node[name];
1670
- }, req))(require);
1671
-
1672
- ;
1673
- "use strict";
1674
- var $;
1675
- (function ($) {
1676
- function $mol_env() {
1677
- return {};
1434
+ absorb(quant = $mol_wire_cursor.stale) {
1435
+ if (this.cursor === $mol_wire_cursor.final)
1436
+ return;
1437
+ if (this.cursor >= quant)
1438
+ return;
1439
+ this.cursor = quant;
1440
+ this.emit($mol_wire_cursor.doubt);
1441
+ }
1442
+ [$mol_dev_format_head]() {
1443
+ return $mol_dev_format_native(this);
1444
+ }
1445
+ get pub_empty() {
1446
+ return this.sub_from === this.pub_from;
1447
+ }
1678
1448
  }
1679
- $.$mol_env = $mol_env;
1680
- })($ || ($ = {}));
1681
-
1682
- ;
1683
- "use strict";
1684
- var $;
1685
- (function ($) {
1686
- $.$mol_env = function $mol_env() {
1687
- return this.process.env;
1688
- };
1449
+ $.$mol_wire_pub_sub = $mol_wire_pub_sub;
1689
1450
  })($ || ($ = {}));
1690
1451
 
1691
1452
  ;
1692
1453
  "use strict";
1693
1454
  var $;
1694
1455
  (function ($) {
1695
- function $mol_exec(dir, command, ...args) {
1696
- let [app, ...args0] = command.split(' ');
1697
- args = [...args0, ...args];
1698
- this.$mol_log3_come({
1699
- place: '$mol_exec',
1700
- dir: $node.path.relative('', dir),
1701
- message: 'Run',
1702
- command: `${app} ${args.join(' ')}`,
1703
- });
1704
- var res = $node['child_process'].spawnSync(app, args, {
1705
- cwd: $node.path.resolve(dir),
1706
- shell: true,
1707
- env: this.$mol_env(),
1708
- });
1709
- if (res.status || res.error) {
1710
- return $mol_fail(res.error || new Error(res.stderr.toString(), { cause: res.stdout }));
1456
+ class $mol_after_timeout extends $mol_object2 {
1457
+ delay;
1458
+ task;
1459
+ id;
1460
+ constructor(delay, task) {
1461
+ super();
1462
+ this.delay = delay;
1463
+ this.task = task;
1464
+ this.id = setTimeout(task, delay);
1465
+ }
1466
+ destructor() {
1467
+ clearTimeout(this.id);
1711
1468
  }
1712
- if (!res.stdout)
1713
- res.stdout = Buffer.from([]);
1714
- return res;
1715
1469
  }
1716
- $.$mol_exec = $mol_exec;
1470
+ $.$mol_after_timeout = $mol_after_timeout;
1717
1471
  })($ || ($ = {}));
1718
1472
 
1719
1473
  ;
1720
1474
  "use strict";
1721
1475
  var $;
1722
1476
  (function ($) {
1723
- $.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
1477
+ class $mol_after_frame extends $mol_after_timeout {
1478
+ task;
1479
+ constructor(task) {
1480
+ super(16, task);
1481
+ this.task = task;
1482
+ }
1483
+ }
1484
+ $.$mol_after_frame = $mol_after_frame;
1724
1485
  })($ || ($ = {}));
1725
1486
 
1726
1487
  ;
1727
1488
  "use strict";
1728
1489
  var $;
1729
1490
  (function ($) {
1730
- function $mol_dom_render_children(el, childNodes) {
1731
- const node_set = new Set(childNodes);
1732
- let nextNode = el.firstChild;
1733
- for (let view of childNodes) {
1734
- if (view == null)
1735
- continue;
1736
- if (view instanceof $mol_dom_context.Node) {
1737
- while (true) {
1738
- if (!nextNode) {
1739
- el.appendChild(view);
1491
+ const handled = new WeakSet();
1492
+ class $mol_wire_fiber extends $mol_wire_pub_sub {
1493
+ task;
1494
+ host;
1495
+ static warm = true;
1496
+ static planning = new Set();
1497
+ static reaping = new Set();
1498
+ static plan_task = null;
1499
+ static plan() {
1500
+ if (this.plan_task)
1501
+ return;
1502
+ this.plan_task = new $mol_after_frame(() => {
1503
+ try {
1504
+ this.sync();
1505
+ }
1506
+ finally {
1507
+ $mol_wire_fiber.plan_task = null;
1508
+ }
1509
+ });
1510
+ }
1511
+ static sync() {
1512
+ while (this.planning.size) {
1513
+ for (const fiber of this.planning) {
1514
+ this.planning.delete(fiber);
1515
+ if (fiber.cursor >= 0)
1516
+ continue;
1517
+ if (fiber.cursor === $mol_wire_cursor.final)
1518
+ continue;
1519
+ fiber.fresh();
1520
+ }
1521
+ }
1522
+ while (this.reaping.size) {
1523
+ const fibers = this.reaping;
1524
+ this.reaping = new Set;
1525
+ for (const fiber of fibers) {
1526
+ if (!fiber.sub_empty)
1527
+ continue;
1528
+ fiber.destructor();
1529
+ }
1530
+ }
1531
+ }
1532
+ [Symbol.toStringTag];
1533
+ cache = undefined;
1534
+ get args() {
1535
+ return this.data.slice(0, this.pub_from);
1536
+ }
1537
+ result() {
1538
+ if ($mol_promise_like(this.cache))
1539
+ return;
1540
+ if (this.cache instanceof Error)
1541
+ return;
1542
+ return this.cache;
1543
+ }
1544
+ get incompleted() {
1545
+ return $mol_promise_like(this.cache);
1546
+ }
1547
+ field() {
1548
+ return this.task.name + '<>';
1549
+ }
1550
+ constructor(id, task, host, args) {
1551
+ super();
1552
+ this.task = task;
1553
+ this.host = host;
1554
+ if (args)
1555
+ this.data.push(...args);
1556
+ this.pub_from = this.sub_from = args?.length ?? 0;
1557
+ this[Symbol.toStringTag] = id;
1558
+ }
1559
+ plan() {
1560
+ $mol_wire_fiber.planning.add(this);
1561
+ $mol_wire_fiber.plan();
1562
+ }
1563
+ reap() {
1564
+ $mol_wire_fiber.reaping.add(this);
1565
+ $mol_wire_fiber.plan();
1566
+ }
1567
+ toString() {
1568
+ return this[Symbol.toStringTag];
1569
+ }
1570
+ toJSON() {
1571
+ return this[Symbol.toStringTag];
1572
+ }
1573
+ [$mol_dev_format_head]() {
1574
+ const cursor = {
1575
+ [$mol_wire_cursor.stale]: '🔴',
1576
+ [$mol_wire_cursor.doubt]: '🟡',
1577
+ [$mol_wire_cursor.fresh]: '🟢',
1578
+ [$mol_wire_cursor.final]: '🔵',
1579
+ }[this.cursor] ?? this.cursor.toString();
1580
+ return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
1581
+ ? $mol_dev_format_auto({
1582
+ [$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
1583
+ [$mol_dev_format_body]: () => $mol_dev_format_native(this),
1584
+ })
1585
+ : $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
1586
+ }
1587
+ get $() {
1588
+ return (this.host ?? this.task)['$'];
1589
+ }
1590
+ emit(quant = $mol_wire_cursor.stale) {
1591
+ if (this.sub_empty)
1592
+ this.plan();
1593
+ else
1594
+ super.emit(quant);
1595
+ }
1596
+ fresh() {
1597
+ if (this.cursor === $mol_wire_cursor.fresh)
1598
+ return;
1599
+ if (this.cursor === $mol_wire_cursor.final)
1600
+ return;
1601
+ check: if (this.cursor === $mol_wire_cursor.doubt) {
1602
+ for (let i = this.pub_from; i < this.sub_from; i += 2) {
1603
+ ;
1604
+ this.data[i]?.fresh();
1605
+ if (this.cursor !== $mol_wire_cursor.doubt)
1606
+ break check;
1607
+ }
1608
+ this.cursor = $mol_wire_cursor.fresh;
1609
+ return;
1610
+ }
1611
+ const bu = this.track_on();
1612
+ let result;
1613
+ try {
1614
+ switch (this.pub_from) {
1615
+ case 0:
1616
+ result = this.task.call(this.host);
1740
1617
  break;
1741
- }
1742
- if (nextNode == view) {
1743
- nextNode = nextNode.nextSibling;
1618
+ case 1:
1619
+ result = this.task.call(this.host, this.data[0]);
1744
1620
  break;
1745
- }
1746
- else {
1747
- if (node_set.has(nextNode)) {
1748
- el.insertBefore(view, nextNode);
1749
- break;
1750
- }
1751
- else {
1752
- const nn = nextNode.nextSibling;
1753
- el.removeChild(nextNode);
1754
- nextNode = nn;
1755
- }
1756
- }
1621
+ default:
1622
+ result = this.task.call(this.host, ...this.args);
1623
+ break;
1624
+ }
1625
+ if ($mol_promise_like(result) && !handled.has(result)) {
1626
+ const put = (res) => {
1627
+ if (this.cache === result)
1628
+ this.put(res);
1629
+ return res;
1630
+ };
1631
+ result = result.then(put, put);
1757
1632
  }
1758
1633
  }
1759
- else {
1760
- if (nextNode && nextNode.nodeName === '#text') {
1761
- const str = String(view);
1762
- if (nextNode.nodeValue !== str)
1763
- nextNode.nodeValue = str;
1764
- nextNode = nextNode.nextSibling;
1634
+ catch (error) {
1635
+ if (error instanceof Error || $mol_promise_like(error)) {
1636
+ result = error;
1765
1637
  }
1766
1638
  else {
1767
- const textNode = $mol_dom_context.document.createTextNode(String(view));
1768
- el.insertBefore(textNode, nextNode);
1639
+ result = new Error(String(error), { cause: error });
1640
+ }
1641
+ if ($mol_promise_like(result) && !handled.has(result)) {
1642
+ result = result.finally(() => {
1643
+ if (this.cache === result)
1644
+ this.absorb();
1645
+ });
1769
1646
  }
1770
1647
  }
1771
- }
1772
- while (nextNode) {
1773
- const currNode = nextNode;
1774
- nextNode = currNode.nextSibling;
1775
- el.removeChild(currNode);
1776
- }
1777
- }
1778
- $.$mol_dom_render_children = $mol_dom_render_children;
1779
- })($ || ($ = {}));
1780
-
1781
- ;
1782
- "use strict";
1783
-
1784
- ;
1785
- "use strict";
1786
- var $;
1787
- (function ($) {
1788
- $.$mol_jsx_prefix = '';
1789
- $.$mol_jsx_crumbs = '';
1790
- $.$mol_jsx_booked = null;
1791
- $.$mol_jsx_document = {
1792
- getElementById: () => null,
1793
- createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
1794
- createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
1795
- };
1796
- $.$mol_jsx_frag = '';
1797
- function $mol_jsx(Elem, props, ...childNodes) {
1798
- const id = props && props.id || '';
1799
- const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
1800
- const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
1801
- if (Elem && $.$mol_jsx_booked) {
1802
- if ($.$mol_jsx_booked.has(id)) {
1803
- $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
1648
+ if ($mol_promise_like(result) && !handled.has(result)) {
1649
+ result = Object.assign(result, {
1650
+ destructor: result['destructor'] ?? (() => { })
1651
+ });
1652
+ handled.add(result);
1653
+ const error = new Error(`Promise in ${this}`);
1654
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
1804
1655
  }
1805
- else {
1806
- $.$mol_jsx_booked.add(id);
1656
+ if (!$mol_promise_like(result)) {
1657
+ this.track_cut();
1807
1658
  }
1659
+ this.track_off(bu);
1660
+ this.put(result);
1808
1661
  }
1809
- let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
1810
- if ($.$mol_jsx_prefix) {
1811
- const prefix_ext = $.$mol_jsx_prefix;
1812
- const booked_ext = $.$mol_jsx_booked;
1813
- const crumbs_ext = $.$mol_jsx_crumbs;
1814
- for (const field in props) {
1815
- const func = props[field];
1816
- if (typeof func !== 'function')
1817
- continue;
1818
- const wrapper = function (...args) {
1819
- const prefix = $.$mol_jsx_prefix;
1820
- const booked = $.$mol_jsx_booked;
1821
- const crumbs = $.$mol_jsx_crumbs;
1822
- try {
1823
- $.$mol_jsx_prefix = prefix_ext;
1824
- $.$mol_jsx_booked = booked_ext;
1825
- $.$mol_jsx_crumbs = crumbs_ext;
1826
- return func.call(this, ...args);
1827
- }
1828
- finally {
1829
- $.$mol_jsx_prefix = prefix;
1830
- $.$mol_jsx_booked = booked;
1831
- $.$mol_jsx_crumbs = crumbs;
1832
- }
1833
- };
1834
- $mol_func_name_from(wrapper, func);
1835
- props[field] = wrapper;
1836
- }
1662
+ refresh() {
1663
+ this.cursor = $mol_wire_cursor.stale;
1664
+ this.fresh();
1837
1665
  }
1838
- if (typeof Elem !== 'string') {
1839
- if ('prototype' in Elem) {
1840
- const view = node && node[String(Elem)] || new Elem;
1841
- Object.assign(view, props);
1842
- view[Symbol.toStringTag] = guid;
1843
- view.childNodes = childNodes;
1844
- if (!view.ownerDocument)
1845
- view.ownerDocument = $.$mol_jsx_document;
1846
- view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
1847
- node = view.valueOf();
1848
- node[String(Elem)] = view;
1849
- return node;
1666
+ sync() {
1667
+ if (!$mol_wire_fiber.warm) {
1668
+ return this.result();
1850
1669
  }
1851
- else {
1852
- const prefix = $.$mol_jsx_prefix;
1853
- const booked = $.$mol_jsx_booked;
1854
- const crumbs = $.$mol_jsx_crumbs;
1855
- try {
1856
- $.$mol_jsx_prefix = guid;
1857
- $.$mol_jsx_booked = new Set;
1858
- $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
1859
- return Elem(props, ...childNodes);
1860
- }
1861
- finally {
1862
- $.$mol_jsx_prefix = prefix;
1863
- $.$mol_jsx_booked = booked;
1864
- $.$mol_jsx_crumbs = crumbs;
1865
- }
1670
+ this.promote();
1671
+ this.fresh();
1672
+ if (this.cache instanceof Error) {
1673
+ return $mol_fail_hidden(this.cache);
1866
1674
  }
1867
- }
1868
- if (!node) {
1869
- node = Elem
1870
- ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
1871
- : $.$mol_jsx_document.createDocumentFragment();
1872
- }
1873
- $mol_dom_render_children(node, [].concat(...childNodes));
1874
- if (!Elem)
1875
- return node;
1876
- if (guid)
1877
- node.id = guid;
1878
- for (const key in props) {
1879
- if (key === 'id')
1880
- continue;
1881
- if (typeof props[key] === 'string') {
1882
- if (typeof node[key] === 'string')
1883
- node[key] = props[key];
1884
- node.setAttribute(key, props[key]);
1675
+ if ($mol_promise_like(this.cache)) {
1676
+ return $mol_fail_hidden(this.cache);
1885
1677
  }
1886
- else if (props[key] &&
1887
- typeof props[key] === 'object' &&
1888
- Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
1889
- if (typeof node[key] === 'object') {
1890
- Object.assign(node[key], props[key]);
1891
- continue;
1678
+ return this.cache;
1679
+ }
1680
+ async async() {
1681
+ while (true) {
1682
+ this.fresh();
1683
+ if (this.cache instanceof Error) {
1684
+ $mol_fail_hidden(this.cache);
1685
+ }
1686
+ if (!$mol_promise_like(this.cache))
1687
+ return this.cache;
1688
+ await Promise.race([this.cache, this.step()]);
1689
+ if (!$mol_promise_like(this.cache))
1690
+ return this.cache;
1691
+ if (this.cursor === $mol_wire_cursor.final) {
1692
+ await new Promise(() => { });
1892
1693
  }
1893
1694
  }
1894
- else {
1895
- node[key] = props[key];
1896
- }
1897
- }
1898
- if ($.$mol_jsx_crumbs)
1899
- node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
1900
- return node;
1901
- }
1902
- $.$mol_jsx = $mol_jsx;
1903
- })($ || ($ = {}));
1904
-
1905
- ;
1906
- "use strict";
1907
- var $;
1908
- (function ($) {
1909
- function $mol_jsx_attach(next, action) {
1910
- const prev = $mol_jsx_document;
1911
- try {
1912
- $mol_jsx_document = next;
1913
- return action();
1914
- }
1915
- finally {
1916
- $mol_jsx_document = prev;
1695
+ }
1696
+ step() {
1697
+ return new Promise(done => {
1698
+ const sub = new $mol_wire_pub_sub;
1699
+ const prev = sub.track_on();
1700
+ sub.track_next(this);
1701
+ sub.track_off(prev);
1702
+ sub.absorb = () => {
1703
+ done(null);
1704
+ sub.destructor();
1705
+ };
1706
+ });
1917
1707
  }
1918
1708
  }
1919
- $.$mol_jsx_attach = $mol_jsx_attach;
1920
- })($ || ($ = {}));
1921
-
1922
- ;
1923
- "use strict";
1924
- var $;
1925
- (function ($) {
1926
- function $mol_const(value) {
1927
- const getter = (() => value);
1928
- getter['()'] = value;
1929
- getter[Symbol.toStringTag] = value;
1930
- getter[$mol_dev_format_head] = () => $mol_dev_format_span({}, '()=> ', $mol_dev_format_auto(value));
1931
- return getter;
1932
- }
1933
- $.$mol_const = $mol_const;
1709
+ $.$mol_wire_fiber = $mol_wire_fiber;
1934
1710
  })($ || ($ = {}));
1935
1711
 
1936
1712
  ;
@@ -1995,6 +1771,206 @@ var $;
1995
1771
  $.$mol_key = $mol_key;
1996
1772
  })($ || ($ = {}));
1997
1773
 
1774
+ ;
1775
+ "use strict";
1776
+ var $;
1777
+ (function ($) {
1778
+ $.$mol_compare_deep_cache = new WeakMap();
1779
+ function $mol_compare_deep(left, right) {
1780
+ if (Object.is(left, right))
1781
+ return true;
1782
+ if (left === null)
1783
+ return false;
1784
+ if (right === null)
1785
+ return false;
1786
+ if (typeof left !== 'object')
1787
+ return false;
1788
+ if (typeof right !== 'object')
1789
+ return false;
1790
+ const left_proto = Reflect.getPrototypeOf(left);
1791
+ const right_proto = Reflect.getPrototypeOf(right);
1792
+ if (left_proto !== right_proto)
1793
+ return false;
1794
+ if (left instanceof Boolean)
1795
+ return Object.is(left.valueOf(), right['valueOf']());
1796
+ if (left instanceof Number)
1797
+ return Object.is(left.valueOf(), right['valueOf']());
1798
+ if (left instanceof String)
1799
+ return Object.is(left.valueOf(), right['valueOf']());
1800
+ if (left instanceof Date)
1801
+ return Object.is(left.valueOf(), right['valueOf']());
1802
+ if (left instanceof RegExp)
1803
+ return left.source === right.source && left.flags === right.flags;
1804
+ if (left instanceof Error)
1805
+ return left.message === right.message && left.stack === right.stack;
1806
+ let left_cache = $.$mol_compare_deep_cache.get(left);
1807
+ if (left_cache) {
1808
+ const right_cache = left_cache.get(right);
1809
+ if (typeof right_cache === 'boolean')
1810
+ return right_cache;
1811
+ }
1812
+ else {
1813
+ left_cache = new WeakMap([[right, true]]);
1814
+ $.$mol_compare_deep_cache.set(left, left_cache);
1815
+ }
1816
+ let result;
1817
+ try {
1818
+ if (!left_proto)
1819
+ result = compare_pojo(left, right);
1820
+ else if (!Reflect.getPrototypeOf(left_proto))
1821
+ result = compare_pojo(left, right);
1822
+ else if (Symbol.toPrimitive in left)
1823
+ result = compare_primitive(left, right);
1824
+ else if (Array.isArray(left))
1825
+ result = compare_array(left, right);
1826
+ else if (left instanceof Set)
1827
+ result = compare_set(left, right);
1828
+ else if (left instanceof Map)
1829
+ result = compare_map(left, right);
1830
+ else if (ArrayBuffer.isView(left))
1831
+ result = compare_buffer(left, right);
1832
+ else if (Symbol.iterator in left)
1833
+ result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
1834
+ else
1835
+ result = false;
1836
+ }
1837
+ finally {
1838
+ left_cache.set(right, result);
1839
+ }
1840
+ return result;
1841
+ }
1842
+ $.$mol_compare_deep = $mol_compare_deep;
1843
+ function compare_array(left, right) {
1844
+ const len = left.length;
1845
+ if (len !== right.length)
1846
+ return false;
1847
+ for (let i = 0; i < len; ++i) {
1848
+ if (!$mol_compare_deep(left[i], right[i]))
1849
+ return false;
1850
+ }
1851
+ return true;
1852
+ }
1853
+ function compare_buffer(left, right) {
1854
+ const len = left.byteLength;
1855
+ if (len !== right.byteLength)
1856
+ return false;
1857
+ if (left instanceof DataView)
1858
+ return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
1859
+ for (let i = 0; i < len; ++i) {
1860
+ if (left[i] !== right[i])
1861
+ return false;
1862
+ }
1863
+ return true;
1864
+ }
1865
+ function compare_iterator(left, right) {
1866
+ while (true) {
1867
+ const left_next = left.next();
1868
+ const right_next = right.next();
1869
+ if (left_next.done !== right_next.done)
1870
+ return false;
1871
+ if (left_next.done)
1872
+ break;
1873
+ if (!$mol_compare_deep(left_next.value, right_next.value))
1874
+ return false;
1875
+ }
1876
+ return true;
1877
+ }
1878
+ function compare_set(left, right) {
1879
+ if (left.size !== right.size)
1880
+ return false;
1881
+ return compare_iterator(left.values(), right.values());
1882
+ }
1883
+ function compare_map(left, right) {
1884
+ if (left.size !== right.size)
1885
+ return false;
1886
+ return compare_iterator(left.keys(), right.keys())
1887
+ && compare_iterator(left.values(), right.values());
1888
+ }
1889
+ function compare_pojo(left, right) {
1890
+ const left_keys = Object.getOwnPropertyNames(left);
1891
+ const right_keys = Object.getOwnPropertyNames(right);
1892
+ if (!compare_array(left_keys, right_keys))
1893
+ return false;
1894
+ for (let key of left_keys) {
1895
+ if (!$mol_compare_deep(left[key], right[key]))
1896
+ return false;
1897
+ }
1898
+ const left_syms = Object.getOwnPropertySymbols(left);
1899
+ const right_syms = Object.getOwnPropertySymbols(right);
1900
+ if (!compare_array(left_syms, right_syms))
1901
+ return false;
1902
+ for (let key of left_syms) {
1903
+ if (!$mol_compare_deep(left[key], right[key]))
1904
+ return false;
1905
+ }
1906
+ return true;
1907
+ }
1908
+ function compare_primitive(left, right) {
1909
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
1910
+ }
1911
+ })($ || ($ = {}));
1912
+
1913
+ ;
1914
+ "use strict";
1915
+ var $;
1916
+ (function ($) {
1917
+ class $mol_wire_task extends $mol_wire_fiber {
1918
+ static getter(task) {
1919
+ return function $mol_wire_task_get(host, args) {
1920
+ const sub = $mol_wire_auto();
1921
+ const existen = sub?.track_next();
1922
+ reuse: if (existen) {
1923
+ if (!existen.temp)
1924
+ break reuse;
1925
+ if (existen.host !== host)
1926
+ break reuse;
1927
+ if (existen.task !== task)
1928
+ break reuse;
1929
+ if (!$mol_compare_deep(existen.args, args))
1930
+ break reuse;
1931
+ return existen;
1932
+ }
1933
+ const next = new $mol_wire_task(`${host?.[Symbol.toStringTag] ?? host}.${task.name}<#>`, task, host, args);
1934
+ if (existen?.temp) {
1935
+ $$.$mol_log3_warn({
1936
+ place: '$mol_wire_task',
1937
+ message: `Non idempotency`,
1938
+ existen,
1939
+ next,
1940
+ hint: 'Ignore it',
1941
+ });
1942
+ }
1943
+ return next;
1944
+ };
1945
+ }
1946
+ get temp() {
1947
+ return true;
1948
+ }
1949
+ complete() {
1950
+ if ($mol_promise_like(this.cache))
1951
+ return;
1952
+ this.destructor();
1953
+ }
1954
+ put(next) {
1955
+ const prev = this.cache;
1956
+ this.cache = next;
1957
+ if ($mol_promise_like(next)) {
1958
+ this.cursor = $mol_wire_cursor.fresh;
1959
+ if (next !== prev)
1960
+ this.emit();
1961
+ return next;
1962
+ }
1963
+ this.cursor = $mol_wire_cursor.final;
1964
+ if (this.sub_empty)
1965
+ this.destructor();
1966
+ else if (next !== prev)
1967
+ this.emit();
1968
+ return next;
1969
+ }
1970
+ }
1971
+ $.$mol_wire_task = $mol_wire_task;
1972
+ })($ || ($ = {}));
1973
+
1998
1974
  ;
1999
1975
  "use strict";
2000
1976
  var $;
@@ -2371,6 +2347,32 @@ var $;
2371
2347
  $.$mol_wire_watch = $mol_wire_watch;
2372
2348
  })($ || ($ = {}));
2373
2349
 
2350
+ ;
2351
+ "use strict";
2352
+ var $;
2353
+ (function ($) {
2354
+ function $mol_wire_sync(obj) {
2355
+ return new Proxy(obj, {
2356
+ get(obj, field) {
2357
+ const val = obj[field];
2358
+ if (typeof val !== 'function')
2359
+ return val;
2360
+ const temp = $mol_wire_task.getter(val);
2361
+ return function $mol_wire_sync(...args) {
2362
+ const fiber = temp(obj, args);
2363
+ return fiber.sync();
2364
+ };
2365
+ },
2366
+ apply(obj, self, args) {
2367
+ const temp = $mol_wire_task.getter(obj);
2368
+ const fiber = temp(self, args);
2369
+ return fiber.sync();
2370
+ },
2371
+ });
2372
+ }
2373
+ $.$mol_wire_sync = $mol_wire_sync;
2374
+ })($ || ($ = {}));
2375
+
2374
2376
  ;
2375
2377
  "use strict";
2376
2378
  var $;
@@ -2879,37 +2881,19 @@ var $;
2879
2881
 
2880
2882
  ;
2881
2883
  "use strict";
2884
+ var $;
2885
+ (function ($_1) {
2886
+ $mol_test_mocks.push($ => $.$mol_fail_log = () => false);
2887
+ })($ || ($ = {}));
2882
2888
 
2883
2889
  ;
2884
2890
  "use strict";
2885
2891
 
2886
- ;
2887
- "use strict";
2888
-
2889
- ;
2890
- "use strict";
2891
- var $;
2892
- (function ($_1) {
2893
- $mol_test({
2894
- 'test types'($) {
2895
- class A {
2896
- static a() {
2897
- return Promise.resolve('');
2898
- }
2899
- static b() {
2900
- return $mol_wire_sync(this).a();
2901
- }
2902
- }
2903
- },
2904
- });
2905
- })($ || ($ = {}));
2892
+ ;
2893
+ "use strict";
2906
2894
 
2907
2895
  ;
2908
2896
  "use strict";
2909
- var $;
2910
- (function ($_1) {
2911
- $mol_test_mocks.push($ => $.$mol_fail_log = () => false);
2912
- })($ || ($ = {}));
2913
2897
 
2914
2898
  ;
2915
2899
  "use strict";
@@ -3212,304 +3196,22 @@ var $;
3212
3196
  .toString(), 'a b x\n');
3213
3197
  $mol_assert_equal($.$mol_tree2_from_string('a b\n')
3214
3198
  .insert($mol_tree2.struct('x'), null, null, null, null)
3215
- .toString(), 'a b \\\n\tx\n');
3216
- },
3217
- 'deleting'($) {
3218
- $mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
3219
- .insert(null, 'a', 'b', 'c')
3220
- .toString(), 'a b\n');
3221
- $mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
3222
- .insert(null, 0, 0, 0)
3223
- .toString(), 'a b\n');
3224
- },
3225
- 'hack'($) {
3226
- const res = $.$mol_tree2_from_string(`foo bar xxx\n`)
3227
- .hack({
3228
- 'bar': (input, belt) => [input.struct('777', input.hack(belt))],
3229
- });
3230
- $mol_assert_equal(res.toString(), 'foo 777 xxx\n');
3231
- },
3232
- });
3233
- })($ || ($ = {}));
3234
-
3235
- ;
3236
- "use strict";
3237
- var $;
3238
- (function ($_1) {
3239
- $mol_test({
3240
- 'tree parsing'($) {
3241
- $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids.length, 2);
3242
- $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids[1].type, "bar");
3243
- $mol_assert_equal($.$mol_tree2_from_string("foo\n\n\n").kids.length, 1);
3244
- $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids.length, 2);
3245
- $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids[1].value, "bar");
3246
- $mol_assert_equal($.$mol_tree2_from_string("foo bar \\pol\n").kids[0].kids[0].kids[0].value, "pol");
3247
- $mol_assert_equal($.$mol_tree2_from_string("foo bar\n\t\\pol\n\t\\men\n").kids[0].kids[0].kids[1].value, "men");
3248
- $mol_assert_equal($.$mol_tree2_from_string('foo bar \\text\n').toString(), 'foo bar \\text\n');
3249
- },
3250
- 'Too many tabs'($) {
3251
- const tree = `
3252
- foo
3253
- bar
3254
- `;
3255
- $mol_assert_fail(() => {
3256
- $.$mol_tree2_from_string(tree, 'test');
3257
- }, 'Too many tabs\ntest#3:1/6\n!!!!!!\n\t\t\t\t\t\tbar');
3258
- },
3259
- 'Too few tabs'($) {
3260
- const tree = `
3261
- foo
3262
- bar
3263
- `;
3264
- $mol_assert_fail(() => {
3265
- $.$mol_tree2_from_string(tree, 'test');
3266
- }, 'Too few tabs\ntest#3:1/4\n!!!!\n\t\t\t\tbar');
3267
- },
3268
- 'Wrong nodes separator at start'($) {
3269
- const tree = `foo\n \tbar\n`;
3270
- $mol_assert_fail(() => {
3271
- $.$mol_tree2_from_string(tree, 'test');
3272
- }, 'Wrong nodes separator\ntest#2:1/2\n!!\n \tbar');
3273
- },
3274
- 'Wrong nodes separator in the middle'($) {
3275
- const tree = `foo bar\n`;
3276
- $mol_assert_fail(() => {
3277
- $.$mol_tree2_from_string(tree, 'test');
3278
- }, 'Wrong nodes separator\ntest#1:5/1\n !\nfoo bar');
3279
- },
3280
- 'Unexpected EOF, LF required'($) {
3281
- const tree = ` foo`;
3282
- $mol_assert_fail(() => {
3283
- $.$mol_tree2_from_string(tree, 'test');
3284
- }, 'Unexpected EOF, LF required\ntest#1:5/1\n !\n foo');
3285
- },
3286
- 'Errors skip and collect'($) {
3287
- const tree = `foo bar`;
3288
- const errors = [];
3289
- const $$ = $.$mol_ambient({
3290
- $mol_fail: (error) => {
3291
- errors.push(error.message);
3292
- return null;
3293
- }
3294
- });
3295
- const res = $$.$mol_tree2_from_string(tree, 'test');
3296
- $mol_assert_like(errors, [
3297
- 'Wrong nodes separator\ntest#1:5/1\n !\nfoo bar',
3298
- 'Unexpected EOF, LF required\ntest#1:9/1\n !\nfoo bar',
3299
- ]);
3300
- $mol_assert_equal(res.toString(), 'foo bar\n');
3301
- },
3302
- });
3303
- })($ || ($ = {}));
3304
-
3305
- ;
3306
- "use strict";
3307
- var $;
3308
- (function ($) {
3309
- $mol_test({
3310
- 'fromJSON'() {
3311
- $mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
3312
- $mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
3313
- $mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
3314
- $mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
3315
- $mol_assert_equal($mol_tree2_from_json(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
3316
- $mol_assert_equal($mol_tree2_from_json({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
3317
- },
3318
- });
3319
- })($ || ($ = {}));
3320
-
3321
- ;
3322
- "use strict";
3323
- var $;
3324
- (function ($_1) {
3325
- $mol_test({
3326
- 'Collect deps'() {
3327
- const pub1 = new $mol_wire_pub;
3328
- const pub2 = new $mol_wire_pub;
3329
- const sub = new $mol_wire_pub_sub;
3330
- const bu1 = sub.track_on();
3331
- try {
3332
- pub1.promote();
3333
- pub2.promote();
3334
- pub2.promote();
3335
- }
3336
- finally {
3337
- sub.track_cut();
3338
- sub.track_off(bu1);
3339
- }
3340
- pub1.emit();
3341
- pub2.emit();
3342
- $mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
3343
- const bu2 = sub.track_on();
3344
- try {
3345
- pub1.promote();
3346
- pub1.promote();
3347
- pub2.promote();
3348
- }
3349
- finally {
3350
- sub.track_cut();
3351
- sub.track_off(bu2);
3352
- }
3353
- pub1.emit();
3354
- pub2.emit();
3355
- $mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
3356
- },
3357
- 'cyclic detection'($) {
3358
- const sub1 = new $mol_wire_pub_sub;
3359
- const sub2 = new $mol_wire_pub_sub;
3360
- const bu1 = sub1.track_on();
3361
- try {
3362
- const bu2 = sub2.track_on();
3363
- try {
3364
- $mol_assert_fail(() => sub1.promote(), 'Circular subscription');
3365
- }
3366
- finally {
3367
- sub2.track_cut();
3368
- sub2.track_off(bu2);
3369
- }
3370
- }
3371
- finally {
3372
- sub1.track_cut();
3373
- sub1.track_off(bu1);
3374
- }
3375
- },
3376
- });
3377
- })($ || ($ = {}));
3378
-
3379
- ;
3380
- "use strict";
3381
- var $;
3382
- (function ($) {
3383
- $.$mol_after_mock_queue = [];
3384
- function $mol_after_mock_warp() {
3385
- const queue = $.$mol_after_mock_queue.splice(0);
3386
- for (const task of queue)
3387
- task();
3388
- }
3389
- $.$mol_after_mock_warp = $mol_after_mock_warp;
3390
- class $mol_after_mock_commmon extends $mol_object2 {
3391
- task;
3392
- promise = Promise.resolve();
3393
- cancelled = false;
3394
- id;
3395
- constructor(task) {
3396
- super();
3397
- this.task = task;
3398
- $.$mol_after_mock_queue.push(task);
3399
- }
3400
- destructor() {
3401
- const index = $.$mol_after_mock_queue.indexOf(this.task);
3402
- if (index >= 0)
3403
- $.$mol_after_mock_queue.splice(index, 1);
3404
- }
3405
- }
3406
- $.$mol_after_mock_commmon = $mol_after_mock_commmon;
3407
- class $mol_after_mock_timeout extends $mol_after_mock_commmon {
3408
- delay;
3409
- constructor(delay, task) {
3410
- super(task);
3411
- this.delay = delay;
3412
- }
3413
- }
3414
- $.$mol_after_mock_timeout = $mol_after_mock_timeout;
3415
- })($ || ($ = {}));
3416
-
3417
- ;
3418
- "use strict";
3419
- var $;
3420
- (function ($_1) {
3421
- $mol_test_mocks.push($ => {
3422
- $.$mol_after_timeout = $mol_after_mock_timeout;
3423
- });
3424
- })($ || ($ = {}));
3425
-
3426
- ;
3427
- "use strict";
3428
- var $;
3429
- (function ($_1) {
3430
- $mol_test_mocks.push($ => {
3431
- $.$mol_after_frame = $mol_after_mock_commmon;
3432
- });
3433
- })($ || ($ = {}));
3434
-
3435
- ;
3436
- "use strict";
3437
- var $;
3438
- (function ($) {
3439
- $mol_test({
3440
- 'Sync execution'() {
3441
- class Sync extends $mol_object2 {
3442
- static calc(a, b) {
3443
- return a + b;
3444
- }
3445
- }
3446
- __decorate([
3447
- $mol_wire_method
3448
- ], Sync, "calc", null);
3449
- $mol_assert_equal(Sync.calc(1, 2), 3);
3450
- },
3451
- async 'async <=> sync'() {
3452
- class SyncAsync extends $mol_object2 {
3453
- static async val(a) {
3454
- return a;
3455
- }
3456
- static sum(a, b) {
3457
- const syn = $mol_wire_sync(this);
3458
- return syn.val(a) + syn.val(b);
3459
- }
3460
- static async calc(a, b) {
3461
- return 5 + await $mol_wire_async(this).sum(a, b);
3462
- }
3463
- }
3464
- $mol_assert_equal(await SyncAsync.calc(1, 2), 8);
3199
+ .toString(), 'a b \\\n\tx\n');
3465
3200
  },
3466
- async 'Idempotence control'() {
3467
- class Idempotence extends $mol_object2 {
3468
- static logs_idemp = 0;
3469
- static logs_unidemp = 0;
3470
- static log_idemp() {
3471
- this.logs_idemp += 1;
3472
- }
3473
- static log_unidemp() {
3474
- this.logs_unidemp += 1;
3475
- }
3476
- static async val(a) {
3477
- return a;
3478
- }
3479
- static sum(a, b) {
3480
- this.log_idemp();
3481
- this.log_unidemp();
3482
- const syn = $mol_wire_sync(this);
3483
- return syn.val(a) + syn.val(b);
3484
- }
3485
- static async calc(a, b) {
3486
- return 5 + await $mol_wire_async(this).sum(a, b);
3487
- }
3488
- }
3489
- __decorate([
3490
- $mol_wire_method
3491
- ], Idempotence, "log_idemp", null);
3492
- $mol_assert_equal(await Idempotence.calc(1, 2), 8);
3493
- $mol_assert_equal(Idempotence.logs_idemp, 1);
3494
- $mol_assert_equal(Idempotence.logs_unidemp, 3);
3201
+ 'deleting'($) {
3202
+ $mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
3203
+ .insert(null, 'a', 'b', 'c')
3204
+ .toString(), 'a b\n');
3205
+ $mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
3206
+ .insert(null, 0, 0, 0)
3207
+ .toString(), 'a b\n');
3495
3208
  },
3496
- async 'Error handling'() {
3497
- class Handle extends $mol_object2 {
3498
- static async sum(a, b) {
3499
- $mol_fail(new Error('test error ' + (a + b)));
3500
- }
3501
- static check() {
3502
- try {
3503
- return $mol_wire_sync(Handle).sum(1, 2);
3504
- }
3505
- catch (error) {
3506
- if ($mol_promise_like(error))
3507
- $mol_fail_hidden(error);
3508
- $mol_assert_equal(error.message, 'test error 3');
3509
- }
3510
- }
3511
- }
3512
- await $mol_wire_async(Handle).check();
3209
+ 'hack'($) {
3210
+ const res = $.$mol_tree2_from_string(`foo bar xxx\n`)
3211
+ .hack({
3212
+ 'bar': (input, belt) => [input.struct('777', input.hack(belt))],
3213
+ });
3214
+ $mol_assert_equal(res.toString(), 'foo 777 xxx\n');
3513
3215
  },
3514
3216
  });
3515
3217
  })($ || ($ = {}));
@@ -3519,50 +3221,83 @@ var $;
3519
3221
  var $;
3520
3222
  (function ($_1) {
3521
3223
  $mol_test({
3522
- 'test types'($) {
3523
- class A {
3524
- static a() {
3525
- return '';
3526
- }
3527
- static b() {
3528
- return $mol_wire_async(this).a();
3529
- }
3530
- }
3224
+ 'tree parsing'($) {
3225
+ $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids.length, 2);
3226
+ $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids[1].type, "bar");
3227
+ $mol_assert_equal($.$mol_tree2_from_string("foo\n\n\n").kids.length, 1);
3228
+ $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids.length, 2);
3229
+ $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids[1].value, "bar");
3230
+ $mol_assert_equal($.$mol_tree2_from_string("foo bar \\pol\n").kids[0].kids[0].kids[0].value, "pol");
3231
+ $mol_assert_equal($.$mol_tree2_from_string("foo bar\n\t\\pol\n\t\\men\n").kids[0].kids[0].kids[1].value, "men");
3232
+ $mol_assert_equal($.$mol_tree2_from_string('foo bar \\text\n').toString(), 'foo bar \\text\n');
3531
3233
  },
3532
- async 'Latest method calls wins'($) {
3533
- class NameLogger extends $mol_object2 {
3534
- static $ = $;
3535
- static first = [];
3536
- static last = [];
3537
- static send(next) {
3538
- $mol_wire_sync(this.first).push(next);
3539
- this.$.$mol_wait_timeout(0);
3540
- this.last.push(next);
3234
+ 'Too many tabs'($) {
3235
+ const tree = `
3236
+ foo
3237
+ bar
3238
+ `;
3239
+ $mol_assert_fail(() => {
3240
+ $.$mol_tree2_from_string(tree, 'test');
3241
+ }, 'Too many tabs\ntest#3:1/6\n!!!!!!\n\t\t\t\t\t\tbar');
3242
+ },
3243
+ 'Too few tabs'($) {
3244
+ const tree = `
3245
+ foo
3246
+ bar
3247
+ `;
3248
+ $mol_assert_fail(() => {
3249
+ $.$mol_tree2_from_string(tree, 'test');
3250
+ }, 'Too few tabs\ntest#3:1/4\n!!!!\n\t\t\t\tbar');
3251
+ },
3252
+ 'Wrong nodes separator at start'($) {
3253
+ const tree = `foo\n \tbar\n`;
3254
+ $mol_assert_fail(() => {
3255
+ $.$mol_tree2_from_string(tree, 'test');
3256
+ }, 'Wrong nodes separator\ntest#2:1/2\n!!\n \tbar');
3257
+ },
3258
+ 'Wrong nodes separator in the middle'($) {
3259
+ const tree = `foo bar\n`;
3260
+ $mol_assert_fail(() => {
3261
+ $.$mol_tree2_from_string(tree, 'test');
3262
+ }, 'Wrong nodes separator\ntest#1:5/1\n !\nfoo bar');
3263
+ },
3264
+ 'Unexpected EOF, LF required'($) {
3265
+ const tree = ` foo`;
3266
+ $mol_assert_fail(() => {
3267
+ $.$mol_tree2_from_string(tree, 'test');
3268
+ }, 'Unexpected EOF, LF required\ntest#1:5/1\n !\n foo');
3269
+ },
3270
+ 'Errors skip and collect'($) {
3271
+ const tree = `foo bar`;
3272
+ const errors = [];
3273
+ const $$ = $.$mol_ambient({
3274
+ $mol_fail: (error) => {
3275
+ errors.push(error.message);
3276
+ return null;
3541
3277
  }
3542
- }
3543
- const name = $mol_wire_async(NameLogger).send;
3544
- name('john');
3545
- const promise = name('jin');
3546
- $.$mol_after_mock_warp();
3547
- await promise;
3548
- $mol_assert_like(NameLogger.first, ['john', 'jin']);
3549
- $mol_assert_like(NameLogger.last, ['jin']);
3278
+ });
3279
+ const res = $$.$mol_tree2_from_string(tree, 'test');
3280
+ $mol_assert_like(errors, [
3281
+ 'Wrong nodes separator\ntest#1:5/1\n !\nfoo bar',
3282
+ 'Unexpected EOF, LF required\ntest#1:9/1\n !\nfoo bar',
3283
+ ]);
3284
+ $mol_assert_equal(res.toString(), 'foo bar\n');
3550
3285
  },
3551
- async 'Latest function calls wins'($) {
3552
- const first = [];
3553
- const last = [];
3554
- function send_name(next) {
3555
- $mol_wire_sync(first).push(next);
3556
- $.$mol_wait_timeout(0);
3557
- last.push(next);
3558
- }
3559
- const name = $mol_wire_async(send_name);
3560
- name('john');
3561
- const promise = name('jin');
3562
- $.$mol_after_mock_warp();
3563
- await promise;
3564
- $mol_assert_like(first, ['john', 'jin']);
3565
- $mol_assert_like(last, ['jin']);
3286
+ });
3287
+ })($ || ($ = {}));
3288
+
3289
+ ;
3290
+ "use strict";
3291
+ var $;
3292
+ (function ($) {
3293
+ $mol_test({
3294
+ 'fromJSON'() {
3295
+ $mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
3296
+ $mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
3297
+ $mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
3298
+ $mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
3299
+ $mol_assert_equal($mol_tree2_from_json(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
3300
+ $mol_assert_equal($mol_tree2_from_json({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
3566
3301
  },
3567
3302
  });
3568
3303
  })($ || ($ = {}));
@@ -3643,16 +3378,115 @@ var $;
3643
3378
  const dom = $mol_jsx(Foo, { id: "app" });
3644
3379
  $mol_assert_equal(dom.outerHTML, '<div id="app" class="Foo"><span id="app/middle" class="Foo_middle Bar"><img id="app/icon" class="Foo_icon"></span></div>');
3645
3380
  },
3646
- 'Fail on same ids from different caller'() {
3647
- const Foo = () => {
3648
- return $mol_jsx("div", null,
3649
- $mol_jsx("img", { id: "icon" }),
3650
- $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
3651
- };
3652
- const Bar = (props) => {
3653
- return $mol_jsx("span", null, props.icon());
3654
- };
3655
- $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
3381
+ 'Fail on same ids from different caller'() {
3382
+ const Foo = () => {
3383
+ return $mol_jsx("div", null,
3384
+ $mol_jsx("img", { id: "icon" }),
3385
+ $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
3386
+ };
3387
+ const Bar = (props) => {
3388
+ return $mol_jsx("span", null, props.icon());
3389
+ };
3390
+ $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
3391
+ },
3392
+ });
3393
+ })($ || ($ = {}));
3394
+
3395
+ ;
3396
+ "use strict";
3397
+ var $;
3398
+ (function ($) {
3399
+ function $mol_dom_parse(text, type = 'application/xhtml+xml') {
3400
+ const parser = new $mol_dom_context.DOMParser();
3401
+ const doc = parser.parseFromString(text, type);
3402
+ const error = doc.getElementsByTagName('parsererror');
3403
+ if (error.length)
3404
+ throw new Error(error[0].textContent);
3405
+ return doc;
3406
+ }
3407
+ $.$mol_dom_parse = $mol_dom_parse;
3408
+ })($ || ($ = {}));
3409
+
3410
+ ;
3411
+ "use strict";
3412
+ var $;
3413
+ (function ($) {
3414
+ $mol_test({
3415
+ 'Attach to document'() {
3416
+ const doc = $mol_dom_parse('<html><body id="foo"></body></html>');
3417
+ $mol_jsx_attach(doc, () => $mol_jsx("body", { id: "foo" }, "bar"));
3418
+ $mol_assert_equal(doc.documentElement.outerHTML, '<html><body id="foo">bar</body></html>');
3419
+ },
3420
+ });
3421
+ })($ || ($ = {}));
3422
+
3423
+ ;
3424
+ "use strict";
3425
+ var $;
3426
+ (function ($) {
3427
+ $mol_test({
3428
+ 'const returns stored value'() {
3429
+ const foo = { bar: $mol_const(Math.random()) };
3430
+ $mol_assert_equal(foo.bar(), foo.bar());
3431
+ $mol_assert_equal(foo.bar(), foo.bar['()']);
3432
+ },
3433
+ });
3434
+ })($ || ($ = {}));
3435
+
3436
+ ;
3437
+ "use strict";
3438
+ var $;
3439
+ (function ($_1) {
3440
+ $mol_test({
3441
+ 'Collect deps'() {
3442
+ const pub1 = new $mol_wire_pub;
3443
+ const pub2 = new $mol_wire_pub;
3444
+ const sub = new $mol_wire_pub_sub;
3445
+ const bu1 = sub.track_on();
3446
+ try {
3447
+ pub1.promote();
3448
+ pub2.promote();
3449
+ pub2.promote();
3450
+ }
3451
+ finally {
3452
+ sub.track_cut();
3453
+ sub.track_off(bu1);
3454
+ }
3455
+ pub1.emit();
3456
+ pub2.emit();
3457
+ $mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
3458
+ const bu2 = sub.track_on();
3459
+ try {
3460
+ pub1.promote();
3461
+ pub1.promote();
3462
+ pub2.promote();
3463
+ }
3464
+ finally {
3465
+ sub.track_cut();
3466
+ sub.track_off(bu2);
3467
+ }
3468
+ pub1.emit();
3469
+ pub2.emit();
3470
+ $mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
3471
+ },
3472
+ 'cyclic detection'($) {
3473
+ const sub1 = new $mol_wire_pub_sub;
3474
+ const sub2 = new $mol_wire_pub_sub;
3475
+ const bu1 = sub1.track_on();
3476
+ try {
3477
+ const bu2 = sub2.track_on();
3478
+ try {
3479
+ $mol_assert_fail(() => sub1.promote(), 'Circular subscription');
3480
+ }
3481
+ finally {
3482
+ sub2.track_cut();
3483
+ sub2.track_off(bu2);
3484
+ }
3485
+ }
3486
+ finally {
3487
+ sub1.track_cut();
3488
+ sub1.track_off(bu1);
3489
+ }
3656
3490
  },
3657
3491
  });
3658
3492
  })($ || ($ = {}));
@@ -3661,27 +3495,55 @@ var $;
3661
3495
  "use strict";
3662
3496
  var $;
3663
3497
  (function ($) {
3664
- function $mol_dom_parse(text, type = 'application/xhtml+xml') {
3665
- const parser = new $mol_dom_context.DOMParser();
3666
- const doc = parser.parseFromString(text, type);
3667
- const error = doc.getElementsByTagName('parsererror');
3668
- if (error.length)
3669
- throw new Error(error[0].textContent);
3670
- return doc;
3498
+ $.$mol_after_mock_queue = [];
3499
+ function $mol_after_mock_warp() {
3500
+ const queue = $.$mol_after_mock_queue.splice(0);
3501
+ for (const task of queue)
3502
+ task();
3671
3503
  }
3672
- $.$mol_dom_parse = $mol_dom_parse;
3504
+ $.$mol_after_mock_warp = $mol_after_mock_warp;
3505
+ class $mol_after_mock_commmon extends $mol_object2 {
3506
+ task;
3507
+ promise = Promise.resolve();
3508
+ cancelled = false;
3509
+ id;
3510
+ constructor(task) {
3511
+ super();
3512
+ this.task = task;
3513
+ $.$mol_after_mock_queue.push(task);
3514
+ }
3515
+ destructor() {
3516
+ const index = $.$mol_after_mock_queue.indexOf(this.task);
3517
+ if (index >= 0)
3518
+ $.$mol_after_mock_queue.splice(index, 1);
3519
+ }
3520
+ }
3521
+ $.$mol_after_mock_commmon = $mol_after_mock_commmon;
3522
+ class $mol_after_mock_timeout extends $mol_after_mock_commmon {
3523
+ delay;
3524
+ constructor(delay, task) {
3525
+ super(task);
3526
+ this.delay = delay;
3527
+ }
3528
+ }
3529
+ $.$mol_after_mock_timeout = $mol_after_mock_timeout;
3673
3530
  })($ || ($ = {}));
3674
3531
 
3675
3532
  ;
3676
3533
  "use strict";
3677
3534
  var $;
3678
- (function ($) {
3679
- $mol_test({
3680
- 'Attach to document'() {
3681
- const doc = $mol_dom_parse('<html><body id="foo"></body></html>');
3682
- $mol_jsx_attach(doc, () => $mol_jsx("body", { id: "foo" }, "bar"));
3683
- $mol_assert_equal(doc.documentElement.outerHTML, '<html><body id="foo">bar</body></html>');
3684
- },
3535
+ (function ($_1) {
3536
+ $mol_test_mocks.push($ => {
3537
+ $.$mol_after_timeout = $mol_after_mock_timeout;
3538
+ });
3539
+ })($ || ($ = {}));
3540
+
3541
+ ;
3542
+ "use strict";
3543
+ var $;
3544
+ (function ($_1) {
3545
+ $mol_test_mocks.push($ => {
3546
+ $.$mol_after_frame = $mol_after_mock_commmon;
3685
3547
  });
3686
3548
  })($ || ($ = {}));
3687
3549
 
@@ -3690,10 +3552,79 @@ var $;
3690
3552
  var $;
3691
3553
  (function ($) {
3692
3554
  $mol_test({
3693
- 'const returns stored value'() {
3694
- const foo = { bar: $mol_const(Math.random()) };
3695
- $mol_assert_equal(foo.bar(), foo.bar());
3696
- $mol_assert_equal(foo.bar(), foo.bar['()']);
3555
+ 'Sync execution'() {
3556
+ class Sync extends $mol_object2 {
3557
+ static calc(a, b) {
3558
+ return a + b;
3559
+ }
3560
+ }
3561
+ __decorate([
3562
+ $mol_wire_method
3563
+ ], Sync, "calc", null);
3564
+ $mol_assert_equal(Sync.calc(1, 2), 3);
3565
+ },
3566
+ async 'async <=> sync'() {
3567
+ class SyncAsync extends $mol_object2 {
3568
+ static async val(a) {
3569
+ return a;
3570
+ }
3571
+ static sum(a, b) {
3572
+ const syn = $mol_wire_sync(this);
3573
+ return syn.val(a) + syn.val(b);
3574
+ }
3575
+ static async calc(a, b) {
3576
+ return 5 + await $mol_wire_async(this).sum(a, b);
3577
+ }
3578
+ }
3579
+ $mol_assert_equal(await SyncAsync.calc(1, 2), 8);
3580
+ },
3581
+ async 'Idempotence control'() {
3582
+ class Idempotence extends $mol_object2 {
3583
+ static logs_idemp = 0;
3584
+ static logs_unidemp = 0;
3585
+ static log_idemp() {
3586
+ this.logs_idemp += 1;
3587
+ }
3588
+ static log_unidemp() {
3589
+ this.logs_unidemp += 1;
3590
+ }
3591
+ static async val(a) {
3592
+ return a;
3593
+ }
3594
+ static sum(a, b) {
3595
+ this.log_idemp();
3596
+ this.log_unidemp();
3597
+ const syn = $mol_wire_sync(this);
3598
+ return syn.val(a) + syn.val(b);
3599
+ }
3600
+ static async calc(a, b) {
3601
+ return 5 + await $mol_wire_async(this).sum(a, b);
3602
+ }
3603
+ }
3604
+ __decorate([
3605
+ $mol_wire_method
3606
+ ], Idempotence, "log_idemp", null);
3607
+ $mol_assert_equal(await Idempotence.calc(1, 2), 8);
3608
+ $mol_assert_equal(Idempotence.logs_idemp, 1);
3609
+ $mol_assert_equal(Idempotence.logs_unidemp, 3);
3610
+ },
3611
+ async 'Error handling'() {
3612
+ class Handle extends $mol_object2 {
3613
+ static async sum(a, b) {
3614
+ $mol_fail(new Error('test error ' + (a + b)));
3615
+ }
3616
+ static check() {
3617
+ try {
3618
+ return $mol_wire_sync(Handle).sum(1, 2);
3619
+ }
3620
+ catch (error) {
3621
+ if ($mol_promise_like(error))
3622
+ $mol_fail_hidden(error);
3623
+ $mol_assert_equal(error.message, 'test error 3');
3624
+ }
3625
+ }
3626
+ }
3627
+ await $mol_wire_async(Handle).check();
3697
3628
  },
3698
3629
  });
3699
3630
  })($ || ($ = {}));
@@ -3759,12 +3690,6 @@ var $;
3759
3690
  });
3760
3691
  })($ || ($ = {}));
3761
3692
 
3762
- ;
3763
- "use strict";
3764
-
3765
- ;
3766
- "use strict";
3767
-
3768
3693
  ;
3769
3694
  "use strict";
3770
3695
  var $;
@@ -4164,6 +4089,83 @@ var $;
4164
4089
  });
4165
4090
  })($ || ($ = {}));
4166
4091
 
4092
+ ;
4093
+ "use strict";
4094
+
4095
+ ;
4096
+ "use strict";
4097
+
4098
+ ;
4099
+ "use strict";
4100
+ var $;
4101
+ (function ($_1) {
4102
+ $mol_test({
4103
+ 'test types'($) {
4104
+ class A {
4105
+ static a() {
4106
+ return Promise.resolve('');
4107
+ }
4108
+ static b() {
4109
+ return $mol_wire_sync(this).a();
4110
+ }
4111
+ }
4112
+ },
4113
+ });
4114
+ })($ || ($ = {}));
4115
+
4116
+ ;
4117
+ "use strict";
4118
+ var $;
4119
+ (function ($_1) {
4120
+ $mol_test({
4121
+ 'test types'($) {
4122
+ class A {
4123
+ static a() {
4124
+ return '';
4125
+ }
4126
+ static b() {
4127
+ return $mol_wire_async(this).a();
4128
+ }
4129
+ }
4130
+ },
4131
+ async 'Latest method calls wins'($) {
4132
+ class NameLogger extends $mol_object2 {
4133
+ static $ = $;
4134
+ static first = [];
4135
+ static last = [];
4136
+ static send(next) {
4137
+ $mol_wire_sync(this.first).push(next);
4138
+ this.$.$mol_wait_timeout(0);
4139
+ this.last.push(next);
4140
+ }
4141
+ }
4142
+ const name = $mol_wire_async(NameLogger).send;
4143
+ name('john');
4144
+ const promise = name('jin');
4145
+ $.$mol_after_mock_warp();
4146
+ await promise;
4147
+ $mol_assert_like(NameLogger.first, ['john', 'jin']);
4148
+ $mol_assert_like(NameLogger.last, ['jin']);
4149
+ },
4150
+ async 'Latest function calls wins'($) {
4151
+ const first = [];
4152
+ const last = [];
4153
+ function send_name(next) {
4154
+ $mol_wire_sync(first).push(next);
4155
+ $.$mol_wait_timeout(0);
4156
+ last.push(next);
4157
+ }
4158
+ const name = $mol_wire_async(send_name);
4159
+ name('john');
4160
+ const promise = name('jin');
4161
+ $.$mol_after_mock_warp();
4162
+ await promise;
4163
+ $mol_assert_like(first, ['john', 'jin']);
4164
+ $mol_assert_like(last, ['jin']);
4165
+ },
4166
+ });
4167
+ })($ || ($ = {}));
4168
+
4167
4169
  ;
4168
4170
  "use strict";
4169
4171
  var $;