@joycostudio/chopper 0.5.2 → 0.5.3

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.
@@ -4,53 +4,126 @@ type NoUnknownFields<Actual, Expected> = Expected extends unknown ? Actual exten
4
4
  [Key in keyof Actual]: Key extends keyof Expected ? NoUnknownFields<Actual[Key], Expected[Key]> : never;
5
5
  } : never : Actual : never : never;
6
6
 
7
+ /** Maximum image dimensions in pixels: `[width, height]`. Both values must be positive integers. */
7
8
  type TextureSize = readonly [width: number, height: number];
8
9
  interface SizedEncoding {
9
- /** Maximum dimensions. Aspect ratio is preserved and images are not enlarged. */
10
+ /**
11
+ * Maximum output dimensions in pixels. Aspect ratio is preserved, and an
12
+ * image smaller than both limits is not enlarged. Omit this property to keep
13
+ * the source dimensions.
14
+ */
10
15
  maxSize?: TextureSize;
11
16
  }
12
17
  interface WebpEncoding extends SizedEncoding {
18
+ /** Encode the image as WebP. */
13
19
  codec: 'webp';
20
+ /** Lossy quality from 1 (smallest, lowest fidelity) to 100. @defaultValue `75` */
14
21
  quality?: number;
22
+ /** Encoder effort from 0 (fastest) to 100 (slowest). @defaultValue `50` */
15
23
  effort?: number;
24
+ /** Use lossless WebP instead of lossy encoding. Lossy `quality` is then ignored. @defaultValue `false` */
16
25
  lossless?: boolean;
17
- /** WebP near-lossless preprocessing strength, from 0 (lossy) to 100. */
26
+ /**
27
+ * Near-lossless preprocessing quality for lossless encoding, from 0
28
+ * (strongest pixel changes and smallest output) to 100 (no preprocessing).
29
+ *
30
+ * @defaultValue `100`
31
+ */
18
32
  nearLossless?: number;
19
33
  }
20
34
  interface AvifEncoding extends SizedEncoding {
35
+ /** Encode the image as AVIF. */
21
36
  codec: 'avif';
37
+ /** Lossy quality from 1 (smallest, lowest fidelity) to 100. @defaultValue `50` */
22
38
  quality?: number;
39
+ /** Encoder effort from 0 (fastest) to 100 (slowest). @defaultValue `40` */
23
40
  effort?: number;
41
+ /** Use lossless AVIF instead of lossy encoding, overriding `quality` and chroma subsampling. @defaultValue `false` */
24
42
  lossless?: boolean;
43
+ /**
44
+ * Chroma resolution: `4:2:0` reduces color detail for smaller files, while
45
+ * `4:4:4` preserves full color resolution. Lossless encoding always uses
46
+ * full color resolution.
47
+ *
48
+ * @defaultValue `'4:2:0'`
49
+ */
25
50
  chromaSubsampling?: '4:2:0' | '4:4:4';
26
51
  }
27
52
  interface JpegEncoding extends SizedEncoding {
53
+ /** Encode the image as JPEG. Alpha is not preserved. */
28
54
  codec: 'jpeg';
55
+ /** Lossy quality from 1 (smallest, lowest fidelity) to 100. @defaultValue `75` */
29
56
  quality?: number;
57
+ /**
58
+ * Chroma resolution: `4:2:0` reduces color detail for smaller files, while
59
+ * `4:4:4` preserves full color resolution.
60
+ *
61
+ * @defaultValue `'4:2:0'`
62
+ */
30
63
  chromaSubsampling?: '4:2:0' | '4:4:4';
31
64
  }
32
65
  interface PngEncoding extends SizedEncoding {
66
+ /** Encode the image as lossless PNG. */
33
67
  codec: 'png';
34
68
  }
35
69
  interface UastcEncoding extends SizedEncoding {
70
+ /** Encode the image in a GPU-ready KTX2 container. */
36
71
  codec: 'ktx2';
72
+ /** Use high-quality UASTC block compression for LDR pixels. */
37
73
  mode: 'uastc';
74
+ /**
75
+ * How the texture is sampled: `srgb` for color data such as albedo and
76
+ * emissive maps, or `linear` for data and normal maps.
77
+ *
78
+ * @defaultValue `'srgb'`
79
+ */
38
80
  colorSpace?: 'srgb' | 'linear';
81
+ /** Tune the encoder for tangent-space normal-map data. @defaultValue `false` */
39
82
  normalMap?: boolean;
83
+ /** Encoder effort from 0 (fastest) to 4 (slowest, highest quality). @defaultValue `2` */
40
84
  level?: 0 | 1 | 2 | 3 | 4;
85
+ /** Generate a complete mip chain for minified rendering. @defaultValue `true` */
41
86
  mipmaps?: boolean;
87
+ /** Apply Zstandard supercompression to reduce download size. @defaultValue `true` */
42
88
  zstd?: boolean;
89
+ /**
90
+ * Enable rate-distortion optimization. This can substantially reduce files
91
+ * at the cost of image fidelity; omit it to disable RDO.
92
+ */
43
93
  rdo?: {
94
+ /**
95
+ * Compression-to-quality tradeoff from 0.001 to 10. Larger values usually
96
+ * produce smaller files with more distortion.
97
+ *
98
+ * @defaultValue `1`
99
+ */
44
100
  lambda?: number;
45
101
  };
46
102
  }
