qrcode.vue 3.8.0 → 3.9.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.
- package/CHANGELOG.md +6 -0
- package/README-zh_cn.md +19 -0
- package/README.md +18 -0
- package/dist/qrcode.vue.browser.js +130 -75
- package/dist/qrcode.vue.browser.min.js +2 -2
- package/dist/qrcode.vue.cjs.js +130 -75
- package/dist/qrcode.vue.esm.js +131 -76
- package/dist/src/index.d.ts +50 -9
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## [3.9.0]
|
|
2
|
+
|
|
3
|
+
### Feature
|
|
4
|
+
|
|
5
|
+
- Support `radius` prop for QRCode module corner rounding. The rounding is context-aware, keeping inner corners sharp while rounding outer corners. Supports both SVG and Canvas rendering modes.
|
|
6
|
+
|
|
1
7
|
## [3.8.0] - 2026-02-02
|
|
2
8
|
|
|
3
9
|
### Performance
|
package/README-zh_cn.md
CHANGED
|
@@ -81,6 +81,7 @@ createApp({
|
|
|
81
81
|
:gradient-start-color="gradientStartColor"
|
|
82
82
|
:gradient-end-color="gradientEndColor"
|
|
83
83
|
:image-settings='imageSettings'
|
|
84
|
+
:radius="radius"
|
|
84
85
|
/>
|
|
85
86
|
</template>
|
|
86
87
|
<script setup lang="ts">
|
|
@@ -110,6 +111,8 @@ createApp({
|
|
|
110
111
|
const gradientType = ref<GradientType>('linear')
|
|
111
112
|
const gradientStartColor = ref('#000000')
|
|
112
113
|
const gradientEndColor = ref('#38bdf8')
|
|
114
|
+
// 可传入圆角半径:
|
|
115
|
+
const radius = ref(0)
|
|
113
116
|
</script>
|
|
114
117
|
```
|
|
115
118
|
|
|
@@ -214,6 +217,22 @@ createApp({
|
|
|
214
217
|
|
|
215
218
|
渐变的结束颜色。
|
|
216
219
|
|
|
220
|
+
### `radius`
|
|
221
|
+
|
|
222
|
+
- 类型:`number`
|
|
223
|
+
- 默认值:`0`
|
|
224
|
+
|
|
225
|
+
每个二维码模块的圆角半径,相对于模块宽度的比例。接受 `0` 到 `0.5` 的值。
|
|
226
|
+
|
|
227
|
+
- `0`(默认)- 方形模块,直角
|
|
228
|
+
- `0.5` - 最大圆角,模块变为圆形
|
|
229
|
+
|
|
230
|
+
圆角是上下文感知的:相邻深色模块之间的内角保持直角,外角则圆角化。
|
|
231
|
+
|
|
232
|
+
```html
|
|
233
|
+
<qrcode-vue value="test" :radius="0.35" />
|
|
234
|
+
```
|
|
235
|
+
|
|
217
236
|
### `class`
|
|
218
237
|
|
|
219
238
|
- 类型:`string`
|
package/README.md
CHANGED
|
@@ -85,6 +85,7 @@ When you use the component with Vue 3 with `TypeScript`:
|
|
|
85
85
|
:gradient-start-color="gradientStartColor"
|
|
86
86
|
:gradient-end-color="gradientEndColor"
|
|
87
87
|
:image-settings='imageSettings'
|
|
88
|
+
:radius="radius"
|
|
88
89
|
/>
|
|
89
90
|
</template>
|
|
90
91
|
<script setup lang="ts">
|
|
@@ -112,6 +113,7 @@ When you use the component with Vue 3 with `TypeScript`:
|
|
|
112
113
|
const gradientType = ref<GradientType>('linear')
|
|
113
114
|
const gradientStartColor = ref('#000000')
|
|
114
115
|
const gradientEndColor = ref('#38bdf8')
|
|
116
|
+
const radius = ref(0)
|
|
115
117
|
</script>
|
|
116
118
|
```
|
|
117
119
|
|
|
@@ -213,6 +215,22 @@ The start color of the gradient.
|
|
|
213
215
|
|
|
214
216
|
The end color of the gradient.
|
|
215
217
|
|
|
218
|
+
### `radius`
|
|
219
|
+
|
|
220
|
+
- Type: `number`
|
|
221
|
+
- Default: `0`
|
|
222
|
+
|
|
223
|
+
The corner radius of each QR module, as a ratio of the module width. Accepts values from `0` to `0.5`.
|
|
224
|
+
|
|
225
|
+
- `0` (default) - square modules with sharp corners
|
|
226
|
+
- `0.5` - maximum rounding, modules become circles
|
|
227
|
+
|
|
228
|
+
The rounding is context-aware: inner corners between adjacent dark modules remain sharp, while outer corners are rounded.
|
|
229
|
+
|
|
230
|
+
```html
|
|
231
|
+
<qrcode-vue value="test" :radius="0.35" />
|
|
232
|
+
```
|
|
233
|
+
|
|
216
234
|
### `class`
|
|
217
235
|
|
|
218
236
|
- Type: `string`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* qrcode.vue v3.
|
|
2
|
+
* qrcode.vue v3.9.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.
|
|
@@ -909,6 +909,13 @@ var qrcodegen;
|
|
|
909
909
|
})(qrcodegen || (qrcodegen = {}));
|
|
910
910
|
var QR = qrcodegen;
|
|
911
911
|
|
|
912
|
+
var _uid = 0;
|
|
913
|
+
function getUid() {
|
|
914
|
+
if (typeof vue.useId === 'function') {
|
|
915
|
+
return "".concat(vue.useId(), "-").concat(_uid++);
|
|
916
|
+
}
|
|
917
|
+
return "vue-".concat(Math.random().toString(36).slice(2), "-").concat(_uid++);
|
|
918
|
+
}
|
|
912
919
|
var defaultErrorCorrectLevel = 'L';
|
|
913
920
|
var DEFAULT_QR_SIZE = 100;
|
|
914
921
|
var DEFAULT_MARGIN = 0;
|
|
@@ -933,42 +940,88 @@ var SUPPORTS_PATH2D = (function () {
|
|
|
933
940
|
function validErrorCorrectLevel(level) {
|
|
934
941
|
return level in ErrorCorrectLevelMap;
|
|
935
942
|
}
|
|
943
|
+
function getNeighborFlags(modules, row, col) {
|
|
944
|
+
var north = row > 0 ? modules[row - 1][col] : false;
|
|
945
|
+
var south = row < modules.length - 1 ? modules[row + 1][col] : false;
|
|
946
|
+
var west = col > 0 ? modules[row][col - 1] : false;
|
|
947
|
+
var east = col < modules[row].length - 1 ? modules[row][col + 1] : false;
|
|
948
|
+
return {
|
|
949
|
+
nw: !north && !west,
|
|
950
|
+
ne: !north && !east,
|
|
951
|
+
se: !south && !east,
|
|
952
|
+
sw: !south && !west,
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
function generateRoundedPath(modules, margin, radius) {
|
|
956
|
+
if (margin === void 0) { margin = 0; }
|
|
957
|
+
if (radius === void 0) { radius = 0; }
|
|
958
|
+
var pathSegments = [];
|
|
959
|
+
var r = Math.min(radius, 0.5);
|
|
960
|
+
for (var row = 0; row < modules.length; row++) {
|
|
961
|
+
for (var col = 0; col < modules[row].length; col++) {
|
|
962
|
+
if (!modules[row][col])
|
|
963
|
+
continue;
|
|
964
|
+
var _a = getNeighborFlags(modules, row, col), nw = _a.nw, ne = _a.ne, se = _a.se, sw = _a.sw;
|
|
965
|
+
var x = col + margin;
|
|
966
|
+
var y = row + margin;
|
|
967
|
+
pathSegments.push("M".concat(x + (nw ? r : 0), " ").concat(y), "L".concat(x + 1 - (ne ? r : 0), " ").concat(y));
|
|
968
|
+
if (ne) {
|
|
969
|
+
pathSegments.push("A".concat(r, " ").concat(r, " 0 0 1 ").concat(x + 1, " ").concat(y + r));
|
|
970
|
+
}
|
|
971
|
+
pathSegments.push("L".concat(x + 1, " ").concat(y + 1 - (se ? r : 0)));
|
|
972
|
+
if (se) {
|
|
973
|
+
pathSegments.push("A".concat(r, " ").concat(r, " 0 0 1 ").concat(x + 1 - r, " ").concat(y + 1));
|
|
974
|
+
}
|
|
975
|
+
pathSegments.push("L".concat(x + (sw ? r : 0), " ").concat(y + 1));
|
|
976
|
+
if (sw) {
|
|
977
|
+
pathSegments.push("A".concat(r, " ").concat(r, " 0 0 1 ").concat(x, " ").concat(y + 1 - r));
|
|
978
|
+
}
|
|
979
|
+
pathSegments.push("L".concat(x, " ").concat(y + (nw ? r : 0)));
|
|
980
|
+
if (nw) {
|
|
981
|
+
pathSegments.push("A".concat(r, " ").concat(r, " 0 0 1 ").concat(x + r, " ").concat(y));
|
|
982
|
+
}
|
|
983
|
+
pathSegments.push('z');
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
return pathSegments.join('');
|
|
987
|
+
}
|
|
936
988
|
function generatePath(modules, margin) {
|
|
937
989
|
if (margin === void 0) { margin = 0; }
|
|
938
|
-
var
|
|
939
|
-
|
|
990
|
+
var pathSegments = [];
|
|
991
|
+
for (var y = 0; y < modules.length; y++) {
|
|
992
|
+
var row = modules[y];
|
|
940
993
|
var start = null;
|
|
941
|
-
|
|
994
|
+
for (var x = 0; x < row.length; x++) {
|
|
995
|
+
var cell = row[x];
|
|
942
996
|
if (!cell && start !== null) {
|
|
943
997
|
// 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");
|
|
998
|
+
pathSegments.push("M".concat(start + margin, " ").concat(y + margin, "h").concat(x - start, "v1H").concat(start + margin, "z"));
|
|
946
999
|
start = null;
|
|
947
|
-
|
|
1000
|
+
continue;
|
|
948
1001
|
}
|
|
949
1002
|
// end of row, clean up or skip
|
|
950
1003
|
if (x === row.length - 1) {
|
|
951
1004
|
if (!cell) {
|
|
952
1005
|
// We would have closed the op above already so this can only mean
|
|
953
1006
|
// 2+ light modules in a row.
|
|
954
|
-
|
|
1007
|
+
continue;
|
|
955
1008
|
}
|
|
956
1009
|
if (start === null) {
|
|
957
1010
|
// Just a single dark module.
|
|
958
|
-
|
|
1011
|
+
pathSegments.push("M".concat(x + margin, ",").concat(y + margin, " h1v1H").concat(x + margin, "z"));
|
|
959
1012
|
}
|
|
960
1013
|
else {
|
|
961
1014
|
// Otherwise finish the current line.
|
|
962
|
-
|
|
1015
|
+
pathSegments.push("M".concat(start + margin, ",").concat(y + margin, " h").concat(x + 1 - start, "v1H").concat(start + margin, "z"));
|
|
963
1016
|
}
|
|
964
|
-
|
|
1017
|
+
continue;
|
|
965
1018
|
}
|
|
966
1019
|
if (cell && start === null) {
|
|
967
1020
|
start = x;
|
|
968
1021
|
}
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
return
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
return pathSegments.join('');
|
|
972
1025
|
}
|
|
973
1026
|
function getImageSettings(cells, size, margin, imageSettings) {
|
|
974
1027
|
var width = imageSettings.width, height = imageSettings.height, imageX = imageSettings.x, imageY = imageSettings.y;
|
|
@@ -980,15 +1033,7 @@ function getImageSettings(cells, size, margin, imageSettings) {
|
|
|
980
1033
|
var x = imageX == null ? cells.length / 2 - w / 2 : imageX * scale;
|
|
981
1034
|
var y = imageY == null ? cells.length / 2 - h / 2 : imageY * scale;
|
|
982
1035
|
var borderRadius = (imageSettings.borderRadius || 0) * scale;
|
|
983
|
-
|
|
984
|
-
if (imageSettings.excavate) {
|
|
985
|
-
var floorX = Math.floor(x);
|
|
986
|
-
var floorY = Math.floor(y);
|
|
987
|
-
var ceilW = Math.ceil(w + x - floorX);
|
|
988
|
-
var ceilH = Math.ceil(h + y - floorY);
|
|
989
|
-
excavation = { x: floorX, y: floorY, w: ceilW, h: ceilH };
|
|
990
|
-
}
|
|
991
|
-
return { x: x, y: y, h: h, w: w, borderRadius: borderRadius, excavation: excavation };
|
|
1036
|
+
return { x: x, y: y, h: h, w: w, borderRadius: borderRadius };
|
|
992
1037
|
}
|
|
993
1038
|
function useQRCode(props) {
|
|
994
1039
|
var margin = vue.computed(function () { var _a; return ((_a = props.margin) !== null && _a !== void 0 ? _a : DEFAULT_MARGIN) >>> 0; });
|
|
@@ -997,11 +1042,15 @@ function useQRCode(props) {
|
|
|
997
1042
|
return QR.QrCode.encodeText(props.value, ErrorCorrectLevelMap[level]).getModules();
|
|
998
1043
|
});
|
|
999
1044
|
var numCells = vue.computed(function () { return cells.value.length + margin.value * 2; });
|
|
1000
|
-
var fgPath = vue.computed(function () {
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
return { x: 0, y: 0, width: 0, height: 0, borderRadius: 0 };
|
|
1045
|
+
var fgPath = vue.computed(function () {
|
|
1046
|
+
if (props.radius > 0) {
|
|
1047
|
+
return generateRoundedPath(cells.value, margin.value, props.radius);
|
|
1004
1048
|
}
|
|
1049
|
+
return generatePath(cells.value, margin.value);
|
|
1050
|
+
});
|
|
1051
|
+
var imageProps = vue.computed(function () {
|
|
1052
|
+
if (!props.imageSettings.src)
|
|
1053
|
+
return null;
|
|
1005
1054
|
var settings = getImageSettings(cells.value, props.size, margin.value, props.imageSettings);
|
|
1006
1055
|
return {
|
|
1007
1056
|
x: settings.x + margin.value,
|
|
@@ -1012,7 +1061,7 @@ function useQRCode(props) {
|
|
|
1012
1061
|
};
|
|
1013
1062
|
});
|
|
1014
1063
|
var imageBorderProps = vue.computed(function () {
|
|
1015
|
-
if (!props.imageSettings.excavate || !
|
|
1064
|
+
if (!props.imageSettings.excavate || !imageProps.value)
|
|
1016
1065
|
return null;
|
|
1017
1066
|
var borderThickness = IMAGE_EXCAVATE_THICKNESS / (props.size / numCells.value);
|
|
1018
1067
|
return {
|
|
@@ -1079,6 +1128,12 @@ var QRCodeProps = {
|
|
|
1079
1128
|
required: false,
|
|
1080
1129
|
default: '#fff',
|
|
1081
1130
|
},
|
|
1131
|
+
radius: {
|
|
1132
|
+
type: Number,
|
|
1133
|
+
required: false,
|
|
1134
|
+
default: 0,
|
|
1135
|
+
validator: function (r) { return !isNaN(r) && r >= 0 && r <= 0.5; },
|
|
1136
|
+
},
|
|
1082
1137
|
};
|
|
1083
1138
|
var QRCodeVueProps = __assign(__assign({}, QRCodeProps), { renderAs: {
|
|
1084
1139
|
type: String,
|
|
@@ -1091,8 +1146,10 @@ var QrcodeSvg = vue.defineComponent({
|
|
|
1091
1146
|
props: QRCodeProps,
|
|
1092
1147
|
setup: function (props) {
|
|
1093
1148
|
var _a = useQRCode(props), numCells = _a.numCells, fgPath = _a.fgPath, imageProps = _a.imageProps, imageBorderProps = _a.imageBorderProps;
|
|
1094
|
-
var
|
|
1095
|
-
var
|
|
1149
|
+
var uid = getUid();
|
|
1150
|
+
var qrGradientId = "qrcode.vue-gradient-".concat(uid);
|
|
1151
|
+
var qrLogoClipPathId = "qrcode.vue-logo-clip-path-".concat(uid);
|
|
1152
|
+
var gradientVNode = vue.computed(function () {
|
|
1096
1153
|
if (!props.gradient)
|
|
1097
1154
|
return null;
|
|
1098
1155
|
var gradientProps = props.gradientType === 'linear'
|
|
@@ -1119,12 +1176,11 @@ var QrcodeSvg = vue.defineComponent({
|
|
|
1119
1176
|
style: { stopColor: props.gradientEndColor },
|
|
1120
1177
|
}),
|
|
1121
1178
|
]);
|
|
1122
|
-
};
|
|
1123
|
-
var
|
|
1124
|
-
|
|
1125
|
-
var borderRadius = imageProps.value.borderRadius;
|
|
1126
|
-
if (!props.imageSettings.src)
|
|
1179
|
+
});
|
|
1180
|
+
var clipPathVNode = vue.computed(function () {
|
|
1181
|
+
if (!imageProps.value)
|
|
1127
1182
|
return null;
|
|
1183
|
+
var borderRadius = imageProps.value.borderRadius;
|
|
1128
1184
|
if (borderRadius <= 0)
|
|
1129
1185
|
return null;
|
|
1130
1186
|
return vue.h('clipPath', { id: qrLogoClipPathId }, [
|
|
@@ -1137,15 +1193,16 @@ var QrcodeSvg = vue.defineComponent({
|
|
|
1137
1193
|
ry: borderRadius,
|
|
1138
1194
|
}),
|
|
1139
1195
|
]);
|
|
1140
|
-
};
|
|
1196
|
+
});
|
|
1141
1197
|
return function () { return vue.h('svg', {
|
|
1142
1198
|
width: props.size,
|
|
1143
1199
|
height: props.size,
|
|
1144
|
-
'shape-rendering': "crispEdges",
|
|
1145
1200
|
xmlns: 'http://www.w3.org/2000/svg',
|
|
1146
1201
|
viewBox: "0 0 ".concat(numCells.value, " ").concat(numCells.value),
|
|
1202
|
+
role: 'img',
|
|
1203
|
+
'aria-label': props.value,
|
|
1147
1204
|
}, [
|
|
1148
|
-
vue.h('defs', {}, [
|
|
1205
|
+
vue.h('defs', {}, [gradientVNode.value, clipPathVNode.value]),
|
|
1149
1206
|
vue.h('rect', {
|
|
1150
1207
|
width: '100%',
|
|
1151
1208
|
height: '100%',
|
|
@@ -1164,7 +1221,7 @@ var QrcodeSvg = vue.defineComponent({
|
|
|
1164
1221
|
rx: imageBorderProps.value.borderRadius,
|
|
1165
1222
|
ry: imageBorderProps.value.borderRadius,
|
|
1166
1223
|
}),
|
|
1167
|
-
props.imageSettings.src && vue.h('image', __assign(__assign({ href: props.imageSettings.src }, imageProps.value), (imageProps.value.borderRadius > 0 ? { 'clip-path': "url(#".concat(qrLogoClipPathId, ")") } : {}))),
|
|
1224
|
+
props.imageSettings.src && imageProps.value && vue.h('image', __assign(__assign({ href: props.imageSettings.src }, imageProps.value), (imageProps.value.borderRadius > 0 ? { 'clip-path': "url(#".concat(qrLogoClipPathId, ")") } : {}))),
|
|
1168
1225
|
]); };
|
|
1169
1226
|
},
|
|
1170
1227
|
});
|
|
@@ -1172,9 +1229,18 @@ var QrcodeCanvas = vue.defineComponent({
|
|
|
1172
1229
|
name: 'QRCodeCanvas',
|
|
1173
1230
|
props: QRCodeProps,
|
|
1174
1231
|
setup: function (props, ctx) {
|
|
1175
|
-
var _a = useQRCode(props), margin = _a.margin, cells = _a.cells, numCells = _a.numCells, imageProps = _a.imageProps, imageBorderProps = _a.imageBorderProps;
|
|
1232
|
+
var _a = useQRCode(props), margin = _a.margin, cells = _a.cells, numCells = _a.numCells, fgPath = _a.fgPath, imageProps = _a.imageProps, imageBorderProps = _a.imageBorderProps;
|
|
1176
1233
|
var canvasEl = vue.ref(null);
|
|
1177
|
-
var
|
|
1234
|
+
var imageEl = vue.ref(null);
|
|
1235
|
+
var drawRoundedRect = function (ctx, x, y, width, height, radius) {
|
|
1236
|
+
ctx.beginPath();
|
|
1237
|
+
if (ctx.roundRect) {
|
|
1238
|
+
ctx.roundRect(x, y, width, height, radius);
|
|
1239
|
+
}
|
|
1240
|
+
else {
|
|
1241
|
+
ctx.rect(x, y, width, height);
|
|
1242
|
+
}
|
|
1243
|
+
};
|
|
1178
1244
|
var generate = function () {
|
|
1179
1245
|
var size = props.size, background = props.background, foreground = props.foreground, gradient = props.gradient, gradientType = props.gradientType, gradientStartColor = props.gradientStartColor, gradientEndColor = props.gradientEndColor;
|
|
1180
1246
|
var canvas = canvasEl.value;
|
|
@@ -1185,12 +1251,11 @@ var QrcodeCanvas = vue.defineComponent({
|
|
|
1185
1251
|
if (!canvasCtx) {
|
|
1186
1252
|
return;
|
|
1187
1253
|
}
|
|
1188
|
-
var
|
|
1189
|
-
var image = imageRef.value;
|
|
1254
|
+
var image = imageEl.value;
|
|
1190
1255
|
var devicePixelRatio = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;
|
|
1191
1256
|
var scale = (size / numCells.value) * devicePixelRatio;
|
|
1192
1257
|
canvas.height = canvas.width = size * devicePixelRatio;
|
|
1193
|
-
canvasCtx.
|
|
1258
|
+
canvasCtx.setTransform(scale, 0, 0, scale, 0, 0);
|
|
1194
1259
|
canvasCtx.fillStyle = background;
|
|
1195
1260
|
canvasCtx.fillRect(0, 0, numCells.value, numCells.value);
|
|
1196
1261
|
if (gradient) {
|
|
@@ -1209,10 +1274,10 @@ var QrcodeCanvas = vue.defineComponent({
|
|
|
1209
1274
|
canvasCtx.fillStyle = foreground;
|
|
1210
1275
|
}
|
|
1211
1276
|
if (SUPPORTS_PATH2D) {
|
|
1212
|
-
canvasCtx.fill(new Path2D(
|
|
1277
|
+
canvasCtx.fill(new Path2D(fgPath.value));
|
|
1213
1278
|
}
|
|
1214
1279
|
else {
|
|
1215
|
-
|
|
1280
|
+
cells.value.forEach(function (row, rdx) {
|
|
1216
1281
|
row.forEach(function (cell, cdx) {
|
|
1217
1282
|
if (cell) {
|
|
1218
1283
|
canvasCtx.fillRect(cdx + margin.value, rdx + margin.value, 1, 1);
|
|
@@ -1221,16 +1286,7 @@ var QrcodeCanvas = vue.defineComponent({
|
|
|
1221
1286
|
});
|
|
1222
1287
|
}
|
|
1223
1288
|
var showImage = props.imageSettings.src && image && image.naturalWidth !== 0 && image.naturalHeight !== 0;
|
|
1224
|
-
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
|
-
};
|
|
1289
|
+
if (showImage && imageProps.value) {
|
|
1234
1290
|
if (imageBorderProps.value) {
|
|
1235
1291
|
var imageBorder = imageBorderProps.value;
|
|
1236
1292
|
canvasCtx.fillStyle = props.background;
|
|
@@ -1252,11 +1308,10 @@ var QrcodeCanvas = vue.defineComponent({
|
|
|
1252
1308
|
};
|
|
1253
1309
|
vue.onMounted(generate);
|
|
1254
1310
|
vue.watchEffect(generate);
|
|
1255
|
-
var style = ctx.attrs.style;
|
|
1256
1311
|
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") }) })),
|
|
1312
|
+
vue.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") }) })),
|
|
1258
1313
|
props.imageSettings.src && vue.h('img', {
|
|
1259
|
-
ref:
|
|
1314
|
+
ref: imageEl,
|
|
1260
1315
|
src: props.imageSettings.src,
|
|
1261
1316
|
style: { display: 'none' },
|
|
1262
1317
|
onLoad: generate,
|
|
@@ -1266,23 +1321,23 @@ var QrcodeCanvas = vue.defineComponent({
|
|
|
1266
1321
|
});
|
|
1267
1322
|
var QrcodeVue = vue.defineComponent({
|
|
1268
1323
|
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
1324
|
props: QRCodeVueProps,
|
|
1325
|
+
setup: function (props) {
|
|
1326
|
+
return function () { return vue.h(props.renderAs === 'svg' ? QrcodeSvg : QrcodeCanvas, {
|
|
1327
|
+
value: props.value,
|
|
1328
|
+
size: props.size,
|
|
1329
|
+
margin: props.margin,
|
|
1330
|
+
level: props.level,
|
|
1331
|
+
background: props.background,
|
|
1332
|
+
foreground: props.foreground,
|
|
1333
|
+
imageSettings: props.imageSettings,
|
|
1334
|
+
gradient: props.gradient,
|
|
1335
|
+
gradientType: props.gradientType,
|
|
1336
|
+
gradientStartColor: props.gradientStartColor,
|
|
1337
|
+
gradientEndColor: props.gradientEndColor,
|
|
1338
|
+
radius: props.radius,
|
|
1339
|
+
}); };
|
|
1340
|
+
},
|
|
1286
1341
|
});
|
|
1287
1342
|
|
|
1288
1343
|
exports.QrcodeCanvas = QrcodeCanvas;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* qrcode.vue v3.
|
|
2
|
+
* qrcode.vue v3.9.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
|
-
!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 o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError,function(e){var t=function(){function t(e,r,n,a){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>a||a>7)throw new RangeError("Mask value out of range");this.size=4*e+17;for(var i=[],u=0;this.size>u;u++)i.push(!1);for(u=0;this.size>u;u++)this.modules.push(i.slice()),this.isFunction.push(i.slice());this.drawFunctionPatterns();var s=this.addEccAndInterleave(n);if(this.drawCodewords(s),-1==a){var l=1e9;for(u=0;8>u;u++){this.applyMask(u),this.drawFormatBits(u);var c=this.getPenaltyScore();l>c&&(a=u,l=c),this.applyMask(u)}}o(a>=0&&7>=a),this.mask=a,this.applyMask(a),this.drawFormatBits(a),this.isFunction=[]}return t.encodeText=function(r,n){var o=e.QrSegment.makeSegments(r);return t.encodeSegments(o,n)},t.encodeBinary=function(r,n){var o=e.QrSegment.makeBytes(r);return t.encodeSegments([o],n)},t.encodeSegments=function(e,n,i,u,s,l){if(void 0===i&&(i=1),void 0===u&&(u=40),void 0===s&&(s=-1),void 0===l&&(l=!0),t.MIN_VERSION>i||i>u||u>t.MAX_VERSION||-1>s||s>7)throw new RangeError("Invalid value");var c,d;for(c=i;;c++){var h=8*t.getNumDataCodewords(c,n),f=a.getTotalBits(e,c);if(h>=f){d=f;break}if(c>=u)throw new RangeError("Data too long")}for(var v=0,g=[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH];g.length>v;v++){var p=g[v];l&&d<=8*t.getNumDataCodewords(c,p)&&(n=p)}for(var m=[],y=0,w=e;w.length>y;y++){var E=w[y];r(E.mode.modeBits,4,m),r(E.numChars,E.mode.numCharCountBits(c),m);for(var C=0,M=E.getData();M.length>C;C++){m.push(M[C])}}o(m.length==d);var R=8*t.getNumDataCodewords(c,n);o(R>=m.length),r(0,Math.min(4,R-m.length),m),r(0,(8-m.length%8)%8,m),o(m.length%8==0);for(var S=236;R>m.length;S^=253)r(S,8,m);for(var A=[];m.length>8*A.length;)A.push(0);return m.forEach(function(e,t){return A[t>>>3]|=e<<7-(7&t)}),new t(c,n,A,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,a=0;10>a;a++)r=r<<1^1335*(r>>>9);var i=21522^(t<<10|r);o(i>>>15==0);for(a=0;5>=a;a++)this.setFunctionModule(8,a,n(i,a));this.setFunctionModule(8,7,n(i,6)),this.setFunctionModule(8,8,n(i,7)),this.setFunctionModule(7,8,n(i,8));for(a=9;15>a;a++)this.setFunctionModule(14-a,8,n(i,a));for(a=0;8>a;a++)this.setFunctionModule(this.size-1-a,8,n(i,a));for(a=8;15>a;a++)this.setFunctionModule(8,this.size-15+a,n(i,a));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;o(r>>>18==0);for(t=0;18>t;t++){var a=n(r,t),i=this.size-11+t%3,u=Math.floor(t/3);this.setFunctionModule(i,u,a),this.setFunctionModule(u,i,a)}}},t.prototype.drawFinderPattern=function(e,t){for(var r=-4;4>=r;r++)for(var n=-4;4>=n;n++){var o=Math.max(Math.abs(n),Math.abs(r)),a=e+n,i=t+r;a>=0&&this.size>a&&i>=0&&this.size>i&&this.setFunctionModule(a,i,2!=o&&4!=o)}},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 a=t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][r],i=t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][r],u=Math.floor(t.getNumRawDataModules(r)/8),s=a-u%a,l=Math.floor(u/a),c=[],d=t.reedSolomonComputeDivisor(i),h=0,f=0;a>h;h++){var v=e.slice(f,f+l-i+(s>h?0:1));f+=v.length;var g=t.reedSolomonComputeRemainder(v,d);s>h&&v.push(0),c.push(v.concat(g))}var p=[],m=function(e){c.forEach(function(t,r){e==l-i&&s>r||p.push(t[e])})};for(h=0;c[0].length>h;h++)m(h);return o(p.length==u),p},t.prototype.drawCodewords=function(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");for(var r=0,a=this.size-1;a>=1;a-=2){6==a&&(a=5);for(var i=0;this.size>i;i++)for(var u=0;2>u;u++){var s=a-u,l=!(a+1&2)?this.size-1-i:i;!this.isFunction[l][s]&&8*e.length>r&&(this.modules[l][s]=n(e[r>>>3],7-(7&r)),r++)}}o(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,a=0,i=[0,0,0,0,0,0,0],u=0;this.size>u;u++)this.modules[r][u]==n?5==++a?e+=t.PENALTY_N1:a>5&&e++:(this.finderPenaltyAddHistory(a,i),n||(e+=this.finderPenaltyCountPatterns(i)*t.PENALTY_N3),n=this.modules[r][u],a=1);e+=this.finderPenaltyTerminateAndCount(n,a,i)*t.PENALTY_N3}for(u=0;this.size>u;u++){n=!1;var s=0;for(i=[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,i),n||(e+=this.finderPenaltyCountPatterns(i)*t.PENALTY_N3),n=this.modules[r][u],s=1);e+=this.finderPenaltyTerminateAndCount(n,s,i)*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 c=0,d=0,h=this.modules;h.length>d;d++){c=h[d].reduce(function(e,t){return e+(t?1:0)},c)}var f=this.size*this.size,v=Math.ceil(Math.abs(20*c-10*f)/f)-1;return o(v>=0&&9>=v),o((e+=v*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 o(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 o=1;for(n=0;e>n;n++){for(var a=0;r.length>a;a++)r[a]=t.reedSolomonMultiply(r[a],o),r.length>a+1&&(r[a]^=r[a+1]);o=t.reedSolomonMultiply(o,2)}return r},t.reedSolomonComputeRemainder=function(e,r){for(var n=r.map(function(e){return 0}),o=function(e){var o=e^n.shift();n.push(0),r.forEach(function(e,r){return n[r]^=t.reedSolomonMultiply(e,o)})},a=0,i=e;i.length>a;a++){o(i[a])}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 o(r>>>8==0),r},t.prototype.finderPenaltyCountPatterns=function(e){var t=e[1];o(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 o(e){if(!e)throw Error("Assertion error")}e.QrCode=t;var a=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=[],o=0,a=t;a.length>o;o++){r(a[o],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=[],o=0;t.length>o;){var a=Math.min(t.length-o,3);r(parseInt(t.substring(o,o+a),10),3*a+1,n),o+=a}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,o=[];for(n=0;t.length>=n+2;n+=2){var a=45*e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(n));r(a+=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(n+1)),11,o)}return t.length>n&&r(e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(n)),6,o),new e(e.Mode.ALPHANUMERIC,t.length,o)},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,o=e;o.length>n;n++){var a=o[n],i=a.mode.numCharCountBits(t);if(a.numChars>=1<<i)return 1/0;r+=4+i+a.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=a}(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 o=r,a=0;var i={L:o.QrCode.Ecc.LOW,M:o.QrCode.Ecc.MEDIUM,Q:o.QrCode.Ecc.QUARTILE,H:o.QrCode.Ecc.HIGH},u=function(){try{(new Path2D).addPath(new Path2D)}catch(e){return!1}return!0}();function s(e){return e in i}function l(e,t,r){var n=t>0&&e[t-1][r],o=e.length-1>t&&e[t+1][r],a=r>0&&e[t][r-1],i=e[t].length-1>r&&e[t][r+1];return{nw:!n&&!a,ne:!n&&!i,se:!o&&!i,sw:!o&&!a}}function c(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 o.QrCode.encodeText(e.value,i[t]).getModules()}),a=t.computed(function(){return n.value.length+2*r.value}),u=t.computed(function(){return e.radius>0?function(e,t,r){void 0===t&&(t=0),void 0===r&&(r=0);for(var n=[],o=Math.min(r,.5),a=0;e.length>a;a++)for(var i=0;e[a].length>i;i++)if(e[a][i]){var u=l(e,a,i),s=u.nw,c=u.ne,d=u.se,h=u.sw,f=i+t,v=a+t;n.push("M".concat(f+(s?o:0)," ").concat(v),"L".concat(f+1-(c?o:0)," ").concat(v)),c&&n.push("A".concat(o," ").concat(o," 0 0 1 ").concat(f+1," ").concat(v+o)),n.push("L".concat(f+1," ").concat(v+1-(d?o:0))),d&&n.push("A".concat(o," ").concat(o," 0 0 1 ").concat(f+1-o," ").concat(v+1)),n.push("L".concat(f+(h?o:0)," ").concat(v+1)),h&&n.push("A".concat(o," ").concat(o," 0 0 1 ").concat(f," ").concat(v+1-o)),n.push("L".concat(f," ").concat(v+(s?o:0))),s&&n.push("A".concat(o," ").concat(o," 0 0 1 ").concat(f+o," ").concat(v)),n.push("z")}return n.join("")}(n.value,r.value,e.radius):function(e,t){void 0===t&&(t=0);for(var r=[],n=0;e.length>n;n++)for(var o=e[n],a=null,i=0;o.length>i;i++){var u=o[i];if(u||null===a)if(i!==o.length-1)u&&null===a&&(a=i);else{if(!u)continue;r.push(null===a?"M".concat(i+t,",").concat(n+t," h1v1H").concat(i+t,"z"):"M".concat(a+t,",").concat(n+t," h").concat(i+1-a,"v1H").concat(a+t,"z"))}else r.push("M".concat(a+t," ").concat(n+t,"h").concat(i-a,"v1H").concat(a+t,"z")),a=null}return r.join("")}(n.value,r.value)}),c=t.computed(function(){if(!e.imageSettings.src)return null;var t=function(e,t,r,n){var o=n.width,a=n.height,i=n.x,u=n.y,s=e.length+2*r,l=Math.floor(.1*t),c=s/t,d=(o||l)*c,h=(a||l)*c;return{x:null==i?e.length/2-d/2:i*c,y:null==u?e.length/2-h/2:u*c,h:h,w:d,borderRadius:(n.borderRadius||0)*c}}(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}}),d=t.computed(function(){if(!e.imageSettings.excavate||!c.value)return null;var t=2/(e.size/a.value);return{x:c.value.x-t,y:c.value.y-t,width:c.value.width+2*t,height:c.value.height+2*t,borderRadius:c.value.borderRadius}});return{margin:r,numCells:a,cells:n,fgPath:u,imageProps:c,imageBorderProps:d}}var d={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"},radius:{type:Number,required:!1,default:0,validator:function(e){return!isNaN(e)&&e>=0&&.5>=e}}},h=n(n({},d),{renderAs:{type:String,required:!1,default:"canvas",validator:function(e){return["canvas","svg"].indexOf(e)>-1}}}),f=t.defineComponent({name:"QRCodeSvg",props:d,setup:function(e){var r=c(e),o=r.numCells,i=r.fgPath,u=r.imageProps,s=r.imageBorderProps,l="function"==typeof t.useId?"".concat(t.useId(),"-").concat(a++):"vue-".concat(Math.random().toString(36).slice(2),"-").concat(a++),d="qrcode.vue-gradient-".concat(l),h="qrcode.vue-logo-clip-path-".concat(l),f=t.computed(function(){return 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}),v=t.computed(function(){if(!u.value)return null;var e=u.value.borderRadius;return e>0?t.h("clipPath",{id:h},[t.h("rect",{x:u.value.x,y:u.value.y,width:u.value.width,height:u.value.height,rx:e,ry:e})]):null});return function(){return t.h("svg",{width:e.size,height:e.size,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 ".concat(o.value," ").concat(o.value),role:"img","aria-label":e.value},[t.h("defs",{},[f.value,v.value]),t.h("rect",{width:"100%",height:"100%",fill:e.background}),t.h("path",{fill:e.gradient?"url(#".concat(d,")"):e.foreground,d:i.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&&u.value&&t.h("image",n(n({href:e.imageSettings.src},u.value),u.value.borderRadius>0?{"clip-path":"url(#".concat(h,")")}:{}))])}}}),v=t.defineComponent({name:"QRCodeCanvas",props:d,setup:function(e,r){var o=c(e),a=o.margin,i=o.cells,s=o.numCells,l=o.fgPath,d=o.imageProps,h=o.imageBorderProps,f=t.ref(null),v=t.ref(null),g=function(e,t,r,n,o,a){e.beginPath(),e.roundRect?e.roundRect(t,r,n,o,a):e.rect(t,r,n,o)},p=function(){var t=e.size,r=e.background,n=e.foreground,o=e.gradient,c=e.gradientType,p=e.gradientStartColor,m=e.gradientEndColor,y=f.value;if(y){var w=y.getContext("2d");if(w){var E=v.value,C="undefined"!=typeof window&&window.devicePixelRatio||1,M=t/s.value*C;if(y.height=y.width=t*C,w.setTransform(M,0,0,M,0,0),w.fillStyle=r,w.fillRect(0,0,s.value,s.value),o){var R=void 0;(R="linear"===c?w.createLinearGradient(0,0,s.value,s.value):w.createRadialGradient(s.value/2,s.value/2,0,s.value/2,s.value/2,s.value/2)).addColorStop(0,p),R.addColorStop(1,m),w.fillStyle=R}else w.fillStyle=n;if(u?w.fill(new Path2D(l.value)):i.value.forEach(function(e,t){e.forEach(function(e,r){e&&w.fillRect(r+a.value,t+a.value,1,1)})}),e.imageSettings.src&&E&&0!==E.naturalWidth&&0!==E.naturalHeight&&d.value){if(h.value){var S=h.value;w.fillStyle=e.background,g(w,S.x,S.y,S.width,S.height,S.borderRadius),w.fill()}var A=d.value.borderRadius;A>0?(w.save(),g(w,d.value.x,d.value.y,d.value.width,d.value.height,A),w.clip(),w.drawImage(E,d.value.x,d.value.y,d.value.width,d.value.height),w.restore()):w.drawImage(E,d.value.x,d.value.y,d.value.width,d.value.height)}}}};return t.onMounted(p),t.watchEffect(p),function(){return t.h(t.Fragment,[t.h("canvas",n(n({},r.attrs),{ref:f,role:"img","aria-label":e.value,style:n(n({},r.attrs.style),{width:"".concat(e.size,"px"),height:"".concat(e.size,"px")})})),e.imageSettings.src&&t.h("img",{ref:v,src:e.imageSettings.src,style:{display:"none"},onLoad:p})])}}}),g=t.defineComponent({name:"Qrcode",props:h,setup:function(e){return function(){return t.h("svg"===e.renderAs?f:v,{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,radius:e.radius})}}});e.QrcodeCanvas=v,e.QrcodeSvg=f,e.default=g,Object.defineProperty(e,"__esModule",{value:!0})});
|