@nodecraft/rendermite 1.0.0 → 1.0.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.
package/README.md CHANGED
@@ -52,6 +52,7 @@ Useful flags: `--size <px>` (default 64), `--format webp|avif`, `--gif` for lega
52
52
  icons/
53
53
  items/<namespace>/<item>.png # always written
54
54
  items/<namespace>/<item>.webp # lossless, animated where the item animates
55
+ rc-enchantment.<format> # each lossless glint format referenced by the CSS
55
56
  rc-<namespace>-64.css # spritesheet CSS (class per item, enchant glint, tint layers)
56
57
  rc-<namespace>.json # rendered item id list
57
58
  rc-<namespace>-failures.json # per-item failures with reasons, never silent
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { n as builtinPackPath, t as bedCompatPath } from "./builtin-C8GZEN40.js";
3
3
  import { n as LayeredResourceManager, t as FolderResourceManager } from "./manager-dfI7b9N4.js";
4
4
  import { t as JarResourceManager } from "./jar-Bt3i0ls4.js";
5
- import { t as run } from "./run-CEaRhk4A.js";
5
+ import { t as run } from "./run-Dr6BfyN9.js";
6
6
  import { t as downloadClientJar } from "./download-D9aARBFp.js";
7
7
  import { a as prepareVersionResources, i as eraForVersion, n as GEOMETRY_DONOR_VERSIONS } from "./prepare-DROxBZp1.js";
8
8
  import path from "node:path";
@@ -6,6 +6,28 @@ import sharp from "sharp";
6
6
  * separate optimization step is needed: lossless everywhere, strictly-smaller
7
7
  * candidates only.
8
8
  */
