@lubomirklimes/character-runtime 0.0.0-stage → 0.1.0-preview.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/LICENSE +21 -0
- package/README.md +89 -2
- package/dist/acs/acs15.d.ts +9 -0
- package/dist/acs/acs15.js +382 -0
- package/dist/acs/acs2-reader.d.ts +2 -0
- package/dist/acs/acs2-reader.js +277 -0
- package/dist/acs/binary.d.ts +1 -0
- package/dist/acs/binary.js +107 -0
- package/dist/acs/compound-file.d.ts +1 -0
- package/dist/acs/compound-file.js +326 -0
- package/dist/acs/document.d.ts +33 -0
- package/dist/acs/document.js +99 -0
- package/dist/acs/errors.d.ts +28 -0
- package/dist/acs/errors.js +41 -0
- package/dist/acs/image.d.ts +30 -0
- package/dist/acs/image.js +113 -0
- package/dist/acs/index.d.ts +11 -0
- package/dist/acs/index.js +10 -0
- package/dist/acs/lz.d.ts +7 -0
- package/dist/acs/lz.js +102 -0
- package/dist/acs/metadata.d.ts +14 -0
- package/dist/acs/metadata.js +126 -0
- package/dist/acs/model.d.ts +130 -0
- package/dist/acs/model.js +12 -0
- package/dist/acs/mouth.d.ts +37 -0
- package/dist/acs/mouth.js +43 -0
- package/dist/acs/wave.d.ts +53 -0
- package/dist/acs/wave.js +422 -0
- package/dist/browser/animation-frame-clock.d.ts +18 -0
- package/dist/browser/animation-frame-clock.js +42 -0
- package/dist/browser/canvas-renderer.d.ts +50 -0
- package/dist/browser/canvas-renderer.js +145 -0
- package/dist/browser/host.d.ts +84 -0
- package/dist/browser/host.js +206 -0
- package/dist/browser/index.d.ts +6 -0
- package/dist/browser/index.js +8 -0
- package/dist/browser/web-audio.d.ts +48 -0
- package/dist/browser/web-audio.js +205 -0
- package/dist/browser/web-speech.d.ts +131 -0
- package/dist/browser/web-speech.js +302 -0
- package/dist/core/activities.d.ts +10 -0
- package/dist/core/activities.js +479 -0
- package/dist/core/agent.d.ts +263 -0
- package/dist/core/agent.js +764 -0
- package/dist/core/audio.d.ts +17 -0
- package/dist/core/audio.js +174 -0
- package/dist/core/balloon.d.ts +43 -0
- package/dist/core/balloon.js +94 -0
- package/dist/core/clock.d.ts +32 -0
- package/dist/core/clock.js +51 -0
- package/dist/core/compositor.d.ts +22 -0
- package/dist/core/compositor.js +67 -0
- package/dist/core/events.d.ts +131 -0
- package/dist/core/events.js +1 -0
- package/dist/core/host.d.ts +29 -0
- package/dist/core/host.js +77 -0
- package/dist/core/index.d.ts +16 -0
- package/dist/core/index.js +13 -0
- package/dist/core/lipsync.d.ts +41 -0
- package/dist/core/lipsync.js +209 -0
- package/dist/core/random.d.ts +52 -0
- package/dist/core/random.js +105 -0
- package/dist/core/request.d.ts +68 -0
- package/dist/core/request.js +131 -0
- package/dist/core/resources.d.ts +70 -0
- package/dist/core/resources.js +243 -0
- package/dist/core/scheduler.d.ts +25 -0
- package/dist/core/scheduler.js +766 -0
- package/dist/core/source.d.ts +21 -0
- package/dist/core/source.js +54 -0
- package/dist/core/speech.d.ts +91 -0
- package/dist/core/speech.js +86 -0
- package/dist/core/text.d.ts +38 -0
- package/dist/core/text.js +97 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/package.json +68 -4
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { guidText, u16, u32, i16, utf16 } from './binary.js';
|
|
2
|
+
import { AcsFormatError } from './errors.js';
|
|
3
|
+
/** Largest character file (256 MiB, ACS.md §10). */
|
|
4
|
+
export const MAX_FILE_BYTES = 256 * 1024 * 1024;
|
|
5
|
+
const MAX_RECORDS = 100_000;
|
|
6
|
+
const MAX_STRING_UNITS = 65536;
|
|
7
|
+
const MAX_TOTAL_STRING_UNITS = 16 * 1024 * 1024;
|
|
8
|
+
function fail(code, message) {
|
|
9
|
+
throw new AcsFormatError(code, message);
|
|
10
|
+
}
|
|
11
|
+
/** A bounded reader restricted to one block of the file. */
|
|
12
|
+
class Cursor {
|
|
13
|
+
bytes;
|
|
14
|
+
pos;
|
|
15
|
+
end;
|
|
16
|
+
budget;
|
|
17
|
+
constructor(bytes, pos, end, budget) {
|
|
18
|
+
this.bytes = bytes;
|
|
19
|
+
this.pos = pos;
|
|
20
|
+
this.end = end;
|
|
21
|
+
this.budget = budget;
|
|
22
|
+
}
|
|
23
|
+
get position() {
|
|
24
|
+
return this.pos;
|
|
25
|
+
}
|
|
26
|
+
get remaining() {
|
|
27
|
+
return this.end - this.pos;
|
|
28
|
+
}
|
|
29
|
+
take(count) {
|
|
30
|
+
if (count < 0 || count > this.remaining)
|
|
31
|
+
fail('bounds', `Truncated block at ${this.pos}, need ${count}, remaining ${this.remaining}.`);
|
|
32
|
+
const at = this.pos;
|
|
33
|
+
this.pos += count;
|
|
34
|
+
return at;
|
|
35
|
+
}
|
|
36
|
+
skip(count) {
|
|
37
|
+
if (count > 0x7fffffff)
|
|
38
|
+
fail('limit', 'Skip exceeds limit.');
|
|
39
|
+
this.take(count);
|
|
40
|
+
}
|
|
41
|
+
u8() {
|
|
42
|
+
return this.bytes[this.take(1)];
|
|
43
|
+
}
|
|
44
|
+
u16() {
|
|
45
|
+
return u16(this.bytes, this.take(2));
|
|
46
|
+
}
|
|
47
|
+
i16() {
|
|
48
|
+
return i16(this.bytes, this.take(2));
|
|
49
|
+
}
|
|
50
|
+
u32() {
|
|
51
|
+
return u32(this.bytes, this.take(4));
|
|
52
|
+
}
|
|
53
|
+
count(minimumBytes, maximum = MAX_RECORDS) {
|
|
54
|
+
const count = this.u32();
|
|
55
|
+
if (count > maximum || count > Math.floor(this.remaining / minimumBytes))
|
|
56
|
+
fail('limit', 'Invalid/excessive record count.');
|
|
57
|
+
return count;
|
|
58
|
+
}
|
|
59
|
+
string() {
|
|
60
|
+
const length = this.u32();
|
|
61
|
+
if (length === 0)
|
|
62
|
+
return '';
|
|
63
|
+
if (length > MAX_STRING_UNITS)
|
|
64
|
+
fail('limit', 'String exceeds 65536 UTF-16 units.');
|
|
65
|
+
this.budget.stringUnits += length;
|
|
66
|
+
if (this.budget.stringUnits > MAX_TOTAL_STRING_UNITS)
|
|
67
|
+
fail('limit', 'Aggregate parsed strings exceed 16 million UTF-16 units.');
|
|
68
|
+
const at = this.take(length * 2);
|
|
69
|
+
const value = utf16(this.bytes, at, length);
|
|
70
|
+
if (value === null)
|
|
71
|
+
fail('unsupported-string', 'Unpaired UTF-16 code units cannot be represented losslessly.');
|
|
72
|
+
if (this.u16() !== 0)
|
|
73
|
+
fail('string-terminator', 'Expected UTF-16 NUL terminator.');
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function validate(bytes, loc) {
|
|
78
|
+
if (loc.offset > bytes.length || loc.size > bytes.length - loc.offset || (loc.size > 0 && loc.offset < 36))
|
|
79
|
+
fail('bounds', `Invalid block ${loc.offset}+${loc.size} in ${bytes.length} bytes.`);
|
|
80
|
+
}
|
|
81
|
+
function section(bytes, loc, budget) {
|
|
82
|
+
validate(bytes, loc);
|
|
83
|
+
return new Cursor(bytes, loc.offset, loc.offset + loc.size, budget);
|
|
84
|
+
}
|
|
85
|
+
function readAssets(bytes, loc, budget) {
|
|
86
|
+
if (loc.size === 0)
|
|
87
|
+
return [];
|
|
88
|
+
const r = section(bytes, loc, budget);
|
|
89
|
+
const count = r.count(12);
|
|
90
|
+
const result = new Array(count);
|
|
91
|
+
for (let i = 0; i < count; i++) {
|
|
92
|
+
const block = { offset: r.u32(), size: r.u32() };
|
|
93
|
+
validate(bytes, block);
|
|
94
|
+
r.u32(); // word3: preserved in the file, not interpreted
|
|
95
|
+
result[i] = block;
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
/** @internal Reads an ACS 2.x file (ACS.md §2–§11). Loading is all-or-nothing; the first failing check gives the error code. */
|
|
100
|
+
export function readAcs2(bytes) {
|
|
101
|
+
if (bytes.length > MAX_FILE_BYTES)
|
|
102
|
+
fail('limit', 'File exceeds 256 MiB policy.');
|
|
103
|
+
const budget = { retained: 0, stringUnits: 0 };
|
|
104
|
+
let r = new Cursor(bytes, 0, bytes.length, budget);
|
|
105
|
+
const signature = r.u32();
|
|
106
|
+
if (signature === 0xabcdabc1 || signature === 0xe011cfd0)
|
|
107
|
+
fail('unsupported-version', 'Legacy ACS or structured-storage candidate; not an ACS 2 file.');
|
|
108
|
+
if (signature === 0xabcdabc4)
|
|
109
|
+
fail('unsupported-format', 'ACF is not ACS.');
|
|
110
|
+
if (signature !== 0xabcdabc3)
|
|
111
|
+
fail('signature', 'Expected ACS signature C3 AB CD AB.');
|
|
112
|
+
const sections = [];
|
|
113
|
+
for (let i = 0; i < 4; i++)
|
|
114
|
+
sections.push({ offset: r.u32(), size: r.u32() });
|
|
115
|
+
for (const loc of sections)
|
|
116
|
+
validate(bytes, loc);
|
|
117
|
+
const retained = [];
|
|
118
|
+
const retain = (start, end) => {
|
|
119
|
+
budget.retained += end - start;
|
|
120
|
+
if (budget.retained > MAX_FILE_BYTES)
|
|
121
|
+
fail('limit', 'Aggregate opaque retention exceeds 256 MiB policy (possibly overlapping blocks).');
|
|
122
|
+
return bytes.subarray(start, end);
|
|
123
|
+
};
|
|
124
|
+
const keep = (kind, start, end) => {
|
|
125
|
+
if (end > start)
|
|
126
|
+
retained.push({ kind, offset: start, bytes: retain(start, end) });
|
|
127
|
+
};
|
|
128
|
+
r = section(bytes, sections[0], budget);
|
|
129
|
+
const minor = r.u16(), major = r.u16();
|
|
130
|
+
if (major !== 2)
|
|
131
|
+
fail('unsupported-version', `Header version ${major}.${minor} is not ACS 2.`);
|
|
132
|
+
const namesLoc = { offset: r.u32(), size: r.u32() };
|
|
133
|
+
validate(bytes, namesLoc);
|
|
134
|
+
const guid = guidText(bytes, r.take(16));
|
|
135
|
+
const width = r.u16(), height = r.u16();
|
|
136
|
+
const transparentIndex = r.u8();
|
|
137
|
+
const style = r.u32(), headerWord = r.u32();
|
|
138
|
+
if ((style & 0x20) !== 0) {
|
|
139
|
+
const start = r.position;
|
|
140
|
+
r.skip(38);
|
|
141
|
+
if (r.u8() !== 0) {
|
|
142
|
+
r.u16();
|
|
143
|
+
r.string();
|
|
144
|
+
r.skip(4);
|
|
145
|
+
r.string();
|
|
146
|
+
}
|
|
147
|
+
keep('tts', start, r.position);
|
|
148
|
+
}
|
|
149
|
+
if ((style & 0x200) !== 0) {
|
|
150
|
+
const start = r.position;
|
|
151
|
+
r.skip(14);
|
|
152
|
+
r.string();
|
|
153
|
+
r.skip(10);
|
|
154
|
+
keep('balloon', start, r.position);
|
|
155
|
+
}
|
|
156
|
+
const paletteCount = r.count(4, 256);
|
|
157
|
+
const palette = new Uint32Array(paletteCount);
|
|
158
|
+
for (let i = 0; i < paletteCount; i++)
|
|
159
|
+
palette[i] = r.u32();
|
|
160
|
+
const iconStart = r.position;
|
|
161
|
+
if (r.u8() !== 0) {
|
|
162
|
+
r.skip(r.u32());
|
|
163
|
+
r.skip(r.u32());
|
|
164
|
+
}
|
|
165
|
+
keep('icon', iconStart, r.position);
|
|
166
|
+
const states = new Map();
|
|
167
|
+
const stateCount = r.u16();
|
|
168
|
+
for (let i = 0; i < stateCount; i++) {
|
|
169
|
+
const name = r.string();
|
|
170
|
+
const count = r.u16();
|
|
171
|
+
const members = [];
|
|
172
|
+
for (let j = 0; j < count; j++)
|
|
173
|
+
members.push(r.string());
|
|
174
|
+
if (states.has(name))
|
|
175
|
+
fail('duplicate-state', 'Duplicate state name.');
|
|
176
|
+
states.set(name, members);
|
|
177
|
+
}
|
|
178
|
+
keep('header-tail', r.position, r.position + r.remaining);
|
|
179
|
+
const names = [];
|
|
180
|
+
if (namesLoc.size !== 0) {
|
|
181
|
+
const n = section(bytes, namesLoc, budget);
|
|
182
|
+
const count = n.u16();
|
|
183
|
+
for (let i = 0; i < count; i++)
|
|
184
|
+
names.push({ language: n.u16(), name: n.string(), description: n.string(), extra: n.string() });
|
|
185
|
+
keep('names-tail', n.position, n.position + n.remaining);
|
|
186
|
+
}
|
|
187
|
+
const images = readAssets(bytes, sections[2], budget);
|
|
188
|
+
const sounds = readAssets(bytes, sections[3], budget);
|
|
189
|
+
const a = section(bytes, sections[1], budget);
|
|
190
|
+
const animationCount = a.count(12);
|
|
191
|
+
const entries = [];
|
|
192
|
+
for (let i = 0; i < animationCount; i++) {
|
|
193
|
+
const name = a.string();
|
|
194
|
+
const block = { offset: a.u32(), size: a.u32() };
|
|
195
|
+
validate(bytes, block);
|
|
196
|
+
entries.push({ name, block });
|
|
197
|
+
}
|
|
198
|
+
keep('animation-index-tail', a.position, a.position + a.remaining);
|
|
199
|
+
const indexTails = [[sections[2], 'image-index-tail', images.length], [sections[3], 'sound-index-tail', sounds.length]];
|
|
200
|
+
for (const [loc, kind, count] of indexTails)
|
|
201
|
+
if (loc.size > 0)
|
|
202
|
+
keep(kind, loc.offset + 4 + count * 12, loc.offset + loc.size);
|
|
203
|
+
let frameBudget = MAX_RECORDS, layerBudget = 1_000_000;
|
|
204
|
+
const warnings = new Set();
|
|
205
|
+
const animations = [];
|
|
206
|
+
for (const entry of entries) {
|
|
207
|
+
const f = section(bytes, entry.block, budget);
|
|
208
|
+
const storedName = f.string();
|
|
209
|
+
const returnType = f.u8();
|
|
210
|
+
const returnName = f.string();
|
|
211
|
+
const count = f.u16();
|
|
212
|
+
frameBudget -= count;
|
|
213
|
+
if (frameBudget < 0)
|
|
214
|
+
fail('limit', 'Total frame budget exceeded.');
|
|
215
|
+
const frames = new Array(count);
|
|
216
|
+
for (let j = 0; j < count; j++) {
|
|
217
|
+
const layerCount = f.u16();
|
|
218
|
+
layerBudget -= layerCount;
|
|
219
|
+
if (layerBudget < 0)
|
|
220
|
+
fail('limit', 'Total layer budget exceeded.');
|
|
221
|
+
const layers = new Array(layerCount);
|
|
222
|
+
for (let k = 0; k < layerCount; k++)
|
|
223
|
+
layers[k] = { image: f.u32(), x: f.i16(), y: f.i16() };
|
|
224
|
+
const sound = f.i16(), durationTicks = f.u16(), exitFrame = f.i16();
|
|
225
|
+
const branchCount = f.u8();
|
|
226
|
+
const branches = new Array(branchCount);
|
|
227
|
+
for (let k = 0; k < branchCount; k++) {
|
|
228
|
+
const word = f.u32();
|
|
229
|
+
branches[k] = { target: word & 0xffff, percent: word >>> 16 };
|
|
230
|
+
}
|
|
231
|
+
const mouthCount = f.u8();
|
|
232
|
+
const mouthAt = f.take(mouthCount * 14);
|
|
233
|
+
const mouths = readMouthRecords(bytes, mouthAt, mouthCount);
|
|
234
|
+
if (sound < -1)
|
|
235
|
+
warnings.add(`Unrecognized negative sound sentinel ${sound}; preserved verbatim, playback semantics unknown.`);
|
|
236
|
+
if (layers.some((l) => l.image >= images.length) || sound >= sounds.length)
|
|
237
|
+
fail('asset-reference', `Animation '${entry.name}', frame ${j}: image or sound reference outside the index.`);
|
|
238
|
+
frames[j] = { layers, sound, durationTicks, exitFrame, branches, mouths };
|
|
239
|
+
}
|
|
240
|
+
const trailing = f.remaining;
|
|
241
|
+
const trailingBytes = retain(f.position, f.position + trailing);
|
|
242
|
+
f.take(trailing);
|
|
243
|
+
animations.push({ name: entry.name, storedName, returnType, returnName, frames, trailingBytes });
|
|
244
|
+
}
|
|
245
|
+
// Gaps outside all known blocks (never a hidden copy of the whole file).
|
|
246
|
+
const coverage = [...sections, namesLoc, ...entries.map((e) => e.block), ...images, ...sounds]
|
|
247
|
+
.filter((x) => x.size > 0)
|
|
248
|
+
.map((x, i) => ({ x, i }))
|
|
249
|
+
.sort((p, q) => p.x.offset - q.x.offset || p.i - q.i)
|
|
250
|
+
.map((p) => p.x);
|
|
251
|
+
let covered = 36;
|
|
252
|
+
for (const block of coverage) {
|
|
253
|
+
if (block.offset > covered)
|
|
254
|
+
keep('file-gap', covered, block.offset);
|
|
255
|
+
covered = Math.max(covered, block.offset + block.size);
|
|
256
|
+
}
|
|
257
|
+
keep('file-trailer', covered, bytes.length);
|
|
258
|
+
const character = {
|
|
259
|
+
format: 'acs2', major, minor, guid, width, height, transparentIndex, style, headerWord, names, palette, states, animations,
|
|
260
|
+
imageCount: images.length, soundCount: sounds.length, retained,
|
|
261
|
+
warnings: [...warnings].sort(ordinal),
|
|
262
|
+
};
|
|
263
|
+
return { character, images, sounds };
|
|
264
|
+
}
|
|
265
|
+
/** @internal Reads `count` 14-byte mouth records at `at`. */
|
|
266
|
+
export function readMouthRecords(bytes, at, count) {
|
|
267
|
+
const records = new Array(count);
|
|
268
|
+
for (let i = 0; i < count; i++) {
|
|
269
|
+
const p = at + i * 14;
|
|
270
|
+
records[i] = { shape: bytes[p], replace: bytes[p + 1], image: u32(bytes, p + 2), x: i16(bytes, p + 6), y: i16(bytes, p + 8), anchorX: i16(bytes, p + 10), anchorY: i16(bytes, p + 12) };
|
|
271
|
+
}
|
|
272
|
+
return records;
|
|
273
|
+
}
|
|
274
|
+
/** Ordinal (UTF-16 code unit) string order. @internal */
|
|
275
|
+
export function ordinal(a, b) {
|
|
276
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
277
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// Little-endian primitives over byte arrays. Every read is explicit about byte order, so nothing depends on the host's endianness.
|
|
2
|
+
/** @internal */
|
|
3
|
+
export function u16(bytes, at) {
|
|
4
|
+
return bytes[at] | (bytes[at + 1] << 8);
|
|
5
|
+
}
|
|
6
|
+
/** @internal */
|
|
7
|
+
export function i16(bytes, at) {
|
|
8
|
+
return (u16(bytes, at) << 16) >> 16;
|
|
9
|
+
}
|
|
10
|
+
/** @internal */
|
|
11
|
+
export function u32(bytes, at) {
|
|
12
|
+
return (bytes[at] | (bytes[at + 1] << 8) | (bytes[at + 2] << 16) | (bytes[at + 3] << 24)) >>> 0;
|
|
13
|
+
}
|
|
14
|
+
/** @internal */
|
|
15
|
+
export function i32(bytes, at) {
|
|
16
|
+
return bytes[at] | (bytes[at + 1] << 8) | (bytes[at + 2] << 16) | (bytes[at + 3] << 24);
|
|
17
|
+
}
|
|
18
|
+
/** @internal */
|
|
19
|
+
export function writeU16(bytes, at, value) {
|
|
20
|
+
bytes[at] = value & 0xff;
|
|
21
|
+
bytes[at + 1] = (value >>> 8) & 0xff;
|
|
22
|
+
}
|
|
23
|
+
/** @internal */
|
|
24
|
+
export function writeU32(bytes, at, value) {
|
|
25
|
+
bytes[at] = value & 0xff;
|
|
26
|
+
bytes[at + 1] = (value >>> 8) & 0xff;
|
|
27
|
+
bytes[at + 2] = (value >>> 16) & 0xff;
|
|
28
|
+
bytes[at + 3] = (value >>> 24) & 0xff;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Decodes `units` UTF-16LE code units starting at `at`. Returns null when the text contains an unpaired surrogate (such text cannot be
|
|
32
|
+
* represented losslessly and is refused by the readers).
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export function utf16(bytes, at, units) {
|
|
36
|
+
const codes = new Array(units);
|
|
37
|
+
for (let i = 0; i < units; i++)
|
|
38
|
+
codes[i] = bytes[at + 2 * i] | (bytes[at + 2 * i + 1] << 8);
|
|
39
|
+
for (let i = 0; i < units; i++) {
|
|
40
|
+
const c = codes[i];
|
|
41
|
+
if (c >= 0xd800 && c <= 0xdbff) {
|
|
42
|
+
const n = i + 1 < units ? codes[i + 1] : -1;
|
|
43
|
+
if (n < 0xdc00 || n > 0xdfff)
|
|
44
|
+
return null;
|
|
45
|
+
i++;
|
|
46
|
+
}
|
|
47
|
+
else if (c >= 0xdc00 && c <= 0xdfff) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
let text = '';
|
|
52
|
+
for (let i = 0; i < units; i += 8192)
|
|
53
|
+
text += String.fromCharCode(...codes.slice(i, i + 8192));
|
|
54
|
+
return text;
|
|
55
|
+
}
|
|
56
|
+
/** The standard text form of a GUID stored in Windows memory order (u32, u16, u16 little-endian, then 8 bytes). @internal */
|
|
57
|
+
export function guidText(bytes, at) {
|
|
58
|
+
const hex = (value, digits) => value.toString(16).padStart(digits, '0');
|
|
59
|
+
let tail = '';
|
|
60
|
+
for (let i = 8; i < 16; i++)
|
|
61
|
+
tail += hex(bytes[at + i], 2);
|
|
62
|
+
return `${hex(u32(bytes, at), 8)}-${hex(u16(bytes, at + 4), 4)}-${hex(u16(bytes, at + 6), 4)}-${tail.slice(0, 4)}-${tail.slice(4)}`;
|
|
63
|
+
}
|
|
64
|
+
/** @internal */
|
|
65
|
+
export function equalBytes(a, aStart, b) {
|
|
66
|
+
if (aStart + b.length > a.length)
|
|
67
|
+
return false;
|
|
68
|
+
for (let i = 0; i < b.length; i++)
|
|
69
|
+
if (a[aStart + i] !== b[i])
|
|
70
|
+
return false;
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
/** ASCII bytes of a four-character chunk identifier. @internal */
|
|
74
|
+
export function fourCC(text) {
|
|
75
|
+
return [text.charCodeAt(0), text.charCodeAt(1), text.charCodeAt(2), text.charCodeAt(3)];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Upper-case mapping used for case-insensitive names (ACS.md §3: ordinal comparison with an invariant, per-code-unit upper-case
|
|
79
|
+
* mapping). Code units whose upper-case form is longer than one unit map to themselves, so lengths never change.
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
export function foldCase(text) {
|
|
83
|
+
let ascii = true;
|
|
84
|
+
for (let i = 0; i < text.length; i++)
|
|
85
|
+
if (text.charCodeAt(i) > 0x7f) {
|
|
86
|
+
ascii = false;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
if (ascii)
|
|
90
|
+
return text.toUpperCase();
|
|
91
|
+
let result = '';
|
|
92
|
+
for (let i = 0; i < text.length; i++) {
|
|
93
|
+
const c = text[i];
|
|
94
|
+
const code = c.charCodeAt(0);
|
|
95
|
+
if (code >= 0xd800 && code <= 0xdfff) {
|
|
96
|
+
result += c;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const upper = c.toUpperCase();
|
|
100
|
+
result += upper.length === 1 ? upper : c;
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
/** Case-insensitive equality of two names (see {@link foldCase}). @internal */
|
|
105
|
+
export function equalsIgnoreCase(a, b) {
|
|
106
|
+
return a.length === b.length && (a === b || foldCase(a) === foldCase(b));
|
|
107
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|