mol_crypto_lib 0.1.1078 → 0.1.1079

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
@@ -36,124 +36,341 @@ var $;
36
36
  "use strict";
37
37
  var $;
38
38
  (function ($) {
39
- function $mol_promise_like(val) {
40
- return val && typeof val === 'object' && 'then' in val && typeof val.then === 'function';
41
- }
42
- $.$mol_promise_like = $mol_promise_like;
39
+ let $mol_wire_cursor;
40
+ (function ($mol_wire_cursor) {
41
+ $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
42
+ $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
43
+ $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
44
+ $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
45
+ })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
43
46
  })($ || ($ = {}));
44
47
 
45
48
  ;
46
49
  "use strict";
47
50
  var $;
48
51
  (function ($) {
49
- function $mol_fail_hidden(error) {
50
- throw error;
52
+ class $mol_wire_pub extends Object {
53
+ data = [];
54
+ static get [Symbol.species]() {
55
+ return Array;
56
+ }
57
+ sub_from = 0;
58
+ get sub_list() {
59
+ const res = [];
60
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
61
+ res.push(this.data[i]);
62
+ }
63
+ return res;
64
+ }
65
+ get sub_empty() {
66
+ return this.sub_from === this.data.length;
67
+ }
68
+ sub_on(sub, pub_pos) {
69
+ const pos = this.data.length;
70
+ this.data.push(sub, pub_pos);
71
+ return pos;
72
+ }
73
+ sub_off(sub_pos) {
74
+ if (!(sub_pos < this.data.length)) {
75
+ $mol_fail(new Error(`Wrong pos ${sub_pos}`));
76
+ }
77
+ const end = this.data.length - 2;
78
+ if (sub_pos !== end) {
79
+ this.peer_move(end, sub_pos);
80
+ }
81
+ this.data.pop();
82
+ this.data.pop();
83
+ if (this.data.length === this.sub_from)
84
+ this.reap();
85
+ }
86
+ reap() { }
87
+ promote() {
88
+ $mol_wire_auto()?.track_next(this);
89
+ }
90
+ fresh() { }
91
+ complete() { }
92
+ get incompleted() {
93
+ return false;
94
+ }
95
+ emit(quant = $mol_wire_cursor.stale) {
96
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
97
+ ;
98
+ this.data[i].absorb(quant);
99
+ }
100
+ }
101
+ peer_move(from_pos, to_pos) {
102
+ const peer = this.data[from_pos];
103
+ const self_pos = this.data[from_pos + 1];
104
+ this.data[to_pos] = peer;
105
+ this.data[to_pos + 1] = self_pos;
106
+ peer.peer_repos(self_pos, to_pos);
107
+ }
108
+ peer_repos(peer_pos, self_pos) {
109
+ this.data[peer_pos + 1] = self_pos;
110
+ }
51
111
  }
52
- $.$mol_fail_hidden = $mol_fail_hidden;
112
+ $.$mol_wire_pub = $mol_wire_pub;
53
113
  })($ || ($ = {}));
54
114
 
55
115
  ;
56
116
  "use strict";
57
- var $;
58
- (function ($) {
59
- const catched = new WeakMap();
60
- function $mol_fail_catch(error) {
61
- if (typeof error !== 'object')
62
- return false;
63
- if ($mol_promise_like(error))
64
- $mol_fail_hidden(error);
65
- if (catched.get(error))
66
- return false;
67
- catched.set(error, true);
68
- return true;
69
- }
70
- $.$mol_fail_catch = $mol_fail_catch;
71
- })($ || ($ = {}));
72
117
 
73
118
  ;
74
119
  "use strict";
75
120
  var $;
76
121
  (function ($) {
77
- function $mol_fail_log(error) {
78
- if ($mol_promise_like(error))
79
- return false;
80
- if (!$mol_fail_catch(error))
81
- return false;
82
- console.error(error);
83
- return true;
122
+ $.$mol_wire_auto_sub = null;
123
+ function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
124
+ return $.$mol_wire_auto_sub = next;
84
125
  }
85
- $.$mol_fail_log = $mol_fail_log;
126
+ $.$mol_wire_auto = $mol_wire_auto;
127
+ $.$mol_wire_affected = [];
86
128
  })($ || ($ = {}));
87
129
 
88
130
  ;
89
131
  "use strict";
90
- var $node = new Proxy({ require }, {
91
- get(target, name, wrapper) {
92
- if (target[name])
93
- return target[name];
94
- const mod = target.require('module');
95
- if (mod.builtinModules.indexOf(name) >= 0)
96
- return target.require(name);
97
- if (name[0] === '.')
98
- return target.require(name);
99
- const path = target.require('path');
100
- const fs = target.require('fs');
101
- let dir = path.resolve('.');
102
- const suffix = `./node_modules/${name}`;
103
- const $$ = $;
104
- while (!fs.existsSync(path.join(dir, suffix))) {
105
- const parent = path.resolve(dir, '..');
106
- if (parent === dir) {
107
- $$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
132
+ var $;
133
+ (function ($) {
134
+ $['devtoolsFormatters'] ||= [];
135
+ function $mol_dev_format_register(config) {
136
+ $['devtoolsFormatters'].push(config);
137
+ }
138
+ $.$mol_dev_format_register = $mol_dev_format_register;
139
+ $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
140
+ $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
141
+ $mol_dev_format_register({
142
+ header: (val, config = false) => {
143
+ if (config)
144
+ return null;
145
+ if (!val)
146
+ return null;
147
+ if ($.$mol_dev_format_head in val) {
108
148
  try {
109
- $$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
149
+ return val[$.$mol_dev_format_head]();
150
+ }
151
+ catch (error) {
152
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
110
153
  }
111
- catch { }
112
- break;
113
154
  }
114
- else {
115
- dir = parent;
155
+ if (typeof val === 'function') {
156
+ return $mol_dev_format_native(val);
157
+ }
158
+ if (Symbol.toStringTag in val) {
159
+ return $mol_dev_format_native(val);
116
160
  }
117
- }
118
- try {
119
- return target.require(name);
120
- }
121
- catch (error) {
122
- $.$mol_fail_log(error);
123
161
  return null;
124
- }
125
- },
126
- set(target, name, value) {
127
- target[name] = value;
128
- return true;
129
- },
130
- });
131
- require = (req => Object.assign(function require(name) {
132
- return $node[name];
133
- }, req))(require);
162
+ },
163
+ hasBody: val => val[$.$mol_dev_format_body],
164
+ body: val => val[$.$mol_dev_format_body](),
165
+ });
166
+ function $mol_dev_format_native(obj) {
167
+ if (typeof obj === 'undefined')
168
+ return $.$mol_dev_format_shade('undefined');
169
+ return [
170
+ 'object',
171
+ {
172
+ object: obj,
173
+ config: true,
174
+ },
175
+ ];
176
+ }
177
+ $.$mol_dev_format_native = $mol_dev_format_native;
178
+ function $mol_dev_format_auto(obj) {
179
+ if (obj == null)
180
+ return $.$mol_dev_format_shade(String(obj));
181
+ return [
182
+ 'object',
183
+ {
184
+ object: obj,
185
+ config: false,
186
+ },
187
+ ];
188
+ }
189
+ $.$mol_dev_format_auto = $mol_dev_format_auto;
190
+ function $mol_dev_format_element(element, style, ...content) {
191
+ const styles = [];
192
+ for (let key in style)
193
+ styles.push(`${key} : ${style[key]}`);
194
+ return [
195
+ element,
196
+ {
197
+ style: styles.join(' ; '),
198
+ },
199
+ ...content,
200
+ ];
201
+ }
202
+ $.$mol_dev_format_element = $mol_dev_format_element;
203
+ function $mol_dev_format_span(style, ...content) {
204
+ return $mol_dev_format_element('span', {
205
+ ...style,
206
+ }, ...content);
207
+ }
208
+ $.$mol_dev_format_span = $mol_dev_format_span;
209
+ $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
210
+ $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
211
+ $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
212
+ $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
213
+ $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
214
+ $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
215
+ $.$mol_dev_format_accent = $mol_dev_format_span.bind(null, {
216
+ 'color': 'magenta',
217
+ });
218
+ $.$mol_dev_format_strong = $mol_dev_format_span.bind(null, {
219
+ 'font-weight': 'bold',
220
+ });
221
+ $.$mol_dev_format_string = $mol_dev_format_span.bind(null, {
222
+ 'color': 'green',
223
+ });
224
+ $.$mol_dev_format_shade = $mol_dev_format_span.bind(null, {
225
+ 'color': 'gray',
226
+ });
227
+ $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
228
+ 'margin-left': '13px'
229
+ });
230
+ })($ || ($ = {}));
134
231
 
135
232
  ;
136
233
  "use strict";
137
234
  var $;
138
235
  (function ($) {
139
- function $mol_log3_area_lazy(event) {
140
- const self = this;
141
- const stack = self.$mol_log3_stack;
142
- const deep = stack.length;
143
- let logged = false;
144
- stack.push(() => {
145
- logged = true;
146
- self.$mol_log3_area.call(self, event);
147
- });
148
- return () => {
149
- if (logged)
150
- self.console.groupEnd();
151
- if (stack.length > deep)
152
- stack.length = deep;
153
- };
236
+ class $mol_wire_pub_sub extends $mol_wire_pub {
237
+ pub_from = 0;
238
+ cursor = $mol_wire_cursor.stale;
239
+ get temp() {
240
+ return false;
241
+ }
242
+ get pub_list() {
243
+ const res = [];
244
+ const max = this.cursor >= 0 ? this.cursor : this.sub_from;
245
+ for (let i = this.pub_from; i < max; i += 2) {
246
+ if (this.data[i])
247
+ res.push(this.data[i]);
248
+ }
249
+ return res;
250
+ }
251
+ track_on() {
252
+ this.cursor = this.pub_from;
253
+ const sub = $mol_wire_auto();
254
+ $mol_wire_auto(this);
255
+ return sub;
256
+ }
257
+ promote() {
258
+ if (this.cursor >= this.pub_from) {
259
+ $mol_fail(new Error('Circular subscription'));
260
+ }
261
+ super.promote();
262
+ }
263
+ track_next(pub) {
264
+ if (this.cursor < 0)
265
+ $mol_fail(new Error('Promo to non begun sub'));
266
+ if (this.cursor < this.sub_from) {
267
+ const next = this.data[this.cursor];
268
+ if (pub === undefined)
269
+ return next ?? null;
270
+ if (next === pub) {
271
+ this.cursor += 2;
272
+ return next;
273
+ }
274
+ if (next) {
275
+ if (this.sub_from < this.data.length) {
276
+ this.peer_move(this.sub_from, this.data.length);
277
+ }
278
+ this.peer_move(this.cursor, this.sub_from);
279
+ this.sub_from += 2;
280
+ }
281
+ }
282
+ else {
283
+ if (pub === undefined)
284
+ return null;
285
+ if (this.sub_from < this.data.length) {
286
+ this.peer_move(this.sub_from, this.data.length);
287
+ }
288
+ this.sub_from += 2;
289
+ }
290
+ this.data[this.cursor] = pub;
291
+ this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
292
+ this.cursor += 2;
293
+ return pub;
294
+ }
295
+ track_off(sub) {
296
+ $mol_wire_auto(sub);
297
+ if (this.cursor < 0) {
298
+ $mol_fail(new Error('End of non begun sub'));
299
+ }
300
+ for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
301
+ const pub = this.data[cursor];
302
+ pub.fresh();
303
+ }
304
+ this.cursor = $mol_wire_cursor.fresh;
305
+ }
306
+ pub_off(sub_pos) {
307
+ this.data[sub_pos] = undefined;
308
+ this.data[sub_pos + 1] = undefined;
309
+ }
310
+ destructor() {
311
+ for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
312
+ const sub = this.data[cursor];
313
+ const pos = this.data[cursor + 1];
314
+ sub.pub_off(pos);
315
+ this.data.pop();
316
+ this.data.pop();
317
+ }
318
+ this.cursor = this.pub_from;
319
+ this.track_cut();
320
+ this.cursor = $mol_wire_cursor.final;
321
+ }
322
+ track_cut() {
323
+ if (this.cursor < this.pub_from) {
324
+ $mol_fail(new Error('Cut of non begun sub'));
325
+ }
326
+ let tail = 0;
327
+ for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
328
+ const pub = this.data[cursor];
329
+ pub?.sub_off(this.data[cursor + 1]);
330
+ if (this.sub_from < this.data.length) {
331
+ this.peer_move(this.data.length - 2, cursor);
332
+ this.data.pop();
333
+ this.data.pop();
334
+ }
335
+ else {
336
+ ++tail;
337
+ }
338
+ }
339
+ for (; tail; --tail) {
340
+ this.data.pop();
341
+ this.data.pop();
342
+ }
343
+ this.sub_from = this.cursor;
344
+ }
345
+ complete() { }
346
+ complete_pubs() {
347
+ const limit = this.cursor < 0 ? this.sub_from : this.cursor;
348
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
349
+ const pub = this.data[cursor];
350
+ if (pub?.incompleted)
351
+ return;
352
+ }
353
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
354
+ const pub = this.data[cursor];
355
+ pub?.complete();
356
+ }
357
+ }
358
+ absorb(quant = $mol_wire_cursor.stale) {
359
+ if (this.cursor === $mol_wire_cursor.final)
360
+ return;
361
+ if (this.cursor >= quant)
362
+ return;
363
+ this.cursor = quant;
364
+ this.emit($mol_wire_cursor.doubt);
365
+ }
366
+ [$mol_dev_format_head]() {
367
+ return $mol_dev_format_native(this);
368
+ }
369
+ get pub_empty() {
370
+ return this.sub_from === this.pub_from;
371
+ }
154
372
  }
155
- $.$mol_log3_area_lazy = $mol_log3_area_lazy;
156
- $.$mol_log3_stack = [];
373
+ $.$mol_wire_pub_sub = $mol_wire_pub_sub;
157
374
  })($ || ($ = {}));
158
375
 
159
376
  ;
@@ -260,6 +477,16 @@ var $;
260
477
  $.$mol_owning_catch = $mol_owning_catch;
261
478
  })($ || ($ = {}));
262
479
 
480
+ ;
481
+ "use strict";
482
+ var $;
483
+ (function ($) {
484
+ function $mol_fail_hidden(error) {
485
+ throw error;
486
+ }
487
+ $.$mol_fail_hidden = $mol_fail_hidden;
488
+ })($ || ($ = {}));
489
+
263
490
  ;
264
491
  "use strict";
265
492
 
@@ -342,1957 +569,2441 @@ var $;
342
569
  "use strict";
343
570
  var $;
