rig-review 4.0.2 → 4.2.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.
@@ -82,6 +82,11 @@ export class PartInspection {
82
82
  value():ControlPart|null {const part=this.live();if(!part)return null;const state=this.sides.get(part.side),identity=partIdentity(state?.identity??null,part.slot);return {...part,...(identity?{identity}:{} )};}
83
83
  assertIdentity(expected:ControlPart|null|undefined):void {if(!expected)return;this.validate(expected);const actual=partIdentity(this.sides.get(expected.side)?.identity??null,expected.slot);if(!actual)throw new Error(`PART_IDENTITY_UNAVAILABLE: ${expected.side} / ${expected.slot} has no held public snapshot`);if(expected.identity&&JSON.stringify(actual)!==JSON.stringify(parsePartIdentity(expected.identity)))throw new Error(`PART_IDENTITY_MISMATCH: ${expected.side} / ${expected.slot} no longer resolves the bookmarked skin/attachment/set/reason`);}
84
84
  validate(value:ControlPart|null|undefined):void {if(!value)return;parseControlPart(value);const state=this.sides.get(value.side);if(!state||!state.entries.some(e=>e.slot===value.slot))throw new Error(`PART_UNAVAILABLE: ${value.side} / ${value.slot}`);}
85
+ /** An in-place rebuild keeps the subject, not the old attachment identity; removed or refused slots become Whole rig. */
86
+ restoreSelection(value:ControlPart|null):void {
87
+ const available=value&&this.sides.get(value.side)?.entries.some(entry=>entry.slot===value.slot);
88
+ try{this.select(available?{side:value.side,slot:value.slot,mode:value.mode}:null);}catch{this.select(null);}
89
+ }
85
90
  select(value:ControlPart|null):void {this.validate(value);const refusal=value?this.refused.get(value.side):undefined;if(refusal)throw new Error(`PARTS_UNAVAILABLE: ${value!.side} / ${refusal.message}`);const next=value?{side:value.side,slot:value.slot,mode:value.mode}:null,previous=this.selected;try{for(const [side,state]of this.sides)if(state.frame)state.player.renderer.render(selectedFrame(state.frame,next,side));}catch(error){for(const [side,state]of this.sides)if(state.frame)state.player.renderer.render(selectedFrame(state.frame,previous,side));throw error;}this.selected=next;}
86
91
  /** Called inside the successful draw boundary, before compare submission is measured complete. */
87
92
  present(side:ControlPart['side']):void {const state=this.sides.get(side);if(!state)return;this.commit(side,state,this.capture(state));}
@@ -55,7 +55,7 @@ export function createPartsViewport(host:PartsViewportHost){const state=createVi
55
55
 
56
56
  import type {partsViewJson} from '../src/parts-view.ts';
57
57
  import {defaultPartsComparison,paintingRectangle,differencePixels,assertOriginalPaintingSize,type PartsComparison} from '../src/parts-comparison.ts';
58
- import {paintAssembly,paintMesh,paintOverlay,paintPaintingCrop,type Box} from './parts-render.ts';
58
+ import {paintAssembly,paintMesh,paintOverlay,paintPaintingCrop,pickAssembly,type Box} from './parts-render.ts';
59
59
  import {bindStageComments,type CommentCodec,type CommentUiPose,type CommentRow} from './stage-comments.ts';
60
60
  import {parsePartsIssue,assertPartsIssueBinding,snapImageRegion,type PartsIssue} from '../src/parts-comment.ts';
61
61
  import {projectMark,unprojectMark,region} from '../src/stage-comment.ts';
@@ -81,11 +81,11 @@ interface PartsPose extends CommentUiPose {item:Item;sourceHash:string;view:Part
81
81
  /** Source-specific pixels and evidence. Shell, list, toolbar, controller and act stay in main.ts. */
82
82
  export function bindPartsSubject(host:{
83
83
  data:PartsSubjectData;canvas:HTMLCanvasElement;referenceCanvas:HTMLCanvasElement;viewport:ViewportController;
84
- el:ViewportProvider['el'];toolbar:HTMLElement;commentsHost:HTMLElement;issues:PartsIssue[];recordComments?:CommentRow[];
84
+ el:ViewportProvider['el'];toolbar:HTMLElement;commentsHost:HTMLElement;openComments?:()=>void;hasPicture?:()=>boolean;issues:PartsIssue[];recordComments?:CommentRow[];
85
85
  request:(path:string,init?:RequestInit)=>Promise<Response>;base:string;paintingPath:string;
86
- mesh:()=>boolean;restoreMesh:(on:boolean)=>void;images:()=>boolean;changed:()=>void;selectionChanged:()=>void;locked:(id:string)=>boolean;refusal:()=>string|null;drawn:(input:{state:'loaded'}|{state:'failed';reason:string})=>void;message:ViewportProvider['message'];
86
+ 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
87
  }) {
88
- const data=host.data,hidden=new Set<string>(),images=new Map<number,Promise<HTMLImageElement>>();
88
+ const data=host.data,hidden=new Set<string>(),images=new Map<number,Promise<HTMLImageElement>>(),loaded=new Map<string,HTMLImageElement>(),assemblyAlpha=new Map<string,{box:Box;alpha:Uint8ClampedArray}>();
89
89
  let selected:string|null=null,solo=false,comparison:PartsComparison=defaultPartsComparison(),token=0,disposed=false,busy=false,failed=false;
90
90
  let drawnFrame:{w:number;h:number}|null=null,drawnReferenceFrame:{w:number;h:number}|null=null;
91
91
  let drawnRegion:Box|null=null,drawnSolo=false;
@@ -98,7 +98,8 @@ export function bindPartsSubject(host:{
98
98
  const image=await loadViewportImage(await host.request(path));
99
99
  if(disposed)throw new Error('PARTS_PAINT_FAILED');return image;
100
100
  };
101
- const image=(entry:Item)=>{let pending=images.get(entry.index);if(!pending){pending=loadImage(`${host.base}/image/${entry.index}`);images.set(entry.index,pending);}return pending;};
101
+ const image=(entry:Item)=>{let pending=images.get(entry.index);if(!pending){pending=loadImage(`${host.base}/image/${entry.index}`).then(img=>{loaded.set(entry.name,img);return img;});images.set(entry.index,pending);}return pending;};
102
+ const sourceAlpha=(entry:Item,img:HTMLImageElement)=>{const cached=assemblyAlpha.get(entry.name);if(cached)return cached;const c=makeCanvas(entry.w,entry.h),rgba=(c.getContext('2d')!.drawImage(img,0,0),c.getContext('2d')!.getImageData(0,0,c.width,c.height).data),alpha=new Uint8ClampedArray(c.width*c.height);for(let i=0;i<alpha.length;i++)alpha[i]=rgba[i*4+3]!;const layer={box:{...entry,w:c.width,h:c.height},alpha};assemblyAlpha.set(entry.name,layer);return layer;};
102
103
  const painting=()=>original??=loadImage(host.paintingPath);
103
104
  const partsBinding=(names:readonly string[])=>names.map(name=>{const entry=data.items.find(item=>item.name===name);if(!entry?.imageHash)throw new Error('PARTS_COMMENT_PART_MISMATCH');return {name,imageHash:entry.imageHash};});
104
105
  const sourceItems=()=>new Map(data.items.map(item=>[item.name,{...item,imageHash:item.imageHash!}]));
@@ -115,7 +116,7 @@ export function bindPartsSubject(host:{
115
116
  try{
116
117
  if(data.mode!=='parts'||!data.items.length)throw new Error('PARTS_IMAGE_UNAVAILABLE');
117
118
  const frame=box(),referenceBox=selected===null?null:item(),shown=assembled()?data.items.filter(item=>!hidden.has(item.name)):[item()];
118
- const layers=await Promise.all(shown.map(async entry=>({box:entry,image:await image(entry)})));
119
+ const layers=await Promise.all(shown.map(async entry=>{const img=await image(entry);loaded.set(entry.name,img);return {box:entry,image:img};}));
119
120
  let reference:HTMLCanvasElement|null=null;
120
121
  if(data.painting&&data.rigSize){
121
122
  const original=await painting();
@@ -154,7 +155,16 @@ export function bindPartsSubject(host:{
154
155
  signature:pose=>[pose.sourceHash,pose.item.name,pose.item.imageHash,pose.view],
155
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;}},
156
157
  label:raw=>{const issue=parsePartsIssue(raw,false,true,false);return `${issue.parts.map(part=>part.name).join(', ')} · ${issue.summary}`;},
157
- chips:(pose,_screen,existing)=>({selected:existing?parsePartsIssue(existing,false,true,false).parts.map(part=>part.name):(pose.view.mode==='item'?[pose.item.name]:[]),candidates:pose.view.mode==='assembled'?data.items.filter(item=>!hidden.has(item.name)).map(item=>item.name):[]}),
158
+ chips:(pose,screen,existing)=>{
159
+ const visible=data.items.filter(item=>!hidden.has(item.name)),candidates=pose.view.mode==='assembled'?visible.map(item=>item.name):[];
160
+ if(existing)return {selected:parsePartsIssue(existing,false,true,false).parts.map(part=>part.name),candidates};
161
+ if(pose.view.mode==='item')return {selected:[pose.item.name],candidates};
162
+ const frame=box(),r=snapImageRegion(region(unprojectMark(screen,pose.camera),unprojectMark({x:screen.x+screen.width,y:screen.y+screen.height},pose.camera),{x:0,y:0,width:frame.w,height:frame.h}));
163
+ const hits=new Set<string>(),layers=visible.flatMap(box=>{const img=loaded.get(box.name);return img?[sourceAlpha(box,img)]:[];});
164
+ const stepX=Math.max(1,r.width/32),stepY=Math.max(1,r.height/32);
165
+ 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
+ return {selected:visible.filter(item=>hits.has(item.name)).map(item=>item.name),candidates};
167
+ },
158
168
  create:async(pose,_view,screen,crop,_bookmark,summary,parts)=>{
159
169
  const frame=box(),r=snapImageRegion(region(unprojectMark(screen,pose.camera),unprojectMark({x:screen.x+screen.width,y:screen.y+screen.height},pose.camera),{x:0,y:0,width:frame.w,height:frame.h})),single=pose.view.mode==='item';
160
170
  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});
@@ -166,7 +176,7 @@ export function bindPartsSubject(host:{
166
176
  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}};
167
177
  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}};
168
178
  };
169
- 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,toggle:host.el<HTMLButtonElement>('stage-comment'),viewports:{rig:host.el('rig-viewport')},pose,pause:async()=>{},bookmark:()=>null,
179
+ 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,
170
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();},
171
181
  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});
172
182
  return {
@@ -186,7 +196,7 @@ export function bindPartsSubject(host:{
186
196
  comparison:()=>comparison,setComparison:(mode:PartsComparison['mode'])=>{comparison=mode==='difference'?{mode,opacity:comparison.opacity,threshold:0}:{mode,opacity:comparison.opacity};redraw();},
187
197
  opacity:(value:number)=>{comparison.opacity=value;redraw();},paint,redraw,
188
198
  async ready(){if(data.painting)host.viewport.state.cameraSync=true;await paint();},
189
- dispose(){disposed=true;++token;comments?.dispose();images.clear();},
199
+ dispose(){disposed=true;++token;comments?.dispose();images.clear();loaded.clear();assemblyAlpha.clear();},
190
200
  };
191
201
  }
192
202
 
@@ -23,11 +23,11 @@ export interface CommentCodec<Row extends CommentRow,Pose extends CommentUiPose>
23
23
  create:(pose:Pose,view:StageComment['viewport'],screen:MarkRegion,crop:StageComment['crop'],bookmark:unknown,summary:string,parts?:string[])=>Promise<Row>;
24
24
  }
25
25
  interface Host<Row extends CommentRow=Feedback,Pose extends CommentUiPose=CommentPose> {
26
- toolbar:HTMLElement;toggle?:HTMLButtonElement;listHost?:HTMLElement;viewports:Partial<Record<StageComment['viewport'],HTMLElement>>;
26
+ toolbar:HTMLElement;toggle?:HTMLButtonElement;listHost?:HTMLElement;openList?:()=>void;hasPicture?:()=>boolean;viewports:Partial<Record<StageComment['viewport'],HTMLElement>>;
27
27
  pose:(view:StageComment['viewport'])=>Pose|null;pause:()=>Promise<void>;
28
28
  bookmark:()=>unknown;restore:(bookmark:unknown,timeOnly?:boolean)=>Promise<void>;
29
29
  feedback:()=>Row[];locked:(id:string)=>boolean;
30
- add:(feedback:Row,side?:'a'|'b')=>void;changed:()=>void;error:(message:string)=>void;
30
+ add:(feedback:Row,side?:'a'|'b')=>void;changed:()=>void|Promise<void>;error:(message:string)=>void;
31
31
  general?:{create:(summary:string)=>Row;matches:(row:Row)=>boolean};
32
32
  refusal?:()=>string|null;blocked:()=>boolean;busy?:()=>boolean;busyError?:(message:string)=>void;shortcutBlocked?:()=>boolean;shortcutActive?:()=>boolean;codec?:CommentCodec<Row,Pose>;
33
33
  }
@@ -66,7 +66,7 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
66
66
  const readMark=(row:Row):CommentUiMark|null=>host.codec?host.codec.read(row):markOf(row as unknown as Feedback);
67
67
  const toggle=host.toggle??document.getElementById('stage-comment') as HTMLButtonElement;if(!toggle)throw new Error('PARTS_WORKSPACE_NODE_REQUIRED: stage-comment');Object.assign(toggle.style,{whiteSpace:'nowrap',flex:'none'});
68
68
  const inline=!!host.listHost;
69
- const list=document.createElement('section');list.id='stage-comment-list';list.className='stage-comment-list stage-comment-ui';list.classList.toggle('stage-comment-list-inline',inline);list.setAttribute('aria-label',t(inline?'Issues':'Stage comments'));list.hidden=!inline;
69
+ const list=document.createElement('section');list.id='stage-comment-list';list.className='stage-comment-list stage-comment-ui';list.classList.toggle('stage-comment-list-inline',inline);list.setAttribute('aria-label',t('Comments'));list.hidden=!inline;
70
70
  // An absolute overlay is not stage chrome: workspace measures stack children
71
71
  // to allocate Inspector height. Keep the list in its positioned main instead,
72
72
  // anchored below the toolbar even when the bar wraps (#284).
@@ -76,7 +76,7 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
76
76
  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
77
  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
78
  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;
79
- const setCapture=(value:boolean)=>{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);};
79
+ 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
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='';};
81
81
  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