9
+ /** Losslessly transcode an existing PNG resource into the formats referenced by generated CSS. */
10
+ async function encodeRasterAsset(source, formats) {
11
+ const image = sharp(source);
12
+ const unique = [...new Set(formats)];
13
+ const encoded = await Promise.all(unique.map(async (format) => {
14
+ switch (format) {
15
+ case "png": return [format, await image.clone().png({
16
+ compressionLevel: 9,
17
+ effort: 10
18
+ }).toBuffer()];
19
+ case "webp": return [format, await image.clone().webp({
20
+ lossless: true,
21
+ effort: 6
22
+ }).toBuffer()];
23
+ case "avif": return [format, await image.clone().avif({
24
+ lossless: true,
25
+ effort: 6
26
+ }).toBuffer()];
27
+ }
28
+ }));
29
+ return new Map(encoded);
30
+ }
9
31
  /**
10
32
  * Encode a multi-frame icon: animated WebP (universal), optional GIF for
11
33
  * legacy browsers, PNG as the static first frame (matching upstream's
@@ -83,4 +105,4 @@ async function encodeIcon(texture, options = {}) {
83
105
  return result;
84
106
  }
85
107
  //#endregion
86
- export { encodeIcon as n, encodeAnimatedIcon as t };
108
+ export { encodeIcon as n, encodeRasterAsset as r, encodeAnimatedIcon as t };
@@ -19,6 +19,9 @@ interface EncodedAnimatedIcon extends EncodedIcon {
19
19
  interface AnimatedEncodeOptions extends EncodeOptions {
20
20
  gif?: boolean;
21
21
  }
22
+ type RasterAssetFormat = 'png' | 'webp' | 'avif';
23
+ /** Losslessly transcode an existing PNG resource into the formats referenced by generated CSS. */
24
+ declare function encodeRasterAsset(source: Buffer, formats: readonly RasterAssetFormat[]): Promise<Map<RasterAssetFormat, Buffer>>;
22
25
  /**
23
26
  * Encode a multi-frame icon: animated WebP (universal), optional GIF for
24
27
  * legacy browsers, PNG as the static first frame (matching upstream's
@@ -28,4 +31,4 @@ interface AnimatedEncodeOptions extends EncodeOptions {
28
31
  declare function encodeAnimatedIcon(frames: FloatTexture[], delaysMs: number[], options?: AnimatedEncodeOptions): Promise<EncodedAnimatedIcon>;
29
32
  declare function encodeIcon(texture: FloatTexture, options?: EncodeOptions): Promise<EncodedIcon>;
30
33
  //#endregion
31
- export { encodeAnimatedIcon as a, EncodedIcon as i, EncodeOptions as n, encodeIcon as o, EncodedAnimatedIcon as r, AnimatedEncodeOptions as t };
34
+ export { RasterAssetFormat as a, encodeRasterAsset as c, EncodedIcon as i, EncodeOptions as n, encodeAnimatedIcon as o, EncodedAnimatedIcon as r, encodeIcon as s, AnimatedEncodeOptions as t };
package/dist/index.d.ts CHANGED
@@ -10,11 +10,11 @@ import { a as pointResize, i as boxDownscale, n as RenderOptions, o as renderMod
10
10
  import { c as defaultProperties, i as ItemRenderInstruction, l as evaluateItemModel, n as InvalidItemDefinitionError, o as TintDefinition, r as ItemProperties, s as UNKNOWN_MODEL } from "./definition-BwX6Xxv0.js";
11
11
  import { i as resolveItem, n as ItemResolutionError, r as discoverItems, t as DiscoveredItem } from "./discovery-CmNYzKPr.js";
12
12
  import { a as resolveTint, i as parseTintValue, n as InvalidTinterDefinitionError, o as resolveTints, t as DYE_COLORS } from "./tints-Fr6WoPaU.js";
13
- import { a as encodeAnimatedIcon, i as EncodedIcon, n as EncodeOptions, o as encodeIcon, r as EncodedAnimatedIcon, t as AnimatedEncodeOptions } from "./encode-BDB_VIHN.js";
13
+ import { i as EncodedIcon, n as EncodeOptions, o as encodeAnimatedIcon, r as EncodedAnimatedIcon, s as encodeIcon, t as AnimatedEncodeOptions } from "./encode-C5kdAm45.js";
14
14
  import { t as minifyStylesheet } from "./minify-CIV6enbr.js";
15
15
  import { a as compareVersions, o as eraForVersion, s as prepareVersionResources } from "./prepare-wfWtaz_X.js";
16
16
  import { i as prepareModResources } from "./prepare-DnnGGv9k.js";
17
17
  import { i as itemClass, n as StylesheetOptions, r as generateStylesheet, t as ItemStyle } from "./stylesheet-i-t_7sZ7.js";
18
- import { i as run, n as RunOptions, r as RunResult, t as ItemFailure } from "./run-D2XL05Zl.js";
18
+ import { i as run, n as RunOptions, r as RunResult, t as ItemFailure } from "./run-BK7Q8WZ3.js";
19
19
  import { n as UnsafeJarError, r as isUnsafeEntryPath, t as JarResourceManager } from "./jar-6T3xdgaL.js";
20
20
  export { type AnimatedEncodeOptions, AnimatedTexture, type AtlasResolver, type AtlasSource, AtlasSourceError, DYE_COLORS, type DiscoveredItem, type EncodeOptions, type EncodedAnimatedIcon, type EncodedIcon, type FloatTexture, FolderResourceManager, InvalidItemDefinitionError, InvalidResourceLocatorError, InvalidTinterDefinitionError, type ItemFailure, type ItemProperties, ItemRenderError, type ItemRenderInstruction, ItemResolutionError, type ItemStyle, JarResourceManager, LayeredResourceManager, type LightSource, LightingProfile, type LightingProfileName, ModelLoader, ModelResolutionError, type RenderOptions, type RenderedFrames, type ResolvedModel, type ResolvedSprite, ResourceKind, type ResourceKindName, ResourceLocator, type ResourceManager, type RunOptions, type RunResult, type StylesheetOptions, type Texture, TextureLoader, type TextureMeta, TextureResolutionError, type TintDefinition, UNKNOWN_MODEL, UnsafeJarError, boxDownscale, builtinDynamicResources, compareVersions, createAtlasResolver, defaultProperties, discoverItems, encodeAnimatedIcon, encodeIcon, eraForVersion, evaluateItemModel, generateStylesheet, isUnsafeEntryPath, itemClass, lightsForProfile, minifyStylesheet, parseAtlasSources, parseTintValue, pointResize, prepareModResources, prepareVersionResources, renderModel, renderModelFrames, resolveItem, resolveTexture, resolveTint, resolveTints, run, salvageJson, toByteTexture, toFloatTexture };
package/dist/index.js CHANGED
@@ -7,14 +7,14 @@ import { a as defaultProperties, i as UNKNOWN_MODEL, n as InvalidItemDefinitionE
7
7
  import { n as discoverItems, r as resolveItem, t as ItemResolutionError } from "./discovery-BzaOti7l.js";
8
8
  import { a as salvageJson, i as resolveTexture, n as ModelResolutionError, t as ModelLoader } from "./loader-C-eqwp3M.js";
9
9
  import { o as toByteTexture, s as toFloatTexture } from "./blend-CHP2-j9U.js";
10
- import { n as encodeIcon, t as encodeAnimatedIcon } from "./encode-BdTHbOp-.js";
10
+ import { n as encodeIcon, t as encodeAnimatedIcon } from "./encode-3u49i-eD.js";
11
11
  import { t as minifyStylesheet } from "./minify-bjMRmr5J.js";
12
12
  import { n as itemClass, t as generateStylesheet } from "./stylesheet-CovT3B2S.js";
13
13
  import { c as lightsForProfile, r as LightingProfile } from "./lighting--5myudVu.js";
14
14
  import { a as renderModelFrames, i as renderModel, n as boxDownscale, r as pointResize, t as ItemRenderError } from "./renderer-CmOz6WI9.js";
15
15
  import { a as resolveTints, i as resolveTint, n as InvalidTinterDefinitionError, r as parseTintValue, t as DYE_COLORS } from "./tints-FQlxTzUL.js";
16
16
  import { n as TextureLoader, r as TextureResolutionError, t as AnimatedTexture } from "./loader-CBzn3Koc.js";
17
- import { t as run } from "./run-CEaRhk4A.js";
17
+ import { t as run } from "./run-Dr6BfyN9.js";
18
18
  import { a as prepareVersionResources, i as eraForVersion, r as compareVersions } from "./prepare-DROxBZp1.js";
19
19
  import { n as prepareModResources } from "./prepare-Bvc5ve2m.js";
20
20
  export { AnimatedTexture, AtlasSourceError, DYE_COLORS, FolderResourceManager, InvalidItemDefinitionError, InvalidResourceLocatorError, InvalidTinterDefinitionError, ItemRenderError, ItemResolutionError, JarResourceManager, LayeredResourceManager, LightingProfile, ModelLoader, ModelResolutionError, ResourceKind, ResourceLocator, TextureLoader, TextureResolutionError, UNKNOWN_MODEL, UnsafeJarError, boxDownscale, builtinDynamicResources, compareVersions, createAtlasResolver, defaultProperties, discoverItems, encodeAnimatedIcon, encodeIcon, eraForVersion, evaluateItemModel, generateStylesheet, isUnsafeEntryPath, itemClass, lightsForProfile, minifyStylesheet, parseAtlasSources, parseTintValue, pointResize, prepareModResources, prepareVersionResources, renderModel, renderModelFrames, resolveItem, resolveTexture, resolveTint, resolveTints, run, salvageJson, toByteTexture, toFloatTexture };
@@ -1,2 +1,2 @@
1
- import { a as encodeAnimatedIcon, i as EncodedIcon, n as EncodeOptions, o as encodeIcon, r as EncodedAnimatedIcon, t as AnimatedEncodeOptions } from "../encode-BDB_VIHN.js";
2
- export { AnimatedEncodeOptions, EncodeOptions, EncodedAnimatedIcon, EncodedIcon, encodeAnimatedIcon, encodeIcon };
1
+ import { a as RasterAssetFormat, c as encodeRasterAsset, i as EncodedIcon, n as EncodeOptions, o as encodeAnimatedIcon, r as EncodedAnimatedIcon, s as encodeIcon, t as AnimatedEncodeOptions } from "../encode-C5kdAm45.js";
2
+ export { AnimatedEncodeOptions, EncodeOptions, EncodedAnimatedIcon, EncodedIcon, RasterAssetFormat, encodeAnimatedIcon, encodeIcon, encodeRasterAsset };
@@ -1,2 +1,2 @@
1
- import { n as encodeIcon, t as encodeAnimatedIcon } from "../encode-BdTHbOp-.js";
2
- export { encodeAnimatedIcon, encodeIcon };
1
+ import { n as encodeIcon, r as encodeRasterAsset, t as encodeAnimatedIcon } from "../encode-3u49i-eD.js";
2
+ export { encodeAnimatedIcon, encodeIcon, encodeRasterAsset };
@@ -46,7 +46,7 @@ interface RunResult {
46
46
  * from genuine misses.
47
47
  */
