@kurot/atlas 0.1.0 → 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 CHANGED
@@ -1,8 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.1 — 2026-11-08
4
+
5
+ Prepared for publication.
6
+
7
+ - Reject repeated PNG image headers during preflight, before decoding either an individual image or a batch. Bound decompression for interlaced PNGs while retaining valid Adam7 input and the existing RGBA/atlas format.
8
+
3
9
  ## 0.1.0 — 2026-10-07
4
10
 
5
- Initial local implementation; not published.
11
+ Initial release, published to npm.
6
12
 
7
13
  - Add independent portable RGBA atlas packing with deterministic nonrotated
8
14
  MaxRects placement and single-sheet power-of-two size selection.
@@ -19,3 +25,126 @@ Initial local implementation; not published.
19
25
  No Core, CLI, Editor, Reskin or game project behavior changes. Filesystem writes,
20
26
  skin edits, manifest updates, rotation, deduplication and multipack are outside
21
27
  this release.
28
+
29
+ ## Reference and CLI validation — 2026-10-07
30
+
31
+ ## basis / basis_icon format and pixel validation
32
+
33
+ Validation date: 2026-10-07 (Asia/Shanghai). Implementation: local `@kurot/atlas 0.1.0`.
34
+ Reference project: `CrashMaster/kurot-project-kui`, using the source images and
35
+ TexturePacker outputs updated for this validation.
36
+
37
+ ### Results
38
+
39
+ All 61 resources across both sets passed checks for names, frame fields, crop
40
+ sizes, offsets, original dimensions and pixels. The new outputs work with the
41
+ existing resource format, without changing KUI, resource manifests or Core atlas
42
+ parsing. Placement coordinates differ, so PNG and JSON must be replaced together.
43
+ Format compatibility does not imply identical output bytes.
44
+
45
+ | Metric | basis | basis_icon |
46
+ | ----------------------------------------------- | ------------- | ------------- |
47
+ | Source images / frames | 29 / 29 | 32 / 32 |
48
+ | Trimmed images | 0 | 32 |
49
+ | TexturePacker atlas | 1024 × 1024 | 256 × 512 |
50
+ | atlas library output | 1024 × 1024 | 256 × 512 |
51
+ | Total frame rectangle area, excluding extrusion | 728,044 px | 97,021 px |
52
+ | Frames with different placement coordinates | 26 | 32 |
53
+ | TexturePacker PNG size | 875,190 bytes | 158,473 bytes |
54
+ | atlas library PNG size | 909,753 bytes | 159,652 bytes |
55
+
56
+ The new PNGs are approximately 3.95% and 0.74% larger, respectively. There is no
57
+ atlas-area or GPU texture memory improvement in these samples. Both placement
58
+ and encoding affect PNG byte size; the difference cannot be attributed solely
59
+ to compression. This validation did not include a stable performance benchmark
60
+ or browser interaction/screenshot acceptance tests.
61
+
62
+ ### Reference inputs and configuration
63
+
64
+ - Source images: `ui-tps/src/basis/*.png`, `ui-tps/src/basis_icon/*.png`.
65
+ - Reference outputs: `ui-tps/export/r_basis.{json,png,tps}`, `r_basis_icon.{json,png,tps}`.
66
+ - Project resources: `resource/assets/ui/app/r_basis.{json,png}`, `r_basis_icon.{json,png}`.
67
+ Runtime PNG/JSON files for both sets are byte-for-byte identical to the export files.
68
+ - TexturePacker 8.3 Egret export: single sheet, no rotation, POT, rectangular sheets
69
+ allowed, maximum 2048², scale 1, RGBA8888 PNG, alpha threshold 1, trim margin 1,
70
+ extrude 1, shape/border padding 0, and cleared RGB for fully transparent pixels.
71
+ Auto-alias is enabled, but neither set contains aliased frames.
72
+
73
+ Atlas used default packing options, with only the corresponding PNG filename
74
+ specified explicitly. The library did not read `.tps`; the validation scope is
75
+ these actual settings and the two resource sets.
76
+
77
+ ### Validation coverage
78
+
79
+ `scripts/verify-reference.ts` and `scripts/reference-checks.ts` check:
80
+
81
+ 1. Source image names exactly match the reference JSON frame set.
82
+ 2. JSON uses `file` + `frames`. Each frame has integer `x/y/w/h` and optional
83
+ `offX/offY/sourceW/sourceH`, with no rotation or nested format.
84
+ 3. Reference and new PNGs are 8-bit RGBA. Frames and their 1 px extrusion fit
85
+ within atlas bounds; extruded rectangles do not overlap.
86
+ 4. Independently computed bounds contain source alpha ≥ 1, expanded by a 1 px
87
+ margin and clamped to source bounds. Both reference and new crops match;
88
+ discarded regions contain no nonzero alpha.
89
+ 5. Each frame is restored to its source canvas using offX/offY. All retained
90
+ pixels match channel by channel: fully transparent pixels have RGB checked
91
+ against 0, and nonzero-alpha pixels have exactly matching RGBA.
92
+ 6. Every pixel in the 1 px edge and corner extrusion matches.
93
+ 7. Apart from x/y, old and new frames have identical field values and field presence.
94
+ 8. Reversing input order produces identical new PNG bytes and JSON objects.
95
+ 9. Reports retain source/reference SHA-256 hashes to identify the baseline after
96
+ future source-image updates.
97
+
98
+ For example, `r_icon_bars` is cropped to 56 × 43 with offX/offY of 6/11, while
99
+ its logical size remains 64 × 64. Base resources `r_bg_stepper` and `r_txt_input`
100
+ are 180 × 60 and 140 × 60, respectively.
101
+
102
+ The new library does not emit TexturePacker's top-level `meta`; Core's
103
+ SheetAnalyzer does not read it. `meta.smartupdate` is TexturePacker update
104
+ metadata and must not retain an old value as if it described a new output.
105
+
106
+ ### Actual CLI build validation
107
+
108
+ A temporary project copy used the sample's installed CLI 3.3.0 to build the
109
+ original atlases, then replaced only the two PNG/JSON pairs. Both development
110
+ `build --strict` runs and the replacement `build --release --strict` succeeded,
111
+ compiling 66 KUI skins each time. The real sample project was not modified.
112
+
113
+ - All 66 authored KUI files, `default.res.json` and `style.json` remained
114
+ byte-for-byte identical to the original project.
115
+ - Development `default.thm.js` outputs were identical after normalizing CLI's
116
+ random temporary directory name. Raw byte comparison differs because the
117
+ generated-source comments contain `kurot-skins-<random>`.
118
+ - All four new atlas resources in development and release outputs were
119
+ byte-for-byte identical to the packing results.
120
+ - Build validation confirms that the existing compilation/copy pipeline accepts
121
+ these outputs. Frame pixel checks and Core's source contract support crop/offset
122
+ compatibility; browser resource loading was not tested.
123
+
124
+ The installed CLI entry was invoked directly with
125
+ `node node_modules/@kurot/cli/dist/index.js ...`. In the temporary copy,
126
+ `pnpm exec` tried to verify dependencies and failed because the newly published
127
+ CLI/ui-document versions had not met minimumReleaseAge. The policy was not
128
+ relaxed, and dependencies were neither reinstalled nor replaced.
129
+
130
+ ### Repeating the validation
131
+
132
+ Run from the engine repository root. The second argument must be a directory
133
+ that does not yet exist and is outside the sample project:
134
+
135
+ ```sh
136
+ pnpm --dir packages/atlas verify:reference \
137
+ /path/to/CrashMaster/kurot-project-kui \
138
+ /tmp/kurot-atlas-reference-new
139
+ ```
140
+
141
+ The script reads the sample project without modifying it and writes two PNG/JSON
142
+ pairs plus `report.json` to the new directory. Failures exit with a nonzero code.
143
+ It is a local reference-validation tool with no fixed developer path; it is not
144
+ part of default CI tests, and its scripts are not published. Rerun it after
145
+ baseline files change. An old report does not verify new files.
146
+
147
+ Local outputs from this run are at `/private/tmp/kurot-atlas-reference-20261007`,
148
+ with `cli-report.json` recording temporary-project build comparisons. These
149
+ temporary files are not distributed with the package.
150
+ See [cli-integration.md](docs/cli-integration.md) for follow-up integration and optimization.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @kurot/atlas
2
2
 
