@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/CHANGELOG.md
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Changelog
|
|
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
|
+
|
|
9
|
+
## 0.1.0 — 2026-10-07
|
|
10
|
+
|
|
11
|
+
Initial release, published to npm.
|
|
12
|
+
|
|
13
|
+
- Add independent portable RGBA atlas packing with deterministic nonrotated
|
|
14
|
+
MaxRects placement and single-sheet power-of-two size selection.
|
|
15
|
+
- Add alpha cropping, retained trim margins, straight-alpha composition,
|
|
16
|
+
transparent RGB clearing and edge/corner extrusion.
|
|
17
|
+
- Emit flat Kurot-compatible file/frames JSON with trim offsets and logical size.
|
|
18
|
+
- Add a separate Node PNG entry point using pngjs; bound decoded pixel counts,
|
|
19
|
+
validate PNG input and reject APNG.
|
|
20
|
+
- Add synthetic pixel, packing, deterministic-output and PNG regression tests.
|
|
21
|
+
- Add repeatable read-only local basis/basis_icon validation for frame schemas,
|
|
22
|
+
RGBA pixels, cropping, extrusion, overlap and deterministic output; record
|
|
23
|
+
existing CLI development/release compatibility and future integration proposals.
|
|
24
|
+
|
|
25
|
+
No Core, CLI, Editor, Reskin or game project behavior changes. Filesystem writes,
|
|
26
|
+
skin edits, manifest updates, rotation, deduplication and multipack are outside
|
|
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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kelvin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,147 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @kurot/atlas
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Version **0.1.1**, prepared for publication.
|
|
4
|
+
|
|
5
|
+
Independent, deterministic sprite-atlas tooling. Packs straight-alpha RGBA pixels
|
|
6
|
+
and outputs the flat `file`/`frames` sheet format consumed by Kurot. No dependency
|
|
7
|
+
on Core, UI, ui-document, ui-runtime or CLI; none of those packages depend on atlas.
|
|
8
|
+
It can be called by Reskin, Editor, a separate atlas tool or build automation.
|
|
9
|
+
|
|
10
|
+
## Entry points
|
|
11
|
+
|
|
12
|
+
- `@kurot/atlas`: pixel-only packing, portable ES2022, no Node or PNG imports.
|
|
13
|
+
- `@kurot/atlas/png`: synchronous Node.js >=20 PNG decoding/encoding through
|
|
14
|
+
[pngjs](https://github.com/pngjs/pngjs), without native binaries.
|
|
15
|
+
|
|
16
|
+
The package performs no filesystem I/O. Callers own reading, source-image storage,
|
|
17
|
+
project-path validation, resource manifests, worker scheduling and atomic saves.
|
|
18
|
+
The PNG functions are synchronous; run larger batches in your tool's worker.
|
|
19
|
+
|
|
20
|
+
## PNG example
|
|
21
|
+
|
|
22
|
+
After installing/linking the package into a tool:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
26
|
+
import { packPNGAtlas } from '@kurot/atlas/png';
|
|
27
|
+
|
|
28
|
+
const result = packPNGAtlas([
|
|
29
|
+
{ name: 'r_btn_bet', png: await readFile('src/basis/r_btn_bet.png') },
|
|
30
|
+
{ name: 'r_prg_thumb', png: await readFile('src/basis/r_prg_thumb.png') },
|
|
31
|
+
], { file: 'r_basis.png' });
|
|
32
|
+
|
|
33
|
+
// Demonstration only: a project editor must stage and commit the pair together.
|
|
34
|
+
await writeFile('export/r_basis.png', result.png);
|
|
35
|
+
await writeFile('export/r_basis.json', JSON.stringify(result.data, undefined, 2) + '\n');
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Frame names are supplied explicitly and remain stable; the library does not
|
|
39
|
+
derive names from filesystem paths. Names start with an ASCII letter or digit,
|
|
40
|
+
followed by letters, digits, underscores, hyphens or dots. Duplicates are errors.
|
|
41
|
+
The `file` option is a PNG basename, resolved relative to the JSON by the consumer.
|
|
42
|
+
|
|
43
|
+
## Pixel example
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { packAtlas } from '@kurot/atlas';
|
|
47
|
+
|
|
48
|
+
const result = packAtlas([
|
|
49
|
+
{ name: 'red', width: 1, height: 1, pixels: new Uint8Array([255, 0, 0, 255]) },
|
|
50
|
+
]);
|
|
51
|
+
// result.image contains width, height and RGBA pixels; result.data contains the sheet JSON.
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Pixel input is row-major, four bytes per pixel, straight alpha, 8-bit channels.
|
|
55
|
+
Uint8Array and Uint8ClampedArray are accepted. Source arrays and buffers are not
|
|
56
|
+
modified. RGB in fully transparent output pixels is cleared; semitransparent
|
|
57
|
+
colors and alpha are retained without premultiplication or gamma correction.
|
|
58
|
+
|
|
59
|
+
## Packing contract
|
|
60
|
+
|
|
61
|
+
One sheet, no rotation, power-of-two dimensions, not necessarily square.
|
|
62
|
+
MaxRects placement uses a stable area/name sort and three heuristics. Candidate
|
|
63
|
+
sizes are tried by ascending area, then closeness to square, then width.
|
|
64
|
+
This is heuristic packing, not proof of an optimal layout; an overflow means
|
|
65
|
+
these searches did not fit within the requested limits. It does not reproduce
|
|
66
|
+
TexturePacker's exact placement or compressed PNG bytes.
|
|
67
|
+
|
|
68
|
+
| Option | Default | Contract |
|
|
69
|
+
| --- | --- | --- |
|
|
70
|
+
| `file` | `atlas.png` | PNG basename |
|
|
71
|
+
| `maxWidth`, `maxHeight` | 2048 | Integer 1–16384; output POT axes stay within bounds |
|
|
72
|
+
| `trim` | true | Crop transparent borders |
|
|
73
|
+
| `alphaThreshold` | 1 | Content alpha threshold, integer 1–255 |
|
|
74
|
+
| `trimMargin` | 1 | Retained source-pixel margin, clamped to original bounds |
|
|
75
|
+
| `extrude` | 1 | Copies nearest edge pixels, including corners, outside the frame |
|
|
76
|
+
| `shapePadding` | 0 | Empty right/bottom gap after each extruded rectangle |
|
|
77
|
+
| `borderPadding` | 0 | Empty outer sheet margin |
|
|
78
|
+
| `maxPixels` | 16777216 | Limits total decoded source area and output area |
|
|
79
|
+
|
|
80
|
+
Margin, extrusion and padding are integers 0–1024. maxPixels is an integer
|
|
81
|
+
1–67108864. Batches contain 1–4096 sources. PNG input has a 32 MiB per-file limit;
|
|
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
|
+
RGBA8; APNG is rejected. The input buffers, decoder intermediates and output may
|
|
84
|
+
coexist, so maxPixels is not a process-wide memory quota.
|
|
85
|
+
|
|
86
|
+
Trimming tests alpha >= alphaThreshold, retains trimMargin around that bounding
|
|
87
|
+
box, then stores source offsets and original dimensions. Pixels below the
|
|
88
|
+
threshold inside the retained rectangle are preserved. An empty cropped source
|
|
89
|
+
becomes a clear 1×1 frame at source offset 0, retaining original logical dimensions.
|
|
90
|
+
Set trim=false when retaining the original canvas is required.
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"file": "r_basis_icon.png",
|
|
95
|
+
"frames": {
|
|
96
|
+
"r_icon_bars": {
|
|
97
|
+
"x": 1, "y": 1, "w": 56, "h": 43,
|
|
98
|
+
"offX": 6, "offY": 11, "sourceW": 64, "sourceH": 64
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Reported rectangles exclude extrusion and padding. Uncropped frames omit offset
|
|
105
|
+
and original-size fields. Sheet metadata does not include TexturePacker ownership,
|
|
106
|
+
smartupdate, pivots, rotation or multipack links.
|
|
107
|
+
|
|
108
|
+
## Errors and integration boundary
|
|
109
|
+
|
|
110
|
+
`AtlasError.code` is `invalid-input`, `invalid-options`, `invalid-png` or
|
|
111
|
+
`atlas-overflow`. Decode failures retain their cause. Overflow never produces a
|
|
112
|
+
partial result or automatically enables rotation/multipack.
|
|
113
|
+
|
|
114
|
+
Resource keys and logical sprite sizes, rather than packed coordinates, connect
|
|
115
|
+
the output to skins. Keep source files as project-owned authoring assets. Preserve
|
|
116
|
+
manifest object-form `subkeys`, groups and resource-default nine-slice metadata
|
|
117
|
+
when replacing a sheet; validate grids against original dimensions. The library
|
|
118
|
+
does not edit these records, KUI XML, style.json or game code. A caller must commit
|
|
119
|
+
PNG/JSON and any changed resource metadata consistently and refresh its caches.
|
|
120
|
+
|
|
121
|
+
Not included: source-folder scanning, `.tps` parsing, GUI, filesystem transactions,
|
|
122
|
+
sprite deduplication, multiple pages, rotation, JPEG/WebP output, polygon meshes,
|
|
123
|
+
automatic scaling or CLI integration.
|
|
124
|
+
|
|
125
|
+
## Development and validation
|
|
126
|
+
|
|
127
|
+
```sh
|
|
128
|
+
pnpm --dir packages/atlas install
|
|
129
|
+
pnpm --dir packages/atlas build
|
|
130
|
+
pnpm --dir packages/atlas test
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Unit tests use synthetic images and do not require the local game checkout.
|
|
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.
|
|
137
|
+
|
|
138
|
+
To repeat local reference verification, provide the sample project root and a new
|
|
139
|
+
output directory outside that project:
|
|
140
|
+
|
|
141
|
+
```sh
|
|
142
|
+
pnpm --dir packages/atlas verify:reference /path/to/kurot-project-kui /tmp/atlas-new
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
See [reference results and checks](docs/reference-validation.md),
|
|
146
|
+
[CLI integration and optimization proposals](docs/cli-integration.md), and
|
|
147
|
+
[architecture and API context](docs/ai-context.md).
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type AtlasErrorCode = 'invalid-input' | 'invalid-options' | 'atlas-overflow' | 'invalid-png';
|
|
2
|
+
/**
|
|
3
|
+
* Stable failure category for tooling; no input files or output files are changed.
|
|
4
|
+
*/
|
|
5
|
+
export declare class AtlasError extends Error {
|
|
6
|
+
readonly code: AtlasErrorCode;
|
|
7
|
+
constructor(code: AtlasErrorCode, message: string, options?: ErrorOptions);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=AtlasError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AtlasError.d.ts","sourceRoot":"","sources":["../src/AtlasError.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG,iBAAiB,GAAG,gBAAgB,GAAG,aAAa,CAAC;AAEpG;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACpC,SAAgB,IAAI,EAAE,cAAc,CAAC;gBAElB,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAKhF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable failure category for tooling; no input files or output files are changed.
|
|
3
|
+
*/
|
|
4
|
+
export class AtlasError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
constructor(code, message, options) {
|
|
7
|
+
super(message, options);
|
|
8
|
+
this.name = 'AtlasError';
|
|
9
|
+
this.code = code;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=AtlasError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AtlasError.js","sourceRoot":"","sources":["../src/AtlasError.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACpB,IAAI,CAAiB;IAErC,YAAmB,IAAoB,EAAE,OAAe,EAAE,OAAsB;QAC/E,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Straight-alpha, 8-bit RGBA pixels in row-major order. Input buffers are never mutated.
|
|
3
|
+
*/
|
|
4
|
+
export interface AtlasImage {
|
|
5
|
+
readonly width: number;
|
|
6
|
+
readonly height: number;
|
|
7
|
+
readonly pixels: Uint8Array | Uint8ClampedArray;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Name is the stable resource key; callers remove extensions or assign names explicitly.
|
|
11
|
+
*/
|
|
12
|
+
export interface AtlasSource extends AtlasImage {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
}
|
|
15
|
+
export interface AtlasOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Output PNG basename, default atlas.png. No directories or URLs.
|
|
18
|
+
*/
|
|
19
|
+
readonly file?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Upper dimension bounds, default 2048 each. Output axes are powers of two.
|
|
22
|
+
*/
|
|
23
|
+
readonly maxWidth?: number;
|
|
24
|
+
readonly maxHeight?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Crop transparent borders, default true.
|
|
27
|
+
*/
|
|
28
|
+
readonly trim?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Alpha values at or above this byte value define content, default 1, range 1–255.
|
|
31
|
+
*/
|
|
32
|
+
readonly alphaThreshold?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Source pixels retained around the content bounding box, default 1.
|
|
35
|
+
*/
|
|
36
|
+
readonly trimMargin?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Repeated edge pixels outside each reported frame, default 1, including corners.
|
|
39
|
+
*/
|
|
40
|
+
readonly extrude?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Additional empty pixels after the extruded rectangle on its right and bottom, default 0.
|
|
43
|
+
*/
|
|
44
|
+
readonly shapePadding?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Empty margin around the packed content, default 0.
|
|
47
|
+
*/
|
|
48
|
+
readonly borderPadding?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Limit for total source pixels and output pixels, default 16,777,216.
|
|
51
|
+
*/
|
|
52
|
+
readonly maxPixels?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Frame coordinates exclude extrusion. Offsets place cropped pixels in the original canvas.
|
|
56
|
+
* Uncropped frames omit offX/offY/sourceW/sourceH. No rotated frames are emitted.
|
|
57
|
+
*/
|
|
58
|
+
export interface AtlasFrame {
|
|
59
|
+
x: number;
|
|
60
|
+
y: number;
|
|
61
|
+
w: number;
|
|
62
|
+
h: number;
|
|
63
|
+
offX?: number;
|
|
64
|
+
offY?: number;
|
|
65
|
+
sourceW?: number;
|
|
66
|
+
sourceH?: number;
|
|
67
|
+
}
|
|
68
|
+
export interface AtlasData {
|
|
69
|
+
file: string;
|
|
70
|
+
frames: Record<string, AtlasFrame>;
|
|
71
|
+
}
|
|
72
|
+
export interface AtlasResult {
|
|
73
|
+
image: AtlasImage;
|
|
74
|
+
data: AtlasData;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=AtlasTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AtlasTypes.d.ts","sourceRoot":"","sources":["../src/AtlasTypes.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,iBAAiB,CAAC;CAChD;AAED;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,U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
|
1
|
+
{"version":3,"file":"AtlasTypes.js","sourceRoot":"","sources":["../src/AtlasTypes.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { AtlasError } from './AtlasError.js';
|
|
2
|
+
export type { AtlasErrorCode } from './AtlasError.js';
|
|
3
|
+
export type { AtlasData, AtlasFrame, AtlasImage, AtlasOptions, AtlasResult, AtlasSource } from './AtlasTypes.js';
|
|
4
|
+
export { packAtlas } from './pack-atlas.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACjH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/layout.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Placement } from './max-rects.js';
|
|
2
|
+
import type { PackingOptions } from './options.js';
|
|
3
|
+
import type { PreparedSource } from './trim.js';
|
|
4
|
+
export interface AtlasLayout {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
placements: Placement[];
|
|
8
|
+
}
|
|
9
|
+
export declare function createLayout(sources: readonly PreparedSource[], options: PackingOptions): AtlasLayout;
|
|
10
|
+
//# sourceMappingURL=layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,SAAS,EAAE,CAAC;CACxB;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,EAAE,OAAO,EAAE,cAAc,GAAG,WAAW,CA+BrG"}
|
package/dist/layout.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { AtlasError } from './AtlasError.js';
|
|
2
|
+
import { placeRectangles } from './max-rects.js';
|
|
3
|
+
export function createLayout(sources, options) {
|
|
4
|
+
const items = sources.map(item => ({
|
|
5
|
+
name: item.source.name,
|
|
6
|
+
width: item.width + options.extrude * 2 + options.shapePadding,
|
|
7
|
+
height: item.height + options.extrude * 2 + options.shapePadding,
|
|
8
|
+
})).sort((a, b) => b.width * b.height - a.width * a.height || Math.max(b.width, b.height) - Math.max(a.width, a.height) ||
|
|
9
|
+
(a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
10
|
+
const margin = options.borderPadding * 2;
|
|
11
|
+
const minWidth = Math.max(...items.map(item => item.width)) + margin;
|
|
12
|
+
const minHeight = Math.max(...items.map(item => item.height)) + margin;
|
|
13
|
+
const area = items.reduce((sum, item) => sum + item.width * item.height, 0);
|
|
14
|
+
const candidates = powersOfTwo(minWidth, options.maxWidth).flatMap(width => powersOfTwo(minHeight, options.maxHeight).map(height => ({ width, height }))).filter(size => (size.width - margin) * (size.height - margin) >= area &&
|
|
15
|
+
size.width * size.height <= options.maxPixels).sort((a, b) => a.width * a.height - b.width * b.height ||
|
|
16
|
+
Math.abs(a.width - a.height) - Math.abs(b.width - b.height) || a.width - b.width);
|
|
17
|
+
const heuristics = ['short-side', 'area', 'long-side'];
|
|
18
|
+
for (const size of candidates) {
|
|
19
|
+
for (const heuristic of heuristics) {
|
|
20
|
+
const placements = placeRectangles(items, size.width - margin, size.height - margin, heuristic);
|
|
21
|
+
if (!placements)
|
|
22
|
+
continue;
|
|
23
|
+
return { ...size, placements: placements.map(rect => ({
|
|
24
|
+
...rect, x: rect.x + options.borderPadding, y: rect.y + options.borderPadding,
|
|
25
|
+
})) };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
throw new AtlasError('atlas-overflow', `Images do not fit a single power-of-two atlas within ${options.maxWidth}×${options.maxHeight} and maxPixels.`);
|
|
29
|
+
}
|
|
30
|
+
function powersOfTwo(min, max) {
|
|
31
|
+
const values = [];
|
|
32
|
+
for (let value = 1; value <= max; value *= 2) {
|
|
33
|
+
if (value >= min) {
|
|
34
|
+
values.push(value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return values;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAWjD,MAAM,UAAU,YAAY,CAAC,OAAkC,EAAE,OAAuB;IACvF,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAClC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;QACtB,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,OAAO,GAAG,C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,IAAI,CAAC,EAAE,CAAC,CAAC;oBACrD,GAAG,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,OAAO,CAAC,aAAa;iBAC7E,CAAC,CAAC,EAAE,CAAC;QACP,CAAC;IACF,CAAC;IACD,MAAM,IAAI,UAAU,CAAC,gBAAgB,EAAE,wDAAwD,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,SAAS,iBAAiB,CAAC,CAAC;AACxJ,CAAC;AAED,SAAS,WAAW,CAAC,GAAW,EAAE,GAAW;IAC5C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,IAAI,GAAG,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QAC9C,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;YAClB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACF,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface PackingRect {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}
|
|
7
|
+
export interface PackingItem {
|
|
8
|
+
name: string;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
export interface Placement extends PackingRect {
|
|
13
|
+
name: string;
|
|
14
|
+
}
|
|
15
|
+
export type PackingHeuristic = 'short-side' | 'area' | 'long-side';
|
|
16
|
+
export declare function placeRectangles(items: readonly PackingItem[], width: number, height: number, heuristic: PackingHeuristic): Placement[] | undefined;
|
|
17
|
+
//# sourceMappingURL=max-rects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"max-rects.d.ts","sourceRoot":"","sources":["../src/max-rects.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC3B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,SAAU,SAAQ,WAAW;IAC7C,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG,MAAM,GAAG,WAAW,CAAC;AAEnE,wBAAgB,eAAe,CAC9B,KAAK,EAAE,SAAS,WAAW,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,GACvF,SAAS,EAAE,GAAG,SAAS,CA4BzB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export function placeRectangles(items, width, height, heuristic) {
|
|
2
|
+
let free = [{ x: 0, y: 0, width, height }];
|
|
3
|
+
const placements = [];
|
|
4
|
+
for (const item of items) {
|
|
5
|
+
let best;
|
|
6
|
+
let bestPrimary = Infinity;
|
|
7
|
+
let bestSecondary = Infinity;
|
|
8
|
+
for (const rect of free) {
|
|
9
|
+
if (item.width > rect.width || item.height > rect.height)
|
|
10
|
+
continue;
|
|
11
|
+
const short = Math.min(rect.width - item.width, rect.height - item.height);
|
|
12
|
+
const long = Math.max(rect.width - item.width, rect.height - item.height);
|
|
13
|
+
const primary = heuristic === 'area' ? rect.width * rect.height - item.width * item.height
|
|
14
|
+
: heuristic === 'long-side' ? long : short;
|
|
15
|
+
const secondary = heuristic === 'area' ? short : heuristic === 'long-side' ? short : long;
|
|
16
|
+
if (primary < bestPrimary || (primary === bestPrimary && secondary < bestSecondary) ||
|
|
17
|
+
(primary === bestPrimary && secondary === bestSecondary &&
|
|
18
|
+
(!best || rect.y < best.y || (rect.y === best.y && rect.x < best.x)))) {
|
|
19
|
+
best = rect;
|
|
20
|
+
bestPrimary = primary;
|
|
21
|
+
bestSecondary = secondary;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (!best)
|
|
25
|
+
return undefined;
|
|
26
|
+
const placed = { name: item.name, x: best.x, y: best.y, width: item.width, height: item.height };
|
|
27
|
+
placements.push(placed);
|
|
28
|
+
free = pruneRectangles(free.flatMap(rect => splitRect(rect, placed)));
|
|
29
|
+
}
|
|
30
|
+
return placements;
|
|
31
|
+
}
|
|
32
|
+
function splitRect(free, used) {
|
|
33
|
+
const right = free.x + free.width;
|
|
34
|
+
const bottom = free.y + free.height;
|
|
35
|
+
const usedRight = used.x + used.width;
|
|
36
|
+
const usedBottom = used.y + used.height;
|
|
37
|
+
if (used.x >= right || usedRight <= free.x || used.y >= bottom || usedBottom <= free.y) {
|
|
38
|
+
return [free];
|
|
39
|
+
}
|
|
40
|
+
const parts = [];
|
|
41
|
+
if (used.x > free.x) {
|
|
42
|
+
parts.push({ x: free.x, y: free.y, width: used.x - free.x, height: free.height });
|
|
43
|
+
}
|
|
44
|
+
if (usedRight < right) {
|
|
45
|
+
parts.push({ x: usedRight, y: free.y, width: right - usedRight, height: free.height });
|
|
46
|
+
}
|
|
47
|
+
if (used.y > free.y) {
|
|
48
|
+
parts.push({ x: free.x, y: free.y, width: free.width, height: used.y - free.y });
|
|
49
|
+
}
|
|
50
|
+
if (usedBottom < bottom) {
|
|
51
|
+
parts.push({ x: free.x, y: usedBottom, width: free.width, height: bottom - usedBottom });
|
|
52
|
+
}
|
|
53
|
+
return parts;
|
|
54
|
+
}
|
|
55
|
+
function pruneRectangles(rects) {
|
|
56
|
+
return rects.filter((rect, index) => !rects.some((other, otherIndex) => {
|
|
57
|
+
if (index === otherIndex)
|
|
58
|
+
return false;
|
|
59
|
+
const contained = rect.x >= other.x && rect.y >= other.y &&
|
|
60
|
+
rect.x + rect.width <= other.x + other.width && rect.y + rect.height <= other.y + other.height;
|
|
61
|
+
if (!contained)
|
|
62
|
+
return false;
|
|
63
|
+
const equal = rect.x === other.x && rect.y === other.y && rect.width === other.width && rect.height === other.height;
|
|
64
|
+
return !equal || otherIndex < index;
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=max-rects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"max-rects.js","sourceRoot":"","sources":["../src/max-rects.ts"],"names":[],"mappings":"AAmBA,MAAM,UAAU,eAAe,CAC9B,KAA6B,EAAE,KAAa,EAAE,MAAc,EAAE,SAA2B;IAEzF,IAAI,IAAI,GAAkB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IAC1D,MAAM,UAAU,GAAgB,EAAE,CAAC;IACnC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,IAAI,IAA6B,CAAC;QAClC,IAAI,WAAW,GAAG,QAAQ,CAAC;QAC3B,IAAI,aAAa,GAAG,QAAQ,CAAC;QAC7B,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;YACzB,IAAI,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM;gBAAE,SAAS;YACnE,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;YAC3E,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;YAC1E,MAAM,OAAO,GAAG,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,I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,KAAK,KAAK,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,CAAC;QACrH,OAAO,CAAC,KAAK,IAAI,UAAU,GAAG,KAAK,CAAC;IACrC,CAAC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AtlasOptions, AtlasSource } from './AtlasTypes.js';
|
|
2
|
+
export type PackingOptions = Required<AtlasOptions>;
|
|
3
|
+
export declare function resolveOptions(options: AtlasOptions): PackingOptions;
|
|
4
|
+
export declare function validateSources(sources: readonly AtlasSource[], options: PackingOptions): void;
|
|
5
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEjE,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;AAEpD,wBAAgB,cAAc,CAAC,OAAO,EAAE,YAAY,GAAG,cAAc,CA4BpE;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI,CA2B9F"}
|