47
103
  interface Etc1sEncoding extends SizedEncoding {
104
+ /** Encode the image in a GPU-ready KTX2 container. */
48
105
  codec: 'ktx2';
106
+ /** Use ETC1S compression for the smallest download size at lower fidelity than UASTC. */
49
107
  mode: 'etc1s';
108
+ /**
109
+ * How the texture is sampled: `srgb` for color data such as albedo and
110
+ * emissive maps, or `linear` for data and normal maps.
111
+ *
112
+ * @defaultValue `'srgb'`
113
+ */
50
114
  colorSpace?: 'srgb' | 'linear';
115
+ /** Tune the encoder for tangent-space normal-map data. @defaultValue `false` */
51
116
  normalMap?: boolean;
117
+ /** Quality from 1 (smallest, lowest fidelity) to 255. @defaultValue `128` */
52
118
  quality?: number;
119
+ /**
120
+ * Encoder effort from 0 (fastest) to 6 (slowest). Higher values search
121
+ * harder for a smaller file at the requested quality.
122
+ *
123
+ * @defaultValue `1`
124
+ */
53
125
  compression?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
126
+ /** Generate a complete mip chain for minified rendering. @defaultValue `true` */
54
127
  mipmaps?: boolean;
55
128
  }
56
129
  /**
@@ -63,75 +136,150 @@ interface Etc1sEncoding extends SizedEncoding {
63
136
  * be authored at their target resolution.
64
137
  */
65
138
  interface UastcHdrEncoding {
139
+ /** Encode the image in a GPU-ready KTX2 container. */
66
140
  codec: 'ktx2';
141
+ /**
142
+ * Use UASTC HDR for half-float EXR or Radiance HDR input. This mode does not
143
+ * support resizing or alpha and is only available to standalone image recipes.
144
+ */
67
145
  mode: 'uastc-hdr';
68
- /** Encoder effort. Higher is slower; rarely helps on low-frequency lightmaps. */
146
+ /**
147
+ * Encoder effort from 0 (fastest) to 4 (slowest). Higher levels rarely help
148
+ * low-frequency content such as diffuse lightmaps.
149
+ *
150
+ * @defaultValue `1`
151
+ */
69
152
  level?: 0 | 1 | 2 | 3 | 4;
153
+ /** Generate a complete mip chain for minified rendering. @defaultValue `true` */
70
154
  mipmaps?: boolean;
155
+ /** Apply Zstandard supercompression to reduce download size. @defaultValue `true` */
71
156
  zstd?: boolean;
72
157
  }
73
158
  type RasterEncoding = WebpEncoding | AvifEncoding | JpegEncoding | PngEncoding;
74
159
  type ImageEncoding = RasterEncoding | UastcEncoding | Etc1sEncoding | UastcHdrEncoding;
75
160
  type GlbProperty = 'accessor' | 'animation' | 'buffer' | 'camera' | 'material' | 'mesh' | 'node' | 'primitive' | 'primitiveTarget' | 'skin' | 'texture';
76
161
  type GlbMethodRecipe = {
162
+ /** Merge equivalent accessors, materials, meshes, skins, or textures. */
77
163
  method: 'dedup';
164
+ /** Keep otherwise-identical properties separate when their names differ. @defaultValue `false` */
78
165
  keepUniqueNames?: boolean;
166
+ /**
167
+ * Property kinds to merge.
168
+ *
169
+ * @defaultValue `['accessor', 'material', 'mesh', 'skin', 'texture']`
170
+ */
79
171
  propertyTypes?: readonly Extract<GlbProperty, 'accessor' | 'material' | 'mesh' | 'skin' | 'texture'>[];
80
172
  } | {
173
+ /** Remove unused GLB properties and optionally simplify redundant data. */
81
174
  method: 'prune';
175
+ /** Keep unused vertex attributes, such as UVs without an assigned texture. @defaultValue `false` */
82
176
  keepAttributes?: boolean;
177
+ /** Prevent a property with custom `extras` data from being removed. @defaultValue `false` */
83
178
  keepExtras?: boolean;
179
+ /** Keep empty leaf nodes that would otherwise be removed. @defaultValue `false` */
84
180
  keepLeaves?: boolean;
181
+ /** Keep single-color textures instead of replacing them with material factors. @defaultValue `false` */
85
182
  keepSolidTextures?: boolean;
183
+ /** Property kinds eligible for pruning. By default, every supported kind is eligible. */
86
184
  propertyTypes?: readonly GlbProperty[];
87
185
  } | {
186
+ /** Remove redundant animation keyframes while keeping motion within a tolerance. */
88
187
  method: 'resample';
188
+ /** Maximum permitted animation-value error. Must be greater than zero. @defaultValue `0.0001` */
89
189
  tolerance?: number;
190
+ /**
191
+ * Deduplicate and prune temporary or unused resources after resampling.
192
+ * Disable this when those resources must be preserved for a later step.
193
+ *
194
+ * @defaultValue `true`
195
+ */
90
196
  cleanup?: boolean;
91
197
  };