3
- Version **0.1.0** — initial local implementation, not published.
3
+ Version **0.1.1**, prepared for publication.
4
4
 
5
5
  Independent, deterministic sprite-atlas tooling. Packs straight-alpha RGBA pixels
6
6
  and outputs the flat `file`/`frames` sheet format consumed by Kurot. No dependency
@@ -79,7 +79,7 @@ TexturePacker's exact placement or compressed PNG bytes.
79
79
 
80
80
  Margin, extrusion and padding are integers 0–1024. maxPixels is an integer
81
81
  1–67108864. Batches contain 1–4096 sources. PNG input has a 32 MiB per-file limit;
82
- dimensions are checked before decoding a batch. Static PNG input is normalized to
82
+ dimensions and a unique IHDR are checked before decoding a batch; interlaced image data is also checked against its pixel budget before the codec expands it. Static PNG input is normalized to
83
83
  RGBA8; APNG is rejected. The input buffers, decoder intermediates and output may
84
84
  coexist, so maxPixels is not a process-wide memory quota.
85
85
 
@@ -131,14 +131,9 @@ pnpm --dir packages/atlas test
131
131
  ```
132
132
 
133
133
  Unit tests use synthetic images and do not require the local game checkout.
134
- Initial local validation against the updated KUI sample on 2026-10-07 packed
135
- all 29 basis and 32 basis_icon sources to 1024×1024 and 256×512 respectively.
136
- All 61 frame field shapes and crop geometries match the existing export. Retained
137
- RGBA pixels and edge/corner extrusion match the sources, and reversed source
138
- order produces identical JSON and PNG bytes. CLI 3.3.0 development/release builds
139
- accept the new resources without authored skin, manifest or stylesheet changes.
140
- That validation does not promise identical layout to TexturePacker or replace
141
- future Editor/Reskin integration and rendered-game acceptance.
134
+ Reference verification checks frame geometry, retained pixels, extrusion and
135
+ input-order determinism against supplied read-only assets. Format compatibility
136
+ does not promise identical packing to TexturePacker or establish game acceptance.
142
137
 
143
138
  To repeat local reference verification, provide the sample project root and a new
144
139
  output directory outside that project:
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/png/index.ts"],"names":[],"mappings":"AAGA,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,CAa/E;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAWvD"}
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"}
package/dist/png/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Buffer } from 'node:buffer';
2
2
  import { PNG } from 'pngjs';
3
+ import { inflateSync } from 'node:zlib';
3
4
  import { AtlasError } from '../AtlasError.js';
4
5
  import { packAtlas } from '../pack-atlas.js';
5
6
  import { resolveOptions } from '../options.js';
@@ -32,10 +33,30 @@ export function decodePNG(bytes, maxPixels = 16_777_216) {
32
33
  if (!Number.isSafeInteger(maxPixels) || maxPixels < 1 || maxPixels > 67_108_864) {
33
34
  throw new AtlasError('invalid-options', 'Invalid maxPixels limit.');
34
35
  }
35
- if (readPixelCount(bytes) > maxPixels) {
36
+ const pixels = readPixelCount(bytes);
37
+ if (pixels > maxPixels) {
36
38
  throw new AtlasError('invalid-input', 'PNG pixels exceed maxPixels.');
37
39
  }
38
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
+ }
39
60
  const png = PNG.sync.read(Buffer.from(bytes), { checkCRC: true });
40
61
  return { width: png.width, height: png.height, pixels: new Uint8Array(png.data) };
41
62
  }
@@ -79,7 +100,11 @@ function readPixelCount(bytes) {
79
100
  if (length > buffer.length - offset - 12) {
80
101
  throw new AtlasError('invalid-png', 'Truncated PNG chunk.');
81
102
  }
82
- if (buffer.toString('ascii', offset + 4, offset + 8) === 'acTL') {
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') {
83
108
  throw new AtlasError('invalid-png', 'Animated PNG is not supported.');
84
109
  }
85
110
  offset += length + 12;
@@ -1 +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,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,CA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;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"}
@@ -1,7 +1,9 @@
1
1
  # @kurot/atlas — AI context map
2
2
 
3
- Version 0.1.0, initial local implementation, not published. Independent build-time
4
- atlas library; no Kurot package dependencies and no integration into consumers yet.
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.
5
7
  Read README.md for input limits and the pixel/output contract.
6
8
 
7
9
  ## Directory map
@@ -1,108 +1,130 @@
1
- # 图集与 CLI 的接入及优化建议
1
+ # Atlas integration with CLI and optimization recommendations
2
2
 
3
- 状态:2026-10-07 的源码分析与样例验证。本文是后续方案;本次没有改动 CLI、Core、
4
- Editor 或 Reskin,也没有添加消费者依赖。
3
+ This document describes the current atlas pipeline and optional tooling work.
5
4
 
6
- ## 当前链路
5
+ ## Current pipeline
7
6
 
8
7
  ```text
