@rig-c/review 1.9.0 → 1.10.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/web/stage-nav.ts CHANGED
@@ -3,20 +3,33 @@ import {getLanguage,onLanguageChange,t} from './i18n.ts';
3
3
  import {pageInstanceAccess} from './instance-access.ts';
4
4
  export const reviewStages = ['1 Parts + mesh','2 Interview','3 Rig + animation','4 Direction'] as const;
5
5
  export type ReviewStage = 1|2|3|4;
6
+ export interface StagePartsState {
7
+ inspectionSourceHash:string;part:string;imageHash:string;box:{x:number;y:number;w:number;h:number};mapping:{skin:string;slot:string;attachment:string};
8
+ rig:{zoom:number;center:{x:number;y:number}|null};reference:{zoom:number;center:{x:number;y:number}|null};cameraSync:boolean;
9
+ bg:string;alpha:boolean;footprints:boolean;view:'item'|'page'|'assembled';mesh:boolean;
10
+ }
11
+ export interface StagePartsWindow extends Window {rigReviewStageParts?:{snapshot:()=>StagePartsState|null}}
12
+ /** Navigation state transfers only over exact original-art/package identity and the same draft address. */
13
+ export function stagePartsSelectionIndex(data:{inspectionSourceHash?:string;items:{name:string;imageHash?:string;x:number;y:number;w:number;h:number}[];draft?:{mappings:{part:string;skin:string;slot:string;attachment:string}[]}},saved:StagePartsState):number {
14
+ const i=data.items.findIndex(item=>item.name===saved.part&&item.imageHash===saved.imageHash&&(['x','y','w','h']as const).every(k=>item[k]===saved.box[k]));
15
+ const m=data.draft?.mappings.find(m=>m.part===saved.part);
16
+ if(i<0||data.inspectionSourceHash!==saved.inspectionSourceHash||!m||(['skin','slot','attachment']as const).some(k=>m[k]!==saved.mapping[k]))throw new Error('STAGE_DRAFT_MISMATCH');
17
+ return i;
18
+ }
6
19
  export function stageReason(stage:ReviewStage,model:boolean):string|null {
7
20
  if(stage===2)return 'INTERVIEW_UNAVAILABLE: no interview consumer contract is installed.';
8
21
  if(stage===4)return 'DIRECTION_UNAVAILABLE: no direction inspection contract is installed.';
9
22
  if(stage===3&&!model)return 'MODEL_UNAVAILABLE: no compiled model is supplied in this inspection.';
10
23
  return null;
11
24
  }