92
198
  type TextureSelector = {
199
+ /** Select textures by the material slots that reference them. */
93
200
  by: 'slot';
201
+ /** glTF material texture-slot names, such as `baseColorTexture` or `normalTexture`. */
94
202
  slots: readonly string[];
95
203
  } | {
204
+ /** Select textures by their authored GLB names. */
96
205
  by: 'name';
206
+ /** Exact, case-sensitive texture names. Names should be unique within the GLB. */
97
207
  names: readonly string[];
98
208
  } | {
209
+ /** Select textures by their zero-based order in the GLB. */
99
210
  by: 'index';
211
+ /** Non-negative texture indices. Indices can change when a source GLB is re-exported. */
100
212
  indices: readonly number[];
101
213
  };
102
214
  interface EmbeddedTextureRecipe {
215
+ /**
216
+ * Unique, non-empty name for this texture group in progress events and
217
+ * optimization reports. It does not rename textures in the GLB.
218
+ */
103
219
  label: string;
220
+ /** Textures to encode. A texture cannot be claimed by more than one selector. */
104
221
  select: TextureSelector;
222
+ /** Output encoding for the selected textures. UASTC HDR is not supported inside GLBs. */
105
223
  encode: ImageEncoding;
106
224
  }
107
225
  type GeometryEncoding = {
226
+ /** Compress geometry with `KHR_draco_mesh_compression` for broad decoder support. */
108
227
  codec: 'draco';
109
228
  } | {
229
+ /** Compress geometry with `EXT_meshopt_compression` for fast runtime decoding. */
110
230
  codec: 'meshopt';
111
231
  };
112
232
  interface GlbAssetRecipe {
233
+ /** Optimize a binary glTF (`.glb`) asset. */
113
234
  kind: 'glb';
235
+ /** Structural transforms to run in array order before texture and geometry encoding. @defaultValue `[]` */
114
236
  methods?: readonly GlbMethodRecipe[];
237
+ /** Embedded texture groups to encode. Unselected textures keep their source encoding. @defaultValue `[]` */
115
238
  textures?: readonly EmbeddedTextureRecipe[];
239
+ /** Geometry codec to apply, or `false` to leave geometry uncompressed. @defaultValue `false` */
116
240
  geometry?: GeometryEncoding | false;
117
241
  }
118
242
  interface ImageAssetRecipe {
243
+ /** Optimize a standalone raster or HDR image. */
119
244
  kind: 'image';
245
+ /** Output codec and its quality, size, and performance tradeoffs. */
120
246
  encode: ImageEncoding;
121
247
  }
122
248
  type AssetRecipe = GlbAssetRecipe | ImageAssetRecipe;
123
249
  declare const COLOR_TEXTURE_SLOTS: readonly ["baseColorTexture", "emissiveTexture", "specularColorTexture", "sheenColorTexture"];
124
250
  declare const DIRECTIONAL_TEXTURE_SLOTS: readonly ["normalTexture", "clearcoatNormalTexture", "anisotropyTexture"];
125
251
  declare const DATA_TEXTURE_SLOTS: readonly ["occlusionTexture", "metallicRoughnessTexture", "specularTexture", "clearcoatTexture", "clearcoatRoughnessTexture", "sheenRoughnessTexture", "transmissionTexture", "thicknessTexture", "iridescenceTexture", "iridescenceThicknessTexture"];
252
+ /** Defines a type-checked optimization recipe while preserving its inferred literal types. */
126
253
  declare const defineRecipe: <const T extends AssetRecipe>(recipe: T & NoUnknownFields<T, AssetRecipe>) => T;
127
254
 
128
255
  interface ChopperRule {
256
+ /**
257
+ * Glob patterns for source assets, evaluated relative to the project directory.
258
+ * A rule runs once for every file matched by at least one pattern.
259
+ */
129
260
  include: readonly string[];
261
+ /**
262
+ * Glob patterns removed from `include` matches, evaluated relative to the
263
+ * project directory. Omit this property to exclude nothing.
264
+ */
130
265
  exclude?: readonly string[];
266
+ /** Optimization recipe applied to every asset matched by this rule. */
131
267
  recipe: AssetRecipe;
268
+ /**
269
+ * Output path template relative to {@link ChopperConfig.output}. Supports
270
+ * `{dir}` (source directory), `{name}` (source basename), and `{ext}`
271
+ * (recipe output extension).
272
+ *
273
+ * @defaultValue `'{dir}/{name}.{ext}'`
274
+ */
132
275
  path?: string;
133
276
  }
