@rig-c/review 4.6.0 → 4.8.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 +243 -28
- package/docs/STABILITY.md +88 -12
- package/package.json +1 -1
- package/src/canonical-json.ts +14 -0
- package/src/feedback-export.ts +2 -2
- package/src/interview-project.ts +27 -19
- package/src/interview-scene.ts +18 -11
- package/src/job-act.ts +99 -12
- package/src/job-api.ts +185 -38
- package/src/job-checkpoint-evidence.ts +19 -6
- package/src/job-cli.ts +12 -6
- package/src/job-contract.ts +91 -15
- package/src/job-front.ts +100 -78
- package/src/job-host.ts +9 -2
- package/src/job-previous-draft.ts +37 -0
- package/src/job-session.ts +76 -41
- package/src/job-source.ts +196 -35
- package/src/manifest.ts +43 -14
- package/src/mesh-edit.ts +7 -1
- package/src/parts-comment-crops.ts +15 -3
- package/src/parts-comparison.ts +21 -8
- package/src/parts-view.ts +23 -8
- package/web/catalog-en.ts +10 -0
- package/web/catalog-ko.ts +10 -0
- package/web/job-rig-screen.ts +63 -21
- package/web/job-session.ts +54 -26
- package/web/main.ts +158 -50
- package/web/mesh-editor.ts +123 -13
- package/web/part-selection.ts +1 -1
- package/web/parts-viewport-provider.ts +46 -11
- package/web/rig-host.ts +5 -3
- package/web/stage-comments.ts +77 -14
- package/web/styles.css +2 -0
- package/web/workspace-layout.ts +10 -0
- package/web/workspace-ui.ts +2 -2
- package/src/create-pin-gate.ts +0 -3
package/web/mesh-editor.ts
CHANGED
|
@@ -11,15 +11,17 @@
|
|
|
11
11
|
* inspected build, and the local draft keeps the applied delta (edits over the revision are not written to it).
|
|
12
12
|
*/
|
|
13
13
|
import type {CropWorldMapping} from '../src/chest-regions.ts';
|
|
14
|
+
import type {JobMeshEditValue} from '../src/job-contract.ts';
|
|
14
15
|
import {readStoredSetupMesh,setupModel} from '../src/setup-mesh.ts';
|
|
15
16
|
import {
|
|
16
17
|
MESH_EDIT_CODES,MESH_EDIT_NO_MESH,MESH_EDIT_PREVIEW_NOTE,MESH_EDIT_RIG_UNAVAILABLE,MESH_EDIT_SELECT_SLOT,MeshEditSession,affineOf,applyAffine,applyMeshOps,attachmentHashText,draftOps,hitMesh,
|
|
17
|
-
invertAffine,meshEditDocument,parseMeshDraft,screenDeltaToCrop,verticesInBox,writeMeshDraft,type MeshEditDocument,type MeshEditResult,type MeshOp,type MeshSource,
|
|
18
|
-
type MeshView,type ScreenPoint,type Vec,
|
|
18
|
+
draftKey,invertAffine,meshEditActValue,meshEditDocument,parseMeshDraft,screenDeltaToCrop,verticesInBox,writeMeshDraft,type MeshEditDocument,type MeshEditResult,type MeshOp,type MeshSource,
|
|
19
|
+
type MeshEditDraft,type MeshView,type ScreenPoint,type Vec,
|
|
19
20
|
} from '../src/mesh-edit.ts';
|
|
20
21
|
import type {OverlayMeshEdit,OverlayPoint,OverlayProject} from './rig-overlays.ts';
|
|
21
22
|
import type {SetupPose} from './setup-pose.ts';
|
|
22
23
|
import {textEntryFocused} from './view-controls.ts';
|
|
24
|
+
import {onLanguageChange,t,tr} from './i18n.ts';
|
|
23
25
|
|
|
24
26
|
export type MeshMode='modify'|'create'|'delete'|'edges';
|
|
25
27
|
export const meshModes:readonly MeshMode[]=['modify','create','delete','edges'];
|
|
@@ -88,12 +90,15 @@ export interface MeshEditorHost {
|
|
|
88
90
|
project:()=>OverlayProject|null;
|
|
89
91
|
mapping:()=>CropWorldMapping;
|
|
90
92
|
inspector:()=>string|undefined;
|
|
93
|
+
readonly readOnly?:boolean;
|
|
91
94
|
/** The selected slot's setup-space source, or the refusal that names why there is none. */
|
|
92
|
-
source:()=>SourceResult;
|
|
95
|
+
source:(slot?:string)=>SourceResult;
|
|
93
96
|
/** Hold the stage still under the setup-pose overlay. */
|
|
94
97
|
pause:()=>void;
|
|
95
98
|
changed:()=>void;
|
|
96
99
|
download:(document:MeshEditDocument)=>void;
|
|
100
|
+
/** Live jobs keep the editor but send rig-review edits via the verdict. */
|
|
101
|
+
job?:{slots:()=>readonly string[];modelHash:()=>string|null}|'read-only';
|
|
97
102
|
/** Apply · Rebuild (#135): send the delta through the shared runner; `built` when the revision is on the stage. Lines stream to `line`. */
|
|
98
103
|
apply:(document:MeshEditDocument,line:(text:string)=>void)=>Promise<{built:boolean;text:string;error:boolean}>;
|
|
99
104
|
/** Whether the stage holds a revision this editor's Apply built. */
|
|
@@ -104,14 +109,75 @@ export interface MeshEditorHost {
|
|
|
104
109
|
confirm:(text:string)=>boolean;
|
|
105
110
|
token:(name:string)=>string;
|
|
106
111
|
}
|
|
107
|
-
export interface
|
|
112
|
+
export interface JobMeshDraftSubmission {
|
|
113
|
+
readonly edits:readonly JobMeshEditValue[];
|
|
114
|
+
clear(accepted:readonly JobMeshEditValue[]):void;
|
|
115
|
+
}
|
|
116
|
+
export interface MeshEditor {active:()=>boolean;overlay:()=>OverlayMeshEdit|null;sync:()=>void;selectionChanged:()=>void;dispose:()=>void;session:()=>MeshEditSession|null;mode:()=>MeshMode|null;statusNote:()=>string;setStatusNote:(text:string,error?:boolean)=>void;hasJobEdits:()=>boolean;jobEdits:()=>Promise<JobMeshDraftSubmission|null>}
|
|
117
|
+
|
|
118
|
+
type JobDraftScanResult={stored:MeshEditDraft;edits:JobMeshEditValue[];stale:boolean;versions:ReadonlyMap<string,number>};
|
|
119
|
+
type JobDraftScan={text:string;modelHash:string;version:number;result?:JobDraftScanResult;pending:Promise<JobDraftScanResult>};
|
|
108
120
|
|
|
109
121
|
type Drag={pointer:number;start:ScreenPoint;ids:number[];base:MeshView;ops:MeshOp[]}|{pointer:number;start:ScreenPoint;box:ScreenPoint;add:boolean};
|
|
110
122
|
|
|
111
123
|
export function bindMeshEditor(host:MeshEditorHost):MeshEditor {
|
|
112
124
|
const node=<T extends HTMLElement>(id:string)=>document.getElementById(id) as T;
|
|
113
125
|
const toggle=node<HTMLButtonElement>('mesh-edit'),bar=node<HTMLElement>('mesh-editor-bar'),status=node<HTMLElement>('mesh-editor-status'),draft=node<HTMLTextAreaElement>('mesh-edit-draft');
|
|
126
|
+
const apply=node<HTMLButtonElement>('mesh-apply');
|
|
114
127
|
const chestToggle=document.getElementById('chest-edit') as HTMLButtonElement|null;
|
|
128
|
+
const job=typeof host.job==='object'?host.job:null;
|
|
129
|
+
const jobDrafts=new Map<string,{session:MeshEditSession;frame:{width:number;height:number};modelHash:string}>();
|
|
130
|
+
const jobVersions=new Map<string,number>();
|
|
131
|
+
let jobDraftText=draft.value,jobVersion=0,jobScan:JobDraftScan|undefined,disposed=false;
|
|
132
|
+
/** Only sessions from the current model and saved entries that replay on it are held. */
|
|
133
|
+
const readJobDraft=async(text:string,modelHash:string):Promise<JobDraftScanResult>=>{
|
|
134
|
+
const stored=parseMeshDraft(text),versions=new Map(jobVersions);
|
|
135
|
+
const sessions=new Map((jobDraftText===text?[...jobDrafts]:[]).filter(([,row])=>row.modelHash===modelHash));
|
|
136
|
+
const edits=[...sessions.values()].filter(({session})=>session.canUndo()).map(({session,frame})=>meshEditActValue(session,frame));
|
|
137
|
+
const unopened=Object.entries(stored.entries).filter(([key,entry])=>entry.ops.length>0&&!sessions.get(key)?.session.canUndo()).map(([key])=>key);
|
|
138
|
+
const keys=new Set(unopened);
|
|
139
|
+
const mapping=host.mapping();
|
|
140
|
+
if(!job||!mapping.available||!keys.size)return {stored,edits,stale:keys.size>0,versions};
|
|
141
|
+
const frame={width:mapping.crop.w,height:mapping.crop.h},sources=new Map<string,Extract<SourceResult,{ok:true}>>();
|
|
142
|
+
const ambiguous=new Set<string>();
|
|
143
|
+
for(const slot of job.slots()){
|
|
144
|
+
if(!unopened.some(key=>key.includes(`/${slot}/`)))continue;
|
|
145
|
+
const result=host.source(slot);
|
|
146
|
+
if(!result.ok)continue;
|
|
147
|
+
const key=draftKey(result.source);
|
|
148
|
+
if(!keys.has(key))continue;
|
|
149
|
+
if(sources.has(key))ambiguous.add(key);
|
|
150
|
+
sources.set(key,result);
|
|
151
|
+
}
|
|
152
|
+
const restored=await Promise.all([...sources].filter(([key])=>!ambiguous.has(key)).map(async ([,result])=>{
|
|
153
|
+
const source={...result.source,hash:await sha256Hex(attachmentHashText(result.entry))};
|
|
154
|
+
const ops=draftOps(stored,source);
|
|
155
|
+
return ops?.length?meshEditActValue(new MeshEditSession(source,ops),frame):null;
|
|
156
|
+
}));
|
|
157
|
+
const eligible=restored.filter(edit=>edit!==null);
|
|
158
|
+
return {stored,edits:[...edits,...eligible],stale:eligible.length!==keys.size,versions};
|
|
159
|
+
};
|
|
160
|
+
const scanJobDraft=()=>{
|
|
161
|
+
const modelHash=job?.modelHash(),text=draft.value;
|
|
162
|
+
if(!modelHash)return;
|
|
163
|
+
if(jobScan?.text===text&&jobScan.modelHash===modelHash&&jobScan.version===jobVersion)return jobScan;
|
|
164
|
+
const scan:JobDraftScan={text,modelHash,version:jobVersion,pending:readJobDraft(text,modelHash)};
|
|
165
|
+
jobScan=scan;
|
|
166
|
+
void scan.pending.then(result=>{
|
|
167
|
+
scan.result=result;
|
|
168
|
+
if(!disposed&&jobScan===scan&&draft.value===text&&job?.modelHash()===modelHash){sync();host.changed();}
|
|
169
|
+
},()=>{});
|
|
170
|
+
return scan;
|
|
171
|
+
};
|
|
172
|
+
const hasJobEdits=()=>!!scanJobDraft()?.result?.edits.length;
|
|
173
|
+
const jobEdits=async():Promise<JobMeshDraftSubmission|null>=>{
|
|
174
|
+
for(let scan=scanJobDraft();scan;scan=scanJobDraft()){
|
|
175
|
+
const submitted=scan,result=await submitted.pending;
|
|
176
|
+
if(submitted===scanJobDraft())return {edits:result.edits,clear:accepted=>clearJobDraft(submitted,result,accepted)};
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
};
|
|
180
|
+
if(host.job){status.style.whiteSpace='normal';status.setAttribute('translate','no');}
|
|
115
181
|
let active=false,entering=false,applying=false,mode:MeshMode|null=null,session:MeshEditSession|null=null,space=false,drag:Drag|null=null,pending:number|null=null,hover:ReturnType<typeof hitMesh>=null,note='',noteError=false,appliedOutcome='';
|
|
116
182
|
let preview:MeshView|null=null;const selected=new Set<number>();
|
|
117
183
|
const view=()=>preview??session?.view()??null;
|
|
@@ -126,23 +192,56 @@ export function bindMeshEditor(host:MeshEditorHost):MeshEditor {
|
|
|
126
192
|
edges:'click vertex A then start vertex B to add a constraint edge · click a constraint edge to remove it'.replace('start ',''),
|
|
127
193
|
};
|
|
128
194
|
const sync=()=>{
|
|
195
|
+
if(job&&jobDraftText!==draft.value){
|
|
196
|
+
jobDraftText=draft.value;jobDrafts.clear();
|
|
197
|
+
if(active){void reenter();return;}
|
|
198
|
+
}
|
|
199
|
+
const held=scanJobDraft()?.result;
|
|
129
200
|
const visible=meshEditVisible(host.inspector());toggle.hidden=!visible;
|
|
201
|
+
if(host.readOnly)toggle.disabled=true;
|
|
130
202
|
if(!visible&&active){setActive(false);return;}
|
|
131
203
|
if(!host.applied()&¬e.startsWith('Applied mesh edit ')){appliedOutcome='';note='';noteError=false;}
|
|
132
204
|
toggle.setAttribute('aria-pressed',String(active));bar.hidden=!active;
|
|
133
205
|
for(const button of bar.querySelectorAll<HTMLButtonElement>('[data-mesh-mode]'))button.setAttribute('aria-pressed',String(button.dataset.meshMode===mode));
|
|
134
|
-
node<HTMLButtonElement>('mesh-undo').disabled=!session?.canUndo();node<HTMLButtonElement>('mesh-redo').disabled=!session?.canRedo();node<HTMLButtonElement>('mesh-reset').disabled=!session?.canUndo()&&!session?.ops().length&&!host.applied();
|
|
206
|
+
node<HTMLButtonElement>('mesh-undo').disabled=!session?.canUndo();node<HTMLButtonElement>('mesh-redo').disabled=!session?.canRedo();node<HTMLButtonElement>('mesh-reset').disabled=!session?.canUndo()&&!session?.ops().length&&!host.applied();apply.disabled=!!host.readOnly||applying||!!host.job;
|
|
135
207
|
if(!session){status.textContent=host.applied()&&appliedOutcome?appliedOutcome:'';status.classList.toggle('error',noteError);return;}
|
|
136
208
|
const s=session.source,count=session.ops().length;
|
|
137
|
-
|
|
138
|
-
|
|
209
|
+
const summary=`${note?note+' · ':''}${count} op${count===1?'':'s'} · setup pose · ${MESH_EDIT_PREVIEW_NOTE} · ${mode?hint[mode]:'no sub-mode — Escape again leaves mesh edit'} · Space-drag pans`;
|
|
210
|
+
const reason=host.job==='read-only'?t('JOB_REVIEW_READ_ONLY'):job?
|
|
211
|
+
t('In a job, press Request changes to send this edit; the producer rebuilds it.'):null;
|
|
212
|
+
const readout=host.job?[reason,held?.stale?t('job.mesh.staleDraft'):null,tr(summary)].filter(Boolean).join(' · '):summary;
|
|
213
|
+
status.textContent=readout;
|
|
214
|
+
status.title=t('{0} / {1} / {2} · {3} vertices · {4} triangles · hull {5} · {6}',
|
|
215
|
+
[s.slot,s.skin,s.attachment,s.vertices.length,s.triangles.length/3,s.hull,readout],host.job?undefined:'en');
|
|
139
216
|
status.classList.toggle('error',noteError);
|
|
140
217
|
if(mode)host.pane.dataset.meshMode=mode;else delete host.pane.dataset.meshMode;
|
|
141
218
|
};
|
|
142
219
|
const say=(text:string,error=false)=>{if(text.startsWith('Applied mesh edit '))appliedOutcome=text;else if(!text)appliedOutcome='';note=text;noteError=error;if(text)host.message(text,error);sync();};
|
|
143
220
|
const setStatusNote=(text:string,error=false)=>{appliedOutcome=text.startsWith('Applied mesh edit ')?text:'';note=text;noteError=error;sync();};
|
|
221
|
+
const writeDraft=(text:string)=>{draft.value=text;jobDraftText=text;draft.dispatchEvent(new Event('input',{bubbles:true}));};
|
|
144
222
|
// While a delta revision is on the stage the draft keeps the delta that built it: edits over the revision are not written.
|
|
145
|
-
const persist=()=>{if(!session||host.applied())return;const text=writeMeshDraft(parseMeshDraft(draft.value),session.source,session.ops());if(text.length>32768){say('MESH_EDIT_DRAFT_LIMIT: the local draft is full — download the JSON; edits after this are not kept on reload',true);return;}
|
|
223
|
+
const persist=()=>{if(!session||host.applied())return;if(job)jobVersions.set(draftKey(session.source),++jobVersion);const text=writeMeshDraft(parseMeshDraft(draft.value),session.source,session.ops());if(text.length>32768){say('MESH_EDIT_DRAFT_LIMIT: the local draft is full — download the JSON; edits after this are not kept on reload',true);return;}writeDraft(text);};
|
|
224
|
+
/** Acknowledge the snapshot per attachment so a later edit, even on the same mesh, survives. */
|
|
225
|
+
const clearJobDraft=(scan:JobDraftScan,sent:JobDraftScanResult,accepted:readonly JobMeshEditValue[])=>{
|
|
226
|
+
const stored=parseMeshDraft(draft.value);
|
|
227
|
+
let text=draft.value,cleared=false;
|
|
228
|
+
for(const edit of accepted){
|
|
229
|
+
const key=draftKey(edit),before=sent.stored.entries[key],now=stored.entries[key];
|
|
230
|
+
if(jobVersions.get(key)!==sent.versions.get(key)||JSON.stringify(now)!==JSON.stringify(before))continue;
|
|
231
|
+
const live=jobDrafts.get(key);
|
|
232
|
+
if(live&&live.session===session&&drag&&'ops' in drag&&drag.ops.length)continue;
|
|
233
|
+
if(now?.hash===edit.source.hash){text=writeMeshDraft(stored,{...edit,hash:edit.source.hash},[]);delete stored.entries[key];}
|
|
234
|
+
if(live?.modelHash===scan.modelHash&&live.session.source.hash===edit.source.hash){
|
|
235
|
+
live.session.reset();
|
|
236
|
+
if(live.session===session){drag=null;preview=null;selected.clear();pending=null;note='';noteError=false;}
|
|
237
|
+
}
|
|
238
|
+
cleared=true;
|
|
239
|
+
}
|
|
240
|
+
if(!cleared)return;
|
|
241
|
+
++jobVersion;
|
|
242
|
+
if(text!==draft.value)writeDraft(text);
|
|
243
|
+
if(!disposed){sync();host.changed();}
|
|
244
|
+
};
|
|
146
245
|
/** Reports a step: a refusal by its code, a no-op by its reason, a change by what it did. */
|
|
147
246
|
const after=(result:MeshEditResult,what:()=>string)=>{
|
|
148
247
|
if(!result.ok)say(result.code,true);
|
|
@@ -155,11 +254,17 @@ export function bindMeshEditor(host:MeshEditorHost):MeshEditor {
|
|
|
155
254
|
const leave=()=>{active=false;mode=null;session=null;drag=null;preview=null;pending=null;hover=null;selected.clear();note='';delete host.pane.dataset.meshHover;delete host.pane.dataset.meshMode;};
|
|
156
255
|
const setActive=(on:boolean)=>{if(!on){leave();sync();host.changed();return;}void enter();};
|
|
157
256
|
const enter=async()=>{
|
|
158
|
-
if(entering)return;entering=true;
|
|
257
|
+
if(host.readOnly||entering)return;entering=true;
|
|
159
258
|
try{
|
|
160
259
|
const result=host.source();if(!result.ok){leave();sync();host.message(result.code,true);host.changed();return;}
|
|
260
|
+
const modelHash=job?.modelHash(),mapping=job?host.mapping():null;
|
|
161
261
|
const hash=await sha256Hex(attachmentHashText(result.entry)),source:MeshSource={...result.source,hash};
|
|
162
|
-
|
|
262
|
+
if(disposed||modelHash!==job?.modelHash())return;
|
|
263
|
+
if(job&&jobDraftText!==draft.value){jobDraftText=draft.value;jobDrafts.clear();}
|
|
264
|
+
const key=draftKey(source),prior=jobDrafts.get(key);
|
|
265
|
+
const restored=prior&&prior.modelHash===modelHash&&prior.session.source.hash===hash?prior.session.ops():draftOps(parseMeshDraft(draft.value),source);
|
|
266
|
+
session=new MeshEditSession(source,restored??[]);
|
|
267
|
+
if(modelHash&&mapping?.available)jobDrafts.set(key,{session,frame:{width:mapping.crop.w,height:mapping.crop.h},modelHash});
|
|
163
268
|
if(chestToggle?.getAttribute('aria-pressed')==='true')chestToggle.click();
|
|
164
269
|
host.pause();active=true;mode='modify';selected.clear();pending=null;note=host.applied()&&appliedOutcome?appliedOutcome:restored?.length?`restored ${restored.length} draft op${restored.length===1?'':'s'}`:'';noteError=false;
|
|
165
270
|
sync();host.changed();
|
|
@@ -181,8 +286,8 @@ export function bindMeshEditor(host:MeshEditorHost):MeshEditor {
|
|
|
181
286
|
node<HTMLButtonElement>('mesh-download').addEventListener('click',()=>{if(session)host.download(meshEditDocument(session));});
|
|
182
287
|
// #135: the delta goes to the producer (`rig-parts remesh --delta`) through the host's shared runner; a built revision
|
|
183
288
|
// loads in place and the editor re-reads its setup mesh; a refusal shows the producer's line verbatim and keeps the delta.
|
|
184
|
-
|
|
185
|
-
if(
|
|
289
|
+
apply.addEventListener('click',()=>{
|
|
290
|
+
if(host.readOnly||!session||applying||host.job)return;
|
|
186
291
|
if(!session.ops().length){say(MESH_EDIT_NOTHING_PENDING,true);return;}
|
|
187
292
|
const doc=meshEditDocument(session);applying=true;say(`Applying ${doc.ops.length} op(s) on ${doc.slot}: remesh --delta, compile…`);
|
|
188
293
|
void (async()=>{
|
|
@@ -297,12 +402,17 @@ export function bindMeshEditor(host:MeshEditorHost):MeshEditor {
|
|
|
297
402
|
if(!active||!session)return;const result=host.source();
|
|
298
403
|
if(!result.ok){leave();sync();host.message(result.code,true);host.changed();return;}
|
|
299
404
|
if(result.source.slot!==session.source.slot||result.source.attachment!==session.source.attachment||result.source.skin!==session.source.skin){leave();void enter();return;}
|
|
405
|
+
if(job&&jobDrafts.get(draftKey(session.source))?.modelHash!==job.modelHash()){void reenter();return;}
|
|
300
406
|
const current=session;
|
|
301
407
|
void sha256Hex(attachmentHashText(result.entry)).then(hash=>{if(active&&session===current&&hash!==current.source.hash)void reenter();});
|
|
302
408
|
};
|
|
409
|
+
const draftChanged=()=>{if(jobDraftText!==draft.value){sync();host.changed();}};
|
|
410
|
+
if(job)draft.addEventListener('input',draftChanged);
|
|
411
|
+
const unsubscribeLanguage=host.job?onLanguageChange(sync):null;
|
|
303
412
|
sync();
|
|
304
413
|
return {
|
|
305
414
|
active:()=>active,overlay,sync,selectionChanged,session:()=>session,mode:()=>mode,statusNote:()=>note||appliedOutcome,setStatusNote,
|
|
306
|
-
|
|
415
|
+
hasJobEdits,jobEdits,
|
|
416
|
+
dispose:()=>{disposed=true;unsubscribeLanguage?.();draft.removeEventListener('input',draftChanged);observer.disconnect();chestObserver.disconnect();host.pane.removeEventListener('pointerdown',down,true);host.pane.removeEventListener('pointermove',move,true);for(const type of ['pointerup','pointercancel'] as const)host.pane.removeEventListener(type,end,true);document.removeEventListener('keydown',keyDown,true);window.removeEventListener('keyup',keyUp,true);window.removeEventListener('blur',blur);},
|
|
307
417
|
};
|
|
308
418
|
}
|
package/web/part-selection.ts
CHANGED
|
@@ -184,7 +184,7 @@ const key=this.viewKey();if(!force&&key===this.selectionKey)return;this.selectio
|
|
|
184
184
|
if(this.images){
|
|
185
185
|
const selected=this.images.items.find(item=>item.name===this.images!.selected());
|
|
186
186
|
setSourceText(nodes.title,selected?.name??'Assembled parts');
|
|
187
|
-
setSourceText(nodes.info
|
|
187
|
+
setSourceText(nodes.info,`${selected?t('Original part image · {name}',{name:selected.name}):t('Select a part to inspect its original image source.')}${selected?' · ':' '}${t('There is no compiled rig yet, so some tools and tabs are unavailable.')}`);
|
|
188
188
|
setSourceText(nodes.declarations,selected?.imageHash?t('Source image SHA-256 · {hash}',{hash:selected.imageHash}):'');
|
|
189
189
|
nodes.declarations.hidden=!selected?.imageHash;
|
|
190
190
|
for(const node of [nodes.bounds,nodes.unavailable,nodes.feedback,nodes.status])node.hidden=true;
|
|
@@ -59,7 +59,6 @@ import {paintAssembly,paintMesh,paintOverlay,paintPaintingCrop,pickAssembly,type
|
|
|
59
59
|
import {bindStageComments,type CommentCodec,type CommentUiPose,type CommentRow} from './stage-comments.ts';
|
|
60
60
|
import {parsePartsIssue,assertPartsIssueBinding,snapImageRegion,type PartsIssue} from '../src/parts-comment.ts';
|
|
61
61
|
import {projectMark,unprojectMark,region} from '../src/stage-comment.ts';
|
|
62
|
-
import {EMIT_UNPINNED_CREATE_FIELDS} from '../src/create-pin-gate.ts';
|
|
63
62
|
/** U5 uses the same native raster paint path as a parts subject, with the whole rig as one operand. */
|
|
64
63
|
export function paintRigDifference(canvas:HTMLCanvasElement,still:HTMLCanvasElement,painting:HTMLImageElement) {
|
|
65
64
|
assertOriginalPaintingSize(painting.naturalWidth,painting.naturalHeight,[still.width,still.height],1);
|
|
@@ -77,11 +76,13 @@ export type PartsSubjectData=ReturnType<typeof partsViewJson>;
|
|
|
77
76
|
export interface PartsSubjectEntry {subject:'parts';parts:PartsSubjectData}
|
|
78
77
|
export interface PartsSubjectSession {subject:'parts';issues:PartsIssue[]}
|
|
79
78
|
type Item=PartsSubjectData['items'][number];
|
|
79
|
+
type DifferenceOperand='painting'|'previous-draft';
|
|
80
80
|
interface PartsPose extends CommentUiPose {item:Item;sourceHash:string;view:PartsIssue['view']}
|
|
81
81
|
/** Source-specific pixels and evidence. Shell, list, toolbar, controller and act stay in main.ts. */
|
|
82
82
|
export function bindPartsSubject(host:{
|
|
83
83
|
data:PartsSubjectData;canvas:HTMLCanvasElement;referenceCanvas:HTMLCanvasElement;viewport:ViewportController;
|
|
84
84
|
el:ViewportProvider['el'];toolbar:HTMLElement;commentsHost:HTMLElement;openComments?:()=>void;hasPicture?:()=>boolean;issues:PartsIssue[];recordComments?:CommentRow[];
|
|
85
|
+
generalComments?:{rows:CommentRow[];available:()=>boolean};submitting?:()=>boolean;
|
|
85
86
|
request:(path:string,init?:RequestInit)=>Promise<Response>;base:string;paintingPath:string;
|
|
86
87
|
mesh:()=>boolean;restoreMesh:(on:boolean)=>void;images:()=>boolean;changed:()=>void|Promise<void>;selectionChanged:()=>void;locked:(id:string)=>boolean;refusal:()=>string|null;drawn:(input:{state:'loaded'}|{state:'failed';reason:string})=>void;message:ViewportProvider['message'];
|
|
87
88
|
}) {
|
|
@@ -95,6 +96,8 @@ export function bindPartsSubject(host:{
|
|
|
95
96
|
const makeCanvas=(w:number,h:number)=>Object.assign(document.createElement('canvas'),{width:w,height:h});
|
|
96
97
|
const item=()=>data.items.find(item=>item.name===selected)??data.items[0]!;
|
|
97
98
|
const assembled=()=>!solo||selected===null;
|
|
99
|
+
const paintingDifferenceAvailable=()=>data.differenceAvailable&&!!data.painting;
|
|
100
|
+
const previousDraftAvailable=()=>assembled()&&!!data.rigSize&&!!data.previousDraft;
|
|
98
101
|
const box=():Box=>assembled()&&data.rigSize?{name:'',index:0,x:0,y:0,w:data.rigSize[0],h:data.rigSize[1]}:item();
|
|
99
102
|
const loadImage=async(path:string):Promise<HTMLImageElement>=>{
|
|
100
103
|
const image=await loadViewportImage(await host.request(path));
|
|
@@ -106,7 +109,6 @@ export function bindPartsSubject(host:{
|
|
|
106
109
|
const partsBinding=(names:readonly string[])=>names.map(name=>{const entry=data.items.find(item=>item.name===name);if(!entry?.imageHash)throw new Error('PARTS_COMMENT_PART_MISMATCH');return {name,imageHash:entry.imageHash};});
|
|
107
110
|
const sourceItems=()=>new Map(data.items.map(item=>[item.name,{...item,imageHash:item.imageHash!}]));
|
|
108
111
|
async function prepare(issue:PartsIssue):Promise<PartsIssue>{
|
|
109
|
-
if(!EMIT_UNPINNED_CREATE_FIELDS&&Object.hasOwn(issue.view,'visibleLayers')){const {visibleLayers:_ignored,...view}=issue.view;issue={...issue,view};}
|
|
110
112
|
const bound=parsePartsIssue(issue,false,false,false);assertPartsIssueBinding(bound,sourceItems(),data.sourceHash);
|
|
111
113
|
const response=await host.request(`${host.base}/comment`,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(bound)});
|
|
112
114
|
if(disposed)throw new Error('PARTS_COMMENT_STALE_SOURCE');return parsePartsIssue((await response.json()).comment,true,false,false);
|
|
@@ -117,7 +119,8 @@ export function bindPartsSubject(host:{
|
|
|
117
119
|
const bitmaps:ImageBitmap[]=[];
|
|
118
120
|
try{
|
|
119
121
|
if(data.mode!=='parts'||!data.items.length)throw new Error('PARTS_IMAGE_UNAVAILABLE');
|
|
120
|
-
const
|
|
122
|
+
const inAssembly=assembled(),settings=comparison;
|
|
123
|
+
const frame=box(),referenceBox=selected===null?null:item(),shown=inAssembly?data.items.filter(item=>!hidden.has(item.name)):[item()];
|
|
121
124
|
const layers=await Promise.all(shown.map(async entry=>{const img=await image(entry);loaded.set(entry.name,img);return {box:entry,image:img};}));
|
|
122
125
|
let reference:HTMLCanvasElement|null=null;
|
|
123
126
|
if(data.painting&&data.rigSize){
|
|
@@ -126,10 +129,19 @@ export function bindPartsSubject(host:{
|
|
|
126
129
|
if(referenceBox)paintPaintingCrop(reference.getContext('2d')!,original,paintingRectangle(referenceBox,data.rigSize,data.painting),referenceBox.w,referenceBox.h,'checker');
|
|
127
130
|
else reference.getContext('2d')!.drawImage(original,0,0);
|
|
128
131
|
}
|
|
132
|
+
if(disposed||navigation!==token)return;
|
|
129
133
|
const raster=makeCanvas(frame.w,frame.h),ctx=raster.getContext('2d')!;
|
|
130
|
-
if(
|
|
134
|
+
if(settings.mode==='difference'){
|
|
135
|
+
const previous=settings.operand==='previous-draft';
|
|
136
|
+
if(previous&&!previousDraftAvailable())throw new Error('PARTS_DIFFERENCE_UNAVAILABLE');
|
|
137
|
+
const suffix=previous?'&operand=previous-draft':'';
|
|
131
138
|
const differences=[];
|
|
132
|
-
for(const entry of
|
|
139
|
+
for(const entry of previous?[frame]:shown){
|
|
140
|
+
const response=await host.request(`${host.base}/difference/${entry.index}?threshold=${settings.threshold}&footprints=false${suffix}`);
|
|
141
|
+
const bitmap=await createImageBitmap(await response.blob());
|
|
142
|
+
bitmaps.push(bitmap);
|
|
143
|
+
differences.push({box:inAssembly?entry:{...entry,x:0,y:0},image:bitmap});
|
|
144
|
+
}
|
|
133
145
|
paintAssembly(ctx,frame.w,frame.h,differences,{bg:'checker',alpha:false,transparent:true});
|
|
134
146
|
}else if(comparison.mode==='overlay'&&data.painting&&data.rigSize){
|
|
135
147
|
const original=await painting();
|
|
@@ -194,11 +206,14 @@ export function bindPartsSubject(host:{
|
|
|
194
206
|
const pose=():PartsPose|null=>{
|
|
195
207
|
let camera=host.viewport.numericView().cameras.rig;const entry=item();if(!camera||!entry||busy||failed||disposed)return null;
|
|
196
208
|
if(data.painting&&!assembled())camera={...camera,center:{x:camera.center.x-entry.x,y:camera.center.y-entry.y},visible:{...camera.visible,x:camera.visible.x-entry.x,y:camera.visible.y-entry.y}};
|
|
197
|
-
return {mode:'parts',item:entry,sourceHash:data.sourceHash,camera,view:{mode:assembled()?'assembled':'item',camera:{zoom:camera.zoom,center:camera.center,viewport:camera.viewport},cameraSync:host.viewport.state.cameraSync,referenceCamera:null,background:'checker',alpha:false,footprints:false,mesh:host.mesh(),comparison:{...comparison},...(assembled()
|
|
209
|
+
return {mode:'parts',item:entry,sourceHash:data.sourceHash,camera,view:{mode:assembled()?'assembled':'item',camera:{zoom:camera.zoom,center:camera.center,viewport:camera.viewport},cameraSync:host.viewport.state.cameraSync,referenceCamera:null,background:'checker',alpha:false,footprints:false,mesh:host.mesh(),comparison:{...comparison},...(assembled()?{visibleLayers:partsBinding(data.items.filter(item=>!hidden.has(item.name)).map(item=>item.name))}:{})},capture:{pane:host.el('rig-viewport'),root:host.el('rig-root'),images:true,canvas:host.canvas,backend:'canvas2d',nearest:true}};
|
|
198
210
|
};
|
|
199
|
-
comments=bindStageComments<CommentRow,PartsPose>({general:host.recordComments
|
|
211
|
+
comments=bindStageComments<CommentRow,PartsPose>({general:host.recordComments||host.generalComments?{
|
|
212
|
+
create:summary=>({id:crypto.randomUUID(),summary}),matches:row=>!('schema' in row),
|
|
213
|
+
...(host.generalComments?{...host.generalComments,refusal:host.refusal}:{}),
|
|
214
|
+
}:undefined,toolbar:host.toolbar,listHost:host.commentsHost,openList:host.openComments,hasPicture:host.hasPicture,toggle:host.el<HTMLButtonElement>('stage-comment'),viewports:{rig:host.el('rig-viewport')},pose,pause:async()=>{},bookmark:()=>null,
|
|
200
215
|
restore:async raw=>{const issue=parsePartsIssue(raw,false,true,false);assertPartsIssueBinding(issue,sourceItems(),data.sourceHash);selected=issue.view.mode==='item'?issue.parts[0]!.name:null;solo=issue.view.mode==='item';comparison=issue.view.comparison??defaultPartsComparison();host.restoreMesh(issue.view.mesh);if(issue.view.visibleLayers){const visible=new Set(issue.view.visibleLayers.map(part=>part.name));hidden.clear();for(const item of data.items)if(!visible.has(item.name))hidden.add(item.name);}await paint();host.viewport.writeCamera('rig',data.painting&&solo?{...issue.view.camera,center:{x:issue.view.camera.center.x+item().x,y:issue.view.camera.center.y+item().y}}:issue.view.camera);host.viewport.activateCamera('rig');if(host.viewport.state.cameraSync)host.viewport.alignCameras();host.viewport.fitCamera();host.selectionChanged();},
|
|
201
|
-
feedback:()=>host.recordComments??host.issues,locked:host.locked,refusal:host.refusal,add:row=>{if(host.recordComments)host.recordComments.push(row);else host.issues.push(row as PartsIssue);},changed:host.changed,error:host.message,blocked:()=>busy||failed||disposed,busy:()=>busy,codec});
|
|
216
|
+
feedback:()=>host.recordComments??host.issues,locked:host.locked,refusal:host.refusal,add:row=>{if(host.recordComments)host.recordComments.push(row);else host.issues.push(row as PartsIssue);},changed:host.changed,error:host.message,blocked:()=>busy||failed||disposed||!!host.submitting?.(),busy:()=>busy,codec});
|
|
202
217
|
return {
|
|
203
218
|
frameSize:(target:CameraTarget):PartsFrame|null=>{
|
|
204
219
|
const frame=target==='rig'?drawnFrame:drawnReferenceFrame;if(!frame||!data.painting||!data.rigSize)return frame;
|
|
@@ -210,10 +225,30 @@ export function bindPartsSubject(host:{
|
|
|
210
225
|
},
|
|
211
226
|
image:(index:number)=>{const entry=data.items.find(item=>item.index===index);if(!entry)return Promise.reject(new Error('PARTS_IMAGE_UNAVAILABLE'));return image(entry);},
|
|
212
227
|
items:()=>data.items,sourceHash:()=>data.sourceHash,refreshComments:()=>comments?.refresh(),selected:()=>selected,solo:()=>solo,visible:(name:string)=>!hidden.has(name),issues:()=>host.issues,
|
|
213
|
-
select:(name:string|null)=>{selected=name;if(name===null)solo=false;redraw();host.selectionChanged();},
|
|
228
|
+
select:(name:string|null)=>{selected=name;if(name===null)solo=false;redraw();host.selectionChanged();},
|
|
229
|
+
isolate:(value:boolean)=>{
|
|
230
|
+
solo=value;
|
|
231
|
+
if(!assembled()&&comparison.mode==='difference'&&comparison.operand==='previous-draft'){
|
|
232
|
+
const {opacity,threshold}=comparison;
|
|
233
|
+
comparison=paintingDifferenceAvailable()?{mode:'difference',opacity,threshold}:{mode:'part',opacity};
|
|
234
|
+
}
|
|
235
|
+
redraw();host.selectionChanged();
|
|
236
|
+
},
|
|
214
237
|
show:(name:string,value:boolean)=>{if(value)hidden.delete(name);else hidden.add(name);redraw();},
|
|
215
|
-
differenceAvailable:()
|
|
216
|
-
|
|
238
|
+
differenceAvailable:()=>!failed&&(paintingDifferenceAvailable()||previousDraftAvailable()),
|
|
239
|
+
paintingDifferenceAvailable,previousDraftAvailable,
|
|
240
|
+
comparison:()=>comparison,
|
|
241
|
+
setComparison:async(mode:PartsComparison['mode'],operand?:DifferenceOperand)=>{
|
|
242
|
+
const paintingAvailable=paintingDifferenceAvailable();
|
|
243
|
+
const usePrevious=operand==='previous-draft'||(operand===undefined&&!paintingAvailable);
|
|
244
|
+
if(mode==='difference'&&!(usePrevious?previousDraftAvailable():paintingAvailable))return false;
|
|
245
|
+
const opacity=comparison.opacity;
|
|
246
|
+
const next:PartsComparison=mode==='difference'
|
|
247
|
+
? {mode,opacity,threshold:0,...(usePrevious?{operand:'previous-draft' as const}:{})}
|
|
248
|
+
: {mode,opacity};
|
|
249
|
+
comparison=next;const navigation=token+1;
|
|
250
|
+
try{await paint();return !disposed&&navigation===token&&comparison===next;}catch{return false;}
|
|
251
|
+
},
|
|
217
252
|
opacity:(value:number)=>{comparison.opacity=value;redraw();},paint,redraw,
|
|
218
253
|
async ready(){if(data.painting)host.viewport.state.cameraSync=true;await paint();},
|
|
219
254
|
dispose(){disposed=true;++token;comments?.dispose();images.clear();loaded.clear();assemblyAlpha.clear();},
|
package/web/rig-host.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type {InspectionBookmark} from './inspection-persistence.ts';
|
|
|
8
8
|
import type {ControlView} from '../src/control.ts';
|
|
9
9
|
import type {InstanceAccess} from './instance-access.ts';
|
|
10
10
|
import type {JobRigStage} from './job-rig-capture.ts';
|
|
11
|
+
import type {CommentRow} from './stage-comments.ts';
|
|
11
12
|
|
|
12
13
|
/** The rig pane as the screen holds it now, for the job's still. */
|
|
13
14
|
export type RigHostStage = Omit<JobRigStage, 'source' | 'presentation'> & {
|
|
@@ -43,11 +44,12 @@ export interface RigHost {
|
|
|
43
44
|
readonly subject?:'parts';
|
|
44
45
|
readonly unavailable?:string;
|
|
45
46
|
readonly direction?:{readonly publicationId:string;readonly sourceHash:string};
|
|
47
|
+
readonly verdictComments?:{readonly publicationId:string;readonly sourceHash:string;readonly rows:CommentRow[];readonly available:()=>boolean};
|
|
46
48
|
readonly navigation?:RigHostNavigation;
|
|
47
49
|
/** Derived from the displayed subject's finalized verdict; never a mode or another subject's act. */
|
|
48
50
|
reviewState?(issues:number,sending:boolean):string;
|
|
49
|
-
readonly record?:{readonly publicationId?:string;readonly label:string;readonly sourceHash:string;readonly hasPicture:boolean};
|
|
50
|
-
submitParts?(issues:readonly PartsIssue[]):Promise<string>;
|
|
51
|
+
readonly record?:{readonly publicationId?:string;readonly label:string;readonly sourceHash:string;readonly hasPicture:boolean;readonly missingPicture?:'rig'|'scene';readonly scenePicture?:true};
|
|
52
|
+
submitParts?(issues:readonly PartsIssue[], general?:readonly string[]):Promise<string>;
|
|
51
53
|
readonly access: InstanceAccess;
|
|
52
54
|
/** UI act authority is separate from a retained backdrop's immutable source access. */
|
|
53
55
|
readonly ownerActAccess?: Pick<InstanceAccess, 'capability'>;
|
|
@@ -56,7 +58,7 @@ export interface RigHost {
|
|
|
56
58
|
/** A read the host answers itself, or undefined to fetch it from the subject's routes. */
|
|
57
59
|
read(path: string, method: string): Promise<unknown> | undefined;
|
|
58
60
|
/** The act bar's Submit review: the session's decisions go out as the pending asks' acts. */
|
|
59
|
-
submit(session: ReviewSession, committed: (commit: RigHostCommit) => void | Promise<void>, directionWords?:string): Promise<string>;
|
|
61
|
+
submit(session: ReviewSession, committed: (commit: RigHostCommit) => void | Promise<void>, directionWords?:string, general?:readonly string[]): Promise<string>;
|
|
60
62
|
attach(screen: RigHostScreen): void;
|
|
61
63
|
/** The first rig draw is on screen (or the open failed): the job acknowledges the display after it. */
|
|
62
64
|
displayed(): void;
|
package/web/stage-comments.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type {ControlNumericCamera} from '../src/control.ts';
|
|
|
6
6
|
import {drawnSlots,region,projectMark,unprojectMark,parseStageComment,feedbackTimingLabel,type MarkRegion,type MarkPoint,type StageComment} from '../src/stage-comment.ts';
|
|
7
7
|
import {getLanguage as i18nLang,onLanguageChange as i18nOnChange,t as i18nT,tr as i18nTr} from './i18n.ts';
|
|
8
8
|
import {panSpaceHeld,textEntryFocused} from './view-controls.ts';
|
|
9
|
+
import {boxesIntersect} from './label-placement.ts';
|
|
9
10
|
export interface CommentPose {
|
|
10
11
|
mode:StageComment['mode'];camera:ControlNumericCamera;frame:StageComment['frame'];timeBasis?:StageComment['timeBasis'];time:number;animation:string|null;
|
|
11
12
|
turn:unknown;sourceHash:string;modelHash:string|null;referenceHash:string|null;referenceId:string|null;frameReason?:string;
|
|
@@ -30,7 +31,7 @@ interface Host<Row extends CommentRow=Feedback,Pose extends CommentUiPose=Commen
|
|
|
30
31
|
bookmark:()=>unknown;restore:(bookmark:unknown,timeOnly?:boolean)=>Promise<void>;
|
|
31
32
|
feedback:()=>Row[];locked:(id:string)=>boolean;
|
|
32
33
|
add:(feedback:Row,side?:'a'|'b')=>void;changed:()=>void|Promise<void>;error:(message:string)=>void;
|
|
33
|
-
general?:{create:(summary:string)=>Row;matches:(row:Row)=>boolean};
|
|
34
|
+
general?:{create:(summary:string)=>Row;matches:(row:Row)=>boolean;rows?:Row[];available?:()=>boolean;refusal?:()=>string|null};
|
|
34
35
|
refusal?:()=>string|null;blocked:()=>boolean;busy?:()=>boolean;busyError?:(message:string)=>void;shortcutBlocked?:()=>boolean;shortcutActive?:()=>boolean;codec?:CommentCodec<Row,Pose>;
|
|
35
36
|
}
|
|
36
37
|
const markOf=(f:Feedback):StageComment|null=>{try{const c=f.context as Record<string,unknown>|undefined;return c?.comment?parseStageComment(c.comment):null;}catch{return null;}};
|
|
@@ -40,6 +41,7 @@ const toEn=(s:string)=>typeof i18nTr==='function'?i18nTr(s,'en'):s;
|
|
|
40
41
|
const onLang=(fn:()=>void)=>typeof i18nOnChange==='function'?i18nOnChange(fn):()=>{};
|
|
41
42
|
const curLang=()=>typeof i18nLang==='function'?i18nLang():'en';
|
|
42
43
|
const spaceHeld=()=>typeof panSpaceHeld==='function'&&panSpaceHeld();
|
|
44
|
+
const resizeHandles=[['nw',0,0],['n',.5,0],['ne',1,0],['e',1,.5],['se',1,1],['s',.5,1],['sw',0,1],['w',0,.5]] as const;
|
|
43
45
|
function rectElement(r:MarkRegion):HTMLDivElement{const node=document.createElement('div');node.className='stage-comment-region';Object.assign(node.style,{left:r.x+'px',top:r.y+'px',width:Math.max(2,r.width)+'px',height:Math.max(2,r.height)+'px'});return node;}
|
|
44
46
|
async function crop(pose:CommentUiPose,r:MarkRegion):Promise<StageComment['crop']>{
|
|
45
47
|
if(!pose.capture)throw new Error(t('COMMENT_CROP_UNAVAILABLE: viewport pixel source unavailable'));
|
|
@@ -86,7 +88,9 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
|
|
|
86
88
|
const setCapture=(value:boolean)=>{value=value&&host.hasPicture?.()!==false;enabled=value;toggle.setAttribute('aria-pressed',String(value||!inline&&!list.hidden));for(const pane of Object.values(host.viewports))pane!.classList.toggle('stage-comment-mode',value);};
|
|
87
89
|
const cancel=()=>{++interaction;const previous=pending??(geometryDrag&&geometryEdit?{view:geometryEdit.view,id:geometryDrag.id}:pinPress);geometryEdit=null;geometryDrag=null;pinPress=null;pending=null;if(previous){const pane=host.viewports[previous.view];if(pane?.hasPointerCapture(previous.id))pane.releasePointerCapture(previous.id);}composer?.remove();composer=null;composerReadOnly=false;composerGeneral=false;syncComposerLang=null;draftMark=null;last='';};
|
|
88
90
|
const assertCapture=()=>{const reason=updateRefusal();if(reason){cancel();setCapture(false);host.error(reason);throw new Error(reason);}if(host.blocked())throw new Error(t('COMMENT_BUSY: wait for inspection'));};
|
|
89
|
-
const
|
|
91
|
+
const generalRefusal=()=>host.general?.refusal?.()??null;
|
|
92
|
+
const assertWritable=(reason:string|null)=>{if(reason){setCapture(false);host.error(reason);throw new Error(reason);}if(host.blocked())throw new Error(t('COMMENT_BUSY: wait for inspection'));};
|
|
93
|
+
const assertEdit=(general=false)=>assertWritable(general?(generalRefusal()??(host.general?.available?.()===false?t('JOB_ACT_NOTHING_TO_SUBMIT'):null)):updateRefusal());
|
|
90
94
|
let jumpGeneration = 0;
|
|
91
95
|
let hiddenPanes: {pane: HTMLElement; visibility: string}[] | null = null;
|
|
92
96
|
const jump = async (row: Row): Promise<boolean> => {
|
|
@@ -129,7 +133,7 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
|
|
|
129
133
|
setCapture(layers.size>0);for(const view of layers.keys())host.pose(view);
|
|
130
134
|
};
|
|
131
135
|
const openComment=async(f:Row)=>{const mark=readMark(f);if(!mark){if(host.general?.matches(f))openComposer(null,{x:0,y:0,width:0,height:0},f);return;}if(list.hidden)setOpen(true);if(list.hidden)return;if(await jump(f)){const reason=updateRefusal();setCapture(!reason&&!host.blocked());const pose=host.pose(mark.viewport),screen=host.codec?.geometry&&pose?region(projectMark(mark.world,pose.camera),projectMark({x:mark.world.x+mark.world.width,y:mark.world.y+mark.world.height},pose.camera)):mark.screen;openComposer(mark.viewport,screen,f,pose?.mode??mark.mode);}};
|
|
132
|
-
const renderList=()=>{placeList();list.setAttribute('aria-label',t('Comments'));list.replaceChildren();const title=document.createElement('strong');title.textContent=t('Comments');list.append(title);const rawReason=host.refusal?.()??null,reason=rawReason?t(rawReason):null;if(reason){const note=document.createElement('small');note.className='stage-comment-refusal-note';note.title=reason;note.textContent=reason;Object.assign(note.style,{display:'block',marginTop:'4px',maxWidth:'100%',whiteSpace:inline?'normal':'nowrap',overflow:'hidden',textOverflow:'ellipsis'});list.append(note);}if(host.general){const add=document.createElement('button');add.type='button';add.textContent=t('Add general comment');add.dataset.commentGeneral='';add.onclick=()=>openComposer(null,{x:0,y:0,width:0,height:0});list.append(add);}const all=host.feedback().filter(f=>readMark(f)||host.general?.matches(f));toggle.textContent=t(host.busy?.()?'Comment · C ({0}) · Rendering':'Comment · C ({0})').replace('{0}',String(all.length));if(!all.length){const empty=document.createElement('p');empty.textContent=t(inline?'No comments yet.':reason?'Read only · Escape closes':'Mark a point or region, then type. Enter saves · Escape cancels.');list.append(empty);}for(const [i,f]of all.entries()){
|
|
136
|
+
const renderList=()=>{placeList();list.setAttribute('aria-label',t('Comments'));list.replaceChildren();const title=document.createElement('strong');title.textContent=t('Comments');list.append(title);const rawReason=host.refusal?.()??null,reason=rawReason?t(rawReason):null;if(reason){const note=document.createElement('small');note.className='stage-comment-refusal-note';note.title=reason;note.textContent=reason;Object.assign(note.style,{display:'block',marginTop:'4px',maxWidth:'100%',whiteSpace:inline?'normal':'nowrap',overflow:'hidden',textOverflow:'ellipsis'});list.append(note);}if(host.general&&host.general.available?.()!==false){const add=document.createElement('button');add.type='button';add.textContent=t('Add general comment');add.dataset.commentGeneral='';add.onclick=()=>openComposer(null,{x:0,y:0,width:0,height:0});list.append(add);}const all=host.feedback().filter(f=>readMark(f)||host.general?.matches(f));if(host.general?.rows)all.push(...host.general.rows);toggle.textContent=t(host.busy?.()?'Comment · C ({0}) · Rendering':'Comment · C ({0})').replace('{0}',String(all.length));if(!all.length){const empty=document.createElement('p');empty.textContent=t(inline?'No comments yet.':reason?'Read only · Escape closes':'Mark a point or region, then type. Enter saves · Escape cancels.');list.append(empty);}for(const [i,f]of all.entries()){
|
|
133
137
|
const mark=readMark(f),row=document.createElement('div');row.className='stage-comment-item';row.dataset.commentId=f.id;
|
|
134
138
|
const go=document.createElement('button');go.type='button';go.className='stage-comment-summary';go.textContent=!mark?`${i+1} · ${t('General comment')} · ${f.summary}`:host.codec?`${i+1} · ${host.codec.label(f,mark)}`:`${i+1} · ${mark.mode.toUpperCase()} · ${mark.viewport.toUpperCase()} · ${mark.frame?`F${mark.frame.index} (${mark.frame.basis})`:t(feedbackTimingLabel(f as unknown as Feedback))} · ${f.summary}`;go.onclick=()=>openComment(f);row.append(go);
|
|
135
139
|
if(host.locked(f.id)){const submitted=document.createElement('span');submitted.textContent=t('Submitted');row.append(submitted);}
|
|
@@ -137,24 +141,80 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
|
|
|
137
141
|
}};
|
|
138
142
|
const refresh=()=>{last='';renderList();renderPins();};
|
|
139
143
|
const openComposer=(view:StageComment['viewport']|null,screen:MarkRegion,existing?:Row,placementMode=view?host.pose(view)?.mode:undefined)=>{
|
|
140
|
-
const general=view===null;
|
|
144
|
+
const general=view===null;
|
|
145
|
+
const generalAvailable=!general||host.general?.available?.()!==false;
|
|
146
|
+
if(general&&(!host.general||(!existing&&!generalAvailable)))return;
|
|
141
147
|
if(!existing){try{general?assertEdit(true):assertCapture();}catch{return;}}
|
|
142
148
|
const currentMode=view?host.pose(view)?.mode:undefined;
|
|
143
149
|
if(!general&&(!placementMode||currentMode&¤tMode!==placementMode)){cancel();return;}
|
|
144
|
-
const locked=!!existing&&host.locked(existing.id),initialRefusal=existing
|
|
150
|
+
const locked=!!existing&&host.locked(existing.id),initialRefusal=existing?(general?generalRefusal():updateRefusal()):null;
|
|
145
151
|
if(existing&&!initialRefusal&&host.blocked()){host.error(t('COMMENT_BUSY: wait for inspection'));return;}
|
|
146
|
-
geometryEdit=null;composer?.remove();composerReadOnly=locked||!!initialRefusal;composerGeneral=general;draftMark=view?{view,mode:placementMode!,screen}:null;const generation=interaction;const pane=view?host.viewports[view]!:list,form=composer=document.createElement('form');form.className='stage-comment-composer stage-comment-ui';form.setAttribute('aria-label',t('Comment composer'));if(general)form.style.position='relative';
|
|
152
|
+
geometryEdit=null;composer?.remove();composerReadOnly=locked||!!initialRefusal||!generalAvailable;composerGeneral=general;draftMark=view?{view,mode:placementMode!,screen}:null;const generation=interaction;const pane=view?host.viewports[view]!:list,form=composer=document.createElement('form');form.className='stage-comment-composer stage-comment-ui';form.setAttribute('aria-label',t('Comment composer'));if(general)form.style.position='relative';
|
|
147
153
|
const field=document.createElement('input');field.type='text';field.maxLength=1000;field.setAttribute('aria-label',t('Comment text'));field.placeholder=t('Describe this spot…');field.value=existing?.summary??'';
|
|
148
|
-
if(
|
|
154
|
+
if(composerReadOnly){field.readOnly=true;field.setAttribute('aria-readonly','true');}
|
|
149
155
|
const hint=document.createElement('small');hint.textContent=composerReadOnly?'Read only · Escape closes':'Enter saves · Escape cancels';hint.textContent=t(hint.textContent);const error=document.createElement('p');error.setAttribute('role','alert');form.append(field,hint,error);
|
|
150
156
|
const place=()=>{if(general)return;
|
|
151
157
|
if(host.codec?.geometry){
|
|
158
|
+
const previousPlacement={position:form.style.position,left:form.style.left,top:form.style.top,width:form.style.width,height:form.style.height,maxWidth:form.style.maxWidth,maxHeight:form.style.maxHeight,zIndex:form.style.zIndex};
|
|
159
|
+
Object.assign(form.style,{position:'absolute',height:'',maxWidth:'',maxHeight:'',zIndex:''});
|
|
152
160
|
const right=pane.clientWidth-screen.x-screen.width-12,left=screen.x-12,available=Math.max(left,right);
|
|
161
|
+
let x:number,y:number;
|
|
153
162
|
if(available>=160){
|
|
154
163
|
const width=Math.min(286,available);form.style.width=width+'px';const height=form.offsetHeight||132;
|
|
155
|
-
|
|
164
|
+
x=right>=left?screen.x+screen.width+8:screen.x-width-8;y=Math.max(4,Math.min(screen.y,pane.clientHeight-height-4));
|
|
165
|
+
}else{
|
|
166
|
+
form.style.width='';const w=form.offsetWidth||294,h=form.offsetHeight||132;
|
|
167
|
+
x=Math.max(4,Math.min(screen.x+screen.width+8,pane.clientWidth-w-4));y=Math.max(4,Math.min(screen.y+screen.height+8,pane.clientHeight-h-4));
|
|
156
168
|
}
|
|
157
|
-
form.
|
|
169
|
+
const w=form.getBoundingClientRect().width||form.offsetWidth||294,h=form.offsetHeight||132,radius=7;
|
|
170
|
+
const clampX=(v:number)=>Math.max(4,Math.min(v,pane.clientWidth-w-4)),clampY=(v:number)=>Math.max(4,Math.min(v,pane.clientHeight-h-4));
|
|
171
|
+
const outside=(p:{x:number;y:number})=>!boxesIntersect({...p,w,h},{x:screen.x-radius,y:screen.y-radius,w:screen.width+2*radius,h:screen.height+2*radius});
|
|
172
|
+
const handles=resizeHandles;
|
|
173
|
+
const points=handles.map(([name,dx,dy])=>({name,x:screen.x+screen.width*dx,y:screen.y+screen.height*dy}));
|
|
174
|
+
const covers=(p:{x:number;y:number},at:{x:number;y:number})=>boxesIntersect({...p,w,h},{x:at.x-radius,y:at.y-radius,w:2*radius,h:2*radius});
|
|
175
|
+
const pointer=geometryDrag&&(geometryDrag.handle==='move'?{x:geometryDrag.start.x+screen.x-geometryDrag.screen.x,y:geometryDrag.start.y+screen.y-geometryDrag.screen.y}:points.find(p=>p.name===geometryDrag!.handle));
|
|
176
|
+
const candidates=[{x,y},...[
|
|
177
|
+
[right>=left?screen.x-w-8:screen.x+screen.width+8,screen.y],
|
|
178
|
+
[screen.x,screen.y+screen.height+8],[screen.x,screen.y-h-8],
|
|
179
|
+
].map(([cx,cy])=>({x:clampX(cx!),y:clampY(cy!)}))];
|
|
180
|
+
// A held handle must never acquire the composer under its pointer.
|
|
181
|
+
const usable=(p:{x:number;y:number})=>!pointer||!covers(p,pointer);
|
|
182
|
+
let chosen=candidates.find(p=>outside(p)&&usable(p));
|
|
183
|
+
if(!chosen){
|
|
184
|
+
// Handle edges partition all possible placements into constant hit-count cells,
|
|
185
|
+
// including the interior of a large area. Boundaries suffice; no pixel scan.
|
|
186
|
+
const xs=[x,4,pane.clientWidth-w-4,...points.flatMap(p=>[p.x-radius-w,p.x+radius])].map(clampX);
|
|
187
|
+
const ys=[y,4,pane.clientHeight-h-4,...points.flatMap(p=>[p.y-radius-h,p.y+radius])].map(clampY);
|
|
188
|
+
candidates.push(...xs.flatMap(cx=>ys.map(cy=>({x:cx,y:cy}))).sort((a,b)=>Math.hypot(a.x-x,a.y-y)-Math.hypot(b.x-x,b.y-y)));
|
|
189
|
+
const safe=candidates.filter(usable);
|
|
190
|
+
const pool=safe.length?safe:candidates;
|
|
191
|
+
chosen=pool.reduce((best,p)=>points.filter(at=>covers(p,at)).length<points.filter(at=>covers(best,at)).length?p:best,pool[0]!);
|
|
192
|
+
}
|
|
193
|
+
if(points.some(at=>covers(chosen!,at))&&workspace){
|
|
194
|
+
const origin=pane.getBoundingClientRect(),main=workspace.getBoundingClientRect();
|
|
195
|
+
const ox=origin.left+pane.clientLeft,oy=origin.top+pane.clientTop;
|
|
196
|
+
const minX=Math.max(4,main.left+4)-ox,minY=Math.max(4,main.top+4)-oy;
|
|
197
|
+
const maxX=Math.min(window.innerWidth-4,main.right-4)-ox-w,maxY=Math.min(window.innerHeight-4,main.bottom-4)-oy-h;
|
|
198
|
+
if(maxX>=minX&&maxY>=minY){
|
|
199
|
+
const cx=(v:number)=>Math.max(minX,Math.min(v,maxX)),cy=(v:number)=>Math.max(minY,Math.min(v,maxY));
|
|
200
|
+
const acts=[...document.querySelectorAll<HTMLElement>('#workspace-act-row,.workspace-act-bar,#save,#request-changes,#submit')].filter(n=>!n.hidden&&n.getClientRects().length).map(n=>{const r=n.getBoundingClientRect();return {x:r.left-ox,y:r.top-oy,width:r.width,height:r.height};});
|
|
201
|
+
const blocksAct=(p:{x:number;y:number})=>acts.some(r=>boxesIntersect({...p,w,h},{x:r.x,y:r.y,w:r.width,h:r.height}));
|
|
202
|
+
const xs=[x,minX,maxX,...points.flatMap(p=>[p.x-radius-w,p.x+radius]),...acts.flatMap(r=>[r.x-w,r.x+r.width])].map(cx);
|
|
203
|
+
const ys=[y,minY,maxY,...points.flatMap(p=>[p.y-radius-h,p.y+radius]),...acts.flatMap(r=>[r.y-h,r.y+r.height])].map(cy);
|
|
204
|
+
const expanded=[...candidates.map(p=>({x:cx(p.x),y:cy(p.y)})),...xs.flatMap(px=>ys.map(py=>({x:px,y:py}))).sort((a,b)=>Math.hypot(a.x-x,a.y-y)-Math.hypot(b.x-x,b.y-y))].filter(usable);
|
|
205
|
+
const zero=expanded.filter(p=>!points.some(at=>covers(p,at))),clear=zero.filter(p=>!blocksAct(p));
|
|
206
|
+
const pool=clear.length?clear:zero.length?zero:expanded;
|
|
207
|
+
if(pool.length){
|
|
208
|
+
const mainChoice=pool.reduce((best,p)=>points.filter(at=>covers(p,at)).length<points.filter(at=>covers(best,at)).length?p:best,pool[0]!);
|
|
209
|
+
if(zero.length||points.filter(at=>covers(mainChoice,at)).length<points.filter(at=>covers(chosen!,at)).length){
|
|
210
|
+
Object.assign(form.style,{position:'fixed',left:mainChoice.x+ox+'px',top:mainChoice.y+oy+'px',width:w+'px',height:h+'px',maxWidth:w+'px',maxHeight:h+'px',zIndex:'30'});return;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// Only after the main search also fails may a held pointer keep its origin.
|
|
216
|
+
if(pointer&&!candidates.some(usable)){Object.assign(form.style,previousPlacement);return;}
|
|
217
|
+
Object.assign(form.style,{left:chosen.x+'px',top:chosen.y+'px'});return;
|
|
158
218
|
}
|
|
159
219
|
const w=form.offsetWidth||294,h=form.offsetHeight||132;Object.assign(form.style,{left:Math.max(4,Math.min(screen.x+screen.width+8,pane.clientWidth-w-4))+'px',top:Math.max(4,Math.min(screen.y+screen.height+8,pane.clientHeight-h-4))+'px'});};
|
|
160
220
|
let removeBtn:HTMLButtonElement|null=null,errorSource='';
|
|
@@ -163,8 +223,9 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
|
|
|
163
223
|
remove.onclick=()=>{
|
|
164
224
|
if(busy)return;
|
|
165
225
|
try{
|
|
166
|
-
|
|
167
|
-
|
|
226
|
+
if(general)assertWritable(generalRefusal());else assertEdit();
|
|
227
|
+
if(host.locked(existing.id))throw new Error(t('COMMENT_SUBMITTED: submitted evidence is immutable'));
|
|
228
|
+
const all=(general?host.general?.rows:undefined)??host.feedback(),index=all.findIndex(x=>x.id===existing.id);if(index>=0)all.splice(index,1);
|
|
168
229
|
cancel();host.changed();refresh();
|
|
169
230
|
}catch(e){errorSource=toEn(e instanceof Error?e.message:String(e));error.textContent=t(errorSource);place();}
|
|
170
231
|
};
|
|
@@ -229,7 +290,9 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
|
|
|
229
290
|
if(index<0)return;
|
|
230
291
|
all.splice(index,1,replacement);
|
|
231
292
|
}else existing.summary=summary;
|
|
232
|
-
}else if(general){
|
|
293
|
+
}else if(general){
|
|
294
|
+
assertEdit(true);const row=host.general!.create(summary);
|
|
295
|
+
if(host.general!.rows)host.general!.rows.push(row);else host.add(row);
|
|
233
296
|
}else{
|
|
234
297
|
assertCapture();if(!pose||!host.codec&&!pose.frame&&!pose.timeBasis)throw new Error(t(pose?.frameReason??'COMMENT_FRAME_UNAVAILABLE: provide an explicit producer clock or a decoded reference frame index'));
|
|
235
298
|
busy=true;field.disabled=true;syncChips();
|
|
@@ -313,7 +376,7 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
|
|
|
313
376
|
const width=pin.offsetWidth||24,height=pin.offsetHeight||24,placed=occupied.get(mark.viewport)??[];
|
|
314
377
|
if(!occupied.has(mark.viewport)){
|
|
315
378
|
occupied.set(mark.viewport,placed);
|
|
316
|
-
if(geometryEdit?.view===mark.viewport){const r=geometryEdit.screen;for(const [x,y]of
|
|
379
|
+
if(geometryEdit?.view===mark.viewport){const r=geometryEdit.screen;for(const [,x,y]of resizeHandles)placed.push({x:r.x+r.width*x!,y:r.y+r.height*y!,width:12,height:12});}
|
|
317
380
|
}
|
|
318
381
|
const clamp=(n:number,size:number,limit:number)=>Math.max(size/2,Math.min(limit-size/2,n));
|
|
319
382
|
const clear=(x:number,y:number)=>placed.every(p=>Math.abs(p.x-x)>=(p.width+width)/2+2||Math.abs(p.y-y)>=(p.height+height)/2+2);
|
|
@@ -325,7 +388,7 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
|
|
|
325
388
|
}if(draftMark&&!geometryEdit)layers.get(draftMark.view)?.append(rectElement(draftMark.screen));
|
|
326
389
|
if(geometryEdit){
|
|
327
390
|
const {view,screen:r}=geometryEdit,layer=layers.get(view)!,box=rectElement(r);box.dataset.commentHandle='move';Object.assign(box.style,{pointerEvents:'auto',cursor:'move'});layer.prepend(box);
|
|
328
|
-
for(const [name,x,y]of
|
|
391
|
+
for(const [name,x,y]of resizeHandles){
|
|
329
392
|
const handle=document.createElement('button');handle.type='button';handle.dataset.commentHandle=name;handle.className='stage-comment-ui';handle.setAttribute('aria-label',t('Resize comment area: {0}').replace('{0}',name));
|
|
330
393
|
Object.assign(handle.style,{position:'absolute',left:r.x+r.width*x+'px',top:r.y+r.height*y+'px',width:'12px',height:'12px',minWidth:'12px',minHeight:'12px',padding:'0',transform:'translate(-50%,-50%)',pointerEvents:'auto',cursor:name+'-resize',borderWidth:'2px',borderStyle:'solid',borderColor:'var(--link)',background:'var(--rv-panel)'});layer.append(handle);
|
|
331
394
|
}
|
package/web/styles.css
CHANGED
|
@@ -469,6 +469,8 @@ main{position:relative}.toolbar{anchor-name:--stage-comment-bar}#stage-comment{w
|
|
|
469
469
|
.workspace-main-toolbar #play{font-size:var(--font-size-compact);line-height:1;flex:none;width:var(--control-height);height:var(--control-height);padding:0}
|
|
470
470
|
.workspace-secondary-toolbar>label{display:inline-flex;align-items:center;gap:var(--space-2);font-size:var(--font-size-meta);line-height:1.5}
|
|
471
471
|
.workspace-secondary-toolbar>label input[type=checkbox]{margin:0}
|
|
472
|
+
#parts-difference-operand-label{max-width:100%}
|
|
473
|
+
#parts-difference-operand{width:auto;min-width:0}
|
|
472
474
|
.workspace-main-toolbar .zoom-controls{padding-right:var(--space-1)}
|
|
473
475
|
.workspace-bottom-tabs{display:flex;align-items:center;gap:var(--space-1);flex-wrap:nowrap}
|
|
474
476
|
.workspace-bottom-tabs [aria-selected=true]{background:var(--rv-pressed-bg);border-color:var(--rv-pressed-border)}
|