mol_vary 0.0.41 → 0.0.42
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/README.md +10 -2
- package/node.d.ts +19 -10
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +143 -105
- package/node.js.map +1 -1
- package/node.mjs +143 -105
- package/node.test.js +156 -110
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.d.ts +19 -10
- package/web.d.ts.map +1 -1
- package/web.deps.json +1 -1
- package/web.js +143 -105
- package/web.js.map +1 -1
- package/web.mjs +143 -105
- package/web.test.js +13 -5
- package/web.test.js.map +1 -1
package/node.mjs
CHANGED
|
@@ -2336,14 +2336,21 @@ var $;
|
|
|
2336
2336
|
$mol_vary_spec[$mol_vary_spec["true"] = 'T'.charCodeAt(0)] = "true";
|
|
2337
2337
|
$mol_vary_spec[$mol_vary_spec["fake"] = 'F'.charCodeAt(0)] = "fake";
|
|
2338
2338
|
$mol_vary_spec[$mol_vary_spec["both"] = 'B'.charCodeAt(0)] = "both";
|
|
2339
|
-
$mol_vary_spec[$mol_vary_spec["fp16"] =
|
|
2340
|
-
$mol_vary_spec[$mol_vary_spec["fp32"] =
|
|
2341
|
-
$mol_vary_spec[$mol_vary_spec["fp64"] =
|
|
2339
|
+
$mol_vary_spec[$mol_vary_spec["fp16"] = 'H'.charCodeAt(0)] = "fp16";
|
|
2340
|
+
$mol_vary_spec[$mol_vary_spec["fp32"] = 'S'.charCodeAt(0)] = "fp32";
|
|
2341
|
+
$mol_vary_spec[$mol_vary_spec["fp64"] = 'D'.charCodeAt(0)] = "fp64";
|
|
2342
2342
|
})($mol_vary_spec = $.$mol_vary_spec || ($.$mol_vary_spec = {}));
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2343
|
+
$.$mol_vary_lean = Symbol.for('$mol_vary_lean');
|
|
2344
|
+
const pojo_maker = (keys) => (vals) => {
|
|
2345
|
+
const obj = {};
|
|
2346
|
+
for (let i = 0; i < keys.length; ++i)
|
|
2347
|
+
obj[keys[i]] = vals[i];
|
|
2348
|
+
return obj;
|
|
2349
|
+
};
|
|
2350
|
+
class $mol_vary_class extends Object {
|
|
2351
|
+
array = new Uint8Array(256);
|
|
2352
|
+
buffer = new DataView(this.array.buffer);
|
|
2353
|
+
pack(data) {
|
|
2347
2354
|
let pos = 0;
|
|
2348
2355
|
let capacity = 9;
|
|
2349
2356
|
const offsets = new Map();
|
|
@@ -2352,19 +2359,19 @@ var $;
|
|
|
2352
2359
|
if (size < 0)
|
|
2353
2360
|
return;
|
|
2354
2361
|
capacity += size;
|
|
2355
|
-
if (
|
|
2362
|
+
if (this.array.byteLength >= capacity)
|
|
2356
2363
|
return;
|
|
2357
2364
|
const buffer2 = new Uint8Array(Math.ceil(capacity / 4096) * 4096);
|
|
2358
|
-
buffer2.set(
|
|
2359
|
-
|
|
2360
|
-
|
|
2365
|
+
buffer2.set(this.array);
|
|
2366
|
+
this.array = buffer2;
|
|
2367
|
+
this.buffer = new DataView(this.array.buffer);
|
|
2361
2368
|
};
|
|
2362
2369
|
const release = (size) => {
|
|
2363
2370
|
capacity -= size;
|
|
2364
2371
|
};
|
|
2365
2372
|
const dump_unum = (tip, val) => {
|
|
2366
2373
|
if (val < $mol_vary_len.L1) {
|
|
2367
|
-
|
|
2374
|
+
this.array[pos++] = tip | Number(val);
|
|
2368
2375
|
release(8);
|
|
2369
2376
|
return;
|
|
2370
2377
|
}
|
|
@@ -2374,25 +2381,25 @@ var $;
|
|
|
2374
2381
|
return dump_unum($mol_vary_tip.link, offset);
|
|
2375
2382
|
}
|
|
2376
2383
|
if (val < 2 ** 8) {
|
|
2377
|
-
|
|
2378
|
-
|
|
2384
|
+
this.array[pos++] = tip | $mol_vary_len.L1;
|
|
2385
|
+
this.array[pos++] = Number(val);
|
|
2379
2386
|
release(7);
|
|
2380
2387
|
}
|
|
2381
2388
|
else if (val < 2 ** 16) {
|
|
2382
|
-
|
|
2383
|
-
|
|
2389
|
+
this.array[pos++] = tip | $mol_vary_len.L2;
|
|
2390
|
+
this.buffer.setUint16(pos, Number(val), true);
|
|
2384
2391
|
pos += 2;
|
|
2385
2392
|
release(6);
|
|
2386
2393
|
}
|
|
2387
2394
|
else if (val < 2 ** 32) {
|
|
2388
|
-
|
|
2389
|
-
|
|
2395
|
+
this.array[pos++] = tip | $mol_vary_len.L4;
|
|
2396
|
+
this.buffer.setUint32(pos, Number(val), true);
|
|
2390
2397
|
pos += 4;
|
|
2391
2398
|
release(4);
|
|
2392
2399
|
}
|
|
2393
2400
|
else if (val < 2n ** 64n) {
|
|
2394
|
-
|
|
2395
|
-
|
|
2401
|
+
this.array[pos++] = tip | $mol_vary_len.L8;
|
|
2402
|
+
this.buffer.setBigUint64(pos, BigInt(val), true);
|
|
2396
2403
|
pos += 8;
|
|
2397
2404
|
}
|
|
2398
2405
|
else {
|
|
@@ -2403,7 +2410,7 @@ var $;
|
|
|
2403
2410
|
};
|
|
2404
2411
|
const dump_snum = (val) => {
|
|
2405
2412
|
if (val > -$mol_vary_len.L1) {
|
|
2406
|
-
|
|
2413
|
+
this.array[pos++] = Number(val);
|
|
2407
2414
|
release(8);
|
|
2408
2415
|
return;
|
|
2409
2416
|
}
|
|
@@ -2411,25 +2418,25 @@ var $;
|
|
|
2411
2418
|
if (offset !== undefined)
|
|
2412
2419
|
return dump_unum($mol_vary_tip.link, offset);
|
|
2413
2420
|
if (val >= -(2 ** 7)) {
|
|
2414
|
-
|
|
2415
|
-
|
|
2421
|
+
this.array[pos++] = -$mol_vary_len.L1;
|
|
2422
|
+
this.array[pos++] = Number(val);
|
|
2416
2423
|
release(7);
|
|
2417
2424
|
}
|
|
2418
2425
|
else if (val >= -(2 ** 15)) {
|
|
2419
|
-
|
|
2420
|
-
|
|
2426
|
+
this.array[pos++] = -$mol_vary_len.L2;
|
|
2427
|
+
this.buffer.setInt16(pos, Number(val), true);
|
|
2421
2428
|
pos += 2;
|
|
2422
2429
|
release(6);
|
|
2423
2430
|
}
|
|
2424
2431
|
else if (val >= -(2 ** 31)) {
|
|
2425
|
-
|
|
2426
|
-
|
|
2432
|
+
this.array[pos++] = -$mol_vary_len.L4;
|
|
2433
|
+
this.buffer.setInt32(pos, Number(val), true);
|
|
2427
2434
|
pos += 4;
|
|
2428
2435
|
release(4);
|
|
2429
2436
|
}
|
|
2430
2437
|
else if (val >= -(2n ** 63n)) {
|
|
2431
|
-
|
|
2432
|
-
|
|
2438
|
+
this.array[pos++] = -$mol_vary_len.L8;
|
|
2439
|
+
this.buffer.setBigInt64(pos, BigInt(val), true);
|
|
2433
2440
|
pos += 8;
|
|
2434
2441
|
}
|
|
2435
2442
|
else {
|
|
@@ -2442,17 +2449,17 @@ var $;
|
|
|
2442
2449
|
if (buf.byteLength > 264)
|
|
2443
2450
|
$mol_fail(new Error('Number too high', { cause: { val } }));
|
|
2444
2451
|
acquire(buf.byteLength - 7);
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2452
|
+
this.array[pos++] = -$mol_vary_len.LA;
|
|
2453
|
+
this.array[pos++] = buf.byteLength - 9;
|
|
2454
|
+
this.array.set(buf, pos);
|
|
2448
2455
|
pos += buf.byteLength;
|
|
2449
2456
|
};
|
|
2450
2457
|
const dump_float = (val) => {
|
|
2451
2458
|
const offset = offsets.get(val);
|
|
2452
2459
|
if (offset !== undefined)
|
|
2453
2460
|
return dump_unum($mol_vary_tip.link, offset);
|
|
2454
|
-
|
|
2455
|
-
|
|
2461
|
+
this.array[pos++] = $mol_vary_spec.fp64;
|
|
2462
|
+
this.buffer.setFloat64(pos, val, true);
|
|
2456
2463
|
pos += 8;
|
|
2457
2464
|
offsets.set(val, offsets.size);
|
|
2458
2465
|
};
|
|
@@ -2462,7 +2469,7 @@ var $;
|
|
|
2462
2469
|
return dump_unum($mol_vary_tip.link, offset);
|
|
2463
2470
|
dump_unum($mol_vary_tip.text, val.length);
|
|
2464
2471
|
acquire(val.length * 3);
|
|
2465
|
-
const len = $mol_charset_encode_to(val,
|
|
2472
|
+
const len = $mol_charset_encode_to(val, this.array, pos);
|
|
2466
2473
|
pos += len;
|
|
2467
2474
|
release(val.length * 3 - len);
|
|
2468
2475
|
offsets.set(val, offsets.size);
|
|
@@ -2475,31 +2482,31 @@ var $;
|
|
|
2475
2482
|
dump_unum($mol_vary_tip.blob, val.byteLength);
|
|
2476
2483
|
acquire(1 + val.byteLength);
|
|
2477
2484
|
if (val instanceof Uint8Array)
|
|
2478
|
-
|
|
2485
|
+
this.array[pos++] = $mol_vary_tip.uint | $mol_vary_len.L1;
|
|
2479
2486
|
else if (val instanceof Uint16Array)
|
|
2480
|
-
|
|
2487
|
+
this.array[pos++] = $mol_vary_tip.uint | $mol_vary_len.L2;
|
|
2481
2488
|
else if (val instanceof Uint32Array)
|
|
2482
|
-
|
|
2489
|
+
this.array[pos++] = $mol_vary_tip.uint | $mol_vary_len.L4;
|
|
2483
2490
|
else if (val instanceof BigUint64Array)
|
|
2484
|
-
|
|
2491
|
+
this.array[pos++] = $mol_vary_tip.uint | $mol_vary_len.L8;
|
|
2485
2492
|
else if (val instanceof Int8Array)
|
|
2486
|
-
|
|
2493
|
+
this.array[pos++] = $mol_vary_tip.sint | ~$mol_vary_len.L1;
|
|
2487
2494
|
else if (val instanceof Int16Array)
|
|
2488
|
-
|
|
2495
|
+
this.array[pos++] = $mol_vary_tip.sint | ~$mol_vary_len.L2;
|
|
2489
2496
|
else if (val instanceof Int32Array)
|
|
2490
|
-
|
|
2497
|
+
this.array[pos++] = $mol_vary_tip.sint | ~$mol_vary_len.L4;
|
|
2491
2498
|
else if (val instanceof BigInt64Array)
|
|
2492
|
-
|
|
2499
|
+
this.array[pos++] = $mol_vary_tip.sint | ~$mol_vary_len.L8;
|
|
2493
2500
|
else if (typeof Float16Array === 'function' && val instanceof Float16Array)
|
|
2494
|
-
|
|
2501
|
+
this.array[pos++] = $mol_vary_spec.fp16;
|
|
2495
2502
|
else if (val instanceof Float32Array)
|
|
2496
|
-
|
|
2503
|
+
this.array[pos++] = $mol_vary_spec.fp32;
|
|
2497
2504
|
else if (val instanceof Float64Array)
|
|
2498
|
-
|
|
2505
|
+
this.array[pos++] = $mol_vary_spec.fp64;
|
|
2499
2506
|
else
|
|
2500
2507
|
$mol_fail(new Error(`Unsupported type`));
|
|
2501
2508
|
const src = (val instanceof Uint8Array) ? val : new Uint8Array(val.buffer, val.byteOffset, val.byteLength);
|
|
2502
|
-
|
|
2509
|
+
this.array.set(src, pos);
|
|
2503
2510
|
pos += val.byteLength;
|
|
2504
2511
|
offsets.set(val, offsets.size);
|
|
2505
2512
|
};
|
|
@@ -2550,12 +2557,12 @@ var $;
|
|
|
2550
2557
|
const dump = (val) => {
|
|
2551
2558
|
switch (typeof val) {
|
|
2552
2559
|
case 'undefined': {
|
|
2553
|
-
|
|
2560
|
+
this.array[pos++] = $mol_vary_spec.both;
|
|
2554
2561
|
release(8);
|
|
2555
2562
|
return;
|
|
2556
2563
|
}
|
|
2557
2564
|
case 'boolean': {
|
|
2558
|
-
|
|
2565
|
+
this.array[pos++] = val ? $mol_vary_spec.true : $mol_vary_spec.fake;
|
|
2559
2566
|
release(8);
|
|
2560
2567
|
return;
|
|
2561
2568
|
}
|
|
@@ -2576,7 +2583,7 @@ var $;
|
|
|
2576
2583
|
case 'object': {
|
|
2577
2584
|
if (!val) {
|
|
2578
2585
|
release(8);
|
|
2579
|
-
return
|
|
2586
|
+
return this.array[pos++] = $mol_vary_spec.none;
|
|
2580
2587
|
}
|
|
2581
2588
|
if (ArrayBuffer.isView(val))
|
|
2582
2589
|
return dump_buffer(val);
|
|
@@ -2590,10 +2597,10 @@ var $;
|
|
|
2590
2597
|
dump(data);
|
|
2591
2598
|
if (pos !== capacity)
|
|
2592
2599
|
$mol_fail(new Error('Wrong reserved capacity', { cause: { capacity, size: pos, data } }));
|
|
2593
|
-
return
|
|
2600
|
+
return this.array.slice(0, pos);
|
|
2594
2601
|
}
|
|
2595
|
-
|
|
2596
|
-
const
|
|
2602
|
+
take(array) {
|
|
2603
|
+
const buffer = new DataView(array.buffer, array.byteOffset, array.byteLength);
|
|
2597
2604
|
const stream = [];
|
|
2598
2605
|
let pos = 0;
|
|
2599
2606
|
const read_unum = (kind) => {
|
|
@@ -2603,18 +2610,18 @@ var $;
|
|
|
2603
2610
|
return num;
|
|
2604
2611
|
let res = 0;
|
|
2605
2612
|
if (num === $mol_vary_len.L1) {
|
|
2606
|
-
res =
|
|
2613
|
+
res = buffer.getUint8(pos++);
|
|
2607
2614
|
}
|
|
2608
2615
|
else if (num === $mol_vary_len.L2) {
|
|
2609
|
-
res =
|
|
2616
|
+
res = buffer.getUint16(pos, true);
|
|
2610
2617
|
pos += 2;
|
|
2611
2618
|
}
|
|
2612
2619
|
else if (num === $mol_vary_len.L4) {
|
|
2613
|
-
res =
|
|
2620
|
+
res = buffer.getUint32(pos, true);
|
|
2614
2621
|
pos += 4;
|
|
2615
2622
|
}
|
|
2616
2623
|
else if (num === $mol_vary_len.L8) {
|
|
2617
|
-
res =
|
|
2624
|
+
res = buffer.getBigUint64(pos, true);
|
|
2618
2625
|
if (res <= Number.MAX_SAFE_INTEGER)
|
|
2619
2626
|
res = Number(res);
|
|
2620
2627
|
pos += 8;
|
|
@@ -2627,30 +2634,30 @@ var $;
|
|
|
2627
2634
|
return res;
|
|
2628
2635
|
};
|
|
2629
2636
|
const read_snum = (kind) => {
|
|
2630
|
-
const num =
|
|
2637
|
+
const num = buffer.getInt8(pos++);
|
|
2631
2638
|
if (num > -$mol_vary_len.L1)
|
|
2632
2639
|
return num;
|
|
2633
2640
|
let res = 0;
|
|
2634
2641
|
if (num === -$mol_vary_len.L1) {
|
|
2635
|
-
res =
|
|
2642
|
+
res = buffer.getInt8(pos++);
|
|
2636
2643
|
}
|
|
2637
2644
|
else if (num === -$mol_vary_len.L2) {
|
|
2638
|
-
res =
|
|
2645
|
+
res = buffer.getInt16(pos, true);
|
|
2639
2646
|
pos += 2;
|
|
2640
2647
|
}
|
|
2641
2648
|
else if (num === -$mol_vary_len.L4) {
|
|
2642
|
-
res =
|
|
2649
|
+
res = buffer.getInt32(pos, true);
|
|
2643
2650
|
pos += 4;
|
|
2644
2651
|
}
|
|
2645
2652
|
else if (num === -$mol_vary_len.L8) {
|
|
2646
|
-
res =
|
|
2653
|
+
res = buffer.getBigInt64(pos, true);
|
|
2647
2654
|
if (res >= Number.MIN_SAFE_INTEGER && res <= Number.MAX_SAFE_INTEGER)
|
|
2648
2655
|
res = Number(res);
|
|
2649
2656
|
pos += 8;
|
|
2650
2657
|
}
|
|
2651
2658
|
else if (num === -$mol_vary_len.LA) {
|
|
2652
|
-
const len =
|
|
2653
|
-
res = $mol_bigint_decode(new Uint8Array(
|
|
2659
|
+
const len = buffer.getUint8(pos++) + 9;
|
|
2660
|
+
res = $mol_bigint_decode(new Uint8Array(buffer.buffer, buffer.byteOffset + pos, len));
|
|
2654
2661
|
pos += len;
|
|
2655
2662
|
}
|
|
2656
2663
|
else {
|
|
@@ -2661,20 +2668,20 @@ var $;
|
|
|
2661
2668
|
};
|
|
2662
2669
|
const read_text = (kind) => {
|
|
2663
2670
|
const len = read_unum(kind);
|
|
2664
|
-
const [text, bytes] = $mol_charset_decode_from(
|
|
2671
|
+
const [text, bytes] = $mol_charset_decode_from(array, buffer.byteOffset + pos, len);
|
|
2665
2672
|
pos += bytes;
|
|
2666
2673
|
stream.push(text);
|
|
2667
2674
|
return text;
|
|
2668
2675
|
};
|
|
2669
2676
|
const read_buffer = (len, TypedArray) => {
|
|
2670
|
-
const bin = new TypedArray(
|
|
2677
|
+
const bin = new TypedArray(array.slice(pos, pos + len).buffer);
|
|
2671
2678
|
pos += len;
|
|
2672
2679
|
stream.push(bin);
|
|
2673
2680
|
return bin;
|
|
2674
2681
|
};
|
|
2675
2682
|
const read_blob = (kind) => {
|
|
2676
2683
|
const len = read_unum(kind);
|
|
2677
|
-
const kind_item =
|
|
2684
|
+
const kind_item = buffer.getUint8(pos++);
|
|
2678
2685
|
switch (kind_item) {
|
|
2679
2686
|
case $mol_vary_len.L1: return read_buffer(len, Uint8Array);
|
|
2680
2687
|
case $mol_vary_len.L2: return read_buffer(len, Uint16Array);
|
|
@@ -2714,13 +2721,8 @@ var $;
|
|
|
2714
2721
|
const node = this.rich_node(keys);
|
|
2715
2722
|
let rich = node.get(null);
|
|
2716
2723
|
if (!rich)
|
|
2717
|
-
node.set(null, rich = (
|
|
2718
|
-
|
|
2719
|
-
for (let i = 0; i < len; ++i)
|
|
2720
|
-
obj[keys[i]] = vals[i];
|
|
2721
|
-
return obj;
|
|
2722
|
-
});
|
|
2723
|
-
const obj = rich(...vals);
|
|
2724
|
+
node.set(null, rich = pojo_maker(keys));
|
|
2725
|
+
const obj = rich(vals);
|
|
2724
2726
|
stream.push(obj);
|
|
2725
2727
|
return obj;
|
|
2726
2728
|
};
|
|
@@ -2739,19 +2741,19 @@ var $;
|
|
|
2739
2741
|
++pos;
|
|
2740
2742
|
return undefined;
|
|
2741
2743
|
case $mol_vary_spec.fp64: {
|
|
2742
|
-
const val =
|
|
2744
|
+
const val = buffer.getFloat64(++pos, true);
|
|
2743
2745
|
stream.push(val);
|
|
2744
2746
|
pos += 8;
|
|
2745
2747
|
return val;
|
|
2746
2748
|
}
|
|
2747
2749
|
case $mol_vary_spec.fp32: {
|
|
2748
|
-
const val =
|
|
2750
|
+
const val = buffer.getFloat32(++pos, true);
|
|
2749
2751
|
stream.push(val);
|
|
2750
2752
|
pos += 4;
|
|
2751
2753
|
return val;
|
|
2752
2754
|
}
|
|
2753
2755
|
case $mol_vary_spec.fp16: {
|
|
2754
|
-
const val =
|
|
2756
|
+
const val = buffer.getFloat16(++pos, true);
|
|
2755
2757
|
stream.push(val);
|
|
2756
2758
|
pos += 2;
|
|
2757
2759
|
return val;
|
|
@@ -2761,7 +2763,7 @@ var $;
|
|
|
2761
2763
|
}
|
|
2762
2764
|
};
|
|
2763
2765
|
const read_vary = () => {
|
|
2764
|
-
const kind =
|
|
2766
|
+
const kind = buffer.getUint8(pos);
|
|
2765
2767
|
const tip = kind & 0b111_00000;
|
|
2766
2768
|
switch (tip) {
|
|
2767
2769
|
case $mol_vary_tip.uint: return read_unum(kind);
|
|
@@ -2776,14 +2778,20 @@ var $;
|
|
|
2776
2778
|
}
|
|
2777
2779
|
};
|
|
2778
2780
|
const result = read_vary();
|
|
2779
|
-
if (pos !==
|
|
2780
|
-
$mol_fail(new Error('Buffer too large', { cause: { size:
|
|
2781
|
+
if (pos !== array.byteLength)
|
|
2782
|
+
$mol_fail(new Error('Buffer too large', { cause: { size: array.byteLength, taken: pos, result } }));
|
|
2781
2783
|
return result;
|
|
2782
2784
|
}
|
|
2783
|
-
|
|
2785
|
+
rich_index = new Map([
|
|
2784
2786
|
[null, () => ({})]
|
|
2785
2787
|
]);
|
|
2786
|
-
|
|
2788
|
+
room() {
|
|
2789
|
+
const room = new $mol_vary_class;
|
|
2790
|
+
const index_clone = (map) => new Map([...map].map(([k, v]) => [k, k === null ? v : index_clone(v)]));
|
|
2791
|
+
room.rich_index = index_clone(this.rich_index);
|
|
2792
|
+
return room;
|
|
2793
|
+
}
|
|
2794
|
+
rich_node(keys) {
|
|
2787
2795
|
let node = this.rich_index;
|
|
2788
2796
|
for (const key of keys) {
|
|
2789
2797
|
let sub = node.get(key);
|
|
@@ -2794,33 +2802,63 @@ var $;
|
|
|
2794
2802
|
}
|
|
2795
2803
|
return node;
|
|
2796
2804
|
}
|
|
2797
|
-
|
|
2805
|
+
type({ type, keys, rich, lean }) {
|
|
2798
2806
|
this.rich_node(keys).set(null, rich);
|
|
2799
|
-
|
|
2807
|
+
type.prototype[$.$mol_vary_lean] = (val) => [keys, lean(val)];
|
|
2800
2808
|
}
|
|
2801
2809
|
}
|
|
2802
|
-
$.$
|
|
2803
|
-
$.$
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2810
|
+
$.$mol_vary_class = $mol_vary_class;
|
|
2811
|
+
$.$mol_vary = new $mol_vary_class;
|
|
2812
|
+
$.$mol_vary.type({
|
|
2813
|
+
type: Map,
|
|
2814
|
+
keys: ['keys', 'vals'],
|
|
2815
|
+
lean: obj => [[...obj.keys()], [...obj.values()]],
|
|
2816
|
+
rich: ([keys, vals]) => new Map(keys.map((k, i) => [k, vals[i]])),
|
|
2817
|
+
});
|
|
2818
|
+
$.$mol_vary.type({
|
|
2819
|
+
type: Set,
|
|
2820
|
+
keys: ['set'],
|
|
2821
|
+
lean: obj => [[...obj.values()]],
|
|
2822
|
+
rich: ([vals]) => new Set(vals),
|
|
2823
|
+
});
|
|
2824
|
+
$.$mol_vary.type({
|
|
2825
|
+
type: Date,
|
|
2826
|
+
keys: ['unix_time'],
|
|
2827
|
+
lean: obj => [obj.valueOf() / 1000],
|
|
2828
|
+
rich: ([ts]) => new Date(ts * 1000),
|
|
2829
|
+
});
|
|
2830
|
+
$.$mol_vary.type({
|
|
2831
|
+
type: $mol_dom.Element,
|
|
2832
|
+
keys: ['elem', 'keys', 'vals', 'kids'],
|
|
2833
|
+
lean: node => {
|
|
2834
|
+
const attrs = [...node.attributes];
|
|
2835
|
+
const kids = [...node.childNodes].map(kid => kid instanceof $mol_dom.Text ? kid.nodeValue : kid);
|
|
2836
|
+
return [node.nodeName, attrs.map(attr => attr.nodeName), attrs.map(attr => attr.nodeValue), kids];
|
|
2837
|
+
},
|
|
2838
|
+
rich: ([name, keys, vals, kids]) => {
|
|
2839
|
+
const el = $mol_dom.document.createElement(name);
|
|
2840
|
+
for (let i = 0; i < keys.length; ++i)
|
|
2841
|
+
el.setAttribute(keys[i], vals[i]);
|
|
2842
|
+
for (let kid of kids) {
|
|
2843
|
+
if (typeof kid === 'string')
|
|
2844
|
+
kid = $mol_dom.document.createTextNode(kid);
|
|
2845
|
+
el.appendChild(kid);
|
|
2846
|
+
}
|
|
2847
|
+
return el;
|
|
2848
|
+
},
|
|
2849
|
+
});
|
|
2850
|
+
$.$mol_vary.type({
|
|
2851
|
+
type: $mol_dom.Comment,
|
|
2852
|
+
keys: ['#comment'],
|
|
2853
|
+
lean: node => [node.nodeValue],
|
|
2854
|
+
rich: ([text]) => $mol_dom.document.createComment(text),
|
|
2855
|
+
});
|
|
2856
|
+
$.$mol_vary.type({
|
|
2857
|
+
type: $mol_dom.ProcessingInstruction,
|
|
2858
|
+
keys: ['target', 'text'],
|
|
2859
|
+
lean: node => [node.nodeName, node.nodeValue],
|
|
2860
|
+
rich: ([target, text]) => $mol_dom.document.createProcessingInstruction(target, text),
|
|
2821
2861
|
});
|
|
2822
|
-
$mol_vary.type($mol_dom.Comment, ['#comment'], node => [node.nodeValue], text => $mol_dom.document.createComment(text));
|
|
2823
|
-
$mol_vary.type($mol_dom.ProcessingInstruction, ['target', 'text'], node => [node.nodeName, node.nodeValue], (target, text) => $mol_dom.document.createProcessingInstruction(target, text));
|
|
2824
2862
|
})($ || ($ = {}));
|
|
2825
2863
|
|
|
2826
2864
|
|