82
  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'));};
@@ -101,18 +101,24 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
101
101
  }
102
102
  }
103
103
  };
104
+ const revealLatest=()=>{
105
+ if(inline&&list.closest('.workspace-review-panel'))list.lastElementChild?.scrollIntoView({block:'nearest',behavior:'instant'});
106
+ };
104
107
  const setOpen=(value:boolean)=>{
105
108
  if(!value){cancel();list.hidden=!inline;toggle.setAttribute('aria-expanded',String(inline));setCapture(false);return;}
106
109
  if(host.busy?.()){(host.busyError??host.error)(t('COMMENT_BUSY: close the active editor or wait for the inspection to settle'));return;}
107
110
  if(host.shortcutBlocked?.()){host.error(t('COMMENT_BUSY: close the active editor or wait for the inspection to settle'));return;}
108
111
  const reason=updateRefusal();
109
112
  if(!reason&&host.blocked()){host.error(t('COMMENT_BUSY: close the active editor or wait for the inspection to settle'));return;}
110
- list.hidden=false;placeList();toggle.setAttribute('aria-expanded','true');renderList();
113
+ list.hidden=false;host.openList?.();placeList();toggle.setAttribute('aria-expanded','true');renderList();
114
+ // Explicitly opening Comments reveals the newest row within its own panel.
115
+ // Refreshes never change the reviewer's scroll position.
116
+ revealLatest();
111
117
  if(reason){setCapture(false);host.error(reason);return;}
112
- setCapture(true);for(const view of layers.keys())host.pose(view);
118
+ setCapture(layers.size>0);for(const view of layers.keys())host.pose(view);
113
119
  };
