tiny-essentials 1.11.0 → 1.12.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 +12 -3
- package/dist/node_modules/firebase-functions/lib/common/trace.cjs +82 -0
- package/dist/node_modules/firebase-functions/lib/logger/common.cjs +57 -0
- package/dist/node_modules/firebase-functions/lib/logger/index.cjs +158 -0
- package/dist/v1/TinyBasicsEs.js +1653 -1
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDragDropDetector.js +307 -0
- package/dist/v1/TinyDragDropDetector.min.js +1 -0
- package/dist/v1/TinyDragger.js +3668 -0
- package/dist/v1/TinyDragger.min.js +2 -0
- package/dist/v1/TinyDragger.min.js.LICENSE.txt +8 -0
- package/dist/v1/TinyEssentials.js +2888 -2
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyNotifyCenter.js +32 -0
- package/dist/v1/TinyNotifyCenter.min.js +1 -1
- package/dist/v1/TinyToastNotify.js +24 -0
- package/dist/v1/TinyToastNotify.min.js +1 -1
- package/dist/v1/TinyUploadClicker.js +5340 -0
- package/dist/v1/TinyUploadClicker.min.js +2 -0
- package/dist/v1/TinyUploadClicker.min.js.LICENSE.txt +8 -0
- package/dist/v1/basics/fileManager.cjs +524 -0
- package/dist/v1/basics/fileManager.d.mts +209 -0
- package/dist/v1/basics/fileManager.mjs +443 -0
- package/dist/v1/basics/fullScreen.cjs +134 -0
- package/dist/v1/basics/fullScreen.d.mts +8 -0
- package/dist/v1/basics/fullScreen.mjs +121 -0
- package/dist/v1/basics/html.cjs +262 -0
- package/dist/v1/basics/html.d.mts +63 -0
- package/dist/v1/basics/html.mjs +208 -0
- package/dist/v1/basics/index.cjs +40 -0
- package/dist/v1/basics/index.d.mts +38 -1
- package/dist/v1/basics/index.mjs +4 -1
- package/dist/v1/build/TinyDragDropDetector.cjs +7 -0
- package/dist/v1/build/TinyDragDropDetector.d.mts +3 -0
- package/dist/v1/build/TinyDragDropDetector.mjs +2 -0
- package/dist/v1/build/TinyDragger.cjs +7 -0
- package/dist/v1/build/TinyDragger.d.mts +3 -0
- package/dist/v1/build/TinyDragger.mjs +2 -0
- package/dist/v1/build/TinyUploadClicker.cjs +7 -0
- package/dist/v1/build/TinyUploadClicker.d.mts +3 -0
- package/dist/v1/build/TinyUploadClicker.mjs +2 -0
- package/dist/v1/css/TinyDraggerExample.css +21 -0
- package/dist/v1/css/TinyDraggerExample.min.css +1 -0
- package/dist/v1/index.cjs +44 -0
- package/dist/v1/index.d.mts +40 -1
- package/dist/v1/index.mjs +6 -1
- package/dist/v1/libs/TinyDragDropDetector.cjs +268 -0
- package/dist/v1/libs/TinyDragDropDetector.d.mts +123 -0
- package/dist/v1/libs/TinyDragDropDetector.mjs +228 -0
- package/dist/v1/libs/TinyDragger.cjs +906 -0
- package/dist/v1/libs/TinyDragger.d.mts +316 -0
- package/dist/v1/libs/TinyDragger.mjs +783 -0
- package/dist/v1/libs/TinyNotifyCenter.cjs +32 -0
- package/dist/v1/libs/TinyNotifyCenter.d.mts +9 -0
- package/dist/v1/libs/TinyNotifyCenter.mjs +28 -0
- package/dist/v1/libs/TinyToastNotify.cjs +24 -0
- package/dist/v1/libs/TinyToastNotify.d.mts +8 -0
- package/dist/v1/libs/TinyToastNotify.mjs +20 -0
- package/dist/v1/libs/TinyUploadClicker.cjs +223 -0
- package/dist/v1/libs/TinyUploadClicker.d.mts +80 -0
- package/dist/v1/libs/TinyUploadClicker.mjs +182 -0
- package/docs/v1/README.md +8 -2
- package/docs/v1/basics/fileManager.md +222 -0
- package/docs/v1/basics/fullScreen.md +183 -0
- package/docs/v1/basics/html.md +243 -0
- package/docs/v1/libs/TinyDragDropDetector.md +143 -0
- package/docs/v1/libs/TinyDragger.md +430 -0
- package/docs/v1/libs/TinyLevelUp.md +1 -1
- package/docs/v1/libs/TinyNotifyCenter.md +20 -0
- package/docs/v1/libs/TinyToastNotify.md +19 -0
- package/docs/v1/libs/TinyUploadClicker.md +108 -0
- package/package.json +12 -2
|
@@ -0,0 +1,3668 @@
|
|
|
1
|
+
/******/ (() => { // webpackBootstrap
|
|
2
|
+
/******/ var __webpack_modules__ = ({
|
|
3
|
+
|
|
4
|
+
/***/ 251:
|
|
5
|
+
/***/ ((__unused_webpack_module, exports) => {
|
|
6
|
+
|
|
7
|
+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
8
|
+
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
|
|
9
|
+
var e, m
|
|
10
|
+
var eLen = (nBytes * 8) - mLen - 1
|
|
11
|
+
var eMax = (1 << eLen) - 1
|
|
12
|
+
var eBias = eMax >> 1
|
|
13
|
+
var nBits = -7
|
|
14
|
+
var i = isLE ? (nBytes - 1) : 0
|
|
15
|
+
var d = isLE ? -1 : 1
|
|
16
|
+
var s = buffer[offset + i]
|
|
17
|
+
|
|
18
|
+
i += d
|
|
19
|
+
|
|
20
|
+
e = s & ((1 << (-nBits)) - 1)
|
|
21
|
+
s >>= (-nBits)
|
|
22
|
+
nBits += eLen
|
|
23
|
+
for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
|
24
|
+
|
|
25
|
+
m = e & ((1 << (-nBits)) - 1)
|
|
26
|
+
e >>= (-nBits)
|
|
27
|
+
nBits += mLen
|
|
28
|
+
for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
|
29
|
+
|
|
30
|
+
if (e === 0) {
|
|
31
|
+
e = 1 - eBias
|
|
32
|
+
} else if (e === eMax) {
|
|
33
|
+
return m ? NaN : ((s ? -1 : 1) * Infinity)
|
|
34
|
+
} else {
|
|
35
|
+
m = m + Math.pow(2, mLen)
|
|
36
|
+
e = e - eBias
|
|
37
|
+
}
|
|
38
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
|
|
42
|
+
var e, m, c
|
|
43
|
+
var eLen = (nBytes * 8) - mLen - 1
|
|
44
|
+
var eMax = (1 << eLen) - 1
|
|
45
|
+
var eBias = eMax >> 1
|
|
46
|
+
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
|
|
47
|
+
var i = isLE ? 0 : (nBytes - 1)
|
|
48
|
+
var d = isLE ? 1 : -1
|
|
49
|
+
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
|
|
50
|
+
|
|
51
|
+
value = Math.abs(value)
|
|
52
|
+
|
|
53
|
+
if (isNaN(value) || value === Infinity) {
|
|
54
|
+
m = isNaN(value) ? 1 : 0
|
|
55
|
+
e = eMax
|
|
56
|
+
} else {
|
|
57
|
+
e = Math.floor(Math.log(value) / Math.LN2)
|
|
58
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
59
|
+
e--
|
|
60
|
+
c *= 2
|
|
61
|
+
}
|
|
62
|
+
if (e + eBias >= 1) {
|
|
63
|
+
value += rt / c
|
|
64
|
+
} else {
|
|
65
|
+
value += rt * Math.pow(2, 1 - eBias)
|
|
66
|
+
}
|
|
67
|
+
if (value * c >= 2) {
|
|
68
|
+
e++
|
|
69
|
+
c /= 2
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (e + eBias >= eMax) {
|
|
73
|
+
m = 0
|
|
74
|
+
e = eMax
|
|
75
|
+
} else if (e + eBias >= 1) {
|
|
76
|
+
m = ((value * c) - 1) * Math.pow(2, mLen)
|
|
77
|
+
e = e + eBias
|
|
78
|
+
} else {
|
|
79
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
|
|
80
|
+
e = 0
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
|
85
|
+
|
|
86
|
+
e = (e << mLen) | m
|
|
87
|
+
eLen += mLen
|
|
88
|
+
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
|
89
|
+
|
|
90
|
+
buffer[offset + i - d] |= s * 128
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
/***/ }),
|
|
95
|
+
|
|
96
|
+
/***/ 287:
|
|
97
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
98
|
+
|
|
99
|
+
"use strict";
|
|
100
|
+
var __webpack_unused_export__;
|
|
101
|
+
/*!
|
|
102
|
+
* The buffer module from node.js, for the browser.
|
|
103
|
+
*
|
|
104
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
105
|
+
* @license MIT
|
|
106
|
+
*/
|
|
107
|
+
/* eslint-disable no-proto */
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
var base64 = __webpack_require__(526)
|
|
112
|
+
var ieee754 = __webpack_require__(251)
|
|
113
|
+
var customInspectSymbol =
|
|
114
|
+
(typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
|
|
115
|
+
? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
|
|
116
|
+
: null
|
|
117
|
+
|
|
118
|
+
exports.hp = Buffer
|
|
119
|
+
__webpack_unused_export__ = SlowBuffer
|
|
120
|
+
exports.IS = 50
|
|
121
|
+
|
|
122
|
+
var K_MAX_LENGTH = 0x7fffffff
|
|
123
|
+
__webpack_unused_export__ = K_MAX_LENGTH
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* If `Buffer.TYPED_ARRAY_SUPPORT`:
|
|
127
|
+
* === true Use Uint8Array implementation (fastest)
|
|
128
|
+
* === false Print warning and recommend using `buffer` v4.x which has an Object
|
|
129
|
+
* implementation (most compatible, even IE6)
|
|
130
|
+
*
|
|
131
|
+
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
|
|
132
|
+
* Opera 11.6+, iOS 4.2+.
|
|
133
|
+
*
|
|
134
|
+
* We report that the browser does not support typed arrays if the are not subclassable
|
|
135
|
+
* using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
|
|
136
|
+
* (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
|
|
137
|
+
* for __proto__ and has a buggy typed array implementation.
|
|
138
|
+
*/
|
|
139
|
+
Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
|
|
140
|
+
|
|
141
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
|
|
142
|
+
typeof console.error === 'function') {
|
|
143
|
+
console.error(
|
|
144
|
+
'This browser lacks typed array (Uint8Array) support which is required by ' +
|
|
145
|
+
'`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function typedArraySupport () {
|
|
150
|
+
// Can typed array instances can be augmented?
|
|
151
|
+
try {
|
|
152
|
+
var arr = new Uint8Array(1)
|
|
153
|
+
var proto = { foo: function () { return 42 } }
|
|
154
|
+
Object.setPrototypeOf(proto, Uint8Array.prototype)
|
|
155
|
+
Object.setPrototypeOf(arr, proto)
|
|
156
|
+
return arr.foo() === 42
|
|
157
|
+
} catch (e) {
|
|
158
|
+
return false
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
Object.defineProperty(Buffer.prototype, 'parent', {
|
|
163
|
+
enumerable: true,
|
|
164
|
+
get: function () {
|
|
165
|
+
if (!Buffer.isBuffer(this)) return undefined
|
|
166
|
+
return this.buffer
|
|
167
|
+
}
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
Object.defineProperty(Buffer.prototype, 'offset', {
|
|
171
|
+
enumerable: true,
|
|
172
|
+
get: function () {
|
|
173
|
+
if (!Buffer.isBuffer(this)) return undefined
|
|
174
|
+
return this.byteOffset
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
function createBuffer (length) {
|
|
179
|
+
if (length > K_MAX_LENGTH) {
|
|
180
|
+
throw new RangeError('The value "' + length + '" is invalid for option "size"')
|
|
181
|
+
}
|
|
182
|
+
// Return an augmented `Uint8Array` instance
|
|
183
|
+
var buf = new Uint8Array(length)
|
|
184
|
+
Object.setPrototypeOf(buf, Buffer.prototype)
|
|
185
|
+
return buf
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* The Buffer constructor returns instances of `Uint8Array` that have their
|
|
190
|
+
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
|
|
191
|
+
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
|
|
192
|
+
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
|
|
193
|
+
* returns a single octet.
|
|
194
|
+
*
|
|
195
|
+
* The `Uint8Array` prototype remains unmodified.
|
|
196
|
+
*/
|
|
197
|
+
|
|
198
|
+
function Buffer (arg, encodingOrOffset, length) {
|
|
199
|
+
// Common case.
|
|
200
|
+
if (typeof arg === 'number') {
|
|
201
|
+
if (typeof encodingOrOffset === 'string') {
|
|
202
|
+
throw new TypeError(
|
|
203
|
+
'The "string" argument must be of type string. Received type number'
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
return allocUnsafe(arg)
|
|
207
|
+
}
|
|
208
|
+
return from(arg, encodingOrOffset, length)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
Buffer.poolSize = 8192 // not used by this implementation
|
|
212
|
+
|
|
213
|
+
function from (value, encodingOrOffset, length) {
|
|
214
|
+
if (typeof value === 'string') {
|
|
215
|
+
return fromString(value, encodingOrOffset)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (ArrayBuffer.isView(value)) {
|
|
219
|
+
return fromArrayView(value)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (value == null) {
|
|
223
|
+
throw new TypeError(
|
|
224
|
+
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
|
225
|
+
'or Array-like Object. Received type ' + (typeof value)
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (isInstance(value, ArrayBuffer) ||
|
|
230
|
+
(value && isInstance(value.buffer, ArrayBuffer))) {
|
|
231
|
+
return fromArrayBuffer(value, encodingOrOffset, length)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (typeof SharedArrayBuffer !== 'undefined' &&
|
|
235
|
+
(isInstance(value, SharedArrayBuffer) ||
|
|
236
|
+
(value && isInstance(value.buffer, SharedArrayBuffer)))) {
|
|
237
|
+
return fromArrayBuffer(value, encodingOrOffset, length)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (typeof value === 'number') {
|
|
241
|
+
throw new TypeError(
|
|
242
|
+
'The "value" argument must not be of type number. Received type number'
|
|
243
|
+
)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
var valueOf = value.valueOf && value.valueOf()
|
|
247
|
+
if (valueOf != null && valueOf !== value) {
|
|
248
|
+
return Buffer.from(valueOf, encodingOrOffset, length)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
var b = fromObject(value)
|
|
252
|
+
if (b) return b
|
|
253
|
+
|
|
254
|
+
if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
|
|
255
|
+
typeof value[Symbol.toPrimitive] === 'function') {
|
|
256
|
+
return Buffer.from(
|
|
257
|
+
value[Symbol.toPrimitive]('string'), encodingOrOffset, length
|
|
258
|
+
)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
throw new TypeError(
|
|
262
|
+
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
|
263
|
+
'or Array-like Object. Received type ' + (typeof value)
|
|
264
|
+
)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
|
|
269
|
+
* if value is a number.
|
|
270
|
+
* Buffer.from(str[, encoding])
|
|
271
|
+
* Buffer.from(array)
|
|
272
|
+
* Buffer.from(buffer)
|
|
273
|
+
* Buffer.from(arrayBuffer[, byteOffset[, length]])
|
|
274
|
+
**/
|
|
275
|
+
Buffer.from = function (value, encodingOrOffset, length) {
|
|
276
|
+
return from(value, encodingOrOffset, length)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
|
|
280
|
+
// https://github.com/feross/buffer/pull/148
|
|
281
|
+
Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype)
|
|
282
|
+
Object.setPrototypeOf(Buffer, Uint8Array)
|
|
283
|
+
|
|
284
|
+
function assertSize (size) {
|
|
285
|
+
if (typeof size !== 'number') {
|
|
286
|
+
throw new TypeError('"size" argument must be of type number')
|
|
287
|
+
} else if (size < 0) {
|
|
288
|
+
throw new RangeError('The value "' + size + '" is invalid for option "size"')
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function alloc (size, fill, encoding) {
|
|
293
|
+
assertSize(size)
|
|
294
|
+
if (size <= 0) {
|
|
295
|
+
return createBuffer(size)
|
|
296
|
+
}
|
|
297
|
+
if (fill !== undefined) {
|
|
298
|
+
// Only pay attention to encoding if it's a string. This
|
|
299
|
+
// prevents accidentally sending in a number that would
|
|
300
|
+
// be interpreted as a start offset.
|
|
301
|
+
return typeof encoding === 'string'
|
|
302
|
+
? createBuffer(size).fill(fill, encoding)
|
|
303
|
+
: createBuffer(size).fill(fill)
|
|
304
|
+
}
|
|
305
|
+
return createBuffer(size)
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Creates a new filled Buffer instance.
|
|
310
|
+
* alloc(size[, fill[, encoding]])
|
|
311
|
+
**/
|
|
312
|
+
Buffer.alloc = function (size, fill, encoding) {
|
|
313
|
+
return alloc(size, fill, encoding)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function allocUnsafe (size) {
|
|
317
|
+
assertSize(size)
|
|
318
|
+
return createBuffer(size < 0 ? 0 : checked(size) | 0)
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
|
|
323
|
+
* */
|
|
324
|
+
Buffer.allocUnsafe = function (size) {
|
|
325
|
+
return allocUnsafe(size)
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
|
329
|
+
*/
|
|
330
|
+
Buffer.allocUnsafeSlow = function (size) {
|
|
331
|
+
return allocUnsafe(size)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function fromString (string, encoding) {
|
|
335
|
+
if (typeof encoding !== 'string' || encoding === '') {
|
|
336
|
+
encoding = 'utf8'
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (!Buffer.isEncoding(encoding)) {
|
|
340
|
+
throw new TypeError('Unknown encoding: ' + encoding)
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
var length = byteLength(string, encoding) | 0
|
|
344
|
+
var buf = createBuffer(length)
|
|
345
|
+
|
|
346
|
+
var actual = buf.write(string, encoding)
|
|
347
|
+
|
|
348
|
+
if (actual !== length) {
|
|
349
|
+
// Writing a hex string, for example, that contains invalid characters will
|
|
350
|
+
// cause everything after the first invalid character to be ignored. (e.g.
|
|
351
|
+
// 'abxxcd' will be treated as 'ab')
|
|
352
|
+
buf = buf.slice(0, actual)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return buf
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function fromArrayLike (array) {
|
|
359
|
+
var length = array.length < 0 ? 0 : checked(array.length) | 0
|
|
360
|
+
var buf = createBuffer(length)
|
|
361
|
+
for (var i = 0; i < length; i += 1) {
|
|
362
|
+
buf[i] = array[i] & 255
|
|
363
|
+
}
|
|
364
|
+
return buf
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function fromArrayView (arrayView) {
|
|
368
|
+
if (isInstance(arrayView, Uint8Array)) {
|
|
369
|
+
var copy = new Uint8Array(arrayView)
|
|
370
|
+
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
|
|
371
|
+
}
|
|
372
|
+
return fromArrayLike(arrayView)
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function fromArrayBuffer (array, byteOffset, length) {
|
|
376
|
+
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
377
|
+
throw new RangeError('"offset" is outside of buffer bounds')
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (array.byteLength < byteOffset + (length || 0)) {
|
|
381
|
+
throw new RangeError('"length" is outside of buffer bounds')
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
var buf
|
|
385
|
+
if (byteOffset === undefined && length === undefined) {
|
|
386
|
+
buf = new Uint8Array(array)
|
|
387
|
+
} else if (length === undefined) {
|
|
388
|
+
buf = new Uint8Array(array, byteOffset)
|
|
389
|
+
} else {
|
|
390
|
+
buf = new Uint8Array(array, byteOffset, length)
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// Return an augmented `Uint8Array` instance
|
|
394
|
+
Object.setPrototypeOf(buf, Buffer.prototype)
|
|
395
|
+
|
|
396
|
+
return buf
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function fromObject (obj) {
|
|
400
|
+
if (Buffer.isBuffer(obj)) {
|
|
401
|
+
var len = checked(obj.length) | 0
|
|
402
|
+
var buf = createBuffer(len)
|
|
403
|
+
|
|
404
|
+
if (buf.length === 0) {
|
|
405
|
+
return buf
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
obj.copy(buf, 0, 0, len)
|
|
409
|
+
return buf
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
if (obj.length !== undefined) {
|
|
413
|
+
if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
|
|
414
|
+
return createBuffer(0)
|
|
415
|
+
}
|
|
416
|
+
return fromArrayLike(obj)
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
|
|
420
|
+
return fromArrayLike(obj.data)
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function checked (length) {
|
|
425
|
+
// Note: cannot use `length < K_MAX_LENGTH` here because that fails when
|
|
426
|
+
// length is NaN (which is otherwise coerced to zero.)
|
|
427
|
+
if (length >= K_MAX_LENGTH) {
|
|
428
|
+
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
|
429
|
+
'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
|
|
430
|
+
}
|
|
431
|
+
return length | 0
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function SlowBuffer (length) {
|
|
435
|
+
if (+length != length) { // eslint-disable-line eqeqeq
|
|
436
|
+
length = 0
|
|
437
|
+
}
|
|
438
|
+
return Buffer.alloc(+length)
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
Buffer.isBuffer = function isBuffer (b) {
|
|
442
|
+
return b != null && b._isBuffer === true &&
|
|
443
|
+
b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
Buffer.compare = function compare (a, b) {
|
|
447
|
+
if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
|
|
448
|
+
if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
|
|
449
|
+
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
|
|
450
|
+
throw new TypeError(
|
|
451
|
+
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
|
|
452
|
+
)
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (a === b) return 0
|
|
456
|
+
|
|
457
|
+
var x = a.length
|
|
458
|
+
var y = b.length
|
|
459
|
+
|
|
460
|
+
for (var i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
461
|
+
if (a[i] !== b[i]) {
|
|
462
|
+
x = a[i]
|
|
463
|
+
y = b[i]
|
|
464
|
+
break
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
if (x < y) return -1
|
|
469
|
+
if (y < x) return 1
|
|
470
|
+
return 0
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
Buffer.isEncoding = function isEncoding (encoding) {
|
|
474
|
+
switch (String(encoding).toLowerCase()) {
|
|
475
|
+
case 'hex':
|
|
476
|
+
case 'utf8':
|
|
477
|
+
case 'utf-8':
|
|
478
|
+
case 'ascii':
|
|
479
|
+
case 'latin1':
|
|
480
|
+
case 'binary':
|
|
481
|
+
case 'base64':
|
|
482
|
+
case 'ucs2':
|
|
483
|
+
case 'ucs-2':
|
|
484
|
+
case 'utf16le':
|
|
485
|
+
case 'utf-16le':
|
|
486
|
+
return true
|
|
487
|
+
default:
|
|
488
|
+
return false
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
Buffer.concat = function concat (list, length) {
|
|
493
|
+
if (!Array.isArray(list)) {
|
|
494
|
+
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
if (list.length === 0) {
|
|
498
|
+
return Buffer.alloc(0)
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
var i
|
|
502
|
+
if (length === undefined) {
|
|
503
|
+
length = 0
|
|
504
|
+
for (i = 0; i < list.length; ++i) {
|
|
505
|
+
length += list[i].length
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
var buffer = Buffer.allocUnsafe(length)
|
|
510
|
+
var pos = 0
|
|
511
|
+
for (i = 0; i < list.length; ++i) {
|
|
512
|
+
var buf = list[i]
|
|
513
|
+
if (isInstance(buf, Uint8Array)) {
|
|
514
|
+
if (pos + buf.length > buffer.length) {
|
|
515
|
+
Buffer.from(buf).copy(buffer, pos)
|
|
516
|
+
} else {
|
|
517
|
+
Uint8Array.prototype.set.call(
|
|
518
|
+
buffer,
|
|
519
|
+
buf,
|
|
520
|
+
pos
|
|
521
|
+
)
|
|
522
|
+
}
|
|
523
|
+
} else if (!Buffer.isBuffer(buf)) {
|
|
524
|
+
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
525
|
+
} else {
|
|
526
|
+
buf.copy(buffer, pos)
|
|
527
|
+
}
|
|
528
|
+
pos += buf.length
|
|
529
|
+
}
|
|
530
|
+
return buffer
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function byteLength (string, encoding) {
|
|
534
|
+
if (Buffer.isBuffer(string)) {
|
|
535
|
+
return string.length
|
|
536
|
+
}
|
|
537
|
+
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
|
|
538
|
+
return string.byteLength
|
|
539
|
+
}
|
|
540
|
+
if (typeof string !== 'string') {
|
|
541
|
+
throw new TypeError(
|
|
542
|
+
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
|
|
543
|
+
'Received type ' + typeof string
|
|
544
|
+
)
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
var len = string.length
|
|
548
|
+
var mustMatch = (arguments.length > 2 && arguments[2] === true)
|
|
549
|
+
if (!mustMatch && len === 0) return 0
|
|
550
|
+
|
|
551
|
+
// Use a for loop to avoid recursion
|
|
552
|
+
var loweredCase = false
|
|
553
|
+
for (;;) {
|
|
554
|
+
switch (encoding) {
|
|
555
|
+
case 'ascii':
|
|
556
|
+
case 'latin1':
|
|
557
|
+
case 'binary':
|
|
558
|
+
return len
|
|
559
|
+
case 'utf8':
|
|
560
|
+
case 'utf-8':
|
|
561
|
+
return utf8ToBytes(string).length
|
|
562
|
+
case 'ucs2':
|
|
563
|
+
case 'ucs-2':
|
|
564
|
+
case 'utf16le':
|
|
565
|
+
case 'utf-16le':
|
|
566
|
+
return len * 2
|
|
567
|
+
case 'hex':
|
|
568
|
+
return len >>> 1
|
|
569
|
+
case 'base64':
|
|
570
|
+
return base64ToBytes(string).length
|
|
571
|
+
default:
|
|
572
|
+
if (loweredCase) {
|
|
573
|
+
return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
|
|
574
|
+
}
|
|
575
|
+
encoding = ('' + encoding).toLowerCase()
|
|
576
|
+
loweredCase = true
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
Buffer.byteLength = byteLength
|
|
581
|
+
|
|
582
|
+
function slowToString (encoding, start, end) {
|
|
583
|
+
var loweredCase = false
|
|
584
|
+
|
|
585
|
+
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
|
|
586
|
+
// property of a typed array.
|
|
587
|
+
|
|
588
|
+
// This behaves neither like String nor Uint8Array in that we set start/end
|
|
589
|
+
// to their upper/lower bounds if the value passed is out of range.
|
|
590
|
+
// undefined is handled specially as per ECMA-262 6th Edition,
|
|
591
|
+
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
|
|
592
|
+
if (start === undefined || start < 0) {
|
|
593
|
+
start = 0
|
|
594
|
+
}
|
|
595
|
+
// Return early if start > this.length. Done here to prevent potential uint32
|
|
596
|
+
// coercion fail below.
|
|
597
|
+
if (start > this.length) {
|
|
598
|
+
return ''
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
if (end === undefined || end > this.length) {
|
|
602
|
+
end = this.length
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
if (end <= 0) {
|
|
606
|
+
return ''
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// Force coercion to uint32. This will also coerce falsey/NaN values to 0.
|
|
610
|
+
end >>>= 0
|
|
611
|
+
start >>>= 0
|
|
612
|
+
|
|
613
|
+
if (end <= start) {
|
|
614
|
+
return ''
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
if (!encoding) encoding = 'utf8'
|
|
618
|
+
|
|
619
|
+
while (true) {
|
|
620
|
+
switch (encoding) {
|
|
621
|
+
case 'hex':
|
|
622
|
+
return hexSlice(this, start, end)
|
|
623
|
+
|
|
624
|
+
case 'utf8':
|
|
625
|
+
case 'utf-8':
|
|
626
|
+
return utf8Slice(this, start, end)
|
|
627
|
+
|
|
628
|
+
case 'ascii':
|
|
629
|
+
return asciiSlice(this, start, end)
|
|
630
|
+
|
|
631
|
+
case 'latin1':
|
|
632
|
+
case 'binary':
|
|
633
|
+
return latin1Slice(this, start, end)
|
|
634
|
+
|
|
635
|
+
case 'base64':
|
|
636
|
+
return base64Slice(this, start, end)
|
|
637
|
+
|
|
638
|
+
case 'ucs2':
|
|
639
|
+
case 'ucs-2':
|
|
640
|
+
case 'utf16le':
|
|
641
|
+
case 'utf-16le':
|
|
642
|
+
return utf16leSlice(this, start, end)
|
|
643
|
+
|
|
644
|
+
default:
|
|
645
|
+
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
646
|
+
encoding = (encoding + '').toLowerCase()
|
|
647
|
+
loweredCase = true
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
|
|
653
|
+
// to detect a Buffer instance. It's not possible to use `instanceof Buffer`
|
|
654
|
+
// reliably in a browserify context because there could be multiple different
|
|
655
|
+
// copies of the 'buffer' package in use. This method works even for Buffer
|
|
656
|
+
// instances that were created from another copy of the `buffer` package.
|
|
657
|
+
// See: https://github.com/feross/buffer/issues/154
|
|
658
|
+
Buffer.prototype._isBuffer = true
|
|
659
|
+
|
|
660
|
+
function swap (b, n, m) {
|
|
661
|
+
var i = b[n]
|
|
662
|
+
b[n] = b[m]
|
|
663
|
+
b[m] = i
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
Buffer.prototype.swap16 = function swap16 () {
|
|
667
|
+
var len = this.length
|
|
668
|
+
if (len % 2 !== 0) {
|
|
669
|
+
throw new RangeError('Buffer size must be a multiple of 16-bits')
|
|
670
|
+
}
|
|
671
|
+
for (var i = 0; i < len; i += 2) {
|
|
672
|
+
swap(this, i, i + 1)
|
|
673
|
+
}
|
|
674
|
+
return this
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
Buffer.prototype.swap32 = function swap32 () {
|
|
678
|
+
var len = this.length
|
|
679
|
+
if (len % 4 !== 0) {
|
|
680
|
+
throw new RangeError('Buffer size must be a multiple of 32-bits')
|
|
681
|
+
}
|
|
682
|
+
for (var i = 0; i < len; i += 4) {
|
|
683
|
+
swap(this, i, i + 3)
|
|
684
|
+
swap(this, i + 1, i + 2)
|
|
685
|
+
}
|
|
686
|
+
return this
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
Buffer.prototype.swap64 = function swap64 () {
|
|
690
|
+
var len = this.length
|
|
691
|
+
if (len % 8 !== 0) {
|
|
692
|
+
throw new RangeError('Buffer size must be a multiple of 64-bits')
|
|
693
|
+
}
|
|
694
|
+
for (var i = 0; i < len; i += 8) {
|
|
695
|
+
swap(this, i, i + 7)
|
|
696
|
+
swap(this, i + 1, i + 6)
|
|
697
|
+
swap(this, i + 2, i + 5)
|
|
698
|
+
swap(this, i + 3, i + 4)
|
|
699
|
+
}
|
|
700
|
+
return this
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
Buffer.prototype.toString = function toString () {
|
|
704
|
+
var length = this.length
|
|
705
|
+
if (length === 0) return ''
|
|
706
|
+
if (arguments.length === 0) return utf8Slice(this, 0, length)
|
|
707
|
+
return slowToString.apply(this, arguments)
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
Buffer.prototype.toLocaleString = Buffer.prototype.toString
|
|
711
|
+
|
|
712
|
+
Buffer.prototype.equals = function equals (b) {
|
|
713
|
+
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
|
714
|
+
if (this === b) return true
|
|
715
|
+
return Buffer.compare(this, b) === 0
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
Buffer.prototype.inspect = function inspect () {
|
|
719
|
+
var str = ''
|
|
720
|
+
var max = exports.IS
|
|
721
|
+
str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
|
|
722
|
+
if (this.length > max) str += ' ... '
|
|
723
|
+
return '<Buffer ' + str + '>'
|
|
724
|
+
}
|
|
725
|
+
if (customInspectSymbol) {
|
|
726
|
+
Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
|
|
730
|
+
if (isInstance(target, Uint8Array)) {
|
|
731
|
+
target = Buffer.from(target, target.offset, target.byteLength)
|
|
732
|
+
}
|
|
733
|
+
if (!Buffer.isBuffer(target)) {
|
|
734
|
+
throw new TypeError(
|
|
735
|
+
'The "target" argument must be one of type Buffer or Uint8Array. ' +
|
|
736
|
+
'Received type ' + (typeof target)
|
|
737
|
+
)
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
if (start === undefined) {
|
|
741
|
+
start = 0
|
|
742
|
+
}
|
|
743
|
+
if (end === undefined) {
|
|
744
|
+
end = target ? target.length : 0
|
|
745
|
+
}
|
|
746
|
+
if (thisStart === undefined) {
|
|
747
|
+
thisStart = 0
|
|
748
|
+
}
|
|
749
|
+
if (thisEnd === undefined) {
|
|
750
|
+
thisEnd = this.length
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
754
|
+
throw new RangeError('out of range index')
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
if (thisStart >= thisEnd && start >= end) {
|
|
758
|
+
return 0
|
|
759
|
+
}
|
|
760
|
+
if (thisStart >= thisEnd) {
|
|
761
|
+
return -1
|
|
762
|
+
}
|
|
763
|
+
if (start >= end) {
|
|
764
|
+
return 1
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
start >>>= 0
|
|
768
|
+
end >>>= 0
|
|
769
|
+
thisStart >>>= 0
|
|
770
|
+
thisEnd >>>= 0
|
|
771
|
+
|
|
772
|
+
if (this === target) return 0
|
|
773
|
+
|
|
774
|
+
var x = thisEnd - thisStart
|
|
775
|
+
var y = end - start
|
|
776
|
+
var len = Math.min(x, y)
|
|
777
|
+
|
|
778
|
+
var thisCopy = this.slice(thisStart, thisEnd)
|
|
779
|
+
var targetCopy = target.slice(start, end)
|
|
780
|
+
|
|
781
|
+
for (var i = 0; i < len; ++i) {
|
|
782
|
+
if (thisCopy[i] !== targetCopy[i]) {
|
|
783
|
+
x = thisCopy[i]
|
|
784
|
+
y = targetCopy[i]
|
|
785
|
+
break
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
if (x < y) return -1
|
|
790
|
+
if (y < x) return 1
|
|
791
|
+
return 0
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
|
|
795
|
+
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
|
|
796
|
+
//
|
|
797
|
+
// Arguments:
|
|
798
|
+
// - buffer - a Buffer to search
|
|
799
|
+
// - val - a string, Buffer, or number
|
|
800
|
+
// - byteOffset - an index into `buffer`; will be clamped to an int32
|
|
801
|
+
// - encoding - an optional encoding, relevant is val is a string
|
|
802
|
+
// - dir - true for indexOf, false for lastIndexOf
|
|
803
|
+
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
|
804
|
+
// Empty buffer means no match
|
|
805
|
+
if (buffer.length === 0) return -1
|
|
806
|
+
|
|
807
|
+
// Normalize byteOffset
|
|
808
|
+
if (typeof byteOffset === 'string') {
|
|
809
|
+
encoding = byteOffset
|
|
810
|
+
byteOffset = 0
|
|
811
|
+
} else if (byteOffset > 0x7fffffff) {
|
|
812
|
+
byteOffset = 0x7fffffff
|
|
813
|
+
} else if (byteOffset < -0x80000000) {
|
|
814
|
+
byteOffset = -0x80000000
|
|
815
|
+
}
|
|
816
|
+
byteOffset = +byteOffset // Coerce to Number.
|
|
817
|
+
if (numberIsNaN(byteOffset)) {
|
|
818
|
+
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
|
|
819
|
+
byteOffset = dir ? 0 : (buffer.length - 1)
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
// Normalize byteOffset: negative offsets start from the end of the buffer
|
|
823
|
+
if (byteOffset < 0) byteOffset = buffer.length + byteOffset
|
|
824
|
+
if (byteOffset >= buffer.length) {
|
|
825
|
+
if (dir) return -1
|
|
826
|
+
else byteOffset = buffer.length - 1
|
|
827
|
+
} else if (byteOffset < 0) {
|
|
828
|
+
if (dir) byteOffset = 0
|
|
829
|
+
else return -1
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
// Normalize val
|
|
833
|
+
if (typeof val === 'string') {
|
|
834
|
+
val = Buffer.from(val, encoding)
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
// Finally, search either indexOf (if dir is true) or lastIndexOf
|
|
838
|
+
if (Buffer.isBuffer(val)) {
|
|
839
|
+
// Special case: looking for empty string/buffer always fails
|
|
840
|
+
if (val.length === 0) {
|
|
841
|
+
return -1
|
|
842
|
+
}
|
|
843
|
+
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
|
844
|
+
} else if (typeof val === 'number') {
|
|
845
|
+
val = val & 0xFF // Search for a byte value [0-255]
|
|
846
|
+
if (typeof Uint8Array.prototype.indexOf === 'function') {
|
|
847
|
+
if (dir) {
|
|
848
|
+
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
|
|
849
|
+
} else {
|
|
850
|
+
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
throw new TypeError('val must be string, number or Buffer')
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
|
|
860
|
+
var indexSize = 1
|
|
861
|
+
var arrLength = arr.length
|
|
862
|
+
var valLength = val.length
|
|
863
|
+
|
|
864
|
+
if (encoding !== undefined) {
|
|
865
|
+
encoding = String(encoding).toLowerCase()
|
|
866
|
+
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
|
|
867
|
+
encoding === 'utf16le' || encoding === 'utf-16le') {
|
|
868
|
+
if (arr.length < 2 || val.length < 2) {
|
|
869
|
+
return -1
|
|
870
|
+
}
|
|
871
|
+
indexSize = 2
|
|
872
|
+
arrLength /= 2
|
|
873
|
+
valLength /= 2
|
|
874
|
+
byteOffset /= 2
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
function read (buf, i) {
|
|
879
|
+
if (indexSize === 1) {
|
|
880
|
+
return buf[i]
|
|
881
|
+
} else {
|
|
882
|
+
return buf.readUInt16BE(i * indexSize)
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
var i
|
|
887
|
+
if (dir) {
|
|
888
|
+
var foundIndex = -1
|
|
889
|
+
for (i = byteOffset; i < arrLength; i++) {
|
|
890
|
+
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
891
|
+
if (foundIndex === -1) foundIndex = i
|
|
892
|
+
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
|
|
893
|
+
} else {
|
|
894
|
+
if (foundIndex !== -1) i -= i - foundIndex
|
|
895
|
+
foundIndex = -1
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
} else {
|
|
899
|
+
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
|
|
900
|
+
for (i = byteOffset; i >= 0; i--) {
|
|
901
|
+
var found = true
|
|
902
|
+
for (var j = 0; j < valLength; j++) {
|
|
903
|
+
if (read(arr, i + j) !== read(val, j)) {
|
|
904
|
+
found = false
|
|
905
|
+
break
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
if (found) return i
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
return -1
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
|
|
916
|
+
return this.indexOf(val, byteOffset, encoding) !== -1
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
|
920
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
|
|
924
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
function hexWrite (buf, string, offset, length) {
|
|
928
|
+
offset = Number(offset) || 0
|
|
929
|
+
var remaining = buf.length - offset
|
|
930
|
+
if (!length) {
|
|
931
|
+
length = remaining
|
|
932
|
+
} else {
|
|
933
|
+
length = Number(length)
|
|
934
|
+
if (length > remaining) {
|
|
935
|
+
length = remaining
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
var strLen = string.length
|
|
940
|
+
|
|
941
|
+
if (length > strLen / 2) {
|
|
942
|
+
length = strLen / 2
|
|
943
|
+
}
|
|
944
|
+
for (var i = 0; i < length; ++i) {
|
|
945
|
+
var parsed = parseInt(string.substr(i * 2, 2), 16)
|
|
946
|
+
if (numberIsNaN(parsed)) return i
|
|
947
|
+
buf[offset + i] = parsed
|
|
948
|
+
}
|
|
949
|
+
return i
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
function utf8Write (buf, string, offset, length) {
|
|
953
|
+
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
function asciiWrite (buf, string, offset, length) {
|
|
957
|
+
return blitBuffer(asciiToBytes(string), buf, offset, length)
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
function base64Write (buf, string, offset, length) {
|
|
961
|
+
return blitBuffer(base64ToBytes(string), buf, offset, length)
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
function ucs2Write (buf, string, offset, length) {
|
|
965
|
+
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
Buffer.prototype.write = function write (string, offset, length, encoding) {
|
|
969
|
+
// Buffer#write(string)
|
|
970
|
+
if (offset === undefined) {
|
|
971
|
+
encoding = 'utf8'
|
|
972
|
+
length = this.length
|
|
973
|
+
offset = 0
|
|
974
|
+
// Buffer#write(string, encoding)
|
|
975
|
+
} else if (length === undefined && typeof offset === 'string') {
|
|
976
|
+
encoding = offset
|
|
977
|
+
length = this.length
|
|
978
|
+
offset = 0
|
|
979
|
+
// Buffer#write(string, offset[, length][, encoding])
|
|
980
|
+
} else if (isFinite(offset)) {
|
|
981
|
+
offset = offset >>> 0
|
|
982
|
+
if (isFinite(length)) {
|
|
983
|
+
length = length >>> 0
|
|
984
|
+
if (encoding === undefined) encoding = 'utf8'
|
|
985
|
+
} else {
|
|
986
|
+
encoding = length
|
|
987
|
+
length = undefined
|
|
988
|
+
}
|
|
989
|
+
} else {
|
|
990
|
+
throw new Error(
|
|
991
|
+
'Buffer.write(string, encoding, offset[, length]) is no longer supported'
|
|
992
|
+
)
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
var remaining = this.length - offset
|
|
996
|
+
if (length === undefined || length > remaining) length = remaining
|
|
997
|
+
|
|
998
|
+
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
|
|
999
|
+
throw new RangeError('Attempt to write outside buffer bounds')
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
if (!encoding) encoding = 'utf8'
|
|
1003
|
+
|
|
1004
|
+
var loweredCase = false
|
|
1005
|
+
for (;;) {
|
|
1006
|
+
switch (encoding) {
|
|
1007
|
+
case 'hex':
|
|
1008
|
+
return hexWrite(this, string, offset, length)
|
|
1009
|
+
|
|
1010
|
+
case 'utf8':
|
|
1011
|
+
case 'utf-8':
|
|
1012
|
+
return utf8Write(this, string, offset, length)
|
|
1013
|
+
|
|
1014
|
+
case 'ascii':
|
|
1015
|
+
case 'latin1':
|
|
1016
|
+
case 'binary':
|
|
1017
|
+
return asciiWrite(this, string, offset, length)
|
|
1018
|
+
|
|
1019
|
+
case 'base64':
|
|
1020
|
+
// Warning: maxLength not taken into account in base64Write
|
|
1021
|
+
return base64Write(this, string, offset, length)
|
|
1022
|
+
|
|
1023
|
+
case 'ucs2':
|
|
1024
|
+
case 'ucs-2':
|
|
1025
|
+
case 'utf16le':
|
|
1026
|
+
case 'utf-16le':
|
|
1027
|
+
return ucs2Write(this, string, offset, length)
|
|
1028
|
+
|
|
1029
|
+
default:
|
|
1030
|
+
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
1031
|
+
encoding = ('' + encoding).toLowerCase()
|
|
1032
|
+
loweredCase = true
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
Buffer.prototype.toJSON = function toJSON () {
|
|
1038
|
+
return {
|
|
1039
|
+
type: 'Buffer',
|
|
1040
|
+
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
function base64Slice (buf, start, end) {
|
|
1045
|
+
if (start === 0 && end === buf.length) {
|
|
1046
|
+
return base64.fromByteArray(buf)
|
|
1047
|
+
} else {
|
|
1048
|
+
return base64.fromByteArray(buf.slice(start, end))
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
function utf8Slice (buf, start, end) {
|
|
1053
|
+
end = Math.min(buf.length, end)
|
|
1054
|
+
var res = []
|
|
1055
|
+
|
|
1056
|
+
var i = start
|
|
1057
|
+
while (i < end) {
|
|
1058
|
+
var firstByte = buf[i]
|
|
1059
|
+
var codePoint = null
|
|
1060
|
+
var bytesPerSequence = (firstByte > 0xEF)
|
|
1061
|
+
? 4
|
|
1062
|
+
: (firstByte > 0xDF)
|
|
1063
|
+
? 3
|
|
1064
|
+
: (firstByte > 0xBF)
|
|
1065
|
+
? 2
|
|
1066
|
+
: 1
|
|
1067
|
+
|
|
1068
|
+
if (i + bytesPerSequence <= end) {
|
|
1069
|
+
var secondByte, thirdByte, fourthByte, tempCodePoint
|
|
1070
|
+
|
|
1071
|
+
switch (bytesPerSequence) {
|
|
1072
|
+
case 1:
|
|
1073
|
+
if (firstByte < 0x80) {
|
|
1074
|
+
codePoint = firstByte
|
|
1075
|
+
}
|
|
1076
|
+
break
|
|
1077
|
+
case 2:
|
|
1078
|
+
secondByte = buf[i + 1]
|
|
1079
|
+
if ((secondByte & 0xC0) === 0x80) {
|
|
1080
|
+
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
|
|
1081
|
+
if (tempCodePoint > 0x7F) {
|
|
1082
|
+
codePoint = tempCodePoint
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
break
|
|
1086
|
+
case 3:
|
|
1087
|
+
secondByte = buf[i + 1]
|
|
1088
|
+
thirdByte = buf[i + 2]
|
|
1089
|
+
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
|
|
1090
|
+
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
|
|
1091
|
+
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
|
|
1092
|
+
codePoint = tempCodePoint
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
break
|
|
1096
|
+
case 4:
|
|
1097
|
+
secondByte = buf[i + 1]
|
|
1098
|
+
thirdByte = buf[i + 2]
|
|
1099
|
+
fourthByte = buf[i + 3]
|
|
1100
|
+
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
|
|
1101
|
+
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
|
|
1102
|
+
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
|
|
1103
|
+
codePoint = tempCodePoint
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
if (codePoint === null) {
|
|
1110
|
+
// we did not generate a valid codePoint so insert a
|
|
1111
|
+
// replacement char (U+FFFD) and advance only 1 byte
|
|
1112
|
+
codePoint = 0xFFFD
|
|
1113
|
+
bytesPerSequence = 1
|
|
1114
|
+
} else if (codePoint > 0xFFFF) {
|
|
1115
|
+
// encode to utf16 (surrogate pair dance)
|
|
1116
|
+
codePoint -= 0x10000
|
|
1117
|
+
res.push(codePoint >>> 10 & 0x3FF | 0xD800)
|
|
1118
|
+
codePoint = 0xDC00 | codePoint & 0x3FF
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
res.push(codePoint)
|
|
1122
|
+
i += bytesPerSequence
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
return decodeCodePointsArray(res)
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
|
|
1129
|
+
// the lowest limit is Chrome, with 0x10000 args.
|
|
1130
|
+
// We go 1 magnitude less, for safety
|
|
1131
|
+
var MAX_ARGUMENTS_LENGTH = 0x1000
|
|
1132
|
+
|
|
1133
|
+
function decodeCodePointsArray (codePoints) {
|
|
1134
|
+
var len = codePoints.length
|
|
1135
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
1136
|
+
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
// Decode in chunks to avoid "call stack size exceeded".
|
|
1140
|
+
var res = ''
|
|
1141
|
+
var i = 0
|
|
1142
|
+
while (i < len) {
|
|
1143
|
+
res += String.fromCharCode.apply(
|
|
1144
|
+
String,
|
|
1145
|
+
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
1146
|
+
)
|
|
1147
|
+
}
|
|
1148
|
+
return res
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
function asciiSlice (buf, start, end) {
|
|
1152
|
+
var ret = ''
|
|
1153
|
+
end = Math.min(buf.length, end)
|
|
1154
|
+
|
|
1155
|
+
for (var i = start; i < end; ++i) {
|
|
1156
|
+
ret += String.fromCharCode(buf[i] & 0x7F)
|
|
1157
|
+
}
|
|
1158
|
+
return ret
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
function latin1Slice (buf, start, end) {
|
|
1162
|
+
var ret = ''
|
|
1163
|
+
end = Math.min(buf.length, end)
|
|
1164
|
+
|
|
1165
|
+
for (var i = start; i < end; ++i) {
|
|
1166
|
+
ret += String.fromCharCode(buf[i])
|
|
1167
|
+
}
|
|
1168
|
+
return ret
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
function hexSlice (buf, start, end) {
|
|
1172
|
+
var len = buf.length
|
|
1173
|
+
|
|
1174
|
+
if (!start || start < 0) start = 0
|
|
1175
|
+
if (!end || end < 0 || end > len) end = len
|
|
1176
|
+
|
|
1177
|
+
var out = ''
|
|
1178
|
+
for (var i = start; i < end; ++i) {
|
|
1179
|
+
out += hexSliceLookupTable[buf[i]]
|
|
1180
|
+
}
|
|
1181
|
+
return out
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
function utf16leSlice (buf, start, end) {
|
|
1185
|
+
var bytes = buf.slice(start, end)
|
|
1186
|
+
var res = ''
|
|
1187
|
+
// If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
|
|
1188
|
+
for (var i = 0; i < bytes.length - 1; i += 2) {
|
|
1189
|
+
res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
|
|
1190
|
+
}
|
|
1191
|
+
return res
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
Buffer.prototype.slice = function slice (start, end) {
|
|
1195
|
+
var len = this.length
|
|
1196
|
+
start = ~~start
|
|
1197
|
+
end = end === undefined ? len : ~~end
|
|
1198
|
+
|
|
1199
|
+
if (start < 0) {
|
|
1200
|
+
start += len
|
|
1201
|
+
if (start < 0) start = 0
|
|
1202
|
+
} else if (start > len) {
|
|
1203
|
+
start = len
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
if (end < 0) {
|
|
1207
|
+
end += len
|
|
1208
|
+
if (end < 0) end = 0
|
|
1209
|
+
} else if (end > len) {
|
|
1210
|
+
end = len
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
if (end < start) end = start
|
|
1214
|
+
|
|
1215
|
+
var newBuf = this.subarray(start, end)
|
|
1216
|
+
// Return an augmented `Uint8Array` instance
|
|
1217
|
+
Object.setPrototypeOf(newBuf, Buffer.prototype)
|
|
1218
|
+
|
|
1219
|
+
return newBuf
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
/*
|
|
1223
|
+
* Need to make sure that buffer isn't trying to write out of bounds.
|
|
1224
|
+
*/
|
|
1225
|
+
function checkOffset (offset, ext, length) {
|
|
1226
|
+
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
|
|
1227
|
+
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
Buffer.prototype.readUintLE =
|
|
1231
|
+
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
|
|
1232
|
+
offset = offset >>> 0
|
|
1233
|
+
byteLength = byteLength >>> 0
|
|
1234
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length)
|
|
1235
|
+
|
|
1236
|
+
var val = this[offset]
|
|
1237
|
+
var mul = 1
|
|
1238
|
+
var i = 0
|
|
1239
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
1240
|
+
val += this[offset + i] * mul
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
return val
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
Buffer.prototype.readUintBE =
|
|
1247
|
+
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
|
|
1248
|
+
offset = offset >>> 0
|
|
1249
|
+
byteLength = byteLength >>> 0
|
|
1250
|
+
if (!noAssert) {
|
|
1251
|
+
checkOffset(offset, byteLength, this.length)
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
var val = this[offset + --byteLength]
|
|
1255
|
+
var mul = 1
|
|
1256
|
+
while (byteLength > 0 && (mul *= 0x100)) {
|
|
1257
|
+
val += this[offset + --byteLength] * mul
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
return val
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
Buffer.prototype.readUint8 =
|
|
1264
|
+
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
|
|
1265
|
+
offset = offset >>> 0
|
|
1266
|
+
if (!noAssert) checkOffset(offset, 1, this.length)
|
|
1267
|
+
return this[offset]
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
Buffer.prototype.readUint16LE =
|
|
1271
|
+
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
|
|
1272
|
+
offset = offset >>> 0
|
|
1273
|
+
if (!noAssert) checkOffset(offset, 2, this.length)
|
|
1274
|
+
return this[offset] | (this[offset + 1] << 8)
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
Buffer.prototype.readUint16BE =
|
|
1278
|
+
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
|
|
1279
|
+
offset = offset >>> 0
|
|
1280
|
+
if (!noAssert) checkOffset(offset, 2, this.length)
|
|
1281
|
+
return (this[offset] << 8) | this[offset + 1]
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
Buffer.prototype.readUint32LE =
|
|
1285
|
+
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
|
|
1286
|
+
offset = offset >>> 0
|
|
1287
|
+
if (!noAssert) checkOffset(offset, 4, this.length)
|
|
1288
|
+
|
|
1289
|
+
return ((this[offset]) |
|
|
1290
|
+
(this[offset + 1] << 8) |
|
|
1291
|
+
(this[offset + 2] << 16)) +
|
|
1292
|
+
(this[offset + 3] * 0x1000000)
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
Buffer.prototype.readUint32BE =
|
|
1296
|
+
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
|
|
1297
|
+
offset = offset >>> 0
|
|
1298
|
+
if (!noAssert) checkOffset(offset, 4, this.length)
|
|
1299
|
+
|
|
1300
|
+
return (this[offset] * 0x1000000) +
|
|
1301
|
+
((this[offset + 1] << 16) |
|
|
1302
|
+
(this[offset + 2] << 8) |
|
|
1303
|
+
this[offset + 3])
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
|
|
1307
|
+
offset = offset >>> 0
|
|
1308
|
+
byteLength = byteLength >>> 0
|
|
1309
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length)
|
|
1310
|
+
|
|
1311
|
+
var val = this[offset]
|
|
1312
|
+
var mul = 1
|
|
1313
|
+
var i = 0
|
|
1314
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
1315
|
+
val += this[offset + i] * mul
|
|
1316
|
+
}
|
|
1317
|
+
mul *= 0x80
|
|
1318
|
+
|
|
1319
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength)
|
|
1320
|
+
|
|
1321
|
+
return val
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
|
|
1325
|
+
offset = offset >>> 0
|
|
1326
|
+
byteLength = byteLength >>> 0
|
|
1327
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length)
|
|
1328
|
+
|
|
1329
|
+
var i = byteLength
|
|
1330
|
+
var mul = 1
|
|
1331
|
+
var val = this[offset + --i]
|
|
1332
|
+
while (i > 0 && (mul *= 0x100)) {
|
|
1333
|
+
val += this[offset + --i] * mul
|
|
1334
|
+
}
|
|
1335
|
+
mul *= 0x80
|
|
1336
|
+
|
|
1337
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength)
|
|
1338
|
+
|
|
1339
|
+
return val
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
|
|
1343
|
+
offset = offset >>> 0
|
|
1344
|
+
if (!noAssert) checkOffset(offset, 1, this.length)
|
|
1345
|
+
if (!(this[offset] & 0x80)) return (this[offset])
|
|
1346
|
+
return ((0xff - this[offset] + 1) * -1)
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
|
|
1350
|
+
offset = offset >>> 0
|
|
1351
|
+
if (!noAssert) checkOffset(offset, 2, this.length)
|
|
1352
|
+
var val = this[offset] | (this[offset + 1] << 8)
|
|
1353
|
+
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
|
|
1357
|
+
offset = offset >>> 0
|
|
1358
|
+
if (!noAssert) checkOffset(offset, 2, this.length)
|
|
1359
|
+
var val = this[offset + 1] | (this[offset] << 8)
|
|
1360
|
+
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
|
|
1364
|
+
offset = offset >>> 0
|
|
1365
|
+
if (!noAssert) checkOffset(offset, 4, this.length)
|
|
1366
|
+
|
|
1367
|
+
return (this[offset]) |
|
|
1368
|
+
(this[offset + 1] << 8) |
|
|
1369
|
+
(this[offset + 2] << 16) |
|
|
1370
|
+
(this[offset + 3] << 24)
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
|
|
1374
|
+
offset = offset >>> 0
|
|
1375
|
+
if (!noAssert) checkOffset(offset, 4, this.length)
|
|
1376
|
+
|
|
1377
|
+
return (this[offset] << 24) |
|
|
1378
|
+
(this[offset + 1] << 16) |
|
|
1379
|
+
(this[offset + 2] << 8) |
|
|
1380
|
+
(this[offset + 3])
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
|
|
1384
|
+
offset = offset >>> 0
|
|
1385
|
+
if (!noAssert) checkOffset(offset, 4, this.length)
|
|
1386
|
+
return ieee754.read(this, offset, true, 23, 4)
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
|
|
1390
|
+
offset = offset >>> 0
|
|
1391
|
+
if (!noAssert) checkOffset(offset, 4, this.length)
|
|
1392
|
+
return ieee754.read(this, offset, false, 23, 4)
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
|
|
1396
|
+
offset = offset >>> 0
|
|
1397
|
+
if (!noAssert) checkOffset(offset, 8, this.length)
|
|
1398
|
+
return ieee754.read(this, offset, true, 52, 8)
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
|
|
1402
|
+
offset = offset >>> 0
|
|
1403
|
+
if (!noAssert) checkOffset(offset, 8, this.length)
|
|
1404
|
+
return ieee754.read(this, offset, false, 52, 8)
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
function checkInt (buf, value, offset, ext, max, min) {
|
|
1408
|
+
if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
|
|
1409
|
+
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
|
|
1410
|
+
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
Buffer.prototype.writeUintLE =
|
|
1414
|
+
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
|
|
1415
|
+
value = +value
|
|
1416
|
+
offset = offset >>> 0
|
|
1417
|
+
byteLength = byteLength >>> 0
|
|
1418
|
+
if (!noAssert) {
|
|
1419
|
+
var maxBytes = Math.pow(2, 8 * byteLength) - 1
|
|
1420
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0)
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
var mul = 1
|
|
1424
|
+
var i = 0
|
|
1425
|
+
this[offset] = value & 0xFF
|
|
1426
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
1427
|
+
this[offset + i] = (value / mul) & 0xFF
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
return offset + byteLength
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
Buffer.prototype.writeUintBE =
|
|
1434
|
+
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
|
|
1435
|
+
value = +value
|
|
1436
|
+
offset = offset >>> 0
|
|
1437
|
+
byteLength = byteLength >>> 0
|
|
1438
|
+
if (!noAssert) {
|
|
1439
|
+
var maxBytes = Math.pow(2, 8 * byteLength) - 1
|
|
1440
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0)
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
var i = byteLength - 1
|
|
1444
|
+
var mul = 1
|
|
1445
|
+
this[offset + i] = value & 0xFF
|
|
1446
|
+
while (--i >= 0 && (mul *= 0x100)) {
|
|
1447
|
+
this[offset + i] = (value / mul) & 0xFF
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
return offset + byteLength
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
Buffer.prototype.writeUint8 =
|
|
1454
|
+
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
|
|
1455
|
+
value = +value
|
|
1456
|
+
offset = offset >>> 0
|
|
1457
|
+
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
|
|
1458
|
+
this[offset] = (value & 0xff)
|
|
1459
|
+
return offset + 1
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
Buffer.prototype.writeUint16LE =
|
|
1463
|
+
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
|
|
1464
|
+
value = +value
|
|
1465
|
+
offset = offset >>> 0
|
|
1466
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
|
|
1467
|
+
this[offset] = (value & 0xff)
|
|
1468
|
+
this[offset + 1] = (value >>> 8)
|
|
1469
|
+
return offset + 2
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
Buffer.prototype.writeUint16BE =
|
|
1473
|
+
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
|
|
1474
|
+
value = +value
|
|
1475
|
+
offset = offset >>> 0
|
|
1476
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
|
|
1477
|
+
this[offset] = (value >>> 8)
|
|
1478
|
+
this[offset + 1] = (value & 0xff)
|
|
1479
|
+
return offset + 2
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
Buffer.prototype.writeUint32LE =
|
|
1483
|
+
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
|
|
1484
|
+
value = +value
|
|
1485
|
+
offset = offset >>> 0
|
|
1486
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
|
|
1487
|
+
this[offset + 3] = (value >>> 24)
|
|
1488
|
+
this[offset + 2] = (value >>> 16)
|
|
1489
|
+
this[offset + 1] = (value >>> 8)
|
|
1490
|
+
this[offset] = (value & 0xff)
|
|
1491
|
+
return offset + 4
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
Buffer.prototype.writeUint32BE =
|
|
1495
|
+
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
|
|
1496
|
+
value = +value
|
|
1497
|
+
offset = offset >>> 0
|
|
1498
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
|
|
1499
|
+
this[offset] = (value >>> 24)
|
|
1500
|
+
this[offset + 1] = (value >>> 16)
|
|
1501
|
+
this[offset + 2] = (value >>> 8)
|
|
1502
|
+
this[offset + 3] = (value & 0xff)
|
|
1503
|
+
return offset + 4
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
|
|
1507
|
+
value = +value
|
|
1508
|
+
offset = offset >>> 0
|
|
1509
|
+
if (!noAssert) {
|
|
1510
|
+
var limit = Math.pow(2, (8 * byteLength) - 1)
|
|
1511
|
+
|
|
1512
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit)
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
var i = 0
|
|
1516
|
+
var mul = 1
|
|
1517
|
+
var sub = 0
|
|
1518
|
+
this[offset] = value & 0xFF
|
|
1519
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
1520
|
+
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
1521
|
+
sub = 1
|
|
1522
|
+
}
|
|
1523
|
+
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
return offset + byteLength
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
|
|
1530
|
+
value = +value
|
|
1531
|
+
offset = offset >>> 0
|
|
1532
|
+
if (!noAssert) {
|
|
1533
|
+
var limit = Math.pow(2, (8 * byteLength) - 1)
|
|
1534
|
+
|
|
1535
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit)
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
var i = byteLength - 1
|
|
1539
|
+
var mul = 1
|
|
1540
|
+
var sub = 0
|
|
1541
|
+
this[offset + i] = value & 0xFF
|
|
1542
|
+
while (--i >= 0 && (mul *= 0x100)) {
|
|
1543
|
+
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
1544
|
+
sub = 1
|
|
1545
|
+
}
|
|
1546
|
+
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
return offset + byteLength
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
|
|
1553
|
+
value = +value
|
|
1554
|
+
offset = offset >>> 0
|
|
1555
|
+
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
|
|
1556
|
+
if (value < 0) value = 0xff + value + 1
|
|
1557
|
+
this[offset] = (value & 0xff)
|
|
1558
|
+
return offset + 1
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
|
|
1562
|
+
value = +value
|
|
1563
|
+
offset = offset >>> 0
|
|
1564
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
|
|
1565
|
+
this[offset] = (value & 0xff)
|
|
1566
|
+
this[offset + 1] = (value >>> 8)
|
|
1567
|
+
return offset + 2
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
|
|
1571
|
+
value = +value
|
|
1572
|
+
offset = offset >>> 0
|
|
1573
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
|
|
1574
|
+
this[offset] = (value >>> 8)
|
|
1575
|
+
this[offset + 1] = (value & 0xff)
|
|
1576
|
+
return offset + 2
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
|
|
1580
|
+
value = +value
|
|
1581
|
+
offset = offset >>> 0
|
|
1582
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
|
|
1583
|
+
this[offset] = (value & 0xff)
|
|
1584
|
+
this[offset + 1] = (value >>> 8)
|
|
1585
|
+
this[offset + 2] = (value >>> 16)
|
|
1586
|
+
this[offset + 3] = (value >>> 24)
|
|
1587
|
+
return offset + 4
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
|
|
1591
|
+
value = +value
|
|
1592
|
+
offset = offset >>> 0
|
|
1593
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
|
|
1594
|
+
if (value < 0) value = 0xffffffff + value + 1
|
|
1595
|
+
this[offset] = (value >>> 24)
|
|
1596
|
+
this[offset + 1] = (value >>> 16)
|
|
1597
|
+
this[offset + 2] = (value >>> 8)
|
|
1598
|
+
this[offset + 3] = (value & 0xff)
|
|
1599
|
+
return offset + 4
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
function checkIEEE754 (buf, value, offset, ext, max, min) {
|
|
1603
|
+
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
1604
|
+
if (offset < 0) throw new RangeError('Index out of range')
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
function writeFloat (buf, value, offset, littleEndian, noAssert) {
|
|
1608
|
+
value = +value
|
|
1609
|
+
offset = offset >>> 0
|
|
1610
|
+
if (!noAssert) {
|
|
1611
|
+
checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
|
|
1612
|
+
}
|
|
1613
|
+
ieee754.write(buf, value, offset, littleEndian, 23, 4)
|
|
1614
|
+
return offset + 4
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
|
|
1618
|
+
return writeFloat(this, value, offset, true, noAssert)
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
|
|
1622
|
+
return writeFloat(this, value, offset, false, noAssert)
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
function writeDouble (buf, value, offset, littleEndian, noAssert) {
|
|
1626
|
+
value = +value
|
|
1627
|
+
offset = offset >>> 0
|
|
1628
|
+
if (!noAssert) {
|
|
1629
|
+
checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
|
|
1630
|
+
}
|
|
1631
|
+
ieee754.write(buf, value, offset, littleEndian, 52, 8)
|
|
1632
|
+
return offset + 8
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
|
|
1636
|
+
return writeDouble(this, value, offset, true, noAssert)
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
|
|
1640
|
+
return writeDouble(this, value, offset, false, noAssert)
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
|
1644
|
+
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
|
|
1645
|
+
if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
|
|
1646
|
+
if (!start) start = 0
|
|
1647
|
+
if (!end && end !== 0) end = this.length
|
|
1648
|
+
if (targetStart >= target.length) targetStart = target.length
|
|
1649
|
+
if (!targetStart) targetStart = 0
|
|
1650
|
+
if (end > 0 && end < start) end = start
|
|
1651
|
+
|
|
1652
|
+
// Copy 0 bytes; we're done
|
|
1653
|
+
if (end === start) return 0
|
|
1654
|
+
if (target.length === 0 || this.length === 0) return 0
|
|
1655
|
+
|
|
1656
|
+
// Fatal error conditions
|
|
1657
|
+
if (targetStart < 0) {
|
|
1658
|
+
throw new RangeError('targetStart out of bounds')
|
|
1659
|
+
}
|
|
1660
|
+
if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
|
|
1661
|
+
if (end < 0) throw new RangeError('sourceEnd out of bounds')
|
|
1662
|
+
|
|
1663
|
+
// Are we oob?
|
|
1664
|
+
if (end > this.length) end = this.length
|
|
1665
|
+
if (target.length - targetStart < end - start) {
|
|
1666
|
+
end = target.length - targetStart + start
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
var len = end - start
|
|
1670
|
+
|
|
1671
|
+
if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
|
|
1672
|
+
// Use built-in when available, missing from IE11
|
|
1673
|
+
this.copyWithin(targetStart, start, end)
|
|
1674
|
+
} else {
|
|
1675
|
+
Uint8Array.prototype.set.call(
|
|
1676
|
+
target,
|
|
1677
|
+
this.subarray(start, end),
|
|
1678
|
+
targetStart
|
|
1679
|
+
)
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
return len
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
// Usage:
|
|
1686
|
+
// buffer.fill(number[, offset[, end]])
|
|
1687
|
+
// buffer.fill(buffer[, offset[, end]])
|
|
1688
|
+
// buffer.fill(string[, offset[, end]][, encoding])
|
|
1689
|
+
Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
|
1690
|
+
// Handle string cases:
|
|
1691
|
+
if (typeof val === 'string') {
|
|
1692
|
+
if (typeof start === 'string') {
|
|
1693
|
+
encoding = start
|
|
1694
|
+
start = 0
|
|
1695
|
+
end = this.length
|
|
1696
|
+
} else if (typeof end === 'string') {
|
|
1697
|
+
encoding = end
|
|
1698
|
+
end = this.length
|
|
1699
|
+
}
|
|
1700
|
+
if (encoding !== undefined && typeof encoding !== 'string') {
|
|
1701
|
+
throw new TypeError('encoding must be a string')
|
|
1702
|
+
}
|
|
1703
|
+
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
|
1704
|
+
throw new TypeError('Unknown encoding: ' + encoding)
|
|
1705
|
+
}
|
|
1706
|
+
if (val.length === 1) {
|
|
1707
|
+
var code = val.charCodeAt(0)
|
|
1708
|
+
if ((encoding === 'utf8' && code < 128) ||
|
|
1709
|
+
encoding === 'latin1') {
|
|
1710
|
+
// Fast path: If `val` fits into a single byte, use that numeric value.
|
|
1711
|
+
val = code
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
} else if (typeof val === 'number') {
|
|
1715
|
+
val = val & 255
|
|
1716
|
+
} else if (typeof val === 'boolean') {
|
|
1717
|
+
val = Number(val)
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
// Invalid ranges are not set to a default, so can range check early.
|
|
1721
|
+
if (start < 0 || this.length < start || this.length < end) {
|
|
1722
|
+
throw new RangeError('Out of range index')
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
if (end <= start) {
|
|
1726
|
+
return this
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
start = start >>> 0
|
|
1730
|
+
end = end === undefined ? this.length : end >>> 0
|
|
1731
|
+
|
|
1732
|
+
if (!val) val = 0
|
|
1733
|
+
|
|
1734
|
+
var i
|
|
1735
|
+
if (typeof val === 'number') {
|
|
1736
|
+
for (i = start; i < end; ++i) {
|
|
1737
|
+
this[i] = val
|
|
1738
|
+
}
|
|
1739
|
+
} else {
|
|
1740
|
+
var bytes = Buffer.isBuffer(val)
|
|
1741
|
+
? val
|
|
1742
|
+
: Buffer.from(val, encoding)
|
|
1743
|
+
var len = bytes.length
|
|
1744
|
+
if (len === 0) {
|
|
1745
|
+
throw new TypeError('The value "' + val +
|
|
1746
|
+
'" is invalid for argument "value"')
|
|
1747
|
+
}
|
|
1748
|
+
for (i = 0; i < end - start; ++i) {
|
|
1749
|
+
this[i + start] = bytes[i % len]
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
return this
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
// HELPER FUNCTIONS
|
|
1757
|
+
// ================
|
|
1758
|
+
|
|
1759
|
+
var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
|
|
1760
|
+
|
|
1761
|
+
function base64clean (str) {
|
|
1762
|
+
// Node takes equal signs as end of the Base64 encoding
|
|
1763
|
+
str = str.split('=')[0]
|
|
1764
|
+
// Node strips out invalid characters like \n and \t from the string, base64-js does not
|
|
1765
|
+
str = str.trim().replace(INVALID_BASE64_RE, '')
|
|
1766
|
+
// Node converts strings with length < 2 to ''
|
|
1767
|
+
if (str.length < 2) return ''
|
|
1768
|
+
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
|
|
1769
|
+
while (str.length % 4 !== 0) {
|
|
1770
|
+
str = str + '='
|
|
1771
|
+
}
|
|
1772
|
+
return str
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
function utf8ToBytes (string, units) {
|
|
1776
|
+
units = units || Infinity
|
|
1777
|
+
var codePoint
|
|
1778
|
+
var length = string.length
|
|
1779
|
+
var leadSurrogate = null
|
|
1780
|
+
var bytes = []
|
|
1781
|
+
|
|
1782
|
+
for (var i = 0; i < length; ++i) {
|
|
1783
|
+
codePoint = string.charCodeAt(i)
|
|
1784
|
+
|
|
1785
|
+
// is surrogate component
|
|
1786
|
+
if (codePoint > 0xD7FF && codePoint < 0xE000) {
|
|
1787
|
+
// last char was a lead
|
|
1788
|
+
if (!leadSurrogate) {
|
|
1789
|
+
// no lead yet
|
|
1790
|
+
if (codePoint > 0xDBFF) {
|
|
1791
|
+
// unexpected trail
|
|
1792
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
|
1793
|
+
continue
|
|
1794
|
+
} else if (i + 1 === length) {
|
|
1795
|
+
// unpaired lead
|
|
1796
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
|
1797
|
+
continue
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
// valid lead
|
|
1801
|
+
leadSurrogate = codePoint
|
|
1802
|
+
|
|
1803
|
+
continue
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
// 2 leads in a row
|
|
1807
|
+
if (codePoint < 0xDC00) {
|
|
1808
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
|
1809
|
+
leadSurrogate = codePoint
|
|
1810
|
+
continue
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
// valid surrogate pair
|
|
1814
|
+
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
|
|
1815
|
+
} else if (leadSurrogate) {
|
|
1816
|
+
// valid bmp char, but last char was a lead
|
|
1817
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
leadSurrogate = null
|
|
1821
|
+
|
|
1822
|
+
// encode utf8
|
|
1823
|
+
if (codePoint < 0x80) {
|
|
1824
|
+
if ((units -= 1) < 0) break
|
|
1825
|
+
bytes.push(codePoint)
|
|
1826
|
+
} else if (codePoint < 0x800) {
|
|
1827
|
+
if ((units -= 2) < 0) break
|
|
1828
|
+
bytes.push(
|
|
1829
|
+
codePoint >> 0x6 | 0xC0,
|
|
1830
|
+
codePoint & 0x3F | 0x80
|
|
1831
|
+
)
|
|
1832
|
+
} else if (codePoint < 0x10000) {
|
|
1833
|
+
if ((units -= 3) < 0) break
|
|
1834
|
+
bytes.push(
|
|
1835
|
+
codePoint >> 0xC | 0xE0,
|
|
1836
|
+
codePoint >> 0x6 & 0x3F | 0x80,
|
|
1837
|
+
codePoint & 0x3F | 0x80
|
|
1838
|
+
)
|
|
1839
|
+
} else if (codePoint < 0x110000) {
|
|
1840
|
+
if ((units -= 4) < 0) break
|
|
1841
|
+
bytes.push(
|
|
1842
|
+
codePoint >> 0x12 | 0xF0,
|
|
1843
|
+
codePoint >> 0xC & 0x3F | 0x80,
|
|
1844
|
+
codePoint >> 0x6 & 0x3F | 0x80,
|
|
1845
|
+
codePoint & 0x3F | 0x80
|
|
1846
|
+
)
|
|
1847
|
+
} else {
|
|
1848
|
+
throw new Error('Invalid code point')
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
return bytes
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
function asciiToBytes (str) {
|
|
1856
|
+
var byteArray = []
|
|
1857
|
+
for (var i = 0; i < str.length; ++i) {
|
|
1858
|
+
// Node's code seems to be doing this and not & 0x7F..
|
|
1859
|
+
byteArray.push(str.charCodeAt(i) & 0xFF)
|
|
1860
|
+
}
|
|
1861
|
+
return byteArray
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
function utf16leToBytes (str, units) {
|
|
1865
|
+
var c, hi, lo
|
|
1866
|
+
var byteArray = []
|
|
1867
|
+
for (var i = 0; i < str.length; ++i) {
|
|
1868
|
+
if ((units -= 2) < 0) break
|
|
1869
|
+
|
|
1870
|
+
c = str.charCodeAt(i)
|
|
1871
|
+
hi = c >> 8
|
|
1872
|
+
lo = c % 256
|
|
1873
|
+
byteArray.push(lo)
|
|
1874
|
+
byteArray.push(hi)
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
return byteArray
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
function base64ToBytes (str) {
|
|
1881
|
+
return base64.toByteArray(base64clean(str))
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
function blitBuffer (src, dst, offset, length) {
|
|
1885
|
+
for (var i = 0; i < length; ++i) {
|
|
1886
|
+
if ((i + offset >= dst.length) || (i >= src.length)) break
|
|
1887
|
+
dst[i + offset] = src[i]
|
|
1888
|
+
}
|
|
1889
|
+
return i
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
|
|
1893
|
+
// the `instanceof` check but they should be treated as of that type.
|
|
1894
|
+
// See: https://github.com/feross/buffer/issues/166
|
|
1895
|
+
function isInstance (obj, type) {
|
|
1896
|
+
return obj instanceof type ||
|
|
1897
|
+
(obj != null && obj.constructor != null && obj.constructor.name != null &&
|
|
1898
|
+
obj.constructor.name === type.name)
|
|
1899
|
+
}
|
|
1900
|
+
function numberIsNaN (obj) {
|
|
1901
|
+
// For IE11 support
|
|
1902
|
+
return obj !== obj // eslint-disable-line no-self-compare
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
// Create lookup table for `toString('hex')`
|
|
1906
|
+
// See: https://github.com/feross/buffer/issues/219
|
|
1907
|
+
var hexSliceLookupTable = (function () {
|
|
1908
|
+
var alphabet = '0123456789abcdef'
|
|
1909
|
+
var table = new Array(256)
|
|
1910
|
+
for (var i = 0; i < 16; ++i) {
|
|
1911
|
+
var i16 = i * 16
|
|
1912
|
+
for (var j = 0; j < 16; ++j) {
|
|
1913
|
+
table[i16 + j] = alphabet[i] + alphabet[j]
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
return table
|
|
1917
|
+
})()
|
|
1918
|
+
|
|
1919
|
+
|
|
1920
|
+
/***/ }),
|
|
1921
|
+
|
|
1922
|
+
/***/ 526:
|
|
1923
|
+
/***/ ((__unused_webpack_module, exports) => {
|
|
1924
|
+
|
|
1925
|
+
"use strict";
|
|
1926
|
+
|
|
1927
|
+
|
|
1928
|
+
exports.byteLength = byteLength
|
|
1929
|
+
exports.toByteArray = toByteArray
|
|
1930
|
+
exports.fromByteArray = fromByteArray
|
|
1931
|
+
|
|
1932
|
+
var lookup = []
|
|
1933
|
+
var revLookup = []
|
|
1934
|
+
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
|
|
1935
|
+
|
|
1936
|
+
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
|
1937
|
+
for (var i = 0, len = code.length; i < len; ++i) {
|
|
1938
|
+
lookup[i] = code[i]
|
|
1939
|
+
revLookup[code.charCodeAt(i)] = i
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
// Support decoding URL-safe base64 strings, as Node.js does.
|
|
1943
|
+
// See: https://en.wikipedia.org/wiki/Base64#URL_applications
|
|
1944
|
+
revLookup['-'.charCodeAt(0)] = 62
|
|
1945
|
+
revLookup['_'.charCodeAt(0)] = 63
|
|
1946
|
+
|
|
1947
|
+
function getLens (b64) {
|
|
1948
|
+
var len = b64.length
|
|
1949
|
+
|
|
1950
|
+
if (len % 4 > 0) {
|
|
1951
|
+
throw new Error('Invalid string. Length must be a multiple of 4')
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1954
|
+
// Trim off extra bytes after placeholder bytes are found
|
|
1955
|
+
// See: https://github.com/beatgammit/base64-js/issues/42
|
|
1956
|
+
var validLen = b64.indexOf('=')
|
|
1957
|
+
if (validLen === -1) validLen = len
|
|
1958
|
+
|
|
1959
|
+
var placeHoldersLen = validLen === len
|
|
1960
|
+
? 0
|
|
1961
|
+
: 4 - (validLen % 4)
|
|
1962
|
+
|
|
1963
|
+
return [validLen, placeHoldersLen]
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
// base64 is 4/3 + up to two characters of the original data
|
|
1967
|
+
function byteLength (b64) {
|
|
1968
|
+
var lens = getLens(b64)
|
|
1969
|
+
var validLen = lens[0]
|
|
1970
|
+
var placeHoldersLen = lens[1]
|
|
1971
|
+
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
function _byteLength (b64, validLen, placeHoldersLen) {
|
|
1975
|
+
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
function toByteArray (b64) {
|
|
1979
|
+
var tmp
|
|
1980
|
+
var lens = getLens(b64)
|
|
1981
|
+
var validLen = lens[0]
|
|
1982
|
+
var placeHoldersLen = lens[1]
|
|
1983
|
+
|
|
1984
|
+
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
|
|
1985
|
+
|
|
1986
|
+
var curByte = 0
|
|
1987
|
+
|
|
1988
|
+
// if there are placeholders, only get up to the last complete 4 chars
|
|
1989
|
+
var len = placeHoldersLen > 0
|
|
1990
|
+
? validLen - 4
|
|
1991
|
+
: validLen
|
|
1992
|
+
|
|
1993
|
+
var i
|
|
1994
|
+
for (i = 0; i < len; i += 4) {
|
|
1995
|
+
tmp =
|
|
1996
|
+
(revLookup[b64.charCodeAt(i)] << 18) |
|
|
1997
|
+
(revLookup[b64.charCodeAt(i + 1)] << 12) |
|
|
1998
|
+
(revLookup[b64.charCodeAt(i + 2)] << 6) |
|
|
1999
|
+
revLookup[b64.charCodeAt(i + 3)]
|
|
2000
|
+
arr[curByte++] = (tmp >> 16) & 0xFF
|
|
2001
|
+
arr[curByte++] = (tmp >> 8) & 0xFF
|
|
2002
|
+
arr[curByte++] = tmp & 0xFF
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
if (placeHoldersLen === 2) {
|
|
2006
|
+
tmp =
|
|
2007
|
+
(revLookup[b64.charCodeAt(i)] << 2) |
|
|
2008
|
+
(revLookup[b64.charCodeAt(i + 1)] >> 4)
|
|
2009
|
+
arr[curByte++] = tmp & 0xFF
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
if (placeHoldersLen === 1) {
|
|
2013
|
+
tmp =
|
|
2014
|
+
(revLookup[b64.charCodeAt(i)] << 10) |
|
|
2015
|
+
(revLookup[b64.charCodeAt(i + 1)] << 4) |
|
|
2016
|
+
(revLookup[b64.charCodeAt(i + 2)] >> 2)
|
|
2017
|
+
arr[curByte++] = (tmp >> 8) & 0xFF
|
|
2018
|
+
arr[curByte++] = tmp & 0xFF
|
|
2019
|
+
}
|
|
2020
|
+
|
|
2021
|
+
return arr
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
function tripletToBase64 (num) {
|
|
2025
|
+
return lookup[num >> 18 & 0x3F] +
|
|
2026
|
+
lookup[num >> 12 & 0x3F] +
|
|
2027
|
+
lookup[num >> 6 & 0x3F] +
|
|
2028
|
+
lookup[num & 0x3F]
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
function encodeChunk (uint8, start, end) {
|
|
2032
|
+
var tmp
|
|
2033
|
+
var output = []
|
|
2034
|
+
for (var i = start; i < end; i += 3) {
|
|
2035
|
+
tmp =
|
|
2036
|
+
((uint8[i] << 16) & 0xFF0000) +
|
|
2037
|
+
((uint8[i + 1] << 8) & 0xFF00) +
|
|
2038
|
+
(uint8[i + 2] & 0xFF)
|
|
2039
|
+
output.push(tripletToBase64(tmp))
|
|
2040
|
+
}
|
|
2041
|
+
return output.join('')
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
function fromByteArray (uint8) {
|
|
2045
|
+
var tmp
|
|
2046
|
+
var len = uint8.length
|
|
2047
|
+
var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
|
|
2048
|
+
var parts = []
|
|
2049
|
+
var maxChunkLength = 16383 // must be multiple of 3
|
|
2050
|
+
|
|
2051
|
+
// go through the array every three bytes, we'll deal with trailing stuff later
|
|
2052
|
+
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
|
2053
|
+
parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
|
|
2054
|
+
}
|
|
2055
|
+
|
|
2056
|
+
// pad the end with zeros, but make sure to not forget the extra bytes
|
|
2057
|
+
if (extraBytes === 1) {
|
|
2058
|
+
tmp = uint8[len - 1]
|
|
2059
|
+
parts.push(
|
|
2060
|
+
lookup[tmp >> 2] +
|
|
2061
|
+
lookup[(tmp << 4) & 0x3F] +
|
|
2062
|
+
'=='
|
|
2063
|
+
)
|
|
2064
|
+
} else if (extraBytes === 2) {
|
|
2065
|
+
tmp = (uint8[len - 2] << 8) + uint8[len - 1]
|
|
2066
|
+
parts.push(
|
|
2067
|
+
lookup[tmp >> 10] +
|
|
2068
|
+
lookup[(tmp >> 4) & 0x3F] +
|
|
2069
|
+
lookup[(tmp << 2) & 0x3F] +
|
|
2070
|
+
'='
|
|
2071
|
+
)
|
|
2072
|
+
}
|
|
2073
|
+
|
|
2074
|
+
return parts.join('')
|
|
2075
|
+
}
|
|
2076
|
+
|
|
2077
|
+
|
|
2078
|
+
/***/ })
|
|
2079
|
+
|
|
2080
|
+
/******/ });
|
|
2081
|
+
/************************************************************************/
|
|
2082
|
+
/******/ // The module cache
|
|
2083
|
+
/******/ var __webpack_module_cache__ = {};
|
|
2084
|
+
/******/
|
|
2085
|
+
/******/ // The require function
|
|
2086
|
+
/******/ function __webpack_require__(moduleId) {
|
|
2087
|
+
/******/ // Check if module is in cache
|
|
2088
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
2089
|
+
/******/ if (cachedModule !== undefined) {
|
|
2090
|
+
/******/ return cachedModule.exports;
|
|
2091
|
+
/******/ }
|
|
2092
|
+
/******/ // Create a new module (and put it into the cache)
|
|
2093
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
2094
|
+
/******/ // no module.id needed
|
|
2095
|
+
/******/ // no module.loaded needed
|
|
2096
|
+
/******/ exports: {}
|
|
2097
|
+
/******/ };
|
|
2098
|
+
/******/
|
|
2099
|
+
/******/ // Execute the module function
|
|
2100
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
2101
|
+
/******/
|
|
2102
|
+
/******/ // Return the exports of the module
|
|
2103
|
+
/******/ return module.exports;
|
|
2104
|
+
/******/ }
|
|
2105
|
+
/******/
|
|
2106
|
+
/************************************************************************/
|
|
2107
|
+
/******/ /* webpack/runtime/define property getters */
|
|
2108
|
+
/******/ (() => {
|
|
2109
|
+
/******/ // define getter functions for harmony exports
|
|
2110
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
2111
|
+
/******/ for(var key in definition) {
|
|
2112
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
2113
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
2114
|
+
/******/ }
|
|
2115
|
+
/******/ }
|
|
2116
|
+
/******/ };
|
|
2117
|
+
/******/ })();
|
|
2118
|
+
/******/
|
|
2119
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
2120
|
+
/******/ (() => {
|
|
2121
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
2122
|
+
/******/ })();
|
|
2123
|
+
/******/
|
|
2124
|
+
/************************************************************************/
|
|
2125
|
+
var __webpack_exports__ = {};
|
|
2126
|
+
// This entry needs to be wrapped in an IIFE because it needs to be in strict mode.
|
|
2127
|
+
(() => {
|
|
2128
|
+
"use strict";
|
|
2129
|
+
|
|
2130
|
+
// EXPORTS
|
|
2131
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
2132
|
+
TinyDragger: () => (/* reexport */ libs_TinyDragger)
|
|
2133
|
+
});
|
|
2134
|
+
|
|
2135
|
+
// EXTERNAL MODULE: ./node_modules/buffer/index.js
|
|
2136
|
+
var buffer = __webpack_require__(287);
|
|
2137
|
+
;// ./src/v1/basics/objFilter.mjs
|
|
2138
|
+
|
|
2139
|
+
|
|
2140
|
+
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
2141
|
+
|
|
2142
|
+
/**
|
|
2143
|
+
* An object containing type validation functions and their evaluation order.
|
|
2144
|
+
*
|
|
2145
|
+
* Each item in `typeValidator.items` is a function that receives any value
|
|
2146
|
+
* and returns a boolean indicating whether the value matches the corresponding type.
|
|
2147
|
+
*
|
|
2148
|
+
* The `order` array defines the priority in which types should be checked,
|
|
2149
|
+
* which can be useful for functions that infer types in a consistent manner.
|
|
2150
|
+
*
|
|
2151
|
+
*/
|
|
2152
|
+
const typeValidator = {
|
|
2153
|
+
items: {},
|
|
2154
|
+
/**
|
|
2155
|
+
* Evaluation order of the type checkers.
|
|
2156
|
+
* @type {string[]}
|
|
2157
|
+
* */
|
|
2158
|
+
order: [],
|
|
2159
|
+
};
|
|
2160
|
+
|
|
2161
|
+
/** @typedef {Object.<string, (val: any) => *>} ExtendObjType */
|
|
2162
|
+
/** @typedef {Array<[string, (val: any) => *]>} ExtendObjTypeArray */
|
|
2163
|
+
|
|
2164
|
+
/**
|
|
2165
|
+
* Adds new type checkers to the typeValidator without overwriting existing ones.
|
|
2166
|
+
*
|
|
2167
|
+
* Accepts either an object with named functions or an array of [key, fn] arrays.
|
|
2168
|
+
* If no index is provided, the type is inserted just before 'object' (if it exists), or at the end.
|
|
2169
|
+
*
|
|
2170
|
+
* @param {ExtendObjType|ExtendObjTypeArray} newItems
|
|
2171
|
+
* - New type validators to be added.
|
|
2172
|
+
* @param {number} [index] - Optional. Position at which to insert each new type. Ignored if the type already exists.
|
|
2173
|
+
* @returns {string[]} - A list of successfully added type names.
|
|
2174
|
+
*
|
|
2175
|
+
* @example
|
|
2176
|
+
* extendObjType({
|
|
2177
|
+
* htmlElement2: val => typeof HTMLElement !== 'undefined' && val instanceof HTMLElement
|
|
2178
|
+
* });
|
|
2179
|
+
*
|
|
2180
|
+
* @example
|
|
2181
|
+
* extendObjType([
|
|
2182
|
+
* ['alpha', val => typeof val === 'string'],
|
|
2183
|
+
* ['beta', val => Array.isArray(val)]
|
|
2184
|
+
* ]);
|
|
2185
|
+
*/
|
|
2186
|
+
function extendObjType(newItems, index) {
|
|
2187
|
+
const added = [];
|
|
2188
|
+
|
|
2189
|
+
const entries = Array.isArray(newItems) ? newItems : Object.entries(newItems);
|
|
2190
|
+
for (const [key, fn] of entries) {
|
|
2191
|
+
if (!typeValidator.items.hasOwnProperty(key)) {
|
|
2192
|
+
// @ts-ignore
|
|
2193
|
+
typeValidator.items[key] = fn;
|
|
2194
|
+
|
|
2195
|
+
let insertAt = typeof index === 'number' ? index : -1; // Default to -1 if index isn't provided
|
|
2196
|
+
|
|
2197
|
+
// Default to before 'object', or to the end
|
|
2198
|
+
if (insertAt === -1) {
|
|
2199
|
+
const objectIndex = typeValidator.order.indexOf('object');
|
|
2200
|
+
insertAt = objectIndex > -1 ? objectIndex : typeValidator.order.length;
|
|
2201
|
+
}
|
|
2202
|
+
|
|
2203
|
+
// Ensure insertAt is a valid number and not out of bounds
|
|
2204
|
+
insertAt = Math.min(Math.max(0, insertAt), typeValidator.order.length);
|
|
2205
|
+
|
|
2206
|
+
typeValidator.order.splice(insertAt, 0, key);
|
|
2207
|
+
added.push(key);
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2210
|
+
|
|
2211
|
+
return added;
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2214
|
+
/**
|
|
2215
|
+
* Reorders the typeValidator.order array according to a custom new order.
|
|
2216
|
+
* All values in the new order must already exist in the current order.
|
|
2217
|
+
* The function does not mutate the original array structure directly.
|
|
2218
|
+
*
|
|
2219
|
+
* @param {string[]} newOrder - The new order of type names.
|
|
2220
|
+
* @returns {boolean} - Returns true if the reorder was successful, false if invalid keys were found.
|
|
2221
|
+
*
|
|
2222
|
+
* @example
|
|
2223
|
+
* reorderObjTypeOrder([
|
|
2224
|
+
* 'string', 'number', 'array', 'object'
|
|
2225
|
+
* ]);
|
|
2226
|
+
*/
|
|
2227
|
+
function reorderObjTypeOrder(newOrder) {
|
|
2228
|
+
const currentOrder = [...typeValidator.order]; // shallow clone
|
|
2229
|
+
|
|
2230
|
+
// All keys in newOrder must exist in currentOrder
|
|
2231
|
+
const isValid = newOrder.every((type) => currentOrder.includes(type));
|
|
2232
|
+
|
|
2233
|
+
if (!isValid) return false;
|
|
2234
|
+
|
|
2235
|
+
// Reassign only if valid
|
|
2236
|
+
typeValidator.order = newOrder.slice(); // assign shallow copy
|
|
2237
|
+
return true;
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
/**
|
|
2241
|
+
* Returns a cloned version of the `typeValidator.order` array.
|
|
2242
|
+
* The cloned array will not be affected by future changes to the original `order`.
|
|
2243
|
+
*
|
|
2244
|
+
* @returns {string[]} - A new array with the same values as `typeValidator.order`.
|
|
2245
|
+
*/
|
|
2246
|
+
function cloneObjTypeOrder() {
|
|
2247
|
+
return [...typeValidator.order]; // Creates a shallow copy of the array
|
|
2248
|
+
}
|
|
2249
|
+
|
|
2250
|
+
/**
|
|
2251
|
+
* Returns the detected type name of a given value based on predefined type validators.
|
|
2252
|
+
*
|
|
2253
|
+
* This function uses `getType` with a predefined `typeValidator` to determine or compare types safely.
|
|
2254
|
+
* in the specified `typeValidator.order`. The first matching type is returned.
|
|
2255
|
+
*
|
|
2256
|
+
* If `val` is `null`, it immediately returns `'null'`.
|
|
2257
|
+
* If no match is found, it returns `'unknown'`.
|
|
2258
|
+
*
|
|
2259
|
+
* @param {any} val - The value whose type should be determined.
|
|
2260
|
+
* @returns {string} - The type name of the value (e.g., "array", "date", "map"), or "unknown" if no match is found.
|
|
2261
|
+
*
|
|
2262
|
+
* @example
|
|
2263
|
+
* getType([]); // "array"
|
|
2264
|
+
* getType(null); // "null"
|
|
2265
|
+
* getType(new Set()); // "set"
|
|
2266
|
+
* getType(() => {}); // "unknown"
|
|
2267
|
+
*/
|
|
2268
|
+
const getType = (val) => {
|
|
2269
|
+
if (val === null) return 'null';
|
|
2270
|
+
// @ts-ignore
|
|
2271
|
+
for (const name of typeValidator.order) {
|
|
2272
|
+
// @ts-ignore
|
|
2273
|
+
if (typeof typeValidator.items[name] !== 'function' || typeValidator.items[name](val))
|
|
2274
|
+
return name;
|
|
2275
|
+
}
|
|
2276
|
+
return 'unknown';
|
|
2277
|
+
};
|
|
2278
|
+
|
|
2279
|
+
/**
|
|
2280
|
+
* Checks the type of a given object or returns its type as a string.
|
|
2281
|
+
*
|
|
2282
|
+
* @param {*} obj - The object to check or identify.
|
|
2283
|
+
* @param {string} [type] - Optional. If provided, checks whether the object matches this type (e.g., "object", "array", "string").
|
|
2284
|
+
* @returns {boolean|string|null} - Returns `true` if the type matches, `false` if not,
|
|
2285
|
+
* the type string if no type is provided, or `null` if the object is `undefined`.
|
|
2286
|
+
*
|
|
2287
|
+
* @example
|
|
2288
|
+
* objType([], 'array'); // true
|
|
2289
|
+
* objType({}, 'object'); // true
|
|
2290
|
+
* objType('hello'); // "string"
|
|
2291
|
+
* objType(undefined); // null
|
|
2292
|
+
*/
|
|
2293
|
+
function objType(obj, type) {
|
|
2294
|
+
if (typeof obj === 'undefined') return null;
|
|
2295
|
+
const result = getType(obj);
|
|
2296
|
+
if (typeof type === 'string') return result === type.toLowerCase();
|
|
2297
|
+
return result;
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
/**
|
|
2301
|
+
* Checks the type of a given object and returns the validation value if a known type is detected.
|
|
2302
|
+
*
|
|
2303
|
+
* @param {*} obj - The object to check or identify.
|
|
2304
|
+
* @returns {{ valid:*; type: string | null }} - Returns the type result.
|
|
2305
|
+
*/
|
|
2306
|
+
function checkObj(obj) {
|
|
2307
|
+
/** @type {{ valid:*; type: string | null }} */
|
|
2308
|
+
const data = { valid: null, type: null };
|
|
2309
|
+
for (const name of typeValidator.order) {
|
|
2310
|
+
// @ts-ignore
|
|
2311
|
+
if (typeof typeValidator.items[name] === 'function') {
|
|
2312
|
+
// @ts-ignore
|
|
2313
|
+
const result = typeValidator.items[name](obj);
|
|
2314
|
+
if (result) {
|
|
2315
|
+
data.valid = result;
|
|
2316
|
+
data.type = name;
|
|
2317
|
+
break;
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
return data;
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2324
|
+
/**
|
|
2325
|
+
* Creates a clone of the functions from the `typeValidator` object.
|
|
2326
|
+
* It returns a new object where the keys are the same and the values are the cloned functions.
|
|
2327
|
+
*/
|
|
2328
|
+
function getCheckObj() {
|
|
2329
|
+
return Object.fromEntries(Object.entries(typeValidator.items).map(([key, fn]) => [key, fn]));
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2332
|
+
/**
|
|
2333
|
+
* Counts the number of elements in an array or the number of properties in an object.
|
|
2334
|
+
*
|
|
2335
|
+
* @param {Array<*>|Record<string|number, any>} obj - The array or object to count.
|
|
2336
|
+
* @returns {number} - The count of items (array elements or object keys), or `0` if the input is neither an array nor an object.
|
|
2337
|
+
*
|
|
2338
|
+
* @example
|
|
2339
|
+
* countObj([1, 2, 3]); // 3
|
|
2340
|
+
* countObj({ a: 1, b: 2 }); // 2
|
|
2341
|
+
* countObj('not an object'); // 0
|
|
2342
|
+
*/
|
|
2343
|
+
function countObj(obj) {
|
|
2344
|
+
// Is Array
|
|
2345
|
+
if (Array.isArray(obj)) return obj.length;
|
|
2346
|
+
// Object
|
|
2347
|
+
if (objType(obj, 'object')) return Object.keys(obj).length;
|
|
2348
|
+
// Nothing
|
|
2349
|
+
return 0;
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2352
|
+
/**
|
|
2353
|
+
* Determines whether a given value is a pure JSON object (plain object).
|
|
2354
|
+
*
|
|
2355
|
+
* A pure object satisfies the following:
|
|
2356
|
+
* - It is not null.
|
|
2357
|
+
* - Its type is "object".
|
|
2358
|
+
* - Its internal [[Class]] is "[object Object]".
|
|
2359
|
+
* - It is not an instance of built-in types like Array, Date, Map, Set, etc.
|
|
2360
|
+
*
|
|
2361
|
+
* This function is useful for strict data validation when you want to ensure
|
|
2362
|
+
* a value is a clean JSON-compatible object, free of class instances or special types.
|
|
2363
|
+
*
|
|
2364
|
+
* @param {unknown} value - The value to test.
|
|
2365
|
+
* @returns {value is Record<string | number | symbol, unknown>} Returns true if the value is a pure object.
|
|
2366
|
+
*/
|
|
2367
|
+
function objFilter_isJsonObject(value) {
|
|
2368
|
+
if (value === null || typeof value !== 'object') return false;
|
|
2369
|
+
if (Array.isArray(value)) return false;
|
|
2370
|
+
if (Object.prototype.toString.call(value) !== '[object Object]') return false;
|
|
2371
|
+
return true;
|
|
2372
|
+
}
|
|
2373
|
+
|
|
2374
|
+
// Insert obj types
|
|
2375
|
+
|
|
2376
|
+
extendObjType([
|
|
2377
|
+
[
|
|
2378
|
+
'undefined',
|
|
2379
|
+
/** @param {*} val @returns {val is undefined} */
|
|
2380
|
+
(val) => typeof val === 'undefined',
|
|
2381
|
+
],
|
|
2382
|
+
[
|
|
2383
|
+
'null',
|
|
2384
|
+
/** @param {*} val @returns {val is null} */
|
|
2385
|
+
(val) => val === null,
|
|
2386
|
+
],
|
|
2387
|
+
[
|
|
2388
|
+
'boolean',
|
|
2389
|
+
/** @param {*} val @returns {val is boolean} */
|
|
2390
|
+
(val) => typeof val === 'boolean',
|
|
2391
|
+
],
|
|
2392
|
+
[
|
|
2393
|
+
'number',
|
|
2394
|
+
/** @param {*} val @returns {val is number} */
|
|
2395
|
+
(val) => typeof val === 'number' && !Number.isNaN(val),
|
|
2396
|
+
],
|
|
2397
|
+
[
|
|
2398
|
+
'bigint',
|
|
2399
|
+
/** @param {*} val @returns {val is bigint} */
|
|
2400
|
+
(val) => typeof val === 'bigint',
|
|
2401
|
+
],
|
|
2402
|
+
[
|
|
2403
|
+
'string',
|
|
2404
|
+
/** @param {*} val @returns {val is string} */
|
|
2405
|
+
(val) => typeof val === 'string',
|
|
2406
|
+
],
|
|
2407
|
+
[
|
|
2408
|
+
'symbol',
|
|
2409
|
+
/** @param {*} val @returns {val is symbol} */
|
|
2410
|
+
(val) => typeof val === 'symbol',
|
|
2411
|
+
],
|
|
2412
|
+
[
|
|
2413
|
+
'function',
|
|
2414
|
+
/** @param {*} val @returns {val is Function} */
|
|
2415
|
+
(val) => typeof val === 'function',
|
|
2416
|
+
],
|
|
2417
|
+
[
|
|
2418
|
+
'array',
|
|
2419
|
+
/** @param {*} val @returns {val is any[]} */
|
|
2420
|
+
(val) => Array.isArray(val),
|
|
2421
|
+
],
|
|
2422
|
+
]);
|
|
2423
|
+
|
|
2424
|
+
if (!isBrowser) {
|
|
2425
|
+
extendObjType([
|
|
2426
|
+
[
|
|
2427
|
+
'buffer',
|
|
2428
|
+
/** @param {*} val @returns {val is Buffer} */
|
|
2429
|
+
(val) => typeof buffer/* Buffer */.hp !== 'undefined' && buffer/* Buffer */.hp.isBuffer(val),
|
|
2430
|
+
],
|
|
2431
|
+
]);
|
|
2432
|
+
}
|
|
2433
|
+
|
|
2434
|
+
if (isBrowser) {
|
|
2435
|
+
extendObjType([
|
|
2436
|
+
[
|
|
2437
|
+
'file',
|
|
2438
|
+
/** @param {*} val @returns {val is File} */
|
|
2439
|
+
(val) => typeof File !== 'undefined' && val instanceof File,
|
|
2440
|
+
],
|
|
2441
|
+
]);
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
extendObjType([
|
|
2445
|
+
[
|
|
2446
|
+
'date',
|
|
2447
|
+
/** @param {*} val @returns {val is Date} */
|
|
2448
|
+
(val) => val instanceof Date,
|
|
2449
|
+
],
|
|
2450
|
+
[
|
|
2451
|
+
'regexp',
|
|
2452
|
+
/** @param {*} val @returns {val is RegExp} */
|
|
2453
|
+
(val) => val instanceof RegExp,
|
|
2454
|
+
],
|
|
2455
|
+
[
|
|
2456
|
+
'map',
|
|
2457
|
+
/** @param {*} val @returns {val is Map<unknown, unknown>} */
|
|
2458
|
+
(val) => val instanceof Map,
|
|
2459
|
+
],
|
|
2460
|
+
[
|
|
2461
|
+
'set',
|
|
2462
|
+
/** @param {*} val @returns {val is Set<unknown>} */
|
|
2463
|
+
(val) => val instanceof Set,
|
|
2464
|
+
],
|
|
2465
|
+
[
|
|
2466
|
+
'weakmap',
|
|
2467
|
+
/** @param {*} val @returns {val is WeakMap<unknown, unknown>} */
|
|
2468
|
+
(val) => val instanceof WeakMap,
|
|
2469
|
+
],
|
|
2470
|
+
[
|
|
2471
|
+
'weakset',
|
|
2472
|
+
/** @param {*} val @returns {val is WeakSet<unknown>} */
|
|
2473
|
+
(val) => val instanceof WeakSet,
|
|
2474
|
+
],
|
|
2475
|
+
[
|
|
2476
|
+
'promise',
|
|
2477
|
+
/** @param {*} val @returns {val is Promise<unknown>} */
|
|
2478
|
+
(val) => val instanceof Promise,
|
|
2479
|
+
],
|
|
2480
|
+
]);
|
|
2481
|
+
|
|
2482
|
+
if (isBrowser) {
|
|
2483
|
+
extendObjType([
|
|
2484
|
+
[
|
|
2485
|
+
'htmlelement',
|
|
2486
|
+
/** @param {*} val @returns {val is HTMLElement} */
|
|
2487
|
+
(val) => typeof HTMLElement !== 'undefined' && val instanceof HTMLElement,
|
|
2488
|
+
],
|
|
2489
|
+
]);
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2492
|
+
extendObjType([
|
|
2493
|
+
[
|
|
2494
|
+
'object',
|
|
2495
|
+
/** @param {*} val @returns {val is Record<string | number | symbol, unknown>} */
|
|
2496
|
+
(val) => objFilter_isJsonObject(val),
|
|
2497
|
+
],
|
|
2498
|
+
]);
|
|
2499
|
+
|
|
2500
|
+
;// ./src/v1/basics/html.mjs
|
|
2501
|
+
|
|
2502
|
+
|
|
2503
|
+
/**
|
|
2504
|
+
* Checks if two DOM elements are colliding on the screen.
|
|
2505
|
+
*
|
|
2506
|
+
* @param {Element} elem1 - First DOM element.
|
|
2507
|
+
* @param {Element} elem2 - Second DOM element.
|
|
2508
|
+
* @returns {boolean} - Returns true if the elements are colliding.
|
|
2509
|
+
*/
|
|
2510
|
+
function areHtmlElsColliding(elem1, elem2) {
|
|
2511
|
+
const rect1 = elem1.getBoundingClientRect();
|
|
2512
|
+
const rect2 = elem2.getBoundingClientRect();
|
|
2513
|
+
|
|
2514
|
+
return !(
|
|
2515
|
+
rect1.right < rect2.left ||
|
|
2516
|
+
rect1.left > rect2.right ||
|
|
2517
|
+
rect1.bottom < rect2.top ||
|
|
2518
|
+
rect1.top > rect2.bottom
|
|
2519
|
+
);
|
|
2520
|
+
}
|
|
2521
|
+
|
|
2522
|
+
/**
|
|
2523
|
+
* Reads and parses a JSON data using FileReader.
|
|
2524
|
+
* Throws an error if the content is not valid JSON.
|
|
2525
|
+
* @param {File} file
|
|
2526
|
+
* @returns {Promise<any>}
|
|
2527
|
+
*/
|
|
2528
|
+
function readJsonBlob(file) {
|
|
2529
|
+
return new Promise((resolve, reject) => {
|
|
2530
|
+
const reader = new FileReader();
|
|
2531
|
+
|
|
2532
|
+
reader.onload = () => {
|
|
2533
|
+
try {
|
|
2534
|
+
// @ts-ignore
|
|
2535
|
+
const result = JSON.parse(reader.result);
|
|
2536
|
+
resolve(result);
|
|
2537
|
+
} catch (error) {
|
|
2538
|
+
// @ts-ignore
|
|
2539
|
+
reject(new Error(`Invalid JSON in file: ${file.name}\n${error.message}`));
|
|
2540
|
+
}
|
|
2541
|
+
};
|
|
2542
|
+
|
|
2543
|
+
reader.onerror = () => {
|
|
2544
|
+
reject(new Error(`Error reading file: ${file.name}`));
|
|
2545
|
+
};
|
|
2546
|
+
|
|
2547
|
+
reader.readAsText(file);
|
|
2548
|
+
});
|
|
2549
|
+
}
|
|
2550
|
+
|
|
2551
|
+
/**
|
|
2552
|
+
* Saves a JSON object as a downloadable file.
|
|
2553
|
+
* @param {string} filename
|
|
2554
|
+
* @param {any} data
|
|
2555
|
+
* @param {number} [spaces=2]
|
|
2556
|
+
*/
|
|
2557
|
+
function saveJsonFile(filename, data, spaces = 2) {
|
|
2558
|
+
const json = JSON.stringify(data, null, spaces);
|
|
2559
|
+
const blob = new Blob([json], { type: 'application/json' });
|
|
2560
|
+
const url = URL.createObjectURL(blob);
|
|
2561
|
+
|
|
2562
|
+
const link = document.createElement('a');
|
|
2563
|
+
link.href = url;
|
|
2564
|
+
link.download = filename;
|
|
2565
|
+
|
|
2566
|
+
document.body.appendChild(link);
|
|
2567
|
+
link.click();
|
|
2568
|
+
document.body.removeChild(link);
|
|
2569
|
+
|
|
2570
|
+
URL.revokeObjectURL(url);
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2573
|
+
/**
|
|
2574
|
+
* Loads and parses a JSON from a remote URL using Fetch API.
|
|
2575
|
+
*
|
|
2576
|
+
* @param {string} url - The full URL to fetch JSON from.
|
|
2577
|
+
* @param {Object} [options] - Optional settings.
|
|
2578
|
+
* @param {string} [options.method="GET"] - HTTP method to use (GET, POST, etc.).
|
|
2579
|
+
* @param {any} [options.body] - Request body (only for methods like POST, PUT).
|
|
2580
|
+
* @param {number} [options.timeout=0] - Timeout in milliseconds (ignored if signal is provided).
|
|
2581
|
+
* @param {number} [options.retries=0] - Number of retry attempts (ignored if signal is provided).
|
|
2582
|
+
* @param {Headers|Record<string, *>} [options.headers={}] - Additional headers.
|
|
2583
|
+
* @param {AbortSignal|null} [options.signal] - External AbortSignal; disables timeout and retries.
|
|
2584
|
+
* @returns {Promise<*>} Parsed JSON object.
|
|
2585
|
+
* @throws {Error} Throws if fetch fails, times out, or returns invalid JSON.
|
|
2586
|
+
*/
|
|
2587
|
+
async function fetchJson(
|
|
2588
|
+
url,
|
|
2589
|
+
{ method = 'GET', body, timeout = 0, retries = 0, headers = {}, signal = null } = {},
|
|
2590
|
+
) {
|
|
2591
|
+
if (
|
|
2592
|
+
typeof url !== 'string' ||
|
|
2593
|
+
(!url.startsWith('../') &&
|
|
2594
|
+
!url.startsWith('./') &&
|
|
2595
|
+
!url.startsWith('/') &&
|
|
2596
|
+
!url.startsWith('https://') &&
|
|
2597
|
+
!url.startsWith('http://'))
|
|
2598
|
+
)
|
|
2599
|
+
throw new Error('Invalid URL: must be a valid http or https address.');
|
|
2600
|
+
|
|
2601
|
+
if (typeof method !== 'string' || !method.trim())
|
|
2602
|
+
throw new Error('Invalid method: must be a non-empty string.');
|
|
2603
|
+
|
|
2604
|
+
if (!signal) {
|
|
2605
|
+
if (
|
|
2606
|
+
typeof timeout !== 'number' ||
|
|
2607
|
+
!Number.isFinite(timeout) ||
|
|
2608
|
+
Number.isNaN(timeout) ||
|
|
2609
|
+
timeout < 0
|
|
2610
|
+
)
|
|
2611
|
+
throw new Error('Invalid timeout: must be a positive number.');
|
|
2612
|
+
|
|
2613
|
+
if (
|
|
2614
|
+
typeof retries !== 'number' ||
|
|
2615
|
+
!Number.isFinite(retries) ||
|
|
2616
|
+
Number.isNaN(retries) ||
|
|
2617
|
+
retries < 0
|
|
2618
|
+
)
|
|
2619
|
+
throw new Error('Invalid retries: must be a positive number.');
|
|
2620
|
+
}
|
|
2621
|
+
|
|
2622
|
+
const attempts = signal ? 1 : retries + 1;
|
|
2623
|
+
/** @type {Error|null} */
|
|
2624
|
+
let lastError = null;
|
|
2625
|
+
|
|
2626
|
+
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
2627
|
+
const controller = signal ? null : new AbortController();
|
|
2628
|
+
const localSignal = signal || (controller?.signal ?? null);
|
|
2629
|
+
const timer =
|
|
2630
|
+
!signal && timeout && controller ? setTimeout(() => controller.abort(), timeout) : null;
|
|
2631
|
+
|
|
2632
|
+
try {
|
|
2633
|
+
const response = await fetch(url, {
|
|
2634
|
+
method: method.toUpperCase(),
|
|
2635
|
+
headers: {
|
|
2636
|
+
Accept: 'application/json',
|
|
2637
|
+
...headers,
|
|
2638
|
+
},
|
|
2639
|
+
body: body !== undefined ? (isJsonObject(body) ? JSON.stringify(body) : body) : undefined,
|
|
2640
|
+
signal: localSignal,
|
|
2641
|
+
});
|
|
2642
|
+
|
|
2643
|
+
if (timer) clearTimeout(timer);
|
|
2644
|
+
|
|
2645
|
+
if (!response.ok) throw new Error(`HTTP error: ${response.status} ${response.statusText}`);
|
|
2646
|
+
|
|
2647
|
+
const contentType = response.headers.get('content-type') || '';
|
|
2648
|
+
if (!contentType.includes('application/json'))
|
|
2649
|
+
throw new Error(`Unexpected content-type: ${contentType}`);
|
|
2650
|
+
|
|
2651
|
+
const data = await response.json();
|
|
2652
|
+
|
|
2653
|
+
if (!isJsonObject(data)) throw new Error('Received invalid data instead of valid JSON.');
|
|
2654
|
+
|
|
2655
|
+
return data;
|
|
2656
|
+
} catch (err) {
|
|
2657
|
+
lastError = /** @type {Error} */ (err);
|
|
2658
|
+
if (signal) break; // if an external signal came, it does not retry
|
|
2659
|
+
if (attempt < retries)
|
|
2660
|
+
await new Promise((resolve) => setTimeout(resolve, 300 * (attempt + 1)));
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
throw new Error(
|
|
2665
|
+
`Failed to fetch JSON from "${url}"${lastError ? `: ${lastError.message}` : '.'}`,
|
|
2666
|
+
);
|
|
2667
|
+
}
|
|
2668
|
+
|
|
2669
|
+
/**
|
|
2670
|
+
* @typedef {Object} HtmlElBoxSides
|
|
2671
|
+
* @property {number} x - Total horizontal size (left + right)
|
|
2672
|
+
* @property {number} y - Total vertical size (top + bottom)
|
|
2673
|
+
* @property {number} left
|
|
2674
|
+
* @property {number} right
|
|
2675
|
+
* @property {number} top
|
|
2676
|
+
* @property {number} bottom
|
|
2677
|
+
*/
|
|
2678
|
+
|
|
2679
|
+
/**
|
|
2680
|
+
* Returns the total border width and individual sides from `border{Side}Width` CSS properties.
|
|
2681
|
+
*
|
|
2682
|
+
* @param {Element} el - The target DOM element.
|
|
2683
|
+
* @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) border widths, and each side individually.
|
|
2684
|
+
*/
|
|
2685
|
+
const getHtmlElBordersWidth = (el) => {
|
|
2686
|
+
const styles = getComputedStyle(el);
|
|
2687
|
+
const left = parseFloat(styles.borderLeftWidth) || 0;
|
|
2688
|
+
const right = parseFloat(styles.borderRightWidth) || 0;
|
|
2689
|
+
const top = parseFloat(styles.borderTopWidth) || 0;
|
|
2690
|
+
const bottom = parseFloat(styles.borderBottomWidth) || 0;
|
|
2691
|
+
const x = left + right;
|
|
2692
|
+
const y = top + bottom;
|
|
2693
|
+
|
|
2694
|
+
return { x, y, left, right, top, bottom };
|
|
2695
|
+
};
|
|
2696
|
+
|
|
2697
|
+
/**
|
|
2698
|
+
* Returns the total border size and individual sides from `border{Side}` CSS properties.
|
|
2699
|
+
*
|
|
2700
|
+
* @param {Element} el - The target DOM element.
|
|
2701
|
+
* @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) border sizes, and each side individually.
|
|
2702
|
+
*/
|
|
2703
|
+
const getHtmlElBorders = (el) => {
|
|
2704
|
+
const styles = getComputedStyle(el);
|
|
2705
|
+
const left = parseFloat(styles.borderLeft) || 0;
|
|
2706
|
+
const right = parseFloat(styles.borderRight) || 0;
|
|
2707
|
+
const top = parseFloat(styles.borderTop) || 0;
|
|
2708
|
+
const bottom = parseFloat(styles.borderBottom) || 0;
|
|
2709
|
+
const x = left + right;
|
|
2710
|
+
const y = top + bottom;
|
|
2711
|
+
|
|
2712
|
+
return { x, y, left, right, top, bottom };
|
|
2713
|
+
};
|
|
2714
|
+
|
|
2715
|
+
/**
|
|
2716
|
+
* Returns the total margin and individual sides from `margin{Side}` CSS properties.
|
|
2717
|
+
*
|
|
2718
|
+
* @param {Element} el - The target DOM element.
|
|
2719
|
+
* @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) margins, and each side individually.
|
|
2720
|
+
*/
|
|
2721
|
+
const getHtmlElMargin = (el) => {
|
|
2722
|
+
const styles = getComputedStyle(el);
|
|
2723
|
+
const left = parseFloat(styles.marginLeft) || 0;
|
|
2724
|
+
const right = parseFloat(styles.marginRight) || 0;
|
|
2725
|
+
const top = parseFloat(styles.marginTop) || 0;
|
|
2726
|
+
const bottom = parseFloat(styles.marginBottom) || 0;
|
|
2727
|
+
|
|
2728
|
+
const x = left + right;
|
|
2729
|
+
const y = top + bottom;
|
|
2730
|
+
|
|
2731
|
+
return { x, y, left, right, top, bottom };
|
|
2732
|
+
};
|
|
2733
|
+
|
|
2734
|
+
/**
|
|
2735
|
+
* Returns the total padding and individual sides from `padding{Side}` CSS properties.
|
|
2736
|
+
*
|
|
2737
|
+
* @param {Element} el - The target DOM element.
|
|
2738
|
+
* @returns {HtmlElBoxSides} - Total horizontal (x) and vertical (y) paddings, and each side individually.
|
|
2739
|
+
*/
|
|
2740
|
+
const getHtmlElPadding = (el) => {
|
|
2741
|
+
const styles = getComputedStyle(el);
|
|
2742
|
+
const left = parseFloat(styles.paddingLeft) || 0;
|
|
2743
|
+
const right = parseFloat(styles.paddingRight) || 0;
|
|
2744
|
+
const top = parseFloat(styles.paddingTop) || 0;
|
|
2745
|
+
const bottom = parseFloat(styles.paddingBottom) || 0;
|
|
2746
|
+
|
|
2747
|
+
const x = left + right;
|
|
2748
|
+
const y = top + bottom;
|
|
2749
|
+
|
|
2750
|
+
return { x, y, left, right, top, bottom };
|
|
2751
|
+
};
|
|
2752
|
+
|
|
2753
|
+
;// ./src/v1/libs/TinyDragger.mjs
|
|
2754
|
+
|
|
2755
|
+
|
|
2756
|
+
|
|
2757
|
+
/**
|
|
2758
|
+
* @typedef {Object} VibrationPatterns
|
|
2759
|
+
* @property {number[]|false} start - Pattern to vibrate on start
|
|
2760
|
+
* @property {number[]|false} end - Pattern to vibrate on end
|
|
2761
|
+
* @property {number[]|false} collide - Pattern to vibrate on collision
|
|
2762
|
+
* @property {number[]|false} move - Pattern to vibrate while moving
|
|
2763
|
+
*/
|
|
2764
|
+
|
|
2765
|
+
/**
|
|
2766
|
+
* TinyDragger enables drag-and-drop functionality for a DOM element.
|
|
2767
|
+
* It supports jail boundaries, optional collision detection, vibration feedback,
|
|
2768
|
+
* automatic reverting, proxy dragging, and event dispatching.
|
|
2769
|
+
*/
|
|
2770
|
+
class TinyDragger {
|
|
2771
|
+
#enabled = true;
|
|
2772
|
+
#destroyed = false;
|
|
2773
|
+
|
|
2774
|
+
#offsetY = 0;
|
|
2775
|
+
#offsetX = 0;
|
|
2776
|
+
|
|
2777
|
+
#multiCollision = false;
|
|
2778
|
+
#lockInsideJail = false;
|
|
2779
|
+
#revertOnDrop = false;
|
|
2780
|
+
#dragging = false;
|
|
2781
|
+
#collisionByMouse = false;
|
|
2782
|
+
#dropInJailOnly = false;
|
|
2783
|
+
|
|
2784
|
+
/** @type {HTMLElement|null} */
|
|
2785
|
+
#lastCollision = null;
|
|
2786
|
+
|
|
2787
|
+
/** @type {HTMLElement[]} */
|
|
2788
|
+
#collidables = [];
|
|
2789
|
+
|
|
2790
|
+
/** @type {HTMLElement|null} */
|
|
2791
|
+
#dragProxy = null;
|
|
2792
|
+
|
|
2793
|
+
/** @type {VibrationPatterns} */
|
|
2794
|
+
#vibration = { start: false, end: false, collide: false, move: false };
|
|
2795
|
+
|
|
2796
|
+
/** @type {HTMLElement|null} */
|
|
2797
|
+
#jail = null;
|
|
2798
|
+
|
|
2799
|
+
#target;
|
|
2800
|
+
|
|
2801
|
+
#dragHiddenClass = 'drag-hidden';
|
|
2802
|
+
#classDragging = 'dragging';
|
|
2803
|
+
#classBodyDragging = 'drag-active';
|
|
2804
|
+
#classJailDragging = 'jail-drag-active';
|
|
2805
|
+
#classJailDragDisabled = 'jail-drag-disabled';
|
|
2806
|
+
#classDragCollision = 'dragging-collision';
|
|
2807
|
+
|
|
2808
|
+
/** @typedef {(event: TouchEvent) => void} TouchDragEvent */
|
|
2809
|
+
|
|
2810
|
+
/**
|
|
2811
|
+
* @param {HTMLElement} targetElement - The element to make draggable.
|
|
2812
|
+
* @param {Object} [options={}] - Configuration options.
|
|
2813
|
+
* @param {HTMLElement} [options.jail] - Optional container to restrict dragging within.
|
|
2814
|
+
* @param {boolean} [options.collisionByMouse=false] - Use mouse position for collision instead of element rect.
|
|
2815
|
+
* @param {string} [options.classDragging='dragging'] - CSS class applied to the clone during dragging.
|
|
2816
|
+
* @param {string} [options.classBodyDragging='drag-active'] - CSS class applied to <body> during dragging.
|
|
2817
|
+
* @param {string} [options.classJailDragging='jail-drag-active'] - CSS class applied to jail element during drag.
|
|
2818
|
+
* @param {string} [options.classJailDragDisabled='jail-drag-disabled'] - CSS class applied to jail element disabled.
|
|
2819
|
+
* @param {string} [options.classDragCollision='dragging-collision'] - CSS class applied to collision element.
|
|
2820
|
+
* @param {boolean} [options.lockInsideJail=false] - Restrict movement within the jail container.
|
|
2821
|
+
* @param {boolean} [options.dropInJailOnly=false] - Restrict drop within the jail container.
|
|
2822
|
+
* @param {boolean} [options.multiCollision=false] - Enables returning multiple collided elements.
|
|
2823
|
+
* @param {VibrationPatterns|false} [options.vibration=false] - Vibration feedback configuration.
|
|
2824
|
+
* @param {boolean} [options.revertOnDrop=false] - Whether to return to original position on drop.
|
|
2825
|
+
* @param {string} [options.classHidden='drag-hidden'] - CSS class to hide original element during dragging.
|
|
2826
|
+
* @throws {Error} If any option has an invalid type.
|
|
2827
|
+
*/
|
|
2828
|
+
constructor(targetElement, options = {}) {
|
|
2829
|
+
if (!(targetElement instanceof HTMLElement))
|
|
2830
|
+
throw new Error('TinyDragger requires a valid target HTMLElement to initialize.');
|
|
2831
|
+
|
|
2832
|
+
this.#target = targetElement;
|
|
2833
|
+
|
|
2834
|
+
// === Validations ===
|
|
2835
|
+
if (options.jail !== undefined && !(options.jail instanceof HTMLElement))
|
|
2836
|
+
throw new Error('The "jail" option must be an HTMLElement if provided.');
|
|
2837
|
+
|
|
2838
|
+
if (
|
|
2839
|
+
options.vibration !== undefined &&
|
|
2840
|
+
options.vibration !== false &&
|
|
2841
|
+
!objFilter_isJsonObject(options.vibration)
|
|
2842
|
+
)
|
|
2843
|
+
throw new Error('The "vibration" option must be an object or false.');
|
|
2844
|
+
|
|
2845
|
+
/**
|
|
2846
|
+
* @param {any} val
|
|
2847
|
+
* @param {string} name
|
|
2848
|
+
*/
|
|
2849
|
+
const validateBoolean = (val, name) => {
|
|
2850
|
+
if (val !== undefined && typeof val !== 'boolean') {
|
|
2851
|
+
throw new Error(`The "${name}" option must be a boolean.`);
|
|
2852
|
+
}
|
|
2853
|
+
};
|
|
2854
|
+
|
|
2855
|
+
/**
|
|
2856
|
+
* @param {any} val
|
|
2857
|
+
* @param {string} name
|
|
2858
|
+
*/
|
|
2859
|
+
const validateString = (val, name) => {
|
|
2860
|
+
if (val !== undefined && typeof val !== 'string') {
|
|
2861
|
+
throw new Error(`The "${name}" option must be a string.`);
|
|
2862
|
+
}
|
|
2863
|
+
};
|
|
2864
|
+
|
|
2865
|
+
validateBoolean(options.collisionByMouse, 'collisionByMouse');
|
|
2866
|
+
validateBoolean(options.lockInsideJail, 'lockInsideJail');
|
|
2867
|
+
validateBoolean(options.dropInJailOnly, 'dropInJailOnly');
|
|
2868
|
+
validateBoolean(options.revertOnDrop, 'revertOnDrop');
|
|
2869
|
+
validateBoolean(options.multiCollision, 'multiCollision');
|
|
2870
|
+
|
|
2871
|
+
validateString(options.classDragging, 'classDragging');
|
|
2872
|
+
validateString(options.classBodyDragging, 'classBodyDragging');
|
|
2873
|
+
validateString(options.classJailDragging, 'classJailDragging');
|
|
2874
|
+
validateString(options.classJailDragDisabled, 'classJailDragDisabled');
|
|
2875
|
+
validateString(options.classDragCollision, 'classDragCollision');
|
|
2876
|
+
validateString(options.classHidden, 'classHidden');
|
|
2877
|
+
|
|
2878
|
+
if (options.jail instanceof HTMLElement) this.#jail = options.jail;
|
|
2879
|
+
|
|
2880
|
+
/** @type {VibrationPatterns} */
|
|
2881
|
+
const vibrationTemplate = { start: false, end: false, collide: false, move: false };
|
|
2882
|
+
this.#vibration = Object.assign(
|
|
2883
|
+
vibrationTemplate,
|
|
2884
|
+
objFilter_isJsonObject(options.vibration) ? options.vibration : {},
|
|
2885
|
+
);
|
|
2886
|
+
|
|
2887
|
+
if (typeof options.classDragging === 'string') this.#classDragging = options.classDragging;
|
|
2888
|
+
if (typeof options.classBodyDragging === 'string')
|
|
2889
|
+
this.#classBodyDragging = options.classBodyDragging;
|
|
2890
|
+
if (typeof options.classJailDragging === 'string')
|
|
2891
|
+
this.#classJailDragging = options.classJailDragging;
|
|
2892
|
+
if (typeof options.classJailDragDisabled === 'string')
|
|
2893
|
+
this.#classJailDragDisabled = options.classJailDragDisabled;
|
|
2894
|
+
if (typeof options.classHidden === 'string') this.#dragHiddenClass = options.classHidden;
|
|
2895
|
+
if (typeof options.classDragCollision === 'string')
|
|
2896
|
+
this.#classDragCollision = options.classDragCollision;
|
|
2897
|
+
|
|
2898
|
+
if (typeof options.collisionByMouse === 'boolean')
|
|
2899
|
+
this.#collisionByMouse = options.collisionByMouse;
|
|
2900
|
+
if (typeof options.revertOnDrop === 'boolean') this.#revertOnDrop = options.revertOnDrop;
|
|
2901
|
+
if (typeof options.lockInsideJail === 'boolean') this.#lockInsideJail = options.lockInsideJail;
|
|
2902
|
+
if (typeof options.dropInJailOnly === 'boolean') this.#dropInJailOnly = options.dropInJailOnly;
|
|
2903
|
+
if (typeof options.multiCollision === 'boolean') this.#multiCollision = options.multiCollision;
|
|
2904
|
+
|
|
2905
|
+
/** @private */
|
|
2906
|
+
this._onMouseDown = this.#startDrag.bind(this);
|
|
2907
|
+
/** @private */
|
|
2908
|
+
this._onMouseMove = this.#drag.bind(this);
|
|
2909
|
+
/** @private */
|
|
2910
|
+
this._onMouseUp = this.#endDrag.bind(this);
|
|
2911
|
+
|
|
2912
|
+
/**
|
|
2913
|
+
* @type {TouchDragEvent}
|
|
2914
|
+
* @private
|
|
2915
|
+
*/
|
|
2916
|
+
this._onTouchStart = (e) => this.#startDrag(e.touches[0]);
|
|
2917
|
+
|
|
2918
|
+
/**
|
|
2919
|
+
* @type {TouchDragEvent}
|
|
2920
|
+
* @private
|
|
2921
|
+
*/
|
|
2922
|
+
this._onTouchMove = (e) => this.#drag(e.touches[0]);
|
|
2923
|
+
|
|
2924
|
+
/**
|
|
2925
|
+
* @type {TouchDragEvent}
|
|
2926
|
+
* @private
|
|
2927
|
+
*/
|
|
2928
|
+
this._onTouchEnd = (e) => this.#endDrag(e.changedTouches[0]);
|
|
2929
|
+
|
|
2930
|
+
this.#target.addEventListener('mousedown', this._onMouseDown);
|
|
2931
|
+
this.#target.addEventListener('touchstart', this._onTouchStart, { passive: false });
|
|
2932
|
+
}
|
|
2933
|
+
|
|
2934
|
+
/**
|
|
2935
|
+
* Enables the drag functionality.
|
|
2936
|
+
*/
|
|
2937
|
+
enable() {
|
|
2938
|
+
this.#checkDestroy();
|
|
2939
|
+
if (this.#jail) this.#jail.classList.add(this.#classJailDragDisabled);
|
|
2940
|
+
this.#enabled = true;
|
|
2941
|
+
}
|
|
2942
|
+
|
|
2943
|
+
/**
|
|
2944
|
+
* Disables the drag functionality.
|
|
2945
|
+
*/
|
|
2946
|
+
disable() {
|
|
2947
|
+
if (this.#jail) this.#jail.classList.remove(this.#classJailDragDisabled);
|
|
2948
|
+
this.#enabled = false;
|
|
2949
|
+
}
|
|
2950
|
+
|
|
2951
|
+
/**
|
|
2952
|
+
* Adds an element to be considered for collision detection.
|
|
2953
|
+
* @param {HTMLElement} element - The element to track collisions with.
|
|
2954
|
+
* @throws {Error} If the element is not a valid HTMLElement.
|
|
2955
|
+
*/
|
|
2956
|
+
addCollidable(element) {
|
|
2957
|
+
this.#checkDestroy();
|
|
2958
|
+
if (!(element instanceof HTMLElement))
|
|
2959
|
+
throw new Error('addCollidable expects an HTMLElement as argument.');
|
|
2960
|
+
if (!this.#collidables.includes(element)) this.#collidables.push(element);
|
|
2961
|
+
}
|
|
2962
|
+
|
|
2963
|
+
/**
|
|
2964
|
+
* Removes a collidable element from the tracking list.
|
|
2965
|
+
* @param {HTMLElement} element - The element to remove.
|
|
2966
|
+
* @throws {Error} If the element is not a valid HTMLElement.
|
|
2967
|
+
*/
|
|
2968
|
+
removeCollidable(element) {
|
|
2969
|
+
this.#checkDestroy();
|
|
2970
|
+
if (!(element instanceof HTMLElement))
|
|
2971
|
+
throw new Error('removeCollidable expects an HTMLElement as argument.');
|
|
2972
|
+
this.#collidables = this.#collidables.filter((el) => el !== element);
|
|
2973
|
+
}
|
|
2974
|
+
|
|
2975
|
+
/**
|
|
2976
|
+
* Sets vibration patterns for drag events.
|
|
2977
|
+
* @param {Object} [param0={}] - Vibration pattern configuration.
|
|
2978
|
+
* @param {number[]|false} [param0.startPattern=false] - Vibration on drag start.
|
|
2979
|
+
* @param {number[]|false} [param0.endPattern=false] - Vibration on drag end.
|
|
2980
|
+
* @param {number[]|false} [param0.collidePattern=false] - Vibration on collision.
|
|
2981
|
+
* @param {number[]|false} [param0.movePattern=false] - Vibration during movement.
|
|
2982
|
+
* @throws {Error} If any pattern is not false or an array of numbers.
|
|
2983
|
+
*/
|
|
2984
|
+
setVibrationPattern({
|
|
2985
|
+
startPattern = false,
|
|
2986
|
+
endPattern = false,
|
|
2987
|
+
collidePattern = false,
|
|
2988
|
+
movePattern = false,
|
|
2989
|
+
} = {}) {
|
|
2990
|
+
this.#checkDestroy();
|
|
2991
|
+
|
|
2992
|
+
/** @param {any} value */
|
|
2993
|
+
const isValidPattern = (value) =>
|
|
2994
|
+
value === false || (Array.isArray(value) && value.every((n) => typeof n === 'number'));
|
|
2995
|
+
|
|
2996
|
+
if (!isValidPattern(startPattern))
|
|
2997
|
+
throw new Error('Invalid "startPattern": must be false or an array of numbers.');
|
|
2998
|
+
if (!isValidPattern(endPattern))
|
|
2999
|
+
throw new Error('Invalid "endPattern": must be false or an array of numbers.');
|
|
3000
|
+
if (!isValidPattern(collidePattern))
|
|
3001
|
+
throw new Error('Invalid "collidePattern": must be false or an array of numbers.');
|
|
3002
|
+
if (!isValidPattern(movePattern))
|
|
3003
|
+
throw new Error('Invalid "movePattern": must be false or an array of numbers.');
|
|
3004
|
+
|
|
3005
|
+
this.#vibration = {
|
|
3006
|
+
start: startPattern,
|
|
3007
|
+
end: endPattern,
|
|
3008
|
+
collide: collidePattern,
|
|
3009
|
+
move: movePattern,
|
|
3010
|
+
};
|
|
3011
|
+
}
|
|
3012
|
+
|
|
3013
|
+
/**
|
|
3014
|
+
* Disables all vibration feedback.
|
|
3015
|
+
*/
|
|
3016
|
+
disableVibration() {
|
|
3017
|
+
this.#checkDestroy();
|
|
3018
|
+
this.#vibration = { start: false, end: false, collide: false, move: false };
|
|
3019
|
+
}
|
|
3020
|
+
|
|
3021
|
+
/**
|
|
3022
|
+
* Calculates the cursor offset relative to the top-left of the target element.
|
|
3023
|
+
* @param {MouseEvent|Touch} event - The mouse or touch event.
|
|
3024
|
+
* @returns {{x: number, y: number}} The offset in pixels.
|
|
3025
|
+
* @throws {Error} If event is not a MouseEvent or Touch with clientX/clientY.
|
|
3026
|
+
*/
|
|
3027
|
+
getOffset(event) {
|
|
3028
|
+
this.#checkDestroy();
|
|
3029
|
+
if (
|
|
3030
|
+
(!(event instanceof MouseEvent) && !(event instanceof Touch)) ||
|
|
3031
|
+
typeof event.clientX !== 'number' ||
|
|
3032
|
+
typeof event.clientY !== 'number'
|
|
3033
|
+
)
|
|
3034
|
+
throw new Error('getOffset expects an event with valid clientX and clientY coordinates.');
|
|
3035
|
+
|
|
3036
|
+
const targetRect = this.#target.getBoundingClientRect();
|
|
3037
|
+
const { left: borderLeft, top: borderTop } = getHtmlElBordersWidth(this.#target);
|
|
3038
|
+
return {
|
|
3039
|
+
x: event.clientX - targetRect.left + borderLeft,
|
|
3040
|
+
y: event.clientY - targetRect.top + borderTop,
|
|
3041
|
+
};
|
|
3042
|
+
}
|
|
3043
|
+
|
|
3044
|
+
/**
|
|
3045
|
+
* Handles the start of a drag event.
|
|
3046
|
+
* @param {MouseEvent|Touch} event - The initiating event.
|
|
3047
|
+
*/
|
|
3048
|
+
#startDrag(event) {
|
|
3049
|
+
if (event instanceof MouseEvent) event.preventDefault();
|
|
3050
|
+
if (this.#destroyed || !this.#enabled || !this.#target.parentElement) return;
|
|
3051
|
+
|
|
3052
|
+
const dragProxy = this.#target.cloneNode(true);
|
|
3053
|
+
if (!(dragProxy instanceof HTMLElement)) return;
|
|
3054
|
+
this.#dragProxy = dragProxy;
|
|
3055
|
+
|
|
3056
|
+
this.#dragging = true;
|
|
3057
|
+
|
|
3058
|
+
const rect = this.#target.getBoundingClientRect();
|
|
3059
|
+
|
|
3060
|
+
Object.assign(this.#dragProxy.style, {
|
|
3061
|
+
position: 'absolute',
|
|
3062
|
+
pointerEvents: 'none',
|
|
3063
|
+
left: `${this.#target.offsetLeft}px`,
|
|
3064
|
+
top: `${this.#target.offsetTop}px`,
|
|
3065
|
+
width: `${rect.width}px`,
|
|
3066
|
+
height: `${rect.height}px`,
|
|
3067
|
+
zIndex: 9999,
|
|
3068
|
+
});
|
|
3069
|
+
|
|
3070
|
+
this.#target.classList.add(this.#dragHiddenClass);
|
|
3071
|
+
this.#target.parentElement.appendChild(this.#dragProxy);
|
|
3072
|
+
|
|
3073
|
+
const { x: offsetX, y: offsetY } = this.getOffset(event);
|
|
3074
|
+
this.#offsetX = offsetX;
|
|
3075
|
+
this.#offsetY = offsetY;
|
|
3076
|
+
|
|
3077
|
+
this.#dragProxy.classList.add(this.#classDragging);
|
|
3078
|
+
document.body.classList.add(this.#classBodyDragging);
|
|
3079
|
+
if (this.#jail) this.#jail.classList.add(this.#classJailDragging);
|
|
3080
|
+
|
|
3081
|
+
document.addEventListener('mousemove', this._onMouseMove);
|
|
3082
|
+
document.addEventListener('mouseup', this._onMouseUp);
|
|
3083
|
+
|
|
3084
|
+
document.addEventListener('touchmove', this._onTouchMove, { passive: false });
|
|
3085
|
+
document.addEventListener('touchend', this._onTouchEnd);
|
|
3086
|
+
|
|
3087
|
+
if (navigator.vibrate && Array.isArray(this.#vibration.start)) {
|
|
3088
|
+
navigator.vibrate(this.#vibration.start);
|
|
3089
|
+
}
|
|
3090
|
+
|
|
3091
|
+
this.checkDragCollision(event);
|
|
3092
|
+
this.#dispatchEvent('drag');
|
|
3093
|
+
}
|
|
3094
|
+
|
|
3095
|
+
/** @type {HTMLElement[]} */
|
|
3096
|
+
#collisionsMarked = [];
|
|
3097
|
+
|
|
3098
|
+
/**
|
|
3099
|
+
* Marks an element as currently collided by adding the collision CSS class.
|
|
3100
|
+
* The element is stored in an internal list for easy removal later.
|
|
3101
|
+
*
|
|
3102
|
+
* @param {HTMLElement|null} el - The element to mark as collided.
|
|
3103
|
+
*/
|
|
3104
|
+
#addCollision(el) {
|
|
3105
|
+
if (!el) return;
|
|
3106
|
+
el.classList.add(this.#classDragCollision);
|
|
3107
|
+
this.#collisionsMarked.push(el);
|
|
3108
|
+
}
|
|
3109
|
+
|
|
3110
|
+
/**
|
|
3111
|
+
* Removes the collision CSS class from all previously marked elements.
|
|
3112
|
+
* Also clears the last single collision element, if set.
|
|
3113
|
+
*
|
|
3114
|
+
*/
|
|
3115
|
+
#removeCollision() {
|
|
3116
|
+
while (this.#collisionsMarked.length > 0) {
|
|
3117
|
+
const el = this.#collisionsMarked.shift();
|
|
3118
|
+
if (el) el.classList.remove(this.#classDragCollision);
|
|
3119
|
+
}
|
|
3120
|
+
if (!this.#lastCollision) return;
|
|
3121
|
+
this.#lastCollision.classList.remove(this.#classDragCollision);
|
|
3122
|
+
}
|
|
3123
|
+
|
|
3124
|
+
/**
|
|
3125
|
+
* Handles dragging collision.
|
|
3126
|
+
* @param {MouseEvent|Touch} event - The drag event.
|
|
3127
|
+
*/
|
|
3128
|
+
checkDragCollision(event) {
|
|
3129
|
+
const { collidedElements } = this.execCollision(event);
|
|
3130
|
+
const first = collidedElements[0] || null;
|
|
3131
|
+
|
|
3132
|
+
// Removes old marking if necessary
|
|
3133
|
+
if (this.#lastCollision && !collidedElements.includes(this.#lastCollision)) {
|
|
3134
|
+
this.#removeCollision();
|
|
3135
|
+
}
|
|
3136
|
+
|
|
3137
|
+
// Adds Marking for All Colluded
|
|
3138
|
+
collidedElements.forEach((el) => this.#addCollision(el));
|
|
3139
|
+
|
|
3140
|
+
// Removes markings from who no longer collided
|
|
3141
|
+
this.#collidables.forEach((el) => {
|
|
3142
|
+
if (!collidedElements.includes(el)) {
|
|
3143
|
+
el.classList.remove(this.#classDragCollision);
|
|
3144
|
+
}
|
|
3145
|
+
});
|
|
3146
|
+
|
|
3147
|
+
if (
|
|
3148
|
+
navigator.vibrate &&
|
|
3149
|
+
Array.isArray(this.#vibration.collide) &&
|
|
3150
|
+
collidedElements.length > 0
|
|
3151
|
+
) {
|
|
3152
|
+
navigator.vibrate(this.#vibration.collide);
|
|
3153
|
+
}
|
|
3154
|
+
|
|
3155
|
+
this.#lastCollision = first;
|
|
3156
|
+
}
|
|
3157
|
+
|
|
3158
|
+
/**
|
|
3159
|
+
* Handles dragging movement.
|
|
3160
|
+
* @param {MouseEvent|Touch} event - The drag event.
|
|
3161
|
+
*/
|
|
3162
|
+
#drag(event) {
|
|
3163
|
+
if (event instanceof MouseEvent) event.preventDefault();
|
|
3164
|
+
if (this.#destroyed || !this.#dragging || !this.#enabled || !this.#dragProxy) return;
|
|
3165
|
+
|
|
3166
|
+
const parent = this.#dragProxy.offsetParent || document.body;
|
|
3167
|
+
const parentRect = parent.getBoundingClientRect();
|
|
3168
|
+
|
|
3169
|
+
let x = event.clientX - parentRect.left - this.#offsetX;
|
|
3170
|
+
let y = event.clientY - parentRect.top - this.#offsetY;
|
|
3171
|
+
|
|
3172
|
+
if (this.#lockInsideJail && this.#jail) {
|
|
3173
|
+
const jailRect = this.#jail.getBoundingClientRect();
|
|
3174
|
+
const targetRect = this.#dragProxy.getBoundingClientRect();
|
|
3175
|
+
|
|
3176
|
+
const jailLeft = jailRect.left - parentRect.left;
|
|
3177
|
+
const jailTop = jailRect.top - parentRect.top;
|
|
3178
|
+
|
|
3179
|
+
const { x: borderX, y: borderY } = getHtmlElBordersWidth(this.#jail);
|
|
3180
|
+
const maxX = jailLeft + jailRect.width - targetRect.width - borderY;
|
|
3181
|
+
const maxY = jailTop + jailRect.height - targetRect.height - borderX;
|
|
3182
|
+
|
|
3183
|
+
x = Math.max(jailLeft, Math.min(x, maxX));
|
|
3184
|
+
y = Math.max(jailTop, Math.min(y, maxY));
|
|
3185
|
+
}
|
|
3186
|
+
|
|
3187
|
+
this.#dragProxy.style.position = 'absolute';
|
|
3188
|
+
this.#dragProxy.style.left = `${x}px`;
|
|
3189
|
+
this.#dragProxy.style.top = `${y}px`;
|
|
3190
|
+
|
|
3191
|
+
if (navigator.vibrate && Array.isArray(this.#vibration.move)) {
|
|
3192
|
+
navigator.vibrate(this.#vibration.move);
|
|
3193
|
+
}
|
|
3194
|
+
|
|
3195
|
+
this.checkDragCollision(event);
|
|
3196
|
+
this.#dispatchEvent('dragging');
|
|
3197
|
+
}
|
|
3198
|
+
|
|
3199
|
+
/**
|
|
3200
|
+
* Handles the collision of a drag.
|
|
3201
|
+
* @param {MouseEvent|Touch} event - The release event.
|
|
3202
|
+
* @returns {{ inJail: boolean; collidedElements: (HTMLElement | null)[] }}
|
|
3203
|
+
*/
|
|
3204
|
+
execCollision(event) {
|
|
3205
|
+
if (this.#destroyed || !this.#dragProxy) return { inJail: false, collidedElements: [] };
|
|
3206
|
+
|
|
3207
|
+
let collidedElements = [];
|
|
3208
|
+
let inJail = true;
|
|
3209
|
+
const jailRect = this.#jail?.getBoundingClientRect();
|
|
3210
|
+
|
|
3211
|
+
if (this.#collisionByMouse) {
|
|
3212
|
+
const x = event.clientX;
|
|
3213
|
+
const y = event.clientY;
|
|
3214
|
+
|
|
3215
|
+
if (this.#dropInJailOnly && this.#jail && jailRect) {
|
|
3216
|
+
inJail =
|
|
3217
|
+
x >= jailRect.left && x <= jailRect.right && y >= jailRect.top && y <= jailRect.bottom;
|
|
3218
|
+
}
|
|
3219
|
+
|
|
3220
|
+
collidedElements = inJail
|
|
3221
|
+
? this.#multiCollision
|
|
3222
|
+
? this.getAllCollidedElements(x, y)
|
|
3223
|
+
: [this.getCollidedElement(x, y)].filter(Boolean)
|
|
3224
|
+
: [];
|
|
3225
|
+
} else {
|
|
3226
|
+
const rect = this.#dragProxy.getBoundingClientRect();
|
|
3227
|
+
|
|
3228
|
+
if (this.#dropInJailOnly && this.#jail && jailRect) {
|
|
3229
|
+
inJail =
|
|
3230
|
+
rect.left >= jailRect.left &&
|
|
3231
|
+
rect.right <= jailRect.right &&
|
|
3232
|
+
rect.top >= jailRect.top &&
|
|
3233
|
+
rect.bottom <= jailRect.bottom;
|
|
3234
|
+
}
|
|
3235
|
+
|
|
3236
|
+
collidedElements = inJail
|
|
3237
|
+
? this.#multiCollision
|
|
3238
|
+
? this.getAllCollidedElementsByRect(rect)
|
|
3239
|
+
: [this.getCollidedElementByRect(rect)].filter(Boolean)
|
|
3240
|
+
: [];
|
|
3241
|
+
}
|
|
3242
|
+
|
|
3243
|
+
return { inJail, collidedElements };
|
|
3244
|
+
}
|
|
3245
|
+
|
|
3246
|
+
/**
|
|
3247
|
+
* Handles the end of a drag.
|
|
3248
|
+
* @param {MouseEvent|Touch} event - The release event.
|
|
3249
|
+
*/
|
|
3250
|
+
#endDrag(event) {
|
|
3251
|
+
if (event instanceof MouseEvent) event.preventDefault();
|
|
3252
|
+
if (this.#destroyed || !this.#dragging) return;
|
|
3253
|
+
|
|
3254
|
+
this.#dragging = false;
|
|
3255
|
+
if (!this.#dragProxy) return;
|
|
3256
|
+
|
|
3257
|
+
this.#target.classList.remove(this.#classDragging);
|
|
3258
|
+
document.body.classList.remove(this.#classBodyDragging);
|
|
3259
|
+
if (this.#jail) this.#jail.classList.remove(this.#classJailDragging);
|
|
3260
|
+
|
|
3261
|
+
document.removeEventListener('mousemove', this._onMouseMove);
|
|
3262
|
+
document.removeEventListener('mouseup', this._onMouseUp);
|
|
3263
|
+
|
|
3264
|
+
document.removeEventListener('touchmove', this._onTouchMove);
|
|
3265
|
+
document.removeEventListener('touchend', this._onTouchEnd);
|
|
3266
|
+
const { collidedElements } = this.execCollision(event);
|
|
3267
|
+
|
|
3268
|
+
if (navigator.vibrate && Array.isArray(this.#vibration.end)) {
|
|
3269
|
+
navigator.vibrate(this.#vibration.end);
|
|
3270
|
+
}
|
|
3271
|
+
|
|
3272
|
+
const newX = this.#dragProxy.style.left;
|
|
3273
|
+
const newY = this.#dragProxy.style.top;
|
|
3274
|
+
if (this.#dragProxy) {
|
|
3275
|
+
this.#dragProxy.remove();
|
|
3276
|
+
this.#dragProxy = null;
|
|
3277
|
+
}
|
|
3278
|
+
|
|
3279
|
+
if (this.#lastCollision) this.#removeCollision();
|
|
3280
|
+
this.#lastCollision = null;
|
|
3281
|
+
|
|
3282
|
+
this.#target.classList.remove(this.#dragHiddenClass);
|
|
3283
|
+
if (!this.#revertOnDrop) {
|
|
3284
|
+
this.#target.style.left = newX;
|
|
3285
|
+
this.#target.style.top = newY;
|
|
3286
|
+
}
|
|
3287
|
+
|
|
3288
|
+
const dropEvent = new CustomEvent('drop', {
|
|
3289
|
+
detail: {
|
|
3290
|
+
targets: collidedElements,
|
|
3291
|
+
first: collidedElements[0] || null,
|
|
3292
|
+
},
|
|
3293
|
+
});
|
|
3294
|
+
this.#target.dispatchEvent(dropEvent);
|
|
3295
|
+
}
|
|
3296
|
+
|
|
3297
|
+
/**
|
|
3298
|
+
* Checks if the provided element intersects with the given bounding rectangle.
|
|
3299
|
+
*
|
|
3300
|
+
* @param {HTMLElement} el - The element to test for collision.
|
|
3301
|
+
* @param {DOMRect} rect - The bounding rectangle to check against.
|
|
3302
|
+
* @returns {boolean} True if the element intersects with the rectangle.
|
|
3303
|
+
*/
|
|
3304
|
+
#getCollidedElementByRect(el, rect) {
|
|
3305
|
+
const elRect = el.getBoundingClientRect();
|
|
3306
|
+
return !(
|
|
3307
|
+
rect.right < elRect.left ||
|
|
3308
|
+
rect.left > elRect.right ||
|
|
3309
|
+
rect.bottom < elRect.top ||
|
|
3310
|
+
rect.top > elRect.bottom
|
|
3311
|
+
);
|
|
3312
|
+
}
|
|
3313
|
+
|
|
3314
|
+
/**
|
|
3315
|
+
* Returns all elements currently colliding with the given rectangle.
|
|
3316
|
+
*
|
|
3317
|
+
* @param {DOMRect} rect - Bounding rectangle of the dragged proxy.
|
|
3318
|
+
* @returns {HTMLElement[]} A list of all collided elements.
|
|
3319
|
+
* @throws {Error} If the input is not a valid DOMRect with numeric bounds.
|
|
3320
|
+
*/
|
|
3321
|
+
getAllCollidedElementsByRect(rect) {
|
|
3322
|
+
this.#checkDestroy();
|
|
3323
|
+
if (
|
|
3324
|
+
!(rect instanceof DOMRect) ||
|
|
3325
|
+
typeof rect.left !== 'number' ||
|
|
3326
|
+
typeof rect.right !== 'number' ||
|
|
3327
|
+
typeof rect.top !== 'number' ||
|
|
3328
|
+
typeof rect.bottom !== 'number'
|
|
3329
|
+
)
|
|
3330
|
+
throw new Error('getCollidedElementByRect expects a valid DOMRect object.');
|
|
3331
|
+
return this.#collidables.filter((el) => this.#getCollidedElementByRect(el, rect));
|
|
3332
|
+
}
|
|
3333
|
+
|
|
3334
|
+
/**
|
|
3335
|
+
* Detects collision based on rectangle intersection.
|
|
3336
|
+
* @param {DOMRect} rect - Bounding rectangle of the dragged proxy.
|
|
3337
|
+
* @returns {HTMLElement|null} The collided element or null.
|
|
3338
|
+
* @throws {Error} If rect is not a DOMRect with valid numeric properties.
|
|
3339
|
+
*/
|
|
3340
|
+
getCollidedElementByRect(rect) {
|
|
3341
|
+
this.#checkDestroy();
|
|
3342
|
+
if (
|
|
3343
|
+
!(rect instanceof DOMRect) ||
|
|
3344
|
+
typeof rect.left !== 'number' ||
|
|
3345
|
+
typeof rect.right !== 'number' ||
|
|
3346
|
+
typeof rect.top !== 'number' ||
|
|
3347
|
+
typeof rect.bottom !== 'number'
|
|
3348
|
+
)
|
|
3349
|
+
throw new Error('getCollidedElementByRect expects a valid DOMRect object.');
|
|
3350
|
+
return this.#collidables.find((el) => this.#getCollidedElementByRect(el, rect)) || null;
|
|
3351
|
+
}
|
|
3352
|
+
|
|
3353
|
+
/**
|
|
3354
|
+
* Checks whether a given (x, y) coordinate is inside the bounding rectangle of an element.
|
|
3355
|
+
*
|
|
3356
|
+
* @param {HTMLElement} el - The element to test for collision.
|
|
3357
|
+
* @param {number} x - Horizontal screen coordinate.
|
|
3358
|
+
* @param {number} y - Vertical screen coordinate.
|
|
3359
|
+
* @returns {boolean} True if the point is within the element's bounds.
|
|
3360
|
+
*/
|
|
3361
|
+
#getCollidedElement(el, x, y) {
|
|
3362
|
+
const rect = el.getBoundingClientRect();
|
|
3363
|
+
return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
|
|
3364
|
+
}
|
|
3365
|
+
|
|
3366
|
+
/**
|
|
3367
|
+
* @param {number} x - Horizontal screen coordinate.
|
|
3368
|
+
* @param {number} y - Vertical screen coordinate.
|
|
3369
|
+
* @returns {HTMLElement[]} The collided element or null.
|
|
3370
|
+
*/
|
|
3371
|
+
getAllCollidedElements(x, y) {
|
|
3372
|
+
this.#checkDestroy();
|
|
3373
|
+
if (typeof x !== 'number' || typeof y !== 'number')
|
|
3374
|
+
throw new Error('getCollidedElement expects numeric x and y coordinates.');
|
|
3375
|
+
return this.#collidables.filter((el) => this.#getCollidedElement(el, x, y));
|
|
3376
|
+
}
|
|
3377
|
+
|
|
3378
|
+
/**
|
|
3379
|
+
* Detects collision with a point using element bounding rectangles.
|
|
3380
|
+
* @param {number} x - Horizontal screen coordinate.
|
|
3381
|
+
* @param {number} y - Vertical screen coordinate.
|
|
3382
|
+
* @returns {HTMLElement|null} The collided element or null.
|
|
3383
|
+
*/
|
|
3384
|
+
getCollidedElement(x, y) {
|
|
3385
|
+
this.#checkDestroy();
|
|
3386
|
+
if (typeof x !== 'number' || typeof y !== 'number')
|
|
3387
|
+
throw new Error('getCollidedElement expects numeric x and y coordinates.');
|
|
3388
|
+
return this.#collidables.find((el) => this.#getCollidedElement(el, x, y)) || null;
|
|
3389
|
+
}
|
|
3390
|
+
|
|
3391
|
+
/**
|
|
3392
|
+
* Dispatches a custom event from the target element.
|
|
3393
|
+
* @param {string} type - The event name.
|
|
3394
|
+
*/
|
|
3395
|
+
#dispatchEvent(type) {
|
|
3396
|
+
const event = new CustomEvent(type);
|
|
3397
|
+
this.#target.dispatchEvent(event);
|
|
3398
|
+
}
|
|
3399
|
+
|
|
3400
|
+
/**
|
|
3401
|
+
* Gets whether dragging is currently active.
|
|
3402
|
+
* @returns {boolean}
|
|
3403
|
+
*/
|
|
3404
|
+
getDragging() {
|
|
3405
|
+
return this.#dragging;
|
|
3406
|
+
}
|
|
3407
|
+
|
|
3408
|
+
/**
|
|
3409
|
+
* Gets whether movement is restricted inside the jail container.
|
|
3410
|
+
* @returns {boolean}
|
|
3411
|
+
*/
|
|
3412
|
+
getLockInsideJail() {
|
|
3413
|
+
return this.#lockInsideJail;
|
|
3414
|
+
}
|
|
3415
|
+
|
|
3416
|
+
/**
|
|
3417
|
+
* Sets whether movement is restricted inside the jail container.
|
|
3418
|
+
* @param {boolean} value
|
|
3419
|
+
*/
|
|
3420
|
+
setLockInsideJail(value) {
|
|
3421
|
+
if (typeof value !== 'boolean') throw new Error('lockInsideJail must be a boolean.');
|
|
3422
|
+
this.#lockInsideJail = value;
|
|
3423
|
+
}
|
|
3424
|
+
|
|
3425
|
+
/**
|
|
3426
|
+
* Gets whether the element should revert to original position on drop.
|
|
3427
|
+
* @returns {boolean}
|
|
3428
|
+
*/
|
|
3429
|
+
getRevertOnDrop() {
|
|
3430
|
+
return this.#revertOnDrop;
|
|
3431
|
+
}
|
|
3432
|
+
|
|
3433
|
+
/**
|
|
3434
|
+
* Sets whether the element should revert to original position on drop.
|
|
3435
|
+
* @param {boolean} value
|
|
3436
|
+
*/
|
|
3437
|
+
setRevertOnDrop(value) {
|
|
3438
|
+
if (typeof value !== 'boolean') throw new Error('revertOnDrop must be a boolean.');
|
|
3439
|
+
this.#revertOnDrop = value;
|
|
3440
|
+
}
|
|
3441
|
+
|
|
3442
|
+
/**
|
|
3443
|
+
* Gets whether collision detection uses mouse position.
|
|
3444
|
+
* @returns {boolean}
|
|
3445
|
+
*/
|
|
3446
|
+
getCollisionByMouse() {
|
|
3447
|
+
return this.#collisionByMouse;
|
|
3448
|
+
}
|
|
3449
|
+
|
|
3450
|
+
/**
|
|
3451
|
+
* Sets whether collision detection uses mouse position.
|
|
3452
|
+
* @param {boolean} value
|
|
3453
|
+
*/
|
|
3454
|
+
setCollisionByMouse(value) {
|
|
3455
|
+
if (typeof value !== 'boolean') throw new Error('collisionByMouse must be a boolean.');
|
|
3456
|
+
this.#collisionByMouse = value;
|
|
3457
|
+
}
|
|
3458
|
+
|
|
3459
|
+
/**
|
|
3460
|
+
* Gets whether dropping is restricted inside the jail container.
|
|
3461
|
+
* @returns {boolean}
|
|
3462
|
+
*/
|
|
3463
|
+
getDropInJailOnly() {
|
|
3464
|
+
return this.#dropInJailOnly;
|
|
3465
|
+
}
|
|
3466
|
+
|
|
3467
|
+
/**
|
|
3468
|
+
* Sets whether dropping is restricted inside the jail container.
|
|
3469
|
+
* @param {boolean} value
|
|
3470
|
+
*/
|
|
3471
|
+
setDropInJailOnly(value) {
|
|
3472
|
+
if (typeof value !== 'boolean') throw new Error('dropInJailOnly must be a boolean.');
|
|
3473
|
+
this.#dropInJailOnly = value;
|
|
3474
|
+
}
|
|
3475
|
+
|
|
3476
|
+
/**
|
|
3477
|
+
* Returns the original target element being dragged.
|
|
3478
|
+
* @returns {HTMLElement}
|
|
3479
|
+
*/
|
|
3480
|
+
getTarget() {
|
|
3481
|
+
return this.#target;
|
|
3482
|
+
}
|
|
3483
|
+
|
|
3484
|
+
/**
|
|
3485
|
+
* Returns the current jail container (if any).
|
|
3486
|
+
* @returns {HTMLElement|null}
|
|
3487
|
+
*/
|
|
3488
|
+
getJail() {
|
|
3489
|
+
return this.#jail;
|
|
3490
|
+
}
|
|
3491
|
+
|
|
3492
|
+
/**
|
|
3493
|
+
* Returns the current proxy element being dragged (if any).
|
|
3494
|
+
* @returns {HTMLElement|null}
|
|
3495
|
+
*/
|
|
3496
|
+
getDragProxy() {
|
|
3497
|
+
return this.#dragProxy;
|
|
3498
|
+
}
|
|
3499
|
+
|
|
3500
|
+
/**
|
|
3501
|
+
* Returns the last collided element (if any).
|
|
3502
|
+
* @returns {HTMLElement|null}
|
|
3503
|
+
*/
|
|
3504
|
+
getLastCollision() {
|
|
3505
|
+
return this.#lastCollision;
|
|
3506
|
+
}
|
|
3507
|
+
|
|
3508
|
+
/**
|
|
3509
|
+
* Returns all registered collidable elements.
|
|
3510
|
+
* @returns {HTMLElement[]}
|
|
3511
|
+
*/
|
|
3512
|
+
getCollidables() {
|
|
3513
|
+
return [...this.#collidables];
|
|
3514
|
+
}
|
|
3515
|
+
|
|
3516
|
+
/**
|
|
3517
|
+
* Returns the CSS class used to hide the target during drag.
|
|
3518
|
+
* @returns {string}
|
|
3519
|
+
*/
|
|
3520
|
+
getDragHiddenClass() {
|
|
3521
|
+
return this.#dragHiddenClass;
|
|
3522
|
+
}
|
|
3523
|
+
|
|
3524
|
+
/**
|
|
3525
|
+
* Returns the CSS class applied to the clone during dragging.
|
|
3526
|
+
* @returns {string}
|
|
3527
|
+
*/
|
|
3528
|
+
getClassDragging() {
|
|
3529
|
+
return this.#classDragging;
|
|
3530
|
+
}
|
|
3531
|
+
|
|
3532
|
+
/**
|
|
3533
|
+
* Returns the CSS class applied to <body> during dragging.
|
|
3534
|
+
* @returns {string}
|
|
3535
|
+
*/
|
|
3536
|
+
getClassBodyDragging() {
|
|
3537
|
+
return this.#classBodyDragging;
|
|
3538
|
+
}
|
|
3539
|
+
|
|
3540
|
+
/**
|
|
3541
|
+
* Returns the CSS class applied to the jail during dragging.
|
|
3542
|
+
* @returns {string}
|
|
3543
|
+
*/
|
|
3544
|
+
getClassJailDragging() {
|
|
3545
|
+
return this.#classJailDragging;
|
|
3546
|
+
}
|
|
3547
|
+
|
|
3548
|
+
/**
|
|
3549
|
+
* Returns the CSS class applied to the jail when dragging is disabled.
|
|
3550
|
+
* @returns {string}
|
|
3551
|
+
*/
|
|
3552
|
+
getClassJailDragDisabled() {
|
|
3553
|
+
return this.#classJailDragDisabled;
|
|
3554
|
+
}
|
|
3555
|
+
|
|
3556
|
+
/**
|
|
3557
|
+
* Returns the CSS class applied to a collided element.
|
|
3558
|
+
* @returns {string}
|
|
3559
|
+
*/
|
|
3560
|
+
getClassDragCollision() {
|
|
3561
|
+
return this.#classDragCollision;
|
|
3562
|
+
}
|
|
3563
|
+
|
|
3564
|
+
/**
|
|
3565
|
+
* Returns the full vibration configuration.
|
|
3566
|
+
* @returns {VibrationPatterns}
|
|
3567
|
+
*/
|
|
3568
|
+
getVibrations() {
|
|
3569
|
+
return { ...this.#vibration };
|
|
3570
|
+
}
|
|
3571
|
+
|
|
3572
|
+
/**
|
|
3573
|
+
* Returns the vibration pattern for drag start.
|
|
3574
|
+
* @returns {number[]|boolean}
|
|
3575
|
+
*/
|
|
3576
|
+
getStartVibration() {
|
|
3577
|
+
return this.#vibration.start;
|
|
3578
|
+
}
|
|
3579
|
+
|
|
3580
|
+
/**
|
|
3581
|
+
* Returns the vibration pattern for drag end.
|
|
3582
|
+
* @returns {number[]|boolean}
|
|
3583
|
+
*/
|
|
3584
|
+
getEndVibration() {
|
|
3585
|
+
return this.#vibration.end;
|
|
3586
|
+
}
|
|
3587
|
+
|
|
3588
|
+
/**
|
|
3589
|
+
* Returns the vibration pattern for collisions.
|
|
3590
|
+
* @returns {number[]|boolean}
|
|
3591
|
+
*/
|
|
3592
|
+
getCollideVibration() {
|
|
3593
|
+
return this.#vibration.collide;
|
|
3594
|
+
}
|
|
3595
|
+
|
|
3596
|
+
/**
|
|
3597
|
+
* Returns the vibration pattern during movement.
|
|
3598
|
+
* @returns {number[]|boolean}
|
|
3599
|
+
*/
|
|
3600
|
+
getMoveVibration() {
|
|
3601
|
+
return this.#vibration.move;
|
|
3602
|
+
}
|
|
3603
|
+
|
|
3604
|
+
/**
|
|
3605
|
+
* Returns whether the dragger is currently enabled.
|
|
3606
|
+
* @returns {boolean}
|
|
3607
|
+
*/
|
|
3608
|
+
isEnabled() {
|
|
3609
|
+
return this.#enabled;
|
|
3610
|
+
}
|
|
3611
|
+
|
|
3612
|
+
/**
|
|
3613
|
+
* Internal method to verify if the instance has been destroyed.
|
|
3614
|
+
* Throws an error if any operation is attempted after destruction.
|
|
3615
|
+
*/
|
|
3616
|
+
#checkDestroy() {
|
|
3617
|
+
if (this.#destroyed)
|
|
3618
|
+
throw new Error('This TinyDragger instance has been destroyed and can no longer be used.');
|
|
3619
|
+
}
|
|
3620
|
+
|
|
3621
|
+
/**
|
|
3622
|
+
* Completely disables drag-and-drop and cleans up all event listeners.
|
|
3623
|
+
* Does NOT remove the original HTML element.
|
|
3624
|
+
*/
|
|
3625
|
+
destroy() {
|
|
3626
|
+
if (this.#destroyed) return;
|
|
3627
|
+
this.disable();
|
|
3628
|
+
|
|
3629
|
+
this.#target.removeEventListener('mousedown', this._onMouseDown);
|
|
3630
|
+
this.#target.removeEventListener('touchstart', this._onTouchStart);
|
|
3631
|
+
|
|
3632
|
+
document.removeEventListener('mousemove', this._onMouseMove);
|
|
3633
|
+
document.removeEventListener('mouseup', this._onMouseUp);
|
|
3634
|
+
|
|
3635
|
+
document.removeEventListener('touchmove', this._onTouchMove);
|
|
3636
|
+
document.removeEventListener('touchend', this._onTouchEnd);
|
|
3637
|
+
|
|
3638
|
+
if (this.#lastCollision) this.#removeCollision();
|
|
3639
|
+
if (this.#dragProxy) {
|
|
3640
|
+
this.#dragProxy.remove();
|
|
3641
|
+
this.#dragProxy = null;
|
|
3642
|
+
}
|
|
3643
|
+
|
|
3644
|
+
this.#collidables = [];
|
|
3645
|
+
this.#dragging = false;
|
|
3646
|
+
this.#lastCollision = null;
|
|
3647
|
+
|
|
3648
|
+
this.#target.classList.remove(this.#dragHiddenClass, this.#classDragging);
|
|
3649
|
+
document.body.classList.remove(this.#classBodyDragging);
|
|
3650
|
+
if (this.#jail)
|
|
3651
|
+
this.#jail.classList.remove(this.#classJailDragging, this.#classJailDragDisabled);
|
|
3652
|
+
|
|
3653
|
+
this.#destroyed = true;
|
|
3654
|
+
}
|
|
3655
|
+
}
|
|
3656
|
+
|
|
3657
|
+
/* harmony default export */ const libs_TinyDragger = (TinyDragger);
|
|
3658
|
+
|
|
3659
|
+
;// ./src/v1/build/TinyDragger.mjs
|
|
3660
|
+
|
|
3661
|
+
|
|
3662
|
+
|
|
3663
|
+
|
|
3664
|
+
})();
|
|
3665
|
+
|
|
3666
|
+
window.TinyDragger = __webpack_exports__.TinyDragger;
|
|
3667
|
+
/******/ })()
|
|
3668
|
+
;
|