@digigov/ui 0.26.2 → 0.26.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -1
- package/app/QrCodeViewer/QRCode.stories.d.ts +8 -0
- package/app/QrCodeViewer/QRCode.stories.js +46 -0
- package/app/QrCodeViewer/__stories__/Custom.d.ts +2 -0
- package/app/QrCodeViewer/__stories__/Custom.js +37 -0
- package/app/QrCodeViewer/__stories__/Default.d.ts +2 -0
- package/app/QrCodeViewer/__stories__/Default.js +24 -0
- package/app/QrCodeViewer/index.d.ts +8 -0
- package/app/QrCodeViewer/index.js +248 -0
- package/app/QrCodeViewer/index.mdx +21 -0
- package/app/QrCodeViewer/qrcodegen.d.ts +100 -0
- package/app/QrCodeViewer/qrcodegen.js +1086 -0
- package/app/QrCodeViewer/types.d.ts +29 -0
- package/app/QrCodeViewer/types.js +5 -0
- package/app/QrCodeViewer/utils.d.ts +11 -0
- package/app/QrCodeViewer/utils.js +108 -0
- package/app/index.d.ts +1 -0
- package/app/index.js +13 -0
- package/es/app/QrCodeViewer/QRCode.stories.js +8 -0
- package/es/app/QrCodeViewer/__stories__/Custom.js +22 -0
- package/es/app/QrCodeViewer/__stories__/Default.js +11 -0
- package/es/app/QrCodeViewer/index.js +224 -0
- package/es/app/QrCodeViewer/index.mdx +21 -0
- package/es/app/QrCodeViewer/qrcodegen.js +1085 -0
- package/es/app/QrCodeViewer/types.js +1 -0
- package/es/app/QrCodeViewer/utils.js +95 -0
- package/es/app/index.js +1 -0
- package/es/registry.js +8 -0
- package/esm/app/QrCodeViewer/QRCode.stories.js +8 -0
- package/esm/app/QrCodeViewer/__stories__/Custom.js +22 -0
- package/esm/app/QrCodeViewer/__stories__/Default.js +11 -0
- package/esm/app/QrCodeViewer/index.js +224 -0
- package/esm/app/QrCodeViewer/index.mdx +21 -0
- package/esm/app/QrCodeViewer/qrcodegen.js +1085 -0
- package/esm/app/QrCodeViewer/types.js +1 -0
- package/esm/app/QrCodeViewer/utils.js +95 -0
- package/esm/app/index.js +1 -0
- package/esm/index.js +1 -1
- package/esm/registry.js +8 -0
- package/package.json +2 -2
- package/registry.d.ts +4 -0
- package/registry.js +12 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
var DEFAULT_IMG_SCALE = 0.1;
|
|
2
|
+
export var MARGIN_SIZE = 4;
|
|
3
|
+
export function generatePath(modules) {
|
|
4
|
+
var margin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
5
|
+
var ops = [];
|
|
6
|
+
modules.forEach(function (row, y) {
|
|
7
|
+
var start = null;
|
|
8
|
+
row.forEach(function (cell, x) {
|
|
9
|
+
if (!cell && start !== null) {
|
|
10
|
+
// M0 0h7v1H0z injects the space with the move and drops the comma,
|
|
11
|
+
// saving a char per operation
|
|
12
|
+
ops.push("M".concat(start + margin, " ").concat(y + margin, "h").concat(x - start, "v1H").concat(start + margin, "z"));
|
|
13
|
+
start = null;
|
|
14
|
+
return;
|
|
15
|
+
} // end of row, clean up or skip
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
if (x === row.length - 1) {
|
|
19
|
+
if (!cell) {
|
|
20
|
+
// We would have closed the op above already so this can only mean
|
|
21
|
+
// 2+ light modules in a row.
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (start === null) {
|
|
26
|
+
// Just a single dark module.
|
|
27
|
+
ops.push("M".concat(x + margin, ",").concat(y + margin, " h1v1H").concat(x + margin, "z"));
|
|
28
|
+
} else {
|
|
29
|
+
// Otherwise finish the current line.
|
|
30
|
+
ops.push("M".concat(start + margin, ",").concat(y + margin, " h").concat(x + 1 - start, "v1H").concat(start + margin, "z"));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (cell && start === null) {
|
|
37
|
+
start = x;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
return ops.join('');
|
|
42
|
+
} // We could just do this in generatePath, except that we want to support
|
|
43
|
+
// non-Path2D canvas, so we need to keep it an explicit step.
|
|
44
|
+
|
|
45
|
+
export function excavateModules(modules, excavation) {
|
|
46
|
+
return modules.slice().map(function (row, y) {
|
|
47
|
+
if (y < excavation.y || y >= excavation.y + excavation.h) {
|
|
48
|
+
return row;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return row.map(function (cell, x) {
|
|
52
|
+
if (x < excavation.x || x >= excavation.x + excavation.w) {
|
|
53
|
+
return cell;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return false;
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export function getImageSettings(cells, size, includeMargin, imageSettings) {
|
|
61
|
+
if (imageSettings == null) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
var margin = includeMargin ? MARGIN_SIZE : 0;
|
|
66
|
+
var numCells = cells.length + margin * 2;
|
|
67
|
+
var defaultSize = Math.floor(size * DEFAULT_IMG_SCALE);
|
|
68
|
+
var scale = numCells / size;
|
|
69
|
+
var w = (imageSettings.width || defaultSize) * scale;
|
|
70
|
+
var h = (imageSettings.height || defaultSize) * scale;
|
|
71
|
+
var x = imageSettings.x == null ? cells.length / 2 - w / 2 : imageSettings.x * scale;
|
|
72
|
+
var y = imageSettings.y == null ? cells.length / 2 - h / 2 : imageSettings.y * scale;
|
|
73
|
+
var excavation;
|
|
74
|
+
|
|
75
|
+
if (imageSettings.excavate) {
|
|
76
|
+
var floorX = Math.floor(x);
|
|
77
|
+
var floorY = Math.floor(y);
|
|
78
|
+
var ceilW = Math.ceil(w + x - floorX);
|
|
79
|
+
var ceilH = Math.ceil(h + y - floorY);
|
|
80
|
+
excavation = {
|
|
81
|
+
x: floorX,
|
|
82
|
+
y: floorY,
|
|
83
|
+
w: ceilW,
|
|
84
|
+
h: ceilH
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
x: x,
|
|
90
|
+
y: y,
|
|
91
|
+
h: h,
|
|
92
|
+
w: w,
|
|
93
|
+
excavation: excavation
|
|
94
|
+
};
|
|
95
|
+
}
|
package/es/app/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from '@digigov/ui/app/App';
|
|
2
2
|
export * from '@digigov/ui/app/PageTitle';
|
|
3
3
|
export * from '@digigov/ui/app/QrCodeScanner';
|
|
4
|
+
export * from '@digigov/ui/app/QrCodeViewer';
|
|
4
5
|
export * from '@digigov/ui/app/Header';
|
|
5
6
|
export * from '@digigov/ui/app/i18n';
|
|
6
7
|
export * from '@digigov/ui/app/I18nText';
|
package/es/registry.js
CHANGED
|
@@ -48,6 +48,10 @@ import * as _digigov_ui_app_OutdatedBrowserBanner from '@digigov/ui/app/Outdated
|
|
|
48
48
|
import * as _digigov_ui_app_PageTitle from '@digigov/ui/app/PageTitle';
|
|
49
49
|
import * as _digigov_ui_app_PhaseBannerHeader from '@digigov/ui/app/PhaseBannerHeader';
|
|
50
50
|
import * as _digigov_ui_app_QrCodeScanner from '@digigov/ui/app/QrCodeScanner';
|
|
51
|
+
import * as _digigov_ui_app_QrCodeViewer from '@digigov/ui/app/QrCodeViewer';
|
|
52
|
+
import * as _digigov_ui_app_QrCodeViewer_qrcodegen from '@digigov/ui/app/QrCodeViewer/qrcodegen';
|
|
53
|
+
import * as _digigov_ui_app_QrCodeViewer_types from '@digigov/ui/app/QrCodeViewer/types';
|
|
54
|
+
import * as _digigov_ui_app_QrCodeViewer_utils from '@digigov/ui/app/QrCodeViewer/utils';
|
|
51
55
|
import * as _digigov_ui_core_Accordion from '@digigov/ui/core/Accordion';
|
|
52
56
|
import * as _digigov_ui_core_BackLink from '@digigov/ui/core/BackLink';
|
|
53
57
|
import * as _digigov_ui_core_Base from '@digigov/ui/core/Base';
|
|
@@ -216,6 +220,10 @@ export default {
|
|
|
216
220
|
'@digigov/ui/app/PageTitle': lazyImport(_digigov_ui_app_PageTitle),
|
|
217
221
|
'@digigov/ui/app/PhaseBannerHeader': lazyImport(_digigov_ui_app_PhaseBannerHeader),
|
|
218
222
|
'@digigov/ui/app/QrCodeScanner': lazyImport(_digigov_ui_app_QrCodeScanner),
|
|
223
|
+
'@digigov/ui/app/QrCodeViewer': lazyImport(_digigov_ui_app_QrCodeViewer),
|
|
224
|
+
'@digigov/ui/app/QrCodeViewer/qrcodegen': lazyImport(_digigov_ui_app_QrCodeViewer_qrcodegen),
|
|
225
|
+
'@digigov/ui/app/QrCodeViewer/types': lazyImport(_digigov_ui_app_QrCodeViewer_types),
|
|
226
|
+
'@digigov/ui/app/QrCodeViewer/utils': lazyImport(_digigov_ui_app_QrCodeViewer_utils),
|
|
219
227
|
'@digigov/ui/core/Accordion': lazyImport(_digigov_ui_core_Accordion),
|
|
220
228
|
'@digigov/ui/core/BackLink': lazyImport(_digigov_ui_core_BackLink),
|
|
221
229
|
'@digigov/ui/core/Base': lazyImport(_digigov_ui_core_Base),
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/* eslint-disable digigov/no-relative-imports */
|
|
2
|
+
import QrCodeViewer from '@digigov/ui/app/QrCodeViewer';
|
|
3
|
+
export default {
|
|
4
|
+
title: 'Digigov UI/app/QrCodeViewer',
|
|
5
|
+
component: QrCodeViewer
|
|
6
|
+
};
|
|
7
|
+
export * from './__stories__/Default';
|
|
8
|
+
export * from './__stories__/Custom';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import QrCodeViewer from '@digigov/ui/app/QrCodeViewer';
|
|
3
|
+
import logo from '@digigov/ui/govgr/images/greek-government-base64';
|
|
4
|
+
export var Custom = function Custom() {
|
|
5
|
+
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(QrCodeViewer, {
|
|
6
|
+
value: "https://www.gov.gr/",
|
|
7
|
+
size: 126,
|
|
8
|
+
bgColor: '#ededed',
|
|
9
|
+
fgColor: '#003375',
|
|
10
|
+
level: 'H',
|
|
11
|
+
includeMargin: false,
|
|
12
|
+
imageSettings: {
|
|
13
|
+
src: "".concat(logo),
|
|
14
|
+
x: undefined,
|
|
15
|
+
y: undefined,
|
|
16
|
+
height: 35,
|
|
17
|
+
width: 50,
|
|
18
|
+
excavate: true
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
};
|
|
22
|
+
export default Custom;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import QrCodeViewer from '@digigov/ui/app/QrCodeViewer';
|
|
3
|
+
|
|
4
|
+
var _ref = /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(QrCodeViewer, {
|
|
5
|
+
value: "https://www.gov.gr/"
|
|
6
|
+
}));
|
|
7
|
+
|
|
8
|
+
export var Default = function Default() {
|
|
9
|
+
return _ref;
|
|
10
|
+
};
|
|
11
|
+
export default Default;
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["value", "size", "level", "bgColor", "fgColor", "includeMargin", "style", "imageSettings"],
|
|
5
|
+
_excluded2 = ["value", "size", "level", "bgColor", "fgColor", "includeMargin", "imageSettings"],
|
|
6
|
+
_excluded3 = ["renderAs"];
|
|
7
|
+
import React, { useRef, useEffect, useState } from 'react';
|
|
8
|
+
import qrcodegen from '@digigov/ui/app/QrCodeViewer/qrcodegen';
|
|
9
|
+
import { generatePath, excavateModules, getImageSettings, MARGIN_SIZE } from '@digigov/ui/app/QrCodeViewer/utils';
|
|
10
|
+
var DEFAULT_SIZE = 128;
|
|
11
|
+
var DEFAULT_LEVEL = 'L';
|
|
12
|
+
var DEFAULT_BGCOLOR = '#FFFFFF';
|
|
13
|
+
var DEFAULT_FGCOLOR = '#000000';
|
|
14
|
+
var DEFAULT_INCLUDEMARGIN = false;
|
|
15
|
+
|
|
16
|
+
var SUPPORTS_PATH2D = function () {
|
|
17
|
+
try {
|
|
18
|
+
new Path2D().addPath(new Path2D());
|
|
19
|
+
} catch (e) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return true;
|
|
24
|
+
}();
|
|
25
|
+
|
|
26
|
+
var ERROR_LEVEL_MAP = {
|
|
27
|
+
L: qrcodegen.QrCode.Ecc.LOW,
|
|
28
|
+
M: qrcodegen.QrCode.Ecc.MEDIUM,
|
|
29
|
+
Q: qrcodegen.QrCode.Ecc.QUARTILE,
|
|
30
|
+
H: qrcodegen.QrCode.Ecc.HIGH
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function QrCodeViewerCanvas(props) {
|
|
34
|
+
var value = props.value,
|
|
35
|
+
_props$size = props.size,
|
|
36
|
+
size = _props$size === void 0 ? DEFAULT_SIZE : _props$size,
|
|
37
|
+
_props$level = props.level,
|
|
38
|
+
level = _props$level === void 0 ? DEFAULT_LEVEL : _props$level,
|
|
39
|
+
_props$bgColor = props.bgColor,
|
|
40
|
+
bgColor = _props$bgColor === void 0 ? DEFAULT_BGCOLOR : _props$bgColor,
|
|
41
|
+
_props$fgColor = props.fgColor,
|
|
42
|
+
fgColor = _props$fgColor === void 0 ? DEFAULT_FGCOLOR : _props$fgColor,
|
|
43
|
+
_props$includeMargin = props.includeMargin,
|
|
44
|
+
includeMargin = _props$includeMargin === void 0 ? DEFAULT_INCLUDEMARGIN : _props$includeMargin,
|
|
45
|
+
style = props.style,
|
|
46
|
+
imageSettings = props.imageSettings,
|
|
47
|
+
otherProps = _objectWithoutProperties(props, _excluded);
|
|
48
|
+
|
|
49
|
+
var imgSrc = imageSettings === null || imageSettings === void 0 ? void 0 : imageSettings.src;
|
|
50
|
+
|
|
51
|
+
var _canvas = useRef(null);
|
|
52
|
+
|
|
53
|
+
var _image = useRef(null); // We're just using this state to trigger rerenders when images load. We
|
|
54
|
+
// Don't actually read the value anywhere. A smarter use of useEffect would
|
|
55
|
+
// depend on this value.
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
var _useState = useState(false),
|
|
60
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
61
|
+
isImgLoaded = _useState2[0],
|
|
62
|
+
setIsImageLoaded = _useState2[1];
|
|
63
|
+
|
|
64
|
+
useEffect(function () {
|
|
65
|
+
// Always update the canvas. It's cheap enough and we want to be correct
|
|
66
|
+
// with the current state.
|
|
67
|
+
if (_canvas.current !== null) {
|
|
68
|
+
var canvas = _canvas.current;
|
|
69
|
+
var ctx = canvas.getContext('2d');
|
|
70
|
+
|
|
71
|
+
if (!ctx) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
var cells = qrcodegen.QrCode.encodeText(value, ERROR_LEVEL_MAP[level]).getModules();
|
|
76
|
+
var margin = includeMargin ? MARGIN_SIZE : 0;
|
|
77
|
+
var numCells = cells.length + margin * 2;
|
|
78
|
+
var calculatedImageSettings = getImageSettings(cells, size, includeMargin, imageSettings);
|
|
79
|
+
var image = _image.current;
|
|
80
|
+
var haveImageToRender = calculatedImageSettings != null && image !== null && image.complete && image.naturalHeight !== 0 && image.naturalWidth !== 0;
|
|
81
|
+
|
|
82
|
+
if (haveImageToRender && calculatedImageSettings) {
|
|
83
|
+
if (calculatedImageSettings.excavation != null) {
|
|
84
|
+
cells = excavateModules(cells, calculatedImageSettings.excavation);
|
|
85
|
+
}
|
|
86
|
+
} // We're going to scale this so that the number of drawable units
|
|
87
|
+
// matches the number of cells. This avoids rounding issues, but does
|
|
88
|
+
// result in some potentially unwanted single pixel issues between
|
|
89
|
+
// blocks, only in environments that don't support Path2D.
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
var pixelRatio = window.devicePixelRatio || 1;
|
|
93
|
+
canvas.height = canvas.width = size * pixelRatio;
|
|
94
|
+
var scale = size / numCells * pixelRatio;
|
|
95
|
+
ctx.scale(scale, scale); // Draw solid background, only paint dark modules.
|
|
96
|
+
|
|
97
|
+
ctx.fillStyle = bgColor;
|
|
98
|
+
ctx.fillRect(0, 0, numCells, numCells);
|
|
99
|
+
ctx.fillStyle = fgColor;
|
|
100
|
+
|
|
101
|
+
if (SUPPORTS_PATH2D) {
|
|
102
|
+
// $FlowFixMe: Path2D c'tor doesn't support args yet.
|
|
103
|
+
ctx.fill(new Path2D(generatePath(cells, margin)));
|
|
104
|
+
} else {
|
|
105
|
+
cells.forEach(function (row, rdx) {
|
|
106
|
+
row.forEach(function (cell, cdx) {
|
|
107
|
+
if (cell) {
|
|
108
|
+
ctx.fillRect(cdx + margin, rdx + margin, 1, 1);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (haveImageToRender && calculatedImageSettings) {
|
|
115
|
+
if (image instanceof HTMLImageElement) {
|
|
116
|
+
ctx.drawImage(image, calculatedImageSettings.x + margin, calculatedImageSettings.y + margin, calculatedImageSettings.w, calculatedImageSettings.h);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}); // Ensure we mark image loaded as false here so we trigger updating the
|
|
121
|
+
// canvas in our other effect.
|
|
122
|
+
|
|
123
|
+
useEffect(function () {
|
|
124
|
+
setIsImageLoaded(false);
|
|
125
|
+
}, [imgSrc, isImgLoaded]);
|
|
126
|
+
|
|
127
|
+
var canvasStyle = _extends({
|
|
128
|
+
height: size,
|
|
129
|
+
width: size
|
|
130
|
+
}, style);
|
|
131
|
+
|
|
132
|
+
var img;
|
|
133
|
+
|
|
134
|
+
if (imgSrc != null) {
|
|
135
|
+
img = /*#__PURE__*/React.createElement("img", {
|
|
136
|
+
src: imgSrc,
|
|
137
|
+
key: imgSrc,
|
|
138
|
+
style: {
|
|
139
|
+
display: 'none'
|
|
140
|
+
},
|
|
141
|
+
onLoad: function onLoad() {
|
|
142
|
+
setIsImageLoaded(true);
|
|
143
|
+
},
|
|
144
|
+
ref: _image
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("canvas", _extends({
|
|
149
|
+
style: canvasStyle,
|
|
150
|
+
height: size,
|
|
151
|
+
width: size,
|
|
152
|
+
ref: _canvas
|
|
153
|
+
}, otherProps)), img);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function QrCodeViewerSVG(props) {
|
|
157
|
+
var value = props.value,
|
|
158
|
+
_props$size2 = props.size,
|
|
159
|
+
size = _props$size2 === void 0 ? DEFAULT_SIZE : _props$size2,
|
|
160
|
+
_props$level2 = props.level,
|
|
161
|
+
level = _props$level2 === void 0 ? DEFAULT_LEVEL : _props$level2,
|
|
162
|
+
_props$bgColor2 = props.bgColor,
|
|
163
|
+
bgColor = _props$bgColor2 === void 0 ? DEFAULT_BGCOLOR : _props$bgColor2,
|
|
164
|
+
_props$fgColor2 = props.fgColor,
|
|
165
|
+
fgColor = _props$fgColor2 === void 0 ? DEFAULT_FGCOLOR : _props$fgColor2,
|
|
166
|
+
_props$includeMargin2 = props.includeMargin,
|
|
167
|
+
includeMargin = _props$includeMargin2 === void 0 ? DEFAULT_INCLUDEMARGIN : _props$includeMargin2,
|
|
168
|
+
imageSettings = props.imageSettings,
|
|
169
|
+
otherProps = _objectWithoutProperties(props, _excluded2);
|
|
170
|
+
|
|
171
|
+
var cells = qrcodegen.QrCode.encodeText(value, ERROR_LEVEL_MAP[level]).getModules();
|
|
172
|
+
var margin = includeMargin ? MARGIN_SIZE : 0;
|
|
173
|
+
var numCells = cells.length + margin * 2;
|
|
174
|
+
var calculatedImageSettings = getImageSettings(cells, size, includeMargin, imageSettings);
|
|
175
|
+
var image;
|
|
176
|
+
|
|
177
|
+
if (imageSettings != null && calculatedImageSettings != null) {
|
|
178
|
+
if (calculatedImageSettings.excavation != null) {
|
|
179
|
+
cells = excavateModules(cells, calculatedImageSettings.excavation);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
image = /*#__PURE__*/React.createElement("image", {
|
|
183
|
+
xlinkHref: imageSettings.src,
|
|
184
|
+
height: calculatedImageSettings.h,
|
|
185
|
+
width: calculatedImageSettings.w,
|
|
186
|
+
x: calculatedImageSettings.x + margin,
|
|
187
|
+
y: calculatedImageSettings.y + margin,
|
|
188
|
+
preserveAspectRatio: "none"
|
|
189
|
+
});
|
|
190
|
+
} // Drawing strategy: instead of a rect per module, we're going to create a
|
|
191
|
+
// single path for the dark modules and layer that on top of a light rect,
|
|
192
|
+
// for a total of 2 DOM nodes. We pay a bit more in string concat but that's
|
|
193
|
+
// way faster than DOM ops.
|
|
194
|
+
// For level 1, 441 nodes -> 2
|
|
195
|
+
// For level 40, 31329 -> 2
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
var fgPath = generatePath(cells, margin);
|
|
199
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
200
|
+
height: size,
|
|
201
|
+
width: size,
|
|
202
|
+
viewBox: "0 0 ".concat(numCells, " ").concat(numCells)
|
|
203
|
+
}, otherProps), /*#__PURE__*/React.createElement("path", {
|
|
204
|
+
fill: bgColor,
|
|
205
|
+
d: "M0,0 h".concat(numCells, "v").concat(numCells, "H0z"),
|
|
206
|
+
shapeRendering: "crispEdges"
|
|
207
|
+
}), /*#__PURE__*/React.createElement("path", {
|
|
208
|
+
fill: fgColor,
|
|
209
|
+
d: fgPath,
|
|
210
|
+
shapeRendering: "crispEdges"
|
|
211
|
+
}), image);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export var QrCodeViewer = function QrCodeViewer(props) {
|
|
215
|
+
var renderAs = props.renderAs,
|
|
216
|
+
otherProps = _objectWithoutProperties(props, _excluded3);
|
|
217
|
+
|
|
218
|
+
if (renderAs === 'svg') {
|
|
219
|
+
return /*#__PURE__*/React.createElement(QrCodeViewerSVG, otherProps);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return /*#__PURE__*/React.createElement(QrCodeViewerCanvas, otherProps);
|
|
223
|
+
};
|
|
224
|
+
export default QrCodeViewer;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: qr-code
|
|
3
|
+
title: QrCodeViewer
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
import QrCodeViewer from '@digigov/ui/app/QrCodeViewer';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## How to use
|
|
12
|
+
|
|
13
|
+
### Default QrCodeViewer
|
|
14
|
+
|
|
15
|
+
<Story packageName="@digigov/ui" component="app/QrCodeViewer" story="Default.tsx" />
|
|
16
|
+
|
|
17
|
+
### Custom QrCodeViewer
|
|
18
|
+
|
|
19
|
+
<Story packageName="@digigov/ui" component="app/QrCodeViewer" story="Custom.tsx" />
|
|
20
|
+
|
|
21
|
+
|