48
48
  skippedTemplates: string[];
49
- /** Files actually written, the only trustworthy success signal. */
49
+ /** Image files actually written, the only trustworthy success signal. */
50
50
  writtenFiles: number;
51
51
  }
52
52
  declare function run(options: RunOptions): Promise<RunResult>;
@@ -6,7 +6,7 @@ import { a as defaultProperties } from "./definition-3MBm8ar_.js";
6
6
  import { n as discoverItems, r as resolveItem } from "./discovery-BzaOti7l.js";
7
7
  import { t as ModelLoader } from "./loader-C-eqwp3M.js";
8
8
  import { s as toFloatTexture, t as blendPixel } from "./blend-CHP2-j9U.js";
9
- import { t as encodeAnimatedIcon } from "./encode-BdTHbOp-.js";
9
+ import { r as encodeRasterAsset, t as encodeAnimatedIcon } from "./encode-3u49i-eD.js";
10
10
  import { t as classifyItemStyle } from "./item-styles-DJ3LWZS2.js";
11
11
  import { t as minifyStylesheet } from "./minify-bjMRmr5J.js";
12
12
  import { t as generateStylesheet } from "./stylesheet-CovT3B2S.js";
@@ -29,6 +29,8 @@ async function run(options) {
29
29
  const size = options.size ?? 64;
30
30
  const quality = options.quality ?? 2;
31
31
  const prefix = options.prefix ?? "rc-";
32
+ const format = options.format ?? "webp";
33
+ const fallback = options.fallback ?? true;
32
34
  const lightingProfile = options.lightingProfile ?? "modern";
33
35
  const dynamic = options.builtin ? builtinDynamicResources() : null;
34
36
  const resources = options.builtin && dynamic ? new LayeredResourceManager([
@@ -38,6 +40,9 @@ async function run(options) {
38
40
  ]) : options.resources;
39
41
  const models = new ModelLoader(resources);
40
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]);
41
46
  textures.setAtlasResolver(await loadAtlasResolver(resources, (locator) => textures.load(locator)));
