pixelkiln 0.110.0 → 0.111.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cli.js +834 -363
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +859 -523
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +278 -19
- package/dist/index.d.ts +278 -19
- package/dist/index.js +779 -460
- package/dist/index.js.map +1 -1
- package/docs/ARCHITECTURE.md +10 -0
- package/docs/CLI.md +86 -6
- package/docs/LIBRARY.md +32 -0
- package/docs/THIRD_PARTY.md +20 -0
- package/package.json +2 -1
- package/skills/pixelkiln/references/models.md +15 -3
- package/skills/pixelkiln/references/vfx.md +48 -21
package/dist/index.js
CHANGED
|
@@ -1411,7 +1411,7 @@ var AssetDeriveSchema = z.object({
|
|
|
1411
1411
|
/** 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. */
|
|
1412
1412
|
tolerance: z.number().min(0).max(442).optional()
|
|
1413
1413
|
}).strict().superRefine((derive, context) => {
|
|
1414
|
-
const issue = (message6,
|
|
1414
|
+
const issue = (message6, path53) => context.addIssue({ code: z.ZodIssueCode.custom, message: message6, path: [path53] });
|
|
1415
1415
|
if (Boolean(derive.from) === Boolean(derive.file)) {
|
|
1416
1416
|
issue("name exactly one source: `from` (an asset in this style) or `file` (a committed PNG)", derive.from ? "file" : "from");
|
|
1417
1417
|
}
|
|
@@ -2764,9 +2764,9 @@ var PixelLabClient = class {
|
|
|
2764
2764
|
apiKey;
|
|
2765
2765
|
http;
|
|
2766
2766
|
/** Retries transport failures, 429, and 5xx; see http.ts for the policy. */
|
|
2767
|
-
async request(
|
|
2767
|
+
async request(path53, init) {
|
|
2768
2768
|
const auth = this.apiKey.startsWith("Bearer ") ? this.apiKey : `Bearer ${this.apiKey}`;
|
|
2769
|
-
const res = await this.http(`${BASE}${
|
|
2769
|
+
const res = await this.http(`${BASE}${path53}`, {
|
|
2770
2770
|
...init,
|
|
2771
2771
|
headers: {
|
|
2772
2772
|
Authorization: auth,
|
|
@@ -2777,13 +2777,13 @@ var PixelLabClient = class {
|
|
|
2777
2777
|
const text = await res.text();
|
|
2778
2778
|
if (!res.ok) {
|
|
2779
2779
|
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' : "";
|
|
2780
|
-
throw new PixelLabError(`${init?.method ?? "GET"} ${
|
|
2780
|
+
throw new PixelLabError(`${init?.method ?? "GET"} ${path53} \u2192 ${res.status}${hint}${refusalReason(res.status, text)}`, res.status, text);
|
|
2781
2781
|
}
|
|
2782
2782
|
if (!text) return {};
|
|
2783
2783
|
try {
|
|
2784
2784
|
return JSON.parse(text);
|
|
2785
2785
|
} catch {
|
|
2786
|
-
throw new Error(`${init?.method ?? "GET"} ${
|
|
2786
|
+
throw new Error(`${init?.method ?? "GET"} ${path53} returned invalid JSON`);
|
|
2787
2787
|
}
|
|
2788
2788
|
}
|
|
2789
2789
|
async balance() {
|
|
@@ -3330,10 +3330,10 @@ var PixelLabClient = class {
|
|
|
3330
3330
|
const palette = args.paletteSwatchBase64 ? { color_image: { type: "base64", base64: args.paletteSwatchBase64, format: "png" }, force_colors: true } : {};
|
|
3331
3331
|
const encode = (image) => ({ type: "base64", base64: image.base64, format: image.format });
|
|
3332
3332
|
const south = args.reference?.south;
|
|
3333
|
-
let
|
|
3333
|
+
let path53;
|
|
3334
3334
|
let body;
|
|
3335
3335
|
if (args.mode === "v3") {
|
|
3336
|
-
|
|
3336
|
+
path53 = "/create-character-v3";
|
|
3337
3337
|
body = {
|
|
3338
3338
|
description: args.description,
|
|
3339
3339
|
image_size: imageSize,
|
|
@@ -3347,7 +3347,7 @@ var PixelLabClient = class {
|
|
|
3347
3347
|
...args.enhancePrompt ? { enhance_prompt: true } : {}
|
|
3348
3348
|
};
|
|
3349
3349
|
} else if (args.mode === "pro-flash") {
|
|
3350
|
-
|
|
3350
|
+
path53 = "/create-character-pro-flash";
|
|
3351
3351
|
const traits = args.styleTraits;
|
|
3352
3352
|
body = {
|
|
3353
3353
|
description: args.description,
|
|
@@ -3371,7 +3371,7 @@ var PixelLabClient = class {
|
|
|
3371
3371
|
} : {}
|
|
3372
3372
|
};
|
|
3373
3373
|
} else if (args.mode === "pro") {
|
|
3374
|
-
|
|
3374
|
+
path53 = "/create-character-pro";
|
|
3375
3375
|
body = {
|
|
3376
3376
|
description: args.description,
|
|
3377
3377
|
image_size: imageSize,
|
|
@@ -3385,7 +3385,7 @@ var PixelLabClient = class {
|
|
|
3385
3385
|
...!south && args.styleCharacterId ? { style_character_id: args.styleCharacterId } : {}
|
|
3386
3386
|
};
|
|
3387
3387
|
} else {
|
|
3388
|
-
|
|
3388
|
+
path53 = args.directions === 4 ? "/create-character-with-4-directions" : "/create-character-with-8-directions";
|
|
3389
3389
|
body = {
|
|
3390
3390
|
description: args.description,
|
|
3391
3391
|
image_size: imageSize,
|
|
@@ -3403,8 +3403,8 @@ var PixelLabClient = class {
|
|
|
3403
3403
|
};
|
|
3404
3404
|
}
|
|
3405
3405
|
if (args.mode === "pro" || args.mode === "pro-flash") Object.assign(body, targetPaletteBody(args.targetPalette));
|
|
3406
|
-
const raw = await this.request(
|
|
3407
|
-
return validateResponse(CharacterSubmitSchema, raw,
|
|
3406
|
+
const raw = await this.request(path53, { method: "POST", body: JSON.stringify(body) });
|
|
3407
|
+
return validateResponse(CharacterSubmitSchema, raw, path53.slice(1));
|
|
3408
3408
|
}
|
|
3409
3409
|
/** A text edit of an existing character, applied to every direction and stored as a sibling. */
|
|
3410
3410
|
async createCharacterState(args) {
|
|
@@ -5034,10 +5034,10 @@ function normalizeHex(value) {
|
|
|
5034
5034
|
function sha256(data) {
|
|
5035
5035
|
return createHash("sha256").update(data).digest("hex");
|
|
5036
5036
|
}
|
|
5037
|
-
async function sha256File(
|
|
5037
|
+
async function sha256File(path53) {
|
|
5038
5038
|
return new Promise((resolve, reject) => {
|
|
5039
5039
|
const hash = createHash("sha256");
|
|
5040
|
-
const stream = createReadStream(
|
|
5040
|
+
const stream = createReadStream(path53);
|
|
5041
5041
|
stream.on("data", (chunk2) => hash.update(chunk2));
|
|
5042
5042
|
stream.on("error", reject);
|
|
5043
5043
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -10836,9 +10836,9 @@ var RetroDiffusionClient = class {
|
|
|
10836
10836
|
if (!response.ok) throw new ProviderError("retrodiffusion", `Retro Diffusion download failed (${response.status})`, { status: response.status });
|
|
10837
10837
|
return Buffer.from(await response.arrayBuffer());
|
|
10838
10838
|
}
|
|
10839
|
-
async call(
|
|
10839
|
+
async call(path53, init = {}) {
|
|
10840
10840
|
if (!this.token) throw new Error("RD_API_KEY is not set");
|
|
10841
|
-
const response = await this.request(`${this.baseUrl}${
|
|
10841
|
+
const response = await this.request(`${this.baseUrl}${path53}`, {
|
|
10842
10842
|
...init,
|
|
10843
10843
|
headers: {
|
|
10844
10844
|
"Content-Type": "application/json",
|
|
@@ -17939,11 +17939,108 @@ async function saveToAssetFile(client2, target, from, opts = {}) {
|
|
|
17939
17939
|
}
|
|
17940
17940
|
|
|
17941
17941
|
// src/pixelfx-vfx.ts
|
|
17942
|
-
import { existsSync as
|
|
17943
|
-
import {
|
|
17942
|
+
import { existsSync as existsSync21, readFileSync as readFileSync5 } from "fs";
|
|
17943
|
+
import { readFile as readFile14 } from "fs/promises";
|
|
17944
17944
|
import { createRequire } from "module";
|
|
17945
|
-
import
|
|
17945
|
+
import path26 from "path";
|
|
17946
17946
|
import { pathToFileURL } from "url";
|
|
17947
|
+
|
|
17948
|
+
// src/local-vfx.ts
|
|
17949
|
+
import { existsSync as existsSync20 } from "fs";
|
|
17950
|
+
import { mkdir as mkdir11, writeFile as writeFile11 } from "fs/promises";
|
|
17951
|
+
import path25 from "path";
|
|
17952
|
+
function localSheet(render) {
|
|
17953
|
+
const { width, height, frames } = render;
|
|
17954
|
+
const columns = Math.min(frames.length, Math.max(1, Math.ceil(Math.sqrt(frames.length * height / width))));
|
|
17955
|
+
const rows = Math.ceil(frames.length / columns);
|
|
17956
|
+
const sheet = Buffer.alloc(columns * width * rows * height * 4);
|
|
17957
|
+
const rects = frames.map((rgba, index) => {
|
|
17958
|
+
const x = index % columns * width;
|
|
17959
|
+
const y = Math.floor(index / columns) * height;
|
|
17960
|
+
for (let row = 0; row < height; row++) {
|
|
17961
|
+
rgba.copy(sheet, ((y + row) * columns * width + x) * 4, row * width * 4, (row + 1) * width * 4);
|
|
17962
|
+
}
|
|
17963
|
+
return { x, y, w: width, h: height };
|
|
17964
|
+
});
|
|
17965
|
+
return { png: encodeRgbaPng(columns * width, rows * height, sheet), columns, rows, rects };
|
|
17966
|
+
}
|
|
17967
|
+
function assertFreshOutputs(out, force) {
|
|
17968
|
+
const paths = vfxOutputPaths(out);
|
|
17969
|
+
if (!force) {
|
|
17970
|
+
for (const file of [paths.sheet, paths.atlas, paths.provenance]) {
|
|
17971
|
+
if (existsSync20(file)) throw new Error(`${file} already exists; pass --force to replace it`);
|
|
17972
|
+
}
|
|
17973
|
+
}
|
|
17974
|
+
return paths;
|
|
17975
|
+
}
|
|
17976
|
+
async function writeLocalVfx(opts) {
|
|
17977
|
+
const { paths, render } = opts;
|
|
17978
|
+
const sheet = localSheet(render);
|
|
17979
|
+
const clip = path25.basename(paths.sheet, ".png");
|
|
17980
|
+
const anchor = { kind: "origin", ...render.anchor };
|
|
17981
|
+
const size = { w: render.width, h: render.height };
|
|
17982
|
+
const atlas = {
|
|
17983
|
+
frames: sheet.rects.map((frame, index) => ({
|
|
17984
|
+
filename: `${clip} ${index}`,
|
|
17985
|
+
frame,
|
|
17986
|
+
rotated: false,
|
|
17987
|
+
trimmed: false,
|
|
17988
|
+
spriteSourceSize: { x: 0, y: 0, ...size },
|
|
17989
|
+
sourceSize: size,
|
|
17990
|
+
duration: Math.round(1e3 / render.fps)
|
|
17991
|
+
})),
|
|
17992
|
+
meta: {
|
|
17993
|
+
app: "pixelkiln",
|
|
17994
|
+
version: "1",
|
|
17995
|
+
image: path25.basename(paths.sheet),
|
|
17996
|
+
format: "RGBA8888",
|
|
17997
|
+
size: { w: sheet.columns * render.width, h: sheet.rows * render.height },
|
|
17998
|
+
scale: "1",
|
|
17999
|
+
frameTags: [{ name: clip, from: 0, to: render.frames.length - 1, direction: "forward" }],
|
|
18000
|
+
anchor,
|
|
18001
|
+
[opts.atlasKey]: {
|
|
18002
|
+
id: opts.effect,
|
|
18003
|
+
name: opts.name,
|
|
18004
|
+
...opts.atlasFacts,
|
|
18005
|
+
fps: render.fps,
|
|
18006
|
+
loop: render.loop,
|
|
18007
|
+
frames: render.frames.length,
|
|
18008
|
+
frameSize: [render.width, render.height],
|
|
18009
|
+
pivot: [anchor.x, anchor.y],
|
|
18010
|
+
columns: sheet.columns
|
|
18011
|
+
}
|
|
18012
|
+
}
|
|
18013
|
+
};
|
|
18014
|
+
const sheetSha256 = sha256(sheet.png);
|
|
18015
|
+
const facts = {
|
|
18016
|
+
name: opts.name,
|
|
18017
|
+
effect: opts.effect,
|
|
18018
|
+
width: render.width,
|
|
18019
|
+
height: render.height,
|
|
18020
|
+
frames: render.frames.length,
|
|
18021
|
+
fps: render.fps,
|
|
18022
|
+
loop: render.loop,
|
|
18023
|
+
anchor
|
|
18024
|
+
};
|
|
18025
|
+
const record = {
|
|
18026
|
+
version: 1,
|
|
18027
|
+
...opts.record,
|
|
18028
|
+
...facts,
|
|
18029
|
+
files: { sheet: path25.basename(paths.sheet), atlas: path25.basename(paths.atlas) },
|
|
18030
|
+
sheetSha256,
|
|
18031
|
+
exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
18032
|
+
recipe: opts.recipe
|
|
18033
|
+
};
|
|
18034
|
+
await mkdir11(path25.dirname(paths.sheet), { recursive: true });
|
|
18035
|
+
await writeFile11(paths.sheet, sheet.png);
|
|
18036
|
+
await writeFile11(paths.atlas, `${JSON.stringify(atlas, null, 2)}
|
|
18037
|
+
`);
|
|
18038
|
+
await writeFile11(paths.provenance, `${JSON.stringify(record, null, 2)}
|
|
18039
|
+
`);
|
|
18040
|
+
return { facts, columns: sheet.columns, sheetSha256, paths: { sheet: paths.sheet, atlas: paths.atlas, provenance: paths.provenance } };
|
|
18041
|
+
}
|
|
18042
|
+
|
|
18043
|
+
// src/pixelfx-vfx.ts
|
|
17947
18044
|
var PIXELFX_TOOL = "pixelfx";
|
|
17948
18045
|
var PIXELFX_REPOSITORY = "https://github.com/patch-gg/pixelfx";
|
|
17949
18046
|
var PIXELFX_INSTALL = "npm i github:patch-gg/pixelfx";
|
|
@@ -17955,17 +18052,17 @@ function missingPixelfx(cause) {
|
|
|
17955
18052
|
);
|
|
17956
18053
|
}
|
|
17957
18054
|
function pixelfxVersion(entry) {
|
|
17958
|
-
for (let dir =
|
|
17959
|
-
const file =
|
|
17960
|
-
if (!
|
|
18055
|
+
for (let dir = path26.dirname(entry); dir !== path26.dirname(dir); dir = path26.dirname(dir)) {
|
|
18056
|
+
const file = path26.join(dir, "package.json");
|
|
18057
|
+
if (!existsSync21(file)) continue;
|
|
17961
18058
|
const pkg = JSON.parse(readFileSync5(file, "utf8"));
|
|
17962
18059
|
if (pkg.name === "pixelfx") return typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
17963
18060
|
}
|
|
17964
18061
|
return "unknown";
|
|
17965
18062
|
}
|
|
17966
18063
|
async function loadPixelfx(from) {
|
|
17967
|
-
const bases = from?.map((base) => pathToFileURL(
|
|
17968
|
-
pathToFileURL(
|
|
18064
|
+
const bases = from?.map((base) => pathToFileURL(path26.resolve(base)).href) ?? [
|
|
18065
|
+
pathToFileURL(path26.join(process.cwd(), "package.json")).href,
|
|
17969
18066
|
import.meta.url
|
|
17970
18067
|
];
|
|
17971
18068
|
let resolved;
|
|
@@ -18131,21 +18228,7 @@ function renderPixelfx(lib, recipe) {
|
|
|
18131
18228
|
frames
|
|
18132
18229
|
};
|
|
18133
18230
|
}
|
|
18134
|
-
|
|
18135
|
-
const { width, height, frames } = render;
|
|
18136
|
-
const columns = Math.min(frames.length, Math.max(1, Math.ceil(Math.sqrt(frames.length * height / width))));
|
|
18137
|
-
const rows = Math.ceil(frames.length / columns);
|
|
18138
|
-
const sheet = Buffer.alloc(columns * width * rows * height * 4);
|
|
18139
|
-
const rects = frames.map((rgba, index) => {
|
|
18140
|
-
const x = index % columns * width;
|
|
18141
|
-
const y = Math.floor(index / columns) * height;
|
|
18142
|
-
for (let row = 0; row < height; row++) {
|
|
18143
|
-
rgba.copy(sheet, ((y + row) * columns * width + x) * 4, row * width * 4, (row + 1) * width * 4);
|
|
18144
|
-
}
|
|
18145
|
-
return { x, y, w: width, h: height };
|
|
18146
|
-
});
|
|
18147
|
-
return { png: encodeRgbaPng(columns * width, rows * height, sheet), columns, rows, rects };
|
|
18148
|
-
}
|
|
18231
|
+
var pixelfxSheet = localSheet;
|
|
18149
18232
|
async function readPixelfxRecipe(file) {
|
|
18150
18233
|
const parsed = JSON.parse(await readFile14(file, "utf8"));
|
|
18151
18234
|
const record = parsed.tool === PIXELFX_TOOL;
|
|
@@ -18169,7 +18252,6 @@ async function readPixelfxRecipe(file) {
|
|
|
18169
18252
|
return { recipe, ...typeof version === "string" ? { libraryVersion: version } : {} };
|
|
18170
18253
|
}
|
|
18171
18254
|
async function makePixelfxVfx(lib, opts) {
|
|
18172
|
-
const paths = vfxOutputPaths(opts.out);
|
|
18173
18255
|
const recipe = {
|
|
18174
18256
|
effect: opts.effect,
|
|
18175
18257
|
...opts.fps !== void 0 ? { fps: opts.fps } : {},
|
|
@@ -18177,98 +18259,314 @@ async function makePixelfxVfx(lib, opts) {
|
|
|
18177
18259
|
...opts.options && Object.keys(opts.options).length ? { options: opts.options } : {}
|
|
18178
18260
|
};
|
|
18179
18261
|
checkPixelfxRecipe(lib, recipe);
|
|
18180
|
-
|
|
18181
|
-
|
|
18182
|
-
|
|
18262
|
+
const paths = assertFreshOutputs(opts.out, opts.force);
|
|
18263
|
+
const render = renderPixelfx(lib, recipe);
|
|
18264
|
+
const written = await writeLocalVfx({
|
|
18265
|
+
paths,
|
|
18266
|
+
name: opts.name ?? render.effect.name,
|
|
18267
|
+
effect: opts.effect,
|
|
18268
|
+
render,
|
|
18269
|
+
atlasKey: "pixelfx",
|
|
18270
|
+
atlasFacts: { version: lib.version },
|
|
18271
|
+
record: {
|
|
18272
|
+
provider: "pixelfx",
|
|
18273
|
+
tool: PIXELFX_TOOL,
|
|
18274
|
+
library: { name: "pixelfx", version: lib.version, repository: PIXELFX_REPOSITORY, license: "MIT" }
|
|
18275
|
+
},
|
|
18276
|
+
recipe
|
|
18277
|
+
});
|
|
18278
|
+
return {
|
|
18279
|
+
provider: "pixelfx",
|
|
18280
|
+
library: { name: "pixelfx", version: lib.version },
|
|
18281
|
+
...written.facts,
|
|
18282
|
+
columns: written.columns,
|
|
18283
|
+
sheetSha256: written.sheetSha256,
|
|
18284
|
+
paths: written.paths,
|
|
18285
|
+
recipe
|
|
18286
|
+
};
|
|
18287
|
+
}
|
|
18288
|
+
|
|
18289
|
+
// src/codex-vfx.ts
|
|
18290
|
+
import { createHash as createHash5 } from "crypto";
|
|
18291
|
+
import { existsSync as existsSync22, readFileSync as readFileSync6, readdirSync } from "fs";
|
|
18292
|
+
import { readFile as readFile15 } from "fs/promises";
|
|
18293
|
+
import { createRequire as createRequire2 } from "module";
|
|
18294
|
+
import path27 from "path";
|
|
18295
|
+
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
18296
|
+
import vm from "vm";
|
|
18297
|
+
var CODEX_ID = "codex";
|
|
18298
|
+
var CODEX_PACKAGE = "pixel-vfx-codex";
|
|
18299
|
+
var CODEX_REPOSITORY = "https://github.com/888wing/pixel-vfx-codex";
|
|
18300
|
+
var CODEX_INSTALL = "npm i github:888wing/pixel-vfx-codex";
|
|
18301
|
+
var CODEX_CAMERAS = ["2d", "25d", "3d"];
|
|
18302
|
+
var CANVAS = { "2d": [160, 100], "25d": [240, 150], "3d": [240, 150] };
|
|
18303
|
+
var CODEX_TUNE_KEYS = ["size", "gain", "density", "dither", "outline", "hitstop", "shake", "flash", "snap"];
|
|
18304
|
+
function missingCodex(cause) {
|
|
18305
|
+
return new PixelKilnError(
|
|
18306
|
+
"pixel-vfx-codex is not installed, so there is nothing to render these effects with",
|
|
18307
|
+
"capability",
|
|
18308
|
+
{ hint: `Install it beside your project: ${CODEX_INSTALL} (${CODEX_REPOSITORY}, MIT; it is not on the npm registry)`, cause }
|
|
18309
|
+
);
|
|
18310
|
+
}
|
|
18311
|
+
function findCodexRoot(from) {
|
|
18312
|
+
const bases = from?.map((base) => pathToFileURL2(path27.resolve(base, "package.json")).href) ?? [
|
|
18313
|
+
pathToFileURL2(path27.join(process.cwd(), "package.json")).href,
|
|
18314
|
+
import.meta.url
|
|
18315
|
+
];
|
|
18316
|
+
let failure;
|
|
18317
|
+
for (const base of bases) {
|
|
18318
|
+
try {
|
|
18319
|
+
return path27.dirname(createRequire2(base).resolve(`${CODEX_PACKAGE}/package.json`));
|
|
18320
|
+
} catch (error) {
|
|
18321
|
+
failure = error;
|
|
18183
18322
|
}
|
|
18184
18323
|
}
|
|
18185
|
-
|
|
18186
|
-
|
|
18187
|
-
|
|
18188
|
-
const
|
|
18189
|
-
const
|
|
18190
|
-
const
|
|
18191
|
-
const
|
|
18192
|
-
|
|
18193
|
-
|
|
18194
|
-
|
|
18195
|
-
|
|
18196
|
-
|
|
18197
|
-
|
|
18198
|
-
|
|
18199
|
-
|
|
18200
|
-
|
|
18201
|
-
|
|
18202
|
-
|
|
18203
|
-
|
|
18204
|
-
|
|
18205
|
-
|
|
18206
|
-
|
|
18207
|
-
|
|
18208
|
-
|
|
18209
|
-
|
|
18210
|
-
|
|
18211
|
-
|
|
18212
|
-
|
|
18213
|
-
|
|
18214
|
-
|
|
18215
|
-
|
|
18216
|
-
|
|
18217
|
-
|
|
18218
|
-
|
|
18219
|
-
|
|
18324
|
+
throw missingCodex(failure);
|
|
18325
|
+
}
|
|
18326
|
+
function loadCodex(from) {
|
|
18327
|
+
const root = findCodexRoot(from);
|
|
18328
|
+
const read = (...parts) => readFileSync6(path27.join(root, ...parts), "utf8");
|
|
18329
|
+
const pkg = JSON.parse(read("package.json"));
|
|
18330
|
+
const version = typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
18331
|
+
for (const required of ["engine/pxfx.js", "engine/kit.js", "fx", "data/meta.json"]) {
|
|
18332
|
+
if (!existsSync22(path27.join(root, required))) {
|
|
18333
|
+
throw new PixelKilnError(`The installed ${CODEX_PACKAGE} (${version}) has no ${required}; PixelKiln was written against its 1.0.0 layout`, "capability");
|
|
18334
|
+
}
|
|
18335
|
+
}
|
|
18336
|
+
const sources = [read("engine", "pxfx.js"), read("engine", "kit.js")];
|
|
18337
|
+
const context = vm.createContext({ console });
|
|
18338
|
+
sources.forEach((source, index) => vm.runInContext(source, context, { filename: index ? "engine/kit.js" : "engine/pxfx.js" }));
|
|
18339
|
+
const engine = context.PXFX;
|
|
18340
|
+
if (!engine || typeof engine.View !== "function" || typeof engine.get !== "function") {
|
|
18341
|
+
throw new PixelKilnError(`The installed ${CODEX_PACKAGE} (${version}) does not define PXFX.View and PXFX.get`, "capability");
|
|
18342
|
+
}
|
|
18343
|
+
const loadErrors = [];
|
|
18344
|
+
for (const file of readdirSync(path27.join(root, "fx")).filter((name) => name.endsWith(".js")).sort()) {
|
|
18345
|
+
try {
|
|
18346
|
+
vm.runInContext(read("fx", file), context, { filename: `fx/${file}` });
|
|
18347
|
+
} catch (error) {
|
|
18348
|
+
loadErrors.push(`${file}: ${error instanceof Error ? error.message : String(error)}`);
|
|
18349
|
+
}
|
|
18350
|
+
}
|
|
18351
|
+
const meta = JSON.parse(read("data", "meta.json"));
|
|
18352
|
+
const catalogue = meta.flatMap(
|
|
18353
|
+
(entry) => typeof entry.id === "string" && engine.get(entry.id) ? [{
|
|
18354
|
+
id: entry.id,
|
|
18355
|
+
en: typeof entry.en === "string" ? entry.en : entry.id,
|
|
18356
|
+
descEn: typeof entry.descEn === "string" ? entry.descEn : "",
|
|
18357
|
+
category: typeof entry.category === "string" ? entry.category : "other",
|
|
18358
|
+
schools: Array.isArray(entry.schools) ? entry.schools.filter((school) => typeof school === "string") : []
|
|
18359
|
+
}] : []
|
|
18360
|
+
);
|
|
18361
|
+
if (!catalogue.length) throw new PixelKilnError(`The installed ${CODEX_PACKAGE} (${version}) loaded no effects`, "capability");
|
|
18362
|
+
const engineSha256 = createHash5("sha256").update(sources.join("\n")).digest("hex").slice(0, 12);
|
|
18363
|
+
return { version, engineSha256, engine, catalogue, loadErrors };
|
|
18364
|
+
}
|
|
18365
|
+
function listCodexEffects(lib) {
|
|
18366
|
+
return lib.catalogue.map((entry) => {
|
|
18367
|
+
const def = lib.engine.get(entry.id);
|
|
18368
|
+
return {
|
|
18369
|
+
...entry,
|
|
18370
|
+
loopSeconds: def.loop,
|
|
18371
|
+
params: Object.fromEntries(
|
|
18372
|
+
Object.entries(def.params ?? {}).map(([key2, param]) => [key2, { label: param.en ?? key2, min: param.min, max: param.max, value: param.value }])
|
|
18373
|
+
)
|
|
18374
|
+
};
|
|
18375
|
+
});
|
|
18376
|
+
}
|
|
18377
|
+
function formatCodexEffects(lib) {
|
|
18378
|
+
const effects = listCodexEffects(lib);
|
|
18379
|
+
const categories = [...new Set(effects.map((effect) => effect.category))];
|
|
18380
|
+
const lines = [`pixel-vfx-codex ${lib.version}: ${effects.length} effects (${CODEX_REPOSITORY}, MIT)`];
|
|
18381
|
+
for (const category of categories) {
|
|
18382
|
+
const inCategory = effects.filter((effect) => effect.category === category);
|
|
18383
|
+
lines.push("", `${category} (${inCategory.length})`);
|
|
18384
|
+
for (const effect of inCategory) lines.push(` ${effect.id.padEnd(28)} ${effect.en}`);
|
|
18385
|
+
}
|
|
18386
|
+
lines.push("", "--json lists every effect's parameters, with their ranges.");
|
|
18387
|
+
return lines.join("\n");
|
|
18388
|
+
}
|
|
18389
|
+
function findDef(lib, id) {
|
|
18390
|
+
const info = listCodexEffects(lib).find((entry) => entry.id === id);
|
|
18391
|
+
if (!info) {
|
|
18392
|
+
const near = lib.catalogue.map((entry) => entry.id).filter((other) => other.includes(id) || id.includes(other));
|
|
18393
|
+
throw new UsageError(
|
|
18394
|
+
`pixel-vfx-codex ${lib.version} has no effect "${id}"` + (near.length ? `; close: ${near.slice(0, 10).join(", ")}` : ""),
|
|
18395
|
+
{ hint: "List them with: pixelkiln vfx effects --lib codex" }
|
|
18396
|
+
);
|
|
18397
|
+
}
|
|
18398
|
+
return { def: lib.engine.get(id), info };
|
|
18399
|
+
}
|
|
18400
|
+
function checkCodexRecipe(lib, recipe) {
|
|
18401
|
+
const { info } = findDef(lib, recipe.effect);
|
|
18402
|
+
const { camera, fps, margin, hue, params = {}, tune = {} } = recipe;
|
|
18403
|
+
if (camera !== void 0 && !CODEX_CAMERAS.includes(camera)) {
|
|
18404
|
+
throw new UsageError(`--camera must be ${CODEX_CAMERAS.join(", ")}, got "${camera}"`);
|
|
18405
|
+
}
|
|
18406
|
+
if (fps !== void 0 && (!Number.isInteger(fps) || fps < 1 || fps > 60)) throw new UsageError(`codex fps must be a whole number 1 to 60, got ${fps}`);
|
|
18407
|
+
if (margin !== void 0 && (!Number.isInteger(margin) || margin < 0 || margin > 64)) {
|
|
18408
|
+
throw new UsageError(`codex margin must be a whole number 0 to 64, got ${margin}`);
|
|
18409
|
+
}
|
|
18410
|
+
if (hue !== void 0 && (typeof hue !== "number" || !Number.isFinite(hue) || hue < -360 || hue > 360)) {
|
|
18411
|
+
throw new UsageError(`codex hue is degrees from -360 to 360, got ${JSON.stringify(hue)}`);
|
|
18412
|
+
}
|
|
18413
|
+
for (const [key2, value] of Object.entries(params)) {
|
|
18414
|
+
const param = info.params[key2];
|
|
18415
|
+
if (!param) {
|
|
18416
|
+
const known = Object.keys(info.params);
|
|
18417
|
+
throw new UsageError(`${recipe.effect} has no parameter "${key2}"${known.length ? `; it has ${known.join(", ")}` : " (it takes none)"}`);
|
|
18418
|
+
}
|
|
18419
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < param.min || value > param.max) {
|
|
18420
|
+
throw new UsageError(`${recipe.effect} ${key2} is a number from ${param.min} to ${param.max}, got ${JSON.stringify(value)}`);
|
|
18421
|
+
}
|
|
18422
|
+
}
|
|
18423
|
+
for (const [key2, value] of Object.entries(tune)) {
|
|
18424
|
+
if (!CODEX_TUNE_KEYS.includes(key2)) throw new UsageError(`unknown tune knob "${key2}"; they are ${CODEX_TUNE_KEYS.join(", ")}`);
|
|
18425
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new UsageError(`tune ${key2} is a number, got ${JSON.stringify(value)}`);
|
|
18426
|
+
}
|
|
18427
|
+
return info;
|
|
18428
|
+
}
|
|
18429
|
+
function cropFrames(frames, width, height, pivot, margin) {
|
|
18430
|
+
let x0 = Math.floor(pivot.x), x1 = Math.floor(pivot.x), y0 = Math.floor(pivot.y), y1 = Math.floor(pivot.y);
|
|
18431
|
+
x0 = Math.max(0, Math.min(x0, width - 1));
|
|
18432
|
+
x1 = Math.max(0, Math.min(x1, width - 1));
|
|
18433
|
+
y0 = Math.max(0, Math.min(y0, height - 1));
|
|
18434
|
+
y1 = Math.max(0, Math.min(y1, height - 1));
|
|
18435
|
+
for (const frame of frames) {
|
|
18436
|
+
for (let y = 0; y < height; y++) {
|
|
18437
|
+
for (let x = 0; x < width; x++) {
|
|
18438
|
+
if (frame[(y * width + x) * 4 + 3]) {
|
|
18439
|
+
if (x < x0) x0 = x;
|
|
18440
|
+
if (x > x1) x1 = x;
|
|
18441
|
+
if (y < y0) y0 = y;
|
|
18442
|
+
if (y > y1) y1 = y;
|
|
18443
|
+
}
|
|
18444
|
+
}
|
|
18445
|
+
}
|
|
18446
|
+
}
|
|
18447
|
+
const cropWidth = x1 - x0 + 1 + margin * 2;
|
|
18448
|
+
const cropHeight = y1 - y0 + 1 + margin * 2;
|
|
18449
|
+
const cropped = frames.map((frame) => {
|
|
18450
|
+
const out = Buffer.alloc(cropWidth * cropHeight * 4);
|
|
18451
|
+
for (let y = 0; y < cropHeight; y++) {
|
|
18452
|
+
const sy = y0 - margin + y;
|
|
18453
|
+
if (sy < 0 || sy >= height) continue;
|
|
18454
|
+
for (let x = 0; x < cropWidth; x++) {
|
|
18455
|
+
const sx = x0 - margin + x;
|
|
18456
|
+
if (sx < 0 || sx >= width) continue;
|
|
18457
|
+
frame.copy(out, (y * cropWidth + x) * 4, (sy * width + sx) * 4, (sy * width + sx) * 4 + 4);
|
|
18220
18458
|
}
|
|
18221
18459
|
}
|
|
18460
|
+
return out;
|
|
18461
|
+
});
|
|
18462
|
+
return { width: cropWidth, height: cropHeight, frames: cropped, anchor: { x: pivot.x - x0 + margin, y: pivot.y - y0 + margin } };
|
|
18463
|
+
}
|
|
18464
|
+
function planCodex(lib, recipe) {
|
|
18465
|
+
checkCodexRecipe(lib, recipe);
|
|
18466
|
+
const camera = recipe.camera ?? "2d";
|
|
18467
|
+
const fps = recipe.fps ?? lib.engine.MODES[camera]?.fps ?? 12;
|
|
18468
|
+
const seconds = lib.engine.timing(lib.engine.get(recipe.effect), { ...recipe.tune ?? {} }).length;
|
|
18469
|
+
return { camera, fps, frames: Math.max(1, Math.round(seconds * fps)), seconds };
|
|
18470
|
+
}
|
|
18471
|
+
function renderCodex(lib, recipe) {
|
|
18472
|
+
const info = checkCodexRecipe(lib, recipe);
|
|
18473
|
+
const def = lib.engine.get(recipe.effect);
|
|
18474
|
+
const camera = recipe.camera ?? "2d";
|
|
18475
|
+
const [canvasWidth, canvasHeight] = CANVAS[camera];
|
|
18476
|
+
const fps = recipe.fps ?? lib.engine.MODES[camera]?.fps ?? 12;
|
|
18477
|
+
const view = new lib.engine.View(null, canvasWidth, canvasHeight);
|
|
18478
|
+
view.mode = camera;
|
|
18479
|
+
view.night = false;
|
|
18480
|
+
view.hue = recipe.hue ?? 0;
|
|
18481
|
+
view.params = { ...recipe.params ?? {} };
|
|
18482
|
+
view.tune = { ...recipe.tune ?? {} };
|
|
18483
|
+
view.transparent = true;
|
|
18484
|
+
view.noProps = true;
|
|
18485
|
+
view.shakeX = 0;
|
|
18486
|
+
view.shakeY = 0;
|
|
18487
|
+
view.camera(def);
|
|
18488
|
+
view.P(0, 0, 0);
|
|
18489
|
+
const pivot = { x: Math.round(view.px), y: Math.round(view.py) };
|
|
18490
|
+
const timing = lib.engine.timing(def, view.tune);
|
|
18491
|
+
const count = Math.max(1, Math.round(timing.length * fps));
|
|
18492
|
+
const frames = [];
|
|
18493
|
+
for (let index = 0; index < count; index++) {
|
|
18494
|
+
view.renderAt(def, lib.engine.frameTime(index / count * timing.length, camera), timing);
|
|
18495
|
+
frames.push(Buffer.from(view.pix.buffer.slice(0)));
|
|
18496
|
+
}
|
|
18497
|
+
const cropped = cropFrames(frames, canvasWidth, canvasHeight, pivot, recipe.margin ?? 0);
|
|
18498
|
+
return { effect: info, fps, loop: true, ...cropped };
|
|
18499
|
+
}
|
|
18500
|
+
async function readCodexRecipe(file, opts = {}) {
|
|
18501
|
+
const parsed = JSON.parse(await readFile15(file, "utf8"));
|
|
18502
|
+
const record = parsed.tool === CODEX_ID;
|
|
18503
|
+
if (!record && !(opts.bare && parsed.tool === void 0)) return null;
|
|
18504
|
+
const raw = record ? parsed.recipe : parsed;
|
|
18505
|
+
if (!raw || typeof raw !== "object" || typeof raw.effect !== "string" || Array.isArray(raw.layers)) {
|
|
18506
|
+
if (record) throw new Error(`${file} is a codex record with no recipe naming an effect`);
|
|
18507
|
+
return null;
|
|
18508
|
+
}
|
|
18509
|
+
const recipe = { effect: raw.effect };
|
|
18510
|
+
if (raw.camera !== void 0) recipe.camera = raw.camera;
|
|
18511
|
+
for (const key2 of ["fps", "margin", "hue"]) if (raw[key2] !== void 0) recipe[key2] = raw[key2];
|
|
18512
|
+
for (const key2 of ["params", "tune"]) {
|
|
18513
|
+
const value = raw[key2];
|
|
18514
|
+
if (value === void 0) continue;
|
|
18515
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`${file}: a codex recipe's ${key2} is an object`);
|
|
18516
|
+
recipe[key2] = value;
|
|
18517
|
+
}
|
|
18518
|
+
const library = record ? parsed.library : void 0;
|
|
18519
|
+
return {
|
|
18520
|
+
recipe,
|
|
18521
|
+
...typeof library?.version === "string" ? { libraryVersion: library.version } : {},
|
|
18522
|
+
...typeof library?.engineSha256 === "string" ? { engineSha256: library.engineSha256 } : {}
|
|
18222
18523
|
};
|
|
18223
|
-
|
|
18224
|
-
|
|
18225
|
-
|
|
18524
|
+
}
|
|
18525
|
+
async function makeCodexVfx(lib, opts) {
|
|
18526
|
+
const recipe = {
|
|
18226
18527
|
effect: opts.effect,
|
|
18227
|
-
|
|
18228
|
-
|
|
18229
|
-
|
|
18230
|
-
|
|
18231
|
-
|
|
18232
|
-
|
|
18528
|
+
...opts.camera && opts.camera !== "2d" ? { camera: opts.camera } : {},
|
|
18529
|
+
...opts.fps !== void 0 ? { fps: opts.fps } : {},
|
|
18530
|
+
...opts.margin ? { margin: opts.margin } : {},
|
|
18531
|
+
...opts.hue ? { hue: opts.hue } : {},
|
|
18532
|
+
...opts.params && Object.keys(opts.params).length ? { params: opts.params } : {},
|
|
18533
|
+
...opts.tune && Object.keys(opts.tune).length ? { tune: opts.tune } : {}
|
|
18233
18534
|
};
|
|
18234
|
-
|
|
18235
|
-
|
|
18236
|
-
|
|
18237
|
-
|
|
18238
|
-
|
|
18239
|
-
|
|
18240
|
-
|
|
18241
|
-
|
|
18242
|
-
|
|
18535
|
+
checkCodexRecipe(lib, recipe);
|
|
18536
|
+
const paths = assertFreshOutputs(opts.out, opts.force);
|
|
18537
|
+
const render = renderCodex(lib, recipe);
|
|
18538
|
+
const library = { name: CODEX_PACKAGE, version: lib.version, engineSha256: lib.engineSha256 };
|
|
18539
|
+
const written = await writeLocalVfx({
|
|
18540
|
+
paths,
|
|
18541
|
+
name: opts.name ?? render.effect.en,
|
|
18542
|
+
effect: opts.effect,
|
|
18543
|
+
render,
|
|
18544
|
+
atlasKey: CODEX_ID,
|
|
18545
|
+
atlasFacts: { version: lib.version, engineSha256: lib.engineSha256, camera: recipe.camera ?? "2d" },
|
|
18546
|
+
record: { provider: CODEX_ID, tool: CODEX_ID, library: { ...library, repository: CODEX_REPOSITORY, license: "MIT" } },
|
|
18243
18547
|
recipe
|
|
18244
|
-
};
|
|
18245
|
-
await mkdir11(path25.dirname(paths.sheet), { recursive: true });
|
|
18246
|
-
await writeFile11(paths.sheet, sheet.png);
|
|
18247
|
-
await writeFile11(paths.atlas, `${JSON.stringify(atlas, null, 2)}
|
|
18248
|
-
`);
|
|
18249
|
-
await writeFile11(paths.provenance, `${JSON.stringify(provenance, null, 2)}
|
|
18250
|
-
`);
|
|
18548
|
+
});
|
|
18251
18549
|
return {
|
|
18252
|
-
provider:
|
|
18253
|
-
library
|
|
18254
|
-
...facts,
|
|
18255
|
-
columns:
|
|
18256
|
-
sheetSha256,
|
|
18257
|
-
paths:
|
|
18550
|
+
provider: CODEX_ID,
|
|
18551
|
+
library,
|
|
18552
|
+
...written.facts,
|
|
18553
|
+
columns: written.columns,
|
|
18554
|
+
sheetSha256: written.sheetSha256,
|
|
18555
|
+
paths: written.paths,
|
|
18258
18556
|
recipe
|
|
18259
18557
|
};
|
|
18260
18558
|
}
|
|
18261
18559
|
|
|
18262
18560
|
// src/pipeline/quality-regression.ts
|
|
18263
|
-
import
|
|
18264
|
-
import { existsSync as
|
|
18265
|
-
import { readFile as
|
|
18561
|
+
import path28 from "path";
|
|
18562
|
+
import { existsSync as existsSync23 } from "fs";
|
|
18563
|
+
import { readFile as readFile16 } from "fs/promises";
|
|
18266
18564
|
import { z as z6 } from "zod";
|
|
18267
18565
|
var SHA256_RE2 = /^[0-9a-f]{64}$/;
|
|
18268
18566
|
var HEX_RE = /^#[0-9a-f]{6}$/;
|
|
18269
18567
|
var MAX_REDMEAN_DISTANCE = 765;
|
|
18270
18568
|
var QualityPathSchema = z6.string().min(1).refine(
|
|
18271
|
-
(value) => !
|
|
18569
|
+
(value) => !path28.posix.isAbsolute(value) && !value.includes("\\"),
|
|
18272
18570
|
"expected a portable relative path"
|
|
18273
18571
|
);
|
|
18274
18572
|
var DEFAULT_QUALITY_TOLERANCES = {
|
|
@@ -18415,10 +18713,10 @@ function measureDecodedImageQuality(png, digest2) {
|
|
|
18415
18713
|
};
|
|
18416
18714
|
}
|
|
18417
18715
|
async function measureImageQuality(file) {
|
|
18418
|
-
const absolute =
|
|
18716
|
+
const absolute = path28.resolve(file);
|
|
18419
18717
|
let bytes;
|
|
18420
18718
|
try {
|
|
18421
|
-
bytes = await
|
|
18719
|
+
bytes = await readFile16(absolute);
|
|
18422
18720
|
} catch (error) {
|
|
18423
18721
|
throw new Error(`Cannot read quality image ${absolute}: ${message4(error)}`, { cause: error });
|
|
18424
18722
|
}
|
|
@@ -18437,11 +18735,11 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
18437
18735
|
}
|
|
18438
18736
|
const ids = parsed.data.map((entry) => entry.id);
|
|
18439
18737
|
if (new Set(ids).size !== ids.length) throw new Error("--inputs contains a duplicate quality case id.");
|
|
18440
|
-
const root =
|
|
18738
|
+
const root = path28.dirname(path28.resolve(inputsFilePath));
|
|
18441
18739
|
return parsed.data.map((entry) => ({
|
|
18442
18740
|
id: entry.id,
|
|
18443
|
-
file:
|
|
18444
|
-
...entry.record ? { record:
|
|
18741
|
+
file: path28.resolve(root, entry.path),
|
|
18742
|
+
...entry.record ? { record: path28.resolve(root, entry.record) } : {},
|
|
18445
18743
|
tolerances: QualityToleranceSchema.parse({
|
|
18446
18744
|
...DEFAULT_QUALITY_TOLERANCES,
|
|
18447
18745
|
...entry.tolerances
|
|
@@ -18449,7 +18747,7 @@ function resolveQualityInputs(raw, inputsFilePath) {
|
|
|
18449
18747
|
}));
|
|
18450
18748
|
}
|
|
18451
18749
|
function portableRelative2(from, to) {
|
|
18452
|
-
return
|
|
18750
|
+
return path28.relative(from, path28.resolve(to)).split(path28.sep).join("/") || ".";
|
|
18453
18751
|
}
|
|
18454
18752
|
async function verifyRecordForImage(recordPath, imagePath) {
|
|
18455
18753
|
const verification = await verifyArtifactBundle(recordPath);
|
|
@@ -18464,20 +18762,20 @@ async function verifyRecordForImage(recordPath, imagePath) {
|
|
|
18464
18762
|
if (record.kind !== "refine" || options === null || typeof options !== "object" || options.schema !== "pixelkiln-quality") {
|
|
18465
18763
|
throw new Error(`Quality record ${recordPath} is not a PixelKiln refinement record.`);
|
|
18466
18764
|
}
|
|
18467
|
-
const outputs = record.outputs.map((output) =>
|
|
18468
|
-
if (!outputs.includes(
|
|
18765
|
+
const outputs = record.outputs.map((output) => path28.resolve(path28.dirname(recordPath), output.path));
|
|
18766
|
+
if (!outputs.includes(path28.resolve(imagePath))) {
|
|
18469
18767
|
throw new Error(`Quality record ${recordPath} does not own ${imagePath}.`);
|
|
18470
18768
|
}
|
|
18471
18769
|
}
|
|
18472
18770
|
async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
18473
18771
|
if (!inputs.length) throw new Error("Cannot snapshot an empty quality baseline.");
|
|
18474
|
-
const absolute =
|
|
18772
|
+
const absolute = path28.resolve(baselinePath);
|
|
18475
18773
|
for (const input of inputs) {
|
|
18476
|
-
if (
|
|
18774
|
+
if (path28.resolve(input.file) === absolute || input.record && path28.resolve(input.record) === absolute) {
|
|
18477
18775
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
18478
18776
|
}
|
|
18479
18777
|
}
|
|
18480
|
-
const root =
|
|
18778
|
+
const root = path28.dirname(absolute);
|
|
18481
18779
|
const cases = [];
|
|
18482
18780
|
for (const input of [...inputs].sort((a, b) => a.id.localeCompare(b.id))) {
|
|
18483
18781
|
const expected = await measureImageQuality(input.file);
|
|
@@ -18504,8 +18802,8 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
18504
18802
|
cases
|
|
18505
18803
|
});
|
|
18506
18804
|
const data = Buffer.from(JSON.stringify(baseline, null, 2) + "\n");
|
|
18507
|
-
if (
|
|
18508
|
-
const current = await
|
|
18805
|
+
if (existsSync23(absolute) && !options.force) {
|
|
18806
|
+
const current = await readFile16(absolute);
|
|
18509
18807
|
if (!current.equals(data)) {
|
|
18510
18808
|
throw new OverwriteRefusedError(
|
|
18511
18809
|
`Quality baseline already exists with different content: ${absolute}. Pass --force to replace it.`,
|
|
@@ -18517,13 +18815,13 @@ async function snapshotQualityBaseline(inputs, baselinePath, options = {}) {
|
|
|
18517
18815
|
return { baseline, path: absolute, changed: result.changed.length > 0 };
|
|
18518
18816
|
}
|
|
18519
18817
|
async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
18520
|
-
const absolute =
|
|
18521
|
-
if (!
|
|
18818
|
+
const absolute = path28.resolve(baselinePath);
|
|
18819
|
+
if (!existsSync23(absolute)) {
|
|
18522
18820
|
throw new Error(`quality snapshot --only updates an existing baseline; ${absolute} does not exist. Run a full snapshot first.`);
|
|
18523
18821
|
}
|
|
18524
18822
|
let raw;
|
|
18525
18823
|
try {
|
|
18526
|
-
raw = JSON.parse(await
|
|
18824
|
+
raw = JSON.parse(await readFile16(absolute, "utf8"));
|
|
18527
18825
|
} catch (error) {
|
|
18528
18826
|
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
18529
18827
|
}
|
|
@@ -18533,12 +18831,12 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
18533
18831
|
if (unknown.length) {
|
|
18534
18832
|
throw new Error(`--only names ${unknown.join(", ")}, which the quality inputs do not list. Known: ${[...byId.keys()].sort().join(", ")}`);
|
|
18535
18833
|
}
|
|
18536
|
-
const root =
|
|
18834
|
+
const root = path28.dirname(absolute);
|
|
18537
18835
|
const cases = [...raw.cases];
|
|
18538
18836
|
const report = [];
|
|
18539
18837
|
for (const id of only) {
|
|
18540
18838
|
const input = byId.get(id);
|
|
18541
|
-
if (
|
|
18839
|
+
if (path28.resolve(input.file) === absolute || input.record && path28.resolve(input.record) === absolute) {
|
|
18542
18840
|
throw new Error(`Quality baseline output would overwrite an input: ${absolute}.`);
|
|
18543
18841
|
}
|
|
18544
18842
|
const expected = await measureImageQuality(input.file);
|
|
@@ -18568,16 +18866,16 @@ async function snapshotQualityCases(inputs, baselinePath, only, options = {}) {
|
|
|
18568
18866
|
}
|
|
18569
18867
|
const baseline = QualityBaselineSchema.parse({ ...raw, cases });
|
|
18570
18868
|
const data = Buffer.from(JSON.stringify({ ...raw, cases }, null, 2) + "\n");
|
|
18571
|
-
const current = await
|
|
18869
|
+
const current = await readFile16(absolute);
|
|
18572
18870
|
const changed = !current.equals(data);
|
|
18573
18871
|
if (changed && !options.dryRun) await writeArtifactBundle([{ path: absolute, data }]);
|
|
18574
18872
|
return { baseline, path: absolute, changed, cases: report };
|
|
18575
18873
|
}
|
|
18576
18874
|
async function readQualityBaseline(baselinePath) {
|
|
18577
|
-
const absolute =
|
|
18875
|
+
const absolute = path28.resolve(baselinePath);
|
|
18578
18876
|
let raw;
|
|
18579
18877
|
try {
|
|
18580
|
-
raw = JSON.parse(await
|
|
18878
|
+
raw = JSON.parse(await readFile16(absolute, "utf8"));
|
|
18581
18879
|
} catch (error) {
|
|
18582
18880
|
throw new Error(`Could not read quality baseline ${absolute}: ${message4(error)}`, { cause: error });
|
|
18583
18881
|
}
|
|
@@ -18599,7 +18897,7 @@ async function readQualityBaseline(baselinePath) {
|
|
|
18599
18897
|
throw new Error(
|
|
18600
18898
|
`Invalid quality baseline ${absolute}:
|
|
18601
18899
|
` + parsed.error.issues.map((issue) => ` ${where(issue.path)}: ${issue.message}`).join("\n") + (missing.length ? `
|
|
18602
|
-
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${
|
|
18900
|
+
Entries missing fields: re-measure them with \`pixelkiln quality snapshot --inputs <inputs> --out ${path28.basename(absolute)} --only ${missing.join(",")}\` rather than editing the JSON by hand.` : "")
|
|
18603
18901
|
);
|
|
18604
18902
|
}
|
|
18605
18903
|
return parsed.data;
|
|
@@ -18661,12 +18959,12 @@ function regressionViolations(expected, actual, tolerances) {
|
|
|
18661
18959
|
return { violations, warnings };
|
|
18662
18960
|
}
|
|
18663
18961
|
async function checkQualityBaseline(baselinePath) {
|
|
18664
|
-
const absolute =
|
|
18962
|
+
const absolute = path28.resolve(baselinePath);
|
|
18665
18963
|
const baseline = await readQualityBaseline(absolute);
|
|
18666
|
-
const root =
|
|
18964
|
+
const root = path28.dirname(absolute);
|
|
18667
18965
|
const cases = [];
|
|
18668
18966
|
for (const entry of baseline.cases) {
|
|
18669
|
-
const file =
|
|
18967
|
+
const file = path28.resolve(root, entry.file);
|
|
18670
18968
|
let actual = null;
|
|
18671
18969
|
const violations = [];
|
|
18672
18970
|
const warnings = [];
|
|
@@ -18679,7 +18977,7 @@ async function checkQualityBaseline(baselinePath) {
|
|
|
18679
18977
|
violations.push(message4(error));
|
|
18680
18978
|
}
|
|
18681
18979
|
if (entry.record) {
|
|
18682
|
-
const recordPath =
|
|
18980
|
+
const recordPath = path28.resolve(root, entry.record.path);
|
|
18683
18981
|
try {
|
|
18684
18982
|
const recordHash = await sha256File(recordPath);
|
|
18685
18983
|
if (recordHash !== entry.record.sha256) violations.push("quality record hash changed");
|
|
@@ -18715,13 +19013,13 @@ async function checkQualityBaseline(baselinePath) {
|
|
|
18715
19013
|
}
|
|
18716
19014
|
|
|
18717
19015
|
// src/pipeline/cache-health.ts
|
|
18718
|
-
import { existsSync as
|
|
18719
|
-
import { readFile as
|
|
18720
|
-
import
|
|
19016
|
+
import { existsSync as existsSync27 } from "fs";
|
|
19017
|
+
import { readFile as readFile19, readdir as readdir3, rm as rm6 } from "fs/promises";
|
|
19018
|
+
import path31 from "path";
|
|
18721
19019
|
|
|
18722
19020
|
// src/cache.ts
|
|
18723
|
-
import { mkdir as mkdir12, readFile as
|
|
18724
|
-
import { existsSync as
|
|
19021
|
+
import { mkdir as mkdir12, readFile as readFile17, rename as rename6, rm as rm4, writeFile as writeFile12 } from "fs/promises";
|
|
19022
|
+
import { existsSync as existsSync24 } from "fs";
|
|
18725
19023
|
import pathModule from "path";
|
|
18726
19024
|
import { z as z7 } from "zod";
|
|
18727
19025
|
var HashCacheSchema = z7.object({
|
|
@@ -18736,10 +19034,10 @@ function isSha256Hash(value) {
|
|
|
18736
19034
|
function parseCache(value) {
|
|
18737
19035
|
return HashCacheSchema.parse(value);
|
|
18738
19036
|
}
|
|
18739
|
-
async function loadCache(
|
|
18740
|
-
if (!
|
|
19037
|
+
async function loadCache(path53) {
|
|
19038
|
+
if (!existsSync24(path53)) return { version: 1, hashes: {} };
|
|
18741
19039
|
try {
|
|
18742
|
-
const parsed = HashCacheSchema.safeParse(JSON.parse(await
|
|
19040
|
+
const parsed = HashCacheSchema.safeParse(JSON.parse(await readFile17(path53, "utf8")));
|
|
18743
19041
|
if (!parsed.success) return { version: 1, hashes: {} };
|
|
18744
19042
|
return {
|
|
18745
19043
|
version: 1,
|
|
@@ -18751,18 +19049,18 @@ async function loadCache(path51) {
|
|
|
18751
19049
|
return { version: 1, hashes: {} };
|
|
18752
19050
|
}
|
|
18753
19051
|
}
|
|
18754
|
-
async function saveCache(
|
|
19052
|
+
async function saveCache(path53, cache) {
|
|
18755
19053
|
const sorted = {};
|
|
18756
19054
|
for (const key2 of Object.keys(cache.hashes).sort()) {
|
|
18757
19055
|
const hash = cache.hashes[key2];
|
|
18758
19056
|
if (!isSha256Hash(hash)) throw new Error(`Refusing to cache invalid SHA-256 for ${key2}`);
|
|
18759
19057
|
sorted[key2] = hash;
|
|
18760
19058
|
}
|
|
18761
|
-
await mkdir12(pathModule.dirname(pathModule.resolve(
|
|
18762
|
-
const tmp = `${
|
|
19059
|
+
await mkdir12(pathModule.dirname(pathModule.resolve(path53)), { recursive: true });
|
|
19060
|
+
const tmp = `${path53}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
18763
19061
|
try {
|
|
18764
19062
|
await writeFile12(tmp, JSON.stringify({ version: 1, hashes: sorted }, null, 2) + "\n");
|
|
18765
|
-
await rename6(tmp,
|
|
19063
|
+
await rename6(tmp, path53);
|
|
18766
19064
|
} finally {
|
|
18767
19065
|
await rm4(tmp, { force: true });
|
|
18768
19066
|
}
|
|
@@ -18786,20 +19084,20 @@ function cachePathFor(lockPath) {
|
|
|
18786
19084
|
}
|
|
18787
19085
|
|
|
18788
19086
|
// src/pipeline/history.ts
|
|
18789
|
-
import { existsSync as
|
|
18790
|
-
import
|
|
19087
|
+
import { existsSync as existsSync26 } from "fs";
|
|
19088
|
+
import path30 from "path";
|
|
18791
19089
|
|
|
18792
19090
|
// src/pipeline/fetch.ts
|
|
18793
|
-
import { existsSync as
|
|
18794
|
-
import { mkdir as mkdir13, readFile as
|
|
18795
|
-
import
|
|
19091
|
+
import { existsSync as existsSync25, readFileSync as readFileSync7 } from "fs";
|
|
19092
|
+
import { mkdir as mkdir13, readFile as readFile18, rename as rename7, rm as rm5, writeFile as writeFile13 } from "fs/promises";
|
|
19093
|
+
import path29 from "path";
|
|
18796
19094
|
async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
18797
19095
|
const log = opts.onProgress ?? (() => {
|
|
18798
19096
|
});
|
|
18799
19097
|
const result = { downloaded: 0, skipped: 0, failed: 0, ...opts.refresh ? { unchanged: 0 } : {} };
|
|
18800
19098
|
const specByKey = new Map(specs.map((s) => [lockKey(s.styleId, s.assetId), s]));
|
|
18801
19099
|
normalizeLockOutputPaths(lock, specs);
|
|
18802
|
-
const cacheDir = opts.cacheDir === false ? null :
|
|
19100
|
+
const cacheDir = opts.cacheDir === false ? null : path29.resolve(opts.cacheDir ?? path29.join(path29.dirname(lockPath), ".pixelkiln", "cache"));
|
|
18803
19101
|
const pending = Object.entries(lock.entries).filter(([key2, e]) => {
|
|
18804
19102
|
if (e.provider !== provider.id || !specByKey.has(key2)) return false;
|
|
18805
19103
|
if (specByKey.get(key2)?.mirror) return false;
|
|
@@ -18812,15 +19110,15 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
18812
19110
|
if (spec && e.specHash === spec.specHash && e.outputs.length && !postprocessCurrent(e, spec)) {
|
|
18813
19111
|
return Boolean(opts.force) || e.outputs.every((output) => {
|
|
18814
19112
|
const file = resolveOutputPath(output.path, spec.root);
|
|
18815
|
-
return
|
|
19113
|
+
return existsSync25(file) && sha256(readFileSync7(file)) === output.sha256;
|
|
18816
19114
|
});
|
|
18817
19115
|
}
|
|
18818
19116
|
if (!opts.repair) return false;
|
|
18819
19117
|
if (e.outputs.length === 0 || !spec) return true;
|
|
18820
19118
|
return e.outputs.some((output) => {
|
|
18821
19119
|
const file = resolveOutputPath(output.path, spec.root);
|
|
18822
|
-
if (!
|
|
18823
|
-
const current = sha256(
|
|
19120
|
+
if (!existsSync25(file)) return true;
|
|
19121
|
+
const current = sha256(readFileSync7(file));
|
|
18824
19122
|
if (current === output.sha256) return false;
|
|
18825
19123
|
return Boolean(opts.force) || (e.supersededOutputs ?? []).some((old) => old.sha256 === current);
|
|
18826
19124
|
});
|
|
@@ -18899,8 +19197,8 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
18899
19197
|
}
|
|
18900
19198
|
for (let index = 0; index < parentEntry.outputs.length; index++) {
|
|
18901
19199
|
const file = currentEntryOutputPath(parentEntry, parentSpec, index);
|
|
18902
|
-
if (!
|
|
18903
|
-
reference.push(await
|
|
19200
|
+
if (!existsSync25(file)) throw new Error(`cannot clean ${key2}: ${wanted.despeckle.of}'s rotation is missing on disk: ${file}`);
|
|
19201
|
+
reference.push(await readFile18(file));
|
|
18904
19202
|
}
|
|
18905
19203
|
}
|
|
18906
19204
|
for (let index = 0; index < sources.length; index++) {
|
|
@@ -18916,21 +19214,21 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
18916
19214
|
if (!source.url) throw new Error(`no durable source URL to refresh ${source.role ?? "asset"} from`);
|
|
18917
19215
|
fresh = await provider.download(source.url);
|
|
18918
19216
|
if (recorded && sha256(fresh) === recordedRaw && !reapply) {
|
|
18919
|
-
log(` current ${
|
|
19217
|
+
log(` current ${path29.relative(process.cwd(), target)}`);
|
|
18920
19218
|
outputs.push({ ...recorded, path: portableOutputPath(target, spec.root) });
|
|
18921
19219
|
continue;
|
|
18922
19220
|
}
|
|
18923
19221
|
}
|
|
18924
19222
|
let raw = null;
|
|
18925
19223
|
let final = null;
|
|
18926
|
-
if (
|
|
19224
|
+
if (existsSync25(target)) {
|
|
18927
19225
|
const currentHash = await sha256File(target);
|
|
18928
19226
|
if (recorded && currentHash === recorded.sha256) {
|
|
18929
19227
|
if (!fresh && !reapply) {
|
|
18930
19228
|
if (cacheDir) {
|
|
18931
19229
|
await cacheMedia(
|
|
18932
19230
|
cacheDir,
|
|
18933
|
-
await
|
|
19231
|
+
await readFile18(target),
|
|
18934
19232
|
recorded.mediaType ?? MediaType.PNG,
|
|
18935
19233
|
recorded.sha256
|
|
18936
19234
|
);
|
|
@@ -18939,10 +19237,10 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
18939
19237
|
continue;
|
|
18940
19238
|
}
|
|
18941
19239
|
if (reapply && !fresh) {
|
|
18942
|
-
if (!recorded.raw) raw = await
|
|
18943
|
-
log(` reapply ${
|
|
19240
|
+
if (!recorded.raw) raw = await readFile18(target);
|
|
19241
|
+
log(` reapply ${path29.relative(process.cwd(), target)}`);
|
|
18944
19242
|
} else {
|
|
18945
|
-
log(` changed ${
|
|
19243
|
+
log(` changed ${path29.relative(process.cwd(), target)} (upstream)`);
|
|
18946
19244
|
}
|
|
18947
19245
|
} else {
|
|
18948
19246
|
const superseded = (entry.supersededOutputs ?? []).find(
|
|
@@ -18963,14 +19261,14 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
18963
19261
|
}
|
|
18964
19262
|
if (outgoing && cacheDir) {
|
|
18965
19263
|
try {
|
|
18966
|
-
const oldBytes = await
|
|
19264
|
+
const oldBytes = await readFile18(target);
|
|
18967
19265
|
const oldMediaType = detectMediaType(oldBytes);
|
|
18968
19266
|
if (oldMediaType) await cacheMedia(cacheDir, oldBytes, oldMediaType, currentHash);
|
|
18969
19267
|
} catch {
|
|
18970
19268
|
}
|
|
18971
19269
|
}
|
|
18972
19270
|
log(
|
|
18973
|
-
` replace ${
|
|
19271
|
+
` replace ${path29.relative(process.cwd(), target)}` + (opts.force ? " (--force)" : " (previous tracked generation)")
|
|
18974
19272
|
);
|
|
18975
19273
|
}
|
|
18976
19274
|
}
|
|
@@ -18979,7 +19277,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
18979
19277
|
} else if (!raw && recorded && cacheDir) {
|
|
18980
19278
|
if (!reapply) final = await readCachedMedia(cacheDir, recorded.sha256, expectedMediaType);
|
|
18981
19279
|
if (!final && recordedRaw) raw = await readCachedMedia(cacheDir, recordedRaw, expectedMediaType);
|
|
18982
|
-
if (final || raw) log(` cached ${
|
|
19280
|
+
if (final || raw) log(` cached ${path29.relative(process.cwd(), target)}`);
|
|
18983
19281
|
}
|
|
18984
19282
|
if (!final && !raw) {
|
|
18985
19283
|
if (!source.url) {
|
|
@@ -19005,12 +19303,12 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
19005
19303
|
const processed = applyPostprocess(raw, mediaType, wanted, reference, source.role);
|
|
19006
19304
|
buf = processed.bytes;
|
|
19007
19305
|
if (processed.changed) rawHash = sha256(raw);
|
|
19008
|
-
if (processed.moved?.clipped) log(` moved ${
|
|
19009
|
-
if (processed.removed) log(` cleaned ${
|
|
19010
|
-
if (processed.snapped) log(` snapped ${
|
|
19306
|
+
if (processed.moved?.clipped) log(` moved ${path29.relative(process.cwd(), target)}: ${processed.moved.clipped} pixels fell off the canvas; raise layer.padding to keep them`);
|
|
19307
|
+
if (processed.removed) log(` cleaned ${path29.relative(process.cwd(), target)} (${processed.removed} ghost pixels)`);
|
|
19308
|
+
if (processed.snapped) log(` snapped ${path29.relative(process.cwd(), target)} to ${wanted.palette.colors.length} colours`);
|
|
19011
19309
|
}
|
|
19012
19310
|
if (cacheDir) await cacheMedia(cacheDir, buf, mediaType);
|
|
19013
|
-
await mkdir13(
|
|
19311
|
+
await mkdir13(path29.dirname(target), { recursive: true });
|
|
19014
19312
|
const tmp = `${target}.pixelkiln.tmp`;
|
|
19015
19313
|
await writeFile13(tmp, buf);
|
|
19016
19314
|
outputs.push({
|
|
@@ -19024,7 +19322,7 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
19024
19322
|
await saveLock(lockPath, lock);
|
|
19025
19323
|
await rename7(tmp, target);
|
|
19026
19324
|
wrote = true;
|
|
19027
|
-
log(` wrote ${
|
|
19325
|
+
log(` wrote ${path29.relative(process.cwd(), target)}`);
|
|
19028
19326
|
}
|
|
19029
19327
|
if (opts.refresh && !wrote) {
|
|
19030
19328
|
if (rotated) {
|
|
@@ -19068,10 +19366,10 @@ async function fetchAssets(provider, specs, lock, lockPath, opts = {}) {
|
|
|
19068
19366
|
return result;
|
|
19069
19367
|
}
|
|
19070
19368
|
async function readCachedMedia(cacheDir, hash, mediaType) {
|
|
19071
|
-
const file =
|
|
19072
|
-
if (!
|
|
19369
|
+
const file = path29.join(cacheDir, cacheFileName(hash, mediaType));
|
|
19370
|
+
if (!existsSync25(file)) return null;
|
|
19073
19371
|
try {
|
|
19074
|
-
const buf = await
|
|
19372
|
+
const buf = await readFile18(file);
|
|
19075
19373
|
if (sha256(buf) !== hash) return null;
|
|
19076
19374
|
validateMedia(buf, mediaType);
|
|
19077
19375
|
return buf;
|
|
@@ -19082,7 +19380,7 @@ async function readCachedMedia(cacheDir, hash, mediaType) {
|
|
|
19082
19380
|
async function cacheMedia(cacheDir, buf, mediaType, knownHash) {
|
|
19083
19381
|
const hash = knownHash ?? sha256(buf);
|
|
19084
19382
|
validateMedia(buf, mediaType);
|
|
19085
|
-
const file =
|
|
19383
|
+
const file = path29.join(cacheDir, cacheFileName(hash, mediaType));
|
|
19086
19384
|
if (await readCachedMedia(cacheDir, hash, mediaType)) return;
|
|
19087
19385
|
await mkdir13(cacheDir, { recursive: true });
|
|
19088
19386
|
const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
@@ -19090,7 +19388,7 @@ async function cacheMedia(cacheDir, buf, mediaType, knownHash) {
|
|
|
19090
19388
|
try {
|
|
19091
19389
|
await rename7(tmp, file);
|
|
19092
19390
|
} catch (err) {
|
|
19093
|
-
if (!
|
|
19391
|
+
if (!existsSync25(file)) throw err;
|
|
19094
19392
|
} finally {
|
|
19095
19393
|
await rm5(tmp, { force: true });
|
|
19096
19394
|
}
|
|
@@ -19214,10 +19512,10 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
|
19214
19512
|
}
|
|
19215
19513
|
for (let i = 0; i < entry.outputs.length; i++) {
|
|
19216
19514
|
const file = currentEntryOutputPath(entry, spec, i);
|
|
19217
|
-
if (!
|
|
19515
|
+
if (!existsSync26(file)) continue;
|
|
19218
19516
|
if (await sha256File(file) !== entry.outputs[i].sha256 && !opts.force) {
|
|
19219
19517
|
throw new OverwriteRefusedError(
|
|
19220
|
-
`${
|
|
19518
|
+
`${path30.relative(process.cwd(), file)} was changed after download; keep it with pixelkiln edit, or pass --force to replace it`,
|
|
19221
19519
|
[file]
|
|
19222
19520
|
);
|
|
19223
19521
|
}
|
|
@@ -19281,11 +19579,11 @@ async function revertGeneration(provider, spec, lock, lockPath, opts) {
|
|
|
19281
19579
|
|
|
19282
19580
|
// src/pipeline/cache-health.ts
|
|
19283
19581
|
async function inspectCaches(lock, lockPath, options = {}) {
|
|
19284
|
-
if (options.prune && !
|
|
19285
|
-
throw new Error(`Refusing to prune without an existing lockfile at ${
|
|
19582
|
+
if (options.prune && !existsSync27(lockPath)) {
|
|
19583
|
+
throw new Error(`Refusing to prune without an existing lockfile at ${path31.resolve(lockPath)}`);
|
|
19286
19584
|
}
|
|
19287
|
-
const contentDir =
|
|
19288
|
-
const remotePath =
|
|
19585
|
+
const contentDir = path31.resolve(path31.dirname(lockPath), ".pixelkiln", "cache");
|
|
19586
|
+
const remotePath = path31.resolve(cachePathFor(lockPath));
|
|
19289
19587
|
const referenced = referencedHashes(lock);
|
|
19290
19588
|
let content = await inspectContentCache(contentDir, referenced);
|
|
19291
19589
|
let remoteHashes = await inspectRemoteHashCache(remotePath);
|
|
@@ -19297,7 +19595,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
19297
19595
|
]);
|
|
19298
19596
|
for (const name of names) {
|
|
19299
19597
|
try {
|
|
19300
|
-
await rm6(
|
|
19598
|
+
await rm6(path31.join(contentDir, name), { force: true });
|
|
19301
19599
|
removed.contentFiles++;
|
|
19302
19600
|
} catch {
|
|
19303
19601
|
}
|
|
@@ -19306,7 +19604,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
19306
19604
|
await saveCache(remotePath, { version: 1, hashes: {} });
|
|
19307
19605
|
removed.resetRemoteHashCache = true;
|
|
19308
19606
|
} else if (remoteHashes.invalidIds.length) {
|
|
19309
|
-
const cache = parseCache(JSON.parse(await
|
|
19607
|
+
const cache = parseCache(JSON.parse(await readFile19(remotePath, "utf8")));
|
|
19310
19608
|
for (const id of remoteHashes.invalidIds) delete cache.hashes[id];
|
|
19311
19609
|
removed.remoteHashEntries = remoteHashes.invalidIds.length;
|
|
19312
19610
|
await saveCache(remotePath, cache);
|
|
@@ -19324,7 +19622,7 @@ async function inspectCaches(lock, lockPath, options = {}) {
|
|
|
19324
19622
|
async function inspectContentCache(contentDir, referenced) {
|
|
19325
19623
|
const report = {
|
|
19326
19624
|
path: contentDir,
|
|
19327
|
-
exists:
|
|
19625
|
+
exists: existsSync27(contentDir),
|
|
19328
19626
|
files: 0,
|
|
19329
19627
|
bytes: 0,
|
|
19330
19628
|
valid: 0,
|
|
@@ -19345,12 +19643,12 @@ async function inspectContentCache(contentDir, referenced) {
|
|
|
19345
19643
|
continue;
|
|
19346
19644
|
}
|
|
19347
19645
|
report.files++;
|
|
19348
|
-
const file =
|
|
19646
|
+
const file = path31.join(contentDir, entry.name);
|
|
19349
19647
|
const mediaType = mediaTypeFromExtension(entry.name);
|
|
19350
19648
|
const expected = mediaType ? entry.name.slice(0, -4) : "";
|
|
19351
19649
|
let bytes;
|
|
19352
19650
|
try {
|
|
19353
|
-
bytes = await
|
|
19651
|
+
bytes = await readFile19(file);
|
|
19354
19652
|
report.bytes += bytes.length;
|
|
19355
19653
|
} catch (err) {
|
|
19356
19654
|
report.invalid.push({
|
|
@@ -19388,7 +19686,7 @@ async function inspectContentCache(contentDir, referenced) {
|
|
|
19388
19686
|
async function inspectRemoteHashCache(remotePath) {
|
|
19389
19687
|
const report = {
|
|
19390
19688
|
path: remotePath,
|
|
19391
|
-
exists:
|
|
19689
|
+
exists: existsSync27(remotePath),
|
|
19392
19690
|
entries: 0,
|
|
19393
19691
|
valid: 0,
|
|
19394
19692
|
invalidIds: [],
|
|
@@ -19397,7 +19695,7 @@ async function inspectRemoteHashCache(remotePath) {
|
|
|
19397
19695
|
if (!report.exists) return report;
|
|
19398
19696
|
let cache;
|
|
19399
19697
|
try {
|
|
19400
|
-
cache = parseCache(JSON.parse(await
|
|
19698
|
+
cache = parseCache(JSON.parse(await readFile19(remotePath, "utf8")));
|
|
19401
19699
|
} catch (err) {
|
|
19402
19700
|
report.error = err instanceof Error ? err.message : String(err);
|
|
19403
19701
|
return report;
|
|
@@ -19412,20 +19710,20 @@ async function inspectRemoteHashCache(remotePath) {
|
|
|
19412
19710
|
}
|
|
19413
19711
|
|
|
19414
19712
|
// src/pipeline/pack.ts
|
|
19415
|
-
import { readFileSync as
|
|
19416
|
-
import
|
|
19713
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
19714
|
+
import path32 from "path";
|
|
19417
19715
|
var DEFAULT_FRAME_SET_FPS = 12;
|
|
19418
19716
|
function resolvePackInputs(raw, inputsFilePath) {
|
|
19419
19717
|
if (!Array.isArray(raw) || !raw.length) {
|
|
19420
19718
|
throw new Error("--inputs must be a non-empty JSON array of { id, path }");
|
|
19421
19719
|
}
|
|
19422
|
-
const baseDir =
|
|
19720
|
+
const baseDir = path32.dirname(path32.resolve(inputsFilePath));
|
|
19423
19721
|
return raw.map((entry, i) => {
|
|
19424
19722
|
const e = entry;
|
|
19425
19723
|
if (typeof e.id !== "string" || typeof e.path !== "string") {
|
|
19426
19724
|
throw new Error(`--inputs[${i}] needs string "id" and "path"`);
|
|
19427
19725
|
}
|
|
19428
|
-
return { id: e.id, path:
|
|
19726
|
+
return { id: e.id, path: path32.resolve(baseDir, e.path) };
|
|
19429
19727
|
});
|
|
19430
19728
|
}
|
|
19431
19729
|
function packSprites(inputs, options = {}) {
|
|
@@ -19446,7 +19744,7 @@ function packSprites(inputs, options = {}) {
|
|
|
19446
19744
|
for (const input of ordered) {
|
|
19447
19745
|
let sourceHash = null;
|
|
19448
19746
|
try {
|
|
19449
|
-
const bytes =
|
|
19747
|
+
const bytes = readFileSync8(input.path);
|
|
19450
19748
|
sourceHash = sha256(bytes);
|
|
19451
19749
|
const png = decodePng(bytes);
|
|
19452
19750
|
sprites.push({ id: input.id, width: png.width, height: png.height, pixels: png.pixels });
|
|
@@ -19509,7 +19807,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
19509
19807
|
}
|
|
19510
19808
|
const inputs2 = Object.entries(options.sourceOverrides).map(([id, source]) => ({
|
|
19511
19809
|
id,
|
|
19512
|
-
path:
|
|
19810
|
+
path: path32.resolve(source)
|
|
19513
19811
|
}));
|
|
19514
19812
|
if (!inputs2.length) throw new Error(`No approved quality outputs for style "${styleId}".`);
|
|
19515
19813
|
const packed2 = packSprites(inputs2, options);
|
|
@@ -19541,7 +19839,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
19541
19839
|
let outputs = resolveEntryOutputs(entry, id, manifestDir);
|
|
19542
19840
|
const source = sources[id];
|
|
19543
19841
|
if (source && outputs.length <= 1) {
|
|
19544
|
-
inputs.push({ id, path:
|
|
19842
|
+
inputs.push({ id, path: path32.resolve(manifestDir, source) });
|
|
19545
19843
|
continue;
|
|
19546
19844
|
}
|
|
19547
19845
|
if (source && sourceIsStem(source, entry, manifestDir)) {
|
|
@@ -19578,7 +19876,7 @@ function packStyle(lock, styleId, manifestDir, options = {}) {
|
|
|
19578
19876
|
}
|
|
19579
19877
|
}
|
|
19580
19878
|
for (const [id, source] of Object.entries(sources)) {
|
|
19581
|
-
if (!locked.has(id)) inputs.push({ id, path:
|
|
19879
|
+
if (!locked.has(id)) inputs.push({ id, path: path32.resolve(manifestDir, source) });
|
|
19582
19880
|
}
|
|
19583
19881
|
if (!inputs.length) {
|
|
19584
19882
|
throw new Error(`No readable sprites for style "${styleId}"; ${noOutput.length} skipped.`);
|
|
@@ -19642,7 +19940,7 @@ function mountSprites(placements, options) {
|
|
|
19642
19940
|
for (const p of placements) {
|
|
19643
19941
|
let sourceHash = null;
|
|
19644
19942
|
try {
|
|
19645
|
-
const bytes =
|
|
19943
|
+
const bytes = readFileSync8(p.path);
|
|
19646
19944
|
sourceHash = sha256(bytes);
|
|
19647
19945
|
const png = decodePng(bytes);
|
|
19648
19946
|
if (png.width > cellWidth || png.height > cellHeight) {
|
|
@@ -19713,7 +20011,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
19713
20011
|
const source = sources[id];
|
|
19714
20012
|
const entry = lock.entries[`${styleId}/${id}`];
|
|
19715
20013
|
if (source && !(entry && sourceIsStem(source, entry, manifestDir))) {
|
|
19716
|
-
placements.push({ id, path:
|
|
20014
|
+
placements.push({ id, path: path32.resolve(manifestDir, source), cell });
|
|
19717
20015
|
continue;
|
|
19718
20016
|
}
|
|
19719
20017
|
if (source && entry) {
|
|
@@ -19746,7 +20044,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
19746
20044
|
`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}`
|
|
19747
20045
|
);
|
|
19748
20046
|
}
|
|
19749
|
-
const basePng = mount.base ?
|
|
20047
|
+
const basePng = mount.base ? readFileSync8(path32.resolve(manifestDir, mount.base)) : void 0;
|
|
19750
20048
|
const mounted = mountSprites(placements, {
|
|
19751
20049
|
cellWidth: mount.cellWidth,
|
|
19752
20050
|
cellHeight: mount.cellHeight,
|
|
@@ -19756,7 +20054,7 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
19756
20054
|
...mounted,
|
|
19757
20055
|
sources: mount.base ? [{
|
|
19758
20056
|
id: "$base",
|
|
19759
|
-
path:
|
|
20057
|
+
path: path32.resolve(manifestDir, mount.base),
|
|
19760
20058
|
sha256: sha256(basePng),
|
|
19761
20059
|
included: true
|
|
19762
20060
|
}, ...mounted.sources] : mounted.sources,
|
|
@@ -20616,34 +20914,34 @@ async function poll(provider, lock, lockPath, opts = {}) {
|
|
|
20616
20914
|
}
|
|
20617
20915
|
|
|
20618
20916
|
// src/pipeline/doctor.ts
|
|
20619
|
-
import { constants, existsSync as
|
|
20917
|
+
import { constants, existsSync as existsSync29 } from "fs";
|
|
20620
20918
|
import { access, stat as stat3 } from "fs/promises";
|
|
20621
|
-
import
|
|
20919
|
+
import path34 from "path";
|
|
20622
20920
|
|
|
20623
20921
|
// src/pipeline/install-check.ts
|
|
20624
|
-
import { existsSync as
|
|
20625
|
-
import
|
|
20922
|
+
import { existsSync as existsSync28, readFileSync as readFileSync9 } from "fs";
|
|
20923
|
+
import path33 from "path";
|
|
20626
20924
|
function readJson(file) {
|
|
20627
20925
|
try {
|
|
20628
|
-
return JSON.parse(
|
|
20926
|
+
return JSON.parse(readFileSync9(file, "utf8"));
|
|
20629
20927
|
} catch {
|
|
20630
20928
|
return null;
|
|
20631
20929
|
}
|
|
20632
20930
|
}
|
|
20633
20931
|
function readInstallFacts(manifestDir, running) {
|
|
20634
|
-
let dir =
|
|
20932
|
+
let dir = path33.resolve(manifestDir);
|
|
20635
20933
|
for (let depth = 0; depth < 4; depth++) {
|
|
20636
|
-
const pkg = readJson(
|
|
20934
|
+
const pkg = readJson(path33.join(dir, "package.json"));
|
|
20637
20935
|
if (pkg) {
|
|
20638
20936
|
const pinned = ["dependencies", "devDependencies", "optionalDependencies"].map((field) => pkg[field]?.pixelkiln).find((spec) => typeof spec === "string");
|
|
20639
20937
|
if (pinned) {
|
|
20640
|
-
const installedPkg = readJson(
|
|
20938
|
+
const installedPkg = readJson(path33.join(dir, "node_modules", "pixelkiln", "package.json"));
|
|
20641
20939
|
const installed = typeof installedPkg?.version === "string" ? installedPkg.version : void 0;
|
|
20642
20940
|
return { pinned, installed, running };
|
|
20643
20941
|
}
|
|
20644
20942
|
}
|
|
20645
|
-
const parent =
|
|
20646
|
-
if (parent === dir || !
|
|
20943
|
+
const parent = path33.dirname(dir);
|
|
20944
|
+
if (parent === dir || !existsSync28(parent)) break;
|
|
20647
20945
|
dir = parent;
|
|
20648
20946
|
}
|
|
20649
20947
|
return null;
|
|
@@ -20706,12 +21004,12 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
20706
21004
|
`${entry.kind === "style" ? "styles" : "assets"}.${entry.id} was left out: ${entry.issues.join("; ")}`
|
|
20707
21005
|
);
|
|
20708
21006
|
}
|
|
20709
|
-
const facts = readInstallFacts(
|
|
21007
|
+
const facts = readInstallFacts(path34.dirname(loaded.path), opts.runningVersion !== void 0 ? opts.runningVersion : pixelkilnVersion());
|
|
20710
21008
|
if (facts) for (const finding of checkInstall(facts)) add("install", finding.level, finding.message);
|
|
20711
21009
|
add("lock", "ok", `${Object.keys(lock.entries).length} valid v2 lock entr(ies)`);
|
|
20712
21010
|
const dirs = [...new Set(specs.flatMap((spec) => [
|
|
20713
|
-
|
|
20714
|
-
...spec.quality ? [
|
|
21011
|
+
path34.dirname(spec.outFile),
|
|
21012
|
+
...spec.quality ? [path34.dirname(spec.quality.outFile)] : []
|
|
20715
21013
|
]))];
|
|
20716
21014
|
const unwritable = [];
|
|
20717
21015
|
for (const dir of dirs) {
|
|
@@ -20734,7 +21032,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
20734
21032
|
for (let index = 0; index < entry.outputs.length; index++) {
|
|
20735
21033
|
const output = entry.outputs[index];
|
|
20736
21034
|
const spec = specByKey.get(key2);
|
|
20737
|
-
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path,
|
|
21035
|
+
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path, path34.dirname(lockPath));
|
|
20738
21036
|
const owner = outputOwners.get(absolute);
|
|
20739
21037
|
if (owner && owner !== key2) duplicateOutputs.push(`${output.path} (${owner}, ${key2})`);
|
|
20740
21038
|
outputOwners.set(absolute, key2);
|
|
@@ -20749,7 +21047,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
20749
21047
|
} else {
|
|
20750
21048
|
add("lock-outputs", "ok", `${outputOwners.size} recorded output path(s) are uniquely owned`);
|
|
20751
21049
|
}
|
|
20752
|
-
const cacheDir =
|
|
21050
|
+
const cacheDir = path34.join(path34.dirname(lockPath), ".pixelkiln", "cache");
|
|
20753
21051
|
const stranded = [];
|
|
20754
21052
|
const invalidState = [];
|
|
20755
21053
|
const staleMapUrls = [];
|
|
@@ -20765,11 +21063,11 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
20765
21063
|
const hasSource = Boolean(entry.sourceUrl || entry.sourceUrls?.length);
|
|
20766
21064
|
let hasCache = false;
|
|
20767
21065
|
for (const output of entry.outputs) {
|
|
20768
|
-
const cached2 =
|
|
21066
|
+
const cached2 = path34.join(
|
|
20769
21067
|
cacheDir,
|
|
20770
21068
|
cacheFileName(output.sha256, output.mediaType ?? MediaType.PNG)
|
|
20771
21069
|
);
|
|
20772
|
-
if (
|
|
21070
|
+
if (existsSync29(cached2) && await sha256File(cached2) === output.sha256) {
|
|
20773
21071
|
hasCache = true;
|
|
20774
21072
|
break;
|
|
20775
21073
|
}
|
|
@@ -20865,16 +21163,16 @@ async function nearestExistingDirectory(start) {
|
|
|
20865
21163
|
if ((await stat3(current)).isDirectory()) return current;
|
|
20866
21164
|
} catch {
|
|
20867
21165
|
}
|
|
20868
|
-
const parent =
|
|
21166
|
+
const parent = path34.dirname(current);
|
|
20869
21167
|
if (parent === current) return current;
|
|
20870
21168
|
current = parent;
|
|
20871
21169
|
}
|
|
20872
21170
|
}
|
|
20873
21171
|
|
|
20874
21172
|
// src/pipeline/adopt.ts
|
|
20875
|
-
import { existsSync as
|
|
20876
|
-
import { readFile as
|
|
20877
|
-
import
|
|
21173
|
+
import { existsSync as existsSync30 } from "fs";
|
|
21174
|
+
import { readFile as readFile20, writeFile as writeFile14 } from "fs/promises";
|
|
21175
|
+
import path35 from "path";
|
|
20878
21176
|
async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
20879
21177
|
const log = opts.onProgress ?? (() => {
|
|
20880
21178
|
});
|
|
@@ -20885,11 +21183,11 @@ async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
|
20885
21183
|
const localByHash = /* @__PURE__ */ new Map();
|
|
20886
21184
|
const unmatchedLocal = [];
|
|
20887
21185
|
for (const spec of specs) {
|
|
20888
|
-
if (!
|
|
21186
|
+
if (!existsSync30(spec.outFile)) {
|
|
20889
21187
|
unmatchedLocal.push(`${spec.styleId}/${spec.assetId} (no file at ${spec.outFile})`);
|
|
20890
21188
|
continue;
|
|
20891
21189
|
}
|
|
20892
|
-
const bytes = await
|
|
21190
|
+
const bytes = await readFile20(spec.outFile);
|
|
20893
21191
|
try {
|
|
20894
21192
|
decodePng(bytes);
|
|
20895
21193
|
} catch (err) {
|
|
@@ -21007,9 +21305,9 @@ async function tagAdopted(provider, specs, lock, opts = {}) {
|
|
|
21007
21305
|
}
|
|
21008
21306
|
|
|
21009
21307
|
// src/pipeline/import.ts
|
|
21010
|
-
import { existsSync as
|
|
21011
|
-
import { readFile as
|
|
21012
|
-
import
|
|
21308
|
+
import { existsSync as existsSync31 } from "fs";
|
|
21309
|
+
import { readFile as readFile21 } from "fs/promises";
|
|
21310
|
+
import path36 from "path";
|
|
21013
21311
|
function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
21014
21312
|
const png = decodePng(bytes);
|
|
21015
21313
|
const at2 = now.toISOString();
|
|
@@ -21061,13 +21359,13 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
21061
21359
|
if (opts.objectId && specs.length !== 1) {
|
|
21062
21360
|
throw new Error(`--object-id names one object; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
21063
21361
|
}
|
|
21064
|
-
const cacheDir = opts.cacheDir === false ? null :
|
|
21362
|
+
const cacheDir = opts.cacheDir === false ? null : path36.resolve(opts.cacheDir ?? path36.join(path36.dirname(lockPath), ".pixelkiln", "cache"));
|
|
21065
21363
|
let rawSha256;
|
|
21066
21364
|
let rawBytes;
|
|
21067
21365
|
if (opts.raw) {
|
|
21068
21366
|
if (specs.length !== 1) throw new Error(`--raw names one original; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
21069
21367
|
try {
|
|
21070
|
-
rawBytes = await
|
|
21368
|
+
rawBytes = await readFile21(opts.raw);
|
|
21071
21369
|
decodePng(rawBytes);
|
|
21072
21370
|
} catch (error) {
|
|
21073
21371
|
throw new Error(`--raw ${opts.raw} is not a readable PNG: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
@@ -21083,7 +21381,7 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
21083
21381
|
skipped.push({ key: key2, reason });
|
|
21084
21382
|
continue;
|
|
21085
21383
|
}
|
|
21086
|
-
if (!
|
|
21384
|
+
if (!existsSync31(spec.outFile)) {
|
|
21087
21385
|
skipped.push({ key: key2, reason: `no file at ${spec.outFile}` });
|
|
21088
21386
|
continue;
|
|
21089
21387
|
}
|
|
@@ -21094,7 +21392,7 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
21094
21392
|
let patch;
|
|
21095
21393
|
let bytes;
|
|
21096
21394
|
try {
|
|
21097
|
-
bytes = await
|
|
21395
|
+
bytes = await readFile21(spec.outFile);
|
|
21098
21396
|
patch = buildImportedEntry(spec, bytes, { ...opts, rawSha256 }, /* @__PURE__ */ new Date());
|
|
21099
21397
|
} catch (error) {
|
|
21100
21398
|
skipped.push({ key: key2, reason: `invalid PNG: ${error instanceof Error ? error.message : String(error)}` });
|
|
@@ -21126,7 +21424,7 @@ async function reportSpecHashes(specs, lock) {
|
|
|
21126
21424
|
for (const spec of specs) {
|
|
21127
21425
|
const key2 = lockKey(spec.styleId, spec.assetId);
|
|
21128
21426
|
let bytes = null;
|
|
21129
|
-
if (
|
|
21427
|
+
if (existsSync31(spec.outFile)) bytes = await readFile21(spec.outFile);
|
|
21130
21428
|
let wouldImport = null;
|
|
21131
21429
|
if (bytes && !unimportable(spec)) {
|
|
21132
21430
|
try {
|
|
@@ -21155,13 +21453,13 @@ async function reportSpecHashes(specs, lock) {
|
|
|
21155
21453
|
}
|
|
21156
21454
|
|
|
21157
21455
|
// src/pick/server.ts
|
|
21158
|
-
import { existsSync as
|
|
21159
|
-
import { readFile as
|
|
21456
|
+
import { existsSync as existsSync33 } from "fs";
|
|
21457
|
+
import { readFile as readFile24 } from "fs/promises";
|
|
21160
21458
|
|
|
21161
21459
|
// src/pipeline/init.ts
|
|
21162
|
-
import { readdir as readdir4, readFile as
|
|
21163
|
-
import { existsSync as
|
|
21164
|
-
import
|
|
21460
|
+
import { readdir as readdir4, readFile as readFile22, writeFile as writeFile15 } from "fs/promises";
|
|
21461
|
+
import { existsSync as existsSync32 } from "fs";
|
|
21462
|
+
import path37 from "path";
|
|
21165
21463
|
function pngSize(buf) {
|
|
21166
21464
|
if (buf.length < 24) return null;
|
|
21167
21465
|
const isPng = buf.readUInt32BE(0) === 2303741511 && buf.readUInt32BE(4) === 218765834;
|
|
@@ -21175,7 +21473,7 @@ function slugify(value) {
|
|
|
21175
21473
|
async function walk(dir, exclude) {
|
|
21176
21474
|
const out = [];
|
|
21177
21475
|
for (const entry of await readdir4(dir, { withFileTypes: true })) {
|
|
21178
|
-
const full =
|
|
21476
|
+
const full = path37.join(dir, entry.name);
|
|
21179
21477
|
if (exclude.some((x) => full.includes(x))) continue;
|
|
21180
21478
|
if (entry.isDirectory()) out.push(...await walk(full, exclude));
|
|
21181
21479
|
else if (entry.name.toLowerCase().endsWith(".png")) out.push(full);
|
|
@@ -21189,14 +21487,14 @@ async function scanAssets(root, opts = {}) {
|
|
|
21189
21487
|
const skipped = [];
|
|
21190
21488
|
const seen = /* @__PURE__ */ new Map();
|
|
21191
21489
|
for (const file of files.sort()) {
|
|
21192
|
-
const size = pngSize(await
|
|
21490
|
+
const size = pngSize(await readFile22(file));
|
|
21193
21491
|
if (!size) {
|
|
21194
21492
|
skipped.push(`${file} (not a readable PNG)`);
|
|
21195
21493
|
continue;
|
|
21196
21494
|
}
|
|
21197
|
-
const rel =
|
|
21198
|
-
const category =
|
|
21199
|
-
let id = slugify(
|
|
21495
|
+
const rel = path37.relative(root, file);
|
|
21496
|
+
const category = path37.dirname(rel) === "." ? "" : path37.dirname(rel);
|
|
21497
|
+
let id = slugify(path37.basename(rel));
|
|
21200
21498
|
if (seen.has(id)) {
|
|
21201
21499
|
const n = seen.get(id) + 1;
|
|
21202
21500
|
seen.set(id, n);
|
|
@@ -21670,7 +21968,7 @@ document.getElementById('submit').onclick = async () => {
|
|
|
21670
21968
|
|
|
21671
21969
|
// src/pick/review-server.ts
|
|
21672
21970
|
import { createServer } from "http";
|
|
21673
|
-
import { readFile as
|
|
21971
|
+
import { readFile as readFile23 } from "fs/promises";
|
|
21674
21972
|
function serveReviewPage(opts) {
|
|
21675
21973
|
const log = opts.onProgress ?? (() => {
|
|
21676
21974
|
});
|
|
@@ -21679,7 +21977,7 @@ function serveReviewPage(opts) {
|
|
|
21679
21977
|
if (req.method === "GET" && req.url && opts.assets?.has(req.url)) {
|
|
21680
21978
|
try {
|
|
21681
21979
|
const asset = opts.assets.get(req.url);
|
|
21682
|
-
const bytes = await
|
|
21980
|
+
const bytes = await readFile23(asset.path);
|
|
21683
21981
|
res.writeHead(200, {
|
|
21684
21982
|
"Content-Type": asset.contentType,
|
|
21685
21983
|
"Cache-Control": "no-store",
|
|
@@ -21755,13 +22053,13 @@ async function currentArt(entry, spec) {
|
|
|
21755
22053
|
const previous = primaryOutput({ ...entry, outputs: entry.supersededOutputs });
|
|
21756
22054
|
if (!previous) return null;
|
|
21757
22055
|
const file = resolveOutputPath(previous.path, spec.root);
|
|
21758
|
-
if (!
|
|
22056
|
+
if (!existsSync33(file)) return null;
|
|
21759
22057
|
const contentType = previous.mediaType ?? mediaTypeFromExtension(file);
|
|
21760
22058
|
if (!contentType) return null;
|
|
21761
22059
|
let width = entry.width;
|
|
21762
22060
|
let height = entry.height;
|
|
21763
22061
|
if (contentType === "image/png") {
|
|
21764
|
-
const size = pngSize(await
|
|
22062
|
+
const size = pngSize(await readFile24(file));
|
|
21765
22063
|
if (size) ({ width, height } = size);
|
|
21766
22064
|
}
|
|
21767
22065
|
return { path: file, contentType, width, height };
|
|
@@ -21769,7 +22067,7 @@ async function currentArt(entry, spec) {
|
|
|
21769
22067
|
async function cachedFrame(url) {
|
|
21770
22068
|
if (!url.startsWith("file://")) return null;
|
|
21771
22069
|
const file = url.slice("file://".length);
|
|
21772
|
-
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await
|
|
22070
|
+
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await readFile24(file).catch(() => Buffer.alloc(0))) ?? "application/octet-stream";
|
|
21773
22071
|
return { path: file, contentType };
|
|
21774
22072
|
}
|
|
21775
22073
|
async function prepareReview(provider, lock, opts = {}) {
|
|
@@ -21801,7 +22099,7 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
21801
22099
|
frameSizes.push(null);
|
|
21802
22100
|
continue;
|
|
21803
22101
|
}
|
|
21804
|
-
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await
|
|
22102
|
+
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await readFile24(cached2.path).catch(() => Buffer.alloc(0))) : null);
|
|
21805
22103
|
const route = `${prefix}/review-frame/${encodeURIComponent(String(groups.length))}/${index}`;
|
|
21806
22104
|
frameAssets.push([route, cached2]);
|
|
21807
22105
|
frameUrls.push(route);
|
|
@@ -21954,15 +22252,15 @@ async function runPicker(provider, lock, lockPath, opts = {}) {
|
|
|
21954
22252
|
}
|
|
21955
22253
|
|
|
21956
22254
|
// src/gallery/snapshot.ts
|
|
21957
|
-
import { createHash as
|
|
21958
|
-
import { existsSync as
|
|
21959
|
-
import { readFile as
|
|
21960
|
-
import
|
|
22255
|
+
import { createHash as createHash7 } from "crypto";
|
|
22256
|
+
import { existsSync as existsSync42 } from "fs";
|
|
22257
|
+
import { readFile as readFile34, stat as stat5 } from "fs/promises";
|
|
22258
|
+
import path48 from "path";
|
|
21961
22259
|
|
|
21962
22260
|
// src/gallery/models.ts
|
|
21963
|
-
import { existsSync as
|
|
21964
|
-
import { readFile as
|
|
21965
|
-
import
|
|
22261
|
+
import { existsSync as existsSync37 } from "fs";
|
|
22262
|
+
import { readFile as readFile29, stat as stat4 } from "fs/promises";
|
|
22263
|
+
import path42 from "path";
|
|
21966
22264
|
import { z as z11 } from "zod";
|
|
21967
22265
|
|
|
21968
22266
|
// src/glb.ts
|
|
@@ -22295,11 +22593,11 @@ function modelItems(json) {
|
|
|
22295
22593
|
}
|
|
22296
22594
|
|
|
22297
22595
|
// src/manifest-edit.ts
|
|
22298
|
-
import { readFile as
|
|
22299
|
-
import
|
|
22596
|
+
import { readFile as readFile25, rename as rename8, rm as rm7, writeFile as writeFile16 } from "fs/promises";
|
|
22597
|
+
import path38 from "path";
|
|
22300
22598
|
import { z as z8 } from "zod";
|
|
22301
22599
|
var HexSha = z8.string().regex(/^[0-9a-f]{64}$/);
|
|
22302
|
-
var ProjectFileSchema = z8.string().min(1).refine((file) => !
|
|
22600
|
+
var ProjectFileSchema = z8.string().min(1).refine((file) => !path38.isAbsolute(file) && !file.split(/[\\/]/).includes(".."), "must be a path inside the project");
|
|
22303
22601
|
var AssetPatchSchema = z8.object({
|
|
22304
22602
|
prompt: z8.string().optional(),
|
|
22305
22603
|
/** Per-style override for the style being viewed; null removes it. */
|
|
@@ -22719,8 +23017,8 @@ function applyEdit(raw, edit) {
|
|
|
22719
23017
|
}
|
|
22720
23018
|
}
|
|
22721
23019
|
async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
22722
|
-
const absolute =
|
|
22723
|
-
const original = await
|
|
23020
|
+
const absolute = path38.resolve(manifestPath);
|
|
23021
|
+
const original = await readFile25(absolute, "utf8");
|
|
22724
23022
|
if (sha256(original) !== edit.expectedSha256) throw new ManifestDriftError(absolute);
|
|
22725
23023
|
let raw;
|
|
22726
23024
|
try {
|
|
@@ -22733,9 +23031,9 @@ async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
|
22733
23031
|
applyEdit(raw, edit);
|
|
22734
23032
|
const next = serializeLike(original, raw);
|
|
22735
23033
|
if (next === original) return unchanged(absolute, original);
|
|
22736
|
-
const tmp =
|
|
22737
|
-
|
|
22738
|
-
`.${
|
|
23034
|
+
const tmp = path38.join(
|
|
23035
|
+
path38.dirname(absolute),
|
|
23036
|
+
`.${path38.basename(absolute)}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`
|
|
22739
23037
|
);
|
|
22740
23038
|
try {
|
|
22741
23039
|
await writeFile16(tmp, next);
|
|
@@ -22764,18 +23062,18 @@ async function applyManifestEdit(manifestPath, edit) {
|
|
|
22764
23062
|
}
|
|
22765
23063
|
|
|
22766
23064
|
// src/pipeline/hand-edit.ts
|
|
22767
|
-
import { existsSync as
|
|
22768
|
-
import { copyFile, mkdir as mkdir14, readFile as
|
|
22769
|
-
import
|
|
23065
|
+
import { existsSync as existsSync34 } from "fs";
|
|
23066
|
+
import { copyFile, mkdir as mkdir14, readFile as readFile26, rename as rename9, rm as rm8, writeFile as writeFile17 } from "fs/promises";
|
|
23067
|
+
import path39 from "path";
|
|
22770
23068
|
import { z as z9 } from "zod";
|
|
22771
23069
|
var HAND_EDIT_DIR = "edits";
|
|
22772
23070
|
function handEditPath(loaded, spec) {
|
|
22773
23071
|
const style = loaded.manifest.styles[spec.styleId];
|
|
22774
|
-
const outDir =
|
|
22775
|
-
const relative =
|
|
22776
|
-
const inside2 = relative && !relative.startsWith("..") && !
|
|
22777
|
-
const file = inside2 ? relative :
|
|
22778
|
-
return
|
|
23072
|
+
const outDir = path39.resolve(loaded.root, style?.outDir ?? ".");
|
|
23073
|
+
const relative = path39.relative(outDir, spec.outFile);
|
|
23074
|
+
const inside2 = relative && !relative.startsWith("..") && !path39.isAbsolute(relative);
|
|
23075
|
+
const file = inside2 ? relative : path39.basename(spec.outFile);
|
|
23076
|
+
return path39.join(outDir, HAND_EDIT_DIR, file.replace(/\.gif$/i, ".png"));
|
|
22779
23077
|
}
|
|
22780
23078
|
function handEditBases(spec, lock) {
|
|
22781
23079
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
@@ -22788,10 +23086,10 @@ function handEditBases(spec, lock) {
|
|
|
22788
23086
|
}));
|
|
22789
23087
|
if (members.some((member) => member.mediaType && member.mediaType !== "image/png")) return null;
|
|
22790
23088
|
if (entry.outputs.length === 1 && !primaryOutput(entry)) return null;
|
|
22791
|
-
if (!members.every((member) =>
|
|
23089
|
+
if (!members.every((member) => existsSync34(member.path))) return null;
|
|
22792
23090
|
return members.map(({ role, path: file }) => ({ role, path: file }));
|
|
22793
23091
|
}
|
|
22794
|
-
return
|
|
23092
|
+
return existsSync34(spec.outFile) ? [{ role: null, path: spec.outFile }] : null;
|
|
22795
23093
|
}
|
|
22796
23094
|
function handEditBase(spec, lock) {
|
|
22797
23095
|
const bases = handEditBases(spec, lock);
|
|
@@ -22841,18 +23139,18 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
22841
23139
|
`${spec.styleId}/${spec.assetId} declares ${spec.source}, one committed file placed for the whole set; clear that source (pixelkiln edit detach) to hand-edit the members one by one`
|
|
22842
23140
|
);
|
|
22843
23141
|
}
|
|
22844
|
-
const existing = spec.source ?
|
|
23142
|
+
const existing = spec.source ? path39.resolve(loaded.root, spec.source) : null;
|
|
22845
23143
|
const editPath = existing ?? handEditPath(loaded, spec);
|
|
22846
23144
|
const members = handEditMembers(loaded, spec, lock, editPath);
|
|
22847
23145
|
let created = false;
|
|
22848
23146
|
for (const member of members) {
|
|
22849
|
-
if (
|
|
23147
|
+
if (existsSync34(member.path)) continue;
|
|
22850
23148
|
if (!member.base) {
|
|
22851
23149
|
throw new ManifestEditError(
|
|
22852
23150
|
`${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
|
|
22853
23151
|
);
|
|
22854
23152
|
}
|
|
22855
|
-
await mkdir14(
|
|
23153
|
+
await mkdir14(path39.dirname(member.path), { recursive: true });
|
|
22856
23154
|
await copyFile(member.base, member.path);
|
|
22857
23155
|
created = true;
|
|
22858
23156
|
}
|
|
@@ -22931,7 +23229,7 @@ function handEditProjectPath(editPath) {
|
|
|
22931
23229
|
async function readHandEditCompanion(editPath) {
|
|
22932
23230
|
let text;
|
|
22933
23231
|
try {
|
|
22934
|
-
text = await
|
|
23232
|
+
text = await readFile26(handEditCompanionPath(editPath), "utf8");
|
|
22935
23233
|
} catch {
|
|
22936
23234
|
return null;
|
|
22937
23235
|
}
|
|
@@ -22975,7 +23273,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
22975
23273
|
}
|
|
22976
23274
|
});
|
|
22977
23275
|
const bases = handEditBases(spec, lock);
|
|
22978
|
-
const expectedSize = bases?.[0] ? decodePng(await
|
|
23276
|
+
const expectedSize = bases?.[0] ? decodePng(await readFile26(bases[0].path)) : { width: spec.width, height: spec.height };
|
|
22979
23277
|
for (const [index, image] of decoded.entries()) {
|
|
22980
23278
|
if (image.width !== expectedSize.width || image.height !== expectedSize.height) {
|
|
22981
23279
|
const which = memberSet ? `member ${incoming[index].role ?? index}` : "the edit";
|
|
@@ -22991,7 +23289,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
22991
23289
|
editor: input.editor,
|
|
22992
23290
|
protocol: input.protocol,
|
|
22993
23291
|
savedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
22994
|
-
project: projectPath ?
|
|
23292
|
+
project: projectPath ? path39.basename(projectPath) : null,
|
|
22995
23293
|
outputs: incoming.map((frame, index) => ({
|
|
22996
23294
|
role: frame.role,
|
|
22997
23295
|
basedOn: basedOnHash(entry, index),
|
|
@@ -23034,9 +23332,9 @@ function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
|
|
|
23034
23332
|
|
|
23035
23333
|
// src/pipeline/model-edit.ts
|
|
23036
23334
|
import { spawn as spawn2 } from "child_process";
|
|
23037
|
-
import { existsSync as
|
|
23038
|
-
import { mkdir as mkdir15, readdir as readdir5, readFile as
|
|
23039
|
-
import
|
|
23335
|
+
import { existsSync as existsSync35, readdirSync as readdirSync2 } from "fs";
|
|
23336
|
+
import { mkdir as mkdir15, readdir as readdir5, readFile as readFile27, rename as rename10, rm as rm9, writeFile as writeFile18 } from "fs/promises";
|
|
23337
|
+
import path40 from "path";
|
|
23040
23338
|
import { z as z10 } from "zod";
|
|
23041
23339
|
|
|
23042
23340
|
// src/jpeg.ts
|
|
@@ -23418,7 +23716,7 @@ var MAX_MODELS = 200;
|
|
|
23418
23716
|
var MAX_DEPTH = 8;
|
|
23419
23717
|
var SKIPPED_DIRS = /* @__PURE__ */ new Set([HAND_EDIT_DIR, "node_modules"]);
|
|
23420
23718
|
async function discoverModels(loaded, opts = {}) {
|
|
23421
|
-
const styles = Object.entries(loaded.manifest.styles).filter(([id]) => !opts.styles?.length || opts.styles.includes(id)).map(([id, style]) => ({ id, outDir:
|
|
23719
|
+
const styles = Object.entries(loaded.manifest.styles).filter(([id]) => !opts.styles?.length || opts.styles.includes(id)).map(([id, style]) => ({ id, outDir: path40.resolve(loaded.root, style.outDir ?? ".") })).sort((a, b) => b.outDir.length - a.outDir.length || a.id.localeCompare(b.id));
|
|
23422
23720
|
const seen = /* @__PURE__ */ new Set();
|
|
23423
23721
|
const models = [];
|
|
23424
23722
|
const walk2 = async (styleId, outDir, dir, depth) => {
|
|
@@ -23432,13 +23730,13 @@ async function discoverModels(loaded, opts = {}) {
|
|
|
23432
23730
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
23433
23731
|
for (const entry of entries) {
|
|
23434
23732
|
if (models.length >= MAX_MODELS) return;
|
|
23435
|
-
const full =
|
|
23733
|
+
const full = path40.join(dir, entry.name);
|
|
23436
23734
|
if (entry.isDirectory()) {
|
|
23437
23735
|
if (entry.name.startsWith(".") || SKIPPED_DIRS.has(entry.name)) continue;
|
|
23438
23736
|
await walk2(styleId, outDir, full, depth + 1);
|
|
23439
23737
|
} else if (entry.isFile() && entry.name.toLowerCase().endsWith(MODEL_EXTENSION) && !seen.has(full)) {
|
|
23440
23738
|
seen.add(full);
|
|
23441
|
-
models.push({ styleId, file: full, editFile:
|
|
23739
|
+
models.push({ styleId, file: full, editFile: path40.join(outDir, HAND_EDIT_DIR, path40.relative(outDir, full)) });
|
|
23442
23740
|
}
|
|
23443
23741
|
}
|
|
23444
23742
|
};
|
|
@@ -23446,12 +23744,12 @@ async function discoverModels(loaded, opts = {}) {
|
|
|
23446
23744
|
return models.sort((a, b) => a.styleId.localeCompare(b.styleId) || a.file.localeCompare(b.file));
|
|
23447
23745
|
}
|
|
23448
23746
|
async function findModel(loaded, portablePath) {
|
|
23449
|
-
const wanted =
|
|
23747
|
+
const wanted = path40.resolve(loaded.root, portablePath);
|
|
23450
23748
|
const model = (await discoverModels(loaded)).find((candidate) => candidate.file === wanted);
|
|
23451
23749
|
if (!model) throw new ManifestEditError(`"${portablePath}" is not a model under one of this project's output folders`);
|
|
23452
23750
|
return model;
|
|
23453
23751
|
}
|
|
23454
|
-
var stem = (editFile) => editFile.slice(0, -
|
|
23752
|
+
var stem = (editFile) => editFile.slice(0, -path40.extname(editFile).length);
|
|
23455
23753
|
function modelCompanionPath(editFile) {
|
|
23456
23754
|
return stem(editFile) + ".edit.json";
|
|
23457
23755
|
}
|
|
@@ -23490,13 +23788,17 @@ var ModelEditCompanionSchema = z10.object({
|
|
|
23490
23788
|
}).strict();
|
|
23491
23789
|
async function readModelCompanion(editFile) {
|
|
23492
23790
|
try {
|
|
23493
|
-
return ModelEditCompanionSchema.parse(JSON.parse(await
|
|
23791
|
+
return ModelEditCompanionSchema.parse(JSON.parse(await readFile27(modelCompanionPath(editFile), "utf8")));
|
|
23494
23792
|
} catch {
|
|
23495
23793
|
return null;
|
|
23496
23794
|
}
|
|
23497
23795
|
}
|
|
23796
|
+
function modelEditStatus(companion, builtSha256) {
|
|
23797
|
+
if (!companion) return "unrecorded";
|
|
23798
|
+
return companion.outputs[0].basedOn === builtSha256 ? "edited" : "rebuilt-since";
|
|
23799
|
+
}
|
|
23498
23800
|
async function replaceFile2(file, bytes) {
|
|
23499
|
-
await mkdir15(
|
|
23801
|
+
await mkdir15(path40.dirname(file), { recursive: true });
|
|
23500
23802
|
const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
23501
23803
|
try {
|
|
23502
23804
|
await writeFile18(tmp, bytes);
|
|
@@ -23508,7 +23810,7 @@ async function replaceFile2(file, bytes) {
|
|
|
23508
23810
|
async function readModel(file, what) {
|
|
23509
23811
|
let bytes;
|
|
23510
23812
|
try {
|
|
23511
|
-
bytes = await
|
|
23813
|
+
bytes = await readFile27(file);
|
|
23512
23814
|
} catch {
|
|
23513
23815
|
throw new ManifestEditError(`${what} is not on disk at ${file}`);
|
|
23514
23816
|
}
|
|
@@ -23535,7 +23837,7 @@ async function saveModelTexture(model, input) {
|
|
|
23535
23837
|
throw new ManifestEditError(`the texture is not a valid PNG: ${error instanceof Error ? error.message : String(error)}`);
|
|
23536
23838
|
}
|
|
23537
23839
|
const original = await readModel(model.file, "the model");
|
|
23538
|
-
const created = !
|
|
23840
|
+
const created = !existsSync35(model.editFile);
|
|
23539
23841
|
const base = created ? original : await readModel(model.editFile, "the model's edit");
|
|
23540
23842
|
let current;
|
|
23541
23843
|
try {
|
|
@@ -23557,7 +23859,7 @@ async function saveModelTexture(model, input) {
|
|
|
23557
23859
|
sha256: sha256(input.png),
|
|
23558
23860
|
editor: input.editor,
|
|
23559
23861
|
savedAt,
|
|
23560
|
-
project: projectPath ?
|
|
23862
|
+
project: projectPath ? path40.basename(projectPath) : null
|
|
23561
23863
|
};
|
|
23562
23864
|
const companion = {
|
|
23563
23865
|
version: 2,
|
|
@@ -23580,7 +23882,7 @@ async function adoptModelExport(model, opts = {}) {
|
|
|
23580
23882
|
const mode2 = opts.mode ?? "textures";
|
|
23581
23883
|
const exported = await readModel(from, "the exported model");
|
|
23582
23884
|
const original = await readModel(model.file, "the model");
|
|
23583
|
-
const created = !
|
|
23885
|
+
const created = !existsSync35(model.editFile);
|
|
23584
23886
|
const savedAt = (opts.now ?? /* @__PURE__ */ new Date()).toISOString();
|
|
23585
23887
|
const editor = opts.editor ?? "blender";
|
|
23586
23888
|
const taken = [];
|
|
@@ -23649,9 +23951,9 @@ async function adoptModelExport(model, opts = {}) {
|
|
|
23649
23951
|
await replaceFile2(companionPath, JSON.stringify(companion, null, 2) + "\n");
|
|
23650
23952
|
return { editFile: model.editFile, companionPath, companion, created, mode: mode2, taken };
|
|
23651
23953
|
}
|
|
23652
|
-
function blenderCommand(env = process.env, platform = process.platform, exists =
|
|
23954
|
+
function blenderCommand(env = process.env, platform = process.platform, exists = existsSync35, list = (dir) => {
|
|
23653
23955
|
try {
|
|
23654
|
-
return
|
|
23956
|
+
return readdirSync2(dir);
|
|
23655
23957
|
} catch {
|
|
23656
23958
|
return [];
|
|
23657
23959
|
}
|
|
@@ -23661,16 +23963,16 @@ function blenderCommand(env = process.env, platform = process.platform, exists =
|
|
|
23661
23963
|
const candidates = [];
|
|
23662
23964
|
if (platform === "darwin") {
|
|
23663
23965
|
candidates.push("/Applications/Blender.app/Contents/MacOS/Blender");
|
|
23664
|
-
if (env.HOME) candidates.push(
|
|
23966
|
+
if (env.HOME) candidates.push(path40.join(env.HOME, "Applications/Blender.app/Contents/MacOS/Blender"));
|
|
23665
23967
|
} else if (platform === "win32") {
|
|
23666
23968
|
for (const root of [env.ProgramFiles, env["ProgramFiles(x86)"]].filter((value) => Boolean(value))) {
|
|
23667
|
-
const foundation =
|
|
23969
|
+
const foundation = path40.win32.join(root, "Blender Foundation");
|
|
23668
23970
|
const versions = list(foundation).filter((name) => /^Blender/i.test(name)).sort((a, b) => b.localeCompare(a, void 0, { numeric: true }));
|
|
23669
|
-
for (const version of versions) candidates.push(
|
|
23971
|
+
for (const version of versions) candidates.push(path40.win32.join(foundation, version, "blender.exe"));
|
|
23670
23972
|
}
|
|
23671
23973
|
} else {
|
|
23672
23974
|
candidates.push("/usr/bin/blender", "/usr/local/bin/blender", "/snap/bin/blender", "/var/lib/flatpak/exports/bin/org.blender.Blender");
|
|
23673
|
-
for (const dir of (env.PATH ?? "").split(":").filter(Boolean)) candidates.push(
|
|
23975
|
+
for (const dir of (env.PATH ?? "").split(":").filter(Boolean)) candidates.push(path40.join(dir, "blender"));
|
|
23674
23976
|
}
|
|
23675
23977
|
const found = candidates.find((candidate) => exists(candidate));
|
|
23676
23978
|
return found ? [found] : null;
|
|
@@ -23703,7 +24005,7 @@ function openInBlender(model, opts = {}) {
|
|
|
23703
24005
|
"Blender was not found in its usual place; set PIXELKILN_BLENDER to the program (for example PIXELKILN_BLENDER=/Applications/Blender.app/Contents/MacOS/Blender) and start the gallery again"
|
|
23704
24006
|
);
|
|
23705
24007
|
}
|
|
23706
|
-
const file =
|
|
24008
|
+
const file = existsSync35(model.editFile) ? model.editFile : model.file;
|
|
23707
24009
|
const [program, ...rest] = command;
|
|
23708
24010
|
const args = [...rest, ...blenderArguments(file, modelExportPath(model.editFile))];
|
|
23709
24011
|
const launch = opts.launch ?? ((bin, argv) => {
|
|
@@ -23713,14 +24015,14 @@ function openInBlender(model, opts = {}) {
|
|
|
23713
24015
|
child.unref();
|
|
23714
24016
|
});
|
|
23715
24017
|
launch(program, args);
|
|
23716
|
-
return `${command.join(" ")} (${
|
|
24018
|
+
return `${command.join(" ")} (${path40.basename(file)})`;
|
|
23717
24019
|
}
|
|
23718
24020
|
|
|
23719
24021
|
// src/pipeline/model-normals.ts
|
|
23720
|
-
import { createHash as
|
|
23721
|
-
import { existsSync as
|
|
23722
|
-
import { mkdir as mkdir16, readdir as readdir6, readFile as
|
|
23723
|
-
import
|
|
24022
|
+
import { createHash as createHash6 } from "crypto";
|
|
24023
|
+
import { existsSync as existsSync36 } from "fs";
|
|
24024
|
+
import { mkdir as mkdir16, readdir as readdir6, readFile as readFile28, writeFile as writeFile19 } from "fs/promises";
|
|
24025
|
+
import path41 from "path";
|
|
23724
24026
|
var MODEL_NORMAL_SOURCES = ["texture", "views", "sprites"];
|
|
23725
24027
|
var TILE_MAX = 512;
|
|
23726
24028
|
function decodeImage(bytes) {
|
|
@@ -23812,13 +24114,13 @@ function poseNodes(document, pose) {
|
|
|
23812
24114
|
const posed = /* @__PURE__ */ new Map();
|
|
23813
24115
|
for (const channel of animation.channels) {
|
|
23814
24116
|
const node = channel.target.node;
|
|
23815
|
-
const
|
|
23816
|
-
if (node === void 0 || !["translation", "rotation", "scale"].includes(
|
|
24117
|
+
const path53 = channel.target.path;
|
|
24118
|
+
if (node === void 0 || !["translation", "rotation", "scale"].includes(path53)) continue;
|
|
23817
24119
|
const sampler = animation.samplers[channel.sampler];
|
|
23818
24120
|
if (!sampler) continue;
|
|
23819
24121
|
const times = readAccessor(document, sampler.input).data;
|
|
23820
24122
|
const values = readAccessor(document, sampler.output);
|
|
23821
|
-
const width =
|
|
24123
|
+
const width = path53 === "rotation" ? 4 : 3;
|
|
23822
24124
|
const cubic = sampler.interpolation === "CUBICSPLINE";
|
|
23823
24125
|
const valueAt = (key3) => Array.from(values.data.subarray((cubic ? key3 * 3 + 1 : key3) * width, (cubic ? key3 * 3 + 1 : key3) * width + width));
|
|
23824
24126
|
const last = times.length - 1;
|
|
@@ -23830,16 +24132,16 @@ function poseNodes(document, pose) {
|
|
|
23830
24132
|
const span = times[key2 + 1] - times[key2];
|
|
23831
24133
|
const f = span > 0 ? (time - times[key2]) / span : 0;
|
|
23832
24134
|
const next = valueAt(key2 + 1);
|
|
23833
|
-
const sign =
|
|
24135
|
+
const sign = path53 === "rotation" && value.reduce((sum, v, k) => sum + v * next[k], 0) < 0 ? -1 : 1;
|
|
23834
24136
|
value = value.map((v, k) => v * (1 - f) + next[k] * sign * f);
|
|
23835
24137
|
}
|
|
23836
|
-
if (
|
|
24138
|
+
if (path53 === "rotation") {
|
|
23837
24139
|
const length = Math.hypot(...value) || 1;
|
|
23838
24140
|
value = value.map((v) => v / length);
|
|
23839
24141
|
}
|
|
23840
24142
|
const base = posed.get(node) ?? { ...document.json.nodes?.[node] ?? {} };
|
|
23841
24143
|
if (base.matrix) delete base.matrix;
|
|
23842
|
-
base[
|
|
24144
|
+
base[path53] = value;
|
|
23843
24145
|
posed.set(node, base);
|
|
23844
24146
|
}
|
|
23845
24147
|
return posed;
|
|
@@ -24449,20 +24751,20 @@ function modelSpritesDir(modelFile) {
|
|
|
24449
24751
|
return modelFile.replace(/\.glb$/i, "") + ".sprites";
|
|
24450
24752
|
}
|
|
24451
24753
|
async function readSpriteFolder(dir) {
|
|
24452
|
-
const folder =
|
|
24754
|
+
const folder = existsSync36(path41.join(dir, "rotations")) ? path41.join(dir, "rotations") : dir;
|
|
24453
24755
|
const names = (await readdir6(folder)).filter((name) => name.toLowerCase().endsWith(".png") && VIEW_TURNS[name.slice(0, -4).toLowerCase()] !== void 0).sort();
|
|
24454
|
-
return Promise.all(names.map(async (name) => ({ direction: name.slice(0, -4).toLowerCase(), png: await
|
|
24756
|
+
return Promise.all(names.map(async (name) => ({ direction: name.slice(0, -4).toLowerCase(), png: await readFile28(path41.join(folder, name)), file: path41.join(folder, name) })));
|
|
24455
24757
|
}
|
|
24456
24758
|
function modelNormalDir(editFile) {
|
|
24457
24759
|
return editFile.replace(/\.glb$/i, "") + ".normal-map";
|
|
24458
24760
|
}
|
|
24459
24761
|
function requestKey(png, options) {
|
|
24460
24762
|
const asked = JSON.stringify([options.mode ?? "lite", options.kind ?? null, options.surfaceDetail ?? null, options.detailSoftness ?? null, options.strength ?? null]);
|
|
24461
|
-
return
|
|
24763
|
+
return createHash6("sha256").update(png).update(asked).digest("hex").slice(0, 16);
|
|
24462
24764
|
}
|
|
24463
24765
|
async function prepare(model, opts) {
|
|
24464
|
-
const fromEdit =
|
|
24465
|
-
const document = parseGlb(await
|
|
24766
|
+
const fromEdit = existsSync36(model.editFile);
|
|
24767
|
+
const document = parseGlb(await readFile28(fromEdit ? model.editFile : model.file));
|
|
24466
24768
|
const summary = describeGlb(document);
|
|
24467
24769
|
const normalImages = summary.images.filter((image) => image.roles.includes("normal"));
|
|
24468
24770
|
if (!normalImages.length) throw new Error("the model has no normal maps; this adds detail to one it has, it does not add a new one");
|
|
@@ -24471,14 +24773,14 @@ async function prepare(model, opts) {
|
|
|
24471
24773
|
if (!normalImages.some((image) => image.index === index)) throw new Error(`image ${index} is not one of the model's normal maps`);
|
|
24472
24774
|
}
|
|
24473
24775
|
const primitives = restPrimitives(document, opts.pose);
|
|
24474
|
-
const dir =
|
|
24776
|
+
const dir = path41.join(modelNormalDir(model.editFile), opts.source);
|
|
24475
24777
|
const surfaces = /* @__PURE__ */ new Map();
|
|
24476
24778
|
const tiles = /* @__PURE__ */ new Map();
|
|
24477
24779
|
const calls = [];
|
|
24478
24780
|
const images = [];
|
|
24479
24781
|
const call = (label, png) => {
|
|
24480
|
-
const cache =
|
|
24481
|
-
calls.push({ label, png, cache, cached:
|
|
24782
|
+
const cache = path41.join(dir, `${label.replace(/[^a-z0-9]+/gi, "-")}.${requestKey(png, opts)}.normal.png`);
|
|
24783
|
+
calls.push({ label, png, cache, cached: existsSync36(cache) });
|
|
24482
24784
|
};
|
|
24483
24785
|
for (const index of wanted) {
|
|
24484
24786
|
const summaryImage = summary.images[index];
|
|
@@ -24548,7 +24850,7 @@ async function planModelNormals(model, opts) {
|
|
|
24548
24850
|
const { plan } = await prepare(model, opts);
|
|
24549
24851
|
await mkdir16(plan.dir, { recursive: true });
|
|
24550
24852
|
for (const entry of plan.calls) await writeFile19(entry.cache.replace(/\.[0-9a-f]{16}\.normal\.png$/, ".png"), entry.png);
|
|
24551
|
-
for (const fit of plan.fits ?? []) await writeFile19(
|
|
24853
|
+
for (const fit of plan.fits ?? []) await writeFile19(path41.join(plan.dir, `${fit.label.replace(/[^a-z0-9]+/gi, "-")}.fit.png`), fit.png);
|
|
24552
24854
|
return plan;
|
|
24553
24855
|
}
|
|
24554
24856
|
async function generateModelNormals(model, opts, mapper, hooks = {}) {
|
|
@@ -24568,7 +24870,7 @@ async function generateModelNormals(model, opts, mapper, hooks = {}) {
|
|
|
24568
24870
|
hooks.onCall?.(entry.label, entry.cached);
|
|
24569
24871
|
await writeFile19(entry.cache.replace(/\.[0-9a-f]{16}\.normal\.png$/, ".png"), entry.png);
|
|
24570
24872
|
if (entry.cached) {
|
|
24571
|
-
answers.push(await
|
|
24873
|
+
answers.push(await readFile28(entry.cache));
|
|
24572
24874
|
continue;
|
|
24573
24875
|
}
|
|
24574
24876
|
const answer = await mapper(entry.png, request);
|
|
@@ -24591,13 +24893,13 @@ async function generateModelNormals(model, opts, mapper, hooks = {}) {
|
|
|
24591
24893
|
field = detailFromViews(surface, prepared.views, answers);
|
|
24592
24894
|
}
|
|
24593
24895
|
bleed(field);
|
|
24594
|
-
const detail =
|
|
24896
|
+
const detail = path41.join(plan.dir, `image-${image}.detail.png`);
|
|
24595
24897
|
await writeFile19(detail, encodeImage(fieldImage(field)));
|
|
24596
24898
|
details.push(detail);
|
|
24597
|
-
const basePath =
|
|
24899
|
+
const basePath = path41.join(modelNormalDir(model.editFile), `image-${image}.base.png`);
|
|
24598
24900
|
const record = companion?.textures.find((entry) => entry.image === image);
|
|
24599
|
-
const ours = record?.editor.startsWith(PIXELLAB_EDITOR) === true &&
|
|
24600
|
-
const existing = ours ? decodeImage(await
|
|
24901
|
+
const ours = record?.editor.startsWith(PIXELLAB_EDITOR) === true && existsSync36(basePath);
|
|
24902
|
+
const existing = ours ? decodeImage(await readFile28(basePath)) : decodeImage(glbImageBytes(document, image).bytes);
|
|
24601
24903
|
if (!ours) await writeFile19(basePath, encodeImage(existing));
|
|
24602
24904
|
const png = encodeImage(applyDetail(existing, field, opts));
|
|
24603
24905
|
result = await saveModelTexture(model, {
|
|
@@ -24646,11 +24948,11 @@ async function describeModels(loaded, media, mediaId, opts = {}) {
|
|
|
24646
24948
|
for (const model of await discoverModels(loaded, opts)) {
|
|
24647
24949
|
let bytes;
|
|
24648
24950
|
try {
|
|
24649
|
-
bytes = await
|
|
24951
|
+
bytes = await readFile29(model.file);
|
|
24650
24952
|
} catch {
|
|
24651
24953
|
continue;
|
|
24652
24954
|
}
|
|
24653
|
-
const outDir =
|
|
24955
|
+
const outDir = path42.resolve(root, loaded.manifest.styles[model.styleId]?.outDir ?? ".");
|
|
24654
24956
|
let summary = null;
|
|
24655
24957
|
let error = null;
|
|
24656
24958
|
if (bytes.length > MAX_MODEL_BYTES) error = `the file is ${bytes.length} bytes; models over ${MAX_MODEL_BYTES} are listed but not opened`;
|
|
@@ -24664,16 +24966,16 @@ async function describeModels(loaded, media, mediaId, opts = {}) {
|
|
|
24664
24966
|
const file = await describeFile(media, mediaId, root, model.file, bytes);
|
|
24665
24967
|
let edit = null;
|
|
24666
24968
|
let adoptedExport = null;
|
|
24667
|
-
if (
|
|
24969
|
+
if (existsSync37(model.editFile)) {
|
|
24668
24970
|
try {
|
|
24669
|
-
const editBytes = await
|
|
24971
|
+
const editBytes = await readFile29(model.editFile);
|
|
24670
24972
|
const described = await describeFile(media, mediaId, root, model.editFile, editBytes);
|
|
24671
24973
|
const companion = await readModelCompanion(model.editFile);
|
|
24672
24974
|
adoptedExport = companion?.adoptedExport ?? null;
|
|
24673
24975
|
const textures = (companion?.textures ?? []).map((texture) => {
|
|
24674
24976
|
const projectPath = texture.project ? modelTextureProjectPath(model.editFile, texture.image) : null;
|
|
24675
24977
|
let projectUrl = null;
|
|
24676
|
-
if (projectPath &&
|
|
24978
|
+
if (projectPath && existsSync37(projectPath)) {
|
|
24677
24979
|
const id = mediaId(projectPath);
|
|
24678
24980
|
media.set(id, { path: projectPath, contentType: "application/octet-stream" });
|
|
24679
24981
|
projectUrl = `/media/${id}?v=${texture.sha256.slice(0, 24)}`;
|
|
@@ -24689,7 +24991,7 @@ async function describeModels(loaded, media, mediaId, opts = {}) {
|
|
|
24689
24991
|
});
|
|
24690
24992
|
edit = {
|
|
24691
24993
|
...described,
|
|
24692
|
-
status:
|
|
24994
|
+
status: modelEditStatus(companion, file.sha256),
|
|
24693
24995
|
editor: companion?.editor ?? null,
|
|
24694
24996
|
savedAt: companion?.savedAt ?? null,
|
|
24695
24997
|
changedSince: companion ? companion.outputs[0].sha256 !== described.sha256 : false,
|
|
@@ -24703,25 +25005,25 @@ async function describeModels(loaded, media, mediaId, opts = {}) {
|
|
|
24703
25005
|
let exportWaiting = null;
|
|
24704
25006
|
try {
|
|
24705
25007
|
const info = await stat4(exportFile);
|
|
24706
|
-
if (info.isFile() && info.size <= MAX_MODEL_BYTES && sha256(await
|
|
25008
|
+
if (info.isFile() && info.size <= MAX_MODEL_BYTES && sha256(await readFile29(exportFile)) !== adoptedExport) {
|
|
24707
25009
|
exportWaiting = { bytes: info.size, modifiedAt: info.mtime.toISOString() };
|
|
24708
25010
|
}
|
|
24709
25011
|
} catch {
|
|
24710
25012
|
}
|
|
24711
25013
|
const spritesDir = modelSpritesDir(model.file);
|
|
24712
25014
|
let sprites = null;
|
|
24713
|
-
if (
|
|
25015
|
+
if (existsSync37(spritesDir)) {
|
|
24714
25016
|
try {
|
|
24715
25017
|
sprites = { path: portableOutputPath(spritesDir, root), directions: (await readSpriteFolder(spritesDir)).map((sprite) => sprite.direction) };
|
|
24716
25018
|
} catch {
|
|
24717
25019
|
}
|
|
24718
25020
|
}
|
|
24719
|
-
const relative =
|
|
25021
|
+
const relative = path42.relative(outDir, model.file).split(path42.sep).join("/");
|
|
24720
25022
|
models.push({
|
|
24721
25023
|
id: `model:${model.styleId}/${relative}`,
|
|
24722
25024
|
project: null,
|
|
24723
25025
|
styleId: model.styleId,
|
|
24724
|
-
name:
|
|
25026
|
+
name: path42.basename(model.file, path42.extname(model.file)),
|
|
24725
25027
|
file,
|
|
24726
25028
|
summary,
|
|
24727
25029
|
error,
|
|
@@ -24816,9 +25118,9 @@ function blenderAvailable() {
|
|
|
24816
25118
|
}
|
|
24817
25119
|
|
|
24818
25120
|
// src/workspace.ts
|
|
24819
|
-
import { mkdir as mkdir17, readFile as
|
|
24820
|
-
import { existsSync as
|
|
24821
|
-
import
|
|
25121
|
+
import { mkdir as mkdir17, readFile as readFile30, rename as rename11, rm as rm10, writeFile as writeFile20 } from "fs/promises";
|
|
25122
|
+
import { existsSync as existsSync38 } from "fs";
|
|
25123
|
+
import path43 from "path";
|
|
24822
25124
|
import { z as z12 } from "zod";
|
|
24823
25125
|
var WorkspaceProjectSchema = z12.object({
|
|
24824
25126
|
id: z12.string().min(1),
|
|
@@ -24843,10 +25145,10 @@ ${parsed.error.issues.slice(0, 5).map((i) => ` ${i.path.join(".")}: ${i.message
|
|
|
24843
25145
|
);
|
|
24844
25146
|
}
|
|
24845
25147
|
async function loadWorkspace(workspacePath) {
|
|
24846
|
-
if (!
|
|
25148
|
+
if (!existsSync38(workspacePath)) return { version: 1, projects: [] };
|
|
24847
25149
|
let raw;
|
|
24848
25150
|
try {
|
|
24849
|
-
raw = JSON.parse(await
|
|
25151
|
+
raw = JSON.parse(await readFile30(workspacePath, "utf8"));
|
|
24850
25152
|
} catch (err) {
|
|
24851
25153
|
throw new ProjectError(
|
|
24852
25154
|
`Workspace catalog at ${workspacePath} is malformed:
|
|
@@ -24860,7 +25162,7 @@ async function saveWorkspace(workspacePath, ws) {
|
|
|
24860
25162
|
version: 1,
|
|
24861
25163
|
projects: [...ws.projects].sort((a, b) => a.id.localeCompare(b.id))
|
|
24862
25164
|
};
|
|
24863
|
-
await mkdir17(
|
|
25165
|
+
await mkdir17(path43.dirname(path43.resolve(workspacePath)), { recursive: true });
|
|
24864
25166
|
const tmp = `${workspacePath}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
24865
25167
|
try {
|
|
24866
25168
|
await writeFile20(tmp, JSON.stringify(sorted, null, 2) + "\n");
|
|
@@ -24870,12 +25172,12 @@ async function saveWorkspace(workspacePath, ws) {
|
|
|
24870
25172
|
}
|
|
24871
25173
|
}
|
|
24872
25174
|
function toPortablePath(dir, absolute) {
|
|
24873
|
-
return
|
|
25175
|
+
return path43.relative(dir, absolute).split(path43.sep).join("/");
|
|
24874
25176
|
}
|
|
24875
25177
|
function resolveProject(dir, project2) {
|
|
24876
25178
|
return {
|
|
24877
|
-
manifestPath:
|
|
24878
|
-
lockPath:
|
|
25179
|
+
manifestPath: path43.resolve(dir, project2.manifest.split("/").join(path43.sep)),
|
|
25180
|
+
lockPath: path43.resolve(dir, project2.lock.split("/").join(path43.sep))
|
|
24879
25181
|
};
|
|
24880
25182
|
}
|
|
24881
25183
|
function validateWorkspace(ws, dir) {
|
|
@@ -24888,21 +25190,21 @@ function validateWorkspace(ws, dir) {
|
|
|
24888
25190
|
const { manifestPath, lockPath } = resolveProject(dir, project2);
|
|
24889
25191
|
lockOwners.set(lockPath, [...lockOwners.get(lockPath) ?? [], project2.id]);
|
|
24890
25192
|
manifestOwners.set(manifestPath, [...manifestOwners.get(manifestPath) ?? [], project2.id]);
|
|
24891
|
-
if (
|
|
25193
|
+
if (path43.isAbsolute(project2.manifest) || path43.isAbsolute(project2.lock)) {
|
|
24892
25194
|
diagnostics.push({
|
|
24893
25195
|
id: "absolute-path",
|
|
24894
25196
|
level: "warning",
|
|
24895
25197
|
message: `project "${project2.id}" stores an absolute path; the catalog will not resolve correctly if this tree is cloned or moved elsewhere`
|
|
24896
25198
|
});
|
|
24897
25199
|
}
|
|
24898
|
-
if (!
|
|
25200
|
+
if (!existsSync38(manifestPath)) {
|
|
24899
25201
|
diagnostics.push({
|
|
24900
25202
|
id: "missing-manifest",
|
|
24901
25203
|
level: "error",
|
|
24902
25204
|
message: `project "${project2.id}" manifest not found: ${manifestPath}`
|
|
24903
25205
|
});
|
|
24904
25206
|
}
|
|
24905
|
-
if (!
|
|
25207
|
+
if (!existsSync38(lockPath)) {
|
|
24906
25208
|
diagnostics.push({
|
|
24907
25209
|
id: "missing-lock",
|
|
24908
25210
|
level: "error",
|
|
@@ -24949,14 +25251,14 @@ function validateWorkspace(ws, dir) {
|
|
|
24949
25251
|
}
|
|
24950
25252
|
|
|
24951
25253
|
// src/gallery/edit.ts
|
|
24952
|
-
import { readFile as
|
|
24953
|
-
import
|
|
25254
|
+
import { readFile as readFile33, rename as rename12, writeFile as writeFile24 } from "fs/promises";
|
|
25255
|
+
import path47 from "path";
|
|
24954
25256
|
import { z as z16 } from "zod";
|
|
24955
25257
|
|
|
24956
25258
|
// src/gallery/upload.ts
|
|
24957
|
-
import { existsSync as
|
|
25259
|
+
import { existsSync as existsSync39 } from "fs";
|
|
24958
25260
|
import { mkdir as mkdir18, writeFile as writeFile21 } from "fs/promises";
|
|
24959
|
-
import
|
|
25261
|
+
import path44 from "path";
|
|
24960
25262
|
import { z as z13 } from "zod";
|
|
24961
25263
|
var MAX_UPLOAD_BYTES = 8 * 1024 * 1024;
|
|
24962
25264
|
var UploadImageSchema = z13.object({
|
|
@@ -24969,12 +25271,12 @@ var UploadImageSchema = z13.object({
|
|
|
24969
25271
|
overwrite: z13.boolean().optional()
|
|
24970
25272
|
}).strict();
|
|
24971
25273
|
async function saveProjectImage(root, request) {
|
|
24972
|
-
const file =
|
|
24973
|
-
const relative =
|
|
24974
|
-
if (relative.startsWith("..") ||
|
|
25274
|
+
const file = path44.resolve(root, request.path);
|
|
25275
|
+
const relative = path44.relative(root, file);
|
|
25276
|
+
if (relative.startsWith("..") || path44.isAbsolute(relative)) {
|
|
24975
25277
|
throw new ManifestEditError("an upload must stay inside the project");
|
|
24976
25278
|
}
|
|
24977
|
-
const extension =
|
|
25279
|
+
const extension = path44.extname(file).toLowerCase();
|
|
24978
25280
|
const expected = extension === ".png" ? "png" : extension === ".jpg" || extension === ".jpeg" ? "jpeg" : null;
|
|
24979
25281
|
if (!expected) throw new ManifestEditError("an upload must be a .png, .jpg, or .jpeg path");
|
|
24980
25282
|
const bytes = Buffer.from(request.base64, "base64");
|
|
@@ -24986,18 +25288,18 @@ async function saveProjectImage(root, request) {
|
|
|
24986
25288
|
if (metadata.format !== expected) {
|
|
24987
25289
|
throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
|
|
24988
25290
|
}
|
|
24989
|
-
if (
|
|
24990
|
-
throw new ManifestEditError(`${relative.split(
|
|
25291
|
+
if (existsSync39(file) && !request.overwrite) {
|
|
25292
|
+
throw new ManifestEditError(`${relative.split(path44.sep).join("/")} already exists; choose another name, or replace it`);
|
|
24991
25293
|
}
|
|
24992
|
-
await mkdir18(
|
|
25294
|
+
await mkdir18(path44.dirname(file), { recursive: true });
|
|
24993
25295
|
await writeFile21(file, bytes);
|
|
24994
|
-
return relative.split(
|
|
25296
|
+
return relative.split(path44.sep).join("/");
|
|
24995
25297
|
}
|
|
24996
25298
|
|
|
24997
25299
|
// src/gallery/image-revision.ts
|
|
24998
|
-
import { existsSync as
|
|
24999
|
-
import { readFile as
|
|
25000
|
-
import
|
|
25300
|
+
import { existsSync as existsSync40 } from "fs";
|
|
25301
|
+
import { readFile as readFile31, rm as rm11, writeFile as writeFile22 } from "fs/promises";
|
|
25302
|
+
import path45 from "path";
|
|
25001
25303
|
import { z as z14 } from "zod";
|
|
25002
25304
|
var InpaintRevisionRequestSchema = z14.object({
|
|
25003
25305
|
action: z14.literal("create-inpaint-revision"),
|
|
@@ -25016,15 +25318,15 @@ var InpaintRevisionRequestSchema = z14.object({
|
|
|
25016
25318
|
overwrite: z14.boolean().optional()
|
|
25017
25319
|
}).strict();
|
|
25018
25320
|
async function createInpaintRevision(manifestPath, request) {
|
|
25019
|
-
const root =
|
|
25020
|
-
if (
|
|
25321
|
+
const root = path45.dirname(path45.resolve(manifestPath));
|
|
25322
|
+
if (path45.extname(request.maskPath).toLowerCase() !== ".png") {
|
|
25021
25323
|
throw new ManifestEditError("the mask must be a .png path inside the project");
|
|
25022
25324
|
}
|
|
25023
25325
|
const bytes = Buffer.from(request.maskBase64, "base64");
|
|
25024
25326
|
const metadata = imageMetadata(bytes);
|
|
25025
25327
|
if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
|
|
25026
|
-
const file =
|
|
25027
|
-
const previous =
|
|
25328
|
+
const file = path45.resolve(root, request.maskPath);
|
|
25329
|
+
const previous = existsSync40(file) ? await readFile31(file) : null;
|
|
25028
25330
|
const mask = await saveProjectImage(root, {
|
|
25029
25331
|
action: "upload-image",
|
|
25030
25332
|
path: request.maskPath,
|
|
@@ -25051,9 +25353,9 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
25051
25353
|
}
|
|
25052
25354
|
|
|
25053
25355
|
// src/gallery/skeleton.ts
|
|
25054
|
-
import { existsSync as
|
|
25055
|
-
import { mkdir as mkdir19, readFile as
|
|
25056
|
-
import
|
|
25356
|
+
import { existsSync as existsSync41 } from "fs";
|
|
25357
|
+
import { mkdir as mkdir19, readFile as readFile32, rm as rm12, writeFile as writeFile23 } from "fs/promises";
|
|
25358
|
+
import path46 from "path";
|
|
25057
25359
|
import { z as z15 } from "zod";
|
|
25058
25360
|
var SkeletonEstimateRequestSchema = z15.object({
|
|
25059
25361
|
project: z15.string().min(1).optional(),
|
|
@@ -25092,20 +25394,20 @@ var SkeletonKeypointsUpdateSchema = z15.object({
|
|
|
25092
25394
|
set: SkeletonSetSchema
|
|
25093
25395
|
}).strict();
|
|
25094
25396
|
async function createSkeletonAnimation(manifestPath, request) {
|
|
25095
|
-
const root =
|
|
25096
|
-
const file =
|
|
25097
|
-
const relative =
|
|
25098
|
-
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") ||
|
|
25397
|
+
const root = path46.dirname(path46.resolve(manifestPath));
|
|
25398
|
+
const file = path46.resolve(root, request.keypointsFile);
|
|
25399
|
+
const relative = path46.relative(root, file);
|
|
25400
|
+
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || path46.isAbsolute(relative)) {
|
|
25099
25401
|
throw new ManifestEditError("the keypoints file must be a .json path inside the project");
|
|
25100
25402
|
}
|
|
25101
|
-
const existed =
|
|
25403
|
+
const existed = existsSync41(file);
|
|
25102
25404
|
let previous = null;
|
|
25103
25405
|
if (request.set) {
|
|
25104
25406
|
if (existed && !request.overwrite) {
|
|
25105
25407
|
throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
|
|
25106
25408
|
}
|
|
25107
|
-
if (existed) previous = await
|
|
25108
|
-
await mkdir19(
|
|
25409
|
+
if (existed) previous = await readFile32(file);
|
|
25410
|
+
await mkdir19(path46.dirname(file), { recursive: true });
|
|
25109
25411
|
await writeFile23(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
25110
25412
|
} else if (!existed) {
|
|
25111
25413
|
throw new ManifestEditError(`${request.keypointsFile} does not exist; paste poses or estimate them from the sprite`);
|
|
@@ -25121,7 +25423,7 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
25121
25423
|
revision: {
|
|
25122
25424
|
mode: "animate-skeleton",
|
|
25123
25425
|
from: request.from,
|
|
25124
|
-
keypointsFile: relative.split(
|
|
25426
|
+
keypointsFile: relative.split(path46.sep).join("/"),
|
|
25125
25427
|
direction: request.direction,
|
|
25126
25428
|
description: request.description,
|
|
25127
25429
|
...request.skeletonTemplate ? { skeletonTemplate: request.skeletonTemplate } : {}
|
|
@@ -25142,19 +25444,19 @@ async function updateSkeletonKeypoints(ctx, request) {
|
|
|
25142
25444
|
if (!spec) throw new ManifestEditError(`"${key2}" is not declared by the manifest`);
|
|
25143
25445
|
const file = spec.revision?.mode === "animate-skeleton" ? spec.revision.keypointsFile : void 0;
|
|
25144
25446
|
if (!file) throw new ManifestEditError(`${key2} is not an animate-skeleton revision`);
|
|
25145
|
-
const relative =
|
|
25146
|
-
if (relative.startsWith("..") ||
|
|
25447
|
+
const relative = path46.relative(ctx.loaded.root, file);
|
|
25448
|
+
if (relative.startsWith("..") || path46.isAbsolute(relative)) {
|
|
25147
25449
|
throw new ManifestEditError(`${key2}'s keypoints file is outside the project; edit it by hand`);
|
|
25148
25450
|
}
|
|
25149
|
-
const current =
|
|
25451
|
+
const current = existsSync41(file) ? sha256(await readFile32(file)) : null;
|
|
25150
25452
|
if (current !== request.expectedSha256) {
|
|
25151
25453
|
throw Object.assign(
|
|
25152
|
-
new Error(`${relative.split(
|
|
25454
|
+
new Error(`${relative.split(path46.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
|
|
25153
25455
|
{ status: 409 }
|
|
25154
25456
|
);
|
|
25155
25457
|
}
|
|
25156
25458
|
await writeFile23(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
25157
|
-
return relative.split(
|
|
25459
|
+
return relative.split(path46.sep).join("/");
|
|
25158
25460
|
}
|
|
25159
25461
|
|
|
25160
25462
|
// src/gallery/edit.ts
|
|
@@ -25208,7 +25510,7 @@ function createGalleryEditHandler(opts) {
|
|
|
25208
25510
|
const history = /* @__PURE__ */ new Map();
|
|
25209
25511
|
const manifestOf = async (project2) => {
|
|
25210
25512
|
try {
|
|
25211
|
-
return
|
|
25513
|
+
return path47.resolve(await opts.manifestFor(typeof project2 === "string" ? project2 : void 0));
|
|
25212
25514
|
} catch {
|
|
25213
25515
|
return null;
|
|
25214
25516
|
}
|
|
@@ -25218,7 +25520,7 @@ function createGalleryEditHandler(opts) {
|
|
|
25218
25520
|
if (undo.success) {
|
|
25219
25521
|
const manifestPath2 = await manifestOf(undo.data.project);
|
|
25220
25522
|
if (!manifestPath2) throw new ManifestEditError("no manifest to undo an edit in");
|
|
25221
|
-
const current = await
|
|
25523
|
+
const current = await readFile33(manifestPath2, "utf8");
|
|
25222
25524
|
if (sha256(current) !== undo.data.expectedSha256) throw new ManifestDriftError(manifestPath2);
|
|
25223
25525
|
const stack = history.get(manifestPath2) ?? [];
|
|
25224
25526
|
const last = stack[stack.length - 1];
|
|
@@ -25231,14 +25533,14 @@ function createGalleryEditHandler(opts) {
|
|
|
25231
25533
|
await writeFile24(tmp, last.before);
|
|
25232
25534
|
await rename12(tmp, manifestPath2);
|
|
25233
25535
|
stack.pop();
|
|
25234
|
-
log(` manifest edit undone in ${
|
|
25536
|
+
log(` manifest edit undone in ${path47.relative(process.cwd(), manifestPath2) || manifestPath2}`);
|
|
25235
25537
|
return opts.reload();
|
|
25236
25538
|
}
|
|
25237
25539
|
const manifestPath = await manifestOf(body?.project);
|
|
25238
|
-
const before = manifestPath ? await
|
|
25540
|
+
const before = manifestPath ? await readFile33(manifestPath, "utf8").catch(() => null) : null;
|
|
25239
25541
|
const build = await apply(body);
|
|
25240
25542
|
if (manifestPath && before !== null) {
|
|
25241
|
-
const after = await
|
|
25543
|
+
const after = await readFile33(manifestPath, "utf8").catch(() => null);
|
|
25242
25544
|
if (after !== null && after !== before) {
|
|
25243
25545
|
const stack = history.get(manifestPath) ?? [];
|
|
25244
25546
|
stack.push({ before, afterSha: sha256(after) });
|
|
@@ -25317,7 +25619,7 @@ function createEditApplier(opts, log) {
|
|
|
25317
25619
|
} catch (error) {
|
|
25318
25620
|
throw new ManifestEditError(error instanceof Error ? error.message : String(error));
|
|
25319
25621
|
}
|
|
25320
|
-
const written = await saveProjectImage(
|
|
25622
|
+
const written = await saveProjectImage(path47.dirname(path47.resolve(manifestPath2)), upload.data);
|
|
25321
25623
|
log(` image added: ${written}`);
|
|
25322
25624
|
return opts.reload();
|
|
25323
25625
|
}
|
|
@@ -25384,7 +25686,7 @@ function createEditApplier(opts, log) {
|
|
|
25384
25686
|
}
|
|
25385
25687
|
const result = await applyManifestEdit(manifestPath, parsed.data);
|
|
25386
25688
|
if (result.changed) {
|
|
25387
|
-
const relative =
|
|
25689
|
+
const relative = path47.relative(process.cwd(), result.manifestPath);
|
|
25388
25690
|
const shown = !relative || relative.startsWith("..") ? result.manifestPath : relative;
|
|
25389
25691
|
log(` manifest edited: ${describeEdit(parsed.data)} in ${shown}`);
|
|
25390
25692
|
}
|
|
@@ -25412,7 +25714,7 @@ function describeEdit(edit) {
|
|
|
25412
25714
|
// src/gallery/snapshot.ts
|
|
25413
25715
|
var PROJECT_FILE_TYPE = "application/octet-stream";
|
|
25414
25716
|
function galleryMediaId(absolutePath) {
|
|
25415
|
-
return
|
|
25717
|
+
return createHash7("sha256").update(path48.resolve(absolutePath)).digest("hex").slice(0, 24);
|
|
25416
25718
|
}
|
|
25417
25719
|
function galleryMediaRoute(id) {
|
|
25418
25720
|
return `/media/${id}`;
|
|
@@ -25436,9 +25738,9 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
25436
25738
|
return (entry.history ?? []).map((generation, i) => {
|
|
25437
25739
|
const outputs = generation.outputs.map((output) => {
|
|
25438
25740
|
const mediaType = output.mediaType ?? MediaType.PNG;
|
|
25439
|
-
const file =
|
|
25741
|
+
const file = path48.join(cacheDir, cacheFileName(output.sha256, mediaType));
|
|
25440
25742
|
let url = null;
|
|
25441
|
-
if (
|
|
25743
|
+
if (existsSync42(file)) {
|
|
25442
25744
|
const id = galleryMediaId(file);
|
|
25443
25745
|
media.set(id, { path: file, contentType: mediaType });
|
|
25444
25746
|
url = `${galleryMediaRoute(id)}?v=${output.sha256.slice(0, 24)}`;
|
|
@@ -25470,7 +25772,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
25470
25772
|
var MAX_COMPARED_BYTES = 8 * 1024 * 1024;
|
|
25471
25773
|
async function samePixels(a, b) {
|
|
25472
25774
|
try {
|
|
25473
|
-
const [left, right] = await Promise.all([
|
|
25775
|
+
const [left, right] = await Promise.all([readFile34(a), readFile34(b)]);
|
|
25474
25776
|
if (left.length > MAX_COMPARED_BYTES || right.length > MAX_COMPARED_BYTES) return false;
|
|
25475
25777
|
const x = decodePng(left);
|
|
25476
25778
|
const y = decodePng(right);
|
|
@@ -25568,10 +25870,10 @@ async function describeOutput(media, root, absolutePath, recorded = {}) {
|
|
|
25568
25870
|
async function describeQuality(media, root, inspection) {
|
|
25569
25871
|
const outputPaths = inspection.outputs ?? [inspection.output];
|
|
25570
25872
|
const outputs = await Promise.all(
|
|
25571
|
-
outputPaths.map((file) => describeOutput(media, root,
|
|
25873
|
+
outputPaths.map((file) => describeOutput(media, root, path48.resolve(root, file)))
|
|
25572
25874
|
);
|
|
25573
|
-
const recordPath =
|
|
25574
|
-
const recordExists =
|
|
25875
|
+
const recordPath = path48.resolve(root, inspection.record);
|
|
25876
|
+
const recordExists = existsSync42(recordPath);
|
|
25575
25877
|
let options = null;
|
|
25576
25878
|
let check = null;
|
|
25577
25879
|
if (recordExists) {
|
|
@@ -25590,7 +25892,7 @@ async function describeQuality(media, root, inspection) {
|
|
|
25590
25892
|
return {
|
|
25591
25893
|
state: inspection.state,
|
|
25592
25894
|
reason: inspection.reason,
|
|
25593
|
-
output: portableOutputPath(
|
|
25895
|
+
output: portableOutputPath(path48.resolve(root, inspection.output), root),
|
|
25594
25896
|
record: portableOutputPath(recordPath, root),
|
|
25595
25897
|
recordExists,
|
|
25596
25898
|
outputs,
|
|
@@ -25628,9 +25930,9 @@ async function buildGallerySnapshot(opts) {
|
|
|
25628
25930
|
const media = /* @__PURE__ */ new Map();
|
|
25629
25931
|
const plan = await buildPlan(specs, lock);
|
|
25630
25932
|
const items = [];
|
|
25631
|
-
const manifestText = await
|
|
25933
|
+
const manifestText = await readFile34(loaded.path, "utf8");
|
|
25632
25934
|
const manifestSha256 = sha256(manifestText);
|
|
25633
|
-
const cacheDir =
|
|
25935
|
+
const cacheDir = path48.resolve(path48.dirname(opts.lockPath), ".pixelkiln", "cache");
|
|
25634
25936
|
let rawStyles = {};
|
|
25635
25937
|
try {
|
|
25636
25938
|
const raw = JSON.parse(manifestText);
|
|
@@ -25654,12 +25956,12 @@ async function buildGallerySnapshot(opts) {
|
|
|
25654
25956
|
)
|
|
25655
25957
|
);
|
|
25656
25958
|
if (spec.source) {
|
|
25657
|
-
const editPath =
|
|
25959
|
+
const editPath = path48.resolve(root, spec.source);
|
|
25658
25960
|
const memberCount = sourceIsStem(spec.source, entry, root) ? entry.outputs.length : 1;
|
|
25659
25961
|
const editShas = await Promise.all(
|
|
25660
25962
|
Array.from({ length: memberCount }, async (_, index) => {
|
|
25661
25963
|
const file = sourceOutputPath(spec.source, entry, index, root);
|
|
25662
|
-
return { file, sha256:
|
|
25964
|
+
return { file, sha256: existsSync42(file) ? await sha256File(file) : null };
|
|
25663
25965
|
})
|
|
25664
25966
|
);
|
|
25665
25967
|
edits = await Promise.all(editShas.map(({ file, sha256: editSha }) => describeOutput(media, root, file, { sha256: editSha })));
|
|
@@ -25667,7 +25969,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
25667
25969
|
const companion = await readHandEditCompanion(editPath);
|
|
25668
25970
|
if (companion) {
|
|
25669
25971
|
const projectPath = handEditProjectPath(editPath);
|
|
25670
|
-
const project2 = companion.project &&
|
|
25972
|
+
const project2 = companion.project && existsSync42(projectPath) ? await fileInfo(projectPath) : null;
|
|
25671
25973
|
let projectUrl = null;
|
|
25672
25974
|
if (project2) {
|
|
25673
25975
|
const id = galleryMediaId(projectPath);
|
|
@@ -25703,8 +26005,8 @@ async function buildGallerySnapshot(opts) {
|
|
|
25703
26005
|
editStatus = edits.some((member) => !member.exists) ? "missing" : editChanged.every((changed) => !changed) ? "same" : regenerated ? "regenerated-since" : "edited";
|
|
25704
26006
|
}
|
|
25705
26007
|
} else if (spec.source) {
|
|
25706
|
-
outputs = [await describeOutput(media, root,
|
|
25707
|
-
} else if (!entry &&
|
|
26008
|
+
outputs = [await describeOutput(media, root, path48.resolve(root, spec.source))];
|
|
26009
|
+
} else if (!entry && existsSync42(spec.outFile)) {
|
|
25708
26010
|
outputs = [await describeOutput(media, root, spec.outFile)];
|
|
25709
26011
|
} else {
|
|
25710
26012
|
outputs = [];
|
|
@@ -25908,7 +26210,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
25908
26210
|
id: loaded.manifest.name,
|
|
25909
26211
|
name: loaded.manifest.name,
|
|
25910
26212
|
manifest: loaded.path,
|
|
25911
|
-
lock:
|
|
26213
|
+
lock: path48.resolve(opts.lockPath),
|
|
25912
26214
|
root,
|
|
25913
26215
|
provider: loaded.manifest.provider,
|
|
25914
26216
|
account: null,
|
|
@@ -25937,7 +26239,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
25937
26239
|
return { snapshot, media };
|
|
25938
26240
|
}
|
|
25939
26241
|
async function buildWorkspaceGallerySnapshot(opts) {
|
|
25940
|
-
const dir =
|
|
26242
|
+
const dir = path48.dirname(path48.resolve(opts.workspacePath));
|
|
25941
26243
|
const media = /* @__PURE__ */ new Map();
|
|
25942
26244
|
const projects = [];
|
|
25943
26245
|
const items = [];
|
|
@@ -25982,11 +26284,11 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
25982
26284
|
id: project2.id,
|
|
25983
26285
|
name: loaded.manifest.name,
|
|
25984
26286
|
manifest: manifestPath,
|
|
25985
|
-
lock:
|
|
26287
|
+
lock: path48.resolve(lockPath),
|
|
25986
26288
|
root: loaded.root,
|
|
25987
26289
|
provider: loaded.manifest.provider,
|
|
25988
26290
|
account: project2.account ?? null,
|
|
25989
|
-
manifestSha256: manifestSha256 ?? sha256(await
|
|
26291
|
+
manifestSha256: manifestSha256 ?? sha256(await readFile34(manifestPath, "utf8")),
|
|
25990
26292
|
historyLimit: historyLimit(loaded.manifest),
|
|
25991
26293
|
entries: Object.keys(lock.entries).length,
|
|
25992
26294
|
items: projectItems.length,
|
|
@@ -25998,8 +26300,8 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
25998
26300
|
id: project2.id,
|
|
25999
26301
|
name: project2.id,
|
|
26000
26302
|
manifest: manifestPath,
|
|
26001
|
-
lock:
|
|
26002
|
-
root:
|
|
26303
|
+
lock: path48.resolve(lockPath),
|
|
26304
|
+
root: path48.dirname(manifestPath),
|
|
26003
26305
|
provider: project2.provider,
|
|
26004
26306
|
account: project2.account ?? null,
|
|
26005
26307
|
manifestSha256: null,
|
|
@@ -26026,7 +26328,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
26026
26328
|
version: 1,
|
|
26027
26329
|
generatedAt: (opts.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
|
|
26028
26330
|
project: null,
|
|
26029
|
-
workspace: { path:
|
|
26331
|
+
workspace: { path: path48.resolve(opts.workspacePath), dir, projects },
|
|
26030
26332
|
filter,
|
|
26031
26333
|
totals: {
|
|
26032
26334
|
entries: projects.reduce((sum, project2) => sum + project2.entries, 0),
|
|
@@ -26045,13 +26347,13 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
26045
26347
|
}
|
|
26046
26348
|
|
|
26047
26349
|
// src/gallery/page.ts
|
|
26048
|
-
import { existsSync as
|
|
26350
|
+
import { existsSync as existsSync43, readFileSync as readFileSync10 } from "fs";
|
|
26049
26351
|
|
|
26050
26352
|
// src/gallery/client-bundle.ts
|
|
26051
|
-
import { createRequire as
|
|
26353
|
+
import { createRequire as createRequire3 } from "module";
|
|
26052
26354
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
26053
26355
|
function bundleGalleryClient(entry = fileURLToPath2(new URL("./client/src/main.ts", import.meta.url))) {
|
|
26054
|
-
const esbuild =
|
|
26356
|
+
const esbuild = createRequire3(import.meta.url)("esbuild");
|
|
26055
26357
|
const result = esbuild.buildSync({
|
|
26056
26358
|
entryPoints: [entry],
|
|
26057
26359
|
bundle: true,
|
|
@@ -26085,8 +26387,8 @@ var client;
|
|
|
26085
26387
|
function clientAssets() {
|
|
26086
26388
|
const prebuilt = new URL("gallery.js", CLIENT_DIR);
|
|
26087
26389
|
client ??= {
|
|
26088
|
-
css:
|
|
26089
|
-
js:
|
|
26390
|
+
css: readFileSync10(new URL("gallery.css", CLIENT_DIR), "utf8"),
|
|
26391
|
+
js: existsSync43(prebuilt) ? readFileSync10(prebuilt, "utf8") : bundleGalleryClient()
|
|
26090
26392
|
};
|
|
26091
26393
|
return client;
|
|
26092
26394
|
}
|
|
@@ -26228,11 +26530,11 @@ var EDITOR_PIN = pin_default;
|
|
|
26228
26530
|
var EDITOR_RELEASE_BASE = "https://github.com/gfargo/pixelkiln/releases/download";
|
|
26229
26531
|
|
|
26230
26532
|
// src/editor/install.ts
|
|
26231
|
-
import { createHash as
|
|
26232
|
-
import { existsSync as
|
|
26233
|
-
import { mkdir as mkdir20, readFile as
|
|
26533
|
+
import { createHash as createHash8 } from "crypto";
|
|
26534
|
+
import { existsSync as existsSync44 } from "fs";
|
|
26535
|
+
import { mkdir as mkdir20, readFile as readFile35, rename as rename13, rm as rm13, stat as stat6, writeFile as writeFile25 } from "fs/promises";
|
|
26234
26536
|
import os3 from "os";
|
|
26235
|
-
import
|
|
26537
|
+
import path49 from "path";
|
|
26236
26538
|
var EditorInstallError = class extends Error {
|
|
26237
26539
|
constructor(message6, file) {
|
|
26238
26540
|
super(message6);
|
|
@@ -26243,15 +26545,15 @@ var EditorInstallError = class extends Error {
|
|
|
26243
26545
|
};
|
|
26244
26546
|
function editorToolsRoot() {
|
|
26245
26547
|
const override = process.env.PIXELKILN_TOOLS_DIR?.trim();
|
|
26246
|
-
if (override) return
|
|
26247
|
-
if (process.platform === "darwin") return
|
|
26548
|
+
if (override) return path49.resolve(override);
|
|
26549
|
+
if (process.platform === "darwin") return path49.join(os3.homedir(), "Library", "Caches", "pixelkiln", "tools");
|
|
26248
26550
|
if (process.platform === "win32") {
|
|
26249
|
-
return
|
|
26551
|
+
return path49.join(process.env.LOCALAPPDATA ?? path49.join(os3.homedir(), "AppData", "Local"), "pixelkiln", "tools");
|
|
26250
26552
|
}
|
|
26251
|
-
return
|
|
26553
|
+
return path49.join(process.env.XDG_CACHE_HOME ?? path49.join(os3.homedir(), ".cache"), "pixelkiln", "tools");
|
|
26252
26554
|
}
|
|
26253
26555
|
function editorDir(pin = EDITOR_PIN, root = editorToolsRoot()) {
|
|
26254
|
-
return
|
|
26556
|
+
return path49.join(root, "pixelorama", pin.release ?? "unpublished");
|
|
26255
26557
|
}
|
|
26256
26558
|
function editorBaseUrl(pin = EDITOR_PIN) {
|
|
26257
26559
|
const override = process.env.PIXELKILN_EDITOR_URL?.trim();
|
|
@@ -26261,7 +26563,7 @@ function editorBaseUrl(pin = EDITOR_PIN) {
|
|
|
26261
26563
|
}
|
|
26262
26564
|
async function sha256Of(file) {
|
|
26263
26565
|
try {
|
|
26264
|
-
return
|
|
26566
|
+
return createHash8("sha256").update(await readFile35(file)).digest("hex");
|
|
26265
26567
|
} catch {
|
|
26266
26568
|
return null;
|
|
26267
26569
|
}
|
|
@@ -26274,8 +26576,8 @@ async function editorStatus(opts = {}) {
|
|
|
26274
26576
|
let totalBytes = 0;
|
|
26275
26577
|
for (const [name, expected] of Object.entries(pin.files)) {
|
|
26276
26578
|
totalBytes += expected.bytes;
|
|
26277
|
-
const file =
|
|
26278
|
-
const info =
|
|
26579
|
+
const file = path49.join(dir, name);
|
|
26580
|
+
const info = existsSync44(file) ? await stat6(file).catch(() => null) : null;
|
|
26279
26581
|
if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
|
|
26280
26582
|
installedBytes += expected.bytes;
|
|
26281
26583
|
} else {
|
|
@@ -26328,11 +26630,11 @@ async function installEditor(opts = {}) {
|
|
|
26328
26630
|
if (bytes.length !== expected.bytes) {
|
|
26329
26631
|
throw new EditorInstallError(`${name}: expected ${expected.bytes} bytes, got ${bytes.length}`, name);
|
|
26330
26632
|
}
|
|
26331
|
-
const digest2 =
|
|
26633
|
+
const digest2 = createHash8("sha256").update(bytes).digest("hex");
|
|
26332
26634
|
if (digest2 !== expected.sha256) {
|
|
26333
26635
|
throw new EditorInstallError(`${name}: sha256 ${digest2.slice(0, 12)}\u2026 does not match the pinned ${expected.sha256.slice(0, 12)}\u2026`, name);
|
|
26334
26636
|
}
|
|
26335
|
-
const final =
|
|
26637
|
+
const final = path49.join(dir, name);
|
|
26336
26638
|
const tmp = `${final}.${process.pid}.part`;
|
|
26337
26639
|
try {
|
|
26338
26640
|
await writeFile25(tmp, bytes);
|
|
@@ -26378,12 +26680,12 @@ var EDITOR_CONTENT_TYPES = {
|
|
|
26378
26680
|
".json": "application/json; charset=utf-8"
|
|
26379
26681
|
};
|
|
26380
26682
|
function editorContentType(name) {
|
|
26381
|
-
return EDITOR_CONTENT_TYPES[
|
|
26683
|
+
return EDITOR_CONTENT_TYPES[path49.extname(name).toLowerCase()] ?? null;
|
|
26382
26684
|
}
|
|
26383
26685
|
|
|
26384
26686
|
// src/gallery/editor.ts
|
|
26385
|
-
import { readFile as
|
|
26386
|
-
import
|
|
26687
|
+
import { readFile as readFile36 } from "fs/promises";
|
|
26688
|
+
import path50 from "path";
|
|
26387
26689
|
function editorRoute(release, name = "index.html") {
|
|
26388
26690
|
return `/editor/${encodeURIComponent(release)}/${encodeURIComponent(name)}`;
|
|
26389
26691
|
}
|
|
@@ -26456,7 +26758,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
26456
26758
|
if (!status.installed) return null;
|
|
26457
26759
|
let bytes;
|
|
26458
26760
|
try {
|
|
26459
|
-
bytes = await
|
|
26761
|
+
bytes = await readFile36(path50.join(dir, name));
|
|
26460
26762
|
} catch {
|
|
26461
26763
|
verified = null;
|
|
26462
26764
|
return null;
|
|
@@ -26473,7 +26775,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
26473
26775
|
// src/gallery/server.ts
|
|
26474
26776
|
import { randomBytes } from "crypto";
|
|
26475
26777
|
import { createServer as createServer2 } from "http";
|
|
26476
|
-
import { readFile as
|
|
26778
|
+
import { readFile as readFile37 } from "fs/promises";
|
|
26477
26779
|
var MAX_EDIT_BYTES = 48 * 1024 * 1024;
|
|
26478
26780
|
var EDITOR_CSP = [
|
|
26479
26781
|
"default-src 'self'",
|
|
@@ -26654,7 +26956,7 @@ async function serveGallery(opts) {
|
|
|
26654
26956
|
const asset = reviewAssets.get(jobId)?.get(url2.pathname);
|
|
26655
26957
|
if (!asset) return fail(404, "no such review asset");
|
|
26656
26958
|
try {
|
|
26657
|
-
const bytes = await
|
|
26959
|
+
const bytes = await readFile37(asset.path);
|
|
26658
26960
|
res.writeHead(200, {
|
|
26659
26961
|
"Content-Type": asset.contentType,
|
|
26660
26962
|
"Cache-Control": "no-store",
|
|
@@ -26737,7 +27039,7 @@ async function serveGallery(opts) {
|
|
|
26737
27039
|
if (!asset) return fail(404, "no such gallery media");
|
|
26738
27040
|
let bytes;
|
|
26739
27041
|
try {
|
|
26740
|
-
bytes = await
|
|
27042
|
+
bytes = await readFile37(asset.path);
|
|
26741
27043
|
} catch {
|
|
26742
27044
|
return fail(404, "gallery media is no longer on disk; refresh the page");
|
|
26743
27045
|
}
|
|
@@ -27147,19 +27449,19 @@ function createGenerateHandlers(opts) {
|
|
|
27147
27449
|
}
|
|
27148
27450
|
|
|
27149
27451
|
// src/pipeline/salvage.ts
|
|
27150
|
-
import { readFile as
|
|
27151
|
-
import { existsSync as
|
|
27152
|
-
import
|
|
27452
|
+
import { readFile as readFile38 } from "fs/promises";
|
|
27453
|
+
import { existsSync as existsSync45 } from "fs";
|
|
27454
|
+
import path51 from "path";
|
|
27153
27455
|
function providerClaimId(provider, objectId) {
|
|
27154
27456
|
return `${encodeURIComponent(provider)}:${encodeURIComponent(objectId)}`;
|
|
27155
27457
|
}
|
|
27156
27458
|
async function loadClaims(lockPaths, opts = {}) {
|
|
27157
27459
|
const claimed = /* @__PURE__ */ new Set();
|
|
27158
27460
|
for (const p of lockPaths) {
|
|
27159
|
-
if (!
|
|
27461
|
+
if (!existsSync45(p)) throw new Error(`Claim lockfile not found: ${p}`);
|
|
27160
27462
|
let parsed;
|
|
27161
27463
|
try {
|
|
27162
|
-
parsed = parseLock(JSON.parse(await
|
|
27464
|
+
parsed = parseLock(JSON.parse(await readFile38(p, "utf8")));
|
|
27163
27465
|
} catch {
|
|
27164
27466
|
throw new Error(`Claim lockfile is malformed: ${p}`);
|
|
27165
27467
|
}
|
|
@@ -27263,20 +27565,20 @@ function matchOrphanStyle(prompt, manifest) {
|
|
|
27263
27565
|
return matchStyleByPattern(prompt, manifest);
|
|
27264
27566
|
}
|
|
27265
27567
|
async function loadSiblingManifests(ownManifestPath, workspaceManifestPaths, claimPaths) {
|
|
27266
|
-
const own =
|
|
27568
|
+
const own = path51.resolve(ownManifestPath);
|
|
27267
27569
|
const siblingManifestPaths = [
|
|
27268
27570
|
.../* @__PURE__ */ new Set([
|
|
27269
27571
|
...workspaceManifestPaths,
|
|
27270
|
-
...claimPaths.map((c) =>
|
|
27572
|
+
...claimPaths.map((c) => path51.join(path51.dirname(path51.resolve(c)), "pixelkiln.manifest.json"))
|
|
27271
27573
|
])
|
|
27272
27574
|
];
|
|
27273
27575
|
const siblings = [];
|
|
27274
27576
|
for (const siblingManifestPath of siblingManifestPaths) {
|
|
27275
|
-
if (
|
|
27276
|
-
if (!
|
|
27577
|
+
if (path51.resolve(siblingManifestPath) === own) continue;
|
|
27578
|
+
if (!existsSync45(siblingManifestPath)) continue;
|
|
27277
27579
|
try {
|
|
27278
27580
|
const { manifest } = await loadManifest(siblingManifestPath);
|
|
27279
|
-
siblings.push({ label:
|
|
27581
|
+
siblings.push({ label: path51.basename(path51.dirname(siblingManifestPath)), manifest });
|
|
27280
27582
|
} catch {
|
|
27281
27583
|
}
|
|
27282
27584
|
}
|
|
@@ -27396,8 +27698,8 @@ async function applyTags(provider, decisions, existing, opts = {}) {
|
|
|
27396
27698
|
}
|
|
27397
27699
|
|
|
27398
27700
|
// src/pick/salvage-server.ts
|
|
27399
|
-
import { mkdir as mkdir21, writeFile as writeFile26, readFile as
|
|
27400
|
-
import
|
|
27701
|
+
import { mkdir as mkdir21, writeFile as writeFile26, readFile as readFile39 } from "fs/promises";
|
|
27702
|
+
import path52 from "path";
|
|
27401
27703
|
|
|
27402
27704
|
// src/pick/salvage-sheet.ts
|
|
27403
27705
|
var escapeHtml3 = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
@@ -27563,7 +27865,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
27563
27865
|
});
|
|
27564
27866
|
const html = renderSalvageSheet(orphans, {
|
|
27565
27867
|
styleId: ctx.styleId,
|
|
27566
|
-
importDir:
|
|
27868
|
+
importDir: path52.relative(process.cwd(), ctx.importDir) || "."
|
|
27567
27869
|
});
|
|
27568
27870
|
const byId = new Map(orphans.map((o) => [o.id, o]));
|
|
27569
27871
|
const existingTags = new Map(orphans.map((o) => [o.id, o.tags]));
|
|
@@ -27619,9 +27921,9 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
27619
27921
|
if (!buf.subarray(0, 8).equals(PNG_SIGNATURE2)) throw new Error("not a PNG");
|
|
27620
27922
|
decodePng(buf);
|
|
27621
27923
|
const assetId = idFromPrompt(orphan.prompt, taken);
|
|
27622
|
-
const rel =
|
|
27623
|
-
const outFile =
|
|
27624
|
-
await mkdir21(
|
|
27924
|
+
const rel = path52.join("_salvaged", `${assetId}.png`);
|
|
27925
|
+
const outFile = path52.resolve(ctx.importDir, rel);
|
|
27926
|
+
await mkdir21(path52.dirname(outFile), { recursive: true });
|
|
27625
27927
|
await writeFile26(outFile, buf);
|
|
27626
27928
|
ctx.manifest.assets[assetId] = {
|
|
27627
27929
|
prompt: orphan.prompt,
|
|
@@ -27654,7 +27956,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
27654
27956
|
sourceUrl: durableSource,
|
|
27655
27957
|
sourceUrls: durableSource ? [{ url: durableSource }] : [],
|
|
27656
27958
|
outputs: [{
|
|
27657
|
-
path: portableOutputPath(outFile,
|
|
27959
|
+
path: portableOutputPath(outFile, path52.dirname(ctx.manifestPath)),
|
|
27658
27960
|
sha256: sha256(buf)
|
|
27659
27961
|
}],
|
|
27660
27962
|
submittedAt: orphan.createdAt,
|
|
@@ -27678,7 +27980,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
27678
27980
|
}
|
|
27679
27981
|
}
|
|
27680
27982
|
await applyTags(provider, decisions, existingTags, { onProgress: log, characters: characterMembers });
|
|
27681
|
-
const raw = JSON.parse(await
|
|
27983
|
+
const raw = JSON.parse(await readFile39(ctx.manifestPath, "utf8"));
|
|
27682
27984
|
for (const id of importedAssetIds) raw.assets[id] = ctx.manifest.assets[id];
|
|
27683
27985
|
await writeFile26(ctx.manifestPath, JSON.stringify(raw, null, 2) + "\n");
|
|
27684
27986
|
await saveLock(ctx.lockPath, ctx.lock);
|
|
@@ -27799,6 +28101,12 @@ export {
|
|
|
27799
28101
|
CHARACTER_DIRECTIONS_4,
|
|
27800
28102
|
CHARACTER_DIRECTIONS_8,
|
|
27801
28103
|
CHARACTER_PROPORTION_PRESETS,
|
|
28104
|
+
CODEX_CAMERAS,
|
|
28105
|
+
CODEX_ID,
|
|
28106
|
+
CODEX_INSTALL,
|
|
28107
|
+
CODEX_PACKAGE,
|
|
28108
|
+
CODEX_REPOSITORY,
|
|
28109
|
+
CODEX_TUNE_KEYS,
|
|
27802
28110
|
CharacterAnimationModeSchema,
|
|
27803
28111
|
CharacterAnimationSchema,
|
|
27804
28112
|
CharacterAttachSchema,
|
|
@@ -27938,6 +28246,7 @@ export {
|
|
|
27938
28246
|
applyManifestEdit,
|
|
27939
28247
|
applyTags,
|
|
27940
28248
|
approveQualityRecord,
|
|
28249
|
+
assertFreshOutputs,
|
|
27941
28250
|
assetInStyle,
|
|
27942
28251
|
auditStyle,
|
|
27943
28252
|
availableProviders,
|
|
@@ -27951,6 +28260,7 @@ export {
|
|
|
27951
28260
|
cacheFileName,
|
|
27952
28261
|
candidateCount,
|
|
27953
28262
|
characterDirections,
|
|
28263
|
+
checkCodexRecipe,
|
|
27954
28264
|
checkExportBytes,
|
|
27955
28265
|
checkPixelfxRecipe,
|
|
27956
28266
|
checkQualityBaseline,
|
|
@@ -27996,6 +28306,7 @@ export {
|
|
|
27996
28306
|
fetchWithRetry,
|
|
27997
28307
|
findOrphans,
|
|
27998
28308
|
fontOutputPaths,
|
|
28309
|
+
formatCodexEffects,
|
|
27999
28310
|
formatCost,
|
|
28000
28311
|
formatPixelfxEffects,
|
|
28001
28312
|
frameSetFps,
|
|
@@ -28038,14 +28349,18 @@ export {
|
|
|
28038
28349
|
isometricTileCost,
|
|
28039
28350
|
layerOffsetFor,
|
|
28040
28351
|
listBundledRecipes,
|
|
28352
|
+
listCodexEffects,
|
|
28041
28353
|
listPixelfxEffects,
|
|
28042
28354
|
loadClaims,
|
|
28355
|
+
loadCodex,
|
|
28043
28356
|
loadLock,
|
|
28044
28357
|
loadManifest,
|
|
28045
28358
|
loadPixelfx,
|
|
28046
28359
|
loadSiblingManifests,
|
|
28047
28360
|
loadWorkspace,
|
|
28361
|
+
localSheet,
|
|
28048
28362
|
lockKey,
|
|
28363
|
+
makeCodexVfx,
|
|
28049
28364
|
makePixelfxVfx,
|
|
28050
28365
|
makeVfx,
|
|
28051
28366
|
makeVfxWithArtist,
|
|
@@ -28097,6 +28412,7 @@ export {
|
|
|
28097
28412
|
pixMiniMaxCost,
|
|
28098
28413
|
pixelateFile,
|
|
28099
28414
|
pixelfxSheet,
|
|
28415
|
+
planCodex,
|
|
28100
28416
|
pngFilesAt,
|
|
28101
28417
|
pngSize,
|
|
28102
28418
|
poll,
|
|
@@ -28114,6 +28430,7 @@ export {
|
|
|
28114
28430
|
qualityRecordPath,
|
|
28115
28431
|
quantizeToPalette,
|
|
28116
28432
|
readArtifactBundleManifest,
|
|
28433
|
+
readCodexRecipe,
|
|
28117
28434
|
readHandEditCompanion,
|
|
28118
28435
|
readPixelfxRecipe,
|
|
28119
28436
|
readQualityBaseline,
|
|
@@ -28129,6 +28446,7 @@ export {
|
|
|
28129
28446
|
registerProvider,
|
|
28130
28447
|
remove,
|
|
28131
28448
|
renderAsepriteSheet,
|
|
28449
|
+
renderCodex,
|
|
28132
28450
|
renderGallery,
|
|
28133
28451
|
renderGodotSpriteFrames,
|
|
28134
28452
|
renderPixelfx,
|
|
@@ -28223,6 +28541,7 @@ export {
|
|
|
28223
28541
|
workspaceClaims,
|
|
28224
28542
|
workspaceStatus,
|
|
28225
28543
|
writeArtifactBundle,
|
|
28544
|
+
writeLocalVfx,
|
|
28226
28545
|
writeManagedArtifactBundle
|
|
28227
28546
|
};
|
|
28228
28547
|
//# sourceMappingURL=index.js.map
|