@@ -12,6 +12,7 @@ import invariant from "tiny-invariant"
12
12
import { useCamera } from "../gestures/useCamera"
13
13
import { useWheelEnabler } from "../gestures/useWheelEnabler"
14
14
import { TestContext } from "../context/TestContext"
15
+ import { Debug } from "../debug"
15
16
16
17
export type MafsProps = React . PropsWithChildren < {
17
18
width ?: number | "auto"
@@ -49,6 +50,9 @@ export type MafsProps = React.PropsWithChildren<{
49
50
* this prop is now ignored.
50
51
*/
51
52
ssr ?: boolean
53
+
54
+ /** Take a peek outside the viewbox to make sure things are rendering properly. */
55
+ debug ?: boolean
52
56
} >
53
57
54
58
export function Mafs ( {
@@ -60,6 +64,7 @@ export function Mafs({
60
64
preserveAspectRatio = "contain" ,
61
65
children,
62
66
ssr = false ,
67
+ debug = false ,
63
68
onClick = undefined ,
64
69
} : MafsProps ) {
65
70
const testContext = React . useContext ( TestContext )
@@ -92,6 +97,7 @@ export function Mafs({
92
97
preserveAspectRatio = { preserveAspectRatio }
93
98
ssr = { ssr }
94
99
onClick = { onClick }
100
+ debug = { debug }
95
101
>
96
102
{ children }
97
103
</ MafsCanvas >
@@ -105,7 +111,9 @@ type MafsCanvasProps = {
105
111
height : number
106
112
desiredCssWidth : string
107
113
rootRef : React . RefObject < HTMLDivElement >
108
- } & Required < Pick < MafsProps , "pan" | "zoom" | "viewBox" | "preserveAspectRatio" | "ssr" > > &
114
+ } & Required <
115
+ Pick < MafsProps , "pan" | "zoom" | "viewBox" | "preserveAspectRatio" | "ssr" | "debug" >
116
+ > &
109
117
Pick < MafsProps , "children" | "onClick" >
110
118
111
119
function MafsCanvas ( {
@@ -119,6 +127,7 @@ function MafsCanvas({
119
127
preserveAspectRatio,
120
128
children,
121
129
onClick,
130
+ debug,
122
131
} : MafsCanvasProps ) {
123
132
let minZoom = 1
124
133
let maxZoom = 1
@@ -306,7 +315,12 @@ function MafsCanvas({
306
315
< svg
307
316
width = { width }
308
317
height = { height }
309
- viewBox = { `${ viewBoxX } ${ viewBoxY } ${ width } ${ height } ` }
318
+ viewBox = { [
319
+ viewBoxX - ( debug ? 150 : 0 ) ,
320
+ viewBoxY - ( debug ? 150 : 0 ) ,
321
+ width + ( debug ? 300 : 0 ) ,
322
+ height + ( debug ? 300 : 0 ) ,
323
+ ] . join ( " " ) }
310
324
preserveAspectRatio = "xMidYMin"
311
325
style = { {
312
326
width : desiredCssWidth ,
@@ -318,6 +332,18 @@ function MafsCanvas({
318
332
} }
319
333
>
320
334
{ children }
335
+ { debug && (
336
+ < rect
337
+ x = { viewBoxX }
338
+ y = { viewBoxY }
339
+ width = { width }
340
+ height = { height }
341
+ fill = "none"
342
+ stroke = "red"
343
+ style = { { outline : "9999px solid #f002" } }
344
+ />
345
+ ) }
346
+ { debug && < Debug . ViewportInfo /> }
321
347
</ svg >
322
348
</ PaneManager >
323
349
</ TransformContext . Provider >
0 commit comments