File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,9 +2,44 @@ import { getBoundariesFromPattern } from './functions'
22import { State } from './types'
33
44export const Preview : React . FC < { state : State } > = ( { state } ) => {
5+ const viewBox = ( ( ) => {
6+ let xMin = 0
7+ let xMax = 1
8+ let yMin = 0
9+ let yMax = 1
10+
11+ // Make sure that default viewBox contains entire pattern
12+ for ( const p of state . patterns ) {
13+ const b = getBoundariesFromPattern ( p )
14+
15+ xMin = Math . min ( xMin , b . xMin )
16+ xMax = Math . max ( xMax , b . xMax )
17+ yMin = Math . min ( yMin , b . yMin )
18+ yMax = Math . max ( yMax , b . yMax )
19+ }
20+
21+ // Add some spacing around the bounding box
22+ xMin -= 0.1
23+ xMax += 0.1
24+ yMin -= 0.1
25+ yMax += 0.1
26+
27+ return `${ xMin } ${ yMin } ${ xMax - xMin } ${ yMax - yMin } `
28+ } ) ( )
29+
530 return (
631 < div className = 'border-1 border-amber-300 aspect-square' >
7- < svg viewBox = '0 0 1 1' xmlns = 'http://www.w3.org/2000/svg' className = 'w-full aspect-square' >
32+ < svg viewBox = { viewBox } xmlns = 'http://www.w3.org/2000/svg' className = 'w-full aspect-square' >
33+ < rect
34+ className = 'stroke-amber-100'
35+ vectorEffect = 'non-scaling-stroke'
36+ fill = 'none'
37+ strokeWidth = '1px'
38+ x = { 0 }
39+ y = { 0 }
40+ width = { 1 }
41+ height = { 1 }
42+ />
843 { state . patterns . map ( ( p , i ) => {
944 const { xMin, xMax, yMin, yMax } = getBoundariesFromPattern ( p )
1045
You can’t perform that action at this time.
0 commit comments