@nodecraft/rendermite 1.0.5 → 1.0.6

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.
Files changed (110) hide show
  1. package/README.md +5 -0
  2. package/dist/atlas/registry.d.ts +3 -3
  3. package/dist/atlas/sources.d.ts +1 -1
  4. package/dist/{blend-Qvrn6YgK.d.ts → blend-CyDIxCne.d.ts} +1 -1
  5. package/dist/cache-Cr2ON3RQ.js +66 -0
  6. package/dist/cli.js +12 -6
  7. package/dist/compose-CQCb2LVv.js +104 -0
  8. package/dist/descriptor-DWebtkI1.js +26 -0
  9. package/dist/{discovery-D89pVVJA.d.ts → discovery-wiJBGryo.d.ts} +1 -1
  10. package/dist/dynamic/generators.d.ts +1 -1
  11. package/dist/dynamic/generators.js +1 -1
  12. package/dist/{encode-3u49i-eD.js → encode-D6dQu2dJ.js} +16 -4
  13. package/dist/{encode-C5kdAm45.d.ts → encode-DaNQF28M.d.ts} +1 -1
  14. package/dist/{entity-fallback-DfL0_eyf.js → entity-fallback-BRCeGKBT.js} +1 -1
  15. package/dist/{face-CpVdnf-w.d.ts → face-BIYg14TE.d.ts} +10 -4
  16. package/dist/{face-D-N1amV4.js → face-DmCiHUd5.js} +23 -10
  17. package/dist/{generators-CcVRG30y.js → generators-BlG4KmtP.js} +1 -1
  18. package/dist/{generators-CCB8h0mP.d.ts → generators-DhRov4RB.d.ts} +1 -1
  19. package/dist/{geo-Dq2zve09.js → geo-Diky41Tw.js} +6 -3
  20. package/dist/index.d.ts +14 -14
  21. package/dist/index.js +11 -11
  22. package/dist/{item-styles-DJ3LWZS2.js → item-styles-upgEO1yP.js} +1 -1
  23. package/dist/items/discovery.d.ts +1 -1
  24. package/dist/{jar-6T3xdgaL.d.ts → jar-CFkA-VgT.d.ts} +2 -1
  25. package/dist/{jar-Bt3i0ls4.js → jar-D9z-X7tA.js} +12 -12
  26. package/dist/{legacy-reshape-CewShfF3.js → legacy-reshape-C05SfAPR.js} +1 -1
  27. package/dist/{loader-A-BZa8J4.js → loader-B8NJO7pR.js} +12 -3
  28. package/dist/{loader-CBzn3Koc.js → loader-CfXMxcEV.js} +37 -7
  29. package/dist/{loader-C-6QN3xv.d.ts → loader-D22zZME7.d.ts} +2 -2
  30. package/dist/{loader-TFFNV4Jl.d.ts → loader-Myy22TDL.d.ts} +8 -2
  31. package/dist/{manager-dfI7b9N4.js → manager-CkletR5K.js} +29 -2
  32. package/dist/{manager-CoZaeQTu.d.ts → manager-Cv1NeFyF.d.ts} +28 -1
  33. package/dist/models/loader.d.ts +1 -1
  34. package/dist/models/loader.js +1 -1
  35. package/dist/mods/prepare.d.ts +1 -1
  36. package/dist/mods/prepare.js +1 -1
  37. package/dist/mods/synthesize.d.ts +2 -2
  38. package/dist/mods/synthesize.js +1 -1
  39. package/dist/mods/tints.d.ts +2 -2
  40. package/dist/mods/tints.js +1 -1
  41. package/dist/output/encode.d.ts +1 -1
  42. package/dist/output/encode.js +1 -1
  43. package/dist/output/item-styles.js +1 -1
  44. package/dist/pipeline-BIk1RRIp.js +221 -0
  45. package/dist/pipeline-zq-yU3Te.d.ts +58 -0
  46. package/dist/pool-CKGp1qup.js +131 -0
  47. package/dist/{prepare-BeUpXwaP.js → prepare-BESRrh6K.js} +4 -4
  48. package/dist/{prepare-gfR1aIjt.d.ts → prepare-CPxO0kKz.d.ts} +1 -1
  49. package/dist/{prepare-C8wRjAXP.js → prepare-Cc8QZ3j0.js} +4 -4
  50. package/dist/{prepare-wfWtaz_X.d.ts → prepare-Cs6QDqie.d.ts} +1 -1
  51. package/dist/{rasterizer-BHWDrmGz.js → rasterizer-76qO8TDh.js} +42 -4
  52. package/dist/{rasterizer-Dh35qXbn.d.ts → rasterizer-yqJkicm1.d.ts} +21 -2
  53. package/dist/render/blend.d.ts +1 -1
  54. package/dist/render/compose.d.ts +2 -2
  55. package/dist/render/compose.js +1 -1
  56. package/dist/render/entity-fallback.d.ts +6 -6
  57. package/dist/render/entity-fallback.js +1 -1
  58. package/dist/render/face.d.ts +2 -2
  59. package/dist/render/face.js +1 -1
  60. package/dist/render/fluid-bucket.d.ts +2 -2
  61. package/dist/render/geo.d.ts +4 -4
  62. package/dist/render/geo.js +1 -1
  63. package/dist/render/legacy-tints.d.ts +2 -2
  64. package/dist/render/obj.d.ts +5 -5
  65. package/dist/render/obj.js +1 -1
  66. package/dist/render/pipeline.d.ts +2 -0
  67. package/dist/render/pipeline.js +2 -0
  68. package/dist/render/rasterizer.d.ts +2 -2
  69. package/dist/render/rasterizer.js +2 -2
  70. package/dist/render/renderer.d.ts +2 -2
  71. package/dist/render/renderer.js +1 -1
  72. package/dist/render/tints.d.ts +1 -1
  73. package/dist/{renderer-LDhBNHcl.js → renderer-CjT19tHd.js} +130 -53
  74. package/dist/{renderer-nbMCw1Pl.d.ts → renderer-DVsZHAvf.d.ts} +23 -6
  75. package/dist/resources/cache.d.ts +30 -0
  76. package/dist/resources/cache.js +2 -0
  77. package/dist/resources/descriptor.d.ts +2 -0
  78. package/dist/resources/descriptor.js +2 -0
  79. package/dist/resources/jar.d.ts +1 -1
  80. package/dist/resources/jar.js +1 -1
  81. package/dist/resources/manager.d.ts +1 -1
  82. package/dist/resources/manager.js +1 -1
  83. package/dist/resources/synthetic.d.ts +1 -1
  84. package/dist/resources/synthetic.js +1 -1
  85. package/dist/resources/zip-reader.d.ts +5 -0
  86. package/dist/resources/zip-reader.js +2 -0
  87. package/dist/run-BnICOF4I.js +209 -0
  88. package/dist/{run-BlSZw9Qk.d.ts → run-CKUtynTy.d.ts} +12 -2
  89. package/dist/run.d.ts +1 -1
  90. package/dist/run.js +1 -1
  91. package/dist/{sources-DH9dk3KF.d.ts → sources-B9X9w3qP.d.ts} +1 -1
  92. package/dist/{synthesize-CRgSEmEp.js → synthesize-3Q0aaOnK.js} +1 -1
  93. package/dist/{synthetic-CDsj--li.d.ts → synthetic-Qk-BSUXO.d.ts} +5 -1
  94. package/dist/{synthetic-DC2bSnGe.js → synthetic-ZAUjXT7E.js} +0 -0
  95. package/dist/textures/loader.d.ts +1 -1
  96. package/dist/textures/loader.js +1 -1
  97. package/dist/{tints-CuG6GwQJ.js → tints-B8UJmZMu.js} +2 -2
  98. package/dist/{tints-txt-8xI5.d.ts → tints-DLBExVWN.d.ts} +2 -2
  99. package/dist/versions/legacy-reshape.d.ts +1 -1
  100. package/dist/versions/legacy-reshape.js +1 -1
  101. package/dist/versions/prepare.d.ts +1 -1
  102. package/dist/versions/prepare.js +1 -1
  103. package/dist/workers/pool.d.ts +36 -5
  104. package/dist/workers/pool.js +2 -67
  105. package/dist/workers/render-worker.d.ts +15 -0
  106. package/dist/workers/render-worker.js +40 -0
  107. package/dist/zip-reader-BSbJKUT1.js +156 -0
  108. package/package.json +4 -2
  109. package/dist/compose-qjhyBvnS.js +0 -41
  110. package/dist/run-CfnWIRY4.js +0 -316
