import { defineComponent, ref, watch, nextTick, onMounted, createElementBlock, openBlock, normalizeClass, unref, createElementVNode } from 'vue';
import '../../../utils/index.mjs';
import { barcodeProps } from './barcode.mjs';
import JsBarcode from '../../../../node_modules/.pnpm/jsbarcode@3.12.1/node_modules/jsbarcode/bin/JsBarcode.mjs';
import { createNamespace } from '../../../utils/create-namespace.mjs';

"use strict";
var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{
    name: "LlBarcode"
  },
  __name: "barcode",
  props: barcodeProps,
  setup(__props) {
    const props = __props;
    const bem = createNamespace("barcode");
    const canvasRef = ref(null);
    const generateBarcode = () => {
      if (!props.value || !canvasRef.value) return;
      try {
        const options = {
          format: props.format,
          width: props.width,
          height: props.height,
          displayValue: props.displayValue,
          textAlign: props.textAlign,
          textPosition: props.textPosition,
          textMargin: props.textMargin,
          fontSize: props.fontSize,
          background: props.background || "#ffffff",
          lineColor: props.lineColor || "#000000",
          margin: props.margin,
          flat: props.format === "ITF14" ? void 0 : false
        };
        JsBarcode(canvasRef.value, props.value, options);
      } catch (error) {
        console.error("\u6761\u5F62\u7801\u751F\u6210\u5931\u8D25:", error);
      }
    };
    watch(
      () => Object.values(props),
      () => {
        nextTick(generateBarcode);
      },
      { deep: true }
    );
    onMounted(() => {
      generateBarcode();
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock(
        "div",
        {
          class: normalizeClass(unref(bem).b())
        },
        [
          createElementVNode(
            "canvas",
            {
              ref_key: "canvasRef",
              ref: canvasRef,
              class: "barcode-canvas"
            },
            null,
            512
            /* NEED_PATCH */
          )
        ],
        2
        /* CLASS */
      );
    };
  }
});

export { _sfc_main as default };
//# sourceMappingURL=barcode.vue2.mjs.map
