qrcode.vue 3.8.0 → 3.8.1
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.
- package/dist/qrcode.vue.browser.js +49 -46
- package/dist/qrcode.vue.browser.min.js +2 -2
- package/dist/qrcode.vue.cjs.js +49 -46
- package/dist/qrcode.vue.esm.js +49 -46
- package/dist/src/index.d.ts +3 -1
- package/package.json +8 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* qrcode.vue v3.8.
|
|
2
|
+
* qrcode.vue v3.8.1
|
|
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.
|
|
@@ -909,6 +909,7 @@ var qrcodegen;
|
|
|
909
909
|
})(qrcodegen || (qrcodegen = {}));
|
|
910
910
|
var QR = qrcodegen;
|
|
911
911
|
|
|
912
|
+
var _uid = 0;
|
|
912
913
|
var defaultErrorCorrectLevel = 'L';
|
|
913
914
|
var DEFAULT_QR_SIZE = 100;
|
|
914
915
|
var DEFAULT_MARGIN = 0;
|
|
@@ -935,40 +936,41 @@ function validErrorCorrectLevel(level) {
|
|
|
935
936
|
}
|
|
936
937
|
function generatePath(modules, margin) {
|
|
937
938
|
if (margin === void 0) { margin = 0; }
|
|
938
|
-
var
|
|
939
|
-
|
|
939
|
+
var pathSegments = [];
|
|
940
|
+
for (var y = 0; y < modules.length; y++) {
|
|
941
|
+
var row = modules[y];
|
|
940
942
|
var start = null;
|
|
941
|
-
|
|
943
|
+
for (var x = 0; x < row.length; x++) {
|
|
944
|
+
var cell = row[x];
|
|
942
945
|
if (!cell && start !== null) {
|
|
943
946
|
// M0 0h7v1H0z injects the space with the move and drops the comma,
|
|
944
|
-
|
|
945
|
-
path += "M".concat(start + margin, " ").concat(y + margin, "h").concat(x - start, "v1H").concat(start + margin, "z");
|
|
947
|
+
pathSegments.push("M".concat(start + margin, " ").concat(y + margin, "h").concat(x - start, "v1H").concat(start + margin, "z"));
|
|
946
948
|
start = null;
|
|
947
|
-
|
|
949
|
+
continue;
|
|
948
950
|
}
|
|
949
951
|
// end of row, clean up or skip
|
|
950
952
|
if (x === row.length - 1) {
|
|
951
953
|
if (!cell) {
|
|
952
954
|
// We would have closed the op above already so this can only mean
|
|
953
955
|
// 2+ light modules in a row.
|
|
954
|
-
|
|
956
|
+
continue;
|
|
955
957
|
}
|
|
956
958
|
if (start === null) {
|
|
957
959
|
// Just a single dark module.
|
|
958
|
-
|
|
960
|
+
pathSegments.push("M".concat(x + margin, ",").concat(y + margin, " h1v1H").concat(x + margin, "z"));
|
|
959
961
|
}
|
|
960
962
|
else {
|
|
961
963
|
// Otherwise finish the current line.
|
|
962
|
-
|
|
964
|
+
pathSegments.push("M".concat(start + margin, ",").concat(y + margin, " h").concat(x + 1 - start, "v1H").concat(start + margin, "z"));
|
|
963
965
|
}
|
|
964
|
-
|
|
966
|
+
continue;
|
|
965
967
|
}
|
|
966
968
|
if (cell && start === null) {
|
|
967
969
|
start = x;
|
|
968
970
|
}
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
return
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
return pathSegments.join('');
|
|
972
974
|
}
|
|
973
975
|
function getImageSettings(cells, size, margin, imageSettings) {
|
|
974
976
|
var width = imageSettings.width, height = imageSettings.height, imageX = imageSettings.x, imageY = imageSettings.y;
|
|
@@ -1091,7 +1093,9 @@ var QrcodeSvg = vue.defineComponent({
|
|
|
1091
1093
|
props: QRCodeProps,
|
|
1092
1094
|
setup: function (props) {
|
|
1093
1095
|
var _a = useQRCode(props), numCells = _a.numCells, fgPath = _a.fgPath, imageProps = _a.imageProps, imageBorderProps = _a.imageBorderProps;
|
|
1094
|
-
var
|
|
1096
|
+
var uid = _uid++;
|
|
1097
|
+
var qrGradientId = "qrcode.vue-gradient-".concat(uid);
|
|
1098
|
+
var qrLogoClipPathId = "qrcode.vue-logo-clip-path-".concat(uid);
|
|
1095
1099
|
var renderGradient = function () {
|
|
1096
1100
|
if (!props.gradient)
|
|
1097
1101
|
return null;
|
|
@@ -1120,7 +1124,6 @@ var QrcodeSvg = vue.defineComponent({
|
|
|
1120
1124
|
}),
|
|
1121
1125
|
]);
|
|
1122
1126
|
};
|
|
1123
|
-
var qrLogoClipPathId = 'qrcode.vue-logo-clip-path';
|
|
1124
1127
|
var renderClipPath = function () {
|
|
1125
1128
|
var borderRadius = imageProps.value.borderRadius;
|
|
1126
1129
|
if (!props.imageSettings.src)
|
|
@@ -1144,6 +1147,8 @@ var QrcodeSvg = vue.defineComponent({
|
|
|
1144
1147
|
'shape-rendering': "crispEdges",
|
|
1145
1148
|
xmlns: 'http://www.w3.org/2000/svg',
|
|
1146
1149
|
viewBox: "0 0 ".concat(numCells.value, " ").concat(numCells.value),
|
|
1150
|
+
role: 'img',
|
|
1151
|
+
'aria-label': props.value,
|
|
1147
1152
|
}, [
|
|
1148
1153
|
vue.h('defs', {}, [renderGradient(), renderClipPath()]),
|
|
1149
1154
|
vue.h('rect', {
|
|
@@ -1172,9 +1177,18 @@ var QrcodeCanvas = vue.defineComponent({
|
|
|
1172
1177
|
name: 'QRCodeCanvas',
|
|
1173
1178
|
props: QRCodeProps,
|
|
1174
1179
|
setup: function (props, ctx) {
|
|
1175
|
-
var _a = useQRCode(props), margin = _a.margin, cells = _a.cells, numCells = _a.numCells, imageProps = _a.imageProps, imageBorderProps = _a.imageBorderProps;
|
|
1180
|
+
var _a = useQRCode(props), margin = _a.margin, cells = _a.cells, numCells = _a.numCells, fgPath = _a.fgPath, imageProps = _a.imageProps, imageBorderProps = _a.imageBorderProps;
|
|
1176
1181
|
var canvasEl = vue.ref(null);
|
|
1177
1182
|
var imageRef = vue.ref(null);
|
|
1183
|
+
var drawRoundedRect = function (ctx, x, y, width, height, radius) {
|
|
1184
|
+
ctx.beginPath();
|
|
1185
|
+
if (ctx.roundRect) {
|
|
1186
|
+
ctx.roundRect(x, y, width, height, radius);
|
|
1187
|
+
}
|
|
1188
|
+
else {
|
|
1189
|
+
ctx.rect(x, y, width, height);
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1178
1192
|
var generate = function () {
|
|
1179
1193
|
var size = props.size, background = props.background, foreground = props.foreground, gradient = props.gradient, gradientType = props.gradientType, gradientStartColor = props.gradientStartColor, gradientEndColor = props.gradientEndColor;
|
|
1180
1194
|
var canvas = canvasEl.value;
|
|
@@ -1185,7 +1199,6 @@ var QrcodeCanvas = vue.defineComponent({
|
|
|
1185
1199
|
if (!canvasCtx) {
|
|
1186
1200
|
return;
|
|
1187
1201
|
}
|
|
1188
|
-
var qrCells = cells.value;
|
|
1189
1202
|
var image = imageRef.value;
|
|
1190
1203
|
var devicePixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;
|
|
1191
1204
|
var scale = (size / numCells.value) * devicePixelRatio;
|
|
@@ -1209,10 +1222,10 @@ var QrcodeCanvas = vue.defineComponent({
|
|
|
1209
1222
|
canvasCtx.fillStyle = foreground;
|
|
1210
1223
|
}
|
|
1211
1224
|
if (SUPPORTS_PATH2D) {
|
|
1212
|
-
canvasCtx.fill(new Path2D(
|
|
1225
|
+
canvasCtx.fill(new Path2D(fgPath.value));
|
|
1213
1226
|
}
|
|
1214
1227
|
else {
|
|
1215
|
-
|
|
1228
|
+
cells.value.forEach(function (row, rdx) {
|
|
1216
1229
|
row.forEach(function (cell, cdx) {
|
|
1217
1230
|
if (cell) {
|
|
1218
1231
|
canvasCtx.fillRect(cdx + margin.value, rdx + margin.value, 1, 1);
|
|
@@ -1222,15 +1235,6 @@ var QrcodeCanvas = vue.defineComponent({
|
|
|
1222
1235
|
}
|
|
1223
1236
|
var showImage = props.imageSettings.src && image && image.naturalWidth !== 0 && image.naturalHeight !== 0;
|
|
1224
1237
|
if (showImage) {
|
|
1225
|
-
var drawRoundedRect = function (ctx, x, y, width, height, radius) {
|
|
1226
|
-
ctx.beginPath();
|
|
1227
|
-
if (ctx.roundRect) {
|
|
1228
|
-
ctx.roundRect(x, y, width, height, radius);
|
|
1229
|
-
}
|
|
1230
|
-
else {
|
|
1231
|
-
ctx.rect(x, y, width, height);
|
|
1232
|
-
}
|
|
1233
|
-
};
|
|
1234
1238
|
if (imageBorderProps.value) {
|
|
1235
1239
|
var imageBorder = imageBorderProps.value;
|
|
1236
1240
|
canvasCtx.fillStyle = props.background;
|
|
@@ -1254,7 +1258,7 @@ var QrcodeCanvas = vue.defineComponent({
|
|
|
1254
1258
|
vue.watchEffect(generate);
|
|
1255
1259
|
var style = ctx.attrs.style;
|
|
1256
1260
|
return function () { return vue.h(vue.Fragment, [
|
|
1257
|
-
vue.h('canvas', __assign(__assign({}, ctx.attrs), { ref: canvasEl, style: __assign(__assign({}, style), { width: "".concat(props.size, "px"), height: "".concat(props.size, "px") }) })),
|
|
1261
|
+
vue.h('canvas', __assign(__assign({}, ctx.attrs), { ref: canvasEl, role: 'img', 'aria-label': props.value, style: __assign(__assign({}, style), { width: "".concat(props.size, "px"), height: "".concat(props.size, "px") }) })),
|
|
1258
1262
|
props.imageSettings.src && vue.h('img', {
|
|
1259
1263
|
ref: imageRef,
|
|
1260
1264
|
src: props.imageSettings.src,
|
|
@@ -1266,23 +1270,22 @@ var QrcodeCanvas = vue.defineComponent({
|
|
|
1266
1270
|
});
|
|
1267
1271
|
var QrcodeVue = vue.defineComponent({
|
|
1268
1272
|
name: 'Qrcode',
|
|
1269
|
-
render: function () {
|
|
1270
|
-
var _a = this.$props, renderAs = _a.renderAs, value = _a.value, size = _a.size, margin = _a.margin, level = _a.level, background = _a.background, foreground = _a.foreground, imageSettings = _a.imageSettings, gradient = _a.gradient, gradientType = _a.gradientType, gradientStartColor = _a.gradientStartColor, gradientEndColor = _a.gradientEndColor;
|
|
1271
|
-
return vue.h(renderAs === 'svg' ? QrcodeSvg : QrcodeCanvas, {
|
|
1272
|
-
value: value,
|
|
1273
|
-
size: size,
|
|
1274
|
-
margin: margin,
|
|
1275
|
-
level: level,
|
|
1276
|
-
background: background,
|
|
1277
|
-
foreground: foreground,
|
|
1278
|
-
imageSettings: imageSettings,
|
|
1279
|
-
gradient: gradient,
|
|
1280
|
-
gradientType: gradientType,
|
|
1281
|
-
gradientStartColor: gradientStartColor,
|
|
1282
|
-
gradientEndColor: gradientEndColor,
|
|
1283
|
-
});
|
|
1284
|
-
},
|
|
1285
1273
|
props: QRCodeVueProps,
|
|
1274
|
+
setup: function (props) {
|
|
1275
|
+
return function () { return vue.h(props.renderAs === 'svg' ? QrcodeSvg : QrcodeCanvas, {
|
|
1276
|
+
value: props.value,
|
|
1277
|
+
size: props.size,
|
|
1278
|
+
margin: props.margin,
|
|
1279
|
+
level: props.level,
|
|
1280
|
+
background: props.background,
|
|
1281
|
+
foreground: props.foreground,
|
|
1282
|
+
imageSettings: props.imageSettings,
|
|
1283
|
+
gradient: props.gradient,
|
|
1284
|
+
gradientType: props.gradientType,
|
|
1285
|
+
gradientStartColor: props.gradientStartColor,
|
|
1286
|
+
gradientEndColor: props.gradientEndColor,
|
|
1287
|
+
}); };
|
|
1288
|
+
},
|
|
1286
1289
|
});
|
|
1287
1290
|
|
|
1288
1291
|
exports.QrcodeCanvas = QrcodeCanvas;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* qrcode.vue v3.8.
|
|
2
|
+
* qrcode.vue v3.8.1
|
|
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
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).QrcodeVue={},e.Vue)}(this,function(e,t){"use strict";var r,n=function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;n>r;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},n.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError,function(e){var t=function(){function t(e,r,n,o){if(this.version=e,this.errorCorrectionLevel=r,this.modules=[],this.isFunction=[],t.MIN_VERSION>e||e>t.MAX_VERSION)throw new RangeError("Version value out of range");if(-1>o||o>7)throw new RangeError("Mask value out of range");this.size=4*e+17;for(var a=[],u=0;this.size>u;u++)a.push(!1);for(u=0;this.size>u;u++)this.modules.push(a.slice()),this.isFunction.push(a.slice());this.drawFunctionPatterns();var s=this.addEccAndInterleave(n);if(this.drawCodewords(s),-1==o){var l=1e9;for(u=0;8>u;u++){this.applyMask(u),this.drawFormatBits(u);var d=this.getPenaltyScore();l>d&&(o=u,l=d),this.applyMask(u)}}i(o>=0&&7>=o),this.mask=o,this.applyMask(o),this.drawFormatBits(o),this.isFunction=[]}return t.encodeText=function(r,n){var i=e.QrSegment.makeSegments(r);return t.encodeSegments(i,n)},t.encodeBinary=function(r,n){var i=e.QrSegment.makeBytes(r);return t.encodeSegments([i],n)},t.encodeSegments=function(e,n,a,u,s,l){if(void 0===a&&(a=1),void 0===u&&(u=40),void 0===s&&(s=-1),void 0===l&&(l=!0),t.MIN_VERSION>a||a>u||u>t.MAX_VERSION||-1>s||s>7)throw new RangeError("Invalid value");var d,h;for(d=a;;d++){var c=8*t.getNumDataCodewords(d,n),f=o.getTotalBits(e,d);if(c>=f){h=f;break}if(d>=u)throw new RangeError("Data too long")}for(var g=0,v=[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH];v.length>g;g++){var m=v[g];l&&h<=8*t.getNumDataCodewords(d,m)&&(n=m)}for(var p=[],E=0,y=e;y.length>E;E++){var w=y[E];r(w.mode.modeBits,4,p),r(w.numChars,w.mode.numCharCountBits(d),p);for(var C=0,M=w.getData();M.length>C;C++){p.push(M[C])}}i(p.length==h);var R=8*t.getNumDataCodewords(d,n);i(R>=p.length),r(0,Math.min(4,R-p.length),p),r(0,(8-p.length%8)%8,p),i(p.length%8==0);for(var S=236;R>p.length;S^=253)r(S,8,p);for(var N=[];p.length>8*N.length;)N.push(0);return p.forEach(function(e,t){return N[t>>>3]|=e<<7-(7&t)}),new t(d,n,N,s)},t.prototype.getModule=function(e,t){return e>=0&&this.size>e&&t>=0&&this.size>t&&this.modules[t][e]},t.prototype.getModules=function(){return this.modules},t.prototype.drawFunctionPatterns=function(){for(var e=0;this.size>e;e++)this.setFunctionModule(6,e,e%2==0),this.setFunctionModule(e,6,e%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);var t=this.getAlignmentPatternPositions(),r=t.length;for(e=0;r>e;e++)for(var n=0;r>n;n++)0==e&&0==n||0==e&&n==r-1||e==r-1&&0==n||this.drawAlignmentPattern(t[e],t[n]);this.drawFormatBits(0),this.drawVersion()},t.prototype.drawFormatBits=function(e){for(var t=this.errorCorrectionLevel.formatBits<<3|e,r=t,o=0;10>o;o++)r=r<<1^1335*(r>>>9);var a=21522^(t<<10|r);i(a>>>15==0);for(o=0;5>=o;o++)this.setFunctionModule(8,o,n(a,o));this.setFunctionModule(8,7,n(a,6)),this.setFunctionModule(8,8,n(a,7)),this.setFunctionModule(7,8,n(a,8));for(o=9;15>o;o++)this.setFunctionModule(14-o,8,n(a,o));for(o=0;8>o;o++)this.setFunctionModule(this.size-1-o,8,n(a,o));for(o=8;15>o;o++)this.setFunctionModule(8,this.size-15+o,n(a,o));this.setFunctionModule(8,this.size-8,!0)},t.prototype.drawVersion=function(){if(this.version>=7){for(var e=this.version,t=0;12>t;t++)e=e<<1^7973*(e>>>11);var r=this.version<<12|e;i(r>>>18==0);for(t=0;18>t;t++){var o=n(r,t),a=this.size-11+t%3,u=Math.floor(t/3);this.setFunctionModule(a,u,o),this.setFunctionModule(u,a,o)}}},t.prototype.drawFinderPattern=function(e,t){for(var r=-4;4>=r;r++)for(var n=-4;4>=n;n++){var i=Math.max(Math.abs(n),Math.abs(r)),o=e+n,a=t+r;o>=0&&this.size>o&&a>=0&&this.size>a&&this.setFunctionModule(o,a,2!=i&&4!=i)}},t.prototype.drawAlignmentPattern=function(e,t){for(var r=-2;2>=r;r++)for(var n=-2;2>=n;n++)this.setFunctionModule(e+n,t+r,1!=Math.max(Math.abs(n),Math.abs(r)))},t.prototype.setFunctionModule=function(e,t,r){this.modules[t][e]=r,this.isFunction[t][e]=!0},t.prototype.addEccAndInterleave=function(e){var r=this.version,n=this.errorCorrectionLevel;if(e.length!=t.getNumDataCodewords(r,n))throw new RangeError("Invalid argument");for(var o=t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][r],a=t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][r],u=Math.floor(t.getNumRawDataModules(r)/8),s=o-u%o,l=Math.floor(u/o),d=[],h=t.reedSolomonComputeDivisor(a),c=0,f=0;o>c;c++){var g=e.slice(f,f+l-a+(s>c?0:1));f+=g.length;var v=t.reedSolomonComputeRemainder(g,h);s>c&&g.push(0),d.push(g.concat(v))}var m=[],p=function(e){d.forEach(function(t,r){e==l-a&&s>r||m.push(t[e])})};for(c=0;d[0].length>c;c++)p(c);return i(m.length==u),m},t.prototype.drawCodewords=function(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");for(var r=0,o=this.size-1;o>=1;o-=2){6==o&&(o=5);for(var a=0;this.size>a;a++)for(var u=0;2>u;u++){var s=o-u,l=!(o+1&2)?this.size-1-a:a;!this.isFunction[l][s]&&8*e.length>r&&(this.modules[l][s]=n(e[r>>>3],7-(7&r)),r++)}}i(r==8*e.length)},t.prototype.applyMask=function(e){if(0>e||e>7)throw new RangeError("Mask value out of range");for(var t=0;this.size>t;t++)for(var r=0;this.size>r;r++){var n=void 0;switch(e){case 0:n=(r+t)%2==0;break;case 1:n=t%2==0;break;case 2:n=r%3==0;break;case 3:n=(r+t)%3==0;break;case 4:n=(Math.floor(r/3)+Math.floor(t/2))%2==0;break;case 5:n=r*t%2+r*t%3==0;break;case 6:n=(r*t%2+r*t%3)%2==0;break;case 7:n=((r+t)%2+r*t%3)%2==0;break;default:throw Error("Unreachable")}!this.isFunction[t][r]&&n&&(this.modules[t][r]=!this.modules[t][r])}},t.prototype.getPenaltyScore=function(){for(var e=0,r=0;this.size>r;r++){for(var n=!1,o=0,a=[0,0,0,0,0,0,0],u=0;this.size>u;u++)this.modules[r][u]==n?5==++o?e+=t.PENALTY_N1:o>5&&e++:(this.finderPenaltyAddHistory(o,a),n||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),n=this.modules[r][u],o=1);e+=this.finderPenaltyTerminateAndCount(n,o,a)*t.PENALTY_N3}for(u=0;this.size>u;u++){n=!1;var s=0;for(a=[0,0,0,0,0,0,0],r=0;this.size>r;r++)this.modules[r][u]==n?5==++s?e+=t.PENALTY_N1:s>5&&e++:(this.finderPenaltyAddHistory(s,a),n||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),n=this.modules[r][u],s=1);e+=this.finderPenaltyTerminateAndCount(n,s,a)*t.PENALTY_N3}for(r=0;this.size-1>r;r++)for(u=0;this.size-1>u;u++){var l=this.modules[r][u];l==this.modules[r][u+1]&&l==this.modules[r+1][u]&&l==this.modules[r+1][u+1]&&(e+=t.PENALTY_N2)}for(var d=0,h=0,c=this.modules;c.length>h;h++){d=c[h].reduce(function(e,t){return e+(t?1:0)},d)}var f=this.size*this.size,g=Math.ceil(Math.abs(20*d-10*f)/f)-1;return i(g>=0&&9>=g),i((e+=g*t.PENALTY_N4)>=0&&2568888>=e),e},t.prototype.getAlignmentPatternPositions=function(){if(1==this.version)return[];for(var e=Math.floor(this.version/7)+2,t=2*Math.floor((8*this.version+3*e+5)/(4*e-4)),r=[6],n=this.size-7;e>r.length;n-=t)r.splice(1,0,n);return r},t.getNumRawDataModules=function(e){if(t.MIN_VERSION>e||e>t.MAX_VERSION)throw new RangeError("Version number out of range");var r=(16*e+128)*e+64;if(e>=2){var n=Math.floor(e/7)+2;r-=(25*n-10)*n-55,7>e||(r-=36)}return i(r>=208&&29648>=r),r},t.getNumDataCodewords=function(e,r){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[r.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][e]},t.reedSolomonComputeDivisor=function(e){if(1>e||e>255)throw new RangeError("Degree out of range");for(var r=[],n=0;e-1>n;n++)r.push(0);r.push(1);var i=1;for(n=0;e>n;n++){for(var o=0;r.length>o;o++)r[o]=t.reedSolomonMultiply(r[o],i),r.length>o+1&&(r[o]^=r[o+1]);i=t.reedSolomonMultiply(i,2)}return r},t.reedSolomonComputeRemainder=function(e,r){for(var n=r.map(function(e){return 0}),i=function(e){var i=e^n.shift();n.push(0),r.forEach(function(e,r){return n[r]^=t.reedSolomonMultiply(e,i)})},o=0,a=e;a.length>o;o++){i(a[o])}return n},t.reedSolomonMultiply=function(e,t){if(e>>>8!=0||t>>>8!=0)throw new RangeError("Byte out of range");for(var r=0,n=7;n>=0;n--)r=r<<1^285*(r>>>7),r^=(t>>>n&1)*e;return i(r>>>8==0),r},t.prototype.finderPenaltyCountPatterns=function(e){var t=e[1];i(3*this.size>=t);var r=t>0&&e[2]==t&&e[3]==3*t&&e[4]==t&&e[5]==t;return(!r||4*t>e[0]||t>e[6]?0:1)+(!r||4*t>e[6]||t>e[0]?0:1)},t.prototype.finderPenaltyTerminateAndCount=function(e,t,r){return e&&(this.finderPenaltyAddHistory(t,r),t=0),this.finderPenaltyAddHistory(t+=this.size,r),this.finderPenaltyCountPatterns(r)},t.prototype.finderPenaltyAddHistory=function(e,t){0==t[0]&&(e+=this.size),t.pop(),t.unshift(e)},t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],t}();function r(e,t,r){if(0>t||t>31||e>>>t!=0)throw new RangeError("Value out of range");for(var n=t-1;n>=0;n--)r.push(e>>>n&1)}function n(e,t){return!!(e>>>t&1)}function i(e){if(!e)throw Error("Assertion error")}e.QrCode=t;var o=function(){function e(e,t,r){if(this.mode=e,this.numChars=t,this.bitData=r,0>t)throw new RangeError("Invalid argument");this.bitData=r.slice()}return e.makeBytes=function(t){for(var n=[],i=0,o=t;o.length>i;i++){r(o[i],8,n)}return new e(e.Mode.BYTE,t.length,n)},e.makeNumeric=function(t){if(!e.isNumeric(t))throw new RangeError("String contains non-numeric characters");for(var n=[],i=0;t.length>i;){var o=Math.min(t.length-i,3);r(parseInt(t.substring(i,i+o),10),3*o+1,n),i+=o}return new e(e.Mode.NUMERIC,t.length,n)},e.makeAlphanumeric=function(t){if(!e.isAlphanumeric(t))throw new RangeError("String contains unencodable characters in alphanumeric mode");var n,i=[];for(n=0;t.length>=n+2;n+=2){var o=45*e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(n));r(o+=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(n+1)),11,i)}return t.length>n&&r(e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(n)),6,i),new e(e.Mode.ALPHANUMERIC,t.length,i)},e.makeSegments=function(t){return""==t?[]:e.isNumeric(t)?[e.makeNumeric(t)]:e.isAlphanumeric(t)?[e.makeAlphanumeric(t)]:[e.makeBytes(e.toUtf8ByteArray(t))]},e.makeEci=function(t){var n=[];if(0>t)throw new RangeError("ECI assignment value out of range");if(128>t)r(t,8,n);else if(16384>t)r(2,2,n),r(t,14,n);else{if(t>=1e6)throw new RangeError("ECI assignment value out of range");r(6,3,n),r(t,21,n)}return new e(e.Mode.ECI,0,n)},e.isNumeric=function(t){return e.NUMERIC_REGEX.test(t)},e.isAlphanumeric=function(t){return e.ALPHANUMERIC_REGEX.test(t)},e.prototype.getData=function(){return this.bitData.slice()},e.getTotalBits=function(e,t){for(var r=0,n=0,i=e;i.length>n;n++){var o=i[n],a=o.mode.numCharCountBits(t);if(o.numChars>=1<<a)return 1/0;r+=4+a+o.bitData.length}return r},e.toUtf8ByteArray=function(e){e=encodeURI(e);for(var t=[],r=0;e.length>r;r++)"%"!=e.charAt(r)?t.push(e.charCodeAt(r)):(t.push(parseInt(e.substring(r+1,r+3),16)),r+=2);return t},e.NUMERIC_REGEX=/^[0-9]*$/,e.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,e.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",e}();e.QrSegment=o}(r||(r={})),function(e){var t,r;t=e.QrCode||(e.QrCode={}),r=function(){function e(e,t){this.ordinal=e,this.formatBits=t}return e.LOW=new e(0,1),e.MEDIUM=new e(1,0),e.QUARTILE=new e(2,3),e.HIGH=new e(3,2),e}(),t.Ecc=r}(r||(r={})),function(e){var t,r;t=e.QrSegment||(e.QrSegment={}),r=function(){function e(e,t){this.modeBits=e,this.numBitsCharCount=t}return e.prototype.numCharCountBits=function(e){return this.numBitsCharCount[Math.floor((e+7)/17)]},e.NUMERIC=new e(1,[10,12,14]),e.ALPHANUMERIC=new e(2,[9,11,13]),e.BYTE=new e(4,[8,16,16]),e.KANJI=new e(8,[8,10,12]),e.ECI=new e(7,[0,0,0]),e}(),t.Mode=r}(r||(r={}));var i=r,o={L:i.QrCode.Ecc.LOW,M:i.QrCode.Ecc.MEDIUM,Q:i.QrCode.Ecc.QUARTILE,H:i.QrCode.Ecc.HIGH},a=function(){try{(new Path2D).addPath(new Path2D)}catch(e){return!1}return!0}();function u(e){return e in o}function s(e,t){void 0===t&&(t=0);var r="";return e.forEach(function(e,n){var i=null;e.forEach(function(o,a){if(!o&&null!==i)return r+="M".concat(i+t," ").concat(n+t,"h").concat(a-i,"v1H").concat(i+t,"z"),void(i=null);if(a!==e.length-1)o&&null===i&&(i=a);else{if(!o)return;r+=null===i?"M".concat(a+t,",").concat(n+t," h1v1H").concat(a+t,"z"):"M".concat(i+t,",").concat(n+t," h").concat(a+1-i,"v1H").concat(i+t,"z")}})}),r}function l(e){var r=t.computed(function(){var t;return(null!==(t=e.margin)&&void 0!==t?t:0)>>>0}),n=t.computed(function(){var t=u(e.level)?e.level:"L";return i.QrCode.encodeText(e.value,o[t]).getModules()}),a=t.computed(function(){return n.value.length+2*r.value}),l=t.computed(function(){return s(n.value,r.value)}),d=t.computed(function(){if(!e.imageSettings.src)return{x:0,y:0,width:0,height:0,borderRadius:0};var t=function(e,t,r,n){var i=n.width,o=n.height,a=n.x,u=n.y,s=e.length+2*r,l=Math.floor(.1*t),d=s/t,h=(i||l)*d,c=(o||l)*d,f=null==a?e.length/2-h/2:a*d,g=null==u?e.length/2-c/2:u*d,v=(n.borderRadius||0)*d,m=null;if(n.excavate){var p=Math.floor(f),E=Math.floor(g);m={x:p,y:E,w:Math.ceil(h+f-p),h:Math.ceil(c+g-E)}}return{x:f,y:g,h:c,w:h,borderRadius:v,excavation:m}}(n.value,e.size,r.value,e.imageSettings);return{x:t.x+r.value,y:t.y+r.value,width:t.w,height:t.h,borderRadius:t.borderRadius}}),h=t.computed(function(){if(!e.imageSettings.excavate||!e.imageSettings.src)return null;var t=2/(e.size/a.value);return{x:d.value.x-t,y:d.value.y-t,width:d.value.width+2*t,height:d.value.height+2*t,borderRadius:d.value.borderRadius}});return{margin:r,numCells:a,cells:n,fgPath:l,imageProps:d,imageBorderProps:h}}var d={value:{type:String,required:!0,default:""},size:{type:Number,default:100},level:{type:String,default:"L",validator:function(e){return u(e)}},background:{type:String,default:"#fff"},foreground:{type:String,default:"#000"},margin:{type:Number,required:!1,default:0},imageSettings:{type:Object,required:!1,default:function(){return{}}},gradient:{type:Boolean,required:!1,default:!1},gradientType:{type:String,required:!1,default:"linear",validator:function(e){return["linear","radial"].indexOf(e)>-1}},gradientStartColor:{type:String,required:!1,default:"#000"},gradientEndColor:{type:String,required:!1,default:"#fff"}},h=n(n({},d),{renderAs:{type:String,required:!1,default:"canvas",validator:function(e){return["canvas","svg"].indexOf(e)>-1}}}),c=t.defineComponent({name:"QRCodeSvg",props:d,setup:function(e){var r=l(e),i=r.numCells,o=r.fgPath,a=r.imageProps,u=r.imageBorderProps,s="qrcode.vue-gradient",d="qrcode.vue-logo-clip-path";return function(){return t.h("svg",{width:e.size,height:e.size,"shape-rendering":"crispEdges",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 ".concat(i.value," ").concat(i.value)},[t.h("defs",{},[e.gradient?t.h("linear"===e.gradientType?"linearGradient":"radialGradient",n({id:s},"linear"===e.gradientType?{x1:"0%",y1:"0%",x2:"100%",y2:"100%"}:{cx:"50%",cy:"50%",r:"50%",fx:"50%",fy:"50%"}),[t.h("stop",{offset:"0%",style:{stopColor:e.gradientStartColor}}),t.h("stop",{offset:"100%",style:{stopColor:e.gradientEndColor}})]):null,(r=a.value.borderRadius,e.imageSettings.src&&r>0?t.h("clipPath",{id:d},[t.h("rect",{x:a.value.x,y:a.value.y,width:a.value.width,height:a.value.height,rx:r,ry:r})]):null)]),t.h("rect",{width:"100%",height:"100%",fill:e.background}),t.h("path",{fill:e.gradient?"url(#".concat(s,")"):e.foreground,d:o.value}),u.value&&t.h("rect",{x:u.value.x,y:u.value.y,width:u.value.width,height:u.value.height,fill:e.background,rx:u.value.borderRadius,ry:u.value.borderRadius}),e.imageSettings.src&&t.h("image",n(n({href:e.imageSettings.src},a.value),a.value.borderRadius>0?{"clip-path":"url(#".concat(d,")")}:{}))]);var r}}}),f=t.defineComponent({name:"QRCodeCanvas",props:d,setup:function(e,r){var i=l(e),o=i.margin,u=i.cells,d=i.numCells,h=i.imageProps,c=i.imageBorderProps,f=t.ref(null),g=t.ref(null),v=function(){var t=e.size,r=e.background,n=e.foreground,i=e.gradient,l=e.gradientType,v=e.gradientStartColor,m=e.gradientEndColor,p=f.value;if(p){var E=p.getContext("2d");if(E){var y=u.value,w=g.value,C="undefined"!=typeof window&&window.devicePixelRatio||1,M=t/d.value*C;if(p.height=p.width=t*C,E.scale(M,M),E.fillStyle=r,E.fillRect(0,0,d.value,d.value),i){var R=void 0;(R="linear"===l?E.createLinearGradient(0,0,d.value,d.value):E.createRadialGradient(d.value/2,d.value/2,0,d.value/2,d.value/2,d.value/2)).addColorStop(0,v),R.addColorStop(1,m),E.fillStyle=R}else E.fillStyle=n;if(a?E.fill(new Path2D(s(y,o.value))):y.forEach(function(e,t){e.forEach(function(e,r){e&&E.fillRect(r+o.value,t+o.value,1,1)})}),e.imageSettings.src&&w&&0!==w.naturalWidth&&0!==w.naturalHeight){var S=function(e,t,r,n,i,o){e.beginPath(),e.roundRect?e.roundRect(t,r,n,i,o):e.rect(t,r,n,i)};if(c.value){var N=c.value;E.fillStyle=e.background,S(E,N.x,N.y,N.width,N.height,N.borderRadius),E.fill()}var A=h.value.borderRadius;A>0?(E.save(),S(E,h.value.x,h.value.y,h.value.width,h.value.height,A),E.clip(),E.drawImage(w,h.value.x,h.value.y,h.value.width,h.value.height),E.restore()):E.drawImage(w,h.value.x,h.value.y,h.value.width,h.value.height)}}}};t.onMounted(v),t.watchEffect(v);var m=r.attrs.style;return function(){return t.h(t.Fragment,[t.h("canvas",n(n({},r.attrs),{ref:f,style:n(n({},m),{width:"".concat(e.size,"px"),height:"".concat(e.size,"px")})})),e.imageSettings.src&&t.h("img",{ref:g,src:e.imageSettings.src,style:{display:"none"},onLoad:v})])}}}),g=t.defineComponent({name:"Qrcode",render:function(){var e=this.$props;return t.h("svg"===e.renderAs?c:f,{value:e.value,size:e.size,margin:e.margin,level:e.level,background:e.background,foreground:e.foreground,imageSettings:e.imageSettings,gradient:e.gradient,gradientType:e.gradientType,gradientStartColor:e.gradientStartColor,gradientEndColor:e.gradientEndColor})},props:h});e.QrcodeCanvas=f,e.QrcodeSvg=c,e.default=g,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
7
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).QrcodeVue={},e.Vue)}(this,function(e,t){"use strict";var r,n=function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;n>r;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},n.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError,function(e){var t=function(){function t(e,r,n,o){if(this.version=e,this.errorCorrectionLevel=r,this.modules=[],this.isFunction=[],t.MIN_VERSION>e||e>t.MAX_VERSION)throw new RangeError("Version value out of range");if(-1>o||o>7)throw new RangeError("Mask value out of range");this.size=4*e+17;for(var a=[],u=0;this.size>u;u++)a.push(!1);for(u=0;this.size>u;u++)this.modules.push(a.slice()),this.isFunction.push(a.slice());this.drawFunctionPatterns();var s=this.addEccAndInterleave(n);if(this.drawCodewords(s),-1==o){var l=1e9;for(u=0;8>u;u++){this.applyMask(u),this.drawFormatBits(u);var h=this.getPenaltyScore();l>h&&(o=u,l=h),this.applyMask(u)}}i(o>=0&&7>=o),this.mask=o,this.applyMask(o),this.drawFormatBits(o),this.isFunction=[]}return t.encodeText=function(r,n){var i=e.QrSegment.makeSegments(r);return t.encodeSegments(i,n)},t.encodeBinary=function(r,n){var i=e.QrSegment.makeBytes(r);return t.encodeSegments([i],n)},t.encodeSegments=function(e,n,a,u,s,l){if(void 0===a&&(a=1),void 0===u&&(u=40),void 0===s&&(s=-1),void 0===l&&(l=!0),t.MIN_VERSION>a||a>u||u>t.MAX_VERSION||-1>s||s>7)throw new RangeError("Invalid value");var h,d;for(h=a;;h++){var c=8*t.getNumDataCodewords(h,n),f=o.getTotalBits(e,h);if(c>=f){d=f;break}if(h>=u)throw new RangeError("Data too long")}for(var g=0,v=[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH];v.length>g;g++){var m=v[g];l&&d<=8*t.getNumDataCodewords(h,m)&&(n=m)}for(var p=[],y=0,E=e;E.length>y;y++){var w=E[y];r(w.mode.modeBits,4,p),r(w.numChars,w.mode.numCharCountBits(h),p);for(var C=0,M=w.getData();M.length>C;C++){p.push(M[C])}}i(p.length==d);var R=8*t.getNumDataCodewords(h,n);i(R>=p.length),r(0,Math.min(4,R-p.length),p),r(0,(8-p.length%8)%8,p),i(p.length%8==0);for(var S=236;R>p.length;S^=253)r(S,8,p);for(var N=[];p.length>8*N.length;)N.push(0);return p.forEach(function(e,t){return N[t>>>3]|=e<<7-(7&t)}),new t(h,n,N,s)},t.prototype.getModule=function(e,t){return e>=0&&this.size>e&&t>=0&&this.size>t&&this.modules[t][e]},t.prototype.getModules=function(){return this.modules},t.prototype.drawFunctionPatterns=function(){for(var e=0;this.size>e;e++)this.setFunctionModule(6,e,e%2==0),this.setFunctionModule(e,6,e%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);var t=this.getAlignmentPatternPositions(),r=t.length;for(e=0;r>e;e++)for(var n=0;r>n;n++)0==e&&0==n||0==e&&n==r-1||e==r-1&&0==n||this.drawAlignmentPattern(t[e],t[n]);this.drawFormatBits(0),this.drawVersion()},t.prototype.drawFormatBits=function(e){for(var t=this.errorCorrectionLevel.formatBits<<3|e,r=t,o=0;10>o;o++)r=r<<1^1335*(r>>>9);var a=21522^(t<<10|r);i(a>>>15==0);for(o=0;5>=o;o++)this.setFunctionModule(8,o,n(a,o));this.setFunctionModule(8,7,n(a,6)),this.setFunctionModule(8,8,n(a,7)),this.setFunctionModule(7,8,n(a,8));for(o=9;15>o;o++)this.setFunctionModule(14-o,8,n(a,o));for(o=0;8>o;o++)this.setFunctionModule(this.size-1-o,8,n(a,o));for(o=8;15>o;o++)this.setFunctionModule(8,this.size-15+o,n(a,o));this.setFunctionModule(8,this.size-8,!0)},t.prototype.drawVersion=function(){if(this.version>=7){for(var e=this.version,t=0;12>t;t++)e=e<<1^7973*(e>>>11);var r=this.version<<12|e;i(r>>>18==0);for(t=0;18>t;t++){var o=n(r,t),a=this.size-11+t%3,u=Math.floor(t/3);this.setFunctionModule(a,u,o),this.setFunctionModule(u,a,o)}}},t.prototype.drawFinderPattern=function(e,t){for(var r=-4;4>=r;r++)for(var n=-4;4>=n;n++){var i=Math.max(Math.abs(n),Math.abs(r)),o=e+n,a=t+r;o>=0&&this.size>o&&a>=0&&this.size>a&&this.setFunctionModule(o,a,2!=i&&4!=i)}},t.prototype.drawAlignmentPattern=function(e,t){for(var r=-2;2>=r;r++)for(var n=-2;2>=n;n++)this.setFunctionModule(e+n,t+r,1!=Math.max(Math.abs(n),Math.abs(r)))},t.prototype.setFunctionModule=function(e,t,r){this.modules[t][e]=r,this.isFunction[t][e]=!0},t.prototype.addEccAndInterleave=function(e){var r=this.version,n=this.errorCorrectionLevel;if(e.length!=t.getNumDataCodewords(r,n))throw new RangeError("Invalid argument");for(var o=t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][r],a=t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][r],u=Math.floor(t.getNumRawDataModules(r)/8),s=o-u%o,l=Math.floor(u/o),h=[],d=t.reedSolomonComputeDivisor(a),c=0,f=0;o>c;c++){var g=e.slice(f,f+l-a+(s>c?0:1));f+=g.length;var v=t.reedSolomonComputeRemainder(g,d);s>c&&g.push(0),h.push(g.concat(v))}var m=[],p=function(e){h.forEach(function(t,r){e==l-a&&s>r||m.push(t[e])})};for(c=0;h[0].length>c;c++)p(c);return i(m.length==u),m},t.prototype.drawCodewords=function(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");for(var r=0,o=this.size-1;o>=1;o-=2){6==o&&(o=5);for(var a=0;this.size>a;a++)for(var u=0;2>u;u++){var s=o-u,l=!(o+1&2)?this.size-1-a:a;!this.isFunction[l][s]&&8*e.length>r&&(this.modules[l][s]=n(e[r>>>3],7-(7&r)),r++)}}i(r==8*e.length)},t.prototype.applyMask=function(e){if(0>e||e>7)throw new RangeError("Mask value out of range");for(var t=0;this.size>t;t++)for(var r=0;this.size>r;r++){var n=void 0;switch(e){case 0:n=(r+t)%2==0;break;case 1:n=t%2==0;break;case 2:n=r%3==0;break;case 3:n=(r+t)%3==0;break;case 4:n=(Math.floor(r/3)+Math.floor(t/2))%2==0;break;case 5:n=r*t%2+r*t%3==0;break;case 6:n=(r*t%2+r*t%3)%2==0;break;case 7:n=((r+t)%2+r*t%3)%2==0;break;default:throw Error("Unreachable")}!this.isFunction[t][r]&&n&&(this.modules[t][r]=!this.modules[t][r])}},t.prototype.getPenaltyScore=function(){for(var e=0,r=0;this.size>r;r++){for(var n=!1,o=0,a=[0,0,0,0,0,0,0],u=0;this.size>u;u++)this.modules[r][u]==n?5==++o?e+=t.PENALTY_N1:o>5&&e++:(this.finderPenaltyAddHistory(o,a),n||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),n=this.modules[r][u],o=1);e+=this.finderPenaltyTerminateAndCount(n,o,a)*t.PENALTY_N3}for(u=0;this.size>u;u++){n=!1;var s=0;for(a=[0,0,0,0,0,0,0],r=0;this.size>r;r++)this.modules[r][u]==n?5==++s?e+=t.PENALTY_N1:s>5&&e++:(this.finderPenaltyAddHistory(s,a),n||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),n=this.modules[r][u],s=1);e+=this.finderPenaltyTerminateAndCount(n,s,a)*t.PENALTY_N3}for(r=0;this.size-1>r;r++)for(u=0;this.size-1>u;u++){var l=this.modules[r][u];l==this.modules[r][u+1]&&l==this.modules[r+1][u]&&l==this.modules[r+1][u+1]&&(e+=t.PENALTY_N2)}for(var h=0,d=0,c=this.modules;c.length>d;d++){h=c[d].reduce(function(e,t){return e+(t?1:0)},h)}var f=this.size*this.size,g=Math.ceil(Math.abs(20*h-10*f)/f)-1;return i(g>=0&&9>=g),i((e+=g*t.PENALTY_N4)>=0&&2568888>=e),e},t.prototype.getAlignmentPatternPositions=function(){if(1==this.version)return[];for(var e=Math.floor(this.version/7)+2,t=2*Math.floor((8*this.version+3*e+5)/(4*e-4)),r=[6],n=this.size-7;e>r.length;n-=t)r.splice(1,0,n);return r},t.getNumRawDataModules=function(e){if(t.MIN_VERSION>e||e>t.MAX_VERSION)throw new RangeError("Version number out of range");var r=(16*e+128)*e+64;if(e>=2){var n=Math.floor(e/7)+2;r-=(25*n-10)*n-55,7>e||(r-=36)}return i(r>=208&&29648>=r),r},t.getNumDataCodewords=function(e,r){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[r.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][e]},t.reedSolomonComputeDivisor=function(e){if(1>e||e>255)throw new RangeError("Degree out of range");for(var r=[],n=0;e-1>n;n++)r.push(0);r.push(1);var i=1;for(n=0;e>n;n++){for(var o=0;r.length>o;o++)r[o]=t.reedSolomonMultiply(r[o],i),r.length>o+1&&(r[o]^=r[o+1]);i=t.reedSolomonMultiply(i,2)}return r},t.reedSolomonComputeRemainder=function(e,r){for(var n=r.map(function(e){return 0}),i=function(e){var i=e^n.shift();n.push(0),r.forEach(function(e,r){return n[r]^=t.reedSolomonMultiply(e,i)})},o=0,a=e;a.length>o;o++){i(a[o])}return n},t.reedSolomonMultiply=function(e,t){if(e>>>8!=0||t>>>8!=0)throw new RangeError("Byte out of range");for(var r=0,n=7;n>=0;n--)r=r<<1^285*(r>>>7),r^=(t>>>n&1)*e;return i(r>>>8==0),r},t.prototype.finderPenaltyCountPatterns=function(e){var t=e[1];i(3*this.size>=t);var r=t>0&&e[2]==t&&e[3]==3*t&&e[4]==t&&e[5]==t;return(!r||4*t>e[0]||t>e[6]?0:1)+(!r||4*t>e[6]||t>e[0]?0:1)},t.prototype.finderPenaltyTerminateAndCount=function(e,t,r){return e&&(this.finderPenaltyAddHistory(t,r),t=0),this.finderPenaltyAddHistory(t+=this.size,r),this.finderPenaltyCountPatterns(r)},t.prototype.finderPenaltyAddHistory=function(e,t){0==t[0]&&(e+=this.size),t.pop(),t.unshift(e)},t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],t}();function r(e,t,r){if(0>t||t>31||e>>>t!=0)throw new RangeError("Value out of range");for(var n=t-1;n>=0;n--)r.push(e>>>n&1)}function n(e,t){return!!(e>>>t&1)}function i(e){if(!e)throw Error("Assertion error")}e.QrCode=t;var o=function(){function e(e,t,r){if(this.mode=e,this.numChars=t,this.bitData=r,0>t)throw new RangeError("Invalid argument");this.bitData=r.slice()}return e.makeBytes=function(t){for(var n=[],i=0,o=t;o.length>i;i++){r(o[i],8,n)}return new e(e.Mode.BYTE,t.length,n)},e.makeNumeric=function(t){if(!e.isNumeric(t))throw new RangeError("String contains non-numeric characters");for(var n=[],i=0;t.length>i;){var o=Math.min(t.length-i,3);r(parseInt(t.substring(i,i+o),10),3*o+1,n),i+=o}return new e(e.Mode.NUMERIC,t.length,n)},e.makeAlphanumeric=function(t){if(!e.isAlphanumeric(t))throw new RangeError("String contains unencodable characters in alphanumeric mode");var n,i=[];for(n=0;t.length>=n+2;n+=2){var o=45*e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(n));r(o+=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(n+1)),11,i)}return t.length>n&&r(e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(n)),6,i),new e(e.Mode.ALPHANUMERIC,t.length,i)},e.makeSegments=function(t){return""==t?[]:e.isNumeric(t)?[e.makeNumeric(t)]:e.isAlphanumeric(t)?[e.makeAlphanumeric(t)]:[e.makeBytes(e.toUtf8ByteArray(t))]},e.makeEci=function(t){var n=[];if(0>t)throw new RangeError("ECI assignment value out of range");if(128>t)r(t,8,n);else if(16384>t)r(2,2,n),r(t,14,n);else{if(t>=1e6)throw new RangeError("ECI assignment value out of range");r(6,3,n),r(t,21,n)}return new e(e.Mode.ECI,0,n)},e.isNumeric=function(t){return e.NUMERIC_REGEX.test(t)},e.isAlphanumeric=function(t){return e.ALPHANUMERIC_REGEX.test(t)},e.prototype.getData=function(){return this.bitData.slice()},e.getTotalBits=function(e,t){for(var r=0,n=0,i=e;i.length>n;n++){var o=i[n],a=o.mode.numCharCountBits(t);if(o.numChars>=1<<a)return 1/0;r+=4+a+o.bitData.length}return r},e.toUtf8ByteArray=function(e){e=encodeURI(e);for(var t=[],r=0;e.length>r;r++)"%"!=e.charAt(r)?t.push(e.charCodeAt(r)):(t.push(parseInt(e.substring(r+1,r+3),16)),r+=2);return t},e.NUMERIC_REGEX=/^[0-9]*$/,e.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,e.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",e}();e.QrSegment=o}(r||(r={})),function(e){var t,r;t=e.QrCode||(e.QrCode={}),r=function(){function e(e,t){this.ordinal=e,this.formatBits=t}return e.LOW=new e(0,1),e.MEDIUM=new e(1,0),e.QUARTILE=new e(2,3),e.HIGH=new e(3,2),e}(),t.Ecc=r}(r||(r={})),function(e){var t,r;t=e.QrSegment||(e.QrSegment={}),r=function(){function e(e,t){this.modeBits=e,this.numBitsCharCount=t}return e.prototype.numCharCountBits=function(e){return this.numBitsCharCount[Math.floor((e+7)/17)]},e.NUMERIC=new e(1,[10,12,14]),e.ALPHANUMERIC=new e(2,[9,11,13]),e.BYTE=new e(4,[8,16,16]),e.KANJI=new e(8,[8,10,12]),e.ECI=new e(7,[0,0,0]),e}(),t.Mode=r}(r||(r={}));var i=r,o=0,a={L:i.QrCode.Ecc.LOW,M:i.QrCode.Ecc.MEDIUM,Q:i.QrCode.Ecc.QUARTILE,H:i.QrCode.Ecc.HIGH},u=function(){try{(new Path2D).addPath(new Path2D)}catch(e){return!1}return!0}();function s(e){return e in a}function l(e){var r=t.computed(function(){var t;return(null!==(t=e.margin)&&void 0!==t?t:0)>>>0}),n=t.computed(function(){var t=s(e.level)?e.level:"L";return i.QrCode.encodeText(e.value,a[t]).getModules()}),o=t.computed(function(){return n.value.length+2*r.value}),u=t.computed(function(){return function(e,t){void 0===t&&(t=0);for(var r=[],n=0;e.length>n;n++)for(var i=e[n],o=null,a=0;i.length>a;a++){var u=i[a];if(u||null===o)if(a!==i.length-1)u&&null===o&&(o=a);else{if(!u)continue;r.push(null===o?"M".concat(a+t,",").concat(n+t," h1v1H").concat(a+t,"z"):"M".concat(o+t,",").concat(n+t," h").concat(a+1-o,"v1H").concat(o+t,"z"))}else r.push("M".concat(o+t," ").concat(n+t,"h").concat(a-o,"v1H").concat(o+t,"z")),o=null}return r.join("")}(n.value,r.value)}),l=t.computed(function(){if(!e.imageSettings.src)return{x:0,y:0,width:0,height:0,borderRadius:0};var t=function(e,t,r,n){var i=n.width,o=n.height,a=n.x,u=n.y,s=e.length+2*r,l=Math.floor(.1*t),h=s/t,d=(i||l)*h,c=(o||l)*h,f=null==a?e.length/2-d/2:a*h,g=null==u?e.length/2-c/2:u*h,v=(n.borderRadius||0)*h,m=null;if(n.excavate){var p=Math.floor(f),y=Math.floor(g);m={x:p,y:y,w:Math.ceil(d+f-p),h:Math.ceil(c+g-y)}}return{x:f,y:g,h:c,w:d,borderRadius:v,excavation:m}}(n.value,e.size,r.value,e.imageSettings);return{x:t.x+r.value,y:t.y+r.value,width:t.w,height:t.h,borderRadius:t.borderRadius}}),h=t.computed(function(){if(!e.imageSettings.excavate||!e.imageSettings.src)return null;var t=2/(e.size/o.value);return{x:l.value.x-t,y:l.value.y-t,width:l.value.width+2*t,height:l.value.height+2*t,borderRadius:l.value.borderRadius}});return{margin:r,numCells:o,cells:n,fgPath:u,imageProps:l,imageBorderProps:h}}var h={value:{type:String,required:!0,default:""},size:{type:Number,default:100},level:{type:String,default:"L",validator:function(e){return s(e)}},background:{type:String,default:"#fff"},foreground:{type:String,default:"#000"},margin:{type:Number,required:!1,default:0},imageSettings:{type:Object,required:!1,default:function(){return{}}},gradient:{type:Boolean,required:!1,default:!1},gradientType:{type:String,required:!1,default:"linear",validator:function(e){return["linear","radial"].indexOf(e)>-1}},gradientStartColor:{type:String,required:!1,default:"#000"},gradientEndColor:{type:String,required:!1,default:"#fff"}},d=n(n({},h),{renderAs:{type:String,required:!1,default:"canvas",validator:function(e){return["canvas","svg"].indexOf(e)>-1}}}),c=t.defineComponent({name:"QRCodeSvg",props:h,setup:function(e){var r=l(e),i=r.numCells,a=r.fgPath,u=r.imageProps,s=r.imageBorderProps,h=o++,d="qrcode.vue-gradient-".concat(h),c="qrcode.vue-logo-clip-path-".concat(h);return function(){return t.h("svg",{width:e.size,height:e.size,"shape-rendering":"crispEdges",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 ".concat(i.value," ").concat(i.value),role:"img","aria-label":e.value},[t.h("defs",{},[e.gradient?t.h("linear"===e.gradientType?"linearGradient":"radialGradient",n({id:d},"linear"===e.gradientType?{x1:"0%",y1:"0%",x2:"100%",y2:"100%"}:{cx:"50%",cy:"50%",r:"50%",fx:"50%",fy:"50%"}),[t.h("stop",{offset:"0%",style:{stopColor:e.gradientStartColor}}),t.h("stop",{offset:"100%",style:{stopColor:e.gradientEndColor}})]):null,(r=u.value.borderRadius,e.imageSettings.src&&r>0?t.h("clipPath",{id:c},[t.h("rect",{x:u.value.x,y:u.value.y,width:u.value.width,height:u.value.height,rx:r,ry:r})]):null)]),t.h("rect",{width:"100%",height:"100%",fill:e.background}),t.h("path",{fill:e.gradient?"url(#".concat(d,")"):e.foreground,d:a.value}),s.value&&t.h("rect",{x:s.value.x,y:s.value.y,width:s.value.width,height:s.value.height,fill:e.background,rx:s.value.borderRadius,ry:s.value.borderRadius}),e.imageSettings.src&&t.h("image",n(n({href:e.imageSettings.src},u.value),u.value.borderRadius>0?{"clip-path":"url(#".concat(c,")")}:{}))]);var r}}}),f=t.defineComponent({name:"QRCodeCanvas",props:h,setup:function(e,r){var i=l(e),o=i.margin,a=i.cells,s=i.numCells,h=i.fgPath,d=i.imageProps,c=i.imageBorderProps,f=t.ref(null),g=t.ref(null),v=function(e,t,r,n,i,o){e.beginPath(),e.roundRect?e.roundRect(t,r,n,i,o):e.rect(t,r,n,i)},m=function(){var t=e.size,r=e.background,n=e.foreground,i=e.gradient,l=e.gradientType,m=e.gradientStartColor,p=e.gradientEndColor,y=f.value;if(y){var E=y.getContext("2d");if(E){var w=g.value,C="undefined"!=typeof window&&window.devicePixelRatio||1,M=t/s.value*C;if(y.height=y.width=t*C,E.scale(M,M),E.fillStyle=r,E.fillRect(0,0,s.value,s.value),i){var R=void 0;(R="linear"===l?E.createLinearGradient(0,0,s.value,s.value):E.createRadialGradient(s.value/2,s.value/2,0,s.value/2,s.value/2,s.value/2)).addColorStop(0,m),R.addColorStop(1,p),E.fillStyle=R}else E.fillStyle=n;if(u?E.fill(new Path2D(h.value)):a.value.forEach(function(e,t){e.forEach(function(e,r){e&&E.fillRect(r+o.value,t+o.value,1,1)})}),e.imageSettings.src&&w&&0!==w.naturalWidth&&0!==w.naturalHeight){if(c.value){var S=c.value;E.fillStyle=e.background,v(E,S.x,S.y,S.width,S.height,S.borderRadius),E.fill()}var N=d.value.borderRadius;N>0?(E.save(),v(E,d.value.x,d.value.y,d.value.width,d.value.height,N),E.clip(),E.drawImage(w,d.value.x,d.value.y,d.value.width,d.value.height),E.restore()):E.drawImage(w,d.value.x,d.value.y,d.value.width,d.value.height)}}}};t.onMounted(m),t.watchEffect(m);var p=r.attrs.style;return function(){return t.h(t.Fragment,[t.h("canvas",n(n({},r.attrs),{ref:f,role:"img","aria-label":e.value,style:n(n({},p),{width:"".concat(e.size,"px"),height:"".concat(e.size,"px")})})),e.imageSettings.src&&t.h("img",{ref:g,src:e.imageSettings.src,style:{display:"none"},onLoad:m})])}}}),g=t.defineComponent({name:"Qrcode",props:d,setup:function(e){return function(){return t.h("svg"===e.renderAs?c:f,{value:e.value,size:e.size,margin:e.margin,level:e.level,background:e.background,foreground:e.foreground,imageSettings:e.imageSettings,gradient:e.gradient,gradientType:e.gradientType,gradientStartColor:e.gradientStartColor,gradientEndColor:e.gradientEndColor})}}});e.QrcodeCanvas=f,e.QrcodeSvg=c,e.default=g,Object.defineProperty(e,"__esModule",{value:!0})});
|
package/dist/qrcode.vue.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* qrcode.vue v3.8.
|
|
2
|
+
* qrcode.vue v3.8.1
|
|
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.
|
|
@@ -909,6 +909,7 @@ var qrcodegen;
|
|
|
909
909
|
})(qrcodegen || (qrcodegen = {}));
|
|
910
910
|
var QR = qrcodegen;
|
|
911
911
|
|
|
912
|
+
var _uid = 0;
|
|
912
913
|
var defaultErrorCorrectLevel = 'L';
|
|
913
914
|
var DEFAULT_QR_SIZE = 100;
|
|
914
915
|
var DEFAULT_MARGIN = 0;
|
|
@@ -935,40 +936,41 @@ function validErrorCorrectLevel(level) {
|
|
|
935
936
|
}
|
|
936
937
|
function generatePath(modules, margin) {
|
|
937
938
|
if (margin === void 0) { margin = 0; }
|
|
938
|
-
var
|
|
939
|
-
|
|
939
|
+
var pathSegments = [];
|
|
940
|
+
for (var y = 0; y < modules.length; y++) {
|
|
941
|
+
var row = modules[y];
|
|
940
942
|
var start = null;
|
|
941
|
-
|
|
943
|
+
for (var x = 0; x < row.length; x++) {
|
|
944
|
+
var cell = row[x];
|
|
942
945
|
if (!cell && start !== null) {
|
|
943
946
|
// M0 0h7v1H0z injects the space with the move and drops the comma,
|
|
944
|
-
|
|
945
|
-
path += "M".concat(start + margin, " ").concat(y + margin, "h").concat(x - start, "v1H").concat(start + margin, "z");
|
|
947
|
+
pathSegments.push("M".concat(start + margin, " ").concat(y + margin, "h").concat(x - start, "v1H").concat(start + margin, "z"));
|
|
946
948
|
start = null;
|
|
947
|
-
|
|
949
|
+
continue;
|
|
948
950
|
}
|
|
949
951
|
// end of row, clean up or skip
|
|
950
952
|
if (x === row.length - 1) {
|
|
951
953
|
if (!cell) {
|
|
952
954
|
// We would have closed the op above already so this can only mean
|
|
953
955
|
// 2+ light modules in a row.
|
|
954
|
-
|
|
956
|
+
continue;
|
|
955
957
|
}
|
|
956
958
|
if (start === null) {
|
|
957
959
|
// Just a single dark module.
|
|
958
|
-
|
|
960
|
+
pathSegments.push("M".concat(x + margin, ",").concat(y + margin, " h1v1H").concat(x + margin, "z"));
|
|
959
961
|
}
|
|
960
962
|
else {
|
|
961
963
|
// Otherwise finish the current line.
|
|
962
|
-
|
|
964
|
+
pathSegments.push("M".concat(start + margin, ",").concat(y + margin, " h").concat(x + 1 - start, "v1H").concat(start + margin, "z"));
|
|
963
965
|
}
|
|
964
|
-
|
|
966
|
+
continue;
|
|
965
967
|
}
|
|
966
968
|
if (cell && start === null) {
|
|
967
969
|
start = x;
|
|
968
970
|
}
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
return
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
return pathSegments.join('');
|
|
972
974
|
}
|
|
973
975
|
function getImageSettings(cells, size, margin, imageSettings) {
|
|
974
976
|
var width = imageSettings.width, height = imageSettings.height, imageX = imageSettings.x, imageY = imageSettings.y;
|
|
@@ -1091,7 +1093,9 @@ var QrcodeSvg = vue.defineComponent({
|
|
|
1091
1093
|
props: QRCodeProps,
|
|
1092
1094
|
setup: function (props) {
|
|
1093
1095
|
var _a = useQRCode(props), numCells = _a.numCells, fgPath = _a.fgPath, imageProps = _a.imageProps, imageBorderProps = _a.imageBorderProps;
|
|
1094
|
-
var
|
|
1096
|
+
var uid = _uid++;
|
|
1097
|
+
var qrGradientId = "qrcode.vue-gradient-".concat(uid);
|
|
1098
|
+
var qrLogoClipPathId = "qrcode.vue-logo-clip-path-".concat(uid);
|
|
1095
1099
|
var renderGradient = function () {
|
|
1096
1100
|
if (!props.gradient)
|
|
1097
1101
|
return null;
|
|
@@ -1120,7 +1124,6 @@ var QrcodeSvg = vue.defineComponent({
|
|
|
1120
1124
|
}),
|
|
1121
1125
|
]);
|
|
1122
1126
|
};
|
|
1123
|
-
var qrLogoClipPathId = 'qrcode.vue-logo-clip-path';
|
|
1124
1127
|
var renderClipPath = function () {
|
|
1125
1128
|
var borderRadius = imageProps.value.borderRadius;
|
|
1126
1129
|
if (!props.imageSettings.src)
|
|
@@ -1144,6 +1147,8 @@ var QrcodeSvg = vue.defineComponent({
|
|
|
1144
1147
|
'shape-rendering': "crispEdges",
|
|
1145
1148
|
xmlns: 'http://www.w3.org/2000/svg',
|
|
1146
1149
|
viewBox: "0 0 ".concat(numCells.value, " ").concat(numCells.value),
|
|
1150
|
+
role: 'img',
|
|
1151
|
+
'aria-label': props.value,
|
|
1147
1152
|
}, [
|
|
1148
1153
|
vue.h('defs', {}, [renderGradient(), renderClipPath()]),
|
|
1149
1154
|
vue.h('rect', {
|
|
@@ -1172,9 +1177,18 @@ var QrcodeCanvas = vue.defineComponent({
|
|
|
1172
1177
|
name: 'QRCodeCanvas',
|
|
1173
1178
|
props: QRCodeProps,
|
|
1174
1179
|
setup: function (props, ctx) {
|
|
1175
|
-
var _a = useQRCode(props), margin = _a.margin, cells = _a.cells, numCells = _a.numCells, imageProps = _a.imageProps, imageBorderProps = _a.imageBorderProps;
|
|
1180
|
+
var _a = useQRCode(props), margin = _a.margin, cells = _a.cells, numCells = _a.numCells, fgPath = _a.fgPath, imageProps = _a.imageProps, imageBorderProps = _a.imageBorderProps;
|
|
1176
1181
|
var canvasEl = vue.ref(null);
|
|
1177
1182
|
var imageRef = vue.ref(null);
|
|
1183
|
+
var drawRoundedRect = function (ctx, x, y, width, height, radius) {
|
|
1184
|
+
ctx.beginPath();
|
|
1185
|
+
if (ctx.roundRect) {
|
|
1186
|
+
ctx.roundRect(x, y, width, height, radius);
|
|
1187
|
+
}
|
|
1188
|
+
else {
|
|
1189
|
+
ctx.rect(x, y, width, height);
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1178
1192
|
var generate = function () {
|
|
1179
1193
|
var size = props.size, background = props.background, foreground = props.foreground, gradient = props.gradient, gradientType = props.gradientType, gradientStartColor = props.gradientStartColor, gradientEndColor = props.gradientEndColor;
|
|
1180
1194
|
var canvas = canvasEl.value;
|
|
@@ -1185,7 +1199,6 @@ var QrcodeCanvas = vue.defineComponent({
|
|
|
1185
1199
|
if (!canvasCtx) {
|
|
1186
1200
|
return;
|
|
1187
1201
|
}
|
|
1188
|
-
var qrCells = cells.value;
|
|
1189
1202
|
var image = imageRef.value;
|
|
1190
1203
|
var devicePixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;
|
|
1191
1204
|
var scale = (size / numCells.value) * devicePixelRatio;
|
|
@@ -1209,10 +1222,10 @@ var QrcodeCanvas = vue.defineComponent({
|
|
|
1209
1222
|
canvasCtx.fillStyle = foreground;
|
|
1210
1223
|
}
|
|
1211
1224
|
if (SUPPORTS_PATH2D) {
|
|
1212
|
-
canvasCtx.fill(new Path2D(
|
|
1225
|
+
canvasCtx.fill(new Path2D(fgPath.value));
|
|
1213
1226
|
}
|
|
1214
1227
|
else {
|
|
1215
|
-
|
|
1228
|
+
cells.value.forEach(function (row, rdx) {
|
|
1216
1229
|
row.forEach(function (cell, cdx) {
|
|
1217
1230
|
if (cell) {
|
|
1218
1231
|
canvasCtx.fillRect(cdx + margin.value, rdx + margin.value, 1, 1);
|
|
@@ -1222,15 +1235,6 @@ var QrcodeCanvas = vue.defineComponent({
|
|
|
1222
1235
|
}
|
|
1223
1236
|
var showImage = props.imageSettings.src && image && image.naturalWidth !== 0 && image.naturalHeight !== 0;
|
|
1224
1237
|
if (showImage) {
|
|
1225
|
-
var drawRoundedRect = function (ctx, x, y, width, height, radius) {
|
|
1226
|
-
ctx.beginPath();
|
|
1227
|
-
if (ctx.roundRect) {
|
|
1228
|
-
ctx.roundRect(x, y, width, height, radius);
|
|
1229
|
-
}
|
|
1230
|
-
else {
|
|
1231
|
-
ctx.rect(x, y, width, height);
|
|
1232
|
-
}
|
|
1233
|
-
};
|
|
1234
1238
|
if (imageBorderProps.value) {
|
|
1235
1239
|
var imageBorder = imageBorderProps.value;
|
|
1236
1240
|
canvasCtx.fillStyle = props.background;
|
|
@@ -1254,7 +1258,7 @@ var QrcodeCanvas = vue.defineComponent({
|
|
|
1254
1258
|
vue.watchEffect(generate);
|
|
1255
1259
|
var style = ctx.attrs.style;
|
|
1256
1260
|
return function () { return vue.h(vue.Fragment, [
|
|
1257
|
-
vue.h('canvas', __assign(__assign({}, ctx.attrs), { ref: canvasEl, style: __assign(__assign({}, style), { width: "".concat(props.size, "px"), height: "".concat(props.size, "px") }) })),
|
|
1261
|
+
vue.h('canvas', __assign(__assign({}, ctx.attrs), { ref: canvasEl, role: 'img', 'aria-label': props.value, style: __assign(__assign({}, style), { width: "".concat(props.size, "px"), height: "".concat(props.size, "px") }) })),
|
|
1258
1262
|
props.imageSettings.src && vue.h('img', {
|
|
1259
1263
|
ref: imageRef,
|
|
1260
1264
|
src: props.imageSettings.src,
|
|
@@ -1266,23 +1270,22 @@ var QrcodeCanvas = vue.defineComponent({
|
|
|
1266
1270
|
});
|
|
1267
1271
|
var QrcodeVue = vue.defineComponent({
|
|
1268
1272
|
name: 'Qrcode',
|
|
1269
|
-
render: function () {
|
|
1270
|
-
var _a = this.$props, renderAs = _a.renderAs, value = _a.value, size = _a.size, margin = _a.margin, level = _a.level, background = _a.background, foreground = _a.foreground, imageSettings = _a.imageSettings, gradient = _a.gradient, gradientType = _a.gradientType, gradientStartColor = _a.gradientStartColor, gradientEndColor = _a.gradientEndColor;
|
|
1271
|
-
return vue.h(renderAs === 'svg' ? QrcodeSvg : QrcodeCanvas, {
|
|
1272
|
-
value: value,
|
|
1273
|
-
size: size,
|
|
1274
|
-
margin: margin,
|
|
1275
|
-
level: level,
|
|
1276
|
-
background: background,
|
|
1277
|
-
foreground: foreground,
|
|
1278
|
-
imageSettings: imageSettings,
|
|
1279
|
-
gradient: gradient,
|
|
1280
|
-
gradientType: gradientType,
|
|
1281
|
-
gradientStartColor: gradientStartColor,
|
|
1282
|
-
gradientEndColor: gradientEndColor,
|
|
1283
|
-
});
|
|
1284
|
-
},
|
|
1285
1273
|
props: QRCodeVueProps,
|
|
1274
|
+
setup: function (props) {
|
|
1275
|
+
return function () { return vue.h(props.renderAs === 'svg' ? QrcodeSvg : QrcodeCanvas, {
|
|
1276
|
+
value: props.value,
|
|
1277
|
+
size: props.size,
|
|
1278
|
+
margin: props.margin,
|
|
1279
|
+
level: props.level,
|
|
1280
|
+
background: props.background,
|
|
1281
|
+
foreground: props.foreground,
|
|
1282
|
+
imageSettings: props.imageSettings,
|
|
1283
|
+
gradient: props.gradient,
|
|
1284
|
+
gradientType: props.gradientType,
|
|
1285
|
+
gradientStartColor: props.gradientStartColor,
|
|
1286
|
+
gradientEndColor: props.gradientEndColor,
|
|
1287
|
+
}); };
|
|
1288
|
+
},
|
|
1286
1289
|
});
|
|
1287
1290
|
|
|
1288
1291
|
exports.QrcodeCanvas = QrcodeCanvas;
|
package/dist/qrcode.vue.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* qrcode.vue v3.8.
|
|
2
|
+
* qrcode.vue v3.8.1
|
|
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.
|
|
@@ -905,6 +905,7 @@ var qrcodegen;
|
|
|
905
905
|
})(qrcodegen || (qrcodegen = {}));
|
|
906
906
|
var QR = qrcodegen;
|
|
907
907
|
|
|
908
|
+
var _uid = 0;
|
|
908
909
|
var defaultErrorCorrectLevel = 'L';
|
|
909
910
|
var DEFAULT_QR_SIZE = 100;
|
|
910
911
|
var DEFAULT_MARGIN = 0;
|
|
@@ -931,40 +932,41 @@ function validErrorCorrectLevel(level) {
|
|
|
931
932
|
}
|
|
932
933
|
function generatePath(modules, margin) {
|
|
933
934
|
if (margin === void 0) { margin = 0; }
|
|
934
|
-
var
|
|
935
|
-
|
|
935
|
+
var pathSegments = [];
|
|
936
|
+
for (var y = 0; y < modules.length; y++) {
|
|
937
|
+
var row = modules[y];
|
|
936
938
|
var start = null;
|
|
937
|
-
|
|
939
|
+
for (var x = 0; x < row.length; x++) {
|
|
940
|
+
var cell = row[x];
|
|
938
941
|
if (!cell && start !== null) {
|
|
939
942
|
// M0 0h7v1H0z injects the space with the move and drops the comma,
|
|
940
|
-
|
|
941
|
-
path += "M".concat(start + margin, " ").concat(y + margin, "h").concat(x - start, "v1H").concat(start + margin, "z");
|
|
943
|
+
pathSegments.push("M".concat(start + margin, " ").concat(y + margin, "h").concat(x - start, "v1H").concat(start + margin, "z"));
|
|
942
944
|
start = null;
|
|
943
|
-
|
|
945
|
+
continue;
|
|
944
946
|
}
|
|
945
947
|
// end of row, clean up or skip
|
|
946
948
|
if (x === row.length - 1) {
|
|
947
949
|
if (!cell) {
|
|
948
950
|
// We would have closed the op above already so this can only mean
|
|
949
951
|
// 2+ light modules in a row.
|
|
950
|
-
|
|
952
|
+
continue;
|
|
951
953
|
}
|
|
952
954
|
if (start === null) {
|
|
953
955
|
// Just a single dark module.
|
|
954
|
-
|
|
956
|
+
pathSegments.push("M".concat(x + margin, ",").concat(y + margin, " h1v1H").concat(x + margin, "z"));
|
|
955
957
|
}
|
|
956
958
|
else {
|
|
957
959
|
// Otherwise finish the current line.
|
|
958
|
-
|
|
960
|
+
pathSegments.push("M".concat(start + margin, ",").concat(y + margin, " h").concat(x + 1 - start, "v1H").concat(start + margin, "z"));
|
|
959
961
|
}
|
|
960
|
-
|
|
962
|
+
continue;
|
|
961
963
|
}
|
|
962
964
|
if (cell && start === null) {
|
|
963
965
|
start = x;
|
|
964
966
|
}
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
return
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
return pathSegments.join('');
|
|
968
970
|
}
|
|
969
971
|
function getImageSettings(cells, size, margin, imageSettings) {
|
|
970
972
|
var width = imageSettings.width, height = imageSettings.height, imageX = imageSettings.x, imageY = imageSettings.y;
|
|
@@ -1087,7 +1089,9 @@ var QrcodeSvg = defineComponent({
|
|
|
1087
1089
|
props: QRCodeProps,
|
|
1088
1090
|
setup: function (props) {
|
|
1089
1091
|
var _a = useQRCode(props), numCells = _a.numCells, fgPath = _a.fgPath, imageProps = _a.imageProps, imageBorderProps = _a.imageBorderProps;
|
|
1090
|
-
var
|
|
1092
|
+
var uid = _uid++;
|
|
1093
|
+
var qrGradientId = "qrcode.vue-gradient-".concat(uid);
|
|
1094
|
+
var qrLogoClipPathId = "qrcode.vue-logo-clip-path-".concat(uid);
|
|
1091
1095
|
var renderGradient = function () {
|
|
1092
1096
|
if (!props.gradient)
|
|
1093
1097
|
return null;
|
|
@@ -1116,7 +1120,6 @@ var QrcodeSvg = defineComponent({
|
|
|
1116
1120
|
}),
|
|
1117
1121
|
]);
|
|
1118
1122
|
};
|
|
1119
|
-
var qrLogoClipPathId = 'qrcode.vue-logo-clip-path';
|
|
1120
1123
|
var renderClipPath = function () {
|
|
1121
1124
|
var borderRadius = imageProps.value.borderRadius;
|
|
1122
1125
|
if (!props.imageSettings.src)
|
|
@@ -1140,6 +1143,8 @@ var QrcodeSvg = defineComponent({
|
|
|
1140
1143
|
'shape-rendering': "crispEdges",
|
|
1141
1144
|
xmlns: 'http://www.w3.org/2000/svg',
|
|
1142
1145
|
viewBox: "0 0 ".concat(numCells.value, " ").concat(numCells.value),
|
|
1146
|
+
role: 'img',
|
|
1147
|
+
'aria-label': props.value,
|
|
1143
1148
|
}, [
|
|
1144
1149
|
h('defs', {}, [renderGradient(), renderClipPath()]),
|
|
1145
1150
|
h('rect', {
|
|
@@ -1168,9 +1173,18 @@ var QrcodeCanvas = defineComponent({
|
|
|
1168
1173
|
name: 'QRCodeCanvas',
|
|
1169
1174
|
props: QRCodeProps,
|
|
1170
1175
|
setup: function (props, ctx) {
|
|
1171
|
-
var _a = useQRCode(props), margin = _a.margin, cells = _a.cells, numCells = _a.numCells, imageProps = _a.imageProps, imageBorderProps = _a.imageBorderProps;
|
|
1176
|
+
var _a = useQRCode(props), margin = _a.margin, cells = _a.cells, numCells = _a.numCells, fgPath = _a.fgPath, imageProps = _a.imageProps, imageBorderProps = _a.imageBorderProps;
|
|
1172
1177
|
var canvasEl = ref(null);
|
|
1173
1178
|
var imageRef = ref(null);
|
|
1179
|
+
var drawRoundedRect = function (ctx, x, y, width, height, radius) {
|
|
1180
|
+
ctx.beginPath();
|
|
1181
|
+
if (ctx.roundRect) {
|
|
1182
|
+
ctx.roundRect(x, y, width, height, radius);
|
|
1183
|
+
}
|
|
1184
|
+
else {
|
|
1185
|
+
ctx.rect(x, y, width, height);
|
|
1186
|
+
}
|
|
1187
|
+
};
|
|
1174
1188
|
var generate = function () {
|
|
1175
1189
|
var size = props.size, background = props.background, foreground = props.foreground, gradient = props.gradient, gradientType = props.gradientType, gradientStartColor = props.gradientStartColor, gradientEndColor = props.gradientEndColor;
|
|
1176
1190
|
var canvas = canvasEl.value;
|
|
@@ -1181,7 +1195,6 @@ var QrcodeCanvas = defineComponent({
|
|
|
1181
1195
|
if (!canvasCtx) {
|
|
1182
1196
|
return;
|
|
1183
1197
|
}
|
|
1184
|
-
var qrCells = cells.value;
|
|
1185
1198
|
var image = imageRef.value;
|
|
1186
1199
|
var devicePixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;
|
|
1187
1200
|
var scale = (size / numCells.value) * devicePixelRatio;
|
|
@@ -1205,10 +1218,10 @@ var QrcodeCanvas = defineComponent({
|
|
|
1205
1218
|
canvasCtx.fillStyle = foreground;
|
|
1206
1219
|
}
|
|
1207
1220
|
if (SUPPORTS_PATH2D) {
|
|
1208
|
-
canvasCtx.fill(new Path2D(
|
|
1221
|
+
canvasCtx.fill(new Path2D(fgPath.value));
|
|
1209
1222
|
}
|
|
1210
1223
|
else {
|
|
1211
|
-
|
|
1224
|
+
cells.value.forEach(function (row, rdx) {
|
|
1212
1225
|
row.forEach(function (cell, cdx) {
|
|
1213
1226
|
if (cell) {
|
|
1214
1227
|
canvasCtx.fillRect(cdx + margin.value, rdx + margin.value, 1, 1);
|
|
@@ -1218,15 +1231,6 @@ var QrcodeCanvas = defineComponent({
|
|
|
1218
1231
|
}
|
|
1219
1232
|
var showImage = props.imageSettings.src && image && image.naturalWidth !== 0 && image.naturalHeight !== 0;
|
|
1220
1233
|
if (showImage) {
|
|
1221
|
-
var drawRoundedRect = function (ctx, x, y, width, height, radius) {
|
|
1222
|
-
ctx.beginPath();
|
|
1223
|
-
if (ctx.roundRect) {
|
|
1224
|
-
ctx.roundRect(x, y, width, height, radius);
|
|
1225
|
-
}
|
|
1226
|
-
else {
|
|
1227
|
-
ctx.rect(x, y, width, height);
|
|
1228
|
-
}
|
|
1229
|
-
};
|
|
1230
1234
|
if (imageBorderProps.value) {
|
|
1231
1235
|
var imageBorder = imageBorderProps.value;
|
|
1232
1236
|
canvasCtx.fillStyle = props.background;
|
|
@@ -1250,7 +1254,7 @@ var QrcodeCanvas = defineComponent({
|
|
|
1250
1254
|
watchEffect(generate);
|
|
1251
1255
|
var style = ctx.attrs.style;
|
|
1252
1256
|
return function () { return h(Fragment, [
|
|
1253
|
-
h('canvas', __assign(__assign({}, ctx.attrs), { ref: canvasEl, style: __assign(__assign({}, style), { width: "".concat(props.size, "px"), height: "".concat(props.size, "px") }) })),
|
|
1257
|
+
h('canvas', __assign(__assign({}, ctx.attrs), { ref: canvasEl, role: 'img', 'aria-label': props.value, style: __assign(__assign({}, style), { width: "".concat(props.size, "px"), height: "".concat(props.size, "px") }) })),
|
|
1254
1258
|
props.imageSettings.src && h('img', {
|
|
1255
1259
|
ref: imageRef,
|
|
1256
1260
|
src: props.imageSettings.src,
|
|
@@ -1262,23 +1266,22 @@ var QrcodeCanvas = defineComponent({
|
|
|
1262
1266
|
});
|
|
1263
1267
|
var QrcodeVue = defineComponent({
|
|
1264
1268
|
name: 'Qrcode',
|
|
1265
|
-
render: function () {
|
|
1266
|
-
var _a = this.$props, renderAs = _a.renderAs, value = _a.value, size = _a.size, margin = _a.margin, level = _a.level, background = _a.background, foreground = _a.foreground, imageSettings = _a.imageSettings, gradient = _a.gradient, gradientType = _a.gradientType, gradientStartColor = _a.gradientStartColor, gradientEndColor = _a.gradientEndColor;
|
|
1267
|
-
return h(renderAs === 'svg' ? QrcodeSvg : QrcodeCanvas, {
|
|
1268
|
-
value: value,
|
|
1269
|
-
size: size,
|
|
1270
|
-
margin: margin,
|
|
1271
|
-
level: level,
|
|
1272
|
-
background: background,
|
|
1273
|
-
foreground: foreground,
|
|
1274
|
-
imageSettings: imageSettings,
|
|
1275
|
-
gradient: gradient,
|
|
1276
|
-
gradientType: gradientType,
|
|
1277
|
-
gradientStartColor: gradientStartColor,
|
|
1278
|
-
gradientEndColor: gradientEndColor,
|
|
1279
|
-
});
|
|
1280
|
-
},
|
|
1281
1269
|
props: QRCodeVueProps,
|
|
1270
|
+
setup: function (props) {
|
|
1271
|
+
return function () { return h(props.renderAs === 'svg' ? QrcodeSvg : QrcodeCanvas, {
|
|
1272
|
+
value: props.value,
|
|
1273
|
+
size: props.size,
|
|
1274
|
+
margin: props.margin,
|
|
1275
|
+
level: props.level,
|
|
1276
|
+
background: props.background,
|
|
1277
|
+
foreground: props.foreground,
|
|
1278
|
+
imageSettings: props.imageSettings,
|
|
1279
|
+
gradient: props.gradient,
|
|
1280
|
+
gradientType: props.gradientType,
|
|
1281
|
+
gradientStartColor: props.gradientStartColor,
|
|
1282
|
+
gradientEndColor: props.gradientEndColor,
|
|
1283
|
+
}); };
|
|
1284
|
+
},
|
|
1282
1285
|
});
|
|
1283
1286
|
|
|
1284
1287
|
export { QrcodeCanvas, QrcodeSvg, QrcodeVue as default };
|
package/dist/src/index.d.ts
CHANGED
|
@@ -317,7 +317,9 @@ declare const QrcodeVue: import("vue").DefineComponent<import("vue").ExtractProp
|
|
|
317
317
|
required: boolean;
|
|
318
318
|
default: string;
|
|
319
319
|
};
|
|
320
|
-
}>,
|
|
320
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
321
|
+
[key: string]: any;
|
|
322
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
321
323
|
renderAs: {
|
|
322
324
|
type: PropType<RenderAs>;
|
|
323
325
|
required: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qrcode.vue",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.1",
|
|
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",
|
|
@@ -49,14 +49,14 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@rollup/plugin-terser": "^0.
|
|
53
|
-
"@rsbuild/core": "^
|
|
54
|
-
"@rstest/core": "^0.
|
|
52
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
53
|
+
"@rsbuild/core": "^2.0.0-rc.0",
|
|
54
|
+
"@rstest/core": "^0.9.6",
|
|
55
55
|
"@vue/test-utils": "^2.4.6",
|
|
56
|
-
"happy-dom": "^20.
|
|
57
|
-
"rollup": "^4.
|
|
58
|
-
"rollup-plugin-typescript2": "^0.
|
|
56
|
+
"happy-dom": "^20.8.9",
|
|
57
|
+
"rollup": "^4.60.1",
|
|
58
|
+
"rollup-plugin-typescript2": "^0.37.0",
|
|
59
59
|
"typescript": "^5.9.3",
|
|
60
|
-
"vue": "^3.5.
|
|
60
|
+
"vue": "^3.5.29"
|
|
61
61
|
}
|
|
62
62
|
}
|