import { defineComponent, watchEffect, createVNode } from 'vue';
import { qrcodeSvgProps } from './props.mjs';
import qrcodegen from './qrcodegen.mjs';
import { DEFAULT_SIZE, DEFAULT_LEVEL, DEFAULT_INCLUDEMARGIN, ERROR_LEVEL_MAP, DEFAULT_BGCOLOR, DEFAULT_FGCOLOR } from './constant.mjs';
import { getMarginSize, getImageSettings, excavateModules, generatePath } from './util.mjs';

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

export { QRCodeSVG as default };
//# sourceMappingURL=SVG.mjs.map
