@matdata/yasgui-graph-plugin 1.5.0 → 1.6.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/README.md +110 -15
- package/dist/yasgui-graph-plugin.cjs.js +3912 -112
- package/dist/yasgui-graph-plugin.cjs.js.map +4 -4
- package/dist/yasgui-graph-plugin.esm.js +3922 -109
- package/dist/yasgui-graph-plugin.esm.js.map +4 -4
- package/dist/yasgui-graph-plugin.min.js +39 -27
- package/dist/yasgui-graph-plugin.min.js.map +4 -4
- package/package.json +5 -3
|
@@ -1,3 +1,1805 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// node_modules/base64-js/index.js
|
|
28
|
+
var require_base64_js = __commonJS({
|
|
29
|
+
"node_modules/base64-js/index.js"(exports) {
|
|
30
|
+
"use strict";
|
|
31
|
+
exports.byteLength = byteLength;
|
|
32
|
+
exports.toByteArray = toByteArray;
|
|
33
|
+
exports.fromByteArray = fromByteArray;
|
|
34
|
+
var lookup = [];
|
|
35
|
+
var revLookup = [];
|
|
36
|
+
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
|
|
37
|
+
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
38
|
+
for (i = 0, len = code.length; i < len; ++i) {
|
|
39
|
+
lookup[i] = code[i];
|
|
40
|
+
revLookup[code.charCodeAt(i)] = i;
|
|
41
|
+
}
|
|
42
|
+
var i;
|
|
43
|
+
var len;
|
|
44
|
+
revLookup["-".charCodeAt(0)] = 62;
|
|
45
|
+
revLookup["_".charCodeAt(0)] = 63;
|
|
46
|
+
function getLens(b64) {
|
|
47
|
+
var len2 = b64.length;
|
|
48
|
+
if (len2 % 4 > 0) {
|
|
49
|
+
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
50
|
+
}
|
|
51
|
+
var validLen = b64.indexOf("=");
|
|
52
|
+
if (validLen === -1) validLen = len2;
|
|
53
|
+
var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
|
|
54
|
+
return [validLen, placeHoldersLen];
|
|
55
|
+
}
|
|
56
|
+
function byteLength(b64) {
|
|
57
|
+
var lens = getLens(b64);
|
|
58
|
+
var validLen = lens[0];
|
|
59
|
+
var placeHoldersLen = lens[1];
|
|
60
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
61
|
+
}
|
|
62
|
+
function _byteLength(b64, validLen, placeHoldersLen) {
|
|
63
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
64
|
+
}
|
|
65
|
+
function toByteArray(b64) {
|
|
66
|
+
var tmp;
|
|
67
|
+
var lens = getLens(b64);
|
|
68
|
+
var validLen = lens[0];
|
|
69
|
+
var placeHoldersLen = lens[1];
|
|
70
|
+
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
71
|
+
var curByte = 0;
|
|
72
|
+
var len2 = placeHoldersLen > 0 ? validLen - 4 : validLen;
|
|
73
|
+
var i2;
|
|
74
|
+
for (i2 = 0; i2 < len2; i2 += 4) {
|
|
75
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 18 | revLookup[b64.charCodeAt(i2 + 1)] << 12 | revLookup[b64.charCodeAt(i2 + 2)] << 6 | revLookup[b64.charCodeAt(i2 + 3)];
|
|
76
|
+
arr[curByte++] = tmp >> 16 & 255;
|
|
77
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
78
|
+
arr[curByte++] = tmp & 255;
|
|
79
|
+
}
|
|
80
|
+
if (placeHoldersLen === 2) {
|
|
81
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 2 | revLookup[b64.charCodeAt(i2 + 1)] >> 4;
|
|
82
|
+
arr[curByte++] = tmp & 255;
|
|
83
|
+
}
|
|
84
|
+
if (placeHoldersLen === 1) {
|
|
85
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 10 | revLookup[b64.charCodeAt(i2 + 1)] << 4 | revLookup[b64.charCodeAt(i2 + 2)] >> 2;
|
|
86
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
87
|
+
arr[curByte++] = tmp & 255;
|
|
88
|
+
}
|
|
89
|
+
return arr;
|
|
90
|
+
}
|
|
91
|
+
function tripletToBase64(num) {
|
|
92
|
+
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
|
|
93
|
+
}
|
|
94
|
+
function encodeChunk(uint8, start, end) {
|
|
95
|
+
var tmp;
|
|
96
|
+
var output = [];
|
|
97
|
+
for (var i2 = start; i2 < end; i2 += 3) {
|
|
98
|
+
tmp = (uint8[i2] << 16 & 16711680) + (uint8[i2 + 1] << 8 & 65280) + (uint8[i2 + 2] & 255);
|
|
99
|
+
output.push(tripletToBase64(tmp));
|
|
100
|
+
}
|
|
101
|
+
return output.join("");
|
|
102
|
+
}
|
|
103
|
+
function fromByteArray(uint8) {
|
|
104
|
+
var tmp;
|
|
105
|
+
var len2 = uint8.length;
|
|
106
|
+
var extraBytes = len2 % 3;
|
|
107
|
+
var parts = [];
|
|
108
|
+
var maxChunkLength = 16383;
|
|
109
|
+
for (var i2 = 0, len22 = len2 - extraBytes; i2 < len22; i2 += maxChunkLength) {
|
|
110
|
+
parts.push(encodeChunk(uint8, i2, i2 + maxChunkLength > len22 ? len22 : i2 + maxChunkLength));
|
|
111
|
+
}
|
|
112
|
+
if (extraBytes === 1) {
|
|
113
|
+
tmp = uint8[len2 - 1];
|
|
114
|
+
parts.push(
|
|
115
|
+
lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "=="
|
|
116
|
+
);
|
|
117
|
+
} else if (extraBytes === 2) {
|
|
118
|
+
tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1];
|
|
119
|
+
parts.push(
|
|
120
|
+
lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "="
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
return parts.join("");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// node_modules/ieee754/index.js
|
|
129
|
+
var require_ieee754 = __commonJS({
|
|
130
|
+
"node_modules/ieee754/index.js"(exports) {
|
|
131
|
+
exports.read = function(buffer, offset, isLE, mLen, nBytes) {
|
|
132
|
+
var e, m;
|
|
133
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
134
|
+
var eMax = (1 << eLen) - 1;
|
|
135
|
+
var eBias = eMax >> 1;
|
|
136
|
+
var nBits = -7;
|
|
137
|
+
var i = isLE ? nBytes - 1 : 0;
|
|
138
|
+
var d = isLE ? -1 : 1;
|
|
139
|
+
var s = buffer[offset + i];
|
|
140
|
+
i += d;
|
|
141
|
+
e = s & (1 << -nBits) - 1;
|
|
142
|
+
s >>= -nBits;
|
|
143
|
+
nBits += eLen;
|
|
144
|
+
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {
|
|
145
|
+
}
|
|
146
|
+
m = e & (1 << -nBits) - 1;
|
|
147
|
+
e >>= -nBits;
|
|
148
|
+
nBits += mLen;
|
|
149
|
+
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {
|
|
150
|
+
}
|
|
151
|
+
if (e === 0) {
|
|
152
|
+
e = 1 - eBias;
|
|
153
|
+
} else if (e === eMax) {
|
|
154
|
+
return m ? NaN : (s ? -1 : 1) * Infinity;
|
|
155
|
+
} else {
|
|
156
|
+
m = m + Math.pow(2, mLen);
|
|
157
|
+
e = e - eBias;
|
|
158
|
+
}
|
|
159
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
160
|
+
};
|
|
161
|
+
exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
|
|
162
|
+
var e, m, c2;
|
|
163
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
164
|
+
var eMax = (1 << eLen) - 1;
|
|
165
|
+
var eBias = eMax >> 1;
|
|
166
|
+
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
167
|
+
var i = isLE ? 0 : nBytes - 1;
|
|
168
|
+
var d = isLE ? 1 : -1;
|
|
169
|
+
var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
170
|
+
value = Math.abs(value);
|
|
171
|
+
if (isNaN(value) || value === Infinity) {
|
|
172
|
+
m = isNaN(value) ? 1 : 0;
|
|
173
|
+
e = eMax;
|
|
174
|
+
} else {
|
|
175
|
+
e = Math.floor(Math.log(value) / Math.LN2);
|
|
176
|
+
if (value * (c2 = Math.pow(2, -e)) < 1) {
|
|
177
|
+
e--;
|
|
178
|
+
c2 *= 2;
|
|
179
|
+
}
|
|
180
|
+
if (e + eBias >= 1) {
|
|
181
|
+
value += rt / c2;
|
|
182
|
+
} else {
|
|
183
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
184
|
+
}
|
|
185
|
+
if (value * c2 >= 2) {
|
|
186
|
+
e++;
|
|
187
|
+
c2 /= 2;
|
|
188
|
+
}
|
|
189
|
+
if (e + eBias >= eMax) {
|
|
190
|
+
m = 0;
|
|
191
|
+
e = eMax;
|
|
192
|
+
} else if (e + eBias >= 1) {
|
|
193
|
+
m = (value * c2 - 1) * Math.pow(2, mLen);
|
|
194
|
+
e = e + eBias;
|
|
195
|
+
} else {
|
|
196
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
197
|
+
e = 0;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {
|
|
201
|
+
}
|
|
202
|
+
e = e << mLen | m;
|
|
203
|
+
eLen += mLen;
|
|
204
|
+
for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {
|
|
205
|
+
}
|
|
206
|
+
buffer[offset + i - d] |= s * 128;
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// node_modules/buffer/index.js
|
|
212
|
+
var require_buffer = __commonJS({
|
|
213
|
+
"node_modules/buffer/index.js"(exports) {
|
|
214
|
+
"use strict";
|
|
215
|
+
var base64 = require_base64_js();
|
|
216
|
+
var ieee754 = require_ieee754();
|
|
217
|
+
var customInspectSymbol = typeof Symbol === "function" && typeof Symbol["for"] === "function" ? Symbol["for"]("nodejs.util.inspect.custom") : null;
|
|
218
|
+
exports.Buffer = Buffer3;
|
|
219
|
+
exports.SlowBuffer = SlowBuffer;
|
|
220
|
+
exports.INSPECT_MAX_BYTES = 50;
|
|
221
|
+
var K_MAX_LENGTH = 2147483647;
|
|
222
|
+
exports.kMaxLength = K_MAX_LENGTH;
|
|
223
|
+
Buffer3.TYPED_ARRAY_SUPPORT = typedArraySupport();
|
|
224
|
+
if (!Buffer3.TYPED_ARRAY_SUPPORT && typeof console !== "undefined" && typeof console.error === "function") {
|
|
225
|
+
console.error(
|
|
226
|
+
"This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
function typedArraySupport() {
|
|
230
|
+
try {
|
|
231
|
+
const arr = new Uint8Array(1);
|
|
232
|
+
const proto = { foo: function() {
|
|
233
|
+
return 42;
|
|
234
|
+
} };
|
|
235
|
+
Object.setPrototypeOf(proto, Uint8Array.prototype);
|
|
236
|
+
Object.setPrototypeOf(arr, proto);
|
|
237
|
+
return arr.foo() === 42;
|
|
238
|
+
} catch (e) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
Object.defineProperty(Buffer3.prototype, "parent", {
|
|
243
|
+
enumerable: true,
|
|
244
|
+
get: function() {
|
|
245
|
+
if (!Buffer3.isBuffer(this)) return void 0;
|
|
246
|
+
return this.buffer;
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
Object.defineProperty(Buffer3.prototype, "offset", {
|
|
250
|
+
enumerable: true,
|
|
251
|
+
get: function() {
|
|
252
|
+
if (!Buffer3.isBuffer(this)) return void 0;
|
|
253
|
+
return this.byteOffset;
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
function createBuffer(length2) {
|
|
257
|
+
if (length2 > K_MAX_LENGTH) {
|
|
258
|
+
throw new RangeError('The value "' + length2 + '" is invalid for option "size"');
|
|
259
|
+
}
|
|
260
|
+
const buf = new Uint8Array(length2);
|
|
261
|
+
Object.setPrototypeOf(buf, Buffer3.prototype);
|
|
262
|
+
return buf;
|
|
263
|
+
}
|
|
264
|
+
function Buffer3(arg, encodingOrOffset, length2) {
|
|
265
|
+
if (typeof arg === "number") {
|
|
266
|
+
if (typeof encodingOrOffset === "string") {
|
|
267
|
+
throw new TypeError(
|
|
268
|
+
'The "string" argument must be of type string. Received type number'
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
return allocUnsafe(arg);
|
|
272
|
+
}
|
|
273
|
+
return from(arg, encodingOrOffset, length2);
|
|
274
|
+
}
|
|
275
|
+
Buffer3.poolSize = 8192;
|
|
276
|
+
function from(value, encodingOrOffset, length2) {
|
|
277
|
+
if (typeof value === "string") {
|
|
278
|
+
return fromString(value, encodingOrOffset);
|
|
279
|
+
}
|
|
280
|
+
if (ArrayBuffer.isView(value)) {
|
|
281
|
+
return fromArrayView(value);
|
|
282
|
+
}
|
|
283
|
+
if (value == null) {
|
|
284
|
+
throw new TypeError(
|
|
285
|
+
"The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) {
|
|
289
|
+
return fromArrayBuffer(value, encodingOrOffset, length2);
|
|
290
|
+
}
|
|
291
|
+
if (typeof SharedArrayBuffer !== "undefined" && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) {
|
|
292
|
+
return fromArrayBuffer(value, encodingOrOffset, length2);
|
|
293
|
+
}
|
|
294
|
+
if (typeof value === "number") {
|
|
295
|
+
throw new TypeError(
|
|
296
|
+
'The "value" argument must not be of type number. Received type number'
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
const valueOf = value.valueOf && value.valueOf();
|
|
300
|
+
if (valueOf != null && valueOf !== value) {
|
|
301
|
+
return Buffer3.from(valueOf, encodingOrOffset, length2);
|
|
302
|
+
}
|
|
303
|
+
const b = fromObject(value);
|
|
304
|
+
if (b) return b;
|
|
305
|
+
if (typeof Symbol !== "undefined" && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === "function") {
|
|
306
|
+
return Buffer3.from(value[Symbol.toPrimitive]("string"), encodingOrOffset, length2);
|
|
307
|
+
}
|
|
308
|
+
throw new TypeError(
|
|
309
|
+
"The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
Buffer3.from = function(value, encodingOrOffset, length2) {
|
|
313
|
+
return from(value, encodingOrOffset, length2);
|
|
314
|
+
};
|
|
315
|
+
Object.setPrototypeOf(Buffer3.prototype, Uint8Array.prototype);
|
|
316
|
+
Object.setPrototypeOf(Buffer3, Uint8Array);
|
|
317
|
+
function assertSize(size) {
|
|
318
|
+
if (typeof size !== "number") {
|
|
319
|
+
throw new TypeError('"size" argument must be of type number');
|
|
320
|
+
} else if (size < 0) {
|
|
321
|
+
throw new RangeError('The value "' + size + '" is invalid for option "size"');
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function alloc(size, fill3, encoding) {
|
|
325
|
+
assertSize(size);
|
|
326
|
+
if (size <= 0) {
|
|
327
|
+
return createBuffer(size);
|
|
328
|
+
}
|
|
329
|
+
if (fill3 !== void 0) {
|
|
330
|
+
return typeof encoding === "string" ? createBuffer(size).fill(fill3, encoding) : createBuffer(size).fill(fill3);
|
|
331
|
+
}
|
|
332
|
+
return createBuffer(size);
|
|
333
|
+
}
|
|
334
|
+
Buffer3.alloc = function(size, fill3, encoding) {
|
|
335
|
+
return alloc(size, fill3, encoding);
|
|
336
|
+
};
|
|
337
|
+
function allocUnsafe(size) {
|
|
338
|
+
assertSize(size);
|
|
339
|
+
return createBuffer(size < 0 ? 0 : checked(size) | 0);
|
|
340
|
+
}
|
|
341
|
+
Buffer3.allocUnsafe = function(size) {
|
|
342
|
+
return allocUnsafe(size);
|
|
343
|
+
};
|
|
344
|
+
Buffer3.allocUnsafeSlow = function(size) {
|
|
345
|
+
return allocUnsafe(size);
|
|
346
|
+
};
|
|
347
|
+
function fromString(string2, encoding) {
|
|
348
|
+
if (typeof encoding !== "string" || encoding === "") {
|
|
349
|
+
encoding = "utf8";
|
|
350
|
+
}
|
|
351
|
+
if (!Buffer3.isEncoding(encoding)) {
|
|
352
|
+
throw new TypeError("Unknown encoding: " + encoding);
|
|
353
|
+
}
|
|
354
|
+
const length2 = byteLength(string2, encoding) | 0;
|
|
355
|
+
let buf = createBuffer(length2);
|
|
356
|
+
const actual = buf.write(string2, encoding);
|
|
357
|
+
if (actual !== length2) {
|
|
358
|
+
buf = buf.slice(0, actual);
|
|
359
|
+
}
|
|
360
|
+
return buf;
|
|
361
|
+
}
|
|
362
|
+
function fromArrayLike(array2) {
|
|
363
|
+
const length2 = array2.length < 0 ? 0 : checked(array2.length) | 0;
|
|
364
|
+
const buf = createBuffer(length2);
|
|
365
|
+
for (let i = 0; i < length2; i += 1) {
|
|
366
|
+
buf[i] = array2[i] & 255;
|
|
367
|
+
}
|
|
368
|
+
return buf;
|
|
369
|
+
}
|
|
370
|
+
function fromArrayView(arrayView) {
|
|
371
|
+
if (isInstance(arrayView, Uint8Array)) {
|
|
372
|
+
const copy = new Uint8Array(arrayView);
|
|
373
|
+
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength);
|
|
374
|
+
}
|
|
375
|
+
return fromArrayLike(arrayView);
|
|
376
|
+
}
|
|
377
|
+
function fromArrayBuffer(array2, byteOffset, length2) {
|
|
378
|
+
if (byteOffset < 0 || array2.byteLength < byteOffset) {
|
|
379
|
+
throw new RangeError('"offset" is outside of buffer bounds');
|
|
380
|
+
}
|
|
381
|
+
if (array2.byteLength < byteOffset + (length2 || 0)) {
|
|
382
|
+
throw new RangeError('"length" is outside of buffer bounds');
|
|
383
|
+
}
|
|
384
|
+
let buf;
|
|
385
|
+
if (byteOffset === void 0 && length2 === void 0) {
|
|
386
|
+
buf = new Uint8Array(array2);
|
|
387
|
+
} else if (length2 === void 0) {
|
|
388
|
+
buf = new Uint8Array(array2, byteOffset);
|
|
389
|
+
} else {
|
|
390
|
+
buf = new Uint8Array(array2, byteOffset, length2);
|
|
391
|
+
}
|
|
392
|
+
Object.setPrototypeOf(buf, Buffer3.prototype);
|
|
393
|
+
return buf;
|
|
394
|
+
}
|
|
395
|
+
function fromObject(obj) {
|
|
396
|
+
if (Buffer3.isBuffer(obj)) {
|
|
397
|
+
const len = checked(obj.length) | 0;
|
|
398
|
+
const buf = createBuffer(len);
|
|
399
|
+
if (buf.length === 0) {
|
|
400
|
+
return buf;
|
|
401
|
+
}
|
|
402
|
+
obj.copy(buf, 0, 0, len);
|
|
403
|
+
return buf;
|
|
404
|
+
}
|
|
405
|
+
if (obj.length !== void 0) {
|
|
406
|
+
if (typeof obj.length !== "number" || numberIsNaN(obj.length)) {
|
|
407
|
+
return createBuffer(0);
|
|
408
|
+
}
|
|
409
|
+
return fromArrayLike(obj);
|
|
410
|
+
}
|
|
411
|
+
if (obj.type === "Buffer" && Array.isArray(obj.data)) {
|
|
412
|
+
return fromArrayLike(obj.data);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
function checked(length2) {
|
|
416
|
+
if (length2 >= K_MAX_LENGTH) {
|
|
417
|
+
throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + K_MAX_LENGTH.toString(16) + " bytes");
|
|
418
|
+
}
|
|
419
|
+
return length2 | 0;
|
|
420
|
+
}
|
|
421
|
+
function SlowBuffer(length2) {
|
|
422
|
+
if (+length2 != length2) {
|
|
423
|
+
length2 = 0;
|
|
424
|
+
}
|
|
425
|
+
return Buffer3.alloc(+length2);
|
|
426
|
+
}
|
|
427
|
+
Buffer3.isBuffer = function isBuffer(b) {
|
|
428
|
+
return b != null && b._isBuffer === true && b !== Buffer3.prototype;
|
|
429
|
+
};
|
|
430
|
+
Buffer3.compare = function compare(a, b) {
|
|
431
|
+
if (isInstance(a, Uint8Array)) a = Buffer3.from(a, a.offset, a.byteLength);
|
|
432
|
+
if (isInstance(b, Uint8Array)) b = Buffer3.from(b, b.offset, b.byteLength);
|
|
433
|
+
if (!Buffer3.isBuffer(a) || !Buffer3.isBuffer(b)) {
|
|
434
|
+
throw new TypeError(
|
|
435
|
+
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
if (a === b) return 0;
|
|
439
|
+
let x = a.length;
|
|
440
|
+
let y = b.length;
|
|
441
|
+
for (let i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
442
|
+
if (a[i] !== b[i]) {
|
|
443
|
+
x = a[i];
|
|
444
|
+
y = b[i];
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
if (x < y) return -1;
|
|
449
|
+
if (y < x) return 1;
|
|
450
|
+
return 0;
|
|
451
|
+
};
|
|
452
|
+
Buffer3.isEncoding = function isEncoding(encoding) {
|
|
453
|
+
switch (String(encoding).toLowerCase()) {
|
|
454
|
+
case "hex":
|
|
455
|
+
case "utf8":
|
|
456
|
+
case "utf-8":
|
|
457
|
+
case "ascii":
|
|
458
|
+
case "latin1":
|
|
459
|
+
case "binary":
|
|
460
|
+
case "base64":
|
|
461
|
+
case "ucs2":
|
|
462
|
+
case "ucs-2":
|
|
463
|
+
case "utf16le":
|
|
464
|
+
case "utf-16le":
|
|
465
|
+
return true;
|
|
466
|
+
default:
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
Buffer3.concat = function concat3(list, length2) {
|
|
471
|
+
if (!Array.isArray(list)) {
|
|
472
|
+
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
473
|
+
}
|
|
474
|
+
if (list.length === 0) {
|
|
475
|
+
return Buffer3.alloc(0);
|
|
476
|
+
}
|
|
477
|
+
let i;
|
|
478
|
+
if (length2 === void 0) {
|
|
479
|
+
length2 = 0;
|
|
480
|
+
for (i = 0; i < list.length; ++i) {
|
|
481
|
+
length2 += list[i].length;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
const buffer = Buffer3.allocUnsafe(length2);
|
|
485
|
+
let pos = 0;
|
|
486
|
+
for (i = 0; i < list.length; ++i) {
|
|
487
|
+
let buf = list[i];
|
|
488
|
+
if (isInstance(buf, Uint8Array)) {
|
|
489
|
+
if (pos + buf.length > buffer.length) {
|
|
490
|
+
if (!Buffer3.isBuffer(buf)) buf = Buffer3.from(buf);
|
|
491
|
+
buf.copy(buffer, pos);
|
|
492
|
+
} else {
|
|
493
|
+
Uint8Array.prototype.set.call(
|
|
494
|
+
buffer,
|
|
495
|
+
buf,
|
|
496
|
+
pos
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
} else if (!Buffer3.isBuffer(buf)) {
|
|
500
|
+
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
501
|
+
} else {
|
|
502
|
+
buf.copy(buffer, pos);
|
|
503
|
+
}
|
|
504
|
+
pos += buf.length;
|
|
505
|
+
}
|
|
506
|
+
return buffer;
|
|
507
|
+
};
|
|
508
|
+
function byteLength(string2, encoding) {
|
|
509
|
+
if (Buffer3.isBuffer(string2)) {
|
|
510
|
+
return string2.length;
|
|
511
|
+
}
|
|
512
|
+
if (ArrayBuffer.isView(string2) || isInstance(string2, ArrayBuffer)) {
|
|
513
|
+
return string2.byteLength;
|
|
514
|
+
}
|
|
515
|
+
if (typeof string2 !== "string") {
|
|
516
|
+
throw new TypeError(
|
|
517
|
+
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof string2
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
const len = string2.length;
|
|
521
|
+
const mustMatch = arguments.length > 2 && arguments[2] === true;
|
|
522
|
+
if (!mustMatch && len === 0) return 0;
|
|
523
|
+
let loweredCase = false;
|
|
524
|
+
for (; ; ) {
|
|
525
|
+
switch (encoding) {
|
|
526
|
+
case "ascii":
|
|
527
|
+
case "latin1":
|
|
528
|
+
case "binary":
|
|
529
|
+
return len;
|
|
530
|
+
case "utf8":
|
|
531
|
+
case "utf-8":
|
|
532
|
+
return utf8ToBytes(string2).length;
|
|
533
|
+
case "ucs2":
|
|
534
|
+
case "ucs-2":
|
|
535
|
+
case "utf16le":
|
|
536
|
+
case "utf-16le":
|
|
537
|
+
return len * 2;
|
|
538
|
+
case "hex":
|
|
539
|
+
return len >>> 1;
|
|
540
|
+
case "base64":
|
|
541
|
+
return base64ToBytes(string2).length;
|
|
542
|
+
default:
|
|
543
|
+
if (loweredCase) {
|
|
544
|
+
return mustMatch ? -1 : utf8ToBytes(string2).length;
|
|
545
|
+
}
|
|
546
|
+
encoding = ("" + encoding).toLowerCase();
|
|
547
|
+
loweredCase = true;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
Buffer3.byteLength = byteLength;
|
|
552
|
+
function slowToString(encoding, start, end) {
|
|
553
|
+
let loweredCase = false;
|
|
554
|
+
if (start === void 0 || start < 0) {
|
|
555
|
+
start = 0;
|
|
556
|
+
}
|
|
557
|
+
if (start > this.length) {
|
|
558
|
+
return "";
|
|
559
|
+
}
|
|
560
|
+
if (end === void 0 || end > this.length) {
|
|
561
|
+
end = this.length;
|
|
562
|
+
}
|
|
563
|
+
if (end <= 0) {
|
|
564
|
+
return "";
|
|
565
|
+
}
|
|
566
|
+
end >>>= 0;
|
|
567
|
+
start >>>= 0;
|
|
568
|
+
if (end <= start) {
|
|
569
|
+
return "";
|
|
570
|
+
}
|
|
571
|
+
if (!encoding) encoding = "utf8";
|
|
572
|
+
while (true) {
|
|
573
|
+
switch (encoding) {
|
|
574
|
+
case "hex":
|
|
575
|
+
return hexSlice(this, start, end);
|
|
576
|
+
case "utf8":
|
|
577
|
+
case "utf-8":
|
|
578
|
+
return utf8Slice(this, start, end);
|
|
579
|
+
case "ascii":
|
|
580
|
+
return asciiSlice(this, start, end);
|
|
581
|
+
case "latin1":
|
|
582
|
+
case "binary":
|
|
583
|
+
return latin1Slice(this, start, end);
|
|
584
|
+
case "base64":
|
|
585
|
+
return base64Slice(this, start, end);
|
|
586
|
+
case "ucs2":
|
|
587
|
+
case "ucs-2":
|
|
588
|
+
case "utf16le":
|
|
589
|
+
case "utf-16le":
|
|
590
|
+
return utf16leSlice(this, start, end);
|
|
591
|
+
default:
|
|
592
|
+
if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
|
|
593
|
+
encoding = (encoding + "").toLowerCase();
|
|
594
|
+
loweredCase = true;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
Buffer3.prototype._isBuffer = true;
|
|
599
|
+
function swap(b, n, m) {
|
|
600
|
+
const i = b[n];
|
|
601
|
+
b[n] = b[m];
|
|
602
|
+
b[m] = i;
|
|
603
|
+
}
|
|
604
|
+
Buffer3.prototype.swap16 = function swap16() {
|
|
605
|
+
const len = this.length;
|
|
606
|
+
if (len % 2 !== 0) {
|
|
607
|
+
throw new RangeError("Buffer size must be a multiple of 16-bits");
|
|
608
|
+
}
|
|
609
|
+
for (let i = 0; i < len; i += 2) {
|
|
610
|
+
swap(this, i, i + 1);
|
|
611
|
+
}
|
|
612
|
+
return this;
|
|
613
|
+
};
|
|
614
|
+
Buffer3.prototype.swap32 = function swap32() {
|
|
615
|
+
const len = this.length;
|
|
616
|
+
if (len % 4 !== 0) {
|
|
617
|
+
throw new RangeError("Buffer size must be a multiple of 32-bits");
|
|
618
|
+
}
|
|
619
|
+
for (let i = 0; i < len; i += 4) {
|
|
620
|
+
swap(this, i, i + 3);
|
|
621
|
+
swap(this, i + 1, i + 2);
|
|
622
|
+
}
|
|
623
|
+
return this;
|
|
624
|
+
};
|
|
625
|
+
Buffer3.prototype.swap64 = function swap64() {
|
|
626
|
+
const len = this.length;
|
|
627
|
+
if (len % 8 !== 0) {
|
|
628
|
+
throw new RangeError("Buffer size must be a multiple of 64-bits");
|
|
629
|
+
}
|
|
630
|
+
for (let i = 0; i < len; i += 8) {
|
|
631
|
+
swap(this, i, i + 7);
|
|
632
|
+
swap(this, i + 1, i + 6);
|
|
633
|
+
swap(this, i + 2, i + 5);
|
|
634
|
+
swap(this, i + 3, i + 4);
|
|
635
|
+
}
|
|
636
|
+
return this;
|
|
637
|
+
};
|
|
638
|
+
Buffer3.prototype.toString = function toString3() {
|
|
639
|
+
const length2 = this.length;
|
|
640
|
+
if (length2 === 0) return "";
|
|
641
|
+
if (arguments.length === 0) return utf8Slice(this, 0, length2);
|
|
642
|
+
return slowToString.apply(this, arguments);
|
|
643
|
+
};
|
|
644
|
+
Buffer3.prototype.toLocaleString = Buffer3.prototype.toString;
|
|
645
|
+
Buffer3.prototype.equals = function equals(b) {
|
|
646
|
+
if (!Buffer3.isBuffer(b)) throw new TypeError("Argument must be a Buffer");
|
|
647
|
+
if (this === b) return true;
|
|
648
|
+
return Buffer3.compare(this, b) === 0;
|
|
649
|
+
};
|
|
650
|
+
Buffer3.prototype.inspect = function inspect() {
|
|
651
|
+
let str = "";
|
|
652
|
+
const max2 = exports.INSPECT_MAX_BYTES;
|
|
653
|
+
str = this.toString("hex", 0, max2).replace(/(.{2})/g, "$1 ").trim();
|
|
654
|
+
if (this.length > max2) str += " ... ";
|
|
655
|
+
return "<Buffer " + str + ">";
|
|
656
|
+
};
|
|
657
|
+
if (customInspectSymbol) {
|
|
658
|
+
Buffer3.prototype[customInspectSymbol] = Buffer3.prototype.inspect;
|
|
659
|
+
}
|
|
660
|
+
Buffer3.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
|
|
661
|
+
if (isInstance(target, Uint8Array)) {
|
|
662
|
+
target = Buffer3.from(target, target.offset, target.byteLength);
|
|
663
|
+
}
|
|
664
|
+
if (!Buffer3.isBuffer(target)) {
|
|
665
|
+
throw new TypeError(
|
|
666
|
+
'The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof target
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
if (start === void 0) {
|
|
670
|
+
start = 0;
|
|
671
|
+
}
|
|
672
|
+
if (end === void 0) {
|
|
673
|
+
end = target ? target.length : 0;
|
|
674
|
+
}
|
|
675
|
+
if (thisStart === void 0) {
|
|
676
|
+
thisStart = 0;
|
|
677
|
+
}
|
|
678
|
+
if (thisEnd === void 0) {
|
|
679
|
+
thisEnd = this.length;
|
|
680
|
+
}
|
|
681
|
+
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
682
|
+
throw new RangeError("out of range index");
|
|
683
|
+
}
|
|
684
|
+
if (thisStart >= thisEnd && start >= end) {
|
|
685
|
+
return 0;
|
|
686
|
+
}
|
|
687
|
+
if (thisStart >= thisEnd) {
|
|
688
|
+
return -1;
|
|
689
|
+
}
|
|
690
|
+
if (start >= end) {
|
|
691
|
+
return 1;
|
|
692
|
+
}
|
|
693
|
+
start >>>= 0;
|
|
694
|
+
end >>>= 0;
|
|
695
|
+
thisStart >>>= 0;
|
|
696
|
+
thisEnd >>>= 0;
|
|
697
|
+
if (this === target) return 0;
|
|
698
|
+
let x = thisEnd - thisStart;
|
|
699
|
+
let y = end - start;
|
|
700
|
+
const len = Math.min(x, y);
|
|
701
|
+
const thisCopy = this.slice(thisStart, thisEnd);
|
|
702
|
+
const targetCopy = target.slice(start, end);
|
|
703
|
+
for (let i = 0; i < len; ++i) {
|
|
704
|
+
if (thisCopy[i] !== targetCopy[i]) {
|
|
705
|
+
x = thisCopy[i];
|
|
706
|
+
y = targetCopy[i];
|
|
707
|
+
break;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
if (x < y) return -1;
|
|
711
|
+
if (y < x) return 1;
|
|
712
|
+
return 0;
|
|
713
|
+
};
|
|
714
|
+
function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
|
|
715
|
+
if (buffer.length === 0) return -1;
|
|
716
|
+
if (typeof byteOffset === "string") {
|
|
717
|
+
encoding = byteOffset;
|
|
718
|
+
byteOffset = 0;
|
|
719
|
+
} else if (byteOffset > 2147483647) {
|
|
720
|
+
byteOffset = 2147483647;
|
|
721
|
+
} else if (byteOffset < -2147483648) {
|
|
722
|
+
byteOffset = -2147483648;
|
|
723
|
+
}
|
|
724
|
+
byteOffset = +byteOffset;
|
|
725
|
+
if (numberIsNaN(byteOffset)) {
|
|
726
|
+
byteOffset = dir ? 0 : buffer.length - 1;
|
|
727
|
+
}
|
|
728
|
+
if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
|
|
729
|
+
if (byteOffset >= buffer.length) {
|
|
730
|
+
if (dir) return -1;
|
|
731
|
+
else byteOffset = buffer.length - 1;
|
|
732
|
+
} else if (byteOffset < 0) {
|
|
733
|
+
if (dir) byteOffset = 0;
|
|
734
|
+
else return -1;
|
|
735
|
+
}
|
|
736
|
+
if (typeof val === "string") {
|
|
737
|
+
val = Buffer3.from(val, encoding);
|
|
738
|
+
}
|
|
739
|
+
if (Buffer3.isBuffer(val)) {
|
|
740
|
+
if (val.length === 0) {
|
|
741
|
+
return -1;
|
|
742
|
+
}
|
|
743
|
+
return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
|
|
744
|
+
} else if (typeof val === "number") {
|
|
745
|
+
val = val & 255;
|
|
746
|
+
if (typeof Uint8Array.prototype.indexOf === "function") {
|
|
747
|
+
if (dir) {
|
|
748
|
+
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
|
|
749
|
+
} else {
|
|
750
|
+
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
|
|
754
|
+
}
|
|
755
|
+
throw new TypeError("val must be string, number or Buffer");
|
|
756
|
+
}
|
|
757
|
+
function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
|
|
758
|
+
let indexSize = 1;
|
|
759
|
+
let arrLength = arr.length;
|
|
760
|
+
let valLength = val.length;
|
|
761
|
+
if (encoding !== void 0) {
|
|
762
|
+
encoding = String(encoding).toLowerCase();
|
|
763
|
+
if (encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") {
|
|
764
|
+
if (arr.length < 2 || val.length < 2) {
|
|
765
|
+
return -1;
|
|
766
|
+
}
|
|
767
|
+
indexSize = 2;
|
|
768
|
+
arrLength /= 2;
|
|
769
|
+
valLength /= 2;
|
|
770
|
+
byteOffset /= 2;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
function read(buf, i2) {
|
|
774
|
+
if (indexSize === 1) {
|
|
775
|
+
return buf[i2];
|
|
776
|
+
} else {
|
|
777
|
+
return buf.readUInt16BE(i2 * indexSize);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
let i;
|
|
781
|
+
if (dir) {
|
|
782
|
+
let foundIndex = -1;
|
|
783
|
+
for (i = byteOffset; i < arrLength; i++) {
|
|
784
|
+
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
785
|
+
if (foundIndex === -1) foundIndex = i;
|
|
786
|
+
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
|
|
787
|
+
} else {
|
|
788
|
+
if (foundIndex !== -1) i -= i - foundIndex;
|
|
789
|
+
foundIndex = -1;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
} else {
|
|
793
|
+
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
|
|
794
|
+
for (i = byteOffset; i >= 0; i--) {
|
|
795
|
+
let found = true;
|
|
796
|
+
for (let j = 0; j < valLength; j++) {
|
|
797
|
+
if (read(arr, i + j) !== read(val, j)) {
|
|
798
|
+
found = false;
|
|
799
|
+
break;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
if (found) return i;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
return -1;
|
|
806
|
+
}
|
|
807
|
+
Buffer3.prototype.includes = function includes4(val, byteOffset, encoding) {
|
|
808
|
+
return this.indexOf(val, byteOffset, encoding) !== -1;
|
|
809
|
+
};
|
|
810
|
+
Buffer3.prototype.indexOf = function indexOf3(val, byteOffset, encoding) {
|
|
811
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
|
|
812
|
+
};
|
|
813
|
+
Buffer3.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
|
|
814
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
|
|
815
|
+
};
|
|
816
|
+
function hexWrite(buf, string2, offset, length2) {
|
|
817
|
+
offset = Number(offset) || 0;
|
|
818
|
+
const remaining = buf.length - offset;
|
|
819
|
+
if (!length2) {
|
|
820
|
+
length2 = remaining;
|
|
821
|
+
} else {
|
|
822
|
+
length2 = Number(length2);
|
|
823
|
+
if (length2 > remaining) {
|
|
824
|
+
length2 = remaining;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
const strLen = string2.length;
|
|
828
|
+
if (length2 > strLen / 2) {
|
|
829
|
+
length2 = strLen / 2;
|
|
830
|
+
}
|
|
831
|
+
let i;
|
|
832
|
+
for (i = 0; i < length2; ++i) {
|
|
833
|
+
const parsed = parseInt(string2.substr(i * 2, 2), 16);
|
|
834
|
+
if (numberIsNaN(parsed)) return i;
|
|
835
|
+
buf[offset + i] = parsed;
|
|
836
|
+
}
|
|
837
|
+
return i;
|
|
838
|
+
}
|
|
839
|
+
function utf8Write(buf, string2, offset, length2) {
|
|
840
|
+
return blitBuffer(utf8ToBytes(string2, buf.length - offset), buf, offset, length2);
|
|
841
|
+
}
|
|
842
|
+
function asciiWrite(buf, string2, offset, length2) {
|
|
843
|
+
return blitBuffer(asciiToBytes(string2), buf, offset, length2);
|
|
844
|
+
}
|
|
845
|
+
function base64Write(buf, string2, offset, length2) {
|
|
846
|
+
return blitBuffer(base64ToBytes(string2), buf, offset, length2);
|
|
847
|
+
}
|
|
848
|
+
function ucs2Write(buf, string2, offset, length2) {
|
|
849
|
+
return blitBuffer(utf16leToBytes(string2, buf.length - offset), buf, offset, length2);
|
|
850
|
+
}
|
|
851
|
+
Buffer3.prototype.write = function write(string2, offset, length2, encoding) {
|
|
852
|
+
if (offset === void 0) {
|
|
853
|
+
encoding = "utf8";
|
|
854
|
+
length2 = this.length;
|
|
855
|
+
offset = 0;
|
|
856
|
+
} else if (length2 === void 0 && typeof offset === "string") {
|
|
857
|
+
encoding = offset;
|
|
858
|
+
length2 = this.length;
|
|
859
|
+
offset = 0;
|
|
860
|
+
} else if (isFinite(offset)) {
|
|
861
|
+
offset = offset >>> 0;
|
|
862
|
+
if (isFinite(length2)) {
|
|
863
|
+
length2 = length2 >>> 0;
|
|
864
|
+
if (encoding === void 0) encoding = "utf8";
|
|
865
|
+
} else {
|
|
866
|
+
encoding = length2;
|
|
867
|
+
length2 = void 0;
|
|
868
|
+
}
|
|
869
|
+
} else {
|
|
870
|
+
throw new Error(
|
|
871
|
+
"Buffer.write(string, encoding, offset[, length]) is no longer supported"
|
|
872
|
+
);
|
|
873
|
+
}
|
|
874
|
+
const remaining = this.length - offset;
|
|
875
|
+
if (length2 === void 0 || length2 > remaining) length2 = remaining;
|
|
876
|
+
if (string2.length > 0 && (length2 < 0 || offset < 0) || offset > this.length) {
|
|
877
|
+
throw new RangeError("Attempt to write outside buffer bounds");
|
|
878
|
+
}
|
|
879
|
+
if (!encoding) encoding = "utf8";
|
|
880
|
+
let loweredCase = false;
|
|
881
|
+
for (; ; ) {
|
|
882
|
+
switch (encoding) {
|
|
883
|
+
case "hex":
|
|
884
|
+
return hexWrite(this, string2, offset, length2);
|
|
885
|
+
case "utf8":
|
|
886
|
+
case "utf-8":
|
|
887
|
+
return utf8Write(this, string2, offset, length2);
|
|
888
|
+
case "ascii":
|
|
889
|
+
case "latin1":
|
|
890
|
+
case "binary":
|
|
891
|
+
return asciiWrite(this, string2, offset, length2);
|
|
892
|
+
case "base64":
|
|
893
|
+
return base64Write(this, string2, offset, length2);
|
|
894
|
+
case "ucs2":
|
|
895
|
+
case "ucs-2":
|
|
896
|
+
case "utf16le":
|
|
897
|
+
case "utf-16le":
|
|
898
|
+
return ucs2Write(this, string2, offset, length2);
|
|
899
|
+
default:
|
|
900
|
+
if (loweredCase) throw new TypeError("Unknown encoding: " + encoding);
|
|
901
|
+
encoding = ("" + encoding).toLowerCase();
|
|
902
|
+
loweredCase = true;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
};
|
|
906
|
+
Buffer3.prototype.toJSON = function toJSON() {
|
|
907
|
+
return {
|
|
908
|
+
type: "Buffer",
|
|
909
|
+
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
910
|
+
};
|
|
911
|
+
};
|
|
912
|
+
function base64Slice(buf, start, end) {
|
|
913
|
+
if (start === 0 && end === buf.length) {
|
|
914
|
+
return base64.fromByteArray(buf);
|
|
915
|
+
} else {
|
|
916
|
+
return base64.fromByteArray(buf.slice(start, end));
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
function utf8Slice(buf, start, end) {
|
|
920
|
+
end = Math.min(buf.length, end);
|
|
921
|
+
const res = [];
|
|
922
|
+
let i = start;
|
|
923
|
+
while (i < end) {
|
|
924
|
+
const firstByte = buf[i];
|
|
925
|
+
let codePoint = null;
|
|
926
|
+
let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
|
|
927
|
+
if (i + bytesPerSequence <= end) {
|
|
928
|
+
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
929
|
+
switch (bytesPerSequence) {
|
|
930
|
+
case 1:
|
|
931
|
+
if (firstByte < 128) {
|
|
932
|
+
codePoint = firstByte;
|
|
933
|
+
}
|
|
934
|
+
break;
|
|
935
|
+
case 2:
|
|
936
|
+
secondByte = buf[i + 1];
|
|
937
|
+
if ((secondByte & 192) === 128) {
|
|
938
|
+
tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
|
|
939
|
+
if (tempCodePoint > 127) {
|
|
940
|
+
codePoint = tempCodePoint;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
break;
|
|
944
|
+
case 3:
|
|
945
|
+
secondByte = buf[i + 1];
|
|
946
|
+
thirdByte = buf[i + 2];
|
|
947
|
+
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
|
|
948
|
+
tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
|
|
949
|
+
if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {
|
|
950
|
+
codePoint = tempCodePoint;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
break;
|
|
954
|
+
case 4:
|
|
955
|
+
secondByte = buf[i + 1];
|
|
956
|
+
thirdByte = buf[i + 2];
|
|
957
|
+
fourthByte = buf[i + 3];
|
|
958
|
+
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
|
|
959
|
+
tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
|
|
960
|
+
if (tempCodePoint > 65535 && tempCodePoint < 1114112) {
|
|
961
|
+
codePoint = tempCodePoint;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
if (codePoint === null) {
|
|
967
|
+
codePoint = 65533;
|
|
968
|
+
bytesPerSequence = 1;
|
|
969
|
+
} else if (codePoint > 65535) {
|
|
970
|
+
codePoint -= 65536;
|
|
971
|
+
res.push(codePoint >>> 10 & 1023 | 55296);
|
|
972
|
+
codePoint = 56320 | codePoint & 1023;
|
|
973
|
+
}
|
|
974
|
+
res.push(codePoint);
|
|
975
|
+
i += bytesPerSequence;
|
|
976
|
+
}
|
|
977
|
+
return decodeCodePointsArray(res);
|
|
978
|
+
}
|
|
979
|
+
var MAX_ARGUMENTS_LENGTH = 4096;
|
|
980
|
+
function decodeCodePointsArray(codePoints) {
|
|
981
|
+
const len = codePoints.length;
|
|
982
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
983
|
+
return String.fromCharCode.apply(String, codePoints);
|
|
984
|
+
}
|
|
985
|
+
let res = "";
|
|
986
|
+
let i = 0;
|
|
987
|
+
while (i < len) {
|
|
988
|
+
res += String.fromCharCode.apply(
|
|
989
|
+
String,
|
|
990
|
+
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
return res;
|
|
994
|
+
}
|
|
995
|
+
function asciiSlice(buf, start, end) {
|
|
996
|
+
let ret = "";
|
|
997
|
+
end = Math.min(buf.length, end);
|
|
998
|
+
for (let i = start; i < end; ++i) {
|
|
999
|
+
ret += String.fromCharCode(buf[i] & 127);
|
|
1000
|
+
}
|
|
1001
|
+
return ret;
|
|
1002
|
+
}
|
|
1003
|
+
function latin1Slice(buf, start, end) {
|
|
1004
|
+
let ret = "";
|
|
1005
|
+
end = Math.min(buf.length, end);
|
|
1006
|
+
for (let i = start; i < end; ++i) {
|
|
1007
|
+
ret += String.fromCharCode(buf[i]);
|
|
1008
|
+
}
|
|
1009
|
+
return ret;
|
|
1010
|
+
}
|
|
1011
|
+
function hexSlice(buf, start, end) {
|
|
1012
|
+
const len = buf.length;
|
|
1013
|
+
if (!start || start < 0) start = 0;
|
|
1014
|
+
if (!end || end < 0 || end > len) end = len;
|
|
1015
|
+
let out = "";
|
|
1016
|
+
for (let i = start; i < end; ++i) {
|
|
1017
|
+
out += hexSliceLookupTable[buf[i]];
|
|
1018
|
+
}
|
|
1019
|
+
return out;
|
|
1020
|
+
}
|
|
1021
|
+
function utf16leSlice(buf, start, end) {
|
|
1022
|
+
const bytes = buf.slice(start, end);
|
|
1023
|
+
let res = "";
|
|
1024
|
+
for (let i = 0; i < bytes.length - 1; i += 2) {
|
|
1025
|
+
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
|
|
1026
|
+
}
|
|
1027
|
+
return res;
|
|
1028
|
+
}
|
|
1029
|
+
Buffer3.prototype.slice = function slice3(start, end) {
|
|
1030
|
+
const len = this.length;
|
|
1031
|
+
start = ~~start;
|
|
1032
|
+
end = end === void 0 ? len : ~~end;
|
|
1033
|
+
if (start < 0) {
|
|
1034
|
+
start += len;
|
|
1035
|
+
if (start < 0) start = 0;
|
|
1036
|
+
} else if (start > len) {
|
|
1037
|
+
start = len;
|
|
1038
|
+
}
|
|
1039
|
+
if (end < 0) {
|
|
1040
|
+
end += len;
|
|
1041
|
+
if (end < 0) end = 0;
|
|
1042
|
+
} else if (end > len) {
|
|
1043
|
+
end = len;
|
|
1044
|
+
}
|
|
1045
|
+
if (end < start) end = start;
|
|
1046
|
+
const newBuf = this.subarray(start, end);
|
|
1047
|
+
Object.setPrototypeOf(newBuf, Buffer3.prototype);
|
|
1048
|
+
return newBuf;
|
|
1049
|
+
};
|
|
1050
|
+
function checkOffset(offset, ext, length2) {
|
|
1051
|
+
if (offset % 1 !== 0 || offset < 0) throw new RangeError("offset is not uint");
|
|
1052
|
+
if (offset + ext > length2) throw new RangeError("Trying to access beyond buffer length");
|
|
1053
|
+
}
|
|
1054
|
+
Buffer3.prototype.readUintLE = Buffer3.prototype.readUIntLE = function readUIntLE(offset, byteLength2, noAssert) {
|
|
1055
|
+
offset = offset >>> 0;
|
|
1056
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1057
|
+
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1058
|
+
let val = this[offset];
|
|
1059
|
+
let mul = 1;
|
|
1060
|
+
let i = 0;
|
|
1061
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1062
|
+
val += this[offset + i] * mul;
|
|
1063
|
+
}
|
|
1064
|
+
return val;
|
|
1065
|
+
};
|
|
1066
|
+
Buffer3.prototype.readUintBE = Buffer3.prototype.readUIntBE = function readUIntBE(offset, byteLength2, noAssert) {
|
|
1067
|
+
offset = offset >>> 0;
|
|
1068
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1069
|
+
if (!noAssert) {
|
|
1070
|
+
checkOffset(offset, byteLength2, this.length);
|
|
1071
|
+
}
|
|
1072
|
+
let val = this[offset + --byteLength2];
|
|
1073
|
+
let mul = 1;
|
|
1074
|
+
while (byteLength2 > 0 && (mul *= 256)) {
|
|
1075
|
+
val += this[offset + --byteLength2] * mul;
|
|
1076
|
+
}
|
|
1077
|
+
return val;
|
|
1078
|
+
};
|
|
1079
|
+
Buffer3.prototype.readUint8 = Buffer3.prototype.readUInt8 = function readUInt8(offset, noAssert) {
|
|
1080
|
+
offset = offset >>> 0;
|
|
1081
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1082
|
+
return this[offset];
|
|
1083
|
+
};
|
|
1084
|
+
Buffer3.prototype.readUint16LE = Buffer3.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
|
|
1085
|
+
offset = offset >>> 0;
|
|
1086
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1087
|
+
return this[offset] | this[offset + 1] << 8;
|
|
1088
|
+
};
|
|
1089
|
+
Buffer3.prototype.readUint16BE = Buffer3.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
|
|
1090
|
+
offset = offset >>> 0;
|
|
1091
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1092
|
+
return this[offset] << 8 | this[offset + 1];
|
|
1093
|
+
};
|
|
1094
|
+
Buffer3.prototype.readUint32LE = Buffer3.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
|
|
1095
|
+
offset = offset >>> 0;
|
|
1096
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1097
|
+
return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;
|
|
1098
|
+
};
|
|
1099
|
+
Buffer3.prototype.readUint32BE = Buffer3.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
|
|
1100
|
+
offset = offset >>> 0;
|
|
1101
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1102
|
+
return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
|
|
1103
|
+
};
|
|
1104
|
+
Buffer3.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE(offset) {
|
|
1105
|
+
offset = offset >>> 0;
|
|
1106
|
+
validateNumber(offset, "offset");
|
|
1107
|
+
const first2 = this[offset];
|
|
1108
|
+
const last = this[offset + 7];
|
|
1109
|
+
if (first2 === void 0 || last === void 0) {
|
|
1110
|
+
boundsError(offset, this.length - 8);
|
|
1111
|
+
}
|
|
1112
|
+
const lo = first2 + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24;
|
|
1113
|
+
const hi2 = this[++offset] + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + last * 2 ** 24;
|
|
1114
|
+
return BigInt(lo) + (BigInt(hi2) << BigInt(32));
|
|
1115
|
+
});
|
|
1116
|
+
Buffer3.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE(offset) {
|
|
1117
|
+
offset = offset >>> 0;
|
|
1118
|
+
validateNumber(offset, "offset");
|
|
1119
|
+
const first2 = this[offset];
|
|
1120
|
+
const last = this[offset + 7];
|
|
1121
|
+
if (first2 === void 0 || last === void 0) {
|
|
1122
|
+
boundsError(offset, this.length - 8);
|
|
1123
|
+
}
|
|
1124
|
+
const hi2 = first2 * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
|
|
1125
|
+
const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last;
|
|
1126
|
+
return (BigInt(hi2) << BigInt(32)) + BigInt(lo);
|
|
1127
|
+
});
|
|
1128
|
+
Buffer3.prototype.readIntLE = function readIntLE(offset, byteLength2, noAssert) {
|
|
1129
|
+
offset = offset >>> 0;
|
|
1130
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1131
|
+
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1132
|
+
let val = this[offset];
|
|
1133
|
+
let mul = 1;
|
|
1134
|
+
let i = 0;
|
|
1135
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1136
|
+
val += this[offset + i] * mul;
|
|
1137
|
+
}
|
|
1138
|
+
mul *= 128;
|
|
1139
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength2);
|
|
1140
|
+
return val;
|
|
1141
|
+
};
|
|
1142
|
+
Buffer3.prototype.readIntBE = function readIntBE(offset, byteLength2, noAssert) {
|
|
1143
|
+
offset = offset >>> 0;
|
|
1144
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1145
|
+
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1146
|
+
let i = byteLength2;
|
|
1147
|
+
let mul = 1;
|
|
1148
|
+
let val = this[offset + --i];
|
|
1149
|
+
while (i > 0 && (mul *= 256)) {
|
|
1150
|
+
val += this[offset + --i] * mul;
|
|
1151
|
+
}
|
|
1152
|
+
mul *= 128;
|
|
1153
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength2);
|
|
1154
|
+
return val;
|
|
1155
|
+
};
|
|
1156
|
+
Buffer3.prototype.readInt8 = function readInt8(offset, noAssert) {
|
|
1157
|
+
offset = offset >>> 0;
|
|
1158
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1159
|
+
if (!(this[offset] & 128)) return this[offset];
|
|
1160
|
+
return (255 - this[offset] + 1) * -1;
|
|
1161
|
+
};
|
|
1162
|
+
Buffer3.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
|
|
1163
|
+
offset = offset >>> 0;
|
|
1164
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1165
|
+
const val = this[offset] | this[offset + 1] << 8;
|
|
1166
|
+
return val & 32768 ? val | 4294901760 : val;
|
|
1167
|
+
};
|
|
1168
|
+
Buffer3.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
|
|
1169
|
+
offset = offset >>> 0;
|
|
1170
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1171
|
+
const val = this[offset + 1] | this[offset] << 8;
|
|
1172
|
+
return val & 32768 ? val | 4294901760 : val;
|
|
1173
|
+
};
|
|
1174
|
+
Buffer3.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
|
|
1175
|
+
offset = offset >>> 0;
|
|
1176
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1177
|
+
return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
|
|
1178
|
+
};
|
|
1179
|
+
Buffer3.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
|
|
1180
|
+
offset = offset >>> 0;
|
|
1181
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1182
|
+
return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
|
|
1183
|
+
};
|
|
1184
|
+
Buffer3.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE(offset) {
|
|
1185
|
+
offset = offset >>> 0;
|
|
1186
|
+
validateNumber(offset, "offset");
|
|
1187
|
+
const first2 = this[offset];
|
|
1188
|
+
const last = this[offset + 7];
|
|
1189
|
+
if (first2 === void 0 || last === void 0) {
|
|
1190
|
+
boundsError(offset, this.length - 8);
|
|
1191
|
+
}
|
|
1192
|
+
const val = this[offset + 4] + this[offset + 5] * 2 ** 8 + this[offset + 6] * 2 ** 16 + (last << 24);
|
|
1193
|
+
return (BigInt(val) << BigInt(32)) + BigInt(first2 + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24);
|
|
1194
|
+
});
|
|
1195
|
+
Buffer3.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE(offset) {
|
|
1196
|
+
offset = offset >>> 0;
|
|
1197
|
+
validateNumber(offset, "offset");
|
|
1198
|
+
const first2 = this[offset];
|
|
1199
|
+
const last = this[offset + 7];
|
|
1200
|
+
if (first2 === void 0 || last === void 0) {
|
|
1201
|
+
boundsError(offset, this.length - 8);
|
|
1202
|
+
}
|
|
1203
|
+
const val = (first2 << 24) + // Overflow
|
|
1204
|
+
this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
|
|
1205
|
+
return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last);
|
|
1206
|
+
});
|
|
1207
|
+
Buffer3.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
|
|
1208
|
+
offset = offset >>> 0;
|
|
1209
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1210
|
+
return ieee754.read(this, offset, true, 23, 4);
|
|
1211
|
+
};
|
|
1212
|
+
Buffer3.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
|
|
1213
|
+
offset = offset >>> 0;
|
|
1214
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1215
|
+
return ieee754.read(this, offset, false, 23, 4);
|
|
1216
|
+
};
|
|
1217
|
+
Buffer3.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
|
|
1218
|
+
offset = offset >>> 0;
|
|
1219
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1220
|
+
return ieee754.read(this, offset, true, 52, 8);
|
|
1221
|
+
};
|
|
1222
|
+
Buffer3.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
|
|
1223
|
+
offset = offset >>> 0;
|
|
1224
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1225
|
+
return ieee754.read(this, offset, false, 52, 8);
|
|
1226
|
+
};
|
|
1227
|
+
function checkInt(buf, value, offset, ext, max2, min2) {
|
|
1228
|
+
if (!Buffer3.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance');
|
|
1229
|
+
if (value > max2 || value < min2) throw new RangeError('"value" argument is out of bounds');
|
|
1230
|
+
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
|
1231
|
+
}
|
|
1232
|
+
Buffer3.prototype.writeUintLE = Buffer3.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength2, noAssert) {
|
|
1233
|
+
value = +value;
|
|
1234
|
+
offset = offset >>> 0;
|
|
1235
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1236
|
+
if (!noAssert) {
|
|
1237
|
+
const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1238
|
+
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1239
|
+
}
|
|
1240
|
+
let mul = 1;
|
|
1241
|
+
let i = 0;
|
|
1242
|
+
this[offset] = value & 255;
|
|
1243
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1244
|
+
this[offset + i] = value / mul & 255;
|
|
1245
|
+
}
|
|
1246
|
+
return offset + byteLength2;
|
|
1247
|
+
};
|
|
1248
|
+
Buffer3.prototype.writeUintBE = Buffer3.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength2, noAssert) {
|
|
1249
|
+
value = +value;
|
|
1250
|
+
offset = offset >>> 0;
|
|
1251
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1252
|
+
if (!noAssert) {
|
|
1253
|
+
const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1254
|
+
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1255
|
+
}
|
|
1256
|
+
let i = byteLength2 - 1;
|
|
1257
|
+
let mul = 1;
|
|
1258
|
+
this[offset + i] = value & 255;
|
|
1259
|
+
while (--i >= 0 && (mul *= 256)) {
|
|
1260
|
+
this[offset + i] = value / mul & 255;
|
|
1261
|
+
}
|
|
1262
|
+
return offset + byteLength2;
|
|
1263
|
+
};
|
|
1264
|
+
Buffer3.prototype.writeUint8 = Buffer3.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
|
|
1265
|
+
value = +value;
|
|
1266
|
+
offset = offset >>> 0;
|
|
1267
|
+
if (!noAssert) checkInt(this, value, offset, 1, 255, 0);
|
|
1268
|
+
this[offset] = value & 255;
|
|
1269
|
+
return offset + 1;
|
|
1270
|
+
};
|
|
1271
|
+
Buffer3.prototype.writeUint16LE = Buffer3.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
|
|
1272
|
+
value = +value;
|
|
1273
|
+
offset = offset >>> 0;
|
|
1274
|
+
if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);
|
|
1275
|
+
this[offset] = value & 255;
|
|
1276
|
+
this[offset + 1] = value >>> 8;
|
|
1277
|
+
return offset + 2;
|
|
1278
|
+
};
|
|
1279
|
+
Buffer3.prototype.writeUint16BE = Buffer3.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
|
|
1280
|
+
value = +value;
|
|
1281
|
+
offset = offset >>> 0;
|
|
1282
|
+
if (!noAssert) checkInt(this, value, offset, 2, 65535, 0);
|
|
1283
|
+
this[offset] = value >>> 8;
|
|
1284
|
+
this[offset + 1] = value & 255;
|
|
1285
|
+
return offset + 2;
|
|
1286
|
+
};
|
|
1287
|
+
Buffer3.prototype.writeUint32LE = Buffer3.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
|
|
1288
|
+
value = +value;
|
|
1289
|
+
offset = offset >>> 0;
|
|
1290
|
+
if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);
|
|
1291
|
+
this[offset + 3] = value >>> 24;
|
|
1292
|
+
this[offset + 2] = value >>> 16;
|
|
1293
|
+
this[offset + 1] = value >>> 8;
|
|
1294
|
+
this[offset] = value & 255;
|
|
1295
|
+
return offset + 4;
|
|
1296
|
+
};
|
|
1297
|
+
Buffer3.prototype.writeUint32BE = Buffer3.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
|
|
1298
|
+
value = +value;
|
|
1299
|
+
offset = offset >>> 0;
|
|
1300
|
+
if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0);
|
|
1301
|
+
this[offset] = value >>> 24;
|
|
1302
|
+
this[offset + 1] = value >>> 16;
|
|
1303
|
+
this[offset + 2] = value >>> 8;
|
|
1304
|
+
this[offset + 3] = value & 255;
|
|
1305
|
+
return offset + 4;
|
|
1306
|
+
};
|
|
1307
|
+
function wrtBigUInt64LE(buf, value, offset, min2, max2) {
|
|
1308
|
+
checkIntBI(value, min2, max2, buf, offset, 7);
|
|
1309
|
+
let lo = Number(value & BigInt(4294967295));
|
|
1310
|
+
buf[offset++] = lo;
|
|
1311
|
+
lo = lo >> 8;
|
|
1312
|
+
buf[offset++] = lo;
|
|
1313
|
+
lo = lo >> 8;
|
|
1314
|
+
buf[offset++] = lo;
|
|
1315
|
+
lo = lo >> 8;
|
|
1316
|
+
buf[offset++] = lo;
|
|
1317
|
+
let hi2 = Number(value >> BigInt(32) & BigInt(4294967295));
|
|
1318
|
+
buf[offset++] = hi2;
|
|
1319
|
+
hi2 = hi2 >> 8;
|
|
1320
|
+
buf[offset++] = hi2;
|
|
1321
|
+
hi2 = hi2 >> 8;
|
|
1322
|
+
buf[offset++] = hi2;
|
|
1323
|
+
hi2 = hi2 >> 8;
|
|
1324
|
+
buf[offset++] = hi2;
|
|
1325
|
+
return offset;
|
|
1326
|
+
}
|
|
1327
|
+
function wrtBigUInt64BE(buf, value, offset, min2, max2) {
|
|
1328
|
+
checkIntBI(value, min2, max2, buf, offset, 7);
|
|
1329
|
+
let lo = Number(value & BigInt(4294967295));
|
|
1330
|
+
buf[offset + 7] = lo;
|
|
1331
|
+
lo = lo >> 8;
|
|
1332
|
+
buf[offset + 6] = lo;
|
|
1333
|
+
lo = lo >> 8;
|
|
1334
|
+
buf[offset + 5] = lo;
|
|
1335
|
+
lo = lo >> 8;
|
|
1336
|
+
buf[offset + 4] = lo;
|
|
1337
|
+
let hi2 = Number(value >> BigInt(32) & BigInt(4294967295));
|
|
1338
|
+
buf[offset + 3] = hi2;
|
|
1339
|
+
hi2 = hi2 >> 8;
|
|
1340
|
+
buf[offset + 2] = hi2;
|
|
1341
|
+
hi2 = hi2 >> 8;
|
|
1342
|
+
buf[offset + 1] = hi2;
|
|
1343
|
+
hi2 = hi2 >> 8;
|
|
1344
|
+
buf[offset] = hi2;
|
|
1345
|
+
return offset + 8;
|
|
1346
|
+
}
|
|
1347
|
+
Buffer3.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE(value, offset = 0) {
|
|
1348
|
+
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1349
|
+
});
|
|
1350
|
+
Buffer3.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value, offset = 0) {
|
|
1351
|
+
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1352
|
+
});
|
|
1353
|
+
Buffer3.prototype.writeIntLE = function writeIntLE(value, offset, byteLength2, noAssert) {
|
|
1354
|
+
value = +value;
|
|
1355
|
+
offset = offset >>> 0;
|
|
1356
|
+
if (!noAssert) {
|
|
1357
|
+
const limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1358
|
+
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1359
|
+
}
|
|
1360
|
+
let i = 0;
|
|
1361
|
+
let mul = 1;
|
|
1362
|
+
let sub = 0;
|
|
1363
|
+
this[offset] = value & 255;
|
|
1364
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1365
|
+
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
1366
|
+
sub = 1;
|
|
1367
|
+
}
|
|
1368
|
+
this[offset + i] = (value / mul >> 0) - sub & 255;
|
|
1369
|
+
}
|
|
1370
|
+
return offset + byteLength2;
|
|
1371
|
+
};
|
|
1372
|
+
Buffer3.prototype.writeIntBE = function writeIntBE(value, offset, byteLength2, noAssert) {
|
|
1373
|
+
value = +value;
|
|
1374
|
+
offset = offset >>> 0;
|
|
1375
|
+
if (!noAssert) {
|
|
1376
|
+
const limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1377
|
+
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1378
|
+
}
|
|
1379
|
+
let i = byteLength2 - 1;
|
|
1380
|
+
let mul = 1;
|
|
1381
|
+
let sub = 0;
|
|
1382
|
+
this[offset + i] = value & 255;
|
|
1383
|
+
while (--i >= 0 && (mul *= 256)) {
|
|
1384
|
+
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
1385
|
+
sub = 1;
|
|
1386
|
+
}
|
|
1387
|
+
this[offset + i] = (value / mul >> 0) - sub & 255;
|
|
1388
|
+
}
|
|
1389
|
+
return offset + byteLength2;
|
|
1390
|
+
};
|
|
1391
|
+
Buffer3.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
|
|
1392
|
+
value = +value;
|
|
1393
|
+
offset = offset >>> 0;
|
|
1394
|
+
if (!noAssert) checkInt(this, value, offset, 1, 127, -128);
|
|
1395
|
+
if (value < 0) value = 255 + value + 1;
|
|
1396
|
+
this[offset] = value & 255;
|
|
1397
|
+
return offset + 1;
|
|
1398
|
+
};
|
|
1399
|
+
Buffer3.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
|
|
1400
|
+
value = +value;
|
|
1401
|
+
offset = offset >>> 0;
|
|
1402
|
+
if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);
|
|
1403
|
+
this[offset] = value & 255;
|
|
1404
|
+
this[offset + 1] = value >>> 8;
|
|
1405
|
+
return offset + 2;
|
|
1406
|
+
};
|
|
1407
|
+
Buffer3.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
|
|
1408
|
+
value = +value;
|
|
1409
|
+
offset = offset >>> 0;
|
|
1410
|
+
if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768);
|
|
1411
|
+
this[offset] = value >>> 8;
|
|
1412
|
+
this[offset + 1] = value & 255;
|
|
1413
|
+
return offset + 2;
|
|
1414
|
+
};
|
|
1415
|
+
Buffer3.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
|
|
1416
|
+
value = +value;
|
|
1417
|
+
offset = offset >>> 0;
|
|
1418
|
+
if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1419
|
+
this[offset] = value & 255;
|
|
1420
|
+
this[offset + 1] = value >>> 8;
|
|
1421
|
+
this[offset + 2] = value >>> 16;
|
|
1422
|
+
this[offset + 3] = value >>> 24;
|
|
1423
|
+
return offset + 4;
|
|
1424
|
+
};
|
|
1425
|
+
Buffer3.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
|
|
1426
|
+
value = +value;
|
|
1427
|
+
offset = offset >>> 0;
|
|
1428
|
+
if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1429
|
+
if (value < 0) value = 4294967295 + value + 1;
|
|
1430
|
+
this[offset] = value >>> 24;
|
|
1431
|
+
this[offset + 1] = value >>> 16;
|
|
1432
|
+
this[offset + 2] = value >>> 8;
|
|
1433
|
+
this[offset + 3] = value & 255;
|
|
1434
|
+
return offset + 4;
|
|
1435
|
+
};
|
|
1436
|
+
Buffer3.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE(value, offset = 0) {
|
|
1437
|
+
return wrtBigUInt64LE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
1438
|
+
});
|
|
1439
|
+
Buffer3.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE(value, offset = 0) {
|
|
1440
|
+
return wrtBigUInt64BE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
1441
|
+
});
|
|
1442
|
+
function checkIEEE754(buf, value, offset, ext, max2, min2) {
|
|
1443
|
+
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
|
1444
|
+
if (offset < 0) throw new RangeError("Index out of range");
|
|
1445
|
+
}
|
|
1446
|
+
function writeFloat(buf, value, offset, littleEndian, noAssert) {
|
|
1447
|
+
value = +value;
|
|
1448
|
+
offset = offset >>> 0;
|
|
1449
|
+
if (!noAssert) {
|
|
1450
|
+
checkIEEE754(buf, value, offset, 4, 34028234663852886e22, -34028234663852886e22);
|
|
1451
|
+
}
|
|
1452
|
+
ieee754.write(buf, value, offset, littleEndian, 23, 4);
|
|
1453
|
+
return offset + 4;
|
|
1454
|
+
}
|
|
1455
|
+
Buffer3.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
|
|
1456
|
+
return writeFloat(this, value, offset, true, noAssert);
|
|
1457
|
+
};
|
|
1458
|
+
Buffer3.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
|
|
1459
|
+
return writeFloat(this, value, offset, false, noAssert);
|
|
1460
|
+
};
|
|
1461
|
+
function writeDouble(buf, value, offset, littleEndian, noAssert) {
|
|
1462
|
+
value = +value;
|
|
1463
|
+
offset = offset >>> 0;
|
|
1464
|
+
if (!noAssert) {
|
|
1465
|
+
checkIEEE754(buf, value, offset, 8, 17976931348623157e292, -17976931348623157e292);
|
|
1466
|
+
}
|
|
1467
|
+
ieee754.write(buf, value, offset, littleEndian, 52, 8);
|
|
1468
|
+
return offset + 8;
|
|
1469
|
+
}
|
|
1470
|
+
Buffer3.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
|
|
1471
|
+
return writeDouble(this, value, offset, true, noAssert);
|
|
1472
|
+
};
|
|
1473
|
+
Buffer3.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
|
|
1474
|
+
return writeDouble(this, value, offset, false, noAssert);
|
|
1475
|
+
};
|
|
1476
|
+
Buffer3.prototype.copy = function copy(target, targetStart, start, end) {
|
|
1477
|
+
if (!Buffer3.isBuffer(target)) throw new TypeError("argument should be a Buffer");
|
|
1478
|
+
if (!start) start = 0;
|
|
1479
|
+
if (!end && end !== 0) end = this.length;
|
|
1480
|
+
if (targetStart >= target.length) targetStart = target.length;
|
|
1481
|
+
if (!targetStart) targetStart = 0;
|
|
1482
|
+
if (end > 0 && end < start) end = start;
|
|
1483
|
+
if (end === start) return 0;
|
|
1484
|
+
if (target.length === 0 || this.length === 0) return 0;
|
|
1485
|
+
if (targetStart < 0) {
|
|
1486
|
+
throw new RangeError("targetStart out of bounds");
|
|
1487
|
+
}
|
|
1488
|
+
if (start < 0 || start >= this.length) throw new RangeError("Index out of range");
|
|
1489
|
+
if (end < 0) throw new RangeError("sourceEnd out of bounds");
|
|
1490
|
+
if (end > this.length) end = this.length;
|
|
1491
|
+
if (target.length - targetStart < end - start) {
|
|
1492
|
+
end = target.length - targetStart + start;
|
|
1493
|
+
}
|
|
1494
|
+
const len = end - start;
|
|
1495
|
+
if (this === target && typeof Uint8Array.prototype.copyWithin === "function") {
|
|
1496
|
+
this.copyWithin(targetStart, start, end);
|
|
1497
|
+
} else {
|
|
1498
|
+
Uint8Array.prototype.set.call(
|
|
1499
|
+
target,
|
|
1500
|
+
this.subarray(start, end),
|
|
1501
|
+
targetStart
|
|
1502
|
+
);
|
|
1503
|
+
}
|
|
1504
|
+
return len;
|
|
1505
|
+
};
|
|
1506
|
+
Buffer3.prototype.fill = function fill3(val, start, end, encoding) {
|
|
1507
|
+
if (typeof val === "string") {
|
|
1508
|
+
if (typeof start === "string") {
|
|
1509
|
+
encoding = start;
|
|
1510
|
+
start = 0;
|
|
1511
|
+
end = this.length;
|
|
1512
|
+
} else if (typeof end === "string") {
|
|
1513
|
+
encoding = end;
|
|
1514
|
+
end = this.length;
|
|
1515
|
+
}
|
|
1516
|
+
if (encoding !== void 0 && typeof encoding !== "string") {
|
|
1517
|
+
throw new TypeError("encoding must be a string");
|
|
1518
|
+
}
|
|
1519
|
+
if (typeof encoding === "string" && !Buffer3.isEncoding(encoding)) {
|
|
1520
|
+
throw new TypeError("Unknown encoding: " + encoding);
|
|
1521
|
+
}
|
|
1522
|
+
if (val.length === 1) {
|
|
1523
|
+
const code = val.charCodeAt(0);
|
|
1524
|
+
if (encoding === "utf8" && code < 128 || encoding === "latin1") {
|
|
1525
|
+
val = code;
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
} else if (typeof val === "number") {
|
|
1529
|
+
val = val & 255;
|
|
1530
|
+
} else if (typeof val === "boolean") {
|
|
1531
|
+
val = Number(val);
|
|
1532
|
+
}
|
|
1533
|
+
if (start < 0 || this.length < start || this.length < end) {
|
|
1534
|
+
throw new RangeError("Out of range index");
|
|
1535
|
+
}
|
|
1536
|
+
if (end <= start) {
|
|
1537
|
+
return this;
|
|
1538
|
+
}
|
|
1539
|
+
start = start >>> 0;
|
|
1540
|
+
end = end === void 0 ? this.length : end >>> 0;
|
|
1541
|
+
if (!val) val = 0;
|
|
1542
|
+
let i;
|
|
1543
|
+
if (typeof val === "number") {
|
|
1544
|
+
for (i = start; i < end; ++i) {
|
|
1545
|
+
this[i] = val;
|
|
1546
|
+
}
|
|
1547
|
+
} else {
|
|
1548
|
+
const bytes = Buffer3.isBuffer(val) ? val : Buffer3.from(val, encoding);
|
|
1549
|
+
const len = bytes.length;
|
|
1550
|
+
if (len === 0) {
|
|
1551
|
+
throw new TypeError('The value "' + val + '" is invalid for argument "value"');
|
|
1552
|
+
}
|
|
1553
|
+
for (i = 0; i < end - start; ++i) {
|
|
1554
|
+
this[i + start] = bytes[i % len];
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
return this;
|
|
1558
|
+
};
|
|
1559
|
+
var errors = {};
|
|
1560
|
+
function E(sym, getMessage, Base) {
|
|
1561
|
+
errors[sym] = class NodeError extends Base {
|
|
1562
|
+
constructor() {
|
|
1563
|
+
super();
|
|
1564
|
+
Object.defineProperty(this, "message", {
|
|
1565
|
+
value: getMessage.apply(this, arguments),
|
|
1566
|
+
writable: true,
|
|
1567
|
+
configurable: true
|
|
1568
|
+
});
|
|
1569
|
+
this.name = `${this.name} [${sym}]`;
|
|
1570
|
+
this.stack;
|
|
1571
|
+
delete this.name;
|
|
1572
|
+
}
|
|
1573
|
+
get code() {
|
|
1574
|
+
return sym;
|
|
1575
|
+
}
|
|
1576
|
+
set code(value) {
|
|
1577
|
+
Object.defineProperty(this, "code", {
|
|
1578
|
+
configurable: true,
|
|
1579
|
+
enumerable: true,
|
|
1580
|
+
value,
|
|
1581
|
+
writable: true
|
|
1582
|
+
});
|
|
1583
|
+
}
|
|
1584
|
+
toString() {
|
|
1585
|
+
return `${this.name} [${sym}]: ${this.message}`;
|
|
1586
|
+
}
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1589
|
+
E(
|
|
1590
|
+
"ERR_BUFFER_OUT_OF_BOUNDS",
|
|
1591
|
+
function(name) {
|
|
1592
|
+
if (name) {
|
|
1593
|
+
return `${name} is outside of buffer bounds`;
|
|
1594
|
+
}
|
|
1595
|
+
return "Attempt to access memory outside buffer bounds";
|
|
1596
|
+
},
|
|
1597
|
+
RangeError
|
|
1598
|
+
);
|
|
1599
|
+
E(
|
|
1600
|
+
"ERR_INVALID_ARG_TYPE",
|
|
1601
|
+
function(name, actual) {
|
|
1602
|
+
return `The "${name}" argument must be of type number. Received type ${typeof actual}`;
|
|
1603
|
+
},
|
|
1604
|
+
TypeError
|
|
1605
|
+
);
|
|
1606
|
+
E(
|
|
1607
|
+
"ERR_OUT_OF_RANGE",
|
|
1608
|
+
function(str, range, input) {
|
|
1609
|
+
let msg = `The value of "${str}" is out of range.`;
|
|
1610
|
+
let received = input;
|
|
1611
|
+
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
|
|
1612
|
+
received = addNumericalSeparator(String(input));
|
|
1613
|
+
} else if (typeof input === "bigint") {
|
|
1614
|
+
received = String(input);
|
|
1615
|
+
if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
|
|
1616
|
+
received = addNumericalSeparator(received);
|
|
1617
|
+
}
|
|
1618
|
+
received += "n";
|
|
1619
|
+
}
|
|
1620
|
+
msg += ` It must be ${range}. Received ${received}`;
|
|
1621
|
+
return msg;
|
|
1622
|
+
},
|
|
1623
|
+
RangeError
|
|
1624
|
+
);
|
|
1625
|
+
function addNumericalSeparator(val) {
|
|
1626
|
+
let res = "";
|
|
1627
|
+
let i = val.length;
|
|
1628
|
+
const start = val[0] === "-" ? 1 : 0;
|
|
1629
|
+
for (; i >= start + 4; i -= 3) {
|
|
1630
|
+
res = `_${val.slice(i - 3, i)}${res}`;
|
|
1631
|
+
}
|
|
1632
|
+
return `${val.slice(0, i)}${res}`;
|
|
1633
|
+
}
|
|
1634
|
+
function checkBounds(buf, offset, byteLength2) {
|
|
1635
|
+
validateNumber(offset, "offset");
|
|
1636
|
+
if (buf[offset] === void 0 || buf[offset + byteLength2] === void 0) {
|
|
1637
|
+
boundsError(offset, buf.length - (byteLength2 + 1));
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
function checkIntBI(value, min2, max2, buf, offset, byteLength2) {
|
|
1641
|
+
if (value > max2 || value < min2) {
|
|
1642
|
+
const n = typeof min2 === "bigint" ? "n" : "";
|
|
1643
|
+
let range;
|
|
1644
|
+
if (byteLength2 > 3) {
|
|
1645
|
+
if (min2 === 0 || min2 === BigInt(0)) {
|
|
1646
|
+
range = `>= 0${n} and < 2${n} ** ${(byteLength2 + 1) * 8}${n}`;
|
|
1647
|
+
} else {
|
|
1648
|
+
range = `>= -(2${n} ** ${(byteLength2 + 1) * 8 - 1}${n}) and < 2 ** ${(byteLength2 + 1) * 8 - 1}${n}`;
|
|
1649
|
+
}
|
|
1650
|
+
} else {
|
|
1651
|
+
range = `>= ${min2}${n} and <= ${max2}${n}`;
|
|
1652
|
+
}
|
|
1653
|
+
throw new errors.ERR_OUT_OF_RANGE("value", range, value);
|
|
1654
|
+
}
|
|
1655
|
+
checkBounds(buf, offset, byteLength2);
|
|
1656
|
+
}
|
|
1657
|
+
function validateNumber(value, name) {
|
|
1658
|
+
if (typeof value !== "number") {
|
|
1659
|
+
throw new errors.ERR_INVALID_ARG_TYPE(name, "number", value);
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
function boundsError(value, length2, type) {
|
|
1663
|
+
if (Math.floor(value) !== value) {
|
|
1664
|
+
validateNumber(value, type);
|
|
1665
|
+
throw new errors.ERR_OUT_OF_RANGE(type || "offset", "an integer", value);
|
|
1666
|
+
}
|
|
1667
|
+
if (length2 < 0) {
|
|
1668
|
+
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS();
|
|
1669
|
+
}
|
|
1670
|
+
throw new errors.ERR_OUT_OF_RANGE(
|
|
1671
|
+
type || "offset",
|
|
1672
|
+
`>= ${type ? 1 : 0} and <= ${length2}`,
|
|
1673
|
+
value
|
|
1674
|
+
);
|
|
1675
|
+
}
|
|
1676
|
+
var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
1677
|
+
function base64clean(str) {
|
|
1678
|
+
str = str.split("=")[0];
|
|
1679
|
+
str = str.trim().replace(INVALID_BASE64_RE, "");
|
|
1680
|
+
if (str.length < 2) return "";
|
|
1681
|
+
while (str.length % 4 !== 0) {
|
|
1682
|
+
str = str + "=";
|
|
1683
|
+
}
|
|
1684
|
+
return str;
|
|
1685
|
+
}
|
|
1686
|
+
function utf8ToBytes(string2, units) {
|
|
1687
|
+
units = units || Infinity;
|
|
1688
|
+
let codePoint;
|
|
1689
|
+
const length2 = string2.length;
|
|
1690
|
+
let leadSurrogate = null;
|
|
1691
|
+
const bytes = [];
|
|
1692
|
+
for (let i = 0; i < length2; ++i) {
|
|
1693
|
+
codePoint = string2.charCodeAt(i);
|
|
1694
|
+
if (codePoint > 55295 && codePoint < 57344) {
|
|
1695
|
+
if (!leadSurrogate) {
|
|
1696
|
+
if (codePoint > 56319) {
|
|
1697
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1698
|
+
continue;
|
|
1699
|
+
} else if (i + 1 === length2) {
|
|
1700
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1701
|
+
continue;
|
|
1702
|
+
}
|
|
1703
|
+
leadSurrogate = codePoint;
|
|
1704
|
+
continue;
|
|
1705
|
+
}
|
|
1706
|
+
if (codePoint < 56320) {
|
|
1707
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1708
|
+
leadSurrogate = codePoint;
|
|
1709
|
+
continue;
|
|
1710
|
+
}
|
|
1711
|
+
codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;
|
|
1712
|
+
} else if (leadSurrogate) {
|
|
1713
|
+
if ((units -= 3) > -1) bytes.push(239, 191, 189);
|
|
1714
|
+
}
|
|
1715
|
+
leadSurrogate = null;
|
|
1716
|
+
if (codePoint < 128) {
|
|
1717
|
+
if ((units -= 1) < 0) break;
|
|
1718
|
+
bytes.push(codePoint);
|
|
1719
|
+
} else if (codePoint < 2048) {
|
|
1720
|
+
if ((units -= 2) < 0) break;
|
|
1721
|
+
bytes.push(
|
|
1722
|
+
codePoint >> 6 | 192,
|
|
1723
|
+
codePoint & 63 | 128
|
|
1724
|
+
);
|
|
1725
|
+
} else if (codePoint < 65536) {
|
|
1726
|
+
if ((units -= 3) < 0) break;
|
|
1727
|
+
bytes.push(
|
|
1728
|
+
codePoint >> 12 | 224,
|
|
1729
|
+
codePoint >> 6 & 63 | 128,
|
|
1730
|
+
codePoint & 63 | 128
|
|
1731
|
+
);
|
|
1732
|
+
} else if (codePoint < 1114112) {
|
|
1733
|
+
if ((units -= 4) < 0) break;
|
|
1734
|
+
bytes.push(
|
|
1735
|
+
codePoint >> 18 | 240,
|
|
1736
|
+
codePoint >> 12 & 63 | 128,
|
|
1737
|
+
codePoint >> 6 & 63 | 128,
|
|
1738
|
+
codePoint & 63 | 128
|
|
1739
|
+
);
|
|
1740
|
+
} else {
|
|
1741
|
+
throw new Error("Invalid code point");
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
return bytes;
|
|
1745
|
+
}
|
|
1746
|
+
function asciiToBytes(str) {
|
|
1747
|
+
const byteArray = [];
|
|
1748
|
+
for (let i = 0; i < str.length; ++i) {
|
|
1749
|
+
byteArray.push(str.charCodeAt(i) & 255);
|
|
1750
|
+
}
|
|
1751
|
+
return byteArray;
|
|
1752
|
+
}
|
|
1753
|
+
function utf16leToBytes(str, units) {
|
|
1754
|
+
let c2, hi2, lo;
|
|
1755
|
+
const byteArray = [];
|
|
1756
|
+
for (let i = 0; i < str.length; ++i) {
|
|
1757
|
+
if ((units -= 2) < 0) break;
|
|
1758
|
+
c2 = str.charCodeAt(i);
|
|
1759
|
+
hi2 = c2 >> 8;
|
|
1760
|
+
lo = c2 % 256;
|
|
1761
|
+
byteArray.push(lo);
|
|
1762
|
+
byteArray.push(hi2);
|
|
1763
|
+
}
|
|
1764
|
+
return byteArray;
|
|
1765
|
+
}
|
|
1766
|
+
function base64ToBytes(str) {
|
|
1767
|
+
return base64.toByteArray(base64clean(str));
|
|
1768
|
+
}
|
|
1769
|
+
function blitBuffer(src, dst, offset, length2) {
|
|
1770
|
+
let i;
|
|
1771
|
+
for (i = 0; i < length2; ++i) {
|
|
1772
|
+
if (i + offset >= dst.length || i >= src.length) break;
|
|
1773
|
+
dst[i + offset] = src[i];
|
|
1774
|
+
}
|
|
1775
|
+
return i;
|
|
1776
|
+
}
|
|
1777
|
+
function isInstance(obj, type) {
|
|
1778
|
+
return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
|
|
1779
|
+
}
|
|
1780
|
+
function numberIsNaN(obj) {
|
|
1781
|
+
return obj !== obj;
|
|
1782
|
+
}
|
|
1783
|
+
var hexSliceLookupTable = (function() {
|
|
1784
|
+
const alphabet = "0123456789abcdef";
|
|
1785
|
+
const table = new Array(256);
|
|
1786
|
+
for (let i = 0; i < 16; ++i) {
|
|
1787
|
+
const i16 = i * 16;
|
|
1788
|
+
for (let j = 0; j < 16; ++j) {
|
|
1789
|
+
table[i16 + j] = alphabet[i] + alphabet[j];
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
return table;
|
|
1793
|
+
})();
|
|
1794
|
+
function defineBigIntMethod(fn) {
|
|
1795
|
+
return typeof BigInt === "undefined" ? BufferBigIntNotDefined : fn;
|
|
1796
|
+
}
|
|
1797
|
+
function BufferBigIntNotDefined() {
|
|
1798
|
+
throw new Error("BigInt not supported");
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
});
|
|
1802
|
+
|
|
1
1803
|
// src/prefixUtils.ts
|
|
2
1804
|
function extractPrefixes(yasr) {
|
|
3
1805
|
const prefixMap = /* @__PURE__ */ new Map();
|
|
@@ -8,114 +1810,1974 @@ function extractPrefixes(yasr) {
|
|
|
8
1810
|
if (uri && prefix) {
|
|
9
1811
|
prefixMap.set(uri, prefix);
|
|
10
1812
|
}
|
|
11
|
-
});
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
const commonPrefixes = {
|
|
1817
|
+
"http://www.w3.org/1999/02/22-rdf-syntax-ns#": "rdf",
|
|
1818
|
+
"http://www.w3.org/2000/01/rdf-schema#": "rdfs",
|
|
1819
|
+
"http://www.w3.org/2001/XMLSchema#": "xsd",
|
|
1820
|
+
"http://www.w3.org/2002/07/owl#": "owl"
|
|
1821
|
+
};
|
|
1822
|
+
Object.entries(commonPrefixes).forEach(([uri, prefix]) => {
|
|
1823
|
+
if (!prefixMap.has(uri)) {
|
|
1824
|
+
prefixMap.set(uri, prefix);
|
|
1825
|
+
}
|
|
1826
|
+
});
|
|
1827
|
+
return prefixMap;
|
|
1828
|
+
}
|
|
1829
|
+
function applyPrefix(uri, prefixMap) {
|
|
1830
|
+
if (!uri || typeof uri !== "string") return uri;
|
|
1831
|
+
for (const [namespace, prefix] of prefixMap.entries()) {
|
|
1832
|
+
if (uri.startsWith(namespace)) {
|
|
1833
|
+
const localName = uri.substring(namespace.length);
|
|
1834
|
+
return `${prefix}:${localName}`;
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
return uri;
|
|
1838
|
+
}
|
|
1839
|
+
function truncateLabel(text, maxLength = 50) {
|
|
1840
|
+
if (!text || typeof text !== "string") return text;
|
|
1841
|
+
if (text.length <= maxLength) return text;
|
|
1842
|
+
return text.substring(0, maxLength - 3) + "...";
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
// src/networkConfig.ts
|
|
1846
|
+
function getDefaultNetworkOptions(themeColors, settings) {
|
|
1847
|
+
const curved = !settings || settings.edgeStyle !== "straight";
|
|
1848
|
+
const nodeSizeMap = { small: 6, medium: 10, large: 16 };
|
|
1849
|
+
const nodeSize = (settings == null ? void 0 : settings.nodeSize) ? nodeSizeMap[settings.nodeSize] : 10;
|
|
1850
|
+
const showNodeLabels = (settings == null ? void 0 : settings.showNodeLabels) !== false;
|
|
1851
|
+
return {
|
|
1852
|
+
// Configure canvas background color based on theme
|
|
1853
|
+
configure: {
|
|
1854
|
+
enabled: false
|
|
1855
|
+
},
|
|
1856
|
+
physics: {
|
|
1857
|
+
enabled: (settings == null ? void 0 : settings.physicsEnabled) !== false,
|
|
1858
|
+
stabilization: {
|
|
1859
|
+
enabled: true,
|
|
1860
|
+
iterations: 200,
|
|
1861
|
+
// Max iterations for performance (<2s target)
|
|
1862
|
+
updateInterval: 25
|
|
1863
|
+
},
|
|
1864
|
+
barnesHut: {
|
|
1865
|
+
gravitationalConstant: -2e3,
|
|
1866
|
+
centralGravity: 0.3,
|
|
1867
|
+
springLength: 95,
|
|
1868
|
+
springConstant: 0.04,
|
|
1869
|
+
damping: 0.09
|
|
1870
|
+
}
|
|
1871
|
+
},
|
|
1872
|
+
interaction: {
|
|
1873
|
+
dragNodes: true,
|
|
1874
|
+
dragView: true,
|
|
1875
|
+
zoomView: true,
|
|
1876
|
+
hover: true,
|
|
1877
|
+
tooltipDelay: 300,
|
|
1878
|
+
// 300ms hover delay per spec
|
|
1879
|
+
hideEdgesOnDrag: false,
|
|
1880
|
+
hideEdgesOnZoom: false
|
|
1881
|
+
},
|
|
1882
|
+
nodes: {
|
|
1883
|
+
shape: "dot",
|
|
1884
|
+
size: nodeSize,
|
|
1885
|
+
font: {
|
|
1886
|
+
size: showNodeLabels ? 12 : 0,
|
|
1887
|
+
color: themeColors.text
|
|
1888
|
+
},
|
|
1889
|
+
borderWidth: 1,
|
|
1890
|
+
borderWidthSelected: 2,
|
|
1891
|
+
labelHighlightBold: true
|
|
1892
|
+
},
|
|
1893
|
+
edges: {
|
|
1894
|
+
arrows: {
|
|
1895
|
+
to: {
|
|
1896
|
+
enabled: true,
|
|
1897
|
+
scaleFactor: 0.6
|
|
1898
|
+
}
|
|
1899
|
+
},
|
|
1900
|
+
smooth: {
|
|
1901
|
+
enabled: curved,
|
|
1902
|
+
type: "dynamic",
|
|
1903
|
+
roundness: 0.5
|
|
1904
|
+
},
|
|
1905
|
+
font: {
|
|
1906
|
+
size: 12,
|
|
1907
|
+
align: "middle",
|
|
1908
|
+
color: themeColors.edgeLabel,
|
|
1909
|
+
background: themeColors.edgeLabelBackground,
|
|
1910
|
+
strokeWidth: 0
|
|
1911
|
+
// Remove white outline/halo
|
|
1912
|
+
},
|
|
1913
|
+
color: {
|
|
1914
|
+
color: themeColors.edge
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
};
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
// node_modules/n3/src/N3Lexer.js
|
|
1921
|
+
var import_buffer = __toESM(require_buffer());
|
|
1922
|
+
|
|
1923
|
+
// node_modules/n3/src/IRIs.js
|
|
1924
|
+
var RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
|
|
1925
|
+
var XSD = "http://www.w3.org/2001/XMLSchema#";
|
|
1926
|
+
var SWAP = "http://www.w3.org/2000/10/swap/";
|
|
1927
|
+
var IRIs_default = {
|
|
1928
|
+
xsd: {
|
|
1929
|
+
decimal: `${XSD}decimal`,
|
|
1930
|
+
boolean: `${XSD}boolean`,
|
|
1931
|
+
double: `${XSD}double`,
|
|
1932
|
+
integer: `${XSD}integer`,
|
|
1933
|
+
string: `${XSD}string`
|
|
1934
|
+
},
|
|
1935
|
+
rdf: {
|
|
1936
|
+
type: `${RDF}type`,
|
|
1937
|
+
nil: `${RDF}nil`,
|
|
1938
|
+
first: `${RDF}first`,
|
|
1939
|
+
rest: `${RDF}rest`,
|
|
1940
|
+
langString: `${RDF}langString`,
|
|
1941
|
+
dirLangString: `${RDF}dirLangString`,
|
|
1942
|
+
reifies: `${RDF}reifies`
|
|
1943
|
+
},
|
|
1944
|
+
owl: {
|
|
1945
|
+
sameAs: "http://www.w3.org/2002/07/owl#sameAs"
|
|
1946
|
+
},
|
|
1947
|
+
r: {
|
|
1948
|
+
forSome: `${SWAP}reify#forSome`,
|
|
1949
|
+
forAll: `${SWAP}reify#forAll`
|
|
1950
|
+
},
|
|
1951
|
+
log: {
|
|
1952
|
+
implies: `${SWAP}log#implies`,
|
|
1953
|
+
isImpliedBy: `${SWAP}log#isImpliedBy`
|
|
1954
|
+
}
|
|
1955
|
+
};
|
|
1956
|
+
|
|
1957
|
+
// node_modules/n3/src/N3Lexer.js
|
|
1958
|
+
var { xsd } = IRIs_default;
|
|
1959
|
+
var escapeSequence = /\\u([a-fA-F0-9]{4})|\\U([a-fA-F0-9]{8})|\\([^])/g;
|
|
1960
|
+
var escapeReplacements = {
|
|
1961
|
+
"\\": "\\",
|
|
1962
|
+
"'": "'",
|
|
1963
|
+
'"': '"',
|
|
1964
|
+
"n": "\n",
|
|
1965
|
+
"r": "\r",
|
|
1966
|
+
"t": " ",
|
|
1967
|
+
"f": "\f",
|
|
1968
|
+
"b": "\b",
|
|
1969
|
+
"_": "_",
|
|
1970
|
+
"~": "~",
|
|
1971
|
+
".": ".",
|
|
1972
|
+
"-": "-",
|
|
1973
|
+
"!": "!",
|
|
1974
|
+
"$": "$",
|
|
1975
|
+
"&": "&",
|
|
1976
|
+
"(": "(",
|
|
1977
|
+
")": ")",
|
|
1978
|
+
"*": "*",
|
|
1979
|
+
"+": "+",
|
|
1980
|
+
",": ",",
|
|
1981
|
+
";": ";",
|
|
1982
|
+
"=": "=",
|
|
1983
|
+
"/": "/",
|
|
1984
|
+
"?": "?",
|
|
1985
|
+
"#": "#",
|
|
1986
|
+
"@": "@",
|
|
1987
|
+
"%": "%"
|
|
1988
|
+
};
|
|
1989
|
+
var illegalIriChars = /[\x00-\x20<>\\"\{\}\|\^\`]/;
|
|
1990
|
+
var lineModeRegExps = {
|
|
1991
|
+
_iri: true,
|
|
1992
|
+
_unescapedIri: true,
|
|
1993
|
+
_simpleQuotedString: true,
|
|
1994
|
+
_langcode: true,
|
|
1995
|
+
_dircode: true,
|
|
1996
|
+
_blank: true,
|
|
1997
|
+
_newline: true,
|
|
1998
|
+
_comment: true,
|
|
1999
|
+
_whitespace: true,
|
|
2000
|
+
_endOfFile: true
|
|
2001
|
+
};
|
|
2002
|
+
var invalidRegExp = /$0^/;
|
|
2003
|
+
var N3Lexer = class {
|
|
2004
|
+
constructor(options) {
|
|
2005
|
+
this._iri = /^<((?:[^ <>{}\\]|\\[uU])+)>[ \t]*/;
|
|
2006
|
+
this._unescapedIri = /^<([^\x00-\x20<>\\"\{\}\|\^\`]*)>[ \t]*/;
|
|
2007
|
+
this._simpleQuotedString = /^"([^"\\\r\n]*)"(?=[^"])/;
|
|
2008
|
+
this._simpleApostropheString = /^'([^'\\\r\n]*)'(?=[^'])/;
|
|
2009
|
+
this._langcode = /^@([a-z]+(?:-[a-z0-9]+)*)(?=[^a-z0-9])/i;
|
|
2010
|
+
this._dircode = /^--(ltr)|(rtl)/;
|
|
2011
|
+
this._prefix = /^((?:[A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)?:(?=[#\s<])/;
|
|
2012
|
+
this._prefixed = /^((?:[A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)?:((?:(?:[0-:A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~])(?:(?:[\.\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~])*(?:[\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~]))?)?)(?:[ \t]+|(?=\.?[,;!\^\s#()\[\]\{\}"'<>]))/;
|
|
2013
|
+
this._variable = /^\?(?:(?:[A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:[\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)(?=[.,;!\^\s#()\[\]\{\}"'<>])/;
|
|
2014
|
+
this._blank = /^_:((?:[0-9A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)(?:[ \t]+|(?=\.?[,;:\s#()\[\]\{\}"'<>]))/;
|
|
2015
|
+
this._number = /^[\-+]?(?:(\d+\.\d*|\.?\d+)[eE][\-+]?|\d*(\.)?)\d+(?=\.?[,;:\s#()\[\]\{\}"'<>])/;
|
|
2016
|
+
this._boolean = /^(?:true|false)(?=[.,;\s#()\[\]\{\}"'<>])/;
|
|
2017
|
+
this._atKeyword = /^@[a-z]+(?=[\s#<:])/i;
|
|
2018
|
+
this._keyword = /^(?:PREFIX|BASE|VERSION|GRAPH)(?=[\s#<])/i;
|
|
2019
|
+
this._shortPredicates = /^a(?=[\s#()\[\]\{\}"'<>])/;
|
|
2020
|
+
this._newline = /^[ \t]*(?:#[^\n\r]*)?(?:\r\n|\n|\r)[ \t]*/;
|
|
2021
|
+
this._comment = /#([^\n\r]*)/;
|
|
2022
|
+
this._whitespace = /^[ \t]+/;
|
|
2023
|
+
this._endOfFile = /^(?:#[^\n\r]*)?$/;
|
|
2024
|
+
options = options || {};
|
|
2025
|
+
this._isImpliedBy = options.isImpliedBy;
|
|
2026
|
+
if (this._lineMode = !!options.lineMode) {
|
|
2027
|
+
this._n3Mode = false;
|
|
2028
|
+
for (const key in this) {
|
|
2029
|
+
if (!(key in lineModeRegExps) && this[key] instanceof RegExp)
|
|
2030
|
+
this[key] = invalidRegExp;
|
|
2031
|
+
}
|
|
2032
|
+
} else {
|
|
2033
|
+
this._n3Mode = options.n3 !== false;
|
|
2034
|
+
}
|
|
2035
|
+
this.comments = !!options.comments;
|
|
2036
|
+
this._literalClosingPos = 0;
|
|
2037
|
+
}
|
|
2038
|
+
// ## Private methods
|
|
2039
|
+
// ### `_tokenizeToEnd` tokenizes as for as possible, emitting tokens through the callback
|
|
2040
|
+
_tokenizeToEnd(callback, inputFinished) {
|
|
2041
|
+
let input = this._input;
|
|
2042
|
+
let currentLineLength = input.length;
|
|
2043
|
+
while (true) {
|
|
2044
|
+
let whiteSpaceMatch, comment;
|
|
2045
|
+
while (whiteSpaceMatch = this._newline.exec(input)) {
|
|
2046
|
+
if (this.comments && (comment = this._comment.exec(whiteSpaceMatch[0])))
|
|
2047
|
+
emitToken("comment", comment[1], "", this._line, whiteSpaceMatch[0].length);
|
|
2048
|
+
input = input.substr(whiteSpaceMatch[0].length, input.length);
|
|
2049
|
+
currentLineLength = input.length;
|
|
2050
|
+
this._line++;
|
|
2051
|
+
}
|
|
2052
|
+
if (!whiteSpaceMatch && (whiteSpaceMatch = this._whitespace.exec(input)))
|
|
2053
|
+
input = input.substr(whiteSpaceMatch[0].length, input.length);
|
|
2054
|
+
if (this._endOfFile.test(input)) {
|
|
2055
|
+
if (inputFinished) {
|
|
2056
|
+
if (this.comments && (comment = this._comment.exec(input)))
|
|
2057
|
+
emitToken("comment", comment[1], "", this._line, input.length);
|
|
2058
|
+
input = null;
|
|
2059
|
+
emitToken("eof", "", "", this._line, 0);
|
|
2060
|
+
}
|
|
2061
|
+
return this._input = input;
|
|
2062
|
+
}
|
|
2063
|
+
const line = this._line, firstChar = input[0];
|
|
2064
|
+
let type = "", value = "", prefix = "", match2 = null, matchLength = 0, inconclusive = false;
|
|
2065
|
+
switch (firstChar) {
|
|
2066
|
+
case "^":
|
|
2067
|
+
if (input.length < 3)
|
|
2068
|
+
break;
|
|
2069
|
+
else if (input[1] === "^") {
|
|
2070
|
+
this._previousMarker = "^^";
|
|
2071
|
+
input = input.substr(2);
|
|
2072
|
+
if (input[0] !== "<") {
|
|
2073
|
+
inconclusive = true;
|
|
2074
|
+
break;
|
|
2075
|
+
}
|
|
2076
|
+
} else {
|
|
2077
|
+
if (this._n3Mode) {
|
|
2078
|
+
matchLength = 1;
|
|
2079
|
+
type = "^";
|
|
2080
|
+
}
|
|
2081
|
+
break;
|
|
2082
|
+
}
|
|
2083
|
+
// Fall through in case the type is an IRI
|
|
2084
|
+
case "<":
|
|
2085
|
+
if (match2 = this._unescapedIri.exec(input))
|
|
2086
|
+
type = "IRI", value = match2[1];
|
|
2087
|
+
else if (match2 = this._iri.exec(input)) {
|
|
2088
|
+
value = this._unescape(match2[1]);
|
|
2089
|
+
if (value === null || illegalIriChars.test(value))
|
|
2090
|
+
return reportSyntaxError(this);
|
|
2091
|
+
type = "IRI";
|
|
2092
|
+
} else if (input.length > 2 && input[1] === "<" && input[2] === "(")
|
|
2093
|
+
type = "<<(", matchLength = 3;
|
|
2094
|
+
else if (!this._lineMode && input.length > (inputFinished ? 1 : 2) && input[1] === "<")
|
|
2095
|
+
type = "<<", matchLength = 2;
|
|
2096
|
+
else if (this._n3Mode && input.length > 1 && input[1] === "=") {
|
|
2097
|
+
matchLength = 2;
|
|
2098
|
+
if (this._isImpliedBy) type = "abbreviation", value = "<";
|
|
2099
|
+
else type = "inverse", value = ">";
|
|
2100
|
+
}
|
|
2101
|
+
break;
|
|
2102
|
+
case ">":
|
|
2103
|
+
if (input.length > 1 && input[1] === ">")
|
|
2104
|
+
type = ">>", matchLength = 2;
|
|
2105
|
+
break;
|
|
2106
|
+
case "_":
|
|
2107
|
+
if ((match2 = this._blank.exec(input)) || inputFinished && (match2 = this._blank.exec(`${input} `)))
|
|
2108
|
+
type = "blank", prefix = "_", value = match2[1];
|
|
2109
|
+
break;
|
|
2110
|
+
case '"':
|
|
2111
|
+
if (match2 = this._simpleQuotedString.exec(input))
|
|
2112
|
+
value = match2[1];
|
|
2113
|
+
else {
|
|
2114
|
+
({ value, matchLength } = this._parseLiteral(input));
|
|
2115
|
+
if (value === null)
|
|
2116
|
+
return reportSyntaxError(this);
|
|
2117
|
+
}
|
|
2118
|
+
if (match2 !== null || matchLength !== 0) {
|
|
2119
|
+
type = "literal";
|
|
2120
|
+
this._literalClosingPos = 0;
|
|
2121
|
+
}
|
|
2122
|
+
break;
|
|
2123
|
+
case "'":
|
|
2124
|
+
if (!this._lineMode) {
|
|
2125
|
+
if (match2 = this._simpleApostropheString.exec(input))
|
|
2126
|
+
value = match2[1];
|
|
2127
|
+
else {
|
|
2128
|
+
({ value, matchLength } = this._parseLiteral(input));
|
|
2129
|
+
if (value === null)
|
|
2130
|
+
return reportSyntaxError(this);
|
|
2131
|
+
}
|
|
2132
|
+
if (match2 !== null || matchLength !== 0) {
|
|
2133
|
+
type = "literal";
|
|
2134
|
+
this._literalClosingPos = 0;
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
break;
|
|
2138
|
+
case "?":
|
|
2139
|
+
if (this._n3Mode && (match2 = this._variable.exec(input)))
|
|
2140
|
+
type = "var", value = match2[0];
|
|
2141
|
+
break;
|
|
2142
|
+
case "@":
|
|
2143
|
+
if (this._previousMarker === "literal" && (match2 = this._langcode.exec(input)) && match2[1] !== "version")
|
|
2144
|
+
type = "langcode", value = match2[1];
|
|
2145
|
+
else if (match2 = this._atKeyword.exec(input))
|
|
2146
|
+
type = match2[0];
|
|
2147
|
+
break;
|
|
2148
|
+
case ".":
|
|
2149
|
+
if (input.length === 1 ? inputFinished : input[1] < "0" || input[1] > "9") {
|
|
2150
|
+
type = ".";
|
|
2151
|
+
matchLength = 1;
|
|
2152
|
+
break;
|
|
2153
|
+
}
|
|
2154
|
+
// Fall through to numerical case (could be a decimal dot)
|
|
2155
|
+
case "0":
|
|
2156
|
+
case "1":
|
|
2157
|
+
case "2":
|
|
2158
|
+
case "3":
|
|
2159
|
+
case "4":
|
|
2160
|
+
case "5":
|
|
2161
|
+
case "6":
|
|
2162
|
+
case "7":
|
|
2163
|
+
case "8":
|
|
2164
|
+
case "9":
|
|
2165
|
+
case "+":
|
|
2166
|
+
case "-":
|
|
2167
|
+
if (input[1] === "-") {
|
|
2168
|
+
if (this._previousMarker === "langcode" && (match2 = this._dircode.exec(input)))
|
|
2169
|
+
type = "dircode", matchLength = 2, value = match2[1] || match2[2], matchLength = value.length + 2;
|
|
2170
|
+
break;
|
|
2171
|
+
}
|
|
2172
|
+
if (match2 = this._number.exec(input) || inputFinished && (match2 = this._number.exec(`${input} `))) {
|
|
2173
|
+
type = "literal", value = match2[0];
|
|
2174
|
+
prefix = typeof match2[1] === "string" ? xsd.double : typeof match2[2] === "string" ? xsd.decimal : xsd.integer;
|
|
2175
|
+
}
|
|
2176
|
+
break;
|
|
2177
|
+
case "B":
|
|
2178
|
+
case "b":
|
|
2179
|
+
case "p":
|
|
2180
|
+
case "P":
|
|
2181
|
+
case "G":
|
|
2182
|
+
case "g":
|
|
2183
|
+
case "V":
|
|
2184
|
+
case "v":
|
|
2185
|
+
if (match2 = this._keyword.exec(input))
|
|
2186
|
+
type = match2[0].toUpperCase();
|
|
2187
|
+
else
|
|
2188
|
+
inconclusive = true;
|
|
2189
|
+
break;
|
|
2190
|
+
case "f":
|
|
2191
|
+
case "t":
|
|
2192
|
+
if (match2 = this._boolean.exec(input))
|
|
2193
|
+
type = "literal", value = match2[0], prefix = xsd.boolean;
|
|
2194
|
+
else
|
|
2195
|
+
inconclusive = true;
|
|
2196
|
+
break;
|
|
2197
|
+
case "a":
|
|
2198
|
+
if (match2 = this._shortPredicates.exec(input))
|
|
2199
|
+
type = "abbreviation", value = "a";
|
|
2200
|
+
else
|
|
2201
|
+
inconclusive = true;
|
|
2202
|
+
break;
|
|
2203
|
+
case "=":
|
|
2204
|
+
if (this._n3Mode && input.length > 1) {
|
|
2205
|
+
type = "abbreviation";
|
|
2206
|
+
if (input[1] !== ">")
|
|
2207
|
+
matchLength = 1, value = "=";
|
|
2208
|
+
else
|
|
2209
|
+
matchLength = 2, value = ">";
|
|
2210
|
+
}
|
|
2211
|
+
break;
|
|
2212
|
+
case "!":
|
|
2213
|
+
if (!this._n3Mode)
|
|
2214
|
+
break;
|
|
2215
|
+
case ")":
|
|
2216
|
+
if (!inputFinished && (input.length === 1 || input.length === 2 && input[1] === ">")) {
|
|
2217
|
+
break;
|
|
2218
|
+
}
|
|
2219
|
+
if (input.length > 2 && input[1] === ">" && input[2] === ">") {
|
|
2220
|
+
type = ")>>", matchLength = 3;
|
|
2221
|
+
break;
|
|
2222
|
+
}
|
|
2223
|
+
case ",":
|
|
2224
|
+
case ";":
|
|
2225
|
+
case "[":
|
|
2226
|
+
case "]":
|
|
2227
|
+
case "(":
|
|
2228
|
+
case "}":
|
|
2229
|
+
case "~":
|
|
2230
|
+
if (!this._lineMode) {
|
|
2231
|
+
matchLength = 1;
|
|
2232
|
+
type = firstChar;
|
|
2233
|
+
}
|
|
2234
|
+
break;
|
|
2235
|
+
case "{":
|
|
2236
|
+
if (!this._lineMode && input.length >= 2) {
|
|
2237
|
+
if (input[1] === "|")
|
|
2238
|
+
type = "{|", matchLength = 2;
|
|
2239
|
+
else
|
|
2240
|
+
type = firstChar, matchLength = 1;
|
|
2241
|
+
}
|
|
2242
|
+
break;
|
|
2243
|
+
case "|":
|
|
2244
|
+
if (input.length >= 2 && input[1] === "}")
|
|
2245
|
+
type = "|}", matchLength = 2;
|
|
2246
|
+
break;
|
|
2247
|
+
default:
|
|
2248
|
+
inconclusive = true;
|
|
2249
|
+
}
|
|
2250
|
+
if (inconclusive) {
|
|
2251
|
+
if ((this._previousMarker === "@prefix" || this._previousMarker === "PREFIX") && (match2 = this._prefix.exec(input)))
|
|
2252
|
+
type = "prefix", value = match2[1] || "";
|
|
2253
|
+
else if ((match2 = this._prefixed.exec(input)) || inputFinished && (match2 = this._prefixed.exec(`${input} `)))
|
|
2254
|
+
type = "prefixed", prefix = match2[1] || "", value = this._unescape(match2[2]);
|
|
2255
|
+
}
|
|
2256
|
+
if (this._previousMarker === "^^") {
|
|
2257
|
+
switch (type) {
|
|
2258
|
+
case "prefixed":
|
|
2259
|
+
type = "type";
|
|
2260
|
+
break;
|
|
2261
|
+
case "IRI":
|
|
2262
|
+
type = "typeIRI";
|
|
2263
|
+
break;
|
|
2264
|
+
default:
|
|
2265
|
+
type = "";
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
if (!type) {
|
|
2269
|
+
if (inputFinished || !/^'''|^"""/.test(input) && /\n|\r/.test(input))
|
|
2270
|
+
return reportSyntaxError(this);
|
|
2271
|
+
else
|
|
2272
|
+
return this._input = input;
|
|
2273
|
+
}
|
|
2274
|
+
const length2 = matchLength || match2[0].length;
|
|
2275
|
+
const token2 = emitToken(type, value, prefix, line, length2);
|
|
2276
|
+
this.previousToken = token2;
|
|
2277
|
+
this._previousMarker = type;
|
|
2278
|
+
input = input.substr(length2, input.length);
|
|
2279
|
+
}
|
|
2280
|
+
function emitToken(type, value, prefix, line, length2) {
|
|
2281
|
+
const start = input ? currentLineLength - input.length : currentLineLength;
|
|
2282
|
+
const end = start + length2;
|
|
2283
|
+
const token2 = { type, value, prefix, line, start, end };
|
|
2284
|
+
callback(null, token2);
|
|
2285
|
+
return token2;
|
|
2286
|
+
}
|
|
2287
|
+
function reportSyntaxError(self2) {
|
|
2288
|
+
callback(self2._syntaxError(/^\S*/.exec(input)[0]));
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
// ### `_unescape` replaces N3 escape codes by their corresponding characters
|
|
2292
|
+
_unescape(item) {
|
|
2293
|
+
let invalid = false;
|
|
2294
|
+
const replaced = item.replace(escapeSequence, (sequence, unicode4, unicode8, escapedChar) => {
|
|
2295
|
+
if (typeof unicode4 === "string")
|
|
2296
|
+
return String.fromCharCode(Number.parseInt(unicode4, 16));
|
|
2297
|
+
if (typeof unicode8 === "string") {
|
|
2298
|
+
let charCode = Number.parseInt(unicode8, 16);
|
|
2299
|
+
return charCode <= 65535 ? String.fromCharCode(Number.parseInt(unicode8, 16)) : String.fromCharCode(55296 + ((charCode -= 65536) >> 10), 56320 + (charCode & 1023));
|
|
2300
|
+
}
|
|
2301
|
+
if (escapedChar in escapeReplacements)
|
|
2302
|
+
return escapeReplacements[escapedChar];
|
|
2303
|
+
invalid = true;
|
|
2304
|
+
return "";
|
|
2305
|
+
});
|
|
2306
|
+
return invalid ? null : replaced;
|
|
2307
|
+
}
|
|
2308
|
+
// ### `_parseLiteral` parses a literal into an unescaped value
|
|
2309
|
+
_parseLiteral(input) {
|
|
2310
|
+
if (input.length >= 3) {
|
|
2311
|
+
const opening = input.match(/^(?:"""|"|'''|'|)/)[0];
|
|
2312
|
+
const openingLength = opening.length;
|
|
2313
|
+
let closingPos = Math.max(this._literalClosingPos, openingLength);
|
|
2314
|
+
while ((closingPos = input.indexOf(opening, closingPos)) > 0) {
|
|
2315
|
+
let backslashCount = 0;
|
|
2316
|
+
while (input[closingPos - backslashCount - 1] === "\\")
|
|
2317
|
+
backslashCount++;
|
|
2318
|
+
if (backslashCount % 2 === 0) {
|
|
2319
|
+
const raw = input.substring(openingLength, closingPos);
|
|
2320
|
+
const lines = raw.split(/\r\n|\r|\n/).length - 1;
|
|
2321
|
+
const matchLength = closingPos + openingLength;
|
|
2322
|
+
if (openingLength === 1 && lines !== 0 || openingLength === 3 && this._lineMode)
|
|
2323
|
+
break;
|
|
2324
|
+
this._line += lines;
|
|
2325
|
+
return { value: this._unescape(raw), matchLength };
|
|
2326
|
+
}
|
|
2327
|
+
closingPos++;
|
|
2328
|
+
}
|
|
2329
|
+
this._literalClosingPos = input.length - openingLength + 1;
|
|
2330
|
+
}
|
|
2331
|
+
return { value: "", matchLength: 0 };
|
|
2332
|
+
}
|
|
2333
|
+
// ### `_syntaxError` creates a syntax error for the given issue
|
|
2334
|
+
_syntaxError(issue) {
|
|
2335
|
+
this._input = null;
|
|
2336
|
+
const err = new Error(`Unexpected "${issue}" on line ${this._line}.`);
|
|
2337
|
+
err.context = {
|
|
2338
|
+
token: void 0,
|
|
2339
|
+
line: this._line,
|
|
2340
|
+
previousToken: this.previousToken
|
|
2341
|
+
};
|
|
2342
|
+
return err;
|
|
2343
|
+
}
|
|
2344
|
+
// ### Strips off any starting UTF BOM mark.
|
|
2345
|
+
_readStartingBom(input) {
|
|
2346
|
+
return input.startsWith("\uFEFF") ? input.substr(1) : input;
|
|
2347
|
+
}
|
|
2348
|
+
// ## Public methods
|
|
2349
|
+
// ### `tokenize` starts the transformation of an N3 document into an array of tokens.
|
|
2350
|
+
// The input can be a string or a stream.
|
|
2351
|
+
tokenize(input, callback) {
|
|
2352
|
+
this._line = 1;
|
|
2353
|
+
if (typeof input === "string") {
|
|
2354
|
+
this._input = this._readStartingBom(input);
|
|
2355
|
+
if (typeof callback === "function")
|
|
2356
|
+
queueMicrotask(() => this._tokenizeToEnd(callback, true));
|
|
2357
|
+
else {
|
|
2358
|
+
const tokens = [];
|
|
2359
|
+
let error;
|
|
2360
|
+
this._tokenizeToEnd((e, t) => e ? error = e : tokens.push(t), true);
|
|
2361
|
+
if (error) throw error;
|
|
2362
|
+
return tokens;
|
|
2363
|
+
}
|
|
2364
|
+
} else {
|
|
2365
|
+
this._pendingBuffer = null;
|
|
2366
|
+
if (typeof input.setEncoding === "function")
|
|
2367
|
+
input.setEncoding("utf8");
|
|
2368
|
+
input.on("data", (data2) => {
|
|
2369
|
+
if (this._input !== null && data2.length !== 0) {
|
|
2370
|
+
if (this._pendingBuffer) {
|
|
2371
|
+
data2 = import_buffer.Buffer.concat([this._pendingBuffer, data2]);
|
|
2372
|
+
this._pendingBuffer = null;
|
|
2373
|
+
}
|
|
2374
|
+
if (data2[data2.length - 1] & 128) {
|
|
2375
|
+
this._pendingBuffer = data2;
|
|
2376
|
+
} else {
|
|
2377
|
+
if (typeof this._input === "undefined")
|
|
2378
|
+
this._input = this._readStartingBom(typeof data2 === "string" ? data2 : data2.toString());
|
|
2379
|
+
else
|
|
2380
|
+
this._input += data2;
|
|
2381
|
+
this._tokenizeToEnd(callback, false);
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2384
|
+
});
|
|
2385
|
+
input.on("end", () => {
|
|
2386
|
+
if (typeof this._input === "string")
|
|
2387
|
+
this._tokenizeToEnd(callback, true);
|
|
2388
|
+
});
|
|
2389
|
+
input.on("error", callback);
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
};
|
|
2393
|
+
|
|
2394
|
+
// node_modules/n3/src/N3DataFactory.js
|
|
2395
|
+
var { rdf, xsd: xsd2 } = IRIs_default;
|
|
2396
|
+
var DEFAULTGRAPH;
|
|
2397
|
+
var _blankNodeCounter = 0;
|
|
2398
|
+
var DataFactory = {
|
|
2399
|
+
namedNode,
|
|
2400
|
+
blankNode,
|
|
2401
|
+
variable,
|
|
2402
|
+
literal,
|
|
2403
|
+
defaultGraph,
|
|
2404
|
+
quad,
|
|
2405
|
+
triple: quad,
|
|
2406
|
+
fromTerm,
|
|
2407
|
+
fromQuad
|
|
2408
|
+
};
|
|
2409
|
+
var N3DataFactory_default = DataFactory;
|
|
2410
|
+
var Term = class _Term {
|
|
2411
|
+
constructor(id2) {
|
|
2412
|
+
this.id = id2;
|
|
2413
|
+
}
|
|
2414
|
+
// ### The value of this term
|
|
2415
|
+
get value() {
|
|
2416
|
+
return this.id;
|
|
2417
|
+
}
|
|
2418
|
+
// ### Returns whether this object represents the same term as the other
|
|
2419
|
+
equals(other) {
|
|
2420
|
+
if (other instanceof _Term)
|
|
2421
|
+
return this.id === other.id;
|
|
2422
|
+
return !!other && this.termType === other.termType && this.value === other.value;
|
|
2423
|
+
}
|
|
2424
|
+
// ### Implement hashCode for Immutable.js, since we implement `equals`
|
|
2425
|
+
// https://immutable-js.com/docs/v4.0.0/ValueObject/#hashCode()
|
|
2426
|
+
hashCode() {
|
|
2427
|
+
return 0;
|
|
2428
|
+
}
|
|
2429
|
+
// ### Returns a plain object representation of this term
|
|
2430
|
+
toJSON() {
|
|
2431
|
+
return {
|
|
2432
|
+
termType: this.termType,
|
|
2433
|
+
value: this.value
|
|
2434
|
+
};
|
|
2435
|
+
}
|
|
2436
|
+
};
|
|
2437
|
+
var NamedNode = class extends Term {
|
|
2438
|
+
// ### The term type of this term
|
|
2439
|
+
get termType() {
|
|
2440
|
+
return "NamedNode";
|
|
2441
|
+
}
|
|
2442
|
+
};
|
|
2443
|
+
var Literal = class _Literal extends Term {
|
|
2444
|
+
// ### The term type of this term
|
|
2445
|
+
get termType() {
|
|
2446
|
+
return "Literal";
|
|
2447
|
+
}
|
|
2448
|
+
// ### The text value of this literal
|
|
2449
|
+
get value() {
|
|
2450
|
+
return this.id.substring(1, this.id.lastIndexOf('"'));
|
|
2451
|
+
}
|
|
2452
|
+
// ### The language of this literal
|
|
2453
|
+
get language() {
|
|
2454
|
+
const id2 = this.id;
|
|
2455
|
+
let atPos = id2.lastIndexOf('"') + 1;
|
|
2456
|
+
const dirPos = id2.lastIndexOf("--");
|
|
2457
|
+
return atPos < id2.length && id2[atPos++] === "@" ? (dirPos > atPos ? id2.substr(0, dirPos) : id2).substr(atPos).toLowerCase() : "";
|
|
2458
|
+
}
|
|
2459
|
+
// ### The direction of this literal
|
|
2460
|
+
get direction() {
|
|
2461
|
+
const id2 = this.id;
|
|
2462
|
+
const atPos = id2.lastIndexOf("--") + 2;
|
|
2463
|
+
return atPos > 1 && atPos < id2.length ? id2.substr(atPos).toLowerCase() : "";
|
|
2464
|
+
}
|
|
2465
|
+
// ### The datatype IRI of this literal
|
|
2466
|
+
get datatype() {
|
|
2467
|
+
return new NamedNode(this.datatypeString);
|
|
2468
|
+
}
|
|
2469
|
+
// ### The datatype string of this literal
|
|
2470
|
+
get datatypeString() {
|
|
2471
|
+
const id2 = this.id, dtPos = id2.lastIndexOf('"') + 1;
|
|
2472
|
+
const char = dtPos < id2.length ? id2[dtPos] : "";
|
|
2473
|
+
return char === "^" ? id2.substr(dtPos + 2) : (
|
|
2474
|
+
// If "@" follows, return rdf:langString or rdf:dirLangString; xsd:string otherwise
|
|
2475
|
+
char !== "@" ? xsd2.string : id2.indexOf("--", dtPos) > 0 ? rdf.dirLangString : rdf.langString
|
|
2476
|
+
);
|
|
2477
|
+
}
|
|
2478
|
+
// ### Returns whether this object represents the same term as the other
|
|
2479
|
+
equals(other) {
|
|
2480
|
+
if (other instanceof _Literal)
|
|
2481
|
+
return this.id === other.id;
|
|
2482
|
+
return !!other && !!other.datatype && this.termType === other.termType && this.value === other.value && this.language === other.language && (this.direction === other.direction || this.direction === "" && !other.direction) && this.datatype.value === other.datatype.value;
|
|
2483
|
+
}
|
|
2484
|
+
toJSON() {
|
|
2485
|
+
return {
|
|
2486
|
+
termType: this.termType,
|
|
2487
|
+
value: this.value,
|
|
2488
|
+
language: this.language,
|
|
2489
|
+
direction: this.direction,
|
|
2490
|
+
datatype: { termType: "NamedNode", value: this.datatypeString }
|
|
2491
|
+
};
|
|
2492
|
+
}
|
|
2493
|
+
};
|
|
2494
|
+
var BlankNode = class extends Term {
|
|
2495
|
+
constructor(name) {
|
|
2496
|
+
super(`_:${name}`);
|
|
2497
|
+
}
|
|
2498
|
+
// ### The term type of this term
|
|
2499
|
+
get termType() {
|
|
2500
|
+
return "BlankNode";
|
|
2501
|
+
}
|
|
2502
|
+
// ### The name of this blank node
|
|
2503
|
+
get value() {
|
|
2504
|
+
return this.id.substr(2);
|
|
2505
|
+
}
|
|
2506
|
+
};
|
|
2507
|
+
var Variable = class extends Term {
|
|
2508
|
+
constructor(name) {
|
|
2509
|
+
super(`?${name}`);
|
|
2510
|
+
}
|
|
2511
|
+
// ### The term type of this term
|
|
2512
|
+
get termType() {
|
|
2513
|
+
return "Variable";
|
|
2514
|
+
}
|
|
2515
|
+
// ### The name of this variable
|
|
2516
|
+
get value() {
|
|
2517
|
+
return this.id.substr(1);
|
|
2518
|
+
}
|
|
2519
|
+
};
|
|
2520
|
+
var DefaultGraph = class extends Term {
|
|
2521
|
+
constructor() {
|
|
2522
|
+
super("");
|
|
2523
|
+
return DEFAULTGRAPH || this;
|
|
2524
|
+
}
|
|
2525
|
+
// ### The term type of this term
|
|
2526
|
+
get termType() {
|
|
2527
|
+
return "DefaultGraph";
|
|
2528
|
+
}
|
|
2529
|
+
// ### Returns whether this object represents the same term as the other
|
|
2530
|
+
equals(other) {
|
|
2531
|
+
return this === other || !!other && this.termType === other.termType;
|
|
2532
|
+
}
|
|
2533
|
+
};
|
|
2534
|
+
DEFAULTGRAPH = new DefaultGraph();
|
|
2535
|
+
var Quad = class extends Term {
|
|
2536
|
+
constructor(subject, predicate, object2, graph) {
|
|
2537
|
+
super("");
|
|
2538
|
+
this._subject = subject;
|
|
2539
|
+
this._predicate = predicate;
|
|
2540
|
+
this._object = object2;
|
|
2541
|
+
this._graph = graph || DEFAULTGRAPH;
|
|
2542
|
+
}
|
|
2543
|
+
// ### The term type of this term
|
|
2544
|
+
get termType() {
|
|
2545
|
+
return "Quad";
|
|
2546
|
+
}
|
|
2547
|
+
get subject() {
|
|
2548
|
+
return this._subject;
|
|
2549
|
+
}
|
|
2550
|
+
get predicate() {
|
|
2551
|
+
return this._predicate;
|
|
2552
|
+
}
|
|
2553
|
+
get object() {
|
|
2554
|
+
return this._object;
|
|
2555
|
+
}
|
|
2556
|
+
get graph() {
|
|
2557
|
+
return this._graph;
|
|
2558
|
+
}
|
|
2559
|
+
// ### Returns a plain object representation of this quad
|
|
2560
|
+
toJSON() {
|
|
2561
|
+
return {
|
|
2562
|
+
termType: this.termType,
|
|
2563
|
+
subject: this._subject.toJSON(),
|
|
2564
|
+
predicate: this._predicate.toJSON(),
|
|
2565
|
+
object: this._object.toJSON(),
|
|
2566
|
+
graph: this._graph.toJSON()
|
|
2567
|
+
};
|
|
2568
|
+
}
|
|
2569
|
+
// ### Returns whether this object represents the same quad as the other
|
|
2570
|
+
equals(other) {
|
|
2571
|
+
return !!other && this._subject.equals(other.subject) && this._predicate.equals(other.predicate) && this._object.equals(other.object) && this._graph.equals(other.graph);
|
|
2572
|
+
}
|
|
2573
|
+
};
|
|
2574
|
+
function namedNode(iri) {
|
|
2575
|
+
return new NamedNode(iri);
|
|
2576
|
+
}
|
|
2577
|
+
function blankNode(name) {
|
|
2578
|
+
return new BlankNode(name || `n3-${_blankNodeCounter++}`);
|
|
2579
|
+
}
|
|
2580
|
+
function literal(value, languageOrDataType) {
|
|
2581
|
+
if (typeof languageOrDataType === "string")
|
|
2582
|
+
return new Literal(`"${value}"@${languageOrDataType.toLowerCase()}`);
|
|
2583
|
+
if (languageOrDataType !== void 0 && !("termType" in languageOrDataType)) {
|
|
2584
|
+
return new Literal(`"${value}"@${languageOrDataType.language.toLowerCase()}${languageOrDataType.direction ? `--${languageOrDataType.direction.toLowerCase()}` : ""}`);
|
|
2585
|
+
}
|
|
2586
|
+
let datatype = languageOrDataType ? languageOrDataType.value : "";
|
|
2587
|
+
if (datatype === "") {
|
|
2588
|
+
if (typeof value === "boolean")
|
|
2589
|
+
datatype = xsd2.boolean;
|
|
2590
|
+
else if (typeof value === "number") {
|
|
2591
|
+
if (Number.isFinite(value))
|
|
2592
|
+
datatype = Number.isInteger(value) ? xsd2.integer : xsd2.double;
|
|
2593
|
+
else {
|
|
2594
|
+
datatype = xsd2.double;
|
|
2595
|
+
if (!Number.isNaN(value))
|
|
2596
|
+
value = value > 0 ? "INF" : "-INF";
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
return datatype === "" || datatype === xsd2.string ? new Literal(`"${value}"`) : new Literal(`"${value}"^^${datatype}`);
|
|
2601
|
+
}
|
|
2602
|
+
function variable(name) {
|
|
2603
|
+
return new Variable(name);
|
|
2604
|
+
}
|
|
2605
|
+
function defaultGraph() {
|
|
2606
|
+
return DEFAULTGRAPH;
|
|
2607
|
+
}
|
|
2608
|
+
function quad(subject, predicate, object2, graph) {
|
|
2609
|
+
return new Quad(subject, predicate, object2, graph);
|
|
2610
|
+
}
|
|
2611
|
+
function fromTerm(term) {
|
|
2612
|
+
if (term instanceof Term)
|
|
2613
|
+
return term;
|
|
2614
|
+
switch (term.termType) {
|
|
2615
|
+
case "NamedNode":
|
|
2616
|
+
return namedNode(term.value);
|
|
2617
|
+
case "BlankNode":
|
|
2618
|
+
return blankNode(term.value);
|
|
2619
|
+
case "Variable":
|
|
2620
|
+
return variable(term.value);
|
|
2621
|
+
case "DefaultGraph":
|
|
2622
|
+
return DEFAULTGRAPH;
|
|
2623
|
+
case "Literal":
|
|
2624
|
+
return literal(term.value, term.language || term.datatype);
|
|
2625
|
+
case "Quad":
|
|
2626
|
+
return fromQuad(term);
|
|
2627
|
+
default:
|
|
2628
|
+
throw new Error(`Unexpected termType: ${term.termType}`);
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
function fromQuad(inQuad) {
|
|
2632
|
+
if (inQuad instanceof Quad)
|
|
2633
|
+
return inQuad;
|
|
2634
|
+
if (inQuad.termType !== "Quad")
|
|
2635
|
+
throw new Error(`Unexpected termType: ${inQuad.termType}`);
|
|
2636
|
+
return quad(fromTerm(inQuad.subject), fromTerm(inQuad.predicate), fromTerm(inQuad.object), fromTerm(inQuad.graph));
|
|
2637
|
+
}
|
|
2638
|
+
|
|
2639
|
+
// node_modules/n3/src/N3Parser.js
|
|
2640
|
+
var blankNodePrefix = 0;
|
|
2641
|
+
var N3Parser = class _N3Parser {
|
|
2642
|
+
constructor(options) {
|
|
2643
|
+
this._contextStack = [];
|
|
2644
|
+
this._graph = null;
|
|
2645
|
+
options = options || {};
|
|
2646
|
+
this._setBase(options.baseIRI);
|
|
2647
|
+
options.factory && initDataFactory(this, options.factory);
|
|
2648
|
+
const format = typeof options.format === "string" ? options.format.match(/\w*$/)[0].toLowerCase() : "", isTurtle = /turtle/.test(format), isTriG = /trig/.test(format), isNTriples = /triple/.test(format), isNQuads = /quad/.test(format), isN3 = this._n3Mode = /n3/.test(format), isLineMode = isNTriples || isNQuads;
|
|
2649
|
+
if (!(this._supportsNamedGraphs = !(isTurtle || isN3)))
|
|
2650
|
+
this._readPredicateOrNamedGraph = this._readPredicate;
|
|
2651
|
+
this._supportsQuads = !(isTurtle || isTriG || isNTriples || isN3);
|
|
2652
|
+
this._isImpliedBy = options.isImpliedBy;
|
|
2653
|
+
if (isLineMode)
|
|
2654
|
+
this._resolveRelativeIRI = (iri) => {
|
|
2655
|
+
return null;
|
|
2656
|
+
};
|
|
2657
|
+
this._blankNodePrefix = typeof options.blankNodePrefix !== "string" ? "" : options.blankNodePrefix.replace(/^(?!_:)/, "_:");
|
|
2658
|
+
this._lexer = options.lexer || new N3Lexer({ lineMode: isLineMode, n3: isN3, isImpliedBy: this._isImpliedBy });
|
|
2659
|
+
this._explicitQuantifiers = !!options.explicitQuantifiers;
|
|
2660
|
+
this._parseUnsupportedVersions = !!options.parseUnsupportedVersions;
|
|
2661
|
+
this._version = options.version;
|
|
2662
|
+
}
|
|
2663
|
+
// ## Static class methods
|
|
2664
|
+
// ### `_resetBlankNodePrefix` restarts blank node prefix identification
|
|
2665
|
+
static _resetBlankNodePrefix() {
|
|
2666
|
+
blankNodePrefix = 0;
|
|
2667
|
+
}
|
|
2668
|
+
// ## Private methods
|
|
2669
|
+
// ### `_setBase` sets the base IRI to resolve relative IRIs
|
|
2670
|
+
_setBase(baseIRI) {
|
|
2671
|
+
if (!baseIRI) {
|
|
2672
|
+
this._base = "";
|
|
2673
|
+
this._basePath = "";
|
|
2674
|
+
} else {
|
|
2675
|
+
const fragmentPos = baseIRI.indexOf("#");
|
|
2676
|
+
if (fragmentPos >= 0)
|
|
2677
|
+
baseIRI = baseIRI.substr(0, fragmentPos);
|
|
2678
|
+
this._base = baseIRI;
|
|
2679
|
+
this._basePath = baseIRI.indexOf("/") < 0 ? baseIRI : baseIRI.replace(/[^\/?]*(?:\?.*)?$/, "");
|
|
2680
|
+
baseIRI = baseIRI.match(/^(?:([a-z][a-z0-9+.-]*:))?(?:\/\/[^\/]*)?/i);
|
|
2681
|
+
this._baseRoot = baseIRI[0];
|
|
2682
|
+
this._baseScheme = baseIRI[1];
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2685
|
+
// ### `_saveContext` stores the current parsing context
|
|
2686
|
+
// when entering a new scope (list, blank node, formula)
|
|
2687
|
+
_saveContext(type, graph, subject, predicate, object2) {
|
|
2688
|
+
const n3Mode = this._n3Mode;
|
|
2689
|
+
this._contextStack.push({
|
|
2690
|
+
type,
|
|
2691
|
+
subject,
|
|
2692
|
+
predicate,
|
|
2693
|
+
object: object2,
|
|
2694
|
+
graph,
|
|
2695
|
+
inverse: n3Mode ? this._inversePredicate : false,
|
|
2696
|
+
blankPrefix: n3Mode ? this._prefixes._ : "",
|
|
2697
|
+
quantified: n3Mode ? this._quantified : null
|
|
2698
|
+
});
|
|
2699
|
+
if (n3Mode) {
|
|
2700
|
+
this._inversePredicate = false;
|
|
2701
|
+
this._prefixes._ = this._graph ? `${this._graph.value}.` : ".";
|
|
2702
|
+
this._quantified = Object.create(this._quantified);
|
|
2703
|
+
}
|
|
2704
|
+
}
|
|
2705
|
+
// ### `_restoreContext` restores the parent context
|
|
2706
|
+
// when leaving a scope (list, blank node, formula)
|
|
2707
|
+
_restoreContext(type, token2) {
|
|
2708
|
+
const context = this._contextStack.pop();
|
|
2709
|
+
if (!context || context.type !== type)
|
|
2710
|
+
return this._error(`Unexpected ${token2.type}`, token2);
|
|
2711
|
+
this._subject = context.subject;
|
|
2712
|
+
this._predicate = context.predicate;
|
|
2713
|
+
this._object = context.object;
|
|
2714
|
+
this._graph = context.graph;
|
|
2715
|
+
if (this._n3Mode) {
|
|
2716
|
+
this._inversePredicate = context.inverse;
|
|
2717
|
+
this._prefixes._ = context.blankPrefix;
|
|
2718
|
+
this._quantified = context.quantified;
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
// ### `_readBeforeTopContext` is called once only at the start of parsing.
|
|
2722
|
+
_readBeforeTopContext(token2) {
|
|
2723
|
+
if (this._version && !this._isValidVersion(this._version))
|
|
2724
|
+
return this._error(`Detected unsupported version as media type parameter: "${this._version}"`, token2);
|
|
2725
|
+
return this._readInTopContext(token2);
|
|
2726
|
+
}
|
|
2727
|
+
// ### `_readInTopContext` reads a token when in the top context
|
|
2728
|
+
_readInTopContext(token2) {
|
|
2729
|
+
switch (token2.type) {
|
|
2730
|
+
// If an EOF token arrives in the top context, signal that we're done
|
|
2731
|
+
case "eof":
|
|
2732
|
+
if (this._graph !== null)
|
|
2733
|
+
return this._error("Unclosed graph", token2);
|
|
2734
|
+
delete this._prefixes._;
|
|
2735
|
+
return this._callback(null, null, this._prefixes);
|
|
2736
|
+
// It could be a prefix declaration
|
|
2737
|
+
case "PREFIX":
|
|
2738
|
+
this._sparqlStyle = true;
|
|
2739
|
+
case "@prefix":
|
|
2740
|
+
return this._readPrefix;
|
|
2741
|
+
// It could be a base declaration
|
|
2742
|
+
case "BASE":
|
|
2743
|
+
this._sparqlStyle = true;
|
|
2744
|
+
case "@base":
|
|
2745
|
+
return this._readBaseIRI;
|
|
2746
|
+
// It could be a version declaration
|
|
2747
|
+
case "VERSION":
|
|
2748
|
+
this._sparqlStyle = true;
|
|
2749
|
+
case "@version":
|
|
2750
|
+
return this._readVersion;
|
|
2751
|
+
// It could be a graph
|
|
2752
|
+
case "{":
|
|
2753
|
+
if (this._supportsNamedGraphs) {
|
|
2754
|
+
this._graph = "";
|
|
2755
|
+
this._subject = null;
|
|
2756
|
+
return this._readSubject;
|
|
2757
|
+
}
|
|
2758
|
+
case "GRAPH":
|
|
2759
|
+
if (this._supportsNamedGraphs)
|
|
2760
|
+
return this._readNamedGraphLabel;
|
|
2761
|
+
// Otherwise, the next token must be a subject
|
|
2762
|
+
default:
|
|
2763
|
+
return this._readSubject(token2);
|
|
2764
|
+
}
|
|
2765
|
+
}
|
|
2766
|
+
// ### `_readEntity` reads an IRI, prefixed name, blank node, or variable
|
|
2767
|
+
_readEntity(token2, quantifier) {
|
|
2768
|
+
let value;
|
|
2769
|
+
switch (token2.type) {
|
|
2770
|
+
// Read a relative or absolute IRI
|
|
2771
|
+
case "IRI":
|
|
2772
|
+
case "typeIRI":
|
|
2773
|
+
const iri = this._resolveIRI(token2.value);
|
|
2774
|
+
if (iri === null)
|
|
2775
|
+
return this._error("Invalid IRI", token2);
|
|
2776
|
+
value = this._factory.namedNode(iri);
|
|
2777
|
+
break;
|
|
2778
|
+
// Read a prefixed name
|
|
2779
|
+
case "type":
|
|
2780
|
+
case "prefixed":
|
|
2781
|
+
const prefix = this._prefixes[token2.prefix];
|
|
2782
|
+
if (prefix === void 0)
|
|
2783
|
+
return this._error(`Undefined prefix "${token2.prefix}:"`, token2);
|
|
2784
|
+
value = this._factory.namedNode(prefix + token2.value);
|
|
2785
|
+
break;
|
|
2786
|
+
// Read a blank node
|
|
2787
|
+
case "blank":
|
|
2788
|
+
value = this._factory.blankNode(this._prefixes[token2.prefix] + token2.value);
|
|
2789
|
+
break;
|
|
2790
|
+
// Read a variable
|
|
2791
|
+
case "var":
|
|
2792
|
+
value = this._factory.variable(token2.value.substr(1));
|
|
2793
|
+
break;
|
|
2794
|
+
// Everything else is not an entity
|
|
2795
|
+
default:
|
|
2796
|
+
return this._error(`Expected entity but got ${token2.type}`, token2);
|
|
2797
|
+
}
|
|
2798
|
+
if (!quantifier && this._n3Mode && value.id in this._quantified)
|
|
2799
|
+
value = this._quantified[value.id];
|
|
2800
|
+
return value;
|
|
2801
|
+
}
|
|
2802
|
+
// ### `_readSubject` reads a quad's subject
|
|
2803
|
+
_readSubject(token2) {
|
|
2804
|
+
this._predicate = null;
|
|
2805
|
+
switch (token2.type) {
|
|
2806
|
+
case "[":
|
|
2807
|
+
this._saveContext(
|
|
2808
|
+
"blank",
|
|
2809
|
+
this._graph,
|
|
2810
|
+
this._subject = this._factory.blankNode(),
|
|
2811
|
+
null,
|
|
2812
|
+
null
|
|
2813
|
+
);
|
|
2814
|
+
return this._readBlankNodeHead;
|
|
2815
|
+
case "(":
|
|
2816
|
+
const stack = this._contextStack, parent2 = stack.length && stack[stack.length - 1];
|
|
2817
|
+
if (parent2.type === "<<") {
|
|
2818
|
+
return this._error("Unexpected list in reified triple", token2);
|
|
2819
|
+
}
|
|
2820
|
+
this._saveContext("list", this._graph, this.RDF_NIL, null, null);
|
|
2821
|
+
this._subject = null;
|
|
2822
|
+
return this._readListItem;
|
|
2823
|
+
case "{":
|
|
2824
|
+
if (!this._n3Mode)
|
|
2825
|
+
return this._error("Unexpected graph", token2);
|
|
2826
|
+
this._saveContext(
|
|
2827
|
+
"formula",
|
|
2828
|
+
this._graph,
|
|
2829
|
+
this._graph = this._factory.blankNode(),
|
|
2830
|
+
null,
|
|
2831
|
+
null
|
|
2832
|
+
);
|
|
2833
|
+
return this._readSubject;
|
|
2834
|
+
case "}":
|
|
2835
|
+
return this._readPunctuation(token2);
|
|
2836
|
+
case "@forSome":
|
|
2837
|
+
if (!this._n3Mode)
|
|
2838
|
+
return this._error('Unexpected "@forSome"', token2);
|
|
2839
|
+
this._subject = null;
|
|
2840
|
+
this._predicate = this.N3_FORSOME;
|
|
2841
|
+
this._quantifier = "blankNode";
|
|
2842
|
+
return this._readQuantifierList;
|
|
2843
|
+
case "@forAll":
|
|
2844
|
+
if (!this._n3Mode)
|
|
2845
|
+
return this._error('Unexpected "@forAll"', token2);
|
|
2846
|
+
this._subject = null;
|
|
2847
|
+
this._predicate = this.N3_FORALL;
|
|
2848
|
+
this._quantifier = "variable";
|
|
2849
|
+
return this._readQuantifierList;
|
|
2850
|
+
case "literal":
|
|
2851
|
+
if (!this._n3Mode)
|
|
2852
|
+
return this._error("Unexpected literal", token2);
|
|
2853
|
+
if (token2.prefix.length === 0) {
|
|
2854
|
+
this._literalValue = token2.value;
|
|
2855
|
+
return this._completeSubjectLiteral;
|
|
2856
|
+
} else
|
|
2857
|
+
this._subject = this._factory.literal(token2.value, this._factory.namedNode(token2.prefix));
|
|
2858
|
+
break;
|
|
2859
|
+
case "<<(":
|
|
2860
|
+
if (!this._n3Mode)
|
|
2861
|
+
return this._error("Disallowed triple term as subject", token2);
|
|
2862
|
+
this._saveContext("<<(", this._graph, null, null, null);
|
|
2863
|
+
this._graph = null;
|
|
2864
|
+
return this._readSubject;
|
|
2865
|
+
case "<<":
|
|
2866
|
+
this._saveContext("<<", this._graph, null, null, null);
|
|
2867
|
+
this._graph = null;
|
|
2868
|
+
return this._readSubject;
|
|
2869
|
+
default:
|
|
2870
|
+
if ((this._subject = this._readEntity(token2)) === void 0)
|
|
2871
|
+
return;
|
|
2872
|
+
if (this._n3Mode)
|
|
2873
|
+
return this._getPathReader(this._readPredicateOrNamedGraph);
|
|
2874
|
+
}
|
|
2875
|
+
return this._readPredicateOrNamedGraph;
|
|
2876
|
+
}
|
|
2877
|
+
// ### `_readPredicate` reads a quad's predicate
|
|
2878
|
+
_readPredicate(token2) {
|
|
2879
|
+
const type = token2.type;
|
|
2880
|
+
switch (type) {
|
|
2881
|
+
case "inverse":
|
|
2882
|
+
this._inversePredicate = true;
|
|
2883
|
+
case "abbreviation":
|
|
2884
|
+
this._predicate = this.ABBREVIATIONS[token2.value];
|
|
2885
|
+
break;
|
|
2886
|
+
case ".":
|
|
2887
|
+
case "]":
|
|
2888
|
+
case "}":
|
|
2889
|
+
case "|}":
|
|
2890
|
+
if (this._predicate === null)
|
|
2891
|
+
return this._error(`Unexpected ${type}`, token2);
|
|
2892
|
+
this._subject = null;
|
|
2893
|
+
return type === "]" ? this._readBlankNodeTail(token2) : this._readPunctuation(token2);
|
|
2894
|
+
case ";":
|
|
2895
|
+
return this._predicate !== null ? this._readPredicate : this._error("Expected predicate but got ;", token2);
|
|
2896
|
+
case "[":
|
|
2897
|
+
if (this._n3Mode) {
|
|
2898
|
+
this._saveContext(
|
|
2899
|
+
"blank",
|
|
2900
|
+
this._graph,
|
|
2901
|
+
this._subject,
|
|
2902
|
+
this._subject = this._factory.blankNode(),
|
|
2903
|
+
null
|
|
2904
|
+
);
|
|
2905
|
+
return this._readBlankNodeHead;
|
|
2906
|
+
}
|
|
2907
|
+
case "blank":
|
|
2908
|
+
if (!this._n3Mode)
|
|
2909
|
+
return this._error("Disallowed blank node as predicate", token2);
|
|
2910
|
+
default:
|
|
2911
|
+
if ((this._predicate = this._readEntity(token2)) === void 0)
|
|
2912
|
+
return;
|
|
2913
|
+
}
|
|
2914
|
+
this._validAnnotation = true;
|
|
2915
|
+
return this._readObject;
|
|
2916
|
+
}
|
|
2917
|
+
// ### `_readObject` reads a quad's object
|
|
2918
|
+
_readObject(token2) {
|
|
2919
|
+
switch (token2.type) {
|
|
2920
|
+
case "literal":
|
|
2921
|
+
if (token2.prefix.length === 0) {
|
|
2922
|
+
this._literalValue = token2.value;
|
|
2923
|
+
return this._readDataTypeOrLang;
|
|
2924
|
+
} else
|
|
2925
|
+
this._object = this._factory.literal(token2.value, this._factory.namedNode(token2.prefix));
|
|
2926
|
+
break;
|
|
2927
|
+
case "[":
|
|
2928
|
+
this._saveContext(
|
|
2929
|
+
"blank",
|
|
2930
|
+
this._graph,
|
|
2931
|
+
this._subject,
|
|
2932
|
+
this._predicate,
|
|
2933
|
+
this._subject = this._factory.blankNode()
|
|
2934
|
+
);
|
|
2935
|
+
return this._readBlankNodeHead;
|
|
2936
|
+
case "(":
|
|
2937
|
+
const stack = this._contextStack, parent2 = stack.length && stack[stack.length - 1];
|
|
2938
|
+
if (parent2.type === "<<") {
|
|
2939
|
+
return this._error("Unexpected list in reified triple", token2);
|
|
2940
|
+
}
|
|
2941
|
+
this._saveContext("list", this._graph, this._subject, this._predicate, this.RDF_NIL);
|
|
2942
|
+
this._subject = null;
|
|
2943
|
+
return this._readListItem;
|
|
2944
|
+
case "{":
|
|
2945
|
+
if (!this._n3Mode)
|
|
2946
|
+
return this._error("Unexpected graph", token2);
|
|
2947
|
+
this._saveContext(
|
|
2948
|
+
"formula",
|
|
2949
|
+
this._graph,
|
|
2950
|
+
this._subject,
|
|
2951
|
+
this._predicate,
|
|
2952
|
+
this._graph = this._factory.blankNode()
|
|
2953
|
+
);
|
|
2954
|
+
return this._readSubject;
|
|
2955
|
+
case "<<(":
|
|
2956
|
+
this._saveContext("<<(", this._graph, this._subject, this._predicate, null);
|
|
2957
|
+
this._graph = null;
|
|
2958
|
+
return this._readSubject;
|
|
2959
|
+
case "<<":
|
|
2960
|
+
this._saveContext("<<", this._graph, this._subject, this._predicate, null);
|
|
2961
|
+
this._graph = null;
|
|
2962
|
+
return this._readSubject;
|
|
2963
|
+
default:
|
|
2964
|
+
if ((this._object = this._readEntity(token2)) === void 0)
|
|
2965
|
+
return;
|
|
2966
|
+
if (this._n3Mode)
|
|
2967
|
+
return this._getPathReader(this._getContextEndReader());
|
|
2968
|
+
}
|
|
2969
|
+
return this._getContextEndReader();
|
|
2970
|
+
}
|
|
2971
|
+
// ### `_readPredicateOrNamedGraph` reads a quad's predicate, or a named graph
|
|
2972
|
+
_readPredicateOrNamedGraph(token2) {
|
|
2973
|
+
return token2.type === "{" ? this._readGraph(token2) : this._readPredicate(token2);
|
|
2974
|
+
}
|
|
2975
|
+
// ### `_readGraph` reads a graph
|
|
2976
|
+
_readGraph(token2) {
|
|
2977
|
+
if (token2.type !== "{")
|
|
2978
|
+
return this._error(`Expected graph but got ${token2.type}`, token2);
|
|
2979
|
+
this._graph = this._subject, this._subject = null;
|
|
2980
|
+
return this._readSubject;
|
|
2981
|
+
}
|
|
2982
|
+
// ### `_readBlankNodeHead` reads the head of a blank node
|
|
2983
|
+
_readBlankNodeHead(token2) {
|
|
2984
|
+
if (token2.type === "]") {
|
|
2985
|
+
this._subject = null;
|
|
2986
|
+
return this._readBlankNodeTail(token2);
|
|
2987
|
+
} else {
|
|
2988
|
+
const stack = this._contextStack, parentParent = stack.length > 1 && stack[stack.length - 2];
|
|
2989
|
+
if (parentParent.type === "<<") {
|
|
2990
|
+
return this._error("Unexpected compound blank node expression in reified triple", token2);
|
|
2991
|
+
}
|
|
2992
|
+
this._predicate = null;
|
|
2993
|
+
return this._readPredicate(token2);
|
|
2994
|
+
}
|
|
2995
|
+
}
|
|
2996
|
+
// ### `_readBlankNodeTail` reads the end of a blank node
|
|
2997
|
+
_readBlankNodeTail(token2) {
|
|
2998
|
+
if (token2.type !== "]")
|
|
2999
|
+
return this._readBlankNodePunctuation(token2);
|
|
3000
|
+
if (this._subject !== null)
|
|
3001
|
+
this._emit(this._subject, this._predicate, this._object, this._graph);
|
|
3002
|
+
const empty2 = this._predicate === null;
|
|
3003
|
+
this._restoreContext("blank", token2);
|
|
3004
|
+
if (this._object !== null)
|
|
3005
|
+
return this._getContextEndReader();
|
|
3006
|
+
else if (this._predicate !== null)
|
|
3007
|
+
return this._readObject;
|
|
3008
|
+
else
|
|
3009
|
+
return empty2 ? this._readPredicateOrNamedGraph : this._readPredicateAfterBlank;
|
|
3010
|
+
}
|
|
3011
|
+
// ### `_readPredicateAfterBlank` reads a predicate after an anonymous blank node
|
|
3012
|
+
_readPredicateAfterBlank(token2) {
|
|
3013
|
+
switch (token2.type) {
|
|
3014
|
+
case ".":
|
|
3015
|
+
case "}":
|
|
3016
|
+
this._subject = null;
|
|
3017
|
+
return this._readPunctuation(token2);
|
|
3018
|
+
default:
|
|
3019
|
+
return this._readPredicate(token2);
|
|
3020
|
+
}
|
|
3021
|
+
}
|
|
3022
|
+
// ### `_readListItem` reads items from a list
|
|
3023
|
+
_readListItem(token2) {
|
|
3024
|
+
let item = null, list = null, next3 = this._readListItem;
|
|
3025
|
+
const previousList = this._subject, stack = this._contextStack, parent2 = stack[stack.length - 1];
|
|
3026
|
+
switch (token2.type) {
|
|
3027
|
+
case "[":
|
|
3028
|
+
this._saveContext(
|
|
3029
|
+
"blank",
|
|
3030
|
+
this._graph,
|
|
3031
|
+
list = this._factory.blankNode(),
|
|
3032
|
+
this.RDF_FIRST,
|
|
3033
|
+
this._subject = item = this._factory.blankNode()
|
|
3034
|
+
);
|
|
3035
|
+
next3 = this._readBlankNodeHead;
|
|
3036
|
+
break;
|
|
3037
|
+
case "(":
|
|
3038
|
+
this._saveContext(
|
|
3039
|
+
"list",
|
|
3040
|
+
this._graph,
|
|
3041
|
+
list = this._factory.blankNode(),
|
|
3042
|
+
this.RDF_FIRST,
|
|
3043
|
+
this.RDF_NIL
|
|
3044
|
+
);
|
|
3045
|
+
this._subject = null;
|
|
3046
|
+
break;
|
|
3047
|
+
case ")":
|
|
3048
|
+
this._restoreContext("list", token2);
|
|
3049
|
+
if (stack.length !== 0 && stack[stack.length - 1].type === "list")
|
|
3050
|
+
this._emit(this._subject, this._predicate, this._object, this._graph);
|
|
3051
|
+
if (this._predicate === null) {
|
|
3052
|
+
next3 = this._readPredicate;
|
|
3053
|
+
if (this._subject === this.RDF_NIL)
|
|
3054
|
+
return next3;
|
|
3055
|
+
} else {
|
|
3056
|
+
next3 = this._getContextEndReader();
|
|
3057
|
+
if (this._object === this.RDF_NIL)
|
|
3058
|
+
return next3;
|
|
3059
|
+
}
|
|
3060
|
+
list = this.RDF_NIL;
|
|
3061
|
+
break;
|
|
3062
|
+
case "literal":
|
|
3063
|
+
if (token2.prefix.length === 0) {
|
|
3064
|
+
this._literalValue = token2.value;
|
|
3065
|
+
next3 = this._readListItemDataTypeOrLang;
|
|
3066
|
+
} else {
|
|
3067
|
+
item = this._factory.literal(token2.value, this._factory.namedNode(token2.prefix));
|
|
3068
|
+
next3 = this._getContextEndReader();
|
|
3069
|
+
}
|
|
3070
|
+
break;
|
|
3071
|
+
case "{":
|
|
3072
|
+
if (!this._n3Mode)
|
|
3073
|
+
return this._error("Unexpected graph", token2);
|
|
3074
|
+
this._saveContext(
|
|
3075
|
+
"formula",
|
|
3076
|
+
this._graph,
|
|
3077
|
+
this._subject,
|
|
3078
|
+
this._predicate,
|
|
3079
|
+
this._graph = this._factory.blankNode()
|
|
3080
|
+
);
|
|
3081
|
+
return this._readSubject;
|
|
3082
|
+
case "<<":
|
|
3083
|
+
this._saveContext("<<", this._graph, null, null, null);
|
|
3084
|
+
this._graph = null;
|
|
3085
|
+
next3 = this._readSubject;
|
|
3086
|
+
break;
|
|
3087
|
+
default:
|
|
3088
|
+
if ((item = this._readEntity(token2)) === void 0)
|
|
3089
|
+
return;
|
|
3090
|
+
}
|
|
3091
|
+
if (list === null)
|
|
3092
|
+
this._subject = list = this._factory.blankNode();
|
|
3093
|
+
if (token2.type === "<<")
|
|
3094
|
+
stack[stack.length - 1].subject = this._subject;
|
|
3095
|
+
if (previousList === null) {
|
|
3096
|
+
if (parent2.predicate === null)
|
|
3097
|
+
parent2.subject = list;
|
|
3098
|
+
else
|
|
3099
|
+
parent2.object = list;
|
|
3100
|
+
} else {
|
|
3101
|
+
this._emit(previousList, this.RDF_REST, list, this._graph);
|
|
3102
|
+
}
|
|
3103
|
+
if (item !== null) {
|
|
3104
|
+
if (this._n3Mode && (token2.type === "IRI" || token2.type === "prefixed")) {
|
|
3105
|
+
this._saveContext("item", this._graph, list, this.RDF_FIRST, item);
|
|
3106
|
+
this._subject = item, this._predicate = null;
|
|
3107
|
+
return this._getPathReader(this._readListItem);
|
|
3108
|
+
}
|
|
3109
|
+
this._emit(list, this.RDF_FIRST, item, this._graph);
|
|
3110
|
+
}
|
|
3111
|
+
return next3;
|
|
3112
|
+
}
|
|
3113
|
+
// ### `_readDataTypeOrLang` reads an _optional_ datatype or language
|
|
3114
|
+
_readDataTypeOrLang(token2) {
|
|
3115
|
+
return this._completeObjectLiteral(token2, false);
|
|
3116
|
+
}
|
|
3117
|
+
// ### `_readListItemDataTypeOrLang` reads an _optional_ datatype or language in a list
|
|
3118
|
+
_readListItemDataTypeOrLang(token2) {
|
|
3119
|
+
return this._completeObjectLiteral(token2, true);
|
|
3120
|
+
}
|
|
3121
|
+
// ### `_completeLiteral` completes a literal with an optional datatype or language
|
|
3122
|
+
_completeLiteral(token2, component) {
|
|
3123
|
+
let literal2 = this._factory.literal(this._literalValue);
|
|
3124
|
+
let readCb;
|
|
3125
|
+
switch (token2.type) {
|
|
3126
|
+
// Create a datatyped literal
|
|
3127
|
+
case "type":
|
|
3128
|
+
case "typeIRI":
|
|
3129
|
+
const datatype = this._readEntity(token2);
|
|
3130
|
+
if (datatype === void 0) return;
|
|
3131
|
+
if (datatype.value === IRIs_default.rdf.langString || datatype.value === IRIs_default.rdf.dirLangString) {
|
|
3132
|
+
return this._error("Detected illegal (directional) languaged-tagged string with explicit datatype", token2);
|
|
3133
|
+
}
|
|
3134
|
+
literal2 = this._factory.literal(this._literalValue, datatype);
|
|
3135
|
+
token2 = null;
|
|
3136
|
+
break;
|
|
3137
|
+
// Create a language-tagged string
|
|
3138
|
+
case "langcode":
|
|
3139
|
+
if (token2.value.length > 8)
|
|
3140
|
+
return this._error("Detected language tag of length larger than 8", token2);
|
|
3141
|
+
literal2 = this._factory.literal(this._literalValue, token2.value);
|
|
3142
|
+
this._literalLanguage = token2.value;
|
|
3143
|
+
token2 = null;
|
|
3144
|
+
readCb = this._readDirCode.bind(this, component);
|
|
3145
|
+
break;
|
|
3146
|
+
}
|
|
3147
|
+
return { token: token2, literal: literal2, readCb };
|
|
3148
|
+
}
|
|
3149
|
+
_readDirCode(component, listItem, token2) {
|
|
3150
|
+
if (token2.type === "dircode") {
|
|
3151
|
+
const term = this._factory.literal(this._literalValue, { language: this._literalLanguage, direction: token2.value });
|
|
3152
|
+
if (component === "subject")
|
|
3153
|
+
this._subject = term;
|
|
3154
|
+
else
|
|
3155
|
+
this._object = term;
|
|
3156
|
+
this._literalLanguage = void 0;
|
|
3157
|
+
token2 = null;
|
|
3158
|
+
}
|
|
3159
|
+
if (component === "subject")
|
|
3160
|
+
return token2 === null ? this._readPredicateOrNamedGraph : this._readPredicateOrNamedGraph(token2);
|
|
3161
|
+
return this._completeObjectLiteralPost(token2, listItem);
|
|
3162
|
+
}
|
|
3163
|
+
// Completes a literal in subject position
|
|
3164
|
+
_completeSubjectLiteral(token2) {
|
|
3165
|
+
const completed = this._completeLiteral(token2, "subject");
|
|
3166
|
+
this._subject = completed.literal;
|
|
3167
|
+
if (completed.readCb)
|
|
3168
|
+
return completed.readCb.bind(this, false);
|
|
3169
|
+
return this._readPredicateOrNamedGraph;
|
|
3170
|
+
}
|
|
3171
|
+
// Completes a literal in object position
|
|
3172
|
+
_completeObjectLiteral(token2, listItem) {
|
|
3173
|
+
const completed = this._completeLiteral(token2, "object");
|
|
3174
|
+
if (!completed)
|
|
3175
|
+
return;
|
|
3176
|
+
this._object = completed.literal;
|
|
3177
|
+
if (completed.readCb)
|
|
3178
|
+
return completed.readCb.bind(this, listItem);
|
|
3179
|
+
return this._completeObjectLiteralPost(completed.token, listItem);
|
|
3180
|
+
}
|
|
3181
|
+
_completeObjectLiteralPost(token2, listItem) {
|
|
3182
|
+
if (listItem)
|
|
3183
|
+
this._emit(this._subject, this.RDF_FIRST, this._object, this._graph);
|
|
3184
|
+
if (token2 === null)
|
|
3185
|
+
return this._getContextEndReader();
|
|
3186
|
+
else {
|
|
3187
|
+
this._readCallback = this._getContextEndReader();
|
|
3188
|
+
return this._readCallback(token2);
|
|
3189
|
+
}
|
|
3190
|
+
}
|
|
3191
|
+
// ### `_readFormulaTail` reads the end of a formula
|
|
3192
|
+
_readFormulaTail(token2) {
|
|
3193
|
+
if (token2.type !== "}")
|
|
3194
|
+
return this._readPunctuation(token2);
|
|
3195
|
+
if (this._subject !== null)
|
|
3196
|
+
this._emit(this._subject, this._predicate, this._object, this._graph);
|
|
3197
|
+
this._restoreContext("formula", token2);
|
|
3198
|
+
return this._object === null ? this._readPredicate : this._getContextEndReader();
|
|
3199
|
+
}
|
|
3200
|
+
// ### `_readPunctuation` reads punctuation between quads or quad parts
|
|
3201
|
+
_readPunctuation(token2) {
|
|
3202
|
+
let next3, graph = this._graph, startingAnnotation = false;
|
|
3203
|
+
const subject = this._subject, inversePredicate = this._inversePredicate;
|
|
3204
|
+
switch (token2.type) {
|
|
3205
|
+
// A closing brace ends a graph
|
|
3206
|
+
case "}":
|
|
3207
|
+
if (this._graph === null)
|
|
3208
|
+
return this._error("Unexpected graph closing", token2);
|
|
3209
|
+
if (this._n3Mode)
|
|
3210
|
+
return this._readFormulaTail(token2);
|
|
3211
|
+
this._graph = null;
|
|
3212
|
+
// A dot just ends the statement, without sharing anything with the next
|
|
3213
|
+
case ".":
|
|
3214
|
+
this._subject = null;
|
|
3215
|
+
this._tripleTerm = null;
|
|
3216
|
+
next3 = this._contextStack.length ? this._readSubject : this._readInTopContext;
|
|
3217
|
+
if (inversePredicate) this._inversePredicate = false;
|
|
3218
|
+
break;
|
|
3219
|
+
// Semicolon means the subject is shared; predicate and object are different
|
|
3220
|
+
case ";":
|
|
3221
|
+
next3 = this._readPredicate;
|
|
3222
|
+
break;
|
|
3223
|
+
// Comma means both the subject and predicate are shared; the object is different
|
|
3224
|
+
case ",":
|
|
3225
|
+
next3 = this._readObject;
|
|
3226
|
+
break;
|
|
3227
|
+
// ~ is allowed in the annotation syntax
|
|
3228
|
+
case "~":
|
|
3229
|
+
next3 = this._readReifierInAnnotation;
|
|
3230
|
+
startingAnnotation = true;
|
|
3231
|
+
break;
|
|
3232
|
+
// {| means that the current triple is annotated with predicate-object pairs.
|
|
3233
|
+
case "{|":
|
|
3234
|
+
this._subject = this._readTripleTerm();
|
|
3235
|
+
this._validAnnotation = false;
|
|
3236
|
+
startingAnnotation = true;
|
|
3237
|
+
next3 = this._readPredicate;
|
|
3238
|
+
break;
|
|
3239
|
+
// |} means that the current reified triple in annotation syntax is finalized.
|
|
3240
|
+
case "|}":
|
|
3241
|
+
if (!this._annotation)
|
|
3242
|
+
return this._error("Unexpected annotation syntax closing", token2);
|
|
3243
|
+
if (!this._validAnnotation)
|
|
3244
|
+
return this._error("Annotation block can not be empty", token2);
|
|
3245
|
+
this._subject = null;
|
|
3246
|
+
this._annotation = false;
|
|
3247
|
+
next3 = this._readPunctuation;
|
|
3248
|
+
break;
|
|
3249
|
+
default:
|
|
3250
|
+
if (this._supportsQuads && this._graph === null && (graph = this._readEntity(token2)) !== void 0) {
|
|
3251
|
+
next3 = this._readQuadPunctuation;
|
|
3252
|
+
break;
|
|
3253
|
+
}
|
|
3254
|
+
return this._error(`Expected punctuation to follow "${this._object.id}"`, token2);
|
|
3255
|
+
}
|
|
3256
|
+
if (subject !== null && (!startingAnnotation || startingAnnotation && !this._annotation)) {
|
|
3257
|
+
const predicate = this._predicate, object2 = this._object;
|
|
3258
|
+
if (!inversePredicate)
|
|
3259
|
+
this._emit(subject, predicate, object2, graph);
|
|
3260
|
+
else
|
|
3261
|
+
this._emit(object2, predicate, subject, graph);
|
|
12
3262
|
}
|
|
3263
|
+
if (startingAnnotation) {
|
|
3264
|
+
this._annotation = true;
|
|
3265
|
+
}
|
|
3266
|
+
return next3;
|
|
13
3267
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
3268
|
+
// ### `_readBlankNodePunctuation` reads punctuation in a blank node
|
|
3269
|
+
_readBlankNodePunctuation(token2) {
|
|
3270
|
+
let next3;
|
|
3271
|
+
switch (token2.type) {
|
|
3272
|
+
// Semicolon means the subject is shared; predicate and object are different
|
|
3273
|
+
case ";":
|
|
3274
|
+
next3 = this._readPredicate;
|
|
3275
|
+
break;
|
|
3276
|
+
// Comma means both the subject and predicate are shared; the object is different
|
|
3277
|
+
case ",":
|
|
3278
|
+
next3 = this._readObject;
|
|
3279
|
+
break;
|
|
3280
|
+
default:
|
|
3281
|
+
return this._error(`Expected punctuation to follow "${this._object.id}"`, token2);
|
|
3282
|
+
}
|
|
3283
|
+
this._emit(this._subject, this._predicate, this._object, this._graph);
|
|
3284
|
+
return next3;
|
|
3285
|
+
}
|
|
3286
|
+
// ### `_readQuadPunctuation` reads punctuation after a quad
|
|
3287
|
+
_readQuadPunctuation(token2) {
|
|
3288
|
+
if (token2.type !== ".")
|
|
3289
|
+
return this._error("Expected dot to follow quad", token2);
|
|
3290
|
+
return this._readInTopContext;
|
|
3291
|
+
}
|
|
3292
|
+
// ### `_readPrefix` reads the prefix of a prefix declaration
|
|
3293
|
+
_readPrefix(token2) {
|
|
3294
|
+
if (token2.type !== "prefix")
|
|
3295
|
+
return this._error("Expected prefix to follow @prefix", token2);
|
|
3296
|
+
this._prefix = token2.value;
|
|
3297
|
+
return this._readPrefixIRI;
|
|
3298
|
+
}
|
|
3299
|
+
// ### `_readPrefixIRI` reads the IRI of a prefix declaration
|
|
3300
|
+
_readPrefixIRI(token2) {
|
|
3301
|
+
if (token2.type !== "IRI")
|
|
3302
|
+
return this._error(`Expected IRI to follow prefix "${this._prefix}:"`, token2);
|
|
3303
|
+
const prefixNode = this._readEntity(token2);
|
|
3304
|
+
this._prefixes[this._prefix] = prefixNode.value;
|
|
3305
|
+
this._prefixCallback(this._prefix, prefixNode);
|
|
3306
|
+
return this._readDeclarationPunctuation;
|
|
3307
|
+
}
|
|
3308
|
+
// ### `_readBaseIRI` reads the IRI of a base declaration
|
|
3309
|
+
_readBaseIRI(token2) {
|
|
3310
|
+
const iri = token2.type === "IRI" && this._resolveIRI(token2.value);
|
|
3311
|
+
if (!iri)
|
|
3312
|
+
return this._error("Expected valid IRI to follow base declaration", token2);
|
|
3313
|
+
this._setBase(iri);
|
|
3314
|
+
return this._readDeclarationPunctuation;
|
|
3315
|
+
}
|
|
3316
|
+
// ### `_isValidVersion` checks if the given version is valid for this parser to handle.
|
|
3317
|
+
_isValidVersion(version2) {
|
|
3318
|
+
return this._parseUnsupportedVersions || _N3Parser.SUPPORTED_VERSIONS.includes(version2);
|
|
3319
|
+
}
|
|
3320
|
+
// ### `_readVersion` reads version string declaration
|
|
3321
|
+
_readVersion(token2) {
|
|
3322
|
+
if (token2.type !== "literal")
|
|
3323
|
+
return this._error("Expected literal to follow version declaration", token2);
|
|
3324
|
+
if (token2.end - token2.start !== token2.value.length + 2)
|
|
3325
|
+
return this._error("Version declarations must use single quotes", token2);
|
|
3326
|
+
this._versionCallback(token2.value);
|
|
3327
|
+
if (!this._isValidVersion(token2.value))
|
|
3328
|
+
return this._error(`Detected unsupported version: "${token2.value}"`, token2);
|
|
3329
|
+
return this._readDeclarationPunctuation;
|
|
3330
|
+
}
|
|
3331
|
+
// ### `_readNamedGraphLabel` reads the label of a named graph
|
|
3332
|
+
_readNamedGraphLabel(token2) {
|
|
3333
|
+
switch (token2.type) {
|
|
3334
|
+
case "IRI":
|
|
3335
|
+
case "blank":
|
|
3336
|
+
case "prefixed":
|
|
3337
|
+
return this._readSubject(token2), this._readGraph;
|
|
3338
|
+
case "[":
|
|
3339
|
+
return this._readNamedGraphBlankLabel;
|
|
3340
|
+
default:
|
|
3341
|
+
return this._error("Invalid graph label", token2);
|
|
3342
|
+
}
|
|
3343
|
+
}
|
|
3344
|
+
// ### `_readNamedGraphLabel` reads a blank node label of a named graph
|
|
3345
|
+
_readNamedGraphBlankLabel(token2) {
|
|
3346
|
+
if (token2.type !== "]")
|
|
3347
|
+
return this._error("Invalid graph label", token2);
|
|
3348
|
+
this._subject = this._factory.blankNode();
|
|
3349
|
+
return this._readGraph;
|
|
3350
|
+
}
|
|
3351
|
+
// ### `_readDeclarationPunctuation` reads the punctuation of a declaration
|
|
3352
|
+
_readDeclarationPunctuation(token2) {
|
|
3353
|
+
if (this._sparqlStyle) {
|
|
3354
|
+
this._sparqlStyle = false;
|
|
3355
|
+
return this._readInTopContext(token2);
|
|
3356
|
+
}
|
|
3357
|
+
if (token2.type !== ".")
|
|
3358
|
+
return this._error("Expected declaration to end with a dot", token2);
|
|
3359
|
+
return this._readInTopContext;
|
|
3360
|
+
}
|
|
3361
|
+
// Reads a list of quantified symbols from a @forSome or @forAll statement
|
|
3362
|
+
_readQuantifierList(token2) {
|
|
3363
|
+
let entity;
|
|
3364
|
+
switch (token2.type) {
|
|
3365
|
+
case "IRI":
|
|
3366
|
+
case "prefixed":
|
|
3367
|
+
if ((entity = this._readEntity(token2, true)) !== void 0)
|
|
3368
|
+
break;
|
|
3369
|
+
default:
|
|
3370
|
+
return this._error(`Unexpected ${token2.type}`, token2);
|
|
23
3371
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
3372
|
+
if (!this._explicitQuantifiers)
|
|
3373
|
+
this._quantified[entity.id] = this._factory[this._quantifier](this._factory.blankNode().value);
|
|
3374
|
+
else {
|
|
3375
|
+
if (this._subject === null)
|
|
3376
|
+
this._emit(
|
|
3377
|
+
this._graph || this.DEFAULTGRAPH,
|
|
3378
|
+
this._predicate,
|
|
3379
|
+
this._subject = this._factory.blankNode(),
|
|
3380
|
+
this.QUANTIFIERS_GRAPH
|
|
3381
|
+
);
|
|
3382
|
+
else
|
|
3383
|
+
this._emit(
|
|
3384
|
+
this._subject,
|
|
3385
|
+
this.RDF_REST,
|
|
3386
|
+
this._subject = this._factory.blankNode(),
|
|
3387
|
+
this.QUANTIFIERS_GRAPH
|
|
3388
|
+
);
|
|
3389
|
+
this._emit(this._subject, this.RDF_FIRST, entity, this.QUANTIFIERS_GRAPH);
|
|
33
3390
|
}
|
|
3391
|
+
return this._readQuantifierPunctuation;
|
|
34
3392
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
},
|
|
70
|
-
interaction: {
|
|
71
|
-
dragNodes: true,
|
|
72
|
-
dragView: true,
|
|
73
|
-
zoomView: true,
|
|
74
|
-
hover: true,
|
|
75
|
-
tooltipDelay: 300,
|
|
76
|
-
// 300ms hover delay per spec
|
|
77
|
-
hideEdgesOnDrag: false,
|
|
78
|
-
hideEdgesOnZoom: false
|
|
79
|
-
},
|
|
80
|
-
nodes: {
|
|
81
|
-
shape: "dot",
|
|
82
|
-
size: nodeSize,
|
|
83
|
-
font: {
|
|
84
|
-
size: showNodeLabels ? 12 : 0,
|
|
85
|
-
color: themeColors.text
|
|
86
|
-
},
|
|
87
|
-
borderWidth: 1,
|
|
88
|
-
borderWidthSelected: 2,
|
|
89
|
-
labelHighlightBold: true
|
|
90
|
-
},
|
|
91
|
-
edges: {
|
|
92
|
-
arrows: {
|
|
93
|
-
to: {
|
|
94
|
-
enabled: true,
|
|
95
|
-
scaleFactor: 0.6
|
|
3393
|
+
// Reads punctuation from a @forSome or @forAll statement
|
|
3394
|
+
_readQuantifierPunctuation(token2) {
|
|
3395
|
+
if (token2.type === ",")
|
|
3396
|
+
return this._readQuantifierList;
|
|
3397
|
+
else {
|
|
3398
|
+
if (this._explicitQuantifiers) {
|
|
3399
|
+
this._emit(this._subject, this.RDF_REST, this.RDF_NIL, this.QUANTIFIERS_GRAPH);
|
|
3400
|
+
this._subject = null;
|
|
3401
|
+
}
|
|
3402
|
+
this._readCallback = this._getContextEndReader();
|
|
3403
|
+
return this._readCallback(token2);
|
|
3404
|
+
}
|
|
3405
|
+
}
|
|
3406
|
+
// ### `_getPathReader` reads a potential path and then resumes with the given function
|
|
3407
|
+
_getPathReader(afterPath) {
|
|
3408
|
+
this._afterPath = afterPath;
|
|
3409
|
+
return this._readPath;
|
|
3410
|
+
}
|
|
3411
|
+
// ### `_readPath` reads a potential path
|
|
3412
|
+
_readPath(token2) {
|
|
3413
|
+
switch (token2.type) {
|
|
3414
|
+
// Forward path
|
|
3415
|
+
case "!":
|
|
3416
|
+
return this._readForwardPath;
|
|
3417
|
+
// Backward path
|
|
3418
|
+
case "^":
|
|
3419
|
+
return this._readBackwardPath;
|
|
3420
|
+
// Not a path; resume reading where we left off
|
|
3421
|
+
default:
|
|
3422
|
+
const stack = this._contextStack, parent2 = stack.length && stack[stack.length - 1];
|
|
3423
|
+
if (parent2 && parent2.type === "item") {
|
|
3424
|
+
const item = this._subject;
|
|
3425
|
+
this._restoreContext("item", token2);
|
|
3426
|
+
this._emit(this._subject, this.RDF_FIRST, item, this._graph);
|
|
96
3427
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
3428
|
+
return this._afterPath(token2);
|
|
3429
|
+
}
|
|
3430
|
+
}
|
|
3431
|
+
// ### `_readForwardPath` reads a '!' path
|
|
3432
|
+
_readForwardPath(token2) {
|
|
3433
|
+
let subject, predicate;
|
|
3434
|
+
const object2 = this._factory.blankNode();
|
|
3435
|
+
if ((predicate = this._readEntity(token2)) === void 0)
|
|
3436
|
+
return;
|
|
3437
|
+
if (this._predicate === null)
|
|
3438
|
+
subject = this._subject, this._subject = object2;
|
|
3439
|
+
else
|
|
3440
|
+
subject = this._object, this._object = object2;
|
|
3441
|
+
this._emit(subject, predicate, object2, this._graph);
|
|
3442
|
+
return this._readPath;
|
|
3443
|
+
}
|
|
3444
|
+
// ### `_readBackwardPath` reads a '^' path
|
|
3445
|
+
_readBackwardPath(token2) {
|
|
3446
|
+
const subject = this._factory.blankNode();
|
|
3447
|
+
let predicate, object2;
|
|
3448
|
+
if ((predicate = this._readEntity(token2)) === void 0)
|
|
3449
|
+
return;
|
|
3450
|
+
if (this._predicate === null)
|
|
3451
|
+
object2 = this._subject, this._subject = subject;
|
|
3452
|
+
else
|
|
3453
|
+
object2 = this._object, this._object = subject;
|
|
3454
|
+
this._emit(subject, predicate, object2, this._graph);
|
|
3455
|
+
return this._readPath;
|
|
3456
|
+
}
|
|
3457
|
+
// ### `_readTripleTermTail` reads the end of a triple term
|
|
3458
|
+
_readTripleTermTail(token2) {
|
|
3459
|
+
if (token2.type !== ")>>")
|
|
3460
|
+
return this._error(`Expected )>> but got ${token2.type}`, token2);
|
|
3461
|
+
const quad2 = this._factory.quad(
|
|
3462
|
+
this._subject,
|
|
3463
|
+
this._predicate,
|
|
3464
|
+
this._object,
|
|
3465
|
+
this._graph || this.DEFAULTGRAPH
|
|
3466
|
+
);
|
|
3467
|
+
this._restoreContext("<<(", token2);
|
|
3468
|
+
if (this._subject === null) {
|
|
3469
|
+
this._subject = quad2;
|
|
3470
|
+
return this._readPredicate;
|
|
3471
|
+
} else {
|
|
3472
|
+
this._object = quad2;
|
|
3473
|
+
return this._getContextEndReader();
|
|
3474
|
+
}
|
|
3475
|
+
}
|
|
3476
|
+
// ### `_readReifiedTripleTailOrReifier` reads a reifier or the end of a nested reified triple
|
|
3477
|
+
_readReifiedTripleTailOrReifier(token2) {
|
|
3478
|
+
if (token2.type === "~") {
|
|
3479
|
+
return this._readReifier;
|
|
3480
|
+
}
|
|
3481
|
+
return this._readReifiedTripleTail(token2);
|
|
3482
|
+
}
|
|
3483
|
+
// ### `_readReifiedTripleTail` reads the end of a nested reified triple
|
|
3484
|
+
_readReifiedTripleTail(token2) {
|
|
3485
|
+
if (token2.type !== ">>")
|
|
3486
|
+
return this._error(`Expected >> but got ${token2.type}`, token2);
|
|
3487
|
+
this._tripleTerm = null;
|
|
3488
|
+
const reifier = this._readTripleTerm();
|
|
3489
|
+
this._restoreContext("<<", token2);
|
|
3490
|
+
const stack = this._contextStack, parent2 = stack.length && stack[stack.length - 1];
|
|
3491
|
+
if (parent2 && parent2.type === "list") {
|
|
3492
|
+
this._emit(this._subject, this.RDF_FIRST, reifier, this._graph);
|
|
3493
|
+
return this._getContextEndReader();
|
|
3494
|
+
} else if (this._subject === null) {
|
|
3495
|
+
this._subject = reifier;
|
|
3496
|
+
return this._readPredicateOrReifierTripleEnd;
|
|
3497
|
+
} else {
|
|
3498
|
+
this._object = reifier;
|
|
3499
|
+
return this._getContextEndReader();
|
|
3500
|
+
}
|
|
3501
|
+
}
|
|
3502
|
+
_readPredicateOrReifierTripleEnd(token2) {
|
|
3503
|
+
if (token2.type === ".") {
|
|
3504
|
+
this._subject = null;
|
|
3505
|
+
return this._readPunctuation(token2);
|
|
3506
|
+
}
|
|
3507
|
+
return this._readPredicate(token2);
|
|
3508
|
+
}
|
|
3509
|
+
// ### `_readReifier` reads the triple term identifier after a tilde when in a reifying triple.
|
|
3510
|
+
_readReifier(token2) {
|
|
3511
|
+
this._reifier = this._readEntity(token2);
|
|
3512
|
+
return this._readReifiedTripleTail;
|
|
3513
|
+
}
|
|
3514
|
+
// ### `_readReifier` reads the optional triple term identifier after a tilde when in annotation syntax.
|
|
3515
|
+
_readReifierInAnnotation(token2) {
|
|
3516
|
+
if (token2.type === "IRI" || token2.type === "typeIRI" || token2.type === "type" || token2.type === "prefixed" || token2.type === "blank" || token2.type === "var") {
|
|
3517
|
+
this._reifier = this._readEntity(token2);
|
|
3518
|
+
return this._readPunctuation;
|
|
3519
|
+
}
|
|
3520
|
+
this._readTripleTerm();
|
|
3521
|
+
this._subject = null;
|
|
3522
|
+
return this._readPunctuation(token2);
|
|
3523
|
+
}
|
|
3524
|
+
_readTripleTerm() {
|
|
3525
|
+
const stack = this._contextStack, parent2 = stack.length && stack[stack.length - 1];
|
|
3526
|
+
const parentGraph = parent2 ? parent2.graph : void 0;
|
|
3527
|
+
const reifier = this._reifier || this._factory.blankNode();
|
|
3528
|
+
this._reifier = null;
|
|
3529
|
+
this._tripleTerm = this._tripleTerm || this._factory.quad(this._subject, this._predicate, this._object);
|
|
3530
|
+
this._emit(reifier, this.RDF_REIFIES, this._tripleTerm, parentGraph || this.DEFAULTGRAPH);
|
|
3531
|
+
return reifier;
|
|
3532
|
+
}
|
|
3533
|
+
// ### `_getContextEndReader` gets the next reader function at the end of a context
|
|
3534
|
+
_getContextEndReader() {
|
|
3535
|
+
const contextStack = this._contextStack;
|
|
3536
|
+
if (!contextStack.length)
|
|
3537
|
+
return this._readPunctuation;
|
|
3538
|
+
switch (contextStack[contextStack.length - 1].type) {
|
|
3539
|
+
case "blank":
|
|
3540
|
+
return this._readBlankNodeTail;
|
|
3541
|
+
case "list":
|
|
3542
|
+
return this._readListItem;
|
|
3543
|
+
case "formula":
|
|
3544
|
+
return this._readFormulaTail;
|
|
3545
|
+
case "<<(":
|
|
3546
|
+
return this._readTripleTermTail;
|
|
3547
|
+
case "<<":
|
|
3548
|
+
return this._readReifiedTripleTailOrReifier;
|
|
3549
|
+
}
|
|
3550
|
+
}
|
|
3551
|
+
// ### `_emit` sends a quad through the callback
|
|
3552
|
+
_emit(subject, predicate, object2, graph) {
|
|
3553
|
+
this._callback(null, this._factory.quad(subject, predicate, object2, graph || this.DEFAULTGRAPH));
|
|
3554
|
+
}
|
|
3555
|
+
// ### `_error` emits an error message through the callback
|
|
3556
|
+
_error(message, token2) {
|
|
3557
|
+
const err = new Error(`${message} on line ${token2.line}.`);
|
|
3558
|
+
err.context = {
|
|
3559
|
+
token: token2,
|
|
3560
|
+
line: token2.line,
|
|
3561
|
+
previousToken: this._lexer.previousToken
|
|
3562
|
+
};
|
|
3563
|
+
this._callback(err);
|
|
3564
|
+
this._callback = noop;
|
|
3565
|
+
}
|
|
3566
|
+
// ### `_resolveIRI` resolves an IRI against the base path
|
|
3567
|
+
_resolveIRI(iri) {
|
|
3568
|
+
return /^[a-z][a-z0-9+.-]*:/i.test(iri) ? iri : this._resolveRelativeIRI(iri);
|
|
3569
|
+
}
|
|
3570
|
+
// ### `_resolveRelativeIRI` resolves an IRI against the base path,
|
|
3571
|
+
// assuming that a base path has been set and that the IRI is indeed relative
|
|
3572
|
+
_resolveRelativeIRI(iri) {
|
|
3573
|
+
if (!iri.length)
|
|
3574
|
+
return this._base;
|
|
3575
|
+
switch (iri[0]) {
|
|
3576
|
+
// Resolve relative fragment IRIs against the base IRI
|
|
3577
|
+
case "#":
|
|
3578
|
+
return this._base + iri;
|
|
3579
|
+
// Resolve relative query string IRIs by replacing the query string
|
|
3580
|
+
case "?":
|
|
3581
|
+
return this._base.replace(/(?:\?.*)?$/, iri);
|
|
3582
|
+
// Resolve root-relative IRIs at the root of the base IRI
|
|
3583
|
+
case "/":
|
|
3584
|
+
return (iri[1] === "/" ? this._baseScheme : this._baseRoot) + this._removeDotSegments(iri);
|
|
3585
|
+
// Resolve all other IRIs at the base IRI's path
|
|
3586
|
+
default:
|
|
3587
|
+
return /^[^/:]*:/.test(iri) ? null : this._removeDotSegments(this._basePath + iri);
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
// ### `_removeDotSegments` resolves './' and '../' path segments in an IRI as per RFC3986
|
|
3591
|
+
_removeDotSegments(iri) {
|
|
3592
|
+
if (!/(^|\/)\.\.?($|[/#?])/.test(iri))
|
|
3593
|
+
return iri;
|
|
3594
|
+
const length2 = iri.length;
|
|
3595
|
+
let result = "", i = -1, pathStart = -1, segmentStart = 0, next3 = "/";
|
|
3596
|
+
while (i < length2) {
|
|
3597
|
+
switch (next3) {
|
|
3598
|
+
// The path starts with the first slash after the authority
|
|
3599
|
+
case ":":
|
|
3600
|
+
if (pathStart < 0) {
|
|
3601
|
+
if (iri[++i] === "/" && iri[++i] === "/")
|
|
3602
|
+
while ((pathStart = i + 1) < length2 && iri[pathStart] !== "/")
|
|
3603
|
+
i = pathStart;
|
|
3604
|
+
}
|
|
3605
|
+
break;
|
|
3606
|
+
// Don't modify a query string or fragment
|
|
3607
|
+
case "?":
|
|
3608
|
+
case "#":
|
|
3609
|
+
i = length2;
|
|
3610
|
+
break;
|
|
3611
|
+
// Handle '/.' or '/..' path segments
|
|
3612
|
+
case "/":
|
|
3613
|
+
if (iri[i + 1] === ".") {
|
|
3614
|
+
next3 = iri[++i + 1];
|
|
3615
|
+
switch (next3) {
|
|
3616
|
+
// Remove a '/.' segment
|
|
3617
|
+
case "/":
|
|
3618
|
+
result += iri.substring(segmentStart, i - 1);
|
|
3619
|
+
segmentStart = i + 1;
|
|
3620
|
+
break;
|
|
3621
|
+
// Remove a trailing '/.' segment
|
|
3622
|
+
case void 0:
|
|
3623
|
+
case "?":
|
|
3624
|
+
case "#":
|
|
3625
|
+
return result + iri.substring(segmentStart, i) + iri.substr(i + 1);
|
|
3626
|
+
// Remove a '/..' segment
|
|
3627
|
+
case ".":
|
|
3628
|
+
next3 = iri[++i + 1];
|
|
3629
|
+
if (next3 === void 0 || next3 === "/" || next3 === "?" || next3 === "#") {
|
|
3630
|
+
result += iri.substring(segmentStart, i - 2);
|
|
3631
|
+
if ((segmentStart = result.lastIndexOf("/")) >= pathStart)
|
|
3632
|
+
result = result.substr(0, segmentStart);
|
|
3633
|
+
if (next3 !== "/")
|
|
3634
|
+
return `${result}/${iri.substr(i + 1)}`;
|
|
3635
|
+
segmentStart = i + 1;
|
|
3636
|
+
}
|
|
3637
|
+
}
|
|
3638
|
+
}
|
|
113
3639
|
}
|
|
3640
|
+
next3 = iri[++i];
|
|
3641
|
+
}
|
|
3642
|
+
return result + iri.substring(segmentStart);
|
|
3643
|
+
}
|
|
3644
|
+
// ## Public methods
|
|
3645
|
+
// ### `parse` parses the N3 input and emits each parsed quad through the onQuad callback.
|
|
3646
|
+
parse(input, quadCallback, prefixCallback, versionCallback) {
|
|
3647
|
+
let onQuad, onPrefix, onComment, onVersion;
|
|
3648
|
+
if (quadCallback && (quadCallback.onQuad || quadCallback.onPrefix || quadCallback.onComment || quadCallback.onVersion)) {
|
|
3649
|
+
onQuad = quadCallback.onQuad;
|
|
3650
|
+
onPrefix = quadCallback.onPrefix;
|
|
3651
|
+
onComment = quadCallback.onComment;
|
|
3652
|
+
onVersion = quadCallback.onVersion;
|
|
3653
|
+
} else {
|
|
3654
|
+
onQuad = quadCallback;
|
|
3655
|
+
onPrefix = prefixCallback;
|
|
3656
|
+
onVersion = versionCallback;
|
|
3657
|
+
}
|
|
3658
|
+
this._readCallback = this._readBeforeTopContext;
|
|
3659
|
+
this._sparqlStyle = false;
|
|
3660
|
+
this._prefixes = /* @__PURE__ */ Object.create(null);
|
|
3661
|
+
this._prefixes._ = this._blankNodePrefix ? this._blankNodePrefix.substr(2) : `b${blankNodePrefix++}_`;
|
|
3662
|
+
this._prefixCallback = onPrefix || noop;
|
|
3663
|
+
this._versionCallback = onVersion || noop;
|
|
3664
|
+
this._inversePredicate = false;
|
|
3665
|
+
this._quantified = /* @__PURE__ */ Object.create(null);
|
|
3666
|
+
if (!onQuad) {
|
|
3667
|
+
const quads = [];
|
|
3668
|
+
let error;
|
|
3669
|
+
this._callback = (e, t) => {
|
|
3670
|
+
e ? error = e : t && quads.push(t);
|
|
3671
|
+
};
|
|
3672
|
+
this._lexer.tokenize(input).every((token2) => {
|
|
3673
|
+
return this._readCallback = this._readCallback(token2);
|
|
3674
|
+
});
|
|
3675
|
+
if (error) throw error;
|
|
3676
|
+
return quads;
|
|
3677
|
+
}
|
|
3678
|
+
let processNextToken = (error, token2) => {
|
|
3679
|
+
if (error !== null)
|
|
3680
|
+
this._callback(error), this._callback = noop;
|
|
3681
|
+
else if (this._readCallback)
|
|
3682
|
+
this._readCallback = this._readCallback(token2);
|
|
3683
|
+
};
|
|
3684
|
+
if (onComment) {
|
|
3685
|
+
this._lexer.comments = true;
|
|
3686
|
+
processNextToken = (error, token2) => {
|
|
3687
|
+
if (error !== null)
|
|
3688
|
+
this._callback(error), this._callback = noop;
|
|
3689
|
+
else if (this._readCallback) {
|
|
3690
|
+
if (token2.type === "comment")
|
|
3691
|
+
onComment(token2.value);
|
|
3692
|
+
else
|
|
3693
|
+
this._readCallback = this._readCallback(token2);
|
|
3694
|
+
}
|
|
3695
|
+
};
|
|
114
3696
|
}
|
|
3697
|
+
this._callback = onQuad;
|
|
3698
|
+
this._lexer.tokenize(input, processNextToken);
|
|
3699
|
+
}
|
|
3700
|
+
};
|
|
3701
|
+
function noop() {
|
|
3702
|
+
}
|
|
3703
|
+
function initDataFactory(parser, factory) {
|
|
3704
|
+
parser._factory = factory;
|
|
3705
|
+
parser.DEFAULTGRAPH = factory.defaultGraph();
|
|
3706
|
+
parser.RDF_FIRST = factory.namedNode(IRIs_default.rdf.first);
|
|
3707
|
+
parser.RDF_REST = factory.namedNode(IRIs_default.rdf.rest);
|
|
3708
|
+
parser.RDF_NIL = factory.namedNode(IRIs_default.rdf.nil);
|
|
3709
|
+
parser.RDF_REIFIES = factory.namedNode(IRIs_default.rdf.reifies);
|
|
3710
|
+
parser.N3_FORALL = factory.namedNode(IRIs_default.r.forAll);
|
|
3711
|
+
parser.N3_FORSOME = factory.namedNode(IRIs_default.r.forSome);
|
|
3712
|
+
parser.ABBREVIATIONS = {
|
|
3713
|
+
"a": factory.namedNode(IRIs_default.rdf.type),
|
|
3714
|
+
"=": factory.namedNode(IRIs_default.owl.sameAs),
|
|
3715
|
+
">": factory.namedNode(IRIs_default.log.implies),
|
|
3716
|
+
"<": factory.namedNode(IRIs_default.log.isImpliedBy)
|
|
115
3717
|
};
|
|
3718
|
+
parser.QUANTIFIERS_GRAPH = factory.namedNode("urn:n3:quantifiers");
|
|
116
3719
|
}
|
|
3720
|
+
N3Parser.SUPPORTED_VERSIONS = [
|
|
3721
|
+
"1.2",
|
|
3722
|
+
"1.2-basic",
|
|
3723
|
+
"1.1"
|
|
3724
|
+
];
|
|
3725
|
+
initDataFactory(N3Parser.prototype, N3DataFactory_default);
|
|
117
3726
|
|
|
118
3727
|
// src/parsers.ts
|
|
3728
|
+
async function parseBackgroundQueryResponse(response) {
|
|
3729
|
+
var _a;
|
|
3730
|
+
if (!response) return [];
|
|
3731
|
+
try {
|
|
3732
|
+
let rdfText;
|
|
3733
|
+
if (typeof response.text === "function") {
|
|
3734
|
+
rdfText = await response.text();
|
|
3735
|
+
} else if (typeof response.data === "string") {
|
|
3736
|
+
rdfText = response.data;
|
|
3737
|
+
} else if (typeof response === "string") {
|
|
3738
|
+
rdfText = response;
|
|
3739
|
+
} else {
|
|
3740
|
+
return [];
|
|
3741
|
+
}
|
|
3742
|
+
const parser = new N3Parser();
|
|
3743
|
+
const quads = parser.parse(rdfText);
|
|
3744
|
+
const triples = [];
|
|
3745
|
+
for (const quad2 of quads) {
|
|
3746
|
+
const subject = quad2.subject.value;
|
|
3747
|
+
const predicate = quad2.predicate.value;
|
|
3748
|
+
let objectType;
|
|
3749
|
+
let objectValue;
|
|
3750
|
+
let datatype;
|
|
3751
|
+
let lang;
|
|
3752
|
+
if (quad2.object.termType === "Literal") {
|
|
3753
|
+
objectType = "literal";
|
|
3754
|
+
objectValue = quad2.object.value;
|
|
3755
|
+
datatype = (_a = quad2.object.datatype) == null ? void 0 : _a.value;
|
|
3756
|
+
lang = quad2.object.language || void 0;
|
|
3757
|
+
} else if (quad2.object.termType === "BlankNode") {
|
|
3758
|
+
objectType = "bnode";
|
|
3759
|
+
objectValue = quad2.object.value;
|
|
3760
|
+
} else {
|
|
3761
|
+
objectType = "uri";
|
|
3762
|
+
objectValue = quad2.object.value;
|
|
3763
|
+
}
|
|
3764
|
+
triples.push({
|
|
3765
|
+
subject,
|
|
3766
|
+
predicate,
|
|
3767
|
+
object: {
|
|
3768
|
+
value: objectValue,
|
|
3769
|
+
type: objectType,
|
|
3770
|
+
datatype,
|
|
3771
|
+
lang
|
|
3772
|
+
}
|
|
3773
|
+
});
|
|
3774
|
+
}
|
|
3775
|
+
return triples;
|
|
3776
|
+
} catch (error) {
|
|
3777
|
+
console.error("Failed to parse RDF response:", error);
|
|
3778
|
+
return [];
|
|
3779
|
+
}
|
|
3780
|
+
}
|
|
119
3781
|
function parseConstructResults(yasrResults) {
|
|
120
3782
|
const triples = [];
|
|
121
3783
|
if (!yasrResults || !yasrResults.getBindings) {
|
|
@@ -626,8 +4288,8 @@ var path$u = {};
|
|
|
626
4288
|
var path$t = path$u;
|
|
627
4289
|
var global$m = global$n;
|
|
628
4290
|
var isCallable$f = isCallable$h;
|
|
629
|
-
var aFunction = function(
|
|
630
|
-
return isCallable$f(
|
|
4291
|
+
var aFunction = function(variable2) {
|
|
4292
|
+
return isCallable$f(variable2) ? variable2 : void 0;
|
|
631
4293
|
};
|
|
632
4294
|
var getBuiltIn$b = function(namespace, method2) {
|
|
633
4295
|
return arguments.length < 2 ? aFunction(path$t[namespace]) || aFunction(global$m[namespace]) : path$t[namespace] && path$t[namespace][method2] || global$m[namespace] && global$m[namespace][method2];
|
|
@@ -2116,17 +5778,17 @@ var isCallable$7 = isCallable$h;
|
|
|
2116
5778
|
var classof$d = classof$e;
|
|
2117
5779
|
var getBuiltIn$9 = getBuiltIn$b;
|
|
2118
5780
|
var inspectSource = inspectSource$1;
|
|
2119
|
-
var
|
|
5781
|
+
var noop2 = function() {
|
|
2120
5782
|
};
|
|
2121
5783
|
var empty = [];
|
|
2122
5784
|
var construct = getBuiltIn$9("Reflect", "construct");
|
|
2123
5785
|
var constructorRegExp = /^\s*(?:class|function)\b/;
|
|
2124
5786
|
var exec$2 = uncurryThis$k(constructorRegExp.exec);
|
|
2125
|
-
var INCORRECT_TO_STRING = !constructorRegExp.test(
|
|
5787
|
+
var INCORRECT_TO_STRING = !constructorRegExp.test(noop2);
|
|
2126
5788
|
var isConstructorModern = function isConstructor(argument) {
|
|
2127
5789
|
if (!isCallable$7(argument)) return false;
|
|
2128
5790
|
try {
|
|
2129
|
-
construct(
|
|
5791
|
+
construct(noop2, empty, argument);
|
|
2130
5792
|
return true;
|
|
2131
5793
|
} catch (error) {
|
|
2132
5794
|
return false;
|
|
@@ -5762,16 +9424,16 @@ function Mash() {
|
|
|
5762
9424
|
};
|
|
5763
9425
|
}
|
|
5764
9426
|
function hammerMock() {
|
|
5765
|
-
const
|
|
9427
|
+
const noop3 = () => {
|
|
5766
9428
|
};
|
|
5767
9429
|
return {
|
|
5768
|
-
on:
|
|
5769
|
-
off:
|
|
5770
|
-
destroy:
|
|
5771
|
-
emit:
|
|
9430
|
+
on: noop3,
|
|
9431
|
+
off: noop3,
|
|
9432
|
+
destroy: noop3,
|
|
9433
|
+
emit: noop3,
|
|
5772
9434
|
get() {
|
|
5773
9435
|
return {
|
|
5774
|
-
set:
|
|
9436
|
+
set: noop3
|
|
5775
9437
|
};
|
|
5776
9438
|
}
|
|
5777
9439
|
};
|
|
@@ -10565,7 +14227,7 @@ var isNan = isNan$1;
|
|
|
10565
14227
|
var _Number$isNaN = /* @__PURE__ */ getDefaultExportFromCjs(isNan);
|
|
10566
14228
|
var global$4 = global$n;
|
|
10567
14229
|
var globalIsFinite = global$4.isFinite;
|
|
10568
|
-
var numberIsFinite$1 = Number.isFinite || function
|
|
14230
|
+
var numberIsFinite$1 = Number.isFinite || function isFinite2(it2) {
|
|
10569
14231
|
return typeof it2 == "number" && globalIsFinite(it2);
|
|
10570
14232
|
};
|
|
10571
14233
|
var $$g = _export;
|
|
@@ -29988,10 +33650,16 @@ function saveSettings(settings) {
|
|
|
29988
33650
|
}
|
|
29989
33651
|
|
|
29990
33652
|
// src/GraphPlugin.ts
|
|
33653
|
+
var LOADING_BORDER_WIDTH = 4;
|
|
33654
|
+
var LOADING_BORDER_COLOR = "#ffa500";
|
|
33655
|
+
var EXPANDED_BORDER_WIDTH = 3;
|
|
33656
|
+
var DEFAULT_BORDER_WIDTH = 2;
|
|
29991
33657
|
var GraphPlugin = class {
|
|
29992
33658
|
constructor(yasr) {
|
|
29993
33659
|
this.settingsPanelOpen = false;
|
|
29994
33660
|
this.clickOutsideHandler = null;
|
|
33661
|
+
this.expansionAbortController = null;
|
|
33662
|
+
this.uriToNodeId = /* @__PURE__ */ new Map();
|
|
29995
33663
|
this.yasr = yasr;
|
|
29996
33664
|
this.network = null;
|
|
29997
33665
|
this.currentTheme = getCurrentTheme();
|
|
@@ -30015,6 +33683,12 @@ var GraphPlugin = class {
|
|
|
30015
33683
|
static get label() {
|
|
30016
33684
|
return "Graph";
|
|
30017
33685
|
}
|
|
33686
|
+
/**
|
|
33687
|
+
* Help/documentation URL
|
|
33688
|
+
*/
|
|
33689
|
+
static get helpReference() {
|
|
33690
|
+
return "https://yasgui-doc.matdata.eu/docs/user-guide#graph-plugin";
|
|
33691
|
+
}
|
|
30018
33692
|
/**
|
|
30019
33693
|
* Check if plugin can handle the current results
|
|
30020
33694
|
* @returns True if results are from CONSTRUCT or DESCRIBE query
|
|
@@ -30036,6 +33710,11 @@ var GraphPlugin = class {
|
|
|
30036
33710
|
*/
|
|
30037
33711
|
draw() {
|
|
30038
33712
|
const wasPanelOpen = this.settingsPanelOpen;
|
|
33713
|
+
if (this.expansionAbortController) {
|
|
33714
|
+
this.expansionAbortController.abort();
|
|
33715
|
+
this.expansionAbortController = null;
|
|
33716
|
+
}
|
|
33717
|
+
this.uriToNodeId = /* @__PURE__ */ new Map();
|
|
30039
33718
|
this.yasr.resultsEl.innerHTML = "";
|
|
30040
33719
|
try {
|
|
30041
33720
|
this.triples = parseConstructResults(this.yasr.results);
|
|
@@ -30092,6 +33771,13 @@ var GraphPlugin = class {
|
|
|
30092
33771
|
this.nodesDataSet.update(updates);
|
|
30093
33772
|
}
|
|
30094
33773
|
});
|
|
33774
|
+
this.setupNodeExpansion();
|
|
33775
|
+
this.uriToNodeId = /* @__PURE__ */ new Map();
|
|
33776
|
+
this.nodesDataSet.get().forEach((node) => {
|
|
33777
|
+
if (node.uri) {
|
|
33778
|
+
this.uriToNodeId.set(node.uri, node.id);
|
|
33779
|
+
}
|
|
33780
|
+
});
|
|
30095
33781
|
if (!this.themeObserver) {
|
|
30096
33782
|
this.themeObserver = watchThemeChanges((newTheme) => {
|
|
30097
33783
|
this.applyTheme(newTheme);
|
|
@@ -30474,7 +34160,119 @@ var GraphPlugin = class {
|
|
|
30474
34160
|
return panel;
|
|
30475
34161
|
}
|
|
30476
34162
|
/**
|
|
30477
|
-
*
|
|
34163
|
+
* Setup double-click handler for node expansion
|
|
34164
|
+
*/
|
|
34165
|
+
setupNodeExpansion() {
|
|
34166
|
+
if (!this.network) return;
|
|
34167
|
+
this.network.on("doubleClick", (params) => {
|
|
34168
|
+
if (params.nodes.length === 0) return;
|
|
34169
|
+
const nodeId = params.nodes[0];
|
|
34170
|
+
const node = this.nodesDataSet.get(nodeId);
|
|
34171
|
+
if (node && node.uri && !node.uri.startsWith("_:")) {
|
|
34172
|
+
this.expandNode(node.uri);
|
|
34173
|
+
}
|
|
34174
|
+
});
|
|
34175
|
+
}
|
|
34176
|
+
/**
|
|
34177
|
+
* Expand a node by executing a DESCRIBE query for the given URI and
|
|
34178
|
+
* merging the returned triples into the existing graph.
|
|
34179
|
+
* @param uri - URI of the node to expand
|
|
34180
|
+
*/
|
|
34181
|
+
async expandNode(uri) {
|
|
34182
|
+
if (!this.yasr.executeQuery) {
|
|
34183
|
+
console.warn("yasgui-graph-plugin: background query execution not available (yasr.executeQuery is not configured)");
|
|
34184
|
+
return;
|
|
34185
|
+
}
|
|
34186
|
+
if (!this.triples || !this.prefixMap) return;
|
|
34187
|
+
if (this.expansionAbortController) {
|
|
34188
|
+
this.expansionAbortController.abort();
|
|
34189
|
+
}
|
|
34190
|
+
const controller = new AbortController();
|
|
34191
|
+
this.expansionAbortController = controller;
|
|
34192
|
+
const nodeId = this.uriToNodeId.get(uri);
|
|
34193
|
+
let originalColor = void 0;
|
|
34194
|
+
let originalBorderWidth = void 0;
|
|
34195
|
+
if (nodeId !== void 0) {
|
|
34196
|
+
const node = this.nodesDataSet.get(nodeId);
|
|
34197
|
+
if (node) {
|
|
34198
|
+
originalColor = node.color;
|
|
34199
|
+
originalBorderWidth = node.borderWidth;
|
|
34200
|
+
}
|
|
34201
|
+
this.nodesDataSet.update({
|
|
34202
|
+
id: nodeId,
|
|
34203
|
+
borderWidth: LOADING_BORDER_WIDTH,
|
|
34204
|
+
color: typeof originalColor === "object" && originalColor !== null ? { ...originalColor, border: LOADING_BORDER_COLOR } : { border: LOADING_BORDER_COLOR, background: originalColor != null ? originalColor : void 0 }
|
|
34205
|
+
});
|
|
34206
|
+
}
|
|
34207
|
+
const restoreNode = (borderWidth) => {
|
|
34208
|
+
if (nodeId !== void 0) {
|
|
34209
|
+
this.nodesDataSet.update({ id: nodeId, borderWidth, color: originalColor });
|
|
34210
|
+
}
|
|
34211
|
+
};
|
|
34212
|
+
try {
|
|
34213
|
+
const response = await this.yasr.executeQuery(`DESCRIBE <${uri}>`, {
|
|
34214
|
+
acceptHeader: "text/turtle",
|
|
34215
|
+
signal: controller.signal
|
|
34216
|
+
});
|
|
34217
|
+
if (controller.signal.aborted) {
|
|
34218
|
+
restoreNode(originalBorderWidth != null ? originalBorderWidth : DEFAULT_BORDER_WIDTH);
|
|
34219
|
+
return;
|
|
34220
|
+
}
|
|
34221
|
+
const newTriples = await parseBackgroundQueryResponse(response);
|
|
34222
|
+
if (controller.signal.aborted) {
|
|
34223
|
+
restoreNode(originalBorderWidth != null ? originalBorderWidth : DEFAULT_BORDER_WIDTH);
|
|
34224
|
+
return;
|
|
34225
|
+
}
|
|
34226
|
+
const existingKeys = new Set(
|
|
34227
|
+
this.triples.map((t) => `${t.subject}|${t.predicate}|${t.object.value}`)
|
|
34228
|
+
);
|
|
34229
|
+
const uniqueNew = newTriples.filter(
|
|
34230
|
+
(t) => !existingKeys.has(`${t.subject}|${t.predicate}|${t.object.value}`)
|
|
34231
|
+
);
|
|
34232
|
+
if (uniqueNew.length > 0) {
|
|
34233
|
+
this.triples = [...this.triples, ...uniqueNew];
|
|
34234
|
+
this.mergeNewTriples();
|
|
34235
|
+
}
|
|
34236
|
+
restoreNode(EXPANDED_BORDER_WIDTH);
|
|
34237
|
+
} catch (error) {
|
|
34238
|
+
if ((error == null ? void 0 : error.name) === "AbortError") {
|
|
34239
|
+
restoreNode(originalBorderWidth != null ? originalBorderWidth : DEFAULT_BORDER_WIDTH);
|
|
34240
|
+
return;
|
|
34241
|
+
}
|
|
34242
|
+
console.error("yasgui-graph-plugin: error expanding node", uri, error);
|
|
34243
|
+
restoreNode(originalBorderWidth != null ? originalBorderWidth : DEFAULT_BORDER_WIDTH);
|
|
34244
|
+
}
|
|
34245
|
+
}
|
|
34246
|
+
/**
|
|
34247
|
+
* Incrementally add new triples to the vis-network DataSets without a full redraw.
|
|
34248
|
+
* New nodes and edges are added; existing ones are left untouched.
|
|
34249
|
+
* Expects `this.triples` to already include the new triples.
|
|
34250
|
+
*/
|
|
34251
|
+
mergeNewTriples() {
|
|
34252
|
+
if (!this.triples || !this.prefixMap || !this.nodesDataSet || !this.edgesDataSet) return;
|
|
34253
|
+
const themeColors = getThemeNodeColors(this.currentTheme);
|
|
34254
|
+
const { nodes, edges } = triplesToGraph(this.triples, this.prefixMap, themeColors, this.settings);
|
|
34255
|
+
const existingValues = new Set(this.nodesDataSet.get().map((n) => n.fullValue));
|
|
34256
|
+
const nodesToAdd = nodes.filter((n) => !existingValues.has(n.fullValue));
|
|
34257
|
+
const existingEdgeKeys = new Set(
|
|
34258
|
+
this.edgesDataSet.get().map((e) => `${e.from}|${e.predicate}|${e.to}`)
|
|
34259
|
+
);
|
|
34260
|
+
const edgesToAdd = edges.filter(
|
|
34261
|
+
(e) => !existingEdgeKeys.has(`${e.from}|${e.predicate}|${e.to}`)
|
|
34262
|
+
);
|
|
34263
|
+
if (nodesToAdd.length > 0) {
|
|
34264
|
+
this.nodesDataSet.add(nodesToAdd);
|
|
34265
|
+
nodesToAdd.forEach((n) => {
|
|
34266
|
+
if (n.uri != null) {
|
|
34267
|
+
this.uriToNodeId.set(n.uri, n.id);
|
|
34268
|
+
}
|
|
34269
|
+
});
|
|
34270
|
+
}
|
|
34271
|
+
if (edgesToAdd.length > 0) {
|
|
34272
|
+
this.edgesDataSet.add(edgesToAdd);
|
|
34273
|
+
}
|
|
34274
|
+
}
|
|
34275
|
+
/**
|
|
30478
34276
|
* @returns Icon element
|
|
30479
34277
|
*/
|
|
30480
34278
|
getIcon() {
|
|
@@ -30496,6 +34294,10 @@ var GraphPlugin = class {
|
|
|
30496
34294
|
*/
|
|
30497
34295
|
destroy() {
|
|
30498
34296
|
this.removeClickOutsideHandler();
|
|
34297
|
+
if (this.expansionAbortController) {
|
|
34298
|
+
this.expansionAbortController.abort();
|
|
34299
|
+
this.expansionAbortController = null;
|
|
34300
|
+
}
|
|
30499
34301
|
if (this.themeObserver) {
|
|
30500
34302
|
this.themeObserver.disconnect();
|
|
30501
34303
|
this.themeObserver = null;
|
|
@@ -30522,6 +34324,17 @@ export {
|
|
|
30522
34324
|
};
|
|
30523
34325
|
/*! Bundled license information:
|
|
30524
34326
|
|
|
34327
|
+
ieee754/index.js:
|
|
34328
|
+
(*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)
|
|
34329
|
+
|
|
34330
|
+
buffer/index.js:
|
|
34331
|
+
(*!
|
|
34332
|
+
* The buffer module from node.js, for the browser.
|
|
34333
|
+
*
|
|
34334
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
34335
|
+
* @license MIT
|
|
34336
|
+
*)
|
|
34337
|
+
|
|
30525
34338
|
vis-network/standalone/esm/vis-network.js:
|
|
30526
34339
|
(**
|
|
30527
34340
|
* vis-network
|