@rig-c/review 2.8.0 → 2.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/PARTS_VIEW.md +103 -66
- package/docs/REVIEW_PACKAGE.md +143 -9
- package/docs/STABILITY.md +6 -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/job-act.ts +43 -23
- package/src/job-api.ts +23 -9
- package/src/job-checkpoint-evidence.ts +113 -0
- package/src/job-cli.ts +6 -2
- package/src/job-contract.ts +110 -13
- package/src/job-front.ts +123 -9
- package/src/job-host.ts +7 -0
- package/src/job-session.ts +73 -8
- package/src/job-source.ts +52 -7
- 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 +45 -1
- package/web/catalog-ko.ts +45 -1
- package/web/job-session.ts +682 -134
- 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 +649 -267
- package/web/stage-comments.ts +79 -25
- package/web/styles.css +27 -5
- 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,36 @@ 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;
|
|
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;painting=false;
|
|
288
|
+
if(paintBusyStatus?.token===token){
|
|
289
|
+
if($('pv-save-status').textContent===paintBusyStatus.text)$('pv-save-status').textContent='';
|
|
290
|
+
paintBusyStatus=null;
|
|
291
|
+
}
|
|
292
|
+
syncPaintState();viewport?.fitCamera();commentUi?.refresh();settleReady();
|
|
96
293
|
}catch(error){
|
|
97
|
-
if(token!==paintToken)return;
|
|
294
|
+
if(disposed||token!==paintToken)return;
|
|
295
|
+
settleReady(error instanceof Error?error:new Error('PARTS_PAINT_FAILED'));
|
|
98
296
|
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
297
|
const canvas=$<HTMLCanvasElement>('pv-canvas');canvas.getContext('2d')?.clearRect(0,0,canvas.width,canvas.height);
|
|
100
298
|
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 +301,55 @@ async function paint():Promise<void>{
|
|
|
103
301
|
try{viewport?.writeCamera?.('rig',{zoom:1,center:null});viewport?.writeCamera?.('reference',{zoom:1,center:null});viewport?.fitCamera();}
|
|
104
302
|
finally{paintReset=false;paintFailure=failure;}
|
|
105
303
|
commentUi?.refresh();
|
|
106
|
-
}finally{
|
|
304
|
+
}finally{
|
|
305
|
+
if(!disposed&&token===paintToken){
|
|
306
|
+
painting=false;
|
|
307
|
+
if(paintBusyStatus?.token===token){
|
|
308
|
+
if(!paintFailure&&$('pv-save-status').textContent===paintBusyStatus.text)$('pv-save-status').textContent='';
|
|
309
|
+
paintBusyStatus=null;
|
|
310
|
+
}
|
|
311
|
+
syncPaintState();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
107
314
|
}
|
|
108
315
|
const assemblyAlpha=new Map<string,Uint8ClampedArray>();
|
|
109
316
|
function sourceAlpha(item:Item,img:HTMLImageElement):Uint8ClampedArray {
|
|
110
317
|
const cached=assemblyAlpha.get(item.name);if(cached)return cached;
|
|
111
|
-
const c=
|
|
318
|
+
const c=doc.createElement('canvas');c.width=item.w;c.height=item.h;const ctx=c.getContext('2d')!;ctx.drawImage(img,0,0);
|
|
112
319
|
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
320
|
}
|
|
114
321
|
|
|
322
|
+
function drawMeshes(ctx: CanvasRenderingContext2D, layers: {box: Item; image: HTMLImageElement}[], assembled = true): void {
|
|
323
|
+
if (!state.meshVisible) return;
|
|
324
|
+
for (const {box, image} of layers) {
|
|
325
|
+
if (!box.mesh) continue;
|
|
326
|
+
const selected = box.index === state.selected;
|
|
327
|
+
ctx.save();
|
|
328
|
+
if (assembled) ctx.translate(box.x, box.y);
|
|
329
|
+
paintMesh(ctx, image, box.w, box.h, box.mesh,
|
|
330
|
+
(w, h) => Object.assign(doc.createElement('canvas'), {width: w, height: h}),
|
|
331
|
+
{tint: selected, alpha: selected ? 1 : .35});
|
|
332
|
+
ctx.restore();
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function renderAssemblySelection(layers: {box: Item; image: HTMLImageElement}[]): void {
|
|
337
|
+
const overlay = $('pv-overlay'), canvas = $<HTMLCanvasElement>('pv-canvas');
|
|
338
|
+
overlay.replaceChildren();
|
|
339
|
+
if (paintingHeld) return;
|
|
340
|
+
const names = new Set([state.data!.items[state.selected]!.name, ...highlightedParts, hoverName]);
|
|
341
|
+
for (const {box, image} of layers) {
|
|
342
|
+
if (!names.has(box.name)) continue;
|
|
343
|
+
const outline = doc.createElement('canvas');
|
|
344
|
+
outline.width = canvas.width;outline.height = canvas.height;outline.dataset.assemblyOutline = box.name;
|
|
345
|
+
paintAssemblyOutline(outline.getContext('2d')!, box, sourceAlpha(box, image));overlay.append(outline);
|
|
346
|
+
if (box.name !== hoverName) continue;
|
|
347
|
+
const label = overlayBox(box.x, box.y, box.w, box.h), text = doc.createElement('span');
|
|
348
|
+
label.style.pointerEvents = 'none';label.dataset.assemblyHover = box.name;text.textContent = box.name;
|
|
349
|
+
label.append(text);overlay.append(label);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
115
353
|
function partFrame(data:ViewData,item:Item) {
|
|
116
354
|
if(state.view==='assembled'&&data.rigSize) {
|
|
117
355
|
return {x:0,y:0,w:data.rigSize[0],h:data.rigSize[1]};
|
|
@@ -144,22 +382,23 @@ async function paintRaster(token:number): Promise<void> {
|
|
|
144
382
|
if(state.view==='assembled'&&data.mode==='parts'&&data.rigSize){
|
|
145
383
|
const shown=data.items.filter(i=>!state.hidden.has(i.name));
|
|
146
384
|
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;
|
|
385
|
+
const original=(paintingHeld||state.comparison.mode==='overlay')&&data.painting?await paintingImage():null;
|
|
386
|
+
if(disposed||token!==paintToken)return;
|
|
149
387
|
const ctx=setCanvas(canvas,w,h);
|
|
150
388
|
if(original){
|
|
151
389
|
paintPaintingCrop(ctx,original,paintingRectangle({x:0,y:0,w,h},data.rigSize,data.painting!),w,h,state.bg);
|
|
152
|
-
const assembled=
|
|
390
|
+
const assembled=doc.createElement('canvas');assembled.width=w;assembled.height=h;
|
|
391
|
+
paintAssembly(assembled.getContext('2d')!,w,h,layers,{bg:state.bg,alpha:false,transparent:true});
|
|
392
|
+
ctx.globalAlpha=paintingHeld?0:state.comparison.opacity;ctx.drawImage(assembled,0,0);ctx.globalAlpha=1;
|
|
153
393
|
}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});
|
|
394
|
+
if (!paintingHeld) drawMeshes(ctx, layers);
|
|
395
|
+
renderAssemblySelection(layers);
|
|
396
|
+
caption.textContent=t('Assembled package · {count} visible parts.',{count:shown.length});
|
|
158
397
|
return;
|
|
159
398
|
}
|
|
160
399
|
if (data.mode === 'atlas' && state.view === 'page') {
|
|
161
400
|
const page = data.pages[state.page]!, img = await pageImage(page.name);
|
|
162
|
-
if (token !== paintToken) return;
|
|
401
|
+
if (disposed || token !== paintToken) return;
|
|
163
402
|
const ctx = setCanvas(canvas, w, h);
|
|
164
403
|
if (state.alpha) paintAlphaOnly(ctx, img, 0, 0, page.width, page.height);
|
|
165
404
|
else { paintBackground(ctx, page.width, page.height, state.bg); ctx.drawImage(img, 0, 0); }
|
|
@@ -168,7 +407,7 @@ async function paintRaster(token:number): Promise<void> {
|
|
|
168
407
|
box.dataset.viewportAction = 'select-region';
|
|
169
408
|
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
409
|
if (r.index === item.index) box.setAttribute('aria-current', 'true');
|
|
171
|
-
const label =
|
|
410
|
+
const label = doc.createElement('span'); label.textContent = r.name; box.append(label);
|
|
172
411
|
box.title = `${r.name} · ${r.x},${r.y} ${r.w}×${r.h}${r.degrees ? ` · ${r.degrees}°` : ''}`;
|
|
173
412
|
box.onclick = () => { select(r.index); setView('item'); };
|
|
174
413
|
return box;
|
|
@@ -181,7 +420,7 @@ async function paintRaster(token:number): Promise<void> {
|
|
|
181
420
|
}
|
|
182
421
|
if (data.mode === 'atlas') {
|
|
183
422
|
const page = data.pages.find(p => p.name === item.page)!, img = await pageImage(item.page!);
|
|
184
|
-
if (token !== paintToken) return;
|
|
423
|
+
if (disposed || token !== paintToken) return;
|
|
185
424
|
const ctx = setCanvas(canvas, w, h);
|
|
186
425
|
if (state.alpha) paintAlphaOnly(ctx, img, x, y, w, h);
|
|
187
426
|
else { paintBackground(ctx, w, h, state.bg); ctx.drawImage(img, x, y, w, h, 0, 0, w, h); }
|
|
@@ -191,23 +430,33 @@ async function paintRaster(token:number): Promise<void> {
|
|
|
191
430
|
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
431
|
return;
|
|
193
432
|
}
|
|
433
|
+
if (paintingHeld && data.painting) {
|
|
434
|
+
const original = await paintingImage();
|
|
435
|
+
if (disposed || token !== paintToken) return;
|
|
436
|
+
const ctx = setCanvas(canvas, w, h);
|
|
437
|
+
paintPaintingCrop(ctx, original, paintingRectangle(item, data.rigSize!, data.painting), w, h, state.bg);
|
|
438
|
+
overlay.replaceChildren();
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
194
441
|
if(state.comparison.mode==='difference'){
|
|
195
|
-
|
|
442
|
+
if (!source.difference) throw new Error('PARTS_DIFFERENCE_UNAVAILABLE: declared painting_in_rig and individual part view required.');
|
|
443
|
+
const response = await source.difference(item.index, state.comparison.threshold, state.footprints);
|
|
196
444
|
if(!response.ok){const out=await response.json() as {error:string};throw new Error(out.error);}
|
|
445
|
+
const meshImage=state.meshVisible&&item.mesh?await itemImage(item):null;
|
|
197
446
|
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();
|
|
447
|
+
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
448
|
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
449
|
}finally{image.close();}return;
|
|
201
450
|
}
|
|
202
451
|
const img = await itemImage(item), front = state.footprints ? frontParts(data.items, item) : [];
|
|
203
452
|
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;
|
|
453
|
+
const original=(paintingHeld||state.comparison.mode==='overlay')&&data.painting?await paintingImage():null;
|
|
454
|
+
if (disposed || token !== paintToken) return;
|
|
206
455
|
const ctx = setCanvas(canvas, w, h);
|
|
207
|
-
const makeCanvas=(w:number,h:number)=>Object.assign(
|
|
456
|
+
const makeCanvas=(w:number,h:number)=>Object.assign(doc.createElement('canvas'),{width:w,height:h});
|
|
208
457
|
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
|
-
|
|
458
|
+
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 }) });
|
|
459
|
+
drawMeshes(ctx, [{box: item, image: img}], false);
|
|
211
460
|
overlay.replaceChildren(...data.flags.filter((f): f is Extract<Flag, { kind: 'faint' }> => f.item === item.name && f.kind === 'faint').map(f => {
|
|
212
461
|
const box = overlayBox(f.box[0], f.box[1], f.box[2], f.box[3]);
|
|
213
462
|
box.dataset.flag = f.id;
|
|
@@ -217,17 +466,17 @@ async function paintRaster(token:number): Promise<void> {
|
|
|
217
466
|
+ (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
467
|
}
|
|
219
468
|
|
|
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
|
|
469
|
+
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
470
|
|
|
222
471
|
function renderComparison():void {
|
|
223
472
|
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
|
-
|
|
473
|
+
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.'):'';}
|
|
474
|
+
const overlayButton=query<HTMLButtonElement>('[data-pv-comparison="overlay"]');if(overlayButton)overlayButton.disabled=!state.data?.painting;
|
|
226
475
|
$('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
|
|
476
|
+
$('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
477
|
$('pv-opacity-control').hidden=!overlay;$<HTMLInputElement>('pv-opacity').value=String(state.comparison.opacity);$('pv-opacity-value').textContent=(state.comparison.opacity*100).toFixed(1)+'%';
|
|
229
478
|
$<HTMLInputElement>('pv-alpha').disabled=overlay||difference;
|
|
230
|
-
|
|
479
|
+
|
|
231
480
|
$<HTMLInputElement>('pv-footprints').disabled=state.data?.mode==='atlas'||state.view==='assembled';
|
|
232
481
|
}
|
|
233
482
|
|
|
@@ -236,13 +485,13 @@ function renderFlags(): void {
|
|
|
236
485
|
const list = $('pv-flags');
|
|
237
486
|
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
487
|
const row = (f: Flag): HTMLLIElement => {
|
|
239
|
-
const li =
|
|
488
|
+
const li = doc.createElement('li');
|
|
240
489
|
li.dataset.flagId = f.id; li.dataset.flagSource = f.source;
|
|
241
|
-
const label =
|
|
490
|
+
const label = doc.createElement('span'); label.className = 'pv-flag-label'; label.textContent = flagLabel(f, t);
|
|
242
491
|
li.append(label);
|
|
243
492
|
if (f.kind === 'check') {
|
|
244
493
|
// The producer's object, verbatim, one click away: the label names its fields and hides none of it.
|
|
245
|
-
const raw =
|
|
494
|
+
const raw = doc.createElement('details'), summary = doc.createElement('summary'), code = doc.createElement('code');
|
|
246
495
|
summary.textContent = t('Producer line'); code.textContent = `${f.path}: ${f.line}`;
|
|
247
496
|
raw.append(summary, code); li.append(raw);
|
|
248
497
|
}
|
|
@@ -252,7 +501,7 @@ function renderFlags(): void {
|
|
|
252
501
|
list.replaceChildren(...(['mesh_report', 'check'] as const).flatMap(source => {
|
|
253
502
|
const fromSource = flags.filter(f => f.source === source);
|
|
254
503
|
if (!fromSource.length) return [];
|
|
255
|
-
const sourceItem =
|
|
504
|
+
const sourceItem = doc.createElement('li'), heading = doc.createElement('h3');
|
|
256
505
|
sourceItem.dataset.pvSource = source;
|
|
257
506
|
heading.textContent = source === 'mesh_report' ? 'mesh_report.json' : 'check.json';
|
|
258
507
|
sourceItem.append(heading);
|
|
@@ -260,7 +509,7 @@ function renderFlags(): void {
|
|
|
260
509
|
for (const category of categories) {
|
|
261
510
|
const selected = fromSource.filter(f => readingGroup(f) === category);
|
|
262
511
|
if (!selected.length) continue;
|
|
263
|
-
const section =
|
|
512
|
+
const section = doc.createElement('details'), title = doc.createElement('summary');
|
|
264
513
|
section.dataset.pvCategory = category;
|
|
265
514
|
title.textContent = t(category === 'mesh' ? 'Mesh flags' : category === 'part' ? 'Part findings' : category === 'pair' ? 'Pair readings' : category === 'evidence' ? 'Check evidence' : 'Unclassified check rows');
|
|
266
515
|
section.append(title);
|
|
@@ -271,7 +520,7 @@ function renderFlags(): void {
|
|
|
271
520
|
group.push(f); roots.set(root, group);
|
|
272
521
|
}
|
|
273
522
|
for (const [root, group] of roots) {
|
|
274
|
-
const details =
|
|
523
|
+
const details = doc.createElement('details'), summary = doc.createElement('summary'), rows = doc.createElement('ul');
|
|
275
524
|
details.dataset.pvRoot = root; details.dataset.flagSource = source;
|
|
276
525
|
summary.textContent = group.length === 1 ? t('{root} · 1 row', { root }) : t('{root} · {count} rows', { root, count: group.length });
|
|
277
526
|
rows.append(...group.map(row)); details.append(summary, rows); section.append(details);
|
|
@@ -280,7 +529,7 @@ function renderFlags(): void {
|
|
|
280
529
|
}
|
|
281
530
|
return [sourceItem];
|
|
282
531
|
}));
|
|
283
|
-
if (!flags.length) { const li =
|
|
532
|
+
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
533
|
$('pv-flag-sources').textContent = [
|
|
285
534
|
data.flagSources.length ? t('Read from: {files}.', { files: data.flagSources.join(', ') }) : '',
|
|
286
535
|
data.flagMissing.length ? t('Not found: {files}.', { files: data.flagMissing.join(', ') }) : '',
|
|
@@ -293,13 +542,14 @@ function renderFlags(): void {
|
|
|
293
542
|
function renderList(): void {
|
|
294
543
|
const data = state.data!, list = $('pv-items');
|
|
295
544
|
const seen = new Set<string>();
|
|
545
|
+
const issueList = comments;
|
|
296
546
|
list.replaceChildren(...data.items.filter(i => !seen.has(i.name) && seen.add(i.name)).map(item => {
|
|
297
|
-
const li =
|
|
547
|
+
const li = doc.createElement('li'), button = doc.createElement('button');
|
|
298
548
|
button.type = 'button'; button.dataset.pvItem = item.name; button.title = item.name;
|
|
299
549
|
if (data.items[state.selected]?.name === item.name) button.setAttribute('aria-current', 'true');
|
|
300
|
-
const name =
|
|
550
|
+
const name = doc.createElement('span'); name.className = 'pv-name'; name.textContent = item.name;
|
|
301
551
|
const onItem = [...data.flags.filter(f => f.kind === 'faint'), ...(data.readings ?? [])].filter(f => f.item === item.name && countedFlag(f));
|
|
302
|
-
const flags =
|
|
552
|
+
const flags = doc.createElement('span'); flags.className = 'pv-count';
|
|
303
553
|
// flagSources holds actual basenames (including custom.json); flagMissing canonically names unread kinds.
|
|
304
554
|
const meshRead = !data.flagMissing.includes('mesh_report.json'), checkRead = !data.flagMissing.includes('check.json');
|
|
305
555
|
const mesh = onItem.filter(f => f.source === 'mesh_report').length, check = onItem.filter(f => f.source === 'check').length;
|
|
@@ -308,178 +558,131 @@ function renderList(): void {
|
|
|
308
558
|
else if (meshRead) flags.textContent = t('mesh {mesh}', { mesh });
|
|
309
559
|
else if (checkRead) flags.textContent = t('check {check}', { check });
|
|
310
560
|
}
|
|
311
|
-
const
|
|
312
|
-
const badge =
|
|
561
|
+
const issueCount = issueList.filter(c => c.parts.some(p => p.name === item.name)).length;
|
|
562
|
+
const badge = doc.createElement('span'); badge.className = 'pv-badge'; badge.dataset.issues = String(issueCount); badge.textContent = issueCount ? String(issueCount) : '';
|
|
313
563
|
button.append(name, flags, badge);
|
|
314
564
|
button.onclick = () => { select(item.index); if (data.mode === 'atlas') setView('item'); };
|
|
315
565
|
li.append(button);
|
|
316
566
|
if(data.mode==='parts'){
|
|
317
|
-
const label=
|
|
567
|
+
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
568
|
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
569
|
}
|
|
320
570
|
return li;
|
|
321
571
|
}));
|
|
322
572
|
}
|
|
323
573
|
|
|
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
574
|
function renderMesh(): void {
|
|
334
|
-
|
|
335
|
-
|
|
575
|
+
query('#pv-mesh-panel')?.remove();
|
|
576
|
+
query('#pv-mesh-control')?.remove();
|
|
336
577
|
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
|
-
|
|
578
|
+
const meshCount = state.data!.items.filter(part => part.mesh).length;
|
|
579
|
+
const control = doc.createElement('label'); control.id = 'pv-mesh-control'; control.className = 'pv-field';
|
|
580
|
+
const toggle = doc.createElement('input'); toggle.type = 'checkbox'; toggle.checked = state.meshVisible;
|
|
581
|
+
toggle.onchange = () => { state.meshVisible = toggle.checked; void paint(); };
|
|
582
|
+
control.append(toggle, meshCount ? t('mesh from rig.json UVs') : t('Mesh (none 0/{0})', [state.data!.items.length])); query('.pv-toolbar')?.append(control);
|
|
583
|
+
const panel = doc.createElement('section'); panel.id = 'pv-mesh-panel';
|
|
584
|
+
const heading = doc.createElement('h2'); heading.textContent = t('Mesh geometry'); panel.append(heading);
|
|
585
|
+
if (!item.mesh) {
|
|
586
|
+
const unavailable = doc.createElement('p');
|
|
587
|
+
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.');
|
|
588
|
+
panel.append(unavailable);slots.side.append(panel);return;
|
|
589
|
+
}
|
|
590
|
+
const figures = doc.createElement('dl');
|
|
345
591
|
for (const key of ['mode', 'vertices', 'triangles', 'art_coverage', 'stray_cleared']) {
|
|
346
|
-
const dt =
|
|
592
|
+
const dt = doc.createElement('dt'), dd = doc.createElement('dd'); dt.textContent = key;
|
|
347
593
|
dd.textContent = Object.hasOwn(item.mesh.figures, key) ? JSON.stringify(item.mesh.figures[key]) : t('not reported');
|
|
348
594
|
dd.dataset.meshFigure = key; figures.append(dt, dd);
|
|
349
595
|
}
|
|
350
596
|
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);
|
|
597
|
+
const help = doc.createElement('p'); help.textContent = t('Pink: art pixels outside every triangle.'); panel.append(help);
|
|
598
|
+
slots.side.append(panel);
|
|
363
599
|
}
|
|
364
600
|
|
|
365
601
|
function select(index: number): void {
|
|
366
|
-
|
|
602
|
+
if (disposed) return;
|
|
603
|
+
hoverName = null;highlightedParts.clear();
|
|
604
|
+
queueMicrotask(() => { if (!disposed) renderCorrections(); });
|
|
367
605
|
const data = state.data!;
|
|
368
606
|
const item = data.items[index]!;
|
|
369
607
|
if (item.page !== undefined) state.page = data.pages.findIndex(p => p.name === item.page);
|
|
370
608
|
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
609
|
commentUi?.refresh();
|
|
372
|
-
renderList(); renderFlags();
|
|
610
|
+
renderList(); renderFlags(); renderMesh(); renderComparison(); void paint();
|
|
373
611
|
}
|
|
374
612
|
|
|
375
613
|
function setView(view: 'item' | 'page' | 'assembled'): void {
|
|
376
614
|
if(view==='assembled'&&(state.data?.mode!=='parts'||!state.data.rigSize))return;
|
|
377
615
|
if((state.view!==view||paintFailure)&&viewport){viewport.writeCamera('rig',{zoom:1,center:null});viewport.writeCamera('reference',{zoom:1,center:null});}
|
|
378
616
|
if(view!=='item'&&state.comparison.mode==='difference')state.comparison={mode:'part',opacity:state.comparison.opacity};
|
|
379
|
-
|
|
380
|
-
|
|
617
|
+
hoverName = null;
|
|
618
|
+
state.view = view;$('pv-assemble').setAttribute('aria-pressed', String(view === 'assembled'));renderMesh();renderComparison();$('rig-label').textContent=t(view==='assembled'?'Assembled':'Selected part');commentUi?.refresh();
|
|
619
|
+
for (const b of queryAll<HTMLButtonElement>('[data-pv-view]')) b.setAttribute('aria-pressed', String(b.dataset.pvView === view));
|
|
381
620
|
void paint();
|
|
382
621
|
}
|
|
383
622
|
|
|
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';
|
|
623
|
+
function renderLegacyVerdict(): void {
|
|
624
|
+
const legacy = state.data?.legacyVerdict;
|
|
625
|
+
const list = query('#pv-legacy-flagged') as HTMLElement | null;
|
|
626
|
+
if (!list) return;
|
|
627
|
+
if (!legacy) {
|
|
628
|
+
list.hidden = true;
|
|
629
|
+
list.replaceChildren();
|
|
399
630
|
return;
|
|
400
631
|
}
|
|
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;}
|
|
632
|
+
list.hidden = !legacy.flaggedParts.length;
|
|
633
|
+
list.replaceChildren(...legacy.flaggedParts.map(fp => {
|
|
634
|
+
const li = doc.createElement('li');
|
|
635
|
+
li.dataset.legacyFlaggedPart = fp.name;
|
|
636
|
+
li.textContent = fp.note ? fp.name + ': ' + fp.note : fp.name;
|
|
637
|
+
return li;
|
|
638
|
+
}));
|
|
431
639
|
}
|
|
432
640
|
|
|
433
641
|
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)=>{
|
|
642
|
+
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;
|
|
643
|
+
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
644
|
frameSize:target=>{
|
|
437
645
|
const data=state.data,item=data?.items[state.selected];
|
|
438
646
|
if(!data||!item||paintReset)return null;
|
|
439
647
|
if(paintFailure)return {w:0,h:0};
|
|
440
648
|
return target==='rig'?rasterFrame(data,item)??{w:0,h:0}:data.painting?partFrame(data,item):null;
|
|
441
649
|
},
|
|
442
|
-
});viewport.bindControls();
|
|
650
|
+
});disposers.push(viewport.bindControls());
|
|
443
651
|
$('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.');
|
|
652
|
+
if (disposed) return;
|
|
653
|
+
let data: ViewData & { error?: string };
|
|
654
|
+
try {
|
|
655
|
+
data = await source.view();
|
|
656
|
+
} catch (err) {
|
|
657
|
+
if (disposed) return;
|
|
658
|
+
const status = $('pv-load');
|
|
659
|
+
status.textContent = t(err instanceof Error ? err.message : 'Save failed.');
|
|
660
|
+
status.dataset.result = 'refused';
|
|
661
|
+
painting=false;paintFailure=err instanceof Error?err.message:String(err);syncPaintState();
|
|
662
|
+
settleReady(err);
|
|
663
|
+
return;
|
|
468
664
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
if (data.
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
665
|
+
if (disposed) return;
|
|
666
|
+
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; }
|
|
667
|
+
if (!data.items.length) throw new Error('PARTS_PAINT_FAILED');
|
|
668
|
+
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;
|
|
669
|
+
if (data.mode !== 'parts' || !data.rigSize) state.view = 'item';
|
|
670
|
+
comments.push(...structuredClone(host.initial()).map(issue => parsePartsIssue(issue, false, true, false)));
|
|
671
|
+
host.register({kind: 'parts-verdict', value: () => {
|
|
672
|
+
if (disposed || state.data?.legacyVerdict?.readOnly) throw new Error('PARTS_VERDICT_READ_ONLY');
|
|
673
|
+
return {verdict: comments.length ? 'changes-requested' : 'approved', issues: structuredClone(comments), words: ''};
|
|
674
|
+
}});
|
|
675
|
+
setupPartsComments();const ro=viewport.observeResize();disposers.push(viewport.bindNavigation(undefined,()=>mountActive&&!disposed&&!commentUi?.active()&&!paintFailure),()=>ro.disconnect());
|
|
676
|
+
renderLegacyVerdict();
|
|
677
|
+
const legacyBanner = data.legacyVerdict ? data.legacyVerdict.code + ': ' + t('parts.legacyVerdictBanner', [data.legacyVerdict.flaggedCount]) : '';
|
|
475
678
|
$('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(
|
|
679
|
+
$('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):'';
|
|
680
|
+
if (legacyBanner) $('pv-load').dataset.result = 'readonly';
|
|
478
681
|
$('pv-atlas-switch').hidden = data.mode !== 'atlas';
|
|
479
682
|
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
683
|
assemble.onclick=()=>{setView(state.view==='assembled'?'item':'assembled');assemble.setAttribute('aria-pressed',String(state.view==='assembled'));};
|
|
481
684
|
bindAssemblyPicking();
|
|
482
|
-
for(const button of
|
|
685
|
+
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
686
|
$<HTMLInputElement>('pv-opacity').oninput=e=>{state.comparison.opacity=Number((e.target as HTMLInputElement).value);renderComparison();void paint();};
|
|
484
687
|
$<HTMLInputElement>('pv-threshold').oninput=e=>{
|
|
485
688
|
const input=e.target as HTMLInputElement,threshold=input.valueAsNumber,status=$('pv-save-status');
|
|
@@ -500,105 +703,284 @@ async function boot(): Promise<void> {
|
|
|
500
703
|
$<HTMLInputElement>('pv-alpha').onchange = e => { state.alpha = (e.target as HTMLInputElement).checked; void paint(); };
|
|
501
704
|
footprints.onchange = e => { state.footprints = (e.target as HTMLInputElement).checked; void paint(); };
|
|
502
705
|
|
|
503
|
-
for (const b of
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
706
|
+
for (const b of queryAll<HTMLButtonElement>('[data-pv-view]')) b.onclick = () => setView(b.dataset.pvView as 'item' | 'page');
|
|
707
|
+
const offLang = onLanguageChange(() => { if (!disposed && state.data) { localizeWorkspace(); select(state.selected); } });
|
|
708
|
+
disposers.push(offLang);
|
|
709
|
+
if(data.items.length){
|
|
710
|
+
const index = pendingSelectPart ? data.items.findIndex(item => item.name === pendingSelectPart) : 0;
|
|
711
|
+
select(index >= 0 ? index : 0);
|
|
712
|
+
$('rig-label').textContent = t(state.view === 'assembled' ? 'Assembled' : 'Selected part');
|
|
713
|
+
assemble.setAttribute('aria-pressed', String(state.view === 'assembled'));
|
|
714
|
+
}
|
|
715
|
+
localizeWorkspace();
|
|
512
716
|
renderCorrections();
|
|
513
|
-
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
function localizeWorkspace(): void {
|
|
720
|
+
applyDomI18n(slots.toolbar);
|
|
721
|
+
$('reference-pane').setAttribute('aria-label', t('Reference'));
|
|
722
|
+
$('rig-pane').setAttribute('aria-label', t('Rig'));
|
|
723
|
+
$('reference-label').textContent = t('Reference');
|
|
724
|
+
$('rig-label').textContent = t(state.view === 'assembled' ? 'Assembled' : 'Selected part');
|
|
725
|
+
$('pv-list-title').textContent = t(state.data?.mode === 'atlas' ? 'REGIONS' : 'PARTS');
|
|
726
|
+
$('pv-flags-title').textContent = t('PRODUCER FLAGS');
|
|
727
|
+
viewport?.renderCameraControls();
|
|
514
728
|
}
|
|
515
729
|
|
|
516
730
|
/** Observe taps only; the shared controller exclusively owns pan, zoom and pinch. */
|
|
731
|
+
function assemblyLayers() {
|
|
732
|
+
return state.data!.items.flatMap(box => {
|
|
733
|
+
const image = images.get(`image:${box.index}`);
|
|
734
|
+
return image && !state.hidden.has(box.name) ? [{box, image, alpha: sourceAlpha(box, image)}] : [];
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
|
|
517
738
|
function bindAssemblyPicking():void {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
const
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
739
|
+
const pane = $('rig-viewport');
|
|
740
|
+
let tap: {id: number; x: number; y: number} | null = null;
|
|
741
|
+
const pointers = new Set<number>();
|
|
742
|
+
const available = () => !disposed && state.view === 'assembled' && !painting && !paintFailure && !paintingHeld && !commentUi?.active();
|
|
743
|
+
const hitAt = (event: MouseEvent) => {
|
|
744
|
+
const bounds = $('pv-canvas').getBoundingClientRect(), zoom = viewport!.paneCamera('rig').zoom;
|
|
745
|
+
return pickAssembly(assemblyLayers(), (event.clientX - bounds.left) / zoom, (event.clientY - bounds.top) / zoom);
|
|
746
|
+
};
|
|
747
|
+
const clearHover = () => {
|
|
748
|
+
if (!hoverName) return;
|
|
749
|
+
hoverName = null;
|
|
750
|
+
if (!disposed && state.view === 'assembled' && !painting && !paintFailure) renderAssemblySelection(assemblyLayers());
|
|
751
|
+
};
|
|
752
|
+
const onDown = (event: PointerEvent) => {
|
|
753
|
+
if ((event.target as Element)?.closest?.('.stage-comment-ui,button,input')) {tap = null;return;}
|
|
754
|
+
pointers.add(event.pointerId);
|
|
755
|
+
tap = pointers.size === 1 && event.button === 0 ? {id: event.pointerId, x: event.clientX, y: event.clientY} : null;
|
|
756
|
+
clearHover();
|
|
757
|
+
};
|
|
758
|
+
const onMove = (event: PointerEvent) => {
|
|
759
|
+
if (tap && Math.hypot(event.clientX - tap.x, event.clientY - tap.y) > 4) tap = null;
|
|
760
|
+
if (!available() || pointers.size || event.buttons) {clearHover();return;}
|
|
761
|
+
const name = hitAt(event)?.name ?? null;
|
|
762
|
+
if (name !== hoverName) {hoverName = name;renderAssemblySelection(assemblyLayers());}
|
|
763
|
+
};
|
|
764
|
+
const onCancel = (event: PointerEvent) => {pointers.delete(event.pointerId);tap = null;clearHover();};
|
|
765
|
+
const onUp = (event: PointerEvent) => {
|
|
766
|
+
pointers.delete(event.pointerId);const start = tap;tap = null;
|
|
767
|
+
if (!start || start.id !== event.pointerId || Math.hypot(event.clientX - start.x, event.clientY - start.y) > 4 || !available()) return;
|
|
768
|
+
const hit = hitAt(event);if (hit) select(hit.index);
|
|
769
|
+
};
|
|
770
|
+
const onDoubleClick = (event: MouseEvent) => {
|
|
771
|
+
if (disposed || state.view !== 'assembled' || paintFailure || paintingHeld || commentUi?.active()) return;
|
|
772
|
+
if ((event.target as Element)?.closest?.('.stage-comment-ui,button,input')) return;
|
|
773
|
+
const hit = hitAt(event);if (hit) {select(hit.index);setView('item');}
|
|
774
|
+
};
|
|
775
|
+
const releasePainting = () => {
|
|
776
|
+
if (!paintingHeld) return;
|
|
777
|
+
paintingHeld = false;
|
|
778
|
+
if (!disposed) void paint();
|
|
779
|
+
};
|
|
780
|
+
const keyDown = (event: KeyboardEvent) => {
|
|
781
|
+
if (mountActive && commentUi?.active()) clearHover();
|
|
782
|
+
if (!mountActive || disposed || event.defaultPrevented || event.repeat || event.ctrlKey || event.metaKey || event.altKey || textEntryFocused(event.target)) return;
|
|
783
|
+
if (event.key === 'Escape' && state.view === 'item' && !commentUi?.active() && !commentUi?.draft()) {
|
|
784
|
+
event.preventDefault();setView('assembled');
|
|
785
|
+
}
|
|
786
|
+
if (event.key.toLowerCase() === 'p' && state.data?.mode === 'parts' && state.data.painting && !painting && !paintFailure && !commentUi?.draft()) {
|
|
787
|
+
event.preventDefault();paintingHeld = true;hoverName = null;void paint();
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
const keyUp = (event: KeyboardEvent) => {if (event.key.toLowerCase() === 'p') releasePainting();};
|
|
791
|
+
const deactivate = () => {if (!mountActive) releasePainting();};
|
|
792
|
+
const onVisibilityChange = () => {
|
|
793
|
+
if (doc.visibilityState === 'hidden') releasePainting();
|
|
794
|
+
};
|
|
795
|
+
const bindings: [EventTarget, string, EventListener][] = [
|
|
796
|
+
[pane, 'pointerdown', onDown as EventListener], [pane, 'pointermove', onMove as EventListener],
|
|
797
|
+
[pane, 'pointercancel', onCancel as EventListener], [pane, 'pointerup', onUp as EventListener],
|
|
798
|
+
[pane, 'pointerleave', clearHover], [pane, 'dblclick', onDoubleClick as EventListener],
|
|
799
|
+
[doc, 'keydown', keyDown as EventListener], [doc, 'keyup', keyUp as EventListener],
|
|
800
|
+
[doc, 'focusin', deactivate], [doc, 'pointerdown', deactivate], [eventWindow, 'blur', releasePainting],
|
|
801
|
+
[doc, 'visibilitychange', onVisibilityChange],
|
|
802
|
+
];
|
|
803
|
+
for (const [target, type, handler] of bindings) target.addEventListener(type, handler);
|
|
804
|
+
disposers.push(() => {for (const [target, type, handler] of bindings) target.removeEventListener(type, handler);});
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
interface PartsPose extends CommentUiPose {item:Item;sourceHash:string;view:PartsIssue['view']}
|
|
808
|
+
function issueParts(names: string[]): PartsIssue['parts'] {
|
|
809
|
+
return names.map(name => {
|
|
810
|
+
const item = state.data?.items.find(item => item.name === name);
|
|
811
|
+
if (!item?.imageHash) throw new Error('PARTS_COMMENT_PART_MISMATCH: comment belongs to another part');
|
|
812
|
+
return {name, imageHash: item.imageHash};
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
async function prepareIssue(issue: PartsIssue): Promise<PartsIssue> {
|
|
817
|
+
const data = state.data!;
|
|
818
|
+
const bound = parsePartsIssue(issue, false, false, false);
|
|
819
|
+
const items = new Map(data.items.map(item => [item.name, {...item, imageHash: item.imageHash!}]));
|
|
820
|
+
assertPartsIssueBinding(bound, items, data.sourceHash);
|
|
821
|
+
const prepared = await source.crop(bound);
|
|
822
|
+
if (disposed || state.data !== data) throw new Error('PARTS_COMMENT_STALE_SOURCE');
|
|
823
|
+
return parsePartsIssue(prepared, true, false, false);
|
|
824
|
+
}
|
|
825
|
+
|
|
532
826
|
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
|
-
|
|
827
|
+
const codec:CommentCodec<PartsIssue,PartsPose>={
|
|
828
|
+
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;}},
|
|
829
|
+
signature:p=>[p.view.mode,p.item.name,p.item.imageHash,p.sourceHash,p.camera,p.view],
|
|
830
|
+
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;}},
|
|
831
|
+
label:raw=>{const c=parsePartsIssue(raw,false,true,false);return `${c.parts.map(pt=>pt.name).join(', ')} · ${c.summary}`;},
|
|
832
|
+
chips:(pose,screen,existing)=>{
|
|
833
|
+
const visible = state.data!.items.filter(item => !state.hidden.has(item.name));
|
|
834
|
+
if (existing) return {selected: existing.parts.map(part => part.name), candidates: existing.view.mode === 'assembled' ? visible.map(item => item.name) : []};
|
|
835
|
+
if (pose.view.mode === 'item') return {selected: [pose.item.name], candidates: []};
|
|
836
|
+
const size = state.data!.rigSize!;
|
|
837
|
+
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]}));
|
|
838
|
+
const hits = new Set<string>(), layers = assemblyLayers();
|
|
839
|
+
const stepX = Math.max(1, r.width / 32), stepY = Math.max(1, r.height / 32);
|
|
840
|
+
for (let y = r.y + .5; y < r.y + r.height; y += stepY) {
|
|
841
|
+
for (let x = r.x + .5; x < r.x + r.width; x += stepX) {
|
|
842
|
+
const hit = pickAssembly(layers, x, y);if (hit) hits.add(hit.name);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
return {selected: visible.filter(item => hits.has(item.name)).map(item => item.name), candidates: visible.map(item => item.name)};
|
|
846
|
+
},
|
|
847
|
+
create:async(p,_view,screen,crop,_bookmark,summary,parts)=>{
|
|
848
|
+
const isItem = p.view.mode === 'item';
|
|
849
|
+
const size = state.data!.rigSize!;
|
|
850
|
+
const bounds = {x: 0, y: 0, width: isItem ? p.item.w : size[0], height: isItem ? p.item.h : size[1]};
|
|
851
|
+
const r = snapImageRegion(region(unprojectMark(screen, p.camera),
|
|
852
|
+
unprojectMark({x: screen.x + screen.width, y: screen.y + screen.height}, p.camera), bounds));
|
|
853
|
+
return prepareIssue({schema:'rig-review-parts-comment/2',id:crypto.randomUUID(),summary,
|
|
854
|
+
parts:issueParts(isItem?[p.item.name]:parts??[]),sourceHash:p.sourceHash,
|
|
855
|
+
imageRegion:isItem?r:null,rigRegion:isItem?{...r,x:p.item.x+r.x,y:p.item.y+r.y}:r,
|
|
856
|
+
view:structuredClone(p.view),crop,nativeCrop:null});
|
|
857
|
+
},
|
|
858
|
+
update:async(existing,summary,parts)=>prepareIssue({...existing,summary,
|
|
859
|
+
parts:existing.view.mode==='assembled'?issueParts(parts??[]):existing.parts}),
|
|
539
860
|
};
|
|
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
|
-
|
|
861
|
+
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}};};
|
|
862
|
+
commentUi=bindStageComments({toolbar:slots.toolbar,listHost:slots.side,toggle:$<HTMLButtonElement>('stage-comment'),viewports:{rig:$('rig-viewport')},pose,pause:async()=>{},bookmark:()=>null,
|
|
863
|
+
restore:async(raw)=>{
|
|
864
|
+
const data = state.data!, navigation = paintToken, current = await source.view();
|
|
865
|
+
if (disposed) return;
|
|
866
|
+
if (navigation !== paintToken) throw new Error('COMMENT_BUSY: wait for inspection');
|
|
867
|
+
if (state.data !== data || current.sourceHash !== data.sourceHash) throw new Error('PARTS_COMMENT_STALE_SOURCE');
|
|
868
|
+
const bookmark = raw as {parts:PartsIssue['parts'];sourceHash:string;view:PartsIssue['view']};
|
|
869
|
+
const matched = bookmark.parts.map(part => data.items.find(item => item.name === part.name && item.imageHash === part.imageHash));
|
|
870
|
+
if (!matched.length || matched.some(item => !item) || data.sourceHash !== bookmark.sourceHash) throw new Error('PARTS_COMMENT_STALE_SOURCE: reopen the bound source');
|
|
871
|
+
setView(bookmark.view.mode);select(matched[0]!.index);
|
|
872
|
+
highlightedParts.clear();for (const part of bookmark.parts) {highlightedParts.add(part.name);state.hidden.delete(part.name);}
|
|
873
|
+
state.bg = bookmark.view.background;state.alpha = bookmark.view.alpha;state.footprints = bookmark.view.footprints;
|
|
874
|
+
state.comparison = {...(bookmark.view.comparison ?? defaultPartsComparison())};
|
|
875
|
+
if (state.comparison.mode === 'difference') state.differenceThreshold = state.comparison.threshold;
|
|
876
|
+
state.meshVisible = bookmark.view.mesh;
|
|
877
|
+
$<HTMLSelectElement>('pv-bg').value=state.bg;$<HTMLInputElement>('pv-alpha').checked=state.alpha;$<HTMLInputElement>('pv-footprints').checked=state.footprints;
|
|
878
|
+
renderList();renderMesh();renderComparison();viewport!.state.cameraRestoring = true;
|
|
879
|
+
const painted = paint(), token = paintToken;
|
|
880
|
+
try {
|
|
881
|
+
await painted;
|
|
882
|
+
if (disposed || token !== paintToken || paintFailure) return;
|
|
883
|
+
viewport!.writeCamera('rig', bookmark.view.camera);
|
|
884
|
+
if (bookmark.view.referenceCamera) viewport!.writeCamera('reference', bookmark.view.referenceCamera);
|
|
885
|
+
viewport!.state.cameraSync = bookmark.view.cameraSync;viewport!.fitCamera();
|
|
886
|
+
} finally {if (!disposed) viewport!.state.cameraRestoring = false;}
|
|
887
|
+
},
|
|
888
|
+
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
889
|
}
|
|
545
890
|
|
|
546
|
-
if (typeof document !== 'undefined' && document.getElementById('parts-app')) void boot();
|
|
547
|
-
|
|
548
891
|
function renderCorrections():void {
|
|
549
892
|
const data = state.data;
|
|
550
893
|
if (!stageEmbedded && (!data || (!Object.hasOwn(data, 'draft') && !Object.hasOwn(data, 'draftUnavailable')))) {
|
|
551
|
-
|
|
894
|
+
query('#pv-corrections')?.remove();
|
|
552
895
|
return;
|
|
553
896
|
}
|
|
554
|
-
let host=
|
|
897
|
+
let host=query('#pv-corrections');if(!host){host=doc.createElement('section');host.id='pv-corrections';slots.stage.append(host);}
|
|
555
898
|
host.replaceChildren();const item=data?.items[state.selected],mapping=data?.draft?.mappings.find(m=>m.part===item?.name);
|
|
556
|
-
const label=
|
|
899
|
+
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
900
|
if(!mapping||!data?.draft)return;
|
|
558
901
|
label.textContent+=` · ${mapping.part} · ${mapping.skin}/${mapping.slot}/${mapping.attachment} · v ${mapping.vertices} t ${mapping.triangles} · ${data.draft.buildId}`;
|
|
559
902
|
if(data.draft.inspectionOnly)return;
|
|
560
903
|
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=
|
|
904
|
+
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
905
|
}
|
|
563
|
-
const guidance=
|
|
906
|
+
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
907
|
}
|
|
565
908
|
|
|
566
909
|
function stagePartsSnapshot():StagePartsState|null {
|
|
567
910
|
const data=state.data,item=data?.items[state.selected],mapping=data?.draft?.mappings.find(m=>m.part===item?.name);
|
|
568
911
|
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.
|
|
912
|
+
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
913
|
}
|
|
571
914
|
async function restoreStageParts(saved:StagePartsState):Promise<void>{
|
|
572
|
-
if(
|
|
915
|
+
if(disposed||!state.data||!viewport)return;
|
|
573
916
|
try{
|
|
574
917
|
const index=stagePartsSelectionIndex(state.data,saved);
|
|
575
918
|
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.')
|
|
919
|
+
state.meshVisible=saved.mesh;
|
|
920
|
+
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();}
|
|
921
|
+
}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
922
|
finally{viewport.state.cameraRestoring=false;}
|
|
580
923
|
}
|
|
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
924
|
|
|
583
|
-
async function revalidateStageParts(
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
925
|
+
async function revalidateStageParts(savedState?: StagePartsState | null): Promise<void> {
|
|
926
|
+
try {
|
|
927
|
+
const data = await source.view();
|
|
928
|
+
if (disposed) return;
|
|
929
|
+
const previous = state.data;
|
|
930
|
+
const sameBuild = data.draft?.buildId === previous?.draft?.buildId;
|
|
931
|
+
const valid = sameBuild ? data.sourceHash === previous?.sourceHash :
|
|
932
|
+
Boolean(data.inspectionSourceHash && data.inspectionSourceHash === previous?.inspectionSourceHash);
|
|
933
|
+
if (!valid) throw new Error('STAGE_DRAFT_MISMATCH: separated parts and draft mesh identity differ.');
|
|
934
|
+
state.data = data;
|
|
935
|
+
imageGeneration++; paintToken++; pendingImages.clear();
|
|
936
|
+
images.clear(); assemblyAlpha.clear();
|
|
937
|
+
if (savedState) await restoreStageParts(savedState);
|
|
938
|
+
else if (data.items.length) { select(Math.min(state.selected, data.items.length - 1)); await paint(); }
|
|
939
|
+
renderCorrections();
|
|
940
|
+
} catch (error) {
|
|
941
|
+
if (disposed) return;
|
|
942
|
+
const status = $('pv-load');
|
|
943
|
+
status.hidden = false; status.dataset.result = 'refused';
|
|
944
|
+
status.textContent = t(error instanceof Error ? error.message : String(error));
|
|
945
|
+
for (const root of roots) if (root !== slots.stage) root.hidden = true;
|
|
946
|
+
$('stage-layout').hidden = true;
|
|
595
947
|
}
|
|
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
948
|
}
|
|
604
|
-
|
|
949
|
+
|
|
950
|
+
syncPaintState();
|
|
951
|
+
void boot().catch(error => {if(disposed)return;painting=false;paintFailure=error instanceof Error?error.message:String(error);syncPaintState();settleReady(error);});
|
|
952
|
+
return {
|
|
953
|
+
ready,
|
|
954
|
+
dispose(): void {
|
|
955
|
+
if (disposed) return;
|
|
956
|
+
disposed = true;
|
|
957
|
+
painting=false;syncPaintState();
|
|
958
|
+
settleReady(new Error('PARTS_WORKSPACE_DISPOSED'));
|
|
959
|
+
paintToken++; imageGeneration++;
|
|
960
|
+
commentUi?.dispose();
|
|
961
|
+
commentUi = null;
|
|
962
|
+
for (const dispose of disposers.splice(0)) dispose();
|
|
963
|
+
pendingImages.clear();
|
|
964
|
+
for (const root of roots) root.replaceChildren();
|
|
965
|
+
images.clear();
|
|
966
|
+
assemblyAlpha.clear();
|
|
967
|
+
},
|
|
968
|
+
select(part: string): void {
|
|
969
|
+
pendingSelectPart = part;
|
|
970
|
+
const idx = state.data?.items.findIndex(i => i.name === part) ?? -1;
|
|
971
|
+
if (idx >= 0) select(idx);
|
|
972
|
+
},
|
|
973
|
+
issues(): PartsIssue[] {
|
|
974
|
+
return structuredClone(comments);
|
|
975
|
+
},
|
|
976
|
+
snapshot(): StagePartsState | null {
|
|
977
|
+
return stagePartsSnapshot();
|
|
978
|
+
},
|
|
979
|
+
restore(saved: StagePartsState): Promise<void> {
|
|
980
|
+
return restoreStageParts(saved);
|
|
981
|
+
},
|
|
982
|
+
revalidate(savedState?: StagePartsState | null): Promise<void> {
|
|
983
|
+
return revalidateStageParts(savedState);
|
|
984
|
+
},
|
|
985
|
+
};
|
|
986
|
+
}
|