134
277
  interface ChopperConfig {
278
+ /**
279
+ * Directory where optimized assets are written. Relative paths are resolved
280
+ * from the project directory, and the resolved directory must remain inside
281
+ * the project.
282
+ */
135
283
  output: string;
136
284
  /**
137
285
  * Every rule matches independently, so one file can be claimed by several of
@@ -141,8 +289,16 @@ interface ChopperConfig {
141
289
  * one input can still fan out to several encodings.
142
290
  */
143
291
  rules: readonly ChopperRule[];
292
+ /**
293
+ * Maximum number of assets optimized at the same time. Must be a positive
294
+ * integer; lower values reduce peak CPU and memory use, while higher values
295
+ * may finish a batch sooner.
296
+ *
297
+ * @defaultValue `2`
298
+ */
144
299
  concurrency?: number;
145
300
  }
301
+ /** Defines a type-checked Chopper project config while preserving its inferred literal types. */
146
302
  declare const defineConfig: <const T extends ChopperConfig>(config: T & NoUnknownFields<T, ChopperConfig>) => T;
147
303
 
148
304
  export { COLOR_TEXTURE_SLOTS, type ChopperConfig, type ChopperRule, DATA_TEXTURE_SLOTS, DIRECTIONAL_TEXTURE_SLOTS, defineConfig, defineRecipe };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/recipes.ts","../../src/config/index.ts"],"names":[],"mappings":";AAkKO,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;AAkDO,IAAM,YAAA,GAAe,CAA8B,MAAA,KAAmD;;;AC/MtG,IAAM,YAAA,GAAe,CAAgC,MAAA,KAAqD","file":"index.js","sourcesContent":["import type { NoUnknownFields } from './exact'\n\nexport type TextureSize = readonly [width: number, height: number]\n\ninterface SizedEncoding {\n /** Maximum dimensions. Aspect ratio is preserved and images are not enlarged. */\n maxSize?: TextureSize\n}\n\nexport interface WebpEncoding extends SizedEncoding {\n codec: 'webp'\n quality?: number\n effort?: number\n lossless?: boolean\n /** WebP near-lossless preprocessing strength, from 0 (lossy) to 100. */\n nearLossless?: number\n}\n\nexport interface AvifEncoding extends SizedEncoding {\n codec: 'avif'\n quality?: number\n effort?: number\n lossless?: boolean\n chromaSubsampling?: '4:2:0' | '4:4:4'\n}\n\nexport interface JpegEncoding extends SizedEncoding {\n codec: 'jpeg'\n quality?: number\n chromaSubsampling?: '4:2:0' | '4:4:4'\n}\n\nexport interface PngEncoding extends SizedEncoding {\n codec: 'png'\n}\n\nexport interface UastcEncoding extends SizedEncoding {\n codec: 'ktx2'\n mode: 'uastc'\n colorSpace?: 'srgb' | 'linear'\n normalMap?: boolean\n level?: 0 | 1 | 2 | 3 | 4\n mipmaps?: boolean\n zstd?: boolean\n rdo?: { lambda?: number }\n}\n\nexport interface Etc1sEncoding extends SizedEncoding {\n codec: 'ktx2'\n mode: 'etc1s'\n colorSpace?: 'srgb' | 'linear'\n normalMap?: boolean\n quality?: number\n compression?: 0 | 1 | 2 | 3 | 4 | 5 | 6\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 codec: 'ktx2'\n mode: 'uastc-hdr'\n /** Encoder effort. Higher is slower; rarely helps on low-frequency lightmaps. */\n level?: 0 | 1 | 2 | 3 | 4\n mipmaps?: boolean\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 method: 'dedup'\n keepUniqueNames?: boolean\n propertyTypes?: readonly Extract<GlbProperty, 'accessor' | 'material' | 'mesh' | 'skin' | 'texture'>[]\n }\n | {\n method: 'prune'\n keepAttributes?: boolean\n keepExtras?: boolean\n keepLeaves?: boolean\n keepSolidTextures?: boolean\n propertyTypes?: readonly GlbProperty[]\n }\n | {\n method: 'resample'\n tolerance?: number\n cleanup?: boolean\n }\n\nexport type TextureSelector =\n | { by: 'slot'; slots: readonly string[] }\n | { by: 'name'; names: readonly string[] }\n | { by: 'index'; indices: readonly number[] }\n\nexport interface EmbeddedTextureRecipe {\n label: string\n select: TextureSelector\n encode: ImageEncoding\n}\n\nexport type GeometryEncoding = { codec: 'draco' } | { codec: 'meshopt' }\n\nexport interface GlbAssetRecipe {\n kind: 'glb'\n methods?: readonly GlbMethodRecipe[]\n textures?: readonly EmbeddedTextureRecipe[]\n geometry?: GeometryEncoding | false\n}\n\nexport interface ImageAssetRecipe {\n kind: 'image'\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 kind: 'image'\n encode: NormalizedImageEncoding\n }\n | {\n kind: 'glb'\n methods: readonly GlbMethodRecipe[]\n textures: readonly (Omit<EmbeddedTextureRecipe, 'encode'> & {\n encode: NormalizedImageEncoding\n })[]\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\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","import type { AssetRecipe } from '../core/recipes'\nimport type { NoUnknownFields } from '../core/exact'\n\nexport { COLOR_TEXTURE_SLOTS, DATA_TEXTURE_SLOTS, DIRECTIONAL_TEXTURE_SLOTS, defineRecipe } from '../core/recipes'\n\nexport interface ChopperRule {\n include: readonly string[]\n exclude?: readonly string[]\n recipe: AssetRecipe\n path?: string\n}\n\nexport interface ChopperConfig {\n output: string\n /**\n * Every rule matches independently, so one file can be claimed by several of\n * them. Where two rules resolve the same output path for the same input, the\n * later rule wins: state the general strategy first and narrow it with\n * exceptions after. Rules that resolve to different output paths all run, so\n * one input can still fan out to several encodings.\n */\n rules: readonly ChopperRule[]\n concurrency?: number\n}\n\nexport const defineConfig = <const T extends ChopperConfig>(config: T & NoUnknownFields<T, ChopperConfig>): T => config\n"]}
1
+ {"version":3,"sources":["../../src/core/recipes.ts","../../src/config/index.ts"],"names":[],"mappings":";AAwTO,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;;;ACzUtG,IAAM,YAAA,GAAe,CAAgC,MAAA,KAAqD","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","import type { AssetRecipe } from '../core/recipes'\nimport type { NoUnknownFields } from '../core/exact'\n\nexport { COLOR_TEXTURE_SLOTS, DATA_TEXTURE_SLOTS, DIRECTIONAL_TEXTURE_SLOTS, defineRecipe } from '../core/recipes'\n\nexport interface ChopperRule {\n /**\n * Glob patterns for source assets, evaluated relative to the project directory.\n * A rule runs once for every file matched by at least one pattern.\n */\n include: readonly string[]\n /**\n * Glob patterns removed from `include` matches, evaluated relative to the\n * project directory. Omit this property to exclude nothing.\n */\n exclude?: readonly string[]\n /** Optimization recipe applied to every asset matched by this rule. */\n recipe: AssetRecipe\n /**\n * Output path template relative to {@link ChopperConfig.output}. Supports\n * `{dir}` (source directory), `{name}` (source basename), and `{ext}`\n * (recipe output extension).\n *\n * @defaultValue `'{dir}/{name}.{ext}'`\n */\n path?: string\n}\n\nexport interface ChopperConfig {\n /**\n * Directory where optimized assets are written. Relative paths are resolved\n * from the project directory, and the resolved directory must remain inside\n * the project.\n */\n output: string\n /**\n * Every rule matches independently, so one file can be claimed by several of\n * them. Where two rules resolve the same output path for the same input, the\n * later rule wins: state the general strategy first and narrow it with\n * exceptions after. Rules that resolve to different output paths all run, so\n * one input can still fan out to several encodings.\n */\n rules: readonly ChopperRule[]\n /**\n * Maximum number of assets optimized at the same time. Must be a positive\n * integer; lower values reduce peak CPU and memory use, while higher values\n * may finish a batch sooner.\n *\n * @defaultValue `2`\n */\n concurrency?: number\n}\n\n/** Defines a type-checked Chopper project config while preserving its inferred literal types. */\nexport const defineConfig = <const T extends ChopperConfig>(config: T & NoUnknownFields<T, ChopperConfig>): T => config\n"]}
package/dist/index.d.ts CHANGED
@@ -4,53 +4,126 @@ type NoUnknownFields<Actual, Expected> = Expected extends unknown ? Actual exten
4
4
  [Key in keyof Actual]: Key extends keyof Expected ? NoUnknownFields<Actual[Key], Expected[Key]> : never;