114
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());openComposer(mark.viewport,mark.screen,f,host.pose(mark.viewport)?.mode??mark.mode);}};
115
- const renderList=()=>{placeList();list.setAttribute('aria-label',t(inline?'Issues':'Stage comments'));list.replaceChildren();const title=document.createElement('strong');title.textContent=t(inline?'Issues':'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 issues 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()){
121
+ 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()){
116
122
  const mark=readMark(f),row=document.createElement('div');row.className='stage-comment-item';row.dataset.commentId=f.id;
117
123
  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);
118
124
  if(host.locked(f.id)){const submitted=document.createElement('span');submitted.textContent=t('Submitted');row.append(submitted);}
@@ -203,7 +209,10 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
203
209
  const n=rigPose.frame?.index??null;host.add({id:crypto.randomUUID(),frameStart:n,frameEnd:n,target:slots[0]?{kind:'slot',name:slots[0].slot}:{kind:'rig',name:rigPose.rig},category:'defect',summary,context:{animation:rigPose.animation,time:rigPose.time,frame:rigPose.frame?.basis==='producer'?n:null,...(turn?{turn:turn as any}:{}),interval:n===null?null:{frameStart:n,frameEnd:n,inclusive:true},comment:comment as any} } as unknown as Row,rigPose.side);
204
210
  }
