okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0b3299a01
main
1/* Local screenshot fixture only. Export controls sit outside the captured app. */ 2( async () => { 3await document . fonts . ready ; 4const button = document . createElement ( 'button' ); 5button . textContent = 'Export full-quality PNG' ; 6button . style . cssText = 'position:absolute;right:16px;top:16px;z-index:2147483647;padding:12px 18px;border:1px solid #047857;border-radius:12px;background:white;color:#171717;font:600 14px system-ui;cursor:pointer' ; 7button . dataset . fixtureCapture = 'true' ; 8const placeButton = () => { const modal = document . querySelector ( '.setupmodal__surface' ); if ( modal && button . parentElement !== modal ){ modal . append ( button ); button . inert = false ;}}; 9document . body . append ( button ); placeButton (); 10new MutationObserver ( placeButton ). observe ( document . getElementById ( 'root' ),{ childList :true , subtree :true }); 11button . addEventListener ( 'click' , async () => { 12button . disabled = true ; button . textContent = 'Rendering full-quality PNG…' ; 13const frozen = document . createElement ( 'style' ); 14frozen . textContent = '#root *,#root *::before,#root *::after{animation-play-state:paused!important;transition:none!important}' ; 15document . head . append ( frozen ); 16const restoredIcons = []; 17try { 18await document . fonts . ready ; 19// SVG foreignObject exports cannot resolve external <use> references. 20// Embed the app's original vector paths, retaining the same viewBox and fill. 21const spriteText = await ( await fetch ( '/icons/sprite.svg' )). text (); 22const sprite = new DOMParser (). parseFromString ( spriteText , 'image/svg+xml' ); 23for ( const use of document . querySelectorAll ( '#root .st-icon use' )){ 24const symbol = sprite . getElementById ( use . getAttribute ( 'href' ). split ( '#' )[ 1 ]); 25if ( ! symbol ) throw new Error ( 'An app icon could not be embedded' ); 26const svg = use . closest ( 'svg' ), viewBox = svg . getAttribute ( 'viewBox' ), transform = svg . style . transform ; 27// Keep transforms from selectors that refer to the original <use>. 28svg . style . transform = getComputedStyle ( svg ). transform ; 29const group = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'g' ); 30group . setAttribute ( 'fill' , symbol . getAttribute ( 'fill' ) ?? 'none' ); 31for ( const child of symbol . children ) group . append ( document . importNode ( child , true )); 32svg . setAttribute ( 'viewBox' , symbol . getAttribute ( 'viewBox' )); use . replaceWith ( group ); 33restoredIcons . push ({ svg, viewBox, transform, use, group}); 34} 35const width = innerWidth , height = innerHeight , scale = 4 ; 36const dataUrl = await htmlToImage . toPng ( document . getElementById ( 'root' ),{ 37 width, height, pixelRatio :scale , skipAutoScale :true , preferredFontFormat :'woff2' , 38backgroundColor :getComputedStyle ( document . body ). backgroundColor , 39filter :node => node . dataset ?. fixtureCapture !== 'true' , 40}); 41const response = await fetch ( '/__fixture/capture' ,{ method :'POST' , headers :{ 'content-type' :'application/json' }, body :JSON . stringify ({ dataUrl, width :width * scale , height :height * scale })}); 42const result = await response . json (); if ( ! response . ok ) throw new Error ( result . error ); 43button . textContent = `PNG saved · ${ result . width } × ${ result . height } ` ; 44} catch ( error ){ button . textContent = `Export failed: ${ error . message } ` ;} 45finally { 46for ( const { svg, viewBox, transform, use, group} of restoredIcons ){ group . replaceWith ( use ); svg . style . transform = transform ; if ( viewBox === null ) svg . removeAttribute ( 'viewBox' ); else svg . setAttribute ( 'viewBox' , viewBox );} 47button . disabled = false ; frozen . remove (); 48} 49}); 50})();