@joycostudio/chopper 0.5.0 → 0.5.2
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 +19 -0
- package/codecs/manifest.json +1 -1
- package/dist/browser/{chunk-6WQPPVM2.js → chunk-C47JCVDL.js} +3 -3
- package/dist/browser/{chunk-6WQPPVM2.js.map → chunk-C47JCVDL.js.map} +1 -1
- package/dist/browser/{in-process-P6TQNY2L.js → in-process-Y2RGECEF.js} +46 -6
- package/dist/browser/in-process-Y2RGECEF.js.map +1 -0
- package/dist/browser/index.js +2 -2
- package/dist/browser/worker.js +49 -4
- package/dist/browser/worker.js.map +1 -1
- package/dist/cli/index.js +77 -10
- package/dist/cli/index.js.map +1 -1
- package/dist/config/index.d.ts +12 -3
- package/dist/config/index.js +20 -1
- package/dist/config/index.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +44 -4
- package/dist/index.js.map +1 -1
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +77 -10
- package/dist/node/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/browser/in-process-P6TQNY2L.js.map +0 -1
package/dist/browser/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { failure, CODEC_MANIFEST_HASH, CODEC_MANIFEST, ENGINE_ID } from './chunk-
|
|
1
|
+
import { failure, CODEC_MANIFEST_HASH, CODEC_MANIFEST, ENGINE_ID } from './chunk-C47JCVDL.js';
|
|
2
2
|
import './chunk-5WRI5ZAA.js';
|
|
3
3
|
|
|
4
4
|
// src/browser/chopper.ts
|
|
@@ -6,7 +6,7 @@ async function createBrowserChopper(options = {}) {
|
|
|
6
6
|
if ((options.execution ?? "worker") === "worker") {
|
|
7
7
|
return createWorkerChopper(options);
|
|
8
8
|
}
|
|
9
|
-
const { createInProcessChopper } = await import('./in-process-
|
|
9
|
+
const { createInProcessChopper } = await import('./in-process-Y2RGECEF.js');
|
|
10
10
|
return createInProcessChopper(options);
|
|
11
11
|
}
|
|
12
12
|
function createWorkerChopper(options) {
|
package/dist/browser/worker.js
CHANGED
|
@@ -49,7 +49,7 @@ var init_package = __esm({
|
|
|
49
49
|
"package.json"() {
|
|
50
50
|
package_default = {
|
|
51
51
|
name: "@joycostudio/chopper",
|
|
52
|
-
version: "0.5.
|
|
52
|
+
version: "0.5.2",
|
|
53
53
|
description: "Isomorphic asset optimization pipeline",
|
|
54
54
|
type: "module",
|
|
55
55
|
license: "ISC",
|
|
@@ -362,6 +362,16 @@ var init_recipes = __esm({
|
|
|
362
362
|
}
|
|
363
363
|
});
|
|
364
364
|
|
|
365
|
+
// src/core/object-validation.ts
|
|
366
|
+
function unknownFieldIssue(value, allowedFields, subject) {
|
|
367
|
+
const field = Object.keys(value).find((key) => !allowedFields.includes(key));
|
|
368
|
+
return field ? `Unknown ${subject} field: ${field}` : void 0;
|
|
369
|
+
}
|
|
370
|
+
var init_object_validation = __esm({
|
|
371
|
+
"src/core/object-validation.ts"() {
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
|
|
365
375
|
// src/core/validation.ts
|
|
366
376
|
function validateRecipe(recipe) {
|
|
367
377
|
const shapeIssue = recipeShapeIssue(recipe);
|
|
@@ -401,15 +411,26 @@ function recipeShapeIssue(recipe) {
|
|
|
401
411
|
return `Unsupported recipe kind: ${String(candidate.kind)}`;
|
|
402
412
|
}
|
|
403
413
|
if (candidate.kind === "image") {
|
|
414
|
+
const unknownField2 = unknownFieldIssue(candidate, ["kind", "encode"], "image recipe");
|
|
415
|
+
if (unknownField2) return unknownField2;
|
|
404
416
|
return encodingShapeIssue(candidate.encode);
|
|
405
417
|
}
|
|
418
|
+
const unknownField = unknownFieldIssue(candidate, ["kind", "methods", "textures", "geometry"], "GLB recipe");
|
|
419
|
+
if (unknownField) return unknownField;
|
|
406
420
|
if (candidate.methods !== void 0 && !Array.isArray(candidate.methods)) {
|
|
407
421
|
return "GLB methods must be an array";
|
|
408
422
|
}
|
|
409
423
|
for (const method of candidate.methods ?? []) {
|
|
410
|
-
if (!method || typeof method !== "object"
|
|
424
|
+
if (!method || typeof method !== "object") {
|
|
425
|
+
return "GLB methods contain an unsupported transform";
|
|
426
|
+
}
|
|
427
|
+
const entry = method;
|
|
428
|
+
if (!["dedup", "prune", "resample"].includes(String(entry.method))) {
|
|
411
429
|
return "GLB methods contain an unsupported transform";
|
|
412
430
|
}
|
|
431
|
+
const allowedFields = entry.method === "dedup" ? ["method", "keepUniqueNames", "propertyTypes"] : entry.method === "prune" ? ["method", "keepAttributes", "keepExtras", "keepLeaves", "keepSolidTextures", "propertyTypes"] : ["method", "tolerance", "cleanup"];
|
|
432
|
+
const unknownField2 = unknownFieldIssue(entry, allowedFields, "GLB method");
|
|
433
|
+
if (unknownField2) return unknownField2;
|
|
413
434
|
}
|
|
414
435
|
if (candidate.textures !== void 0 && !Array.isArray(candidate.textures)) {
|
|
415
436
|
return "GLB textures must be an array";
|
|
@@ -417,19 +438,32 @@ function recipeShapeIssue(recipe) {
|
|
|
417
438
|
for (const texture of candidate.textures ?? []) {
|
|
418
439
|
if (!texture || typeof texture !== "object") return "Texture recipes must be objects";
|
|
419
440
|
const entry = texture;
|
|
441
|
+
const unknownField2 = unknownFieldIssue(entry, ["label", "select", "encode"], "texture recipe");
|
|
442
|
+
if (unknownField2) return unknownField2;
|
|
420
443
|
if (typeof entry.label !== "string") return "Texture recipe labels must be strings";
|
|
421
444
|
if (!entry.select || typeof entry.select !== "object") return "Texture recipes require a selector";
|
|
422
445
|
const selector = entry.select;
|
|
423
|
-
|
|
424
|
-
if (!["slot", "name", "index"].includes(String(selector.by)) || !Array.isArray(values)) {
|
|
446
|
+
if (!["slot", "name", "index"].includes(String(selector.by))) {
|
|
425
447
|
return "Texture recipe selectors are malformed";
|
|
426
448
|
}
|
|
449
|
+
const valueField = selector.by === "slot" ? "slots" : selector.by === "name" ? "names" : "indices";
|
|
450
|
+
const selectorUnknownField = unknownFieldIssue(selector, ["by", valueField], "texture selector");
|
|
451
|
+
if (selectorUnknownField) return selectorUnknownField;
|
|
452
|
+
if (!Array.isArray(selector[valueField])) return "Texture recipe selectors are malformed";
|
|
427
453
|
const encodingIssue2 = encodingShapeIssue(entry.encode);
|
|
428
454
|
if (encodingIssue2) return encodingIssue2;
|
|
429
455
|
}
|
|
430
456
|
if (candidate.geometry !== void 0 && candidate.geometry !== false && (!candidate.geometry || typeof candidate.geometry !== "object" || !["draco", "meshopt"].includes(String(candidate.geometry.codec)))) {
|
|
431
457
|
return "GLB geometry must be false, Draco, or Meshopt";
|
|
432
458
|
}
|
|
459
|
+
if (candidate.geometry && typeof candidate.geometry === "object") {
|
|
460
|
+
const geometryUnknownField = unknownFieldIssue(
|
|
461
|
+
candidate.geometry,
|
|
462
|
+
["codec"],
|
|
463
|
+
"GLB geometry"
|
|
464
|
+
);
|
|
465
|
+
if (geometryUnknownField) return geometryUnknownField;
|
|
466
|
+
}
|
|
433
467
|
return void 0;
|
|
434
468
|
}
|
|
435
469
|
function encodingShapeIssue(encoding) {
|
|
@@ -444,6 +478,16 @@ function encodingShapeIssue(encoding) {
|
|
|
444
478
|
if (candidate.codec === "ktx2" && candidate.mode === "uastc-hdr" && candidate.maxSize !== void 0) {
|
|
445
479
|
return "UASTC HDR does not support maxSize; resizing requires a decoded 8-bit image. Author the source at its target resolution.";
|
|
446
480
|
}
|
|
481
|
+
const allowedFields = candidate.codec === "webp" ? ["codec", "maxSize", "quality", "effort", "lossless", "nearLossless"] : candidate.codec === "avif" ? ["codec", "maxSize", "quality", "effort", "lossless", "chromaSubsampling"] : candidate.codec === "jpeg" ? ["codec", "maxSize", "quality", "chromaSubsampling"] : candidate.codec === "png" ? ["codec", "maxSize"] : candidate.mode === "uastc" ? ["codec", "mode", "maxSize", "colorSpace", "normalMap", "level", "mipmaps", "zstd", "rdo"] : candidate.mode === "etc1s" ? ["codec", "mode", "maxSize", "colorSpace", "normalMap", "quality", "compression", "mipmaps"] : ["codec", "mode", "level", "mipmaps", "zstd"];
|
|
482
|
+
const unknownField = unknownFieldIssue(candidate, allowedFields, "image encoding");
|
|
483
|
+
if (unknownField) return unknownField;
|
|
484
|
+
if (candidate.codec === "ktx2" && candidate.mode === "uastc" && candidate.rdo !== void 0) {
|
|
485
|
+
if (!candidate.rdo || typeof candidate.rdo !== "object" || Array.isArray(candidate.rdo)) {
|
|
486
|
+
return "UASTC RDO must be an object";
|
|
487
|
+
}
|
|
488
|
+
const rdoUnknownField = unknownFieldIssue(candidate.rdo, ["lambda"], "UASTC RDO");
|
|
489
|
+
if (rdoUnknownField) return rdoUnknownField;
|
|
490
|
+
}
|
|
447
491
|
return void 0;
|
|
448
492
|
}
|
|
449
493
|
function recipeIssue(recipe) {
|
|
@@ -587,6 +631,7 @@ function normalizeEncoding(encoding) {
|
|
|
587
631
|
var init_validation = __esm({
|
|
588
632
|
"src/core/validation.ts"() {
|
|
589
633
|
init_result();
|
|
634
|
+
init_object_validation();
|
|
590
635
|
}
|
|
591
636
|
});
|
|
592
637
|
|