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