5
5
  } : never : Actual : never : never;
6
6
 
7
+ /** Maximum image dimensions in pixels: `[width, height]`. Both values must be positive integers. */
7
8
  type TextureSize = readonly [width: number, height: number];
8
9
  interface SizedEncoding {
9
- /** Maximum dimensions. Aspect ratio is preserved and images are not enlarged. */
10
+ /**
11
+ * Maximum output dimensions in pixels. Aspect ratio is preserved, and an
12
+ * image smaller than both limits is not enlarged. Omit this property to keep
13
+ * the source dimensions.
14
+ */
10
15
  maxSize?: TextureSize;
11
16
  }
12
17
  interface WebpEncoding extends SizedEncoding {
18
+ /** Encode the image as WebP. */
13
19
  codec: 'webp';
20
+ /** Lossy quality from 1 (smallest, lowest fidelity) to 100. @defaultValue `75` */
14
21
  quality?: number;
22
+ /** Encoder effort from 0 (fastest) to 100 (slowest). @defaultValue `50` */
15
23
  effort?: number;
24
+ /** Use lossless WebP instead of lossy encoding. Lossy `quality` is then ignored. @defaultValue `false` */
16
25
  lossless?: boolean;
17
- /** WebP near-lossless preprocessing strength, from 0 (lossy) to 100. */
26
+ /**
27
+ * Near-lossless preprocessing quality for lossless encoding, from 0
28
+ * (strongest pixel changes and smallest output) to 100 (no preprocessing).
29
+ *
30
+ * @defaultValue `100`
31
+ */
18
32
  nearLossless?: number;
19
33
  }
