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/cli.js
CHANGED
|
@@ -244,6 +244,7 @@ var COMMANDS = [
|
|
|
244
244
|
"estimate-skeleton",
|
|
245
245
|
"anchors",
|
|
246
246
|
"redraw",
|
|
247
|
+
"layer",
|
|
247
248
|
"skeleton-preview",
|
|
248
249
|
"unzoom",
|
|
249
250
|
"pixelate",
|
|
@@ -276,6 +277,7 @@ var TALK_SUBCOMMANDS = ["visemes", "gif", "plan"];
|
|
|
276
277
|
var ASSET_SUBCOMMANDS = ["canvas", "mirror", "import", "save", "expand", "review", "export"];
|
|
277
278
|
var UI_SUBCOMMANDS = ["show", "split", "states", "nine-slice", "pull"];
|
|
278
279
|
var PARALLAX_SUBCOMMANDS = ["preview", "export"];
|
|
280
|
+
var LAYER_SUBCOMMANDS = ["preview"];
|
|
279
281
|
function parseArgs(argv) {
|
|
280
282
|
const [command = "help"] = argv;
|
|
281
283
|
if (!COMMANDS.includes(command)) {
|
|
@@ -378,6 +380,18 @@ function parseArgs(argv) {
|
|
|
378
380
|
target = rest[0]?.startsWith("-") ? void 0 : rest[0];
|
|
379
381
|
if (target === void 0) throw new UsageError("redraw needs a layer's asset id: pixelkiln redraw <asset> --frame <name>");
|
|
380
382
|
rest = rest.slice(1);
|
|
383
|
+
} else if (command === "layer") {
|
|
384
|
+
subcommand = rest[0];
|
|
385
|
+
if (subcommand === void 0 || subcommand.startsWith("-")) {
|
|
386
|
+
throw new UsageError(`layer needs a subcommand: ${LAYER_SUBCOMMANDS.join(", ")}`);
|
|
387
|
+
}
|
|
388
|
+
if (!LAYER_SUBCOMMANDS.includes(subcommand)) {
|
|
389
|
+
throw new UsageError(`Unknown layer subcommand "${subcommand}". Known: ${LAYER_SUBCOMMANDS.join(", ")}`);
|
|
390
|
+
}
|
|
391
|
+
rest = rest.slice(1);
|
|
392
|
+
target = rest[0]?.startsWith("-") ? void 0 : rest[0];
|
|
393
|
+
if (target === void 0) throw new UsageError("layer preview needs a layer's asset id: pixelkiln layer preview <asset>");
|
|
394
|
+
rest = rest.slice(1);
|
|
381
395
|
} else if (command === "skeleton-preview") {
|
|
382
396
|
target = rest[0]?.startsWith("-") ? void 0 : rest[0];
|
|
383
397
|
if (target === void 0) {
|
|
@@ -746,6 +760,11 @@ Commands
|
|
|
746
760
|
beside them. Direct and un-budgeted, 10 to 25 generations by sheet
|
|
747
761
|
size. The new frames replace the old in the lockfile. Without
|
|
748
762
|
--frame it lists the names; --dry-run prices the call.
|
|
763
|
+
layer preview <layer> [--style <id>]
|
|
764
|
+
Free and offline: build a paperdoll layer's sheet, keyed sheet and
|
|
765
|
+
mask as gen would send them, write them (and each frame's own) to
|
|
766
|
+
.pixelkiln/layers/<style>/<layer>/preview/, and print each frame's
|
|
767
|
+
neck row and the inpaint's price. Nothing is submitted.
|
|
749
768
|
skeleton-preview <keypoints.json | asset> [--from <image>] [--out <file>]
|
|
750
769
|
Draw every pose of a keypoints file over its source image as one
|
|
751
770
|
PNG, locally and free. Given an animate-skeleton asset id, reads
|
|
@@ -1473,10 +1492,10 @@ function normalizeHex(value) {
|
|
|
1473
1492
|
function sha256(data) {
|
|
1474
1493
|
return createHash("sha256").update(data).digest("hex");
|
|
1475
1494
|
}
|
|
1476
|
-
async function sha256File(
|
|
1495
|
+
async function sha256File(path81) {
|
|
1477
1496
|
return new Promise((resolve, reject) => {
|
|
1478
1497
|
const hash = createHash("sha256");
|
|
1479
|
-
const stream = createReadStream(
|
|
1498
|
+
const stream = createReadStream(path81);
|
|
1480
1499
|
stream.on("data", (chunk2) => hash.update(chunk2));
|
|
1481
1500
|
stream.on("error", reject);
|
|
1482
1501
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -1619,6 +1638,8 @@ function specHash(spec, styleImageHashes, providerOptionIdentity = spec.provider
|
|
|
1619
1638
|
keyed: spec.character.layer.keyed?.sha256,
|
|
1620
1639
|
skin: spec.character.layer.skin?.map(normalizeHex),
|
|
1621
1640
|
key: spec.character.layer.key ? normalizeHex(spec.character.layer.key) : void 0,
|
|
1641
|
+
// Omitted unless set so a layer made before it existed keeps its identity.
|
|
1642
|
+
cover: spec.character.layer.cover,
|
|
1622
1643
|
clean: spec.character.layer.clean,
|
|
1623
1644
|
columns: spec.character.layer.columns,
|
|
1624
1645
|
// Omitted at their defaults so a layer made before these existed keeps its identity.
|
|
@@ -2202,6 +2223,13 @@ var CharacterLayerSchema = z.object({
|
|
|
2202
2223
|
skin: z.array(HexColorSchema).min(1).max(64).optional(),
|
|
2203
2224
|
/** The stand-in colour skin is painted before the provider sees it. Default cyan. */
|
|
2204
2225
|
key: HexColorSchema.optional(),
|
|
2226
|
+
/**
|
|
2227
|
+
* Key every opaque pixel inside the mask, whatever its colour, not only
|
|
2228
|
+
* skin. For a base that wears underwear (or anything else it cannot be
|
|
2229
|
+
* drawn without): what it wears is body to dress over, so the outfit
|
|
2230
|
+
* covers it instead of being drawn around it. Default false.
|
|
2231
|
+
*/
|
|
2232
|
+
cover: z.boolean().optional(),
|
|
2205
2233
|
/**
|
|
2206
2234
|
* Remove animation ghosts from the loops before dressing them, judged
|
|
2207
2235
|
* against the stills among `of` (bases and states). Default true; it has
|
|
@@ -2242,7 +2270,7 @@ var CharacterLayerSchema = z.object({
|
|
|
2242
2270
|
attach: CharacterAttachSchema.optional()
|
|
2243
2271
|
}).strict().superRefine((layer, context) => {
|
|
2244
2272
|
if (!layer.attach) return;
|
|
2245
|
-
for (const field of ["mask", "keyed", "skin", "key", "clean", "region"]) {
|
|
2273
|
+
for (const field of ["mask", "keyed", "skin", "key", "cover", "clean", "region"]) {
|
|
2246
2274
|
if (layer[field] !== void 0) {
|
|
2247
2275
|
context.addIssue({
|
|
2248
2276
|
code: z.ZodIssueCode.custom,
|
|
@@ -3246,7 +3274,7 @@ var AssetDeriveSchema = z.object({
|
|
|
3246
3274
|
/** 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. */
|
|
3247
3275
|
tolerance: z.number().min(0).max(442).optional()
|
|
3248
3276
|
}).strict().superRefine((derive, context) => {
|
|
3249
|
-
const issue = (message6,
|
|
3277
|
+
const issue = (message6, path81) => context.addIssue({ code: z.ZodIssueCode.custom, message: message6, path: [path81] });
|
|
3250
3278
|
if (Boolean(derive.from) === Boolean(derive.file)) {
|
|
3251
3279
|
issue("name exactly one source: `from` (an asset in this style) or `file` (a committed PNG)", derive.from ? "file" : "from");
|
|
3252
3280
|
}
|
|
@@ -4574,8 +4602,23 @@ function hsv(r, g, b) {
|
|
|
4574
4602
|
}
|
|
4575
4603
|
return { h, s: max === 0 ? 0 : delta / max, v: max / 255 };
|
|
4576
4604
|
}
|
|
4605
|
+
function unpackSheet(sheet, cells) {
|
|
4606
|
+
const image = decodePng(sheet);
|
|
4607
|
+
return cells.map((cell, index) => {
|
|
4608
|
+
if (cell.x < 0 || cell.y < 0 || cell.x + cell.width > image.width || cell.y + cell.height > image.height) {
|
|
4609
|
+
throw new Error(`cell ${index} does not fit inside the ${image.width}x${image.height} sheet`);
|
|
4610
|
+
}
|
|
4611
|
+
const out = Buffer.alloc(cell.width * cell.height * 4);
|
|
4612
|
+
for (let y = 0; y < cell.height; y++) {
|
|
4613
|
+
const from = at(image, cell.x, cell.y + y);
|
|
4614
|
+
image.pixels.copy(out, y * cell.width * 4, from, from + cell.width * 4);
|
|
4615
|
+
}
|
|
4616
|
+
return encodeRgbaPng(cell.width, cell.height, out);
|
|
4617
|
+
});
|
|
4618
|
+
}
|
|
4577
4619
|
var DEFAULT_KEY = "#00ffff";
|
|
4578
4620
|
var KEY_SATURATION = 0.85;
|
|
4621
|
+
var COVER_FLOOR = 96;
|
|
4579
4622
|
function keySkin(png, options = {}) {
|
|
4580
4623
|
const image = decodePng(png);
|
|
4581
4624
|
const key3 = parseHex(options.key ?? DEFAULT_KEY);
|
|
@@ -4628,23 +4671,103 @@ function neckRow(image, cell = whole(image)) {
|
|
|
4628
4671
|
}
|
|
4629
4672
|
return best === null ? null : cell.y + best;
|
|
4630
4673
|
}
|
|
4631
|
-
function
|
|
4674
|
+
function longestRun(image, cell, y) {
|
|
4675
|
+
let best = null;
|
|
4676
|
+
let start = -1;
|
|
4677
|
+
for (let x = 0; x <= cell.width; x++) {
|
|
4678
|
+
const on = x < cell.width && opaque(image, cell.x + x, cell.y + y);
|
|
4679
|
+
if (on && start < 0) start = x;
|
|
4680
|
+
if (!on && start >= 0) {
|
|
4681
|
+
if (!best || x - 1 - start > best[1] - best[0]) best = [start, x - 1];
|
|
4682
|
+
start = -1;
|
|
4683
|
+
}
|
|
4684
|
+
}
|
|
4685
|
+
return best;
|
|
4686
|
+
}
|
|
4687
|
+
var median = (values) => {
|
|
4688
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
4689
|
+
return sorted[Math.floor((sorted.length - 1) / 2)];
|
|
4690
|
+
};
|
|
4691
|
+
function layerMask(sheet, cells, region = "body") {
|
|
4632
4692
|
const image = decodePng(sheet);
|
|
4633
4693
|
const out = Buffer.alloc(image.width * image.height * 4);
|
|
4634
4694
|
for (let i = 3; i < out.length; i += 4) out[i] = 255;
|
|
4635
|
-
|
|
4695
|
+
const all = cells ?? [whole(image)];
|
|
4696
|
+
const first = all.map((cell) => {
|
|
4697
|
+
let top = -1;
|
|
4698
|
+
let bottom = -1;
|
|
4699
|
+
for (let y = 0; y < cell.height && top < 0; y++) if (longestRun(image, cell, y)) top = y;
|
|
4700
|
+
for (let y = cell.height - 1; y >= 0 && bottom < 0; y--) if (longestRun(image, cell, y)) bottom = y;
|
|
4701
|
+
if (top < 0) return null;
|
|
4636
4702
|
const neck = neckRow(image, cell);
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4703
|
+
return { top, bottom, detected: neck === null ? null : neck - cell.y };
|
|
4704
|
+
});
|
|
4705
|
+
const seen = first.filter((frame) => frame !== null);
|
|
4706
|
+
const offsets = seen.filter((frame) => frame.detected !== null).map((frame) => frame.detected - frame.top);
|
|
4707
|
+
if (!offsets.length) return { png: encodeRgbaPng(image.width, image.height, out), necks: all.map(() => null) };
|
|
4708
|
+
const drop = median(offsets);
|
|
4709
|
+
const heads = seen.map((frame) => {
|
|
4710
|
+
const cell = all[first.indexOf(frame)];
|
|
4711
|
+
const run = longestRun(image, cell, Math.min(frame.bottom, frame.top + Math.floor(drop / 2)));
|
|
4712
|
+
return run ? run[1] - run[0] + 1 : 1;
|
|
4713
|
+
});
|
|
4714
|
+
const wide = Math.max(1, Math.ceil(median(heads) / 2));
|
|
4715
|
+
const necks = all.map((cell, index) => {
|
|
4716
|
+
const frame = first[index];
|
|
4717
|
+
if (!frame) return null;
|
|
4718
|
+
let head = frame.top;
|
|
4719
|
+
for (let y = frame.top; y <= frame.bottom; y++) {
|
|
4720
|
+
const run = longestRun(image, cell, y);
|
|
4721
|
+
if (run && run[1] - run[0] + 1 >= wide) {
|
|
4722
|
+
head = y;
|
|
4723
|
+
break;
|
|
4724
|
+
}
|
|
4725
|
+
}
|
|
4726
|
+
const row = Math.min(head + drop, frame.bottom);
|
|
4727
|
+
const slack = Math.max(2, Math.round((frame.bottom - frame.top + 1) * 0.06));
|
|
4728
|
+
const corrected = frame.detected === null || Math.abs(frame.detected - row) > slack;
|
|
4729
|
+
const from = region === "head" ? 0 : row + 1;
|
|
4730
|
+
const to = region === "head" ? row + 1 : cell.height;
|
|
4640
4731
|
for (let y = from; y < to; y++) {
|
|
4641
|
-
for (let x =
|
|
4642
|
-
if (region === "body" && !opaque(image, x, y)) continue;
|
|
4643
|
-
out.fill(255, at(image, x, y), at(image, x, y) + 3);
|
|
4732
|
+
for (let x = 0; x < cell.width; x++) {
|
|
4733
|
+
if (region === "body" && !opaque(image, cell.x + x, cell.y + y)) continue;
|
|
4734
|
+
out.fill(255, at(image, cell.x + x, cell.y + y), at(image, cell.x + x, cell.y + y) + 3);
|
|
4735
|
+
}
|
|
4736
|
+
}
|
|
4737
|
+
if (region === "body") {
|
|
4738
|
+
const seed = longestRun(image, cell, head);
|
|
4739
|
+
const inHead = new Uint8Array(cell.width * (row + 1));
|
|
4740
|
+
const queue = [];
|
|
4741
|
+
for (let x = seed[0]; x <= seed[1]; x++) {
|
|
4742
|
+
inHead[head * cell.width + x] = 1;
|
|
4743
|
+
queue.push([x, head]);
|
|
4744
|
+
}
|
|
4745
|
+
let left = seed[0];
|
|
4746
|
+
let right = seed[1];
|
|
4747
|
+
while (queue.length) {
|
|
4748
|
+
const [x, y] = queue.pop();
|
|
4749
|
+
left = Math.min(left, x);
|
|
4750
|
+
right = Math.max(right, x);
|
|
4751
|
+
for (const [dx, dy] of STEPS) {
|
|
4752
|
+
const nx = x + dx;
|
|
4753
|
+
const ny = y + dy;
|
|
4754
|
+
if (nx < 0 || nx >= cell.width || ny < 0 || ny > row) continue;
|
|
4755
|
+
if (inHead[ny * cell.width + nx] || !opaque(image, cell.x + nx, cell.y + ny)) continue;
|
|
4756
|
+
inHead[ny * cell.width + nx] = 1;
|
|
4757
|
+
queue.push([nx, ny]);
|
|
4758
|
+
}
|
|
4759
|
+
}
|
|
4760
|
+
for (let y = 0; y <= row; y++) {
|
|
4761
|
+
for (let x = 0; x < cell.width; x++) {
|
|
4762
|
+
if (x >= left - 1 && x <= right + 1) continue;
|
|
4763
|
+
if (!opaque(image, cell.x + x, cell.y + y)) continue;
|
|
4764
|
+
out.fill(255, at(image, cell.x + x, cell.y + y), at(image, cell.x + x, cell.y + y) + 3);
|
|
4765
|
+
}
|
|
4644
4766
|
}
|
|
4645
4767
|
}
|
|
4646
|
-
|
|
4647
|
-
|
|
4768
|
+
return { row, head, detected: frame.detected, corrected };
|
|
4769
|
+
});
|
|
4770
|
+
return { png: encodeRgbaPng(image.width, image.height, out), necks };
|
|
4648
4771
|
}
|
|
4649
4772
|
function extractLayer(result, keyed, mask, options = {}) {
|
|
4650
4773
|
const out = decodePng(result);
|
|
@@ -4677,10 +4800,10 @@ function despeckle(png, options) {
|
|
|
4677
4800
|
for (const still of options.reference) {
|
|
4678
4801
|
const { pixels } = decodePng(still);
|
|
4679
4802
|
for (let i = 0; i < pixels.length; i += 4) {
|
|
4680
|
-
if (pixels[i + 3] === 0
|
|
4803
|
+
if (pixels[i + 3] === 0) continue;
|
|
4681
4804
|
const rgb = pixels[i] << 16 | pixels[i + 1] << 8 | pixels[i + 2];
|
|
4682
4805
|
palette.set(rgb, (palette.get(rgb) ?? 0) + 1);
|
|
4683
|
-
total++;
|
|
4806
|
+
if (!outline(pixels, i)) total++;
|
|
4684
4807
|
}
|
|
4685
4808
|
}
|
|
4686
4809
|
if (!total) throw new Error("the reference stills have no opaque pixels that are not outline");
|
|
@@ -4740,7 +4863,7 @@ function despeckle(png, options) {
|
|
|
4740
4863
|
const strange = run.filter(([x, y]) => foreign(at(image, x, y))).length / run.length > 0.5;
|
|
4741
4864
|
let debris;
|
|
4742
4865
|
const exposed = run.some(([x, y]) => STEPS.some(([dx, dy]) => open2(x + dx, y + dy)));
|
|
4743
|
-
if (strange &&
|
|
4866
|
+
if (strange && run.length > limb) {
|
|
4744
4867
|
debris = false;
|
|
4745
4868
|
limbs.add(index);
|
|
4746
4869
|
} else if (exposed) {
|
|
@@ -4775,6 +4898,7 @@ function despeckle(png, options) {
|
|
|
4775
4898
|
if (src[at(image, x, y) + 3] > 0 && out[at(image, x, y) + 3] === 0) frontier.push([x, y]);
|
|
4776
4899
|
}
|
|
4777
4900
|
}
|
|
4901
|
+
const seeds = frontier.length;
|
|
4778
4902
|
for (let n = 0; n < frontier.length; n++) {
|
|
4779
4903
|
const [fx, fy] = frontier[n];
|
|
4780
4904
|
for (let dy = -1; dy <= 1; dy++) {
|
|
@@ -4798,6 +4922,31 @@ function despeckle(png, options) {
|
|
|
4798
4922
|
}
|
|
4799
4923
|
}
|
|
4800
4924
|
}
|
|
4925
|
+
const chained = new Set(frontier.slice(seeds).map(([x, y]) => local(x, y)));
|
|
4926
|
+
const visited = /* @__PURE__ */ new Set();
|
|
4927
|
+
for (const [sx, sy] of frontier.slice(seeds)) {
|
|
4928
|
+
if (visited.has(local(sx, sy))) continue;
|
|
4929
|
+
const group = [[sx, sy]];
|
|
4930
|
+
visited.add(local(sx, sy));
|
|
4931
|
+
for (let n = 0; n < group.length; n++) {
|
|
4932
|
+
const [gx, gy] = group[n];
|
|
4933
|
+
for (let dy = -1; dy <= 1; dy++) {
|
|
4934
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
4935
|
+
const x = gx + dx;
|
|
4936
|
+
const y = gy + dy;
|
|
4937
|
+
if (!inside(cell, x, y) || visited.has(local(x, y)) || !chained.has(local(x, y))) continue;
|
|
4938
|
+
visited.add(local(x, y));
|
|
4939
|
+
group.push([x, y]);
|
|
4940
|
+
}
|
|
4941
|
+
}
|
|
4942
|
+
}
|
|
4943
|
+
if (group.length <= limb) continue;
|
|
4944
|
+
for (const [x, y] of group) {
|
|
4945
|
+
const i = at(image, x, y);
|
|
4946
|
+
src.copy(out, i, i, i + 4);
|
|
4947
|
+
removed--;
|
|
4948
|
+
}
|
|
4949
|
+
}
|
|
4801
4950
|
}
|
|
4802
4951
|
return { png: encodeRgbaPng(image.width, image.height, out), removed };
|
|
4803
4952
|
}
|
|
@@ -4913,23 +5062,55 @@ function buildLayerSheet(sources, options) {
|
|
|
4913
5062
|
}
|
|
4914
5063
|
return png;
|
|
4915
5064
|
};
|
|
4916
|
-
const
|
|
5065
|
+
const computed = options.mask ? void 0 : layerMask(sheetPng, frames.map((frame) => frame.cell), options.region);
|
|
5066
|
+
const mask = options.mask ? sized("mask", options.mask) : computed.png;
|
|
5067
|
+
const keyed = options.keyed ? void 0 : keyInsideMask(sheetPng, mask, { key: options.key, skin: options.skin, cover: options.cover });
|
|
4917
5068
|
return {
|
|
4918
5069
|
sheet: sheetPng,
|
|
4919
|
-
keyed: options.keyed ? sized("keyed sheet", options.keyed) :
|
|
5070
|
+
keyed: options.keyed ? sized("keyed sheet", options.keyed) : keyed.png,
|
|
4920
5071
|
mask,
|
|
4921
5072
|
frames,
|
|
4922
|
-
cleaned
|
|
5073
|
+
cleaned,
|
|
5074
|
+
...computed ? { necks: computed.necks } : {},
|
|
5075
|
+
...keyed ? { closed: keyed.closed } : {}
|
|
4923
5076
|
};
|
|
4924
5077
|
}
|
|
4925
5078
|
function keyInsideMask(sheet, mask, options) {
|
|
4926
5079
|
const original = decodePng(sheet);
|
|
4927
|
-
const keyed = decodePng(keySkin(sheet, options));
|
|
4928
5080
|
const allowed = decodePng(mask);
|
|
5081
|
+
const key3 = parseHex(options.key ?? DEFAULT_KEY);
|
|
5082
|
+
const keyed = options.cover ? { ...original, pixels: Buffer.from(original.pixels) } : decodePng(keySkin(sheet, options));
|
|
5083
|
+
const paint = (i, lift) => {
|
|
5084
|
+
const brightest = Math.max(original.pixels[i], original.pixels[i + 1], original.pixels[i + 2]);
|
|
5085
|
+
const value = lift ? COVER_FLOOR + Math.floor(brightest * (255 - COVER_FLOOR) / 255) : brightest;
|
|
5086
|
+
const tint = (channel) => Math.floor(value * (1 - KEY_SATURATION + KEY_SATURATION * channel / 255));
|
|
5087
|
+
keyed.pixels[i] = tint(key3.r);
|
|
5088
|
+
keyed.pixels[i + 1] = tint(key3.g);
|
|
5089
|
+
keyed.pixels[i + 2] = tint(key3.b);
|
|
5090
|
+
};
|
|
4929
5091
|
for (let i = 0; i < keyed.pixels.length; i += 4) {
|
|
4930
5092
|
if (allowed.pixels[i] !== 255) original.pixels.copy(keyed.pixels, i, i, i + 4);
|
|
5093
|
+
else if (options.cover && original.pixels[i + 3]) paint(i, true);
|
|
5094
|
+
}
|
|
5095
|
+
let closed = 0;
|
|
5096
|
+
if (!options.cover && !options.skin) {
|
|
5097
|
+
const changed = (i) => original.pixels[i + 3] > 0 && original.pixels.compare(keyed.pixels, i, i + 3, i, i + 3) !== 0;
|
|
5098
|
+
const holes = [];
|
|
5099
|
+
for (let y = 0; y < keyed.height; y++) {
|
|
5100
|
+
for (let x = 0; x < keyed.width; x++) {
|
|
5101
|
+
const i = (y * keyed.width + x) * 4;
|
|
5102
|
+
if (allowed.pixels[i] !== 255 || !original.pixels[i + 3] || changed(i)) continue;
|
|
5103
|
+
const near = (dir) => [1, 2, 3].some((k) => {
|
|
5104
|
+
const nx = x + dir * k;
|
|
5105
|
+
return nx >= 0 && nx < keyed.width && allowed.pixels[i + dir * k * 4] === 255 && changed(i + dir * k * 4);
|
|
5106
|
+
});
|
|
5107
|
+
if (near(-1) && near(1)) holes.push(i);
|
|
5108
|
+
}
|
|
5109
|
+
}
|
|
5110
|
+
for (const i of holes) paint(i, false);
|
|
5111
|
+
closed = holes.length;
|
|
4931
5112
|
}
|
|
4932
|
-
return encodeRgbaPng(keyed.width, keyed.height, keyed.pixels);
|
|
5113
|
+
return { png: encodeRgbaPng(keyed.width, keyed.height, keyed.pixels), closed };
|
|
4933
5114
|
}
|
|
4934
5115
|
var SPECK = 8;
|
|
4935
5116
|
var BLEED = 20;
|
|
@@ -5214,10 +5395,13 @@ function applyPostprocess(bytes, mediaType, record, reference = [], role) {
|
|
|
5214
5395
|
if (mediaType !== MediaType.PNG || !record?.palette && !record?.despeckle && !record?.offset) return { bytes, changed: false };
|
|
5215
5396
|
let out = bytes;
|
|
5216
5397
|
let removed = 0;
|
|
5398
|
+
let opaque2 = 0;
|
|
5217
5399
|
if (record.despeckle) {
|
|
5218
5400
|
if (!reference.length) throw new Error(`cleaning needs the rotations of ${record.despeckle.of}, and none were given`);
|
|
5219
5401
|
const cleaned = despeckle(out, { reference });
|
|
5220
5402
|
if (cleaned.removed) {
|
|
5403
|
+
const { pixels } = decodePng(out);
|
|
5404
|
+
for (let i = 3; i < pixels.length; i += 4) if (pixels[i] > 0) opaque2++;
|
|
5221
5405
|
out = cleaned.png;
|
|
5222
5406
|
removed = cleaned.removed;
|
|
5223
5407
|
}
|
|
@@ -5241,8 +5425,9 @@ function applyPostprocess(bytes, mediaType, record, reference = [], role) {
|
|
|
5241
5425
|
}
|
|
5242
5426
|
}
|
|
5243
5427
|
if (!removed && !snapped && !moved) return { bytes, changed: false };
|
|
5244
|
-
return { bytes: out, changed: true, ...removed ? { removed } : {}, ...snapped ? { snapped } : {}, ...moved ? { moved } : {} };
|
|
5428
|
+
return { bytes: out, changed: true, ...removed ? { removed, opaque: opaque2 } : {}, ...snapped ? { snapped } : {}, ...moved ? { moved } : {} };
|
|
5245
5429
|
}
|
|
5430
|
+
var CLEAN_DAMAGE_SHARE = 0.03;
|
|
5246
5431
|
|
|
5247
5432
|
// src/pipeline/mirror.ts
|
|
5248
5433
|
function mirrorSourceHash(source) {
|
|
@@ -7592,10 +7777,15 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
7592
7777
|
} else if (spec.mirror && entry.status === "downloaded" && entry.outputs.some((_output, index) => !existsSync7(currentEntryOutputPath(entry, spec, index)))) {
|
|
7593
7778
|
state = "stale";
|
|
7594
7779
|
reason = "mirror output missing on disk; flip it again (no generation cost)";
|
|
7595
|
-
} else if (
|
|
7780
|
+
} else if (
|
|
7781
|
+
// A mirror carries its source's character shape, but it is a flip of
|
|
7782
|
+
// the source's files: whether it is current is the check above, never
|
|
7783
|
+
// the outfit or layer rule its source answers to (#418).
|
|
7784
|
+
!spec.mirror && spec.character?.kind === "outfit" && entry.outfit?.sourceSha256 !== mirrorSourceHash(lock.entries[lockKey(spec.styleId, spec.character.parentAssetId)] ?? { outputs: [] })
|
|
7785
|
+
) {
|
|
7596
7786
|
state = "stale";
|
|
7597
7787
|
reason = `outfit source ${spec.character.parentAssetId} changed; re-clothe the loop again`;
|
|
7598
|
-
} else if (spec.character?.kind === "layer" && changedLayerSource(spec, entry, lock)) {
|
|
7788
|
+
} else if (!spec.mirror && spec.character?.kind === "layer" && changedLayerSource(spec, entry, lock)) {
|
|
7599
7789
|
state = "stale";
|
|
7600
7790
|
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`;
|
|
7601
7791
|
} else if (isHeldItem(spec) && entry.status === "downloaded" && entry.outputs.some((_output, index) => !existsSync7(currentEntryOutputPath(entry, spec, index)))) {
|
|
@@ -7663,6 +7853,7 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
7663
7853
|
}
|
|
7664
7854
|
const isActionable = (i) => i.state === "missing" || i.state === "stale" || i.state === "failed";
|
|
7665
7855
|
const stateOf = new Map(items.map((i) => [i.key, i.state]));
|
|
7856
|
+
const waiting = /* @__PURE__ */ new Set();
|
|
7666
7857
|
for (const item of items) {
|
|
7667
7858
|
if (!isActionable(item)) continue;
|
|
7668
7859
|
for (const parent of dependencies(item.spec)) {
|
|
@@ -7671,11 +7862,35 @@ async function buildPlan(specs, lock, opts = {}) {
|
|
|
7671
7862
|
if (parentState && isActionable({ state: parentState })) {
|
|
7672
7863
|
item.state = "blocked";
|
|
7673
7864
|
item.reason = `parent ${parentKey} is being generated in this run; this follows in the next wave`;
|
|
7865
|
+
waiting.add(item.key);
|
|
7674
7866
|
break;
|
|
7675
7867
|
}
|
|
7676
7868
|
if ((item.spec.mirror || item.spec.derive || isHeldItem(item.spec)) && (parentState === "recoverable" || parentState === "in-flight")) {
|
|
7677
7869
|
item.state = "blocked";
|
|
7678
7870
|
item.reason = `mirror source ${parentKey} is ${parentState}; this follows in the next wave`;
|
|
7871
|
+
waiting.add(item.key);
|
|
7872
|
+
break;
|
|
7873
|
+
}
|
|
7874
|
+
}
|
|
7875
|
+
}
|
|
7876
|
+
const byKey = new Map(items.map((i) => [i.key, i]));
|
|
7877
|
+
for (let changed = true; changed; ) {
|
|
7878
|
+
changed = false;
|
|
7879
|
+
for (const item of items) {
|
|
7880
|
+
if (item.state !== "blocked" || waiting.has(item.key)) continue;
|
|
7881
|
+
for (const parent of dependencies(item.spec)) {
|
|
7882
|
+
const parentKey = lockKey(parent.styleId, parent.assetId);
|
|
7883
|
+
const parentItem = byKey.get(parentKey);
|
|
7884
|
+
if (!parentItem || !item.reason.includes(`${parentKey} is not ready`)) continue;
|
|
7885
|
+
if (isActionable(parentItem)) {
|
|
7886
|
+
item.reason = `waits for ${parentKey}, which this run generates first; follows in a later wave (${item.reason})`;
|
|
7887
|
+
} else if (waiting.has(parentKey)) {
|
|
7888
|
+
item.reason = `waits for ${parentKey}, which itself follows in a later wave of this run (${item.reason})`;
|
|
7889
|
+
} else {
|
|
7890
|
+
continue;
|
|
7891
|
+
}
|
|
7892
|
+
waiting.add(item.key);
|
|
7893
|
+
changed = true;
|
|
7679
7894
|
break;
|
|
7680
7895
|
}
|
|
7681
7896
|
}
|
|
@@ -9436,9 +9651,9 @@ var PixelLabClient = class {
|
|
|
9436
9651
|
apiKey;
|
|
9437
9652
|
http;
|
|
9438
9653
|
/** Retries transport failures, 429, and 5xx; see http.ts for the policy. */
|
|
9439
|
-
async request(
|
|
9654
|
+
async request(path81, init) {
|
|
9440
9655
|
const auth = this.apiKey.startsWith("Bearer ") ? this.apiKey : `Bearer ${this.apiKey}`;
|
|
9441
|
-
const res = await this.http(`${BASE}${
|
|
9656
|
+
const res = await this.http(`${BASE}${path81}`, {
|
|
9442
9657
|
...init,
|
|
9443
9658
|
headers: {
|
|
9444
9659
|
Authorization: auth,
|
|
@@ -9449,13 +9664,13 @@ var PixelLabClient = class {
|
|
|
9449
9664
|
const text = await res.text();
|
|
9450
9665
|
if (!res.ok) {
|
|
9451
9666
|
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' : "";
|
|
9452
|
-
throw new PixelLabError(`${init?.method ?? "GET"} ${
|
|
9667
|
+
throw new PixelLabError(`${init?.method ?? "GET"} ${path81} \u2192 ${res.status}${hint}${refusalReason(res.status, text)}`, res.status, text);
|
|
9453
9668
|
}
|
|
9454
9669
|
if (!text) return {};
|
|
9455
9670
|
try {
|
|
9456
9671
|
return JSON.parse(text);
|
|
9457
9672
|
} catch {
|
|
9458
|
-
throw new Error(`${init?.method ?? "GET"} ${
|
|
9673
|
+
throw new Error(`${init?.method ?? "GET"} ${path81} returned invalid JSON`);
|
|
9459
9674
|
}
|
|
9460
9675
|
}
|
|
9461
9676
|
async balance() {
|
|
@@ -10007,10 +10222,10 @@ var PixelLabClient = class {
|
|
|
10007
10222
|
const palette = args.paletteSwatchBase64 ? { color_image: { type: "base64", base64: args.paletteSwatchBase64, format: "png" }, force_colors: true } : {};
|
|
10008
10223
|
const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
|
|
10009
10224
|
const south = args.reference?.south;
|
|
10010
|
-
let
|
|
10225
|
+
let path81;
|
|
10011
10226
|
let body;
|
|
10012
10227
|
if (args.mode === "v3") {
|
|
10013
|
-
|
|
10228
|
+
path81 = "/create-character-v3";
|
|
10014
10229
|
body = {
|
|
10015
10230
|
description: args.description,
|
|
10016
10231
|
image_size: imageSize,
|
|
@@ -10024,7 +10239,7 @@ var PixelLabClient = class {
|
|
|
10024
10239
|
...args.enhancePrompt ? { enhance_prompt: true } : {}
|
|
10025
10240
|
};
|
|
10026
10241
|
} else if (args.mode === "pro-flash") {
|
|
10027
|
-
|
|
10242
|
+
path81 = "/create-character-pro-flash";
|
|
10028
10243
|
const traits = args.styleTraits;
|
|
10029
10244
|
body = {
|
|
10030
10245
|
description: args.description,
|
|
@@ -10048,7 +10263,7 @@ var PixelLabClient = class {
|
|
|
10048
10263
|
} : {}
|
|
10049
10264
|
};
|
|
10050
10265
|
} else if (args.mode === "pro") {
|
|
10051
|
-
|
|
10266
|
+
path81 = "/create-character-pro";
|
|
10052
10267
|
body = {
|
|
10053
10268
|
description: args.description,
|
|
10054
10269
|
image_size: imageSize,
|
|
@@ -10062,7 +10277,7 @@ var PixelLabClient = class {
|
|
|
10062
10277
|
...!south && args.styleCharacterId ? { style_character_id: args.styleCharacterId } : {}
|
|
10063
10278
|
};
|
|
10064
10279
|
} else {
|
|
10065
|
-
|
|
10280
|
+
path81 = args.directions === 4 ? "/create-character-with-4-directions" : "/create-character-with-8-directions";
|
|
10066
10281
|
body = {
|
|
10067
10282
|
description: args.description,
|
|
10068
10283
|
image_size: imageSize,
|
|
@@ -10080,8 +10295,8 @@ var PixelLabClient = class {
|
|
|
10080
10295
|
};
|
|
10081
10296
|
}
|
|
10082
10297
|
if (args.mode === "pro" || args.mode === "pro-flash") Object.assign(body, targetPaletteBody(args.targetPalette));
|
|
10083
|
-
const raw = await this.request(
|
|
10084
|
-
return validateResponse(CharacterSubmitSchema, raw,
|
|
10298
|
+
const raw = await this.request(path81, { method: "POST", body: JSON.stringify(body) });
|
|
10299
|
+
return validateResponse(CharacterSubmitSchema, raw, path81.slice(1));
|
|
10085
10300
|
}
|
|
10086
10301
|
/** A text edit of an existing character, applied to every direction and stored as a sibling. */
|
|
10087
10302
|
async createCharacterState(args) {
|
|
@@ -11135,8 +11350,8 @@ var PixelLabClient = class {
|
|
|
11135
11350
|
}
|
|
11136
11351
|
/** Irreversible: the character, its states are separate records, and its animations. Checks `success` like `deleteObject`. */
|
|
11137
11352
|
async deleteCharacter(characterId) {
|
|
11138
|
-
const
|
|
11139
|
-
return deleteSucceeded(await this.request(
|
|
11353
|
+
const path81 = `/characters/${encodeURIComponent(characterId)}`;
|
|
11354
|
+
return deleteSucceeded(await this.request(path81, { method: "DELETE" }), `DELETE ${path81}`);
|
|
11140
11355
|
}
|
|
11141
11356
|
setCharacterTags(characterId, tags) {
|
|
11142
11357
|
return this.request(`/characters/${encodeURIComponent(characterId)}/tags`, {
|
|
@@ -12479,6 +12694,37 @@ var GRASP_PROMPT = "Every cyan mannequin on this spritesheet carries the same it
|
|
|
12479
12694
|
function layerWorkDir(spec) {
|
|
12480
12695
|
return path17.join(spec.root, ".pixelkiln", "layers", spec.styleId, spec.assetId);
|
|
12481
12696
|
}
|
|
12697
|
+
function layerSheetFor(spec, outputs) {
|
|
12698
|
+
const character = spec.character;
|
|
12699
|
+
const layer = character.layer;
|
|
12700
|
+
const label = `${spec.styleId}/${spec.assetId}`;
|
|
12701
|
+
if (!outputs.length) throw new Error(`${label}: its layer sources have no downloaded frames`);
|
|
12702
|
+
const sources = outputs.map((output) => ({
|
|
12703
|
+
assetId: output.assetId ?? character.parentAssetId,
|
|
12704
|
+
...output.role ? { role: output.role } : {},
|
|
12705
|
+
png: readFileSync2(output.path),
|
|
12706
|
+
still: output.still === true
|
|
12707
|
+
}));
|
|
12708
|
+
const supplied = (name, file) => {
|
|
12709
|
+
if (!file) return void 0;
|
|
12710
|
+
const bytes = readFileSync2(file.path);
|
|
12711
|
+
if (sha256(bytes) !== file.sha256) throw new Error(`${label}: layer ${name} changed after the manifest was resolved: ${file.path}`);
|
|
12712
|
+
return bytes;
|
|
12713
|
+
};
|
|
12714
|
+
return buildLayerSheet(sources, {
|
|
12715
|
+
minSide: 32,
|
|
12716
|
+
maxSide: LAYER_SHEET_MAX_SIDE,
|
|
12717
|
+
columns: layer.columns,
|
|
12718
|
+
region: layer.region,
|
|
12719
|
+
padding: layer.padding,
|
|
12720
|
+
key: layer.key,
|
|
12721
|
+
skin: layer.skin,
|
|
12722
|
+
cover: layer.cover,
|
|
12723
|
+
reference: layer.clean ? sources.filter((source) => source.still).map((source) => source.png) : [],
|
|
12724
|
+
mask: supplied("mask", layer.mask),
|
|
12725
|
+
keyed: supplied("keyed sheet", layer.keyed)
|
|
12726
|
+
});
|
|
12727
|
+
}
|
|
12482
12728
|
var PixelLabProvider = class _PixelLabProvider {
|
|
12483
12729
|
/**
|
|
12484
12730
|
* `mcp` reaches the tools PixelLab offers only over MCP (the VFX
|
|
@@ -13370,31 +13616,7 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
13370
13616
|
const layer = character.layer;
|
|
13371
13617
|
const label = `${spec.styleId}/${spec.assetId}`;
|
|
13372
13618
|
const outputs = context?.parentOutputs ?? [];
|
|
13373
|
-
|
|
13374
|
-
const sources = outputs.map((output) => ({
|
|
13375
|
-
assetId: output.assetId ?? character.parentAssetId,
|
|
13376
|
-
...output.role ? { role: output.role } : {},
|
|
13377
|
-
png: readFileSync2(output.path),
|
|
13378
|
-
still: output.still === true
|
|
13379
|
-
}));
|
|
13380
|
-
const supplied = (name2, file) => {
|
|
13381
|
-
if (!file) return void 0;
|
|
13382
|
-
const bytes = readFileSync2(file.path);
|
|
13383
|
-
if (sha256(bytes) !== file.sha256) throw new Error(`${label}: layer ${name2} changed after the manifest was resolved: ${file.path}`);
|
|
13384
|
-
return bytes;
|
|
13385
|
-
};
|
|
13386
|
-
const built = buildLayerSheet(sources, {
|
|
13387
|
-
minSide: 32,
|
|
13388
|
-
maxSide: LAYER_SHEET_MAX_SIDE,
|
|
13389
|
-
columns: layer.columns,
|
|
13390
|
-
region: layer.region,
|
|
13391
|
-
padding: layer.padding,
|
|
13392
|
-
key: layer.key,
|
|
13393
|
-
skin: layer.skin,
|
|
13394
|
-
reference: layer.clean ? sources.filter((source) => source.still).map((source) => source.png) : [],
|
|
13395
|
-
mask: supplied("mask", layer.mask),
|
|
13396
|
-
keyed: supplied("keyed sheet", layer.keyed)
|
|
13397
|
-
});
|
|
13619
|
+
const built = layerSheetFor(spec, outputs);
|
|
13398
13620
|
const dir = layerWorkDir(spec);
|
|
13399
13621
|
mkdirSync(dir, { recursive: true });
|
|
13400
13622
|
let prepared = built;
|
|
@@ -13449,7 +13671,15 @@ var PixelLabProvider = class _PixelLabProvider {
|
|
|
13449
13671
|
character: {
|
|
13450
13672
|
kind: "layer",
|
|
13451
13673
|
backgroundJobId: res2.background_job_id,
|
|
13452
|
-
sheet: {
|
|
13674
|
+
sheet: {
|
|
13675
|
+
width,
|
|
13676
|
+
height,
|
|
13677
|
+
frames: prepared.frames.length,
|
|
13678
|
+
cleanedPixels: prepared.cleaned,
|
|
13679
|
+
// Each frame's neck row in its cell, and the frames whose own narrowest row was overruled; submit prints both.
|
|
13680
|
+
...prepared.necks ? { necks: prepared.necks.map((neck) => neck?.row ?? null) } : {},
|
|
13681
|
+
...prepared.necks?.some((neck) => neck?.corrected) ? { neckCorrected: prepared.necks.flatMap((neck, index) => neck?.corrected ? [index] : []) } : {}
|
|
13682
|
+
}
|
|
13453
13683
|
}
|
|
13454
13684
|
}
|
|
13455
13685
|
};
|
|
@@ -15512,9 +15742,9 @@ var RetroDiffusionClient = class {
|
|
|
15512
15742
|
if (!response.ok) throw new ProviderError("retrodiffusion", `Retro Diffusion download failed (${response.status})`, { status: response.status });
|
|
15513
15743
|
return Buffer.from(await response.arrayBuffer());
|
|
15514
15744
|
}
|
|
15515
|
-
async call(
|
|
15745
|
+
async call(path81, init = {}) {
|
|
15516
15746
|
if (!this.token) throw new Error("RD_API_KEY is not set");
|
|
15517
|
-
const response = await this.request(`${this.baseUrl}${
|
|
15747
|
+
const response = await this.request(`${this.baseUrl}${path81}`, {
|
|
15518
15748
|
...init,
|
|
15519
15749
|
headers: {
|
|
15520
15750
|
"Content-Type": "application/json",
|
|
@@ -17691,6 +17921,7 @@ async function resolveSpecs(loaded, filter) {
|
|
|
17691
17921
|
...keyed ? { keyed } : {},
|
|
17692
17922
|
...asset.layer.skin ? { skin: asset.layer.skin } : {},
|
|
17693
17923
|
...asset.layer.key ? { key: asset.layer.key } : {},
|
|
17924
|
+
...asset.layer.cover ? { cover: true } : {},
|
|
17694
17925
|
clean: asset.layer.clean ?? true,
|
|
17695
17926
|
...asset.layer.columns ? { columns: asset.layer.columns } : {},
|
|
17696
17927
|
region: asset.layer.region ?? "body",
|
|
@@ -18479,6 +18710,9 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
18479
18710
|
if (processed.changed) rawHash = sha256(raw);
|
|
18480
18711
|
if (processed.moved?.clipped) log2(` moved ${path20.relative(process.cwd(), target)}: ${processed.moved.clipped} pixels fell off the canvas; raise layer.padding to keep them`);
|
|
18481
18712
|
if (processed.removed) log2(` cleaned ${path20.relative(process.cwd(), target)} (${processed.removed} ghost pixels)`);
|
|
18713
|
+
if (processed.removed && processed.opaque && processed.removed > processed.opaque * CLEAN_DAMAGE_SHARE) {
|
|
18714
|
+
log2(` warning: cleaning took ${processed.removed} of ${processed.opaque} opaque pixels (${(100 * processed.removed / processed.opaque).toFixed(1)}%) from ${path20.relative(process.cwd(), target)}; check the frame for holes, and set clean: false then fetch to restore the provider's bytes`);
|
|
18715
|
+
}
|
|
18482
18716
|
if (processed.snapped) log2(` snapped ${path20.relative(process.cwd(), target)} to ${wanted.palette.colors.length} colours`);
|
|
18483
18717
|
}
|
|
18484
18718
|
if (cacheDir) await cacheMedia(cacheDir, buf, mediaType);
|
|
@@ -18971,10 +19205,10 @@ function isSha256Hash(value) {
|
|
|
18971
19205
|
function parseCache(value) {
|
|
18972
19206
|
return HashCacheSchema.parse(value);
|
|
18973
19207
|
}
|
|
18974
|
-
async function loadCache(
|
|
18975
|
-
if (!existsSync18(
|
|
19208
|
+
async function loadCache(path81) {
|
|
19209
|
+
if (!existsSync18(path81)) return { version: 1, hashes: {} };
|
|
18976
19210
|
try {
|
|
18977
|
-
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile13(
|
|
19211
|
+
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile13(path81, "utf8")));
|
|
18978
19212
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
18979
19213
|
return {
|
|
18980
19214
|
version: 1,
|
|
@@ -18986,18 +19220,18 @@ async function loadCache(path79) {
|
|
|
18986
19220
|
return { version: 1, hashes: {} };
|
|
18987
19221
|
}
|
|
18988
19222
|
}
|
|
18989
|
-
async function saveCache(
|
|
19223
|
+
async function saveCache(path81, cache) {
|
|
18990
19224
|
const sorted = {};
|
|
18991
19225
|
for (const key3 of Object.keys(cache.hashes).sort()) {
|
|
18992
19226
|
const hash = cache.hashes[key3];
|
|
18993
19227
|
if (!isSha256Hash(hash)) throw new Error(`Refusing to cache invalid SHA-256 for ${key3}`);
|
|
18994
19228
|
sorted[key3] = hash;
|
|
18995
19229
|
}
|
|
18996
|
-
await mkdir9(pathModule.dirname(pathModule.resolve(
|
|
18997
|
-
const tmp = `${
|
|
19230
|
+
await mkdir9(pathModule.dirname(pathModule.resolve(path81)), { recursive: true });
|
|
19231
|
+
const tmp = `${path81}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
18998
19232
|
try {
|
|
18999
19233
|
await writeFile9(tmp, JSON.stringify({ version: 1, hashes: sorted }, null, 2) + "\n");
|
|
19000
|
-
await rename7(tmp,
|
|
19234
|
+
await rename7(tmp, path81);
|
|
19001
19235
|
} finally {
|
|
19002
19236
|
await rm5(tmp, { force: true });
|
|
19003
19237
|
}
|
|
@@ -23320,13 +23554,13 @@ function poseNodes(document, pose) {
|
|
|
23320
23554
|
const posed = /* @__PURE__ */ new Map();
|
|
23321
23555
|
for (const channel of animation.channels) {
|
|
23322
23556
|
const node = channel.target.node;
|
|
23323
|
-
const
|
|
23324
|
-
if (node === void 0 || !["translation", "rotation", "scale"].includes(
|
|
23557
|
+
const path81 = channel.target.path;
|
|
23558
|
+
if (node === void 0 || !["translation", "rotation", "scale"].includes(path81)) continue;
|
|
23325
23559
|
const sampler = animation.samplers[channel.sampler];
|
|
23326
23560
|
if (!sampler) continue;
|
|
23327
23561
|
const times = readAccessor(document, sampler.input).data;
|
|
23328
23562
|
const values = readAccessor(document, sampler.output);
|
|
23329
|
-
const width =
|
|
23563
|
+
const width = path81 === "rotation" ? 4 : 3;
|
|
23330
23564
|
const cubic = sampler.interpolation === "CUBICSPLINE";
|
|
23331
23565
|
const valueAt = (key4) => Array.from(values.data.subarray((cubic ? key4 * 3 + 1 : key4) * width, (cubic ? key4 * 3 + 1 : key4) * width + width));
|
|
23332
23566
|
const last = times.length - 1;
|
|
@@ -23338,16 +23572,16 @@ function poseNodes(document, pose) {
|
|
|
23338
23572
|
const span = times[key3 + 1] - times[key3];
|
|
23339
23573
|
const f = span > 0 ? (time - times[key3]) / span : 0;
|
|
23340
23574
|
const next = valueAt(key3 + 1);
|
|
23341
|
-
const sign =
|
|
23575
|
+
const sign = path81 === "rotation" && value.reduce((sum, v, k) => sum + v * next[k], 0) < 0 ? -1 : 1;
|
|
23342
23576
|
value = value.map((v, k) => v * (1 - f) + next[k] * sign * f);
|
|
23343
23577
|
}
|
|
23344
|
-
if (
|
|
23578
|
+
if (path81 === "rotation") {
|
|
23345
23579
|
const length = Math.hypot(...value) || 1;
|
|
23346
23580
|
value = value.map((v) => v / length);
|
|
23347
23581
|
}
|
|
23348
23582
|
const base = posed.get(node) ?? { ...document.json.nodes?.[node] ?? {} };
|
|
23349
23583
|
if (base.matrix) delete base.matrix;
|
|
23350
|
-
base[
|
|
23584
|
+
base[path81] = value;
|
|
23351
23585
|
posed.set(node, base);
|
|
23352
23586
|
}
|
|
23353
23587
|
return posed;
|
|
@@ -25830,7 +26064,7 @@ function describeSize(document, image) {
|
|
|
25830
26064
|
}
|
|
25831
26065
|
|
|
25832
26066
|
// src/cli/commands/gallery.ts
|
|
25833
|
-
import
|
|
26067
|
+
import path48 from "path";
|
|
25834
26068
|
import { existsSync as existsSync39 } from "fs";
|
|
25835
26069
|
|
|
25836
26070
|
// src/gallery/server.ts
|
|
@@ -26570,6 +26804,83 @@ async function poll(provider, lock, lockPath, opts = {}) {
|
|
|
26570
26804
|
return result;
|
|
26571
26805
|
}
|
|
26572
26806
|
|
|
26807
|
+
// src/pipeline/layer-preview.ts
|
|
26808
|
+
import { mkdir as mkdir19, rm as rm13, writeFile as writeFile23 } from "fs/promises";
|
|
26809
|
+
import path44 from "path";
|
|
26810
|
+
function layerSourceOutputs(spec, lock) {
|
|
26811
|
+
return spec.character.layer.sources.flatMap((source) => {
|
|
26812
|
+
const sourceEntry = lock.entries[lockKey(source.spec.styleId, source.spec.assetId)];
|
|
26813
|
+
return sourceEntry.outputs.map((output, index) => ({
|
|
26814
|
+
path: currentEntryOutputPath(sourceEntry, source.spec, index),
|
|
26815
|
+
role: output.role,
|
|
26816
|
+
assetId: source.assetId,
|
|
26817
|
+
still: source.spec.character?.kind !== "animation"
|
|
26818
|
+
}));
|
|
26819
|
+
});
|
|
26820
|
+
}
|
|
26821
|
+
function overlay(sheet, mask) {
|
|
26822
|
+
const image = decodePng(sheet);
|
|
26823
|
+
const allowed = decodePng(mask);
|
|
26824
|
+
const out = Buffer.from(image.pixels);
|
|
26825
|
+
for (let i = 0; i < out.length; i += 4) {
|
|
26826
|
+
if (allowed.pixels[i] === 255) {
|
|
26827
|
+
out[i] = Math.round(out[i] * 0.4 + 255 * 0.6);
|
|
26828
|
+
out[i + 1] = Math.round(out[i + 1] * 0.4);
|
|
26829
|
+
out[i + 2] = Math.round(out[i + 2] * 0.4 + 255 * 0.6);
|
|
26830
|
+
out[i + 3] = 255;
|
|
26831
|
+
} else if (out[i + 3]) {
|
|
26832
|
+
out[i + 3] = 110;
|
|
26833
|
+
}
|
|
26834
|
+
}
|
|
26835
|
+
return encodeRgbaPng(image.width, image.height, out);
|
|
26836
|
+
}
|
|
26837
|
+
async function previewLayer(spec, lock) {
|
|
26838
|
+
const label = `${spec.styleId}/${spec.assetId}`;
|
|
26839
|
+
const layer = spec.character?.kind === "layer" ? spec.character.layer : void 0;
|
|
26840
|
+
if (!layer) throw new Error(`${label} is not a paperdoll layer`);
|
|
26841
|
+
if (layer.attach) throw new Error(`${label} is a held item, placed rather than inpainted; it has no mask to preview`);
|
|
26842
|
+
await requireRevisionReady(spec, lock);
|
|
26843
|
+
const built = layerSheetFor(spec, layerSourceOutputs(spec, lock));
|
|
26844
|
+
const { width, height } = decodePng(built.keyed);
|
|
26845
|
+
const dir = path44.join(layerWorkDir(spec), "preview");
|
|
26846
|
+
await rm13(dir, { recursive: true, force: true });
|
|
26847
|
+
await mkdir19(path44.join(dir, "frames"), { recursive: true });
|
|
26848
|
+
const written = [];
|
|
26849
|
+
const put = async (name, png) => {
|
|
26850
|
+
const file = path44.join(dir, name);
|
|
26851
|
+
await writeFile23(file, png);
|
|
26852
|
+
written.push(file);
|
|
26853
|
+
};
|
|
26854
|
+
await put("sheet.png", built.sheet);
|
|
26855
|
+
await put("keyed.png", built.keyed);
|
|
26856
|
+
await put("mask.png", built.mask);
|
|
26857
|
+
await put("overlay.png", overlay(built.sheet, built.mask));
|
|
26858
|
+
const cells = built.frames.map((frame) => frame.cell);
|
|
26859
|
+
const keyedCells = unpackSheet(built.keyed, cells);
|
|
26860
|
+
const maskCells = unpackSheet(built.mask, cells);
|
|
26861
|
+
const frames = [];
|
|
26862
|
+
for (const [index, frame] of built.frames.entries()) {
|
|
26863
|
+
const name = `${frame.assetId}.${frame.role ?? String(index).padStart(2, "0")}`;
|
|
26864
|
+
const stem2 = `${String(index).padStart(3, "0")}-${name.replace(/[^A-Za-z0-9._-]/g, "_")}`;
|
|
26865
|
+
await put(path44.join("frames", `${stem2}.keyed.png`), keyedCells[index]);
|
|
26866
|
+
await put(path44.join("frames", `${stem2}.mask.png`), maskCells[index]);
|
|
26867
|
+
const { pixels } = decodePng(maskCells[index]);
|
|
26868
|
+
let masked = 0;
|
|
26869
|
+
for (let i = 0; i < pixels.length; i += 4) if (pixels[i] === 255) masked++;
|
|
26870
|
+
frames.push({ name, neck: built.necks?.[index] ?? null, masked });
|
|
26871
|
+
}
|
|
26872
|
+
return {
|
|
26873
|
+
dir,
|
|
26874
|
+
sheet: { width, height },
|
|
26875
|
+
cost: proTierCost(width, height),
|
|
26876
|
+
frames,
|
|
26877
|
+
supplied: { mask: Boolean(layer.mask), keyed: Boolean(layer.keyed) },
|
|
26878
|
+
...built.closed !== void 0 ? { closed: built.closed } : {},
|
|
26879
|
+
cleaned: built.cleaned,
|
|
26880
|
+
written
|
|
26881
|
+
};
|
|
26882
|
+
}
|
|
26883
|
+
|
|
26573
26884
|
// src/pipeline/submit.ts
|
|
26574
26885
|
var IN_FLIGHT_POLL_MS = 5e3;
|
|
26575
26886
|
var sleep2 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -26852,15 +27163,7 @@ async function submit(provider, loaded, items, lock, lockPath, opts = {}) {
|
|
|
26852
27163
|
const parentOutputs = spec.character?.kind === "outfit" && parentEntry ? parentEntry.outputs.map((output, index) => ({
|
|
26853
27164
|
path: currentEntryOutputPath(parentEntry, spec.character.parentSpec, index),
|
|
26854
27165
|
role: output.role
|
|
26855
|
-
})) : spec.character?.kind === "layer" ? spec
|
|
26856
|
-
const sourceEntry = lock.entries[lockKey(source.spec.styleId, source.spec.assetId)];
|
|
26857
|
-
return sourceEntry.outputs.map((output, index) => ({
|
|
26858
|
-
path: currentEntryOutputPath(sourceEntry, source.spec, index),
|
|
26859
|
-
role: output.role,
|
|
26860
|
-
assetId: source.assetId,
|
|
26861
|
-
still: source.spec.character?.kind !== "animation"
|
|
26862
|
-
}));
|
|
26863
|
-
}) : void 0;
|
|
27166
|
+
})) : spec.character?.kind === "layer" ? layerSourceOutputs(spec, lock) : void 0;
|
|
26864
27167
|
const referenceSourceImageId = ownedReferenceImageId(spec, lock, provider.id);
|
|
26865
27168
|
const { jobId, metadata } = await provider.submit(spec, refs, {
|
|
26866
27169
|
...previousJobId ? { previousJobId } : {},
|
|
@@ -26909,6 +27212,13 @@ async function submit(provider, loaded, items, lock, lockPath, opts = {}) {
|
|
|
26909
27212
|
log2(
|
|
26910
27213
|
` ${key3} \u2192 ${jobId} (${spec.width}x${spec.height}` + (estimate.candidates > 1 ? `, ${estimate.candidates} ${spec.tileFeature ? "outputs" : "candidates"}` : "") + `, ${estimate.amount})`
|
|
26911
27214
|
);
|
|
27215
|
+
const sheet = metadata?.character?.sheet;
|
|
27216
|
+
if (sheet?.necks) {
|
|
27217
|
+
log2(` neck rows by frame: ${sheet.necks.map((row) => row ?? "-").join(" ")}`);
|
|
27218
|
+
if (sheet.neckCorrected?.length) {
|
|
27219
|
+
log2(` frame${sheet.neckCorrected.length === 1 ? "" : "s"} ${sheet.neckCorrected.join(", ")}: own narrowest row disagreed; neck taken from the head and the other frames`);
|
|
27220
|
+
}
|
|
27221
|
+
}
|
|
26912
27222
|
} catch (err) {
|
|
26913
27223
|
const message6 = err instanceof Error ? err.message : String(err);
|
|
26914
27224
|
const entry = lock.entries[key3];
|
|
@@ -26951,9 +27261,9 @@ import { existsSync as existsSync37 } from "fs";
|
|
|
26951
27261
|
import { readFile as readFile33 } from "fs/promises";
|
|
26952
27262
|
|
|
26953
27263
|
// src/pipeline/init.ts
|
|
26954
|
-
import { readdir as readdir4, readFile as readFile32, writeFile as
|
|
27264
|
+
import { readdir as readdir4, readFile as readFile32, writeFile as writeFile24 } from "fs/promises";
|
|
26955
27265
|
import { existsSync as existsSync36 } from "fs";
|
|
26956
|
-
import
|
|
27266
|
+
import path45 from "path";
|
|
26957
27267
|
function pngSize(buf) {
|
|
26958
27268
|
if (buf.length < 24) return null;
|
|
26959
27269
|
const isPng = buf.readUInt32BE(0) === 2303741511 && buf.readUInt32BE(4) === 218765834;
|
|
@@ -26967,7 +27277,7 @@ function slugify(value) {
|
|
|
26967
27277
|
async function walk(dir, exclude) {
|
|
26968
27278
|
const out = [];
|
|
26969
27279
|
for (const entry of await readdir4(dir, { withFileTypes: true })) {
|
|
26970
|
-
const full =
|
|
27280
|
+
const full = path45.join(dir, entry.name);
|
|
26971
27281
|
if (exclude.some((x) => full.includes(x))) continue;
|
|
26972
27282
|
if (entry.isDirectory()) out.push(...await walk(full, exclude));
|
|
26973
27283
|
else if (entry.name.toLowerCase().endsWith(".png")) out.push(full);
|
|
@@ -26986,9 +27296,9 @@ async function scanAssets(root, opts = {}) {
|
|
|
26986
27296
|
skipped.push(`${file} (not a readable PNG)`);
|
|
26987
27297
|
continue;
|
|
26988
27298
|
}
|
|
26989
|
-
const rel =
|
|
26990
|
-
const category =
|
|
26991
|
-
let id = slugify(
|
|
27299
|
+
const rel = path45.relative(root, file);
|
|
27300
|
+
const category = path45.dirname(rel) === "." ? "" : path45.dirname(rel);
|
|
27301
|
+
let id = slugify(path45.basename(rel));
|
|
26992
27302
|
if (seen.has(id)) {
|
|
26993
27303
|
const n = seen.get(id) + 1;
|
|
26994
27304
|
seen.set(id, n);
|
|
@@ -27049,7 +27359,7 @@ async function writeManifestFile(target, manifest) {
|
|
|
27049
27359
|
if (existsSync36(target)) {
|
|
27050
27360
|
throw new Error(`${target} already exists; refusing to overwrite an existing manifest.`);
|
|
27051
27361
|
}
|
|
27052
|
-
await
|
|
27362
|
+
await writeFile24(target, JSON.stringify(manifest, null, 2) + "\n");
|
|
27053
27363
|
}
|
|
27054
27364
|
|
|
27055
27365
|
// src/pick/sheet.ts
|
|
@@ -28757,14 +29067,14 @@ function createGenerateHandlers(opts) {
|
|
|
28757
29067
|
|
|
28758
29068
|
// src/gallery/editor.ts
|
|
28759
29069
|
import { readFile as readFile35 } from "fs/promises";
|
|
28760
|
-
import
|
|
29070
|
+
import path47 from "path";
|
|
28761
29071
|
|
|
28762
29072
|
// src/editor/install.ts
|
|
28763
29073
|
import { createHash as createHash6 } from "crypto";
|
|
28764
29074
|
import { existsSync as existsSync38 } from "fs";
|
|
28765
|
-
import { mkdir as
|
|
29075
|
+
import { mkdir as mkdir20, readFile as readFile34, rename as rename14, rm as rm14, stat as stat4, writeFile as writeFile25 } from "fs/promises";
|
|
28766
29076
|
import os3 from "os";
|
|
28767
|
-
import
|
|
29077
|
+
import path46 from "path";
|
|
28768
29078
|
|
|
28769
29079
|
// tools/pixelorama-bridge/pin.json
|
|
28770
29080
|
var pin_default = {
|
|
@@ -28828,15 +29138,15 @@ var EditorInstallError = class extends Error {
|
|
|
28828
29138
|
};
|
|
28829
29139
|
function editorToolsRoot() {
|
|
28830
29140
|
const override = process.env.PIXELKILN_TOOLS_DIR?.trim();
|
|
28831
|
-
if (override) return
|
|
28832
|
-
if (process.platform === "darwin") return
|
|
29141
|
+
if (override) return path46.resolve(override);
|
|
29142
|
+
if (process.platform === "darwin") return path46.join(os3.homedir(), "Library", "Caches", "pixelkiln", "tools");
|
|
28833
29143
|
if (process.platform === "win32") {
|
|
28834
|
-
return
|
|
29144
|
+
return path46.join(process.env.LOCALAPPDATA ?? path46.join(os3.homedir(), "AppData", "Local"), "pixelkiln", "tools");
|
|
28835
29145
|
}
|
|
28836
|
-
return
|
|
29146
|
+
return path46.join(process.env.XDG_CACHE_HOME ?? path46.join(os3.homedir(), ".cache"), "pixelkiln", "tools");
|
|
28837
29147
|
}
|
|
28838
29148
|
function editorDir(pin = EDITOR_PIN, root = editorToolsRoot()) {
|
|
28839
|
-
return
|
|
29149
|
+
return path46.join(root, "pixelorama", pin.release ?? "unpublished");
|
|
28840
29150
|
}
|
|
28841
29151
|
function editorBaseUrl(pin = EDITOR_PIN) {
|
|
28842
29152
|
const override = process.env.PIXELKILN_EDITOR_URL?.trim();
|
|
@@ -28859,7 +29169,7 @@ async function editorStatus(opts = {}) {
|
|
|
28859
29169
|
let totalBytes = 0;
|
|
28860
29170
|
for (const [name, expected] of Object.entries(pin.files)) {
|
|
28861
29171
|
totalBytes += expected.bytes;
|
|
28862
|
-
const file =
|
|
29172
|
+
const file = path46.join(dir, name);
|
|
28863
29173
|
const info = existsSync38(file) ? await stat4(file).catch(() => null) : null;
|
|
28864
29174
|
if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
|
|
28865
29175
|
installedBytes += expected.bytes;
|
|
@@ -28889,7 +29199,7 @@ async function installEditor(opts = {}) {
|
|
|
28889
29199
|
);
|
|
28890
29200
|
}
|
|
28891
29201
|
if (!baseUrl) throw new EditorInstallError("no download location for the editor build");
|
|
28892
|
-
await
|
|
29202
|
+
await mkdir20(dir, { recursive: true });
|
|
28893
29203
|
const downloaded = [];
|
|
28894
29204
|
const skipped = Object.keys(pin.files).filter((name) => !before.missing.includes(name));
|
|
28895
29205
|
let fetchedBytes = before.installedBytes;
|
|
@@ -28917,13 +29227,13 @@ async function installEditor(opts = {}) {
|
|
|
28917
29227
|
if (digest2 !== expected.sha256) {
|
|
28918
29228
|
throw new EditorInstallError(`${name}: sha256 ${digest2.slice(0, 12)}\u2026 does not match the pinned ${expected.sha256.slice(0, 12)}\u2026`, name);
|
|
28919
29229
|
}
|
|
28920
|
-
const final =
|
|
29230
|
+
const final = path46.join(dir, name);
|
|
28921
29231
|
const tmp = `${final}.${process.pid}.part`;
|
|
28922
29232
|
try {
|
|
28923
|
-
await
|
|
29233
|
+
await writeFile25(tmp, bytes);
|
|
28924
29234
|
await rename14(tmp, final);
|
|
28925
29235
|
} finally {
|
|
28926
|
-
await
|
|
29236
|
+
await rm14(tmp, { force: true });
|
|
28927
29237
|
}
|
|
28928
29238
|
fetchedBytes += bytes.length;
|
|
28929
29239
|
downloaded.push(name);
|
|
@@ -28963,7 +29273,7 @@ var EDITOR_CONTENT_TYPES = {
|
|
|
28963
29273
|
".json": "application/json; charset=utf-8"
|
|
28964
29274
|
};
|
|
28965
29275
|
function editorContentType(name) {
|
|
28966
|
-
return EDITOR_CONTENT_TYPES[
|
|
29276
|
+
return EDITOR_CONTENT_TYPES[path46.extname(name).toLowerCase()] ?? null;
|
|
28967
29277
|
}
|
|
28968
29278
|
|
|
28969
29279
|
// src/gallery/editor.ts
|
|
@@ -29039,7 +29349,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
29039
29349
|
if (!status.installed) return null;
|
|
29040
29350
|
let bytes;
|
|
29041
29351
|
try {
|
|
29042
|
-
bytes = await readFile35(
|
|
29352
|
+
bytes = await readFile35(path47.join(dir, name));
|
|
29043
29353
|
} catch {
|
|
29044
29354
|
verified = null;
|
|
29045
29355
|
return null;
|
|
@@ -29079,7 +29389,7 @@ async function serveUntilStopped(initial, reload, args, access2) {
|
|
|
29079
29389
|
};
|
|
29080
29390
|
const loadProject = async (project2) => {
|
|
29081
29391
|
const ctx = await access2.loadProject(project2);
|
|
29082
|
-
loadProjectEnv(
|
|
29392
|
+
loadProjectEnv(path48.dirname(ctx.loaded.path));
|
|
29083
29393
|
return ctx;
|
|
29084
29394
|
};
|
|
29085
29395
|
const loadProjectEnv = (dir) => {
|
|
@@ -29088,7 +29398,7 @@ async function serveUntilStopped(initial, reload, args, access2) {
|
|
|
29088
29398
|
for (const [name, value] of Object.entries(declared)) {
|
|
29089
29399
|
if (credentialNames.has(name) && name in process.env && process.env[name] !== value) {
|
|
29090
29400
|
throw new Error(
|
|
29091
|
-
`${
|
|
29401
|
+
`${path48.relative(process.cwd(), dir) || "."} sets ${name} to a different value than the one this gallery already loaded; run a separate gallery for that project so its work uses its own account.`
|
|
29092
29402
|
);
|
|
29093
29403
|
}
|
|
29094
29404
|
}
|
|
@@ -29096,7 +29406,7 @@ async function serveUntilStopped(initial, reload, args, access2) {
|
|
|
29096
29406
|
};
|
|
29097
29407
|
const quoters = /* @__PURE__ */ new Map();
|
|
29098
29408
|
const quoteFor = async (project2) => {
|
|
29099
|
-
loadProjectEnv(
|
|
29409
|
+
loadProjectEnv(path48.dirname(path48.resolve(await access2.manifestFor(project2))));
|
|
29100
29410
|
const key3 = process.env.PIXELLAB_API_KEY;
|
|
29101
29411
|
if (!key3) return null;
|
|
29102
29412
|
let quoter = quoters.get(key3);
|
|
@@ -29147,7 +29457,7 @@ async function serveUntilStopped(initial, reload, args, access2) {
|
|
|
29147
29457
|
}
|
|
29148
29458
|
async function runGallery(args) {
|
|
29149
29459
|
if (args.workspace) {
|
|
29150
|
-
const workspacePath =
|
|
29460
|
+
const workspacePath = path48.resolve(args.workspace);
|
|
29151
29461
|
if (!existsSync39(workspacePath)) {
|
|
29152
29462
|
throw new Error(`Workspace catalog not found: ${workspacePath}`);
|
|
29153
29463
|
}
|
|
@@ -29168,7 +29478,7 @@ async function runGallery(args) {
|
|
|
29168
29478
|
const registered = async (projectId) => {
|
|
29169
29479
|
const project2 = (await loadWorkspace(workspacePath)).projects.find((candidate) => candidate.id === projectId);
|
|
29170
29480
|
if (!projectId || !project2) throw new Error(`unknown workspace project "${projectId ?? ""}"`);
|
|
29171
|
-
return resolveProject(
|
|
29481
|
+
return resolveProject(path48.dirname(workspacePath), project2);
|
|
29172
29482
|
};
|
|
29173
29483
|
await serveUntilStopped(initial, build2, args, {
|
|
29174
29484
|
manifestFor: async (projectId) => (await registered(projectId)).manifestPath,
|
|
@@ -29193,7 +29503,7 @@ async function runGallery(args) {
|
|
|
29193
29503
|
return buildGallerySnapshot({ ...fresh, filter });
|
|
29194
29504
|
};
|
|
29195
29505
|
await serveUntilStopped(await build(), reload, args, {
|
|
29196
|
-
manifestFor: () =>
|
|
29506
|
+
manifestFor: () => path48.resolve(args.manifest),
|
|
29197
29507
|
loadProject: () => openProject(args.manifest, { lockPath: args.lock, env: false })
|
|
29198
29508
|
});
|
|
29199
29509
|
}
|
|
@@ -29540,14 +29850,14 @@ import { existsSync as existsSync41 } from "fs";
|
|
|
29540
29850
|
|
|
29541
29851
|
// src/pipeline/cache-health.ts
|
|
29542
29852
|
import { existsSync as existsSync40 } from "fs";
|
|
29543
|
-
import { readFile as readFile36, readdir as readdir5, rm as
|
|
29544
|
-
import
|
|
29853
|
+
import { readFile as readFile36, readdir as readdir5, rm as rm15 } from "fs/promises";
|
|
29854
|
+
import path49 from "path";
|
|
29545
29855
|
async function inspectCaches(lock, lockPath, options = {}) {
|
|
29546
29856
|
if (options.prune && !existsSync40(lockPath)) {
|
|
29547
|
-
throw new Error(`Refusing to prune without an existing lockfile at ${
|
|
29857
|
+
throw new Error(`Refusing to prune without an existing lockfile at ${path49.resolve(lockPath)}`);
|
|
29548
29858
|
}
|
|
29549
|
-
const contentDir =
|
|
29550
|
-
const remotePath =
|
|
29859
|
+
const contentDir = path49.resolve(path49.dirname(lockPath), ".pixelkiln", "cache");
|
|
29860
|
+
const remotePath = path49.resolve(cachePathFor(lockPath));
|
|
29551
29861
|
const referenced = referencedHashes(lock);
|
|
29552
29862
|
let content = await inspectContentCache(contentDir, referenced);
|
|
29553
29863
|
let remoteHashes = await inspectRemoteHashCache(remotePath);
|
|
@@ -29559,7 +29869,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
29559
29869
|
]);
|
|
29560
29870
|
for (const name of names) {
|
|
29561
29871
|
try {
|
|
29562
|
-
await
|
|
29872
|
+
await rm15(path49.join(contentDir, name), { force: true });
|
|
29563
29873
|
removed.contentFiles++;
|
|
29564
29874
|
} catch {
|
|
29565
29875
|
}
|
|
@@ -29607,7 +29917,7 @@ async function inspectContentCache(contentDir, referenced) {
|
|
|
29607
29917
|
continue;
|
|
29608
29918
|
}
|
|
29609
29919
|
report.files++;
|
|
29610
|
-
const file =
|
|
29920
|
+
const file = path49.join(contentDir, entry.name);
|
|
29611
29921
|
const mediaType = mediaTypeFromExtension(entry.name);
|
|
29612
29922
|
const expected = mediaType ? entry.name.slice(0, -4) : "";
|
|
29613
29923
|
let bytes;
|
|
@@ -29778,46 +30088,46 @@ This drops their provenance from the lockfile. The art on disk is`);
|
|
|
29778
30088
|
}
|
|
29779
30089
|
|
|
29780
30090
|
// src/cli/commands/init.ts
|
|
29781
|
-
import
|
|
30091
|
+
import path50 from "path";
|
|
29782
30092
|
import { existsSync as existsSync42 } from "fs";
|
|
29783
30093
|
async function runInit(args) {
|
|
29784
30094
|
if (!args.from) throw new Error("init needs --from <dir> pointing at your existing PNGs.");
|
|
29785
|
-
const root =
|
|
30095
|
+
const root = path50.resolve(args.from);
|
|
29786
30096
|
if (!existsSync42(root)) throw new Error(`No directory at ${root}`);
|
|
29787
30097
|
const generator = args.generator ?? "map";
|
|
29788
30098
|
if (generator !== "1dir" && generator !== "map") {
|
|
29789
30099
|
throw new Error(`--generator must be "1dir" or "map", got "${args.generator}".`);
|
|
29790
30100
|
}
|
|
29791
|
-
const target =
|
|
30101
|
+
const target = path50.resolve(args.out ?? "pixelkiln.manifest.json");
|
|
29792
30102
|
const { assets, skipped } = await scanAssets(root, { exclude: args.exclude });
|
|
29793
30103
|
if (!assets.length) throw new Error(`No PNGs found under ${root}`);
|
|
29794
30104
|
const manifest = buildManifest(
|
|
29795
|
-
args.name ??
|
|
30105
|
+
args.name ?? path50.basename(path50.dirname(target)),
|
|
29796
30106
|
args.styles[0] ?? "base",
|
|
29797
30107
|
generator,
|
|
29798
|
-
|
|
30108
|
+
path50.relative(path50.dirname(target), root) || ".",
|
|
29799
30109
|
assets
|
|
29800
30110
|
);
|
|
29801
30111
|
await writeManifestFile(target, manifest);
|
|
29802
|
-
log(` scanned ${assets.length} PNG(s) under ${
|
|
30112
|
+
log(` scanned ${assets.length} PNG(s) under ${path50.relative(process.cwd(), root)}`);
|
|
29803
30113
|
if (skipped.length) log(` skipped ${skipped.length} unreadable file(s)`);
|
|
29804
|
-
log(` wrote ${
|
|
30114
|
+
log(` wrote ${path50.relative(process.cwd(), target)}`);
|
|
29805
30115
|
log(`
|
|
29806
30116
|
Prompts are intentionally empty. To recover the real ones from your`);
|
|
29807
30117
|
log(` PixelLab account instead of inventing them:`);
|
|
29808
30118
|
log(`
|
|
29809
|
-
pixelkiln adopt --manifest ${
|
|
30119
|
+
pixelkiln adopt --manifest ${path50.relative(process.cwd(), target)} --write-prompts
|
|
29810
30120
|
`);
|
|
29811
30121
|
}
|
|
29812
30122
|
|
|
29813
30123
|
// src/pipeline/doctor.ts
|
|
29814
30124
|
import { constants, existsSync as existsSync44 } from "fs";
|
|
29815
30125
|
import { access, stat as stat5 } from "fs/promises";
|
|
29816
|
-
import
|
|
30126
|
+
import path52 from "path";
|
|
29817
30127
|
|
|
29818
30128
|
// src/pipeline/install-check.ts
|
|
29819
30129
|
import { existsSync as existsSync43, readFileSync as readFileSync7 } from "fs";
|
|
29820
|
-
import
|
|
30130
|
+
import path51 from "path";
|
|
29821
30131
|
function readJson(file) {
|
|
29822
30132
|
try {
|
|
29823
30133
|
return JSON.parse(readFileSync7(file, "utf8"));
|
|
@@ -29826,18 +30136,18 @@ function readJson(file) {
|
|
|
29826
30136
|
}
|
|
29827
30137
|
}
|
|
29828
30138
|
function readInstallFacts(manifestDir, running) {
|
|
29829
|
-
let dir =
|
|
30139
|
+
let dir = path51.resolve(manifestDir);
|
|
29830
30140
|
for (let depth = 0; depth < 4; depth++) {
|
|
29831
|
-
const pkg = readJson(
|
|
30141
|
+
const pkg = readJson(path51.join(dir, "package.json"));
|
|
29832
30142
|
if (pkg) {
|
|
29833
30143
|
const pinned = ["dependencies", "devDependencies", "optionalDependencies"].map((field) => pkg[field]?.pixelkiln).find((spec) => typeof spec === "string");
|
|
29834
30144
|
if (pinned) {
|
|
29835
|
-
const installedPkg = readJson(
|
|
30145
|
+
const installedPkg = readJson(path51.join(dir, "node_modules", "pixelkiln", "package.json"));
|
|
29836
30146
|
const installed = typeof installedPkg?.version === "string" ? installedPkg.version : void 0;
|
|
29837
30147
|
return { pinned, installed, running };
|
|
29838
30148
|
}
|
|
29839
30149
|
}
|
|
29840
|
-
const parent =
|
|
30150
|
+
const parent = path51.dirname(dir);
|
|
29841
30151
|
if (parent === dir || !existsSync43(parent)) break;
|
|
29842
30152
|
dir = parent;
|
|
29843
30153
|
}
|
|
@@ -29901,12 +30211,12 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
29901
30211
|
`${entry.kind === "style" ? "styles" : "assets"}.${entry.id} was left out: ${entry.issues.join("; ")}`
|
|
29902
30212
|
);
|
|
29903
30213
|
}
|
|
29904
|
-
const facts = readInstallFacts(
|
|
30214
|
+
const facts = readInstallFacts(path52.dirname(loaded.path), opts.runningVersion !== void 0 ? opts.runningVersion : pixelkilnVersion());
|
|
29905
30215
|
if (facts) for (const finding of checkInstall(facts)) add("install", finding.level, finding.message);
|
|
29906
30216
|
add("lock", "ok", `${Object.keys(lock.entries).length} valid v2 lock entr(ies)`);
|
|
29907
30217
|
const dirs = [...new Set(specs.flatMap((spec) => [
|
|
29908
|
-
|
|
29909
|
-
...spec.quality ? [
|
|
30218
|
+
path52.dirname(spec.outFile),
|
|
30219
|
+
...spec.quality ? [path52.dirname(spec.quality.outFile)] : []
|
|
29910
30220
|
]))];
|
|
29911
30221
|
const unwritable = [];
|
|
29912
30222
|
for (const dir of dirs) {
|
|
@@ -29929,7 +30239,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
29929
30239
|
for (let index = 0; index < entry.outputs.length; index++) {
|
|
29930
30240
|
const output = entry.outputs[index];
|
|
29931
30241
|
const spec = specByKey.get(key3);
|
|
29932
|
-
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path,
|
|
30242
|
+
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path, path52.dirname(lockPath));
|
|
29933
30243
|
const owner = outputOwners.get(absolute);
|
|
29934
30244
|
if (owner && owner !== key3) duplicateOutputs.push(`${output.path} (${owner}, ${key3})`);
|
|
29935
30245
|
outputOwners.set(absolute, key3);
|
|
@@ -29944,7 +30254,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
29944
30254
|
} else {
|
|
29945
30255
|
add("lock-outputs", "ok", `${outputOwners.size} recorded output path(s) are uniquely owned`);
|
|
29946
30256
|
}
|
|
29947
|
-
const cacheDir =
|
|
30257
|
+
const cacheDir = path52.join(path52.dirname(lockPath), ".pixelkiln", "cache");
|
|
29948
30258
|
const stranded = [];
|
|
29949
30259
|
const invalidState = [];
|
|
29950
30260
|
const staleMapUrls = [];
|
|
@@ -29960,7 +30270,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
29960
30270
|
const hasSource = Boolean(entry.sourceUrl || entry.sourceUrls?.length);
|
|
29961
30271
|
let hasCache = false;
|
|
29962
30272
|
for (const output of entry.outputs) {
|
|
29963
|
-
const cached2 =
|
|
30273
|
+
const cached2 = path52.join(
|
|
29964
30274
|
cacheDir,
|
|
29965
30275
|
cacheFileName(output.sha256, output.mediaType ?? MediaType.PNG)
|
|
29966
30276
|
);
|
|
@@ -30060,7 +30370,7 @@ async function nearestExistingDirectory(start) {
|
|
|
30060
30370
|
if ((await stat5(current)).isDirectory()) return current;
|
|
30061
30371
|
} catch {
|
|
30062
30372
|
}
|
|
30063
|
-
const parent =
|
|
30373
|
+
const parent = path52.dirname(current);
|
|
30064
30374
|
if (parent === current) return current;
|
|
30065
30375
|
current = parent;
|
|
30066
30376
|
}
|
|
@@ -30069,7 +30379,7 @@ async function nearestExistingDirectory(start) {
|
|
|
30069
30379
|
// src/pipeline/audit.ts
|
|
30070
30380
|
import { readFile as readFile37 } from "fs/promises";
|
|
30071
30381
|
import { existsSync as existsSync45 } from "fs";
|
|
30072
|
-
import
|
|
30382
|
+
import path53 from "path";
|
|
30073
30383
|
function paletteDistance(asset, reference) {
|
|
30074
30384
|
if (!asset.length || !reference.length) return 0;
|
|
30075
30385
|
let total = 0;
|
|
@@ -30134,7 +30444,7 @@ async function auditStyle(loaded, specs, styleId, lock) {
|
|
|
30134
30444
|
let referenceFromStyleImages = false;
|
|
30135
30445
|
const refPalettes = [];
|
|
30136
30446
|
for (const img of style.styleImages) {
|
|
30137
|
-
const abs =
|
|
30447
|
+
const abs = path53.resolve(loaded.root, img.path);
|
|
30138
30448
|
if (!existsSync45(abs)) continue;
|
|
30139
30449
|
try {
|
|
30140
30450
|
refPalettes.push(extractPalette(decodePng(await readFile37(abs)), 12));
|
|
@@ -30392,24 +30702,24 @@ async function runHash(args) {
|
|
|
30392
30702
|
}
|
|
30393
30703
|
|
|
30394
30704
|
// src/cli/commands/pack.ts
|
|
30395
|
-
import
|
|
30705
|
+
import path55 from "path";
|
|
30396
30706
|
import { readFile as readFile38 } from "fs/promises";
|
|
30397
30707
|
|
|
30398
30708
|
// src/pipeline/pack.ts
|
|
30399
30709
|
import { readFileSync as readFileSync8 } from "fs";
|
|
30400
|
-
import
|
|
30710
|
+
import path54 from "path";
|
|
30401
30711
|
var DEFAULT_FRAME_SET_FPS = 12;
|
|
30402
30712
|
function resolvePackInputs(raw, inputsFilePath) {
|
|
30403
30713
|
if (!Array.isArray(raw) || !raw.length) {
|
|
30404
30714
|
throw new Error("--inputs must be a non-empty JSON array of { id, path }");
|
|
30405
30715
|
}
|
|
30406
|
-
const baseDir =
|
|
30716
|
+
const baseDir = path54.dirname(path54.resolve(inputsFilePath));
|
|
30407
30717
|
return raw.map((entry, i) => {
|
|
30408
30718
|
const e = entry;
|
|
30409
30719
|
if (typeof e.id !== "string" || typeof e.path !== "string") {
|
|
30410
30720
|
throw new Error(`--inputs[${i}] needs string "id" and "path"`);
|
|
30411
30721
|
}
|
|
30412
|
-
return { id: e.id, path:
|
|
30722
|
+
return { id: e.id, path: path54.resolve(baseDir, e.path) };
|
|
30413
30723
|
});
|
|
30414
30724
|
}
|
|
30415
30725
|
function packSprites(inputs, options = {}) {
|
|
@@ -30493,7 +30803,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
30493
30803
|
}
|
|
30494
30804
|
const inputs2 = Object.entries(options.sourceOverrides).map(([id, source]) => ({
|
|
30495
30805
|
id,
|
|
30496
|
-
path:
|
|
30806
|
+
path: path54.resolve(source)
|
|
30497
30807
|
}));
|
|
30498
30808
|
if (!inputs2.length) throw new Error(`No approved quality outputs for style "${styleId}".`);
|
|
30499
30809
|
const packed2 = packSprites(inputs2, options);
|
|
@@ -30525,7 +30835,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
30525
30835
|
let outputs = resolveEntryOutputs(entry, id, manifestDir);
|
|
30526
30836
|
const source = sources[id];
|
|
30527
30837
|
if (source && outputs.length <= 1) {
|
|
30528
|
-
inputs.push({ id, path:
|
|
30838
|
+
inputs.push({ id, path: path54.resolve(manifestDir, source) });
|
|
30529
30839
|
continue;
|
|
30530
30840
|
}
|
|
30531
30841
|
if (source && sourceIsStem(source, entry, manifestDir)) {
|
|
@@ -30562,7 +30872,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
30562
30872
|
}
|
|
30563
30873
|
}
|
|
30564
30874
|
for (const [id, source] of Object.entries(sources)) {
|
|
30565
|
-
if (!locked.has(id)) inputs.push({ id, path:
|
|
30875
|
+
if (!locked.has(id)) inputs.push({ id, path: path54.resolve(manifestDir, source) });
|
|
30566
30876
|
}
|
|
30567
30877
|
if (!inputs.length) {
|
|
30568
30878
|
throw new Error(`No readable sprites for style "${styleId}"; ${noOutput.length} skipped.`);
|
|
@@ -30697,7 +31007,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
30697
31007
|
const source = sources[id];
|
|
30698
31008
|
const entry = lock.entries[`${styleId}/${id}`];
|
|
30699
31009
|
if (source && !(entry && sourceIsStem(source, entry, manifestDir))) {
|
|
30700
|
-
placements.push({ id, path:
|
|
31010
|
+
placements.push({ id, path: path54.resolve(manifestDir, source), cell });
|
|
30701
31011
|
continue;
|
|
30702
31012
|
}
|
|
30703
31013
|
if (source && entry) {
|
|
@@ -30730,7 +31040,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
30730
31040
|
`Nothing to mount for style "${styleId}": ${ids.length} asset(s) declare a cell, but none has generated output or a \`source\`. Run \`pixelkiln gen --style ${styleId}\`, or point each at a file.${detail}`
|
|
30731
31041
|
);
|
|
30732
31042
|
}
|
|
30733
|
-
const basePng = mount.base ? readFileSync8(
|
|
31043
|
+
const basePng = mount.base ? readFileSync8(path54.resolve(manifestDir, mount.base)) : void 0;
|
|
30734
31044
|
const mounted = mountSprites(placements, {
|
|
30735
31045
|
cellWidth: mount.cellWidth,
|
|
30736
31046
|
cellHeight: mount.cellHeight,
|
|
@@ -30740,7 +31050,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
30740
31050
|
...mounted,
|
|
30741
31051
|
sources: mount.base ? [{
|
|
30742
31052
|
id: "$base",
|
|
30743
|
-
path:
|
|
31053
|
+
path: path54.resolve(manifestDir, mount.base),
|
|
30744
31054
|
sha256: sha256(basePng),
|
|
30745
31055
|
included: true
|
|
30746
31056
|
}, ...mounted.sources] : mounted.sources,
|
|
@@ -31917,12 +32227,12 @@ async function runPack(args) {
|
|
|
31917
32227
|
if (args.primaryOnly || args.outputRoles.length) {
|
|
31918
32228
|
throw new Error("--primary-only and --output-role require manifest-driven pack");
|
|
31919
32229
|
}
|
|
31920
|
-
const raw = JSON.parse(await readFile38(
|
|
32230
|
+
const raw = JSON.parse(await readFile38(path55.resolve(args.inputs), "utf8"));
|
|
31921
32231
|
const inputs = resolvePackInputs(raw, args.inputs);
|
|
31922
32232
|
const { png, atlas, skipped, sources } = packSprites(inputs, { columns: args.columns });
|
|
31923
32233
|
const format = sheetFormat(args);
|
|
31924
|
-
const base =
|
|
31925
|
-
const { extension, document } = renderSheetDocument(format, atlas, { imageName:
|
|
32234
|
+
const base = path55.resolve(args.out.replace(/\.(?:png|json|tres)$/i, ""));
|
|
32235
|
+
const { extension, document } = renderSheetDocument(format, atlas, { imageName: path55.basename(`${base}.png`) });
|
|
31926
32236
|
const outputs = [
|
|
31927
32237
|
{ path: `${base}.png`, data: png },
|
|
31928
32238
|
{ path: `${base}${extension}`, data: document }
|
|
@@ -31935,7 +32245,7 @@ async function runPack(args) {
|
|
|
31935
32245
|
log(
|
|
31936
32246
|
` ${atlas.frames.length} sprite(s), ${atlas.sheet.width}x${atlas.sheet.height} in ${atlas.columns} column(s), ${(png.length / 1024).toFixed(1)} KB (${format})`
|
|
31937
32247
|
);
|
|
31938
|
-
log(` ${
|
|
32248
|
+
log(` ${path55.relative(process.cwd(), base)}.png + ${extension} + .pixelkiln.json`);
|
|
31939
32249
|
for (const s of skipped) log(` skipped ${s.id}: ${s.reason}`);
|
|
31940
32250
|
return;
|
|
31941
32251
|
}
|
|
@@ -31943,7 +32253,7 @@ async function runPack(args) {
|
|
|
31943
32253
|
if (args.primaryOnly && args.outputRoles.length) {
|
|
31944
32254
|
throw new Error("pack accepts either --primary-only or --output-role, not both");
|
|
31945
32255
|
}
|
|
31946
|
-
const manifestDir =
|
|
32256
|
+
const manifestDir = path55.dirname(path55.resolve(args.manifest));
|
|
31947
32257
|
const styleIds = args.styles.length ? args.styles : Object.keys(loaded.manifest.styles);
|
|
31948
32258
|
for (const styleId of styleIds) {
|
|
31949
32259
|
const style = loaded.manifest.styles[styleId];
|
|
@@ -31958,9 +32268,9 @@ async function runPack(args) {
|
|
|
31958
32268
|
sourceOverrides: qualitySources,
|
|
31959
32269
|
sources: manifestSources(loaded.manifest, styleId)
|
|
31960
32270
|
});
|
|
31961
|
-
const base = args.out ?
|
|
32271
|
+
const base = args.out ? path55.resolve(args.out.replace(/\.(?:png|json|tres)$/i, "")) : path55.resolve(manifestDir, style.outDir, `${styleId}-sheet`);
|
|
31962
32272
|
const format = sheetFormat(args);
|
|
31963
|
-
const { extension, document } = renderSheetDocument(format, atlas, { imageName:
|
|
32273
|
+
const { extension, document } = renderSheetDocument(format, atlas, { imageName: path55.basename(`${base}.png`) });
|
|
31964
32274
|
const outputs = [
|
|
31965
32275
|
{ path: `${base}.png`, data: png },
|
|
31966
32276
|
{ path: `${base}${extension}`, data: document }
|
|
@@ -31992,13 +32302,13 @@ async function runPack(args) {
|
|
|
31992
32302
|
log(
|
|
31993
32303
|
` ${styleId}: ${atlas.frames.length} sprite(s), ${atlas.sheet.width}x${atlas.sheet.height} in ${atlas.columns} column(s)` + (atlas.sets?.length ? `, ${atlas.sets.length} set(s)` : "") + ` (${format})`
|
|
31994
32304
|
);
|
|
31995
|
-
log(` ${
|
|
32305
|
+
log(` ${path55.relative(process.cwd(), base)}.png + ${extension} + .pixelkiln.json`);
|
|
31996
32306
|
for (const s of skipped) log(` skipped ${s.id}: ${s.reason}`);
|
|
31997
32307
|
}
|
|
31998
32308
|
}
|
|
31999
32309
|
async function runMount(args) {
|
|
32000
32310
|
const { loaded, lock } = await openProject2(args);
|
|
32001
|
-
const manifestDir =
|
|
32311
|
+
const manifestDir = path55.dirname(path55.resolve(args.manifest));
|
|
32002
32312
|
const styleIds = args.styles.length ? args.styles : Object.keys(loaded.manifest.styles);
|
|
32003
32313
|
for (const styleId of styleIds) {
|
|
32004
32314
|
const style = loaded.manifest.styles[styleId];
|
|
@@ -32037,9 +32347,9 @@ async function runMount(args) {
|
|
|
32037
32347
|
sources,
|
|
32038
32348
|
outputRoles
|
|
32039
32349
|
);
|
|
32040
|
-
const out =
|
|
32350
|
+
const out = path55.resolve(manifestDir, style.mount.out);
|
|
32041
32351
|
const format = sheetFormat(args);
|
|
32042
|
-
const { extension, document } = renderSheetDocument(format, atlas, { imageName:
|
|
32352
|
+
const { extension, document } = renderSheetDocument(format, atlas, { imageName: path55.basename(out) });
|
|
32043
32353
|
const metadata = out.replace(/\.png$/, "") + extension;
|
|
32044
32354
|
const companion = out.replace(/\.png$/, "") + ".pixelkiln.json";
|
|
32045
32355
|
const outputs = [
|
|
@@ -32059,7 +32369,7 @@ async function runMount(args) {
|
|
|
32059
32369
|
await provenanceFile("$lock", args.lock),
|
|
32060
32370
|
...qualityRecords,
|
|
32061
32371
|
...artifactSources.filter(
|
|
32062
|
-
(source) => source.id !== "$base" ||
|
|
32372
|
+
(source) => source.id !== "$base" || path55.resolve(source.path) !== out
|
|
32063
32373
|
)
|
|
32064
32374
|
],
|
|
32065
32375
|
options: {
|
|
@@ -32073,14 +32383,14 @@ async function runMount(args) {
|
|
|
32073
32383
|
log(
|
|
32074
32384
|
` ${styleId}: ${atlas.frames.length} cell(s) into ${atlas.sheet.width}x${atlas.sheet.height}` + (overBase ? ` over ${style.mount.base}` : " (new sheet)")
|
|
32075
32385
|
);
|
|
32076
|
-
log(` ${
|
|
32386
|
+
log(` ${path55.relative(process.cwd(), out)} + atlas/provenance JSON`);
|
|
32077
32387
|
for (const s of skipped) log(` skipped ${s.id}: ${s.reason}`);
|
|
32078
32388
|
}
|
|
32079
32389
|
}
|
|
32080
32390
|
async function runExport(args) {
|
|
32081
32391
|
const { loaded, specs, lock } = await openProject2(args);
|
|
32082
32392
|
const format = args.format ?? "generic";
|
|
32083
|
-
const manifestDir =
|
|
32393
|
+
const manifestDir = path55.dirname(path55.resolve(args.manifest));
|
|
32084
32394
|
const selected = specs.filter((spec) => {
|
|
32085
32395
|
if (spec.generator !== "tiles" && spec.generator !== "terrain") return false;
|
|
32086
32396
|
if (args.styles.length && !args.styles.includes(spec.styleId)) return false;
|
|
@@ -32120,12 +32430,12 @@ async function runExport(args) {
|
|
|
32120
32430
|
const merged = group.length > 1;
|
|
32121
32431
|
const style = loaded.manifest.styles[spec.styleId];
|
|
32122
32432
|
const assetName = group.map((member) => member.assetId).join("-");
|
|
32123
|
-
const defaultBase =
|
|
32124
|
-
const base = args.out ?
|
|
32433
|
+
const defaultBase = path55.resolve(manifestDir, style.outDir, `${assetName}-tileset`);
|
|
32434
|
+
const base = args.out ? path55.resolve(args.out.replace(/\.(?:png|json|tsj|tres|ldtk)$/i, "")) : defaultBase;
|
|
32125
32435
|
const exportOptions = {
|
|
32126
32436
|
format,
|
|
32127
32437
|
manifestDir,
|
|
32128
|
-
imageName:
|
|
32438
|
+
imageName: path55.basename(`${base}.png`),
|
|
32129
32439
|
columns: args.columns
|
|
32130
32440
|
};
|
|
32131
32441
|
const result = merged ? exportMergedTilesets(
|
|
@@ -32147,7 +32457,7 @@ async function runExport(args) {
|
|
|
32147
32457
|
asset: result.generic.asset,
|
|
32148
32458
|
columns: args.columns ?? null,
|
|
32149
32459
|
format,
|
|
32150
|
-
image:
|
|
32460
|
+
image: path55.basename(`${base}.png`),
|
|
32151
32461
|
providerRules: result.generic.providerRules,
|
|
32152
32462
|
...merged ? { sets: result.generic.sets } : {},
|
|
32153
32463
|
style: spec.styleId,
|
|
@@ -32158,7 +32468,7 @@ async function runExport(args) {
|
|
|
32158
32468
|
` ${spec.styleId}/${merged ? group.map((member) => member.assetId).join(" + ") : spec.assetId}: ${result.generic.tiles.length} tile(s), ` + (merged ? `${result.generic.rules.terrains.length} terrains (${result.generic.rules.terrains.join(", ")}), ` : "") + `${result.generic.sheet.width}x${result.generic.sheet.height} (${format})`
|
|
32159
32469
|
);
|
|
32160
32470
|
log(
|
|
32161
|
-
` ${
|
|
32471
|
+
` ${path55.relative(process.cwd(), base)}.png + ${path55.basename(base)}${result.extension} + .pixelkiln.json`
|
|
32162
32472
|
);
|
|
32163
32473
|
for (const warning of result.warnings) log(` warning: ${warning}`);
|
|
32164
32474
|
}
|
|
@@ -32173,21 +32483,21 @@ function sheetFormat(args) {
|
|
|
32173
32483
|
|
|
32174
32484
|
// src/cli/commands/pixellab-utils.ts
|
|
32175
32485
|
import { readFile as readFile41 } from "fs/promises";
|
|
32176
|
-
import
|
|
32486
|
+
import path59 from "path";
|
|
32177
32487
|
|
|
32178
32488
|
// src/codex-vfx.ts
|
|
32179
32489
|
import { createHash as createHash8 } from "crypto";
|
|
32180
32490
|
import { existsSync as existsSync47, readFileSync as readFileSync9, readdirSync as readdirSync2 } from "fs";
|
|
32181
32491
|
import { readFile as readFile39 } from "fs/promises";
|
|
32182
32492
|
import { createRequire as createRequire2 } from "module";
|
|
32183
|
-
import
|
|
32493
|
+
import path57 from "path";
|
|
32184
32494
|
import { pathToFileURL } from "url";
|
|
32185
32495
|
import vm from "vm";
|
|
32186
32496
|
|
|
32187
32497
|
// src/local-vfx.ts
|
|
32188
32498
|
import { existsSync as existsSync46 } from "fs";
|
|
32189
|
-
import { mkdir as
|
|
32190
|
-
import
|
|
32499
|
+
import { mkdir as mkdir21, writeFile as writeFile26 } from "fs/promises";
|
|
32500
|
+
import path56 from "path";
|
|
32191
32501
|
function localSheet(render) {
|
|
32192
32502
|
const { width, height, frames } = render;
|
|
32193
32503
|
const columns = Math.min(frames.length, Math.max(1, Math.ceil(Math.sqrt(frames.length * height / width))));
|
|
@@ -32215,7 +32525,7 @@ function assertFreshOutputs(out, force) {
|
|
|
32215
32525
|
async function writeLocalVfx(opts) {
|
|
32216
32526
|
const { paths, render } = opts;
|
|
32217
32527
|
const sheet = localSheet(render);
|
|
32218
|
-
const clip =
|
|
32528
|
+
const clip = path56.basename(paths.sheet, ".png");
|
|
32219
32529
|
const anchor = { kind: "origin", ...render.anchor };
|
|
32220
32530
|
const size = { w: render.width, h: render.height };
|
|
32221
32531
|
const atlas = {
|
|
@@ -32231,7 +32541,7 @@ async function writeLocalVfx(opts) {
|
|
|
32231
32541
|
meta: {
|
|
32232
32542
|
app: "pixelkiln",
|
|
32233
32543
|
version: "1",
|
|
32234
|
-
image:
|
|
32544
|
+
image: path56.basename(paths.sheet),
|
|
32235
32545
|
format: "RGBA8888",
|
|
32236
32546
|
size: { w: sheet.columns * render.width, h: sheet.rows * render.height },
|
|
32237
32547
|
scale: "1",
|
|
@@ -32265,16 +32575,16 @@ async function writeLocalVfx(opts) {
|
|
|
32265
32575
|
version: 1,
|
|
32266
32576
|
...opts.record,
|
|
32267
32577
|
...facts,
|
|
32268
|
-
files: { sheet:
|
|
32578
|
+
files: { sheet: path56.basename(paths.sheet), atlas: path56.basename(paths.atlas) },
|
|
32269
32579
|
sheetSha256,
|
|
32270
32580
|
exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
32271
32581
|
recipe: opts.recipe
|
|
32272
32582
|
};
|
|
32273
|
-
await
|
|
32274
|
-
await
|
|
32275
|
-
await
|
|
32583
|
+
await mkdir21(path56.dirname(paths.sheet), { recursive: true });
|
|
32584
|
+
await writeFile26(paths.sheet, sheet.png);
|
|
32585
|
+
await writeFile26(paths.atlas, `${JSON.stringify(atlas, null, 2)}
|
|
32276
32586
|
`);
|
|
32277
|
-
await
|
|
32587
|
+
await writeFile26(paths.provenance, `${JSON.stringify(record, null, 2)}
|
|
32278
32588
|
`);
|
|
32279
32589
|
return { facts, columns: sheet.columns, sheetSha256, paths: { sheet: paths.sheet, atlas: paths.atlas, provenance: paths.provenance } };
|
|
32280
32590
|
}
|
|
@@ -32295,14 +32605,14 @@ function missingCodex(cause) {
|
|
|
32295
32605
|
);
|
|
32296
32606
|
}
|
|
32297
32607
|
function findCodexRoot(from) {
|
|
32298
|
-
const bases = from?.map((base) => pathToFileURL(
|
|
32299
|
-
pathToFileURL(
|
|
32608
|
+
const bases = from?.map((base) => pathToFileURL(path57.resolve(base, "package.json")).href) ?? [
|
|
32609
|
+
pathToFileURL(path57.join(process.cwd(), "package.json")).href,
|
|
32300
32610
|
import.meta.url
|
|
32301
32611
|
];
|
|
32302
32612
|
let failure;
|
|
32303
32613
|
for (const base of bases) {
|
|
32304
32614
|
try {
|
|
32305
|
-
return
|
|
32615
|
+
return path57.dirname(createRequire2(base).resolve(`${CODEX_PACKAGE}/package.json`));
|
|
32306
32616
|
} catch (error) {
|
|
32307
32617
|
failure = error;
|
|
32308
32618
|
}
|
|
@@ -32311,11 +32621,11 @@ function findCodexRoot(from) {
|
|
|
32311
32621
|
}
|
|
32312
32622
|
function loadCodex(from) {
|
|
32313
32623
|
const root = findCodexRoot(from);
|
|
32314
|
-
const read = (...parts) => readFileSync9(
|
|
32624
|
+
const read = (...parts) => readFileSync9(path57.join(root, ...parts), "utf8");
|
|
32315
32625
|
const pkg = JSON.parse(read("package.json"));
|
|
32316
32626
|
const version = typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
32317
32627
|
for (const required of ["engine/pxfx.js", "engine/kit.js", "fx", "data/meta.json"]) {
|
|
32318
|
-
if (!existsSync47(
|
|
32628
|
+
if (!existsSync47(path57.join(root, required))) {
|
|
32319
32629
|
throw new PixelKilnError(`The installed ${CODEX_PACKAGE} (${version}) has no ${required}; PixelKiln was written against its 1.0.0 layout`, "capability");
|
|
32320
32630
|
}
|
|
32321
32631
|
}
|
|
@@ -32327,7 +32637,7 @@ function loadCodex(from) {
|
|
|
32327
32637
|
throw new PixelKilnError(`The installed ${CODEX_PACKAGE} (${version}) does not define PXFX.View and PXFX.get`, "capability");
|
|
32328
32638
|
}
|
|
32329
32639
|
const loadErrors = [];
|
|
32330
|
-
for (const file of readdirSync2(
|
|
32640
|
+
for (const file of readdirSync2(path57.join(root, "fx")).filter((name) => name.endsWith(".js")).sort()) {
|
|
32331
32641
|
try {
|
|
32332
32642
|
vm.runInContext(read("fx", file), context, { filename: `fx/${file}` });
|
|
32333
32643
|
} catch (error) {
|
|
@@ -32547,7 +32857,7 @@ async function makeCodexVfx(lib, opts) {
|
|
|
32547
32857
|
import { existsSync as existsSync48, readFileSync as readFileSync10 } from "fs";
|
|
32548
32858
|
import { readFile as readFile40 } from "fs/promises";
|
|
32549
32859
|
import { createRequire as createRequire3 } from "module";
|
|
32550
|
-
import
|
|
32860
|
+
import path58 from "path";
|
|
32551
32861
|
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
32552
32862
|
var PIXELFX_TOOL = "pixelfx";
|
|
32553
32863
|
var PIXELFX_REPOSITORY = "https://github.com/patch-gg/pixelfx";
|
|
@@ -32560,8 +32870,8 @@ function missingPixelfx(cause) {
|
|
|
32560
32870
|
);
|
|
32561
32871
|
}
|
|
32562
32872
|
function pixelfxVersion(entry) {
|
|
32563
|
-
for (let dir =
|
|
32564
|
-
const file =
|
|
32873
|
+
for (let dir = path58.dirname(entry); dir !== path58.dirname(dir); dir = path58.dirname(dir)) {
|
|
32874
|
+
const file = path58.join(dir, "package.json");
|
|
32565
32875
|
if (!existsSync48(file)) continue;
|
|
32566
32876
|
const pkg = JSON.parse(readFileSync10(file, "utf8"));
|
|
32567
32877
|
if (pkg.name === "pixelfx") return typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
@@ -32569,8 +32879,8 @@ function pixelfxVersion(entry) {
|
|
|
32569
32879
|
return "unknown";
|
|
32570
32880
|
}
|
|
32571
32881
|
async function loadPixelfx(from) {
|
|
32572
|
-
const bases = from?.map((base) => pathToFileURL2(
|
|
32573
|
-
pathToFileURL2(
|
|
32882
|
+
const bases = from?.map((base) => pathToFileURL2(path58.resolve(base)).href) ?? [
|
|
32883
|
+
pathToFileURL2(path58.join(process.cwd(), "package.json")).href,
|
|
32574
32884
|
import.meta.url
|
|
32575
32885
|
];
|
|
32576
32886
|
let resolved;
|
|
@@ -32795,7 +33105,7 @@ async function makePixelfxVfx(lib, opts) {
|
|
|
32795
33105
|
|
|
32796
33106
|
// src/cli/commands/pixellab-utils.ts
|
|
32797
33107
|
function loadKeys(args) {
|
|
32798
|
-
loadEnvFiles(
|
|
33108
|
+
loadEnvFiles(path59.dirname(path59.resolve(args.manifest)));
|
|
32799
33109
|
loadEnvFiles(process.cwd());
|
|
32800
33110
|
}
|
|
32801
33111
|
async function runUnzoom(args) {
|
|
@@ -33051,7 +33361,7 @@ async function runVfx(args) {
|
|
|
33051
33361
|
const fromRecipe = args.recipe ? await readVfxRecipe(args.recipe) : void 0;
|
|
33052
33362
|
const sprite = args.sprite ?? fromRecipe?.sprite;
|
|
33053
33363
|
const recipeName = typeof fromRecipe?.recipe.name === "string" ? fromRecipe.recipe.name : void 0;
|
|
33054
|
-
const name = args.name ?? (args.effect ? void 0 : recipeName ?? args.preset ??
|
|
33364
|
+
const name = args.name ?? (args.effect ? void 0 : recipeName ?? args.preset ?? path59.basename(paths.sheet, ".png"));
|
|
33055
33365
|
const from = args.preset ? `preset ${args.preset}` : args.recipe ? `recipe ${args.recipe}` : args.effect ? `saved effect ${args.effect}` : "nothing";
|
|
33056
33366
|
log(
|
|
33057
33367
|
` vfx ${name ? `"${name}"` : "(keeping its saved name)"} from ${from}${args.parts.length ? ` + ${args.parts.join(", ")}` : ""}${sprite ? ` around ${sprite}` : ""} \u2192 ${paths.sheet} (+ .gif, .json, .vfx.json${args.gamePack ? ", -game.zip" : ""})`
|
|
@@ -33246,7 +33556,7 @@ async function runVfxArtist(args, out) {
|
|
|
33246
33556
|
);
|
|
33247
33557
|
if (args.effect) {
|
|
33248
33558
|
log(
|
|
33249
|
-
` changes saved effect ${args.effect} in place` + (conversation ? `, priced as a change (its conversation is in ${
|
|
33559
|
+
` changes saved effect ${args.effect} in place` + (conversation ? `, priced as a change (its conversation is in ${path59.basename(paths.provenance)})` : `; ${path59.basename(paths.provenance)} holds no conversation for it, so PixelLab prices it as a new effect`)
|
|
33250
33560
|
);
|
|
33251
33561
|
}
|
|
33252
33562
|
log(` cost: about ${quote} generations by PixelLab's table, billed on delivery; at most ${ceiling} if the effect runs long`);
|
|
@@ -33297,12 +33607,12 @@ async function runVfxArtist(args, out) {
|
|
|
33297
33607
|
|
|
33298
33608
|
// src/cli/commands/audio.ts
|
|
33299
33609
|
import { readFile as readFile42 } from "fs/promises";
|
|
33300
|
-
import
|
|
33610
|
+
import path61 from "path";
|
|
33301
33611
|
|
|
33302
33612
|
// src/pixellab-audio.ts
|
|
33303
33613
|
import { existsSync as existsSync49 } from "fs";
|
|
33304
|
-
import { mkdir as
|
|
33305
|
-
import
|
|
33614
|
+
import { mkdir as mkdir22, writeFile as writeFile27 } from "fs/promises";
|
|
33615
|
+
import path60 from "path";
|
|
33306
33616
|
var MUSIC_COST_GENERATIONS = 10;
|
|
33307
33617
|
var MUSIC_LOOP_COST_GENERATIONS = 4;
|
|
33308
33618
|
var MUSIC_LOOP_MIN_BODY_SECONDS = 36;
|
|
@@ -33359,7 +33669,7 @@ async function billedUsage(client2, jobId) {
|
|
|
33359
33669
|
}
|
|
33360
33670
|
}
|
|
33361
33671
|
function musicOutputPaths(out) {
|
|
33362
|
-
const base =
|
|
33672
|
+
const base = path60.resolve(out.replace(/\.(music\.json|mp3)$/i, ""));
|
|
33363
33673
|
return {
|
|
33364
33674
|
takes: [`${base}.mp3`, `${base}.take2.mp3`],
|
|
33365
33675
|
loops: [`${base}.loop.mp3`, `${base}.loop.take2.mp3`],
|
|
@@ -33381,8 +33691,8 @@ async function collectTakes(client2, songs, files, what, opts) {
|
|
|
33381
33691
|
if (!song.audio_url) throw new Error(`PixelLab ${what} ${song.id} completed without an audio URL`);
|
|
33382
33692
|
const bytes = await client2.download(song.audio_url);
|
|
33383
33693
|
validateAudio(bytes, "mp3");
|
|
33384
|
-
await
|
|
33385
|
-
await
|
|
33694
|
+
await mkdir22(path60.dirname(file), { recursive: true });
|
|
33695
|
+
await writeFile27(file, bytes);
|
|
33386
33696
|
finished.push(song);
|
|
33387
33697
|
takes.push({
|
|
33388
33698
|
songId: song.id,
|
|
@@ -33447,10 +33757,10 @@ async function generateMusic(client2, opts) {
|
|
|
33447
33757
|
quotedGenerations: quoted,
|
|
33448
33758
|
usage: usage2
|
|
33449
33759
|
});
|
|
33450
|
-
const relative = (take) => ({ ...take, file:
|
|
33760
|
+
const relative = (take) => ({ ...take, file: path60.basename(take.file) });
|
|
33451
33761
|
const writeRecord = async (result2) => {
|
|
33452
|
-
await
|
|
33453
|
-
await
|
|
33762
|
+
await mkdir22(path60.dirname(paths.record), { recursive: true });
|
|
33763
|
+
await writeFile27(
|
|
33454
33764
|
paths.record,
|
|
33455
33765
|
JSON.stringify(
|
|
33456
33766
|
{
|
|
@@ -33490,7 +33800,7 @@ async function generateMusic(client2, opts) {
|
|
|
33490
33800
|
submitted = await client2.loopMusic(loopSource);
|
|
33491
33801
|
} catch (error) {
|
|
33492
33802
|
const detail = refusalDetail(error);
|
|
33493
|
-
const kept = takes.length ? ` The song's takes are saved (${
|
|
33803
|
+
const kept = takes.length ? ` The song's takes are saved (${path60.basename(paths.record)}); nothing was charged for the loop.` : "";
|
|
33494
33804
|
throw new Error(`PixelLab refused to loop ${loopSource}: ${detail ?? (error instanceof Error ? error.message : String(error))}${kept}`, { cause: error });
|
|
33495
33805
|
}
|
|
33496
33806
|
quoted = (quoted ?? 0) + (submitted.quoted_generations ?? 0);
|
|
@@ -33504,7 +33814,7 @@ async function generateMusic(client2, opts) {
|
|
|
33504
33814
|
return result;
|
|
33505
33815
|
}
|
|
33506
33816
|
function soundEffectOutputPaths(out) {
|
|
33507
|
-
const base =
|
|
33817
|
+
const base = path60.resolve(out.replace(/\.(sfx\.json|wav)$/i, ""));
|
|
33508
33818
|
return { wav: `${base}.wav`, record: `${base}.sfx.json` };
|
|
33509
33819
|
}
|
|
33510
33820
|
async function generateSoundEffect(client2, opts) {
|
|
@@ -33519,8 +33829,8 @@ async function generateSoundEffect(client2, opts) {
|
|
|
33519
33829
|
if (!clip.audio_url) throw new Error(`PixelLab sound effect ${id} completed without an audio URL`);
|
|
33520
33830
|
const bytes = await client2.download(clip.audio_url);
|
|
33521
33831
|
validateAudio(bytes, "wav");
|
|
33522
|
-
await
|
|
33523
|
-
await
|
|
33832
|
+
await mkdir22(path60.dirname(wav), { recursive: true });
|
|
33833
|
+
await writeFile27(wav, bytes);
|
|
33524
33834
|
const result = {
|
|
33525
33835
|
soundEffectId: id,
|
|
33526
33836
|
file: wav,
|
|
@@ -33531,7 +33841,7 @@ async function generateSoundEffect(client2, opts) {
|
|
|
33531
33841
|
quotedGenerations: submitted.quoted_generations ?? null,
|
|
33532
33842
|
usage: await billedUsage(client2, submitted.background_job_id)
|
|
33533
33843
|
};
|
|
33534
|
-
await
|
|
33844
|
+
await writeFile27(
|
|
33535
33845
|
record,
|
|
33536
33846
|
JSON.stringify(
|
|
33537
33847
|
{
|
|
@@ -33542,7 +33852,7 @@ async function generateSoundEffect(client2, opts) {
|
|
|
33542
33852
|
prompt: opts.prompt,
|
|
33543
33853
|
seconds,
|
|
33544
33854
|
soundEffectId: id,
|
|
33545
|
-
file:
|
|
33855
|
+
file: path60.basename(wav),
|
|
33546
33856
|
sha256: result.sha256,
|
|
33547
33857
|
durationMs: result.durationMs,
|
|
33548
33858
|
quotedGenerations: result.quotedGenerations,
|
|
@@ -33557,7 +33867,7 @@ async function generateSoundEffect(client2, opts) {
|
|
|
33557
33867
|
|
|
33558
33868
|
// src/cli/commands/audio.ts
|
|
33559
33869
|
function loadKeys2(args) {
|
|
33560
|
-
loadEnvFiles(
|
|
33870
|
+
loadEnvFiles(path61.dirname(path61.resolve(args.manifest)));
|
|
33561
33871
|
loadEnvFiles(process.cwd());
|
|
33562
33872
|
}
|
|
33563
33873
|
function progress() {
|
|
@@ -33614,7 +33924,7 @@ async function runMusic(args) {
|
|
|
33614
33924
|
const cost = musicCost({ loop: args.loop, loopOf: args.loopOf });
|
|
33615
33925
|
const paths = musicOutputPaths(args.out);
|
|
33616
33926
|
const what = args.loopOf ? `loop of ${args.loopOf} (two loop takes)` : `"${args.description}"${vocals ? ", with vocals" : ", instrumental"}, two takes${args.loop ? " plus loops of take 1" : ""}`;
|
|
33617
|
-
log(` music: ${what} \u2192 ${
|
|
33927
|
+
log(` music: ${what} \u2192 ${path61.relative(process.cwd(), args.loopOf ? paths.loops[0] : paths.takes[0])} \u2026`);
|
|
33618
33928
|
log(` cost: ${cost} generations (PixelLab's published price)${args.improve ? ", plus about 0.05 for --improve" : ""}`);
|
|
33619
33929
|
if (args.budget !== void 0 && args.budget < cost) {
|
|
33620
33930
|
throw new Error(`--budget ${args.budget} is below this run's ${cost}-generation cost`);
|
|
@@ -33631,7 +33941,7 @@ async function runMusic(args) {
|
|
|
33631
33941
|
style = (await client2.improveMusicStyle({ style, instrumental: !vocals, bpm: args.bpm })).style;
|
|
33632
33942
|
log(` style: ${style}`);
|
|
33633
33943
|
}
|
|
33634
|
-
const lyrics = args.lyrics ? await readFile42(
|
|
33944
|
+
const lyrics = args.lyrics ? await readFile42(path61.resolve(args.lyrics), "utf8") : void 0;
|
|
33635
33945
|
const res = await generateMusic(client2, {
|
|
33636
33946
|
style,
|
|
33637
33947
|
lyrics,
|
|
@@ -33667,7 +33977,7 @@ async function runSfx(args) {
|
|
|
33667
33977
|
const seconds = args.seconds ?? 2;
|
|
33668
33978
|
const cost = soundEffectCost(seconds);
|
|
33669
33979
|
const { wav } = soundEffectOutputPaths(args.out);
|
|
33670
|
-
log(` sfx: "${args.description}", ${seconds} s \u2192 ${
|
|
33980
|
+
log(` sfx: "${args.description}", ${seconds} s \u2192 ${path61.relative(process.cwd(), wav)}`);
|
|
33671
33981
|
log(` cost: ${cost} generation${cost === 1 ? "" : "s"} (PixelLab's published price, by length)`);
|
|
33672
33982
|
if (args.budget !== void 0 && args.budget < cost) {
|
|
33673
33983
|
throw new Error(`--budget ${args.budget} is below this clip's ${cost}-generation cost`);
|
|
@@ -33695,12 +34005,12 @@ async function runSfx(args) {
|
|
|
33695
34005
|
}
|
|
33696
34006
|
|
|
33697
34007
|
// src/cli/commands/ui.ts
|
|
33698
|
-
import
|
|
34008
|
+
import path63 from "path";
|
|
33699
34009
|
|
|
33700
34010
|
// src/pixellab-ui.ts
|
|
33701
34011
|
import { existsSync as existsSync50 } from "fs";
|
|
33702
|
-
import { mkdir as
|
|
33703
|
-
import
|
|
34012
|
+
import { mkdir as mkdir23, writeFile as writeFile28 } from "fs/promises";
|
|
34013
|
+
import path62 from "path";
|
|
33704
34014
|
var UI_STATES_COSTS = [10, 15, 25];
|
|
33705
34015
|
var UI_STATES_MAX_COST = 25;
|
|
33706
34016
|
var UI_STATES_MAX_ELEMENTS = 64;
|
|
@@ -33793,8 +34103,8 @@ async function pullUiAsset(client2, uiAssetId, opts) {
|
|
|
33793
34103
|
const asset = await client2.getUiAssetDetail(uiAssetId);
|
|
33794
34104
|
if (asset.status && asset.status !== "completed") throw new Error(`UI asset ${uiAssetId} is ${asset.status}; pull it once it is completed`);
|
|
33795
34105
|
if (!asset.image_url) throw new Error(`UI asset ${uiAssetId} has no image yet`);
|
|
33796
|
-
const dir =
|
|
33797
|
-
const record =
|
|
34106
|
+
const dir = path62.resolve(opts.out);
|
|
34107
|
+
const record = path62.join(dir, "ui.json");
|
|
33798
34108
|
const plan = [];
|
|
33799
34109
|
const insets = (part) => part.nine_slice ? { nineSlice: { left: part.nine_slice.left, right: part.nine_slice.right, top: part.nine_slice.top, bottom: part.nine_slice.bottom } } : {};
|
|
33800
34110
|
const taken = /* @__PURE__ */ new Set();
|
|
@@ -33842,7 +34152,7 @@ async function pullUiAsset(client2, uiAssetId, opts) {
|
|
|
33842
34152
|
}
|
|
33843
34153
|
if (kind === "element") addStates(asset, rootName, asset.states);
|
|
33844
34154
|
if (!opts.force) {
|
|
33845
|
-
for (const file of [record, ...plan.map((item) =>
|
|
34155
|
+
for (const file of [record, ...plan.map((item) => path62.join(dir, item.file))]) {
|
|
33846
34156
|
if (existsSync50(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
33847
34157
|
}
|
|
33848
34158
|
}
|
|
@@ -33850,12 +34160,12 @@ async function pullUiAsset(client2, uiAssetId, opts) {
|
|
|
33850
34160
|
for (const { url, ...item } of plan) {
|
|
33851
34161
|
const bytes = await client2.download(url);
|
|
33852
34162
|
validateMedia(bytes, MediaType.PNG);
|
|
33853
|
-
const target =
|
|
33854
|
-
await
|
|
33855
|
-
await
|
|
34163
|
+
const target = path62.join(dir, item.file);
|
|
34164
|
+
await mkdir23(path62.dirname(target), { recursive: true });
|
|
34165
|
+
await writeFile28(target, bytes);
|
|
33856
34166
|
files.push({ ...item, sha256: sha256(bytes) });
|
|
33857
34167
|
}
|
|
33858
|
-
await
|
|
34168
|
+
await writeFile28(
|
|
33859
34169
|
record,
|
|
33860
34170
|
JSON.stringify(
|
|
33861
34171
|
{
|
|
@@ -33877,7 +34187,7 @@ async function pullUiAsset(client2, uiAssetId, opts) {
|
|
|
33877
34187
|
|
|
33878
34188
|
// src/cli/commands/ui.ts
|
|
33879
34189
|
function loadKeys3(args) {
|
|
33880
|
-
loadEnvFiles(
|
|
34190
|
+
loadEnvFiles(path63.dirname(path63.resolve(args.manifest)));
|
|
33881
34191
|
loadEnvFiles(process.cwd());
|
|
33882
34192
|
}
|
|
33883
34193
|
function requireId(args) {
|
|
@@ -33991,18 +34301,18 @@ async function runUi(args) {
|
|
|
33991
34301
|
log(JSON.stringify({ version: 1, ...res }, null, 2));
|
|
33992
34302
|
return;
|
|
33993
34303
|
}
|
|
33994
|
-
for (const file of res.files) log(` wrote ${
|
|
33995
|
-
log(` wrote ${
|
|
34304
|
+
for (const file of res.files) log(` wrote ${path63.join(args.out, file.file)} (${file.kind}, ${file.size.width}x${file.size.height})`);
|
|
34305
|
+
log(` wrote ${path63.join(args.out, "ui.json")}`);
|
|
33996
34306
|
}
|
|
33997
34307
|
|
|
33998
34308
|
// src/cli/commands/asset.ts
|
|
33999
34309
|
import { readFile as readFile44 } from "fs/promises";
|
|
34000
|
-
import
|
|
34310
|
+
import path65 from "path";
|
|
34001
34311
|
|
|
34002
34312
|
// src/pixellab-assets.ts
|
|
34003
34313
|
import { existsSync as existsSync51 } from "fs";
|
|
34004
|
-
import { mkdir as
|
|
34005
|
-
import
|
|
34314
|
+
import { mkdir as mkdir24, readdir as readdir6, readFile as readFile43, stat as stat6, writeFile as writeFile29 } from "fs/promises";
|
|
34315
|
+
import path64 from "path";
|
|
34006
34316
|
var ASSET_KINDS = ["object", "character"];
|
|
34007
34317
|
var EXPORT_FORMATS = ["zip", "spritesheet", "aseprite", "gif"];
|
|
34008
34318
|
var MIRROR_DIRECTIONS = ["east", "west", "south-east", "south-west", "north-east", "north-west"];
|
|
@@ -34022,7 +34332,7 @@ function parseCanvasSize(text, kind) {
|
|
|
34022
34332
|
}
|
|
34023
34333
|
function exportOutPath(out, format) {
|
|
34024
34334
|
const extension = format === "aseprite" ? ".aseprite" : format === "gif" ? ".gif" : ".zip";
|
|
34025
|
-
return
|
|
34335
|
+
return path64.extname(out) ? path64.resolve(out) : path64.resolve(`${out}${extension}`);
|
|
34026
34336
|
}
|
|
34027
34337
|
function checkExportBytes(bytes, format) {
|
|
34028
34338
|
const ok = format === "gif" ? bytes.subarray(0, 4).toString("ascii") === "GIF8" : format === "aseprite" ? bytes.length > 6 && bytes.readUInt16LE(4) === 42464 : bytes.subarray(0, 2).toString("ascii") === "PK";
|
|
@@ -34033,8 +34343,8 @@ async function exportAssetFile(client2, kind, id, format, opts) {
|
|
|
34033
34343
|
if (existsSync51(out) && !opts.force) throw new Error(`${out} already exists; pass --force to replace it`);
|
|
34034
34344
|
const bytes = await client2.exportAsset(kind, id, format, { animationGroupId: opts.animationGroupId, direction: opts.direction });
|
|
34035
34345
|
checkExportBytes(bytes, format);
|
|
34036
|
-
await
|
|
34037
|
-
await
|
|
34346
|
+
await mkdir24(path64.dirname(out), { recursive: true });
|
|
34347
|
+
await writeFile29(out, bytes);
|
|
34038
34348
|
return { out, bytes: bytes.length };
|
|
34039
34349
|
}
|
|
34040
34350
|
async function importObjectFile(client2, file, opts = {}) {
|
|
@@ -34080,17 +34390,17 @@ async function pullExpansionReview(client2, id, opts) {
|
|
|
34080
34390
|
if (object.status !== "review-expansion" || !review?.rotation_urls) {
|
|
34081
34391
|
throw new Error(`object ${id} is ${object.status ?? "unknown"}; there is no expansion waiting for review`);
|
|
34082
34392
|
}
|
|
34083
|
-
const dir =
|
|
34393
|
+
const dir = path64.resolve(opts.out);
|
|
34084
34394
|
const entries = Object.entries(review.rotation_urls).filter((entry) => typeof entry[1] === "string");
|
|
34085
|
-
const files = entries.map(([direction]) => ({ direction, file:
|
|
34395
|
+
const files = entries.map(([direction]) => ({ direction, file: path64.join(dir, `${direction}.png`) }));
|
|
34086
34396
|
if (!opts.force) {
|
|
34087
34397
|
for (const { file } of files) if (existsSync51(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
34088
34398
|
}
|
|
34089
|
-
await
|
|
34399
|
+
await mkdir24(dir, { recursive: true });
|
|
34090
34400
|
for (const [index, [, url]] of entries.entries()) {
|
|
34091
34401
|
const bytes = await client2.download(url);
|
|
34092
34402
|
validateMedia(bytes, MediaType.PNG);
|
|
34093
|
-
await
|
|
34403
|
+
await writeFile29(files[index].file, bytes);
|
|
34094
34404
|
}
|
|
34095
34405
|
return { dir, existingDirection: review.existing_direction ?? null, files };
|
|
34096
34406
|
}
|
|
@@ -34153,7 +34463,7 @@ async function pngFilesAt(from) {
|
|
|
34153
34463
|
if (!(await stat6(from)).isDirectory()) return [from];
|
|
34154
34464
|
const names = (await readdir6(from)).filter((name) => /\.png$/i.test(name)).sort((a, b) => a.localeCompare(b, void 0, { numeric: true }));
|
|
34155
34465
|
if (names.length === 0) throw new Error(`${from} holds no PNG files`);
|
|
34156
|
-
return names.map((name) =>
|
|
34466
|
+
return names.map((name) => path64.join(from, name));
|
|
34157
34467
|
}
|
|
34158
34468
|
function importTileHeights(tileType, tileSize) {
|
|
34159
34469
|
if (tileType === "square_topdown" || tileType === "octagon") return { min: tileSize, max: tileSize };
|
|
@@ -34188,14 +34498,14 @@ function checkSaveTarget(target) {
|
|
|
34188
34498
|
}
|
|
34189
34499
|
function saveUndoDir(target, now = /* @__PURE__ */ new Date()) {
|
|
34190
34500
|
const stamp = now.toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z");
|
|
34191
|
-
return
|
|
34501
|
+
return path64.resolve("pixelkiln-undo", `${target.replace(/[^a-zA-Z0-9-]+/g, "_")}-${stamp}`);
|
|
34192
34502
|
}
|
|
34193
34503
|
async function writeUndo(frames, dir) {
|
|
34194
|
-
await
|
|
34504
|
+
await mkdir24(dir, { recursive: true });
|
|
34195
34505
|
const files = [];
|
|
34196
34506
|
for (const [index, frame] of frames.entries()) {
|
|
34197
|
-
const file =
|
|
34198
|
-
await
|
|
34507
|
+
const file = path64.join(dir, frames.length === 1 ? "previous.png" : `previous-${String(index).padStart(2, "0")}.png`);
|
|
34508
|
+
await writeFile29(file, Buffer.from(frame.base64, "base64"));
|
|
34199
34509
|
files.push(file);
|
|
34200
34510
|
}
|
|
34201
34511
|
return files;
|
|
@@ -34226,7 +34536,7 @@ async function saveToAssetFile(client2, target, from, opts = {}) {
|
|
|
34226
34536
|
frames.push({ base64: bytes.toString("base64"), format: "png" });
|
|
34227
34537
|
}
|
|
34228
34538
|
}
|
|
34229
|
-
const undoDir = opts.undoDir ?
|
|
34539
|
+
const undoDir = opts.undoDir ? path64.resolve(opts.undoDir) : saveUndoDir(target);
|
|
34230
34540
|
let res;
|
|
34231
34541
|
try {
|
|
34232
34542
|
res = await client2.saveToAsset({ target, image, frames, name: opts.name, description: opts.description });
|
|
@@ -34262,7 +34572,7 @@ async function saveToAssetFile(client2, target, from, opts = {}) {
|
|
|
34262
34572
|
|
|
34263
34573
|
// src/cli/commands/asset.ts
|
|
34264
34574
|
function loadKeys4(args) {
|
|
34265
|
-
loadEnvFiles(
|
|
34575
|
+
loadEnvFiles(path65.dirname(path65.resolve(args.manifest)));
|
|
34266
34576
|
loadEnvFiles(process.cwd());
|
|
34267
34577
|
}
|
|
34268
34578
|
function kindOf(args) {
|
|
@@ -34383,7 +34693,7 @@ async function runAsset(args) {
|
|
|
34383
34693
|
const res2 = await pullExpansionReview(clientFromEnv(), id, { out: args.out, force: args.force });
|
|
34384
34694
|
if (args.json) emit(res2);
|
|
34385
34695
|
else {
|
|
34386
|
-
for (const file of res2.files) log(` wrote ${
|
|
34696
|
+
for (const file of res2.files) log(` wrote ${path65.join(args.out, `${file.direction}.png`)}${file.direction === res2.existingDirection ? " (your image, unchanged)" : ""}`);
|
|
34387
34697
|
log(` keep them: pixelkiln asset expand --id ${id} --keep discard: pixelkiln asset expand --id ${id} --discard`);
|
|
34388
34698
|
}
|
|
34389
34699
|
return;
|
|
@@ -34467,7 +34777,7 @@ async function runSave(args, emit) {
|
|
|
34467
34777
|
if (!args.from) throw new UsageError("asset save needs --from: a PNG, an animated GIF, or a directory of PNG frames");
|
|
34468
34778
|
await usage(() => checkSaveTarget(target));
|
|
34469
34779
|
const adding = target === "gallery:new";
|
|
34470
|
-
const undoDir = args.out ?
|
|
34780
|
+
const undoDir = args.out ? path65.resolve(args.out) : saveUndoDir(target);
|
|
34471
34781
|
if (adding) log(` add ${args.from} to your PixelLab gallery as a new image (free)`);
|
|
34472
34782
|
else {
|
|
34473
34783
|
log(` save ${args.from} over ${target} on PixelLab (free)`);
|
|
@@ -34490,7 +34800,7 @@ async function runSave(args, emit) {
|
|
|
34490
34800
|
else {
|
|
34491
34801
|
log(` ${res.target}: ${res.kind} saved, ${res.width}x${res.height}, ${res.frames} frame(s), ${res.changedPixels} pixel(s) changed`);
|
|
34492
34802
|
for (const file of res.undo) log(` kept the old pixels: ${file}`);
|
|
34493
|
-
if (res.undo.length) log(` undo: pixelkiln asset save --target ${res.target} --from ${res.undo.length === 1 ? res.undo[0] :
|
|
34803
|
+
if (res.undo.length) log(` undo: pixelkiln asset save --target ${res.target} --from ${res.undo.length === 1 ? res.undo[0] : path65.dirname(res.undo[0])} --yes`);
|
|
34494
34804
|
}
|
|
34495
34805
|
if (res.note) log(` ${res.note}`);
|
|
34496
34806
|
if (res.maps) log(` ${res.maps}`);
|
|
@@ -34498,13 +34808,13 @@ async function runSave(args, emit) {
|
|
|
34498
34808
|
|
|
34499
34809
|
// src/cli/commands/talk.ts
|
|
34500
34810
|
import { existsSync as existsSync53 } from "fs";
|
|
34501
|
-
import { mkdir as
|
|
34502
|
-
import
|
|
34811
|
+
import { mkdir as mkdir26, readFile as readFile46, writeFile as writeFile31 } from "fs/promises";
|
|
34812
|
+
import path67 from "path";
|
|
34503
34813
|
|
|
34504
34814
|
// src/pixellab-talk.ts
|
|
34505
34815
|
import { existsSync as existsSync52 } from "fs";
|
|
34506
|
-
import { mkdir as
|
|
34507
|
-
import
|
|
34816
|
+
import { mkdir as mkdir25, readFile as readFile45, writeFile as writeFile30 } from "fs/promises";
|
|
34817
|
+
import path66 from "path";
|
|
34508
34818
|
var TALK_MOODS = ["neutral", "happy", "angry", "sad", "surprised"];
|
|
34509
34819
|
var VISEME_COUNTS = [3, 5, 7, 12];
|
|
34510
34820
|
var VISEME_ENGINES = ["v3", "pixminimax"];
|
|
@@ -34515,7 +34825,7 @@ function visemeCost(engine, side, count) {
|
|
|
34515
34825
|
return Math.ceil(forSeven * count / 7);
|
|
34516
34826
|
}
|
|
34517
34827
|
function talkOutputPaths(out) {
|
|
34518
|
-
const base =
|
|
34828
|
+
const base = path66.resolve(out.replace(/\.(png|json)$/i, "").replace(/\.(talk|visemes)$/i, ""));
|
|
34519
34829
|
return { strip: `${base}.visemes.png`, record: `${base}.talk.json` };
|
|
34520
34830
|
}
|
|
34521
34831
|
function readPortrait(bytes, label) {
|
|
@@ -34609,8 +34919,8 @@ async function makeVisemes(client2, opts) {
|
|
|
34609
34919
|
throw new Error(`PixelLab vocal-animation job ${jobId} finished with no mouth positions and no spritesheet`);
|
|
34610
34920
|
}
|
|
34611
34921
|
const usage2 = (await client2.getBackgroundJob(jobId).catch(() => null))?.usage ?? job.usage ?? null;
|
|
34612
|
-
await
|
|
34613
|
-
await
|
|
34922
|
+
await mkdir25(path66.dirname(paths.strip), { recursive: true });
|
|
34923
|
+
await writeFile30(paths.strip, strip);
|
|
34614
34924
|
const record = {
|
|
34615
34925
|
version: 1,
|
|
34616
34926
|
provider: "pixellab",
|
|
@@ -34620,14 +34930,14 @@ async function makeVisemes(client2, opts) {
|
|
|
34620
34930
|
visemeCount,
|
|
34621
34931
|
visemeOrder,
|
|
34622
34932
|
cell,
|
|
34623
|
-
strip:
|
|
34624
|
-
source: opts.portrait ? { portrait:
|
|
34933
|
+
strip: path66.basename(paths.strip),
|
|
34934
|
+
source: opts.portrait ? { portrait: path66.relative(path66.dirname(paths.record), path66.resolve(opts.portrait)).split(path66.sep).join("/") } : { characterId: opts.characterId },
|
|
34625
34935
|
...job.moods_on_character ? { moodsOnCharacter: job.moods_on_character } : {},
|
|
34626
34936
|
jobId,
|
|
34627
34937
|
usage: usage2,
|
|
34628
34938
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
34629
34939
|
};
|
|
34630
|
-
await
|
|
34940
|
+
await writeFile30(paths.record, `${JSON.stringify(record, null, 2)}
|
|
34631
34941
|
`);
|
|
34632
34942
|
return { ...record, paths };
|
|
34633
34943
|
}
|
|
@@ -34641,7 +34951,7 @@ async function readTalkRecord(file) {
|
|
|
34641
34951
|
if (record?.tool !== "vocal-animation" || !Array.isArray(record.visemeOrder) || !record.cell || !record.strip) {
|
|
34642
34952
|
throw new Error(`${file} is not a .talk.json record from pixelkiln talk visemes`);
|
|
34643
34953
|
}
|
|
34644
|
-
const stripFile =
|
|
34954
|
+
const stripFile = path66.resolve(path66.dirname(path66.resolve(file)), record.strip);
|
|
34645
34955
|
if (!existsSync52(stripFile)) throw new Error(`${file} names ${record.strip}, which is missing beside it`);
|
|
34646
34956
|
const row = Math.max(0, record.moodsOnCharacter?.indexOf(record.mood) ?? 0);
|
|
34647
34957
|
const cells = cutStrip(await readFile45(stripFile), record.visemeOrder.length, record.cell, row);
|
|
@@ -34657,15 +34967,15 @@ function checkText(text) {
|
|
|
34657
34967
|
async function makeTalkingGif(client2, text, source, opts) {
|
|
34658
34968
|
if (Boolean(source.record) === Boolean(source.characterId)) throw new Error("give a .talk.json record or a character id, not both");
|
|
34659
34969
|
if (source.record && source.mood) throw new Error("a record holds one expression; --mood picks among a character's stored ones");
|
|
34660
|
-
const out =
|
|
34970
|
+
const out = path66.extname(opts.out) ? path66.resolve(opts.out) : path66.resolve(`${opts.out}.gif`);
|
|
34661
34971
|
if (existsSync52(out) && !opts.force) throw new Error(`${out} already exists; pass --force to replace it`);
|
|
34662
34972
|
const line = checkText(text);
|
|
34663
34973
|
const visemes = source.record ? (await readTalkRecord(source.record)).visemes : void 0;
|
|
34664
34974
|
const res = await client2.createTalkingGif({ text: line, visemes, characterId: source.characterId, mood: source.mood, frameMs: opts.frameMs, holdMs: opts.holdMs });
|
|
34665
34975
|
const bytes = Buffer.from(res.gif_base64, "base64");
|
|
34666
34976
|
if (bytes.subarray(0, 4).toString("ascii") !== "GIF8") throw new Error(`PixelLab's talking GIF was not a GIF (${bytes.length} bytes)`);
|
|
34667
|
-
await
|
|
34668
|
-
await
|
|
34977
|
+
await mkdir25(path66.dirname(out), { recursive: true });
|
|
34978
|
+
await writeFile30(out, bytes);
|
|
34669
34979
|
return { out, frames: res.frames, durationMs: res.duration_ms, frameMs: res.frame_ms, holdMs: res.hold_ms, width: res.width, height: res.height, bytes: bytes.length };
|
|
34670
34980
|
}
|
|
34671
34981
|
async function planLipSync(client2, text, source, opts = {}) {
|
|
@@ -34697,7 +35007,7 @@ async function planLipSync(client2, text, source, opts = {}) {
|
|
|
34697
35007
|
|
|
34698
35008
|
// src/cli/commands/talk.ts
|
|
34699
35009
|
function loadKeys5(args) {
|
|
34700
|
-
loadEnvFiles(
|
|
35010
|
+
loadEnvFiles(path67.dirname(path67.resolve(args.manifest)));
|
|
34701
35011
|
loadEnvFiles(process.cwd());
|
|
34702
35012
|
}
|
|
34703
35013
|
function moodOf(args) {
|
|
@@ -34820,10 +35130,10 @@ async function runPlan2(args) {
|
|
|
34820
35130
|
log(json2.trimEnd());
|
|
34821
35131
|
return;
|
|
34822
35132
|
}
|
|
34823
|
-
const out =
|
|
35133
|
+
const out = path67.extname(args.out) ? path67.resolve(args.out) : path67.resolve(`${args.out}.json`);
|
|
34824
35134
|
if (existsSync53(out) && !args.force) throw new Error(`${out} already exists; pass --force to replace it`);
|
|
34825
|
-
await
|
|
34826
|
-
await
|
|
35135
|
+
await mkdir26(path67.dirname(out), { recursive: true });
|
|
35136
|
+
await writeFile31(out, json2);
|
|
34827
35137
|
if (args.json) log(json2.trimEnd());
|
|
34828
35138
|
else log(` wrote ${out} (${plan.frames.length} frames, ${(plan.totalMs / 1e3).toFixed(2)} s, free)`);
|
|
34829
35139
|
}
|
|
@@ -34834,11 +35144,11 @@ async function runTalk(args) {
|
|
|
34834
35144
|
}
|
|
34835
35145
|
|
|
34836
35146
|
// src/cli/commands/quality.ts
|
|
34837
|
-
import
|
|
35147
|
+
import path69 from "path";
|
|
34838
35148
|
import { readFile as readFile48 } from "fs/promises";
|
|
34839
35149
|
|
|
34840
35150
|
// src/pipeline/quality-regression.ts
|
|
34841
|
-
import
|
|
35151
|
+
import path68 from "path";
|
|
34842
35152
|
import { existsSync as existsSync54 } from "fs";
|
|
34843
35153
|
import { readFile as readFile47 } from "fs/promises";
|
|
34844
35154
|
import { z as z17 } from "zod";
|
|
@@ -34846,7 +35156,7 @@ var SHA256_RE = /^[0-9a-f]{64}$/;
|
|
|
34846
35156
|
var HEX_RE = /^#[0-9a-f]{6}$/;
|
|
34847
35157
|
var MAX_REDMEAN_DISTANCE = 765;
|
|
34848
35158
|
var QualityPathSchema = z17.string().min(1).refine(
|
|
34849
|
-
(value) => !
|
|
35159
|
+
(value) => !path68.posix.isAbsolute(value) && !value.includes("\\"),
|
|
34850
35160
|
"expected a portable relative path"
|
|
34851
35161
|
);
|
|
34852
35162
|
var DEFAULT_QUALITY_TOLERANCES = {
|
|
@@ -34993,7 +35303,7 @@ function measureDecodedImageQuality(png, digest2) {
|
|
|
34993
35303
|
};
|
|
34994
35304
|
}
|
|
34995
35305
|
async function measureImageQuality(file) {
|
|
34996
|
-
const absolute =
|
|
35306
|
+
const absolute = path68.resolve(file);
|
|
34997
35307
|
let bytes;
|
|
34998
35308
|
try {
|
|
34999
35309
|
bytes = await readFile47(absolute);
|
|
@@ -35015,11 +35325,11 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
35015
35325
|
}
|
|
35016
35326
|
const ids = parsed.data.map((entry) => entry.id);
|
|
35017
35327
|
if (new Set(ids).size !== ids.length) throw new Error("--inputs contains a duplicate quality case id.");
|
|
35018
|
-
const root =
|
|
35328
|
+
const root = path68.dirname(path68.resolve(inputsFilePath));
|
|
35019
35329
|
return parsed.data.map((entry) => ({
|
|
35020
35330
|
id: entry.id,
|
|
35021
|
-
file:
|
|
35022
|
-
...entry.record ? { record:
|
|
35331
|
+
file: path68.resolve(root, entry.path),
|
|
35332
|
+
...entry.record ? { record: path68.resolve(root, entry.record) } : {},
|
|
35023
35333
|
tolerances: QualityToleranceSchema.parse({
|
|
35024
35334
|
...DEFAULT_QUALITY_TOLERANCES,
|
|
35025
35335
|
...entry.tolerances
|
|
@@ -35027,7 +35337,7 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
35027
35337
|
}));
|
|
35028
35338
|
}
|
|
35029
35339
|
function portableRelative2(from, to) {
|
|
35030
|
-
return
|
|
35340
|
+
return path68.relative(from, path68.resolve(to)).split(path68.sep).join("/") || ".";
|
|
35031
35341
|
}
|
|
35032
35342
|
async function verifyRecordForImage(recordPath, imagePath) {
|
|
35033
35343
|
const verification = await verifyArtifactBundle(recordPath);
|
|
@@ -35042,20 +35352,20 @@ async function verifyRecordForImage(recordPath, imagePath) {
|
|
|
35042
35352
|
if (record.kind !== "refine" || options === null || typeof options !== "object" || options.schema !== "pixelkiln-quality") {
|
|
35043
35353
|
throw new Error(`Quality record ${recordPath} is not a PixelKiln refinement record.`);
|
|
35044
35354
|
}
|
|
35045
|
-
const outputs = record.outputs.map((output) =>
|
|
35046
|
-
if (!outputs.includes(
|
|
35355
|
+
const outputs = record.outputs.map((output) => path68.resolve(path68.dirname(recordPath), output.path));
|
|
35356
|
+
if (!outputs.includes(path68.resolve(imagePath))) {
|
|
35047
35357
|
throw new Error(`Quality record ${recordPath} does not own ${imagePath}.`);
|
|
35048
35358
|
}
|
|
35049
35359
|
}
|
|
35050
35360
|
async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
35051
35361
|
if (!inputs.length) throw new Error("Cannot snapshot an empty quality baseline.");
|
|
35052
|
-
const absolute =
|
|
35362
|
+
const absolute = path68.resolve(baselinePath);
|
|
35053
35363
|
for (const input of inputs) {
|
|
35054
|
-
if (
|
|
35364
|
+
if (path68.resolve(input.file) === absolute || input.record && path68.resolve(input.record) === absolute) {
|
|
35055
35365
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
35056
35366
|
}
|
|
35057
35367
|
}
|
|
35058
|
-
const root =
|
|
35368
|
+
const root = path68.dirname(absolute);
|
|
35059
35369
|
const cases = [];
|
|
35060
35370
|
for (const input of [...inputs].sort((a, b) => a.id.localeCompare(b.id))) {
|
|
35061
35371
|
const expected = await measureImageQuality(input.file);
|
|
@@ -35095,7 +35405,7 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
35095
35405
|
return { baseline, path: absolute, changed: result.changed.length > 0 };
|
|
35096
35406
|
}
|
|
35097
35407
|
async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
35098
|
-
const absolute =
|
|
35408
|
+
const absolute = path68.resolve(baselinePath);
|
|
35099
35409
|
if (!existsSync54(absolute)) {
|
|
35100
35410
|
throw new Error(`quality snapshot --only updates an existing baseline; ${absolute} does not exist. Run a full snapshot first.`);
|
|
35101
35411
|
}
|
|
@@ -35111,12 +35421,12 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
35111
35421
|
if (unknown.length) {
|
|
35112
35422
|
throw new Error(`--only names ${unknown.join(", ")}, which the quality inputs do not list. Known: ${[...byId.keys()].sort().join(", ")}`);
|
|
35113
35423
|
}
|
|
35114
|
-
const root =
|
|
35424
|
+
const root = path68.dirname(absolute);
|
|
35115
35425
|
const cases = [...raw.cases];
|
|
35116
35426
|
const report = [];
|
|
35117
35427
|
for (const id of only) {
|
|
35118
35428
|
const input = byId.get(id);
|
|
35119
|
-
if (
|
|
35429
|
+
if (path68.resolve(input.file) === absolute || input.record && path68.resolve(input.record) === absolute) {
|
|
35120
35430
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
35121
35431
|
}
|
|
35122
35432
|
const expected = await measureImageQuality(input.file);
|
|
@@ -35152,7 +35462,7 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
35152
35462
|
return { baseline, path: absolute, changed, cases: report };
|
|
35153
35463
|
}
|
|
35154
35464
|
async function readQualityBaseline(baselinePath) {
|
|
35155
|
-
const absolute =
|
|
35465
|
+
const absolute = path68.resolve(baselinePath);
|
|
35156
35466
|
let raw;
|
|
35157
35467
|
try {
|
|
35158
35468
|
raw = JSON.parse(await readFile47(absolute, "utf8"));
|
|
@@ -35177,7 +35487,7 @@ async function readQualityBaseline(baselinePath) {
|
|
|
35177
35487
|
throw new Error(
|
|
35178
35488
|
`Invalid quality baseline ${absolute}:
|
|
35179
35489
|
` + parsed.error.issues.map((issue) => ` ${where(issue.path)}: ${issue.message}`).join("\n") + (missing.length ? `
|
|
35180
|
-
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${
|
|
35490
|
+
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${path68.basename(absolute)} --only ${missing.join(",")}\` rather than editing the JSON by hand.` : "")
|
|
35181
35491
|
);
|
|
35182
35492
|
}
|
|
35183
35493
|
return parsed.data;
|
|
@@ -35239,12 +35549,12 @@ function regressionViolations(expected, actual, tolerances) {
|
|
|
35239
35549
|
return { violations, warnings };
|
|
35240
35550
|
}
|
|
35241
35551
|
async function checkQualityBaseline(baselinePath) {
|
|
35242
|
-
const absolute =
|
|
35552
|
+
const absolute = path68.resolve(baselinePath);
|
|
35243
35553
|
const baseline = await readQualityBaseline(absolute);
|
|
35244
|
-
const root =
|
|
35554
|
+
const root = path68.dirname(absolute);
|
|
35245
35555
|
const cases = [];
|
|
35246
35556
|
for (const entry of baseline.cases) {
|
|
35247
|
-
const file =
|
|
35557
|
+
const file = path68.resolve(root, entry.file);
|
|
35248
35558
|
let actual = null;
|
|
35249
35559
|
const violations = [];
|
|
35250
35560
|
const warnings = [];
|
|
@@ -35257,7 +35567,7 @@ async function checkQualityBaseline(baselinePath) {
|
|
|
35257
35567
|
violations.push(message4(error));
|
|
35258
35568
|
}
|
|
35259
35569
|
if (entry.record) {
|
|
35260
|
-
const recordPath =
|
|
35570
|
+
const recordPath = path68.resolve(root, entry.record.path);
|
|
35261
35571
|
try {
|
|
35262
35572
|
const recordHash = await sha256File(recordPath);
|
|
35263
35573
|
if (recordHash !== entry.record.sha256) violations.push("quality record hash changed");
|
|
@@ -35299,15 +35609,15 @@ async function runQuality(args) {
|
|
|
35299
35609
|
if (!args.out) throw new Error("quality snapshot needs --out <pixelkiln.quality.json>.");
|
|
35300
35610
|
let raw;
|
|
35301
35611
|
try {
|
|
35302
|
-
raw = JSON.parse(await readFile48(
|
|
35612
|
+
raw = JSON.parse(await readFile48(path69.resolve(args.inputs), "utf8"));
|
|
35303
35613
|
} catch (error) {
|
|
35304
35614
|
throw new Error(
|
|
35305
|
-
`Could not read quality inputs ${
|
|
35615
|
+
`Could not read quality inputs ${path69.resolve(args.inputs)}: ${error instanceof Error ? error.message : String(error)}`,
|
|
35306
35616
|
{ cause: error }
|
|
35307
35617
|
);
|
|
35308
35618
|
}
|
|
35309
35619
|
const inputs = resolveQualityInputs(raw, args.inputs);
|
|
35310
|
-
if (
|
|
35620
|
+
if (path69.resolve(args.inputs) === path69.resolve(args.out)) {
|
|
35311
35621
|
throw new Error("quality snapshot --out must not overwrite its --inputs file.");
|
|
35312
35622
|
}
|
|
35313
35623
|
if (args.assets.length) {
|
|
@@ -35322,7 +35632,7 @@ async function runQuality(args) {
|
|
|
35322
35632
|
}
|
|
35323
35633
|
log(
|
|
35324
35634
|
`
|
|
35325
|
-
${result2.changed ? args.dryRun ? "would write" : "wrote" : "no changes to"} ${
|
|
35635
|
+
${result2.changed ? args.dryRun ? "would write" : "wrote" : "no changes to"} ${path69.relative(process.cwd(), result2.path)}; other cases left as they were.`
|
|
35326
35636
|
);
|
|
35327
35637
|
return;
|
|
35328
35638
|
}
|
|
@@ -35337,7 +35647,7 @@ async function runQuality(args) {
|
|
|
35337
35647
|
}, null, 2));
|
|
35338
35648
|
} else {
|
|
35339
35649
|
log(
|
|
35340
|
-
` ${result.changed ? "wrote" : "unchanged"} ${
|
|
35650
|
+
` ${result.changed ? "wrote" : "unchanged"} ${path69.relative(process.cwd(), result.path)} (${result.baseline.cases.length} case(s))`
|
|
35341
35651
|
);
|
|
35342
35652
|
log(` Review the tolerances, commit the baseline, then run quality check in CI.`);
|
|
35343
35653
|
}
|
|
@@ -35363,10 +35673,10 @@ async function runQuality(args) {
|
|
|
35363
35673
|
}
|
|
35364
35674
|
|
|
35365
35675
|
// src/cli/commands/recipe.ts
|
|
35366
|
-
import
|
|
35676
|
+
import path71 from "path";
|
|
35367
35677
|
|
|
35368
35678
|
// src/recipes.ts
|
|
35369
|
-
import
|
|
35679
|
+
import path70 from "path";
|
|
35370
35680
|
import { existsSync as existsSync55 } from "fs";
|
|
35371
35681
|
import { readdir as readdir7, readFile as readFile49 } from "fs/promises";
|
|
35372
35682
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
@@ -35377,7 +35687,7 @@ var VERSION_RE = /^\d+\.\d+\.\d+$/;
|
|
|
35377
35687
|
var RECIPE_FILE = "pixelkiln.recipe.json";
|
|
35378
35688
|
var RECIPE_DIR_TOKEN = "{{recipeDir}}";
|
|
35379
35689
|
var PortablePathSchema = z18.string().min(1).refine((value) => {
|
|
35380
|
-
if (value.includes("\\") ||
|
|
35690
|
+
if (value.includes("\\") || path70.posix.isAbsolute(value)) return false;
|
|
35381
35691
|
const parts = value.split("/");
|
|
35382
35692
|
return !parts.includes("") && !parts.includes(".") && !parts.includes("..");
|
|
35383
35693
|
}, "expected a portable relative path without '.', '..', or backslashes");
|
|
@@ -35574,7 +35884,7 @@ function message5(error) {
|
|
|
35574
35884
|
return error instanceof Error ? error.message : String(error);
|
|
35575
35885
|
}
|
|
35576
35886
|
async function readRecipeFile(recipePath, bundled) {
|
|
35577
|
-
const absolute =
|
|
35887
|
+
const absolute = path70.resolve(recipePath);
|
|
35578
35888
|
let raw;
|
|
35579
35889
|
try {
|
|
35580
35890
|
raw = JSON.parse(await readFile49(absolute, "utf8"));
|
|
@@ -35588,13 +35898,13 @@ async function readRecipeFile(recipePath, bundled) {
|
|
|
35588
35898
|
` + parsed.error.issues.map((issue) => ` ${issue.path.join(".") || "$"}: ${issue.message}`).join("\n")
|
|
35589
35899
|
);
|
|
35590
35900
|
}
|
|
35591
|
-
return { recipe: parsed.data, authored: raw, path: absolute, dir:
|
|
35901
|
+
return { recipe: parsed.data, authored: raw, path: absolute, dir: path70.dirname(absolute), bundled };
|
|
35592
35902
|
}
|
|
35593
35903
|
async function walkRecipeFiles(root) {
|
|
35594
35904
|
if (!existsSync55(root)) return [];
|
|
35595
35905
|
const out = [];
|
|
35596
35906
|
for (const entry of await readdir7(root, { withFileTypes: true })) {
|
|
35597
|
-
const resolved =
|
|
35907
|
+
const resolved = path70.join(root, entry.name);
|
|
35598
35908
|
if (entry.isDirectory()) out.push(...await walkRecipeFiles(resolved));
|
|
35599
35909
|
else if (entry.isFile() && entry.name === RECIPE_FILE) out.push(resolved);
|
|
35600
35910
|
}
|
|
@@ -35605,7 +35915,7 @@ function bundledRecipeRoot() {
|
|
|
35605
35915
|
}
|
|
35606
35916
|
async function listBundledRecipes(root = bundledRecipeRoot()) {
|
|
35607
35917
|
const recipes = await Promise.all(
|
|
35608
|
-
(await walkRecipeFiles(
|
|
35918
|
+
(await walkRecipeFiles(path70.resolve(root))).map((file) => readRecipeFile(file, true))
|
|
35609
35919
|
);
|
|
35610
35920
|
return recipes.sort(
|
|
35611
35921
|
(a, b) => a.recipe.id.localeCompare(b.recipe.id) || compareVersions(b.recipe.version, a.recipe.version)
|
|
@@ -35628,9 +35938,9 @@ function parseSelector(selector) {
|
|
|
35628
35938
|
return { id: match[1], version: match[2] };
|
|
35629
35939
|
}
|
|
35630
35940
|
async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
35631
|
-
const local =
|
|
35941
|
+
const local = path70.resolve(target);
|
|
35632
35942
|
if (existsSync55(local)) {
|
|
35633
|
-
const recipePath =
|
|
35943
|
+
const recipePath = path70.basename(local) === RECIPE_FILE ? local : path70.join(local, RECIPE_FILE);
|
|
35634
35944
|
return readRecipeFile(recipePath, false);
|
|
35635
35945
|
}
|
|
35636
35946
|
if (target.startsWith(".") || target.startsWith("/") || target.includes("\\")) {
|
|
@@ -35644,7 +35954,7 @@ async function resolveRecipe(target, bundledRoot = bundledRecipeRoot()) {
|
|
|
35644
35954
|
return matches[0];
|
|
35645
35955
|
}
|
|
35646
35956
|
async function verifyFile(root, file) {
|
|
35647
|
-
const absolute =
|
|
35957
|
+
const absolute = path70.resolve(root, ...file.path.split("/"));
|
|
35648
35958
|
if (!existsSync55(absolute)) {
|
|
35649
35959
|
return { path: file.path, expectedSha256: file.sha256, actualSha256: null, status: "missing" };
|
|
35650
35960
|
}
|
|
@@ -35660,7 +35970,7 @@ async function verifyRecipe(target, options = {}) {
|
|
|
35660
35970
|
const loaded = await resolveRecipe(target, options.bundledRoot);
|
|
35661
35971
|
const actualIntegrity = recipeDigest(loaded.authored);
|
|
35662
35972
|
const files = await Promise.all(loaded.recipe.files.map((file) => verifyFile(loaded.dir, file)));
|
|
35663
|
-
const modelRoot = options.modelRoot ?
|
|
35973
|
+
const modelRoot = options.modelRoot ? path70.resolve(options.modelRoot) : null;
|
|
35664
35974
|
const models = modelRoot ? await Promise.all(loaded.recipe.models.map(async (model) => ({
|
|
35665
35975
|
...await verifyFile(modelRoot, model),
|
|
35666
35976
|
source: model.source,
|
|
@@ -35694,7 +36004,7 @@ async function verifyRecipe(target, options = {}) {
|
|
|
35694
36004
|
};
|
|
35695
36005
|
}
|
|
35696
36006
|
function renderStyle(style, destination, cwd) {
|
|
35697
|
-
const portableDir =
|
|
36007
|
+
const portableDir = path70.relative(cwd, destination).split(path70.sep).join("/") || ".";
|
|
35698
36008
|
const replace = (value) => {
|
|
35699
36009
|
if (typeof value === "string") return value.replaceAll(RECIPE_DIR_TOKEN, portableDir);
|
|
35700
36010
|
if (Array.isArray(value)) return value.map(replace);
|
|
@@ -35706,19 +36016,19 @@ function renderStyle(style, destination, cwd) {
|
|
|
35706
36016
|
return replace(style);
|
|
35707
36017
|
}
|
|
35708
36018
|
async function installRecipe(target, options = {}) {
|
|
35709
|
-
const cwd =
|
|
36019
|
+
const cwd = path70.resolve(options.cwd ?? process.cwd());
|
|
35710
36020
|
const loaded = await resolveRecipe(target, options.bundledRoot);
|
|
35711
36021
|
const verification = await verifyRecipe(loaded.path);
|
|
35712
36022
|
if (!verification.ok) {
|
|
35713
36023
|
throw new Error(`Recipe ${loaded.recipe.id}@${loaded.recipe.version} failed integrity verification.`);
|
|
35714
36024
|
}
|
|
35715
|
-
const destination = options.out ?
|
|
36025
|
+
const destination = options.out ? path70.resolve(cwd, options.out) : path70.join(cwd, "pixelkiln-recipes", ...loaded.recipe.id.split("/"), loaded.recipe.version);
|
|
35716
36026
|
const sources = [
|
|
35717
36027
|
{ path: RECIPE_FILE, source: loaded.path },
|
|
35718
|
-
...loaded.recipe.files.map((file) => ({ path: file.path, source:
|
|
36028
|
+
...loaded.recipe.files.map((file) => ({ path: file.path, source: path70.join(loaded.dir, ...file.path.split("/")) }))
|
|
35719
36029
|
];
|
|
35720
36030
|
const files = await Promise.all(sources.map(async (file) => ({
|
|
35721
|
-
path:
|
|
36031
|
+
path: path70.join(destination, ...file.path.split("/")),
|
|
35722
36032
|
data: await readFile49(file.source)
|
|
35723
36033
|
})));
|
|
35724
36034
|
if (!options.force) {
|
|
@@ -35818,14 +36128,14 @@ async function runRecipe(args) {
|
|
|
35818
36128
|
}, null, 2));
|
|
35819
36129
|
} else {
|
|
35820
36130
|
log(` installed ${result.recipe.id}@${result.recipe.version}`);
|
|
35821
|
-
log(` ${
|
|
36131
|
+
log(` ${path71.relative(process.cwd(), result.destination) || "."}`);
|
|
35822
36132
|
log(`
|
|
35823
36133
|
Add this entry under your manifest's styles object:`);
|
|
35824
36134
|
log(JSON.stringify({ [result.styleId]: result.style }, null, 2));
|
|
35825
36135
|
if (result.recipe.models.length) {
|
|
35826
36136
|
log(`
|
|
35827
36137
|
Models are not downloaded automatically. Verify them with:`);
|
|
35828
|
-
log(` pixelkiln recipe verify ${
|
|
36138
|
+
log(` pixelkiln recipe verify ${path71.relative(process.cwd(), result.destination)} --model-root <ComfyUI/models>`);
|
|
35829
36139
|
}
|
|
35830
36140
|
}
|
|
35831
36141
|
return;
|
|
@@ -35833,7 +36143,7 @@ async function runRecipe(args) {
|
|
|
35833
36143
|
}
|
|
35834
36144
|
|
|
35835
36145
|
// src/cli/commands/refine.ts
|
|
35836
|
-
import
|
|
36146
|
+
import path72 from "path";
|
|
35837
36147
|
async function runRefine(args) {
|
|
35838
36148
|
if (args.from || args.subcommand === "approve") {
|
|
35839
36149
|
if (!args.from) {
|
|
@@ -35863,12 +36173,12 @@ async function runRefine(args) {
|
|
|
35863
36173
|
` recovered ${result3.detection.columns}x${result3.detection.rows} native grid (${result3.detection.confidence}: ${result3.detection.consensus})`
|
|
35864
36174
|
);
|
|
35865
36175
|
log(` enforced ${result3.palette.length}-color palette without dithering`);
|
|
35866
|
-
log(` wrote ${
|
|
35867
|
-
log(` quality record: ${
|
|
36176
|
+
log(` wrote ${path72.relative(process.cwd(), result3.output)}`);
|
|
36177
|
+
log(` quality record: ${path72.relative(process.cwd(), result3.record)}`);
|
|
35868
36178
|
log(`
|
|
35869
36179
|
Automated checks passed. Human 1\xD7 review is still required:`);
|
|
35870
36180
|
log(
|
|
35871
|
-
` pixelkiln refine approve --from ${
|
|
36181
|
+
` pixelkiln refine approve --from ${path72.relative(process.cwd(), result3.record)} --reviewer "Your Name"`
|
|
35872
36182
|
);
|
|
35873
36183
|
}
|
|
35874
36184
|
return;
|
|
@@ -35896,7 +36206,7 @@ async function runRefine(args) {
|
|
|
35896
36206
|
if (args.json) log(JSON.stringify(result3, null, 2));
|
|
35897
36207
|
else {
|
|
35898
36208
|
log(
|
|
35899
|
-
result3.options.frameSet ? ` approved ${result3.outputs.length} frames in ${
|
|
36209
|
+
result3.options.frameSet ? ` approved ${result3.outputs.length} frames in ${path72.relative(process.cwd(), result3.record)} by ${args.reviewer.trim()}` : ` approved ${path72.relative(process.cwd(), result3.output)} by ${args.reviewer.trim()}`
|
|
35900
36210
|
);
|
|
35901
36211
|
}
|
|
35902
36212
|
return;
|
|
@@ -35905,7 +36215,7 @@ async function runRefine(args) {
|
|
|
35905
36215
|
if (args.json) {
|
|
35906
36216
|
log(JSON.stringify(result2, null, 2));
|
|
35907
36217
|
} else {
|
|
35908
|
-
log(` ${result2.safe ? "release-ready" : "not release-ready"}: ${
|
|
36218
|
+
log(` ${result2.safe ? "release-ready" : "not release-ready"}: ${path72.relative(process.cwd(), result2.output || result2.record)}`);
|
|
35909
36219
|
for (const reason of result2.reasons) log(` ${reason}`);
|
|
35910
36220
|
}
|
|
35911
36221
|
if (!result2.safe) process.exitCode = 1;
|
|
@@ -35951,7 +36261,7 @@ async function runRefine(args) {
|
|
|
35951
36261
|
log(` ${item.state.padEnd(16)} ${item.key} ${item.reason}`);
|
|
35952
36262
|
if (item.state === "needs-approval") {
|
|
35953
36263
|
log(
|
|
35954
|
-
` pixelkiln refine approve --from ${
|
|
36264
|
+
` pixelkiln refine approve --from ${path72.relative(process.cwd(), item.record)} --reviewer "Your Name"`
|
|
35955
36265
|
);
|
|
35956
36266
|
}
|
|
35957
36267
|
}
|
|
@@ -35964,7 +36274,7 @@ async function runRefine(args) {
|
|
|
35964
36274
|
}
|
|
35965
36275
|
|
|
35966
36276
|
// src/cli/commands/anchors.ts
|
|
35967
|
-
import
|
|
36277
|
+
import path73 from "path";
|
|
35968
36278
|
async function runAnchors(args) {
|
|
35969
36279
|
const target = args.target;
|
|
35970
36280
|
const { specs, lock } = await openProject2(args);
|
|
@@ -35985,7 +36295,7 @@ async function runAnchors(args) {
|
|
|
35985
36295
|
dryRun: args.dryRun,
|
|
35986
36296
|
onProgress: log
|
|
35987
36297
|
});
|
|
35988
|
-
const file =
|
|
36298
|
+
const file = path73.relative(spec.root, result.file) || result.file;
|
|
35989
36299
|
if (args.dryRun) {
|
|
35990
36300
|
log(` ${result.estimated} frame${result.estimated === 1 ? "" : "s"} to estimate (about ${cost(result.estimated)}), ${result.current} already current`);
|
|
35991
36301
|
} else if (result.estimated) {
|
|
@@ -35997,12 +36307,12 @@ async function runAnchors(args) {
|
|
|
35997
36307
|
}
|
|
35998
36308
|
|
|
35999
36309
|
// src/cli/commands/parallax.ts
|
|
36000
|
-
import
|
|
36310
|
+
import path75 from "path";
|
|
36001
36311
|
|
|
36002
36312
|
// src/pipeline/parallax.ts
|
|
36003
36313
|
import { createHash as createHash9 } from "crypto";
|
|
36004
36314
|
import { readFile as readFile50 } from "fs/promises";
|
|
36005
|
-
import
|
|
36315
|
+
import path74 from "path";
|
|
36006
36316
|
var PARALLAX_FORMATS = ["tiled", "godot", "ldtk"];
|
|
36007
36317
|
var SEAM_WARN_RATIO = 2;
|
|
36008
36318
|
function layerFiles(layer) {
|
|
@@ -36071,7 +36381,7 @@ function seamRatio(png) {
|
|
|
36071
36381
|
}
|
|
36072
36382
|
function layerName(layer, index) {
|
|
36073
36383
|
if (layer.name) return layer.name;
|
|
36074
|
-
const base = layer.asset ?? (layer.file ?
|
|
36384
|
+
const base = layer.asset ?? (layer.file ? path74.basename(layer.file, path74.extname(layer.file)) : layer.run ? "run" : "sky");
|
|
36075
36385
|
const slug3 = base.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/^[^A-Za-z]+/, "");
|
|
36076
36386
|
return slug3 || `layer${index + 1}`;
|
|
36077
36387
|
}
|
|
@@ -36434,7 +36744,7 @@ function timeColours(set) {
|
|
|
36434
36744
|
}
|
|
36435
36745
|
async function readPicture(manifest, manifestDir, lock, setId, name, ref, warnings) {
|
|
36436
36746
|
if (ref.file) {
|
|
36437
|
-
const file2 =
|
|
36747
|
+
const file2 = path74.resolve(manifestDir, ref.file);
|
|
36438
36748
|
return { png: decodePng(await readFile50(file2)), source: { kind: "file", path: file2 } };
|
|
36439
36749
|
}
|
|
36440
36750
|
const assetId = ref.asset;
|
|
@@ -36443,7 +36753,7 @@ async function readPicture(manifest, manifestDir, lock, setId, name, ref, warnin
|
|
|
36443
36753
|
if (!entry) throw new Error(`parallax ${setId}: ${style}/${assetId} has not been generated; run gen first`);
|
|
36444
36754
|
const output = entry.outputs.find((candidate) => /\.png$/i.test(candidate.path)) ?? entry.outputs[0];
|
|
36445
36755
|
if (!output) throw new Error(`parallax ${setId}: ${style}/${assetId} has no output in the lockfile`);
|
|
36446
|
-
const file =
|
|
36756
|
+
const file = path74.resolve(manifestDir, output.path);
|
|
36447
36757
|
if (entry.outputs.length > 1) warnings.push(`${name}: ${style}/${assetId} has ${entry.outputs.length} outputs; using ${output.path}`);
|
|
36448
36758
|
return { png: decodePng(await readFile50(file)), source: { kind: "asset", style, asset: assetId, path: file } };
|
|
36449
36759
|
}
|
|
@@ -36559,7 +36869,7 @@ function cameraPath(set, frames) {
|
|
|
36559
36869
|
function layerPngs(set, base) {
|
|
36560
36870
|
return set.layers.map((layer) => ({
|
|
36561
36871
|
layer,
|
|
36562
|
-
file: `${
|
|
36872
|
+
file: `${path74.basename(base)}-${layer.name}.png`,
|
|
36563
36873
|
png: encodeRgbaPng(layer.png.width, layer.png.height, layer.png.pixels)
|
|
36564
36874
|
}));
|
|
36565
36875
|
}
|
|
@@ -36609,7 +36919,7 @@ function exportTiled(set, base) {
|
|
|
36609
36919
|
]
|
|
36610
36920
|
};
|
|
36611
36921
|
return {
|
|
36612
|
-
files: [{ path: `${base}.tmj`, data: JSON.stringify(map, null, 2) + "\n" }, ...pictures.map((p) => ({ path:
|
|
36922
|
+
files: [{ path: `${base}.tmj`, data: JSON.stringify(map, null, 2) + "\n" }, ...pictures.map((p) => ({ path: path74.join(path74.dirname(base), p.file), data: p.png }))],
|
|
36613
36923
|
options: { format: "tiled", start: [0, set.climb] }
|
|
36614
36924
|
};
|
|
36615
36925
|
}
|
|
@@ -36622,7 +36932,7 @@ function godotNumber(value) {
|
|
|
36622
36932
|
function exportGodot(set, base) {
|
|
36623
36933
|
const [vw, vh] = set.view;
|
|
36624
36934
|
const pictures = layerPngs(set, base);
|
|
36625
|
-
const name =
|
|
36935
|
+
const name = path74.basename(base);
|
|
36626
36936
|
const times = set.times ?? [];
|
|
36627
36937
|
const lines = [`[gd_scene load_steps=${pictures.length + 1 + (times.length ? 3 : 0)} format=3]`, ""];
|
|
36628
36938
|
pictures.forEach(({ file }, index) => {
|
|
@@ -36659,7 +36969,7 @@ function exportGodot(set, base) {
|
|
|
36659
36969
|
lines.push(`position = Vector2(${px}, ${py})`);
|
|
36660
36970
|
});
|
|
36661
36971
|
return {
|
|
36662
|
-
files: [{ path: `${base}.tscn`, data: lines.join("\n") + "\n" }, ...pictures.map((p) => ({ path:
|
|
36972
|
+
files: [{ path: `${base}.tscn`, data: lines.join("\n") + "\n" }, ...pictures.map((p) => ({ path: path74.join(path74.dirname(base), p.file), data: p.png })), ...extra],
|
|
36663
36973
|
options: { format: "godot", start: [0, set.climb], ...times.length ? { shader: `${name}.gdshader` } : {} }
|
|
36664
36974
|
};
|
|
36665
36975
|
}
|
|
@@ -36673,7 +36983,7 @@ function exportLdtk(set, base) {
|
|
|
36673
36983
|
const grid = LDTK_GRID;
|
|
36674
36984
|
const levelW = vw + set.travel;
|
|
36675
36985
|
const levelH = vh + set.climb;
|
|
36676
|
-
const name =
|
|
36986
|
+
const name = path74.basename(base);
|
|
36677
36987
|
const files = [];
|
|
36678
36988
|
const warnings = [];
|
|
36679
36989
|
const identifiers = /* @__PURE__ */ new Set();
|
|
@@ -36708,7 +37018,7 @@ function exportLdtk(set, base) {
|
|
|
36708
37018
|
const span = { width: cols * grid, height: rows * grid, pixels: Buffer.alloc(cols * grid * rows * grid * 4) };
|
|
36709
37019
|
drawLayer(span, layer, px.pad + layer.x - x0, py.pad + layer.y - y0);
|
|
36710
37020
|
const file = `${name}-${layer.name}.png`;
|
|
36711
|
-
files.push({ path:
|
|
37021
|
+
files.push({ path: path74.join(path74.dirname(base), file), data: encodeRgbaPng(span.width, span.height, span.pixels) });
|
|
36712
37022
|
const tilesetUid = uid++;
|
|
36713
37023
|
const layerUid = uid++;
|
|
36714
37024
|
let identifier2 = layer.name.replace(/[^A-Za-z0-9_]/g, "_");
|
|
@@ -36911,7 +37221,7 @@ function exportParallax(set, format, base) {
|
|
|
36911
37221
|
if (!warnings.includes(warning)) result.options.warnings = [...warnings, warning];
|
|
36912
37222
|
}
|
|
36913
37223
|
}
|
|
36914
|
-
result.options.maps = [
|
|
37224
|
+
result.options.maps = [path74.basename(result.files[0].path), ...set.times.map((t) => `${path74.basename(base)}.${t.name}${path74.extname(result.files[0].path)}`)];
|
|
36915
37225
|
return result;
|
|
36916
37226
|
}
|
|
36917
37227
|
var GODOT_TIMES_SHADER = `// Written by pixelkiln parallax export. Recolours the set to one of its times of day.
|
|
@@ -37038,7 +37348,7 @@ Promise.all(images.flat().map((image) => image.decode())).then(() => requestAnim
|
|
|
37038
37348
|
// src/cli/commands/parallax.ts
|
|
37039
37349
|
async function runParallax(args) {
|
|
37040
37350
|
const { loaded, lock } = await openProject2(args);
|
|
37041
|
-
const manifestDir =
|
|
37351
|
+
const manifestDir = path75.dirname(path75.resolve(args.manifest));
|
|
37042
37352
|
const ids = Object.keys(loaded.manifest.parallax ?? {});
|
|
37043
37353
|
if (!ids.length) throw new Error('The manifest has no parallax sets. Add one under "parallax"; see docs/PARALLAX.md.');
|
|
37044
37354
|
const wanted = args.target ? [args.target] : ids;
|
|
@@ -37047,7 +37357,7 @@ async function runParallax(args) {
|
|
|
37047
37357
|
}
|
|
37048
37358
|
for (const id of wanted) {
|
|
37049
37359
|
const set = await resolveParallaxSet(loaded.manifest, manifestDir, lock, id);
|
|
37050
|
-
const root =
|
|
37360
|
+
const root = path75.resolve(args.out ?? path75.join(manifestDir, "parallax", id));
|
|
37051
37361
|
const sources = [
|
|
37052
37362
|
await provenanceFile("$manifest", args.manifest),
|
|
37053
37363
|
await provenanceFile("$lock", args.lock),
|
|
@@ -37061,7 +37371,7 @@ async function runParallax(args) {
|
|
|
37061
37371
|
if (args.subcommand === "export") {
|
|
37062
37372
|
const formats = args.format ? [args.format] : [...PARALLAX_FORMATS];
|
|
37063
37373
|
for (const format of formats) {
|
|
37064
|
-
const base =
|
|
37374
|
+
const base = path75.join(root, format, id);
|
|
37065
37375
|
const result = exportParallax(set, format, base);
|
|
37066
37376
|
const outputs = result.files.map((file) => ({ path: file.path, data: typeof file.data === "string" ? Buffer.from(file.data) : file.data }));
|
|
37067
37377
|
await writeManagedArtifactBundle(`${base}.pixelkiln.json`, outputs, {
|
|
@@ -37069,7 +37379,7 @@ async function runParallax(args) {
|
|
|
37069
37379
|
sources,
|
|
37070
37380
|
options: { set: id, ...describe2, ...result.options }
|
|
37071
37381
|
}, { force: args.force });
|
|
37072
|
-
log(` ${id} (${format}): ${
|
|
37382
|
+
log(` ${id} (${format}): ${path75.relative(process.cwd(), result.files[0].path)} + ${result.files.length - 1} more file(s)`);
|
|
37073
37383
|
for (const warning of result.options.warnings ?? []) log(` warning: ${warning}`);
|
|
37074
37384
|
}
|
|
37075
37385
|
} else {
|
|
@@ -37080,7 +37390,7 @@ async function runParallax(args) {
|
|
|
37080
37390
|
return encodeRgbaPng(frame.width, frame.height, frame.pixels);
|
|
37081
37391
|
})
|
|
37082
37392
|
);
|
|
37083
|
-
const base =
|
|
37393
|
+
const base = path75.join(root, `${id}.preview`);
|
|
37084
37394
|
await writeManagedArtifactBundle(`${base}.pixelkiln.json`, [
|
|
37085
37395
|
{ path: `${base}.html`, data: Buffer.from(previewHtml(set)) },
|
|
37086
37396
|
{ path: `${base}.png`, data: strip(set) },
|
|
@@ -37091,8 +37401,8 @@ async function runParallax(args) {
|
|
|
37091
37401
|
sources,
|
|
37092
37402
|
options: { set: id, ...describe2, preview: { frames } }
|
|
37093
37403
|
}, { force: args.force });
|
|
37094
|
-
log(` ${id}: ${
|
|
37095
|
-
if (set.times?.length) log(` times: ${set.times.map((time) => `${time.name} (${
|
|
37404
|
+
log(` ${id}: ${path75.relative(process.cwd(), base)}.html (scrolls in a browser) + .png (${frames} frames, start to end)`);
|
|
37405
|
+
if (set.times?.length) log(` times: ${set.times.map((time) => `${time.name} (${path75.basename(base)}.${time.name}.png)`).join(", ")}`);
|
|
37096
37406
|
}
|
|
37097
37407
|
for (const layer of set.layers) {
|
|
37098
37408
|
const seam = (layer.seamRatio === void 0 ? "" : `, seam ${layer.seamRatio.toFixed(1)}`) + (layer.seamRatioY === void 0 ? "" : `, vertical seam ${layer.seamRatioY.toFixed(1)}`);
|
|
@@ -37125,12 +37435,12 @@ function setOptions(set) {
|
|
|
37125
37435
|
}
|
|
37126
37436
|
|
|
37127
37437
|
// src/cli/commands/redraw.ts
|
|
37128
|
-
import
|
|
37438
|
+
import path77 from "path";
|
|
37129
37439
|
|
|
37130
37440
|
// src/pipeline/redraw.ts
|
|
37131
37441
|
import { existsSync as existsSync56 } from "fs";
|
|
37132
|
-
import { mkdir as
|
|
37133
|
-
import
|
|
37442
|
+
import { mkdir as mkdir27, readFile as readFile51, rename as rename15, writeFile as writeFile32 } from "fs/promises";
|
|
37443
|
+
import path76 from "path";
|
|
37134
37444
|
function redrawRoles(spec, lock) {
|
|
37135
37445
|
return (lock.entries[lockKey(spec.styleId, spec.assetId)]?.outputs ?? []).map((output) => output.role ?? "");
|
|
37136
37446
|
}
|
|
@@ -37193,6 +37503,7 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
37193
37503
|
padding: layer.padding,
|
|
37194
37504
|
key: layer.key,
|
|
37195
37505
|
skin: layer.skin,
|
|
37506
|
+
cover: layer.cover,
|
|
37196
37507
|
reference: layer.clean ? stills : []
|
|
37197
37508
|
});
|
|
37198
37509
|
const offset = entry.postprocess?.offset;
|
|
@@ -37217,12 +37528,12 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
37217
37528
|
const prepared = redrawSheet(built, layers, redraw);
|
|
37218
37529
|
const size = decodePng(prepared.keyed);
|
|
37219
37530
|
const cost = proTierCost(size.width, size.height);
|
|
37220
|
-
const workDir =
|
|
37531
|
+
const workDir = path76.join(layerWorkDir(spec), "redraw");
|
|
37221
37532
|
const result = { roles, guides, sheet: { width: size.width, height: size.height }, cost, billed: null, written: [], workDir };
|
|
37222
37533
|
if (opts.dryRun) return result;
|
|
37223
|
-
await
|
|
37224
|
-
await
|
|
37225
|
-
await
|
|
37534
|
+
await mkdir27(workDir, { recursive: true });
|
|
37535
|
+
await writeFile32(path76.join(workDir, "keyed.png"), prepared.keyed);
|
|
37536
|
+
await writeFile32(path76.join(workDir, "mask.png"), prepared.mask);
|
|
37226
37537
|
const count = roles.length;
|
|
37227
37538
|
const description = `${spec.prompt}. Every figure but ${count === 1 ? "one" : count} already wears it. Dress the unfinished figure${count === 1 ? "" : "s"} in exactly the same thing, the same colours and details, seen from the side ${count === 1 ? "that figure faces" : "each of those figures faces"}.`;
|
|
37228
37539
|
const jobId = await painter.paintSheet({ description, keyed: prepared.keyed, mask: prepared.mask, seed: opts.seed ?? spec.seed });
|
|
@@ -37240,13 +37551,13 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
37240
37551
|
if (Date.now() > deadline) throw new Error(`${label}: redraw job ${jobId} did not finish in time; nothing was changed`);
|
|
37241
37552
|
await new Promise((resolve) => setTimeout(resolve, opts.pollMs ?? 3e3));
|
|
37242
37553
|
}
|
|
37243
|
-
await
|
|
37554
|
+
await writeFile32(path76.join(workDir, "result.png"), painted);
|
|
37244
37555
|
const returned = decodePng(painted);
|
|
37245
37556
|
if (returned.width !== size.width || returned.height !== size.height) {
|
|
37246
37557
|
throw new Error(`${label}: redraw job ${jobId} returned a ${returned.width}x${returned.height} image for a ${size.width}x${size.height} sheet`);
|
|
37247
37558
|
}
|
|
37248
37559
|
const cut = cutLayerFrames(painted, { keyed: prepared.keyed, mask: prepared.mask, frames: built.frames }, { key: layer.key, region: layer.region });
|
|
37249
|
-
const cacheDir =
|
|
37560
|
+
const cacheDir = path76.resolve(opts.cacheDir ?? path76.join(path76.dirname(opts.lockPath), ".pixelkiln", "cache"));
|
|
37250
37561
|
const outputs = [...entry.outputs];
|
|
37251
37562
|
const renames = [];
|
|
37252
37563
|
for (const [index, at2] of targets) {
|
|
@@ -37260,7 +37571,7 @@ async function redrawLayerFrames(spec, lock, painter, opts) {
|
|
|
37260
37571
|
const processed = applyPostprocess(raw, MediaType.PNG, entry.postprocess, [], role);
|
|
37261
37572
|
await cacheMedia(cacheDir, processed.bytes, MediaType.PNG);
|
|
37262
37573
|
const tmp = `${target}.pixelkiln.tmp`;
|
|
37263
|
-
await
|
|
37574
|
+
await writeFile32(tmp, processed.bytes);
|
|
37264
37575
|
renames.push([tmp, target]);
|
|
37265
37576
|
const { raw: _raw, ...kept } = outputs[at2];
|
|
37266
37577
|
outputs[at2] = { ...kept, sha256: sha256(processed.bytes), ...processed.changed ? { raw: sha256(raw) } : {} };
|
|
@@ -37304,7 +37615,7 @@ async function runRedraw(args) {
|
|
|
37304
37615
|
const painter = args.dryRun ? { paintSheet: never, paintedSheet: never } : new PixelLabProvider(clientFromEnv());
|
|
37305
37616
|
const result = await redrawLayerFrames(spec, project2.lock, painter, {
|
|
37306
37617
|
frames: args.redrawFrames,
|
|
37307
|
-
lockPath:
|
|
37618
|
+
lockPath: path77.resolve(args.lock),
|
|
37308
37619
|
seed: args.seed,
|
|
37309
37620
|
dryRun: args.dryRun,
|
|
37310
37621
|
onProgress: log
|
|
@@ -37315,16 +37626,42 @@ async function runRedraw(args) {
|
|
|
37315
37626
|
log(` would redraw ${frames} (${result.roles.join(", ")}) beside ${result.guides} dressed, on a ${sheet} sheet: about ${result.cost} generations`);
|
|
37316
37627
|
return;
|
|
37317
37628
|
}
|
|
37318
|
-
for (const file of result.written) log(` wrote ${
|
|
37629
|
+
for (const file of result.written) log(` wrote ${path77.relative(process.cwd(), file)}`);
|
|
37319
37630
|
const billed = result.billed ? `${result.billed.amount} ${result.billed.unit} billed` : `about ${result.cost} generations`;
|
|
37320
|
-
log(` redrew ${frames} of ${target} (${billed}); the sheet and result are in ${
|
|
37631
|
+
log(` redrew ${frames} of ${target} (${billed}); the sheet and result are in ${path77.relative(process.cwd(), result.workDir)}`);
|
|
37321
37632
|
log(` look at ${result.written.length === 1 ? "it" : "them"}, then run pixelkiln gen to rebuild anything made from this layer`);
|
|
37322
37633
|
}
|
|
37323
37634
|
|
|
37635
|
+
// src/cli/commands/layer.ts
|
|
37636
|
+
import path78 from "path";
|
|
37637
|
+
async function runLayer(args) {
|
|
37638
|
+
const target = args.target;
|
|
37639
|
+
const project2 = await openProject2(args);
|
|
37640
|
+
const named = project2.specs.filter((spec) => spec.assetId === target);
|
|
37641
|
+
if (!named.length) throw new UsageError(`No asset "${target}" in ${args.manifest}`);
|
|
37642
|
+
const layers = named.filter((spec) => spec.character?.kind === "layer");
|
|
37643
|
+
if (!layers.length) throw new UsageError(`${target} is not a paperdoll layer`);
|
|
37644
|
+
if (layers.length > 1) {
|
|
37645
|
+
throw new UsageError(`${target} is a layer in ${layers.length} styles (${layers.map((spec) => spec.styleId).join(", ")}); pick one with --style`);
|
|
37646
|
+
}
|
|
37647
|
+
const result = await previewLayer(layers[0], project2.lock);
|
|
37648
|
+
const width = Math.max(...result.frames.map((frame) => frame.name.length));
|
|
37649
|
+
for (const frame of result.frames) {
|
|
37650
|
+
const neck = frame.neck ? `neck row ${String(frame.neck.row).padStart(3)}` + (frame.neck.corrected ? ` (own narrowest row ${frame.neck.detected ?? "none"}; taken from the head and the other frames)` : "") : result.supplied.mask ? "mask supplied" : "empty";
|
|
37651
|
+
log(` ${frame.name.padEnd(width)} ${String(frame.masked).padStart(6)} px open ${neck}`);
|
|
37652
|
+
}
|
|
37653
|
+
const corrected = result.frames.filter((frame) => frame.neck?.corrected).length;
|
|
37654
|
+
if (corrected) log(` ${corrected} frame${corrected === 1 ? "'s" : "s'"} neck overruled; look at those in overlay.png before paying`);
|
|
37655
|
+
if (result.closed) log(` ${result.closed} pinhole pixel${result.closed === 1 ? "" : "s"} keyed shut inside the mask`);
|
|
37656
|
+
if (result.cleaned) log(` ${result.cleaned} ghost pixel${result.cleaned === 1 ? "" : "s"} cleaned from the loops`);
|
|
37657
|
+
log(` wrote ${result.written.length} files to ${path78.relative(process.cwd(), result.dir) || "."} (overlay.png shows the mask over the frames)`);
|
|
37658
|
+
log(` ${result.frames.length} frames on a ${result.sheet.width}x${result.sheet.height} sheet: about ${result.cost} generations when generated; nothing was sent`);
|
|
37659
|
+
}
|
|
37660
|
+
|
|
37324
37661
|
// src/cli/commands/skeleton.ts
|
|
37325
|
-
import
|
|
37662
|
+
import path79 from "path";
|
|
37326
37663
|
import { existsSync as existsSync57 } from "fs";
|
|
37327
|
-
import { readFile as readFile52, writeFile as
|
|
37664
|
+
import { readFile as readFile52, writeFile as writeFile33 } from "fs/promises";
|
|
37328
37665
|
|
|
37329
37666
|
// src/skeleton-preview.ts
|
|
37330
37667
|
var RIGHT = [255, 140, 40, 255];
|
|
@@ -37445,12 +37782,12 @@ var Canvas = class {
|
|
|
37445
37782
|
async function runEstimateSkeleton(args) {
|
|
37446
37783
|
const image = args.target;
|
|
37447
37784
|
if (!image) throw new UsageError("estimate-skeleton needs an image path: pixelkiln estimate-skeleton <image> [--out keypoints.json]");
|
|
37448
|
-
if (args.out && existsSync57(
|
|
37785
|
+
if (args.out && existsSync57(path79.resolve(args.out)) && !args.force) {
|
|
37449
37786
|
throw new UsageError(`${args.out} already exists; pass --force to replace it`);
|
|
37450
37787
|
}
|
|
37451
|
-
loadEnvFiles(
|
|
37788
|
+
loadEnvFiles(path79.dirname(path79.resolve(args.manifest)));
|
|
37452
37789
|
loadEnvFiles(process.cwd());
|
|
37453
|
-
const bytes = await readFile52(
|
|
37790
|
+
const bytes = await readFile52(path79.resolve(image));
|
|
37454
37791
|
const metadata = imageMetadata(bytes);
|
|
37455
37792
|
if (!metadata) throw new UsageError(`${image} is not a readable PNG or JPEG`);
|
|
37456
37793
|
if (args.custom) return estimateCustom(args, image, bytes, metadata);
|
|
@@ -37463,7 +37800,7 @@ async function runEstimateSkeleton(args) {
|
|
|
37463
37800
|
const frames = args.frames ?? DEFAULT_SCAFFOLD_FRAMES;
|
|
37464
37801
|
const json2 = JSON.stringify(scaffoldSkeletonSet(res.keypoints, frames), null, 2);
|
|
37465
37802
|
if (args.out) {
|
|
37466
|
-
await
|
|
37803
|
+
await writeFile33(path79.resolve(args.out), json2 + "\n");
|
|
37467
37804
|
log(` wrote ${args.out}: the estimated pose and ${frames} frames to edit`);
|
|
37468
37805
|
log(` preview it with: pixelkiln skeleton-preview ${args.out} --from ${image}`);
|
|
37469
37806
|
} else {
|
|
@@ -37498,7 +37835,7 @@ async function estimateCustom(args, image, bytes, metadata) {
|
|
|
37498
37835
|
const json2 = JSON.stringify(scaffoldSkeletonSet(res.keypoints, frames, { rig: res.rig, kind: res.kind }), null, 2);
|
|
37499
37836
|
const extra = res.rig.filter((joint) => !joint.estimate).map((joint) => joint.name);
|
|
37500
37837
|
if (args.out) {
|
|
37501
|
-
await
|
|
37838
|
+
await writeFile33(path79.resolve(args.out), json2 + "\n");
|
|
37502
37839
|
log(` wrote ${args.out}: a ${res.kind ?? "custom"} rig of ${res.rig.length} joints and ${frames} frames to edit`);
|
|
37503
37840
|
if (extra.length) log(` joints beyond the 18: ${extra.slice(0, 12).join(", ")}${extra.length > 12 ? ", \u2026" : ""}`);
|
|
37504
37841
|
log(` preview it with: pixelkiln skeleton-preview ${args.out} --from ${image}`);
|
|
@@ -37512,8 +37849,8 @@ async function runSkeletonPreview(args) {
|
|
|
37512
37849
|
let sourceFile;
|
|
37513
37850
|
let label;
|
|
37514
37851
|
if (target.endsWith(".json")) {
|
|
37515
|
-
keypointsFile =
|
|
37516
|
-
sourceFile = args.from ?
|
|
37852
|
+
keypointsFile = path79.resolve(target);
|
|
37853
|
+
sourceFile = args.from ? path79.resolve(args.from) : void 0;
|
|
37517
37854
|
label = target;
|
|
37518
37855
|
} else {
|
|
37519
37856
|
const loaded = await loadManifest(args.manifest);
|
|
@@ -37525,7 +37862,7 @@ async function runSkeletonPreview(args) {
|
|
|
37525
37862
|
);
|
|
37526
37863
|
}
|
|
37527
37864
|
keypointsFile = spec.revision.keypointsFile;
|
|
37528
|
-
sourceFile = args.from ?
|
|
37865
|
+
sourceFile = args.from ? path79.resolve(args.from) : spec.revision.sourceFile;
|
|
37529
37866
|
label = `${spec.styleId}/${spec.assetId}`;
|
|
37530
37867
|
}
|
|
37531
37868
|
if (!existsSync57(keypointsFile)) throw new UsageError(`Keypoints file does not exist yet: ${keypointsFile}`);
|
|
@@ -37546,10 +37883,10 @@ async function runSkeletonPreview(args) {
|
|
|
37546
37883
|
source = decodePng(bytes);
|
|
37547
37884
|
}
|
|
37548
37885
|
}
|
|
37549
|
-
const out =
|
|
37550
|
-
await
|
|
37886
|
+
const out = path79.resolve(args.out ?? keypointsFile.replace(/\.json$/, "") + ".preview.png");
|
|
37887
|
+
await writeFile33(out, renderSkeletonSheet(set, { source }));
|
|
37551
37888
|
log(` ${label}: ${set.frames.length} frames after the starting pose`);
|
|
37552
|
-
const shown2 =
|
|
37889
|
+
const shown2 = path79.relative(process.cwd(), out);
|
|
37553
37890
|
log(` wrote ${shown2.startsWith("..") ? out : shown2}`);
|
|
37554
37891
|
}
|
|
37555
37892
|
|
|
@@ -37595,15 +37932,15 @@ async function runTools(args) {
|
|
|
37595
37932
|
}
|
|
37596
37933
|
|
|
37597
37934
|
// src/cli/commands/workspace.ts
|
|
37598
|
-
import
|
|
37935
|
+
import path80 from "path";
|
|
37599
37936
|
import { existsSync as existsSync58 } from "fs";
|
|
37600
37937
|
async function runWorkspace(args) {
|
|
37601
|
-
const workspacePath =
|
|
37602
|
-
const dir =
|
|
37938
|
+
const workspacePath = path80.resolve(args.workspace ?? "pixelkiln.workspace.json");
|
|
37939
|
+
const dir = path80.dirname(workspacePath);
|
|
37603
37940
|
if (args.subcommand === "add") {
|
|
37604
|
-
const manifestPath =
|
|
37941
|
+
const manifestPath = path80.resolve(args.target);
|
|
37605
37942
|
const loadedTarget = await loadManifest(manifestPath);
|
|
37606
|
-
const lockPath = args.explicitLock ?
|
|
37943
|
+
const lockPath = args.explicitLock ? path80.resolve(args.explicitLock) : path80.join(path80.dirname(manifestPath), "pixelkiln.lock.json");
|
|
37607
37944
|
const ws = await loadWorkspace(workspacePath);
|
|
37608
37945
|
const id = args.name ?? loadedTarget.manifest.name;
|
|
37609
37946
|
if (ws.projects.some((p) => p.id === id)) {
|
|
@@ -37623,7 +37960,7 @@ async function runWorkspace(args) {
|
|
|
37623
37960
|
...args.account ? { account: args.account } : {}
|
|
37624
37961
|
};
|
|
37625
37962
|
await saveWorkspace(workspacePath, { version: 1, projects: [...ws.projects, project2] });
|
|
37626
|
-
log(` registered "${id}" in ${
|
|
37963
|
+
log(` registered "${id}" in ${path80.relative(process.cwd(), workspacePath)}`);
|
|
37627
37964
|
log(` manifest: ${project2.manifest}`);
|
|
37628
37965
|
log(` lock: ${project2.lock}`);
|
|
37629
37966
|
if (!existsSync58(lockPath)) {
|
|
@@ -37635,7 +37972,7 @@ async function runWorkspace(args) {
|
|
|
37635
37972
|
}
|
|
37636
37973
|
if (args.subcommand === "remove") {
|
|
37637
37974
|
const ws = await loadWorkspace(workspacePath);
|
|
37638
|
-
const resolvedTarget =
|
|
37975
|
+
const resolvedTarget = path80.resolve(args.target);
|
|
37639
37976
|
const match = ws.projects.find(
|
|
37640
37977
|
(p) => p.id === args.target || resolveProject(dir, p).manifestPath === resolvedTarget
|
|
37641
37978
|
);
|
|
@@ -37646,7 +37983,7 @@ async function runWorkspace(args) {
|
|
|
37646
37983
|
version: 1,
|
|
37647
37984
|
projects: ws.projects.filter((p) => p !== match)
|
|
37648
37985
|
});
|
|
37649
|
-
log(` removed "${match.id}" from ${
|
|
37986
|
+
log(` removed "${match.id}" from ${path80.relative(process.cwd(), workspacePath)}`);
|
|
37650
37987
|
return;
|
|
37651
37988
|
}
|
|
37652
37989
|
if (args.subcommand === "list") {
|
|
@@ -37658,9 +37995,9 @@ async function runWorkspace(args) {
|
|
|
37658
37995
|
if (args.json) {
|
|
37659
37996
|
log(JSON.stringify({ version: 1, workspace: workspacePath, projects: ws.projects, diagnostics }, null, 2));
|
|
37660
37997
|
} else if (!ws.projects.length) {
|
|
37661
|
-
log(` no projects registered in ${
|
|
37998
|
+
log(` no projects registered in ${path80.relative(process.cwd(), workspacePath)}`);
|
|
37662
37999
|
} else {
|
|
37663
|
-
log(` ${ws.projects.length} project(s) in ${
|
|
38000
|
+
log(` ${ws.projects.length} project(s) in ${path80.relative(process.cwd(), workspacePath)}:`);
|
|
37664
38001
|
for (const p of ws.projects) {
|
|
37665
38002
|
log(` ${p.id.padEnd(24)} ${p.manifest.padEnd(40)} (${p.provider}${p.account ? `, ${p.account}` : ""})`);
|
|
37666
38003
|
}
|
|
@@ -37678,7 +38015,7 @@ async function runWorkspace(args) {
|
|
|
37678
38015
|
if (args.json) {
|
|
37679
38016
|
log(JSON.stringify({ ...report, workspace: workspacePath }, null, 2));
|
|
37680
38017
|
} else {
|
|
37681
|
-
log(` workspace: ${
|
|
38018
|
+
log(` workspace: ${path80.relative(process.cwd(), workspacePath)}`);
|
|
37682
38019
|
for (const p of report.projects) {
|
|
37683
38020
|
if (p.error) {
|
|
37684
38021
|
log(`
|
|
@@ -37782,6 +38119,7 @@ var RUNNERS = {
|
|
|
37782
38119
|
"estimate-skeleton": runEstimateSkeleton,
|
|
37783
38120
|
anchors: runAnchors,
|
|
37784
38121
|
redraw: runRedraw,
|
|
38122
|
+
layer: runLayer,
|
|
37785
38123
|
"skeleton-preview": runSkeletonPreview,
|
|
37786
38124
|
unzoom: runUnzoom,
|
|
37787
38125
|
pixelate: runPixelate,
|