1 line
17 KiB
JSON
1 line
17 KiB
JSON
{"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, { useCallback, useEffect, useRef, useState } 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 QRCodeCanvas(props, forwardedRef) {\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 = useRef(null);\n var _image = useRef(null);\n var setCanvasRef = useCallback(function (node) {\n _canvas.current = node;\n if (typeof forwardedRef === 'function') {\n forwardedRef(node);\n } else if (forwardedRef) {\n forwardedRef.current = node;\n }\n }, [forwardedRef]);\n var _useState = useState(false),\n _useState2 = _slicedToArray(_useState, 2),\n setIsImageLoaded = _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 useEffect(function () {\n if (_canvas.current != null) {\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 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});\nQRCodeCanvas.displayName = 'QRCodeCanvas';\nexport { QRCodeCanvas };","map":{"version":3,"names":["_extends","_objectSpread","_slicedToArray","_objectWithoutProperties","_excluded","React","useCallback","useEffect","useRef","useState","useQRCode","DEFAULT_BACKGROUND_COLOR","DEFAULT_FRONT_COLOR","DEFAULT_NEED_MARGIN","DEFAULT_LEVEL","DEFAULT_MINVERSION","DEFAULT_SIZE","isSupportPath2d","excavateModules","generatePath","QRCodeCanvas","forwardRef","props","forwardedRef","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","_image","setCanvasRef","node","current","_useState","_useState2","setIsImageLoaded","_useQRCode","margin","cells","numCells","calculatedImageSettings","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","ref","crossOrigin","Fragment","role","displayName"],"sources":["C:/Users/Аришина)/Desktop/promo/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, { useCallback, useEffect, useRef, useState } 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 QRCodeCanvas(props, forwardedRef) {\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 = useRef(null);\n var _image = useRef(null);\n var setCanvasRef = useCallback(function (node) {\n _canvas.current = node;\n if (typeof forwardedRef === 'function') {\n forwardedRef(node);\n } else if (forwardedRef) {\n forwardedRef.current = node;\n }\n }, [forwardedRef]);\n var _useState = useState(false),\n _useState2 = _slicedToArray(_useState, 2),\n setIsImageLoaded = _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 useEffect(function () {\n if (_canvas.current != null) {\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 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});\nQRCodeCanvas.displayName = 'QRCodeCanvas';\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,IAAIC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACvE,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,aAAaf,KAAK,CAACgB,UAAU,CAAC,SAASD,YAAYA,CAACE,KAAK,EAAEC,YAAY,EAAE;EAC1F,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,a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