@joycostudio/chopper 0.7.1 → 0.8.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.
@@ -156,7 +156,28 @@ interface UastcHdrEncoding {
156
156
  zstd?: boolean;
157
157
  }
158
158
  type RasterEncoding = WebpEncoding | AvifEncoding | JpegEncoding | PngEncoding;
159
- type ImageEncoding = RasterEncoding | UastcEncoding | Etc1sEncoding | UastcHdrEncoding;
159
+ /** Standalone, lossless RGBA8 texels. Color-space metadata never transforms samples. */
160
+ type RawKtx2Encoding = {
161
+ /** Store decoded RGBA8 pixels in KTX2. */
162
+ codec: 'ktx2';
163
+ /** Preserve original dimensions and every decoded RGBA8 byte, including transparent RGB. */
164
+ mode: 'raw';
165
+ /** Label unchanged samples; alpha is always linear. @defaultValue `'linear'` */
166
+ colorSpace?: 'linear' | 'srgb';
167
+ /** Raw mode stores exactly one base level. @defaultValue `false` */
168
+ mipmaps?: false;
169
+ } & ({
170
+ /** Compress the texels for delivery; GPU storage remains RGBA8. @defaultValue `true` */
171
+ zstd?: true;
172
+ /** Offline compression effort, integer 1–19; never changes fidelity. @defaultValue `19` */
173
+ zstdLevel?: number;
174
+ } | {
175
+ /** Store texels without supercompression. */
176
+ zstd: false;
177
+ /** Effort is unavailable when Zstandard is disabled. */
178
+ zstdLevel?: never;
179
+ });
180
+ type ImageEncoding = RasterEncoding | UastcEncoding | Etc1sEncoding | UastcHdrEncoding | RawKtx2Encoding;
160
181
  type GlbProperty = 'accessor' | 'animation' | 'buffer' | 'camera' | 'material' | 'mesh' | 'node' | 'primitive' | 'primitiveTarget' | 'skin' | 'texture';
