pixelkiln 0.148.0 → 0.149.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/dist/cli.js +719 -381
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +551 -336
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -14
- package/dist/index.d.ts +76 -14
- package/dist/index.js +488 -273
- package/dist/index.js.map +1 -1
- package/docs/CHARACTERS.md +13 -3
- package/docs/CLI.md +19 -1
- package/docs/PAPERDOLL.md +97 -9
- package/package.json +1 -1
- package/skills/pixelkiln/references/paperdoll.md +15 -0
package/dist/index.cjs
CHANGED
|
@@ -929,6 +929,13 @@ var CharacterLayerSchema = import_zod.z.object({
|
|
|
929
929
|
skin: import_zod.z.array(HexColorSchema).min(1).max(64).optional(),
|
|
930
930
|
/** The stand-in colour skin is painted before the provider sees it. Default cyan. */
|
|
931
931
|
key: HexColorSchema.optional(),
|
|
932
|
+
/**
|
|
933
|
+
* Key every opaque pixel inside the mask, whatever its colour, not only
|
|
934
|
+
* skin. For a base that wears underwear (or anything else it cannot be
|
|
935
|
+
* drawn without): what it wears is body to dress over, so the outfit
|
|
936
|
+
* covers it instead of being drawn around it. Default false.
|
|
937
|
+
*/
|
|
938
|
+
cover: import_zod.z.boolean().optional(),
|
|
932
939
|
/**
|
|
933
940
|
* Remove animation ghosts from the loops before dressing them, judged
|
|
934
941
|
* against the stills among `of` (bases and states). Default true; it has
|
|
@@ -969,7 +976,7 @@ var CharacterLayerSchema = import_zod.z.object({
|
|
|
969
976
|
attach: CharacterAttachSchema.optional()
|
|
970
977
|
}).strict().superRefine((layer, context) => {
|
|
971
978
|
if (!layer.attach) return;
|
|
972
|
-
for (const field of ["mask", "keyed", "skin", "key", "clean", "region"]) {
|
|
979
|
+
for (const field of ["mask", "keyed", "skin", "key", "cover", "clean", "region"]) {
|
|
973
980
|
if (layer[field] !== void 0) {
|
|
974
981
|
context.addIssue({
|
|
975
982
|
code: import_zod.z.ZodIssueCode.custom,
|
|
@@ -1973,7 +1980,7 @@ var AssetDeriveSchema = import_zod.z.object({
|
|
|
1973
1980
|
/** key-skin: how far a pixel may sit from a `skin` colour. despeckle: how near a reference colour must be to vouch for a pixel. */
|
|
1974
1981
|
tolerance: import_zod.z.number().min(0).max(442).optional()
|
|
1975
1982
|
}).strict().superRefine((derive, context) => {
|
|
1976
|
-
const issue = (message6,
|
|
1983
|
+
const issue = (message6, path55) => context.addIssue({ code: import_zod.z.ZodIssueCode.custom, message: message6, path: [path55] });
|
|
1977
1984
|
if (Boolean(derive.from) === Boolean(derive.file)) {
|
|
1978
1985
|
issue("name exactly one source: `from` (an asset in this style) or `file` (a committed PNG)", derive.from ? "file" : "from");
|
|
1979
1986
|
}
|
|
@@ -3552,9 +3559,9 @@ var PixelLabClient = class {
|
|
|
3552
3559
|
apiKey;
|
|
3553
3560
|
http;
|
|
3554
3561
|
/** Retries transport failures, 429, and 5xx; see http.ts for the policy. */
|
|
3555
|
-
async request(
|
|
3562
|
+
async request(path55, init) {
|
|
3556
3563
|
const auth = this.apiKey.startsWith("Bearer ") ? this.apiKey : `Bearer ${this.apiKey}`;
|
|
3557
|
-
const res = await this.http(`${BASE}${
|
|
3564
|
+
const res = await this.http(`${BASE}${path55}`, {
|
|
3558
3565
|
...init,
|
|
3559
3566
|
headers: {
|
|
3560
3567
|
Authorization: auth,
|
|
@@ -3565,13 +3572,13 @@ var PixelLabClient = class {
|
|
|
3565
3572
|
const text = await res.text();
|
|
3566
3573
|
if (!res.ok) {
|
|
3567
3574
|
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' : "";
|
|
3568
|
-
throw new PixelLabError(`${init?.method ?? "GET"} ${
|
|
3575
|
+
throw new PixelLabError(`${init?.method ?? "GET"} ${path55} \u2192 ${res.status}${hint}${refusalReason(res.status, text)}`, res.status, text);
|
|
3569
3576
|
}
|
|
3570
3577
|
if (!text) return {};
|
|
3571
3578
|
try {
|
|
3572
3579
|
return JSON.parse(text);
|
|
3573
3580
|
} catch {
|
|
3574
|
-
throw new Error(`${init?.method ?? "GET"} ${
|
|
3581
|
+
throw new Error(`${init?.method ?? "GET"} ${path55} returned invalid JSON`);
|
|
3575
3582
|
}
|
|
3576
3583
|
}
|
|
3577
3584
|
async balance() {
|
|
@@ -4123,10 +4130,10 @@ var PixelLabClient = class {
|
|
|
4123
4130
|
const palette = args.paletteSwatchBase64 ? { color_image: { type: "base64", base64: args.paletteSwatchBase64, format: "png" }, force_colors: true } : {};
|
|
4124
4131
|
const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
|
|
4125
4132
|
const south = args.reference?.south;
|
|
4126
|
-
let
|
|
4133
|
+
let path55;
|
|
4127
4134
|
let body;
|
|
4128
4135
|
if (args.mode === "v3") {
|
|
4129
|
-
|
|
4136
|
+
path55 = "/create-character-v3";
|
|
4130
4137
|
body = {
|
|
4131
4138
|
description: args.description,
|
|
4132
4139
|
image_size: imageSize,
|
|
@@ -4140,7 +4147,7 @@ var PixelLabClient = class {
|
|
|
4140
4147
|
...args.enhancePrompt ? { enhance_prompt: true } : {}
|
|
4141
4148
|
};
|
|
4142
4149
|
} else if (args.mode === "pro-flash") {
|
|
4143
|
-
|
|
4150
|
+
path55 = "/create-character-pro-flash";
|
|
4144
4151
|
const traits = args.styleTraits;
|
|
4145
4152
|
body = {
|
|
4146
4153
|
description: args.description,
|
|
@@ -4164,7 +4171,7 @@ var PixelLabClient = class {
|
|
|
4164
4171
|
} : {}
|
|
4165
4172
|
};
|
|
4166
4173
|
} else if (args.mode === "pro") {
|
|
4167
|
-
|
|
4174
|
+
path55 = "/create-character-pro";
|
|
4168
4175
|
body = {
|
|
4169
4176
|
description: args.description,
|
|
4170
4177
|
image_size: imageSize,
|
|
@@ -4178,7 +4185,7 @@ var PixelLabClient = class {
|
|
|
4178
4185
|
...!south && args.styleCharacterId ? { style_character_id: args.styleCharacterId } : {}
|
|
4179
4186
|
};
|
|
4180
4187
|
} else {
|
|
4181
|
-
|
|
4188
|
+
path55 = args.directions === 4 ? "/create-character-with-4-directions" : "/create-character-with-8-directions";
|
|
4182
4189
|
body = {
|
|
4183
4190
|
description: args.description,
|
|
4184
4191
|
image_size: imageSize,
|
|
@@ -4196,8 +4203,8 @@ var PixelLabClient = class {
|
|
|
4196
4203
|
};
|
|
4197
4204
|
}
|
|
4198
4205
|
if (args.mode === "pro" || args.mode === "pro-flash") Object.assign(body, targetPaletteBody(args.targetPalette));
|
|
4199
|
-
const raw = await this.request(
|
|
4200
|
-
return validateResponse(CharacterSubmitSchema, raw,
|
|
4206
|
+
const raw = await this.request(path55, { method: "POST", body: JSON.stringify(body) });
|
|
4207
|
+
return validateResponse(CharacterSubmitSchema, raw, path55.slice(1));
|
|
4201
4208
|
}
|
|
4202
4209
|
/** A text edit of an existing character, applied to every direction and stored as a sibling. */
|
|
4203
4210
|
async createCharacterState(args) {
|
|
@@ -5251,8 +5258,8 @@ var PixelLabClient = class {
|
|
|
5251
5258
|
}
|
|
5252
5259
|
/** Irreversible: the character, its states are separate records, and its animations. Checks `success` like `deleteObject`. */
|
|
5253
5260
|
async deleteCharacter(characterId) {
|
|
5254
|
-
const
|
|
5255
|
-
return deleteSucceeded(await this.request(
|
|
5261
|
+
const path55 = `/characters/${encodeURIComponent(characterId)}`;
|
|
5262
|
+
return deleteSucceeded(await this.request(path55, { method: "DELETE" }), `DELETE ${path55}`);
|
|
5256
5263
|
}
|
|
5257
5264
|
setCharacterTags(characterId, tags) {
|
|
5258
5265
|
return this.request(`/characters/${encodeURIComponent(characterId)}/tags`, {
|
|
@@ -5888,10 +5895,10 @@ function normalizeHex(value) {
|
|
|
5888
5895
|
function sha256(data) {
|
|
5889
5896
|
return (0, import_node_crypto.createHash)("sha256").update(data).digest("hex");
|
|
5890
5897
|
}
|
|
5891
|
-
async function sha256File(
|
|
5898
|
+
async function sha256File(path55) {
|
|
5892
5899
|
return new Promise((resolve, reject) => {
|
|
5893
5900
|
const hash = (0, import_node_crypto.createHash)("sha256");
|
|
5894
|
-
const stream = (0, import_node_fs.createReadStream)(
|
|
5901
|
+
const stream = (0, import_node_fs.createReadStream)(path55);
|
|
5895
5902
|
stream.on("data", (chunk2) => hash.update(chunk2));
|
|
5896
5903
|
stream.on("error", reject);
|
|
5897
5904
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -6034,6 +6041,8 @@ function specHash(spec, styleImageHashes, providerOptionIdentity = spec.provider
|
|
|
6034
6041
|
keyed: spec.character.layer.keyed?.sha256,
|
|
6035
6042
|
skin: spec.character.layer.skin?.map(normalizeHex),
|
|
6036
6043
|
key: spec.character.layer.key ? normalizeHex(spec.character.layer.key) : void 0,
|
|
6044
|
+
// Omitted unless set so a layer made before it existed keeps its identity.
|
|
6045
|
+
cover: spec.character.layer.cover,
|
|
6037
6046
|
clean: spec.character.layer.clean,
|
|
6038
6047
|
columns: spec.character.layer.columns,
|
|
6039
6048
|
// Omitted at their defaults so a layer made before these existed keeps its identity.
|
|
@@ -7261,6 +7270,7 @@ function hsv(r, g, b) {
|
|
|
7261
7270
|
}
|
|
7262
7271
|
var DEFAULT_KEY = "#00ffff";
|
|
7263
7272
|
var KEY_SATURATION = 0.85;
|
|
7273
|
+
var COVER_FLOOR = 96;
|
|
7264
7274
|
function keySkin(png, options = {}) {
|
|
7265
7275
|
const image = decodePng(png);
|
|
7266
7276
|
const key3 = parseHex(options.key ?? DEFAULT_KEY);
|
|
@@ -7313,23 +7323,103 @@ function neckRow(image, cell = whole(image)) {
|
|
|
7313
7323
|
}
|
|
7314
7324
|
return best === null ? null : cell.y + best;
|
|
7315
7325
|
}
|
|
7316
|
-
function
|
|
7326
|
+
function longestRun(image, cell, y) {
|
|
7327
|
+
let best = null;
|
|
7328
|
+
let start = -1;
|
|
7329
|
+
for (let x = 0; x <= cell.width; x++) {
|
|
7330
|
+
const on = x < cell.width && opaque(image, cell.x + x, cell.y + y);
|
|
7331
|
+
if (on && start < 0) start = x;
|
|
7332
|
+
if (!on && start >= 0) {
|
|
7333
|
+
if (!best || x - 1 - start > best[1] - best[0]) best = [start, x - 1];
|
|
7334
|
+
start = -1;
|
|
7335
|
+
}
|
|
7336
|
+
}
|
|
7337
|
+
return best;
|
|
7338
|
+
}
|
|
7339
|
+
var median = (values) => {
|
|
7340
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
7341
|
+
return sorted[Math.floor((sorted.length - 1) / 2)];
|
|
7342
|
+
};
|
|
7343
|
+
function layerMask(sheet, cells, region = "body") {
|
|
7317
7344
|
const image = decodePng(sheet);
|
|
7318
7345
|
const out = Buffer.alloc(image.width * image.height * 4);
|
|
7319
7346
|
for (let i = 3; i < out.length; i += 4) out[i] = 255;
|
|
7320
|
-
|
|
7347
|
+
const all = cells ?? [whole(image)];
|
|
7348
|
+
const first = all.map((cell) => {
|
|
7349
|
+
let top = -1;
|
|
7350
|
+
let bottom = -1;
|
|
7351
|
+
for (let y = 0; y < cell.height && top < 0; y++) if (longestRun(image, cell, y)) top = y;
|
|
7352
|
+
for (let y = cell.height - 1; y >= 0 && bottom < 0; y--) if (longestRun(image, cell, y)) bottom = y;
|
|
7353
|
+
if (top < 0) return null;
|
|
7321
7354
|
const neck = neckRow(image, cell);
|
|
7322
|
-
|
|
7323
|
-
|
|
7324
|
-
|
|
7355
|
+
return { top, bottom, detected: neck === null ? null : neck - cell.y };
|
|
7356
|
+
});
|
|
7357
|
+
const seen = first.filter((frame) => frame !== null);
|
|
7358
|
+
const offsets = seen.filter((frame) => frame.detected !== null).map((frame) => frame.detected - frame.top);
|
|
7359
|
+
if (!offsets.length) return { png: encodeRgbaPng(image.width, image.height, out), necks: all.map(() => null) };
|
|
7360
|
+
const drop = median(offsets);
|
|
7361
|
+
const heads = seen.map((frame) => {
|
|
7362
|
+
const cell = all[first.indexOf(frame)];
|
|
7363
|
+
const run = longestRun(image, cell, Math.min(frame.bottom, frame.top + Math.floor(drop / 2)));
|
|
7364
|
+
return run ? run[1] - run[0] + 1 : 1;
|
|
7365
|
+
});
|
|
7366
|
+
const wide = Math.max(1, Math.ceil(median(heads) / 2));
|
|
7367
|
+
const necks = all.map((cell, index) => {
|
|
7368
|
+
const frame = first[index];
|
|
7369
|
+
if (!frame) return null;
|
|
7370
|
+
let head = frame.top;
|
|
7371
|
+
for (let y = frame.top; y <= frame.bottom; y++) {
|
|
7372
|
+
const run = longestRun(image, cell, y);
|
|
7373
|
+
if (run && run[1] - run[0] + 1 >= wide) {
|
|
7374
|
+
head = y;
|
|
7375
|
+
break;
|
|
7376
|
+
}
|
|
7377
|
+
}
|
|
7378
|
+
const row = Math.min(head + drop, frame.bottom);
|
|
7379
|
+
const slack = Math.max(2, Math.round((frame.bottom - frame.top + 1) * 0.06));
|
|
7380
|
+
const corrected = frame.detected === null || Math.abs(frame.detected - row) > slack;
|
|
7381
|
+
const from = region === "head" ? 0 : row + 1;
|
|
7382
|
+
const to = region === "head" ? row + 1 : cell.height;
|
|
7325
7383
|
for (let y = from; y < to; y++) {
|
|
7326
|
-
for (let x =
|
|
7327
|
-
if (region === "body" && !opaque(image, x, y)) continue;
|
|
7328
|
-
out.fill(255, at(image, x, y), at(image, x, y) + 3);
|
|
7384
|
+
for (let x = 0; x < cell.width; x++) {
|
|
7385
|
+
if (region === "body" && !opaque(image, cell.x + x, cell.y + y)) continue;
|
|
7386
|
+
out.fill(255, at(image, cell.x + x, cell.y + y), at(image, cell.x + x, cell.y + y) + 3);
|
|
7387
|
+
}
|
|
7388
|
+
}
|
|
7389
|
+
if (region === "body") {
|
|
7390
|
+
const seed = longestRun(image, cell, head);
|
|
7391
|
+
const inHead = new Uint8Array(cell.width * (row + 1));
|
|
7392
|
+
const queue = [];
|
|
7393
|
+
for (let x = seed[0]; x <= seed[1]; x++) {
|
|
7394
|
+
inHead[head * cell.width + x] = 1;
|
|
7395
|
+
queue.push([x, head]);
|
|
7396
|
+
}
|
|
7397
|
+
let left = seed[0];
|
|
7398
|
+
let right = seed[1];
|
|
7399
|
+
while (queue.length) {
|
|
7400
|
+
const [x, y] = queue.pop();
|
|
7401
|
+
left = Math.min(left, x);
|
|
7402
|
+
right = Math.max(right, x);
|
|
7403
|
+
for (const [dx, dy] of STEPS) {
|
|
7404
|
+
const nx = x + dx;
|
|
7405
|
+
const ny = y + dy;
|
|
7406
|
+
if (nx < 0 || nx >= cell.width || ny < 0 || ny > row) continue;
|
|
7407
|
+
if (inHead[ny * cell.width + nx] || !opaque(image, cell.x + nx, cell.y + ny)) continue;
|
|
7408
|
+
inHead[ny * cell.width + nx] = 1;
|
|
7409
|
+
queue.push([nx, ny]);
|
|
7410
|
+
}
|
|
7411
|
+
}
|
|
7412
|
+
for (let y = 0; y <= row; y++) {
|
|
7413
|
+
for (let x = 0; x < cell.width; x++) {
|
|
7414
|
+
if (x >= left - 1 && x <= right + 1) continue;
|
|
7415
|
+
if (!opaque(image, cell.x + x, cell.y + y)) continue;
|
|
7416
|
+
out.fill(255, at(image, cell.x + x, cell.y + y), at(image, cell.x + x, cell.y + y) + 3);
|
|
7417
|
+
}
|
|
7329
7418
|
}
|
|
7330
7419
|
}
|
|
7331
|
-
|
|
7332
|
-
|
|
7420
|
+
return { row, head, detected: frame.detected, corrected };
|
|
7421
|
+
});
|
|
7422
|
+
return { png: encodeRgbaPng(image.width, image.height, out), necks };
|
|
7333
7423
|
}
|
|
7334
7424
|
function extractLayer(result, keyed, mask, options = {}) {
|
|
7335
7425
|
const out = decodePng(result);
|
|
@@ -7362,10 +7452,10 @@ function despeckle(png, options) {
|
|
|
7362
7452
|
for (const still of options.reference) {
|
|
7363
7453
|
const { pixels } = decodePng(still);
|
|
7364
7454
|
for (let i = 0; i < pixels.length; i += 4) {
|
|
7365
|
-
if (pixels[i + 3] === 0
|
|
7455
|
+
if (pixels[i + 3] === 0) continue;
|
|
7366
7456
|
const rgb = pixels[i] << 16 | pixels[i + 1] << 8 | pixels[i + 2];
|
|
7367
7457
|
palette.set(rgb, (palette.get(rgb) ?? 0) + 1);
|
|
7368
|
-
total++;
|
|
7458
|
+
if (!outline(pixels, i)) total++;
|
|
7369
7459
|
}
|
|
7370
7460
|
}
|
|
7371
7461
|
if (!total) throw new Error("the reference stills have no opaque pixels that are not outline");
|
|
@@ -7425,7 +7515,7 @@ function despeckle(png, options) {
|
|
|
7425
7515
|
const strange = run.filter(([x, y]) => foreign(at(image, x, y))).length / run.length > 0.5;
|
|
7426
7516
|
let debris;
|
|
7427
7517
|
const exposed = run.some(([x, y]) => STEPS.some(([dx, dy]) => open(x + dx, y + dy)));
|
|
7428
|
-
if (strange &&
|
|
7518
|
+
if (strange && run.length > limb) {
|
|
7429
7519
|
debris = false;
|
|
7430
7520
|
limbs.add(index);
|
|
7431
7521
|
} else if (exposed) {
|
|
@@ -7460,6 +7550,7 @@ function despeckle(png, options) {
|
|
|
7460
7550
|
if (src[at(image, x, y) + 3] > 0 && out[at(image, x, y) + 3] === 0) frontier.push([x, y]);
|
|
7461
7551
|
}
|
|
7462
7552
|
}
|
|
7553
|
+
const seeds = frontier.length;
|
|
7463
7554
|
for (let n = 0; n < frontier.length; n++) {
|
|
7464
7555
|
const [fx, fy] = frontier[n];
|
|
7465
7556
|
for (let dy = -1; dy <= 1; dy++) {
|
|
@@ -7483,6 +7574,31 @@ function despeckle(png, options) {
|
|
|
7483
7574
|
}
|
|
7484
7575
|
}
|
|
7485
7576
|
}
|
|
7577
|
+
const chained = new Set(frontier.slice(seeds).map(([x, y]) => local(x, y)));
|
|
7578
|
+
const visited = /* @__PURE__ */ new Set();
|
|
7579
|
+
for (const [sx, sy] of frontier.slice(seeds)) {
|
|
7580
|
+
if (visited.has(local(sx, sy))) continue;
|
|
7581
|
+
const group = [[sx, sy]];
|
|
7582
|
+
visited.add(local(sx, sy));
|
|
7583
|
+
for (let n = 0; n < group.length; n++) {
|
|
7584
|
+
const [gx, gy] = group[n];
|
|
7585
|
+
for (let dy = -1; dy <= 1; dy++) {
|
|
7586
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
7587
|
+
const x = gx + dx;
|
|
7588
|
+
const y = gy + dy;
|
|
7589
|
+
if (!inside(cell, x, y) || visited.has(local(x, y)) || !chained.has(local(x, y))) continue;
|
|
7590
|
+
visited.add(local(x, y));
|
|
7591
|
+
group.push([x, y]);
|
|
7592
|
+
}
|
|
7593
|
+
}
|
|
7594
|
+
}
|
|
7595
|
+
if (group.length <= limb) continue;
|
|
7596
|
+
for (const [x, y] of group) {
|
|
7597
|
+
const i = at(image, x, y);
|
|
7598
|
+
src.copy(out, i, i, i + 4);
|
|
7599
|
+
removed--;
|
|
7600
|
+
}
|
|
7601
|
+
}
|
|
7486
7602
|
}
|
|
7487
7603
|
return { png: encodeRgbaPng(image.width, image.height, out), removed };
|
|
7488
7604
|
}
|
|
@@ -7598,23 +7714,55 @@ function buildLayerSheet(sources, options) {
|
|
|
7598
7714
|
}
|
|
7599
7715
|
return png;
|
|
7600
7716
|
};
|
|
7601
|
-
const
|
|
7717
|
+
const computed = options.mask ? void 0 : layerMask(sheetPng, frames.map((frame) => frame.cell), options.region);
|
|
7718
|
+
const mask = options.mask ? sized("mask", options.mask) : computed.png;
|
|
7719
|
+
const keyed = options.keyed ? void 0 : keyInsideMask(sheetPng, mask, { key: options.key, skin: options.skin, cover: options.cover });
|
|
7602
7720
|
return {
|
|
7603
7721
|
sheet: sheetPng,
|
|
7604
|
-
keyed: options.keyed ? sized("keyed sheet", options.keyed) :
|
|
7722
|
+
keyed: options.keyed ? sized("keyed sheet", options.keyed) : keyed.png,
|
|
7605
7723
|
mask,
|
|
7606
7724
|
frames,
|
|
7607
|
-
cleaned
|
|
7725
|
+
cleaned,
|
|
7726
|
+
...computed ? { necks: computed.necks } : {},
|
|
7727
|
+
...keyed ? { closed: keyed.closed } : {}
|
|
7608
7728
|
};
|
|
7609
7729
|
}
|
|
7610
7730
|
function keyInsideMask(sheet, mask, options) {
|
|
7611
7731
|
const original = decodePng(sheet);
|
|
7612
|
-
const keyed = decodePng(keySkin(sheet, options));
|
|
7613
7732
|
const allowed = decodePng(mask);
|
|
7733
|
+
const key3 = parseHex(options.key ?? DEFAULT_KEY);
|
|
7734
|
+
const keyed = options.cover ? { ...original, pixels: Buffer.from(original.pixels) } : decodePng(keySkin(sheet, options));
|
|
7735
|
+
const paint = (i, lift) => {
|
|
7736
|
+
const brightest = Math.max(original.pixels[i], original.pixels[i + 1], original.pixels[i + 2]);
|
|
7737
|
+
const value = lift ? COVER_FLOOR + Math.floor(brightest * (255 - COVER_FLOOR) / 255) : brightest;
|
|
7738
|
+
const tint = (channel) => Math.floor(value * (1 - KEY_SATURATION + KEY_SATURATION * channel / 255));
|
|
7739
|
+
keyed.pixels[i] = tint(key3.r);
|
|
7740
|
+
keyed.pixels[i + 1] = tint(key3.g);
|
|
7741
|
+
keyed.pixels[i + 2] = tint(key3.b);
|
|
7742
|
+
};
|
|
7614
7743
|
for (let i = 0; i < keyed.pixels.length; i += 4) {
|
|
7615
7744
|
if (allowed.pixels[i] !== 255) original.pixels.copy(keyed.pixels, i, i, i + 4);
|
|
7745
|
+
else if (options.cover && original.pixels[i + 3]) paint(i, true);
|
|
7746
|
+
}
|
|
7747
|
+
let closed = 0;
|
|
7748
|
+
if (!options.cover && !options.skin) {
|
|
7749
|
+
const changed = (i) => original.pixels[i + 3] > 0 && original.pixels.compare(keyed.pixels, i, i + 3, i, i + 3) !== 0;
|
|
7750
|
+
const holes = [];
|
|
7751
|
+
for (let y = 0; y < keyed.height; y++) {
|
|
7752
|
+
for (let x = 0; x < keyed.width; x++) {
|
|
7753
|
+
const i = (y * keyed.width + x) * 4;
|
|
7754
|
+
if (allowed.pixels[i] !== 255 || !original.pixels[i + 3] || changed(i)) continue;
|
|
7755
|
+
const near = (dir) => [1, 2, 3].some((k) => {
|
|
7756
|
+
const nx = x + dir * k;
|
|
7757
|
+
return nx >= 0 && nx < keyed.width && allowed.pixels[i + dir * k * 4] === 255 && changed(i + dir * k * 4);
|
|
7758
|
+
});
|
|
7759
|
+
if (near(-1) && near(1)) holes.push(i);
|
|
7760
|
+
}
|
|
7761
|
+
}
|
|
7762
|
+
for (const i of holes) paint(i, false);
|
|
7763
|
+
closed = holes.length;
|
|
7616
7764
|
}
|
|
7617
|
-
return encodeRgbaPng(keyed.width, keyed.height, keyed.pixels);
|
|
7765
|
+
return { png: encodeRgbaPng(keyed.width, keyed.height, keyed.pixels), closed };
|
|
7618
7766
|
}
|
|
7619
7767
|
var SPECK = 8;
|
|
7620
7768
|
var BLEED = 20;
|
|
@@ -8286,10 +8434,13 @@ function applyPostprocess(bytes, mediaType, record, reference = [], role) {
|
|
|
8286
8434
|
if (mediaType !== MediaType.PNG || !record?.palette && !record?.despeckle && !record?.offset) return { bytes, changed: false };
|
|
8287
8435
|
let out = bytes;
|
|
8288
8436
|
let removed = 0;
|
|
8437
|
+
let opaque2 = 0;
|
|
8289
8438
|
if (record.despeckle) {
|
|
8290
8439
|
if (!reference.length) throw new Error(`cleaning needs the rotations of ${record.despeckle.of}, and none were given`);
|
|
8291
8440
|
const cleaned = despeckle(out, { reference });
|
|
8292
8441
|
if (cleaned.removed) {
|
|
8442
|
+
const { pixels } = decodePng(out);
|
|
8443
|
+
for (let i = 3; i < pixels.length; i += 4) if (pixels[i] > 0) opaque2++;
|
|
8293
8444
|
out = cleaned.png;
|
|
8294
8445
|
removed = cleaned.removed;
|
|
8295
8446
|
}
|
|
@@ -8313,8 +8464,9 @@ function applyPostprocess(bytes, mediaType, record, reference = [], role) {
|
|
|
8313
8464
|
}
|
|
8314
8465
|
}
|
|
8315
8466
|
if (!removed && !snapped && !moved) return { bytes, changed: false };
|
|
8316
|
-
return { bytes: out, changed: true, ...removed ? { removed } : {}, ...snapped ? { snapped } : {}, ...moved ? { moved } : {} };
|
|
8467
|
+
return { bytes: out, changed: true, ...removed ? { removed, opaque: opaque2 } : {}, ...snapped ? { snapped } : {}, ...moved ? { moved } : {} };
|
|
8317
8468
|
}
|
|
8469
|
+
var CLEAN_DAMAGE_SHARE = 0.03;
|
|
8318
8470
|
|
|
8319
8471
|
// src/pipeline/mirror.ts
|
|
8320
8472
|
function mirrorSourceHash(source) {
|
|
@@ -8735,6 +8887,37 @@ var GRASP_PROMPT = "Every cyan mannequin on this spritesheet carries the same it
|
|
|
8735
8887
|
function layerWorkDir(spec) {
|
|
8736
8888
|
return import_node_path7.default.join(spec.root, ".pixelkiln", "layers", spec.styleId, spec.assetId);
|
|
8737
8889
|
}
|
|
8890
|
+
function layerSheetFor(spec, outputs) {
|
|
8891
|
+
const character = spec.character;
|
|
8892
|
+
const layer = character.layer;
|
|
8893
|
+
const label = `${spec.styleId}/${spec.assetId}`;
|
|
8894
|
+
if (!outputs.length) throw new Error(`${label}: its layer sources have no downloaded frames`);
|
|
8895
|
+
const sources = outputs.map((output) => ({
|
|
8896
|
+
assetId: output.assetId ?? character.parentAssetId,
|
|
8897
|
+
...output.role ? { role: output.role } : {},
|
|
8898
|
+
png: (0, import_node_fs7.readFileSync)(output.path),
|
|
8899
|
+
still: output.still === true
|
|
8900
|
+
}));
|
|
8901
|
+
const supplied = (name, file) => {
|
|
8902
|
+
if (!file) return void 0;
|
|
8903
|
+
const bytes = (0, import_node_fs7.readFileSync)(file.path);
|
|
8904
|
+
if (sha256(bytes) !== file.sha256) throw new Error(`${label}: layer ${name} changed after the manifest was resolved: ${file.path}`);
|
|
8905
|
+
return bytes;
|
|
8906
|
+
};
|
|
8907
|
+
return buildLayerSheet(sources, {
|
|
8908
|
+
minSide: 32,
|
|
8909
|
+
maxSide: LAYER_SHEET_MAX_SIDE,
|
|
8910
|
+
columns: layer.columns,
|
|
8911
|
+
region: layer.region,
|
|
8912
|
+
padding: layer.padding,
|
|
8913
|
+
key: layer.key,
|
|
8914
|
+
skin: layer.skin,
|
|
8915
|
+
cover: layer.cover,
|
|
8916
|
+
reference: layer.clean ? sources.filter((source) => source.still).map((source) => source.png) : [],
|
|
8917
|
+
mask: supplied("mask", layer.mask),
|
|
8918
|
+
keyed: supplied("keyed sheet", layer.keyed)
|
|
8919
|
+
});
|
|
8920
|
+
}
|
|
8738
8921
|
var PixelLabProvider = class _PixelLabProvider {
|
|
8739
8922
|
/**
|
|
8740
8923
|
* `mcp` reaches the tools PixelLab offers only over MCP (the VFX
|
|
@@ -9626,31 +9809,7 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
9626
9809
|
const layer = character.layer;
|
|
9627
9810
|
const label = `${spec.styleId}/${spec.assetId}`;
|
|
9628
9811
|
const outputs = context?.parentOutputs ?? [];
|
|
9629
|
-
|
|
9630
|
-
const sources = outputs.map((output) => ({
|
|
9631
|
-
assetId: output.assetId ?? character.parentAssetId,
|
|
9632
|
-
...output.role ? { role: output.role } : {},
|
|
9633
|
-
png: (0, import_node_fs7.readFileSync)(output.path),
|
|
9634
|
-
still: output.still === true
|
|
9635
|
-
}));
|
|
9636
|
-
const supplied = (name2, file) => {
|
|
9637
|
-
if (!file) return void 0;
|
|
9638
|
-
const bytes = (0, import_node_fs7.readFileSync)(file.path);
|
|
9639
|
-
if (sha256(bytes) !== file.sha256) throw new Error(`${label}: layer ${name2} changed after the manifest was resolved: ${file.path}`);
|
|
9640
|
-
return bytes;
|
|
9641
|
-
};
|
|
9642
|
-
const built = buildLayerSheet(sources, {
|
|
9643
|
-
minSide: 32,
|
|
9644
|
-
maxSide: LAYER_SHEET_MAX_SIDE,
|
|
9645
|
-
columns: layer.columns,
|
|
9646
|
-
region: layer.region,
|
|
9647
|
-
padding: layer.padding,
|
|
9648
|
-
key: layer.key,
|
|
9649
|
-
skin: layer.skin,
|
|
9650
|
-
reference: layer.clean ? sources.filter((source) => source.still).map((source) => source.png) : [],
|
|
9651
|
-
mask: supplied("mask", layer.mask),
|
|
9652
|
-
keyed: supplied("keyed sheet", layer.keyed)
|
|
9653
|
-
});
|
|
9812
|
+
const built = layerSheetFor(spec, outputs);
|
|
9654
9813
|
const dir = layerWorkDir(spec);
|
|
9655
9814
|
(0, import_node_fs7.mkdirSync)(dir, { recursive: true });
|
|
9656
9815
|
let prepared = built;
|
|
@@ -9705,7 +9864,15 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
9705
9864
|
character: {
|
|
9706
9865
|
kind: "layer",
|
|
9707
9866
|
backgroundJobId: res2.background_job_id,
|
|
9708
|
-
sheet: {
|
|
9867
|
+
sheet: {
|
|
9868
|
+
width,
|
|
9869
|
+
height,
|
|
9870
|
+
frames: prepared.frames.length,
|
|
9871
|
+
cleanedPixels: prepared.cleaned,
|
|
9872
|
+
// Each frame's neck row in its cell, and the frames whose own narrowest row was overruled; submit prints both.
|
|
9873
|
+
...prepared.necks ? { necks: prepared.necks.map((neck) => neck?.row ?? null) } : {},
|
|
9874
|
+
...prepared.necks?.some((neck) => neck?.corrected) ? { neckCorrected: prepared.necks.flatMap((neck, index) => neck?.corrected ? [index] : []) } : {}
|
|
9875
|
+
}
|
|
9709
9876
|
}
|
|
9710
9877
|
}
|
|
9711
9878
|
};
|
|
@@ -11768,9 +11935,9 @@ var RetroDiffusionClient = class {
|
|
|
11768
11935
|
if (!response.ok) throw new ProviderError("retrodiffusion", `Retro Diffusion download failed (${response.status})`, { status: response.status });
|
|
11769
11936
|
return Buffer.from(await response.arrayBuffer());
|
|
11770
11937
|
}
|
|
11771
|
-
async call(
|
|
11938
|
+
async call(path55, init = {}) {
|
|
11772
11939
|
if (!this.token) throw new Error("RD_API_KEY is not set");
|
|
11773
|
-
const response = await this.request(`${this.baseUrl}${
|
|
11940
|
+
const response = await this.request(`${this.baseUrl}${path55}`, {
|
|
11774
11941
|
...init,
|
|
11775
11942
|
headers: {
|
|
11776
11943
|
"Content-Type": "application/json",
|
|
@@ -15276,6 +15443,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
15276
15443
|
...keyed ? { keyed } : {},
|
|
15277
15444
|
...asset.layer.skin ? { skin: asset.layer.skin } : {},
|
|
15278
15445
|
...asset.layer.key ? { key: asset.layer.key } : {},
|
|
15446
|
+
...asset.layer.cover ? { cover: true } : {},
|
|
15279
15447
|
clean: asset.layer.clean ?? true,
|
|
15280
15448
|
...asset.layer.columns ? { columns: asset.layer.columns } : {},
|
|
15281
15449
|
region: asset.layer.region ?? "body",
|
|
@@ -17579,10 +17747,15 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
17579
17747
|
} else if (spec.mirror && entry.status === "downloaded" && entry.outputs.some((_output, index) => !(0, import_node_fs16.existsSync)(currentEntryOutputPath(entry, spec, index)))) {
|
|
17580
17748
|
state = "stale";
|
|
17581
17749
|
reason = "mirror output missing on disk; flip it again (no generation cost)";
|
|
17582
|
-
} else if (
|
|
17750
|
+
} else if (
|
|
17751
|
+
// A mirror carries its source's character shape, but it is a flip of
|
|
17752
|
+
// the source's files: whether it is current is the check above, never
|
|
17753
|
+
// the outfit or layer rule its source answers to (#418).
|
|
17754
|
+
!spec.mirror && spec.character?.kind === "outfit" && entry.outfit?.sourceSha256 !== mirrorSourceHash(lock.entries[lockKey(spec.styleId, spec.character.parentAssetId)] ?? { outputs: [] })
|
|
17755
|
+
) {
|
|
17583
17756
|
state = "stale";
|
|
17584
17757
|
reason = `outfit source ${spec.character.parentAssetId} changed; re-clothe the loop again`;
|
|
17585
|
-
} else if (spec.character?.kind === "layer" && changedLayerSource(spec, entry, lock)) {
|
|
17758
|
+
} else if (!spec.mirror && spec.character?.kind === "layer" && changedLayerSource(spec, entry, lock)) {
|
|
17586
17759
|
state = "stale";
|
|
17587
17760
|
reason = isHeldItem(spec) ? `layer source ${changedLayerSource(spec, entry, lock)} changed; place the item again (no generation cost)` : `layer source ${changedLayerSource(spec, entry, lock)} changed; dress the frames again`;
|
|
17588
17761
|
} else if (isHeldItem(spec) && entry.status === "downloaded" && entry.outputs.some((_output, index) => !(0, import_node_fs16.existsSync)(currentEntryOutputPath(entry, spec, index)))) {
|
|
@@ -17650,6 +17823,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
17650
17823
|
}
|
|
17651
17824
|
const isActionable = (i) => i.state === "missing" || i.state === "stale" || i.state === "failed";
|
|
17652
17825
|
const stateOf = new Map(items.map((i) => [i.key, i.state]));
|
|
17826
|
+
const waiting = /* @__PURE__ */ new Set();
|
|
17653
17827
|
for (const item of items) {
|
|
17654
17828
|
if (!isActionable(item)) continue;
|
|
17655
17829
|
for (const parent of dependencies(item.spec)) {
|
|
@@ -17658,11 +17832,35 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
17658
17832
|
if (parentState && isActionable({ state: parentState })) {
|
|
17659
17833
|
item.state = "blocked";
|
|
17660
17834
|
item.reason = `parent ${parentKey} is being generated in this run; this follows in the next wave`;
|
|
17835
|
+
waiting.add(item.key);
|
|
17661
17836
|
break;
|
|
17662
17837
|
}
|
|
17663
17838
|
if ((item.spec.mirror || item.spec.derive || isHeldItem(item.spec)) && (parentState === "recoverable" || parentState === "in-flight")) {
|
|
17664
17839
|
item.state = "blocked";
|
|
17665
17840
|
item.reason = `mirror source ${parentKey} is ${parentState}; this follows in the next wave`;
|
|
17841
|
+
waiting.add(item.key);
|
|
17842
|
+
break;
|
|
17843
|
+
}
|
|
17844
|
+
}
|
|
17845
|
+
}
|
|
17846
|
+
const byKey = new Map(items.map((i) => [i.key, i]));
|
|
17847
|
+
for (let changed = true; changed; ) {
|
|
17848
|
+
changed = false;
|
|
17849
|
+
for (const item of items) {
|
|
17850
|
+
if (item.state !== "blocked" || waiting.has(item.key)) continue;
|
|
17851
|
+
for (const parent of dependencies(item.spec)) {
|
|
17852
|
+
const parentKey = lockKey(parent.styleId, parent.assetId);
|
|
17853
|
+
const parentItem = byKey.get(parentKey);
|
|
17854
|
+
if (!parentItem || !item.reason.includes(`${parentKey} is not ready`)) continue;
|
|
17855
|
+
if (isActionable(parentItem)) {
|
|
17856
|
+
item.reason = `waits for ${parentKey}, which this run generates first; follows in a later wave (${item.reason})`;
|
|
17857
|
+
} else if (waiting.has(parentKey)) {
|
|
17858
|
+
item.reason = `waits for ${parentKey}, which itself follows in a later wave of this run (${item.reason})`;
|
|
17859
|
+
} else {
|
|
17860
|
+
continue;
|
|
17861
|
+
}
|
|
17862
|
+
waiting.add(item.key);
|
|
17863
|
+
changed = true;
|
|
17666
17864
|
break;
|
|
17667
17865
|
}
|
|
17668
17866
|
}
|
|
@@ -20107,10 +20305,10 @@ function isSha256Hash(value) {
|
|
|
20107
20305
|
function parseCache(value) {
|
|
20108
20306
|
return HashCacheSchema.parse(value);
|
|
20109
20307
|
}
|
|
20110
|
-
async function loadCache(
|
|
20111
|
-
if (!(0, import_node_fs26.existsSync)(
|
|
20308
|
+
async function loadCache(path55) {
|
|
20309
|
+
if (!(0, import_node_fs26.existsSync)(path55)) return { version: 1, hashes: {} };
|
|
20112
20310
|
try {
|
|
20113
|
-
const parsed = HashCacheSchema.safeParse(JSON.parse(await (0, import_promises20.readFile)(
|
|
20311
|
+
const parsed = HashCacheSchema.safeParse(JSON.parse(await (0, import_promises20.readFile)(path55, "utf8")));
|
|
20114
20312
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
20115
20313
|
return {
|
|
20116
20314
|
version: 1,
|
|
@@ -20122,18 +20320,18 @@ async function loadCache(path54) {
|
|
|
20122
20320
|
return { version: 1, hashes: {} };
|
|
20123
20321
|
}
|
|
20124
20322
|
}
|
|
20125
|
-
async function saveCache(
|
|
20323
|
+
async function saveCache(path55, cache) {
|
|
20126
20324
|
const sorted = {};
|
|
20127
20325
|
for (const key3 of Object.keys(cache.hashes).sort()) {
|
|
20128
20326
|
const hash = cache.hashes[key3];
|
|
20129
20327
|
if (!isSha256Hash(hash)) throw new Error(`Refusing to cache invalid SHA-256 for ${key3}`);
|
|
20130
20328
|
sorted[key3] = hash;
|
|
20131
20329
|
}
|
|
20132
|
-
await (0, import_promises20.mkdir)(import_node_path29.default.dirname(import_node_path29.default.resolve(
|
|
20133
|
-
const tmp = `${
|
|
20330
|
+
await (0, import_promises20.mkdir)(import_node_path29.default.dirname(import_node_path29.default.resolve(path55)), { recursive: true });
|
|
20331
|
+
const tmp = `${path55}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
20134
20332
|
try {
|
|
20135
20333
|
await (0, import_promises20.writeFile)(tmp, JSON.stringify({ version: 1, hashes: sorted }, null, 2) + "\n");
|
|
20136
|
-
await (0, import_promises20.rename)(tmp,
|
|
20334
|
+
await (0, import_promises20.rename)(tmp, path55);
|
|
20137
20335
|
} finally {
|
|
20138
20336
|
await (0, import_promises20.rm)(tmp, { force: true });
|
|
20139
20337
|
}
|
|
@@ -20379,6 +20577,9 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
20379
20577
|
if (processed.changed) rawHash = sha256(raw);
|
|
20380
20578
|
if (processed.moved?.clipped) log(` moved ${import_node_path30.default.relative(process.cwd(), target)}: ${processed.moved.clipped} pixels fell off the canvas; raise layer.padding to keep them`);
|
|
20381
20579
|
if (processed.removed) log(` cleaned ${import_node_path30.default.relative(process.cwd(), target)} (${processed.removed} ghost pixels)`);
|
|
20580
|
+
if (processed.removed && processed.opaque && processed.removed > processed.opaque * CLEAN_DAMAGE_SHARE) {
|
|
20581
|
+
log(` warning: cleaning took ${processed.removed} of ${processed.opaque} opaque pixels (${(100 * processed.removed / processed.opaque).toFixed(1)}%) from ${import_node_path30.default.relative(process.cwd(), target)}; check the frame for holes, and set clean: false then fetch to restore the provider's bytes`);
|
|
20582
|
+
}
|
|
20382
20583
|
if (processed.snapped) log(` snapped ${import_node_path30.default.relative(process.cwd(), target)} to ${wanted.palette.colors.length} colours`);
|
|
20383
20584
|
}
|
|
20384
20585
|
if (cacheDir) await cacheMedia(cacheDir, buf, mediaType);
|
|
@@ -22298,6 +22499,21 @@ function renderSheetDocument(format, atlas, opts) {
|
|
|
22298
22499
|
return { extension: ".json", document: JSON.stringify(atlas, null, 2) + "\n" };
|
|
22299
22500
|
}
|
|
22300
22501
|
|
|
22502
|
+
// src/pipeline/layer-preview.ts
|
|
22503
|
+
var import_promises23 = require("fs/promises");
|
|
22504
|
+
var import_node_path34 = __toESM(require("path"), 1);
|
|
22505
|
+
function layerSourceOutputs(spec, lock) {
|
|
22506
|
+
return spec.character.layer.sources.flatMap((source) => {
|
|
22507
|
+
const sourceEntry = lock.entries[lockKey(source.spec.styleId, source.spec.assetId)];
|
|
22508
|
+
return sourceEntry.outputs.map((output, index) => ({
|
|
22509
|
+
path: currentEntryOutputPath(sourceEntry, source.spec, index),
|
|
22510
|
+
role: output.role,
|
|
22511
|
+
assetId: source.assetId,
|
|
22512
|
+
still: source.spec.character?.kind !== "animation"
|
|
22513
|
+
}));
|
|
22514
|
+
});
|
|
22515
|
+
}
|
|
22516
|
+
|
|
22301
22517
|
// src/pipeline/submit.ts
|
|
22302
22518
|
var IN_FLIGHT_POLL_MS = 5e3;
|
|
22303
22519
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -22580,15 +22796,7 @@ async function submit(provider, loaded, items, lock, lockPath, opts = {}) {
|
|
|
22580
22796
|
const parentOutputs = spec.character?.kind === "outfit" && parentEntry ? parentEntry.outputs.map((output, index) => ({
|
|
22581
22797
|
path: currentEntryOutputPath(parentEntry, spec.character.parentSpec, index),
|
|
22582
22798
|
role: output.role
|
|
22583
|
-
})) : spec.character?.kind === "layer" ? spec
|
|
22584
|
-
const sourceEntry = lock.entries[lockKey(source.spec.styleId, source.spec.assetId)];
|
|
22585
|
-
return sourceEntry.outputs.map((output, index) => ({
|
|
22586
|
-
path: currentEntryOutputPath(sourceEntry, source.spec, index),
|
|
22587
|
-
role: output.role,
|
|
22588
|
-
assetId: source.assetId,
|
|
22589
|
-
still: source.spec.character?.kind !== "animation"
|
|
22590
|
-
}));
|
|
22591
|
-
}) : void 0;
|
|
22799
|
+
})) : spec.character?.kind === "layer" ? layerSourceOutputs(spec, lock) : void 0;
|
|
22592
22800
|
const referenceSourceImageId = ownedReferenceImageId(spec, lock, provider.id);
|
|
22593
22801
|
const { jobId, metadata } = await provider.submit(spec, refs, {
|
|
22594
22802
|
...previousJobId ? { previousJobId } : {},
|
|
@@ -22637,6 +22845,13 @@ async function submit(provider, loaded, items, lock, lockPath, opts = {}) {
|
|
|
22637
22845
|
log(
|
|
22638
22846
|
` ${key3} \u2192 ${jobId} (${spec.width}x${spec.height}` + (estimate.candidates > 1 ? `, ${estimate.candidates} ${spec.tileFeature ? "outputs" : "candidates"}` : "") + `, ${estimate.amount})`
|
|
22639
22847
|
);
|
|
22848
|
+
const sheet = metadata?.character?.sheet;
|
|
22849
|
+
if (sheet?.necks) {
|
|
22850
|
+
log(` neck rows by frame: ${sheet.necks.map((row) => row ?? "-").join(" ")}`);
|
|
22851
|
+
if (sheet.neckCorrected?.length) {
|
|
22852
|
+
log(` frame${sheet.neckCorrected.length === 1 ? "" : "s"} ${sheet.neckCorrected.join(", ")}: own narrowest row disagreed; neck taken from the head and the other frames`);
|
|
22853
|
+
}
|
|
22854
|
+
}
|
|
22640
22855
|
} catch (err) {
|
|
22641
22856
|
const message6 = err instanceof Error ? err.message : String(err);
|
|
22642
22857
|
const entry = lock.entries[key3];
|
|
@@ -22676,8 +22891,8 @@ function ownedReferenceImageId(spec, lock, providerId) {
|
|
|
22676
22891
|
|
|
22677
22892
|
// src/pick/candidates.ts
|
|
22678
22893
|
var import_node_fs31 = require("fs");
|
|
22679
|
-
var
|
|
22680
|
-
var
|
|
22894
|
+
var import_promises24 = require("fs/promises");
|
|
22895
|
+
var import_node_path35 = __toESM(require("path"), 1);
|
|
22681
22896
|
var import_zod8 = require("zod");
|
|
22682
22897
|
var REVIEW_STATE_VERSION = 1;
|
|
22683
22898
|
var CandidateSchema = import_zod8.z.object({
|
|
@@ -22721,30 +22936,30 @@ var ReviewStateSchema = import_zod8.z.object({
|
|
|
22721
22936
|
assets: import_zod8.z.record(ReviewAssetSchema)
|
|
22722
22937
|
});
|
|
22723
22938
|
function candidateCacheDirFor(lockPath) {
|
|
22724
|
-
return
|
|
22939
|
+
return import_node_path35.default.resolve(import_node_path35.default.dirname(lockPath), ".pixelkiln", "cache");
|
|
22725
22940
|
}
|
|
22726
22941
|
function reviewStatePathFor(lockPath) {
|
|
22727
|
-
const base =
|
|
22942
|
+
const base = import_node_path35.default.basename(lockPath);
|
|
22728
22943
|
const name = base === "pixelkiln.lock.json" ? "review-state.json" : `${base.replace(/\.json$/, "")}.review-state.json`;
|
|
22729
|
-
return
|
|
22944
|
+
return import_node_path35.default.resolve(import_node_path35.default.dirname(lockPath), ".pixelkiln", name);
|
|
22730
22945
|
}
|
|
22731
22946
|
async function loadReviewState(file) {
|
|
22732
22947
|
if (!(0, import_node_fs31.existsSync)(file)) return { version: REVIEW_STATE_VERSION, assets: {} };
|
|
22733
22948
|
try {
|
|
22734
|
-
const parsed = ReviewStateSchema.safeParse(JSON.parse(await (0,
|
|
22949
|
+
const parsed = ReviewStateSchema.safeParse(JSON.parse(await (0, import_promises24.readFile)(file, "utf8")));
|
|
22735
22950
|
if (parsed.success) return parsed.data;
|
|
22736
22951
|
} catch {
|
|
22737
22952
|
}
|
|
22738
22953
|
return { version: REVIEW_STATE_VERSION, assets: {} };
|
|
22739
22954
|
}
|
|
22740
22955
|
async function saveReviewState(file, state) {
|
|
22741
|
-
await (0,
|
|
22956
|
+
await (0, import_promises24.mkdir)(import_node_path35.default.dirname(file), { recursive: true });
|
|
22742
22957
|
const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
22743
22958
|
try {
|
|
22744
|
-
await (0,
|
|
22745
|
-
await (0,
|
|
22959
|
+
await (0, import_promises24.writeFile)(tmp, JSON.stringify(state, null, 2) + "\n");
|
|
22960
|
+
await (0, import_promises24.rename)(tmp, file);
|
|
22746
22961
|
} finally {
|
|
22747
|
-
await (0,
|
|
22962
|
+
await (0, import_promises24.rm)(tmp, { force: true });
|
|
22748
22963
|
}
|
|
22749
22964
|
}
|
|
22750
22965
|
async function updateReviewAsset(file, key3, change) {
|
|
@@ -22758,7 +22973,7 @@ async function updateReviewAsset(file, key3, change) {
|
|
|
22758
22973
|
}
|
|
22759
22974
|
function cachedCandidatePath(cacheDir, candidate) {
|
|
22760
22975
|
if (!candidate.sha256 || !candidate.mediaType) return null;
|
|
22761
|
-
const file =
|
|
22976
|
+
const file = import_node_path35.default.join(cacheDir, cacheFileName(candidate.sha256, candidate.mediaType));
|
|
22762
22977
|
return (0, import_node_fs31.existsSync)(file) ? file : null;
|
|
22763
22978
|
}
|
|
22764
22979
|
function fullyCached(cacheDir, asset) {
|
|
@@ -22966,12 +23181,12 @@ async function poll(provider, lock, lockPath, opts = {}) {
|
|
|
22966
23181
|
|
|
22967
23182
|
// src/pipeline/doctor.ts
|
|
22968
23183
|
var import_node_fs33 = require("fs");
|
|
22969
|
-
var
|
|
22970
|
-
var
|
|
23184
|
+
var import_promises25 = require("fs/promises");
|
|
23185
|
+
var import_node_path37 = __toESM(require("path"), 1);
|
|
22971
23186
|
|
|
22972
23187
|
// src/pipeline/install-check.ts
|
|
22973
23188
|
var import_node_fs32 = require("fs");
|
|
22974
|
-
var
|
|
23189
|
+
var import_node_path36 = __toESM(require("path"), 1);
|
|
22975
23190
|
function readJson(file) {
|
|
22976
23191
|
try {
|
|
22977
23192
|
return JSON.parse((0, import_node_fs32.readFileSync)(file, "utf8"));
|
|
@@ -22980,18 +23195,18 @@ function readJson(file) {
|
|
|
22980
23195
|
}
|
|
22981
23196
|
}
|
|
22982
23197
|
function readInstallFacts(manifestDir, running) {
|
|
22983
|
-
let dir =
|
|
23198
|
+
let dir = import_node_path36.default.resolve(manifestDir);
|
|
22984
23199
|
for (let depth = 0; depth < 4; depth++) {
|
|
22985
|
-
const pkg = readJson(
|
|
23200
|
+
const pkg = readJson(import_node_path36.default.join(dir, "package.json"));
|
|
22986
23201
|
if (pkg) {
|
|
22987
23202
|
const pinned = ["dependencies", "devDependencies", "optionalDependencies"].map((field) => pkg[field]?.pixelkiln).find((spec) => typeof spec === "string");
|
|
22988
23203
|
if (pinned) {
|
|
22989
|
-
const installedPkg = readJson(
|
|
23204
|
+
const installedPkg = readJson(import_node_path36.default.join(dir, "node_modules", "pixelkiln", "package.json"));
|
|
22990
23205
|
const installed = typeof installedPkg?.version === "string" ? installedPkg.version : void 0;
|
|
22991
23206
|
return { pinned, installed, running };
|
|
22992
23207
|
}
|
|
22993
23208
|
}
|
|
22994
|
-
const parent =
|
|
23209
|
+
const parent = import_node_path36.default.dirname(dir);
|
|
22995
23210
|
if (parent === dir || !(0, import_node_fs32.existsSync)(parent)) break;
|
|
22996
23211
|
dir = parent;
|
|
22997
23212
|
}
|
|
@@ -23055,18 +23270,18 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
23055
23270
|
`${entry.kind === "style" ? "styles" : "assets"}.${entry.id} was left out: ${entry.issues.join("; ")}`
|
|
23056
23271
|
);
|
|
23057
23272
|
}
|
|
23058
|
-
const facts = readInstallFacts(
|
|
23273
|
+
const facts = readInstallFacts(import_node_path37.default.dirname(loaded.path), opts.runningVersion !== void 0 ? opts.runningVersion : pixelkilnVersion());
|
|
23059
23274
|
if (facts) for (const finding of checkInstall(facts)) add("install", finding.level, finding.message);
|
|
23060
23275
|
add("lock", "ok", `${Object.keys(lock.entries).length} valid v2 lock entr(ies)`);
|
|
23061
23276
|
const dirs = [...new Set(specs.flatMap((spec) => [
|
|
23062
|
-
|
|
23063
|
-
...spec.quality ? [
|
|
23277
|
+
import_node_path37.default.dirname(spec.outFile),
|
|
23278
|
+
...spec.quality ? [import_node_path37.default.dirname(spec.quality.outFile)] : []
|
|
23064
23279
|
]))];
|
|
23065
23280
|
const unwritable = [];
|
|
23066
23281
|
for (const dir of dirs) {
|
|
23067
23282
|
const ancestor = await nearestExistingDirectory(dir);
|
|
23068
23283
|
try {
|
|
23069
|
-
await (0,
|
|
23284
|
+
await (0, import_promises25.access)(ancestor, import_node_fs33.constants.W_OK);
|
|
23070
23285
|
} catch {
|
|
23071
23286
|
unwritable.push(dir);
|
|
23072
23287
|
}
|
|
@@ -23083,7 +23298,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
23083
23298
|
for (let index = 0; index < entry.outputs.length; index++) {
|
|
23084
23299
|
const output = entry.outputs[index];
|
|
23085
23300
|
const spec = specByKey.get(key3);
|
|
23086
|
-
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path,
|
|
23301
|
+
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path, import_node_path37.default.dirname(lockPath));
|
|
23087
23302
|
const owner = outputOwners.get(absolute);
|
|
23088
23303
|
if (owner && owner !== key3) duplicateOutputs.push(`${output.path} (${owner}, ${key3})`);
|
|
23089
23304
|
outputOwners.set(absolute, key3);
|
|
@@ -23098,7 +23313,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
23098
23313
|
} else {
|
|
23099
23314
|
add("lock-outputs", "ok", `${outputOwners.size} recorded output path(s) are uniquely owned`);
|
|
23100
23315
|
}
|
|
23101
|
-
const cacheDir =
|
|
23316
|
+
const cacheDir = import_node_path37.default.join(import_node_path37.default.dirname(lockPath), ".pixelkiln", "cache");
|
|
23102
23317
|
const stranded = [];
|
|
23103
23318
|
const invalidState = [];
|
|
23104
23319
|
const staleMapUrls = [];
|
|
@@ -23114,7 +23329,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
23114
23329
|
const hasSource = Boolean(entry.sourceUrl || entry.sourceUrls?.length);
|
|
23115
23330
|
let hasCache = false;
|
|
23116
23331
|
for (const output of entry.outputs) {
|
|
23117
|
-
const cached2 =
|
|
23332
|
+
const cached2 = import_node_path37.default.join(
|
|
23118
23333
|
cacheDir,
|
|
23119
23334
|
cacheFileName(output.sha256, output.mediaType ?? MediaType.PNG)
|
|
23120
23335
|
);
|
|
@@ -23211,10 +23426,10 @@ async function nearestExistingDirectory(start) {
|
|
|
23211
23426
|
let current = start;
|
|
23212
23427
|
for (; ; ) {
|
|
23213
23428
|
try {
|
|
23214
|
-
if ((await (0,
|
|
23429
|
+
if ((await (0, import_promises25.stat)(current)).isDirectory()) return current;
|
|
23215
23430
|
} catch {
|
|
23216
23431
|
}
|
|
23217
|
-
const parent =
|
|
23432
|
+
const parent = import_node_path37.default.dirname(current);
|
|
23218
23433
|
if (parent === current) return current;
|
|
23219
23434
|
current = parent;
|
|
23220
23435
|
}
|
|
@@ -23222,8 +23437,8 @@ async function nearestExistingDirectory(start) {
|
|
|
23222
23437
|
|
|
23223
23438
|
// src/pipeline/adopt.ts
|
|
23224
23439
|
var import_node_fs34 = require("fs");
|
|
23225
|
-
var
|
|
23226
|
-
var
|
|
23440
|
+
var import_promises26 = require("fs/promises");
|
|
23441
|
+
var import_node_path38 = __toESM(require("path"), 1);
|
|
23227
23442
|
async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
23228
23443
|
const log = opts.onProgress ?? (() => {
|
|
23229
23444
|
});
|
|
@@ -23238,7 +23453,7 @@ async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
|
23238
23453
|
unmatchedLocal.push(`${spec.styleId}/${spec.assetId} (no file at ${spec.outFile})`);
|
|
23239
23454
|
continue;
|
|
23240
23455
|
}
|
|
23241
|
-
const bytes = await (0,
|
|
23456
|
+
const bytes = await (0, import_promises26.readFile)(spec.outFile);
|
|
23242
23457
|
try {
|
|
23243
23458
|
decodePng(bytes);
|
|
23244
23459
|
} catch (err) {
|
|
@@ -23357,8 +23572,8 @@ async function tagAdopted(provider, specs, lock, opts = {}) {
|
|
|
23357
23572
|
|
|
23358
23573
|
// src/pipeline/import.ts
|
|
23359
23574
|
var import_node_fs35 = require("fs");
|
|
23360
|
-
var
|
|
23361
|
-
var
|
|
23575
|
+
var import_promises27 = require("fs/promises");
|
|
23576
|
+
var import_node_path39 = __toESM(require("path"), 1);
|
|
23362
23577
|
function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date(), frames) {
|
|
23363
23578
|
const png = decodePng(bytes);
|
|
23364
23579
|
for (const frame of frames ?? []) decodePng(frame.bytes);
|
|
@@ -23411,10 +23626,10 @@ function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Da
|
|
|
23411
23626
|
var frameRole2 = (index) => `frame-${String(index).padStart(2, "0")}`;
|
|
23412
23627
|
async function findFrames(spec) {
|
|
23413
23628
|
const at2 = (index) => memberPath(spec.outFile, frameRole2(index), 0, 2, MediaType.PNG);
|
|
23414
|
-
const base =
|
|
23629
|
+
const base = import_node_path39.default.basename(at2(0)).replace(/00\.png$/, "");
|
|
23415
23630
|
let names = [];
|
|
23416
23631
|
try {
|
|
23417
|
-
names = await (0,
|
|
23632
|
+
names = await (0, import_promises27.readdir)(import_node_path39.default.dirname(spec.outFile));
|
|
23418
23633
|
} catch {
|
|
23419
23634
|
names = [];
|
|
23420
23635
|
}
|
|
@@ -23444,13 +23659,13 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
23444
23659
|
if (opts.objectId && specs.length !== 1) {
|
|
23445
23660
|
throw new Error(`--object-id names one object; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
23446
23661
|
}
|
|
23447
|
-
const cacheDir = opts.cacheDir === false ? null :
|
|
23662
|
+
const cacheDir = opts.cacheDir === false ? null : import_node_path39.default.resolve(opts.cacheDir ?? import_node_path39.default.join(import_node_path39.default.dirname(lockPath), ".pixelkiln", "cache"));
|
|
23448
23663
|
let rawSha256;
|
|
23449
23664
|
let rawBytes;
|
|
23450
23665
|
if (opts.raw) {
|
|
23451
23666
|
if (specs.length !== 1) throw new Error(`--raw names one original; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
23452
23667
|
try {
|
|
23453
|
-
rawBytes = await (0,
|
|
23668
|
+
rawBytes = await (0, import_promises27.readFile)(opts.raw);
|
|
23454
23669
|
decodePng(rawBytes);
|
|
23455
23670
|
} catch (error) {
|
|
23456
23671
|
throw new Error(`--raw ${opts.raw} is not a readable PNG: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
@@ -23474,7 +23689,7 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
23474
23689
|
continue;
|
|
23475
23690
|
}
|
|
23476
23691
|
if ("missing" in frames2) {
|
|
23477
|
-
skipped.push({ key: key3, reason: `frame set is missing ${frames2.missing.map((file) =>
|
|
23692
|
+
skipped.push({ key: key3, reason: `frame set is missing ${frames2.missing.map((file) => import_node_path39.default.basename(file)).join(", ")} (in ${import_node_path39.default.dirname(spec.outFile)})` });
|
|
23478
23693
|
continue;
|
|
23479
23694
|
}
|
|
23480
23695
|
frameFiles = frames2.files;
|
|
@@ -23487,8 +23702,8 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
23487
23702
|
let bytes;
|
|
23488
23703
|
let frames;
|
|
23489
23704
|
try {
|
|
23490
|
-
frames = frameFiles ? await Promise.all(frameFiles.map(async (frame) => ({ ...frame, bytes: await (0,
|
|
23491
|
-
bytes = frames ? frames[0].bytes : await (0,
|
|
23705
|
+
frames = frameFiles ? await Promise.all(frameFiles.map(async (frame) => ({ ...frame, bytes: await (0, import_promises27.readFile)(frame.file) }))) : void 0;
|
|
23706
|
+
bytes = frames ? frames[0].bytes : await (0, import_promises27.readFile)(spec.outFile);
|
|
23492
23707
|
patch = buildImportedEntry(spec, bytes, { ...opts, rawSha256 }, /* @__PURE__ */ new Date(), frames);
|
|
23493
23708
|
} catch (error) {
|
|
23494
23709
|
skipped.push({ key: key3, reason: `invalid PNG: ${error instanceof Error ? error.message : String(error)}` });
|
|
@@ -23521,7 +23736,7 @@ async function reportSpecHashes(specs, lock) {
|
|
|
23521
23736
|
for (const spec of specs) {
|
|
23522
23737
|
const key3 = lockKey(spec.styleId, spec.assetId);
|
|
23523
23738
|
let bytes = null;
|
|
23524
|
-
if ((0, import_node_fs35.existsSync)(spec.outFile)) bytes = await (0,
|
|
23739
|
+
if ((0, import_node_fs35.existsSync)(spec.outFile)) bytes = await (0, import_promises27.readFile)(spec.outFile);
|
|
23525
23740
|
let wouldImport = null;
|
|
23526
23741
|
if (bytes && !unimportable(spec)) {
|
|
23527
23742
|
try {
|
|
@@ -23551,12 +23766,12 @@ async function reportSpecHashes(specs, lock) {
|
|
|
23551
23766
|
|
|
23552
23767
|
// src/pick/server.ts
|
|
23553
23768
|
var import_node_fs37 = require("fs");
|
|
23554
|
-
var
|
|
23769
|
+
var import_promises30 = require("fs/promises");
|
|
23555
23770
|
|
|
23556
23771
|
// src/pipeline/init.ts
|
|
23557
|
-
var
|
|
23772
|
+
var import_promises28 = require("fs/promises");
|
|
23558
23773
|
var import_node_fs36 = require("fs");
|
|
23559
|
-
var
|
|
23774
|
+
var import_node_path40 = __toESM(require("path"), 1);
|
|
23560
23775
|
function pngSize(buf) {
|
|
23561
23776
|
if (buf.length < 24) return null;
|
|
23562
23777
|
const isPng = buf.readUInt32BE(0) === 2303741511 && buf.readUInt32BE(4) === 218765834;
|
|
@@ -23569,8 +23784,8 @@ function slugify(value) {
|
|
|
23569
23784
|
}
|
|
23570
23785
|
async function walk(dir, exclude) {
|
|
23571
23786
|
const out = [];
|
|
23572
|
-
for (const entry of await (0,
|
|
23573
|
-
const full =
|
|
23787
|
+
for (const entry of await (0, import_promises28.readdir)(dir, { withFileTypes: true })) {
|
|
23788
|
+
const full = import_node_path40.default.join(dir, entry.name);
|
|
23574
23789
|
if (exclude.some((x) => full.includes(x))) continue;
|
|
23575
23790
|
if (entry.isDirectory()) out.push(...await walk(full, exclude));
|
|
23576
23791
|
else if (entry.name.toLowerCase().endsWith(".png")) out.push(full);
|
|
@@ -23584,14 +23799,14 @@ async function scanAssets(root, opts = {}) {
|
|
|
23584
23799
|
const skipped = [];
|
|
23585
23800
|
const seen = /* @__PURE__ */ new Map();
|
|
23586
23801
|
for (const file of files.sort()) {
|
|
23587
|
-
const size = pngSize(await (0,
|
|
23802
|
+
const size = pngSize(await (0, import_promises28.readFile)(file));
|
|
23588
23803
|
if (!size) {
|
|
23589
23804
|
skipped.push(`${file} (not a readable PNG)`);
|
|
23590
23805
|
continue;
|
|
23591
23806
|
}
|
|
23592
|
-
const rel =
|
|
23593
|
-
const category =
|
|
23594
|
-
let id = slugify(
|
|
23807
|
+
const rel = import_node_path40.default.relative(root, file);
|
|
23808
|
+
const category = import_node_path40.default.dirname(rel) === "." ? "" : import_node_path40.default.dirname(rel);
|
|
23809
|
+
let id = slugify(import_node_path40.default.basename(rel));
|
|
23595
23810
|
if (seen.has(id)) {
|
|
23596
23811
|
const n = seen.get(id) + 1;
|
|
23597
23812
|
seen.set(id, n);
|
|
@@ -24568,7 +24783,7 @@ if (CONFIG.sessionUrl) {
|
|
|
24568
24783
|
|
|
24569
24784
|
// src/pick/review-server.ts
|
|
24570
24785
|
var import_node_http = require("http");
|
|
24571
|
-
var
|
|
24786
|
+
var import_promises29 = require("fs/promises");
|
|
24572
24787
|
async function readJsonBody(req, res) {
|
|
24573
24788
|
const expectedOrigin = req.headers.host ? `http://${req.headers.host}` : null;
|
|
24574
24789
|
if (req.headers.origin && req.headers.origin !== expectedOrigin) {
|
|
@@ -24603,7 +24818,7 @@ function serveReviewPage(opts) {
|
|
|
24603
24818
|
if (req.method === "GET" && req.url && opts.assets?.has(req.url)) {
|
|
24604
24819
|
try {
|
|
24605
24820
|
const asset = opts.assets.get(req.url);
|
|
24606
|
-
const bytes = await (0,
|
|
24821
|
+
const bytes = await (0, import_promises29.readFile)(asset.path);
|
|
24607
24822
|
res.writeHead(200, {
|
|
24608
24823
|
"Content-Type": asset.contentType,
|
|
24609
24824
|
// A frame route names one cached candidate for the life of this
|
|
@@ -24686,7 +24901,7 @@ async function currentArt(entry, spec) {
|
|
|
24686
24901
|
let width = entry.width;
|
|
24687
24902
|
let height = entry.height;
|
|
24688
24903
|
if (contentType === "image/png") {
|
|
24689
|
-
const size = pngSize(await (0,
|
|
24904
|
+
const size = pngSize(await (0, import_promises30.readFile)(file));
|
|
24690
24905
|
if (size) ({ width, height } = size);
|
|
24691
24906
|
}
|
|
24692
24907
|
return { path: file, contentType, width, height };
|
|
@@ -24694,7 +24909,7 @@ async function currentArt(entry, spec) {
|
|
|
24694
24909
|
async function cachedFrame(url) {
|
|
24695
24910
|
if (!url.startsWith("file://")) return null;
|
|
24696
24911
|
const file = url.slice("file://".length);
|
|
24697
|
-
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await (0,
|
|
24912
|
+
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await (0, import_promises30.readFile)(file).catch(() => Buffer.alloc(0))) ?? "application/octet-stream";
|
|
24698
24913
|
return { path: file, contentType };
|
|
24699
24914
|
}
|
|
24700
24915
|
async function prepareReview(provider, lock, opts = {}) {
|
|
@@ -24756,7 +24971,7 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
24756
24971
|
frameSizes.push(null);
|
|
24757
24972
|
continue;
|
|
24758
24973
|
}
|
|
24759
|
-
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await (0,
|
|
24974
|
+
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await (0, import_promises30.readFile)(cached2.path).catch(() => Buffer.alloc(0))) : null);
|
|
24760
24975
|
const route = `${prefix}/review-frame/${encodeURIComponent(String((opts.routeBase ?? 0) + groups.length))}/${index}`;
|
|
24761
24976
|
frameAssets.push([route, cached2]);
|
|
24762
24977
|
frameUrls.push(route);
|
|
@@ -25097,13 +25312,13 @@ async function runPicker(provider, lock, lockPath, opts = {}) {
|
|
|
25097
25312
|
// src/gallery/snapshot.ts
|
|
25098
25313
|
var import_node_crypto10 = require("crypto");
|
|
25099
25314
|
var import_node_fs46 = require("fs");
|
|
25100
|
-
var
|
|
25101
|
-
var
|
|
25315
|
+
var import_promises41 = require("fs/promises");
|
|
25316
|
+
var import_node_path51 = __toESM(require("path"), 1);
|
|
25102
25317
|
|
|
25103
25318
|
// src/gallery/models.ts
|
|
25104
25319
|
var import_node_fs41 = require("fs");
|
|
25105
|
-
var
|
|
25106
|
-
var
|
|
25320
|
+
var import_promises35 = require("fs/promises");
|
|
25321
|
+
var import_node_path45 = __toESM(require("path"), 1);
|
|
25107
25322
|
var import_zod12 = require("zod");
|
|
25108
25323
|
|
|
25109
25324
|
// src/glb.ts
|
|
@@ -25436,11 +25651,11 @@ function modelItems(json2) {
|
|
|
25436
25651
|
}
|
|
25437
25652
|
|
|
25438
25653
|
// src/manifest-edit.ts
|
|
25439
|
-
var
|
|
25440
|
-
var
|
|
25654
|
+
var import_promises31 = require("fs/promises");
|
|
25655
|
+
var import_node_path41 = __toESM(require("path"), 1);
|
|
25441
25656
|
var import_zod9 = require("zod");
|
|
25442
25657
|
var HexSha = import_zod9.z.string().regex(/^[0-9a-f]{64}$/);
|
|
25443
|
-
var ProjectFileSchema = import_zod9.z.string().min(1).refine((file) => !
|
|
25658
|
+
var ProjectFileSchema = import_zod9.z.string().min(1).refine((file) => !import_node_path41.default.isAbsolute(file) && !file.split(/[\\/]/).includes(".."), "must be a path inside the project");
|
|
25444
25659
|
var AssetPatchSchema = import_zod9.z.object({
|
|
25445
25660
|
prompt: import_zod9.z.string().optional(),
|
|
25446
25661
|
/** Per-style override for the style being viewed; null removes it. */
|
|
@@ -25861,8 +26076,8 @@ function applyEdit(raw, edit) {
|
|
|
25861
26076
|
}
|
|
25862
26077
|
}
|
|
25863
26078
|
async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
25864
|
-
const absolute =
|
|
25865
|
-
const original = await (0,
|
|
26079
|
+
const absolute = import_node_path41.default.resolve(manifestPath);
|
|
26080
|
+
const original = await (0, import_promises31.readFile)(absolute, "utf8");
|
|
25866
26081
|
if (sha256(original) !== edit.expectedSha256) throw new ManifestDriftError(absolute);
|
|
25867
26082
|
let raw;
|
|
25868
26083
|
try {
|
|
@@ -25875,12 +26090,12 @@ async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
|
25875
26090
|
applyEdit(raw, edit);
|
|
25876
26091
|
const next = serializeLike(original, raw);
|
|
25877
26092
|
if (next === original) return unchanged(absolute, original);
|
|
25878
|
-
const tmp =
|
|
25879
|
-
|
|
25880
|
-
`.${
|
|
26093
|
+
const tmp = import_node_path41.default.join(
|
|
26094
|
+
import_node_path41.default.dirname(absolute),
|
|
26095
|
+
`.${import_node_path41.default.basename(absolute)}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`
|
|
25881
26096
|
);
|
|
25882
26097
|
try {
|
|
25883
|
-
await (0,
|
|
26098
|
+
await (0, import_promises31.writeFile)(tmp, next);
|
|
25884
26099
|
let specs;
|
|
25885
26100
|
try {
|
|
25886
26101
|
specs = await resolveSpecs(await loadManifest(tmp));
|
|
@@ -25890,7 +26105,7 @@ async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
|
25890
26105
|
}
|
|
25891
26106
|
return await use({ absolute, original, next, tmp, specs });
|
|
25892
26107
|
} finally {
|
|
25893
|
-
await (0,
|
|
26108
|
+
await (0, import_promises31.rm)(tmp, { force: true });
|
|
25894
26109
|
}
|
|
25895
26110
|
}
|
|
25896
26111
|
async function applyManifestEdit(manifestPath, edit) {
|
|
@@ -25898,7 +26113,7 @@ async function applyManifestEdit(manifestPath, edit) {
|
|
|
25898
26113
|
manifestPath,
|
|
25899
26114
|
edit,
|
|
25900
26115
|
async ({ absolute, next, tmp }) => {
|
|
25901
|
-
await (0,
|
|
26116
|
+
await (0, import_promises31.rename)(tmp, absolute);
|
|
25902
26117
|
return { manifestPath: absolute, sha256: sha256(next), changed: true };
|
|
25903
26118
|
},
|
|
25904
26119
|
(absolute, original) => ({ manifestPath: absolute, sha256: sha256(original), changed: false })
|
|
@@ -25907,17 +26122,17 @@ async function applyManifestEdit(manifestPath, edit) {
|
|
|
25907
26122
|
|
|
25908
26123
|
// src/pipeline/hand-edit.ts
|
|
25909
26124
|
var import_node_fs38 = require("fs");
|
|
25910
|
-
var
|
|
25911
|
-
var
|
|
26125
|
+
var import_promises32 = require("fs/promises");
|
|
26126
|
+
var import_node_path42 = __toESM(require("path"), 1);
|
|
25912
26127
|
var import_zod10 = require("zod");
|
|
25913
26128
|
var HAND_EDIT_DIR = "edits";
|
|
25914
26129
|
function handEditPath(loaded, spec) {
|
|
25915
26130
|
const style = loaded.manifest.styles[spec.styleId];
|
|
25916
|
-
const outDir =
|
|
25917
|
-
const relative =
|
|
25918
|
-
const inside2 = relative && !relative.startsWith("..") && !
|
|
25919
|
-
const file = inside2 ? relative :
|
|
25920
|
-
return
|
|
26131
|
+
const outDir = import_node_path42.default.resolve(loaded.root, style?.outDir ?? ".");
|
|
26132
|
+
const relative = import_node_path42.default.relative(outDir, spec.outFile);
|
|
26133
|
+
const inside2 = relative && !relative.startsWith("..") && !import_node_path42.default.isAbsolute(relative);
|
|
26134
|
+
const file = inside2 ? relative : import_node_path42.default.basename(spec.outFile);
|
|
26135
|
+
return import_node_path42.default.join(outDir, HAND_EDIT_DIR, file.replace(/\.gif$/i, ".png"));
|
|
25921
26136
|
}
|
|
25922
26137
|
function handEditBases(spec, lock) {
|
|
25923
26138
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
@@ -25983,7 +26198,7 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
25983
26198
|
`${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`
|
|
25984
26199
|
);
|
|
25985
26200
|
}
|
|
25986
|
-
const existing = spec.source ?
|
|
26201
|
+
const existing = spec.source ? import_node_path42.default.resolve(loaded.root, spec.source) : null;
|
|
25987
26202
|
const editPath = existing ?? handEditPath(loaded, spec);
|
|
25988
26203
|
const members = handEditMembers(loaded, spec, lock, editPath);
|
|
25989
26204
|
let created = false;
|
|
@@ -25994,8 +26209,8 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
25994
26209
|
`${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
|
|
25995
26210
|
);
|
|
25996
26211
|
}
|
|
25997
|
-
await (0,
|
|
25998
|
-
await (0,
|
|
26212
|
+
await (0, import_promises32.mkdir)(import_node_path42.default.dirname(member.path), { recursive: true });
|
|
26213
|
+
await (0, import_promises32.copyFile)(member.base, member.path);
|
|
25999
26214
|
created = true;
|
|
26000
26215
|
}
|
|
26001
26216
|
const source = portableOutputPath(editPath, loaded.root);
|
|
@@ -26073,7 +26288,7 @@ function handEditProjectPath(editPath) {
|
|
|
26073
26288
|
async function readHandEditCompanion(editPath) {
|
|
26074
26289
|
let text;
|
|
26075
26290
|
try {
|
|
26076
|
-
text = await (0,
|
|
26291
|
+
text = await (0, import_promises32.readFile)(handEditCompanionPath(editPath), "utf8");
|
|
26077
26292
|
} catch {
|
|
26078
26293
|
return null;
|
|
26079
26294
|
}
|
|
@@ -26117,7 +26332,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
26117
26332
|
}
|
|
26118
26333
|
});
|
|
26119
26334
|
const bases = handEditBases(spec, lock);
|
|
26120
|
-
const expectedSize = bases?.[0] ? decodePng(await (0,
|
|
26335
|
+
const expectedSize = bases?.[0] ? decodePng(await (0, import_promises32.readFile)(bases[0].path)) : { width: spec.width, height: spec.height };
|
|
26121
26336
|
for (const [index, image] of decoded.entries()) {
|
|
26122
26337
|
if (image.width !== expectedSize.width || image.height !== expectedSize.height) {
|
|
26123
26338
|
const which = memberSet ? `member ${incoming[index].role ?? index}` : "the edit";
|
|
@@ -26133,7 +26348,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
26133
26348
|
editor: input.editor,
|
|
26134
26349
|
protocol: input.protocol,
|
|
26135
26350
|
savedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
26136
|
-
project: projectPath ?
|
|
26351
|
+
project: projectPath ? import_node_path42.default.basename(projectPath) : null,
|
|
26137
26352
|
outputs: incoming.map((frame, index) => ({
|
|
26138
26353
|
role: frame.role,
|
|
26139
26354
|
basedOn: basedOnHash(entry, index),
|
|
@@ -26163,10 +26378,10 @@ function basedOnHash(entry, index) {
|
|
|
26163
26378
|
async function replaceFile(file, bytes) {
|
|
26164
26379
|
const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
26165
26380
|
try {
|
|
26166
|
-
await (0,
|
|
26167
|
-
await (0,
|
|
26381
|
+
await (0, import_promises32.writeFile)(tmp, bytes);
|
|
26382
|
+
await (0, import_promises32.rename)(tmp, file);
|
|
26168
26383
|
} finally {
|
|
26169
|
-
await (0,
|
|
26384
|
+
await (0, import_promises32.rm)(tmp, { force: true });
|
|
26170
26385
|
}
|
|
26171
26386
|
}
|
|
26172
26387
|
function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
|
|
@@ -26177,8 +26392,8 @@ function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
|
|
|
26177
26392
|
// src/pipeline/model-edit.ts
|
|
26178
26393
|
var import_node_child_process3 = require("child_process");
|
|
26179
26394
|
var import_node_fs39 = require("fs");
|
|
26180
|
-
var
|
|
26181
|
-
var
|
|
26395
|
+
var import_promises33 = require("fs/promises");
|
|
26396
|
+
var import_node_path43 = __toESM(require("path"), 1);
|
|
26182
26397
|
var import_zod11 = require("zod");
|
|
26183
26398
|
|
|
26184
26399
|
// src/jpeg.ts
|
|
@@ -26560,27 +26775,27 @@ var MAX_MODELS = 200;
|
|
|
26560
26775
|
var MAX_DEPTH = 8;
|
|
26561
26776
|
var SKIPPED_DIRS = /* @__PURE__ */ new Set([HAND_EDIT_DIR, "node_modules"]);
|
|
26562
26777
|
async function discoverModels(loaded, opts = {}) {
|
|
26563
|
-
const styles = Object.entries(loaded.manifest.styles).filter(([id]) => !opts.styles?.length || opts.styles.includes(id)).map(([id, style]) => ({ id, outDir:
|
|
26778
|
+
const styles = Object.entries(loaded.manifest.styles).filter(([id]) => !opts.styles?.length || opts.styles.includes(id)).map(([id, style]) => ({ id, outDir: import_node_path43.default.resolve(loaded.root, style.outDir ?? ".") })).sort((a, b) => b.outDir.length - a.outDir.length || a.id.localeCompare(b.id));
|
|
26564
26779
|
const seen = /* @__PURE__ */ new Set();
|
|
26565
26780
|
const models = [];
|
|
26566
26781
|
const walk2 = async (styleId, outDir, dir, depth) => {
|
|
26567
26782
|
if (depth > MAX_DEPTH || models.length >= MAX_MODELS) return;
|
|
26568
26783
|
let entries;
|
|
26569
26784
|
try {
|
|
26570
|
-
entries = await (0,
|
|
26785
|
+
entries = await (0, import_promises33.readdir)(dir, { withFileTypes: true });
|
|
26571
26786
|
} catch {
|
|
26572
26787
|
return;
|
|
26573
26788
|
}
|
|
26574
26789
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
26575
26790
|
for (const entry of entries) {
|
|
26576
26791
|
if (models.length >= MAX_MODELS) return;
|
|
26577
|
-
const full =
|
|
26792
|
+
const full = import_node_path43.default.join(dir, entry.name);
|
|
26578
26793
|
if (entry.isDirectory()) {
|
|
26579
26794
|
if (entry.name.startsWith(".") || SKIPPED_DIRS.has(entry.name)) continue;
|
|
26580
26795
|
await walk2(styleId, outDir, full, depth + 1);
|
|
26581
26796
|
} else if (entry.isFile() && entry.name.toLowerCase().endsWith(MODEL_EXTENSION) && !seen.has(full)) {
|
|
26582
26797
|
seen.add(full);
|
|
26583
|
-
models.push({ styleId, file: full, editFile:
|
|
26798
|
+
models.push({ styleId, file: full, editFile: import_node_path43.default.join(outDir, HAND_EDIT_DIR, import_node_path43.default.relative(outDir, full)) });
|
|
26584
26799
|
}
|
|
26585
26800
|
}
|
|
26586
26801
|
};
|
|
@@ -26588,12 +26803,12 @@ async function discoverModels(loaded, opts = {}) {
|
|
|
26588
26803
|
return models.sort((a, b) => a.styleId.localeCompare(b.styleId) || a.file.localeCompare(b.file));
|
|
26589
26804
|
}
|
|
26590
26805
|
async function findModel(loaded, portablePath) {
|
|
26591
|
-
const wanted =
|
|
26806
|
+
const wanted = import_node_path43.default.resolve(loaded.root, portablePath);
|
|
26592
26807
|
const model = (await discoverModels(loaded)).find((candidate) => candidate.file === wanted);
|
|
26593
26808
|
if (!model) throw new ManifestEditError(`"${portablePath}" is not a model under one of this project's output folders`);
|
|
26594
26809
|
return model;
|
|
26595
26810
|
}
|
|
26596
|
-
var stem = (editFile) => editFile.slice(0, -
|
|
26811
|
+
var stem = (editFile) => editFile.slice(0, -import_node_path43.default.extname(editFile).length);
|
|
26597
26812
|
function modelCompanionPath(editFile) {
|
|
26598
26813
|
return stem(editFile) + ".edit.json";
|
|
26599
26814
|
}
|
|
@@ -26632,7 +26847,7 @@ var ModelEditCompanionSchema = import_zod11.z.object({
|
|
|
26632
26847
|
}).strict();
|
|
26633
26848
|
async function readModelCompanion(editFile) {
|
|
26634
26849
|
try {
|
|
26635
|
-
return ModelEditCompanionSchema.parse(JSON.parse(await (0,
|
|
26850
|
+
return ModelEditCompanionSchema.parse(JSON.parse(await (0, import_promises33.readFile)(modelCompanionPath(editFile), "utf8")));
|
|
26636
26851
|
} catch {
|
|
26637
26852
|
return null;
|
|
26638
26853
|
}
|
|
@@ -26642,19 +26857,19 @@ function modelEditStatus(companion, builtSha256) {
|
|
|
26642
26857
|
return companion.outputs[0].basedOn === builtSha256 ? "edited" : "rebuilt-since";
|
|
26643
26858
|
}
|
|
26644
26859
|
async function replaceFile2(file, bytes) {
|
|
26645
|
-
await (0,
|
|
26860
|
+
await (0, import_promises33.mkdir)(import_node_path43.default.dirname(file), { recursive: true });
|
|
26646
26861
|
const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
26647
26862
|
try {
|
|
26648
|
-
await (0,
|
|
26649
|
-
await (0,
|
|
26863
|
+
await (0, import_promises33.writeFile)(tmp, bytes);
|
|
26864
|
+
await (0, import_promises33.rename)(tmp, file);
|
|
26650
26865
|
} finally {
|
|
26651
|
-
await (0,
|
|
26866
|
+
await (0, import_promises33.rm)(tmp, { force: true });
|
|
26652
26867
|
}
|
|
26653
26868
|
}
|
|
26654
26869
|
async function readModel(file, what) {
|
|
26655
26870
|
let bytes;
|
|
26656
26871
|
try {
|
|
26657
|
-
bytes = await (0,
|
|
26872
|
+
bytes = await (0, import_promises33.readFile)(file);
|
|
26658
26873
|
} catch {
|
|
26659
26874
|
throw new ManifestEditError(`${what} is not on disk at ${file}`);
|
|
26660
26875
|
}
|
|
@@ -26703,7 +26918,7 @@ async function saveModelTexture(model, input) {
|
|
|
26703
26918
|
sha256: sha256(input.png),
|
|
26704
26919
|
editor: input.editor,
|
|
26705
26920
|
savedAt,
|
|
26706
|
-
project: projectPath ?
|
|
26921
|
+
project: projectPath ? import_node_path43.default.basename(projectPath) : null
|
|
26707
26922
|
};
|
|
26708
26923
|
const companion = {
|
|
26709
26924
|
version: 2,
|
|
@@ -26807,16 +27022,16 @@ function blenderCommand(env = process.env, platform = process.platform, exists =
|
|
|
26807
27022
|
const candidates = [];
|
|
26808
27023
|
if (platform === "darwin") {
|
|
26809
27024
|
candidates.push("/Applications/Blender.app/Contents/MacOS/Blender");
|
|
26810
|
-
if (env.HOME) candidates.push(
|
|
27025
|
+
if (env.HOME) candidates.push(import_node_path43.default.join(env.HOME, "Applications/Blender.app/Contents/MacOS/Blender"));
|
|
26811
27026
|
} else if (platform === "win32") {
|
|
26812
27027
|
for (const root of [env.ProgramFiles, env["ProgramFiles(x86)"]].filter((value) => Boolean(value))) {
|
|
26813
|
-
const foundation =
|
|
27028
|
+
const foundation = import_node_path43.default.win32.join(root, "Blender Foundation");
|
|
26814
27029
|
const versions = list(foundation).filter((name) => /^Blender/i.test(name)).sort((a, b) => b.localeCompare(a, void 0, { numeric: true }));
|
|
26815
|
-
for (const version of versions) candidates.push(
|
|
27030
|
+
for (const version of versions) candidates.push(import_node_path43.default.win32.join(foundation, version, "blender.exe"));
|
|
26816
27031
|
}
|
|
26817
27032
|
} else {
|
|
26818
27033
|
candidates.push("/usr/bin/blender", "/usr/local/bin/blender", "/snap/bin/blender", "/var/lib/flatpak/exports/bin/org.blender.Blender");
|
|
26819
|
-
for (const dir of (env.PATH ?? "").split(":").filter(Boolean)) candidates.push(
|
|
27034
|
+
for (const dir of (env.PATH ?? "").split(":").filter(Boolean)) candidates.push(import_node_path43.default.join(dir, "blender"));
|
|
26820
27035
|
}
|
|
26821
27036
|
const found = candidates.find((candidate) => exists(candidate));
|
|
26822
27037
|
return found ? [found] : null;
|
|
@@ -26859,14 +27074,14 @@ function openInBlender(model, opts = {}) {
|
|
|
26859
27074
|
child.unref();
|
|
26860
27075
|
});
|
|
26861
27076
|
launch(program, args);
|
|
26862
|
-
return `${command.join(" ")} (${
|
|
27077
|
+
return `${command.join(" ")} (${import_node_path43.default.basename(file)})`;
|
|
26863
27078
|
}
|
|
26864
27079
|
|
|
26865
27080
|
// src/pipeline/model-normals.ts
|
|
26866
27081
|
var import_node_crypto9 = require("crypto");
|
|
26867
27082
|
var import_node_fs40 = require("fs");
|
|
26868
|
-
var
|
|
26869
|
-
var
|
|
27083
|
+
var import_promises34 = require("fs/promises");
|
|
27084
|
+
var import_node_path44 = __toESM(require("path"), 1);
|
|
26870
27085
|
var MODEL_NORMAL_SOURCES = ["texture", "views", "sprites"];
|
|
26871
27086
|
var TILE_MAX = 512;
|
|
26872
27087
|
function decodeImage(bytes) {
|
|
@@ -26958,13 +27173,13 @@ function poseNodes(document2, pose) {
|
|
|
26958
27173
|
const posed = /* @__PURE__ */ new Map();
|
|
26959
27174
|
for (const channel of animation.channels) {
|
|
26960
27175
|
const node = channel.target.node;
|
|
26961
|
-
const
|
|
26962
|
-
if (node === void 0 || !["translation", "rotation", "scale"].includes(
|
|
27176
|
+
const path55 = channel.target.path;
|
|
27177
|
+
if (node === void 0 || !["translation", "rotation", "scale"].includes(path55)) continue;
|
|
26963
27178
|
const sampler = animation.samplers[channel.sampler];
|
|
26964
27179
|
if (!sampler) continue;
|
|
26965
27180
|
const times = readAccessor(document2, sampler.input).data;
|
|
26966
27181
|
const values = readAccessor(document2, sampler.output);
|
|
26967
|
-
const width =
|
|
27182
|
+
const width = path55 === "rotation" ? 4 : 3;
|
|
26968
27183
|
const cubic = sampler.interpolation === "CUBICSPLINE";
|
|
26969
27184
|
const valueAt = (key4) => Array.from(values.data.subarray((cubic ? key4 * 3 + 1 : key4) * width, (cubic ? key4 * 3 + 1 : key4) * width + width));
|
|
26970
27185
|
const last = times.length - 1;
|
|
@@ -26976,16 +27191,16 @@ function poseNodes(document2, pose) {
|
|
|
26976
27191
|
const span = times[key3 + 1] - times[key3];
|
|
26977
27192
|
const f = span > 0 ? (time - times[key3]) / span : 0;
|
|
26978
27193
|
const next = valueAt(key3 + 1);
|
|
26979
|
-
const sign =
|
|
27194
|
+
const sign = path55 === "rotation" && value.reduce((sum, v, k) => sum + v * next[k], 0) < 0 ? -1 : 1;
|
|
26980
27195
|
value = value.map((v, k) => v * (1 - f) + next[k] * sign * f);
|
|
26981
27196
|
}
|
|
26982
|
-
if (
|
|
27197
|
+
if (path55 === "rotation") {
|
|
26983
27198
|
const length = Math.hypot(...value) || 1;
|
|
26984
27199
|
value = value.map((v) => v / length);
|
|
26985
27200
|
}
|
|
26986
27201
|
const base = posed.get(node) ?? { ...document2.json.nodes?.[node] ?? {} };
|
|
26987
27202
|
if (base.matrix) delete base.matrix;
|
|
26988
|
-
base[
|
|
27203
|
+
base[path55] = value;
|
|
26989
27204
|
posed.set(node, base);
|
|
26990
27205
|
}
|
|
26991
27206
|
return posed;
|
|
@@ -27595,9 +27810,9 @@ function modelSpritesDir(modelFile) {
|
|
|
27595
27810
|
return modelFile.replace(/\.glb$/i, "") + ".sprites";
|
|
27596
27811
|
}
|
|
27597
27812
|
async function readSpriteFolder(dir) {
|
|
27598
|
-
const folder = (0, import_node_fs40.existsSync)(
|
|
27599
|
-
const names = (await (0,
|
|
27600
|
-
return Promise.all(names.map(async (name) => ({ direction: name.slice(0, -4).toLowerCase(), png: await (0,
|
|
27813
|
+
const folder = (0, import_node_fs40.existsSync)(import_node_path44.default.join(dir, "rotations")) ? import_node_path44.default.join(dir, "rotations") : dir;
|
|
27814
|
+
const names = (await (0, import_promises34.readdir)(folder)).filter((name) => name.toLowerCase().endsWith(".png") && VIEW_TURNS[name.slice(0, -4).toLowerCase()] !== void 0).sort();
|
|
27815
|
+
return Promise.all(names.map(async (name) => ({ direction: name.slice(0, -4).toLowerCase(), png: await (0, import_promises34.readFile)(import_node_path44.default.join(folder, name)), file: import_node_path44.default.join(folder, name) })));
|
|
27601
27816
|
}
|
|
27602
27817
|
function modelNormalDir(editFile) {
|
|
27603
27818
|
return editFile.replace(/\.glb$/i, "") + ".normal-map";
|
|
@@ -27608,7 +27823,7 @@ function requestKey(png, options) {
|
|
|
27608
27823
|
}
|
|
27609
27824
|
async function prepare(model, opts) {
|
|
27610
27825
|
const fromEdit = (0, import_node_fs40.existsSync)(model.editFile);
|
|
27611
|
-
const document2 = parseGlb(await (0,
|
|
27826
|
+
const document2 = parseGlb(await (0, import_promises34.readFile)(fromEdit ? model.editFile : model.file));
|
|
27612
27827
|
const summary = describeGlb(document2);
|
|
27613
27828
|
const normalImages = summary.images.filter((image) => image.roles.includes("normal"));
|
|
27614
27829
|
if (!normalImages.length) throw new Error("the model has no normal maps; this adds detail to one it has, it does not add a new one");
|
|
@@ -27617,13 +27832,13 @@ async function prepare(model, opts) {
|
|
|
27617
27832
|
if (!normalImages.some((image) => image.index === index)) throw new Error(`image ${index} is not one of the model's normal maps`);
|
|
27618
27833
|
}
|
|
27619
27834
|
const primitives = restPrimitives(document2, opts.pose);
|
|
27620
|
-
const dir =
|
|
27835
|
+
const dir = import_node_path44.default.join(modelNormalDir(model.editFile), opts.source);
|
|
27621
27836
|
const surfaces = /* @__PURE__ */ new Map();
|
|
27622
27837
|
const tiles = /* @__PURE__ */ new Map();
|
|
27623
27838
|
const calls = [];
|
|
27624
27839
|
const images = [];
|
|
27625
27840
|
const call = (label, png) => {
|
|
27626
|
-
const cache =
|
|
27841
|
+
const cache = import_node_path44.default.join(dir, `${label.replace(/[^a-z0-9]+/gi, "-")}.${requestKey(png, opts)}.normal.png`);
|
|
27627
27842
|
calls.push({ label, png, cache, cached: (0, import_node_fs40.existsSync)(cache) });
|
|
27628
27843
|
};
|
|
27629
27844
|
for (const index of wanted) {
|
|
@@ -27692,15 +27907,15 @@ async function prepare(model, opts) {
|
|
|
27692
27907
|
}
|
|
27693
27908
|
async function planModelNormals(model, opts) {
|
|
27694
27909
|
const { plan } = await prepare(model, opts);
|
|
27695
|
-
await (0,
|
|
27696
|
-
for (const entry of plan.calls) await (0,
|
|
27697
|
-
for (const fit of plan.fits ?? []) await (0,
|
|
27910
|
+
await (0, import_promises34.mkdir)(plan.dir, { recursive: true });
|
|
27911
|
+
for (const entry of plan.calls) await (0, import_promises34.writeFile)(entry.cache.replace(/\.[0-9a-f]{16}\.normal\.png$/, ".png"), entry.png);
|
|
27912
|
+
for (const fit of plan.fits ?? []) await (0, import_promises34.writeFile)(import_node_path44.default.join(plan.dir, `${fit.label.replace(/[^a-z0-9]+/gi, "-")}.fit.png`), fit.png);
|
|
27698
27913
|
return plan;
|
|
27699
27914
|
}
|
|
27700
27915
|
async function generateModelNormals(model, opts, mapper, hooks = {}) {
|
|
27701
27916
|
const prepared = await prepare(model, opts);
|
|
27702
27917
|
const { plan, document: document2 } = prepared;
|
|
27703
|
-
await (0,
|
|
27918
|
+
await (0, import_promises34.mkdir)(plan.dir, { recursive: true });
|
|
27704
27919
|
const request = {
|
|
27705
27920
|
...opts.mode ? { mode: opts.mode } : {},
|
|
27706
27921
|
...opts.kind ? { kind: opts.kind } : {},
|
|
@@ -27712,14 +27927,14 @@ async function generateModelNormals(model, opts, mapper, hooks = {}) {
|
|
|
27712
27927
|
let sent = 0;
|
|
27713
27928
|
for (const entry of plan.calls) {
|
|
27714
27929
|
hooks.onCall?.(entry.label, entry.cached);
|
|
27715
|
-
await (0,
|
|
27930
|
+
await (0, import_promises34.writeFile)(entry.cache.replace(/\.[0-9a-f]{16}\.normal\.png$/, ".png"), entry.png);
|
|
27716
27931
|
if (entry.cached) {
|
|
27717
|
-
answers.push(await (0,
|
|
27932
|
+
answers.push(await (0, import_promises34.readFile)(entry.cache));
|
|
27718
27933
|
continue;
|
|
27719
27934
|
}
|
|
27720
27935
|
const answer = await mapper(entry.png, request);
|
|
27721
27936
|
sent++;
|
|
27722
|
-
await (0,
|
|
27937
|
+
await (0, import_promises34.writeFile)(entry.cache, answer);
|
|
27723
27938
|
answers.push(answer);
|
|
27724
27939
|
}
|
|
27725
27940
|
let result = null;
|
|
@@ -27737,14 +27952,14 @@ async function generateModelNormals(model, opts, mapper, hooks = {}) {
|
|
|
27737
27952
|
field = detailFromViews(surface, prepared.views, answers);
|
|
27738
27953
|
}
|
|
27739
27954
|
bleed(field);
|
|
27740
|
-
const detail =
|
|
27741
|
-
await (0,
|
|
27955
|
+
const detail = import_node_path44.default.join(plan.dir, `image-${image}.detail.png`);
|
|
27956
|
+
await (0, import_promises34.writeFile)(detail, encodeImage(fieldImage(field)));
|
|
27742
27957
|
details.push(detail);
|
|
27743
|
-
const basePath =
|
|
27958
|
+
const basePath = import_node_path44.default.join(modelNormalDir(model.editFile), `image-${image}.base.png`);
|
|
27744
27959
|
const record = companion?.textures.find((entry) => entry.image === image);
|
|
27745
27960
|
const ours = record?.editor.startsWith(PIXELLAB_EDITOR) === true && (0, import_node_fs40.existsSync)(basePath);
|
|
27746
|
-
const existing = ours ? decodeImage(await (0,
|
|
27747
|
-
if (!ours) await (0,
|
|
27961
|
+
const existing = ours ? decodeImage(await (0, import_promises34.readFile)(basePath)) : decodeImage(glbImageBytes(document2, image).bytes);
|
|
27962
|
+
if (!ours) await (0, import_promises34.writeFile)(basePath, encodeImage(existing));
|
|
27748
27963
|
const png = encodeImage(applyDetail(existing, field, opts));
|
|
27749
27964
|
result = await saveModelTexture(model, {
|
|
27750
27965
|
image,
|
|
@@ -27773,7 +27988,7 @@ function modelNormalMapper(client2) {
|
|
|
27773
27988
|
// src/gallery/models.ts
|
|
27774
27989
|
var MODEL_FILE_TYPE = "model/gltf-binary";
|
|
27775
27990
|
async function describeFile(media, mediaId, root, file, bytes) {
|
|
27776
|
-
const info = await (0,
|
|
27991
|
+
const info = await (0, import_promises35.stat)(file);
|
|
27777
27992
|
const id = mediaId(file);
|
|
27778
27993
|
const hash = sha256(bytes);
|
|
27779
27994
|
media.set(id, { path: file, contentType: MODEL_FILE_TYPE });
|
|
@@ -27792,11 +28007,11 @@ async function describeModels(loaded, media, mediaId, opts = {}) {
|
|
|
27792
28007
|
for (const model of await discoverModels(loaded, opts)) {
|
|
27793
28008
|
let bytes;
|
|
27794
28009
|
try {
|
|
27795
|
-
bytes = await (0,
|
|
28010
|
+
bytes = await (0, import_promises35.readFile)(model.file);
|
|
27796
28011
|
} catch {
|
|
27797
28012
|
continue;
|
|
27798
28013
|
}
|
|
27799
|
-
const outDir =
|
|
28014
|
+
const outDir = import_node_path45.default.resolve(root, loaded.manifest.styles[model.styleId]?.outDir ?? ".");
|
|
27800
28015
|
let summary = null;
|
|
27801
28016
|
let error = null;
|
|
27802
28017
|
if (bytes.length > MAX_MODEL_BYTES) error = `the file is ${bytes.length} bytes; models over ${MAX_MODEL_BYTES} are listed but not opened`;
|
|
@@ -27812,7 +28027,7 @@ async function describeModels(loaded, media, mediaId, opts = {}) {
|
|
|
27812
28027
|
let adoptedExport = null;
|
|
27813
28028
|
if ((0, import_node_fs41.existsSync)(model.editFile)) {
|
|
27814
28029
|
try {
|
|
27815
|
-
const editBytes = await (0,
|
|
28030
|
+
const editBytes = await (0, import_promises35.readFile)(model.editFile);
|
|
27816
28031
|
const described = await describeFile(media, mediaId, root, model.editFile, editBytes);
|
|
27817
28032
|
const companion = await readModelCompanion(model.editFile);
|
|
27818
28033
|
adoptedExport = companion?.adoptedExport ?? null;
|
|
@@ -27848,8 +28063,8 @@ async function describeModels(loaded, media, mediaId, opts = {}) {
|
|
|
27848
28063
|
const exportFile = modelExportPath(model.editFile);
|
|
27849
28064
|
let exportWaiting = null;
|
|
27850
28065
|
try {
|
|
27851
|
-
const info = await (0,
|
|
27852
|
-
if (info.isFile() && info.size <= MAX_MODEL_BYTES && sha256(await (0,
|
|
28066
|
+
const info = await (0, import_promises35.stat)(exportFile);
|
|
28067
|
+
if (info.isFile() && info.size <= MAX_MODEL_BYTES && sha256(await (0, import_promises35.readFile)(exportFile)) !== adoptedExport) {
|
|
27853
28068
|
exportWaiting = { bytes: info.size, modifiedAt: info.mtime.toISOString() };
|
|
27854
28069
|
}
|
|
27855
28070
|
} catch {
|
|
@@ -27862,12 +28077,12 @@ async function describeModels(loaded, media, mediaId, opts = {}) {
|
|
|
27862
28077
|
} catch {
|
|
27863
28078
|
}
|
|
27864
28079
|
}
|
|
27865
|
-
const relative =
|
|
28080
|
+
const relative = import_node_path45.default.relative(outDir, model.file).split(import_node_path45.default.sep).join("/");
|
|
27866
28081
|
models.push({
|
|
27867
28082
|
id: `model:${model.styleId}/${relative}`,
|
|
27868
28083
|
project: null,
|
|
27869
28084
|
styleId: model.styleId,
|
|
27870
|
-
name:
|
|
28085
|
+
name: import_node_path45.default.basename(model.file, import_node_path45.default.extname(model.file)),
|
|
27871
28086
|
file,
|
|
27872
28087
|
summary,
|
|
27873
28088
|
error,
|
|
@@ -27962,9 +28177,9 @@ function blenderAvailable() {
|
|
|
27962
28177
|
}
|
|
27963
28178
|
|
|
27964
28179
|
// src/workspace.ts
|
|
27965
|
-
var
|
|
28180
|
+
var import_promises36 = require("fs/promises");
|
|
27966
28181
|
var import_node_fs42 = require("fs");
|
|
27967
|
-
var
|
|
28182
|
+
var import_node_path46 = __toESM(require("path"), 1);
|
|
27968
28183
|
var import_zod13 = require("zod");
|
|
27969
28184
|
var WorkspaceProjectSchema = import_zod13.z.object({
|
|
27970
28185
|
id: import_zod13.z.string().min(1),
|
|
@@ -27992,7 +28207,7 @@ async function loadWorkspace(workspacePath) {
|
|
|
27992
28207
|
if (!(0, import_node_fs42.existsSync)(workspacePath)) return { version: 1, projects: [] };
|
|
27993
28208
|
let raw;
|
|
27994
28209
|
try {
|
|
27995
|
-
raw = JSON.parse(await (0,
|
|
28210
|
+
raw = JSON.parse(await (0, import_promises36.readFile)(workspacePath, "utf8"));
|
|
27996
28211
|
} catch (err) {
|
|
27997
28212
|
throw new ProjectError(
|
|
27998
28213
|
`Workspace catalog at ${workspacePath} is malformed:
|
|
@@ -28006,22 +28221,22 @@ async function saveWorkspace(workspacePath, ws) {
|
|
|
28006
28221
|
version: 1,
|
|
28007
28222
|
projects: [...ws.projects].sort((a, b) => a.id.localeCompare(b.id))
|
|
28008
28223
|
};
|
|
28009
|
-
await (0,
|
|
28224
|
+
await (0, import_promises36.mkdir)(import_node_path46.default.dirname(import_node_path46.default.resolve(workspacePath)), { recursive: true });
|
|
28010
28225
|
const tmp = `${workspacePath}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
28011
28226
|
try {
|
|
28012
|
-
await (0,
|
|
28013
|
-
await (0,
|
|
28227
|
+
await (0, import_promises36.writeFile)(tmp, JSON.stringify(sorted, null, 2) + "\n");
|
|
28228
|
+
await (0, import_promises36.rename)(tmp, workspacePath);
|
|
28014
28229
|
} finally {
|
|
28015
|
-
await (0,
|
|
28230
|
+
await (0, import_promises36.rm)(tmp, { force: true });
|
|
28016
28231
|
}
|
|
28017
28232
|
}
|
|
28018
28233
|
function toPortablePath(dir, absolute) {
|
|
28019
|
-
return
|
|
28234
|
+
return import_node_path46.default.relative(dir, absolute).split(import_node_path46.default.sep).join("/");
|
|
28020
28235
|
}
|
|
28021
28236
|
function resolveProject(dir, project2) {
|
|
28022
28237
|
return {
|
|
28023
|
-
manifestPath:
|
|
28024
|
-
lockPath:
|
|
28238
|
+
manifestPath: import_node_path46.default.resolve(dir, project2.manifest.split("/").join(import_node_path46.default.sep)),
|
|
28239
|
+
lockPath: import_node_path46.default.resolve(dir, project2.lock.split("/").join(import_node_path46.default.sep))
|
|
28025
28240
|
};
|
|
28026
28241
|
}
|
|
28027
28242
|
function validateWorkspace(ws, dir) {
|
|
@@ -28034,7 +28249,7 @@ function validateWorkspace(ws, dir) {
|
|
|
28034
28249
|
const { manifestPath, lockPath } = resolveProject(dir, project2);
|
|
28035
28250
|
lockOwners.set(lockPath, [...lockOwners.get(lockPath) ?? [], project2.id]);
|
|
28036
28251
|
manifestOwners.set(manifestPath, [...manifestOwners.get(manifestPath) ?? [], project2.id]);
|
|
28037
|
-
if (
|
|
28252
|
+
if (import_node_path46.default.isAbsolute(project2.manifest) || import_node_path46.default.isAbsolute(project2.lock)) {
|
|
28038
28253
|
diagnostics.push({
|
|
28039
28254
|
id: "absolute-path",
|
|
28040
28255
|
level: "warning",
|
|
@@ -28095,14 +28310,14 @@ function validateWorkspace(ws, dir) {
|
|
|
28095
28310
|
}
|
|
28096
28311
|
|
|
28097
28312
|
// src/gallery/edit.ts
|
|
28098
|
-
var
|
|
28099
|
-
var
|
|
28313
|
+
var import_promises40 = require("fs/promises");
|
|
28314
|
+
var import_node_path50 = __toESM(require("path"), 1);
|
|
28100
28315
|
var import_zod17 = require("zod");
|
|
28101
28316
|
|
|
28102
28317
|
// src/gallery/upload.ts
|
|
28103
28318
|
var import_node_fs43 = require("fs");
|
|
28104
|
-
var
|
|
28105
|
-
var
|
|
28319
|
+
var import_promises37 = require("fs/promises");
|
|
28320
|
+
var import_node_path47 = __toESM(require("path"), 1);
|
|
28106
28321
|
var import_zod14 = require("zod");
|
|
28107
28322
|
var MAX_UPLOAD_BYTES = 8 * 1024 * 1024;
|
|
28108
28323
|
var UploadImageSchema = import_zod14.z.object({
|
|
@@ -28115,12 +28330,12 @@ var UploadImageSchema = import_zod14.z.object({
|
|
|
28115
28330
|
overwrite: import_zod14.z.boolean().optional()
|
|
28116
28331
|
}).strict();
|
|
28117
28332
|
async function saveProjectImage(root, request) {
|
|
28118
|
-
const file =
|
|
28119
|
-
const relative =
|
|
28120
|
-
if (relative.startsWith("..") ||
|
|
28333
|
+
const file = import_node_path47.default.resolve(root, request.path);
|
|
28334
|
+
const relative = import_node_path47.default.relative(root, file);
|
|
28335
|
+
if (relative.startsWith("..") || import_node_path47.default.isAbsolute(relative)) {
|
|
28121
28336
|
throw new ManifestEditError("an upload must stay inside the project");
|
|
28122
28337
|
}
|
|
28123
|
-
const extension =
|
|
28338
|
+
const extension = import_node_path47.default.extname(file).toLowerCase();
|
|
28124
28339
|
const expected = extension === ".png" ? "png" : extension === ".jpg" || extension === ".jpeg" ? "jpeg" : null;
|
|
28125
28340
|
if (!expected) throw new ManifestEditError("an upload must be a .png, .jpg, or .jpeg path");
|
|
28126
28341
|
const bytes = Buffer.from(request.base64, "base64");
|
|
@@ -28133,17 +28348,17 @@ async function saveProjectImage(root, request) {
|
|
|
28133
28348
|
throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
|
|
28134
28349
|
}
|
|
28135
28350
|
if ((0, import_node_fs43.existsSync)(file) && !request.overwrite) {
|
|
28136
|
-
throw new ManifestEditError(`${relative.split(
|
|
28351
|
+
throw new ManifestEditError(`${relative.split(import_node_path47.default.sep).join("/")} already exists; choose another name, or replace it`);
|
|
28137
28352
|
}
|
|
28138
|
-
await (0,
|
|
28139
|
-
await (0,
|
|
28140
|
-
return relative.split(
|
|
28353
|
+
await (0, import_promises37.mkdir)(import_node_path47.default.dirname(file), { recursive: true });
|
|
28354
|
+
await (0, import_promises37.writeFile)(file, bytes);
|
|
28355
|
+
return relative.split(import_node_path47.default.sep).join("/");
|
|
28141
28356
|
}
|
|
28142
28357
|
|
|
28143
28358
|
// src/gallery/image-revision.ts
|
|
28144
28359
|
var import_node_fs44 = require("fs");
|
|
28145
|
-
var
|
|
28146
|
-
var
|
|
28360
|
+
var import_promises38 = require("fs/promises");
|
|
28361
|
+
var import_node_path48 = __toESM(require("path"), 1);
|
|
28147
28362
|
var import_zod15 = require("zod");
|
|
28148
28363
|
var InpaintRevisionRequestSchema = import_zod15.z.object({
|
|
28149
28364
|
action: import_zod15.z.literal("create-inpaint-revision"),
|
|
@@ -28162,15 +28377,15 @@ var InpaintRevisionRequestSchema = import_zod15.z.object({
|
|
|
28162
28377
|
overwrite: import_zod15.z.boolean().optional()
|
|
28163
28378
|
}).strict();
|
|
28164
28379
|
async function createInpaintRevision(manifestPath, request) {
|
|
28165
|
-
const root =
|
|
28166
|
-
if (
|
|
28380
|
+
const root = import_node_path48.default.dirname(import_node_path48.default.resolve(manifestPath));
|
|
28381
|
+
if (import_node_path48.default.extname(request.maskPath).toLowerCase() !== ".png") {
|
|
28167
28382
|
throw new ManifestEditError("the mask must be a .png path inside the project");
|
|
28168
28383
|
}
|
|
28169
28384
|
const bytes = Buffer.from(request.maskBase64, "base64");
|
|
28170
28385
|
const metadata = imageMetadata(bytes);
|
|
28171
28386
|
if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
|
|
28172
|
-
const file =
|
|
28173
|
-
const previous = (0, import_node_fs44.existsSync)(file) ? await (0,
|
|
28387
|
+
const file = import_node_path48.default.resolve(root, request.maskPath);
|
|
28388
|
+
const previous = (0, import_node_fs44.existsSync)(file) ? await (0, import_promises38.readFile)(file) : null;
|
|
28174
28389
|
const mask = await saveProjectImage(root, {
|
|
28175
28390
|
action: "upload-image",
|
|
28176
28391
|
path: request.maskPath,
|
|
@@ -28189,8 +28404,8 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
28189
28404
|
}
|
|
28190
28405
|
});
|
|
28191
28406
|
} catch (error) {
|
|
28192
|
-
if (previous) await (0,
|
|
28193
|
-
else await (0,
|
|
28407
|
+
if (previous) await (0, import_promises38.writeFile)(file, previous);
|
|
28408
|
+
else await (0, import_promises38.rm)(file, { force: true });
|
|
28194
28409
|
throw error;
|
|
28195
28410
|
}
|
|
28196
28411
|
return mask;
|
|
@@ -28198,8 +28413,8 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
28198
28413
|
|
|
28199
28414
|
// src/gallery/skeleton.ts
|
|
28200
28415
|
var import_node_fs45 = require("fs");
|
|
28201
|
-
var
|
|
28202
|
-
var
|
|
28416
|
+
var import_promises39 = require("fs/promises");
|
|
28417
|
+
var import_node_path49 = __toESM(require("path"), 1);
|
|
28203
28418
|
var import_zod16 = require("zod");
|
|
28204
28419
|
var SkeletonEstimateRequestSchema = import_zod16.z.object({
|
|
28205
28420
|
project: import_zod16.z.string().min(1).optional(),
|
|
@@ -28238,10 +28453,10 @@ var SkeletonKeypointsUpdateSchema = import_zod16.z.object({
|
|
|
28238
28453
|
set: SkeletonSetSchema
|
|
28239
28454
|
}).strict();
|
|
28240
28455
|
async function createSkeletonAnimation(manifestPath, request) {
|
|
28241
|
-
const root =
|
|
28242
|
-
const file =
|
|
28243
|
-
const relative =
|
|
28244
|
-
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") ||
|
|
28456
|
+
const root = import_node_path49.default.dirname(import_node_path49.default.resolve(manifestPath));
|
|
28457
|
+
const file = import_node_path49.default.resolve(root, request.keypointsFile);
|
|
28458
|
+
const relative = import_node_path49.default.relative(root, file);
|
|
28459
|
+
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || import_node_path49.default.isAbsolute(relative)) {
|
|
28245
28460
|
throw new ManifestEditError("the keypoints file must be a .json path inside the project");
|
|
28246
28461
|
}
|
|
28247
28462
|
const existed = (0, import_node_fs45.existsSync)(file);
|
|
@@ -28250,9 +28465,9 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
28250
28465
|
if (existed && !request.overwrite) {
|
|
28251
28466
|
throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
|
|
28252
28467
|
}
|
|
28253
|
-
if (existed) previous = await (0,
|
|
28254
|
-
await (0,
|
|
28255
|
-
await (0,
|
|
28468
|
+
if (existed) previous = await (0, import_promises39.readFile)(file);
|
|
28469
|
+
await (0, import_promises39.mkdir)(import_node_path49.default.dirname(file), { recursive: true });
|
|
28470
|
+
await (0, import_promises39.writeFile)(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
28256
28471
|
} else if (!existed) {
|
|
28257
28472
|
throw new ManifestEditError(`${request.keypointsFile} does not exist; paste poses or estimate them from the sprite`);
|
|
28258
28473
|
}
|
|
@@ -28267,7 +28482,7 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
28267
28482
|
revision: {
|
|
28268
28483
|
mode: "animate-skeleton",
|
|
28269
28484
|
from: request.from,
|
|
28270
|
-
keypointsFile: relative.split(
|
|
28485
|
+
keypointsFile: relative.split(import_node_path49.default.sep).join("/"),
|
|
28271
28486
|
direction: request.direction,
|
|
28272
28487
|
description: request.description,
|
|
28273
28488
|
...request.skeletonTemplate ? { skeletonTemplate: request.skeletonTemplate } : {}
|
|
@@ -28276,8 +28491,8 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
28276
28491
|
});
|
|
28277
28492
|
} catch (error) {
|
|
28278
28493
|
if (request.set) {
|
|
28279
|
-
if (previous) await (0,
|
|
28280
|
-
else await (0,
|
|
28494
|
+
if (previous) await (0, import_promises39.writeFile)(file, previous);
|
|
28495
|
+
else await (0, import_promises39.rm)(file, { force: true });
|
|
28281
28496
|
}
|
|
28282
28497
|
throw error;
|
|
28283
28498
|
}
|
|
@@ -28288,19 +28503,19 @@ async function updateSkeletonKeypoints(ctx, request) {
|
|
|
28288
28503
|
if (!spec) throw new ManifestEditError(`"${key3}" is not declared by the manifest`);
|
|
28289
28504
|
const file = spec.revision?.mode === "animate-skeleton" ? spec.revision.keypointsFile : void 0;
|
|
28290
28505
|
if (!file) throw new ManifestEditError(`${key3} is not an animate-skeleton revision`);
|
|
28291
|
-
const relative =
|
|
28292
|
-
if (relative.startsWith("..") ||
|
|
28506
|
+
const relative = import_node_path49.default.relative(ctx.loaded.root, file);
|
|
28507
|
+
if (relative.startsWith("..") || import_node_path49.default.isAbsolute(relative)) {
|
|
28293
28508
|
throw new ManifestEditError(`${key3}'s keypoints file is outside the project; edit it by hand`);
|
|
28294
28509
|
}
|
|
28295
|
-
const current = (0, import_node_fs45.existsSync)(file) ? sha256(await (0,
|
|
28510
|
+
const current = (0, import_node_fs45.existsSync)(file) ? sha256(await (0, import_promises39.readFile)(file)) : null;
|
|
28296
28511
|
if (current !== request.expectedSha256) {
|
|
28297
28512
|
throw Object.assign(
|
|
28298
|
-
new Error(`${relative.split(
|
|
28513
|
+
new Error(`${relative.split(import_node_path49.default.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
|
|
28299
28514
|
{ status: 409 }
|
|
28300
28515
|
);
|
|
28301
28516
|
}
|
|
28302
|
-
await (0,
|
|
28303
|
-
return relative.split(
|
|
28517
|
+
await (0, import_promises39.writeFile)(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
28518
|
+
return relative.split(import_node_path49.default.sep).join("/");
|
|
28304
28519
|
}
|
|
28305
28520
|
|
|
28306
28521
|
// src/gallery/edit.ts
|
|
@@ -28354,7 +28569,7 @@ function createGalleryEditHandler(opts) {
|
|
|
28354
28569
|
const history = /* @__PURE__ */ new Map();
|
|
28355
28570
|
const manifestOf = async (project2) => {
|
|
28356
28571
|
try {
|
|
28357
|
-
return
|
|
28572
|
+
return import_node_path50.default.resolve(await opts.manifestFor(typeof project2 === "string" ? project2 : void 0));
|
|
28358
28573
|
} catch {
|
|
28359
28574
|
return null;
|
|
28360
28575
|
}
|
|
@@ -28364,7 +28579,7 @@ function createGalleryEditHandler(opts) {
|
|
|
28364
28579
|
if (undo.success) {
|
|
28365
28580
|
const manifestPath2 = await manifestOf(undo.data.project);
|
|
28366
28581
|
if (!manifestPath2) throw new ManifestEditError("no manifest to undo an edit in");
|
|
28367
|
-
const current = await (0,
|
|
28582
|
+
const current = await (0, import_promises40.readFile)(manifestPath2, "utf8");
|
|
28368
28583
|
if (sha256(current) !== undo.data.expectedSha256) throw new ManifestDriftError(manifestPath2);
|
|
28369
28584
|
const stack = history.get(manifestPath2) ?? [];
|
|
28370
28585
|
const last = stack[stack.length - 1];
|
|
@@ -28374,17 +28589,17 @@ function createGalleryEditHandler(opts) {
|
|
|
28374
28589
|
throw Object.assign(new Error("the manifest changed outside the gallery since its last edit; undo would discard that change"), { status: 409 });
|
|
28375
28590
|
}
|
|
28376
28591
|
const tmp = manifestPath2 + ".pixelkiln-undo";
|
|
28377
|
-
await (0,
|
|
28378
|
-
await (0,
|
|
28592
|
+
await (0, import_promises40.writeFile)(tmp, last.before);
|
|
28593
|
+
await (0, import_promises40.rename)(tmp, manifestPath2);
|
|
28379
28594
|
stack.pop();
|
|
28380
|
-
log(` manifest edit undone in ${
|
|
28595
|
+
log(` manifest edit undone in ${import_node_path50.default.relative(process.cwd(), manifestPath2) || manifestPath2}`);
|
|
28381
28596
|
return opts.reload();
|
|
28382
28597
|
}
|
|
28383
28598
|
const manifestPath = await manifestOf(body?.project);
|
|
28384
|
-
const before = manifestPath ? await (0,
|
|
28599
|
+
const before = manifestPath ? await (0, import_promises40.readFile)(manifestPath, "utf8").catch(() => null) : null;
|
|
28385
28600
|
const build = await apply(body);
|
|
28386
28601
|
if (manifestPath && before !== null) {
|
|
28387
|
-
const after = await (0,
|
|
28602
|
+
const after = await (0, import_promises40.readFile)(manifestPath, "utf8").catch(() => null);
|
|
28388
28603
|
if (after !== null && after !== before) {
|
|
28389
28604
|
const stack = history.get(manifestPath) ?? [];
|
|
28390
28605
|
stack.push({ before, afterSha: sha256(after) });
|
|
@@ -28463,7 +28678,7 @@ function createEditApplier(opts, log) {
|
|
|
28463
28678
|
} catch (error) {
|
|
28464
28679
|
throw new ManifestEditError(error instanceof Error ? error.message : String(error));
|
|
28465
28680
|
}
|
|
28466
|
-
const written = await saveProjectImage(
|
|
28681
|
+
const written = await saveProjectImage(import_node_path50.default.dirname(import_node_path50.default.resolve(manifestPath2)), upload.data);
|
|
28467
28682
|
log(` image added: ${written}`);
|
|
28468
28683
|
return opts.reload();
|
|
28469
28684
|
}
|
|
@@ -28530,7 +28745,7 @@ function createEditApplier(opts, log) {
|
|
|
28530
28745
|
}
|
|
28531
28746
|
const result = await applyManifestEdit(manifestPath, parsed.data);
|
|
28532
28747
|
if (result.changed) {
|
|
28533
|
-
const relative =
|
|
28748
|
+
const relative = import_node_path50.default.relative(process.cwd(), result.manifestPath);
|
|
28534
28749
|
const shown = !relative || relative.startsWith("..") ? result.manifestPath : relative;
|
|
28535
28750
|
log(` manifest edited: ${describeEdit(parsed.data)} in ${shown}`);
|
|
28536
28751
|
}
|
|
@@ -28558,7 +28773,7 @@ function describeEdit(edit) {
|
|
|
28558
28773
|
// src/gallery/snapshot.ts
|
|
28559
28774
|
var PROJECT_FILE_TYPE = "application/octet-stream";
|
|
28560
28775
|
function galleryMediaId(absolutePath) {
|
|
28561
|
-
return (0, import_node_crypto10.createHash)("sha256").update(
|
|
28776
|
+
return (0, import_node_crypto10.createHash)("sha256").update(import_node_path51.default.resolve(absolutePath)).digest("hex").slice(0, 24);
|
|
28562
28777
|
}
|
|
28563
28778
|
function galleryMediaRoute(id) {
|
|
28564
28779
|
return `/media/${id}`;
|
|
@@ -28582,7 +28797,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
28582
28797
|
return (entry.history ?? []).map((generation, i) => {
|
|
28583
28798
|
const outputs = generation.outputs.map((output) => {
|
|
28584
28799
|
const mediaType = output.mediaType ?? MediaType.PNG;
|
|
28585
|
-
const file =
|
|
28800
|
+
const file = import_node_path51.default.join(cacheDir, cacheFileName(output.sha256, mediaType));
|
|
28586
28801
|
let url = null;
|
|
28587
28802
|
if ((0, import_node_fs46.existsSync)(file)) {
|
|
28588
28803
|
const id = galleryMediaId(file);
|
|
@@ -28616,7 +28831,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
28616
28831
|
var MAX_COMPARED_BYTES = 8 * 1024 * 1024;
|
|
28617
28832
|
async function samePixels(a, b) {
|
|
28618
28833
|
try {
|
|
28619
|
-
const [left, right] = await Promise.all([(0,
|
|
28834
|
+
const [left, right] = await Promise.all([(0, import_promises41.readFile)(a), (0, import_promises41.readFile)(b)]);
|
|
28620
28835
|
if (left.length > MAX_COMPARED_BYTES || right.length > MAX_COMPARED_BYTES) return false;
|
|
28621
28836
|
const x = decodePng(left);
|
|
28622
28837
|
const y = decodePng(right);
|
|
@@ -28682,7 +28897,7 @@ function describeCharacter(spec, entry) {
|
|
|
28682
28897
|
}
|
|
28683
28898
|
async function fileInfo(absolutePath) {
|
|
28684
28899
|
try {
|
|
28685
|
-
const info = await (0,
|
|
28900
|
+
const info = await (0, import_promises41.stat)(absolutePath);
|
|
28686
28901
|
return info.isFile() ? { bytes: info.size, modifiedAt: info.mtime.toISOString() } : null;
|
|
28687
28902
|
} catch {
|
|
28688
28903
|
return null;
|
|
@@ -28714,9 +28929,9 @@ async function describeOutput(media, root, absolutePath, recorded = {}) {
|
|
|
28714
28929
|
async function describeQuality(media, root, inspection) {
|
|
28715
28930
|
const outputPaths = inspection.outputs ?? [inspection.output];
|
|
28716
28931
|
const outputs = await Promise.all(
|
|
28717
|
-
outputPaths.map((file) => describeOutput(media, root,
|
|
28932
|
+
outputPaths.map((file) => describeOutput(media, root, import_node_path51.default.resolve(root, file)))
|
|
28718
28933
|
);
|
|
28719
|
-
const recordPath =
|
|
28934
|
+
const recordPath = import_node_path51.default.resolve(root, inspection.record);
|
|
28720
28935
|
const recordExists = (0, import_node_fs46.existsSync)(recordPath);
|
|
28721
28936
|
let options = null;
|
|
28722
28937
|
let check = null;
|
|
@@ -28736,7 +28951,7 @@ async function describeQuality(media, root, inspection) {
|
|
|
28736
28951
|
return {
|
|
28737
28952
|
state: inspection.state,
|
|
28738
28953
|
reason: inspection.reason,
|
|
28739
|
-
output: portableOutputPath(
|
|
28954
|
+
output: portableOutputPath(import_node_path51.default.resolve(root, inspection.output), root),
|
|
28740
28955
|
record: portableOutputPath(recordPath, root),
|
|
28741
28956
|
recordExists,
|
|
28742
28957
|
outputs,
|
|
@@ -28774,9 +28989,9 @@ async function buildGallerySnapshot(opts) {
|
|
|
28774
28989
|
const media = /* @__PURE__ */ new Map();
|
|
28775
28990
|
const plan = await buildPlan(specs, lock);
|
|
28776
28991
|
const items = [];
|
|
28777
|
-
const manifestText = await (0,
|
|
28992
|
+
const manifestText = await (0, import_promises41.readFile)(loaded.path, "utf8");
|
|
28778
28993
|
const manifestSha256 = sha256(manifestText);
|
|
28779
|
-
const cacheDir =
|
|
28994
|
+
const cacheDir = import_node_path51.default.resolve(import_node_path51.default.dirname(opts.lockPath), ".pixelkiln", "cache");
|
|
28780
28995
|
let rawStyles = {};
|
|
28781
28996
|
try {
|
|
28782
28997
|
const raw = JSON.parse(manifestText);
|
|
@@ -28800,7 +29015,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
28800
29015
|
)
|
|
28801
29016
|
);
|
|
28802
29017
|
if (spec.source) {
|
|
28803
|
-
const editPath =
|
|
29018
|
+
const editPath = import_node_path51.default.resolve(root, spec.source);
|
|
28804
29019
|
const memberCount = sourceIsStem(spec.source, entry, root) ? entry.outputs.length : 1;
|
|
28805
29020
|
const editShas = await Promise.all(
|
|
28806
29021
|
Array.from({ length: memberCount }, async (_, index) => {
|
|
@@ -28849,7 +29064,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
28849
29064
|
editStatus = edits.some((member) => !member.exists) ? "missing" : editChanged.every((changed) => !changed) ? "same" : regenerated ? "regenerated-since" : "edited";
|
|
28850
29065
|
}
|
|
28851
29066
|
} else if (spec.source) {
|
|
28852
|
-
outputs = [await describeOutput(media, root,
|
|
29067
|
+
outputs = [await describeOutput(media, root, import_node_path51.default.resolve(root, spec.source))];
|
|
28853
29068
|
} else if (!entry && (0, import_node_fs46.existsSync)(spec.outFile)) {
|
|
28854
29069
|
outputs = [await describeOutput(media, root, spec.outFile)];
|
|
28855
29070
|
} else {
|
|
@@ -29054,7 +29269,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
29054
29269
|
id: loaded.manifest.name,
|
|
29055
29270
|
name: loaded.manifest.name,
|
|
29056
29271
|
manifest: loaded.path,
|
|
29057
|
-
lock:
|
|
29272
|
+
lock: import_node_path51.default.resolve(opts.lockPath),
|
|
29058
29273
|
root,
|
|
29059
29274
|
provider: loaded.manifest.provider,
|
|
29060
29275
|
account: null,
|
|
@@ -29083,7 +29298,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
29083
29298
|
return { snapshot, media };
|
|
29084
29299
|
}
|
|
29085
29300
|
async function buildWorkspaceGallerySnapshot(opts) {
|
|
29086
|
-
const dir =
|
|
29301
|
+
const dir = import_node_path51.default.dirname(import_node_path51.default.resolve(opts.workspacePath));
|
|
29087
29302
|
const media = /* @__PURE__ */ new Map();
|
|
29088
29303
|
const projects = [];
|
|
29089
29304
|
const items = [];
|
|
@@ -29128,11 +29343,11 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
29128
29343
|
id: project2.id,
|
|
29129
29344
|
name: loaded.manifest.name,
|
|
29130
29345
|
manifest: manifestPath,
|
|
29131
|
-
lock:
|
|
29346
|
+
lock: import_node_path51.default.resolve(lockPath),
|
|
29132
29347
|
root: loaded.root,
|
|
29133
29348
|
provider: loaded.manifest.provider,
|
|
29134
29349
|
account: project2.account ?? null,
|
|
29135
|
-
manifestSha256: manifestSha256 ?? sha256(await (0,
|
|
29350
|
+
manifestSha256: manifestSha256 ?? sha256(await (0, import_promises41.readFile)(manifestPath, "utf8")),
|
|
29136
29351
|
historyLimit: historyLimit(loaded.manifest),
|
|
29137
29352
|
entries: Object.keys(lock.entries).length,
|
|
29138
29353
|
items: projectItems.length,
|
|
@@ -29144,8 +29359,8 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
29144
29359
|
id: project2.id,
|
|
29145
29360
|
name: project2.id,
|
|
29146
29361
|
manifest: manifestPath,
|
|
29147
|
-
lock:
|
|
29148
|
-
root:
|
|
29362
|
+
lock: import_node_path51.default.resolve(lockPath),
|
|
29363
|
+
root: import_node_path51.default.dirname(manifestPath),
|
|
29149
29364
|
provider: project2.provider,
|
|
29150
29365
|
account: project2.account ?? null,
|
|
29151
29366
|
manifestSha256: null,
|
|
@@ -29172,7 +29387,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
29172
29387
|
version: 1,
|
|
29173
29388
|
generatedAt: (opts.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
|
|
29174
29389
|
project: null,
|
|
29175
|
-
workspace: { path:
|
|
29390
|
+
workspace: { path: import_node_path51.default.resolve(opts.workspacePath), dir, projects },
|
|
29176
29391
|
filter,
|
|
29177
29392
|
totals: {
|
|
29178
29393
|
entries: projects.reduce((sum, project2) => sum + project2.entries, 0),
|
|
@@ -29376,9 +29591,9 @@ var EDITOR_RELEASE_BASE = "https://github.com/gfargo/pixelkiln/releases/download
|
|
|
29376
29591
|
// src/editor/install.ts
|
|
29377
29592
|
var import_node_crypto11 = require("crypto");
|
|
29378
29593
|
var import_node_fs48 = require("fs");
|
|
29379
|
-
var
|
|
29594
|
+
var import_promises42 = require("fs/promises");
|
|
29380
29595
|
var import_node_os4 = __toESM(require("os"), 1);
|
|
29381
|
-
var
|
|
29596
|
+
var import_node_path52 = __toESM(require("path"), 1);
|
|
29382
29597
|
var EditorInstallError = class extends Error {
|
|
29383
29598
|
constructor(message6, file) {
|
|
29384
29599
|
super(message6);
|
|
@@ -29389,15 +29604,15 @@ var EditorInstallError = class extends Error {
|
|
|
29389
29604
|
};
|
|
29390
29605
|
function editorToolsRoot() {
|
|
29391
29606
|
const override = process.env.PIXELKILN_TOOLS_DIR?.trim();
|
|
29392
|
-
if (override) return
|
|
29393
|
-
if (process.platform === "darwin") return
|
|
29607
|
+
if (override) return import_node_path52.default.resolve(override);
|
|
29608
|
+
if (process.platform === "darwin") return import_node_path52.default.join(import_node_os4.default.homedir(), "Library", "Caches", "pixelkiln", "tools");
|
|
29394
29609
|
if (process.platform === "win32") {
|
|
29395
|
-
return
|
|
29610
|
+
return import_node_path52.default.join(process.env.LOCALAPPDATA ?? import_node_path52.default.join(import_node_os4.default.homedir(), "AppData", "Local"), "pixelkiln", "tools");
|
|
29396
29611
|
}
|
|
29397
|
-
return
|
|
29612
|
+
return import_node_path52.default.join(process.env.XDG_CACHE_HOME ?? import_node_path52.default.join(import_node_os4.default.homedir(), ".cache"), "pixelkiln", "tools");
|
|
29398
29613
|
}
|
|
29399
29614
|
function editorDir(pin = EDITOR_PIN, root = editorToolsRoot()) {
|
|
29400
|
-
return
|
|
29615
|
+
return import_node_path52.default.join(root, "pixelorama", pin.release ?? "unpublished");
|
|
29401
29616
|
}
|
|
29402
29617
|
function editorBaseUrl(pin = EDITOR_PIN) {
|
|
29403
29618
|
const override = process.env.PIXELKILN_EDITOR_URL?.trim();
|
|
@@ -29407,7 +29622,7 @@ function editorBaseUrl(pin = EDITOR_PIN) {
|
|
|
29407
29622
|
}
|
|
29408
29623
|
async function sha256Of(file) {
|
|
29409
29624
|
try {
|
|
29410
|
-
return (0, import_node_crypto11.createHash)("sha256").update(await (0,
|
|
29625
|
+
return (0, import_node_crypto11.createHash)("sha256").update(await (0, import_promises42.readFile)(file)).digest("hex");
|
|
29411
29626
|
} catch {
|
|
29412
29627
|
return null;
|
|
29413
29628
|
}
|
|
@@ -29420,8 +29635,8 @@ async function editorStatus(opts = {}) {
|
|
|
29420
29635
|
let totalBytes = 0;
|
|
29421
29636
|
for (const [name, expected] of Object.entries(pin.files)) {
|
|
29422
29637
|
totalBytes += expected.bytes;
|
|
29423
|
-
const file =
|
|
29424
|
-
const info = (0, import_node_fs48.existsSync)(file) ? await (0,
|
|
29638
|
+
const file = import_node_path52.default.join(dir, name);
|
|
29639
|
+
const info = (0, import_node_fs48.existsSync)(file) ? await (0, import_promises42.stat)(file).catch(() => null) : null;
|
|
29425
29640
|
if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
|
|
29426
29641
|
installedBytes += expected.bytes;
|
|
29427
29642
|
} else {
|
|
@@ -29450,7 +29665,7 @@ async function installEditor(opts = {}) {
|
|
|
29450
29665
|
);
|
|
29451
29666
|
}
|
|
29452
29667
|
if (!baseUrl) throw new EditorInstallError("no download location for the editor build");
|
|
29453
|
-
await (0,
|
|
29668
|
+
await (0, import_promises42.mkdir)(dir, { recursive: true });
|
|
29454
29669
|
const downloaded = [];
|
|
29455
29670
|
const skipped = Object.keys(pin.files).filter((name) => !before.missing.includes(name));
|
|
29456
29671
|
let fetchedBytes = before.installedBytes;
|
|
@@ -29478,13 +29693,13 @@ async function installEditor(opts = {}) {
|
|
|
29478
29693
|
if (digest2 !== expected.sha256) {
|
|
29479
29694
|
throw new EditorInstallError(`${name}: sha256 ${digest2.slice(0, 12)}\u2026 does not match the pinned ${expected.sha256.slice(0, 12)}\u2026`, name);
|
|
29480
29695
|
}
|
|
29481
|
-
const final =
|
|
29696
|
+
const final = import_node_path52.default.join(dir, name);
|
|
29482
29697
|
const tmp = `${final}.${process.pid}.part`;
|
|
29483
29698
|
try {
|
|
29484
|
-
await (0,
|
|
29485
|
-
await (0,
|
|
29699
|
+
await (0, import_promises42.writeFile)(tmp, bytes);
|
|
29700
|
+
await (0, import_promises42.rename)(tmp, final);
|
|
29486
29701
|
} finally {
|
|
29487
|
-
await (0,
|
|
29702
|
+
await (0, import_promises42.rm)(tmp, { force: true });
|
|
29488
29703
|
}
|
|
29489
29704
|
fetchedBytes += bytes.length;
|
|
29490
29705
|
downloaded.push(name);
|
|
@@ -29524,12 +29739,12 @@ var EDITOR_CONTENT_TYPES = {
|
|
|
29524
29739
|
".json": "application/json; charset=utf-8"
|
|
29525
29740
|
};
|
|
29526
29741
|
function editorContentType(name) {
|
|
29527
|
-
return EDITOR_CONTENT_TYPES[
|
|
29742
|
+
return EDITOR_CONTENT_TYPES[import_node_path52.default.extname(name).toLowerCase()] ?? null;
|
|
29528
29743
|
}
|
|
29529
29744
|
|
|
29530
29745
|
// src/gallery/editor.ts
|
|
29531
|
-
var
|
|
29532
|
-
var
|
|
29746
|
+
var import_promises43 = require("fs/promises");
|
|
29747
|
+
var import_node_path53 = __toESM(require("path"), 1);
|
|
29533
29748
|
function editorRoute(release, name = "index.html") {
|
|
29534
29749
|
return `/editor/${encodeURIComponent(release)}/${encodeURIComponent(name)}`;
|
|
29535
29750
|
}
|
|
@@ -29602,7 +29817,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
29602
29817
|
if (!status.installed) return null;
|
|
29603
29818
|
let bytes;
|
|
29604
29819
|
try {
|
|
29605
|
-
bytes = await (0,
|
|
29820
|
+
bytes = await (0, import_promises43.readFile)(import_node_path53.default.join(dir, name));
|
|
29606
29821
|
} catch {
|
|
29607
29822
|
verified = null;
|
|
29608
29823
|
return null;
|
|
@@ -29619,7 +29834,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
29619
29834
|
// src/gallery/server.ts
|
|
29620
29835
|
var import_node_crypto12 = require("crypto");
|
|
29621
29836
|
var import_node_http2 = require("http");
|
|
29622
|
-
var
|
|
29837
|
+
var import_promises44 = require("fs/promises");
|
|
29623
29838
|
var MAX_EDIT_BYTES = 48 * 1024 * 1024;
|
|
29624
29839
|
var EDITOR_CSP = [
|
|
29625
29840
|
"default-src 'self'",
|
|
@@ -29800,7 +30015,7 @@ async function serveGallery(opts) {
|
|
|
29800
30015
|
const asset = reviewAssets.get(jobId)?.get(url2.pathname);
|
|
29801
30016
|
if (!asset) return fail(404, "no such review asset");
|
|
29802
30017
|
try {
|
|
29803
|
-
const bytes = await (0,
|
|
30018
|
+
const bytes = await (0, import_promises44.readFile)(asset.path);
|
|
29804
30019
|
res.writeHead(200, {
|
|
29805
30020
|
"Content-Type": asset.contentType,
|
|
29806
30021
|
"Cache-Control": "no-store",
|
|
@@ -29883,7 +30098,7 @@ async function serveGallery(opts) {
|
|
|
29883
30098
|
if (!asset) return fail(404, "no such gallery media");
|
|
29884
30099
|
let bytes;
|
|
29885
30100
|
try {
|
|
29886
|
-
bytes = await (0,
|
|
30101
|
+
bytes = await (0, import_promises44.readFile)(asset.path);
|
|
29887
30102
|
} catch {
|
|
29888
30103
|
return fail(404, "gallery media is no longer on disk; refresh the page");
|
|
29889
30104
|
}
|
|
@@ -30294,9 +30509,9 @@ function createGenerateHandlers(opts) {
|
|
|
30294
30509
|
}
|
|
30295
30510
|
|
|
30296
30511
|
// src/pipeline/salvage.ts
|
|
30297
|
-
var
|
|
30512
|
+
var import_promises45 = require("fs/promises");
|
|
30298
30513
|
var import_node_fs49 = require("fs");
|
|
30299
|
-
var
|
|
30514
|
+
var import_node_path54 = __toESM(require("path"), 1);
|
|
30300
30515
|
function providerClaimId(provider, objectId) {
|
|
30301
30516
|
return `${encodeURIComponent(provider)}:${encodeURIComponent(objectId)}`;
|
|
30302
30517
|
}
|
|
@@ -30306,7 +30521,7 @@ async function loadClaims(lockPaths, opts = {}) {
|
|
|
30306
30521
|
if (!(0, import_node_fs49.existsSync)(p)) throw new Error(`Claim lockfile not found: ${p}`);
|
|
30307
30522
|
let parsed;
|
|
30308
30523
|
try {
|
|
30309
|
-
parsed = parseLock(JSON.parse(await (0,
|
|
30524
|
+
parsed = parseLock(JSON.parse(await (0, import_promises45.readFile)(p, "utf8")));
|
|
30310
30525
|
} catch {
|
|
30311
30526
|
throw new Error(`Claim lockfile is malformed: ${p}`);
|
|
30312
30527
|
}
|
|
@@ -30410,20 +30625,20 @@ function matchOrphanStyle(prompt, manifest) {
|
|
|
30410
30625
|
return matchStyleByPattern(prompt, manifest);
|
|
30411
30626
|
}
|
|
30412
30627
|
async function loadSiblingManifests(ownManifestPath, workspaceManifestPaths, claimPaths) {
|
|
30413
|
-
const own =
|
|
30628
|
+
const own = import_node_path54.default.resolve(ownManifestPath);
|
|
30414
30629
|
const siblingManifestPaths = [
|
|
30415
30630
|
.../* @__PURE__ */ new Set([
|
|
30416
30631
|
...workspaceManifestPaths,
|
|
30417
|
-
...claimPaths.map((c) =>
|
|
30632
|
+
...claimPaths.map((c) => import_node_path54.default.join(import_node_path54.default.dirname(import_node_path54.default.resolve(c)), "pixelkiln.manifest.json"))
|
|
30418
30633
|
])
|
|
30419
30634
|
];
|
|
30420
30635
|
const siblings = [];
|
|
30421
30636
|
for (const siblingManifestPath of siblingManifestPaths) {
|
|
30422
|
-
if (
|
|
30637
|
+
if (import_node_path54.default.resolve(siblingManifestPath) === own) continue;
|
|
30423
30638
|
if (!(0, import_node_fs49.existsSync)(siblingManifestPath)) continue;
|
|
30424
30639
|
try {
|
|
30425
30640
|
const { manifest } = await loadManifest(siblingManifestPath);
|
|
30426
|
-
siblings.push({ label:
|
|
30641
|
+
siblings.push({ label: import_node_path54.default.basename(import_node_path54.default.dirname(siblingManifestPath)), manifest });
|
|
30427
30642
|
} catch {
|
|
30428
30643
|
}
|
|
30429
30644
|
}
|
|
@@ -30543,8 +30758,8 @@ async function applyTags(provider, decisions, existing, opts = {}) {
|
|
|
30543
30758
|
}
|
|
30544
30759
|
|
|
30545
30760
|
// src/pick/salvage-server.ts
|
|
30546
|
-
var
|
|
30547
|
-
var
|
|
30761
|
+
var import_promises46 = require("fs/promises");
|
|
30762
|
+
var import_node_path55 = __toESM(require("path"), 1);
|
|
30548
30763
|
|
|
30549
30764
|
// src/pick/salvage-sheet.ts
|
|
30550
30765
|
var escapeHtml3 = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
@@ -30710,7 +30925,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
30710
30925
|
});
|
|
30711
30926
|
const html = renderSalvageSheet(orphans, {
|
|
30712
30927
|
styleId: ctx.styleId,
|
|
30713
|
-
importDir:
|
|
30928
|
+
importDir: import_node_path55.default.relative(process.cwd(), ctx.importDir) || "."
|
|
30714
30929
|
});
|
|
30715
30930
|
const byId = new Map(orphans.map((o) => [o.id, o]));
|
|
30716
30931
|
const existingTags = new Map(orphans.map((o) => [o.id, o.tags]));
|
|
@@ -30766,10 +30981,10 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
30766
30981
|
if (!buf.subarray(0, 8).equals(PNG_SIGNATURE2)) throw new Error("not a PNG");
|
|
30767
30982
|
decodePng(buf);
|
|
30768
30983
|
const assetId = idFromPrompt(orphan.prompt, taken);
|
|
30769
|
-
const rel =
|
|
30770
|
-
const outFile =
|
|
30771
|
-
await (0,
|
|
30772
|
-
await (0,
|
|
30984
|
+
const rel = import_node_path55.default.join("_salvaged", `${assetId}.png`);
|
|
30985
|
+
const outFile = import_node_path55.default.resolve(ctx.importDir, rel);
|
|
30986
|
+
await (0, import_promises46.mkdir)(import_node_path55.default.dirname(outFile), { recursive: true });
|
|
30987
|
+
await (0, import_promises46.writeFile)(outFile, buf);
|
|
30773
30988
|
ctx.manifest.assets[assetId] = {
|
|
30774
30989
|
prompt: orphan.prompt,
|
|
30775
30990
|
promptByStyle: {},
|
|
@@ -30801,7 +31016,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
30801
31016
|
sourceUrl: durableSource,
|
|
30802
31017
|
sourceUrls: durableSource ? [{ url: durableSource }] : [],
|
|
30803
31018
|
outputs: [{
|
|
30804
|
-
path: portableOutputPath(outFile,
|
|
31019
|
+
path: portableOutputPath(outFile, import_node_path55.default.dirname(ctx.manifestPath)),
|
|
30805
31020
|
sha256: sha256(buf)
|
|
30806
31021
|
}],
|
|
30807
31022
|
submittedAt: orphan.createdAt,
|
|
@@ -30825,9 +31040,9 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
30825
31040
|
}
|
|
30826
31041
|
}
|
|
30827
31042
|
await applyTags(provider, decisions, existingTags, { onProgress: log, characters: characterMembers });
|
|
30828
|
-
const raw = JSON.parse(await (0,
|
|
31043
|
+
const raw = JSON.parse(await (0, import_promises46.readFile)(ctx.manifestPath, "utf8"));
|
|
30829
31044
|
for (const id of importedAssetIds) raw.assets[id] = ctx.manifest.assets[id];
|
|
30830
|
-
await (0,
|
|
31045
|
+
await (0, import_promises46.writeFile)(ctx.manifestPath, JSON.stringify(raw, null, 2) + "\n");
|
|
30831
31046
|
await saveLock(ctx.lockPath, ctx.lock);
|
|
30832
31047
|
if (characterAssetIds.length) result.characterAssetIds = characterAssetIds;
|
|
30833
31048
|
return result;
|