9
- 原图 → @kurot/atlas → PNG + 图集 JSON
10
- ↓ 调用方保存
11
- resource/default.res.json → CLI 读取资源默认值 → 编译 KUI
12
- resource/ 下的 PNG/JSON → CLI copyAssets → 构建输出
13
- 构建输出的图集 JSON/PNG → Core SheetAnalyzer → SpriteSheet / Texture
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
14
13
  ```
15
14
 
16
- CLI 没有在编译 KUI 时解析图集的帧坐标或 PNG。
17
- `src/core/kui/skin-module-builder.ts` 读取 `default.res.json`,通过 ui-document 的
18
- `parseUIResourceConfigEntries` 获得资源和九宫格默认值;`kui-parser.ts` 在副本上依次
19
- 应用资源默认值、Label presets 和颜色。`plugins/copy-assets.ts` 复制 resource,
20
- 排除 authored KUI 和生成的主题文件。
21
-
22
- Core 的 `packages/core/src/kurot/resource/analyzers/SheetAnalyzer.ts` 在运行时读取
23
- `file/frames`,将裁剪坐标、偏移和原始尺寸交给 `SpriteSheet.createTexture`。
24
- 因此本次格式兼容已经足够,无需为了接入库改造 CLI 的 KUI parser 或 Core。
25
-
26
- atlas 保持独立;Reskin/Editor 的资源服务可以调用库。以后若 CLI 提供打包功能,
27
- CLI 可依赖 atlas,但 atlas 不依赖 CLI/Core。单纯复制、消费已打包图集无需新增依赖。
28
-
29
- ## 第一优先级:资源更新能够到达预览
30
-
31
- CLI `src/core/dev-server.ts` 的 `watchResources` 目前仅响应 `.kui.xml`、
32
- `default.res.json` 和 `config/style.json`,并且要求项目配置 `ui`。
33
- PNG 与普通图集 JSON 的修改不会触发此监听器。完整 build 能复制新产物,
34
- 但运行中的 dev 服务可能继续提供旧资源。这是源码确认的缺口,尚未做运行中 watcher 验收。
35
-
36
- 建议增加资源变化分支:
37
-
38
- | 变化 | 建议动作 |
39
- | --- | --- |
40
- | 图集 PNG / 帧 JSON,资源名称和九宫格不变 | 校验成对产物、复制资源、通知预览重新加载 |
41
- | default.res.json 中资源默认九宫格变化 | 校验清单、重新编译受影响 KUI、复制资源 |
42
- | style.json 中颜色 / 字体 / Label presets 变化 | 继续使用既有样式副本解析链和 KUI 重编译 |
43
- | KUI 变化 | 保持既有编译流程;Reskin 不提供这个编辑入口 |
44
-
45
- 第一版可复用现有 copyAssets,先保证正确性;后续再只复制变化文件。
46
- 资源监听不应绑定 ui 存在,Core-only 项目也需要复制变化的资源。
47
- 无需通过修改或 touch KUI/default.res.json 伪造更新事件。
48
-
49
- PNG 和 JSON 各自 rename 并不构成双文件原子事务。调用方应先生成并验证临时产物,
50
- 再提交一整组;同进程用提交完成事件串行触发复制。外部文件监听可采用去抖与有界重试,
51
- 但它们不能严格保证同尺寸 PNG/JSON 是同一代。需要跨进程严格一致时,考虑版本目录
52
- 加一次性指针切换,或显式 commit 标记/代次协议;该方案应独立评审。
53
- 只有成组验证和复制完成后才发布成功事件。预览刷新还要处理 Core 资源缓存和浏览器缓存;
54
- 第一阶段整页重载比只清除一个子纹理可靠,不应向产物 JSON 塞入未定义缓存字段。
55
-
56
- ## 第二优先级:构建前资源完整性校验
57
-
58
- 增加独立校验步骤,位于编译/复制前,不改变 authored KUI:
59
-
60
- - 清单中的 sheet URL 指向存在的 JSON;JSON 的 file 指向合法、存在的相对 PNG。
61
- - PNG 尺寸、frame 整数与边界、裁剪偏移及逻辑尺寸一致,拒绝不支持的旋转格式。
62
- - `subkeys` 继续使用对象格式;对照实际 frame 集合报告缺失/多余条目,
63
- 严格模式下对引用不到的帧失败,错误包含 sheet 名、资源路径和 frame 名。
64
- - 资源默认 `scale9grid` 按未裁剪的 sourceW/sourceH 校验,不能按图集 x/y 或裁剪 w/h 重算。
65
- - 沿用现有名称/别名优先级,区分重复裸帧名和可使用的 `sheet.frame` 引用。
66
-
67
- 相关契约见 `packages/ui-document/docs/resource-nine-slice.md`。
68
- 现有清单解析器不读取 PNG/帧文件,因此不能把它通过解析视为完整的图集校验。
69
- 新增纯格式检查可放在独立工具模块;不要仅为读取已有图集强迫 Core 或 ui-document 依赖 atlas。
70
- 若将来共享读取校验器,可提供不含 PNG 编码器的独立入口,再评估 CLI 是否需要依赖。
71
-
72
- Reskin 默认保持资源键集合,按已有键替换素材。重打包不需要重新生成整份清单。
73
- 保留 frame 的既有九宫格和未知元数据、groups、URL 与资源顺序;出现键集合变化时先报告,
74
- 不能静默删除或重写已有引用。不得自动调整皮肤、布局或把局部字段迁移成 presets。
75
-
76
- ## 第三优先级:增量处理和可选打包入口
77
-
78
- 先按源图内容指纹、规范化 options、库版本缓存产物,命中后跳过解码/打包/编码。
79
- 不同原图路径顺序不影响输出,已有确定性校验覆盖这一点。
80
- CLI 可以在一次构建中只读取一次清单和每个相关 sheet,建立资源索引,避免多皮肤重复 I/O。
81
- 坐标变化不影响 KUI 编译;默认九宫格或样式变化才影响生成代码。
82
- 按资源/样式到皮肤的依赖关系减少编译,需要先完善引用追踪和删除事件测试。
83
-
84
- 若 CLI 增加 opt-in pack 插件,顺序建议为:
85
- `配置校验 → 打包 → 成组校验/提交 → KUI 编译 → copyAssets`。
86
- 输入配置需要显式 source/output、稳定资源名、打包选项,禁止依靠扫描结果猜测既有资源键。
87
- 通用 CLI 项目不因已有 PNG/JSON 就自动重打包;其余消费者仍直接调用同一 atlas API。
88
- 工具拥有路径、文件提交、队列/worker 与进度;库继续只返回内存结果。
89
-
90
- ## 图集本身的优化空间
91
-
92
- 两组新图集与 TexturePacker 面积相同,优先优化更新链路与诊断。
93
- 可以试验 PNG filter/deflate 设置、替代无损编码器与不同 MaxRects 排序组合,
94
- 同时记录耗时、PNG 字节、图集面积和内存峰值。以多组资源基准选择策略,
95
- 每种策略必须重新通过 RGBA 与裁剪/扩边校验;减少 PNG 字节不等于减少 GPU 内存。
96
-
97
- 重复像素别名在当前两组里无收益;旋转和 multipack 会扩大 Core/清单/工具契约,
98
- 不作为当前格式一致目标的优化。不可用有损量化、丢弃低 alpha 或减少 margin/extrusion
99
- 换取大小优势并继续声称与当前像素契约一致。
100
-
101
- ## 建议验收顺序
102
-
103
- 1. 保留 `verify:reference` 基线,先完成 Reskin/Editor 的成组替换与整页预览刷新。
104
- 2. CLI 验收 dev 下仅替换 PNG/JSON、删除资源、外部提交中途失败和 Core-only 项目资源更新。
105
- 3. 验收九宫格逻辑尺寸、裁剪图标、manifest 不变、KUI 未修改、现有 preset 引用不变。
106
- 4. 再引入输入缓存、增量复制或 opt-in CLI 打包,分别测量改善和测试失败回滚。
107
-
108
- 本次兼容性证据见 [reference-validation.md](./reference-validation.md)。
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.
@@ -1,85 +1,53 @@
1
- # basis / basis_icon 格式与像素验证
2
-
3
- 验证日期:2026-10-07(Asia/Shanghai)。实现:本地 `@kurot/atlas 0.1.0`。
4
- 参考项目:`CrashMaster/kurot-project-kui`,采用本次更新后的原图与 TexturePacker 产物。
5
-
6
- ## 结论
7
-
8
- 两组共 61 个资源的名称、帧字段、裁剪尺寸、偏移、原始尺寸和像素均通过验证。
9
- 新产物可以采用现有资源格式;不需要修改 KUI、资源清单或 Core 的图集解析。
10
- 排布坐标有所不同,PNG 和 JSON 必须成对替换。格式兼容不代表产物字节相同。
11
-
12
- | 项目 | basis | basis_icon |
13
- | --- | --- | --- |
14
- | 原图 / 帧数 | 29 / 29 | 32 / 32 |
15
- | 发生裁剪 | 0 | 32 |
16
- | TexturePacker 图集 | 1024 × 1024 | 256 × 512 |
17
- | atlas 图集 | 1024 × 1024 | 256 × 512 |
18
- | 有效帧矩形总面积,不含扩边 | 728,044 px | 97,021 px |
19
- | 排布坐标不同的帧 | 26 | 32 |
20
- | TexturePacker PNG 大小 | 875,190 bytes | 158,473 bytes |
21
- | atlas PNG 大小 | 909,753 bytes | 159,652 bytes |
22
-
23
- 新 PNG 分别大约多 3.95% 和 0.74%。当前没有图集面积或 GPU 纹理内存收益。
24
- PNG 字节大小由排布与编码共同影响,不能把差异全部归因于压缩器。
25
- 本次没有进行稳定的性能基准,也没有启动浏览器做交互或截图验收。
26
-
27
- ## 参考材料与配置
28
-
29
- - 原图:`ui-tps/src/basis/*.png`、`ui-tps/src/basis_icon/*.png`。
30
- - 参考:`ui-tps/export/r_basis.{json,png,tps}`、`r_basis_icon.{json,png,tps}`。
31
- - 项目使用的资源:`resource/assets/ui/app/r_basis.{json,png}`、`r_basis_icon.{json,png}`。
32
- 两组运行时 PNG、JSON 与 export 文件均逐字节相同。
33
- - TexturePacker 8.3 的 Egret 导出:单图集、无旋转、POT、允许矩形、最大 2048²、
34
- 缩放 1、RGBA8888 PNG、alpha threshold 1、trim margin 1、extrude 1、
35
- shape/border padding 0、清除完全透明像素的 RGB。开启 auto-alias,但这两组没有别名帧。
36
-
37
- 本次 atlas 使用默认打包选项,只显式指定对应 PNG 文件名。
38
- 库没有读取 `.tps`,验证范围是上述实际配置与两组资源。
39
-
40
- ## 校验覆盖
41
-
42
- `scripts/verify-reference.ts` 和 `scripts/reference-checks.ts` 执行:
43
-
44
- 1. 原图名称与参考 JSON 的帧集合完全相同。
45
- 2. JSON 使用 `file` + `frames`;每帧是整数 `x/y/w/h` 与可选
46
- `offX/offY/sourceW/sourceH`,没有旋转或嵌套格式。
47
- 3. 参考 PNG 与新 PNG 均为 8-bit RGBA;帧与 1 px 扩边在图集边界内,扩边矩形不重叠。
48
- 4. 独立计算原图 alpha ≥ 1 的包围盒,加 1 px margin 后夹到原图边界;
49
- 对参考、新产物分别验证裁剪。裁掉的区域没有非零 alpha。
50
- 5. 按 offX/offY 将每帧放回原始画布,逐通道核对所有保留像素;
51
- 完全透明像素的 RGB 按 0 核对,非零 alpha 像素的 RGBA 必须精确相同。
52
- 6. 逐像素核对四边和四角的 1 px extrusion。
53
- 7. 新旧帧除了 x/y,其他字段的值和字段是否存在都完全相同。
54
- 8. 反转输入顺序后,新 PNG 字节和 JSON 对象保持一致。
55
- 9. 报告保留源图和参考产物的 SHA-256,供后续原图更新时识别验证基线。
56
-
57
- 例如 `r_icon_bars` 裁剪为 56 × 43,offX/offY 为 6/11,逻辑尺寸仍是 64 × 64。
58
- 基础资源 `r_bg_stepper` 为 180 × 60,`r_txt_input` 为 140 × 60。
59
-
60
- TexturePacker 的顶层 `meta` 不由新库生成;Core 的 SheetAnalyzer 不读取它。
61
- `meta.smartupdate` 属于 TexturePacker 更新信息,不能保留旧值冒充新产物。
62
-
63
- ## CLI 实际构建验证
64
-
65
- 在项目临时副本中使用样例已安装的 CLI 3.3.0,先构建原始图集,再仅替换两组 PNG/JSON。
66
- 两次 development `build --strict` 和替换后的 `build --release --strict` 均成功,
67
- 每次编译 66 个 KUI skin。没有修改真实示例项目。
68
-
69
- - 66 个 authored KUI、`default.res.json` 和 `style.json` 与原项目逐字节相同。
70
- - development 编译的 `default.thm.js` 在归一化 CLI 随机临时目录名后完全相同;
71
- 原始字节比较会因 `kurot-skins-<random>` 的生成来源注释不同而失败。
72
- - development 和 release 中的四个新图集资源均与打包结果逐字节相同。
73
- - 构建验证证明现有编译和复制链可接收这些产物;逐帧像素校验与 Core 源码契约
74
- 支持裁剪/偏移兼容判断,未执行浏览器资源加载测试。
75
-
76
- 使用已安装的 CLI 入口直接调用 `node node_modules/@kurot/cli/dist/index.js ...`。
77
- 临时副本中的 `pnpm exec` 尝试检查依赖,并因新发布的 CLI/ui-document 未满足
78
- minimumReleaseAge 而失败;没有放宽策略、重新安装或更换依赖。
79
-
80
- ## 重复验证
81
-
82
- 从引擎仓库根目录运行,第二个参数必须是尚不存在、且位于示例项目外的目录:
1
+ # Atlas reference validation
2
+
3
+ Use the local read-only reference validator to check frame geometry and pixels
4
+ against supplied basis/basis_icon source and atlas files. Reference data is not
5
+ part of the npm package.
6
+
7
+ ## Reference inputs and configuration
8
+
9
+ - Source images: `ui-tps/src/basis/*.png`, `ui-tps/src/basis_icon/*.png`.
10
+ - Reference outputs: `ui-tps/export/r_basis.{json,png,tps}`, `r_basis_icon.{json,png,tps}`.
11
+ - Project resources: `resource/assets/ui/app/r_basis.{json,png}`, `r_basis_icon.{json,png}`.
12
+ Compare the selected baseline explicitly rather than assuming it matches runtime copies.
13
+ - TexturePacker 8.3 Egret export: single sheet, no rotation, POT, rectangular sheets
14
+ allowed, maximum 2048², scale 1, RGBA8888 PNG, alpha threshold 1, trim margin 1,
15
+ extrude 1, shape/border padding 0, and cleared RGB for fully transparent pixels.
16
+ Auto-alias is enabled; alias behavior requires a separate fixture when relevant.
17
+
18
+ Use default packing options, with only the corresponding PNG filename
19
+ specified explicitly. The library does not read `.tps`; scope compatibility to the selected settings
20
+ and source sets.
21
+
22
+ ## Validation coverage
23
+
24
+ `scripts/verify-reference.ts` and `scripts/reference-checks.ts` check:
25
+
26
+ 1. Source image names exactly match the reference JSON frame set.
27
+ 2. JSON uses `file` + `frames`. Each frame has integer `x/y/w/h` and optional
28
+ `offX/offY/sourceW/sourceH`, with no rotation or nested format.
29
+ 3. Reference and new PNGs are 8-bit RGBA. Frames and their 1 px extrusion fit
30
+ within atlas bounds; extruded rectangles do not overlap.
31
+ 4. Independently computed bounds contain source alpha ≥ 1, expanded by a 1 px
32
+ margin and clamped to source bounds. Both reference and new crops match;
33
+ discarded regions contain no nonzero alpha.
34
+ 5. Each frame is restored to its source canvas using offX/offY. All retained
35
+ pixels match channel by channel: fully transparent pixels have RGB checked
36
+ against 0, and nonzero-alpha pixels have exactly matching RGBA.
37
+ 6. Every pixel in the 1 px edge and corner extrusion matches.
38
+ 7. Apart from x/y, old and new frames have identical field values and field presence.
39
+ 8. Reversing input order produces identical new PNG bytes and JSON objects.
40
+ 9. Reports retain source/reference SHA-256 hashes to identify the baseline after
41
+ future source-image updates.
42
+
43
+ The library does not emit TexturePacker's top-level `meta`; Core's
44
+ SheetAnalyzer does not read it. `meta.smartupdate` is TexturePacker update
45
+ metadata and must not retain an old value as if it described a new output.
46
+
47
+ ## Repeating the validation
48
+
49
+ Run from the engine repository root. The second argument must be a directory
50
+ that does not yet exist and is outside the sample project:
83
51
 
84
52
  ```sh
85
53
  pnpm --dir packages/atlas verify:reference \
@@ -87,10 +55,8 @@ pnpm --dir packages/atlas verify:reference \
87
55
  /tmp/kurot-atlas-reference-new
88
56
  ```
89
57
 
90
- 脚本只读示例项目,在新目录输出两组 PNG/JSON 和 `report.json`;失败会以非零码退出。
91
- 它是本地参考验证工具,不依赖固定的开发者路径,不纳入默认 CI 测试,也不发布脚本。
92
- 基线文件更新后需要重新执行,旧报告不能证明新文件通过验证。
93
-
94
- 本次本地产物位于 `/private/tmp/kurot-atlas-reference-20261007`,另有
95
- `cli-report.json` 记录临时项目的构建核对结果。这些临时文件不随包分发。
96
- 后续接入与优化见 [cli-integration.md](./cli-integration.md)。
58
+ The script reads the sample project without modifying it and writes two PNG/JSON
59
+ pairs plus `report.json` to the new directory. Failures exit with a nonzero code.
60
+ It is a local reference-validation tool with no fixed developer path; it is not
61
+ part of default CI tests, and its scripts are not published. Rerun it after
62
+ baseline files change. An old report does not verify new files.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kurot/atlas",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Independent RGBA atlas packing and PNG tooling with Kurot-compatible sheet output",
5
5
  "author": "Kelvin <kyia.x52@gmail.com>",
6
6
  "license": "MIT",