20
34
  interface AvifEncoding extends SizedEncoding {
35
+ /** Encode the image as AVIF. */
21
36
  codec: 'avif';
37
+ /** Lossy quality from 1 (smallest, lowest fidelity) to 100. @defaultValue `50` */
22
38
  quality?: number;
39
+ /** Encoder effort from 0 (fastest) to 100 (slowest). @defaultValue `40` */
23
40
  effort?: number;
41
+ /** Use lossless AVIF instead of lossy encoding, overriding `quality` and chroma subsampling. @defaultValue `false` */
24
42
  lossless?: boolean;
43
+ /**
44
+ * Chroma resolution: `4:2:0` reduces color detail for smaller files, while
45
+ * `4:4:4` preserves full color resolution. Lossless encoding always uses
46
+ * full color resolution.
47
+ *
48
+ * @defaultValue `'4:2:0'`
49
+ */
25
50
  chromaSubsampling?: '4:2:0' | '4:4:4';
26
51
  }
27
52
  interface JpegEncoding extends SizedEncoding {
53
+ /** Encode the image as JPEG. Alpha is not preserved. */
28
54
  codec: 'jpeg';
55
+ /** Lossy quality from 1 (smallest, lowest fidelity) to 100. @defaultValue `75` */
29
56
  quality?: number;
57
+ /**
58
+ * Chroma resolution: `4:2:0` reduces color detail for smaller files, while
59
+ * `4:4:4` preserves full color resolution.
60
+ *
61
+ * @defaultValue `'4:2:0'`
62
+ */
30
63
  chromaSubsampling?: '4:2:0' | '4:4:4';
31
64
  }
32
65
  interface PngEncoding extends SizedEncoding {
66
+ /** Encode the image as lossless PNG. */
33
67
  codec: 'png';
34
68
  }
35
69
  interface UastcEncoding extends SizedEncoding {
70
+ /** Encode the image in a GPU-ready KTX2 container. */
36
71
  codec: 'ktx2';
72
+ /** Use high-quality UASTC block compression for LDR pixels. */
37
73
  mode: 'uastc';
74
+ /**
75
+ * How the texture is sampled: `srgb` for color data such as albedo and
76
+ * emissive maps, or `linear` for data and normal maps.
77
+ *
78
+ * @defaultValue `'srgb'`
79
+ */
38
80
  colorSpace?: 'srgb' | 'linear';
81
+ /** Tune the encoder for tangent-space normal-map data. @defaultValue `false` */
39
82
  normalMap?: boolean;
83
+ /** Encoder effort from 0 (fastest) to 4 (slowest, highest quality). @defaultValue `2` */
40
84
  level?: 0 | 1 | 2 | 3 | 4;
85
+ /** Generate a complete mip chain for minified rendering. @defaultValue `true` */
41
86
  mipmaps?: boolean;
87
+ /** Apply Zstandard supercompression to reduce download size. @defaultValue `true` */
42
88
  zstd?: boolean;
89
+ /**
90
+ * Enable rate-distortion optimization. This can substantially reduce files
91
+ * at the cost of image fidelity; omit it to disable RDO.
92
+ */
43
93
  rdo?: {
94
+ /**
95
+ * Compression-to-quality tradeoff from 0.001 to 10. Larger values usually
96
+ * produce smaller files with more distortion.
97
+ *
98
+ * @defaultValue `1`
99
+ */
44
100
  lambda?: number;
45
101
  };
46
102
  }
47
103
  interface Etc1sEncoding extends SizedEncoding {
104
+ /** Encode the image in a GPU-ready KTX2 container. */
48
105
  codec: 'ktx2';
106
+ /** Use ETC1S compression for the smallest download size at lower fidelity than UASTC. */
49
107
  mode: 'etc1s';
108
+ /**
109
+ * How the texture is sampled: `srgb` for color data such as albedo and
110
+ * emissive maps, or `linear` for data and normal maps.
111
+ *
112
+ * @defaultValue `'srgb'`
113
+ */
50
114
  colorSpace?: 'srgb' | 'linear';
115
+ /** Tune the encoder for tangent-space normal-map data. @defaultValue `false` */
51
116
  normalMap?: boolean;
117
+ /** Quality from 1 (smallest, lowest fidelity) to 255. @defaultValue `128` */
52
118
  quality?: number;
119
+ /**
120
+ * Encoder effort from 0 (fastest) to 6 (slowest). Higher values search
121
+ * harder for a smaller file at the requested quality.
122
+ *
123
+ * @defaultValue `1`
124
+ */
53
125
  compression?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
126
+ /** Generate a complete mip chain for minified rendering. @defaultValue `true` */
54
127
  mipmaps?: boolean;
55
128
  }
