com.sweaxizone.w3c.extension 1.0.2 → 1.0.4
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 +4 -1
- package/dist/Chars.d.ts +1 -0
- package/dist/Chars.js +91 -0
- package/dist/E4X.d.ts +1 -0
- package/dist/E4X.js +1 -0
- package/dist/Enum.d.ts +1 -0
- package/dist/Enum.js +2 -1
- package/dist/SAByteArray.js +20 -15
- package/dist/SAEventTarget.d.ts +1 -0
- package/dist/SAEventTarget.js +1 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +21 -7
- package/dist/src/Chars.d.ts +1 -0
- package/dist/src/Chars.js +91 -0
- package/dist/src/E4X.d.ts +1 -0
- package/dist/src/E4X.js +115 -0
- package/dist/src/Enum.d.ts +1 -0
- package/dist/src/Enum.js +21 -0
- package/dist/src/SAByteArray.d.ts +1 -0
- package/dist/src/SAByteArray.js +271 -0
- package/dist/src/SAEventTarget.d.ts +1 -0
- package/dist/src/SAEventTarget.js +36 -0
- package/dist/src/index.d.ts +282 -0
- package/dist/src/index.js +48 -0
- package/dist/test/src/Chars.d.ts +1 -0
- package/dist/test/src/Chars.js +3 -0
- package/dist/test/src/index.d.ts +2 -0
- package/dist/test/src/index.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ ExampleEnum.valueOf(x) // val: number
|
|
|
60
60
|
ExampleEnum.plus("variantA", 1) // 1
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
## Other
|
|
63
|
+
## Other additions
|
|
64
64
|
|
|
65
65
|
- `assert`
|
|
66
66
|
- `AssertionError`
|
|
@@ -73,6 +73,9 @@ ExampleEnum.plus("variantA", 1) // 1
|
|
|
73
73
|
- `isXMLName(argument)` (like E4X's `isXMLName()`)
|
|
74
74
|
- `Namespace` (like E4X's `Namespace`)
|
|
75
75
|
- `QName` (like E4X's `QName`)
|
|
76
|
+
- `Iterator.prototype.length()`
|
|
77
|
+
- `Chars`
|
|
78
|
+
- `String.prototype.chars()`
|
|
76
79
|
|
|
77
80
|
## License
|
|
78
81
|
|
package/dist/Chars.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/Chars.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// Chars
|
|
4
|
+
globalThis.Chars = class Chars extends Iterator {
|
|
5
|
+
_str;
|
|
6
|
+
_length;
|
|
7
|
+
_offset;
|
|
8
|
+
constructor(str, offset = -1) {
|
|
9
|
+
super();
|
|
10
|
+
this._str = str;
|
|
11
|
+
this._length = str.length;
|
|
12
|
+
this._offset = offset == -1 ? 0 : offset;
|
|
13
|
+
}
|
|
14
|
+
get hasRemaining() {
|
|
15
|
+
return this._offset < this._length;
|
|
16
|
+
}
|
|
17
|
+
get reachedEnd() {
|
|
18
|
+
return this._offset >= this._length;
|
|
19
|
+
}
|
|
20
|
+
next() {
|
|
21
|
+
const ch = this._str.codePointAt(this._offset);
|
|
22
|
+
if (ch === undefined) {
|
|
23
|
+
return { done: true, value: 0 };
|
|
24
|
+
}
|
|
25
|
+
if (ch >= 0x10000) {
|
|
26
|
+
this._offset++;
|
|
27
|
+
}
|
|
28
|
+
this._offset++;
|
|
29
|
+
return { done: false, value: ch };
|
|
30
|
+
}
|
|
31
|
+
skipOneInPlace() {
|
|
32
|
+
this.next();
|
|
33
|
+
}
|
|
34
|
+
skipInPlace(count) {
|
|
35
|
+
for (let i = 0; i < count; i++) {
|
|
36
|
+
if (this.next().done) {
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
get index() {
|
|
42
|
+
return this._offset;
|
|
43
|
+
}
|
|
44
|
+
get nextOrZero() {
|
|
45
|
+
const r = this.next();
|
|
46
|
+
return r.done ? 0 : r.value;
|
|
47
|
+
}
|
|
48
|
+
peek() {
|
|
49
|
+
return this._str.codePointAt(this._offset) ?? null;
|
|
50
|
+
}
|
|
51
|
+
peekOrZero() {
|
|
52
|
+
return this._str.codePointAt(this._offset) ?? 0;
|
|
53
|
+
}
|
|
54
|
+
at(index) {
|
|
55
|
+
let offset = this._offset;
|
|
56
|
+
for (let i = 0; i < index; i++) {
|
|
57
|
+
const ch = this._str.codePointAt(offset);
|
|
58
|
+
if (ch === undefined) {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
if (ch >= 0x10000) {
|
|
62
|
+
offset++;
|
|
63
|
+
}
|
|
64
|
+
offset++;
|
|
65
|
+
}
|
|
66
|
+
return this._str.codePointAt(offset) ?? null;
|
|
67
|
+
}
|
|
68
|
+
atOrZero(index) {
|
|
69
|
+
return this.at(index) ?? 0;
|
|
70
|
+
}
|
|
71
|
+
seq(numChars) {
|
|
72
|
+
const r = [];
|
|
73
|
+
let offset = this._offset;
|
|
74
|
+
for (let i = 0; i < numChars; i++) {
|
|
75
|
+
const ch = this._str.codePointAt(offset);
|
|
76
|
+
if (ch === undefined) {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
if (ch >= 0x10000) {
|
|
80
|
+
offset++;
|
|
81
|
+
}
|
|
82
|
+
offset++;
|
|
83
|
+
r.push(String.fromCodePoint(ch));
|
|
84
|
+
}
|
|
85
|
+
return r.join("");
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
// String.prototype.chars()
|
|
89
|
+
String.prototype.chars = function () {
|
|
90
|
+
return new Chars(this);
|
|
91
|
+
};
|
package/dist/E4X.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/E4X.js
CHANGED
package/dist/Enum.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/Enum.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
3
|
globalThis.Enum = function Enum(variants, methods = null) {
|
|
3
4
|
const fn = (key) => key;
|
|
4
5
|
fn.valueOf = (key) => variants[key];
|
|
5
|
-
fn.variants = () =>
|
|
6
|
+
fn.variants = () => Object.keys(variants);
|
|
6
7
|
fn.from = (arg) => {
|
|
7
8
|
if (typeof arg == "string") {
|
|
8
9
|
const v = typeof variants[arg];
|
package/dist/SAByteArray.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const assert_1 = __importDefault(require("assert"));
|
|
2
7
|
//
|
|
3
8
|
const validEndianSet = ["bigEndian", "littleEndian"];
|
|
4
9
|
//
|
|
@@ -11,7 +16,7 @@ globalThis.SAByteArray = class SAByteArray {
|
|
|
11
16
|
m_endian = "bigEndian";
|
|
12
17
|
constructor(initialCapacityArg = undefined) {
|
|
13
18
|
let initialCapacity = initialCapacityArg === undefined ? SAByteArray.INITIAL_CAPACITY : initialCapacityArg;
|
|
14
|
-
|
|
19
|
+
(0, assert_1.default)(initialCapacity >= 2, 'SAByteArray initial capacity must be >= 2.');
|
|
15
20
|
this.m_dataview = new DataView(new ArrayBuffer(initialCapacity));
|
|
16
21
|
this.m_u8array = new Uint8Array(this.m_dataview.buffer);
|
|
17
22
|
}
|
|
@@ -63,7 +68,7 @@ globalThis.SAByteArray = class SAByteArray {
|
|
|
63
68
|
return this.m_endian;
|
|
64
69
|
}
|
|
65
70
|
set endian(val) {
|
|
66
|
-
|
|
71
|
+
(0, assert_1.default)(validEndianSet.indexOf(val) != -1);
|
|
67
72
|
this.m_endian = val;
|
|
68
73
|
}
|
|
69
74
|
get length() {
|
|
@@ -122,7 +127,7 @@ globalThis.SAByteArray = class SAByteArray {
|
|
|
122
127
|
}
|
|
123
128
|
}
|
|
124
129
|
readUnsignedByte() {
|
|
125
|
-
|
|
130
|
+
(0, assert_1.default)(this.m_position < this.m_length, 'Insufficient data available to read.');
|
|
126
131
|
let k = this.m_dataview.getUint8(this.m_position);
|
|
127
132
|
this.m_position += 1;
|
|
128
133
|
return k;
|
|
@@ -133,7 +138,7 @@ globalThis.SAByteArray = class SAByteArray {
|
|
|
133
138
|
this.m_position += 1;
|
|
134
139
|
}
|
|
135
140
|
readByte() {
|
|
136
|
-
|
|
141
|
+
(0, assert_1.default)(this.m_position < this.m_length, 'Insufficient data available to read.');
|
|
137
142
|
let k = this.m_dataview.getInt8(this.m_position);
|
|
138
143
|
this.m_position += 1;
|
|
139
144
|
return k;
|
|
@@ -144,7 +149,7 @@ globalThis.SAByteArray = class SAByteArray {
|
|
|
144
149
|
this.m_position += 1;
|
|
145
150
|
}
|
|
146
151
|
readShort() {
|
|
147
|
-
|
|
152
|
+
(0, assert_1.default)(this.m_position + 2 <= this.m_length, 'Insufficient data available to read.');
|
|
148
153
|
let k = this.m_dataview.getInt16(this.m_position, this.m_endian == "littleEndian");
|
|
149
154
|
this.m_position += 2;
|
|
150
155
|
return k;
|
|
@@ -155,7 +160,7 @@ globalThis.SAByteArray = class SAByteArray {
|
|
|
155
160
|
this.m_position += 2;
|
|
156
161
|
}
|
|
157
162
|
readUnsignedShort() {
|
|
158
|
-
|
|
163
|
+
(0, assert_1.default)(this.m_position + 2 <= this.m_length, 'Insufficient data available to read.');
|
|
159
164
|
let k = this.m_dataview.getUint16(this.m_position, this.m_endian == "littleEndian");
|
|
160
165
|
this.m_position += 2;
|
|
161
166
|
return k;
|
|
@@ -166,7 +171,7 @@ globalThis.SAByteArray = class SAByteArray {
|
|
|
166
171
|
this.m_position += 2;
|
|
167
172
|
}
|
|
168
173
|
readInt() {
|
|
169
|
-
|
|
174
|
+
(0, assert_1.default)(this.m_position + 4 <= this.m_length, 'Insufficient data available to read.');
|
|
170
175
|
let k = this.m_dataview.getInt32(this.m_position, this.m_endian == "littleEndian");
|
|
171
176
|
this.m_position += 4;
|
|
172
177
|
return k;
|
|
@@ -177,7 +182,7 @@ globalThis.SAByteArray = class SAByteArray {
|
|
|
177
182
|
this.m_position += 4;
|
|
178
183
|
}
|
|
179
184
|
readUnsignedInt() {
|
|
180
|
-
|
|
185
|
+
(0, assert_1.default)(this.m_position + 4 <= this.m_length, 'Insufficient data available to read.');
|
|
181
186
|
let k = this.m_dataview.getUint32(this.m_position, this.m_endian == "littleEndian");
|
|
182
187
|
this.m_position += 4;
|
|
183
188
|
return k;
|
|
@@ -188,7 +193,7 @@ globalThis.SAByteArray = class SAByteArray {
|
|
|
188
193
|
this.m_position += 4;
|
|
189
194
|
}
|
|
190
195
|
readLong() {
|
|
191
|
-
|
|
196
|
+
(0, assert_1.default)(this.m_position + 8 <= this.m_length, 'Insufficient data available to read.');
|
|
192
197
|
let k = this.m_dataview.getBigInt64(this.m_position, this.m_endian == "littleEndian");
|
|
193
198
|
this.m_position += 8;
|
|
194
199
|
return k;
|
|
@@ -199,7 +204,7 @@ globalThis.SAByteArray = class SAByteArray {
|
|
|
199
204
|
this.m_position += 8;
|
|
200
205
|
}
|
|
201
206
|
readUnsignedLong() {
|
|
202
|
-
|
|
207
|
+
(0, assert_1.default)(this.m_position + 8 <= this.m_length, 'Insufficient data available to read.');
|
|
203
208
|
let k = this.m_dataview.getBigUint64(this.m_position, this.m_endian == "littleEndian");
|
|
204
209
|
this.m_position += 8;
|
|
205
210
|
return k;
|
|
@@ -210,7 +215,7 @@ globalThis.SAByteArray = class SAByteArray {
|
|
|
210
215
|
this.m_position += 8;
|
|
211
216
|
}
|
|
212
217
|
readFloat() {
|
|
213
|
-
|
|
218
|
+
(0, assert_1.default)(this.m_position + 4 <= this.m_length, 'Insufficient data available to read.');
|
|
214
219
|
let k = this.m_dataview.getFloat32(this.m_position, this.m_endian == "littleEndian");
|
|
215
220
|
this.m_position += 4;
|
|
216
221
|
return k;
|
|
@@ -221,7 +226,7 @@ globalThis.SAByteArray = class SAByteArray {
|
|
|
221
226
|
this.m_position += 4;
|
|
222
227
|
}
|
|
223
228
|
readDouble() {
|
|
224
|
-
|
|
229
|
+
(0, assert_1.default)(this.m_position + 8 <= this.m_length, 'Insufficient data available to read.');
|
|
225
230
|
let k = this.m_dataview.getFloat64(this.m_position, this.m_endian == "littleEndian");
|
|
226
231
|
this.m_position += 8;
|
|
227
232
|
return k;
|
|
@@ -232,7 +237,7 @@ globalThis.SAByteArray = class SAByteArray {
|
|
|
232
237
|
this.m_position += 8;
|
|
233
238
|
}
|
|
234
239
|
readUTF(length) {
|
|
235
|
-
|
|
240
|
+
(0, assert_1.default)(this.m_position + length <= this.m_length, 'Insufficient data available to read.');
|
|
236
241
|
let k = this.m_u8array.subarray(this.m_position, this.m_position + length);
|
|
237
242
|
this.m_position += length;
|
|
238
243
|
return new TextDecoder().decode(k);
|
|
@@ -244,7 +249,7 @@ globalThis.SAByteArray = class SAByteArray {
|
|
|
244
249
|
this.m_position += u8arr.length;
|
|
245
250
|
}
|
|
246
251
|
readBytes(length) {
|
|
247
|
-
|
|
252
|
+
(0, assert_1.default)(this.m_position + length <= this.m_length, 'Insufficient data available to read.');
|
|
248
253
|
let k = this.m_u8array.subarray(this.m_position, this.m_position + length);
|
|
249
254
|
this.m_position += length;
|
|
250
255
|
return SAByteArray.from(k);
|
package/dist/SAEventTarget.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/SAEventTarget.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import "./Enum";
|
|
|
2
2
|
import "./E4X";
|
|
3
3
|
import "./SAEventTarget";
|
|
4
4
|
import "./SAByteArray";
|
|
5
|
+
import "./Chars";
|
|
5
6
|
import impAssert from "assert";
|
|
6
7
|
declare global {
|
|
7
8
|
const assert: typeof import("assert");
|
|
@@ -202,3 +203,80 @@ declare global {
|
|
|
202
203
|
valueOf(): QName;
|
|
203
204
|
}
|
|
204
205
|
}
|
|
206
|
+
declare global {
|
|
207
|
+
interface IteratorObject<T, TReturn, TNext> {
|
|
208
|
+
/**
|
|
209
|
+
* Consumes the iterator and returns the number of
|
|
210
|
+
* iterated entries.
|
|
211
|
+
*/
|
|
212
|
+
length(): number;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
declare global {
|
|
216
|
+
/**
|
|
217
|
+
* `Chars` may be used for iterating characters (as Unicode code points)
|
|
218
|
+
* from left-to-right in a string with miscellaneous operation methods.
|
|
219
|
+
*/
|
|
220
|
+
class Chars extends Iterator<number> {
|
|
221
|
+
/**
|
|
222
|
+
* Constructs a `Chars` iterator over the specified string,
|
|
223
|
+
* at the specified UTF-16 `offset`.
|
|
224
|
+
*/
|
|
225
|
+
constructor(str: string, offset?: number);
|
|
226
|
+
/**
|
|
227
|
+
* Indicates if there are remaining code points to read.
|
|
228
|
+
*/
|
|
229
|
+
get hasRemaining(): boolean;
|
|
230
|
+
/**
|
|
231
|
+
* Indicates if the reader has reached the end of the string.
|
|
232
|
+
*/
|
|
233
|
+
get reachedEnd(): boolean;
|
|
234
|
+
next(): IteratorResult<number>;
|
|
235
|
+
/**
|
|
236
|
+
* Returns the next code point. If there are no code points
|
|
237
|
+
* available, returns U+00.
|
|
238
|
+
*/
|
|
239
|
+
get nextOrZero(): number;
|
|
240
|
+
/**
|
|
241
|
+
* Skips a code point. This is equivalent to
|
|
242
|
+
* calling `next()`.
|
|
243
|
+
*/
|
|
244
|
+
skipOneInPlace(): void;
|
|
245
|
+
/**
|
|
246
|
+
* Skips the given number of code points.
|
|
247
|
+
*/
|
|
248
|
+
skipInPlace(count: number): void;
|
|
249
|
+
/**
|
|
250
|
+
* Returns the current UTF-16 offset in the string.
|
|
251
|
+
*/
|
|
252
|
+
get index(): number;
|
|
253
|
+
/**
|
|
254
|
+
* Peeks the next code point.
|
|
255
|
+
*/
|
|
256
|
+
peek(): null | number;
|
|
257
|
+
/**
|
|
258
|
+
* Peeks the next code point. If there are no code points
|
|
259
|
+
* available, returns U+00.
|
|
260
|
+
*/
|
|
261
|
+
peekOrZero(): number;
|
|
262
|
+
/**
|
|
263
|
+
* Peeks the next code point at the given
|
|
264
|
+
* zero based code point index.
|
|
265
|
+
*/
|
|
266
|
+
at(index: number): null | number;
|
|
267
|
+
/**
|
|
268
|
+
* Peeks the next code point at the given zero based code point index.
|
|
269
|
+
* If there are no code points available, returns U+00.
|
|
270
|
+
*/
|
|
271
|
+
atOrZero(index: number): number;
|
|
272
|
+
/**
|
|
273
|
+
* Peeks a number of code points until the string's end.
|
|
274
|
+
*/
|
|
275
|
+
seq(numChars: number): string;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
declare global {
|
|
279
|
+
interface String {
|
|
280
|
+
chars(): Chars;
|
|
281
|
+
}
|
|
282
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
require("./Enum");
|
|
7
|
+
require("./E4X");
|
|
8
|
+
require("./SAEventTarget");
|
|
9
|
+
require("./SAByteArray");
|
|
10
|
+
require("./Chars");
|
|
11
|
+
const assert_1 = __importDefault(require("assert"));
|
|
6
12
|
// assert
|
|
7
|
-
globalThis.assert =
|
|
8
|
-
globalThis.AssertionError =
|
|
13
|
+
globalThis.assert = assert_1.default;
|
|
14
|
+
globalThis.AssertionError = assert_1.default.AssertionError;
|
|
9
15
|
// trace(), etrace()
|
|
10
16
|
globalThis.trace = console.log;
|
|
11
17
|
globalThis.etrace = console.error;
|
|
@@ -32,3 +38,11 @@ BigInt.max = (...rest) => {
|
|
|
32
38
|
}
|
|
33
39
|
return r;
|
|
34
40
|
};
|
|
41
|
+
// Iterator.length()
|
|
42
|
+
Iterator.prototype.length = function () {
|
|
43
|
+
let n = 0;
|
|
44
|
+
for (const _ of this) {
|
|
45
|
+
n++;
|
|
46
|
+
}
|
|
47
|
+
return n;
|
|
48
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// Chars
|
|
4
|
+
globalThis.Chars = class Chars extends Iterator {
|
|
5
|
+
_str;
|
|
6
|
+
_length;
|
|
7
|
+
_offset;
|
|
8
|
+
constructor(str, offset = -1) {
|
|
9
|
+
super();
|
|
10
|
+
this._str = str;
|
|
11
|
+
this._length = str.length;
|
|
12
|
+
this._offset = offset == -1 ? 0 : offset;
|
|
13
|
+
}
|
|
14
|
+
get hasRemaining() {
|
|
15
|
+
return this._offset < this._length;
|
|
16
|
+
}
|
|
17
|
+
get reachedEnd() {
|
|
18
|
+
return this._offset >= this._length;
|
|
19
|
+
}
|
|
20
|
+
next() {
|
|
21
|
+
const ch = this._str.codePointAt(this._offset);
|
|
22
|
+
if (ch === undefined) {
|
|
23
|
+
return { done: true, value: 0 };
|
|
24
|
+
}
|
|
25
|
+
if (ch >= 0x10000) {
|
|
26
|
+
this._offset++;
|
|
27
|
+
}
|
|
28
|
+
this._offset++;
|
|
29
|
+
return { done: false, value: ch };
|
|
30
|
+
}
|
|
31
|
+
skipOneInPlace() {
|
|
32
|
+
this.next();
|
|
33
|
+
}
|
|
34
|
+
skipInPlace(count) {
|
|
35
|
+
for (let i = 0; i < count; i++) {
|
|
36
|
+
if (this.next().done) {
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
get index() {
|
|
42
|
+
return this._offset;
|
|
43
|
+
}
|
|
44
|
+
get nextOrZero() {
|
|
45
|
+
const r = this.next();
|
|
46
|
+
return r.done ? 0 : r.value;
|
|
47
|
+
}
|
|
48
|
+
peek() {
|
|
49
|
+
return this._str.codePointAt(this._offset) ?? null;
|
|
50
|
+
}
|
|
51
|
+
peekOrZero() {
|
|
52
|
+
return this._str.codePointAt(this._offset) ?? 0;
|
|
53
|
+
}
|
|
54
|
+
at(index) {
|
|
55
|
+
let offset = this._offset;
|
|
56
|
+
for (let i = 0; i < index; i++) {
|
|
57
|
+
const ch = this._str.codePointAt(offset);
|
|
58
|
+
if (ch === undefined) {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
if (ch >= 0x10000) {
|
|
62
|
+
offset++;
|
|
63
|
+
}
|
|
64
|
+
offset++;
|
|
65
|
+
}
|
|
66
|
+
return this._str.codePointAt(offset) ?? null;
|
|
67
|
+
}
|
|
68
|
+
atOrZero(index) {
|
|
69
|
+
return this.at(index) ?? 0;
|
|
70
|
+
}
|
|
71
|
+
seq(numChars) {
|
|
72
|
+
const r = [];
|
|
73
|
+
let offset = this._offset;
|
|
74
|
+
for (let i = 0; i < numChars; i++) {
|
|
75
|
+
const ch = this._str.codePointAt(offset);
|
|
76
|
+
if (ch === undefined) {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
if (ch >= 0x10000) {
|
|
80
|
+
offset++;
|
|
81
|
+
}
|
|
82
|
+
offset++;
|
|
83
|
+
r.push(String.fromCodePoint(ch));
|
|
84
|
+
}
|
|
85
|
+
return r.join("");
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
// String.prototype.chars()
|
|
89
|
+
String.prototype.chars = function () {
|
|
90
|
+
return new Chars(this);
|
|
91
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/src/E4X.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// isXMLName
|
|
4
|
+
function isXMLName(argument) {
|
|
5
|
+
argument = String(argument);
|
|
6
|
+
return /[a-z_][a-z_0-9.\-]*/i.test(argument);
|
|
7
|
+
}
|
|
8
|
+
globalThis.isXMLName = isXMLName;
|
|
9
|
+
// Namespace
|
|
10
|
+
globalThis.Namespace = class Namespace {
|
|
11
|
+
_prefix = "";
|
|
12
|
+
_uri = "";
|
|
13
|
+
// Namespace(uri:*)
|
|
14
|
+
// Namespace(prefix:*, uri:*)
|
|
15
|
+
constructor(arg1 = undefined, arg2 = undefined) {
|
|
16
|
+
if (arg2 === undefined || arg2 === null) {
|
|
17
|
+
if (arg1 instanceof Namespace) {
|
|
18
|
+
this._uri = arg1.uri;
|
|
19
|
+
}
|
|
20
|
+
else if (arg1 instanceof QName) {
|
|
21
|
+
this._uri = arg1.uri ?? "";
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
this._uri = String(arg1);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
// arg1 = prefixValue
|
|
29
|
+
if (arg1 === undefined && !isXMLName(arg1)) {
|
|
30
|
+
this._prefix = "undefined";
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
this._prefix = String(arg1);
|
|
34
|
+
}
|
|
35
|
+
// arg2 = uriValue
|
|
36
|
+
if (arg2 instanceof QName) {
|
|
37
|
+
this._uri = arg2.uri ?? "";
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this._uri = String(arg2);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
get prefix() {
|
|
45
|
+
return this._prefix;
|
|
46
|
+
}
|
|
47
|
+
set prefix(val) {
|
|
48
|
+
this._prefix = String(val);
|
|
49
|
+
}
|
|
50
|
+
get uri() {
|
|
51
|
+
return this._uri;
|
|
52
|
+
}
|
|
53
|
+
set uri(val) {
|
|
54
|
+
this._uri = String(val);
|
|
55
|
+
}
|
|
56
|
+
toString() {
|
|
57
|
+
return this._uri;
|
|
58
|
+
}
|
|
59
|
+
valueOf() {
|
|
60
|
+
return this._uri;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
// QName
|
|
64
|
+
globalThis.QName = class QName {
|
|
65
|
+
_uri = null;
|
|
66
|
+
_localName = "";
|
|
67
|
+
// QName(qname:*)
|
|
68
|
+
// QName(uri:*, localName:*)
|
|
69
|
+
constructor(arg1 = undefined, arg2 = undefined) {
|
|
70
|
+
// QName(qname:*)
|
|
71
|
+
if (arg2 === undefined || arg2 === null) {
|
|
72
|
+
if (arg1 === undefined || arg1 === null) {
|
|
73
|
+
this._localName = "";
|
|
74
|
+
}
|
|
75
|
+
else if (arg1 instanceof QName) {
|
|
76
|
+
this._uri = arg1.uri;
|
|
77
|
+
this._localName = arg1.localName;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
this._localName = String(arg1);
|
|
81
|
+
}
|
|
82
|
+
// QName(uri:*, localName:*)
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
if (arg1 !== undefined && arg1 !== null) {
|
|
86
|
+
if (arg1 instanceof Namespace) {
|
|
87
|
+
this._uri = arg1.uri;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
this._uri = String(arg1);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (arg2 instanceof QName) {
|
|
94
|
+
this._localName = arg2.localName;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
this._localName = String(arg2);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
get localName() {
|
|
102
|
+
return this._localName;
|
|
103
|
+
}
|
|
104
|
+
// null = wildcard (*)
|
|
105
|
+
get uri() {
|
|
106
|
+
return this._uri;
|
|
107
|
+
}
|
|
108
|
+
toString() {
|
|
109
|
+
const { uri, localName } = this;
|
|
110
|
+
return uri === "" ? localName : uri === null ? "*::" + localName : uri + "::" + localName;
|
|
111
|
+
}
|
|
112
|
+
valueOf() {
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/src/Enum.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
globalThis.Enum = function Enum(variants, methods = null) {
|
|
4
|
+
const fn = (key) => key;
|
|
5
|
+
fn.valueOf = (key) => variants[key];
|
|
6
|
+
fn.variants = () => Object.keys(variants);
|
|
7
|
+
fn.from = (arg) => {
|
|
8
|
+
if (typeof arg == "string") {
|
|
9
|
+
const v = typeof variants[arg];
|
|
10
|
+
return v == "number" || v == "bigint" ? arg : null;
|
|
11
|
+
}
|
|
12
|
+
if (typeof arg == "number" || typeof arg == "bigint") {
|
|
13
|
+
return Object.entries(variants).find(([k, v]) => v === arg)?.[0] ?? null;
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
};
|
|
17
|
+
if (methods) {
|
|
18
|
+
Object.assign(fn, methods);
|
|
19
|
+
}
|
|
20
|
+
return fn;
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const assert_1 = __importDefault(require("assert"));
|
|
7
|
+
//
|
|
8
|
+
const validEndianSet = ["bigEndian", "littleEndian"];
|
|
9
|
+
//
|
|
10
|
+
globalThis.SAByteArray = class SAByteArray {
|
|
11
|
+
static INITIAL_CAPACITY = 8;
|
|
12
|
+
m_dataview;
|
|
13
|
+
m_u8array;
|
|
14
|
+
m_position = 0;
|
|
15
|
+
m_length = 0;
|
|
16
|
+
m_endian = "bigEndian";
|
|
17
|
+
constructor(initialCapacityArg = undefined) {
|
|
18
|
+
let initialCapacity = initialCapacityArg === undefined ? SAByteArray.INITIAL_CAPACITY : initialCapacityArg;
|
|
19
|
+
(0, assert_1.default)(initialCapacity >= 2, 'SAByteArray initial capacity must be >= 2.');
|
|
20
|
+
this.m_dataview = new DataView(new ArrayBuffer(initialCapacity));
|
|
21
|
+
this.m_u8array = new Uint8Array(this.m_dataview.buffer);
|
|
22
|
+
}
|
|
23
|
+
static withCapacity(bytes) {
|
|
24
|
+
return new SAByteArray(bytes);
|
|
25
|
+
}
|
|
26
|
+
static zeroes(length) {
|
|
27
|
+
const r = new SAByteArray();
|
|
28
|
+
r.m_dataview = new DataView(new ArrayBuffer(Math.max(2, length >> 0)));
|
|
29
|
+
r.m_u8array = new Uint8Array(r.m_dataview.buffer);
|
|
30
|
+
r.m_length = length;
|
|
31
|
+
return r;
|
|
32
|
+
}
|
|
33
|
+
static from(arg) {
|
|
34
|
+
const r = new SAByteArray();
|
|
35
|
+
if (arg instanceof SAByteArray) {
|
|
36
|
+
r.m_dataview = new DataView(arg.m_dataview.buffer.slice(0));
|
|
37
|
+
r.m_u8array = new Uint8Array(r.m_dataview.buffer);
|
|
38
|
+
r.m_length = arg.m_length;
|
|
39
|
+
return r;
|
|
40
|
+
}
|
|
41
|
+
r.m_dataview = new DataView(arg instanceof Uint8Array ? arg.buffer : arg);
|
|
42
|
+
r.m_u8array = new Uint8Array(r.m_dataview.buffer);
|
|
43
|
+
r.m_length = r.m_dataview.byteLength;
|
|
44
|
+
return r;
|
|
45
|
+
}
|
|
46
|
+
clone() {
|
|
47
|
+
return SAByteArray.from(this);
|
|
48
|
+
}
|
|
49
|
+
toArrayBuffer() {
|
|
50
|
+
return this.m_dataview.buffer;
|
|
51
|
+
}
|
|
52
|
+
toBuffer() {
|
|
53
|
+
return Buffer.from(this.m_dataview.buffer.slice(0));
|
|
54
|
+
}
|
|
55
|
+
equals(other) {
|
|
56
|
+
const l = this.m_length;
|
|
57
|
+
if (l != other.m_length) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
for (let i = 0; i < l; i++) {
|
|
61
|
+
if (this.m_u8array[i] != other.m_u8array[i]) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
get endian() {
|
|
68
|
+
return this.m_endian;
|
|
69
|
+
}
|
|
70
|
+
set endian(val) {
|
|
71
|
+
(0, assert_1.default)(validEndianSet.indexOf(val) != -1);
|
|
72
|
+
this.m_endian = val;
|
|
73
|
+
}
|
|
74
|
+
get length() {
|
|
75
|
+
return this.m_length >>> 0;
|
|
76
|
+
}
|
|
77
|
+
set length(val) {
|
|
78
|
+
this.m_length = Math.min(Math.max(0, val >>> 0), this.m_length);
|
|
79
|
+
}
|
|
80
|
+
get position() {
|
|
81
|
+
return this.m_position >>> 0;
|
|
82
|
+
}
|
|
83
|
+
set position(val) {
|
|
84
|
+
this.m_position = Math.min(Math.max(val >>> 0, 0), this.m_length);
|
|
85
|
+
}
|
|
86
|
+
get bytesAvailable() {
|
|
87
|
+
return this.length - this.position;
|
|
88
|
+
}
|
|
89
|
+
get hasRemaining() {
|
|
90
|
+
return this.position < this.length;
|
|
91
|
+
}
|
|
92
|
+
get(position) {
|
|
93
|
+
return position < this.m_length ? this.m_u8array[position] : 0;
|
|
94
|
+
}
|
|
95
|
+
set(position, val) {
|
|
96
|
+
if (position >= this.m_length) {
|
|
97
|
+
throw new RangeError("Index is out of bounds (index=" + position + ", length=" + this.m_length + ")");
|
|
98
|
+
}
|
|
99
|
+
this.m_u8array[position] = val >>> 0;
|
|
100
|
+
}
|
|
101
|
+
paygrow(length) {
|
|
102
|
+
const ipl = this.m_position + length;
|
|
103
|
+
// double buffer capacity as needed
|
|
104
|
+
while (ipl > this.m_dataview.byteLength) {
|
|
105
|
+
const arraybuf = new ArrayBuffer(this.m_dataview.byteLength * 2);
|
|
106
|
+
this.m_dataview = new DataView(arraybuf);
|
|
107
|
+
const k = this.m_u8array;
|
|
108
|
+
this.m_u8array = new Uint8Array(arraybuf);
|
|
109
|
+
this.m_u8array.set(k.subarray(0, this.m_length));
|
|
110
|
+
}
|
|
111
|
+
const newBytes = -(this.m_length - ipl);
|
|
112
|
+
this.m_length += Math.max(0, newBytes);
|
|
113
|
+
}
|
|
114
|
+
*[Symbol.iterator]() {
|
|
115
|
+
for (let i = 0; i < this.m_length; i++) {
|
|
116
|
+
yield this.m_u8array[i];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
*keys() {
|
|
120
|
+
for (let i = 0; i < this.m_length; i++) {
|
|
121
|
+
yield i;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
*values() {
|
|
125
|
+
for (let i = 0; i < this.m_length; i++) {
|
|
126
|
+
yield this.m_u8array[i];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
readUnsignedByte() {
|
|
130
|
+
(0, assert_1.default)(this.m_position < this.m_length, 'Insufficient data available to read.');
|
|
131
|
+
let k = this.m_dataview.getUint8(this.m_position);
|
|
132
|
+
this.m_position += 1;
|
|
133
|
+
return k;
|
|
134
|
+
}
|
|
135
|
+
writeUnsignedByte(value) {
|
|
136
|
+
this.paygrow(1);
|
|
137
|
+
this.m_dataview.setUint8(this.m_position, value);
|
|
138
|
+
this.m_position += 1;
|
|
139
|
+
}
|
|
140
|
+
readByte() {
|
|
141
|
+
(0, assert_1.default)(this.m_position < this.m_length, 'Insufficient data available to read.');
|
|
142
|
+
let k = this.m_dataview.getInt8(this.m_position);
|
|
143
|
+
this.m_position += 1;
|
|
144
|
+
return k;
|
|
145
|
+
}
|
|
146
|
+
writeByte(value) {
|
|
147
|
+
this.paygrow(1);
|
|
148
|
+
this.m_dataview.setInt8(this.m_position, value);
|
|
149
|
+
this.m_position += 1;
|
|
150
|
+
}
|
|
151
|
+
readShort() {
|
|
152
|
+
(0, assert_1.default)(this.m_position + 2 <= this.m_length, 'Insufficient data available to read.');
|
|
153
|
+
let k = this.m_dataview.getInt16(this.m_position, this.m_endian == "littleEndian");
|
|
154
|
+
this.m_position += 2;
|
|
155
|
+
return k;
|
|
156
|
+
}
|
|
157
|
+
writeShort(value) {
|
|
158
|
+
this.paygrow(2);
|
|
159
|
+
this.m_dataview.setInt16(this.m_position, value, this.m_endian == "littleEndian");
|
|
160
|
+
this.m_position += 2;
|
|
161
|
+
}
|
|
162
|
+
readUnsignedShort() {
|
|
163
|
+
(0, assert_1.default)(this.m_position + 2 <= this.m_length, 'Insufficient data available to read.');
|
|
164
|
+
let k = this.m_dataview.getUint16(this.m_position, this.m_endian == "littleEndian");
|
|
165
|
+
this.m_position += 2;
|
|
166
|
+
return k;
|
|
167
|
+
}
|
|
168
|
+
writeUnsignedShort(value) {
|
|
169
|
+
this.paygrow(2);
|
|
170
|
+
this.m_dataview.setUint16(this.m_position, value, this.m_endian == "littleEndian");
|
|
171
|
+
this.m_position += 2;
|
|
172
|
+
}
|
|
173
|
+
readInt() {
|
|
174
|
+
(0, assert_1.default)(this.m_position + 4 <= this.m_length, 'Insufficient data available to read.');
|
|
175
|
+
let k = this.m_dataview.getInt32(this.m_position, this.m_endian == "littleEndian");
|
|
176
|
+
this.m_position += 4;
|
|
177
|
+
return k;
|
|
178
|
+
}
|
|
179
|
+
writeInt(value) {
|
|
180
|
+
this.paygrow(4);
|
|
181
|
+
this.m_dataview.setInt32(this.m_position, value, this.m_endian == "littleEndian");
|
|
182
|
+
this.m_position += 4;
|
|
183
|
+
}
|
|
184
|
+
readUnsignedInt() {
|
|
185
|
+
(0, assert_1.default)(this.m_position + 4 <= this.m_length, 'Insufficient data available to read.');
|
|
186
|
+
let k = this.m_dataview.getUint32(this.m_position, this.m_endian == "littleEndian");
|
|
187
|
+
this.m_position += 4;
|
|
188
|
+
return k;
|
|
189
|
+
}
|
|
190
|
+
writeUnsignedInt(value) {
|
|
191
|
+
this.paygrow(4);
|
|
192
|
+
this.m_dataview.setUint32(this.m_position, value, this.m_endian == "littleEndian");
|
|
193
|
+
this.m_position += 4;
|
|
194
|
+
}
|
|
195
|
+
readLong() {
|
|
196
|
+
(0, assert_1.default)(this.m_position + 8 <= this.m_length, 'Insufficient data available to read.');
|
|
197
|
+
let k = this.m_dataview.getBigInt64(this.m_position, this.m_endian == "littleEndian");
|
|
198
|
+
this.m_position += 8;
|
|
199
|
+
return k;
|
|
200
|
+
}
|
|
201
|
+
writeLong(value) {
|
|
202
|
+
this.paygrow(8);
|
|
203
|
+
this.m_dataview.setBigInt64(this.m_position, value, this.m_endian == "littleEndian");
|
|
204
|
+
this.m_position += 8;
|
|
205
|
+
}
|
|
206
|
+
readUnsignedLong() {
|
|
207
|
+
(0, assert_1.default)(this.m_position + 8 <= this.m_length, 'Insufficient data available to read.');
|
|
208
|
+
let k = this.m_dataview.getBigUint64(this.m_position, this.m_endian == "littleEndian");
|
|
209
|
+
this.m_position += 8;
|
|
210
|
+
return k;
|
|
211
|
+
}
|
|
212
|
+
writeUnsignedLong(value) {
|
|
213
|
+
this.paygrow(8);
|
|
214
|
+
this.m_dataview.setBigUint64(this.m_position, value, this.m_endian == "littleEndian");
|
|
215
|
+
this.m_position += 8;
|
|
216
|
+
}
|
|
217
|
+
readFloat() {
|
|
218
|
+
(0, assert_1.default)(this.m_position + 4 <= this.m_length, 'Insufficient data available to read.');
|
|
219
|
+
let k = this.m_dataview.getFloat32(this.m_position, this.m_endian == "littleEndian");
|
|
220
|
+
this.m_position += 4;
|
|
221
|
+
return k;
|
|
222
|
+
}
|
|
223
|
+
writeFloat(value) {
|
|
224
|
+
this.paygrow(4);
|
|
225
|
+
this.m_dataview.setFloat32(this.m_position, value, this.m_endian == "littleEndian");
|
|
226
|
+
this.m_position += 4;
|
|
227
|
+
}
|
|
228
|
+
readDouble() {
|
|
229
|
+
(0, assert_1.default)(this.m_position + 8 <= this.m_length, 'Insufficient data available to read.');
|
|
230
|
+
let k = this.m_dataview.getFloat64(this.m_position, this.m_endian == "littleEndian");
|
|
231
|
+
this.m_position += 8;
|
|
232
|
+
return k;
|
|
233
|
+
}
|
|
234
|
+
writeDouble(value) {
|
|
235
|
+
this.paygrow(8);
|
|
236
|
+
this.m_dataview.setFloat64(this.m_position, value, this.m_endian == "littleEndian");
|
|
237
|
+
this.m_position += 8;
|
|
238
|
+
}
|
|
239
|
+
readUTF(length) {
|
|
240
|
+
(0, assert_1.default)(this.m_position + length <= this.m_length, 'Insufficient data available to read.');
|
|
241
|
+
let k = this.m_u8array.subarray(this.m_position, this.m_position + length);
|
|
242
|
+
this.m_position += length;
|
|
243
|
+
return new TextDecoder().decode(k);
|
|
244
|
+
}
|
|
245
|
+
writeUTF(value) {
|
|
246
|
+
var u8arr = new TextEncoder().encode(value);
|
|
247
|
+
this.paygrow(u8arr.length);
|
|
248
|
+
this.m_u8array.set(u8arr, this.m_position);
|
|
249
|
+
this.m_position += u8arr.length;
|
|
250
|
+
}
|
|
251
|
+
readBytes(length) {
|
|
252
|
+
(0, assert_1.default)(this.m_position + length <= this.m_length, 'Insufficient data available to read.');
|
|
253
|
+
let k = this.m_u8array.subarray(this.m_position, this.m_position + length);
|
|
254
|
+
this.m_position += length;
|
|
255
|
+
return SAByteArray.from(k);
|
|
256
|
+
}
|
|
257
|
+
writeBytes(value) {
|
|
258
|
+
const u8arr = value.m_u8array;
|
|
259
|
+
this.paygrow(u8arr.length);
|
|
260
|
+
this.m_u8array.set(u8arr, this.m_position);
|
|
261
|
+
;
|
|
262
|
+
this.m_position += u8arr.length;
|
|
263
|
+
}
|
|
264
|
+
clear() {
|
|
265
|
+
this.m_position = 0;
|
|
266
|
+
this.m_length = 0;
|
|
267
|
+
const arraybuf = new ArrayBuffer(SAByteArray.INITIAL_CAPACITY);
|
|
268
|
+
this.m_dataview = new DataView(arraybuf);
|
|
269
|
+
this.m_u8array = new Uint8Array(arraybuf);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// EventRecord
|
|
4
|
+
globalThis.EventRecord = Symbol("http://sweaxizone.com/javascript/EventRecord");
|
|
5
|
+
// SAEventTarget
|
|
6
|
+
globalThis.SAEventTarget = class SAEventTarget {
|
|
7
|
+
//
|
|
8
|
+
m_eventTarget = new globalThis.EventTarget();
|
|
9
|
+
//
|
|
10
|
+
on(type, listener, options = undefined) {
|
|
11
|
+
const new_options = typeof options == "object"
|
|
12
|
+
? { capture: options.capture }
|
|
13
|
+
: options;
|
|
14
|
+
this.m_eventTarget.addEventListener(type, listener, new_options);
|
|
15
|
+
}
|
|
16
|
+
//
|
|
17
|
+
off(type, listener, options = undefined) {
|
|
18
|
+
const new_options = typeof options == "object"
|
|
19
|
+
? { capture: options.capture }
|
|
20
|
+
: options;
|
|
21
|
+
this.m_eventTarget.removeEventListener(type, listener, new_options);
|
|
22
|
+
}
|
|
23
|
+
//
|
|
24
|
+
emit(arg1, arg2, arg3) {
|
|
25
|
+
let event = null;
|
|
26
|
+
if (arg1 instanceof Event) {
|
|
27
|
+
event = arg1;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
event = typeof arg3 !== "undefined" ?
|
|
31
|
+
new arg2(arg1, arg3) :
|
|
32
|
+
new arg2(arg1);
|
|
33
|
+
}
|
|
34
|
+
return this.m_eventTarget.dispatchEvent(event);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import "./Enum";
|
|
2
|
+
import "./E4X";
|
|
3
|
+
import "./SAEventTarget";
|
|
4
|
+
import "./SAByteArray";
|
|
5
|
+
import "./Chars";
|
|
6
|
+
import impAssert from "assert";
|
|
7
|
+
declare global {
|
|
8
|
+
const assert: typeof import("assert");
|
|
9
|
+
class AssertionError extends impAssert.AssertionError {
|
|
10
|
+
}
|
|
11
|
+
type AssertPredicate = impAssert.AssertPredicate;
|
|
12
|
+
}
|
|
13
|
+
declare global {
|
|
14
|
+
/**
|
|
15
|
+
* Used to declare known compile-time events
|
|
16
|
+
* for a class that extends `EventTarget` or
|
|
17
|
+
* implements `IEventTarget`.
|
|
18
|
+
*/
|
|
19
|
+
const EventRecord: unique symbol;
|
|
20
|
+
/**
|
|
21
|
+
* `SAEventTarget` stands for Short-Augmented Event Target.
|
|
22
|
+
*/
|
|
23
|
+
class SAEventTarget implements ISAEventTarget {
|
|
24
|
+
[EventRecord]: {};
|
|
25
|
+
on<K extends keyof this[typeof EventRecord]>(type: K, listener: (e: this[typeof EventRecord][K] extends Event ? this[typeof EventRecord][K] : never) => void | undefined, options?: boolean | SAOnEventOptions): void;
|
|
26
|
+
on(type: string, listener: (e: Event) => void | undefined, options?: boolean | SAOnEventOptions): void;
|
|
27
|
+
off<K extends keyof this[typeof EventRecord]>(type: K, listener: (e: this[typeof EventRecord][K] extends Event ? this[typeof EventRecord][K] : never) => void | undefined, options?: boolean | SAOffEventOptions): void;
|
|
28
|
+
off(type: string, listener: (e: Event) => void | undefined, options?: boolean | SAOffEventOptions): void;
|
|
29
|
+
emit<K extends string & keyof this[typeof EventRecord], C extends (new (type: K) => EventResult), EventResult extends this[typeof EventRecord][K]>(type: K, constructor: C): boolean;
|
|
30
|
+
emit<K extends string & keyof this[typeof EventRecord], C extends (new (type: K, options: O) => EventResult), O, EventResult extends this[typeof EventRecord][K]>(type: K, constructor: C, options: O): boolean;
|
|
31
|
+
emit(event: Event): boolean;
|
|
32
|
+
}
|
|
33
|
+
interface ISAEventTarget {
|
|
34
|
+
[EventRecord]: {};
|
|
35
|
+
on<K extends keyof this[typeof EventRecord]>(type: K, listener: (e: this[typeof EventRecord][K] extends Event ? this[typeof EventRecord][K] : never) => void | undefined, options?: boolean | SAOnEventOptions): void;
|
|
36
|
+
on(type: string, listener: (e: Event) => void | undefined, options?: boolean | SAOnEventOptions): void;
|
|
37
|
+
off<K extends keyof this[typeof EventRecord]>(type: K, listener: (e: this[typeof EventRecord][K] extends Event ? this[typeof EventRecord][K] : never) => void | undefined, options?: boolean | SAOffEventOptions): void;
|
|
38
|
+
off(type: string, listener: (e: Event) => void | undefined, options?: boolean | SAOffEventOptions): void;
|
|
39
|
+
emit<K extends string & keyof this[typeof EventRecord], C extends (new (type: K) => EventResult), EventResult extends this[typeof EventRecord][K]>(type: K, constructor: C): boolean;
|
|
40
|
+
emit<K extends string & keyof this[typeof EventRecord], C extends (new (type: K, options: O) => EventResult), O, EventResult extends this[typeof EventRecord][K]>(type: K, constructor: C, options: O): boolean;
|
|
41
|
+
emit(event: Event): boolean;
|
|
42
|
+
}
|
|
43
|
+
type SAOnEventOptions = {
|
|
44
|
+
capture?: boolean;
|
|
45
|
+
};
|
|
46
|
+
type SAOffEventOptions = {
|
|
47
|
+
capture?: boolean;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
declare global {
|
|
51
|
+
/**
|
|
52
|
+
* Simple enumerations with number-to-string mapping and vice-versa,
|
|
53
|
+
* as well as the ability to add documentation comments to
|
|
54
|
+
* variants.
|
|
55
|
+
*/
|
|
56
|
+
function Enum<K extends string, V extends number | bigint, UserMethods>(variants: Record<K, V>, methods?: UserMethods): EnumType<K, V, UserMethods>;
|
|
57
|
+
type EnumType<K, V, UserMethods> = {
|
|
58
|
+
(key: K): K;
|
|
59
|
+
from(arg: string | number | bigint): null | K;
|
|
60
|
+
valueOf(key: K): V;
|
|
61
|
+
variants(): K[];
|
|
62
|
+
} & (UserMethods extends object ? UserMethods : {});
|
|
63
|
+
}
|
|
64
|
+
declare global {
|
|
65
|
+
const trace: typeof console.log;
|
|
66
|
+
const etrace: typeof console.error;
|
|
67
|
+
}
|
|
68
|
+
declare global {
|
|
69
|
+
interface Math {
|
|
70
|
+
/**
|
|
71
|
+
* Clamps value to specified range (inclusive on both ends).
|
|
72
|
+
*/
|
|
73
|
+
clamp(val: number, from: number, to: number): number;
|
|
74
|
+
/**
|
|
75
|
+
* Clamps value to specified range (inclusive on both ends).
|
|
76
|
+
*/
|
|
77
|
+
clamp(val: bigint, from: bigint, to: bigint): bigint;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
declare global {
|
|
81
|
+
interface BigIntConstructor {
|
|
82
|
+
min(...rest: bigint[]): bigint;
|
|
83
|
+
max(...rest: bigint[]): bigint;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
declare global {
|
|
87
|
+
type Endian = "littleEndian" | "bigEndian";
|
|
88
|
+
class SAByteArray implements ISADataInput, ISADataOutput {
|
|
89
|
+
constructor(initialCapacity?: number);
|
|
90
|
+
static withCapacity(bytes: number): SAByteArray;
|
|
91
|
+
static zeroes(length: number): SAByteArray;
|
|
92
|
+
static from(argument: SAByteArray | Uint8Array | ArrayBuffer | SharedArrayBuffer): SAByteArray;
|
|
93
|
+
clone(): SAByteArray;
|
|
94
|
+
toArrayBuffer(): ArrayBuffer;
|
|
95
|
+
/**
|
|
96
|
+
* *Applies to the Node.js runtime.*
|
|
97
|
+
*/
|
|
98
|
+
toBuffer(): Buffer;
|
|
99
|
+
equals(other: SAByteArray): boolean;
|
|
100
|
+
get endian(): Endian;
|
|
101
|
+
set endian(val: Endian);
|
|
102
|
+
get length(): number;
|
|
103
|
+
set length(val: number);
|
|
104
|
+
get position(): number;
|
|
105
|
+
set position(val: number);
|
|
106
|
+
get bytesAvailable(): number;
|
|
107
|
+
get hasRemaining(): boolean;
|
|
108
|
+
get(position: number): number;
|
|
109
|
+
set(position: number, val: number): void;
|
|
110
|
+
[Symbol.iterator](): Iterator<number>;
|
|
111
|
+
keys(): Iterator<number>;
|
|
112
|
+
values(): Iterator<number>;
|
|
113
|
+
readUnsignedByte(): number;
|
|
114
|
+
writeUnsignedByte(value: number): void;
|
|
115
|
+
readByte(): number;
|
|
116
|
+
writeByte(value: number): void;
|
|
117
|
+
readShort(): number;
|
|
118
|
+
writeShort(value: number): void;
|
|
119
|
+
readUnsignedShort(): number;
|
|
120
|
+
writeUnsignedShort(value: number): void;
|
|
121
|
+
readInt(): number;
|
|
122
|
+
writeInt(value: number): void;
|
|
123
|
+
readUnsignedInt(): number;
|
|
124
|
+
writeUnsignedInt(value: number): void;
|
|
125
|
+
readLong(): bigint;
|
|
126
|
+
writeLong(value: bigint): void;
|
|
127
|
+
readUnsignedLong(): bigint;
|
|
128
|
+
writeUnsignedLong(value: bigint): void;
|
|
129
|
+
readFloat(): number;
|
|
130
|
+
writeFloat(value: number): void;
|
|
131
|
+
readDouble(): number;
|
|
132
|
+
writeDouble(value: number): void;
|
|
133
|
+
readUTF(length: number): string;
|
|
134
|
+
writeUTF(value: string): void;
|
|
135
|
+
readBytes(length: number): SAByteArray;
|
|
136
|
+
writeBytes(value: SAByteArray): void;
|
|
137
|
+
clear(): void;
|
|
138
|
+
}
|
|
139
|
+
interface ISADataInput {
|
|
140
|
+
get endian(): Endian;
|
|
141
|
+
set endian(val: Endian);
|
|
142
|
+
get bytesAvailable(): number;
|
|
143
|
+
get hasRemaining(): boolean;
|
|
144
|
+
readUnsignedByte(): number;
|
|
145
|
+
readByte(): number;
|
|
146
|
+
readShort(): number;
|
|
147
|
+
readUnsignedShort(): number;
|
|
148
|
+
readInt(): number;
|
|
149
|
+
readUnsignedInt(): number;
|
|
150
|
+
readLong(): bigint;
|
|
151
|
+
readUnsignedLong(): bigint;
|
|
152
|
+
readFloat(): number;
|
|
153
|
+
readDouble(): number;
|
|
154
|
+
readUTF(length: number): string;
|
|
155
|
+
readBytes(length: number): SAByteArray;
|
|
156
|
+
}
|
|
157
|
+
interface ISADataOutput {
|
|
158
|
+
get endian(): Endian;
|
|
159
|
+
set endian(val: Endian);
|
|
160
|
+
writeUnsignedByte(value: number): void;
|
|
161
|
+
writeByte(value: number): void;
|
|
162
|
+
writeShort(value: number): void;
|
|
163
|
+
writeUnsignedShort(value: number): void;
|
|
164
|
+
writeInt(value: number): void;
|
|
165
|
+
writeUnsignedInt(value: number): void;
|
|
166
|
+
writeLong(value: bigint): void;
|
|
167
|
+
writeUnsignedLong(value: bigint): void;
|
|
168
|
+
writeFloat(value: number): void;
|
|
169
|
+
writeDouble(value: number): void;
|
|
170
|
+
writeUTF(value: string): void;
|
|
171
|
+
writeBytes(value: SAByteArray): void;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
declare global {
|
|
175
|
+
function isXMLName(argument: string): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Represents a XML namespace.
|
|
178
|
+
*/
|
|
179
|
+
class Namespace {
|
|
180
|
+
constructor(uri: string | Namespace | QName);
|
|
181
|
+
constructor(prefix: string, uri: string | QName);
|
|
182
|
+
get prefix(): string;
|
|
183
|
+
set prefix(val: string);
|
|
184
|
+
get uri(): string;
|
|
185
|
+
set uri(val: string);
|
|
186
|
+
toString(): string;
|
|
187
|
+
valueOf(): string;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Represents a XML qualified name.
|
|
191
|
+
*
|
|
192
|
+
* The `uri` component may be `null`, in which
|
|
193
|
+
* case it means *wildcard* (\*), used to match
|
|
194
|
+
* any URI.
|
|
195
|
+
*/
|
|
196
|
+
class QName {
|
|
197
|
+
constructor(localName: string);
|
|
198
|
+
constructor(qname: QName);
|
|
199
|
+
constructor(uri: null | Namespace | string, localName: QName | string);
|
|
200
|
+
get localName(): string;
|
|
201
|
+
get uri(): null | string;
|
|
202
|
+
toString(): string;
|
|
203
|
+
valueOf(): QName;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
declare global {
|
|
207
|
+
interface IteratorObject<T, TReturn, TNext> {
|
|
208
|
+
/**
|
|
209
|
+
* Consumes the iterator and returns the number of
|
|
210
|
+
* iterated entries.
|
|
211
|
+
*/
|
|
212
|
+
length(): number;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
declare global {
|
|
216
|
+
/**
|
|
217
|
+
* `Chars` may be used for iterating characters (as Unicode code points)
|
|
218
|
+
* from left-to-right in a string with miscellaneous operation methods.
|
|
219
|
+
*/
|
|
220
|
+
class Chars extends Iterator<number> {
|
|
221
|
+
/**
|
|
222
|
+
* Constructs a `Chars` iterator over the specified string,
|
|
223
|
+
* at the specified UTF-16 `offset`.
|
|
224
|
+
*/
|
|
225
|
+
constructor(str: string, offset?: number);
|
|
226
|
+
/**
|
|
227
|
+
* Indicates if there are remaining code points to read.
|
|
228
|
+
*/
|
|
229
|
+
get hasRemaining(): boolean;
|
|
230
|
+
/**
|
|
231
|
+
* Indicates if the reader has reached the end of the string.
|
|
232
|
+
*/
|
|
233
|
+
get reachedEnd(): boolean;
|
|
234
|
+
next(): IteratorResult<number>;
|
|
235
|
+
/**
|
|
236
|
+
* Returns the next code point. If there are no code points
|
|
237
|
+
* available, returns U+00.
|
|
238
|
+
*/
|
|
239
|
+
get nextOrZero(): number;
|
|
240
|
+
/**
|
|
241
|
+
* Skips a code point. This is equivalent to
|
|
242
|
+
* calling `next()`.
|
|
243
|
+
*/
|
|
244
|
+
skipOneInPlace(): void;
|
|
245
|
+
/**
|
|
246
|
+
* Skips the given number of code points.
|
|
247
|
+
*/
|
|
248
|
+
skipInPlace(count: number): void;
|
|
249
|
+
/**
|
|
250
|
+
* Returns the current UTF-16 offset in the string.
|
|
251
|
+
*/
|
|
252
|
+
get index(): number;
|
|
253
|
+
/**
|
|
254
|
+
* Peeks the next code point.
|
|
255
|
+
*/
|
|
256
|
+
peek(): null | number;
|
|
257
|
+
/**
|
|
258
|
+
* Peeks the next code point. If there are no code points
|
|
259
|
+
* available, returns U+00.
|
|
260
|
+
*/
|
|
261
|
+
peekOrZero(): number;
|
|
262
|
+
/**
|
|
263
|
+
* Peeks the next code point at the given
|
|
264
|
+
* zero based code point index.
|
|
265
|
+
*/
|
|
266
|
+
at(index: number): null | number;
|
|
267
|
+
/**
|
|
268
|
+
* Peeks the next code point at the given zero based code point index.
|
|
269
|
+
* If there are no code points available, returns U+00.
|
|
270
|
+
*/
|
|
271
|
+
atOrZero(index: number): number;
|
|
272
|
+
/**
|
|
273
|
+
* Peeks a number of code points until the string's end.
|
|
274
|
+
*/
|
|
275
|
+
seq(numChars: number): string;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
declare global {
|
|
279
|
+
interface String {
|
|
280
|
+
chars(): Chars;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
require("./Enum");
|
|
7
|
+
require("./E4X");
|
|
8
|
+
require("./SAEventTarget");
|
|
9
|
+
require("./SAByteArray");
|
|
10
|
+
require("./Chars");
|
|
11
|
+
const assert_1 = __importDefault(require("assert"));
|
|
12
|
+
// assert
|
|
13
|
+
globalThis.assert = assert_1.default;
|
|
14
|
+
globalThis.AssertionError = assert_1.default.AssertionError;
|
|
15
|
+
// trace(), etrace()
|
|
16
|
+
globalThis.trace = console.log;
|
|
17
|
+
globalThis.etrace = console.error;
|
|
18
|
+
// Math.clamp()
|
|
19
|
+
Math.clamp = (val, from, to) => {
|
|
20
|
+
return val < from ? from : val > to ? to : val;
|
|
21
|
+
};
|
|
22
|
+
// BigInt.min(), BigInt.max()
|
|
23
|
+
BigInt.min = (...rest) => {
|
|
24
|
+
let r = rest.pop() ?? 0n;
|
|
25
|
+
for (const val of rest) {
|
|
26
|
+
if (val < r) {
|
|
27
|
+
r = val;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return r;
|
|
31
|
+
};
|
|
32
|
+
BigInt.max = (...rest) => {
|
|
33
|
+
let r = rest.pop() ?? 0n;
|
|
34
|
+
for (const val of rest) {
|
|
35
|
+
if (val > r) {
|
|
36
|
+
r = val;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return r;
|
|
40
|
+
};
|
|
41
|
+
// Iterator.length()
|
|
42
|
+
Iterator.prototype.length = function () {
|
|
43
|
+
let n = 0;
|
|
44
|
+
for (const _ of this) {
|
|
45
|
+
n++;
|
|
46
|
+
}
|
|
47
|
+
return n;
|
|
48
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|