mol_vary 0.0.21 → 0.0.23
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 +11 -10
- package/node.d.ts +476 -3
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +2132 -28
- package/node.js.map +1 -1
- package/node.mjs +2132 -28
- package/node.test.js +3719 -3681
- package/node.test.js.map +1 -1
- package/package.json +55 -3
- package/web.d.ts +14 -3
- package/web.d.ts.map +1 -1
- package/web.deps.json +1 -1
- package/web.js +58 -28
- package/web.js.map +1 -1
- package/web.mjs +58 -28
- package/web.test.js +29 -21
- package/web.test.js.map +1 -1
package/web.mjs
CHANGED
|
@@ -117,27 +117,27 @@ var $;
|
|
|
117
117
|
var $;
|
|
118
118
|
(function ($) {
|
|
119
119
|
function $mol_charset_decode_from(buffer, from, count) {
|
|
120
|
-
|
|
120
|
+
const codes = [];
|
|
121
121
|
let pos = from;
|
|
122
|
-
while (pos < buffer.length &&
|
|
122
|
+
while (pos < buffer.length && codes.length < count) {
|
|
123
123
|
const byte1 = buffer[pos++];
|
|
124
124
|
if (byte1 <= 0x7F) {
|
|
125
|
-
|
|
125
|
+
codes.push(byte1);
|
|
126
126
|
}
|
|
127
127
|
else if ((byte1 & 0xE0) === 0xC0) {
|
|
128
128
|
if (pos >= buffer.length)
|
|
129
129
|
break;
|
|
130
130
|
const byte2 = buffer[pos++];
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
const code = ((byte1 & 0x1F) << 6) | (byte2 & 0x3F);
|
|
132
|
+
codes.push(code);
|
|
133
133
|
}
|
|
134
134
|
else if ((byte1 & 0xF0) === 0xE0) {
|
|
135
135
|
if (pos + 1 >= buffer.length)
|
|
136
136
|
break;
|
|
137
137
|
const byte2 = buffer[pos++];
|
|
138
138
|
const byte3 = buffer[pos++];
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
const code = ((byte1 & 0x0F) << 12) | ((byte2 & 0x3F) << 6) | (byte3 & 0x3F);
|
|
140
|
+
codes.push(code);
|
|
141
141
|
}
|
|
142
142
|
else if ((byte1 & 0xF8) === 0xF0) {
|
|
143
143
|
if (pos + 2 >= buffer.length)
|
|
@@ -150,21 +150,41 @@ var $;
|
|
|
150
150
|
code -= 0x10000;
|
|
151
151
|
const hi = 0xD800 + (code >> 10);
|
|
152
152
|
const lo = 0xDC00 + (code & 0x3FF);
|
|
153
|
-
|
|
153
|
+
codes.push(hi, lo);
|
|
154
154
|
}
|
|
155
155
|
else {
|
|
156
|
-
|
|
156
|
+
codes.push(code);
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
else {
|
|
160
|
-
|
|
160
|
+
codes.push(0xFFFD);
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
return [
|
|
163
|
+
return [String.fromCharCode(...codes), pos - from];
|
|
164
164
|
}
|
|
165
165
|
$.$mol_charset_decode_from = $mol_charset_decode_from;
|
|
166
166
|
})($ || ($ = {}));
|
|
167
167
|
|
|
168
|
+
;
|
|
169
|
+
"use strict";
|
|
170
|
+
var $;
|
|
171
|
+
(function ($) {
|
|
172
|
+
})($ || ($ = {}));
|
|
173
|
+
|
|
174
|
+
;
|
|
175
|
+
"use strict";
|
|
176
|
+
var $;
|
|
177
|
+
(function ($) {
|
|
178
|
+
$.$mol_dom_context = self;
|
|
179
|
+
})($ || ($ = {}));
|
|
180
|
+
|
|
181
|
+
;
|
|
182
|
+
"use strict";
|
|
183
|
+
var $;
|
|
184
|
+
(function ($) {
|
|
185
|
+
$.$mol_dom = $mol_dom_context;
|
|
186
|
+
})($ || ($ = {}));
|
|
187
|
+
|
|
168
188
|
;
|
|
169
189
|
"use strict";
|
|
170
190
|
var $;
|
|
@@ -276,7 +296,7 @@ var $;
|
|
|
276
296
|
pos += 8;
|
|
277
297
|
}
|
|
278
298
|
else {
|
|
279
|
-
$mol_fail(new Error('Number too high', { cause: val }));
|
|
299
|
+
$mol_fail(new Error('Number too high', { cause: { val } }));
|
|
280
300
|
}
|
|
281
301
|
};
|
|
282
302
|
const dump_string = (val) => {
|
|
@@ -347,10 +367,8 @@ var $;
|
|
|
347
367
|
const offset = offsets.get(val);
|
|
348
368
|
if (offset !== undefined)
|
|
349
369
|
return dump_unum($mol_vary_tip.link, offset);
|
|
350
|
-
const
|
|
351
|
-
const
|
|
352
|
-
const keys = lean ? this.keys.get(proto) : Object.keys(val);
|
|
353
|
-
const vals = lean ? lean(val) : Object.values(val);
|
|
370
|
+
const keys = val[$.$mol_vary_keys] ?? Object.keys(val);
|
|
371
|
+
const vals = val[$.$mol_vary_lean]?.(val) ?? Object.values(val);
|
|
354
372
|
dump_unum($mol_vary_tip.tupl, vals.length);
|
|
355
373
|
acquire(vals.length * 2 * 9);
|
|
356
374
|
for (const item of keys)
|
|
@@ -589,22 +607,34 @@ var $;
|
|
|
589
607
|
};
|
|
590
608
|
return read_vary();
|
|
591
609
|
}
|
|
592
|
-
static leanes = new Map();
|
|
593
|
-
static keys = new Map();
|
|
594
610
|
static riches = new Map();
|
|
595
|
-
static type(keys,
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
this.leanes.set(proto, lean);
|
|
600
|
-
this.keys.set(proto, keys);
|
|
601
|
-
this.riches.set(shape, rich);
|
|
611
|
+
static type(Class, keys, lean, rich) {
|
|
612
|
+
this.riches.set(JSON.stringify(keys), rich);
|
|
613
|
+
Class.prototype[$.$mol_vary_lean] = lean;
|
|
614
|
+
Class.prototype[$.$mol_vary_keys] = keys;
|
|
602
615
|
}
|
|
603
616
|
}
|
|
604
617
|
$.$mol_vary = $mol_vary;
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
$mol_vary.type(['
|
|
618
|
+
$.$mol_vary_lean = Symbol.for('$mol_vary_lean');
|
|
619
|
+
$.$mol_vary_keys = Symbol.for('$mol_vary_keys');
|
|
620
|
+
$mol_vary.type(Map, ['keys', 'vals'], obj => [[...obj.keys()], [...obj.values()]], (keys, vals) => new Map(keys.map((k, i) => [k, vals[i]])));
|
|
621
|
+
$mol_vary.type(Set, ['set'], obj => [[...obj.values()]], vals => new Set(vals));
|
|
622
|
+
$mol_vary.type(Date, ['unix_time'], obj => [obj.valueOf() / 1000], ts => new Date(ts * 1000));
|
|
623
|
+
$mol_vary.type($mol_dom.Element, ['elem', 'keys', 'vals', 'kids'], node => {
|
|
624
|
+
const attrs = [...node.attributes];
|
|
625
|
+
const kids = [...node.childNodes].map(kid => kid instanceof $mol_dom.Text ? kid.nodeValue : kid);
|
|
626
|
+
return [node.nodeName, attrs.map(attr => attr.nodeName), attrs.map(attr => attr.nodeValue), kids];
|
|
627
|
+
}, (name, keys, vals, kids) => {
|
|
628
|
+
const el = $mol_dom.document.createElement(name);
|
|
629
|
+
for (let i = 0; i < keys.length; ++i)
|
|
630
|
+
el.setAttribute(keys[i], vals[i]);
|
|
631
|
+
for (let kid of kids) {
|
|
632
|
+
if (typeof kid === 'string')
|
|
633
|
+
kid = $mol_dom.document.createTextNode(kid);
|
|
634
|
+
el.appendChild(kid);
|
|
635
|
+
}
|
|
636
|
+
return el;
|
|
637
|
+
});
|
|
608
638
|
})($ || ($ = {}));
|
|
609
639
|
|
|
610
640
|
|
package/web.test.js
CHANGED
|
@@ -120,26 +120,6 @@ var $;
|
|
|
120
120
|
$.$mol_test_complete = $mol_test_complete;
|
|
121
121
|
})($ || ($ = {}));
|
|
122
122
|
|
|
123
|
-
;
|
|
124
|
-
"use strict";
|
|
125
|
-
var $;
|
|
126
|
-
(function ($) {
|
|
127
|
-
})($ || ($ = {}));
|
|
128
|
-
|
|
129
|
-
;
|
|
130
|
-
"use strict";
|
|
131
|
-
var $;
|
|
132
|
-
(function ($) {
|
|
133
|
-
$.$mol_dom_context = self;
|
|
134
|
-
})($ || ($ = {}));
|
|
135
|
-
|
|
136
|
-
;
|
|
137
|
-
"use strict";
|
|
138
|
-
var $;
|
|
139
|
-
(function ($) {
|
|
140
|
-
$.$mol_dom = $mol_dom_context;
|
|
141
|
-
})($ || ($ = {}));
|
|
142
|
-
|
|
143
123
|
;
|
|
144
124
|
"use strict";
|
|
145
125
|
var $;
|
|
@@ -1634,6 +1614,34 @@ var $;
|
|
|
1634
1614
|
const date2 = new Date('2025-01-02T03:04:05.678');
|
|
1635
1615
|
check(date2, [tupl | 1, text | 9, ...str('unix_time'), fp64, ...new Uint8Array(new Float64Array([date2.valueOf() / 1000]).buffer)]);
|
|
1636
1616
|
},
|
|
1617
|
+
"vary pack Node"($) {
|
|
1618
|
+
check($mol_jsx("span", null), [
|
|
1619
|
+
tupl | 4, text | 4, ...str('elem'), text | 4, ...str('keys'), text | 4, ...str('vals'), text | 4, ...str('kids'),
|
|
1620
|
+
text | 4, ...str('SPAN'), list | 0, list | 0, list | 0
|
|
1621
|
+
]);
|
|
1622
|
+
check($mol_jsx("svg", null), [
|
|
1623
|
+
tupl | 4, text | 4, ...str('elem'), text | 4, ...str('keys'), text | 4, ...str('vals'), text | 4, ...str('kids'),
|
|
1624
|
+
text | 3, ...str('SVG'), list | 0, list | 0, list | 0
|
|
1625
|
+
]);
|
|
1626
|
+
check($mol_jsx("span", { tabIndex: "0" }), [
|
|
1627
|
+
tupl | 4, text | 4, ...str('elem'), text | 4, ...str('keys'), text | 4, ...str('vals'), text | 4, ...str('kids'),
|
|
1628
|
+
text | 4, ...str('SPAN'), list | 1, text | 8, ...str('tabindex'), list | 1, text | 1, ...str('0'), list | 0
|
|
1629
|
+
]);
|
|
1630
|
+
check($mol_jsx("span", null, "text"), [
|
|
1631
|
+
tupl | 4, text | 4, ...str('elem'), text | 4, ...str('keys'), text | 4, ...str('vals'), text | 4, ...str('kids'),
|
|
1632
|
+
text | 4, ...str('SPAN'), list | 0, list | 0, list | 1,
|
|
1633
|
+
text | 4, ...str('text')
|
|
1634
|
+
]);
|
|
1635
|
+
check($mol_jsx("div", null,
|
|
1636
|
+
$mol_jsx("span", null),
|
|
1637
|
+
" "), [
|
|
1638
|
+
tupl | 4, text | 4, ...str('elem'), text | 4, ...str('keys'), text | 4, ...str('vals'), text | 4, ...str('kids'),
|
|
1639
|
+
text | 3, ...str('DIV'), list | 0, list | 0, list | 2,
|
|
1640
|
+
tupl | 4, link | 0, link | 1, link | 2, link | 3,
|
|
1641
|
+
text | 4, ...str('SPAN'), list | 0, list | 0, list | 0,
|
|
1642
|
+
text | 1, ...str(' '),
|
|
1643
|
+
]);
|
|
1644
|
+
},
|
|
1637
1645
|
"vary pack custom class"($) {
|
|
1638
1646
|
class Foo {
|
|
1639
1647
|
a;
|
|
@@ -1647,7 +1655,7 @@ var $;
|
|
|
1647
1655
|
return [this.a, this.b].values();
|
|
1648
1656
|
}
|
|
1649
1657
|
}
|
|
1650
|
-
$mol_vary.type(['a', 'b'], (a = 0, b = 0) => new Foo(a, b)
|
|
1658
|
+
$mol_vary.type(Foo, ['a', 'b'], foo => [foo.a, foo.b], (a = 0, b = 0) => new Foo(a, b));
|
|
1651
1659
|
check(new Foo(1, 2), [tupl | 2, text | 1, ...str('a'), text | 1, ...str('b'), 1, 2]);
|
|
1652
1660
|
},
|
|
1653
1661
|
});
|