@digigov/ui 0.26.2 → 0.26.4

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.
Files changed (84) hide show
  1. package/CHANGELOG.md +18 -1
  2. package/admin/AutoComplete/index.d.ts +3 -3
  3. package/admin/AutoComplete/index.js +16 -6
  4. package/admin/CopyToClipboard/__stories__/Default.js +3 -3
  5. package/admin/CopyToClipboard/__stories__/MultipleCopies.js +3 -3
  6. package/admin/CopyToClipboard/index.d.ts +3 -2
  7. package/admin/CopyToClipboard/index.js +6 -4
  8. package/app/Footer/Footer.stories.d.ts +1 -0
  9. package/app/Footer/Footer.stories.js +14 -0
  10. package/app/Footer/__stories__/FooterWithLogo.js +1 -1
  11. package/app/Footer/__stories__/FooterWithSecondaryNavigation.js +1 -1
  12. package/app/Footer/__stories__/YearCopyright.d.ts +2 -0
  13. package/app/Footer/__stories__/YearCopyright.js +44 -0
  14. package/app/QrCodeViewer/QRCode.stories.d.ts +8 -0
  15. package/app/QrCodeViewer/QRCode.stories.js +46 -0
  16. package/app/QrCodeViewer/__stories__/Custom.d.ts +2 -0
  17. package/app/QrCodeViewer/__stories__/Custom.js +37 -0
  18. package/app/QrCodeViewer/__stories__/Default.d.ts +2 -0
  19. package/app/QrCodeViewer/__stories__/Default.js +24 -0
  20. package/app/QrCodeViewer/index.d.ts +8 -0
  21. package/app/QrCodeViewer/index.js +248 -0
  22. package/app/QrCodeViewer/index.mdx +21 -0
  23. package/app/QrCodeViewer/qrcodegen.d.ts +100 -0
  24. package/app/QrCodeViewer/qrcodegen.js +1086 -0
  25. package/app/QrCodeViewer/types.d.ts +29 -0
  26. package/app/QrCodeViewer/types.js +5 -0
  27. package/app/QrCodeViewer/utils.d.ts +11 -0
  28. package/app/QrCodeViewer/utils.js +108 -0
  29. package/app/index.d.ts +1 -0
  30. package/app/index.js +13 -0
  31. package/core/FileUpload/index.d.ts +1 -0
  32. package/core/FileUpload/index.js +14 -0
  33. package/es/admin/AutoComplete/index.js +16 -6
  34. package/es/admin/CopyToClipboard/__stories__/Default.js +2 -2
  35. package/es/admin/CopyToClipboard/__stories__/MultipleCopies.js +3 -3
  36. package/es/admin/CopyToClipboard/index.js +6 -4
  37. package/es/app/Footer/Footer.stories.js +2 -1
  38. package/es/app/Footer/__stories__/FooterWithLogo.js +1 -1
  39. package/es/app/Footer/__stories__/FooterWithSecondaryNavigation.js +1 -1
  40. package/es/app/Footer/__stories__/YearCopyright.js +22 -0
  41. package/es/app/QrCodeViewer/QRCode.stories.js +8 -0
  42. package/es/app/QrCodeViewer/__stories__/Custom.js +22 -0
  43. package/es/app/QrCodeViewer/__stories__/Default.js +11 -0
  44. package/es/app/QrCodeViewer/index.js +224 -0
  45. package/es/app/QrCodeViewer/index.mdx +21 -0
  46. package/es/app/QrCodeViewer/qrcodegen.js +1085 -0
  47. package/es/app/QrCodeViewer/types.js +1 -0
  48. package/es/app/QrCodeViewer/utils.js +95 -0
  49. package/es/app/index.js +1 -0
  50. package/es/core/FileUpload/index.js +1 -0
  51. package/es/govgr/Footer/Copyright.js +7 -10
  52. package/es/layouts/Grid/__stories__/Default.js +19 -18
  53. package/es/layouts/Grid/__stories__/Inline.js +19 -18
  54. package/es/registry.js +8 -0
  55. package/esm/admin/AutoComplete/index.js +16 -6
  56. package/esm/admin/CopyToClipboard/__stories__/Default.js +2 -2
  57. package/esm/admin/CopyToClipboard/__stories__/MultipleCopies.js +3 -3
  58. package/esm/admin/CopyToClipboard/index.js +6 -4
  59. package/esm/app/Footer/Footer.stories.js +2 -1
  60. package/esm/app/Footer/__stories__/FooterWithLogo.js +1 -1
  61. package/esm/app/Footer/__stories__/FooterWithSecondaryNavigation.js +1 -1
  62. package/esm/app/Footer/__stories__/YearCopyright.js +22 -0
  63. package/esm/app/QrCodeViewer/QRCode.stories.js +8 -0
  64. package/esm/app/QrCodeViewer/__stories__/Custom.js +22 -0
  65. package/esm/app/QrCodeViewer/__stories__/Default.js +11 -0
  66. package/esm/app/QrCodeViewer/index.js +224 -0
  67. package/esm/app/QrCodeViewer/index.mdx +21 -0
  68. package/esm/app/QrCodeViewer/qrcodegen.js +1085 -0
  69. package/esm/app/QrCodeViewer/types.js +1 -0
  70. package/esm/app/QrCodeViewer/utils.js +95 -0
  71. package/esm/app/index.js +1 -0
  72. package/esm/core/FileUpload/index.js +1 -0
  73. package/esm/govgr/Footer/Copyright.js +7 -10
  74. package/esm/index.js +1 -1
  75. package/esm/layouts/Grid/__stories__/Default.js +19 -18
  76. package/esm/layouts/Grid/__stories__/Inline.js +19 -18
  77. package/esm/registry.js +8 -0
  78. package/govgr/Footer/Copyright.d.ts +1 -0
  79. package/govgr/Footer/Copyright.js +9 -8
  80. package/layouts/Grid/__stories__/Default.js +20 -18
  81. package/layouts/Grid/__stories__/Inline.js +20 -18
  82. package/package.json +3 -3
  83. package/registry.d.ts +4 -0
  84. package/registry.js +12 -0
