mol_mutable 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,925 @@
1
+ "use strict";
2
+ function require( path ){ return $node[ path ] };
3
+ "use strict";
4
+ var $;
5
+ (function ($) {
6
+ function $mol_fail(error) {
7
+ throw error;
8
+ }
9
+ $.$mol_fail = $mol_fail;
10
+ })($ || ($ = {}));
11
+ //mol/fail/fail.ts
12
+ ;
13
+ "use strict";
14
+ var $;
15
+ (function ($) {
16
+ function $mol_fail_hidden(error) {
17
+ throw error;
18
+ }
19
+ $.$mol_fail_hidden = $mol_fail_hidden;
20
+ })($ || ($ = {}));
21
+ //mol/fail/hidden/hidden.ts
22
+ ;
23
+ "use strict";
24
+ var $;
25
+ (function ($_1) {
26
+ function $mol_test(set) {
27
+ for (let name in set) {
28
+ const code = set[name];
29
+ const test = (typeof code === 'string') ? new Function('', code) : code;
30
+ $_1.$mol_test_all.push(test);
31
+ }
32
+ $mol_test_schedule();
33
+ }
34
+ $_1.$mol_test = $mol_test;
35
+ $_1.$mol_test_mocks = [];
36
+ $_1.$mol_test_all = [];
37
+ async function $mol_test_run() {
38
+ for (var test of $_1.$mol_test_all) {
39
+ let context = Object.create($$);
40
+ for (let mock of $_1.$mol_test_mocks)
41
+ await mock(context);
42
+ const res = test(context);
43
+ if (res instanceof Promise) {
44
+ await new Promise((done, fail) => {
45
+ res.then(done, fail);
46
+ setTimeout(() => fail(new Error('Test timeout: ' + test.name)), 1000);
47
+ });
48
+ }
49
+ }
50
+ $$.$mol_log3_done({
51
+ place: '$mol_test',
52
+ message: 'All tests passed',
53
+ count: $_1.$mol_test_all.length,
54
+ });
55
+ }
56
+ $_1.$mol_test_run = $mol_test_run;
57
+ let scheduled = false;
58
+ function $mol_test_schedule() {
59
+ if (scheduled)
60
+ return;
61
+ scheduled = true;
62
+ setTimeout(async () => {
63
+ scheduled = false;
64
+ await $mol_test_run();
65
+ $$.$mol_test_complete();
66
+ }, 1000);
67
+ }
68
+ $_1.$mol_test_schedule = $mol_test_schedule;
69
+ $_1.$mol_test_mocks.push(context => {
70
+ let seed = 0;
71
+ context.Math = Object.create(Math);
72
+ context.Math.random = () => Math.sin(seed++);
73
+ const forbidden = ['XMLHttpRequest', 'fetch'];
74
+ for (let api of forbidden) {
75
+ context[api] = new Proxy(function () { }, {
76
+ get() {
77
+ $mol_fail_hidden(new Error(`${api} is forbidden in tests`));
78
+ },
79
+ apply() {
80
+ $mol_fail_hidden(new Error(`${api} is forbidden in tests`));
81
+ },
82
+ });
83
+ }
84
+ });
85
+ $mol_test({
86
+ 'mocked Math.random'($) {
87
+ console.assert($.Math.random() === 0);
88
+ console.assert($.Math.random() === Math.sin(1));
89
+ },
90
+ 'forbidden XMLHttpRequest'($) {
91
+ try {
92
+ console.assert(void new $.XMLHttpRequest);
93
+ }
94
+ catch (error) {
95
+ console.assert(error.message === 'XMLHttpRequest is forbidden in tests');
96
+ }
97
+ },
98
+ 'forbidden fetch'($) {
99
+ try {
100
+ console.assert(void $.fetch(''));
101
+ }
102
+ catch (error) {
103
+ console.assert(error.message === 'fetch is forbidden in tests');
104
+ }
105
+ },
106
+ });
107
+ })($ || ($ = {}));
108
+ //mol/test/test.test.ts
109
+ ;
110
+ "use strict";
111
+ var $;
112
+ (function ($) {
113
+ function $mol_test_complete() {
114
+ }
115
+ $.$mol_test_complete = $mol_test_complete;
116
+ })($ || ($ = {}));
117
+ //mol/test/test.web.test.ts
118
+ ;
119
+ "use strict";
120
+ var $;
121
+ (function ($) {
122
+ })($ || ($ = {}));
123
+ //mol/dom/context/context.ts
124
+ ;
125
+ "use strict";
126
+ var $;
127
+ (function ($) {
128
+ $.$mol_dom_context = self;
129
+ })($ || ($ = {}));
130
+ //mol/dom/context/context.web.ts
131
+ ;
132
+ "use strict";
133
+ var $;
134
+ (function ($) {
135
+ function $mol_dom_render_children(el, childNodes) {
136
+ const node_set = new Set(childNodes);
137
+ let nextNode = el.firstChild;
138
+ for (let view of childNodes) {
139
+ if (view == null)
140
+ continue;
141
+ if (view instanceof $mol_dom_context.Node) {
142
+ while (true) {
143
+ if (!nextNode) {
144
+ el.appendChild(view);
145
+ break;
146
+ }
147
+ if (nextNode == view) {
148
+ nextNode = nextNode.nextSibling;
149
+ break;
150
+ }
151
+ else {
152
+ if (node_set.has(nextNode)) {
153
+ el.insertBefore(view, nextNode);
154
+ break;
155
+ }
156
+ else {
157
+ const nn = nextNode.nextSibling;
158
+ el.removeChild(nextNode);
159
+ nextNode = nn;
160
+ }
161
+ }
162
+ }
163
+ }
164
+ else {
165
+ if (nextNode && nextNode.nodeName === '#text') {
166
+ const str = String(view);
167
+ if (nextNode.nodeValue !== str)
168
+ nextNode.nodeValue = str;
169
+ nextNode = nextNode.nextSibling;
170
+ }
171
+ else {
172
+ const textNode = $mol_dom_context.document.createTextNode(String(view));
173
+ el.insertBefore(textNode, nextNode);
174
+ }
175
+ }
176
+ }
177
+ while (nextNode) {
178
+ const currNode = nextNode;
179
+ nextNode = currNode.nextSibling;
180
+ el.removeChild(currNode);
181
+ }
182
+ }
183
+ $.$mol_dom_render_children = $mol_dom_render_children;
184
+ })($ || ($ = {}));
185
+ //mol/dom/render/children/children.ts
186
+ ;
187
+ "use strict";
188
+ //mol/type/error/error.ts
189
+ ;
190
+ "use strict";
191
+ //mol/type/assert/assert.test.ts
192
+ ;
193
+ "use strict";
194
+ //mol/type/assert/assert.ts
195
+ ;
196
+ "use strict";
197
+ //mol/type/equals/equals.test.ts
198
+ ;
199
+ "use strict";
200
+ //mol/type/equals/equals.ts
201
+ ;
202
+ "use strict";
203
+ //mol/type/partial/deep/deep.test.ts
204
+ ;
205
+ "use strict";
206
+ //mol/type/partial/deep/deep.ts
207
+ ;
208
+ "use strict";
209
+ var $;
210
+ (function ($) {
211
+ $mol_test({
212
+ 'Make empty div'() {
213
+ $mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
214
+ },
215
+ 'Define native field'() {
216
+ const dom = $mol_jsx("input", { value: '123' });
217
+ $mol_assert_equal(dom.outerHTML, '<input value="123">');
218
+ $mol_assert_equal(dom.value, '123');
219
+ },
220
+ 'Define classes'() {
221
+ const dom = $mol_jsx("div", { class: 'foo bar' });
222
+ $mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
223
+ },
224
+ 'Define styles'() {
225
+ const dom = $mol_jsx("div", { style: { color: 'red' } });
226
+ $mol_assert_equal(dom.outerHTML, '<div style="color: red;"></div>');
227
+ },
228
+ 'Define dataset'() {
229
+ const dom = $mol_jsx("div", { dataset: { foo: 'bar' } });
230
+ $mol_assert_equal(dom.outerHTML, '<div data-foo="bar"></div>');
231
+ },
232
+ 'Define attributes'() {
233
+ const dom = $mol_jsx("div", { lang: "ru", hidden: true });
234
+ $mol_assert_equal(dom.outerHTML, '<div lang="ru" hidden=""></div>');
235
+ },
236
+ 'Define child nodes'() {
237
+ const dom = $mol_jsx("div", null,
238
+ "hello",
239
+ $mol_jsx("strong", null, "world"),
240
+ "!");
241
+ $mol_assert_equal(dom.outerHTML, '<div>hello<strong>world</strong>!</div>');
242
+ },
243
+ 'Function as component'() {
244
+ const Button = (props, target) => {
245
+ return $mol_jsx("button", { title: props.hint }, target());
246
+ };
247
+ const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
248
+ $mol_assert_equal(dom.outerHTML, '<button id="foo" title="click me" class="Button">hey!</button>');
249
+ },
250
+ 'Nested guid generation'() {
251
+ const Foo = () => {
252
+ return $mol_jsx("div", null,
253
+ $mol_jsx(Bar, { id: "bar" },
254
+ $mol_jsx("img", { id: "icon" })));
255
+ };
256
+ const Bar = (props, icon) => {
257
+ return $mol_jsx("span", null,
258
+ icon,
259
+ $mol_jsx("i", { id: "label" }));
260
+ };
261
+ const dom = $mol_jsx(Foo, { id: "foo" });
262
+ $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>');
263
+ },
264
+ 'Fail on non unique ids'() {
265
+ const App = () => {
266
+ return $mol_jsx("div", null,
267
+ $mol_jsx("span", { id: "bar" }),
268
+ $mol_jsx("span", { id: "bar" }));
269
+ };
270
+ $mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
271
+ },
272
+ 'Owner based guid generationn'() {
273
+ const Foo = () => {
274
+ return $mol_jsx("div", null,
275
+ $mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
276
+ };
277
+ const Bar = (props) => {
278
+ return $mol_jsx("span", null, props.icon());
279
+ };
280
+ const dom = $mol_jsx(Foo, { id: "app" });
281
+ $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>');
282
+ },
283
+ 'Fail on same ids from different caller'() {
284
+ const Foo = () => {
285
+ return $mol_jsx("div", null,
286
+ $mol_jsx("img", { id: "icon" }),
287
+ $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
288
+ };
289
+ const Bar = (props) => {
290
+ return $mol_jsx("span", null, props.icon());
291
+ };
292
+ $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
293
+ },
294
+ });
295
+ })($ || ($ = {}));
296
+ //mol/jsx/jsx.test.tsx
297
+ ;
298
+ "use strict";
299
+ var $;
300
+ (function ($) {
301
+ $.$mol_jsx_prefix = '';
302
+ $.$mol_jsx_crumbs = '';
303
+ $.$mol_jsx_booked = null;
304
+ $.$mol_jsx_document = {
305
+ getElementById: () => null,
306
+ createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
307
+ createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
308
+ };
309
+ $.$mol_jsx_frag = '';
310
+ function $mol_jsx(Elem, props, ...childNodes) {
311
+ const id = props && props.id || '';
312
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
313
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
314
+ if (Elem && $.$mol_jsx_booked) {
315
+ if ($.$mol_jsx_booked.has(id)) {
316
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
317
+ }
318
+ else {
319
+ $.$mol_jsx_booked.add(id);
320
+ }
321
+ }
322
+ let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
323
+ if ($.$mol_jsx_prefix) {
324
+ const prefix_ext = $.$mol_jsx_prefix;
325
+ const booked_ext = $.$mol_jsx_booked;
326
+ const crumbs_ext = $.$mol_jsx_crumbs;
327
+ for (const field in props) {
328
+ const func = props[field];
329
+ if (typeof func !== 'function')
330
+ continue;
331
+ const wrapper = function (...args) {
332
+ const prefix = $.$mol_jsx_prefix;
333
+ const booked = $.$mol_jsx_booked;
334
+ const crumbs = $.$mol_jsx_crumbs;
335
+ try {
336
+ $.$mol_jsx_prefix = prefix_ext;
337
+ $.$mol_jsx_booked = booked_ext;
338
+ $.$mol_jsx_crumbs = crumbs_ext;
339
+ return func.call(this, ...args);
340
+ }
341
+ finally {
342
+ $.$mol_jsx_prefix = prefix;
343
+ $.$mol_jsx_booked = booked;
344
+ $.$mol_jsx_crumbs = crumbs;
345
+ }
346
+ };
347
+ $mol_func_name_from(wrapper, func);
348
+ props[field] = wrapper;
349
+ }
350
+ }
351
+ if (typeof Elem !== 'string') {
352
+ if ('prototype' in Elem) {
353
+ const view = node && node[Elem] || new Elem;
354
+ Object.assign(view, props);
355
+ view[Symbol.toStringTag] = guid;
356
+ view.childNodes = childNodes;
357
+ if (!view.ownerDocument)
358
+ view.ownerDocument = $.$mol_jsx_document;
359
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
360
+ node = view.valueOf();
361
+ node[Elem] = view;
362
+ return node;
363
+ }
364
+ else {
365
+ const prefix = $.$mol_jsx_prefix;
366
+ const booked = $.$mol_jsx_booked;
367
+ const crumbs = $.$mol_jsx_crumbs;
368
+ try {
369
+ $.$mol_jsx_prefix = guid;
370
+ $.$mol_jsx_booked = new Set;
371
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
372
+ return Elem(props, ...childNodes);
373
+ }
374
+ finally {
375
+ $.$mol_jsx_prefix = prefix;
376
+ $.$mol_jsx_booked = booked;
377
+ $.$mol_jsx_crumbs = crumbs;
378
+ }
379
+ }
380
+ }
381
+ if (!node) {
382
+ node = Elem
383
+ ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
384
+ : $.$mol_jsx_document.createDocumentFragment();
385
+ }
386
+ $mol_dom_render_children(node, [].concat(...childNodes));
387
+ if (!Elem)
388
+ return node;
389
+ if (guid)
390
+ node.id = guid;
391
+ for (const key in props) {
392
+ if (key === 'id')
393
+ continue;
394
+ if (typeof props[key] === 'string') {
395
+ if (typeof node[key] === 'string')
396
+ node[key] = props[key];
397
+ node.setAttribute(key, props[key]);
398
+ }
399
+ else if (props[key] &&
400
+ typeof props[key] === 'object' &&
401
+ Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
402
+ if (typeof node[key] === 'object') {
403
+ Object.assign(node[key], props[key]);
404
+ continue;
405
+ }
406
+ }
407
+ else {
408
+ node[key] = props[key];
409
+ }
410
+ }
411
+ if ($.$mol_jsx_crumbs)
412
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
413
+ return node;
414
+ }
415
+ $.$mol_jsx = $mol_jsx;
416
+ })($ || ($ = {}));
417
+ //mol/jsx/jsx.ts
418
+ ;
419
+ "use strict";
420
+ var $;
421
+ (function ($) {
422
+ $mol_test({
423
+ 'nulls & undefineds'() {
424
+ $mol_assert_ok($mol_compare_deep(null, null));
425
+ $mol_assert_ok($mol_compare_deep(undefined, undefined));
426
+ $mol_assert_not($mol_compare_deep(undefined, null));
427
+ $mol_assert_not($mol_compare_deep({}, null));
428
+ },
429
+ 'number'() {
430
+ $mol_assert_ok($mol_compare_deep(1, 1));
431
+ $mol_assert_ok($mol_compare_deep(Number.NaN, Number.NaN));
432
+ $mol_assert_not($mol_compare_deep(1, 2));
433
+ $mol_assert_ok($mol_compare_deep(Object(1), Object(1)));
434
+ $mol_assert_not($mol_compare_deep(Object(1), Object(2)));
435
+ },
436
+ 'POJO'() {
437
+ $mol_assert_ok($mol_compare_deep({}, {}));
438
+ $mol_assert_not($mol_compare_deep({ a: 1 }, { b: 2 }));
439
+ $mol_assert_not($mol_compare_deep({ a: 1 }, { a: 2 }));
440
+ $mol_assert_not($mol_compare_deep({}, { a: undefined }));
441
+ $mol_assert_ok($mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
442
+ $mol_assert_ok($mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
443
+ },
444
+ 'Array'() {
445
+ $mol_assert_ok($mol_compare_deep([], []));
446
+ $mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
447
+ $mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
448
+ $mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
449
+ },
450
+ 'Non POJO are different'() {
451
+ class Thing extends Object {
452
+ }
453
+ $mol_assert_not($mol_compare_deep(new Thing, new Thing));
454
+ $mol_assert_not($mol_compare_deep(() => 1, () => 1));
455
+ $mol_assert_not($mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
456
+ },
457
+ 'same POJOs with cyclic reference'() {
458
+ const a = { foo: {} };
459
+ a['self'] = a;
460
+ const b = { foo: {} };
461
+ b['self'] = b;
462
+ $mol_assert_ok($mol_compare_deep(a, b));
463
+ },
464
+ 'Date'() {
465
+ $mol_assert_ok($mol_compare_deep(new Date(12345), new Date(12345)));
466
+ $mol_assert_not($mol_compare_deep(new Date(12345), new Date(12346)));
467
+ },
468
+ 'RegExp'() {
469
+ $mol_assert_ok($mol_compare_deep(/\x22/mig, /\x22/mig));
470
+ $mol_assert_not($mol_compare_deep(/\x22/mig, /\x21/mig));
471
+ $mol_assert_not($mol_compare_deep(/\x22/mig, /\x22/mg));
472
+ },
473
+ 'Error'() {
474
+ $mol_assert_not($mol_compare_deep(new Error('xxx'), new Error('xxx')));
475
+ const fail = (message) => new Error(message);
476
+ $mol_assert_ok($mol_compare_deep(...['xxx', 'xxx'].map(msg => new Error(msg))));
477
+ $mol_assert_not($mol_compare_deep(...['xxx', 'yyy'].map(msg => new Error(msg))));
478
+ },
479
+ 'Map'() {
480
+ $mol_assert_ok($mol_compare_deep(new Map, new Map));
481
+ $mol_assert_ok($mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
482
+ $mol_assert_ok($mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
483
+ $mol_assert_not($mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
484
+ $mol_assert_not($mol_compare_deep(new Map([[[1], 2]]), new Map([[[3], 2]])));
485
+ },
486
+ 'Set'() {
487
+ $mol_assert_ok($mol_compare_deep(new Set, new Set));
488
+ $mol_assert_ok($mol_compare_deep(new Set([1, [2]]), new Set([1, [2]])));
489
+ $mol_assert_not($mol_compare_deep(new Set([1]), new Set([2])));
490
+ },
491
+ 'Uint8Array'() {
492
+ $mol_assert_ok($mol_compare_deep(new Uint8Array, new Uint8Array));
493
+ $mol_assert_ok($mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
494
+ $mol_assert_not($mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
495
+ },
496
+ 'Custom comparator'() {
497
+ class User {
498
+ name;
499
+ rand;
500
+ constructor(name, rand = Math.random()) {
501
+ this.name = name;
502
+ this.rand = rand;
503
+ }
504
+ [Symbol.toPrimitive](mode) {
505
+ return this.name;
506
+ }
507
+ }
508
+ $mol_assert_ok($mol_compare_deep(new User('Jin'), new User('Jin')));
509
+ $mol_assert_not($mol_compare_deep(new User('Jin'), new User('John')));
510
+ },
511
+ });
512
+ })($ || ($ = {}));
513
+ //mol/compare/deep/deep.test.tsx
514
+ ;
515
+ "use strict";
516
+ var $;
517
+ (function ($) {
518
+ $.$mol_compare_deep_cache = new WeakMap();
519
+ function $mol_compare_deep(left, right) {
520
+ if (Object.is(left, right))
521
+ return true;
522
+ if (left === null)
523
+ return false;
524
+ if (right === null)
525
+ return false;
526
+ if (typeof left !== 'object')
527
+ return false;
528
+ if (typeof right !== 'object')
529
+ return false;
530
+ const left_proto = Reflect.getPrototypeOf(left);
531
+ const right_proto = Reflect.getPrototypeOf(right);
532
+ if (left_proto !== right_proto)
533
+ return false;
534
+ if (left instanceof Boolean)
535
+ return Object.is(left.valueOf(), right['valueOf']());
536
+ if (left instanceof Number)
537
+ return Object.is(left.valueOf(), right['valueOf']());
538
+ if (left instanceof String)
539
+ return Object.is(left.valueOf(), right['valueOf']());
540
+ if (left instanceof Date)
541
+ return Object.is(left.valueOf(), right['valueOf']());
542
+ if (left instanceof RegExp)
543
+ return left.source === right['source'] && left.flags === right['flags'];
544
+ if (left instanceof Error)
545
+ return left.message === right['message'] && left.stack === right['stack'];
546
+ let left_cache = $.$mol_compare_deep_cache.get(left);
547
+ if (left_cache) {
548
+ const right_cache = left_cache.get(right);
549
+ if (typeof right_cache === 'boolean')
550
+ return right_cache;
551
+ }
552
+ else {
553
+ left_cache = new WeakMap([[right, true]]);
554
+ $.$mol_compare_deep_cache.set(left, left_cache);
555
+ }
556
+ let result;
557
+ try {
558
+ if (left_proto && !Reflect.getPrototypeOf(left_proto))
559
+ result = compare_pojo(left, right);
560
+ else if (Array.isArray(left))
561
+ result = compare_array(left, right);
562
+ else if (left instanceof Set)
563
+ result = compare_set(left, right);
564
+ else if (left instanceof Map)
565
+ result = compare_map(left, right);
566
+ else if (ArrayBuffer.isView(left))
567
+ result = compare_buffer(left, right);
568
+ else if (Symbol.toPrimitive in left)
569
+ result = compare_primitive(left, right);
570
+ else
571
+ result = false;
572
+ }
573
+ finally {
574
+ left_cache.set(right, result);
575
+ }
576
+ return result;
577
+ }
578
+ $.$mol_compare_deep = $mol_compare_deep;
579
+ function compare_array(left, right) {
580
+ const len = left.length;
581
+ if (len !== right.length)
582
+ return false;
583
+ for (let i = 0; i < len; ++i) {
584
+ if (!$mol_compare_deep(left[i], right[i]))
585
+ return false;
586
+ }
587
+ return true;
588
+ }
589
+ function compare_buffer(left, right) {
590
+ const len = left.byteLength;
591
+ if (len !== right.byteLength)
592
+ return false;
593
+ for (let i = 0; i < len; ++i) {
594
+ if (left[i] !== right[i])
595
+ return false;
596
+ }
597
+ return true;
598
+ }
599
+ function compare_iterator(left, right) {
600
+ while (true) {
601
+ const left_next = left.next();
602
+ const right_next = right.next();
603
+ if (left_next.done !== right_next.done)
604
+ return false;
605
+ if (left_next.done)
606
+ break;
607
+ if (!$mol_compare_deep(left_next.value, right_next.value))
608
+ return false;
609
+ }
610
+ return true;
611
+ }
612
+ function compare_set(left, right) {
613
+ if (left.size !== right.size)
614
+ return false;
615
+ return compare_iterator(left.values(), right.values());
616
+ }
617
+ function compare_map(left, right) {
618
+ if (left.size !== right.size)
619
+ return false;
620
+ return compare_iterator(left.keys(), right.keys())
621
+ && compare_iterator(left.values(), right.values());
622
+ }
623
+ function compare_pojo(left, right) {
624
+ const left_keys = Object.getOwnPropertyNames(left);
625
+ const right_keys = Object.getOwnPropertyNames(right);
626
+ if (left_keys.length !== right_keys.length)
627
+ return false;
628
+ for (let key of left_keys) {
629
+ if (!$mol_compare_deep(left[key], Reflect.get(right, key)))
630
+ return false;
631
+ }
632
+ return true;
633
+ }
634
+ function compare_primitive(left, right) {
635
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
636
+ }
637
+ })($ || ($ = {}));
638
+ //mol/compare/deep/deep.ts
639
+ ;
640
+ "use strict";
641
+ var $;
642
+ (function ($) {
643
+ function $mol_dom_serialize(node) {
644
+ const serializer = new $mol_dom_context.XMLSerializer;
645
+ return serializer.serializeToString(node);
646
+ }
647
+ $.$mol_dom_serialize = $mol_dom_serialize;
648
+ })($ || ($ = {}));
649
+ //mol/dom/serialize/serialize.ts
650
+ ;
651
+ "use strict";
652
+ var $;
653
+ (function ($) {
654
+ $mol_test({
655
+ 'must be false'() {
656
+ $mol_assert_not(0);
657
+ },
658
+ 'must be true'() {
659
+ $mol_assert_ok(1);
660
+ },
661
+ 'two must be equal'() {
662
+ $mol_assert_equal(2, 2);
663
+ },
664
+ 'three must be equal'() {
665
+ $mol_assert_equal(2, 2, 2);
666
+ },
667
+ 'two must be unique'() {
668
+ $mol_assert_unique([3], [3]);
669
+ },
670
+ 'three must be unique'() {
671
+ $mol_assert_unique([3], [3], [3]);
672
+ },
673
+ 'two must be alike'() {
674
+ $mol_assert_like([3], [3]);
675
+ },
676
+ 'three must be alike'() {
677
+ $mol_assert_like([3], [3], [3]);
678
+ },
679
+ });
680
+ })($ || ($ = {}));
681
+ //mol/assert/assert.test.ts
682
+ ;
683
+ "use strict";
684
+ var $;
685
+ (function ($) {
686
+ function $mol_assert_ok(value) {
687
+ if (value)
688
+ return;
689
+ $mol_fail(new Error(`${value} ≠ true`));
690
+ }
691
+ $.$mol_assert_ok = $mol_assert_ok;
692
+ function $mol_assert_not(value) {
693
+ if (!value)
694
+ return;
695
+ $mol_fail(new Error(`${value} ≠ false`));
696
+ }
697
+ $.$mol_assert_not = $mol_assert_not;
698
+ function $mol_assert_fail(handler, ErrorRight) {
699
+ const fail = $.$mol_fail;
700
+ try {
701
+ $.$mol_fail = $.$mol_fail_hidden;
702
+ handler();
703
+ }
704
+ catch (error) {
705
+ if (!ErrorRight)
706
+ return error;
707
+ $.$mol_fail = fail;
708
+ if (typeof ErrorRight === 'string') {
709
+ $mol_assert_equal(error.message, ErrorRight);
710
+ }
711
+ else {
712
+ $mol_assert_ok(error instanceof ErrorRight);
713
+ }
714
+ return error;
715
+ }
716
+ finally {
717
+ $.$mol_fail = fail;
718
+ }
719
+ $mol_fail(new Error('Not failed'));
720
+ }
721
+ $.$mol_assert_fail = $mol_assert_fail;
722
+ function $mol_assert_equal(...args) {
723
+ for (let i = 0; i < args.length; ++i) {
724
+ for (let j = 0; j < args.length; ++j) {
725
+ if (i === j)
726
+ continue;
727
+ if (Number.isNaN(args[i]) && Number.isNaN(args[j]))
728
+ continue;
729
+ if (args[i] !== args[j])
730
+ $mol_fail(new Error(`Not equal (${i + 1}:${j + 1})\n${args[i]}\n${args[j]}`));
731
+ }
732
+ }
733
+ }
734
+ $.$mol_assert_equal = $mol_assert_equal;
735
+ function $mol_assert_unique(...args) {
736
+ for (let i = 0; i < args.length; ++i) {
737
+ for (let j = 0; j < args.length; ++j) {
738
+ if (i === j)
739
+ continue;
740
+ if (args[i] === args[j] || (Number.isNaN(args[i]) && Number.isNaN(args[j]))) {
741
+ $mol_fail(new Error(`args[${i}] = args[${j}] = ${args[i]}`));
742
+ }
743
+ }
744
+ }
745
+ }
746
+ $.$mol_assert_unique = $mol_assert_unique;
747
+ function $mol_assert_like(head, ...tail) {
748
+ for (let [index, value] of Object.entries(tail)) {
749
+ if (!$mol_compare_deep(value, head)) {
750
+ const print = (val) => {
751
+ if (!val)
752
+ return val;
753
+ if (typeof val !== 'object')
754
+ return val;
755
+ if ('outerHTML' in val)
756
+ return val.outerHTML;
757
+ try {
758
+ return JSON.stringify(val);
759
+ }
760
+ catch (error) {
761
+ console.error(error);
762
+ return val;
763
+ }
764
+ };
765
+ return $mol_fail(new Error(`Not like (1:${+index + 2})\n${print(head)}\n---\n${print(value)}`));
766
+ }
767
+ }
768
+ }
769
+ $.$mol_assert_like = $mol_assert_like;
770
+ function $mol_assert_dom(left, right) {
771
+ $mol_assert_equal($mol_dom_serialize(left), $mol_dom_serialize(right));
772
+ }
773
+ $.$mol_assert_dom = $mol_assert_dom;
774
+ })($ || ($ = {}));
775
+ //mol/assert/assert.ts
776
+ ;
777
+ "use strict";
778
+ var $;
779
+ (function ($) {
780
+ function $mol_log3_area_lazy(event) {
781
+ const self = this;
782
+ const stack = self.$mol_log3_stack;
783
+ const deep = stack.length;
784
+ let logged = false;
785
+ stack.push(() => {
786
+ logged = true;
787
+ self.$mol_log3_area.call(self, event);
788
+ });
789
+ return () => {
790
+ if (logged)
791
+ self.console.groupEnd();
792
+ if (stack.length > deep)
793
+ stack.length = deep;
794
+ };
795
+ }
796
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
797
+ $.$mol_log3_stack = [];
798
+ })($ || ($ = {}));
799
+ //mol/log3/log3.ts
800
+ ;
801
+ "use strict";
802
+ //mol/type/keys/extract/extract.test.ts
803
+ ;
804
+ "use strict";
805
+ //mol/type/keys/extract/extract.ts
806
+ ;
807
+ "use strict";
808
+ var $;
809
+ (function ($_1) {
810
+ $mol_test_mocks.push($ => {
811
+ $.$mol_log3_come = () => { };
812
+ $.$mol_log3_done = () => { };
813
+ $.$mol_log3_fail = () => { };
814
+ $.$mol_log3_warn = () => { };
815
+ $.$mol_log3_rise = () => { };
816
+ $.$mol_log3_area = () => () => { };
817
+ });
818
+ })($ || ($ = {}));
819
+ //mol/log3/log3.test.ts
820
+ ;
821
+ "use strict";
822
+ var $;
823
+ (function ($) {
824
+ function $mol_log3_web_make(level, color) {
825
+ return function $mol_log3_logger(event) {
826
+ const pending = this.$mol_log3_stack.pop();
827
+ if (pending)
828
+ pending();
829
+ let tpl = '%c';
830
+ const chunks = Object.values(event);
831
+ for (let i = 0; i < chunks.length; ++i) {
832
+ tpl += (typeof chunks[i] === 'string') ? ' ⦙ %s' : ' ⦙ %o';
833
+ }
834
+ const style = `color:${color};font-weight:bolder`;
835
+ this.console[level](tpl, style, ...chunks);
836
+ const self = this;
837
+ return () => self.console.groupEnd();
838
+ };
839
+ }
840
+ $.$mol_log3_web_make = $mol_log3_web_make;
841
+ $.$mol_log3_come = $mol_log3_web_make('info', 'royalblue');
842
+ $.$mol_log3_done = $mol_log3_web_make('info', 'forestgreen');
843
+ $.$mol_log3_fail = $mol_log3_web_make('error', 'orangered');
844
+ $.$mol_log3_warn = $mol_log3_web_make('warn', 'goldenrod');
845
+ $.$mol_log3_rise = $mol_log3_web_make('log', 'magenta');
846
+ $.$mol_log3_area = $mol_log3_web_make('group', 'cyan');
847
+ })($ || ($ = {}));
848
+ //mol/log3/log3.web.ts
849
+ ;
850
+ "use strict";
851
+ var $;
852
+ (function ($_1) {
853
+ $mol_test({
854
+ 'FQN of anon function'($) {
855
+ const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
856
+ $mol_assert_equal($$.$mol_func_name_test.name, '');
857
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
858
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
859
+ },
860
+ });
861
+ })($ || ($ = {}));
862
+ //mol/func/name/name.test.ts
863
+ ;
864
+ "use strict";
865
+ var $;
866
+ (function ($) {
867
+ function $mol_func_name(func) {
868
+ let name = func.name;
869
+ if (name?.length > 1)
870
+ return name;
871
+ for (let key in this) {
872
+ try {
873
+ if (this[key] !== func)
874
+ continue;
875
+ name = key;
876
+ Object.defineProperty(func, 'name', { value: name });
877
+ break;
878
+ }
879
+ catch { }
880
+ }
881
+ return name;
882
+ }
883
+ $.$mol_func_name = $mol_func_name;
884
+ function $mol_func_name_from(target, source) {
885
+ Object.defineProperty(target, 'name', { value: source.name });
886
+ return target;
887
+ }
888
+ $.$mol_func_name_from = $mol_func_name_from;
889
+ })($ || ($ = {}));
890
+ //mol/func/name/name.ts
891
+ ;
892
+ "use strict";
893
+ var $;
894
+ (function ($) {
895
+ $mol_test({
896
+ 'Wrap & unwrap'() {
897
+ const val = [1];
898
+ const mut = $mol_mutable(val);
899
+ $mol_assert_equal(val, mut());
900
+ },
901
+ 'Deep array'() {
902
+ const val = [[1], [2], [3]];
903
+ const mut = $mol_mutable(val);
904
+ $mol_assert_equal(mut[1][0](v => -v), -2);
905
+ $mol_assert_unique(val, mut());
906
+ $mol_assert_equal(val[0], mut()[0]);
907
+ $mol_assert_equal(val[2], mut()[2]);
908
+ $mol_assert_unique(val[1], mut()[1]);
909
+ $mol_assert_like(mut()[1], [-2]);
910
+ },
911
+ 'Deep objects'() {
912
+ const val = { a: { x: 1 }, b: { y: 2 }, c: { z: 3 } };
913
+ const mut = $mol_mutable(val);
914
+ $mol_assert_equal(mut.b.y(v => -v), -2);
915
+ $mol_assert_unique(val, mut());
916
+ $mol_assert_equal(val.a, mut().a);
917
+ $mol_assert_equal(val.c, mut().c);
918
+ $mol_assert_unique(val.b, mut().b);
919
+ $mol_assert_like(mut().b, { y: -2 });
920
+ },
921
+ });
922
+ })($ || ($ = {}));
923
+ //mol/mutable/mutable.test.ts
924
+
925
+ //# sourceMappingURL=web.test.js.map