205
211
  }
206
- cancel();host.changed();refresh();
212
+ busy=true;field.disabled=true;syncChips();
213
+ await host.changed();
214
+ if(disposed||generation!==interaction)return;
215
+ cancel();refresh();revealLatest();
207
216
  }catch(e){if(disposed||generation!==interaction)return;const msg=e instanceof Error?e.message:String(e);errorSource=toEn(msg);error.textContent=t(errorSource);place();if(locked)host.error(t(errorSource));field.disabled=false;field.focus();}finally{busy=false;if(composer===form)syncChips();}};
208
217
  field.focus();last='';
209
218
  };
@@ -217,10 +226,10 @@ export function bindStageComments<Row extends CommentRow=Feedback,Pose extends C
217
226
  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);
218
227
  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);});
219
228
  }
220
- const key=(e:KeyboardEvent)=>{if(host.shortcutActive&&!host.shortcutActive())return;if(e.key==='Escape'&&(pending||composer||(enabled||!inline&&!list.hidden)&&!host.shortcutBlocked?.()&&!textEntryFocused(e.target))){e.preventDefault();setOpen(false);return;}if(e.defaultPrevented||e.repeat||e.ctrlKey||e.metaKey||e.altKey||textEntryFocused(e.target)||host.shortcutBlocked?.())return;if(e.key.toLowerCase()==='c'){e.preventDefault();setOpen(inline?!enabled:list.hidden);}};
221
- window.addEventListener('blur',cancel);window.addEventListener('resize',placeList);document.addEventListener('keydown',key);toggle.onclick=()=>setOpen(inline?!enabled:list.hidden);
229
+ const key=(e:KeyboardEvent)=>{if(host.shortcutActive&&!host.shortcutActive())return;if(e.key==='Escape'&&(pending||composer||(enabled||!inline&&!list.hidden)&&!host.shortcutBlocked?.()&&!textEntryFocused(e.target))){e.preventDefault();setOpen(false);return;}if(e.defaultPrevented||e.repeat||e.ctrlKey||e.metaKey||e.altKey||textEntryFocused(e.target)||host.shortcutBlocked?.())return;if(e.key.toLowerCase()==='c'){e.preventDefault();setOpen(inline?true:list.hidden);}};
230
+ window.addEventListener('blur',cancel);window.addEventListener('resize',placeList);document.addEventListener('keydown',key);toggle.onclick=()=>setOpen(inline?true:list.hidden);
222
231
  const ro=typeof ResizeObserver==='function'?new ResizeObserver(()=>{if(!disposed&&!list.hidden)placeList();}):null;if(ro){try{ro.observe(host.toolbar);if(workspace)ro.observe(workspace);}catch{}}
223
- const renderPins=()=>{if(disposed)return;if(!list.hidden)placeList();const refusal=updateRefusal();if(refusal&&(enabled||pending||composer&&!composerReadOnly&&!composerGeneral)){cancel();setCapture(false);host.error(refusal);}const all=host.feedback().map(f=>({f,mark:readMark(f)})).filter(x=>x.mark);
232
+ const renderPins=()=>{if(disposed)return;if(enabled&&host.hasPicture?.()===false){cancel();setCapture(false);}if(!list.hidden)placeList();const refusal=updateRefusal();if(refusal&&(enabled||pending||composer&&!composerReadOnly&&!composerGeneral)){cancel();setCapture(false);host.error(refusal);}const all=host.feedback().map(f=>({f,mark:readMark(f)})).filter(x=>x.mark);
224
233
  // #356: a pose reads the pane's size (a forced layout after the played frame's writes); with no mark, draft or pending
225
234
  // capture there is nothing to place, so this per-frame loop skips it.
226
235
  const poses=new Map(all.length||draftMark||pending?[...layers.keys()].map(view=>[view,host.pose(view)]):[]);