@@ -0,0 +1,248 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports["default"] = exports.QrCodeViewer = void 0;
11
+
12
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
+
14
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
+
16
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
17
+
18
+ var _react = _interopRequireWildcard(require("react"));
19
+
20
+ var _qrcodegen = _interopRequireDefault(require("@digigov/ui/app/QrCodeViewer/qrcodegen"));
21
+
22
+ var _utils = require("@digigov/ui/app/QrCodeViewer/utils");
23
+
24
+ var _excluded = ["value", "size", "level", "bgColor", "fgColor", "includeMargin", "style", "imageSettings"],
25
+ _excluded2 = ["value", "size", "level", "bgColor", "fgColor", "includeMargin", "imageSettings"],
26
+ _excluded3 = ["renderAs"];
27
+
28
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
29
+
30
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
31
+
32
+ var DEFAULT_SIZE = 128;
33
+ var DEFAULT_LEVEL = 'L';
34
+ var DEFAULT_BGCOLOR = '#FFFFFF';
35
+ var DEFAULT_FGCOLOR = '#000000';
36
+ var DEFAULT_INCLUDEMARGIN = false;
37
+
38
+ var SUPPORTS_PATH2D = function () {
39
+ try {
40
+ new Path2D().addPath(new Path2D());
41
+ } catch (e) {
42
+ return false;
43
+ }
44
+
45
+ return true;
46
+ }();
47
+
48
+ var ERROR_LEVEL_MAP = {
49
+ L: _qrcodegen["default"].QrCode.Ecc.LOW,
50
+ M: _qrcodegen["default"].QrCode.Ecc.MEDIUM,
51
+ Q: _qrcodegen["default"].QrCode.Ecc.QUARTILE,
52
+ H: _qrcodegen["default"].QrCode.Ecc.HIGH
53
+ };
54
+
55
+ function QrCodeViewerCanvas(props) {
56
+ var value = props.value,
57
+ _props$size = props.size,
58
+ size = _props$size === void 0 ? DEFAULT_SIZE : _props$size,
59
+ _props$level = props.level,
60
+ level = _props$level === void 0 ? DEFAULT_LEVEL : _props$level,
61
+ _props$bgColor = props.bgColor,
62
+ bgColor = _props$bgColor === void 0 ? DEFAULT_BGCOLOR : _props$bgColor,
63
+ _props$fgColor = props.fgColor,
64
+ fgColor = _props$fgColor === void 0 ? DEFAULT_FGCOLOR : _props$fgColor,
65
+ _props$includeMargin = props.includeMargin,
66
+ includeMargin = _props$includeMargin === void 0 ? DEFAULT_INCLUDEMARGIN : _props$includeMargin,
67
+ style = props.style,
68
+ imageSettings = props.imageSettings,
69
+ otherProps = (0, _objectWithoutProperties2["default"])(props, _excluded);
70
+ var imgSrc = imageSettings === null || imageSettings === void 0 ? void 0 : imageSettings.src;
71
+
72
+ var _canvas = (0, _react.useRef)(null);
73
+
74
+ var _image = (0, _react.useRef)(null); // We're just using this state to trigger rerenders when images load. We
75
+ // Don't actually read the value anywhere. A smarter use of useEffect would
76
+ // depend on this value.
77
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
78
+
79
+
80
+ var _useState = (0, _react.useState)(false),
81
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
82
+ isImgLoaded = _useState2[0],
83
+ setIsImageLoaded = _useState2[1];
84
+
85
+ (0, _react.useEffect)(function () {
86
+ // Always update the canvas. It's cheap enough and we want to be correct
87
+ // with the current state.
88
+ if (_canvas.current !== null) {
89
+ var canvas = _canvas.current;
90
+ var ctx = canvas.getContext('2d');
91
+
92
+ if (!ctx) {
93
+ return;
94
+ }
95
+
96
+ var cells = _qrcodegen["default"].QrCode.encodeText(value, ERROR_LEVEL_MAP[level]).getModules();
97
+
98
+ var margin = includeMargin ? _utils.MARGIN_SIZE : 0;
99
+ var numCells = cells.length + margin * 2;
100
+ var calculatedImageSettings = (0, _utils.getImageSettings)(cells, size, includeMargin, imageSettings);
101
+ var image = _image.current;
102
+ var haveImageToRender = calculatedImageSettings != null && image !== null && image.complete && image.naturalHeight !== 0 && image.naturalWidth !== 0;
103
+
104
+ if (haveImageToRender && calculatedImageSettings) {
105
+ if (calculatedImageSettings.excavation != null) {
106
+ cells = (0, _utils.excavateModules)(cells, calculatedImageSettings.excavation);
107
+ }
108
+ } // We're going to scale this so that the number of drawable units
109
+ // matches the number of cells. This avoids rounding issues, but does
110
+ // result in some potentially unwanted single pixel issues between
111
+ // blocks, only in environments that don't support Path2D.
112
+
113
+
114
+ var pixelRatio = window.devicePixelRatio || 1;
115
+ canvas.height = canvas.width = size * pixelRatio;
116
+ var scale = size / numCells * pixelRatio;
117
+ ctx.scale(scale, scale); // Draw solid background, only paint dark modules.
118
+
119
+ ctx.fillStyle = bgColor;
120
+ ctx.fillRect(0, 0, numCells, numCells);
121
+ ctx.fillStyle = fgColor;
122
+
123
+ if (SUPPORTS_PATH2D) {
124
+ // $FlowFixMe: Path2D c'tor doesn't support args yet.
125
+ ctx.fill(new Path2D((0, _utils.generatePath)(cells, margin)));
126
+ } else {
127
+ cells.forEach(function (row, rdx) {
128
+ row.forEach(function (cell, cdx) {
129
+ if (cell) {
130
+ ctx.fillRect(cdx + margin, rdx + margin, 1, 1);
131
+ }
132
+ });
133
+ });
134
+ }
135
+
136
+ if (haveImageToRender && calculatedImageSettings) {
137
+ if (image instanceof HTMLImageElement) {
138
+ ctx.drawImage(image, calculatedImageSettings.x + margin, calculatedImageSettings.y + margin, calculatedImageSettings.w, calculatedImageSettings.h);
139
+ }
140
+ }
141
+ }
142
+ }); // Ensure we mark image loaded as false here so we trigger updating the
143
+ // canvas in our other effect.
144
+
145
+ (0, _react.useEffect)(function () {
146
+ setIsImageLoaded(false);
147
+ }, [imgSrc, isImgLoaded]);
148
+ var canvasStyle = (0, _extends2["default"])({
149
+ height: size,
150
+ width: size
151
+ }, style);
152
+ var img;
153
+
154
+ if (imgSrc != null) {
155
+ img = /*#__PURE__*/_react["default"].createElement("img", {
156
+ src: imgSrc,
157
+ key: imgSrc,
158
+ style: {
159
+ display: 'none'
160
+ },
161
+ onLoad: function onLoad() {
162
+ setIsImageLoaded(true);
163
+ },
164
+ ref: _image
165
+ });
166
+ }
167
+
168
+ return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("canvas", (0, _extends2["default"])({
169
+ style: canvasStyle,
170
+ height: size,
171
+ width: size,
172
+ ref: _canvas
173
+ }, otherProps)), img);
174
+ }
175
+
176
+ function QrCodeViewerSVG(props) {
177
+ var value = props.value,
178
+ _props$size2 = props.size,
179
+ size = _props$size2 === void 0 ? DEFAULT_SIZE : _props$size2,
180
+ _props$level2 = props.level,
181
+ level = _props$level2 === void 0 ? DEFAULT_LEVEL : _props$level2,
182
+ _props$bgColor2 = props.bgColor,
183
+ bgColor = _props$bgColor2 === void 0 ? DEFAULT_BGCOLOR : _props$bgColor2,
184
+ _props$fgColor2 = props.fgColor,
185
+ fgColor = _props$fgColor2 === void 0 ? DEFAULT_FGCOLOR : _props$fgColor2,
186
+ _props$includeMargin2 = props.includeMargin,
187
+ includeMargin = _props$includeMargin2 === void 0 ? DEFAULT_INCLUDEMARGIN : _props$includeMargin2,
188
+ imageSettings = props.imageSettings,
189
+ otherProps = (0, _objectWithoutProperties2["default"])(props, _excluded2);
190
+
191
+ var cells = _qrcodegen["default"].QrCode.encodeText(value, ERROR_LEVEL_MAP[level]).getModules();
192
+
193
+ var margin = includeMargin ? _utils.MARGIN_SIZE : 0;
194
+ var numCells = cells.length + margin * 2;
195
+ var calculatedImageSettings = (0, _utils.getImageSettings)(cells, size, includeMargin, imageSettings);
196
+ var image;
197
+
198
+ if (imageSettings != null && calculatedImageSettings != null) {
199
+ if (calculatedImageSettings.excavation != null) {
200
+ cells = (0, _utils.excavateModules)(cells, calculatedImageSettings.excavation);
201
+ }
202
+
203
+ image = /*#__PURE__*/_react["default"].createElement("image", {
204
+ xlinkHref: imageSettings.src,
205
+ height: calculatedImageSettings.h,
206
+ width: calculatedImageSettings.w,
207
+ x: calculatedImageSettings.x + margin,
208
+ y: calculatedImageSettings.y + margin,
209
+ preserveAspectRatio: "none"
210
+ });
211
+ } // Drawing strategy: instead of a rect per module, we're going to create a
212
+ // single path for the dark modules and layer that on top of a light rect,
213
+ // for a total of 2 DOM nodes. We pay a bit more in string concat but that's
214
+ // way faster than DOM ops.
215
+ // For level 1, 441 nodes -> 2
216
+ // For level 40, 31329 -> 2
217
+
218
+
219
+ var fgPath = (0, _utils.generatePath)(cells, margin);
220
+ return /*#__PURE__*/_react["default"].createElement("svg", (0, _extends2["default"])({
221
+ height: size,
222
+ width: size,
223
+ viewBox: "0 0 ".concat(numCells, " ").concat(numCells)
224
+ }, otherProps), /*#__PURE__*/_react["default"].createElement("path", {
225
+ fill: bgColor,
226
+ d: "M0,0 h".concat(numCells, "v").concat(numCells, "H0z"),
227
+ shapeRendering: "crispEdges"
228
+ }), /*#__PURE__*/_react["default"].createElement("path", {
229
+ fill: fgColor,
230
+ d: fgPath,
231
+ shapeRendering: "crispEdges"
232
+ }), image);
233
+ }
234
+
235
+ var QrCodeViewer = function QrCodeViewer(props) {
236
+ var renderAs = props.renderAs,
237
+ otherProps = (0, _objectWithoutProperties2["default"])(props, _excluded3);
238
+
239
+ if (renderAs === 'svg') {
240
+ return /*#__PURE__*/_react["default"].createElement(QrCodeViewerSVG, otherProps);
241
+ }
242
+
243
+ return /*#__PURE__*/_react["default"].createElement(QrCodeViewerCanvas, otherProps);
244
+ };
245
+
246
+ exports.QrCodeViewer = QrCodeViewer;
247
+ var _default = QrCodeViewer;
248
+ exports["default"] = _default;
@@ -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
+
@@ -0,0 +1,100 @@
1
+ /**
2
+ * @license QR Code generator library (TypeScript)
3
+ * Copyright (c) Project Nayuki.
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ declare namespace qrcodegen {
7
+ type bit = number;
8
+ type byte = number;
9
+ type int = number;
10
+ export class QrCode {
11
+ static encodeText(text: string, ecl: QrCode.Ecc): QrCode;
12
+ static encodeBinary(data: Readonly<Array<byte>>, ecl: QrCode.Ecc): QrCode;
13
+ static encodeSegments(segs: Readonly<Array<QrSegment>>, ecl: QrCode.Ecc, minVersion?: int, maxVersion?: int, mask?: int, boostEcl?: boolean): QrCode;
14
+ readonly version: int;
15
+ readonly errorCorrectionLevel: QrCode.Ecc;
16
+ readonly size: int;
17
+ readonly mask: int;
18
+ private readonly modules;
19
+ private readonly isFunction;
20
+ constructor(version: int, errorCorrectionLevel: QrCode.Ecc, dataCodewords: Readonly<Array<byte>>, msk: int);
21
+ getModule(x: int, y: int): boolean;
22
+ getModules(): boolean[][];
23
+ private drawFunctionPatterns;
24
+ private drawFormatBits;
25
+ private drawVersion;
26
+ private drawFinderPattern;
27
+ private drawAlignmentPattern;
28
+ private setFunctionModule;
29
+ private addEccAndInterleave;
30
+ private drawCodewords;
31
+ private applyMask;
32
+ private getPenaltyScore;
33
+ private getAlignmentPatternPositions;
34
+ private static getNumRawDataModules;
35
+ private static getNumDataCodewords;
36
+ private static reedSolomonComputeDivisor;
37
+ private static reedSolomonComputeRemainder;
38
+ private static reedSolomonMultiply;
39
+ private finderPenaltyCountPatterns;
40
+ private finderPenaltyTerminateAndCount;
41
+ private finderPenaltyAddHistory;
42
+ static readonly MIN_VERSION: int;
43
+ static readonly MAX_VERSION: int;
44
+ private static readonly PENALTY_N1;
45
+ private static readonly PENALTY_N2;
46
+ private static readonly PENALTY_N3;
47
+ private static readonly PENALTY_N4;
48
+ private static readonly ECC_CODEWORDS_PER_BLOCK;
49
+ private static readonly NUM_ERROR_CORRECTION_BLOCKS;
50
+ }
51
+ export class QrSegment {
52
+ static makeBytes(data: Readonly<Array<byte>>): QrSegment;
53
+ static makeNumeric(digits: string): QrSegment;
54
+ static makeAlphanumeric(text: string): QrSegment;
55
+ static makeSegments(text: string): Array<QrSegment>;
56
+ static makeEci(assignVal: int): QrSegment;
57
+ static isNumeric(text: string): boolean;
58
+ static isAlphanumeric(text: string): boolean;
59
+ readonly mode: QrSegment.Mode;
60
+ readonly numChars: int;
61
+ private readonly bitData;
62
+ constructor(mode: QrSegment.Mode, numChars: int, bitData: Array<bit>);
63
+ getData(): Array<bit>;
64
+ static getTotalBits(segs: Readonly<Array<QrSegment>>, version: int): number;
65
+ private static toUtf8ByteArray;
66
+ private static readonly NUMERIC_REGEX;
67
+ private static readonly ALPHANUMERIC_REGEX;
68
+ private static readonly ALPHANUMERIC_CHARSET;
69
+ }
70
+ export {};
71
+ }
72
+ declare namespace qrcodegen.QrCode {
73
+ type int = number;
74
+ export class Ecc {
75
+ static readonly LOW: Ecc;
76
+ static readonly MEDIUM: Ecc;
77
+ static readonly QUARTILE: Ecc;
78
+ static readonly HIGH: Ecc;
79
+ readonly ordinal: int;
80
+ readonly formatBits: int;
81
+ private constructor();
82
+ }
83
+ export {};
84
+ }
85
+ declare namespace qrcodegen.QrSegment {
86
+ type int = number;
87
+ export class Mode {
88
+ static readonly NUMERIC: Mode;
89
+ static readonly ALPHANUMERIC: Mode;
90
+ static readonly BYTE: Mode;
91
+ static readonly KANJI: Mode;
92
+ static readonly ECI: Mode;
93
+ readonly modeBits: int;
94
+ private readonly numBitsCharCount;
95
+ private constructor();
96
+ numCharCountBits(ver: int): int;
97
+ }
98
+ export {};
99
+ }
100
+ export default qrcodegen;