@kurot/atlas 0.0.0-stage → 0.1.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/CHANGELOG.md +150 -0
- package/LICENSE +21 -0
- package/README.md +146 -2
- package/dist/AtlasError.d.ts +9 -0
- package/dist/AtlasError.d.ts.map +1 -0
- package/dist/AtlasError.js +12 -0
- package/dist/AtlasError.js.map +1 -0
- package/dist/AtlasTypes.d.ts +76 -0
- package/dist/AtlasTypes.d.ts.map +1 -0
- package/dist/AtlasTypes.js +2 -0
- package/dist/AtlasTypes.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/layout.d.ts +10 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +39 -0
- package/dist/layout.js.map +1 -0
- package/dist/max-rects.d.ts +17 -0
- package/dist/max-rects.d.ts.map +1 -0
- package/dist/max-rects.js +67 -0
- package/dist/max-rects.js.map +1 -0
- package/dist/options.d.ts +5 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +64 -0
- package/dist/options.js.map +1 -0
- package/dist/pack-atlas.d.ts +7 -0
- package/dist/pack-atlas.d.ts.map +1 -0
- package/dist/pack-atlas.js +16 -0
- package/dist/pack-atlas.js.map +1 -0
- package/dist/png/index.d.ts +26 -0
- package/dist/png/index.d.ts.map +1 -0
- package/dist/png/index.js +114 -0
- package/dist/png/index.js.map +1 -0
- package/dist/render.d.ts +6 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +40 -0
- package/dist/render.js.map +1 -0
- package/dist/trim.d.ts +12 -0
- package/dist/trim.d.ts.map +1 -0
- package/dist/trim.js +29 -0
- package/dist/trim.js.map +1 -0
- package/docs/ai-context.md +78 -0
- package/docs/cli-integration.md +130 -0
- package/docs/reference-validation.md +62 -0
- package/package.json +40 -5
package/dist/options.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { AtlasError } from './AtlasError.js';
|
|
2
|
+
export function resolveOptions(options) {
|
|
3
|
+
const resolved = {
|
|
4
|
+
file: options.file ?? 'atlas.png',
|
|
5
|
+
maxWidth: options.maxWidth ?? 2048,
|
|
6
|
+
maxHeight: options.maxHeight ?? 2048,
|
|
7
|
+
trim: options.trim ?? true,
|
|
8
|
+
alphaThreshold: options.alphaThreshold ?? 1,
|
|
9
|
+
trimMargin: options.trimMargin ?? 1,
|
|
10
|
+
extrude: options.extrude ?? 1,
|
|
11
|
+
shapePadding: options.shapePadding ?? 0,
|
|
12
|
+
borderPadding: options.borderPadding ?? 0,
|
|
13
|
+
maxPixels: options.maxPixels ?? 16_777_216,
|
|
14
|
+
};
|
|
15
|
+
if (typeof resolved.file !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9_.-]*\.png$/.test(resolved.file)) {
|
|
16
|
+
throw new AtlasError('invalid-options', 'file must be a PNG basename without directories.');
|
|
17
|
+
}
|
|
18
|
+
if (typeof resolved.trim !== 'boolean') {
|
|
19
|
+
throw new AtlasError('invalid-options', 'trim must be boolean.');
|
|
20
|
+
}
|
|
21
|
+
for (const key of ['maxWidth', 'maxHeight']) {
|
|
22
|
+
checkInteger(key, resolved[key], 1, 16_384);
|
|
23
|
+
}
|
|
24
|
+
checkInteger('alphaThreshold', resolved.alphaThreshold, 1, 255);
|
|
25
|
+
for (const key of ['trimMargin', 'extrude', 'shapePadding', 'borderPadding']) {
|
|
26
|
+
checkInteger(key, resolved[key], 0, 1024);
|
|
27
|
+
}
|
|
28
|
+
checkInteger('maxPixels', resolved.maxPixels, 1, 67_108_864);
|
|
29
|
+
return resolved;
|
|
30
|
+
}
|
|
31
|
+
export function validateSources(sources, options) {
|
|
32
|
+
if (!Array.isArray(sources) || sources.length === 0 || sources.length > 4096) {
|
|
33
|
+
throw new AtlasError('invalid-input', 'Provide between 1 and 4096 source images.');
|
|
34
|
+
}
|
|
35
|
+
const names = new Set();
|
|
36
|
+
let pixels = 0;
|
|
37
|
+
for (const source of sources) {
|
|
38
|
+
if (typeof source.name !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9_.-]*$/.test(source.name)) {
|
|
39
|
+
throw new AtlasError('invalid-input', 'Source names must be nonempty resource keys without paths or whitespace.');
|
|
40
|
+
}
|
|
41
|
+
if (names.has(source.name)) {
|
|
42
|
+
throw new AtlasError('invalid-input', `Duplicate source name: ${source.name}.`);
|
|
43
|
+
}
|
|
44
|
+
names.add(source.name);
|
|
45
|
+
if (!Number.isSafeInteger(source.width) || source.width < 1 ||
|
|
46
|
+
!Number.isSafeInteger(source.height) || source.height < 1) {
|
|
47
|
+
throw new AtlasError('invalid-input', `Invalid source dimensions: ${source.name}.`);
|
|
48
|
+
}
|
|
49
|
+
pixels += source.width * source.height;
|
|
50
|
+
if (!Number.isSafeInteger(pixels) || pixels > options.maxPixels) {
|
|
51
|
+
throw new AtlasError('invalid-input', 'Total source pixels exceed maxPixels.');
|
|
52
|
+
}
|
|
53
|
+
if (!(source.pixels instanceof Uint8Array || source.pixels instanceof Uint8ClampedArray) ||
|
|
54
|
+
source.pixels.length !== source.width * source.height * 4) {
|
|
55
|
+
throw new AtlasError('invalid-input', `Expected width × height × 4 RGBA bytes: ${source.name}.`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function checkInteger(key, value, min, max) {
|
|
60
|
+
if (!Number.isSafeInteger(value) || value < min || value > max) {
|
|
61
|
+
throw new AtlasError('invalid-options', `${key} must be an integer in ${min}–${max}.`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAK7C,MAAM,UAAU,cAAc,CAAC,OAAqB;IACnD,MAAM,QAAQ,GAAG;QAChB,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MAAM,IAAI,UAAU,CAAC,eAAe,EAAE,8BAA8B,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC;QACrF,CAAC;QACD,MAAM,IAAI,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC;QACvC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;YACjE,MAAM,IAAI,UAAU,CAAC,eAAe,EAAE,uCAAuC,CAAC,CAAC;QAChF,CAAC;QACD,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,YAAY,UAAU,IAAI,MAAM,CAAC,MAAM,YAAY,iBAAiB,CAAC;YACvF,MAAM,CAAC,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5D,MAAM,IAAI,UAAU,CAAC,eAAe,EAAE,2CAA2C,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC;QAClG,CAAC;IACF,CAAC;AACF,CAAC;AAED,SAAS,YAAY,CAAC,GAAW,EAAE,KAAa,EAAE,GAAW,EAAE,GAAW;IACzE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,GAAG,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;QAChE,MAAM,IAAI,UAAU,CAAC,iBAAiB,EAAE,GAAG,GAAG,0BAA0B,GAAG,IAAI,GAAG,GAAG,CAAC,CAAC;IACxF,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AtlasOptions, AtlasResult, AtlasSource } from './AtlasTypes.js';
|
|
2
|
+
/**
|
|
3
|
+
* Packs one nonrotated atlas. Deterministic for the same named pixels and options,
|
|
4
|
+
* independent of input order. Performs no I/O and never mutates source buffers.
|
|
5
|
+
*/
|
|
6
|
+
export declare function packAtlas(sources: readonly AtlasSource[], options?: AtlasOptions): AtlasResult;
|
|
7
|
+
//# sourceMappingURL=pack-atlas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack-atlas.d.ts","sourceRoot":"","sources":["../src/pack-atlas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAM9E;;;GAGG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,EAAE,OAAO,GAAE,YAAiB,GAAG,WAAW,CAMlG"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createLayout } from './layout.js';
|
|
2
|
+
import { resolveOptions, validateSources } from './options.js';
|
|
3
|
+
import { renderAtlas } from './render.js';
|
|
4
|
+
import { prepareSource } from './trim.js';
|
|
5
|
+
/**
|
|
6
|
+
* Packs one nonrotated atlas. Deterministic for the same named pixels and options,
|
|
7
|
+
* independent of input order. Performs no I/O and never mutates source buffers.
|
|
8
|
+
*/
|
|
9
|
+
export function packAtlas(sources, options = {}) {
|
|
10
|
+
const settings = resolveOptions(options);
|
|
11
|
+
validateSources(sources, settings);
|
|
12
|
+
const prepared = sources.map(source => prepareSource(source, settings))
|
|
13
|
+
.sort((a, b) => a.source.name < b.source.name ? -1 : a.source.name > b.source.name ? 1 : 0);
|
|
14
|
+
return renderAtlas(prepared, createLayout(prepared, settings), settings);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=pack-atlas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack-atlas.js","sourceRoot":"","sources":["../src/pack-atlas.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,OAA+B,EAAE,UAAwB,EAAE;IACpF,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACzC,eAAe,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACnC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;SACrE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7F,OAAO,WAAW,CAAC,QAAQ,EAAE,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AtlasData, AtlasImage, AtlasOptions } from '../AtlasTypes.js';
|
|
2
|
+
export interface PNGAtlasSource {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly png: Uint8Array;
|
|
5
|
+
}
|
|
6
|
+
export interface PNGAtlasResult {
|
|
7
|
+
png: Uint8Array;
|
|
8
|
+
data: AtlasData;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Node.js PNG adapter. Decodes all sources, packs once and encodes RGBA8 PNG.
|
|
14
|
+
* Performs no filesystem writes. Run large jobs in a caller-owned worker.
|
|
15
|
+
*/
|
|
16
|
+
export declare function packPNGAtlas(sources: readonly PNGAtlasSource[], options?: AtlasOptions): PNGAtlasResult;
|
|
17
|
+
/**
|
|
18
|
+
* Decodes static PNG to straight-alpha RGBA8 without gamma correction.
|
|
19
|
+
* maxPixels defaults to 16,777,216; input is limited to 32 MiB. APNG is rejected.
|
|
20
|
+
*/
|
|
21
|
+
export declare function decodePNG(bytes: Uint8Array, maxPixels?: number): AtlasImage;
|
|
22
|
+
/**
|
|
23
|
+
* Encodes straight-alpha RGBA as a static 8-bit PNG; leaves the image buffer unchanged.
|
|
24
|
+
*/
|
|
25
|
+
export declare function encodePNG(image: AtlasImage): Uint8Array;
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/png/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAI5E,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;CACzB;AAED,MAAM,WAAW,cAAc;IAC9B,GAAG,EAAE,UAAU,CAAC;IAChB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,EAAE,OAAO,GAAE,YAAiB,GAAG,cAAc,CAgB3G;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,SAAa,GAAG,UAAU,CAiC/E;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAWvD"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { PNG } from 'pngjs';
|
|
3
|
+
import { inflateSync } from 'node:zlib';
|
|
4
|
+
import { AtlasError } from '../AtlasError.js';
|
|
5
|
+
import { packAtlas } from '../pack-atlas.js';
|
|
6
|
+
import { resolveOptions } from '../options.js';
|
|
7
|
+
/**
|
|
8
|
+
* Node.js PNG adapter. Decodes all sources, packs once and encodes RGBA8 PNG.
|
|
9
|
+
* Performs no filesystem writes. Run large jobs in a caller-owned worker.
|
|
10
|
+
*/
|
|
11
|
+
export function packPNGAtlas(sources, options = {}) {
|
|
12
|
+
const settings = resolveOptions(options);
|
|
13
|
+
if (!Array.isArray(sources) || sources.length === 0 || sources.length > 4096) {
|
|
14
|
+
throw new AtlasError('invalid-input', 'Provide between 1 and 4096 PNG sources.');
|
|
15
|
+
}
|
|
16
|
+
let pixelCount = 0;
|
|
17
|
+
// Read every header before decoding so an oversized batch cannot allocate all decoded images first.
|
|
18
|
+
for (const source of sources) {
|
|
19
|
+
pixelCount += readPixelCount(source.png);
|
|
20
|
+
if (!Number.isSafeInteger(pixelCount) || pixelCount > settings.maxPixels) {
|
|
21
|
+
throw new AtlasError('invalid-input', 'Total source pixels exceed maxPixels.');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const decoded = sources.map(source => ({ name: source.name, ...decodePNG(source.png, settings.maxPixels) }));
|
|
25
|
+
const result = packAtlas(decoded, settings);
|
|
26
|
+
return { png: encodePNG(result.image), data: result.data, width: result.image.width, height: result.image.height };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Decodes static PNG to straight-alpha RGBA8 without gamma correction.
|
|
30
|
+
* maxPixels defaults to 16,777,216; input is limited to 32 MiB. APNG is rejected.
|
|
31
|
+
*/
|
|
32
|
+
export function decodePNG(bytes, maxPixels = 16_777_216) {
|
|
33
|
+
if (!Number.isSafeInteger(maxPixels) || maxPixels < 1 || maxPixels > 67_108_864) {
|
|
34
|
+
throw new AtlasError('invalid-options', 'Invalid maxPixels limit.');
|
|
35
|
+
}
|
|
36
|
+
const pixels = readPixelCount(bytes);
|
|
37
|
+
if (pixels > maxPixels) {
|
|
38
|
+
throw new AtlasError('invalid-input', 'PNG pixels exceed maxPixels.');
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
// pngjs bounds ordinary scanlines but uses an unbounded inflate for Adam7.
|
|
42
|
+
// Verify that stream first: even RGBA16 needs at most 8 bytes plus one
|
|
43
|
+
// filter byte per pixel, including all seven passes.
|
|
44
|
+
if (bytes[28] === 1) {
|
|
45
|
+
const buffer = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
46
|
+
const chunks = [];
|
|
47
|
+
for (let offset = 33; offset + 12 <= buffer.length;) {
|
|
48
|
+
const length = buffer.readUInt32BE(offset);
|
|
49
|
+
const type = buffer.toString('latin1', offset + 4, offset + 8);
|
|
50
|
+
if (type === 'IEND') {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
if (type === 'IDAT' && length > 0) {
|
|
54
|
+
chunks.push(buffer.subarray(offset + 8, offset + 8 + length));
|
|
55
|
+
}
|
|
56
|
+
offset += length + 12;
|
|
57
|
+
}
|
|
58
|
+
inflateSync(Buffer.concat(chunks), { maxOutputLength: pixels * 9 });
|
|
59
|
+
}
|
|
60
|
+
const png = PNG.sync.read(Buffer.from(bytes), { checkCRC: true });
|
|
61
|
+
return { width: png.width, height: png.height, pixels: new Uint8Array(png.data) };
|
|
62
|
+
}
|
|
63
|
+
catch (cause) {
|
|
64
|
+
throw new AtlasError('invalid-png', 'Unable to decode PNG.', { cause });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Encodes straight-alpha RGBA as a static 8-bit PNG; leaves the image buffer unchanged.
|
|
69
|
+
*/
|
|
70
|
+
export function encodePNG(image) {
|
|
71
|
+
if (!Number.isSafeInteger(image.width) || image.width < 1 || !Number.isSafeInteger(image.height) || image.height < 1 ||
|
|
72
|
+
image.width * image.height > 67_108_864 ||
|
|
73
|
+
!(image.pixels instanceof Uint8Array || image.pixels instanceof Uint8ClampedArray) ||
|
|
74
|
+
image.pixels.length !== image.width * image.height * 4) {
|
|
75
|
+
throw new AtlasError('invalid-input', 'Invalid RGBA image dimensions or pixels.');
|
|
76
|
+
}
|
|
77
|
+
const png = new PNG({ width: image.width, height: image.height });
|
|
78
|
+
png.data.set(image.pixels);
|
|
79
|
+
return new Uint8Array(PNG.sync.write(png, { colorType: 6, inputColorType: 6, bitDepth: 8, deflateLevel: 9, deflateStrategy: 3, filterType: -1 }));
|
|
80
|
+
}
|
|
81
|
+
function readPixelCount(bytes) {
|
|
82
|
+
if (!(bytes instanceof Uint8Array) || bytes.length < 33 || bytes.length > 33_554_432) {
|
|
83
|
+
throw new AtlasError('invalid-png', 'PNG input must contain 33 bytes to 32 MiB.');
|
|
84
|
+
}
|
|
85
|
+
const signature = [137, 80, 78, 71, 13, 10, 26, 10];
|
|
86
|
+
if (!signature.every((byte, index) => bytes[index] === byte)) {
|
|
87
|
+
throw new AtlasError('invalid-png', 'Invalid PNG signature.');
|
|
88
|
+
}
|
|
89
|
+
const buffer = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
90
|
+
if (buffer.readUInt32BE(8) !== 13 || buffer.toString('ascii', 12, 16) !== 'IHDR') {
|
|
91
|
+
throw new AtlasError('invalid-png', 'PNG must start with an IHDR chunk.');
|
|
92
|
+
}
|
|
93
|
+
const width = buffer.readUInt32BE(16);
|
|
94
|
+
const height = buffer.readUInt32BE(20);
|
|
95
|
+
if (width === 0 || height === 0 || !Number.isSafeInteger(width * height)) {
|
|
96
|
+
throw new AtlasError('invalid-png', 'Invalid PNG dimensions.');
|
|
97
|
+
}
|
|
98
|
+
for (let offset = 8; offset + 12 <= buffer.length;) {
|
|
99
|
+
const length = buffer.readUInt32BE(offset);
|
|
100
|
+
if (length > buffer.length - offset - 12) {
|
|
101
|
+
throw new AtlasError('invalid-png', 'Truncated PNG chunk.');
|
|
102
|
+
}
|
|
103
|
+
const type = buffer.toString('latin1', offset + 4, offset + 8);
|
|
104
|
+
if (offset !== 8 && type === 'IHDR') {
|
|
105
|
+
throw new AtlasError('invalid-png', 'PNG must contain exactly one IHDR chunk.');
|
|
106
|
+
}
|
|
107
|
+
if (type === 'acTL') {
|
|
108
|
+
throw new AtlasError('invalid-png', 'Animated PNG is not supported.');
|
|
109
|
+
}
|
|
110
|
+
offset += length + 12;
|
|
111
|
+
}
|
|
112
|
+
return width * height;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/png/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAc/C;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,OAAkC,EAAE,UAAwB,EAAE;IAC1F,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACzC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,EAAE,CAAC;QAC9E,MAAM,IAAI,UAAU,CAAC,eAAe,EAAE,yCAAyC,CAAC,CAAC;IAClF,CAAC;IACD,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,oGAAoG;IACpG,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC9B,UAAU,IAAI,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC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AAG,EAAE,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QACpD,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAC3C,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,EAAE,EAAE,CAAC;YAC1C,MAAM,IAAI,UAAU,CAAC,aAAa,EAAE,sBAAsB,CAAC,CAAC;QAC7D,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC;QAC/D,IAAI,MAAM,KAAK,CAAC,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;YACrC,MAAM,IAAI,UAAU,CAAC,aAAa,EAAE,0CAA0C,CAAC,CAAC;QACjF,CAAC;QACD,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;YACrB,MAAM,IAAI,UAAU,CAAC,aAAa,EAAE,gCAAgC,CAAC,CAAC;QACvE,CAAC;QACD,MAAM,IAAI,MAAM,GAAG,EAAE,CAAC;IACvB,CAAC;IACD,OAAO,KAAK,GAAG,MAAM,CAAC;AACvB,CAAC"}
|
package/dist/render.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AtlasResult } from './AtlasTypes.js';
|
|
2
|
+
import type { AtlasLayout } from './layout.js';
|
|
3
|
+
import type { PackingOptions } from './options.js';
|
|
4
|
+
import type { PreparedSource } from './trim.js';
|
|
5
|
+
export declare function renderAtlas(sources: readonly PreparedSource[], layout: AtlasLayout, options: PackingOptions): AtlasResult;
|
|
6
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,wBAAgB,WAAW,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,GAAG,WAAW,CAoBzH"}
|
package/dist/render.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export function renderAtlas(sources, layout, options) {
|
|
2
|
+
const pixels = new Uint8Array(layout.width * layout.height * 4);
|
|
3
|
+
const positions = new Map(layout.placements.map(rect => [rect.name, rect]));
|
|
4
|
+
const frames = sources.map(item => {
|
|
5
|
+
const rect = positions.get(item.source.name);
|
|
6
|
+
const x = rect.x + options.extrude;
|
|
7
|
+
const y = rect.y + options.extrude;
|
|
8
|
+
const frame = { x, y, w: item.width, h: item.height };
|
|
9
|
+
if (item.x !== 0 || item.y !== 0 || item.width !== item.source.width || item.height !== item.source.height) {
|
|
10
|
+
frame.offX = item.x;
|
|
11
|
+
frame.offY = item.y;
|
|
12
|
+
frame.sourceW = item.source.width;
|
|
13
|
+
frame.sourceH = item.source.height;
|
|
14
|
+
}
|
|
15
|
+
if (!item.empty) {
|
|
16
|
+
blit(item, pixels, layout.width, x, y, options.extrude);
|
|
17
|
+
}
|
|
18
|
+
return [item.source.name, frame];
|
|
19
|
+
});
|
|
20
|
+
return { image: { width: layout.width, height: layout.height, pixels }, data: { file: options.file, frames: Object.fromEntries(frames) } };
|
|
21
|
+
}
|
|
22
|
+
function blit(item, target, targetWidth, x, y, extrude) {
|
|
23
|
+
for (let dy = -extrude; dy < item.height + extrude; dy++) {
|
|
24
|
+
const sy = item.y + Math.max(0, Math.min(item.height - 1, dy));
|
|
25
|
+
for (let dx = -extrude; dx < item.width + extrude; dx++) {
|
|
26
|
+
const sx = item.x + Math.max(0, Math.min(item.width - 1, dx));
|
|
27
|
+
const sourceOffset = (sy * item.source.width + sx) * 4;
|
|
28
|
+
const targetOffset = ((y + dy) * targetWidth + x + dx) * 4;
|
|
29
|
+
const alpha = item.source.pixels[sourceOffset + 3];
|
|
30
|
+
// Straight alpha is retained; hidden RGB is canonicalized to avoid stale transparent pixels.
|
|
31
|
+
if (alpha === 0)
|
|
32
|
+
continue;
|
|
33
|
+
target[targetOffset] = item.source.pixels[sourceOffset];
|
|
34
|
+
target[targetOffset + 1] = item.source.pixels[sourceOffset + 1];
|
|
35
|
+
target[targetOffset + 2] = item.source.pixels[sourceOffset + 2];
|
|
36
|
+
target[targetOffset + 3] = alpha;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,WAAW,CAAC,OAAkC,EAAE,MAAmB,EAAE,OAAuB;IAC3G,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAC5E,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QACjC,MAAM,IAAI,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAE,CAAC;QAC9C,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;QACnC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;QACnC,MAAM,KAAK,GAAe,EAAE,CAAC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AAC;YACjE,MAAM,CAAC,YAAY,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;QAClC,CAAC;IACF,CAAC;AACF,CAAC"}
|
package/dist/trim.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AtlasSource } from './AtlasTypes.js';
|
|
2
|
+
import type { PackingOptions } from './options.js';
|
|
3
|
+
export interface PreparedSource {
|
|
4
|
+
source: AtlasSource;
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
empty: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function prepareSource(source: AtlasSource, options: PackingOptions): PreparedSource;
|
|
12
|
+
//# sourceMappingURL=trim.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trim.d.ts","sourceRoot":"","sources":["../src/trim.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,MAAM,WAAW,cAAc;IAC9B,MAAM,EAAE,WAAW,CAAC;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;CACf;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,GAAG,cAAc,CA0B1F"}
|
package/dist/trim.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function prepareSource(source, options) {
|
|
2
|
+
if (!options.trim) {
|
|
3
|
+
return { source, x: 0, y: 0, width: source.width, height: source.height, empty: false };
|
|
4
|
+
}
|
|
5
|
+
let left = source.width;
|
|
6
|
+
let top = source.height;
|
|
7
|
+
let right = -1;
|
|
8
|
+
let bottom = -1;
|
|
9
|
+
for (let y = 0; y < source.height; y++) {
|
|
10
|
+
for (let x = 0; x < source.width; x++) {
|
|
11
|
+
if (source.pixels[(y * source.width + x) * 4 + 3] < options.alphaThreshold)
|
|
12
|
+
continue;
|
|
13
|
+
left = Math.min(left, x);
|
|
14
|
+
top = Math.min(top, y);
|
|
15
|
+
right = Math.max(right, x);
|
|
16
|
+
bottom = Math.max(bottom, y);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (right < 0) {
|
|
20
|
+
// A transparent placeholder retains original logical dimensions without zero-sized textures.
|
|
21
|
+
return { source, x: 0, y: 0, width: 1, height: 1, empty: true };
|
|
22
|
+
}
|
|
23
|
+
left = Math.max(0, left - options.trimMargin);
|
|
24
|
+
top = Math.max(0, top - options.trimMargin);
|
|
25
|
+
right = Math.min(source.width - 1, right + options.trimMargin);
|
|
26
|
+
bottom = Math.min(source.height - 1, bottom + options.trimMargin);
|
|
27
|
+
return { source, x: left, y: top, width: right - left + 1, height: bottom - top + 1, empty: false };
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=trim.js.map
|
package/dist/trim.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trim.js","sourceRoot":"","sources":["../src/trim.ts"],"names":[],"mappings":"AAYA,MAAM,UAAU,aAAa,CAAC,MAAmB,EAAE,OAAuB;IACzE,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QACnB,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IACzF,CAAC;IACD,IAAI,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC;IACxB,IAAI,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC;IACxB,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;IACf,IAAI,M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AAC,CAAC;IAC/D,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAClE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,GAAG,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AACrG,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# @kurot/atlas — AI context map
|
|
2
|
+
|
|
3
|
+
Version 0.1.1, prepared for publication. Independent build-time
|
|
4
|
+
atlas library; no Kurot package dependencies. Private tools/default-ui-assets
|
|
5
|
+
consumes registry 0.1.0 to generate the committed KUI default atlas. No published
|
|
6
|
+
SDK or browser runtime gains an atlas dependency.
|
|
7
|
+
Read README.md for input limits and the pixel/output contract.
|
|
8
|
+
|
|
9
|
+
## Directory map
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
src/
|
|
13
|
+
index.ts Portable public entry point, no Node or PNG imports
|
|
14
|
+
AtlasTypes.ts Pixels, stable source names, options and flat sheet types
|
|
15
|
+
AtlasError.ts Error categories
|
|
16
|
+
options.ts Bounds and pixel/source validation
|
|
17
|
+
trim.ts Alpha crop, retained margins, transparent placeholder
|
|
18
|
+
max-rects.ts Nonrotated placement, split/prune free rectangles
|
|
19
|
+
layout.ts POT candidate search and deterministic sorting
|
|
20
|
+
render.ts RGBA blit, edge/corner extrusion, frame serialization
|
|
21
|
+
pack-atlas.ts Pure pack pipeline
|
|
22
|
+
png/index.ts Node-only static PNG decode/encode and batch adapter
|
|
23
|
+
test/
|
|
24
|
+
helpers.ts Synthetic RGBA sources and pixel access
|
|
25
|
+
pack-atlas.test.ts Pixel geometry, packing invariants, validation
|
|
26
|
+
png.test.ts Codec roundtrip, PNG contract and input limits
|
|
27
|
+
scripts/
|
|
28
|
+
verify-reference.ts Read-only local sample validation with output/report in a new directory
|
|
29
|
+
reference-checks.ts Independent crop, pixel, extrusion and overlap checks
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Public API
|
|
33
|
+
|
|
34
|
+
- `packAtlas(sources, options?)`: in-memory RGBA to AtlasResult (image and data).
|
|
35
|
+
- `AtlasError`, `AtlasErrorCode`: categorized failures.
|
|
36
|
+
- `AtlasImage`, `AtlasSource`, `AtlasOptions`, `AtlasFrame`, `AtlasData`, `AtlasResult`.
|
|
37
|
+
- Subpath `@kurot/atlas/png`: `decodePNG`, `encodePNG`, `packPNGAtlas`,
|
|
38
|
+
`PNGAtlasSource`, `PNGAtlasResult`. All synchronous, Node.js >=20; no I/O.
|
|
39
|
+
|
|
40
|
+
## Non-obvious invariants
|
|
41
|
+
|
|
42
|
+
- Name is the exact authored resource key, not a guessed filename. Duplicate names
|
|
43
|
+
reject, duplicate pixels do not alias. Object member names are safe frame keys.
|
|
44
|
+
- Input buffers remain unchanged. Output zero-alpha RGB is zero; alpha is straight.
|
|
45
|
+
- Extrusion is outside frames; offX/offY locate trimmed pixels in the source canvas.
|
|
46
|
+
SourceW/sourceH are logical dimensions, not packing bounds.
|
|
47
|
+
- Fully transparent cropped images emit one clear pixel plus original logical size.
|
|
48
|
+
- Trimming is per source; no automatic nine-slice detection. Callers may disable
|
|
49
|
+
trimming for a batch. No default-resource metadata is authored here.
|
|
50
|
+
- Candidate sizes are powers of two and can be rectangular. Packing is heuristic;
|
|
51
|
+
output is deterministic but not identical to TexturePacker.
|
|
52
|
+
- Shape padding reserves right/bottom space even for an outermost item; extrusion
|
|
53
|
+
is already included separately. Border padding is outside all placements.
|
|
54
|
+
- Default settings match the observed sample's trim threshold/margin/extrusion and
|
|
55
|
+
POT single-sheet profile. This is not a generic `.tps` compatibility promise.
|
|
56
|
+
- Errors and results never change files. Atomic project replacement, manifest
|
|
57
|
+
preservation, cache invalidation and worker scheduling belong to the caller.
|
|
58
|
+
- PNG metadata/colorspace are not propagated or gamma-corrected; output is RGBA8.
|
|
59
|
+
- Public root exports must stay free of Node/pngjs imports. No runtime library may
|
|
60
|
+
gain an atlas dependency just to load prebuilt sheets.
|
|
61
|
+
|
|
62
|
+
## Task routing
|
|
63
|
+
|
|
64
|
+
| Task | Files |
|
|
65
|
+
| --- | --- |
|
|
66
|
+
| Input/output contracts | AtlasTypes.ts, options.ts, README.md |
|
|
67
|
+
| Crop/empty-source behavior | trim.ts, render.ts, pixel tests |
|
|
68
|
+
| Packing density/determinism | max-rects.ts, layout.ts, packing tests |
|
|
69
|
+
| Extrusion/transparent RGB | render.ts, pixel tests |
|
|
70
|
+
| PNG safety/encoding | png/index.ts, png.test.ts |
|
|
71
|
+
| Reskin/Editor persistence | Consumer service; outside this package |
|
|
72
|
+
| Sample compatibility and repeatable verification | docs/reference-validation.md, scripts/ |
|
|
73
|
+
| CLI asset watching, validation and future packing | docs/cli-integration.md |
|
|
74
|
+
|
|
75
|
+
Build and test from packages/atlas with pnpm; tests typecheck separately.
|
|
76
|
+
Every new exported function has an explicit return type. Keep new source files
|
|
77
|
+
under 300 lines and follow root docs/code-rules.md. Tests must remain self-contained;
|
|
78
|
+
the local ui-tps directories are read-only reference material, not CI dependencies.
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Atlas integration with CLI and optimization recommendations
|
|
2
|
+
|
|
3
|
+
This document describes the current atlas pipeline and optional tooling work.
|
|
4
|
+
|
|
5
|
+
## Current pipeline
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
Source images → @kurot/atlas → PNG + atlas JSON
|
|
9
|
+
↓ saved by the caller
|
|
10
|
+
resource/default.res.json → CLI reads resource defaults → KUI compilation
|
|
11
|
+
PNG/JSON under resource/ → CLI copyAssets → build output
|
|
12
|
+
Atlas JSON/PNG in output → Core SheetAnalyzer → SpriteSheet / Texture
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
CLI does not parse atlas frame coordinates or PNG data when compiling KUI.
|
|
16
|
+
`src/core/kui/skin-module-builder.ts` reads `default.res.json` and uses
|
|
17
|
+
ui-document's `parseUIResourceConfigEntries` to obtain resources and nine-slice
|
|
18
|
+
defaults. `kui-parser.ts` applies resource defaults, Label presets and colors to
|
|
19
|
+
copies, in that order. `plugins/copy-assets.ts` copies resource files, excluding
|
|
20
|
+
authored KUI and generated theme files.
|
|
21
|
+
|
|
22
|
+
Core's `packages/core/src/kurot/resource/analyzers/SheetAnalyzer.ts` reads
|
|
23
|
+
`file/frames` at runtime and passes crop coordinates, offsets and original sizes
|
|
24
|
+
to `SpriteSheet.createTexture`. The output format supports
|
|
25
|
+
this pipeline; adopting the library does not require changes to CLI's KUI parser
|
|
26
|
+
or Core.
|
|
27
|
+
|
|
28
|
+
Atlas remains independent. Reskin/Editor resource services can call it. If CLI
|
|
29
|
+
later offers packing, CLI may depend on atlas; atlas must not depend on CLI/Core.
|
|
30
|
+
Copying or consuming prebuilt atlases requires no new dependency.
|
|
31
|
+
|
|
32
|
+
## Resource updates and grouped commits
|
|
33
|
+
|
|
34
|
+
The CLI watches the resource tree, batches copies, handles deletion and serves
|
|
35
|
+
no-store responses. Resource watching works without a UI configuration. See
|
|
36
|
+
[CLI resource watching](../../cli/docs/dev-resource-watching.md) for the current
|
|
37
|
+
implementation and batch limits. PNG/atlas JSON changes refresh resources;
|
|
38
|
+
manifest defaults, styles and KUI changes also request Skin recompilation. Browser
|
|
39
|
+
refresh remains manual.
|
|
40
|
+
|
|
41
|
+
Strict PNG/JSON transactions remain a separate tooling concern.
|
|
42
|
+
Renaming PNG and JSON separately does not create an atomic two-file transaction.
|
|
43
|
+
The caller should generate and validate temporary outputs, then commit the whole
|
|
44
|
+
pair. In one process, a commit-complete event can serialize copying. External
|
|
45
|
+
file watchers may use debouncing and bounded retries, but these cannot guarantee
|
|
46
|
+
that same-sized PNG/JSON files belong to the same generation. Strict consistency
|
|
47
|
+
across processes may require versioned directories with a single pointer switch,
|
|
48
|
+
or an explicit commit marker / generation protocol. Review that design separately.
|
|
49
|
+
Publish success only after grouped validation and copying finish. Preview refresh
|
|
50
|
+
must also account for Core resource caches and browser caches. A full-page reload
|
|
51
|
+
is more reliable for the first stage than clearing one subtexture. Do not add
|
|
52
|
+
undefined cache fields to output JSON.
|
|
53
|
+
|
|
54
|
+
## Second priority: resource integrity checks before building
|
|
55
|
+
|
|
56
|
+
Add a separate validation step before compilation/copying, without changing
|
|
57
|
+
authored KUI:
|
|
58
|
+
|
|
59
|
+
- A manifest sheet URL points to an existing JSON file, whose `file` points to a
|
|
60
|
+
valid, existing relative PNG.
|
|
61
|
+
- PNG dimensions, integer frame fields, bounds, crop offsets and logical sizes
|
|
62
|
+
agree. Reject unsupported rotation formats.
|
|
63
|
+
- Keep `subkeys` in object form. Compare them with actual frames and report missing
|
|
64
|
+
or extra entries. In strict mode, fail on unresolved frame references, including
|
|
65
|
+
the sheet name, resource path and frame name in the error.
|
|
66
|
+
- Validate resource-default `scale9grid` against untrimmed sourceW/sourceH. Do not
|
|
67
|
+
recalculate it from atlas x/y or cropped w/h.
|
|
68
|
+
- Preserve existing name/alias precedence and distinguish duplicate bare frame
|
|
69
|
+
names from usable `sheet.frame` references.
|
|
70
|
+
|
|
71
|
+
See `packages/ui-document/docs/resource-nine-slice.md` for the contract. The
|
|
72
|
+
existing manifest parser does not read PNG/frame files, so successful parsing
|
|
73
|
+
is not complete atlas validation. Pure format checks can live in a separate
|
|
74
|
+
tool module. Do not force Core or ui-document to depend on atlas just to read
|
|
75
|
+
prebuilt sheets. If a shared validator is introduced, consider a separate entry
|
|
76
|
+
without PNG encoding before deciding whether CLI needs the dependency.
|
|
77
|
+
|
|
78
|
+
Reskin preserves resource keys by default and replaces assets under existing
|
|
79
|
+
keys. Repacking does not require regenerating the whole manifest. Preserve frame
|
|
80
|
+
nine-slice values, unknown metadata, groups, URLs and resource order. Report key
|
|
81
|
+
set changes before applying them; do not silently remove or rewrite references.
|
|
82
|
+
Do not automatically adjust skins or layouts, or migrate local fields to presets.
|
|
83
|
+
|
|
84
|
+
## Third priority: incremental processing and optional packing
|
|
85
|
+
|
|
86
|
+
Cache outputs by source image content fingerprint, normalized options and library
|
|
87
|
+
version. A cache hit skips decoding, packing and encoding. Input path order does
|
|
88
|
+
not affect output; the existing determinism checks cover this.
|
|
89
|
+
CLI can read the manifest and each relevant sheet once per build to create a
|
|
90
|
+
resource index, avoiding repeated I/O for multiple skins. Coordinate changes do
|
|
91
|
+
not affect KUI compilation; default nine-slice or style changes affect generated
|
|
92
|
+
code. Reducing compilation through resource/style-to-skin dependencies first
|
|
93
|
+
requires complete reference tracking and deletion-event tests.
|
|
94
|
+
|
|
95
|
+
For an opt-in CLI packing plugin, the recommended order is:
|
|
96
|
+
`configuration validation → packing → grouped validation/commit → KUI compilation → copyAssets`.
|
|
97
|
+
Configuration must explicitly specify source/output paths, stable resource names
|
|
98
|
+
and packing options. Do not infer existing resource keys from directory scans.
|
|
99
|
+
A generic CLI project should not automatically repack existing PNG/JSON files.
|
|
100
|
+
Other consumers can continue calling the same atlas API directly.
|
|
101
|
+
Tools own paths, file commits, queues/workers and progress. The library continues
|
|
102
|
+
to return only in-memory results.
|
|
103
|
+
|
|
104
|
+
## Atlas optimization opportunities
|
|
105
|
+
|
|
106
|
+
Experiments can compare PNG filter/deflate settings, alternative
|
|
107
|
+
lossless encoders and MaxRects sorting combinations, recording time, PNG bytes,
|
|
108
|
+
atlas area and peak memory. Choose strategies using several resource benchmarks.
|
|
109
|
+
Every strategy must pass RGBA, crop and extrusion checks again. Fewer PNG bytes
|
|
110
|
+
do not imply lower GPU memory use.
|
|
111
|
+
|
|
112
|
+
Rotation and
|
|
113
|
+
multipack would expand Core, manifest and tooling contracts, so they are outside
|
|
114
|
+
the current format-compatibility optimization scope. Lossy quantization,
|
|
115
|
+
discarding low-alpha pixels or reducing margin/extrusion cannot claim compliance
|
|
116
|
+
with the current pixel contract just because they reduce output size.
|
|
117
|
+
|
|
118
|
+
## Recommended acceptance order
|
|
119
|
+
|
|
120
|
+
1. Keep the `verify:reference` baseline and first complete grouped replacement and
|
|
121
|
+
full-page preview refresh in Reskin/Editor.
|
|
122
|
+
2. Verify CLI dev updates for PNG/JSON-only replacement, resource deletion,
|
|
123
|
+
interrupted external commits and Core-only projects.
|
|
124
|
+
3. Verify nine-slice logical dimensions, cropped icons, unchanged manifests,
|
|
125
|
+
unmodified KUI and preserved preset references.
|
|
126
|
+
4. Introduce input caching, incremental copying or opt-in CLI packing afterward;
|
|
127
|
+
measure each improvement and test rollback on failure.
|
|
128
|
+
|
|
129
|
+
Use [reference validation](reference-validation.md) to check format compatibility;
|
|
130
|
+
record completed results in CHANGELOG.md.
|