344
571
  (function ($) {
345
- class $mol_span extends $mol_object2 {
346
- uri;
347
- source;
348
- row;
349
- col;
350
- length;
351
- constructor(uri, source, row, col, length) {
572
+ class $mol_after_timeout extends $mol_object2 {
573
+ delay;
574
+ task;
575
+ id;
576
+ constructor(delay, task) {
352
577
  super();
353
- this.uri = uri;
354
- this.source = source;
355
- this.row = row;
356
- this.col = col;
357
- this.length = length;
358
- this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
359
- }
360
- static unknown = $mol_span.begin('?');
361
- static begin(uri, source = '') {
362
- return new $mol_span(uri, source, 1, 1, 0);
363
- }
364
- static end(uri, source) {
365
- return new $mol_span(uri, source, 1, source.length + 1, 0);
366
- }
367
- static entire(uri, source) {
368
- return new $mol_span(uri, source, 1, 1, source.length);
369
- }
370
- toString() {
371
- return this[Symbol.toStringTag];
372
- }
373
- toJSON() {
374
- return {
375
- uri: this.uri,
376
- row: this.row,
377
- col: this.col,
378
- length: this.length
379
- };
380
- }
381
- error(message, Class = Error) {
382
- return new Class(`${message} (${this})`);
578
+ this.delay = delay;
579
+ this.task = task;
580
+ this.id = setTimeout(task, delay);
383
581
  }
384
- span(row, col, length) {
385
- return new $mol_span(this.uri, this.source, row, col, length);
386
- }
387
- after(length = 0) {
388
- return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
389
- }
390
- slice(begin, end = -1) {
391
- let len = this.length;
392
- if (begin < 0)
393
- begin += len;
394
- if (end < 0)
395
- end += len;
396
- if (begin < 0 || begin > len)
397
- this.$.$mol_fail(this.error(`Begin value '${begin}' out of range`, RangeError));
398
- if (end < 0 || end > len)
399
- this.$.$mol_fail(this.error(`End value '${end}' out of range`, RangeError));
400
- if (end < begin)
401
- this.$.$mol_fail(this.error(`End value '${end}' can't be less than begin value`, RangeError));
402
- return this.span(this.row, this.col + begin, end - begin);
582
+ destructor() {
583
+ clearTimeout(this.id);
403
584
  }
404
585
  }
405
- $.$mol_span = $mol_span;
586
+ $.$mol_after_timeout = $mol_after_timeout;
406
587
  })($ || ($ = {}));
407
588
 
408
589
  ;
409
590
  "use strict";
410
591
  var $;
411
592
  (function ($) {
412
- function $mol_tree2_to_string(tree) {
413
- let output = [];
414
- function dump(tree, prefix = '') {
415
- if (tree.type.length) {
416
- if (!prefix.length) {
417
- prefix = "\t";
418
- }
419
- output.push(tree.type);
420
- if (tree.kids.length == 1) {
421
- output.push(' ');
422
- dump(tree.kids[0], prefix);
423
- return;
424
- }
425
- output.push("\n");
426
- }
427
- else if (tree.value.length || prefix.length) {
428
- output.push("\\" + tree.value + "\n");
429
- }
430
- for (const kid of tree.kids) {
431
- output.push(prefix);
432
- dump(kid, prefix + "\t");
433
- }
593
+ class $mol_after_frame extends $mol_after_timeout {
594
+ task;
595
+ constructor(task) {
596
+ super(16, task);
597
+ this.task = task;
434
598
  }
435
- dump(tree);
436
- return output.join('');
437
599
  }
438
- $.$mol_tree2_to_string = $mol_tree2_to_string;
600
+ $.$mol_after_frame = $mol_after_frame;
439
601
  })($ || ($ = {}));
440
602
 
441
603
  ;
442
604
  "use strict";
443
605
  var $;
444
606
  (function ($) {
445
- class $mol_tree2 extends Object {
446
- type;
447
- value;
448
- kids;
449
- span;
450
- constructor(type, value, kids, span) {
451
- super();
452
- this.type = type;
453
- this.value = value;
454
- this.kids = kids;
455
- this.span = span;
456
- this[Symbol.toStringTag] = type || '\\' + value;
607
+ function $mol_promise_like(val) {
608
+ return val && typeof val === 'object' && 'then' in val && typeof val.then === 'function';
609
+ }
610
+ $.$mol_promise_like = $mol_promise_like;
611
+ })($ || ($ = {}));
612
+
613
+ ;
614
+ "use strict";
615
+ var $;
616
+ (function ($) {
617
+ const handled = new WeakSet();
618
+ class $mol_wire_fiber extends $mol_wire_pub_sub {
619
+ task;
620
+ host;
621
+ static warm = true;
622
+ static planning = new Set();
623
+ static reaping = new Set();
624
+ static plan_task = null;
625
+ static plan() {
626
+ if (this.plan_task)
627
+ return;
628
+ this.plan_task = new $mol_after_frame(() => {
629
+ try {
630
+ this.sync();
631
+ }
632
+ finally {
633
+ $mol_wire_fiber.plan_task = null;
634
+ }
635
+ });
457
636
  }
458
- static list(kids, span = $mol_span.unknown) {
459
- return new $mol_tree2('', '', kids, span);
637
+ static sync() {
638
+ while (this.planning.size) {
639
+ for (const fiber of this.planning) {
640
+ this.planning.delete(fiber);
641
+ if (fiber.cursor >= 0)
642
+ continue;
643
+ if (fiber.cursor === $mol_wire_cursor.final)
644
+ continue;
645
+ fiber.fresh();
646
+ }
647
+ }
648
+ while (this.reaping.size) {
649
+ const fibers = this.reaping;
650
+ this.reaping = new Set;
651
+ for (const fiber of fibers) {
652
+ if (!fiber.sub_empty)
653
+ continue;
654
+ fiber.destructor();
655
+ }
656
+ }
460
657
  }
461
- list(kids) {
462
- return $mol_tree2.list(kids, this.span);
463
- }
464
- static data(value, kids = [], span = $mol_span.unknown) {
465
- const chunks = value.split('\n');
466
- if (chunks.length > 1) {
467
- let kid_span = span.span(span.row, span.col, 0);
468
- const data = chunks.map(chunk => {
469
- kid_span = kid_span.after(chunk.length);
470
- return new $mol_tree2('', chunk, [], kid_span);
471
- });
472
- kids = [...data, ...kids];
473
- value = '';
474
- }
475
- return new $mol_tree2('', value, kids, span);
658
+ [Symbol.toStringTag];
659
+ cache = undefined;
660
+ get args() {
661
+ return this.data.slice(0, this.pub_from);
476
662
  }
477
- data(value, kids = []) {
478
- return $mol_tree2.data(value, kids, this.span);
663
+ result() {
664
+ if ($mol_promise_like(this.cache))
665
+ return;
666
+ if (this.cache instanceof Error)
667
+ return;
668
+ return this.cache;
479
669
  }
480
- static struct(type, kids = [], span = $mol_span.unknown) {
481
- if (/[ \n\t\\]/.test(type)) {
482
- $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
483
- }
484
- return new $mol_tree2(type, '', kids, span);
670
+ get incompleted() {
671
+ return $mol_promise_like(this.cache);
485
672
  }
486
- struct(type, kids = []) {
487
- return $mol_tree2.struct(type, kids, this.span);
673
+ field() {
674
+ return this.task.name + '<>';
488
675
  }
489
- clone(kids, span = this.span) {
490
- return new $mol_tree2(this.type, this.value, kids, span);
676
+ constructor(id, task, host, args) {
677
+ super();
678
+ this.task = task;
679
+ this.host = host;
680
+ if (args)
681
+ this.data.push(...args);
682
+ this.pub_from = this.sub_from = args?.length ?? 0;
683
+ this[Symbol.toStringTag] = id;
491
684
  }
492
- text() {
493
- var values = [];
494
- for (var kid of this.kids) {
495
- if (kid.type)
496
- continue;
497
- values.push(kid.value);
498
- }
499
- return this.value + values.join('\n');
685
+ plan() {
686
+ $mol_wire_fiber.planning.add(this);
687
+ $mol_wire_fiber.plan();
500
688
  }
501
- static fromString(str, uri = 'unknown') {
502
- return $$.$mol_tree2_from_string(str, uri);
689
+ reap() {
690
+ $mol_wire_fiber.reaping.add(this);
691
+ $mol_wire_fiber.plan();
503
692
  }
504
693
  toString() {
505
- return $$.$mol_tree2_to_string(this);
694
+ return this[Symbol.toStringTag];
506
695
  }
507
- insert(value, ...path) {
508
- if (path.length === 0)
509
- return value;
510
- const type = path[0];
511
- if (typeof type === 'string') {
512
- let replaced = false;
513
- const sub = this.kids.map((item, index) => {
514
- if (item.type !== type)
515
- return item;
516
- replaced = true;
517
- return item.insert(value, ...path.slice(1));
518
- }).filter(Boolean);
519
- if (!replaced && value) {
520
- sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
696
+ toJSON() {
697
+ return this[Symbol.toStringTag];
698
+ }
699
+ [$mol_dev_format_head]() {
700
+ const cursor = {
701
+ [$mol_wire_cursor.stale]: '🔴',
702
+ [$mol_wire_cursor.doubt]: '🟡',
703
+ [$mol_wire_cursor.fresh]: '🟢',
704
+ [$mol_wire_cursor.final]: '🔵',
705
+ }[this.cursor] ?? this.cursor.toString();
706
+ return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
707
+ ? $mol_dev_format_auto({
708
+ [$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
709
+ [$mol_dev_format_body]: () => $mol_dev_format_native(this),
710
+ })
711
+ : $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
712
+ }
713
+ get $() {
714
+ return (this.host ?? this.task)['$'];
715
+ }
716
+ emit(quant = $mol_wire_cursor.stale) {
717
+ if (this.sub_empty)
718
+ this.plan();
719
+ else
720
+ super.emit(quant);
721
+ }
722
+ fresh() {
723
+ if (this.cursor === $mol_wire_cursor.fresh)
724
+ return;
725
+ if (this.cursor === $mol_wire_cursor.final)
726
+ return;
727
+ check: if (this.cursor === $mol_wire_cursor.doubt) {
728
+ for (let i = this.pub_from; i < this.sub_from; i += 2) {
729
+ ;
730
+ this.data[i]?.fresh();
731
+ if (this.cursor !== $mol_wire_cursor.doubt)
732
+ break check;
521
733
  }
522
- return this.clone(sub);
523
- }
524
- else if (typeof type === 'number') {
525
- const sub = this.kids.slice();
526
- sub[type] = (sub[type] || this.list([]))
527
- .insert(value, ...path.slice(1));
528
- return this.clone(sub.filter(Boolean));
529
- }
530
- else {
531
- const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
532
- .map(item => item.insert(value, ...path.slice(1)))
533
- .filter(Boolean);
534
- return this.clone(kids);
734
+ this.cursor = $mol_wire_cursor.fresh;
735
+ return;
535
736
  }
536
- }
537
- select(...path) {
538
- let next = [this];
539
- for (const type of path) {
540
- if (!next.length)
541
- break;
542
- const prev = next;
543
- next = [];
544
- for (var item of prev) {
545
- switch (typeof (type)) {
546
- case 'string':
547
- for (var child of item.kids) {
548
- if (child.type == type) {
549
- next.push(child);
550
- }
551
- }
552
- break;
553
- case 'number':
554
- if (type < item.kids.length)
555
- next.push(item.kids[type]);
556
- break;
557
- default: next.push(...item.kids);
558
- }
737
+ const bu = this.track_on();
738
+ let result;
739
+ try {
740
+ switch (this.pub_from) {
741
+ case 0:
742
+ result = this.task.call(this.host);
743
+ break;
744
+ case 1:
745
+ result = this.task.call(this.host, this.data[0]);
746
+ break;
747
+ default:
748
+ result = this.task.call(this.host, ...this.args);
749
+ break;
750
+ }
751
+ if ($mol_promise_like(result) && !handled.has(result)) {
752
+ const put = (res) => {
753
+ if (this.cache === result)
754
+ this.put(res);
755
+ return res;
756
+ };
757
+ result = result.then(put, put);
559
758
  }
560
759
  }
561
- return this.list(next);
562
- }
563
- filter(path, value) {
564
- const sub = this.kids.filter(item => {
565
- var found = item.select(...path);
566
- if (value === undefined) {
567
- return Boolean(found.kids.length);
760
+ catch (error) {
761
+ if (error instanceof Error || $mol_promise_like(error)) {
762
+ result = error;
568
763
  }
569
764
  else {
570
- return found.kids.some(child => child.value == value);
765
+ result = new Error(String(error), { cause: error });
766
+ }
767
+ if ($mol_promise_like(result) && !handled.has(result)) {
768
+ result = result.finally(() => {
769
+ if (this.cache === result)
770
+ this.absorb();
771
+ });
571
772
  }
572
- });
573
- return this.clone(sub);
574
- }
575
- hack_self(belt, context = {}) {
576
- let handle = belt[this.type] || belt[''];
577
- if (!handle || handle === Object.prototype[this.type]) {
578
- handle = (input, belt, context) => [
579
- input.clone(input.hack(belt, context), context.span)
580
- ];
581
773
  }
582
- try {
583
- return handle(this, belt, context);
774
+ if ($mol_promise_like(result) && !handled.has(result)) {
775
+ result = Object.assign(result, {
776
+ destructor: result['destructor'] ?? (() => { })
777
+ });
778
+ handled.add(result);
779
+ const error = new Error(`Promise in ${this}`);
780
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
584
781
  }
585
- catch (error) {
586
- error.message += `\n${this.clone([])}${this.span}`;
587
- $mol_fail_hidden(error);
782
+ if (!$mol_promise_like(result)) {
783
+ this.track_cut();
588
784
  }
785
+ this.track_off(bu);
786
+ this.put(result);
589
787
  }
590
- hack(belt, context = {}) {
591
- return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
592
- }
593
- error(message, Class = Error) {
594
- return this.span.error(`${message}\n${this.clone([])}`, Class);
595
- }
596
- }
597
- $.$mol_tree2 = $mol_tree2;
598
- class $mol_tree2_empty extends $mol_tree2 {
599
- constructor() {
600
- super('', '', [], $mol_span.unknown);
601
- }
602
- }
603
- $.$mol_tree2_empty = $mol_tree2_empty;
604
- })($ || ($ = {}));
605
-
606
- ;
607
- "use strict";
608
- var $;
609
- (function ($) {
610
- class $mol_error_syntax extends SyntaxError {
611
- reason;
612
- line;
613
- span;
614
- constructor(reason, line, span) {
615
- super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
616
- this.reason = reason;
617
- this.line = line;
618
- this.span = span;
788
+ refresh() {
789
+ this.cursor = $mol_wire_cursor.stale;
790
+ this.fresh();
619
791
  }
620
- }
621
- $.$mol_error_syntax = $mol_error_syntax;
622
- })($ || ($ = {}));
623
-
624
- ;
625
- "use strict";
626
- var $;
627
- (function ($) {
628
- function $mol_tree2_from_string(str, uri = '?') {
629
- const span = $mol_span.entire(uri, str);
630
- var root = $mol_tree2.list([], span);
631
- var stack = [root];
632
- var pos = 0, row = 0, min_indent = 0;
633
- while (str.length > pos) {
634
- var indent = 0;
635
- var line_start = pos;
636
- row++;
637
- while (str.length > pos && str[pos] == '\t') {
638
- indent++;
639
- pos++;
792
+ sync() {
793
+ if (!$mol_wire_fiber.warm) {
794
+ return this.result();
640
795
  }
641
- if (!root.kids.length) {
642
- min_indent = indent;
796
+ this.promote();
797
+ this.fresh();
798
+ if (this.cache instanceof Error) {
799
+ return $mol_fail_hidden(this.cache);
643
800
  }
644
- indent -= min_indent;
645
- if (indent < 0 || indent >= stack.length) {
646
- const sp = span.span(row, 1, pos - line_start);
647
- while (str.length > pos && str[pos] != '\n') {
648
- pos++;
649
- }
650
- if (indent < 0) {
651
- if (str.length > pos) {
652
- this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
653
- }
654
- }
655
- else {
656
- this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
657
- }
801
+ if ($mol_promise_like(this.cache)) {
802
+ return $mol_fail_hidden(this.cache);
658
803
  }
659
- stack.length = indent + 1;
660
- var parent = stack[indent];
661
- while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
662
- var error_start = pos;
663
- while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
664
- pos++;
665
- }
666
- if (pos > error_start) {
667
- let line_end = str.indexOf('\n', pos);
668
- if (line_end === -1)
669
- line_end = str.length;
670
- const sp = span.span(row, error_start - line_start + 1, pos - error_start);
671
- this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
672
- }
673
- var type_start = pos;
674
- while (str.length > pos &&
675
- str[pos] != '\\' &&
676
- str[pos] != ' ' &&
677
- str[pos] != '\t' &&
678
- str[pos] != '\n') {
679
- pos++;
680
- }
681
- if (pos > type_start) {
682
- let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
683
- const parent_kids = parent.kids;
684
- parent_kids.push(next);
685
- parent = next;
686
- }
687
- if (str.length > pos && str[pos] == ' ') {
688
- pos++;
804
+ return this.cache;
805
+ }
806
+ async async() {
807
+ while (true) {
808
+ this.fresh();
809
+ if (this.cache instanceof Error) {
810
+ $mol_fail_hidden(this.cache);
689
811
  }
690
- }
691
- if (str.length > pos && str[pos] == '\\') {
692
- var data_start = pos;
693
- while (str.length > pos && str[pos] != '\n') {
694
- pos++;
812
+ if (!$mol_promise_like(this.cache))
813
+ return this.cache;
814
+ await Promise.race([this.cache, this.step()]);
815
+ if (!$mol_promise_like(this.cache))
816
+ return this.cache;
817
+ if (this.cursor === $mol_wire_cursor.final) {
818
+ await new Promise(() => { });
695
819
  }
696
- let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
697
- const parent_kids = parent.kids;
698
- parent_kids.push(next);
699
- parent = next;
700
820
  }
701
- if (str.length === pos && stack.length > 0) {
702
- const sp = span.span(row, pos - line_start + 1, 1);
703
- this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
704
- }
705
- stack.push(parent);
706
- pos++;
707
821
  }
708
- return root;
822
+ step() {
823
+ return new Promise(done => {
824
+ const sub = new $mol_wire_pub_sub;
825
+ const prev = sub.track_on();
826
+ sub.track_next(this);
827
+ sub.track_off(prev);
828
+ sub.absorb = () => {
829
+ done(null);
830
+ sub.destructor();
831
+ };
832
+ });
833
+ }
709
834
  }
710
- $.$mol_tree2_from_string = $mol_tree2_from_string;
835
+ $.$mol_wire_fiber = $mol_wire_fiber;
711
836
  })($ || ($ = {}));
712
837
 
713
838
  ;
714
839
  "use strict";
715
840
  var $;
716
841
  (function ($) {
717
- function $mol_tree2_from_json(json, span = $mol_span.unknown) {
718
- if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
719
- return new $mol_tree2(String(json), '', [], span);
720
- }
721
- if (typeof json === 'string') {
722
- return $mol_tree2.data(json, [], span);
723
- }
724
- if (Array.isArray(json)) {
725
- const sub = json.map(json => $mol_tree2_from_json(json, span));
726
- return new $mol_tree2('/', '', sub, span);
727
- }
728
- if (ArrayBuffer.isView(json)) {
729
- const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
730
- return $mol_tree2.data(String.fromCharCode(...buf), [], span);
842
+ $.$mol_compare_deep_cache = new WeakMap();
843
+ function $mol_compare_deep(left, right) {
844
+ if (Object.is(left, right))
845
+ return true;
846
+ if (left === null)
847
+ return false;
848
+ if (right === null)
849
+ return false;
850
+ if (typeof left !== 'object')
851
+ return false;
852
+ if (typeof right !== 'object')
853
+ return false;
854
+ const left_proto = Reflect.getPrototypeOf(left);
855
+ const right_proto = Reflect.getPrototypeOf(right);
856
+ if (left_proto !== right_proto)
857
+ return false;
858
+ if (left instanceof Boolean)
859
+ return Object.is(left.valueOf(), right['valueOf']());
860
+ if (left instanceof Number)
861
+ return Object.is(left.valueOf(), right['valueOf']());
862
+ if (left instanceof String)
863
+ return Object.is(left.valueOf(), right['valueOf']());
864
+ if (left instanceof Date)
865
+ return Object.is(left.valueOf(), right['valueOf']());
866
+ if (left instanceof RegExp)
867
+ return left.source === right.source && left.flags === right.flags;
868
+ if (left instanceof Error)
869
+ return left.message === right.message && left.stack === right.stack;
870
+ let left_cache = $.$mol_compare_deep_cache.get(left);
871
+ if (left_cache) {
872
+ const right_cache = left_cache.get(right);
873
+ if (typeof right_cache === 'boolean')
874
+ return right_cache;
731
875
  }
732
- if (json instanceof Date) {
733
- return new $mol_tree2('', json.toISOString(), [], span);
876
+ else {
877
+ left_cache = new WeakMap([[right, true]]);
878
+ $.$mol_compare_deep_cache.set(left, left_cache);
734
879
  }
735
- if (typeof json.toJSON === 'function') {
736
- return $mol_tree2_from_json(json.toJSON());
880
+ let result;
881
+ try {
882
+ if (!left_proto)
883
+ result = compare_pojo(left, right);
884
+ else if (!Reflect.getPrototypeOf(left_proto))
885
+ result = compare_pojo(left, right);
886
+ else if (Symbol.toPrimitive in left)
887
+ result = compare_primitive(left, right);
888
+ else if (Array.isArray(left))
889
+ result = compare_array(left, right);
890
+ else if (left instanceof Set)
891
+ result = compare_set(left, right);
892
+ else if (left instanceof Map)
893
+ result = compare_map(left, right);
894
+ else if (ArrayBuffer.isView(left))
895
+ result = compare_buffer(left, right);
896
+ else if (Symbol.iterator in left)
897
+ result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
898
+ else
899
+ result = false;
737
900
  }
738
- if (json.toString !== Object.prototype.toString) {
739
- return $mol_tree2.data(json.toString(), [], span);
901
+ finally {
902
+ left_cache.set(right, result);
740
903
  }
741
- if (json instanceof Error) {
742
- const { name, message, stack } = json;
743
- json = { ...json, name, message, stack };
904
+ return result;
905
+ }
906
+ $.$mol_compare_deep = $mol_compare_deep;
907
+ function compare_array(left, right) {
908
+ const len = left.length;
909
+ if (len !== right.length)
910
+ return false;
911
+ for (let i = 0; i < len; ++i) {
912
+ if (!$mol_compare_deep(left[i], right[i]))
913
+ return false;
744
914
  }
745
- const sub = [];
746
- for (var key in json) {
747
- const val = json[key];
748
- if (val === undefined)
749
- continue;
750
- const subsub = $mol_tree2_from_json(val, span);
751
- if (/^[^\n\t\\ ]+$/.test(key)) {
752
- sub.push(new $mol_tree2(key, '', [subsub], span));
753
- }
754
- else {
755
- sub.push($mol_tree2.data(key, [subsub], span));
756
- }
915
+ return true;
916
+ }
917
+ function compare_buffer(left, right) {
918
+ const len = left.byteLength;
919
+ if (len !== right.byteLength)
920
+ return false;
921
+ if (left instanceof DataView)
922
+ return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
923
+ for (let i = 0; i < len; ++i) {
924
+ if (left[i] !== right[i])
925
+ return false;
757
926
  }
758
- return new $mol_tree2('*', '', sub, span);
927
+ return true;
759
928
  }
760
- $.$mol_tree2_from_json = $mol_tree2_from_json;
761
- })($ || ($ = {}));
762
-
763
- ;
764
- "use strict";
765
- var $;
766
- (function ($) {
767
- class $mol_term_color {
768
- static reset = this.ansi(0, 0);
769
- static bold = this.ansi(1, 22);
770
- static italic = this.ansi(3, 23);
771
- static underline = this.ansi(4, 24);
772
- static inverse = this.ansi(7, 27);
773
- static hidden = this.ansi(8, 28);
774
- static strike = this.ansi(9, 29);
775
- static gray = this.ansi(90, 39);
776
- static red = this.ansi(91, 39);
777
- static green = this.ansi(92, 39);
778
- static yellow = this.ansi(93, 39);
779
- static blue = this.ansi(94, 39);
780
- static magenta = this.ansi(95, 39);
781
- static cyan = this.ansi(96, 39);
782
- static Gray = (str) => this.inverse(this.gray(str));
783
- static Red = (str) => this.inverse(this.red(str));
784
- static Green = (str) => this.inverse(this.green(str));
785
- static Yellow = (str) => this.inverse(this.yellow(str));
786
- static Blue = (str) => this.inverse(this.blue(str));
787
- static Magenta = (str) => this.inverse(this.magenta(str));
788
- static Cyan = (str) => this.inverse(this.cyan(str));
789
- static ansi(open, close) {
790
- if (typeof process === 'undefined')
791
- return String;
792
- if (!process.stdout.isTTY)
793
- return String;
794
- const prefix = `\x1b[${open}m`;
795
- const postfix = `\x1b[${close}m`;
796
- const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
797
- return function colorer(str) {
798
- str = String(str);
799
- if (str === '')
800
- return str;
801
- const suffix = str.replace(suffix_regexp, prefix);
802
- return prefix + suffix + postfix;
803
- };
929
+ function compare_iterator(left, right) {
930
+ while (true) {
931
+ const left_next = left.next();
932
+ const right_next = right.next();
933
+ if (left_next.done !== right_next.done)
934
+ return false;
935
+ if (left_next.done)
936
+ break;
937
+ if (!$mol_compare_deep(left_next.value, right_next.value))
938
+ return false;
804
939
  }
940
+ return true;
805
941
  }
806
- $.$mol_term_color = $mol_term_color;
807
- })($ || ($ = {}));
808
-
809
- ;
810
- "use strict";
811
- var $;
812
- (function ($) {
813
- function $mol_log3_node_make(level, output, type, color) {
814
- return function $mol_log3_logger(event) {
815
- if (!event.time)
816
- event = { time: new Date().toISOString(), ...event };
817
- let tree = this.$mol_tree2_from_json(event);
818
- tree = tree.struct(type, tree.kids);
819
- let str = color(tree.toString());
820
- this.console[level](str);
821
- const self = this;
822
- return () => self.console.groupEnd();
823
- };
942
+ function compare_set(left, right) {
943
+ if (left.size !== right.size)
944
+ return false;
945
+ return compare_iterator(left.values(), right.values());
824
946
  }
825
- $.$mol_log3_node_make = $mol_log3_node_make;
826
- $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
827
- $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
828
- $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
829
- $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
830
- $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
831
- $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
832
- })($ || ($ = {}));
833
-
834
- ;
835
- "use strict";
836
- var $;
837
- (function ($) {
838
- function $mol_env() {
839
- return {};
947
+ function compare_map(left, right) {
948
+ if (left.size !== right.size)
949
+ return false;
950
+ return compare_iterator(left.keys(), right.keys())
951
+ && compare_iterator(left.values(), right.values());
952
+ }
953
+ function compare_pojo(left, right) {
954
+ const left_keys = Object.getOwnPropertyNames(left);
955
+ const right_keys = Object.getOwnPropertyNames(right);
956
+ if (!compare_array(left_keys, right_keys))
957
+ return false;
958
+ for (let key of left_keys) {
959
+ if (!$mol_compare_deep(left[key], right[key]))
960
+ return false;
961
+ }
962
+ const left_syms = Object.getOwnPropertySymbols(left);
963
+ const right_syms = Object.getOwnPropertySymbols(right);
964
+ if (!compare_array(left_syms, right_syms))
965
+ return false;
966
+ for (let key of left_syms) {
967
+ if (!$mol_compare_deep(left[key], right[key]))
968
+ return false;
969
+ }
970
+ return true;
971
+ }
972
+ function compare_primitive(left, right) {
973
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
840
974
  }
841
- $.$mol_env = $mol_env;
842
975
  })($ || ($ = {}));
843
976
 
844
977
  ;
845
978
  "use strict";
846
979
  var $;
847
980
  (function ($) {
848
- $.$mol_env = function $mol_env() {
849
- return this.process.env;
850
- };
981
+ function $mol_log3_area_lazy(event) {
982
+ const self = this;
983
+ const stack = self.$mol_log3_stack;
984
+ const deep = stack.length;
985
+ let logged = false;
986
+ stack.push(() => {
987
+ logged = true;
988
+ self.$mol_log3_area.call(self, event);
989
+ });
990
+ return () => {
991
+ if (logged)
992
+ self.console.groupEnd();
993
+ if (stack.length > deep)
994
+ stack.length = deep;
995
+ };
996
+ }
997
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
998
+ $.$mol_log3_stack = [];
851
999
  })($ || ($ = {}));
852
1000
 
853
1001
  ;
854
1002
  "use strict";
855
1003
  var $;
856
1004
  (function ($) {
857
- function $mol_exec(dir, command, ...args) {
858
- let [app, ...args0] = command.split(' ');
859
- args = [...args0, ...args];
860
- this.$mol_log3_come({
861
- place: '$mol_exec',
862
- dir: $node.path.relative('', dir),
863
- message: 'Run',
864
- command: `${app} ${args.join(' ')}`,
865
- });
866
- var res = $node['child_process'].spawnSync(app, args, {
867
- cwd: $node.path.resolve(dir),
868
- shell: true,
869
- env: this.$mol_env(),
870
- });
871
- if (res.status || res.error) {
872
- return $mol_fail(res.error || new Error(res.stderr.toString(), { cause: res.stdout }));
1005
+ class $mol_span extends $mol_object2 {
1006
+ uri;
1007
+ source;
1008
+ row;
1009
+ col;
1010
+ length;
1011
+ constructor(uri, source, row, col, length) {
1012
+ super();
1013
+ this.uri = uri;
1014
+ this.source = source;
1015
+ this.row = row;
1016
+ this.col = col;
1017
+ this.length = length;
1018
+ this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
1019
+ }
1020
+ static unknown = $mol_span.begin('?');
1021
+ static begin(uri, source = '') {
1022
+ return new $mol_span(uri, source, 1, 1, 0);
1023
+ }
1024
+ static end(uri, source) {
1025
+ return new $mol_span(uri, source, 1, source.length + 1, 0);
1026
+ }
1027
+ static entire(uri, source) {
1028
+ return new $mol_span(uri, source, 1, 1, source.length);
1029
+ }
1030
+ toString() {
1031
+ return this[Symbol.toStringTag];
1032
+ }
1033
+ toJSON() {
1034
+ return {
1035
+ uri: this.uri,
1036
+ row: this.row,
1037
+ col: this.col,
1038
+ length: this.length
1039
+ };
1040
+ }
1041
+ error(message, Class = Error) {
1042
+ return new Class(`${message} (${this})`);
1043
+ }
1044
+ span(row, col, length) {
1045
+ return new $mol_span(this.uri, this.source, row, col, length);
1046
+ }
1047
+ after(length = 0) {
1048
+ return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
1049
+ }
1050
+ slice(begin, end = -1) {
1051
+ let len = this.length;
1052
+ if (begin < 0)
1053
+ begin += len;
1054
+ if (end < 0)
1055
+ end += len;
1056
+ if (begin < 0 || begin > len)
1057
+ this.$.$mol_fail(this.error(`Begin value '${begin}' out of range`, RangeError));
1058
+ if (end < 0 || end > len)
1059
+ this.$.$mol_fail(this.error(`End value '${end}' out of range`, RangeError));
1060
+ if (end < begin)
1061
+ this.$.$mol_fail(this.error(`End value '${end}' can't be less than begin value`, RangeError));
1062
+ return this.span(this.row, this.col + begin, end - begin);
873
1063
  }
874
- if (!res.stdout)
875
- res.stdout = Buffer.from([]);
876
- return res;
877
1064
  }
878
- $.$mol_exec = $mol_exec;
879
- })($ || ($ = {}));
880
-
881
- ;
882
- "use strict";
883
- var $;
884
- (function ($) {
885
- $.$mol_crypto_native = $node.crypto.webcrypto;
1065
+ $.$mol_span = $mol_span;
886
1066
  })($ || ($ = {}));
887
1067
 
888
1068
  ;
889
1069
  "use strict";
890
1070
  var $;
891
1071
  (function ($) {
892
- const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
893
- const encoder = new TextEncoder();
894
- function $mol_charset_encode(value) {
895
- return encoder.encode(value);
1072
+ function $mol_tree2_to_string(tree) {
1073
+ let output = [];
1074
+ function dump(tree, prefix = '') {
1075
+ if (tree.type.length) {
1076
+ if (!prefix.length) {
1077
+ prefix = "\t";
1078
+ }
1079
+ output.push(tree.type);
1080
+ if (tree.kids.length == 1) {
1081
+ output.push(' ');
1082
+ dump(tree.kids[0], prefix);
1083
+ return;
1084
+ }
1085
+ output.push("\n");
1086
+ }
1087
+ else if (tree.value.length || prefix.length) {
1088
+ output.push("\\" + tree.value + "\n");
1089
+ }
1090
+ for (const kid of tree.kids) {
1091
+ output.push(prefix);
1092
+ dump(kid, prefix + "\t");
1093
+ }
1094
+ }
1095
+ dump(tree);
1096
+ return output.join('');
896
1097
  }
897
- $.$mol_charset_encode = $mol_charset_encode;
1098
+ $.$mol_tree2_to_string = $mol_tree2_to_string;
898
1099
  })($ || ($ = {}));
899
1100
 
900
1101
  ;
901
1102
  "use strict";
902
1103
  var $;
903
1104
  (function ($) {
904
- const algorithm = {
905
- name: 'AES-CBC',
906
- length: 128,
907
- tagLength: 32,
908
- };
909
- class $mol_crypto_secret extends Object {
910
- native;
911
- static size = 16;
912
- constructor(native) {
1105
+ class $mol_tree2 extends Object {
1106
+ type;
1107
+ value;
1108
+ kids;
1109
+ span;
1110
+ constructor(type, value, kids, span) {
913
1111
  super();
914
- this.native = native;
1112
+ this.type = type;
1113
+ this.value = value;
1114
+ this.kids = kids;
1115
+ this.span = span;
1116
+ this[Symbol.toStringTag] = type || '\\' + value;
915
1117
  }
916
- static async generate() {
917
- return new this(await $mol_crypto_native.subtle.generateKey(algorithm, true, ['encrypt', 'decrypt']));
1118
+ static list(kids, span = $mol_span.unknown) {
1119
+ return new $mol_tree2('', '', kids, span);
918
1120
  }
919
- static async from(serial) {
920
- if (typeof serial === 'string') {
921
- serial = $mol_charset_encode(serial);
922
- serial = await $mol_crypto_native.subtle.digest('SHA-256', serial);
1121
+ list(kids) {
1122
+ return $mol_tree2.list(kids, this.span);
1123
+ }
1124
+ static data(value, kids = [], span = $mol_span.unknown) {
1125
+ const chunks = value.split('\n');
1126
+ if (chunks.length > 1) {
1127
+ let kid_span = span.span(span.row, span.col, 0);
1128
+ const data = chunks.map(chunk => {
1129
+ kid_span = kid_span.after(chunk.length);
1130
+ return new $mol_tree2('', chunk, [], kid_span);
1131
+ });
1132
+ kids = [...data, ...kids];
1133
+ value = '';
923
1134
  }
924
- return new this(await $mol_crypto_native.subtle.importKey('raw', serial, algorithm, true, ['encrypt', 'decrypt']));
1135
+ return new $mol_tree2('', value, kids, span);
925
1136
  }
926
- static async derive(private_serial, public_serial) {
927
- const ecdh = { name: "ECDH", namedCurve: "P-256" };
928
- const jwk = { crv: 'P-256', ext: true, kty: 'EC' };
929
- const private_key = await $mol_crypto_native.subtle.importKey('jwk', {
930
- ...jwk,
931
- key_ops: ['deriveKey'],
932
- x: private_serial.slice(0, 43),
933
- y: private_serial.slice(43, 86),
934
- d: private_serial.slice(86, 129),
935
- }, ecdh, true, ['deriveKey']);
936
- const public_key = await $mol_crypto_native.subtle.importKey('jwk', {
937
- ...jwk,
938
- key_ops: [],
939
- x: public_serial.slice(0, 43),
940
- y: public_serial.slice(43, 86),
941
- }, ecdh, true, []);
942
- const secret = await $mol_crypto_native.subtle.deriveKey({
943
- name: "ECDH",
944
- public: public_key,
945
- }, private_key, algorithm, true, ["encrypt", "decrypt"]);
946
- return new this(secret);
1137
+ data(value, kids = []) {
1138
+ return $mol_tree2.data(value, kids, this.span);
947
1139
  }
948
- async serial() {
949
- return await $mol_crypto_native.subtle.exportKey('raw', this.native);
1140
+ static struct(type, kids = [], span = $mol_span.unknown) {
1141
+ if (/[ \n\t\\]/.test(type)) {
1142
+ $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
1143
+ }
1144
+ return new $mol_tree2(type, '', kids, span);
950
1145
  }
951
- async encrypt(open, salt) {
952
- return await $mol_crypto_native.subtle.encrypt({
953
- ...algorithm,
954
- iv: salt,
955
- }, this.native, open);
1146
+ struct(type, kids = []) {
1147
+ return $mol_tree2.struct(type, kids, this.span);
956
1148
  }
957
- async decrypt(closed, salt) {
958
- return await $mol_crypto_native.subtle.decrypt({
959
- ...algorithm,
960
- iv: salt,
961
- }, this.native, closed);
1149
+ clone(kids, span = this.span) {
1150
+ return new $mol_tree2(this.type, this.value, kids, span);
1151
+ }
1152
+ text() {
1153
+ var values = [];
1154
+ for (var kid of this.kids) {
1155
+ if (kid.type)
1156
+ continue;
1157
+ values.push(kid.value);
1158
+ }
1159
+ return this.value + values.join('\n');
1160
+ }
1161
+ static fromString(str, uri = 'unknown') {
1162
+ return $$.$mol_tree2_from_string(str, uri);
1163
+ }
1164
+ toString() {
1165
+ return $$.$mol_tree2_to_string(this);
1166
+ }
1167
+ insert(value, ...path) {
1168
+ if (path.length === 0)
1169
+ return value;
1170
+ const type = path[0];
1171
+ if (typeof type === 'string') {
1172
+ let replaced = false;
1173
+ const sub = this.kids.map((item, index) => {
1174
+ if (item.type !== type)
1175
+ return item;
1176
+ replaced = true;
1177
+ return item.insert(value, ...path.slice(1));
1178
+ }).filter(Boolean);
1179
+ if (!replaced && value) {
1180
+ sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
1181
+ }
1182
+ return this.clone(sub);
1183
+ }
1184
+ else if (typeof type === 'number') {
1185
+ const sub = this.kids.slice();
1186
+ sub[type] = (sub[type] || this.list([]))
1187
+ .insert(value, ...path.slice(1));
1188
+ return this.clone(sub.filter(Boolean));
1189
+ }
1190
+ else {
1191
+ const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
1192
+ .map(item => item.insert(value, ...path.slice(1)))
1193
+ .filter(Boolean);
1194
+ return this.clone(kids);
1195
+ }
1196
+ }
1197
+ select(...path) {
1198
+ let next = [this];
1199
+ for (const type of path) {
1200
+ if (!next.length)
1201
+ break;
1202
+ const prev = next;
1203
+ next = [];
1204
+ for (var item of prev) {
1205
+ switch (typeof (type)) {
1206
+ case 'string':
1207
+ for (var child of item.kids) {
1208
+ if (child.type == type) {
1209
+ next.push(child);
1210
+ }
1211
+ }
1212
+ break;
1213
+ case 'number':
1214
+ if (type < item.kids.length)
1215
+ next.push(item.kids[type]);
1216
+ break;
1217
+ default: next.push(...item.kids);
1218
+ }
1219
+ }
1220
+ }
1221
+ return this.list(next);
1222
+ }
1223
+ filter(path, value) {
1224
+ const sub = this.kids.filter(item => {
1225
+ var found = item.select(...path);
1226
+ if (value === undefined) {
1227
+ return Boolean(found.kids.length);
1228
+ }
1229
+ else {
1230
+ return found.kids.some(child => child.value == value);
1231
+ }
1232
+ });
1233
+ return this.clone(sub);
1234
+ }
1235
+ hack_self(belt, context = {}) {
1236
+ let handle = belt[this.type] || belt[''];
1237
+ if (!handle || handle === Object.prototype[this.type]) {
1238
+ handle = (input, belt, context) => [
1239
+ input.clone(input.hack(belt, context), context.span)
1240
+ ];
1241
+ }
1242
+ try {
1243
+ return handle(this, belt, context);
1244
+ }
1245
+ catch (error) {
1246
+ error.message += `\n${this.clone([])}${this.span}`;
1247
+ $mol_fail_hidden(error);
1248
+ }
1249
+ }
1250
+ hack(belt, context = {}) {
1251
+ return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
1252
+ }
1253
+ error(message, Class = Error) {
1254
+ return this.span.error(`${message}\n${this.clone([])}`, Class);
962
1255
  }
963
1256
  }
964
- $.$mol_crypto_secret = $mol_crypto_secret;
965
- })($ || ($ = {}));
966
-
967
- ;
968
- "use strict";
969
- var $;
970
- (function ($) {
971
- })($ || ($ = {}));
972
-
973
- ;
974
- "use strict";
975
- var $;
976
- (function ($) {
977
- $.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
978
- })($ || ($ = {}));
979
-
980
- ;
981
- "use strict";
982
- var $;
983
- (function ($) {
984
- async function $mol_crypto_secret_id() {
985
- const signed = this.$mol_dom_context.localStorage.getItem('$mol_crypto_secret');
986
- if (signed === '')
987
- return await this.$mol_crypto_secret_id_get();
988
- const id = await this.$mol_crypto_secret_id_new();
989
- this.$mol_dom_context.localStorage.setItem('$mol_crypto_secret', '');
990
- return id;
991
- }
992
- $.$mol_crypto_secret_id = $mol_crypto_secret_id;
993
- async function $mol_crypto_secret_id_new() {
994
- const cred = await this.$mol_dom_context.navigator.credentials.create({
995
- publicKey: {
996
- rp: {
997
- name: "$mol_crypto_id",
998
- },
999
- user: {
1000
- id: new Uint8Array([0]),
1001
- name: "",
1002
- displayName: ""
1003
- },
1004
- pubKeyCredParams: [
1005
- { type: "public-key", alg: -7 },
1006
- { type: "public-key", alg: -257 },
1007
- ],
1008
- challenge: new Uint8Array().buffer,
1009
- },
1010
- });
1011
- return $mol_crypto_secret.from(cred.rawId);
1012
- }
1013
- $.$mol_crypto_secret_id_new = $mol_crypto_secret_id_new;
1014
- async function $mol_crypto_secret_id_get() {
1015
- const cred = await this.$mol_dom_context.navigator.credentials.get({
1016
- mediation: 'silent',
1017
- publicKey: {
1018
- userVerification: 'discouraged',
1019
- challenge: new Uint8Array().buffer,
1020
- },
1021
- });
1022
- return $mol_crypto_secret.from(cred.rawId);
1023
- }
1024
- $.$mol_crypto_secret_id_get = $mol_crypto_secret_id_get;
1025
- })($ || ($ = {}));
1026
-
1027
- ;
1028
- "use strict";
1029
- var $;
1030
- (function ($) {
1031
- function $mol_base64_encode(src) {
1032
- throw new Error('Not implemented');
1033
- }
1034
- $.$mol_base64_encode = $mol_base64_encode;
1035
- })($ || ($ = {}));
1036
-
1037
- ;
1038
- "use strict";
1039
- var $;
1040
- (function ($) {
1041
- function $mol_base64_encode_node(str) {
1042
- if (!str)
1043
- return '';
1044
- if (Buffer.isBuffer(str))
1045
- return str.toString('base64');
1046
- return Buffer.from(str).toString('base64');
1047
- }
1048
- $.$mol_base64_encode_node = $mol_base64_encode_node;
1049
- $.$mol_base64_encode = $mol_base64_encode_node;
1050
- })($ || ($ = {}));
1051
-
1052
- ;
1053
- "use strict";
1054
- var $;
1055
- (function ($) {
1056
- function $mol_base64_decode(base64) {
1057
- throw new Error('Not implemented');
1257
+ $.$mol_tree2 = $mol_tree2;
1258
+ class $mol_tree2_empty extends $mol_tree2 {
1259
+ constructor() {
1260
+ super('', '', [], $mol_span.unknown);
1261
+ }
1058
1262
  }
1059
- $.$mol_base64_decode = $mol_base64_decode;
1263
+ $.$mol_tree2_empty = $mol_tree2_empty;
1060
1264
  })($ || ($ = {}));
1061
1265
 
1062
1266
  ;
1063
1267
  "use strict";
1064
1268
  var $;
1065
1269
  (function ($) {
1066
- function $mol_base64_decode_node(base64Str) {
1067
- base64Str = base64Str.replace(/-/g, '+').replace(/_/g, '/');
1068
- const buffer = Buffer.from(base64Str, 'base64');
1069
- return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1270
+ class $mol_error_syntax extends SyntaxError {
1271
+ reason;
1272
+ line;
1273
+ span;
1274
+ constructor(reason, line, span) {
1275
+ super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
1276
+ this.reason = reason;
1277
+ this.line = line;
1278
+ this.span = span;
1279
+ }
1070
1280
  }
1071
- $.$mol_base64_decode_node = $mol_base64_decode_node;
1072
- $.$mol_base64_decode = $mol_base64_decode_node;
1281
+ $.$mol_error_syntax = $mol_error_syntax;
1073
1282
  })($ || ($ = {}));
1074
1283
 
1075
1284
  ;
1076
1285
  "use strict";
1077
1286
  var $;
1078
1287
  (function ($) {
1079
- function $mol_base64_ae_encode(buffer) {
1080
- return $mol_base64_encode(buffer).replace(/\+/g, 'æ').replace(/\//g, 'Æ').replace(/=/g, '');
1081
- }
1082
- $.$mol_base64_ae_encode = $mol_base64_ae_encode;
1083
- function $mol_base64_ae_decode(str) {
1084
- return $mol_base64_decode(str.replace(/æ/g, '+').replace(/Æ/g, '/'));
1288
+ function $mol_tree2_from_string(str, uri = '?') {
1289
+ const span = $mol_span.entire(uri, str);
1290
+ var root = $mol_tree2.list([], span);
1291
+ var stack = [root];
1292
+ var pos = 0, row = 0, min_indent = 0;
1293
+ while (str.length > pos) {
1294
+ var indent = 0;
1295
+ var line_start = pos;
1296
+ row++;
1297
+ while (str.length > pos && str[pos] == '\t') {
1298
+ indent++;
1299
+ pos++;
1300
+ }
1301
+ if (!root.kids.length) {
1302
+ min_indent = indent;
1303
+ }
1304
+ indent -= min_indent;
1305
+ if (indent < 0 || indent >= stack.length) {
1306
+ const sp = span.span(row, 1, pos - line_start);
1307
+ while (str.length > pos && str[pos] != '\n') {
1308
+ pos++;
1309
+ }
1310
+ if (indent < 0) {
1311
+ if (str.length > pos) {
1312
+ this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
1313
+ }
1314
+ }
1315
+ else {
1316
+ this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
1317
+ }
1318
+ }
1319
+ stack.length = indent + 1;
1320
+ var parent = stack[indent];
1321
+ while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
1322
+ var error_start = pos;
1323
+ while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
1324
+ pos++;
1325
+ }
1326
+ if (pos > error_start) {
1327
+ let line_end = str.indexOf('\n', pos);
1328
+ if (line_end === -1)
1329
+ line_end = str.length;
1330
+ const sp = span.span(row, error_start - line_start + 1, pos - error_start);
1331
+ this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
1332
+ }
1333
+ var type_start = pos;
1334
+ while (str.length > pos &&
1335
+ str[pos] != '\\' &&
1336
+ str[pos] != ' ' &&
1337
+ str[pos] != '\t' &&
1338
+ str[pos] != '\n') {
1339
+ pos++;
1340
+ }
1341
+ if (pos > type_start) {
1342
+ let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
1343
+ const parent_kids = parent.kids;
1344
+ parent_kids.push(next);
1345
+ parent = next;
1346
+ }
1347
+ if (str.length > pos && str[pos] == ' ') {
1348
+ pos++;
1349
+ }
1350
+ }
1351
+ if (str.length > pos && str[pos] == '\\') {
1352
+ var data_start = pos;
1353
+ while (str.length > pos && str[pos] != '\n') {
1354
+ pos++;
1355
+ }
1356
+ let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
1357
+ const parent_kids = parent.kids;
1358
+ parent_kids.push(next);
1359
+ parent = next;
1360
+ }
1361
+ if (str.length === pos && stack.length > 0) {
1362
+ const sp = span.span(row, pos - line_start + 1, 1);
1363
+ this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
1364
+ }
1365
+ stack.push(parent);
1366
+ pos++;
1367
+ }
1368
+ return root;
1085
1369
  }
1086
- $.$mol_base64_ae_decode = $mol_base64_ae_decode;
1370
+ $.$mol_tree2_from_string = $mol_tree2_from_string;
1087
1371
  })($ || ($ = {}));
1088
1372
 
1089
1373
  ;
1090
1374
  "use strict";
1091
1375
  var $;
1092
1376
  (function ($) {
1093
- class $mol_buffer extends DataView {
1094
- static from(array) {
1095
- if (typeof array === 'number')
1096
- array = new Uint8Array(array);
1097
- if (typeof array === 'string')
1098
- array = $mol_base64_ae_decode(array);
1099
- return new this(array.buffer, array.byteOffset, array.byteLength);
1100
- }
1101
- static toString() {
1102
- return $$.$mol_func_name(this);
1103
- }
1104
- getUint48(offset, LE = false) {
1105
- if (offset % 4) {
1106
- return this.getUint16(offset, LE) + this.getUint32(offset + 2, LE) * 2 ** 16;
1107
- }
1108
- else {
1109
- return this.getUint32(offset, LE) + this.getUint16(offset + 4, LE) * 2 ** 32;
1110
- }
1111
- }
1112
- setUint48(offset, value, LE = false) {
1113
- if (offset % 4) {
1114
- this.setUint16(offset, value & ((1 << 16) - 1), LE);
1115
- this.setUint32(offset + 2, (value / 2 ** 16) | 0, LE);
1116
- }
1117
- else {
1118
- this.setUint32(offset, value | 0, LE);
1119
- this.setUint16(offset + 4, (value / 2 ** 32) | 0, LE);
1120
- }
1121
- }
1122
- int8(offset, next) {
1123
- if (next === undefined)
1124
- return this.getInt8(offset);
1125
- if (next >= -(2 ** 7) && next < 2 ** 7)
1126
- return this.setInt8(offset, next), next;
1127
- $mol_fail(new Error(`Wrong int8 value ${next}`));
1128
- }
1129
- uint8(offset, next) {
1130
- if (next === undefined)
1131
- return this.getUint8(offset);
1132
- if (next >= 0 && next < 2 ** 8)
1133
- return this.setUint8(offset, next), next;
1134
- $mol_fail(new Error(`Wrong uint8 value ${next}`));
1135
- }
1136
- int16(offset, next) {
1137
- if (next === undefined)
1138
- return this.getInt16(offset, !!'LE');
1139
- if (next >= -(2 ** 15) && next < 2 ** 15)
1140
- return this.setInt16(offset, next, !!'LE'), next;
1141
- $mol_fail(new Error(`Wrong int16 value ${next}`));
1142
- }
1143
- uint16(offset, next) {
1144
- if (next === undefined)
1145
- return this.getUint16(offset, !!'LE');
1146
- if (next >= 0 && next < 2 ** 16)
1147
- return this.setUint16(offset, next, !!'LE'), next;
1148
- $mol_fail(new Error(`Wrong uint16 value ${next}`));
1149
- }
1150
- int32(offset, next) {
1151
- if (next === undefined)
1152
- return this.getInt32(offset, !!'LE');
1153
- if (next >= -(2 ** 31) && next < 2 ** 31)
1154
- return this.setInt32(offset, next, !!'LE'), next;
1155
- $mol_fail(new Error(`Wrong int32 value ${next}`));
1377
+ function $mol_tree2_from_json(json, span = $mol_span.unknown) {
1378
+ if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
1379
+ return new $mol_tree2(String(json), '', [], span);
1156
1380
  }
1157
- uint32(offset, next) {
1158
- if (next === undefined)
1159
- return this.getUint32(offset, !!'LE');
1160
- if (next >= 0 && next < 2 ** 32)
1161
- return this.setUint32(offset, next, !!'LE'), next;
1162
- $mol_fail(new Error(`Wrong uint32 value ${next}`));
1381
+ if (typeof json === 'string') {
1382
+ return $mol_tree2.data(json, [], span);
1163
1383
  }
1164
- uint48(offset, next) {
1165
- if (next === undefined)
1166
- return this.getUint48(offset, !!'LE');
1167
- if (next >= 0 && next < 2 ** 48)
1168
- return this.setUint48(offset, next, !!'LE'), next;
1169
- $mol_fail(new Error(`Wrong uint48 value ${next}`));
1384
+ if (Array.isArray(json)) {
1385
+ const sub = json.map(json => $mol_tree2_from_json(json, span));
1386
+ return new $mol_tree2('/', '', sub, span);
1170
1387
  }
1171
- int64(offset, next) {
1172
- if (next === undefined)
1173
- return this.getBigInt64(offset, !!'LE');
1174
- if (next >= -(2 ** 63) && next < 2 ** 63)
1175
- return this.setBigInt64(offset, next, !!'LE'), next;
1176
- $mol_fail(new Error(`Wrong int64 value ${next}`));
1388
+ if (ArrayBuffer.isView(json)) {
1389
+ const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
1390
+ return $mol_tree2.data(String.fromCharCode(...buf), [], span);
1177
1391
  }
1178
- uint64(offset, next) {
1179
- if (next === undefined)
1180
- return this.getBigUint64(offset, !!'LE');
1181
- if (next >= 0 && next < 2 ** 64)
1182
- return this.setBigUint64(offset, next, !!'LE'), next;
1183
- $mol_fail(new Error(`Wrong uint64 value ${next}`));
1392
+ if (json instanceof Date) {
1393
+ return new $mol_tree2('', json.toISOString(), [], span);
1184
1394
  }
1185
- float32(offset, next) {
1186
- if (next !== undefined)
1187
- this.setFloat32(offset, next, !!'LE');
1188
- return this.getFloat32(offset, !!'LE');
1395
+ if (typeof json.toJSON === 'function') {
1396
+ return $mol_tree2_from_json(json.toJSON());
1189
1397
  }
1190
- float64(offset, next) {
1191
- if (next !== undefined)
1192
- this.setFloat64(offset, next, !!'LE');
1193
- return this.getFloat64(offset, !!'LE');
1398
+ if (json.toString !== Object.prototype.toString) {
1399
+ return $mol_tree2.data(json.toString(), [], span);
1194
1400
  }
1195
- asArray() {
1196
- return new Uint8Array(this.buffer, this.byteOffset, this.byteLength);
1401
+ if (json instanceof Error) {
1402
+ const { name, message, stack } = json;
1403
+ json = { ...json, name, message, stack };
1197
1404
  }
1198
- toString() {
1199
- return $mol_base64_ae_encode(this.asArray());
1405
+ const sub = [];
1406
+ for (var key in json) {
1407
+ const val = json[key];
1408
+ if (val === undefined)
1409
+ continue;
1410
+ const subsub = $mol_tree2_from_json(val, span);
1411
+ if (/^[^\n\t\\ ]+$/.test(key)) {
1412
+ sub.push(new $mol_tree2(key, '', [subsub], span));
1413
+ }
1414
+ else {
1415
+ sub.push($mol_tree2.data(key, [subsub], span));
1416
+ }
1200
1417
  }
1418
+ return new $mol_tree2('*', '', sub, span);
1201
1419
  }
1202
- $.$mol_buffer = $mol_buffer;
1420
+ $.$mol_tree2_from_json = $mol_tree2_from_json;
1203
1421
  })($ || ($ = {}));
1204
1422
 
1205
1423
  ;
1206
1424
  "use strict";
1207
1425
  var $;
1208
1426
  (function ($) {
1209
- function $mol_base64_url_encode(buffer) {
1210
- return $mol_base64_encode(buffer).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
1427
+ class $mol_term_color {
1428
+ static reset = this.ansi(0, 0);
1429
+ static bold = this.ansi(1, 22);
1430
+ static italic = this.ansi(3, 23);
1431
+ static underline = this.ansi(4, 24);
1432
+ static inverse = this.ansi(7, 27);
1433
+ static hidden = this.ansi(8, 28);
1434
+ static strike = this.ansi(9, 29);
1435
+ static gray = this.ansi(90, 39);
1436
+ static red = this.ansi(91, 39);
1437
+ static green = this.ansi(92, 39);
1438
+ static yellow = this.ansi(93, 39);
1439
+ static blue = this.ansi(94, 39);
1440
+ static magenta = this.ansi(95, 39);
1441
+ static cyan = this.ansi(96, 39);
1442
+ static Gray = (str) => this.inverse(this.gray(str));
1443
+ static Red = (str) => this.inverse(this.red(str));
1444
+ static Green = (str) => this.inverse(this.green(str));
1445
+ static Yellow = (str) => this.inverse(this.yellow(str));
1446
+ static Blue = (str) => this.inverse(this.blue(str));
1447
+ static Magenta = (str) => this.inverse(this.magenta(str));
1448
+ static Cyan = (str) => this.inverse(this.cyan(str));
1449
+ static ansi(open, close) {
1450
+ if (typeof process === 'undefined')
1451
+ return String;
1452
+ if (!process.stdout.isTTY)
1453
+ return String;
1454
+ const prefix = `\x1b[${open}m`;
1455
+ const postfix = `\x1b[${close}m`;
1456
+ const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
1457
+ return function colorer(str) {
1458
+ str = String(str);
1459
+ if (str === '')
1460
+ return str;
1461
+ const suffix = str.replace(suffix_regexp, prefix);
1462
+ return prefix + suffix + postfix;
1463
+ };
1464
+ }
1211
1465
  }
1212
- $.$mol_base64_url_encode = $mol_base64_url_encode;
1213
- function $mol_base64_url_decode(str) {
1214
- return $mol_base64_decode(str.replace(/-/g, '+').replace(/_/g, '/'));
1466
+ $.$mol_term_color = $mol_term_color;
1467
+ })($ || ($ = {}));
1468
+
1469
+ ;
1470
+ "use strict";
1471
+ var $;
1472
+ (function ($) {
1473
+ function $mol_log3_node_make(level, output, type, color) {
1474
+ return function $mol_log3_logger(event) {
1475
+ if (!event.time)
1476
+ event = { time: new Date().toISOString(), ...event };
1477
+ let tree = this.$mol_tree2_from_json(event);
1478
+ tree = tree.struct(type, tree.kids);
1479
+ let str = color(tree.toString());
1480
+ this.console[level](str);
1481
+ const self = this;
1482
+ return () => self.console.groupEnd();
1483
+ };
1215
1484
  }
1216
- $.$mol_base64_url_decode = $mol_base64_url_decode;
1485
+ $.$mol_log3_node_make = $mol_log3_node_make;
1486
+ $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
1487
+ $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
1488
+ $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
1489
+ $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
1490
+ $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
1491
+ $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
1217
1492
  })($ || ($ = {}));
1218
1493
 
1219
1494
  ;
1220
1495
  "use strict";
1221
1496
  var $;
1222
1497
  (function ($) {
1223
- class $mol_wrapper extends $mol_object2 {
1224
- static wrap;
1225
- static run(task) {
1226
- return this.func(task)();
1227
- }
1228
- static func(func) {
1229
- return this.wrap(func);
1230
- }
1231
- static get class() {
1232
- return (Class) => {
1233
- const construct = (target, args) => new Class(...args);
1234
- const handler = {
1235
- construct: this.func(construct)
1236
- };
1237
- handler[Symbol.toStringTag] = Class.name + '#';
1238
- return new Proxy(Class, handler);
1498
+ class $mol_wire_task extends $mol_wire_fiber {
1499
+ static getter(task) {
1500
+ return function $mol_wire_task_get(host, args) {
1501
+ const sub = $mol_wire_auto();
1502
+ const existen = sub?.track_next();
1503
+ reuse: if (existen) {
1504
+ if (!existen.temp)
1505
+ break reuse;
1506
+ if (existen.host !== host)
1507
+ break reuse;
1508
+ if (existen.task !== task)
1509
+ break reuse;
1510
+ if (!$mol_compare_deep(existen.args, args))
1511
+ break reuse;
1512
+ return existen;
1513
+ }
1514
+ const next = new $mol_wire_task(`${host?.[Symbol.toStringTag] ?? host}.${task.name}<#>`, task, host, args);
1515
+ if (existen?.temp) {
1516
+ $$.$mol_log3_warn({
1517
+ place: '$mol_wire_task',
1518
+ message: `Non idempotency`,
1519
+ existen,
1520
+ next,
1521
+ hint: 'Ignore it',
1522
+ });
1523
+ }
1524
+ return next;
1239
1525
  };
1240
1526
  }
1241
- static get method() {
1242
- return (obj, name, descr) => {
1243
- descr.value = this.func(descr.value);
1244
- return descr;
1245
- };
1527
+ get temp() {
1528
+ return true;
1246
1529
  }
1247
- static get field() {
1248
- return (obj, name, descr) => {
1249
- descr.get = descr.set = this.func(descr.get);
1250
- return descr;
1251
- };
1530
+ complete() {
1531
+ if ($mol_promise_like(this.cache))
1532
+ return;
1533
+ this.destructor();
1534
+ }
1535
+ put(next) {
1536
+ const prev = this.cache;
1537
+ this.cache = next;
1538
+ if ($mol_promise_like(next)) {
1539
+ this.cursor = $mol_wire_cursor.fresh;
1540
+ if (next !== prev)
1541
+ this.emit();
1542
+ return next;
1543
+ }
1544
+ this.cursor = $mol_wire_cursor.final;
1545
+ if (this.sub_empty)
1546
+ this.destructor();
1547
+ else if (next !== prev)
1548
+ this.emit();
1549
+ return next;
1252
1550
  }
1253
1551
  }
1254
- $.$mol_wrapper = $mol_wrapper;
1552
+ $.$mol_wire_task = $mol_wire_task;
1255
1553
  })($ || ($ = {}));
1256
1554
 
1257
1555
  ;
1258
1556
  "use strict";
1259
1557
  var $;
1260
1558
  (function ($) {
1261
- class $mol_memo extends $mol_wrapper {
1262
- static wrap(task) {
1263
- const store = new WeakMap();
1264
- return function (next) {
1265
- if (next === undefined && store.has(this))
1266
- return store.get(this);
1267
- const val = task.call(this, next) ?? next;
1268
- store.set(this, val);
1269
- return val;
1270
- };
1271
- }
1559
+ function $mol_wire_sync(obj) {
1560
+ return new Proxy(obj, {
1561
+ get(obj, field) {
1562
+ const val = obj[field];
1563
+ if (typeof val !== 'function')
1564
+ return val;
1565
+ const temp = $mol_wire_task.getter(val);
1566
+ return function $mol_wire_sync(...args) {
1567
+ const fiber = temp(obj, args);
1568
+ return fiber.sync();
1569
+ };
1570
+ },
1571
+ apply(obj, self, args) {
1572
+ const temp = $mol_wire_task.getter(obj);
1573
+ const fiber = temp(self, args);
1574
+ return fiber.sync();
1575
+ },
1576
+ });
1272
1577
  }
1273
- $.$mol_memo = $mol_memo;
1578
+ $.$mol_wire_sync = $mol_wire_sync;
1274
1579
  })($ || ($ = {}));
1275
1580
 
1276
1581
  ;
1277
1582
  "use strict";
1278
1583
  var $;
1279
1584
  (function ($) {
1280
- const algorithm = {
1281
- name: 'ECDSA',
1282
- hash: 'SHA-256',
1283
- namedCurve: "P-256",
1284
- };
1285
- class $mol_crypto_key extends $mol_buffer {
1286
- static from(serial) {
1287
- if (typeof serial === 'string') {
1288
- serial = new Uint8Array([
1289
- ...$mol_base64_url_decode(serial.slice(0, 43)),
1290
- ...$mol_base64_url_decode(serial.slice(43, 86)),
1291
- ...$mol_base64_url_decode(serial.slice(86, 129)),
1292
- ]);
1293
- }
1294
- return super.from(serial);
1295
- }
1296
- asArray() {
1297
- return new Uint8Array(this.buffer, this.byteOffset, this.byteLength);
1298
- }
1299
- toString() {
1300
- const arr = this.asArray();
1301
- return $mol_base64_url_encode(arr.subarray(0, 32))
1302
- + $mol_base64_url_encode(arr.subarray(32, 64))
1303
- + $mol_base64_url_encode(arr.subarray(64));
1304
- }
1585
+ const catched = new WeakMap();
1586
+ function $mol_fail_catch(error) {
1587
+ if (typeof error !== 'object')
1588
+ return false;
1589
+ if ($mol_promise_like(error))
1590
+ $mol_fail_hidden(error);
1591
+ if (catched.get(error))
1592
+ return false;
1593
+ catched.set(error, true);
1594
+ return true;
1305
1595
  }
1306
- __decorate([
1307
- $mol_memo.method
1308
- ], $mol_crypto_key.prototype, "toString", null);
1309
- $.$mol_crypto_key = $mol_crypto_key;
1310
- class $mol_crypto_key_public extends $mol_crypto_key {
1311
- static size_str = 86;
1312
- static size_bin = 64;
1313
- async native() {
1314
- const str = this.toString();
1315
- return $mol_crypto_native.subtle.importKey('jwk', {
1316
- crv: "P-256",
1317
- ext: true,
1318
- key_ops: ['verify'],
1319
- kty: "EC",
1320
- x: str.slice(0, 43),
1321
- y: str.slice(43, 86),
1322
- }, algorithm, true, ['verify']);
1323
- }
1324
- async verify(data, sign) {
1325
- return await $mol_crypto_native.subtle.verify(algorithm, await this.native(), sign, data);
1326
- }
1596
+ $.$mol_fail_catch = $mol_fail_catch;
1597
+ })($ || ($ = {}));
1598
+
1599
+ ;
1600
+ "use strict";
1601
+ var $;
1602
+ (function ($) {
1603
+ function $mol_fail_log(error) {
1604
+ if ($mol_promise_like(error))
1605
+ return false;
1606
+ if (!$mol_fail_catch(error))
1607
+ return false;
1608
+ console.error(error);
1609
+ return true;
1327
1610
  }
1328
- __decorate([
1329
- $mol_memo.method
1330
- ], $mol_crypto_key_public.prototype, "native", null);
1331
- $.$mol_crypto_key_public = $mol_crypto_key_public;
1332
- class $mol_crypto_key_private extends $mol_crypto_key {
1333
- static size_str = 129;
1334
- static size_bin = 96;
1335
- static size_sign = 64;
1336
- static async generate() {
1337
- const pair = await $mol_crypto_native.subtle.generateKey(algorithm, true, ['sign', 'verify']);
1338
- const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', pair.privateKey);
1339
- return this.from(x + y + d);
1340
- }
1341
- async native() {
1342
- const str = this.toString();
1343
- return await $mol_crypto_native.subtle.importKey('jwk', {
1344
- crv: "P-256",
1345
- ext: true,
1346
- key_ops: ['sign'],
1347
- kty: "EC",
1348
- x: str.slice(0, 43),
1349
- y: str.slice(43, 86),
1350
- d: str.slice(86, 129),
1351
- }, algorithm, true, ['sign']);
1611
+ $.$mol_fail_log = $mol_fail_log;
1612
+ })($ || ($ = {}));
1613
+
1614
+ ;
1615
+ "use strict";
1616
+ var $node = new Proxy({ require }, {
1617
+ get(target, name, wrapper) {
1618
+ if (target[name])
1619
+ return target[name];
1620
+ const mod = target.require('module');
1621
+ if (mod.builtinModules.indexOf(name) >= 0)
1622
+ return target.require(name);
1623
+ if (name[0] === '.')
1624
+ return target.require(name);
1625
+ const path = target.require('path');
1626
+ const fs = target.require('fs');
1627
+ let dir = path.resolve('.');
1628
+ const suffix = `./node_modules/${name}`;
1629
+ const $$ = $;
1630
+ while (!fs.existsSync(path.join(dir, suffix))) {
1631
+ const parent = path.resolve(dir, '..');
1632
+ if (parent === dir) {
1633
+ $$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
1634
+ try {
1635
+ $$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
1636
+ }
1637
+ catch { }
1638
+ break;
1639
+ }
1640
+ else {
1641
+ dir = parent;
1642
+ }
1352
1643
  }
1353
- public() {
1354
- return new $mol_crypto_key_public(this.buffer, this.byteOffset, this.byteOffset + 64);
1644
+ try {
1645
+ return $.$mol_wire_sync(target).require(name);
1355
1646
  }
1356
- async sign(data) {
1357
- return await $mol_crypto_native.subtle.sign(algorithm, await this.native(), data);
1647
+ catch (error) {
1648
+ if (error.code === 'ERR_REQUIRE_ESM') {
1649
+ return importSync(name);
1650
+ }
1651
+ $.$mol_fail_log(error);
1652
+ return null;
1358
1653
  }
1654
+ },
1655
+ set(target, name, value) {
1656
+ target[name] = value;
1657
+ return true;
1658
+ },
1659
+ });
1660
+ const importAsync = async (uri) => import(uri);
1661
+ const importSync = $.$mol_wire_sync(importAsync);
1662
+ require = (req => Object.assign(function require(name) {
1663
+ return $node[name];
1664
+ }, req))(require);
1665
+
1666
+ ;
1667
+ "use strict";
1668
+ var $;
1669
+ (function ($) {
1670
+ function $mol_env() {
1671
+ return {};
1359
1672
  }
1360
- __decorate([
1361
- $mol_memo.method
1362
- ], $mol_crypto_key_private.prototype, "native", null);
1363
- __decorate([
1364
- $mol_memo.method
1365
- ], $mol_crypto_key_private.prototype, "public", null);
1366
- $.$mol_crypto_key_private = $mol_crypto_key_private;
1673
+ $.$mol_env = $mol_env;
1367
1674
  })($ || ($ = {}));
1368
1675
 
1369
1676
  ;
1370
1677
  "use strict";
1371
1678
  var $;
1372
1679
  (function ($) {
1373
- let sponge = new Uint32Array(80);
1374
- function $mol_crypto_hash(data) {
1375
- const bits = data.byteLength << 3;
1376
- const kbits = bits >> 5;
1377
- const kword = 0x80 << (24 - bits & 0b11111);
1378
- const bytes = 16 + (bits + 64 >>> 9 << 4);
1379
- const klens = bytes - 1;
1380
- const words = new Int32Array(data.buffer, data.byteOffset, data.byteLength >> 2);
1381
- let tail = 0;
1382
- for (let i = words.length * 4; i < data.length; ++i) {
1383
- tail |= data[i] << (i << 3 & 0b11000);
1384
- }
1385
- const hash = new Int32Array([1732584193, -271733879, -1732584194, 271733878, -1009589776]);
1386
- for (let i = 0; i < bytes; i += 16) {
1387
- let h0 = hash[0];
1388
- let h1 = hash[1];
1389
- let h2 = hash[2];
1390
- let h3 = hash[3];
1391
- let h4 = hash[4];
1392
- for (let j = 0; j < 80; ++j) {
1393
- let turn;
1394
- if (j < 16) {
1395
- const k = i + j;
1396
- if (k === klens) {
1397
- sponge[j] = bits;
1398
- }
1399
- else {
1400
- let word = k === words.length ? tail :
1401
- k > words.length ? 0 :
1402
- words[k];
1403
- word = word << 24 | word << 8 & 0xFF0000 | word >>> 8 & 0xFF00 | word >>> 24 & 0xFF;
1404
- if (k === kbits)
1405
- word |= kword;
1406
- sponge[j] = word;
1407
- }
1408
- turn = (h1 & h2 | ~h1 & h3) + 1518500249;
1409
- }
1410
- else {
1411
- const shuffle = sponge[j - 3] ^ sponge[j - 8] ^ sponge[j - 14] ^ sponge[j - 16];
1412
- sponge[j] = shuffle << 1 | shuffle >>> 31;
1413
- turn =
1414
- j < 20 ? (h1 & h2 | ~h1 & h3) + 1518500249 :
1415
- j < 40 ? (h1 ^ h2 ^ h3) + 1859775393 :
1416
- j < 60 ? (h1 & h2 | h1 & h3 | h2 & h3) - 1894007588 :
1417
- (h1 ^ h2 ^ h3) - 899497514;
1418
- }
1419
- const next = turn + h4 + (sponge[j] >>> 0) + ((h0 << 5) | (h0 >>> 27));
1420
- h4 = h3;
1421
- h3 = h2;
1422
- h2 = (h1 << 30) | (h1 >>> 2);
1423
- h1 = h0;
1424
- h0 = next;
1425
- }
1426
- hash[0] += h0;
1427
- hash[1] += h1;
1428
- hash[2] += h2;
1429
- hash[3] += h3;
1430
- hash[4] += h4;
1431
- }
1432
- for (let i = 0; i < 20; ++i) {
1433
- const word = hash[i];
1434
- hash[i] = word << 24 | word << 8 & 0xFF0000 | word >>> 8 & 0xFF00 | word >>> 24 & 0xFF;
1680
+ $.$mol_env = function $mol_env() {
1681
+ return this.process.env;
1682
+ };
1683
+ })($ || ($ = {}));
1684
+
1685
+ ;
1686
+ "use strict";
1687
+ var $;
1688
+ (function ($) {
1689
+ function $mol_exec(dir, command, ...args) {
1690
+ let [app, ...args0] = command.split(' ');
1691
+ args = [...args0, ...args];
1692
+ this.$mol_log3_come({
1693
+ place: '$mol_exec',
1694
+ dir: $node.path.relative('', dir),
1695
+ message: 'Run',
1696
+ command: `${app} ${args.join(' ')}`,
1697
+ });
1698
+ var res = $node['child_process'].spawnSync(app, args, {
1699
+ cwd: $node.path.resolve(dir),
1700
+ shell: true,
1701
+ env: this.$mol_env(),
1702
+ });
1703
+ if (res.status || res.error) {
1704
+ return $mol_fail(res.error || new Error(res.stderr.toString(), { cause: res.stdout }));
1435
1705
  }
1436
- return new Uint8Array(hash.buffer);
1706
+ if (!res.stdout)
1707
+ res.stdout = Buffer.from([]);
1708
+ return res;
1437
1709
  }
1438
- $.$mol_crypto_hash = $mol_crypto_hash;
1710
+ $.$mol_exec = $mol_exec;
1439
1711
  })($ || ($ = {}));
1440
1712
 
1441
1713
  ;
1442
1714
  "use strict";
1443
1715
  var $;
1444
1716
  (function ($) {
1445
- function $mol_crypto_salt() {
1446
- return $mol_crypto_native.getRandomValues(new Uint8Array(16));
1717
+ $.$mol_crypto_native = $node.crypto.webcrypto;
1718
+ })($ || ($ = {}));
1719
+
1720
+ ;
1721
+ "use strict";
1722
+ var $;
1723
+ (function ($) {
1724
+ const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
1725
+ const encoder = new TextEncoder();
1726
+ function $mol_charset_encode(value) {
1727
+ return encoder.encode(value);
1447
1728
  }
1448
- $.$mol_crypto_salt = $mol_crypto_salt;
1729
+ $.$mol_charset_encode = $mol_charset_encode;
1449
1730
  })($ || ($ = {}));
1450
1731
 
1451
1732
  ;
1452
1733
  "use strict";
1453
1734
  var $;
1454
- (function ($_1) {
1455
- function $mol_test(set) {
1456
- for (let name in set) {
1457
- const code = set[name];
1458
- const test = (typeof code === 'string') ? new Function('', code) : code;
1459
- $_1.$mol_test_all.push(test);
1735
+ (function ($) {
1736
+ const algorithm = {
1737
+ name: 'AES-CBC',
1738
+ length: 128,
1739
+ tagLength: 32,
1740
+ };
1741
+ class $mol_crypto_secret extends Object {
1742
+ native;
1743
+ static size = 16;
1744
+ constructor(native) {
1745
+ super();
1746
+ this.native = native;
1460
1747
  }
1461
- $mol_test_schedule();
1462
- }
1463
- $_1.$mol_test = $mol_test;
1464
- $_1.$mol_test_mocks = [];
1465
- $_1.$mol_test_all = [];
1466
- async function $mol_test_run() {
1467
- for (var test of $_1.$mol_test_all) {
1468
- let context = Object.create($$);
1469
- for (let mock of $_1.$mol_test_mocks)
1470
- await mock(context);
1471
- const res = test(context);
1472
- if ($mol_promise_like(res)) {
1473
- await new Promise((done, fail) => {
1474
- res.then(done, fail);
1475
- setTimeout(() => fail(new Error('Test timeout: ' + test.name)), 1000);
1476
- });
1748
+ static async generate() {
1749
+ return new this(await $mol_crypto_native.subtle.generateKey(algorithm, true, ['encrypt', 'decrypt']));
1750
+ }
1751
+ static async from(serial) {
1752
+ if (typeof serial === 'string') {
1753
+ serial = $mol_charset_encode(serial);
1754
+ serial = await $mol_crypto_native.subtle.digest('SHA-256', serial);
1477
1755
  }
1756
+ return new this(await $mol_crypto_native.subtle.importKey('raw', serial, algorithm, true, ['encrypt', 'decrypt']));
1478
1757
  }
1479
- $$.$mol_log3_done({
1480
- place: '$mol_test',
1481
- message: 'All tests passed',
1482
- count: $_1.$mol_test_all.length,
1483
- });
1484
- }
1485
- $_1.$mol_test_run = $mol_test_run;
1486
- let scheduled = false;
1487
- function $mol_test_schedule() {
1488
- if (scheduled)
1489
- return;
1490
- scheduled = true;
1491
- setTimeout(async () => {
1492
- scheduled = false;
1493
- await $mol_test_run();
1494
- $$.$mol_test_complete();
1495
- }, 1000);
1496
- }
1497
- $_1.$mol_test_schedule = $mol_test_schedule;
1498
- $_1.$mol_test_mocks.push(context => {
1499
- let seed = 0;
1500
- context.Math = Object.create(Math);
1501
- context.Math.random = () => Math.sin(seed++);
1502
- const forbidden = ['XMLHttpRequest', 'fetch'];
1503
- for (let api of forbidden) {
1504
- context[api] = new Proxy(function () { }, {
1505
- get() {
1506
- $mol_fail_hidden(new Error(`${api} is forbidden in tests`));
1507
- },
1508
- apply() {
1509
- $mol_fail_hidden(new Error(`${api} is forbidden in tests`));
1510
- },
1511
- });
1758
+ static async derive(private_serial, public_serial) {
1759
+ const ecdh = { name: "ECDH", namedCurve: "P-256" };
1760
+ const jwk = { crv: 'P-256', ext: true, kty: 'EC' };
1761
+ const private_key = await $mol_crypto_native.subtle.importKey('jwk', {
1762
+ ...jwk,
1763
+ key_ops: ['deriveKey'],
1764
+ x: private_serial.slice(0, 43),
1765
+ y: private_serial.slice(43, 86),
1766
+ d: private_serial.slice(86, 129),
1767
+ }, ecdh, true, ['deriveKey']);
1768
+ const public_key = await $mol_crypto_native.subtle.importKey('jwk', {
1769
+ ...jwk,
1770
+ key_ops: [],
1771
+ x: public_serial.slice(0, 43),
1772
+ y: public_serial.slice(43, 86),
1773
+ }, ecdh, true, []);
1774
+ const secret = await $mol_crypto_native.subtle.deriveKey({
1775
+ name: "ECDH",
1776
+ public: public_key,
1777
+ }, private_key, algorithm, true, ["encrypt", "decrypt"]);
1778
+ return new this(secret);
1512
1779
  }
1513
- });
1514
- $mol_test({
1515
- 'mocked Math.random'($) {
1516
- console.assert($.Math.random() === 0);
1517
- console.assert($.Math.random() === Math.sin(1));
1518
- },
1519
- 'forbidden XMLHttpRequest'($) {
1520
- try {
1521
- console.assert(void new $.XMLHttpRequest);
1522
- }
1523
- catch (error) {
1524
- console.assert(error.message === 'XMLHttpRequest is forbidden in tests');
1525
- }
1526
- },
1527
- 'forbidden fetch'($) {
1528
- try {
1529
- console.assert(void $.fetch(''));
1530
- }
1531
- catch (error) {
1532
- console.assert(error.message === 'fetch is forbidden in tests');
1533
- }
1534
- },
1535
- });
1780
+ async serial() {
1781
+ return await $mol_crypto_native.subtle.exportKey('raw', this.native);
1782
+ }
1783
+ async encrypt(open, salt) {
1784
+ return await $mol_crypto_native.subtle.encrypt({
1785
+ ...algorithm,
1786
+ iv: salt,
1787
+ }, this.native, open);
1788
+ }
1789
+ async decrypt(closed, salt) {
1790
+ return await $mol_crypto_native.subtle.decrypt({
1791
+ ...algorithm,
1792
+ iv: salt,
1793
+ }, this.native, closed);
1794
+ }
1795
+ }
1796
+ $.$mol_crypto_secret = $mol_crypto_secret;
1536
1797
  })($ || ($ = {}));
1537
1798
 
1538
1799
  ;
1539
1800
  "use strict";
1540
1801
  var $;
1541
1802
  (function ($) {
1542
- function $mol_test_complete() {
1543
- process.exit(0);
1544
- }
1545
- $.$mol_test_complete = $mol_test_complete;
1546
1803
  })($ || ($ = {}));
1547
1804
 
1548
1805
  ;
1549
1806
  "use strict";
1550
1807
  var $;
1551
- (function ($_1) {
1552
- $mol_test_mocks.push($ => $.$mol_fail_log = () => false);
1808
+ (function ($) {
1809
+ $.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
1553
1810
  })($ || ($ = {}));
1554
1811
 
1555
1812
  ;
1556
1813
  "use strict";
1557
1814
  var $;
1558
- (function ($_1) {
1559
- $mol_test_mocks.push($ => {
1560
- $.$mol_log3_come = () => { };
1561
- $.$mol_log3_done = () => { };
1562
- $.$mol_log3_fail = () => { };
1563
- $.$mol_log3_warn = () => { };
1564
- $.$mol_log3_rise = () => { };
1565
- $.$mol_log3_area = () => () => { };
1566
- });
1815
+ (function ($) {
1816
+ async function $mol_crypto_secret_id() {
1817
+ const signed = this.$mol_dom_context.localStorage.getItem('$mol_crypto_secret');
1818
+ if (signed === '')
1819
+ return await this.$mol_crypto_secret_id_get();
1820
+ const id = await this.$mol_crypto_secret_id_new();
1821
+ this.$mol_dom_context.localStorage.setItem('$mol_crypto_secret', '');
1822
+ return id;
1823
+ }
1824
+ $.$mol_crypto_secret_id = $mol_crypto_secret_id;
1825
+ async function $mol_crypto_secret_id_new() {
1826
+ const cred = await this.$mol_dom_context.navigator.credentials.create({
1827
+ publicKey: {
1828
+ rp: {
1829
+ name: "$mol_crypto_id",
1830
+ },
1831
+ user: {
1832
+ id: new Uint8Array([0]),
1833
+ name: "",
1834
+ displayName: ""
1835
+ },
1836
+ pubKeyCredParams: [
1837
+ { type: "public-key", alg: -7 },
1838
+ { type: "public-key", alg: -257 },
1839
+ ],
1840
+ challenge: new Uint8Array().buffer,
1841
+ },
1842
+ });
1843
+ return $mol_crypto_secret.from(cred.rawId);
1844
+ }
1845
+ $.$mol_crypto_secret_id_new = $mol_crypto_secret_id_new;
1846
+ async function $mol_crypto_secret_id_get() {
1847
+ const cred = await this.$mol_dom_context.navigator.credentials.get({
1848
+ mediation: 'silent',
1849
+ publicKey: {
1850
+ userVerification: 'discouraged',
1851
+ challenge: new Uint8Array().buffer,
1852
+ },
1853
+ });
1854
+ return $mol_crypto_secret.from(cred.rawId);
1855
+ }
1856
+ $.$mol_crypto_secret_id_get = $mol_crypto_secret_id_get;
1567
1857
  })($ || ($ = {}));
1568
1858
 
1569
1859
  ;
1570
1860
  "use strict";
1861
+ var $;
1862
+ (function ($) {
1863
+ function $mol_base64_encode(src) {
1864
+ throw new Error('Not implemented');
1865
+ }
1866
+ $.$mol_base64_encode = $mol_base64_encode;
1867
+ })($ || ($ = {}));
1571
1868
 
1572
1869
  ;
1573
1870
  "use strict";
1871
+ var $;
1872
+ (function ($) {
1873
+ function $mol_base64_encode_node(str) {
1874
+ if (!str)
1875
+ return '';
1876
+ if (Buffer.isBuffer(str))
1877
+ return str.toString('base64');
1878
+ return Buffer.from(str).toString('base64');
1879
+ }
1880
+ $.$mol_base64_encode_node = $mol_base64_encode_node;
1881
+ $.$mol_base64_encode = $mol_base64_encode_node;
1882
+ })($ || ($ = {}));
1574
1883
 
1575
1884
  ;
1576
1885
  "use strict";
1886
+ var $;
1887
+ (function ($) {
1888
+ function $mol_base64_decode(base64) {
1889
+ throw new Error('Not implemented');
1890
+ }
1891
+ $.$mol_base64_decode = $mol_base64_decode;
1892
+ })($ || ($ = {}));
1577
1893
 
1578
1894
  ;
1579
1895
  "use strict";
1896
+ var $;
1897
+ (function ($) {
1898
+ function $mol_base64_decode_node(base64Str) {
1899
+ base64Str = base64Str.replace(/-/g, '+').replace(/_/g, '/');
1900
+ const buffer = Buffer.from(base64Str, 'base64');
1901
+ return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1902
+ }
1903
+ $.$mol_base64_decode_node = $mol_base64_decode_node;
1904
+ $.$mol_base64_decode = $mol_base64_decode_node;
1905
+ })($ || ($ = {}));
1580
1906
 
1581
1907
  ;
1582
1908
  "use strict";
1583
-
1584
- ;
1585
- "use strict";
1909
+ var $;
1910
+ (function ($) {
1911
+ function $mol_base64_ae_encode(buffer) {
1912
+ return $mol_base64_encode(buffer).replace(/\+/g, 'æ').replace(/\//g, 'Æ').replace(/=/g, '');
1913
+ }
1914
+ $.$mol_base64_ae_encode = $mol_base64_ae_encode;
1915
+ function $mol_base64_ae_decode(str) {
1916
+ return $mol_base64_decode(str.replace(/æ/g, '+').replace(/Æ/g, '/'));
1917
+ }
1918
+ $.$mol_base64_ae_decode = $mol_base64_ae_decode;
1919
+ })($ || ($ = {}));
1586
1920
 
1587
1921
  ;
1588
1922
  "use strict";
1589
1923
  var $;
1590
1924
  (function ($) {
1591
- function $mol_dom_render_children(el, childNodes) {
1592
- const node_set = new Set(childNodes);
1593
- let nextNode = el.firstChild;
1594
- for (let view of childNodes) {
1595
- if (view == null)
1596
- continue;
1597
- if (view instanceof $mol_dom_context.Node) {
1598
- while (true) {
1599
- if (!nextNode) {
1600
- el.appendChild(view);
1601
- break;
1602
- }
1603
- if (nextNode == view) {
1604
- nextNode = nextNode.nextSibling;
1605
- break;
1606
- }
1607
- else {
1608
- if (node_set.has(nextNode)) {
1609
- el.insertBefore(view, nextNode);
1610
- break;
1611
- }
1612
- else {
1613
- const nn = nextNode.nextSibling;
1614
- el.removeChild(nextNode);
1615
- nextNode = nn;
1616
- }
1617
- }
1618
- }
1925
+ class $mol_buffer extends DataView {
1926
+ static from(array) {
1927
+ if (typeof array === 'number')
1928
+ array = new Uint8Array(array);
1929
+ if (typeof array === 'string')
1930
+ array = $mol_base64_ae_decode(array);
1931
+ return new this(array.buffer, array.byteOffset, array.byteLength);
1932
+ }
1933
+ static toString() {
1934
+ return $$.$mol_func_name(this);
1935
+ }
1936
+ getUint48(offset, LE = false) {
1937
+ if (offset % 4) {
1938
+ return this.getUint16(offset, LE) + this.getUint32(offset + 2, LE) * 2 ** 16;
1619
1939
  }
1620
1940
  else {
1621
- if (nextNode && nextNode.nodeName === '#text') {
1622
- const str = String(view);
1623
- if (nextNode.nodeValue !== str)
1624
- nextNode.nodeValue = str;
1625
- nextNode = nextNode.nextSibling;
1626
- }
1627
- else {
1628
- const textNode = $mol_dom_context.document.createTextNode(String(view));
1629
- el.insertBefore(textNode, nextNode);
1630
- }
1941
+ return this.getUint32(offset, LE) + this.getUint16(offset + 4, LE) * 2 ** 32;
1631
1942
  }
1632
1943
  }
1633
- while (nextNode) {
1634
- const currNode = nextNode;
1635
- nextNode = currNode.nextSibling;
1636
- el.removeChild(currNode);
1944
+ setUint48(offset, value, LE = false) {
1945
+ if (offset % 4) {
1946
+ this.setUint16(offset, value & ((1 << 16) - 1), LE);
1947
+ this.setUint32(offset + 2, (value / 2 ** 16) | 0, LE);
1948
+ }
1949
+ else {
1950
+ this.setUint32(offset, value | 0, LE);
1951
+ this.setUint16(offset + 4, (value / 2 ** 32) | 0, LE);
1952
+ }
1953
+ }
1954
+ int8(offset, next) {
1955
+ if (next === undefined)
1956
+ return this.getInt8(offset);
1957
+ if (next >= -(2 ** 7) && next < 2 ** 7)
1958
+ return this.setInt8(offset, next), next;
1959
+ $mol_fail(new Error(`Wrong int8 value ${next}`));
1960
+ }
1961
+ uint8(offset, next) {
1962
+ if (next === undefined)
1963
+ return this.getUint8(offset);
1964
+ if (next >= 0 && next < 2 ** 8)
1965
+ return this.setUint8(offset, next), next;
1966
+ $mol_fail(new Error(`Wrong uint8 value ${next}`));
1967
+ }
1968
+ int16(offset, next) {
1969
+ if (next === undefined)
1970
+ return this.getInt16(offset, !!'LE');
1971
+ if (next >= -(2 ** 15) && next < 2 ** 15)
1972
+ return this.setInt16(offset, next, !!'LE'), next;
1973
+ $mol_fail(new Error(`Wrong int16 value ${next}`));
1974
+ }
1975
+ uint16(offset, next) {
1976
+ if (next === undefined)
1977
+ return this.getUint16(offset, !!'LE');
1978
+ if (next >= 0 && next < 2 ** 16)
1979
+ return this.setUint16(offset, next, !!'LE'), next;
1980
+ $mol_fail(new Error(`Wrong uint16 value ${next}`));
1981
+ }
1982
+ int32(offset, next) {
1983
+ if (next === undefined)
1984
+ return this.getInt32(offset, !!'LE');
1985
+ if (next >= -(2 ** 31) && next < 2 ** 31)
1986
+ return this.setInt32(offset, next, !!'LE'), next;
1987
+ $mol_fail(new Error(`Wrong int32 value ${next}`));
1988
+ }
1989
+ uint32(offset, next) {
1990
+ if (next === undefined)
1991
+ return this.getUint32(offset, !!'LE');
1992
+ if (next >= 0 && next < 2 ** 32)
1993
+ return this.setUint32(offset, next, !!'LE'), next;
1994
+ $mol_fail(new Error(`Wrong uint32 value ${next}`));
1995
+ }
1996
+ uint48(offset, next) {
1997
+ if (next === undefined)
1998
+ return this.getUint48(offset, !!'LE');
1999
+ if (next >= 0 && next < 2 ** 48)
2000
+ return this.setUint48(offset, next, !!'LE'), next;
2001
+ $mol_fail(new Error(`Wrong uint48 value ${next}`));
2002
+ }
2003
+ int64(offset, next) {
2004
+ if (next === undefined)
2005
+ return this.getBigInt64(offset, !!'LE');
2006
+ if (next >= -(2 ** 63) && next < 2 ** 63)
2007
+ return this.setBigInt64(offset, next, !!'LE'), next;
2008
+ $mol_fail(new Error(`Wrong int64 value ${next}`));
2009
+ }
2010
+ uint64(offset, next) {
2011
+ if (next === undefined)
2012
+ return this.getBigUint64(offset, !!'LE');
2013
+ if (next >= 0 && next < 2 ** 64)
2014
+ return this.setBigUint64(offset, next, !!'LE'), next;
2015
+ $mol_fail(new Error(`Wrong uint64 value ${next}`));
2016
+ }
2017
+ float32(offset, next) {
2018
+ if (next !== undefined)
2019
+ this.setFloat32(offset, next, !!'LE');
2020
+ return this.getFloat32(offset, !!'LE');
2021
+ }
2022
+ float64(offset, next) {
2023
+ if (next !== undefined)
2024
+ this.setFloat64(offset, next, !!'LE');
2025
+ return this.getFloat64(offset, !!'LE');
2026
+ }
2027
+ asArray() {
2028
+ return new Uint8Array(this.buffer, this.byteOffset, this.byteLength);
2029
+ }
2030
+ toString() {
2031
+ return $mol_base64_ae_encode(this.asArray());
1637
2032
  }
1638
2033
  }
1639
- $.$mol_dom_render_children = $mol_dom_render_children;
2034
+ $.$mol_buffer = $mol_buffer;
1640
2035
  })($ || ($ = {}));
1641
2036
 
1642
2037
  ;
1643
2038
  "use strict";
2039
+ var $;
2040
+ (function ($) {
2041
+ function $mol_base64_url_encode(buffer) {
2042
+ return $mol_base64_encode(buffer).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
2043
+ }
2044
+ $.$mol_base64_url_encode = $mol_base64_url_encode;
2045
+ function $mol_base64_url_decode(str) {
2046
+ return $mol_base64_decode(str.replace(/-/g, '+').replace(/_/g, '/'));
2047
+ }
2048
+ $.$mol_base64_url_decode = $mol_base64_url_decode;
2049
+ })($ || ($ = {}));
1644
2050
 
1645
2051
  ;
1646
2052
  "use strict";
2053
+ var $;
2054
+ (function ($) {
2055
+ class $mol_wrapper extends $mol_object2 {
2056
+ static wrap;
2057
+ static run(task) {
2058
+ return this.func(task)();
2059
+ }
2060
+ static func(func) {
2061
+ return this.wrap(func);
2062
+ }
2063
+ static get class() {
2064
+ return (Class) => {
2065
+ const construct = (target, args) => new Class(...args);
2066
+ const handler = {
2067
+ construct: this.func(construct)
2068
+ };
2069
+ handler[Symbol.toStringTag] = Class.name + '#';
2070
+ return new Proxy(Class, handler);
2071
+ };
2072
+ }
2073
+ static get method() {
2074
+ return (obj, name, descr) => {
2075
+ descr.value = this.func(descr.value);
2076
+ return descr;
2077
+ };
2078
+ }
2079
+ static get field() {
2080
+ return (obj, name, descr) => {
2081
+ descr.get = descr.set = this.func(descr.get);
2082
+ return descr;
2083
+ };
2084
+ }
2085
+ }
2086
+ $.$mol_wrapper = $mol_wrapper;
2087
+ })($ || ($ = {}));
1647
2088
 
1648
2089
  ;
1649
2090
  "use strict";
1650
2091
  var $;
1651
2092
  (function ($) {
1652
- $.$mol_jsx_prefix = '';
1653
- $.$mol_jsx_crumbs = '';
1654
- $.$mol_jsx_booked = null;
1655
- $.$mol_jsx_document = {
1656
- getElementById: () => null,
1657
- createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
1658
- createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
2093
+ class $mol_memo extends $mol_wrapper {
2094
+ static wrap(task) {
2095
+ const store = new WeakMap();
2096
+ return function (next) {
2097
+ if (next === undefined && store.has(this))
2098
+ return store.get(this);
2099
+ const val = task.call(this, next) ?? next;
2100
+ store.set(this, val);
2101
+ return val;
2102
+ };
2103
+ }
2104
+ }
2105
+ $.$mol_memo = $mol_memo;
2106
+ })($ || ($ = {}));
2107
+
2108
+ ;
2109
+ "use strict";
2110
+ var $;
2111
+ (function ($) {
2112
+ const algorithm = {
2113
+ name: 'ECDSA',
2114
+ hash: 'SHA-256',
2115
+ namedCurve: "P-256",
1659
2116
  };
1660
- $.$mol_jsx_frag = '';
1661
- function $mol_jsx(Elem, props, ...childNodes) {
1662
- const id = props && props.id || '';
1663
- const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
1664
- const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
1665
- if (Elem && $.$mol_jsx_booked) {
1666
- if ($.$mol_jsx_booked.has(id)) {
1667
- $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
1668
- }
1669
- else {
1670
- $.$mol_jsx_booked.add(id);
2117
+ class $mol_crypto_key extends $mol_buffer {
2118
+ static from(serial) {
2119
+ if (typeof serial === 'string') {
2120
+ serial = new Uint8Array([
2121
+ ...$mol_base64_url_decode(serial.slice(0, 43)),
2122
+ ...$mol_base64_url_decode(serial.slice(43, 86)),
2123
+ ...$mol_base64_url_decode(serial.slice(86, 129)),
2124
+ ]);
1671
2125
  }
2126
+ return super.from(serial);
1672
2127
  }
1673
- let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
1674
- if ($.$mol_jsx_prefix) {
1675
- const prefix_ext = $.$mol_jsx_prefix;
1676
- const booked_ext = $.$mol_jsx_booked;
1677
- const crumbs_ext = $.$mol_jsx_crumbs;
1678
- for (const field in props) {
1679
- const func = props[field];
1680
- if (typeof func !== 'function')
1681
- continue;
1682
- const wrapper = function (...args) {
1683
- const prefix = $.$mol_jsx_prefix;
1684
- const booked = $.$mol_jsx_booked;
1685
- const crumbs = $.$mol_jsx_crumbs;
1686
- try {
1687
- $.$mol_jsx_prefix = prefix_ext;
1688
- $.$mol_jsx_booked = booked_ext;
1689
- $.$mol_jsx_crumbs = crumbs_ext;
1690
- return func.call(this, ...args);
1691
- }
1692
- finally {
1693
- $.$mol_jsx_prefix = prefix;
1694
- $.$mol_jsx_booked = booked;
1695
- $.$mol_jsx_crumbs = crumbs;
1696
- }
1697
- };
1698
- $mol_func_name_from(wrapper, func);
1699
- props[field] = wrapper;
1700
- }
2128
+ asArray() {
2129
+ return new Uint8Array(this.buffer, this.byteOffset, this.byteLength);
1701
2130
  }
1702
- if (typeof Elem !== 'string') {
1703
- if ('prototype' in Elem) {
1704
- const view = node && node[String(Elem)] || new Elem;
1705
- Object.assign(view, props);
1706
- view[Symbol.toStringTag] = guid;
1707
- view.childNodes = childNodes;
1708
- if (!view.ownerDocument)
1709
- view.ownerDocument = $.$mol_jsx_document;
1710
- view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
1711
- node = view.valueOf();
1712
- node[String(Elem)] = view;
1713
- return node;
1714
- }
1715
- else {
1716
- const prefix = $.$mol_jsx_prefix;
1717
- const booked = $.$mol_jsx_booked;
1718
- const crumbs = $.$mol_jsx_crumbs;
1719
- try {
1720
- $.$mol_jsx_prefix = guid;
1721
- $.$mol_jsx_booked = new Set;
1722
- $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
1723
- return Elem(props, ...childNodes);
1724
- }
1725
- finally {
1726
- $.$mol_jsx_prefix = prefix;
1727
- $.$mol_jsx_booked = booked;
1728
- $.$mol_jsx_crumbs = crumbs;
1729
- }
1730
- }
2131
+ toString() {
2132
+ const arr = this.asArray();
2133
+ return $mol_base64_url_encode(arr.subarray(0, 32))
2134
+ + $mol_base64_url_encode(arr.subarray(32, 64))
2135
+ + $mol_base64_url_encode(arr.subarray(64));
1731
2136
  }
1732
- if (!node) {
1733
- node = Elem
1734
- ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
1735
- : $.$mol_jsx_document.createDocumentFragment();
2137
+ }
2138
+ __decorate([
2139
+ $mol_memo.method
2140
+ ], $mol_crypto_key.prototype, "toString", null);
2141
+ $.$mol_crypto_key = $mol_crypto_key;
2142
+ class $mol_crypto_key_public extends $mol_crypto_key {
2143
+ static size_str = 86;
2144
+ static size_bin = 64;
2145
+ async native() {
2146
+ const str = this.toString();
2147
+ return $mol_crypto_native.subtle.importKey('jwk', {
2148
+ crv: "P-256",
2149
+ ext: true,
2150
+ key_ops: ['verify'],
2151
+ kty: "EC",
2152
+ x: str.slice(0, 43),
2153
+ y: str.slice(43, 86),
2154
+ }, algorithm, true, ['verify']);
1736
2155
  }
1737
- $mol_dom_render_children(node, [].concat(...childNodes));
1738
- if (!Elem)
1739
- return node;
1740
- if (guid)
1741
- node.id = guid;
1742
- for (const key in props) {
1743
- if (key === 'id')
1744
- continue;
1745
- if (typeof props[key] === 'string') {
1746
- if (typeof node[key] === 'string')
1747
- node[key] = props[key];
1748
- node.setAttribute(key, props[key]);
1749
- }
1750
- else if (props[key] &&
1751
- typeof props[key] === 'object' &&
1752
- Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
1753
- if (typeof node[key] === 'object') {
1754
- Object.assign(node[key], props[key]);
1755
- continue;
1756
- }
1757
- }
1758
- else {
1759
- node[key] = props[key];
1760
- }
2156
+ async verify(data, sign) {
2157
+ return await $mol_crypto_native.subtle.verify(algorithm, await this.native(), sign, data);
1761
2158
  }
1762
- if ($.$mol_jsx_crumbs)
1763
- node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
1764
- return node;
1765
2159
  }
1766
- $.$mol_jsx = $mol_jsx;
1767
- })($ || ($ = {}));
1768
-
1769
- ;
1770
- "use strict";
1771
- var $;
1772
- (function ($) {
1773
- $mol_test({
1774
- 'Make empty div'() {
1775
- $mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
1776
- },
1777
- 'Define native field'() {
1778
- const dom = $mol_jsx("input", { value: '123' });
1779
- $mol_assert_equal(dom.outerHTML, '<input value="123">');
1780
- $mol_assert_equal(dom.value, '123');
1781
- },
1782
- 'Define classes'() {
1783
- const dom = $mol_jsx("div", { class: 'foo bar' });
1784
- $mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
1785
- },
1786
- 'Define styles'() {
1787
- const dom = $mol_jsx("div", { style: { color: 'red' } });
1788
- $mol_assert_equal(dom.outerHTML, '<div style="color: red;"></div>');
1789
- },
1790
- 'Define dataset'() {
1791
- const dom = $mol_jsx("div", { dataset: { foo: 'bar' } });
1792
- $mol_assert_equal(dom.outerHTML, '<div data-foo="bar"></div>');
1793
- },
1794
- 'Define attributes'() {
1795
- const dom = $mol_jsx("div", { lang: "ru", hidden: true });
1796
- $mol_assert_equal(dom.outerHTML, '<div lang="ru" hidden=""></div>');
1797
- },
1798
- 'Define child nodes'() {
1799
- const dom = $mol_jsx("div", null,
1800
- "hello",
1801
- $mol_jsx("strong", null, "world"),
1802
- "!");
1803
- $mol_assert_equal(dom.outerHTML, '<div>hello<strong>world</strong>!</div>');
1804
- },
1805
- 'Function as component'() {
1806
- const Button = (props, target) => {
1807
- return $mol_jsx("button", { title: props.hint }, target());
1808
- };
1809
- const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
1810
- $mol_assert_equal(dom.outerHTML, '<button id="foo" title="click me" class="Button">hey!</button>');
1811
- },
1812
- 'Nested guid generation'() {
1813
- const Foo = () => {
1814
- return $mol_jsx("div", null,
1815
- $mol_jsx(Bar, { id: "bar" },
1816
- $mol_jsx("img", { id: "icon" })));
1817
- };
1818
- const Bar = (props, icon) => {
1819
- return $mol_jsx("span", null,
1820
- icon,
1821
- $mol_jsx("i", { id: "label" }));
1822
- };
1823
- const dom = $mol_jsx(Foo, { id: "foo" });
1824
- $mol_assert_equal(dom.outerHTML, '<div id="foo" class="Foo"><span id="foo/bar" class="Foo_bar Bar"><img id="foo/icon" class="Foo_icon"><i id="foo/bar/label" class="Foo_bar_label Bar_label"></i></span></div>');
1825
- },
1826
- 'Fail on non unique ids'() {
1827
- const App = () => {
1828
- return $mol_jsx("div", null,
1829
- $mol_jsx("span", { id: "bar" }),
1830
- $mol_jsx("span", { id: "bar" }));
1831
- };
1832
- $mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
1833
- },
1834
- 'Owner based guid generationn'() {
1835
- const Foo = () => {
1836
- return $mol_jsx("div", null,
1837
- $mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
1838
- };
1839
- const Bar = (props) => {
1840
- return $mol_jsx("span", null, props.icon());
1841
- };
1842
- const dom = $mol_jsx(Foo, { id: "app" });
1843
- $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>');
1844
- },
1845
- 'Fail on same ids from different caller'() {
1846
- const Foo = () => {
1847
- return $mol_jsx("div", null,
1848
- $mol_jsx("img", { id: "icon" }),
1849
- $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
1850
- };
1851
- const Bar = (props) => {
1852
- return $mol_jsx("span", null, props.icon());
1853
- };
1854
- $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
1855
- },
1856
- });
1857
- })($ || ($ = {}));
1858
-
1859
- ;
1860
- "use strict";
1861
- var $;
1862
- (function ($) {
1863
- function $mol_guid(length = 8, exists = () => false) {
1864
- for (;;) {
1865
- let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
1866
- if (exists(id))
1867
- continue;
1868
- return id;
2160
+ __decorate([
2161
+ $mol_memo.method
2162
+ ], $mol_crypto_key_public.prototype, "native", null);
2163
+ $.$mol_crypto_key_public = $mol_crypto_key_public;
2164
+ class $mol_crypto_key_private extends $mol_crypto_key {
2165
+ static size_str = 129;
2166
+ static size_bin = 96;
2167
+ static size_sign = 64;
2168
+ static async generate() {
2169
+ const pair = await $mol_crypto_native.subtle.generateKey(algorithm, true, ['sign', 'verify']);
2170
+ const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', pair.privateKey);
2171
+ return this.from(x + y + d);
2172
+ }
2173
+ async native() {
2174
+ const str = this.toString();
2175
+ return await $mol_crypto_native.subtle.importKey('jwk', {
2176
+ crv: "P-256",
2177
+ ext: true,
2178
+ key_ops: ['sign'],
2179
+ kty: "EC",
2180
+ x: str.slice(0, 43),
2181
+ y: str.slice(43, 86),
2182
+ d: str.slice(86, 129),
2183
+ }, algorithm, true, ['sign']);
2184
+ }
2185
+ public() {
2186
+ return new $mol_crypto_key_public(this.buffer, this.byteOffset, this.byteOffset + 64);
2187
+ }
2188
+ async sign(data) {
2189
+ return await $mol_crypto_native.subtle.sign(algorithm, await this.native(), data);
1869
2190
  }
1870
2191
  }
1871
- $.$mol_guid = $mol_guid;
2192
+ __decorate([
2193
+ $mol_memo.method
2194
+ ], $mol_crypto_key_private.prototype, "native", null);
2195
+ __decorate([
2196
+ $mol_memo.method
2197
+ ], $mol_crypto_key_private.prototype, "public", null);
2198
+ $.$mol_crypto_key_private = $mol_crypto_key_private;
1872
2199
  })($ || ($ = {}));
1873
2200
 
1874
2201
  ;
1875
2202
  "use strict";
1876
2203
  var $;
1877
2204
  (function ($) {
1878
- function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
1879
- const source = typeof item === 'function' ? new $mol_range2_array() : item;
1880
- if (typeof item !== 'function') {
1881
- item = index => source[index];
1882
- size = () => source.length;
2205
+ let sponge = new Uint32Array(80);
2206
+ function $mol_crypto_hash(data) {
2207
+ const bits = data.byteLength << 3;
2208
+ const kbits = bits >> 5;
2209
+ const kword = 0x80 << (24 - bits & 0b11111);
2210
+ const bytes = 16 + (bits + 64 >>> 9 << 4);
2211
+ const klens = bytes - 1;
2212
+ const words = new Int32Array(data.buffer, data.byteOffset, data.byteLength >> 2);
2213
+ let tail = 0;
2214
+ for (let i = words.length * 4; i < data.length; ++i) {
2215
+ tail |= data[i] << (i << 3 & 0b11000);
1883
2216
  }
1884
- return new Proxy(source, {
1885
- get(target, field) {
1886
- if (typeof field === 'string') {
1887
- if (field === 'length')
1888
- return size();
1889
- const index = Number(field);
1890
- if (index < 0)
1891
- return undefined;
1892
- if (index >= size())
1893
- return undefined;
1894
- if (index === Math.trunc(index))
1895
- return item(index);
2217
+ const hash = new Int32Array([1732584193, -271733879, -1732584194, 271733878, -1009589776]);
2218
+ for (let i = 0; i < bytes; i += 16) {
2219
+ let h0 = hash[0];
2220
+ let h1 = hash[1];
2221
+ let h2 = hash[2];
2222
+ let h3 = hash[3];
2223
+ let h4 = hash[4];
2224
+ for (let j = 0; j < 80; ++j) {
2225
+ let turn;
2226
+ if (j < 16) {
2227
+ const k = i + j;
2228
+ if (k === klens) {
2229
+ sponge[j] = bits;
2230
+ }
2231
+ else {
2232
+ let word = k === words.length ? tail :
2233
+ k > words.length ? 0 :
2234
+ words[k];
2235
+ word = word << 24 | word << 8 & 0xFF0000 | word >>> 8 & 0xFF00 | word >>> 24 & 0xFF;
2236
+ if (k === kbits)
2237
+ word |= kword;
2238
+ sponge[j] = word;
2239
+ }
2240
+ turn = (h1 & h2 | ~h1 & h3) + 1518500249;
1896
2241
  }
1897
- return $mol_range2_array.prototype[field];
1898
- },
1899
- set(target, field) {
1900
- return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
1901
- },
1902
- ownKeys(target) {
1903
- return [...Array(size())].map((v, i) => String(i)).concat('length');
1904
- },
1905
- getOwnPropertyDescriptor(target, field) {
1906
- if (field === "length")
1907
- return {
1908
- value: size(),
1909
- writable: true,
1910
- enumerable: false,
1911
- configurable: false,
1912
- };
1913
- const index = Number(field);
1914
- if (index === Math.trunc(index))
1915
- return {
1916
- get: () => this.get(target, field, this),
1917
- enumerable: true,
1918
- configurable: true,
1919
- };
1920
- return Object.getOwnPropertyDescriptor(target, field);
1921
- }
1922
- });
1923
- }
1924
- $.$mol_range2 = $mol_range2;
1925
- class $mol_range2_array extends Array {
1926
- concat(...tail) {
1927
- if (tail.length === 0)
1928
- return this;
1929
- if (tail.length > 1) {
1930
- let list = this;
1931
- for (let item of tail)
1932
- list = list.concat(item);
1933
- return list;
1934
- }
1935
- return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
1936
- }
1937
- filter(check, context) {
1938
- const filtered = [];
1939
- let cursor = -1;
1940
- return $mol_range2(index => {
1941
- while (cursor < this.length && index >= filtered.length - 1) {
1942
- const val = this[++cursor];
1943
- if (check(val, cursor, this))
1944
- filtered.push(val);
2242
+ else {
2243
+ const shuffle = sponge[j - 3] ^ sponge[j - 8] ^ sponge[j - 14] ^ sponge[j - 16];
2244
+ sponge[j] = shuffle << 1 | shuffle >>> 31;
2245
+ turn =
2246
+ j < 20 ? (h1 & h2 | ~h1 & h3) + 1518500249 :
2247
+ j < 40 ? (h1 ^ h2 ^ h3) + 1859775393 :
2248
+ j < 60 ? (h1 & h2 | h1 & h3 | h2 & h3) - 1894007588 :
2249
+ (h1 ^ h2 ^ h3) - 899497514;
1945
2250
  }
1946
- return filtered[index];
1947
- }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
2251
+ const next = turn + h4 + (sponge[j] >>> 0) + ((h0 << 5) | (h0 >>> 27));
2252
+ h4 = h3;
2253
+ h3 = h2;
2254
+ h2 = (h1 << 30) | (h1 >>> 2);
2255
+ h1 = h0;
2256
+ h0 = next;
2257
+ }
2258
+ hash[0] += h0;
2259
+ hash[1] += h1;
2260
+ hash[2] += h2;
2261
+ hash[3] += h3;
2262
+ hash[4] += h4;
1948
2263
  }
1949
- forEach(proceed, context) {
1950
- for (let [key, value] of this.entries())
1951
- proceed.call(context, value, key, this);
2264
+ for (let i = 0; i < 20; ++i) {
2265
+ const word = hash[i];
2266
+ hash[i] = word << 24 | word << 8 & 0xFF0000 | word >>> 8 & 0xFF00 | word >>> 24 & 0xFF;
1952
2267
  }
1953
- map(proceed, context) {
1954
- return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
2268
+ return new Uint8Array(hash.buffer);
2269
+ }
2270
+ $.$mol_crypto_hash = $mol_crypto_hash;
2271
+ })($ || ($ = {}));
2272
+
2273
+ ;
2274
+ "use strict";
2275
+ var $;
2276
+ (function ($) {
2277
+ function $mol_crypto_salt() {
2278
+ return $mol_crypto_native.getRandomValues(new Uint8Array(16));
2279
+ }
2280
+ $.$mol_crypto_salt = $mol_crypto_salt;
2281
+ })($ || ($ = {}));
2282
+
2283
+ ;
2284
+ "use strict";
2285
+ var $;
2286
+ (function ($_1) {
2287
+ function $mol_test(set) {
2288
+ for (let name in set) {
2289
+ const code = set[name];
2290
+ const test = (typeof code === 'string') ? new Function('', code) : code;
2291
+ $_1.$mol_test_all.push(test);
1955
2292
  }
1956
- reduce(merge, result) {
1957
- let index = 0;
1958
- if (arguments.length === 1) {
1959
- result = this[index++];
1960
- }
1961
- for (; index < this.length; ++index) {
1962
- result = merge(result, this[index], index, this);
2293
+ $mol_test_schedule();
2294
+ }
2295
+ $_1.$mol_test = $mol_test;
2296
+ $_1.$mol_test_mocks = [];
2297
+ $_1.$mol_test_all = [];
2298
+ async function $mol_test_run() {
2299
+ for (var test of $_1.$mol_test_all) {
2300
+ let context = Object.create($$);
2301
+ for (let mock of $_1.$mol_test_mocks)
2302
+ await mock(context);
2303
+ const res = test(context);
2304
+ if ($mol_promise_like(res)) {
2305
+ await new Promise((done, fail) => {
2306
+ res.then(done, fail);
2307
+ setTimeout(() => fail(new Error('Test timeout: ' + test.name)), 1000);
2308
+ });
1963
2309
  }
1964
- return result;
1965
2310
  }
1966
- toReversed() {
1967
- return $mol_range2(index => this[this.length - 1 - index], () => this.length);
1968
- }
1969
- slice(from = 0, to = this.length) {
1970
- return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
2311
+ $$.$mol_log3_done({
2312
+ place: '$mol_test',
2313
+ message: 'All tests passed',
2314
+ count: $_1.$mol_test_all.length,
2315
+ });
2316
+ }
2317
+ $_1.$mol_test_run = $mol_test_run;
2318
+ let scheduled = false;
2319
+ function $mol_test_schedule() {
2320
+ if (scheduled)
2321
+ return;
2322
+ scheduled = true;
2323
+ setTimeout(async () => {
2324
+ scheduled = false;
2325
+ await $mol_test_run();
2326
+ $$.$mol_test_complete();
2327
+ }, 1000);
2328
+ }
2329
+ $_1.$mol_test_schedule = $mol_test_schedule;
2330
+ $_1.$mol_test_mocks.push(context => {
2331
+ let seed = 0;
2332
+ context.Math = Object.create(Math);
2333
+ context.Math.random = () => Math.sin(seed++);
2334
+ const forbidden = ['XMLHttpRequest', 'fetch'];
2335
+ for (let api of forbidden) {
2336
+ context[api] = new Proxy(function () { }, {
2337
+ get() {
2338
+ $mol_fail_hidden(new Error(`${api} is forbidden in tests`));
2339
+ },
2340
+ apply() {
2341
+ $mol_fail_hidden(new Error(`${api} is forbidden in tests`));
2342
+ },
2343
+ });
1971
2344
  }
1972
- some(check, context) {
1973
- for (let index = 0; index < this.length; ++index) {
1974
- if (check.call(context, this[index], index, this))
1975
- return true;
2345
+ });
2346
+ $mol_test({
2347
+ 'mocked Math.random'($) {
2348
+ console.assert($.Math.random() === 0);
2349
+ console.assert($.Math.random() === Math.sin(1));
2350
+ },
2351
+ 'forbidden XMLHttpRequest'($) {
2352
+ try {
2353
+ console.assert(void new $.XMLHttpRequest);
1976
2354
  }
1977
- return false;
1978
- }
1979
- every(check, context) {
1980
- for (let index = 0; index < this.length; ++index) {
1981
- if (!check.call(context, this[index], index, this))
1982
- return false;
2355
+ catch (error) {
2356
+ console.assert(error.message === 'XMLHttpRequest is forbidden in tests');
1983
2357
  }
1984
- return true;
1985
- }
1986
- reverse() {
1987
- return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
1988
- }
1989
- sort() {
1990
- return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
1991
- }
1992
- [Symbol.toPrimitive]() {
1993
- return $mol_guid();
1994
- }
1995
- }
1996
- $.$mol_range2_array = $mol_range2_array;
2358
+ },
2359
+ 'forbidden fetch'($) {
2360
+ try {
2361
+ console.assert(void $.fetch(''));
2362
+ }
2363
+ catch (error) {
2364
+ console.assert(error.message === 'fetch is forbidden in tests');
2365
+ }
2366
+ },
2367
+ });
1997
2368
  })($ || ($ = {}));
1998
2369
 
1999
2370
  ;
2000
2371
  "use strict";
2001
2372
  var $;
2002
2373
  (function ($) {
2374
+ function $mol_test_complete() {
2375
+ process.exit(0);
2376
+ }
2377
+ $.$mol_test_complete = $mol_test_complete;
2378
+ })($ || ($ = {}));
2379
+
2380
+ ;
2381
+ "use strict";
2382
+
2383
+ ;
2384
+ "use strict";
2385
+
2386
+ ;
2387
+ "use strict";
2388
+
2389
+ ;
2390
+ "use strict";
2391
+ var $;
2392
+ (function ($_1) {
2003
2393
  $mol_test({
2004
- 'lazy calls'() {
2005
- let calls = 0;
2006
- const list = $mol_range2(index => (++calls, index), () => 10);
2007
- $mol_assert_equal(true, list instanceof Array);
2008
- $mol_assert_equal(list.length, 10);
2009
- $mol_assert_equal(list[-1], undefined);
2010
- $mol_assert_equal(list[0], 0);
2011
- $mol_assert_equal(list[9], 9);
2012
- $mol_assert_equal(list[9.5], undefined);
2013
- $mol_assert_equal(list[10], undefined);
2014
- $mol_assert_equal(calls, 2);
2015
- },
2016
- 'infinity list'() {
2017
- let calls = 0;
2018
- const list = $mol_range2(index => (++calls, index));
2019
- $mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
2020
- $mol_assert_equal(list[0], 0);
2021
- $mol_assert_equal(list[4], 4);
2022
- $mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
2023
- $mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
2024
- $mol_assert_equal(calls, 3);
2025
- },
2026
- 'stringify'() {
2027
- const list = $mol_range2(i => i, () => 5);
2028
- $mol_assert_equal(list.toString(), '0,1,2,3,4');
2029
- $mol_assert_equal(list.join(';'), '0;1;2;3;4');
2030
- },
2031
- 'for-of'() {
2032
- let log = '';
2033
- for (let i of $mol_range2(i => i + 1, () => 5)) {
2034
- log += i;
2394
+ 'test types'($) {
2395
+ class A {
2396
+ static a() {
2397
+ return Promise.resolve('');
2398
+ }
2399
+ static b() {
2400
+ return $mol_wire_sync(this).a();
2401
+ }
2035
2402
  }
2036
- $mol_assert_equal(log, '12345');
2037
2403
  },
2038
- 'for-in'() {
2039
- let log = '';
2040
- for (let i in $mol_range2(i => i, () => 5)) {
2041
- log += i;
2404
+ });
2405
+ })($ || ($ = {}));
2406
+
2407
+ ;
2408
+ "use strict";
2409
+ var $;
2410
+ (function ($_1) {
2411
+ $mol_test_mocks.push($ => $.$mol_fail_log = () => false);
2412
+ })($ || ($ = {}));
2413
+
2414
+ ;
2415
+ "use strict";
2416
+ var $;
2417
+ (function ($_1) {
2418
+ $mol_test_mocks.push($ => {
2419
+ $.$mol_log3_come = () => { };
2420
+ $.$mol_log3_done = () => { };
2421
+ $.$mol_log3_fail = () => { };
2422
+ $.$mol_log3_warn = () => { };
2423
+ $.$mol_log3_rise = () => { };
2424
+ $.$mol_log3_area = () => () => { };
2425
+ });
2426
+ })($ || ($ = {}));
2427
+
2428
+ ;
2429
+ "use strict";
2430
+
2431
+ ;
2432
+ "use strict";
2433
+
2434
+ ;
2435
+ "use strict";
2436
+
2437
+ ;
2438
+ "use strict";
2439
+ var $;
2440
+ (function ($) {
2441
+ function $mol_dom_render_children(el, childNodes) {
2442
+ const node_set = new Set(childNodes);
2443
+ let nextNode = el.firstChild;
2444
+ for (let view of childNodes) {
2445
+ if (view == null)
2446
+ continue;
2447
+ if (view instanceof $mol_dom_context.Node) {
2448
+ while (true) {
2449
+ if (!nextNode) {
2450
+ el.appendChild(view);
2451
+ break;
2452
+ }
2453
+ if (nextNode == view) {
2454
+ nextNode = nextNode.nextSibling;
2455
+ break;
2456
+ }
2457
+ else {
2458
+ if (node_set.has(nextNode)) {
2459
+ el.insertBefore(view, nextNode);
2460
+ break;
2461
+ }
2462
+ else {
2463
+ const nn = nextNode.nextSibling;
2464
+ el.removeChild(nextNode);
2465
+ nextNode = nn;
2466
+ }
2467
+ }
2468
+ }
2042
2469
  }
2043
- $mol_assert_equal(log, '01234');
2470
+ else {
2471
+ if (nextNode && nextNode.nodeName === '#text') {
2472
+ const str = String(view);
2473
+ if (nextNode.nodeValue !== str)
2474
+ nextNode.nodeValue = str;
2475
+ nextNode = nextNode.nextSibling;
2476
+ }
2477
+ else {
2478
+ const textNode = $mol_dom_context.document.createTextNode(String(view));
2479
+ el.insertBefore(textNode, nextNode);
2480
+ }
2481
+ }
2482
+ }
2483
+ while (nextNode) {
2484
+ const currNode = nextNode;
2485
+ nextNode = currNode.nextSibling;
2486
+ el.removeChild(currNode);
2487
+ }
2488
+ }
2489
+ $.$mol_dom_render_children = $mol_dom_render_children;
2490
+ })($ || ($ = {}));
2491
+
2492
+ ;
2493
+ "use strict";
2494
+
2495
+ ;
2496
+ "use strict";
2497
+
2498
+ ;
2499
+ "use strict";
2500
+ var $;
2501
+ (function ($) {
2502
+ $.$mol_jsx_prefix = '';
2503
+ $.$mol_jsx_crumbs = '';
2504
+ $.$mol_jsx_booked = null;
2505
+ $.$mol_jsx_document = {
2506
+ getElementById: () => null,
2507
+ createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
2508
+ createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
2509
+ };
2510
+ $.$mol_jsx_frag = '';
2511
+ function $mol_jsx(Elem, props, ...childNodes) {
2512
+ const id = props && props.id || '';
2513
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
2514
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
2515
+ if (Elem && $.$mol_jsx_booked) {
2516
+ if ($.$mol_jsx_booked.has(id)) {
2517
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
2518
+ }
2519
+ else {
2520
+ $.$mol_jsx_booked.add(id);
2521
+ }
2522
+ }
2523
+ let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
2524
+ if ($.$mol_jsx_prefix) {
2525
+ const prefix_ext = $.$mol_jsx_prefix;
2526
+ const booked_ext = $.$mol_jsx_booked;
2527
+ const crumbs_ext = $.$mol_jsx_crumbs;
2528
+ for (const field in props) {
2529
+ const func = props[field];
2530
+ if (typeof func !== 'function')
2531
+ continue;
2532
+ const wrapper = function (...args) {
2533
+ const prefix = $.$mol_jsx_prefix;
2534
+ const booked = $.$mol_jsx_booked;
2535
+ const crumbs = $.$mol_jsx_crumbs;
2536
+ try {
2537
+ $.$mol_jsx_prefix = prefix_ext;
2538
+ $.$mol_jsx_booked = booked_ext;
2539
+ $.$mol_jsx_crumbs = crumbs_ext;
2540
+ return func.call(this, ...args);
2541
+ }
2542
+ finally {
2543
+ $.$mol_jsx_prefix = prefix;
2544
+ $.$mol_jsx_booked = booked;
2545
+ $.$mol_jsx_crumbs = crumbs;
2546
+ }
2547
+ };
2548
+ $mol_func_name_from(wrapper, func);
2549
+ props[field] = wrapper;
2550
+ }
2551
+ }
2552
+ if (typeof Elem !== 'string') {
2553
+ if ('prototype' in Elem) {
2554
+ const view = node && node[String(Elem)] || new Elem;
2555
+ Object.assign(view, props);
2556
+ view[Symbol.toStringTag] = guid;
2557
+ view.childNodes = childNodes;
2558
+ if (!view.ownerDocument)
2559
+ view.ownerDocument = $.$mol_jsx_document;
2560
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
2561
+ node = view.valueOf();
2562
+ node[String(Elem)] = view;
2563
+ return node;
2564
+ }
2565
+ else {
2566
+ const prefix = $.$mol_jsx_prefix;
2567
+ const booked = $.$mol_jsx_booked;
2568
+ const crumbs = $.$mol_jsx_crumbs;
2569
+ try {
2570
+ $.$mol_jsx_prefix = guid;
2571
+ $.$mol_jsx_booked = new Set;
2572
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
2573
+ return Elem(props, ...childNodes);
2574
+ }
2575
+ finally {
2576
+ $.$mol_jsx_prefix = prefix;
2577
+ $.$mol_jsx_booked = booked;
2578
+ $.$mol_jsx_crumbs = crumbs;
2579
+ }
2580
+ }
2581
+ }
2582
+ if (!node) {
2583
+ node = Elem
2584
+ ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
2585
+ : $.$mol_jsx_document.createDocumentFragment();
2586
+ }
2587
+ $mol_dom_render_children(node, [].concat(...childNodes));
2588
+ if (!Elem)
2589
+ return node;
2590
+ if (guid)
2591
+ node.id = guid;
2592
+ for (const key in props) {
2593
+ if (key === 'id')
2594
+ continue;
2595
+ if (typeof props[key] === 'string') {
2596
+ if (typeof node[key] === 'string')
2597
+ node[key] = props[key];
2598
+ node.setAttribute(key, props[key]);
2599
+ }
2600
+ else if (props[key] &&
2601
+ typeof props[key] === 'object' &&
2602
+ Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
2603
+ if (typeof node[key] === 'object') {
2604
+ Object.assign(node[key], props[key]);
2605
+ continue;
2606
+ }
2607
+ }
2608
+ else {
2609
+ node[key] = props[key];
2610
+ }
2611
+ }
2612
+ if ($.$mol_jsx_crumbs)
2613
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
2614
+ return node;
2615
+ }
2616
+ $.$mol_jsx = $mol_jsx;
2617
+ })($ || ($ = {}));
2618
+
2619
+ ;
2620
+ "use strict";
2621
+ var $;
2622
+ (function ($) {
2623
+ $mol_test({
2624
+ 'Make empty div'() {
2625
+ $mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
2044
2626
  },
2045
- 'forEach'() {
2046
- let log = '';
2047
- $mol_range2(i => i, () => 5).forEach(i => log += i);
2048
- $mol_assert_equal(log, '01234');
2627
+ 'Define native field'() {
2628
+ const dom = $mol_jsx("input", { value: '123' });
2629
+ $mol_assert_equal(dom.outerHTML, '<input value="123">');
2630
+ $mol_assert_equal(dom.value, '123');
2049
2631
  },
2050
- 'reduce'() {
2051
- let calls = 0;
2052
- const list = $mol_range2().slice(1, 6);
2053
- $mol_assert_equal(list.reduce((s, v) => s + v), 15);
2054
- $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
2632
+ 'Define classes'() {
2633
+ const dom = $mol_jsx("div", { class: 'foo bar' });
2634
+ $mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
2055
2635
  },
2056
- 'lazy concat'() {
2057
- let calls1 = 0;
2058
- let calls2 = 0;
2059
- const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
2060
- $mol_assert_equal(true, list instanceof Array);
2061
- $mol_assert_equal(list.length, 15);
2062
- $mol_assert_equal(list[0], 0);
2063
- $mol_assert_equal(list[4], 4);
2064
- $mol_assert_equal(list[5], 0);
2065
- $mol_assert_equal(list[9], 4);
2066
- $mol_assert_equal(list[10], 0);
2067
- $mol_assert_equal(list[14], 4);
2068
- $mol_assert_equal(list[15], undefined);
2069
- $mol_assert_equal(calls1, 2);
2070
- $mol_assert_equal(calls2, 2);
2636
+ 'Define styles'() {
2637
+ const dom = $mol_jsx("div", { style: { color: 'red' } });
2638
+ $mol_assert_equal(dom.outerHTML, '<div style="color: red;"></div>');
2071
2639
  },
2072
- 'lazy filter'() {
2073
- let calls = 0;
2074
- const list = $mol_range2(index => (++calls, index), () => 15).filter(v => v % 2).slice(0, 3);
2075
- $mol_assert_equal(true, list instanceof Array);
2076
- $mol_assert_equal(list.length, 3);
2077
- $mol_assert_equal(list[0], 1);
2078
- $mol_assert_equal(list[2], 5);
2079
- $mol_assert_equal(list[3], undefined);
2080
- $mol_assert_equal(calls, 8);
2640
+ 'Define dataset'() {
2641
+ const dom = $mol_jsx("div", { dataset: { foo: 'bar' } });
2642
+ $mol_assert_equal(dom.outerHTML, '<div data-foo="bar"></div>');
2081
2643
  },
2082
- 'lazy reverse'() {
2083
- let calls = 0;
2084
- const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
2085
- $mol_assert_equal(true, list instanceof Array);
2086
- $mol_assert_equal(list.length, 3);
2087
- $mol_assert_equal(list[0], 9);
2088
- $mol_assert_equal(list[2], 7);
2089
- $mol_assert_equal(list[3], undefined);
2090
- $mol_assert_equal(calls, 2);
2644
+ 'Define attributes'() {
2645
+ const dom = $mol_jsx("div", { lang: "ru", hidden: true });
2646
+ $mol_assert_equal(dom.outerHTML, '<div lang="ru" hidden=""></div>');
2091
2647
  },
2092
- 'lazy map'() {
2093
- let calls1 = 0;
2094
- let calls2 = 0;
2095
- const source = $mol_range2(index => (++calls1, index), () => 5);
2096
- const target = source.map((item, index, self) => {
2097
- ++calls2;
2098
- $mol_assert_equal(source, self);
2099
- return index + 10;
2100
- }, () => 5);
2101
- $mol_assert_equal(true, target instanceof Array);
2102
- $mol_assert_equal(target.length, 5);
2103
- $mol_assert_equal(target[0], 10);
2104
- $mol_assert_equal(target[4], 14);
2105
- $mol_assert_equal(target[5], undefined);
2106
- $mol_assert_equal(calls1, 2);
2107
- $mol_assert_equal(calls2, 2);
2648
+ 'Define child nodes'() {
2649
+ const dom = $mol_jsx("div", null,
2650
+ "hello",
2651
+ $mol_jsx("strong", null, "world"),
2652
+ "!");
2653
+ $mol_assert_equal(dom.outerHTML, '<div>hello<strong>world</strong>!</div>');
2108
2654
  },
2109
- 'lazy slice'() {
2110
- let calls = 0;
2111
- const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
2112
- $mol_assert_equal(true, list instanceof Array);
2113
- $mol_assert_equal(list.length, 4);
2114
- $mol_assert_equal(list[0], 3);
2115
- $mol_assert_equal(list[3], 6);
2116
- $mol_assert_equal(list[4], undefined);
2117
- $mol_assert_equal(calls, 2);
2655
+ 'Function as component'() {
2656
+ const Button = (props, target) => {
2657
+ return $mol_jsx("button", { title: props.hint }, target());
2658
+ };
2659
+ const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
2660
+ $mol_assert_equal(dom.outerHTML, '<button id="foo" title="click me" class="Button">hey!</button>');
2118
2661
  },
2119
- 'lazy some'() {
2120
- let calls = 0;
2121
- $mol_assert_equal(true, $mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
2122
- $mol_assert_equal(calls, 3);
2123
- $mol_assert_equal(false, $mol_range2(i => i, () => 0).some(v => true));
2124
- $mol_assert_equal(true, $mol_range2(i => i).some(v => v > 5));
2662
+ 'Nested guid generation'() {
2663
+ const Foo = () => {
2664
+ return $mol_jsx("div", null,
2665
+ $mol_jsx(Bar, { id: "bar" },
2666
+ $mol_jsx("img", { id: "icon" })));
2667
+ };
2668
+ const Bar = (props, icon) => {
2669
+ return $mol_jsx("span", null,
2670
+ icon,
2671
+ $mol_jsx("i", { id: "label" }));
2672
+ };
2673
+ const dom = $mol_jsx(Foo, { id: "foo" });
2674
+ $mol_assert_equal(dom.outerHTML, '<div id="foo" class="Foo"><span id="foo/bar" class="Foo_bar Bar"><img id="foo/icon" class="Foo_icon"><i id="foo/bar/label" class="Foo_bar_label Bar_label"></i></span></div>');
2125
2675
  },
2126
- 'lazy every'() {
2127
- let calls = 0;
2128
- $mol_assert_equal(false, $mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
2129
- $mol_assert_equal(calls, 3);
2130
- $mol_assert_equal(true, $mol_range2(i => i, () => 0).every(v => false));
2131
- $mol_assert_equal(false, $mol_range2(i => i).every(v => v < 5));
2676
+ 'Fail on non unique ids'() {
2677
+ const App = () => {
2678
+ return $mol_jsx("div", null,
2679
+ $mol_jsx("span", { id: "bar" }),
2680
+ $mol_jsx("span", { id: "bar" }));
2681
+ };
2682
+ $mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
2132
2683
  },
2133
- 'lazyfy'() {
2134
- let calls = 0;
2135
- const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
2136
- $mol_assert_equal(true, list instanceof Array);
2137
- $mol_assert_equal(list.length, 4);
2138
- $mol_assert_equal(calls, 0);
2139
- $mol_assert_equal(list[0], 12);
2140
- $mol_assert_equal(list[3], 15);
2141
- $mol_assert_equal(list[4], undefined);
2142
- $mol_assert_equal(calls, 2);
2684
+ 'Owner based guid generationn'() {
2685
+ const Foo = () => {
2686
+ return $mol_jsx("div", null,
2687
+ $mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
2688
+ };
2689
+ const Bar = (props) => {
2690
+ return $mol_jsx("span", null, props.icon());
2691
+ };
2692
+ const dom = $mol_jsx(Foo, { id: "app" });
2693
+ $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>');
2143
2694
  },
2144
- 'prevent modification'() {
2145
- const list = $mol_range2(i => i, () => 5);
2146
- $mol_assert_fail(() => list.push(4), TypeError);
2147
- $mol_assert_fail(() => list.pop(), TypeError);
2148
- $mol_assert_fail(() => list.unshift(4), TypeError);
2149
- $mol_assert_fail(() => list.shift(), TypeError);
2150
- $mol_assert_fail(() => list.splice(1, 2), TypeError);
2151
- $mol_assert_fail(() => list[1] = 2, TypeError);
2152
- $mol_assert_fail(() => list.reverse(), TypeError);
2153
- $mol_assert_fail(() => list.sort(), TypeError);
2154
- $mol_assert_equal(list.toString(), '0,1,2,3,4');
2695
+ 'Fail on same ids from different caller'() {
2696
+ const Foo = () => {
2697
+ return $mol_jsx("div", null,
2698
+ $mol_jsx("img", { id: "icon" }),
2699
+ $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
2700
+ };
2701
+ const Bar = (props) => {
2702
+ return $mol_jsx("span", null, props.icon());
2703
+ };
2704
+ $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
2705
+ },
2706
+ });
2707
+ })($ || ($ = {}));
2708
+
2709
+ ;
2710
+ "use strict";
2711
+ var $;
2712
+ (function ($) {
2713
+ function $mol_guid(length = 8, exists = () => false) {
2714
+ for (;;) {
2715
+ let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
2716
+ if (exists(id))
2717
+ continue;
2718
+ return id;
2719
+ }
2720
+ }
2721
+ $.$mol_guid = $mol_guid;
2722
+ })($ || ($ = {}));
2723
+
2724
+ ;
2725
+ "use strict";
2726
+ var $;
2727
+ (function ($) {
2728
+ function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
2729
+ const source = typeof item === 'function' ? new $mol_range2_array() : item;
2730
+ if (typeof item !== 'function') {
2731
+ item = index => source[index];
2732
+ size = () => source.length;
2733
+ }
2734
+ return new Proxy(source, {
2735
+ get(target, field) {
2736
+ if (typeof field === 'string') {
2737
+ if (field === 'length')
2738
+ return size();
2739
+ const index = Number(field);
2740
+ if (index < 0)
2741
+ return undefined;
2742
+ if (index >= size())
2743
+ return undefined;
2744
+ if (index === Math.trunc(index))
2745
+ return item(index);
2746
+ }
2747
+ return $mol_range2_array.prototype[field];
2748
+ },
2749
+ set(target, field) {
2750
+ return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
2751
+ },
2752
+ ownKeys(target) {
2753
+ return [...Array(size())].map((v, i) => String(i)).concat('length');
2754
+ },
2755
+ getOwnPropertyDescriptor(target, field) {
2756
+ if (field === "length")
2757
+ return {
2758
+ value: size(),
2759
+ writable: true,
2760
+ enumerable: false,
2761
+ configurable: false,
2762
+ };
2763
+ const index = Number(field);
2764
+ if (index === Math.trunc(index))
2765
+ return {
2766
+ get: () => this.get(target, field, this),
2767
+ enumerable: true,
2768
+ configurable: true,
2769
+ };
2770
+ return Object.getOwnPropertyDescriptor(target, field);
2771
+ }
2772
+ });
2773
+ }
2774
+ $.$mol_range2 = $mol_range2;
2775
+ class $mol_range2_array extends Array {
2776
+ concat(...tail) {
2777
+ if (tail.length === 0)
2778
+ return this;
2779
+ if (tail.length > 1) {
2780
+ let list = this;
2781
+ for (let item of tail)
2782
+ list = list.concat(item);
2783
+ return list;
2784
+ }
2785
+ return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
2155
2786
  }
2156
- });
2157
- })($ || ($ = {}));
2158
-
2159
- ;
2160
- "use strict";
2161
- var $;
2162
- (function ($) {
2163
- $.$mol_compare_deep_cache = new WeakMap();
2164
- function $mol_compare_deep(left, right) {
2165
- if (Object.is(left, right))
2166
- return true;
2167
- if (left === null)
2168
- return false;
2169
- if (right === null)
2170
- return false;
2171
- if (typeof left !== 'object')
2172
- return false;
2173
- if (typeof right !== 'object')
2174
- return false;
2175
- const left_proto = Reflect.getPrototypeOf(left);
2176
- const right_proto = Reflect.getPrototypeOf(right);
2177
- if (left_proto !== right_proto)
2178
- return false;
2179
- if (left instanceof Boolean)
2180
- return Object.is(left.valueOf(), right['valueOf']());
2181
- if (left instanceof Number)
2182
- return Object.is(left.valueOf(), right['valueOf']());
2183
- if (left instanceof String)
2184
- return Object.is(left.valueOf(), right['valueOf']());
2185
- if (left instanceof Date)
2186
- return Object.is(left.valueOf(), right['valueOf']());
2187
- if (left instanceof RegExp)
2188
- return left.source === right.source && left.flags === right.flags;
2189
- if (left instanceof Error)
2190
- return left.message === right.message && left.stack === right.stack;
2191
- let left_cache = $.$mol_compare_deep_cache.get(left);
2192
- if (left_cache) {
2193
- const right_cache = left_cache.get(right);
2194
- if (typeof right_cache === 'boolean')
2195
- return right_cache;
2787
+ filter(check, context) {
2788
+ const filtered = [];
2789
+ let cursor = -1;
2790
+ return $mol_range2(index => {
2791
+ while (cursor < this.length && index >= filtered.length - 1) {
2792
+ const val = this[++cursor];
2793
+ if (check(val, cursor, this))
2794
+ filtered.push(val);
2795
+ }
2796
+ return filtered[index];
2797
+ }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
2196
2798
  }
2197
- else {
2198
- left_cache = new WeakMap([[right, true]]);
2199
- $.$mol_compare_deep_cache.set(left, left_cache);
2799
+ forEach(proceed, context) {
2800
+ for (let [key, value] of this.entries())
2801
+ proceed.call(context, value, key, this);
2200
2802
  }
2201
- let result;
2202
- try {
2203
- if (!left_proto)
2204
- result = compare_pojo(left, right);
2205
- else if (!Reflect.getPrototypeOf(left_proto))
2206
- result = compare_pojo(left, right);
2207
- else if (Symbol.toPrimitive in left)
2208
- result = compare_primitive(left, right);
2209
- else if (Array.isArray(left))
2210
- result = compare_array(left, right);
2211
- else if (left instanceof Set)
2212
- result = compare_set(left, right);
2213
- else if (left instanceof Map)
2214
- result = compare_map(left, right);
2215
- else if (ArrayBuffer.isView(left))
2216
- result = compare_buffer(left, right);
2217
- else if (Symbol.iterator in left)
2218
- result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
2219
- else
2220
- result = false;
2803
+ map(proceed, context) {
2804
+ return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
2221
2805
  }
2222
- finally {
2223
- left_cache.set(right, result);
2806
+ reduce(merge, result) {
2807
+ let index = 0;
2808
+ if (arguments.length === 1) {
2809
+ result = this[index++];
2810
+ }
2811
+ for (; index < this.length; ++index) {
2812
+ result = merge(result, this[index], index, this);
2813
+ }
2814
+ return result;
2224
2815
  }
2225
- return result;
2226
- }
2227
- $.$mol_compare_deep = $mol_compare_deep;
2228
- function compare_array(left, right) {
2229
- const len = left.length;
2230
- if (len !== right.length)
2231
- return false;
2232
- for (let i = 0; i < len; ++i) {
2233
- if (!$mol_compare_deep(left[i], right[i]))
2234
- return false;
2816
+ toReversed() {
2817
+ return $mol_range2(index => this[this.length - 1 - index], () => this.length);
2235
2818
  }
2236
- return true;
2237
- }
2238
- function compare_buffer(left, right) {
2239
- const len = left.byteLength;
2240
- if (len !== right.byteLength)
2819
+ slice(from = 0, to = this.length) {
2820
+ return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
2821
+ }
2822
+ some(check, context) {
2823
+ for (let index = 0; index < this.length; ++index) {
2824
+ if (check.call(context, this[index], index, this))
2825
+ return true;
2826
+ }
2241
2827
  return false;
2242
- if (left instanceof DataView)
2243
- return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
2244
- for (let i = 0; i < len; ++i) {
2245
- if (left[i] !== right[i])
2246
- return false;
2247
2828
  }
2248
- return true;
2249
- }
2250
- function compare_iterator(left, right) {
2251
- while (true) {
2252
- const left_next = left.next();
2253
- const right_next = right.next();
2254
- if (left_next.done !== right_next.done)
2255
- return false;
2256
- if (left_next.done)
2257
- break;
2258
- if (!$mol_compare_deep(left_next.value, right_next.value))
2259
- return false;
2829
+ every(check, context) {
2830
+ for (let index = 0; index < this.length; ++index) {
2831
+ if (!check.call(context, this[index], index, this))
2832
+ return false;
2833
+ }
2834
+ return true;
2260
2835
  }
2261
- return true;
2262
- }
2263
- function compare_set(left, right) {
2264
- if (left.size !== right.size)
2265
- return false;
2266
- return compare_iterator(left.values(), right.values());
2267
- }
2268
- function compare_map(left, right) {
2269
- if (left.size !== right.size)
2270
- return false;
2271
- return compare_iterator(left.keys(), right.keys())
2272
- && compare_iterator(left.values(), right.values());
2273
- }
2274
- function compare_pojo(left, right) {
2275
- const left_keys = Object.getOwnPropertyNames(left);
2276
- const right_keys = Object.getOwnPropertyNames(right);
2277
- if (!compare_array(left_keys, right_keys))
2278
- return false;
2279
- for (let key of left_keys) {
2280
- if (!$mol_compare_deep(left[key], right[key]))
2281
- return false;
2836
+ reverse() {
2837
+ return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
2282
2838
  }
2283
- const left_syms = Object.getOwnPropertySymbols(left);
2284
- const right_syms = Object.getOwnPropertySymbols(right);
2285
- if (!compare_array(left_syms, right_syms))
2286
- return false;
2287
- for (let key of left_syms) {
2288
- if (!$mol_compare_deep(left[key], right[key]))
2289
- return false;
2839
+ sort() {
2840
+ return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
2841
+ }
2842
+ [Symbol.toPrimitive]() {
2843
+ return $mol_guid();
2844
+ }
2845
+ }
2846
+ $.$mol_range2_array = $mol_range2_array;
2847
+ })($ || ($ = {}));
2848
+
2849
+ ;
2850
+ "use strict";
2851
+ var $;
2852
+ (function ($) {
2853
+ $mol_test({
2854
+ 'lazy calls'() {
2855
+ let calls = 0;
2856
+ const list = $mol_range2(index => (++calls, index), () => 10);
2857
+ $mol_assert_equal(true, list instanceof Array);
2858
+ $mol_assert_equal(list.length, 10);
2859
+ $mol_assert_equal(list[-1], undefined);
2860
+ $mol_assert_equal(list[0], 0);
2861
+ $mol_assert_equal(list[9], 9);
2862
+ $mol_assert_equal(list[9.5], undefined);
2863
+ $mol_assert_equal(list[10], undefined);
2864
+ $mol_assert_equal(calls, 2);
2865
+ },
2866
+ 'infinity list'() {
2867
+ let calls = 0;
2868
+ const list = $mol_range2(index => (++calls, index));
2869
+ $mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
2870
+ $mol_assert_equal(list[0], 0);
2871
+ $mol_assert_equal(list[4], 4);
2872
+ $mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
2873
+ $mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
2874
+ $mol_assert_equal(calls, 3);
2875
+ },
2876
+ 'stringify'() {
2877
+ const list = $mol_range2(i => i, () => 5);
2878
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
2879
+ $mol_assert_equal(list.join(';'), '0;1;2;3;4');
2880
+ },
2881
+ 'for-of'() {
2882
+ let log = '';
2883
+ for (let i of $mol_range2(i => i + 1, () => 5)) {
2884
+ log += i;
2885
+ }
2886
+ $mol_assert_equal(log, '12345');
2887
+ },
2888
+ 'for-in'() {
2889
+ let log = '';
2890
+ for (let i in $mol_range2(i => i, () => 5)) {
2891
+ log += i;
2892
+ }
2893
+ $mol_assert_equal(log, '01234');
2894
+ },
2895
+ 'forEach'() {
2896
+ let log = '';
2897
+ $mol_range2(i => i, () => 5).forEach(i => log += i);
2898
+ $mol_assert_equal(log, '01234');
2899
+ },
2900
+ 'reduce'() {
2901
+ let calls = 0;
2902
+ const list = $mol_range2().slice(1, 6);
2903
+ $mol_assert_equal(list.reduce((s, v) => s + v), 15);
2904
+ $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
2905
+ },
2906
+ 'lazy concat'() {
2907
+ let calls1 = 0;
2908
+ let calls2 = 0;
2909
+ const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
2910
+ $mol_assert_equal(true, list instanceof Array);
2911
+ $mol_assert_equal(list.length, 15);
2912
+ $mol_assert_equal(list[0], 0);
2913
+ $mol_assert_equal(list[4], 4);
2914
+ $mol_assert_equal(list[5], 0);
2915
+ $mol_assert_equal(list[9], 4);
2916
+ $mol_assert_equal(list[10], 0);
2917
+ $mol_assert_equal(list[14], 4);
2918
+ $mol_assert_equal(list[15], undefined);
2919
+ $mol_assert_equal(calls1, 2);
2920
+ $mol_assert_equal(calls2, 2);
2921
+ },
2922
+ 'lazy filter'() {
2923
+ let calls = 0;
2924
+ const list = $mol_range2(index => (++calls, index), () => 15).filter(v => v % 2).slice(0, 3);
2925
+ $mol_assert_equal(true, list instanceof Array);
2926
+ $mol_assert_equal(list.length, 3);
2927
+ $mol_assert_equal(list[0], 1);
2928
+ $mol_assert_equal(list[2], 5);
2929
+ $mol_assert_equal(list[3], undefined);
2930
+ $mol_assert_equal(calls, 8);
2931
+ },
2932
+ 'lazy reverse'() {
2933
+ let calls = 0;
2934
+ const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
2935
+ $mol_assert_equal(true, list instanceof Array);
2936
+ $mol_assert_equal(list.length, 3);
2937
+ $mol_assert_equal(list[0], 9);
2938
+ $mol_assert_equal(list[2], 7);
2939
+ $mol_assert_equal(list[3], undefined);
2940
+ $mol_assert_equal(calls, 2);
2941
+ },
2942
+ 'lazy map'() {
2943
+ let calls1 = 0;
2944
+ let calls2 = 0;
2945
+ const source = $mol_range2(index => (++calls1, index), () => 5);
2946
+ const target = source.map((item, index, self) => {
2947
+ ++calls2;
2948
+ $mol_assert_equal(source, self);
2949
+ return index + 10;
2950
+ }, () => 5);
2951
+ $mol_assert_equal(true, target instanceof Array);
2952
+ $mol_assert_equal(target.length, 5);
2953
+ $mol_assert_equal(target[0], 10);
2954
+ $mol_assert_equal(target[4], 14);
2955
+ $mol_assert_equal(target[5], undefined);
2956
+ $mol_assert_equal(calls1, 2);
2957
+ $mol_assert_equal(calls2, 2);
2958
+ },
2959
+ 'lazy slice'() {
2960
+ let calls = 0;
2961
+ const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
2962
+ $mol_assert_equal(true, list instanceof Array);
2963
+ $mol_assert_equal(list.length, 4);
2964
+ $mol_assert_equal(list[0], 3);
2965
+ $mol_assert_equal(list[3], 6);
2966
+ $mol_assert_equal(list[4], undefined);
2967
+ $mol_assert_equal(calls, 2);
2968
+ },
2969
+ 'lazy some'() {
2970
+ let calls = 0;
2971
+ $mol_assert_equal(true, $mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
2972
+ $mol_assert_equal(calls, 3);
2973
+ $mol_assert_equal(false, $mol_range2(i => i, () => 0).some(v => true));
2974
+ $mol_assert_equal(true, $mol_range2(i => i).some(v => v > 5));
2975
+ },
2976
+ 'lazy every'() {
2977
+ let calls = 0;
2978
+ $mol_assert_equal(false, $mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
2979
+ $mol_assert_equal(calls, 3);
2980
+ $mol_assert_equal(true, $mol_range2(i => i, () => 0).every(v => false));
2981
+ $mol_assert_equal(false, $mol_range2(i => i).every(v => v < 5));
2982
+ },
2983
+ 'lazyfy'() {
2984
+ let calls = 0;
2985
+ const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
2986
+ $mol_assert_equal(true, list instanceof Array);
2987
+ $mol_assert_equal(list.length, 4);
2988
+ $mol_assert_equal(calls, 0);
2989
+ $mol_assert_equal(list[0], 12);
2990
+ $mol_assert_equal(list[3], 15);
2991
+ $mol_assert_equal(list[4], undefined);
2992
+ $mol_assert_equal(calls, 2);
2993
+ },
2994
+ 'prevent modification'() {
2995
+ const list = $mol_range2(i => i, () => 5);
2996
+ $mol_assert_fail(() => list.push(4), TypeError);
2997
+ $mol_assert_fail(() => list.pop(), TypeError);
2998
+ $mol_assert_fail(() => list.unshift(4), TypeError);
2999
+ $mol_assert_fail(() => list.shift(), TypeError);
3000
+ $mol_assert_fail(() => list.splice(1, 2), TypeError);
3001
+ $mol_assert_fail(() => list[1] = 2, TypeError);
3002
+ $mol_assert_fail(() => list.reverse(), TypeError);
3003
+ $mol_assert_fail(() => list.sort(), TypeError);
3004
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
2290
3005
  }
2291
- return true;
2292
- }
2293
- function compare_primitive(left, right) {
2294
- return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
2295
- }
3006
+ });
2296
3007
  })($ || ($ = {}));
2297
3008
 
2298
3009
  ;
@@ -2790,6 +3501,348 @@ var $;
2790
3501
  });
2791
3502
  })($ || ($ = {}));
2792
3503
 
3504
+ ;
3505
+ "use strict";
3506
+ var $;
3507
+ (function ($_1) {
3508
+ $mol_test({
3509
+ 'Collect deps'() {
3510
+ const pub1 = new $mol_wire_pub;
3511
+ const pub2 = new $mol_wire_pub;
3512
+ const sub = new $mol_wire_pub_sub;
3513
+ const bu1 = sub.track_on();
3514
+ try {
3515
+ pub1.promote();
3516
+ pub2.promote();
3517
+ pub2.promote();
3518
+ }
3519
+ finally {
3520
+ sub.track_cut();
3521
+ sub.track_off(bu1);
3522
+ }
3523
+ pub1.emit();
3524
+ pub2.emit();
3525
+ $mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
3526
+ const bu2 = sub.track_on();
3527
+ try {
3528
+ pub1.promote();
3529
+ pub1.promote();
3530
+ pub2.promote();
3531
+ }
3532
+ finally {
3533
+ sub.track_cut();
3534
+ sub.track_off(bu2);
3535
+ }
3536
+ pub1.emit();
3537
+ pub2.emit();
3538
+ $mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
3539
+ },
3540
+ 'cyclic detection'($) {
3541
+ const sub1 = new $mol_wire_pub_sub;
3542
+ const sub2 = new $mol_wire_pub_sub;
3543
+ const bu1 = sub1.track_on();
3544
+ try {
3545
+ const bu2 = sub2.track_on();
3546
+ try {
3547
+ $mol_assert_fail(() => sub1.promote(), 'Circular subscription');
3548
+ }
3549
+ finally {
3550
+ sub2.track_cut();
3551
+ sub2.track_off(bu2);
3552
+ }
3553
+ }
3554
+ finally {
3555
+ sub1.track_cut();
3556
+ sub1.track_off(bu1);
3557
+ }
3558
+ },
3559
+ });
3560
+ })($ || ($ = {}));
3561
+
3562
+ ;
3563
+ "use strict";
3564
+ var $;
3565
+ (function ($) {
3566
+ $.$mol_after_mock_queue = [];
3567
+ function $mol_after_mock_warp() {
3568
+ const queue = $.$mol_after_mock_queue.splice(0);
3569
+ for (const task of queue)
3570
+ task();
3571
+ }
3572
+ $.$mol_after_mock_warp = $mol_after_mock_warp;
3573
+ class $mol_after_mock_commmon extends $mol_object2 {
3574
+ task;
3575
+ promise = Promise.resolve();
3576
+ cancelled = false;
3577
+ id;
3578
+ constructor(task) {
3579
+ super();
3580
+ this.task = task;
3581
+ $.$mol_after_mock_queue.push(task);
3582
+ }
3583
+ destructor() {
3584
+ const index = $.$mol_after_mock_queue.indexOf(this.task);
3585
+ if (index >= 0)
3586
+ $.$mol_after_mock_queue.splice(index, 1);
3587
+ }
3588
+ }
3589
+ $.$mol_after_mock_commmon = $mol_after_mock_commmon;
3590
+ class $mol_after_mock_timeout extends $mol_after_mock_commmon {
3591
+ delay;
3592
+ constructor(delay, task) {
3593
+ super(task);
3594
+ this.delay = delay;
3595
+ }
3596
+ }
3597
+ $.$mol_after_mock_timeout = $mol_after_mock_timeout;
3598
+ })($ || ($ = {}));
3599
+
3600
+ ;
3601
+ "use strict";
3602
+ var $;
3603
+ (function ($_1) {
3604
+ $mol_test_mocks.push($ => {
3605
+ $.$mol_after_timeout = $mol_after_mock_timeout;
3606
+ });
3607
+ })($ || ($ = {}));
3608
+
3609
+ ;
3610
+ "use strict";
3611
+ var $;
3612
+ (function ($_1) {
3613
+ $mol_test_mocks.push($ => {
3614
+ $.$mol_after_frame = $mol_after_mock_commmon;
3615
+ });
3616
+ })($ || ($ = {}));
3617
+
3618
+ ;
3619
+ "use strict";
3620
+ var $;
3621
+ (function ($) {
3622
+ $mol_test({
3623
+ 'Sync execution'() {
3624
+ class Sync extends $mol_object2 {
3625
+ static calc(a, b) {
3626
+ return a + b;
3627
+ }
3628
+ }
3629
+ __decorate([
3630
+ $mol_wire_method
3631
+ ], Sync, "calc", null);
3632
+ $mol_assert_equal(Sync.calc(1, 2), 3);
3633
+ },
3634
+ async 'async <=> sync'() {
3635
+ class SyncAsync extends $mol_object2 {
3636
+ static async val(a) {
3637
+ return a;
3638
+ }
3639
+ static sum(a, b) {
3640
+ const syn = $mol_wire_sync(this);
3641
+ return syn.val(a) + syn.val(b);
3642
+ }
3643
+ static async calc(a, b) {
3644
+ return 5 + await $mol_wire_async(this).sum(a, b);
3645
+ }
3646
+ }
3647
+ $mol_assert_equal(await SyncAsync.calc(1, 2), 8);
3648
+ },
3649
+ async 'Idempotence control'() {
3650
+ class Idempotence extends $mol_object2 {
3651
+ static logs_idemp = 0;
3652
+ static logs_unidemp = 0;
3653
+ static log_idemp() {
3654
+ this.logs_idemp += 1;
3655
+ }
3656
+ static log_unidemp() {
3657
+ this.logs_unidemp += 1;
3658
+ }
3659
+ static async val(a) {
3660
+ return a;
3661
+ }
3662
+ static sum(a, b) {
3663
+ this.log_idemp();
3664
+ this.log_unidemp();
3665
+ const syn = $mol_wire_sync(this);
3666
+ return syn.val(a) + syn.val(b);
3667
+ }
3668
+ static async calc(a, b) {
3669
+ return 5 + await $mol_wire_async(this).sum(a, b);
3670
+ }
3671
+ }
3672
+ __decorate([
3673
+ $mol_wire_method
3674
+ ], Idempotence, "log_idemp", null);
3675
+ $mol_assert_equal(await Idempotence.calc(1, 2), 8);
3676
+ $mol_assert_equal(Idempotence.logs_idemp, 1);
3677
+ $mol_assert_equal(Idempotence.logs_unidemp, 3);
3678
+ },
3679
+ async 'Error handling'() {
3680
+ class Handle extends $mol_object2 {
3681
+ static async sum(a, b) {
3682
+ $mol_fail(new Error('test error ' + (a + b)));
3683
+ }
3684
+ static check() {
3685
+ try {
3686
+ return $mol_wire_sync(Handle).sum(1, 2);
3687
+ }
3688
+ catch (error) {
3689
+ if ($mol_promise_like(error))
3690
+ $mol_fail_hidden(error);
3691
+ $mol_assert_equal(error.message, 'test error 3');
3692
+ }
3693
+ }
3694
+ }
3695
+ await $mol_wire_async(Handle).check();
3696
+ },
3697
+ });
3698
+ })($ || ($ = {}));
3699
+
3700
+ ;
3701
+ "use strict";
3702
+ var $;
3703
+ (function ($) {
3704
+ function $mol_wire_method(host, field, descr) {
3705
+ if (!descr)
3706
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
3707
+ const orig = descr?.value ?? host[field];
3708
+ const sup = Reflect.getPrototypeOf(host);
3709
+ if (typeof sup[field] === 'function') {
3710
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
3711
+ }
3712
+ const temp = $mol_wire_task.getter(orig);
3713
+ const value = function (...args) {
3714
+ const fiber = temp(this ?? null, args);
3715
+ return fiber.sync();
3716
+ };
3717
+ Object.defineProperty(value, 'name', { value: orig.name + ' ' });
3718
+ Object.assign(value, { orig });
3719
+ const descr2 = { ...descr, value };
3720
+ Reflect.defineProperty(host, field, descr2);
3721
+ return descr2;
3722
+ }
3723
+ $.$mol_wire_method = $mol_wire_method;
3724
+ })($ || ($ = {}));
3725
+
3726
+ ;
3727
+ "use strict";
3728
+ var $;
3729
+ (function ($) {
3730
+ function $mol_promise() {
3731
+ let done;
3732
+ let fail;
3733
+ const promise = new Promise((d, f) => {
3734
+ done = d;
3735
+ fail = f;
3736
+ });
3737
+ return Object.assign(promise, {
3738
+ done,
3739
+ fail,
3740
+ });
3741
+ }
3742
+ $.$mol_promise = $mol_promise;
3743
+ })($ || ($ = {}));
3744
+
3745
+ ;
3746
+ "use strict";
3747
+ var $;
3748
+ (function ($) {
3749
+ function $mol_wait_timeout_async(timeout) {
3750
+ const promise = $mol_promise();
3751
+ const task = new this.$mol_after_timeout(timeout, () => promise.done());
3752
+ return Object.assign(promise, {
3753
+ destructor: () => task.destructor()
3754
+ });
3755
+ }
3756
+ $.$mol_wait_timeout_async = $mol_wait_timeout_async;
3757
+ function $mol_wait_timeout(timeout) {
3758
+ return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
3759
+ }
3760
+ $.$mol_wait_timeout = $mol_wait_timeout;
3761
+ })($ || ($ = {}));
3762
+
3763
+ ;
3764
+ "use strict";
3765
+ var $;
3766
+ (function ($) {
3767
+ function $mol_wire_async(obj) {
3768
+ let fiber;
3769
+ const temp = $mol_wire_task.getter(obj);
3770
+ return new Proxy(obj, {
3771
+ get(obj, field) {
3772
+ const val = obj[field];
3773
+ if (typeof val !== 'function')
3774
+ return val;
3775
+ let fiber;
3776
+ const temp = $mol_wire_task.getter(val);
3777
+ return function $mol_wire_async(...args) {
3778
+ fiber?.destructor();
3779
+ fiber = temp(obj, args);
3780
+ return fiber.async();
3781
+ };
3782
+ },
3783
+ apply(obj, self, args) {
3784
+ fiber?.destructor();
3785
+ fiber = temp(self, args);
3786
+ return fiber.async();
3787
+ },
3788
+ });
3789
+ }
3790
+ $.$mol_wire_async = $mol_wire_async;
3791
+ })($ || ($ = {}));
3792
+
3793
+ ;
3794
+ "use strict";
3795
+ var $;
3796
+ (function ($_1) {
3797
+ $mol_test({
3798
+ 'test types'($) {
3799
+ class A {
3800
+ static a() {
3801
+ return '';
3802
+ }
3803
+ static b() {
3804
+ return $mol_wire_async(this).a();
3805
+ }
3806
+ }
3807
+ },
3808
+ async 'Latest method calls wins'($) {
3809
+ class NameLogger extends $mol_object2 {
3810
+ static $ = $;
3811
+ static first = [];
3812
+ static last = [];
3813
+ static send(next) {
3814
+ $mol_wire_sync(this.first).push(next);
3815
+ this.$.$mol_wait_timeout(0);
3816
+ this.last.push(next);
3817
+ }
3818
+ }
3819
+ const name = $mol_wire_async(NameLogger).send;
3820
+ name('john');
3821
+ const promise = name('jin');
3822
+ $.$mol_after_mock_warp();
3823
+ await promise;
3824
+ $mol_assert_like(NameLogger.first, ['john', 'jin']);
3825
+ $mol_assert_like(NameLogger.last, ['jin']);
3826
+ },
3827
+ async 'Latest function calls wins'($) {
3828
+ const first = [];
3829
+ const last = [];
3830
+ function send_name(next) {
3831
+ $mol_wire_sync(first).push(next);
3832
+ $.$mol_wait_timeout(0);
3833
+ last.push(next);
3834
+ }
3835
+ const name = $mol_wire_async(send_name);
3836
+ name('john');
3837
+ const promise = name('jin');
3838
+ $.$mol_after_mock_warp();
3839
+ await promise;
3840
+ $mol_assert_like(first, ['john', 'jin']);
3841
+ $mol_assert_like(last, ['jin']);
3842
+ },
3843
+ });
3844
+ })($ || ($ = {}));
3845
+
2793
3846
  ;
2794
3847
  "use strict";
2795
3848
  var $;