pixelkiln 0.110.0 → 0.112.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 +1214 -366
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1236 -523
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +281 -22
- package/dist/index.d.ts +281 -22
- package/dist/index.js +1156 -460
- package/dist/index.js.map +1 -1
- package/docs/ARCHITECTURE.md +10 -0
- package/docs/CLI.md +90 -10
- package/docs/LIBRARY.md +32 -0
- package/docs/THIRD_PARTY.md +20 -0
- package/docs/TILES.md +47 -3
- 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,
|
|
@@ -19765,6 +20063,374 @@ function mountStyle(lock, styleId, manifestDir, mount, cells, sources = {}, outp
|
|
|
19765
20063
|
};
|
|
19766
20064
|
}
|
|
19767
20065
|
|
|
20066
|
+
// src/pipeline/ldtk-export.ts
|
|
20067
|
+
import { createHash as createHash6 } from "crypto";
|
|
20068
|
+
var LDTK_JSON_VERSION = "1.5.3";
|
|
20069
|
+
var FIRST = 1;
|
|
20070
|
+
var SECOND = 2;
|
|
20071
|
+
var DEMO_WIDTH = 12;
|
|
20072
|
+
var DEMO_HEIGHT = 9;
|
|
20073
|
+
function ldtkRuleMatches(rule, grid, cx, cy) {
|
|
20074
|
+
const radius = Math.floor(rule.size / 2);
|
|
20075
|
+
for (let py = 0; py < rule.size; py++) {
|
|
20076
|
+
for (let px = 0; px < rule.size; px++) {
|
|
20077
|
+
const wanted = rule.pattern[px + py * rule.size];
|
|
20078
|
+
if (wanted === 0) continue;
|
|
20079
|
+
const x = cx + px - radius;
|
|
20080
|
+
const y = cy + py - radius;
|
|
20081
|
+
const inside2 = x >= 0 && y >= 0 && x < grid.width && y < grid.height;
|
|
20082
|
+
const value = inside2 ? grid.cells[y * grid.width + x] : rule.outOfBoundsValue;
|
|
20083
|
+
if (wanted > 0 && value !== wanted) return false;
|
|
20084
|
+
if (wanted < 0 && value === -wanted) return false;
|
|
20085
|
+
}
|
|
20086
|
+
}
|
|
20087
|
+
return true;
|
|
20088
|
+
}
|
|
20089
|
+
function iid(...parts) {
|
|
20090
|
+
const hex2 = createHash6("sha256").update(parts.join("\0")).digest("hex");
|
|
20091
|
+
return `${hex2.slice(0, 8)}-${hex2.slice(8, 12)}-4${hex2.slice(13, 16)}-8${hex2.slice(17, 20)}-${hex2.slice(20, 32)}`;
|
|
20092
|
+
}
|
|
20093
|
+
function identifier(text, fallback) {
|
|
20094
|
+
const slug3 = text.replace(/[^A-Za-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
20095
|
+
return /^[A-Za-z]/.test(slug3) ? slug3 : slug3 ? `${fallback}_${slug3}` : fallback;
|
|
20096
|
+
}
|
|
20097
|
+
function dominantValue(mask) {
|
|
20098
|
+
const first = [0, 1, 2, 3].filter((bit) => (mask & 1 << bit) !== 0).length;
|
|
20099
|
+
return first * 2 >= 4 ? FIRST : SECOND;
|
|
20100
|
+
}
|
|
20101
|
+
function ldtkPattern(rules, mask) {
|
|
20102
|
+
const value = (bit) => (mask & 1 << bit) !== 0 ? FIRST : SECOND;
|
|
20103
|
+
const pattern = new Array(9).fill(0);
|
|
20104
|
+
if (rules.ruleType === "corner") {
|
|
20105
|
+
pattern[4] = value(3);
|
|
20106
|
+
pattern[5] = value(2);
|
|
20107
|
+
pattern[7] = value(1);
|
|
20108
|
+
pattern[8] = value(0);
|
|
20109
|
+
return pattern;
|
|
20110
|
+
}
|
|
20111
|
+
pattern[4] = dominantValue(mask);
|
|
20112
|
+
pattern[1] = value(0);
|
|
20113
|
+
pattern[5] = value(1);
|
|
20114
|
+
pattern[7] = value(2);
|
|
20115
|
+
pattern[3] = value(3);
|
|
20116
|
+
return pattern;
|
|
20117
|
+
}
|
|
20118
|
+
function resolveLdtkTiles(rules, grid) {
|
|
20119
|
+
const out = [];
|
|
20120
|
+
for (let cy = 0; cy < grid.height; cy++) {
|
|
20121
|
+
for (let cx = 0; cx < grid.width; cx++) {
|
|
20122
|
+
const rule = rules.find((candidate) => ldtkRuleMatches(candidate, grid, cx, cy));
|
|
20123
|
+
if (rule) out.push({ cx, cy, rule, tile: rule.tileRectsIds[(cx * 7 + cy * 13) % rule.tileRectsIds.length][0] });
|
|
20124
|
+
}
|
|
20125
|
+
}
|
|
20126
|
+
return out;
|
|
20127
|
+
}
|
|
20128
|
+
function demoGrid(rules, wanted) {
|
|
20129
|
+
let best = null;
|
|
20130
|
+
let bestCovered = -1;
|
|
20131
|
+
for (let seed = 1; seed <= 400; seed++) {
|
|
20132
|
+
let state = seed * 2654435761 >>> 0;
|
|
20133
|
+
const cells = Array.from({ length: DEMO_WIDTH * DEMO_HEIGHT }, () => {
|
|
20134
|
+
state = Math.imul(state, 1664525) + 1013904223 >>> 0;
|
|
20135
|
+
return (state >>> 16) % 100 < 52 ? FIRST : SECOND;
|
|
20136
|
+
});
|
|
20137
|
+
const grid = { width: DEMO_WIDTH, height: DEMO_HEIGHT, cells };
|
|
20138
|
+
const covered = new Set(resolveLdtkTiles(rules, grid).map((hit) => hit.rule.uid)).size;
|
|
20139
|
+
if (covered > bestCovered) {
|
|
20140
|
+
best = grid;
|
|
20141
|
+
bestCovered = covered;
|
|
20142
|
+
}
|
|
20143
|
+
if (covered >= wanted) break;
|
|
20144
|
+
}
|
|
20145
|
+
return best;
|
|
20146
|
+
}
|
|
20147
|
+
var TERRAIN_COLORS = ["#5AB552", "#4C78A8"];
|
|
20148
|
+
function buildLdtk(generic, tileType) {
|
|
20149
|
+
const rules = generic.rules;
|
|
20150
|
+
if (!rules || rules.ruleType === "outline") {
|
|
20151
|
+
throw new Error("ldtk export needs recognized corner or edge adjacency rules; use --format generic");
|
|
20152
|
+
}
|
|
20153
|
+
if (tileType === void 0 || tileType === "isometric" || tileType === "oblique" || tileType === "hex" || tileType === "hex_pointy") {
|
|
20154
|
+
throw new Error(
|
|
20155
|
+
`ldtk export needs square tiles on an orthogonal grid, and this set is ${tileType ?? "isometric"}; use --format generic or --format tiled`
|
|
20156
|
+
);
|
|
20157
|
+
}
|
|
20158
|
+
const grid = generic.tile.width;
|
|
20159
|
+
if (generic.tile.width !== generic.tile.height) {
|
|
20160
|
+
throw new Error(`ldtk grids are square; these tiles are ${generic.tile.width}x${generic.tile.height}`);
|
|
20161
|
+
}
|
|
20162
|
+
const corner = rules.ruleType === "corner";
|
|
20163
|
+
const base = identifier(generic.name.replace("/", "_"), "Tileset");
|
|
20164
|
+
const name = base.charAt(0).toUpperCase() + base.slice(1);
|
|
20165
|
+
const terrainNames = [rules.terrains[0] ?? "feature", rules.terrains[1] ?? "background"];
|
|
20166
|
+
const columns = generic.sheet.columns;
|
|
20167
|
+
const rows = Math.ceil(generic.tiles.length / columns);
|
|
20168
|
+
const byMask = /* @__PURE__ */ new Map();
|
|
20169
|
+
for (const tile of generic.tiles) {
|
|
20170
|
+
if (tile.bitmask === void 0) continue;
|
|
20171
|
+
byMask.set(tile.bitmask, [...byMask.get(tile.bitmask) ?? [], tile.id]);
|
|
20172
|
+
}
|
|
20173
|
+
if (!byMask.size) throw new Error("ldtk export found no tiles with adjacency masks; use --format generic");
|
|
20174
|
+
const tilesetUid = 1;
|
|
20175
|
+
const sourceUid = 2;
|
|
20176
|
+
const autoUid = 3;
|
|
20177
|
+
const groupUid = 4;
|
|
20178
|
+
const ruleList = [...byMask.entries()].map(([mask, ids], index) => ({
|
|
20179
|
+
uid: 5 + index,
|
|
20180
|
+
active: true,
|
|
20181
|
+
size: 3,
|
|
20182
|
+
tileRectsIds: ids.map((id) => [id]),
|
|
20183
|
+
alpha: 1,
|
|
20184
|
+
chance: 1,
|
|
20185
|
+
breakOnMatch: true,
|
|
20186
|
+
pattern: ldtkPattern(rules, mask),
|
|
20187
|
+
flipX: false,
|
|
20188
|
+
flipY: false,
|
|
20189
|
+
xModulo: 1,
|
|
20190
|
+
yModulo: 1,
|
|
20191
|
+
xOffset: 0,
|
|
20192
|
+
yOffset: 0,
|
|
20193
|
+
tileXOffset: 0,
|
|
20194
|
+
tileYOffset: 0,
|
|
20195
|
+
tileRandomXMin: 0,
|
|
20196
|
+
tileRandomXMax: 0,
|
|
20197
|
+
tileRandomYMin: 0,
|
|
20198
|
+
tileRandomYMax: 0,
|
|
20199
|
+
checker: "None",
|
|
20200
|
+
tileMode: "Single",
|
|
20201
|
+
pivotX: 0,
|
|
20202
|
+
pivotY: 0,
|
|
20203
|
+
outOfBoundsValue: SECOND,
|
|
20204
|
+
invalidated: false,
|
|
20205
|
+
perlinActive: false,
|
|
20206
|
+
perlinSeed: 1,
|
|
20207
|
+
perlinScale: 0.2,
|
|
20208
|
+
perlinOctaves: 2
|
|
20209
|
+
}));
|
|
20210
|
+
const levelUid = 5 + ruleList.length;
|
|
20211
|
+
const nextUid = levelUid + 1;
|
|
20212
|
+
const tileRect = (id) => {
|
|
20213
|
+
const tile = generic.tiles.find((candidate) => candidate.id === id);
|
|
20214
|
+
return tile ? { tilesetUid, x: tile.x, y: tile.y, w: tile.width, h: tile.height } : null;
|
|
20215
|
+
};
|
|
20216
|
+
const full = (1 << rules.arity) - 1;
|
|
20217
|
+
const representative = (terrain) => generic.tiles.find((tile) => tile.bitmask === (terrain === 0 ? full : 0))?.id;
|
|
20218
|
+
const shift = corner ? -Math.floor(grid / 2) : 0;
|
|
20219
|
+
const sourceName = `${name}_${corner ? "corners" : "cells"}`;
|
|
20220
|
+
const autoName = name;
|
|
20221
|
+
const layerBase = {
|
|
20222
|
+
guideGridWid: 0,
|
|
20223
|
+
guideGridHei: 0,
|
|
20224
|
+
displayOpacity: 1,
|
|
20225
|
+
inactiveOpacity: 1,
|
|
20226
|
+
hideInList: false,
|
|
20227
|
+
hideFieldsWhenInactive: false,
|
|
20228
|
+
canSelectWhenInactive: true,
|
|
20229
|
+
parallaxFactorX: 0,
|
|
20230
|
+
parallaxFactorY: 0,
|
|
20231
|
+
parallaxScaling: true,
|
|
20232
|
+
requiredTags: [],
|
|
20233
|
+
excludedTags: [],
|
|
20234
|
+
autoTilesKilledByOtherLayerUid: null,
|
|
20235
|
+
uiFilterTags: [],
|
|
20236
|
+
useAsyncRender: false,
|
|
20237
|
+
tilePivotX: 0,
|
|
20238
|
+
tilePivotY: 0,
|
|
20239
|
+
biomeFieldUid: null,
|
|
20240
|
+
gridSize: grid,
|
|
20241
|
+
tilesetDefUid: tilesetUid
|
|
20242
|
+
};
|
|
20243
|
+
const sourceLayer = {
|
|
20244
|
+
__type: "IntGrid",
|
|
20245
|
+
identifier: sourceName,
|
|
20246
|
+
type: "IntGrid",
|
|
20247
|
+
uid: sourceUid,
|
|
20248
|
+
doc: corner ? `Paint ${terrainNames[0]} (1) and ${terrainNames[1]} (2). Each cell is a corner where four tiles meet, so it is drawn half a tile up and left of the tiles it controls.` : `Paint ${terrainNames[0]} (1) and ${terrainNames[1]} (2). Each tile looks at its own cell and the four around it.`,
|
|
20249
|
+
uiColor: TERRAIN_COLORS[0],
|
|
20250
|
+
...layerBase,
|
|
20251
|
+
renderInWorldView: true,
|
|
20252
|
+
pxOffsetX: shift,
|
|
20253
|
+
pxOffsetY: shift,
|
|
20254
|
+
intGridValues: [FIRST, SECOND].map((value, index) => ({
|
|
20255
|
+
value,
|
|
20256
|
+
identifier: identifier(terrainNames[index], `terrain${value}`),
|
|
20257
|
+
color: TERRAIN_COLORS[index],
|
|
20258
|
+
tile: tileRect(representative(index)),
|
|
20259
|
+
groupUid: 0
|
|
20260
|
+
})),
|
|
20261
|
+
intGridValuesGroups: [],
|
|
20262
|
+
autoRuleGroups: [],
|
|
20263
|
+
autoSourceLayerDefUid: null
|
|
20264
|
+
};
|
|
20265
|
+
const autoLayer = {
|
|
20266
|
+
__type: "AutoLayer",
|
|
20267
|
+
identifier: autoName,
|
|
20268
|
+
type: "AutoLayer",
|
|
20269
|
+
uid: autoUid,
|
|
20270
|
+
doc: `Drawn by rules from ${sourceName}: one rule for each way the two terrains can meet.`,
|
|
20271
|
+
uiColor: TERRAIN_COLORS[1],
|
|
20272
|
+
...layerBase,
|
|
20273
|
+
renderInWorldView: true,
|
|
20274
|
+
pxOffsetX: 0,
|
|
20275
|
+
pxOffsetY: 0,
|
|
20276
|
+
intGridValues: [],
|
|
20277
|
+
intGridValuesGroups: [],
|
|
20278
|
+
autoRuleGroups: [{
|
|
20279
|
+
uid: groupUid,
|
|
20280
|
+
name: "Borders",
|
|
20281
|
+
color: null,
|
|
20282
|
+
icon: null,
|
|
20283
|
+
active: true,
|
|
20284
|
+
isOptional: false,
|
|
20285
|
+
rules: ruleList,
|
|
20286
|
+
usesWizard: false,
|
|
20287
|
+
requiredBiomeValues: [],
|
|
20288
|
+
biomeRequirementMode: 0
|
|
20289
|
+
}],
|
|
20290
|
+
autoSourceLayerDefUid: sourceUid
|
|
20291
|
+
};
|
|
20292
|
+
const level = demoGrid(ruleList, ruleList.length);
|
|
20293
|
+
const hits = resolveLdtkTiles(ruleList, level);
|
|
20294
|
+
const tileAt = (id) => ({ x: id % columns * grid, y: Math.floor(id / columns) * grid });
|
|
20295
|
+
const instanceBase = (layerDef, offset) => ({
|
|
20296
|
+
__identifier: layerDef.identifier,
|
|
20297
|
+
__type: layerDef.__type,
|
|
20298
|
+
__cWid: DEMO_WIDTH,
|
|
20299
|
+
__cHei: DEMO_HEIGHT,
|
|
20300
|
+
__gridSize: grid,
|
|
20301
|
+
__opacity: 1,
|
|
20302
|
+
__pxTotalOffsetX: offset,
|
|
20303
|
+
__pxTotalOffsetY: offset,
|
|
20304
|
+
__tilesetDefUid: tilesetUid,
|
|
20305
|
+
__tilesetRelPath: generic.image,
|
|
20306
|
+
iid: iid(generic.name, "layer", layerDef.uid),
|
|
20307
|
+
levelId: levelUid,
|
|
20308
|
+
layerDefUid: layerDef.uid,
|
|
20309
|
+
pxOffsetX: 0,
|
|
20310
|
+
pxOffsetY: 0,
|
|
20311
|
+
visible: true,
|
|
20312
|
+
optionalRules: [],
|
|
20313
|
+
seed: 1e3 + layerDef.uid,
|
|
20314
|
+
overrideTilesetUid: null,
|
|
20315
|
+
gridTiles: [],
|
|
20316
|
+
entityInstances: []
|
|
20317
|
+
});
|
|
20318
|
+
const project2 = {
|
|
20319
|
+
__header__: {
|
|
20320
|
+
fileType: "LDtk Project JSON",
|
|
20321
|
+
app: "LDtk",
|
|
20322
|
+
doc: "https://ldtk.io/json",
|
|
20323
|
+
schema: "https://ldtk.io/files/JSON_SCHEMA.json",
|
|
20324
|
+
appAuthor: "Sebastien 'deepnight' Benard",
|
|
20325
|
+
appVersion: LDTK_JSON_VERSION,
|
|
20326
|
+
url: "https://ldtk.io"
|
|
20327
|
+
},
|
|
20328
|
+
iid: iid(generic.name, "project"),
|
|
20329
|
+
jsonVersion: LDTK_JSON_VERSION,
|
|
20330
|
+
appBuildId: 473702,
|
|
20331
|
+
nextUid,
|
|
20332
|
+
identifierStyle: "Capitalize",
|
|
20333
|
+
toc: [],
|
|
20334
|
+
worldLayout: "LinearHorizontal",
|
|
20335
|
+
worldGridWidth: 256,
|
|
20336
|
+
worldGridHeight: 256,
|
|
20337
|
+
defaultLevelWidth: DEMO_WIDTH * grid,
|
|
20338
|
+
defaultLevelHeight: DEMO_HEIGHT * grid,
|
|
20339
|
+
defaultPivotX: 0,
|
|
20340
|
+
defaultPivotY: 0,
|
|
20341
|
+
defaultGridSize: grid,
|
|
20342
|
+
defaultEntityWidth: grid,
|
|
20343
|
+
defaultEntityHeight: grid,
|
|
20344
|
+
bgColor: "#4A5066",
|
|
20345
|
+
defaultLevelBgColor: "#474B67",
|
|
20346
|
+
minifyJson: false,
|
|
20347
|
+
externalLevels: false,
|
|
20348
|
+
exportTiled: false,
|
|
20349
|
+
simplifiedExport: false,
|
|
20350
|
+
imageExportMode: "None",
|
|
20351
|
+
exportLevelBg: true,
|
|
20352
|
+
pngFilePattern: null,
|
|
20353
|
+
backupOnSave: false,
|
|
20354
|
+
backupLimit: 10,
|
|
20355
|
+
backupRelPath: null,
|
|
20356
|
+
levelNamePattern: "%world_Level_%idx",
|
|
20357
|
+
tutorialDesc: null,
|
|
20358
|
+
customCommands: [],
|
|
20359
|
+
flags: ["ExportOldTableOfContentData", "UseMultilinesType"],
|
|
20360
|
+
defs: {
|
|
20361
|
+
layers: [autoLayer, sourceLayer],
|
|
20362
|
+
entities: [],
|
|
20363
|
+
tilesets: [{
|
|
20364
|
+
__cWid: columns,
|
|
20365
|
+
__cHei: rows,
|
|
20366
|
+
identifier: `${name}_tiles`,
|
|
20367
|
+
uid: tilesetUid,
|
|
20368
|
+
relPath: generic.image,
|
|
20369
|
+
embedAtlas: null,
|
|
20370
|
+
pxWid: generic.sheet.width,
|
|
20371
|
+
pxHei: generic.sheet.height,
|
|
20372
|
+
tileGridSize: grid,
|
|
20373
|
+
spacing: 0,
|
|
20374
|
+
padding: 0,
|
|
20375
|
+
tags: [],
|
|
20376
|
+
tagsSourceEnumUid: null,
|
|
20377
|
+
enumTags: [],
|
|
20378
|
+
customData: generic.tiles.filter((tile) => tile.bitmask !== void 0).map((tile) => ({ tileId: tile.id, data: `mask=${tile.bitmask}` })),
|
|
20379
|
+
savedSelections: [],
|
|
20380
|
+
cachedPixelData: null
|
|
20381
|
+
}],
|
|
20382
|
+
enums: [],
|
|
20383
|
+
externalEnums: [],
|
|
20384
|
+
levelFields: []
|
|
20385
|
+
},
|
|
20386
|
+
levels: [{
|
|
20387
|
+
identifier: "Preview",
|
|
20388
|
+
iid: iid(generic.name, "level"),
|
|
20389
|
+
uid: levelUid,
|
|
20390
|
+
// A linear world ignores the position; LDtk itself writes -1 for it.
|
|
20391
|
+
worldX: -1,
|
|
20392
|
+
worldY: -1,
|
|
20393
|
+
worldDepth: 0,
|
|
20394
|
+
pxWid: DEMO_WIDTH * grid,
|
|
20395
|
+
pxHei: DEMO_HEIGHT * grid,
|
|
20396
|
+
__bgColor: "#474B67",
|
|
20397
|
+
bgColor: null,
|
|
20398
|
+
useAutoIdentifier: false,
|
|
20399
|
+
bgRelPath: null,
|
|
20400
|
+
bgPos: null,
|
|
20401
|
+
bgPivotX: 0.5,
|
|
20402
|
+
bgPivotY: 0.5,
|
|
20403
|
+
__smartColor: "#9A9CAB",
|
|
20404
|
+
__bgPos: null,
|
|
20405
|
+
externalRelPath: null,
|
|
20406
|
+
fieldInstances: [],
|
|
20407
|
+
layerInstances: [
|
|
20408
|
+
{
|
|
20409
|
+
...instanceBase(autoLayer, 0),
|
|
20410
|
+
intGridCsv: [],
|
|
20411
|
+
autoLayerTiles: hits.map((hit) => ({
|
|
20412
|
+
px: [hit.cx * grid, hit.cy * grid],
|
|
20413
|
+
src: [tileAt(hit.tile).x, tileAt(hit.tile).y],
|
|
20414
|
+
f: 0,
|
|
20415
|
+
t: hit.tile,
|
|
20416
|
+
d: [hit.rule.uid, hit.cy * DEMO_WIDTH + hit.cx],
|
|
20417
|
+
a: 1
|
|
20418
|
+
}))
|
|
20419
|
+
},
|
|
20420
|
+
{
|
|
20421
|
+
...instanceBase(sourceLayer, shift),
|
|
20422
|
+
intGridCsv: level.cells,
|
|
20423
|
+
autoLayerTiles: []
|
|
20424
|
+
}
|
|
20425
|
+
],
|
|
20426
|
+
__neighbours: []
|
|
20427
|
+
}],
|
|
20428
|
+
worlds: [],
|
|
20429
|
+
dummyWorldIid: iid(generic.name, "world")
|
|
20430
|
+
};
|
|
20431
|
+
return JSON.stringify(project2, null, 2) + "\n";
|
|
20432
|
+
}
|
|
20433
|
+
|
|
19768
20434
|
// src/pipeline/tileset-export.ts
|
|
19769
20435
|
function normalizeTileRules(raw) {
|
|
19770
20436
|
if (!isRecord2(raw)) return null;
|
|
@@ -19881,6 +20547,15 @@ function exportTileset(entry, spec, options) {
|
|
|
19881
20547
|
sources: packed.sources
|
|
19882
20548
|
};
|
|
19883
20549
|
}
|
|
20550
|
+
if (options.format === "ldtk") {
|
|
20551
|
+
return {
|
|
20552
|
+
png: packed.png,
|
|
20553
|
+
extension: ".ldtk",
|
|
20554
|
+
document: buildLdtk(generic, spec.tileType),
|
|
20555
|
+
generic,
|
|
20556
|
+
sources: packed.sources
|
|
20557
|
+
};
|
|
20558
|
+
}
|
|
19884
20559
|
return {
|
|
19885
20560
|
png: packed.png,
|
|
19886
20561
|
extension: ".tres",
|
|
@@ -20616,34 +21291,34 @@ async function poll(provider, lock, lockPath, opts = {}) {
|
|
|
20616
21291
|
}
|
|
20617
21292
|
|
|
20618
21293
|
// src/pipeline/doctor.ts
|
|
20619
|
-
import { constants, existsSync as
|
|
21294
|
+
import { constants, existsSync as existsSync29 } from "fs";
|
|
20620
21295
|
import { access, stat as stat3 } from "fs/promises";
|
|
20621
|
-
import
|
|
21296
|
+
import path34 from "path";
|
|
20622
21297
|
|
|
20623
21298
|
// src/pipeline/install-check.ts
|
|
20624
|
-
import { existsSync as
|
|
20625
|
-
import
|
|
21299
|
+
import { existsSync as existsSync28, readFileSync as readFileSync9 } from "fs";
|
|
21300
|
+
import path33 from "path";
|
|
20626
21301
|
function readJson(file) {
|
|
20627
21302
|
try {
|
|
20628
|
-
return JSON.parse(
|
|
21303
|
+
return JSON.parse(readFileSync9(file, "utf8"));
|
|
20629
21304
|
} catch {
|
|
20630
21305
|
return null;
|
|
20631
21306
|
}
|
|
20632
21307
|
}
|
|
20633
21308
|
function readInstallFacts(manifestDir, running) {
|
|
20634
|
-
let dir =
|
|
21309
|
+
let dir = path33.resolve(manifestDir);
|
|
20635
21310
|
for (let depth = 0; depth < 4; depth++) {
|
|
20636
|
-
const pkg = readJson(
|
|
21311
|
+
const pkg = readJson(path33.join(dir, "package.json"));
|
|
20637
21312
|
if (pkg) {
|
|
20638
21313
|
const pinned = ["dependencies", "devDependencies", "optionalDependencies"].map((field) => pkg[field]?.pixelkiln).find((spec) => typeof spec === "string");
|
|
20639
21314
|
if (pinned) {
|
|
20640
|
-
const installedPkg = readJson(
|
|
21315
|
+
const installedPkg = readJson(path33.join(dir, "node_modules", "pixelkiln", "package.json"));
|
|
20641
21316
|
const installed = typeof installedPkg?.version === "string" ? installedPkg.version : void 0;
|
|
20642
21317
|
return { pinned, installed, running };
|
|
20643
21318
|
}
|
|
20644
21319
|
}
|
|
20645
|
-
const parent =
|
|
20646
|
-
if (parent === dir || !
|
|
21320
|
+
const parent = path33.dirname(dir);
|
|
21321
|
+
if (parent === dir || !existsSync28(parent)) break;
|
|
20647
21322
|
dir = parent;
|
|
20648
21323
|
}
|
|
20649
21324
|
return null;
|
|
@@ -20706,12 +21381,12 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
20706
21381
|
`${entry.kind === "style" ? "styles" : "assets"}.${entry.id} was left out: ${entry.issues.join("; ")}`
|
|
20707
21382
|
);
|
|
20708
21383
|
}
|
|
20709
|
-
const facts = readInstallFacts(
|
|
21384
|
+
const facts = readInstallFacts(path34.dirname(loaded.path), opts.runningVersion !== void 0 ? opts.runningVersion : pixelkilnVersion());
|
|
20710
21385
|
if (facts) for (const finding of checkInstall(facts)) add("install", finding.level, finding.message);
|
|
20711
21386
|
add("lock", "ok", `${Object.keys(lock.entries).length} valid v2 lock entr(ies)`);
|
|
20712
21387
|
const dirs = [...new Set(specs.flatMap((spec) => [
|
|
20713
|
-
|
|
20714
|
-
...spec.quality ? [
|
|
21388
|
+
path34.dirname(spec.outFile),
|
|
21389
|
+
...spec.quality ? [path34.dirname(spec.quality.outFile)] : []
|
|
20715
21390
|
]))];
|
|
20716
21391
|
const unwritable = [];
|
|
20717
21392
|
for (const dir of dirs) {
|
|
@@ -20734,7 +21409,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
20734
21409
|
for (let index = 0; index < entry.outputs.length; index++) {
|
|
20735
21410
|
const output = entry.outputs[index];
|
|
20736
21411
|
const spec = specByKey.get(key2);
|
|
20737
|
-
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path,
|
|
21412
|
+
const absolute = spec ? currentEntryOutputPath(entry, spec, index) : resolveOutputPath(output.path, path34.dirname(lockPath));
|
|
20738
21413
|
const owner = outputOwners.get(absolute);
|
|
20739
21414
|
if (owner && owner !== key2) duplicateOutputs.push(`${output.path} (${owner}, ${key2})`);
|
|
20740
21415
|
outputOwners.set(absolute, key2);
|
|
@@ -20749,7 +21424,7 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
20749
21424
|
} else {
|
|
20750
21425
|
add("lock-outputs", "ok", `${outputOwners.size} recorded output path(s) are uniquely owned`);
|
|
20751
21426
|
}
|
|
20752
|
-
const cacheDir =
|
|
21427
|
+
const cacheDir = path34.join(path34.dirname(lockPath), ".pixelkiln", "cache");
|
|
20753
21428
|
const stranded = [];
|
|
20754
21429
|
const invalidState = [];
|
|
20755
21430
|
const staleMapUrls = [];
|
|
@@ -20765,11 +21440,11 @@ async function doctor(loaded, specs, lock, lockPath, opts = {}) {
|
|
|
20765
21440
|
const hasSource = Boolean(entry.sourceUrl || entry.sourceUrls?.length);
|
|
20766
21441
|
let hasCache = false;
|
|
20767
21442
|
for (const output of entry.outputs) {
|
|
20768
|
-
const cached2 =
|
|
21443
|
+
const cached2 = path34.join(
|
|
20769
21444
|
cacheDir,
|
|
20770
21445
|
cacheFileName(output.sha256, output.mediaType ?? MediaType.PNG)
|
|
20771
21446
|
);
|
|
20772
|
-
if (
|
|
21447
|
+
if (existsSync29(cached2) && await sha256File(cached2) === output.sha256) {
|
|
20773
21448
|
hasCache = true;
|
|
20774
21449
|
break;
|
|
20775
21450
|
}
|
|
@@ -20865,16 +21540,16 @@ async function nearestExistingDirectory(start) {
|
|
|
20865
21540
|
if ((await stat3(current)).isDirectory()) return current;
|
|
20866
21541
|
} catch {
|
|
20867
21542
|
}
|
|
20868
|
-
const parent =
|
|
21543
|
+
const parent = path34.dirname(current);
|
|
20869
21544
|
if (parent === current) return current;
|
|
20870
21545
|
current = parent;
|
|
20871
21546
|
}
|
|
20872
21547
|
}
|
|
20873
21548
|
|
|
20874
21549
|
// src/pipeline/adopt.ts
|
|
20875
|
-
import { existsSync as
|
|
20876
|
-
import { readFile as
|
|
20877
|
-
import
|
|
21550
|
+
import { existsSync as existsSync30 } from "fs";
|
|
21551
|
+
import { readFile as readFile20, writeFile as writeFile14 } from "fs/promises";
|
|
21552
|
+
import path35 from "path";
|
|
20878
21553
|
async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
20879
21554
|
const log = opts.onProgress ?? (() => {
|
|
20880
21555
|
});
|
|
@@ -20885,11 +21560,11 @@ async function adopt(provider, specs, lock, lockPath, opts = {}) {
|
|
|
20885
21560
|
const localByHash = /* @__PURE__ */ new Map();
|
|
20886
21561
|
const unmatchedLocal = [];
|
|
20887
21562
|
for (const spec of specs) {
|
|
20888
|
-
if (!
|
|
21563
|
+
if (!existsSync30(spec.outFile)) {
|
|
20889
21564
|
unmatchedLocal.push(`${spec.styleId}/${spec.assetId} (no file at ${spec.outFile})`);
|
|
20890
21565
|
continue;
|
|
20891
21566
|
}
|
|
20892
|
-
const bytes = await
|
|
21567
|
+
const bytes = await readFile20(spec.outFile);
|
|
20893
21568
|
try {
|
|
20894
21569
|
decodePng(bytes);
|
|
20895
21570
|
} catch (err) {
|
|
@@ -21007,9 +21682,9 @@ async function tagAdopted(provider, specs, lock, opts = {}) {
|
|
|
21007
21682
|
}
|
|
21008
21683
|
|
|
21009
21684
|
// src/pipeline/import.ts
|
|
21010
|
-
import { existsSync as
|
|
21011
|
-
import { readFile as
|
|
21012
|
-
import
|
|
21685
|
+
import { existsSync as existsSync31 } from "fs";
|
|
21686
|
+
import { readFile as readFile21 } from "fs/promises";
|
|
21687
|
+
import path36 from "path";
|
|
21013
21688
|
function buildImportedEntry(spec, bytes, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
21014
21689
|
const png = decodePng(bytes);
|
|
21015
21690
|
const at2 = now.toISOString();
|
|
@@ -21061,13 +21736,13 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
21061
21736
|
if (opts.objectId && specs.length !== 1) {
|
|
21062
21737
|
throw new Error(`--object-id names one object; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
21063
21738
|
}
|
|
21064
|
-
const cacheDir = opts.cacheDir === false ? null :
|
|
21739
|
+
const cacheDir = opts.cacheDir === false ? null : path36.resolve(opts.cacheDir ?? path36.join(path36.dirname(lockPath), ".pixelkiln", "cache"));
|
|
21065
21740
|
let rawSha256;
|
|
21066
21741
|
let rawBytes;
|
|
21067
21742
|
if (opts.raw) {
|
|
21068
21743
|
if (specs.length !== 1) throw new Error(`--raw names one original; ${specs.length} assets are selected. Narrow with --only and --style.`);
|
|
21069
21744
|
try {
|
|
21070
|
-
rawBytes = await
|
|
21745
|
+
rawBytes = await readFile21(opts.raw);
|
|
21071
21746
|
decodePng(rawBytes);
|
|
21072
21747
|
} catch (error) {
|
|
21073
21748
|
throw new Error(`--raw ${opts.raw} is not a readable PNG: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
@@ -21083,7 +21758,7 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
21083
21758
|
skipped.push({ key: key2, reason });
|
|
21084
21759
|
continue;
|
|
21085
21760
|
}
|
|
21086
|
-
if (!
|
|
21761
|
+
if (!existsSync31(spec.outFile)) {
|
|
21087
21762
|
skipped.push({ key: key2, reason: `no file at ${spec.outFile}` });
|
|
21088
21763
|
continue;
|
|
21089
21764
|
}
|
|
@@ -21094,7 +21769,7 @@ async function importLocal(specs, lock, lockPath, opts = {}) {
|
|
|
21094
21769
|
let patch;
|
|
21095
21770
|
let bytes;
|
|
21096
21771
|
try {
|
|
21097
|
-
bytes = await
|
|
21772
|
+
bytes = await readFile21(spec.outFile);
|
|
21098
21773
|
patch = buildImportedEntry(spec, bytes, { ...opts, rawSha256 }, /* @__PURE__ */ new Date());
|
|
21099
21774
|
} catch (error) {
|
|
21100
21775
|
skipped.push({ key: key2, reason: `invalid PNG: ${error instanceof Error ? error.message : String(error)}` });
|
|
@@ -21126,7 +21801,7 @@ async function reportSpecHashes(specs, lock) {
|
|
|
21126
21801
|
for (const spec of specs) {
|
|
21127
21802
|
const key2 = lockKey(spec.styleId, spec.assetId);
|
|
21128
21803
|
let bytes = null;
|
|
21129
|
-
if (
|
|
21804
|
+
if (existsSync31(spec.outFile)) bytes = await readFile21(spec.outFile);
|
|
21130
21805
|
let wouldImport = null;
|
|
21131
21806
|
if (bytes && !unimportable(spec)) {
|
|
21132
21807
|
try {
|
|
@@ -21155,13 +21830,13 @@ async function reportSpecHashes(specs, lock) {
|
|
|
21155
21830
|
}
|
|
21156
21831
|
|
|
21157
21832
|
// src/pick/server.ts
|
|
21158
|
-
import { existsSync as
|
|
21159
|
-
import { readFile as
|
|
21833
|
+
import { existsSync as existsSync33 } from "fs";
|
|
21834
|
+
import { readFile as readFile24 } from "fs/promises";
|
|
21160
21835
|
|
|
21161
21836
|
// src/pipeline/init.ts
|
|
21162
|
-
import { readdir as readdir4, readFile as
|
|
21163
|
-
import { existsSync as
|
|
21164
|
-
import
|
|
21837
|
+
import { readdir as readdir4, readFile as readFile22, writeFile as writeFile15 } from "fs/promises";
|
|
21838
|
+
import { existsSync as existsSync32 } from "fs";
|
|
21839
|
+
import path37 from "path";
|
|
21165
21840
|
function pngSize(buf) {
|
|
21166
21841
|
if (buf.length < 24) return null;
|
|
21167
21842
|
const isPng = buf.readUInt32BE(0) === 2303741511 && buf.readUInt32BE(4) === 218765834;
|
|
@@ -21175,7 +21850,7 @@ function slugify(value) {
|
|
|
21175
21850
|
async function walk(dir, exclude) {
|
|
21176
21851
|
const out = [];
|
|
21177
21852
|
for (const entry of await readdir4(dir, { withFileTypes: true })) {
|
|
21178
|
-
const full =
|
|
21853
|
+
const full = path37.join(dir, entry.name);
|
|
21179
21854
|
if (exclude.some((x) => full.includes(x))) continue;
|
|
21180
21855
|
if (entry.isDirectory()) out.push(...await walk(full, exclude));
|
|
21181
21856
|
else if (entry.name.toLowerCase().endsWith(".png")) out.push(full);
|
|
@@ -21189,14 +21864,14 @@ async function scanAssets(root, opts = {}) {
|
|
|
21189
21864
|
const skipped = [];
|
|
21190
21865
|
const seen = /* @__PURE__ */ new Map();
|
|
21191
21866
|
for (const file of files.sort()) {
|
|
21192
|
-
const size = pngSize(await
|
|
21867
|
+
const size = pngSize(await readFile22(file));
|
|
21193
21868
|
if (!size) {
|
|
21194
21869
|
skipped.push(`${file} (not a readable PNG)`);
|
|
21195
21870
|
continue;
|
|
21196
21871
|
}
|
|
21197
|
-
const rel =
|
|
21198
|
-
const category =
|
|
21199
|
-
let id = slugify(
|
|
21872
|
+
const rel = path37.relative(root, file);
|
|
21873
|
+
const category = path37.dirname(rel) === "." ? "" : path37.dirname(rel);
|
|
21874
|
+
let id = slugify(path37.basename(rel));
|
|
21200
21875
|
if (seen.has(id)) {
|
|
21201
21876
|
const n = seen.get(id) + 1;
|
|
21202
21877
|
seen.set(id, n);
|
|
@@ -21670,7 +22345,7 @@ document.getElementById('submit').onclick = async () => {
|
|
|
21670
22345
|
|
|
21671
22346
|
// src/pick/review-server.ts
|
|
21672
22347
|
import { createServer } from "http";
|
|
21673
|
-
import { readFile as
|
|
22348
|
+
import { readFile as readFile23 } from "fs/promises";
|
|
21674
22349
|
function serveReviewPage(opts) {
|
|
21675
22350
|
const log = opts.onProgress ?? (() => {
|
|
21676
22351
|
});
|
|
@@ -21679,7 +22354,7 @@ function serveReviewPage(opts) {
|
|
|
21679
22354
|
if (req.method === "GET" && req.url && opts.assets?.has(req.url)) {
|
|
21680
22355
|
try {
|
|
21681
22356
|
const asset = opts.assets.get(req.url);
|
|
21682
|
-
const bytes = await
|
|
22357
|
+
const bytes = await readFile23(asset.path);
|
|
21683
22358
|
res.writeHead(200, {
|
|
21684
22359
|
"Content-Type": asset.contentType,
|
|
21685
22360
|
"Cache-Control": "no-store",
|
|
@@ -21755,13 +22430,13 @@ async function currentArt(entry, spec) {
|
|
|
21755
22430
|
const previous = primaryOutput({ ...entry, outputs: entry.supersededOutputs });
|
|
21756
22431
|
if (!previous) return null;
|
|
21757
22432
|
const file = resolveOutputPath(previous.path, spec.root);
|
|
21758
|
-
if (!
|
|
22433
|
+
if (!existsSync33(file)) return null;
|
|
21759
22434
|
const contentType = previous.mediaType ?? mediaTypeFromExtension(file);
|
|
21760
22435
|
if (!contentType) return null;
|
|
21761
22436
|
let width = entry.width;
|
|
21762
22437
|
let height = entry.height;
|
|
21763
22438
|
if (contentType === "image/png") {
|
|
21764
|
-
const size = pngSize(await
|
|
22439
|
+
const size = pngSize(await readFile24(file));
|
|
21765
22440
|
if (size) ({ width, height } = size);
|
|
21766
22441
|
}
|
|
21767
22442
|
return { path: file, contentType, width, height };
|
|
@@ -21769,7 +22444,7 @@ async function currentArt(entry, spec) {
|
|
|
21769
22444
|
async function cachedFrame(url) {
|
|
21770
22445
|
if (!url.startsWith("file://")) return null;
|
|
21771
22446
|
const file = url.slice("file://".length);
|
|
21772
|
-
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await
|
|
22447
|
+
const contentType = mediaTypeFromExtension(file) ?? detectMediaType(await readFile24(file).catch(() => Buffer.alloc(0))) ?? "application/octet-stream";
|
|
21773
22448
|
return { path: file, contentType };
|
|
21774
22449
|
}
|
|
21775
22450
|
async function prepareReview(provider, lock, opts = {}) {
|
|
@@ -21801,7 +22476,7 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
21801
22476
|
frameSizes.push(null);
|
|
21802
22477
|
continue;
|
|
21803
22478
|
}
|
|
21804
|
-
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await
|
|
22479
|
+
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await readFile24(cached2.path).catch(() => Buffer.alloc(0))) : null);
|
|
21805
22480
|
const route = `${prefix}/review-frame/${encodeURIComponent(String(groups.length))}/${index}`;
|
|
21806
22481
|
frameAssets.push([route, cached2]);
|
|
21807
22482
|
frameUrls.push(route);
|
|
@@ -21954,15 +22629,15 @@ async function runPicker(provider, lock, lockPath, opts = {}) {
|
|
|
21954
22629
|
}
|
|
21955
22630
|
|
|
21956
22631
|
// src/gallery/snapshot.ts
|
|
21957
|
-
import { createHash as
|
|
21958
|
-
import { existsSync as
|
|
21959
|
-
import { readFile as
|
|
21960
|
-
import
|
|
22632
|
+
import { createHash as createHash8 } from "crypto";
|
|
22633
|
+
import { existsSync as existsSync42 } from "fs";
|
|
22634
|
+
import { readFile as readFile34, stat as stat5 } from "fs/promises";
|
|
22635
|
+
import path48 from "path";
|
|
21961
22636
|
|
|
21962
22637
|
// src/gallery/models.ts
|
|
21963
|
-
import { existsSync as
|
|
21964
|
-
import { readFile as
|
|
21965
|
-
import
|
|
22638
|
+
import { existsSync as existsSync37 } from "fs";
|
|
22639
|
+
import { readFile as readFile29, stat as stat4 } from "fs/promises";
|
|
22640
|
+
import path42 from "path";
|
|
21966
22641
|
import { z as z11 } from "zod";
|
|
21967
22642
|
|
|
21968
22643
|
// src/glb.ts
|
|
@@ -22295,11 +22970,11 @@ function modelItems(json) {
|
|
|
22295
22970
|
}
|
|
22296
22971
|
|
|
22297
22972
|
// src/manifest-edit.ts
|
|
22298
|
-
import { readFile as
|
|
22299
|
-
import
|
|
22973
|
+
import { readFile as readFile25, rename as rename8, rm as rm7, writeFile as writeFile16 } from "fs/promises";
|
|
22974
|
+
import path38 from "path";
|
|
22300
22975
|
import { z as z8 } from "zod";
|
|
22301
22976
|
var HexSha = z8.string().regex(/^[0-9a-f]{64}$/);
|
|
22302
|
-
var ProjectFileSchema = z8.string().min(1).refine((file) => !
|
|
22977
|
+
var ProjectFileSchema = z8.string().min(1).refine((file) => !path38.isAbsolute(file) && !file.split(/[\\/]/).includes(".."), "must be a path inside the project");
|
|
22303
22978
|
var AssetPatchSchema = z8.object({
|
|
22304
22979
|
prompt: z8.string().optional(),
|
|
22305
22980
|
/** Per-style override for the style being viewed; null removes it. */
|
|
@@ -22719,8 +23394,8 @@ function applyEdit(raw, edit) {
|
|
|
22719
23394
|
}
|
|
22720
23395
|
}
|
|
22721
23396
|
async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
22722
|
-
const absolute =
|
|
22723
|
-
const original = await
|
|
23397
|
+
const absolute = path38.resolve(manifestPath);
|
|
23398
|
+
const original = await readFile25(absolute, "utf8");
|
|
22724
23399
|
if (sha256(original) !== edit.expectedSha256) throw new ManifestDriftError(absolute);
|
|
22725
23400
|
let raw;
|
|
22726
23401
|
try {
|
|
@@ -22733,9 +23408,9 @@ async function withCandidate(manifestPath, edit, use, unchanged) {
|
|
|
22733
23408
|
applyEdit(raw, edit);
|
|
22734
23409
|
const next = serializeLike(original, raw);
|
|
22735
23410
|
if (next === original) return unchanged(absolute, original);
|
|
22736
|
-
const tmp =
|
|
22737
|
-
|
|
22738
|
-
`.${
|
|
23411
|
+
const tmp = path38.join(
|
|
23412
|
+
path38.dirname(absolute),
|
|
23413
|
+
`.${path38.basename(absolute)}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`
|
|
22739
23414
|
);
|
|
22740
23415
|
try {
|
|
22741
23416
|
await writeFile16(tmp, next);
|
|
@@ -22764,18 +23439,18 @@ async function applyManifestEdit(manifestPath, edit) {
|
|
|
22764
23439
|
}
|
|
22765
23440
|
|
|
22766
23441
|
// src/pipeline/hand-edit.ts
|
|
22767
|
-
import { existsSync as
|
|
22768
|
-
import { copyFile, mkdir as mkdir14, readFile as
|
|
22769
|
-
import
|
|
23442
|
+
import { existsSync as existsSync34 } from "fs";
|
|
23443
|
+
import { copyFile, mkdir as mkdir14, readFile as readFile26, rename as rename9, rm as rm8, writeFile as writeFile17 } from "fs/promises";
|
|
23444
|
+
import path39 from "path";
|
|
22770
23445
|
import { z as z9 } from "zod";
|
|
22771
23446
|
var HAND_EDIT_DIR = "edits";
|
|
22772
23447
|
function handEditPath(loaded, spec) {
|
|
22773
23448
|
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
|
|
23449
|
+
const outDir = path39.resolve(loaded.root, style?.outDir ?? ".");
|
|
23450
|
+
const relative = path39.relative(outDir, spec.outFile);
|
|
23451
|
+
const inside2 = relative && !relative.startsWith("..") && !path39.isAbsolute(relative);
|
|
23452
|
+
const file = inside2 ? relative : path39.basename(spec.outFile);
|
|
23453
|
+
return path39.join(outDir, HAND_EDIT_DIR, file.replace(/\.gif$/i, ".png"));
|
|
22779
23454
|
}
|
|
22780
23455
|
function handEditBases(spec, lock) {
|
|
22781
23456
|
const entry = lock.entries[lockKey(spec.styleId, spec.assetId)];
|
|
@@ -22788,10 +23463,10 @@ function handEditBases(spec, lock) {
|
|
|
22788
23463
|
}));
|
|
22789
23464
|
if (members.some((member) => member.mediaType && member.mediaType !== "image/png")) return null;
|
|
22790
23465
|
if (entry.outputs.length === 1 && !primaryOutput(entry)) return null;
|
|
22791
|
-
if (!members.every((member) =>
|
|
23466
|
+
if (!members.every((member) => existsSync34(member.path))) return null;
|
|
22792
23467
|
return members.map(({ role, path: file }) => ({ role, path: file }));
|
|
22793
23468
|
}
|
|
22794
|
-
return
|
|
23469
|
+
return existsSync34(spec.outFile) ? [{ role: null, path: spec.outFile }] : null;
|
|
22795
23470
|
}
|
|
22796
23471
|
function handEditBase(spec, lock) {
|
|
22797
23472
|
const bases = handEditBases(spec, lock);
|
|
@@ -22841,18 +23516,18 @@ async function startHandEdit(loaded, lock, spec, opts = {}) {
|
|
|
22841
23516
|
`${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
23517
|
);
|
|
22843
23518
|
}
|
|
22844
|
-
const existing = spec.source ?
|
|
23519
|
+
const existing = spec.source ? path39.resolve(loaded.root, spec.source) : null;
|
|
22845
23520
|
const editPath = existing ?? handEditPath(loaded, spec);
|
|
22846
23521
|
const members = handEditMembers(loaded, spec, lock, editPath);
|
|
22847
23522
|
let created = false;
|
|
22848
23523
|
for (const member of members) {
|
|
22849
|
-
if (
|
|
23524
|
+
if (existsSync34(member.path)) continue;
|
|
22850
23525
|
if (!member.base) {
|
|
22851
23526
|
throw new ManifestEditError(
|
|
22852
23527
|
`${spec.styleId}/${spec.assetId} has no generated PNG on disk to start from; generate or restore it first`
|
|
22853
23528
|
);
|
|
22854
23529
|
}
|
|
22855
|
-
await mkdir14(
|
|
23530
|
+
await mkdir14(path39.dirname(member.path), { recursive: true });
|
|
22856
23531
|
await copyFile(member.base, member.path);
|
|
22857
23532
|
created = true;
|
|
22858
23533
|
}
|
|
@@ -22931,7 +23606,7 @@ function handEditProjectPath(editPath) {
|
|
|
22931
23606
|
async function readHandEditCompanion(editPath) {
|
|
22932
23607
|
let text;
|
|
22933
23608
|
try {
|
|
22934
|
-
text = await
|
|
23609
|
+
text = await readFile26(handEditCompanionPath(editPath), "utf8");
|
|
22935
23610
|
} catch {
|
|
22936
23611
|
return null;
|
|
22937
23612
|
}
|
|
@@ -22975,7 +23650,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
22975
23650
|
}
|
|
22976
23651
|
});
|
|
22977
23652
|
const bases = handEditBases(spec, lock);
|
|
22978
|
-
const expectedSize = bases?.[0] ? decodePng(await
|
|
23653
|
+
const expectedSize = bases?.[0] ? decodePng(await readFile26(bases[0].path)) : { width: spec.width, height: spec.height };
|
|
22979
23654
|
for (const [index, image] of decoded.entries()) {
|
|
22980
23655
|
if (image.width !== expectedSize.width || image.height !== expectedSize.height) {
|
|
22981
23656
|
const which = memberSet ? `member ${incoming[index].role ?? index}` : "the edit";
|
|
@@ -22991,7 +23666,7 @@ async function saveHandEdit(loaded, lock, spec, input) {
|
|
|
22991
23666
|
editor: input.editor,
|
|
22992
23667
|
protocol: input.protocol,
|
|
22993
23668
|
savedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
22994
|
-
project: projectPath ?
|
|
23669
|
+
project: projectPath ? path39.basename(projectPath) : null,
|
|
22995
23670
|
outputs: incoming.map((frame, index) => ({
|
|
22996
23671
|
role: frame.role,
|
|
22997
23672
|
basedOn: basedOnHash(entry, index),
|
|
@@ -23034,9 +23709,9 @@ function openInEditor(file, editor = process.env.PIXELKILN_EDITOR) {
|
|
|
23034
23709
|
|
|
23035
23710
|
// src/pipeline/model-edit.ts
|
|
23036
23711
|
import { spawn as spawn2 } from "child_process";
|
|
23037
|
-
import { existsSync as
|
|
23038
|
-
import { mkdir as mkdir15, readdir as readdir5, readFile as
|
|
23039
|
-
import
|
|
23712
|
+
import { existsSync as existsSync35, readdirSync as readdirSync2 } from "fs";
|
|
23713
|
+
import { mkdir as mkdir15, readdir as readdir5, readFile as readFile27, rename as rename10, rm as rm9, writeFile as writeFile18 } from "fs/promises";
|
|
23714
|
+
import path40 from "path";
|
|
23040
23715
|
import { z as z10 } from "zod";
|
|
23041
23716
|
|
|
23042
23717
|
// src/jpeg.ts
|
|
@@ -23418,7 +24093,7 @@ var MAX_MODELS = 200;
|
|
|
23418
24093
|
var MAX_DEPTH = 8;
|
|
23419
24094
|
var SKIPPED_DIRS = /* @__PURE__ */ new Set([HAND_EDIT_DIR, "node_modules"]);
|
|
23420
24095
|
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:
|
|
24096
|
+
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
24097
|
const seen = /* @__PURE__ */ new Set();
|
|
23423
24098
|
const models = [];
|
|
23424
24099
|
const walk2 = async (styleId, outDir, dir, depth) => {
|
|
@@ -23432,13 +24107,13 @@ async function discoverModels(loaded, opts = {}) {
|
|
|
23432
24107
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
23433
24108
|
for (const entry of entries) {
|
|
23434
24109
|
if (models.length >= MAX_MODELS) return;
|
|
23435
|
-
const full =
|
|
24110
|
+
const full = path40.join(dir, entry.name);
|
|
23436
24111
|
if (entry.isDirectory()) {
|
|
23437
24112
|
if (entry.name.startsWith(".") || SKIPPED_DIRS.has(entry.name)) continue;
|
|
23438
24113
|
await walk2(styleId, outDir, full, depth + 1);
|
|
23439
24114
|
} else if (entry.isFile() && entry.name.toLowerCase().endsWith(MODEL_EXTENSION) && !seen.has(full)) {
|
|
23440
24115
|
seen.add(full);
|
|
23441
|
-
models.push({ styleId, file: full, editFile:
|
|
24116
|
+
models.push({ styleId, file: full, editFile: path40.join(outDir, HAND_EDIT_DIR, path40.relative(outDir, full)) });
|
|
23442
24117
|
}
|
|
23443
24118
|
}
|
|
23444
24119
|
};
|
|
@@ -23446,12 +24121,12 @@ async function discoverModels(loaded, opts = {}) {
|
|
|
23446
24121
|
return models.sort((a, b) => a.styleId.localeCompare(b.styleId) || a.file.localeCompare(b.file));
|
|
23447
24122
|
}
|
|
23448
24123
|
async function findModel(loaded, portablePath) {
|
|
23449
|
-
const wanted =
|
|
24124
|
+
const wanted = path40.resolve(loaded.root, portablePath);
|
|
23450
24125
|
const model = (await discoverModels(loaded)).find((candidate) => candidate.file === wanted);
|
|
23451
24126
|
if (!model) throw new ManifestEditError(`"${portablePath}" is not a model under one of this project's output folders`);
|
|
23452
24127
|
return model;
|
|
23453
24128
|
}
|
|
23454
|
-
var stem = (editFile) => editFile.slice(0, -
|
|
24129
|
+
var stem = (editFile) => editFile.slice(0, -path40.extname(editFile).length);
|
|
23455
24130
|
function modelCompanionPath(editFile) {
|
|
23456
24131
|
return stem(editFile) + ".edit.json";
|
|
23457
24132
|
}
|
|
@@ -23490,13 +24165,17 @@ var ModelEditCompanionSchema = z10.object({
|
|
|
23490
24165
|
}).strict();
|
|
23491
24166
|
async function readModelCompanion(editFile) {
|
|
23492
24167
|
try {
|
|
23493
|
-
return ModelEditCompanionSchema.parse(JSON.parse(await
|
|
24168
|
+
return ModelEditCompanionSchema.parse(JSON.parse(await readFile27(modelCompanionPath(editFile), "utf8")));
|
|
23494
24169
|
} catch {
|
|
23495
24170
|
return null;
|
|
23496
24171
|
}
|
|
23497
24172
|
}
|
|
24173
|
+
function modelEditStatus(companion, builtSha256) {
|
|
24174
|
+
if (!companion) return "unrecorded";
|
|
24175
|
+
return companion.outputs[0].basedOn === builtSha256 ? "edited" : "rebuilt-since";
|
|
24176
|
+
}
|
|
23498
24177
|
async function replaceFile2(file, bytes) {
|
|
23499
|
-
await mkdir15(
|
|
24178
|
+
await mkdir15(path40.dirname(file), { recursive: true });
|
|
23500
24179
|
const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
23501
24180
|
try {
|
|
23502
24181
|
await writeFile18(tmp, bytes);
|
|
@@ -23508,7 +24187,7 @@ async function replaceFile2(file, bytes) {
|
|
|
23508
24187
|
async function readModel(file, what) {
|
|
23509
24188
|
let bytes;
|
|
23510
24189
|
try {
|
|
23511
|
-
bytes = await
|
|
24190
|
+
bytes = await readFile27(file);
|
|
23512
24191
|
} catch {
|
|
23513
24192
|
throw new ManifestEditError(`${what} is not on disk at ${file}`);
|
|
23514
24193
|
}
|
|
@@ -23535,7 +24214,7 @@ async function saveModelTexture(model, input) {
|
|
|
23535
24214
|
throw new ManifestEditError(`the texture is not a valid PNG: ${error instanceof Error ? error.message : String(error)}`);
|
|
23536
24215
|
}
|
|
23537
24216
|
const original = await readModel(model.file, "the model");
|
|
23538
|
-
const created = !
|
|
24217
|
+
const created = !existsSync35(model.editFile);
|
|
23539
24218
|
const base = created ? original : await readModel(model.editFile, "the model's edit");
|
|
23540
24219
|
let current;
|
|
23541
24220
|
try {
|
|
@@ -23557,7 +24236,7 @@ async function saveModelTexture(model, input) {
|
|
|
23557
24236
|
sha256: sha256(input.png),
|
|
23558
24237
|
editor: input.editor,
|
|
23559
24238
|
savedAt,
|
|
23560
|
-
project: projectPath ?
|
|
24239
|
+
project: projectPath ? path40.basename(projectPath) : null
|
|
23561
24240
|
};
|
|
23562
24241
|
const companion = {
|
|
23563
24242
|
version: 2,
|
|
@@ -23580,7 +24259,7 @@ async function adoptModelExport(model, opts = {}) {
|
|
|
23580
24259
|
const mode2 = opts.mode ?? "textures";
|
|
23581
24260
|
const exported = await readModel(from, "the exported model");
|
|
23582
24261
|
const original = await readModel(model.file, "the model");
|
|
23583
|
-
const created = !
|
|
24262
|
+
const created = !existsSync35(model.editFile);
|
|
23584
24263
|
const savedAt = (opts.now ?? /* @__PURE__ */ new Date()).toISOString();
|
|
23585
24264
|
const editor = opts.editor ?? "blender";
|
|
23586
24265
|
const taken = [];
|
|
@@ -23649,9 +24328,9 @@ async function adoptModelExport(model, opts = {}) {
|
|
|
23649
24328
|
await replaceFile2(companionPath, JSON.stringify(companion, null, 2) + "\n");
|
|
23650
24329
|
return { editFile: model.editFile, companionPath, companion, created, mode: mode2, taken };
|
|
23651
24330
|
}
|
|
23652
|
-
function blenderCommand(env = process.env, platform = process.platform, exists =
|
|
24331
|
+
function blenderCommand(env = process.env, platform = process.platform, exists = existsSync35, list = (dir) => {
|
|
23653
24332
|
try {
|
|
23654
|
-
return
|
|
24333
|
+
return readdirSync2(dir);
|
|
23655
24334
|
} catch {
|
|
23656
24335
|
return [];
|
|
23657
24336
|
}
|
|
@@ -23661,16 +24340,16 @@ function blenderCommand(env = process.env, platform = process.platform, exists =
|
|
|
23661
24340
|
const candidates = [];
|
|
23662
24341
|
if (platform === "darwin") {
|
|
23663
24342
|
candidates.push("/Applications/Blender.app/Contents/MacOS/Blender");
|
|
23664
|
-
if (env.HOME) candidates.push(
|
|
24343
|
+
if (env.HOME) candidates.push(path40.join(env.HOME, "Applications/Blender.app/Contents/MacOS/Blender"));
|
|
23665
24344
|
} else if (platform === "win32") {
|
|
23666
24345
|
for (const root of [env.ProgramFiles, env["ProgramFiles(x86)"]].filter((value) => Boolean(value))) {
|
|
23667
|
-
const foundation =
|
|
24346
|
+
const foundation = path40.win32.join(root, "Blender Foundation");
|
|
23668
24347
|
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(
|
|
24348
|
+
for (const version of versions) candidates.push(path40.win32.join(foundation, version, "blender.exe"));
|
|
23670
24349
|
}
|
|
23671
24350
|
} else {
|
|
23672
24351
|
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(
|
|
24352
|
+
for (const dir of (env.PATH ?? "").split(":").filter(Boolean)) candidates.push(path40.join(dir, "blender"));
|
|
23674
24353
|
}
|
|
23675
24354
|
const found = candidates.find((candidate) => exists(candidate));
|
|
23676
24355
|
return found ? [found] : null;
|
|
@@ -23703,7 +24382,7 @@ function openInBlender(model, opts = {}) {
|
|
|
23703
24382
|
"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
24383
|
);
|
|
23705
24384
|
}
|
|
23706
|
-
const file =
|
|
24385
|
+
const file = existsSync35(model.editFile) ? model.editFile : model.file;
|
|
23707
24386
|
const [program, ...rest] = command;
|
|
23708
24387
|
const args = [...rest, ...blenderArguments(file, modelExportPath(model.editFile))];
|
|
23709
24388
|
const launch = opts.launch ?? ((bin, argv) => {
|
|
@@ -23713,14 +24392,14 @@ function openInBlender(model, opts = {}) {
|
|
|
23713
24392
|
child.unref();
|
|
23714
24393
|
});
|
|
23715
24394
|
launch(program, args);
|
|
23716
|
-
return `${command.join(" ")} (${
|
|
24395
|
+
return `${command.join(" ")} (${path40.basename(file)})`;
|
|
23717
24396
|
}
|
|
23718
24397
|
|
|
23719
24398
|
// 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
|
|
24399
|
+
import { createHash as createHash7 } from "crypto";
|
|
24400
|
+
import { existsSync as existsSync36 } from "fs";
|
|
24401
|
+
import { mkdir as mkdir16, readdir as readdir6, readFile as readFile28, writeFile as writeFile19 } from "fs/promises";
|
|
24402
|
+
import path41 from "path";
|
|
23724
24403
|
var MODEL_NORMAL_SOURCES = ["texture", "views", "sprites"];
|
|
23725
24404
|
var TILE_MAX = 512;
|
|
23726
24405
|
function decodeImage(bytes) {
|
|
@@ -23812,13 +24491,13 @@ function poseNodes(document, pose) {
|
|
|
23812
24491
|
const posed = /* @__PURE__ */ new Map();
|
|
23813
24492
|
for (const channel of animation.channels) {
|
|
23814
24493
|
const node = channel.target.node;
|
|
23815
|
-
const
|
|
23816
|
-
if (node === void 0 || !["translation", "rotation", "scale"].includes(
|
|
24494
|
+
const path53 = channel.target.path;
|
|
24495
|
+
if (node === void 0 || !["translation", "rotation", "scale"].includes(path53)) continue;
|
|
23817
24496
|
const sampler = animation.samplers[channel.sampler];
|
|
23818
24497
|
if (!sampler) continue;
|
|
23819
24498
|
const times = readAccessor(document, sampler.input).data;
|
|
23820
24499
|
const values = readAccessor(document, sampler.output);
|
|
23821
|
-
const width =
|
|
24500
|
+
const width = path53 === "rotation" ? 4 : 3;
|
|
23822
24501
|
const cubic = sampler.interpolation === "CUBICSPLINE";
|
|
23823
24502
|
const valueAt = (key3) => Array.from(values.data.subarray((cubic ? key3 * 3 + 1 : key3) * width, (cubic ? key3 * 3 + 1 : key3) * width + width));
|
|
23824
24503
|
const last = times.length - 1;
|
|
@@ -23830,16 +24509,16 @@ function poseNodes(document, pose) {
|
|
|
23830
24509
|
const span = times[key2 + 1] - times[key2];
|
|
23831
24510
|
const f = span > 0 ? (time - times[key2]) / span : 0;
|
|
23832
24511
|
const next = valueAt(key2 + 1);
|
|
23833
|
-
const sign =
|
|
24512
|
+
const sign = path53 === "rotation" && value.reduce((sum, v, k) => sum + v * next[k], 0) < 0 ? -1 : 1;
|
|
23834
24513
|
value = value.map((v, k) => v * (1 - f) + next[k] * sign * f);
|
|
23835
24514
|
}
|
|
23836
|
-
if (
|
|
24515
|
+
if (path53 === "rotation") {
|
|
23837
24516
|
const length = Math.hypot(...value) || 1;
|
|
23838
24517
|
value = value.map((v) => v / length);
|
|
23839
24518
|
}
|
|
23840
24519
|
const base = posed.get(node) ?? { ...document.json.nodes?.[node] ?? {} };
|
|
23841
24520
|
if (base.matrix) delete base.matrix;
|
|
23842
|
-
base[
|
|
24521
|
+
base[path53] = value;
|
|
23843
24522
|
posed.set(node, base);
|
|
23844
24523
|
}
|
|
23845
24524
|
return posed;
|
|
@@ -24449,20 +25128,20 @@ function modelSpritesDir(modelFile) {
|
|
|
24449
25128
|
return modelFile.replace(/\.glb$/i, "") + ".sprites";
|
|
24450
25129
|
}
|
|
24451
25130
|
async function readSpriteFolder(dir) {
|
|
24452
|
-
const folder =
|
|
25131
|
+
const folder = existsSync36(path41.join(dir, "rotations")) ? path41.join(dir, "rotations") : dir;
|
|
24453
25132
|
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
|
|
25133
|
+
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
25134
|
}
|
|
24456
25135
|
function modelNormalDir(editFile) {
|
|
24457
25136
|
return editFile.replace(/\.glb$/i, "") + ".normal-map";
|
|
24458
25137
|
}
|
|
24459
25138
|
function requestKey(png, options) {
|
|
24460
25139
|
const asked = JSON.stringify([options.mode ?? "lite", options.kind ?? null, options.surfaceDetail ?? null, options.detailSoftness ?? null, options.strength ?? null]);
|
|
24461
|
-
return
|
|
25140
|
+
return createHash7("sha256").update(png).update(asked).digest("hex").slice(0, 16);
|
|
24462
25141
|
}
|
|
24463
25142
|
async function prepare(model, opts) {
|
|
24464
|
-
const fromEdit =
|
|
24465
|
-
const document = parseGlb(await
|
|
25143
|
+
const fromEdit = existsSync36(model.editFile);
|
|
25144
|
+
const document = parseGlb(await readFile28(fromEdit ? model.editFile : model.file));
|
|
24466
25145
|
const summary = describeGlb(document);
|
|
24467
25146
|
const normalImages = summary.images.filter((image) => image.roles.includes("normal"));
|
|
24468
25147
|
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 +25150,14 @@ async function prepare(model, opts) {
|
|
|
24471
25150
|
if (!normalImages.some((image) => image.index === index)) throw new Error(`image ${index} is not one of the model's normal maps`);
|
|
24472
25151
|
}
|
|
24473
25152
|
const primitives = restPrimitives(document, opts.pose);
|
|
24474
|
-
const dir =
|
|
25153
|
+
const dir = path41.join(modelNormalDir(model.editFile), opts.source);
|
|
24475
25154
|
const surfaces = /* @__PURE__ */ new Map();
|
|
24476
25155
|
const tiles = /* @__PURE__ */ new Map();
|
|
24477
25156
|
const calls = [];
|
|
24478
25157
|
const images = [];
|
|
24479
25158
|
const call = (label, png) => {
|
|
24480
|
-
const cache =
|
|
24481
|
-
calls.push({ label, png, cache, cached:
|
|
25159
|
+
const cache = path41.join(dir, `${label.replace(/[^a-z0-9]+/gi, "-")}.${requestKey(png, opts)}.normal.png`);
|
|
25160
|
+
calls.push({ label, png, cache, cached: existsSync36(cache) });
|
|
24482
25161
|
};
|
|
24483
25162
|
for (const index of wanted) {
|
|
24484
25163
|
const summaryImage = summary.images[index];
|
|
@@ -24548,7 +25227,7 @@ async function planModelNormals(model, opts) {
|
|
|
24548
25227
|
const { plan } = await prepare(model, opts);
|
|
24549
25228
|
await mkdir16(plan.dir, { recursive: true });
|
|
24550
25229
|
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(
|
|
25230
|
+
for (const fit of plan.fits ?? []) await writeFile19(path41.join(plan.dir, `${fit.label.replace(/[^a-z0-9]+/gi, "-")}.fit.png`), fit.png);
|
|
24552
25231
|
return plan;
|
|
24553
25232
|
}
|
|
24554
25233
|
async function generateModelNormals(model, opts, mapper, hooks = {}) {
|
|
@@ -24568,7 +25247,7 @@ async function generateModelNormals(model, opts, mapper, hooks = {}) {
|
|
|
24568
25247
|
hooks.onCall?.(entry.label, entry.cached);
|
|
24569
25248
|
await writeFile19(entry.cache.replace(/\.[0-9a-f]{16}\.normal\.png$/, ".png"), entry.png);
|
|
24570
25249
|
if (entry.cached) {
|
|
24571
|
-
answers.push(await
|
|
25250
|
+
answers.push(await readFile28(entry.cache));
|
|
24572
25251
|
continue;
|
|
24573
25252
|
}
|
|
24574
25253
|
const answer = await mapper(entry.png, request);
|
|
@@ -24591,13 +25270,13 @@ async function generateModelNormals(model, opts, mapper, hooks = {}) {
|
|
|
24591
25270
|
field = detailFromViews(surface, prepared.views, answers);
|
|
24592
25271
|
}
|
|
24593
25272
|
bleed(field);
|
|
24594
|
-
const detail =
|
|
25273
|
+
const detail = path41.join(plan.dir, `image-${image}.detail.png`);
|
|
24595
25274
|
await writeFile19(detail, encodeImage(fieldImage(field)));
|
|
24596
25275
|
details.push(detail);
|
|
24597
|
-
const basePath =
|
|
25276
|
+
const basePath = path41.join(modelNormalDir(model.editFile), `image-${image}.base.png`);
|
|
24598
25277
|
const record = companion?.textures.find((entry) => entry.image === image);
|
|
24599
|
-
const ours = record?.editor.startsWith(PIXELLAB_EDITOR) === true &&
|
|
24600
|
-
const existing = ours ? decodeImage(await
|
|
25278
|
+
const ours = record?.editor.startsWith(PIXELLAB_EDITOR) === true && existsSync36(basePath);
|
|
25279
|
+
const existing = ours ? decodeImage(await readFile28(basePath)) : decodeImage(glbImageBytes(document, image).bytes);
|
|
24601
25280
|
if (!ours) await writeFile19(basePath, encodeImage(existing));
|
|
24602
25281
|
const png = encodeImage(applyDetail(existing, field, opts));
|
|
24603
25282
|
result = await saveModelTexture(model, {
|
|
@@ -24646,11 +25325,11 @@ async function describeModels(loaded, media, mediaId, opts = {}) {
|
|
|
24646
25325
|
for (const model of await discoverModels(loaded, opts)) {
|
|
24647
25326
|
let bytes;
|
|
24648
25327
|
try {
|
|
24649
|
-
bytes = await
|
|
25328
|
+
bytes = await readFile29(model.file);
|
|
24650
25329
|
} catch {
|
|
24651
25330
|
continue;
|
|
24652
25331
|
}
|
|
24653
|
-
const outDir =
|
|
25332
|
+
const outDir = path42.resolve(root, loaded.manifest.styles[model.styleId]?.outDir ?? ".");
|
|
24654
25333
|
let summary = null;
|
|
24655
25334
|
let error = null;
|
|
24656
25335
|
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 +25343,16 @@ async function describeModels(loaded, media, mediaId, opts = {}) {
|
|
|
24664
25343
|
const file = await describeFile(media, mediaId, root, model.file, bytes);
|
|
24665
25344
|
let edit = null;
|
|
24666
25345
|
let adoptedExport = null;
|
|
24667
|
-
if (
|
|
25346
|
+
if (existsSync37(model.editFile)) {
|
|
24668
25347
|
try {
|
|
24669
|
-
const editBytes = await
|
|
25348
|
+
const editBytes = await readFile29(model.editFile);
|
|
24670
25349
|
const described = await describeFile(media, mediaId, root, model.editFile, editBytes);
|
|
24671
25350
|
const companion = await readModelCompanion(model.editFile);
|
|
24672
25351
|
adoptedExport = companion?.adoptedExport ?? null;
|
|
24673
25352
|
const textures = (companion?.textures ?? []).map((texture) => {
|
|
24674
25353
|
const projectPath = texture.project ? modelTextureProjectPath(model.editFile, texture.image) : null;
|
|
24675
25354
|
let projectUrl = null;
|
|
24676
|
-
if (projectPath &&
|
|
25355
|
+
if (projectPath && existsSync37(projectPath)) {
|
|
24677
25356
|
const id = mediaId(projectPath);
|
|
24678
25357
|
media.set(id, { path: projectPath, contentType: "application/octet-stream" });
|
|
24679
25358
|
projectUrl = `/media/${id}?v=${texture.sha256.slice(0, 24)}`;
|
|
@@ -24689,7 +25368,7 @@ async function describeModels(loaded, media, mediaId, opts = {}) {
|
|
|
24689
25368
|
});
|
|
24690
25369
|
edit = {
|
|
24691
25370
|
...described,
|
|
24692
|
-
status:
|
|
25371
|
+
status: modelEditStatus(companion, file.sha256),
|
|
24693
25372
|
editor: companion?.editor ?? null,
|
|
24694
25373
|
savedAt: companion?.savedAt ?? null,
|
|
24695
25374
|
changedSince: companion ? companion.outputs[0].sha256 !== described.sha256 : false,
|
|
@@ -24703,25 +25382,25 @@ async function describeModels(loaded, media, mediaId, opts = {}) {
|
|
|
24703
25382
|
let exportWaiting = null;
|
|
24704
25383
|
try {
|
|
24705
25384
|
const info = await stat4(exportFile);
|
|
24706
|
-
if (info.isFile() && info.size <= MAX_MODEL_BYTES && sha256(await
|
|
25385
|
+
if (info.isFile() && info.size <= MAX_MODEL_BYTES && sha256(await readFile29(exportFile)) !== adoptedExport) {
|
|
24707
25386
|
exportWaiting = { bytes: info.size, modifiedAt: info.mtime.toISOString() };
|
|
24708
25387
|
}
|
|
24709
25388
|
} catch {
|
|
24710
25389
|
}
|
|
24711
25390
|
const spritesDir = modelSpritesDir(model.file);
|
|
24712
25391
|
let sprites = null;
|
|
24713
|
-
if (
|
|
25392
|
+
if (existsSync37(spritesDir)) {
|
|
24714
25393
|
try {
|
|
24715
25394
|
sprites = { path: portableOutputPath(spritesDir, root), directions: (await readSpriteFolder(spritesDir)).map((sprite) => sprite.direction) };
|
|
24716
25395
|
} catch {
|
|
24717
25396
|
}
|
|
24718
25397
|
}
|
|
24719
|
-
const relative =
|
|
25398
|
+
const relative = path42.relative(outDir, model.file).split(path42.sep).join("/");
|
|
24720
25399
|
models.push({
|
|
24721
25400
|
id: `model:${model.styleId}/${relative}`,
|
|
24722
25401
|
project: null,
|
|
24723
25402
|
styleId: model.styleId,
|
|
24724
|
-
name:
|
|
25403
|
+
name: path42.basename(model.file, path42.extname(model.file)),
|
|
24725
25404
|
file,
|
|
24726
25405
|
summary,
|
|
24727
25406
|
error,
|
|
@@ -24816,9 +25495,9 @@ function blenderAvailable() {
|
|
|
24816
25495
|
}
|
|
24817
25496
|
|
|
24818
25497
|
// src/workspace.ts
|
|
24819
|
-
import { mkdir as mkdir17, readFile as
|
|
24820
|
-
import { existsSync as
|
|
24821
|
-
import
|
|
25498
|
+
import { mkdir as mkdir17, readFile as readFile30, rename as rename11, rm as rm10, writeFile as writeFile20 } from "fs/promises";
|
|
25499
|
+
import { existsSync as existsSync38 } from "fs";
|
|
25500
|
+
import path43 from "path";
|
|
24822
25501
|
import { z as z12 } from "zod";
|
|
24823
25502
|
var WorkspaceProjectSchema = z12.object({
|
|
24824
25503
|
id: z12.string().min(1),
|
|
@@ -24843,10 +25522,10 @@ ${parsed.error.issues.slice(0, 5).map((i) => ` ${i.path.join(".")}: ${i.message
|
|
|
24843
25522
|
);
|
|
24844
25523
|
}
|
|
24845
25524
|
async function loadWorkspace(workspacePath) {
|
|
24846
|
-
if (!
|
|
25525
|
+
if (!existsSync38(workspacePath)) return { version: 1, projects: [] };
|
|
24847
25526
|
let raw;
|
|
24848
25527
|
try {
|
|
24849
|
-
raw = JSON.parse(await
|
|
25528
|
+
raw = JSON.parse(await readFile30(workspacePath, "utf8"));
|
|
24850
25529
|
} catch (err) {
|
|
24851
25530
|
throw new ProjectError(
|
|
24852
25531
|
`Workspace catalog at ${workspacePath} is malformed:
|
|
@@ -24860,7 +25539,7 @@ async function saveWorkspace(workspacePath, ws) {
|
|
|
24860
25539
|
version: 1,
|
|
24861
25540
|
projects: [...ws.projects].sort((a, b) => a.id.localeCompare(b.id))
|
|
24862
25541
|
};
|
|
24863
|
-
await mkdir17(
|
|
25542
|
+
await mkdir17(path43.dirname(path43.resolve(workspacePath)), { recursive: true });
|
|
24864
25543
|
const tmp = `${workspacePath}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
24865
25544
|
try {
|
|
24866
25545
|
await writeFile20(tmp, JSON.stringify(sorted, null, 2) + "\n");
|
|
@@ -24870,12 +25549,12 @@ async function saveWorkspace(workspacePath, ws) {
|
|
|
24870
25549
|
}
|
|
24871
25550
|
}
|
|
24872
25551
|
function toPortablePath(dir, absolute) {
|
|
24873
|
-
return
|
|
25552
|
+
return path43.relative(dir, absolute).split(path43.sep).join("/");
|
|
24874
25553
|
}
|
|
24875
25554
|
function resolveProject(dir, project2) {
|
|
24876
25555
|
return {
|
|
24877
|
-
manifestPath:
|
|
24878
|
-
lockPath:
|
|
25556
|
+
manifestPath: path43.resolve(dir, project2.manifest.split("/").join(path43.sep)),
|
|
25557
|
+
lockPath: path43.resolve(dir, project2.lock.split("/").join(path43.sep))
|
|
24879
25558
|
};
|
|
24880
25559
|
}
|
|
24881
25560
|
function validateWorkspace(ws, dir) {
|
|
@@ -24888,21 +25567,21 @@ function validateWorkspace(ws, dir) {
|
|
|
24888
25567
|
const { manifestPath, lockPath } = resolveProject(dir, project2);
|
|
24889
25568
|
lockOwners.set(lockPath, [...lockOwners.get(lockPath) ?? [], project2.id]);
|
|
24890
25569
|
manifestOwners.set(manifestPath, [...manifestOwners.get(manifestPath) ?? [], project2.id]);
|
|
24891
|
-
if (
|
|
25570
|
+
if (path43.isAbsolute(project2.manifest) || path43.isAbsolute(project2.lock)) {
|
|
24892
25571
|
diagnostics.push({
|
|
24893
25572
|
id: "absolute-path",
|
|
24894
25573
|
level: "warning",
|
|
24895
25574
|
message: `project "${project2.id}" stores an absolute path; the catalog will not resolve correctly if this tree is cloned or moved elsewhere`
|
|
24896
25575
|
});
|
|
24897
25576
|
}
|
|
24898
|
-
if (!
|
|
25577
|
+
if (!existsSync38(manifestPath)) {
|
|
24899
25578
|
diagnostics.push({
|
|
24900
25579
|
id: "missing-manifest",
|
|
24901
25580
|
level: "error",
|
|
24902
25581
|
message: `project "${project2.id}" manifest not found: ${manifestPath}`
|
|
24903
25582
|
});
|
|
24904
25583
|
}
|
|
24905
|
-
if (!
|
|
25584
|
+
if (!existsSync38(lockPath)) {
|
|
24906
25585
|
diagnostics.push({
|
|
24907
25586
|
id: "missing-lock",
|
|
24908
25587
|
level: "error",
|
|
@@ -24949,14 +25628,14 @@ function validateWorkspace(ws, dir) {
|
|
|
24949
25628
|
}
|
|
24950
25629
|
|
|
24951
25630
|
// src/gallery/edit.ts
|
|
24952
|
-
import { readFile as
|
|
24953
|
-
import
|
|
25631
|
+
import { readFile as readFile33, rename as rename12, writeFile as writeFile24 } from "fs/promises";
|
|
25632
|
+
import path47 from "path";
|
|
24954
25633
|
import { z as z16 } from "zod";
|
|
24955
25634
|
|
|
24956
25635
|
// src/gallery/upload.ts
|
|
24957
|
-
import { existsSync as
|
|
25636
|
+
import { existsSync as existsSync39 } from "fs";
|
|
24958
25637
|
import { mkdir as mkdir18, writeFile as writeFile21 } from "fs/promises";
|
|
24959
|
-
import
|
|
25638
|
+
import path44 from "path";
|
|
24960
25639
|
import { z as z13 } from "zod";
|
|
24961
25640
|
var MAX_UPLOAD_BYTES = 8 * 1024 * 1024;
|
|
24962
25641
|
var UploadImageSchema = z13.object({
|
|
@@ -24969,12 +25648,12 @@ var UploadImageSchema = z13.object({
|
|
|
24969
25648
|
overwrite: z13.boolean().optional()
|
|
24970
25649
|
}).strict();
|
|
24971
25650
|
async function saveProjectImage(root, request) {
|
|
24972
|
-
const file =
|
|
24973
|
-
const relative =
|
|
24974
|
-
if (relative.startsWith("..") ||
|
|
25651
|
+
const file = path44.resolve(root, request.path);
|
|
25652
|
+
const relative = path44.relative(root, file);
|
|
25653
|
+
if (relative.startsWith("..") || path44.isAbsolute(relative)) {
|
|
24975
25654
|
throw new ManifestEditError("an upload must stay inside the project");
|
|
24976
25655
|
}
|
|
24977
|
-
const extension =
|
|
25656
|
+
const extension = path44.extname(file).toLowerCase();
|
|
24978
25657
|
const expected = extension === ".png" ? "png" : extension === ".jpg" || extension === ".jpeg" ? "jpeg" : null;
|
|
24979
25658
|
if (!expected) throw new ManifestEditError("an upload must be a .png, .jpg, or .jpeg path");
|
|
24980
25659
|
const bytes = Buffer.from(request.base64, "base64");
|
|
@@ -24986,18 +25665,18 @@ async function saveProjectImage(root, request) {
|
|
|
24986
25665
|
if (metadata.format !== expected) {
|
|
24987
25666
|
throw new ManifestEditError(`the upload is a ${metadata.format.toUpperCase()}; name it ${metadata.format === "png" ? ".png" : ".jpg"}`);
|
|
24988
25667
|
}
|
|
24989
|
-
if (
|
|
24990
|
-
throw new ManifestEditError(`${relative.split(
|
|
25668
|
+
if (existsSync39(file) && !request.overwrite) {
|
|
25669
|
+
throw new ManifestEditError(`${relative.split(path44.sep).join("/")} already exists; choose another name, or replace it`);
|
|
24991
25670
|
}
|
|
24992
|
-
await mkdir18(
|
|
25671
|
+
await mkdir18(path44.dirname(file), { recursive: true });
|
|
24993
25672
|
await writeFile21(file, bytes);
|
|
24994
|
-
return relative.split(
|
|
25673
|
+
return relative.split(path44.sep).join("/");
|
|
24995
25674
|
}
|
|
24996
25675
|
|
|
24997
25676
|
// src/gallery/image-revision.ts
|
|
24998
|
-
import { existsSync as
|
|
24999
|
-
import { readFile as
|
|
25000
|
-
import
|
|
25677
|
+
import { existsSync as existsSync40 } from "fs";
|
|
25678
|
+
import { readFile as readFile31, rm as rm11, writeFile as writeFile22 } from "fs/promises";
|
|
25679
|
+
import path45 from "path";
|
|
25001
25680
|
import { z as z14 } from "zod";
|
|
25002
25681
|
var InpaintRevisionRequestSchema = z14.object({
|
|
25003
25682
|
action: z14.literal("create-inpaint-revision"),
|
|
@@ -25016,15 +25695,15 @@ var InpaintRevisionRequestSchema = z14.object({
|
|
|
25016
25695
|
overwrite: z14.boolean().optional()
|
|
25017
25696
|
}).strict();
|
|
25018
25697
|
async function createInpaintRevision(manifestPath, request) {
|
|
25019
|
-
const root =
|
|
25020
|
-
if (
|
|
25698
|
+
const root = path45.dirname(path45.resolve(manifestPath));
|
|
25699
|
+
if (path45.extname(request.maskPath).toLowerCase() !== ".png") {
|
|
25021
25700
|
throw new ManifestEditError("the mask must be a .png path inside the project");
|
|
25022
25701
|
}
|
|
25023
25702
|
const bytes = Buffer.from(request.maskBase64, "base64");
|
|
25024
25703
|
const metadata = imageMetadata(bytes);
|
|
25025
25704
|
if (!metadata || metadata.format !== "png") throw new ManifestEditError("the mask is not a readable PNG");
|
|
25026
|
-
const file =
|
|
25027
|
-
const previous =
|
|
25705
|
+
const file = path45.resolve(root, request.maskPath);
|
|
25706
|
+
const previous = existsSync40(file) ? await readFile31(file) : null;
|
|
25028
25707
|
const mask = await saveProjectImage(root, {
|
|
25029
25708
|
action: "upload-image",
|
|
25030
25709
|
path: request.maskPath,
|
|
@@ -25051,9 +25730,9 @@ async function createInpaintRevision(manifestPath, request) {
|
|
|
25051
25730
|
}
|
|
25052
25731
|
|
|
25053
25732
|
// src/gallery/skeleton.ts
|
|
25054
|
-
import { existsSync as
|
|
25055
|
-
import { mkdir as mkdir19, readFile as
|
|
25056
|
-
import
|
|
25733
|
+
import { existsSync as existsSync41 } from "fs";
|
|
25734
|
+
import { mkdir as mkdir19, readFile as readFile32, rm as rm12, writeFile as writeFile23 } from "fs/promises";
|
|
25735
|
+
import path46 from "path";
|
|
25057
25736
|
import { z as z15 } from "zod";
|
|
25058
25737
|
var SkeletonEstimateRequestSchema = z15.object({
|
|
25059
25738
|
project: z15.string().min(1).optional(),
|
|
@@ -25092,20 +25771,20 @@ var SkeletonKeypointsUpdateSchema = z15.object({
|
|
|
25092
25771
|
set: SkeletonSetSchema
|
|
25093
25772
|
}).strict();
|
|
25094
25773
|
async function createSkeletonAnimation(manifestPath, request) {
|
|
25095
|
-
const root =
|
|
25096
|
-
const file =
|
|
25097
|
-
const relative =
|
|
25098
|
-
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") ||
|
|
25774
|
+
const root = path46.dirname(path46.resolve(manifestPath));
|
|
25775
|
+
const file = path46.resolve(root, request.keypointsFile);
|
|
25776
|
+
const relative = path46.relative(root, file);
|
|
25777
|
+
if (!request.keypointsFile.endsWith(".json") || relative.startsWith("..") || path46.isAbsolute(relative)) {
|
|
25099
25778
|
throw new ManifestEditError("the keypoints file must be a .json path inside the project");
|
|
25100
25779
|
}
|
|
25101
|
-
const existed =
|
|
25780
|
+
const existed = existsSync41(file);
|
|
25102
25781
|
let previous = null;
|
|
25103
25782
|
if (request.set) {
|
|
25104
25783
|
if (existed && !request.overwrite) {
|
|
25105
25784
|
throw new ManifestEditError(`${request.keypointsFile} already exists; choose another path, or replace it`);
|
|
25106
25785
|
}
|
|
25107
|
-
if (existed) previous = await
|
|
25108
|
-
await mkdir19(
|
|
25786
|
+
if (existed) previous = await readFile32(file);
|
|
25787
|
+
await mkdir19(path46.dirname(file), { recursive: true });
|
|
25109
25788
|
await writeFile23(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
25110
25789
|
} else if (!existed) {
|
|
25111
25790
|
throw new ManifestEditError(`${request.keypointsFile} does not exist; paste poses or estimate them from the sprite`);
|
|
@@ -25121,7 +25800,7 @@ async function createSkeletonAnimation(manifestPath, request) {
|
|
|
25121
25800
|
revision: {
|
|
25122
25801
|
mode: "animate-skeleton",
|
|
25123
25802
|
from: request.from,
|
|
25124
|
-
keypointsFile: relative.split(
|
|
25803
|
+
keypointsFile: relative.split(path46.sep).join("/"),
|
|
25125
25804
|
direction: request.direction,
|
|
25126
25805
|
description: request.description,
|
|
25127
25806
|
...request.skeletonTemplate ? { skeletonTemplate: request.skeletonTemplate } : {}
|
|
@@ -25142,19 +25821,19 @@ async function updateSkeletonKeypoints(ctx, request) {
|
|
|
25142
25821
|
if (!spec) throw new ManifestEditError(`"${key2}" is not declared by the manifest`);
|
|
25143
25822
|
const file = spec.revision?.mode === "animate-skeleton" ? spec.revision.keypointsFile : void 0;
|
|
25144
25823
|
if (!file) throw new ManifestEditError(`${key2} is not an animate-skeleton revision`);
|
|
25145
|
-
const relative =
|
|
25146
|
-
if (relative.startsWith("..") ||
|
|
25824
|
+
const relative = path46.relative(ctx.loaded.root, file);
|
|
25825
|
+
if (relative.startsWith("..") || path46.isAbsolute(relative)) {
|
|
25147
25826
|
throw new ManifestEditError(`${key2}'s keypoints file is outside the project; edit it by hand`);
|
|
25148
25827
|
}
|
|
25149
|
-
const current =
|
|
25828
|
+
const current = existsSync41(file) ? sha256(await readFile32(file)) : null;
|
|
25150
25829
|
if (current !== request.expectedSha256) {
|
|
25151
25830
|
throw Object.assign(
|
|
25152
|
-
new Error(`${relative.split(
|
|
25831
|
+
new Error(`${relative.split(path46.sep).join("/")} changed on disk since this page loaded it; press Refresh and edit again`),
|
|
25153
25832
|
{ status: 409 }
|
|
25154
25833
|
);
|
|
25155
25834
|
}
|
|
25156
25835
|
await writeFile23(file, JSON.stringify(request.set, null, 2) + "\n");
|
|
25157
|
-
return relative.split(
|
|
25836
|
+
return relative.split(path46.sep).join("/");
|
|
25158
25837
|
}
|
|
25159
25838
|
|
|
25160
25839
|
// src/gallery/edit.ts
|
|
@@ -25208,7 +25887,7 @@ function createGalleryEditHandler(opts) {
|
|
|
25208
25887
|
const history = /* @__PURE__ */ new Map();
|
|
25209
25888
|
const manifestOf = async (project2) => {
|
|
25210
25889
|
try {
|
|
25211
|
-
return
|
|
25890
|
+
return path47.resolve(await opts.manifestFor(typeof project2 === "string" ? project2 : void 0));
|
|
25212
25891
|
} catch {
|
|
25213
25892
|
return null;
|
|
25214
25893
|
}
|
|
@@ -25218,7 +25897,7 @@ function createGalleryEditHandler(opts) {
|
|
|
25218
25897
|
if (undo.success) {
|
|
25219
25898
|
const manifestPath2 = await manifestOf(undo.data.project);
|
|
25220
25899
|
if (!manifestPath2) throw new ManifestEditError("no manifest to undo an edit in");
|
|
25221
|
-
const current = await
|
|
25900
|
+
const current = await readFile33(manifestPath2, "utf8");
|
|
25222
25901
|
if (sha256(current) !== undo.data.expectedSha256) throw new ManifestDriftError(manifestPath2);
|
|
25223
25902
|
const stack = history.get(manifestPath2) ?? [];
|
|
25224
25903
|
const last = stack[stack.length - 1];
|
|
@@ -25231,14 +25910,14 @@ function createGalleryEditHandler(opts) {
|
|
|
25231
25910
|
await writeFile24(tmp, last.before);
|
|
25232
25911
|
await rename12(tmp, manifestPath2);
|
|
25233
25912
|
stack.pop();
|
|
25234
|
-
log(` manifest edit undone in ${
|
|
25913
|
+
log(` manifest edit undone in ${path47.relative(process.cwd(), manifestPath2) || manifestPath2}`);
|
|
25235
25914
|
return opts.reload();
|
|
25236
25915
|
}
|
|
25237
25916
|
const manifestPath = await manifestOf(body?.project);
|
|
25238
|
-
const before = manifestPath ? await
|
|
25917
|
+
const before = manifestPath ? await readFile33(manifestPath, "utf8").catch(() => null) : null;
|
|
25239
25918
|
const build = await apply(body);
|
|
25240
25919
|
if (manifestPath && before !== null) {
|
|
25241
|
-
const after = await
|
|
25920
|
+
const after = await readFile33(manifestPath, "utf8").catch(() => null);
|
|
25242
25921
|
if (after !== null && after !== before) {
|
|
25243
25922
|
const stack = history.get(manifestPath) ?? [];
|
|
25244
25923
|
stack.push({ before, afterSha: sha256(after) });
|
|
@@ -25317,7 +25996,7 @@ function createEditApplier(opts, log) {
|
|
|
25317
25996
|
} catch (error) {
|
|
25318
25997
|
throw new ManifestEditError(error instanceof Error ? error.message : String(error));
|
|
25319
25998
|
}
|
|
25320
|
-
const written = await saveProjectImage(
|
|
25999
|
+
const written = await saveProjectImage(path47.dirname(path47.resolve(manifestPath2)), upload.data);
|
|
25321
26000
|
log(` image added: ${written}`);
|
|
25322
26001
|
return opts.reload();
|
|
25323
26002
|
}
|
|
@@ -25384,7 +26063,7 @@ function createEditApplier(opts, log) {
|
|
|
25384
26063
|
}
|
|
25385
26064
|
const result = await applyManifestEdit(manifestPath, parsed.data);
|
|
25386
26065
|
if (result.changed) {
|
|
25387
|
-
const relative =
|
|
26066
|
+
const relative = path47.relative(process.cwd(), result.manifestPath);
|
|
25388
26067
|
const shown = !relative || relative.startsWith("..") ? result.manifestPath : relative;
|
|
25389
26068
|
log(` manifest edited: ${describeEdit(parsed.data)} in ${shown}`);
|
|
25390
26069
|
}
|
|
@@ -25412,7 +26091,7 @@ function describeEdit(edit) {
|
|
|
25412
26091
|
// src/gallery/snapshot.ts
|
|
25413
26092
|
var PROJECT_FILE_TYPE = "application/octet-stream";
|
|
25414
26093
|
function galleryMediaId(absolutePath) {
|
|
25415
|
-
return
|
|
26094
|
+
return createHash8("sha256").update(path48.resolve(absolutePath)).digest("hex").slice(0, 24);
|
|
25416
26095
|
}
|
|
25417
26096
|
function galleryMediaRoute(id) {
|
|
25418
26097
|
return `/media/${id}`;
|
|
@@ -25436,9 +26115,9 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
25436
26115
|
return (entry.history ?? []).map((generation, i) => {
|
|
25437
26116
|
const outputs = generation.outputs.map((output) => {
|
|
25438
26117
|
const mediaType = output.mediaType ?? MediaType.PNG;
|
|
25439
|
-
const file =
|
|
26118
|
+
const file = path48.join(cacheDir, cacheFileName(output.sha256, mediaType));
|
|
25440
26119
|
let url = null;
|
|
25441
|
-
if (
|
|
26120
|
+
if (existsSync42(file)) {
|
|
25442
26121
|
const id = galleryMediaId(file);
|
|
25443
26122
|
media.set(id, { path: file, contentType: mediaType });
|
|
25444
26123
|
url = `${galleryMediaRoute(id)}?v=${output.sha256.slice(0, 24)}`;
|
|
@@ -25470,7 +26149,7 @@ function describeHistory(media, entry, cacheDir) {
|
|
|
25470
26149
|
var MAX_COMPARED_BYTES = 8 * 1024 * 1024;
|
|
25471
26150
|
async function samePixels(a, b) {
|
|
25472
26151
|
try {
|
|
25473
|
-
const [left, right] = await Promise.all([
|
|
26152
|
+
const [left, right] = await Promise.all([readFile34(a), readFile34(b)]);
|
|
25474
26153
|
if (left.length > MAX_COMPARED_BYTES || right.length > MAX_COMPARED_BYTES) return false;
|
|
25475
26154
|
const x = decodePng(left);
|
|
25476
26155
|
const y = decodePng(right);
|
|
@@ -25568,10 +26247,10 @@ async function describeOutput(media, root, absolutePath, recorded = {}) {
|
|
|
25568
26247
|
async function describeQuality(media, root, inspection) {
|
|
25569
26248
|
const outputPaths = inspection.outputs ?? [inspection.output];
|
|
25570
26249
|
const outputs = await Promise.all(
|
|
25571
|
-
outputPaths.map((file) => describeOutput(media, root,
|
|
26250
|
+
outputPaths.map((file) => describeOutput(media, root, path48.resolve(root, file)))
|
|
25572
26251
|
);
|
|
25573
|
-
const recordPath =
|
|
25574
|
-
const recordExists =
|
|
26252
|
+
const recordPath = path48.resolve(root, inspection.record);
|
|
26253
|
+
const recordExists = existsSync42(recordPath);
|
|
25575
26254
|
let options = null;
|
|
25576
26255
|
let check = null;
|
|
25577
26256
|
if (recordExists) {
|
|
@@ -25590,7 +26269,7 @@ async function describeQuality(media, root, inspection) {
|
|
|
25590
26269
|
return {
|
|
25591
26270
|
state: inspection.state,
|
|
25592
26271
|
reason: inspection.reason,
|
|
25593
|
-
output: portableOutputPath(
|
|
26272
|
+
output: portableOutputPath(path48.resolve(root, inspection.output), root),
|
|
25594
26273
|
record: portableOutputPath(recordPath, root),
|
|
25595
26274
|
recordExists,
|
|
25596
26275
|
outputs,
|
|
@@ -25628,9 +26307,9 @@ async function buildGallerySnapshot(opts) {
|
|
|
25628
26307
|
const media = /* @__PURE__ */ new Map();
|
|
25629
26308
|
const plan = await buildPlan(specs, lock);
|
|
25630
26309
|
const items = [];
|
|
25631
|
-
const manifestText = await
|
|
26310
|
+
const manifestText = await readFile34(loaded.path, "utf8");
|
|
25632
26311
|
const manifestSha256 = sha256(manifestText);
|
|
25633
|
-
const cacheDir =
|
|
26312
|
+
const cacheDir = path48.resolve(path48.dirname(opts.lockPath), ".pixelkiln", "cache");
|
|
25634
26313
|
let rawStyles = {};
|
|
25635
26314
|
try {
|
|
25636
26315
|
const raw = JSON.parse(manifestText);
|
|
@@ -25654,12 +26333,12 @@ async function buildGallerySnapshot(opts) {
|
|
|
25654
26333
|
)
|
|
25655
26334
|
);
|
|
25656
26335
|
if (spec.source) {
|
|
25657
|
-
const editPath =
|
|
26336
|
+
const editPath = path48.resolve(root, spec.source);
|
|
25658
26337
|
const memberCount = sourceIsStem(spec.source, entry, root) ? entry.outputs.length : 1;
|
|
25659
26338
|
const editShas = await Promise.all(
|
|
25660
26339
|
Array.from({ length: memberCount }, async (_, index) => {
|
|
25661
26340
|
const file = sourceOutputPath(spec.source, entry, index, root);
|
|
25662
|
-
return { file, sha256:
|
|
26341
|
+
return { file, sha256: existsSync42(file) ? await sha256File(file) : null };
|
|
25663
26342
|
})
|
|
25664
26343
|
);
|
|
25665
26344
|
edits = await Promise.all(editShas.map(({ file, sha256: editSha }) => describeOutput(media, root, file, { sha256: editSha })));
|
|
@@ -25667,7 +26346,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
25667
26346
|
const companion = await readHandEditCompanion(editPath);
|
|
25668
26347
|
if (companion) {
|
|
25669
26348
|
const projectPath = handEditProjectPath(editPath);
|
|
25670
|
-
const project2 = companion.project &&
|
|
26349
|
+
const project2 = companion.project && existsSync42(projectPath) ? await fileInfo(projectPath) : null;
|
|
25671
26350
|
let projectUrl = null;
|
|
25672
26351
|
if (project2) {
|
|
25673
26352
|
const id = galleryMediaId(projectPath);
|
|
@@ -25703,8 +26382,8 @@ async function buildGallerySnapshot(opts) {
|
|
|
25703
26382
|
editStatus = edits.some((member) => !member.exists) ? "missing" : editChanged.every((changed) => !changed) ? "same" : regenerated ? "regenerated-since" : "edited";
|
|
25704
26383
|
}
|
|
25705
26384
|
} else if (spec.source) {
|
|
25706
|
-
outputs = [await describeOutput(media, root,
|
|
25707
|
-
} else if (!entry &&
|
|
26385
|
+
outputs = [await describeOutput(media, root, path48.resolve(root, spec.source))];
|
|
26386
|
+
} else if (!entry && existsSync42(spec.outFile)) {
|
|
25708
26387
|
outputs = [await describeOutput(media, root, spec.outFile)];
|
|
25709
26388
|
} else {
|
|
25710
26389
|
outputs = [];
|
|
@@ -25908,7 +26587,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
25908
26587
|
id: loaded.manifest.name,
|
|
25909
26588
|
name: loaded.manifest.name,
|
|
25910
26589
|
manifest: loaded.path,
|
|
25911
|
-
lock:
|
|
26590
|
+
lock: path48.resolve(opts.lockPath),
|
|
25912
26591
|
root,
|
|
25913
26592
|
provider: loaded.manifest.provider,
|
|
25914
26593
|
account: null,
|
|
@@ -25937,7 +26616,7 @@ async function buildGallerySnapshot(opts) {
|
|
|
25937
26616
|
return { snapshot, media };
|
|
25938
26617
|
}
|
|
25939
26618
|
async function buildWorkspaceGallerySnapshot(opts) {
|
|
25940
|
-
const dir =
|
|
26619
|
+
const dir = path48.dirname(path48.resolve(opts.workspacePath));
|
|
25941
26620
|
const media = /* @__PURE__ */ new Map();
|
|
25942
26621
|
const projects = [];
|
|
25943
26622
|
const items = [];
|
|
@@ -25982,11 +26661,11 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
25982
26661
|
id: project2.id,
|
|
25983
26662
|
name: loaded.manifest.name,
|
|
25984
26663
|
manifest: manifestPath,
|
|
25985
|
-
lock:
|
|
26664
|
+
lock: path48.resolve(lockPath),
|
|
25986
26665
|
root: loaded.root,
|
|
25987
26666
|
provider: loaded.manifest.provider,
|
|
25988
26667
|
account: project2.account ?? null,
|
|
25989
|
-
manifestSha256: manifestSha256 ?? sha256(await
|
|
26668
|
+
manifestSha256: manifestSha256 ?? sha256(await readFile34(manifestPath, "utf8")),
|
|
25990
26669
|
historyLimit: historyLimit(loaded.manifest),
|
|
25991
26670
|
entries: Object.keys(lock.entries).length,
|
|
25992
26671
|
items: projectItems.length,
|
|
@@ -25998,8 +26677,8 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
25998
26677
|
id: project2.id,
|
|
25999
26678
|
name: project2.id,
|
|
26000
26679
|
manifest: manifestPath,
|
|
26001
|
-
lock:
|
|
26002
|
-
root:
|
|
26680
|
+
lock: path48.resolve(lockPath),
|
|
26681
|
+
root: path48.dirname(manifestPath),
|
|
26003
26682
|
provider: project2.provider,
|
|
26004
26683
|
account: project2.account ?? null,
|
|
26005
26684
|
manifestSha256: null,
|
|
@@ -26026,7 +26705,7 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
26026
26705
|
version: 1,
|
|
26027
26706
|
generatedAt: (opts.now ?? (() => /* @__PURE__ */ new Date()))().toISOString(),
|
|
26028
26707
|
project: null,
|
|
26029
|
-
workspace: { path:
|
|
26708
|
+
workspace: { path: path48.resolve(opts.workspacePath), dir, projects },
|
|
26030
26709
|
filter,
|
|
26031
26710
|
totals: {
|
|
26032
26711
|
entries: projects.reduce((sum, project2) => sum + project2.entries, 0),
|
|
@@ -26045,13 +26724,13 @@ async function buildWorkspaceGallerySnapshot(opts) {
|
|
|
26045
26724
|
}
|
|
26046
26725
|
|
|
26047
26726
|
// src/gallery/page.ts
|
|
26048
|
-
import { existsSync as
|
|
26727
|
+
import { existsSync as existsSync43, readFileSync as readFileSync10 } from "fs";
|
|
26049
26728
|
|
|
26050
26729
|
// src/gallery/client-bundle.ts
|
|
26051
|
-
import { createRequire as
|
|
26730
|
+
import { createRequire as createRequire3 } from "module";
|
|
26052
26731
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
26053
26732
|
function bundleGalleryClient(entry = fileURLToPath2(new URL("./client/src/main.ts", import.meta.url))) {
|
|
26054
|
-
const esbuild =
|
|
26733
|
+
const esbuild = createRequire3(import.meta.url)("esbuild");
|
|
26055
26734
|
const result = esbuild.buildSync({
|
|
26056
26735
|
entryPoints: [entry],
|
|
26057
26736
|
bundle: true,
|
|
@@ -26085,8 +26764,8 @@ var client;
|
|
|
26085
26764
|
function clientAssets() {
|
|
26086
26765
|
const prebuilt = new URL("gallery.js", CLIENT_DIR);
|
|
26087
26766
|
client ??= {
|
|
26088
|
-
css:
|
|
26089
|
-
js:
|
|
26767
|
+
css: readFileSync10(new URL("gallery.css", CLIENT_DIR), "utf8"),
|
|
26768
|
+
js: existsSync43(prebuilt) ? readFileSync10(prebuilt, "utf8") : bundleGalleryClient()
|
|
26090
26769
|
};
|
|
26091
26770
|
return client;
|
|
26092
26771
|
}
|
|
@@ -26228,11 +26907,11 @@ var EDITOR_PIN = pin_default;
|
|
|
26228
26907
|
var EDITOR_RELEASE_BASE = "https://github.com/gfargo/pixelkiln/releases/download";
|
|
26229
26908
|
|
|
26230
26909
|
// src/editor/install.ts
|
|
26231
|
-
import { createHash as
|
|
26232
|
-
import { existsSync as
|
|
26233
|
-
import { mkdir as mkdir20, readFile as
|
|
26910
|
+
import { createHash as createHash9 } from "crypto";
|
|
26911
|
+
import { existsSync as existsSync44 } from "fs";
|
|
26912
|
+
import { mkdir as mkdir20, readFile as readFile35, rename as rename13, rm as rm13, stat as stat6, writeFile as writeFile25 } from "fs/promises";
|
|
26234
26913
|
import os3 from "os";
|
|
26235
|
-
import
|
|
26914
|
+
import path49 from "path";
|
|
26236
26915
|
var EditorInstallError = class extends Error {
|
|
26237
26916
|
constructor(message6, file) {
|
|
26238
26917
|
super(message6);
|
|
@@ -26243,15 +26922,15 @@ var EditorInstallError = class extends Error {
|
|
|
26243
26922
|
};
|
|
26244
26923
|
function editorToolsRoot() {
|
|
26245
26924
|
const override = process.env.PIXELKILN_TOOLS_DIR?.trim();
|
|
26246
|
-
if (override) return
|
|
26247
|
-
if (process.platform === "darwin") return
|
|
26925
|
+
if (override) return path49.resolve(override);
|
|
26926
|
+
if (process.platform === "darwin") return path49.join(os3.homedir(), "Library", "Caches", "pixelkiln", "tools");
|
|
26248
26927
|
if (process.platform === "win32") {
|
|
26249
|
-
return
|
|
26928
|
+
return path49.join(process.env.LOCALAPPDATA ?? path49.join(os3.homedir(), "AppData", "Local"), "pixelkiln", "tools");
|
|
26250
26929
|
}
|
|
26251
|
-
return
|
|
26930
|
+
return path49.join(process.env.XDG_CACHE_HOME ?? path49.join(os3.homedir(), ".cache"), "pixelkiln", "tools");
|
|
26252
26931
|
}
|
|
26253
26932
|
function editorDir(pin = EDITOR_PIN, root = editorToolsRoot()) {
|
|
26254
|
-
return
|
|
26933
|
+
return path49.join(root, "pixelorama", pin.release ?? "unpublished");
|
|
26255
26934
|
}
|
|
26256
26935
|
function editorBaseUrl(pin = EDITOR_PIN) {
|
|
26257
26936
|
const override = process.env.PIXELKILN_EDITOR_URL?.trim();
|
|
@@ -26261,7 +26940,7 @@ function editorBaseUrl(pin = EDITOR_PIN) {
|
|
|
26261
26940
|
}
|
|
26262
26941
|
async function sha256Of(file) {
|
|
26263
26942
|
try {
|
|
26264
|
-
return
|
|
26943
|
+
return createHash9("sha256").update(await readFile35(file)).digest("hex");
|
|
26265
26944
|
} catch {
|
|
26266
26945
|
return null;
|
|
26267
26946
|
}
|
|
@@ -26274,8 +26953,8 @@ async function editorStatus(opts = {}) {
|
|
|
26274
26953
|
let totalBytes = 0;
|
|
26275
26954
|
for (const [name, expected] of Object.entries(pin.files)) {
|
|
26276
26955
|
totalBytes += expected.bytes;
|
|
26277
|
-
const file =
|
|
26278
|
-
const info =
|
|
26956
|
+
const file = path49.join(dir, name);
|
|
26957
|
+
const info = existsSync44(file) ? await stat6(file).catch(() => null) : null;
|
|
26279
26958
|
if (info && info.size === expected.bytes && await sha256Of(file) === expected.sha256) {
|
|
26280
26959
|
installedBytes += expected.bytes;
|
|
26281
26960
|
} else {
|
|
@@ -26328,11 +27007,11 @@ async function installEditor(opts = {}) {
|
|
|
26328
27007
|
if (bytes.length !== expected.bytes) {
|
|
26329
27008
|
throw new EditorInstallError(`${name}: expected ${expected.bytes} bytes, got ${bytes.length}`, name);
|
|
26330
27009
|
}
|
|
26331
|
-
const digest2 =
|
|
27010
|
+
const digest2 = createHash9("sha256").update(bytes).digest("hex");
|
|
26332
27011
|
if (digest2 !== expected.sha256) {
|
|
26333
27012
|
throw new EditorInstallError(`${name}: sha256 ${digest2.slice(0, 12)}\u2026 does not match the pinned ${expected.sha256.slice(0, 12)}\u2026`, name);
|
|
26334
27013
|
}
|
|
26335
|
-
const final =
|
|
27014
|
+
const final = path49.join(dir, name);
|
|
26336
27015
|
const tmp = `${final}.${process.pid}.part`;
|
|
26337
27016
|
try {
|
|
26338
27017
|
await writeFile25(tmp, bytes);
|
|
@@ -26378,12 +27057,12 @@ var EDITOR_CONTENT_TYPES = {
|
|
|
26378
27057
|
".json": "application/json; charset=utf-8"
|
|
26379
27058
|
};
|
|
26380
27059
|
function editorContentType(name) {
|
|
26381
|
-
return EDITOR_CONTENT_TYPES[
|
|
27060
|
+
return EDITOR_CONTENT_TYPES[path49.extname(name).toLowerCase()] ?? null;
|
|
26382
27061
|
}
|
|
26383
27062
|
|
|
26384
27063
|
// src/gallery/editor.ts
|
|
26385
|
-
import { readFile as
|
|
26386
|
-
import
|
|
27064
|
+
import { readFile as readFile36 } from "fs/promises";
|
|
27065
|
+
import path50 from "path";
|
|
26387
27066
|
function editorRoute(release, name = "index.html") {
|
|
26388
27067
|
return `/editor/${encodeURIComponent(release)}/${encodeURIComponent(name)}`;
|
|
26389
27068
|
}
|
|
@@ -26456,7 +27135,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
26456
27135
|
if (!status.installed) return null;
|
|
26457
27136
|
let bytes;
|
|
26458
27137
|
try {
|
|
26459
|
-
bytes = await
|
|
27138
|
+
bytes = await readFile36(path50.join(dir, name));
|
|
26460
27139
|
} catch {
|
|
26461
27140
|
verified = null;
|
|
26462
27141
|
return null;
|
|
@@ -26473,7 +27152,7 @@ function createGalleryEditorHandlers(opts = {}) {
|
|
|
26473
27152
|
// src/gallery/server.ts
|
|
26474
27153
|
import { randomBytes } from "crypto";
|
|
26475
27154
|
import { createServer as createServer2 } from "http";
|
|
26476
|
-
import { readFile as
|
|
27155
|
+
import { readFile as readFile37 } from "fs/promises";
|
|
26477
27156
|
var MAX_EDIT_BYTES = 48 * 1024 * 1024;
|
|
26478
27157
|
var EDITOR_CSP = [
|
|
26479
27158
|
"default-src 'self'",
|
|
@@ -26654,7 +27333,7 @@ async function serveGallery(opts) {
|
|
|
26654
27333
|
const asset = reviewAssets.get(jobId)?.get(url2.pathname);
|
|
26655
27334
|
if (!asset) return fail(404, "no such review asset");
|
|
26656
27335
|
try {
|
|
26657
|
-
const bytes = await
|
|
27336
|
+
const bytes = await readFile37(asset.path);
|
|
26658
27337
|
res.writeHead(200, {
|
|
26659
27338
|
"Content-Type": asset.contentType,
|
|
26660
27339
|
"Cache-Control": "no-store",
|
|
@@ -26737,7 +27416,7 @@ async function serveGallery(opts) {
|
|
|
26737
27416
|
if (!asset) return fail(404, "no such gallery media");
|
|
26738
27417
|
let bytes;
|
|
26739
27418
|
try {
|
|
26740
|
-
bytes = await
|
|
27419
|
+
bytes = await readFile37(asset.path);
|
|
26741
27420
|
} catch {
|
|
26742
27421
|
return fail(404, "gallery media is no longer on disk; refresh the page");
|
|
26743
27422
|
}
|
|
@@ -27147,19 +27826,19 @@ function createGenerateHandlers(opts) {
|
|
|
27147
27826
|
}
|
|
27148
27827
|
|
|
27149
27828
|
// src/pipeline/salvage.ts
|
|
27150
|
-
import { readFile as
|
|
27151
|
-
import { existsSync as
|
|
27152
|
-
import
|
|
27829
|
+
import { readFile as readFile38 } from "fs/promises";
|
|
27830
|
+
import { existsSync as existsSync45 } from "fs";
|
|
27831
|
+
import path51 from "path";
|
|
27153
27832
|
function providerClaimId(provider, objectId) {
|
|
27154
27833
|
return `${encodeURIComponent(provider)}:${encodeURIComponent(objectId)}`;
|
|
27155
27834
|
}
|
|
27156
27835
|
async function loadClaims(lockPaths, opts = {}) {
|
|
27157
27836
|
const claimed = /* @__PURE__ */ new Set();
|
|
27158
27837
|
for (const p of lockPaths) {
|
|
27159
|
-
if (!
|
|
27838
|
+
if (!existsSync45(p)) throw new Error(`Claim lockfile not found: ${p}`);
|
|
27160
27839
|
let parsed;
|
|
27161
27840
|
try {
|
|
27162
|
-
parsed = parseLock(JSON.parse(await
|
|
27841
|
+
parsed = parseLock(JSON.parse(await readFile38(p, "utf8")));
|
|
27163
27842
|
} catch {
|
|
27164
27843
|
throw new Error(`Claim lockfile is malformed: ${p}`);
|
|
27165
27844
|
}
|
|
@@ -27263,20 +27942,20 @@ function matchOrphanStyle(prompt, manifest) {
|
|
|
27263
27942
|
return matchStyleByPattern(prompt, manifest);
|
|
27264
27943
|
}
|
|
27265
27944
|
async function loadSiblingManifests(ownManifestPath, workspaceManifestPaths, claimPaths) {
|
|
27266
|
-
const own =
|
|
27945
|
+
const own = path51.resolve(ownManifestPath);
|
|
27267
27946
|
const siblingManifestPaths = [
|
|
27268
27947
|
.../* @__PURE__ */ new Set([
|
|
27269
27948
|
...workspaceManifestPaths,
|
|
27270
|
-
...claimPaths.map((c) =>
|
|
27949
|
+
...claimPaths.map((c) => path51.join(path51.dirname(path51.resolve(c)), "pixelkiln.manifest.json"))
|
|
27271
27950
|
])
|
|
27272
27951
|
];
|
|
27273
27952
|
const siblings = [];
|
|
27274
27953
|
for (const siblingManifestPath of siblingManifestPaths) {
|
|
27275
|
-
if (
|
|
27276
|
-
if (!
|
|
27954
|
+
if (path51.resolve(siblingManifestPath) === own) continue;
|
|
27955
|
+
if (!existsSync45(siblingManifestPath)) continue;
|
|
27277
27956
|
try {
|
|
27278
27957
|
const { manifest } = await loadManifest(siblingManifestPath);
|
|
27279
|
-
siblings.push({ label:
|
|
27958
|
+
siblings.push({ label: path51.basename(path51.dirname(siblingManifestPath)), manifest });
|
|
27280
27959
|
} catch {
|
|
27281
27960
|
}
|
|
27282
27961
|
}
|
|
@@ -27396,8 +28075,8 @@ async function applyTags(provider, decisions, existing, opts = {}) {
|
|
|
27396
28075
|
}
|
|
27397
28076
|
|
|
27398
28077
|
// src/pick/salvage-server.ts
|
|
27399
|
-
import { mkdir as mkdir21, writeFile as writeFile26, readFile as
|
|
27400
|
-
import
|
|
28078
|
+
import { mkdir as mkdir21, writeFile as writeFile26, readFile as readFile39 } from "fs/promises";
|
|
28079
|
+
import path52 from "path";
|
|
27401
28080
|
|
|
27402
28081
|
// src/pick/salvage-sheet.ts
|
|
27403
28082
|
var escapeHtml3 = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
@@ -27563,7 +28242,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
27563
28242
|
});
|
|
27564
28243
|
const html = renderSalvageSheet(orphans, {
|
|
27565
28244
|
styleId: ctx.styleId,
|
|
27566
|
-
importDir:
|
|
28245
|
+
importDir: path52.relative(process.cwd(), ctx.importDir) || "."
|
|
27567
28246
|
});
|
|
27568
28247
|
const byId = new Map(orphans.map((o) => [o.id, o]));
|
|
27569
28248
|
const existingTags = new Map(orphans.map((o) => [o.id, o.tags]));
|
|
@@ -27619,9 +28298,9 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
27619
28298
|
if (!buf.subarray(0, 8).equals(PNG_SIGNATURE2)) throw new Error("not a PNG");
|
|
27620
28299
|
decodePng(buf);
|
|
27621
28300
|
const assetId = idFromPrompt(orphan.prompt, taken);
|
|
27622
|
-
const rel =
|
|
27623
|
-
const outFile =
|
|
27624
|
-
await mkdir21(
|
|
28301
|
+
const rel = path52.join("_salvaged", `${assetId}.png`);
|
|
28302
|
+
const outFile = path52.resolve(ctx.importDir, rel);
|
|
28303
|
+
await mkdir21(path52.dirname(outFile), { recursive: true });
|
|
27625
28304
|
await writeFile26(outFile, buf);
|
|
27626
28305
|
ctx.manifest.assets[assetId] = {
|
|
27627
28306
|
prompt: orphan.prompt,
|
|
@@ -27654,7 +28333,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
27654
28333
|
sourceUrl: durableSource,
|
|
27655
28334
|
sourceUrls: durableSource ? [{ url: durableSource }] : [],
|
|
27656
28335
|
outputs: [{
|
|
27657
|
-
path: portableOutputPath(outFile,
|
|
28336
|
+
path: portableOutputPath(outFile, path52.dirname(ctx.manifestPath)),
|
|
27658
28337
|
sha256: sha256(buf)
|
|
27659
28338
|
}],
|
|
27660
28339
|
submittedAt: orphan.createdAt,
|
|
@@ -27678,7 +28357,7 @@ async function runSalvage(provider, orphans, ctx, opts = {}) {
|
|
|
27678
28357
|
}
|
|
27679
28358
|
}
|
|
27680
28359
|
await applyTags(provider, decisions, existingTags, { onProgress: log, characters: characterMembers });
|
|
27681
|
-
const raw = JSON.parse(await
|
|
28360
|
+
const raw = JSON.parse(await readFile39(ctx.manifestPath, "utf8"));
|
|
27682
28361
|
for (const id of importedAssetIds) raw.assets[id] = ctx.manifest.assets[id];
|
|
27683
28362
|
await writeFile26(ctx.manifestPath, JSON.stringify(raw, null, 2) + "\n");
|
|
27684
28363
|
await saveLock(ctx.lockPath, ctx.lock);
|
|
@@ -27799,6 +28478,12 @@ export {
|
|
|
27799
28478
|
CHARACTER_DIRECTIONS_4,
|
|
27800
28479
|
CHARACTER_DIRECTIONS_8,
|
|
27801
28480
|
CHARACTER_PROPORTION_PRESETS,
|
|
28481
|
+
CODEX_CAMERAS,
|
|
28482
|
+
CODEX_ID,
|
|
28483
|
+
CODEX_INSTALL,
|
|
28484
|
+
CODEX_PACKAGE,
|
|
28485
|
+
CODEX_REPOSITORY,
|
|
28486
|
+
CODEX_TUNE_KEYS,
|
|
27802
28487
|
CharacterAnimationModeSchema,
|
|
27803
28488
|
CharacterAnimationSchema,
|
|
27804
28489
|
CharacterAttachSchema,
|
|
@@ -27938,6 +28623,7 @@ export {
|
|
|
27938
28623
|
applyManifestEdit,
|
|
27939
28624
|
applyTags,
|
|
27940
28625
|
approveQualityRecord,
|
|
28626
|
+
assertFreshOutputs,
|
|
27941
28627
|
assetInStyle,
|
|
27942
28628
|
auditStyle,
|
|
27943
28629
|
availableProviders,
|
|
@@ -27951,6 +28637,7 @@ export {
|
|
|
27951
28637
|
cacheFileName,
|
|
27952
28638
|
candidateCount,
|
|
27953
28639
|
characterDirections,
|
|
28640
|
+
checkCodexRecipe,
|
|
27954
28641
|
checkExportBytes,
|
|
27955
28642
|
checkPixelfxRecipe,
|
|
27956
28643
|
checkQualityBaseline,
|
|
@@ -27996,6 +28683,7 @@ export {
|
|
|
27996
28683
|
fetchWithRetry,
|
|
27997
28684
|
findOrphans,
|
|
27998
28685
|
fontOutputPaths,
|
|
28686
|
+
formatCodexEffects,
|
|
27999
28687
|
formatCost,
|
|
28000
28688
|
formatPixelfxEffects,
|
|
28001
28689
|
frameSetFps,
|
|
@@ -28038,14 +28726,18 @@ export {
|
|
|
28038
28726
|
isometricTileCost,
|
|
28039
28727
|
layerOffsetFor,
|
|
28040
28728
|
listBundledRecipes,
|
|
28729
|
+
listCodexEffects,
|
|
28041
28730
|
listPixelfxEffects,
|
|
28042
28731
|
loadClaims,
|
|
28732
|
+
loadCodex,
|
|
28043
28733
|
loadLock,
|
|
28044
28734
|
loadManifest,
|
|
28045
28735
|
loadPixelfx,
|
|
28046
28736
|
loadSiblingManifests,
|
|
28047
28737
|
loadWorkspace,
|
|
28738
|
+
localSheet,
|
|
28048
28739
|
lockKey,
|
|
28740
|
+
makeCodexVfx,
|
|
28049
28741
|
makePixelfxVfx,
|
|
28050
28742
|
makeVfx,
|
|
28051
28743
|
makeVfxWithArtist,
|
|
@@ -28097,6 +28789,7 @@ export {
|
|
|
28097
28789
|
pixMiniMaxCost,
|
|
28098
28790
|
pixelateFile,
|
|
28099
28791
|
pixelfxSheet,
|
|
28792
|
+
planCodex,
|
|
28100
28793
|
pngFilesAt,
|
|
28101
28794
|
pngSize,
|
|
28102
28795
|
poll,
|
|
@@ -28114,6 +28807,7 @@ export {
|
|
|
28114
28807
|
qualityRecordPath,
|
|
28115
28808
|
quantizeToPalette,
|
|
28116
28809
|
readArtifactBundleManifest,
|
|
28810
|
+
readCodexRecipe,
|
|
28117
28811
|
readHandEditCompanion,
|
|
28118
28812
|
readPixelfxRecipe,
|
|
28119
28813
|
readQualityBaseline,
|
|
@@ -28129,6 +28823,7 @@ export {
|
|
|
28129
28823
|
registerProvider,
|
|
28130
28824
|
remove,
|
|
28131
28825
|
renderAsepriteSheet,
|
|
28826
|
+
renderCodex,
|
|
28132
28827
|
renderGallery,
|
|
28133
28828
|
renderGodotSpriteFrames,
|
|
28134
28829
|
renderPixelfx,
|
|
@@ -28223,6 +28918,7 @@ export {
|
|
|
28223
28918
|
workspaceClaims,
|
|
28224
28919
|
workspaceStatus,
|
|
28225
28920
|
writeArtifactBundle,
|
|
28921
|
+
writeLocalVfx,
|
|
28226
28922
|
writeManagedArtifactBundle
|
|
28227
28923
|
};
|
|
28228
28924
|
//# sourceMappingURL=index.js.map
|