@@ -12,83 +12,116 @@ import path from "node:path";
1212import { fileURLToPath } from "node:url" ;
1313
1414const HERE = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
15- const OUTPUT = path . resolve (
16- HERE ,
17- "../../src/shared/ui/assets/card-texture.png" ,
18- ) ;
19-
20- // CSS-pixel source geometry. Screenshotting at DPR 2 produces a crisp asset.
21- const CARD_SIZE = 640 ;
22- const OUTSET = 96 ;
23- const CAPTURE_SIZE = CARD_SIZE + OUTSET * 2 ;
15+ const OUTPUT_DIRECTORY = path . resolve ( HERE , "../../src/shared/ui/assets" ) ;
2416const DPR = 2 ;
2517
2618// Approved texture parameters, archived from the former runtime SVG filter.
27- const BLUR = 66 ;
28- const DILATE = Math . round ( BLUR * 0.85 ) ;
2919const THRESHOLD_BIAS = 0.302 ;
3020const SLOPE = 8 ;
3121const FREQUENCY = 0.999 ;
3222const OCTAVES = 3 ;
3323const SEED = 5315 ;
3424
35- await mkdir ( path . dirname ( OUTPUT ) , { recursive : true } ) ;
25+ const TEXTURES = [
26+ {
27+ filename : "card-texture.png" ,
28+ color : "white" ,
29+ cardSize : 640 ,
30+ outset : 96 ,
31+ blur : 66 ,
32+ innerBand : 112 ,
33+ } ,
34+ {
35+ filename : "card-texture-dark.png" ,
36+ color : "#171b21" ,
37+ cardSize : 640 ,
38+ outset : 96 ,
39+ blur : 66 ,
40+ innerBand : 112 ,
41+ } ,
42+ {
43+ filename : "card-texture-compact.png" ,
44+ color : "white" ,
45+ cardSize : 320 ,
46+ outset : 24 ,
47+ blur : 24 ,
48+ innerBand : 44 ,
49+ } ,
50+ {
51+ filename : "card-texture-dark-compact.png" ,
52+ color : "#171b21" ,
53+ cardSize : 320 ,
54+ outset : 24 ,
55+ blur : 24 ,
56+ innerBand : 44 ,
57+ } ,
58+ ] ;
59+
60+ await mkdir ( OUTPUT_DIRECTORY , { recursive : true } ) ;
3661
3762const browser = await chromium . launch ( ) ;
3863try {
39- const page = await browser . newPage ( {
40- deviceScaleFactor : DPR ,
41- viewport : { height : CAPTURE_SIZE , width : CAPTURE_SIZE } ,
42- } ) ;
64+ for ( const texture of TEXTURES ) {
65+ const captureSize = texture . cardSize + texture . outset * 2 ;
66+ const dilate = Math . round ( texture . blur * 0.85 ) ;
67+ const output = path . join ( OUTPUT_DIRECTORY , texture . filename ) ;
68+ const page = await browser . newPage ( {
69+ deviceScaleFactor : DPR ,
70+ viewport : { height : captureSize , width : captureSize } ,
71+ } ) ;
4372
44- await page . setContent ( `<!doctype html>
45- <style>
46- html, body { margin: 0; width: 100%; height: 100%; background: transparent; }
47- #stage { position: relative; width: ${ CAPTURE_SIZE } px; height: ${ CAPTURE_SIZE } px; }
48- #core {
49- position: absolute;
50- inset: ${ OUTSET + BLUR / 2 } px;
51- background: white ;
52- filter: blur(${ BLUR / 3 } px);
53- }
54- </style>
55- <div id="stage">
56- <svg width="${ CAPTURE_SIZE } " height="${ CAPTURE_SIZE } " aria-hidden="true">
57- <defs>
58- <filter id="texture" x="0" y="0" width="100%" height="100%"
59- filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
60- <feMorphology in="SourceAlpha" operator="dilate" radius="${ DILATE } " result="squared" />
61- <feGaussianBlur in="squared" stdDeviation="${ BLUR } " result="ramp" />
62- <feTurbulence type="fractalNoise" baseFrequency="${ FREQUENCY } "
63- numOctaves="${ OCTAVES } " seed="${ SEED } " result="grain" />
64- <feColorMatrix in="grain" result="grainAlpha" type="matrix"
65- values="0 0 0 0 0
66- 0 0 0 0 0
67- 0 0 0 0 0
68- 1 0 0 0 0" />
69- <feComposite in="ramp" in2="grainAlpha" operator="arithmetic"
70- k1="0" k2="1" k3="-1" k4="${ - THRESHOLD_BIAS } " result="dithered" />
71- <feComponentTransfer in="dithered" result="specks">
72- <feFuncA type="linear" slope="${ SLOPE } " intercept="0" />
73- </feComponentTransfer>
74- <feFlood flood-color="white " result="white " />
75- <feComposite in="white " in2="specks" operator="in" />
76- </filter>
77- </defs>
78- <rect x="${ OUTSET } " y="${ OUTSET } " width="${ CARD_SIZE } " height="${ CARD_SIZE } "
79- fill="white " filter="url(#texture)" />
80- </svg>
81- <span id="core"></span>
82- </div>` ) ;
73+ await page . setContent ( `<!doctype html>
74+ <style>
75+ html, body { margin: 0; width: 100%; height: 100%; background: transparent; }
76+ #stage { position: relative; width: ${ captureSize } px; height: ${ captureSize } px; }
77+ #core {
78+ position: absolute;
79+ inset: ${ texture . outset + texture . blur / 2 } px;
80+ background: ${ texture . color } ;
81+ filter: blur(${ texture . blur / 3 } px);
82+ }
83+ </style>
84+ <div id="stage">
85+ <svg width="${ captureSize } " height="${ captureSize } " aria-hidden="true">
86+ <defs>
87+ <filter id="texture" x="0" y="0" width="100%" height="100%"
88+ filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
89+ <feMorphology in="SourceAlpha" operator="dilate" radius="${ dilate } " result="squared" />
90+ <feGaussianBlur in="squared" stdDeviation="${ texture . blur } " result="ramp" />
91+ <feTurbulence type="fractalNoise" baseFrequency="${ FREQUENCY } "
92+ numOctaves="${ OCTAVES } " seed="${ SEED } " result="grain" />
93+ <feColorMatrix in="grain" result="grainAlpha" type="matrix"
94+ values="0 0 0 0 0
95+ 0 0 0 0 0
96+ 0 0 0 0 0
97+ 1 0 0 0 0" />
98+ <feComposite in="ramp" in2="grainAlpha" operator="arithmetic"
99+ k1="0" k2="1" k3="-1" k4="${ - THRESHOLD_BIAS } " result="dithered" />
100+ <feComponentTransfer in="dithered" result="specks">
101+ <feFuncA type="linear" slope="${ SLOPE } " intercept="0" />
102+ </feComponentTransfer>
103+ <feFlood flood-color="${ texture . color } " result="surfaceColor " />
104+ <feComposite in="surfaceColor " in2="specks" operator="in" />
105+ </filter>
106+ </defs>
107+ <rect x="${ texture . outset } " y="${ texture . outset } " width="${ texture . cardSize } " height="${ texture . cardSize } "
108+ fill="${ texture . color } " filter="url(#texture)" />
109+ </svg>
110+ <span id="core"></span>
111+ </div>` ) ;
83112
84- await page . locator ( "#stage" ) . screenshot ( {
85- omitBackground : true ,
86- path : OUTPUT ,
87- } ) ;
113+ await page . locator ( "#stage" ) . screenshot ( {
114+ omitBackground : true ,
115+ path : output ,
116+ } ) ;
117+ await page . close ( ) ;
118+
119+ console . log ( `Generated ${ output } ` ) ;
120+ console . log ( `Asset: ${ captureSize * DPR } ×${ captureSize * DPR } px @${ DPR } x` ) ;
121+ console . log (
122+ `Runtime slice: ${ ( texture . outset + texture . innerBand ) * DPR } px; outset: ${ texture . outset } px` ,
123+ ) ;
124+ }
88125} finally {
89126 await browser . close ( ) ;
90127}
91-
92- console . log ( `Generated ${ OUTPUT } ` ) ;
93- console . log ( `Asset: ${ CAPTURE_SIZE * DPR } ×${ CAPTURE_SIZE * DPR } px @${ DPR } x` ) ;
94- console . log ( `Runtime slice: ${ ( OUTSET + 112 ) * DPR } px; outset: ${ OUTSET } px` ) ;
0 commit comments