pixelkiln 0.96.1 → 0.98.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 +1 -1
- package/dist/cli.js +1796 -172
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1527 -358
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3948 -101
- package/dist/index.d.ts +3948 -101
- package/dist/index.js +1456 -330
- package/dist/index.js.map +1 -1
- package/docs/CLI.md +211 -2
- package/docs/ENDPOINTS.md +221 -15
- package/docs/GENERATORS.md +2 -2
- package/docs/MANIFEST.md +7 -0
- package/docs/PIXELLAB.md +5 -2
- package/docs/TILES.md +29 -0
- package/package.json +1 -1
- package/schema/manifest.schema.json +76 -0
- package/schema/recipe.schema.json +29 -0
- package/skills/pixelkiln/references/pixellab.md +1 -1
package/dist/index.js
CHANGED
|
@@ -98,7 +98,7 @@ function terrainTileCount(transitionSize, mode2, orientation) {
|
|
|
98
98
|
return transitionSize === 1 ? 25 : 16;
|
|
99
99
|
}
|
|
100
100
|
function terrainCost(mode2, tileSize, orientation) {
|
|
101
|
-
if (orientation === "sidescroller") return
|
|
101
|
+
if (orientation === "sidescroller") return mode2 === "pro" ? 15 : 1;
|
|
102
102
|
if (mode2 === "pro") return tileSize <= 32 ? 15 : 25;
|
|
103
103
|
return 4;
|
|
104
104
|
}
|
|
@@ -886,6 +886,48 @@ var StyleObjectSchema = z.object({
|
|
|
886
886
|
* lower terrain between them.
|
|
887
887
|
*/
|
|
888
888
|
terrainConnectDiagonals: z.boolean().optional(),
|
|
889
|
+
/**
|
|
890
|
+
* `terrain` generator only, standard mode, top-down. Which ragged border
|
|
891
|
+
* `terrainRaggedness` draws, 0 to 99 (the website's Reshuffle): another
|
|
892
|
+
* number gives a different boundary at the same raggedness. API default 0.
|
|
893
|
+
*/
|
|
894
|
+
terrainShapeSeed: z.number().int().min(0).max(99).optional(),
|
|
895
|
+
/**
|
|
896
|
+
* `terrain` generator only, standard mode, top-down, with
|
|
897
|
+
* `terrainTransitionSize` above 0. How thick the wall reads on the top
|
|
898
|
+
* rim and down both sides of the front face, 0 to 1. The website starts
|
|
899
|
+
* at 0.1.
|
|
900
|
+
*/
|
|
901
|
+
terrainSideWallThickness: z.number().min(0).max(1).optional(),
|
|
902
|
+
/**
|
|
903
|
+
* `terrain` generator only, standard mode, top-down, with
|
|
904
|
+
* `terrainTransitionSize` above 0. Which side of the border the wall sits
|
|
905
|
+
* on: 0 sticks out past the terrain (the API default), 1 is carved into
|
|
906
|
+
* it so the shape stays put. The website starts at 0.5.
|
|
907
|
+
*/
|
|
908
|
+
terrainSideWallPlacement: z.number().min(0).max(1).optional(),
|
|
909
|
+
/**
|
|
910
|
+
* `terrain` generator only, standard mode. PixelLab rewrites the terrain
|
|
911
|
+
* descriptions and picks base colors before drawing unless this is
|
|
912
|
+
* false. On by default upstream; set false to have your wording used as
|
|
913
|
+
* written.
|
|
914
|
+
*/
|
|
915
|
+
terrainEnhance: z.boolean().optional(),
|
|
916
|
+
/**
|
|
917
|
+
* `terrain` generator only, a standard sidescroller set. How thick the
|
|
918
|
+
* platform body is, 0 thin to 1 thick. Left out, PixelLab fits it to
|
|
919
|
+
* `terrainTransitionSize`.
|
|
920
|
+
*/
|
|
921
|
+
terrainPlatformThickness: z.number().min(0).max(1).optional(),
|
|
922
|
+
/**
|
|
923
|
+
* `terrain` generator only, top-down. Whether each terrain can be walked
|
|
924
|
+
* on, stored with the set for PixelLab's maps and engine exports (left
|
|
925
|
+
* out, those guess from the terrain's name). They change no pixel, so
|
|
926
|
+
* they are sent when the set is generated and are not part of its
|
|
927
|
+
* identity: changing one later does not make the set stale.
|
|
928
|
+
*/
|
|
929
|
+
terrainLowerWalkable: z.boolean().optional(),
|
|
930
|
+
terrainUpperWalkable: z.boolean().optional(),
|
|
889
931
|
/**
|
|
890
932
|
* `terrain` generator only. Visual height of the step between lower and
|
|
891
933
|
* upper terrain. Without `terrainShapeStyle`, only 0, 0.25, 0.5, or 1 are
|
|
@@ -1123,7 +1165,7 @@ var AssetDeriveSchema = z.object({
|
|
|
1123
1165
|
/** scale: `nearest` (default) keeps hard edges; `box` averages the covered pixels. */
|
|
1124
1166
|
mode: z.enum(["nearest", "box"]).optional()
|
|
1125
1167
|
}).strict().superRefine((derive, context) => {
|
|
1126
|
-
const issue = (message6,
|
|
1168
|
+
const issue = (message6, path46) => context.addIssue({ code: z.ZodIssueCode.custom, message: message6, path: [path46] });
|
|
1127
1169
|
if (Boolean(derive.from) === Boolean(derive.file)) {
|
|
1128
1170
|
issue("name exactly one source: `from` (an asset in this style) or `file` (a committed PNG)", derive.from ? "file" : "from");
|
|
1129
1171
|
}
|
|
@@ -1278,6 +1320,18 @@ var AssetSchema = z.object({
|
|
|
1278
1320
|
* (a sword hand, a parted fringe) comes out the other way round.
|
|
1279
1321
|
*/
|
|
1280
1322
|
mirror: z.string().min(1).optional(),
|
|
1323
|
+
/**
|
|
1324
|
+
* `terrain` styles only: a PNG per terrain for PixelLab to take that
|
|
1325
|
+
* terrain's look from, paths relative to the manifest. Top-down sets
|
|
1326
|
+
* take `lower`, `upper` and `transition`. A sidescroller set takes
|
|
1327
|
+
* `lower` (the platform body, pro mode) or `transition` (the surface
|
|
1328
|
+
* layer, standard mode), each a square PNG of the tile size.
|
|
1329
|
+
*/
|
|
1330
|
+
terrainReferences: z.object({
|
|
1331
|
+
lower: z.string().min(1).optional(),
|
|
1332
|
+
upper: z.string().min(1).optional(),
|
|
1333
|
+
transition: z.string().min(1).optional()
|
|
1334
|
+
}).strict().optional(),
|
|
1281
1335
|
/** Made from existing pixels by a local transform; see AssetDeriveSchema. Free; the provider is never called. */
|
|
1282
1336
|
derive: AssetDeriveSchema.optional(),
|
|
1283
1337
|
/** Built by a tool outside pixelkiln; see AssetExternalSchema. Never generated. */
|
|
@@ -1964,6 +2018,69 @@ var UiAssetGetSchema = z3.object({
|
|
|
1964
2018
|
progress_percent: z3.number().nullable().optional(),
|
|
1965
2019
|
eta_seconds: z3.number().nullable().optional()
|
|
1966
2020
|
}).passthrough();
|
|
2021
|
+
var CanvasChangeSchema = z3.object({
|
|
2022
|
+
id: z3.string(),
|
|
2023
|
+
previous: z3.object({ width: z3.number(), height: z3.number() }).passthrough(),
|
|
2024
|
+
canvas: z3.object({ width: z3.number(), height: z3.number() }).passthrough(),
|
|
2025
|
+
rotations_moved: z3.number().int().default(0),
|
|
2026
|
+
placements_moved: z3.number().int().nullable().optional()
|
|
2027
|
+
}).passthrough();
|
|
2028
|
+
var MirrorAnimationSchema = z3.object({
|
|
2029
|
+
animation_group_id: z3.string(),
|
|
2030
|
+
source_direction: z3.string(),
|
|
2031
|
+
target_direction: z3.string(),
|
|
2032
|
+
frames_created: z3.number().int()
|
|
2033
|
+
}).passthrough();
|
|
2034
|
+
var ImportObjectSchema = z3.object({
|
|
2035
|
+
object_id: z3.string().min(1),
|
|
2036
|
+
name: z3.string().nullable().optional(),
|
|
2037
|
+
size: z3.object({ width: z3.number(), height: z3.number() }).passthrough(),
|
|
2038
|
+
image_url: z3.string()
|
|
2039
|
+
}).passthrough();
|
|
2040
|
+
var ExpandRotationsSchema = z3.object({
|
|
2041
|
+
object_id: z3.string().min(1),
|
|
2042
|
+
background_job_id: z3.string().min(1),
|
|
2043
|
+
status: z3.string().default("expanding"),
|
|
2044
|
+
min_generations: z3.number(),
|
|
2045
|
+
max_generations: z3.number()
|
|
2046
|
+
}).passthrough();
|
|
2047
|
+
var UiNineSliceSchema = z3.object({ left: z3.number().int(), right: z3.number().int(), top: z3.number().int(), bottom: z3.number().int() }).passthrough();
|
|
2048
|
+
var UiSplitBoxSchema = z3.object({ label: z3.string().default(""), x: z3.number().int(), y: z3.number().int(), width: z3.number().int(), height: z3.number().int() }).passthrough();
|
|
2049
|
+
var UiSizeSchema = z3.object({ width: z3.number().int(), height: z3.number().int() }).passthrough();
|
|
2050
|
+
var UiStatePartSchema = z3.object({
|
|
2051
|
+
id: z3.string().min(1),
|
|
2052
|
+
name: z3.string().nullable().optional(),
|
|
2053
|
+
kind: z3.string().default("state"),
|
|
2054
|
+
size: UiSizeSchema,
|
|
2055
|
+
image_url: z3.string(),
|
|
2056
|
+
nine_slice: UiNineSliceSchema.nullable().optional()
|
|
2057
|
+
}).passthrough();
|
|
2058
|
+
var UiElementPartSchema = UiStatePartSchema.extend({
|
|
2059
|
+
template_box: UiSplitBoxSchema.nullable().optional(),
|
|
2060
|
+
states: z3.array(UiStatePartSchema).default([])
|
|
2061
|
+
}).passthrough();
|
|
2062
|
+
var UiAssetDetailSchema = z3.object({
|
|
2063
|
+
id: z3.string().min(1),
|
|
2064
|
+
name: z3.string().nullable().optional(),
|
|
2065
|
+
prompt: z3.string().default(""),
|
|
2066
|
+
size: UiSizeSchema,
|
|
2067
|
+
image_url: z3.string().nullable().optional(),
|
|
2068
|
+
status: z3.string().nullable().optional(),
|
|
2069
|
+
kind: z3.string().nullable().optional(),
|
|
2070
|
+
template_id: z3.string().nullable().optional(),
|
|
2071
|
+
parent_id: z3.string().nullable().optional(),
|
|
2072
|
+
nine_slice: UiNineSliceSchema.nullable().optional(),
|
|
2073
|
+
elements: z3.array(UiElementPartSchema).default([]),
|
|
2074
|
+
states: z3.array(UiStatePartSchema).default([]),
|
|
2075
|
+
split_preview: z3.array(UiSplitBoxSchema).default([])
|
|
2076
|
+
}).passthrough();
|
|
2077
|
+
var UiSplitResponseSchema = z3.object({ elements: z3.array(UiElementPartSchema) }).passthrough();
|
|
2078
|
+
var UiStatesSubmitSchema = z3.object({
|
|
2079
|
+
background_job_id: z3.string().min(1),
|
|
2080
|
+
status: z3.string().default("processing"),
|
|
2081
|
+
generations: z3.number(),
|
|
2082
|
+
count: z3.number().int()
|
|
2083
|
+
}).passthrough();
|
|
1967
2084
|
var RevisionJobSubmitSchema = z3.object({
|
|
1968
2085
|
background_job_id: z3.string().min(1),
|
|
1969
2086
|
status: z3.string().default("processing")
|
|
@@ -2050,6 +2167,48 @@ var FontJobSchema = z3.object({
|
|
|
2050
2167
|
download_ttf_url: z3.string().nullable().optional(),
|
|
2051
2168
|
usage: z3.unknown().optional()
|
|
2052
2169
|
}).passthrough();
|
|
2170
|
+
var SongSchema = z3.object({
|
|
2171
|
+
id: z3.string().min(1),
|
|
2172
|
+
status: z3.string(),
|
|
2173
|
+
error: z3.string().nullable().optional(),
|
|
2174
|
+
name: z3.string().default(""),
|
|
2175
|
+
audio_url: z3.string().nullable().optional(),
|
|
2176
|
+
duration_ms: z3.number().nullable().optional(),
|
|
2177
|
+
style: z3.string().default(""),
|
|
2178
|
+
instrumental: z3.boolean().default(true),
|
|
2179
|
+
lyrics: z3.string().default(""),
|
|
2180
|
+
take: z3.number().int().default(1),
|
|
2181
|
+
request_id: z3.string().optional(),
|
|
2182
|
+
loop_of: z3.string().nullable().optional(),
|
|
2183
|
+
loop_start_s: z3.number().nullable().optional(),
|
|
2184
|
+
loop_end_s: z3.number().nullable().optional()
|
|
2185
|
+
}).passthrough();
|
|
2186
|
+
var MusicSubmitSchema = z3.object({
|
|
2187
|
+
background_job_id: z3.string().min(1),
|
|
2188
|
+
status: z3.string().default("processing"),
|
|
2189
|
+
songs: z3.array(SongSchema).min(1),
|
|
2190
|
+
quoted_generations: z3.number().nullable().optional(),
|
|
2191
|
+
usage: z3.unknown().optional()
|
|
2192
|
+
}).passthrough();
|
|
2193
|
+
var SoundEffectSchema = z3.object({
|
|
2194
|
+
id: z3.string().min(1),
|
|
2195
|
+
status: z3.string(),
|
|
2196
|
+
error: z3.string().nullable().optional(),
|
|
2197
|
+
name: z3.string().default(""),
|
|
2198
|
+
audio_url: z3.string().nullable().optional(),
|
|
2199
|
+
duration_ms: z3.number().nullable().optional(),
|
|
2200
|
+
prompt: z3.string().default(""),
|
|
2201
|
+
seconds: z3.number().optional()
|
|
2202
|
+
}).passthrough();
|
|
2203
|
+
var SoundEffectSubmitSchema = z3.object({
|
|
2204
|
+
background_job_id: z3.string().min(1),
|
|
2205
|
+
status: z3.string().default("processing"),
|
|
2206
|
+
sound_effect: SoundEffectSchema,
|
|
2207
|
+
quoted_generations: z3.number().nullable().optional(),
|
|
2208
|
+
usage: z3.unknown().optional()
|
|
2209
|
+
}).passthrough();
|
|
2210
|
+
var ImproveStyleSchema = z3.object({ style: z3.string().min(1), usage: z3.unknown().optional() }).passthrough();
|
|
2211
|
+
var WriteLyricsSchema = z3.object({ lyrics: z3.array(z3.string()).min(1), usage: z3.unknown().optional() }).passthrough();
|
|
2053
2212
|
var SelectFramesSchema = z3.object({ created_object_ids: z3.array(z3.string()) }).passthrough();
|
|
2054
2213
|
var EstimateSkeletonResponseSchema = z3.object({
|
|
2055
2214
|
keypoints: z3.array(SkeletonKeypointSchema).length(18),
|
|
@@ -2192,6 +2351,20 @@ function parseProFlashQuote(raw) {
|
|
|
2192
2351
|
if (image !== null || rotations !== null) return { image, rotations, total: (image ?? 0) + (rotations ?? 0) };
|
|
2193
2352
|
throw new Error(`GET /pro-flash/cost returned no price: ${JSON.stringify(raw).slice(0, 200)}`);
|
|
2194
2353
|
}
|
|
2354
|
+
function refusalReason(status, body) {
|
|
2355
|
+
if (status < 400 || status >= 500 || !body.startsWith("{")) return "";
|
|
2356
|
+
try {
|
|
2357
|
+
const detail = JSON.parse(body).detail;
|
|
2358
|
+
if (typeof detail === "string" && detail) return `: ${detail.slice(0, 400)}`;
|
|
2359
|
+
if (Array.isArray(detail)) {
|
|
2360
|
+
const messages = detail.map((item) => item && typeof item === "object" && typeof item.msg === "string" ? item.msg : "").filter(Boolean).map((msg) => msg.replace(/^Value error, /, ""));
|
|
2361
|
+
if (messages.length) return `: ${messages.join("; ").slice(0, 400)}`;
|
|
2362
|
+
}
|
|
2363
|
+
return "";
|
|
2364
|
+
} catch {
|
|
2365
|
+
return "";
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2195
2368
|
var PixelLabError = class extends ProviderError {
|
|
2196
2369
|
constructor(message6, status, body) {
|
|
2197
2370
|
super("pixellab", message6, { status });
|
|
@@ -2230,9 +2403,9 @@ var PixelLabClient = class {
|
|
|
2230
2403
|
apiKey;
|
|
2231
2404
|
http;
|
|
2232
2405
|
/** Retries transport failures, 429, and 5xx; see http.ts for the policy. */
|
|
2233
|
-
async request(
|
|
2406
|
+
async request(path46, init) {
|
|
2234
2407
|
const auth = this.apiKey.startsWith("Bearer ") ? this.apiKey : `Bearer ${this.apiKey}`;
|
|
2235
|
-
const res = await this.http(`${BASE}${
|
|
2408
|
+
const res = await this.http(`${BASE}${path46}`, {
|
|
2236
2409
|
...init,
|
|
2237
2410
|
headers: {
|
|
2238
2411
|
Authorization: auth,
|
|
@@ -2243,13 +2416,13 @@ var PixelLabClient = class {
|
|
|
2243
2416
|
const text = await res.text();
|
|
2244
2417
|
if (!res.ok) {
|
|
2245
2418
|
const hint = res.status === 500 && text.includes("Failed to start any animation jobs") ? '; a skeleton-v3 loop needs a character with a stored 3D skeleton (a v3 base), use mode: "template" on a standard one' : "";
|
|
2246
|
-
throw new PixelLabError(`${init?.method ?? "GET"} ${
|
|
2419
|
+
throw new PixelLabError(`${init?.method ?? "GET"} ${path46} \u2192 ${res.status}${hint}${refusalReason(res.status, text)}`, res.status, text);
|
|
2247
2420
|
}
|
|
2248
2421
|
if (!text) return {};
|
|
2249
2422
|
try {
|
|
2250
2423
|
return JSON.parse(text);
|
|
2251
2424
|
} catch {
|
|
2252
|
-
throw new Error(`${init?.method ?? "GET"} ${
|
|
2425
|
+
throw new Error(`${init?.method ?? "GET"} ${path46} returned invalid JSON`);
|
|
2253
2426
|
}
|
|
2254
2427
|
}
|
|
2255
2428
|
async balance() {
|
|
@@ -2389,6 +2562,16 @@ var PixelLabClient = class {
|
|
|
2389
2562
|
lower_description: args.lowerDescription,
|
|
2390
2563
|
upper_description: args.upperDescription
|
|
2391
2564
|
};
|
|
2565
|
+
const image = (value) => ({ type: "base64", base64: value.base64, format: value.format });
|
|
2566
|
+
if (args.shapeSeed != null) body.shape_seed = args.shapeSeed;
|
|
2567
|
+
if (args.sideWallThickness != null) body.side_wall_thickness = args.sideWallThickness;
|
|
2568
|
+
if (args.sideWallPlacement != null) body.side_wall_placement = args.sideWallPlacement;
|
|
2569
|
+
if (args.enhance != null) body.enhance = args.enhance;
|
|
2570
|
+
if (args.lowerWalkable != null) body.lower_walkable = args.lowerWalkable;
|
|
2571
|
+
if (args.upperWalkable != null) body.upper_walkable = args.upperWalkable;
|
|
2572
|
+
if (args.lowerReferenceImage) body.lower_reference_image = image(args.lowerReferenceImage);
|
|
2573
|
+
if (args.upperReferenceImage) body.upper_reference_image = image(args.upperReferenceImage);
|
|
2574
|
+
if (args.transitionReferenceImage) body.transition_reference_image = image(args.transitionReferenceImage);
|
|
2392
2575
|
if (args.transitionDescription) body.transition_description = args.transitionDescription;
|
|
2393
2576
|
if (args.lowerBaseTileId) body.lower_base_tile_id = args.lowerBaseTileId;
|
|
2394
2577
|
if (args.upperBaseTileId) body.upper_base_tile_id = args.upperBaseTileId;
|
|
@@ -2426,6 +2609,12 @@ var PixelLabClient = class {
|
|
|
2426
2609
|
*/
|
|
2427
2610
|
async createTilesetSidescroller(args) {
|
|
2428
2611
|
const body = { lower_description: args.lowerDescription };
|
|
2612
|
+
const image = (value) => ({ type: "base64", base64: value.base64, format: value.format });
|
|
2613
|
+
if (args.mode) body.mode = args.mode;
|
|
2614
|
+
if (args.enhance != null) body.enhance = args.enhance;
|
|
2615
|
+
if (args.platformThickness != null) body.platform_thickness = args.platformThickness;
|
|
2616
|
+
if (args.transitionReferenceImage) body.transition_reference_image = image(args.transitionReferenceImage);
|
|
2617
|
+
if (args.lowerReferenceImage) body.lower_reference_image = image(args.lowerReferenceImage);
|
|
2429
2618
|
if (args.transitionDescription) body.transition_description = args.transitionDescription;
|
|
2430
2619
|
if (args.lowerBaseTileId) body.lower_base_tile_id = args.lowerBaseTileId;
|
|
2431
2620
|
if (args.tileSize != null) body.tile_size = { width: args.tileSize, height: args.tileSize };
|
|
@@ -2516,6 +2705,57 @@ var PixelLabClient = class {
|
|
|
2516
2705
|
);
|
|
2517
2706
|
return { ui_asset_id: res.ui_asset_id, background_job_id: res.background_job_id, usage: res.usage };
|
|
2518
2707
|
}
|
|
2708
|
+
/** `GET /ui-assets/{id}` with everything it reports: kind, elements and their states, 9-slice, and the default split boxes. */
|
|
2709
|
+
async getUiAssetDetail(uiAssetId) {
|
|
2710
|
+
return validateResponse(
|
|
2711
|
+
UiAssetDetailSchema,
|
|
2712
|
+
await this.request(`/ui-assets/${encodeURIComponent(uiAssetId)}`),
|
|
2713
|
+
"ui-assets/{id}"
|
|
2714
|
+
);
|
|
2715
|
+
}
|
|
2716
|
+
/**
|
|
2717
|
+
* `POST /ui-assets/{id}/split`: cut a template into one UI asset per shape.
|
|
2718
|
+
* Free; nothing is generated. A template splits once. Without `boxes` it
|
|
2719
|
+
* cuts along the shapes the template was generated from (`split_preview`).
|
|
2720
|
+
*/
|
|
2721
|
+
async splitUiAsset(uiAssetId, boxes) {
|
|
2722
|
+
const res = validateResponse(
|
|
2723
|
+
UiSplitResponseSchema,
|
|
2724
|
+
await this.request(`/ui-assets/${encodeURIComponent(uiAssetId)}/split`, {
|
|
2725
|
+
method: "POST",
|
|
2726
|
+
body: JSON.stringify(boxes?.length ? { boxes } : {})
|
|
2727
|
+
}),
|
|
2728
|
+
"ui-assets/{id}/split"
|
|
2729
|
+
);
|
|
2730
|
+
return res.elements;
|
|
2731
|
+
}
|
|
2732
|
+
/**
|
|
2733
|
+
* `POST /ui-assets/states`: draw every listed element in every listed state
|
|
2734
|
+
* in one generation, so the set matches. A background job; the 202 carries
|
|
2735
|
+
* the price (`generations`: 10, 15 or 25 by the size of the grid PixelLab
|
|
2736
|
+
* lays out) and is charged when the states are saved.
|
|
2737
|
+
*/
|
|
2738
|
+
async createUiStates(args) {
|
|
2739
|
+
const body = { element_ids: args.elementIds, states: args.states };
|
|
2740
|
+
Object.assign(body, targetPaletteBody(args.targetPalette));
|
|
2741
|
+
return validateResponse(
|
|
2742
|
+
UiStatesSubmitSchema,
|
|
2743
|
+
await this.request("/ui-assets/states", { method: "POST", body: JSON.stringify(body) }),
|
|
2744
|
+
"ui-assets/states"
|
|
2745
|
+
);
|
|
2746
|
+
}
|
|
2747
|
+
/** `PATCH /ui-assets/{id}`: rename, or set or clear the 9-slice insets. Free. */
|
|
2748
|
+
async updateUiAsset(uiAssetId, args) {
|
|
2749
|
+
const body = {};
|
|
2750
|
+
if (args.name) body.name = args.name;
|
|
2751
|
+
if (args.nineSlice) body.nine_slice = args.nineSlice;
|
|
2752
|
+
if (args.clearNineSlice) body.clear_nine_slice = true;
|
|
2753
|
+
return validateResponse(
|
|
2754
|
+
UiAssetDetailSchema,
|
|
2755
|
+
await this.request(`/ui-assets/${encodeURIComponent(uiAssetId)}`, { method: "PATCH", body: JSON.stringify(body) }),
|
|
2756
|
+
"ui-assets/{id}"
|
|
2757
|
+
);
|
|
2758
|
+
}
|
|
2519
2759
|
async getUiAsset(uiAssetId) {
|
|
2520
2760
|
const res = await validateResponse(
|
|
2521
2761
|
UiAssetGetSchema,
|
|
@@ -2702,10 +2942,10 @@ var PixelLabClient = class {
|
|
|
2702
2942
|
const palette = args.paletteSwatchBase64 ? { color_image: { type: "base64", base64: args.paletteSwatchBase64, format: "png" }, force_colors: true } : {};
|
|
2703
2943
|
const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
|
|
2704
2944
|
const south = args.reference?.south;
|
|
2705
|
-
let
|
|
2945
|
+
let path46;
|
|
2706
2946
|
let body;
|
|
2707
2947
|
if (args.mode === "v3") {
|
|
2708
|
-
|
|
2948
|
+
path46 = "/create-character-v3";
|
|
2709
2949
|
body = {
|
|
2710
2950
|
description: args.description,
|
|
2711
2951
|
image_size: imageSize,
|
|
@@ -2719,7 +2959,7 @@ var PixelLabClient = class {
|
|
|
2719
2959
|
...args.enhancePrompt ? { enhance_prompt: true } : {}
|
|
2720
2960
|
};
|
|
2721
2961
|
} else if (args.mode === "pro-flash") {
|
|
2722
|
-
|
|
2962
|
+
path46 = "/create-character-pro-flash";
|
|
2723
2963
|
const traits = args.styleTraits;
|
|
2724
2964
|
body = {
|
|
2725
2965
|
description: args.description,
|
|
@@ -2743,7 +2983,7 @@ var PixelLabClient = class {
|
|
|
2743
2983
|
} : {}
|
|
2744
2984
|
};
|
|
2745
2985
|
} else if (args.mode === "pro") {
|
|
2746
|
-
|
|
2986
|
+
path46 = "/create-character-pro";
|
|
2747
2987
|
body = {
|
|
2748
2988
|
description: args.description,
|
|
2749
2989
|
image_size: imageSize,
|
|
@@ -2757,7 +2997,7 @@ var PixelLabClient = class {
|
|
|
2757
2997
|
...!south && args.styleCharacterId ? { style_character_id: args.styleCharacterId } : {}
|
|
2758
2998
|
};
|
|
2759
2999
|
} else {
|
|
2760
|
-
|
|
3000
|
+
path46 = args.directions === 4 ? "/create-character-with-4-directions" : "/create-character-with-8-directions";
|
|
2761
3001
|
body = {
|
|
2762
3002
|
description: args.description,
|
|
2763
3003
|
image_size: imageSize,
|
|
@@ -2775,8 +3015,8 @@ var PixelLabClient = class {
|
|
|
2775
3015
|
};
|
|
2776
3016
|
}
|
|
2777
3017
|
if (args.mode === "pro" || args.mode === "pro-flash") Object.assign(body, targetPaletteBody(args.targetPalette));
|
|
2778
|
-
const raw = await this.request(
|
|
2779
|
-
return validateResponse(CharacterSubmitSchema, raw,
|
|
3018
|
+
const raw = await this.request(path46, { method: "POST", body: JSON.stringify(body) });
|
|
3019
|
+
return validateResponse(CharacterSubmitSchema, raw, path46.slice(1));
|
|
2780
3020
|
}
|
|
2781
3021
|
/** A text edit of an existing character, applied to every direction and stored as a sibling. */
|
|
2782
3022
|
async createCharacterState(args) {
|
|
@@ -3354,6 +3594,184 @@ var PixelLabClient = class {
|
|
|
3354
3594
|
"vfx"
|
|
3355
3595
|
);
|
|
3356
3596
|
}
|
|
3597
|
+
/**
|
|
3598
|
+
* `POST /music`: two takes of a song from a style description, instrumental
|
|
3599
|
+
* unless lyrics are sent or `autoLyrics` is set. A background job whose 202
|
|
3600
|
+
* carries the pending takes and `quoted_generations` (10 for the pair);
|
|
3601
|
+
* PixelLab bills when the takes are made. Poll each take with `getMusic`.
|
|
3602
|
+
*/
|
|
3603
|
+
async createMusic(args) {
|
|
3604
|
+
const body = { style: args.style };
|
|
3605
|
+
if (args.instrumental !== void 0) body.instrumental = args.instrumental;
|
|
3606
|
+
if (args.lyrics) body.lyrics = args.lyrics;
|
|
3607
|
+
if (args.autoLyrics) body.auto_lyrics = true;
|
|
3608
|
+
if (args.about) body.about = args.about;
|
|
3609
|
+
if (args.lengthS != null) body.length_s = args.lengthS;
|
|
3610
|
+
if (args.bpm != null) body.bpm = args.bpm;
|
|
3611
|
+
if (args.voice) body.voice = args.voice;
|
|
3612
|
+
if (args.exclude) body.exclude = args.exclude;
|
|
3613
|
+
if (args.styleWeight != null) body.style_weight = args.styleWeight;
|
|
3614
|
+
if (args.name) body.name = args.name;
|
|
3615
|
+
if (args.restyleSongId) body.restyle_song_id = args.restyleSongId;
|
|
3616
|
+
return validateResponse(
|
|
3617
|
+
MusicSubmitSchema,
|
|
3618
|
+
await this.request("/music", { method: "POST", body: JSON.stringify(body) }),
|
|
3619
|
+
"music"
|
|
3620
|
+
);
|
|
3621
|
+
}
|
|
3622
|
+
/** `GET /music/{song_id}`: status, then a no-auth MP3 URL and, for a loop, its loop points. */
|
|
3623
|
+
async getMusic(songId) {
|
|
3624
|
+
return validateResponse(SongSchema, await this.request(`/music/${encodeURIComponent(songId)}`), "music/{song_id}");
|
|
3625
|
+
}
|
|
3626
|
+
/**
|
|
3627
|
+
* `POST /music/{song_id}/loop`: a finished instrumental song made again so
|
|
3628
|
+
* the part between its intro and ending repeats without a seam. Two new
|
|
3629
|
+
* takes, each a song with `loop_start_s` and `loop_end_s`; 4 generations.
|
|
3630
|
+
*/
|
|
3631
|
+
async loopMusic(songId) {
|
|
3632
|
+
return validateResponse(
|
|
3633
|
+
MusicSubmitSchema,
|
|
3634
|
+
await this.request(`/music/${encodeURIComponent(songId)}/loop`, { method: "POST", body: "{}" }),
|
|
3635
|
+
"music/{song_id}/loop"
|
|
3636
|
+
);
|
|
3637
|
+
}
|
|
3638
|
+
/** `POST /music/improve-style`: a short idea written out as a full style for `createMusic`. Synchronous. */
|
|
3639
|
+
async improveMusicStyle(args) {
|
|
3640
|
+
const body = { style: args.style };
|
|
3641
|
+
if (args.instrumental !== void 0) body.instrumental = args.instrumental;
|
|
3642
|
+
if (args.bpm != null) body.bpm = args.bpm;
|
|
3643
|
+
const res = validateResponse(
|
|
3644
|
+
ImproveStyleSchema,
|
|
3645
|
+
await this.request("/music/improve-style", { method: "POST", body: JSON.stringify(body) }),
|
|
3646
|
+
"music/improve-style"
|
|
3647
|
+
);
|
|
3648
|
+
return { style: res.style, usage: res.usage };
|
|
3649
|
+
}
|
|
3650
|
+
/** `POST /music/lyrics`: two lyric drafts with section tags, for `createMusic`'s `lyrics`. Synchronous. */
|
|
3651
|
+
async writeMusicLyrics(topic) {
|
|
3652
|
+
const res = validateResponse(
|
|
3653
|
+
WriteLyricsSchema,
|
|
3654
|
+
await this.request("/music/lyrics", { method: "POST", body: JSON.stringify({ topic }) }),
|
|
3655
|
+
"music/lyrics"
|
|
3656
|
+
);
|
|
3657
|
+
return { lyrics: res.lyrics, usage: res.usage };
|
|
3658
|
+
}
|
|
3659
|
+
/**
|
|
3660
|
+
* `POST /sound-effects`: one clip (WAV) from a description, 0.5 to 30
|
|
3661
|
+
* seconds. A background job whose 202 carries the pending clip and
|
|
3662
|
+
* `quoted_generations`, priced by length; billed when the clip is made.
|
|
3663
|
+
*/
|
|
3664
|
+
async createSoundEffect(args) {
|
|
3665
|
+
const body = { prompt: args.prompt };
|
|
3666
|
+
if (args.seconds != null) body.seconds = args.seconds;
|
|
3667
|
+
if (args.name) body.name = args.name;
|
|
3668
|
+
return validateResponse(
|
|
3669
|
+
SoundEffectSubmitSchema,
|
|
3670
|
+
await this.request("/sound-effects", { method: "POST", body: JSON.stringify(body) }),
|
|
3671
|
+
"sound-effects"
|
|
3672
|
+
);
|
|
3673
|
+
}
|
|
3674
|
+
/** `GET /sound-effects/{id}`: status, then a no-auth WAV URL once completed. */
|
|
3675
|
+
async getSoundEffect(id) {
|
|
3676
|
+
return validateResponse(
|
|
3677
|
+
SoundEffectSchema,
|
|
3678
|
+
await this.request(`/sound-effects/${encodeURIComponent(id)}`),
|
|
3679
|
+
"sound-effects/{id}"
|
|
3680
|
+
);
|
|
3681
|
+
}
|
|
3682
|
+
/**
|
|
3683
|
+
* `POST /image-to-pixelart-pro`: the strongest of the three converters. Like
|
|
3684
|
+
* Pro Flash the output size is picked from the picture; 20 generations at
|
|
3685
|
+
* any source size. A plain background job.
|
|
3686
|
+
*/
|
|
3687
|
+
async imageToPixelartPro(args) {
|
|
3688
|
+
const body = { image: args.image };
|
|
3689
|
+
if (args.description) body.description = args.description;
|
|
3690
|
+
if (args.seed != null) body.seed = args.seed;
|
|
3691
|
+
Object.assign(body, targetPaletteBody(args.targetPalette));
|
|
3692
|
+
return validateResponse(
|
|
3693
|
+
RevisionJobSubmitSchema,
|
|
3694
|
+
await this.request("/image-to-pixelart-pro", { method: "POST", body: JSON.stringify(body) }),
|
|
3695
|
+
"image-to-pixelart-pro"
|
|
3696
|
+
);
|
|
3697
|
+
}
|
|
3698
|
+
/**
|
|
3699
|
+
* `POST /{objects|characters}/{id}/canvas`: add or remove transparent margin
|
|
3700
|
+
* around every rotation. Never scales or crops; a size smaller than the art
|
|
3701
|
+
* is refused with the art's bounds. Free.
|
|
3702
|
+
*/
|
|
3703
|
+
async setCanvasSize(kind, id, size) {
|
|
3704
|
+
return validateResponse(
|
|
3705
|
+
CanvasChangeSchema,
|
|
3706
|
+
await this.request(`/${kind}s/${encodeURIComponent(id)}/canvas`, { method: "POST", body: JSON.stringify({ image_size: size }) }),
|
|
3707
|
+
`${kind}s/{id}/canvas`
|
|
3708
|
+
);
|
|
3709
|
+
}
|
|
3710
|
+
/** `POST /{objects|characters}/{id}/animations/{group}/mirror`: flip one direction of a loop into its missing opposite. Free. */
|
|
3711
|
+
async mirrorAnimation(kind, id, animationGroupId, sourceDirection) {
|
|
3712
|
+
return validateResponse(
|
|
3713
|
+
MirrorAnimationSchema,
|
|
3714
|
+
await this.request(
|
|
3715
|
+
`/${kind}s/${encodeURIComponent(id)}/animations/${encodeURIComponent(animationGroupId)}/mirror`,
|
|
3716
|
+
{ method: "POST", body: JSON.stringify({ source_direction: sourceDirection }) }
|
|
3717
|
+
),
|
|
3718
|
+
`${kind}s/{id}/animations/{group}/mirror`
|
|
3719
|
+
);
|
|
3720
|
+
}
|
|
3721
|
+
/** `POST /objects/import`: your own PNG (at most 256x256) as a completed 1-direction object. Stored exactly; free. */
|
|
3722
|
+
async importObject(args) {
|
|
3723
|
+
const body = { image: { type: "base64", base64: args.image.base64, format: args.image.format } };
|
|
3724
|
+
if (args.name) body.name = args.name;
|
|
3725
|
+
return validateResponse(
|
|
3726
|
+
ImportObjectSchema,
|
|
3727
|
+
await this.request("/objects/import", { method: "POST", body: JSON.stringify(body) }),
|
|
3728
|
+
"objects/import"
|
|
3729
|
+
);
|
|
3730
|
+
}
|
|
3731
|
+
/**
|
|
3732
|
+
* `POST /objects/{id}/expand-rotations`: draw the 7 missing directions of a
|
|
3733
|
+
* 1-direction object. The object then waits in `review-expansion` until
|
|
3734
|
+
* `acceptObjectExpansion` or `dismissObjectReview`. 10 to 25 generations.
|
|
3735
|
+
*/
|
|
3736
|
+
async expandObjectRotations(id, args) {
|
|
3737
|
+
const body = { existing_direction: args.existingDirection };
|
|
3738
|
+
if (args.description) body.description = args.description;
|
|
3739
|
+
return validateResponse(
|
|
3740
|
+
ExpandRotationsSchema,
|
|
3741
|
+
await this.request(`/objects/${encodeURIComponent(id)}/expand-rotations`, { method: "POST", body: JSON.stringify(body) }),
|
|
3742
|
+
"objects/{id}/expand-rotations"
|
|
3743
|
+
);
|
|
3744
|
+
}
|
|
3745
|
+
/** Keep a reviewed 8-direction expansion: `select-frames` with no indices. The object becomes 8-direction. */
|
|
3746
|
+
async acceptObjectExpansion(id) {
|
|
3747
|
+
return this.request(`/objects/${encodeURIComponent(id)}/select-frames`, { method: "POST", body: "{}" });
|
|
3748
|
+
}
|
|
3749
|
+
/** Discard a pending expansion (or a review pack); the object itself is kept as it was. */
|
|
3750
|
+
async dismissObjectReview(id) {
|
|
3751
|
+
return this.request(`/objects/${encodeURIComponent(id)}/dismiss-review`, { method: "POST", body: "{}" });
|
|
3752
|
+
}
|
|
3753
|
+
/**
|
|
3754
|
+
* `GET /{objects|characters}/{id}/{zip|spritesheet|aseprite|gif}`: the
|
|
3755
|
+
* website's exports as bytes. Answers 423 while the asset or one of its
|
|
3756
|
+
* animations is still generating.
|
|
3757
|
+
*/
|
|
3758
|
+
async exportAsset(kind, id, format, opts = {}) {
|
|
3759
|
+
const query = new URLSearchParams();
|
|
3760
|
+
if (opts.animationGroupId) query.set("animation_group_id", opts.animationGroupId);
|
|
3761
|
+
if (opts.direction) query.set("direction", opts.direction);
|
|
3762
|
+
const suffix = query.size ? `?${query}` : "";
|
|
3763
|
+
const pathname = `/${kind}s/${encodeURIComponent(id)}/${format}${suffix}`;
|
|
3764
|
+
const auth = this.apiKey.startsWith("Bearer ") ? this.apiKey : `Bearer ${this.apiKey}`;
|
|
3765
|
+
const res = await this.http(`${BASE}${pathname}`, { headers: { Authorization: auth } });
|
|
3766
|
+
if (!res.ok) {
|
|
3767
|
+
const text = await res.text();
|
|
3768
|
+
const hint = res.status === 423 ? "; the asset or one of its animations is still generating, try again shortly" : "";
|
|
3769
|
+
throw new PixelLabError(`GET ${pathname} \u2192 ${res.status}${hint}`, res.status, text);
|
|
3770
|
+
}
|
|
3771
|
+
const bytes = Buffer.from(await res.arrayBuffer());
|
|
3772
|
+
if (bytes.length > MAX_DOWNLOAD_BYTES) throw new Error(`export ${pathname} exceeds the ${MAX_DOWNLOAD_BYTES}-byte safety limit`);
|
|
3773
|
+
return bytes;
|
|
3774
|
+
}
|
|
3357
3775
|
/** `GET /generate-font-pro/{job_id}`: status, then no-auth atlas and `.ttf` URLs once completed. */
|
|
3358
3776
|
async getFontJob(jobId) {
|
|
3359
3777
|
const raw = await this.request(`/generate-font-pro/${encodeURIComponent(jobId)}`);
|
|
@@ -4117,10 +4535,10 @@ function normalizeHex(value) {
|
|
|
4117
4535
|
function sha256(data) {
|
|
4118
4536
|
return createHash("sha256").update(data).digest("hex");
|
|
4119
4537
|
}
|
|
4120
|
-
async function sha256File(
|
|
4538
|
+
async function sha256File(path46) {
|
|
4121
4539
|
return new Promise((resolve, reject) => {
|
|
4122
4540
|
const hash = createHash("sha256");
|
|
4123
|
-
const stream = createReadStream(
|
|
4541
|
+
const stream = createReadStream(path46);
|
|
4124
4542
|
stream.on("data", (chunk2) => hash.update(chunk2));
|
|
4125
4543
|
stream.on("error", reject);
|
|
4126
4544
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -4172,6 +4590,21 @@ function specHash(spec, styleImageHashes, providerOptionIdentity = spec.provider
|
|
|
4172
4590
|
terrainBoundarySeed: spec.terrainBoundarySeed,
|
|
4173
4591
|
terrainStepSlope: spec.terrainStepSlope,
|
|
4174
4592
|
terrainConnectDiagonals: spec.terrainConnectDiagonals,
|
|
4593
|
+
// Added after the fields above, each only when set, so no terrain entry
|
|
4594
|
+
// written before them changes hash. The walkable flags change no pixel
|
|
4595
|
+
// and are deliberately not here.
|
|
4596
|
+
terrainShapeSeed: spec.terrainShapeSeed,
|
|
4597
|
+
terrainSideWallThickness: spec.terrainSideWallThickness,
|
|
4598
|
+
terrainSideWallPlacement: spec.terrainSideWallPlacement,
|
|
4599
|
+
terrainEnhance: spec.terrainEnhance,
|
|
4600
|
+
terrainPlatformThickness: spec.terrainPlatformThickness,
|
|
4601
|
+
// Reference images enter as their bytes' hashes, never their paths.
|
|
4602
|
+
terrainReferences: spec.terrainReferences && Object.keys(spec.terrainReferences).length ? Object.fromEntries(
|
|
4603
|
+
["lower", "upper", "transition"].flatMap((side) => {
|
|
4604
|
+
const reference = spec.terrainReferences[side];
|
|
4605
|
+
return reference ? [[side, reference.sha256]] : [];
|
|
4606
|
+
})
|
|
4607
|
+
) : void 0,
|
|
4175
4608
|
// "top-down" is the default and draws the same set as leaving it out.
|
|
4176
4609
|
terrainOrientation: spec.terrainOrientation === "sidescroller" ? spec.terrainOrientation : void 0,
|
|
4177
4610
|
// Which set and which of its terrains, not that terrain's id: the id
|
|
@@ -5007,6 +5440,7 @@ async function generateFont(client2, opts) {
|
|
|
5007
5440
|
await sleep3(interval);
|
|
5008
5441
|
}
|
|
5009
5442
|
}
|
|
5443
|
+
var PIXELATE_PRO_COST_GENERATIONS = 20;
|
|
5010
5444
|
var PIXELATE_COST_GENERATIONS = 6;
|
|
5011
5445
|
var PIXELATE_MAX_SIDE = 2048;
|
|
5012
5446
|
function defaultPixelateOut(input) {
|
|
@@ -5024,11 +5458,16 @@ async function pixelateFile(client2, input, opts = {}) {
|
|
|
5024
5458
|
const sleep3 = opts.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
5025
5459
|
const interval = opts.intervalMs ?? 5e3;
|
|
5026
5460
|
const timeout = opts.timeoutMs ?? 10 * 6e4;
|
|
5027
|
-
const
|
|
5028
|
-
|
|
5461
|
+
const image = { base64: bytes.toString("base64"), format };
|
|
5462
|
+
if (!opts.pro && (opts.palette?.length || opts.maxColors != null)) {
|
|
5463
|
+
throw new Error("a palette or color cap needs the Pro converter; add --pro");
|
|
5464
|
+
}
|
|
5465
|
+
const submitted = opts.pro ? await client2.imageToPixelartPro({
|
|
5466
|
+
image,
|
|
5029
5467
|
description: opts.description,
|
|
5030
|
-
seed: opts.seed
|
|
5031
|
-
|
|
5468
|
+
seed: opts.seed,
|
|
5469
|
+
targetPalette: opts.palette?.length || opts.maxColors != null ? { ...opts.palette?.length ? { colors: opts.palette } : {}, ...opts.maxColors != null ? { maxColors: opts.maxColors } : {} } : void 0
|
|
5470
|
+
}) : await client2.imageToPixelartProFlash({ image, description: opts.description, seed: opts.seed });
|
|
5032
5471
|
const jobId = submitted.background_job_id;
|
|
5033
5472
|
const started = Date.now();
|
|
5034
5473
|
for (; ; ) {
|
|
@@ -5037,20 +5476,32 @@ async function pixelateFile(client2, input, opts = {}) {
|
|
|
5037
5476
|
if (job.status === "failed") throw new Error(`PixelLab pixelate job ${jobId} failed upstream`);
|
|
5038
5477
|
if (job.status === "completed") {
|
|
5039
5478
|
const images = job.last_response?.images;
|
|
5040
|
-
const first = Array.isArray(images) ? images[0] :
|
|
5479
|
+
const first = Array.isArray(images) ? images[0] : job.last_response?.image;
|
|
5041
5480
|
if (!first || typeof first.base64 !== "string" || !first.base64) {
|
|
5042
|
-
throw new Error(`PixelLab pixelate job ${jobId} completed without an image at last_response.images[0]`);
|
|
5481
|
+
throw new Error(`PixelLab pixelate job ${jobId} completed without an image at last_response.images[0] or last_response.image`);
|
|
5043
5482
|
}
|
|
5044
5483
|
const png = Buffer.from(first.base64, "base64");
|
|
5045
5484
|
const size = imageMetadata(png);
|
|
5046
5485
|
await mkdir2(path2.dirname(out), { recursive: true });
|
|
5047
5486
|
await writeFile2(out, png);
|
|
5487
|
+
const reduced = job.last_response?.quantized_image;
|
|
5488
|
+
const count = (value) => typeof value === "number" ? value : null;
|
|
5489
|
+
let quantized;
|
|
5490
|
+
if (reduced && typeof reduced.base64 === "string" && reduced.base64) {
|
|
5491
|
+
const quantizedOut = out.replace(/(\.png)?$/i, ".quantized.png");
|
|
5492
|
+
if (!existsSync2(quantizedOut) || opts.force) {
|
|
5493
|
+
await writeFile2(quantizedOut, Buffer.from(reduced.base64, "base64"));
|
|
5494
|
+
quantized = { out: quantizedOut, colors: count(job.last_response?.quantized_image_n_colors) };
|
|
5495
|
+
}
|
|
5496
|
+
}
|
|
5048
5497
|
return {
|
|
5049
5498
|
jobId,
|
|
5050
5499
|
out,
|
|
5051
5500
|
original: { width, height },
|
|
5052
5501
|
pixelated: { width: size?.width ?? Number(first.width), height: size?.height ?? Number(first.height) },
|
|
5053
|
-
imageId: submitted.image_id,
|
|
5502
|
+
...submitted.image_id ? { imageId: submitted.image_id } : {},
|
|
5503
|
+
...quantized ? { quantized } : {},
|
|
5504
|
+
...opts.pro ? { colors: count(job.last_response?.original_image_n_colors) } : {},
|
|
5054
5505
|
usage: job.usage ?? null
|
|
5055
5506
|
};
|
|
5056
5507
|
}
|
|
@@ -5739,6 +6190,23 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
5739
6190
|
if (spec.terrainTileSize === 64 && spec.terrainMode !== "pro") {
|
|
5740
6191
|
throw new Error('PixelLab terrain: a 64px tile needs terrainMode: "pro"');
|
|
5741
6192
|
}
|
|
6193
|
+
const standardOnly = {
|
|
6194
|
+
terrainShapeSeed: spec.terrainShapeSeed,
|
|
6195
|
+
terrainSideWallThickness: spec.terrainSideWallThickness,
|
|
6196
|
+
terrainSideWallPlacement: spec.terrainSideWallPlacement,
|
|
6197
|
+
terrainEnhance: spec.terrainEnhance
|
|
6198
|
+
};
|
|
6199
|
+
const proSet = Object.entries(standardOnly).filter(([, value]) => value != null).map(([field]) => field);
|
|
6200
|
+
if (pro && proSet.length) {
|
|
6201
|
+
throw new Error(`PixelLab terrain: ${proSet.join(", ")} shape a standard set; terrainMode: "pro" ignores them`);
|
|
6202
|
+
}
|
|
6203
|
+
if ((spec.terrainSideWallThickness != null || spec.terrainSideWallPlacement != null) && !(spec.terrainTransitionSize != null && spec.terrainTransitionSize > 0)) {
|
|
6204
|
+
throw new Error("PixelLab terrain: terrainSideWallThickness and terrainSideWallPlacement shape the wall, which needs a terrainTransitionSize above 0");
|
|
6205
|
+
}
|
|
6206
|
+
if (spec.terrainPlatformThickness != null) {
|
|
6207
|
+
throw new Error("PixelLab terrain: terrainPlatformThickness is a sidescroller control");
|
|
6208
|
+
}
|
|
6209
|
+
this.requireTerrainReferences(spec);
|
|
5742
6210
|
if (spec.terrainShapeStyle && spec.terrainTransitionSize != null && spec.terrainTransitionSize > 0.5) {
|
|
5743
6211
|
throw new Error(
|
|
5744
6212
|
"PixelLab terrain: terrainShapeStyle with terrainTransitionSize above 0.5 uses an extended 32-tile layout pixelkiln does not model; use 0, 0.25, or 0.5"
|
|
@@ -5757,7 +6225,6 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
5757
6225
|
*/
|
|
5758
6226
|
validateSidescrollerTerrain(spec) {
|
|
5759
6227
|
const topDownOnly = {
|
|
5760
|
-
terrainMode: spec.terrainMode,
|
|
5761
6228
|
terrainShapeStyle: spec.terrainShapeStyle,
|
|
5762
6229
|
terrainView: spec.terrainView,
|
|
5763
6230
|
terrainSpreadX: spec.terrainSpreadX,
|
|
@@ -5767,7 +6234,12 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
5767
6234
|
terrainBoundaryAmplitude: spec.terrainBoundaryAmplitude,
|
|
5768
6235
|
terrainBoundarySeed: spec.terrainBoundarySeed,
|
|
5769
6236
|
terrainStepSlope: spec.terrainStepSlope,
|
|
5770
|
-
terrainConnectDiagonals: spec.terrainConnectDiagonals
|
|
6237
|
+
terrainConnectDiagonals: spec.terrainConnectDiagonals,
|
|
6238
|
+
terrainShapeSeed: spec.terrainShapeSeed,
|
|
6239
|
+
terrainSideWallThickness: spec.terrainSideWallThickness,
|
|
6240
|
+
terrainSideWallPlacement: spec.terrainSideWallPlacement,
|
|
6241
|
+
terrainLowerWalkable: spec.terrainLowerWalkable,
|
|
6242
|
+
terrainUpperWalkable: spec.terrainUpperWalkable
|
|
5771
6243
|
};
|
|
5772
6244
|
const set = Object.entries(topDownOnly).filter(([, value]) => value != null).map(([field]) => field);
|
|
5773
6245
|
if (set.length) {
|
|
@@ -5776,9 +6248,26 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
5776
6248
|
if (spec.terrainTileSize !== 16 && spec.terrainTileSize !== 32) {
|
|
5777
6249
|
throw new Error(`PixelLab terrain: a sidescroller set's tiles are 16 or 32px, got ${spec.terrainTileSize}`);
|
|
5778
6250
|
}
|
|
5779
|
-
if (spec.terrainTransitionSize != null && ![0, 0.25, 0.5
|
|
5780
|
-
throw new Error("PixelLab terrain: a sidescroller set's terrainTransitionSize must be 0, 0.25, 0.5
|
|
6251
|
+
if (spec.terrainTransitionSize != null && ![0, 0.25, 0.5].includes(spec.terrainTransitionSize)) {
|
|
6252
|
+
throw new Error("PixelLab terrain: a sidescroller set's terrainTransitionSize must be 0, 0.25, or 0.5 (the top layer stops at half a tile)");
|
|
6253
|
+
}
|
|
6254
|
+
const pro = spec.terrainMode === "pro";
|
|
6255
|
+
if (pro && (spec.terrainEnhance != null || spec.terrainPlatformThickness != null)) {
|
|
6256
|
+
throw new Error('PixelLab terrain: terrainEnhance and terrainPlatformThickness shape a standard sidescroller set; terrainMode: "pro" ignores them');
|
|
6257
|
+
}
|
|
6258
|
+
if (spec.terrainConnect?.lower && !pro) {
|
|
6259
|
+
throw new Error(`PixelLab terrain: a sidescroller set connects to another set's platform only with terrainMode: "pro"`);
|
|
6260
|
+
}
|
|
6261
|
+
if (spec.terrainReferences?.upper) {
|
|
6262
|
+
throw new Error("PixelLab terrain: a sidescroller set's upper terrain is empty air; it takes no upper reference");
|
|
6263
|
+
}
|
|
6264
|
+
if (spec.terrainReferences?.lower && !pro) {
|
|
6265
|
+
throw new Error('PixelLab terrain: a sidescroller set keeps a lower (platform body) reference only with terrainMode: "pro"');
|
|
6266
|
+
}
|
|
6267
|
+
if (spec.terrainReferences?.transition && pro) {
|
|
6268
|
+
throw new Error('PixelLab terrain: a sidescroller set textures its top layer from a transition reference only on standard mode; drop it or terrainMode: "pro"');
|
|
5781
6269
|
}
|
|
6270
|
+
this.requireTerrainReferences(spec, spec.terrainTileSize);
|
|
5782
6271
|
if (spec.terrainConnect?.upper) {
|
|
5783
6272
|
throw new Error(
|
|
5784
6273
|
"PixelLab terrain: a sidescroller set's upper terrain is empty air; only its lower (platform) terrain can connect"
|
|
@@ -5791,6 +6280,19 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
5791
6280
|
);
|
|
5792
6281
|
}
|
|
5793
6282
|
}
|
|
6283
|
+
/** Reference files must exist; a sidescroller's must be a square PNG of the tile size. */
|
|
6284
|
+
requireTerrainReferences(spec, tileSize) {
|
|
6285
|
+
for (const [side, reference] of Object.entries(spec.terrainReferences ?? {})) {
|
|
6286
|
+
if (!reference?.sha256) {
|
|
6287
|
+
throw new Error(`PixelLab terrain: the ${side} reference is missing or not a PNG: ${reference?.file}`);
|
|
6288
|
+
}
|
|
6289
|
+
if (tileSize != null && (reference.width !== tileSize || reference.height !== tileSize)) {
|
|
6290
|
+
throw new Error(
|
|
6291
|
+
`PixelLab terrain: a sidescroller set's ${side} reference must be a ${tileSize}x${tileSize} PNG; ${reference.file} is ${reference.width}x${reference.height}`
|
|
6292
|
+
);
|
|
6293
|
+
}
|
|
6294
|
+
}
|
|
6295
|
+
}
|
|
5794
6296
|
validateCharacter(spec, styleImages = []) {
|
|
5795
6297
|
const character = spec.character;
|
|
5796
6298
|
if (!character) throw new Error(`${spec.styleId}/${spec.assetId} has no character shape`);
|
|
@@ -6568,7 +7070,12 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
6568
7070
|
outline: spec.outline,
|
|
6569
7071
|
shading: spec.shading,
|
|
6570
7072
|
detail: spec.detail,
|
|
6571
|
-
seed: spec.seed
|
|
7073
|
+
seed: spec.seed,
|
|
7074
|
+
mode: spec.terrainMode,
|
|
7075
|
+
enhance: spec.terrainEnhance,
|
|
7076
|
+
platformThickness: spec.terrainPlatformThickness,
|
|
7077
|
+
lowerReferenceImage: await terrainReferenceImage(spec, "lower"),
|
|
7078
|
+
transitionReferenceImage: await terrainReferenceImage(spec, "transition")
|
|
6572
7079
|
});
|
|
6573
7080
|
return {
|
|
6574
7081
|
jobId: res2.tileset_id,
|
|
@@ -6603,7 +7110,16 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
6603
7110
|
shading: spec.shading,
|
|
6604
7111
|
detail: spec.detail,
|
|
6605
7112
|
seed: spec.seed,
|
|
6606
|
-
targetPalette: targetPaletteFor(spec)
|
|
7113
|
+
targetPalette: targetPaletteFor(spec),
|
|
7114
|
+
shapeSeed: spec.terrainShapeSeed,
|
|
7115
|
+
sideWallThickness: spec.terrainSideWallThickness,
|
|
7116
|
+
sideWallPlacement: spec.terrainSideWallPlacement,
|
|
7117
|
+
enhance: spec.terrainEnhance,
|
|
7118
|
+
lowerWalkable: spec.terrainLowerWalkable,
|
|
7119
|
+
upperWalkable: spec.terrainUpperWalkable,
|
|
7120
|
+
lowerReferenceImage: await terrainReferenceImage(spec, "lower"),
|
|
7121
|
+
upperReferenceImage: await terrainReferenceImage(spec, "upper"),
|
|
7122
|
+
transitionReferenceImage: await terrainReferenceImage(spec, "transition")
|
|
6607
7123
|
});
|
|
6608
7124
|
return {
|
|
6609
7125
|
jobId: res2.tileset_id,
|
|
@@ -7561,8 +8077,8 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
7561
8077
|
const sources = [];
|
|
7562
8078
|
const terrainTiles = [];
|
|
7563
8079
|
for (const [index, tile] of tileset.tiles.entries()) {
|
|
7564
|
-
const
|
|
7565
|
-
const role = `tile-${String(index).padStart(2, "0")}-${
|
|
8080
|
+
const slug3 = tile.name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "tile";
|
|
8081
|
+
const role = `tile-${String(index).padStart(2, "0")}-${slug3}`;
|
|
7566
8082
|
const file = path3.join(_PixelLabProvider.cacheDir(), `${tilesetId}-${index}.png`);
|
|
7567
8083
|
writeFileSync(file, Buffer.from(tile.image.base64, "base64"));
|
|
7568
8084
|
sources.push({ url: `file://${file}`, role });
|
|
@@ -7782,6 +8298,16 @@ function sendsTargetPalette(spec) {
|
|
|
7782
8298
|
return false;
|
|
7783
8299
|
}
|
|
7784
8300
|
}
|
|
8301
|
+
async function terrainReferenceImage(spec, side) {
|
|
8302
|
+
const reference = spec.terrainReferences?.[side];
|
|
8303
|
+
if (!reference) return void 0;
|
|
8304
|
+
if (!existsSync3(reference.file)) throw new Error(`terrain ${side} reference is missing: ${reference.file}`);
|
|
8305
|
+
const bytes = readFileSync(reference.file);
|
|
8306
|
+
if (sha256(bytes) !== reference.sha256) {
|
|
8307
|
+
throw new Error(`terrain ${side} reference changed after the manifest was resolved: ${reference.file}; run the command again`);
|
|
8308
|
+
}
|
|
8309
|
+
return { base64: bytes.toString("base64"), format: "png" };
|
|
8310
|
+
}
|
|
7785
8311
|
function targetPaletteFor(spec) {
|
|
7786
8312
|
if (!sendsTargetPalette(spec)) return void 0;
|
|
7787
8313
|
if (!spec.palette.length && spec.maxColors == null) return void 0;
|
|
@@ -7955,9 +8481,9 @@ var RetroDiffusionClient = class {
|
|
|
7955
8481
|
if (!response.ok) throw new ProviderError("retrodiffusion", `Retro Diffusion download failed (${response.status})`, { status: response.status });
|
|
7956
8482
|
return Buffer.from(await response.arrayBuffer());
|
|
7957
8483
|
}
|
|
7958
|
-
async call(
|
|
8484
|
+
async call(path46, init = {}) {
|
|
7959
8485
|
if (!this.token) throw new Error("RD_API_KEY is not set");
|
|
7960
|
-
const response = await this.request(`${this.baseUrl}${
|
|
8486
|
+
const response = await this.request(`${this.baseUrl}${path46}`, {
|
|
7961
8487
|
...init,
|
|
7962
8488
|
headers: {
|
|
7963
8489
|
"Content-Type": "application/json",
|
|
@@ -11064,6 +11590,13 @@ async function resolveSpecs(loaded, filter) {
|
|
|
11064
11590
|
terrainBoundarySeed: generator === "terrain" ? style.terrainBoundarySeed : void 0,
|
|
11065
11591
|
terrainStepSlope: generator === "terrain" ? style.terrainStepSlope : void 0,
|
|
11066
11592
|
terrainConnectDiagonals: generator === "terrain" ? style.terrainConnectDiagonals : void 0,
|
|
11593
|
+
terrainShapeSeed: generator === "terrain" ? style.terrainShapeSeed : void 0,
|
|
11594
|
+
terrainSideWallThickness: generator === "terrain" ? style.terrainSideWallThickness : void 0,
|
|
11595
|
+
terrainSideWallPlacement: generator === "terrain" ? style.terrainSideWallPlacement : void 0,
|
|
11596
|
+
terrainEnhance: generator === "terrain" ? style.terrainEnhance : void 0,
|
|
11597
|
+
terrainPlatformThickness: generator === "terrain" ? style.terrainPlatformThickness : void 0,
|
|
11598
|
+
terrainLowerWalkable: generator === "terrain" ? style.terrainLowerWalkable : void 0,
|
|
11599
|
+
terrainUpperWalkable: generator === "terrain" ? style.terrainUpperWalkable : void 0,
|
|
11067
11600
|
terrainTransitionSize: generator === "terrain" ? style.terrainTransitionSize : void 0,
|
|
11068
11601
|
terrainView: generator === "terrain" ? style.terrainView : void 0,
|
|
11069
11602
|
terrainOrientation: generator === "terrain" ? style.terrainOrientation : void 0,
|
|
@@ -11496,6 +12029,20 @@ async function resolveSpecs(loaded, filter) {
|
|
|
11496
12029
|
}
|
|
11497
12030
|
resolved.terrainConnect = links;
|
|
11498
12031
|
}
|
|
12032
|
+
if (asset.terrainReferences) {
|
|
12033
|
+
if (resolved.generator !== "terrain") {
|
|
12034
|
+
throw new Error(`assets.${assetId}.terrainReferences: only a terrain set takes terrain references; style "${styleId}" uses "${resolved.generator}"`);
|
|
12035
|
+
}
|
|
12036
|
+
const references = {};
|
|
12037
|
+
for (const side of ["lower", "upper", "transition"]) {
|
|
12038
|
+
const relative = asset.terrainReferences[side];
|
|
12039
|
+
if (!relative) continue;
|
|
12040
|
+
const file = path8.resolve(root, relative);
|
|
12041
|
+
const image = await optionalRevisionImage(file, `terrain ${side} reference`, "png");
|
|
12042
|
+
references[side] = { file, sha256: image?.hash ?? null, width: image?.width ?? null, height: image?.height ?? null };
|
|
12043
|
+
}
|
|
12044
|
+
if (Object.keys(references).length) resolved.terrainReferences = references;
|
|
12045
|
+
}
|
|
11499
12046
|
if (asset.scene) resolved.scene = await resolveMapScene(root, styleId, assetId, resolved.generator, asset.scene, activeProvider);
|
|
11500
12047
|
resolved.specHash = specHash(
|
|
11501
12048
|
resolved,
|
|
@@ -14568,16 +15115,552 @@ function hex(c) {
|
|
|
14568
15115
|
return `#${[c.r, c.g, c.b].map((v) => v.toString(16).padStart(2, "0")).join("")}`;
|
|
14569
15116
|
}
|
|
14570
15117
|
|
|
14571
|
-
// src/
|
|
14572
|
-
import path21 from "path";
|
|
15118
|
+
// src/pixellab-audio.ts
|
|
14573
15119
|
import { existsSync as existsSync16 } from "fs";
|
|
14574
|
-
import {
|
|
15120
|
+
import { mkdir as mkdir7, writeFile as writeFile7 } from "fs/promises";
|
|
15121
|
+
import path21 from "path";
|
|
15122
|
+
var MUSIC_COST_GENERATIONS = 10;
|
|
15123
|
+
var MUSIC_LOOP_COST_GENERATIONS = 4;
|
|
15124
|
+
var MUSIC_LOOP_MIN_BODY_SECONDS = 36;
|
|
15125
|
+
var MUSIC_MIN_SECONDS = 10;
|
|
15126
|
+
var MUSIC_MAX_SECONDS = 360;
|
|
15127
|
+
var MUSIC_MIN_BPM = 60;
|
|
15128
|
+
var MUSIC_MAX_BPM = 180;
|
|
15129
|
+
var SFX_MIN_SECONDS = 0.5;
|
|
15130
|
+
var SFX_MAX_SECONDS = 30;
|
|
15131
|
+
function soundEffectCost(seconds) {
|
|
15132
|
+
return Math.max(1, Math.ceil(0.614 * seconds - 1e-9));
|
|
15133
|
+
}
|
|
15134
|
+
function detectAudioFormat(bytes) {
|
|
15135
|
+
if (bytes.length >= 12 && bytes.subarray(0, 4).toString("ascii") === "RIFF" && bytes.subarray(8, 12).toString("ascii") === "WAVE") {
|
|
15136
|
+
return "wav";
|
|
15137
|
+
}
|
|
15138
|
+
if (bytes.length >= 3 && bytes.subarray(0, 3).toString("ascii") === "ID3") return "mp3";
|
|
15139
|
+
if (bytes.length >= 2 && bytes[0] === 255 && (bytes[1] & 224) === 224) return "mp3";
|
|
15140
|
+
return null;
|
|
15141
|
+
}
|
|
15142
|
+
function validateAudio(bytes, expected) {
|
|
15143
|
+
const actual = detectAudioFormat(bytes);
|
|
15144
|
+
if (actual !== expected) {
|
|
15145
|
+
throw new Error(`PixelLab returned ${actual ?? `${bytes.length} bytes that are not audio`}, expected ${expected}`);
|
|
15146
|
+
}
|
|
15147
|
+
}
|
|
15148
|
+
async function waitFor(what, read, opts, defaults) {
|
|
15149
|
+
const sleep3 = opts.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
15150
|
+
const interval = opts.intervalMs ?? defaults.intervalMs;
|
|
15151
|
+
const timeout = opts.timeoutMs ?? defaults.timeoutMs;
|
|
15152
|
+
const started = Date.now();
|
|
15153
|
+
for (; ; ) {
|
|
15154
|
+
const item = await read();
|
|
15155
|
+
opts.onProgress?.(item.status);
|
|
15156
|
+
if (item.status === "failed") throw new Error(`PixelLab ${what} failed upstream${item.error ? `: ${item.error}` : ""}`);
|
|
15157
|
+
if (item.status === "completed") return item;
|
|
15158
|
+
if (Date.now() - started > timeout) {
|
|
15159
|
+
throw new Error(
|
|
15160
|
+
`PixelLab ${what} is still ${item.status} after ${Math.round(timeout / 1e3)} s; it keeps running upstream and stays in your PixelLab library, but this command has stopped waiting`
|
|
15161
|
+
);
|
|
15162
|
+
}
|
|
15163
|
+
await sleep3(interval);
|
|
15164
|
+
}
|
|
15165
|
+
}
|
|
15166
|
+
function refusalDetail(error) {
|
|
15167
|
+
const body = error?.body;
|
|
15168
|
+
if (typeof body !== "string" || !body) return null;
|
|
15169
|
+
try {
|
|
15170
|
+
const detail = JSON.parse(body).detail;
|
|
15171
|
+
return typeof detail === "string" ? detail : null;
|
|
15172
|
+
} catch {
|
|
15173
|
+
return null;
|
|
15174
|
+
}
|
|
15175
|
+
}
|
|
15176
|
+
async function billedUsage(client2, jobId) {
|
|
15177
|
+
try {
|
|
15178
|
+
return (await client2.getBackgroundJob(jobId)).usage ?? null;
|
|
15179
|
+
} catch {
|
|
15180
|
+
return null;
|
|
15181
|
+
}
|
|
15182
|
+
}
|
|
15183
|
+
function musicOutputPaths(out) {
|
|
15184
|
+
const base = path21.resolve(out.replace(/\.(music\.json|mp3)$/i, ""));
|
|
15185
|
+
return {
|
|
15186
|
+
takes: [`${base}.mp3`, `${base}.take2.mp3`],
|
|
15187
|
+
loops: [`${base}.loop.mp3`, `${base}.loop.take2.mp3`],
|
|
15188
|
+
record: `${base}.music.json`
|
|
15189
|
+
};
|
|
15190
|
+
}
|
|
15191
|
+
function musicCost(opts) {
|
|
15192
|
+
if (opts.loopOf) return MUSIC_LOOP_COST_GENERATIONS;
|
|
15193
|
+
return MUSIC_COST_GENERATIONS + (opts.loop ? MUSIC_LOOP_COST_GENERATIONS : 0);
|
|
15194
|
+
}
|
|
15195
|
+
async function collectTakes(client2, songs, files, what, opts) {
|
|
15196
|
+
const takes = [];
|
|
15197
|
+
const finished = [];
|
|
15198
|
+
const ordered = [...songs].sort((a, b) => a.take - b.take);
|
|
15199
|
+
for (const [index, pending] of ordered.entries()) {
|
|
15200
|
+
const file = files[index];
|
|
15201
|
+
if (!file) break;
|
|
15202
|
+
const song = await waitFor(`${what} ${pending.id}`, () => client2.getMusic(pending.id), opts, { intervalMs: 1e4, timeoutMs: 6 * 6e4 });
|
|
15203
|
+
if (!song.audio_url) throw new Error(`PixelLab ${what} ${song.id} completed without an audio URL`);
|
|
15204
|
+
const bytes = await client2.download(song.audio_url);
|
|
15205
|
+
validateAudio(bytes, "mp3");
|
|
15206
|
+
await mkdir7(path21.dirname(file), { recursive: true });
|
|
15207
|
+
await writeFile7(file, bytes);
|
|
15208
|
+
finished.push(song);
|
|
15209
|
+
takes.push({
|
|
15210
|
+
songId: song.id,
|
|
15211
|
+
take: song.take,
|
|
15212
|
+
file,
|
|
15213
|
+
sha256: sha256(bytes),
|
|
15214
|
+
durationMs: song.duration_ms ?? null,
|
|
15215
|
+
...song.loop_start_s != null ? { loopStartS: song.loop_start_s } : {},
|
|
15216
|
+
...song.loop_end_s != null ? { loopEndS: song.loop_end_s } : {}
|
|
15217
|
+
});
|
|
15218
|
+
}
|
|
15219
|
+
return { takes, finished };
|
|
15220
|
+
}
|
|
15221
|
+
async function generateMusic(client2, opts) {
|
|
15222
|
+
const paths = musicOutputPaths(opts.out);
|
|
15223
|
+
const instrumental = !(opts.lyrics || opts.autoLyrics);
|
|
15224
|
+
const wantsLoop = Boolean(opts.loop || opts.loopOf);
|
|
15225
|
+
if (!opts.loopOf && !opts.style) throw new Error("music needs a style description");
|
|
15226
|
+
if (wantsLoop && !opts.loopOf && !instrumental) throw new Error("PixelLab loops instrumental songs only; drop the lyrics or the loop");
|
|
15227
|
+
if (opts.loop && opts.lengthS != null && opts.lengthS <= MUSIC_LOOP_MIN_BODY_SECONDS) {
|
|
15228
|
+
throw new Error(
|
|
15229
|
+
`a loop needs at least ${MUSIC_LOOP_MIN_BODY_SECONDS} s of music between the intro and the ending, so a ${opts.lengthS} s song cannot be looped; ask for a longer song (60 s or more is safe) or leave the length to PixelLab`
|
|
15230
|
+
);
|
|
15231
|
+
}
|
|
15232
|
+
const writes = [paths.record, ...opts.loopOf ? [] : paths.takes, ...wantsLoop ? paths.loops : []];
|
|
15233
|
+
if (!opts.force) {
|
|
15234
|
+
for (const file of writes) if (existsSync16(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
15235
|
+
}
|
|
15236
|
+
const usage = [];
|
|
15237
|
+
let quoted = null;
|
|
15238
|
+
let takes = [];
|
|
15239
|
+
let source;
|
|
15240
|
+
if (!opts.loopOf) {
|
|
15241
|
+
const submitted = await client2.createMusic({
|
|
15242
|
+
style: opts.style,
|
|
15243
|
+
instrumental,
|
|
15244
|
+
lyrics: opts.lyrics,
|
|
15245
|
+
autoLyrics: opts.autoLyrics,
|
|
15246
|
+
about: opts.about,
|
|
15247
|
+
lengthS: opts.lengthS,
|
|
15248
|
+
bpm: opts.bpm,
|
|
15249
|
+
voice: opts.voice,
|
|
15250
|
+
exclude: opts.exclude,
|
|
15251
|
+
styleWeight: opts.styleWeight,
|
|
15252
|
+
name: opts.name,
|
|
15253
|
+
restyleSongId: opts.restyleSongId
|
|
15254
|
+
});
|
|
15255
|
+
quoted = submitted.quoted_generations ?? null;
|
|
15256
|
+
const made = await collectTakes(client2, submitted.songs, paths.takes, "song", opts);
|
|
15257
|
+
takes = made.takes;
|
|
15258
|
+
source = made.finished[0];
|
|
15259
|
+
usage.push(await billedUsage(client2, submitted.background_job_id));
|
|
15260
|
+
}
|
|
15261
|
+
let loops = [];
|
|
15262
|
+
const snapshot = () => ({
|
|
15263
|
+
record: paths.record,
|
|
15264
|
+
takes,
|
|
15265
|
+
loops,
|
|
15266
|
+
style: source?.style ?? opts.style ?? "",
|
|
15267
|
+
instrumental: source?.instrumental ?? instrumental,
|
|
15268
|
+
lyrics: source?.lyrics ?? opts.lyrics ?? "",
|
|
15269
|
+
quotedGenerations: quoted,
|
|
15270
|
+
usage
|
|
15271
|
+
});
|
|
15272
|
+
const relative = (take) => ({ ...take, file: path21.basename(take.file) });
|
|
15273
|
+
const writeRecord = async (result2) => {
|
|
15274
|
+
await mkdir7(path21.dirname(paths.record), { recursive: true });
|
|
15275
|
+
await writeFile7(
|
|
15276
|
+
paths.record,
|
|
15277
|
+
JSON.stringify(
|
|
15278
|
+
{
|
|
15279
|
+
schema: "pixelkiln-music",
|
|
15280
|
+
version: 1,
|
|
15281
|
+
provider: "pixellab",
|
|
15282
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
15283
|
+
request: {
|
|
15284
|
+
...opts.style ? { style: opts.style } : {},
|
|
15285
|
+
...opts.bpm != null ? { bpm: opts.bpm } : {},
|
|
15286
|
+
...opts.lengthS != null ? { lengthS: opts.lengthS } : {},
|
|
15287
|
+
...opts.exclude ? { exclude: opts.exclude } : {},
|
|
15288
|
+
...opts.styleWeight != null ? { styleWeight: opts.styleWeight } : {},
|
|
15289
|
+
...opts.voice ? { voice: opts.voice } : {},
|
|
15290
|
+
...opts.autoLyrics ? { autoLyrics: true, ...opts.about ? { about: opts.about } : {} } : {},
|
|
15291
|
+
...opts.restyleSongId ? { restyleSongId: opts.restyleSongId } : {},
|
|
15292
|
+
...opts.loopOf ? { loopOf: opts.loopOf } : {}
|
|
15293
|
+
},
|
|
15294
|
+
style: result2.style,
|
|
15295
|
+
instrumental: result2.instrumental,
|
|
15296
|
+
...result2.lyrics ? { lyrics: result2.lyrics } : {},
|
|
15297
|
+
takes: result2.takes.map(relative),
|
|
15298
|
+
loops: result2.loops.map(relative),
|
|
15299
|
+
quotedGenerations: result2.quotedGenerations,
|
|
15300
|
+
usage: result2.usage
|
|
15301
|
+
},
|
|
15302
|
+
null,
|
|
15303
|
+
2
|
|
15304
|
+
) + "\n"
|
|
15305
|
+
);
|
|
15306
|
+
};
|
|
15307
|
+
if (takes.length) await writeRecord(snapshot());
|
|
15308
|
+
if (wantsLoop) {
|
|
15309
|
+
const loopSource = opts.loopOf ?? source.id;
|
|
15310
|
+
let submitted;
|
|
15311
|
+
try {
|
|
15312
|
+
submitted = await client2.loopMusic(loopSource);
|
|
15313
|
+
} catch (error) {
|
|
15314
|
+
const detail = refusalDetail(error);
|
|
15315
|
+
const kept = takes.length ? ` The song's takes are saved (${path21.basename(paths.record)}); nothing was charged for the loop.` : "";
|
|
15316
|
+
throw new Error(`PixelLab refused to loop ${loopSource}: ${detail ?? (error instanceof Error ? error.message : String(error))}${kept}`, { cause: error });
|
|
15317
|
+
}
|
|
15318
|
+
quoted = (quoted ?? 0) + (submitted.quoted_generations ?? 0);
|
|
15319
|
+
const made = await collectTakes(client2, submitted.songs, paths.loops, "loop", opts);
|
|
15320
|
+
loops = made.takes;
|
|
15321
|
+
source ??= made.finished[0];
|
|
15322
|
+
usage.push(await billedUsage(client2, submitted.background_job_id));
|
|
15323
|
+
}
|
|
15324
|
+
const result = snapshot();
|
|
15325
|
+
await writeRecord(result);
|
|
15326
|
+
return result;
|
|
15327
|
+
}
|
|
15328
|
+
function soundEffectOutputPaths(out) {
|
|
15329
|
+
const base = path21.resolve(out.replace(/\.(sfx\.json|wav)$/i, ""));
|
|
15330
|
+
return { wav: `${base}.wav`, record: `${base}.sfx.json` };
|
|
15331
|
+
}
|
|
15332
|
+
async function generateSoundEffect(client2, opts) {
|
|
15333
|
+
const { wav, record } = soundEffectOutputPaths(opts.out);
|
|
15334
|
+
if (!opts.force) {
|
|
15335
|
+
for (const file of [wav, record]) if (existsSync16(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
15336
|
+
}
|
|
15337
|
+
const seconds = opts.seconds ?? 2;
|
|
15338
|
+
const submitted = await client2.createSoundEffect({ prompt: opts.prompt, seconds, name: opts.name });
|
|
15339
|
+
const id = submitted.sound_effect.id;
|
|
15340
|
+
const clip = await waitFor(`sound effect ${id}`, () => client2.getSoundEffect(id), opts, { intervalMs: 4e3, timeoutMs: 4 * 6e4 });
|
|
15341
|
+
if (!clip.audio_url) throw new Error(`PixelLab sound effect ${id} completed without an audio URL`);
|
|
15342
|
+
const bytes = await client2.download(clip.audio_url);
|
|
15343
|
+
validateAudio(bytes, "wav");
|
|
15344
|
+
await mkdir7(path21.dirname(wav), { recursive: true });
|
|
15345
|
+
await writeFile7(wav, bytes);
|
|
15346
|
+
const result = {
|
|
15347
|
+
soundEffectId: id,
|
|
15348
|
+
file: wav,
|
|
15349
|
+
record,
|
|
15350
|
+
sha256: sha256(bytes),
|
|
15351
|
+
durationMs: clip.duration_ms ?? null,
|
|
15352
|
+
seconds,
|
|
15353
|
+
quotedGenerations: submitted.quoted_generations ?? null,
|
|
15354
|
+
usage: await billedUsage(client2, submitted.background_job_id)
|
|
15355
|
+
};
|
|
15356
|
+
await writeFile7(
|
|
15357
|
+
record,
|
|
15358
|
+
JSON.stringify(
|
|
15359
|
+
{
|
|
15360
|
+
schema: "pixelkiln-sfx",
|
|
15361
|
+
version: 1,
|
|
15362
|
+
provider: "pixellab",
|
|
15363
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
15364
|
+
prompt: opts.prompt,
|
|
15365
|
+
seconds,
|
|
15366
|
+
soundEffectId: id,
|
|
15367
|
+
file: path21.basename(wav),
|
|
15368
|
+
sha256: result.sha256,
|
|
15369
|
+
durationMs: result.durationMs,
|
|
15370
|
+
quotedGenerations: result.quotedGenerations,
|
|
15371
|
+
usage: result.usage
|
|
15372
|
+
},
|
|
15373
|
+
null,
|
|
15374
|
+
2
|
|
15375
|
+
) + "\n"
|
|
15376
|
+
);
|
|
15377
|
+
return result;
|
|
15378
|
+
}
|
|
15379
|
+
|
|
15380
|
+
// src/pixellab-ui.ts
|
|
15381
|
+
import { existsSync as existsSync17 } from "fs";
|
|
15382
|
+
import { mkdir as mkdir8, writeFile as writeFile8 } from "fs/promises";
|
|
15383
|
+
import path22 from "path";
|
|
15384
|
+
var UI_STATES_COSTS = [10, 15, 25];
|
|
15385
|
+
var UI_STATES_MAX_COST = 25;
|
|
15386
|
+
var UI_STATES_MAX_ELEMENTS = 64;
|
|
15387
|
+
var UI_STATES_MAX_STATES = 16;
|
|
15388
|
+
function parseUiState(text) {
|
|
15389
|
+
const at = text.indexOf("=");
|
|
15390
|
+
const name = at < 0 ? "" : text.slice(0, at).trim();
|
|
15391
|
+
const description = at < 0 ? "" : text.slice(at + 1).trim();
|
|
15392
|
+
if (!name || !description) {
|
|
15393
|
+
throw new Error(`a state is written "name=description", e.g. "pressed=pushed in: darker, face 1 px lower"; got "${text}"`);
|
|
15394
|
+
}
|
|
15395
|
+
return { name, description };
|
|
15396
|
+
}
|
|
15397
|
+
function parseUiBox(text) {
|
|
15398
|
+
const colon = text.lastIndexOf(":");
|
|
15399
|
+
const label = colon < 0 ? "" : text.slice(0, colon).trim();
|
|
15400
|
+
const numbers = (colon < 0 ? text : text.slice(colon + 1)).split(",").map((part) => Number(part.trim()));
|
|
15401
|
+
if (numbers.length !== 4 || numbers.some((n) => !Number.isInteger(n) || n < 0) || numbers[2] < 1 || numbers[3] < 1) {
|
|
15402
|
+
throw new Error(`a box is written "label:x,y,width,height" in template pixels, e.g. "Play:40,30,120,40"; got "${text}"`);
|
|
15403
|
+
}
|
|
15404
|
+
const [x, y, width, height] = numbers;
|
|
15405
|
+
return { ...label ? { label } : {}, x, y, width, height };
|
|
15406
|
+
}
|
|
15407
|
+
function parseUiInsets(text) {
|
|
15408
|
+
const numbers = text.split(",").map((part) => Number(part.trim()));
|
|
15409
|
+
if (numbers.length !== 1 && numbers.length !== 4 || numbers.some((n) => !Number.isInteger(n) || n < 0)) {
|
|
15410
|
+
throw new Error(`insets are one whole number for every side, or "left,right,top,bottom"; got "${text}"`);
|
|
15411
|
+
}
|
|
15412
|
+
const [left, right = left, top = left, bottom = left] = numbers;
|
|
15413
|
+
return { left, right, top, bottom };
|
|
15414
|
+
}
|
|
15415
|
+
function checkUiInsets(insets, size) {
|
|
15416
|
+
if (insets.left + insets.right >= size.width || insets.top + insets.bottom >= size.height) {
|
|
15417
|
+
throw new Error(
|
|
15418
|
+
`insets ${insets.left},${insets.right},${insets.top},${insets.bottom} leave no middle to stretch in a ${size.width}x${size.height} image; left + right must be below the width and top + bottom below the height`
|
|
15419
|
+
);
|
|
15420
|
+
}
|
|
15421
|
+
}
|
|
15422
|
+
function uiStateElements(asset, only) {
|
|
15423
|
+
if (asset.kind === "state") throw new Error(`${asset.id} is a state; states are made for an element or a split template`);
|
|
15424
|
+
if (asset.kind === "element") return [asset.id];
|
|
15425
|
+
if (!asset.elements.length) {
|
|
15426
|
+
throw new Error(`template ${asset.id} has not been split; run pixelkiln ui split --id ${asset.id} first (free)`);
|
|
15427
|
+
}
|
|
15428
|
+
const ids = asset.elements.map((element) => element.id);
|
|
15429
|
+
if (!only?.length) return ids;
|
|
15430
|
+
const unknown = only.filter((id) => !ids.includes(id));
|
|
15431
|
+
if (unknown.length) throw new Error(`not elements of template ${asset.id}: ${unknown.join(", ")}`);
|
|
15432
|
+
return only;
|
|
15433
|
+
}
|
|
15434
|
+
async function createUiStates(client2, opts) {
|
|
15435
|
+
if (!opts.states.length) throw new Error("ui states needs at least one state");
|
|
15436
|
+
if (opts.states.length > UI_STATES_MAX_STATES) throw new Error(`PixelLab takes at most ${UI_STATES_MAX_STATES} states per call`);
|
|
15437
|
+
const before = await client2.getUiAssetDetail(opts.uiAssetId);
|
|
15438
|
+
const elementIds = uiStateElements(before, opts.elementIds);
|
|
15439
|
+
if (elementIds.length > UI_STATES_MAX_ELEMENTS) throw new Error(`PixelLab takes at most ${UI_STATES_MAX_ELEMENTS} elements per call`);
|
|
15440
|
+
const submitted = await client2.createUiStates({ elementIds, states: opts.states, targetPalette: opts.targetPalette });
|
|
15441
|
+
opts.onQuote?.(submitted.generations, submitted.count);
|
|
15442
|
+
const sleep3 = opts.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
15443
|
+
const interval = opts.intervalMs ?? 8e3;
|
|
15444
|
+
const timeout = opts.timeoutMs ?? 8 * 6e4;
|
|
15445
|
+
const started = Date.now();
|
|
15446
|
+
for (; ; ) {
|
|
15447
|
+
const job = await client2.getBackgroundJob(submitted.background_job_id);
|
|
15448
|
+
opts.onProgress?.(job.status);
|
|
15449
|
+
if (job.status === "failed") throw new Error(`PixelLab UI states job ${submitted.background_job_id} failed upstream`);
|
|
15450
|
+
if (job.status === "completed") {
|
|
15451
|
+
return {
|
|
15452
|
+
jobId: submitted.background_job_id,
|
|
15453
|
+
elementIds,
|
|
15454
|
+
quotedGenerations: submitted.generations,
|
|
15455
|
+
count: submitted.count,
|
|
15456
|
+
usage: job.usage ?? null,
|
|
15457
|
+
asset: await client2.getUiAssetDetail(opts.uiAssetId)
|
|
15458
|
+
};
|
|
15459
|
+
}
|
|
15460
|
+
if (Date.now() - started > timeout) {
|
|
15461
|
+
throw new Error(
|
|
15462
|
+
`PixelLab UI states job ${submitted.background_job_id} is still ${job.status} after ${Math.round(timeout / 1e3)} s; it keeps running upstream, and pixelkiln ui show will list the states once they are saved`
|
|
15463
|
+
);
|
|
15464
|
+
}
|
|
15465
|
+
await sleep3(interval);
|
|
15466
|
+
}
|
|
15467
|
+
}
|
|
15468
|
+
function slug(text, fallback) {
|
|
15469
|
+
const cleaned = (text ?? "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
15470
|
+
return cleaned || fallback;
|
|
15471
|
+
}
|
|
15472
|
+
async function pullUiAsset(client2, uiAssetId, opts) {
|
|
15473
|
+
const asset = await client2.getUiAssetDetail(uiAssetId);
|
|
15474
|
+
if (asset.status && asset.status !== "completed") throw new Error(`UI asset ${uiAssetId} is ${asset.status}; pull it once it is completed`);
|
|
15475
|
+
if (!asset.image_url) throw new Error(`UI asset ${uiAssetId} has no image yet`);
|
|
15476
|
+
const dir = path22.resolve(opts.out);
|
|
15477
|
+
const record = path22.join(dir, "ui.json");
|
|
15478
|
+
const plan = [];
|
|
15479
|
+
const insets = (part) => part.nine_slice ? { nineSlice: { left: part.nine_slice.left, right: part.nine_slice.right, top: part.nine_slice.top, bottom: part.nine_slice.bottom } } : {};
|
|
15480
|
+
const taken = /* @__PURE__ */ new Set();
|
|
15481
|
+
const unique = (base) => {
|
|
15482
|
+
let name = base;
|
|
15483
|
+
for (let n = 2; taken.has(name); n++) name = `${base}-${n}`;
|
|
15484
|
+
taken.add(name);
|
|
15485
|
+
return name;
|
|
15486
|
+
};
|
|
15487
|
+
const kind = asset.kind ?? "template";
|
|
15488
|
+
const rootName = slug(asset.name, kind);
|
|
15489
|
+
plan.push({ id: asset.id, kind, name: rootName, file: `${rootName}.png`, size: asset.size, url: asset.image_url, ...insets(asset) });
|
|
15490
|
+
const addStates = (owner, ownerName, states) => {
|
|
15491
|
+
const stateNames = /* @__PURE__ */ new Set();
|
|
15492
|
+
for (const [i, state] of states.entries()) {
|
|
15493
|
+
let stateName = slug(state.name, `state-${i + 1}`);
|
|
15494
|
+
for (let n = 2; stateNames.has(stateName); n++) stateName = `${slug(state.name, `state-${i + 1}`)}-${n}`;
|
|
15495
|
+
stateNames.add(stateName);
|
|
15496
|
+
plan.push({
|
|
15497
|
+
id: state.id,
|
|
15498
|
+
kind: "state",
|
|
15499
|
+
name: `${ownerName}.${stateName}`,
|
|
15500
|
+
file: `elements/${ownerName}.${stateName}.png`,
|
|
15501
|
+
size: state.size,
|
|
15502
|
+
url: state.image_url,
|
|
15503
|
+
elementId: owner.id,
|
|
15504
|
+
...insets(state)
|
|
15505
|
+
});
|
|
15506
|
+
}
|
|
15507
|
+
};
|
|
15508
|
+
for (const [i, element] of asset.elements.entries()) {
|
|
15509
|
+
const name = unique(slug(element.name || element.template_box?.label, `element-${i + 1}`));
|
|
15510
|
+
const box = element.template_box;
|
|
15511
|
+
plan.push({
|
|
15512
|
+
id: element.id,
|
|
15513
|
+
kind: "element",
|
|
15514
|
+
name,
|
|
15515
|
+
file: `elements/${name}.png`,
|
|
15516
|
+
size: element.size,
|
|
15517
|
+
url: element.image_url,
|
|
15518
|
+
...box ? { box: { ...box.label ? { label: box.label } : {}, x: box.x, y: box.y, width: box.width, height: box.height } } : {},
|
|
15519
|
+
...insets(element)
|
|
15520
|
+
});
|
|
15521
|
+
addStates(element, name, element.states);
|
|
15522
|
+
}
|
|
15523
|
+
if (kind === "element") addStates(asset, rootName, asset.states);
|
|
15524
|
+
if (!opts.force) {
|
|
15525
|
+
for (const file of [record, ...plan.map((item) => path22.join(dir, item.file))]) {
|
|
15526
|
+
if (existsSync17(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
15527
|
+
}
|
|
15528
|
+
}
|
|
15529
|
+
const files = [];
|
|
15530
|
+
for (const { url, ...item } of plan) {
|
|
15531
|
+
const bytes = await client2.download(url);
|
|
15532
|
+
validateMedia(bytes, MediaType.PNG);
|
|
15533
|
+
const target = path22.join(dir, item.file);
|
|
15534
|
+
await mkdir8(path22.dirname(target), { recursive: true });
|
|
15535
|
+
await writeFile8(target, bytes);
|
|
15536
|
+
files.push({ ...item, sha256: sha256(bytes) });
|
|
15537
|
+
}
|
|
15538
|
+
await writeFile8(
|
|
15539
|
+
record,
|
|
15540
|
+
JSON.stringify(
|
|
15541
|
+
{
|
|
15542
|
+
schema: "pixelkiln-ui",
|
|
15543
|
+
version: 1,
|
|
15544
|
+
provider: "pixellab",
|
|
15545
|
+
pulledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
15546
|
+
uiAssetId: asset.id,
|
|
15547
|
+
kind,
|
|
15548
|
+
prompt: asset.prompt,
|
|
15549
|
+
files
|
|
15550
|
+
},
|
|
15551
|
+
null,
|
|
15552
|
+
2
|
|
15553
|
+
) + "\n"
|
|
15554
|
+
);
|
|
15555
|
+
return { dir, record, files };
|
|
15556
|
+
}
|
|
15557
|
+
|
|
15558
|
+
// src/pixellab-assets.ts
|
|
15559
|
+
import { existsSync as existsSync18 } from "fs";
|
|
15560
|
+
import { mkdir as mkdir9, readFile as readFile12, writeFile as writeFile9 } from "fs/promises";
|
|
15561
|
+
import path23 from "path";
|
|
15562
|
+
var ASSET_KINDS = ["object", "character"];
|
|
15563
|
+
var EXPORT_FORMATS = ["zip", "spritesheet", "aseprite", "gif"];
|
|
15564
|
+
var MIRROR_DIRECTIONS = ["east", "west", "south-east", "south-west", "north-east", "north-west"];
|
|
15565
|
+
var EXPAND_DIRECTIONS = ["south", "south-east", "east", "north-east", "north", "north-west", "west", "south-west"];
|
|
15566
|
+
var EXPAND_MIN_COST = 10;
|
|
15567
|
+
var EXPAND_MAX_COST = 25;
|
|
15568
|
+
var IMPORT_MAX_SIDE = 256;
|
|
15569
|
+
function parseCanvasSize(text, kind) {
|
|
15570
|
+
const match = /^(\d+)\s*x\s*(\d+)$/i.exec(text.trim());
|
|
15571
|
+
const max = kind === "object" ? 400 : 256;
|
|
15572
|
+
const width = Number(match?.[1]);
|
|
15573
|
+
const height = Number(match?.[2]);
|
|
15574
|
+
if (!match || [width, height].some((side) => side < 8 || side > max || side % 4 !== 0)) {
|
|
15575
|
+
throw new Error(`--size is <width>x<height> in multiples of 4, from 8 to ${max} for a ${kind}, e.g. 64x64; got "${text}"`);
|
|
15576
|
+
}
|
|
15577
|
+
return { width, height };
|
|
15578
|
+
}
|
|
15579
|
+
function exportOutPath(out, format) {
|
|
15580
|
+
const extension = format === "aseprite" ? ".aseprite" : format === "gif" ? ".gif" : ".zip";
|
|
15581
|
+
return path23.extname(out) ? path23.resolve(out) : path23.resolve(`${out}${extension}`);
|
|
15582
|
+
}
|
|
15583
|
+
function checkExportBytes(bytes, format) {
|
|
15584
|
+
const ok = format === "gif" ? bytes.subarray(0, 4).toString("ascii") === "GIF8" : format === "aseprite" ? bytes.length > 6 && bytes.readUInt16LE(4) === 42464 : bytes.subarray(0, 2).toString("ascii") === "PK";
|
|
15585
|
+
if (!ok) throw new Error(`PixelLab's ${format} export was not a ${format === "spritesheet" ? "ZIP" : format} file (${bytes.length} bytes)`);
|
|
15586
|
+
}
|
|
15587
|
+
async function exportAssetFile(client2, kind, id, format, opts) {
|
|
15588
|
+
const out = exportOutPath(opts.out, format);
|
|
15589
|
+
if (existsSync18(out) && !opts.force) throw new Error(`${out} already exists; pass --force to replace it`);
|
|
15590
|
+
const bytes = await client2.exportAsset(kind, id, format, { animationGroupId: opts.animationGroupId, direction: opts.direction });
|
|
15591
|
+
checkExportBytes(bytes, format);
|
|
15592
|
+
await mkdir9(path23.dirname(out), { recursive: true });
|
|
15593
|
+
await writeFile9(out, bytes);
|
|
15594
|
+
return { out, bytes: bytes.length };
|
|
15595
|
+
}
|
|
15596
|
+
async function importObjectFile(client2, file, opts = {}) {
|
|
15597
|
+
const bytes = await readFile12(file);
|
|
15598
|
+
const metadata = imageMetadata(bytes);
|
|
15599
|
+
if (!metadata || metadata.format !== "png") throw new Error(`${file} is not a PNG; PixelLab imports PNG only (JPEG compression would be stored as pixels)`);
|
|
15600
|
+
if (metadata.width > IMPORT_MAX_SIDE || metadata.height > IMPORT_MAX_SIDE) {
|
|
15601
|
+
throw new Error(`${file} is ${metadata.width}x${metadata.height}; PixelLab imports at most ${IMPORT_MAX_SIDE}x${IMPORT_MAX_SIDE}`);
|
|
15602
|
+
}
|
|
15603
|
+
const res = await client2.importObject({ image: { base64: bytes.toString("base64"), format: "png" }, name: opts.name });
|
|
15604
|
+
return { objectId: res.object_id, name: res.name ?? null, size: { width: res.size.width, height: res.size.height }, imageUrl: res.image_url };
|
|
15605
|
+
}
|
|
15606
|
+
async function expandObject(client2, id, opts) {
|
|
15607
|
+
const submitted = await client2.expandObjectRotations(id, { existingDirection: opts.existingDirection, description: opts.description });
|
|
15608
|
+
opts.onQuote?.(submitted.min_generations, submitted.max_generations);
|
|
15609
|
+
const sleep3 = opts.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
15610
|
+
const interval = opts.intervalMs ?? 1e4;
|
|
15611
|
+
const timeout = opts.timeoutMs ?? 10 * 6e4;
|
|
15612
|
+
const started = Date.now();
|
|
15613
|
+
for (; ; ) {
|
|
15614
|
+
const object = await client2.getObject(id);
|
|
15615
|
+
const status = object.status ?? "unknown";
|
|
15616
|
+
opts.onProgress?.(status);
|
|
15617
|
+
if (status === "failed") throw new Error(`PixelLab could not expand object ${id}`);
|
|
15618
|
+
if (status !== "expanding") {
|
|
15619
|
+
let usage = null;
|
|
15620
|
+
try {
|
|
15621
|
+
usage = (await client2.getBackgroundJob(submitted.background_job_id)).usage ?? null;
|
|
15622
|
+
} catch {
|
|
15623
|
+
usage = null;
|
|
15624
|
+
}
|
|
15625
|
+
return { objectId: id, jobId: submitted.background_job_id, minGenerations: submitted.min_generations, maxGenerations: submitted.max_generations, status, usage };
|
|
15626
|
+
}
|
|
15627
|
+
if (Date.now() - started > timeout) {
|
|
15628
|
+
throw new Error(`object ${id} is still expanding after ${Math.round(timeout / 1e3)} s; it keeps running upstream, and asset expand --keep or --discard finishes it later`);
|
|
15629
|
+
}
|
|
15630
|
+
await sleep3(interval);
|
|
15631
|
+
}
|
|
15632
|
+
}
|
|
15633
|
+
async function pullExpansionReview(client2, id, opts) {
|
|
15634
|
+
const object = await client2.getObject(id);
|
|
15635
|
+
const review = object.expansion_review;
|
|
15636
|
+
if (object.status !== "review-expansion" || !review?.rotation_urls) {
|
|
15637
|
+
throw new Error(`object ${id} is ${object.status ?? "unknown"}; there is no expansion waiting for review`);
|
|
15638
|
+
}
|
|
15639
|
+
const dir = path23.resolve(opts.out);
|
|
15640
|
+
const entries = Object.entries(review.rotation_urls).filter((entry) => typeof entry[1] === "string");
|
|
15641
|
+
const files = entries.map(([direction]) => ({ direction, file: path23.join(dir, `${direction}.png`) }));
|
|
15642
|
+
if (!opts.force) {
|
|
15643
|
+
for (const { file } of files) if (existsSync18(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
15644
|
+
}
|
|
15645
|
+
await mkdir9(dir, { recursive: true });
|
|
15646
|
+
for (const [index, [, url]] of entries.entries()) {
|
|
15647
|
+
const bytes = await client2.download(url);
|
|
15648
|
+
validateMedia(bytes, MediaType.PNG);
|
|
15649
|
+
await writeFile9(files[index].file, bytes);
|
|
15650
|
+
}
|
|
15651
|
+
return { dir, existingDirection: review.existing_direction ?? null, files };
|
|
15652
|
+
}
|
|
15653
|
+
|
|
15654
|
+
// src/pipeline/quality-regression.ts
|
|
15655
|
+
import path24 from "path";
|
|
15656
|
+
import { existsSync as existsSync19 } from "fs";
|
|
15657
|
+
import { readFile as readFile13 } from "fs/promises";
|
|
14575
15658
|
import { z as z5 } from "zod";
|
|
14576
15659
|
var SHA256_RE2 = /^[0-9a-f]{64}$/;
|
|
14577
15660
|
var HEX_RE = /^#[0-9a-f]{6}$/;
|
|
14578
15661
|
var MAX_REDMEAN_DISTANCE = 765;
|
|
14579
15662
|
var QualityPathSchema = z5.string().min(1).refine(
|
|
14580
|
-
(value) => !
|
|
15663
|
+
(value) => !path24.posix.isAbsolute(value) && !value.includes("\\"),
|
|
14581
15664
|
"expected a portable relative path"
|
|
14582
15665
|
);
|
|
14583
15666
|
var DEFAULT_QUALITY_TOLERANCES = {
|
|
@@ -14724,10 +15807,10 @@ function measureDecodedImageQuality(png, digest2) {
|
|
|
14724
15807
|
};
|
|
14725
15808
|
}
|
|
14726
15809
|
async function measureImageQuality(file) {
|
|
14727
|
-
const absolute =
|
|
15810
|
+
const absolute = path24.resolve(file);
|
|
14728
15811
|
let bytes;
|
|
14729
15812
|
try {
|
|
14730
|
-
bytes = await
|
|
15813
|
+
bytes = await readFile13(absolute);
|
|
14731
15814
|
} catch (error) {
|
|
14732
15815
|
throw new Error(`Cannot read quality image ${absolute}: ${message4(error)}`, { cause: error });
|
|
14733
15816
|
}
|
|
@@ -14746,11 +15829,11 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
14746
15829
|
}
|
|
14747
15830
|
const ids = parsed.data.map((entry) => entry.id);
|
|
14748
15831
|
if (new Set(ids).size !== ids.length) throw new Error("--inputs contains a duplicate quality case id.");
|
|
14749
|
-
const root =
|
|
15832
|
+
const root = path24.dirname(path24.resolve(inputsFilePath));
|
|
14750
15833
|
return parsed.data.map((entry) => ({
|
|
14751
15834
|
id: entry.id,
|
|
14752
|
-
file:
|
|
14753
|
-
...entry.record ? { record:
|
|
15835
|
+
file: path24.resolve(root, entry.path),
|
|
15836
|
+
...entry.record ? { record: path24.resolve(root, entry.record) } : {},
|
|
14754
15837
|
tolerances: QualityToleranceSchema.parse({
|
|
14755
15838
|
...DEFAULT_QUALITY_TOLERANCES,
|
|
14756
15839
|
...entry.tolerances
|
|
@@ -14758,7 +15841,7 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
14758
15841
|
}));
|
|
14759
15842
|
}
|
|
14760
15843
|
function portableRelative2(from, to) {
|
|
14761
|
-
return
|
|
15844
|
+
return path24.relative(from, path24.resolve(to)).split(path24.sep).join("/") || ".";
|
|
14762
15845
|
}
|
|
14763
15846
|
async function verifyRecordForImage(recordPath, imagePath) {
|
|
14764
15847
|
const verification = await verifyArtifactBundle(recordPath);
|
|
@@ -14773,20 +15856,20 @@ async function verifyRecordForImage(recordPath, imagePath) {
|
|
|
14773
15856
|
if (record.kind !== "refine" || options === null || typeof options !== "object" || options.schema !== "pixelkiln-quality") {
|
|
14774
15857
|
throw new Error(`Quality record ${recordPath} is not a PixelKiln refinement record.`);
|
|
14775
15858
|
}
|
|
14776
|
-
const outputs = record.outputs.map((output) =>
|
|
14777
|
-
if (!outputs.includes(
|
|
15859
|
+
const outputs = record.outputs.map((output) => path24.resolve(path24.dirname(recordPath), output.path));
|
|
15860
|
+
if (!outputs.includes(path24.resolve(imagePath))) {
|
|
14778
15861
|
throw new Error(`Quality record ${recordPath} does not own ${imagePath}.`);
|
|
14779
15862
|
}
|
|
14780
15863
|
}
|
|
14781
15864
|
async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
14782
15865
|
if (!inputs.length) throw new Error("Cannot snapshot an empty quality baseline.");
|
|
14783
|
-
const absolute =
|
|
15866
|
+
const absolute = path24.resolve(baselinePath);
|
|
14784
15867
|
for (const input of inputs) {
|
|
14785
|
-
if (
|
|
15868
|
+
if (path24.resolve(input.file) === absolute || input.record && path24.resolve(input.record) === absolute) {
|
|
14786
15869
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
14787
15870
|
}
|
|
14788
15871
|
}
|
|
14789
|
-
const root =
|
|
15872
|
+
const root = path24.dirname(absolute);
|
|
14790
15873
|
const cases = [];
|
|
14791
15874
|
for (const input of [...inputs].sort((a, b) => a.id.localeCompare(b.id))) {
|
|
14792
15875
|
const expected = await measureImageQuality(input.file);
|
|
@@ -14813,8 +15896,8 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
14813
15896
|
cases
|
|
14814
15897
|
});
|
|
14815
15898
|
const data = Buffer.from(JSON.stringify(baseline, null, 2) + "\n");
|
|
14816
|
-
if (
|
|
14817
|
-
const current = await
|
|
15899
|
+
if (existsSync19(absolute) && !options.force) {
|
|
15900
|
+
const current = await readFile13(absolute);
|
|
14818
15901
|
if (!current.equals(data)) {
|
|
14819
15902
|
throw new OverwriteRefusedError(
|
|
14820
15903
|
`Quality baseline already exists with different content: ${absolute}. Pass --force to replace it.`,
|
|
@@ -14826,13 +15909,13 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
14826
15909
|
return { baseline, path: absolute, changed: result.changed.length > 0 };
|
|
14827
15910
|
}
|
|
14828
15911
|
async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
14829
|
-
const absolute =
|
|
14830
|
-
if (!
|
|
15912
|
+
const absolute = path24.resolve(baselinePath);
|
|
15913
|
+
if (!existsSync19(absolute)) {
|
|
14831
15914
|
throw new Error(`quality snapshot --only updates an existing baseline; ${absolute} does not exist. Run a full snapshot first.`);
|
|
14832
15915
|
}
|
|
14833
15916
|
let raw;
|
|
14834
15917
|
try {
|
|
14835
|
-
raw = JSON.parse(await
|
|
15918
|
+
raw = JSON.parse(await readFile13(absolute, "utf8"));
|
|
14836
15919
|
} catch (error) {
|
|
14837
15920
|
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
14838
15921
|
}
|
|
@@ -14842,12 +15925,12 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
14842
15925
|
if (unknown.length) {
|
|
14843
15926
|
throw new Error(`--only names ${unknown.join(", ")}, which the quality inputs do not list. Known: ${[...byId.keys()].sort().join(", ")}`);
|
|
14844
15927
|
}
|
|
14845
|
-
const root =
|
|
15928
|
+
const root = path24.dirname(absolute);
|
|
14846
15929
|
const cases = [...raw.cases];
|
|
14847
15930
|
const report = [];
|
|
14848
15931
|
for (const id of only) {
|
|
14849
15932
|
const input = byId.get(id);
|
|
14850
|
-
if (
|
|
15933
|
+
if (path24.resolve(input.file) === absolute || input.record && path24.resolve(input.record) === absolute) {
|
|
14851
15934
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
14852
15935
|
}
|
|
14853
15936
|
const expected = await measureImageQuality(input.file);
|
|
@@ -14877,16 +15960,16 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
14877
15960
|
}
|
|
14878
15961
|
const baseline = QualityBaselineSchema.parse({ ...raw, cases });
|
|
14879
15962
|
const data = Buffer.from(JSON.stringify({ ...raw, cases }, null, 2) + "\n");
|
|
14880
|
-
const current = await
|
|
15963
|
+
const current = await readFile13(absolute);
|
|
14881
15964
|
const changed = !current.equals(data);
|
|
14882
15965
|
if (changed && !options.dryRun) await writeArtifactBundle([{ path: absolute, data }]);
|
|
14883
15966
|
return { baseline, path: absolute, changed, cases: report };
|
|
14884
15967
|
}
|
|
14885
15968
|
async function readQualityBaseline(baselinePath) {
|
|
14886
|
-
const absolute =
|
|
15969
|
+
const absolute = path24.resolve(baselinePath);
|
|
14887
15970
|
let raw;
|
|
14888
15971
|
try {
|
|
14889
|
-
raw = JSON.parse(await
|
|
15972
|
+
raw = JSON.parse(await readFile13(absolute, "utf8"));
|
|
14890
15973
|
} catch (error) {
|
|
14891
15974
|
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
14892
15975
|
}
|
|
@@ -14908,7 +15991,7 @@ async function readQualityBaseline(baselinePath) {
|
|
|
14908
15991
|
throw new Error(
|
|
14909
15992
|
`Invalid quality baseline ${absolute}:
|
|
14910
15993
|
` + parsed.error.issues.map((issue) => ` ${where(issue.path)}: ${issue.message}`).join("\n") + (missing.length ? `
|
|
14911
|
-
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${
|
|
15994
|
+
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${path24.basename(absolute)} --only ${missing.join(",")}\` rather than editing the JSON by hand.` : "")
|
|
14912
15995
|
);
|
|
14913
15996
|
}
|
|
14914
15997
|
return parsed.data;
|
|
@@ -14970,12 +16053,12 @@ function regressionViolations(expected, actual, tolerances) {
|
|
|
14970
16053
|
return { violations, warnings };
|
|
14971
16054
|
}
|
|
14972
16055
|
async function checkQualityBaseline(baselinePath) {
|
|
14973
|
-
const absolute =
|
|
16056
|
+
const absolute = path24.resolve(baselinePath);
|
|
14974
16057
|
const baseline = await readQualityBaseline(absolute);
|
|
14975
|
-
const root =
|
|
16058
|
+
const root = path24.dirname(absolute);
|
|
14976
16059
|
const cases = [];
|
|
14977
16060
|
for (const entry of baseline.cases) {
|
|
14978
|
-
const file =
|
|
16061
|
+
const file = path24.resolve(root, entry.file);
|
|
14979
16062
|
let actual = null;
|
|
14980
16063
|
const violations = [];
|
|
14981
16064
|
const warnings = [];
|
|
@@ -14988,7 +16071,7 @@ async function checkQualityBaseline(baselinePath) {
|
|
|
14988
16071
|
violations.push(message4(error));
|
|
14989
16072
|
}
|
|
14990
16073
|
if (entry.record) {
|
|
14991
|
-
const recordPath =
|
|
16074
|
+
const recordPath = path24.resolve(root, entry.record.path);
|
|
14992
16075
|
try {
|
|
14993
16076
|
const recordHash = await sha256File(recordPath);
|
|
14994
16077
|
if (recordHash !== entry.record.sha256) violations.push("quality record hash changed");
|
|
@@ -15024,13 +16107,13 @@ async function checkQualityBaseline(baselinePath) {
|
|
|
15024
16107
|
}
|
|
15025
16108
|
|
|
15026
16109
|
// src/pipeline/cache-health.ts
|
|
15027
|
-
import { existsSync as
|
|
15028
|
-
import { readFile as
|
|
15029
|
-
import
|
|
16110
|
+
import { existsSync as existsSync23 } from "fs";
|
|
16111
|
+
import { readFile as readFile16, readdir as readdir2, rm as rm6 } from "fs/promises";
|
|
16112
|
+
import path27 from "path";
|
|
15030
16113
|
|
|
15031
16114
|
// src/cache.ts
|
|
15032
|
-
import { mkdir as
|
|
15033
|
-
import { existsSync as
|
|
16115
|
+
import { mkdir as mkdir10, readFile as readFile14, rename as rename5, rm as rm4, writeFile as writeFile10 } from "fs/promises";
|
|
16116
|
+
import { existsSync as existsSync20 } from "fs";
|
|
15034
16117
|
import pathModule from "path";
|
|
15035
16118
|
import { z as z6 } from "zod";
|
|
15036
16119
|
var HashCacheSchema = z6.object({
|
|
@@ -15045,10 +16128,10 @@ function isSha256Hash(value) {
|
|
|
15045
16128
|
function parseCache(value) {
|
|
15046
16129
|
return HashCacheSchema.parse(value);
|
|
15047
16130
|
}
|
|
15048
|
-
async function loadCache(
|
|
15049
|
-
if (!
|
|
16131
|
+
async function loadCache(path46) {
|
|
16132
|
+
if (!existsSync20(path46)) return { version: 1, hashes: {} };
|
|
15050
16133
|
try {
|
|
15051
|
-
const parsed = HashCacheSchema.safeParse(JSON.parse(await
|
|
16134
|
+
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile14(path46, "utf8")));
|
|
15052
16135
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
15053
16136
|
return {
|
|
15054
16137
|
version: 1,
|
|
@@ -15060,18 +16143,18 @@ async function loadCache(path43) {
|
|
|
15060
16143
|
return { version: 1, hashes: {} };
|
|
15061
16144
|
}
|
|
15062
16145
|
}
|
|
15063
|
-
async function saveCache(
|
|
16146
|
+
async function saveCache(path46, cache) {
|
|
15064
16147
|
const sorted = {};
|
|
15065
16148
|
for (const key2 of Object.keys(cache.hashes).sort()) {
|
|
15066
16149
|
const hash = cache.hashes[key2];
|
|
15067
16150
|
if (!isSha256Hash(hash)) throw new Error(`Refusing to cache invalid SHA-256 for ${key2}`);
|
|
15068
16151
|
sorted[key2] = hash;
|
|
15069
16152
|
}
|
|
15070
|
-
await
|
|
15071
|
-
const tmp = `${
|
|
16153
|
+
await mkdir10(pathModule.dirname(pathModule.resolve(path46)), { recursive: true });
|
|
16154
|
+
const tmp = `${path46}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
15072
16155
|
try {
|
|
15073
|
-
await
|
|
15074
|
-
await rename5(tmp,
|
|
16156
|
+
await writeFile10(tmp, JSON.stringify({ version: 1, hashes: sorted }, null, 2) + "\n");
|
|
16157
|
+
await rename5(tmp, path46);
|
|
15075
16158
|
} finally {
|
|
15076
16159
|
await rm4(tmp, { force: true });
|
|
15077
16160
|
}
|
|
@@ -15095,20 +16178,20 @@ function cachePathFor(lockPath) {
|
|
|
15095
16178
|
}
|
|
15096
16179
|
|
|
15097
16180
|
// src/pipeline/history.ts
|
|
15098
|
-
import { existsSync as
|
|
15099
|
-
import
|
|
16181
|
+
import { existsSync as existsSync22 } from "fs";
|
|
16182
|
+
import path26 from "path";
|
|
15100
16183
|
|
|
15101
16184
|
// src/pipeline/fetch.ts
|
|
15102
|
-
import { existsSync as
|
|
15103
|
-
import { mkdir as
|
|
15104
|
-
import
|
|
16185
|
+
import { existsSync as existsSync21, readFileSync as readFileSync5 } from "fs";
|
|
16186
|
+
import { mkdir as mkdir11, readFile as readFile15, rename as rename6, rm as rm5, writeFile as writeFile11 } from "fs/promises";
|
|
16187
|
+
import path25 from "path";
|
|
15105
16188
|
async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
15106
16189
|
const log = opts.onProgress ?? (() => {
|
|
15107
16190
|
});
|
|
15108
16191
|
const result = { downloaded: 0, skipped: 0, failed: 0, ...opts.refresh ? { unchanged: 0 } : {} };
|
|
15109
16192
|
const specByKey = new Map(specs.map((s) => [lockKey(s.styleId, s.assetId), s]));
|
|
15110
16193
|
normalizeLockOutputPaths(lock, specs);
|
|
15111
|
-
const cacheDir = opts.cacheDir === false ? null :
|
|
16194
|
+
const cacheDir = opts.cacheDir === false ? null : path25.resolve(opts.cacheDir ?? path25.join(path25.dirname(lockPath), ".pixelkiln", "cache"));
|
|
15112
16195
|
const pending = Object.entries(lock.entries).filter(([key2, e]) => {
|
|
15113
16196
|
if (e.provider !== provider.id || !specByKey.has(key2)) return false;
|
|
15114
16197
|
if (specByKey.get(key2)?.mirror) return false;
|
|
@@ -15120,14 +16203,14 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
15120
16203
|
if (spec && e.specHash === spec.specHash && e.outputs.length && !postprocessCurrent(e, spec)) {
|
|
15121
16204
|
return Boolean(opts.force) || e.outputs.every((output) => {
|
|
15122
16205
|
const file = resolveOutputPath(output.path, spec.root);
|
|
15123
|
-
return
|
|
16206
|
+
return existsSync21(file) && sha256(readFileSync5(file)) === output.sha256;
|
|
15124
16207
|
});
|
|
15125
16208
|
}
|
|
15126
16209
|
if (!opts.repair) return false;
|
|
15127
16210
|
if (e.outputs.length === 0 || !spec) return true;
|
|
15128
16211
|
return e.outputs.some((output) => {
|
|
15129
16212
|
const file = resolveOutputPath(output.path, spec.root);
|
|
15130
|
-
if (!
|
|
16213
|
+
if (!existsSync21(file)) return true;
|
|
15131
16214
|
const current = sha256(readFileSync5(file));
|
|
15132
16215
|
if (current === output.sha256) return false;
|
|
15133
16216
|
return Boolean(opts.force) || (e.supersededOutputs ?? []).some((old) => old.sha256 === current);
|
|
@@ -15211,21 +16294,21 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
15211
16294
|
if (!source.url) throw new Error(`no durable source URL to refresh ${source.role ?? "asset"} from`);
|
|
15212
16295
|
fresh = await provider.download(source.url);
|
|
15213
16296
|
if (recorded && sha256(fresh) === recordedRaw && !reapply) {
|
|
15214
|
-
log(` current ${
|
|
16297
|
+
log(` current ${path25.relative(process.cwd(), target)}`);
|
|
15215
16298
|
outputs.push({ ...recorded, path: portableOutputPath(target, spec.root) });
|
|
15216
16299
|
continue;
|
|
15217
16300
|
}
|
|
15218
16301
|
}
|
|
15219
16302
|
let raw = null;
|
|
15220
16303
|
let final = null;
|
|
15221
|
-
if (
|
|
16304
|
+
if (existsSync21(target)) {
|
|
15222
16305
|
const currentHash = await sha256File(target);
|
|
15223
16306
|
if (recorded && currentHash === recorded.sha256) {
|
|
15224
16307
|
if (!fresh && !reapply) {
|
|
15225
16308
|
if (cacheDir) {
|
|
15226
16309
|
await cacheMedia(
|
|
15227
16310
|
cacheDir,
|
|
15228
|
-
await
|
|
16311
|
+
await readFile15(target),
|
|
15229
16312
|
recorded.mediaType ?? MediaType.PNG,
|
|
15230
16313
|
recorded.sha256
|
|
15231
16314
|
);
|
|
@@ -15234,10 +16317,10 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
15234
16317
|
continue;
|
|
15235
16318
|
}
|
|
15236
16319
|
if (reapply && !fresh) {
|
|
15237
|
-
if (!recorded.raw) raw = await
|
|
15238
|
-
log(` reapply ${
|
|
16320
|
+
if (!recorded.raw) raw = await readFile15(target);
|
|
16321
|
+
log(` reapply ${path25.relative(process.cwd(), target)}`);
|
|
15239
16322
|
} else {
|
|
15240
|
-
log(` changed ${
|
|
16323
|
+
log(` changed ${path25.relative(process.cwd(), target)} (upstream)`);
|
|
15241
16324
|
}
|
|
15242
16325
|
} else {
|
|
15243
16326
|
const superseded = (entry.supersededOutputs ?? []).find(
|
|
@@ -15258,14 +16341,14 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
15258
16341
|
}
|
|
15259
16342
|
if (outgoing && cacheDir) {
|
|
15260
16343
|
try {
|
|
15261
|
-
const oldBytes = await
|
|
16344
|
+
const oldBytes = await readFile15(target);
|
|
15262
16345
|
const oldMediaType = detectMediaType(oldBytes);
|
|
15263
16346
|
if (oldMediaType) await cacheMedia(cacheDir, oldBytes, oldMediaType, currentHash);
|
|
15264
16347
|
} catch {
|
|
15265
16348
|
}
|
|
15266
16349
|
}
|
|
15267
16350
|
log(
|
|
15268
|
-
` replace ${
|
|
16351
|
+
` replace ${path25.relative(process.cwd(), target)}` + (opts.force ? " (--force)" : " (previous tracked generation)")
|
|
15269
16352
|
);
|
|
15270
16353
|
}
|
|
15271
16354
|
}
|
|
@@ -15274,7 +16357,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
15274
16357
|
} else if (!raw && recorded && cacheDir) {
|
|
15275
16358
|
if (!reapply) final = await readCachedMedia(cacheDir, recorded.sha256, expectedMediaType);
|
|
15276
16359
|
if (!final && recordedRaw) raw = await readCachedMedia(cacheDir, recordedRaw, expectedMediaType);
|
|
15277
|
-
if (final || raw) log(` cached ${
|
|
16360
|
+
if (final || raw) log(` cached ${path25.relative(process.cwd(), target)}`);
|
|
15278
16361
|
}
|
|
15279
16362
|
if (!final && !raw) {
|
|
15280
16363
|
if (!source.url) {
|
|
@@ -15301,13 +16384,13 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
15301
16384
|
buf = processed.bytes;
|
|
15302
16385
|
if (processed.changed) {
|
|
15303
16386
|
rawHash = sha256(raw);
|
|
15304
|
-
log(` snapped ${
|
|
16387
|
+
log(` snapped ${path25.relative(process.cwd(), target)} to ${wanted.palette.colors.length} colours`);
|
|
15305
16388
|
}
|
|
15306
16389
|
}
|
|
15307
16390
|
if (cacheDir) await cacheMedia(cacheDir, buf, mediaType);
|
|
15308
|
-
await
|
|
16391
|
+
await mkdir11(path25.dirname(target), { recursive: true });
|
|
15309
16392
|
const tmp = `${target}.pixelkiln.tmp`;
|
|
15310
|
-
await
|
|
16393
|
+
await writeFile11(tmp, buf);
|
|
15311
16394
|
outputs.push({
|
|
15312
16395
|
path: portableOutputPath(target, spec.root),
|
|
15313
16396
|
sha256: sha256(buf),
|
|
@@ -15319,7 +16402,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
15319
16402
|
await saveLock(lockPath, lock);
|
|
15320
16403
|
await rename6(tmp, target);
|
|
15321
16404
|
wrote = true;
|
|
15322
|
-
log(` wrote ${
|
|
16405
|
+
log(` wrote ${path25.relative(process.cwd(), target)}`);
|
|
15323
16406
|
}
|
|
15324
16407
|
if (opts.refresh && !wrote) {
|
|
15325
16408
|
if (rotated) {
|
|
@@ -15363,10 +16446,10 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
15363
16446
|
return result;
|
|
15364
16447
|
}
|
|
15365
16448
|
async function readCachedMedia(cacheDir, hash, mediaType) {
|
|
15366
|
-
const file =
|
|
15367
|
-
if (!
|
|
16449
|
+
const file = path25.join(cacheDir, cacheFileName(hash, mediaType));
|
|
16450
|
+
if (!existsSync21(file)) return null;
|
|
15368
16451
|
try {
|
|
15369
|
-
const buf = await
|
|
16452
|
+
const buf = await readFile15(file);
|
|
15370
16453
|
if (sha256(buf) !== hash) return null;
|
|
15371
16454
|
validateMedia(buf, mediaType);
|
|
15372
16455
|
return buf;
|
|
@@ -15377,15 +16460,15 @@ async function readCachedMedia(cacheDir, hash, mediaType) {
|
|
|
15377
16460
|
async function cacheMedia(cacheDir, buf, mediaType, knownHash) {
|
|
15378
16461
|
const hash = knownHash ?? sha256(buf);
|
|
15379
16462
|
validateMedia(buf, mediaType);
|
|
15380
|
-
const file =
|
|
16463
|
+
const file = path25.join(cacheDir, cacheFileName(hash, mediaType));
|
|
15381
16464
|
if (await readCachedMedia(cacheDir, hash, mediaType)) return;
|
|
15382
|
-
await
|
|
16465
|
+
await mkdir11(cacheDir, { recursive: true });
|
|
15383
16466
|
const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
15384
|
-
await
|
|
16467
|
+
await writeFile11(tmp, buf);
|
|
15385
16468
|
try {
|
|
15386
16469
|
await rename6(tmp, file);
|
|
15387
16470
|
} catch (err) {
|
|
15388
|
-
if (!
|
|
16471
|
+
if (!existsSync21(file)) throw err;
|
|
15389
16472
|
} finally {
|
|
15390
16473
|
await rm5(tmp, { force: true });
|
|
15391
16474
|
}
|
|
@@ -15509,10 +16592,10 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
|
15509
16592
|
}
|
|
15510
16593
|
for (let i = 0; i < entry.outputs.length; i++) {
|
|
15511
16594
|
const file = currentEntryOutputPath(entry, spec, i);
|
|
15512
|
-
if (!
|
|
16595
|
+
if (!existsSync22(file)) continue;
|
|
15513
16596
|
if (await sha256File(file) !== entry.outputs[i].sha256 && !opts.force) {
|
|
15514
16597
|
throw new OverwriteRefusedError(
|
|
15515
|
-
`${
|
|
16598
|
+
`${path26.relative(process.cwd(), file)} was changed after download; keep it with pixelkiln edit, or pass --force to replace it`,
|
|
15516
16599
|
[file]
|
|
15517
16600
|
);
|
|
15518
16601
|
}
|
|
@@ -15576,11 +16659,11 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
|
15576
16659
|
|
|
15577
16660
|
// src/pipeline/cache-health.ts
|
|
15578
16661
|
async function inspectCaches(lock, lockPath, options = {}) {
|
|
15579
|
-
if (options.prune && !
|
|
15580
|
-
throw new Error(`Refusing to prune without an existing lockfile at ${
|
|
16662
|
+
if (options.prune && !existsSync23(lockPath)) {
|
|
16663
|
+
throw new Error(`Refusing to prune without an existing lockfile at ${path27.resolve(lockPath)}`);
|
|
15581
16664
|
}
|
|
15582
|
-
const contentDir =
|
|
15583
|
-
const remotePath =
|
|
16665
|
+
const contentDir = path27.resolve(path27.dirname(lockPath), ".pixelkiln", "cache");
|
|
16666
|
+
const remotePath = path27.resolve(cachePathFor(lockPath));
|
|
15584
16667
|
const referenced = referencedHashes(lock);
|
|
15585
16668
|
let content = await inspectContentCache(contentDir, referenced);
|
|
15586
16669
|
let remoteHashes = await inspectRemoteHashCache(remotePath);
|
|
@@ -15592,7 +16675,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
15592
16675
|
]);
|
|
15593
16676
|
for (const name of names) {
|
|
15594
16677
|
try {
|
|
15595
|
-
await rm6(
|
|
16678
|
+
await rm6(path27.join(contentDir, name), { force: true });
|
|
15596
16679
|
removed.contentFiles++;
|
|
15597
16680
|
} catch {
|
|
15598
16681
|
}
|
|
@@ -15601,7 +16684,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
15601
16684
|
await saveCache(remotePath, { version: 1, hashes: {} });
|
|
15602
16685
|
removed.resetRemoteHashCache = true;
|
|
15603
16686
|
} else if (remoteHashes.invalidIds.length) {
|
|
15604
|
-
const cache = parseCache(JSON.parse(await
|
|
16687
|
+
const cache = parseCache(JSON.parse(await readFile16(remotePath, "utf8")));
|
|
15605
16688
|
for (const id of remoteHashes.invalidIds) delete cache.hashes[id];
|
|
15606
16689
|
removed.remoteHashEntries = remoteHashes.invalidIds.length;
|
|
15607
16690
|
await saveCache(remotePath, cache);
|
|
@@ -15619,7 +16702,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
15619
16702
|
async function inspectContentCache(contentDir, referenced) {
|
|
15620
16703
|
const report = {
|
|
15621
16704
|
path: contentDir,
|
|
15622
|
-
exists:
|
|
16705
|
+
exists: existsSync23(contentDir),
|
|
15623
16706
|
files: 0,
|
|
15624
16707
|
bytes: 0,
|
|
15625
16708
|
valid: 0,
|
|
@@ -15640,12 +16723,12 @@ async function inspectContentCache(contentDir, referenced) {
|
|
|
15640
16723
|
continue;
|
|
15641
16724
|
}
|
|
15642
16725
|
report.files++;
|
|
15643
|
-
const file =
|
|
16726
|
+
const file = path27.join(contentDir, entry.name);
|
|
15644
16727
|
const mediaType = mediaTypeFromExtension(entry.name);
|
|
15645
16728
|
const expected = mediaType ? entry.name.slice(0, -4) : "";
|
|
15646
16729
|
let bytes;
|
|
15647
16730
|
try {
|
|
15648
|
-
bytes = await
|
|
16731
|
+
bytes = await readFile16(file);
|
|
15649
16732
|
report.bytes += bytes.length;
|
|
15650
16733
|
} catch (err) {
|
|
15651
16734
|
report.invalid.push({
|
|
@@ -15683,7 +16766,7 @@ async function inspectContentCache(contentDir, referenced) {
|
|
|
15683
16766
|
async function inspectRemoteHashCache(remotePath) {
|
|
15684
16767
|
const report = {
|
|
15685
16768
|
path: remotePath,
|
|
15686
|
-
exists:
|
|
16769
|
+
exists: existsSync23(remotePath),
|
|
15687
16770
|
entries: 0,
|
|
15688
16771
|
valid: 0,
|
|
15689
16772
|
invalidIds: [],
|
|
@@ -15692,7 +16775,7 @@ async function inspectRemoteHashCache(remotePath) {
|
|
|
15692
16775
|
if (!report.exists) return report;
|
|
15693
16776
|
let cache;
|
|
15694
16777
|
try {
|
|
15695
|
-
cache = parseCache(JSON.parse(await
|
|
16778
|
+
cache = parseCache(JSON.parse(await readFile16(remotePath, "utf8")));
|
|
15696
16779
|
} catch (err) {
|
|
15697
16780
|
report.error = err instanceof Error ? err.message : String(err);
|
|
15698
16781
|
return report;
|
|
@@ -15708,19 +16791,19 @@ async function inspectRemoteHashCache(remotePath) {
|
|
|
15708
16791
|
|
|
15709
16792
|
// src/pipeline/pack.ts
|
|
15710
16793
|
import { readFileSync as readFileSync6 } from "fs";
|
|
15711
|
-
import
|
|
16794
|
+
import path28 from "path";
|
|
15712
16795
|
var DEFAULT_FRAME_SET_FPS = 12;
|
|
15713
16796
|
function resolvePackInputs(raw, inputsFilePath) {
|
|
15714
16797
|
if (!Array.isArray(raw) || !raw.length) {
|
|
15715
16798
|
throw new Error("--inputs must be a non-empty JSON array of { id, path }");
|
|
15716
16799
|
}
|
|
15717
|
-
const baseDir =
|
|
16800
|
+
const baseDir = path28.dirname(path28.resolve(inputsFilePath));
|
|
15718
16801
|
return raw.map((entry, i) => {
|
|
15719
16802
|
const e = entry;
|
|
15720
16803
|
if (typeof e.id !== "string" || typeof e.path !== "string") {
|
|
15721
16804
|
throw new Error(`--inputs[${i}] needs string "id" and "path"`);
|
|
15722
16805
|
}
|
|
15723
|
-
return { id: e.id, path:
|
|
16806
|
+
return { id: e.id, path: path28.resolve(baseDir, e.path) };
|
|
15724
16807
|
});
|
|
15725
16808
|
}
|
|
15726
16809
|
function packSprites(inputs, options = {}) {
|
|
@@ -15804,7 +16887,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
15804
16887
|
}
|
|
15805
16888
|
const inputs2 = Object.entries(options.sourceOverrides).map(([id, source]) => ({
|
|
15806
16889
|
id,
|
|
15807
|
-
path:
|
|
16890
|
+
path: path28.resolve(source)
|
|
15808
16891
|
}));
|
|
15809
16892
|
if (!inputs2.length) throw new Error(`No approved quality outputs for style "${styleId}".`);
|
|
15810
16893
|
const packed2 = packSprites(inputs2, options);
|
|
@@ -15828,7 +16911,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
15828
16911
|
let outputs = resolveEntryOutputs(entry, id, manifestDir);
|
|
15829
16912
|
const source = sources[id];
|
|
15830
16913
|
if (source && outputs.length <= 1) {
|
|
15831
|
-
inputs.push({ id, path:
|
|
16914
|
+
inputs.push({ id, path: path28.resolve(manifestDir, source) });
|
|
15832
16915
|
continue;
|
|
15833
16916
|
}
|
|
15834
16917
|
if (source && sourceIsStem(source, entry, manifestDir)) {
|
|
@@ -15863,7 +16946,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
15863
16946
|
}
|
|
15864
16947
|
}
|
|
15865
16948
|
for (const [id, source] of Object.entries(sources)) {
|
|
15866
|
-
if (!locked.has(id)) inputs.push({ id, path:
|
|
16949
|
+
if (!locked.has(id)) inputs.push({ id, path: path28.resolve(manifestDir, source) });
|
|
15867
16950
|
}
|
|
15868
16951
|
if (!inputs.length) {
|
|
15869
16952
|
throw new Error(`No readable sprites for style "${styleId}"; ${noOutput.length} skipped.`);
|
|
@@ -15971,7 +17054,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
15971
17054
|
const source = sources[id];
|
|
15972
17055
|
const entry = lock.entries[`${styleId}/${id}`];
|
|
15973
17056
|
if (source && !(entry && sourceIsStem(source, entry, manifestDir))) {
|
|
15974
|
-
placements.push({ id, path:
|
|
17057
|
+
placements.push({ id, path: path28.resolve(manifestDir, source), cell });
|
|
15975
17058
|
continue;
|
|
15976
17059
|
}
|
|
15977
17060
|
if (source && entry) {
|
|
@@ -16004,7 +17087,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
16004
17087
|
`Nothing to mount for style "${styleId}": ${ids.length} asset(s) declare a cell, but none has generated output or a \`source\`. Run \`pixelkiln gen --style ${styleId}\`, or point each at a file.${detail}`
|
|
16005
17088
|
);
|
|
16006
17089
|
}
|
|
16007
|
-
const basePng = mount.base ? readFileSync6(
|
|
17090
|
+
const basePng = mount.base ? readFileSync6(path28.resolve(manifestDir, mount.base)) : void 0;
|
|
16008
17091
|
const mounted = mountSprites(placements, {
|
|
16009
17092
|
cellWidth: mount.cellWidth,
|
|
16010
17093
|
cellHeight: mount.cellHeight,
|
|
@@ -16014,7 +17097,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
16014
17097
|
...mounted,
|
|
16015
17098
|
sources: mount.base ? [{
|
|
16016
17099
|
id: "$base",
|
|
16017
|
-
path:
|
|
17100
|
+
path: path28.resolve(manifestDir, mount.base),
|
|
16018
17101
|
sha256: sha256(basePng),
|
|
16019
17102
|
included: true
|
|
16020
17103
|
}, ...mounted.sources] : mounted.sources,
|
|
@@ -16859,13 +17942,13 @@ async function poll(provider, lock, lockPath, opts = {}) {
|
|
|
16859
17942
|
}
|
|
16860
17943
|
|
|
16861
17944
|
// src/pipeline/doctor.ts
|
|
16862
|
-
import { constants, existsSync as
|
|
17945
|
+
import { constants, existsSync as existsSync25 } from "fs";
|
|
16863
17946
|
import { access, stat as stat2 } from "fs/promises";
|
|
16864
|
-
import
|
|
17947
|
+
import path30 from "path";
|
|
16865
17948
|
|
|
16866
17949
|
// src/pipeline/install-check.ts
|
|
16867
|
-
import { existsSync as
|
|
16868
|
-
import
|
|
17950
|
+
import { existsSync as existsSync24, readFileSync as readFileSync7 } from "fs";
|
|
17951
|
+
import path29 from "path";
|
|
16869
17952
|
function readJson(file) {
|
|
16870
17953
|
try {
|
|
16871
17954
|
return JSON.parse(readFileSync7(file, "utf8"));
|
|
@@ -16874,19 +17957,19 @@ function readJson(file) {
|
|
|
16874
17957
|
}
|
|
16875
17958
|
}
|
|
16876
17959
|
function readInstallFacts(manifestDir, running) {
|
|
16877
|
-
let dir =
|
|
17960
|
+
let dir = path29.resolve(manifestDir);
|
|
16878
17961
|
for (let depth = 0; depth < 4; depth++) {
|
|
16879
|
-
const pkg = readJson(
|
|
17962
|
+
const pkg = readJson(path29.join(dir, "package.json"));
|
|
16880
17963
|
if (pkg) {
|
|
16881
17964
|
const pinned = ["dependencies", "devDependencies", "optionalDependencies"].map((field) => pkg[field]?.pixelkiln).find((spec) => typeof spec === "string");
|
|
16882
17965
|
if (pinned) {
|
|
16883
|
-
const installedPkg = readJson(
|
|
17966
|
+
const installedPkg = readJson(path29.join(dir, "node_modules", "pixelkiln", "package.json"));
|
|
16884
17967
|
const installed = typeof installedPkg?.version === "string" ? installedPkg.version : void 0;
|
|
16885
17968
|
return { pinned, installed, running };
|
|
16886
17969
|
}
|
|
16887
17970
|
}
|
|
16888
|
-
const parent =
|
|
16889
|
-
if (parent === dir || !
|
|
17971
|
+
const parent = path29.dirname(dir);
|
|
17972
|
+
if (parent === dir || !existsSync24(parent)) break;
|
|
16890
17973
|
dir = parent;
|
|
16891
17974
|
}
|
|
16892
17975
|
return null;
|
|
@@ -16949,12 +18032,12 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
16949
18032
|
`${entry.kind === "style" ? "styles" : "assets"}.${entry.id} was left out: ${entry.issues.join("; ")}`
|
|
16950
18033
|
);
|
|
16951
18034
|
}
|
|
16952
|
-
const facts = readInstallFacts(
|
|
18035
|
+
const facts = readInstallFacts(path30.dirname(loaded.path), opts.runningVersion !== void 0 ? opts.runningVersion : pixelkilnVersion());
|
|
16953
18036
|
if (facts) for (const finding of checkInstall(facts)) add("install", finding.level, finding.message);
|
|
16954
18037
|
add("lock", "ok", `${Object.keys(lock.entries).length} valid v2 lock entr(ies)`);
|
|
16955
18038
|
const dirs = [...new Set(specs.flatMap((spec) => [
|
|
16956
|
-
|
|
16957
|
-
...spec.quality ? [
|
|
18039
|
+
path30.dirname(spec.outFile),
|
|
18040
|
+
...spec.quality ? [path30.dirname(spec.quality.outFile)] : []
|
|
16958
18041
|
]))];
|
|
16959
18042
|
const unwritable = [];
|
|
16960
18043
|
for (const dir of dirs) {
|
|
@@ -16977,7 +18060,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
16977
18060
|
for (let index = 0; index < entry.outputs.length; index++) {
|
|
16978
18061
|
const output = entry.outputs[index];
|
|
16979
18062
|
const spec = specByKey.get(key2);
|
|
16980
|
-
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path,
|
|
18063
|
+
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path, path30.dirname(lockPath));
|
|
16981
18064
|
const owner = outputOwners.get(absolute);
|
|
16982
18065
|
if (owner && owner !== key2) duplicateOutputs.push(`${output.path} (${owner}, ${key2})`);
|
|
16983
18066
|
outputOwners.set(absolute, key2);
|
|
@@ -16992,7 +18075,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
16992
18075
|
} else {
|
|
16993
18076
|
add("lock-outputs", "ok", `${outputOwners.size} recorded output path(s) are uniquely owned`);
|
|
16994
18077
|
}
|
|
16995
|
-
const cacheDir =
|
|
18078
|
+
const cacheDir = path30.join(path30.dirname(lockPath), ".pixelkiln", "cache");
|
|
16996
18079
|
const stranded = [];
|
|
16997
18080
|
const invalidState = [];
|
|
16998
18081
|
const staleMapUrls = [];
|
|
@@ -17008,11 +18091,11 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
17008
18091
|
const hasSource = Boolean(entry.sourceUrl || entry.sourceUrls?.length);
|
|
17009
18092
|
let hasCache = false;
|
|
17010
18093
|
for (const output of entry.outputs) {
|
|
17011
|
-
const cached2 =
|
|
18094
|
+
const cached2 = path30.join(
|
|
17012
18095
|
cacheDir,
|
|
17013
18096
|
cacheFileName(output.sha256, output.mediaType ?? MediaType.PNG)
|
|
17014
18097
|
);
|
|
17015
|
-
if (
|
|
18098
|
+
if (existsSync25(cached2) && await sha256File(cached2) === output.sha256) {
|
|
17016
18099
|
hasCache = true;
|
|
17017
18100
|
break;
|
|
17018
18101
|
}
|
|
@@ -17108,16 +18191,16 @@ async function nearestExistingDirectory(start) {
|
|
|
17108
18191
|
if ((await stat2(current)).isDirectory()) return current;
|
|
17109
18192
|
} catch {
|
|
17110
18193
|
}
|
|
17111
|
-
const parent =
|
|
18194
|
+
const parent = path30.dirname(current);
|
|
17112
18195
|
if (parent === current) return current;
|
|
17113
18196
|
current = parent;
|
|
17114
18197
|
}
|
|
17115
18198
|
}
|
|
17116
18199
|
|
|
17117
18200
|
// src/pipeline/adopt.ts
|
|
17118
|
-
import { existsSync as
|
|
17119
|
-
import { readFile as
|
|
17120
|
-
import
|
|
18201
|
+
import { existsSync as existsSync26 } from "fs";
|
|
18202
|
+
import { readFile as readFile17, writeFile as writeFile12 } from "fs/promises";
|
|
18203
|
+
import path31 from "path";
|
|
17121
18204
|
async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
17122
18205
|
const log = opts.onProgress ?? (() => {
|
|
17123
18206
|
});
|
|
@@ -17128,11 +18211,11 @@ async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
|
17128
18211
|
const localByHash = /* @__PURE__ */ new Map();
|
|
17129
18212
|
const unmatchedLocal = [];
|
|
17130
18213
|
for (const spec of specs) {
|
|
17131
|
-
if (!
|
|
18214
|
+
if (!existsSync26(spec.outFile)) {
|
|
17132
18215
|
unmatchedLocal.push(`${spec.styleId}/${spec.assetId} (no file at ${spec.outFile})`);
|
|
17133
18216
|
continue;
|
|
17134
18217
|
}
|
|
17135
|
-
const bytes = await
|
|
18218
|
+
const bytes = await readFile17(spec.outFile);
|
|
17136
18219
|
try {
|
|
17137
18220
|
decodePng(bytes);
|
|
17138
18221
|
} catch (err) {
|
|
@@ -17250,9 +18333,9 @@ async function tagAdopted(provider, specs, lock, opts = {}) {
|
|
|
17250
18333
|
}
|
|
17251
18334
|
|
|
17252
18335
|
// src/pipeline/import.ts
|
|
17253
|
-
import { existsSync as
|
|
17254
|
-
import { readFile as
|
|
17255
|
-
import
|
|
18336
|
+
import { existsSync as existsSync27 } from "fs";
|
|
18337
|
+
import { readFile as readFile18 } from "fs/promises";
|
|
18338
|
+
import path32 from "path";
|
|
17256
18339
|
function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
17257
18340
|
const png = decodePng(bytes);
|
|
17258
18341
|
const at = now.toISOString();
|
|
@@ -17304,13 +18387,13 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
17304
18387
|
if (opts.objectId && specs.length !== 1) {
|
|
17305
18388
|
throw new Error(`--object-id names one object; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
17306
18389
|
}
|
|
17307
|
-
const cacheDir = opts.cacheDir === false ? null :
|
|
18390
|
+
const cacheDir = opts.cacheDir === false ? null : path32.resolve(opts.cacheDir ?? path32.join(path32.dirname(lockPath), ".pixelkiln", "cache"));
|
|
17308
18391
|
let rawSha256;
|
|
17309
18392
|
let rawBytes;
|
|
17310
18393
|
if (opts.raw) {
|
|
17311
18394
|
if (specs.length !== 1) throw new Error(`--raw names one original; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
17312
18395
|
try {
|
|
17313
|
-
rawBytes = await
|
|
18396
|
+
rawBytes = await readFile18(opts.raw);
|
|
17314
18397
|
decodePng(rawBytes);
|
|
17315
18398
|
} catch (error) {
|
|
17316
18399
|
throw new Error(`--raw ${opts.raw} is not a readable PNG: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
@@ -17326,7 +18409,7 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
17326
18409
|
skipped.push({ key: key2, reason });
|
|
17327
18410
|
continue;
|
|
17328
18411
|
}
|
|
17329
|
-
if (!
|
|
18412
|
+
if (!existsSync27(spec.outFile)) {
|
|
17330
18413
|
skipped.push({ key: key2, reason: `no file at ${spec.outFile}` });
|
|
17331
18414
|
continue;
|
|
17332
18415
|
}
|
|
@@ -17337,7 +18420,7 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
17337
18420
|
let patch;
|
|
17338
18421
|
let bytes;
|
|
17339
18422
|
try {
|
|
17340
|
-
bytes = await
|
|
18423
|
+
bytes = await readFile18(spec.outFile);
|
|
17341
18424
|
patch = buildImportedEntry(spec, bytes, { ...opts, rawSha256 }, /* @__PURE__ */ new Date());
|
|
17342
18425
|
} catch (error) {
|
|
17343
18426
|
skipped.push({ key: key2, reason: `invalid PNG: ${error instanceof Error ? error.message : String(error)}` });
|
|
@@ -17369,7 +18452,7 @@ async function reportSpecHashes(specs, lock) {
|
|
|
17369
18452
|
for (const spec of specs) {
|
|
17370
18453
|
const key2 = lockKey(spec.styleId, spec.assetId);
|
|
17371
18454
|
let bytes = null;
|
|
17372
|
-
if (
|
|
18455
|
+
if (existsSync27(spec.outFile)) bytes = await readFile18(spec.outFile);
|
|
17373
18456
|
let wouldImport = null;
|
|
17374
18457
|
if (bytes && !unimportable(spec)) {
|
|
17375
18458
|
try {
|
|
@@ -17398,13 +18481,13 @@ async function reportSpecHashes(specs, lock) {
|
|
|
17398
18481
|
}
|
|
17399
18482
|
|
|
17400
18483
|
// src/pick/server.ts
|
|
17401
|
-
import { existsSync as
|
|
17402
|
-
import { readFile as
|
|
18484
|
+
import { existsSync as existsSync29 } from "fs";
|
|
18485
|
+
import { readFile as readFile21 } from "fs/promises";
|
|
17403
18486
|
|
|
17404
18487
|
// src/pipeline/init.ts
|
|
17405
|
-
import { readdir as readdir3, readFile as
|
|
17406
|
-
import { existsSync as
|
|
17407
|
-
import
|
|
18488
|
+
import { readdir as readdir3, readFile as readFile19, writeFile as writeFile13 } from "fs/promises";
|
|
18489
|
+
import { existsSync as existsSync28 } from "fs";
|
|
18490
|
+
import path33 from "path";
|
|
17408
18491
|
function pngSize(buf) {
|
|
17409
18492
|
if (buf.length < 24) return null;
|
|
17410
18493
|
const isPng = buf.readUInt32BE(0) === 2303741511 && buf.readUInt32BE(4) === 218765834;
|
|
@@ -17418,7 +18501,7 @@ function slugify(value) {
|
|
|
17418
18501
|
async function walk(dir, exclude) {
|
|
17419
18502
|
const out = [];
|
|
17420
18503
|
for (const entry of await readdir3(dir, { withFileTypes: true })) {
|
|
17421
|
-
const full =
|
|
18504
|
+
const full = path33.join(dir, entry.name);
|
|
17422
18505
|
if (exclude.some((x) => full.includes(x))) continue;
|
|
17423
18506
|
if (entry.isDirectory()) out.push(...await walk(full, exclude));
|
|
17424
18507
|
else if (entry.name.toLowerCase().endsWith(".png")) out.push(full);
|
|
@@ -17432,14 +18515,14 @@ async function scanAssets(root, opts = {}) {
|
|
|
17432
18515
|
const skipped = [];
|
|
17433
18516
|
const seen = /* @__PURE__ */ new Map();
|
|
17434
18517
|
for (const file of files.sort()) {
|
|
17435
|
-
const size = pngSize(await
|
|
18518
|
+
const size = pngSize(await readFile19(file));
|
|
17436
18519
|
if (!size) {
|
|
17437
18520
|
skipped.push(`${file} (not a readable PNG)`);
|
|
17438
18521
|
continue;
|
|
17439
18522
|
}
|
|
17440
|
-
const rel =
|
|
17441
|
-
const category =
|
|
17442
|
-
let id = slugify(
|
|
18523
|
+
const rel = path33.relative(root, file);
|
|
18524
|
+
const category = path33.dirname(rel) === "." ? "" : path33.dirname(rel);
|
|
18525
|
+
let id = slugify(path33.basename(rel));
|
|
17443
18526
|
if (seen.has(id)) {
|
|
17444
18527
|
const n = seen.get(id) + 1;
|
|
17445
18528
|
seen.set(id, n);
|
|
@@ -17913,7 +18996,7 @@ document.getElementById('submit').onclick = async () => {
|
|
|
17913
18996
|
|
|
17914
18997
|
// src/pick/review-server.ts
|
|
17915
18998
|
import { createServer } from "http";
|
|
17916
|
-
import { readFile as
|
|
18999
|
+
import { readFile as readFile20 } from "fs/promises";
|
|
17917
19000
|
function serveReviewPage(opts) {
|
|
17918
19001
|
const log = opts.onProgress ?? (() => {
|
|
17919
19002
|
});
|
|
@@ -17922,7 +19005,7 @@ function serveReviewPage(opts) {
|
|
|
17922
19005
|
if (req.method === "GET" && req.url && opts.assets?.has(req.url)) {
|
|
17923
19006
|
try {
|
|
17924
19007
|
const asset = opts.assets.get(req.url);
|
|
17925
|
-
const bytes = await
|
|
19008
|
+
const bytes = await readFile20(asset.path);
|
|
17926
19009
|
res.writeHead(200, {
|
|
17927
19010
|
"Content-Type": asset.contentType,
|
|
17928
19011
|
"Cache-Control": "no-store",
|
|
@@ -17998,13 +19081,13 @@ async function currentArt(entry, spec) {
|
|
|
17998
19081
|
const previous = primaryOutput({ ...entry, outputs: entry.supersededOutputs });
|
|
17999
19082
|
if (!previous) return null;
|
|
18000
19083
|
const file = resolveOutputPath(previous.path, spec.root);
|
|
18001
|
-
if (!
|
|
19084
|
+
if (!existsSync29(file)) return null;
|
|
18002
19085
|
const contentType = previous.mediaType ?? mediaTypeFromExtension(file);
|
|
18003
19086
|
if (!contentType) return null;
|
|
18004
19087
|
let width = entry.width;
|
|
18005
19088
|
let height = entry.height;
|
|
18006
19089
|
if (contentType === "image/png") {
|
|
18007
|
-
const size = pngSize(await
|
|
19090
|
+
const size = pngSize(await readFile21(file));
|
|
18008
19091
|
if (size) ({ width, height } = size);
|
|
18009
19092
|
}
|
|
18010
19093
|
return { path: file, contentType, width, height };
|
|
@@ -18012,7 +19095,7 @@ async function currentArt(entry, spec) {
|
|
|
18012
19095
|
async function cachedFrame(url) {
|
|
18013
19096
|
if (!url.startsWith("file://")) return null;
|
|
18014
19097
|
const file = url.slice("file://".length);
|
|
18015
|
-
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await
|
|
19098
|
+
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await readFile21(file).catch(() => Buffer.alloc(0))) ?? "application/octet-stream";
|
|
18016
19099
|
return { path: file, contentType };
|
|
18017
19100
|
}
|
|
18018
19101
|
async function prepareReview(provider, lock, opts = {}) {
|
|
@@ -18044,7 +19127,7 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
18044
19127
|
frameSizes.push(null);
|
|
18045
19128
|
continue;
|
|
18046
19129
|
}
|
|
18047
|
-
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await
|
|
19130
|
+
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await readFile21(cached2.path).catch(() => Buffer.alloc(0))) : null);
|
|
18048
19131
|
const route = `${prefix}/review-frame/${encodeURIComponent(String(groups.length))}/${index}`;
|
|
18049
19132
|
frameAssets.push([route, cached2]);
|
|
18050
19133
|
frameUrls.push(route);
|
|
@@ -18198,14 +19281,14 @@ async function runPicker(provider, lock, lockPath, opts = {}) {
|
|
|
18198
19281
|
|
|
18199
19282
|
// src/gallery/snapshot.ts
|
|
18200
19283
|
import { createHash as createHash5 } from "crypto";
|
|
18201
|
-
import { existsSync as
|
|
18202
|
-
import { readFile as
|
|
18203
|
-
import
|
|
19284
|
+
import { existsSync as existsSync35 } from "fs";
|
|
19285
|
+
import { readFile as readFile28, stat as stat3 } from "fs/promises";
|
|
19286
|
+
import path41 from "path";
|
|
18204
19287
|
|
|
18205
19288
|
// src/workspace.ts
|
|
18206
|
-
import { mkdir as
|
|
18207
|
-
import { existsSync as
|
|
18208
|
-
import
|
|
19289
|
+
import { mkdir as mkdir12, readFile as readFile22, rename as rename7, rm as rm7, writeFile as writeFile14 } from "fs/promises";
|
|
19290
|
+
import { existsSync as existsSync30 } from "fs";
|
|
19291
|
+
import path34 from "path";
|
|
18209
19292
|
import { z as z7 } from "zod";
|
|
18210
19293
|
var WorkspaceProjectSchema = z7.object({
|
|
18211
19294
|
id: z7.string().min(1),
|
|
@@ -18230,10 +19313,10 @@ ${parsed.error.issues.slice(0, 5).map((i) => ` ${i.path.join(".")}: ${i.message
|
|
|
18230
19313
|
);
|
|
18231
19314
|
}
|
|
18232
19315
|
async function loadWorkspace(workspacePath) {
|
|
18233
|
-
if (!
|
|
19316
|
+
if (!existsSync30(workspacePath)) return { version: 1, projects: [] };
|
|
18234
19317
|
let raw;
|
|
18235
19318
|
try {
|
|
18236
|
-
raw = JSON.parse(await
|
|
19319
|
+
raw = JSON.parse(await readFile22(workspacePath, "utf8"));
|
|
18237
19320
|
} catch (err) {
|
|
18238
19321
|
throw new ProjectError(
|
|
18239
19322
|
`Workspace catalog at ${workspacePath} is malformed:
|
|
@@ -18247,22 +19330,22 @@ async function saveWorkspace(workspacePath, ws) {
|
|
|
18247
19330
|
version: 1,
|
|
18248
19331
|
projects: [...ws.projects].sort((a, b) => a.id.localeCompare(b.id))
|
|
18249
19332
|
};
|
|
18250
|
-
await
|
|
19333
|
+
await mkdir12(path34.dirname(path34.resolve(workspacePath)), { recursive: true });
|
|
18251
19334
|
const tmp = `${workspacePath}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
18252
19335
|
try {
|
|
18253
|
-
await
|
|
19336
|
+
await writeFile14(tmp, JSON.stringify(sorted, null, 2) + "\n");
|
|
18254
19337
|
await rename7(tmp, workspacePath);
|
|
18255
19338
|
} finally {
|
|
18256
19339
|
await rm7(tmp, { force: true });
|
|
18257
19340
|
}
|
|
18258
19341
|
}
|
|
18259
19342
|
function toPortablePath(dir, absolute) {
|
|
18260
|
-
return
|
|
19343
|
+
return path34.relative(dir, absolute).split(path34.sep).join("/");
|
|
18261
19344
|
}
|
|
18262
19345
|
function resolveProject(dir, project) {
|
|
18263
19346
|
return {
|
|
18264
|
-
manifestPath:
|
|
18265
|
-
lockPath:
|
|
19347
|
+
manifestPath: path34.resolve(dir, project.manifest.split("/").join(path34.sep)),
|
|
19348
|
+
lockPath: path34.resolve(dir, project.lock.split("/").join(path34.sep))
|
|
18266
19349
|
};
|
|
18267
19350
|
}
|
|
18268
19351
|
function validateWorkspace(ws, dir) {
|
|
@@ -18275,21 +19358,21 @@ function validateWorkspace(ws, dir) {
|
|
|
18275
19358
|
const { manifestPath, lockPath } = resolveProject(dir, project);
|
|
18276
19359
|
lockOwners.set(lockPath, [...lockOwners.get(lockPath) ?? [], project.id]);
|
|
18277
19360
|
manifestOwners.set(manifestPath, [...manifestOwners.get(manifestPath) ?? [], project.id]);
|
|
18278
|
-
if (
|
|
19361
|
+
if (path34.isAbsolute(project.manifest) || path34.isAbsolute(project.lock)) {
|
|
18279
19362
|
diagnostics.push({
|
|
18280
19363
|
id: "absolute-path",
|
|
18281
19364
|
level: "warning",
|
|
18282
19365
|
message: `project "${project.id}" stores an absolute path; the catalog will not resolve correctly if this tree is cloned or moved elsewhere`
|
|
18283
19366
|
});
|
|
18284
19367
|
}
|
|
18285
|
-
if (!
|
|
19368
|
+
if (!existsSync30(manifestPath)) {
|
|
18286
19369
|
diagnostics.push({
|
|
18287
19370
|
id: "missing-manifest",
|
|
18288
19371
|
level: "error",
|
|
18289
19372
|
message: `project "${project.id}" manifest not found: ${manifestPath}`
|
|
18290
19373
|
});
|
|
18291
19374
|
}
|
|
18292
|
-
if (!
|
|
19375
|
+
if (!existsSync30(lockPath)) {
|
|
18293
19376
|
diagnostics.push({
|
|
18294
19377
|
id: "missing-lock",
|
|
18295
19378
|
level: "error",
|
|
@@ -18336,16 +19419,16 @@ function validateWorkspace(ws, dir) {
|
|
|
18336
19419
|
}
|
|
18337
19420
|
|
|
18338
19421
|
// src/gallery/edit.ts
|
|
18339
|
-
import { readFile as
|
|
18340
|
-
import
|
|
19422
|
+
import { readFile as readFile27, rename as rename10, writeFile as writeFile20 } from "fs/promises";
|
|
19423
|
+
import path40 from "path";
|
|
18341
19424
|
import { z as z13 } from "zod";
|
|
18342
19425
|
|
|
18343
19426
|
// src/manifest-edit.ts
|
|
18344
|
-
import { readFile as
|
|
18345
|
-
import
|
|
19427
|
+
import { readFile as readFile23, rename as rename8, rm as rm8, writeFile as writeFile15 } from "fs/promises";
|
|
19428
|
+
import path35 from "path";
|
|
18346
19429
|
import { z as z8 } from "zod";
|
|
18347
19430
|
var HexSha = z8.string().regex(/^[0-9a-f]{64}$/);
|
|
18348
|
-
var ProjectFileSchema = z8.string().min(1).refine((file) => !
|
|
19431
|
+
var ProjectFileSchema = z8.string().min(1).refine((file) => !path35.isAbsolute(file) && !file.split(/[\\/]/).includes(".."), "must be a path inside the project");
|
|
18349
19432
|
var AssetPatchSchema = z8.object({
|
|
18350
19433
|
prompt: z8.string().optional(),
|
|
18351
19434
|
/** Per-style override for the style being viewed; null removes it. */
|
|
@@ -18765,8 +19848,8 @@ function applyEdit(raw, edit) {
|
|
|
18765
19848
|
}
|
|
18766
19849
|
}
|
|
18767
19850
|
async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
18768
|
-
const absolute =
|
|
18769
|
-
const original = await
|
|
19851
|
+
const absolute = path35.resolve(manifestPath);
|
|
19852
|
+
const original = await readFile23(absolute, "utf8");
|
|
18770
19853
|
if (sha256(original) !== edit.expectedSha256) throw new ManifestDriftError(absolute);
|
|
18771
19854
|
let raw;
|
|
18772
19855
|
try {
|
|
@@ -18779,12 +19862,12 @@ async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
|
18779
19862
|
applyEdit(raw, edit);
|
|
18780
19863
|
const next = serializeLike(original, raw);
|
|
18781
19864
|
if (next === original) return unchanged(absolute, original);
|
|
18782
|
-
const tmp =
|
|
18783
|
-
|
|
18784
|
-
`.${
|
|
19865
|
+
const tmp = path35.join(
|
|
19866
|
+
path35.dirname(absolute),
|
|
19867
|
+
`.${path35.basename(absolute)}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`
|
|
18785
19868
|
);
|
|
18786
19869
|
try {
|
|
18787
|
-
await
|
|
19870
|
+
await writeFile15(tmp, next);
|
|
18788
19871
|
let specs;
|
|
18789
19872
|
try {
|
|
18790
19873
|
specs = await resolveSpecs(await loadManifest(tmp));
|
|
@@ -18810,18 +19893,18 @@ async function applyManifestEdit(manifestPath, edit) {
|
|
|
18810
19893
|
}
|
|
18811
19894
|
|
|
18812
19895
|
// src/pipeline/hand-edit.ts
|
|
18813
|
-
import { existsSync as
|
|
18814
|
-
import { copyFile, mkdir as
|
|
18815
|
-
import
|
|
19896
|
+
import { existsSync as existsSync31 } from "fs";
|
|
19897
|
+
import { copyFile, mkdir as mkdir13, readFile as readFile24, rename as rename9, rm as rm9, writeFile as writeFile16 } from "fs/promises";
|
|
19898
|
+
import path36 from "path";
|
|
18816
19899
|
import { z as z9 } from "zod";
|
|
18817
19900
|
var HAND_EDIT_DIR = "edits";
|
|
18818
19901
|
function handEditPath(loaded, spec) {
|
|
18819
19902
|
const style = loaded.manifest.styles[spec.styleId];
|
|
18820
|
-
const outDir =
|
|
18821
|
-
const relative =
|
|
18822
|
-
const inside = relative && !relative.startsWith("..") && !
|
|
18823
|
-
const file = inside ? relative :
|
|
18824
|
-
return
|
|
19903
|
+
const outDir = path36.resolve(loaded.root, style?.outDir ?? ".");
|
|
19904
|
+
const relative = path36.relative(outDir, spec.outFile);
|
|
19905
|
+
const inside = relative && !relative.startsWith("..") && !path36.isAbsolute(relative);
|
|
19906
|
+
const file = inside ? relative : path36.basename(spec.outFile);
|
|
19907
|
+
return path36.join(outDir, HAND_EDIT_DIR, file.replace(/\.gif$/i, ".png"));
|
|
18825
19908
|
}
|
|
18826
19909
|
function handEditBases(spec, lock) {
|
|
18827
19910
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
@@ -18834,10 +19917,10 @@ function handEditBases(spec, lock) {
|
|
|
18834
19917
|
}));
|
|
18835
19918
|
if (members.some((member) => member.mediaType && member.mediaType !== "image/png")) return null;
|
|
18836
19919
|
if (entry.outputs.length === 1 && !primaryOutput(entry)) return null;
|
|
18837
|
-
if (!members.every((member) =>
|
|
19920
|
+
if (!members.every((member) => existsSync31(member.path))) return null;
|
|
18838
19921
|
return members.map(({ role, path: file }) => ({ role, path: file }));
|
|
18839
19922
|
}
|
|
18840
|
-
return
|
|
19923
|
+
return existsSync31(spec.outFile) ? [{ role: null, path: spec.outFile }] : null;
|
|
18841
19924
|
}
|
|
18842
19925
|
function handEditBase(spec, lock) {
|
|
18843
19926
|
const bases = handEditBases(spec, lock);
|
|
@@ -18887,18 +19970,18 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
18887
19970
|
`${spec.styleId}/${spec.assetId} declares ${spec.source}, one committed file placed for the whole set; clear that source (pixelkiln edit detach) to hand-edit the members one by one`
|
|
18888
19971
|
);
|
|
18889
19972
|
}
|
|
18890
|
-
const existing = spec.source ?
|
|
19973
|
+
const existing = spec.source ? path36.resolve(loaded.root, spec.source) : null;
|
|
18891
19974
|
const editPath = existing ?? handEditPath(loaded, spec);
|
|
18892
19975
|
const members = handEditMembers(loaded, spec, lock, editPath);
|
|
18893
19976
|
let created = false;
|
|
18894
19977
|
for (const member of members) {
|
|
18895
|
-
if (
|
|
19978
|
+
if (existsSync31(member.path)) continue;
|
|
18896
19979
|
if (!member.base) {
|
|
18897
19980
|
throw new ManifestEditError(
|
|
18898
19981
|
`${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
|
|
18899
19982
|
);
|
|
18900
19983
|
}
|
|
18901
|
-
await
|
|
19984
|
+
await mkdir13(path36.dirname(member.path), { recursive: true });
|
|
18902
19985
|
await copyFile(member.base, member.path);
|
|
18903
19986
|
created = true;
|
|
18904
19987
|
}
|
|
@@ -18977,7 +20060,7 @@ function handEditProjectPath(editPath) {
|
|
|
18977
20060
|
async function readHandEditCompanion(editPath) {
|
|
18978
20061
|
let text;
|
|
18979
20062
|
try {
|
|
18980
|
-
text = await
|
|
20063
|
+
text = await readFile24(handEditCompanionPath(editPath), "utf8");
|
|
18981
20064
|
} catch {
|
|
18982
20065
|
return null;
|
|
18983
20066
|
}
|
|
@@ -19021,7 +20104,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
19021
20104
|
}
|
|
19022
20105
|
});
|
|
19023
20106
|
const bases = handEditBases(spec, lock);
|
|
19024
|
-
const expectedSize = bases?.[0] ? decodePng(await
|
|
20107
|
+
const expectedSize = bases?.[0] ? decodePng(await readFile24(bases[0].path)) : { width: spec.width, height: spec.height };
|
|
19025
20108
|
for (const [index, image] of decoded.entries()) {
|
|
19026
20109
|
if (image.width !== expectedSize.width || image.height !== expectedSize.height) {
|
|
19027
20110
|
const which = memberSet ? `member ${incoming[index].role ?? index}` : "the edit";
|
|
@@ -19037,7 +20120,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
19037
20120
|
editor: input.editor,
|
|
19038
20121
|
protocol: input.protocol,
|
|
19039
20122
|
savedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
19040
|
-
project: projectPath ?
|
|
20123
|
+
project: projectPath ? path36.basename(projectPath) : null,
|
|
19041
20124
|
outputs: incoming.map((frame, index) => ({
|
|
19042
20125
|
role: frame.role,
|
|
19043
20126
|
basedOn: basedOnHash(entry, index),
|
|
@@ -19067,7 +20150,7 @@ function basedOnHash(entry, index) {
|
|
|
19067
20150
|
async function replaceFile(file, bytes) {
|
|
19068
20151
|
const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
19069
20152
|
try {
|
|
19070
|
-
await
|
|
20153
|
+
await writeFile16(tmp, bytes);
|
|
19071
20154
|
await rename9(tmp, file);
|
|
19072
20155
|
} finally {
|
|
19073
20156
|
await rm9(tmp, { force: true });
|
|
@@ -19079,9 +20162,9 @@ function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
|
|
|
19079
20162
|
}
|
|
19080
20163
|
|
|
19081
20164
|
// src/gallery/upload.ts
|
|
19082
|
-
import { existsSync as
|
|
19083
|
-
import { mkdir as
|
|
19084
|
-
import
|
|
20165
|
+
import { existsSync as existsSync32 } from "fs";
|
|
20166
|
+
import { mkdir as mkdir14, writeFile as writeFile17 } from "fs/promises";
|
|
20167
|
+
import path37 from "path";
|
|
19085
20168
|
import { z as z10 } from "zod";
|
|
19086
20169
|
var MAX_UPLOAD_BYTES = 8 * 1024 * 1024;
|
|
19087
20170
|
var UploadImageSchema = z10.object({
|
|
@@ -19094,12 +20177,12 @@ var UploadImageSchema = z10.object({
|
|
|
19094
20177
|
overwrite: z10.boolean().optional()
|
|
19095
20178
|
}).strict();
|
|
19096
20179
|
async function saveProjectImage(root, request) {
|
|
19097
|
-
const file =
|
|
19098
|
-
const relative =
|
|
19099
|
-
if (relative.startsWith("..") ||
|
|
20180
|
+
const file = path37.resolve(root, request.path);
|
|
20181
|
+
const relative = path37.relative(root, file);
|
|
20182
|
+
if (relative.startsWith("..") || path37.isAbsolute(relative)) {
|
|
19100
20183
|
throw new ManifestEditError("an upload must stay inside the project");
|
|
19101
20184
|
}
|
|
19102
|
-
const extension =
|
|
20185
|
+
const extension = path37.extname(file).toLowerCase();
|
|
19103
20186
|
const expected = extension === ".png" ? "png" : extension === ".jpg" || extension === ".jpeg" ? "jpeg" : null;
|
|
19104
20187
|
if (!expected) throw new ManifestEditError("an upload must be a .png, .jpg, or .jpeg path");
|
|
19105
20188
|
const bytes = Buffer.from(request.base64, "base64");
|
|
@@ -19111,18 +20194,18 @@ async function saveProjectImage(root, request) {
|
|
|
19111
20194
|
if (metadata.format !== expected) {
|
|
19112
20195
|
throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
|
|
19113
20196
|
}
|
|
19114
|
-
if (
|
|
19115
|
-
throw new ManifestEditError(`${relative.split(
|
|
20197
|
+
if (existsSync32(file) && !request.overwrite) {
|
|
20198
|
+
throw new ManifestEditError(`${relative.split(path37.sep).join("/")} already exists; choose another name, or replace it`);
|
|
19116
20199
|
}
|
|
19117
|
-
await
|
|
19118
|
-
await
|
|
19119
|
-
return relative.split(
|
|
20200
|
+
await mkdir14(path37.dirname(file), { recursive: true });
|
|
20201
|
+
await writeFile17(file, bytes);
|
|
20202
|
+
return relative.split(path37.sep).join("/");
|
|
19120
20203
|
}
|
|
19121
20204
|
|
|
19122
20205
|
// src/gallery/image-revision.ts
|
|
19123
|
-
import { existsSync as
|
|
19124
|
-
import { readFile as
|
|
19125
|
-
import
|
|
20206
|
+
import { existsSync as existsSync33 } from "fs";
|
|
20207
|
+
import { readFile as readFile25, rm as rm10, writeFile as writeFile18 } from "fs/promises";
|
|
20208
|
+
import path38 from "path";
|
|
19126
20209
|
import { z as z11 } from "zod";
|
|
19127
20210
|
var InpaintRevisionRequestSchema = z11.object({
|
|
19128
20211
|
action: z11.literal("create-inpaint-revision"),
|
|
@@ -19141,15 +20224,15 @@ var InpaintRevisionRequestSchema = z11.object({
|
|
|
19141
20224
|
overwrite: z11.boolean().optional()
|
|
19142
20225
|
}).strict();
|
|
19143
20226
|
async function createInpaintRevision(manifestPath, request) {
|
|
19144
|
-
const root =
|
|
19145
|
-
if (
|
|
20227
|
+
const root = path38.dirname(path38.resolve(manifestPath));
|
|
20228
|
+
if (path38.extname(request.maskPath).toLowerCase() !== ".png") {
|
|
19146
20229
|
throw new ManifestEditError("the mask must be a .png path inside the project");
|
|
19147
20230
|
}
|
|
19148
20231
|
const bytes = Buffer.from(request.maskBase64, "base64");
|
|
19149
20232
|
const metadata = imageMetadata(bytes);
|
|
19150
20233
|
if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
|
|
19151
|
-
const file =
|
|
19152
|
-
const previous =
|
|
20234
|
+
const file = path38.resolve(root, request.maskPath);
|
|
20235
|
+
const previous = existsSync33(file) ? await readFile25(file) : null;
|
|
19153
20236
|
const mask = await saveProjectImage(root, {
|
|
19154
20237
|
action: "upload-image",
|
|
19155
20238
|
path: request.maskPath,
|
|
@@ -19168,7 +20251,7 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
19168
20251
|
}
|
|
19169
20252
|
});
|
|
19170
20253
|
} catch (error) {
|
|
19171
|
-
if (previous) await
|
|
20254
|
+
if (previous) await writeFile18(file, previous);
|
|
19172
20255
|
else await rm10(file, { force: true });
|
|
19173
20256
|
throw error;
|
|
19174
20257
|
}
|
|
@@ -19176,9 +20259,9 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
19176
20259
|
}
|
|
19177
20260
|
|
|
19178
20261
|
// src/gallery/skeleton.ts
|
|
19179
|
-
import { existsSync as
|
|
19180
|
-
import { mkdir as
|
|
19181
|
-
import
|
|
20262
|
+
import { existsSync as existsSync34 } from "fs";
|
|
20263
|
+
import { mkdir as mkdir15, readFile as readFile26, rm as rm11, writeFile as writeFile19 } from "fs/promises";
|
|
20264
|
+
import path39 from "path";
|
|
19182
20265
|
import { z as z12 } from "zod";
|
|
19183
20266
|
var SkeletonEstimateRequestSchema = z12.object({
|
|
19184
20267
|
project: z12.string().min(1).optional(),
|
|
@@ -19217,21 +20300,21 @@ var SkeletonKeypointsUpdateSchema = z12.object({
|
|
|
19217
20300
|
set: SkeletonSetSchema
|
|
19218
20301
|
}).strict();
|
|
19219
20302
|
async function createSkeletonAnimation(manifestPath, request) {
|
|
19220
|
-
const root =
|
|
19221
|
-
const file =
|
|
19222
|
-
const relative =
|
|
19223
|
-
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") ||
|
|
20303
|
+
const root = path39.dirname(path39.resolve(manifestPath));
|
|
20304
|
+
const file = path39.resolve(root, request.keypointsFile);
|
|
20305
|
+
const relative = path39.relative(root, file);
|
|
20306
|
+
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || path39.isAbsolute(relative)) {
|
|
19224
20307
|
throw new ManifestEditError("the keypoints file must be a .json path inside the project");
|
|
19225
20308
|
}
|
|
19226
|
-
const existed =
|
|
20309
|
+
const existed = existsSync34(file);
|
|
19227
20310
|
let previous = null;
|
|
19228
20311
|
if (request.set) {
|
|
19229
20312
|
if (existed && !request.overwrite) {
|
|
19230
20313
|
throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
|
|
19231
20314
|
}
|
|
19232
|
-
if (existed) previous = await
|
|
19233
|
-
await
|
|
19234
|
-
await
|
|
20315
|
+
if (existed) previous = await readFile26(file);
|
|
20316
|
+
await mkdir15(path39.dirname(file), { recursive: true });
|
|
20317
|
+
await writeFile19(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
19235
20318
|
} else if (!existed) {
|
|
19236
20319
|
throw new ManifestEditError(`${request.keypointsFile} does not exist; paste poses or estimate them from the sprite`);
|
|
19237
20320
|
}
|
|
@@ -19246,7 +20329,7 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
19246
20329
|
revision: {
|
|
19247
20330
|
mode: "animate-skeleton",
|
|
19248
20331
|
from: request.from,
|
|
19249
|
-
keypointsFile: relative.split(
|
|
20332
|
+
keypointsFile: relative.split(path39.sep).join("/"),
|
|
19250
20333
|
direction: request.direction,
|
|
19251
20334
|
description: request.description,
|
|
19252
20335
|
...request.skeletonTemplate ? { skeletonTemplate: request.skeletonTemplate } : {}
|
|
@@ -19255,7 +20338,7 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
19255
20338
|
});
|
|
19256
20339
|
} catch (error) {
|
|
19257
20340
|
if (request.set) {
|
|
19258
|
-
if (previous) await
|
|
20341
|
+
if (previous) await writeFile19(file, previous);
|
|
19259
20342
|
else await rm11(file, { force: true });
|
|
19260
20343
|
}
|
|
19261
20344
|
throw error;
|
|
@@ -19267,19 +20350,19 @@ async function updateSkeletonKeypoints(ctx, request) {
|
|
|
19267
20350
|
if (!spec) throw new ManifestEditError(`"${key2}" is not declared by the manifest`);
|
|
19268
20351
|
const file = spec.revision?.mode === "animate-skeleton" ? spec.revision.keypointsFile : void 0;
|
|
19269
20352
|
if (!file) throw new ManifestEditError(`${key2} is not an animate-skeleton revision`);
|
|
19270
|
-
const relative =
|
|
19271
|
-
if (relative.startsWith("..") ||
|
|
20353
|
+
const relative = path39.relative(ctx.loaded.root, file);
|
|
20354
|
+
if (relative.startsWith("..") || path39.isAbsolute(relative)) {
|
|
19272
20355
|
throw new ManifestEditError(`${key2}'s keypoints file is outside the project; edit it by hand`);
|
|
19273
20356
|
}
|
|
19274
|
-
const current =
|
|
20357
|
+
const current = existsSync34(file) ? sha256(await readFile26(file)) : null;
|
|
19275
20358
|
if (current !== request.expectedSha256) {
|
|
19276
20359
|
throw Object.assign(
|
|
19277
|
-
new Error(`${relative.split(
|
|
20360
|
+
new Error(`${relative.split(path39.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
|
|
19278
20361
|
{ status: 409 }
|
|
19279
20362
|
);
|
|
19280
20363
|
}
|
|
19281
|
-
await
|
|
19282
|
-
return relative.split(
|
|
20364
|
+
await writeFile19(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
20365
|
+
return relative.split(path39.sep).join("/");
|
|
19283
20366
|
}
|
|
19284
20367
|
|
|
19285
20368
|
// src/gallery/edit.ts
|
|
@@ -19333,7 +20416,7 @@ function createGalleryEditHandler(opts) {
|
|
|
19333
20416
|
const history = /* @__PURE__ */ new Map();
|
|
19334
20417
|
const manifestOf = async (project) => {
|
|
19335
20418
|
try {
|
|
19336
|
-
return
|
|
20419
|
+
return path40.resolve(await opts.manifestFor(typeof project === "string" ? project : void 0));
|
|
19337
20420
|
} catch {
|
|
19338
20421
|
return null;
|
|
19339
20422
|
}
|
|
@@ -19343,7 +20426,7 @@ function createGalleryEditHandler(opts) {
|
|
|
19343
20426
|
if (undo.success) {
|
|
19344
20427
|
const manifestPath2 = await manifestOf(undo.data.project);
|
|
19345
20428
|
if (!manifestPath2) throw new ManifestEditError("no manifest to undo an edit in");
|
|
19346
|
-
const current = await
|
|
20429
|
+
const current = await readFile27(manifestPath2, "utf8");
|
|
19347
20430
|
if (sha256(current) !== undo.data.expectedSha256) throw new ManifestDriftError(manifestPath2);
|
|
19348
20431
|
const stack = history.get(manifestPath2) ?? [];
|
|
19349
20432
|
const last = stack[stack.length - 1];
|
|
@@ -19353,17 +20436,17 @@ function createGalleryEditHandler(opts) {
|
|
|
19353
20436
|
throw Object.assign(new Error("the manifest changed outside the gallery since its last edit; undo would discard that change"), { status: 409 });
|
|
19354
20437
|
}
|
|
19355
20438
|
const tmp = manifestPath2 + ".pixelkiln-undo";
|
|
19356
|
-
await
|
|
20439
|
+
await writeFile20(tmp, last.before);
|
|
19357
20440
|
await rename10(tmp, manifestPath2);
|
|
19358
20441
|
stack.pop();
|
|
19359
|
-
log(` manifest edit undone in ${
|
|
20442
|
+
log(` manifest edit undone in ${path40.relative(process.cwd(), manifestPath2) || manifestPath2}`);
|
|
19360
20443
|
return opts.reload();
|
|
19361
20444
|
}
|
|
19362
20445
|
const manifestPath = await manifestOf(body?.project);
|
|
19363
|
-
const before = manifestPath ? await
|
|
20446
|
+
const before = manifestPath ? await readFile27(manifestPath, "utf8").catch(() => null) : null;
|
|
19364
20447
|
const build = await apply(body);
|
|
19365
20448
|
if (manifestPath && before !== null) {
|
|
19366
|
-
const after = await
|
|
20449
|
+
const after = await readFile27(manifestPath, "utf8").catch(() => null);
|
|
19367
20450
|
if (after !== null && after !== before) {
|
|
19368
20451
|
const stack = history.get(manifestPath) ?? [];
|
|
19369
20452
|
stack.push({ before, afterSha: sha256(after) });
|
|
@@ -19418,7 +20501,7 @@ function createEditApplier(opts, log) {
|
|
|
19418
20501
|
} catch (error) {
|
|
19419
20502
|
throw new ManifestEditError(error instanceof Error ? error.message : String(error));
|
|
19420
20503
|
}
|
|
19421
|
-
const written = await saveProjectImage(
|
|
20504
|
+
const written = await saveProjectImage(path40.dirname(path40.resolve(manifestPath2)), upload.data);
|
|
19422
20505
|
log(` image added: ${written}`);
|
|
19423
20506
|
return opts.reload();
|
|
19424
20507
|
}
|
|
@@ -19485,7 +20568,7 @@ function createEditApplier(opts, log) {
|
|
|
19485
20568
|
}
|
|
19486
20569
|
const result = await applyManifestEdit(manifestPath, parsed.data);
|
|
19487
20570
|
if (result.changed) {
|
|
19488
|
-
const relative =
|
|
20571
|
+
const relative = path40.relative(process.cwd(), result.manifestPath);
|
|
19489
20572
|
const shown = !relative || relative.startsWith("..") ? result.manifestPath : relative;
|
|
19490
20573
|
log(` manifest edited: ${describeEdit(parsed.data)} in ${shown}`);
|
|
19491
20574
|
}
|
|
@@ -19513,7 +20596,7 @@ function describeEdit(edit) {
|
|
|
19513
20596
|
// src/gallery/snapshot.ts
|
|
19514
20597
|
var PROJECT_FILE_TYPE = "application/octet-stream";
|
|
19515
20598
|
function galleryMediaId(absolutePath) {
|
|
19516
|
-
return createHash5("sha256").update(
|
|
20599
|
+
return createHash5("sha256").update(path41.resolve(absolutePath)).digest("hex").slice(0, 24);
|
|
19517
20600
|
}
|
|
19518
20601
|
function galleryMediaRoute(id) {
|
|
19519
20602
|
return `/media/${id}`;
|
|
@@ -19537,9 +20620,9 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
19537
20620
|
return (entry.history ?? []).map((generation, i) => {
|
|
19538
20621
|
const outputs = generation.outputs.map((output) => {
|
|
19539
20622
|
const mediaType = output.mediaType ?? MediaType.PNG;
|
|
19540
|
-
const file =
|
|
20623
|
+
const file = path41.join(cacheDir, cacheFileName(output.sha256, mediaType));
|
|
19541
20624
|
let url = null;
|
|
19542
|
-
if (
|
|
20625
|
+
if (existsSync35(file)) {
|
|
19543
20626
|
const id = galleryMediaId(file);
|
|
19544
20627
|
media.set(id, { path: file, contentType: mediaType });
|
|
19545
20628
|
url = `${galleryMediaRoute(id)}?v=${output.sha256.slice(0, 24)}`;
|
|
@@ -19571,7 +20654,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
19571
20654
|
var MAX_COMPARED_BYTES = 8 * 1024 * 1024;
|
|
19572
20655
|
async function samePixels(a, b) {
|
|
19573
20656
|
try {
|
|
19574
|
-
const [left, right] = await Promise.all([
|
|
20657
|
+
const [left, right] = await Promise.all([readFile28(a), readFile28(b)]);
|
|
19575
20658
|
if (left.length > MAX_COMPARED_BYTES || right.length > MAX_COMPARED_BYTES) return false;
|
|
19576
20659
|
const x = decodePng(left);
|
|
19577
20660
|
const y = decodePng(right);
|
|
@@ -19669,10 +20752,10 @@ async function describeOutput(media, root, absolutePath, recorded = {}) {
|
|
|
19669
20752
|
async function describeQuality(media, root, inspection) {
|
|
19670
20753
|
const outputPaths = inspection.outputs ?? [inspection.output];
|
|
19671
20754
|
const outputs = await Promise.all(
|
|
19672
|
-
outputPaths.map((file) => describeOutput(media, root,
|
|
20755
|
+
outputPaths.map((file) => describeOutput(media, root, path41.resolve(root, file)))
|
|
19673
20756
|
);
|
|
19674
|
-
const recordPath =
|
|
19675
|
-
const recordExists =
|
|
20757
|
+
const recordPath = path41.resolve(root, inspection.record);
|
|
20758
|
+
const recordExists = existsSync35(recordPath);
|
|
19676
20759
|
let options = null;
|
|
19677
20760
|
let check = null;
|
|
19678
20761
|
if (recordExists) {
|
|
@@ -19691,7 +20774,7 @@ async function describeQuality(media, root, inspection) {
|
|
|
19691
20774
|
return {
|
|
19692
20775
|
state: inspection.state,
|
|
19693
20776
|
reason: inspection.reason,
|
|
19694
|
-
output: portableOutputPath(
|
|
20777
|
+
output: portableOutputPath(path41.resolve(root, inspection.output), root),
|
|
19695
20778
|
record: portableOutputPath(recordPath, root),
|
|
19696
20779
|
recordExists,
|
|
19697
20780
|
outputs,
|
|
@@ -19729,9 +20812,9 @@ async function buildGallerySnapshot(opts) {
|
|
|
19729
20812
|
const media = /* @__PURE__ */ new Map();
|
|
19730
20813
|
const plan = await buildPlan(specs, lock);
|
|
19731
20814
|
const items = [];
|
|
19732
|
-
const manifestText = await
|
|
20815
|
+
const manifestText = await readFile28(loaded.path, "utf8");
|
|
19733
20816
|
const manifestSha256 = sha256(manifestText);
|
|
19734
|
-
const cacheDir =
|
|
20817
|
+
const cacheDir = path41.resolve(path41.dirname(opts.lockPath), ".pixelkiln", "cache");
|
|
19735
20818
|
let rawStyles = {};
|
|
19736
20819
|
try {
|
|
19737
20820
|
const raw = JSON.parse(manifestText);
|
|
@@ -19755,12 +20838,12 @@ async function buildGallerySnapshot(opts) {
|
|
|
19755
20838
|
)
|
|
19756
20839
|
);
|
|
19757
20840
|
if (spec.source) {
|
|
19758
|
-
const editPath =
|
|
20841
|
+
const editPath = path41.resolve(root, spec.source);
|
|
19759
20842
|
const memberCount = sourceIsStem(spec.source, entry, root) ? entry.outputs.length : 1;
|
|
19760
20843
|
const editShas = await Promise.all(
|
|
19761
20844
|
Array.from({ length: memberCount }, async (_, index) => {
|
|
19762
20845
|
const file = sourceOutputPath(spec.source, entry, index, root);
|
|
19763
|
-
return { file, sha256:
|
|
20846
|
+
return { file, sha256: existsSync35(file) ? await sha256File(file) : null };
|
|
19764
20847
|
})
|
|
19765
20848
|
);
|
|
19766
20849
|
edits = await Promise.all(editShas.map(({ file, sha256: editSha }) => describeOutput(media, root, file, { sha256: editSha })));
|
|
@@ -19768,7 +20851,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
19768
20851
|
const companion = await readHandEditCompanion(editPath);
|
|
19769
20852
|
if (companion) {
|
|
19770
20853
|
const projectPath = handEditProjectPath(editPath);
|
|
19771
|
-
const project = companion.project &&
|
|
20854
|
+
const project = companion.project && existsSync35(projectPath) ? await fileInfo(projectPath) : null;
|
|
19772
20855
|
let projectUrl = null;
|
|
19773
20856
|
if (project) {
|
|
19774
20857
|
const id = galleryMediaId(projectPath);
|
|
@@ -19804,8 +20887,8 @@ async function buildGallerySnapshot(opts) {
|
|
|
19804
20887
|
editStatus = edits.some((member) => !member.exists) ? "missing" : editChanged.every((changed) => !changed) ? "same" : regenerated ? "regenerated-since" : "edited";
|
|
19805
20888
|
}
|
|
19806
20889
|
} else if (spec.source) {
|
|
19807
|
-
outputs = [await describeOutput(media, root,
|
|
19808
|
-
} else if (!entry &&
|
|
20890
|
+
outputs = [await describeOutput(media, root, path41.resolve(root, spec.source))];
|
|
20891
|
+
} else if (!entry && existsSync35(spec.outFile)) {
|
|
19809
20892
|
outputs = [await describeOutput(media, root, spec.outFile)];
|
|
19810
20893
|
} else {
|
|
19811
20894
|
outputs = [];
|
|
@@ -20009,7 +21092,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
20009
21092
|
id: loaded.manifest.name,
|
|
20010
21093
|
name: loaded.manifest.name,
|
|
20011
21094
|
manifest: loaded.path,
|
|
20012
|
-
lock:
|
|
21095
|
+
lock: path41.resolve(opts.lockPath),
|
|
20013
21096
|
root,
|
|
20014
21097
|
provider: loaded.manifest.provider,
|
|
20015
21098
|
account: null,
|
|
@@ -20035,7 +21118,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
20035
21118
|
return { snapshot, media };
|
|
20036
21119
|
}
|
|
20037
21120
|
async function buildWorkspaceGallerySnapshot(opts) {
|
|
20038
|
-
const dir =
|
|
21121
|
+
const dir = path41.dirname(path41.resolve(opts.workspacePath));
|
|
20039
21122
|
const media = /* @__PURE__ */ new Map();
|
|
20040
21123
|
const projects = [];
|
|
20041
21124
|
const items = [];
|
|
@@ -20078,11 +21161,11 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
20078
21161
|
id: project.id,
|
|
20079
21162
|
name: loaded.manifest.name,
|
|
20080
21163
|
manifest: manifestPath,
|
|
20081
|
-
lock:
|
|
21164
|
+
lock: path41.resolve(lockPath),
|
|
20082
21165
|
root: loaded.root,
|
|
20083
21166
|
provider: loaded.manifest.provider,
|
|
20084
21167
|
account: project.account ?? null,
|
|
20085
|
-
manifestSha256: manifestSha256 ?? sha256(await
|
|
21168
|
+
manifestSha256: manifestSha256 ?? sha256(await readFile28(manifestPath, "utf8")),
|
|
20086
21169
|
historyLimit: historyLimit(loaded.manifest),
|
|
20087
21170
|
entries: Object.keys(lock.entries).length,
|
|
20088
21171
|
items: projectItems.length,
|
|
@@ -20094,8 +21177,8 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
20094
21177
|
id: project.id,
|
|
20095
21178
|
name: project.id,
|
|
20096
21179
|
manifest: manifestPath,
|
|
20097
|
-
lock:
|
|
20098
|
-
root:
|
|
21180
|
+
lock: path41.resolve(lockPath),
|
|
21181
|
+
root: path41.dirname(manifestPath),
|
|
20099
21182
|
provider: project.provider,
|
|
20100
21183
|
account: project.account ?? null,
|
|
20101
21184
|
manifestSha256: null,
|
|
@@ -20122,7 +21205,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
20122
21205
|
version: 1,
|
|
20123
21206
|
generatedAt: (opts.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
|
|
20124
21207
|
project: null,
|
|
20125
|
-
workspace: { path:
|
|
21208
|
+
workspace: { path: path41.resolve(opts.workspacePath), dir, projects },
|
|
20126
21209
|
filter,
|
|
20127
21210
|
totals: {
|
|
20128
21211
|
entries: projects.reduce((sum, project) => sum + project.entries, 0),
|
|
@@ -20139,7 +21222,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
20139
21222
|
}
|
|
20140
21223
|
|
|
20141
21224
|
// src/gallery/page.ts
|
|
20142
|
-
import { existsSync as
|
|
21225
|
+
import { existsSync as existsSync36, readFileSync as readFileSync8 } from "fs";
|
|
20143
21226
|
|
|
20144
21227
|
// src/gallery/client-bundle.ts
|
|
20145
21228
|
import { createRequire } from "module";
|
|
@@ -20180,7 +21263,7 @@ function clientAssets() {
|
|
|
20180
21263
|
const prebuilt = new URL("gallery.js", CLIENT_DIR);
|
|
20181
21264
|
client ??= {
|
|
20182
21265
|
css: readFileSync8(new URL("gallery.css", CLIENT_DIR), "utf8"),
|
|
20183
|
-
js:
|
|
21266
|
+
js: existsSync36(prebuilt) ? readFileSync8(prebuilt, "utf8") : bundleGalleryClient()
|
|
20184
21267
|
};
|
|
20185
21268
|
return client;
|
|
20186
21269
|
}
|
|
@@ -20323,10 +21406,10 @@ var EDITOR_RELEASE_BASE = "https://github.com/gfargo/pixelkiln/releases/download
|
|
|
20323
21406
|
|
|
20324
21407
|
// src/editor/install.ts
|
|
20325
21408
|
import { createHash as createHash6 } from "crypto";
|
|
20326
|
-
import { existsSync as
|
|
20327
|
-
import { mkdir as
|
|
21409
|
+
import { existsSync as existsSync37 } from "fs";
|
|
21410
|
+
import { mkdir as mkdir16, readFile as readFile29, rename as rename11, rm as rm12, stat as stat4, writeFile as writeFile21 } from "fs/promises";
|
|
20328
21411
|
import os3 from "os";
|
|
20329
|
-
import
|
|
21412
|
+
import path42 from "path";
|
|
20330
21413
|
var EditorInstallError = class extends Error {
|
|
20331
21414
|
constructor(message6, file) {
|
|
20332
21415
|
super(message6);
|
|
@@ -20337,15 +21420,15 @@ var EditorInstallError = class extends Error {
|
|
|
20337
21420
|
};
|
|
20338
21421
|
function editorToolsRoot() {
|
|
20339
21422
|
const override = process.env.PIXELKILN_TOOLS_DIR?.trim();
|
|
20340
|
-
if (override) return
|
|
20341
|
-
if (process.platform === "darwin") return
|
|
21423
|
+
if (override) return path42.resolve(override);
|
|
21424
|
+
if (process.platform === "darwin") return path42.join(os3.homedir(), "Library", "Caches", "pixelkiln", "tools");
|
|
20342
21425
|
if (process.platform === "win32") {
|
|
20343
|
-
return
|
|
21426
|
+
return path42.join(process.env.LOCALAPPDATA ?? path42.join(os3.homedir(), "AppData", "Local"), "pixelkiln", "tools");
|
|
20344
21427
|
}
|
|
20345
|
-
return
|
|
21428
|
+
return path42.join(process.env.XDG_CACHE_HOME ?? path42.join(os3.homedir(), ".cache"), "pixelkiln", "tools");
|
|
20346
21429
|
}
|
|
20347
21430
|
function editorDir(pin = EDITOR_PIN, root = editorToolsRoot()) {
|
|
20348
|
-
return
|
|
21431
|
+
return path42.join(root, "pixelorama", pin.release ?? "unpublished");
|
|
20349
21432
|
}
|
|
20350
21433
|
function editorBaseUrl(pin = EDITOR_PIN) {
|
|
20351
21434
|
const override = process.env.PIXELKILN_EDITOR_URL?.trim();
|
|
@@ -20355,7 +21438,7 @@ function editorBaseUrl(pin = EDITOR_PIN) {
|
|
|
20355
21438
|
}
|
|
20356
21439
|
async function sha256Of(file) {
|
|
20357
21440
|
try {
|
|
20358
|
-
return createHash6("sha256").update(await
|
|
21441
|
+
return createHash6("sha256").update(await readFile29(file)).digest("hex");
|
|
20359
21442
|
} catch {
|
|
20360
21443
|
return null;
|
|
20361
21444
|
}
|
|
@@ -20368,8 +21451,8 @@ async function editorStatus(opts = {}) {
|
|
|
20368
21451
|
let totalBytes = 0;
|
|
20369
21452
|
for (const [name, expected] of Object.entries(pin.files)) {
|
|
20370
21453
|
totalBytes += expected.bytes;
|
|
20371
|
-
const file =
|
|
20372
|
-
const info =
|
|
21454
|
+
const file = path42.join(dir, name);
|
|
21455
|
+
const info = existsSync37(file) ? await stat4(file).catch(() => null) : null;
|
|
20373
21456
|
if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
|
|
20374
21457
|
installedBytes += expected.bytes;
|
|
20375
21458
|
} else {
|
|
@@ -20398,7 +21481,7 @@ async function installEditor(opts = {}) {
|
|
|
20398
21481
|
);
|
|
20399
21482
|
}
|
|
20400
21483
|
if (!baseUrl) throw new EditorInstallError("no download location for the editor build");
|
|
20401
|
-
await
|
|
21484
|
+
await mkdir16(dir, { recursive: true });
|
|
20402
21485
|
const downloaded = [];
|
|
20403
21486
|
const skipped = Object.keys(pin.files).filter((name) => !before.missing.includes(name));
|
|
20404
21487
|
let fetchedBytes = before.installedBytes;
|
|
@@ -20426,10 +21509,10 @@ async function installEditor(opts = {}) {
|
|
|
20426
21509
|
if (digest2 !== expected.sha256) {
|
|
20427
21510
|
throw new EditorInstallError(`${name}: sha256 ${digest2.slice(0, 12)}\u2026 does not match the pinned ${expected.sha256.slice(0, 12)}\u2026`, name);
|
|
20428
21511
|
}
|
|
20429
|
-
const final =
|
|
21512
|
+
const final = path42.join(dir, name);
|
|
20430
21513
|
const tmp = `${final}.${process.pid}.part`;
|
|
20431
21514
|
try {
|
|
20432
|
-
await
|
|
21515
|
+
await writeFile21(tmp, bytes);
|
|
20433
21516
|
await rename11(tmp, final);
|
|
20434
21517
|
} finally {
|
|
20435
21518
|
await rm12(tmp, { force: true });
|
|
@@ -20472,12 +21555,12 @@ var EDITOR_CONTENT_TYPES = {
|
|
|
20472
21555
|
".json": "application/json; charset=utf-8"
|
|
20473
21556
|
};
|
|
20474
21557
|
function editorContentType(name) {
|
|
20475
|
-
return EDITOR_CONTENT_TYPES[
|
|
21558
|
+
return EDITOR_CONTENT_TYPES[path42.extname(name).toLowerCase()] ?? null;
|
|
20476
21559
|
}
|
|
20477
21560
|
|
|
20478
21561
|
// src/gallery/editor.ts
|
|
20479
|
-
import { readFile as
|
|
20480
|
-
import
|
|
21562
|
+
import { readFile as readFile30 } from "fs/promises";
|
|
21563
|
+
import path43 from "path";
|
|
20481
21564
|
function editorRoute(release, name = "index.html") {
|
|
20482
21565
|
return `/editor/${encodeURIComponent(release)}/${encodeURIComponent(name)}`;
|
|
20483
21566
|
}
|
|
@@ -20550,7 +21633,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
20550
21633
|
if (!status.installed) return null;
|
|
20551
21634
|
let bytes;
|
|
20552
21635
|
try {
|
|
20553
|
-
bytes = await
|
|
21636
|
+
bytes = await readFile30(path43.join(dir, name));
|
|
20554
21637
|
} catch {
|
|
20555
21638
|
verified = null;
|
|
20556
21639
|
return null;
|
|
@@ -20567,7 +21650,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
20567
21650
|
// src/gallery/server.ts
|
|
20568
21651
|
import { randomBytes } from "crypto";
|
|
20569
21652
|
import { createServer as createServer2 } from "http";
|
|
20570
|
-
import { readFile as
|
|
21653
|
+
import { readFile as readFile31 } from "fs/promises";
|
|
20571
21654
|
var MAX_EDIT_BYTES = 48 * 1024 * 1024;
|
|
20572
21655
|
var EDITOR_CSP = [
|
|
20573
21656
|
"default-src 'self'",
|
|
@@ -20748,7 +21831,7 @@ async function serveGallery(opts) {
|
|
|
20748
21831
|
const asset = reviewAssets.get(jobId)?.get(url2.pathname);
|
|
20749
21832
|
if (!asset) return fail(404, "no such review asset");
|
|
20750
21833
|
try {
|
|
20751
|
-
const bytes = await
|
|
21834
|
+
const bytes = await readFile31(asset.path);
|
|
20752
21835
|
res.writeHead(200, {
|
|
20753
21836
|
"Content-Type": asset.contentType,
|
|
20754
21837
|
"Cache-Control": "no-store",
|
|
@@ -20831,7 +21914,7 @@ async function serveGallery(opts) {
|
|
|
20831
21914
|
if (!asset) return fail(404, "no such gallery media");
|
|
20832
21915
|
let bytes;
|
|
20833
21916
|
try {
|
|
20834
|
-
bytes = await
|
|
21917
|
+
bytes = await readFile31(asset.path);
|
|
20835
21918
|
} catch {
|
|
20836
21919
|
return fail(404, "gallery media is no longer on disk; refresh the page");
|
|
20837
21920
|
}
|
|
@@ -21241,19 +22324,19 @@ function createGenerateHandlers(opts) {
|
|
|
21241
22324
|
}
|
|
21242
22325
|
|
|
21243
22326
|
// src/pipeline/salvage.ts
|
|
21244
|
-
import { readFile as
|
|
21245
|
-
import { existsSync as
|
|
21246
|
-
import
|
|
22327
|
+
import { readFile as readFile32 } from "fs/promises";
|
|
22328
|
+
import { existsSync as existsSync38 } from "fs";
|
|
22329
|
+
import path44 from "path";
|
|
21247
22330
|
function providerClaimId(provider, objectId) {
|
|
21248
22331
|
return `${encodeURIComponent(provider)}:${encodeURIComponent(objectId)}`;
|
|
21249
22332
|
}
|
|
21250
22333
|
async function loadClaims(lockPaths, opts = {}) {
|
|
21251
22334
|
const claimed = /* @__PURE__ */ new Set();
|
|
21252
22335
|
for (const p of lockPaths) {
|
|
21253
|
-
if (!
|
|
22336
|
+
if (!existsSync38(p)) throw new Error(`Claim lockfile not found: ${p}`);
|
|
21254
22337
|
let parsed;
|
|
21255
22338
|
try {
|
|
21256
|
-
parsed = parseLock(JSON.parse(await
|
|
22339
|
+
parsed = parseLock(JSON.parse(await readFile32(p, "utf8")));
|
|
21257
22340
|
} catch {
|
|
21258
22341
|
throw new Error(`Claim lockfile is malformed: ${p}`);
|
|
21259
22342
|
}
|
|
@@ -21305,7 +22388,7 @@ function characterSalvageAssets(characters, ctx) {
|
|
|
21305
22388
|
assets[baseId] = { prompt: base.prompt || base.name || baseId, remoteId: base.id, ...size, ...common };
|
|
21306
22389
|
const assetIdOf = /* @__PURE__ */ new Map([[base.id, baseId]]);
|
|
21307
22390
|
for (const state of ordered.slice(1)) {
|
|
21308
|
-
const stateId = uniqueId(`${baseId}_${
|
|
22391
|
+
const stateId = uniqueId(`${baseId}_${slug2(state.stateName ?? "state")}`, ctx.taken);
|
|
21309
22392
|
assetIdOf.set(state.id, stateId);
|
|
21310
22393
|
assets[stateId] = { prompt: state.prompt || state.stateName || stateId, state: { of: baseId }, remoteId: state.id, ...common };
|
|
21311
22394
|
}
|
|
@@ -21318,7 +22401,7 @@ function characterSalvageAssets(characters, ctx) {
|
|
|
21318
22401
|
skipped.push(`${parentId}: "${label}" ${animation.direction} loop has no animation group id to adopt it by`);
|
|
21319
22402
|
continue;
|
|
21320
22403
|
}
|
|
21321
|
-
const loopId = uniqueId(`${parentId}.${
|
|
22404
|
+
const loopId = uniqueId(`${parentId}.${slug2(label)}.${animation.direction}`, ctx.taken);
|
|
21322
22405
|
assets[loopId] = {
|
|
21323
22406
|
prompt: label,
|
|
21324
22407
|
animation: { of: parentId, direction: animation.direction },
|
|
@@ -21329,7 +22412,7 @@ function characterSalvageAssets(characters, ctx) {
|
|
|
21329
22412
|
}
|
|
21330
22413
|
return { assets, skipped };
|
|
21331
22414
|
}
|
|
21332
|
-
function
|
|
22415
|
+
function slug2(text) {
|
|
21333
22416
|
return text.toLowerCase().replace(/^pixelkiln:.*\//, "").replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "") || "loop";
|
|
21334
22417
|
}
|
|
21335
22418
|
function uniqueId(base, taken) {
|
|
@@ -21357,20 +22440,20 @@ function matchOrphanStyle(prompt, manifest) {
|
|
|
21357
22440
|
return matchStyleByPattern(prompt, manifest);
|
|
21358
22441
|
}
|
|
21359
22442
|
async function loadSiblingManifests(ownManifestPath, workspaceManifestPaths, claimPaths) {
|
|
21360
|
-
const own =
|
|
22443
|
+
const own = path44.resolve(ownManifestPath);
|
|
21361
22444
|
const siblingManifestPaths = [
|
|
21362
22445
|
.../* @__PURE__ */ new Set([
|
|
21363
22446
|
...workspaceManifestPaths,
|
|
21364
|
-
...claimPaths.map((c) =>
|
|
22447
|
+
...claimPaths.map((c) => path44.join(path44.dirname(path44.resolve(c)), "pixelkiln.manifest.json"))
|
|
21365
22448
|
])
|
|
21366
22449
|
];
|
|
21367
22450
|
const siblings = [];
|
|
21368
22451
|
for (const siblingManifestPath of siblingManifestPaths) {
|
|
21369
|
-
if (
|
|
21370
|
-
if (!
|
|
22452
|
+
if (path44.resolve(siblingManifestPath) === own) continue;
|
|
22453
|
+
if (!existsSync38(siblingManifestPath)) continue;
|
|
21371
22454
|
try {
|
|
21372
22455
|
const { manifest } = await loadManifest(siblingManifestPath);
|
|
21373
|
-
siblings.push({ label:
|
|
22456
|
+
siblings.push({ label: path44.basename(path44.dirname(siblingManifestPath)), manifest });
|
|
21374
22457
|
} catch {
|
|
21375
22458
|
}
|
|
21376
22459
|
}
|
|
@@ -21490,8 +22573,8 @@ async function applyTags(provider, decisions, existing, opts = {}) {
|
|
|
21490
22573
|
}
|
|
21491
22574
|
|
|
21492
22575
|
// src/pick/salvage-server.ts
|
|
21493
|
-
import { mkdir as
|
|
21494
|
-
import
|
|
22576
|
+
import { mkdir as mkdir17, writeFile as writeFile22, readFile as readFile33 } from "fs/promises";
|
|
22577
|
+
import path45 from "path";
|
|
21495
22578
|
|
|
21496
22579
|
// src/pick/salvage-sheet.ts
|
|
21497
22580
|
var escapeHtml3 = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
@@ -21657,7 +22740,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
21657
22740
|
});
|
|
21658
22741
|
const html = renderSalvageSheet(orphans, {
|
|
21659
22742
|
styleId: ctx.styleId,
|
|
21660
|
-
importDir:
|
|
22743
|
+
importDir: path45.relative(process.cwd(), ctx.importDir) || "."
|
|
21661
22744
|
});
|
|
21662
22745
|
const byId = new Map(orphans.map((o) => [o.id, o]));
|
|
21663
22746
|
const existingTags = new Map(orphans.map((o) => [o.id, o.tags]));
|
|
@@ -21713,10 +22796,10 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
21713
22796
|
if (!buf.subarray(0, 8).equals(PNG_SIGNATURE2)) throw new Error("not a PNG");
|
|
21714
22797
|
decodePng(buf);
|
|
21715
22798
|
const assetId = idFromPrompt(orphan.prompt, taken);
|
|
21716
|
-
const rel =
|
|
21717
|
-
const outFile =
|
|
21718
|
-
await
|
|
21719
|
-
await
|
|
22799
|
+
const rel = path45.join("_salvaged", `${assetId}.png`);
|
|
22800
|
+
const outFile = path45.resolve(ctx.importDir, rel);
|
|
22801
|
+
await mkdir17(path45.dirname(outFile), { recursive: true });
|
|
22802
|
+
await writeFile22(outFile, buf);
|
|
21720
22803
|
ctx.manifest.assets[assetId] = {
|
|
21721
22804
|
prompt: orphan.prompt,
|
|
21722
22805
|
promptByStyle: {},
|
|
@@ -21748,7 +22831,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
21748
22831
|
sourceUrl: durableSource,
|
|
21749
22832
|
sourceUrls: durableSource ? [{ url: durableSource }] : [],
|
|
21750
22833
|
outputs: [{
|
|
21751
|
-
path: portableOutputPath(outFile,
|
|
22834
|
+
path: portableOutputPath(outFile, path45.dirname(ctx.manifestPath)),
|
|
21752
22835
|
sha256: sha256(buf)
|
|
21753
22836
|
}],
|
|
21754
22837
|
submittedAt: orphan.createdAt,
|
|
@@ -21772,9 +22855,9 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
21772
22855
|
}
|
|
21773
22856
|
}
|
|
21774
22857
|
await applyTags(provider, decisions, existingTags, { onProgress: log, characters: characterMembers });
|
|
21775
|
-
const raw = JSON.parse(await
|
|
22858
|
+
const raw = JSON.parse(await readFile33(ctx.manifestPath, "utf8"));
|
|
21776
22859
|
for (const id of importedAssetIds) raw.assets[id] = ctx.manifest.assets[id];
|
|
21777
|
-
await
|
|
22860
|
+
await writeFile22(ctx.manifestPath, JSON.stringify(raw, null, 2) + "\n");
|
|
21778
22861
|
await saveLock(ctx.lockPath, ctx.lock);
|
|
21779
22862
|
if (characterAssetIds.length) result.characterAssetIds = characterAssetIds;
|
|
21780
22863
|
return result;
|
|
@@ -21882,6 +22965,7 @@ async function workspaceStatus(ws, dir) {
|
|
|
21882
22965
|
};
|
|
21883
22966
|
}
|
|
21884
22967
|
export {
|
|
22968
|
+
ASSET_KINDS,
|
|
21885
22969
|
AssetBatchSchema,
|
|
21886
22970
|
AssetDeriveSchema,
|
|
21887
22971
|
AssetExternalSchema,
|
|
@@ -21908,6 +22992,10 @@ export {
|
|
|
21908
22992
|
EDITOR_PIN,
|
|
21909
22993
|
EDITOR_RELEASE_BASE,
|
|
21910
22994
|
EXIT_CODES,
|
|
22995
|
+
EXPAND_DIRECTIONS,
|
|
22996
|
+
EXPAND_MAX_COST,
|
|
22997
|
+
EXPAND_MIN_COST,
|
|
22998
|
+
EXPORT_FORMATS,
|
|
21911
22999
|
EditorInstallError,
|
|
21912
23000
|
FAKE_PNG,
|
|
21913
23001
|
FONT_COST_GENERATIONS,
|
|
@@ -21922,6 +23010,7 @@ export {
|
|
|
21922
23010
|
HAND_EDIT_DIR,
|
|
21923
23011
|
HISTORY_ENV,
|
|
21924
23012
|
HandEditCompanionSchema,
|
|
23013
|
+
IMPORT_MAX_SIDE,
|
|
21925
23014
|
ImageQualityMetricsSchema,
|
|
21926
23015
|
InheritedStyleSchema,
|
|
21927
23016
|
LockEntrySchema,
|
|
@@ -21934,6 +23023,14 @@ export {
|
|
|
21934
23023
|
MAX_RETRIES,
|
|
21935
23024
|
MEMBER_SET_REVISION_MODES,
|
|
21936
23025
|
MIRRORED_DIRECTION,
|
|
23026
|
+
MIRROR_DIRECTIONS,
|
|
23027
|
+
MUSIC_COST_GENERATIONS,
|
|
23028
|
+
MUSIC_LOOP_COST_GENERATIONS,
|
|
23029
|
+
MUSIC_LOOP_MIN_BODY_SECONDS,
|
|
23030
|
+
MUSIC_MAX_BPM,
|
|
23031
|
+
MUSIC_MAX_SECONDS,
|
|
23032
|
+
MUSIC_MIN_BPM,
|
|
23033
|
+
MUSIC_MIN_SECONDS,
|
|
21937
23034
|
ManifestDriftError,
|
|
21938
23035
|
ManifestEditError,
|
|
21939
23036
|
ManifestEditSchema,
|
|
@@ -21951,6 +23048,7 @@ export {
|
|
|
21951
23048
|
OverwriteRefusedError,
|
|
21952
23049
|
PIXELATE_COST_GENERATIONS,
|
|
21953
23050
|
PIXELATE_MAX_SIDE,
|
|
23051
|
+
PIXELATE_PRO_COST_GENERATIONS,
|
|
21954
23052
|
PIXELLAB_MCP_URL,
|
|
21955
23053
|
PIXEL_ART_FIXER_REVISION,
|
|
21956
23054
|
PIXEL_ART_FIXER_URL,
|
|
@@ -21971,6 +23069,8 @@ export {
|
|
|
21971
23069
|
RevisionDitheringSchema,
|
|
21972
23070
|
RevisionModeSchema,
|
|
21973
23071
|
RevisionSchema,
|
|
23072
|
+
SFX_MAX_SECONDS,
|
|
23073
|
+
SFX_MIN_SECONDS,
|
|
21974
23074
|
SHEET_FORMATS,
|
|
21975
23075
|
ScenarioProvider,
|
|
21976
23076
|
StyleInputSchema,
|
|
@@ -21979,6 +23079,10 @@ export {
|
|
|
21979
23079
|
TerrainConnectSchema,
|
|
21980
23080
|
TerrainLinkSchema,
|
|
21981
23081
|
TerrainSideSchema,
|
|
23082
|
+
UI_STATES_COSTS,
|
|
23083
|
+
UI_STATES_MAX_COST,
|
|
23084
|
+
UI_STATES_MAX_ELEMENTS,
|
|
23085
|
+
UI_STATES_MAX_STATES,
|
|
21982
23086
|
UNZOOM_MAX_AREA,
|
|
21983
23087
|
UNZOOM_MIN_SIDE,
|
|
21984
23088
|
UiElementSchema,
|
|
@@ -22008,8 +23112,10 @@ export {
|
|
|
22008
23112
|
cacheFileName,
|
|
22009
23113
|
candidateCount,
|
|
22010
23114
|
characterDirections,
|
|
23115
|
+
checkExportBytes,
|
|
22011
23116
|
checkQualityBaseline,
|
|
22012
23117
|
checkQualityRecord,
|
|
23118
|
+
checkUiInsets,
|
|
22013
23119
|
clientFromEnv,
|
|
22014
23120
|
colorDistance,
|
|
22015
23121
|
countNumberedDescriptions,
|
|
@@ -22018,6 +23124,7 @@ export {
|
|
|
22018
23124
|
createGalleryEditorHandlers,
|
|
22019
23125
|
createGenerateHandlers,
|
|
22020
23126
|
createProvider,
|
|
23127
|
+
createUiStates,
|
|
22021
23128
|
currentEntryOutputPath,
|
|
22022
23129
|
currentOutputPath,
|
|
22023
23130
|
defaultNormalMapOut,
|
|
@@ -22026,6 +23133,7 @@ export {
|
|
|
22026
23133
|
defaultUnzoomOut,
|
|
22027
23134
|
describeVfx,
|
|
22028
23135
|
detachHandEdit,
|
|
23136
|
+
detectAudioFormat,
|
|
22029
23137
|
detectMediaType,
|
|
22030
23138
|
doctor,
|
|
22031
23139
|
editorBaseUrl,
|
|
@@ -22036,7 +23144,10 @@ export {
|
|
|
22036
23144
|
errorCode,
|
|
22037
23145
|
evaluateAudit,
|
|
22038
23146
|
exitCodeFor,
|
|
23147
|
+
expandObject,
|
|
22039
23148
|
expectedOutputPath,
|
|
23149
|
+
exportAssetFile,
|
|
23150
|
+
exportOutPath,
|
|
22040
23151
|
exportTileset,
|
|
22041
23152
|
fallbackOutputRole,
|
|
22042
23153
|
fetchAssets,
|
|
@@ -22050,6 +23161,8 @@ export {
|
|
|
22050
23161
|
galleryMediaId,
|
|
22051
23162
|
galleryMediaRoute,
|
|
22052
23163
|
generateFont,
|
|
23164
|
+
generateMusic,
|
|
23165
|
+
generateSoundEffect,
|
|
22053
23166
|
generationCost,
|
|
22054
23167
|
groupOrphansByStyle,
|
|
22055
23168
|
handEditBase,
|
|
@@ -22064,6 +23177,7 @@ export {
|
|
|
22064
23177
|
idFromPrompt,
|
|
22065
23178
|
imageMetadata,
|
|
22066
23179
|
importLocal,
|
|
23180
|
+
importObjectFile,
|
|
22067
23181
|
inspectCaches,
|
|
22068
23182
|
inspectQualityProfile,
|
|
22069
23183
|
inspectRevisionReadiness,
|
|
@@ -22095,6 +23209,8 @@ export {
|
|
|
22095
23209
|
mergePalettes,
|
|
22096
23210
|
mountSprites,
|
|
22097
23211
|
mountStyle,
|
|
23212
|
+
musicCost,
|
|
23213
|
+
musicOutputPaths,
|
|
22098
23214
|
normalMapFile,
|
|
22099
23215
|
normalMapResultPng,
|
|
22100
23216
|
normalMapSizeProblem,
|
|
@@ -22111,10 +23227,14 @@ export {
|
|
|
22111
23227
|
packStyle,
|
|
22112
23228
|
paletteDistance,
|
|
22113
23229
|
parentAssetId,
|
|
23230
|
+
parseCanvasSize,
|
|
22114
23231
|
parseLock,
|
|
22115
23232
|
parseMcpBody,
|
|
22116
23233
|
parseProFlashQuote,
|
|
22117
23234
|
parseTerrainDescriptions,
|
|
23235
|
+
parseUiBox,
|
|
23236
|
+
parseUiInsets,
|
|
23237
|
+
parseUiState,
|
|
22118
23238
|
parseVfxArtistResult,
|
|
22119
23239
|
parseVfxExport,
|
|
22120
23240
|
parseVfxRecipe,
|
|
@@ -22132,6 +23252,8 @@ export {
|
|
|
22132
23252
|
proportionsPayload,
|
|
22133
23253
|
providerCredentialEnvs,
|
|
22134
23254
|
providerFactory,
|
|
23255
|
+
pullExpansionReview,
|
|
23256
|
+
pullUiAsset,
|
|
22135
23257
|
pushTags,
|
|
22136
23258
|
qualityFrameOutputPath,
|
|
22137
23259
|
qualityRecordPath,
|
|
@@ -22197,6 +23319,8 @@ export {
|
|
|
22197
23319
|
slugify,
|
|
22198
23320
|
snapshotQualityBaseline,
|
|
22199
23321
|
snapshotQualityCases,
|
|
23322
|
+
soundEffectCost,
|
|
23323
|
+
soundEffectOutputPaths,
|
|
22200
23324
|
sourceIsStem,
|
|
22201
23325
|
sourceOutputPath,
|
|
22202
23326
|
specHash,
|
|
@@ -22216,8 +23340,10 @@ export {
|
|
|
22216
23340
|
toPortablePath,
|
|
22217
23341
|
totalSpend,
|
|
22218
23342
|
uiElementCandidateCount,
|
|
23343
|
+
uiStateElements,
|
|
22219
23344
|
unzoomFile,
|
|
22220
23345
|
upsert,
|
|
23346
|
+
validateAudio,
|
|
22221
23347
|
validateCostEstimate,
|
|
22222
23348
|
validateMedia,
|
|
22223
23349
|
validateWorkspace,
|