@openfairygui/functions 0.2.0-alpha.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -6
- package/dist/atlas-C6tbl7nn.d.ts +193 -0
- package/dist/atlas-CHsu2Y8i.d.cts +193 -0
- package/dist/index.cjs +17 -3603
- package/dist/index.d.cts +5 -294
- package/dist/index.d.ts +5 -294
- package/dist/index.js +4 -3595
- package/dist/node.cjs +256 -0
- package/dist/node.d.cts +36 -0
- package/dist/node.d.ts +36 -0
- package/dist/node.js +254 -0
- package/dist/publish-CykUJfVa.cjs +3269 -0
- package/dist/publish-DXoaC1Nl.js +3174 -0
- package/dist/restore-BQp01WY3.js +914 -0
- package/dist/restore-BeWaJNjR.d.cts +288 -0
- package/dist/restore-CEywQUHz.cjs +919 -0
- package/dist/restore-Dh0-Nvms.d.ts +288 -0
- package/dist/uam-transaction.cjs +29 -14
- package/dist/uam-transaction.d.cts +2 -1
- package/dist/uam-transaction.d.ts +2 -1
- package/dist/uam-transaction.js +30 -16
- package/dist/web.cjs +440 -0
- package/dist/web.d.cts +44 -0
- package/dist/web.d.ts +44 -0
- package/dist/web.js +439 -0
- package/package.json +29 -4
- package/src/adapters/node/plugins.ts +82 -0
- package/src/adapters/node/publish.ts +130 -0
- package/src/adapters/node/restore.ts +187 -0
- package/src/adapters/web/publish.ts +196 -0
- package/src/adapters/web/raster.ts +421 -0
- package/src/atlas/font.ts +95 -0
- package/src/atlas/inputs.ts +445 -0
- package/src/atlas/jta.ts +157 -0
- package/src/atlas/packing.ts +762 -0
- package/src/atlas.ts +129 -1221
- package/src/codegen.ts +108 -82
- package/src/index.ts +43 -3
- package/src/node.ts +8 -0
- package/src/path-utils.ts +40 -0
- package/src/plugins/types.ts +56 -0
- package/src/publish/contracts.ts +80 -0
- package/src/publish/external-resources.ts +117 -0
- package/src/publish/options.ts +180 -0
- package/src/publish/package-context.ts +608 -0
- package/src/publish/resource-references.ts +210 -0
- package/src/publish.ts +327 -975
- package/src/restore-internals/font.ts +100 -0
- package/src/restore-internals/movie-clip.ts +104 -0
- package/src/restore-internals/output-transaction.ts +124 -0
- package/src/restore.ts +122 -311
- package/src/shared-types.ts +4 -8
- package/src/uam-transaction.ts +34 -17
- package/src/utils.ts +28 -0
- package/src/web.ts +11 -0
package/README.md
CHANGED
|
@@ -11,19 +11,55 @@ npm install --save @openfairygui/core @openfairygui/functions
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
-
import { NodeIO } from '@openfairygui/core';
|
|
15
|
-
import { inspect
|
|
14
|
+
import { NodeIO } from '@openfairygui/core/node';
|
|
15
|
+
import { inspect } from '@openfairygui/functions';
|
|
16
|
+
import { publishNode, restoreNode } from '@openfairygui/functions/node';
|
|
16
17
|
|
|
17
18
|
const io = new NodeIO();
|
|
18
19
|
const doc = await io.readProject('./MyProject/MyProject.fairy');
|
|
19
20
|
|
|
20
21
|
const report = inspect(doc);
|
|
21
|
-
await
|
|
22
|
+
await publishNode({ document: doc, output: './release' });
|
|
23
|
+
|
|
24
|
+
await restoreNode({
|
|
25
|
+
inputDir: './release',
|
|
26
|
+
output: './restored-project',
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`publishNode` owns the standard Node filesystem, Sharp raster backend, and project plugin discovery. `restoreNode` owns the Node filesystem and Sharp image extraction required by trusted-local artifact recovery. The root `publish()` and `restore()` exports remain the lower-level capability-injected workflows for custom hosts.
|
|
31
|
+
|
|
32
|
+
## Browser LayaBox publish
|
|
33
|
+
|
|
34
|
+
Use `@openfairygui/core/web` to read the raw project, then publish through the browser-only entry. Both filesystems are caller-owned, so they can be File System Access, OPFS, IndexedDB, ZIP, or memory adapters.
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { WebIO } from '@openfairygui/core/web';
|
|
38
|
+
import { publishBrowser } from '@openfairygui/functions/web';
|
|
39
|
+
|
|
40
|
+
const document = await new WebIO(sourceFileSystem).readProject('Project.fairy');
|
|
41
|
+
const result = await publishBrowser({
|
|
42
|
+
document,
|
|
43
|
+
sourceFileSystem,
|
|
44
|
+
outputFileSystem,
|
|
45
|
+
projectType: 'layabox',
|
|
46
|
+
output: '.fairygui-runtime',
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (!result.success) console.error(result.diagnostics);
|
|
22
50
|
```
|
|
23
51
|
|
|
24
|
-
|
|
52
|
+
The browser entry uses native Canvas APIs for atlas PNGs, writes only through `outputFileSystem`, and supplies no Node plugin capability. Persisted Laya publish compression, atlas, and safe file-extension settings apply; explicit `compressed` and `atlas` options override their corresponding settings. Explicit `output`, `branch`, and `packages` also keep their normal precedence, so desktop-only configured output paths are not used when `output` is supplied.
|
|
53
|
+
|
|
54
|
+
Browser code generation is not supported. If global code generation is enabled and a selected package requests it, preflight returns `unsupported_publish_setting` with `setting` and `path` before Canvas checks or output writes. On any failure, `files` lists only `writeFileRaw` operations that completed successfully; `success: false` with a non-empty list therefore means built-in output is partial. Callers needing atomic publication should provide a transactional or staging `outputFileSystem`.
|
|
55
|
+
|
|
56
|
+
Publish plugins are documented in the repository guide:
|
|
25
57
|
|
|
26
|
-
|
|
58
|
+
- https://github.com/OpenFairyGUI/OpenFairyGUI/blob/main/docs/publish-plugins.md
|
|
59
|
+
|
|
60
|
+
## UAM authoring seam
|
|
61
|
+
|
|
62
|
+
`@openfairygui/functions` also exposes a thin stateless wrapper over the UAM
|
|
27
63
|
transaction contract from `@openfairygui/core`.
|
|
28
64
|
|
|
29
65
|
This seam:
|
|
@@ -34,6 +70,16 @@ This seam:
|
|
|
34
70
|
- does not define a second selector / operation grammar
|
|
35
71
|
- does not wrap `publish` or `restore`
|
|
36
72
|
|
|
73
|
+
The transaction surface includes component size/root properties, component-instance
|
|
74
|
+
extension overlays, resource rename/move, complete image-resource property snapshots,
|
|
75
|
+
byte-backed binary resource add/replace/remove,
|
|
76
|
+
and add/update/remove for `display`, `display2`, `look`, `xy`, `size`, `color`,
|
|
77
|
+
`animation`, `text`, `icon`, and `fontSize` gears. Resource
|
|
78
|
+
rename/move/replace/remove requires `sourceBytes`; opt in with
|
|
79
|
+
`ProjectReader.read(path, { hydrateResourceBytes: true })` before lifting a project to
|
|
80
|
+
UAM. Source bytes are written back with the project, and stale source files are removed
|
|
81
|
+
only after all replacement content succeeds.
|
|
82
|
+
|
|
37
83
|
```ts
|
|
38
84
|
import {
|
|
39
85
|
type UamProject,
|
|
@@ -41,7 +87,7 @@ import {
|
|
|
41
87
|
} from '@openfairygui/core';
|
|
42
88
|
import { applyUamTransactionApp } from '@openfairygui/functions';
|
|
43
89
|
|
|
44
|
-
const project: UamProject = /*
|
|
90
|
+
const project: UamProject = /* project read and lifted with hydrateResourceBytes */;
|
|
45
91
|
const operations: UamTransactionOperation[] = [
|
|
46
92
|
{
|
|
47
93
|
kind: 'renameResource',
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { FileSystem, Transform } from "@openfairygui/core";
|
|
2
|
+
|
|
3
|
+
//#region src/publish/contracts.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Source files required by a publish adapter.
|
|
6
|
+
*
|
|
7
|
+
* The host owns this filesystem: Node adapters use native paths while web
|
|
8
|
+
* adapters can use File System Access, OPFS, IndexedDB, ZIP, or memory.
|
|
9
|
+
*/
|
|
10
|
+
type PublishSourceFileSystem = Pick<FileSystem, 'readFileRaw' | 'join'>;
|
|
11
|
+
/**
|
|
12
|
+
* Output files required by a publish adapter.
|
|
13
|
+
*/
|
|
14
|
+
type PublishOutputFileSystem = Pick<FileSystem, 'writeFileRaw' | 'mkdir' | 'join'>;
|
|
15
|
+
/**
|
|
16
|
+
* Full filesystem contract consumed by the capability-injected publish core.
|
|
17
|
+
*
|
|
18
|
+
* Read, enumeration, and delete operations are optional because individual
|
|
19
|
+
* publish lanes only request them when needed.
|
|
20
|
+
*/
|
|
21
|
+
type PublishFileSystem = PublishOutputFileSystem & {
|
|
22
|
+
deleteFile?: (path: string) => Promise<void>;
|
|
23
|
+
exists?: FileSystem['exists'];
|
|
24
|
+
readdir?: FileSystem['readdir'];
|
|
25
|
+
readFileRaw?: FileSystem['readFileRaw'];
|
|
26
|
+
};
|
|
27
|
+
interface AtlasRasterMetadata {
|
|
28
|
+
width?: number;
|
|
29
|
+
height?: number;
|
|
30
|
+
channels?: number;
|
|
31
|
+
hasAlpha?: boolean;
|
|
32
|
+
trimOffsetLeft?: number;
|
|
33
|
+
trimOffsetTop?: number;
|
|
34
|
+
}
|
|
35
|
+
interface AtlasRasterResolvedBuffer {
|
|
36
|
+
data: Uint8Array;
|
|
37
|
+
info: Required<Pick<AtlasRasterMetadata, 'width' | 'height' | 'channels'>> & AtlasRasterMetadata;
|
|
38
|
+
}
|
|
39
|
+
interface AtlasRasterCompositeInput {
|
|
40
|
+
input: Uint8Array;
|
|
41
|
+
left: number;
|
|
42
|
+
top: number;
|
|
43
|
+
}
|
|
44
|
+
type AtlasRasterInput = string | Uint8Array | {
|
|
45
|
+
create: {
|
|
46
|
+
width: number;
|
|
47
|
+
height: number;
|
|
48
|
+
channels: 4;
|
|
49
|
+
background: {
|
|
50
|
+
r: number;
|
|
51
|
+
g: number;
|
|
52
|
+
b: number;
|
|
53
|
+
alpha: number;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Host-provided raster pipeline used by atlas packing.
|
|
59
|
+
*
|
|
60
|
+
* Sharp and the browser Canvas adapter both satisfy this contract.
|
|
61
|
+
*/
|
|
62
|
+
interface AtlasRasterPipeline {
|
|
63
|
+
ensureAlpha(): AtlasRasterPipeline;
|
|
64
|
+
resize(options: {
|
|
65
|
+
width: number;
|
|
66
|
+
height: number;
|
|
67
|
+
fit?: 'fill';
|
|
68
|
+
}): AtlasRasterPipeline;
|
|
69
|
+
raw(): AtlasRasterPipeline;
|
|
70
|
+
extract(options: {
|
|
71
|
+
left: number;
|
|
72
|
+
top: number;
|
|
73
|
+
width: number;
|
|
74
|
+
height: number;
|
|
75
|
+
}): AtlasRasterPipeline;
|
|
76
|
+
png(): AtlasRasterPipeline;
|
|
77
|
+
rotate(angle: number): AtlasRasterPipeline;
|
|
78
|
+
composite(inputs: AtlasRasterCompositeInput[]): AtlasRasterPipeline;
|
|
79
|
+
metadata(): Promise<AtlasRasterMetadata>;
|
|
80
|
+
toBuffer(options: {
|
|
81
|
+
resolveWithObject: true;
|
|
82
|
+
}): Promise<AtlasRasterResolvedBuffer>;
|
|
83
|
+
toBuffer(options?: {
|
|
84
|
+
resolveWithObject?: false;
|
|
85
|
+
}): Promise<Uint8Array>;
|
|
86
|
+
toFile(path: string): Promise<unknown>;
|
|
87
|
+
}
|
|
88
|
+
type AtlasRasterBackend = (input: AtlasRasterInput) => AtlasRasterPipeline;
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/atlas.d.ts
|
|
91
|
+
interface AtlasOptions {
|
|
92
|
+
/**
|
|
93
|
+
* Limit atlas generation to specific package names.
|
|
94
|
+
* When omitted, all packages are processed.
|
|
95
|
+
*/
|
|
96
|
+
packages?: string[];
|
|
97
|
+
/**
|
|
98
|
+
* Raster backend, injected by the host adapter.
|
|
99
|
+
* Required for actual image compositing and trimImage.
|
|
100
|
+
*
|
|
101
|
+
* ```ts
|
|
102
|
+
* import sharp from 'sharp';
|
|
103
|
+
* await doc.transform(atlas({ encoder: sharp }));
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
encoder?: AtlasRasterBackend;
|
|
107
|
+
/** Maximum atlas texture size (width and height). Default: 2048. */
|
|
108
|
+
maxSize?: number;
|
|
109
|
+
/** Whether to use the fast editor-compatible packing heuristics. Default: true. */
|
|
110
|
+
fast?: boolean;
|
|
111
|
+
/** Allow rotating sprites 90° for better packing. Default: true. */
|
|
112
|
+
allowRotation?: boolean;
|
|
113
|
+
/** Pixel padding between sprites. Default: 1. */
|
|
114
|
+
padding?: number;
|
|
115
|
+
/** Constrain atlas dimensions to powers of two. Default: false. */
|
|
116
|
+
powerOfTwo?: boolean;
|
|
117
|
+
/** Force square atlas (width === height). Default: false. */
|
|
118
|
+
square?: boolean;
|
|
119
|
+
/** Allow spilling into multiple atlas pages. Default: true. */
|
|
120
|
+
multiPage?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Trim transparent pixels from image edges before packing.
|
|
123
|
+
* Requires a raster backend. Stores offset/originalSize in Sprite nodes.
|
|
124
|
+
* Default: false.
|
|
125
|
+
*/
|
|
126
|
+
trimImage?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Base path for reading source images. If not set, images must have
|
|
129
|
+
* their pixel data stored in extras._imageData as Uint8Array.
|
|
130
|
+
*/
|
|
131
|
+
basePath?: string;
|
|
132
|
+
/**
|
|
133
|
+
* Output directory for generated atlas PNGs.
|
|
134
|
+
* Required when encoder is provided.
|
|
135
|
+
*/
|
|
136
|
+
outputPath?: string;
|
|
137
|
+
/**
|
|
138
|
+
* Optional mkdir function to ensure output directory exists.
|
|
139
|
+
* If not provided, the outputPath directory must already exist.
|
|
140
|
+
*/
|
|
141
|
+
mkdir?: (path: string) => Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* Optional raw file reader for reading .jta MovieClip files.
|
|
144
|
+
* Required for MovieClip frame atlas packing.
|
|
145
|
+
*/
|
|
146
|
+
readFileRaw?: (path: string) => Promise<Uint8Array>;
|
|
147
|
+
/**
|
|
148
|
+
* Keep original input order when MaxRects tie-break scores are equal.
|
|
149
|
+
* This is an internal publish detail used to mirror editor/CLI behavior.
|
|
150
|
+
*/
|
|
151
|
+
preserveInputOrderOnTie?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Internal publish detail used by Unity binary output:
|
|
154
|
+
* allow single untrimmed PNG image packages to bypass the packer and
|
|
155
|
+
* write atlas0 directly, matching the reference CLI behavior.
|
|
156
|
+
*/
|
|
157
|
+
directSingleImageOutput?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Internal publish detail used by the direct-image-output path.
|
|
160
|
+
* When extractAlpha is enabled, the direct output shortcut must be disabled.
|
|
161
|
+
*/
|
|
162
|
+
extractAlpha?: boolean;
|
|
163
|
+
/**
|
|
164
|
+
* When branchProcessing keeps branch resources, publish branch images into
|
|
165
|
+
* separate atlas pages/files per branch instead of mixing them with main.
|
|
166
|
+
*/
|
|
167
|
+
separatedAtlasForBranch?: boolean;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Packs image resources into texture atlases.
|
|
171
|
+
*
|
|
172
|
+
* This transform performs MaxRects bin-packing on all ImageResource items
|
|
173
|
+
* within each package, creating Atlas and Sprite property nodes. When an
|
|
174
|
+
* a raster backend is provided, it also composites the actual PNG files.
|
|
175
|
+
*
|
|
176
|
+
* When `trimImage` is enabled and encoder is available, transparent pixels
|
|
177
|
+
* at image edges are trimmed before packing. The trimmed offset and original
|
|
178
|
+
* dimensions are stored in the Sprite nodes for runtime reconstruction.
|
|
179
|
+
*
|
|
180
|
+
* ```ts
|
|
181
|
+
* import sharp from 'sharp';
|
|
182
|
+
* await doc.transform(atlas({
|
|
183
|
+
* encoder: sharp,
|
|
184
|
+
* maxSize: 2048,
|
|
185
|
+
* trimImage: true,
|
|
186
|
+
* basePath: './assets/',
|
|
187
|
+
* outputPath: './dist/',
|
|
188
|
+
* }));
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
declare function atlas(_options?: AtlasOptions): Transform;
|
|
192
|
+
//#endregion
|
|
193
|
+
export { AtlasRasterInput as a, AtlasRasterResolvedBuffer as c, PublishSourceFileSystem as d, AtlasRasterCompositeInput as i, PublishFileSystem as l, atlas as n, AtlasRasterMetadata as o, AtlasRasterBackend as r, AtlasRasterPipeline as s, AtlasOptions as t, PublishOutputFileSystem as u };
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { FileSystem, Transform } from "@openfairygui/core";
|
|
2
|
+
|
|
3
|
+
//#region src/publish/contracts.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Source files required by a publish adapter.
|
|
6
|
+
*
|
|
7
|
+
* The host owns this filesystem: Node adapters use native paths while web
|
|
8
|
+
* adapters can use File System Access, OPFS, IndexedDB, ZIP, or memory.
|
|
9
|
+
*/
|
|
10
|
+
type PublishSourceFileSystem = Pick<FileSystem, 'readFileRaw' | 'join'>;
|
|
11
|
+
/**
|
|
12
|
+
* Output files required by a publish adapter.
|
|
13
|
+
*/
|
|
14
|
+
type PublishOutputFileSystem = Pick<FileSystem, 'writeFileRaw' | 'mkdir' | 'join'>;
|
|
15
|
+
/**
|
|
16
|
+
* Full filesystem contract consumed by the capability-injected publish core.
|
|
17
|
+
*
|
|
18
|
+
* Read, enumeration, and delete operations are optional because individual
|
|
19
|
+
* publish lanes only request them when needed.
|
|
20
|
+
*/
|
|
21
|
+
type PublishFileSystem = PublishOutputFileSystem & {
|
|
22
|
+
deleteFile?: (path: string) => Promise<void>;
|
|
23
|
+
exists?: FileSystem['exists'];
|
|
24
|
+
readdir?: FileSystem['readdir'];
|
|
25
|
+
readFileRaw?: FileSystem['readFileRaw'];
|
|
26
|
+
};
|
|
27
|
+
interface AtlasRasterMetadata {
|
|
28
|
+
width?: number;
|
|
29
|
+
height?: number;
|
|
30
|
+
channels?: number;
|
|
31
|
+
hasAlpha?: boolean;
|
|
32
|
+
trimOffsetLeft?: number;
|
|
33
|
+
trimOffsetTop?: number;
|
|
34
|
+
}
|
|
35
|
+
interface AtlasRasterResolvedBuffer {
|
|
36
|
+
data: Uint8Array;
|
|
37
|
+
info: Required<Pick<AtlasRasterMetadata, 'width' | 'height' | 'channels'>> & AtlasRasterMetadata;
|
|
38
|
+
}
|
|
39
|
+
interface AtlasRasterCompositeInput {
|
|
40
|
+
input: Uint8Array;
|
|
41
|
+
left: number;
|
|
42
|
+
top: number;
|
|
43
|
+
}
|
|
44
|
+
type AtlasRasterInput = string | Uint8Array | {
|
|
45
|
+
create: {
|
|
46
|
+
width: number;
|
|
47
|
+
height: number;
|
|
48
|
+
channels: 4;
|
|
49
|
+
background: {
|
|
50
|
+
r: number;
|
|
51
|
+
g: number;
|
|
52
|
+
b: number;
|
|
53
|
+
alpha: number;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Host-provided raster pipeline used by atlas packing.
|
|
59
|
+
*
|
|
60
|
+
* Sharp and the browser Canvas adapter both satisfy this contract.
|
|
61
|
+
*/
|
|
62
|
+
interface AtlasRasterPipeline {
|
|
63
|
+
ensureAlpha(): AtlasRasterPipeline;
|
|
64
|
+
resize(options: {
|
|
65
|
+
width: number;
|
|
66
|
+
height: number;
|
|
67
|
+
fit?: 'fill';
|
|
68
|
+
}): AtlasRasterPipeline;
|
|
69
|
+
raw(): AtlasRasterPipeline;
|
|
70
|
+
extract(options: {
|
|
71
|
+
left: number;
|
|
72
|
+
top: number;
|
|
73
|
+
width: number;
|
|
74
|
+
height: number;
|
|
75
|
+
}): AtlasRasterPipeline;
|
|
76
|
+
png(): AtlasRasterPipeline;
|
|
77
|
+
rotate(angle: number): AtlasRasterPipeline;
|
|
78
|
+
composite(inputs: AtlasRasterCompositeInput[]): AtlasRasterPipeline;
|
|
79
|
+
metadata(): Promise<AtlasRasterMetadata>;
|
|
80
|
+
toBuffer(options: {
|
|
81
|
+
resolveWithObject: true;
|
|
82
|
+
}): Promise<AtlasRasterResolvedBuffer>;
|
|
83
|
+
toBuffer(options?: {
|
|
84
|
+
resolveWithObject?: false;
|
|
85
|
+
}): Promise<Uint8Array>;
|
|
86
|
+
toFile(path: string): Promise<unknown>;
|
|
87
|
+
}
|
|
88
|
+
type AtlasRasterBackend = (input: AtlasRasterInput) => AtlasRasterPipeline;
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/atlas.d.ts
|
|
91
|
+
interface AtlasOptions {
|
|
92
|
+
/**
|
|
93
|
+
* Limit atlas generation to specific package names.
|
|
94
|
+
* When omitted, all packages are processed.
|
|
95
|
+
*/
|
|
96
|
+
packages?: string[];
|
|
97
|
+
/**
|
|
98
|
+
* Raster backend, injected by the host adapter.
|
|
99
|
+
* Required for actual image compositing and trimImage.
|
|
100
|
+
*
|
|
101
|
+
* ```ts
|
|
102
|
+
* import sharp from 'sharp';
|
|
103
|
+
* await doc.transform(atlas({ encoder: sharp }));
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
encoder?: AtlasRasterBackend;
|
|
107
|
+
/** Maximum atlas texture size (width and height). Default: 2048. */
|
|
108
|
+
maxSize?: number;
|
|
109
|
+
/** Whether to use the fast editor-compatible packing heuristics. Default: true. */
|
|
110
|
+
fast?: boolean;
|
|
111
|
+
/** Allow rotating sprites 90° for better packing. Default: true. */
|
|
112
|
+
allowRotation?: boolean;
|
|
113
|
+
/** Pixel padding between sprites. Default: 1. */
|
|
114
|
+
padding?: number;
|
|
115
|
+
/** Constrain atlas dimensions to powers of two. Default: false. */
|
|
116
|
+
powerOfTwo?: boolean;
|
|
117
|
+
/** Force square atlas (width === height). Default: false. */
|
|
118
|
+
square?: boolean;
|
|
119
|
+
/** Allow spilling into multiple atlas pages. Default: true. */
|
|
120
|
+
multiPage?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Trim transparent pixels from image edges before packing.
|
|
123
|
+
* Requires a raster backend. Stores offset/originalSize in Sprite nodes.
|
|
124
|
+
* Default: false.
|
|
125
|
+
*/
|
|
126
|
+
trimImage?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Base path for reading source images. If not set, images must have
|
|
129
|
+
* their pixel data stored in extras._imageData as Uint8Array.
|
|
130
|
+
*/
|
|
131
|
+
basePath?: string;
|
|
132
|
+
/**
|
|
133
|
+
* Output directory for generated atlas PNGs.
|
|
134
|
+
* Required when encoder is provided.
|
|
135
|
+
*/
|
|
136
|
+
outputPath?: string;
|
|
137
|
+
/**
|
|
138
|
+
* Optional mkdir function to ensure output directory exists.
|
|
139
|
+
* If not provided, the outputPath directory must already exist.
|
|
140
|
+
*/
|
|
141
|
+
mkdir?: (path: string) => Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* Optional raw file reader for reading .jta MovieClip files.
|
|
144
|
+
* Required for MovieClip frame atlas packing.
|
|
145
|
+
*/
|
|
146
|
+
readFileRaw?: (path: string) => Promise<Uint8Array>;
|
|
147
|
+
/**
|
|
148
|
+
* Keep original input order when MaxRects tie-break scores are equal.
|
|
149
|
+
* This is an internal publish detail used to mirror editor/CLI behavior.
|
|
150
|
+
*/
|
|
151
|
+
preserveInputOrderOnTie?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Internal publish detail used by Unity binary output:
|
|
154
|
+
* allow single untrimmed PNG image packages to bypass the packer and
|
|
155
|
+
* write atlas0 directly, matching the reference CLI behavior.
|
|
156
|
+
*/
|
|
157
|
+
directSingleImageOutput?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Internal publish detail used by the direct-image-output path.
|
|
160
|
+
* When extractAlpha is enabled, the direct output shortcut must be disabled.
|
|
161
|
+
*/
|
|
162
|
+
extractAlpha?: boolean;
|
|
163
|
+
/**
|
|
164
|
+
* When branchProcessing keeps branch resources, publish branch images into
|
|
165
|
+
* separate atlas pages/files per branch instead of mixing them with main.
|
|
166
|
+
*/
|
|
167
|
+
separatedAtlasForBranch?: boolean;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Packs image resources into texture atlases.
|
|
171
|
+
*
|
|
172
|
+
* This transform performs MaxRects bin-packing on all ImageResource items
|
|
173
|
+
* within each package, creating Atlas and Sprite property nodes. When an
|
|
174
|
+
* a raster backend is provided, it also composites the actual PNG files.
|
|
175
|
+
*
|
|
176
|
+
* When `trimImage` is enabled and encoder is available, transparent pixels
|
|
177
|
+
* at image edges are trimmed before packing. The trimmed offset and original
|
|
178
|
+
* dimensions are stored in the Sprite nodes for runtime reconstruction.
|
|
179
|
+
*
|
|
180
|
+
* ```ts
|
|
181
|
+
* import sharp from 'sharp';
|
|
182
|
+
* await doc.transform(atlas({
|
|
183
|
+
* encoder: sharp,
|
|
184
|
+
* maxSize: 2048,
|
|
185
|
+
* trimImage: true,
|
|
186
|
+
* basePath: './assets/',
|
|
187
|
+
* outputPath: './dist/',
|
|
188
|
+
* }));
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
declare function atlas(_options?: AtlasOptions): Transform;
|
|
192
|
+
//#endregion
|
|
193
|
+
export { AtlasRasterInput as a, AtlasRasterResolvedBuffer as c, PublishSourceFileSystem as d, AtlasRasterCompositeInput as i, PublishFileSystem as l, atlas as n, AtlasRasterMetadata as o, AtlasRasterBackend as r, AtlasRasterPipeline as s, AtlasOptions as t, PublishOutputFileSystem as u };
|