poppygl 0.0.22 → 0.0.23
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/dist/index.js +51 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1612,10 +1612,50 @@ function createSceneFromGLTF(gltf, resources) {
|
|
|
1612
1612
|
// lib/gltf/resourceUtils.ts
|
|
1613
1613
|
import { PassThrough } from "readable-stream";
|
|
1614
1614
|
import * as PImage from "pureimage";
|
|
1615
|
+
|
|
1616
|
+
// lib/utils/bytes.ts
|
|
1617
|
+
function getNodeBuffer() {
|
|
1618
|
+
const maybeBuffer = globalThis.Buffer;
|
|
1619
|
+
if (!maybeBuffer) {
|
|
1620
|
+
throw new Error("Node Buffer API is not available in this runtime.");
|
|
1621
|
+
}
|
|
1622
|
+
return maybeBuffer;
|
|
1623
|
+
}
|
|
1624
|
+
function toUint8Array(chunk) {
|
|
1625
|
+
if (chunk instanceof Uint8Array) return chunk;
|
|
1626
|
+
if (chunk instanceof ArrayBuffer) return new Uint8Array(chunk);
|
|
1627
|
+
return new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
1628
|
+
}
|
|
1629
|
+
function concatUint8Arrays(chunks) {
|
|
1630
|
+
const totalLength = chunks.reduce((length, chunk) => length + chunk.length, 0);
|
|
1631
|
+
const result = new Uint8Array(totalLength);
|
|
1632
|
+
let offset = 0;
|
|
1633
|
+
for (const chunk of chunks) {
|
|
1634
|
+
result.set(chunk, offset);
|
|
1635
|
+
offset += chunk.length;
|
|
1636
|
+
}
|
|
1637
|
+
return result;
|
|
1638
|
+
}
|
|
1639
|
+
function base64ToUint8Array(base64) {
|
|
1640
|
+
if (typeof globalThis.atob === "function") {
|
|
1641
|
+
const binary = globalThis.atob(base64);
|
|
1642
|
+
const bytes = new Uint8Array(binary.length);
|
|
1643
|
+
for (let i = 0; i < binary.length; i++) {
|
|
1644
|
+
bytes[i] = binary.charCodeAt(i);
|
|
1645
|
+
}
|
|
1646
|
+
return bytes;
|
|
1647
|
+
}
|
|
1648
|
+
return new Uint8Array(getNodeBuffer().from(base64, "base64"));
|
|
1649
|
+
}
|
|
1650
|
+
function uint8ArrayToNodeBuffer(bytes) {
|
|
1651
|
+
return getNodeBuffer().from(bytes);
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
// lib/gltf/resourceUtils.ts
|
|
1615
1655
|
function bufferFromDataURI(uri) {
|
|
1616
1656
|
const match = uri.match(/^data:.*?;base64,(.*)$/);
|
|
1617
1657
|
if (!match) throw new Error(`Unsupported data URI: ${uri.slice(0, 64)}...`);
|
|
1618
|
-
return
|
|
1658
|
+
return base64ToUint8Array(match[1]);
|
|
1619
1659
|
}
|
|
1620
1660
|
function isPNG(filenameOrUri) {
|
|
1621
1661
|
return /\.png(\?|$)/i.test(filenameOrUri) || /image\/png/i.test(filenameOrUri);
|
|
@@ -1632,7 +1672,7 @@ function detectMimeTypeFromBuffer(buf, hint) {
|
|
|
1632
1672
|
}
|
|
1633
1673
|
function bufferToStream(buf) {
|
|
1634
1674
|
const stream = new PassThrough();
|
|
1635
|
-
stream.end(
|
|
1675
|
+
stream.end(buf);
|
|
1636
1676
|
return stream;
|
|
1637
1677
|
}
|
|
1638
1678
|
async function decodeImageFromBuffer(buf, mimeType) {
|
|
@@ -1808,11 +1848,16 @@ import * as PImage3 from "pureimage";
|
|
|
1808
1848
|
async function encodePNGToBuffer(image) {
|
|
1809
1849
|
const passThrough = new PassThrough2();
|
|
1810
1850
|
const chunks = [];
|
|
1811
|
-
passThrough.on(
|
|
1812
|
-
|
|
1813
|
-
|
|
1851
|
+
passThrough.on(
|
|
1852
|
+
"data",
|
|
1853
|
+
(chunk) => {
|
|
1854
|
+
chunks.push(toUint8Array(chunk));
|
|
1855
|
+
}
|
|
1856
|
+
);
|
|
1814
1857
|
const resultPromise = new Promise((resolve, reject) => {
|
|
1815
|
-
passThrough.on("end", () =>
|
|
1858
|
+
passThrough.on("end", () => {
|
|
1859
|
+
resolve(uint8ArrayToNodeBuffer(concatUint8Arrays(chunks)));
|
|
1860
|
+
});
|
|
1816
1861
|
passThrough.on("error", reject);
|
|
1817
1862
|
});
|
|
1818
1863
|
await PImage3.encodePNGToStream(image, passThrough);
|