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.js
CHANGED
|
@@ -2309,8 +2309,8 @@ var SkeletonSetSchema = z2.object({
|
|
|
2309
2309
|
}
|
|
2310
2310
|
}
|
|
2311
2311
|
});
|
|
2312
|
-
function parseSkeletonSet(
|
|
2313
|
-
const result = SkeletonSetSchema.safeParse(
|
|
2312
|
+
function parseSkeletonSet(json2, file) {
|
|
2313
|
+
const result = SkeletonSetSchema.safeParse(json2);
|
|
2314
2314
|
if (!result.success) {
|
|
2315
2315
|
const issues = result.error.issues.slice(0, 4).map((issue) => `${issue.path.join(".") || "root"}: ${issue.message}`).join("; ");
|
|
2316
2316
|
throw new Error(`revision keypoints file ${file} does not match the expected shape: ${issues}`);
|
|
@@ -5567,9 +5567,9 @@ ${text.slice(0, 600)}`);
|
|
|
5567
5567
|
function parseVfxRecipe(text) {
|
|
5568
5568
|
const lines = text.split(/\r?\n/);
|
|
5569
5569
|
const at2 = lines.findIndex((line) => line.trim() === "working recipe:");
|
|
5570
|
-
const
|
|
5571
|
-
if (!
|
|
5572
|
-
return JSON.parse(
|
|
5570
|
+
const json2 = at2 >= 0 ? lines[at2 + 1]?.trim() : void 0;
|
|
5571
|
+
if (!json2?.startsWith("{")) return null;
|
|
5572
|
+
return JSON.parse(json2);
|
|
5573
5573
|
}
|
|
5574
5574
|
function parseVfxExport(text) {
|
|
5575
5575
|
const effectId = new RegExp(`effect id (${UUID})`).exec(text)?.[1];
|
|
@@ -6365,8 +6365,8 @@ var AnchorsFileSchema = z4.object({
|
|
|
6365
6365
|
version: z4.literal(1),
|
|
6366
6366
|
frames: z4.record(z4.string().min(1), z4.record(z4.string().min(1), AnchorFrameSchema))
|
|
6367
6367
|
}).strict();
|
|
6368
|
-
function parseAnchorsFile(
|
|
6369
|
-
const parsed = AnchorsFileSchema.safeParse(
|
|
6368
|
+
function parseAnchorsFile(json2, label) {
|
|
6369
|
+
const parsed = AnchorsFileSchema.safeParse(json2);
|
|
6370
6370
|
if (!parsed.success) {
|
|
6371
6371
|
const issue = parsed.error.issues[0];
|
|
6372
6372
|
throw new Error(`${label} is not an anchors file: ${issue.path.join(".") || "(root)"}: ${issue.message}`);
|
|
@@ -7696,13 +7696,13 @@ function heldFrames(spec, lock) {
|
|
|
7696
7696
|
return frames;
|
|
7697
7697
|
}
|
|
7698
7698
|
async function readAnchorsFile(file) {
|
|
7699
|
-
let
|
|
7699
|
+
let json2;
|
|
7700
7700
|
try {
|
|
7701
|
-
|
|
7701
|
+
json2 = JSON.parse(await readFile5(file, "utf8"));
|
|
7702
7702
|
} catch (error) {
|
|
7703
7703
|
throw new Error(`${file} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
7704
7704
|
}
|
|
7705
|
-
return parseAnchorsFile(
|
|
7705
|
+
return parseAnchorsFile(json2, file);
|
|
7706
7706
|
}
|
|
7707
7707
|
async function placeHeldFrames(spec, frames) {
|
|
7708
7708
|
const layer = spec.character.layer;
|
|
@@ -14787,13 +14787,13 @@ async function optionalRevisionImage(file, label, requiredFormat) {
|
|
|
14787
14787
|
async function optionalSkeletonSet(file) {
|
|
14788
14788
|
if (!existsSync9(file)) return null;
|
|
14789
14789
|
const bytes = await readFile8(file);
|
|
14790
|
-
let
|
|
14790
|
+
let json2;
|
|
14791
14791
|
try {
|
|
14792
|
-
|
|
14792
|
+
json2 = JSON.parse(bytes.toString("utf8"));
|
|
14793
14793
|
} catch (error) {
|
|
14794
14794
|
throw new Error(`revision keypoints file ${file} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
14795
14795
|
}
|
|
14796
|
-
return { hash: sha256(bytes), skeleton: parseSkeletonSet(
|
|
14796
|
+
return { hash: sha256(bytes), skeleton: parseSkeletonSet(json2, file) };
|
|
14797
14797
|
}
|
|
14798
14798
|
async function revisionSourceMembers(stem2, label) {
|
|
14799
14799
|
if (existsSync9(stem2)) return null;
|
|
@@ -21814,6 +21814,10 @@ var ReviewAssetSchema = z8.object({
|
|
|
21814
21814
|
status: z8.enum(["pending", "applied"]),
|
|
21815
21815
|
/** The chosen candidate index, or null while nothing is chosen. */
|
|
21816
21816
|
chosen: z8.number().int().nonnegative().nullable(),
|
|
21817
|
+
/** Frames (or candidates) the reviewer flagged as bad on the pick page. */
|
|
21818
|
+
flagged: z8.array(z8.number().int().nonnegative()).optional(),
|
|
21819
|
+
/** Set aside on the pick page to decide later. */
|
|
21820
|
+
later: z8.boolean().optional(),
|
|
21817
21821
|
updatedAt: z8.string()
|
|
21818
21822
|
});
|
|
21819
21823
|
var ReviewStateSchema = z8.object({
|
|
@@ -21923,6 +21927,8 @@ async function cacheReviewCandidates(provider, key3, jobId, job, opts) {
|
|
|
21923
21927
|
candidates,
|
|
21924
21928
|
status: "pending",
|
|
21925
21929
|
chosen: previous?.chosen ?? null,
|
|
21930
|
+
...previous?.flagged?.length ? { flagged: previous.flagged } : {},
|
|
21931
|
+
...previous?.later ? { later: true } : {},
|
|
21926
21932
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
21927
21933
|
};
|
|
21928
21934
|
const latest = await loadReviewState(opts.statePath);
|
|
@@ -22704,421 +22710,950 @@ function mode(values) {
|
|
|
22704
22710
|
|
|
22705
22711
|
// src/pick/sheet.ts
|
|
22706
22712
|
var escapeHtml = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
22707
|
-
function
|
|
22708
|
-
|
|
22713
|
+
function renderableGroups(groups) {
|
|
22714
|
+
return groups.map((g) => ({
|
|
22709
22715
|
...g,
|
|
22710
22716
|
styleId: escapeHtml(g.styleId),
|
|
22711
22717
|
assetId: escapeHtml(g.assetId),
|
|
22712
22718
|
prompt: escapeHtml(g.prompt),
|
|
22713
|
-
...g.revision ? {
|
|
22714
|
-
revision: {
|
|
22715
|
-
...g.revision,
|
|
22716
|
-
sourceAssetId: escapeHtml(g.revision.sourceAssetId)
|
|
22717
|
-
}
|
|
22718
|
-
} : {}
|
|
22719
|
+
...g.revision ? { revision: { ...g.revision, sourceAssetId: escapeHtml(g.revision.sourceAssetId) } } : {}
|
|
22719
22720
|
}));
|
|
22720
|
-
|
|
22721
|
-
|
|
22722
|
-
|
|
22721
|
+
}
|
|
22722
|
+
var json = (value) => JSON.stringify(value).replace(/<\//g, "<\\/");
|
|
22723
|
+
function renderSheet(groups, options = {}) {
|
|
22724
|
+
const config = {
|
|
22725
|
+
applyUrl: options.applyUrl ?? "/apply",
|
|
22723
22726
|
headers: options.applyHeaders ?? {},
|
|
22724
|
-
embedded: options.embedded === true
|
|
22725
|
-
|
|
22727
|
+
embedded: options.embedded === true,
|
|
22728
|
+
sessionUrl: options.sessionUrl ?? null,
|
|
22729
|
+
stateUrl: options.stateUrl ?? null,
|
|
22730
|
+
rerollUrl: options.rerollUrl ?? null
|
|
22731
|
+
};
|
|
22726
22732
|
return `<!doctype html>
|
|
22727
22733
|
<html lang="en">
|
|
22728
22734
|
<head>
|
|
22729
22735
|
<meta charset="utf-8">
|
|
22730
22736
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
22731
|
-
<title>
|
|
22737
|
+
<title>Review candidates | pixelkiln</title>
|
|
22732
22738
|
<style>
|
|
22739
|
+
/*
|
|
22740
|
+
* True-black flat, warmed for a kiln: elevation by lightness alone
|
|
22741
|
+
* (ground, surface, raised), no borders on panels, no shadows at rest.
|
|
22742
|
+
* The ember is the one hue and lives only on data: an accepted asset, the
|
|
22743
|
+
* chosen frame. Flagged frames take the negative pair. Buttons are neutral;
|
|
22744
|
+
* the one primary (Apply) is an inverted white pill.
|
|
22745
|
+
*/
|
|
22733
22746
|
:root {
|
|
22734
|
-
--
|
|
22735
|
-
--
|
|
22736
|
-
--
|
|
22737
|
-
--
|
|
22738
|
-
--
|
|
22739
|
-
|
|
22740
|
-
|
|
22741
|
-
|
|
22742
|
-
|
|
22743
|
-
header { position:sticky; top:0; z-index:10; background:var(--panel);
|
|
22744
|
-
border-bottom:1px solid var(--line-strong); }
|
|
22745
|
-
.bar { width:min(100%,var(--content)); margin:0 auto; padding:15px 22px;
|
|
22746
|
-
display:flex; align-items:center; gap:16px; flex-wrap:wrap; }
|
|
22747
|
-
h1 { font:700 14px/1 ui-monospace,SFMono-Regular,Menlo,monospace;
|
|
22748
|
-
margin:0; letter-spacing:-.02em; }
|
|
22749
|
-
h1::before { content:'\u25C6'; color:var(--accent); margin-right:9px; font-size:11px; }
|
|
22750
|
-
.count { color:var(--dim); font-variant-numeric:tabular-nums; }
|
|
22751
|
-
button { font:inherit; font-weight:600; border-radius:0; padding:9px 16px;
|
|
22752
|
-
border:1px solid var(--line); background:transparent; color:var(--text); cursor:pointer; }
|
|
22753
|
-
button.primary { background:var(--accent); border-color:var(--accent); color:var(--bg); }
|
|
22754
|
-
button:disabled { opacity:.45; cursor:not-allowed; }
|
|
22755
|
-
main, footer { width:min(100%,var(--content)); margin-inline:auto; }
|
|
22756
|
-
main { border-inline:1px solid var(--line); }
|
|
22757
|
-
.group { border-bottom:1px solid var(--line); padding:22px; overflow:hidden; }
|
|
22758
|
-
.group.done { background:rgba(185,242,124,.035); }
|
|
22759
|
-
.ghead { display:flex; align-items:baseline; gap:12px; margin-bottom:16px; flex-wrap:wrap; }
|
|
22760
|
-
.style { font-size:10.5px; font-weight:650; text-transform:uppercase; letter-spacing:.03em;
|
|
22761
|
-
color:var(--accent-soft); border:1px solid var(--accent); border-radius:0; padding:2px 6px; }
|
|
22762
|
-
.aid { font-weight:650; font-family:ui-monospace,SFMono-Regular,Menlo,monospace; }
|
|
22763
|
-
.prompt { flex:1; min-width:280px; color:var(--dim); font-size:12.5px; max-width:80ch; }
|
|
22764
|
-
.review { display:grid; grid-template-columns:minmax(180px,280px) minmax(0,1fr); gap:16px;
|
|
22765
|
-
align-items:start; }
|
|
22766
|
-
.review.no-context { display:block; }
|
|
22767
|
-
.context { border:1px solid var(--line); padding:8px; background:var(--panel-deep);
|
|
22768
|
-
min-width:0; display:grid; gap:12px; align-content:start; }
|
|
22769
|
-
.context-label { display:flex; justify-content:space-between; gap:8px; margin-bottom:7px;
|
|
22770
|
-
color:var(--dim); font-size:10.5px; font-variant-numeric:tabular-nums; }
|
|
22771
|
-
.context img { display:block; width:100%; height:auto; max-height:420px; object-fit:contain;
|
|
22772
|
-
image-rendering:pixelated;
|
|
22773
|
-
background-image:linear-gradient(45deg,#0000 25%,#7f7f7f22 25%,#7f7f7f22 75%,#0000 75%),
|
|
22774
|
-
linear-gradient(45deg,#0000 25%,#7f7f7f22 25%,#7f7f7f22 75%,#0000 75%);
|
|
22775
|
-
background-size:12px 12px; background-position:0 0,6px 6px; }
|
|
22776
|
-
.frames { display:flex; flex-wrap:wrap; gap:10px; max-width:100%; overflow-x:auto; }
|
|
22777
|
-
.loop { display:flex; align-items:flex-start; gap:12px; margin-bottom:12px; }
|
|
22778
|
-
.loop img { image-rendering:pixelated; border:2px solid var(--accent); padding:7px;
|
|
22779
|
-
background:var(--panel-deep); max-width:min(var(--preview),calc(100vw - 62px)); height:auto; }
|
|
22780
|
-
.loop-copy { color:var(--dim); font-size:11px; max-width:32ch; display:flex;
|
|
22781
|
-
flex-direction:column; gap:8px; }
|
|
22782
|
-
.loop-copy p { margin:0; }
|
|
22783
|
-
.loop-copy button { align-self:flex-start; padding:5px 9px; font-size:10.5px; }
|
|
22784
|
-
.cand { border:2px solid var(--line-strong); border-radius:0; padding:7px; background:var(--panel-deep);
|
|
22785
|
-
cursor:pointer; display:flex; flex:0 0 auto; flex-direction:column; align-items:center; gap:5px;
|
|
22786
|
-
position:relative; max-width:100%; }
|
|
22787
|
-
.cand:hover { border-color:var(--dim); }
|
|
22788
|
-
.cand.active { border-color:var(--dim); box-shadow:0 0 0 2px color-mix(in srgb, var(--dim) 20%, transparent); }
|
|
22789
|
-
.cand.sel { border-color:var(--ok); box-shadow:0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
|
|
22790
|
-
.cand.set-frame { cursor:pointer; }
|
|
22791
|
-
.cand.recommended:not(.sel) { border-color:var(--accent); }
|
|
22792
|
-
.cand.recommended .badge { position:absolute; top:-1px; left:-1px; font-size:9.5px; font-weight:650;
|
|
22793
|
-
text-transform:uppercase; letter-spacing:.03em; color:var(--bg); background:var(--accent); padding:1px 5px; }
|
|
22794
|
-
.cand img { image-rendering:pixelated; display:block;
|
|
22795
|
-
background-image:
|
|
22796
|
-
linear-gradient(45deg,#0000 25%,#7f7f7f22 25%,#7f7f7f22 75%,#0000 75%),
|
|
22797
|
-
linear-gradient(45deg,#0000 25%,#7f7f7f22 25%,#7f7f7f22 75%,#0000 75%);
|
|
22798
|
-
background-size:12px 12px; background-position:0 0,6px 6px; border-radius:0; }
|
|
22799
|
-
.cand img.preview { max-width:min(var(--preview),calc(100vw - 62px)); height:auto; }
|
|
22800
|
-
.idx { font-size:10.5px; color:var(--dim); font-variant-numeric:tabular-nums; }
|
|
22801
|
-
.actual { position:absolute; right:-3px; bottom:-3px; image-rendering:pixelated;
|
|
22802
|
-
border:1px solid var(--line); border-radius:0; background:var(--panel); }
|
|
22803
|
-
.skip { align-self:center; color:var(--dim); font-size:12px; }
|
|
22804
|
-
footer { padding:26px 20px 60px; color:var(--dim); }
|
|
22805
|
-
kbd { border:1px solid var(--line); border-bottom-width:2px; border-radius:0;
|
|
22806
|
-
padding:1px 5px; font-size:11px; font-family:ui-monospace,Menlo,monospace; }
|
|
22807
|
-
#status { color:var(--warn); }
|
|
22808
|
-
@media (max-width:640px) {
|
|
22809
|
-
.bar, .group { padding-inline:14px; }
|
|
22810
|
-
.prompt { min-width:100%; }
|
|
22811
|
-
.cand img.preview { max-width:calc(100vw - 50px); }
|
|
22812
|
-
}
|
|
22813
|
-
@media (max-width:900px) {
|
|
22814
|
-
.review { grid-template-columns:1fr; }
|
|
22815
|
-
.context { max-width:280px; }
|
|
22747
|
+
--ground:#0e0d0c; --surface:#181716; --raised:#26241f; --hover:#1f1d1a; --rule:#22201d;
|
|
22748
|
+
--text:#ffffff; --muted:#b4b4b4; --faint:#949494; --control:#46423b;
|
|
22749
|
+
--ember:#ff6b35; --ember-bg:#2e1a10;
|
|
22750
|
+
--negative:#e5566f; --negative-bg:#2c1a20;
|
|
22751
|
+
--list:340px; --head:56px; --pad:22px; --gap:14px; --row:56px;
|
|
22752
|
+
--radius-card:14px; --radius-chip:6px;
|
|
22753
|
+
--font: ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
|
|
22754
|
+
--mono: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
22755
|
+
color-scheme: dark;
|
|
22816
22756
|
}
|
|
22757
|
+
* { box-sizing:border-box; }
|
|
22758
|
+
html, body { height:100%; }
|
|
22759
|
+
body { margin:0; background:var(--ground); color:var(--text); font:14px/1.45 var(--font);
|
|
22760
|
+
display:grid; grid-template-rows:auto minmax(0,1fr) auto; overflow:hidden; }
|
|
22761
|
+
button { font:inherit; color:inherit; background:none; border:0; cursor:pointer; }
|
|
22762
|
+
button:focus-visible, [tabindex]:focus-visible { outline:2px solid var(--text); outline-offset:2px; }
|
|
22763
|
+
.num { font-variant-numeric:tabular-nums; }
|
|
22764
|
+
.id { font-family:var(--mono); font-size:12px; }
|
|
22765
|
+
|
|
22766
|
+
/* Top bar */
|
|
22767
|
+
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; }
|
|
22768
|
+
.break { display:none; }
|
|
22769
|
+
.mark { font-weight:600; display:flex; align-items:center; gap:8px; white-space:nowrap; }
|
|
22770
|
+
.mark svg { display:block; }
|
|
22771
|
+
.counter { color:var(--muted); white-space:nowrap; }
|
|
22772
|
+
.counter b { color:var(--text); font-weight:600; }
|
|
22773
|
+
.filters { display:flex; gap:2px; margin-left:8px; }
|
|
22774
|
+
.filters button { height:32px; padding:0 10px; border-radius:var(--radius-chip); color:#bbb; white-space:nowrap; }
|
|
22775
|
+
.filters button:hover { background:var(--hover); }
|
|
22776
|
+
.filters button[aria-pressed="true"] { color:var(--text); background:var(--raised); }
|
|
22777
|
+
.filters .n { color:var(--faint); margin-left:6px; }
|
|
22778
|
+
.grow { flex:1; }
|
|
22779
|
+
.batch { display:flex; gap:2px; }
|
|
22780
|
+
.batch button, .tool { height:32px; padding:0 10px; border-radius:var(--radius-chip); color:#bbb; white-space:nowrap; }
|
|
22781
|
+
.batch button:hover, .tool:hover { background:var(--hover); color:var(--text); }
|
|
22782
|
+
.primary { height:36px; padding:0 18px; border-radius:999px; background:var(--text); color:#000; font-weight:600; white-space:nowrap; }
|
|
22783
|
+
.primary:disabled { background:var(--raised); color:var(--faint); cursor:not-allowed; }
|
|
22784
|
+
#status { color:var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:28ch; }
|
|
22785
|
+
#status.error { color:var(--negative); }
|
|
22786
|
+
|
|
22787
|
+
/* Master list */
|
|
22788
|
+
main { display:grid; grid-template-columns:var(--list) minmax(0,1fr); min-height:0; }
|
|
22789
|
+
#list { overflow-y:auto; border-right:1px solid var(--rule); padding:8px; scroll-padding:8px; outline:none; }
|
|
22790
|
+
.row { display:grid; grid-template-columns:44px minmax(0,1fr) auto; align-items:center; gap:12px;
|
|
22791
|
+
width:100%; height:var(--row); padding:6px 10px 6px 6px; border-radius:10px; text-align:left; }
|
|
22792
|
+
.row:hover { background:var(--hover); }
|
|
22793
|
+
.row[aria-selected="true"] { background:var(--raised); }
|
|
22794
|
+
.thumb { width:44px; height:44px; border-radius:8px; background:var(--surface); display:grid; place-items:center; overflow:hidden; }
|
|
22795
|
+
.thumb canvas { image-rendering:pixelated; display:block; }
|
|
22796
|
+
.row .name { display:block; font-weight:500; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
|
|
22797
|
+
.row .meta { display:block; color:var(--faint); font-size:13px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
|
|
22798
|
+
.state { font-size:13px; color:var(--faint); white-space:nowrap; }
|
|
22799
|
+
.state.accepted { color:var(--ember); }
|
|
22800
|
+
.state.flagged { color:var(--negative); }
|
|
22801
|
+
.state.later, .state.rerolling { color:var(--muted); }
|
|
22802
|
+
.empty { color:var(--muted); padding:24px 12px; }
|
|
22803
|
+
|
|
22804
|
+
/* Stage */
|
|
22805
|
+
#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); }
|
|
22806
|
+
.title { display:flex; align-items:baseline; gap:12px; min-width:0; }
|
|
22807
|
+
.title h1 { font-size:20px; font-weight:600; margin:0; white-space:nowrap; }
|
|
22808
|
+
.title .id { color:var(--faint); white-space:nowrap; }
|
|
22809
|
+
.title .pos { margin-left:auto; color:var(--faint); white-space:nowrap; }
|
|
22810
|
+
.prompt { color:var(--muted); margin:4px 0 0; max-width:90ch; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
|
|
22811
|
+
.view { position:relative; min-height:0; border-radius:var(--radius-card); background-color:var(--surface);
|
|
22812
|
+
background-image:linear-gradient(45deg,#ffffff08 25%,transparent 25%,transparent 75%,#ffffff08 75%),
|
|
22813
|
+
linear-gradient(45deg,#ffffff08 25%,transparent 25%,transparent 75%,#ffffff08 75%);
|
|
22814
|
+
background-size:16px 16px; background-position:0 0,8px 8px;
|
|
22815
|
+
display:grid; place-items:center; overflow:hidden; }
|
|
22816
|
+
.view canvas { image-rendering:pixelated; display:block; }
|
|
22817
|
+
.view .tag { position:absolute; left:14px; top:12px; color:var(--muted); font-size:13px; }
|
|
22818
|
+
.view .tag b { color:var(--text); font-weight:500; }
|
|
22819
|
+
.view .scale { position:absolute; right:14px; top:12px; color:var(--faint); font-size:13px; }
|
|
22820
|
+
.view .notice { position:absolute; inset:auto 14px 12px 14px; color:var(--muted); font-size:13px; }
|
|
22821
|
+
.view.flipped .tag b { color:var(--ember); }
|
|
22822
|
+
.controls { display:flex; align-items:center; gap:4px; flex-wrap:wrap; }
|
|
22823
|
+
.tool[aria-pressed="true"] { color:var(--text); background:var(--raised); }
|
|
22824
|
+
.tool kbd, .act kbd { color:var(--faint); margin-left:6px; font:13px var(--font); }
|
|
22825
|
+
.tool:disabled { color:#8f8a82; cursor:default; background:none; }
|
|
22826
|
+
.actions { display:flex; gap:6px; margin-left:auto; }
|
|
22827
|
+
.act { height:36px; padding:0 14px; border-radius:999px; background:var(--raised); white-space:nowrap; }
|
|
22828
|
+
.act:hover { background:#34312b; }
|
|
22829
|
+
.act.on { background:var(--ember-bg); color:var(--ember); }
|
|
22830
|
+
.act.warn { background:var(--negative-bg); color:var(--negative); }
|
|
22831
|
+
.act:disabled { color:var(--faint); background:var(--surface); cursor:default; }
|
|
22832
|
+
|
|
22833
|
+
/* Frame strip */
|
|
22834
|
+
.strip { display:flex; gap:6px; overflow-x:auto; padding-bottom:4px; scroll-padding:8px; }
|
|
22835
|
+
.strip[hidden] { display:none; }
|
|
22836
|
+
.cell { flex:0 0 auto; display:flex; flex-direction:column; align-items:center; gap:4px; padding:6px; border-radius:10px; min-width:64px; }
|
|
22837
|
+
.cell:hover { background:var(--hover); }
|
|
22838
|
+
.cell .pic { display:grid; place-items:center; background:var(--surface); border-radius:6px; padding:4px; }
|
|
22839
|
+
.cell canvas { image-rendering:pixelated; display:block; }
|
|
22840
|
+
.cell .lab { font-size:13px; color:var(--faint); }
|
|
22841
|
+
.cell[aria-current="true"] { background:var(--raised); }
|
|
22842
|
+
.cell[aria-current="true"] .lab { color:var(--text); }
|
|
22843
|
+
.cell.chosen .pic { box-shadow:inset 0 -3px 0 var(--ember); }
|
|
22844
|
+
.cell.chosen .lab { color:var(--ember); }
|
|
22845
|
+
.cell.flag .pic { box-shadow:inset 0 0 0 2px var(--negative); }
|
|
22846
|
+
.cell.flag .lab { color:var(--negative); }
|
|
22847
|
+
|
|
22848
|
+
footer { display:flex; gap:18px; flex-wrap:wrap; padding:8px var(--pad); border-top:1px solid var(--rule); color:var(--faint); font-size:12px; }
|
|
22849
|
+
footer kbd { font:12px var(--font); color:var(--muted); }
|
|
22850
|
+
body.done main { opacity:.5; pointer-events:none; }
|
|
22851
|
+
|
|
22852
|
+
@media (max-width: 1240px) {
|
|
22853
|
+
header { flex-wrap:wrap; row-gap:4px; padding:8px var(--pad); }
|
|
22854
|
+
.break { display:block; flex-basis:100%; height:0; order:5; }
|
|
22855
|
+
.filters { order:6; margin-left:-10px; }
|
|
22856
|
+
.batch { order:7; margin-left:auto; }
|
|
22857
|
+
}
|
|
22858
|
+
@media (max-width: 900px) {
|
|
22859
|
+
body { overflow:auto; grid-template-rows:auto auto auto; height:auto; }
|
|
22860
|
+
header { flex-wrap:wrap; padding:10px 16px; gap:10px; }
|
|
22861
|
+
.filters { margin-left:0; overflow-x:auto; max-width:100%; }
|
|
22862
|
+
main { grid-template-columns:1fr; }
|
|
22863
|
+
#list { max-height:38vh; border-right:0; border-bottom:1px solid var(--rule); }
|
|
22864
|
+
#stage { padding:14px 16px; grid-template-rows:auto 56vh auto auto; }
|
|
22865
|
+
.actions { margin-left:0; flex-wrap:wrap; }
|
|
22866
|
+
}
|
|
22867
|
+
@media (prefers-reduced-motion: reduce) { * { scroll-behavior:auto !important; } }
|
|
22817
22868
|
</style>
|
|
22818
22869
|
</head>
|
|
22819
22870
|
<body>
|
|
22820
22871
|
<header>
|
|
22821
|
-
<
|
|
22822
|
-
|
|
22823
|
-
|
|
22824
|
-
|
|
22825
|
-
|
|
22826
|
-
|
|
22872
|
+
<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>
|
|
22873
|
+
<span class="counter num" id="counter" aria-live="polite"></span>
|
|
22874
|
+
<nav class="filters" id="filters" aria-label="Filter by status"></nav>
|
|
22875
|
+
<span class="grow"></span>
|
|
22876
|
+
<span id="status" role="status"></span>
|
|
22877
|
+
<div class="batch">
|
|
22878
|
+
<button type="button" id="select-all" title="Accept every asset in this view (Shift+S)">Select all</button>
|
|
22879
|
+
<button type="button" id="deselect-all" title="Clear every acceptance (Shift+D)">Deselect all</button>
|
|
22880
|
+
<button type="button" id="accept-unflagged" title="Accept every undecided asset with no flags (Shift+A)">Accept unflagged</button>
|
|
22827
22881
|
</div>
|
|
22882
|
+
<button type="button" class="primary num" id="apply" disabled>Apply</button>
|
|
22883
|
+
<span class="break"></span>
|
|
22828
22884
|
</header>
|
|
22829
|
-
<main
|
|
22885
|
+
<main>
|
|
22886
|
+
<div id="list" role="listbox" aria-label="Assets awaiting review" tabindex="0"></div>
|
|
22887
|
+
<section id="stage" aria-label="Current asset">
|
|
22888
|
+
<div>
|
|
22889
|
+
<div class="title"><h1 id="s-name"></h1><span class="id" id="s-key"></span><span class="pos num" id="s-pos"></span></div>
|
|
22890
|
+
<p class="prompt" id="s-prompt"></p>
|
|
22891
|
+
</div>
|
|
22892
|
+
<div class="view" id="view">
|
|
22893
|
+
<canvas id="s-canvas" aria-label="Animated frame-set preview"></canvas>
|
|
22894
|
+
<span class="tag" id="s-tag"></span>
|
|
22895
|
+
<span class="scale num" id="s-scale"></span>
|
|
22896
|
+
<span class="notice" id="s-notice"></span>
|
|
22897
|
+
</div>
|
|
22898
|
+
<div class="controls">
|
|
22899
|
+
<button type="button" class="tool" id="t-play" aria-pressed="false">Pause<kbd>Space</kbd></button>
|
|
22900
|
+
<button type="button" class="tool" id="t-flip" aria-pressed="false">Show current art<kbd>C</kbd></button>
|
|
22901
|
+
<button type="button" class="tool" id="t-strip" aria-pressed="false">Frames<kbd>X</kbd></button>
|
|
22902
|
+
<button type="button" class="tool" id="t-onion" aria-pressed="false">Onion skin<kbd>O</kbd></button>
|
|
22903
|
+
<button type="button" class="tool" id="t-pong" aria-pressed="false">Ping-pong<kbd>P</kbd></button>
|
|
22904
|
+
<div class="actions">
|
|
22905
|
+
<button type="button" class="act" id="a-flag">Flag frame<kbd>F</kbd></button>
|
|
22906
|
+
<button type="button" class="act" id="a-later">Later<kbd>L</kbd></button>
|
|
22907
|
+
<button type="button" class="act" id="a-reroll">Reroll<kbd>R</kbd></button>
|
|
22908
|
+
<button type="button" class="act" id="a-accept">Accept<kbd>A</kbd></button>
|
|
22909
|
+
</div>
|
|
22910
|
+
</div>
|
|
22911
|
+
<div class="strip" id="strip" role="listbox" aria-label="Frames" hidden></div>
|
|
22912
|
+
</section>
|
|
22913
|
+
</main>
|
|
22830
22914
|
<footer>
|
|
22831
|
-
|
|
22832
|
-
|
|
22833
|
-
<kbd
|
|
22834
|
-
<kbd>
|
|
22835
|
-
<kbd
|
|
22836
|
-
|
|
22915
|
+
<span><kbd>\u2191</kbd> <kbd>\u2193</kbd> asset</span>
|
|
22916
|
+
<span><kbd>\u2190</kbd> <kbd>\u2192</kbd> frame or candidate</span>
|
|
22917
|
+
<span><kbd>A</kbd> accept</span>
|
|
22918
|
+
<span><kbd>F</kbd> flag frame</span>
|
|
22919
|
+
<span><kbd>L</kbd> later</span>
|
|
22920
|
+
<span><kbd>R</kbd> reroll</span>
|
|
22921
|
+
<span><kbd>X</kbd> frames</span>
|
|
22922
|
+
<span><kbd>C</kbd> compare</span>
|
|
22923
|
+
<span><kbd>1</kbd>\u2013<kbd>5</kbd> filter</span>
|
|
22924
|
+
<span><kbd>Shift</kbd>+<kbd>A</kbd> accept unflagged</span>
|
|
22925
|
+
<span><kbd>\u2318</kbd>/<kbd>Ctrl</kbd>+<kbd>Enter</kbd> apply</span>
|
|
22926
|
+
<span>Unaccepted assets stay in review; closing this page loses nothing.</span>
|
|
22837
22927
|
</footer>
|
|
22838
22928
|
<script>
|
|
22839
|
-
const
|
|
22840
|
-
|
|
22841
|
-
|
|
22842
|
-
|
|
22843
|
-
|
|
22929
|
+
const CONFIG = ${json(config)};
|
|
22930
|
+
let GROUPS = ${json(renderableGroups(groups))};
|
|
22931
|
+
${CLIENT}
|
|
22932
|
+
</script>
|
|
22933
|
+
</body>
|
|
22934
|
+
</html>`;
|
|
22935
|
+
}
|
|
22936
|
+
var CLIENT = String.raw`
|
|
22937
|
+
const $ = (id) => document.getElementById(id);
|
|
22938
|
+
const reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
22939
|
+
const STORE = 'pixelkiln-pick:';
|
|
22940
|
+
const FILTERS = [
|
|
22941
|
+
['all', 'All'], ['undecided', 'Undecided'], ['accepted', 'Accepted'], ['flagged', 'Flagged'], ['later', 'Later'],
|
|
22942
|
+
];
|
|
22844
22943
|
|
|
22845
|
-
|
|
22846
|
-
|
|
22847
|
-
|
|
22848
|
-
|
|
22849
|
-
|
|
22850
|
-
|
|
22851
|
-
|
|
22852
|
-
|
|
22853
|
-
|
|
22854
|
-
|
|
22855
|
-
|
|
22856
|
-
|
|
22857
|
-
|
|
22858
|
-
|
|
22859
|
-
|
|
22860
|
-
|
|
22861
|
-
|
|
22862
|
-
|
|
22863
|
-
|
|
22864
|
-
|
|
22865
|
-
|
|
22866
|
-
|
|
22867
|
-
const label = document.createElement('div');
|
|
22868
|
-
label.className = 'context-label';
|
|
22869
|
-
const identity = document.createElement('span');
|
|
22870
|
-
identity.textContent = identityText;
|
|
22871
|
-
const dimensions = document.createElement('span');
|
|
22872
|
-
dimensions.textContent = dimensionsText;
|
|
22873
|
-
label.append(identity, dimensions);
|
|
22874
|
-
const img = document.createElement('img');
|
|
22944
|
+
let state = {}; // key -> { chosen, flagged, later }
|
|
22945
|
+
let rerolls = {}; // key -> { state, error }
|
|
22946
|
+
let canReroll = Boolean(CONFIG.rerollUrl);
|
|
22947
|
+
let filter = 'all';
|
|
22948
|
+
let currentKey = GROUPS[0] ? GROUPS[0].key : null;
|
|
22949
|
+
let cursor = {}; // key -> frame or candidate index on the stage
|
|
22950
|
+
let playing = !reduced;
|
|
22951
|
+
let flipped = 0; // 0 candidate, then each comparison the asset has
|
|
22952
|
+
let showStrip = false, onion = false, pingpong = false;
|
|
22953
|
+
let armedReroll = null, armedTimer = null;
|
|
22954
|
+
let applying = false;
|
|
22955
|
+
|
|
22956
|
+
// ---- one request per frame -------------------------------------------------
|
|
22957
|
+
const images = new Map();
|
|
22958
|
+
function image(url) {
|
|
22959
|
+
let entry = images.get(url);
|
|
22960
|
+
if (!entry) {
|
|
22961
|
+
const img = new Image();
|
|
22962
|
+
img.decoding = 'async';
|
|
22963
|
+
entry = { img, ready: false, failed: false };
|
|
22964
|
+
img.onload = () => { entry.ready = true; dirty = true; };
|
|
22965
|
+
img.onerror = () => { entry.failed = true; dirty = true; };
|
|
22875
22966
|
img.src = url;
|
|
22876
|
-
|
|
22877
|
-
block.append(label, img);
|
|
22878
|
-
return block;
|
|
22879
|
-
};
|
|
22880
|
-
if (g.revision || g.current) {
|
|
22881
|
-
const context = document.createElement('aside');
|
|
22882
|
-
context.className = 'context';
|
|
22883
|
-
if (g.revision) {
|
|
22884
|
-
context.append(contextPanel(
|
|
22885
|
-
g.revision.mode.toUpperCase() + ' \xB7 SOURCE ' + g.revision.sourceAssetId,
|
|
22886
|
-
g.revision.width + '\xD7' + g.revision.height,
|
|
22887
|
-
g.revision.sourceUrl, 'Revision source ' + g.revision.sourceAssetId));
|
|
22888
|
-
}
|
|
22889
|
-
if (g.current) {
|
|
22890
|
-
context.append(contextPanel(
|
|
22891
|
-
'CURRENT ART \xB7 replaced if you choose',
|
|
22892
|
-
g.current.width + '\xD7' + g.current.height,
|
|
22893
|
-
g.current.url, 'Current ' + g.assetId));
|
|
22894
|
-
}
|
|
22895
|
-
review.insertBefore(context, frames);
|
|
22896
|
-
}
|
|
22897
|
-
if (g.mode === 'frame-set') {
|
|
22898
|
-
const loop = document.createElement('div');
|
|
22899
|
-
loop.className = 'loop';
|
|
22900
|
-
const preview = document.createElement('img');
|
|
22901
|
-
preview.src = g.frameUrls[0];
|
|
22902
|
-
preview.width = displayWidth;
|
|
22903
|
-
preview.height = displayHeight;
|
|
22904
|
-
preview.alt = 'Animated frame-set preview';
|
|
22905
|
-
const copy = document.createElement('div');
|
|
22906
|
-
copy.className = 'loop-copy';
|
|
22907
|
-
const copyText = document.createElement('p');
|
|
22908
|
-
copyText.textContent = g.frameUrls.length + ' ordered frames \xB7 ' + (g.fps || 12) +
|
|
22909
|
-
' fps. Accepting keeps every frame; one bad frame means leave the set unchosen.';
|
|
22910
|
-
const playback = document.createElement('button');
|
|
22911
|
-
playback.type = 'button';
|
|
22912
|
-
let userPaused = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
22913
|
-
let loopVisible = true;
|
|
22914
|
-
let pageVisible = !document.hidden;
|
|
22915
|
-
let loopTimer = null;
|
|
22916
|
-
let loopIndex = 0;
|
|
22917
|
-
const stopLoop = () => {
|
|
22918
|
-
if (loopTimer !== null) window.clearInterval(loopTimer);
|
|
22919
|
-
loopTimer = null;
|
|
22920
|
-
};
|
|
22921
|
-
const syncLoop = () => {
|
|
22922
|
-
stopLoop();
|
|
22923
|
-
playback.textContent = userPaused ? 'Play preview' : 'Pause preview';
|
|
22924
|
-
playback.setAttribute('aria-pressed', String(userPaused));
|
|
22925
|
-
if (!userPaused && loopVisible && pageVisible) {
|
|
22926
|
-
loopTimer = window.setInterval(() => {
|
|
22927
|
-
loopIndex = (loopIndex + 1) % g.frameUrls.length;
|
|
22928
|
-
preview.src = g.frameUrls[loopIndex];
|
|
22929
|
-
}, Math.max(16, Math.round(1000 / (g.fps || 12))));
|
|
22930
|
-
}
|
|
22931
|
-
};
|
|
22932
|
-
playback.addEventListener('click', () => {
|
|
22933
|
-
userPaused = !userPaused;
|
|
22934
|
-
syncLoop();
|
|
22935
|
-
});
|
|
22936
|
-
copy.append(copyText, playback);
|
|
22937
|
-
loop.append(preview, copy);
|
|
22938
|
-
review.insertBefore(loop, frames);
|
|
22939
|
-
document.addEventListener('visibilitychange', () => {
|
|
22940
|
-
pageVisible = !document.hidden;
|
|
22941
|
-
syncLoop();
|
|
22942
|
-
});
|
|
22943
|
-
syncLoop();
|
|
22944
|
-
if ('IntersectionObserver' in window) {
|
|
22945
|
-
new IntersectionObserver((entries) => {
|
|
22946
|
-
loopVisible = entries[0]?.isIntersecting ?? false;
|
|
22947
|
-
syncLoop();
|
|
22948
|
-
}).observe(loop);
|
|
22949
|
-
}
|
|
22967
|
+
images.set(url, entry);
|
|
22950
22968
|
}
|
|
22951
|
-
|
|
22952
|
-
|
|
22953
|
-
const c = document.createElement('button');
|
|
22954
|
-
c.type = 'button';
|
|
22955
|
-
c.className = 'cand' + (g.mode === 'frame-set' ? ' set-frame' : '') +
|
|
22956
|
-
(g.recommendedIndex != null && i === recommended ? ' recommended' : '');
|
|
22957
|
-
c.tabIndex = -1;
|
|
22958
|
-
c.setAttribute('aria-label', (g.mode === 'frame-set'
|
|
22959
|
-
? 'Accept ordered frame set from frame ' + (i + 1)
|
|
22960
|
-
: 'Choose candidate ' + (i + 1) + ' of ' + g.frameUrls.length) +
|
|
22961
|
-
(g.recommendedIndex != null && i === recommended ? ' (this asset\u2019s declared slot)' : ''));
|
|
22969
|
+
return entry;
|
|
22970
|
+
}
|
|
22962
22971
|
|
|
22963
|
-
|
|
22964
|
-
|
|
22965
|
-
|
|
22966
|
-
|
|
22967
|
-
|
|
22968
|
-
|
|
22969
|
-
|
|
22970
|
-
|
|
22971
|
-
|
|
22972
|
-
|
|
22973
|
-
|
|
22974
|
-
|
|
22975
|
-
|
|
22976
|
-
|
|
22977
|
-
|
|
22978
|
-
|
|
22979
|
-
|
|
22980
|
-
|
|
22981
|
-
|
|
22982
|
-
|
|
22983
|
-
|
|
22984
|
-
|
|
22985
|
-
|
|
22986
|
-
|
|
22987
|
-
|
|
22988
|
-
|
|
22989
|
-
|
|
22990
|
-
|
|
22991
|
-
|
|
22992
|
-
|
|
22993
|
-
|
|
22994
|
-
|
|
22995
|
-
|
|
22996
|
-
|
|
22997
|
-
|
|
22998
|
-
|
|
22972
|
+
// ---- state -----------------------------------------------------------------
|
|
22973
|
+
const blank = () => ({ chosen: null, flagged: [], later: false });
|
|
22974
|
+
const group = (key) => GROUPS.find((g) => g.key === key);
|
|
22975
|
+
const st = (key) => state[key] || (state[key] = blank());
|
|
22976
|
+
function statusOf(g) {
|
|
22977
|
+
if (rerolls[g.key] && rerolls[g.key].state === 'running') return 'rerolling';
|
|
22978
|
+
const s = st(g.key);
|
|
22979
|
+
if (s.chosen !== null) return 'accepted';
|
|
22980
|
+
if (s.flagged.length) return 'flagged';
|
|
22981
|
+
if (s.later) return 'later';
|
|
22982
|
+
return 'undecided';
|
|
22983
|
+
}
|
|
22984
|
+
function inFilter(g) {
|
|
22985
|
+
const s = statusOf(g);
|
|
22986
|
+
return filter === 'all' || s === filter || (filter === 'undecided' && s === 'rerolling');
|
|
22987
|
+
}
|
|
22988
|
+
const visible = () => GROUPS.filter(inFilter);
|
|
22989
|
+
const isSet = (g) => g.mode === 'frame-set';
|
|
22990
|
+
const startIndex = (g) => (g.recommendedIndex != null && g.recommendedIndex < g.frameUrls.length ? g.recommendedIndex : 0);
|
|
22991
|
+
const cur = (g) => (cursor[g.key] != null ? cursor[g.key] : (cursor[g.key] = startIndex(g)));
|
|
22992
|
+
|
|
22993
|
+
function localKey(g) { return STORE + g.reviewObjectId + ':' + g.key; }
|
|
22994
|
+
function remember(g) {
|
|
22995
|
+
try { localStorage.setItem(localKey(g), JSON.stringify(st(g.key))); } catch (e) { /* private mode */ }
|
|
22996
|
+
}
|
|
22997
|
+
function recall(g) {
|
|
22998
|
+
try {
|
|
22999
|
+
const raw = localStorage.getItem(localKey(g));
|
|
23000
|
+
if (raw) state[g.key] = Object.assign(blank(), JSON.parse(raw));
|
|
23001
|
+
} catch (e) { /* ignore */ }
|
|
23002
|
+
}
|
|
23003
|
+
|
|
23004
|
+
const pending = new Map();
|
|
23005
|
+
function save(g) {
|
|
23006
|
+
remember(g);
|
|
23007
|
+
if (!CONFIG.stateUrl) return;
|
|
23008
|
+
clearTimeout(pending.get(g.key));
|
|
23009
|
+
pending.set(g.key, setTimeout(async () => {
|
|
23010
|
+
pending.delete(g.key);
|
|
23011
|
+
try {
|
|
23012
|
+
const res = await fetch(CONFIG.stateUrl, {
|
|
23013
|
+
method: 'POST',
|
|
23014
|
+
headers: Object.assign({ 'Content-Type': 'application/json' }, CONFIG.headers),
|
|
23015
|
+
body: JSON.stringify(Object.assign({ key: g.key }, st(g.key))),
|
|
23016
|
+
});
|
|
23017
|
+
if (!res.ok) throw new Error(await res.text());
|
|
23018
|
+
} catch (err) {
|
|
23019
|
+
say('Could not save ' + g.assetId + ': ' + err.message + '. It is kept in this browser.', true);
|
|
22999
23020
|
}
|
|
23021
|
+
}, 200));
|
|
23022
|
+
}
|
|
23000
23023
|
|
|
23001
|
-
|
|
23002
|
-
|
|
23003
|
-
|
|
23004
|
-
|
|
23005
|
-
|
|
23006
|
-
|
|
23007
|
-
|
|
23008
|
-
|
|
23009
|
-
c.onmouseenter = () => activate(i, frames);
|
|
23010
|
-
frames.appendChild(c);
|
|
23011
|
-
});
|
|
23012
|
-
frames.dataset.active = '0';
|
|
23013
|
-
frames.querySelector('.cand')?.classList.add('active');
|
|
23014
|
-
if (recommended > 0) activate(recommended, frames);
|
|
23015
|
-
root.appendChild(el);
|
|
23016
|
-
});
|
|
23024
|
+
// ---- rendering: list -------------------------------------------------------
|
|
23025
|
+
const list = $('list');
|
|
23026
|
+
const rows = new Map();
|
|
23027
|
+
const thumbsOnScreen = new Set();
|
|
23028
|
+
const io = 'IntersectionObserver' in window ? new IntersectionObserver((entries) => {
|
|
23029
|
+
for (const e of entries) (e.isIntersecting ? thumbsOnScreen.add(e.target.dataset.key) : thumbsOnScreen.delete(e.target.dataset.key));
|
|
23030
|
+
dirty = true;
|
|
23031
|
+
}, { root: list }) : null;
|
|
23017
23032
|
|
|
23018
|
-
function
|
|
23019
|
-
const
|
|
23020
|
-
|
|
23021
|
-
|
|
23022
|
-
|
|
23023
|
-
|
|
23024
|
-
|
|
23025
|
-
|
|
23026
|
-
return
|
|
23033
|
+
function stateLabel(g) {
|
|
23034
|
+
const s = statusOf(g);
|
|
23035
|
+
const st0 = st(g.key);
|
|
23036
|
+
if (s === 'accepted') return isSet(g) ? 'Accepted' : 'Accepted ' + (st0.chosen + 1);
|
|
23037
|
+
if (s === 'flagged') return st0.flagged.length + ' flagged';
|
|
23038
|
+
if (s === 'later') return 'Later';
|
|
23039
|
+
if (s === 'rerolling') return 'Rerolling';
|
|
23040
|
+
if (rerolls[g.key] && rerolls[g.key].state === 'failed') return 'Reroll failed';
|
|
23041
|
+
return '';
|
|
23027
23042
|
}
|
|
23028
23043
|
|
|
23029
|
-
function
|
|
23030
|
-
|
|
23031
|
-
|
|
23032
|
-
|
|
23033
|
-
|
|
23034
|
-
|
|
23035
|
-
|
|
23044
|
+
function buildList() {
|
|
23045
|
+
list.textContent = '';
|
|
23046
|
+
rows.clear();
|
|
23047
|
+
if (io) io.disconnect();
|
|
23048
|
+
thumbsOnScreen.clear();
|
|
23049
|
+
const shown = visible();
|
|
23050
|
+
if (!shown.length) {
|
|
23051
|
+
const p = document.createElement('p');
|
|
23052
|
+
p.className = 'empty';
|
|
23053
|
+
p.textContent = filter === 'all' ? 'Nothing is waiting for review.' : 'No assets are ' + filter + '. Press 1 to show all.';
|
|
23054
|
+
list.append(p);
|
|
23036
23055
|
return;
|
|
23037
23056
|
}
|
|
23038
|
-
const
|
|
23039
|
-
|
|
23040
|
-
|
|
23041
|
-
|
|
23042
|
-
|
|
23057
|
+
for (const g of shown) {
|
|
23058
|
+
const row = document.createElement('button');
|
|
23059
|
+
row.type = 'button';
|
|
23060
|
+
row.className = 'row';
|
|
23061
|
+
row.id = 'row-' + GROUPS.indexOf(g);
|
|
23062
|
+
row.setAttribute('role', 'option');
|
|
23063
|
+
row.tabIndex = -1;
|
|
23064
|
+
row.dataset.key = g.key;
|
|
23065
|
+
const thumb = document.createElement('span');
|
|
23066
|
+
thumb.className = 'thumb';
|
|
23067
|
+
const c = document.createElement('canvas');
|
|
23068
|
+
c.width = c.height = 0;
|
|
23069
|
+
thumb.append(c);
|
|
23070
|
+
const text = document.createElement('span');
|
|
23071
|
+
text.style.minWidth = '0';
|
|
23072
|
+
const name = document.createElement('span');
|
|
23073
|
+
name.className = 'name';
|
|
23074
|
+
name.textContent = decode(g.assetId);
|
|
23075
|
+
const meta = document.createElement('span');
|
|
23076
|
+
meta.className = 'meta num';
|
|
23077
|
+
meta.textContent = decode(g.styleId) + ', ' + g.frameUrls.length + (isSet(g) ? ' frames' : g.frameUrls.length === 1 ? ' candidate' : ' candidates');
|
|
23078
|
+
text.append(name, meta);
|
|
23079
|
+
const label = document.createElement('span');
|
|
23080
|
+
label.className = 'state';
|
|
23081
|
+
row.append(thumb, text, label);
|
|
23082
|
+
row.addEventListener('click', () => { select(g.key); row.blur(); list.focus({ preventScroll: true }); });
|
|
23083
|
+
list.append(row);
|
|
23084
|
+
rows.set(g.key, { row, canvas: c, label, drawn: -1 });
|
|
23085
|
+
if (io) io.observe(row); else thumbsOnScreen.add(g.key);
|
|
23086
|
+
}
|
|
23087
|
+
refreshRows();
|
|
23088
|
+
}
|
|
23089
|
+
function refreshRows() {
|
|
23090
|
+
for (const [key, r] of rows) {
|
|
23091
|
+
const g = group(key);
|
|
23092
|
+
if (!g) continue;
|
|
23093
|
+
r.label.textContent = stateLabel(g);
|
|
23094
|
+
r.label.className = 'state ' + statusOf(g);
|
|
23095
|
+
r.row.setAttribute('aria-selected', String(key === currentKey));
|
|
23096
|
+
r.row.setAttribute('aria-label', decode(g.assetId) + ' in ' + decode(g.styleId) + (stateLabel(g) ? ', ' + stateLabel(g) : ', undecided'));
|
|
23097
|
+
}
|
|
23098
|
+
const active = rows.get(currentKey);
|
|
23099
|
+
if (active) list.setAttribute('aria-activedescendant', active.row.id);
|
|
23043
23100
|
}
|
|
23044
|
-
|
|
23045
|
-
|
|
23046
|
-
|
|
23101
|
+
|
|
23102
|
+
// Prompts arrive HTML-escaped; textContent wants them plain.
|
|
23103
|
+
const decoder = document.createElement('textarea');
|
|
23104
|
+
function decode(s) { decoder.innerHTML = s; return decoder.value; }
|
|
23105
|
+
|
|
23106
|
+
// ---- rendering: header -----------------------------------------------------
|
|
23107
|
+
function buildFilters() {
|
|
23108
|
+
const nav = $('filters');
|
|
23109
|
+
nav.textContent = '';
|
|
23110
|
+
FILTERS.forEach(([id, label], i) => {
|
|
23111
|
+
const b = document.createElement('button');
|
|
23112
|
+
b.type = 'button';
|
|
23113
|
+
b.dataset.filter = id;
|
|
23114
|
+
b.title = label + ' (' + (i + 1) + ')';
|
|
23115
|
+
b.addEventListener('click', () => { setFilter(id); b.blur(); });
|
|
23116
|
+
nav.append(b);
|
|
23117
|
+
});
|
|
23118
|
+
}
|
|
23119
|
+
function refreshHeader() {
|
|
23120
|
+
const counts = { all: GROUPS.length, undecided: 0, accepted: 0, flagged: 0, later: 0 };
|
|
23121
|
+
for (const g of GROUPS) {
|
|
23122
|
+
const s = statusOf(g);
|
|
23123
|
+
counts[s === 'rerolling' ? 'undecided' : s]++;
|
|
23124
|
+
}
|
|
23125
|
+
$('counter').innerHTML = '<b>' + counts.accepted + '</b> of ' + GROUPS.length + ' accepted' +
|
|
23126
|
+
(counts.flagged ? ', ' + counts.flagged + ' flagged' : '');
|
|
23127
|
+
for (const b of $('filters').children) {
|
|
23128
|
+
const id = b.dataset.filter;
|
|
23129
|
+
b.setAttribute('aria-pressed', String(id === filter));
|
|
23130
|
+
b.innerHTML = '';
|
|
23131
|
+
b.append(FILTERS.find((f) => f[0] === id)[1]);
|
|
23132
|
+
const n = document.createElement('span');
|
|
23133
|
+
n.className = 'n num';
|
|
23134
|
+
n.textContent = counts[id];
|
|
23135
|
+
b.append(n);
|
|
23136
|
+
}
|
|
23137
|
+
const running = Object.values(rerolls).some((r) => r.state === 'running');
|
|
23138
|
+
const apply = $('apply');
|
|
23139
|
+
apply.disabled = applying || counts.accepted === 0 || running;
|
|
23140
|
+
apply.textContent = counts.accepted ? 'Apply ' + counts.accepted : 'Apply';
|
|
23141
|
+
apply.title = running ? 'Wait for the reroll to finish' : 'Commit the accepted assets (Ctrl or Cmd+Enter)';
|
|
23047
23142
|
}
|
|
23048
|
-
document.addEventListener('keydown', e => {
|
|
23049
|
-
const g = document.activeElement?.closest?.('.group');
|
|
23050
|
-
if (!g) return;
|
|
23051
|
-
const gi = Number(g.dataset.gi);
|
|
23052
|
-
const frames = g.querySelector('.frames');
|
|
23053
|
-
const candidates = [...frames.querySelectorAll('.cand')];
|
|
23054
|
-
const active = Number(frames.dataset.active || 0);
|
|
23055
|
-
let advance = false;
|
|
23056
23143
|
|
|
23057
|
-
|
|
23058
|
-
|
|
23059
|
-
|
|
23060
|
-
|
|
23061
|
-
|
|
23062
|
-
|
|
23063
|
-
|
|
23064
|
-
|
|
23065
|
-
|
|
23066
|
-
|
|
23067
|
-
|
|
23068
|
-
|
|
23069
|
-
|
|
23070
|
-
|
|
23071
|
-
|
|
23072
|
-
|
|
23073
|
-
|
|
23074
|
-
|
|
23075
|
-
|
|
23076
|
-
|
|
23077
|
-
|
|
23078
|
-
|
|
23079
|
-
|
|
23080
|
-
|
|
23144
|
+
// ---- rendering: stage ------------------------------------------------------
|
|
23145
|
+
const canvas = $('s-canvas');
|
|
23146
|
+
const ctx = canvas.getContext('2d');
|
|
23147
|
+
let dirty = true;
|
|
23148
|
+
|
|
23149
|
+
function views(g) {
|
|
23150
|
+
const out = [{ label: isSet(g) ? 'Candidate' : 'Candidate', kind: 'candidate' }];
|
|
23151
|
+
if (g.current) out.push({ label: 'Current art', kind: 'current', url: g.current.url });
|
|
23152
|
+
if (g.revision) out.push({ label: 'Revision source', kind: 'source', url: g.revision.sourceUrl });
|
|
23153
|
+
return out;
|
|
23154
|
+
}
|
|
23155
|
+
function frameSize(g, i) {
|
|
23156
|
+
const known = g.frameSizes && g.frameSizes[i];
|
|
23157
|
+
if (known) return known;
|
|
23158
|
+
const e = image(g.frameUrls[i]);
|
|
23159
|
+
if (e.ready) return { width: e.img.naturalWidth, height: e.img.naturalHeight };
|
|
23160
|
+
return { width: g.width, height: g.height };
|
|
23161
|
+
}
|
|
23162
|
+
// The largest whole-number zoom that fits; below 1x the frame is fitted and
|
|
23163
|
+
// labelled so, never stretched.
|
|
23164
|
+
function fitScale(w, h, boxW, boxH) {
|
|
23165
|
+
const s = Math.min(boxW / w, boxH / h);
|
|
23166
|
+
return s >= 1 ? Math.min(32, Math.floor(s)) : s;
|
|
23167
|
+
}
|
|
23168
|
+
|
|
23169
|
+
let clock = 0, lastTick = 0;
|
|
23170
|
+
function playIndex(g) {
|
|
23171
|
+
const n = g.frameUrls.length;
|
|
23172
|
+
if (n < 2) return 0;
|
|
23173
|
+
const step = Math.floor(clock * (g.fps || 12) / 1000);
|
|
23174
|
+
if (!pingpong) return step % n;
|
|
23175
|
+
const period = 2 * n - 2;
|
|
23176
|
+
const k = step % period;
|
|
23177
|
+
return k < n ? k : period - k;
|
|
23178
|
+
}
|
|
23179
|
+
// What the stage shows right now: frame sets play, candidates hold the cursor.
|
|
23180
|
+
function stageIndex(g) {
|
|
23181
|
+
return isSet(g) && playing ? playIndex(g) : cur(g);
|
|
23182
|
+
}
|
|
23183
|
+
|
|
23184
|
+
function drawStage() {
|
|
23185
|
+
const g = group(currentKey);
|
|
23186
|
+
const view = $('view');
|
|
23187
|
+
if (!g) { canvas.width = canvas.height = 0; return; }
|
|
23188
|
+
const vs = views(g);
|
|
23189
|
+
const mode = vs[flipped % vs.length];
|
|
23190
|
+
view.classList.toggle('flipped', mode.kind !== 'candidate');
|
|
23191
|
+
const box = view.getBoundingClientRect();
|
|
23192
|
+
const i = stageIndex(g);
|
|
23193
|
+
const size = frameSize(g, i);
|
|
23194
|
+
const scale = fitScale(size.width, size.height, Math.max(1, box.width - 48), Math.max(1, box.height - 72));
|
|
23195
|
+
const w = Math.max(1, Math.round(size.width * scale)), h = Math.max(1, Math.round(size.height * scale));
|
|
23196
|
+
if (canvas.width !== w || canvas.height !== h) { canvas.width = w; canvas.height = h; }
|
|
23197
|
+
ctx.imageSmoothingEnabled = scale < 1;
|
|
23198
|
+
ctx.clearRect(0, 0, w, h);
|
|
23199
|
+
const draw = (url, alpha) => {
|
|
23200
|
+
const e = image(url);
|
|
23201
|
+
if (!e.ready) return false;
|
|
23202
|
+
ctx.globalAlpha = alpha;
|
|
23203
|
+
// Same scale as the candidate, so a comparison is pixel for pixel.
|
|
23204
|
+
ctx.drawImage(e.img, 0, 0, e.img.naturalWidth * scale, e.img.naturalHeight * scale);
|
|
23205
|
+
ctx.globalAlpha = 1;
|
|
23206
|
+
return true;
|
|
23207
|
+
};
|
|
23208
|
+
let notice = '';
|
|
23209
|
+
if (mode.kind === 'candidate') {
|
|
23210
|
+
if (onion && g.frameUrls.length > 1) {
|
|
23211
|
+
const prev = (i - 1 + g.frameUrls.length) % g.frameUrls.length;
|
|
23212
|
+
draw(g.frameUrls[prev], 0.3);
|
|
23213
|
+
}
|
|
23214
|
+
const e = image(g.frameUrls[i]);
|
|
23215
|
+
if (e.failed) notice = 'This frame did not load. Reroll the asset or check the run log.';
|
|
23216
|
+
else if (!draw(g.frameUrls[i], 1)) notice = 'Loading…';
|
|
23217
|
+
} else {
|
|
23218
|
+
const e = image(mode.url);
|
|
23219
|
+
if (e.failed) notice = 'The ' + mode.label.toLowerCase() + ' did not load.';
|
|
23220
|
+
else draw(mode.url, 1);
|
|
23221
|
+
}
|
|
23222
|
+
const n = g.frameUrls.length;
|
|
23223
|
+
const s = st(g.key);
|
|
23224
|
+
let tag = '<b>' + mode.label + '</b>';
|
|
23225
|
+
if (mode.kind === 'candidate') {
|
|
23226
|
+
tag += isSet(g)
|
|
23227
|
+
? ', frame ' + (i + 1) + ' of ' + n + ', ' + (g.fps || 12) + ' fps'
|
|
23228
|
+
: ', ' + (i + 1) + ' of ' + n + (g.recommendedIndex === i ? ' (declared slot)' : '');
|
|
23229
|
+
if (s.flagged.includes(i)) tag += ', flagged';
|
|
23230
|
+
if (!isSet(g) && s.chosen === i) tag += ', accepted';
|
|
23081
23231
|
} else {
|
|
23232
|
+
tag += ' at the candidate’s scale';
|
|
23233
|
+
}
|
|
23234
|
+
$('s-tag').innerHTML = tag;
|
|
23235
|
+
$('s-scale').textContent = size.width + '×' + size.height + ', ' + (scale >= 1 ? scale + '×' : 'fitted');
|
|
23236
|
+
$('s-notice').textContent = notice;
|
|
23237
|
+
}
|
|
23238
|
+
|
|
23239
|
+
function buildStage() {
|
|
23240
|
+
const g = group(currentKey);
|
|
23241
|
+
const has = Boolean(g);
|
|
23242
|
+
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;
|
|
23243
|
+
if (!g) {
|
|
23244
|
+
$('s-name').textContent = 'Nothing selected';
|
|
23245
|
+
$('s-key').textContent = '';
|
|
23246
|
+
$('s-pos').textContent = '';
|
|
23247
|
+
$('s-prompt').textContent = visible().length ? '' : 'Change the filter to see more assets.';
|
|
23248
|
+
$('strip').hidden = true;
|
|
23249
|
+
dirty = true;
|
|
23082
23250
|
return;
|
|
23083
23251
|
}
|
|
23084
|
-
|
|
23085
|
-
|
|
23086
|
-
|
|
23252
|
+
const shown = visible();
|
|
23253
|
+
$('s-name').textContent = decode(g.assetId);
|
|
23254
|
+
$('s-key').textContent = decode(g.styleId) + '/' + decode(g.assetId);
|
|
23255
|
+
const pos = shown.indexOf(g);
|
|
23256
|
+
$('s-pos').textContent = (pos >= 0 ? pos + 1 : '–') + ' of ' + shown.length;
|
|
23257
|
+
$('s-prompt').textContent = decode(g.prompt);
|
|
23258
|
+
// Warm this asset's frames and the next one's: still one request each.
|
|
23259
|
+
g.frameUrls.forEach(image);
|
|
23260
|
+
const after = shown[pos + 1];
|
|
23261
|
+
if (after) after.frameUrls.forEach(image);
|
|
23262
|
+
const vs = views(g);
|
|
23263
|
+
$('t-flip').disabled = vs.length < 2;
|
|
23264
|
+
const next = vs[(flipped + 1) % vs.length];
|
|
23265
|
+
$('t-flip').firstChild.textContent = vs.length < 2 ? 'No current art' : flipped % vs.length ? 'Show candidate' : 'Show ' + next.label.toLowerCase();
|
|
23266
|
+
$('t-flip').setAttribute('aria-pressed', String(flipped % vs.length !== 0));
|
|
23267
|
+
$('t-play').firstChild.textContent = playing ? 'Pause' : 'Play';
|
|
23268
|
+
$('t-play').setAttribute('aria-pressed', String(!playing));
|
|
23269
|
+
$('t-strip').setAttribute('aria-pressed', String(showStrip));
|
|
23270
|
+
$('t-onion').setAttribute('aria-pressed', String(onion));
|
|
23271
|
+
$('t-pong').setAttribute('aria-pressed', String(pingpong));
|
|
23272
|
+
$('t-onion').disabled = $('t-pong').disabled = g.frameUrls.length < 2;
|
|
23273
|
+
if (!isSet(g)) $('t-pong').disabled = true;
|
|
23274
|
+
|
|
23275
|
+
const s = st(g.key);
|
|
23276
|
+
const status = statusOf(g);
|
|
23277
|
+
const accept = $('a-accept');
|
|
23278
|
+
accept.className = 'act' + (s.chosen !== null ? ' on' : '');
|
|
23279
|
+
accept.firstChild.textContent = s.chosen !== null ? 'Accepted' : isSet(g) ? 'Accept set' : 'Accept ' + (cur(g) + 1);
|
|
23280
|
+
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);
|
|
23281
|
+
accept.disabled = status === 'rerolling';
|
|
23282
|
+
const flag = $('a-flag');
|
|
23283
|
+
const flaggedHere = s.flagged.includes(cur(g));
|
|
23284
|
+
flag.className = 'act' + (flaggedHere ? ' warn' : '');
|
|
23285
|
+
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);
|
|
23286
|
+
$('a-later').className = 'act' + (s.later ? ' on' : '');
|
|
23287
|
+
const reroll = $('a-reroll');
|
|
23288
|
+
reroll.hidden = !canReroll;
|
|
23289
|
+
const r = rerolls[g.key];
|
|
23290
|
+
reroll.disabled = status === 'rerolling';
|
|
23291
|
+
reroll.className = 'act' + (armedReroll === g.key ? ' warn' : '');
|
|
23292
|
+
reroll.firstChild.textContent = status === 'rerolling' ? 'Rerolling…' : armedReroll === g.key ? 'Press R again to spend' : 'Reroll';
|
|
23293
|
+
if (r && r.state === 'failed') say('Reroll of ' + g.assetId + ' failed: ' + r.error, true);
|
|
23294
|
+
buildStrip(g);
|
|
23295
|
+
dirty = true;
|
|
23296
|
+
}
|
|
23297
|
+
|
|
23298
|
+
function buildStrip(g) {
|
|
23299
|
+
const strip = $('strip');
|
|
23300
|
+
strip.hidden = !showStrip;
|
|
23301
|
+
if (!showStrip) return;
|
|
23302
|
+
strip.textContent = '';
|
|
23303
|
+
const s = st(g.key);
|
|
23304
|
+
g.frameUrls.forEach((url, i) => {
|
|
23305
|
+
const cell = document.createElement('button');
|
|
23306
|
+
cell.type = 'button';
|
|
23307
|
+
cell.className = 'cell' + (s.flagged.includes(i) ? ' flag' : '') +
|
|
23308
|
+
((isSet(g) ? s.chosen !== null : s.chosen === i) ? ' chosen' : '');
|
|
23309
|
+
cell.setAttribute('role', 'option');
|
|
23310
|
+
cell.setAttribute('aria-current', String(i === cur(g)));
|
|
23311
|
+
cell.setAttribute('aria-label', (isSet(g) ? 'Frame ' : 'Candidate ') + (i + 1) + (s.flagged.includes(i) ? ', flagged' : ''));
|
|
23312
|
+
cell.tabIndex = -1;
|
|
23313
|
+
const pic = document.createElement('span');
|
|
23314
|
+
pic.className = 'pic';
|
|
23315
|
+
const c = document.createElement('canvas');
|
|
23316
|
+
c.width = c.height = 0;
|
|
23317
|
+
pic.append(c);
|
|
23318
|
+
const lab = document.createElement('span');
|
|
23319
|
+
lab.className = 'lab num';
|
|
23320
|
+
lab.textContent = String(i + 1) + (s.flagged.includes(i) ? ' flagged' : '');
|
|
23321
|
+
cell.append(pic, lab);
|
|
23322
|
+
cell.addEventListener('click', () => { setCursor(g, i); cell.blur(); });
|
|
23323
|
+
strip.append(cell);
|
|
23324
|
+
const paint = () => {
|
|
23325
|
+
const e = image(url);
|
|
23326
|
+
if (!e.ready) return;
|
|
23327
|
+
const w = e.img.naturalWidth, h = e.img.naturalHeight;
|
|
23328
|
+
const k = fitScale(w, h, 96, 72);
|
|
23329
|
+
c.width = Math.max(1, Math.round(w * k)); c.height = Math.max(1, Math.round(h * k));
|
|
23330
|
+
const x = c.getContext('2d');
|
|
23331
|
+
x.imageSmoothingEnabled = k < 1;
|
|
23332
|
+
x.drawImage(e.img, 0, 0, c.width, c.height);
|
|
23333
|
+
};
|
|
23334
|
+
const e = image(url);
|
|
23335
|
+
if (e.ready) paint(); else e.img.addEventListener('load', paint, { once: true });
|
|
23336
|
+
});
|
|
23337
|
+
const active = strip.children[cur(g)];
|
|
23338
|
+
if (active) active.scrollIntoView({ block: 'nearest', inline: 'nearest' });
|
|
23339
|
+
}
|
|
23340
|
+
|
|
23341
|
+
function drawThumbs() {
|
|
23342
|
+
for (const key of thumbsOnScreen) {
|
|
23343
|
+
const r = rows.get(key);
|
|
23344
|
+
const g = group(key);
|
|
23345
|
+
if (!r || !g) continue;
|
|
23346
|
+
const s = st(key);
|
|
23347
|
+
const i = isSet(g) ? (playing ? playIndex(g) : 0) : (s.chosen !== null ? s.chosen : cur(g));
|
|
23348
|
+
const e = image(g.frameUrls[i]);
|
|
23349
|
+
if (!e.ready) continue;
|
|
23350
|
+
if (r.drawn === i && r.canvas.width) continue;
|
|
23351
|
+
const w = e.img.naturalWidth, h = e.img.naturalHeight;
|
|
23352
|
+
const k = fitScale(w, h, 40, 40);
|
|
23353
|
+
const cw = Math.max(1, Math.round(w * k)), ch = Math.max(1, Math.round(h * k));
|
|
23354
|
+
if (r.canvas.width !== cw || r.canvas.height !== ch) { r.canvas.width = cw; r.canvas.height = ch; }
|
|
23355
|
+
const x = r.canvas.getContext('2d');
|
|
23356
|
+
x.imageSmoothingEnabled = k < 1;
|
|
23357
|
+
x.clearRect(0, 0, cw, ch);
|
|
23358
|
+
x.drawImage(e.img, 0, 0, cw, ch);
|
|
23359
|
+
r.drawn = i;
|
|
23087
23360
|
}
|
|
23088
|
-
|
|
23089
|
-
});
|
|
23361
|
+
}
|
|
23090
23362
|
|
|
23091
|
-
|
|
23092
|
-
|
|
23093
|
-
|
|
23094
|
-
|
|
23095
|
-
|
|
23096
|
-
const
|
|
23363
|
+
// One clock for the page: thumbnails and stage advance together, and stop
|
|
23364
|
+
// when the tab is hidden.
|
|
23365
|
+
function tick(t) {
|
|
23366
|
+
if (playing && lastTick) clock += t - lastTick;
|
|
23367
|
+
lastTick = t;
|
|
23368
|
+
const g = group(currentKey);
|
|
23369
|
+
const before = tick.last;
|
|
23370
|
+
const now = g ? stageIndex(g) + ':' + flipped + ':' + onion : '';
|
|
23371
|
+
if (dirty || now !== before) { drawStage(); tick.last = now; dirty = false; }
|
|
23372
|
+
drawThumbs();
|
|
23373
|
+
requestAnimationFrame(tick);
|
|
23374
|
+
}
|
|
23375
|
+
|
|
23376
|
+
// ---- actions ---------------------------------------------------------------
|
|
23377
|
+
function say(text, error) {
|
|
23378
|
+
const s = $('status');
|
|
23379
|
+
s.textContent = text;
|
|
23380
|
+
s.title = text;
|
|
23381
|
+
s.className = error ? 'error' : '';
|
|
23382
|
+
}
|
|
23383
|
+
function refresh() { refreshRows(); refreshHeader(); buildStage(); }
|
|
23384
|
+
|
|
23385
|
+
function select(key, scroll) {
|
|
23386
|
+
currentKey = key;
|
|
23387
|
+
flipped = 0;
|
|
23388
|
+
if (armedReroll && armedReroll !== key) armedReroll = null;
|
|
23389
|
+
refresh();
|
|
23390
|
+
const r = rows.get(key);
|
|
23391
|
+
if (r && scroll !== false) r.row.scrollIntoView({ block: 'nearest' });
|
|
23392
|
+
}
|
|
23393
|
+
function move(delta) {
|
|
23394
|
+
const shown = visible();
|
|
23395
|
+
if (!shown.length) return;
|
|
23396
|
+
const at = shown.findIndex((g) => g.key === currentKey);
|
|
23397
|
+
const next = at < 0 ? 0 : Math.max(0, Math.min(shown.length - 1, at + delta));
|
|
23398
|
+
select(shown[next].key);
|
|
23399
|
+
}
|
|
23400
|
+
function advance() {
|
|
23401
|
+
// After a decision, go to the next asset still waiting in this view.
|
|
23402
|
+
const shown = visible();
|
|
23403
|
+
const at = GROUPS.findIndex((g) => g.key === currentKey);
|
|
23404
|
+
const after = GROUPS.slice(at + 1).concat(GROUPS.slice(0, at + 1));
|
|
23405
|
+
const next = after.find((g) => inFilter(g) && statusOf(g) === 'undecided');
|
|
23406
|
+
if (filter !== 'all' && !inFilter(group(currentKey))) { buildList(); }
|
|
23407
|
+
if (next) select(next.key); else if (shown.length) refresh(); else { buildList(); select(visible()[0] ? visible()[0].key : null); }
|
|
23408
|
+
}
|
|
23409
|
+
// Pausing holds the frame on screen, so the arrows step from there.
|
|
23410
|
+
function togglePlay() {
|
|
23411
|
+
const g = group(currentKey);
|
|
23412
|
+
if (playing && g && isSet(g)) cursor[g.key] = playIndex(g);
|
|
23413
|
+
playing = !playing;
|
|
23414
|
+
buildStage();
|
|
23415
|
+
}
|
|
23416
|
+
function setCursor(g, i) {
|
|
23417
|
+
const n = g.frameUrls.length;
|
|
23418
|
+
cursor[g.key] = ((i % n) + n) % n;
|
|
23419
|
+
if (isSet(g)) playing = false;
|
|
23420
|
+
if (!isSet(g) && rows.get(g.key)) rows.get(g.key).drawn = -1;
|
|
23421
|
+
buildStage();
|
|
23422
|
+
refreshHeader();
|
|
23423
|
+
}
|
|
23424
|
+
function changed(g) { save(g); if (!inFilter(g)) buildList(); refresh(); }
|
|
23425
|
+
|
|
23426
|
+
function accept() {
|
|
23427
|
+
const g = group(currentKey);
|
|
23428
|
+
if (!g || statusOf(g) === 'rerolling') return;
|
|
23429
|
+
const s = st(g.key);
|
|
23430
|
+
const index = isSet(g) ? 0 : cur(g);
|
|
23431
|
+
if (s.chosen === index) { s.chosen = null; changed(g); return; }
|
|
23432
|
+
s.chosen = index;
|
|
23433
|
+
s.later = false;
|
|
23434
|
+
save(g);
|
|
23435
|
+
if (rows.get(g.key)) rows.get(g.key).drawn = -1;
|
|
23436
|
+
advance();
|
|
23437
|
+
}
|
|
23438
|
+
function flag() {
|
|
23439
|
+
const g = group(currentKey);
|
|
23440
|
+
if (!g) return;
|
|
23441
|
+
// A playing set flags the frame on screen, and holds it there.
|
|
23442
|
+
if (isSet(g) && playing) { cursor[g.key] = playIndex(g); playing = false; }
|
|
23443
|
+
const s = st(g.key);
|
|
23444
|
+
const i = cur(g);
|
|
23445
|
+
s.flagged =s.flagged.includes(i) ? s.flagged.filter((n) => n !== i) : s.flagged.concat(i).sort((a, b) => a - b);
|
|
23446
|
+
// A set with a bad frame is not accepted; a flagged candidate cannot be the choice.
|
|
23447
|
+
if (s.flagged.length && (isSet(g) || s.chosen === i)) s.chosen = null;
|
|
23448
|
+
changed(g);
|
|
23449
|
+
}
|
|
23450
|
+
function later() {
|
|
23451
|
+
const g = group(currentKey);
|
|
23452
|
+
if (!g) return;
|
|
23453
|
+
const s = st(g.key);
|
|
23454
|
+
s.later = !s.later;
|
|
23455
|
+
if (s.later) { s.chosen = null; save(g); advance(); } else changed(g);
|
|
23456
|
+
}
|
|
23457
|
+
async function reroll() {
|
|
23458
|
+
const g = group(currentKey);
|
|
23459
|
+
if (!g || !canReroll || statusOf(g) === 'rerolling') return;
|
|
23460
|
+
if (armedReroll !== g.key) {
|
|
23461
|
+
armedReroll = g.key;
|
|
23462
|
+
clearTimeout(armedTimer);
|
|
23463
|
+
armedTimer = setTimeout(() => { armedReroll = null; buildStage(); }, 4000);
|
|
23464
|
+
say('Rerolling spends credits. Press R again to regenerate ' + decode(g.assetId) + '.');
|
|
23465
|
+
buildStage();
|
|
23466
|
+
return;
|
|
23467
|
+
}
|
|
23468
|
+
armedReroll = null;
|
|
23469
|
+
clearTimeout(armedTimer);
|
|
23097
23470
|
try {
|
|
23098
|
-
const res = await fetch(
|
|
23099
|
-
method: 'POST',
|
|
23471
|
+
const res = await fetch(CONFIG.rerollUrl, {
|
|
23472
|
+
method: 'POST',
|
|
23473
|
+
headers: Object.assign({ 'Content-Type': 'application/json' }, CONFIG.headers),
|
|
23474
|
+
body: JSON.stringify({ key: g.key }),
|
|
23475
|
+
});
|
|
23476
|
+
if (!res.ok) throw new Error(await res.text());
|
|
23477
|
+
rerolls[g.key] = { state: 'running' };
|
|
23478
|
+
say('Rerolling ' + decode(g.assetId) + '. Keep reviewing; it comes back here when ready.');
|
|
23479
|
+
refresh();
|
|
23480
|
+
watch();
|
|
23481
|
+
} catch (err) {
|
|
23482
|
+
say('Reroll failed: ' + err.message, true);
|
|
23483
|
+
}
|
|
23484
|
+
}
|
|
23485
|
+
function batch(kind) {
|
|
23486
|
+
const shown = kind === 'select' ? visible() : GROUPS;
|
|
23487
|
+
let n = 0;
|
|
23488
|
+
for (const g of shown) {
|
|
23489
|
+
if (statusOf(g) === 'rerolling') continue;
|
|
23490
|
+
const s = st(g.key);
|
|
23491
|
+
if (kind === 'deselect') { if (s.chosen !== null) { s.chosen = null; save(g); n++; } continue; }
|
|
23492
|
+
if (s.chosen !== null) continue;
|
|
23493
|
+
if (kind === 'unflagged' && (s.flagged.length || s.later)) continue;
|
|
23494
|
+
if (isSet(g) && s.flagged.length) continue;
|
|
23495
|
+
const index = isSet(g) ? 0 : (s.flagged.includes(cur(g)) ? -1 : cur(g));
|
|
23496
|
+
if (index < 0) continue;
|
|
23497
|
+
s.chosen = index; s.later = false; save(g); n++;
|
|
23498
|
+
}
|
|
23499
|
+
say(kind === 'deselect' ? 'Cleared ' + n + ' acceptance' + (n === 1 ? '' : 's') : 'Accepted ' + n + ' asset' + (n === 1 ? '' : 's'));
|
|
23500
|
+
for (const r of rows.values()) r.drawn = -1;
|
|
23501
|
+
buildList();
|
|
23502
|
+
refresh();
|
|
23503
|
+
}
|
|
23504
|
+
function setFilter(id) {
|
|
23505
|
+
filter = id;
|
|
23506
|
+
buildList();
|
|
23507
|
+
const shown = visible();
|
|
23508
|
+
if (!shown.some((g) => g.key === currentKey)) currentKey = shown[0] ? shown[0].key : null;
|
|
23509
|
+
select(currentKey);
|
|
23510
|
+
}
|
|
23511
|
+
|
|
23512
|
+
async function apply() {
|
|
23513
|
+
if ($('apply').disabled) return;
|
|
23514
|
+
applying = true;
|
|
23515
|
+
refreshHeader();
|
|
23516
|
+
say('Applying…');
|
|
23517
|
+
const selections = GROUPS.filter((g) => st(g.key).chosen !== null).map((g) => ({ key: g.key, index: st(g.key).chosen }));
|
|
23518
|
+
try {
|
|
23519
|
+
const res = await fetch(CONFIG.applyUrl, {
|
|
23520
|
+
method: 'POST',
|
|
23521
|
+
headers: Object.assign({ 'Content-Type': 'application/json' }, CONFIG.headers),
|
|
23100
23522
|
body: JSON.stringify({ selections }),
|
|
23101
23523
|
});
|
|
23102
23524
|
if (!res.ok) throw new Error(await res.text());
|
|
23103
23525
|
const result = await res.json();
|
|
23104
|
-
|
|
23105
|
-
|
|
23106
|
-
|
|
23526
|
+
for (const g of GROUPS) { try { localStorage.removeItem(localKey(g)); } catch (e) { /* ignore */ } }
|
|
23527
|
+
say(CONFIG.embedded ? 'Applied ' + result.selected : 'Applied ' + result.selected + '. You can close this tab.');
|
|
23528
|
+
document.body.classList.add('done');
|
|
23529
|
+
if (CONFIG.embedded && window.parent !== window) {
|
|
23107
23530
|
window.parent.postMessage({ type: 'pixelkiln:review-applied', result }, location.origin);
|
|
23108
23531
|
}
|
|
23109
23532
|
} catch (err) {
|
|
23110
|
-
|
|
23111
|
-
|
|
23533
|
+
applying = false;
|
|
23534
|
+
say('Apply failed: ' + err.message, true);
|
|
23535
|
+
refreshHeader();
|
|
23112
23536
|
}
|
|
23113
|
-
};
|
|
23114
|
-
</script>
|
|
23115
|
-
</body>
|
|
23116
|
-
</html>`;
|
|
23117
23537
|
}
|
|
23118
23538
|
|
|
23539
|
+
// ---- server session --------------------------------------------------------
|
|
23540
|
+
let watching = null;
|
|
23541
|
+
async function sync() {
|
|
23542
|
+
if (!CONFIG.sessionUrl) return;
|
|
23543
|
+
const res = await fetch(CONFIG.sessionUrl, { headers: CONFIG.headers });
|
|
23544
|
+
if (!res.ok) throw new Error(await res.text());
|
|
23545
|
+
const data = await res.json();
|
|
23546
|
+
const before = new Map(GROUPS.map((g) => [g.key, g.reviewObjectId]));
|
|
23547
|
+
GROUPS = data.groups;
|
|
23548
|
+
canReroll = Boolean(data.canReroll && CONFIG.rerollUrl);
|
|
23549
|
+
rerolls = data.rerolls || {};
|
|
23550
|
+
for (const g of GROUPS) {
|
|
23551
|
+
const fresh = before.get(g.key) !== g.reviewObjectId;
|
|
23552
|
+
if (fresh) { delete cursor[g.key]; if (before.has(g.key)) say(decode(g.assetId) + ' is back with a new take.'); }
|
|
23553
|
+
state[g.key] = Object.assign(blank(), data.state[g.key] || {});
|
|
23554
|
+
}
|
|
23555
|
+
buildList();
|
|
23556
|
+
refresh();
|
|
23557
|
+
}
|
|
23558
|
+
function watch() {
|
|
23559
|
+
if (watching || !CONFIG.sessionUrl) return;
|
|
23560
|
+
watching = setInterval(async () => {
|
|
23561
|
+
try { await sync(); } catch (e) { /* the run may have ended */ }
|
|
23562
|
+
if (!Object.values(rerolls).some((r) => r.state === 'running')) { clearInterval(watching); watching = null; }
|
|
23563
|
+
}, 2000);
|
|
23564
|
+
}
|
|
23565
|
+
|
|
23566
|
+
// ---- keyboard --------------------------------------------------------------
|
|
23567
|
+
document.addEventListener('keydown', (e) => {
|
|
23568
|
+
if (document.body.classList.contains('done')) return;
|
|
23569
|
+
const onButton = e.target instanceof HTMLButtonElement && !e.target.closest('#list');
|
|
23570
|
+
if (onButton && (e.key === 'Enter' || e.key === ' ')) return;
|
|
23571
|
+
if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') { apply(); e.preventDefault(); return; }
|
|
23572
|
+
if (e.metaKey || e.ctrlKey || e.altKey) return;
|
|
23573
|
+
const g = group(currentKey);
|
|
23574
|
+
const k = e.key;
|
|
23575
|
+
if (k === 'ArrowDown' || k === 'j') move(1);
|
|
23576
|
+
else if (k === 'ArrowUp' || k === 'k') move(-1);
|
|
23577
|
+
else if (k === 'Home') { const v = visible(); if (v[0]) select(v[0].key); }
|
|
23578
|
+
else if (k === 'End') { const v = visible(); if (v.length) select(v[v.length - 1].key); }
|
|
23579
|
+
else if ((k === 'ArrowRight' || k === 'ArrowLeft') && g) setCursor(g, cur(g) + (k === 'ArrowRight' ? 1 : -1));
|
|
23580
|
+
else if (k === ' ') togglePlay();
|
|
23581
|
+
else if (k === 'A' && e.shiftKey) batch('unflagged');
|
|
23582
|
+
else if (k === 'S' && e.shiftKey) batch('select');
|
|
23583
|
+
else if (k === 'D' && e.shiftKey) batch('deselect');
|
|
23584
|
+
else if (k === 'a' || k === 'Enter') accept();
|
|
23585
|
+
else if (k === 'f') flag();
|
|
23586
|
+
else if (k === 'l') later();
|
|
23587
|
+
else if (k === 'r') reroll();
|
|
23588
|
+
else if (k === 'x') { showStrip = !showStrip; buildStage(); }
|
|
23589
|
+
else if (k === 'c' && g) { flipped = (flipped + 1) % views(g).length; buildStage(); }
|
|
23590
|
+
else if (k === 'o') { onion = !onion; buildStage(); }
|
|
23591
|
+
else if (k === 'p') { pingpong = !pingpong; buildStage(); }
|
|
23592
|
+
else if (/^[1-5]$/.test(k)) setFilter(FILTERS[Number(k) - 1][0]);
|
|
23593
|
+
else if (k === 'Escape' && armedReroll) { armedReroll = null; say(''); buildStage(); }
|
|
23594
|
+
else return;
|
|
23595
|
+
e.preventDefault();
|
|
23596
|
+
});
|
|
23597
|
+
|
|
23598
|
+
const press = (id, fn) => $(id).addEventListener('click', (e) => { fn(); e.currentTarget.blur(); });
|
|
23599
|
+
press('a-accept', accept);
|
|
23600
|
+
press('a-flag', flag);
|
|
23601
|
+
press('a-later', later);
|
|
23602
|
+
press('a-reroll', reroll);
|
|
23603
|
+
press('t-play', togglePlay);
|
|
23604
|
+
press('t-flip', () => { const g = group(currentKey); if (g) { flipped = (flipped + 1) % views(g).length; buildStage(); } });
|
|
23605
|
+
press('t-strip', () => { showStrip = !showStrip; buildStage(); });
|
|
23606
|
+
press('t-onion', () => { onion = !onion; buildStage(); });
|
|
23607
|
+
press('t-pong', () => { pingpong = !pingpong; buildStage(); });
|
|
23608
|
+
press('select-all', () => batch('select'));
|
|
23609
|
+
press('deselect-all', () => batch('deselect'));
|
|
23610
|
+
press('accept-unflagged', () => batch('unflagged'));
|
|
23611
|
+
press('apply', apply);
|
|
23612
|
+
window.addEventListener('resize', () => { dirty = true; });
|
|
23613
|
+
document.addEventListener('visibilitychange', () => { lastTick = 0; });
|
|
23614
|
+
|
|
23615
|
+
// ---- boot ------------------------------------------------------------------
|
|
23616
|
+
for (const g of GROUPS) recall(g);
|
|
23617
|
+
buildFilters();
|
|
23618
|
+
buildList();
|
|
23619
|
+
refresh();
|
|
23620
|
+
list.focus({ preventScroll: true });
|
|
23621
|
+
requestAnimationFrame(tick);
|
|
23622
|
+
if (CONFIG.sessionUrl) {
|
|
23623
|
+
sync().then(() => { if (Object.values(rerolls).some((r) => r.state === 'running')) watch(); })
|
|
23624
|
+
.catch((err) => say('Could not load saved selections: ' + err.message, true));
|
|
23625
|
+
}
|
|
23626
|
+
`;
|
|
23627
|
+
|
|
23119
23628
|
// src/pick/review-server.ts
|
|
23120
23629
|
import { createServer } from "http";
|
|
23121
23630
|
import { readFile as readFile24 } from "fs/promises";
|
|
23631
|
+
async function readJsonBody(req, res) {
|
|
23632
|
+
const expectedOrigin = req.headers.host ? `http://${req.headers.host}` : null;
|
|
23633
|
+
if (req.headers.origin && req.headers.origin !== expectedOrigin) {
|
|
23634
|
+
res.writeHead(403, { "Content-Type": "text/plain" });
|
|
23635
|
+
res.end("cross-origin review submissions are not allowed");
|
|
23636
|
+
return { ok: false };
|
|
23637
|
+
}
|
|
23638
|
+
if (!req.headers["content-type"]?.toLowerCase().startsWith("application/json")) {
|
|
23639
|
+
res.writeHead(415, { "Content-Type": "text/plain" });
|
|
23640
|
+
res.end("application/json is required");
|
|
23641
|
+
return { ok: false };
|
|
23642
|
+
}
|
|
23643
|
+
const chunks = [];
|
|
23644
|
+
let bytes = 0;
|
|
23645
|
+
for await (const c of req) {
|
|
23646
|
+
const chunk2 = c;
|
|
23647
|
+
bytes += chunk2.length;
|
|
23648
|
+
if (bytes > 64 * 1024) {
|
|
23649
|
+
res.writeHead(413, { "Content-Type": "text/plain" });
|
|
23650
|
+
res.end("review submission is too large");
|
|
23651
|
+
return { ok: false };
|
|
23652
|
+
}
|
|
23653
|
+
chunks.push(chunk2);
|
|
23654
|
+
}
|
|
23655
|
+
return { ok: true, body: JSON.parse(Buffer.concat(chunks).toString("utf8")) };
|
|
23656
|
+
}
|
|
23122
23657
|
function serveReviewPage(opts) {
|
|
23123
23658
|
const log = opts.onProgress ?? (() => {
|
|
23124
23659
|
});
|
|
@@ -23130,7 +23665,9 @@ function serveReviewPage(opts) {
|
|
|
23130
23665
|
const bytes = await readFile24(asset.path);
|
|
23131
23666
|
res.writeHead(200, {
|
|
23132
23667
|
"Content-Type": asset.contentType,
|
|
23133
|
-
|
|
23668
|
+
// A frame route names one cached candidate for the life of this
|
|
23669
|
+
// server, so the browser may keep it; everything else is re-read.
|
|
23670
|
+
"Cache-Control": req.url.includes("/review-frame/") ? "private, max-age=86400, immutable" : "no-store",
|
|
23134
23671
|
"X-Content-Type-Options": "nosniff"
|
|
23135
23672
|
});
|
|
23136
23673
|
res.end(bytes);
|
|
@@ -23142,39 +23679,38 @@ function serveReviewPage(opts) {
|
|
|
23142
23679
|
}
|
|
23143
23680
|
if (req.method === "GET" && (req.url === "/" || req.url?.startsWith("/?"))) {
|
|
23144
23681
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
23145
|
-
res.end(opts.html);
|
|
23682
|
+
res.end(typeof opts.html === "function" ? opts.html() : opts.html);
|
|
23146
23683
|
return;
|
|
23147
23684
|
}
|
|
23148
|
-
if (req.method === "
|
|
23149
|
-
|
|
23150
|
-
|
|
23151
|
-
|
|
23152
|
-
|
|
23153
|
-
|
|
23154
|
-
|
|
23155
|
-
|
|
23156
|
-
|
|
23157
|
-
|
|
23685
|
+
if (opts.handleRequest && req.url && req.url !== "/apply" && (req.method === "GET" || req.method === "POST")) {
|
|
23686
|
+
try {
|
|
23687
|
+
let body = void 0;
|
|
23688
|
+
if (req.method === "POST") {
|
|
23689
|
+
const parsed = await readJsonBody(req, res);
|
|
23690
|
+
if (!parsed.ok) return;
|
|
23691
|
+
body = parsed.body;
|
|
23692
|
+
}
|
|
23693
|
+
const handled = await opts.handleRequest(req.method, req.url, body);
|
|
23694
|
+
if (handled) {
|
|
23695
|
+
res.writeHead(handled.status, { "Content-Type": "application/json", "Cache-Control": "no-store" });
|
|
23696
|
+
res.end(JSON.stringify(handled.body));
|
|
23697
|
+
return;
|
|
23698
|
+
}
|
|
23699
|
+
} catch (err) {
|
|
23700
|
+
res.writeHead(400, { "Content-Type": "text/plain" });
|
|
23701
|
+
res.end(err instanceof Error ? err.message : String(err));
|
|
23158
23702
|
return;
|
|
23159
23703
|
}
|
|
23704
|
+
}
|
|
23705
|
+
if (req.method === "POST" && req.url === "/apply") {
|
|
23160
23706
|
try {
|
|
23161
|
-
const
|
|
23162
|
-
|
|
23163
|
-
|
|
23164
|
-
const chunk2 = c;
|
|
23165
|
-
bytes += chunk2.length;
|
|
23166
|
-
if (bytes > 64 * 1024) {
|
|
23167
|
-
res.writeHead(413, { "Content-Type": "text/plain" });
|
|
23168
|
-
res.end("review submission is too large");
|
|
23169
|
-
return;
|
|
23170
|
-
}
|
|
23171
|
-
chunks.push(chunk2);
|
|
23172
|
-
}
|
|
23173
|
-
const body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
23174
|
-
const result = await opts.handleApply(body);
|
|
23707
|
+
const parsed = await readJsonBody(req, res);
|
|
23708
|
+
if (!parsed.ok) return;
|
|
23709
|
+
const result = await opts.handleApply(parsed.body);
|
|
23175
23710
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
23176
23711
|
res.end(JSON.stringify(result));
|
|
23177
23712
|
server.close(() => resolve(result));
|
|
23713
|
+
res.on("finish", () => server.closeIdleConnections?.());
|
|
23178
23714
|
} catch (err) {
|
|
23179
23715
|
const message6 = err instanceof Error ? err.message : String(err);
|
|
23180
23716
|
log(` apply failed: ${message6}`);
|
|
@@ -23280,11 +23816,11 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
23280
23816
|
continue;
|
|
23281
23817
|
}
|
|
23282
23818
|
frameSizes.push(cached2.contentType === "image/png" ? pngSize(await readFile25(cached2.path).catch(() => Buffer.alloc(0))) : null);
|
|
23283
|
-
const route = `${prefix}/review-frame/${encodeURIComponent(String(groups.length))}/${index}`;
|
|
23819
|
+
const route = `${prefix}/review-frame/${encodeURIComponent(String((opts.routeBase ?? 0) + groups.length))}/${index}`;
|
|
23284
23820
|
frameAssets.push([route, cached2]);
|
|
23285
23821
|
frameUrls.push(route);
|
|
23286
23822
|
}
|
|
23287
|
-
const sourceRoute = spec?.revision ? `${prefix}/revision-source/${encodeURIComponent(String(groups.length))}` : null;
|
|
23823
|
+
const sourceRoute = spec?.revision ? `${prefix}/revision-source/${encodeURIComponent(String((opts.routeBase ?? 0) + groups.length))}` : null;
|
|
23288
23824
|
if (sourceRoute && spec?.revision) {
|
|
23289
23825
|
reviewAssets.set(sourceRoute, {
|
|
23290
23826
|
path: spec.revision.sourceFile,
|
|
@@ -23292,7 +23828,7 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
23292
23828
|
});
|
|
23293
23829
|
}
|
|
23294
23830
|
const current = await currentArt(entry, spec);
|
|
23295
|
-
const currentRoute = current ? `${prefix}/current-art/${encodeURIComponent(String(groups.length))}` : null;
|
|
23831
|
+
const currentRoute = current ? `${prefix}/current-art/${encodeURIComponent(String((opts.routeBase ?? 0) + groups.length))}` : null;
|
|
23296
23832
|
if (current && currentRoute) {
|
|
23297
23833
|
reviewAssets.set(currentRoute, { path: current.path, contentType: current.contentType });
|
|
23298
23834
|
}
|
|
@@ -23443,6 +23979,130 @@ async function prepareReview(provider, lock, opts = {}) {
|
|
|
23443
23979
|
}
|
|
23444
23980
|
};
|
|
23445
23981
|
}
|
|
23982
|
+
function createReviewHost(provider, lock, lockPath, first, opts = {}) {
|
|
23983
|
+
const log = opts.onProgress ?? (() => {
|
|
23984
|
+
});
|
|
23985
|
+
const statePath = reviewStatePathFor(lockPath);
|
|
23986
|
+
let groups = [...first.groups];
|
|
23987
|
+
const owner = new Map(groups.map((g) => [g.key, first]));
|
|
23988
|
+
const assets = new Map(first.assets);
|
|
23989
|
+
const memory = /* @__PURE__ */ new Map();
|
|
23990
|
+
const rerolls = /* @__PURE__ */ new Map();
|
|
23991
|
+
const running = /* @__PURE__ */ new Set();
|
|
23992
|
+
let nextRoute = groups.length;
|
|
23993
|
+
const readState = async () => {
|
|
23994
|
+
const saved = (await loadReviewState(statePath)).assets;
|
|
23995
|
+
const out = {};
|
|
23996
|
+
for (const g of groups) {
|
|
23997
|
+
const record = saved[g.key];
|
|
23998
|
+
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 };
|
|
23999
|
+
}
|
|
24000
|
+
return out;
|
|
24001
|
+
};
|
|
24002
|
+
const writeState = async (body) => {
|
|
24003
|
+
const { key: key3, chosen, flagged, later } = body ?? {};
|
|
24004
|
+
const group = groups.find((g) => g.key === key3);
|
|
24005
|
+
if (!group) throw new Error(`${String(key3)} is not on this review page`);
|
|
24006
|
+
const count = group.frameUrls.length;
|
|
24007
|
+
const index = (n) => typeof n === "number" && Number.isInteger(n) && n >= 0 && n < count;
|
|
24008
|
+
if (chosen !== null && chosen !== void 0 && !index(chosen)) throw new Error(`chosen must be a candidate index below ${count}`);
|
|
24009
|
+
if (flagged !== void 0 && (!Array.isArray(flagged) || !flagged.every(index))) throw new Error("flagged must list frame indexes");
|
|
24010
|
+
const next = {
|
|
24011
|
+
chosen: chosen ?? null,
|
|
24012
|
+
flagged: [...new Set(flagged ?? [])].sort((a, b) => a - b),
|
|
24013
|
+
later: later === true
|
|
24014
|
+
};
|
|
24015
|
+
const saved = await updateReviewAsset(
|
|
24016
|
+
statePath,
|
|
24017
|
+
group.key,
|
|
24018
|
+
(asset) => asset.jobId !== group.reviewObjectId ? asset : {
|
|
24019
|
+
...asset,
|
|
24020
|
+
chosen: next.chosen,
|
|
24021
|
+
...next.flagged.length ? { flagged: next.flagged } : { flagged: void 0 },
|
|
24022
|
+
...next.later ? { later: true } : { later: void 0 }
|
|
24023
|
+
}
|
|
24024
|
+
);
|
|
24025
|
+
if (!saved || saved.jobId !== group.reviewObjectId) memory.set(group.key, next);
|
|
24026
|
+
return next;
|
|
24027
|
+
};
|
|
24028
|
+
const startReroll = (key3) => {
|
|
24029
|
+
if (!opts.reroll) throw new Error("this review page cannot reroll; run gen --force for the asset");
|
|
24030
|
+
if (!groups.some((g) => g.key === key3)) throw new Error(`${key3} is not on this review page`);
|
|
24031
|
+
if (rerolls.get(key3)?.state === "running") return;
|
|
24032
|
+
rerolls.set(key3, { state: "running" });
|
|
24033
|
+
log(` rerolling ${key3} (--force)\u2026`);
|
|
24034
|
+
const job = (async () => {
|
|
24035
|
+
await opts.reroll(key3);
|
|
24036
|
+
const session = await prepareReview(provider, lock, {
|
|
24037
|
+
keys: [key3],
|
|
24038
|
+
specs: opts.specs,
|
|
24039
|
+
onProgress: log,
|
|
24040
|
+
lockPath,
|
|
24041
|
+
routeBase: nextRoute
|
|
24042
|
+
});
|
|
24043
|
+
const fresh = session?.groups.find((g) => g.key === key3);
|
|
24044
|
+
if (!session || !fresh) throw new Error(`${key3} did not come back into review`);
|
|
24045
|
+
nextRoute += session.groups.length;
|
|
24046
|
+
for (const [route, asset] of session.assets) assets.set(route, asset);
|
|
24047
|
+
groups = groups.map((g) => g.key === key3 ? fresh : g);
|
|
24048
|
+
owner.set(key3, session);
|
|
24049
|
+
memory.delete(key3);
|
|
24050
|
+
rerolls.delete(key3);
|
|
24051
|
+
log(` ${key3}: new candidate ready on the review page`);
|
|
24052
|
+
})().catch((err) => {
|
|
24053
|
+
const message6 = err instanceof Error ? err.message : String(err);
|
|
24054
|
+
rerolls.set(key3, { state: "failed", error: message6 });
|
|
24055
|
+
log(` reroll ${key3} failed: ${message6}`);
|
|
24056
|
+
});
|
|
24057
|
+
running.add(job);
|
|
24058
|
+
void job.finally(() => running.delete(job));
|
|
24059
|
+
};
|
|
24060
|
+
return {
|
|
24061
|
+
groups: () => groups,
|
|
24062
|
+
assets,
|
|
24063
|
+
html: () => renderSheet(groups, { sessionUrl: "/session", stateUrl: "/state", rerollUrl: opts.reroll ? "/reroll" : void 0 }),
|
|
24064
|
+
async apply(body) {
|
|
24065
|
+
if ([...rerolls.values()].some((r) => r.state === "running")) {
|
|
24066
|
+
throw new Error("a reroll is still running; apply once it is back");
|
|
24067
|
+
}
|
|
24068
|
+
const { selections } = body ?? {};
|
|
24069
|
+
if (!Array.isArray(selections)) throw new Error("selections must be a list");
|
|
24070
|
+
const bySession = /* @__PURE__ */ new Map();
|
|
24071
|
+
for (const selection of selections) {
|
|
24072
|
+
const session = owner.get(selection?.key);
|
|
24073
|
+
if (!session) continue;
|
|
24074
|
+
bySession.set(session, [...bySession.get(session) ?? [], selection]);
|
|
24075
|
+
}
|
|
24076
|
+
let selected = 0;
|
|
24077
|
+
for (const [session, picks] of bySession) selected += (await session.apply({ selections: picks }, lockPath)).selected;
|
|
24078
|
+
return { selected, skipped: groups.length - selected };
|
|
24079
|
+
},
|
|
24080
|
+
async handleRequest(method, url, body) {
|
|
24081
|
+
if (method === "GET" && url === "/session") {
|
|
24082
|
+
return {
|
|
24083
|
+
status: 200,
|
|
24084
|
+
body: {
|
|
24085
|
+
groups: renderableGroups(groups),
|
|
24086
|
+
state: await readState(),
|
|
24087
|
+
rerolls: Object.fromEntries(rerolls),
|
|
24088
|
+
canReroll: Boolean(opts.reroll)
|
|
24089
|
+
}
|
|
24090
|
+
};
|
|
24091
|
+
}
|
|
24092
|
+
if (method === "POST" && url === "/state") return { status: 200, body: await writeState(body) };
|
|
24093
|
+
if (method === "POST" && url === "/reroll") {
|
|
24094
|
+
const key3 = body?.key;
|
|
24095
|
+
if (typeof key3 !== "string") throw new Error("key is required");
|
|
24096
|
+
startReroll(key3);
|
|
24097
|
+
return { status: 202, body: { key: key3, ...rerolls.get(key3) } };
|
|
24098
|
+
}
|
|
24099
|
+
return void 0;
|
|
24100
|
+
},
|
|
24101
|
+
async idle() {
|
|
24102
|
+
while (running.size) await Promise.all([...running]);
|
|
24103
|
+
}
|
|
24104
|
+
};
|
|
24105
|
+
}
|
|
23446
24106
|
async function runPicker(provider, lock, lockPath, opts = {}) {
|
|
23447
24107
|
const log = opts.onProgress ?? (() => {
|
|
23448
24108
|
});
|
|
@@ -23461,30 +24121,34 @@ async function runPicker(provider, lock, lockPath, opts = {}) {
|
|
|
23461
24121
|
autoSelected = res.selected;
|
|
23462
24122
|
log(` --yes: accepted ${res.selected} single-candidate asset(s)`);
|
|
23463
24123
|
const rest = session.groups.filter((g) => !singles.includes(g)).map((g) => g.key);
|
|
23464
|
-
session = rest.length ? await prepareReview(provider, lock, { onProgress: log, keys: rest, specs: opts.specs }) : null;
|
|
24124
|
+
session = rest.length ? await prepareReview(provider, lock, { onProgress: log, keys: rest, specs: opts.specs, lockPath }) : null;
|
|
23465
24125
|
if (!session) return { selected: autoSelected, skipped: 0 };
|
|
23466
24126
|
}
|
|
23467
24127
|
}
|
|
23468
|
-
const
|
|
23469
|
-
|
|
24128
|
+
const host = createReviewHost(provider, lock, lockPath, session, {
|
|
24129
|
+
specs: opts.specs,
|
|
24130
|
+
onProgress: log,
|
|
24131
|
+
reroll: opts.reroll
|
|
24132
|
+
});
|
|
23470
24133
|
const served = await serveReviewPage({
|
|
23471
|
-
html:
|
|
24134
|
+
html: host.html,
|
|
23472
24135
|
port: opts.port,
|
|
23473
24136
|
open: opts.open,
|
|
23474
24137
|
onProgress: log,
|
|
23475
|
-
assets:
|
|
24138
|
+
assets: host.assets,
|
|
24139
|
+
handleRequest: host.handleRequest,
|
|
23476
24140
|
onReady: (url) => {
|
|
23477
|
-
const info = { url, keys: groups.map((group) => group.key) };
|
|
24141
|
+
const info = { url, keys: host.groups().map((group) => group.key) };
|
|
23478
24142
|
if (opts.onReady) {
|
|
23479
24143
|
opts.onReady(info);
|
|
23480
24144
|
} else {
|
|
23481
24145
|
log(`
|
|
23482
|
-
${
|
|
24146
|
+
${info.keys.length} asset(s) awaiting selection: ${url}`);
|
|
23483
24147
|
log(` (leave this running; it exits once you apply)
|
|
23484
24148
|
`);
|
|
23485
24149
|
}
|
|
23486
24150
|
},
|
|
23487
|
-
handleApply:
|
|
24151
|
+
handleApply: host.apply
|
|
23488
24152
|
});
|
|
23489
24153
|
return { selected: served.selected + autoSelected, skipped: served.skipped };
|
|
23490
24154
|
}
|
|
@@ -23515,7 +24179,7 @@ function parseGlb(bytes) {
|
|
|
23515
24179
|
const total = view.getUint32(8, true);
|
|
23516
24180
|
if (total > bytes.length) throw new Error(`invalid glb: header says ${total} bytes, the file has ${bytes.length}`);
|
|
23517
24181
|
let offset = 12;
|
|
23518
|
-
let
|
|
24182
|
+
let json2 = null;
|
|
23519
24183
|
let bin = null;
|
|
23520
24184
|
const extraChunks = [];
|
|
23521
24185
|
while (offset + 8 <= total) {
|
|
@@ -23524,7 +24188,7 @@ function parseGlb(bytes) {
|
|
|
23524
24188
|
const start = offset + 8;
|
|
23525
24189
|
if (start + length > total) throw new Error("invalid glb: a chunk runs past the end of the file");
|
|
23526
24190
|
const data = bytes.subarray(start, start + length);
|
|
23527
|
-
if (type === CHUNK_JSON && !
|
|
24191
|
+
if (type === CHUNK_JSON && !json2) {
|
|
23528
24192
|
let parsed;
|
|
23529
24193
|
try {
|
|
23530
24194
|
parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(data));
|
|
@@ -23532,7 +24196,7 @@ function parseGlb(bytes) {
|
|
|
23532
24196
|
throw new Error(`invalid glb: the JSON chunk does not parse (${error instanceof Error ? error.message : String(error)})`);
|
|
23533
24197
|
}
|
|
23534
24198
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("invalid glb: the JSON chunk is not an object");
|
|
23535
|
-
|
|
24199
|
+
json2 = parsed;
|
|
23536
24200
|
} else if (type === CHUNK_BIN && !bin) {
|
|
23537
24201
|
bin = data;
|
|
23538
24202
|
} else {
|
|
@@ -23540,15 +24204,15 @@ function parseGlb(bytes) {
|
|
|
23540
24204
|
}
|
|
23541
24205
|
offset = start + pad4(length);
|
|
23542
24206
|
}
|
|
23543
|
-
if (!
|
|
23544
|
-
if (!
|
|
23545
|
-
const declared =
|
|
24207
|
+
if (!json2) throw new Error("invalid glb: no JSON chunk");
|
|
24208
|
+
if (!json2.asset || typeof json2.asset.version !== "string") throw new Error("invalid glb: the JSON has no asset.version");
|
|
24209
|
+
const declared = json2.buffers?.[0]?.byteLength;
|
|
23546
24210
|
if (bin && typeof declared === "number") {
|
|
23547
24211
|
if (declared > bin.length) throw new Error(`invalid glb: buffer 0 declares ${declared} bytes, the BIN chunk has ${bin.length}`);
|
|
23548
24212
|
bin = bin.subarray(0, declared);
|
|
23549
24213
|
}
|
|
23550
|
-
const document = { json, bin: bin ?? new Uint8Array(0), extraChunks };
|
|
23551
|
-
for (const [index, bufferView] of (
|
|
24214
|
+
const document = { json: json2, bin: bin ?? new Uint8Array(0), extraChunks };
|
|
24215
|
+
for (const [index, bufferView] of (json2.bufferViews ?? []).entries()) {
|
|
23552
24216
|
if (bufferView.buffer !== 0) continue;
|
|
23553
24217
|
const start = bufferView.byteOffset ?? 0;
|
|
23554
24218
|
if (start < 0 || bufferView.byteLength < 0 || start + bufferView.byteLength > document.bin.length) {
|
|
@@ -23558,8 +24222,8 @@ function parseGlb(bytes) {
|
|
|
23558
24222
|
return document;
|
|
23559
24223
|
}
|
|
23560
24224
|
function serializeGlb(document) {
|
|
23561
|
-
const
|
|
23562
|
-
const jsonLength = pad4(
|
|
24225
|
+
const json2 = new TextEncoder().encode(JSON.stringify(document.json));
|
|
24226
|
+
const jsonLength = pad4(json2.length);
|
|
23563
24227
|
const hasBin = document.bin.length > 0;
|
|
23564
24228
|
const binLength = pad4(document.bin.length);
|
|
23565
24229
|
const extra = document.extraChunks.reduce((sum, chunk2) => sum + 8 + pad4(chunk2.data.length), 0);
|
|
@@ -23572,8 +24236,8 @@ function serializeGlb(document) {
|
|
|
23572
24236
|
let offset = 12;
|
|
23573
24237
|
view.setUint32(offset, jsonLength, true);
|
|
23574
24238
|
view.setUint32(offset + 4, CHUNK_JSON, true);
|
|
23575
|
-
out.set(
|
|
23576
|
-
out.fill(32, offset + 8 +
|
|
24239
|
+
out.set(json2, offset + 8);
|
|
24240
|
+
out.fill(32, offset + 8 + json2.length, offset + 8 + jsonLength);
|
|
23577
24241
|
offset += 8 + jsonLength;
|
|
23578
24242
|
if (hasBin) {
|
|
23579
24243
|
view.setUint32(offset, binLength, true);
|
|
@@ -23634,9 +24298,9 @@ function replaceGlbImage(document, imageIndex, bytes, mimeType) {
|
|
|
23634
24298
|
const source = document.json;
|
|
23635
24299
|
const image = source.images?.[imageIndex];
|
|
23636
24300
|
if (!image) throw new Error(`the model has no image ${imageIndex}`);
|
|
23637
|
-
const
|
|
23638
|
-
const views =
|
|
23639
|
-
const target =
|
|
24301
|
+
const json2 = structuredCloneJson(source);
|
|
24302
|
+
const views = json2.bufferViews ??= [];
|
|
24303
|
+
const target = json2.images[imageIndex];
|
|
23640
24304
|
const viewIndex = typeof image.bufferView === "number" ? image.bufferView : -1;
|
|
23641
24305
|
const old = viewIndex >= 0 ? source.bufferViews?.[viewIndex] : void 0;
|
|
23642
24306
|
const usedElsewhere = viewIndex >= 0 && ((source.images ?? []).some((other, index) => index !== imageIndex && other.bufferView === viewIndex) || (source.accessors ?? []).some((accessor) => accessor.bufferView === viewIndex));
|
|
@@ -23677,9 +24341,9 @@ function replaceGlbImage(document, imageIndex, bytes, mimeType) {
|
|
|
23677
24341
|
}
|
|
23678
24342
|
}
|
|
23679
24343
|
target.mimeType = mimeType;
|
|
23680
|
-
|
|
23681
|
-
|
|
23682
|
-
return { json, bin, extraChunks: document.extraChunks };
|
|
24344
|
+
json2.buffers = json2.buffers?.length ? json2.buffers : [{ byteLength: 0 }];
|
|
24345
|
+
json2.buffers[0] = { ...json2.buffers[0], byteLength: bin.length };
|
|
24346
|
+
return { json: json2, bin, extraChunks: document.extraChunks };
|
|
23683
24347
|
}
|
|
23684
24348
|
function structuredCloneJson(value) {
|
|
23685
24349
|
return JSON.parse(JSON.stringify(value));
|
|
@@ -23737,8 +24401,8 @@ function readAccessor(document, accessorIndex) {
|
|
|
23737
24401
|
return { data: out, size, count: accessor.count };
|
|
23738
24402
|
}
|
|
23739
24403
|
function describeGlb(document) {
|
|
23740
|
-
const
|
|
23741
|
-
const images = (
|
|
24404
|
+
const json2 = document.json;
|
|
24405
|
+
const images = (json2.images ?? []).map((image, index) => {
|
|
23742
24406
|
let info = null;
|
|
23743
24407
|
let bytes = null;
|
|
23744
24408
|
const embedded = typeof image.bufferView === "number";
|
|
@@ -23762,9 +24426,9 @@ function describeGlb(document) {
|
|
|
23762
24426
|
meshes: []
|
|
23763
24427
|
};
|
|
23764
24428
|
});
|
|
23765
|
-
const imageOfTexture = (info) => info && typeof info.index === "number" ?
|
|
24429
|
+
const imageOfTexture = (info) => info && typeof info.index === "number" ? json2.textures?.[info.index]?.source : void 0;
|
|
23766
24430
|
const meshesOfMaterial = /* @__PURE__ */ new Map();
|
|
23767
|
-
for (const [meshIndex, mesh] of (
|
|
24431
|
+
for (const [meshIndex, mesh] of (json2.meshes ?? []).entries()) {
|
|
23768
24432
|
for (const primitive of mesh.primitives ?? []) {
|
|
23769
24433
|
if (typeof primitive.material !== "number") continue;
|
|
23770
24434
|
const names = meshesOfMaterial.get(primitive.material) ?? [];
|
|
@@ -23773,7 +24437,7 @@ function describeGlb(document) {
|
|
|
23773
24437
|
meshesOfMaterial.set(primitive.material, names);
|
|
23774
24438
|
}
|
|
23775
24439
|
}
|
|
23776
|
-
for (const [materialIndex, material] of (
|
|
24440
|
+
for (const [materialIndex, material] of (json2.materials ?? []).entries()) {
|
|
23777
24441
|
const uses = [
|
|
23778
24442
|
["baseColor", material.pbrMetallicRoughness?.baseColorTexture],
|
|
23779
24443
|
["normal", material.normalTexture],
|
|
@@ -23793,39 +24457,39 @@ function describeGlb(document) {
|
|
|
23793
24457
|
}
|
|
23794
24458
|
}
|
|
23795
24459
|
const bones = [];
|
|
23796
|
-
for (const skin of
|
|
24460
|
+
for (const skin of json2.skins ?? []) {
|
|
23797
24461
|
for (const joint of skin.joints ?? []) {
|
|
23798
|
-
const name =
|
|
24462
|
+
const name = json2.nodes?.[joint]?.name ?? `node ${joint}`;
|
|
23799
24463
|
if (!bones.includes(name)) bones.push(name);
|
|
23800
24464
|
}
|
|
23801
24465
|
}
|
|
23802
|
-
const meshes = (
|
|
24466
|
+
const meshes = (json2.meshes ?? []).map((mesh, index) => {
|
|
23803
24467
|
let vertices = 0;
|
|
23804
24468
|
let triangles = 0;
|
|
23805
24469
|
for (const primitive of mesh.primitives ?? []) {
|
|
23806
|
-
const position =
|
|
24470
|
+
const position = json2.accessors?.[primitive.attributes?.POSITION ?? -1];
|
|
23807
24471
|
const count = position?.count ?? 0;
|
|
23808
24472
|
vertices += count;
|
|
23809
24473
|
if ((primitive.mode ?? 4) === 4) {
|
|
23810
|
-
triangles += Math.floor((typeof primitive.indices === "number" ?
|
|
24474
|
+
triangles += Math.floor((typeof primitive.indices === "number" ? json2.accessors?.[primitive.indices]?.count ?? 0 : count) / 3);
|
|
23811
24475
|
}
|
|
23812
24476
|
}
|
|
23813
24477
|
return { name: mesh.name ?? `mesh ${index}`, primitives: mesh.primitives?.length ?? 0, vertices, triangles };
|
|
23814
24478
|
});
|
|
23815
24479
|
return {
|
|
23816
|
-
generator: typeof
|
|
24480
|
+
generator: typeof json2.asset.generator === "string" ? json2.asset.generator : null,
|
|
23817
24481
|
meshes,
|
|
23818
24482
|
bones,
|
|
23819
|
-
animations: (
|
|
24483
|
+
animations: (json2.animations ?? []).map((animation, index) => animation.name ?? `animation ${index}`),
|
|
23820
24484
|
images,
|
|
23821
|
-
items: modelItems(
|
|
24485
|
+
items: modelItems(json2)
|
|
23822
24486
|
};
|
|
23823
24487
|
}
|
|
23824
24488
|
function isBodyNode(node) {
|
|
23825
24489
|
return Array.isArray(node.extras?.hiddenBy) || node.extras?.body === true;
|
|
23826
24490
|
}
|
|
23827
|
-
function modelItems(
|
|
23828
|
-
const meshNodes = (
|
|
24491
|
+
function modelItems(json2) {
|
|
24492
|
+
const meshNodes = (json2.nodes ?? []).filter((node) => typeof node.mesh === "number");
|
|
23829
24493
|
if (!meshNodes.some(isBodyNode)) return meshNodes.length > 1 ? meshNodes.map((node, index) => node.name ?? `part ${index + 1}`) : [];
|
|
23830
24494
|
return meshNodes.filter((node) => !isBodyNode(node)).map((node, index) => node.name ?? `part ${index + 1}`);
|
|
23831
24495
|
}
|
|
@@ -25385,14 +26049,14 @@ function poseNodes(document, pose) {
|
|
|
25385
26049
|
return posed;
|
|
25386
26050
|
}
|
|
25387
26051
|
function restPrimitives(document, pose) {
|
|
25388
|
-
const
|
|
26052
|
+
const json2 = document.json;
|
|
25389
26053
|
const world = worldMatrices(document, pose ? poseNodes(document, pose) : void 0);
|
|
25390
26054
|
const out = [];
|
|
25391
|
-
for (const [nodeIndex, node] of (
|
|
26055
|
+
for (const [nodeIndex, node] of (json2.nodes ?? []).entries()) {
|
|
25392
26056
|
if (typeof node.mesh !== "number") continue;
|
|
25393
|
-
const mesh =
|
|
26057
|
+
const mesh = json2.meshes?.[node.mesh];
|
|
25394
26058
|
if (!mesh) continue;
|
|
25395
|
-
const skin = typeof node.skin === "number" ?
|
|
26059
|
+
const skin = typeof node.skin === "number" ? json2.skins?.[node.skin] : void 0;
|
|
25396
26060
|
let jointMatrices = null;
|
|
25397
26061
|
if (skin) {
|
|
25398
26062
|
const inverse = typeof skin.inverseBindMatrices === "number" ? readAccessor(document, skin.inverseBindMatrices) : null;
|
|
@@ -28024,7 +28688,7 @@ var EDITOR_CSP = [
|
|
|
28024
28688
|
"connect-src 'self'",
|
|
28025
28689
|
"frame-ancestors 'self'"
|
|
28026
28690
|
].join("; ");
|
|
28027
|
-
async function
|
|
28691
|
+
async function readJsonBody2(req) {
|
|
28028
28692
|
const chunks = [];
|
|
28029
28693
|
let bytes = 0;
|
|
28030
28694
|
for await (const chunk2 of req) {
|
|
@@ -28062,7 +28726,7 @@ async function serveGallery(opts) {
|
|
|
28062
28726
|
res.writeHead(status, { "Content-Type": "text/plain; charset=utf-8" });
|
|
28063
28727
|
res.end(message6);
|
|
28064
28728
|
};
|
|
28065
|
-
const
|
|
28729
|
+
const json2 = (status, value) => {
|
|
28066
28730
|
res.writeHead(status, {
|
|
28067
28731
|
"Content-Type": "application/json; charset=utf-8",
|
|
28068
28732
|
"Cache-Control": "no-store",
|
|
@@ -28084,7 +28748,7 @@ async function serveGallery(opts) {
|
|
|
28084
28748
|
fail(415, "application/json is required");
|
|
28085
28749
|
return void 0;
|
|
28086
28750
|
}
|
|
28087
|
-
return
|
|
28751
|
+
return readJsonBody2(req);
|
|
28088
28752
|
};
|
|
28089
28753
|
const reportError = (what, err) => {
|
|
28090
28754
|
const status = typeof err?.status === "number" ? err.status : 500;
|
|
@@ -28099,7 +28763,7 @@ async function serveGallery(opts) {
|
|
|
28099
28763
|
if (body === void 0) return;
|
|
28100
28764
|
const build = await opts.edit(body);
|
|
28101
28765
|
media = build.media;
|
|
28102
|
-
|
|
28766
|
+
json2(200, build.snapshot);
|
|
28103
28767
|
} catch (err) {
|
|
28104
28768
|
reportError("edit", err);
|
|
28105
28769
|
}
|
|
@@ -28110,7 +28774,7 @@ async function serveGallery(opts) {
|
|
|
28110
28774
|
try {
|
|
28111
28775
|
const body = await guardedBody("generation requests");
|
|
28112
28776
|
if (body === void 0) return;
|
|
28113
|
-
|
|
28777
|
+
json2(202, await opts.generate.start(body));
|
|
28114
28778
|
} catch (err) {
|
|
28115
28779
|
reportError("generate", err);
|
|
28116
28780
|
}
|
|
@@ -28121,7 +28785,7 @@ async function serveGallery(opts) {
|
|
|
28121
28785
|
try {
|
|
28122
28786
|
const body = await guardedBody("price requests");
|
|
28123
28787
|
if (body === void 0) return;
|
|
28124
|
-
|
|
28788
|
+
json2(200, await opts.price(body));
|
|
28125
28789
|
} catch (err) {
|
|
28126
28790
|
reportError("price", err);
|
|
28127
28791
|
}
|
|
@@ -28132,7 +28796,7 @@ async function serveGallery(opts) {
|
|
|
28132
28796
|
try {
|
|
28133
28797
|
const body = await guardedBody("skeleton estimates");
|
|
28134
28798
|
if (body === void 0) return;
|
|
28135
|
-
|
|
28799
|
+
json2(200, await opts.skeleton.estimate(body));
|
|
28136
28800
|
} catch (err) {
|
|
28137
28801
|
reportError("skeleton estimate", err);
|
|
28138
28802
|
}
|
|
@@ -28143,7 +28807,7 @@ async function serveGallery(opts) {
|
|
|
28143
28807
|
try {
|
|
28144
28808
|
const body = await guardedBody("editor installs");
|
|
28145
28809
|
if (body === void 0) return;
|
|
28146
|
-
|
|
28810
|
+
json2(202, await opts.editor.install());
|
|
28147
28811
|
} catch (err) {
|
|
28148
28812
|
reportError("editor install", err);
|
|
28149
28813
|
}
|
|
@@ -28158,7 +28822,7 @@ async function serveGallery(opts) {
|
|
|
28158
28822
|
if (body === void 0) return;
|
|
28159
28823
|
const result = await opts.generate.applyReview(jobId, body);
|
|
28160
28824
|
reviewAssets.delete(jobId);
|
|
28161
|
-
|
|
28825
|
+
json2(200, result);
|
|
28162
28826
|
} catch (err) {
|
|
28163
28827
|
reportError("review", err);
|
|
28164
28828
|
}
|
|
@@ -28210,16 +28874,16 @@ async function serveGallery(opts) {
|
|
|
28210
28874
|
if (req.method !== "GET" && req.method !== "HEAD") return fail(405, "the gallery is read-only");
|
|
28211
28875
|
if (url2.pathname === "/api/skeleton") {
|
|
28212
28876
|
if (!opts.skeleton) return fail(404, "skeleton estimates need the gallery started with --edit");
|
|
28213
|
-
return
|
|
28877
|
+
return json2(200, opts.skeleton.status());
|
|
28214
28878
|
}
|
|
28215
28879
|
if (url2.pathname === "/api/jobs") {
|
|
28216
28880
|
if (!opts.generate) return fail(404, "generation is off");
|
|
28217
|
-
return
|
|
28881
|
+
return json2(200, opts.generate.status());
|
|
28218
28882
|
}
|
|
28219
28883
|
if (url2.pathname === "/api/editor") {
|
|
28220
28884
|
if (!opts.editor) return fail(404, "the in-browser editor is off for this gallery");
|
|
28221
28885
|
try {
|
|
28222
|
-
return
|
|
28886
|
+
return json2(200, await opts.editor.status());
|
|
28223
28887
|
} catch (err) {
|
|
28224
28888
|
return reportError("editor status", err);
|
|
28225
28889
|
}
|