'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var props = require('./props.cjs');
var qrcodegen = require('./qrcodegen.cjs');
var constant = require('./constant.cjs');
var util = require('./util.cjs');

var QRCodeSVG = /* @__PURE__ */ vue.defineComponent({
  name: "QRCodeSVG",
  inheritAttrs: false,
  props: props.qrcodeSvgProps(),
  setup(props) {
    let cells = null;
    let margin = null;
    let numCells = null;
    let calculatedImageSettings = null;
    let fgPath = null;
    let image = null;
    vue.watchEffect(() => {
      const {
        value,
        size = constant.DEFAULT_SIZE,
        level = constant.DEFAULT_LEVEL,
        includeMargin = constant.DEFAULT_INCLUDEMARGIN,
        marginSize,
        imageSettings
      } = props;
      cells = qrcodegen.default.QrCode.encodeText(value, constant.ERROR_LEVEL_MAP[level]).getModules();
      margin = util.getMarginSize(includeMargin, marginSize);
      numCells = cells.length + margin * 2;
      calculatedImageSettings = util.getImageSettings(cells, size, margin, imageSettings);
      if (imageSettings != null && calculatedImageSettings != null) {
        if (calculatedImageSettings.excavation != null)
          cells = util.excavateModules(cells, calculatedImageSettings.excavation);
        image = vue.createVNode("image", {
          "xlink:href": imageSettings.src,
          "height": calculatedImageSettings.h,
          "width": calculatedImageSettings.w,
          "x": calculatedImageSettings.x + margin,
          "y": calculatedImageSettings.y + margin,
          "preserveAspectRatio": "none"
        }, null);
      }
      fgPath = util.generatePath(cells, margin);
    });
    return () => {
      const bgColor = props.bgColor && constant.DEFAULT_BGCOLOR;
      const fgColor = props.fgColor && constant.DEFAULT_FGCOLOR;
      return vue.createVNode("svg", {
        "height": props.size,
        "width": props.size,
        "viewBox": `0 0 ${numCells} ${numCells}`
      }, [!!props.title && vue.createVNode("title", null, [props.title]), vue.createVNode("path", {
        "fill": bgColor,
        "d": `M0,0 h${numCells}v${numCells}H0z`,
        "shape-rendering": "crispEdges"
      }, null), vue.createVNode("path", {
        "fill": fgColor,
        "d": fgPath,
        "shape-rendering": "crispEdges"
      }, null), image]);
    };
  }
});

exports.default = QRCodeSVG;
//# sourceMappingURL=SVG.cjs.map
