rig-review 2.4.5 → 2.5.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/REVIEW_PACKAGE.md +32 -1
- package/docs/STABILITY.md +2 -0
- package/package.json +1 -1
- package/src/comment-crops.ts +48 -3
- package/src/entry.ts +1 -0
- package/src/interview-project.ts +81 -26
- package/src/interview-routes.ts +14 -6
- package/src/interview-scene.ts +109 -0
- package/src/job-act.ts +59 -4
- package/src/job-api.ts +21 -6
- package/src/job-cli.ts +207 -11
- package/src/job-contract.ts +57 -1
- package/src/job-host.ts +4 -0
- package/src/job-session.ts +31 -4
- package/src/job-source.ts +6 -1
- package/src/job-store.ts +28 -0
- package/web/catalog-en.ts +9 -1
- package/web/catalog-ko.ts +9 -1
- package/web/interview-panel.ts +20 -4
- package/web/job-rig-capture.ts +169 -0
- package/web/job-session.ts +162 -17
- package/web/parts.ts +6 -1
- package/web/styles.css +14 -0
- package/web/viewport-capture.ts +119 -17
package/web/interview-panel.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HistoricalInterview, InterviewQuestion } from '../src/interview-project.ts';
|
|
1
|
+
import type { HistoricalInterview, InterviewQuestion, InterviewDiagnostic } from '../src/interview-project.ts';
|
|
2
2
|
import type { Picks } from '../src/interview-picks.ts';
|
|
3
3
|
import { onLanguageChange, t } from './i18n.ts';
|
|
4
4
|
import type { InstanceAccess } from './instance-access.ts';
|
|
@@ -34,11 +34,11 @@ async function request(access: InstanceAccess, path: string, body?: Picks) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export async function mountInterview(host: HTMLElement, access: InstanceAccess) {
|
|
37
|
-
let data: {questions:Question[];historical:HistoricalInterview[]; binding?:{projectHash:string;sourceHash:string;version?:number;draftId?:string}};
|
|
37
|
+
let data: {questions:Question[];historical:HistoricalInterview[]; diagnostics?:InterviewDiagnostic[]; binding?:{projectHash:string;sourceHash:string;version?:number;draftId?:string}};
|
|
38
38
|
try {data = await request(access, '/api/interview');}
|
|
39
39
|
catch (error) {
|
|
40
40
|
const render = () => {host.textContent = t(errorKey(error));};
|
|
41
|
-
onLanguageChange(render); render(); return;
|
|
41
|
+
const unmount = onLanguageChange(render); render(); return unmount;
|
|
42
42
|
}
|
|
43
43
|
const {questions, historical:legacy} = data;
|
|
44
44
|
const drafts = questions.map(question => {
|
|
@@ -56,17 +56,28 @@ export async function mountInterview(host: HTMLElement, access: InstanceAccess)
|
|
|
56
56
|
const joined = data.binding;
|
|
57
57
|
const source = joined ? element('p', t(joined.draftId===undefined?'interview.joined':'interview.joinedDraft', [joined.draftId??String(joined.version), joined.projectHash, joined.sourceHash])) : null;
|
|
58
58
|
if (source) source.className = 'interview-binding';
|
|
59
|
+
const diagnostics = element('section');
|
|
60
|
+
diagnostics.className = 'interview-diagnostics';
|
|
61
|
+
diagnostics.setAttribute('role', 'status');
|
|
62
|
+
for (const diagnostic of data.diagnostics ?? []) {
|
|
63
|
+
const message = diagnostic.code === 'INTERVIEW_OPTIONS_STALE' ? 'interview.historicalIssue' : diagnostic.code;
|
|
64
|
+
diagnostics.append(element('p', t(message)),
|
|
65
|
+
element('code', [diagnostic.question, diagnostic.record, diagnostic.at, diagnostic.ref.path, diagnostic.ref.sha256].filter(Boolean).join(' · ')));
|
|
66
|
+
}
|
|
59
67
|
const archive = element('details');
|
|
60
68
|
archive.append(element('summary', t('interview.legacy')));
|
|
61
69
|
for (const answer of legacy) {
|
|
62
70
|
const item = element('section');
|
|
63
71
|
item.append(element('h3', answer.question), element('p', [answer.by,answer.at].filter(Boolean).join(' · ')),
|
|
64
72
|
element('pre', answer.verbatim));
|
|
73
|
+
if (answer.ref) item.append(element('code', answer.ref.path + ' · ' + answer.ref.sha256));
|
|
74
|
+
if (answer.answer) item.append(element('pre', [answer.answer.by, answer.answer.at, answer.answer.source].filter(value => typeof value === 'string').join(' · ')));
|
|
65
75
|
archive.append(item);
|
|
66
76
|
}
|
|
67
77
|
if (!questions.length) {
|
|
68
78
|
host.replaceChildren(element('p', t('interview.empty')));
|
|
69
79
|
if (source) host.prepend(source);
|
|
80
|
+
host.append(diagnostics);
|
|
70
81
|
if (legacy.length) {archive.open = true; host.append(archive);}
|
|
71
82
|
return;
|
|
72
83
|
}
|
|
@@ -110,6 +121,10 @@ export async function mountInterview(host: HTMLElement, access: InstanceAccess)
|
|
|
110
121
|
const provenance = element('p', t('interview.provenance', [question.set.drafted_by, question.set.drafted_at]));
|
|
111
122
|
const binding = element('code', question.ref.path + ' · ' + question.ref.sha256);
|
|
112
123
|
form.append(provenance, binding);
|
|
124
|
+
if (question.answer) {
|
|
125
|
+
form.append(element('pre', [question.answer.by, question.answer.at, question.answer.source].filter(value => typeof value === 'string').join(' · ')),
|
|
126
|
+
element('pre', typeof question.answer.verbatim === 'string' ? question.answer.verbatim : ''));
|
|
127
|
+
}
|
|
113
128
|
const historical = question.answer?.choice as {picks?:Picks['picks'];note?:string} | undefined;
|
|
114
129
|
const status = element('p'); status.setAttribute('role','status');
|
|
115
130
|
const markUnsaved = () => {
|
|
@@ -182,7 +197,8 @@ export async function mountInterview(host: HTMLElement, access: InstanceAccess)
|
|
|
182
197
|
};
|
|
183
198
|
grid.append(art, form); host.replaceChildren(picker, grid);
|
|
184
199
|
if (source) host.prepend(source);
|
|
200
|
+
host.append(diagnostics);
|
|
185
201
|
if (legacy.length) host.append(archive);
|
|
186
202
|
};
|
|
187
|
-
onLanguageChange(render); render();
|
|
203
|
+
const unmount = onLanguageChange(render); render(); return unmount;
|
|
188
204
|
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type {RigPlayer} from '@rig-c/play';
|
|
2
|
+
import {jobStillByteLimit, type JobRigCapture, type JobUISubmission} from '../src/job-contract.ts';
|
|
3
|
+
import type {JobRigPresentation} from './viewport-capture.ts';
|
|
4
|
+
|
|
5
|
+
type DrawSource = Pick<JobRigCapture['binding'], 'publicationId' | 'instanceKey' | 'sourceHash' | 'pageId'>;
|
|
6
|
+
export interface JobRigDrawState {
|
|
7
|
+
player: Pick<RigPlayer, 'generation' | 'current' | 'time' | 'slots'> & {readonly renderer: object};
|
|
8
|
+
frameGeneration: number | undefined;
|
|
9
|
+
presentation: JobRigPresentation | undefined;
|
|
10
|
+
source: DrawSource;
|
|
11
|
+
layout: string;
|
|
12
|
+
defaultCamera: boolean;
|
|
13
|
+
wholeRig: boolean;
|
|
14
|
+
playing: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface JobRigDraw {
|
|
17
|
+
readonly player: JobRigDrawState['player'];
|
|
18
|
+
readonly renderer: object;
|
|
19
|
+
readonly presentation: JobRigPresentation;
|
|
20
|
+
readonly playerGeneration: number;
|
|
21
|
+
readonly drawGeneration: number;
|
|
22
|
+
readonly animation: string | null;
|
|
23
|
+
readonly time: number;
|
|
24
|
+
readonly playing: boolean;
|
|
25
|
+
readonly source: DrawSource;
|
|
26
|
+
readonly layout: string;
|
|
27
|
+
}
|
|
28
|
+
export interface JobRigPixels {
|
|
29
|
+
readonly width: number;
|
|
30
|
+
readonly height: number;
|
|
31
|
+
encode(): Promise<string>;
|
|
32
|
+
}
|
|
33
|
+
export interface FrozenJobRigCapture {
|
|
34
|
+
encode(): Promise<JobRigCapture>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const sourceKey = (source: DrawSource) => JSON.stringify([
|
|
38
|
+
source.publicationId, source.instanceKey, source.sourceHash, source.pageId,
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
/** Bind local placement and physical-pixel phase while allowing whole-pixel page movement. */
|
|
42
|
+
export function jobRigPixelPlacement(pane: Pick<DOMRect, 'left' | 'top'>,
|
|
43
|
+
canvas: Pick<DOMRect, 'left' | 'top'>, ratio: number) {
|
|
44
|
+
function phase(coordinate: number): number {
|
|
45
|
+
const deviceCoordinate = coordinate * ratio;
|
|
46
|
+
return deviceCoordinate - Math.floor(deviceCoordinate);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
offsetX: canvas.left - pane.left,
|
|
50
|
+
offsetY: canvas.top - pane.top,
|
|
51
|
+
panePhaseX: phase(pane.left),
|
|
52
|
+
panePhaseY: phase(pane.top),
|
|
53
|
+
canvasPhaseX: phase(canvas.left),
|
|
54
|
+
canvasPhaseY: phase(canvas.top),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Called after the public draw/present and viewport-render boundaries succeed. */
|
|
59
|
+
export function recordJobRigDraw(state: JobRigDrawState, drawGeneration: number): JobRigDraw {
|
|
60
|
+
if (!state.presentation || state.frameGeneration !== state.player.generation || !Number.isSafeInteger(drawGeneration) || drawGeneration < 1 ||
|
|
61
|
+
!Number.isSafeInteger(state.player.generation) || state.player.generation < 0 || !Number.isFinite(state.player.time) || state.player.time < 0) {
|
|
62
|
+
throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
63
|
+
}
|
|
64
|
+
return Object.freeze({
|
|
65
|
+
player: state.player,
|
|
66
|
+
renderer: state.player.renderer,
|
|
67
|
+
presentation: state.presentation,
|
|
68
|
+
playerGeneration: state.player.generation,
|
|
69
|
+
drawGeneration,
|
|
70
|
+
animation: state.player.current,
|
|
71
|
+
time: state.player.time,
|
|
72
|
+
playing: state.playing,
|
|
73
|
+
source: Object.freeze({...state.source}),
|
|
74
|
+
layout: state.layout,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** copy() runs synchronously. The returned encoder owns an already copied bitmap. */
|
|
79
|
+
export function freezeJobRigCapture(draw: JobRigDraw | undefined, state: JobRigDrawState, askId: string,
|
|
80
|
+
copy: () => JobRigPixels): FrozenJobRigCapture {
|
|
81
|
+
if (!state.defaultCamera) throw new Error('JOB_STILL_CAMERA_NOT_FIXED');
|
|
82
|
+
if (!state.wholeRig || state.player.slots !== null) throw new Error('JOB_STILL_VIEW_UNSUPPORTED');
|
|
83
|
+
if (!draw) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
84
|
+
if (draw.presentation !== state.presentation || draw.player !== state.player || draw.renderer !== state.player.renderer || draw.playerGeneration !== state.player.generation ||
|
|
85
|
+
state.frameGeneration !== draw.playerGeneration || draw.animation !== state.player.current ||
|
|
86
|
+
draw.time !== state.player.time || draw.layout !== state.layout || sourceKey(draw.source) !== sourceKey(state.source)) {
|
|
87
|
+
throw new Error('JOB_STILL_BINDING_MISMATCH');
|
|
88
|
+
}
|
|
89
|
+
if (draw.animation !== null && !draw.animation) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
90
|
+
const pixels = copy();
|
|
91
|
+
if (state.presentation !== draw.presentation || state.player.renderer !== draw.renderer || state.player.generation !== draw.playerGeneration || state.player.current !== draw.animation ||
|
|
92
|
+
state.player.time !== draw.time || draw.layout !== state.layout || sourceKey(draw.source) !== sourceKey(state.source)) {
|
|
93
|
+
throw new Error('JOB_STILL_BINDING_MISMATCH');
|
|
94
|
+
}
|
|
95
|
+
if (!Number.isSafeInteger(pixels.width) || !Number.isSafeInteger(pixels.height) || pixels.width < 1 || pixels.height < 1 ||
|
|
96
|
+
pixels.width > 16384 || pixels.height > 16384 || pixels.width * pixels.height > 16777216) {
|
|
97
|
+
throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
98
|
+
}
|
|
99
|
+
const metadata: Omit<JobRigCapture, 'png'> = {
|
|
100
|
+
width: pixels.width, height: pixels.height, camera: 'fixed', framing: 'default', view: 'whole-rig',
|
|
101
|
+
frame: draw.animation === null ? 'setup' : draw.time,
|
|
102
|
+
...(draw.animation === null ? {} : {animation: draw.animation}), playing: draw.playing,
|
|
103
|
+
binding: {...draw.source, askId, drawGeneration: draw.drawGeneration, playerGeneration: draw.playerGeneration},
|
|
104
|
+
};
|
|
105
|
+
return {async encode() {
|
|
106
|
+
const png = await pixels.encode();
|
|
107
|
+
if (!png.startsWith('data:image/png;base64,') || png.length > 22 + Math.ceil(jobStillByteLimit / 3) * 4) {
|
|
108
|
+
throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
109
|
+
}
|
|
110
|
+
return {...metadata, png};
|
|
111
|
+
}};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Copy the committed display bitmap synchronously, before asynchronous PNG encoding. */
|
|
115
|
+
export function copyJobRigViewport(presentation: JobRigPresentation): JobRigPixels {
|
|
116
|
+
const {canvas: displayed, width, height, ratio} = presentation;
|
|
117
|
+
if (!displayed.isConnected || displayed.width !== width || displayed.height !== height ||
|
|
118
|
+
ratio !== (globalThis.devicePixelRatio || 1) || width < 1 || height < 1 ||
|
|
119
|
+
width > 16384 || height > 16384 || width * height > 16777216) {
|
|
120
|
+
throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
121
|
+
}
|
|
122
|
+
const canvas = document.createElement('canvas');
|
|
123
|
+
canvas.width = width;
|
|
124
|
+
canvas.height = height;
|
|
125
|
+
try {
|
|
126
|
+
const source = displayed.getContext('2d');
|
|
127
|
+
const context = canvas.getContext('2d');
|
|
128
|
+
if (!source || !context) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
129
|
+
context.putImageData(source.getImageData(0, 0, width, height), 0, 0);
|
|
130
|
+
} catch { throw new Error('JOB_STILL_CAPTURE_FAILED'); }
|
|
131
|
+
return {width, height, encode: () => new Promise<string>((resolve, reject) => {
|
|
132
|
+
canvas.toBlob(blob => {
|
|
133
|
+
if (!blob || blob.size > jobStillByteLimit) {reject(new Error('JOB_STILL_CAPTURE_FAILED')); return;}
|
|
134
|
+
const reader = new FileReader();
|
|
135
|
+
reader.onload = () => typeof reader.result === 'string' ? resolve(reader.result) : reject(new Error('JOB_STILL_CAPTURE_FAILED'));
|
|
136
|
+
reader.onerror = () => reject(new Error('JOB_STILL_CAPTURE_FAILED'));
|
|
137
|
+
reader.readAsDataURL(blob);
|
|
138
|
+
}, 'image/png');
|
|
139
|
+
}).catch(() => {throw new Error('JOB_STILL_CAPTURE_FAILED');})};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Per-form first attempt, including human words and observed generation, survives a lost reply. */
|
|
143
|
+
export function createJobRigSubmission() {
|
|
144
|
+
let frozen: {identity: string; base: Extract<JobUISubmission, {kind: 'review-verdict'}>; copy?: FrozenJobRigCapture;
|
|
145
|
+
pending?: Promise<JobUISubmission>; request?: JobUISubmission} | undefined;
|
|
146
|
+
return {
|
|
147
|
+
reset() {frozen = undefined;},
|
|
148
|
+
prepare(input: JobUISubmission, copy: () => FrozenJobRigCapture): Promise<JobUISubmission> {
|
|
149
|
+
if (input.kind !== 'review-verdict' || input.value.stage !== 'rig-review') throw new Error('JOB_ACT_INVALID');
|
|
150
|
+
const identity = JSON.stringify([input.publicationId, input.pageId, input.displayedNonce, input.askId, input.submissionId, input.kind]);
|
|
151
|
+
if (frozen && frozen.identity !== identity) throw new Error('JOB_STILL_BINDING_MISMATCH');
|
|
152
|
+
if (!frozen) {
|
|
153
|
+
const base = structuredClone(input);
|
|
154
|
+
frozen = {identity, base, copy: copy()};
|
|
155
|
+
}
|
|
156
|
+
const saved = frozen;
|
|
157
|
+
if (saved.request) return Promise.resolve(saved.request);
|
|
158
|
+
if (!saved.pending) saved.pending = saved.copy!.encode().then(capture => {
|
|
159
|
+
Object.freeze(capture.binding);
|
|
160
|
+
Object.freeze(capture);
|
|
161
|
+
Object.freeze(saved.base.value);
|
|
162
|
+
saved.request = Object.freeze({...saved.base, capture});
|
|
163
|
+
saved.copy = undefined;
|
|
164
|
+
return saved.request;
|
|
165
|
+
}).finally(() => {saved.pending = undefined;});
|
|
166
|
+
return saved.pending;
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
package/web/job-session.ts
CHANGED
|
@@ -4,6 +4,10 @@ import {enCatalog} from './catalog-en.ts';
|
|
|
4
4
|
import {koCatalog} from './catalog-ko.ts';
|
|
5
5
|
import {t} from './i18n.ts';
|
|
6
6
|
import {JOB_HUB_READY, jobHubMessageMatches, type JobHubBinding} from './job-hub.ts';
|
|
7
|
+
import {recordJobRigDraw, freezeJobRigCapture, copyJobRigViewport, createJobRigSubmission, jobRigPixelPlacement,
|
|
8
|
+
type JobRigDraw, type JobRigDrawState} from './job-rig-capture.ts';
|
|
9
|
+
import {presentJobRigViewport, type JobRigPresentation} from './viewport-capture.ts';
|
|
10
|
+
import {CanvasRenderer} from '@rig-c/play';
|
|
7
11
|
|
|
8
12
|
/** Imported runtimes may throw arbitrary prose. Only registered refusal copy reaches the window. */
|
|
9
13
|
export function jobWindowRefusal(error: unknown, fallback = 'JOB_WINDOW_FAILED'): string {
|
|
@@ -125,6 +129,7 @@ export function createJobWindow<Prepared>(options: {
|
|
|
125
129
|
}) {
|
|
126
130
|
const { transport, adapter, pageId } = options;
|
|
127
131
|
const pending = new Map<string, JobPendingAsk>();
|
|
132
|
+
const rigAttempts = new WeakSet<JobUISubmission>();
|
|
128
133
|
const retainedDrafts: JobRetainedDraft[] = [];
|
|
129
134
|
let generation = 0;
|
|
130
135
|
let displayed: JobDisplayPublication | null = null;
|
|
@@ -256,14 +261,16 @@ export function createJobWindow<Prepared>(options: {
|
|
|
256
261
|
if (closed)
|
|
257
262
|
return { ok: false, error: { code: 'JOB_CLOSED', message: 'JOB_CLOSED' } };
|
|
258
263
|
const ask = pending.get(input.askId);
|
|
264
|
+
const retry = input.capture !== undefined && rigAttempts.has(input);
|
|
259
265
|
if (preparing || !displayed || !receipt ||
|
|
260
266
|
input.publicationId !== displayed.publication.publicationId ||
|
|
261
267
|
input.pageId !== pageId || input.displayedNonce !== receipt.displayedNonce ||
|
|
262
268
|
input.expectedGeneration > generation ||
|
|
263
|
-
ask && (ask.status !== 'pending' || ask.publicationId !== input.publicationId || ask.subject.kind !== input.kind)) {
|
|
269
|
+
ask && (ask.status !== 'pending' && !retry || ask.publicationId !== input.publicationId || ask.subject.kind !== input.kind)) {
|
|
264
270
|
return { ok: false, error: { code: 'JOB_ACT_SOURCE_STALE', message: 'JOB_ACT_SOURCE_STALE' } };
|
|
265
271
|
}
|
|
266
272
|
// The backend authenticates the actual Request and validates the semantic value.
|
|
273
|
+
if (input.capture !== undefined) rigAttempts.add(input);
|
|
267
274
|
return transport.submit(input);
|
|
268
275
|
}
|
|
269
276
|
return {
|
|
@@ -609,8 +616,9 @@ export interface JobPreparedInspection {
|
|
|
609
616
|
assets: ModelAssets | null;
|
|
610
617
|
player: RigPlayer | null;
|
|
611
618
|
rigRoot: HTMLElement;
|
|
619
|
+
rigPresentation?: JobRigPresentation;
|
|
612
620
|
inspection: PartInspection | null;
|
|
613
|
-
setupPose(): void;
|
|
621
|
+
setupPose(setup?: boolean): void;
|
|
614
622
|
dispose(): void;
|
|
615
623
|
}
|
|
616
624
|
async function jobBytes(url: string, signal: AbortSignal, maximum: number): Promise<Uint8Array<ArrayBuffer>> {
|
|
@@ -689,12 +697,19 @@ export async function prepareJobInspection(display: JobDisplayPublication, signa
|
|
|
689
697
|
let assets: ModelAssets | null = null;
|
|
690
698
|
let player: RigPlayer | null = null;
|
|
691
699
|
let inspection: PartInspection | null = null;
|
|
692
|
-
let resetToSetup = () => {};
|
|
700
|
+
let resetToSetup: (setup?: boolean) => void = () => {};
|
|
701
|
+
let rigPresentation: JobRigPresentation | undefined;
|
|
702
|
+
function clearRigPresentation(): void {
|
|
703
|
+
rigPresentation?.canvas.parentElement?.removeAttribute('data-job-rig-canonical');
|
|
704
|
+
rigPresentation?.canvas.remove();
|
|
705
|
+
rigPresentation = undefined;
|
|
706
|
+
}
|
|
693
707
|
let disposed = false;
|
|
694
708
|
const dispose = () => {
|
|
695
709
|
if (disposed)
|
|
696
710
|
return;
|
|
697
711
|
disposed = true;
|
|
712
|
+
clearRigPresentation();
|
|
698
713
|
for (const video of media) {
|
|
699
714
|
video.pause();
|
|
700
715
|
video.removeAttribute('src');
|
|
@@ -879,13 +894,17 @@ export async function prepareJobInspection(display: JobDisplayPublication, signa
|
|
|
879
894
|
const loadedAssets = assets;
|
|
880
895
|
const parts = await import('./part-selection.ts');
|
|
881
896
|
const catalog = await parts.loadPartModel(modelUrl, modelHash, metadata.feedbackCatalog.slots ?? [], checkedFetch);
|
|
882
|
-
resetToSetup = () => {
|
|
897
|
+
resetToSetup = (setup = true) => {
|
|
898
|
+
clearRigPresentation();
|
|
883
899
|
player?.dispose();
|
|
884
900
|
player = new runtime.RigPlayer(rigRoot, loadedAssets);
|
|
885
|
-
player.draw();
|
|
886
901
|
inspection = new parts.PartInspection();
|
|
887
902
|
inspection.register('single', catalog.entries, player);
|
|
888
|
-
|
|
903
|
+
if (setup) {
|
|
904
|
+
player.clear(0, {mix: 0});
|
|
905
|
+
player.draw();
|
|
906
|
+
inspection.present('single');
|
|
907
|
+
}
|
|
889
908
|
};
|
|
890
909
|
resetToSetup();
|
|
891
910
|
}
|
|
@@ -898,9 +917,14 @@ export async function prepareJobInspection(display: JobDisplayPublication, signa
|
|
|
898
917
|
references.sort((a, b) => order.indexOf(a.id) - order.indexOf(b.id));
|
|
899
918
|
return {
|
|
900
919
|
display, metadata, interview, parts, partImages, interviewImages, imageSetImages, references, assets, rigRoot,
|
|
920
|
+
get rigPresentation() { return rigPresentation; },
|
|
921
|
+
set rigPresentation(value) {
|
|
922
|
+
clearRigPresentation();
|
|
923
|
+
rigPresentation = value;
|
|
924
|
+
},
|
|
901
925
|
get player() { return player; },
|
|
902
926
|
get inspection() { return inspection; },
|
|
903
|
-
setupPose: () => resetToSetup(),
|
|
927
|
+
setupPose: (setup = true) => resetToSetup(setup),
|
|
904
928
|
dispose,
|
|
905
929
|
};
|
|
906
930
|
}
|
|
@@ -974,12 +998,15 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
974
998
|
read: () => JobUISubmission['value'];
|
|
975
999
|
submissionId: string;
|
|
976
1000
|
dirty: boolean;
|
|
1001
|
+
rigSubmission: ReturnType<typeof createJobRigSubmission>;
|
|
977
1002
|
};
|
|
978
1003
|
type PreparedWindow = JobPreparedInspection & {
|
|
979
1004
|
element: HTMLElement;
|
|
980
1005
|
forms: Map<string, JobForm>;
|
|
981
1006
|
};
|
|
982
1007
|
const forms = new Map<string, JobForm>();
|
|
1008
|
+
const drawn = new WeakMap<JobPreparedInspection, JobRigDraw>();
|
|
1009
|
+
let drawGeneration = 0;
|
|
983
1010
|
const viewportState = createViewportState();
|
|
984
1011
|
const el = <Element extends HTMLElement = HTMLElement>(id: string): Element => {
|
|
985
1012
|
const element = workspace.querySelector<HTMLElement>('#' + id);
|
|
@@ -1003,6 +1030,89 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1003
1030
|
fit.textContent = t(fit.textContent ?? 'Fit');
|
|
1004
1031
|
};
|
|
1005
1032
|
const viewport = createViewportController(provider, viewportState);
|
|
1033
|
+
const renderViewport = provider.render;
|
|
1034
|
+
provider.render = controller => {
|
|
1035
|
+
try {renderViewport(controller); rememberDraw();}
|
|
1036
|
+
catch (error) {
|
|
1037
|
+
if (current) {
|
|
1038
|
+
drawn.delete(current);
|
|
1039
|
+
current.rigPresentation = undefined;
|
|
1040
|
+
}
|
|
1041
|
+
throw error;
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
function rigDrawState(): JobRigDrawState {
|
|
1045
|
+
const owner = current, player = owner?.player;
|
|
1046
|
+
if (!owner || !player || !hubVisible) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
1047
|
+
const pane = el('rig-viewport'), root = owner.rigRoot, rect = pane.getBoundingClientRect();
|
|
1048
|
+
const ratio = globalThis.devicePixelRatio || 1;
|
|
1049
|
+
const frame = viewport.paneFrame('rig'), camera = viewport.numericView().cameras.rig;
|
|
1050
|
+
if (!frame || !camera || !pane.isConnected || !root.isConnected || el('rig-pane').hidden ||
|
|
1051
|
+
rect.width <= 0 || rect.height <= 0) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
1052
|
+
const style = getComputedStyle(root), paneStyle = getComputedStyle(pane);
|
|
1053
|
+
const plain = style.filter === 'none' && style.perspective === 'none' && style.opacity === '1' &&
|
|
1054
|
+
paneStyle.filter === 'none' && paneStyle.transform === 'none' && paneStyle.perspective === 'none' && paneStyle.opacity === '1';
|
|
1055
|
+
const presentation = owner.rigPresentation;
|
|
1056
|
+
const canvas = presentation?.canvas;
|
|
1057
|
+
const pixels = canvas?.getBoundingClientRect();
|
|
1058
|
+
const canvasStyle = canvas ? getComputedStyle(canvas) : null;
|
|
1059
|
+
if (canvas && (!canvas.isConnected || canvasStyle?.visibility !== 'visible' ||
|
|
1060
|
+
canvasStyle.display === 'none' || canvasStyle.opacity !== '1' || canvasStyle.filter !== 'none' ||
|
|
1061
|
+
canvasStyle.transform !== 'none')) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
1062
|
+
return {player, presentation, frameGeneration: owner.inspection?.frame('single')?.generation,
|
|
1063
|
+
source: {pageId, publicationId: owner.display.publication.publicationId,
|
|
1064
|
+
instanceKey: owner.display.publication.instanceKey, sourceHash: owner.display.publication.source.sourceHash},
|
|
1065
|
+
layout: JSON.stringify([
|
|
1066
|
+
pane.clientWidth, pane.clientHeight, rect.width, rect.height, ratio,
|
|
1067
|
+
root.getAttribute('style'), style.transform, camera, presentation?.area, presentation?.ratio,
|
|
1068
|
+
pixels ? jobRigPixelPlacement(rect, pixels, ratio) : null,
|
|
1069
|
+
pixels?.width, pixels?.height, canvas?.width, canvas?.height, canvas?.getAttribute('style'),
|
|
1070
|
+
]),
|
|
1071
|
+
defaultCamera: plain && camera.zoom === 1 && camera.center.x === frame.center.x && camera.center.y === frame.center.y,
|
|
1072
|
+
wholeRig: !selectedPart && !owner.inspection?.value() && player.slots === null,
|
|
1073
|
+
playing: false};
|
|
1074
|
+
}
|
|
1075
|
+
function rememberDraw(): void {
|
|
1076
|
+
const owner = current;
|
|
1077
|
+
if (!owner) return;
|
|
1078
|
+
try {
|
|
1079
|
+
const player = owner.player;
|
|
1080
|
+
const posed = owner.inspection?.frame('single');
|
|
1081
|
+
const camera = viewport.numericView().cameras.rig;
|
|
1082
|
+
if (!hubVisible || !player || !owner.assets || !posed || !camera) {
|
|
1083
|
+
throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
1084
|
+
}
|
|
1085
|
+
const renderer = player.renderer;
|
|
1086
|
+
const pane = el('rig-viewport');
|
|
1087
|
+
const presentation = presentJobRigViewport({pane, root: owner.rigRoot, images: true,
|
|
1088
|
+
canvas: renderer instanceof CanvasRenderer ? renderer.canvas : undefined,
|
|
1089
|
+
backend: renderer instanceof CanvasRenderer ? renderer.backendActive : renderer.meshBackendActive},
|
|
1090
|
+
{camera, posed, assets: owner.assets});
|
|
1091
|
+
pane.append(presentation.canvas);
|
|
1092
|
+
owner.rigPresentation = presentation;
|
|
1093
|
+
pane.dataset.jobRigCanonical = '';
|
|
1094
|
+
drawn.set(owner, recordJobRigDraw(rigDrawState(), ++drawGeneration));
|
|
1095
|
+
} catch {
|
|
1096
|
+
drawn.delete(owner);
|
|
1097
|
+
owner.rigPresentation = undefined;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
function drawInspection(owner: JobPreparedInspection): void {
|
|
1101
|
+
drawn.delete(owner);
|
|
1102
|
+
owner.rigPresentation = undefined;
|
|
1103
|
+
owner.player?.draw();
|
|
1104
|
+
owner.inspection?.present('single');
|
|
1105
|
+
}
|
|
1106
|
+
function copyRigVerdict(ask: JobPendingAsk, owner: JobPreparedInspection) {
|
|
1107
|
+
if (owner !== current || ask.publicationId !== owner.display.publication.publicationId) {
|
|
1108
|
+
throw new Error('JOB_STILL_BINDING_MISMATCH');
|
|
1109
|
+
}
|
|
1110
|
+
assertJobAskSource(ask, owner.display);
|
|
1111
|
+
return freezeJobRigCapture(drawn.get(owner), rigDrawState(), ask.askId, () => {
|
|
1112
|
+
if (!owner.rigPresentation) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
1113
|
+
return copyJobRigViewport(owner.rigPresentation);
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1006
1116
|
const referenceSelection = createJobReferenceSelection<JobReferenceView>({
|
|
1007
1117
|
current: () => ({owner: current, time}),
|
|
1008
1118
|
present(value) {
|
|
@@ -1225,7 +1335,8 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1225
1335
|
const status = node('p');
|
|
1226
1336
|
status.setAttribute('role', 'status');
|
|
1227
1337
|
form.append(status);
|
|
1228
|
-
const entry = { form, fieldset: fields, read, submissionId: crypto.randomUUID(), dirty: false
|
|
1338
|
+
const entry: JobForm = { form, fieldset: fields, read, submissionId: crypto.randomUUID(), dirty: false,
|
|
1339
|
+
rigSubmission: createJobRigSubmission() };
|
|
1229
1340
|
try {
|
|
1230
1341
|
const saved = JSON.parse(localStorage.getItem(localDraftKey(prepared.display)) ?? 'null');
|
|
1231
1342
|
if (saved?.publicationId === prepared.display.publication.publicationId &&
|
|
@@ -1248,25 +1359,36 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1248
1359
|
}
|
|
1249
1360
|
}
|
|
1250
1361
|
catch { /* Invalid or unavailable local drafts grant no submission authority. */ }
|
|
1251
|
-
form.oninput = () => { entry.dirty = true; entry.submissionId = crypto.randomUUID(); saveDraft(); };
|
|
1362
|
+
form.oninput = () => { entry.dirty = true; entry.submissionId = crypto.randomUUID(); entry.rigSubmission.reset(); saveDraft(); };
|
|
1252
1363
|
form.onsubmit = async (event) => {
|
|
1253
1364
|
event.preventDefault();
|
|
1254
1365
|
const state = window.state();
|
|
1255
1366
|
const receipt = state.receipt;
|
|
1256
1367
|
if (!receipt || state.preparing || state.closed || !access.capability || !form.reportValidity())
|
|
1257
1368
|
return;
|
|
1258
|
-
fields.disabled = true;
|
|
1259
1369
|
try {
|
|
1260
|
-
const
|
|
1370
|
+
const input = { kind: subject.kind, publicationId: ask.publicationId,
|
|
1261
1371
|
askId: ask.askId, pageId, displayedNonce: receipt.displayedNonce,
|
|
1262
|
-
expectedGeneration: state.generation, submissionId: entry.submissionId, value: read() } as JobUISubmission
|
|
1372
|
+
expectedGeneration: state.generation, submissionId: entry.submissionId, value: read() } as JobUISubmission;
|
|
1373
|
+
const activeAsk = state.pending.find(item => item.askId === ask.askId);
|
|
1374
|
+
if (!activeAsk) throw new Error('JOB_ASK_INVALID');
|
|
1375
|
+
const pending = subject.kind === 'review-verdict' && subject.stage === 'rig-review'
|
|
1376
|
+
? entry.rigSubmission.prepare(input, () => copyRigVerdict(activeAsk, prepared)) : Promise.resolve(input);
|
|
1377
|
+
fields.disabled = true;
|
|
1378
|
+
const frozen = await pending;
|
|
1379
|
+
if (entry.submissionId !== frozen.submissionId) throw new Error('JOB_STILL_BINDING_MISMATCH');
|
|
1380
|
+
const result = await window.submit(frozen);
|
|
1263
1381
|
if (!result.ok)
|
|
1264
1382
|
throw new Error(result.error.code);
|
|
1265
1383
|
entry.dirty = false;
|
|
1384
|
+
entry.rigSubmission.reset();
|
|
1385
|
+
status.dataset.jobText = 'job.saved';
|
|
1266
1386
|
status.textContent = t('job.saved');
|
|
1267
1387
|
saveDraft();
|
|
1268
1388
|
}
|
|
1269
1389
|
catch (error) {
|
|
1390
|
+
status.dataset.jobText = error instanceof Error && Object.hasOwn(enCatalog, error.message) && Object.hasOwn(koCatalog, error.message)
|
|
1391
|
+
? error.message : 'JOB_ACT_INVALID';
|
|
1270
1392
|
status.textContent = jobWindowRefusal(error, 'JOB_ACT_INVALID');
|
|
1271
1393
|
fields.disabled = false;
|
|
1272
1394
|
}
|
|
@@ -1506,7 +1628,10 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1506
1628
|
function selectPart(): void {
|
|
1507
1629
|
if (!current?.inspection)
|
|
1508
1630
|
return;
|
|
1631
|
+
drawn.delete(current);
|
|
1632
|
+
current.rigPresentation = undefined;
|
|
1509
1633
|
current.inspection.select(selectedPart ? { side: 'single', slot: selectedPart, mode: partMode } : null);
|
|
1634
|
+
rememberDraw();
|
|
1510
1635
|
setText('job-part-observation', selectedPart ? JSON.stringify(current.inspection.observation(), null, 2) : '');
|
|
1511
1636
|
viewport.renderCameraControls();
|
|
1512
1637
|
}
|
|
@@ -1536,14 +1661,17 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1536
1661
|
return;
|
|
1537
1662
|
}
|
|
1538
1663
|
if (!animation && current.player?.current) current.setupPose();
|
|
1664
|
+
// Setup uses an empty composed track. Animation seek needs a fresh single track.
|
|
1665
|
+
if (animation && current.player?.composed) current.setupPose(false);
|
|
1539
1666
|
if (current.player) {
|
|
1667
|
+
drawn.delete(current);
|
|
1668
|
+
current.rigPresentation = undefined;
|
|
1540
1669
|
if (animation && current.player.current !== animation)
|
|
1541
1670
|
current.player.play(animation, { loop: true });
|
|
1542
1671
|
if (animation)
|
|
1543
1672
|
current.player.seek(time);
|
|
1544
1673
|
current.player.pause();
|
|
1545
|
-
current
|
|
1546
|
-
current.inspection?.present('single');
|
|
1674
|
+
drawInspection(current);
|
|
1547
1675
|
current.inspection?.select(selectedPart ? { side: 'single', slot: selectedPart, mode: partMode } : null);
|
|
1548
1676
|
setText('job-part-observation', selectedPart ? JSON.stringify(current.inspection?.observation(), null, 2) : '');
|
|
1549
1677
|
}
|
|
@@ -1690,8 +1818,8 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1690
1818
|
}
|
|
1691
1819
|
await reference()?.seek(time, signal);
|
|
1692
1820
|
if (prepared.player) {
|
|
1693
|
-
prepared
|
|
1694
|
-
|
|
1821
|
+
drawInspection(prepared);
|
|
1822
|
+
rememberDraw();
|
|
1695
1823
|
}
|
|
1696
1824
|
await new Promise<void>(resolve => requestAnimationFrame(() => requestAnimationFrame(() => resolve())));
|
|
1697
1825
|
if (signal.aborted)
|
|
@@ -1757,14 +1885,31 @@ export async function mountJobSession(host: HTMLElement): Promise<() => void> {
|
|
|
1757
1885
|
i18n.setLinkLanguage(null); i18n.setLanguagePreference(event.data.language);
|
|
1758
1886
|
}
|
|
1759
1887
|
pauseHiddenHubFrame();
|
|
1760
|
-
if (hubVisible)
|
|
1888
|
+
if (current && !hubVisible) {
|
|
1889
|
+
drawn.delete(current);
|
|
1890
|
+
current.rigPresentation = undefined;
|
|
1891
|
+
}
|
|
1892
|
+
if (hubVisible && current?.player) {drawInspection(current); rememberDraw();}
|
|
1761
1893
|
};
|
|
1762
1894
|
if (hubIncarnation) {globalThis.addEventListener('message', hubVisibility); announceHubFrame();}
|
|
1763
1895
|
events = startJobWindowEvents({access, signal: abort.signal, member: !!hubIncarnation,
|
|
1764
1896
|
event: event => window.event(event),
|
|
1765
1897
|
refused: error => {notice.textContent = jobWindowRefusal(error, 'JOB_STREAM_FAILED');},
|
|
1766
1898
|
});
|
|
1899
|
+
let resolution: MediaQueryList | undefined;
|
|
1900
|
+
const resolutionChanged = () => {
|
|
1901
|
+
resolution?.removeEventListener('change', resolutionChanged);
|
|
1902
|
+
resolution = globalThis.matchMedia(`(resolution:${globalThis.devicePixelRatio || 1}dppx)`);
|
|
1903
|
+
resolution.addEventListener('change', resolutionChanged);
|
|
1904
|
+
if (current) {
|
|
1905
|
+
drawn.delete(current);
|
|
1906
|
+
current.rigPresentation = undefined;
|
|
1907
|
+
viewport.fitCamera();
|
|
1908
|
+
}
|
|
1909
|
+
};
|
|
1910
|
+
resolutionChanged();
|
|
1767
1911
|
const stop = () => {
|
|
1912
|
+
resolution?.removeEventListener('change', resolutionChanged);
|
|
1768
1913
|
globalThis.removeEventListener('message', hubVisibility);
|
|
1769
1914
|
saveDraft();
|
|
1770
1915
|
referenceSelection.cancel();
|
package/web/parts.ts
CHANGED
|
@@ -546,8 +546,13 @@ function setupPartsComments():void {
|
|
|
546
546
|
if (typeof document !== 'undefined' && document.getElementById('parts-app')) void boot();
|
|
547
547
|
|
|
548
548
|
function renderCorrections():void {
|
|
549
|
+
const data = state.data;
|
|
550
|
+
if (!stageEmbedded && (!data || (!Object.hasOwn(data, 'draft') && !Object.hasOwn(data, 'draftUnavailable')))) {
|
|
551
|
+
document.getElementById('pv-corrections')?.remove();
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
549
554
|
let host=document.getElementById('pv-corrections');if(!host){host=document.createElement('section');host.id='pv-corrections';document.querySelector('.pv-toolbar')!.after(host);}
|
|
550
|
-
host.replaceChildren();const
|
|
555
|
+
host.replaceChildren();const item=data?.items[state.selected],mapping=data?.draft?.mappings.find(m=>m.part===item?.name);
|
|
551
556
|
const label=document.createElement('p');label.textContent=t(data?.draft&&!mapping?'STAGE_DRAFT_NO_MESH: this part has no mesh attachment; direct correction is unavailable.':data?.draft?.label??data?.draftUnavailable??'STAGE_DRAFT_UNAVAILABLE: no producer-compatible draft is supplied.');host.append(label);
|
|
552
557
|
if(!mapping||!data?.draft)return;
|
|
553
558
|
label.textContent+=` · ${mapping.part} · ${mapping.skin}/${mapping.slot}/${mapping.attachment} · v ${mapping.vertices} t ${mapping.triangles} · ${data.draft.buildId}`;
|
package/web/styles.css
CHANGED
|
@@ -462,3 +462,17 @@ body.job-window{display:grid;grid-template-rows:auto auto minmax(0,1fr);height:1
|
|
|
462
462
|
.job-window .job-part-images{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:6px}
|
|
463
463
|
.job-window .job-part-images img{width:100%;height:auto;background:var(--rv-media-bg)}
|
|
464
464
|
@media(max-width:780px){.job-window .job-inspection{grid-template-columns:160px minmax(0,1fr)}.job-window .job-stage #stage-layout{grid-template-columns:minmax(0,1fr);grid-template-rows:repeat(2,minmax(0,1fr))}}
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
.job-window #rig-viewport[data-job-rig-canonical] > #rig-root {
|
|
468
|
+
visibility: hidden;
|
|
469
|
+
}
|
|
470
|
+
.job-window #rig-viewport > .job-rig-presentation {
|
|
471
|
+
position: absolute;
|
|
472
|
+
z-index: 0;
|
|
473
|
+
visibility: visible;
|
|
474
|
+
pointer-events: none;
|
|
475
|
+
user-select: none;
|
|
476
|
+
transform: none;
|
|
477
|
+
opacity: 1;
|
|
478
|
+
}
|