@@ -1,316 +0,0 @@
1
- import { a as defaultProperties } from "./definition-3MBm8ar_.js";
2
- import { n as ResourceLocator } from "./locator-ycZzh_6z.js";
3
- import { n as LayeredResourceManager, t as FolderResourceManager } from "./manager-dfI7b9N4.js";
4
- import { t as loadAtlasResolver } from "./registry-B9TcjVbs.js";
5
- import { a as builtinDynamicResources } from "./generators-CcVRG30y.js";
6
- import { n as discoverItems, r as resolveItem } from "./discovery-0SM0cTLw.js";
7
- import { t as ModelLoader } from "./loader-A-BZa8J4.js";
8
- import { s as toFloatTexture, t as blendPixel } from "./blend-CHP2-j9U.js";
9
- import { r as encodeRasterAsset, t as encodeAnimatedIcon } from "./encode-3u49i-eD.js";
10
- import { t as classifyItemStyle } from "./item-styles-DJ3LWZS2.js";
11
- import { t as minifyStylesheet } from "./minify-bjMRmr5J.js";
12
- import { t as generateStylesheet } from "./stylesheet-CovT3B2S.js";
13
- import { a as renderModelFrames, i as renderModel, n as boxDownscale, r as pointResize } from "./renderer-LDhBNHcl.js";
14
- import { n as renderEntityFallback, r as spawnEggTints, t as renderDyedVariantFallback } from "./entity-fallback-DfL0_eyf.js";
15
- import { i as renderGeo, t as findGeoForItem } from "./geo-Dq2zve09.js";
16
- import { t as legacyTintsForChain } from "./legacy-tints-B09J0Rxh.js";
17
- import { a as resolveTints } from "./tints-BtbHegpI.js";
18
- import { n as TextureLoader } from "./loader-CBzn3Koc.js";
19
- import path from "node:path";
20
- import { mkdir, writeFile } from "node:fs/promises";
21
- //#region src/run.ts
22
- /**
23
- * Render-run orchestration: discover items, evaluate definitions, render,
24
- * encode, write images + stylesheet + item list. Unlike upstream, failures are
25
- * per-item, collected, and reported — a run summary counts files, never log lines.
26
- */
27
- async function run(options) {
28
- const namespaces = options.namespaces ?? ["minecraft"];
29
- const size = options.size ?? 64;
30
- const quality = options.quality ?? 2;
31
- const prefix = options.prefix ?? "rc-";
32
- const format = options.format ?? "webp";
33
- const fallback = options.fallback ?? true;
34
- const lightingProfile = options.lightingProfile ?? "modern";
35
- const dynamic = options.builtin ? builtinDynamicResources() : null;
36
- const resources = options.builtin && dynamic ? new LayeredResourceManager([
37
- new FolderResourceManager(options.builtin),
38
- dynamic.layer,
39
- options.resources
40
- ]) : options.resources;
41
- const models = new ModelLoader(resources);
42
- const textures = new TextureLoader(resources);
43
- const glint = await resolveEnchantmentGlint(resources);
44
- if (!glint) throw new Error("Missing enchantment glint texture (minecraft:misc/enchanted_glint_item or enchanted_item_glint)");
45
- const encodedGlint = await encodeRasterAsset(glint, fallback ? ["png", format] : [format]);
46
- textures.setAtlasResolver(await loadAtlasResolver(resources, (locator) => textures.load(locator)));
47
- const ids = [];
48
- const seen = /* @__PURE__ */ new Set();
49
- if (options.builtin) for (const placeholder of ["renderchest:unknown", "renderchest:empty"]) {
50
- seen.add(placeholder);
51
- ids.push(placeholder);
52
- }
53
- for (const namespace of namespaces) for (const item of await discoverItems(resources, namespace, { filterUntranslatedModels: options.filterUntranslatedModels })) {
54
- if (seen.has(item.id)) continue;
55
- if (options.builtin && !await itemExistsIn(options.resources, item.id)) continue;
56
- seen.add(item.id);
57
- ids.push(item.id);
58
- }
59
- if (dynamic && namespaces.includes("minecraft")) {
60
- const hasTrims = await resources.hasResource("texture", ResourceLocator.parse("minecraft:trims/color_palettes/trim_palette"));
61
- const groupAvailable = {
62
- _armor_trims: hasTrims,
63
- _leather_armor: hasTrims,
64
- _decorated_pot: await resources.hasResource("texture", ResourceLocator.parse("minecraft:entity/decorated_pot/decorated_pot_base")),
65
- _crossbow: await resources.hasResource("model", ResourceLocator.parse("minecraft:item/crossbow_arrow"))
66
- };
67
- for (const item of dynamic.items) if ((groupAvailable[item.id.split(":", 1)[0]] ?? true) && !seen.has(item.id)) {
68
- seen.add(item.id);
69
- ids.push(item.id);
70
- }
71
- }
72
- const rendered = [];
73
- const failed = [];
74
- const spriteFallbacks = [];
75
- const skippedTemplates = [];
76
- const styles = [];
77
- let writtenFiles = 0;
78
- await mkdir(options.output, { recursive: true });
79
- for (const [extension, buffer] of encodedGlint) {
80
- await writeFile(path.join(options.output, `${prefix}enchantment.${extension}`), buffer);
81
- writtenFiles++;
82
- }
83
- let templateParents = null;
84
- const loadTemplateParents = async () => {
85
- const parents = /* @__PURE__ */ new Set();
86
- for (const namespace of namespaces) for (const modelLocator of await resources.listResources("model", namespace)) {
87
- if (!modelLocator.path.startsWith("item/")) continue;
88
- const raw = await resources.getResource("model", modelLocator);
89
- if (!raw) continue;
90
- try {
91
- const parent = JSON.parse(raw.toString("utf8")).parent;
92
- if (typeof parent === "string") parents.add(ResourceLocator.parse(parent).toString());
93
- } catch {}
94
- }
95
- return parents;
96
- };
97
- const isTemplateModel = async (id) => {
98
- const locator = ResourceLocator.parse(id);
99
- if (await resources.hasResource("itemDefinition", locator)) return false;
100
- templateParents ??= loadTemplateParents();
101
- return (await templateParents).has(new ResourceLocator(locator.namespace, `item/${locator.path}`).toString());
102
- };
103
- /**
104
- * Code-rendered models often still ship a flat item sprite (the old
105
- * pipeline's black-icon audit checked exactly this). A real sprite beats
106
- * no icon; the fallback is recorded so it is never a silent substitution.
107
- */
108
- const spriteFallback = async (id) => {
109
- const locator = ResourceLocator.parse(id);
110
- for (const directory of ["item", "items"]) {
111
- const texture = await textures.load(new ResourceLocator(locator.namespace, `${directory}/${locator.path}`));
112
- if (texture) {
113
- const float = toFloatTexture(texture);
114
- const upscaled = pointResize(float, size * quality, size * quality);
115
- return quality === 1 ? upscaled : boxDownscale(upscaled, quality);
116
- }
117
- }
118
- return null;
119
- };
120
- const concurrency = Math.max(1, options.concurrency ?? 8);
121
- let nextIndex = 0;
122
- let completed = 0;
123
- const renderFrames = async (id) => {
124
- const instructions = await resolveItem(resources, id, defaultProperties());
125
- let frames;
126
- let delaysMs;
127
- if (instructions.length === 1) {
128
- const model = await models.load(instructions[0].model);
129
- let tints = instructions[0].tints.length > 0 ? await resolveTints(instructions[0].tints, { textures }) : await legacyTintsForChain(model.chain, textures);
130
- if (!tints && model.chain.some((entry) => entry.endsWith("item/template_spawn_egg"))) tints = await spawnEggTints(id, resources, textures).catch(() => null);
131
- tints ??= [];
132
- const result = await renderModelFrames(model, textures, {
133
- size,
134
- quality,
135
- lightingProfile,
136
- itemTransform: instructions[0].transform,
137
- tints,
138
- resources
139
- });
140
- frames = result.frames;
141
- delaysMs = result.delaysMs;
142
- } else {
143
- let combined = null;
144
- for (const instruction of instructions) {
145
- const model = await models.load(instruction.model);
146
- const tints = instruction.tints.length > 0 ? await resolveTints(instruction.tints, { textures }) : await legacyTintsForChain(model.chain, textures) ?? [];
147
- const renderedModel = await renderModel(model, textures, {
148
- size,
149
- quality,
150
- lightingProfile,
151
- itemTransform: instruction.transform,
152
- tints,
153
- resources
154
- });
155
- combined = combined === null ? renderedModel : blendOver(combined, renderedModel);
156
- }
157
- frames = [combined ?? {
158
- width: size,
159
- height: size,
160
- data: new Float64Array(size * size * 4)
161
- }];
162
- delaysMs = [50];
163
- }
164
- if (frames.length === 0) {
165
- frames = [{
166
- width: size,
167
- height: size,
168
- data: new Float64Array(size * size * 4)
169
- }];
170
- delaysMs = [50];
171
- }
172
- return {
173
- frames,
174
- delaysMs
175
- };
176
- };
177
- const renderOne = async (index) => {
178
- const id = ids[index];
179
- let frames;
180
- let delaysMs;
181
- let usedFallback = false;
182
- try {
183
- ({frames, delaysMs} = await renderFrames(id));
184
- } catch (err) {
185
- const blockLocator = ResourceLocator.parse(id);
186
- const blockRender = await models.load(new ResourceLocator(blockLocator.namespace, `block/${blockLocator.path}`)).then((model) => renderModel(model, textures, {
187
- size,
188
- quality,
189
- lightingProfile,
190
- resources
191
- })).catch(() => null);
192
- const geo = blockRender ? null : await findGeoForItem(resources, id).catch(() => null);
193
- const geoRender = geo ? await renderGeo(geo.geo, geo.texture, textures, {
194
- size,
195
- quality,
196
- lightingProfile
197
- }).catch(() => null) : null;
198
- let fallbackRender = blockRender ?? (geoRender && quality !== 1 ? boxDownscale(geoRender, quality) : geoRender);
199
- fallbackRender ??= options.builtin ? await renderEntityFallback(id, models, textures, resources, {
200
- size,
201
- quality,
202
- lightingProfile,
203
- resources
204
- }).catch(() => null) : null;
205
- fallbackRender ??= await renderDyedVariantFallback(id, models, textures, {
206
- size,
207
- quality,
208
- lightingProfile,
209
- resources
210
- }).catch(() => null);
211
- if (fallbackRender) {
212
- frames = [fallbackRender];
213
- delaysMs = [50];
214
- } else {
215
- const fallback = await spriteFallback(id).catch(() => null);
216
- if (!fallback) {
217
- if (await isTemplateModel(id).catch(() => false)) skippedTemplates.push(id);
218
- else failed.push({
219
- id,
220
- error: err.message
221
- });
222
- completed++;
223
- options.onProgress?.(completed, ids.length, id, err.message);
224
- return;
225
- }
226
- frames = [fallback];
227
- delaysMs = [50];
228
- usedFallback = true;
229
- }
230
- }
231
- try {
232
- const encoded = await encodeAnimatedIcon(frames, delaysMs, {
233
- webp: true,
234
- gif: options.gif,
235
- avif: options.avif || format === "avif"
236
- });
237
- const [namespace, itemPath] = id.split(":", 2);
238
- const imageBase = path.join(options.output, "items", namespace, `${itemPath}`);
239
- await mkdir(path.dirname(imageBase), { recursive: true });
240
- await writeFile(`${imageBase}.png`, encoded.png);
241
- writtenFiles++;
242
- for (const [extension, buffer] of [
243
- ["webp", encoded.webp],
244
- ["gif", encoded.gif],
245
- ["avif", encoded.avif]
246
- ]) {
247
- if (!buffer) continue;
248
- await writeFile(`${imageBase}.${extension}`, buffer);
249
- writtenFiles++;
250
- }
251
- rendered.push(id);
252
- if (usedFallback) spriteFallbacks.push(id);
253
- completed++;
254
- options.onProgress?.(completed, ids.length, id);
255
- } catch (err) {
256
- failed.push({
257
- id,
258
- error: err.message
259
- });
260
- completed++;
261
- options.onProgress?.(completed, ids.length, id, err.message);
262
- }
263
- };
264
- await Promise.all(Array.from({ length: Math.min(concurrency, ids.length) }, async () => {
265
- while (nextIndex < ids.length) {
266
- const index = nextIndex++;
267
- await renderOne(index);
268
- }
269
- }));
270
- rendered.sort((left, right) => left.localeCompare(right));
271
- const renderedSet = new Set(rendered);
272
- for (const id of rendered) {
273
- const style = classifyItemStyle(id, renderedSet);
274
- if (style) styles.push(style);
275
- }
276
- const stylesheet = generateStylesheet(styles, {
277
- prefix,
278
- format,
279
- fallback
280
- });
281
- const finalStylesheet = options.minify === false ? stylesheet : minifyStylesheet(stylesheet, (message) => options.onProgress?.(0, 0, "stylesheet", message));
282
- await writeFile(path.join(options.output, `${prefix}${namespaces[0]}-${size}.css`), finalStylesheet);
283
- if (options.itemList !== false) {
284
- await writeFile(path.join(options.output, `${prefix}${namespaces[0]}.json`), JSON.stringify(rendered));
285
- await writeFile(path.join(options.output, `${prefix}${namespaces[0]}-failures.json`), JSON.stringify(failed, null, " "));
286
- }
287
- return {
288
- rendered,
289
- failed,
290
- spriteFallbacks,
291
- skippedTemplates,
292
- writtenFiles
293
- };
294
- }
295
- async function itemExistsIn(resources, id) {
296
- const locator = ResourceLocator.parse(id);
297
- if (await resources.hasResource("itemDefinition", locator)) return true;
298
- return resources.hasResource("model", new ResourceLocator(locator.namespace, `item/${locator.path}`));
299
- }
300
- /** Resolve both names used on either side of Minecraft 1.19.3. */
301
- async function resolveEnchantmentGlint(resources) {
302
- for (const path of ["misc/enchanted_glint_item", "misc/enchanted_item_glint"]) {
303
- const texture = await resources.getResource("texture", new ResourceLocator("minecraft", path));
304
- if (texture) return texture;
305
- }
306
- return null;
307
- }
308
- function blendOver(base, layer) {
309
- for (let offset = 0; offset < base.data.length; offset += 4) {
310
- const alpha = layer.data[offset + 3];
311
- if (alpha > 0) blendPixel(base.data, offset, layer.data[offset], layer.data[offset + 1], layer.data[offset + 2], alpha);
312
- }
313
- return base;
314
- }
315
- //#endregion
316
- export { run as t };