@rig-c/review 2.13.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/docs/PARTS_VIEW.md +1 -1
- package/docs/REVIEW_PACKAGE.md +32 -91
- package/docs/STABILITY.md +27 -194
- package/docs/WORKFLOWS.md +0 -107
- package/package.json +1 -1
- package/skills/rig-review/SKILL.md +11 -25
- package/src/build.ts +2 -2
- package/src/direction-inspection.ts +6 -2
- package/src/front.ts +4 -193
- package/src/interview-scene.ts +3 -3
- package/src/job-act.ts +1 -35
- package/src/job-api.ts +27 -19
- package/src/job-cli.ts +3 -3
- package/src/job-contract.ts +14 -50
- package/src/job-front.ts +17 -44
- package/src/job-host.ts +1 -4
- package/src/job-session.ts +22 -10
- package/src/job-source.ts +3 -17
- package/src/job-store.ts +80 -6
- package/src/job-worker.ts +1 -47
- package/src/manifest.ts +23 -4
- package/src/open.ts +2 -3
- package/src/scene-inspection.ts +50 -0
- package/src/server.ts +1 -1
- package/web/catalog-en.ts +37 -27
- package/web/catalog-ko.ts +37 -27
- package/web/compare.css +0 -4
- package/web/direction-panel.ts +22 -6
- package/web/inspector-blocks.ts +8 -4
- package/web/job-rig-capture.ts +62 -12
- package/web/job-rig-screen.ts +75 -55
- package/web/job-session.ts +89 -1091
- package/web/main.ts +113 -56
- package/web/parts-viewport-provider.ts +8 -3
- package/web/retained-frame-stage.ts +7 -7
- package/web/rig-host.ts +5 -3
- package/web/rig-viewport-provider.ts +2 -0
- package/web/scene-plates.ts +57 -4
- package/web/styles.css +12 -82
- package/web/viewport-capture.ts +12 -2
- package/web/workspace-ui.ts +5 -6
- package/src/front-worker.ts +0 -2
- package/src/job-hub.ts +0 -304
- package/src/job-image-set.ts +0 -73
- package/web/job-hub.ts +0 -160
package/web/job-session.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {mountWorkspaceShell} from './workspace-ui.ts';
|
|
2
1
|
/** Live job window transactions. Every form remains bound to its displayed publication. */
|
|
3
2
|
import type {
|
|
4
3
|
ActV3,
|
|
@@ -24,11 +23,9 @@ import {koCatalog} from './catalog-ko.ts';
|
|
|
24
23
|
import {t,onLanguageChange} from './i18n.ts';
|
|
25
24
|
import type {InstanceAccess} from './instance-access.ts';
|
|
26
25
|
import {JOB_PLAN_TEXT_FIELDS, parseJobPlanTextProjection, type JobPlanTextProjection} from '../src/job-contract.ts';
|
|
27
|
-
import {
|
|
28
|
-
import {advancePlayback} from './playback-clock.ts';
|
|
29
|
-
import {createJobRigScreen, isJobRigScreen, type JobRigScreenPrepared} from './job-rig-screen.ts';
|
|
26
|
+
import {createJobRigScreen, type JobRigScreenPrepared} from './job-rig-screen.ts';
|
|
30
27
|
import type {JobRigPresentation} from './viewport-capture.ts';
|
|
31
|
-
import {labelledControl
|
|
28
|
+
import {labelledControl} from './view-controls.ts';
|
|
32
29
|
import {createInterviewForm,interviewPicksRecord,interviewRecords,interviewErrors,type InterviewDisplayQuestion} from './interview-panel.ts';
|
|
33
30
|
import {JOB_COMMENTS_ACT_SCHEMA, JOB_PANEL_COMPOSITION_SCHEMA, JOB_PARTS_VERDICT_ACT_SCHEMA, parsePanelComposition} from '../src/job-contract.ts';
|
|
34
31
|
import type {PartsIssue} from '../src/parts-comment.ts';
|
|
@@ -42,6 +39,17 @@ export function jobWindowRefusal(error: unknown, fallback = 'JOB_WINDOW_FAILED')
|
|
|
42
39
|
}
|
|
43
40
|
return t(fallback);
|
|
44
41
|
}
|
|
42
|
+
/** Submission copy and its diagnostic title share the existing catalog refusal registry. */
|
|
43
|
+
export function jobSubmissionRefusal(error: unknown): {code: string; text: string; title: string} {
|
|
44
|
+
const message = error instanceof Error ? error.message : error;
|
|
45
|
+
const code = typeof message === 'string' && /^JOB_[A-Z_]+$/.test(message) ? message : 'JOB_ACT_INVALID';
|
|
46
|
+
const key = 'job.submit.' + code;
|
|
47
|
+
const reason = Object.hasOwn(enCatalog, key) && Object.hasOwn(koCatalog, key) ? key : 'job.submit.refused';
|
|
48
|
+
const origin = error instanceof Error && typeof error.cause === 'string' ? error.cause : 'client: submission';
|
|
49
|
+
const title = code + ' · ' + origin;
|
|
50
|
+
if (code === 'JOB_BODY_LIMIT' || reason === 'job.submit.refused') console.warn(title);
|
|
51
|
+
return {code, title, text: t('Review was not submitted: {0}', [t(reason)])};
|
|
52
|
+
}
|
|
45
53
|
export interface JobWindowTransport {
|
|
46
54
|
readPublication(publicationId: string, signal?: AbortSignal): Promise<JobResult<DisplayPublicationV3>>;
|
|
47
55
|
acknowledge(input: {
|
|
@@ -82,13 +90,14 @@ export interface JobWindowState {
|
|
|
82
90
|
readonly preparing: boolean;
|
|
83
91
|
readonly closed: boolean;
|
|
84
92
|
readonly error: string | null;
|
|
93
|
+
readonly errorOrigin?: string;
|
|
85
94
|
readonly previousLabel: string | null;
|
|
86
95
|
readonly pending: readonly JobWindowAsk[];
|
|
87
96
|
readonly retainedDrafts: readonly JobRetainedDraft[];
|
|
88
97
|
}
|
|
89
98
|
function unwrap<Value>(result: JobResult<Value>): Value {
|
|
90
99
|
if (!result.ok)
|
|
91
|
-
throw new Error(result.error.code);
|
|
100
|
+
throw new Error(result.error.code, {cause: (result.error as {cause?: unknown}).cause});
|
|
92
101
|
return result.value;
|
|
93
102
|
}
|
|
94
103
|
function isRecordSource(source: SourceV3): source is RecordSource {
|
|
@@ -191,6 +200,7 @@ export function createJobWindow<Prepared>(options: {
|
|
|
191
200
|
let preparing = false;
|
|
192
201
|
let closed = false;
|
|
193
202
|
let error: string | null;
|
|
203
|
+
let errorOrigin: string | undefined;
|
|
194
204
|
error = null;
|
|
195
205
|
let previousLabel: string | null = null;
|
|
196
206
|
let intent = 0;
|
|
@@ -199,7 +209,7 @@ export function createJobWindow<Prepared>(options: {
|
|
|
199
209
|
let queue = Promise.resolve();
|
|
200
210
|
function state(): JobWindowState {
|
|
201
211
|
return {
|
|
202
|
-
generation, displayed, receipt, preparing, closed, error, previousLabel,
|
|
212
|
+
generation, displayed, receipt, preparing, closed, error, previousLabel, ...(errorOrigin ? {errorOrigin} : {}),
|
|
203
213
|
pending: [...pending.values()], retainedDrafts: [...retainedDrafts],
|
|
204
214
|
};
|
|
205
215
|
}
|
|
@@ -213,6 +223,7 @@ export function createJobWindow<Prepared>(options: {
|
|
|
213
223
|
controller = abort;
|
|
214
224
|
preparing = true;
|
|
215
225
|
error = null;
|
|
226
|
+
errorOrigin = undefined;
|
|
216
227
|
changed();
|
|
217
228
|
queue = queue.then(async () => {
|
|
218
229
|
if (revision !== intent || stopped)
|
|
@@ -220,7 +231,8 @@ export function createJobWindow<Prepared>(options: {
|
|
|
220
231
|
let prepared: Prepared | undefined;
|
|
221
232
|
let committed: JobPreparedCommit | undefined;
|
|
222
233
|
try {
|
|
223
|
-
if (publication.visual.status !== 'available' && !isRecordSource(publication.source)
|
|
234
|
+
if (publication.visual.status !== 'available' && !isRecordSource(publication.source) &&
|
|
235
|
+
(publication.source.model||publication.source.parts))
|
|
224
236
|
throw new Error(publication.visual.code);
|
|
225
237
|
const candidate = unwrap(await transport.readPublication(publication.publicationId, abort.signal));
|
|
226
238
|
if (candidate.publication.publicationId !== publication.publicationId ||
|
|
@@ -299,8 +311,10 @@ export function createJobWindow<Prepared>(options: {
|
|
|
299
311
|
}
|
|
300
312
|
}
|
|
301
313
|
catch (failure) {
|
|
302
|
-
if (revision === intent && !stopped)
|
|
314
|
+
if (revision === intent && !stopped) {
|
|
303
315
|
error = failure instanceof Error ? failure.message : 'JOB_DISPLAY_MISMATCH';
|
|
316
|
+
errorOrigin = failure instanceof Error && typeof failure.cause === 'string' ? failure.cause : undefined;
|
|
317
|
+
}
|
|
304
318
|
}
|
|
305
319
|
finally {
|
|
306
320
|
await committed?.rollback();
|
|
@@ -362,41 +376,8 @@ export function createJobWindow<Prepared>(options: {
|
|
|
362
376
|
}
|
|
363
377
|
return result;
|
|
364
378
|
}
|
|
365
|
-
async function submitParts(input: UISubmissionV3, signoffSubmissionId: string): Promise<JobResult<ActV3>> {
|
|
366
|
-
const publicationId = input.publicationId;
|
|
367
|
-
const ask = pending.get(input.askId);
|
|
368
|
-
if (!displayed || displayed.publication.publicationId !== publicationId || !ask ||
|
|
369
|
-
ask.subject.kind !== 'parts-verdict') throw new Error('JOB_ACT_SOURCE_STALE');
|
|
370
|
-
assertJobAskSource(ask, displayed);
|
|
371
|
-
const previous = ask.act;
|
|
372
|
-
// An act@6 verdict's note is its one general comment; the signoff resends it.
|
|
373
|
-
const value = (previous?.kind !== 'parts-verdict' ? input.value : previous.schema !== JOB_COMMENTS_ACT_SCHEMA ? previous.value :
|
|
374
|
-
{verdict: previous.value.verdict, words: previous.value.comments.find(comment => !comment.anchor)?.text ?? ''}) as Pick<PartsVerdictValue, 'verdict' | 'words'>;
|
|
375
|
-
const signoff = [...pending.values()].find(item => item.publicationId === publicationId &&
|
|
376
|
-
item.subject.kind === 'signoff' && item.subject.stage === 'parts-review' && item.status === 'pending');
|
|
377
|
-
if (value.verdict === 'approved' && !signoff) throw new Error('JOB_PARTS_SIGNOFF_MISSING');
|
|
378
|
-
let result: JobResult<ActV3>;
|
|
379
|
-
if (ask.status === 'pending') {
|
|
380
|
-
result = await submit(input);
|
|
381
|
-
if (!result.ok) return result;
|
|
382
|
-
} else {
|
|
383
|
-
if (!previous || previous.kind !== 'parts-verdict' || (previous.schema !== JOB_PARTS_VERDICT_ACT_SCHEMA && previous.schema !== JOB_COMMENTS_ACT_SCHEMA) ||
|
|
384
|
-
value.verdict !== 'approved') throw new Error('JOB_ACT_SOURCE_STALE');
|
|
385
|
-
result = {ok: true, value: previous};
|
|
386
|
-
}
|
|
387
|
-
if (value.verdict !== 'approved') return result;
|
|
388
|
-
// Recheck after the first durable write. A replacement never inherits this signoff.
|
|
389
|
-
const latest = state();
|
|
390
|
-
if (latest.displayed?.publication.publicationId !== publicationId || !latest.receipt || !signoff)
|
|
391
|
-
throw new Error('JOB_ACT_SOURCE_STALE');
|
|
392
|
-
assertJobAskSource(signoff, latest.displayed);
|
|
393
|
-
return submit({kind: 'signoff', publicationId, pageId: input.pageId, askId: signoff.askId,
|
|
394
|
-
expectedGeneration: latest.generation, displayedNonce: latest.receipt.displayedNonce,
|
|
395
|
-
submissionId: signoffSubmissionId,
|
|
396
|
-
value: {stage: 'parts-review', decision: 'approved', words: value.words}});
|
|
397
|
-
}
|
|
398
379
|
return {
|
|
399
|
-
event, replace, submit,
|
|
380
|
+
event, replace, submit, state, refresh: changed,
|
|
400
381
|
settled: () => queue,
|
|
401
382
|
stop() { stopped = true; ++intent; controller?.abort(); },
|
|
402
383
|
};
|
|
@@ -518,6 +499,8 @@ export function createJobWindowTransport(access: JobWindowAccess, fetcher: typeo
|
|
|
518
499
|
throw new Error('JOB_REQUEST_INVALID');
|
|
519
500
|
if (!response.ok && value.ok)
|
|
520
501
|
throw new Error('JOB_REQUEST_INVALID');
|
|
502
|
+
if (!value.ok) Object.defineProperty(value.error, 'cause', {value:
|
|
503
|
+
`${init?.method ?? 'GET'} ${new URL(access.route(path), 'http://127.0.0.1').pathname} · ${typeof init?.body === 'string' ? new TextEncoder().encode(init.body).byteLength : 0} bytes · HTTP ${response.status}`});
|
|
521
504
|
return value;
|
|
522
505
|
}
|
|
523
506
|
function post<Value>(path: string, body: unknown, signal?: AbortSignal) {
|
|
@@ -552,18 +535,55 @@ export async function* jobWindowEvents(access: JobWindowAccess, after: string |
|
|
|
552
535
|
let newline = buffered.indexOf('\n');
|
|
553
536
|
while (newline >= 0) {
|
|
554
537
|
if (newline > limit)
|
|
555
|
-
throw new Error('JOB_BODY_LIMIT');
|
|
538
|
+
throw new Error('JOB_BODY_LIMIT', {cause: 'client: event stream'});
|
|
556
539
|
const event = JSON.parse(buffered.slice(0, newline)) as EventV3;
|
|
557
540
|
if (!event || event.jobId !== access.jobId || typeof event.cursor !== 'string' ||
|
|
558
541
|
!Number.isSafeInteger(event.generation) || event.generation < 0 ||
|
|
559
542
|
!['published', 'pending', 'act', 'closed'].includes(event.type))
|
|
560
543
|
throw new Error('JOB_STREAM_FAILED');
|
|
561
544
|
buffered = buffered.slice(newline + 1);
|
|
545
|
+
const crops = new Map<string, {owner: Record<string, unknown>; key: string}[]>();
|
|
546
|
+
const packed = event as EventV3 & {_jobCommentCrops?: [string[], string][]};
|
|
547
|
+
for (const [path, sha256] of packed._jobCommentCrops ?? []) {
|
|
548
|
+
if (!Array.isArray(path) || !path.every(key => typeof key === 'string') || path.at(-1) !== 'png' ||
|
|
549
|
+
typeof sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(sha256)) throw new Error('JOB_STREAM_FAILED');
|
|
550
|
+
let owner: any = event;
|
|
551
|
+
for (const key of path.slice(0, -1)) {
|
|
552
|
+
if (!owner || typeof owner !== 'object' || !Object.hasOwn(owner, key)) throw new Error('JOB_STREAM_FAILED');
|
|
553
|
+
owner = owner[key];
|
|
554
|
+
}
|
|
555
|
+
if (owner?.png !== 'job-crop:' + sha256 || owner.sha256 !== sha256 ||
|
|
556
|
+
owner.path !== `comment-crops/${sha256}.png`) throw new Error('JOB_STREAM_FAILED');
|
|
557
|
+
const reference = 'job-crop:' + sha256, refs = crops.get(reference) ?? [];
|
|
558
|
+
refs.push({owner, key: 'png'}); crops.set(reference, refs);
|
|
559
|
+
}
|
|
560
|
+
delete packed._jobCommentCrops;
|
|
561
|
+
for (const [reference, refs] of crops) {
|
|
562
|
+
try {
|
|
563
|
+
const crop = await fetcher(access.route('comment-crops/' + reference.slice(9) + '.png'),
|
|
564
|
+
{signal: AbortSignal.any([signal, AbortSignal.timeout(5000)]), headers: access.headers()});
|
|
565
|
+
if (!crop.ok) throw new Error('JOB_STREAM_FAILED');
|
|
566
|
+
const bytes = new Uint8Array(await crop.arrayBuffer());
|
|
567
|
+
const digest = Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256', bytes)),
|
|
568
|
+
byte => byte.toString(16).padStart(2, '0')).join('');
|
|
569
|
+
if (digest !== reference.slice(9)) throw new Error('JOB_STREAM_FAILED');
|
|
570
|
+
let binary = '';
|
|
571
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
572
|
+
for (const ref of refs) ref.owner[ref.key] = 'data:image/png;base64,' + btoa(binary);
|
|
573
|
+
} catch {
|
|
574
|
+
if (signal.aborted) return;
|
|
575
|
+
// A missing image is local presentation state, never a reason to replay an immutable act forever.
|
|
576
|
+
for (const ref of refs) {
|
|
577
|
+
ref.owner[ref.key] = null;
|
|
578
|
+
ref.owner.unavailable = 'COMMENT_CROP_STATE_UNAVAILABLE: stored crop cannot be read';
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
562
582
|
yield event;
|
|
563
583
|
newline = buffered.indexOf('\n');
|
|
564
584
|
}
|
|
565
585
|
if (buffered.length > limit)
|
|
566
|
-
throw new Error('JOB_BODY_LIMIT');
|
|
586
|
+
throw new Error('JOB_BODY_LIMIT', {cause: 'client: event stream'});
|
|
567
587
|
}
|
|
568
588
|
}
|
|
569
589
|
finally {
|
|
@@ -571,25 +591,17 @@ export async function* jobWindowEvents(access: JobWindowAccess, after: string |
|
|
|
571
591
|
reader.releaseLock();
|
|
572
592
|
}
|
|
573
593
|
}
|
|
574
|
-
/** One reader per window
|
|
594
|
+
/** One persistent reader per window, resumed from the last delivered cursor. */
|
|
575
595
|
export function startJobWindowEvents(options: {
|
|
576
596
|
access: JobWindowAccess;
|
|
577
597
|
signal: AbortSignal;
|
|
578
|
-
member: boolean;
|
|
579
598
|
event(value: EventV3): void;
|
|
580
599
|
refused(error: unknown): void;
|
|
581
600
|
fetcher?: typeof fetch;
|
|
582
601
|
}) {
|
|
583
|
-
let bootstrap = options.member;
|
|
584
|
-
let visible = !options.member;
|
|
585
602
|
let cursor: string | null = null;
|
|
586
603
|
let reader: AbortController | null = null;
|
|
587
604
|
let wake: (() => void) | null = null;
|
|
588
|
-
const enabled = () => bootstrap || visible;
|
|
589
|
-
function changed() {
|
|
590
|
-
if (!enabled()) reader?.abort();
|
|
591
|
-
wake?.();
|
|
592
|
-
}
|
|
593
605
|
const stopped = () => { reader?.abort(); wake?.(); };
|
|
594
606
|
options.signal.addEventListener('abort', stopped, {once: true});
|
|
595
607
|
function wait(milliseconds?: number): Promise<void> {
|
|
@@ -603,7 +615,6 @@ export function startJobWindowEvents(options: {
|
|
|
603
615
|
const done = (async () => {
|
|
604
616
|
try {
|
|
605
617
|
while (!options.signal.aborted) {
|
|
606
|
-
if (!enabled()) { await wait(); continue; }
|
|
607
618
|
const current = new AbortController();
|
|
608
619
|
reader = current;
|
|
609
620
|
try {
|
|
@@ -616,14 +627,12 @@ export function startJobWindowEvents(options: {
|
|
|
616
627
|
} catch (error) {
|
|
617
628
|
if (!current.signal.aborted && !options.signal.aborted) options.refused(error);
|
|
618
629
|
} finally { reader = null; }
|
|
619
|
-
if (!options.signal.aborted &&
|
|
630
|
+
if (!options.signal.aborted && !current.signal.aborted) await wait(500);
|
|
620
631
|
}
|
|
621
632
|
} finally { options.signal.removeEventListener('abort', stopped); }
|
|
622
633
|
})();
|
|
623
634
|
return {
|
|
624
635
|
done,
|
|
625
|
-
visibility(value: boolean) { if (options.member) { bootstrap = false; visible = value; changed(); } },
|
|
626
|
-
displayed() { if (options.member) { bootstrap = false; changed(); } },
|
|
627
636
|
};
|
|
628
637
|
}
|
|
629
638
|
import type { ModelAssets, RigPlayer } from '@rig-c/play';
|
|
@@ -703,8 +712,7 @@ interface JobReferenceView {
|
|
|
703
712
|
export function resolveJobPanels(metadata: JobInspectionMetadataV3, source: SourceV3) {
|
|
704
713
|
const parts: JobPanelComposition = {schema: JOB_PANEL_COMPOSITION_SCHEMA, left: ['parts.list'],
|
|
705
714
|
stage: ['parts.canvas'], toolbar: ['parts.layers'], side: ['parts.issues', 'act.submit']};
|
|
706
|
-
const stage: PanelComponent = source.subject === '
|
|
707
|
-
isRecordSource(source) ? source.subject === 'plan' ? 'plan.body' : 'interview.picks' :
|
|
715
|
+
const stage: PanelComponent = isRecordSource(source) ? source.subject === 'plan' ? 'plan.body' : 'interview.picks' :
|
|
708
716
|
source.direction ? 'scene.composite' : 'rig.playback';
|
|
709
717
|
const fallback: JobPanelComposition = metadata.capabilities.preRig ? parts :
|
|
710
718
|
{schema: JOB_PANEL_COMPOSITION_SCHEMA, stage: [stage], side: ['act.submit']};
|
|
@@ -785,7 +793,6 @@ export interface JobPreparedInspection {
|
|
|
785
793
|
partImages: Map<string, HTMLImageElement>;
|
|
786
794
|
partPages?: Map<number, HTMLImageElement>;
|
|
787
795
|
interviewImages: Map<string, HTMLImageElement>;
|
|
788
|
-
imageSetImages?: readonly HTMLImageElement[];
|
|
789
796
|
checkpointEvidence?: readonly {
|
|
790
797
|
packet: JobCheckpointEvidence;
|
|
791
798
|
table: JobCheckpointTable;
|
|
@@ -814,7 +821,7 @@ async function jobBytes(url: string, signal: AbortSignal, maximum: number): Prom
|
|
|
814
821
|
break;
|
|
815
822
|
size += next.value.length;
|
|
816
823
|
if (size > maximum)
|
|
817
|
-
throw new Error('JOB_BODY_LIMIT');
|
|
824
|
+
throw new Error('JOB_BODY_LIMIT', {cause: 'client: preload'});
|
|
818
825
|
chunks.push(next.value);
|
|
819
826
|
}
|
|
820
827
|
}
|
|
@@ -838,7 +845,7 @@ async function jobJson<Value>(url: string, signal: AbortSignal): Promise<Value>
|
|
|
838
845
|
const bytes = await jobBytes(url, signal, 2 * 1024 * 1024);
|
|
839
846
|
return JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes)) as Value;
|
|
840
847
|
}
|
|
841
|
-
function mediaReady(media: HTMLVideoElement, name: 'loadeddata' | 'seeked', signal: AbortSignal): Promise<void> {
|
|
848
|
+
export function mediaReady(media: HTMLVideoElement, name: 'loadeddata' | 'seeked', signal: AbortSignal): Promise<void> {
|
|
842
849
|
return new Promise((resolve, reject) => {
|
|
843
850
|
const finish = (error?: Error) => {
|
|
844
851
|
clearTimeout(timer);
|
|
@@ -950,7 +957,7 @@ export async function prepareJobInspection(display: DisplayPublicationV3, signal
|
|
|
950
957
|
sourceSnapshot(interview.interview) !== sourceSnapshot(display.publication.interview)) {
|
|
951
958
|
throw new Error('JOB_DISPLAY_MISMATCH');
|
|
952
959
|
}
|
|
953
|
-
const parts = metadata.capabilities.preRig ? await jobJson<JobPartsInventory>(routes.api('stage-parts'), signal) : null;
|
|
960
|
+
const parts = metadata.capabilities.preRig && 'parts' in publishedSource && publishedSource.parts ? await jobJson<JobPartsInventory>(routes.api('stage-parts'), signal) : null;
|
|
954
961
|
if (metadata.sourceHash !== publishedSource.sourceHash || parts && parts.sourceHash !== publishedSource.sourceHash)
|
|
955
962
|
throw new Error('JOB_SOURCE_MISMATCH');
|
|
956
963
|
const references: JobReferenceView[] = [];
|
|
@@ -958,7 +965,6 @@ export async function prepareJobInspection(display: DisplayPublicationV3, signal
|
|
|
958
965
|
const interviewImages = new Map<string, HTMLImageElement>();
|
|
959
966
|
const partPages = new Map<number, HTMLImageElement>();
|
|
960
967
|
const preload: Promise<void>[] = [];
|
|
961
|
-
const imageSetImages: HTMLImageElement[] = [];
|
|
962
968
|
const source = display.publication.source;
|
|
963
969
|
const checkpointEvidence: NonNullable<JobPreparedInspection['checkpointEvidence']>[number][] = [];
|
|
964
970
|
if (Object.hasOwn(metadata, 'checkpointEvidence') !== Object.hasOwn(source, 'checkpointEvidence') ||
|
|
@@ -1002,20 +1008,6 @@ export async function prepareJobInspection(display: DisplayPublicationV3, signal
|
|
|
1002
1008
|
checkpointEvidence[index] = {packet, table, images};
|
|
1003
1009
|
})());
|
|
1004
1010
|
}
|
|
1005
|
-
if (source.subject === 'image-set') {
|
|
1006
|
-
if (metadata.sourceHash !== source.sourceHash || metadata.manifest?.model)
|
|
1007
|
-
throw new Error('JOB_DISPLAY_MISMATCH');
|
|
1008
|
-
const canonical = source.imageSet.images.map(({role, name, sha256}) => ({role, name, sha256}));
|
|
1009
|
-
if (source.imageSet.images.length < 2 || source.imageSet.images.length > 8 ||
|
|
1010
|
-
await jobDigest(new TextEncoder().encode(JSON.stringify(canonical))) !== source.imageSetDigest)
|
|
1011
|
-
throw new Error('JOB_SOURCE_MISMATCH');
|
|
1012
|
-
for (const [index, entry] of source.imageSet.images.entries()) {
|
|
1013
|
-
preload.push(image(routes.api('image-set/' + index), entry.sha256).then(element => {
|
|
1014
|
-
element.alt = entry.name;
|
|
1015
|
-
imageSetImages[index] = element;
|
|
1016
|
-
}));
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
1011
|
for (const reference of metadata.manifest?.references ?? []) {
|
|
1020
1012
|
if (reference.id === metadata.sourcePainting?.id) continue;
|
|
1021
1013
|
preload.push((async () => {
|
|
@@ -1171,7 +1163,7 @@ export async function prepareJobInspection(display: DisplayPublicationV3, signal
|
|
|
1171
1163
|
};
|
|
1172
1164
|
resetToSetup();
|
|
1173
1165
|
}
|
|
1174
|
-
if (!isRecordSource(source) && !player && !references.length && !partImages.size && !
|
|
1166
|
+
if (!formsOnly && !isRecordSource(source) && !player && !references.length && !partImages.size && !checkpointEvidence.length)
|
|
1175
1167
|
throw new Error('JOB_VISUAL_UNAVAILABLE');
|
|
1176
1168
|
if (signal.aborted)
|
|
1177
1169
|
throw new Error('JOB_PRELOAD_CANCELLED');
|
|
@@ -1179,7 +1171,7 @@ export async function prepareJobInspection(display: DisplayPublicationV3, signal
|
|
|
1179
1171
|
const order = [metadata.sourcePainting?.id, ...(metadata.manifest?.references.map(reference => reference.id) ?? [])];
|
|
1180
1172
|
references.sort((a, b) => order.indexOf(a.id) - order.indexOf(b.id));
|
|
1181
1173
|
return {
|
|
1182
|
-
display, metadata, interview, parts, partImages, partPages, interviewImages,
|
|
1174
|
+
display, metadata, interview, parts, partImages, partPages, interviewImages, checkpointEvidence, references, assets, rigRoot,
|
|
1183
1175
|
get rigPresentation() { return rigPresentation; },
|
|
1184
1176
|
set rigPresentation(value) {
|
|
1185
1177
|
clearRigPresentation();
|
|
@@ -1222,14 +1214,8 @@ export function createJobFormHelpers(node: JobFormNode, t: typeof import('./i18n
|
|
|
1222
1214
|
});
|
|
1223
1215
|
return select;
|
|
1224
1216
|
}
|
|
1225
|
-
function textArea(parent: HTMLElement, key: string, name = 'note'): HTMLTextAreaElement {
|
|
1226
|
-
const input = node('textarea');
|
|
1227
|
-
input.name = name;
|
|
1228
|
-
parent.append(inputLabel(key, input));
|
|
1229
|
-
return input;
|
|
1230
|
-
}
|
|
1231
1217
|
function imageGallery(images: readonly {name: string; sha256: string; element?: HTMLImageElement;
|
|
1232
|
-
role?: string; duplicate?: boolean}[], titleOnly = false): HTMLElement {
|
|
1218
|
+
role?: string; duplicate?: boolean}[], titleOnly = false, native = false): HTMLElement {
|
|
1233
1219
|
const gallery = node('section');
|
|
1234
1220
|
gallery.style.display = 'grid';
|
|
1235
1221
|
gallery.style.gridAutoFlow = 'column';
|
|
@@ -1238,6 +1224,7 @@ export function createJobFormHelpers(node: JobFormNode, t: typeof import('./i18n
|
|
|
1238
1224
|
gallery.style.overflow = 'auto';
|
|
1239
1225
|
gallery.style.minHeight = '0';
|
|
1240
1226
|
gallery.style.flex = '1';
|
|
1227
|
+
if(native){gallery.style.gridAutoColumns='max-content';gallery.style.overflow='visible';gallery.style.width='max-content';gallery.style.color='var(--rv-stage-fg)';}
|
|
1241
1228
|
for (const image of images) {
|
|
1242
1229
|
const element = image.element;
|
|
1243
1230
|
if (!element) throw new Error('JOB_VISUAL_UNAVAILABLE');
|
|
@@ -1247,20 +1234,21 @@ export function createJobFormHelpers(node: JobFormNode, t: typeof import('./i18n
|
|
|
1247
1234
|
figure.dataset.imageName = image.name;
|
|
1248
1235
|
const name = node('h3');
|
|
1249
1236
|
name.textContent = image.name;
|
|
1250
|
-
|
|
1237
|
+
name.setAttribute('translate', 'no');
|
|
1251
1238
|
name.style.overflowWrap = 'anywhere';
|
|
1252
1239
|
const role = image.role ? node('p', 'job.imageRole.' + image.role) : node('p');
|
|
1253
1240
|
const hash = node('code');
|
|
1254
1241
|
hash.className = 'job-source';
|
|
1255
1242
|
hash.style.display = 'block';
|
|
1256
1243
|
hash.style.overflowWrap = 'anywhere';
|
|
1257
|
-
if (titleOnly) hash.title = image.sha256;
|
|
1244
|
+
if (titleOnly || native) hash.title = image.sha256;
|
|
1258
1245
|
else hash.textContent = image.sha256;
|
|
1259
1246
|
element.style.width = '100%';
|
|
1260
1247
|
element.style.height = 'auto';
|
|
1261
1248
|
element.style.maxHeight = '70vh';
|
|
1262
1249
|
element.style.objectFit = 'contain';
|
|
1263
|
-
figure.
|
|
1250
|
+
if(native){element.style.width=element.naturalWidth+'px';element.style.maxHeight='none';figure.style.width=element.naturalWidth+'px';}
|
|
1251
|
+
if(native){figure.title=image.sha256;figure.append(name,element);}else figure.append(name, role, element, hash);
|
|
1264
1252
|
if (image.duplicate)
|
|
1265
1253
|
figure.append(node('p', 'job.identicalImages'));
|
|
1266
1254
|
gallery.append(figure);
|
|
@@ -1334,7 +1322,7 @@ export function createJobFormHelpers(node: JobFormNode, t: typeof import('./i18n
|
|
|
1334
1322
|
section.append(list);
|
|
1335
1323
|
return section;
|
|
1336
1324
|
}
|
|
1337
|
-
return {inputLabel, selectValues,
|
|
1325
|
+
return {inputLabel, selectValues, imageGallery, planTextList, planStepText};
|
|
1338
1326
|
}
|
|
1339
1327
|
|
|
1340
1328
|
/** The answer builder owns no page shell, transport or draft collection. */
|
|
@@ -1358,7 +1346,7 @@ export interface JobFormDependencies {
|
|
|
1358
1346
|
|
|
1359
1347
|
/** Build the existing answer form with explicit host dependencies. */
|
|
1360
1348
|
function formFor(ask: PendingAskV3, prepared: JobPreparedInspection, deps: JobFormDependencies): JobForm {
|
|
1361
|
-
const {node, translate: t, helpers: {
|
|
1349
|
+
const {node, translate: t, helpers: {selectValues, imageGallery, planTextList, planStepText, assertJobAskSource, jobCheckpointContext},
|
|
1362
1350
|
draftStorage, localDraftKey, saveDraft, window, access, pageId} = deps;
|
|
1363
1351
|
if (ask.publicationId !== prepared.display.publication.publicationId)
|
|
1364
1352
|
throw new Error('JOB_DISPLAY_MISMATCH');
|
|
@@ -1378,8 +1366,8 @@ export interface JobFormDependencies {
|
|
|
1378
1366
|
if (ask.subject.kind !== 'review-verdict') {source.title = ask.source.sourceHash; source.setAttribute('translate', 'no');}
|
|
1379
1367
|
fields.append(source);
|
|
1380
1368
|
const subject = ask.subject;
|
|
1369
|
+
if(subject.kind==='review-verdict')throw new Error('JOB_ACT_KIND_DISABLED');
|
|
1381
1370
|
const commentOnly = subject.kind === 'checkpoint' || subject.kind === 'signoff' || subject.kind === 'reopen';
|
|
1382
|
-
const note = commentOnly || subject.kind === 'interview-picks' ? null : textArea(fields, 'interview.note');
|
|
1383
1371
|
if(commentOnly)fields.append(node('p','job.commentsFromWorkspace'));
|
|
1384
1372
|
let retainedCommentWords='';
|
|
1385
1373
|
const commentWords=()=>form.commentWords?.()??retainedCommentWords;
|
|
@@ -1492,33 +1480,7 @@ export interface JobFormDependencies {
|
|
|
1492
1480
|
read = () => ({ checkpointId: subject.checkpointId, outcome: outcome.value as 'pass' | 'fail', words: commentWords() });
|
|
1493
1481
|
submitKey = 'job.saveCheckpoint';
|
|
1494
1482
|
}
|
|
1495
|
-
else if(subject.kind==='parts-verdict')throw new Error('
|
|
1496
|
-
else if (subject.kind === 'review-verdict' && (subject.stage === 'image-review' || subject.stage === 'direction-review')) {
|
|
1497
|
-
const verdict = selectValues(['pending', 'approved', 'changes-requested'], ['Pending', 'Approved', 'Changes requested']);
|
|
1498
|
-
verdict.name = 'verdict';
|
|
1499
|
-
fields.append(verdict);
|
|
1500
|
-
const stage = subject.stage;
|
|
1501
|
-
if (stage === 'image-review') {
|
|
1502
|
-
const source = ask.source;
|
|
1503
|
-
if (source.subject !== 'image-set') throw new Error('JOB_ACT_SOURCE_STALE');
|
|
1504
|
-
const imageNotes = source.imageSet.images.map((image, index) => {
|
|
1505
|
-
const group = node('fieldset');
|
|
1506
|
-
const name = node('legend');
|
|
1507
|
-
name.textContent = image.name;
|
|
1508
|
-
group.append(name);
|
|
1509
|
-
fields.append(group);
|
|
1510
|
-
return {name: image.name, input: textArea(group, 'job.imageNote', 'image-note-' + index)};
|
|
1511
|
-
});
|
|
1512
|
-
read = () => {
|
|
1513
|
-
const notes = imageNotes.filter(note => note.input.value !== '')
|
|
1514
|
-
.map(note => ({name: note.name, words: note.input.value}));
|
|
1515
|
-
return {stage, verdict: verdict.value as 'pending' | 'approved' | 'changes-requested', words: (note?.value ?? ''),
|
|
1516
|
-
...(notes.length ? {imageNotes: notes} : {})};
|
|
1517
|
-
};
|
|
1518
|
-
} else {
|
|
1519
|
-
read = () => ({ stage, verdict: verdict.value as 'pending' | 'approved' | 'changes-requested', words: (note?.value ?? '') });
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1483
|
+
else if(subject.kind==='parts-verdict')throw new Error('JOB_ACT_KIND_DISABLED');
|
|
1522
1484
|
else if (subject.kind === 'signoff') {
|
|
1523
1485
|
fields.title = subject.stage;
|
|
1524
1486
|
if (ask.source.plan) fields.append(planTextList(ask.source.plan, prepared.metadata.planText));
|
|
@@ -1710,7 +1672,7 @@ export async function mountJobScreen(host:HTMLElement):Promise<()=>void> {
|
|
|
1710
1672
|
const modalState=()=>{const prepared=rigScreen.mounted();return prepared?.record??prepared?.modals;};
|
|
1711
1673
|
const drafts=createJobFormDrafts({jobId:access.jobId,current:()=>modalState()?.inspection??null,forms:()=>modalState()?.forms??emptyForms,storage:()=>localStorage});
|
|
1712
1674
|
const transport=createJobWindowTransport(access);
|
|
1713
|
-
let
|
|
1675
|
+
let stopped=false;
|
|
1714
1676
|
const dependencies:JobFormDependencies={node,translate:t,helpers:{...helpers,assertJobAskSource,jobCheckpointContext},draftStorage:()=>localStorage,...drafts,access,pageId,
|
|
1715
1677
|
window:{state:()=>window.state(),submit:input=>window.submit(input)}};
|
|
1716
1678
|
const rigScreen=createJobRigScreen({host,pageId,access,translate:(key,values)=>i18n.t(key,values,'en'),refusal:jobWindowRefusal,formDependencies:dependencies,
|
|
@@ -1719,979 +1681,15 @@ export async function mountJobScreen(host:HTMLElement):Promise<()=>void> {
|
|
|
1719
1681
|
let bootstrapNotice:HTMLElement|null=null;
|
|
1720
1682
|
const report=(error:unknown,fallback?:string)=>{if(rigScreen.mounted()){rigScreen.report(error,fallback);return;}if(!bootstrapNotice){bootstrapNotice=node('p');bootstrapNotice.setAttribute('role','status');host.append(bootstrapNotice);}bootstrapNotice.textContent=jobWindowRefusal(error,fallback);};
|
|
1721
1683
|
const window=createJobWindow<JobRigScreenPrepared|null>({jobId:access.jobId,pageId,transport,adapter:{
|
|
1722
|
-
async prepare(display,signal){
|
|
1684
|
+
async prepare(display,signal){return rigScreen.prepare(display,signal);},
|
|
1723
1685
|
captureDraft(){drafts.saveDraft();const forms=modalState()?.forms;const dirty=forms?[...forms].filter(([,entry])=>entry.dirty):[];return dirty.length?dirty.map(([askId,entry])=>({askId,value:entry.read()})):null;},
|
|
1724
1686
|
commit:prepared=>prepared?rigScreen.commit(prepared):{rollback(){},finalize(){}},
|
|
1725
|
-
async painted(prepared,signal){if(
|
|
1687
|
+
async painted(prepared,signal){if(stopped||signal.aborted)return;if(prepared)await rigScreen.painted(prepared,signal);},
|
|
1726
1688
|
discard:prepared=>{const modal=prepared?.record??prepared?.modals;for(const entry of modal?.forms.values()??[])entry.dispose?.();modal?.inspection.dispose();},
|
|
1727
|
-
changed(state){rigScreen.changed(state);if(state.error&&(!rigScreen.mounted()||rigScreen.mounted()?.record))report(state.error);
|
|
1689
|
+
changed(state){rigScreen.changed(state);if(state.error&&(!rigScreen.mounted()||rigScreen.mounted()?.record))report(state.error);},
|
|
1728
1690
|
}});
|
|
1729
|
-
const hub=new URL(location.href).searchParams.get('hub');
|
|
1730
|
-
const binding=()=>({jobId:access.jobId,incarnation:hub!,publicationId:window.state().displayed?.publication.publicationId??null,sourceHash:window.state().displayed?.publication.source.sourceHash??null});
|
|
1731
|
-
const visibility=(event:MessageEvent)=>{if(!hub||!jobHubMessageMatches(event,location.origin,globalThis.parent,binding(),'visibility'))return;events?.visibility(event.data.visible);i18n.setLinkLanguage(null);i18n.setLanguagePreference(event.data.language);};
|
|
1732
|
-
if(hub)globalThis.addEventListener('message',visibility);
|
|
1733
1691
|
const localize=i18n.onLanguageChange(()=>{for(const element of host.querySelectorAll<HTMLElement>('[data-job-text]'))element.textContent=t(element.dataset.jobText!);for(const form of host.querySelectorAll('form.interview-answer'))form.dispatchEvent(new Event('job-form-language'));});
|
|
1734
|
-
|
|
1735
|
-
const stop=()=>{if(stopped)return;stopped=true;drafts.saveDraft();abort.abort();window.stop();const modal=modalState();for(const entry of modal?.forms.values()??[])entry.dispose?.();modal?.inspection.dispose();localize();
|
|
1692
|
+
startJobWindowEvents({access,signal:abort.signal,event:event=>window.event(event),refused:error=>report(error,'JOB_STREAM_FAILED')});
|
|
1693
|
+
const stop=()=>{if(stopped)return;stopped=true;drafts.saveDraft();abort.abort();window.stop();const modal=modalState();for(const entry of modal?.forms.values()??[])entry.dispose?.();modal?.inspection.dispose();localize();globalThis.removeEventListener('pagehide',stop);};
|
|
1736
1694
|
globalThis.addEventListener('pagehide',stop,{once:true});return stop;
|
|
1737
1695
|
}
|
|
1738
|
-
|
|
1739
|
-
/** Browser mount is explicit so importing transaction helpers never starts an app. */
|
|
1740
|
-
/** `inherited` keeps the capability the one-screen mount already took off the URL (it may live only in memory). */
|
|
1741
|
-
export async function mountJobSession(host: HTMLElement, legacy=false, inherited?: JobWindowAccess): Promise<() => void> {
|
|
1742
|
-
if(!legacy)return mountJobScreen(host);
|
|
1743
|
-
const [{ createViewportController, createViewportState }, { createRigViewportProvider }, { mountViewportPair }, i18n] = await Promise.all([
|
|
1744
|
-
import('./viewport-controller.ts'), import('./rig-viewport-provider.ts'),
|
|
1745
|
-
import('./viewport-pair.ts'), import('./i18n.ts'),
|
|
1746
|
-
]);
|
|
1747
|
-
let storage: Storage | null = null;
|
|
1748
|
-
try {
|
|
1749
|
-
storage = sessionStorage;
|
|
1750
|
-
}
|
|
1751
|
-
catch { /* Capability stays in memory. */ }
|
|
1752
|
-
const access = inherited ?? jobWindowAccess(location.href, storage, href => history.replaceState(history.state, '', href));
|
|
1753
|
-
const hubIncarnation = new URL(location.href).searchParams.get('hub');
|
|
1754
|
-
let hubVisible = !hubIncarnation;
|
|
1755
|
-
let events: ReturnType<typeof startJobWindowEvents> | undefined;
|
|
1756
|
-
const pageId = crypto.randomUUID();
|
|
1757
|
-
const transport = createJobWindowTransport(access);
|
|
1758
|
-
const abort = new AbortController();
|
|
1759
|
-
const language = new URL(location.href).searchParams.get('lang');
|
|
1760
|
-
if (language === 'en' || language === 'ko')
|
|
1761
|
-
i18n.setLanguagePreference(language);
|
|
1762
|
-
const t = i18n.t;
|
|
1763
|
-
const node = <Tag extends keyof HTMLElementTagNameMap>(tag: Tag, key?: string) => {
|
|
1764
|
-
const value = document.createElement(tag);
|
|
1765
|
-
if (key) {
|
|
1766
|
-
value.dataset.jobText = key;
|
|
1767
|
-
value.textContent = t(key);
|
|
1768
|
-
}
|
|
1769
|
-
return value;
|
|
1770
|
-
};
|
|
1771
|
-
const formHelpers = prepareJobForms.helpers(node, t);
|
|
1772
|
-
const {inputLabel, imageGallery} = formHelpers;
|
|
1773
|
-
const shell = mountWorkspaceShell({compatibility: 'legacyJobStep5', title: t('job.title')});
|
|
1774
|
-
const {header, title} = shell, languages = shell.language!;
|
|
1775
|
-
languages.value = i18n.getLanguage();
|
|
1776
|
-
languages.setAttribute('aria-label', t('interview.language'));
|
|
1777
|
-
languages.onchange = () => { i18n.setLinkLanguage(null); i18n.setLanguagePreference(languages.value === 'ko' ? 'ko' : 'en'); };
|
|
1778
|
-
const notice = node('p', 'job.waiting');
|
|
1779
|
-
notice.className = 'job-notice';
|
|
1780
|
-
notice.setAttribute('role', 'status');
|
|
1781
|
-
const workspace = node('main');
|
|
1782
|
-
host.classList.add('job-window');
|
|
1783
|
-
host.replaceChildren(header, notice, workspace);
|
|
1784
|
-
let current: JobPreparedInspection | null = null;
|
|
1785
|
-
let currentElement: HTMLElement | null = null;
|
|
1786
|
-
let view = 'compare';
|
|
1787
|
-
type SavedCameraState = Pick<
|
|
1788
|
-
ReturnType<typeof createViewportState>,
|
|
1789
|
-
'cameraSync' | 'activeCamera' | 'zoom' | 'cameraCenter' | 'referenceZoom' | 'referenceCenter'
|
|
1790
|
-
>;
|
|
1791
|
-
type SavedJobWindowState = {
|
|
1792
|
-
publicationId: string;
|
|
1793
|
-
label: string;
|
|
1794
|
-
sourceHash: string;
|
|
1795
|
-
previousLabel: string | null;
|
|
1796
|
-
compatibilityNotice?: boolean;
|
|
1797
|
-
animation?: string;
|
|
1798
|
-
time?: number;
|
|
1799
|
-
loop?: boolean;
|
|
1800
|
-
selectedReference?: string;
|
|
1801
|
-
panel?: string;
|
|
1802
|
-
camera?: unknown;
|
|
1803
|
-
};
|
|
1804
|
-
const parseSavedPoint = (raw: unknown): { x: number; y: number } | null | undefined => {
|
|
1805
|
-
if (raw === null) return null;
|
|
1806
|
-
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return undefined;
|
|
1807
|
-
const point = raw as Record<string, unknown>;
|
|
1808
|
-
return typeof point.x === 'number' && Number.isFinite(point.x) &&
|
|
1809
|
-
typeof point.y === 'number' && Number.isFinite(point.y)
|
|
1810
|
-
? { x: point.x, y: point.y }
|
|
1811
|
-
: undefined;
|
|
1812
|
-
};
|
|
1813
|
-
const parseSavedCamera = (raw: unknown): SavedCameraState | null => {
|
|
1814
|
-
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
|
|
1815
|
-
const value = raw as Record<string, unknown>;
|
|
1816
|
-
const cameraCenter = parseSavedPoint(value.cameraCenter);
|
|
1817
|
-
const referenceCenter = parseSavedPoint(value.referenceCenter);
|
|
1818
|
-
if (typeof value.cameraSync !== 'boolean' ||
|
|
1819
|
-
(value.activeCamera !== 'rig' && value.activeCamera !== 'reference') ||
|
|
1820
|
-
typeof value.zoom !== 'number' || !Number.isFinite(value.zoom) || value.zoom < 0.25 || value.zoom > 8 ||
|
|
1821
|
-
typeof value.referenceZoom !== 'number' || !Number.isFinite(value.referenceZoom) || value.referenceZoom < 0.25 || value.referenceZoom > 8 ||
|
|
1822
|
-
cameraCenter === undefined || referenceCenter === undefined) {
|
|
1823
|
-
return null;
|
|
1824
|
-
}
|
|
1825
|
-
return {
|
|
1826
|
-
cameraSync: value.cameraSync,
|
|
1827
|
-
activeCamera: value.activeCamera,
|
|
1828
|
-
zoom: value.zoom,
|
|
1829
|
-
cameraCenter,
|
|
1830
|
-
referenceZoom: value.referenceZoom,
|
|
1831
|
-
referenceCenter,
|
|
1832
|
-
};
|
|
1833
|
-
};
|
|
1834
|
-
const parseSavedDraftRecord = (raw: unknown): JobRetainedDraft | null => {
|
|
1835
|
-
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
|
|
1836
|
-
const draft = raw as Record<string, unknown>;
|
|
1837
|
-
if (!Array.isArray(draft.forms) || !draft.forms.length ||
|
|
1838
|
-
typeof draft.publicationId !== 'string' || !draft.publicationId ||
|
|
1839
|
-
typeof draft.sourceHash !== 'string' || !draft.sourceHash ||
|
|
1840
|
-
typeof draft.label !== 'string' || !draft.label ||
|
|
1841
|
-
!draft.source || typeof draft.source !== 'object' || Array.isArray(draft.source) ||
|
|
1842
|
-
(draft.source as { sourceHash?: unknown }).sourceHash !== draft.sourceHash) {
|
|
1843
|
-
return null;
|
|
1844
|
-
}
|
|
1845
|
-
const forms = draft.forms.filter((item: unknown): item is { askId: string; value: unknown } =>
|
|
1846
|
-
!!item && typeof item === 'object' && !Array.isArray(item) &&
|
|
1847
|
-
typeof (item as { askId?: unknown }).askId === 'string' && !!(item as { askId: string }).askId);
|
|
1848
|
-
if (!forms.length) return null;
|
|
1849
|
-
return {
|
|
1850
|
-
publicationId: draft.publicationId,
|
|
1851
|
-
sourceHash: draft.sourceHash,
|
|
1852
|
-
source: draft.source as SourceV3,
|
|
1853
|
-
label: draft.label,
|
|
1854
|
-
value: forms.map(item => ({ askId: item.askId, value: item.value })),
|
|
1855
|
-
};
|
|
1856
|
-
};
|
|
1857
|
-
const localWindowKey = 'rig-review-job-window/1:' + access.jobId;
|
|
1858
|
-
let savedWindow: SavedJobWindowState | null = null;
|
|
1859
|
-
try {
|
|
1860
|
-
const parsed = JSON.parse(localStorage.getItem(localWindowKey) ?? 'null');
|
|
1861
|
-
if (parsed && typeof parsed.publicationId === 'string' && typeof parsed.label === 'string' &&
|
|
1862
|
-
typeof parsed.sourceHash === 'string') {
|
|
1863
|
-
savedWindow = parsed as SavedJobWindowState;
|
|
1864
|
-
}
|
|
1865
|
-
}
|
|
1866
|
-
catch { /* Invalid saved window state falls back to defaults. */ }
|
|
1867
|
-
const initialRetainedDrafts: JobRetainedDraft[] = [];
|
|
1868
|
-
try {
|
|
1869
|
-
const draftPrefix = 'rig-review-job-draft/1:' + access.jobId + ':';
|
|
1870
|
-
for (let index = 0; index < localStorage.length; index++) {
|
|
1871
|
-
const key = localStorage.key(index);
|
|
1872
|
-
if (!key?.startsWith(draftPrefix)) continue;
|
|
1873
|
-
try {
|
|
1874
|
-
const parsedDraft = parseSavedDraftRecord(JSON.parse(localStorage.getItem(key) ?? 'null'));
|
|
1875
|
-
if (parsedDraft) initialRetainedDrafts.push(parsedDraft);
|
|
1876
|
-
}
|
|
1877
|
-
catch { /* Ignore malformed draft entries without dropping sibling drafts. */ }
|
|
1878
|
-
}
|
|
1879
|
-
}
|
|
1880
|
-
catch { /* In-memory standing state remains active when storage is unavailable. */ }
|
|
1881
|
-
const previousDisplayed = savedWindow ? {
|
|
1882
|
-
publicationId: savedWindow.publicationId,
|
|
1883
|
-
label: savedWindow.label,
|
|
1884
|
-
previousLabel: typeof savedWindow.previousLabel === 'string' ? savedWindow.previousLabel : null,
|
|
1885
|
-
} : null;
|
|
1886
|
-
let animation = typeof savedWindow?.animation === 'string' ? savedWindow.animation : '';
|
|
1887
|
-
let time = typeof savedWindow?.time === 'number' && Number.isFinite(savedWindow.time) && savedWindow.time >= 0
|
|
1888
|
-
? savedWindow.time : 0;
|
|
1889
|
-
let playing = false;
|
|
1890
|
-
let loop = typeof savedWindow?.loop === 'boolean' ? savedWindow.loop : true;
|
|
1891
|
-
let playbackCarry = 0;
|
|
1892
|
-
let rafHandle = 0;
|
|
1893
|
-
let lastFrameTime = 0;
|
|
1894
|
-
let inPlaybackStep = false;
|
|
1895
|
-
let lastRunningSaveMs: number | null = null;
|
|
1896
|
-
let lastSavedWindowJson: string | null = null;
|
|
1897
|
-
let selectedReference = typeof savedWindow?.selectedReference === 'string' ? savedWindow.selectedReference : '';
|
|
1898
|
-
let panel = typeof savedWindow?.panel === 'string' && ['1', '2', '3', '4'].includes(savedWindow.panel)
|
|
1899
|
-
? savedWindow.panel : '3';
|
|
1900
|
-
let restoredCamera: SavedCameraState | null = parseSavedCamera(savedWindow?.camera);
|
|
1901
|
-
let compatibilityNotice = Boolean(savedWindow?.compatibilityNotice);
|
|
1902
|
-
type PreparedWindow = JobPreparedInspection & {
|
|
1903
|
-
element: HTMLElement;
|
|
1904
|
-
forms: Map<string, JobForm>;
|
|
1905
|
-
};
|
|
1906
|
-
const forms = new Map<string, JobForm>();
|
|
1907
|
-
const viewportState = createViewportState();
|
|
1908
|
-
if (restoredCamera) {
|
|
1909
|
-
Object.assign(viewportState, restoredCamera, { cameraRestoring: false });
|
|
1910
|
-
}
|
|
1911
|
-
function saveWindowState(nowMs?: number): void {
|
|
1912
|
-
if (!current)
|
|
1913
|
-
return;
|
|
1914
|
-
if (inPlaybackStep && nowMs === undefined)
|
|
1915
|
-
return;
|
|
1916
|
-
const state = window.state();
|
|
1917
|
-
if (state.displayed?.publication.publicationId !== current.display.publication.publicationId)
|
|
1918
|
-
return;
|
|
1919
|
-
if (nowMs !== undefined) {
|
|
1920
|
-
if (lastRunningSaveMs === null) {
|
|
1921
|
-
lastRunningSaveMs = nowMs;
|
|
1922
|
-
return;
|
|
1923
|
-
}
|
|
1924
|
-
if (nowMs - lastRunningSaveMs < 1000)
|
|
1925
|
-
return;
|
|
1926
|
-
lastRunningSaveMs = nowMs;
|
|
1927
|
-
}
|
|
1928
|
-
try {
|
|
1929
|
-
const serialized = JSON.stringify({
|
|
1930
|
-
publicationId: current.display.publication.publicationId,
|
|
1931
|
-
label: current.display.publication.label,
|
|
1932
|
-
sourceHash: current.display.publication.source.sourceHash,
|
|
1933
|
-
previousLabel: state.previousLabel,
|
|
1934
|
-
compatibilityNotice,
|
|
1935
|
-
animation,
|
|
1936
|
-
time,
|
|
1937
|
-
loop,
|
|
1938
|
-
selectedReference,
|
|
1939
|
-
panel,
|
|
1940
|
-
camera: {
|
|
1941
|
-
cameraSync: viewportState.cameraSync,
|
|
1942
|
-
activeCamera: viewportState.activeCamera,
|
|
1943
|
-
zoom: viewportState.zoom,
|
|
1944
|
-
cameraCenter: viewportState.cameraCenter
|
|
1945
|
-
? { x: viewportState.cameraCenter.x, y: viewportState.cameraCenter.y } : null,
|
|
1946
|
-
referenceZoom: viewportState.referenceZoom,
|
|
1947
|
-
referenceCenter: viewportState.referenceCenter
|
|
1948
|
-
? { x: viewportState.referenceCenter.x, y: viewportState.referenceCenter.y } : null,
|
|
1949
|
-
},
|
|
1950
|
-
});
|
|
1951
|
-
if (serialized === lastSavedWindowJson)
|
|
1952
|
-
return;
|
|
1953
|
-
localStorage.setItem(localWindowKey, serialized);
|
|
1954
|
-
lastSavedWindowJson = serialized;
|
|
1955
|
-
}
|
|
1956
|
-
catch { /* Standing state stays in memory when storage is unavailable. */ }
|
|
1957
|
-
}
|
|
1958
|
-
const el = <Element extends HTMLElement = HTMLElement>(id: string): Element => {
|
|
1959
|
-
const element = workspace.querySelector<HTMLElement>('#' + id);
|
|
1960
|
-
if (!element)
|
|
1961
|
-
throw new Error('JOB_WINDOW_ELEMENT_MISSING');
|
|
1962
|
-
return element as Element;
|
|
1963
|
-
};
|
|
1964
|
-
const reference = () => current?.references.find(item => item.id === selectedReference) ?? null;
|
|
1965
|
-
const setText = (id: string, value: string) => { const element = workspace.querySelector('#' + id); if (element)
|
|
1966
|
-
element.textContent = i18n.tr(value); };
|
|
1967
|
-
const provider = createRigViewportProvider({
|
|
1968
|
-
el, player: () => current?.player ?? null, assets: () => current?.assets ?? null,
|
|
1969
|
-
referenceSize: () => reference(), view: () => view, referenceGeneration: () => current?.display.publication.generation ?? 0,
|
|
1970
|
-
parts: () => current?.inspection ?? null, text: setText, fitLabel: 'Fit',
|
|
1971
|
-
message: value => { notice.textContent = jobWindowRefusal(value); }, redrawOverlay: () => {},
|
|
1972
|
-
}, viewportState);
|
|
1973
|
-
const canonicalControls = provider.renderControls;
|
|
1974
|
-
provider.renderControls = controller => {
|
|
1975
|
-
canonicalControls(controller);
|
|
1976
|
-
const fit = el('fit');
|
|
1977
|
-
fit.textContent = t(fit.textContent ?? 'Fit');
|
|
1978
|
-
saveWindowState();
|
|
1979
|
-
};
|
|
1980
|
-
const viewport = createViewportController(provider, viewportState);
|
|
1981
|
-
function drawInspection(owner: JobPreparedInspection): void {
|
|
1982
|
-
owner.player?.draw();
|
|
1983
|
-
owner.inspection?.present('single');
|
|
1984
|
-
}
|
|
1985
|
-
function syncTransportControls(): void {
|
|
1986
|
-
const playBtn = workspace.querySelector<HTMLButtonElement>('#job-play');
|
|
1987
|
-
if (playBtn) {
|
|
1988
|
-
const clip = current?.assets?.animations.find(item => item.name === animation);
|
|
1989
|
-
playBtn.disabled = !animation || !clip || !(clip.duration > 0) || !current?.player;
|
|
1990
|
-
const key = playing ? 'Pause' : 'Play';
|
|
1991
|
-
playBtn.dataset.jobText = key;
|
|
1992
|
-
playBtn.textContent = t(key);
|
|
1993
|
-
playBtn.setAttribute('aria-pressed', String(playing));
|
|
1994
|
-
}
|
|
1995
|
-
const loopInput = workspace.querySelector<HTMLInputElement>('#job-loop');
|
|
1996
|
-
if (loopInput) loopInput.checked = loop;
|
|
1997
|
-
}
|
|
1998
|
-
function stopPlayback(targetPlayer = current?.player): void {
|
|
1999
|
-
if (rafHandle) {
|
|
2000
|
-
cancelAnimationFrame(rafHandle);
|
|
2001
|
-
rafHandle = 0;
|
|
2002
|
-
}
|
|
2003
|
-
playing = false;
|
|
2004
|
-
playbackCarry = 0;
|
|
2005
|
-
lastFrameTime = 0;
|
|
2006
|
-
lastRunningSaveMs = null;
|
|
2007
|
-
targetPlayer?.pause();
|
|
2008
|
-
syncTransportControls();
|
|
2009
|
-
saveWindowState();
|
|
2010
|
-
}
|
|
2011
|
-
function presentCurrentFrame(owner: JobPreparedInspection): void {
|
|
2012
|
-
if (!owner.player) return;
|
|
2013
|
-
drawInspection(owner);
|
|
2014
|
-
viewport.fitCamera();
|
|
2015
|
-
}
|
|
2016
|
-
function armPlayback(expectedOwner: JobPreparedInspection, expectedPlayer: RigPlayer): void {
|
|
2017
|
-
if (rafHandle) {
|
|
2018
|
-
cancelAnimationFrame(rafHandle);
|
|
2019
|
-
rafHandle = 0;
|
|
2020
|
-
}
|
|
2021
|
-
const handle = requestAnimationFrame(now => stepPlayback(handle, expectedOwner, expectedPlayer, now));
|
|
2022
|
-
rafHandle = handle;
|
|
2023
|
-
}
|
|
2024
|
-
function playbackTimeLabel(duration: number, trackTime: number): string {
|
|
2025
|
-
// A one-second 1/60 replay leaves six epsilons after modulo. Limit display snapping
|
|
2026
|
-
// to eight duration-scaled epsilons. The public time and captured frame stay raw.
|
|
2027
|
-
if (trackTime < duration) return String(time);
|
|
2028
|
-
const residue = 8 * Number.EPSILON * duration;
|
|
2029
|
-
if (time <= residue) return '0';
|
|
2030
|
-
if (duration - time <= residue) return String(duration);
|
|
2031
|
-
return String(time);
|
|
2032
|
-
}
|
|
2033
|
-
function stepPlayback(handle: number, expectedOwner: JobPreparedInspection, expectedPlayer: RigPlayer, now: number): void {
|
|
2034
|
-
if (current !== expectedOwner || current?.player !== expectedPlayer) {
|
|
2035
|
-
expectedPlayer.pause();
|
|
2036
|
-
return;
|
|
2037
|
-
}
|
|
2038
|
-
if (handle !== rafHandle) return;
|
|
2039
|
-
rafHandle = 0;
|
|
2040
|
-
const clip = expectedOwner.assets?.animations.find(item => item.name === animation);
|
|
2041
|
-
if (!playing || !hubVisible || !animation || !clip || !(clip.duration > 0)) {
|
|
2042
|
-
stopPlayback(expectedPlayer);
|
|
2043
|
-
return;
|
|
2044
|
-
}
|
|
2045
|
-
const dt = lastFrameTime > 0 ? Math.min(Math.max(0, (now - lastFrameTime) / 1000), 0.1) : 0;
|
|
2046
|
-
lastFrameTime = now;
|
|
2047
|
-
const next = advancePlayback({ time, duration: clip.duration, carry: playbackCarry, elapsed: dt, repeat: loop });
|
|
2048
|
-
for (const step of next.steps) expectedPlayer.advance(step);
|
|
2049
|
-
const activeEntry = expectedPlayer.entry(0);
|
|
2050
|
-
if (!activeEntry || activeEntry.animation !== animation || activeEntry.loop !== loop ||
|
|
2051
|
-
!Number.isFinite(activeEntry.animationTime) || activeEntry.animationTime < 0 ||
|
|
2052
|
-
activeEntry.animationTime > activeEntry.duration) {
|
|
2053
|
-
stopPlayback(expectedPlayer);
|
|
2054
|
-
return;
|
|
2055
|
-
}
|
|
2056
|
-
playbackCarry = next.carry;
|
|
2057
|
-
if (next.ended) {
|
|
2058
|
-
playing = false;
|
|
2059
|
-
playbackCarry = 0;
|
|
2060
|
-
lastFrameTime = 0;
|
|
2061
|
-
expectedPlayer.pause();
|
|
2062
|
-
time = clip.duration;
|
|
2063
|
-
} else {
|
|
2064
|
-
time = activeEntry.animationTime;
|
|
2065
|
-
}
|
|
2066
|
-
const clock = workspace.querySelector<HTMLInputElement>('#job-time');
|
|
2067
|
-
if (clock) clock.value = playbackTimeLabel(clip.duration, activeEntry.trackTime);
|
|
2068
|
-
inPlaybackStep = true;
|
|
2069
|
-
try {
|
|
2070
|
-
syncTransportControls();
|
|
2071
|
-
presentCurrentFrame(expectedOwner);
|
|
2072
|
-
}
|
|
2073
|
-
finally {
|
|
2074
|
-
inPlaybackStep = false;
|
|
2075
|
-
}
|
|
2076
|
-
if (playing) {
|
|
2077
|
-
saveWindowState(now);
|
|
2078
|
-
} else {
|
|
2079
|
-
lastRunningSaveMs = null;
|
|
2080
|
-
saveWindowState();
|
|
2081
|
-
}
|
|
2082
|
-
if (playing && current === expectedOwner && current.player === expectedPlayer && hubVisible) {
|
|
2083
|
-
armPlayback(expectedOwner, expectedPlayer);
|
|
2084
|
-
}
|
|
2085
|
-
}
|
|
2086
|
-
const referenceSelection = createJobReferenceSelection<JobReferenceView>({
|
|
2087
|
-
current: () => ({owner: current, time}),
|
|
2088
|
-
present(value) {
|
|
2089
|
-
const previous = selectedReference;
|
|
2090
|
-
const camera = structuredClone(viewportState);
|
|
2091
|
-
selectedReference = value.id;
|
|
2092
|
-
try {
|
|
2093
|
-
showReference();
|
|
2094
|
-
el<HTMLSelectElement>('job-reference').value = value.id;
|
|
2095
|
-
viewport.fitCamera();
|
|
2096
|
-
} catch (error) {
|
|
2097
|
-
selectedReference = previous;
|
|
2098
|
-
Object.assign(viewportState, camera);
|
|
2099
|
-
showReference();
|
|
2100
|
-
el<HTMLSelectElement>('job-reference').value = previous;
|
|
2101
|
-
viewport.fitCamera();
|
|
2102
|
-
throw error;
|
|
2103
|
-
}
|
|
2104
|
-
},
|
|
2105
|
-
refused(error) {
|
|
2106
|
-
el<HTMLSelectElement>('job-reference').value = selectedReference;
|
|
2107
|
-
notice.textContent = jobWindowRefusal(error, 'JOB_VISUAL_UNAVAILABLE');
|
|
2108
|
-
},
|
|
2109
|
-
});
|
|
2110
|
-
let unbindNavigation: (() => void) | null = null;
|
|
2111
|
-
let resize: ResizeObserver | null = null;
|
|
2112
|
-
const {localDraftKey,saveDraft}=prepareJobForms.drafts({jobId:access.jobId,current:()=>current,forms:()=>forms,storage:()=>localStorage});
|
|
2113
|
-
function updateForms(state: JobWindowState): void {
|
|
2114
|
-
if (!current)
|
|
2115
|
-
return;
|
|
2116
|
-
const host = workspace.querySelector<HTMLElement>('[data-job-forms]');
|
|
2117
|
-
if (!host)
|
|
2118
|
-
return;
|
|
2119
|
-
for(const ask of state.pending){
|
|
2120
|
-
if(ask.publicationId!==current.display.publication.publicationId)continue;
|
|
2121
|
-
if(ask.subject.kind!=='review-verdict'||!['image-review','direction-review'].includes(ask.subject.stage))throw new Error('JOB_PANEL_UNAVAILABLE');
|
|
2122
|
-
let entry=forms.get(ask.askId);
|
|
2123
|
-
if(!entry&&ask.status==='pending'){
|
|
2124
|
-
try{entry=prepareJobForms.formFor(ask,current,formDependencies);forms.set(ask.askId,entry);host.append(entry.form);}
|
|
2125
|
-
catch(error){const refusal=node('p');refusal.textContent=jobWindowRefusal(error,'JOB_ASK_INVALID');host.append(refusal);}
|
|
2126
|
-
}
|
|
2127
|
-
if(entry)entry.fieldset.disabled=entry.submitting||ask.status!=='pending'||state.preparing||state.closed||!state.receipt||!access.capability;
|
|
2128
|
-
}
|
|
2129
|
-
}
|
|
2130
|
-
function build(prepared: JobPreparedInspection): HTMLElement {
|
|
2131
|
-
const root = node('div');
|
|
2132
|
-
root.className = 'job-inspection';
|
|
2133
|
-
const sidebar = node('section');
|
|
2134
|
-
sidebar.className = 'job-sidebar';
|
|
2135
|
-
const identity = node('p');
|
|
2136
|
-
identity.className = 'job-source';
|
|
2137
|
-
identity.textContent = prepared.display.publication.label + '\n' + prepared.display.publication.source.sourceHash;
|
|
2138
|
-
sidebar.append(identity);
|
|
2139
|
-
const binding = node('details');
|
|
2140
|
-
const bindingTitle = node('summary', 'job.binding');
|
|
2141
|
-
const sourceBinding = node('pre');
|
|
2142
|
-
sourceBinding.className = 'job-source';
|
|
2143
|
-
sourceBinding.textContent = JSON.stringify(prepared.display.publication.source, null, 2);
|
|
2144
|
-
binding.append(bindingTitle, sourceBinding);
|
|
2145
|
-
sidebar.append(binding);
|
|
2146
|
-
const referenceSelect = node('select');
|
|
2147
|
-
referenceSelect.id = 'job-reference';
|
|
2148
|
-
for (const reference of prepared.references) {
|
|
2149
|
-
const option = node('option');
|
|
2150
|
-
option.value = reference.id;
|
|
2151
|
-
option.textContent = reference.label;
|
|
2152
|
-
referenceSelect.append(option);
|
|
2153
|
-
}
|
|
2154
|
-
referenceSelect.onchange = () => {
|
|
2155
|
-
const next = prepared.references.find(item => item.id === referenceSelect.value);
|
|
2156
|
-
if (current === prepared && next) void referenceSelection.select(next);
|
|
2157
|
-
};
|
|
2158
|
-
sidebar.append(inputLabel('Reference', referenceSelect));
|
|
2159
|
-
const stage = node('section');
|
|
2160
|
-
stage.className = 'job-stage';
|
|
2161
|
-
const controls = node('div');
|
|
2162
|
-
controls.className = 'viewbar';
|
|
2163
|
-
const viewControls = createViewControls({layout:'rigStep1', viewSwitch:inspectionViewSwitch(next => {
|
|
2164
|
-
view = next;
|
|
2165
|
-
pair.querySelector<HTMLElement>('#reference-pane')!.hidden = next === 'rig';
|
|
2166
|
-
pair.querySelector<HTMLElement>('#rig-pane')!.hidden = next === 'reference';
|
|
2167
|
-
viewport.fitCamera();
|
|
2168
|
-
})});
|
|
2169
|
-
controls.append(viewControls.syncLabel, viewControls.zoomGroup!);
|
|
2170
|
-
const pair = node('div');
|
|
2171
|
-
pair.id = 'stage-layout';
|
|
2172
|
-
mountViewportPair(pair);
|
|
2173
|
-
for (const id of ['idle-handles', 'rig-fields-stage'])
|
|
2174
|
-
pair.querySelector('#' + id)?.remove();
|
|
2175
|
-
for (const [id, key] of [['reference-label', 'Reference'], ['rig-label', 'Generated rig · read only'],
|
|
2176
|
-
['reference-empty', 'No reference supplied.'], ['rig-empty', 'No compiled model supplied.']]) {
|
|
2177
|
-
const label = pair.querySelector<HTMLElement>('#' + id);
|
|
2178
|
-
if (label) {
|
|
2179
|
-
label.dataset.jobText = key;
|
|
2180
|
-
label.textContent = t(key!);
|
|
2181
|
-
}
|
|
2182
|
-
}
|
|
2183
|
-
pair.querySelector('#reference-pane')?.setAttribute('aria-label', t('Reference'));
|
|
2184
|
-
pair.querySelector('#rig-pane')?.setAttribute('aria-label', t('Rig'));
|
|
2185
|
-
const rigViewport = pair.querySelector<HTMLElement>('#rig-viewport');
|
|
2186
|
-
if (rigViewport) {
|
|
2187
|
-
rigViewport.setAttribute('tabindex', '-1');
|
|
2188
|
-
rigViewport.addEventListener('pointerdown', () => rigViewport.focus?.());
|
|
2189
|
-
}
|
|
2190
|
-
pair.querySelector('#rig-root')!.replaceWith(prepared.rigRoot);
|
|
2191
|
-
const transport = node('div');
|
|
2192
|
-
transport.className = 'job-transport';
|
|
2193
|
-
const clips = node('select');
|
|
2194
|
-
clips.id = 'job-animation';
|
|
2195
|
-
const setup = node('option', 'Setup');
|
|
2196
|
-
setup.value = '';
|
|
2197
|
-
clips.append(setup);
|
|
2198
|
-
for (const clip of prepared.assets?.animations ?? []) {
|
|
2199
|
-
const option = node('option');
|
|
2200
|
-
option.value = clip.name;
|
|
2201
|
-
option.textContent = clip.name;
|
|
2202
|
-
clips.append(option);
|
|
2203
|
-
}
|
|
2204
|
-
clips.onchange = () => { stopPlayback(); animation = clips.value; time = 0; pose(); };
|
|
2205
|
-
const playButton = node('button', 'Play');
|
|
2206
|
-
playButton.id = 'job-play';
|
|
2207
|
-
playButton.type = 'button';
|
|
2208
|
-
playButton.setAttribute('aria-pressed', 'false');
|
|
2209
|
-
playButton.disabled = true;
|
|
2210
|
-
playButton.onclick = () => {
|
|
2211
|
-
const clip = current?.assets?.animations.find(item => item.name === animation);
|
|
2212
|
-
if (!current?.player || !animation || !clip || !(clip.duration > 0)) {
|
|
2213
|
-
stopPlayback();
|
|
2214
|
-
return;
|
|
2215
|
-
}
|
|
2216
|
-
if (playing) {
|
|
2217
|
-
stopPlayback();
|
|
2218
|
-
presentCurrentFrame(current);
|
|
2219
|
-
return;
|
|
2220
|
-
}
|
|
2221
|
-
if (current.player.composed) current.setupPose(false);
|
|
2222
|
-
if (!loop && time >= clip.duration) {
|
|
2223
|
-
time = 0;
|
|
2224
|
-
current.player.play(animation, { loop });
|
|
2225
|
-
} else if (current.player.current !== animation) {
|
|
2226
|
-
current.player.play(animation, { loop });
|
|
2227
|
-
if (time > 0) current.player.seek(time);
|
|
2228
|
-
} else {
|
|
2229
|
-
current.player.resume();
|
|
2230
|
-
}
|
|
2231
|
-
playing = true;
|
|
2232
|
-
playbackCarry = 0;
|
|
2233
|
-
lastFrameTime = 0;
|
|
2234
|
-
lastRunningSaveMs = null;
|
|
2235
|
-
const clockInput = workspace.querySelector<HTMLInputElement>('#job-time');
|
|
2236
|
-
if (clockInput) clockInput.value = playbackTimeLabel(clip.duration, current.player.time);
|
|
2237
|
-
syncTransportControls();
|
|
2238
|
-
presentCurrentFrame(current);
|
|
2239
|
-
if (hubVisible) armPlayback(current, current.player);
|
|
2240
|
-
};
|
|
2241
|
-
const loopInput = node('input');
|
|
2242
|
-
loopInput.id = 'job-loop';
|
|
2243
|
-
loopInput.type = 'checkbox';
|
|
2244
|
-
loopInput.checked = loop;
|
|
2245
|
-
loopInput.onchange = () => {
|
|
2246
|
-
loop = loopInput.checked;
|
|
2247
|
-
playbackCarry = 0;
|
|
2248
|
-
lastFrameTime = 0;
|
|
2249
|
-
const clip = current?.assets?.animations.find(item => item.name === animation);
|
|
2250
|
-
if (current?.player && animation && clip) {
|
|
2251
|
-
if (current.player.composed) current.setupPose(false);
|
|
2252
|
-
current.player.play(animation, { loop });
|
|
2253
|
-
if (time > 0) current.player.seek(time);
|
|
2254
|
-
const activeEntry = current.player.entry(0);
|
|
2255
|
-
if (!activeEntry || activeEntry.animation !== animation || activeEntry.loop !== loop ||
|
|
2256
|
-
!Number.isFinite(activeEntry.animationTime) || activeEntry.animationTime < 0 ||
|
|
2257
|
-
activeEntry.animationTime > activeEntry.duration) {
|
|
2258
|
-
stopPlayback(current.player);
|
|
2259
|
-
return;
|
|
2260
|
-
}
|
|
2261
|
-
time = activeEntry.animationTime;
|
|
2262
|
-
const clockInput = workspace.querySelector<HTMLInputElement>('#job-time');
|
|
2263
|
-
if (clockInput) clockInput.value = playbackTimeLabel(clip.duration, activeEntry.trackTime);
|
|
2264
|
-
if (!playing) current.player.pause();
|
|
2265
|
-
syncTransportControls();
|
|
2266
|
-
presentCurrentFrame(current);
|
|
2267
|
-
saveWindowState();
|
|
2268
|
-
if (playing && hubVisible) armPlayback(current, current.player);
|
|
2269
|
-
} else {
|
|
2270
|
-
syncTransportControls();
|
|
2271
|
-
saveWindowState();
|
|
2272
|
-
}
|
|
2273
|
-
};
|
|
2274
|
-
const clock = node('input');
|
|
2275
|
-
clock.id = 'job-time';
|
|
2276
|
-
clock.type = 'number';
|
|
2277
|
-
clock.min = '0';
|
|
2278
|
-
clock.step = '0.001';
|
|
2279
|
-
clock.oninput = () => {
|
|
2280
|
-
if (!playing) return;
|
|
2281
|
-
stopPlayback();
|
|
2282
|
-
if (current) presentCurrentFrame(current);
|
|
2283
|
-
};
|
|
2284
|
-
clock.onchange = () => {
|
|
2285
|
-
const value = Number(clock.value);
|
|
2286
|
-
const duration = current?.assets?.animations.find(clip => clip.name === animation)?.duration;
|
|
2287
|
-
if (!Number.isFinite(value) || value < 0 || duration !== undefined && value > duration) {
|
|
2288
|
-
clock.value = String(time);
|
|
2289
|
-
notice.textContent = t('KEY_TIME_OUT_OF_DOMAIN');
|
|
2290
|
-
return;
|
|
2291
|
-
}
|
|
2292
|
-
stopPlayback();
|
|
2293
|
-
time = value;
|
|
2294
|
-
pose();
|
|
2295
|
-
};
|
|
2296
|
-
transport.append(clips, playButton, inputLabel('Repeat', loopInput), inputLabel('job.time', clock));
|
|
2297
|
-
const numeric = node('pre');
|
|
2298
|
-
numeric.id = 'view-coordinates';
|
|
2299
|
-
numeric.hidden = true;
|
|
2300
|
-
const coordinates = node('span');
|
|
2301
|
-
coordinates.id = 'coordinates';
|
|
2302
|
-
coordinates.hidden = true;
|
|
2303
|
-
stage.append(controls, pair, transport, numeric, coordinates);
|
|
2304
|
-
const source = prepared.display.publication.source;
|
|
2305
|
-
if (source.subject === 'image-set') {
|
|
2306
|
-
const heading = node('h2', 'job.imageSetTitle');
|
|
2307
|
-
const digest = node('p');
|
|
2308
|
-
digest.className = 'job-source';
|
|
2309
|
-
digest.style.overflowWrap = 'anywhere';
|
|
2310
|
-
const digestLabel = node('span', 'job.imageSetDigest');
|
|
2311
|
-
const digestValue = node('code');
|
|
2312
|
-
digestValue.textContent = source.imageSetDigest;
|
|
2313
|
-
digest.append(digestLabel, document.createTextNode(' '), digestValue);
|
|
2314
|
-
const gallery = imageGallery(source.imageSet.images.map((image, index) => ({...image,
|
|
2315
|
-
element: prepared.imageSetImages?.[index],
|
|
2316
|
-
duplicate: source.duplicateHashes.some(group => group.names.includes(image.name))})));
|
|
2317
|
-
gallery.dataset.jobImageSet = '';
|
|
2318
|
-
stage.prepend(heading, digest, gallery);
|
|
2319
|
-
controls.hidden = pair.hidden = transport.hidden = true;
|
|
2320
|
-
controls.style.display = pair.style.display = transport.style.display = 'none';
|
|
2321
|
-
for (const child of sidebar.children) {
|
|
2322
|
-
if (child instanceof HTMLElement && child !== identity && child !== binding) child.hidden = true;
|
|
2323
|
-
}
|
|
2324
|
-
}
|
|
2325
|
-
const formsHost = node('section');
|
|
2326
|
-
formsHost.className = 'job-forms';
|
|
2327
|
-
formsHost.dataset.jobForms = '';
|
|
2328
|
-
const heading = node('h2', 'job.pending');
|
|
2329
|
-
formsHost.append(heading);
|
|
2330
|
-
const direction = node('pre');
|
|
2331
|
-
direction.className = 'job-direction';
|
|
2332
|
-
direction.dataset.jobDirection = '';
|
|
2333
|
-
if (prepared.metadata.direction)
|
|
2334
|
-
direction.textContent = t('job.metadata') + '\n' + JSON.stringify(prepared.metadata.direction, null, 2);
|
|
2335
|
-
const interviewDiagnostics = node('section');
|
|
2336
|
-
interviewDiagnostics.className = 'job-interview-diagnostics';
|
|
2337
|
-
interviewDiagnostics.dataset.jobInterviewDiagnostics = '';
|
|
2338
|
-
const interviewState = prepared.interview?.interview ?? prepared.display.publication.interview ?? null;
|
|
2339
|
-
if (interviewState && (interviewState.diagnostics.length > 0 || interviewState.records.some(record => record.timeKind !== 'inspection'))) {
|
|
2340
|
-
interviewDiagnostics.append(node('h3', 'interview.history'));
|
|
2341
|
-
for (const diagnostic of interviewState.diagnostics) {
|
|
2342
|
-
const item = node('div');
|
|
2343
|
-
item.dataset.jobInterviewDiagnostic = diagnostic.code;
|
|
2344
|
-
item.dataset.severity = diagnostic.severity;
|
|
2345
|
-
item.dataset.record = diagnostic.record;
|
|
2346
|
-
const summary = node('p', diagnostic.code);
|
|
2347
|
-
const detail = node('pre');
|
|
2348
|
-
detail.className = 'job-source';
|
|
2349
|
-
detail.textContent = JSON.stringify(diagnostic, null, 2);
|
|
2350
|
-
item.append(summary, detail);
|
|
2351
|
-
interviewDiagnostics.append(item);
|
|
2352
|
-
}
|
|
2353
|
-
for (const record of interviewState.records) {
|
|
2354
|
-
if (record.timeKind === 'inspection') continue;
|
|
2355
|
-
const item = node('div');
|
|
2356
|
-
item.dataset.jobInterviewRecord = record.record;
|
|
2357
|
-
item.dataset.timeKind = record.timeKind;
|
|
2358
|
-
const detail = node('pre');
|
|
2359
|
-
detail.className = 'job-source';
|
|
2360
|
-
detail.textContent = JSON.stringify(record, null, 2);
|
|
2361
|
-
item.append(detail);
|
|
2362
|
-
interviewDiagnostics.append(item);
|
|
2363
|
-
}
|
|
2364
|
-
}
|
|
2365
|
-
else {
|
|
2366
|
-
interviewDiagnostics.hidden = true;
|
|
2367
|
-
}
|
|
2368
|
-
const history = node('div');
|
|
2369
|
-
history.className = 'job-history';
|
|
2370
|
-
history.dataset.jobHistory = '';
|
|
2371
|
-
formsHost.append(direction, interviewDiagnostics, history);
|
|
2372
|
-
root.append(sidebar, stage, formsHost);
|
|
2373
|
-
return root;
|
|
2374
|
-
}
|
|
2375
|
-
function showReference(): void {
|
|
2376
|
-
const value = reference();
|
|
2377
|
-
el('reference-content').replaceChildren(...(value ? [value.element] : []));
|
|
2378
|
-
el('reference-empty').hidden = !!value;
|
|
2379
|
-
}
|
|
2380
|
-
function showPanel(): void {
|
|
2381
|
-
const direction = workspace.querySelector<HTMLElement>('[data-job-direction]');
|
|
2382
|
-
if (direction) direction.hidden = !current?.metadata.direction;
|
|
2383
|
-
saveWindowState();
|
|
2384
|
-
}
|
|
2385
|
-
function pose(seekReference = true): void {
|
|
2386
|
-
if (!current)
|
|
2387
|
-
return;
|
|
2388
|
-
const clip = current.assets?.animations.find(item => item.name === animation);
|
|
2389
|
-
const clock = el<HTMLInputElement>('job-time');
|
|
2390
|
-
clock.value = String(time);
|
|
2391
|
-
if (animation && (!clip || time > clip.duration)) {
|
|
2392
|
-
notice.textContent = t('KEY_TIME_OUT_OF_DOMAIN');
|
|
2393
|
-
return;
|
|
2394
|
-
}
|
|
2395
|
-
if (!animation && current.player?.current) current.setupPose();
|
|
2396
|
-
// Setup uses an empty composed track. Animation seek needs a fresh single track.
|
|
2397
|
-
if (animation && current.player?.composed) current.setupPose(false);
|
|
2398
|
-
if (current.player) {
|
|
2399
|
-
if (animation && (current.player.current !== animation || current.player.entry(0)?.loop !== loop))
|
|
2400
|
-
current.player.play(animation, { loop });
|
|
2401
|
-
if (animation) {
|
|
2402
|
-
const seekAtLoopEnd = loop && time === clip?.duration;
|
|
2403
|
-
current.player.seek(time);
|
|
2404
|
-
const activeEntry = current.player.entry(0);
|
|
2405
|
-
if (!activeEntry || activeEntry.animation !== animation || activeEntry.loop !== loop ||
|
|
2406
|
-
!Number.isFinite(activeEntry.animationTime) || activeEntry.animationTime < 0 ||
|
|
2407
|
-
activeEntry.animationTime > activeEntry.duration) {
|
|
2408
|
-
current.player.pause();
|
|
2409
|
-
notice.textContent = t('JOB_VISUAL_UNAVAILABLE');
|
|
2410
|
-
return;
|
|
2411
|
-
}
|
|
2412
|
-
time = activeEntry.animationTime;
|
|
2413
|
-
clock.value = seekAtLoopEnd ? '0' : String(time);
|
|
2414
|
-
}
|
|
2415
|
-
current.player.pause();
|
|
2416
|
-
drawInspection(current);
|
|
2417
|
-
}
|
|
2418
|
-
syncTransportControls();
|
|
2419
|
-
if (seekReference) {
|
|
2420
|
-
const value = reference();
|
|
2421
|
-
const owner = current;
|
|
2422
|
-
const at = time;
|
|
2423
|
-
void value?.seek(at, abort.signal).catch(error => {
|
|
2424
|
-
if (current === owner && reference() === value && time === at)
|
|
2425
|
-
notice.textContent = jobWindowRefusal(error, 'JOB_VISUAL_UNAVAILABLE');
|
|
2426
|
-
});
|
|
2427
|
-
}
|
|
2428
|
-
viewport.fitCamera();
|
|
2429
|
-
}
|
|
2430
|
-
function hubBinding(): JobHubBinding {
|
|
2431
|
-
return {incarnation: hubIncarnation!, jobId: access.jobId,
|
|
2432
|
-
publicationId: current?.display.publication.publicationId ?? null,
|
|
2433
|
-
sourceHash: current?.display.publication.source.sourceHash ?? null};
|
|
2434
|
-
}
|
|
2435
|
-
function pauseHiddenHubFrame(): void {
|
|
2436
|
-
if (hubVisible) return;
|
|
2437
|
-
stopPlayback();
|
|
2438
|
-
for (const video of workspace.querySelectorAll('video')) video.pause();
|
|
2439
|
-
}
|
|
2440
|
-
function announceHubFrame(): void {
|
|
2441
|
-
if (hubIncarnation) globalThis.parent.postMessage({...hubBinding(), schema: JOB_HUB_READY}, location.origin);
|
|
2442
|
-
}
|
|
2443
|
-
// Only publications without a shared-screen host retain this fallback.
|
|
2444
|
-
const formDependencies: JobFormDependencies = {
|
|
2445
|
-
node, translate: t, helpers: {...formHelpers, assertJobAskSource, jobCheckpointContext},
|
|
2446
|
-
draftStorage: () => localStorage, localDraftKey, saveDraft, access, pageId,
|
|
2447
|
-
window: {state: () => window.state(), submit: input => window.submit(input)},
|
|
2448
|
-
};
|
|
2449
|
-
const rigScreen = createJobRigScreen({host, pageId, access, translate: (key, values) => i18n.t(key, values, 'en'), refusal: jobWindowRefusal, formDependencies,
|
|
2450
|
-
readPublication: (id, signal) => transport.readPublication(id, signal),
|
|
2451
|
-
window: {state: () => window.state(), submit: input => window.submit(input)},
|
|
2452
|
-
routes: display => jobPublicationRoutes(display, location.origin), load: async () => (await import('./main.ts')).mountRigScreen()});
|
|
2453
|
-
const window = createJobWindow({ jobId: access.jobId, pageId, transport,
|
|
2454
|
-
previousDisplayed, initialRetainedDrafts,
|
|
2455
|
-
adapter: {
|
|
2456
|
-
async prepare(display, signal): Promise<PreparedWindow | JobRigScreenPrepared> {
|
|
2457
|
-
const rig = await rigScreen.prepare(display, signal);
|
|
2458
|
-
if (!rig && rigScreen.mounted()) { location.reload(); return new Promise<never>(() => {}); }
|
|
2459
|
-
if (rig && current) { location.reload(); return new Promise<never>(() => {}); }
|
|
2460
|
-
if (rig) return rig;
|
|
2461
|
-
const source = display.publication.source;
|
|
2462
|
-
if ('record' in source || source.subject !== 'image-set' && !source.direction && (source.model || source.parts))
|
|
2463
|
-
throw new Error('JOB_PANEL_UNAVAILABLE');
|
|
2464
|
-
const inspection = await prepareJobInspection(display, signal);
|
|
2465
|
-
try {
|
|
2466
|
-
const element = build(inspection);
|
|
2467
|
-
const asks = window.state().pending;
|
|
2468
|
-
const preparedForms = prepareJobForms(display, asks, ask => prepareJobForms.formFor(ask, inspection, formDependencies));
|
|
2469
|
-
return Object.assign(inspection, { element, forms: preparedForms });
|
|
2470
|
-
}
|
|
2471
|
-
catch (error) {
|
|
2472
|
-
inspection.dispose();
|
|
2473
|
-
throw error;
|
|
2474
|
-
}
|
|
2475
|
-
},
|
|
2476
|
-
captureDraft() { if (rigScreen.mounted()) return null; saveDraft(); const dirty = [...forms].filter(([, item]) => item.dirty); return dirty.length ? dirty.map(([askId, item]) => ({ askId, value: item.read() })) : null; },
|
|
2477
|
-
commit(prepared, display) {
|
|
2478
|
-
if (isJobRigScreen(prepared)) return rigScreen.commit(prepared);
|
|
2479
|
-
// Pending asks can arrive while assets load. Finish their forms before the visible replacement.
|
|
2480
|
-
const asks = window.state().pending;
|
|
2481
|
-
const nextForms = prepareJobForms(display, asks,
|
|
2482
|
-
ask => prepared.forms.get(ask.askId) ?? prepareJobForms.formFor(ask, prepared, formDependencies));
|
|
2483
|
-
const root = prepared.element;
|
|
2484
|
-
const formHost = root.querySelector<HTMLElement>('[data-job-forms]');
|
|
2485
|
-
if (!formHost) throw new Error('JOB_WINDOW_ELEMENT_MISSING');
|
|
2486
|
-
for (const entry of nextForms.values()) formHost.append(entry.form);
|
|
2487
|
-
referenceSelection.cancel();
|
|
2488
|
-
const previous = current;
|
|
2489
|
-
stopPlayback(previous?.player);
|
|
2490
|
-
const previousElement = currentElement;
|
|
2491
|
-
const previousForms = new Map(forms);
|
|
2492
|
-
const restoringCamera = Boolean(previous || restoredCamera);
|
|
2493
|
-
const navigation = { animation, time, loop, selectedReference, panel,
|
|
2494
|
-
camera: structuredClone(viewportState) };
|
|
2495
|
-
compatibilityNotice = Boolean(!previous &&
|
|
2496
|
-
savedWindow?.publicationId === display.publication.publicationId &&
|
|
2497
|
-
savedWindow.compatibilityNotice);
|
|
2498
|
-
if (animation && !prepared.assets?.animations.some(item => item.name === animation && time <= item.duration)) {
|
|
2499
|
-
animation = '';
|
|
2500
|
-
time = 0;
|
|
2501
|
-
compatibilityNotice = true;
|
|
2502
|
-
}
|
|
2503
|
-
if (!prepared.references.some(item => item.id === selectedReference))
|
|
2504
|
-
selectedReference = prepared.references[0]?.id ?? '';
|
|
2505
|
-
let nextUnbind: (() => void) | null = null;
|
|
2506
|
-
let nextResize: ResizeObserver | null = null;
|
|
2507
|
-
const rollback = () => {
|
|
2508
|
-
stopPlayback(prepared.player);
|
|
2509
|
-
nextUnbind?.();
|
|
2510
|
-
nextResize?.disconnect();
|
|
2511
|
-
current = previous;
|
|
2512
|
-
currentElement = previousElement;
|
|
2513
|
-
animation = navigation.animation;
|
|
2514
|
-
time = navigation.time;
|
|
2515
|
-
loop = navigation.loop;
|
|
2516
|
-
selectedReference = navigation.selectedReference;
|
|
2517
|
-
panel = navigation.panel;
|
|
2518
|
-
forms.clear();
|
|
2519
|
-
for (const [id, item] of previousForms)
|
|
2520
|
-
forms.set(id, item);
|
|
2521
|
-
workspace.replaceChildren(...(previousElement ? [previousElement] : []));
|
|
2522
|
-
Object.assign(viewportState, navigation.camera);
|
|
2523
|
-
if (current) {
|
|
2524
|
-
el<HTMLSelectElement>('job-reference').value = selectedReference;
|
|
2525
|
-
syncTransportControls();
|
|
2526
|
-
viewport.fitCamera();
|
|
2527
|
-
}
|
|
2528
|
-
};
|
|
2529
|
-
try {
|
|
2530
|
-
current = prepared;
|
|
2531
|
-
currentElement = root;
|
|
2532
|
-
forms.clear();
|
|
2533
|
-
for (const [id, entry] of nextForms) forms.set(id, entry);
|
|
2534
|
-
workspace.replaceChildren(root);
|
|
2535
|
-
el<HTMLSelectElement>('job-reference').value = selectedReference;
|
|
2536
|
-
el<HTMLSelectElement>('job-animation').value = animation;
|
|
2537
|
-
el<HTMLInputElement>('job-loop').checked = loop;
|
|
2538
|
-
el('rig-empty').hidden = !!prepared.player;
|
|
2539
|
-
Object.assign(viewportState, navigation.camera, { cameraRestoring: restoringCamera });
|
|
2540
|
-
showReference();
|
|
2541
|
-
pose(false);
|
|
2542
|
-
viewportState.cameraRestoring = false;
|
|
2543
|
-
updateForms(window.state());
|
|
2544
|
-
showPanel();
|
|
2545
|
-
viewport.bindControls();
|
|
2546
|
-
nextUnbind = viewport.bindNavigation();
|
|
2547
|
-
nextResize = viewport.observeResize();
|
|
2548
|
-
return {
|
|
2549
|
-
rollback,
|
|
2550
|
-
finalize() {
|
|
2551
|
-
restoredCamera = null;
|
|
2552
|
-
savedWindow = null;
|
|
2553
|
-
unbindNavigation?.();
|
|
2554
|
-
resize?.disconnect();
|
|
2555
|
-
unbindNavigation = nextUnbind;
|
|
2556
|
-
resize = nextResize;
|
|
2557
|
-
previous?.dispose();
|
|
2558
|
-
title.textContent = display.publication.source.package?.id ?? display.publication.label;
|
|
2559
|
-
},
|
|
2560
|
-
};
|
|
2561
|
-
}
|
|
2562
|
-
catch (error) {
|
|
2563
|
-
rollback();
|
|
2564
|
-
throw error;
|
|
2565
|
-
}
|
|
2566
|
-
},
|
|
2567
|
-
async painted(prepared, signal) {
|
|
2568
|
-
if (isJobRigScreen(prepared)) return rigScreen.painted(prepared, signal);
|
|
2569
|
-
for (const image of prepared.imageSetImages ?? []) {
|
|
2570
|
-
if (!image.isConnected || !image.complete || !image.naturalWidth || !image.naturalHeight)
|
|
2571
|
-
throw new Error('JOB_VISUAL_UNAVAILABLE');
|
|
2572
|
-
}
|
|
2573
|
-
await reference()?.seek(time, signal);
|
|
2574
|
-
if (prepared.player) {
|
|
2575
|
-
drawInspection(prepared);
|
|
2576
|
-
}
|
|
2577
|
-
await new Promise<void>(resolve => requestAnimationFrame(() => requestAnimationFrame(() => resolve())));
|
|
2578
|
-
if (signal.aborted)
|
|
2579
|
-
throw new Error('JOB_PRELOAD_CANCELLED');
|
|
2580
|
-
},
|
|
2581
|
-
discard(prepared) { if (!isJobRigScreen(prepared)) prepared.dispose(); },
|
|
2582
|
-
changed(state) {
|
|
2583
|
-
if (rigScreen.mounted()) {
|
|
2584
|
-
rigScreen.changed(state); announceHubFrame();
|
|
2585
|
-
if (state.receipt && !state.preparing) events?.displayed();
|
|
2586
|
-
return;
|
|
2587
|
-
}
|
|
2588
|
-
notice.dataset.failed = String(!!state.error);
|
|
2589
|
-
if (state.error)
|
|
2590
|
-
notice.textContent = state.displayed && state.error !== 'JOB_WINDOW_CLEANUP_FAILED'
|
|
2591
|
-
? t('job.failed') + ' · ' + jobWindowRefusal(state.error) : jobWindowRefusal(state.error);
|
|
2592
|
-
else if (state.closed)
|
|
2593
|
-
notice.textContent = t('job.closed');
|
|
2594
|
-
else if (state.preparing)
|
|
2595
|
-
notice.textContent = t('job.preparing');
|
|
2596
|
-
else if (state.displayed) {
|
|
2597
|
-
delete notice.dataset.jobPartsState;
|
|
2598
|
-
notice.textContent = state.previousLabel
|
|
2599
|
-
? t('job.updated', [state.previousLabel, state.displayed.publication.label]) : state.displayed.publication.label;
|
|
2600
|
-
if (compatibilityNotice)
|
|
2601
|
-
notice.textContent += ' · ' + t('job.incompatible');
|
|
2602
|
-
}
|
|
2603
|
-
if (state.closed) {
|
|
2604
|
-
const wasPlaying = playing;
|
|
2605
|
-
stopPlayback();
|
|
2606
|
-
if (wasPlaying && current) presentCurrentFrame(current);
|
|
2607
|
-
}
|
|
2608
|
-
updateForms(state);
|
|
2609
|
-
if (current)
|
|
2610
|
-
showPanel();
|
|
2611
|
-
const history = workspace.querySelector<HTMLElement>('[data-job-history]');
|
|
2612
|
-
if (history) {
|
|
2613
|
-
const retained = new Map(state.retainedDrafts.map(draft => [draft.publicationId, draft]));
|
|
2614
|
-
try {
|
|
2615
|
-
const prefix = 'rig-review-job-draft/1:' + access.jobId + ':';
|
|
2616
|
-
for (let index = 0; index < localStorage.length; index++) {
|
|
2617
|
-
const key = localStorage.key(index);
|
|
2618
|
-
if (!key?.startsWith(prefix))
|
|
2619
|
-
continue;
|
|
2620
|
-
try {
|
|
2621
|
-
const parsedDraft = parseSavedDraftRecord(JSON.parse(localStorage.getItem(key) ?? 'null'));
|
|
2622
|
-
if (!parsedDraft || parsedDraft.publicationId === state.displayed?.publication.publicationId)
|
|
2623
|
-
continue;
|
|
2624
|
-
retained.set(parsedDraft.publicationId, parsedDraft);
|
|
2625
|
-
}
|
|
2626
|
-
catch { /* Ignore malformed draft entries without dropping sibling drafts. */ }
|
|
2627
|
-
}
|
|
2628
|
-
}
|
|
2629
|
-
catch { /* In-memory retained evidence remains available. */ }
|
|
2630
|
-
history.textContent = [...retained.values()].map(draft => t('job.retained', [draft.label]) + '\n' + draft.sourceHash + '\n' + JSON.stringify(draft.value, null, 2)).join('\n');
|
|
2631
|
-
}
|
|
2632
|
-
saveWindowState();
|
|
2633
|
-
pauseHiddenHubFrame(); announceHubFrame();
|
|
2634
|
-
if (state.receipt && !state.preparing) events?.displayed();
|
|
2635
|
-
},
|
|
2636
|
-
} });
|
|
2637
|
-
const localize = i18n.onLanguageChange(() => {
|
|
2638
|
-
for (const element of host.querySelectorAll<HTMLElement>('[data-job-text]'))
|
|
2639
|
-
element.textContent = t(element.dataset.jobText!);
|
|
2640
|
-
languages.setAttribute('aria-label', t('interview.language'));
|
|
2641
|
-
if (current) {
|
|
2642
|
-
workspace.querySelector('#rig-overlay')?.setAttribute('aria-label', t('Actual rig mesh and bone overlay'));
|
|
2643
|
-
viewport.renderCameraControls();
|
|
2644
|
-
}
|
|
2645
|
-
window.refresh();
|
|
2646
|
-
});
|
|
2647
|
-
const hubVisibility = (event: MessageEvent) => {
|
|
2648
|
-
if (!hubIncarnation || !jobHubMessageMatches(event, location.origin, globalThis.parent, hubBinding(), 'visibility')) return;
|
|
2649
|
-
hubVisible = event.data.visible;
|
|
2650
|
-
host.dataset.hubVisible = String(hubVisible);
|
|
2651
|
-
events?.visibility(hubVisible);
|
|
2652
|
-
if (event.data.language !== i18n.getLanguage()) {
|
|
2653
|
-
i18n.setLinkLanguage(null); i18n.setLanguagePreference(event.data.language);
|
|
2654
|
-
}
|
|
2655
|
-
pauseHiddenHubFrame();
|
|
2656
|
-
if (hubVisible && current?.player) drawInspection(current);
|
|
2657
|
-
};
|
|
2658
|
-
if (hubIncarnation) {globalThis.addEventListener('message', hubVisibility); announceHubFrame();}
|
|
2659
|
-
events = startJobWindowEvents({access, signal: abort.signal, member: !!hubIncarnation,
|
|
2660
|
-
event: event => window.event(event),
|
|
2661
|
-
refused: error => {notice.textContent = jobWindowRefusal(error, 'JOB_STREAM_FAILED');},
|
|
2662
|
-
});
|
|
2663
|
-
let resolution: MediaQueryList | undefined;
|
|
2664
|
-
const resolutionChanged = () => {
|
|
2665
|
-
resolution?.removeEventListener('change', resolutionChanged);
|
|
2666
|
-
resolution = globalThis.matchMedia(`(resolution:${globalThis.devicePixelRatio || 1}dppx)`);
|
|
2667
|
-
resolution.addEventListener('change', resolutionChanged);
|
|
2668
|
-
if (current) {
|
|
2669
|
-
viewport.fitCamera();
|
|
2670
|
-
}
|
|
2671
|
-
};
|
|
2672
|
-
resolutionChanged();
|
|
2673
|
-
const stop = () => {
|
|
2674
|
-
stopPlayback();
|
|
2675
|
-
resolution?.removeEventListener('change', resolutionChanged);
|
|
2676
|
-
globalThis.removeEventListener('message', hubVisibility);
|
|
2677
|
-
saveDraft();
|
|
2678
|
-
saveWindowState();
|
|
2679
|
-
referenceSelection.cancel();
|
|
2680
|
-
abort.abort();
|
|
2681
|
-
window.stop();
|
|
2682
|
-
localize();
|
|
2683
|
-
unbindNavigation?.();
|
|
2684
|
-
resize?.disconnect();
|
|
2685
|
-
current?.dispose();
|
|
2686
|
-
};
|
|
2687
|
-
globalThis.addEventListener('pagehide', stop, { once: true });
|
|
2688
|
-
return () => { globalThis.removeEventListener('pagehide', stop); stop(); };
|
|
2689
|
-
}
|
|
2690
|
-
if (typeof document !== 'undefined' && document.body?.hasAttribute('data-job-window')) {
|
|
2691
|
-
void mountJobSession(document.body).catch(error => {
|
|
2692
|
-
const status = document.createElement('p');
|
|
2693
|
-
status.setAttribute('role', 'alert');
|
|
2694
|
-
status.textContent = jobWindowRefusal(error);
|
|
2695
|
-
document.body.append(status);
|
|
2696
|
-
});
|
|
2697
|
-
}
|