// Run from repository root after capture-solver-library.cjs. Never changes rendered UI. const sharp=require('sharp'),fs=require('node:fs'),path=require('node:path'),crypto=require('node:crypto'); const masters=process.argv[2];if(!masters)throw Error('Pass the internal master directory'); const root='PlotLine/Content/WritingSolver/Presentation',file=root+'/results-v1.json',catalog=JSON.parse(fs.readFileSync(file)); const captures=JSON.parse(fs.readFileSync(path.join(masters,'captures.json'))); const descriptions={ 'plot-lines-weave':'PlotDirector Plot Lines workspace showing two narrative threads meeting at shared scenes.', 'timeline-chronology':'PlotDirector Timeline comparing scene dates, locations and events in manuscript order.', 'timeline-scene-overview':'PlotDirector Timeline organising chapters and scene summaries with characters and viewpoints.', 'character-records':'PlotDirector Characters bringing six cast records together for consistent reference.', 'relationship-map':'PlotDirector Relationship Map showing six characters, their connections and relationship details.', 'character-knowledge':'PlotDirector knowledge timeline showing Mara moving from suspicion to confirmed knowledge across scenes.', 'character-arc':'PlotDirector character arc comparing emotional weight, tension and intensity across Mara’s scenes.', 'location-reference':'PlotDirector Locations organising a harbour, pier, archive and beacon in a nested hierarchy.', 'object-journey':'PlotDirector object journey following the sealed letter between recorded locations across scenes.', 'timeline-story-values':'PlotDirector Timeline graph comparing recorded tension, emotional weight, intensity and action.', 'scenario-alternatives':'PlotDirector Scenarios showing three named alternative arrangements kept separate from the main manuscript.', 'continuity-story-state':'PlotDirector Continuity Explorer showing recorded character and object locations at a story position.', 'series-project':'PlotDirector series dashboard showing three ordered books and shared story records.', 'story-bible':'PlotDirector Story Bible linking searchable character records to their scenes, viewpoints and knowledge notes.'}; (async()=>{const selection=process.env.CAPTURE_ASSETS?.split(',');const assets=selection?JSON.parse(fs.readFileSync(root+'/screenshot-assets-v1.json')).assets.filter(a=>!selection.includes(a.asset)):[];const out='PlotLine/wwwroot/images/writing-solver';fs.mkdirSync(out,{recursive:true}); for(const capture of captures){if(selection&&!selection.includes(capture.asset))continue;const key=capture.asset,source=path.join(masters,key+'.png'),metadata=await sharp(source).metadata();if(![1280,1440].includes(metadata.width))throw Error('Unexpected master width');const variants=[]; for(const width of [640,960,1280])for(const format of ['avif','webp']){const name=key+(width===1280?'':'-'+width)+'.'+format;let image=sharp(source).resize({width});image=format==='avif'?image.avif({quality:68,chromaSubsampling:'4:4:4',effort:6}):image.webp({quality:91,effort:6,smartSubsample:true});await image.toFile(path.join(out,name));variants.push({file:name,width,bytes:fs.statSync(path.join(out,name)).size});} const caps=catalog.capabilities.filter(c=>c.asset===key+'.webp');const ids=caps.map(c=>c.id);const diagnoses=catalog.results.filter(r=>ids.includes(r.capability)).map(r=>r.solution);const alt=descriptions[key];if(!alt)throw Error('Missing editorial alt text'); for(const c of caps){c.image='/images/writing-solver/'+key+'.webp';c.imageAlt=alt;c.imageWidth=1280;c.imageHeight=Math.round(metadata.height*1280/metadata.width);} assets.push({...capture,sourceWidth:metadata.width,sourceHeight:metadata.height,width:1280,height:Math.round(metadata.height*1280/metadata.width),sourceViews:[...new Set(caps.map(c=>c.captureView))],capabilities:ids,diagnoses,alt,aspect:`1280:${Math.round(metadata.height*1280/metadata.width)}`,masterSha256:crypto.createHash('sha256').update(fs.readFileSync(source)).digest('hex'),variants});console.log(key,variants.map(v=>v.bytes).join(','));} if(assets.length!==14||catalog.capabilities.some(c=>!c.image))throw Error('Incomplete library');fs.writeFileSync(file,JSON.stringify(catalog,null,2)+'\n');fs.writeFileSync(root+'/screenshot-assets-v1.json',JSON.stringify({version:1,capturedOn:'2026-11-02',source:'https://dev.plotdirector.com',theme:'plotdirector',assets},null,2)+'\n');})();