xl-public-utils 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
- import bwipjs from 'bwip-js';
1
+ import { qrcode, datamatrix} from './bwip-js.mjs';
2
2
 
3
3
  /**
4
4
  * @typedef {Object} QrCodeOptions
5
- * @property {string} [bcid='qrcode'] - 二维码类型,具体支持请查看文档
5
+ * @property {'qrcode' | 'dataMatrix'} [bcid='qrcode'] - 二维码类型,具体支持请查看文档
6
6
  * @property {number} [width=1056] - 最终图片宽度
7
7
  * @property {number} [height=342] - 最终图片高度
8
8
  * @property {number} [qrcodeW=300] - 二维码宽度
@@ -45,6 +45,22 @@ export function generateQRCodeWithText(content, options = {}) {
45
45
  textColor = '#000',
46
46
  textContent
47
47
  } = options
48
+ /**
49
+ * Alias for {@link qrcode | dataMatrix}
50
+ * @function
51
+ */
52
+ let generFunc;
53
+ switch(bcid) {
54
+ case "qrcode":
55
+ generFunc = qrcode;
56
+ break;
57
+ case "dataMatrix":
58
+ generFunc = datamatrix;
59
+ break;
60
+ default:
61
+ throw('bcidError')
62
+ return false
63
+ }
48
64
  // Create the canvas and set its size
49
65
  const canvas = document.createElement('canvas');
50
66
  canvas.width = width;
@@ -60,7 +76,7 @@ export function generateQRCodeWithText(content, options = {}) {
60
76
  tempCanvas.width = qrcodeW;
61
77
  tempCanvas.height = qrcodeH;
62
78
  try {
63
- bwipjs.toCanvas(tempCanvas, {
79
+ generFunc(tempCanvas, {
64
80
  bcid: bcid, // Barcode type
65
81
  text: content, // QR code content
66
82
  scale: 1,
File without changes
File without changes