rig-review 4.5.0 → 4.7.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 +235 -16
- package/docs/STABILITY.md +62 -4
- package/package.json +1 -1
- package/src/canonical-json.ts +14 -0
- package/src/create-pin-gate.ts +1 -1
- package/src/direction-inspection.ts +17 -7
- 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 +85 -9
- package/src/job-api.ts +182 -31
- package/src/job-checkpoint-evidence.ts +19 -6
- package/src/job-cli.ts +6 -6
- package/src/job-contract.ts +85 -14
- 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 +74 -40
- 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 +11 -0
- package/web/catalog-ko.ts +11 -0
- package/web/direction-panel.ts +11 -7
- package/web/job-rig-screen.ts +65 -21
- package/web/job-session.ts +54 -26
- package/web/main.ts +158 -50
- package/web/mesh-editor.ts +124 -13
- package/web/part-selection.ts +1 -1
- package/web/parts-viewport-provider.ts +45 -8
- 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/web/mesh-editor.ts
CHANGED
|
@@ -11,15 +11,18 @@
|
|
|
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 {EMIT_UNPINNED_CREATE_FIELDS} from '../src/create-pin-gate.ts';
|
|
15
|
+
import type {JobMeshEditValue} from '../src/job-contract.ts';
|
|
14
16
|
import {readStoredSetupMesh,setupModel} from '../src/setup-mesh.ts';
|
|
15
17
|
import {
|
|
16
18
|
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,
|
|
19
|
+
draftKey,invertAffine,meshEditActValue,meshEditDocument,parseMeshDraft,screenDeltaToCrop,verticesInBox,writeMeshDraft,type MeshEditDocument,type MeshEditResult,type MeshOp,type MeshSource,
|
|
20
|
+
type MeshEditDraft,type MeshView,type ScreenPoint,type Vec,
|
|
19
21
|
} from '../src/mesh-edit.ts';
|
|
20
22
|
import type {OverlayMeshEdit,OverlayPoint,OverlayProject} from './rig-overlays.ts';
|
|
21
23
|
import type {SetupPose} from './setup-pose.ts';
|
|
22
24
|
import {textEntryFocused} from './view-controls.ts';
|
|
25
|
+
import {onLanguageChange,t,tr} from './i18n.ts';
|
|
23
26
|
|
|
24
27
|
export type MeshMode='modify'|'create'|'delete'|'edges';
|
|
25
28
|
export const meshModes:readonly MeshMode[]=['modify','create','delete','edges'];
|
|
@@ -88,12 +91,15 @@ export interface MeshEditorHost {
|
|
|
88
91
|
project:()=>OverlayProject|null;
|
|
89
92
|
mapping:()=>CropWorldMapping;
|
|
90
93
|
inspector:()=>string|undefined;
|
|
94
|
+
readonly readOnly?:boolean;
|
|
91
95
|
/** The selected slot's setup-space source, or the refusal that names why there is none. */
|
|
92
|
-
source:()=>SourceResult;
|
|
96
|
+
source:(slot?:string)=>SourceResult;
|
|
93
97
|
/** Hold the stage still under the setup-pose overlay. */
|
|
94
98
|
pause:()=>void;
|
|
95
99
|
changed:()=>void;
|
|
96
100
|
download:(document:MeshEditDocument)=>void;
|
|
101
|
+
/** Live jobs keep the editor but send rig-review edits via the verdict. */
|
|
102
|
+
job?:{slots:()=>readonly string[];modelHash:()=>string|null}|'read-only';
|
|
97
103
|
/** Apply · Rebuild (#135): send the delta through the shared runner; `built` when the revision is on the stage. Lines stream to `line`. */
|
|
98
104
|
apply:(document:MeshEditDocument,line:(text:string)=>void)=>Promise<{built:boolean;text:string;error:boolean}>;
|
|
99
105
|
/** Whether the stage holds a revision this editor's Apply built. */
|
|
@@ -104,14 +110,75 @@ export interface MeshEditorHost {
|
|
|
104
110
|
confirm:(text:string)=>boolean;
|
|
105
111
|
token:(name:string)=>string;
|
|
106
112
|
}
|
|
107
|
-
export interface
|
|
113
|
+
export interface JobMeshDraftSubmission {
|
|
114
|
+
readonly edits:readonly JobMeshEditValue[];
|
|
115
|
+
clear(accepted:readonly JobMeshEditValue[]):void;
|
|
116
|
+
}
|
|
117
|
+
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>}
|
|
118
|
+
|
|
119
|
+
type JobDraftScanResult={stored:MeshEditDraft;edits:JobMeshEditValue[];stale:boolean;versions:ReadonlyMap<string,number>};
|
|
120
|
+
type JobDraftScan={text:string;modelHash:string;version:number;result?:JobDraftScanResult;pending:Promise<JobDraftScanResult>};
|
|
108
121
|
|
|
109
122
|
type Drag={pointer:number;start:ScreenPoint;ids:number[];base:MeshView;ops:MeshOp[]}|{pointer:number;start:ScreenPoint;box:ScreenPoint;add:boolean};
|
|
110
123
|
|
|
111
124
|
export function bindMeshEditor(host:MeshEditorHost):MeshEditor {
|
|
112
125
|
const node=<T extends HTMLElement>(id:string)=>document.getElementById(id) as T;
|
|
113
126
|
const toggle=node<HTMLButtonElement>('mesh-edit'),bar=node<HTMLElement>('mesh-editor-bar'),status=node<HTMLElement>('mesh-editor-status'),draft=node<HTMLTextAreaElement>('mesh-edit-draft');
|
|
127
|
+
const apply=node<HTMLButtonElement>('mesh-apply');
|
|
114
128
|
const chestToggle=document.getElementById('chest-edit') as HTMLButtonElement|null;
|
|
129
|
+
const job=typeof host.job==='object'?host.job:null;
|
|
130
|
+
const jobDrafts=new Map<string,{session:MeshEditSession;frame:{width:number;height:number};modelHash:string}>();
|
|
131
|
+
const jobVersions=new Map<string,number>();
|
|
132
|
+
let jobDraftText=draft.value,jobVersion=0,jobScan:JobDraftScan|undefined,disposed=false;
|
|
133
|
+
/** Only sessions from the current model and saved entries that replay on it are held. */
|
|
134
|
+
const readJobDraft=async(text:string,modelHash:string):Promise<JobDraftScanResult>=>{
|
|
135
|
+
const stored=parseMeshDraft(text),versions=new Map(jobVersions);
|
|
136
|
+
const sessions=new Map((jobDraftText===text?[...jobDrafts]:[]).filter(([,row])=>row.modelHash===modelHash));
|
|
137
|
+
const edits=[...sessions.values()].filter(({session})=>session.canUndo()).map(({session,frame})=>meshEditActValue(session,frame));
|
|
138
|
+
const unopened=Object.entries(stored.entries).filter(([key,entry])=>entry.ops.length>0&&!sessions.get(key)?.session.canUndo()).map(([key])=>key);
|
|
139
|
+
const keys=new Set(unopened);
|
|
140
|
+
const mapping=host.mapping();
|
|
141
|
+
if(!job||!mapping.available||!keys.size)return {stored,edits,stale:keys.size>0,versions};
|
|
142
|
+
const frame={width:mapping.crop.w,height:mapping.crop.h},sources=new Map<string,Extract<SourceResult,{ok:true}>>();
|
|
143
|
+
const ambiguous=new Set<string>();
|
|
144
|
+
for(const slot of job.slots()){
|
|
145
|
+
if(!unopened.some(key=>key.includes(`/${slot}/`)))continue;
|
|
146
|
+
const result=host.source(slot);
|
|
147
|
+
if(!result.ok)continue;
|
|
148
|
+
const key=draftKey(result.source);
|
|
149
|
+
if(!keys.has(key))continue;
|
|
150
|
+
if(sources.has(key))ambiguous.add(key);
|
|
151
|
+
sources.set(key,result);
|
|
152
|
+
}
|
|
153
|
+
const restored=await Promise.all([...sources].filter(([key])=>!ambiguous.has(key)).map(async ([,result])=>{
|
|
154
|
+
const source={...result.source,hash:await sha256Hex(attachmentHashText(result.entry))};
|
|
155
|
+
const ops=draftOps(stored,source);
|
|
156
|
+
return ops?.length?meshEditActValue(new MeshEditSession(source,ops),frame):null;
|
|
157
|
+
}));
|
|
158
|
+
const eligible=restored.filter(edit=>edit!==null);
|
|
159
|
+
return {stored,edits:[...edits,...eligible],stale:eligible.length!==keys.size,versions};
|
|
160
|
+
};
|
|
161
|
+
const scanJobDraft=()=>{
|
|
162
|
+
const modelHash=job?.modelHash(),text=draft.value;
|
|
163
|
+
if(!modelHash)return;
|
|
164
|
+
if(jobScan?.text===text&&jobScan.modelHash===modelHash&&jobScan.version===jobVersion)return jobScan;
|
|
165
|
+
const scan:JobDraftScan={text,modelHash,version:jobVersion,pending:readJobDraft(text,modelHash)};
|
|
166
|
+
jobScan=scan;
|
|
167
|
+
void scan.pending.then(result=>{
|
|
168
|
+
scan.result=result;
|
|
169
|
+
if(!disposed&&jobScan===scan&&draft.value===text&&job?.modelHash()===modelHash){sync();host.changed();}
|
|
170
|
+
},()=>{});
|
|
171
|
+
return scan;
|
|
172
|
+
};
|
|
173
|
+
const hasJobEdits=()=>!!scanJobDraft()?.result?.edits.length;
|
|
174
|
+
const jobEdits=async():Promise<JobMeshDraftSubmission|null>=>{
|
|
175
|
+
for(let scan=scanJobDraft();scan;scan=scanJobDraft()){
|
|
176
|
+
const submitted=scan,result=await submitted.pending;
|
|
177
|
+
if(submitted===scanJobDraft())return {edits:result.edits,clear:accepted=>clearJobDraft(submitted,result,accepted)};
|
|
178
|
+
}
|
|
179
|
+
return null;
|
|
180
|
+
};
|
|
181
|
+
if(host.job){status.style.whiteSpace='normal';status.setAttribute('translate','no');}
|
|
115
182
|
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
183
|
let preview:MeshView|null=null;const selected=new Set<number>();
|
|
117
184
|
const view=()=>preview??session?.view()??null;
|
|
@@ -126,23 +193,56 @@ export function bindMeshEditor(host:MeshEditorHost):MeshEditor {
|
|
|
126
193
|
edges:'click vertex A then start vertex B to add a constraint edge · click a constraint edge to remove it'.replace('start ',''),
|
|
127
194
|
};
|
|
128
195
|
const sync=()=>{
|
|
196
|
+
if(job&&jobDraftText!==draft.value){
|
|
197
|
+
jobDraftText=draft.value;jobDrafts.clear();
|
|
198
|
+
if(active){void reenter();return;}
|
|
199
|
+
}
|
|
200
|
+
const held=scanJobDraft()?.result;
|
|
129
201
|
const visible=meshEditVisible(host.inspector());toggle.hidden=!visible;
|
|
202
|
+
if(host.readOnly)toggle.disabled=true;
|
|
130
203
|
if(!visible&&active){setActive(false);return;}
|
|
131
204
|
if(!host.applied()&¬e.startsWith('Applied mesh edit ')){appliedOutcome='';note='';noteError=false;}
|
|
132
205
|
toggle.setAttribute('aria-pressed',String(active));bar.hidden=!active;
|
|
133
206
|
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();
|
|
207
|
+
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
208
|
if(!session){status.textContent=host.applied()&&appliedOutcome?appliedOutcome:'';status.classList.toggle('error',noteError);return;}
|
|
136
209
|
const s=session.source,count=session.ops().length;
|
|
137
|
-
|
|
138
|
-
|
|
210
|
+
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`;
|
|
211
|
+
const reason=host.job==='read-only'?t('JOB_REVIEW_READ_ONLY'):!job?null:EMIT_UNPINNED_CREATE_FIELDS?
|
|
212
|
+
t('In a job, press Request changes to send this edit; the producer rebuilds it.'):held?.edits.length?t('job.submit.JOB_ACT_KIND_DISABLED'):null;
|
|
213
|
+
const readout=host.job?[reason,held?.stale?t('job.mesh.staleDraft'):null,tr(summary)].filter(Boolean).join(' · '):summary;
|
|
214
|
+
status.textContent=readout;
|
|
215
|
+
status.title=t('{0} / {1} / {2} · {3} vertices · {4} triangles · hull {5} · {6}',
|
|
216
|
+
[s.slot,s.skin,s.attachment,s.vertices.length,s.triangles.length/3,s.hull,readout],host.job?undefined:'en');
|
|
139
217
|
status.classList.toggle('error',noteError);
|
|
140
218
|
if(mode)host.pane.dataset.meshMode=mode;else delete host.pane.dataset.meshMode;
|
|
141
219
|
};
|
|
142
220
|
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
221
|
const setStatusNote=(text:string,error=false)=>{appliedOutcome=text.startsWith('Applied mesh edit ')?text:'';note=text;noteError=error;sync();};
|
|
222
|
+
const writeDraft=(text:string)=>{draft.value=text;jobDraftText=text;draft.dispatchEvent(new Event('input',{bubbles:true}));};
|
|
144
223
|
// 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;}
|
|
224
|
+
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);};
|
|
225
|
+
/** Acknowledge the snapshot per attachment so a later edit, even on the same mesh, survives. */
|
|
226
|
+
const clearJobDraft=(scan:JobDraftScan,sent:JobDraftScanResult,accepted:readonly JobMeshEditValue[])=>{
|
|
227
|
+
const stored=parseMeshDraft(draft.value);
|
|
228
|
+
let text=draft.value,cleared=false;
|
|
229
|
+
for(const edit of accepted){
|
|
230
|
+
const key=draftKey(edit),before=sent.stored.entries[key],now=stored.entries[key];
|
|
231
|
+
if(jobVersions.get(key)!==sent.versions.get(key)||JSON.stringify(now)!==JSON.stringify(before))continue;
|
|
232
|
+
const live=jobDrafts.get(key);
|
|
233
|
+
if(live&&live.session===session&&drag&&'ops' in drag&&drag.ops.length)continue;
|
|
234
|
+
if(now?.hash===edit.source.hash){text=writeMeshDraft(stored,{...edit,hash:edit.source.hash},[]);delete stored.entries[key];}
|
|
235
|
+
if(live?.modelHash===scan.modelHash&&live.session.source.hash===edit.source.hash){
|
|
236
|
+
live.session.reset();
|
|
237
|
+
if(live.session===session){drag=null;preview=null;selected.clear();pending=null;note='';noteError=false;}
|
|
238
|
+
}
|
|
239
|
+
cleared=true;
|
|
240
|
+
}
|
|
241
|
+
if(!cleared)return;
|
|
242
|
+
++jobVersion;
|
|
243
|
+
if(text!==draft.value)writeDraft(text);
|
|
244
|
+
if(!disposed){sync();host.changed();}
|
|
245
|
+
};
|
|
146
246
|
/** Reports a step: a refusal by its code, a no-op by its reason, a change by what it did. */
|
|
147
247
|
const after=(result:MeshEditResult,what:()=>string)=>{
|
|
148
248
|
if(!result.ok)say(result.code,true);
|
|
@@ -155,11 +255,17 @@ export function bindMeshEditor(host:MeshEditorHost):MeshEditor {
|
|
|
155
255
|
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
256
|
const setActive=(on:boolean)=>{if(!on){leave();sync();host.changed();return;}void enter();};
|
|
157
257
|
const enter=async()=>{
|
|
158
|
-
if(entering)return;entering=true;
|
|
258
|
+
if(host.readOnly||entering)return;entering=true;
|
|
159
259
|
try{
|
|
160
260
|
const result=host.source();if(!result.ok){leave();sync();host.message(result.code,true);host.changed();return;}
|
|
261
|
+
const modelHash=job?.modelHash(),mapping=job?host.mapping():null;
|
|
161
262
|
const hash=await sha256Hex(attachmentHashText(result.entry)),source:MeshSource={...result.source,hash};
|
|
162
|
-
|
|
263
|
+
if(disposed||modelHash!==job?.modelHash())return;
|
|
264
|
+
if(job&&jobDraftText!==draft.value){jobDraftText=draft.value;jobDrafts.clear();}
|
|
265
|
+
const key=draftKey(source),prior=jobDrafts.get(key);
|
|
266
|
+
const restored=prior&&prior.modelHash===modelHash&&prior.session.source.hash===hash?prior.session.ops():draftOps(parseMeshDraft(draft.value),source);
|
|
267
|
+
session=new MeshEditSession(source,restored??[]);
|
|
268
|
+
if(modelHash&&mapping?.available)jobDrafts.set(key,{session,frame:{width:mapping.crop.w,height:mapping.crop.h},modelHash});
|
|
163
269
|
if(chestToggle?.getAttribute('aria-pressed')==='true')chestToggle.click();
|
|
164
270
|
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
271
|
sync();host.changed();
|
|
@@ -181,8 +287,8 @@ export function bindMeshEditor(host:MeshEditorHost):MeshEditor {
|
|
|
181
287
|
node<HTMLButtonElement>('mesh-download').addEventListener('click',()=>{if(session)host.download(meshEditDocument(session));});
|
|
182
288
|
// #135: the delta goes to the producer (`rig-parts remesh --delta`) through the host's shared runner; a built revision
|
|
183
289
|
// 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(
|
|
290
|
+
apply.addEventListener('click',()=>{
|
|
291
|
+
if(host.readOnly||!session||applying||host.job)return;
|
|
186
292
|
if(!session.ops().length){say(MESH_EDIT_NOTHING_PENDING,true);return;}
|
|
187
293
|
const doc=meshEditDocument(session);applying=true;say(`Applying ${doc.ops.length} op(s) on ${doc.slot}: remesh --delta, compile…`);
|
|
188
294
|
void (async()=>{
|
|
@@ -297,12 +403,17 @@ export function bindMeshEditor(host:MeshEditorHost):MeshEditor {
|
|
|
297
403
|
if(!active||!session)return;const result=host.source();
|
|
298
404
|
if(!result.ok){leave();sync();host.message(result.code,true);host.changed();return;}
|
|
299
405
|
if(result.source.slot!==session.source.slot||result.source.attachment!==session.source.attachment||result.source.skin!==session.source.skin){leave();void enter();return;}
|
|
406
|
+
if(job&&jobDrafts.get(draftKey(session.source))?.modelHash!==job.modelHash()){void reenter();return;}
|
|
300
407
|
const current=session;
|
|
301
408
|
void sha256Hex(attachmentHashText(result.entry)).then(hash=>{if(active&&session===current&&hash!==current.source.hash)void reenter();});
|
|
302
409
|
};
|
|
410
|
+
const draftChanged=()=>{if(jobDraftText!==draft.value){sync();host.changed();}};
|
|
411
|
+
if(job)draft.addEventListener('input',draftChanged);
|
|
412
|
+
const unsubscribeLanguage=host.job?onLanguageChange(sync):null;
|
|
303
413
|
sync();
|
|
304
414
|
return {
|
|
305
415
|
active:()=>active,overlay,sync,selectionChanged,session:()=>session,mode:()=>mode,statusNote:()=>note||appliedOutcome,setStatusNote,
|
|
306
|
-
|
|
416
|
+
hasJobEdits,jobEdits,
|
|
417
|
+
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
418
|
};
|
|
308
419
|
}
|
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;
|
|
@@ -77,11 +77,13 @@ export type PartsSubjectData=ReturnType<typeof partsViewJson>;
|
|
|
77
77
|
export interface PartsSubjectEntry {subject:'parts';parts:PartsSubjectData}
|
|
78
78
|
export interface PartsSubjectSession {subject:'parts';issues:PartsIssue[]}
|
|
79
79
|
type Item=PartsSubjectData['items'][number];
|
|
80
|
+
type DifferenceOperand='painting'|'previous-draft';
|
|
80
81
|
interface PartsPose extends CommentUiPose {item:Item;sourceHash:string;view:PartsIssue['view']}
|
|
81
82
|
/** Source-specific pixels and evidence. Shell, list, toolbar, controller and act stay in main.ts. */
|
|
82
83
|
export function bindPartsSubject(host:{
|
|
83
84
|
data:PartsSubjectData;canvas:HTMLCanvasElement;referenceCanvas:HTMLCanvasElement;viewport:ViewportController;
|
|
84
85
|
el:ViewportProvider['el'];toolbar:HTMLElement;commentsHost:HTMLElement;openComments?:()=>void;hasPicture?:()=>boolean;issues:PartsIssue[];recordComments?:CommentRow[];
|
|
86
|
+
generalComments?:{rows:CommentRow[];available:()=>boolean};submitting?:()=>boolean;
|
|
85
87
|
request:(path:string,init?:RequestInit)=>Promise<Response>;base:string;paintingPath:string;
|
|
86
88
|
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
89
|
}) {
|
|
@@ -95,6 +97,8 @@ export function bindPartsSubject(host:{
|
|
|
95
97
|
const makeCanvas=(w:number,h:number)=>Object.assign(document.createElement('canvas'),{width:w,height:h});
|
|
96
98
|
const item=()=>data.items.find(item=>item.name===selected)??data.items[0]!;
|
|
97
99
|
const assembled=()=>!solo||selected===null;
|
|
100
|
+
const paintingDifferenceAvailable=()=>data.differenceAvailable&&!!data.painting;
|
|
101
|
+
const previousDraftAvailable=()=>assembled()&&!!data.rigSize&&!!data.previousDraft;
|
|
98
102
|
const box=():Box=>assembled()&&data.rigSize?{name:'',index:0,x:0,y:0,w:data.rigSize[0],h:data.rigSize[1]}:item();
|
|
99
103
|
const loadImage=async(path:string):Promise<HTMLImageElement>=>{
|
|
100
104
|
const image=await loadViewportImage(await host.request(path));
|
|
@@ -117,7 +121,8 @@ export function bindPartsSubject(host:{
|
|
|
117
121
|
const bitmaps:ImageBitmap[]=[];
|
|
118
122
|
try{
|
|
119
123
|
if(data.mode!=='parts'||!data.items.length)throw new Error('PARTS_IMAGE_UNAVAILABLE');
|
|
120
|
-
const
|
|
124
|
+
const inAssembly=assembled(),settings=comparison;
|
|
125
|
+
const frame=box(),referenceBox=selected===null?null:item(),shown=inAssembly?data.items.filter(item=>!hidden.has(item.name)):[item()];
|
|
121
126
|
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
127
|
let reference:HTMLCanvasElement|null=null;
|
|
123
128
|
if(data.painting&&data.rigSize){
|
|
@@ -126,10 +131,19 @@ export function bindPartsSubject(host:{
|
|
|
126
131
|
if(referenceBox)paintPaintingCrop(reference.getContext('2d')!,original,paintingRectangle(referenceBox,data.rigSize,data.painting),referenceBox.w,referenceBox.h,'checker');
|
|
127
132
|
else reference.getContext('2d')!.drawImage(original,0,0);
|
|
128
133
|
}
|
|
134
|
+
if(disposed||navigation!==token)return;
|
|
129
135
|
const raster=makeCanvas(frame.w,frame.h),ctx=raster.getContext('2d')!;
|
|
130
|
-
if(
|
|
136
|
+
if(settings.mode==='difference'){
|
|
137
|
+
const previous=settings.operand==='previous-draft';
|
|
138
|
+
if(previous&&!previousDraftAvailable())throw new Error('PARTS_DIFFERENCE_UNAVAILABLE');
|
|
139
|
+
const suffix=previous?'&operand=previous-draft':'';
|
|
131
140
|
const differences=[];
|
|
132
|
-
for(const entry of
|
|
141
|
+
for(const entry of previous?[frame]:shown){
|
|
142
|
+
const response=await host.request(`${host.base}/difference/${entry.index}?threshold=${settings.threshold}&footprints=false${suffix}`);
|
|
143
|
+
const bitmap=await createImageBitmap(await response.blob());
|
|
144
|
+
bitmaps.push(bitmap);
|
|
145
|
+
differences.push({box:inAssembly?entry:{...entry,x:0,y:0},image:bitmap});
|
|
146
|
+
}
|
|
133
147
|
paintAssembly(ctx,frame.w,frame.h,differences,{bg:'checker',alpha:false,transparent:true});
|
|
134
148
|
}else if(comparison.mode==='overlay'&&data.painting&&data.rigSize){
|
|
135
149
|
const original=await painting();
|
|
@@ -196,9 +210,12 @@ export function bindPartsSubject(host:{
|
|
|
196
210
|
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
211
|
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()&&EMIT_UNPINNED_CREATE_FIELDS?{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
212
|
};
|
|
199
|
-
comments=bindStageComments<CommentRow,PartsPose>({general:host.recordComments
|
|
213
|
+
comments=bindStageComments<CommentRow,PartsPose>({general:host.recordComments||host.generalComments?{
|
|
214
|
+
create:summary=>({id:crypto.randomUUID(),summary}),matches:row=>!('schema' in row),
|
|
215
|
+
...(host.generalComments?{...host.generalComments,refusal:host.refusal}:{}),
|
|
216
|
+
}: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
217
|
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});
|
|
218
|
+
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
219
|
return {
|
|
203
220
|
frameSize:(target:CameraTarget):PartsFrame|null=>{
|
|
204
221
|
const frame=target==='rig'?drawnFrame:drawnReferenceFrame;if(!frame||!data.painting||!data.rigSize)return frame;
|
|
@@ -210,10 +227,30 @@ export function bindPartsSubject(host:{
|
|
|
210
227
|
},
|
|
211
228
|
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
229
|
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();},
|
|
230
|
+
select:(name:string|null)=>{selected=name;if(name===null)solo=false;redraw();host.selectionChanged();},
|
|
231
|
+
isolate:(value:boolean)=>{
|
|
232
|
+
solo=value;
|
|
233
|
+
if(!assembled()&&comparison.mode==='difference'&&comparison.operand==='previous-draft'){
|
|
234
|
+
const {opacity,threshold}=comparison;
|
|
235
|
+
comparison=paintingDifferenceAvailable()?{mode:'difference',opacity,threshold}:{mode:'part',opacity};
|
|
236
|
+
}
|
|
237
|
+
redraw();host.selectionChanged();
|
|
238
|
+
},
|
|
214
239
|
show:(name:string,value:boolean)=>{if(value)hidden.delete(name);else hidden.add(name);redraw();},
|
|
215
|
-
differenceAvailable:()
|
|
216
|
-
|
|
240
|
+
differenceAvailable:()=>!failed&&(paintingDifferenceAvailable()||previousDraftAvailable()),
|
|
241
|
+
paintingDifferenceAvailable,previousDraftAvailable,
|
|
242
|
+
comparison:()=>comparison,
|
|
243
|
+
setComparison:async(mode:PartsComparison['mode'],operand?:DifferenceOperand)=>{
|
|
244
|
+
const paintingAvailable=paintingDifferenceAvailable();
|
|
245
|
+
const usePrevious=operand==='previous-draft'||(operand===undefined&&!paintingAvailable);
|
|
246
|
+
if(mode==='difference'&&!(usePrevious?previousDraftAvailable():paintingAvailable))return false;
|
|
247
|
+
const opacity=comparison.opacity;
|
|
248
|
+
const next:PartsComparison=mode==='difference'
|
|
249
|
+
? {mode,opacity,threshold:0,...(usePrevious?{operand:'previous-draft' as const}:{})}
|
|
250
|
+
: {mode,opacity};
|
|
251
|
+
comparison=next;const navigation=token+1;
|
|
252
|
+
try{await paint();return !disposed&&navigation===token&&comparison===next;}catch{return false;}
|
|
253
|
+
},
|
|
217
254
|
opacity:(value:number)=>{comparison.opacity=value;redraw();},paint,redraw,
|
|
218
255
|
async ready(){if(data.painting)host.viewport.state.cameraSync=true;await paint();},
|
|
219
256
|
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)}
|
package/web/workspace-layout.ts
CHANGED
|
@@ -84,6 +84,16 @@ export function parseInspectorScroll(value:unknown):InspectorScrollSnapshot {
|
|
|
84
84
|
for(const [tab,raw]of Object.entries(value)){if(!validTab(tab)||!raw||typeof raw!=='object'||Array.isArray(raw))throw new Error('INSPECTOR_SCROLL: unknown tab or malformed offset');const o=raw as Record<string,unknown>;if(Object.keys(o).some(key=>key!=='x'&&key!=='y')||![o.x,o.y].every(n=>typeof n==='number'&&Number.isFinite(n)&&n>=0&&n<=10000000))throw new Error('INSPECTOR_SCROLL: finite nonnegative x/y <=10000000 required');result[tab]={x:o.x as number,y:o.y as number};}return result;
|
|
85
85
|
}
|
|
86
86
|
const scrollScheduler:ScrollScheduler={request:callback=>typeof requestAnimationFrame==='function'?requestAnimationFrame(callback):Number(setTimeout(callback,0)),cancel:handle=>typeof cancelAnimationFrame==='function'?cancelAnimationFrame(handle):clearTimeout(handle)};
|
|
87
|
+
export const SETTLE_FRAME_TIMEOUT_MS=250;
|
|
88
|
+
/** Wait for two animation frames, or a bounded timer when the view delivers no frames. */
|
|
89
|
+
export function settleAnimationFrames(timeoutMs=SETTLE_FRAME_TIMEOUT_MS,scheduler:ScrollScheduler=scrollScheduler):Promise<void> {
|
|
90
|
+
return new Promise<void>(resolve=>{
|
|
91
|
+
let settled=false,first:number|null=null,second:number|null=null;
|
|
92
|
+
const finish=()=>{if(settled)return;settled=true;clearTimeout(timer);if(first!==null)scheduler.cancel(first);if(second!==null)scheduler.cancel(second);resolve();};
|
|
93
|
+
const timer=setTimeout(finish,timeoutMs);
|
|
94
|
+
first=scheduler.request(()=>{first=null;if(!settled)second=scheduler.request(()=>{second=null;finish();});});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
87
97
|
/** One instance per source draft. Capture BEFORE hiding a tab; restore AFTER activation.
|
|
88
98
|
* Two frame boundaries settle layout, and later content can explicitly restore again.
|
|
89
99
|
* Clamping never overwrites the remembered desired offsets with a temporary empty extent.
|