UNPKG

tdesign-react

Version:
86 lines (82 loc) 4.13 kB
/** * tdesign v1.13.2 * (c) 2025 tdesign * @license MIT */ import { _ as _defineProperty } from '../_chunks/dep-8618a2f1.js'; import { _ as _objectWithoutProperties } from '../_chunks/dep-30ed04a0.js'; import React from 'react'; import { D as DEFAULT_SIZE, a as DEFAULT_LEVEL, b as DEFAULT_BACKGROUND_COLOR, c as DEFAULT_FRONT_COLOR, d as DEFAULT_NEED_MARGIN, e as DEFAULT_MINVERSION, u as useQRCode, f as excavateModules, g as generatePath } from '../_chunks/dep-dda9ffab.js'; import '../_chunks/dep-c37cc2fd.js'; import '../_chunks/dep-c8ec9532.js'; var _excluded = ["value", "size", "level", "bgColor", "fgColor", "includeMargin", "minVersion", "title", "marginSize", "imageSettings"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var QRCodeSVG = /*#__PURE__*/React.forwardRef(function (props, ref) { var value = props.value, _props$size = props.size, size = _props$size === void 0 ? DEFAULT_SIZE : _props$size, _props$level = props.level, level = _props$level === void 0 ? DEFAULT_LEVEL : _props$level, _props$bgColor = props.bgColor, bgColor = _props$bgColor === void 0 ? DEFAULT_BACKGROUND_COLOR : _props$bgColor, _props$fgColor = props.fgColor, fgColor = _props$fgColor === void 0 ? DEFAULT_FRONT_COLOR : _props$fgColor, _props$includeMargin = props.includeMargin, includeMargin = _props$includeMargin === void 0 ? DEFAULT_NEED_MARGIN : _props$includeMargin, _props$minVersion = props.minVersion, minVersion = _props$minVersion === void 0 ? DEFAULT_MINVERSION : _props$minVersion, title = props.title, marginSize = props.marginSize, imageSettings = props.imageSettings, otherProps = _objectWithoutProperties(props, _excluded); var _useQRCode = useQRCode({ value: value, level: level, minVersion: minVersion, includeMargin: includeMargin, marginSize: marginSize, imageSettings: imageSettings, size: size }), margin = _useQRCode.margin, cells = _useQRCode.cells, numCells = _useQRCode.numCells, calculatedImageSettings = _useQRCode.calculatedImageSettings; var cellsToDraw = cells; var image = null; if (imageSettings != null && calculatedImageSettings != null) { if (calculatedImageSettings.excavation != null) { cellsToDraw = excavateModules(cells, calculatedImageSettings.excavation); } image = /* @__PURE__ */React.createElement("image", { href: imageSettings.src, height: calculatedImageSettings.h, width: calculatedImageSettings.w, x: calculatedImageSettings.x + margin, y: calculatedImageSettings.y + margin, preserveAspectRatio: "none", opacity: calculatedImageSettings.opacity, crossOrigin: calculatedImageSettings.crossOrigin }); } var fgPath = generatePath(cellsToDraw, margin); return /* @__PURE__ */React.createElement("svg", _objectSpread({ height: size, width: size, viewBox: "0 0 ".concat(numCells, " ").concat(numCells), ref: ref, role: "img" }, otherProps), !!title && /* @__PURE__ */React.createElement("title", null, title), /* @__PURE__ */React.createElement("path", { fill: bgColor, d: "M0,0 h".concat(numCells, "v").concat(numCells, "H0z"), shapeRendering: "crispEdges" }), /* @__PURE__ */React.createElement("path", { fill: fgColor, d: fgPath, shapeRendering: "crispEdges" }), image); }); QRCodeSVG.displayName = "QRCodeSVG"; export { QRCodeSVG }; //# sourceMappingURL=QRCodeSVG.js.map