56
129
  /**
@@ -63,73 +136,133 @@ interface Etc1sEncoding extends SizedEncoding {
63
136
  * be authored at their target resolution.
64
137
  */
65
138
  interface UastcHdrEncoding {
139
+ /** Encode the image in a GPU-ready KTX2 container. */
66
140
  codec: 'ktx2';
141
+ /**
142
+ * Use UASTC HDR for half-float EXR or Radiance HDR input. This mode does not
143
+ * support resizing or alpha and is only available to standalone image recipes.
144
+ */
67
145
  mode: 'uastc-hdr';
68
- /** Encoder effort. Higher is slower; rarely helps on low-frequency lightmaps. */
146
+ /**
147
+ * Encoder effort from 0 (fastest) to 4 (slowest). Higher levels rarely help
148
+ * low-frequency content such as diffuse lightmaps.
149
+ *
150
+ * @defaultValue `1`
151
+ */
69
152
  level?: 0 | 1 | 2 | 3 | 4;
153
+ /** Generate a complete mip chain for minified rendering. @defaultValue `true` */
70
154
  mipmaps?: boolean;
155
+ /** Apply Zstandard supercompression to reduce download size. @defaultValue `true` */
71
156
  zstd?: boolean;
72
157
  }
73
158
  type RasterEncoding = WebpEncoding | AvifEncoding | JpegEncoding | PngEncoding;
74
159
  type ImageEncoding = RasterEncoding | UastcEncoding | Etc1sEncoding | UastcHdrEncoding;
75
160
  type GlbProperty = 'accessor' | 'animation' | 'buffer' | 'camera' | 'material' | 'mesh' | 'node' | 'primitive' | 'primitiveTarget' | 'skin' | 'texture';
76
161
  type GlbMethodRecipe = {
162
+ /** Merge equivalent accessors, materials, meshes, skins, or textures. */
77
163
  method: 'dedup';
164
+ /** Keep otherwise-identical properties separate when their names differ. @defaultValue `false` */
78
165
  keepUniqueNames?: boolean;
166
+ /**
167
+ * Property kinds to merge.
168
+ *
169
+ * @defaultValue `['accessor', 'material', 'mesh', 'skin', 'texture']`
170
+ */
79
171
  propertyTypes?: readonly Extract<GlbProperty, 'accessor' | 'material' | 'mesh' | 'skin' | 'texture'>[];
80
172
  } | {
173
+ /** Remove unused GLB properties and optionally simplify redundant data. */
81
174
  method: 'prune';
175
+ /** Keep unused vertex attributes, such as UVs without an assigned texture. @defaultValue `false` */
82
176
  keepAttributes?: boolean;
177
+ /** Prevent a property with custom `extras` data from being removed. @defaultValue `false` */
83
178
  keepExtras?: boolean;
179
+ /** Keep empty leaf nodes that would otherwise be removed. @defaultValue `false` */
84
180
  keepLeaves?: boolean;
181
+ /** Keep single-color textures instead of replacing them with material factors. @defaultValue `false` */
85
182
  keepSolidTextures?: boolean;
183
+ /** Property kinds eligible for pruning. By default, every supported kind is eligible. */
86
184
  propertyTypes?: readonly GlbProperty[];
87
185
  } | {
186
+ /** Remove redundant animation keyframes while keeping motion within a tolerance. */
88
187
  method: 'resample';
188
+ /** Maximum permitted animation-value error. Must be greater than zero. @defaultValue `0.0001` */
89
189
  tolerance?: number;
190
+ /**
191
+ * Deduplicate and prune temporary or unused resources after resampling.
192
+ * Disable this when those resources must be preserved for a later step.
193
+ *
194
+ * @defaultValue `true`
195
+ */
90
196
  cleanup?: boolean;
91
197
  };
92
198
  type TextureSelector = {
199
+ /** Select textures by the material slots that reference them. */
93
200
  by: 'slot';
201
+ /** glTF material texture-slot names, such as `baseColorTexture` or `normalTexture`. */
94
202
  slots: readonly string[];
95
203
  } | {
204
+ /** Select textures by their authored GLB names. */
96
205
  by: 'name';
206
+ /** Exact, case-sensitive texture names. Names should be unique within the GLB. */
97
207
  names: readonly string[];
98
208
  } | {
209
+ /** Select textures by their zero-based order in the GLB. */
99
210
  by: 'index';
211
+ /** Non-negative texture indices. Indices can change when a source GLB is re-exported. */
100
212
  indices: readonly number[];
101
213
  };
102
214
  interface EmbeddedTextureRecipe {
215
+ /**
216
+ * Unique, non-empty name for this texture group in progress events and
217
+ * optimization reports. It does not rename textures in the GLB.
218
+ */
103
219
  label: string;
220
+ /** Textures to encode. A texture cannot be claimed by more than one selector. */
104
221
  select: TextureSelector;
222
+ /** Output encoding for the selected textures. UASTC HDR is not supported inside GLBs. */
105
223
  encode: ImageEncoding;
106
224
  }
