minerender 2.1.0-alpha.118 → 2.1.0-alpha.119

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.
@@ -16162,6 +16162,79 @@ function parseSceneDocument(value) {
16162
16162
  return JSON.parse(JSON.stringify(input));
16163
16163
  }
16164
16164
 
16165
+ // src/scene/SceneDocumentCodec.ts
16166
+ var SCENE_DOCUMENT_MAX_BYTES = 1024 * 1024;
16167
+ async function readBounded(stream, label) {
16168
+ const reader = stream.getReader();
16169
+ const chunks = [];
16170
+ let size = 0;
16171
+ try {
16172
+ while (true) {
16173
+ const { value, done } = await reader.read();
16174
+ if (done) break;
16175
+ size += value.byteLength;
16176
+ if (size > SCENE_DOCUMENT_MAX_BYTES) throw new RangeError(`${label} exceeds ${SCENE_DOCUMENT_MAX_BYTES} bytes`);
16177
+ chunks.push(value);
16178
+ }
16179
+ } catch (error) {
16180
+ await reader.cancel().catch(() => {
16181
+ });
16182
+ throw error;
16183
+ } finally {
16184
+ reader.releaseLock();
16185
+ }
16186
+ const bytes = new Uint8Array(size);
16187
+ let offset = 0;
16188
+ for (const chunk of chunks) {
16189
+ bytes.set(chunk, offset);
16190
+ offset += chunk.byteLength;
16191
+ }
16192
+ return bytes;
16193
+ }
16194
+ function encodeBase64(bytes) {
16195
+ let binary = "";
16196
+ for (let offset = 0; offset < bytes.length; offset += 32768) {
16197
+ binary += String.fromCharCode(...bytes.subarray(offset, offset + 32768));
16198
+ }
16199
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
16200
+ }
16201
+ async function encodeSceneDocument(value) {
16202
+ const scene = parseSceneDocument(value);
16203
+ const bytes = new TextEncoder().encode(JSON.stringify(scene));
16204
+ if (bytes.byteLength > SCENE_DOCUMENT_MAX_BYTES) {
16205
+ throw new RangeError(`Scene document exceeds ${SCENE_DOCUMENT_MAX_BYTES} bytes`);
16206
+ }
16207
+ const compressed = await readBounded(new Blob([bytes]).stream().pipeThrough(new CompressionStream("deflate")), "Encoded scene");
16208
+ return `v1.${encodeBase64(compressed)}`;
16209
+ }
16210
+ async function decodeSceneDocument(value) {
16211
+ if (!value.startsWith("v1.")) throw new Error("Unsupported scene encoding version; expected v1");
16212
+ const encoded = value.slice(3);
16213
+ if (encoded.length > Math.ceil(SCENE_DOCUMENT_MAX_BYTES * 4 / 3)) {
16214
+ throw new RangeError(`Encoded scene exceeds ${SCENE_DOCUMENT_MAX_BYTES} bytes`);
16215
+ }
16216
+ if (!/^[A-Za-z0-9_-]+$/.test(encoded) || encoded.length % 4 === 1) {
16217
+ throw new Error("Invalid scene base64url encoding");
16218
+ }
16219
+ const binary = atob(encoded.replace(/-/g, "+").replace(/_/g, "/"));
16220
+ const compressed = Uint8Array.from(binary, (character) => character.charCodeAt(0));
16221
+ if (encodeBase64(compressed) !== encoded) throw new Error("Invalid scene base64url encoding");
16222
+ let bytes;
16223
+ try {
16224
+ bytes = await readBounded(new Blob([compressed]).stream().pipeThrough(new DecompressionStream("deflate")), "Scene document");
16225
+ } catch (error) {
16226
+ if (error instanceof RangeError) throw error;
16227
+ throw new Error("Invalid compressed scene document");
16228
+ }
16229
+ let json;
16230
+ try {
16231
+ json = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
16232
+ } catch {
16233
+ throw new Error("Invalid UTF-8 scene document");
16234
+ }
16235
+ return parseSceneDocument(json);
16236
+ }
16237
+
16165
16238
  // src/scene/SceneDocumentLoader.ts
16166
16239
  init_AssetKey();
16167
16240
  init_AssetLoader();
@@ -19249,6 +19322,7 @@ export {
19249
19322
  Renderer,
19250
19323
  RequestError,
19251
19324
  Requests,
19325
+ SCENE_DOCUMENT_MAX_BYTES,
19252
19326
  SKIN_PARTS,
19253
19327
  SceneDocumentLoader,
19254
19328
  SceneExporter,
@@ -19300,6 +19374,8 @@ export {
19300
19374
  createGuiTextGeometry,
19301
19375
  createGuiTextureGeometry,
19302
19376
  createImage,
19377
+ decodeSceneDocument,
19378
+ encodeSceneDocument,
19303
19379
  entityAnimationTime,
19304
19380
  estimateBytesUsed,
19305
19381
  fluidKindOf,