161
182
  type GlbMethodRecipe = {
162
183
  /** Merge equivalent accessors, materials, meshes, skins, or textures. */
@@ -219,8 +240,8 @@ interface EmbeddedTextureRecipe {
219
240
  label: string;
220
241
  /** Textures to encode. A texture cannot be claimed by more than one selector. */
221
242
  select: TextureSelector;
222
- /** Output encoding for the selected textures. UASTC HDR is not supported inside GLBs. */
223
- encode: ImageEncoding;
243
+ /** Output encoding for the selected textures. Raw RGBA8 and UASTC HDR are not supported inside GLBs. */
244
+ encode: Exclude<ImageEncoding, RawKtx2Encoding>;
224
245
  }
225
246
  type GeometryEncoding = {
226
247
  /** Compress geometry with `KHR_draco_mesh_compression` for broad decoder support. */
@@ -280,32 +301,36 @@ interface ChopperRule {
280
301
  exclude?: readonly string[];
281
302
  /** Optimization recipe applied to every asset matched by this rule. */
282
303
  recipe: AssetRecipe;
283
- /**
284
- * Output path template relative to {@link ChopperConfig.output}. Supports
285
- * `{dir}` (source directory), `{name}` (source basename), and `{ext}`
286
- * (recipe output extension).
287
- *
288
- * @defaultValue `'{dir}/{name}.{ext}'`
289
- */
290
- path?: string;
291
304
  }
292
305
  interface ChopperConfig {
293
306
  /**
294
- * Filesystem root used by Node and the CLI for generated bytes. Relative
295
- * paths are resolved from the project directory, and the resolved directory
296
- * must remain inside the project. This directory is not included in
297
- * {@link PlannedConfigAsset.output}.
307
+ * Physical filesystem root where Node and the CLI write generated bytes.
308
+ * Relative paths are resolved from the project directory, and the resolved
309
+ * directory must remain inside the project. This build directory is never
310
+ * included in the logical paths returned by {@link ConfigAssetPlanner}.
311
+ *
312
+ * For example, a planned output of `assets/compressed/wall.webp` is written
313
+ * to `.chopper/assets/compressed/wall.webp` when this property uses its
314
+ * default. Use {@link outputDirectory} to control the reserved sibling
315
+ * segment in the planned path; use this property only to control where Node
316
+ * and the CLI store the resulting bytes.
298
317
  *
299
318
  * @defaultValue `'.chopper'`
300
319
  */
301
- output?: string;
320
+ buildDirectory?: string;
302
321
  /**
303
- * Reserved sibling directory used for logical generated asset paths.
322
+ * Reserved sibling directory segment used in logical generated asset paths.
304
323
  *
305
324
  * Given `assets/wall.png` and `outputDirectory: 'compressed'`, a WebP
306
325
  * recipe resolves to `assets/compressed/wall.webp`. Inputs already inside
307
326
  * this directory are classified as generated outputs and are never
308
- * processed again.
327
+ * processed again. Rules choose which assets and recipes apply; this
328
+ * config-level property is the sole authority for where their logical
329
+ * outputs go. This logical segment is independent of
330
+ * {@link buildDirectory}, the physical filesystem root used by Node and the
331
+ * CLI.
332
+ *
333
+ * @defaultValue `'compressed'`
309
334
  */
310
335
  outputDirectory?: string;
311
336
  /**
@@ -328,7 +353,7 @@ interface ChopperConfig {
328
353
  interface PlannedConfigAsset {
329
354
  /** Project-relative POSIX path tested against the config globs. */
330
355
  input: string;
331
- /** Logical generated asset path, relative to the filesystem output root. */
356
+ /** Logical generated asset path, relative to {@link ChopperConfig.buildDirectory} when written by Node. */
332
357
  output: string;
333
358
  /** The winning Chopper rule that produces this output. */
334
359
  rule: ChopperRule;
@@ -350,8 +375,9 @@ interface ConfigAssetPlanner {
350
375
  /** Plans one known project-relative asset without reading the filesystem. */
351
376
  resolve(input: string): ChopperResult<PlannedConfigAsset[]>;
352
377
  }
353
- type ConfiguredChopper<T extends ChopperConfig = ChopperConfig> = Omit<T, 'output'> & {
354
- output: T['output'] extends string ? T['output'] : string;
378
+ type ConfiguredChopper<T extends ChopperConfig = ChopperConfig> = Omit<T, 'buildDirectory' | 'outputDirectory'> & {
379
+ buildDirectory: T['buildDirectory'] extends string ? T['buildDirectory'] : string;
380
+ outputDirectory: T['outputDirectory'] extends string ? T['outputDirectory'] : string;
355
381
  } & ConfigAssetPlanner;
356
382
 
357
383
  /**
@@ -102,6 +102,9 @@ function recipeShapeIssue(recipe) {
102
102
  if (!Array.isArray(selector[valueField])) return "Texture recipe selectors are malformed";
103
103
  const encodingIssue2 = encodingShapeIssue(entry.encode);
104
104
  if (encodingIssue2) return encodingIssue2;
105
+ if (entry.encode.codec === "ktx2" && entry.encode.mode === "raw") {
106
+ return `Texture recipe "${entry.label}" uses raw RGBA8, which KHR_texture_basisu does not cover; raw mode is only supported for standalone image recipes`;
107
+ }
105
108
  }
106
109
  if (candidate.geometry !== void 0 && candidate.geometry !== false && (!candidate.geometry || typeof candidate.geometry !== "object" || !["draco", "meshopt"].includes(String(candidate.geometry.codec)))) {
107
110
  return "GLB geometry must be false, Draco, or Meshopt";
@@ -122,15 +125,18 @@ function encodingShapeIssue(encoding) {
122
125
  if (!["webp", "avif", "jpeg", "png", "ktx2"].includes(String(candidate.codec))) {
123
126
  return `Unsupported image codec: ${String(candidate.codec)}`;
124
127
  }
125
- if (candidate.codec === "ktx2" && candidate.mode !== "uastc" && candidate.mode !== "etc1s" && candidate.mode !== "uastc-hdr") {
128
+ if (candidate.codec === "ktx2" && candidate.mode !== "uastc" && candidate.mode !== "etc1s" && candidate.mode !== "raw" && candidate.mode !== "uastc-hdr") {
126
129
  return `Unsupported KTX2 mode: ${String(candidate.mode)}`;
127
130
  }
128
131
  if (candidate.codec === "ktx2" && candidate.mode === "uastc-hdr" && candidate.maxSize !== void 0) {
129
132
  return "UASTC HDR does not support maxSize; resizing requires a decoded 8-bit image. Author the source at its target resolution.";
130
133
  }
131
- 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"];
134
+ 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"] : candidate.mode === "raw" ? ["codec", "mode", "colorSpace", "mipmaps", "zstd", "zstdLevel"] : ["codec", "mode", "level", "mipmaps", "zstd"];
132
135
  const unknownField = unknownFieldIssue(candidate, allowedFields, "image encoding");
133
136
  if (unknownField) return unknownField;
137
+ if (candidate.codec === "ktx2" && candidate.mode === "raw" && candidate.zstd === false && candidate.zstdLevel !== void 0) {
138
+ return "Raw KTX2 zstdLevel requires Zstandard supercompression";
139
+ }
134
140
  if (candidate.codec === "ktx2" && candidate.mode === "uastc" && candidate.rdo !== void 0) {
135
141
  if (!candidate.rdo || typeof candidate.rdo !== "object" || Array.isArray(candidate.rdo)) {
136
142
  return "UASTC RDO must be an object";
@@ -186,6 +192,18 @@ function selectorValues(selector) {
186
192
  return success(selector.indices);
187
193
  }
188
194
  function encodingIssue(encoding) {
195
+ if (encoding.codec === "ktx2" && encoding.mode === "raw") {
196
+ if (encoding.colorSpace !== void 0 && encoding.colorSpace !== "linear" && encoding.colorSpace !== "srgb") {
197
+ return "Raw KTX2 colorSpace must be linear or srgb";
198
+ }
199
+ if (encoding.mipmaps !== void 0 && encoding.mipmaps !== false) return "Raw KTX2 mipmaps must be false";
200
+ if (encoding.zstd !== void 0 && typeof encoding.zstd !== "boolean") return "Raw KTX2 zstd must be a boolean";
201
+ if (encoding.zstdLevel !== void 0) {
202
+ if (!Number.isInteger(encoding.zstdLevel) || encoding.zstdLevel < 1 || encoding.zstdLevel > 19) {
203
+ return "Raw KTX2 zstdLevel must be an integer between 1 and 19";
204
+ }
205
+ }
206
+ }
189
207
  if ("maxSize" in encoding && encoding.maxSize) {
190
208
  const [width, height] = encoding.maxSize;
191
209
  if (!Number.isInteger(width) || width < 1 || !Number.isInteger(height) || height < 1) {
@@ -225,19 +243,27 @@ function encodingIssue(encoding) {
225
243
  }
226
244
 
227
245
  // src/config/validation.ts
228
- var DEFAULT_OUTPUT = ".chopper";
246
+ var DEFAULT_BUILD_DIRECTORY = ".chopper";
247
+ var DEFAULT_OUTPUT_DIRECTORY = "compressed";
229
248
  function validateConfig(config) {
230
249
  if (!config || typeof config !== "object" || Array.isArray(config)) {
231
250
  return failure("invalid_recipe", "Config must be an object");
232
251
  }
233
252
  const candidate = config;
234
- const unknownField = unknownFieldIssue(candidate, ["output", "outputDirectory", "rules", "concurrency"], "config");
253
+ const unknownField = unknownFieldIssue(
254
+ candidate,
255
+ ["buildDirectory", "outputDirectory", "rules", "concurrency"],
256
+ "config"
257
+ );
235
258
  if (unknownField) return failure("invalid_recipe", unknownField);
236
- if (candidate.output !== void 0 && (typeof candidate.output !== "string" || !candidate.output)) {
237
- return failure("invalid_recipe", "Config output must be a non-empty string");
259
+ if (candidate.buildDirectory !== void 0 && (typeof candidate.buildDirectory !== "string" || !candidate.buildDirectory)) {
260
+ return failure("invalid_recipe", "Config buildDirectory must be a non-empty string");
238
261
  }
239
- if (candidate.output !== void 0 && !isProjectRelativePath(candidate.output, true)) {
240
- return failure("invalid_recipe", `Output directory must be a project-relative POSIX path: ${candidate.output}`);
262
+ if (candidate.buildDirectory !== void 0 && !isProjectRelativePath(candidate.buildDirectory, true)) {
263
+ return failure(
264
+ "invalid_recipe",
265
+ `Build directory must be a project-relative POSIX path: ${candidate.buildDirectory}`
266
+ );
241
267
  }
242
268
  if (candidate.outputDirectory !== void 0 && !isSafePathSegment(candidate.outputDirectory)) {
243
269
  return failure(
@@ -256,7 +282,7 @@ function validateConfig(config) {
256
282
  return failure("invalid_recipe", `Config rule ${index} must be an object`);
257
283
  }
258
284
  const entry = rule;
259
- const ruleUnknownField = unknownFieldIssue(entry, ["include", "exclude", "recipe", "path"], `config rule ${index}`);
285
+ const ruleUnknownField = unknownFieldIssue(entry, ["include", "exclude", "recipe"], `config rule ${index}`);
260
286
  if (ruleUnknownField) return failure("invalid_recipe", ruleUnknownField);
261
287
  if (!isStringArray(entry.include)) {
262
288
  return failure("invalid_recipe", `Config rule ${index} include must be an array of glob patterns`);
@@ -270,19 +296,14 @@ function validateConfig(config) {
270
296
  if (invalidGlob) {
271
297
  return failure("invalid_recipe", `Config rule ${index} glob must be project-relative: ${invalidGlob}`);
272
298
  }
273
- if (entry.path !== void 0 && (typeof entry.path !== "string" || !entry.path)) {
274
- return failure("invalid_recipe", `Config rule ${index} path must be a non-empty string`);
275
- }
276
- if (candidate.outputDirectory !== void 0 && entry.path !== void 0) {
277
- return failure(
278
- "invalid_recipe",
279
- `Config rule ${index} path cannot be combined with outputDirectory; authoritative sibling output routing determines the output path`
280
- );
281
- }
282
299
  const recipe = validateRecipe(entry.recipe);
283
300
  if (!recipe.ok) return recipe;
284
301
  }
285
- return success({ ...config, output: candidate.output ?? DEFAULT_OUTPUT });
302
+ return success({
303
+ ...config,
304
+ buildDirectory: candidate.buildDirectory ?? DEFAULT_BUILD_DIRECTORY,
305
+ outputDirectory: candidate.outputDirectory ?? DEFAULT_OUTPUT_DIRECTORY
306
+ });
286
307
  }
287
308
  function normalizeProjectPath(path) {
288
309
  if (typeof path !== "string") return void 0;
@@ -348,15 +369,14 @@ function createConfigAssetPlanner(config) {
348
369
  if (!normalizedInput) {
349
370
  return failure("invalid_recipe", `Asset input must be a project-relative POSIX path: ${input}`);
350
371
  }
351
- if (prepared.data.outputDirectory && isGeneratedOutput(normalizedInput, prepared.data.outputDirectory)) {
372
+ if (isGeneratedOutput(normalizedInput, prepared.data.outputDirectory)) {
352
373
  return success({ kind: "output", input: normalizedInput });
353
374
  }
354
375
  const planned = /* @__PURE__ */ new Map();
355
376
  for (const { rule, matches } of prepared.data.rules) {
356
377
  if (!matches(normalizedInput)) continue;
357
378
  const output = resolveOutput(rule, normalizedInput, prepared.data.outputDirectory);
358
- if (!output.ok) return output;
359
- planned.set(output.data, { input: normalizedInput, output: output.data, rule });
379
+ planned.set(output, { input: normalizedInput, output, rule });
360
380
  }
361
381
  const outputs = [...planned.values()];
362
382
  return outputs.length ? success({ kind: "source", input: normalizedInput, outputs }) : success({ kind: "unmatched", input: normalizedInput });
@@ -406,19 +426,7 @@ function resolveOutput(rule, input, outputDirectory) {
406
426
  const dot = base.lastIndexOf(".");
407
427
  const name = dot <= 0 ? base : base.slice(0, dot);
408
428
  const extension = rule.recipe.kind === "glb" ? ".glb" : outputExtension(rule.recipe.encode);
409
- if (outputDirectory) {
410
- return success(`${directory ? `${directory}/` : ""}${outputDirectory}/${name}${extension}`);
411
- }
412
- const template = rule.path ?? "{dir}/{name}.{ext}";
413
- if (template.includes("\\") || template.startsWith("/") || /^[A-Za-z]:\//.test(template)) {
414
- return failure("invalid_recipe", `Output path must stay inside the configured output directory: ${template}`);
415
- }
416
- const rendered = template.replaceAll("{dir}/", directory ? `${directory}/` : "").replaceAll("{dir}", directory).replaceAll("{name}", name).replaceAll("{ext}", extension.slice(1));
417
- if (/\{[^{}]+\}/.test(rendered)) {
418
- return failure("invalid_recipe", `Output path contains an unsupported placeholder: ${template}`);
419
- }
420
- const output = normalizeProjectPath(rendered);
421
- return output ? success(output) : failure("invalid_recipe", `Output path must stay inside the configured output directory: ${template}`);
429
+ return `${directory ? `${directory}/` : ""}${outputDirectory}/${name}${extension}`;
422
430
  }
423
431
  function isGeneratedOutput(input, outputDirectory) {
424
432
  return input.split("/").slice(0, -1).includes(outputDirectory);
@@ -426,8 +434,8 @@ function isGeneratedOutput(input, outputDirectory) {
426
434
 
427
435
  // src/config/index.ts
428
436
  function createChopper(config) {
429
- const { output = DEFAULT_OUTPUT, ...rest } = config;
430
- const defined = { output, ...rest };
437
+ const { buildDirectory = DEFAULT_BUILD_DIRECTORY, outputDirectory = DEFAULT_OUTPUT_DIRECTORY, ...rest } = config;
438
+ const defined = { buildDirectory, outputDirectory, ...rest };
431
439
  const planner = createConfigAssetPlanner(defined);
432
440
  Object.defineProperties(defined, {
433
441
  route: { enumerable: false, value: planner.route },
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/recipes.ts","../../src/core/result.ts","../../src/core/object-validation.ts","../../src/core/validation.ts","../../src/config/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,EAAA,OAAO,MAAA,GACH,QAAQ,MAAM,CAAA,GACd,QAAQ,gBAAA,EAAkB,CAAA,8DAAA,EAAiE,QAAQ,CAAA,CAAE,CAAA;AAC3G;AAEA,SAAS,iBAAA,CAAkB,OAAe,eAAA,EAAkC;AAC1E,EAAA,OAAO,KAAA,CAAM,MAAM,GAAG,CAAA,CAAE,MAAM,CAAA,EAAG,EAAE,CAAA,CAAE,QAAA,CAAS,eAAe,CAAA;AAC/D;;;ACvHO,SAAS,cACd,MAAA,EACsB;AACtB,EAAA,MAAM,EAAE,MAAA,GAAS,cAAA,EAAgB,GAAG,MAAK,GAAI,MAAA;AAC7C,EAAA,MAAM,OAAA,GAAU,EAAE,MAAA,EAAQ,GAAG,IAAA,EAAK;AAClC,EAAA,MAAM,OAAA,GAAU,yBAAyB,OAAO,CAAA;AAChD,EAAA,MAAA,CAAO,iBAAiB,OAAA,EAAS;AAAA,IAC/B,OAAO,EAAE,UAAA,EAAY,KAAA,EAAO,KAAA,EAAO,QAAQ,KAAA,EAAM;AAAA,IACjD,SAAS,EAAE,UAAA,EAAY,KAAA,EAAO,KAAA,EAAO,QAAQ,OAAA;AAAQ,GACtD,CAAA;AACD,EAAA,OAAO,OAAA;AACT;AAGO,IAAM,YAAA,GAAqC","file":"index.js","sourcesContent":["import type { NoUnknownFields } from './exact'\n\n/** Maximum image dimensions in pixels: `[width, height]`. Both values must be positive integers. */\nexport type TextureSize = readonly [width: number, height: number]\n\ninterface SizedEncoding {\n /**\n * Maximum output dimensions in pixels. Aspect ratio is preserved, and an\n * image smaller than both limits is not enlarged. Omit this property to keep\n * the source dimensions.\n */\n maxSize?: TextureSize\n}\n\nexport interface WebpEncoding extends SizedEncoding {\n /** Encode the image as WebP. */\n codec: 'webp'\n /** Lossy quality from 1 (smallest, lowest fidelity) to 100. @defaultValue `75` */\n quality?: number\n /** Encoder effort from 0 (fastest) to 100 (slowest). @defaultValue `50` */\n effort?: number\n /** Use lossless WebP instead of lossy encoding. Lossy `quality` is then ignored. @defaultValue `false` */\n lossless?: boolean\n /**\n * Near-lossless preprocessing quality for lossless encoding, from 0\n * (strongest pixel changes and smallest output) to 100 (no preprocessing).\n *\n * @defaultValue `100`\n */\n nearLossless?: number\n}\n\nexport interface AvifEncoding extends SizedEncoding {\n /** Encode the image as AVIF. */\n codec: 'avif'\n /** Lossy quality from 1 (smallest, lowest fidelity) to 100. @defaultValue `50` */\n quality?: number\n /** Encoder effort from 0 (fastest) to 100 (slowest). @defaultValue `40` */\n effort?: number\n /** Use lossless AVIF instead of lossy encoding, overriding `quality` and chroma subsampling. @defaultValue `false` */\n lossless?: boolean\n /**\n * Chroma resolution: `4:2:0` reduces color detail for smaller files, while\n * `4:4:4` preserves full color resolution. Lossless encoding always uses\n * full color resolution.\n *\n * @defaultValue `'4:2:0'`\n */\n chromaSubsampling?: '4:2:0' | '4:4:4'\n}\n\nexport interface JpegEncoding extends SizedEncoding {\n /** Encode the image as JPEG. Alpha is not preserved. */\n codec: 'jpeg'\n /** Lossy quality from 1 (smallest, lowest fidelity) to 100. @defaultValue `75` */\n quality?: number\n /**\n * Chroma resolution: `4:2:0` reduces color detail for smaller files, while\n * `4:4:4` preserves full color resolution.\n *\n * @defaultValue `'4:2:0'`\n */\n chromaSubsampling?: '4:2:0' | '4:4:4'\n}\n\nexport interface PngEncoding extends SizedEncoding {\n /** Encode the image as lossless PNG. */\n codec: 'png'\n}\n\nexport interface UastcEncoding extends SizedEncoding {\n /** Encode the image in a GPU-ready KTX2 container. */\n codec: 'ktx2'\n /** Use high-quality UASTC block compression for LDR pixels. */\n mode: 'uastc'\n /**\n * How the texture is sampled: `srgb` for color data such as albedo and\n * emissive maps, or `linear` for data and normal maps.\n *\n * @defaultValue `'srgb'`\n */\n colorSpace?: 'srgb' | 'linear'\n /** Tune the encoder for tangent-space normal-map data. @defaultValue `false` */\n normalMap?: boolean\n /** Encoder effort from 0 (fastest) to 4 (slowest, highest quality). @defaultValue `2` */\n level?: 0 | 1 | 2 | 3 | 4\n /** Generate a complete mip chain for minified rendering. @defaultValue `true` */\n mipmaps?: boolean\n /** Apply Zstandard supercompression to reduce download size. @defaultValue `true` */\n zstd?: boolean\n /**\n * Enable rate-distortion optimization. This can substantially reduce files\n * at the cost of image fidelity; omit it to disable RDO.\n */\n rdo?: {\n /**\n * Compression-to-quality tradeoff from 0.001 to 10. Larger values usually\n * produce smaller files with more distortion.\n *\n * @defaultValue `1`\n */\n lambda?: number\n }\n}\n\nexport interface Etc1sEncoding extends SizedEncoding {\n /** Encode the image in a GPU-ready KTX2 container. */\n codec: 'ktx2'\n /** Use ETC1S compression for the smallest download size at lower fidelity than UASTC. */\n mode: 'etc1s'\n /**\n * How the texture is sampled: `srgb` for color data such as albedo and\n * emissive maps, or `linear` for data and normal maps.\n *\n * @defaultValue `'srgb'`\n */\n colorSpace?: 'srgb' | 'linear'\n /** Tune the encoder for tangent-space normal-map data. @defaultValue `false` */\n normalMap?: boolean\n /** Quality from 1 (smallest, lowest fidelity) to 255. @defaultValue `128` */\n quality?: number\n /**\n * Encoder effort from 0 (fastest) to 6 (slowest). Higher values search\n * harder for a smaller file at the requested quality.\n *\n * @defaultValue `1`\n */\n compression?: 0 | 1 | 2 | 3 | 4 | 5 | 6\n /** Generate a complete mip chain for minified rendering. @defaultValue `true` */\n mipmaps?: boolean\n}\n\n/**\n * UASTC HDR 4x4. Encodes half-float EXR source into blocks the runtime\n * transcodes to BC6H on desktop, or uploads as ASTC 4x4 SFLOAT where the HDR\n * profile exists. Fixed 8 bits per texel on the GPU regardless of source.\n *\n * Deliberately not a `SizedEncoding`: resizing runs on decoded 8-bit RGBA, and\n * there is no half-float resampler in the pipeline, so HDR sources must already\n * be authored at their target resolution.\n */\nexport interface UastcHdrEncoding {\n /** Encode the image in a GPU-ready KTX2 container. */\n codec: 'ktx2'\n /**\n * Use UASTC HDR for half-float EXR or Radiance HDR input. This mode does not\n * support resizing or alpha and is only available to standalone image recipes.\n */\n mode: 'uastc-hdr'\n /**\n * Encoder effort from 0 (fastest) to 4 (slowest). Higher levels rarely help\n * low-frequency content such as diffuse lightmaps.\n *\n * @defaultValue `1`\n */\n level?: 0 | 1 | 2 | 3 | 4\n /** Generate a complete mip chain for minified rendering. @defaultValue `true` */\n mipmaps?: boolean\n /** Apply Zstandard supercompression to reduce download size. @defaultValue `true` */\n zstd?: boolean\n}\n\nexport type RasterEncoding = WebpEncoding | AvifEncoding | JpegEncoding | PngEncoding\n\nexport type ImageEncoding = RasterEncoding | UastcEncoding | Etc1sEncoding | UastcHdrEncoding\n\nexport type GlbProperty =\n | 'accessor'\n | 'animation'\n | 'buffer'\n | 'camera'\n | 'material'\n | 'mesh'\n | 'node'\n | 'primitive'\n | 'primitiveTarget'\n | 'skin'\n | 'texture'\n\nexport type GlbMethodRecipe =\n | {\n /** Merge equivalent accessors, materials, meshes, skins, or textures. */\n method: 'dedup'\n /** Keep otherwise-identical properties separate when their names differ. @defaultValue `false` */\n keepUniqueNames?: boolean\n /**\n * Property kinds to merge.\n *\n * @defaultValue `['accessor', 'material', 'mesh', 'skin', 'texture']`\n */\n propertyTypes?: readonly Extract<GlbProperty, 'accessor' | 'material' | 'mesh' | 'skin' | 'texture'>[]\n }\n | {\n /** Remove unused GLB properties and optionally simplify redundant data. */\n method: 'prune'\n /** Keep unused vertex attributes, such as UVs without an assigned texture. @defaultValue `false` */\n keepAttributes?: boolean\n /** Prevent a property with custom `extras` data from being removed. @defaultValue `false` */\n keepExtras?: boolean\n /** Keep empty leaf nodes that would otherwise be removed. @defaultValue `false` */\n keepLeaves?: boolean\n /** Keep single-color textures instead of replacing them with material factors. @defaultValue `false` */\n keepSolidTextures?: boolean\n /** Property kinds eligible for pruning. By default, every supported kind is eligible. */\n propertyTypes?: readonly GlbProperty[]\n }\n | {\n /** Remove redundant animation keyframes while keeping motion within a tolerance. */\n method: 'resample'\n /** Maximum permitted animation-value error. Must be greater than zero. @defaultValue `0.0001` */\n tolerance?: number\n /**\n * Deduplicate and prune temporary or unused resources after resampling.\n * Disable this when those resources must be preserved for a later step.\n *\n * @defaultValue `true`\n */\n cleanup?: boolean\n }\n\nexport type TextureSelector =\n | {\n /** Select textures by the material slots that reference them. */\n by: 'slot'\n /** glTF material texture-slot names, such as `baseColorTexture` or `normalTexture`. */\n slots: readonly string[]\n }\n | {\n /** Select textures by their authored GLB names. */\n by: 'name'\n /** Exact, case-sensitive texture names. Names should be unique within the GLB. */\n names: readonly string[]\n }\n | {\n /** Select textures by their zero-based order in the GLB. */\n by: 'index'\n /** Non-negative texture indices. Indices can change when a source GLB is re-exported. */\n indices: readonly number[]\n }\n\nexport interface EmbeddedTextureRecipe {\n /**\n * Unique, non-empty name for this texture group in progress events and\n * optimization reports. It does not rename textures in the GLB.\n */\n label: string\n /** Textures to encode. A texture cannot be claimed by more than one selector. */\n select: TextureSelector\n /** Output encoding for the selected textures. UASTC HDR is not supported inside GLBs. */\n encode: ImageEncoding\n}\n\nexport type GeometryEncoding =\n | {\n /** Compress geometry with `KHR_draco_mesh_compression` for broad decoder support. */\n codec: 'draco'\n }\n | {\n /** Compress geometry with `EXT_meshopt_compression` for fast runtime decoding. */\n codec: 'meshopt'\n }\n\nexport interface GlbAssetRecipe {\n /** Optimize a binary glTF (`.glb`) asset. */\n kind: 'glb'\n /** Structural transforms to run in array order before texture and geometry encoding. @defaultValue `[]` */\n methods?: readonly GlbMethodRecipe[]\n /** Embedded texture groups to encode. Unselected textures keep their source encoding. @defaultValue `[]` */\n textures?: readonly EmbeddedTextureRecipe[]\n /** Geometry codec to apply, or `false` to leave geometry uncompressed. @defaultValue `false` */\n geometry?: GeometryEncoding | false\n}\n\nexport interface ImageAssetRecipe {\n /** Optimize a standalone raster or HDR image. */\n kind: 'image'\n /** Output codec and its quality, size, and performance tradeoffs. */\n encode: ImageEncoding\n}\n\nexport type AssetRecipe = GlbAssetRecipe | ImageAssetRecipe\n\nexport type NormalizedImageEncoding =\n | (Required<Omit<WebpEncoding, 'maxSize'>> & Pick<WebpEncoding, 'maxSize'>)\n | (Required<Omit<AvifEncoding, 'maxSize'>> & Pick<AvifEncoding, 'maxSize'>)\n | (Required<Omit<JpegEncoding, 'maxSize'>> & Pick<JpegEncoding, 'maxSize'>)\n | PngEncoding\n | (Required<Omit<UastcEncoding, 'maxSize' | 'rdo'>> & Pick<UastcEncoding, 'maxSize' | 'rdo'>)\n | (Required<Omit<Etc1sEncoding, 'maxSize'>> & Pick<Etc1sEncoding, 'maxSize'>)\n | Required<UastcHdrEncoding>\n\nexport type NormalizedAssetRecipe =\n | {\n /** Identifies the normalized recipe as a standalone image recipe. */\n kind: 'image'\n /** Image encoding with every codec default resolved. */\n encode: NormalizedImageEncoding\n }\n | {\n /** Identifies the normalized recipe as a binary glTF recipe. */\n kind: 'glb'\n /** Structural transforms to run, with an omitted value resolved to an empty array. */\n methods: readonly GlbMethodRecipe[]\n /** Embedded texture groups with every codec default resolved. */\n textures: readonly (Omit<EmbeddedTextureRecipe, 'encode'> & {\n /** Output encoding with every codec default resolved. */\n encode: NormalizedImageEncoding\n })[]\n /** Resolved geometry codec, or `false` when geometry compression is disabled. */\n geometry: GeometryEncoding | false\n }\n\nexport const COLOR_TEXTURE_SLOTS = [\n 'baseColorTexture',\n 'emissiveTexture',\n 'specularColorTexture',\n 'sheenColorTexture',\n] as const\n\nexport const DIRECTIONAL_TEXTURE_SLOTS = ['normalTexture', 'clearcoatNormalTexture', 'anisotropyTexture'] as const\n\nexport const DATA_TEXTURE_SLOTS = [\n 'occlusionTexture',\n 'metallicRoughnessTexture',\n 'specularTexture',\n 'clearcoatTexture',\n 'clearcoatRoughnessTexture',\n 'sheenRoughnessTexture',\n 'transmissionTexture',\n 'thicknessTexture',\n 'iridescenceTexture',\n 'iridescenceThicknessTexture',\n] as const\n\nexport const DEFAULT_GLB_RECIPE: GlbAssetRecipe = {\n kind: 'glb',\n methods: [],\n textures: [\n {\n label: 'color',\n select: { by: 'slot', slots: COLOR_TEXTURE_SLOTS },\n encode: {\n codec: 'ktx2',\n mode: 'uastc',\n colorSpace: 'srgb',\n level: 3,\n zstd: true,\n },\n },\n {\n label: 'directional',\n select: { by: 'slot', slots: DIRECTIONAL_TEXTURE_SLOTS },\n encode: {\n codec: 'ktx2',\n mode: 'uastc',\n colorSpace: 'linear',\n normalMap: true,\n level: 3,\n zstd: true,\n },\n },\n {\n label: 'data',\n select: { by: 'slot', slots: DATA_TEXTURE_SLOTS },\n encode: {\n codec: 'ktx2',\n mode: 'uastc',\n colorSpace: 'linear',\n level: 3,\n zstd: true,\n rdo: { lambda: 1 },\n },\n },\n ],\n geometry: { codec: 'draco' },\n}\n\nexport const DEFAULT_IMAGE_RECIPE: ImageAssetRecipe = {\n kind: 'image',\n encode: { codec: 'webp', quality: 85, effort: 80 },\n}\n\n/** Defines a type-checked optimization recipe while preserving its inferred literal types. */\nexport const defineRecipe = <const T extends AssetRecipe>(recipe: T & NoUnknownFields<T, AssetRecipe>): T => recipe\n\nexport function outputExtension(encoding: ImageEncoding): string {\n if (encoding.codec === 'ktx2') return '.ktx2'\n if (encoding.codec === 'jpeg') return '.jpg'\n return `.${encoding.codec}`\n}\n\nexport function outputMimeType(encoding: ImageEncoding): string {\n if (encoding.codec === 'ktx2') return 'image/ktx2'\n return `image/${encoding.codec}`\n}\n","export type ChopperErrorCode =\n | 'unsupported_asset'\n | 'invalid_recipe'\n | 'codec_load_failed'\n | 'decode_failed'\n | 'encode_failed'\n | 'validation_failed'\n | 'aborted'\n | 'io_failed'\n\nexport interface ChopperFailure {\n ok: false\n error: {\n code: ChopperErrorCode\n message: string\n cause?: unknown\n }\n}\n\nexport interface ChopperSuccess<T> {\n ok: true\n data: T\n}\n\nexport type ChopperResult<T> = ChopperSuccess<T> | ChopperFailure\n\nexport const success = <T>(data: T): ChopperSuccess<T> => ({ ok: true, data })\n\nexport const failure = (code: ChopperErrorCode, message: string, cause?: unknown): ChopperFailure => ({\n ok: false,\n error: cause === undefined ? { code, message } : { code, message, cause },\n})\n","export function unknownFieldIssue(\n value: Record<string, unknown>,\n allowedFields: readonly string[],\n subject: string\n): string | undefined {\n const field = Object.keys(value).find((key) => !allowedFields.includes(key))\n return field ? `Unknown ${subject} field: ${field}` : undefined\n}\n","import { failure, success, type ChopperResult } from './result'\nimport { unknownFieldIssue } from './object-validation'\nimport {\n type AssetRecipe,\n type ImageEncoding,\n type NormalizedAssetRecipe,\n type NormalizedImageEncoding,\n type TextureSelector,\n} from './recipes'\n\nexport function validateRecipe(recipe: unknown): ChopperResult<AssetRecipe> {\n const shapeIssue = recipeShapeIssue(recipe)\n if (shapeIssue) return failure('invalid_recipe', shapeIssue)\n\n try {\n const typedRecipe = recipe as AssetRecipe\n const issue = recipeIssue(typedRecipe)\n return issue ? failure('invalid_recipe', issue) : success(typedRecipe)\n } catch {\n return failure('invalid_recipe', 'Recipe contains malformed fields')\n }\n}\n\nexport function normalizeRecipe(value: AssetRecipe): ChopperResult<NormalizedAssetRecipe> {\n const validated = validateRecipe(value)\n if (!validated.ok) return validated\n const recipe = validated.data\n\n if (recipe.kind === 'image') {\n return success({\n kind: 'image',\n encode: normalizeEncoding(recipe.encode),\n })\n }\n\n return success({\n kind: 'glb',\n methods: recipe.methods ?? [],\n textures: (recipe.textures ?? []).map((texture) => ({\n ...texture,\n encode: normalizeEncoding(texture.encode),\n })),\n geometry: recipe.geometry ?? false,\n })\n}\n\nfunction recipeShapeIssue(recipe: unknown): string | undefined {\n if (!recipe || typeof recipe !== 'object') return 'Recipe must be an object'\n const candidate = recipe as Record<string, unknown>\n if (candidate.kind !== 'image' && candidate.kind !== 'glb') {\n return `Unsupported recipe kind: ${String(candidate.kind)}`\n }\n\n if (candidate.kind === 'image') {\n const unknownField = unknownFieldIssue(candidate, ['kind', 'encode'], 'image recipe')\n if (unknownField) return unknownField\n return encodingShapeIssue(candidate.encode)\n }\n\n const unknownField = unknownFieldIssue(candidate, ['kind', 'methods', 'textures', 'geometry'], 'GLB recipe')\n if (unknownField) return unknownField\n\n if (candidate.methods !== undefined && !Array.isArray(candidate.methods)) {\n return 'GLB methods must be an array'\n }\n for (const method of (candidate.methods ?? []) as unknown[]) {\n if (!method || typeof method !== 'object') {\n return 'GLB methods contain an unsupported transform'\n }\n const entry = method as Record<string, unknown>\n if (!['dedup', 'prune', 'resample'].includes(String(entry.method))) {\n return 'GLB methods contain an unsupported transform'\n }\n const allowedFields =\n entry.method === 'dedup'\n ? ['method', 'keepUniqueNames', 'propertyTypes']\n : entry.method === 'prune'\n ? ['method', 'keepAttributes', 'keepExtras', 'keepLeaves', 'keepSolidTextures', 'propertyTypes']\n : ['method', 'tolerance', 'cleanup']\n const unknownField = unknownFieldIssue(entry, allowedFields, 'GLB method')\n if (unknownField) return unknownField\n }\n if (candidate.textures !== undefined && !Array.isArray(candidate.textures)) {\n return 'GLB textures must be an array'\n }\n for (const texture of (candidate.textures ?? []) as unknown[]) {\n if (!texture || typeof texture !== 'object') return 'Texture recipes must be objects'\n const entry = texture as Record<string, unknown>\n const unknownField = unknownFieldIssue(entry, ['label', 'select', 'encode'], 'texture recipe')\n if (unknownField) return unknownField\n if (typeof entry.label !== 'string') return 'Texture recipe labels must be strings'\n if (!entry.select || typeof entry.select !== 'object') return 'Texture recipes require a selector'\n const selector = entry.select as Record<string, unknown>\n if (!['slot', 'name', 'index'].includes(String(selector.by))) {\n return 'Texture recipe selectors are malformed'\n }\n const valueField = selector.by === 'slot' ? 'slots' : selector.by === 'name' ? 'names' : 'indices'\n const selectorUnknownField = unknownFieldIssue(selector, ['by', valueField], 'texture selector')\n if (selectorUnknownField) return selectorUnknownField\n if (!Array.isArray(selector[valueField])) return 'Texture recipe selectors are malformed'\n const encodingIssue = encodingShapeIssue(entry.encode)\n if (encodingIssue) return encodingIssue\n }\n if (\n candidate.geometry !== undefined &&\n candidate.geometry !== false &&\n (!candidate.geometry ||\n typeof candidate.geometry !== 'object' ||\n !['draco', 'meshopt'].includes(String((candidate.geometry as Record<string, unknown>).codec)))\n ) {\n return 'GLB geometry must be false, Draco, or Meshopt'\n }\n if (candidate.geometry && typeof candidate.geometry === 'object') {\n const geometryUnknownField = unknownFieldIssue(\n candidate.geometry as Record<string, unknown>,\n ['codec'],\n 'GLB geometry'\n )\n if (geometryUnknownField) return geometryUnknownField\n }\n return undefined\n}\n\nfunction encodingShapeIssue(encoding: unknown): string | undefined {\n if (!encoding || typeof encoding !== 'object') return 'Image encoding must be an object'\n const candidate = encoding as Record<string, unknown>\n if (!['webp', 'avif', 'jpeg', 'png', 'ktx2'].includes(String(candidate.codec))) {\n return `Unsupported image codec: ${String(candidate.codec)}`\n }\n if (\n candidate.codec === 'ktx2' &&\n candidate.mode !== 'uastc' &&\n candidate.mode !== 'etc1s' &&\n candidate.mode !== 'uastc-hdr'\n ) {\n return `Unsupported KTX2 mode: ${String(candidate.mode)}`\n }\n if (candidate.codec === 'ktx2' && candidate.mode === 'uastc-hdr' && candidate.maxSize !== undefined) {\n return 'UASTC HDR does not support maxSize; resizing requires a decoded 8-bit image. Author the source at its target resolution.'\n }\n const allowedFields =\n candidate.codec === 'webp'\n ? ['codec', 'maxSize', 'quality', 'effort', 'lossless', 'nearLossless']\n : candidate.codec === 'avif'\n ? ['codec', 'maxSize', 'quality', 'effort', 'lossless', 'chromaSubsampling']\n : candidate.codec === 'jpeg'\n ? ['codec', 'maxSize', 'quality', 'chromaSubsampling']\n : candidate.codec === 'png'\n ? ['codec', 'maxSize']\n : candidate.mode === 'uastc'\n ? ['codec', 'mode', 'maxSize', 'colorSpace', 'normalMap', 'level', 'mipmaps', 'zstd', 'rdo']\n : candidate.mode === 'etc1s'\n ? ['codec', 'mode', 'maxSize', 'colorSpace', 'normalMap', 'quality', 'compression', 'mipmaps']\n : ['codec', 'mode', 'level', 'mipmaps', 'zstd']\n const unknownField = unknownFieldIssue(candidate, allowedFields, 'image encoding')\n if (unknownField) return unknownField\n if (candidate.codec === 'ktx2' && candidate.mode === 'uastc' && candidate.rdo !== undefined) {\n if (!candidate.rdo || typeof candidate.rdo !== 'object' || Array.isArray(candidate.rdo)) {\n return 'UASTC RDO must be an object'\n }\n const rdoUnknownField = unknownFieldIssue(candidate.rdo as Record<string, unknown>, ['lambda'], 'UASTC RDO')\n if (rdoUnknownField) return rdoUnknownField\n }\n return undefined\n}\n\nfunction recipeIssue(recipe: AssetRecipe): string | undefined {\n if (recipe.kind === 'image') return encodingIssue(recipe.encode)\n\n const labels = new Set<string>()\n const selectors = new Set<string>()\n for (const texture of recipe.textures ?? []) {\n if (!texture.label) return 'Texture recipe labels cannot be empty'\n if (labels.has(texture.label)) {\n return `Duplicate texture recipe label: ${texture.label}`\n }\n labels.add(texture.label)\n\n const values = selectorValues(texture.select)\n if (!values.ok) return values.error.message\n if (!values.data.length) {\n return `Texture recipe \"${texture.label}\" has an empty selector`\n }\n for (const value of values.data) {\n const key = `${texture.select.by}:${value}`\n if (selectors.has(key)) {\n return `Texture selector appears in more than one recipe: ${key}`\n }\n selectors.add(key)\n }\n\n if (texture.encode.codec === 'ktx2' && texture.encode.mode === 'uastc-hdr') {\n return `Texture recipe \"${texture.label}\" uses UASTC HDR, which KHR_texture_basisu does not cover; HDR is only supported for standalone image recipes`\n }\n\n const issue = encodingIssue(texture.encode)\n if (issue) return issue\n }\n\n for (const method of recipe.methods ?? []) {\n if (method.method === 'resample' && (method.tolerance ?? 1e-4) <= 0) {\n return 'Resample tolerance must be greater than zero'\n }\n }\n\n return undefined\n}\n\nfunction selectorValues(selector: TextureSelector): ChopperResult<readonly (string | number)[]> {\n if (selector.by === 'slot') return success(selector.slots)\n if (selector.by === 'name') return success(selector.names)\n for (const index of selector.indices) {\n if (!Number.isInteger(index) || index < 0) {\n return failure('invalid_recipe', 'Texture indices must be non-negative integers')\n }\n }\n return success(selector.indices)\n}\n\nfunction encodingIssue(encoding: ImageEncoding): string | undefined {\n if ('maxSize' in encoding && encoding.maxSize) {\n const [width, height] = encoding.maxSize\n if (!Number.isInteger(width) || width < 1 || !Number.isInteger(height) || height < 1) {\n return 'Texture maxSize must contain positive integers'\n }\n }\n\n if ('quality' in encoding && encoding.quality !== undefined) {\n const max = encoding.codec === 'ktx2' ? 255 : 100\n if (encoding.quality < 1 || encoding.quality > max) {\n return `${encoding.codec} quality must be between 1 and ${max}`\n }\n }\n\n if ('effort' in encoding && encoding.effort !== undefined) {\n if (encoding.effort < 0 || encoding.effort > 100) {\n return `${encoding.codec} effort must be between 0 and 100`\n }\n }\n\n if (\n encoding.codec === 'webp' &&\n encoding.nearLossless !== undefined &&\n (encoding.nearLossless < 0 || encoding.nearLossless > 100)\n ) {\n return 'WebP nearLossless must be between 0 and 100'\n }\n\n if (encoding.codec === 'ktx2' && encoding.mode === 'uastc') {\n if (\n encoding.level !== undefined &&\n (!Number.isInteger(encoding.level) || encoding.level < 0 || encoding.level > 4)\n ) {\n return 'UASTC level must be an integer between 0 and 4'\n }\n const lambda = encoding.rdo?.lambda\n if (lambda !== undefined && (lambda < 0.001 || lambda > 10)) {\n return 'UASTC RDO lambda must be between 0.001 and 10'\n }\n }\n\n if (\n encoding.codec === 'ktx2' &&\n encoding.mode === 'uastc-hdr' &&\n encoding.level !== undefined &&\n (!Number.isInteger(encoding.level) || encoding.level < 0 || encoding.level > 4)\n ) {\n return 'UASTC HDR level must be an integer between 0 and 4'\n }\n\n if (\n encoding.codec === 'ktx2' &&\n encoding.mode === 'etc1s' &&\n encoding.compression !== undefined &&\n (!Number.isInteger(encoding.compression) || encoding.compression < 0 || encoding.compression > 6)\n ) {\n return 'ETC1S compression must be an integer between 0 and 6'\n }\n\n return undefined\n}\n\nfunction normalizeEncoding(encoding: ImageEncoding): NormalizedImageEncoding {\n switch (encoding.codec) {\n case 'webp':\n return {\n ...encoding,\n quality: encoding.quality ?? 75,\n effort: encoding.effort ?? 50,\n lossless: encoding.lossless ?? false,\n nearLossless: encoding.nearLossless ?? 100,\n }\n case 'avif':\n return {\n ...encoding,\n quality: encoding.quality ?? 50,\n effort: encoding.effort ?? 40,\n lossless: encoding.lossless ?? false,\n chromaSubsampling: encoding.chromaSubsampling ?? '4:2:0',\n }\n case 'jpeg':\n return {\n ...encoding,\n quality: encoding.quality ?? 75,\n chromaSubsampling: encoding.chromaSubsampling ?? '4:2:0',\n }\n case 'png':\n return { ...encoding }\n case 'ktx2':\n if (encoding.mode === 'uastc-hdr') {\n return {\n ...encoding,\n level: encoding.level ?? 1,\n mipmaps: encoding.mipmaps ?? true,\n zstd: encoding.zstd ?? true,\n }\n }\n if (encoding.mode === 'uastc') {\n return {\n ...encoding,\n colorSpace: encoding.colorSpace ?? 'srgb',\n normalMap: encoding.normalMap ?? false,\n level: encoding.level ?? 2,\n mipmaps: encoding.mipmaps ?? true,\n zstd: encoding.zstd ?? true,\n }\n }\n return {\n ...encoding,\n colorSpace: encoding.colorSpace ?? 'srgb',\n normalMap: encoding.normalMap ?? false,\n quality: encoding.quality ?? 128,\n compression: encoding.compression ?? 1,\n mipmaps: encoding.mipmaps ?? true,\n }\n }\n}\n","import { unknownFieldIssue } from '../core/object-validation'\nimport { failure, success, type ChopperResult } from '../core/result'\nimport { validateRecipe } from '../core/validation'\nimport type { EffectiveChopperConfig } from './types'\n\nexport const DEFAULT_OUTPUT = '.chopper'\n\nexport function validateConfig(config: unknown): ChopperResult<EffectiveChopperConfig> {\n if (!config || typeof config !== 'object' || Array.isArray(config)) {\n return failure('invalid_recipe', 'Config must be an object')\n }\n const candidate = config as Record<string, unknown>\n const unknownField = unknownFieldIssue(candidate, ['output', 'outputDirectory', 'rules', 'concurrency'], 'config')\n if (unknownField) return failure('invalid_recipe', unknownField)\n if (candidate.output !== undefined && (typeof candidate.output !== 'string' || !candidate.output)) {\n return failure('invalid_recipe', 'Config output must be a non-empty string')\n }\n if (candidate.output !== undefined && !isProjectRelativePath(candidate.output, true)) {\n return failure('invalid_recipe', `Output directory must be a project-relative POSIX path: ${candidate.output}`)\n }\n if (candidate.outputDirectory !== undefined && !isSafePathSegment(candidate.outputDirectory)) {\n return failure(\n 'invalid_recipe',\n `Config outputDirectory must be exactly one safe path segment: ${candidate.outputDirectory}`\n )\n }\n if (!Array.isArray(candidate.rules)) {\n return failure('invalid_recipe', 'Config rules must be an array')\n }\n if (\n candidate.concurrency !== undefined &&\n (typeof candidate.concurrency !== 'number' || !Number.isInteger(candidate.concurrency) || candidate.concurrency < 1)\n ) {\n return failure('invalid_recipe', 'Config concurrency must be a positive integer')\n }\n for (const [index, rule] of candidate.rules.entries()) {\n if (!rule || typeof rule !== 'object' || Array.isArray(rule)) {\n return failure('invalid_recipe', `Config rule ${index} must be an object`)\n }\n const entry = rule as Record<string, unknown>\n const ruleUnknownField = unknownFieldIssue(entry, ['include', 'exclude', 'recipe', 'path'], `config rule ${index}`)\n if (ruleUnknownField) return failure('invalid_recipe', ruleUnknownField)\n if (!isStringArray(entry.include)) {\n return failure('invalid_recipe', `Config rule ${index} include must be an array of glob patterns`)\n }\n if (entry.exclude !== undefined && !isStringArray(entry.exclude)) {\n return failure('invalid_recipe', `Config rule ${index} exclude must be an array of glob patterns`)\n }\n const invalidGlob = [...entry.include, ...((entry.exclude ?? []) as string[])].find(\n (pattern) => !isProjectRelativeGlob(pattern)\n )\n if (invalidGlob) {\n return failure('invalid_recipe', `Config rule ${index} glob must be project-relative: ${invalidGlob}`)\n }\n if (entry.path !== undefined && (typeof entry.path !== 'string' || !entry.path)) {\n return failure('invalid_recipe', `Config rule ${index} path must be a non-empty string`)\n }\n if (candidate.outputDirectory !== undefined && entry.path !== undefined) {\n return failure(\n 'invalid_recipe',\n `Config rule ${index} path cannot be combined with outputDirectory; authoritative sibling output routing determines the output path`\n )\n }\n const recipe = validateRecipe(entry.recipe)\n if (!recipe.ok) return recipe\n }\n return success({ ...config, output: candidate.output ?? DEFAULT_OUTPUT } as EffectiveChopperConfig)\n}\n\nexport function normalizeProjectPath(path: unknown): string | undefined {\n if (typeof path !== 'string') return undefined\n if (!isProjectRelativePath(path, false)) return undefined\n const parts: string[] = []\n for (const part of path.split('/')) {\n if (!part || part === '.') continue\n if (part === '..') {\n if (!parts.length) return undefined\n parts.pop()\n } else {\n parts.push(part)\n }\n }\n return parts.join('/') || undefined\n}\n\nfunction isStringArray(value: unknown): value is string[] {\n return Array.isArray(value) && value.every((item) => typeof item === 'string' && item.length > 0)\n}\n\nfunction isSafePathSegment(value: unknown): value is string {\n return (\n typeof value === 'string' &&\n value.length > 0 &&\n value !== '.' &&\n value !== '..' &&\n !value.includes('/') &&\n !value.includes('\\\\') &&\n !value.includes('\\0') &&\n !value.includes(':')\n )\n}\n\nfunction isProjectRelativeGlob(pattern: string): boolean {\n const path = pattern.startsWith('!') && !pattern.startsWith('!(') ? pattern.slice(1) : pattern\n return (\n path.length > 0 &&\n !path.includes('\\0') &&\n !path.startsWith('/') &&\n !/^[A-Za-z]:\\//.test(path) &&\n !path.split('/').includes('..')\n )\n}\n\nfunction isProjectRelativePath(path: string, allowCurrentDirectory: boolean): boolean {\n if (!path || path.includes('\\\\') || path.includes('\\0') || path.startsWith('/') || /^[A-Za-z]:\\//.test(path)) {\n return false\n }\n const normalized = normalizeSegments(path)\n return normalized !== undefined && (allowCurrentDirectory || normalized !== '')\n}\n\nfunction normalizeSegments(path: string): string | undefined {\n const parts: string[] = []\n for (const part of path.split('/')) {\n if (!part || part === '.') continue\n if (part === '..') {\n if (!parts.length) return undefined\n parts.pop()\n } else {\n parts.push(part)\n }\n }\n return parts.join('/')\n}\n","import picomatch, { type PicomatchOptions } from 'picomatch'\n\nimport { outputExtension } from '../core/recipes'\nimport { failure, success, type ChopperResult } from '../core/result'\nimport type { ChopperConfig, ChopperRule, ConfigAssetPlanner, ConfigRoute, PlannedConfigAsset } from './types'\nimport { normalizeProjectPath, validateConfig } from './validation'\n\nconst GLOB_OPTIONS: PicomatchOptions = {\n dot: false,\n nobrace: false,\n nocase: false,\n noextglob: false,\n noglobstar: false,\n posix: true,\n}\n\ninterface PreparedRule {\n rule: ChopperRule\n matches(input: string): boolean\n}\n\ninterface PreparedConfig {\n outputDirectory?: string\n rules: PreparedRule[]\n}\n\n/** Compiles one reusable, runtime-neutral planner for a Chopper config. */\nexport function createConfigAssetPlanner(config: ChopperConfig): ConfigAssetPlanner {\n let prepared: ChopperResult<PreparedConfig> | undefined\n\n const route = (input: string): ChopperResult<ConfigRoute> => {\n prepared ??= prepareRules(config)\n if (!prepared.ok) return prepared\n\n const normalizedInput = normalizeProjectPath(input)\n if (!normalizedInput) {\n return failure('invalid_recipe', `Asset input must be a project-relative POSIX path: ${input}`)\n }\n if (prepared.data.outputDirectory && isGeneratedOutput(normalizedInput, prepared.data.outputDirectory)) {\n return success({ kind: 'output', input: normalizedInput })\n }\n\n const planned = new Map<string, PlannedConfigAsset>()\n for (const { rule, matches } of prepared.data.rules) {\n if (!matches(normalizedInput)) continue\n const output = resolveOutput(rule, normalizedInput, prepared.data.outputDirectory)\n if (!output.ok) return output\n planned.set(output.data, { input: normalizedInput, output: output.data, rule })\n }\n const outputs = [...planned.values()]\n return outputs.length\n ? success({ kind: 'source', input: normalizedInput, outputs })\n : success({ kind: 'unmatched', input: normalizedInput })\n }\n\n const resolve = (input: string): ChopperResult<PlannedConfigAsset[]> => {\n const routed = route(input)\n if (!routed.ok) return routed\n return success(routed.data.kind === 'source' ? routed.data.outputs : [])\n }\n\n return { route, resolve }\n}\n\nfunction prepareRules(config: ChopperConfig): ChopperResult<PreparedConfig> {\n const validated = validateConfig(config)\n if (!validated.ok) return validated\n\n try {\n return success({\n outputDirectory: validated.data.outputDirectory,\n rules: validated.data.rules.map((rule) => ({ rule, matches: compileRuleMatcher(rule) })),\n })\n } catch (cause) {\n return failure('invalid_recipe', 'Config contains an invalid glob pattern', cause)\n }\n}\n\nfunction compileRuleMatcher(rule: ChopperRule): (input: string) => boolean {\n const includePatterns: string[] = []\n const ignorePatterns = (rule.exclude ?? []).filter((pattern) => !pattern.startsWith('!') || pattern.startsWith('!('))\n for (const pattern of rule.include) {\n if (pattern.startsWith('!') && !pattern.startsWith('!(')) {\n if (!pattern.startsWith('!!') || pattern.startsWith('!!(')) ignorePatterns.push(pattern.slice(1))\n } else {\n includePatterns.push(pattern)\n }\n }\n\n const include = picomatch(includePatterns.map(expandDirectoryPattern), GLOB_OPTIONS)\n const ignore = picomatch(ignorePatterns.map(expandDirectoryPattern), GLOB_OPTIONS)\n return (input) => include(input) && !ignore(input)\n}\n\nfunction expandDirectoryPattern(pattern: string): string {\n const normalized =\n pattern\n .split('/')\n .filter((segment) => segment && segment !== '.')\n .join('/') || '**'\n const withoutTrailingSlash = normalized.endsWith('/') ? normalized.slice(0, -1) : normalized\n return withoutTrailingSlash.endsWith('*') ? withoutTrailingSlash : `${withoutTrailingSlash}/**`\n}\n\nfunction resolveOutput(rule: ChopperRule, input: string, outputDirectory?: string): ChopperResult<string> {\n const slash = input.lastIndexOf('/')\n const directory = slash < 0 ? '' : input.slice(0, slash)\n const base = slash < 0 ? input : input.slice(slash + 1)\n const dot = base.lastIndexOf('.')\n const name = dot <= 0 ? base : base.slice(0, dot)\n const extension = rule.recipe.kind === 'glb' ? '.glb' : outputExtension(rule.recipe.encode)\n\n if (outputDirectory) {\n return success(`${directory ? `${directory}/` : ''}${outputDirectory}/${name}${extension}`)\n }\n\n const template = rule.path ?? '{dir}/{name}.{ext}'\n if (template.includes('\\\\') || template.startsWith('/') || /^[A-Za-z]:\\//.test(template)) {\n return failure('invalid_recipe', `Output path must stay inside the configured output directory: ${template}`)\n }\n\n const rendered = template\n .replaceAll('{dir}/', directory ? `${directory}/` : '')\n .replaceAll('{dir}', directory)\n .replaceAll('{name}', name)\n .replaceAll('{ext}', extension.slice(1))\n\n if (/\\{[^{}]+\\}/.test(rendered)) {\n return failure('invalid_recipe', `Output path contains an unsupported placeholder: ${template}`)\n }\n const output = normalizeProjectPath(rendered)\n return output\n ? success(output)\n : failure('invalid_recipe', `Output path must stay inside the configured output directory: ${template}`)\n}\n\nfunction isGeneratedOutput(input: string, outputDirectory: string): boolean {\n return input.split('/').slice(0, -1).includes(outputDirectory)\n}\n","import type { NoUnknownFields } from '../core/exact'\nimport { createConfigAssetPlanner } from './planner'\nimport type { ChopperConfig, ConfiguredChopper } from './types'\nimport { DEFAULT_OUTPUT } from './validation'\n\nexport { COLOR_TEXTURE_SLOTS, DATA_TEXTURE_SLOTS, DIRECTIONAL_TEXTURE_SLOTS, defineRecipe } from '../core/recipes'\nexport type {\n ChopperConfig,\n ChopperRule,\n ConfigAssetPlanner,\n ConfigRoute,\n ConfiguredChopper,\n PlannedConfigAsset,\n} from './types'\n\n/**\n * Defines a type-checked Chopper project config and binds a browser-safe asset\n * planner to it while preserving its inferred literal types.\n */\nexport function createChopper<const T extends ChopperConfig>(\n config: T & NoUnknownFields<T, ChopperConfig>\n): ConfiguredChopper<T> {\n const { output = DEFAULT_OUTPUT, ...rest } = config\n const defined = { output, ...rest } as unknown as ConfiguredChopper<T>\n const planner = createConfigAssetPlanner(defined)\n Object.defineProperties(defined, {\n route: { enumerable: false, value: planner.route },\n resolve: { enumerable: false, value: planner.resolve },\n })\n return defined\n}\n\n/** @deprecated Use {@link createChopper} instead. */\nexport const defineConfig: typeof createChopper = createChopper\n"]}
1
+ {"version":3,"sources":["../../src/core/recipes.ts","../../src/core/result.ts","../../src/core/object-validation.ts","../../src/core/validation.ts","../../src/config/validation.ts","../../src/config/planner.ts","../../src/config/index.ts"],"names":["unknownField","encodingIssue"],"mappings":";;;;;AAmVO,IAAM,mBAAA,GAAsB;AAAA,EACjC,kBAAA;AAAA,EACA,iBAAA;AAAA,EACA,sBAAA;AAAA,EACA;AACF;AAEO,IAAM,yBAAA,GAA4B,CAAC,eAAA,EAAiB,wBAAA,EAA0B,mBAAmB;AAEjG,IAAM,kBAAA,GAAqB;AAAA,EAChC,kBAAA;AAAA,EACA,0BAAA;AAAA,EACA,iBAAA;AAAA,EACA,kBAAA;AAAA,EACA,2BAAA;AAAA,EACA,uBAAA;AAAA,EACA,qBAAA;AAAA,EACA,kBAAA;AAAA,EACA,oBAAA;AAAA,EACA;AACF;AAmDO,IAAM,YAAA,GAAe,CAA8B,MAAA,KAAmD;AAEtG,SAAS,gBAAgB,QAAA,EAAiC;AAC/D,E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AAA,OAAO,OAAA;AACT;AAGO,IAAM,YAAA,GAAqC","file":"index.js","sourcesContent":["import type { NoUnknownFields } from './exact'\n\n/** Maximum image dimensions in pixels: `[width, height]`. Both values must be positive integers. */\nexport type TextureSize = readonly [width: number, height: number]\n\ninterface SizedEncoding {\n /**\n * Maximum output dimensions in pixels. Aspect ratio is preserved, and an\n * image smaller than both limits is not enlarged. Omit this property to keep\n * the source dimensions.\n */\n maxSize?: TextureSize\n}\n\nexport interface WebpEncoding extends SizedEncoding {\n /** Encode the image as WebP. */\n codec: 'webp'\n /** Lossy quality from 1 (smallest, lowest fidelity) to 100. @defaultValue `75` */\n quality?: number\n /** Encoder effort from 0 (fastest) to 100 (slowest). @defaultValue `50` */\n effort?: number\n /** Use lossless WebP instead of lossy encoding. Lossy `quality` is then ignored. @defaultValue `false` */\n lossless?: boolean\n /**\n * Near-lossless preprocessing quality for lossless encoding, from 0\n * (strongest pixel changes and smallest output) to 100 (no preprocessing).\n *\n * @defaultValue `100`\n */\n nearLossless?: number\n}\n\nexport interface AvifEncoding extends SizedEncoding {\n /** Encode the image as AVIF. */\n codec: 'avif'\n /** Lossy quality from 1 (smallest, lowest fidelity) to 100. @defaultValue `50` */\n quality?: number\n /** Encoder effort from 0 (fastest) to 100 (slowest). @defaultValue `40` */\n effort?: number\n /** Use lossless AVIF instead of lossy encoding, overriding `quality` and chroma subsampling. @defaultValue `false` */\n lossless?: boolean\n /**\n * Chroma resolution: `4:2:0` reduces color detail for smaller files, while\n * `4:4:4` preserves full color resolution. Lossless encoding always uses\n * full color resolution.\n *\n * @defaultValue `'4:2:0'`\n */\n chromaSubsampling?: '4:2:0' | '4:4:4'\n}\n\nexport interface JpegEncoding extends SizedEncoding {\n /** Encode the image as JPEG. Alpha is not preserved. */\n codec: 'jpeg'\n /** Lossy quality from 1 (smallest, lowest fidelity) to 100. @defaultValue `75` */\n quality?: number\n /**\n * Chroma resolution: `4:2:0` reduces color detail for smaller files, while\n * `4:4:4` preserves full color resolution.\n *\n * @defaultValue `'4:2:0'`\n */\n chromaSubsampling?: '4:2:0' | '4:4:4'\n}\n\nexport interface PngEncoding extends SizedEncoding {\n /** Encode the image as lossless PNG. */\n codec: 'png'\n}\n\nexport interface UastcEncoding extends SizedEncoding {\n /** Encode the image in a GPU-ready KTX2 container. */\n codec: 'ktx2'\n /** Use high-quality UASTC block compression for LDR pixels. */\n mode: 'uastc'\n /**\n * How the texture is sampled: `srgb` for color data such as albedo and\n * emissive maps, or `linear` for data and normal maps.\n *\n * @defaultValue `'srgb'`\n */\n colorSpace?: 'srgb' | 'linear'\n /** Tune the encoder for tangent-space normal-map data. @defaultValue `false` */\n normalMap?: boolean\n /** Encoder effort from 0 (fastest) to 4 (slowest, highest quality). @defaultValue `2` */\n level?: 0 | 1 | 2 | 3 | 4\n /** Generate a complete mip chain for minified rendering. @defaultValue `true` */\n mipmaps?: boolean\n /** Apply Zstandard supercompression to reduce download size. @defaultValue `true` */\n zstd?: boolean\n /**\n * Enable rate-distortion optimization. This can substantially reduce files\n * at the cost of image fidelity; omit it to disable RDO.\n */\n rdo?: {\n /**\n * Compression-to-quality tradeoff from 0.001 to 10. Larger values usually\n * produce smaller files with more distortion.\n *\n * @defaultValue `1`\n */\n lambda?: number\n }\n}\n\nexport interface Etc1sEncoding extends SizedEncoding {\n /** Encode the image in a GPU-ready KTX2 container. */\n codec: 'ktx2'\n /** Use ETC1S compression for the smallest download size at lower fidelity than UASTC. */\n mode: 'etc1s'\n /**\n * How the texture is sampled: `srgb` for color data such as albedo and\n * emissive maps, or `linear` for data and normal maps.\n *\n * @defaultValue `'srgb'`\n */\n colorSpace?: 'srgb' | 'linear'\n /** Tune the encoder for tangent-space normal-map data. @defaultValue `false` */\n normalMap?: boolean\n /** Quality from 1 (smallest, lowest fidelity) to 255. @defaultValue `128` */\n quality?: number\n /**\n * Encoder effort from 0 (fastest) to 6 (slowest). Higher values search\n * harder for a smaller file at the requested quality.\n *\n * @defaultValue `1`\n */\n compression?: 0 | 1 | 2 | 3 | 4 | 5 | 6\n /** Generate a complete mip chain for minified rendering. @defaultValue `true` */\n mipmaps?: boolean\n}\n\n/**\n * UASTC HDR 4x4. Encodes half-float EXR source into blocks the runtime\n * transcodes to BC6H on desktop, or uploads as ASTC 4x4 SFLOAT where the HDR\n * profile exists. Fixed 8 bits per texel on the GPU regardless of source.\n *\n * Deliberately not a `SizedEncoding`: resizing runs on decoded 8-bit RGBA, and\n * there is no half-float resampler in the pipeline, so HDR sources must already\n * be authored at their target resolution.\n */\nexport interface UastcHdrEncoding {\n /** Encode the image in a GPU-ready KTX2 container. */\n codec: 'ktx2'\n /**\n * Use UASTC HDR for half-float EXR or Radiance HDR input. This mode does not\n * support resizing or alpha and is only available to standalone image recipes.\n */\n mode: 'uastc-hdr'\n /**\n * Encoder effort from 0 (fastest) to 4 (slowest). Higher levels rarely help\n * low-frequency content such as diffuse lightmaps.\n *\n * @defaultValue `1`\n */\n level?: 0 | 1 | 2 | 3 | 4\n /** Generate a complete mip chain for minified rendering. @defaultValue `true` */\n mipmaps?: boolean\n /** Apply Zstandard supercompression to reduce download size. @defaultValue `true` */\n zstd?: boolean\n}\n\nexport type RasterEncoding = WebpEncoding | AvifEncoding | JpegEncoding | PngEncoding\n\n/** Standalone, lossless RGBA8 texels. Color-space metadata never transforms samples. */\nexport type RawKtx2Encoding = {\n /** Store decoded RGBA8 pixels in KTX2. */\n codec: 'ktx2'\n /** Preserve original dimensions and every decoded RGBA8 byte, including transparent RGB. */\n mode: 'raw'\n /** Label unchanged samples; alpha is always linear. @defaultValue `'linear'` */\n colorSpace?: 'linear' | 'srgb'\n /** Raw mode stores exactly one base level. @defaultValue `false` */\n mipmaps?: false\n} & (\n | {\n /** Compress the texels for delivery; GPU storage remains RGBA8. @defaultValue `true` */\n zstd?: true\n /** Offline compression effort, integer 1–19; never changes fidelity. @defaultValue `19` */\n zstdLevel?: number\n }\n | {\n /** Store texels without supercompression. */\n zstd: false\n /** Effort is unavailable when Zstandard is disabled. */\n zstdLevel?: never\n }\n)\n\nexport type ImageEncoding = RasterEncoding | UastcEncoding | Etc1sEncoding | UastcHdrEncoding | RawKtx2Encoding\n\nexport type GlbProperty =\n | 'accessor'\n | 'animation'\n | 'buffer'\n | 'camera'\n | 'material'\n | 'mesh'\n | 'node'\n | 'primitive'\n | 'primitiveTarget'\n | 'skin'\n | 'texture'\n\nexport type GlbMethodRecipe =\n | {\n /** Merge equivalent accessors, materials, meshes, skins, or textures. */\n method: 'dedup'\n /** Keep otherwise-identical properties separate when their names differ. @defaultValue `false` */\n keepUniqueNames?: boolean\n /**\n * Property kinds to merge.\n *\n * @defaultValue `['accessor', 'material', 'mesh', 'skin', 'texture']`\n */\n propertyTypes?: readonly Extract<GlbProperty, 'accessor' | 'material' | 'mesh' | 'skin' | 'texture'>[]\n }\n | {\n /** Remove unused GLB properties and optionally simplify redundant data. */\n method: 'prune'\n /** Keep unused vertex attributes, such as UVs without an assigned texture. @defaultValue `false` */\n keepAttributes?: boolean\n /** Prevent a property with custom `extras` data from being removed. @defaultValue `false` */\n keepExtras?: boolean\n /** Keep empty leaf nodes that would otherwise be removed. @defaultValue `false` */\n keepLeaves?: boolean\n /** Keep single-color textures instead of replacing them with material factors. @defaultValue `false` */\n keepSolidTextures?: boolean\n /** Property kinds eligible for pruning. By default, every supported kind is eligible. */\n propertyTypes?: readonly GlbProperty[]\n }\n | {\n /** Remove redundant animation keyframes while keeping motion within a tolerance. */\n method: 'resample'\n /** Maximum permitted animation-value error. Must be greater than zero. @defaultValue `0.0001` */\n tolerance?: number\n /**\n * Deduplicate and prune temporary or unused resources after resampling.\n * Disable this when those resources must be preserved for a later step.\n *\n * @defaultValue `true`\n */\n cleanup?: boolean\n }\n\nexport type TextureSelector =\n | {\n /** Select textures by the material slots that reference them. */\n by: 'slot'\n /** glTF material texture-slot names, such as `baseColorTexture` or `normalTexture`. */\n slots: readonly string[]\n }\n | {\n /** Select textures by their authored GLB names. */\n by: 'name'\n /** Exact, case-sensitive texture names. Names should be unique within the GLB. */\n names: readonly string[]\n }\n | {\n /** Select textures by their zero-based order in the GLB. */\n by: 'index'\n /** Non-negative texture indices. Indices can change when a source GLB is re-exported. */\n indices: readonly number[]\n }\n\nexport interface EmbeddedTextureRecipe {\n /**\n * Unique, non-empty name for this texture group in progress events and\n * optimization reports. It does not rename textures in the GLB.\n */\n label: string\n /** Textures to encode. A texture cannot be claimed by more than one selector. */\n select: TextureSelector\n /** Output encoding for the selected textures. Raw RGBA8 and UASTC HDR are not supported inside GLBs. */\n encode: Exclude<ImageEncoding, RawKtx2Encoding>\n}\n\nexport type GeometryEncoding =\n | {\n /** Compress geometry with `KHR_draco_mesh_compression` for broad decoder support. */\n codec: 'draco'\n }\n | {\n /** Compress geometry with `EXT_meshopt_compression` for fast runtime decoding. */\n codec: 'meshopt'\n }\n\nexport interface GlbAssetRecipe {\n /** Optimize a binary glTF (`.glb`) asset. */\n kind: 'glb'\n /** Structural transforms to run in array order before texture and geometry encoding. @defaultValue `[]` */\n methods?: readonly GlbMethodRecipe[]\n /** Embedded texture groups to encode. Unselected textures keep their source encoding. @defaultValue `[]` */\n textures?: readonly EmbeddedTextureRecipe[]\n /** Geometry codec to apply, or `false` to leave geometry uncompressed. @defaultValue `false` */\n geometry?: GeometryEncoding | false\n}\n\nexport interface ImageAssetRecipe {\n /** Optimize a standalone raster or HDR image. */\n kind: 'image'\n /** Output codec and its quality, size, and performance tradeoffs. */\n encode: ImageEncoding\n}\n\nexport type AssetRecipe = GlbAssetRecipe | ImageAssetRecipe\n\nexport type NormalizedImageEncoding =\n | (Required<Omit<WebpEncoding, 'maxSize'>> & Pick<WebpEncoding, 'maxSize'>)\n | (Required<Omit<AvifEncoding, 'maxSize'>> & Pick<AvifEncoding, 'maxSize'>)\n | (Required<Omit<JpegEncoding, 'maxSize'>> & Pick<JpegEncoding, 'maxSize'>)\n | PngEncoding\n | (Required<Omit<UastcEncoding, 'maxSize' | 'rdo'>> & Pick<UastcEncoding, 'maxSize' | 'rdo'>)\n | (Required<Omit<Etc1sEncoding, 'maxSize'>> & Pick<Etc1sEncoding, 'maxSize'>)\n | Required<UastcHdrEncoding>\n | (Required<Pick<RawKtx2Encoding, 'codec' | 'mode' | 'colorSpace' | 'mipmaps'>> &\n ({ zstd: true; zstdLevel: number } | { zstd: false; zstdLevel?: never }))\n\nexport type NormalizedAssetRecipe =\n | {\n /** Identifies the normalized recipe as a standalone image recipe. */\n kind: 'image'\n /** Image encoding with every codec default resolved. */\n encode: NormalizedImageEncoding\n }\n | {\n /** Identifies the normalized recipe as a binary glTF recipe. */\n kind: 'glb'\n /** Structural transforms to run, with an omitted value resolved to an empty array. */\n methods: readonly GlbMethodRecipe[]\n /** Embedded texture groups with every codec default resolved. */\n textures: readonly (Omit<EmbeddedTextureRecipe, 'encode'> & {\n /** Output encoding with every codec default resolved. */\n encode: Exclude<NormalizedImageEncoding, RawKtx2Encoding>\n })[]\n /** Resolved geometry codec, or `false` when geometry compression is disabled. */\n geometry: GeometryEncoding | false\n }\n\nexport const COLOR_TEXTURE_SLOTS = [\n 'baseColorTexture',\n 'emissiveTexture',\n 'specularColorTexture',\n 'sheenColorTexture',\n] as const\n\nexport const DIRECTIONAL_TEXTURE_SLOTS = ['normalTexture', 'clearcoatNormalTexture', 'anisotropyTexture'] as const\n\nexport const DATA_TEXTURE_SLOTS = [\n 'occlusionTexture',\n 'metallicRoughnessTexture',\n 'specularTexture',\n 'clearcoatTexture',\n 'clearcoatRoughnessTexture',\n 'sheenRoughnessTexture',\n 'transmissionTexture',\n 'thicknessTexture',\n 'iridescenceTexture',\n 'iridescenceThicknessTexture',\n] as const\n\nexport const DEFAULT_GLB_RECIPE: GlbAssetRecipe = {\n kind: 'glb',\n methods: [],\n textures: [\n {\n label: 'color',\n select: { by: 'slot', slots: COLOR_TEXTURE_SLOTS },\n encode: {\n codec: 'ktx2',\n mode: 'uastc',\n colorSpace: 'srgb',\n level: 3,\n zstd: true,\n },\n },\n {\n label: 'directional',\n select: { by: 'slot', slots: DIRECTIONAL_TEXTURE_SLOTS },\n encode: {\n codec: 'ktx2',\n mode: 'uastc',\n colorSpace: 'linear',\n normalMap: true,\n level: 3,\n zstd: true,\n },\n },\n {\n label: 'data',\n select: { by: 'slot', slots: DATA_TEXTURE_SLOTS },\n encode: {\n codec: 'ktx2',\n mode: 'uastc',\n colorSpace: 'linear',\n level: 3,\n zstd: true,\n rdo: { lambda: 1 },\n },\n },\n ],\n geometry: { codec: 'draco' },\n}\n\nexport const DEFAULT_IMAGE_RECIPE: ImageAssetRecipe = {\n kind: 'image',\n encode: { codec: 'webp', quality: 85, effort: 80 },\n}\n\n/** Defines a type-checked optimization recipe while preserving its inferred literal types. */\nexport const defineRecipe = <const T extends AssetRecipe>(recipe: T & NoUnknownFields<T, AssetRecipe>): T => recipe\n\nexport function outputExtension(encoding: ImageEncoding): string {\n if (encoding.codec === 'ktx2') return '.ktx2'\n if (encoding.codec === 'jpeg') return '.jpg'\n return `.${encoding.codec}`\n}\n\nexport function outputMimeType(encoding: ImageEncoding): string {\n if (encoding.codec === 'ktx2') return 'image/ktx2'\n return `image/${encoding.codec}`\n}\n","export type ChopperErrorCode =\n | 'unsupported_asset'\n | 'invalid_recipe'\n | 'codec_load_failed'\n | 'decode_failed'\n | 'encode_failed'\n | 'validation_failed'\n | 'aborted'\n | 'io_failed'\n\nexport interface ChopperFailure {\n ok: false\n error: {\n code: ChopperErrorCode\n message: string\n cause?: unknown\n }\n}\n\nexport interface ChopperSuccess<T> {\n ok: true\n data: T\n}\n\nexport type ChopperResult<T> = ChopperSuccess<T> | ChopperFailure\n\nexport const success = <T>(data: T): ChopperSuccess<T> => ({ ok: true, data })\n\nexport const failure = (code: ChopperErrorCode, message: string, cause?: unknown): ChopperFailure => ({\n ok: false,\n error: cause === undefined ? { code, message } : { code, message, cause },\n})\n","export function unknownFieldIssue(\n value: Record<string, unknown>,\n allowedFields: readonly string[],\n subject: string\n): string | undefined {\n const field = Object.keys(value).find((key) => !allowedFields.includes(key))\n return field ? `Unknown ${subject} field: ${field}` : undefined\n}\n","import { failure, success, type ChopperResult } from './result'\nimport { unknownFieldIssue } from './object-validation'\nimport {\n type AssetRecipe,\n type EmbeddedTextureRecipe,\n type ImageEncoding,\n type NormalizedAssetRecipe,\n type NormalizedImageEncoding,\n type RawKtx2Encoding,\n type TextureSelector,\n} from './recipes'\n\nexport function validateRecipe(recipe: unknown): ChopperResult<AssetRecipe> {\n const shapeIssue = recipeShapeIssue(recipe)\n if (shapeIssue) return failure('invalid_recipe', shapeIssue)\n\n try {\n const typedRecipe = recipe as AssetRecipe\n const issue = recipeIssue(typedRecipe)\n return issue ? failure('invalid_recipe', issue) : success(typedRecipe)\n } catch {\n return failure('invalid_recipe', 'Recipe contains malformed fields')\n }\n}\n\nexport function normalizeRecipe(value: AssetRecipe): ChopperResult<NormalizedAssetRecipe> {\n const validated = validateRecipe(value)\n if (!validated.ok) return validated\n const recipe = validated.data\n\n if (recipe.kind === 'image') {\n return success({\n kind: 'image',\n encode: normalizeEncoding(recipe.encode),\n })\n }\n\n return success({\n kind: 'glb',\n methods: recipe.methods ?? [],\n textures: (recipe.textures ?? []).map((texture) => ({\n ...texture,\n encode: normalizeEncoding(texture.encode),\n })),\n geometry: recipe.geometry ?? false,\n })\n}\n\nfunction recipeShapeIssue(recipe: unknown): string | undefined {\n if (!recipe || typeof recipe !== 'object') return 'Recipe must be an object'\n const candidate = recipe as Record<string, unknown>\n if (candidate.kind !== 'image' && candidate.kind !== 'glb') {\n return `Unsupported recipe kind: ${String(candidate.kind)}`\n }\n\n if (candidate.kind === 'image') {\n const unknownField = unknownFieldIssue(candidate, ['kind', 'encode'], 'image recipe')\n if (unknownField) return unknownField\n return encodingShapeIssue(candidate.encode)\n }\n\n const unknownField = unknownFieldIssue(candidate, ['kind', 'methods', 'textures', 'geometry'], 'GLB recipe')\n if (unknownField) return unknownField\n\n if (candidate.methods !== undefined && !Array.isArray(candidate.methods)) {\n return 'GLB methods must be an array'\n }\n for (const method of (candidate.methods ?? []) as unknown[]) {\n if (!method || typeof method !== 'object') {\n return 'GLB methods contain an unsupported transform'\n }\n const entry = method as Record<string, unknown>\n if (!['dedup', 'prune', 'resample'].includes(String(entry.method))) {\n return 'GLB methods contain an unsupported transform'\n }\n const allowedFields =\n entry.method === 'dedup'\n ? ['method', 'keepUniqueNames', 'propertyTypes']\n : entry.method === 'prune'\n ? ['method', 'keepAttributes', 'keepExtras', 'keepLeaves', 'keepSolidTextures', 'propertyTypes']\n : ['method', 'tolerance', 'cleanup']\n const unknownField = unknownFieldIssue(entry, allowedFields, 'GLB method')\n if (unknownField) return unknownField\n }\n if (candidate.textures !== undefined && !Array.isArray(candidate.textures)) {\n return 'GLB textures must be an array'\n }\n for (const texture of (candidate.textures ?? []) as unknown[]) {\n if (!texture || typeof texture !== 'object') return 'Texture recipes must be objects'\n const entry = texture as Record<string, unknown>\n const unknownField = unknownFieldIssue(entry, ['label', 'select', 'encode'], 'texture recipe')\n if (unknownField) return unknownField\n if (typeof entry.label !== 'string') return 'Texture recipe labels must be strings'\n if (!entry.select || typeof entry.select !== 'object') return 'Texture recipes require a selector'\n const selector = entry.select as Record<string, unknown>\n if (!['slot', 'name', 'index'].includes(String(selector.by))) {\n return 'Texture recipe selectors are malformed'\n }\n const valueField = selector.by === 'slot' ? 'slots' : selector.by === 'name' ? 'names' : 'indices'\n const selectorUnknownField = unknownFieldIssue(selector, ['by', valueField], 'texture selector')\n if (selectorUnknownField) return selectorUnknownField\n if (!Array.isArray(selector[valueField])) return 'Texture recipe selectors are malformed'\n const encodingIssue = encodingShapeIssue(entry.encode)\n if (encodingIssue) return encodingIssue\n if ((entry.encode as ImageEncoding).codec === 'ktx2' && (entry.encode as { mode?: string }).mode === 'raw') {\n return `Texture recipe \"${entry.label}\" uses raw RGBA8, which KHR_texture_basisu does not cover; raw mode is only supported for standalone image recipes`\n }\n }\n if (\n candidate.geometry !== undefined &&\n candidate.geometry !== false &&\n (!candidate.geometry ||\n typeof candidate.geometry !== 'object' ||\n !['draco', 'meshopt'].includes(String((candidate.geometry as Record<string, unknown>).codec)))\n ) {\n return 'GLB geometry must be false, Draco, or Meshopt'\n }\n if (candidate.geometry && typeof candidate.geometry === 'object') {\n const geometryUnknownField = unknownFieldIssue(\n candidate.geometry as Record<string, unknown>,\n ['codec'],\n 'GLB geometry'\n )\n if (geometryUnknownField) return geometryUnknownField\n }\n return undefined\n}\n\nfunction encodingShapeIssue(encoding: unknown): string | undefined {\n if (!encoding || typeof encoding !== 'object') return 'Image encoding must be an object'\n const candidate = encoding as Record<string, unknown>\n if (!['webp', 'avif', 'jpeg', 'png', 'ktx2'].includes(String(candidate.codec))) {\n return `Unsupported image codec: ${String(candidate.codec)}`\n }\n if (\n candidate.codec === 'ktx2' &&\n candidate.mode !== 'uastc' &&\n candidate.mode !== 'etc1s' &&\n candidate.mode !== 'raw' &&\n candidate.mode !== 'uastc-hdr'\n ) {\n return `Unsupported KTX2 mode: ${String(candidate.mode)}`\n }\n if (candidate.codec === 'ktx2' && candidate.mode === 'uastc-hdr' && candidate.maxSize !== undefined) {\n return 'UASTC HDR does not support maxSize; resizing requires a decoded 8-bit image. Author the source at its target resolution.'\n }\n const allowedFields =\n candidate.codec === 'webp'\n ? ['codec', 'maxSize', 'quality', 'effort', 'lossless', 'nearLossless']\n : candidate.codec === 'avif'\n ? ['codec', 'maxSize', 'quality', 'effort', 'lossless', 'chromaSubsampling']\n : candidate.codec === 'jpeg'\n ? ['codec', 'maxSize', 'quality', 'chromaSubsampling']\n : candidate.codec === 'png'\n ? ['codec', 'maxSize']\n : candidate.mode === 'uastc'\n ? ['codec', 'mode', 'maxSize', 'colorSpace', 'normalMap', 'level', 'mipmaps', 'zstd', 'rdo']\n : candidate.mode === 'etc1s'\n ? ['codec', 'mode', 'maxSize', 'colorSpace', 'normalMap', 'quality', 'compression', 'mipmaps']\n : candidate.mode === 'raw'\n ? ['codec', 'mode', 'colorSpace', 'mipmaps', 'zstd', 'zstdLevel']\n : ['codec', 'mode', 'level', 'mipmaps', 'zstd']\n const unknownField = unknownFieldIssue(candidate, allowedFields, 'image encoding')\n if (unknownField) return unknownField\n if (\n candidate.codec === 'ktx2' &&\n candidate.mode === 'raw' &&\n candidate.zstd === false &&\n candidate.zstdLevel !== undefined\n ) {\n return 'Raw KTX2 zstdLevel requires Zstandard supercompression'\n }\n if (candidate.codec === 'ktx2' && candidate.mode === 'uastc' && candidate.rdo !== undefined) {\n if (!candidate.rdo || typeof candidate.rdo !== 'object' || Array.isArray(candidate.rdo)) {\n return 'UASTC RDO must be an object'\n }\n const rdoUnknownField = unknownFieldIssue(candidate.rdo as Record<string, unknown>, ['lambda'], 'UASTC RDO')\n if (rdoUnknownField) return rdoUnknownField\n }\n return undefined\n}\n\nfunction recipeIssue(recipe: AssetRecipe): string | undefined {\n if (recipe.kind === 'image') return encodingIssue(recipe.encode)\n\n const labels = new Set<string>()\n const selectors = new Set<string>()\n for (const texture of recipe.textures ?? []) {\n if (!texture.label) return 'Texture recipe labels cannot be empty'\n if (labels.has(texture.label)) {\n return `Duplicate texture recipe label: ${texture.label}`\n }\n labels.add(texture.label)\n\n const values = selectorValues(texture.select)\n if (!values.ok) return values.error.message\n if (!values.data.length) {\n return `Texture recipe \"${texture.label}\" has an empty selector`\n }\n for (const value of values.data) {\n const key = `${texture.select.by}:${value}`\n if (selectors.has(key)) {\n return `Texture selector appears in more than one recipe: ${key}`\n }\n selectors.add(key)\n }\n\n if (texture.encode.codec === 'ktx2' && texture.encode.mode === 'uastc-hdr') {\n return `Texture recipe \"${texture.label}\" uses UASTC HDR, which KHR_texture_basisu does not cover; HDR is only supported for standalone image recipes`\n }\n\n const issue = encodingIssue(texture.encode)\n if (issue) return issue\n }\n\n for (const method of recipe.methods ?? []) {\n if (method.method === 'resample' && (method.tolerance ?? 1e-4) <= 0) {\n return 'Resample tolerance must be greater than zero'\n }\n }\n\n return undefined\n}\n\nfunction selectorValues(selector: TextureSelector): ChopperResult<readonly (string | number)[]> {\n if (selector.by === 'slot') return success(selector.slots)\n if (selector.by === 'name') return success(selector.names)\n for (const index of selector.indices) {\n if (!Number.isInteger(index) || index < 0) {\n return failure('invalid_recipe', 'Texture indices must be non-negative integers')\n }\n }\n return success(selector.indices)\n}\n\nfunction encodingIssue(encoding: ImageEncoding): string | undefined {\n if (encoding.codec === 'ktx2' && encoding.mode === 'raw') {\n if (encoding.colorSpace !== undefined && encoding.colorSpace !== 'linear' && encoding.colorSpace !== 'srgb') {\n return 'Raw KTX2 colorSpace must be linear or srgb'\n }\n if (encoding.mipmaps !== undefined && encoding.mipmaps !== false) return 'Raw KTX2 mipmaps must be false'\n if (encoding.zstd !== undefined && typeof encoding.zstd !== 'boolean') return 'Raw KTX2 zstd must be a boolean'\n if (encoding.zstdLevel !== undefined) {\n if (!Number.isInteger(encoding.zstdLevel) || encoding.zstdLevel < 1 || encoding.zstdLevel > 19) {\n return 'Raw KTX2 zstdLevel must be an integer between 1 and 19'\n }\n }\n }\n if ('maxSize' in encoding && encoding.maxSize) {\n const [width, height] = encoding.maxSize\n if (!Number.isInteger(width) || width < 1 || !Number.isInteger(height) || height < 1) {\n return 'Texture maxSize must contain positive integers'\n }\n }\n\n if ('quality' in encoding && encoding.quality !== undefined) {\n const max = encoding.codec === 'ktx2' ? 255 : 100\n if (encoding.quality < 1 || encoding.quality > max) {\n return `${encoding.codec} quality must be between 1 and ${max}`\n }\n }\n\n if ('effort' in encoding && encoding.effort !== undefined) {\n if (encoding.effort < 0 || encoding.effort > 100) {\n return `${encoding.codec} effort must be between 0 and 100`\n }\n }\n\n if (\n encoding.codec === 'webp' &&\n encoding.nearLossless !== undefined &&\n (encoding.nearLossless < 0 || encoding.nearLossless > 100)\n ) {\n return 'WebP nearLossless must be between 0 and 100'\n }\n\n if (encoding.codec === 'ktx2' && encoding.mode === 'uastc') {\n if (\n encoding.level !== undefined &&\n (!Number.isInteger(encoding.level) || encoding.level < 0 || encoding.level > 4)\n ) {\n return 'UASTC level must be an integer between 0 and 4'\n }\n const lambda = encoding.rdo?.lambda\n if (lambda !== undefined && (lambda < 0.001 || lambda > 10)) {\n return 'UASTC RDO lambda must be between 0.001 and 10'\n }\n }\n\n if (\n encoding.codec === 'ktx2' &&\n encoding.mode === 'uastc-hdr' &&\n encoding.level !== undefined &&\n (!Number.isInteger(encoding.level) || encoding.level < 0 || encoding.level > 4)\n ) {\n return 'UASTC HDR level must be an integer between 0 and 4'\n }\n\n if (\n encoding.codec === 'ktx2' &&\n encoding.mode === 'etc1s' &&\n encoding.compression !== undefined &&\n (!Number.isInteger(encoding.compression) || encoding.compression < 0 || encoding.compression > 6)\n ) {\n return 'ETC1S compression must be an integer between 0 and 6'\n }\n\n return undefined\n}\n\nfunction normalizeEncoding(encoding: EmbeddedTextureRecipe['encode']): Exclude<NormalizedImageEncoding, RawKtx2Encoding>\nfunction normalizeEncoding(encoding: ImageEncoding): NormalizedImageEncoding\nfunction normalizeEncoding(encoding: ImageEncoding): NormalizedImageEncoding {\n switch (encoding.codec) {\n case 'webp':\n return {\n ...encoding,\n quality: encoding.quality ?? 75,\n effort: encoding.effort ?? 50,\n lossless: encoding.lossless ?? false,\n nearLossless: encoding.nearLossless ?? 100,\n }\n case 'avif':\n return {\n ...encoding,\n quality: encoding.quality ?? 50,\n effort: encoding.effort ?? 40,\n lossless: encoding.lossless ?? false,\n chromaSubsampling: encoding.chromaSubsampling ?? '4:2:0',\n }\n case 'jpeg':\n return {\n ...encoding,\n quality: encoding.quality ?? 75,\n chromaSubsampling: encoding.chromaSubsampling ?? '4:2:0',\n }\n case 'png':\n return { ...encoding }\n case 'ktx2':\n if (encoding.mode === 'raw') {\n return {\n codec: 'ktx2',\n mode: 'raw',\n colorSpace: encoding.colorSpace ?? 'linear',\n mipmaps: false,\n ...(encoding.zstd === false ? { zstd: false } : { zstd: true, zstdLevel: encoding.zstdLevel ?? 19 }),\n }\n }\n if (encoding.mode === 'uastc-hdr') {\n return {\n ...encoding,\n level: encoding.level ?? 1,\n mipmaps: encoding.mipmaps ?? true,\n zstd: encoding.zstd ?? true,\n }\n }\n if (encoding.mode === 'uastc') {\n return {\n ...encoding,\n colorSpace: encoding.colorSpace ?? 'srgb',\n normalMap: encoding.normalMap ?? false,\n level: encoding.level ?? 2,\n mipmaps: encoding.mipmaps ?? true,\n zstd: encoding.zstd ?? true,\n }\n }\n return {\n ...encoding,\n colorSpace: encoding.colorSpace ?? 'srgb',\n normalMap: encoding.normalMap ?? false,\n quality: encoding.quality ?? 128,\n compression: encoding.compression ?? 1,\n mipmaps: encoding.mipmaps ?? true,\n }\n }\n}\n","import { unknownFieldIssue } from '../core/object-validation'\nimport { failure, success, type ChopperResult } from '../core/result'\nimport { validateRecipe } from '../core/validation'\nimport type { EffectiveChopperConfig } from './types'\n\nexport const DEFAULT_BUILD_DIRECTORY = '.chopper'\nexport const DEFAULT_OUTPUT_DIRECTORY = 'compressed'\n\nexport function validateConfig(config: unknown): ChopperResult<EffectiveChopperConfig> {\n if (!config || typeof config !== 'object' || Array.isArray(config)) {\n return failure('invalid_recipe', 'Config must be an object')\n }\n const candidate = config as Record<string, unknown>\n const unknownField = unknownFieldIssue(\n candidate,\n ['buildDirectory', 'outputDirectory', 'rules', 'concurrency'],\n 'config'\n )\n if (unknownField) return failure('invalid_recipe', unknownField)\n if (\n candidate.buildDirectory !== undefined &&\n (typeof candidate.buildDirectory !== 'string' || !candidate.buildDirectory)\n ) {\n return failure('invalid_recipe', 'Config buildDirectory must be a non-empty string')\n }\n if (candidate.buildDirectory !== undefined && !isProjectRelativePath(candidate.buildDirectory, true)) {\n return failure(\n 'invalid_recipe',\n `Build directory must be a project-relative POSIX path: ${candidate.buildDirectory}`\n )\n }\n if (candidate.outputDirectory !== undefined && !isSafePathSegment(candidate.outputDirectory)) {\n return failure(\n 'invalid_recipe',\n `Config outputDirectory must be exactly one safe path segment: ${candidate.outputDirectory}`\n )\n }\n if (!Array.isArray(candidate.rules)) {\n return failure('invalid_recipe', 'Config rules must be an array')\n }\n if (\n candidate.concurrency !== undefined &&\n (typeof candidate.concurrency !== 'number' || !Number.isInteger(candidate.concurrency) || candidate.concurrency < 1)\n ) {\n return failure('invalid_recipe', 'Config concurrency must be a positive integer')\n }\n for (const [index, rule] of candidate.rules.entries()) {\n if (!rule || typeof rule !== 'object' || Array.isArray(rule)) {\n return failure('invalid_recipe', `Config rule ${index} must be an object`)\n }\n const entry = rule as Record<string, unknown>\n const ruleUnknownField = unknownFieldIssue(entry, ['include', 'exclude', 'recipe'], `config rule ${index}`)\n if (ruleUnknownField) return failure('invalid_recipe', ruleUnknownField)\n if (!isStringArray(entry.include)) {\n return failure('invalid_recipe', `Config rule ${index} include must be an array of glob patterns`)\n }\n if (entry.exclude !== undefined && !isStringArray(entry.exclude)) {\n return failure('invalid_recipe', `Config rule ${index} exclude must be an array of glob patterns`)\n }\n const invalidGlob = [...entry.include, ...((entry.exclude ?? []) as string[])].find(\n (pattern) => !isProjectRelativeGlob(pattern)\n )\n if (invalidGlob) {\n return failure('invalid_recipe', `Config rule ${index} glob must be project-relative: ${invalidGlob}`)\n }\n const recipe = validateRecipe(entry.recipe)\n if (!recipe.ok) return recipe\n }\n return success({\n ...config,\n buildDirectory: candidate.buildDirectory ?? DEFAULT_BUILD_DIRECTORY,\n outputDirectory: candidate.outputDirectory ?? DEFAULT_OUTPUT_DIRECTORY,\n } as EffectiveChopperConfig)\n}\n\nexport function normalizeProjectPath(path: unknown): string | undefined {\n if (typeof path !== 'string') return undefined\n if (!isProjectRelativePath(path, false)) return undefined\n const parts: string[] = []\n for (const part of path.split('/')) {\n if (!part || part === '.') continue\n if (part === '..') {\n if (!parts.length) return undefined\n parts.pop()\n } else {\n parts.push(part)\n }\n }\n return parts.join('/') || undefined\n}\n\nfunction isStringArray(value: unknown): value is string[] {\n return Array.isArray(value) && value.every((item) => typeof item === 'string' && item.length > 0)\n}\n\nfunction isSafePathSegment(value: unknown): value is string {\n return (\n typeof value === 'string' &&\n value.length > 0 &&\n value !== '.' &&\n value !== '..' &&\n !value.includes('/') &&\n !value.includes('\\\\') &&\n !value.includes('\\0') &&\n !value.includes(':')\n )\n}\n\nfunction isProjectRelativeGlob(pattern: string): boolean {\n const path = pattern.startsWith('!') && !pattern.startsWith('!(') ? pattern.slice(1) : pattern\n return (\n path.length > 0 &&\n !path.includes('\\0') &&\n !path.startsWith('/') &&\n !/^[A-Za-z]:\\//.test(path) &&\n !path.split('/').includes('..')\n )\n}\n\nfunction isProjectRelativePath(path: string, allowCurrentDirectory: boolean): boolean {\n if (!path || path.includes('\\\\') || path.includes('\\0') || path.startsWith('/') || /^[A-Za-z]:\\//.test(path)) {\n return false\n }\n const normalized = normalizeSegments(path)\n return normalized !== undefined && (allowCurrentDirectory || normalized !== '')\n}\n\nfunction normalizeSegments(path: string): string | undefined {\n const parts: string[] = []\n for (const part of path.split('/')) {\n if (!part || part === '.') continue\n if (part === '..') {\n if (!parts.length) return undefined\n parts.pop()\n } else {\n parts.push(part)\n }\n }\n return parts.join('/')\n}\n","import picomatch, { type PicomatchOptions } from 'picomatch'\n\nimport { outputExtension } from '../core/recipes'\nimport { failure, success, type ChopperResult } from '../core/result'\nimport type { ChopperConfig, ChopperRule, ConfigAssetPlanner, ConfigRoute, PlannedConfigAsset } from './types'\nimport { normalizeProjectPath, validateConfig } from './validation'\n\nconst GLOB_OPTIONS: PicomatchOptions = {\n dot: false,\n nobrace: false,\n nocase: false,\n noextglob: false,\n noglobstar: false,\n posix: true,\n}\n\ninterface PreparedRule {\n rule: ChopperRule\n matches(input: string): boolean\n}\n\ninterface PreparedConfig {\n outputDirectory: string\n rules: PreparedRule[]\n}\n\n/** Compiles one reusable, runtime-neutral planner for a Chopper config. */\nexport function createConfigAssetPlanner(config: ChopperConfig): ConfigAssetPlanner {\n let prepared: ChopperResult<PreparedConfig> | undefined\n\n const route = (input: string): ChopperResult<ConfigRoute> => {\n prepared ??= prepareRules(config)\n if (!prepared.ok) return prepared\n\n const normalizedInput = normalizeProjectPath(input)\n if (!normalizedInput) {\n return failure('invalid_recipe', `Asset input must be a project-relative POSIX path: ${input}`)\n }\n if (isGeneratedOutput(normalizedInput, prepared.data.outputDirectory)) {\n return success({ kind: 'output', input: normalizedInput })\n }\n\n const planned = new Map<string, PlannedConfigAsset>()\n for (const { rule, matches } of prepared.data.rules) {\n if (!matches(normalizedInput)) continue\n const output = resolveOutput(rule, normalizedInput, prepared.data.outputDirectory)\n planned.set(output, { input: normalizedInput, output, rule })\n }\n const outputs = [...planned.values()]\n return outputs.length\n ? success({ kind: 'source', input: normalizedInput, outputs })\n : success({ kind: 'unmatched', input: normalizedInput })\n }\n\n const resolve = (input: string): ChopperResult<PlannedConfigAsset[]> => {\n const routed = route(input)\n if (!routed.ok) return routed\n return success(routed.data.kind === 'source' ? routed.data.outputs : [])\n }\n\n return { route, resolve }\n}\n\nfunction prepareRules(config: ChopperConfig): ChopperResult<PreparedConfig> {\n const validated = validateConfig(config)\n if (!validated.ok) return validated\n\n try {\n return success({\n outputDirectory: validated.data.outputDirectory,\n rules: validated.data.rules.map((rule) => ({ rule, matches: compileRuleMatcher(rule) })),\n })\n } catch (cause) {\n return failure('invalid_recipe', 'Config contains an invalid glob pattern', cause)\n }\n}\n\nfunction compileRuleMatcher(rule: ChopperRule): (input: string) => boolean {\n const includePatterns: string[] = []\n const ignorePatterns = (rule.exclude ?? []).filter((pattern) => !pattern.startsWith('!') || pattern.startsWith('!('))\n for (const pattern of rule.include) {\n if (pattern.startsWith('!') && !pattern.startsWith('!(')) {\n if (!pattern.startsWith('!!') || pattern.startsWith('!!(')) ignorePatterns.push(pattern.slice(1))\n } else {\n includePatterns.push(pattern)\n }\n }\n\n const include = picomatch(includePatterns.map(expandDirectoryPattern), GLOB_OPTIONS)\n const ignore = picomatch(ignorePatterns.map(expandDirectoryPattern), GLOB_OPTIONS)\n return (input) => include(input) && !ignore(input)\n}\n\nfunction expandDirectoryPattern(pattern: string): string {\n const normalized =\n pattern\n .split('/')\n .filter((segment) => segment && segment !== '.')\n .join('/') || '**'\n const withoutTrailingSlash = normalized.endsWith('/') ? normalized.slice(0, -1) : normalized\n return withoutTrailingSlash.endsWith('*') ? withoutTrailingSlash : `${withoutTrailingSlash}/**`\n}\n\nfunction resolveOutput(rule: ChopperRule, input: string, outputDirectory: string): string {\n const slash = input.lastIndexOf('/')\n const directory = slash < 0 ? '' : input.slice(0, slash)\n const base = slash < 0 ? input : input.slice(slash + 1)\n const dot = base.lastIndexOf('.')\n const name = dot <= 0 ? base : base.slice(0, dot)\n const extension = rule.recipe.kind === 'glb' ? '.glb' : outputExtension(rule.recipe.encode)\n\n return `${directory ? `${directory}/` : ''}${outputDirectory}/${name}${extension}`\n}\n\nfunction isGeneratedOutput(input: string, outputDirectory: string): boolean {\n return input.split('/').slice(0, -1).includes(outputDirectory)\n}\n","import type { NoUnknownFields } from '../core/exact'\nimport { createConfigAssetPlanner } from './planner'\nimport type { ChopperConfig, ConfiguredChopper } from './types'\nimport { DEFAULT_BUILD_DIRECTORY, DEFAULT_OUTPUT_DIRECTORY } from './validation'\n\nexport { COLOR_TEXTURE_SLOTS, DATA_TEXTURE_SLOTS, DIRECTIONAL_TEXTURE_SLOTS, defineRecipe } from '../core/recipes'\nexport type {\n ChopperConfig,\n ChopperRule,\n ConfigAssetPlanner,\n ConfigRoute,\n ConfiguredChopper,\n PlannedConfigAsset,\n} from './types'\n\n/**\n * Defines a type-checked Chopper project config and binds a browser-safe asset\n * planner to it while preserving its inferred literal types.\n */\nexport function createChopper<const T extends ChopperConfig>(\n config: T & NoUnknownFields<T, ChopperConfig>\n): ConfiguredChopper<T> {\n const { buildDirectory = DEFAULT_BUILD_DIRECTORY, outputDirectory = DEFAULT_OUTPUT_DIRECTORY, ...rest } = config\n const defined = { buildDirectory, outputDirectory, ...rest } as unknown as ConfiguredChopper<T>\n const planner = createConfigAssetPlanner(defined)\n Object.defineProperties(defined, {\n route: { enumerable: false, value: planner.route },\n resolve: { enumerable: false, value: planner.resolve },\n })\n return defined\n}\n\n/** @deprecated Use {@link createChopper} instead. */\nexport const defineConfig: typeof createChopper = createChopper\n"]}