rig-review 4.2.0 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/PARTS_VIEW.md +17 -8
- package/package.json +1 -1
- package/web/catalog-en.ts +1 -0
- package/web/catalog-ko.ts +1 -0
- package/web/parts-viewport-provider.ts +19 -5
- package/web/stage-comments.ts +105 -16
package/docs/PARTS_VIEW.md
CHANGED
|
@@ -324,14 +324,21 @@ The four-stage navigator preserves this entry and its explicit save behavior. Co
|
|
|
324
324
|
|
|
325
325
|
**Comment · C (n)** uses the same capture toggle, dragged region, composer and pins as the rig stage.
|
|
326
326
|
The **Issues** list stays visible in the side panel while C opens or closes capture. While capture is
|
|
327
|
-
on, drag within the rig pane
|
|
328
|
-
pan. Enter adds the issue,
|
|
327
|
+
on, drag within the rig pane, including from an existing pin, to mark a new region; clicking a pin
|
|
328
|
+
opens its comment. Keep controls clear and close capture to pan. Enter adds the issue,
|
|
329
329
|
and **Save sign-off** persists the verdict. Escape cancels the composer or capture while the inline
|
|
330
330
|
list stays visible. Rows and pins use the same edit, delete and jump actions.
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
331
|
+
For an editable saved comment opened in the composer, eight handles resize its area and dragging its
|
|
332
|
+
interior moves it; Enter saves text and geometry, Escape reverts the edit, and Shift+drag starts a
|
|
333
|
+
new area over the selected area or its handles. Tags are recomputed after resize or move only until
|
|
334
|
+
a chip is touched in this edit; reopening a saved comment keeps its chosen tags.
|
|
335
|
+
|
|
336
|
+
Opening a source-bound issue row or pin keeps the current view and camera when its source and view
|
|
337
|
+
mode match the screen and, in item view, it names the same part. Otherwise, a valid issue restores
|
|
338
|
+
its saved item or assembled mode, mesh, painting comparison and any recorded layer visibility,
|
|
339
|
+
then writes the saved rig camera (adjusted for the part placement in item view with painting).
|
|
340
|
+
The reference camera aligns only when camera sync is currently on; stale source or part bindings
|
|
341
|
+
are refused. Atlas inspection remains read only for pointed comments. Joined compiled Stage 1 refuses issue authoring with
|
|
335
342
|
`PARTS_JOINED_ISSUE_UNSUPPORTED` and directs the reviewer to the standing live job route. Its
|
|
336
343
|
zero-issue approval path remains available.
|
|
337
344
|
|
|
@@ -457,8 +464,10 @@ frontmost visible nontransparent art within the marked region. Review the chips
|
|
|
457
464
|
visible parts as needed. At least one referenced part is required, and the rig-space region must
|
|
458
465
|
remain inside their combined bounding box. Editing chips or wording validates and prepares the
|
|
459
466
|
candidate through the same source-bound crop pipeline before replacing the existing issue. A rejected
|
|
460
|
-
edit preserves the existing issue.
|
|
461
|
-
referenced parts
|
|
467
|
+
edit preserves the existing issue. Opening an assembled issue keeps an already matching assembled
|
|
468
|
+
view and shows its referenced parts as selected chips; a valid issue from a different context
|
|
469
|
+
restores its saved assembled view as described above. Assembly visibility stays temporary and is
|
|
470
|
+
excluded from saved issues and verdicts.
|
|
462
471
|
|
|
463
472
|
With `--painting`, the reference pane and Overlay use the same whole-canvas visual mapping described
|
|
464
473
|
above. Without painting the reference names `PARTS_REFERENCE_UNAVAILABLE`. Atlas assembly is disabled
|
package/package.json
CHANGED
package/web/catalog-en.ts
CHANGED
|
@@ -3614,4 +3614,5 @@ export const enCatalog: Readonly<Record<string, string>> = {
|
|
|
3614
3614
|
"Parts ready. Source files remain unchanged.": "Parts ready. Source files remain unchanged.",
|
|
3615
3615
|
"This request has no picture.": "This request has no picture.",
|
|
3616
3616
|
"The selected part has no chest regions. The chest editor keeps its current part.": "The selected part has no chest regions. The chest editor keeps its current part.",
|
|
3617
|
+
'Resize comment area: {0}': 'Resize comment area: {0}',
|
|
3617
3618
|
};
|
package/web/catalog-ko.ts
CHANGED
|
@@ -3614,4 +3614,5 @@ export const koCatalog: Readonly<Record<string, string>> = {
|
|
|
3614
3614
|
"Parts ready. Source files remain unchanged.": "파츠 준비 완료. 원본 파일은 변경되지 않습니다.",
|
|
3615
3615
|
"This request has no picture.": "이 요청에는 그림이 없습니다.",
|
|
3616
3616
|
"The selected part has no chest regions. The chest editor keeps its current part.": "선택한 파츠에는 가슴 영역이 없어요. 가슴 편집기는 지금 파츠를 그대로 둬요.",
|
|
3617
|
+
'Resize comment area: {0}': '코멘트 영역 크기를 조절해요: {0}',
|
|
3617
3618
|
};
|
|
@@ -150,26 +150,40 @@ export function bindPartsSubject(host:{
|
|
|
150
150
|
finally{for(const bitmap of bitmaps)bitmap.close();if(navigation===token){busy=false;host.el('stage-layout').setAttribute('aria-busy','false');comments?.refresh();}}
|
|
151
151
|
}
|
|
152
152
|
const redraw=()=>{void paint().catch(()=>{});};
|
|
153
|
+
const commentRegion=(pose:PartsPose,screen:ReturnType<typeof region>)=>{
|
|
154
|
+
const frame=box(),a=unprojectMark(screen,pose.camera),b=unprojectMark({x:screen.x+screen.width,y:screen.y+screen.height},pose.camera);
|
|
155
|
+
const stable=(n:number)=>Math.abs(n-Math.round(n))<1e-6?Math.round(n):n;
|
|
156
|
+
return snapImageRegion(region({x:stable(a.x),y:stable(a.y)},{x:stable(b.x),y:stable(b.y)},{x:0,y:0,width:frame.w,height:frame.h}));
|
|
157
|
+
};
|
|
153
158
|
const codec:CommentCodec<CommentRow,PartsPose>={
|
|
159
|
+
geometry:true,
|
|
154
160
|
read:raw=>{try{const c=parsePartsIssue(raw,false,true,false),camera={space:'image' as const,center:c.view.camera.center,zoom:c.view.camera.zoom,viewport:c.view.camera.viewport,visible:{x:c.view.camera.center.x-c.view.camera.viewport.width/c.view.camera.zoom/2,y:c.view.camera.center.y-c.view.camera.viewport.height/c.view.camera.zoom/2,width:c.view.camera.viewport.width/c.view.camera.zoom,height:c.view.camera.viewport.height/c.view.camera.zoom}},r=c.view.mode==='assembled'?c.rigRegion:c.imageRegion!;return {mode:'parts',viewport:'rig',screen:region(projectMark(r,camera),projectMark({x:r.x+r.width,y:r.y+r.height},camera)),world:r,camera,crop:{...c.crop,png:c.crop.png??''},bookmark:c};}catch{return null;}},
|
|
155
161
|
signature:pose=>[pose.sourceHash,pose.item.name,pose.item.imageHash,pose.view],
|
|
156
|
-
matches:(_mark,pose,raw)=>{try{const c=parsePartsIssue(raw,false,true,false);return pose.sourceHash===c.sourceHash&&pose.view.mode===c.view.mode&&(assembled()||c.parts[0]?.name===pose.item.name);}catch{return false;}},
|
|
162
|
+
matches:(_mark,pose,raw)=>{try{const c=parsePartsIssue(raw,false,true,false);assertPartsIssueBinding(c,sourceItems(),data.sourceHash);return pose.sourceHash===c.sourceHash&&pose.view.mode===c.view.mode&&(assembled()||c.parts[0]?.name===pose.item.name);}catch{return false;}},
|
|
157
163
|
label:raw=>{const issue=parsePartsIssue(raw,false,true,false);return `${issue.parts.map(part=>part.name).join(', ')} · ${issue.summary}`;},
|
|
158
164
|
chips:(pose,screen,existing)=>{
|
|
159
165
|
const visible=data.items.filter(item=>!hidden.has(item.name)),candidates=pose.view.mode==='assembled'?visible.map(item=>item.name):[];
|
|
160
166
|
if(existing)return {selected:parsePartsIssue(existing,false,true,false).parts.map(part=>part.name),candidates};
|
|
161
167
|
if(pose.view.mode==='item')return {selected:[pose.item.name],candidates};
|
|
162
|
-
const
|
|
168
|
+
const r=commentRegion(pose,screen);
|
|
163
169
|
const hits=new Set<string>(),layers=visible.flatMap(box=>{const img=loaded.get(box.name);return img?[sourceAlpha(box,img)]:[];});
|
|
164
170
|
const stepX=Math.max(1,r.width/32),stepY=Math.max(1,r.height/32);
|
|
165
171
|
for(let y=r.y+.5;y<r.y+r.height;y+=stepY)for(let x=r.x+.5;x<r.x+r.width;x+=stepX){const hit=pickAssembly(layers,x,y);if(hit)hits.add(hit.name);}
|
|
166
172
|
return {selected:visible.filter(item=>hits.has(item.name)).map(item=>item.name),candidates};
|
|
167
173
|
},
|
|
168
174
|
create:async(pose,_view,screen,crop,_bookmark,summary,parts)=>{
|
|
169
|
-
const
|
|
175
|
+
const r=commentRegion(pose,screen),single=pose.view.mode==='item';
|
|
170
176
|
return prepare({schema:'rig-review-parts-comment/2',id:crypto.randomUUID(),summary,sourceHash:data.sourceHash,parts:partsBinding(single?[pose.item.name]:parts??[]),rigRegion:single?{...r,x:r.x+pose.item.x,y:r.y+pose.item.y}:r,imageRegion:single?r:null,view:structuredClone(pose.view),crop,nativeCrop:null});
|
|
171
177
|
},
|
|
172
|
-
update:(raw,summary,parts)=>{
|
|
178
|
+
update:(raw,summary,parts,geometry)=>{
|
|
179
|
+
const existing=parsePartsIssue(raw,false,true,false);let updated=existing;
|
|
180
|
+
if(geometry){
|
|
181
|
+
const {pose,screen,crop}=geometry,r=commentRegion(pose,screen),single=pose.view.mode==='item';
|
|
182
|
+
if(pose.sourceHash!==existing.sourceHash)throw new Error('PARTS_COMMENT_STALE_SOURCE');
|
|
183
|
+
updated={...existing,rigRegion:single?{...r,x:r.x+pose.item.x,y:r.y+pose.item.y}:r,imageRegion:single?r:null,view:structuredClone(pose.view),crop,nativeCrop:null};
|
|
184
|
+
}
|
|
185
|
+
return prepare({...updated,summary,parts:existing.view.mode==='assembled'?partsBinding(parts??[]):existing.parts});
|
|
186
|
+
},
|
|
173
187
|
};
|
|
174
188
|
const pose=():PartsPose|null=>{
|
|
175
189
|
let camera=host.viewport.numericView().cameras.rig;const entry=item();if(!camera||!entry||busy||failed||disposed)return null;
|
|
@@ -177,7 +191,7 @@ export function bindPartsSubject(host:{
|
|
|
177
191
|
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}};
|
|
178
192
|
};
|
|
179
193
|
comments=bindStageComments<CommentRow,PartsPose>({general:host.recordComments?{create:summary=>({id:crypto.randomUUID(),summary}),matches:row=>!('schema' in row)}: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,
|
|
180
|
-
restore:async raw=>{const issue=parsePartsIssue(raw,false,true,false);assertPartsIssueBinding(issue,sourceItems(),data.sourceHash);selected=issue.parts[0]!.name;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();},
|
|
194
|
+
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();},
|
|
181
195
|
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});
|
|
182
196
|
return {
|
|
183
197
|
frameSize:(target:CameraTarget):PartsFrame|null=>{
|
package/web/stage-comments.ts
CHANGED
|
@@ -19,7 +19,9 @@ export interface CommentCodec<Row extends CommentRow,Pose extends CommentUiPose>
|
|
|
19
19
|
read:(row:Row)=>CommentUiMark|null;signature:(pose:Pose)=>unknown;matches:(mark:CommentUiMark,pose:Pose,row:Row)=>boolean;
|
|
20
20
|
label:(row:Row,mark:CommentUiMark)=>string;
|
|
21
21
|
chips?:(pose:Pose,screen:MarkRegion,existing?:Row)=>{selected:string[];candidates:string[]};
|
|
22
|
-
|
|
22
|
+
/** Opt in only when this codec can prepare replacement geometry and fresh pixel evidence. */
|
|
23
|
+
geometry?:boolean;
|
|
24
|
+
update?:(row:Row,summary:string,parts?:string[],geometry?:{pose:Pose;screen:MarkRegion;crop:StageComment['crop']})=>Promise<Row>|Row;
|
|
23
25
|
create:(pose:Pose,view:StageComment['viewport'],screen:MarkRegion,crop:StageComment['crop'],bookmark:unknown,summary:string,parts?:string[])=>Promise<Row>;
|
|
24
26
|
}
|
|
25
27
|
interface Host<Row extends CommentRow=Feedback,Pose extends CommentUiPose=CommentPose> {
|
|
@@ -76,8 +78,12 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
|
|
|
76
78
|
const updateRefusal=()=>{const raw=host.refusal?.()??null,reason=raw?t(raw):null,prev=refusalNote.textContent||'',nextTitle=reason??t(originalTitle);toggle.disabled=!!host.busy?.();toggle.setAttribute('aria-busy',String(toggle.disabled));if(toggle.title!==nextTitle)toggle.title=nextTitle;if(refusalNote.title!==(reason??''))refusalNote.title=reason??'';if(refusalNote.textContent!==(reason??''))refusalNote.textContent=reason??'';refusalNote.hidden=!reason;if(!list.hidden&&(reason??'')!==prev)renderList();return reason;};
|
|
77
79
|
const layers=new Map<StageComment['viewport'],HTMLDivElement>();for(const [key,pane]of Object.entries(host.viewports)){const layer=document.createElement('div');layer.className='stage-comment-layer';pane!.append(layer);layers.set(key as StageComment['viewport'],layer);}
|
|
78
80
|
let enabled=false,disposed=false,pending:{view:StageComment['viewport'];start:MarkPoint;end:MarkPoint;mode:string;id:number;interaction:number;settled:Promise<void>}|null=null,composer:HTMLFormElement|null=null,composerReadOnly=false,composerGeneral=false,syncComposerLang:(()=>void)|null=null,draftMark:{view:StageComment['viewport'];mode:string;screen:MarkRegion}|null=null,busy=false,last='',raf=0,interaction=0;
|
|
81
|
+
let geometryEdit:{view:StageComment['viewport'];screen:MarkRegion;id?:string;update:(screen:MarkRegion)=>void;changed:boolean;camera:string}|null=null;
|
|
82
|
+
let geometryDrag:{id:number;start:MarkPoint;screen:MarkRegion;handle:string}|null=null;
|
|
83
|
+
let suppressPinClick=false;
|
|
84
|
+
let pinPress:{id:number;view:StageComment['viewport'];start:MarkPoint;pin:HTMLButtonElement}|null=null;
|
|
79
85
|
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);};
|
|
80
|
-
const cancel=()=>{++interaction;const previous=pending;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='';};
|
|
86
|
+
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='';};
|
|
81
87
|
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'));};
|
|
82
88
|
const assertEdit=(general=false)=>{const reason=general?null:updateRefusal();if(reason){setCapture(false);host.error(reason);throw new Error(reason);}if(host.blocked())throw new Error(t('COMMENT_BUSY: wait for inspection'));};
|
|
83
89
|
let jumpGeneration = 0;
|
|
@@ -85,6 +91,10 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
|
|
|
85
91
|
const jump = async (row: Row): Promise<boolean> => {
|
|
86
92
|
const mark = readMark(row);if (!mark) return false;
|
|
87
93
|
cancel();const generation = interaction, request = ++jumpGeneration;
|
|
94
|
+
// Editing a mark already visible in this parts view must not replay its navigation bookmark.
|
|
95
|
+
const pose=host.pose(mark.viewport);
|
|
96
|
+
if(host.codec?.geometry&&pose&&host.codec.matches(mark,pose,row)){last='';return true;}
|
|
97
|
+
|
|
88
98
|
hiddenPanes ??= Object.values(host.viewports).map(pane => ({pane: pane!, visibility: pane!.style.visibility}));
|
|
89
99
|
try {
|
|
90
100
|
for (const {pane} of hiddenPanes) pane.style.visibility = 'hidden';
|
|
@@ -117,7 +127,7 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
|
|
|
117
127
|
if(reason){setCapture(false);host.error(reason);return;}
|
|
118
128
|
setCapture(layers.size>0);for(const view of layers.keys())host.pose(view);
|
|
119
129
|
};
|
|
120
|
-
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());
|
|
130
|
+
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);}};
|
|
121
131
|
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()){
|
|
122
132
|
const mark=readMark(f),row=document.createElement('div');row.className='stage-comment-item';row.dataset.commentId=f.id;
|
|
123
133
|
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);
|
|
@@ -132,11 +142,20 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
|
|
|
132
142
|
if(!general&&(!placementMode||currentMode&¤tMode!==placementMode)){cancel();return;}
|
|
133
143
|
const locked=!!existing&&host.locked(existing.id),initialRefusal=existing&&!general?updateRefusal():null;
|
|
134
144
|
if(existing&&!initialRefusal&&host.blocked()){host.error(t('COMMENT_BUSY: wait for inspection'));return;}
|
|
135
|
-
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';
|
|
145
|
+
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';
|
|
136
146
|
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??'';
|
|
137
147
|
if(locked||initialRefusal){field.readOnly=true;field.setAttribute('aria-readonly','true');}
|
|
138
148
|
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);
|
|
139
|
-
const place=()=>{if(general)return;
|
|
149
|
+
const place=()=>{if(general)return;
|
|
150
|
+
if(host.codec?.geometry){
|
|
151
|
+
const right=pane.clientWidth-screen.x-screen.width-12,left=screen.x-12,available=Math.max(left,right);
|
|
152
|
+
if(available>=160){
|
|
153
|
+
const width=Math.min(286,available);form.style.width=width+'px';const height=form.offsetHeight||132;
|
|
154
|
+
Object.assign(form.style,{left:(right>=left?screen.x+screen.width+8:screen.x-width-8)+'px',top:Math.max(4,Math.min(screen.y,pane.clientHeight-height-4))+'px'});return;
|
|
155
|
+
}
|
|
156
|
+
form.style.width='';
|
|
157
|
+
}
|
|
158
|
+
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'});};
|
|
140
159
|
let removeBtn:HTMLButtonElement|null=null,errorSource='';
|
|
141
160
|
if(existing&&!locked){
|
|
142
161
|
const remove=removeBtn=document.createElement('button');remove.type='button';remove.className='stage-comment-delete';remove.textContent=t('Delete');
|
|
@@ -153,7 +172,7 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
|
|
|
153
172
|
// Capture all view context now; camera or dial changes while typing cannot rebind the mark.
|
|
154
173
|
const pose=view?host.pose(view):null,bookmark=general?null:copy(host.bookmark()),turn=pose?.turn===undefined?null:copy(pose.turn);
|
|
155
174
|
const initialParts = pose ? host.codec?.chips?.(pose, screen, existing) : undefined;
|
|
156
|
-
let selectedParts = initialParts?.selected.slice();
|
|
175
|
+
let selectedParts = initialParts?.selected.slice(),partsTouched=!!existing;
|
|
157
176
|
const chipBox = initialParts ? document.createElement('div') : null;
|
|
158
177
|
const chipNames = initialParts ? [...new Set([...initialParts.selected, ...initialParts.candidates])] : [];
|
|
159
178
|
const syncChips = () => {
|
|
@@ -165,6 +184,7 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
|
|
|
165
184
|
chip.setAttribute('aria-pressed', String(selectedParts!.includes(name)));
|
|
166
185
|
chip.onclick = () => {
|
|
167
186
|
if (busy || composerReadOnly) return;
|
|
187
|
+
partsTouched=true;
|
|
168
188
|
const chosen = new Set(selectedParts);
|
|
169
189
|
if (chosen.has(name)) chosen.delete(name);else chosen.add(name);
|
|
170
190
|
selectedParts = chipNames.filter(part => chosen.has(part));
|
|
@@ -179,8 +199,19 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
|
|
|
179
199
|
syncComposerLang=()=>{if(composer!==form)return;form.setAttribute('aria-label',t('Comment composer'));if(general)form.style.position='relative';field.setAttribute('aria-label',t('Comment text'));field.placeholder=t('Describe this spot…');hint.textContent=t(composerReadOnly?'Read only · Escape closes':'Enter saves · Escape cancels');if(removeBtn)removeBtn.textContent=t('Delete');if(errorSource)error.textContent=t(errorSource);syncChips();};
|
|
180
200
|
pane.append(form);place();
|
|
181
201
|
const previous=existing?readMark(existing):null;
|
|
182
|
-
|
|
202
|
+
let prepared=general?Promise.resolve(null):previous?Promise.resolve(previous.crop):pose?crop(pose,screen):Promise.reject(new Error('COMMENT_VIEW_UNAVAILABLE'));
|
|
183
203
|
prepared.catch(()=>{});
|
|
204
|
+
if(view&&pose&&host.codec?.geometry&&!composerReadOnly){
|
|
205
|
+
geometryEdit={view,screen:{...screen},id:existing?.id,changed:false,camera:JSON.stringify(pose.camera),update:next=>{
|
|
206
|
+
const a=unprojectMark(next,pose.camera),b=unprojectMark({x:next.x+next.width,y:next.y+next.height},pose.camera);
|
|
207
|
+
let x=Math.round(a.x),y=Math.round(a.y),right=Math.round(b.x),bottom=Math.round(b.y);
|
|
208
|
+
if(right<=x){if(geometryDrag?.handle.includes('w'))x=right-1;else right=x+1;}
|
|
209
|
+
if(bottom<=y){if(geometryDrag?.handle.includes('n'))y=bottom-1;else bottom=y+1;}
|
|
210
|
+
screen=region(projectMark({x,y},pose.camera),projectMark({x:right,y:bottom},pose.camera));draftMark={view,mode:placementMode!,screen};geometryEdit!.screen=screen;geometryEdit!.changed=true;
|
|
211
|
+
if(!partsTouched){selectedParts=host.codec?.chips?.(pose,screen)?.selected.slice();syncChips();}
|
|
212
|
+
prepared=crop(pose,screen);prepared.catch(()=>{});last='';place();
|
|
213
|
+
}};
|
|
214
|
+
}
|
|
184
215
|
form.onkeydown=e=>{if(e.key==='Escape'){e.preventDefault();e.stopPropagation();setOpen(false);pane.focus();}};
|
|
185
216
|
form.onsubmit=async e=>{e.preventDefault();if(busy)return;if(generation!==interaction||view&&host.pose(view)&&host.pose(view!)?.mode!==placementMode){cancel();return;}const summary=field.value.trim();if(!summary){field.focus();return;}try{
|
|
186
217
|
if(selectedParts && !selectedParts.length)throw new Error(t('Select at least one part.'));
|
|
@@ -188,7 +219,9 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
|
|
|
188
219
|
assertEdit(general);if(host.locked(existing.id))throw new Error(t('COMMENT_SUBMITTED: submitted evidence is immutable'));
|
|
189
220
|
busy=true;field.disabled=true;syncChips();
|
|
190
221
|
if(!general&&host.codec?.update){
|
|
191
|
-
const
|
|
222
|
+
const geometry=geometryEdit?.changed&&pose?{pose,screen:{...screen},crop:(await prepared)!}:undefined;
|
|
223
|
+
if(disposed||generation!==interaction)return;assertEdit(general);
|
|
224
|
+
const replacement=await host.codec.update(copy(existing),summary,selectedParts?.slice(),geometry);
|
|
192
225
|
if(disposed||generation!==interaction)return;
|
|
193
226
|
assertEdit(general);if(host.locked(existing.id))throw new Error(t('COMMENT_SUBMITTED: submitted evidence is immutable'));
|
|
194
227
|
const all=host.feedback(),index=all.indexOf(existing);
|
|
@@ -219,10 +252,44 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
|
|
|
219
252
|
const disposers:(()=>void)[]=[];
|
|
220
253
|
for(const [key,pane]of Object.entries(host.viewports)){
|
|
221
254
|
const view=key as StageComment['viewport'],local=(e:PointerEvent)=>{const r=pane!.getBoundingClientRect();return {x:Math.max(0,Math.min(pane!.clientWidth,e.clientX-r.left-pane!.clientLeft)),y:Math.max(0,Math.min(pane!.clientHeight,e.clientY-r.top-pane!.clientTop))};};
|
|
222
|
-
const down=(e:PointerEvent)=>{
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
255
|
+
const down=(e:PointerEvent)=>{
|
|
256
|
+
if(e.button!==0||!e.isPrimary)return;
|
|
257
|
+
const target=e.target as Element,pin=host.codec?.geometry?target.closest<HTMLButtonElement>('.stage-comment-pin'):null;
|
|
258
|
+
const handle=target.closest<HTMLElement>('[data-comment-handle]')?.dataset.commentHandle;
|
|
259
|
+
if(geometryEdit?.view===view&&handle&&!e.shiftKey){
|
|
260
|
+
if(busy||host.blocked()||geometryEdit.id&&host.locked(geometryEdit.id))return;
|
|
261
|
+
try{assertEdit();}catch{return;}
|
|
262
|
+
e.preventDefault();e.stopImmediatePropagation();suppressPinClick=true;geometryDrag={id:e.pointerId,start:local(e),screen:{...geometryEdit.screen},handle};pane!.setPointerCapture(e.pointerId);return;
|
|
263
|
+
}
|
|
264
|
+
if(pin&&!host.blocked()){
|
|
265
|
+
if(!enabled)setOpen(true);if(!enabled)return;
|
|
266
|
+
try{assertCapture();}catch{return;}
|
|
267
|
+
e.preventDefault();e.stopImmediatePropagation();suppressPinClick=true;pinPress={id:e.pointerId,view,start:local(e),pin};pane!.setPointerCapture(e.pointerId);return;
|
|
268
|
+
}
|
|
269
|
+
if(target.closest('.stage-comment-ui,button,input')&&!(e.shiftKey&&handle&&host.codec?.geometry)){if(host.codec?.geometry)e.stopImmediatePropagation();return;}
|
|
270
|
+
if(enabled||!inline&&!list.hidden){try{assertCapture();}catch{return;}}if(!enabled||host.blocked())return;e.preventDefault();e.stopImmediatePropagation();cancel();const mode=host.pose(view)?.mode;if(!mode)return;const at=local(e),generation=interaction;pending={view,start:at,end:at,mode,id:e.pointerId,interaction:generation,settled:host.pause()};pending.settled.catch(e=>{if(interaction===generation&&!disposed)host.error(String(e));});pane!.setPointerCapture(e.pointerId);};
|
|
271
|
+
const move=(e:PointerEvent)=>{
|
|
272
|
+
if(geometryDrag?.id===e.pointerId&&geometryEdit){
|
|
273
|
+
e.preventDefault();e.stopImmediatePropagation();const p=local(e),g=geometryDrag,r=g.screen,dx=p.x-g.start.x,dy=p.y-g.start.y;
|
|
274
|
+
let x=r.x,y=r.y,right=r.x+r.width,bottom=r.y+r.height;
|
|
275
|
+
if(g.handle==='move'){x=Math.max(0,Math.min(pane!.clientWidth-r.width,x+dx));y=Math.max(0,Math.min(pane!.clientHeight-r.height,y+dy));right=x+r.width;bottom=y+r.height;}
|
|
276
|
+
else {if(g.handle.includes('w'))x=Math.max(0,Math.min(right-1,x+dx));if(g.handle.includes('e'))right=Math.min(pane!.clientWidth,Math.max(x+1,right+dx));if(g.handle.includes('n'))y=Math.max(0,Math.min(bottom-1,y+dy));if(g.handle.includes('s'))bottom=Math.min(pane!.clientHeight,Math.max(y+1,bottom+dy));}
|
|
277
|
+
geometryEdit.update({x,y,width:right-x,height:bottom-y});return;
|
|
278
|
+
}
|
|
279
|
+
if(pinPress?.id===e.pointerId){
|
|
280
|
+
const p=pinPress,at=local(e);if(Math.hypot(at.x-p.start.x,at.y-p.start.y)<4)return;
|
|
281
|
+
e.preventDefault();e.stopImmediatePropagation();// Transfer the held pointer to new capture without releasing it.
|
|
282
|
+
const start=p.start;pinPress=null;cancel();const mode=host.pose(view)?.mode;if(!mode)return;
|
|
283
|
+
pending={view,start,end:at,mode,id:e.pointerId,interaction,settled:host.pause()};pending.settled.catch(error=>host.error(String(error)));
|
|
284
|
+
}
|
|
285
|
+
if(!pending||pending.id!==e.pointerId)return;e.preventDefault();e.stopImmediatePropagation();pending.end=local(e);draftMark={view,mode:pending.mode,screen:region(pending.start,pending.end)};last='';};
|
|
286
|
+
const up=async(e:PointerEvent)=>{
|
|
287
|
+
if(geometryDrag?.id===e.pointerId){e.preventDefault();e.stopImmediatePropagation();geometryDrag=null;if(pane!.hasPointerCapture(e.pointerId))pane!.releasePointerCapture(e.pointerId);return;}
|
|
288
|
+
if(pinPress?.id===e.pointerId){e.preventDefault();e.stopImmediatePropagation();const pin=pinPress.pin;pinPress=null;if(pane!.hasPointerCapture(e.pointerId))pane!.releasePointerCapture(e.pointerId);pin.click();return;}
|
|
289
|
+
if(!pending||pending.id!==e.pointerId)return;e.preventDefault();e.stopImmediatePropagation();const p=pending;pending=null;if(pane!.hasPointerCapture(e.pointerId))pane!.releasePointerCapture(e.pointerId);try{await p.settled;assertCapture();if(disposed||interaction!==p.interaction||!enabled)return;const r=Math.hypot(p.end.x-p.start.x,p.end.y-p.start.y)<4?region(p.start,p.start):region(p.start,p.end);openComposer(view,r,undefined,p.mode);}catch(error){host.error(String(error));cancel();}};
|
|
290
|
+
const abort=(e:PointerEvent)=>{if(pending?.view===view&&pending.id===e.pointerId||geometryDrag?.id===e.pointerId||pinPress?.id===e.pointerId)cancel();};
|
|
291
|
+
const suppressClick=(e:MouseEvent)=>{if(host.codec?.geometry&&(e.target as Element)?.closest('.stage-comment-pin')&&e.isTrusted&&e.detail>0&&suppressPinClick){suppressPinClick=false;e.preventDefault();e.stopImmediatePropagation();}};
|
|
292
|
+
pane!.addEventListener('click',suppressClick,true);disposers.push(()=>pane!.removeEventListener('click',suppressClick,true));
|
|
226
293
|
pane!.addEventListener('pointerdown',down,true);pane!.addEventListener('pointermove',move,true);pane!.addEventListener('pointerup',up,true);pane!.addEventListener('pointercancel',abort,true);pane!.addEventListener('lostpointercapture',abort,true);
|
|
227
294
|
disposers.push(()=>{pane!.removeEventListener('pointerdown',down,true);pane!.removeEventListener('pointermove',move,true);pane!.removeEventListener('pointerup',up,true);pane!.removeEventListener('pointercancel',abort,true);pane!.removeEventListener('lostpointercapture',abort,true);});
|
|
228
295
|
}
|
|
@@ -234,11 +301,33 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
|
|
|
234
301
|
// capture there is nothing to place, so this per-frame loop skips it.
|
|
235
302
|
const poses=new Map(all.length||draftMark||pending?[...layers.keys()].map(view=>[view,host.pose(view)]):[]);
|
|
236
303
|
if(draftMark&&poses.get(draftMark.view)?.mode!==draftMark.mode||pending&&poses.get(pending.view)?.mode!==pending.mode)cancel();
|
|
237
|
-
|
|
238
|
-
|
|
304
|
+
if(geometryEdit&&(geometryEdit.id&&host.locked(geometryEdit.id)||JSON.stringify(poses.get(geometryEdit.view)?.camera)!==geometryEdit.camera))cancel();
|
|
305
|
+
const signature=JSON.stringify([geometryEdit?.screen,curLang(),refusal,all.map(({f,mark})=>[f.id,f.summary,mark!.mode,mark!.world]),[...poses].map(([view,p])=>[view,host.codec&&p?host.codec.signature(p):[p?.mode,p?.animation,p?.frame,p?.timeBasis,p?.time,p?.turn,p?.camera,p?.referenceId,p?.referenceHash]]),draftMark]);
|
|
306
|
+
if(signature!==last){last=signature;for(const layer of layers.values())layer.replaceChildren();const occupied=new Map<StageComment['viewport'],{x:number;y:number;width:number;height:number}[]>();for(const [i,{f,mark:m}]of all.entries()){
|
|
239
307
|
const mark=m!,pose=poses.get(mark.viewport),layer=layers.get(mark.viewport);if(refusal||!pose||!layer||(host.codec?!host.codec.matches(mark,pose,f):pose.mode!==mark.mode||pose.animation!==mark.animation||pose.sourceHash!==mark.sourceHash||pose.modelHash!==mark.modelHash||pose.referenceId!==mark.referenceId||pose.referenceHash!==mark.referenceHash||JSON.stringify(pose.frame)!==JSON.stringify(mark.frame)||JSON.stringify(pose.timeBasis??null)!==JSON.stringify(mark.timeBasis??null)||Math.abs((pose.time??0)-(mark.time??0))>1e-7||JSON.stringify(pose.turn)!==JSON.stringify((f.context as any)?.turn??null)))continue;
|
|
240
|
-
const a=projectMark(mark.world,pose.camera),b=projectMark({x:mark.world.x+mark.world.width,y:mark.world.y+mark.world.height},pose.camera),r=region(a,b),box=rectElement(r),pin=document.createElement('button');pin.type='button';pin.className='stage-comment-pin stage-comment-ui';pin.textContent=String(i+1);pin.setAttribute('aria-label',`${t('Comment {0}:').replace('{0}',String(i+1))} ${f.summary}`);pin.title=f.summary;Object.assign(pin.style,{left:r.x+'px',top:r.y+'px'});pin.onclick=()=>openComment(f);layer.append(box,pin);
|
|
241
|
-
|
|
308
|
+
const a=projectMark(mark.world,pose.camera),b=projectMark({x:mark.world.x+mark.world.width,y:mark.world.y+mark.world.height},pose.camera),r=geometryEdit?.id===f.id?geometryEdit.screen:region(a,b),box=rectElement(r),pin=document.createElement('button');pin.type='button';pin.className='stage-comment-pin stage-comment-ui';pin.textContent=String(i+1);pin.setAttribute('aria-label',`${t('Comment {0}:').replace('{0}',String(i+1))} ${f.summary}`);pin.title=f.summary;Object.assign(pin.style,{left:r.x+'px',top:r.y+'px'});pin.onclick=()=>openComment(f);layer.append(box,pin);
|
|
309
|
+
const pane=host.viewports[mark.viewport]!;
|
|
310
|
+
if(host.codec?.geometry&&r.x>=0&&r.y>=0&&r.x<=pane.clientWidth&&r.y<=pane.clientHeight){
|
|
311
|
+
const width=pin.offsetWidth||24,height=pin.offsetHeight||24,placed=occupied.get(mark.viewport)??[];
|
|
312
|
+
if(!occupied.has(mark.viewport)){
|
|
313
|
+
occupied.set(mark.viewport,placed);
|
|
314
|
+
if(geometryEdit?.view===mark.viewport){const r=geometryEdit.screen;for(const [x,y]of [[0,0],[.5,0],[1,0],[1,.5],[1,1],[.5,1],[0,1],[0,.5]])placed.push({x:r.x+r.width*x!,y:r.y+r.height*y!,width:12,height:12});}
|
|
315
|
+
}
|
|
316
|
+
const clamp=(n:number,size:number,limit:number)=>Math.max(size/2,Math.min(limit-size/2,n));
|
|
317
|
+
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);
|
|
318
|
+
let x=clamp(r.x,width,pane.clientWidth),y=clamp(r.y,height,pane.clientHeight),distance=Infinity;
|
|
319
|
+
if(!clear(x,y))for(let py=height/2;py<=pane.clientHeight-height/2;py+=height+4)for(let px=width/2;px<=pane.clientWidth-width/2;px+=width+4){const d=(px-r.x)**2+(py-r.y)**2;if(d<distance&&clear(px,py)){x=px;y=py;distance=d;}}
|
|
320
|
+
placed.push({x,y,width,height});Object.assign(pin.style,{left:x+'px',top:y+'px'});
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
}if(draftMark&&!geometryEdit)layers.get(draftMark.view)?.append(rectElement(draftMark.screen));
|
|
324
|
+
if(geometryEdit){
|
|
325
|
+
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);
|
|
326
|
+
for(const [name,x,y]of [['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){
|
|
327
|
+
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));
|
|
328
|
+
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);
|
|
329
|
+
}
|
|
330
|
+
}}};
|
|
242
331
|
const paint=()=>{if(disposed)return;renderPins();raf=requestAnimationFrame(paint);};
|
|
243
332
|
const offLang=onLang(()=>{if(disposed)return;updateRefusal();renderList();syncComposerLang?.();last='';renderPins();});
|
|
244
333
|
refresh();paint();return {active:()=>enabled,draft:()=>!!pending||!!composer&&!composerReadOnly,refresh,dispose:()=>{disposed=true;ro?.disconnect();offLang();cancelAnimationFrame(raf);cancel();window.removeEventListener('blur',cancel);window.removeEventListener('resize',placeList);document.removeEventListener('keydown',key);for(const dispose of disposers)dispose();for(const layer of layers.values())layer.remove();toggle.onclick=null;list.remove();refusalNote.remove();}};
|