@@ -12,81 +12,79 @@ import {
1212} from './utils' ;
1313import { useQRCode } from './hooks/useQRCode' ;
1414
15- const QRCodeSVG = React . forwardRef < SVGSVGElement , QRPropsSVG > (
16- function QRCodeSVG ( props , forwardedRef ) {
17- const {
18- value,
19- size = DEFAULT_SIZE ,
20- level = DEFAULT_LEVEL ,
21- bgColor = DEFAULT_BACKGROUND_COLOR ,
22- fgColor = DEFAULT_FRONT_COLOR ,
23- includeMargin = DEFAULT_NEED_MARGIN ,
24- minVersion = DEFAULT_MINVERSION ,
25- title,
26- marginSize,
27- imageSettings,
28- ...otherProps
29- } = props ;
15+ const QRCodeSVG = React . forwardRef < SVGSVGElement , QRPropsSVG > ( ( props , ref ) => {
16+ const {
17+ value,
18+ size = DEFAULT_SIZE ,
19+ level = DEFAULT_LEVEL ,
20+ bgColor = DEFAULT_BACKGROUND_COLOR ,
21+ fgColor = DEFAULT_FRONT_COLOR ,
22+ includeMargin = DEFAULT_NEED_MARGIN ,
23+ minVersion = DEFAULT_MINVERSION ,
24+ title,
25+ marginSize,
26+ imageSettings,
27+ ...otherProps
28+ } = props ;
3029
31- const { margin, cells, numCells, calculatedImageSettings } = useQRCode ( {
32- value,
33- level,
34- minVersion,
35- includeMargin,
36- marginSize,
37- imageSettings,
38- size,
39- } ) ;
30+ const { margin, cells, numCells, calculatedImageSettings } = useQRCode ( {
31+ value,
32+ level,
33+ minVersion,
34+ includeMargin,
35+ marginSize,
36+ imageSettings,
37+ size,
38+ } ) ;
4039
41- let cellsToDraw = cells ;
42- let image = null ;
43- if ( imageSettings != null && calculatedImageSettings != null ) {
44- if ( calculatedImageSettings . excavation != null ) {
45- cellsToDraw = excavateModules (
46- cells ,
47- calculatedImageSettings . excavation ,
48- ) ;
49- }
50-
51- image = (
52- < image
53- href = { imageSettings . src }
54- height = { calculatedImageSettings . h }
55- width = { calculatedImageSettings . w }
56- x = { calculatedImageSettings . x + margin }
57- y = { calculatedImageSettings . y + margin }
58- preserveAspectRatio = "none"
59- opacity = { calculatedImageSettings . opacity }
60- // when crossOrigin is not set, the image will be tainted
61- // and the canvas cannot be exported to an image
62- crossOrigin = { calculatedImageSettings . crossOrigin }
63- />
64- ) ;
40+ let cellsToDraw = cells ;
41+ let image = null ;
42+ if ( imageSettings != null && calculatedImageSettings != null ) {
43+ if ( calculatedImageSettings . excavation != null ) {
44+ cellsToDraw = excavateModules ( cells , calculatedImageSettings . excavation ) ;
6545 }
6646
67- const fgPath = generatePath ( cellsToDraw , margin ) ;
68-
69- return (
70- < svg
71- height = { size }
72- width = { size }
73- viewBox = { `0 0 ${ numCells } ${ numCells } ` }
74- ref = { forwardedRef }
75- role = "img"
76- { ...otherProps }
77- >
78- { ! ! title && < title > { title } </ title > }
79- < path
80- fill = { bgColor }
81- d = { `M0,0 h${ numCells } v${ numCells } H0z` }
82- shapeRendering = "crispEdges"
83- />
84- < path fill = { fgColor } d = { fgPath } shapeRendering = "crispEdges" />
85- { image }
86- </ svg >
47+ image = (
48+ < image
49+ href = { imageSettings . src }
50+ height = { calculatedImageSettings . h }
51+ width = { calculatedImageSettings . w }
52+ x = { calculatedImageSettings . x + margin }
53+ y = { calculatedImageSettings . y + margin }
54+ preserveAspectRatio = "none"
55+ opacity = { calculatedImageSettings . opacity }
56+ // when crossOrigin is not set, the image will be tainted
57+ // and the canvas cannot be exported to an image
58+ crossOrigin = { calculatedImageSettings . crossOrigin }
59+ />
8760 ) ;
88- } ,
89- ) ;
90- QRCodeSVG . displayName = 'QRCodeSVG' ;
61+ }
62+
63+ const fgPath = generatePath ( cellsToDraw , margin ) ;
64+
65+ return (
66+ < svg
67+ height = { size }
68+ width = { size }
69+ viewBox = { `0 0 ${ numCells } ${ numCells } ` }
70+ ref = { ref }
71+ role = "img"
72+ { ...otherProps }
73+ >
74+ { ! ! title && < title > { title } </ title > }
75+ < path
76+ fill = { bgColor }
77+ d = { `M0,0 h${ numCells } v${ numCells } H0z` }
78+ shapeRendering = "crispEdges"
79+ />
80+ < path fill = { fgColor } d = { fgPath } shapeRendering = "crispEdges" />
81+ { image }
82+ </ svg >
83+ ) ;
84+ } ) ;
85+
86+ if ( process . env . NODE_ENV !== 'production' ) {
87+ QRCodeSVG . displayName = 'QRCodeSVG' ;
88+ }
9189
9290export { QRCodeSVG } ;
0 commit comments