rig-review 2.7.1 → 2.9.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/PARTS_VIEW.md +103 -66
- package/docs/REVIEW_PACKAGE.md +32 -17
- package/docs/STABILITY.md +85 -4
- package/docs/WORKFLOWS.md +1 -1
- package/package.json +3 -3
- package/src/build.ts +10 -2
- package/src/cli.ts +4 -5
- package/src/correction-handoff.ts +27 -4
- package/src/feedback-export.ts +1 -1
- package/src/front.ts +2 -1
- package/src/handoff.ts +1 -1
- package/src/interview-project.ts +173 -10
- package/src/job-act.ts +101 -33
- package/src/job-api.ts +194 -13
- package/src/job-cli.ts +6 -2
- package/src/job-contract.ts +203 -19
- package/src/job-front.ts +270 -34
- package/src/job-host.ts +123 -1
- package/src/job-session.ts +227 -47
- package/src/job-source.ts +88 -16
- package/src/manifest.ts +9 -0
- package/src/open-workspace-launch.ts +2 -2
- package/src/open.ts +2 -1
- package/src/parts-comment-crops.ts +126 -31
- package/src/parts-comment.ts +321 -28
- package/src/parts-view.ts +485 -89
- package/src/stage-comment.ts +9 -1
- package/src/stage-parts.ts +5 -1
- package/src/versions.ts +7 -7
- package/web/catalog-en.ts +37 -1
- package/web/catalog-ko.ts +37 -1
- package/web/job-session.ts +830 -161
- package/web/parts-page.ts +217 -0
- package/web/parts-render.ts +26 -19
- package/web/parts-viewport-provider.ts +13 -1
- package/web/parts.css +13 -1
- package/web/parts.html +4 -38
- package/web/parts.ts +644 -267
- package/web/stage-comments.ts +77 -23
- package/web/styles.css +10 -2
- package/web/viewport-controller.ts +13 -4
package/web/parts.ts
CHANGED
|
@@ -2,72 +2,248 @@ import {defaultPartsComparison,paintingRectangle,type PartsComparison} from '../
|
|
|
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
|
-
import {
|
|
5
|
+
import {parsePartsIssue,assertPartsIssueBinding,snapImageRegion,type PartsComment,type PartsIssue} from '../src/parts-comment.ts';
|
|
6
6
|
import {projectMark,unprojectMark,region} from '../src/stage-comment.ts';
|
|
7
|
-
import {
|
|
7
|
+
import {textEntryFocused} from './view-controls.ts';
|
|
8
|
+
import {stagePartsSelectionIndex,type StagePartsState} from './stage-nav.ts';
|
|
9
|
+
import type {JobEnabledActKind,UISubmissionV3} from '../src/job-contract.ts';
|
|
10
|
+
import type {LegacyPartsVerdictView} from '../src/parts-view.ts';
|
|
8
11
|
/**
|
|
9
12
|
* The parts and atlas view (#348). Every part on its own, on a sentinel background, through the shared native-scale
|
|
10
|
-
* viewport controller; the footprints of the parts drawn in front of it; the producer's flags on it; and
|
|
11
|
-
*
|
|
13
|
+
* viewport controller; the footprints of the parts drawn in front of it; the producer's flags on it; and pointed
|
|
14
|
+
* issues saved as `rig-review-parts-verdict/4`. In atlas mode, the pages as packed with every region's box
|
|
12
15
|
* and name, and a click from a region to its own view.
|
|
13
16
|
*
|
|
14
17
|
* Nothing here measures the art: flags come from the producer's files, and the footprint is the front parts' own
|
|
15
18
|
* alpha drawn over the selected part (the parts.json draw order, back first, says which parts are in front).
|
|
16
19
|
*/
|
|
17
|
-
import {
|
|
18
|
-
import { pageInstanceAccess } from './instance-access.ts';
|
|
19
|
-
import { connectLiveWindow } from './live-connection.ts';
|
|
20
|
+
import { applyDomI18n, onLanguageChange, t } from './i18n.ts';
|
|
20
21
|
import { flagLabel, readingGroup, countedFlag } from './parts-flags.ts';
|
|
21
22
|
import { paintAssembly, pickAssembly, paintAssemblyOutline, frontParts, paintAlphaOnly, paintBackground, paintPart, paintMesh, paintOverlay, paintPaintingCrop, paintFootprints } from './parts-render.ts';
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
interface
|
|
25
|
-
interface
|
|
26
|
-
|
|
27
|
-
interface Page { name: string; width: number; height: number; index: number }
|
|
28
|
-
type Flag =
|
|
24
|
+
export interface Mesh { vertices: number[]; triangles: number[]; figures: Record<string, unknown> }
|
|
25
|
+
export interface Item { mesh?: Mesh; meshUnavailable?: 'PARTS_MESH_GENERATED'; name: string; index: number; x: number; y: number; w: number; h: number; page?: string; degrees?: number; image?: boolean;imageHash?:string }
|
|
26
|
+
export interface Page { name: string; width: number; height: number; index: number }
|
|
27
|
+
export type Flag =
|
|
29
28
|
| { id: string; item: string; source: 'mesh_report'; kind: 'faint'; art: number; maxAlpha: number; box: [number, number, number, number] }
|
|
30
29
|
| { 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
|
-
interface ViewData {
|
|
30
|
+
export interface ViewData {
|
|
32
31
|
inspectionSourceHash?:string;
|
|
33
32
|
joinedVerdictBinding?:string;
|
|
34
33
|
verdictReadOnlyReason?:string;
|
|
35
34
|
draft?:{inspectionOnly?:boolean;label:string;buildId:string;inspectionSourceHash:string;mappings:{part:string;skin:string;slot:string;attachment:string;vertices:number;triangles:number}[];evidence:unknown};draftUnavailable?:string;
|
|
36
35
|
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[];
|
|
37
36
|
flagSources: string[]; flagMissing: string[]; verdictFile: string;
|
|
38
|
-
verdict: { comments?:PartsComment[];status: string; parts
|
|
37
|
+
verdict: { issues?:PartsIssue[];comments?:PartsComment[];status: string; parts?: Record<string, unknown> } | null; verdictStale: 'files' | 'flags' | null;
|
|
38
|
+
legacyVerdict?: LegacyPartsVerdictView;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface PanelOutput {
|
|
42
|
+
kind: JobEnabledActKind;
|
|
43
|
+
value(): UISubmissionV3['value'];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface PartsSource {
|
|
47
|
+
view(): Promise<ViewData>;
|
|
48
|
+
image(index: number): Promise<HTMLImageElement>;
|
|
49
|
+
page(index: number): Promise<HTMLImageElement>;
|
|
50
|
+
painting(): Promise<HTMLImageElement> | null;
|
|
51
|
+
difference?(index: number, threshold: number, footprints: boolean): Promise<Response>;
|
|
52
|
+
crop(issue: PartsIssue): Promise<PartsIssue>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface PartsHost {
|
|
56
|
+
initial(): PartsIssue[];
|
|
57
|
+
changed(issues: PartsIssue[]): void;
|
|
58
|
+
register(output: PanelOutput): void;
|
|
59
|
+
locked(): 'open' | 'sent' | 'approved' | 'retry-signoff';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface PartsWorkspaceSlots {
|
|
63
|
+
left: HTMLElement;
|
|
64
|
+
stage: HTMLElement;
|
|
65
|
+
toolbar: HTMLElement;
|
|
66
|
+
side: HTMLElement;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface MountPartsWorkspaceOptions {
|
|
70
|
+
defaultView: 'item' | 'assembled';
|
|
71
|
+
embedded?: boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface PartsWorkspaceHandle {
|
|
75
|
+
dispose(): void;
|
|
76
|
+
select(part: string): void;
|
|
77
|
+
ready: Promise<void>;
|
|
78
|
+
issues(): PartsIssue[];
|
|
79
|
+
snapshot(): StagePartsState | null;
|
|
80
|
+
restore(saved: StagePartsState): Promise<void>;
|
|
81
|
+
revalidate(savedState?: StagePartsState | null): Promise<void>;
|
|
39
82
|
}
|
|
40
83
|
|
|
41
84
|
/** Page pixels shown around a region in its own view, so the packer's bleed and padding are visible. */
|
|
42
85
|
export const REGION_MARGIN = 4;
|
|
43
86
|
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
87
|
+
function mountPartsMarkup(slots: PartsWorkspaceSlots): void {
|
|
88
|
+
const doc = slots.stage.ownerDocument;
|
|
89
|
+
if (slots.left) {
|
|
90
|
+
const title = doc.createElement('h2'); title.id = 'pv-list-title'; title.textContent = t('PARTS');
|
|
91
|
+
const ul = doc.createElement('ul'); ul.id = 'pv-items'; ul.setAttribute('data-pv-items', '');
|
|
92
|
+
slots.left.append(title, ul);
|
|
93
|
+
}
|
|
94
|
+
if (slots.toolbar) {
|
|
95
|
+
slots.toolbar.classList.add('pv-toolbar');
|
|
96
|
+
const assemble = doc.createElement('button'); assemble.type = 'button'; assemble.id = 'pv-assemble'; assemble.setAttribute('aria-pressed', 'false'); assemble.textContent = t('Assembled');
|
|
97
|
+
const bgLabel = doc.createElement('label'); bgLabel.className = 'pv-field'; bgLabel.textContent = t('Background');
|
|
98
|
+
const bgSelect = doc.createElement('select'); bgSelect.id = 'pv-bg'; bgSelect.setAttribute('data-pv-bg', '');
|
|
99
|
+
for (const [val, text] of [['green', 'Green'], ['magenta', 'Magenta'], ['black', 'Black'], ['white', 'White'], ['checker', 'Checker']]) {
|
|
100
|
+
const opt = doc.createElement('option'); opt.value = val!; opt.textContent = t(text!); bgSelect.append(opt);
|
|
101
|
+
}
|
|
102
|
+
bgLabel.append(bgSelect);
|
|
103
|
+
const zoomGroup = doc.createElement('span'); zoomGroup.className = 'pv-group'; zoomGroup.setAttribute('role', 'group'); zoomGroup.setAttribute('aria-label', t('Zoom'));
|
|
104
|
+
for (const [id, text] of [['zoom-out', '−'], ['zoom-in', '+'], ['fit', 'Fit'], ['native-one', '1:1']]) {
|
|
105
|
+
if (id === 'zoom-in') { const zv = doc.createElement('span'); zv.id = 'zoom-value'; zv.textContent = '1:1'; zoomGroup.append(zv); }
|
|
106
|
+
const btn = doc.createElement('button'); btn.type = 'button'; btn.id = id!; btn.textContent = text === 'Fit' ? t('Fit') : text!;
|
|
107
|
+
if (id === 'native-one') btn.setAttribute('aria-pressed', 'true');
|
|
108
|
+
zoomGroup.append(btn);
|
|
109
|
+
}
|
|
110
|
+
const syncLabel = doc.createElement('label'); syncLabel.className = 'pv-field';
|
|
111
|
+
const syncInput = doc.createElement('input'); syncInput.id = 'camera-sync'; syncInput.type = 'checkbox';
|
|
112
|
+
syncLabel.append(syncInput, t('Sync cameras'));
|
|
113
|
+
const commentBtn = doc.createElement('button'); commentBtn.type = 'button'; commentBtn.id = 'stage-comment'; commentBtn.setAttribute('aria-pressed', 'false'); commentBtn.setAttribute('aria-controls', 'stage-comment-list'); commentBtn.textContent = t('Comment · C ({0})', [0]);
|
|
114
|
+
const alphaLabel = doc.createElement('label'); alphaLabel.className = 'pv-field';
|
|
115
|
+
const alphaInput = doc.createElement('input'); alphaInput.type = 'checkbox'; alphaInput.id = 'pv-alpha'; alphaInput.setAttribute('data-pv-alpha', '');
|
|
116
|
+
alphaLabel.append(alphaInput, t('Alpha only'));
|
|
117
|
+
const fpLabel = doc.createElement('label'); fpLabel.className = 'pv-field'; fpLabel.id = 'pv-footprint-control';
|
|
118
|
+
const fpInput = doc.createElement('input'); fpInput.type = 'checkbox'; fpInput.id = 'pv-footprints'; fpInput.setAttribute('data-pv-footprints', '');
|
|
119
|
+
fpLabel.append(fpInput, t('Footprints of parts in front'));
|
|
120
|
+
const compSpan = doc.createElement('span'); compSpan.id = 'pv-comparison'; compSpan.className = 'pv-comparison'; compSpan.hidden = true;
|
|
121
|
+
const compGroupWrap = doc.createElement('span'); compGroupWrap.className = 'pv-field'; compGroupWrap.textContent = t('Painting comparison');
|
|
122
|
+
const compGroup = doc.createElement('span'); compGroup.className = 'pv-group'; compGroup.setAttribute('role', 'group'); compGroup.setAttribute('aria-label', t('Painting comparison'));
|
|
123
|
+
for (const [mode, text] of [['part', 'Part'], ['overlay', 'Overlay'], ['difference', 'Difference']]) {
|
|
124
|
+
const btn = doc.createElement('button'); btn.type = 'button'; btn.setAttribute('data-pv-comparison', mode!); btn.setAttribute('aria-pressed', String(mode === 'part')); btn.textContent = t(text!);
|
|
125
|
+
compGroup.append(btn);
|
|
126
|
+
}
|
|
127
|
+
compGroupWrap.append(compGroup);
|
|
128
|
+
const opLabel = doc.createElement('label'); opLabel.className = 'pv-field'; opLabel.id = 'pv-opacity-control'; opLabel.hidden = true; opLabel.textContent = t('Part opacity');
|
|
129
|
+
const opInput = doc.createElement('input'); opInput.type = 'range'; opInput.id = 'pv-opacity'; opInput.min = '0'; opInput.max = '1'; opInput.step = '0.001'; opInput.value = '0.5';
|
|
130
|
+
const opOut = doc.createElement('output'); opOut.id = 'pv-opacity-value'; opOut.textContent = '50.0%';
|
|
131
|
+
opLabel.append(opInput, opOut);
|
|
132
|
+
const thLabel = doc.createElement('label'); thLabel.className = 'pv-field'; thLabel.id = 'pv-threshold-control'; thLabel.hidden = true; thLabel.textContent = t('Threshold');
|
|
133
|
+
const thInput = doc.createElement('input'); thInput.type = 'number'; thInput.id = 'pv-threshold'; thInput.min = '0'; thInput.max = '255'; thInput.step = '1'; thInput.value = '0';
|
|
134
|
+
thLabel.append(thInput);
|
|
135
|
+
compSpan.append(compGroupWrap, opLabel, thLabel);
|
|
136
|
+
const atlasSwitch = doc.createElement('span'); atlasSwitch.className = 'pv-group'; atlasSwitch.setAttribute('role', 'group'); atlasSwitch.setAttribute('aria-label', t('Atlas view')); atlasSwitch.id = 'pv-atlas-switch'; atlasSwitch.hidden = true;
|
|
137
|
+
for (const [view, text] of [['item', 'Region'], ['page', 'Pages']]) {
|
|
138
|
+
const btn = doc.createElement('button'); btn.type = 'button'; btn.setAttribute('data-pv-view', view!); btn.setAttribute('aria-pressed', String(view === 'item')); btn.textContent = t(text!);
|
|
139
|
+
atlasSwitch.append(btn);
|
|
140
|
+
}
|
|
141
|
+
slots.toolbar.append(assemble, bgLabel, zoomGroup, syncLabel, commentBtn, alphaLabel, fpLabel, compSpan, atlasSwitch);
|
|
142
|
+
}
|
|
143
|
+
if (slots.stage) {
|
|
144
|
+
const wrap = doc.createElement('div'); wrap.className = 'pv-canvas-wrap'; wrap.id = 'stage-layout';
|
|
145
|
+
const box = doc.createElement('div'); box.className = 'pv-canvas-box'; box.id = 'pv-canvas-box';
|
|
146
|
+
const canvas = doc.createElement('canvas'); canvas.id = 'pv-canvas'; canvas.setAttribute('data-pv-canvas', ''); canvas.width = 1; canvas.height = 1;
|
|
147
|
+
const overlay = doc.createElement('div'); overlay.id = 'pv-overlay'; overlay.className = 'pv-overlay';
|
|
148
|
+
box.append(canvas, overlay); wrap.append(box);
|
|
149
|
+
const caption = doc.createElement('p'); caption.id = 'pv-caption'; caption.className = 'pv-subtle';
|
|
150
|
+
const status = doc.createElement('p'); status.id = 'pv-load'; status.className = 'pv-subtle'; status.setAttribute('role', 'status');
|
|
151
|
+
const message = doc.createElement('p'); message.id = 'pv-save-status'; message.className = 'pv-subtle'; message.setAttribute('role', 'status');
|
|
152
|
+
slots.stage.append(status, wrap, caption, message);
|
|
153
|
+
}
|
|
154
|
+
if (slots.side) {
|
|
155
|
+
const flagsSec = doc.createElement('section');
|
|
156
|
+
const flagsH2 = doc.createElement('h2'); flagsH2.id = 'pv-flags-title'; flagsH2.textContent = t('PRODUCER FLAGS');
|
|
157
|
+
const flagsUl = doc.createElement('ul'); flagsUl.id = 'pv-flags'; flagsUl.setAttribute('data-pv-flags', '');
|
|
158
|
+
const flagsSources = doc.createElement('p'); flagsSources.id = 'pv-flag-sources'; flagsSources.className = 'pv-subtle';
|
|
159
|
+
flagsSec.append(flagsH2, flagsUl, flagsSources);
|
|
160
|
+
const legacyUl = doc.createElement('ul'); legacyUl.id = 'pv-legacy-flagged'; legacyUl.className = 'pv-legacy-flagged'; legacyUl.hidden = true;
|
|
161
|
+
slots.side.append(flagsSec, legacyUl);
|
|
162
|
+
}
|
|
68
163
|
}
|
|
69
|
-
|
|
70
|
-
|
|
164
|
+
|
|
165
|
+
export function mountPartsWorkspace(
|
|
166
|
+
slots: PartsWorkspaceSlots,
|
|
167
|
+
source: PartsSource,
|
|
168
|
+
host: PartsHost,
|
|
169
|
+
options: MountPartsWorkspaceOptions,
|
|
170
|
+
): PartsWorkspaceHandle {
|
|
171
|
+
const roots = [slots.left, slots.stage, slots.toolbar, slots.side];
|
|
172
|
+
if (roots.some(root => !root)) throw new Error('PARTS_WORKSPACE_SLOT_REQUIRED');
|
|
173
|
+
const doc = slots.stage.ownerDocument;
|
|
174
|
+
const win = doc.defaultView;
|
|
175
|
+
if (!win || roots.some(root => root.ownerDocument !== doc)) throw new Error('PARTS_WORKSPACE_DOCUMENT_REQUIRED');
|
|
176
|
+
const eventWindow: EventTarget = win;
|
|
177
|
+
for (const root of roots) root.replaceChildren();
|
|
178
|
+
mountPartsMarkup(slots);
|
|
179
|
+
const query = <T extends Element = HTMLElement>(selector: string): T | null => {
|
|
180
|
+
for (const root of roots) {
|
|
181
|
+
if (root.matches(selector)) return root as unknown as T;
|
|
182
|
+
const found = root.querySelector<T>(selector);
|
|
183
|
+
if (found) return found;
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
};
|
|
187
|
+
const queryAll = <T extends Element = HTMLElement>(selector: string): T[] =>
|
|
188
|
+
[...new Set(roots.flatMap(root => [...root.querySelectorAll<T>(selector)]))];
|
|
189
|
+
const $ = <T extends HTMLElement>(id: string): T => {
|
|
190
|
+
const found = query<T>(`#${id}`);
|
|
191
|
+
if (!found) throw new Error(`PARTS_WORKSPACE_NODE_REQUIRED: ${id}`);
|
|
192
|
+
return found;
|
|
193
|
+
};
|
|
194
|
+
const disposers: (() => void)[] = [];
|
|
195
|
+
let disposed = false;
|
|
196
|
+
let resolveReady!: () => void;
|
|
197
|
+
let rejectReady!: (error: unknown) => void;
|
|
198
|
+
let readyPending = true;
|
|
199
|
+
const ready = new Promise<void>((resolve, reject) => { resolveReady = resolve; rejectReady = reject; });
|
|
200
|
+
const settleReady = (error?: unknown) => {
|
|
201
|
+
if (!readyPending) return;
|
|
202
|
+
readyPending = false;
|
|
203
|
+
if (error === undefined) resolveReady(); else rejectReady(error);
|
|
204
|
+
};
|
|
205
|
+
let pendingSelectPart: string | null = null;
|
|
206
|
+
let mountActive = false;
|
|
207
|
+
const activate = (event: Event) => {
|
|
208
|
+
mountActive = roots.some(root => event.target instanceof win.Node && root.contains(event.target));
|
|
209
|
+
};
|
|
210
|
+
for (const event of ['pointerdown', 'focusin']) {
|
|
211
|
+
doc.addEventListener(event, activate, true);
|
|
212
|
+
disposers.push(() => doc.removeEventListener(event, activate, true));
|
|
213
|
+
}
|
|
214
|
+
const stageEmbedded = Boolean(options.embedded);
|
|
215
|
+
const state = { data: null as ViewData | null, selected: 0, zoom: 1, bg: 'checker', alpha: false, footprints: false, comparison:defaultPartsComparison(), differenceThreshold:0, hidden: new Set<string>(), view: options.defaultView as 'item' | 'page' | 'assembled', page: 0, meshVisible: false };
|
|
216
|
+
const comments:PartsIssue[]=[];let commentUi:ReturnType<typeof bindStageComments>|null=null;let viewport:ReturnType<typeof createPartsViewport>|null=null;let painting=true;
|
|
217
|
+
let paintingHeld = false;
|
|
218
|
+
let hoverName: string | null = null;
|
|
219
|
+
const highlightedParts = new Set<string>();
|
|
220
|
+
const images = new Map<string, HTMLImageElement>();
|
|
221
|
+
const pendingImages = new Map<string, Promise<HTMLImageElement>>();
|
|
222
|
+
let imageGeneration = 0;
|
|
223
|
+
function cachedImage(key: string, read: () => Promise<HTMLImageElement>): Promise<HTMLImageElement> {
|
|
224
|
+
const cached = images.get(key);
|
|
225
|
+
if (cached) return Promise.resolve(cached);
|
|
226
|
+
const pending = pendingImages.get(key);
|
|
227
|
+
if (pending) return pending;
|
|
228
|
+
const generation = imageGeneration;
|
|
229
|
+
const result = read().then(image => {
|
|
230
|
+
if (!disposed && generation === imageGeneration) images.set(key, image);
|
|
231
|
+
return image;
|
|
232
|
+
}).finally(() => { if (pendingImages.get(key) === result) pendingImages.delete(key); });
|
|
233
|
+
pendingImages.set(key, result);
|
|
234
|
+
return result;
|
|
235
|
+
}
|
|
236
|
+
const itemImage = (item: Item) => cachedImage(`image:${item.index}`, () => source.image(item.index));
|
|
237
|
+
const pageImage = (name: string) => {
|
|
238
|
+
const page = state.data?.pages.find(page => page.name === name);
|
|
239
|
+
if (!page) return Promise.reject(new Error('PARTS_PAINT_FAILED'));
|
|
240
|
+
return cachedImage(`page:${page.index}`, () => source.page(page.index));
|
|
241
|
+
};
|
|
242
|
+
const paintingImage = () => cachedImage('painting', () => {
|
|
243
|
+
const image = source.painting();
|
|
244
|
+
if (!image) return Promise.reject(new Error('PARTS_REFERENCE_UNAVAILABLE: supply --painting to compare the original painting'));
|
|
245
|
+
return image;
|
|
246
|
+
});
|
|
71
247
|
|
|
72
248
|
function setCanvas(canvas: HTMLCanvasElement, w: number, h: number): CanvasRenderingContext2D {
|
|
73
249
|
canvas.width = w; canvas.height = h;
|
|
@@ -78,7 +254,7 @@ function setCanvas(canvas: HTMLCanvasElement, w: number, h: number): CanvasRende
|
|
|
78
254
|
}
|
|
79
255
|
|
|
80
256
|
function overlayBox(x: number, y: number, w: number, h: number): HTMLDivElement {
|
|
81
|
-
const div =
|
|
257
|
+
const div = doc.createElement('div');
|
|
82
258
|
div.className = 'pv-box';
|
|
83
259
|
div.style.left = `${x * state.zoom}px`; div.style.top = `${y * state.zoom}px`;
|
|
84
260
|
div.style.width = `${w * state.zoom}px`; div.style.height = `${h * state.zoom}px`;
|
|
@@ -87,14 +263,31 @@ function overlayBox(x: number, y: number, w: number, h: number): HTMLDivElement
|
|
|
87
263
|
|
|
88
264
|
let paintToken = 0;
|
|
89
265
|
let paintFailure:string|null=null,paintReset=false;
|
|
266
|
+
let paintBusyStatus: {token: number; text: string} | null = null;
|
|
267
|
+
function syncPaintState(): void {
|
|
268
|
+
slots.stage.dataset.partsPaintState = disposed ? 'disposed' : painting ? 'busy' : paintFailure ? 'failed' : 'ready';
|
|
269
|
+
slots.stage.setAttribute('aria-busy', String(painting));
|
|
270
|
+
const toggle = $<HTMLButtonElement>('stage-comment');
|
|
271
|
+
toggle.disabled = painting || paintingHeld;
|
|
272
|
+
toggle.setAttribute('aria-busy', String(painting));
|
|
273
|
+
if (commentUi) commentUi.refresh();
|
|
274
|
+
else toggle.textContent = t(painting ? 'Comment · C ({0}) · Rendering' : 'Comment · C ({0})', [0]);
|
|
275
|
+
}
|
|
276
|
+
|
|
90
277
|
async function paint():Promise<void>{
|
|
91
278
|
const token=++paintToken;painting=true;
|
|
279
|
+
if (paintBusyStatus) {
|
|
280
|
+
if ($('pv-save-status').textContent === paintBusyStatus.text) paintBusyStatus.token = token;
|
|
281
|
+
else paintBusyStatus = null;
|
|
282
|
+
}
|
|
283
|
+
syncPaintState();
|
|
92
284
|
try{
|
|
93
|
-
await paintRaster(token);if(token!==paintToken)return;
|
|
94
|
-
await paintReference(token);if(token!==paintToken)return;
|
|
95
|
-
if(paintFailure)$('pv-save-status').textContent='';paintFailure=null;viewport?.fitCamera();commentUi?.refresh();
|
|
285
|
+
await paintRaster(token);if(disposed||token!==paintToken)return;
|
|
286
|
+
await paintReference(token);if(disposed||token!==paintToken)return;
|
|
287
|
+
if(paintFailure&&$('pv-save-status').textContent===t(paintFailure))$('pv-save-status').textContent='';paintFailure=null;viewport?.fitCamera();commentUi?.refresh();settleReady();
|
|
96
288
|
}catch(error){
|
|
97
|
-
if(token!==paintToken)return;
|
|
289
|
+
if(disposed||token!==paintToken)return;
|
|
290
|
+
settleReady(error instanceof Error?error:new Error('PARTS_PAINT_FAILED'));
|
|
98
291
|
const failure=error instanceof Error&&error.message.startsWith('PARTS_DIFFERENCE_')?error.message:'PARTS_PAINT_FAILED: view could not be rendered; select the part to retry';
|
|
99
292
|
const canvas=$<HTMLCanvasElement>('pv-canvas');canvas.getContext('2d')?.clearRect(0,0,canvas.width,canvas.height);
|
|
100
293
|
const ref=$<HTMLCanvasElement>('pv-reference') as HTMLCanvasElement|null;if(ref){if(canvas.width>0&&canvas.height>0){ref.width=canvas.width;ref.height=canvas.height;}ref.getContext('2d')?.clearRect(0,0,ref.width,ref.height);}
|
|
@@ -103,15 +296,55 @@ async function paint():Promise<void>{
|
|
|
103
296
|
try{viewport?.writeCamera?.('rig',{zoom:1,center:null});viewport?.writeCamera?.('reference',{zoom:1,center:null});viewport?.fitCamera();}
|
|
104
297
|
finally{paintReset=false;paintFailure=failure;}
|
|
105
298
|
commentUi?.refresh();
|
|
106
|
-
}finally{
|
|
299
|
+
}finally{
|
|
300
|
+
if(!disposed&&token===paintToken){
|
|
301
|
+
painting=false;
|
|
302
|
+
if(paintBusyStatus?.token===token){
|
|
303
|
+
if(!paintFailure&&$('pv-save-status').textContent===paintBusyStatus.text)$('pv-save-status').textContent='';
|
|
304
|
+
paintBusyStatus=null;
|
|
305
|
+
}
|
|
306
|
+
syncPaintState();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
107
309
|
}
|
|
108
310
|
const assemblyAlpha=new Map<string,Uint8ClampedArray>();
|
|
109
311
|
function sourceAlpha(item:Item,img:HTMLImageElement):Uint8ClampedArray {
|
|
110
312
|
const cached=assemblyAlpha.get(item.name);if(cached)return cached;
|
|
111
|
-
const c=
|
|
313
|
+
const c=doc.createElement('canvas');c.width=item.w;c.height=item.h;const ctx=c.getContext('2d')!;ctx.drawImage(img,0,0);
|
|
112
314
|
const rgba=ctx.getImageData(0,0,item.w,item.h).data,alpha=new Uint8ClampedArray(item.w*item.h);for(let i=0;i<alpha.length;i++)alpha[i]=rgba[i*4+3]!;assemblyAlpha.set(item.name,alpha);return alpha;
|
|
113
315
|
}
|
|
114
316
|
|
|
317
|
+
function drawMeshes(ctx: CanvasRenderingContext2D, layers: {box: Item; image: HTMLImageElement}[], assembled = true): void {
|
|
318
|
+
if (!state.meshVisible) return;
|
|
319
|
+
for (const {box, image} of layers) {
|
|
320
|
+
if (!box.mesh) continue;
|
|
321
|
+
const selected = box.index === state.selected;
|
|
322
|
+
ctx.save();
|
|
323
|
+
if (assembled) ctx.translate(box.x, box.y);
|
|
324
|
+
paintMesh(ctx, image, box.w, box.h, box.mesh,
|
|
325
|
+
(w, h) => Object.assign(doc.createElement('canvas'), {width: w, height: h}),
|
|
326
|
+
{tint: selected, alpha: selected ? 1 : .35});
|
|
327
|
+
ctx.restore();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function renderAssemblySelection(layers: {box: Item; image: HTMLImageElement}[]): void {
|
|
332
|
+
const overlay = $('pv-overlay'), canvas = $<HTMLCanvasElement>('pv-canvas');
|
|
333
|
+
overlay.replaceChildren();
|
|
334
|
+
if (paintingHeld) return;
|
|
335
|
+
const names = new Set([state.data!.items[state.selected]!.name, ...highlightedParts, hoverName]);
|
|
336
|
+
for (const {box, image} of layers) {
|
|
337
|
+
if (!names.has(box.name)) continue;
|
|
338
|
+
const outline = doc.createElement('canvas');
|
|
339
|
+
outline.width = canvas.width;outline.height = canvas.height;outline.dataset.assemblyOutline = box.name;
|
|
340
|
+
paintAssemblyOutline(outline.getContext('2d')!, box, sourceAlpha(box, image));overlay.append(outline);
|
|
341
|
+
if (box.name !== hoverName) continue;
|
|
342
|
+
const label = overlayBox(box.x, box.y, box.w, box.h), text = doc.createElement('span');
|
|
343
|
+
label.style.pointerEvents = 'none';label.dataset.assemblyHover = box.name;text.textContent = box.name;
|
|
344
|
+
label.append(text);overlay.append(label);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
115
348
|
function partFrame(data:ViewData,item:Item) {
|
|
116
349
|
if(state.view==='assembled'&&data.rigSize) {
|
|
117
350
|
return {x:0,y:0,w:data.rigSize[0],h:data.rigSize[1]};
|
|
@@ -144,22 +377,23 @@ async function paintRaster(token:number): Promise<void> {
|
|
|
144
377
|
if(state.view==='assembled'&&data.mode==='parts'&&data.rigSize){
|
|
145
378
|
const shown=data.items.filter(i=>!state.hidden.has(i.name));
|
|
146
379
|
const layers=await Promise.all(shown.map(async box=>({box,image:await itemImage(box)})));
|
|
147
|
-
const original=state.comparison.mode==='overlay'&&data.painting?await
|
|
148
|
-
if(token!==paintToken)return;
|
|
380
|
+
const original=(paintingHeld||state.comparison.mode==='overlay')&&data.painting?await paintingImage():null;
|
|
381
|
+
if(disposed||token!==paintToken)return;
|
|
149
382
|
const ctx=setCanvas(canvas,w,h);
|
|
150
383
|
if(original){
|
|
151
384
|
paintPaintingCrop(ctx,original,paintingRectangle({x:0,y:0,w,h},data.rigSize,data.painting!),w,h,state.bg);
|
|
152
|
-
const assembled=
|
|
385
|
+
const assembled=doc.createElement('canvas');assembled.width=w;assembled.height=h;
|
|
386
|
+
paintAssembly(assembled.getContext('2d')!,w,h,layers,{bg:state.bg,alpha:false,transparent:true});
|
|
387
|
+
ctx.globalAlpha=paintingHeld?0:state.comparison.opacity;ctx.drawImage(assembled,0,0);ctx.globalAlpha=1;
|
|
153
388
|
}else paintAssembly(ctx,w,h,layers,{bg:state.bg,alpha:state.alpha});
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
caption.textContent=t('Assembled package · {count} visible parts. Selection and verdict remain per part.',{count:shown.length});
|
|
389
|
+
if (!paintingHeld) drawMeshes(ctx, layers);
|
|
390
|
+
renderAssemblySelection(layers);
|
|
391
|
+
caption.textContent=t('Assembled package · {count} visible parts.',{count:shown.length});
|
|
158
392
|
return;
|
|
159
393
|
}
|
|
160
394
|
if (data.mode === 'atlas' && state.view === 'page') {
|
|
161
395
|
const page = data.pages[state.page]!, img = await pageImage(page.name);
|
|
162
|
-
if (token !== paintToken) return;
|
|
396
|
+
if (disposed || token !== paintToken) return;
|
|
163
397
|
const ctx = setCanvas(canvas, w, h);
|
|
164
398
|
if (state.alpha) paintAlphaOnly(ctx, img, 0, 0, page.width, page.height);
|
|
165
399
|
else { paintBackground(ctx, page.width, page.height, state.bg); ctx.drawImage(img, 0, 0); }
|
|
@@ -168,7 +402,7 @@ async function paintRaster(token:number): Promise<void> {
|
|
|
168
402
|
box.dataset.viewportAction = 'select-region';
|
|
169
403
|
box.dataset.region = r.name; box.dataset.x = String(r.x); box.dataset.y = String(r.y); box.dataset.w = String(r.w); box.dataset.h = String(r.h);
|
|
170
404
|
if (r.index === item.index) box.setAttribute('aria-current', 'true');
|
|
171
|
-
const label =
|
|
405
|
+
const label = doc.createElement('span'); label.textContent = r.name; box.append(label);
|
|
172
406
|
box.title = `${r.name} · ${r.x},${r.y} ${r.w}×${r.h}${r.degrees ? ` · ${r.degrees}°` : ''}`;
|
|
173
407
|
box.onclick = () => { select(r.index); setView('item'); };
|
|
174
408
|
return box;
|
|
@@ -181,7 +415,7 @@ async function paintRaster(token:number): Promise<void> {
|
|
|
181
415
|
}
|
|
182
416
|
if (data.mode === 'atlas') {
|
|
183
417
|
const page = data.pages.find(p => p.name === item.page)!, img = await pageImage(item.page!);
|
|
184
|
-
if (token !== paintToken) return;
|
|
418
|
+
if (disposed || token !== paintToken) return;
|
|
185
419
|
const ctx = setCanvas(canvas, w, h);
|
|
186
420
|
if (state.alpha) paintAlphaOnly(ctx, img, x, y, w, h);
|
|
187
421
|
else { paintBackground(ctx, w, h, state.bg); ctx.drawImage(img, x, y, w, h, 0, 0, w, h); }
|
|
@@ -191,23 +425,33 @@ async function paintRaster(token:number): Promise<void> {
|
|
|
191
425
|
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 }) : '');
|
|
192
426
|
return;
|
|
193
427
|
}
|
|
428
|
+
if (paintingHeld && data.painting) {
|
|
429
|
+
const original = await paintingImage();
|
|
430
|
+
if (disposed || token !== paintToken) return;
|
|
431
|
+
const ctx = setCanvas(canvas, w, h);
|
|
432
|
+
paintPaintingCrop(ctx, original, paintingRectangle(item, data.rigSize!, data.painting), w, h, state.bg);
|
|
433
|
+
overlay.replaceChildren();
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
194
436
|
if(state.comparison.mode==='difference'){
|
|
195
|
-
|
|
437
|
+
if (!source.difference) throw new Error('PARTS_DIFFERENCE_UNAVAILABLE: declared painting_in_rig and individual part view required.');
|
|
438
|
+
const response = await source.difference(item.index, state.comparison.threshold, state.footprints);
|
|
196
439
|
if(!response.ok){const out=await response.json() as {error:string};throw new Error(out.error);}
|
|
440
|
+
const meshImage=state.meshVisible&&item.mesh?await itemImage(item):null;
|
|
197
441
|
const image=await createImageBitmap(await response.blob());
|
|
198
|
-
try{if(token!==paintToken)return;const ctx=setCanvas(canvas,w,h);paintBackground(ctx,w,h,state.bg);ctx.drawImage(image,0,0);overlay.replaceChildren();
|
|
442
|
+
try{if(disposed||token!==paintToken)return;const ctx=setCanvas(canvas,w,h);paintBackground(ctx,w,h,state.bg);ctx.drawImage(image,0,0);if(meshImage)drawMeshes(ctx,[{box:item,image:meshImage}],false);overlay.replaceChildren();
|
|
199
443
|
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')??''});
|
|
200
444
|
}finally{image.close();}return;
|
|
201
445
|
}
|
|
202
446
|
const img = await itemImage(item), front = state.footprints ? frontParts(data.items, item) : [];
|
|
203
447
|
const fronts = await Promise.all(front.map(async o => ({ o, img: await itemImage(o) })));
|
|
204
|
-
const original=state.comparison.mode==='overlay'&&data.painting?await
|
|
205
|
-
if (token !== paintToken) return;
|
|
448
|
+
const original=(paintingHeld||state.comparison.mode==='overlay')&&data.painting?await paintingImage():null;
|
|
449
|
+
if (disposed || token !== paintToken) return;
|
|
206
450
|
const ctx = setCanvas(canvas, w, h);
|
|
207
|
-
const makeCanvas=(w:number,h:number)=>Object.assign(
|
|
451
|
+
const makeCanvas=(w:number,h:number)=>Object.assign(doc.createElement('canvas'),{width:w,height:h});
|
|
208
452
|
if(original){paintOverlay(ctx,item,img,original,paintingRectangle(item,data.rigSize!,data.painting!),state.comparison.opacity,state.bg);paintFootprints(ctx,item,fronts.map(f=>({box:f.o,image:f.img})),makeCanvas);}
|
|
209
|
-
else paintPart(ctx, item, img, { bg: state.bg, alpha: state.alpha, fronts: fronts.map(f => ({ box: f.o, image: f.img })), makeCanvas: (w, h) => Object.assign(
|
|
210
|
-
|
|
453
|
+
else paintPart(ctx, item, img, { bg: state.bg, alpha: state.alpha, fronts: fronts.map(f => ({ box: f.o, image: f.img })), makeCanvas: (w, h) => Object.assign(doc.createElement('canvas'), { width: w, height: h }) });
|
|
454
|
+
drawMeshes(ctx, [{box: item, image: img}], false);
|
|
211
455
|
overlay.replaceChildren(...data.flags.filter((f): f is Extract<Flag, { kind: 'faint' }> => f.item === item.name && f.kind === 'faint').map(f => {
|
|
212
456
|
const box = overlayBox(f.box[0], f.box[1], f.box[2], f.box[3]);
|
|
213
457
|
box.dataset.flag = f.id;
|
|
@@ -217,17 +461,17 @@ async function paintRaster(token:number): Promise<void> {
|
|
|
217
461
|
+ (state.footprints ? ' ' + (front.length === 1 ? t('Tinted: the footprint of the part drawn in front ({names}).', { names: front[0]!.name }) : front.length ? t('Tinted: the footprints of {count} parts drawn in front ({names}).', { count: front.length, names: front.map(o => o.name).join(', ') }) : t('No part is drawn in front of it.')) : '');
|
|
218
462
|
}
|
|
219
463
|
|
|
220
|
-
async function paintReference(token:number):Promise<void>{const data=state.data,item=data?.items[state.selected];if(!data?.painting||!item)return;const img=await
|
|
464
|
+
async function paintReference(token:number):Promise<void>{const data=state.data,item=data?.items[state.selected];if(!data?.painting||!item)return;const img=await paintingImage();if(disposed||token!==paintToken||data!==state.data||item!==state.data?.items[state.selected])return;const box=partFrame(data,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);}
|
|
221
465
|
|
|
222
466
|
function renderComparison():void {
|
|
223
467
|
const active=state.data?.mode==='parts'&&(!!state.data.painting||!!state.data.differenceAvailable),overlay=active&&state.comparison.mode==='overlay',difference=state.comparison.mode==='difference';
|
|
224
|
-
const button=
|
|
225
|
-
|
|
468
|
+
const button=query<HTMLButtonElement>('[data-pv-comparison="difference"]');if(button){button.disabled=!state.data?.differenceAvailable||!source.difference||state.view!=='item';button.title=button.disabled?t('PARTS_DIFFERENCE_UNAVAILABLE: declared painting_in_rig and individual part view required.'):'';}
|
|
469
|
+
const overlayButton=query<HTMLButtonElement>('[data-pv-comparison="overlay"]');if(overlayButton)overlayButton.disabled=!state.data?.painting;
|
|
226
470
|
$('pv-threshold-control').hidden=!difference;$<HTMLInputElement>('pv-threshold').value=String(state.comparison.mode==='difference'?state.comparison.threshold:state.differenceThreshold);
|
|
227
|
-
$('pv-comparison').hidden=!active;for(const b of
|
|
471
|
+
$('pv-comparison').hidden=!active;for(const b of queryAll<HTMLElement>('[data-pv-comparison]'))b.setAttribute('aria-pressed',String(b.dataset.pvComparison===state.comparison.mode));
|
|
228
472
|
$('pv-opacity-control').hidden=!overlay;$<HTMLInputElement>('pv-opacity').value=String(state.comparison.opacity);$('pv-opacity-value').textContent=(state.comparison.opacity*100).toFixed(1)+'%';
|
|
229
473
|
$<HTMLInputElement>('pv-alpha').disabled=overlay||difference;
|
|
230
|
-
|
|
474
|
+
|
|
231
475
|
$<HTMLInputElement>('pv-footprints').disabled=state.data?.mode==='atlas'||state.view==='assembled';
|
|
232
476
|
}
|
|
233
477
|
|
|
@@ -236,13 +480,13 @@ function renderFlags(): void {
|
|
|
236
480
|
const list = $('pv-flags');
|
|
237
481
|
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 === '')] : [];
|
|
238
482
|
const row = (f: Flag): HTMLLIElement => {
|
|
239
|
-
const li =
|
|
483
|
+
const li = doc.createElement('li');
|
|
240
484
|
li.dataset.flagId = f.id; li.dataset.flagSource = f.source;
|
|
241
|
-
const label =
|
|
485
|
+
const label = doc.createElement('span'); label.className = 'pv-flag-label'; label.textContent = flagLabel(f, t);
|
|
242
486
|
li.append(label);
|
|
243
487
|
if (f.kind === 'check') {
|
|
244
488
|
// The producer's object, verbatim, one click away: the label names its fields and hides none of it.
|
|
245
|
-
const raw =
|
|
489
|
+
const raw = doc.createElement('details'), summary = doc.createElement('summary'), code = doc.createElement('code');
|
|
246
490
|
summary.textContent = t('Producer line'); code.textContent = `${f.path}: ${f.line}`;
|
|
247
491
|
raw.append(summary, code); li.append(raw);
|
|
248
492
|
}
|
|
@@ -252,7 +496,7 @@ function renderFlags(): void {
|
|
|
252
496
|
list.replaceChildren(...(['mesh_report', 'check'] as const).flatMap(source => {
|
|
253
497
|
const fromSource = flags.filter(f => f.source === source);
|
|
254
498
|
if (!fromSource.length) return [];
|
|
255
|
-
const sourceItem =
|
|
499
|
+
const sourceItem = doc.createElement('li'), heading = doc.createElement('h3');
|
|
256
500
|
sourceItem.dataset.pvSource = source;
|
|
257
501
|
heading.textContent = source === 'mesh_report' ? 'mesh_report.json' : 'check.json';
|
|
258
502
|
sourceItem.append(heading);
|
|
@@ -260,7 +504,7 @@ function renderFlags(): void {
|
|
|
260
504
|
for (const category of categories) {
|
|
261
505
|
const selected = fromSource.filter(f => readingGroup(f) === category);
|
|
262
506
|
if (!selected.length) continue;
|
|
263
|
-
const section =
|
|
507
|
+
const section = doc.createElement('details'), title = doc.createElement('summary');
|
|
264
508
|
section.dataset.pvCategory = category;
|
|
265
509
|
title.textContent = t(category === 'mesh' ? 'Mesh flags' : category === 'part' ? 'Part findings' : category === 'pair' ? 'Pair readings' : category === 'evidence' ? 'Check evidence' : 'Unclassified check rows');
|
|
266
510
|
section.append(title);
|
|
@@ -271,7 +515,7 @@ function renderFlags(): void {
|
|
|
271
515
|
group.push(f); roots.set(root, group);
|
|
272
516
|
}
|
|
273
517
|
for (const [root, group] of roots) {
|
|
274
|
-
const details =
|
|
518
|
+
const details = doc.createElement('details'), summary = doc.createElement('summary'), rows = doc.createElement('ul');
|
|
275
519
|
details.dataset.pvRoot = root; details.dataset.flagSource = source;
|
|
276
520
|
summary.textContent = group.length === 1 ? t('{root} · 1 row', { root }) : t('{root} · {count} rows', { root, count: group.length });
|
|
277
521
|
rows.append(...group.map(row)); details.append(summary, rows); section.append(details);
|
|
@@ -280,7 +524,7 @@ function renderFlags(): void {
|
|
|
280
524
|
}
|
|
281
525
|
return [sourceItem];
|
|
282
526
|
}));
|
|
283
|
-
if (!flags.length) { const li =
|
|
527
|
+
if (!flags.length) { const li = doc.createElement('li'); li.className = 'pv-none'; li.textContent = t('No producer flag names this part.'); list.replaceChildren(li); }
|
|
284
528
|
$('pv-flag-sources').textContent = [
|
|
285
529
|
data.flagSources.length ? t('Read from: {files}.', { files: data.flagSources.join(', ') }) : '',
|
|
286
530
|
data.flagMissing.length ? t('Not found: {files}.', { files: data.flagMissing.join(', ') }) : '',
|
|
@@ -293,13 +537,14 @@ function renderFlags(): void {
|
|
|
293
537
|
function renderList(): void {
|
|
294
538
|
const data = state.data!, list = $('pv-items');
|
|
295
539
|
const seen = new Set<string>();
|
|
540
|
+
const issueList = comments;
|
|
296
541
|
list.replaceChildren(...data.items.filter(i => !seen.has(i.name) && seen.add(i.name)).map(item => {
|
|
297
|
-
const li =
|
|
542
|
+
const li = doc.createElement('li'), button = doc.createElement('button');
|
|
298
543
|
button.type = 'button'; button.dataset.pvItem = item.name; button.title = item.name;
|
|
299
544
|
if (data.items[state.selected]?.name === item.name) button.setAttribute('aria-current', 'true');
|
|
300
|
-
const name =
|
|
545
|
+
const name = doc.createElement('span'); name.className = 'pv-name'; name.textContent = item.name;
|
|
301
546
|
const onItem = [...data.flags.filter(f => f.kind === 'faint'), ...(data.readings ?? [])].filter(f => f.item === item.name && countedFlag(f));
|
|
302
|
-
const flags =
|
|
547
|
+
const flags = doc.createElement('span'); flags.className = 'pv-count';
|
|
303
548
|
// flagSources holds actual basenames (including custom.json); flagMissing canonically names unread kinds.
|
|
304
549
|
const meshRead = !data.flagMissing.includes('mesh_report.json'), checkRead = !data.flagMissing.includes('check.json');
|
|
305
550
|
const mesh = onItem.filter(f => f.source === 'mesh_report').length, check = onItem.filter(f => f.source === 'check').length;
|
|
@@ -308,178 +553,131 @@ function renderList(): void {
|
|
|
308
553
|
else if (meshRead) flags.textContent = t('mesh {mesh}', { mesh });
|
|
309
554
|
else if (checkRead) flags.textContent = t('check {check}', { check });
|
|
310
555
|
}
|
|
311
|
-
const
|
|
312
|
-
const badge =
|
|
556
|
+
const issueCount = issueList.filter(c => c.parts.some(p => p.name === item.name)).length;
|
|
557
|
+
const badge = doc.createElement('span'); badge.className = 'pv-badge'; badge.dataset.issues = String(issueCount); badge.textContent = issueCount ? String(issueCount) : '';
|
|
313
558
|
button.append(name, flags, badge);
|
|
314
559
|
button.onclick = () => { select(item.index); if (data.mode === 'atlas') setView('item'); };
|
|
315
560
|
li.append(button);
|
|
316
561
|
if(data.mode==='parts'){
|
|
317
|
-
const label=
|
|
562
|
+
const label=doc.createElement('label'),visible=doc.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}));
|
|
318
563
|
visible.onchange=()=>{if(visible.checked)state.hidden.delete(item.name);else state.hidden.add(item.name);void paint();};label.append(visible);li.append(label);
|
|
319
564
|
}
|
|
320
565
|
return li;
|
|
321
566
|
}));
|
|
322
567
|
}
|
|
323
568
|
|
|
324
|
-
function renderVerdict(): void {
|
|
325
|
-
const item = state.data!.items[state.selected];
|
|
326
|
-
if (!item) return;
|
|
327
|
-
const entry = state.verdict.get(item.name) ?? { outcome: 'pending' as Outcome, note: '' };
|
|
328
|
-
for (const radio of document.querySelectorAll<HTMLInputElement>('input[data-pv-outcome]')) radio.checked = radio.value === entry.outcome;
|
|
329
|
-
$<HTMLTextAreaElement>('pv-note').value = entry.note;
|
|
330
|
-
$('pv-comment-count').textContent=t('Comments on this part: {count}',{count:comments.filter(c=>c.part===item.name).length});
|
|
331
|
-
}
|
|
332
|
-
|
|
333
569
|
function renderMesh(): void {
|
|
334
|
-
|
|
335
|
-
|
|
570
|
+
query('#pv-mesh-panel')?.remove();
|
|
571
|
+
query('#pv-mesh-control')?.remove();
|
|
336
572
|
const item = state.data!.items[state.selected]!;
|
|
337
|
-
|
|
338
|
-
const control =
|
|
339
|
-
const toggle =
|
|
340
|
-
toggle.onchange = () => {
|
|
341
|
-
control.append(toggle, t('mesh from rig.json UVs'));
|
|
342
|
-
const panel =
|
|
343
|
-
const heading =
|
|
344
|
-
|
|
573
|
+
const meshCount = state.data!.items.filter(part => part.mesh).length;
|
|
574
|
+
const control = doc.createElement('label'); control.id = 'pv-mesh-control'; control.className = 'pv-field';
|
|
575
|
+
const toggle = doc.createElement('input'); toggle.type = 'checkbox'; toggle.checked = state.meshVisible;
|
|
576
|
+
toggle.onchange = () => { state.meshVisible = toggle.checked; void paint(); };
|
|
577
|
+
control.append(toggle, meshCount ? t('mesh from rig.json UVs') : t('Mesh (none 0/{0})', [state.data!.items.length])); query('.pv-toolbar')?.append(control);
|
|
578
|
+
const panel = doc.createElement('section'); panel.id = 'pv-mesh-panel';
|
|
579
|
+
const heading = doc.createElement('h2'); heading.textContent = t('Mesh geometry'); panel.append(heading);
|
|
580
|
+
if (!item.mesh) {
|
|
581
|
+
const unavailable = doc.createElement('p');
|
|
582
|
+
unavailable.textContent = t(item.meshUnavailable === 'PARTS_MESH_GENERATED' ? 'PARTS_MESH_GENERATED: No mesh geometry is available for this part.' : meshCount ? 'No mesh geometry is available for this part.' : 'No mesh geometry is available for this draft.');
|
|
583
|
+
panel.append(unavailable);slots.side.append(panel);return;
|
|
584
|
+
}
|
|
585
|
+
const figures = doc.createElement('dl');
|
|
345
586
|
for (const key of ['mode', 'vertices', 'triangles', 'art_coverage', 'stray_cleared']) {
|
|
346
|
-
const dt =
|
|
587
|
+
const dt = doc.createElement('dt'), dd = doc.createElement('dd'); dt.textContent = key;
|
|
347
588
|
dd.textContent = Object.hasOwn(item.mesh.figures, key) ? JSON.stringify(item.mesh.figures[key]) : t('not reported');
|
|
348
589
|
dd.dataset.meshFigure = key; figures.append(dt, dd);
|
|
349
590
|
}
|
|
350
591
|
panel.append(figures);
|
|
351
|
-
const help =
|
|
352
|
-
|
|
353
|
-
const entry = state.verdict.get(item.name)!;
|
|
354
|
-
const select = document.createElement('select'); select.setAttribute('aria-label', t('Mesh outcome'));
|
|
355
|
-
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); }
|
|
356
|
-
select.value = entry.mesh!.outcome;
|
|
357
|
-
const note = document.createElement('textarea'); note.maxLength = 10000; note.value = entry.mesh!.note; note.setAttribute('aria-label', t('Mesh note'));
|
|
358
|
-
select.onchange = () => { entry.mesh!.outcome = select.value as Outcome; };
|
|
359
|
-
note.oninput = () => { entry.mesh!.note = note.value; };
|
|
360
|
-
const outcomeLabel = document.createElement('label'), noteLabel = document.createElement('label');
|
|
361
|
-
outcomeLabel.append(t('Mesh outcome'), select); noteLabel.append(t('Mesh note'), note);
|
|
362
|
-
panel.append(outcomeLabel, noteLabel); document.querySelector('.pv-verdict')!.before(panel);
|
|
592
|
+
const help = doc.createElement('p'); help.textContent = t('Pink: art pixels outside every triangle.'); panel.append(help);
|
|
593
|
+
slots.side.append(panel);
|
|
363
594
|
}
|
|
364
595
|
|
|
365
596
|
function select(index: number): void {
|
|
366
|
-
|
|
597
|
+
if (disposed) return;
|
|
598
|
+
hoverName = null;highlightedParts.clear();
|
|
599
|
+
queueMicrotask(() => { if (!disposed) renderCorrections(); });
|
|
367
600
|
const data = state.data!;
|
|
368
601
|
const item = data.items[index]!;
|
|
369
602
|
if (item.page !== undefined) state.page = data.pages.findIndex(p => p.name === item.page);
|
|
370
603
|
const changed=state.selected!==index;state.selected = index;if((changed||paintFailure)&&viewport&&state.view!=='assembled'){viewport.writeCamera('rig',{zoom:1,center:null});viewport.writeCamera('reference',{zoom:1,center:null});}
|
|
371
604
|
commentUi?.refresh();
|
|
372
|
-
renderList(); renderFlags();
|
|
605
|
+
renderList(); renderFlags(); renderMesh(); renderComparison(); void paint();
|
|
373
606
|
}
|
|
374
607
|
|
|
375
608
|
function setView(view: 'item' | 'page' | 'assembled'): void {
|
|
376
609
|
if(view==='assembled'&&(state.data?.mode!=='parts'||!state.data.rigSize))return;
|
|
377
610
|
if((state.view!==view||paintFailure)&&viewport){viewport.writeCamera('rig',{zoom:1,center:null});viewport.writeCamera('reference',{zoom:1,center:null});}
|
|
378
611
|
if(view!=='item'&&state.comparison.mode==='difference')state.comparison={mode:'part',opacity:state.comparison.opacity};
|
|
379
|
-
|
|
380
|
-
|
|
612
|
+
hoverName = null;
|
|
613
|
+
state.view = view;$('pv-assemble').setAttribute('aria-pressed', String(view === 'assembled'));renderMesh();renderComparison();$('rig-label').textContent=t(view==='assembled'?'Assembled':'Selected part');commentUi?.refresh();
|
|
614
|
+
for (const b of queryAll<HTMLButtonElement>('[data-pv-view]')) b.setAttribute('aria-pressed', String(b.dataset.pvView === view));
|
|
381
615
|
void paint();
|
|
382
616
|
}
|
|
383
617
|
|
|
384
|
-
function
|
|
385
|
-
const
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
/** Explicit approval only: refuse before changing any pending entry when a flag remains. */
|
|
392
|
-
async function approveAll(): Promise<void> {
|
|
393
|
-
if (stageEmbedded || !state.data) return;
|
|
394
|
-
const entries = state.data.items.map(item => state.verdict.get(item.name));
|
|
395
|
-
if (entries.some(entry => entry?.outcome === 'flagged' || entry?.mesh?.outcome === 'flagged')) {
|
|
396
|
-
const status = $('pv-save-status');
|
|
397
|
-
status.textContent = t('PARTS_APPROVE_ALL_FLAGGED: resolve flagged part and mesh outcomes before approving all.');
|
|
398
|
-
status.dataset.result = 'refused';
|
|
618
|
+
function renderLegacyVerdict(): void {
|
|
619
|
+
const legacy = state.data?.legacyVerdict;
|
|
620
|
+
const list = query('#pv-legacy-flagged') as HTMLElement | null;
|
|
621
|
+
if (!list) return;
|
|
622
|
+
if (!legacy) {
|
|
623
|
+
list.hidden = true;
|
|
624
|
+
list.replaceChildren();
|
|
399
625
|
return;
|
|
400
626
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
state.verdict.set(item.name, entry);
|
|
409
|
-
}
|
|
410
|
-
$<HTMLSelectElement>('pv-overall').value = 'approved';
|
|
411
|
-
renderList(); renderVerdict(); renderMesh();
|
|
412
|
-
await save();
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
async function save(): Promise<void> {
|
|
416
|
-
const data=state.data;
|
|
417
|
-
if(!data||stageEmbedded&&(!data.joinedVerdictBinding||!access.capability||stageBuild!=='inspected'))return;
|
|
418
|
-
const status = $('pv-save-status'),button=$<HTMLButtonElement>('pv-save');
|
|
419
|
-
const body = { status: $<HTMLSelectElement>('pv-overall').value, parts: Object.fromEntries(state.verdict),
|
|
420
|
-
...(stageEmbedded?{binding:data.joinedVerdictBinding}:{comments}) };
|
|
421
|
-
button.disabled=true;
|
|
422
|
-
try{
|
|
423
|
-
const headers=stageEmbedded?stageHeaders():access.headers();headers.set('Content-Type','application/json');
|
|
424
|
-
const res = await fetch(access.route(stageEmbedded?partsApi+'/verdict':'/api/parts/verdict'), { method: 'POST', headers, body: JSON.stringify(body) });
|
|
425
|
-
const out = await res.json() as { error?: string; verdict?: { source: { sha256: string } } };
|
|
426
|
-
status.textContent = res.ok ? t('Saved {file}: source {hash}.', { file: data.verdictFile, hash: out.verdict!.source.sha256.slice(0, 12) }) : out.error ? t(out.error) : t('Save failed.');
|
|
427
|
-
status.dataset.result = res.ok ? 'saved' : 'refused';
|
|
428
|
-
}catch{
|
|
429
|
-
status.textContent=t('Save failed.');status.dataset.result='refused';
|
|
430
|
-
}finally{button.disabled=false;}
|
|
627
|
+
list.hidden = !legacy.flaggedParts.length;
|
|
628
|
+
list.replaceChildren(...legacy.flaggedParts.map(fp => {
|
|
629
|
+
const li = doc.createElement('li');
|
|
630
|
+
li.dataset.legacyFlaggedPart = fp.name;
|
|
631
|
+
li.textContent = fp.note ? fp.name + ': ' + fp.note : fp.name;
|
|
632
|
+
return li;
|
|
633
|
+
}));
|
|
431
634
|
}
|
|
432
635
|
|
|
433
636
|
async function boot(): Promise<void> {
|
|
434
|
-
const box=$('pv-canvas-box'),layout=$('stage-layout');mountViewportPair(layout);$('rig-root').append(box);const reference=
|
|
435
|
-
viewport=createPartsViewport({el:$,canvas:$<HTMLCanvasElement>('pv-canvas'),message:(msg)=>{
|
|
637
|
+
const box=$('pv-canvas-box'),layout=$('stage-layout');mountViewportPair(layout);$('rig-root').append(box);const reference=doc.createElement('canvas');reference.id='pv-reference';$('reference-content').append(reference);$('rig-empty').hidden=true;$('rig-overlay').hidden=true;$('rig-label').textContent=t('Selected part');$('rig-viewport').tabIndex=0;
|
|
638
|
+
viewport=createPartsViewport({el:$,canvas:$<HTMLCanvasElement>('pv-canvas'),message:(msg)=>{paintBusyStatus=null;$('pv-save-status').textContent=t(msg);},reference:()=>state.data?.painting?$<HTMLCanvasElement>('pv-reference'):null,
|
|
436
639
|
frameSize:target=>{
|
|
437
640
|
const data=state.data,item=data?.items[state.selected];
|
|
438
641
|
if(!data||!item||paintReset)return null;
|
|
439
642
|
if(paintFailure)return {w:0,h:0};
|
|
440
643
|
return target==='rig'?rasterFrame(data,item)??{w:0,h:0}:data.painting?partFrame(data,item):null;
|
|
441
644
|
},
|
|
442
|
-
});viewport.bindControls();
|
|
645
|
+
});disposers.push(viewport.bindControls());
|
|
443
646
|
$('native-one').onclick=()=>viewport!.cameraAction(()=>viewport!.updateCamera(viewport!.availableCamera()??'rig',{zoom:1,pan:{x:0,y:0}}));
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
if(stageEmbedded)await sourceReady;
|
|
457
|
-
const res = await fetch(access.route(partsApi), { headers: stageHeaders() });
|
|
458
|
-
const data = await res.json() as ViewData & { error?: string };
|
|
459
|
-
if (!res.ok) { const status=$('pv-load');status.textContent=t(data.error??'Load failed.');status.dataset.result='refused';return; }
|
|
460
|
-
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()&&!paintFailure);viewport.observeResize();
|
|
461
|
-
if(stageEmbedded&&data.joinedVerdictBinding){
|
|
462
|
-
document.querySelector<HTMLElement>('.pv-verdict')!.hidden=false;
|
|
463
|
-
$('pv-approve-all').hidden=true;
|
|
464
|
-
$('pv-comment-count').hidden=true;
|
|
465
|
-
const save=$<HTMLButtonElement>('pv-save');
|
|
466
|
-
save.disabled=!access.capability;
|
|
467
|
-
if(!access.capability)save.title=t('Read-only view: reopen with rig-review open to edit.');
|
|
647
|
+
if (disposed) return;
|
|
648
|
+
let data: ViewData & { error?: string };
|
|
649
|
+
try {
|
|
650
|
+
data = await source.view();
|
|
651
|
+
} catch (err) {
|
|
652
|
+
if (disposed) return;
|
|
653
|
+
const status = $('pv-load');
|
|
654
|
+
status.textContent = t(err instanceof Error ? err.message : 'Save failed.');
|
|
655
|
+
status.dataset.result = 'refused';
|
|
656
|
+
painting=false;paintFailure=err instanceof Error?err.message:String(err);syncPaintState();
|
|
657
|
+
settleReady(err);
|
|
658
|
+
return;
|
|
468
659
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
if (data.
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
660
|
+
if (disposed) return;
|
|
661
|
+
if (data.error) { const status=$('pv-load');status.textContent=t(data.error);status.dataset.result='refused';painting=false;paintFailure=data.error;syncPaintState();settleReady(new Error(data.error));return; }
|
|
662
|
+
if (!data.items.length) throw new Error('PARTS_PAINT_FAILED');
|
|
663
|
+
state.data = data;state.meshVisible=stageEmbedded||!data.items.some(item=>item.mesh);$<HTMLSelectElement>('pv-bg').value=state.bg;$('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;
|
|
664
|
+
if (data.mode !== 'parts' || !data.rigSize) state.view = 'item';
|
|
665
|
+
comments.push(...structuredClone(host.initial()).map(issue => parsePartsIssue(issue, false, true, false)));
|
|
666
|
+
host.register({kind: 'parts-verdict', value: () => {
|
|
667
|
+
if (disposed || state.data?.legacyVerdict?.readOnly) throw new Error('PARTS_VERDICT_READ_ONLY');
|
|
668
|
+
return {verdict: comments.length ? 'changes-requested' : 'approved', issues: structuredClone(comments), words: ''};
|
|
669
|
+
}});
|
|
670
|
+
setupPartsComments();const ro=viewport.observeResize();disposers.push(viewport.bindNavigation(undefined,()=>mountActive&&!disposed&&!commentUi?.active()&&!paintFailure),()=>ro.disconnect());
|
|
671
|
+
renderLegacyVerdict();
|
|
672
|
+
const legacyBanner = data.legacyVerdict ? data.legacyVerdict.code + ': ' + t('parts.legacyVerdictBanner', [data.legacyVerdict.flaggedCount]) : '';
|
|
475
673
|
$('pv-list-title').textContent = data.mode === 'parts' ? t('PARTS') : t('REGIONS');
|
|
476
|
-
$('pv-load').textContent = data.verdictStale === 'files' ? t('A saved sign-off was made on other files; this review starts fresh.') : data.verdictStale === 'flags' ? t('The saved sign-off is for different producer flags; this review starts fresh.') : data.verdict ? t('Saved sign-off loaded.') : data.verdictReadOnlyReason?t(data.verdictReadOnlyReason):'';
|
|
477
|
-
if(
|
|
674
|
+
$('pv-load').textContent = data.verdictStale === 'files' ? t('A saved sign-off was made on other files; this review starts fresh.') : data.verdictStale === 'flags' ? t('The saved sign-off is for different producer flags; this review starts fresh.') : legacyBanner ? legacyBanner : data.verdict ? t('Saved sign-off loaded.') : data.verdictReadOnlyReason?t(data.verdictReadOnlyReason):'';
|
|
675
|
+
if (legacyBanner) $('pv-load').dataset.result = 'readonly';
|
|
478
676
|
$('pv-atlas-switch').hidden = data.mode !== 'atlas';
|
|
479
677
|
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.'):'';
|
|
480
678
|
assemble.onclick=()=>{setView(state.view==='assembled'?'item':'assembled');assemble.setAttribute('aria-pressed',String(state.view==='assembled'));};
|
|
481
679
|
bindAssemblyPicking();
|
|
482
|
-
for(const button of
|
|
680
|
+
for(const button of queryAll<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;renderMesh();}renderComparison();void paint();};
|
|
483
681
|
$<HTMLInputElement>('pv-opacity').oninput=e=>{state.comparison.opacity=Number((e.target as HTMLInputElement).value);renderComparison();void paint();};
|
|
484
682
|
$<HTMLInputElement>('pv-threshold').oninput=e=>{
|
|
485
683
|
const input=e.target as HTMLInputElement,threshold=input.valueAsNumber,status=$('pv-save-status');
|
|
@@ -500,105 +698,284 @@ async function boot(): Promise<void> {
|
|
|
500
698
|
$<HTMLInputElement>('pv-alpha').onchange = e => { state.alpha = (e.target as HTMLInputElement).checked; void paint(); };
|
|
501
699
|
footprints.onchange = e => { state.footprints = (e.target as HTMLInputElement).checked; void paint(); };
|
|
502
700
|
|
|
503
|
-
for (const b of
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
701
|
+
for (const b of queryAll<HTMLButtonElement>('[data-pv-view]')) b.onclick = () => setView(b.dataset.pvView as 'item' | 'page');
|
|
702
|
+
const offLang = onLanguageChange(() => { if (!disposed && state.data) { localizeWorkspace(); select(state.selected); } });
|
|
703
|
+
disposers.push(offLang);
|
|
704
|
+
if(data.items.length){
|
|
705
|
+
const index = pendingSelectPart ? data.items.findIndex(item => item.name === pendingSelectPart) : 0;
|
|
706
|
+
select(index >= 0 ? index : 0);
|
|
707
|
+
$('rig-label').textContent = t(state.view === 'assembled' ? 'Assembled' : 'Selected part');
|
|
708
|
+
assemble.setAttribute('aria-pressed', String(state.view === 'assembled'));
|
|
709
|
+
}
|
|
710
|
+
localizeWorkspace();
|
|
512
711
|
renderCorrections();
|
|
513
|
-
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
function localizeWorkspace(): void {
|
|
715
|
+
applyDomI18n(slots.toolbar);
|
|
716
|
+
$('reference-pane').setAttribute('aria-label', t('Reference'));
|
|
717
|
+
$('rig-pane').setAttribute('aria-label', t('Rig'));
|
|
718
|
+
$('reference-label').textContent = t('Reference');
|
|
719
|
+
$('rig-label').textContent = t(state.view === 'assembled' ? 'Assembled' : 'Selected part');
|
|
720
|
+
$('pv-list-title').textContent = t(state.data?.mode === 'atlas' ? 'REGIONS' : 'PARTS');
|
|
721
|
+
$('pv-flags-title').textContent = t('PRODUCER FLAGS');
|
|
722
|
+
viewport?.renderCameraControls();
|
|
514
723
|
}
|
|
515
724
|
|
|
516
725
|
/** Observe taps only; the shared controller exclusively owns pan, zoom and pinch. */
|
|
726
|
+
function assemblyLayers() {
|
|
727
|
+
return state.data!.items.flatMap(box => {
|
|
728
|
+
const image = images.get(`image:${box.index}`);
|
|
729
|
+
return image && !state.hidden.has(box.name) ? [{box, image, alpha: sourceAlpha(box, image)}] : [];
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
|
|
517
733
|
function bindAssemblyPicking():void {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
const
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
734
|
+
const pane = $('rig-viewport');
|
|
735
|
+
let tap: {id: number; x: number; y: number} | null = null;
|
|
736
|
+
const pointers = new Set<number>();
|
|
737
|
+
const available = () => !disposed && state.view === 'assembled' && !painting && !paintFailure && !paintingHeld && !commentUi?.active();
|
|
738
|
+
const hitAt = (event: MouseEvent) => {
|
|
739
|
+
const bounds = $('pv-canvas').getBoundingClientRect(), zoom = viewport!.paneCamera('rig').zoom;
|
|
740
|
+
return pickAssembly(assemblyLayers(), (event.clientX - bounds.left) / zoom, (event.clientY - bounds.top) / zoom);
|
|
741
|
+
};
|
|
742
|
+
const clearHover = () => {
|
|
743
|
+
if (!hoverName) return;
|
|
744
|
+
hoverName = null;
|
|
745
|
+
if (!disposed && state.view === 'assembled' && !painting && !paintFailure) renderAssemblySelection(assemblyLayers());
|
|
746
|
+
};
|
|
747
|
+
const onDown = (event: PointerEvent) => {
|
|
748
|
+
if ((event.target as Element)?.closest?.('.stage-comment-ui,button,input')) {tap = null;return;}
|
|
749
|
+
pointers.add(event.pointerId);
|
|
750
|
+
tap = pointers.size === 1 && event.button === 0 ? {id: event.pointerId, x: event.clientX, y: event.clientY} : null;
|
|
751
|
+
clearHover();
|
|
752
|
+
};
|
|
753
|
+
const onMove = (event: PointerEvent) => {
|
|
754
|
+
if (tap && Math.hypot(event.clientX - tap.x, event.clientY - tap.y) > 4) tap = null;
|
|
755
|
+
if (!available() || pointers.size || event.buttons) {clearHover();return;}
|
|
756
|
+
const name = hitAt(event)?.name ?? null;
|
|
757
|
+
if (name !== hoverName) {hoverName = name;renderAssemblySelection(assemblyLayers());}
|
|
758
|
+
};
|
|
759
|
+
const onCancel = (event: PointerEvent) => {pointers.delete(event.pointerId);tap = null;clearHover();};
|
|
760
|
+
const onUp = (event: PointerEvent) => {
|
|
761
|
+
pointers.delete(event.pointerId);const start = tap;tap = null;
|
|
762
|
+
if (!start || start.id !== event.pointerId || Math.hypot(event.clientX - start.x, event.clientY - start.y) > 4 || !available()) return;
|
|
763
|
+
const hit = hitAt(event);if (hit) select(hit.index);
|
|
764
|
+
};
|
|
765
|
+
const onDoubleClick = (event: MouseEvent) => {
|
|
766
|
+
if (disposed || state.view !== 'assembled' || paintFailure || paintingHeld || commentUi?.active()) return;
|
|
767
|
+
if ((event.target as Element)?.closest?.('.stage-comment-ui,button,input')) return;
|
|
768
|
+
const hit = hitAt(event);if (hit) {select(hit.index);setView('item');}
|
|
769
|
+
};
|
|
770
|
+
const releasePainting = () => {
|
|
771
|
+
if (!paintingHeld) return;
|
|
772
|
+
paintingHeld = false;
|
|
773
|
+
if (!disposed) void paint();
|
|
774
|
+
};
|
|
775
|
+
const keyDown = (event: KeyboardEvent) => {
|
|
776
|
+
if (mountActive && commentUi?.active()) clearHover();
|
|
777
|
+
if (!mountActive || disposed || event.defaultPrevented || event.repeat || event.ctrlKey || event.metaKey || event.altKey || textEntryFocused(event.target)) return;
|
|
778
|
+
if (event.key === 'Escape' && state.view === 'item' && !commentUi?.active() && !commentUi?.draft()) {
|
|
779
|
+
event.preventDefault();setView('assembled');
|
|
780
|
+
}
|
|
781
|
+
if (event.key.toLowerCase() === 'p' && state.data?.mode === 'parts' && state.data.painting && !painting && !paintFailure && !commentUi?.draft()) {
|
|
782
|
+
event.preventDefault();paintingHeld = true;hoverName = null;void paint();
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
const keyUp = (event: KeyboardEvent) => {if (event.key.toLowerCase() === 'p') releasePainting();};
|
|
786
|
+
const deactivate = () => {if (!mountActive) releasePainting();};
|
|
787
|
+
const onVisibilityChange = () => {
|
|
788
|
+
if (doc.visibilityState === 'hidden') releasePainting();
|
|
789
|
+
};
|
|
790
|
+
const bindings: [EventTarget, string, EventListener][] = [
|
|
791
|
+
[pane, 'pointerdown', onDown as EventListener], [pane, 'pointermove', onMove as EventListener],
|
|
792
|
+
[pane, 'pointercancel', onCancel as EventListener], [pane, 'pointerup', onUp as EventListener],
|
|
793
|
+
[pane, 'pointerleave', clearHover], [pane, 'dblclick', onDoubleClick as EventListener],
|
|
794
|
+
[doc, 'keydown', keyDown as EventListener], [doc, 'keyup', keyUp as EventListener],
|
|
795
|
+
[doc, 'focusin', deactivate], [doc, 'pointerdown', deactivate], [eventWindow, 'blur', releasePainting],
|
|
796
|
+
[doc, 'visibilitychange', onVisibilityChange],
|
|
797
|
+
];
|
|
798
|
+
for (const [target, type, handler] of bindings) target.addEventListener(type, handler);
|
|
799
|
+
disposers.push(() => {for (const [target, type, handler] of bindings) target.removeEventListener(type, handler);});
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
interface PartsPose extends CommentUiPose {item:Item;sourceHash:string;view:PartsIssue['view']}
|
|
803
|
+
function issueParts(names: string[]): PartsIssue['parts'] {
|
|
804
|
+
return names.map(name => {
|
|
805
|
+
const item = state.data?.items.find(item => item.name === name);
|
|
806
|
+
if (!item?.imageHash) throw new Error('PARTS_COMMENT_PART_MISMATCH: comment belongs to another part');
|
|
807
|
+
return {name, imageHash: item.imageHash};
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
async function prepareIssue(issue: PartsIssue): Promise<PartsIssue> {
|
|
812
|
+
const data = state.data!;
|
|
813
|
+
const bound = parsePartsIssue(issue, false, false, false);
|
|
814
|
+
const items = new Map(data.items.map(item => [item.name, {...item, imageHash: item.imageHash!}]));
|
|
815
|
+
assertPartsIssueBinding(bound, items, data.sourceHash);
|
|
816
|
+
const prepared = await source.crop(bound);
|
|
817
|
+
if (disposed || state.data !== data) throw new Error('PARTS_COMMENT_STALE_SOURCE');
|
|
818
|
+
return parsePartsIssue(prepared, true, false, false);
|
|
819
|
+
}
|
|
820
|
+
|
|
532
821
|
function setupPartsComments():void {
|
|
533
|
-
const codec:CommentCodec<
|
|
534
|
-
read:
|
|
535
|
-
signature:p=>[p.item.name,p.item.imageHash,p.sourceHash,p.camera,p.view],
|
|
536
|
-
matches:(_mark,p,c)
|
|
537
|
-
label:c
|
|
538
|
-
|
|
822
|
+
const codec:CommentCodec<PartsIssue,PartsPose>={
|
|
823
|
+
read:raw=>{try{const c=parsePartsIssue(raw,false,true,false);const camera={space:'image' as const,center:c.view.camera.center,zoom:c.view.camera.zoom,viewport:c.view.camera.viewport,visible:{x:c.view.camera.center.x-c.view.camera.viewport.width/c.view.camera.zoom/2,y:c.view.camera.center.y-c.view.camera.viewport.height/c.view.camera.zoom/2,width:c.view.camera.viewport.width/c.view.camera.zoom,height:c.view.camera.viewport.height/c.view.camera.zoom}};const r=c.view.mode==='assembled'?c.rigRegion:c.imageRegion!;return {mode:'parts',viewport:'rig',screen:region(projectMark(r,camera),projectMark({x:r.x+r.width,y:r.y+r.height},camera)),world:r,camera,crop:{...c.crop,png:c.crop.png??''},bookmark:{parts:c.parts,sourceHash:c.sourceHash,view:c.view}};}catch{return null;}},
|
|
824
|
+
signature:p=>[p.view.mode,p.item.name,p.item.imageHash,p.sourceHash,p.camera,p.view],
|
|
825
|
+
matches:(_mark,p,raw)=>{try{const c=parsePartsIssue(raw,false,true,false);return p.sourceHash===c.sourceHash&&p.view.mode===c.view.mode&&(c.view.mode==='assembled'?c.parts.every(part=>state.data?.items.some(item=>item.name===part.name&&item.imageHash===part.imageHash)):p.item.name===c.parts[0]?.name&&p.item.imageHash===c.parts[0]?.imageHash);}catch{return false;}},
|
|
826
|
+
label:raw=>{const c=parsePartsIssue(raw,false,true,false);return `${c.parts.map(pt=>pt.name).join(', ')} · ${c.summary}`;},
|
|
827
|
+
chips:(pose,screen,existing)=>{
|
|
828
|
+
const visible = state.data!.items.filter(item => !state.hidden.has(item.name));
|
|
829
|
+
if (existing) return {selected: existing.parts.map(part => part.name), candidates: existing.view.mode === 'assembled' ? visible.map(item => item.name) : []};
|
|
830
|
+
if (pose.view.mode === 'item') return {selected: [pose.item.name], candidates: []};
|
|
831
|
+
const size = state.data!.rigSize!;
|
|
832
|
+
const r = snapImageRegion(region(unprojectMark(screen, pose.camera), unprojectMark({x: screen.x + screen.width, y: screen.y + screen.height}, pose.camera), {x: 0, y: 0, width: size[0], height: size[1]}));
|
|
833
|
+
const hits = new Set<string>(), layers = assemblyLayers();
|
|
834
|
+
const stepX = Math.max(1, r.width / 32), stepY = Math.max(1, r.height / 32);
|
|
835
|
+
for (let y = r.y + .5; y < r.y + r.height; y += stepY) {
|
|
836
|
+
for (let x = r.x + .5; x < r.x + r.width; x += stepX) {
|
|
837
|
+
const hit = pickAssembly(layers, x, y);if (hit) hits.add(hit.name);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
return {selected: visible.filter(item => hits.has(item.name)).map(item => item.name), candidates: visible.map(item => item.name)};
|
|
841
|
+
},
|
|
842
|
+
create:async(p,_view,screen,crop,_bookmark,summary,parts)=>{
|
|
843
|
+
const isItem = p.view.mode === 'item';
|
|
844
|
+
const size = state.data!.rigSize!;
|
|
845
|
+
const bounds = {x: 0, y: 0, width: isItem ? p.item.w : size[0], height: isItem ? p.item.h : size[1]};
|
|
846
|
+
const r = snapImageRegion(region(unprojectMark(screen, p.camera),
|
|
847
|
+
unprojectMark({x: screen.x + screen.width, y: screen.y + screen.height}, p.camera), bounds));
|
|
848
|
+
return prepareIssue({schema:'rig-review-parts-comment/2',id:crypto.randomUUID(),summary,
|
|
849
|
+
parts:issueParts(isItem?[p.item.name]:parts??[]),sourceHash:p.sourceHash,
|
|
850
|
+
imageRegion:isItem?r:null,rigRegion:isItem?{...r,x:p.item.x+r.x,y:p.item.y+r.y}:r,
|
|
851
|
+
view:structuredClone(p.view),crop,nativeCrop:null});
|
|
852
|
+
},
|
|
853
|
+
update:async(existing,summary,parts)=>prepareIssue({...existing,summary,
|
|
854
|
+
parts:existing.view.mode==='assembled'?issueParts(parts??[]):existing.parts}),
|
|
539
855
|
};
|
|
540
|
-
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.
|
|
541
|
-
commentUi=bindStageComments({toolbar:
|
|
542
|
-
|
|
543
|
-
|
|
856
|
+
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'||paintingHeld||(state.view!=='item'&&state.view!=='assembled'))return null;return {mode:'parts',camera,item:{...item},sourceHash:data.sourceHash,view:{mode:state.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.meshVisible,comparison:{...state.comparison}},capture:{pane:$('rig-viewport'),root:$('rig-root'),images:true,canvas:$<HTMLCanvasElement>('pv-canvas'),backend:'canvas2d',nearest:true}};};
|
|
857
|
+
commentUi=bindStageComments({toolbar:slots.toolbar,listHost:slots.side,toggle:$<HTMLButtonElement>('stage-comment'),viewports:{rig:$('rig-viewport')},pose,pause:async()=>{},bookmark:()=>null,
|
|
858
|
+
restore:async(raw)=>{
|
|
859
|
+
const data = state.data!, navigation = paintToken, current = await source.view();
|
|
860
|
+
if (disposed) return;
|
|
861
|
+
if (navigation !== paintToken) throw new Error('COMMENT_BUSY: wait for inspection');
|
|
862
|
+
if (state.data !== data || current.sourceHash !== data.sourceHash) throw new Error('PARTS_COMMENT_STALE_SOURCE');
|
|
863
|
+
const bookmark = raw as {parts:PartsIssue['parts'];sourceHash:string;view:PartsIssue['view']};
|
|
864
|
+
const matched = bookmark.parts.map(part => data.items.find(item => item.name === part.name && item.imageHash === part.imageHash));
|
|
865
|
+
if (!matched.length || matched.some(item => !item) || data.sourceHash !== bookmark.sourceHash) throw new Error('PARTS_COMMENT_STALE_SOURCE: reopen the bound source');
|
|
866
|
+
setView(bookmark.view.mode);select(matched[0]!.index);
|
|
867
|
+
highlightedParts.clear();for (const part of bookmark.parts) {highlightedParts.add(part.name);state.hidden.delete(part.name);}
|
|
868
|
+
state.bg = bookmark.view.background;state.alpha = bookmark.view.alpha;state.footprints = bookmark.view.footprints;
|
|
869
|
+
state.comparison = {...(bookmark.view.comparison ?? defaultPartsComparison())};
|
|
870
|
+
if (state.comparison.mode === 'difference') state.differenceThreshold = state.comparison.threshold;
|
|
871
|
+
state.meshVisible = bookmark.view.mesh;
|
|
872
|
+
$<HTMLSelectElement>('pv-bg').value=state.bg;$<HTMLInputElement>('pv-alpha').checked=state.alpha;$<HTMLInputElement>('pv-footprints').checked=state.footprints;
|
|
873
|
+
renderList();renderMesh();renderComparison();viewport!.state.cameraRestoring = true;
|
|
874
|
+
const painted = paint(), token = paintToken;
|
|
875
|
+
try {
|
|
876
|
+
await painted;
|
|
877
|
+
if (disposed || token !== paintToken || paintFailure) return;
|
|
878
|
+
viewport!.writeCamera('rig', bookmark.view.camera);
|
|
879
|
+
if (bookmark.view.referenceCamera) viewport!.writeCamera('reference', bookmark.view.referenceCamera);
|
|
880
|
+
viewport!.state.cameraSync = bookmark.view.cameraSync;viewport!.fitCamera();
|
|
881
|
+
} finally {if (!disposed) viewport!.state.cameraRestoring = false;}
|
|
882
|
+
},
|
|
883
|
+
feedback:()=>comments,locked:()=>Boolean(state.data?.legacyVerdict?.readOnly)||host.locked() !== 'open',add:c=>comments.push(c),changed:()=>{renderList();host.changed(structuredClone(comments));},error:m=>{paintBusyStatus=null;$('pv-save-status').textContent=t(m);},blocked:()=>painting||paintingHeld,busy:()=>painting||paintingHeld,busyError:message=>{paintBusyStatus={token:paintToken,text:t(message)};$('pv-save-status').textContent=paintBusyStatus.text;},shortcutActive:()=>mountActive&&!disposed,refusal:()=>paintFailure??(state.data?.legacyVerdict?.readOnly?state.data.legacyVerdict.code+': '+t('parts.legacyVerdictBanner',[state.data.legacyVerdict.flaggedCount]):null)??(host.locked() !== 'open'?'Read-only view: reopen with rig-review open to edit.':null)??(stageEmbedded&&state.data?.mode==='parts'?'PARTS_JOINED_ISSUE_UNSUPPORTED':null)??(state.data?.mode!=='parts'?'PARTS_COMMENT_UNAVAILABLE: original part image required':null),codec});
|
|
544
884
|
}
|
|
545
885
|
|
|
546
|
-
if (typeof document !== 'undefined' && document.getElementById('parts-app')) void boot();
|
|
547
|
-
|
|
548
886
|
function renderCorrections():void {
|
|
549
887
|
const data = state.data;
|
|
550
888
|
if (!stageEmbedded && (!data || (!Object.hasOwn(data, 'draft') && !Object.hasOwn(data, 'draftUnavailable')))) {
|
|
551
|
-
|
|
889
|
+
query('#pv-corrections')?.remove();
|
|
552
890
|
return;
|
|
553
891
|
}
|
|
554
|
-
let host=
|
|
892
|
+
let host=query('#pv-corrections');if(!host){host=doc.createElement('section');host.id='pv-corrections';slots.stage.append(host);}
|
|
555
893
|
host.replaceChildren();const item=data?.items[state.selected],mapping=data?.draft?.mappings.find(m=>m.part===item?.name);
|
|
556
|
-
const label=
|
|
894
|
+
const label=doc.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);
|
|
557
895
|
if(!mapping||!data?.draft)return;
|
|
558
896
|
label.textContent+=` · ${mapping.part} · ${mapping.skin}/${mapping.slot}/${mapping.attachment} · v ${mapping.vertices} t ${mapping.triangles} · ${data.draft.buildId}`;
|
|
559
897
|
if(data.draft.inspectionOnly)return;
|
|
560
898
|
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')]]){
|
|
561
|
-
const button=
|
|
899
|
+
const button=doc.createElement('button');button.type='button';button.textContent=t(title!);button.title=`${mapping.part} · ${operation}`;button.onclick=()=>slots.stage.dispatchEvent(new CustomEvent('parts-correction',{detail:{type:'review-stage-correction',part:mapping.part,sourceHash:data.sourceHash,buildId:data.draft!.buildId,instrument}}));host.append(button);
|
|
562
900
|
}
|
|
563
|
-
const guidance=
|
|
901
|
+
const guidance=doc.createElement('p');guidance.textContent=t('Use Write review, choose Parts review and name the Create draft. Export the saved item with the feedback CLI. Mesh deltas retain evidence as unsupported operations.');host.append(guidance);
|
|
564
902
|
}
|
|
565
903
|
|
|
566
904
|
function stagePartsSnapshot():StagePartsState|null {
|
|
567
905
|
const data=state.data,item=data?.items[state.selected],mapping=data?.draft?.mappings.find(m=>m.part===item?.name);
|
|
568
906
|
if(!data?.inspectionSourceHash||!item?.imageHash||!mapping||!viewport)return null;
|
|
569
|
-
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.
|
|
907
|
+
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.meshVisible};
|
|
570
908
|
}
|
|
571
909
|
async function restoreStageParts(saved:StagePartsState):Promise<void>{
|
|
572
|
-
if(
|
|
910
|
+
if(disposed||!state.data||!viewport)return;
|
|
573
911
|
try{
|
|
574
912
|
const index=stagePartsSelectionIndex(state.data,saved);
|
|
575
913
|
viewport.state.cameraRestoring=true;state.bg=saved.bg;state.alpha=saved.alpha;state.footprints=saved.footprints;state.view=saved.view;
|
|
576
|
-
|
|
577
|
-
select(index);await paint();if(!paintFailure){viewport.writeCamera('rig',saved.rig);if(state.data.painting)viewport.writeCamera('reference',saved.reference);viewport.state.cameraSync=saved.cameraSync;viewport.fitCamera();}
|
|
578
|
-
}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.')
|
|
914
|
+
state.meshVisible=saved.mesh;
|
|
915
|
+
select(index);await paint();if(!disposed&&!paintFailure){viewport.writeCamera('rig',saved.rig);if(state.data.painting)viewport.writeCamera('reference',saved.reference);viewport.state.cameraSync=saved.cameraSync;viewport.fitCamera();}
|
|
916
|
+
}catch{if(disposed)return;const status=$('pv-load');status.hidden=false;status.dataset.result='refused';status.textContent=t('STAGE_DRAFT_MISMATCH: separated parts and draft mesh identity differ.');$('stage-layout').hidden=true;}
|
|
579
917
|
finally{viewport.state.cameraRestoring=false;}
|
|
580
918
|
}
|
|
581
|
-
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);});
|
|
582
919
|
|
|
583
|
-
async function revalidateStageParts(
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
920
|
+
async function revalidateStageParts(savedState?: StagePartsState | null): Promise<void> {
|
|
921
|
+
try {
|
|
922
|
+
const data = await source.view();
|
|
923
|
+
if (disposed) return;
|
|
924
|
+
const previous = state.data;
|
|
925
|
+
const sameBuild = data.draft?.buildId === previous?.draft?.buildId;
|
|
926
|
+
const valid = sameBuild ? data.sourceHash === previous?.sourceHash :
|
|
927
|
+
Boolean(data.inspectionSourceHash && data.inspectionSourceHash === previous?.inspectionSourceHash);
|
|
928
|
+
if (!valid) throw new Error('STAGE_DRAFT_MISMATCH: separated parts and draft mesh identity differ.');
|
|
929
|
+
state.data = data;
|
|
930
|
+
imageGeneration++; paintToken++; pendingImages.clear();
|
|
931
|
+
images.clear(); assemblyAlpha.clear();
|
|
932
|
+
if (savedState) await restoreStageParts(savedState);
|
|
933
|
+
else if (data.items.length) { select(Math.min(state.selected, data.items.length - 1)); await paint(); }
|
|
934
|
+
renderCorrections();
|
|
935
|
+
} catch (error) {
|
|
936
|
+
if (disposed) return;
|
|
937
|
+
const status = $('pv-load');
|
|
938
|
+
status.hidden = false; status.dataset.result = 'refused';
|
|
939
|
+
status.textContent = t(error instanceof Error ? error.message : String(error));
|
|
940
|
+
for (const root of roots) if (root !== slots.stage) root.hidden = true;
|
|
941
|
+
$('stage-layout').hidden = true;
|
|
595
942
|
}
|
|
596
|
-
if(savedState)await restoreStageParts(savedState);else if(!sameBuild){select(state.selected);await paint();}
|
|
597
|
-
renderCorrections();
|
|
598
|
-
}catch(error){
|
|
599
|
-
document.querySelector<HTMLElement>('.pv-verdict')!.hidden=true;if(state.data)delete state.data.joinedVerdictBinding;
|
|
600
|
-
const status=$('pv-load');status.hidden=false;status.dataset.result='refused';status.textContent=t(error instanceof Error?error.message:String(error));
|
|
601
|
-
document.querySelector<HTMLElement>('.pv-layout')!.hidden=true;
|
|
602
|
-
}
|
|
603
943
|
}
|
|
604
|
-
|
|
944
|
+
|
|
945
|
+
syncPaintState();
|
|
946
|
+
void boot().catch(error => {if(disposed)return;painting=false;paintFailure=error instanceof Error?error.message:String(error);syncPaintState();settleReady(error);});
|
|
947
|
+
return {
|
|
948
|
+
ready,
|
|
949
|
+
dispose(): void {
|
|
950
|
+
if (disposed) return;
|
|
951
|
+
disposed = true;
|
|
952
|
+
painting=false;syncPaintState();
|
|
953
|
+
settleReady(new Error('PARTS_WORKSPACE_DISPOSED'));
|
|
954
|
+
paintToken++; imageGeneration++;
|
|
955
|
+
commentUi?.dispose();
|
|
956
|
+
commentUi = null;
|
|
957
|
+
for (const dispose of disposers.splice(0)) dispose();
|
|
958
|
+
pendingImages.clear();
|
|
959
|
+
for (const root of roots) root.replaceChildren();
|
|
960
|
+
images.clear();
|
|
961
|
+
assemblyAlpha.clear();
|
|
962
|
+
},
|
|
963
|
+
select(part: string): void {
|
|
964
|
+
pendingSelectPart = part;
|
|
965
|
+
const idx = state.data?.items.findIndex(i => i.name === part) ?? -1;
|
|
966
|
+
if (idx >= 0) select(idx);
|
|
967
|
+
},
|
|
968
|
+
issues(): PartsIssue[] {
|
|
969
|
+
return structuredClone(comments);
|
|
970
|
+
},
|
|
971
|
+
snapshot(): StagePartsState | null {
|
|
972
|
+
return stagePartsSnapshot();
|
|
973
|
+
},
|
|
974
|
+
restore(saved: StagePartsState): Promise<void> {
|
|
975
|
+
return restoreStageParts(saved);
|
|
976
|
+
},
|
|
977
|
+
revalidate(savedState?: StagePartsState | null): Promise<void> {
|
|
978
|
+
return revalidateStageParts(savedState);
|
|
979
|
+
},
|
|
980
|
+
};
|
|
981
|
+
}
|