pixelkiln 0.131.0 → 0.133.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 +3 -2
- package/dist/cli.js +1169 -481
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1122 -458
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -14
- package/dist/index.d.ts +39 -14
- package/dist/index.js +1122 -458
- package/dist/index.js.map +1 -1
- package/docs/CHARACTERS_3D.md +4 -0
- package/docs/CLI.md +35 -18
- package/docs/GETTING_STARTED.md +1 -1
- package/docs/RESEARCH_3D.md +44 -1
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -2807,8 +2807,8 @@ var SkeletonSetSchema = import_zod2.z.object({
|
|
|
2807
2807
|
}
|
|
2808
2808
|
}
|
|
2809
2809
|
});
|
|
2810
|
-
function parseSkeletonSet(
|
|
2811
|
-
const result = SkeletonSetSchema.safeParse(
|
|
2810
|
+
function parseSkeletonSet(json2, file) {
|
|
2811
|
+
const result = SkeletonSetSchema.safeParse(json2);
|
|
2812
2812
|
if (!result.success) {
|
|
2813
2813
|
const issues = result.error.issues.slice(0, 4).map((issue) => `${issue.path.join(".") || "root"}: ${issue.message}`).join("; ");
|
|
2814
2814
|
throw new Error(`revision keypoints file ${file} does not match the expected shape: ${issues}`);
|
|
@@ -6065,9 +6065,9 @@ ${text.slice(0, 600)}`);
|
|
|
6065
6065
|
function parseVfxRecipe(text) {
|
|
6066
6066
|
const lines = text.split(/\r?\n/);
|
|
6067
6067
|
const at2 = lines.findIndex((line) => line.trim() === "working recipe:");
|
|
6068
|
-
const
|
|
6069
|
-
if (!
|
|
6070
|
-
return JSON.parse(
|
|
6068
|
+
const json2 = at2 >= 0 ? lines[at2 + 1]?.trim() : void 0;
|
|
6069
|
+
if (!json2?.startsWith("{")) return null;
|
|
6070
|
+
return JSON.parse(json2);
|
|
6071
6071
|
}
|
|
6072
6072
|
function parseVfxExport(text) {
|
|
6073
6073
|
const effectId = new RegExp(`effect id (${UUID})`).exec(text)?.[1];
|
|
@@ -6863,8 +6863,8 @@ var AnchorsFileSchema = import_zod4.z.object({
|
|
|
6863
6863
|
version: import_zod4.z.literal(1),
|
|
6864
6864
|
frames: import_zod4.z.record(import_zod4.z.string().min(1), import_zod4.z.record(import_zod4.z.string().min(1), AnchorFrameSchema))
|
|
6865
6865
|
}).strict();
|
|
6866
|
-
function parseAnchorsFile(
|
|
6867
|
-
const parsed = AnchorsFileSchema.safeParse(
|
|
6866
|
+
function parseAnchorsFile(json2, label) {
|
|
6867
|
+
const parsed = AnchorsFileSchema.safeParse(json2);
|
|
6868
6868
|
if (!parsed.success) {
|
|
6869
6869
|
const issue = parsed.error.issues[0];
|
|
6870
6870
|
throw new Error(`${label} is not an anchors file: ${issue.path.join(".") || "(root)"}: ${issue.message}`);
|
|
@@ -8194,13 +8194,13 @@ function heldFrames(spec, lock) {
|
|
|
8194
8194
|
return frames;
|
|
8195
8195
|
}
|
|
8196
8196
|
async function readAnchorsFile(file) {
|
|
8197
|
-
let
|
|
8197
|
+
let json2;
|
|
8198
8198
|
try {
|
|
8199
|
-
|
|
8199
|
+
json2 = JSON.parse(await (0, import_promises5.readFile)(file, "utf8"));
|
|
8200
8200
|
} catch (error) {
|
|
8201
8201
|
throw new Error(`${file} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
8202
8202
|
}
|
|
8203
|
-
return parseAnchorsFile(
|
|
8203
|
+
return parseAnchorsFile(json2, file);
|
|
8204
8204
|
}
|
|
8205
8205
|
async function placeHeldFrames(spec, frames) {
|
|
8206
8206
|
const layer = spec.character.layer;
|
|
@@ -15285,13 +15285,13 @@ async function optionalRevisionImage(file, label, requiredFormat) {
|
|
|
15285
15285
|
async function optionalSkeletonSet(file) {
|
|
15286
15286
|
if (!(0, import_node_fs11.existsSync)(file)) return null;
|
|
15287
15287
|
const bytes = await (0, import_promises8.readFile)(file);
|
|
15288
|
-
let
|
|
15288
|
+
let json2;
|
|
15289
15289
|
try {
|
|
15290
|
-
|
|
15290
|
+
json2 = JSON.parse(bytes.toString("utf8"));
|
|
15291
15291
|
} catch (error) {
|
|
15292
15292
|
throw new Error(`revision keypoints file ${file} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
15293
15293
|
}
|
|
15294
|
-
return { hash: sha256(bytes), skeleton: parseSkeletonSet(
|
|
15294
|
+
return { hash: sha256(bytes), skeleton: parseSkeletonSet(json2, file) };
|
|
15295
15295
|
}
|
|
15296
15296
|
async function revisionSourceMembers(stem2, label) {
|
|
15297
15297
|
if ((0, import_node_fs11.existsSync)(stem2)) return null;
|
|
@@ -22312,6 +22312,10 @@ var ReviewAssetSchema = import_zod8.z.object({
|
|
|
22312
22312
|
status: import_zod8.z.enum(["pending", "applied"]),
|
|
22313
22313
|
/** The chosen candidate index, or null while nothing is chosen. */
|
|
22314
22314
|
chosen: import_zod8.z.number().int().nonnegative().nullable(),
|
|
22315
|
+
/** Frames (or candidates) the reviewer flagged as bad on the pick page. */
|
|
22316
|
+
flagged: import_zod8.z.array(import_zod8.z.number().int().nonnegative()).optional(),
|
|
22317
|
+
/** Set aside on the pick page to decide later. */
|
|
22318
|
+
later: import_zod8.z.boolean().optional(),
|
|
22315
22319
|
updatedAt: import_zod8.z.string()
|
|
22316
22320
|
});
|
|
22317
22321
|
var ReviewStateSchema = import_zod8.z.object({
|
|
@@ -22421,6 +22425,8 @@ async function cacheReviewCandidates(provider, key3, jobId, job, opts) {
|
|
|
22421
22425
|
candidates,
|
|
22422
22426
|
status: "pending",
|
|
22423
22427
|
chosen: previous?.chosen ?? null,
|
|
22428
|
+
...previous?.flagged?.length ? { flagged: previous.flagged } : {},
|
|
22429
|
+
...previous?.later ? { later: true } : {},
|
|
22424
22430
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
22425
22431
|
};
|
|
22426
22432
|
const latest = await loadReviewState(opts.statePath);
|
|
@@ -23202,421 +23208,950 @@ function mode(values) {
|
|
|
23202
23208
|
|
|
23203
23209
|
// src/pick/sheet.ts
|
|
23204
23210
|
var escapeHtml = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
23205
|
-
function
|
|
23206
|
-
|
|
23211
|
+
function renderableGroups(groups) {
|
|
23212
|
+
return groups.map((g) => ({
|
|
23207
23213
|
...g,
|
|
23208
23214
|
styleId: escapeHtml(g.styleId),
|
|
23209
23215
|
assetId: escapeHtml(g.assetId),
|
|
23210
23216
|
prompt: escapeHtml(g.prompt),
|
|
23211
|
-
...g.revision ? {
|
|
23212
|
-
revision: {
|
|
23213
|
-
...g.revision,
|
|
23214
|
-
sourceAssetId: escapeHtml(g.revision.sourceAssetId)
|
|
23215
|
-
}
|
|
23216
|
-
} : {}
|
|
23217
|
+
...g.revision ? { revision: { ...g.revision, sourceAssetId: escapeHtml(g.revision.sourceAssetId) } } : {}
|
|
23217
23218
|
}));
|
|
23218
|
-
|
|
23219
|
-
|
|
23220
|
-
|
|
23219
|
+
}
|
|
23220
|
+
var json = (value) => JSON.stringify(value).replace(/<\//g, "<\\/");
|
|
23221
|
+
function renderSheet(groups, options = {}) {
|
|
23222
|
+
const config = {
|
|
23223
|
+
applyUrl: options.applyUrl ?? "/apply",
|
|
23221
23224
|
headers: options.applyHeaders ?? {},
|
|
23222
|
-
embedded: options.embedded === true
|
|
23223
|
-
|
|
23225
|
+
embedded: options.embedded === true,
|
|
23226
|
+
sessionUrl: options.sessionUrl ?? null,
|
|
23227
|
+
stateUrl: options.stateUrl ?? null,
|
|
23228
|
+
rerollUrl: options.rerollUrl ?? null
|
|
23229
|
+
};
|
|
23224
23230
|
return `<!doctype html>
|
|
23225
23231
|
<html lang="en">
|
|
23226
23232
|
<head>
|
|
23227
23233
|
<meta charset="utf-8">
|
|
23228
23234
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
23229
|
-
<title>
|
|
23235
|
+
<title>Review candidates | pixelkiln</title>
|
|
23230
23236
|
<style>
|
|
23237
|
+
/*
|
|
23238
|
+
* True-black flat, warmed for a kiln: elevation by lightness alone
|
|
23239
|
+
* (ground, surface, raised), no borders on panels, no shadows at rest.
|
|
23240
|
+
* The ember is the one hue and lives only on data: an accepted asset, the
|
|
23241
|
+
* chosen frame. Flagged frames take the negative pair. Buttons are neutral;
|
|
23242
|
+
* the one primary (Apply) is an inverted white pill.
|
|
23243
|
+
*/
|
|
23231
23244
|
:root {
|
|
23232
|
-
--
|
|
23233
|
-
--
|
|
23234
|
-
--
|
|
23235
|
-
--
|
|
23236
|
-
--
|
|
23237
|
-
|
|
23238
|
-
|
|
23239
|
-
|
|
23240
|
-
|
|
23241
|
-
header { position:sticky; top:0; z-index:10; background:var(--panel);
|
|
23242
|
-
border-bottom:1px solid var(--line-strong); }
|
|
23243
|
-
.bar { width:min(100%,var(--content)); margin:0 auto; padding:15px 22px;
|
|
23244
|
-
display:flex; align-items:center; gap:16px; flex-wrap:wrap; }
|
|
23245
|
-
h1 { font:700 14px/1 ui-monospace,SFMono-Regular,Menlo,monospace;
|
|
23246
|
-
margin:0; letter-spacing:-.02em; }
|
|
23247
|
-
h1::before { content:'\u25C6'; color:var(--accent); margin-right:9px; font-size:11px; }
|
|
23248
|
-
.count { color:var(--dim); font-variant-numeric:tabular-nums; }
|
|
23249
|
-
button { font:inherit; font-weight:600; border-radius:0; padding:9px 16px;
|
|
23250
|
-
border:1px solid var(--line); background:transparent; color:var(--text); cursor:pointer; }
|
|
23251
|
-
button.primary { background:var(--accent); border-color:var(--accent); color:var(--bg); }
|
|
23252
|
-
button:disabled { opacity:.45; cursor:not-allowed; }
|
|
23253
|
-
main, footer { width:min(100%,var(--content)); margin-inline:auto; }
|
|
23254
|
-
main { border-inline:1px solid var(--line); }
|
|
23255
|
-
.group { border-bottom:1px solid var(--line); padding:22px; overflow:hidden; }
|
|
23256
|
-
.group.done { background:rgba(185,242,124,.035); }
|
|
23257
|
-
.ghead { display:flex; align-items:baseline; gap:12px; margin-bottom:16px; flex-wrap:wrap; }
|
|
23258
|
-
.style { font-size:10.5px; font-weight:650; text-transform:uppercase; letter-spacing:.03em;
|
|
23259
|
-
color:var(--accent-soft); border:1px solid var(--accent); border-radius:0; padding:2px 6px; }
|
|
23260
|
-
.aid { font-weight:650; font-family:ui-monospace,SFMono-Regular,Menlo,monospace; }
|
|
23261
|
-
.prompt { flex:1; min-width:280px; color:var(--dim); font-size:12.5px; max-width:80ch; }
|
|
23262
|
-
.review { display:grid; grid-template-columns:minmax(180px,280px) minmax(0,1fr); gap:16px;
|
|
23263
|
-
align-items:start; }
|
|
23264
|
-
.review.no-context { display:block; }
|
|
23265
|
-
.context { border:1px solid var(--line); padding:8px; background:var(--panel-deep);
|
|
23266
|
-
min-width:0; display:grid; gap:12px; align-content:start; }
|
|
23267
|
-
.context-label { display:flex; justify-content:space-between; gap:8px; margin-bottom:7px;
|
|
23268
|
-
color:var(--dim); font-size:10.5px; font-variant-numeric:tabular-nums; }
|
|
23269
|
-
.context img { display:block; width:100%; height:auto; max-height:420px; object-fit:contain;
|
|
23270
|
-
image-rendering:pixelated;
|
|
23271
|
-
background-image:linear-gradient(45deg,#0000 25%,#7f7f7f22 25%,#7f7f7f22 75%,#0000 75%),
|
|
23272
|
-
linear-gradient(45deg,#0000 25%,#7f7f7f22 25%,#7f7f7f22 75%,#0000 75%);
|
|
23273
|
-
background-size:12px 12px; background-position:0 0,6px 6px; }
|
|
23274
|
-
.frames { display:flex; flex-wrap:wrap; gap:10px; max-width:100%; overflow-x:auto; }
|
|
23275
|
-
.loop { display:flex; align-items:flex-start; gap:12px; margin-bottom:12px; }
|
|
23276
|
-
.loop img { image-rendering:pixelated; border:2px solid var(--accent); padding:7px;
|
|
23277
|
-
background:var(--panel-deep); max-width:min(var(--preview),calc(100vw - 62px)); height:auto; }
|
|
23278
|
-
.loop-copy { color:var(--dim); font-size:11px; max-width:32ch; display:flex;
|
|
23279
|
-
flex-direction:column; gap:8px; }
|
|
23280
|
-
.loop-copy p { margin:0; }
|
|
23281
|
-
.loop-copy button { align-self:flex-start; padding:5px 9px; font-size:10.5px; }
|
|
23282
|
-
.cand { border:2px solid var(--line-strong); border-radius:0; padding:7px; background:var(--panel-deep);
|
|
23283
|
-
cursor:pointer; display:flex; flex:0 0 auto; flex-direction:column; align-items:center; gap:5px;
|
|
23284
|
-
position:relative; max-width:100%; }
|
|
23285
|
-
.cand:hover { border-color:var(--dim); }
|
|
23286
|
-
.cand.active { border-color:var(--dim); box-shadow:0 0 0 2px color-mix(in srgb, var(--dim) 20%, transparent); }
|
|
23287
|
-
.cand.sel { border-color:var(--ok); box-shadow:0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
|
|
23288
|
-
.cand.set-frame { cursor:pointer; }
|
|
23289
|
-
.cand.recommended:not(.sel) { border-color:var(--accent); }
|
|
23290
|
-
.cand.recommended .badge { position:absolute; top:-1px; left:-1px; font-size:9.5px; font-weight:650;
|
|
23291
|
-
text-transform:uppercase; letter-spacing:.03em; color:var(--bg); background:var(--accent); padding:1px 5px; }
|
|
23292
|
-
.cand img { image-rendering:pixelated; display:block;
|
|
23293
|
-
background-image:
|
|
23294
|
-
linear-gradient(45deg,#0000 25%,#7f7f7f22 25%,#7f7f7f22 75%,#0000 75%),
|
|
23295
|
-
linear-gradient(45deg,#0000 25%,#7f7f7f22 25%,#7f7f7f22 75%,#0000 75%);
|
|
23296
|
-
background-size:12px 12px; background-position:0 0,6px 6px; border-radius:0; }
|
|
23297
|
-
.cand img.preview { max-width:min(var(--preview),calc(100vw - 62px)); height:auto; }
|
|
23298
|
-
.idx { font-size:10.5px; color:var(--dim); font-variant-numeric:tabular-nums; }
|
|
23299
|
-
.actual { position:absolute; right:-3px; bottom:-3px; image-rendering:pixelated;
|
|
23300
|
-
border:1px solid var(--line); border-radius:0; background:var(--panel); }
|
|
23301
|
-
.skip { align-self:center; color:var(--dim); font-size:12px; }
|
|
23302
|
-
footer { padding:26px 20px 60px; color:var(--dim); }
|
|
23303
|
-
kbd { border:1px solid var(--line); border-bottom-width:2px; border-radius:0;
|
|
23304
|
-
padding:1px 5px; font-size:11px; font-family:ui-monospace,Menlo,monospace; }
|
|
23305
|
-
#status { color:var(--warn); }
|
|
23306
|
-
@media (max-width:640px) {
|
|
23307
|
-
.bar, .group { padding-inline:14px; }
|
|
23308
|
-
.prompt { min-width:100%; }
|
|
23309
|
-
.cand img.preview { max-width:calc(100vw - 50px); }
|
|
23310
|
-
}
|
|
23311
|
-
@media (max-width:900px) {
|
|
23312
|
-
.review { grid-template-columns:1fr; }
|
|
23313
|
-
.context { max-width:280px; }
|
|
23245
|
+
--ground:#0e0d0c; --surface:#181716; --raised:#26241f; --hover:#1f1d1a; --rule:#22201d;
|
|
23246
|
+
--text:#ffffff; --muted:#b4b4b4; --faint:#949494; --control:#46423b;
|
|
23247
|
+
--ember:#ff6b35; --ember-bg:#2e1a10;
|
|
23248
|
+
--negative:#e5566f; --negative-bg:#2c1a20;
|
|
23249
|
+
--list:340px; --head:56px; --pad:22px; --gap:14px; --row:56px;
|
|
23250
|
+
--radius-card:14px; --radius-chip:6px;
|
|
23251
|
+
--font: ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
|
|
23252
|
+
--mono: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
23253
|
+
color-scheme: dark;
|
|
23314
23254
|
}
|
|
23255
|
+
* { box-sizing:border-box; }
|
|
23256
|
+
html, body { height:100%; }
|
|
23257
|
+
body { margin:0; background:var(--ground); color:var(--text); font:14px/1.45 var(--font);
|
|
23258
|
+
display:grid; grid-template-rows:auto minmax(0,1fr) auto; overflow:hidden; }
|
|
23259
|
+
button { font:inherit; color:inherit; background:none; border:0; cursor:pointer; }
|
|
23260
|
+
button:focus-visible, [tabindex]:focus-visible { outline:2px solid var(--text); outline-offset:2px; }
|
|
23261
|
+
.num { font-variant-numeric:tabular-nums; }
|
|
23262
|
+
.id { font-family:var(--mono); font-size:12px; }
|
|
23263
|
+
|
|
23264
|
+
/* Top bar */
|
|
23265
|
+
header { display:flex; align-items:center; gap:20px; min-height:var(--head); padding:0 var(--pad); border-bottom:1px solid var(--rule); min-width:0; }
|
|
23266
|
+
.break { display:none; }
|
|
23267
|
+
.mark { font-weight:600; display:flex; align-items:center; gap:8px; white-space:nowrap; }
|
|
23268
|
+
.mark svg { display:block; }
|
|
23269
|
+
.counter { color:var(--muted); white-space:nowrap; }
|
|
23270
|
+
.counter b { color:var(--text); font-weight:600; }
|
|
23271
|
+
.filters { display:flex; gap:2px; margin-left:8px; }
|
|
23272
|
+
.filters button { height:32px; padding:0 10px; border-radius:var(--radius-chip); color:#bbb; white-space:nowrap; }
|
|
23273
|
+
.filters button:hover { background:var(--hover); }
|
|
23274
|
+
.filters button[aria-pressed="true"] { color:var(--text); background:var(--raised); }
|
|
23275
|
+
.filters .n { color:var(--faint); margin-left:6px; }
|
|
23276
|
+
.grow { flex:1; }
|
|
23277
|
+
.batch { display:flex; gap:2px; }
|
|
23278
|
+
.batch button, .tool { height:32px; padding:0 10px; border-radius:var(--radius-chip); color:#bbb; white-space:nowrap; }
|
|
23279
|
+
.batch button:hover, .tool:hover { background:var(--hover); color:var(--text); }
|
|
23280
|
+
.primary { height:36px; padding:0 18px; border-radius:999px; background:var(--text); color:#000; font-weight:600; white-space:nowrap; }
|
|
23281
|
+
.primary:disabled { background:var(--raised); color:var(--faint); cursor:not-allowed; }
|
|
23282
|
+
#status { color:var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:28ch; }
|
|
23283
|
+
#status.error { color:var(--negative); }
|
|
23284
|
+
|
|
23285
|
+
/* Master list */
|
|
23286
|
+
main { display:grid; grid-template-columns:var(--list) minmax(0,1fr); min-height:0; }
|
|
23287
|
+
#list { overflow-y:auto; border-right:1px solid var(--rule); padding:8px; scroll-padding:8px; outline:none; }
|
|
23288
|
+
.row { display:grid; grid-template-columns:44px minmax(0,1fr) auto; align-items:center; gap:12px;
|
|
23289
|
+
width:100%; height:var(--row); padding:6px 10px 6px 6px; border-radius:10px; text-align:left; }
|
|
23290
|
+
.row:hover { background:var(--hover); }
|
|
23291
|
+
.row[aria-selected="true"] { background:var(--raised); }
|
|
23292
|
+
.thumb { width:44px; height:44px; border-radius:8px; background:var(--surface); display:grid; place-items:center; overflow:hidden; }
|
|
23293
|
+
.thumb canvas { image-rendering:pixelated; display:block; }
|
|
23294
|
+
.row .name { display:block; font-weight:500; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
|
|
23295
|
+
.row .meta { display:block; color:var(--faint); font-size:13px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
|
|
23296
|
+
.state { font-size:13px; color:var(--faint); white-space:nowrap; }
|
|
23297
|
+
.state.accepted { color:var(--ember); }
|
|
23298
|
+
.state.flagged { color:var(--negative); }
|
|
23299
|
+
.state.later, .state.rerolling { color:var(--muted); }
|
|
23300
|
+
.empty { color:var(--muted); padding:24px 12px; }
|
|
23301
|
+
|
|
23302
|
+
/* Stage */
|
|
23303
|
+
#stage { display:grid; grid-template-rows:auto minmax(0,1fr) auto auto; min-width:0; min-height:0; padding:18px var(--pad) 16px; gap:var(--gap); }
|
|
23304
|
+
.title { display:flex; align-items:baseline; gap:12px; min-width:0; }
|
|
23305
|
+
.title h1 { font-size:20px; font-weight:600; margin:0; white-space:nowrap; }
|
|
23306
|
+
.title .id { color:var(--faint); white-space:nowrap; }
|
|
23307
|
+
.title .pos { margin-left:auto; color:var(--faint); white-space:nowrap; }
|
|
23308
|
+
.prompt { color:var(--muted); margin:4px 0 0; max-width:90ch; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
|
|
23309
|
+
.view { position:relative; min-height:0; border-radius:var(--radius-card); background-color:var(--surface);
|
|
23310
|
+
background-image:linear-gradient(45deg,#ffffff08 25%,transparent 25%,transparent 75%,#ffffff08 75%),
|
|
23311
|
+
linear-gradient(45deg,#ffffff08 25%,transparent 25%,transparent 75%,#ffffff08 75%);
|
|
23312
|
+
background-size:16px 16px; background-position:0 0,8px 8px;
|
|
23313
|
+
display:grid; place-items:center; overflow:hidden; }
|
|
23314
|
+
.view canvas { image-rendering:pixelated; display:block; }
|
|
23315
|
+
.view .tag { position:absolute; left:14px; top:12px; color:var(--muted); font-size:13px; }
|
|
23316
|
+
.view .tag b { color:var(--text); font-weight:500; }
|
|
23317
|
+
.view .scale { position:absolute; right:14px; top:12px; color:var(--faint); font-size:13px; }
|
|
23318
|
+
.view .notice { position:absolute; inset:auto 14px 12px 14px; color:var(--muted); font-size:13px; }
|
|
23319
|
+
.view.flipped .tag b { color:var(--ember); }
|
|
23320
|
+
.controls { display:flex; align-items:center; gap:4px; flex-wrap:wrap; }
|
|
23321
|
+
.tool[aria-pressed="true"] { color:var(--text); background:var(--raised); }
|
|
23322
|
+
.tool kbd, .act kbd { color:var(--faint); margin-left:6px; font:13px var(--font); }
|
|
23323
|
+
.tool:disabled { color:#8f8a82; cursor:default; background:none; }
|
|
23324
|
+
.actions { display:flex; gap:6px; margin-left:auto; }
|
|
23325
|
+
.act { height:36px; padding:0 14px; border-radius:999px; background:var(--raised); white-space:nowrap; }
|
|
23326
|
+
.act:hover { background:#34312b; }
|
|
23327
|
+
.act.on { background:var(--ember-bg); color:var(--ember); }
|
|
23328
|
+
.act.warn { background:var(--negative-bg); color:var(--negative); }
|
|
23329
|
+
.act:disabled { color:var(--faint); background:var(--surface); cursor:default; }
|
|
23330
|
+
|
|
23331
|
+
/* Frame strip */
|
|
23332
|
+
.strip { display:flex; gap:6px; overflow-x:auto; padding-bottom:4px; scroll-padding:8px; }
|
|
23333
|
+
.strip[hidden] { display:none; }
|
|
23334
|
+
.cell { flex:0 0 auto; display:flex; flex-direction:column; align-items:center; gap:4px; padding:6px; border-radius:10px; min-width:64px; }
|
|
23335
|
+
.cell:hover { background:var(--hover); }
|
|
23336
|
+
.cell .pic { display:grid; place-items:center; background:var(--surface); border-radius:6px; padding:4px; }
|
|
23337
|
+
.cell canvas { image-rendering:pixelated; display:block; }
|
|
23338
|
+
.cell .lab { font-size:13px; color:var(--faint); }
|
|
23339
|
+
.cell[aria-current="true"] { background:var(--raised); }
|
|
23340
|
+
.cell[aria-current="true"] .lab { color:var(--text); }
|
|
23341
|
+
.cell.chosen .pic { box-shadow:inset 0 -3px 0 var(--ember); }
|
|
23342
|
+
.cell.chosen .lab { color:var(--ember); }
|
|
23343
|
+
.cell.flag .pic { box-shadow:inset 0 0 0 2px var(--negative); }
|
|
23344
|
+
.cell.flag .lab { color:var(--negative); }
|
|
23345
|
+
|
|
23346
|
+
footer { display:flex; gap:18px; flex-wrap:wrap; padding:8px var(--pad); border-top:1px solid var(--rule); color:var(--faint); font-size:12px; }
|
|
23347
|
+
footer kbd { font:12px var(--font); color:var(--muted); }
|
|
23348
|
+
body.done main { opacity:.5; pointer-events:none; }
|
|
23349
|
+
|
|
23350
|
+
@media (max-width: 1240px) {
|
|
23351
|
+
header { flex-wrap:wrap; row-gap:4px; padding:8px var(--pad); }
|
|
23352
|
+
.break { display:block; flex-basis:100%; height:0; order:5; }
|
|
23353
|
+
.filters { order:6; margin-left:-10px; }
|
|
23354
|
+
.batch { order:7; margin-left:auto; }
|
|
23355
|
+
}
|
|
23356
|
+
@media (max-width: 900px) {
|
|
23357
|
+
body { overflow:auto; grid-template-rows:auto auto auto; height:auto; }
|
|
23358
|
+
header { flex-wrap:wrap; padding:10px 16px; gap:10px; }
|
|
23359
|
+
.filters { margin-left:0; overflow-x:auto; max-width:100%; }
|
|
23360
|
+
main { grid-template-columns:1fr; }
|
|
23361
|
+
#list { max-height:38vh; border-right:0; border-bottom:1px solid var(--rule); }
|
|
23362
|
+
#stage { padding:14px 16px; grid-template-rows:auto 56vh auto auto; }
|
|
23363
|
+
.actions { margin-left:0; flex-wrap:wrap; }
|
|
23364
|
+
}
|
|
23365
|
+
@media (prefers-reduced-motion: reduce) { * { scroll-behavior:auto !important; } }
|
|
23315
23366
|
</style>
|
|
23316
23367
|
</head>
|
|
23317
23368
|
<body>
|
|
23318
23369
|
<header>
|
|
23319
|
-
<
|
|
23320
|
-
|
|
23321
|
-
|
|
23322
|
-
|
|
23323
|
-
|
|
23324
|
-
|
|
23370
|
+
<span class="mark"><svg width="14" height="14" viewBox="0 0 7 7" aria-hidden="true" shape-rendering="crispEdges"><path fill="#ff6b35" d="M3 0h1v1h1v1h1v1h1v1H6v1H5v1H4v1H3V6H2V5H1V4H0V3h1V2h1V1h1z"/></svg>pixelkiln</span>
|
|
23371
|
+
<span class="counter num" id="counter" aria-live="polite"></span>
|
|
23372
|
+
<nav class="filters" id="filters" aria-label="Filter by status"></nav>
|
|
23373
|
+
<span class="grow"></span>
|
|
23374
|
+
<span id="status" role="status"></span>
|
|
23375
|
+
<div class="batch">
|
|
23376
|
+
<button type="button" id="select-all" title="Accept every asset in this view (Shift+S)">Select all</button>
|
|
23377
|
+
<button type="button" id="deselect-all" title="Clear every acceptance (Shift+D)">Deselect all</button>
|
|
23378
|
+
<button type="button" id="accept-unflagged" title="Accept every undecided asset with no flags (Shift+A)">Accept unflagged</button>
|
|
23325
23379
|
</div>
|
|
23380
|
+
<button type="button" class="primary num" id="apply" disabled>Apply</button>
|
|
23381
|
+
<span class="break"></span>
|
|
23326
23382
|
</header>
|
|
23327
|
-
<main
|
|
23383
|
+
<main>
|
|
23384
|
+
<div id="list" role="listbox" aria-label="Assets awaiting review" tabindex="0"></div>
|
|
23385
|
+
<section id="stage" aria-label="Current asset">
|
|
23386
|
+
<div>
|
|
23387
|
+
<div class="title"><h1 id="s-name"></h1><span class="id" id="s-key"></span><span class="pos num" id="s-pos"></span></div>
|
|
23388
|
+
<p class="prompt" id="s-prompt"></p>
|
|
23389
|
+
</div>
|
|
23390
|
+
<div class="view" id="view">
|
|
23391
|
+
<canvas id="s-canvas" aria-label="Animated frame-set preview"></canvas>
|
|
23392
|
+
<span class="tag" id="s-tag"></span>
|
|
23393
|
+
<span class="scale num" id="s-scale"></span>
|
|
23394
|
+
<span class="notice" id="s-notice"></span>
|
|
23395
|
+
</div>
|
|
23396
|
+
<div class="controls">
|
|
23397
|
+
<button type="button" class="tool" id="t-play" aria-pressed="false">Pause<kbd>Space</kbd></button>
|
|
23398
|
+
<button type="button" class="tool" id="t-flip" aria-pressed="false">Show current art<kbd>C</kbd></button>
|
|
23399
|
+
<button type="button" class="tool" id="t-strip" aria-pressed="false">Frames<kbd>X</kbd></button>
|
|
23400
|
+
<button type="button" class="tool" id="t-onion" aria-pressed="false">Onion skin<kbd>O</kbd></button>
|
|
23401
|
+
<button type="button" class="tool" id="t-pong" aria-pressed="false">Ping-pong<kbd>P</kbd></button>
|
|
23402
|
+
<div class="actions">
|
|
23403
|
+
<button type="button" class="act" id="a-flag">Flag frame<kbd>F</kbd></button>
|
|
23404
|
+
<button type="button" class="act" id="a-later">Later<kbd>L</kbd></button>
|
|
23405
|
+
<button type="button" class="act" id="a-reroll">Reroll<kbd>R</kbd></button>
|
|
23406
|
+
<button type="button" class="act" id="a-accept">Accept<kbd>A</kbd></button>
|
|
23407
|
+
</div>
|
|
23408
|
+
</div>
|
|
23409
|
+
<div class="strip" id="strip" role="listbox" aria-label="Frames" hidden></div>
|
|
23410
|
+
</section>
|
|
23411
|
+
</main>
|
|
23328
23412
|
<footer>
|
|
23329
|
-
|
|
23330
|
-
|
|
23331
|
-
<kbd
|
|
23332
|
-
<kbd>
|
|
23333
|
-
<kbd
|
|
23334
|
-
|
|
23413
|
+
<span><kbd>\u2191</kbd> <kbd>\u2193</kbd> asset</span>
|
|
23414
|
+
<span><kbd>\u2190</kbd> <kbd>\u2192</kbd> frame or candidate</span>
|
|
23415
|
+
<span><kbd>A</kbd> accept</span>
|
|
23416
|
+
<span><kbd>F</kbd> flag frame</span>
|
|
23417
|
+
<span><kbd>L</kbd> later</span>
|
|
23418
|
+
<span><kbd>R</kbd> reroll</span>
|
|
23419
|
+
<span><kbd>X</kbd> frames</span>
|
|
23420
|
+
<span><kbd>C</kbd> compare</span>
|
|
23421
|
+
<span><kbd>1</kbd>\u2013<kbd>5</kbd> filter</span>
|
|
23422
|
+
<span><kbd>Shift</kbd>+<kbd>A</kbd> accept unflagged</span>
|
|
23423
|
+
<span><kbd>\u2318</kbd>/<kbd>Ctrl</kbd>+<kbd>Enter</kbd> apply</span>
|
|
23424
|
+
<span>Unaccepted assets stay in review; closing this page loses nothing.</span>
|
|
23335
23425
|
</footer>
|
|
23336
23426
|
<script>
|
|
23337
|
-
const
|
|
23338
|
-
|
|
23339
|
-
|
|
23340
|
-
|
|
23341
|
-
|
|
23427
|
+
const CONFIG = ${json(config)};
|
|
23428
|
+
let GROUPS = ${json(renderableGroups(groups))};
|
|
23429
|
+
${CLIENT}
|
|
23430
|
+
</script>
|
|
23431
|
+
</body>
|
|
23432
|
+
</html>`;
|
|
23433
|
+
}
|
|
23434
|
+
var CLIENT = String.raw`
|
|
23435
|
+
const $ = (id) => document.getElementById(id);
|
|
23436
|
+
const reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
23437
|
+
const STORE = 'pixelkiln-pick:';
|
|
23438
|
+
const FILTERS = [
|
|
23439
|
+
['all', 'All'], ['undecided', 'Undecided'], ['accepted', 'Accepted'], ['flagged', 'Flagged'], ['later', 'Later'],
|
|
23440
|
+
];
|
|
23342
23441
|
|
|
23343
|
-
|
|
23344
|
-
|
|
23345
|
-
|
|
23346
|
-
|
|
23347
|
-
|
|
23348
|
-
|
|
23349
|
-
|
|
23350
|
-
|
|
23351
|
-
|
|
23352
|
-
|
|
23353
|
-
|
|
23354
|
-
|
|
23355
|
-
|
|
23356
|
-
|
|
23357
|
-
|
|
23358
|
-
|
|
23359
|
-
|
|
23360
|
-
|
|
23361
|
-
|
|
23362
|
-
|
|
23363
|
-
|
|
23364
|
-
|
|
23365
|
-
const label = document.createElement('div');
|
|
23366
|
-
label.className = 'context-label';
|
|
23367
|
-
const identity = document.createElement('span');
|
|
23368
|
-
identity.textContent = identityText;
|
|
23369
|
-
const dimensions = document.createElement('span');
|
|
23370
|
-
dimensions.textContent = dimensionsText;
|
|
23371
|
-
label.append(identity, dimensions);
|
|
23372
|
-
const img = document.createElement('img');
|
|
23442
|
+
let state = {}; // key -> { chosen, flagged, later }
|
|
23443
|
+
let rerolls = {}; // key -> { state, error }
|
|
23444
|
+
let canReroll = Boolean(CONFIG.rerollUrl);
|
|
23445
|
+
let filter = 'all';
|
|
23446
|
+
let currentKey = GROUPS[0] ? GROUPS[0].key : null;
|
|
23447
|
+
let cursor = {}; // key -> frame or candidate index on the stage
|
|
23448
|
+
let playing = !reduced;
|
|
23449
|
+
let flipped = 0; // 0 candidate, then each comparison the asset has
|
|
23450
|
+
let showStrip = false, onion = false, pingpong = false;
|
|
23451
|
+
let armedReroll = null, armedTimer = null;
|
|
23452
|
+
let applying = false;
|
|
23453
|
+
|
|
23454
|
+
// ---- one request per frame -------------------------------------------------
|
|
23455
|
+
const images = new Map();
|
|
23456
|
+
function image(url) {
|
|
23457
|
+
let entry = images.get(url);
|
|
23458
|
+
if (!entry) {
|
|
23459
|
+
const img = new Image();
|
|
23460
|
+
img.decoding = 'async';
|
|
23461
|
+
entry = { img, ready: false, failed: false };
|
|
23462
|
+
img.onload = () => { entry.ready = true; dirty = true; };
|
|
23463
|
+
img.onerror = () => { entry.failed = true; dirty = true; };
|
|
23373
23464
|
img.src = url;
|
|
23374
|
-
|
|
23375
|
-
block.append(label, img);
|
|
23376
|
-
return block;
|
|
23377
|
-
};
|
|
23378
|
-
if (g.revision || g.current) {
|
|
23379
|
-
const context = document.createElement('aside');
|
|
23380
|
-
context.className = 'context';
|
|
23381
|
-
if (g.revision) {
|
|
23382
|
-
context.append(contextPanel(
|
|
23383
|
-
g.revision.mode.toUpperCase() + ' \xB7 SOURCE ' + g.revision.sourceAssetId,
|
|
23384
|
-
g.revision.width + '\xD7' + g.revision.height,
|
|
23385
|
-
g.revision.sourceUrl, 'Revision source ' + g.revision.sourceAssetId));
|
|
23386
|
-
}
|
|
23387
|
-
if (g.current) {
|
|
23388
|
-
context.append(contextPanel(
|
|
23389
|
-
'CURRENT ART \xB7 replaced if you choose',
|
|
23390
|
-
g.current.width + '\xD7' + g.current.height,
|
|
23391
|
-
g.current.url, 'Current ' + g.assetId));
|
|
23392
|
-
}
|
|
23393
|
-
review.insertBefore(context, frames);
|
|
23394
|
-
}
|
|
23395
|
-
if (g.mode === 'frame-set') {
|
|
23396
|
-
const loop = document.createElement('div');
|
|
23397
|
-
loop.className = 'loop';
|
|
23398
|
-
const preview = document.createElement('img');
|
|
23399
|
-
preview.src = g.frameUrls[0];
|
|
23400
|
-
preview.width = displayWidth;
|
|
23401
|
-
preview.height = displayHeight;
|
|
23402
|
-
preview.alt = 'Animated frame-set preview';
|
|
23403
|
-
const copy = document.createElement('div');
|
|
23404
|
-
copy.className = 'loop-copy';
|
|
23405
|
-
const copyText = document.createElement('p');
|
|
23406
|
-
copyText.textContent = g.frameUrls.length + ' ordered frames \xB7 ' + (g.fps || 12) +
|
|
23407
|
-
' fps. Accepting keeps every frame; one bad frame means leave the set unchosen.';
|
|
23408
|
-
const playback = document.createElement('button');
|
|
23409
|
-
playback.type = 'button';
|
|
23410
|
-
let userPaused = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
23411
|
-
let loopVisible = true;
|
|
23412
|
-
let pageVisible = !document.hidden;
|
|
23413
|
-
let loopTimer = null;
|
|
23414
|
-
let loopIndex = 0;
|
|
23415
|
-
const stopLoop = () => {
|
|
23416
|
-
if (loopTimer !== null) window.clearInterval(loopTimer);
|
|
23417
|
-
loopTimer = null;
|
|
23418
|
-
};
|
|
23419
|
-
const syncLoop = () => {
|
|
23420
|
-
stopLoop();
|
|
23421
|
-
playback.textContent = userPaused ? 'Play preview' : 'Pause preview';
|
|
23422
|
-
playback.setAttribute('aria-pressed', String(userPaused));
|
|
23423
|
-
if (!userPaused && loopVisible && pageVisible) {
|
|
23424
|
-
loopTimer = window.setInterval(() => {
|
|
23425
|
-
loopIndex = (loopIndex + 1) % g.frameUrls.length;
|
|
23426
|
-
preview.src = g.frameUrls[loopIndex];
|
|
23427
|
-
}, Math.max(16, Math.round(1000 / (g.fps || 12))));
|
|
23428
|
-
}
|
|
23429
|
-
};
|
|
23430
|
-
playback.addEventListener('click', () => {
|
|
23431
|
-
userPaused = !userPaused;
|
|
23432
|
-
syncLoop();
|
|
23433
|
-
});
|
|
23434
|
-
copy.append(copyText, playback);
|
|
23435
|
-
loop.append(preview, copy);
|
|
23436
|
-
review.insertBefore(loop, frames);
|
|
23437
|
-
document.addEventListener('visibilitychange', () => {
|
|
23438
|
-
pageVisible = !document.hidden;
|
|
23439
|
-
syncLoop();
|
|
23440
|
-
});
|
|
23441
|
-
syncLoop();
|
|
23442
|
-
if ('IntersectionObserver' in window) {
|
|
23443
|
-
new IntersectionObserver((entries) => {
|
|
23444
|
-
loopVisible = entries[0]?.isIntersecting ?? false;
|
|
23445
|
-
syncLoop();
|
|
23446
|
-
}).observe(loop);
|
|
23447
|
-
}
|
|
23465
|
+
images.set(url, entry);
|
|
23448
23466
|
}
|
|
23449
|
-
|
|
23450
|
-
|
|
23451
|
-
const c = document.createElement('button');
|
|
23452
|
-
c.type = 'button';
|
|
23453
|
-
c.className = 'cand' + (g.mode === 'frame-set' ? ' set-frame' : '') +
|
|
23454
|
-
(g.recommendedIndex != null && i === recommended ? ' recommended' : '');
|
|
23455
|
-
c.tabIndex = -1;
|
|
23456
|
-
c.setAttribute('aria-label', (g.mode === 'frame-set'
|
|
23457
|
-
? 'Accept ordered frame set from frame ' + (i + 1)
|
|
23458
|
-
: 'Choose candidate ' + (i + 1) + ' of ' + g.frameUrls.length) +
|
|
23459
|
-
(g.recommendedIndex != null && i === recommended ? ' (this asset\u2019s declared slot)' : ''));
|
|
23467
|
+
return entry;
|
|
23468
|
+
}
|
|
23460
23469
|
|
|
23461
|
-
|
|
23462
|
-
|
|
23463
|
-
|
|
23464
|
-
|
|
23465
|
-
|
|
23466
|
-
|
|
23467
|
-
|
|
23468
|
-
|
|
23469
|
-
|
|
23470
|
-
|
|
23471
|
-
|
|
23472
|
-
|
|
23473
|
-
|
|
23474
|
-
|
|
23475
|
-
|
|
23476
|
-
|
|
23477
|
-
|
|
23478
|
-
|
|
23479
|
-
|
|
23480
|
-
|
|
23481
|
-
|
|
23482
|
-
|
|
23483
|
-
|
|
23484
|
-
|
|
23485
|
-
|
|
23486
|
-
|
|
23487
|
-
|
|
23488
|
-
|
|
23489
|
-
|
|
23490
|
-
|
|
23491
|
-
|
|
23492
|
-
|
|
23493
|
-
|
|
23494
|
-
|
|
23495
|
-
|
|
23496
|
-
|
|
23470
|
+
// ---- state -----------------------------------------------------------------
|
|
23471
|
+
const blank = () => ({ chosen: null, flagged: [], later: false });
|
|
23472
|
+
const group = (key) => GROUPS.find((g) => g.key === key);
|
|
23473
|
+
const st = (key) => state[key] || (state[key] = blank());
|
|
23474
|
+
function statusOf(g) {
|
|
23475
|
+
if (rerolls[g.key] && rerolls[g.key].state === 'running') return 'rerolling';
|
|
23476
|
+
const s = st(g.key);
|
|
23477
|
+
if (s.chosen !== null) return 'accepted';
|
|
23478
|
+
if (s.flagged.length) return 'flagged';
|
|
23479
|
+
if (s.later) return 'later';
|
|
23480
|
+
return 'undecided';
|
|
23481
|
+
}
|
|
23482
|
+
function inFilter(g) {
|
|
23483
|
+
const s = statusOf(g);
|
|
23484
|
+
return filter === 'all' || s === filter || (filter === 'undecided' && s === 'rerolling');
|
|
23485
|
+
}
|
|
23486
|
+
const visible = () => GROUPS.filter(inFilter);
|
|
23487
|
+
const isSet = (g) => g.mode === 'frame-set';
|
|
23488
|
+
const startIndex = (g) => (g.recommendedIndex != null && g.recommendedIndex < g.frameUrls.length ? g.recommendedIndex : 0);
|
|
23489
|
+
const cur = (g) => (cursor[g.key] != null ? cursor[g.key] : (cursor[g.key] = startIndex(g)));
|
|
23490
|
+
|
|
23491
|
+
function localKey(g) { return STORE + g.reviewObjectId + ':' + g.key; }
|
|
23492
|
+
function remember(g) {
|
|
23493
|
+
try { localStorage.setItem(localKey(g), JSON.stringify(st(g.key))); } catch (e) { /* private mode */ }
|
|
23494
|
+
}
|
|
23495
|
+
function recall(g) {
|
|
23496
|
+
try {
|
|
23497
|
+
const raw = localStorage.getItem(localKey(g));
|
|
23498
|
+
if (raw) state[g.key] = Object.assign(blank(), JSON.parse(raw));
|
|
23499
|
+
} catch (e) { /* ignore */ }
|
|
23500
|
+
}
|
|
23501
|
+
|
|
23502
|
+
const pending = new Map();
|
|
23503
|
+
function save(g) {
|
|
23504
|
+
remember(g);
|
|
23505
|
+
if (!CONFIG.stateUrl) return;
|
|
23506
|
+
clearTimeout(pending.get(g.key));
|
|
23507
|
+
pending.set(g.key, setTimeout(async () => {
|
|
23508
|
+
pending.delete(g.key);
|
|
23509
|
+
try {
|
|
23510
|
+
const res = await fetch(CONFIG.stateUrl, {
|
|
23511
|
+
method: 'POST',
|
|
23512
|
+
headers: Object.assign({ 'Content-Type': 'application/json' }, CONFIG.headers),
|
|
23513
|
+
body: JSON.stringify(Object.assign({ key: g.key }, st(g.key))),
|
|
23514
|
+
});
|
|
23515
|
+
if (!res.ok) throw new Error(await res.text());
|
|
23516
|
+
} catch (err) {
|
|
23517
|
+
say('Could not save ' + g.assetId + ': ' + err.message + '. It is kept in this browser.', true);
|
|
23497
23518
|
}
|
|
23519
|
+
}, 200));
|
|
23520
|
+
}
|
|
23498
23521
|
|
|
23499
|
-
|
|
23500
|
-
|
|
23501
|
-
|
|
23502
|
-
|
|
23503
|
-
|
|
23504
|
-
|
|
23505
|
-
|
|
23506
|
-
|
|
23507
|
-
c.onmouseenter = () => activate(i, frames);
|
|
23508
|
-
frames.appendChild(c);
|
|
23509
|
-
});
|
|
23510
|
-
frames.dataset.active = '0';
|
|
23511
|
-
frames.querySelector('.cand')?.classList.add('active');
|
|
23512
|
-
if (recommended > 0) activate(recommended, frames);
|
|
23513
|
-
root.appendChild(el);
|
|
23514
|
-
});
|
|
23522
|
+
// ---- rendering: list -------------------------------------------------------
|
|
23523
|
+
const list = $('list');
|
|
23524
|
+
const rows = new Map();
|
|
23525
|
+
const thumbsOnScreen = new Set();
|
|
23526
|
+
const io = 'IntersectionObserver' in window ? new IntersectionObserver((entries) => {
|
|
23527
|
+
for (const e of entries) (e.isIntersecting ? thumbsOnScreen.add(e.target.dataset.key) : thumbsOnScreen.delete(e.target.dataset.key));
|
|
23528
|
+
dirty = true;
|
|
23529
|
+
}, { root: list }) : null;
|
|
23515
23530
|
|
|
23516
|
-
function
|
|
23517
|
-
const
|
|
23518
|
-
|
|
23519
|
-
|
|
23520
|
-
|
|
23521
|
-
|
|
23522
|
-
|
|
23523
|
-
|
|
23524
|
-
return
|
|
23531
|
+
function stateLabel(g) {
|
|
23532
|
+
const s = statusOf(g);
|
|
23533
|
+
const st0 = st(g.key);
|
|
23534
|
+
if (s === 'accepted') return isSet(g) ? 'Accepted' : 'Accepted ' + (st0.chosen + 1);
|
|
23535
|
+
if (s === 'flagged') return st0.flagged.length + ' flagged';
|
|
23536
|
+
if (s === 'later') return 'Later';
|
|
23537
|
+
if (s === 'rerolling') return 'Rerolling';
|
|
23538
|
+
if (rerolls[g.key] && rerolls[g.key].state === 'failed') return 'Reroll failed';
|
|
23539
|
+
return '';
|
|
23525
23540
|
}
|
|
23526
23541
|
|
|
23527
|
-
function
|
|
23528
|
-
|
|
23529
|
-
|
|
23530
|
-
|
|
23531
|
-
|
|
23532
|
-
|
|
23533
|
-
|
|
23542
|
+
function buildList() {
|
|
23543
|
+
list.textContent = '';
|
|
23544
|
+
rows.clear();
|
|
23545
|
+
if (io) io.disconnect();
|
|
23546
|
+
thumbsOnScreen.clear();
|
|
23547
|
+
const shown = visible();
|
|
23548
|
+
if (!shown.length) {
|
|
23549
|
+
const p = document.createElement('p');
|
|
23550
|
+
p.className = 'empty';
|
|
23551
|
+
p.textContent = filter === 'all' ? 'Nothing is waiting for review.' : 'No assets are ' + filter + '. Press 1 to show all.';
|
|
23552
|
+
list.append(p);
|
|
23534
23553
|
return;
|
|
23535
23554
|
}
|
|
23536
|
-
const
|
|
23537
|
-
|
|
23538
|
-
|
|
23539
|
-
|
|
23540
|
-
|
|
23555
|
+
for (const g of shown) {
|
|
23556
|
+
const row = document.createElement('button');
|
|
23557
|
+
row.type = 'button';
|
|
23558
|
+
row.className = 'row';
|
|
23559
|
+
row.id = 'row-' + GROUPS.indexOf(g);
|
|
23560
|
+
row.setAttribute('role', 'option');
|
|
23561
|
+
row.tabIndex = -1;
|
|
23562
|
+
row.dataset.key = g.key;
|
|
23563
|
+
const thumb = document.createElement('span');
|
|
23564
|
+
thumb.className = 'thumb';
|
|
23565
|
+
const c = document.createElement('canvas');
|
|
23566
|
+
c.width = c.height = 0;
|
|
23567
|
+
thumb.append(c);
|
|
23568
|
+
const text = document.createElement('span');
|
|
23569
|
+
text.style.minWidth = '0';
|
|
23570
|
+
const name = document.createElement('span');
|
|
23571
|
+
name.className = 'name';
|
|
23572
|
+
name.textContent = decode(g.assetId);
|
|
23573
|
+
const meta = document.createElement('span');
|
|
23574
|
+
meta.className = 'meta num';
|
|
23575
|
+
meta.textContent = decode(g.styleId) + ', ' + g.frameUrls.length + (isSet(g) ? ' frames' : g.frameUrls.length === 1 ? ' candidate' : ' candidates');
|
|
23576
|
+
text.append(name, meta);
|
|
23577
|
+
const label = document.createElement('span');
|
|
23578
|
+
label.className = 'state';
|
|
23579
|
+
row.append(thumb, text, label);
|
|
23580
|
+
row.addEventListener('click', () => { select(g.key); row.blur(); list.focus({ preventScroll: true }); });
|
|
23581
|
+
list.append(row);
|
|
23582
|
+
rows.set(g.key, { row, canvas: c, label, drawn: -1 });
|
|
23583
|
+
if (io) io.observe(row); else thumbsOnScreen.add(g.key);
|
|
23584
|
+
}
|
|
23585
|
+
refreshRows();
|
|
23586
|
+
}
|
|
23587
|
+
function refreshRows() {
|
|
23588
|
+
for (const [key, r] of rows) {
|
|
23589
|
+
const g = group(key);
|
|
23590
|
+
if (!g) continue;
|
|
23591
|
+
r.label.textContent = stateLabel(g);
|
|
23592
|
+
r.label.className = 'state ' + statusOf(g);
|
|
23593
|
+
r.row.setAttribute('aria-selected', String(key === currentKey));
|
|
23594
|
+
r.row.setAttribute('aria-label', decode(g.assetId) + ' in ' + decode(g.styleId) + (stateLabel(g) ? ', ' + stateLabel(g) : ', undecided'));
|
|
23595
|
+
}
|
|
23596
|
+
const active = rows.get(currentKey);
|
|
23597
|
+
if (active) list.setAttribute('aria-activedescendant', active.row.id);
|
|
23541
23598
|
}
|
|
23542
|
-
|
|
23543
|
-
|
|
23544
|
-
|
|
23599
|
+
|
|
23600
|
+
// Prompts arrive HTML-escaped; textContent wants them plain.
|
|
23601
|
+
const decoder = document.createElement('textarea');
|
|
23602
|
+
function decode(s) { decoder.innerHTML = s; return decoder.value; }
|
|
23603
|
+
|
|
23604
|
+
// ---- rendering: header -----------------------------------------------------
|
|
23605
|
+
function buildFilters() {
|
|
23606
|
+
const nav = $('filters');
|
|
23607
|
+
nav.textContent = '';
|
|
23608
|
+
FILTERS.forEach(([id, label], i) => {
|
|
23609
|
+
const b = document.createElement('button');
|
|
23610
|
+
b.type = 'button';
|
|
23611
|
+
b.dataset.filter = id;
|
|
23612
|
+
b.title = label + ' (' + (i + 1) + ')';
|
|
23613
|
+
b.addEventListener('click', () => { setFilter(id); b.blur(); });
|
|
23614
|
+
nav.append(b);
|
|
23615
|
+
});
|
|
23616
|
+
}
|
|
23617
|
+
function refreshHeader() {
|
|
23618
|
+
const counts = { all: GROUPS.length, undecided: 0, accepted: 0, flagged: 0, later: 0 };
|
|
23619
|
+
for (const g of GROUPS) {
|
|
23620
|
+
const s = statusOf(g);
|
|
23621
|
+
counts[s === 'rerolling' ? 'undecided' : s]++;
|
|
23622
|
+
}
|
|
23623
|
+
$('counter').innerHTML = '<b>' + counts.accepted + '</b> of ' + GROUPS.length + ' accepted' +
|
|
23624
|
+
(counts.flagged ? ', ' + counts.flagged + ' flagged' : '');
|
|
23625
|
+
for (const b of $('filters').children) {
|
|
23626
|
+
const id = b.dataset.filter;
|
|
23627
|
+
b.setAttribute('aria-pressed', String(id === filter));
|
|
23628
|
+
b.innerHTML = '';
|
|
23629
|
+
b.append(FILTERS.find((f) => f[0] === id)[1]);
|
|
23630
|
+
const n = document.createElement('span');
|
|
23631
|
+
n.className = 'n num';
|
|
23632
|
+
n.textContent = counts[id];
|
|
23633
|
+
b.append(n);
|
|
23634
|
+
}
|
|
23635
|
+
const running = Object.values(rerolls).some((r) => r.state === 'running');
|
|
23636
|
+
const apply = $('apply');
|
|
23637
|
+
apply.disabled = applying || counts.accepted === 0 || running;
|
|
23638
|
+
apply.textContent = counts.accepted ? 'Apply ' + counts.accepted : 'Apply';
|
|
23639
|
+
apply.title = running ? 'Wait for the reroll to finish' : 'Commit the accepted assets (Ctrl or Cmd+Enter)';
|
|
23545
23640
|
}
|
|
23546
|
-
document.addEventListener('keydown', e => {
|
|
23547
|
-
const g = document.activeElement?.closest?.('.group');
|
|
23548
|
-
if (!g) return;
|
|
23549
|
-
const gi = Number(g.dataset.gi);
|
|
23550
|
-
const frames = g.querySelector('.frames');
|
|
23551
|
-
const candidates = [...frames.querySelectorAll('.cand')];
|
|
23552
|
-
const active = Number(frames.dataset.active || 0);
|
|
23553
|
-
let advance = false;
|
|
23554
23641
|
|
|
23555
|
-
|
|
23556
|
-
|
|
23557
|
-
|
|
23558
|
-
|
|
23559
|
-
|
|
23560
|
-
|
|
23561
|
-
|
|
23562
|
-
|
|
23563
|
-
|
|
23564
|
-
|
|
23565
|
-
|
|
23566
|
-
|
|
23567
|
-
|
|
23568
|
-
|
|
23569
|
-
|
|
23570
|
-
|
|
23571
|
-
|
|
23572
|
-
|
|
23573
|
-
|
|
23574
|
-
|
|
23575
|
-
|
|
23576
|
-
|
|
23577
|
-
|
|
23578
|
-
|
|
23642
|
+
// ---- rendering: stage ------------------------------------------------------
|
|
23643
|
+
const canvas = $('s-canvas');
|
|
23644
|
+
const ctx = canvas.getContext('2d');
|
|
23645
|
+
let dirty = true;
|
|
23646
|
+
|
|
23647
|
+
function views(g) {
|
|
23648
|
+
const out = [{ label: isSet(g) ? 'Candidate' : 'Candidate', kind: 'candidate' }];
|
|
23649
|
+
if (g.current) out.push({ label: 'Current art', kind: 'current', url: g.current.url });
|
|
23650
|
+
if (g.revision) out.push({ label: 'Revision source', kind: 'source', url: g.revision.sourceUrl });
|
|
23651
|
+
return out;
|
|
23652
|
+
}
|
|
23653
|
+
function frameSize(g, i) {
|
|
23654
|
+
const known = g.frameSizes && g.frameSizes[i];
|
|
23655
|
+
if (known) return known;
|
|
23656
|
+
const e = image(g.frameUrls[i]);
|
|
23657
|
+
if (e.ready) return { width: e.img.naturalWidth, height: e.img.naturalHeight };
|
|
23658
|
+
return { width: g.width, height: g.height };
|
|
23659
|
+
}
|
|
23660
|
+
// The largest whole-number zoom that fits; below 1x the frame is fitted and
|
|
23661
|
+
// labelled so, never stretched.
|
|
23662
|
+
function fitScale(w, h, boxW, boxH) {
|
|
23663
|
+
const s = Math.min(boxW / w, boxH / h);
|
|
23664
|
+
return s >= 1 ? Math.min(32, Math.floor(s)) : s;
|
|
23665
|
+
}
|
|
23666
|
+
|
|
23667
|
+
let clock = 0, lastTick = 0;
|
|
23668
|
+
function playIndex(g) {
|
|
23669
|
+
const n = g.frameUrls.length;
|
|
23670
|
+
if (n < 2) return 0;
|
|
23671
|
+
const step = Math.floor(clock * (g.fps || 12) / 1000);
|
|
23672
|
+
if (!pingpong) return step % n;
|
|
23673
|
+
const period = 2 * n - 2;
|
|
23674
|
+
const k = step % period;
|
|
23675
|
+
return k < n ? k : period - k;
|
|
23676
|
+
}
|
|
23677
|
+
// What the stage shows right now: frame sets play, candidates hold the cursor.
|
|
23678
|
+
function stageIndex(g) {
|
|
23679
|
+
return isSet(g) && playing ? playIndex(g) : cur(g);
|
|
23680
|
+
}
|
|
23681
|
+
|
|
23682
|
+
function drawStage() {
|
|
23683
|
+
const g = group(currentKey);
|
|
23684
|
+
const view = $('view');
|
|
23685
|
+
if (!g) { canvas.width = canvas.height = 0; return; }
|
|
23686
|
+
const vs = views(g);
|
|
23687
|
+
const mode = vs[flipped % vs.length];
|
|
23688
|
+
view.classList.toggle('flipped', mode.kind !== 'candidate');
|
|
23689
|
+
const box = view.getBoundingClientRect();
|
|
23690
|
+
const i = stageIndex(g);
|
|
23691
|
+
const size = frameSize(g, i);
|
|
23692
|
+
const scale = fitScale(size.width, size.height, Math.max(1, box.width - 48), Math.max(1, box.height - 72));
|
|
23693
|
+
const w = Math.max(1, Math.round(size.width * scale)), h = Math.max(1, Math.round(size.height * scale));
|
|
23694
|
+
if (canvas.width !== w || canvas.height !== h) { canvas.width = w; canvas.height = h; }
|
|
23695
|
+
ctx.imageSmoothingEnabled = scale < 1;
|
|
23696
|
+
ctx.clearRect(0, 0, w, h);
|
|
23697
|
+
const draw = (url, alpha) => {
|
|
23698
|
+
const e = image(url);
|
|
23699
|
+
if (!e.ready) return false;
|
|
23700
|
+
ctx.globalAlpha = alpha;
|
|
23701
|
+
// Same scale as the candidate, so a comparison is pixel for pixel.
|
|
23702
|
+
ctx.drawImage(e.img, 0, 0, e.img.naturalWidth * scale, e.img.naturalHeight * scale);
|
|
23703
|
+
ctx.globalAlpha = 1;
|
|
23704
|
+
return true;
|
|
23705
|
+
};
|
|
23706
|
+
let notice = '';
|
|
23707
|
+
if (mode.kind === 'candidate') {
|
|
23708
|
+
if (onion && g.frameUrls.length > 1) {
|
|
23709
|
+
const prev = (i - 1 + g.frameUrls.length) % g.frameUrls.length;
|
|
23710
|
+
draw(g.frameUrls[prev], 0.3);
|
|
23711
|
+
}
|
|
23712
|
+
const e = image(g.frameUrls[i]);
|
|
23713
|
+
if (e.failed) notice = 'This frame did not load. Reroll the asset or check the run log.';
|
|
23714
|
+
else if (!draw(g.frameUrls[i], 1)) notice = 'Loading…';
|
|
23715
|
+
} else {
|
|
23716
|
+
const e = image(mode.url);
|
|
23717
|
+
if (e.failed) notice = 'The ' + mode.label.toLowerCase() + ' did not load.';
|
|
23718
|
+
else draw(mode.url, 1);
|
|
23719
|
+
}
|
|
23720
|
+
const n = g.frameUrls.length;
|
|
23721
|
+
const s = st(g.key);
|
|
23722
|
+
let tag = '<b>' + mode.label + '</b>';
|
|
23723
|
+
if (mode.kind === 'candidate') {
|
|
23724
|
+
tag += isSet(g)
|
|
23725
|
+
? ', frame ' + (i + 1) + ' of ' + n + ', ' + (g.fps || 12) + ' fps'
|
|
23726
|
+
: ', ' + (i + 1) + ' of ' + n + (g.recommendedIndex === i ? ' (declared slot)' : '');
|
|
23727
|
+
if (s.flagged.includes(i)) tag += ', flagged';
|
|
23728
|
+
if (!isSet(g) && s.chosen === i) tag += ', accepted';
|
|
23579
23729
|
} else {
|
|
23730
|
+
tag += ' at the candidate’s scale';
|
|
23731
|
+
}
|
|
23732
|
+
$('s-tag').innerHTML = tag;
|
|
23733
|
+
$('s-scale').textContent = size.width + '×' + size.height + ', ' + (scale >= 1 ? scale + '×' : 'fitted');
|
|
23734
|
+
$('s-notice').textContent = notice;
|
|
23735
|
+
}
|
|
23736
|
+
|
|
23737
|
+
function buildStage() {
|
|
23738
|
+
const g = group(currentKey);
|
|
23739
|
+
const has = Boolean(g);
|
|
23740
|
+
for (const id of ['a-accept', 'a-flag', 'a-later', 'a-reroll', 't-play', 't-flip', 't-strip', 't-onion', 't-pong']) $(id).disabled = !has;
|
|
23741
|
+
if (!g) {
|
|
23742
|
+
$('s-name').textContent = 'Nothing selected';
|
|
23743
|
+
$('s-key').textContent = '';
|
|
23744
|
+
$('s-pos').textContent = '';
|
|
23745
|
+
$('s-prompt').textContent = visible().length ? '' : 'Change the filter to see more assets.';
|
|
23746
|
+
$('strip').hidden = true;
|
|
23747
|
+
dirty = true;
|
|
23580
23748
|
return;
|
|
23581
23749
|
}
|
|
23582
|
-
|
|
23583
|
-
|
|
23584
|
-
|
|
23750
|
+
const shown = visible();
|
|
23751
|
+
$('s-name').textContent = decode(g.assetId);
|
|
23752
|
+
$('s-key').textContent = decode(g.styleId) + '/' + decode(g.assetId);
|
|
23753
|
+
const pos = shown.indexOf(g);
|
|
23754
|
+
$('s-pos').textContent = (pos >= 0 ? pos + 1 : '–') + ' of ' + shown.length;
|
|
23755
|
+
$('s-prompt').textContent = decode(g.prompt);
|
|
23756
|
+
// Warm this asset's frames and the next one's: still one request each.
|
|
23757
|
+
g.frameUrls.forEach(image);
|
|
23758
|
+
const after = shown[pos + 1];
|
|
23759
|
+
if (after) after.frameUrls.forEach(image);
|
|
23760
|
+
const vs = views(g);
|
|
23761
|
+
$('t-flip').disabled = vs.length < 2;
|
|
23762
|
+
const next = vs[(flipped + 1) % vs.length];
|
|
23763
|
+
$('t-flip').firstChild.textContent = vs.length < 2 ? 'No current art' : flipped % vs.length ? 'Show candidate' : 'Show ' + next.label.toLowerCase();
|
|
23764
|
+
$('t-flip').setAttribute('aria-pressed', String(flipped % vs.length !== 0));
|
|
23765
|
+
$('t-play').firstChild.textContent = playing ? 'Pause' : 'Play';
|
|
23766
|
+
$('t-play').setAttribute('aria-pressed', String(!playing));
|
|
23767
|
+
$('t-strip').setAttribute('aria-pressed', String(showStrip));
|
|
23768
|
+
$('t-onion').setAttribute('aria-pressed', String(onion));
|
|
23769
|
+
$('t-pong').setAttribute('aria-pressed', String(pingpong));
|
|
23770
|
+
$('t-onion').disabled = $('t-pong').disabled = g.frameUrls.length < 2;
|
|
23771
|
+
if (!isSet(g)) $('t-pong').disabled = true;
|
|
23772
|
+
|
|
23773
|
+
const s = st(g.key);
|
|
23774
|
+
const status = statusOf(g);
|
|
23775
|
+
const accept = $('a-accept');
|
|
23776
|
+
accept.className = 'act' + (s.chosen !== null ? ' on' : '');
|
|
23777
|
+
accept.firstChild.textContent = s.chosen !== null ? 'Accepted' : isSet(g) ? 'Accept set' : 'Accept ' + (cur(g) + 1);
|
|
23778
|
+
accept.setAttribute('aria-label', s.chosen !== null ? 'Accepted; press to undo' : isSet(g) ? 'Accept ordered frame set' : 'Choose candidate ' + (cur(g) + 1) + ' of ' + g.frameUrls.length);
|
|
23779
|
+
accept.disabled = status === 'rerolling';
|
|
23780
|
+
const flag = $('a-flag');
|
|
23781
|
+
const flaggedHere = s.flagged.includes(cur(g));
|
|
23782
|
+
flag.className = 'act' + (flaggedHere ? ' warn' : '');
|
|
23783
|
+
flag.firstChild.textContent = flaggedHere && !(isSet(g) && playing) ? 'Unflag ' + (cur(g) + 1) : isSet(g) ? (playing ? 'Flag this frame' : 'Flag frame ' + (cur(g) + 1)) : 'Flag ' + (cur(g) + 1);
|
|
23784
|
+
$('a-later').className = 'act' + (s.later ? ' on' : '');
|
|
23785
|
+
const reroll = $('a-reroll');
|
|
23786
|
+
reroll.hidden = !canReroll;
|
|
23787
|
+
const r = rerolls[g.key];
|
|
23788
|
+
reroll.disabled = status === 'rerolling';
|
|
23789
|
+
reroll.className = 'act' + (armedReroll === g.key ? ' warn' : '');
|
|
23790
|
+
reroll.firstChild.textContent = status === 'rerolling' ? 'Rerolling…' : armedReroll === g.key ? 'Press R again to spend' : 'Reroll';
|
|
23791
|
+
if (r && r.state === 'failed') say('Reroll of ' + g.assetId + ' failed: ' + r.error, true);
|
|
23792
|
+
buildStrip(g);
|
|
23793
|
+
dirty = true;
|
|
23794
|
+
}
|
|
23795
|
+
|
|
23796
|
+
function buildStrip(g) {
|
|
23797
|
+
const strip = $('strip');
|
|
23798
|
+
strip.hidden = !showStrip;
|
|
23799
|
+
if (!showStrip) return;
|
|
23800
|
+
strip.textContent = '';
|
|
23801
|
+
const s = st(g.key);
|
|
23802
|
+
g.frameUrls.forEach((url, i) => {
|
|
23803
|
+
const cell = document.createElement('button');
|
|
23804
|
+
cell.type = 'button';
|
|
23805
|
+
cell.className = 'cell' + (s.flagged.includes(i) ? ' flag' : '') +
|
|
23806
|
+
((isSet(g) ? s.chosen !== null : s.chosen === i) ? ' chosen' : '');
|
|
23807
|
+
cell.setAttribute('role', 'option');
|
|
23808
|
+
cell.setAttribute('aria-current', String(i === cur(g)));
|
|
23809
|
+
cell.setAttribute('aria-label', (isSet(g) ? 'Frame ' : 'Candidate ') + (i + 1) + (s.flagged.includes(i) ? ', flagged' : ''));
|
|
23810
|
+
cell.tabIndex = -1;
|
|
23811
|
+
const pic = document.createElement('span');
|
|
23812
|
+
pic.className = 'pic';
|
|
23813
|
+
const c = document.createElement('canvas');
|
|
23814
|
+
c.width = c.height = 0;
|
|
23815
|
+
pic.append(c);
|
|
23816
|
+
const lab = document.createElement('span');
|
|
23817
|
+
lab.className = 'lab num';
|
|
23818
|
+
lab.textContent = String(i + 1) + (s.flagged.includes(i) ? ' flagged' : '');
|
|
23819
|
+
cell.append(pic, lab);
|
|
23820
|
+
cell.addEventListener('click', () => { setCursor(g, i); cell.blur(); });
|
|
23821
|
+
strip.append(cell);
|
|
23822
|
+
const paint = () => {
|
|
23823
|
+
const e = image(url);
|
|
23824
|
+
if (!e.ready) return;
|
|
23825
|
+
const w = e.img.naturalWidth, h = e.img.naturalHeight;
|
|
23826
|
+
const k = fitScale(w, h, 96, 72);
|
|
23827
|
+
c.width = Math.max(1, Math.round(w * k)); c.height = Math.max(1, Math.round(h * k));
|
|
23828
|
+
const x = c.getContext('2d');
|
|
23829
|
+
x.imageSmoothingEnabled = k < 1;
|
|
23830
|
+
x.drawImage(e.img, 0, 0, c.width, c.height);
|
|
23831
|
+
};
|
|
23832
|
+
const e = image(url);
|
|
23833
|
+
if (e.ready) paint(); else e.img.addEventListener('load', paint, { once: true });
|
|
23834
|
+
});
|
|
23835
|
+
const active = strip.children[cur(g)];
|
|
23836
|
+
if (active) active.scrollIntoView({ block: 'nearest', inline: 'nearest' });
|
|
23837
|
+
}
|
|
23838
|
+
|
|
23839
|
+
function drawThumbs() {
|
|
23840
|
+
for (const key of thumbsOnScreen) {
|
|
23841
|
+
const r = rows.get(key);
|
|
23842
|
+
const g = group(key);
|
|
23843
|
+
if (!r || !g) continue;
|
|
23844
|
+
const s = st(key);
|
|
23845
|
+
const i = isSet(g) ? (playing ? playIndex(g) : 0) : (s.chosen !== null ? s.chosen : cur(g));
|
|
23846
|
+
const e = image(g.frameUrls[i]);
|
|
23847
|
+
if (!e.ready) continue;
|
|
23848
|
+
if (r.drawn === i && r.canvas.width) continue;
|
|
23849
|
+
const w = e.img.naturalWidth, h = e.img.naturalHeight;
|
|
23850
|
+
const k = fitScale(w, h, 40, 40);
|
|
23851
|
+
const cw = Math.max(1, Math.round(w * k)), ch = Math.max(1, Math.round(h * k));
|
|
23852
|
+
if (r.canvas.width !== cw || r.canvas.height !== ch) { r.canvas.width = cw; r.canvas.height = ch; }
|
|
23853
|
+
const x = r.canvas.getContext('2d');
|
|
23854
|
+
x.imageSmoothingEnabled = k < 1;
|
|
23855
|
+
x.clearRect(0, 0, cw, ch);
|
|
23856
|
+
x.drawImage(e.img, 0, 0, cw, ch);
|
|
23857
|
+
r.drawn = i;
|
|
23585
23858
|
}
|
|
23586
|
-
|
|
23587
|
-
});
|
|
23859
|
+
}
|
|
23588
23860
|
|
|
23589
|
-
|
|
23590
|
-
|
|
23591
|
-
|
|
23592
|
-
|
|
23593
|
-
|
|
23594
|
-
const
|
|
23861
|
+
// One clock for the page: thumbnails and stage advance together, and stop
|
|
23862
|
+
// when the tab is hidden.
|
|
23863
|
+
function tick(t) {
|
|
23864
|
+
if (playing && lastTick) clock += t - lastTick;
|
|
23865
|
+
lastTick = t;
|
|
23866
|
+
const g = group(currentKey);
|
|
23867
|
+
const before = tick.last;
|
|
23868
|
+
const now = g ? stageIndex(g) + ':' + flipped + ':' + onion : '';
|
|
23869
|
+
if (dirty || now !== before) { drawStage(); tick.last = now; dirty = false; }
|
|
23870
|
+
drawThumbs();
|
|
23871
|
+
requestAnimationFrame(tick);
|
|
23872
|
+
}
|
|
23873
|
+
|
|
23874
|
+
// ---- actions ---------------------------------------------------------------
|
|
23875
|
+
function say(text, error) {
|
|
23876
|
+
const s = $('status');
|
|
23877
|
+
s.textContent = text;
|
|
23878
|
+
s.title = text;
|
|
23879
|
+
s.className = error ? 'error' : '';
|
|
23880
|
+
}
|
|
23881
|
+
function refresh() { refreshRows(); refreshHeader(); buildStage(); }
|
|
23882
|
+
|
|
23883
|
+
function select(key, scroll) {
|
|
23884
|
+
currentKey = key;
|
|
23885
|
+
flipped = 0;
|
|
23886
|
+
if (armedReroll && armedReroll !== key) armedReroll = null;
|
|
23887
|
+
refresh();
|
|
23888
|
+
const r = rows.get(key);
|
|
23889
|
+
if (r && scroll !== false) r.row.scrollIntoView({ block: 'nearest' });
|
|
23890
|
+
}
|
|
23891
|
+
function move(delta) {
|
|
23892
|
+
const shown = visible();
|
|
23893
|
+
if (!shown.length) return;
|
|
23894
|
+
const at = shown.findIndex((g) => g.key === currentKey);
|
|
23895
|
+
const next = at < 0 ? 0 : Math.max(0, Math.min(shown.length - 1, at + delta));
|
|
23896
|
+
select(shown[next].key);
|
|
23897
|
+
}
|
|
23898
|
+
function advance() {
|
|
23899
|
+
// After a decision, go to the next asset still waiting in this view.
|
|
23900
|
+
const shown = visible();
|
|
23901
|
+
const at = GROUPS.findIndex((g) => g.key === currentKey);
|
|
23902
|
+
const after = GROUPS.slice(at + 1).concat(GROUPS.slice(0, at + 1));
|
|
23903
|
+
const next = after.find((g) => inFilter(g) && statusOf(g) === 'undecided');
|
|
23904
|
+
if (filter !== 'all' && !inFilter(group(currentKey))) { buildList(); }
|
|
23905
|
+
if (next) select(next.key); else if (shown.length) refresh(); else { buildList(); select(visible()[0] ? visible()[0].key : null); }
|
|
23906
|
+
}
|
|
23907
|
+
// Pausing holds the frame on screen, so the arrows step from there.
|
|
23908
|
+
function togglePlay() {
|
|
23909
|
+
const g = group(currentKey);
|
|
23910
|
+
if (playing && g && isSet(g)) cursor[g.key] = playIndex(g);
|
|
23911
|
+
playing = !playing;
|
|
23912
|
+
buildStage();
|
|
23913
|
+
}
|
|
23914
|
+
function setCursor(g, i) {
|
|
23915
|
+
const n = g.frameUrls.length;
|
|
23916
|
+
cursor[g.key] = ((i % n) + n) % n;
|
|
23917
|
+
if (isSet(g)) playing = false;
|
|
23918
|
+
if (!isSet(g) && rows.get(g.key)) rows.get(g.key).drawn = -1;
|
|
23919
|
+
buildStage();
|
|
23920
|
+
refreshHeader();
|
|
23921
|
+
}
|
|
23922
|
+
function changed(g) { save(g); if (!inFilter(g)) buildList(); refresh(); }
|
|
23923
|
+
|
|
23924
|
+
function accept() {
|
|
23925
|
+
const g = group(currentKey);
|
|
23926
|
+
if (!g || statusOf(g) === 'rerolling') return;
|
|
23927
|
+
const s = st(g.key);
|
|
23928
|
+
const index = isSet(g) ? 0 : cur(g);
|
|
23929
|
+
if (s.chosen === index) { s.chosen = null; changed(g); return; }
|
|
23930
|
+
s.chosen = index;
|
|
23931
|
+
s.later = false;
|
|
23932
|
+
save(g);
|
|
23933
|
+
if (rows.get(g.key)) rows.get(g.key).drawn = -1;
|
|
23934
|
+
advance();
|
|
23935
|
+
}
|
|
23936
|
+
function flag() {
|
|
23937
|
+
const g = group(currentKey);
|
|
23938
|
+
if (!g) return;
|
|
23939
|
+
// A playing set flags the frame on screen, and holds it there.
|
|
23940
|
+
if (isSet(g) && playing) { cursor[g.key] = playIndex(g); playing = false; }
|
|
23941
|
+
const s = st(g.key);
|
|
23942
|
+
const i = cur(g);
|
|
23943
|
+
s.flagged =s.flagged.includes(i) ? s.flagged.filter((n) => n !== i) : s.flagged.concat(i).sort((a, b) => a - b);
|
|
23944
|
+
// A set with a bad frame is not accepted; a flagged candidate cannot be the choice.
|
|
23945
|
+
if (s.flagged.length && (isSet(g) || s.chosen === i)) s.chosen = null;
|
|
23946
|
+
changed(g);
|
|
23947
|
+
}
|
|
23948
|
+
function later() {
|
|
23949
|
+
const g = group(currentKey);
|
|
23950
|
+
if (!g) return;
|
|
23951
|
+
const s = st(g.key);
|
|
23952
|
+
s.later = !s.later;
|
|
23953
|
+
if (s.later) { s.chosen = null; save(g); advance(); } else changed(g);
|
|
23954
|
+
}
|
|
23955
|
+
async function reroll() {
|
|
23956
|
+
const g = group(currentKey);
|
|
23957
|
+
if (!g || !canReroll || statusOf(g) === 'rerolling') return;
|
|
23958
|
+
if (armedReroll !== g.key) {
|
|
23959
|
+
armedReroll = g.key;
|
|
23960
|
+
clearTimeout(armedTimer);
|
|
23961
|
+
armedTimer = setTimeout(() => { armedReroll = null; buildStage(); }, 4000);
|
|
23962
|
+
say('Rerolling spends credits. Press R again to regenerate ' + decode(g.assetId) + '.');
|
|
23963
|
+
buildStage();
|
|
23964
|
+
return;
|
|
23965
|
+
}
|
|
23966
|
+
armedReroll = null;
|
|
23967
|
+
clearTimeout(armedTimer);
|
|
23595
23968
|
try {
|
|
23596
|
-
const res = await fetch(
|
|
23597
|
-
method: 'POST',
|
|
23969
|
+
const res = await fetch(CONFIG.rerollUrl, {
|
|
23970
|
+
method: 'POST',
|
|
23971
|
+
headers: Object.assign({ 'Content-Type': 'application/json' }, CONFIG.headers),
|
|
23972
|
+
body: JSON.stringify({ key: g.key }),
|
|
23973
|
+
});
|
|
23974
|
+
if (!res.ok) throw new Error(await res.text());
|
|
23975
|
+
rerolls[g.key] = { state: 'running' };
|
|
23976
|
+
say('Rerolling ' + decode(g.assetId) + '. Keep reviewing; it comes back here when ready.');
|
|
23977
|
+
refresh();
|
|
23978
|
+
watch();
|
|
23979
|
+
} catch (err) {
|
|
23980
|
+
say('Reroll failed: ' + err.message, true);
|
|
23981
|
+
}
|
|
23982
|
+
}
|
|
23983
|
+
function batch(kind) {
|
|
23984
|
+
const shown = kind === 'select' ? visible() : GROUPS;
|
|
23985
|
+
let n = 0;
|
|
23986
|
+
for (const g of shown) {
|
|
23987
|
+
if (statusOf(g) === 'rerolling') continue;
|
|
23988
|
+
const s = st(g.key);
|
|
23989
|
+
if (kind === 'deselect') { if (s.chosen !== null) { s.chosen = null; save(g); n++; } continue; }
|
|
23990
|
+
if (s.chosen !== null) continue;
|
|
23991
|
+
if (kind === 'unflagged' && (s.flagged.length || s.later)) continue;
|
|
23992
|
+
if (isSet(g) && s.flagged.length) continue;
|
|
23993
|
+
const index = isSet(g) ? 0 : (s.flagged.includes(cur(g)) ? -1 : cur(g));
|
|
23994
|
+
if (index < 0) continue;
|
|
23995
|
+
s.chosen = index; s.later = false; save(g); n++;
|
|
23996
|
+
}
|
|
23997
|
+
say(kind === 'deselect' ? 'Cleared ' + n + ' acceptance' + (n === 1 ? '' : 's') : 'Accepted ' + n + ' asset' + (n === 1 ? '' : 's'));
|
|
23998
|
+
for (const r of rows.values()) r.drawn = -1;
|
|
23999
|
+
buildList();
|
|
24000
|
+
refresh();
|
|
24001
|
+
}
|
|
24002
|
+
function setFilter(id) {
|
|
24003
|
+
filter = id;
|
|
24004
|
+
buildList();
|
|
24005
|
+
const shown = visible();
|
|
24006
|
+
if (!shown.some((g) => g.key === currentKey)) currentKey = shown[0] ? shown[0].key : null;
|
|
24007
|
+
select(currentKey);
|
|
24008
|
+
}
|
|
24009
|
+
|
|
24010
|
+
async function apply() {
|
|
24011
|
+
if ($('apply').disabled) return;
|
|
24012
|
+
applying = true;
|
|
24013
|
+
refreshHeader();
|
|
24014
|
+
say('Applying…');
|
|
24015
|
+
const selections = GROUPS.filter((g) => st(g.key).chosen !== null).map((g) => ({ key: g.key, index: st(g.key).chosen }));
|
|
24016
|
+
try {
|
|
24017
|
+
const res = await fetch(CONFIG.applyUrl, {
|
|
24018
|
+
method: 'POST',
|
|
24019
|
+
headers: Object.assign({ 'Content-Type': 'application/json' }, CONFIG.headers),
|
|
23598
24020
|
body: JSON.stringify({ selections }),
|
|
23599
24021
|
});
|
|
23600
24022
|
if (!res.ok) throw new Error(await res.text());
|
|
23601
24023
|
const result = await res.json();
|
|
23602
|
-
|
|
23603
|
-
|
|
23604
|
-
|
|
24024
|
+
for (const g of GROUPS) { try { localStorage.removeItem(localKey(g)); } catch (e) { /* ignore */ } }
|
|
24025
|
+
say(CONFIG.embedded ? 'Applied ' + result.selected : 'Applied ' + result.selected + '. You can close this tab.');
|
|
24026
|
+
document.body.classList.add('done');
|
|
24027
|
+
if (CONFIG.embedded && window.parent !== window) {
|
|
23605
24028
|
window.parent.postMessage({ type: 'pixelkiln:review-applied', result }, location.origin);
|
|
23606
24029
|
}
|
|
23607
24030
|
} catch (err) {
|
|
23608
|
-
|
|
23609
|
-
|
|
24031
|
+
applying = false;
|
|
24032
|
+
say('Apply failed: ' + err.message, true);
|
|
24033
|
+
refreshHeader();
|
|
23610
24034
|
}
|
|
23611
|
-
};
|
|
23612
|
-
</script>
|
|
23613
|
-
</body>
|
|
23614
|
-
</html>`;
|
|
23615
24035
|
}
|
|
23616
24036
|
|
|
24037
|
+
// ---- server session --------------------------------------------------------
|
|
24038
|
+
let watching = null;
|
|
24039
|
+
async function sync() {
|
|
24040
|
+
if (!CONFIG.sessionUrl) return;
|
|
24041
|
+
const res = await fetch(CONFIG.sessionUrl, { headers: CONFIG.headers });
|
|
24042
|
+
if (!res.ok) throw new Error(await res.text());
|
|
24043
|
+
const data = await res.json();
|
|
24044
|
+
const before = new Map(GROUPS.map((g) => [g.key, g.reviewObjectId]));
|
|
24045
|
+
GROUPS = data.groups;
|
|
24046
|
+
canReroll = Boolean(data.canReroll && CONFIG.rerollUrl);
|
|
24047
|
+
rerolls = data.rerolls || {};
|
|
24048
|
+
for (const g of GROUPS) {
|
|
24049
|
+
const fresh = before.get(g.key) !== g.reviewObjectId;
|
|
24050
|
+
if (fresh) { delete cursor[g.key]; if (before.has(g.key)) say(decode(g.assetId) + ' is back with a new take.'); }
|
|
24051
|
+
state[g.key] = Object.assign(blank(), data.state[g.key] || {});
|
|
24052
|
+
}
|
|
24053
|
+
buildList();
|
|
24054
|
+
refresh();
|
|
24055
|
+
}
|
|
24056
|
+
function watch() {
|
|
24057
|
+
if (watching || !CONFIG.sessionUrl) return;
|
|
24058
|
+
watching = setInterval(async () => {
|
|
24059
|
+
try { await sync(); } catch (e) { /* the run may have ended */ }
|
|
24060
|
+
if (!Object.values(rerolls).some((r) => r.state === 'running')) { clearInterval(watching); watching = null; }
|
|
24061
|
+
}, 2000);
|
|
24062
|
+
}
|
|
24063
|
+
|
|
24064
|
+
// ---- keyboard --------------------------------------------------------------
|
|
24065
|
+
document.addEventListener('keydown', (e) => {
|
|
24066
|
+
if (document.body.classList.contains('done')) return;
|
|
24067
|
+
const onButton = e.target instanceof HTMLButtonElement && !e.target.closest('#list');
|
|
24068
|
+
if (onButton && (e.key === 'Enter' || e.key === ' ')) return;
|
|
24069
|
+
if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') { apply(); e.preventDefault(); return; }
|
|
24070
|
+
if (e.metaKey || e.ctrlKey || e.altKey) return;
|
|
24071
|
+
const g = group(currentKey);
|
|
24072
|
+
const k = e.key;
|
|
24073
|
+
if (k === 'ArrowDown' || k === 'j') move(1);
|
|
24074
|
+
else if (k === 'ArrowUp' || k === 'k') move(-1);
|
|
24075
|
+
else if (k === 'Home') { const v = visible(); if (v[0]) select(v[0].key); }
|
|
24076
|
+
else if (k === 'End') { const v = visible(); if (v.length) select(v[v.length - 1].key); }
|
|
24077
|
+
else if ((k === 'ArrowRight' || k === 'ArrowLeft') && g) setCursor(g, cur(g) + (k === 'ArrowRight' ? 1 : -1));
|
|
24078
|
+
else if (k === ' ') togglePlay();
|
|
24079
|
+
else if (k === 'A' && e.shiftKey) batch('unflagged');
|
|
24080
|
+
else if (k === 'S' && e.shiftKey) batch('select');
|
|
24081
|
+
else if (k === 'D' && e.shiftKey) batch('deselect');
|
|
24082
|
+
else if (k === 'a' || k === 'Enter') accept();
|
|
24083
|
+
else if (k === 'f') flag();
|
|
24084
|
+
else if (k === 'l') later();
|
|
24085
|
+
else if (k === 'r') reroll();
|
|
24086
|
+
else if (k === 'x') { showStrip = !showStrip; buildStage(); }
|
|
24087
|
+
else if (k === 'c' && g) { flipped = (flipped + 1) % views(g).length; buildStage(); }
|
|
24088
|
+
else if (k === 'o') { onion = !onion; buildStage(); }
|
|
24089
|
+
else if (k === 'p') { pingpong = !pingpong; buildStage(); }
|
|
24090
|
+
else if (/^[1-5]$/.test(k)) setFilter(FILTERS[Number(k) - 1][0]);
|
|
24091
|
+
else if (k === 'Escape' && armedReroll) { armedReroll = null; say(''); buildStage(); }
|
|
24092
|
+
else return;
|
|
24093
|
+
e.preventDefault();
|
|
24094
|
+
});
|
|
24095
|
+
|
|
24096
|
+
const press = (id, fn) => $(id).addEventListener('click', (e) => { fn(); e.currentTarget.blur(); });
|
|
24097
|
+
press('a-accept', accept);
|
|
24098
|
+
press('a-flag', flag);
|
|
24099
|
+
press('a-later', later);
|
|
24100
|
+
press('a-reroll', reroll);
|
|
24101
|
+
press('t-play', togglePlay);
|
|
24102
|
+
press('t-flip', () => { const g = group(currentKey); if (g) { flipped = (flipped + 1) % views(g).length; buildStage(); } });
|
|
24103
|
+
press('t-strip', () => { showStrip = !showStrip; buildStage(); });
|
|
24104
|
+
press('t-onion', () => { onion = !onion; buildStage(); });
|
|
24105
|
+
press('t-pong', () => { pingpong = !pingpong; buildStage(); });
|
|
24106
|
+
press('select-all', () => batch('select'));
|
|
24107
|
+
press('deselect-all', () => batch('deselect'));
|
|
24108
|
+
press('accept-unflagged', () => batch('unflagged'));
|
|
24109
|
+
press('apply', apply);
|
|
24110
|
+
window.addEventListener('resize', () => { dirty = true; });
|
|
24111
|
+
document.addEventListener('visibilitychange', () => { lastTick = 0; });
|
|
24112
|
+
|
|
24113
|
+
// ---- boot ------------------------------------------------------------------
|
|
24114
|
+
for (const g of GROUPS) recall(g);
|
|
24115
|
+
buildFilters();
|
|
24116
|
+
buildList();
|
|
24117
|
+
refresh();
|
|
24118
|
+
list.focus({ preventScroll: true });
|
|
24119
|
+
requestAnimationFrame(tick);
|
|
24120
|
+
if (CONFIG.sessionUrl) {
|
|
24121
|
+
sync().then(() => { if (Object.values(rerolls).some((r) => r.state === 'running')) watch(); })
|
|
24122
|
+
.catch((err) => say('Could not load saved selections: ' + err.message, true));
|
|
24123
|
+
}
|
|
24124
|
+
`;
|
|
24125
|
+
|
|
23617
24126
|
// src/pick/review-server.ts
|
|
23618
24127
|
var import_node_http = require("http");
|
|
23619
24128
|
var import_promises28 = require("fs/promises");
|
|
24129
|
+
async function readJsonBody(req, res) {
|
|
24130
|
+
const expectedOrigin = req.headers.host ? `http://${req.headers.host}` : null;
|
|
24131
|
+
if (req.headers.origin && req.headers.origin !== expectedOrigin) {
|
|
24132
|
+
res.writeHead(403, { "Content-Type": "text/plain" });
|
|
24133
|
+
res.end("cross-origin review submissions are not allowed");
|
|
24134
|
+
return { ok: false };
|
|
24135
|
+
}
|
|
24136
|
+
if (!req.headers["content-type"]?.toLowerCase().startsWith("application/json")) {
|
|
24137
|
+
res.writeHead(415, { "Content-Type": "text/plain" });
|
|
24138
|
+
res.end("application/json is required");
|
|
24139
|
+
return { ok: false };
|
|
24140
|
+
}
|
|
24141
|
+
const chunks = [];
|
|
24142
|
+
let bytes = 0;
|
|
24143
|
+
for await (const c of req) {
|
|
24144
|
+
const chunk2 = c;
|
|
24145
|
+
bytes += chunk2.length;
|
|
24146
|
+
if (bytes > 64 * 1024) {
|
|
24147
|
+
res.writeHead(413, { "Content-Type": "text/plain" });
|
|
24148
|
+
res.end("review submission is too large");
|
|
24149
|
+
return { ok: false };
|
|
24150
|
+
}
|
|
24151
|
+
chunks.push(chunk2);
|
|
24152
|
+
}
|
|
24153
|
+
return { ok: true, body: JSON.parse(Buffer.concat(chunks).toString("utf8")) };
|
|
24154
|
+
}
|
|
23620
24155
|
function serveReviewPage(opts) {
|
|
23621
24156
|
const log = opts.onProgress ?? (() => {
|
|
23622
24157
|
});
|
|
@@ -23628,7 +24163,9 @@ function serveReviewPage(opts) {
|
|
|
23628
24163
|
const bytes = await (0, import_promises28.readFile)(asset.path);
|
|
23629
24164
|
res.writeHead(200, {
|
|
23630
24165
|
"Content-Type": asset.contentType,
|
|
23631
|
-
|
|
24166
|
+
// A frame route names one cached candidate for the life of this
|
|
24167
|
+
// server, so the browser may keep it; everything else is re-read.
|
|
24168
|
+
"Cache-Control": req.url.includes("/review-frame/") ? "private, max-age=86400, immutable" : "no-store",
|
|
23632
24169
|
"X-Content-Type-Options": "nosniff"
|
|
23633
24170
|
});
|
|
23634
24171
|
res.end(bytes);
|
|
@@ -23640,39 +24177,38 @@ function serveReviewPage(opts) {
|
|
|
23640
24177
|
}
|
|
23641
24178
|
if (req.method === "GET" && (req.url === "/" || req.url?.startsWith("/?"))) {
|
|
23642
24179
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
23643
|
-
res.end(opts.html);
|
|
24180
|
+
res.end(typeof opts.html === "function" ? opts.html() : opts.html);
|
|
23644
24181
|
return;
|
|
23645
24182
|
}
|
|
23646
|
-
if (req.method === "
|
|
23647
|
-
|
|
23648
|
-
|
|
23649
|
-
|
|
23650
|
-
|
|
23651
|
-
|
|
23652
|
-
|
|
23653
|
-
|
|
23654
|
-
|
|
23655
|
-
|
|
24183
|
+
if (opts.handleRequest && req.url && req.url !== "/apply" && (req.method === "GET" || req.method === "POST")) {
|
|
24184
|
+
try {
|
|
24185
|
+
let body = void 0;
|
|
24186
|
+
if (req.method === "POST") {
|
|
24187
|
+
const parsed = await readJsonBody(req, res);
|
|
24188
|
+
if (!parsed.ok) return;
|
|
24189
|
+
body = parsed.body;
|
|
24190
|
+
}
|
|
24191
|
+
const handled = await opts.handleRequest(req.method, req.url, body);
|
|
24192
|
+
if (handled) {
|
|
24193
|
+
res.writeHead(handled.status, { "Content-Type": "application/json", "Cache-Control": "no-store" });
|
|
24194
|
+
res.end(JSON.stringify(handled.body));
|
|
24195
|
+
return;
|
|
24196
|
+
}
|
|
24197
|
+
} catch (err) {
|
|
24198
|
+
res.writeHead(400, { "Content-Type": "text/plain" });
|
|
24199
|
+
res.end(err instanceof Error ? err.message : String(err));
|
|
23656
24200
|
return;
|
|
23657
24201
|
}
|
|
24202
|
+
}
|
|
24203
|
+
if (req.method === "POST" && req.url === "/apply") {
|
|
23658
24204
|
try {
|
|
23659
|
-
const
|
|
23660
|
-
|
|
23661
|
-
|
|
23662
|
-
const chunk2 = c;
|
|
23663
|
-
bytes += chunk2.length;
|
|
23664
|
-
if (bytes > 64 * 1024) {
|
|
23665
|
-
res.writeHead(413, { "Content-Type": "text/plain" });
|
|
23666
|
-
res.end("review submission is too large");
|
|
23667
|
-
return;
|
|
23668
|
-
}
|
|
23669
|
-
chunks.push(chunk2);
|
|
23670
|
-
}
|
|
23671
|
-
const body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
23672
|
-
const result = await opts.handleApply(body);
|
|
24205
|
+
const parsed = await readJsonBody(req, res);
|
|
24206
|
+
if (!parsed.ok) return;
|
|
24207
|
+
const result = await opts.handleApply(parsed.body);
|
|
23673
24208
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
23674
24209
|
res.end(JSON.stringify(result));
|
|
23675
24210
|
server.close(() => resolve(result));
|
|
24211
|
+
res.on("finish", () => server.closeIdleConnections?.());
|
|
23676
24212
|
} catch (err) {
|
|
23677
24213
|
const message6 = err instanceof Error ? err.message : String(err);
|
|
23678
24214
|
log(` apply failed: ${message6}`);
|
|
@@ -23778,11 +24314,11 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
23778
24314
|
continue;
|
|
23779
24315
|
}
|
|
23780
24316
|
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await (0, import_promises29.readFile)(cached2.path).catch(() => Buffer.alloc(0))) : null);
|
|
23781
|
-
const route = `${prefix}/review-frame/${encodeURIComponent(String(groups.length))}/${index}`;
|
|
24317
|
+
const route = `${prefix}/review-frame/${encodeURIComponent(String((opts.routeBase ?? 0) + groups.length))}/${index}`;
|
|
23782
24318
|
frameAssets.push([route, cached2]);
|
|
23783
24319
|
frameUrls.push(route);
|
|
23784
24320
|
}
|
|
23785
|
-
const sourceRoute = spec?.revision ? `${prefix}/revision-source/${encodeURIComponent(String(groups.length))}` : null;
|
|
24321
|
+
const sourceRoute = spec?.revision ? `${prefix}/revision-source/${encodeURIComponent(String((opts.routeBase ?? 0) + groups.length))}` : null;
|
|
23786
24322
|
if (sourceRoute && spec?.revision) {
|
|
23787
24323
|
reviewAssets.set(sourceRoute, {
|
|
23788
24324
|
path: spec.revision.sourceFile,
|
|
@@ -23790,7 +24326,7 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
23790
24326
|
});
|
|
23791
24327
|
}
|
|
23792
24328
|
const current = await currentArt(entry, spec);
|
|
23793
|
-
const currentRoute = current ? `${prefix}/current-art/${encodeURIComponent(String(groups.length))}` : null;
|
|
24329
|
+
const currentRoute = current ? `${prefix}/current-art/${encodeURIComponent(String((opts.routeBase ?? 0) + groups.length))}` : null;
|
|
23794
24330
|
if (current && currentRoute) {
|
|
23795
24331
|
reviewAssets.set(currentRoute, { path: current.path, contentType: current.contentType });
|
|
23796
24332
|
}
|
|
@@ -23941,6 +24477,130 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
23941
24477
|
}
|
|
23942
24478
|
};
|
|
23943
24479
|
}
|
|
24480
|
+
function createReviewHost(provider, lock, lockPath, first, opts = {}) {
|
|
24481
|
+
const log = opts.onProgress ?? (() => {
|
|
24482
|
+
});
|
|
24483
|
+
const statePath = reviewStatePathFor(lockPath);
|
|
24484
|
+
let groups = [...first.groups];
|
|
24485
|
+
const owner = new Map(groups.map((g) => [g.key, first]));
|
|
24486
|
+
const assets = new Map(first.assets);
|
|
24487
|
+
const memory = /* @__PURE__ */ new Map();
|
|
24488
|
+
const rerolls = /* @__PURE__ */ new Map();
|
|
24489
|
+
const running = /* @__PURE__ */ new Set();
|
|
24490
|
+
let nextRoute = groups.length;
|
|
24491
|
+
const readState = async () => {
|
|
24492
|
+
const saved = (await loadReviewState(statePath)).assets;
|
|
24493
|
+
const out = {};
|
|
24494
|
+
for (const g of groups) {
|
|
24495
|
+
const record = saved[g.key];
|
|
24496
|
+
out[g.key] = record && record.jobId === g.reviewObjectId && record.status === "pending" ? { chosen: record.chosen, flagged: record.flagged ?? [], later: record.later ?? false } : memory.get(g.key) ?? { chosen: null, flagged: [], later: false };
|
|
24497
|
+
}
|
|
24498
|
+
return out;
|
|
24499
|
+
};
|
|
24500
|
+
const writeState = async (body) => {
|
|
24501
|
+
const { key: key3, chosen, flagged, later } = body ?? {};
|
|
24502
|
+
const group = groups.find((g) => g.key === key3);
|
|
24503
|
+
if (!group) throw new Error(`${String(key3)} is not on this review page`);
|
|
24504
|
+
const count = group.frameUrls.length;
|
|
24505
|
+
const index = (n) => typeof n === "number" && Number.isInteger(n) && n >= 0 && n < count;
|
|
24506
|
+
if (chosen !== null && chosen !== void 0 && !index(chosen)) throw new Error(`chosen must be a candidate index below ${count}`);
|
|
24507
|
+
if (flagged !== void 0 && (!Array.isArray(flagged) || !flagged.every(index))) throw new Error("flagged must list frame indexes");
|
|
24508
|
+
const next = {
|
|
24509
|
+
chosen: chosen ?? null,
|
|
24510
|
+
flagged: [...new Set(flagged ?? [])].sort((a, b) => a - b),
|
|
24511
|
+
later: later === true
|
|
24512
|
+
};
|
|
24513
|
+
const saved = await updateReviewAsset(
|
|
24514
|
+
statePath,
|
|
24515
|
+
group.key,
|
|
24516
|
+
(asset) => asset.jobId !== group.reviewObjectId ? asset : {
|
|
24517
|
+
...asset,
|
|
24518
|
+
chosen: next.chosen,
|
|
24519
|
+
...next.flagged.length ? { flagged: next.flagged } : { flagged: void 0 },
|
|
24520
|
+
...next.later ? { later: true } : { later: void 0 }
|
|
24521
|
+
}
|
|
24522
|
+
);
|
|
24523
|
+
if (!saved || saved.jobId !== group.reviewObjectId) memory.set(group.key, next);
|
|
24524
|
+
return next;
|
|
24525
|
+
};
|
|
24526
|
+
const startReroll = (key3) => {
|
|
24527
|
+
if (!opts.reroll) throw new Error("this review page cannot reroll; run gen --force for the asset");
|
|
24528
|
+
if (!groups.some((g) => g.key === key3)) throw new Error(`${key3} is not on this review page`);
|
|
24529
|
+
if (rerolls.get(key3)?.state === "running") return;
|
|
24530
|
+
rerolls.set(key3, { state: "running" });
|
|
24531
|
+
log(` rerolling ${key3} (--force)\u2026`);
|
|
24532
|
+
const job = (async () => {
|
|
24533
|
+
await opts.reroll(key3);
|
|
24534
|
+
const session = await prepareReview(provider, lock, {
|
|
24535
|
+
keys: [key3],
|
|
24536
|
+
specs: opts.specs,
|
|
24537
|
+
onProgress: log,
|
|
24538
|
+
lockPath,
|
|
24539
|
+
routeBase: nextRoute
|
|
24540
|
+
});
|
|
24541
|
+
const fresh = session?.groups.find((g) => g.key === key3);
|
|
24542
|
+
if (!session || !fresh) throw new Error(`${key3} did not come back into review`);
|
|
24543
|
+
nextRoute += session.groups.length;
|
|
24544
|
+
for (const [route, asset] of session.assets) assets.set(route, asset);
|
|
24545
|
+
groups = groups.map((g) => g.key === key3 ? fresh : g);
|
|
24546
|
+
owner.set(key3, session);
|
|
24547
|
+
memory.delete(key3);
|
|
24548
|
+
rerolls.delete(key3);
|
|
24549
|
+
log(` ${key3}: new candidate ready on the review page`);
|
|
24550
|
+
})().catch((err) => {
|
|
24551
|
+
const message6 = err instanceof Error ? err.message : String(err);
|
|
24552
|
+
rerolls.set(key3, { state: "failed", error: message6 });
|
|
24553
|
+
log(` reroll ${key3} failed: ${message6}`);
|
|
24554
|
+
});
|
|
24555
|
+
running.add(job);
|
|
24556
|
+
void job.finally(() => running.delete(job));
|
|
24557
|
+
};
|
|
24558
|
+
return {
|
|
24559
|
+
groups: () => groups,
|
|
24560
|
+
assets,
|
|
24561
|
+
html: () => renderSheet(groups, { sessionUrl: "/session", stateUrl: "/state", rerollUrl: opts.reroll ? "/reroll" : void 0 }),
|
|
24562
|
+
async apply(body) {
|
|
24563
|
+
if ([...rerolls.values()].some((r) => r.state === "running")) {
|
|
24564
|
+
throw new Error("a reroll is still running; apply once it is back");
|
|
24565
|
+
}
|
|
24566
|
+
const { selections } = body ?? {};
|
|
24567
|
+
if (!Array.isArray(selections)) throw new Error("selections must be a list");
|
|
24568
|
+
const bySession = /* @__PURE__ */ new Map();
|
|
24569
|
+
for (const selection of selections) {
|
|
24570
|
+
const session = owner.get(selection?.key);
|
|
24571
|
+
if (!session) continue;
|
|
24572
|
+
bySession.set(session, [...bySession.get(session) ?? [], selection]);
|
|
24573
|
+
}
|
|
24574
|
+
let selected = 0;
|
|
24575
|
+
for (const [session, picks] of bySession) selected += (await session.apply({ selections: picks }, lockPath)).selected;
|
|
24576
|
+
return { selected, skipped: groups.length - selected };
|
|
24577
|
+
},
|
|
24578
|
+
async handleRequest(method, url, body) {
|
|
24579
|
+
if (method === "GET" && url === "/session") {
|
|
24580
|
+
return {
|
|
24581
|
+
status: 200,
|
|
24582
|
+
body: {
|
|
24583
|
+
groups: renderableGroups(groups),
|
|
24584
|
+
state: await readState(),
|
|
24585
|
+
rerolls: Object.fromEntries(rerolls),
|
|
24586
|
+
canReroll: Boolean(opts.reroll)
|
|
24587
|
+
}
|
|
24588
|
+
};
|
|
24589
|
+
}
|
|
24590
|
+
if (method === "POST" && url === "/state") return { status: 200, body: await writeState(body) };
|
|
24591
|
+
if (method === "POST" && url === "/reroll") {
|
|
24592
|
+
const key3 = body?.key;
|
|
24593
|
+
if (typeof key3 !== "string") throw new Error("key is required");
|
|
24594
|
+
startReroll(key3);
|
|
24595
|
+
return { status: 202, body: { key: key3, ...rerolls.get(key3) } };
|
|
24596
|
+
}
|
|
24597
|
+
return void 0;
|
|
24598
|
+
},
|
|
24599
|
+
async idle() {
|
|
24600
|
+
while (running.size) await Promise.all([...running]);
|
|
24601
|
+
}
|
|
24602
|
+
};
|
|
24603
|
+
}
|
|
23944
24604
|
async function runPicker(provider, lock, lockPath, opts = {}) {
|
|
23945
24605
|
const log = opts.onProgress ?? (() => {
|
|
23946
24606
|
});
|
|
@@ -23959,30 +24619,34 @@ async function runPicker(provider, lock, lockPath, opts = {}) {
|
|
|
23959
24619
|
autoSelected = res.selected;
|
|
23960
24620
|
log(` --yes: accepted ${res.selected} single-candidate asset(s)`);
|
|
23961
24621
|
const rest = session.groups.filter((g) => !singles.includes(g)).map((g) => g.key);
|
|
23962
|
-
session = rest.length ? await prepareReview(provider, lock, { onProgress: log, keys: rest, specs: opts.specs }) : null;
|
|
24622
|
+
session = rest.length ? await prepareReview(provider, lock, { onProgress: log, keys: rest, specs: opts.specs, lockPath }) : null;
|
|
23963
24623
|
if (!session) return { selected: autoSelected, skipped: 0 };
|
|
23964
24624
|
}
|
|
23965
24625
|
}
|
|
23966
|
-
const
|
|
23967
|
-
|
|
24626
|
+
const host = createReviewHost(provider, lock, lockPath, session, {
|
|
24627
|
+
specs: opts.specs,
|
|
24628
|
+
onProgress: log,
|
|
24629
|
+
reroll: opts.reroll
|
|
24630
|
+
});
|
|
23968
24631
|
const served = await serveReviewPage({
|
|
23969
|
-
html:
|
|
24632
|
+
html: host.html,
|
|
23970
24633
|
port: opts.port,
|
|
23971
24634
|
open: opts.open,
|
|
23972
24635
|
onProgress: log,
|
|
23973
|
-
assets:
|
|
24636
|
+
assets: host.assets,
|
|
24637
|
+
handleRequest: host.handleRequest,
|
|
23974
24638
|
onReady: (url) => {
|
|
23975
|
-
const info = { url, keys: groups.map((group) => group.key) };
|
|
24639
|
+
const info = { url, keys: host.groups().map((group) => group.key) };
|
|
23976
24640
|
if (opts.onReady) {
|
|
23977
24641
|
opts.onReady(info);
|
|
23978
24642
|
} else {
|
|
23979
24643
|
log(`
|
|
23980
|
-
${
|
|
24644
|
+
${info.keys.length} asset(s) awaiting selection: ${url}`);
|
|
23981
24645
|
log(` (leave this running; it exits once you apply)
|
|
23982
24646
|
`);
|
|
23983
24647
|
}
|
|
23984
24648
|
},
|
|
23985
|
-
handleApply:
|
|
24649
|
+
handleApply: host.apply
|
|
23986
24650
|
});
|
|
23987
24651
|
return { selected: served.selected + autoSelected, skipped: served.skipped };
|
|
23988
24652
|
}
|
|
@@ -24013,7 +24677,7 @@ function parseGlb(bytes) {
|
|
|
24013
24677
|
const total = view.getUint32(8, true);
|
|
24014
24678
|
if (total > bytes.length) throw new Error(`invalid glb: header says ${total} bytes, the file has ${bytes.length}`);
|
|
24015
24679
|
let offset = 12;
|
|
24016
|
-
let
|
|
24680
|
+
let json2 = null;
|
|
24017
24681
|
let bin = null;
|
|
24018
24682
|
const extraChunks = [];
|
|
24019
24683
|
while (offset + 8 <= total) {
|
|
@@ -24022,7 +24686,7 @@ function parseGlb(bytes) {
|
|
|
24022
24686
|
const start = offset + 8;
|
|
24023
24687
|
if (start + length > total) throw new Error("invalid glb: a chunk runs past the end of the file");
|
|
24024
24688
|
const data = bytes.subarray(start, start + length);
|
|
24025
|
-
if (type === CHUNK_JSON && !
|
|
24689
|
+
if (type === CHUNK_JSON && !json2) {
|
|
24026
24690
|
let parsed;
|
|
24027
24691
|
try {
|
|
24028
24692
|
parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(data));
|
|
@@ -24030,7 +24694,7 @@ function parseGlb(bytes) {
|
|
|
24030
24694
|
throw new Error(`invalid glb: the JSON chunk does not parse (${error instanceof Error ? error.message : String(error)})`);
|
|
24031
24695
|
}
|
|
24032
24696
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("invalid glb: the JSON chunk is not an object");
|
|
24033
|
-
|
|
24697
|
+
json2 = parsed;
|
|
24034
24698
|
} else if (type === CHUNK_BIN && !bin) {
|
|
24035
24699
|
bin = data;
|
|
24036
24700
|
} else {
|
|
@@ -24038,15 +24702,15 @@ function parseGlb(bytes) {
|
|
|
24038
24702
|
}
|
|
24039
24703
|
offset = start + pad4(length);
|
|
24040
24704
|
}
|
|
24041
|
-
if (!
|
|
24042
|
-
if (!
|
|
24043
|
-
const declared =
|
|
24705
|
+
if (!json2) throw new Error("invalid glb: no JSON chunk");
|
|
24706
|
+
if (!json2.asset || typeof json2.asset.version !== "string") throw new Error("invalid glb: the JSON has no asset.version");
|
|
24707
|
+
const declared = json2.buffers?.[0]?.byteLength;
|
|
24044
24708
|
if (bin && typeof declared === "number") {
|
|
24045
24709
|
if (declared > bin.length) throw new Error(`invalid glb: buffer 0 declares ${declared} bytes, the BIN chunk has ${bin.length}`);
|
|
24046
24710
|
bin = bin.subarray(0, declared);
|
|
24047
24711
|
}
|
|
24048
|
-
const document2 = { json, bin: bin ?? new Uint8Array(0), extraChunks };
|
|
24049
|
-
for (const [index, bufferView] of (
|
|
24712
|
+
const document2 = { json: json2, bin: bin ?? new Uint8Array(0), extraChunks };
|
|
24713
|
+
for (const [index, bufferView] of (json2.bufferViews ?? []).entries()) {
|
|
24050
24714
|
if (bufferView.buffer !== 0) continue;
|
|
24051
24715
|
const start = bufferView.byteOffset ?? 0;
|
|
24052
24716
|
if (start < 0 || bufferView.byteLength < 0 || start + bufferView.byteLength > document2.bin.length) {
|
|
@@ -24056,8 +24720,8 @@ function parseGlb(bytes) {
|
|
|
24056
24720
|
return document2;
|
|
24057
24721
|
}
|
|
24058
24722
|
function serializeGlb(document2) {
|
|
24059
|
-
const
|
|
24060
|
-
const jsonLength = pad4(
|
|
24723
|
+
const json2 = new TextEncoder().encode(JSON.stringify(document2.json));
|
|
24724
|
+
const jsonLength = pad4(json2.length);
|
|
24061
24725
|
const hasBin = document2.bin.length > 0;
|
|
24062
24726
|
const binLength = pad4(document2.bin.length);
|
|
24063
24727
|
const extra = document2.extraChunks.reduce((sum, chunk2) => sum + 8 + pad4(chunk2.data.length), 0);
|
|
@@ -24070,8 +24734,8 @@ function serializeGlb(document2) {
|
|
|
24070
24734
|
let offset = 12;
|
|
24071
24735
|
view.setUint32(offset, jsonLength, true);
|
|
24072
24736
|
view.setUint32(offset + 4, CHUNK_JSON, true);
|
|
24073
|
-
out.set(
|
|
24074
|
-
out.fill(32, offset + 8 +
|
|
24737
|
+
out.set(json2, offset + 8);
|
|
24738
|
+
out.fill(32, offset + 8 + json2.length, offset + 8 + jsonLength);
|
|
24075
24739
|
offset += 8 + jsonLength;
|
|
24076
24740
|
if (hasBin) {
|
|
24077
24741
|
view.setUint32(offset, binLength, true);
|
|
@@ -24132,9 +24796,9 @@ function replaceGlbImage(document2, imageIndex, bytes, mimeType) {
|
|
|
24132
24796
|
const source = document2.json;
|
|
24133
24797
|
const image = source.images?.[imageIndex];
|
|
24134
24798
|
if (!image) throw new Error(`the model has no image ${imageIndex}`);
|
|
24135
|
-
const
|
|
24136
|
-
const views =
|
|
24137
|
-
const target =
|
|
24799
|
+
const json2 = structuredCloneJson(source);
|
|
24800
|
+
const views = json2.bufferViews ??= [];
|
|
24801
|
+
const target = json2.images[imageIndex];
|
|
24138
24802
|
const viewIndex = typeof image.bufferView === "number" ? image.bufferView : -1;
|
|
24139
24803
|
const old = viewIndex >= 0 ? source.bufferViews?.[viewIndex] : void 0;
|
|
24140
24804
|
const usedElsewhere = viewIndex >= 0 && ((source.images ?? []).some((other, index) => index !== imageIndex && other.bufferView === viewIndex) || (source.accessors ?? []).some((accessor) => accessor.bufferView === viewIndex));
|
|
@@ -24175,9 +24839,9 @@ function replaceGlbImage(document2, imageIndex, bytes, mimeType) {
|
|
|
24175
24839
|
}
|
|
24176
24840
|
}
|
|
24177
24841
|
target.mimeType = mimeType;
|
|
24178
|
-
|
|
24179
|
-
|
|
24180
|
-
return { json, bin, extraChunks: document2.extraChunks };
|
|
24842
|
+
json2.buffers = json2.buffers?.length ? json2.buffers : [{ byteLength: 0 }];
|
|
24843
|
+
json2.buffers[0] = { ...json2.buffers[0], byteLength: bin.length };
|
|
24844
|
+
return { json: json2, bin, extraChunks: document2.extraChunks };
|
|
24181
24845
|
}
|
|
24182
24846
|
function structuredCloneJson(value) {
|
|
24183
24847
|
return JSON.parse(JSON.stringify(value));
|
|
@@ -24235,8 +24899,8 @@ function readAccessor(document2, accessorIndex) {
|
|
|
24235
24899
|
return { data: out, size, count: accessor.count };
|
|
24236
24900
|
}
|
|
24237
24901
|
function describeGlb(document2) {
|
|
24238
|
-
const
|
|
24239
|
-
const images = (
|
|
24902
|
+
const json2 = document2.json;
|
|
24903
|
+
const images = (json2.images ?? []).map((image, index) => {
|
|
24240
24904
|
let info = null;
|
|
24241
24905
|
let bytes = null;
|
|
24242
24906
|
const embedded = typeof image.bufferView === "number";
|
|
@@ -24260,9 +24924,9 @@ function describeGlb(document2) {
|
|
|
24260
24924
|
meshes: []
|
|
24261
24925
|
};
|
|
24262
24926
|
});
|
|
24263
|
-
const imageOfTexture = (info) => info && typeof info.index === "number" ?
|
|
24927
|
+
const imageOfTexture = (info) => info && typeof info.index === "number" ? json2.textures?.[info.index]?.source : void 0;
|
|
24264
24928
|
const meshesOfMaterial = /* @__PURE__ */ new Map();
|
|
24265
|
-
for (const [meshIndex, mesh] of (
|
|
24929
|
+
for (const [meshIndex, mesh] of (json2.meshes ?? []).entries()) {
|
|
24266
24930
|
for (const primitive of mesh.primitives ?? []) {
|
|
24267
24931
|
if (typeof primitive.material !== "number") continue;
|
|
24268
24932
|
const names = meshesOfMaterial.get(primitive.material) ?? [];
|
|
@@ -24271,7 +24935,7 @@ function describeGlb(document2) {
|
|
|
24271
24935
|
meshesOfMaterial.set(primitive.material, names);
|
|
24272
24936
|
}
|
|
24273
24937
|
}
|
|
24274
|
-
for (const [materialIndex, material] of (
|
|
24938
|
+
for (const [materialIndex, material] of (json2.materials ?? []).entries()) {
|
|
24275
24939
|
const uses = [
|
|
24276
24940
|
["baseColor", material.pbrMetallicRoughness?.baseColorTexture],
|
|
24277
24941
|
["normal", material.normalTexture],
|
|
@@ -24291,39 +24955,39 @@ function describeGlb(document2) {
|
|
|
24291
24955
|
}
|
|
24292
24956
|
}
|
|
24293
24957
|
const bones = [];
|
|
24294
|
-
for (const skin of
|
|
24958
|
+
for (const skin of json2.skins ?? []) {
|
|
24295
24959
|
for (const joint of skin.joints ?? []) {
|
|
24296
|
-
const name =
|
|
24960
|
+
const name = json2.nodes?.[joint]?.name ?? `node ${joint}`;
|
|
24297
24961
|
if (!bones.includes(name)) bones.push(name);
|
|
24298
24962
|
}
|
|
24299
24963
|
}
|
|
24300
|
-
const meshes = (
|
|
24964
|
+
const meshes = (json2.meshes ?? []).map((mesh, index) => {
|
|
24301
24965
|
let vertices = 0;
|
|
24302
24966
|
let triangles = 0;
|
|
24303
24967
|
for (const primitive of mesh.primitives ?? []) {
|
|
24304
|
-
const position =
|
|
24968
|
+
const position = json2.accessors?.[primitive.attributes?.POSITION ?? -1];
|
|
24305
24969
|
const count = position?.count ?? 0;
|
|
24306
24970
|
vertices += count;
|
|
24307
24971
|
if ((primitive.mode ?? 4) === 4) {
|
|
24308
|
-
triangles += Math.floor((typeof primitive.indices === "number" ?
|
|
24972
|
+
triangles += Math.floor((typeof primitive.indices === "number" ? json2.accessors?.[primitive.indices]?.count ?? 0 : count) / 3);
|
|
24309
24973
|
}
|
|
24310
24974
|
}
|
|
24311
24975
|
return { name: mesh.name ?? `mesh ${index}`, primitives: mesh.primitives?.length ?? 0, vertices, triangles };
|
|
24312
24976
|
});
|
|
24313
24977
|
return {
|
|
24314
|
-
generator: typeof
|
|
24978
|
+
generator: typeof json2.asset.generator === "string" ? json2.asset.generator : null,
|
|
24315
24979
|
meshes,
|
|
24316
24980
|
bones,
|
|
24317
|
-
animations: (
|
|
24981
|
+
animations: (json2.animations ?? []).map((animation, index) => animation.name ?? `animation ${index}`),
|
|
24318
24982
|
images,
|
|
24319
|
-
items: modelItems(
|
|
24983
|
+
items: modelItems(json2)
|
|
24320
24984
|
};
|
|
24321
24985
|
}
|
|
24322
24986
|
function isBodyNode(node) {
|
|
24323
24987
|
return Array.isArray(node.extras?.hiddenBy) || node.extras?.body === true;
|
|
24324
24988
|
}
|
|
24325
|
-
function modelItems(
|
|
24326
|
-
const meshNodes = (
|
|
24989
|
+
function modelItems(json2) {
|
|
24990
|
+
const meshNodes = (json2.nodes ?? []).filter((node) => typeof node.mesh === "number");
|
|
24327
24991
|
if (!meshNodes.some(isBodyNode)) return meshNodes.length > 1 ? meshNodes.map((node, index) => node.name ?? `part ${index + 1}`) : [];
|
|
24328
24992
|
return meshNodes.filter((node) => !isBodyNode(node)).map((node, index) => node.name ?? `part ${index + 1}`);
|
|
24329
24993
|
}
|
|
@@ -25883,14 +26547,14 @@ function poseNodes(document2, pose) {
|
|
|
25883
26547
|
return posed;
|
|
25884
26548
|
}
|
|
25885
26549
|
function restPrimitives(document2, pose) {
|
|
25886
|
-
const
|
|
26550
|
+
const json2 = document2.json;
|
|
25887
26551
|
const world = worldMatrices(document2, pose ? poseNodes(document2, pose) : void 0);
|
|
25888
26552
|
const out = [];
|
|
25889
|
-
for (const [nodeIndex, node] of (
|
|
26553
|
+
for (const [nodeIndex, node] of (json2.nodes ?? []).entries()) {
|
|
25890
26554
|
if (typeof node.mesh !== "number") continue;
|
|
25891
|
-
const mesh =
|
|
26555
|
+
const mesh = json2.meshes?.[node.mesh];
|
|
25892
26556
|
if (!mesh) continue;
|
|
25893
|
-
const skin = typeof node.skin === "number" ?
|
|
26557
|
+
const skin = typeof node.skin === "number" ? json2.skins?.[node.skin] : void 0;
|
|
25894
26558
|
let jointMatrices = null;
|
|
25895
26559
|
if (skin) {
|
|
25896
26560
|
const inverse = typeof skin.inverseBindMatrices === "number" ? readAccessor(document2, skin.inverseBindMatrices) : null;
|
|
@@ -28522,7 +29186,7 @@ var EDITOR_CSP = [
|
|
|
28522
29186
|
"connect-src 'self'",
|
|
28523
29187
|
"frame-ancestors 'self'"
|
|
28524
29188
|
].join("; ");
|
|
28525
|
-
async function
|
|
29189
|
+
async function readJsonBody2(req) {
|
|
28526
29190
|
const chunks = [];
|
|
28527
29191
|
let bytes = 0;
|
|
28528
29192
|
for await (const chunk2 of req) {
|
|
@@ -28560,7 +29224,7 @@ async function serveGallery(opts) {
|
|
|
28560
29224
|
res.writeHead(status, { "Content-Type": "text/plain; charset=utf-8" });
|
|
28561
29225
|
res.end(message6);
|
|
28562
29226
|
};
|
|
28563
|
-
const
|
|
29227
|
+
const json2 = (status, value) => {
|
|
28564
29228
|
res.writeHead(status, {
|
|
28565
29229
|
"Content-Type": "application/json; charset=utf-8",
|
|
28566
29230
|
"Cache-Control": "no-store",
|
|
@@ -28582,7 +29246,7 @@ async function serveGallery(opts) {
|
|
|
28582
29246
|
fail(415, "application/json is required");
|
|
28583
29247
|
return void 0;
|
|
28584
29248
|
}
|
|
28585
|
-
return
|
|
29249
|
+
return readJsonBody2(req);
|
|
28586
29250
|
};
|
|
28587
29251
|
const reportError = (what, err) => {
|
|
28588
29252
|
const status = typeof err?.status === "number" ? err.status : 500;
|
|
@@ -28597,7 +29261,7 @@ async function serveGallery(opts) {
|
|
|
28597
29261
|
if (body === void 0) return;
|
|
28598
29262
|
const build = await opts.edit(body);
|
|
28599
29263
|
media = build.media;
|
|
28600
|
-
|
|
29264
|
+
json2(200, build.snapshot);
|
|
28601
29265
|
} catch (err) {
|
|
28602
29266
|
reportError("edit", err);
|
|
28603
29267
|
}
|
|
@@ -28608,7 +29272,7 @@ async function serveGallery(opts) {
|
|
|
28608
29272
|
try {
|
|
28609
29273
|
const body = await guardedBody("generation requests");
|
|
28610
29274
|
if (body === void 0) return;
|
|
28611
|
-
|
|
29275
|
+
json2(202, await opts.generate.start(body));
|
|
28612
29276
|
} catch (err) {
|
|
28613
29277
|
reportError("generate", err);
|
|
28614
29278
|
}
|
|
@@ -28619,7 +29283,7 @@ async function serveGallery(opts) {
|
|
|
28619
29283
|
try {
|
|
28620
29284
|
const body = await guardedBody("price requests");
|
|
28621
29285
|
if (body === void 0) return;
|
|
28622
|
-
|
|
29286
|
+
json2(200, await opts.price(body));
|
|
28623
29287
|
} catch (err) {
|
|
28624
29288
|
reportError("price", err);
|
|
28625
29289
|
}
|
|
@@ -28630,7 +29294,7 @@ async function serveGallery(opts) {
|
|
|
28630
29294
|
try {
|
|
28631
29295
|
const body = await guardedBody("skeleton estimates");
|
|
28632
29296
|
if (body === void 0) return;
|
|
28633
|
-
|
|
29297
|
+
json2(200, await opts.skeleton.estimate(body));
|
|
28634
29298
|
} catch (err) {
|
|
28635
29299
|
reportError("skeleton estimate", err);
|
|
28636
29300
|
}
|
|
@@ -28641,7 +29305,7 @@ async function serveGallery(opts) {
|
|
|
28641
29305
|
try {
|
|
28642
29306
|
const body = await guardedBody("editor installs");
|
|
28643
29307
|
if (body === void 0) return;
|
|
28644
|
-
|
|
29308
|
+
json2(202, await opts.editor.install());
|
|
28645
29309
|
} catch (err) {
|
|
28646
29310
|
reportError("editor install", err);
|
|
28647
29311
|
}
|
|
@@ -28656,7 +29320,7 @@ async function serveGallery(opts) {
|
|
|
28656
29320
|
if (body === void 0) return;
|
|
28657
29321
|
const result = await opts.generate.applyReview(jobId, body);
|
|
28658
29322
|
reviewAssets.delete(jobId);
|
|
28659
|
-
|
|
29323
|
+
json2(200, result);
|
|
28660
29324
|
} catch (err) {
|
|
28661
29325
|
reportError("review", err);
|
|
28662
29326
|
}
|
|
@@ -28708,16 +29372,16 @@ async function serveGallery(opts) {
|
|
|
28708
29372
|
if (req.method !== "GET" && req.method !== "HEAD") return fail(405, "the gallery is read-only");
|
|
28709
29373
|
if (url2.pathname === "/api/skeleton") {
|
|
28710
29374
|
if (!opts.skeleton) return fail(404, "skeleton estimates need the gallery started with --edit");
|
|
28711
|
-
return
|
|
29375
|
+
return json2(200, opts.skeleton.status());
|
|
28712
29376
|
}
|
|
28713
29377
|
if (url2.pathname === "/api/jobs") {
|
|
28714
29378
|
if (!opts.generate) return fail(404, "generation is off");
|
|
28715
|
-
return
|
|
29379
|
+
return json2(200, opts.generate.status());
|
|
28716
29380
|
}
|
|
28717
29381
|
if (url2.pathname === "/api/editor") {
|
|
28718
29382
|
if (!opts.editor) return fail(404, "the in-browser editor is off for this gallery");
|
|
28719
29383
|
try {
|
|
28720
|
-
return
|
|
29384
|
+
return json2(200, await opts.editor.status());
|
|
28721
29385
|
} catch (err) {
|
|
28722
29386
|
return reportError("editor status", err);
|
|
28723
29387
|
}
|