@rig-c/review 1.8.0 → 1.10.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/docs/DESIGN.md +38 -14
- package/docs/PANELS.md +37 -13
- package/docs/PARTS_VIEW.md +138 -30
- package/docs/REVIEW_PACKAGE.md +66 -0
- package/package.json +1 -1
- package/src/applied-context.ts +17 -4
- package/src/front.ts +5 -1
- package/src/parts-comment-crops.ts +3 -1
- package/src/parts-comparison.ts +25 -2
- package/src/parts-server.ts +11 -2
- package/src/parts-view.ts +87 -15
- package/src/rebuild.ts +84 -1
- package/src/retune-check.ts +1 -1
- package/src/server.ts +4 -2
- package/src/stage-parts.ts +81 -4
- package/web/catalog-en.ts +47 -1
- package/web/catalog-ko.ts +53 -7
- package/web/chest-editor.ts +3 -0
- package/web/main.ts +59 -13
- package/web/parts-flags.ts +9 -1
- package/web/parts.css +12 -3
- package/web/parts.html +3 -1
- package/web/parts.ts +132 -24
- package/web/rebuild-client.ts +15 -7
- package/web/stage-nav.ts +21 -6
package/web/parts.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {defaultPartsComparison,paintingRectangle} from '../src/parts-comparison.ts';
|
|
1
|
+
import {defaultPartsComparison,paintingRectangle,type PartsComparison} from '../src/parts-comparison.ts';
|
|
2
2
|
import {mountViewportPair} from './viewport-pair.ts';
|
|
3
3
|
import {createPartsViewport} from './parts-viewport-provider.ts';
|
|
4
4
|
import {bindStageComments,type CommentUiPose,type CommentCodec} from './stage-comments.ts';
|
|
5
5
|
import {parsePartsComment,snapImageRegion,type PartsComment} from '../src/parts-comment.ts';
|
|
6
6
|
import {projectMark,unprojectMark,region} from '../src/stage-comment.ts';
|
|
7
|
-
import {bindStageNav} from './stage-nav.ts';
|
|
7
|
+
import {bindStageNav,stagePartsSelectionIndex,type StagePartsState,type StagePartsWindow} from './stage-nav.ts';
|
|
8
8
|
/**
|
|
9
9
|
* The parts and atlas view (#348). Every part on its own, on a sentinel background, through the shared native-scale
|
|
10
10
|
* viewport controller; the footprints of the parts drawn in front of it; the producer's flags on it; and a
|
|
@@ -17,7 +17,7 @@ import {bindStageNav} from './stage-nav.ts';
|
|
|
17
17
|
import { bindDomI18n, onLanguageChange, setLinkLanguage, setLanguagePreference, t } from './i18n.ts';
|
|
18
18
|
import { pageInstanceAccess } from './instance-access.ts';
|
|
19
19
|
import { connectLiveWindow } from './live-connection.ts';
|
|
20
|
-
import { flagLabel } from './parts-flags.ts';
|
|
20
|
+
import { flagLabel, readingGroup, countedFlag } from './parts-flags.ts';
|
|
21
21
|
import { paintAssembly, pickAssembly, paintAssemblyOutline, frontParts, paintAlphaOnly, paintBackground, paintPart, paintMesh, paintOverlay, paintPaintingCrop, paintFootprints } from './parts-render.ts';
|
|
22
22
|
|
|
23
23
|
type Outcome = 'pending' | 'clean' | 'flagged';
|
|
@@ -27,9 +27,11 @@ interface Item { mesh?: Mesh; name: string; index: number; x: number; y: number;
|
|
|
27
27
|
interface Page { name: string; width: number; height: number; index: number }
|
|
28
28
|
type Flag =
|
|
29
29
|
| { id: string; item: string; source: 'mesh_report'; kind: 'faint'; art: number; maxAlpha: number; box: [number, number, number, number] }
|
|
30
|
-
| { id: string; item: string; source: 'check'; kind: 'check'; path: string; line: string; root: string; status: string | null; entry: Record<string, unknown
|
|
30
|
+
| { id: string; item: string; source: 'check'; kind: 'check'; path: string; line: string; root: string; status: string | null; entry: Record<string, unknown>; classification?: 'part' | 'pair' | 'evidence' | 'unclassified' };
|
|
31
31
|
interface ViewData {
|
|
32
|
-
|
|
32
|
+
inspectionSourceHash?:string;
|
|
33
|
+
draft?:{label:string;buildId:string;inspectionSourceHash:string;mappings:{part:string;skin:string;slot:string;attachment:string;vertices:number;triangles:number}[];evidence:unknown};draftUnavailable?:string;
|
|
34
|
+
differenceAvailable?:boolean;painting:{sha256:string;width:number;height:number}|null;sourceHash:string;mode: 'parts' | 'atlas'; title: string; rigSize: [number, number] | null; items: Item[]; pages: Page[]; flags: Flag[]; readings?: Flag[];
|
|
33
35
|
flagSources: string[]; flagMissing: string[]; verdictFile: string;
|
|
34
36
|
verdict: { comments?:PartsComment[];status: string; parts: Record<string, Entry> } | null; verdictStale: 'files' | 'flags' | null;
|
|
35
37
|
}
|
|
@@ -41,9 +43,13 @@ const $ = <T extends HTMLElement>(id: string) => document.getElementById(id) as
|
|
|
41
43
|
const access = pageInstanceAccess();
|
|
42
44
|
const stageEmbedded=new URL(location.href).searchParams.get('stageEmbed')==='1';
|
|
43
45
|
const stageSide=new URL(location.href).searchParams.get('side');
|
|
46
|
+
let stageBuild='inspected',stageRestore:StagePartsState|null=null;
|
|
47
|
+
let receiveSource:()=>void=()=>{};const sourceReady=new Promise<void>(resolve=>{receiveSource=resolve;});
|
|
48
|
+
if(typeof window!=='undefined')window.addEventListener('message',event=>{if(event.source===parent&&event.origin===location.origin&&event.data?.type==='review-stage-source'&&(event.data.buildId==='inspected'||/^[a-f0-9]{64}$/.test(event.data.buildId))){stageBuild=event.data.buildId;stageRestore=event.data.state??null;receiveSource();}});
|
|
49
|
+
const stageHeaders=()=>access.headers(stageEmbedded?{'X-Review-Stage-Build':stageBuild}:{});
|
|
44
50
|
const partsApi=stageEmbedded?(stageSide==='a'||stageSide==='b'?`/api/compare/${stageSide}/stage-parts`:'/api/stage-parts'):'/api/parts';
|
|
45
51
|
|
|
46
|
-
const state = { data: null as ViewData | null, selected: 0, zoom: 1, bg: 'green', alpha: false, footprints: false, comparison:defaultPartsComparison(), hidden: new Set<string>(), view: 'item' as 'item' | 'page' | 'assembled', page: 0, meshShown: new Set<string>(), verdict: new Map<string, Entry>() };
|
|
52
|
+
const state = { data: null as ViewData | null, selected: 0, zoom: 1, bg: 'green', alpha: false, footprints: false, comparison:defaultPartsComparison(), differenceThreshold:0, hidden: new Set<string>(), view: 'item' as 'item' | 'page' | 'assembled', page: 0, meshShown: new Set<string>(), verdict: new Map<string, Entry>() };
|
|
47
53
|
const comments:PartsComment[]=[];let commentUi:ReturnType<typeof bindStageComments>|null=null;let viewport:ReturnType<typeof createPartsViewport>|null=null;let painting=false;
|
|
48
54
|
const images = new Map<string, HTMLImageElement>();
|
|
49
55
|
|
|
@@ -54,7 +60,8 @@ function load(src: string): Promise<HTMLImageElement> {
|
|
|
54
60
|
const img = new Image();
|
|
55
61
|
img.onload = () => { images.set(src, img); resolve(img); };
|
|
56
62
|
img.onerror = () => reject(new Error(src));
|
|
57
|
-
|
|
63
|
+
if(stageEmbedded)void fetch(access.route(src),{headers:stageHeaders()}).then(async res=>{if(!res.ok)throw new Error('STAGE_DRAFT_CHANGED');const url=URL.createObjectURL(await res.blob());img.addEventListener('load',()=>URL.revokeObjectURL(url),{once:true});img.src=url;}).catch(reject);
|
|
64
|
+
else img.src = access.route(src);
|
|
58
65
|
});
|
|
59
66
|
}
|
|
60
67
|
const itemImage = (item: Item) => load(`${partsApi}/image/${item.index}`);
|
|
@@ -84,9 +91,9 @@ async function paint():Promise<void>{
|
|
|
84
91
|
await paintRaster(token);if(token!==paintToken)return;
|
|
85
92
|
await paintReference(token);if(token!==paintToken)return;
|
|
86
93
|
viewport?.fitCamera();if(paintFailure)$('pv-save-status').textContent='';paintFailure=null;commentUi?.refresh();
|
|
87
|
-
}catch{
|
|
94
|
+
}catch(error){
|
|
88
95
|
if(token!==paintToken)return;
|
|
89
|
-
paintFailure='PARTS_PAINT_FAILED: view could not be rendered; select the part to retry';
|
|
96
|
+
paintFailure=error instanceof Error&&error.message.startsWith('PARTS_DIFFERENCE_')?error.message:'PARTS_PAINT_FAILED: view could not be rendered; select the part to retry';
|
|
90
97
|
const canvas=$<HTMLCanvasElement>('pv-canvas');canvas.getContext('2d')?.clearRect(0,0,canvas.width,canvas.height);$('pv-overlay').replaceChildren();
|
|
91
98
|
$('pv-caption').textContent=t(paintFailure);$('pv-save-status').textContent=t(paintFailure);commentUi?.refresh();
|
|
92
99
|
}finally{if(token===paintToken)painting=false;}
|
|
@@ -155,6 +162,14 @@ async function paintRaster(token:number): Promise<void> {
|
|
|
155
162
|
caption.textContent = t('Region {name} on {page} at {x},{y}, {width}×{height} px, with {margin} px of the page around it (dashed: the region box).', { name: item.name, page: item.page!, x: item.x, y: item.y, width: item.w, height: item.h, margin: REGION_MARGIN }) + (item.degrees ? ' ' + t('Packed at {degrees}°.', { degrees: item.degrees }) : '');
|
|
156
163
|
return;
|
|
157
164
|
}
|
|
165
|
+
if(state.comparison.mode==='difference'){
|
|
166
|
+
const response=await fetch(access.route(`${partsApi}/difference/${item.index}?threshold=${state.comparison.threshold}&footprints=${state.footprints}`),{headers:stageHeaders()});
|
|
167
|
+
if(!response.ok){const out=await response.json() as {error:string};throw new Error(out.error);}
|
|
168
|
+
const image=await createImageBitmap(await response.blob());
|
|
169
|
+
try{if(token!==paintToken)return;const ctx=setCanvas(canvas,item.w,item.h);paintBackground(ctx,item.w,item.h,state.bg);ctx.drawImage(image,0,0);overlay.replaceChildren();
|
|
170
|
+
caption.textContent=t('Difference: {count} pixels above threshold · {covered} covered pixels excluded · visual comparison, no automatic verdict.',{count:response.headers.get('X-Difference-Count')??'',covered:response.headers.get('X-Difference-Covered')??''});
|
|
171
|
+
}finally{image.close();}return;
|
|
172
|
+
}
|
|
158
173
|
const img = await itemImage(item), front = state.footprints ? frontParts(data.items, item) : [];
|
|
159
174
|
const fronts = await Promise.all(front.map(async o => ({ o, img: await itemImage(o) })));
|
|
160
175
|
const original=state.comparison.mode==='overlay'&&data.painting?await load('/api/parts/painting'):null;
|
|
@@ -176,18 +191,21 @@ async function paintRaster(token:number): Promise<void> {
|
|
|
176
191
|
async function paintReference(token:number):Promise<void>{const data=state.data,item=data?.items[state.selected];if(!data?.painting||!item)return;const img=await load('/api/parts/painting');if(token!==paintToken||data!==state.data||item!==state.data?.items[state.selected])return;const box=state.view==='assembled'?{x:0,y:0,w:data.rigSize![0],h:data.rigSize![1]}:item;const canvas=$<HTMLCanvasElement>('pv-reference');canvas.width=box.w;canvas.height=box.h;const ctx=canvas.getContext('2d')!;paintPaintingCrop(ctx,img,paintingRectangle(box,data.rigSize!,data.painting),box.w,box.h,state.bg);}
|
|
177
192
|
|
|
178
193
|
function renderComparison():void {
|
|
179
|
-
const active=state.data?.mode==='parts'
|
|
194
|
+
const active=state.data?.mode==='parts'&&(!!state.data.painting||!!state.data.differenceAvailable),overlay=active&&state.comparison.mode==='overlay',difference=state.comparison.mode==='difference';
|
|
195
|
+
const button=document.querySelector<HTMLButtonElement>('[data-pv-comparison="difference"]');if(button){button.disabled=!state.data?.differenceAvailable||state.view!=='item';button.title=button.disabled?t('PARTS_DIFFERENCE_UNAVAILABLE: declared painting_in_rig and individual part view required.'):'';}
|
|
196
|
+
document.querySelector<HTMLButtonElement>('[data-pv-comparison="overlay"]')!.disabled=!state.data?.painting;
|
|
197
|
+
$('pv-threshold-control').hidden=!difference;$<HTMLInputElement>('pv-threshold').value=String(state.comparison.mode==='difference'?state.comparison.threshold:state.differenceThreshold);
|
|
180
198
|
$('pv-comparison').hidden=!active;for(const b of document.querySelectorAll<HTMLElement>('[data-pv-comparison]'))b.setAttribute('aria-pressed',String(b.dataset.pvComparison===state.comparison.mode));
|
|
181
199
|
$('pv-opacity-control').hidden=!overlay;$<HTMLInputElement>('pv-opacity').value=String(state.comparison.opacity);$('pv-opacity-value').textContent=(state.comparison.opacity*100).toFixed(1)+'%';
|
|
182
|
-
$<HTMLInputElement>('pv-alpha').disabled=overlay;
|
|
183
|
-
const mesh=document.querySelector<HTMLInputElement>('#pv-mesh-control input');if(mesh)mesh.disabled=overlay||state.view==='assembled';
|
|
200
|
+
$<HTMLInputElement>('pv-alpha').disabled=overlay||difference;
|
|
201
|
+
const mesh=document.querySelector<HTMLInputElement>('#pv-mesh-control input');if(mesh)mesh.disabled=overlay||difference||state.view==='assembled';
|
|
184
202
|
$<HTMLInputElement>('pv-footprints').disabled=state.data?.mode==='atlas'||state.view==='assembled';
|
|
185
203
|
}
|
|
186
204
|
|
|
187
205
|
function renderFlags(): void {
|
|
188
206
|
const data = state.data!, item = data.items[state.selected];
|
|
189
207
|
const list = $('pv-flags');
|
|
190
|
-
const flags = item ? data.flags.filter(f => f.item === item.name) : [];
|
|
208
|
+
const flags = item ? [...data.flags.filter(f => f.kind === 'faint' && f.item === item.name), ...(data.readings ?? data.flags.filter(f => f.kind === 'check')).filter(f => f.item === item.name || f.item === '')] : [];
|
|
191
209
|
const row = (f: Flag): HTMLLIElement => {
|
|
192
210
|
const li = document.createElement('li');
|
|
193
211
|
li.dataset.flagId = f.id; li.dataset.flagSource = f.source;
|
|
@@ -209,8 +227,16 @@ function renderFlags(): void {
|
|
|
209
227
|
sourceItem.dataset.pvSource = source;
|
|
210
228
|
heading.textContent = source === 'mesh_report' ? 'mesh_report.json' : 'check.json';
|
|
211
229
|
sourceItem.append(heading);
|
|
230
|
+
const categories = source === 'mesh_report' ? ['mesh'] as const : ['part', 'pair', 'evidence', 'unclassified'] as const;
|
|
231
|
+
for (const category of categories) {
|
|
232
|
+
const selected = fromSource.filter(f => readingGroup(f) === category);
|
|
233
|
+
if (!selected.length) continue;
|
|
234
|
+
const section = document.createElement('details'), title = document.createElement('summary');
|
|
235
|
+
section.dataset.pvCategory = category;
|
|
236
|
+
title.textContent = t(category === 'mesh' ? 'Mesh flags' : category === 'part' ? 'Part findings' : category === 'pair' ? 'Pair readings' : category === 'evidence' ? 'Check evidence' : 'Unclassified check rows');
|
|
237
|
+
section.append(title);
|
|
212
238
|
const roots = new Map<string, Flag[]>();
|
|
213
|
-
for (const f of
|
|
239
|
+
for (const f of selected) {
|
|
214
240
|
const root = f.kind === 'check' ? f.root : 'contour.bridges.faint';
|
|
215
241
|
const group = roots.get(root) ?? [];
|
|
216
242
|
group.push(f); roots.set(root, group);
|
|
@@ -219,7 +245,9 @@ function renderFlags(): void {
|
|
|
219
245
|
const details = document.createElement('details'), summary = document.createElement('summary'), rows = document.createElement('ul');
|
|
220
246
|
details.dataset.pvRoot = root; details.dataset.flagSource = source;
|
|
221
247
|
summary.textContent = group.length === 1 ? t('{root} · 1 row', { root }) : t('{root} · {count} rows', { root, count: group.length });
|
|
222
|
-
rows.append(...group.map(row)); details.append(summary, rows);
|
|
248
|
+
rows.append(...group.map(row)); details.append(summary, rows); section.append(details);
|
|
249
|
+
}
|
|
250
|
+
sourceItem.append(section);
|
|
223
251
|
}
|
|
224
252
|
return [sourceItem];
|
|
225
253
|
}));
|
|
@@ -228,7 +256,8 @@ function renderFlags(): void {
|
|
|
228
256
|
data.flagSources.length ? t('Read from: {files}.', { files: data.flagSources.join(', ') }) : '',
|
|
229
257
|
data.flagMissing.length ? t('Not found: {files}.', { files: data.flagMissing.join(', ') }) : '',
|
|
230
258
|
t('Occlusion coverage is not read yet: the producer does not write it.'),
|
|
231
|
-
t('
|
|
259
|
+
t('Badges count only mesh flags and explicit part findings. Pair readings and check evidence are not counted.'),
|
|
260
|
+
flags.some(f => readingGroup(f) === 'unclassified') ? t('Missing or invalid row metadata: source-root rows remain unclassified and are not counted.') : '',
|
|
232
261
|
].filter(Boolean).join(' ');
|
|
233
262
|
}
|
|
234
263
|
|
|
@@ -240,7 +269,7 @@ function renderList(): void {
|
|
|
240
269
|
button.type = 'button'; button.dataset.pvItem = item.name; button.title = item.name;
|
|
241
270
|
if (data.items[state.selected]?.name === item.name) button.setAttribute('aria-current', 'true');
|
|
242
271
|
const name = document.createElement('span'); name.className = 'pv-name'; name.textContent = item.name;
|
|
243
|
-
const onItem = data.flags.filter(f => f.item === item.name);
|
|
272
|
+
const onItem = [...data.flags.filter(f => f.kind === 'faint'), ...(data.readings ?? [])].filter(f => f.item === item.name && countedFlag(f));
|
|
244
273
|
const flags = document.createElement('span'); flags.className = 'pv-count';
|
|
245
274
|
// flagSources holds actual basenames (including custom.json); flagMissing canonically names unread kinds.
|
|
246
275
|
const meshRead = !data.flagMissing.includes('mesh_report.json'), checkRead = !data.flagMissing.includes('check.json');
|
|
@@ -257,7 +286,7 @@ function renderList(): void {
|
|
|
257
286
|
li.append(button);
|
|
258
287
|
if(data.mode==='parts'){
|
|
259
288
|
const label=document.createElement('label'),visible=document.createElement('input');visible.type='checkbox';visible.checked=!state.hidden.has(item.name);visible.dataset.pvVisible=item.name;visible.setAttribute('aria-label',t('Show {name} in assembly',{name:item.name}));
|
|
260
|
-
visible.onchange=()=>{if(visible.checked)state.hidden.delete(item.name);else state.hidden.add(item.name);void paint();};label.append(visible
|
|
289
|
+
visible.onchange=()=>{if(visible.checked)state.hidden.delete(item.name);else state.hidden.add(item.name);void paint();};label.append(visible);li.append(label);
|
|
261
290
|
}
|
|
262
291
|
return li;
|
|
263
292
|
}));
|
|
@@ -278,7 +307,7 @@ function renderMesh(): void {
|
|
|
278
307
|
const item = state.data!.items[state.selected]!;
|
|
279
308
|
if (!item.mesh) return;
|
|
280
309
|
const control = document.createElement('label'); control.id = 'pv-mesh-control'; control.className = 'pv-field';
|
|
281
|
-
const toggle = document.createElement('input'); toggle.type = 'checkbox'; toggle.checked = state.meshShown.has(item.name); toggle.disabled=state.comparison.mode
|
|
310
|
+
const toggle = document.createElement('input'); toggle.type = 'checkbox'; toggle.checked = state.meshShown.has(item.name); toggle.disabled=state.comparison.mode!=='part'||state.view==='assembled';
|
|
282
311
|
toggle.onchange = () => { if (toggle.checked) state.meshShown.add(item.name); else state.meshShown.delete(item.name); void paint(); };
|
|
283
312
|
control.append(toggle, t('mesh from rig.json UVs')); document.querySelector('.pv-toolbar')!.append(control);
|
|
284
313
|
const panel = document.createElement('section'); panel.id = 'pv-mesh-panel';
|
|
@@ -291,6 +320,7 @@ function renderMesh(): void {
|
|
|
291
320
|
}
|
|
292
321
|
panel.append(figures);
|
|
293
322
|
const help = document.createElement('p'); help.textContent = t('Pink: art pixels outside every triangle.'); panel.append(help);
|
|
323
|
+
if(stageEmbedded){document.querySelector('.pv-verdict')!.before(panel);return;}
|
|
294
324
|
const entry = state.verdict.get(item.name)!;
|
|
295
325
|
const select = document.createElement('select'); select.setAttribute('aria-label', t('Mesh outcome'));
|
|
296
326
|
for (const [value, label] of [['pending', 'Pending'], ['clean', 'Clean'], ['flagged', 'Flagged']]) { const option = document.createElement('option'); option.value = value!; option.textContent = t(label!); select.append(option); }
|
|
@@ -304,6 +334,7 @@ function renderMesh(): void {
|
|
|
304
334
|
}
|
|
305
335
|
|
|
306
336
|
function select(index: number): void {
|
|
337
|
+
queueMicrotask(renderCorrections);
|
|
307
338
|
const data = state.data!;
|
|
308
339
|
const changed=state.selected!==index;state.selected = index;if(changed&&viewport&&state.view!=='assembled'){viewport.writeCamera('rig',{zoom:1,center:null});viewport.writeCamera('reference',{zoom:1,center:null});}
|
|
309
340
|
commentUi?.refresh();
|
|
@@ -315,6 +346,7 @@ function select(index: number): void {
|
|
|
315
346
|
function setView(view: 'item' | 'page' | 'assembled'): void {
|
|
316
347
|
if(view==='assembled'&&(state.data?.mode!=='parts'||!state.data.rigSize))return;
|
|
317
348
|
if(state.view!==view&&viewport){viewport.writeCamera('rig',{zoom:1,center:null});viewport.writeCamera('reference',{zoom:1,center:null});}
|
|
349
|
+
if(view!=='item'&&state.comparison.mode==='difference')state.comparison={mode:'part',opacity:state.comparison.opacity};
|
|
318
350
|
state.view = view;renderMesh();renderComparison();$('rig-label').textContent=t(view==='assembled'?'Assembled':'Selected part');commentUi?.refresh();
|
|
319
351
|
for (const b of document.querySelectorAll<HTMLButtonElement>('[data-pv-view]')) b.setAttribute('aria-pressed', String(b.dataset.pvView === view));
|
|
320
352
|
void paint();
|
|
@@ -327,6 +359,30 @@ function updateEntry(change: Partial<{ outcome: Outcome; note: string }>): void
|
|
|
327
359
|
renderList();
|
|
328
360
|
}
|
|
329
361
|
|
|
362
|
+
/** Explicit approval only: refuse before changing any pending entry when a flag remains. */
|
|
363
|
+
async function approveAll(): Promise<void> {
|
|
364
|
+
if (stageEmbedded || !state.data) return;
|
|
365
|
+
const entries = state.data.items.map(item => state.verdict.get(item.name));
|
|
366
|
+
if (entries.some(entry => entry?.outcome === 'flagged' || entry?.mesh?.outcome === 'flagged')) {
|
|
367
|
+
const status = $('pv-save-status');
|
|
368
|
+
status.textContent = t('PARTS_APPROVE_ALL_FLAGGED: resolve flagged part and mesh outcomes before approving all.');
|
|
369
|
+
status.dataset.result = 'refused';
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
for (const item of state.data.items) {
|
|
373
|
+
const entry = state.verdict.get(item.name) ?? { outcome: 'pending' as Outcome, note: '' };
|
|
374
|
+
if (entry.outcome === 'pending') entry.outcome = 'clean';
|
|
375
|
+
if (item.mesh) {
|
|
376
|
+
entry.mesh ??= { outcome: 'pending', note: '' };
|
|
377
|
+
if (entry.mesh.outcome === 'pending') entry.mesh.outcome = 'clean';
|
|
378
|
+
}
|
|
379
|
+
state.verdict.set(item.name, entry);
|
|
380
|
+
}
|
|
381
|
+
$<HTMLSelectElement>('pv-overall').value = 'approved';
|
|
382
|
+
renderList(); renderVerdict(); renderMesh();
|
|
383
|
+
await save();
|
|
384
|
+
}
|
|
385
|
+
|
|
330
386
|
async function save(): Promise<void> {
|
|
331
387
|
if(stageEmbedded)return;
|
|
332
388
|
const status = $('pv-save-status');
|
|
@@ -348,14 +404,16 @@ async function boot(): Promise<void> {
|
|
|
348
404
|
header.hidden=true;status.classList.add('pv-embedded-status');header.after(status);
|
|
349
405
|
document.querySelector<HTMLElement>('.pv-layout')!.hidden=true;
|
|
350
406
|
document.querySelector<HTMLElement>('.pv-verdict')!.hidden=true;
|
|
407
|
+
const approveButton=$<HTMLButtonElement>('pv-approve-all');approveButton.disabled=true;
|
|
351
408
|
const saveButton=$<HTMLButtonElement>('pv-save');saveButton.disabled=true;saveButton.title=t('Embedded atlas inspection is read-only. Use the parts command for a separate sign-off.');
|
|
352
409
|
}
|
|
353
410
|
window.addEventListener('message',event=>{if(event.source!==parent||event.origin!==location.origin||event.data?.type!=='review-stage-language'||!['en','ko'].includes(event.data.language))return;setLinkLanguage(null);setLanguagePreference(event.data.language);});
|
|
354
411
|
connectLiveWindow(access);
|
|
355
|
-
|
|
412
|
+
if(stageEmbedded)await sourceReady;
|
|
413
|
+
const res = await fetch(access.route(partsApi), { headers: stageHeaders() });
|
|
356
414
|
const data = await res.json() as ViewData & { error?: string };
|
|
357
415
|
if (!res.ok) { const status=$('pv-load');status.textContent=t(data.error??'Load failed.');status.dataset.result='refused';return; }
|
|
358
|
-
state.data = data;$('reference-empty').textContent=data.painting?'':t('PARTS_REFERENCE_UNAVAILABLE: supply --painting to compare the original painting');$('reference-empty').hidden=!!data.painting;if(data.painting)viewport.state.cameraSync=true;comments.push(...data.verdict?.comments??[]);setupPartsComments();viewport.bindNavigation(undefined,()=>!commentUi?.active());viewport.observeResize();
|
|
416
|
+
state.data = data;if(!data.differenceAvailable)document.querySelector('[data-pv-comparison="difference"]')?.remove();if(stageEmbedded)for(const item of data.items)if(item.mesh)state.meshShown.add(item.name);$('reference-empty').textContent=data.painting?'':t('PARTS_REFERENCE_UNAVAILABLE: supply --painting to compare the original painting');$('reference-empty').hidden=!!data.painting;if(data.painting)viewport.state.cameraSync=true;comments.push(...data.verdict?.comments??[]);setupPartsComments();viewport.bindNavigation(undefined,()=>!commentUi?.active());viewport.observeResize();
|
|
359
417
|
for (const item of data.items) state.verdict.set(item.name, { outcome: 'pending', note: '', ...(item.mesh ? { mesh: { outcome: 'pending' as Outcome, note: '' } } : {}) });
|
|
360
418
|
if (data.verdict) { for (const [name, v] of Object.entries(data.verdict.parts)) if (state.verdict.has(name)) state.verdict.set(name, { outcome: v.outcome, note: v.note ?? '', ...(v.mesh ? { mesh: v.mesh } : {}) }); $<HTMLSelectElement>('pv-overall').value = data.verdict.status; }
|
|
361
419
|
document.title = data.title;
|
|
@@ -368,8 +426,21 @@ async function boot(): Promise<void> {
|
|
|
368
426
|
const assemble=$<HTMLButtonElement>('pv-assemble');assemble.disabled=data.mode!=='parts'||!data.rigSize;assemble.title=assemble.disabled?t(data.mode==='atlas'?'Assembly unavailable: atlas regions carry no rig placement.':'Assembly unavailable: rig_size is not declared.'):'';
|
|
369
427
|
assemble.onclick=()=>{setView(state.view==='assembled'?'item':'assembled');assemble.setAttribute('aria-pressed',String(state.view==='assembled'));};
|
|
370
428
|
bindAssemblyPicking();
|
|
371
|
-
for(const button of document.querySelectorAll<HTMLElement>('[data-pv-comparison]'))button.onclick=()=>{
|
|
429
|
+
for(const button of document.querySelectorAll<HTMLElement>('[data-pv-comparison]'))button.onclick=()=>{const mode=button.dataset.pvComparison as PartsComparison['mode'];state.comparison=mode==='difference'?{mode,opacity:state.comparison.opacity,threshold:state.differenceThreshold}:{mode,opacity:state.comparison.opacity};if(state.comparison.mode!=='part'){state.alpha=false;$<HTMLInputElement>('pv-alpha').checked=false;state.meshShown.delete(state.data!.items[state.selected]!.name);renderMesh();}renderComparison();void paint();};
|
|
372
430
|
$<HTMLInputElement>('pv-opacity').oninput=e=>{state.comparison.opacity=Number((e.target as HTMLInputElement).value);renderComparison();void paint();};
|
|
431
|
+
$<HTMLInputElement>('pv-threshold').oninput=e=>{
|
|
432
|
+
const input=e.target as HTMLInputElement,threshold=input.valueAsNumber,status=$('pv-save-status');
|
|
433
|
+
if(!Number.isInteger(threshold)||threshold<0||threshold>255){
|
|
434
|
+
input.value=String(state.differenceThreshold);
|
|
435
|
+
status.dataset.thresholdRefused='true';
|
|
436
|
+
status.textContent=t('PARTS_COMPARISON_INVALID: enter an integer threshold from 0 to 255. Last valid value restored.');
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
if(status.dataset.thresholdRefused){delete status.dataset.thresholdRefused;status.textContent='';}
|
|
440
|
+
state.differenceThreshold=threshold;
|
|
441
|
+
if(state.comparison.mode==='difference')state.comparison.threshold=threshold;
|
|
442
|
+
void paint();
|
|
443
|
+
};
|
|
373
444
|
const footprints = $<HTMLInputElement>('pv-footprints');
|
|
374
445
|
if (data.mode === 'atlas') { footprints.disabled = true; $('pv-footprint-control').title = t('Footprints need a parts package: atlas regions carry no rig placement.'); }
|
|
375
446
|
$<HTMLSelectElement>('pv-bg').onchange = e => { state.bg = (e.target as HTMLSelectElement).value; void paint(); };
|
|
@@ -380,9 +451,12 @@ async function boot(): Promise<void> {
|
|
|
380
451
|
for (const r of document.querySelectorAll<HTMLInputElement>('input[data-pv-outcome]')) r.onchange = () => { if (r.checked) updateEntry({ outcome: r.value as Outcome }); };
|
|
381
452
|
$<HTMLTextAreaElement>('pv-note').oninput = e => updateEntry({ note: (e.target as HTMLTextAreaElement).value });
|
|
382
453
|
$('pv-save').onclick = () => { void save(); };
|
|
454
|
+
$('pv-approve-all').onclick = () => approveAll();
|
|
383
455
|
for(const format of ['json','issue'])$('pv-export-'+format).onclick=async()=>{const res=await fetch(access.route('/api/parts/export?format='+format),{headers:access.headers()});const value=await res.text();if(!res.ok){$('pv-save-status').textContent=value;return;}const url=URL.createObjectURL(new Blob([value],{type:format==='json'?'application/json':'text/markdown'})),a=document.createElement('a');a.href=url;a.download=format==='json'?'parts-review-export.json':'parts-review-export.md';a.click();setTimeout(()=>URL.revokeObjectURL(url),1000);};
|
|
384
456
|
onLanguageChange(() => { if (state.data) select(state.selected); });
|
|
385
|
-
if
|
|
457
|
+
if(stageEmbedded)(window as StagePartsWindow).rigReviewStageParts={snapshot:stagePartsSnapshot};
|
|
458
|
+
if(data.items.length){if(stageRestore)await restoreStageParts(stageRestore);else select(0);}
|
|
459
|
+
renderCorrections();
|
|
386
460
|
document.body.dataset.ready = 'true';
|
|
387
461
|
}
|
|
388
462
|
|
|
@@ -412,8 +486,42 @@ function setupPartsComments():void {
|
|
|
412
486
|
};
|
|
413
487
|
const pose=():PartsPose|null=>{const data=state.data,item=data?.items[state.selected],camera=viewport?.numericView().cameras.rig;if(!data||!item||!camera||data.mode!=='parts'||state.view!=='item')return null;return {mode:'parts',camera,item:{...item},sourceHash:data.sourceHash,view:{camera:{zoom:camera.zoom,center:{...camera.center},viewport:{...camera.viewport}},cameraSync:viewport!.state.cameraSync,referenceCamera:(()=>{const c=viewport!.numericView().cameras.reference;return c?{zoom:c.zoom,center:{...c.center},viewport:{...c.viewport}}:null;})(),background:state.bg,alpha:state.alpha,footprints:state.footprints,mesh:state.meshShown.has(item.name),comparison:{...state.comparison}},capture:{pane:$('rig-viewport'),root:$('rig-root'),images:true,canvas:$<HTMLCanvasElement>('pv-canvas'),backend:'canvas2d',nearest:true}};};
|
|
414
488
|
commentUi=bindStageComments({toolbar:document.querySelector<HTMLElement>('.pv-toolbar')!,viewports:{rig:$('rig-viewport')},pose,pause:async()=>{},bookmark:()=>null,
|
|
415
|
-
restore:async(raw)=>{const b=raw as {part:string;imageHash:string;sourceHash:string;view:PartsComment['view']},item=state.data!.items.find(i=>i.name===b.part);if(!item||item.imageHash!==b.imageHash||state.data!.sourceHash!==b.sourceHash)throw new Error('PARTS_COMMENT_STALE_SOURCE: reopen the bound source');setView('item');$('pv-assemble').setAttribute('aria-pressed','false');select(item.index);state.bg=b.view.background;state.alpha=b.view.alpha;state.footprints=b.view.footprints;state.comparison={...(b.view.comparison??defaultPartsComparison())};renderComparison();if(b.view.mesh)state.meshShown.add(item.name);else state.meshShown.delete(item.name);$<HTMLSelectElement>('pv-bg').value=state.bg;$<HTMLInputElement>('pv-alpha').checked=state.alpha;$<HTMLInputElement>('pv-footprints').checked=state.footprints;renderMesh();viewport!.state.cameraRestoring=true;try{await paint();viewport!.writeCamera('rig',{zoom:b.view.camera.zoom,center:{...b.view.camera.center}});if(b.view.referenceCamera)viewport!.writeCamera('reference',{zoom:b.view.referenceCamera.zoom,center:{...b.view.referenceCamera.center}});viewport!.state.cameraSync=b.view.cameraSync;viewport!.fitCamera();}finally{viewport!.state.cameraRestoring=false;}},
|
|
489
|
+
restore:async(raw)=>{const res=await fetch(access.route(partsApi),{headers:stageHeaders()});const current=await res.json() as ViewData&{error?:string};if(!res.ok||current.sourceHash!==state.data?.sourceHash)throw new Error(current.error??'PARTS_COMMENT_STALE_SOURCE');const b=raw as {part:string;imageHash:string;sourceHash:string;view:PartsComment['view']},item=state.data!.items.find(i=>i.name===b.part);if(!item||item.imageHash!==b.imageHash||state.data!.sourceHash!==b.sourceHash)throw new Error('PARTS_COMMENT_STALE_SOURCE: reopen the bound source');setView('item');$('pv-assemble').setAttribute('aria-pressed','false');select(item.index);state.bg=b.view.background;state.alpha=b.view.alpha;state.footprints=b.view.footprints;state.comparison={...(b.view.comparison??defaultPartsComparison())};if(state.comparison.mode==='difference')state.differenceThreshold=state.comparison.threshold;renderComparison();if(b.view.mesh)state.meshShown.add(item.name);else state.meshShown.delete(item.name);$<HTMLSelectElement>('pv-bg').value=state.bg;$<HTMLInputElement>('pv-alpha').checked=state.alpha;$<HTMLInputElement>('pv-footprints').checked=state.footprints;renderMesh();viewport!.state.cameraRestoring=true;try{await paint();viewport!.writeCamera('rig',{zoom:b.view.camera.zoom,center:{...b.view.camera.center}});if(b.view.referenceCamera)viewport!.writeCamera('reference',{zoom:b.view.referenceCamera.zoom,center:{...b.view.referenceCamera.center}});viewport!.state.cameraSync=b.view.cameraSync;viewport!.fitCamera();}finally{viewport!.state.cameraRestoring=false;}},
|
|
416
490
|
feedback:()=>comments,locked:()=>false,add:c=>comments.push(c),changed:()=>renderVerdict(),error:m=>{$('pv-save-status').textContent=t(m);},blocked:()=>painting,refusal:()=>paintFailure??(state.view==='assembled'?'PARTS_COMMENT_UNAVAILABLE: select the individual part view to comment':null)??(state.data?.mode!=='parts'||stageEmbedded?'PARTS_COMMENT_UNAVAILABLE: original part image required':null),codec});
|
|
417
491
|
}
|
|
418
492
|
|
|
419
493
|
if (typeof document !== 'undefined' && document.getElementById('parts-app')) void boot();
|
|
494
|
+
|
|
495
|
+
function renderCorrections():void {
|
|
496
|
+
let host=document.getElementById('pv-corrections');if(!host){host=document.createElement('section');host.id='pv-corrections';document.querySelector('.pv-toolbar')!.after(host);}
|
|
497
|
+
host.replaceChildren();const data=state.data,item=data?.items[state.selected],mapping=data?.draft?.mappings.find(m=>m.part===item?.name);
|
|
498
|
+
const label=document.createElement('p');label.textContent=t(data?.draft&&!mapping?'STAGE_DRAFT_NO_MESH: this part has no mesh attachment; direct correction is unavailable.':data?.draft?.label??data?.draftUnavailable??'STAGE_DRAFT_UNAVAILABLE: no producer-compatible draft is supplied.');host.append(label);
|
|
499
|
+
if(!mapping||!data?.draft)return;
|
|
500
|
+
label.textContent+=` · ${mapping.part} · ${mapping.skin}/${mapping.slot}/${mapping.attachment} · v ${mapping.vertices} t ${mapping.triangles} · ${data.draft.buildId}`;
|
|
501
|
+
for(const [instrument,title,operation]of [['chest','Chest regions',t('rig-parts remesh --mesh')],['mesh','Mesh parameters',t('rig-parts remesh --mesh')],['delta','Edit Mesh',t('rig-parts remesh --delta')]]){
|
|
502
|
+
const button=document.createElement('button');button.type='button';button.textContent=t(title!);button.title=`${mapping.part} · ${operation}`;button.onclick=()=>parent.postMessage({type:'review-stage-correction',part:mapping.part,sourceHash:data.sourceHash,buildId:data.draft!.buildId,instrument},location.origin);host.append(button);
|
|
503
|
+
}
|
|
504
|
+
const unavailable=document.createElement('p');unavailable.textContent=t('Correction-record export unavailable: waiting for the shared correction contract.');host.append(unavailable);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function stagePartsSnapshot():StagePartsState|null {
|
|
508
|
+
const data=state.data,item=data?.items[state.selected],mapping=data?.draft?.mappings.find(m=>m.part===item?.name);
|
|
509
|
+
if(!data?.inspectionSourceHash||!item?.imageHash||!mapping||!viewport)return null;
|
|
510
|
+
return {inspectionSourceHash:data.inspectionSourceHash,part:item.name,imageHash:item.imageHash,box:{x:item.x,y:item.y,w:item.w,h:item.h},mapping:{skin:mapping.skin,slot:mapping.slot,attachment:mapping.attachment},rig:{...viewport.paneCamera('rig')},reference:{...viewport.paneCamera('reference')},cameraSync:viewport.state.cameraSync,bg:state.bg,alpha:state.alpha,footprints:state.footprints,view:state.view,mesh:state.meshShown.has(item.name)};
|
|
511
|
+
}
|
|
512
|
+
async function restoreStageParts(saved:StagePartsState):Promise<void>{
|
|
513
|
+
if(!state.data||!viewport)return;
|
|
514
|
+
try{
|
|
515
|
+
const index=stagePartsSelectionIndex(state.data,saved);
|
|
516
|
+
viewport.state.cameraRestoring=true;state.bg=saved.bg;state.alpha=saved.alpha;state.footprints=saved.footprints;state.view=saved.view;
|
|
517
|
+
if(saved.mesh)state.meshShown.add(saved.part);else state.meshShown.delete(saved.part);
|
|
518
|
+
select(index);await paint();viewport.writeCamera('rig',saved.rig);if(state.data.painting)viewport.writeCamera('reference',saved.reference);viewport.state.cameraSync=saved.cameraSync;viewport.fitCamera();
|
|
519
|
+
}catch{const status=$('pv-load');status.hidden=false;status.dataset.result='refused';status.textContent=t('STAGE_DRAFT_MISMATCH: separated parts and draft mesh identity differ.');document.querySelector<HTMLElement>('.pv-layout')!.hidden=true;}
|
|
520
|
+
finally{viewport.state.cameraRestoring=false;}
|
|
521
|
+
}
|
|
522
|
+
if(typeof window!=='undefined')window.addEventListener('message',event=>{if(event.source===parent&&event.origin===location.origin&&event.data?.type==='review-stage-restore'&&event.data.state)void restoreStageParts(event.data.state);});
|
|
523
|
+
|
|
524
|
+
if(typeof window!=='undefined')window.addEventListener('message',event=>{if(event.source!==parent||event.origin!==location.origin||event.data?.type!=='review-stage-revalidate')return;void (async()=>{
|
|
525
|
+
try{const response=await fetch(access.route(partsApi),{headers:stageHeaders()}),data=await response.json() as ViewData&{error?:string};if(!response.ok||data.sourceHash!==state.data?.sourceHash)throw new Error(data.error??'STAGE_DRAFT_MISMATCH: separated parts and draft mesh identity differ.');if(event.data.state)await restoreStageParts(event.data.state);}
|
|
526
|
+
catch(error){const status=$('pv-load');status.hidden=false;status.dataset.result='refused';status.textContent=t(error instanceof Error?error.message:String(error));document.querySelector<HTMLElement>('.pv-layout')!.hidden=true;}
|
|
527
|
+
})();});
|
package/web/rebuild-client.ts
CHANGED
|
@@ -27,12 +27,12 @@ export type AnimationSourceView=import('../src/rebuild.ts').AnimationSourceStatu
|
|
|
27
27
|
export interface RebuildStatusView {retarget?:RetargetStatusView;animations?:AnimationSourceView|null;available:boolean;viewOnly?:boolean;handoff:HandoffView|null;baseline:BaselineView|null;inputs:{config:string;parts:string|null;rig:string|null;configHash:string}|null;parts:{name:string;regions:unknown[]}[];contour:Record<string,Record<string,unknown>>;meshes?:Record<string,unknown>;constraints?:unknown[]|null;bones?:unknown[]|null;fields?:Record<string,unknown>|null;cuts?:{config:Record<string,unknown>;build:string|null}|null;inspectedCheck?:InspectedCheckView|null;idle?:import('../src/idle-tracks.ts').IdleStatus|null;cloth?:ClothStatusView|null;producer:{package:string;version:string}|null;compiler:{package:string;version:string}|null;reason:string|null}
|
|
28
28
|
/** #111: the cloth recipe form's status — the reader's tags, the recipes as written, each tag's parts and chains, the keypoints, the route and why Apply cannot run. */
|
|
29
29
|
export interface ClothStatusView {targets:string[];targetsRead:boolean;recipes:Record<string,unknown>|null;tags:import('../src/cloth-recipe.ts').ClothTagView[];keypoints:{path:string;sha256:string}|null;route:'build'|'rig';reason:string|null}
|
|
30
|
-
export interface RebuildJobView {id:string;status:'running'|'built'|'refused'|'failed';reused:boolean;lines:string[];producerLine:string|null;hint?:string;exitCode:number|null;wallMs:{remesh:number|null;compile:number|null};build:{modelUrl:string;modelHash:string;files:Record<string,string>}|null;request:{part:string;regions:RegionEntry[];configHash:string;entrySha256:string;bust?:BustSpec};producer:{package:string;version:string};compiler:{package:string;version:string}}
|
|
30
|
+
export interface RebuildJobView {stageInputHash?:string;files?:FilesDiff|null;remesh?:import('../src/mesh-entry.ts').RemeshCounts|null;check?:CheckSummary|null;id:string;status:'running'|'built'|'refused'|'failed';reused:boolean;lines:string[];producerLine:string|null;hint?:string;exitCode:number|null;wallMs:{remesh:number|null;compile:number|null};build:{modelUrl:string;modelHash:string;files:Record<string,string>}|null;request:{part:string;regions:RegionEntry[];configHash:string;entrySha256:string;bust?:BustSpec};producer:{package:string;version:string};compiler:{package:string;version:string}}
|
|
31
31
|
export interface RebuildRefusal {status:'refused';error:string;producerLine:string|null}
|
|
32
32
|
/** #99 regions or #105 landmarks: exactly one of `regions` and `bust`. */
|
|
33
33
|
export type RebuildRequestBody={part:string;regions:RegionEntry[];configHash:string}|{part:string;bust:BustSpec;configHash:string};
|
|
34
34
|
/** What the draft keeps and the feedback context carries: the exact last applied inputs and the producer's line. */
|
|
35
|
-
export interface AppliedRecord {schema:'rig-review-applied/1';buildId:string;part:string;regions:RegionEntry[];bust?:BustSpec;configHash:string;entrySha256:string;producer:{package:string;version:string};compiler:{package:string;version:string};line:string|null;modelHash:string}
|
|
35
|
+
export interface AppliedRecord {stageInputHash?:string;files?:FilesDiff|null;mesh?:{part:string;before:import('../src/mesh-entry.ts').MeshCounts;after:import('../src/mesh-entry.ts').MeshCounts};check?:CheckSummary|null;schema:'rig-review-applied/1';buildId:string;part:string;regions:RegionEntry[];bust?:BustSpec;configHash:string;entrySha256:string;producer:{package:string;version:string};compiler:{package:string;version:string};line:string|null;modelHash:string}
|
|
36
36
|
|
|
37
37
|
const number=(read:ChestFieldReader,id:string)=>{const raw=(read(id)?.value??'').trim();if(!raw)return null;const value=Number(raw);return Number.isFinite(value)?value:Number.NaN;};
|
|
38
38
|
|
|
@@ -132,6 +132,14 @@ function chestPart(status:Pick<RebuildStatusView,'parts'|'contour'>){
|
|
|
132
132
|
const bust=(p:{name:string})=>{const c=status.contour[p.name]?.contour;return !!c&&typeof c==='object'&&'bust' in (c as Record<string,unknown>);};
|
|
133
133
|
return status.parts.find(bust)??status.parts.find(p=>p.regions.some(readable))??status.parts.find(p=>p.regions.length);
|
|
134
134
|
}
|
|
135
|
+
/** The fields and kept-region seed must use the same explicit part as Stage 1's correction request. */
|
|
136
|
+
export function chestStatusForPart<T extends Pick<RebuildStatusView,'parts'|'contour'>>(status:T,part:string|null):T {
|
|
137
|
+
return part?{...status,parts:status.parts.filter(p=>p.name===part),contour:Object.fromEntries(Object.entries(status.contour).filter(([name])=>name===part))}:status;
|
|
138
|
+
}
|
|
139
|
+
export function chestPartFields(status:Pick<RebuildStatusView,'parts'|'contour'>,part:string):{fields:Record<string,string>;mode:'circles'|'landmarks';seed:ChestSeed} {
|
|
140
|
+
const scoped=chestStatusForPart(status,part),empty=()=>undefined,landmarks=seedLandmarks(scoped,empty);
|
|
141
|
+
return {fields:{...(seedFields(scoped,empty)??{}),...(landmarks??{})},mode:landmarks?'landmarks':'circles',seed:chestSeed(scoped)};
|
|
142
|
+
}
|
|
135
143
|
/** The config's regions as chest rows (at most two), read by measurement, never by point count. Pure: Apply recomputes it. */
|
|
136
144
|
export function chestSeed(status:Pick<RebuildStatusView,'parts'|'contour'>):ChestSeed {
|
|
137
145
|
const part=chestPart(status),entry=part?status.contour[part.name]:undefined;if(!part||!entry)return {part:null,rows:[],refusals:[],kept:[]};
|
|
@@ -199,17 +207,17 @@ export function seedLandmarks(status:Pick<RebuildStatusView,'parts'|'contour'>,r
|
|
|
199
207
|
return null;
|
|
200
208
|
}
|
|
201
209
|
|
|
202
|
-
export const appliedRecord=(job:RebuildJobView):AppliedRecord=>({schema:'rig-review-applied/1',buildId:job.id,part:job.request.part,regions:job.request.regions,...(job.request.bust?{bust:job.request.bust}:{}),configHash:job.request.configHash,entrySha256:job.request.entrySha256,producer:job.producer,compiler:job.compiler,line:job.producerLine,modelHash:job.build!.modelHash});
|
|
210
|
+
export const appliedRecord=(job:RebuildJobView):AppliedRecord=>({schema:'rig-review-applied/1',...(job.stageInputHash?{stageInputHash:job.stageInputHash}:{}),...(job.files!==undefined?{files:job.files}:{}),...(job.remesh?{mesh:{part:job.remesh.part,before:job.remesh.before,after:job.remesh.after}}:{}),...(Object.hasOwn(job,'check')?{check:job.check}:{}),buildId:job.id,part:job.request.part,regions:job.request.regions,...(job.request.bust?{bust:job.request.bust}:{}),configHash:job.request.configHash,entrySha256:job.request.entrySha256,producer:job.producer,compiler:job.compiler,line:job.producerLine,modelHash:job.build!.modelHash});
|
|
203
211
|
export function parseApplied(text:string):AppliedRecord|AppliedPatch|AppliedDelta|AppliedRetarget|AppliedAnimation|null {try{const value=JSON.parse(text);return value?.schema==='rig-review-applied/1'||value?.schema===APPLIED_PATCH_SCHEMA||value?.schema===APPLIED_DELTA_SCHEMA||value?.schema===APPLIED_RETARGET_SCHEMA||value?.schema===APPLIED_ANIMATION_SCHEMA?value as AppliedRecord|AppliedPatch|AppliedDelta|AppliedRetarget|AppliedAnimation:null;}catch{return null;}}
|
|
204
212
|
|
|
205
213
|
/** A patch Apply's job (#102): the patch and its hash, the op/compile/check wall clocks, check's summary and the rig.json diff. */
|
|
206
214
|
/** #115: a build job's assemble readout (`AssembledView` in src/rebuild.ts). */
|
|
207
215
|
export type AssembledJobView=import('../src/rebuild.ts').AssembledView;
|
|
208
|
-
export interface PatchJobView {id:string;kind:'patch';op?:'rig'|'retune'|'remesh'|'build'|'cloth';assembled?:AssembledJobView;cloth?:import('../src/rebuild.ts').ClothJob;status:'running'|'built'|'refused'|'failed';reused:boolean;lines:string[];producerLine:string|null;hint?:string;exitCode:number|null;wallMs:{op:number|null;compile:number|null;check:number|null};check:CheckSummary|null;diff:{count:number;paths:string[]}|null;files?:FilesDiff|null;remesh?:import('../src/mesh-entry.ts').RemeshCounts&{modelTriangles:number|null}|null;build:{modelUrl:string;modelHash:string;files:Record<string,string>}|null;request:{patch:ConfigPatch;patchSha256:string;configHash:string};producer:{package:string;version:string};compiler:{package:string;version:string};environment?:{sha256:string;steps:number}}
|
|
216
|
+
export interface PatchJobView {stageInputHash?:string;id:string;kind:'patch';op?:'rig'|'retune'|'remesh'|'build'|'cloth';assembled?:AssembledJobView;cloth?:import('../src/rebuild.ts').ClothJob;status:'running'|'built'|'refused'|'failed';reused:boolean;lines:string[];producerLine:string|null;hint?:string;exitCode:number|null;wallMs:{op:number|null;compile:number|null;check:number|null};check:CheckSummary|null;diff:{count:number;paths:string[]}|null;files?:FilesDiff|null;remesh?:import('../src/mesh-entry.ts').RemeshCounts&{modelTriangles:number|null}|null;build:{modelUrl:string;modelHash:string;files:Record<string,string>}|null;request:{patch:ConfigPatch;patchSha256:string;configHash:string};producer:{package:string;version:string};compiler:{package:string;version:string};environment?:{sha256:string;steps:number}}
|
|
209
217
|
/** #112: `environment` is the exported `rigc-environment/1` schedule Apply's check reads, when "Use for readings" is on. */
|
|
210
218
|
export interface PatchRequestBody {patch:ConfigPatch;environment?:import('../src/environment-schedule.ts').EnvironmentSchedule}
|
|
211
219
|
/** Edit Mesh's delta Apply (#135): `remesh --delta`, the per-file diff and the part's counts; remesh's own gate holds check. */
|
|
212
|
-
export interface DeltaJobView {id:string;kind:'delta';op:'remesh';status:'running'|'built'|'refused'|'failed';reused:boolean;lines:string[];producerLine:string|null;hint?:string;exitCode:number|null;wallMs:{op:number|null;compile:number|null};files:FilesDiff|null;remesh:import('../src/mesh-entry.ts').RemeshCounts&{modelTriangles:number|null}|null;build:{modelUrl:string;modelHash:string;files:Record<string,string>}|null;request:{part:string;delta:Record<string,unknown>;deltaSha256:string;configHash:string};producer:{package:string;version:string};compiler:{package:string;version:string}}
|
|
220
|
+
export interface DeltaJobView {stageInputHash?:string;check?:CheckSummary|null;id:string;kind:'delta';op:'remesh';status:'running'|'built'|'refused'|'failed';reused:boolean;lines:string[];producerLine:string|null;hint?:string;exitCode:number|null;wallMs:{op:number|null;compile:number|null};files:FilesDiff|null;remesh:import('../src/mesh-entry.ts').RemeshCounts&{modelTriangles:number|null}|null;build:{modelUrl:string;modelHash:string;files:Record<string,string>}|null;request:{part:string;delta:Record<string,unknown>;deltaSha256:string;configHash:string};producer:{package:string;version:string};compiler:{package:string;version:string}}
|
|
213
221
|
/** `{part, delta, configHash}`: the server owns every path and flag; the delta is the editor's export as it stands. */
|
|
214
222
|
export interface DeltaRequestBody {part:string;delta:import('../src/mesh-edit.ts').MeshEditDocument;configHash:string}
|
|
215
223
|
/** A retarget Apply's job (#114): clean, retarget, compile; every FAIL line of the step that refused, verbatim; the listed lines. */
|
|
@@ -267,14 +275,14 @@ export function makePatch(status:Pick<RebuildStatusView,'inputs'|'producer'>,ops
|
|
|
267
275
|
return {schema:CONFIG_PATCH_SCHEMA,config_sha256:status.inputs.configHash,ops:ops.map(o=>({...o})),producer:{name:status.producer.package,version:status.producer.version},op:{cmd:op.cmd,args:[...(op.args??[])]}};
|
|
268
276
|
}
|
|
269
277
|
/** What the draft keeps and `context.applied` carries for a patch: the patch, its hash, the producer's line and check's summary. */
|
|
270
|
-
export const patchAppliedRecord=(job:PatchJobView):AppliedPatch=>({schema:APPLIED_PATCH_SCHEMA,buildId:job.id,patch:job.request.patch,patchSha256:job.request.patchSha256,configHash:job.request.configHash,producer:job.producer,compiler:job.compiler,line:job.producerLine,check:job.check,diff:job.diff,...(job.files?{files:job.files}:{}),modelHash:job.build!.modelHash,...(job.op?{op:job.op}:{}),...(job.remesh?{mesh:{part:job.remesh.part,before:{...job.remesh.before},after:{...job.remesh.after}}}:{}),...(job.op==='cloth'&&job.cloth?{cloth:{route:job.cloth.route,keypoints:{...job.cloth.inputs.keypoints},written:{count:job.cloth.written?.count??0,paths:[...(job.cloth.written?.paths??[])]}}}:{}),...(job.op==='build'||(job.op==='cloth'&&job.cloth?.route==='build')?{assembled:assembledRecord(job)}:{}),...(job.environment?{environment:{...job.environment}}:{})});
|
|
278
|
+
export const patchAppliedRecord=(job:PatchJobView):AppliedPatch=>({schema:APPLIED_PATCH_SCHEMA,...(job.stageInputHash?{stageInputHash:job.stageInputHash}:{}),buildId:job.id,patch:job.request.patch,patchSha256:job.request.patchSha256,configHash:job.request.configHash,producer:job.producer,compiler:job.compiler,line:job.producerLine,check:job.check,diff:job.diff,...(job.files?{files:job.files}:{}),modelHash:job.build!.modelHash,...(job.op?{op:job.op}:{}),...(job.remesh?{mesh:{part:job.remesh.part,before:{...job.remesh.before},after:{...job.remesh.after}}}:{}),...(job.op==='cloth'&&job.cloth?{cloth:{route:job.cloth.route,keypoints:{...job.cloth.inputs.keypoints},written:{count:job.cloth.written?.count??0,paths:[...(job.cloth.written?.paths??[])]}}}:{}),...(job.op==='build'||(job.op==='cloth'&&job.cloth?.route==='build')?{assembled:assembledRecord(job)}:{}),...(job.environment?{environment:{...job.environment}}:{})});
|
|
271
279
|
/** #115: what a build Apply records: the build's own wall clock, the recomposite figures, the parts it changed and its `seam pair` lines. */
|
|
272
280
|
export function assembledRecord(job:PatchJobView):AppliedAssembled {
|
|
273
281
|
const a=job.assembled,fig=(f:Record<string,number>|null|undefined)=>f?{...f}:null;
|
|
274
282
|
return {wallMs:job.op==='cloth'?job.cloth?.wallMs.build??null:job.wallMs.op,recomposite:{before:fig(a?.recomposite.before as Record<string,number>|null),after:fig(a?.recomposite.after as Record<string,number>|null)},partsChanged:[...(a?.parts?.changed??[])],seamPairs:(a?.seamPairs??[]).slice(0,64)};
|
|
275
283
|
}
|
|
276
284
|
/** What the draft keeps and `context.applied` carries for a delta: the document and its hash, the producer's line, op "remesh", the diff and the counts. */
|
|
277
|
-
export const deltaAppliedRecord=(job:DeltaJobView):AppliedDelta=>({schema:APPLIED_DELTA_SCHEMA,buildId:job.id,part:job.request.part,delta:JSON.parse(JSON.stringify(job.request.delta)),deltaSha256:job.request.deltaSha256,configHash:job.request.configHash,producer:job.producer,compiler:job.compiler,line:job.producerLine,op:'remesh',files:job.files,...(job.remesh?{mesh:{part:job.remesh.part,before:{...job.remesh.before},after:{...job.remesh.after}}}:{}),modelHash:job.build!.modelHash});
|
|
285
|
+
export const deltaAppliedRecord=(job:DeltaJobView):AppliedDelta=>({schema:APPLIED_DELTA_SCHEMA,...(job.stageInputHash?{stageInputHash:job.stageInputHash}:{}),...(Object.hasOwn(job,'check')?{check:job.check}:{}),buildId:job.id,part:job.request.part,delta:JSON.parse(JSON.stringify(job.request.delta)),deltaSha256:job.request.deltaSha256,configHash:job.request.configHash,producer:job.producer,compiler:job.compiler,line:job.producerLine,op:'remesh',files:job.files,...(job.remesh?{mesh:{part:job.remesh.part,before:{...job.remesh.before},after:{...job.remesh.after}}}:{}),modelHash:job.build!.modelHash});
|
|
278
286
|
/** A delta job's status line: built (wall clocks, counts, the per-file diff) or the producer's line verbatim. */
|
|
279
287
|
export function deltaOutcomeLine(result:DeltaJobView|RebuildRefusal):{text:string;error:boolean} {
|
|
280
288
|
if(!('id' in result))return {text:result.producerLine??result.error,error:true};
|
package/web/stage-nav.ts
CHANGED
|
@@ -3,20 +3,33 @@ import {getLanguage,onLanguageChange,t} from './i18n.ts';
|
|
|
3
3
|
import {pageInstanceAccess} from './instance-access.ts';
|
|
4
4
|
export const reviewStages = ['1 Parts + mesh','2 Interview','3 Rig + animation','4 Direction'] as const;
|
|
5
5
|
export type ReviewStage = 1|2|3|4;
|
|
6
|
+
export interface StagePartsState {
|
|
7
|
+
inspectionSourceHash:string;part:string;imageHash:string;box:{x:number;y:number;w:number;h:number};mapping:{skin:string;slot:string;attachment:string};
|
|
8
|
+
rig:{zoom:number;center:{x:number;y:number}|null};reference:{zoom:number;center:{x:number;y:number}|null};cameraSync:boolean;
|
|
9
|
+
bg:string;alpha:boolean;footprints:boolean;view:'item'|'page'|'assembled';mesh:boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface StagePartsWindow extends Window {rigReviewStageParts?:{snapshot:()=>StagePartsState|null}}
|
|
12
|
+
/** Navigation state transfers only over exact original-art/package identity and the same draft address. */
|
|
13
|
+
export function stagePartsSelectionIndex(data:{inspectionSourceHash?:string;items:{name:string;imageHash?:string;x:number;y:number;w:number;h:number}[];draft?:{mappings:{part:string;skin:string;slot:string;attachment:string}[]}},saved:StagePartsState):number {
|
|
14
|
+
const i=data.items.findIndex(item=>item.name===saved.part&&item.imageHash===saved.imageHash&&(['x','y','w','h']as const).every(k=>item[k]===saved.box[k]));
|
|
15
|
+
const m=data.draft?.mappings.find(m=>m.part===saved.part);
|
|
16
|
+
if(i<0||data.inspectionSourceHash!==saved.inspectionSourceHash||!m||(['skin','slot','attachment']as const).some(k=>m[k]!==saved.mapping[k]))throw new Error('STAGE_DRAFT_MISMATCH');
|
|
17
|
+
return i;
|
|
18
|
+
}
|
|
6
19
|
export function stageReason(stage:ReviewStage,model:boolean):string|null {
|
|
7
20
|
if(stage===2)return 'INTERVIEW_UNAVAILABLE: no interview consumer contract is installed.';
|
|
8
21
|
if(stage===4)return 'DIRECTION_UNAVAILABLE: no direction inspection contract is installed.';
|
|
9
22
|
if(stage===3&&!model)return 'MODEL_UNAVAILABLE: no compiled model is supplied in this inspection.';
|
|
10
23
|
return null;
|
|
11
24
|
}
|
|
12
|
-
export function bindStageNav(options:{partsOnly?:boolean;model:boolean;side?:()=> 'a'|'b';setup?:()=>void}):()=>void {
|
|
25
|
+
export function bindStageNav(options:{partsOnly?:boolean;model:boolean;side?:()=> 'a'|'b';setup?:()=>void;draftBuild?:()=>string;correction?:(request:{part:string;sourceHash:string;buildId:string;instrument:string})=>Promise<void>}):()=>void {
|
|
13
26
|
const host=document.querySelector<HTMLElement>('[data-stage-nav]');if(!host)return ()=>{};
|
|
14
27
|
const embedded=new URL(location.href).searchParams.get('stageEmbed')==='1';
|
|
15
28
|
if(embedded){host.hidden=true;return ()=>{};}
|
|
16
29
|
const access=pageInstanceAccess(),panel=document.createElement('section');panel.className='review-stage-panel';panel.hidden=true;panel.setAttribute('aria-live','polite');document.body.append(panel);
|
|
17
30
|
const status=document.createElement('p');status.setAttribute('role','status');panel.append(status);
|
|
18
31
|
const sourcePicker=document.getElementById('mode-build-picker');
|
|
19
|
-
const frames=new Map<string,HTMLIFrameElement>();let current:ReviewStage=options.partsOnly?1:3;
|
|
32
|
+
const frames=new Map<string,HTMLIFrameElement>();let lastFrame:HTMLIFrameElement|null=null;let current:ReviewStage=options.partsOnly?1:3;
|
|
20
33
|
const workspace=document.querySelector<HTMLElement>(options.partsOnly?'.pv-layout':'.layout');const wasInert=workspace?.inert??false;
|
|
21
34
|
const buttons=reviewStages.map((label,index)=>{const button=document.createElement('button');button.type='button';button.dataset.reviewStage=String(index+1);button.onclick=()=>show(index+1 as ReviewStage);host.append(button);return button;});
|
|
22
35
|
const mesh=document.createElement('button');mesh.type='button';mesh.onclick=()=>{show(3);options.setup?.();};panel.append(mesh);
|
|
@@ -26,10 +39,12 @@ export function bindStageNav(options:{partsOnly?:boolean;model:boolean;side?:()=
|
|
|
26
39
|
current=stage;document.documentElement.dataset.inspectionStage=String(stage);render();place();const reason=stageReason(stage,options.model);
|
|
27
40
|
panel.hidden=stage===(options.partsOnly?1:3)&&!reason;
|
|
28
41
|
if(workspace)workspace.inert=!panel.hidden||wasInert;
|
|
29
|
-
status.textContent=reason?t(reason):stage===1&&!options.partsOnly?t('Atlas inspection, read only — inspected package. Applied scratch atlas, pre-rig parts, mesh sign-off and draft corrections are unavailable here.'):'';mesh.hidden=stage!==1||!options.model||!!options.partsOnly;
|
|
42
|
+
status.textContent=reason?t(reason):stage===1&&!options.partsOnly?t(options.correction?'Draft rig · structure evidence only':'Atlas inspection, read only — inspected package. Applied scratch atlas, pre-rig parts, mesh sign-off and draft corrections are unavailable here.'):'';mesh.hidden=stage!==1||!options.model||!!options.partsOnly;
|
|
30
43
|
for(const frame of frames.values())frame.hidden=true;
|
|
31
|
-
if(stage===1&&!options.partsOnly){const side=options.side?.(),key=side??'single';let frame=frames.get(key);if(!frame){frame=document.createElement('iframe');frame.title=t('Parts and atlas inspection');frame.src=access.route('/stage-parts.html')+'?stageEmbed=1&lang='+getLanguage()+(side?'&side='+side:'');frame.addEventListener('load',()=>frame!.contentWindow?.postMessage({type:'review-stage-language',language:getLanguage()},location.origin));frames.set(key,frame);panel.append(frame);}frame.hidden=false;}
|
|
44
|
+
if(stage===1&&!options.partsOnly){const saved=(lastFrame?.contentWindow as StagePartsWindow|null)?.rigReviewStageParts?.snapshot()??null;const side=options.side?.(),key=(side??'single')+':'+(options.draftBuild?.()??'inspected');let frame=frames.get(key);if(!frame){if(options.correction){for(const old of frames.values())old.remove();frames.clear();}frame=document.createElement('iframe');frame.title=t('Parts and atlas inspection');frame.src=access.route('/stage-parts.html')+'?stageEmbed=1&lang='+getLanguage()+(side?'&side='+side:'');frame.addEventListener('load',()=>{frame!.contentWindow?.postMessage({type:'review-stage-language',language:getLanguage()},location.origin);frame!.contentWindow?.postMessage({type:'review-stage-source',buildId:options.draftBuild?.()??'inspected',state:saved},location.origin);});frames.set(key,frame);panel.append(frame);}else if(options.correction){frame.contentWindow?.postMessage({type:'review-stage-revalidate',state:lastFrame!==frame?saved:null},location.origin);}frame.hidden=false;lastFrame=frame;}
|
|
32
45
|
}
|
|
46
|
+
const correction=async(event:MessageEvent)=>{if(event.origin!==location.origin||![...frames.values()].some(f=>f.contentWindow===event.source)||event.data?.type!=='review-stage-correction'||!options.correction)return;const r=event.data;if(typeof r.part!=='string'||typeof r.sourceHash!=='string'||typeof r.buildId!=='string'||!['chest','mesh','delta'].includes(r.instrument))return;try{await options.correction(r);show(3);}catch(error){status.textContent=error instanceof Error?error.message:String(error);}};
|
|
47
|
+
window.addEventListener('message',correction);
|
|
33
48
|
// Legacy Setup/Animate/Compare selectors keep their IDs, payloads and behavior.
|
|
34
49
|
const legacy=()=>show(3);document.querySelectorAll('[data-mode],[data-inspector]').forEach(b=>b.addEventListener('click',legacy));
|
|
35
50
|
// A side choice reuses the canonical closed A/B picker, then reveals that side's retained atlas.
|
|
@@ -39,7 +54,7 @@ export function bindStageNav(options:{partsOnly?:boolean;model:boolean;side?:()=
|
|
|
39
54
|
// Legacy bookmark/control restoration writes these canonical attributes even when a mode is unchanged.
|
|
40
55
|
const canonical=new MutationObserver(()=>{if(current!==3&&!options.partsOnly&&!pickingSource)show(3);});
|
|
41
56
|
document.querySelectorAll('[data-inspector]').forEach(button=>canonical.observe(button,{attributes:true,attributeFilter:['aria-selected','aria-pressed']}));
|
|
42
|
-
const language=onLanguageChange(()=>{render();if(!panel.hidden)status.textContent=t(stageReason(current,options.model)??(current===1?'Atlas inspection, read only — inspected package. Applied scratch atlas, pre-rig parts, mesh sign-off and draft corrections are unavailable here.':''));for(const f of frames.values()){f.title=t('Parts and atlas inspection');f.contentWindow?.postMessage({type:'review-stage-language',language:getLanguage()},location.origin);}});
|
|
57
|
+
const language=onLanguageChange(()=>{render();if(!panel.hidden)status.textContent=t(stageReason(current,options.model)??(current===1&&options.correction?'Draft rig · structure evidence only':current===1?'Atlas inspection, read only — inspected package. Applied scratch atlas, pre-rig parts, mesh sign-off and draft corrections are unavailable here.':''));for(const f of frames.values()){f.title=t('Parts and atlas inspection');f.contentWindow?.postMessage({type:'review-stage-language',language:getLanguage()},location.origin);}});
|
|
43
58
|
window.addEventListener('resize',place);show(current);
|
|
44
|
-
return ()=>{language();canonical.disconnect();sourcePicker?.querySelectorAll('[data-build-side]').forEach(button=>button.removeEventListener('click',sourceChanged));delete document.documentElement.dataset.inspectionStage;if(workspace)workspace.inert=wasInert;panel.remove();window.removeEventListener('resize',place);document.querySelectorAll('[data-mode],[data-inspector]').forEach(b=>b.removeEventListener('click',legacy));};
|
|
59
|
+
return ()=>{window.removeEventListener('message',correction);language();canonical.disconnect();sourcePicker?.querySelectorAll('[data-build-side]').forEach(button=>button.removeEventListener('click',sourceChanged));delete document.documentElement.dataset.inspectionStage;if(workspace)workspace.inert=wasInert;panel.remove();window.removeEventListener('resize',place);document.querySelectorAll('[data-mode],[data-inspector]').forEach(b=>b.removeEventListener('click',legacy));};
|
|
45
60
|
}
|