12
- export function bindStageNav(options:{partsOnly?:boolean;model:boolean;side?:()=> 'a'|'b';setup?:()=>void}):()=>void {
25
+ export function bindStageNav(options:{partsOnly?:boolean;model:boolean;side?:()=> 'a'|'b';setup?:()=>void;draftBuild?:()=>string;correction?:(request:{part:string;sourceHash:string;buildId:string;instrument:string})=>Promise<void>}):()=>void {
13
26
  const host=document.querySelector<HTMLElement>('[data-stage-nav]');if(!host)return ()=>{};
14
27
  const embedded=new URL(location.href).searchParams.get('stageEmbed')==='1';
15
28
  if(embedded){host.hidden=true;return ()=>{};}
16
29
  const access=pageInstanceAccess(),panel=document.createElement('section');panel.className='review-stage-panel';panel.hidden=true;panel.setAttribute('aria-live','polite');document.body.append(panel);
17
30
  const status=document.createElement('p');status.setAttribute('role','status');panel.append(status);
18
31
  const sourcePicker=document.getElementById('mode-build-picker');
19
- const frames=new Map<string,HTMLIFrameElement>();let current:ReviewStage=options.partsOnly?1:3;
32
+ const frames=new Map<string,HTMLIFrameElement>();let lastFrame:HTMLIFrameElement|null=null;let current:ReviewStage=options.partsOnly?1:3;
20
33
  const workspace=document.querySelector<HTMLElement>(options.partsOnly?'.pv-layout':'.layout');const wasInert=workspace?.inert??false;
21
34
  const buttons=reviewStages.map((label,index)=>{const button=document.createElement('button');button.type='button';button.dataset.reviewStage=String(index+1);button.onclick=()=>show(index+1 as ReviewStage);host.append(button);return button;});
22
35
  const mesh=document.createElement('button');mesh.type='button';mesh.onclick=()=>{show(3);options.setup?.();};panel.append(mesh);
@@ -26,10 +39,12 @@ export function bindStageNav(options:{partsOnly?:boolean;model:boolean;side?:()=
26
39
  current=stage;document.documentElement.dataset.inspectionStage=String(stage);render();place();const reason=stageReason(stage,options.model);
27
40
  panel.hidden=stage===(options.partsOnly?1:3)&&!reason;
28
41
  if(workspace)workspace.inert=!panel.hidden||wasInert;
29
- status.textContent=reason?t(reason):stage===1&&!options.partsOnly?t('Atlas inspection, read only — inspected package. Applied scratch atlas, pre-rig parts, mesh sign-off and draft corrections are unavailable here.'):'';mesh.hidden=stage!==1||!options.model||!!options.partsOnly;
42
+ status.textContent=reason?t(reason):stage===1&&!options.partsOnly?t(options.correction?'Draft rig · structure evidence only':'Atlas inspection, read only — inspected package. Applied scratch atlas, pre-rig parts, mesh sign-off and draft corrections are unavailable here.'):'';mesh.hidden=stage!==1||!options.model||!!options.partsOnly;
30
43
  for(const frame of frames.values())frame.hidden=true;
31
- if(stage===1&&!options.partsOnly){const side=options.side?.(),key=side??'single';let frame=frames.get(key);if(!frame){frame=document.createElement('iframe');frame.title=t('Parts and atlas inspection');frame.src=access.route('/stage-parts.html')+'?stageEmbed=1&lang='+getLanguage()+(side?'&side='+side:'');frame.addEventListener('load',()=>frame!.contentWindow?.postMessage({type:'review-stage-language',language:getLanguage()},location.origin));frames.set(key,frame);panel.append(frame);}frame.hidden=false;}
44
+ if(stage===1&&!options.partsOnly){const saved=(lastFrame?.contentWindow as StagePartsWindow|null)?.rigReviewStageParts?.snapshot()??null;const side=options.side?.(),key=(side??'single')+':'+(options.draftBuild?.()??'inspected');let frame=frames.get(key);if(!frame){if(options.correction){for(const old of frames.values())old.remove();frames.clear();}frame=document.createElement('iframe');frame.title=t('Parts and atlas inspection');frame.src=access.route('/stage-parts.html')+'?stageEmbed=1&lang='+getLanguage()+(side?'&side='+side:'');frame.addEventListener('load',()=>{frame!.contentWindow?.postMessage({type:'review-stage-language',language:getLanguage()},location.origin);frame!.contentWindow?.postMessage({type:'review-stage-source',buildId:options.draftBuild?.()??'inspected',state:saved},location.origin);});frames.set(key,frame);panel.append(frame);}else if(options.correction){frame.contentWindow?.postMessage({type:'review-stage-revalidate',state:lastFrame!==frame?saved:null},location.origin);}frame.hidden=false;lastFrame=frame;}
32
45
  }
46
+ const correction=async(event:MessageEvent)=>{if(event.origin!==location.origin||![...frames.values()].some(f=>f.contentWindow===event.source)||event.data?.type!=='review-stage-correction'||!options.correction)return;const r=event.data;if(typeof r.part!=='string'||typeof r.sourceHash!=='string'||typeof r.buildId!=='string'||!['chest','mesh','delta'].includes(r.instrument))return;try{await options.correction(r);show(3);}catch(error){status.textContent=error instanceof Error?error.message:String(error);}};
47
+ window.addEventListener('message',correction);
33
48
  // Legacy Setup/Animate/Compare selectors keep their IDs, payloads and behavior.
34
49
  const legacy=()=>show(3);document.querySelectorAll('[data-mode],[data-inspector]').forEach(b=>b.addEventListener('click',legacy));
35
50
  // A side choice reuses the canonical closed A/B picker, then reveals that side's retained atlas.
@@ -39,7 +54,7 @@ export function bindStageNav(options:{partsOnly?:boolean;model:boolean;side?:()=
39
54
  // Legacy bookmark/control restoration writes these canonical attributes even when a mode is unchanged.
40
55
  const canonical=new MutationObserver(()=>{if(current!==3&&!options.partsOnly&&!pickingSource)show(3);});
41
56
  document.querySelectorAll('[data-inspector]').forEach(button=>canonical.observe(button,{attributes:true,attributeFilter:['aria-selected','aria-pressed']}));
42
- const language=onLanguageChange(()=>{render();if(!panel.hidden)status.textContent=t(stageReason(current,options.model)??(current===1?'Atlas inspection, read only — inspected package. Applied scratch atlas, pre-rig parts, mesh sign-off and draft corrections are unavailable here.':''));for(const f of frames.values()){f.title=t('Parts and atlas inspection');f.contentWindow?.postMessage({type:'review-stage-language',language:getLanguage()},location.origin);}});
57
+ const language=onLanguageChange(()=>{render();if(!panel.hidden)status.textContent=t(stageReason(current,options.model)??(current===1&&options.correction?'Draft rig · structure evidence only':current===1?'Atlas inspection, read only — inspected package. Applied scratch atlas, pre-rig parts, mesh sign-off and draft corrections are unavailable here.':''));for(const f of frames.values()){f.title=t('Parts and atlas inspection');f.contentWindow?.postMessage({type:'review-stage-language',language:getLanguage()},location.origin);}});
43
58
  window.addEventListener('resize',place);show(current);
44
- return ()=>{language();canonical.disconnect();sourcePicker?.querySelectorAll('[data-build-side]').forEach(button=>button.removeEventListener('click',sourceChanged));delete document.documentElement.dataset.inspectionStage;if(workspace)workspace.inert=wasInert;panel.remove();window.removeEventListener('resize',place);document.querySelectorAll('[data-mode],[data-inspector]').forEach(b=>b.removeEventListener('click',legacy));};
59
+ return ()=>{window.removeEventListener('message',correction);language();canonical.disconnect();sourcePicker?.querySelectorAll('[data-build-side]').forEach(button=>button.removeEventListener('click',sourceChanged));delete document.documentElement.dataset.inspectionStage;if(workspace)workspace.inert=wasInert;panel.remove();window.removeEventListener('resize',place);document.querySelectorAll('[data-mode],[data-inspector]').forEach(b=>b.removeEventListener('click',legacy));};
45
60
  }