mirror of
https://github.com/SamEyeBam/animate.git
synced 2025-12-14 17:58:02 +00:00
larry babby and threejs for glsl
This commit is contained in:
8
webGl/my-threejs-test/node_modules/ordered-binary/.idea/modules.xml
generated
vendored
Normal file
8
webGl/my-threejs-test/node_modules/ordered-binary/.idea/modules.xml
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/ordered-binary.iml" filepath="$PROJECT_DIR$/.idea/ordered-binary.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
14
webGl/my-threejs-test/node_modules/ordered-binary/.idea/ordered-binary.iml
generated
vendored
Normal file
14
webGl/my-threejs-test/node_modules/ordered-binary/.idea/ordered-binary.iml
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.idea" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/dist" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
1
webGl/my-threejs-test/node_modules/ordered-binary/.nyc_output/5b6bd808-0399-4ee6-9395-344688761dfa.json
generated
vendored
Normal file
1
webGl/my-threejs-test/node_modules/ordered-binary/.nyc_output/5b6bd808-0399-4ee6-9395-344688761dfa.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
1
webGl/my-threejs-test/node_modules/ordered-binary/.nyc_output/processinfo/5b6bd808-0399-4ee6-9395-344688761dfa.json
generated
vendored
Normal file
1
webGl/my-threejs-test/node_modules/ordered-binary/.nyc_output/processinfo/5b6bd808-0399-4ee6-9395-344688761dfa.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"parent":null,"pid":240712,"argv":["/home/kzyp/.nvm/versions/node/v20.0.0/bin/node","/home/kzyp/dev/ordered-binary/node_modules/mocha/bin/mocha","--ui","tdd","--reporter","/home/kzyp/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/222.4167.35.plugins/NodeJS/js/mocha-intellij/lib/mochaIntellijReporter.js","/home/kzyp/dev/ordered-binary/tests/test.js"],"execArgv":[],"cwd":"/home/kzyp/dev/ordered-binary","time":1688411366364,"ppid":240701,"coverageFilename":"/home/kzyp/dev/ordered-binary/.nyc_output/5b6bd808-0399-4ee6-9395-344688761dfa.json","externalId":"","uuid":"5b6bd808-0399-4ee6-9395-344688761dfa","files":[]}
|
||||
1
webGl/my-threejs-test/node_modules/ordered-binary/.nyc_output/processinfo/index.json
generated
vendored
Normal file
1
webGl/my-threejs-test/node_modules/ordered-binary/.nyc_output/processinfo/index.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"processes":{"5b6bd808-0399-4ee6-9395-344688761dfa":{"parent":null,"children":[]}},"files":{},"externalIds":{}}
|
||||
21
webGl/my-threejs-test/node_modules/ordered-binary/LICENSE
generated
vendored
Normal file
21
webGl/my-threejs-test/node_modules/ordered-binary/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Kris Zyp
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
39
webGl/my-threejs-test/node_modules/ordered-binary/README.md
generated
vendored
Normal file
39
webGl/my-threejs-test/node_modules/ordered-binary/README.md
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
[](https://www.npmjs.org/package/ordered-binary)
|
||||
[](https://www.npmjs.org/package/ordered-binary)
|
||||
[](LICENSE)
|
||||
<a href="https://dev.doctorevidence.com/"><img src="./assets/powers-dre.png" width="203" /></a>
|
||||
|
||||
The ordered-binary package provides a representation of JavaScript primitives, serialized into binary format (NodeJS Buffers or Uint8Arrays), such that the binary values are naturally ordered such that it matches the natural ordering or values. For example, since -2.0321 > -2.04, then `toBufferKey(-2.0321)` will be greater than `toBufferKey(-2.04)` as a binary representation, in left-to-right evaluation. This is particular useful for storing keys as binaries with something like LMDB or LevelDB, to avoid any custom sorting.
|
||||
|
||||
The ordered-binary package supports strings, numbers, booleans, symbols, null, as well as an array of primitives. Here is an example of ordering of primitive values:
|
||||
```
|
||||
Buffer.from([0]) // buffers are left unchanged, and this is the minimum value
|
||||
Symbol.for('even symbols')
|
||||
-10 // negative supported
|
||||
-1.1 // decimals supported
|
||||
400
|
||||
3E10
|
||||
'Hello'
|
||||
['Hello', 'World']
|
||||
'World'
|
||||
'hello'
|
||||
['hello', 1, 'world']
|
||||
['hello', 'world']
|
||||
Buffer.from([0xff])
|
||||
```
|
||||
|
||||
|
||||
The main module exports these functions:
|
||||
|
||||
`writeKey(key: string | number | boolean | null | Array, target: Buffer, position: integer, inSequence?: boolean)` - Writes the provide key to the target buffer
|
||||
|
||||
`readKey(buffer, start, end, inSequence)` - Reads the key from the buffer, given the provided start and end, as a primitive value
|
||||
|
||||
`toBufferKey(jsPrimitive)` - This accepts a string, number, or boolean as the argument, and returns a `Buffer`.
|
||||
|
||||
`fromBufferKey(bufferKey, multiple)` - This accepts a Buffer and returns a JavaScript primitive value. This can also parse buffers that hold multiple values delimited by a byte `30`, by setting the second argument to true (in which case it will return an array).
|
||||
|
||||
And these constants:
|
||||
|
||||
`MINIMUM_KEY` - The minimum key supported (`null`, which is represented as single zero byte)
|
||||
`MAXIMUM_KEY` - A maximum key larger than any supported primitive (single 0xff byte)
|
||||
BIN
webGl/my-threejs-test/node_modules/ordered-binary/assets/powers-dre.png
generated
vendored
Normal file
BIN
webGl/my-threejs-test/node_modules/ordered-binary/assets/powers-dre.png
generated
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
443
webGl/my-threejs-test/node_modules/ordered-binary/dist/index.cjs
generated
vendored
Normal file
443
webGl/my-threejs-test/node_modules/ordered-binary/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,443 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
require('constants');
|
||||
|
||||
/*
|
||||
control character types:
|
||||
1 - metadata
|
||||
2 - symbols
|
||||
6 - false
|
||||
7 - true
|
||||
8- 16 - negative doubles
|
||||
16-24 positive doubles
|
||||
27 - String starts with a character 27 or less or is an empty string
|
||||
0 - multipart separator
|
||||
> 27 normal string characters
|
||||
*/
|
||||
|
||||
const float64Array = new Float64Array(2);
|
||||
const int32Array = new Int32Array(float64Array.buffer, 0, 4);
|
||||
let nullTerminate = false;
|
||||
let textEncoder;
|
||||
try {
|
||||
textEncoder = new TextEncoder();
|
||||
} catch (error) {}
|
||||
|
||||
/*
|
||||
* Convert arbitrary scalar values to buffer bytes with type preservation and type-appropriate ordering
|
||||
*/
|
||||
function writeKey(key, target, position, inSequence) {
|
||||
let targetView = target.dataView;
|
||||
if (!targetView)
|
||||
targetView = target.dataView = new DataView(target.buffer, target.byteOffset, ((target.byteLength + 3) >> 2) << 2);
|
||||
switch (typeof key) {
|
||||
case 'string':
|
||||
let strLength = key.length;
|
||||
let c1 = key.charCodeAt(0);
|
||||
if (!(c1 >= 28)) // escape character
|
||||
target[position++] = 27;
|
||||
if (strLength < 0x40) {
|
||||
let i, c2;
|
||||
for (i = 0; i < strLength; i++) {
|
||||
c1 = key.charCodeAt(i);
|
||||
if (c1 <= 4) {
|
||||
target[position++] = 4;
|
||||
target[position++] = c1;
|
||||
} else if (c1 < 0x80) {
|
||||
target[position++] = c1;
|
||||
} else if (c1 < 0x800) {
|
||||
target[position++] = c1 >> 6 | 0xc0;
|
||||
target[position++] = c1 & 0x3f | 0x80;
|
||||
} else if (
|
||||
(c1 & 0xfc00) === 0xd800 &&
|
||||
((c2 = key.charCodeAt(i + 1)) & 0xfc00) === 0xdc00
|
||||
) {
|
||||
c1 = 0x10000 + ((c1 & 0x03ff) << 10) + (c2 & 0x03ff);
|
||||
i++;
|
||||
target[position++] = c1 >> 18 | 0xf0;
|
||||
target[position++] = c1 >> 12 & 0x3f | 0x80;
|
||||
target[position++] = c1 >> 6 & 0x3f | 0x80;
|
||||
target[position++] = c1 & 0x3f | 0x80;
|
||||
} else {
|
||||
target[position++] = c1 >> 12 | 0xe0;
|
||||
target[position++] = c1 >> 6 & 0x3f | 0x80;
|
||||
target[position++] = c1 & 0x3f | 0x80;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (target.utf8Write)
|
||||
position += target.utf8Write(key, position, 0xffffffff);
|
||||
else
|
||||
position += textEncoder.encodeInto(key, target.subarray(position)).written;
|
||||
if (position > target.length - 4)
|
||||
throw new RangeError('String does not fit in target buffer')
|
||||
}
|
||||
break
|
||||
case 'number':
|
||||
float64Array[0] = key;
|
||||
let lowInt = int32Array[0];
|
||||
let highInt = int32Array[1];
|
||||
let length;
|
||||
if (key < 0) {
|
||||
targetView.setInt32(position + 4, ~((lowInt >>> 4) | (highInt << 28)));
|
||||
targetView.setInt32(position + 0, (highInt ^ 0x7fffffff) >>> 4);
|
||||
targetView.setInt32(position + 8, ((lowInt & 0xf) ^ 0xf) << 4, true); // just always do the null termination here
|
||||
return position + 9
|
||||
} else if ((lowInt & 0xf) || inSequence) {
|
||||
length = 9;
|
||||
} else if (lowInt & 0xfffff)
|
||||
length = 8;
|
||||
else if (lowInt || (highInt & 0xf))
|
||||
length = 6;
|
||||
else
|
||||
length = 4;
|
||||
// switching order to go to little endian
|
||||
targetView.setInt32(position + 0, (highInt >>> 4) | 0x10000000);
|
||||
targetView.setInt32(position + 4, (lowInt >>> 4) | (highInt << 28));
|
||||
// if (length == 9 || nullTerminate)
|
||||
targetView.setInt32(position + 8, (lowInt & 0xf) << 4, true);
|
||||
return position + length;
|
||||
case 'object':
|
||||
if (key) {
|
||||
if (Array.isArray(key)) {
|
||||
for (let i = 0, l = key.length; i < l; i++) {
|
||||
if (i > 0)
|
||||
target[position++] = 0;
|
||||
position = writeKey(key[i], target, position, true);
|
||||
}
|
||||
break
|
||||
} else if (key instanceof Uint8Array) {
|
||||
target.set(key, position);
|
||||
position += key.length;
|
||||
break
|
||||
} else {
|
||||
throw new Error('Unable to serialize object as a key: ' + JSON.stringify(key))
|
||||
}
|
||||
} else // null
|
||||
target[position++] = 0;
|
||||
break
|
||||
case 'boolean':
|
||||
targetView.setUint32(position++, key ? 7 : 6, true);
|
||||
return position
|
||||
case 'bigint':
|
||||
let asFloat = Number(key);
|
||||
if (BigInt(asFloat) > key) {
|
||||
float64Array[0] = asFloat;
|
||||
if (asFloat > 0) {
|
||||
if (int32Array[0])
|
||||
int32Array[0]--;
|
||||
else {
|
||||
int32Array[1]--;
|
||||
int32Array[0] = 0xffffffff;
|
||||
}
|
||||
} else {
|
||||
if (int32Array[0] < 0xffffffff)
|
||||
int32Array[0]++;
|
||||
else {
|
||||
int32Array[1]++;
|
||||
int32Array[0] = 0;
|
||||
}
|
||||
}
|
||||
asFloat = float64Array[0];
|
||||
}
|
||||
let difference = key - BigInt(asFloat);
|
||||
if (difference === 0n)
|
||||
return writeKey(asFloat, target, position, inSequence)
|
||||
writeKey(asFloat, target, position, inSequence);
|
||||
position += 9; // always increment by 9 if we are adding fractional bits
|
||||
let exponent = BigInt((int32Array[1] >> 20 & 0x7ff) - 1079);
|
||||
let nextByte = difference >> exponent;
|
||||
target[position - 1] |= Number(nextByte);
|
||||
difference -= nextByte << exponent;
|
||||
let first = true;
|
||||
while (difference || first) {
|
||||
first = false;
|
||||
exponent -= 7n;
|
||||
let nextByte = difference >> exponent;
|
||||
target[position++] = Number(nextByte) | 0x80;
|
||||
difference -= nextByte << exponent;
|
||||
}
|
||||
return position;
|
||||
case 'undefined':
|
||||
return position
|
||||
// undefined is interpreted as the absence of a key, signified by zero length
|
||||
case 'symbol':
|
||||
target[position++] = 2;
|
||||
return writeKey(key.description, target, position, inSequence)
|
||||
default:
|
||||
throw new Error('Can not serialize key of type ' + typeof key)
|
||||
}
|
||||
if (nullTerminate && !inSequence)
|
||||
targetView.setUint32(position, 0);
|
||||
return position
|
||||
}
|
||||
|
||||
let position;
|
||||
function readKey(buffer, start, end, inSequence) {
|
||||
buffer[end] = 0; // make sure it is null terminated
|
||||
position = start;
|
||||
let controlByte = buffer[position];
|
||||
let value;
|
||||
if (controlByte < 24) {
|
||||
if (controlByte < 8) {
|
||||
position++;
|
||||
if (controlByte == 6) {
|
||||
value = false;
|
||||
} else if (controlByte == 7) {
|
||||
value = true;
|
||||
} else if (controlByte == 0) {
|
||||
value = null;
|
||||
} else if (controlByte == 2) {
|
||||
value = Symbol.for(readString(buffer));
|
||||
} else
|
||||
return Uint8Array.prototype.slice.call(buffer, start, end)
|
||||
} else {
|
||||
let dataView;
|
||||
try {
|
||||
dataView = buffer.dataView || (buffer.dataView = new DataView(buffer.buffer, buffer.byteOffset, ((buffer.byteLength + 3) >> 2) << 2));
|
||||
} catch(error) {
|
||||
// if it is write at the end of the ArrayBuffer, we may need to retry with the exact remaining bytes
|
||||
dataView = buffer.dataView || (buffer.dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.buffer.byteLength - buffer.byteOffset));
|
||||
}
|
||||
|
||||
let highInt = dataView.getInt32(position) << 4;
|
||||
let size = end - position;
|
||||
let lowInt;
|
||||
if (size > 4) {
|
||||
lowInt = dataView.getInt32(position + 4);
|
||||
highInt |= lowInt >>> 28;
|
||||
if (size <= 6) { // clear the last bits
|
||||
lowInt &= -0x1000;
|
||||
}
|
||||
lowInt = lowInt << 4;
|
||||
if (size > 8) {
|
||||
lowInt = lowInt | buffer[position + 8] >> 4;
|
||||
}
|
||||
} else
|
||||
lowInt = 0;
|
||||
if (controlByte < 16) {
|
||||
// negative gets negated
|
||||
highInt = highInt ^ 0x7fffffff;
|
||||
lowInt = ~lowInt;
|
||||
}
|
||||
int32Array[1] = highInt;
|
||||
int32Array[0] = lowInt;
|
||||
value = float64Array[0];
|
||||
position += 9;
|
||||
if (size > 9 && buffer[position] > 0) {
|
||||
// convert the float to bigint, and then we will add precision as we enumerate through the
|
||||
// extra bytes
|
||||
value = BigInt(value);
|
||||
let exponent = highInt >> 20 & 0x7ff;
|
||||
let next_byte = buffer[position - 1] & 0xf;
|
||||
value += BigInt(next_byte) << BigInt(exponent - 1079);
|
||||
while ((next_byte = buffer[position]) > 0 && position++ < end) {
|
||||
value += BigInt(next_byte & 0x7f) << BigInt((start - position) * 7 + exponent - 1016);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (controlByte == 27) {
|
||||
position++;
|
||||
}
|
||||
value = readString(buffer);
|
||||
/*let strStart = position
|
||||
let strEnd = end
|
||||
for (; position < end; position++) {
|
||||
if (buffer[position] == 0) {
|
||||
break
|
||||
}
|
||||
}
|
||||
value = buffer.toString('utf8', strStart, position++)*/
|
||||
}
|
||||
while (position < end) {
|
||||
if (buffer[position] === 0)
|
||||
position++;
|
||||
if (inSequence) {
|
||||
encoder.position = position;
|
||||
return value
|
||||
}
|
||||
let nextValue = readKey(buffer, position, end, true);
|
||||
if (value instanceof Array) {
|
||||
value.push(nextValue);
|
||||
} else
|
||||
value = [ value, nextValue ];
|
||||
}
|
||||
return value
|
||||
}
|
||||
const enableNullTermination = () => nullTerminate = true;
|
||||
|
||||
const encoder = {
|
||||
writeKey,
|
||||
readKey,
|
||||
enableNullTermination,
|
||||
};
|
||||
let targetBuffer = [];
|
||||
let targetPosition = 0;
|
||||
const hasNodeBuffer = typeof Buffer !== 'undefined';
|
||||
const ByteArrayAllocate = hasNodeBuffer ? Buffer.allocUnsafeSlow : Uint8Array;
|
||||
const toBufferKey = (key) => {
|
||||
let newBuffer;
|
||||
if (targetPosition + 100 > targetBuffer.length) {
|
||||
targetBuffer = new ByteArrayAllocate(8192);
|
||||
targetPosition = 0;
|
||||
newBuffer = true;
|
||||
}
|
||||
try {
|
||||
let result = targetBuffer.slice(targetPosition, targetPosition = writeKey(key, targetBuffer, targetPosition));
|
||||
if (targetPosition > targetBuffer.length) {
|
||||
if (newBuffer)
|
||||
throw new Error('Key is too large')
|
||||
return toBufferKey(key)
|
||||
}
|
||||
return result
|
||||
} catch(error) {
|
||||
if (newBuffer)
|
||||
throw error
|
||||
targetPosition = targetBuffer.length;
|
||||
return toBufferKey(key)
|
||||
}
|
||||
};
|
||||
const fromBufferKey = (sourceBuffer) => {
|
||||
return readKey(sourceBuffer, 0, sourceBuffer.length)
|
||||
};
|
||||
const fromCharCode = String.fromCharCode;
|
||||
function makeStringBuilder() {
|
||||
let stringBuildCode = '(source) => {';
|
||||
let previous = [];
|
||||
for (let i = 0; i < 0x30; i++) {
|
||||
let v = fromCharCode((i & 0xf) + 97) + fromCharCode((i >> 4) + 97);
|
||||
stringBuildCode += `
|
||||
let ${v} = source[position++]
|
||||
if (${v} > 4) {
|
||||
if (${v} >= 0x80) ${v} = finishUtf8(${v}, source)
|
||||
} else {
|
||||
if (${v} === 4)
|
||||
${v} = source[position++]
|
||||
else
|
||||
return fromCharCode(${previous})
|
||||
}
|
||||
`;
|
||||
previous.push(v);
|
||||
if (i == 1000000) // this just exists to prevent rollup from doing dead code elimination on finishUtf8
|
||||
finishUtf8();
|
||||
}
|
||||
stringBuildCode += `return fromCharCode(${previous}) + readString(source)}`;
|
||||
return stringBuildCode
|
||||
}
|
||||
|
||||
let pendingSurrogate;
|
||||
function finishUtf8(byte1, src) {
|
||||
if ((byte1 & 0xe0) === 0xc0) {
|
||||
// 2 bytes
|
||||
const byte2 = src[position++] & 0x3f;
|
||||
return ((byte1 & 0x1f) << 6) | byte2
|
||||
} else if ((byte1 & 0xf0) === 0xe0) {
|
||||
// 3 bytes
|
||||
const byte2 = src[position++] & 0x3f;
|
||||
const byte3 = src[position++] & 0x3f;
|
||||
return ((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3
|
||||
} else if ((byte1 & 0xf8) === 0xf0) {
|
||||
// 4 bytes
|
||||
if (pendingSurrogate) {
|
||||
byte1 = pendingSurrogate;
|
||||
pendingSurrogate = null;
|
||||
position += 3;
|
||||
return byte1
|
||||
}
|
||||
const byte2 = src[position++] & 0x3f;
|
||||
const byte3 = src[position++] & 0x3f;
|
||||
const byte4 = src[position++] & 0x3f;
|
||||
let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
|
||||
if (unit > 0xffff) {
|
||||
pendingSurrogate = 0xdc00 | (unit & 0x3ff);
|
||||
unit = (((unit - 0x10000) >>> 10) & 0x3ff) | 0xd800;
|
||||
position -= 4; // reset so we can return the next part of the surrogate pair
|
||||
}
|
||||
return unit
|
||||
} else {
|
||||
return byte1
|
||||
}
|
||||
}
|
||||
|
||||
const readString =
|
||||
typeof process !== 'undefined' && process.isBun ? // the eval in bun doesn't properly closure on position, so we
|
||||
// have to manually update it
|
||||
(function(reading) {
|
||||
let { setPosition, getPosition, readString } = reading;
|
||||
return (source) => {
|
||||
setPosition(position);
|
||||
let value = readString(source);
|
||||
position = getPosition();
|
||||
return value;
|
||||
};
|
||||
})((new Function('fromCharCode', 'let position; let readString = ' + makeStringBuilder() +
|
||||
';return {' +
|
||||
'setPosition(p) { position = p },' +
|
||||
'getPosition() { return position },' +
|
||||
'readString }'))(fromCharCode)) :
|
||||
eval(makeStringBuilder());
|
||||
|
||||
function compareKeys(a, b) {
|
||||
// compare with type consistency that matches binary comparison
|
||||
if (typeof a == 'object') {
|
||||
if (!a) {
|
||||
return b == null ? 0 : -1
|
||||
}
|
||||
if (a.compare) {
|
||||
if (b == null) {
|
||||
return 1
|
||||
} else if (b.compare) {
|
||||
return a.compare(b)
|
||||
} else {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
let arrayComparison;
|
||||
if (b instanceof Array) {
|
||||
let i = 0;
|
||||
while((arrayComparison = compareKeys(a[i], b[i])) == 0 && i <= a.length) {
|
||||
i++;
|
||||
}
|
||||
return arrayComparison
|
||||
}
|
||||
arrayComparison = compareKeys(a[0], b);
|
||||
if (arrayComparison == 0 && a.length > 1)
|
||||
return 1
|
||||
return arrayComparison
|
||||
} else if (typeof a == typeof b) {
|
||||
if (typeof a === 'symbol') {
|
||||
a = Symbol.keyFor(a);
|
||||
b = Symbol.keyFor(b);
|
||||
}
|
||||
return a < b ? -1 : a === b ? 0 : 1
|
||||
}
|
||||
else if (typeof b == 'object') {
|
||||
if (b instanceof Array)
|
||||
return -compareKeys(b, a)
|
||||
return 1
|
||||
} else {
|
||||
return typeOrder[typeof a] < typeOrder[typeof b] ? -1 : 1
|
||||
}
|
||||
}
|
||||
const typeOrder = {
|
||||
symbol: 0,
|
||||
undefined: 1,
|
||||
boolean: 2,
|
||||
number: 3,
|
||||
string: 4
|
||||
};
|
||||
const MINIMUM_KEY = null;
|
||||
const MAXIMUM_KEY = new Uint8Array([0xff]);
|
||||
|
||||
exports.MAXIMUM_KEY = MAXIMUM_KEY;
|
||||
exports.MINIMUM_KEY = MINIMUM_KEY;
|
||||
exports.compareKeys = compareKeys;
|
||||
exports.enableNullTermination = enableNullTermination;
|
||||
exports.encoder = encoder;
|
||||
exports.fromBufferKey = fromBufferKey;
|
||||
exports.readKey = readKey;
|
||||
exports.toBufferKey = toBufferKey;
|
||||
exports.writeKey = writeKey;
|
||||
23
webGl/my-threejs-test/node_modules/ordered-binary/index.d.ts
generated
vendored
Normal file
23
webGl/my-threejs-test/node_modules/ordered-binary/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
type Key = Key[] | string | symbol | number | boolean | Uint8Array;
|
||||
/** Writes a key (a primitive value) to the target buffer, starting at the given position */
|
||||
export function writeKey(key: Key, target: Uint8Array, position: number, inSequence?: boolean): number;
|
||||
/** Reads a key from the provided buffer, from the given range */
|
||||
export function readKey(buffer: Uint8Array, start: number, end?: number, inSequence?: boolean): Key;
|
||||
/** Converts key to a Buffer. This is generally much slower than using writeKey since it involves a full buffer allocation, and should be avoided for performance sensitive code. */
|
||||
export function toBufferKey(key: Key): Buffer;
|
||||
/** Converts Buffer to Key */
|
||||
export function fromBufferKey(source: Buffer): Key;
|
||||
/** Compares two keys, returning -1 if `a` comes before `b` in the ordered binary representation of the keys, or 1 if `a` comes after `b`, or 0 if they are equivalent */
|
||||
export function compareKeys(a: Key, b: Key): number;
|
||||
/** The minimum key, with the "first" binary representation (one byte of zero) */
|
||||
export const MINIMUM_KEY: null
|
||||
/** A maximum key, with a binary representation after all other JS primitives (one byte of 0xff) */
|
||||
export const MAXIMUM_KEY: Uint8Array
|
||||
/** Enables null termination, ensuring that writing keys to buffers will end with a padding of zeros at the end to complete the following 32-bit word */
|
||||
export function enableNullTermination(): void;
|
||||
/** An object that holds the functions for encapsulation as a single encoder */
|
||||
export const encoder: {
|
||||
writeKey: typeof writeKey,
|
||||
readKey: typeof readKey,
|
||||
enableNullTermination: typeof enableNullTermination,
|
||||
}
|
||||
432
webGl/my-threejs-test/node_modules/ordered-binary/index.js
generated
vendored
Normal file
432
webGl/my-threejs-test/node_modules/ordered-binary/index.js
generated
vendored
Normal file
@@ -0,0 +1,432 @@
|
||||
/*
|
||||
control character types:
|
||||
1 - metadata
|
||||
2 - symbols
|
||||
6 - false
|
||||
7 - true
|
||||
8- 16 - negative doubles
|
||||
16-24 positive doubles
|
||||
27 - String starts with a character 27 or less or is an empty string
|
||||
0 - multipart separator
|
||||
> 27 normal string characters
|
||||
*/
|
||||
/*
|
||||
* Convert arbitrary scalar values to buffer bytes with type preservation and type-appropriate ordering
|
||||
*/
|
||||
|
||||
import exp from "constants"
|
||||
|
||||
const float64Array = new Float64Array(2)
|
||||
const int32Array = new Int32Array(float64Array.buffer, 0, 4)
|
||||
let nullTerminate = false
|
||||
let textEncoder
|
||||
try {
|
||||
textEncoder = new TextEncoder()
|
||||
} catch (error) {}
|
||||
|
||||
/*
|
||||
* Convert arbitrary scalar values to buffer bytes with type preservation and type-appropriate ordering
|
||||
*/
|
||||
export function writeKey(key, target, position, inSequence) {
|
||||
let targetView = target.dataView
|
||||
if (!targetView)
|
||||
targetView = target.dataView = new DataView(target.buffer, target.byteOffset, ((target.byteLength + 3) >> 2) << 2)
|
||||
switch (typeof key) {
|
||||
case 'string':
|
||||
let strLength = key.length
|
||||
let c1 = key.charCodeAt(0)
|
||||
if (!(c1 >= 28)) // escape character
|
||||
target[position++] = 27
|
||||
if (strLength < 0x40) {
|
||||
let i, c2
|
||||
for (i = 0; i < strLength; i++) {
|
||||
c1 = key.charCodeAt(i)
|
||||
if (c1 <= 4) {
|
||||
target[position++] = 4
|
||||
target[position++] = c1
|
||||
} else if (c1 < 0x80) {
|
||||
target[position++] = c1
|
||||
} else if (c1 < 0x800) {
|
||||
target[position++] = c1 >> 6 | 0xc0
|
||||
target[position++] = c1 & 0x3f | 0x80
|
||||
} else if (
|
||||
(c1 & 0xfc00) === 0xd800 &&
|
||||
((c2 = key.charCodeAt(i + 1)) & 0xfc00) === 0xdc00
|
||||
) {
|
||||
c1 = 0x10000 + ((c1 & 0x03ff) << 10) + (c2 & 0x03ff)
|
||||
i++
|
||||
target[position++] = c1 >> 18 | 0xf0
|
||||
target[position++] = c1 >> 12 & 0x3f | 0x80
|
||||
target[position++] = c1 >> 6 & 0x3f | 0x80
|
||||
target[position++] = c1 & 0x3f | 0x80
|
||||
} else {
|
||||
target[position++] = c1 >> 12 | 0xe0
|
||||
target[position++] = c1 >> 6 & 0x3f | 0x80
|
||||
target[position++] = c1 & 0x3f | 0x80
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (target.utf8Write)
|
||||
position += target.utf8Write(key, position, 0xffffffff)
|
||||
else
|
||||
position += textEncoder.encodeInto(key, target.subarray(position)).written
|
||||
if (position > target.length - 4)
|
||||
throw new RangeError('String does not fit in target buffer')
|
||||
}
|
||||
break
|
||||
case 'number':
|
||||
float64Array[0] = key
|
||||
let lowInt = int32Array[0]
|
||||
let highInt = int32Array[1]
|
||||
let length
|
||||
if (key < 0) {
|
||||
targetView.setInt32(position + 4, ~((lowInt >>> 4) | (highInt << 28)))
|
||||
targetView.setInt32(position + 0, (highInt ^ 0x7fffffff) >>> 4)
|
||||
targetView.setInt32(position + 8, ((lowInt & 0xf) ^ 0xf) << 4, true) // just always do the null termination here
|
||||
return position + 9
|
||||
} else if ((lowInt & 0xf) || inSequence) {
|
||||
length = 9
|
||||
} else if (lowInt & 0xfffff)
|
||||
length = 8
|
||||
else if (lowInt || (highInt & 0xf))
|
||||
length = 6
|
||||
else
|
||||
length = 4
|
||||
// switching order to go to little endian
|
||||
targetView.setInt32(position + 0, (highInt >>> 4) | 0x10000000)
|
||||
targetView.setInt32(position + 4, (lowInt >>> 4) | (highInt << 28))
|
||||
// if (length == 9 || nullTerminate)
|
||||
targetView.setInt32(position + 8, (lowInt & 0xf) << 4, true)
|
||||
return position + length;
|
||||
case 'object':
|
||||
if (key) {
|
||||
if (Array.isArray(key)) {
|
||||
for (let i = 0, l = key.length; i < l; i++) {
|
||||
if (i > 0)
|
||||
target[position++] = 0
|
||||
position = writeKey(key[i], target, position, true)
|
||||
}
|
||||
break
|
||||
} else if (key instanceof Uint8Array) {
|
||||
target.set(key, position)
|
||||
position += key.length
|
||||
break
|
||||
} else {
|
||||
throw new Error('Unable to serialize object as a key: ' + JSON.stringify(key))
|
||||
}
|
||||
} else // null
|
||||
target[position++] = 0
|
||||
break
|
||||
case 'boolean':
|
||||
targetView.setUint32(position++, key ? 7 : 6, true)
|
||||
return position
|
||||
case 'bigint':
|
||||
let asFloat = Number(key)
|
||||
if (BigInt(asFloat) > key) {
|
||||
float64Array[0] = asFloat;
|
||||
if (asFloat > 0) {
|
||||
if (int32Array[0])
|
||||
int32Array[0]--;
|
||||
else {
|
||||
int32Array[1]--;
|
||||
int32Array[0] = 0xffffffff;
|
||||
}
|
||||
} else {
|
||||
if (int32Array[0] < 0xffffffff)
|
||||
int32Array[0]++;
|
||||
else {
|
||||
int32Array[1]++;
|
||||
int32Array[0] = 0;
|
||||
}
|
||||
}
|
||||
asFloat = float64Array[0];
|
||||
}
|
||||
let difference = key - BigInt(asFloat);
|
||||
if (difference === 0n)
|
||||
return writeKey(asFloat, target, position, inSequence)
|
||||
writeKey(asFloat, target, position, inSequence)
|
||||
position += 9; // always increment by 9 if we are adding fractional bits
|
||||
let exponent = BigInt((int32Array[1] >> 20 & 0x7ff) - 1079);
|
||||
let nextByte = difference >> exponent;
|
||||
target[position - 1] |= Number(nextByte);
|
||||
difference -= nextByte << exponent;
|
||||
let first = true;
|
||||
while (difference || first) {
|
||||
first = false;
|
||||
exponent -= 7n;
|
||||
let nextByte = difference >> exponent;
|
||||
target[position++] = Number(nextByte) | 0x80;
|
||||
difference -= nextByte << exponent;
|
||||
}
|
||||
return position;
|
||||
case 'undefined':
|
||||
return position
|
||||
// undefined is interpreted as the absence of a key, signified by zero length
|
||||
case 'symbol':
|
||||
target[position++] = 2
|
||||
return writeKey(key.description, target, position, inSequence)
|
||||
default:
|
||||
throw new Error('Can not serialize key of type ' + typeof key)
|
||||
}
|
||||
if (nullTerminate && !inSequence)
|
||||
targetView.setUint32(position, 0)
|
||||
return position
|
||||
}
|
||||
|
||||
let position
|
||||
export function readKey(buffer, start, end, inSequence) {
|
||||
buffer[end] = 0 // make sure it is null terminated
|
||||
position = start
|
||||
let controlByte = buffer[position]
|
||||
let value
|
||||
if (controlByte < 24) {
|
||||
if (controlByte < 8) {
|
||||
position++
|
||||
if (controlByte == 6) {
|
||||
value = false
|
||||
} else if (controlByte == 7) {
|
||||
value = true
|
||||
} else if (controlByte == 0) {
|
||||
value = null
|
||||
} else if (controlByte == 2) {
|
||||
value = Symbol.for(readString(buffer))
|
||||
} else
|
||||
return Uint8Array.prototype.slice.call(buffer, start, end)
|
||||
} else {
|
||||
let dataView;
|
||||
try {
|
||||
dataView = buffer.dataView || (buffer.dataView = new DataView(buffer.buffer, buffer.byteOffset, ((buffer.byteLength + 3) >> 2) << 2))
|
||||
} catch(error) {
|
||||
// if it is write at the end of the ArrayBuffer, we may need to retry with the exact remaining bytes
|
||||
dataView = buffer.dataView || (buffer.dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.buffer.byteLength - buffer.byteOffset))
|
||||
}
|
||||
|
||||
let highInt = dataView.getInt32(position) << 4
|
||||
let size = end - position
|
||||
let lowInt
|
||||
if (size > 4) {
|
||||
lowInt = dataView.getInt32(position + 4)
|
||||
highInt |= lowInt >>> 28
|
||||
if (size <= 6) { // clear the last bits
|
||||
lowInt &= -0x1000
|
||||
}
|
||||
lowInt = lowInt << 4
|
||||
if (size > 8) {
|
||||
lowInt = lowInt | buffer[position + 8] >> 4
|
||||
}
|
||||
} else
|
||||
lowInt = 0
|
||||
if (controlByte < 16) {
|
||||
// negative gets negated
|
||||
highInt = highInt ^ 0x7fffffff
|
||||
lowInt = ~lowInt
|
||||
}
|
||||
int32Array[1] = highInt
|
||||
int32Array[0] = lowInt
|
||||
value = float64Array[0]
|
||||
position += 9
|
||||
if (size > 9 && buffer[position] > 0) {
|
||||
// convert the float to bigint, and then we will add precision as we enumerate through the
|
||||
// extra bytes
|
||||
value = BigInt(value);
|
||||
let exponent = highInt >> 20 & 0x7ff;
|
||||
let next_byte = buffer[position - 1] & 0xf;
|
||||
value += BigInt(next_byte) << BigInt(exponent - 1079);
|
||||
while ((next_byte = buffer[position]) > 0 && position++ < end) {
|
||||
value += BigInt(next_byte & 0x7f) << BigInt((start - position) * 7 + exponent - 1016);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (controlByte == 27) {
|
||||
position++
|
||||
}
|
||||
value = readString(buffer)
|
||||
/*let strStart = position
|
||||
let strEnd = end
|
||||
for (; position < end; position++) {
|
||||
if (buffer[position] == 0) {
|
||||
break
|
||||
}
|
||||
}
|
||||
value = buffer.toString('utf8', strStart, position++)*/
|
||||
}
|
||||
while (position < end) {
|
||||
if (buffer[position] === 0)
|
||||
position++
|
||||
if (inSequence) {
|
||||
encoder.position = position
|
||||
return value
|
||||
}
|
||||
let nextValue = readKey(buffer, position, end, true)
|
||||
if (value instanceof Array) {
|
||||
value.push(nextValue)
|
||||
} else
|
||||
value = [ value, nextValue ]
|
||||
}
|
||||
return value
|
||||
}
|
||||
export const enableNullTermination = () => nullTerminate = true
|
||||
|
||||
export const encoder = {
|
||||
writeKey,
|
||||
readKey,
|
||||
enableNullTermination,
|
||||
}
|
||||
let targetBuffer = []
|
||||
let targetPosition = 0
|
||||
const hasNodeBuffer = typeof Buffer !== 'undefined'
|
||||
const ByteArrayAllocate = hasNodeBuffer ? Buffer.allocUnsafeSlow : Uint8Array
|
||||
export const toBufferKey = (key) => {
|
||||
let newBuffer
|
||||
if (targetPosition + 100 > targetBuffer.length) {
|
||||
targetBuffer = new ByteArrayAllocate(8192)
|
||||
targetPosition = 0
|
||||
newBuffer = true
|
||||
}
|
||||
try {
|
||||
let result = targetBuffer.slice(targetPosition, targetPosition = writeKey(key, targetBuffer, targetPosition))
|
||||
if (targetPosition > targetBuffer.length) {
|
||||
if (newBuffer)
|
||||
throw new Error('Key is too large')
|
||||
return toBufferKey(key)
|
||||
}
|
||||
return result
|
||||
} catch(error) {
|
||||
if (newBuffer)
|
||||
throw error
|
||||
targetPosition = targetBuffer.length
|
||||
return toBufferKey(key)
|
||||
}
|
||||
}
|
||||
export const fromBufferKey = (sourceBuffer) => {
|
||||
return readKey(sourceBuffer, 0, sourceBuffer.length)
|
||||
}
|
||||
const fromCharCode = String.fromCharCode
|
||||
function makeStringBuilder() {
|
||||
let stringBuildCode = '(source) => {'
|
||||
let previous = []
|
||||
for (let i = 0; i < 0x30; i++) {
|
||||
let v = fromCharCode((i & 0xf) + 97) + fromCharCode((i >> 4) + 97)
|
||||
stringBuildCode += `
|
||||
let ${v} = source[position++]
|
||||
if (${v} > 4) {
|
||||
if (${v} >= 0x80) ${v} = finishUtf8(${v}, source)
|
||||
} else {
|
||||
if (${v} === 4)
|
||||
${v} = source[position++]
|
||||
else
|
||||
return fromCharCode(${previous})
|
||||
}
|
||||
`
|
||||
previous.push(v)
|
||||
if (i == 1000000) // this just exists to prevent rollup from doing dead code elimination on finishUtf8
|
||||
finishUtf8()
|
||||
}
|
||||
stringBuildCode += `return fromCharCode(${previous}) + readString(source)}`
|
||||
return stringBuildCode
|
||||
}
|
||||
|
||||
let pendingSurrogate
|
||||
function finishUtf8(byte1, src) {
|
||||
if ((byte1 & 0xe0) === 0xc0) {
|
||||
// 2 bytes
|
||||
const byte2 = src[position++] & 0x3f
|
||||
return ((byte1 & 0x1f) << 6) | byte2
|
||||
} else if ((byte1 & 0xf0) === 0xe0) {
|
||||
// 3 bytes
|
||||
const byte2 = src[position++] & 0x3f
|
||||
const byte3 = src[position++] & 0x3f
|
||||
return ((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3
|
||||
} else if ((byte1 & 0xf8) === 0xf0) {
|
||||
// 4 bytes
|
||||
if (pendingSurrogate) {
|
||||
byte1 = pendingSurrogate
|
||||
pendingSurrogate = null
|
||||
position += 3
|
||||
return byte1
|
||||
}
|
||||
const byte2 = src[position++] & 0x3f
|
||||
const byte3 = src[position++] & 0x3f
|
||||
const byte4 = src[position++] & 0x3f
|
||||
let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4
|
||||
if (unit > 0xffff) {
|
||||
pendingSurrogate = 0xdc00 | (unit & 0x3ff)
|
||||
unit = (((unit - 0x10000) >>> 10) & 0x3ff) | 0xd800
|
||||
position -= 4 // reset so we can return the next part of the surrogate pair
|
||||
}
|
||||
return unit
|
||||
} else {
|
||||
return byte1
|
||||
}
|
||||
}
|
||||
|
||||
const readString =
|
||||
typeof process !== 'undefined' && process.isBun ? // the eval in bun doesn't properly closure on position, so we
|
||||
// have to manually update it
|
||||
(function(reading) {
|
||||
let { setPosition, getPosition, readString } = reading;
|
||||
return (source) => {
|
||||
setPosition(position);
|
||||
let value = readString(source);
|
||||
position = getPosition();
|
||||
return value;
|
||||
};
|
||||
})((new Function('fromCharCode', 'let position; let readString = ' + makeStringBuilder() +
|
||||
';return {' +
|
||||
'setPosition(p) { position = p },' +
|
||||
'getPosition() { return position },' +
|
||||
'readString }'))(fromCharCode)) :
|
||||
eval(makeStringBuilder())
|
||||
|
||||
export function compareKeys(a, b) {
|
||||
// compare with type consistency that matches binary comparison
|
||||
if (typeof a == 'object') {
|
||||
if (!a) {
|
||||
return b == null ? 0 : -1
|
||||
}
|
||||
if (a.compare) {
|
||||
if (b == null) {
|
||||
return 1
|
||||
} else if (b.compare) {
|
||||
return a.compare(b)
|
||||
} else {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
let arrayComparison
|
||||
if (b instanceof Array) {
|
||||
let i = 0
|
||||
while((arrayComparison = compareKeys(a[i], b[i])) == 0 && i <= a.length) {
|
||||
i++
|
||||
}
|
||||
return arrayComparison
|
||||
}
|
||||
arrayComparison = compareKeys(a[0], b)
|
||||
if (arrayComparison == 0 && a.length > 1)
|
||||
return 1
|
||||
return arrayComparison
|
||||
} else if (typeof a == typeof b) {
|
||||
if (typeof a === 'symbol') {
|
||||
a = Symbol.keyFor(a)
|
||||
b = Symbol.keyFor(b)
|
||||
}
|
||||
return a < b ? -1 : a === b ? 0 : 1
|
||||
}
|
||||
else if (typeof b == 'object') {
|
||||
if (b instanceof Array)
|
||||
return -compareKeys(b, a)
|
||||
return 1
|
||||
} else {
|
||||
return typeOrder[typeof a] < typeOrder[typeof b] ? -1 : 1
|
||||
}
|
||||
}
|
||||
const typeOrder = {
|
||||
symbol: 0,
|
||||
undefined: 1,
|
||||
boolean: 2,
|
||||
number: 3,
|
||||
string: 4
|
||||
}
|
||||
export const MINIMUM_KEY = null
|
||||
export const MAXIMUM_KEY = new Uint8Array([0xff])
|
||||
37
webGl/my-threejs-test/node_modules/ordered-binary/package.json
generated
vendored
Normal file
37
webGl/my-threejs-test/node_modules/ordered-binary/package.json
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "ordered-binary",
|
||||
"author": "Kris Zyp",
|
||||
"version": "1.5.1",
|
||||
"description": "Conversion of JavaScript primitives to and from Buffer with binary order matching natural primitive order",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "http://github.com/kriszyp/ordered-binary"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rollup -c",
|
||||
"prepare": "rollup -c",
|
||||
"test": "mocha tests -u tdd"
|
||||
},
|
||||
"type": "module",
|
||||
"main": "dist/index.cjs",
|
||||
"module": "index.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"require": "./dist/index.cjs",
|
||||
"import": "./index.js"
|
||||
},
|
||||
"./index.js": {
|
||||
"require": "./dist/index.cjs",
|
||||
"import": "./index.js"
|
||||
}
|
||||
},
|
||||
"typings": "./index.d.ts",
|
||||
"optionalDependencies": {},
|
||||
"devDependencies": {
|
||||
"@types/node": "latest",
|
||||
"chai": "^4",
|
||||
"mocha": "^9.2.0",
|
||||
"rollup": "^2.61.1"
|
||||
}
|
||||
}
|
||||
11
webGl/my-threejs-test/node_modules/ordered-binary/rollup.config.js
generated
vendored
Normal file
11
webGl/my-threejs-test/node_modules/ordered-binary/rollup.config.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export default [
|
||||
{
|
||||
input: "index.js",
|
||||
output: [
|
||||
{
|
||||
file: "dist/index.cjs",
|
||||
format: "cjs"
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
161
webGl/my-threejs-test/node_modules/ordered-binary/tests/test.js
generated
vendored
Normal file
161
webGl/my-threejs-test/node_modules/ordered-binary/tests/test.js
generated
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
import { assert } from 'chai'
|
||||
|
||||
import { toBufferKey, fromBufferKey, readKey, writeKey } from '../index.js'
|
||||
|
||||
function assertBufferComparison(lesser, greater) {
|
||||
for (let i = 0; i < lesser.length; i++) {
|
||||
if (lesser[i] < greater[i]) {
|
||||
return
|
||||
}
|
||||
if (lesser[i] > (greater[i] || 0)) {
|
||||
assert.fail('Byte ' + i + 'should not be ' + lesser[i] + '>' + greater[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
//var inspector = require('inspector'); inspector.open(9330, null, true); debugger
|
||||
let seed = 0;
|
||||
export function random() {
|
||||
seed++;
|
||||
let a = seed * 15485863;
|
||||
return ((a * a * a) % 2038074743) / 2038074743;
|
||||
}
|
||||
|
||||
suite('key buffers', () => {
|
||||
|
||||
test('numbers equivalence', () => {
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(4)), 4)
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(-4)), -4)
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(3.4)), 3.4)
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(Math.PI)), Math.PI)
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(9377288)), 9377288)
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(1503579323825)), 1503579323825)
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(1503579323825.3523532)), 1503579323825.3523532)
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(-1503579323825)), -1503579323825)
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(0.00005032)), 0.00005032)
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(-0.00005032)), -0.00005032)
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(0.00000000000000000000000005431)), 0.00000000000000000000000005431)
|
||||
})
|
||||
test('number comparison', () => {
|
||||
assertBufferComparison(toBufferKey(4), toBufferKey(5))
|
||||
assertBufferComparison(toBufferKey(1503579323824), toBufferKey(1503579323825))
|
||||
assertBufferComparison(toBufferKey(1.4), toBufferKey(2))
|
||||
assertBufferComparison(toBufferKey(0.000000001), toBufferKey(0.00000001))
|
||||
assertBufferComparison(toBufferKey(-4), toBufferKey(3))
|
||||
assertBufferComparison(toBufferKey(0), toBufferKey(1))
|
||||
assertBufferComparison(toBufferKey(-0.001), toBufferKey(0))
|
||||
assertBufferComparison(toBufferKey(-0.001), toBufferKey(-0.000001))
|
||||
assertBufferComparison(toBufferKey(-5236532532532), toBufferKey(-5236532532531))
|
||||
})
|
||||
test('bigint equivalence', () => {
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(-35913040084491349n)), -35913040084491349n)
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(6135421331404949076605986n)), 6135421331404949076605986n)
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(0xfffffffffffffffffffffn)), 0xfffffffffffffffffffffn)
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(12345678901234567890n)), 12345678901234567890n)
|
||||
assert.deepEqual(fromBufferKey(toBufferKey([12345678901234567890n, 44])), [12345678901234567890n, 44])
|
||||
assert.deepEqual(fromBufferKey(toBufferKey(['hi', 12345678901234567890n])), ['hi', 12345678901234567890n])
|
||||
assert.deepEqual(fromBufferKey(toBufferKey([6135421331404949076605986n, 'after'])), [6135421331404949076605986n, 'after'])
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(132923456789012345678903533235253252353211125n)), 132923456789012345678903533235253252353211125n)
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(352n)), 352)
|
||||
let num = 5325n
|
||||
for (let i = 0; i < 1100; i++) {
|
||||
num *= BigInt(Math.floor(random() * 3 + 1));
|
||||
num -= BigInt(Math.floor(random() * 1000));
|
||||
assert.strictEqual(BigInt(fromBufferKey(toBufferKey(num))), num)
|
||||
assert.strictEqual(BigInt(fromBufferKey(toBufferKey(-num))), -num)
|
||||
}
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(-352n)), -352)
|
||||
})
|
||||
test('bigint comparison', () => {
|
||||
assertBufferComparison(toBufferKey(0xfffffffffffffffffffffn), toBufferKey(0x100fffffffffffffffffffn))
|
||||
assertBufferComparison(toBufferKey(12345678901234567890), toBufferKey(12345678901234567890n))
|
||||
})
|
||||
|
||||
test('string equivalence', () => {
|
||||
assert.strictEqual(fromBufferKey(toBufferKey('4')), '4')
|
||||
assert.strictEqual(fromBufferKey(toBufferKey('hello')), 'hello')
|
||||
assert.strictEqual(fromBufferKey(toBufferKey('')), '')
|
||||
assert.strictEqual(fromBufferKey(toBufferKey('\x00')), '\x00')
|
||||
assert.strictEqual(fromBufferKey(toBufferKey('\x03test\x01\x00')), '\x03test\x01\x00')
|
||||
assert.strictEqual(fromBufferKey(toBufferKey('prance 🧚🏻♀️🩷')), 'prance 🧚🏻♀️🩷')
|
||||
})
|
||||
test('string comparison', () => {
|
||||
assertBufferComparison(toBufferKey('4'), toBufferKey('5'))
|
||||
assertBufferComparison(toBufferKey('and'), toBufferKey('bad'))
|
||||
assertBufferComparison(toBufferKey('hello'), toBufferKey('hello2'))
|
||||
let buffer = Buffer.alloc(1024)
|
||||
let end = writeKey(['this is a test', 5.25], buffer, 0)
|
||||
})
|
||||
test('boolean equivalence', () => {
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(true)), true)
|
||||
assert.strictEqual(fromBufferKey(toBufferKey(false)), false)
|
||||
})
|
||||
|
||||
test('multipart equivalence', () => {
|
||||
assert.deepEqual(fromBufferKey(toBufferKey([4, 5])),
|
||||
[4, 5])
|
||||
assert.deepEqual(fromBufferKey(toBufferKey(['hello', 5.25])),
|
||||
['hello', 5.25])
|
||||
assert.deepEqual(fromBufferKey(toBufferKey([true, 1503579323825])),
|
||||
[true, 1503579323825])
|
||||
assert.deepEqual(fromBufferKey(toBufferKey([-0.2525, 'sec\x00nd'])),
|
||||
[-0.2525, 'sec\x00nd'])
|
||||
assert.deepEqual(fromBufferKey(toBufferKey([-0.2525, '2nd', '3rd'])),
|
||||
[-0.2525, '2nd', '3rd'])
|
||||
})
|
||||
|
||||
test('multipart comparison', () => {
|
||||
assertBufferComparison(
|
||||
Buffer.concat([toBufferKey(4), Buffer.from([30]), toBufferKey(5)]),
|
||||
Buffer.concat([toBufferKey(5), Buffer.from([30]), toBufferKey(5)]))
|
||||
assertBufferComparison(
|
||||
Buffer.concat([toBufferKey(4), Buffer.from([30]), toBufferKey(5)]),
|
||||
Buffer.concat([toBufferKey(4), Buffer.from([30]), toBufferKey(6)]))
|
||||
assertBufferComparison(
|
||||
Buffer.concat([toBufferKey('and'), Buffer.from([30]), toBufferKey(5)]),
|
||||
Buffer.concat([toBufferKey('and2'), Buffer.from([30]), toBufferKey(5)]))
|
||||
assertBufferComparison(
|
||||
Buffer.concat([toBufferKey(4), Buffer.from([30]), toBufferKey('and')]),
|
||||
Buffer.concat([toBufferKey(4), Buffer.from([30]), toBufferKey('cat')]))
|
||||
})
|
||||
test('performance', () => {
|
||||
let buffer = Buffer.alloc(1024)
|
||||
let start = process.hrtime.bigint()
|
||||
let end, value
|
||||
for (let i = 0; i < 1000000; i++) {
|
||||
end = writeKey('this is a test of a longer string to read and write', buffer, 0)
|
||||
}
|
||||
console.log('writeKey string time', nextTime(), end)
|
||||
for (let i = 0; i < 1000000; i++) {
|
||||
value = readKey(buffer, 0, end)
|
||||
}
|
||||
console.log('readKey string time', nextTime(), value)
|
||||
|
||||
for (let i = 0; i < 1000000; i++) {
|
||||
end = writeKey(33456, buffer, 0)
|
||||
}
|
||||
console.log('writeKey number time', nextTime(), end)
|
||||
|
||||
for (let i = 0; i < 1000000; i++) {
|
||||
value = readKey(buffer, 2, end)
|
||||
}
|
||||
console.log('readKey number time', nextTime(), value)
|
||||
|
||||
for (let i = 0; i < 1000000; i++) {
|
||||
end = writeKey(['hello', 33456], buffer, 0)
|
||||
}
|
||||
console.log('writeKey array time', nextTime(), end, buffer.slice(0, end))
|
||||
|
||||
for (let i = 0; i < 1000000; i++) {
|
||||
value = readKey(buffer, 0, end)
|
||||
}
|
||||
console.log('readKey array time', nextTime(), value)
|
||||
|
||||
function nextTime() {
|
||||
let ns = process.hrtime.bigint()
|
||||
let elapsed = ns - start
|
||||
start = ns
|
||||
return Number(elapsed) / 1000000 + 'ns'
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user