mol_conform 0.0.1

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/web.test.js ADDED
@@ -0,0 +1,1398 @@
1
+ "use strict";
2
+ function require( path ){ return $node[ path ] };
3
+ "use strict";
4
+ var $;
5
+ (function ($) {
6
+ function $mol_promise_like(val) {
7
+ try {
8
+ return val && typeof val === 'object' && 'then' in val && typeof val.then === 'function';
9
+ }
10
+ catch {
11
+ return false;
12
+ }
13
+ }
14
+ $.$mol_promise_like = $mol_promise_like;
15
+ })($ || ($ = {}));
16
+
17
+ ;
18
+ "use strict";
19
+ var $;
20
+ (function ($) {
21
+ function $mol_fail(error) {
22
+ throw error;
23
+ }
24
+ $.$mol_fail = $mol_fail;
25
+ })($ || ($ = {}));
26
+
27
+ ;
28
+ "use strict";
29
+ var $;
30
+ (function ($) {
31
+ function $mol_fail_hidden(error) {
32
+ throw error;
33
+ }
34
+ $.$mol_fail_hidden = $mol_fail_hidden;
35
+ })($ || ($ = {}));
36
+
37
+ ;
38
+ "use strict";
39
+ var $;
40
+ (function ($_1) {
41
+ function $mol_test(set) {
42
+ for (let name in set) {
43
+ const code = set[name];
44
+ const test = (typeof code === 'string') ? new Function('', code) : code;
45
+ $_1.$mol_test_all.push(test);
46
+ }
47
+ $mol_test_schedule();
48
+ }
49
+ $_1.$mol_test = $mol_test;
50
+ $_1.$mol_test_mocks = [];
51
+ $_1.$mol_test_all = [];
52
+ async function $mol_test_run() {
53
+ for (var test of $_1.$mol_test_all) {
54
+ let context = Object.create($$);
55
+ for (let mock of $_1.$mol_test_mocks)
56
+ await mock(context);
57
+ const res = test(context);
58
+ if ($mol_promise_like(res)) {
59
+ await new Promise((done, fail) => {
60
+ res.then(done, fail);
61
+ setTimeout(() => fail(new Error('Test timeout: ' + test.name)), 1000);
62
+ });
63
+ }
64
+ }
65
+ $$.$mol_log3_done({
66
+ place: '$mol_test',
67
+ message: 'All tests passed',
68
+ count: $_1.$mol_test_all.length,
69
+ });
70
+ }
71
+ $_1.$mol_test_run = $mol_test_run;
72
+ let scheduled = false;
73
+ function $mol_test_schedule() {
74
+ if (scheduled)
75
+ return;
76
+ scheduled = true;
77
+ setTimeout(async () => {
78
+ scheduled = false;
79
+ await $mol_test_run();
80
+ $$.$mol_test_complete();
81
+ }, 1000);
82
+ }
83
+ $_1.$mol_test_schedule = $mol_test_schedule;
84
+ $_1.$mol_test_mocks.push(context => {
85
+ let seed = 0;
86
+ context.Math = Object.create(Math);
87
+ context.Math.random = () => Math.sin(seed++);
88
+ const forbidden = ['XMLHttpRequest', 'fetch'];
89
+ for (let api of forbidden) {
90
+ context[api] = new Proxy(function () { }, {
91
+ get() {
92
+ $mol_fail_hidden(new Error(`${api} is forbidden in tests`));
93
+ },
94
+ apply() {
95
+ $mol_fail_hidden(new Error(`${api} is forbidden in tests`));
96
+ },
97
+ });
98
+ }
99
+ });
100
+ $mol_test({
101
+ 'mocked Math.random'($) {
102
+ console.assert($.Math.random() === 0);
103
+ console.assert($.Math.random() === Math.sin(1));
104
+ },
105
+ 'forbidden XMLHttpRequest'($) {
106
+ try {
107
+ console.assert(void new $.XMLHttpRequest);
108
+ }
109
+ catch (error) {
110
+ console.assert(error.message === 'XMLHttpRequest is forbidden in tests');
111
+ }
112
+ },
113
+ 'forbidden fetch'($) {
114
+ try {
115
+ console.assert(void $.fetch(''));
116
+ }
117
+ catch (error) {
118
+ console.assert(error.message === 'fetch is forbidden in tests');
119
+ }
120
+ },
121
+ });
122
+ })($ || ($ = {}));
123
+
124
+ ;
125
+ "use strict";
126
+ var $;
127
+ (function ($) {
128
+ function $mol_test_complete() {
129
+ }
130
+ $.$mol_test_complete = $mol_test_complete;
131
+ })($ || ($ = {}));
132
+
133
+ ;
134
+ "use strict";
135
+ var $;
136
+ (function ($) {
137
+ })($ || ($ = {}));
138
+
139
+ ;
140
+ "use strict";
141
+ var $;
142
+ (function ($) {
143
+ $.$mol_dom_context = self;
144
+ })($ || ($ = {}));
145
+
146
+ ;
147
+ "use strict";
148
+ var $;
149
+ (function ($) {
150
+ $.$mol_dom = $mol_dom_context;
151
+ })($ || ($ = {}));
152
+
153
+ ;
154
+ "use strict";
155
+ var $;
156
+ (function ($) {
157
+ function $mol_dom_render_children(el, childNodes) {
158
+ const node_set = new Set(childNodes);
159
+ let nextNode = el.firstChild;
160
+ for (let view of childNodes) {
161
+ if (view == null)
162
+ continue;
163
+ if (view instanceof $mol_dom_context.Node) {
164
+ while (true) {
165
+ if (!nextNode) {
166
+ el.appendChild(view);
167
+ break;
168
+ }
169
+ if (nextNode == view) {
170
+ nextNode = nextNode.nextSibling;
171
+ break;
172
+ }
173
+ else {
174
+ if (node_set.has(nextNode)) {
175
+ el.insertBefore(view, nextNode);
176
+ break;
177
+ }
178
+ else {
179
+ const nn = nextNode.nextSibling;
180
+ el.removeChild(nextNode);
181
+ nextNode = nn;
182
+ }
183
+ }
184
+ }
185
+ }
186
+ else {
187
+ if (nextNode && nextNode.nodeName === '#text') {
188
+ const str = String(view);
189
+ if (nextNode.nodeValue !== str)
190
+ nextNode.nodeValue = str;
191
+ nextNode = nextNode.nextSibling;
192
+ }
193
+ else {
194
+ const textNode = $mol_dom_context.document.createTextNode(String(view));
195
+ el.insertBefore(textNode, nextNode);
196
+ }
197
+ }
198
+ }
199
+ while (nextNode) {
200
+ const currNode = nextNode;
201
+ nextNode = currNode.nextSibling;
202
+ el.removeChild(currNode);
203
+ }
204
+ }
205
+ $.$mol_dom_render_children = $mol_dom_render_children;
206
+ })($ || ($ = {}));
207
+
208
+ ;
209
+ "use strict";
210
+
211
+ ;
212
+ "use strict";
213
+
214
+ ;
215
+ "use strict";
216
+
217
+ ;
218
+ "use strict";
219
+
220
+ ;
221
+ "use strict";
222
+
223
+ ;
224
+ "use strict";
225
+ var $;
226
+ (function ($) {
227
+ function $mol_dom_serialize(node) {
228
+ const serializer = new $mol_dom_context.XMLSerializer;
229
+ return serializer.serializeToString(node);
230
+ }
231
+ $.$mol_dom_serialize = $mol_dom_serialize;
232
+ })($ || ($ = {}));
233
+
234
+ ;
235
+ "use strict";
236
+ var $;
237
+ (function ($) {
238
+ $.$mol_jsx_prefix = '';
239
+ $.$mol_jsx_crumbs = '';
240
+ $.$mol_jsx_booked = null;
241
+ $.$mol_jsx_document = {
242
+ getElementById: () => null,
243
+ createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
244
+ createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
245
+ };
246
+ $.$mol_jsx_frag = '';
247
+ function $mol_jsx(Elem, props, ...childNodes) {
248
+ const id = props && props.id || '';
249
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
250
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
251
+ if (Elem && $.$mol_jsx_booked) {
252
+ if ($.$mol_jsx_booked.has(id)) {
253
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
254
+ }
255
+ else {
256
+ $.$mol_jsx_booked.add(id);
257
+ }
258
+ }
259
+ let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
260
+ if ($.$mol_jsx_prefix) {
261
+ const prefix_ext = $.$mol_jsx_prefix;
262
+ const booked_ext = $.$mol_jsx_booked;
263
+ const crumbs_ext = $.$mol_jsx_crumbs;
264
+ for (const field in props) {
265
+ const func = props[field];
266
+ if (typeof func !== 'function')
267
+ continue;
268
+ const wrapper = function (...args) {
269
+ const prefix = $.$mol_jsx_prefix;
270
+ const booked = $.$mol_jsx_booked;
271
+ const crumbs = $.$mol_jsx_crumbs;
272
+ try {
273
+ $.$mol_jsx_prefix = prefix_ext;
274
+ $.$mol_jsx_booked = booked_ext;
275
+ $.$mol_jsx_crumbs = crumbs_ext;
276
+ return func.call(this, ...args);
277
+ }
278
+ finally {
279
+ $.$mol_jsx_prefix = prefix;
280
+ $.$mol_jsx_booked = booked;
281
+ $.$mol_jsx_crumbs = crumbs;
282
+ }
283
+ };
284
+ $mol_func_name_from(wrapper, func);
285
+ props[field] = wrapper;
286
+ }
287
+ }
288
+ if (typeof Elem !== 'string') {
289
+ if ('prototype' in Elem) {
290
+ const view = node && node[String(Elem)] || new Elem;
291
+ Object.assign(view, props);
292
+ view[Symbol.toStringTag] = guid;
293
+ view.childNodes = childNodes;
294
+ if (!view.ownerDocument)
295
+ view.ownerDocument = $.$mol_jsx_document;
296
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
297
+ node = view.valueOf();
298
+ node[String(Elem)] = view;
299
+ return node;
300
+ }
301
+ else {
302
+ const prefix = $.$mol_jsx_prefix;
303
+ const booked = $.$mol_jsx_booked;
304
+ const crumbs = $.$mol_jsx_crumbs;
305
+ try {
306
+ $.$mol_jsx_prefix = guid;
307
+ $.$mol_jsx_booked = new Set;
308
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
309
+ return Elem(props, ...childNodes);
310
+ }
311
+ finally {
312
+ $.$mol_jsx_prefix = prefix;
313
+ $.$mol_jsx_booked = booked;
314
+ $.$mol_jsx_crumbs = crumbs;
315
+ }
316
+ }
317
+ }
318
+ if (!node) {
319
+ node = Elem
320
+ ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
321
+ : $.$mol_jsx_document.createDocumentFragment();
322
+ }
323
+ $mol_dom_render_children(node, [].concat(...childNodes));
324
+ if (!Elem)
325
+ return node;
326
+ if (guid)
327
+ node.id = guid;
328
+ for (const key in props) {
329
+ if (key === 'id')
330
+ continue;
331
+ if (typeof props[key] === 'string') {
332
+ if (typeof node[key] === 'string')
333
+ node[key] = props[key];
334
+ node.setAttribute(key, props[key]);
335
+ }
336
+ else if (props[key] &&
337
+ typeof props[key] === 'object' &&
338
+ Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
339
+ if (typeof node[key] === 'object') {
340
+ Object.assign(node[key], props[key]);
341
+ continue;
342
+ }
343
+ }
344
+ else {
345
+ node[key] = props[key];
346
+ }
347
+ }
348
+ if ($.$mol_jsx_crumbs)
349
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
350
+ return node;
351
+ }
352
+ $.$mol_jsx = $mol_jsx;
353
+ })($ || ($ = {}));
354
+
355
+ ;
356
+ "use strict";
357
+ var $;
358
+ (function ($) {
359
+ $mol_test({
360
+ 'Make empty div'() {
361
+ $mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
362
+ },
363
+ 'Define native field'() {
364
+ const dom = $mol_jsx("input", { value: '123' });
365
+ $mol_assert_equal(dom.outerHTML, '<input value="123">');
366
+ $mol_assert_equal(dom.value, '123');
367
+ },
368
+ 'Define classes'() {
369
+ const dom = $mol_jsx("div", { class: 'foo bar' });
370
+ $mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
371
+ },
372
+ 'Define styles'() {
373
+ const dom = $mol_jsx("div", { style: { color: 'red' } });
374
+ $mol_assert_equal(dom.outerHTML, '<div style="color: red;"></div>');
375
+ },
376
+ 'Define dataset'() {
377
+ const dom = $mol_jsx("div", { dataset: { foo: 'bar' } });
378
+ $mol_assert_equal(dom.outerHTML, '<div data-foo="bar"></div>');
379
+ },
380
+ 'Define attributes'() {
381
+ const dom = $mol_jsx("div", { lang: "ru", hidden: true });
382
+ $mol_assert_equal(dom.outerHTML, '<div lang="ru" hidden=""></div>');
383
+ },
384
+ 'Define child nodes'() {
385
+ const dom = $mol_jsx("div", null,
386
+ "hello",
387
+ $mol_jsx("strong", null, "world"),
388
+ "!");
389
+ $mol_assert_equal(dom.outerHTML, '<div>hello<strong>world</strong>!</div>');
390
+ },
391
+ 'Make fragment'() {
392
+ const dom = $mol_jsx($mol_jsx_frag, null,
393
+ $mol_jsx("br", null),
394
+ $mol_jsx("hr", null));
395
+ $mol_assert_equal($mol_dom_serialize(dom), '<br xmlns="http://www.w3.org/1999/xhtml" /><hr xmlns="http://www.w3.org/1999/xhtml" />');
396
+ },
397
+ 'Spread fragment'() {
398
+ const dom = $mol_jsx("div", null,
399
+ $mol_jsx($mol_jsx_frag, null,
400
+ $mol_jsx("br", null),
401
+ $mol_jsx("hr", null)));
402
+ $mol_assert_equal(dom.outerHTML, '<div><br><hr></div>');
403
+ },
404
+ 'Function as component'() {
405
+ const Button = (props, target) => {
406
+ return $mol_jsx("button", { title: props.hint }, target());
407
+ };
408
+ const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
409
+ $mol_assert_equal(dom.outerHTML, '<button id="foo" title="click me" class="Button">hey!</button>');
410
+ },
411
+ 'Nested guid generation'() {
412
+ const Foo = () => {
413
+ return $mol_jsx("div", null,
414
+ $mol_jsx(Bar, { id: "bar" },
415
+ $mol_jsx("img", { id: "icon" })));
416
+ };
417
+ const Bar = (props, icon) => {
418
+ return $mol_jsx("span", null,
419
+ icon,
420
+ $mol_jsx("i", { id: "label" }));
421
+ };
422
+ const dom = $mol_jsx(Foo, { id: "foo" });
423
+ $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>');
424
+ },
425
+ 'Fail on non unique ids'() {
426
+ const App = () => {
427
+ return $mol_jsx("div", null,
428
+ $mol_jsx("span", { id: "bar" }),
429
+ $mol_jsx("span", { id: "bar" }));
430
+ };
431
+ $mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
432
+ },
433
+ 'Owner based guid generationn'() {
434
+ const Foo = () => {
435
+ return $mol_jsx("div", null,
436
+ $mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
437
+ };
438
+ const Bar = (props) => {
439
+ return $mol_jsx("span", null, props.icon());
440
+ };
441
+ const dom = $mol_jsx(Foo, { id: "app" });
442
+ $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>');
443
+ },
444
+ 'Fail on same ids from different caller'() {
445
+ const Foo = () => {
446
+ return $mol_jsx("div", null,
447
+ $mol_jsx("img", { id: "icon" }),
448
+ $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
449
+ };
450
+ const Bar = (props) => {
451
+ return $mol_jsx("span", null, props.icon());
452
+ };
453
+ $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
454
+ },
455
+ });
456
+ })($ || ($ = {}));
457
+
458
+ ;
459
+ "use strict";
460
+ var $;
461
+ (function ($) {
462
+ function $mol_guid(length = 8, exists = () => false) {
463
+ for (;;) {
464
+ let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
465
+ if (exists(id))
466
+ continue;
467
+ return id;
468
+ }
469
+ }
470
+ $.$mol_guid = $mol_guid;
471
+ })($ || ($ = {}));
472
+
473
+ ;
474
+ "use strict";
475
+ var $;
476
+ (function ($) {
477
+ function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
478
+ const source = typeof item === 'function' ? new $mol_range2_array() : item;
479
+ if (typeof item !== 'function') {
480
+ item = index => source[index];
481
+ size = () => source.length;
482
+ }
483
+ return new Proxy(source, {
484
+ get(target, field) {
485
+ if (typeof field === 'string') {
486
+ if (field === 'length')
487
+ return size();
488
+ const index = Number(field);
489
+ if (index < 0)
490
+ return undefined;
491
+ if (index >= size())
492
+ return undefined;
493
+ if (index === Math.trunc(index))
494
+ return item(index);
495
+ }
496
+ return $mol_range2_array.prototype[field];
497
+ },
498
+ set(target, field) {
499
+ return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
500
+ },
501
+ ownKeys(target) {
502
+ return [...Array(size())].map((v, i) => String(i)).concat('length');
503
+ },
504
+ getOwnPropertyDescriptor(target, field) {
505
+ if (field === "length")
506
+ return {
507
+ value: size(),
508
+ writable: true,
509
+ enumerable: false,
510
+ configurable: false,
511
+ };
512
+ const index = Number(field);
513
+ if (index === Math.trunc(index))
514
+ return {
515
+ get: () => this.get(target, field, this),
516
+ enumerable: true,
517
+ configurable: true,
518
+ };
519
+ return Object.getOwnPropertyDescriptor(target, field);
520
+ }
521
+ });
522
+ }
523
+ $.$mol_range2 = $mol_range2;
524
+ class $mol_range2_array extends Array {
525
+ concat(...tail) {
526
+ if (tail.length === 0)
527
+ return this;
528
+ if (tail.length > 1) {
529
+ let list = this;
530
+ for (let item of tail)
531
+ list = list.concat(item);
532
+ return list;
533
+ }
534
+ return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
535
+ }
536
+ filter(check, context) {
537
+ const filtered = [];
538
+ let cursor = -1;
539
+ return $mol_range2(index => {
540
+ while (cursor < this.length && index >= filtered.length - 1) {
541
+ const val = this[++cursor];
542
+ if (check(val, cursor, this))
543
+ filtered.push(val);
544
+ }
545
+ return filtered[index];
546
+ }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
547
+ }
548
+ forEach(proceed, context) {
549
+ for (let [key, value] of this.entries())
550
+ proceed.call(context, value, key, this);
551
+ }
552
+ map(proceed, context) {
553
+ return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
554
+ }
555
+ reduce(merge, result) {
556
+ let index = 0;
557
+ if (arguments.length === 1) {
558
+ result = this[index++];
559
+ }
560
+ for (; index < this.length; ++index) {
561
+ result = merge(result, this[index], index, this);
562
+ }
563
+ return result;
564
+ }
565
+ toReversed() {
566
+ return $mol_range2(index => this[this.length - 1 - index], () => this.length);
567
+ }
568
+ slice(from = 0, to = this.length) {
569
+ return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
570
+ }
571
+ some(check, context) {
572
+ for (let index = 0; index < this.length; ++index) {
573
+ if (check.call(context, this[index], index, this))
574
+ return true;
575
+ }
576
+ return false;
577
+ }
578
+ every(check, context) {
579
+ for (let index = 0; index < this.length; ++index) {
580
+ if (!check.call(context, this[index], index, this))
581
+ return false;
582
+ }
583
+ return true;
584
+ }
585
+ reverse() {
586
+ return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
587
+ }
588
+ sort() {
589
+ return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
590
+ }
591
+ [Symbol.toPrimitive]() {
592
+ return $mol_guid();
593
+ }
594
+ }
595
+ $.$mol_range2_array = $mol_range2_array;
596
+ })($ || ($ = {}));
597
+
598
+ ;
599
+ "use strict";
600
+ var $;
601
+ (function ($) {
602
+ $mol_test({
603
+ 'lazy calls'() {
604
+ let calls = 0;
605
+ const list = $mol_range2(index => (++calls, index), () => 10);
606
+ $mol_assert_equal(true, list instanceof Array);
607
+ $mol_assert_equal(list.length, 10);
608
+ $mol_assert_equal(list[-1], undefined);
609
+ $mol_assert_equal(list[0], 0);
610
+ $mol_assert_equal(list[9], 9);
611
+ $mol_assert_equal(list[9.5], undefined);
612
+ $mol_assert_equal(list[10], undefined);
613
+ $mol_assert_equal(calls, 2);
614
+ },
615
+ 'infinity list'() {
616
+ let calls = 0;
617
+ const list = $mol_range2(index => (++calls, index));
618
+ $mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
619
+ $mol_assert_equal(list[0], 0);
620
+ $mol_assert_equal(list[4], 4);
621
+ $mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
622
+ $mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
623
+ $mol_assert_equal(calls, 3);
624
+ },
625
+ 'stringify'() {
626
+ const list = $mol_range2(i => i, () => 5);
627
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
628
+ $mol_assert_equal(list.join(';'), '0;1;2;3;4');
629
+ },
630
+ 'for-of'() {
631
+ let log = '';
632
+ for (let i of $mol_range2(i => i + 1, () => 5)) {
633
+ log += i;
634
+ }
635
+ $mol_assert_equal(log, '12345');
636
+ },
637
+ 'for-in'() {
638
+ let log = '';
639
+ for (let i in $mol_range2(i => i, () => 5)) {
640
+ log += i;
641
+ }
642
+ $mol_assert_equal(log, '01234');
643
+ },
644
+ 'forEach'() {
645
+ let log = '';
646
+ $mol_range2(i => i, () => 5).forEach(i => log += i);
647
+ $mol_assert_equal(log, '01234');
648
+ },
649
+ 'reduce'() {
650
+ let calls = 0;
651
+ const list = $mol_range2().slice(1, 6);
652
+ $mol_assert_equal(list.reduce((s, v) => s + v), 15);
653
+ $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
654
+ },
655
+ 'lazy concat'() {
656
+ let calls1 = 0;
657
+ let calls2 = 0;
658
+ const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
659
+ $mol_assert_equal(true, list instanceof Array);
660
+ $mol_assert_equal(list.length, 15);
661
+ $mol_assert_equal(list[0], 0);
662
+ $mol_assert_equal(list[4], 4);
663
+ $mol_assert_equal(list[5], 0);
664
+ $mol_assert_equal(list[9], 4);
665
+ $mol_assert_equal(list[10], 0);
666
+ $mol_assert_equal(list[14], 4);
667
+ $mol_assert_equal(list[15], undefined);
668
+ $mol_assert_equal(calls1, 2);
669
+ $mol_assert_equal(calls2, 2);
670
+ },
671
+ 'lazy filter'() {
672
+ let calls = 0;
673
+ const list = $mol_range2(index => (++calls, index), () => 15).filter(v => v % 2).slice(0, 3);
674
+ $mol_assert_equal(true, list instanceof Array);
675
+ $mol_assert_equal(list.length, 3);
676
+ $mol_assert_equal(list[0], 1);
677
+ $mol_assert_equal(list[2], 5);
678
+ $mol_assert_equal(list[3], undefined);
679
+ $mol_assert_equal(calls, 8);
680
+ },
681
+ 'lazy reverse'() {
682
+ let calls = 0;
683
+ const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
684
+ $mol_assert_equal(true, list instanceof Array);
685
+ $mol_assert_equal(list.length, 3);
686
+ $mol_assert_equal(list[0], 9);
687
+ $mol_assert_equal(list[2], 7);
688
+ $mol_assert_equal(list[3], undefined);
689
+ $mol_assert_equal(calls, 2);
690
+ },
691
+ 'lazy map'() {
692
+ let calls1 = 0;
693
+ let calls2 = 0;
694
+ const source = $mol_range2(index => (++calls1, index), () => 5);
695
+ const target = source.map((item, index, self) => {
696
+ ++calls2;
697
+ $mol_assert_equal(source, self);
698
+ return index + 10;
699
+ }, () => 5);
700
+ $mol_assert_equal(true, target instanceof Array);
701
+ $mol_assert_equal(target.length, 5);
702
+ $mol_assert_equal(target[0], 10);
703
+ $mol_assert_equal(target[4], 14);
704
+ $mol_assert_equal(target[5], undefined);
705
+ $mol_assert_equal(calls1, 2);
706
+ $mol_assert_equal(calls2, 2);
707
+ },
708
+ 'lazy slice'() {
709
+ let calls = 0;
710
+ const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
711
+ $mol_assert_equal(true, list instanceof Array);
712
+ $mol_assert_equal(list.length, 4);
713
+ $mol_assert_equal(list[0], 3);
714
+ $mol_assert_equal(list[3], 6);
715
+ $mol_assert_equal(list[4], undefined);
716
+ $mol_assert_equal(calls, 2);
717
+ },
718
+ 'lazy some'() {
719
+ let calls = 0;
720
+ $mol_assert_equal(true, $mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
721
+ $mol_assert_equal(calls, 3);
722
+ $mol_assert_equal(false, $mol_range2(i => i, () => 0).some(v => true));
723
+ $mol_assert_equal(true, $mol_range2(i => i).some(v => v > 5));
724
+ },
725
+ 'lazy every'() {
726
+ let calls = 0;
727
+ $mol_assert_equal(false, $mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
728
+ $mol_assert_equal(calls, 3);
729
+ $mol_assert_equal(true, $mol_range2(i => i, () => 0).every(v => false));
730
+ $mol_assert_equal(false, $mol_range2(i => i).every(v => v < 5));
731
+ },
732
+ 'lazyfy'() {
733
+ let calls = 0;
734
+ const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
735
+ $mol_assert_equal(true, list instanceof Array);
736
+ $mol_assert_equal(list.length, 4);
737
+ $mol_assert_equal(calls, 0);
738
+ $mol_assert_equal(list[0], 12);
739
+ $mol_assert_equal(list[3], 15);
740
+ $mol_assert_equal(list[4], undefined);
741
+ $mol_assert_equal(calls, 2);
742
+ },
743
+ 'prevent modification'() {
744
+ const list = $mol_range2(i => i, () => 5);
745
+ $mol_assert_fail(() => list.push(4), TypeError);
746
+ $mol_assert_fail(() => list.pop(), TypeError);
747
+ $mol_assert_fail(() => list.unshift(4), TypeError);
748
+ $mol_assert_fail(() => list.shift(), TypeError);
749
+ $mol_assert_fail(() => list.splice(1, 2), TypeError);
750
+ $mol_assert_fail(() => list[1] = 2, TypeError);
751
+ $mol_assert_fail(() => list.reverse(), TypeError);
752
+ $mol_assert_fail(() => list.sort(), TypeError);
753
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
754
+ }
755
+ });
756
+ })($ || ($ = {}));
757
+
758
+ ;
759
+ "use strict";
760
+ var $;
761
+ (function ($) {
762
+ $.$mol_compare_deep_cache = new WeakMap();
763
+ function $mol_compare_deep(left, right) {
764
+ if (Object.is(left, right))
765
+ return true;
766
+ if (left === null)
767
+ return false;
768
+ if (right === null)
769
+ return false;
770
+ if (typeof left !== 'object')
771
+ return false;
772
+ if (typeof right !== 'object')
773
+ return false;
774
+ const left_proto = Reflect.getPrototypeOf(left);
775
+ const right_proto = Reflect.getPrototypeOf(right);
776
+ if (left_proto !== right_proto)
777
+ return false;
778
+ if (left instanceof Boolean)
779
+ return Object.is(left.valueOf(), right['valueOf']());
780
+ if (left instanceof Number)
781
+ return Object.is(left.valueOf(), right['valueOf']());
782
+ if (left instanceof String)
783
+ return Object.is(left.valueOf(), right['valueOf']());
784
+ if (left instanceof Date)
785
+ return Object.is(left.valueOf(), right['valueOf']());
786
+ if (left instanceof RegExp)
787
+ return left.source === right.source && left.flags === right.flags;
788
+ if (left instanceof Error)
789
+ return left.message === right.message && left.stack === right.stack;
790
+ let left_cache = $.$mol_compare_deep_cache.get(left);
791
+ if (left_cache) {
792
+ const right_cache = left_cache.get(right);
793
+ if (typeof right_cache === 'boolean')
794
+ return right_cache;
795
+ }
796
+ else {
797
+ left_cache = new WeakMap();
798
+ $.$mol_compare_deep_cache.set(left, left_cache);
799
+ }
800
+ left_cache.set(right, true);
801
+ let result;
802
+ try {
803
+ if (!left_proto)
804
+ result = compare_pojo(left, right);
805
+ else if (!Reflect.getPrototypeOf(left_proto))
806
+ result = compare_pojo(left, right);
807
+ else if (Symbol.toPrimitive in left)
808
+ result = compare_primitive(left, right);
809
+ else if (Array.isArray(left))
810
+ result = compare_array(left, right);
811
+ else if (left instanceof Set)
812
+ result = compare_set(left, right);
813
+ else if (left instanceof Map)
814
+ result = compare_map(left, right);
815
+ else if (ArrayBuffer.isView(left))
816
+ result = compare_buffer(left, right);
817
+ else if (Symbol.iterator in left)
818
+ result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
819
+ else
820
+ result = false;
821
+ }
822
+ finally {
823
+ left_cache.set(right, result);
824
+ }
825
+ return result;
826
+ }
827
+ $.$mol_compare_deep = $mol_compare_deep;
828
+ function compare_array(left, right) {
829
+ const len = left.length;
830
+ if (len !== right.length)
831
+ return false;
832
+ for (let i = 0; i < len; ++i) {
833
+ if (!$mol_compare_deep(left[i], right[i]))
834
+ return false;
835
+ }
836
+ return true;
837
+ }
838
+ function compare_buffer(left, right) {
839
+ const len = left.byteLength;
840
+ if (len !== right.byteLength)
841
+ return false;
842
+ if (left instanceof DataView)
843
+ return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, right.byteOffset, right.byteLength));
844
+ for (let i = 0; i < len; ++i) {
845
+ if (left[i] !== right[i])
846
+ return false;
847
+ }
848
+ return true;
849
+ }
850
+ function compare_iterator(left, right) {
851
+ while (true) {
852
+ const left_next = left.next();
853
+ const right_next = right.next();
854
+ if (left_next.done !== right_next.done)
855
+ return false;
856
+ if (left_next.done)
857
+ break;
858
+ if (!$mol_compare_deep(left_next.value, right_next.value))
859
+ return false;
860
+ }
861
+ return true;
862
+ }
863
+ function compare_set(left, right) {
864
+ if (left.size !== right.size)
865
+ return false;
866
+ return compare_iterator(left.values(), right.values());
867
+ }
868
+ function compare_map(left, right) {
869
+ if (left.size !== right.size)
870
+ return false;
871
+ return compare_iterator(left.keys(), right.keys())
872
+ && compare_iterator(left.values(), right.values());
873
+ }
874
+ function compare_pojo(left, right) {
875
+ const left_keys = Object.getOwnPropertyNames(left);
876
+ const right_keys = Object.getOwnPropertyNames(right);
877
+ if (!compare_array(left_keys, right_keys))
878
+ return false;
879
+ for (let key of left_keys) {
880
+ if (!$mol_compare_deep(left[key], right[key]))
881
+ return false;
882
+ }
883
+ const left_syms = Object.getOwnPropertySymbols(left);
884
+ const right_syms = Object.getOwnPropertySymbols(right);
885
+ if (!compare_array(left_syms, right_syms))
886
+ return false;
887
+ for (let key of left_syms) {
888
+ if (!$mol_compare_deep(left[key], right[key]))
889
+ return false;
890
+ }
891
+ return true;
892
+ }
893
+ function compare_primitive(left, right) {
894
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
895
+ }
896
+ })($ || ($ = {}));
897
+
898
+ ;
899
+ "use strict";
900
+ var $;
901
+ (function ($) {
902
+ $mol_test({
903
+ 'nulls & undefineds'() {
904
+ $mol_assert_ok($mol_compare_deep(null, null));
905
+ $mol_assert_ok($mol_compare_deep(undefined, undefined));
906
+ $mol_assert_not($mol_compare_deep(undefined, null));
907
+ $mol_assert_not($mol_compare_deep({}, null));
908
+ },
909
+ 'number'() {
910
+ $mol_assert_ok($mol_compare_deep(1, 1));
911
+ $mol_assert_ok($mol_compare_deep(Number.NaN, Number.NaN));
912
+ $mol_assert_not($mol_compare_deep(1, 2));
913
+ $mol_assert_ok($mol_compare_deep(Object(1), Object(1)));
914
+ $mol_assert_not($mol_compare_deep(Object(1), Object(2)));
915
+ },
916
+ 'POJO'() {
917
+ $mol_assert_ok($mol_compare_deep({}, {}));
918
+ $mol_assert_not($mol_compare_deep({ a: 1 }, { b: 2 }));
919
+ $mol_assert_not($mol_compare_deep({ a: 1 }, { a: 2 }));
920
+ $mol_assert_not($mol_compare_deep({}, { a: undefined }));
921
+ $mol_assert_not($mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
922
+ $mol_assert_ok($mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
923
+ $mol_assert_ok($mol_compare_deep(Object.create(null), Object.create(null)));
924
+ },
925
+ 'Array'() {
926
+ $mol_assert_ok($mol_compare_deep([], []));
927
+ $mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
928
+ $mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
929
+ $mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
930
+ $mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
931
+ $mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
932
+ },
933
+ 'Non POJO are different'() {
934
+ class Thing extends Object {
935
+ }
936
+ $mol_assert_not($mol_compare_deep(new Thing, new Thing));
937
+ $mol_assert_not($mol_compare_deep(() => 1, () => 1));
938
+ $mol_assert_not($mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
939
+ },
940
+ 'POJO with symbols'() {
941
+ const sym = Symbol();
942
+ $mol_assert_ok($mol_compare_deep({ [sym]: true }, { [sym]: true }));
943
+ $mol_assert_not($mol_compare_deep({ [Symbol()]: true }, { [Symbol()]: true }));
944
+ },
945
+ 'same POJOs with cyclic reference'() {
946
+ const a = { foo: {} };
947
+ a['self'] = a;
948
+ const b = { foo: {} };
949
+ b['self'] = b;
950
+ $mol_assert_ok($mol_compare_deep(a, b));
951
+ },
952
+ 'same POJOs with cyclic reference with cache warmup'() {
953
+ const obj1 = { test: 1, obj3: null };
954
+ const obj1_copy = { test: 1, obj3: null };
955
+ const obj2 = { test: 2, obj1 };
956
+ const obj2_copy = { test: 2, obj1: obj1_copy };
957
+ const obj3 = { test: 3, obj2 };
958
+ const obj3_copy = { test: 3, obj2: obj2_copy };
959
+ obj1.obj3 = obj3;
960
+ obj1_copy.obj3 = obj3_copy;
961
+ $mol_assert_not($mol_compare_deep(obj1, {}));
962
+ $mol_assert_not($mol_compare_deep(obj2, {}));
963
+ $mol_assert_not($mol_compare_deep(obj3, {}));
964
+ $mol_assert_ok($mol_compare_deep(obj3, obj3_copy));
965
+ },
966
+ 'Date'() {
967
+ $mol_assert_ok($mol_compare_deep(new Date(12345), new Date(12345)));
968
+ $mol_assert_not($mol_compare_deep(new Date(12345), new Date(12346)));
969
+ },
970
+ 'RegExp'() {
971
+ $mol_assert_ok($mol_compare_deep(/\x22/mig, /\x22/mig));
972
+ $mol_assert_not($mol_compare_deep(/\x22/mig, /\x21/mig));
973
+ $mol_assert_not($mol_compare_deep(/\x22/mig, /\x22/mg));
974
+ },
975
+ 'Error'() {
976
+ $mol_assert_not($mol_compare_deep(new Error('xxx'), new Error('xxx')));
977
+ const fail = (message) => new Error(message);
978
+ $mol_assert_ok($mol_compare_deep(...['xxx', 'xxx'].map(msg => new Error(msg))));
979
+ $mol_assert_not($mol_compare_deep(...['xxx', 'yyy'].map(msg => new Error(msg))));
980
+ },
981
+ 'Map'() {
982
+ $mol_assert_ok($mol_compare_deep(new Map, new Map));
983
+ $mol_assert_ok($mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
984
+ $mol_assert_ok($mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
985
+ $mol_assert_not($mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
986
+ $mol_assert_not($mol_compare_deep(new Map([[[1], 2]]), new Map([[[3], 2]])));
987
+ },
988
+ 'Set'() {
989
+ $mol_assert_ok($mol_compare_deep(new Set, new Set));
990
+ $mol_assert_ok($mol_compare_deep(new Set([1, [2]]), new Set([1, [2]])));
991
+ $mol_assert_not($mol_compare_deep(new Set([1]), new Set([2])));
992
+ },
993
+ 'Uint8Array'() {
994
+ $mol_assert_ok($mol_compare_deep(new Uint8Array, new Uint8Array));
995
+ $mol_assert_ok($mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
996
+ $mol_assert_not($mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
997
+ },
998
+ 'DataView'() {
999
+ $mol_assert_ok($mol_compare_deep(new DataView(new Uint8Array().buffer), new DataView(new Uint8Array().buffer)));
1000
+ $mol_assert_ok($mol_compare_deep(new DataView(new Uint8Array([0]).buffer), new DataView(new Uint8Array([0]).buffer)));
1001
+ $mol_assert_not($mol_compare_deep(new DataView(new Uint8Array([0]).buffer), new DataView(new Uint8Array([1]).buffer)));
1002
+ },
1003
+ 'Serializale'() {
1004
+ class User {
1005
+ name;
1006
+ rand;
1007
+ constructor(name, rand = Math.random()) {
1008
+ this.name = name;
1009
+ this.rand = rand;
1010
+ }
1011
+ [Symbol.toPrimitive](mode) {
1012
+ return this.name;
1013
+ }
1014
+ }
1015
+ $mol_assert_ok($mol_compare_deep(new User('Jin'), new User('Jin')));
1016
+ $mol_assert_not($mol_compare_deep(new User('Jin'), new User('John')));
1017
+ },
1018
+ 'Iterable'() {
1019
+ $mol_assert_ok($mol_compare_deep(new URLSearchParams({ foo: 'bar' }), new URLSearchParams({ foo: 'bar' })));
1020
+ $mol_assert_not($mol_compare_deep(new URLSearchParams({ foo: 'xxx' }), new URLSearchParams({ foo: 'yyy' })));
1021
+ $mol_assert_not($mol_compare_deep(new URLSearchParams({ foo: 'xxx', bar: 'yyy' }), new URLSearchParams({ bar: 'yyy', foo: 'xxx' })));
1022
+ },
1023
+ });
1024
+ })($ || ($ = {}));
1025
+
1026
+ ;
1027
+ "use strict";
1028
+ var $;
1029
+ (function ($) {
1030
+ function $mol_assert_ok(value) {
1031
+ if (value)
1032
+ return;
1033
+ $mol_fail(new Error(`${value} ≠ true`));
1034
+ }
1035
+ $.$mol_assert_ok = $mol_assert_ok;
1036
+ function $mol_assert_not(value) {
1037
+ if (!value)
1038
+ return;
1039
+ $mol_fail(new Error(`${value} ≠ false`));
1040
+ }
1041
+ $.$mol_assert_not = $mol_assert_not;
1042
+ function $mol_assert_fail(handler, ErrorRight) {
1043
+ const fail = $.$mol_fail;
1044
+ try {
1045
+ $.$mol_fail = $.$mol_fail_hidden;
1046
+ handler();
1047
+ }
1048
+ catch (error) {
1049
+ $.$mol_fail = fail;
1050
+ if (typeof ErrorRight === 'string') {
1051
+ $mol_assert_equal(error.message, ErrorRight);
1052
+ }
1053
+ else {
1054
+ $mol_assert_equal(error instanceof ErrorRight, true);
1055
+ }
1056
+ return error;
1057
+ }
1058
+ finally {
1059
+ $.$mol_fail = fail;
1060
+ }
1061
+ $mol_fail(new Error('Not failed'));
1062
+ }
1063
+ $.$mol_assert_fail = $mol_assert_fail;
1064
+ function $mol_assert_like(...args) {
1065
+ $mol_assert_equal(...args);
1066
+ }
1067
+ $.$mol_assert_like = $mol_assert_like;
1068
+ function $mol_assert_unique(...args) {
1069
+ for (let i = 0; i < args.length; ++i) {
1070
+ for (let j = 0; j < args.length; ++j) {
1071
+ if (i === j)
1072
+ continue;
1073
+ if (!$mol_compare_deep(args[i], args[j]))
1074
+ continue;
1075
+ $mol_fail(new Error(`args[${i}] = args[${j}] = ${print(args[i])}`));
1076
+ }
1077
+ }
1078
+ }
1079
+ $.$mol_assert_unique = $mol_assert_unique;
1080
+ function $mol_assert_equal(...args) {
1081
+ for (let i = 1; i < args.length; ++i) {
1082
+ if ($mol_compare_deep(args[0], args[i]))
1083
+ continue;
1084
+ if (args[0] instanceof $mol_dom_context.Element && args[i] instanceof $mol_dom_context.Element && args[0].outerHTML === args[i].outerHTML)
1085
+ continue;
1086
+ return $mol_fail(new Error(`args[0] ≠ args[${i}]\n${print(args[0])}\n---\n${print(args[i])}`));
1087
+ }
1088
+ }
1089
+ $.$mol_assert_equal = $mol_assert_equal;
1090
+ const print = (val) => {
1091
+ if (!val)
1092
+ return val;
1093
+ if (typeof val === 'bigint')
1094
+ return String(val) + 'n';
1095
+ if (typeof val === 'symbol')
1096
+ return `Symbol(${val.description})`;
1097
+ if (typeof val !== 'object')
1098
+ return val;
1099
+ if ('outerHTML' in val)
1100
+ return val.outerHTML;
1101
+ try {
1102
+ return JSON.stringify(val, (k, v) => typeof v === 'bigint' ? String(v) : v, '\t');
1103
+ }
1104
+ catch (error) {
1105
+ console.error(error);
1106
+ return val;
1107
+ }
1108
+ };
1109
+ })($ || ($ = {}));
1110
+
1111
+ ;
1112
+ "use strict";
1113
+ var $;
1114
+ (function ($) {
1115
+ $mol_test({
1116
+ 'must be false'() {
1117
+ $mol_assert_not(0);
1118
+ },
1119
+ 'must be true'() {
1120
+ $mol_assert_ok(1);
1121
+ },
1122
+ 'two must be equal'() {
1123
+ $mol_assert_equal(2, 2);
1124
+ },
1125
+ 'three must be equal'() {
1126
+ $mol_assert_equal(2, 2, 2);
1127
+ },
1128
+ 'two must be unique'() {
1129
+ $mol_assert_unique([2], [3]);
1130
+ },
1131
+ 'three must be unique'() {
1132
+ $mol_assert_unique([1], [2], [3]);
1133
+ },
1134
+ 'two must be alike'() {
1135
+ $mol_assert_like([3], [3]);
1136
+ },
1137
+ 'three must be alike'() {
1138
+ $mol_assert_like([3], [3], [3]);
1139
+ },
1140
+ 'two object must be alike'() {
1141
+ $mol_assert_like({ a: 1 }, { a: 1 });
1142
+ },
1143
+ 'three object must be alike'() {
1144
+ $mol_assert_like({ a: 1 }, { a: 1 }, { a: 1 });
1145
+ },
1146
+ });
1147
+ })($ || ($ = {}));
1148
+
1149
+ ;
1150
+ "use strict";
1151
+ var $;
1152
+ (function ($) {
1153
+ function $mol_log3_area_lazy(event) {
1154
+ const self = this;
1155
+ const stack = self.$mol_log3_stack;
1156
+ const deep = stack.length;
1157
+ let logged = false;
1158
+ stack.push(() => {
1159
+ logged = true;
1160
+ self.$mol_log3_area.call(self, event);
1161
+ });
1162
+ return () => {
1163
+ if (logged)
1164
+ self.console.groupEnd();
1165
+ if (stack.length > deep)
1166
+ stack.length = deep;
1167
+ };
1168
+ }
1169
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1170
+ $.$mol_log3_stack = [];
1171
+ })($ || ($ = {}));
1172
+
1173
+ ;
1174
+ "use strict";
1175
+
1176
+ ;
1177
+ "use strict";
1178
+
1179
+ ;
1180
+ "use strict";
1181
+
1182
+ ;
1183
+ "use strict";
1184
+
1185
+ ;
1186
+ "use strict";
1187
+ var $;
1188
+ (function ($) {
1189
+ function $mol_log3_web_make(level, color) {
1190
+ return function $mol_log3_logger(event) {
1191
+ const pending = this.$mol_log3_stack.pop();
1192
+ if (pending)
1193
+ pending();
1194
+ let tpl = '%c';
1195
+ const chunks = Object.entries(event);
1196
+ for (let i = 0; i < chunks.length; ++i) {
1197
+ tpl += (typeof chunks[i][1] === 'string') ? '%s: %s\n' : '%s: %o\n';
1198
+ }
1199
+ const style = `color:${color};font-weight:bolder`;
1200
+ this.console[level](tpl.trim(), style, ...[].concat(...chunks));
1201
+ const self = this;
1202
+ return () => self.console.groupEnd();
1203
+ };
1204
+ }
1205
+ $.$mol_log3_web_make = $mol_log3_web_make;
1206
+ $.$mol_log3_come = $mol_log3_web_make('info', 'royalblue');
1207
+ $.$mol_log3_done = $mol_log3_web_make('info', 'forestgreen');
1208
+ $.$mol_log3_fail = $mol_log3_web_make('error', 'orangered');
1209
+ $.$mol_log3_warn = $mol_log3_web_make('warn', 'goldenrod');
1210
+ $.$mol_log3_rise = $mol_log3_web_make('log', 'magenta');
1211
+ $.$mol_log3_area = $mol_log3_web_make('group', 'cyan');
1212
+ })($ || ($ = {}));
1213
+
1214
+ ;
1215
+ "use strict";
1216
+ var $;
1217
+ (function ($_1) {
1218
+ $mol_test_mocks.push($ => {
1219
+ $.$mol_log3_come = () => { };
1220
+ $.$mol_log3_done = () => { };
1221
+ $.$mol_log3_fail = () => { };
1222
+ $.$mol_log3_warn = () => { };
1223
+ $.$mol_log3_rise = () => { };
1224
+ $.$mol_log3_area = () => () => { };
1225
+ });
1226
+ })($ || ($ = {}));
1227
+
1228
+ ;
1229
+ "use strict";
1230
+ var $;
1231
+ (function ($) {
1232
+ const named = new WeakSet();
1233
+ function $mol_func_name(func) {
1234
+ let name = func.name;
1235
+ if (name?.length > 1)
1236
+ return name;
1237
+ if (named.has(func))
1238
+ return name;
1239
+ for (let key in this) {
1240
+ try {
1241
+ if (this[key] !== func)
1242
+ continue;
1243
+ name = key;
1244
+ Object.defineProperty(func, 'name', { value: name });
1245
+ break;
1246
+ }
1247
+ catch { }
1248
+ }
1249
+ named.add(func);
1250
+ return name;
1251
+ }
1252
+ $.$mol_func_name = $mol_func_name;
1253
+ function $mol_func_name_from(target, source) {
1254
+ Object.defineProperty(target, 'name', { value: source.name });
1255
+ return target;
1256
+ }
1257
+ $.$mol_func_name_from = $mol_func_name_from;
1258
+ })($ || ($ = {}));
1259
+
1260
+ ;
1261
+ "use strict";
1262
+ var $;
1263
+ (function ($_1) {
1264
+ $mol_test({
1265
+ 'FQN of anon function'($) {
1266
+ const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
1267
+ $mol_assert_equal($$.$mol_func_name_test.name, '');
1268
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
1269
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
1270
+ },
1271
+ });
1272
+ })($ || ($ = {}));
1273
+
1274
+ ;
1275
+ "use strict";
1276
+ var $;
1277
+ (function ($) {
1278
+ $mol_test({
1279
+ 'return source when same object'() {
1280
+ const target = {};
1281
+ $mol_assert_equal($mol_conform(target, target), target);
1282
+ },
1283
+ 'return target when some is not object'() {
1284
+ const obj = { a: 1 };
1285
+ $mol_assert_equal($mol_conform(true, obj), true);
1286
+ $mol_assert_equal($mol_conform(obj, true), obj);
1287
+ },
1288
+ 'return target when some is null'() {
1289
+ const obj = { a: 1 };
1290
+ $mol_assert_equal($mol_conform(null, obj), null);
1291
+ $mol_assert_equal($mol_conform(obj, null), obj);
1292
+ },
1293
+ 'return target when some is undefined'() {
1294
+ const obj = { a: 1 };
1295
+ $mol_assert_equal($mol_conform(undefined, obj), undefined);
1296
+ $mol_assert_equal($mol_conform(obj, undefined), obj);
1297
+ },
1298
+ 'return target when different keys count'() {
1299
+ const target = [1, 2, 3];
1300
+ const source = [1, 2, 3, undefined];
1301
+ const result = $mol_conform(target, source);
1302
+ $mol_assert_equal(result, target);
1303
+ $mol_assert_equal(result.join(','), '1,2,3');
1304
+ },
1305
+ 'return source when array values are strong equal'() {
1306
+ const source = [1, 2, 3];
1307
+ $mol_assert_equal($mol_conform([1, 2, 3], source), source);
1308
+ },
1309
+ 'return source when object values are strong equal'() {
1310
+ const source = { a: 1, b: 2 };
1311
+ $mol_assert_equal($mol_conform({ a: 1, b: 2 }, source), source);
1312
+ },
1313
+ 'return target when some values are not equal'() {
1314
+ const target = [1, 2, 3];
1315
+ const source = [1, 2, 5];
1316
+ const result = $mol_conform(target, source);
1317
+ $mol_assert_equal(result, target);
1318
+ $mol_assert_equal(result.join(','), '1,2,3');
1319
+ },
1320
+ 'return source when values are deep equal'() {
1321
+ const source = { foo: { bar: 1 } };
1322
+ $mol_assert_equal($mol_conform({ foo: { bar: 1 } }, source), source);
1323
+ },
1324
+ 'return target with equal values from source and not equal from target'() {
1325
+ const source = { foo: { xxx: 1 }, bar: { xxx: 2 } };
1326
+ const target = { foo: { xxx: 1 }, bar: { xxx: 3 } };
1327
+ const result = $mol_conform(target, source);
1328
+ $mol_assert_equal(result, target);
1329
+ $mol_assert_equal(result.foo, source.foo);
1330
+ $mol_assert_equal(result.bar, target.bar);
1331
+ },
1332
+ 'return target when equal but with different class'() {
1333
+ const target = { '0': 1 };
1334
+ $mol_assert_equal($mol_conform(target, [1]), target);
1335
+ },
1336
+ 'return target when conformer for class is not defined'() {
1337
+ const Obj = class {
1338
+ };
1339
+ const source = new Obj;
1340
+ const target = new Obj;
1341
+ const result = $mol_conform(target, source);
1342
+ $mol_assert_equal(result, target);
1343
+ },
1344
+ 'return target when has cyclic reference'() {
1345
+ const source = { foo: {} };
1346
+ source['self'] = source;
1347
+ const target = { foo: {} };
1348
+ target['self'] = target;
1349
+ const result = $mol_conform(target, source);
1350
+ $mol_assert_equal(result, target);
1351
+ $mol_assert_equal(result['self'], target);
1352
+ $mol_assert_equal(result.foo, source.foo);
1353
+ },
1354
+ 'return source when equal dates'() {
1355
+ const source = new Date(12345);
1356
+ const target = new Date(12345);
1357
+ const result = $mol_conform(target, source);
1358
+ $mol_assert_equal(result, source);
1359
+ },
1360
+ 'return source when equal regular expressions'() {
1361
+ const source = /\x22/mig;
1362
+ const target = /\x22/mig;
1363
+ const result = $mol_conform(target, source);
1364
+ $mol_assert_equal(result, source);
1365
+ },
1366
+ 'return cached value if already conformed'() {
1367
+ const source = { foo: { xxx: 1 }, bar: { xxx: 3 } };
1368
+ const target = { foo: { xxx: 2 }, bar: { xxx: 3 } };
1369
+ const result = $mol_conform(target, source);
1370
+ target.foo.xxx = 1;
1371
+ $mol_assert_equal($mol_conform(target.foo, source.foo), target.foo);
1372
+ },
1373
+ 'skip readlony fields'() {
1374
+ const source = { foo: {}, bar: {} };
1375
+ const target = { foo: {}, bar: {} };
1376
+ Object.defineProperty(target, 'bar', { value: {}, writable: false });
1377
+ const result = $mol_conform(target, source);
1378
+ $mol_assert_equal(result, target);
1379
+ $mol_assert_equal(result.foo, source.foo);
1380
+ $mol_assert_equal(result.bar, target.bar);
1381
+ },
1382
+ 'object with NaN'() {
1383
+ const source = { foo: Number.NaN };
1384
+ const target = { foo: Number.NaN };
1385
+ const result = $mol_conform(target, source);
1386
+ $mol_assert_equal(result, source);
1387
+ },
1388
+ 'array with NaN'() {
1389
+ const source = [Number.NaN];
1390
+ const target = [Number.NaN];
1391
+ const result = $mol_conform(target, source);
1392
+ $mol_assert_equal(result, source);
1393
+ },
1394
+ });
1395
+ })($ || ($ = {}));
1396
+
1397
+
1398
+ //# sourceMappingURL=web.test.js.map