107
225
  type GeometryEncoding = {
226
+ /** Compress geometry with `KHR_draco_mesh_compression` for broad decoder support. */
108
227
  codec: 'draco';
109
228
  } | {
229
+ /** Compress geometry with `EXT_meshopt_compression` for fast runtime decoding. */
110
230
  codec: 'meshopt';
111
231
  };
112
232
  interface GlbAssetRecipe {
233
+ /** Optimize a binary glTF (`.glb`) asset. */
113
234
  kind: 'glb';
235
+ /** Structural transforms to run in array order before texture and geometry encoding. @defaultValue `[]` */
114
236
  methods?: readonly GlbMethodRecipe[];
237
+ /** Embedded texture groups to encode. Unselected textures keep their source encoding. @defaultValue `[]` */
115
238
  textures?: readonly EmbeddedTextureRecipe[];
239
+ /** Geometry codec to apply, or `false` to leave geometry uncompressed. @defaultValue `false` */
116
240
  geometry?: GeometryEncoding | false;
117
241
  }
118
242
  interface ImageAssetRecipe {
243
+ /** Optimize a standalone raster or HDR image. */
119
244
  kind: 'image';
245
+ /** Output codec and its quality, size, and performance tradeoffs. */
120
246
  encode: ImageEncoding;
121
247
  }
122
248
  type AssetRecipe = GlbAssetRecipe | ImageAssetRecipe;
123
249
  type NormalizedImageEncoding = (Required<Omit<WebpEncoding, 'maxSize'>> & Pick<WebpEncoding, 'maxSize'>) | (Required<Omit<AvifEncoding, 'maxSize'>> & Pick<AvifEncoding, 'maxSize'>) | (Required<Omit<JpegEncoding, 'maxSize'>> & Pick<JpegEncoding, 'maxSize'>) | PngEncoding | (Required<Omit<UastcEncoding, 'maxSize' | 'rdo'>> & Pick<UastcEncoding, 'maxSize' | 'rdo'>) | (Required<Omit<Etc1sEncoding, 'maxSize'>> & Pick<Etc1sEncoding, 'maxSize'>) | Required<UastcHdrEncoding>;
124
250
  type NormalizedAssetRecipe = {
251
+ /** Identifies the normalized recipe as a standalone image recipe. */
125
252
  kind: 'image';
253
+ /** Image encoding with every codec default resolved. */
126
254
  encode: NormalizedImageEncoding;
127
255
  } | {
256
+ /** Identifies the normalized recipe as a binary glTF recipe. */
128
257
  kind: 'glb';
258
+ /** Structural transforms to run, with an omitted value resolved to an empty array. */
129
259
  methods: readonly GlbMethodRecipe[];
260
+ /** Embedded texture groups with every codec default resolved. */
130
261
  textures: readonly (Omit<EmbeddedTextureRecipe, 'encode'> & {
262
+ /** Output encoding with every codec default resolved. */
131
263
  encode: NormalizedImageEncoding;
132
264
  })[];
265
+ /** Resolved geometry codec, or `false` when geometry compression is disabled. */
133
266
  geometry: GeometryEncoding | false;
134
267
  };
135
268
  declare const COLOR_TEXTURE_SLOTS: readonly ["baseColorTexture", "emissiveTexture", "specularColorTexture", "sheenColorTexture"];
@@ -137,6 +270,7 @@ declare const DIRECTIONAL_TEXTURE_SLOTS: readonly ["normalTexture", "clearcoatNo
137
270
  declare const DATA_TEXTURE_SLOTS: readonly ["occlusionTexture", "metallicRoughnessTexture", "specularTexture", "clearcoatTexture", "clearcoatRoughnessTexture", "sheenRoughnessTexture", "transmissionTexture", "thicknessTexture", "iridescenceTexture", "iridescenceThicknessTexture"];
138
271
  declare const DEFAULT_GLB_RECIPE: GlbAssetRecipe;
139
272
  declare const DEFAULT_IMAGE_RECIPE: ImageAssetRecipe;
273
+ /** Defines a type-checked optimization recipe while preserving its inferred literal types. */
140
274
  declare const defineRecipe: <const T extends AssetRecipe>(recipe: T & NoUnknownFields<T, AssetRecipe>) => T;
141
275
  declare function outputExtension(encoding: ImageEncoding): string;
142
276
  declare function outputMimeType(encoding: ImageEncoding): string;
package/dist/index.js CHANGED
@@ -356,7 +356,7 @@ function isHdrSourceMimeType(mimeType) {
356
356
 
357
357
  // package.json
358
358
  var package_default = {
359
- version: "0.5.2"};
359
+ version: "0.5.3"};
360
360
 
361
361
  // src/codecs/manifest.ts
362
362
  var CODEC_MANIFEST_HASH = "2046d60deb0f9f224743f4404f3c6e8ba5399f81b2811fa50466e93fce3bd322";