1 |
- {"ast":null,"code":"import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport _objectWithoutProperties from \"@babel/runtime/helpers/esm/objectWithoutProperties\";\nvar _excluded = [\"value\", \"size\", \"level\", \"bgColor\", \"fgColor\", \"includeMargin\", \"minVersion\", \"marginSize\", \"style\", \"imageSettings\"];\nimport React from 'react';\nimport { useQRCode } from \"./hooks/useQRCode\";\nimport { DEFAULT_BACKGROUND_COLOR, DEFAULT_FRONT_COLOR, DEFAULT_NEED_MARGIN, DEFAULT_LEVEL, DEFAULT_MINVERSION, DEFAULT_SIZE, isSupportPath2d, excavateModules, generatePath } from \"./utils\";\nvar QRCodeCanvas = /*#__PURE__*/React.forwardRef(function (props, ref) {\n var value = props.value,\n _props$size = props.size,\n size = _props$size === void 0 ? DEFAULT_SIZE : _props$size,\n _props$level = props.level,\n level = _props$level === void 0 ? DEFAULT_LEVEL : _props$level,\n _props$bgColor = props.bgColor,\n bgColor = _props$bgColor === void 0 ? DEFAULT_BACKGROUND_COLOR : _props$bgColor,\n _props$fgColor = props.fgColor,\n fgColor = _props$fgColor === void 0 ? DEFAULT_FRONT_COLOR : _props$fgColor,\n _props$includeMargin = props.includeMargin,\n includeMargin = _props$includeMargin === void 0 ? DEFAULT_NEED_MARGIN : _props$includeMargin,\n _props$minVersion = props.minVersion,\n minVersion = _props$minVersion === void 0 ? DEFAULT_MINVERSION : _props$minVersion,\n marginSize = props.marginSize,\n style = props.style,\n imageSettings = props.imageSettings,\n otherProps = _objectWithoutProperties(props, _excluded);\n var imgSrc = imageSettings === null || imageSettings === void 0 ? void 0 : imageSettings.src;\n var _canvas = React.useRef(null);\n var _image = React.useRef(null);\n var setCanvasRef = React.useCallback(function (node) {\n _canvas.current = node;\n if (typeof ref === 'function') {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }, [ref]);\n var _React$useState = React.useState(false),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n setIsImageLoaded = _React$useState2[1];\n var _useQRCode = useQRCode({\n value: value,\n level: level,\n minVersion: minVersion,\n includeMargin: includeMargin,\n marginSize: marginSize,\n imageSettings: imageSettings,\n size: size\n }),\n margin = _useQRCode.margin,\n cells = _useQRCode.cells,\n numCells = _useQRCode.numCells,\n calculatedImageSettings = _useQRCode.calculatedImageSettings;\n React.useEffect(function () {\n if (_canvas.current) {\n var canvas = _canvas.current;\n var ctx = canvas.getContext('2d');\n if (!ctx) {\n return;\n }\n var cellsToDraw = cells;\n var image = _image.current;\n var haveImageToRender = calculatedImageSettings != null && image !== null && image.complete && image.naturalHeight !== 0 && image.naturalWidth !== 0;\n if (haveImageToRender) {\n if (calculatedImageSettings.excavation != null) {\n cellsToDraw = excavateModules(cells, calculatedImageSettings.excavation);\n }\n }\n var pixelRatio = window.devicePixelRatio || 1;\n canvas.height = canvas.width = size * pixelRatio;\n var scale = size / numCells * pixelRatio;\n ctx.scale(scale, scale);\n ctx.fillStyle = bgColor;\n ctx.fillRect(0, 0, numCells, numCells);\n ctx.fillStyle = fgColor;\n if (isSupportPath2d) {\n ctx.fill(new Path2D(generatePath(cellsToDraw, margin)));\n } else {\n cells.forEach(function (row, rdx) {\n row.forEach(function (cell, cdx) {\n if (cell) {\n ctx.fillRect(cdx + margin, rdx + margin, 1, 1);\n }\n });\n });\n }\n if (calculatedImageSettings) {\n ctx.globalAlpha = calculatedImageSettings.opacity;\n }\n if (haveImageToRender) {\n ctx.drawImage(image, calculatedImageSettings.x + margin, calculatedImageSettings.y + margin, calculatedImageSettings.w, calculatedImageSettings.h);\n }\n }\n });\n React.useEffect(function () {\n setIsImageLoaded(false);\n }, [imgSrc]);\n var canvasStyle = _objectSpread({\n height: size,\n width: size\n }, style);\n var img = null;\n if (imgSrc != null) {\n img = /*#__PURE__*/React.createElement(\"img\", {\n src: imgSrc,\n key: imgSrc,\n style: {\n display: 'none'\n },\n onLoad: function onLoad() {\n setIsImageLoaded(true);\n },\n ref: _image\n // when crossOrigin is not set, the image will be tainted\n // and the canvas cannot be exported to an image\n ,\n\n crossOrigin: calculatedImageSettings === null || calculatedImageSettings === void 0 ? void 0 : calculatedImageSettings.crossOrigin\n });\n }\n return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(\"canvas\", _extends({\n style: canvasStyle,\n height: size,\n width: size,\n ref: setCanvasRef,\n role: \"img\"\n }, otherProps)), img);\n});\nif (process.env.NODE_ENV !== 'production') {\n QRCodeCanvas.displayName = 'QRCodeCanvas';\n}\nexport { QRCodeCanvas };","map":{"version":3,"names":["_extends","_objectSpread","_slicedToArray","_objectWithoutProperties","_excluded","React","useQRCode","DEFAULT_BACKGROUND_COLOR","DEFAULT_FRONT_COLOR","DEFAULT_NEED_MARGIN","DEFAULT_LEVEL","DEFAULT_MINVERSION","DEFAULT_SIZE","isSupportPath2d","excavateModules","generatePath","QRCodeCanvas","forwardRef","props","ref","value","_props$size","size","_props$level","level","_props$bgColor","bgColor","_props$fgColor","fgColor","_props$includeMargin","includeMargin","_props$minVersion","minVersion","marginSize","style","imageSettings","otherProps","imgSrc","src","_canvas","useRef","_image","setCanvasRef","useCallback","node","current","_React$useState","useState","_React$useState2","setIsImageLoaded","_useQRCode","margin","cells","numCells","calculatedImageSettings","useEffect","canvas","ctx","getContext","cellsToDraw","image","haveImageToRender","complete","naturalHeight","naturalWidth","excavation","pixelRatio","window","devicePixelRatio","height","width","scale","fillStyle","fillRect","fill","Path2D","forEach","row","rdx","cell","cdx","globalAlpha","opacity","drawImage","x","y","w","h","canvasStyle","img","createElement","key","display","onLoad","crossOrigin","Fragment","role","process","env","NODE_ENV","displayName"],"sources":["/Users/max_liu/max_liu/company/tools_auto_pt/node_modules/@rc-component/qrcode/es/QRCodeCanvas.js"],"sourcesContent":["import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport _objectWithoutProperties from \"@babel/runtime/helpers/esm/objectWithoutProperties\";\nvar _excluded = [\"value\", \"size\", \"level\", \"bgColor\", \"fgColor\", \"includeMargin\", \"minVersion\", \"marginSize\", \"style\", \"imageSettings\"];\nimport React from 'react';\nimport { useQRCode } from \"./hooks/useQRCode\";\nimport { DEFAULT_BACKGROUND_COLOR, DEFAULT_FRONT_COLOR, DEFAULT_NEED_MARGIN, DEFAULT_LEVEL, DEFAULT_MINVERSION, DEFAULT_SIZE, isSupportPath2d, excavateModules, generatePath } from \"./utils\";\nvar QRCodeCanvas = /*#__PURE__*/React.forwardRef(function (props, ref) {\n var value = props.value,\n _props$size = props.size,\n size = _props$size === void 0 ? DEFAULT_SIZE : _props$size,\n _props$level = props.level,\n level = _props$level === void 0 ? DEFAULT_LEVEL : _props$level,\n _props$bgColor = props.bgColor,\n bgColor = _props$bgColor === void 0 ? DEFAULT_BACKGROUND_COLOR : _props$bgColor,\n _props$fgColor = props.fgColor,\n fgColor = _props$fgColor === void 0 ? DEFAULT_FRONT_COLOR : _props$fgColor,\n _props$includeMargin = props.includeMargin,\n includeMargin = _props$includeMargin === void 0 ? DEFAULT_NEED_MARGIN : _props$includeMargin,\n _props$minVersion = props.minVersion,\n minVersion = _props$minVersion === void 0 ? DEFAULT_MINVERSION : _props$minVersion,\n marginSize = props.marginSize,\n style = props.style,\n imageSettings = props.imageSettings,\n otherProps = _objectWithoutProperties(props, _excluded);\n var imgSrc = imageSettings === null || imageSettings === void 0 ? void 0 : imageSettings.src;\n var _canvas = React.useRef(null);\n var _image = React.useRef(null);\n var setCanvasRef = React.useCallback(function (node) {\n _canvas.current = node;\n if (typeof ref === 'function') {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }, [ref]);\n var _React$useState = React.useState(false),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n setIsImageLoaded = _React$useState2[1];\n var _useQRCode = useQRCode({\n value: value,\n level: level,\n minVersion: minVersion,\n includeMargin: includeMargin,\n marginSize: marginSize,\n imageSettings: imageSettings,\n size: size\n }),\n margin = _useQRCode.margin,\n cells = _useQRCode.cells,\n numCells = _useQRCode.numCells,\n calculatedImageSettings = _useQRCode.calculatedImageSettings;\n React.useEffect(function () {\n if (_canvas.current) {\n var canvas = _canvas.current;\n var ctx = canvas.getContext('2d');\n if (!ctx) {\n return;\n }\n var cellsToDraw = cells;\n var image = _image.current;\n var haveImageToRender = calculatedImageSettings != null && image !== null && image.complete && image.naturalHeight !== 0 && image.naturalWidth !== 0;\n if (haveImageToRender) {\n if (calculatedImageSettings.excavation != null) {\n cellsToDraw = excavateModules(cells, calculatedImageSettings.excavation);\n }\n }\n var pixelRatio = window.devicePixelRatio || 1;\n canvas.height = canvas.width = size * pixelRatio;\n var scale = size / numCells * pixelRatio;\n ctx.scale(scale, scale);\n ctx.fillStyle = bgColor;\n ctx.fillRect(0, 0, numCells, numCells);\n ctx.fillStyle = fgColor;\n if (isSupportPath2d) {\n ctx.fill(new Path2D(generatePath(cellsToDraw, margin)));\n } else {\n cells.forEach(function (row, rdx) {\n row.forEach(function (cell, cdx) {\n if (cell) {\n ctx.fillRect(cdx + margin, rdx + margin, 1, 1);\n }\n });\n });\n }\n if (calculatedImageSettings) {\n ctx.globalAlpha = calculatedImageSettings.opacity;\n }\n if (haveImageToRender) {\n ctx.drawImage(image, calculatedImageSettings.x + margin, calculatedImageSettings.y + margin, calculatedImageSettings.w, calculatedImageSettings.h);\n }\n }\n });\n React.useEffect(function () {\n setIsImageLoaded(false);\n }, [imgSrc]);\n var canvasStyle = _objectSpread({\n height: size,\n width: size\n }, style);\n var img = null;\n if (imgSrc != null) {\n img = /*#__PURE__*/React.createElement(\"img\", {\n src: imgSrc,\n key: imgSrc,\n style: {\n display: 'none'\n },\n onLoad: function onLoad() {\n setIsImageLoaded(true);\n },\n ref: _image\n // when crossOrigin is not set, the image will be tainted\n // and the canvas cannot be exported to an image\n ,\n crossOrigin: calculatedImageSettings === null || calculatedImageSettings === void 0 ? void 0 : calculatedImageSettings.crossOrigin\n });\n }\n return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(\"canvas\", _extends({\n style: canvasStyle,\n height: size,\n width: size,\n ref: setCanvasRef,\n role: \"img\"\n }, otherProps)), img);\n});\nif (process.env.NODE_ENV !== 'production') {\n QRCodeCanvas.displayName = 'QRCodeCanvas';\n}\nexport { QRCodeCanvas };"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,oCAAoC;AACzD,OAAOC,aAAa,MAAM,0CAA0C;AACpE,OAAOC,cAAc,MAAM,0CAA0C;AACrE,OAAOC,wBAAwB,MAAM,oDAAoD;AACzF,IAAIC,SAAS,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,eAAe,CAAC;AACvI,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,SAAS,QAAQ,mBAAmB;AAC7C,SAASC,wBAAwB,EAAEC,mBAAmB,EAAEC,mBAAmB,EAAEC,aAAa,EAAEC,kBAAkB,EAAEC,YAAY,EAAEC,eAAe,EAAEC,eAAe,EAAEC,YAAY,QAAQ,SAAS;AAC7L,IAAIC,YAAY,GAAG,aAAaX,KAAK,CAACY,UAAU,CAAC,UAAUC,KAAK,EAAEC,GAAG,EAAE;EACrE,IAAIC,KAAK,GAAGF,KAAK,CAACE,KAAK;IACrBC,WAAW,GAAGH,KAAK,CAACI,IAAI;IACxBA,IAAI,GAAGD,WAAW,KAAK,KAAK,CAAC,GAAGT,YAAY,GAAGS,WAAW;IAC1DE,YAAY,GAAGL,KAAK,CAACM,KAAK;IAC1BA,KAAK,GAAGD,YAAY,KAAK,KAAK,CAAC,GAAGb,aAAa,GAAGa,YAAY;IAC9DE,cAAc,GAAGP,KAAK,CAACQ,OAAO;IAC9BA,OAAO,GAAGD,cAAc,KAAK,KAAK,CAA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