qrcode.vue 3.9.1 → 3.10.0

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,10 +1,10 @@
1
1
  /*!
2
- * qrcode.vue v3.9.1
2
+ * qrcode.vue v3.10.0
3
3
  * A Vue.js component to generate QRCode. Both support Vue 2 and Vue 3
4
4
  * © 2017-PRESENT @scopewu(https://github.com/scopewu)
5
5
  * MIT License.
6
6
  */
7
- import { defineComponent, computed, h, ref, onMounted, watchEffect, Fragment } from 'vue';
7
+ import { defineComponent, ref, computed, h, onMounted, watchEffect, Fragment } from 'vue';
8
8
 
9
9
  /******************************************************************************
10
10
  Copyright (c) Microsoft Corporation.
@@ -1069,6 +1069,14 @@ function useQRCode(props) {
1069
1069
  });
1070
1070
  return { margin: margin, numCells: numCells, cells: cells, fgPath: fgPath, imageProps: imageProps, imageBorderProps: imageBorderProps };
1071
1071
  }
1072
+ function downloadDataURLAsFile(data, filename) {
1073
+ var link = document.createElement('a');
1074
+ link.download = filename;
1075
+ link.href = data;
1076
+ document.body.appendChild(link);
1077
+ link.click();
1078
+ document.body.removeChild(link);
1079
+ }
1072
1080
  var QRCodeProps = {
1073
1081
  value: {
1074
1082
  type: String,
@@ -1094,38 +1102,32 @@ var QRCodeProps = {
1094
1102
  },
1095
1103
  margin: {
1096
1104
  type: Number,
1097
- required: false,
1098
1105
  default: DEFAULT_MARGIN,
1106
+ validator: function (m) { return m >= 0; },
1099
1107
  },
1100
1108
  imageSettings: {
1101
1109
  type: Object,
1102
- required: false,
1103
1110
  default: function () { return ({}); },
1104
1111
  },
1105
1112
  gradient: {
1106
1113
  type: Boolean,
1107
- required: false,
1108
1114
  default: false,
1109
1115
  },
1110
1116
  gradientType: {
1111
1117
  type: String,
1112
- required: false,
1113
1118
  default: 'linear',
1114
1119
  validator: function (t) { return ['linear', 'radial'].indexOf(t) > -1; },
1115
1120
  },
1116
1121
  gradientStartColor: {
1117
1122
  type: String,
1118
- required: false,
1119
1123
  default: '#000',
1120
1124
  },
1121
1125
  gradientEndColor: {
1122
1126
  type: String,
1123
- required: false,
1124
1127
  default: '#fff',
1125
1128
  },
1126
1129
  radius: {
1127
1130
  type: Number,
1128
- required: false,
1129
1131
  default: 0,
1130
1132
  validator: function (r) { return !isNaN(r) && r >= 0 && r <= 0.5; },
1131
1133
  },
@@ -1143,8 +1145,9 @@ var QRCodeVueProps = __assign(__assign({}, QRCodeProps), { renderAs: {
1143
1145
  var QrcodeSvg = defineComponent({
1144
1146
  name: 'QRCodeSvg',
1145
1147
  props: QRCodeProps,
1146
- setup: function (props) {
1148
+ setup: function (props, ctx) {
1147
1149
  var _a = useQRCode(props), numCells = _a.numCells, fgPath = _a.fgPath, imageProps = _a.imageProps, imageBorderProps = _a.imageBorderProps;
1150
+ var svgEl = ref();
1148
1151
  var uid = getUid(props.id);
1149
1152
  var qrGradientId = "qrcode.vue-gradient-".concat(uid);
1150
1153
  var qrLogoClipPathId = "qrcode.vue-logo-clip-path-".concat(uid);
@@ -1193,15 +1196,32 @@ var QrcodeSvg = defineComponent({
1193
1196
  }),
1194
1197
  ]);
1195
1198
  });
1199
+ var getSvgDataURL = function (svg) { return 'data:image/svg+xml;charset=utf-8,' +
1200
+ encodeURIComponent('<?xml version="1.0" standalone="no"?>' + new XMLSerializer().serializeToString(svg)); };
1201
+ ctx.expose({
1202
+ toDataURL: function () {
1203
+ var svg = svgEl.value;
1204
+ if (!svg)
1205
+ return;
1206
+ return getSvgDataURL(svg);
1207
+ },
1208
+ download: function (filename) {
1209
+ if (filename === void 0) { filename = 'qrcode.svg'; }
1210
+ var svg = svgEl.value;
1211
+ if (!svg)
1212
+ return;
1213
+ downloadDataURLAsFile(getSvgDataURL(svg), filename);
1214
+ },
1215
+ });
1196
1216
  return function () { return h('svg', {
1217
+ ref: svgEl,
1197
1218
  width: props.size,
1198
1219
  height: props.size,
1199
1220
  xmlns: 'http://www.w3.org/2000/svg',
1200
1221
  viewBox: "0 0 ".concat(numCells.value, " ").concat(numCells.value),
1201
1222
  role: 'img',
1202
- 'aria-label': props.value,
1203
1223
  }, [
1204
- h('defs', {}, [gradientVNode.value, clipPathVNode.value]),
1224
+ h('defs', {}, [gradientVNode.value, clipPathVNode.value].filter(Boolean)),
1205
1225
  h('rect', {
1206
1226
  width: '100%',
1207
1227
  height: '100%',
@@ -1220,7 +1240,7 @@ var QrcodeSvg = defineComponent({
1220
1240
  rx: imageBorderProps.value.borderRadius,
1221
1241
  ry: imageBorderProps.value.borderRadius,
1222
1242
  }),
1223
- props.imageSettings.src && imageProps.value && h('image', __assign(__assign({ href: props.imageSettings.src }, imageProps.value), (imageProps.value.borderRadius > 0 ? { 'clip-path': "url(#".concat(qrLogoClipPathId, ")") } : {}))),
1243
+ props.imageSettings.src && imageProps.value && h('image', __assign({ href: props.imageSettings.src, crossorigin: props.imageSettings.crossOrigin, 'clip-path': imageProps.value.borderRadius > 0 ? "url(#".concat(qrLogoClipPathId, ")") : void 0 }, imageProps.value)),
1224
1244
  ]); };
1225
1245
  },
1226
1246
  });
@@ -1306,12 +1326,23 @@ var QrcodeCanvas = defineComponent({
1306
1326
  }
1307
1327
  };
1308
1328
  onMounted(generate);
1309
- watchEffect(generate);
1329
+ watchEffect(generate, { flush: 'post' });
1330
+ ctx.expose({
1331
+ toDataURL: function (type, quality) { var _a; return (_a = canvasEl.value) === null || _a === void 0 ? void 0 : _a.toDataURL(type, quality); },
1332
+ download: function (filename) {
1333
+ if (filename === void 0) { filename = 'qrcode.png'; }
1334
+ var canvas = canvasEl.value;
1335
+ if (!canvas)
1336
+ return;
1337
+ downloadDataURLAsFile(canvas.toDataURL('image/png'), filename);
1338
+ },
1339
+ });
1310
1340
  return function () { return h(Fragment, [
1311
- h('canvas', __assign(__assign({}, ctx.attrs), { ref: canvasEl, role: 'img', 'aria-label': props.value, style: __assign(__assign({}, ctx.attrs.style), { width: "".concat(props.size, "px"), height: "".concat(props.size, "px") }) })),
1341
+ h('canvas', __assign(__assign({}, ctx.attrs), { ref: canvasEl, role: 'img', style: __assign(__assign({}, ctx.attrs.style), { width: "".concat(props.size, "px"), height: "".concat(props.size, "px") }) })),
1312
1342
  props.imageSettings.src && h('img', {
1313
1343
  ref: imageEl,
1314
1344
  src: props.imageSettings.src,
1345
+ crossorigin: props.imageSettings.crossOrigin,
1315
1346
  style: { display: 'none' },
1316
1347
  onLoad: generate,
1317
1348
  })
@@ -1321,8 +1352,14 @@ var QrcodeCanvas = defineComponent({
1321
1352
  var QrcodeVue = defineComponent({
1322
1353
  name: 'Qrcode',
1323
1354
  props: QRCodeVueProps,
1324
- setup: function (props) {
1355
+ setup: function (props, ctx) {
1356
+ var childRef = ref();
1357
+ ctx.expose({
1358
+ toDataURL: function (type, quality) { var _a, _b; return (_b = (_a = childRef.value) === null || _a === void 0 ? void 0 : _a.toDataURL) === null || _b === void 0 ? void 0 : _b.call(_a, type, quality); },
1359
+ download: function (filename) { var _a, _b; return (_b = (_a = childRef.value) === null || _a === void 0 ? void 0 : _a.download) === null || _b === void 0 ? void 0 : _b.call(_a, filename); },
1360
+ });
1325
1361
  return function () { return h(props.renderAs === 'svg' ? QrcodeSvg : QrcodeCanvas, {
1362
+ ref: childRef,
1326
1363
  value: props.value,
1327
1364
  size: props.size,
1328
1365
  margin: props.margin,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qrcode.vue",
3
- "version": "3.9.1",
3
+ "version": "3.10.0",
4
4
  "description": "A Vue.js component to generate QRCode. Both support Vue 2 and Vue 3",
5
5
  "type": "module",
6
6
  "main": "./dist/qrcode.vue.cjs.js",
@@ -18,8 +18,10 @@
18
18
  "./package": "./package.json"
19
19
  },
20
20
  "scripts": {
21
- "dev": "rsbuild dev",
21
+ "dev": "node example/scripts/generate-i18n.mjs && rsbuild dev",
22
22
  "build": "rollup -c",
23
+ "build:example": "node example/scripts/generate-i18n.mjs && rsbuild build",
24
+ "generate:i18n": "node example/scripts/generate-i18n.mjs",
23
25
  "test": "rstest"
24
26
  },
25
27
  "repository": "https://github.com/scopewu/qrcode.vue.git",
@@ -50,13 +52,13 @@
50
52
  "dependencies": {},
51
53
  "devDependencies": {
52
54
  "@rollup/plugin-terser": "^1.0.0",
53
- "@rsbuild/core": "^2.0.5",
54
- "@rstest/core": "^0.9.10",
55
- "@vue/test-utils": "^2.4.10",
56
- "happy-dom": "^20.9.0",
57
- "rollup": "^4.60.3",
55
+ "@rsbuild/core": "^2.0.13",
56
+ "@rstest/core": "^0.10.4",
57
+ "@vue/test-utils": "^2.4.11",
58
+ "happy-dom": "^20.10.3",
59
+ "rollup": "^4.62.0",
58
60
  "rollup-plugin-typescript2": "^0.37.0",
59
61
  "typescript": "^5.9.3",
60
- "vue": "^3.5.34"
62
+ "vue": "^3.5.38"
61
63
  }
62
64
  }