@replayablejs/assets 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/index.d.mts +272 -0
- package/dist/index.mjs +3932 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Replayable contributors
|
|
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
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @replayablejs/assets
|
|
2
|
+
|
|
3
|
+
Build optimized resources and generated TypeScript asset modules.
|
|
4
|
+
|
|
5
|
+
Part of [Replayable](https://github.com/replayablejs/replayable) **0.1.0-alpha.0**.
|
|
6
|
+
APIs may change during the alpha series.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
pnpm add -D @replayablejs/assets@0.1.0-alpha.0
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Public surface
|
|
15
|
+
|
|
16
|
+
`defineConfig`, `assetConfigSchema`, `buildAssets`; category and bundle constants; asset configuration, build-result and runtime asset types.
|
|
17
|
+
|
|
18
|
+
[Usage and reference](https://github.com/replayablejs/replayable/blob/main/docs/reference/assets.md).
|
|
19
|
+
The package manifest defines supported import paths; internal source files are not public APIs.
|
|
20
|
+
|
|
21
|
+
## Development
|
|
22
|
+
|
|
23
|
+
From the repository root, install with `pnpm install --frozen-lockfile` and build dependencies
|
|
24
|
+
with `pnpm build`. Run `pnpm --filter @replayablejs/assets test` for this package's tests.
|
|
25
|
+
|
|
26
|
+
## License
|
|
27
|
+
|
|
28
|
+
Original code is [MIT licensed](https://github.com/replayablejs/replayable/blob/main/LICENSE). Bundled third-party resources retain
|
|
29
|
+
their accompanying license terms.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AssetBundleName, AssetCategory, AssetMode, Assets, AssetsInBundle, AtlasAsset, FontAsset, GroupedAssetCategory, ImageAsset, JsonObject, JsonPrimitive, JsonValue, LocaleAsset, LocaleDictionary, ShaderAsset, SimpleAssetCategory, SpineAsset, assetBundleNames, assetCategories, groupedAssetCategories, simpleAssetCategories } from "@replayablejs/runtime/assets";
|
|
3
|
+
//#region src/types/build.d.ts
|
|
4
|
+
/** Summary returned after a successful assets build. */
|
|
5
|
+
interface BuildAssetsResult {
|
|
6
|
+
/** Emitted runtime bundles in loading order; primary is always present. */
|
|
7
|
+
readonly bundles: readonly AssetBundleName[];
|
|
8
|
+
/** Number of logical entries emitted into the runtime assets object. */
|
|
9
|
+
readonly emittedAssets: number;
|
|
10
|
+
/** Number of physical asset files written to the output directory. */
|
|
11
|
+
readonly emittedFiles: number;
|
|
12
|
+
/** Absolute directory containing the processed asset files. */
|
|
13
|
+
readonly outputDirectory: string;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/config/schema.d.ts
|
|
17
|
+
/**
|
|
18
|
+
* Complete runtime schema for `replayable.assets.ts`.
|
|
19
|
+
*
|
|
20
|
+
* `AssetConfigInput` describes author-written configuration where defaulted
|
|
21
|
+
* values may be absent. Parsing produces `AssetConfig`, where defaults are
|
|
22
|
+
* present and strings such as language codes have been trimmed.
|
|
23
|
+
*
|
|
24
|
+
* @remarks Most consumers should call `defineConfig()` instead of invoking
|
|
25
|
+
* this schema directly. The schema is exported for integrations that need Zod
|
|
26
|
+
* parsing, safe parsing, or introspection.
|
|
27
|
+
*/
|
|
28
|
+
declare const assetConfigSchema: z.ZodObject<{
|
|
29
|
+
sourceDir: z.ZodString;
|
|
30
|
+
outDir: z.ZodString;
|
|
31
|
+
localization: z.ZodObject<{
|
|
32
|
+
fallback: z.ZodString;
|
|
33
|
+
language: z.ZodString;
|
|
34
|
+
}, z.core.$strict>;
|
|
35
|
+
bundles: z.ZodPrefault<z.ZodObject<{
|
|
36
|
+
secondary: z.ZodOptional<z.ZodObject<{
|
|
37
|
+
exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
38
|
+
include: z.ZodArray<z.ZodString>;
|
|
39
|
+
}, z.core.$strict>>;
|
|
40
|
+
}, z.core.$strict>>;
|
|
41
|
+
assets: z.ZodObject<{
|
|
42
|
+
atlases: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
43
|
+
match: z.ZodDefault<z.ZodString>;
|
|
44
|
+
exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
45
|
+
options: z.ZodPrefault<z.ZodUnion<readonly [z.ZodObject<{
|
|
46
|
+
scale: z.ZodDefault<z.ZodNumber>;
|
|
47
|
+
lossless: z.ZodDefault<z.ZodLiteral<false>>;
|
|
48
|
+
quality: z.ZodOptional<z.ZodNumber>;
|
|
49
|
+
allowTrim: z.ZodDefault<z.ZodBoolean>;
|
|
50
|
+
allowRotation: z.ZodDefault<z.ZodBoolean>;
|
|
51
|
+
padding: z.ZodDefault<z.ZodNumber>;
|
|
52
|
+
extrude: z.ZodDefault<z.ZodNumber>;
|
|
53
|
+
powerOfTwo: z.ZodDefault<z.ZodBoolean>;
|
|
54
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
55
|
+
scale: z.ZodDefault<z.ZodNumber>;
|
|
56
|
+
lossless: z.ZodLiteral<true>;
|
|
57
|
+
allowTrim: z.ZodDefault<z.ZodBoolean>;
|
|
58
|
+
allowRotation: z.ZodDefault<z.ZodBoolean>;
|
|
59
|
+
padding: z.ZodDefault<z.ZodNumber>;
|
|
60
|
+
extrude: z.ZodDefault<z.ZodNumber>;
|
|
61
|
+
powerOfTwo: z.ZodDefault<z.ZodBoolean>;
|
|
62
|
+
}, z.core.$strict>]>>;
|
|
63
|
+
}, z.core.$strict>>>;
|
|
64
|
+
fonts: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
65
|
+
match: z.ZodDefault<z.ZodString>;
|
|
66
|
+
exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
67
|
+
options: z.ZodObject<{
|
|
68
|
+
family: z.ZodString;
|
|
69
|
+
extraCharacters: z.ZodOptional<z.ZodString>;
|
|
70
|
+
}, z.core.$strict>;
|
|
71
|
+
}, z.core.$strict>>>;
|
|
72
|
+
locales: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
73
|
+
match: z.ZodDefault<z.ZodString>;
|
|
74
|
+
exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
75
|
+
}, z.core.$strict>>>;
|
|
76
|
+
shaders: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
77
|
+
match: z.ZodDefault<z.ZodString>;
|
|
78
|
+
exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
79
|
+
}, z.core.$strict>>>;
|
|
80
|
+
sounds: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
81
|
+
match: z.ZodDefault<z.ZodString>;
|
|
82
|
+
exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
83
|
+
options: z.ZodPrefault<z.ZodObject<{
|
|
84
|
+
bitrate: z.ZodDefault<z.ZodNumber>;
|
|
85
|
+
channels: z.ZodDefault<z.ZodEnum<{
|
|
86
|
+
mono: "mono";
|
|
87
|
+
source: "source";
|
|
88
|
+
stereo: "stereo";
|
|
89
|
+
}>>;
|
|
90
|
+
sampleRate: z.ZodDefault<z.ZodNumber>;
|
|
91
|
+
}, z.core.$strict>>;
|
|
92
|
+
}, z.core.$strict>>>;
|
|
93
|
+
spines: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
94
|
+
match: z.ZodDefault<z.ZodString>;
|
|
95
|
+
exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
96
|
+
options: z.ZodPrefault<z.ZodUnion<readonly [z.ZodObject<{
|
|
97
|
+
scale: z.ZodDefault<z.ZodNumber>;
|
|
98
|
+
lossless: z.ZodDefault<z.ZodLiteral<false>>;
|
|
99
|
+
quality: z.ZodOptional<z.ZodNumber>;
|
|
100
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
101
|
+
scale: z.ZodDefault<z.ZodNumber>;
|
|
102
|
+
lossless: z.ZodLiteral<true>;
|
|
103
|
+
}, z.core.$strict>]>>;
|
|
104
|
+
}, z.core.$strict>>>;
|
|
105
|
+
sprites: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
106
|
+
match: z.ZodDefault<z.ZodString>;
|
|
107
|
+
exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
108
|
+
options: z.ZodPrefault<z.ZodUnion<readonly [z.ZodObject<{
|
|
109
|
+
scale: z.ZodDefault<z.ZodNumber>;
|
|
110
|
+
lossless: z.ZodDefault<z.ZodLiteral<false>>;
|
|
111
|
+
quality: z.ZodOptional<z.ZodNumber>;
|
|
112
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
113
|
+
scale: z.ZodDefault<z.ZodNumber>;
|
|
114
|
+
lossless: z.ZodLiteral<true>;
|
|
115
|
+
}, z.core.$strict>]>>;
|
|
116
|
+
}, z.core.$strict>>>;
|
|
117
|
+
textures: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
118
|
+
match: z.ZodDefault<z.ZodString>;
|
|
119
|
+
exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
120
|
+
options: z.ZodPrefault<z.ZodUnion<readonly [z.ZodObject<{
|
|
121
|
+
scale: z.ZodDefault<z.ZodNumber>;
|
|
122
|
+
lossless: z.ZodDefault<z.ZodLiteral<false>>;
|
|
123
|
+
quality: z.ZodOptional<z.ZodNumber>;
|
|
124
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
125
|
+
scale: z.ZodDefault<z.ZodNumber>;
|
|
126
|
+
lossless: z.ZodLiteral<true>;
|
|
127
|
+
}, z.core.$strict>]>>;
|
|
128
|
+
}, z.core.$strict>>>;
|
|
129
|
+
}, z.core.$strict>;
|
|
130
|
+
exclude: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
131
|
+
emit: z.ZodObject<{
|
|
132
|
+
assets: z.ZodDefault<z.ZodString>;
|
|
133
|
+
registries: z.ZodOptional<z.ZodString>;
|
|
134
|
+
}, z.core.$strict>;
|
|
135
|
+
}, z.core.$strict>;
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/types/config.d.ts
|
|
138
|
+
/** Validated asset configuration with every schema default applied. */
|
|
139
|
+
type AssetConfig = z.infer<typeof assetConfigSchema>;
|
|
140
|
+
/** Author-written asset configuration accepted before defaults are applied. */
|
|
141
|
+
type AssetConfigInput = z.input<typeof assetConfigSchema>;
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/build-assets.d.ts
|
|
144
|
+
/**
|
|
145
|
+
* Builds every configured asset and generates the runtime assets module.
|
|
146
|
+
*
|
|
147
|
+
* @param input - Author-written or previously normalized asset configuration.
|
|
148
|
+
* @param workingDirectory - Project root used to resolve every configured path.
|
|
149
|
+
* Defaults to the current process directory.
|
|
150
|
+
* @returns Logical asset and physical file counts, populated bundles, and the
|
|
151
|
+
* absolute output directory.
|
|
152
|
+
* @throws When configuration is invalid, configured paths are unsafe, or an
|
|
153
|
+
* asset cannot be resolved, processed, or emitted.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
*
|
|
157
|
+
* ```ts
|
|
158
|
+
* const result = await buildAssets(config, process.cwd());
|
|
159
|
+
*
|
|
160
|
+
* console.log(result.emittedAssets);
|
|
161
|
+
* console.log(result.emittedFiles);
|
|
162
|
+
* console.log(result.outputDirectory);
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
declare function buildAssets(input: AssetConfigInput, workingDirectory?: string): Promise<BuildAssetsResult>;
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/config/define-config.d.ts
|
|
168
|
+
/**
|
|
169
|
+
* Validates an authored asset configuration and applies schema defaults.
|
|
170
|
+
*
|
|
171
|
+
* Invalid fields or values throw when the configuration module loads. Valid
|
|
172
|
+
* input is returned with trimmed strings, normalized category arrays, and all
|
|
173
|
+
* processor defaults applied.
|
|
174
|
+
*
|
|
175
|
+
* @param config - Author-written configuration to validate and normalize.
|
|
176
|
+
* @returns A validated configuration with schema defaults applied.
|
|
177
|
+
* @throws When any configuration value fails schema validation.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
*
|
|
181
|
+
* ```ts
|
|
182
|
+
* import { defineConfig } from '@replayablejs/assets';
|
|
183
|
+
*
|
|
184
|
+
* export default defineConfig({
|
|
185
|
+
* assets: {
|
|
186
|
+
* sounds: [{ match: '**' }],
|
|
187
|
+
* },
|
|
188
|
+
* emit: { assets: 'src/assets/assets.gen.ts' },
|
|
189
|
+
* localization: { language: 'en', fallback: 'en' },
|
|
190
|
+
* outDir: 'assets/out',
|
|
191
|
+
* sourceDir: 'assets/source',
|
|
192
|
+
* });
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
declare function defineConfig(config: AssetConfigInput): AssetConfig;
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region src/config/schemas/atlas.d.ts
|
|
198
|
+
/** Image encoding and texture-packing options for generated atlas sheets. */
|
|
199
|
+
declare const atlasOptionsSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
200
|
+
scale: z.ZodDefault<z.ZodNumber>;
|
|
201
|
+
lossless: z.ZodDefault<z.ZodLiteral<false>>;
|
|
202
|
+
quality: z.ZodOptional<z.ZodNumber>;
|
|
203
|
+
allowTrim: z.ZodDefault<z.ZodBoolean>;
|
|
204
|
+
allowRotation: z.ZodDefault<z.ZodBoolean>;
|
|
205
|
+
padding: z.ZodDefault<z.ZodNumber>;
|
|
206
|
+
extrude: z.ZodDefault<z.ZodNumber>;
|
|
207
|
+
powerOfTwo: z.ZodDefault<z.ZodBoolean>;
|
|
208
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
209
|
+
scale: z.ZodDefault<z.ZodNumber>;
|
|
210
|
+
lossless: z.ZodLiteral<true>;
|
|
211
|
+
allowTrim: z.ZodDefault<z.ZodBoolean>;
|
|
212
|
+
allowRotation: z.ZodDefault<z.ZodBoolean>;
|
|
213
|
+
padding: z.ZodDefault<z.ZodNumber>;
|
|
214
|
+
extrude: z.ZodDefault<z.ZodNumber>;
|
|
215
|
+
powerOfTwo: z.ZodDefault<z.ZodBoolean>;
|
|
216
|
+
}, z.core.$strict>]>;
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region src/config/schemas/font.d.ts
|
|
219
|
+
/** Required runtime family name plus optional characters added to the subset. */
|
|
220
|
+
declare const fontOptionsSchema: z.ZodObject<{
|
|
221
|
+
family: z.ZodString;
|
|
222
|
+
extraCharacters: z.ZodOptional<z.ZodString>;
|
|
223
|
+
}, z.core.$strict>;
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/config/schemas/image.d.ts
|
|
226
|
+
/** Options shared by standalone images and Spine texture pages. */
|
|
227
|
+
declare const imageOptionsSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
228
|
+
scale: z.ZodDefault<z.ZodNumber>;
|
|
229
|
+
lossless: z.ZodDefault<z.ZodLiteral<false>>;
|
|
230
|
+
quality: z.ZodOptional<z.ZodNumber>;
|
|
231
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
232
|
+
scale: z.ZodDefault<z.ZodNumber>;
|
|
233
|
+
lossless: z.ZodLiteral<true>;
|
|
234
|
+
}, z.core.$strict>]>;
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/config/schemas/sound.d.ts
|
|
237
|
+
/** Encoding settings applied to every generated MP3 and M4A candidate. */
|
|
238
|
+
declare const soundOptionsSchema: z.ZodObject<{
|
|
239
|
+
bitrate: z.ZodDefault<z.ZodNumber>;
|
|
240
|
+
channels: z.ZodDefault<z.ZodEnum<{
|
|
241
|
+
mono: "mono";
|
|
242
|
+
source: "source";
|
|
243
|
+
stereo: "stereo";
|
|
244
|
+
}>>;
|
|
245
|
+
sampleRate: z.ZodDefault<z.ZodNumber>;
|
|
246
|
+
}, z.core.$strict>;
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/config/schemas/spine.d.ts
|
|
249
|
+
/** Image processing options applied independently to every Spine texture page. */
|
|
250
|
+
declare const spineOptionsSchema: import("zod").ZodUnion<readonly [import("zod").ZodObject<{
|
|
251
|
+
scale: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
252
|
+
lossless: import("zod").ZodDefault<import("zod").ZodLiteral<false>>;
|
|
253
|
+
quality: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
254
|
+
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
255
|
+
scale: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
256
|
+
lossless: import("zod").ZodLiteral<true>;
|
|
257
|
+
}, import("zod/v4/core").$strict>]>;
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/types/asset-options.d.ts
|
|
260
|
+
/** Author-written atlas options accepted before defaults are applied. */
|
|
261
|
+
type AtlasAssetOptions = z.input<typeof atlasOptionsSchema>;
|
|
262
|
+
/** Author-written font options accepted before validation. */
|
|
263
|
+
type FontAssetOptions = z.input<typeof fontOptionsSchema>;
|
|
264
|
+
/** Author-written image options accepted before defaults are applied. */
|
|
265
|
+
type ImageAssetOptions = z.input<typeof imageOptionsSchema>;
|
|
266
|
+
/** Author-written sound options accepted before defaults are applied. */
|
|
267
|
+
type SoundAssetOptions = z.input<typeof soundOptionsSchema>;
|
|
268
|
+
/** Author-written image options applied to Spine texture pages. */
|
|
269
|
+
type SpineAssetOptions = z.input<typeof spineOptionsSchema>;
|
|
270
|
+
//#endregion
|
|
271
|
+
export { type AssetBundleName, type AssetCategory, type AssetConfig, type AssetConfigInput, type AssetMode, type Assets, type AssetsInBundle, type AtlasAsset, type AtlasAssetOptions, type BuildAssetsResult, type FontAsset, type FontAssetOptions, type GroupedAssetCategory, type ImageAsset, type ImageAssetOptions, type JsonObject, type JsonPrimitive, type JsonValue, type LocaleAsset, type LocaleDictionary, type ShaderAsset, type SimpleAssetCategory, type SoundAssetOptions, type SpineAsset, type SpineAssetOptions, assetBundleNames, assetCategories, assetConfigSchema, buildAssets, defineConfig, groupedAssetCategories, simpleAssetCategories };
|
|
272
|
+
//# sourceMappingURL=index.d.mts.map
|