42
47
  const ids = [];
43
48
  const seen = /* @__PURE__ */ new Set();
@@ -70,6 +75,11 @@ async function run(options) {
70
75
  const skippedTemplates = [];
71
76
  const styles = [];
72
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
+ }
73
83
  let templateParents = null;
74
84
  const loadTemplateParents = async () => {
75
85
  const parents = /* @__PURE__ */ new Set();
@@ -222,7 +232,7 @@ async function run(options) {
222
232
  const encoded = await encodeAnimatedIcon(frames, delaysMs, {
223
233
  webp: true,
224
234
  gif: options.gif,
225
- avif: options.avif
235
+ avif: options.avif || format === "avif"
226
236
  });
227
237
  const [namespace, itemPath] = id.split(":", 2);
228
238
  const imageBase = path.join(options.output, "items", namespace, `${itemPath}`);
@@ -265,8 +275,8 @@ async function run(options) {
265
275
  }
266
276
  const stylesheet = generateStylesheet(styles, {
267
277
  prefix,
268
- format: options.format ?? "webp",
269
- fallback: options.fallback ?? true
278
+ format,
279
+ fallback
270
280
  });
271
281
  const finalStylesheet = options.minify === false ? stylesheet : minifyStylesheet(stylesheet, (message) => options.onProgress?.(0, 0, "stylesheet", message));
272
282
  await writeFile(path.join(options.output, `${prefix}${namespaces[0]}-${size}.css`), finalStylesheet);
@@ -287,6 +297,14 @@ async function itemExistsIn(resources, id) {
287
297
  if (await resources.hasResource("itemDefinition", locator)) return true;
288
298
  return resources.hasResource("model", new ResourceLocator(locator.namespace, `item/${locator.path}`));
289
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
+ }
290
308
  function blendOver(base, layer) {
291
309
  for (let offset = 0; offset < base.data.length; offset += 4) {
292
310
  const alpha = layer.data[offset + 3];
package/dist/run.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { l as evaluateItemModel } from "./definition-BwX6Xxv0.js";
2
- import { i as run, n as RunOptions, r as RunResult, t as ItemFailure } from "./run-D2XL05Zl.js";
2
+ import { i as run, n as RunOptions, r as RunResult, t as ItemFailure } from "./run-BK7Q8WZ3.js";
3
3
  export { ItemFailure, RunOptions, RunResult, evaluateItemModel, run };
package/dist/run.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import { o as evaluateItemModel } from "./definition-3MBm8ar_.js";
2
- import { t as run } from "./run-CEaRhk4A.js";
2
+ import { t as run } from "./run-Dr6BfyN9.js";
3
3
  export { evaluateItemModel, run };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodecraft/rendermite",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Minecraft item icon renderer: renders inventory-identical item icons from vanilla and modded assets across game versions, outputting optimized PNG/WebP/AVIF plus CSS and a JSON item library.",
5
5
  "type": "module",
6
6
  "license": "MIT",