@bigbinary/neeto-molecules 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BrowserSupport.cjs.js +2 -1462
- package/dist/BrowserSupport.js +2 -1456
- package/dist/Columns.cjs.js +1 -183
- package/dist/Columns.js +1 -177
- package/dist/CustomDomain.cjs.js +2 -753
- package/dist/CustomDomain.js +2 -727
- package/dist/DateFormat.cjs.js +1 -46
- package/dist/DateFormat.js +1 -40
- package/dist/DateRangeFilter.cjs.js +1 -233
- package/dist/DateRangeFilter.js +1 -226
- package/dist/DynamicVariables.cjs.js +1 -112
- package/dist/DynamicVariables.js +1 -106
- package/dist/EmailPreview.cjs.js +1 -89
- package/dist/EmailPreview.js +1 -83
- package/dist/ErrorPage.cjs.js +1 -189
- package/dist/ErrorPage.js +1 -165
- package/dist/IpRestriction.cjs.js +1 -3578
- package/dist/IpRestriction.js +1 -3552
- package/dist/KeyboardShortcuts.cjs.js +6 -2193
- package/dist/KeyboardShortcuts.js +6 -2186
- package/dist/LoginPage.cjs.js +1 -598
- package/dist/LoginPage.js +1 -573
- package/dist/NeetoWidget.cjs.js +3 -86957
- package/dist/NeetoWidget.js +3 -86931
- package/dist/PublishBlock.cjs.js +2 -184
- package/dist/PublishBlock.js +2 -178
- package/dist/Schedule.cjs.js +1 -950
- package/dist/Schedule.js +1 -919
- package/dist/ShareViaEmail.cjs.js +2 -2832
- package/dist/ShareViaEmail.js +2 -2805
- package/dist/ShareViaLink.cjs.js +2 -1243
- package/dist/ShareViaLink.js +2 -1237
- package/dist/Sidebar.cjs.js +1 -222
- package/dist/Sidebar.js +1 -195
- package/dist/TimeFormat.cjs.js +1 -11
- package/dist/TimeFormat.js +1 -5
- package/package.json +2 -1
- package/src/translations/en.json +0 -1
- package/types/ShareViaEmail.d.ts +9 -2
package/dist/ShareViaLink.cjs.js
CHANGED
|
@@ -1,1247 +1,6 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var React = require('react');
|
|
4
|
-
var pure = require('@bigbinary/neeto-commons-frontend/pure');
|
|
5
|
-
var utils = require('@bigbinary/neeto-commons-frontend/utils');
|
|
6
|
-
var neetoIcons = require('@bigbinary/neeto-icons');
|
|
7
|
-
var neetoui = require('@bigbinary/neetoui');
|
|
8
|
-
var reactI18next = require('react-i18next');
|
|
9
|
-
|
|
10
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
-
|
|
12
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
13
|
-
|
|
14
|
-
function _arrayWithHoles(arr) {
|
|
15
|
-
if (Array.isArray(arr)) return arr;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _iterableToArrayLimit(arr, i) {
|
|
19
|
-
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
|
|
20
|
-
if (null != _i) {
|
|
21
|
-
var _s,
|
|
22
|
-
_e,
|
|
23
|
-
_x,
|
|
24
|
-
_r,
|
|
25
|
-
_arr = [],
|
|
26
|
-
_n = !0,
|
|
27
|
-
_d = !1;
|
|
28
|
-
try {
|
|
29
|
-
if (_x = (_i = _i.call(arr)).next, 0 === i) {
|
|
30
|
-
if (Object(_i) !== _i) return;
|
|
31
|
-
_n = !1;
|
|
32
|
-
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
|
|
33
|
-
} catch (err) {
|
|
34
|
-
_d = !0, _e = err;
|
|
35
|
-
} finally {
|
|
36
|
-
try {
|
|
37
|
-
if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return;
|
|
38
|
-
} finally {
|
|
39
|
-
if (_d) throw _e;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return _arr;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function _arrayLikeToArray(arr, len) {
|
|
47
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
48
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
49
|
-
return arr2;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
53
|
-
if (!o) return;
|
|
54
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
55
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
56
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
57
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
58
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function _nonIterableRest() {
|
|
62
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function _slicedToArray(arr, i) {
|
|
66
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
var RegenerateURL = function RegenerateURL(_ref) {
|
|
70
|
-
var isOpen = _ref.isOpen,
|
|
71
|
-
onClose = _ref.onClose,
|
|
72
|
-
url = _ref.url,
|
|
73
|
-
isRegenerating = _ref.isRegenerating,
|
|
74
|
-
handleRegenerate = _ref.handleRegenerate;
|
|
75
|
-
var _useTranslation = reactI18next.useTranslation(),
|
|
76
|
-
t = _useTranslation.t;
|
|
77
|
-
return /*#__PURE__*/React__default["default"].createElement(neetoui.Modal, {
|
|
78
|
-
"data-testid": "regenerate-url-modal",
|
|
79
|
-
isOpen: isOpen,
|
|
80
|
-
onClose: onClose
|
|
81
|
-
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Modal.Header, null, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
82
|
-
lineHeight: "normal",
|
|
83
|
-
style: "h2",
|
|
84
|
-
weight: "semibold"
|
|
85
|
-
}, t("neetoMolecules.shareViaLink.regenerateUrl.title"))), /*#__PURE__*/React__default["default"].createElement(neetoui.Modal.Body, null, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
86
|
-
className: "w-full space-y-6"
|
|
87
|
-
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Input, {
|
|
88
|
-
disabled: true,
|
|
89
|
-
label: t("neetoMolecules.shareViaLink.regenerateUrl.inputLabel"),
|
|
90
|
-
value: url
|
|
91
|
-
}), /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
92
|
-
className: "neeto-ui-text-gray-700",
|
|
93
|
-
lineHeight: "normal",
|
|
94
|
-
style: "body2"
|
|
95
|
-
}, t("neetoMolecules.shareViaLink.regenerateUrl.description")), /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
96
|
-
className: "neeto-ui-text-gray-700",
|
|
97
|
-
lineHeight: "normal",
|
|
98
|
-
style: "body2"
|
|
99
|
-
}, t("neetoMolecules.shareViaLink.regenerateUrl.confirmation")))), /*#__PURE__*/React__default["default"].createElement(neetoui.Modal.Footer, {
|
|
100
|
-
className: "space-x-2"
|
|
101
|
-
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
|
|
102
|
-
"data-testid": "regenerate-url-confirm-button",
|
|
103
|
-
loading: isRegenerating,
|
|
104
|
-
label: t("neetoMolecules.shareViaLink.regenerateUrl.submitButtonLabel"),
|
|
105
|
-
onClick: function onClick() {
|
|
106
|
-
handleRegenerate();
|
|
107
|
-
onClose();
|
|
108
|
-
}
|
|
109
|
-
}), /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
|
|
110
|
-
"data-testid": "regenerate-url-cancel-button",
|
|
111
|
-
style: "text",
|
|
112
|
-
label: t("neetoMolecules.shareViaLink.regenerateUrl.cancelButtonLabel"),
|
|
113
|
-
onClick: onClose
|
|
114
|
-
})));
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
var Menu = neetoui.Dropdown.Menu,
|
|
118
|
-
MenuItem = neetoui.Dropdown.MenuItem;
|
|
119
|
-
var Link = function Link(_ref) {
|
|
120
|
-
var enableRegenerateUrl = _ref.enableRegenerateUrl,
|
|
121
|
-
entityName = _ref.entityName,
|
|
122
|
-
handleRegenerate = _ref.handleRegenerate,
|
|
123
|
-
isRegenerating = _ref.isRegenerating,
|
|
124
|
-
previewUrl = _ref.previewUrl,
|
|
125
|
-
url = _ref.url;
|
|
126
|
-
var _useState = React.useState(false),
|
|
127
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
128
|
-
isRegenerateURLModalOpen = _useState2[0],
|
|
129
|
-
setIsRegenerateURLModalOpen = _useState2[1];
|
|
130
|
-
var _useTranslation = reactI18next.useTranslation(),
|
|
131
|
-
t = _useTranslation.t;
|
|
132
|
-
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
133
|
-
className: "space-y-4",
|
|
134
|
-
"data-testid": "link-block"
|
|
135
|
-
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
136
|
-
className: "space-y-0.5"
|
|
137
|
-
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
138
|
-
"data-testid": "link-title",
|
|
139
|
-
lineHeight: "normal",
|
|
140
|
-
style: "h3",
|
|
141
|
-
weight: "semibold"
|
|
142
|
-
}, t("neetoMolecules.shareViaLink.title")), /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
143
|
-
className: "neeto-ui-text-gray-700",
|
|
144
|
-
"data-testid": "link-description",
|
|
145
|
-
lineHeight: "normal",
|
|
146
|
-
style: "body2"
|
|
147
|
-
}, t("neetoMolecules.shareViaLink.description", {
|
|
148
|
-
entity: entityName
|
|
149
|
-
}))), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
150
|
-
className: "flex items-center gap-1"
|
|
151
|
-
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Input, {
|
|
152
|
-
readOnly: true,
|
|
153
|
-
value: url
|
|
154
|
-
}), /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
|
|
155
|
-
"data-testid": "link-copy-button",
|
|
156
|
-
icon: neetoIcons.Copy,
|
|
157
|
-
label: t("neetoMolecules.shareViaLink.copyLink"),
|
|
158
|
-
onClick: function onClick() {
|
|
159
|
-
return utils.copyToClipboard(url);
|
|
160
|
-
}
|
|
161
|
-
}), /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
|
|
162
|
-
"data-testid": "preview-button",
|
|
163
|
-
href: previewUrl || url,
|
|
164
|
-
icon: neetoIcons.ExternalLink,
|
|
165
|
-
style: "secondary",
|
|
166
|
-
target: "_blank",
|
|
167
|
-
tooltipProps: {
|
|
168
|
-
content: t("neetoMolecules.shareViaLink.open", {
|
|
169
|
-
entity: entityName
|
|
170
|
-
}),
|
|
171
|
-
position: "top"
|
|
172
|
-
}
|
|
173
|
-
}), enableRegenerateUrl && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(neetoui.Dropdown, {
|
|
174
|
-
buttonStyle: "text",
|
|
175
|
-
icon: neetoIcons.MenuHorizontal
|
|
176
|
-
}, /*#__PURE__*/React__default["default"].createElement(Menu, null, /*#__PURE__*/React__default["default"].createElement(MenuItem.Button, {
|
|
177
|
-
"data-testid": "regenerate-url-button",
|
|
178
|
-
onClick: function onClick() {
|
|
179
|
-
return setIsRegenerateURLModalOpen(true);
|
|
180
|
-
}
|
|
181
|
-
}, t("neetoMolecules.shareViaLink.regenerateUrl.title")))), /*#__PURE__*/React__default["default"].createElement(RegenerateURL, {
|
|
182
|
-
handleRegenerate: handleRegenerate,
|
|
183
|
-
isOpen: isRegenerateURLModalOpen,
|
|
184
|
-
isRegenerating: isRegenerating,
|
|
185
|
-
url: url,
|
|
186
|
-
onClose: function onClose() {
|
|
187
|
-
return setIsRegenerateURLModalOpen(false);
|
|
188
|
-
}
|
|
189
|
-
}))));
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
var facebookShareLink = function facebookShareLink(_ref) {
|
|
193
|
-
var id = _ref.id;
|
|
194
|
-
return utils.buildUrl("https://www.facebook.com/sharer/sharer.php", {
|
|
195
|
-
u: "https://".concat(window.location.host, "/").concat(id)
|
|
196
|
-
});
|
|
197
|
-
};
|
|
198
|
-
var linkedInShareLink = function linkedInShareLink(_ref2) {
|
|
199
|
-
var id = _ref2.id,
|
|
200
|
-
title = _ref2.title;
|
|
201
|
-
return utils.buildUrl("https://www.linkedin.com/shareArticle", {
|
|
202
|
-
mini: true,
|
|
203
|
-
url: "https://".concat(window.location.host, "/").concat(id),
|
|
204
|
-
title: title
|
|
205
|
-
});
|
|
206
|
-
};
|
|
207
|
-
var twitterShareLink = function twitterShareLink(_ref3) {
|
|
208
|
-
var id = _ref3.id,
|
|
209
|
-
title = _ref3.title;
|
|
210
|
-
return utils.buildUrl("http://twitter.com/share", {
|
|
211
|
-
text: title,
|
|
212
|
-
url: "https://".concat(window.location.host, "/").concat(id)
|
|
213
|
-
});
|
|
214
|
-
};
|
|
215
|
-
var downloadCanvas = function downloadCanvas(canvas) {
|
|
216
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
217
|
-
var _options$name = options.name,
|
|
218
|
-
name = _options$name === void 0 ? "image" : _options$name,
|
|
219
|
-
_options$extension = options.extension,
|
|
220
|
-
extension = _options$extension === void 0 ? "png" : _options$extension;
|
|
221
|
-
var canvasUrl = canvas.toDataURL("image/".concat(extension));
|
|
222
|
-
var element = document.createElement("a");
|
|
223
|
-
element.href = canvasUrl;
|
|
224
|
-
element.download = "".concat(name, ".").concat(extension);
|
|
225
|
-
element.click();
|
|
226
|
-
element.remove();
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
var SOCIAL_MEDIA_OPTIONS = {
|
|
230
|
-
FACEBOOK: {
|
|
231
|
-
label: "Facebook",
|
|
232
|
-
icon: neetoIcons.Facebook,
|
|
233
|
-
generateShareUrl: facebookShareLink
|
|
234
|
-
},
|
|
235
|
-
LINKEDIN: {
|
|
236
|
-
label: "LinkedIn",
|
|
237
|
-
icon: neetoIcons.Linkedin,
|
|
238
|
-
generateShareUrl: linkedInShareLink
|
|
239
|
-
},
|
|
240
|
-
TWITTER: {
|
|
241
|
-
label: "Twitter",
|
|
242
|
-
icon: neetoIcons.Twitter,
|
|
243
|
-
generateShareUrl: twitterShareLink
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
var __defProp = Object.defineProperty;
|
|
248
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
249
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
250
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
251
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
252
|
-
var __spreadValues = (a, b) => {
|
|
253
|
-
for (var prop in b || (b = {}))
|
|
254
|
-
if (__hasOwnProp.call(b, prop))
|
|
255
|
-
__defNormalProp(a, prop, b[prop]);
|
|
256
|
-
if (__getOwnPropSymbols)
|
|
257
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
258
|
-
if (__propIsEnum.call(b, prop))
|
|
259
|
-
__defNormalProp(a, prop, b[prop]);
|
|
260
|
-
}
|
|
261
|
-
return a;
|
|
262
|
-
};
|
|
263
|
-
var __objRest = (source, exclude) => {
|
|
264
|
-
var target = {};
|
|
265
|
-
for (var prop in source)
|
|
266
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
267
|
-
target[prop] = source[prop];
|
|
268
|
-
if (source != null && __getOwnPropSymbols)
|
|
269
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
270
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
271
|
-
target[prop] = source[prop];
|
|
272
|
-
}
|
|
273
|
-
return target;
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
// src/third-party/qrcodegen/index.ts
|
|
277
|
-
/**
|
|
278
|
-
* @license QR Code generator library (TypeScript)
|
|
279
|
-
* Copyright (c) Project Nayuki.
|
|
280
|
-
* SPDX-License-Identifier: MIT
|
|
281
|
-
*/
|
|
282
|
-
var qrcodegen;
|
|
283
|
-
((qrcodegen2) => {
|
|
284
|
-
const _QrCode = class {
|
|
285
|
-
constructor(version, errorCorrectionLevel, dataCodewords, msk) {
|
|
286
|
-
this.version = version;
|
|
287
|
-
this.errorCorrectionLevel = errorCorrectionLevel;
|
|
288
|
-
this.modules = [];
|
|
289
|
-
this.isFunction = [];
|
|
290
|
-
if (version < _QrCode.MIN_VERSION || version > _QrCode.MAX_VERSION)
|
|
291
|
-
throw new RangeError("Version value out of range");
|
|
292
|
-
if (msk < -1 || msk > 7)
|
|
293
|
-
throw new RangeError("Mask value out of range");
|
|
294
|
-
this.size = version * 4 + 17;
|
|
295
|
-
let row = [];
|
|
296
|
-
for (let i = 0; i < this.size; i++)
|
|
297
|
-
row.push(false);
|
|
298
|
-
for (let i = 0; i < this.size; i++) {
|
|
299
|
-
this.modules.push(row.slice());
|
|
300
|
-
this.isFunction.push(row.slice());
|
|
301
|
-
}
|
|
302
|
-
this.drawFunctionPatterns();
|
|
303
|
-
const allCodewords = this.addEccAndInterleave(dataCodewords);
|
|
304
|
-
this.drawCodewords(allCodewords);
|
|
305
|
-
if (msk == -1) {
|
|
306
|
-
let minPenalty = 1e9;
|
|
307
|
-
for (let i = 0; i < 8; i++) {
|
|
308
|
-
this.applyMask(i);
|
|
309
|
-
this.drawFormatBits(i);
|
|
310
|
-
const penalty = this.getPenaltyScore();
|
|
311
|
-
if (penalty < minPenalty) {
|
|
312
|
-
msk = i;
|
|
313
|
-
minPenalty = penalty;
|
|
314
|
-
}
|
|
315
|
-
this.applyMask(i);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
assert(0 <= msk && msk <= 7);
|
|
319
|
-
this.mask = msk;
|
|
320
|
-
this.applyMask(msk);
|
|
321
|
-
this.drawFormatBits(msk);
|
|
322
|
-
this.isFunction = [];
|
|
323
|
-
}
|
|
324
|
-
static encodeText(text, ecl) {
|
|
325
|
-
const segs = qrcodegen2.QrSegment.makeSegments(text);
|
|
326
|
-
return _QrCode.encodeSegments(segs, ecl);
|
|
327
|
-
}
|
|
328
|
-
static encodeBinary(data, ecl) {
|
|
329
|
-
const seg = qrcodegen2.QrSegment.makeBytes(data);
|
|
330
|
-
return _QrCode.encodeSegments([seg], ecl);
|
|
331
|
-
}
|
|
332
|
-
static encodeSegments(segs, ecl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
|
|
333
|
-
if (!(_QrCode.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= _QrCode.MAX_VERSION) || mask < -1 || mask > 7)
|
|
334
|
-
throw new RangeError("Invalid value");
|
|
335
|
-
let version;
|
|
336
|
-
let dataUsedBits;
|
|
337
|
-
for (version = minVersion; ; version++) {
|
|
338
|
-
const dataCapacityBits2 = _QrCode.getNumDataCodewords(version, ecl) * 8;
|
|
339
|
-
const usedBits = QrSegment.getTotalBits(segs, version);
|
|
340
|
-
if (usedBits <= dataCapacityBits2) {
|
|
341
|
-
dataUsedBits = usedBits;
|
|
342
|
-
break;
|
|
343
|
-
}
|
|
344
|
-
if (version >= maxVersion)
|
|
345
|
-
throw new RangeError("Data too long");
|
|
346
|
-
}
|
|
347
|
-
for (const newEcl of [_QrCode.Ecc.MEDIUM, _QrCode.Ecc.QUARTILE, _QrCode.Ecc.HIGH]) {
|
|
348
|
-
if (boostEcl && dataUsedBits <= _QrCode.getNumDataCodewords(version, newEcl) * 8)
|
|
349
|
-
ecl = newEcl;
|
|
350
|
-
}
|
|
351
|
-
let bb = [];
|
|
352
|
-
for (const seg of segs) {
|
|
353
|
-
appendBits(seg.mode.modeBits, 4, bb);
|
|
354
|
-
appendBits(seg.numChars, seg.mode.numCharCountBits(version), bb);
|
|
355
|
-
for (const b of seg.getData())
|
|
356
|
-
bb.push(b);
|
|
357
|
-
}
|
|
358
|
-
assert(bb.length == dataUsedBits);
|
|
359
|
-
const dataCapacityBits = _QrCode.getNumDataCodewords(version, ecl) * 8;
|
|
360
|
-
assert(bb.length <= dataCapacityBits);
|
|
361
|
-
appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
|
|
362
|
-
appendBits(0, (8 - bb.length % 8) % 8, bb);
|
|
363
|
-
assert(bb.length % 8 == 0);
|
|
364
|
-
for (let padByte = 236; bb.length < dataCapacityBits; padByte ^= 236 ^ 17)
|
|
365
|
-
appendBits(padByte, 8, bb);
|
|
366
|
-
let dataCodewords = [];
|
|
367
|
-
while (dataCodewords.length * 8 < bb.length)
|
|
368
|
-
dataCodewords.push(0);
|
|
369
|
-
bb.forEach((b, i) => dataCodewords[i >>> 3] |= b << 7 - (i & 7));
|
|
370
|
-
return new _QrCode(version, ecl, dataCodewords, mask);
|
|
371
|
-
}
|
|
372
|
-
getModule(x, y) {
|
|
373
|
-
return 0 <= x && x < this.size && 0 <= y && y < this.size && this.modules[y][x];
|
|
374
|
-
}
|
|
375
|
-
getModules() {
|
|
376
|
-
return this.modules;
|
|
377
|
-
}
|
|
378
|
-
drawFunctionPatterns() {
|
|
379
|
-
for (let i = 0; i < this.size; i++) {
|
|
380
|
-
this.setFunctionModule(6, i, i % 2 == 0);
|
|
381
|
-
this.setFunctionModule(i, 6, i % 2 == 0);
|
|
382
|
-
}
|
|
383
|
-
this.drawFinderPattern(3, 3);
|
|
384
|
-
this.drawFinderPattern(this.size - 4, 3);
|
|
385
|
-
this.drawFinderPattern(3, this.size - 4);
|
|
386
|
-
const alignPatPos = this.getAlignmentPatternPositions();
|
|
387
|
-
const numAlign = alignPatPos.length;
|
|
388
|
-
for (let i = 0; i < numAlign; i++) {
|
|
389
|
-
for (let j = 0; j < numAlign; j++) {
|
|
390
|
-
if (!(i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0))
|
|
391
|
-
this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
this.drawFormatBits(0);
|
|
395
|
-
this.drawVersion();
|
|
396
|
-
}
|
|
397
|
-
drawFormatBits(mask) {
|
|
398
|
-
const data = this.errorCorrectionLevel.formatBits << 3 | mask;
|
|
399
|
-
let rem = data;
|
|
400
|
-
for (let i = 0; i < 10; i++)
|
|
401
|
-
rem = rem << 1 ^ (rem >>> 9) * 1335;
|
|
402
|
-
const bits = (data << 10 | rem) ^ 21522;
|
|
403
|
-
assert(bits >>> 15 == 0);
|
|
404
|
-
for (let i = 0; i <= 5; i++)
|
|
405
|
-
this.setFunctionModule(8, i, getBit(bits, i));
|
|
406
|
-
this.setFunctionModule(8, 7, getBit(bits, 6));
|
|
407
|
-
this.setFunctionModule(8, 8, getBit(bits, 7));
|
|
408
|
-
this.setFunctionModule(7, 8, getBit(bits, 8));
|
|
409
|
-
for (let i = 9; i < 15; i++)
|
|
410
|
-
this.setFunctionModule(14 - i, 8, getBit(bits, i));
|
|
411
|
-
for (let i = 0; i < 8; i++)
|
|
412
|
-
this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
|
|
413
|
-
for (let i = 8; i < 15; i++)
|
|
414
|
-
this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
|
|
415
|
-
this.setFunctionModule(8, this.size - 8, true);
|
|
416
|
-
}
|
|
417
|
-
drawVersion() {
|
|
418
|
-
if (this.version < 7)
|
|
419
|
-
return;
|
|
420
|
-
let rem = this.version;
|
|
421
|
-
for (let i = 0; i < 12; i++)
|
|
422
|
-
rem = rem << 1 ^ (rem >>> 11) * 7973;
|
|
423
|
-
const bits = this.version << 12 | rem;
|
|
424
|
-
assert(bits >>> 18 == 0);
|
|
425
|
-
for (let i = 0; i < 18; i++) {
|
|
426
|
-
const color = getBit(bits, i);
|
|
427
|
-
const a = this.size - 11 + i % 3;
|
|
428
|
-
const b = Math.floor(i / 3);
|
|
429
|
-
this.setFunctionModule(a, b, color);
|
|
430
|
-
this.setFunctionModule(b, a, color);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
drawFinderPattern(x, y) {
|
|
434
|
-
for (let dy = -4; dy <= 4; dy++) {
|
|
435
|
-
for (let dx = -4; dx <= 4; dx++) {
|
|
436
|
-
const dist = Math.max(Math.abs(dx), Math.abs(dy));
|
|
437
|
-
const xx = x + dx;
|
|
438
|
-
const yy = y + dy;
|
|
439
|
-
if (0 <= xx && xx < this.size && 0 <= yy && yy < this.size)
|
|
440
|
-
this.setFunctionModule(xx, yy, dist != 2 && dist != 4);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
drawAlignmentPattern(x, y) {
|
|
445
|
-
for (let dy = -2; dy <= 2; dy++) {
|
|
446
|
-
for (let dx = -2; dx <= 2; dx++)
|
|
447
|
-
this.setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
setFunctionModule(x, y, isDark) {
|
|
451
|
-
this.modules[y][x] = isDark;
|
|
452
|
-
this.isFunction[y][x] = true;
|
|
453
|
-
}
|
|
454
|
-
addEccAndInterleave(data) {
|
|
455
|
-
const ver = this.version;
|
|
456
|
-
const ecl = this.errorCorrectionLevel;
|
|
457
|
-
if (data.length != _QrCode.getNumDataCodewords(ver, ecl))
|
|
458
|
-
throw new RangeError("Invalid argument");
|
|
459
|
-
const numBlocks = _QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
|
|
460
|
-
const blockEccLen = _QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver];
|
|
461
|
-
const rawCodewords = Math.floor(_QrCode.getNumRawDataModules(ver) / 8);
|
|
462
|
-
const numShortBlocks = numBlocks - rawCodewords % numBlocks;
|
|
463
|
-
const shortBlockLen = Math.floor(rawCodewords / numBlocks);
|
|
464
|
-
let blocks = [];
|
|
465
|
-
const rsDiv = _QrCode.reedSolomonComputeDivisor(blockEccLen);
|
|
466
|
-
for (let i = 0, k = 0; i < numBlocks; i++) {
|
|
467
|
-
let dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
|
|
468
|
-
k += dat.length;
|
|
469
|
-
const ecc = _QrCode.reedSolomonComputeRemainder(dat, rsDiv);
|
|
470
|
-
if (i < numShortBlocks)
|
|
471
|
-
dat.push(0);
|
|
472
|
-
blocks.push(dat.concat(ecc));
|
|
473
|
-
}
|
|
474
|
-
let result = [];
|
|
475
|
-
for (let i = 0; i < blocks[0].length; i++) {
|
|
476
|
-
blocks.forEach((block, j) => {
|
|
477
|
-
if (i != shortBlockLen - blockEccLen || j >= numShortBlocks)
|
|
478
|
-
result.push(block[i]);
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
assert(result.length == rawCodewords);
|
|
482
|
-
return result;
|
|
483
|
-
}
|
|
484
|
-
drawCodewords(data) {
|
|
485
|
-
if (data.length != Math.floor(_QrCode.getNumRawDataModules(this.version) / 8))
|
|
486
|
-
throw new RangeError("Invalid argument");
|
|
487
|
-
let i = 0;
|
|
488
|
-
for (let right = this.size - 1; right >= 1; right -= 2) {
|
|
489
|
-
if (right == 6)
|
|
490
|
-
right = 5;
|
|
491
|
-
for (let vert = 0; vert < this.size; vert++) {
|
|
492
|
-
for (let j = 0; j < 2; j++) {
|
|
493
|
-
const x = right - j;
|
|
494
|
-
const upward = (right + 1 & 2) == 0;
|
|
495
|
-
const y = upward ? this.size - 1 - vert : vert;
|
|
496
|
-
if (!this.isFunction[y][x] && i < data.length * 8) {
|
|
497
|
-
this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
|
|
498
|
-
i++;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
assert(i == data.length * 8);
|
|
504
|
-
}
|
|
505
|
-
applyMask(mask) {
|
|
506
|
-
if (mask < 0 || mask > 7)
|
|
507
|
-
throw new RangeError("Mask value out of range");
|
|
508
|
-
for (let y = 0; y < this.size; y++) {
|
|
509
|
-
for (let x = 0; x < this.size; x++) {
|
|
510
|
-
let invert;
|
|
511
|
-
switch (mask) {
|
|
512
|
-
case 0:
|
|
513
|
-
invert = (x + y) % 2 == 0;
|
|
514
|
-
break;
|
|
515
|
-
case 1:
|
|
516
|
-
invert = y % 2 == 0;
|
|
517
|
-
break;
|
|
518
|
-
case 2:
|
|
519
|
-
invert = x % 3 == 0;
|
|
520
|
-
break;
|
|
521
|
-
case 3:
|
|
522
|
-
invert = (x + y) % 3 == 0;
|
|
523
|
-
break;
|
|
524
|
-
case 4:
|
|
525
|
-
invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 == 0;
|
|
526
|
-
break;
|
|
527
|
-
case 5:
|
|
528
|
-
invert = x * y % 2 + x * y % 3 == 0;
|
|
529
|
-
break;
|
|
530
|
-
case 6:
|
|
531
|
-
invert = (x * y % 2 + x * y % 3) % 2 == 0;
|
|
532
|
-
break;
|
|
533
|
-
case 7:
|
|
534
|
-
invert = ((x + y) % 2 + x * y % 3) % 2 == 0;
|
|
535
|
-
break;
|
|
536
|
-
default:
|
|
537
|
-
throw new Error("Unreachable");
|
|
538
|
-
}
|
|
539
|
-
if (!this.isFunction[y][x] && invert)
|
|
540
|
-
this.modules[y][x] = !this.modules[y][x];
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
getPenaltyScore() {
|
|
545
|
-
let result = 0;
|
|
546
|
-
for (let y = 0; y < this.size; y++) {
|
|
547
|
-
let runColor = false;
|
|
548
|
-
let runX = 0;
|
|
549
|
-
let runHistory = [0, 0, 0, 0, 0, 0, 0];
|
|
550
|
-
for (let x = 0; x < this.size; x++) {
|
|
551
|
-
if (this.modules[y][x] == runColor) {
|
|
552
|
-
runX++;
|
|
553
|
-
if (runX == 5)
|
|
554
|
-
result += _QrCode.PENALTY_N1;
|
|
555
|
-
else if (runX > 5)
|
|
556
|
-
result++;
|
|
557
|
-
} else {
|
|
558
|
-
this.finderPenaltyAddHistory(runX, runHistory);
|
|
559
|
-
if (!runColor)
|
|
560
|
-
result += this.finderPenaltyCountPatterns(runHistory) * _QrCode.PENALTY_N3;
|
|
561
|
-
runColor = this.modules[y][x];
|
|
562
|
-
runX = 1;
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * _QrCode.PENALTY_N3;
|
|
566
|
-
}
|
|
567
|
-
for (let x = 0; x < this.size; x++) {
|
|
568
|
-
let runColor = false;
|
|
569
|
-
let runY = 0;
|
|
570
|
-
let runHistory = [0, 0, 0, 0, 0, 0, 0];
|
|
571
|
-
for (let y = 0; y < this.size; y++) {
|
|
572
|
-
if (this.modules[y][x] == runColor) {
|
|
573
|
-
runY++;
|
|
574
|
-
if (runY == 5)
|
|
575
|
-
result += _QrCode.PENALTY_N1;
|
|
576
|
-
else if (runY > 5)
|
|
577
|
-
result++;
|
|
578
|
-
} else {
|
|
579
|
-
this.finderPenaltyAddHistory(runY, runHistory);
|
|
580
|
-
if (!runColor)
|
|
581
|
-
result += this.finderPenaltyCountPatterns(runHistory) * _QrCode.PENALTY_N3;
|
|
582
|
-
runColor = this.modules[y][x];
|
|
583
|
-
runY = 1;
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
result += this.finderPenaltyTerminateAndCount(runColor, runY, runHistory) * _QrCode.PENALTY_N3;
|
|
587
|
-
}
|
|
588
|
-
for (let y = 0; y < this.size - 1; y++) {
|
|
589
|
-
for (let x = 0; x < this.size - 1; x++) {
|
|
590
|
-
const color = this.modules[y][x];
|
|
591
|
-
if (color == this.modules[y][x + 1] && color == this.modules[y + 1][x] && color == this.modules[y + 1][x + 1])
|
|
592
|
-
result += _QrCode.PENALTY_N2;
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
let dark = 0;
|
|
596
|
-
for (const row of this.modules)
|
|
597
|
-
dark = row.reduce((sum, color) => sum + (color ? 1 : 0), dark);
|
|
598
|
-
const total = this.size * this.size;
|
|
599
|
-
const k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
|
|
600
|
-
assert(0 <= k && k <= 9);
|
|
601
|
-
result += k * _QrCode.PENALTY_N4;
|
|
602
|
-
assert(0 <= result && result <= 2568888);
|
|
603
|
-
return result;
|
|
604
|
-
}
|
|
605
|
-
getAlignmentPatternPositions() {
|
|
606
|
-
if (this.version == 1)
|
|
607
|
-
return [];
|
|
608
|
-
else {
|
|
609
|
-
const numAlign = Math.floor(this.version / 7) + 2;
|
|
610
|
-
const step = this.version == 32 ? 26 : Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
|
|
611
|
-
let result = [6];
|
|
612
|
-
for (let pos = this.size - 7; result.length < numAlign; pos -= step)
|
|
613
|
-
result.splice(1, 0, pos);
|
|
614
|
-
return result;
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
static getNumRawDataModules(ver) {
|
|
618
|
-
if (ver < _QrCode.MIN_VERSION || ver > _QrCode.MAX_VERSION)
|
|
619
|
-
throw new RangeError("Version number out of range");
|
|
620
|
-
let result = (16 * ver + 128) * ver + 64;
|
|
621
|
-
if (ver >= 2) {
|
|
622
|
-
const numAlign = Math.floor(ver / 7) + 2;
|
|
623
|
-
result -= (25 * numAlign - 10) * numAlign - 55;
|
|
624
|
-
if (ver >= 7)
|
|
625
|
-
result -= 36;
|
|
626
|
-
}
|
|
627
|
-
assert(208 <= result && result <= 29648);
|
|
628
|
-
return result;
|
|
629
|
-
}
|
|
630
|
-
static getNumDataCodewords(ver, ecl) {
|
|
631
|
-
return Math.floor(_QrCode.getNumRawDataModules(ver) / 8) - _QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] * _QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
|
|
632
|
-
}
|
|
633
|
-
static reedSolomonComputeDivisor(degree) {
|
|
634
|
-
if (degree < 1 || degree > 255)
|
|
635
|
-
throw new RangeError("Degree out of range");
|
|
636
|
-
let result = [];
|
|
637
|
-
for (let i = 0; i < degree - 1; i++)
|
|
638
|
-
result.push(0);
|
|
639
|
-
result.push(1);
|
|
640
|
-
let root = 1;
|
|
641
|
-
for (let i = 0; i < degree; i++) {
|
|
642
|
-
for (let j = 0; j < result.length; j++) {
|
|
643
|
-
result[j] = _QrCode.reedSolomonMultiply(result[j], root);
|
|
644
|
-
if (j + 1 < result.length)
|
|
645
|
-
result[j] ^= result[j + 1];
|
|
646
|
-
}
|
|
647
|
-
root = _QrCode.reedSolomonMultiply(root, 2);
|
|
648
|
-
}
|
|
649
|
-
return result;
|
|
650
|
-
}
|
|
651
|
-
static reedSolomonComputeRemainder(data, divisor) {
|
|
652
|
-
let result = divisor.map((_) => 0);
|
|
653
|
-
for (const b of data) {
|
|
654
|
-
const factor = b ^ result.shift();
|
|
655
|
-
result.push(0);
|
|
656
|
-
divisor.forEach((coef, i) => result[i] ^= _QrCode.reedSolomonMultiply(coef, factor));
|
|
657
|
-
}
|
|
658
|
-
return result;
|
|
659
|
-
}
|
|
660
|
-
static reedSolomonMultiply(x, y) {
|
|
661
|
-
if (x >>> 8 != 0 || y >>> 8 != 0)
|
|
662
|
-
throw new RangeError("Byte out of range");
|
|
663
|
-
let z = 0;
|
|
664
|
-
for (let i = 7; i >= 0; i--) {
|
|
665
|
-
z = z << 1 ^ (z >>> 7) * 285;
|
|
666
|
-
z ^= (y >>> i & 1) * x;
|
|
667
|
-
}
|
|
668
|
-
assert(z >>> 8 == 0);
|
|
669
|
-
return z;
|
|
670
|
-
}
|
|
671
|
-
finderPenaltyCountPatterns(runHistory) {
|
|
672
|
-
const n = runHistory[1];
|
|
673
|
-
assert(n <= this.size * 3);
|
|
674
|
-
const core = n > 0 && runHistory[2] == n && runHistory[3] == n * 3 && runHistory[4] == n && runHistory[5] == n;
|
|
675
|
-
return (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0) + (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0);
|
|
676
|
-
}
|
|
677
|
-
finderPenaltyTerminateAndCount(currentRunColor, currentRunLength, runHistory) {
|
|
678
|
-
if (currentRunColor) {
|
|
679
|
-
this.finderPenaltyAddHistory(currentRunLength, runHistory);
|
|
680
|
-
currentRunLength = 0;
|
|
681
|
-
}
|
|
682
|
-
currentRunLength += this.size;
|
|
683
|
-
this.finderPenaltyAddHistory(currentRunLength, runHistory);
|
|
684
|
-
return this.finderPenaltyCountPatterns(runHistory);
|
|
685
|
-
}
|
|
686
|
-
finderPenaltyAddHistory(currentRunLength, runHistory) {
|
|
687
|
-
if (runHistory[0] == 0)
|
|
688
|
-
currentRunLength += this.size;
|
|
689
|
-
runHistory.pop();
|
|
690
|
-
runHistory.unshift(currentRunLength);
|
|
691
|
-
}
|
|
692
|
-
};
|
|
693
|
-
let QrCode = _QrCode;
|
|
694
|
-
QrCode.MIN_VERSION = 1;
|
|
695
|
-
QrCode.MAX_VERSION = 40;
|
|
696
|
-
QrCode.PENALTY_N1 = 3;
|
|
697
|
-
QrCode.PENALTY_N2 = 3;
|
|
698
|
-
QrCode.PENALTY_N3 = 40;
|
|
699
|
-
QrCode.PENALTY_N4 = 10;
|
|
700
|
-
QrCode.ECC_CODEWORDS_PER_BLOCK = [
|
|
701
|
-
[-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],
|
|
702
|
-
[-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],
|
|
703
|
-
[-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],
|
|
704
|
-
[-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]
|
|
705
|
-
];
|
|
706
|
-
QrCode.NUM_ERROR_CORRECTION_BLOCKS = [
|
|
707
|
-
[-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],
|
|
708
|
-
[-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],
|
|
709
|
-
[-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],
|
|
710
|
-
[-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]
|
|
711
|
-
];
|
|
712
|
-
qrcodegen2.QrCode = QrCode;
|
|
713
|
-
function appendBits(val, len, bb) {
|
|
714
|
-
if (len < 0 || len > 31 || val >>> len != 0)
|
|
715
|
-
throw new RangeError("Value out of range");
|
|
716
|
-
for (let i = len - 1; i >= 0; i--)
|
|
717
|
-
bb.push(val >>> i & 1);
|
|
718
|
-
}
|
|
719
|
-
function getBit(x, i) {
|
|
720
|
-
return (x >>> i & 1) != 0;
|
|
721
|
-
}
|
|
722
|
-
function assert(cond) {
|
|
723
|
-
if (!cond)
|
|
724
|
-
throw new Error("Assertion error");
|
|
725
|
-
}
|
|
726
|
-
const _QrSegment = class {
|
|
727
|
-
constructor(mode, numChars, bitData) {
|
|
728
|
-
this.mode = mode;
|
|
729
|
-
this.numChars = numChars;
|
|
730
|
-
this.bitData = bitData;
|
|
731
|
-
if (numChars < 0)
|
|
732
|
-
throw new RangeError("Invalid argument");
|
|
733
|
-
this.bitData = bitData.slice();
|
|
734
|
-
}
|
|
735
|
-
static makeBytes(data) {
|
|
736
|
-
let bb = [];
|
|
737
|
-
for (const b of data)
|
|
738
|
-
appendBits(b, 8, bb);
|
|
739
|
-
return new _QrSegment(_QrSegment.Mode.BYTE, data.length, bb);
|
|
740
|
-
}
|
|
741
|
-
static makeNumeric(digits) {
|
|
742
|
-
if (!_QrSegment.isNumeric(digits))
|
|
743
|
-
throw new RangeError("String contains non-numeric characters");
|
|
744
|
-
let bb = [];
|
|
745
|
-
for (let i = 0; i < digits.length; ) {
|
|
746
|
-
const n = Math.min(digits.length - i, 3);
|
|
747
|
-
appendBits(parseInt(digits.substr(i, n), 10), n * 3 + 1, bb);
|
|
748
|
-
i += n;
|
|
749
|
-
}
|
|
750
|
-
return new _QrSegment(_QrSegment.Mode.NUMERIC, digits.length, bb);
|
|
751
|
-
}
|
|
752
|
-
static makeAlphanumeric(text) {
|
|
753
|
-
if (!_QrSegment.isAlphanumeric(text))
|
|
754
|
-
throw new RangeError("String contains unencodable characters in alphanumeric mode");
|
|
755
|
-
let bb = [];
|
|
756
|
-
let i;
|
|
757
|
-
for (i = 0; i + 2 <= text.length; i += 2) {
|
|
758
|
-
let temp = _QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
|
|
759
|
-
temp += _QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
|
|
760
|
-
appendBits(temp, 11, bb);
|
|
761
|
-
}
|
|
762
|
-
if (i < text.length)
|
|
763
|
-
appendBits(_QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
|
|
764
|
-
return new _QrSegment(_QrSegment.Mode.ALPHANUMERIC, text.length, bb);
|
|
765
|
-
}
|
|
766
|
-
static makeSegments(text) {
|
|
767
|
-
if (text == "")
|
|
768
|
-
return [];
|
|
769
|
-
else if (_QrSegment.isNumeric(text))
|
|
770
|
-
return [_QrSegment.makeNumeric(text)];
|
|
771
|
-
else if (_QrSegment.isAlphanumeric(text))
|
|
772
|
-
return [_QrSegment.makeAlphanumeric(text)];
|
|
773
|
-
else
|
|
774
|
-
return [_QrSegment.makeBytes(_QrSegment.toUtf8ByteArray(text))];
|
|
775
|
-
}
|
|
776
|
-
static makeEci(assignVal) {
|
|
777
|
-
let bb = [];
|
|
778
|
-
if (assignVal < 0)
|
|
779
|
-
throw new RangeError("ECI assignment value out of range");
|
|
780
|
-
else if (assignVal < 1 << 7)
|
|
781
|
-
appendBits(assignVal, 8, bb);
|
|
782
|
-
else if (assignVal < 1 << 14) {
|
|
783
|
-
appendBits(2, 2, bb);
|
|
784
|
-
appendBits(assignVal, 14, bb);
|
|
785
|
-
} else if (assignVal < 1e6) {
|
|
786
|
-
appendBits(6, 3, bb);
|
|
787
|
-
appendBits(assignVal, 21, bb);
|
|
788
|
-
} else
|
|
789
|
-
throw new RangeError("ECI assignment value out of range");
|
|
790
|
-
return new _QrSegment(_QrSegment.Mode.ECI, 0, bb);
|
|
791
|
-
}
|
|
792
|
-
static isNumeric(text) {
|
|
793
|
-
return _QrSegment.NUMERIC_REGEX.test(text);
|
|
794
|
-
}
|
|
795
|
-
static isAlphanumeric(text) {
|
|
796
|
-
return _QrSegment.ALPHANUMERIC_REGEX.test(text);
|
|
797
|
-
}
|
|
798
|
-
getData() {
|
|
799
|
-
return this.bitData.slice();
|
|
800
|
-
}
|
|
801
|
-
static getTotalBits(segs, version) {
|
|
802
|
-
let result = 0;
|
|
803
|
-
for (const seg of segs) {
|
|
804
|
-
const ccbits = seg.mode.numCharCountBits(version);
|
|
805
|
-
if (seg.numChars >= 1 << ccbits)
|
|
806
|
-
return Infinity;
|
|
807
|
-
result += 4 + ccbits + seg.bitData.length;
|
|
808
|
-
}
|
|
809
|
-
return result;
|
|
810
|
-
}
|
|
811
|
-
static toUtf8ByteArray(str) {
|
|
812
|
-
str = encodeURI(str);
|
|
813
|
-
let result = [];
|
|
814
|
-
for (let i = 0; i < str.length; i++) {
|
|
815
|
-
if (str.charAt(i) != "%")
|
|
816
|
-
result.push(str.charCodeAt(i));
|
|
817
|
-
else {
|
|
818
|
-
result.push(parseInt(str.substr(i + 1, 2), 16));
|
|
819
|
-
i += 2;
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
return result;
|
|
823
|
-
}
|
|
824
|
-
};
|
|
825
|
-
let QrSegment = _QrSegment;
|
|
826
|
-
QrSegment.NUMERIC_REGEX = /^[0-9]*$/;
|
|
827
|
-
QrSegment.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
|
|
828
|
-
QrSegment.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
|
|
829
|
-
qrcodegen2.QrSegment = QrSegment;
|
|
830
|
-
})(qrcodegen || (qrcodegen = {}));
|
|
831
|
-
((qrcodegen2) => {
|
|
832
|
-
((QrCode2) => {
|
|
833
|
-
const _Ecc = class {
|
|
834
|
-
constructor(ordinal, formatBits) {
|
|
835
|
-
this.ordinal = ordinal;
|
|
836
|
-
this.formatBits = formatBits;
|
|
837
|
-
}
|
|
838
|
-
};
|
|
839
|
-
let Ecc = _Ecc;
|
|
840
|
-
Ecc.LOW = new _Ecc(0, 1);
|
|
841
|
-
Ecc.MEDIUM = new _Ecc(1, 0);
|
|
842
|
-
Ecc.QUARTILE = new _Ecc(2, 3);
|
|
843
|
-
Ecc.HIGH = new _Ecc(3, 2);
|
|
844
|
-
QrCode2.Ecc = Ecc;
|
|
845
|
-
})(qrcodegen2.QrCode || (qrcodegen2.QrCode = {}));
|
|
846
|
-
})(qrcodegen || (qrcodegen = {}));
|
|
847
|
-
((qrcodegen2) => {
|
|
848
|
-
((QrSegment2) => {
|
|
849
|
-
const _Mode = class {
|
|
850
|
-
constructor(modeBits, numBitsCharCount) {
|
|
851
|
-
this.modeBits = modeBits;
|
|
852
|
-
this.numBitsCharCount = numBitsCharCount;
|
|
853
|
-
}
|
|
854
|
-
numCharCountBits(ver) {
|
|
855
|
-
return this.numBitsCharCount[Math.floor((ver + 7) / 17)];
|
|
856
|
-
}
|
|
857
|
-
};
|
|
858
|
-
let Mode = _Mode;
|
|
859
|
-
Mode.NUMERIC = new _Mode(1, [10, 12, 14]);
|
|
860
|
-
Mode.ALPHANUMERIC = new _Mode(2, [9, 11, 13]);
|
|
861
|
-
Mode.BYTE = new _Mode(4, [8, 16, 16]);
|
|
862
|
-
Mode.KANJI = new _Mode(8, [8, 10, 12]);
|
|
863
|
-
Mode.ECI = new _Mode(7, [0, 0, 0]);
|
|
864
|
-
QrSegment2.Mode = Mode;
|
|
865
|
-
})(qrcodegen2.QrSegment || (qrcodegen2.QrSegment = {}));
|
|
866
|
-
})(qrcodegen || (qrcodegen = {}));
|
|
867
|
-
var qrcodegen_default = qrcodegen;
|
|
868
|
-
|
|
869
|
-
// src/index.tsx
|
|
1
|
+
"use strict";var e=require("react"),t=require("@bigbinary/neeto-commons-frontend/pure"),n=require("@bigbinary/neeto-commons-frontend/utils"),r=require("@bigbinary/neeto-icons"),a=require("@bigbinary/neetoui"),o=require("react-i18next");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=l(e);function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,a,o,l,i=[],s=!0,u=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;s=!1}else for(;!(s=(r=o.call(n)).done)&&(i.push(r.value),i.length!==t);s=!0);}catch(e){u=!0,a=e}finally{try{if(!s&&null!=n.return&&(l=n.return(),Object(l)!==l))return}finally{if(u)throw a}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var c,d,h=function(e){var t=e.isOpen,n=e.onClose,r=e.url,l=e.isRegenerating,s=e.handleRegenerate,u=o.useTranslation().t;return i.default.createElement(a.Modal,{"data-testid":"regenerate-url-modal",isOpen:t,onClose:n},i.default.createElement(a.Modal.Header,null,i.default.createElement(a.Typography,{lineHeight:"normal",style:"h2",weight:"semibold"},u("neetoMolecules.shareViaLink.regenerateUrl.title"))),i.default.createElement(a.Modal.Body,null,i.default.createElement("div",{className:"w-full space-y-6"},i.default.createElement(a.Input,{disabled:!0,label:u("neetoMolecules.shareViaLink.regenerateUrl.inputLabel"),value:r}),i.default.createElement(a.Typography,{className:"neeto-ui-text-gray-700",lineHeight:"normal",style:"body2"},u("neetoMolecules.shareViaLink.regenerateUrl.description")),i.default.createElement(a.Typography,{className:"neeto-ui-text-gray-700",lineHeight:"normal",style:"body2"},u("neetoMolecules.shareViaLink.regenerateUrl.confirmation")))),i.default.createElement(a.Modal.Footer,{className:"space-x-2"},i.default.createElement(a.Button,{"data-testid":"regenerate-url-confirm-button",loading:l,label:u("neetoMolecules.shareViaLink.regenerateUrl.submitButtonLabel"),onClick:function(){s(),n()}}),i.default.createElement(a.Button,{"data-testid":"regenerate-url-cancel-button",style:"text",label:u("neetoMolecules.shareViaLink.regenerateUrl.cancelButtonLabel"),onClick:n})))},f=a.Dropdown.Menu,m=a.Dropdown.MenuItem,g=function(t){var l=t.enableRegenerateUrl,s=t.entityName,c=t.handleRegenerate,d=t.isRegenerating,g=t.previewUrl,E=t.url,y=u(e.useState(!1),2),p=y[0],M=y[1],w=o.useTranslation().t;return i.default.createElement("div",{className:"space-y-4","data-testid":"link-block"},i.default.createElement("div",{className:"space-y-0.5"},i.default.createElement(a.Typography,{"data-testid":"link-title",lineHeight:"normal",style:"h3",weight:"semibold"},w("neetoMolecules.shareViaLink.title")),i.default.createElement(a.Typography,{className:"neeto-ui-text-gray-700","data-testid":"link-description",lineHeight:"normal",style:"body2"},w("neetoMolecules.shareViaLink.description",{entity:s}))),i.default.createElement("div",{className:"flex items-center gap-1"},i.default.createElement(a.Input,{readOnly:!0,value:E}),i.default.createElement(a.Button,{"data-testid":"link-copy-button",icon:r.Copy,label:w("neetoMolecules.shareViaLink.copyLink"),onClick:function(){return n.copyToClipboard(E)}}),i.default.createElement(a.Button,{"data-testid":"preview-button",href:g||E,icon:r.ExternalLink,style:"secondary",target:"_blank",tooltipProps:{content:w("neetoMolecules.shareViaLink.open",{entity:s}),position:"top"}}),l&&i.default.createElement(i.default.Fragment,null,i.default.createElement(a.Dropdown,{buttonStyle:"text",icon:r.MenuHorizontal},i.default.createElement(f,null,i.default.createElement(m.Button,{"data-testid":"regenerate-url-button",onClick:function(){return M(!0)}},w("neetoMolecules.shareViaLink.regenerateUrl.title")))),i.default.createElement(h,{handleRegenerate:c,isOpen:p,isRegenerating:d,url:E,onClose:function(){return M(!1)}}))))},E={FACEBOOK:{label:"Facebook",icon:r.Facebook,generateShareUrl:function(e){var t=e.id;return n.buildUrl("https://www.facebook.com/sharer/sharer.php",{u:"https://".concat(window.location.host,"/").concat(t)})}},LINKEDIN:{label:"LinkedIn",icon:r.Linkedin,generateShareUrl:function(e){var t=e.id,r=e.title;return n.buildUrl("https://www.linkedin.com/shareArticle",{mini:!0,url:"https://".concat(window.location.host,"/").concat(t),title:r})}},TWITTER:{label:"Twitter",icon:r.Twitter,generateShareUrl:function(e){var t=e.id,r=e.title;return n.buildUrl("http://twitter.com/share",{text:r,url:"https://".concat(window.location.host,"/").concat(t)})}}},y=Object.defineProperty,p=Object.getOwnPropertySymbols,M=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable,C=(e,t,n)=>t in e?y(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,b=(e,t)=>{for(var n in t||(t={}))M.call(t,n)&&C(e,n,t[n]);if(p)for(var n of p(t))w.call(t,n)&&C(e,n,t[n]);return e},v=(e,t)=>{var n={};for(var r in e)M.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&p)for(var r of p(e))t.indexOf(r)<0&&w.call(e,r)&&(n[r]=e[r]);return n};(e=>{const t=class{constructor(e,n,r,a){if(this.version=e,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],e<t.MIN_VERSION||e>t.MAX_VERSION)throw new RangeError("Version value out of range");if(a<-1||a>7)throw new RangeError("Mask value out of range");this.size=4*e+17;let l=[];for(let e=0;e<this.size;e++)l.push(!1);for(let e=0;e<this.size;e++)this.modules.push(l.slice()),this.isFunction.push(l.slice());this.drawFunctionPatterns();const i=this.addEccAndInterleave(r);if(this.drawCodewords(i),-1==a){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);const n=this.getPenaltyScore();n<e&&(a=t,e=n),this.applyMask(t)}}o(0<=a&&a<=7),this.mask=a,this.applyMask(a),this.drawFormatBits(a),this.isFunction=[]}static encodeText(n,r){const a=e.QrSegment.makeSegments(n);return t.encodeSegments(a,r)}static encodeBinary(n,r){const a=e.QrSegment.makeBytes(n);return t.encodeSegments([a],r)}static encodeSegments(e,n,a=1,l=40,s=-1,u=!0){if(!(t.MIN_VERSION<=a&&a<=l&&l<=t.MAX_VERSION)||s<-1||s>7)throw new RangeError("Invalid value");let c,d;for(c=a;;c++){const r=8*t.getNumDataCodewords(c,n),a=i.getTotalBits(e,c);if(a<=r){d=a;break}if(c>=l)throw new RangeError("Data too long")}for(const e of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])u&&d<=8*t.getNumDataCodewords(c,e)&&(n=e);let h=[];for(const t of e){r(t.mode.modeBits,4,h),r(t.numChars,t.mode.numCharCountBits(c),h);for(const e of t.getData())h.push(e)}o(h.length==d);const f=8*t.getNumDataCodewords(c,n);o(h.length<=f),r(0,Math.min(4,f-h.length),h),r(0,(8-h.length%8)%8,h),o(h.length%8==0);for(let e=236;h.length<f;e^=253)r(e,8,h);let m=[];for(;8*m.length<h.length;)m.push(0);return h.forEach(((e,t)=>m[t>>>3]|=e<<7-(7&t))),new t(c,n,m,s)}getModule(e,t){return 0<=e&&e<this.size&&0<=t&&t<this.size&&this.modules[t][e]}getModules(){return this.modules}drawFunctionPatterns(){for(let e=0;e<this.size;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);const e=this.getAlignmentPatternPositions(),t=e.length;for(let n=0;n<t;n++)for(let r=0;r<t;r++)0==n&&0==r||0==n&&r==t-1||n==t-1&&0==r||this.drawAlignmentPattern(e[n],e[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){const t=this.errorCorrectionLevel.formatBits<<3|e;let n=t;for(let e=0;e<10;e++)n=n<<1^1335*(n>>>9);const r=21522^(t<<10|n);o(r>>>15==0);for(let e=0;e<=5;e++)this.setFunctionModule(8,e,a(r,e));this.setFunctionModule(8,7,a(r,6)),this.setFunctionModule(8,8,a(r,7)),this.setFunctionModule(7,8,a(r,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,a(r,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,a(r,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,a(r,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^7973*(e>>>11);const t=this.version<<12|e;o(t>>>18==0);for(let e=0;e<18;e++){const n=a(t,e),r=this.size-11+e%3,o=Math.floor(e/3);this.setFunctionModule(r,o,n),this.setFunctionModule(o,r,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){const a=Math.max(Math.abs(r),Math.abs(n)),o=e+r,l=t+n;0<=o&&o<this.size&&0<=l&&l<this.size&&this.setFunctionModule(o,l,2!=a&&4!=a)}}drawAlignmentPattern(e,t){for(let n=-2;n<=2;n++)for(let r=-2;r<=2;r++)this.setFunctionModule(e+r,t+n,1!=Math.max(Math.abs(r),Math.abs(n)))}setFunctionModule(e,t,n){this.modules[t][e]=n,this.isFunction[t][e]=!0}addEccAndInterleave(e){const n=this.version,r=this.errorCorrectionLevel;if(e.length!=t.getNumDataCodewords(n,r))throw new RangeError("Invalid argument");const a=t.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][n],l=t.ECC_CODEWORDS_PER_BLOCK[r.ordinal][n],i=Math.floor(t.getNumRawDataModules(n)/8),s=a-i%a,u=Math.floor(i/a);let c=[];const d=t.reedSolomonComputeDivisor(l);for(let n=0,r=0;n<a;n++){let a=e.slice(r,r+u-l+(n<s?0:1));r+=a.length;const o=t.reedSolomonComputeRemainder(a,d);n<s&&a.push(0),c.push(a.concat(o))}let h=[];for(let e=0;e<c[0].length;e++)c.forEach(((t,n)=>{(e!=u-l||n>=s)&&h.push(t[e])}));return o(h.length==i),h}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let n=0;for(let t=this.size-1;t>=1;t-=2){6==t&&(t=5);for(let r=0;r<this.size;r++)for(let o=0;o<2;o++){const l=t-o,i=0==(t+1&2)?this.size-1-r:r;!this.isFunction[i][l]&&n<8*e.length&&(this.modules[i][l]=a(e[n>>>3],7-(7&n)),n++)}}o(n==8*e.length)}applyMask(e){if(e<0||e>7)throw new RangeError("Mask value out of range");for(let t=0;t<this.size;t++)for(let n=0;n<this.size;n++){let r;switch(e){case 0:r=(n+t)%2==0;break;case 1:r=t%2==0;break;case 2:r=n%3==0;break;case 3:r=(n+t)%3==0;break;case 4:r=(Math.floor(n/3)+Math.floor(t/2))%2==0;break;case 5:r=n*t%2+n*t%3==0;break;case 6:r=(n*t%2+n*t%3)%2==0;break;case 7:r=((n+t)%2+n*t%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[t][n]&&r&&(this.modules[t][n]=!this.modules[t][n])}}getPenaltyScore(){let e=0;for(let n=0;n<this.size;n++){let r=!1,a=0,o=[0,0,0,0,0,0,0];for(let l=0;l<this.size;l++)this.modules[n][l]==r?(a++,5==a?e+=t.PENALTY_N1:a>5&&e++):(this.finderPenaltyAddHistory(a,o),r||(e+=this.finderPenaltyCountPatterns(o)*t.PENALTY_N3),r=this.modules[n][l],a=1);e+=this.finderPenaltyTerminateAndCount(r,a,o)*t.PENALTY_N3}for(let n=0;n<this.size;n++){let r=!1,a=0,o=[0,0,0,0,0,0,0];for(let l=0;l<this.size;l++)this.modules[l][n]==r?(a++,5==a?e+=t.PENALTY_N1:a>5&&e++):(this.finderPenaltyAddHistory(a,o),r||(e+=this.finderPenaltyCountPatterns(o)*t.PENALTY_N3),r=this.modules[l][n],a=1);e+=this.finderPenaltyTerminateAndCount(r,a,o)*t.PENALTY_N3}for(let n=0;n<this.size-1;n++)for(let r=0;r<this.size-1;r++){const a=this.modules[n][r];a==this.modules[n][r+1]&&a==this.modules[n+1][r]&&a==this.modules[n+1][r+1]&&(e+=t.PENALTY_N2)}let n=0;for(const e of this.modules)n=e.reduce(((e,t)=>e+(t?1:0)),n);const r=this.size*this.size,a=Math.ceil(Math.abs(20*n-10*r)/r)-1;return o(0<=a&&a<=9),e+=a*t.PENALTY_N4,o(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(1==this.version)return[];{const e=Math.floor(this.version/7)+2,t=32==this.version?26:2*Math.ceil((4*this.version+4)/(2*e-2));let n=[6];for(let r=this.size-7;n.length<e;r-=t)n.splice(1,0,r);return n}}static getNumRawDataModules(e){if(e<t.MIN_VERSION||e>t.MAX_VERSION)throw new RangeError("Version number out of range");let n=(16*e+128)*e+64;if(e>=2){const t=Math.floor(e/7)+2;n-=(25*t-10)*t-55,e>=7&&(n-=36)}return o(208<=n&&n<=29648),n}static getNumDataCodewords(e,n){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw new RangeError("Degree out of range");let n=[];for(let t=0;t<e-1;t++)n.push(0);n.push(1);let r=1;for(let a=0;a<e;a++){for(let e=0;e<n.length;e++)n[e]=t.reedSolomonMultiply(n[e],r),e+1<n.length&&(n[e]^=n[e+1]);r=t.reedSolomonMultiply(r,2)}return n}static reedSolomonComputeRemainder(e,n){let r=n.map((e=>0));for(const a of e){const e=a^r.shift();r.push(0),n.forEach(((n,a)=>r[a]^=t.reedSolomonMultiply(n,e)))}return r}static reedSolomonMultiply(e,t){if(e>>>8!=0||t>>>8!=0)throw new RangeError("Byte out of range");let n=0;for(let r=7;r>=0;r--)n=n<<1^285*(n>>>7),n^=(t>>>r&1)*e;return o(n>>>8==0),n}finderPenaltyCountPatterns(e){const t=e[1];o(t<=3*this.size);const n=t>0&&e[2]==t&&e[3]==3*t&&e[4]==t&&e[5]==t;return(n&&e[0]>=4*t&&e[6]>=t?1:0)+(n&&e[6]>=4*t&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){0==t[0]&&(e+=this.size),t.pop(),t.unshift(e)}};let n=t;function r(e,t,n){if(t<0||t>31||e>>>t!=0)throw new RangeError("Value out of range");for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function a(e,t){return 0!=(e>>>t&1)}function o(e){if(!e)throw new Error("Assertion error")}n.MIN_VERSION=1,n.MAX_VERSION=40,n.PENALTY_N1=3,n.PENALTY_N2=3,n.PENALTY_N3=40,n.PENALTY_N4=10,n.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]],n.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]],e.QrCode=n;const l=class{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw new RangeError("Invalid argument");this.bitData=n.slice()}static makeBytes(e){let t=[];for(const n of e)r(n,8,t);return new l(l.Mode.BYTE,e.length,t)}static makeNumeric(e){if(!l.isNumeric(e))throw new RangeError("String contains non-numeric characters");let t=[];for(let n=0;n<e.length;){const a=Math.min(e.length-n,3);r(parseInt(e.substr(n,a),10),3*a+1,t),n+=a}return new l(l.Mode.NUMERIC,e.length,t)}static makeAlphanumeric(e){if(!l.isAlphanumeric(e))throw new RangeError("String contains unencodable characters in alphanumeric mode");let t,n=[];for(t=0;t+2<=e.length;t+=2){let a=45*l.ALPHANUMERIC_CHARSET.indexOf(e.charAt(t));a+=l.ALPHANUMERIC_CHARSET.indexOf(e.charAt(t+1)),r(a,11,n)}return t<e.length&&r(l.ALPHANUMERIC_CHARSET.indexOf(e.charAt(t)),6,n),new l(l.Mode.ALPHANUMERIC,e.length,n)}static makeSegments(e){return""==e?[]:l.isNumeric(e)?[l.makeNumeric(e)]:l.isAlphanumeric(e)?[l.makeAlphanumeric(e)]:[l.makeBytes(l.toUtf8ByteArray(e))]}static makeEci(e){let t=[];if(e<0)throw new RangeError("ECI assignment value out of range");if(e<128)r(e,8,t);else if(e<16384)r(2,2,t),r(e,14,t);else{if(!(e<1e6))throw new RangeError("ECI assignment value out of range");r(6,3,t),r(e,21,t)}return new l(l.Mode.ECI,0,t)}static isNumeric(e){return l.NUMERIC_REGEX.test(e)}static isAlphanumeric(e){return l.ALPHANUMERIC_REGEX.test(e)}getData(){return this.bitData.slice()}static getTotalBits(e,t){let n=0;for(const r of e){const e=r.mode.numCharCountBits(t);if(r.numChars>=1<<e)return 1/0;n+=4+e+r.bitData.length}return n}static toUtf8ByteArray(e){e=encodeURI(e);let t=[];for(let n=0;n<e.length;n++)"%"!=e.charAt(n)?t.push(e.charCodeAt(n)):(t.push(parseInt(e.substr(n+1,2),16)),n+=2);return t}};let i=l;i.NUMERIC_REGEX=/^[0-9]*$/,i.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,i.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",e.QrSegment=i})(c||(c={})),(e=>{const t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};let n=t;n.LOW=new t(0,1),n.MEDIUM=new t(1,0),n.QUARTILE=new t(2,3),n.HIGH=new t(3,2),e.Ecc=n})((d=c||(c={})).QrCode||(d.QrCode={})),(e=>{(e=>{const t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};let n=t;n.NUMERIC=new t(1,[10,12,14]),n.ALPHANUMERIC=new t(2,[9,11,13]),n.BYTE=new t(4,[8,16,16]),n.KANJI=new t(8,[8,10,12]),n.ECI=new t(7,[0,0,0]),e.Mode=n})(e.QrSegment||(e.QrSegment={}))})(c||(c={}));var R=c,N={L:R.QrCode.Ecc.LOW,M:R.QrCode.Ecc.MEDIUM,Q:R.QrCode.Ecc.QUARTILE,H:R.QrCode.Ecc.HIGH},A=128,k="L",S="#FFFFFF",I="#000000",P=!1,L=4,O=.1;
|
|
870
2
|
/**
|
|
871
3
|
* @license qrcode.react
|
|
872
4
|
* Copyright (c) Paul O'Shannessy
|
|
873
5
|
* SPDX-License-Identifier: ISC
|
|
874
|
-
*/
|
|
875
|
-
var ERROR_LEVEL_MAP = {
|
|
876
|
-
L: qrcodegen_default.QrCode.Ecc.LOW,
|
|
877
|
-
M: qrcodegen_default.QrCode.Ecc.MEDIUM,
|
|
878
|
-
Q: qrcodegen_default.QrCode.Ecc.QUARTILE,
|
|
879
|
-
H: qrcodegen_default.QrCode.Ecc.HIGH
|
|
880
|
-
};
|
|
881
|
-
var DEFAULT_SIZE = 128;
|
|
882
|
-
var DEFAULT_LEVEL = "L";
|
|
883
|
-
var DEFAULT_BGCOLOR = "#FFFFFF";
|
|
884
|
-
var DEFAULT_FGCOLOR = "#000000";
|
|
885
|
-
var DEFAULT_INCLUDEMARGIN = false;
|
|
886
|
-
var MARGIN_SIZE = 4;
|
|
887
|
-
var DEFAULT_IMG_SCALE = 0.1;
|
|
888
|
-
function generatePath(modules, margin = 0) {
|
|
889
|
-
const ops = [];
|
|
890
|
-
modules.forEach(function(row, y) {
|
|
891
|
-
let start = null;
|
|
892
|
-
row.forEach(function(cell, x) {
|
|
893
|
-
if (!cell && start !== null) {
|
|
894
|
-
ops.push(`M${start + margin} ${y + margin}h${x - start}v1H${start + margin}z`);
|
|
895
|
-
start = null;
|
|
896
|
-
return;
|
|
897
|
-
}
|
|
898
|
-
if (x === row.length - 1) {
|
|
899
|
-
if (!cell) {
|
|
900
|
-
return;
|
|
901
|
-
}
|
|
902
|
-
if (start === null) {
|
|
903
|
-
ops.push(`M${x + margin},${y + margin} h1v1H${x + margin}z`);
|
|
904
|
-
} else {
|
|
905
|
-
ops.push(`M${start + margin},${y + margin} h${x + 1 - start}v1H${start + margin}z`);
|
|
906
|
-
}
|
|
907
|
-
return;
|
|
908
|
-
}
|
|
909
|
-
if (cell && start === null) {
|
|
910
|
-
start = x;
|
|
911
|
-
}
|
|
912
|
-
});
|
|
913
|
-
});
|
|
914
|
-
return ops.join("");
|
|
915
|
-
}
|
|
916
|
-
function excavateModules(modules, excavation) {
|
|
917
|
-
return modules.slice().map((row, y) => {
|
|
918
|
-
if (y < excavation.y || y >= excavation.y + excavation.h) {
|
|
919
|
-
return row;
|
|
920
|
-
}
|
|
921
|
-
return row.map((cell, x) => {
|
|
922
|
-
if (x < excavation.x || x >= excavation.x + excavation.w) {
|
|
923
|
-
return cell;
|
|
924
|
-
}
|
|
925
|
-
return false;
|
|
926
|
-
});
|
|
927
|
-
});
|
|
928
|
-
}
|
|
929
|
-
function getImageSettings(cells, size, includeMargin, imageSettings) {
|
|
930
|
-
if (imageSettings == null) {
|
|
931
|
-
return null;
|
|
932
|
-
}
|
|
933
|
-
const margin = includeMargin ? MARGIN_SIZE : 0;
|
|
934
|
-
const numCells = cells.length + margin * 2;
|
|
935
|
-
const defaultSize = Math.floor(size * DEFAULT_IMG_SCALE);
|
|
936
|
-
const scale = numCells / size;
|
|
937
|
-
const w = (imageSettings.width || defaultSize) * scale;
|
|
938
|
-
const h = (imageSettings.height || defaultSize) * scale;
|
|
939
|
-
const x = imageSettings.x == null ? cells.length / 2 - w / 2 : imageSettings.x * scale;
|
|
940
|
-
const y = imageSettings.y == null ? cells.length / 2 - h / 2 : imageSettings.y * scale;
|
|
941
|
-
let excavation = null;
|
|
942
|
-
if (imageSettings.excavate) {
|
|
943
|
-
let floorX = Math.floor(x);
|
|
944
|
-
let floorY = Math.floor(y);
|
|
945
|
-
let ceilW = Math.ceil(w + x - floorX);
|
|
946
|
-
let ceilH = Math.ceil(h + y - floorY);
|
|
947
|
-
excavation = { x: floorX, y: floorY, w: ceilW, h: ceilH };
|
|
948
|
-
}
|
|
949
|
-
return { x, y, h, w, excavation };
|
|
950
|
-
}
|
|
951
|
-
var SUPPORTS_PATH2D = function() {
|
|
952
|
-
try {
|
|
953
|
-
new Path2D().addPath(new Path2D());
|
|
954
|
-
} catch (e) {
|
|
955
|
-
return false;
|
|
956
|
-
}
|
|
957
|
-
return true;
|
|
958
|
-
}();
|
|
959
|
-
function QRCodeCanvas(props) {
|
|
960
|
-
const _a = props, {
|
|
961
|
-
value,
|
|
962
|
-
size = DEFAULT_SIZE,
|
|
963
|
-
level = DEFAULT_LEVEL,
|
|
964
|
-
bgColor = DEFAULT_BGCOLOR,
|
|
965
|
-
fgColor = DEFAULT_FGCOLOR,
|
|
966
|
-
includeMargin = DEFAULT_INCLUDEMARGIN,
|
|
967
|
-
style,
|
|
968
|
-
imageSettings
|
|
969
|
-
} = _a, otherProps = __objRest(_a, [
|
|
970
|
-
"value",
|
|
971
|
-
"size",
|
|
972
|
-
"level",
|
|
973
|
-
"bgColor",
|
|
974
|
-
"fgColor",
|
|
975
|
-
"includeMargin",
|
|
976
|
-
"style",
|
|
977
|
-
"imageSettings"
|
|
978
|
-
]);
|
|
979
|
-
const imgSrc = imageSettings == null ? void 0 : imageSettings.src;
|
|
980
|
-
const _canvas = React.useRef(null);
|
|
981
|
-
const _image = React.useRef(null);
|
|
982
|
-
const [isImgLoaded, setIsImageLoaded] = React.useState(false);
|
|
983
|
-
React.useEffect(() => {
|
|
984
|
-
if (_canvas.current != null) {
|
|
985
|
-
const canvas = _canvas.current;
|
|
986
|
-
const ctx = canvas.getContext("2d");
|
|
987
|
-
if (!ctx) {
|
|
988
|
-
return;
|
|
989
|
-
}
|
|
990
|
-
let cells = qrcodegen_default.QrCode.encodeText(value, ERROR_LEVEL_MAP[level]).getModules();
|
|
991
|
-
const margin = includeMargin ? MARGIN_SIZE : 0;
|
|
992
|
-
const numCells = cells.length + margin * 2;
|
|
993
|
-
const calculatedImageSettings = getImageSettings(cells, size, includeMargin, imageSettings);
|
|
994
|
-
const image = _image.current;
|
|
995
|
-
const haveImageToRender = calculatedImageSettings != null && image !== null && image.complete && image.naturalHeight !== 0 && image.naturalWidth !== 0;
|
|
996
|
-
if (haveImageToRender) {
|
|
997
|
-
if (calculatedImageSettings.excavation != null) {
|
|
998
|
-
cells = excavateModules(cells, calculatedImageSettings.excavation);
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
const pixelRatio = window.devicePixelRatio || 1;
|
|
1002
|
-
canvas.height = canvas.width = size * pixelRatio;
|
|
1003
|
-
const scale = size / numCells * pixelRatio;
|
|
1004
|
-
ctx.scale(scale, scale);
|
|
1005
|
-
ctx.fillStyle = bgColor;
|
|
1006
|
-
ctx.fillRect(0, 0, numCells, numCells);
|
|
1007
|
-
ctx.fillStyle = fgColor;
|
|
1008
|
-
if (SUPPORTS_PATH2D) {
|
|
1009
|
-
ctx.fill(new Path2D(generatePath(cells, margin)));
|
|
1010
|
-
} else {
|
|
1011
|
-
cells.forEach(function(row, rdx) {
|
|
1012
|
-
row.forEach(function(cell, cdx) {
|
|
1013
|
-
if (cell) {
|
|
1014
|
-
ctx.fillRect(cdx + margin, rdx + margin, 1, 1);
|
|
1015
|
-
}
|
|
1016
|
-
});
|
|
1017
|
-
});
|
|
1018
|
-
}
|
|
1019
|
-
if (haveImageToRender) {
|
|
1020
|
-
ctx.drawImage(image, calculatedImageSettings.x + margin, calculatedImageSettings.y + margin, calculatedImageSettings.w, calculatedImageSettings.h);
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
});
|
|
1024
|
-
React.useEffect(() => {
|
|
1025
|
-
setIsImageLoaded(false);
|
|
1026
|
-
}, [imgSrc]);
|
|
1027
|
-
const canvasStyle = __spreadValues({ height: size, width: size }, style);
|
|
1028
|
-
let img = null;
|
|
1029
|
-
if (imgSrc != null) {
|
|
1030
|
-
img = /* @__PURE__ */ React__default["default"].createElement("img", {
|
|
1031
|
-
src: imgSrc,
|
|
1032
|
-
key: imgSrc,
|
|
1033
|
-
style: { display: "none" },
|
|
1034
|
-
onLoad: () => {
|
|
1035
|
-
setIsImageLoaded(true);
|
|
1036
|
-
},
|
|
1037
|
-
ref: _image
|
|
1038
|
-
});
|
|
1039
|
-
}
|
|
1040
|
-
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, /* @__PURE__ */ React__default["default"].createElement("canvas", __spreadValues({
|
|
1041
|
-
style: canvasStyle,
|
|
1042
|
-
height: size,
|
|
1043
|
-
width: size,
|
|
1044
|
-
ref: _canvas
|
|
1045
|
-
}, otherProps)), img);
|
|
1046
|
-
}
|
|
1047
|
-
function QRCodeSVG(props) {
|
|
1048
|
-
const _a = props, {
|
|
1049
|
-
value,
|
|
1050
|
-
size = DEFAULT_SIZE,
|
|
1051
|
-
level = DEFAULT_LEVEL,
|
|
1052
|
-
bgColor = DEFAULT_BGCOLOR,
|
|
1053
|
-
fgColor = DEFAULT_FGCOLOR,
|
|
1054
|
-
includeMargin = DEFAULT_INCLUDEMARGIN,
|
|
1055
|
-
imageSettings
|
|
1056
|
-
} = _a, otherProps = __objRest(_a, [
|
|
1057
|
-
"value",
|
|
1058
|
-
"size",
|
|
1059
|
-
"level",
|
|
1060
|
-
"bgColor",
|
|
1061
|
-
"fgColor",
|
|
1062
|
-
"includeMargin",
|
|
1063
|
-
"imageSettings"
|
|
1064
|
-
]);
|
|
1065
|
-
let cells = qrcodegen_default.QrCode.encodeText(value, ERROR_LEVEL_MAP[level]).getModules();
|
|
1066
|
-
const margin = includeMargin ? MARGIN_SIZE : 0;
|
|
1067
|
-
const numCells = cells.length + margin * 2;
|
|
1068
|
-
const calculatedImageSettings = getImageSettings(cells, size, includeMargin, imageSettings);
|
|
1069
|
-
let image = null;
|
|
1070
|
-
if (imageSettings != null && calculatedImageSettings != null) {
|
|
1071
|
-
if (calculatedImageSettings.excavation != null) {
|
|
1072
|
-
cells = excavateModules(cells, calculatedImageSettings.excavation);
|
|
1073
|
-
}
|
|
1074
|
-
image = /* @__PURE__ */ React__default["default"].createElement("image", {
|
|
1075
|
-
xlinkHref: imageSettings.src,
|
|
1076
|
-
height: calculatedImageSettings.h,
|
|
1077
|
-
width: calculatedImageSettings.w,
|
|
1078
|
-
x: calculatedImageSettings.x + margin,
|
|
1079
|
-
y: calculatedImageSettings.y + margin,
|
|
1080
|
-
preserveAspectRatio: "none"
|
|
1081
|
-
});
|
|
1082
|
-
}
|
|
1083
|
-
const fgPath = generatePath(cells, margin);
|
|
1084
|
-
return /* @__PURE__ */ React__default["default"].createElement("svg", __spreadValues({
|
|
1085
|
-
height: size,
|
|
1086
|
-
width: size,
|
|
1087
|
-
viewBox: `0 0 ${numCells} ${numCells}`
|
|
1088
|
-
}, otherProps), /* @__PURE__ */ React__default["default"].createElement("path", {
|
|
1089
|
-
fill: bgColor,
|
|
1090
|
-
d: `M0,0 h${numCells}v${numCells}H0z`,
|
|
1091
|
-
shapeRendering: "crispEdges"
|
|
1092
|
-
}), /* @__PURE__ */ React__default["default"].createElement("path", {
|
|
1093
|
-
fill: fgColor,
|
|
1094
|
-
d: fgPath,
|
|
1095
|
-
shapeRendering: "crispEdges"
|
|
1096
|
-
}), image);
|
|
1097
|
-
}
|
|
1098
|
-
var QRCode = (props) => {
|
|
1099
|
-
const _a = props, { renderAs } = _a, otherProps = __objRest(_a, ["renderAs"]);
|
|
1100
|
-
if (renderAs === "svg") {
|
|
1101
|
-
return /* @__PURE__ */ React__default["default"].createElement(QRCodeSVG, __spreadValues({}, otherProps));
|
|
1102
|
-
}
|
|
1103
|
-
return /* @__PURE__ */ React__default["default"].createElement(QRCodeCanvas, __spreadValues({}, otherProps));
|
|
1104
|
-
};
|
|
1105
|
-
|
|
1106
|
-
var QRCodeModal = function QRCodeModal(_ref) {
|
|
1107
|
-
var entity = _ref.entity,
|
|
1108
|
-
entityName = _ref.entityName,
|
|
1109
|
-
isOpen = _ref.isOpen,
|
|
1110
|
-
onClose = _ref.onClose,
|
|
1111
|
-
url = _ref.url;
|
|
1112
|
-
var _useTranslation = reactI18next.useTranslation(),
|
|
1113
|
-
t = _useTranslation.t;
|
|
1114
|
-
if (!entity) return null;
|
|
1115
|
-
var id = entity.id,
|
|
1116
|
-
name = entity.name;
|
|
1117
|
-
var canvasId = "qrcode-share-".concat(id);
|
|
1118
|
-
var handleDownload = function handleDownload() {
|
|
1119
|
-
var canvas = document.getElementById(canvasId);
|
|
1120
|
-
if (canvas) downloadCanvas(canvas, {
|
|
1121
|
-
name: pure.slugify(name)
|
|
1122
|
-
});
|
|
1123
|
-
};
|
|
1124
|
-
return /*#__PURE__*/React__default["default"].createElement(neetoui.Modal, {
|
|
1125
|
-
"data-testid": "qr-code-modal",
|
|
1126
|
-
isOpen: isOpen,
|
|
1127
|
-
onClose: onClose
|
|
1128
|
-
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Modal.Header, {
|
|
1129
|
-
description: t("neetoMolecules.shareViaLink.socialMediaShare.qrCodeInfo", {
|
|
1130
|
-
entity: entityName
|
|
1131
|
-
})
|
|
1132
|
-
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
1133
|
-
className: "mb-0.5",
|
|
1134
|
-
lineHeight: "normal",
|
|
1135
|
-
style: "h3",
|
|
1136
|
-
weight: "semibold"
|
|
1137
|
-
}, t("neetoMolecules.shareViaLink.socialMediaShare.qrCodeDownload"))), /*#__PURE__*/React__default["default"].createElement(neetoui.Modal.Body, null, /*#__PURE__*/React__default["default"].createElement(QRCode, {
|
|
1138
|
-
"data-testid": canvasId,
|
|
1139
|
-
id: canvasId,
|
|
1140
|
-
value: url
|
|
1141
|
-
})), /*#__PURE__*/React__default["default"].createElement(neetoui.Modal.Footer, {
|
|
1142
|
-
className: "space-x-2"
|
|
1143
|
-
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
|
|
1144
|
-
"data-testid": "qr-code-download-button",
|
|
1145
|
-
label: t("neetoMolecules.shareViaLink.socialMediaShare.qrCodeDownload"),
|
|
1146
|
-
onClick: handleDownload
|
|
1147
|
-
}), /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
|
|
1148
|
-
label: t("neetoMolecules.common.actions.cancel"),
|
|
1149
|
-
style: "text",
|
|
1150
|
-
onClick: onClose
|
|
1151
|
-
})));
|
|
1152
|
-
};
|
|
1153
|
-
|
|
1154
|
-
var SocialMedia = function SocialMedia(_ref) {
|
|
1155
|
-
var entity = _ref.entity,
|
|
1156
|
-
entityName = _ref.entityName,
|
|
1157
|
-
postTitle = _ref.postTitle,
|
|
1158
|
-
url = _ref.url;
|
|
1159
|
-
var _useState = React.useState(false),
|
|
1160
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
1161
|
-
isQRCodeModalOpen = _useState2[0],
|
|
1162
|
-
setIsQRCodeModalOpen = _useState2[1];
|
|
1163
|
-
var _useTranslation = reactI18next.useTranslation(),
|
|
1164
|
-
t = _useTranslation.t;
|
|
1165
|
-
var socialMediaButtonClasses = "neeto-ui-bg-gray-200 hover:neeto-ui-bg-gray-300 flex h-12 w-12 cursor-pointer items-center justify-center rounded-md transition-colors duration-300 ease-in-out";
|
|
1166
|
-
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1167
|
-
className: "space-y-4",
|
|
1168
|
-
"data-testid": "social-media-block"
|
|
1169
|
-
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
1170
|
-
className: "neeto-ui-text-gray-800",
|
|
1171
|
-
lineHeight: "snug",
|
|
1172
|
-
style: "body2",
|
|
1173
|
-
weight: "medium"
|
|
1174
|
-
}, t("neetoMolecules.shareViaLink.socialMediaShare.title")), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1175
|
-
className: "flex items-center gap-4"
|
|
1176
|
-
}, Object.entries(SOCIAL_MEDIA_OPTIONS).map(function (_ref2) {
|
|
1177
|
-
var _ref3 = _slicedToArray(_ref2, 2),
|
|
1178
|
-
key = _ref3[0],
|
|
1179
|
-
_ref3$ = _ref3[1],
|
|
1180
|
-
label = _ref3$.label,
|
|
1181
|
-
Icon = _ref3$.icon,
|
|
1182
|
-
generateShareUrl = _ref3$.generateShareUrl;
|
|
1183
|
-
return /*#__PURE__*/React__default["default"].createElement("a", {
|
|
1184
|
-
className: socialMediaButtonClasses,
|
|
1185
|
-
"data-testid": "social-media-button-".concat(key),
|
|
1186
|
-
href: generateShareUrl({
|
|
1187
|
-
id: entity.id,
|
|
1188
|
-
title: postTitle
|
|
1189
|
-
}),
|
|
1190
|
-
key: key,
|
|
1191
|
-
rel: "noopener noreferrer",
|
|
1192
|
-
target: "_blank",
|
|
1193
|
-
title: label
|
|
1194
|
-
}, /*#__PURE__*/React__default["default"].createElement(Icon, {
|
|
1195
|
-
size: 24
|
|
1196
|
-
}));
|
|
1197
|
-
}), /*#__PURE__*/React__default["default"].createElement(neetoui.Tooltip, {
|
|
1198
|
-
content: t("neetoMolecules.shareViaLink.socialMediaShare.qrCode")
|
|
1199
|
-
}, /*#__PURE__*/React__default["default"].createElement("button", {
|
|
1200
|
-
className: socialMediaButtonClasses,
|
|
1201
|
-
"data-testid": "qr-code-button",
|
|
1202
|
-
onClick: function onClick() {
|
|
1203
|
-
return setIsQRCodeModalOpen(true);
|
|
1204
|
-
}
|
|
1205
|
-
}, /*#__PURE__*/React__default["default"].createElement(neetoIcons.QrCode, null)))), /*#__PURE__*/React__default["default"].createElement(QRCodeModal, {
|
|
1206
|
-
entity: entity,
|
|
1207
|
-
entityName: entityName,
|
|
1208
|
-
isOpen: isQRCodeModalOpen,
|
|
1209
|
-
url: url,
|
|
1210
|
-
onClose: function onClose() {
|
|
1211
|
-
return setIsQRCodeModalOpen(false);
|
|
1212
|
-
}
|
|
1213
|
-
}));
|
|
1214
|
-
};
|
|
1215
|
-
|
|
1216
|
-
var ShareViaLink = function ShareViaLink(_ref) {
|
|
1217
|
-
var _ref$isRegenerating = _ref.isRegenerating,
|
|
1218
|
-
isRegenerating = _ref$isRegenerating === void 0 ? false : _ref$isRegenerating,
|
|
1219
|
-
_ref$enableRegenerate = _ref.enableRegenerateUrl,
|
|
1220
|
-
enableRegenerateUrl = _ref$enableRegenerate === void 0 ? false : _ref$enableRegenerate,
|
|
1221
|
-
entity = _ref.entity,
|
|
1222
|
-
entityName = _ref.entityName,
|
|
1223
|
-
_ref$handleRegenerate = _ref.handleRegenerate,
|
|
1224
|
-
handleRegenerate = _ref$handleRegenerate === void 0 ? pure.noop : _ref$handleRegenerate,
|
|
1225
|
-
_ref$previewUrl = _ref.previewUrl,
|
|
1226
|
-
previewUrl = _ref$previewUrl === void 0 ? "" : _ref$previewUrl,
|
|
1227
|
-
socialMediaPostTitle = _ref.socialMediaPostTitle,
|
|
1228
|
-
url = _ref.url;
|
|
1229
|
-
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1230
|
-
className: "neeto-ui-border-gray-400 neeto-ui-shadow-xs neeto-ui-rounded-lg neeto-ui-bg-white col-span-2 space-y-4 border p-8",
|
|
1231
|
-
"data-testid": "share-via-link"
|
|
1232
|
-
}, /*#__PURE__*/React__default["default"].createElement(Link, {
|
|
1233
|
-
enableRegenerateUrl: enableRegenerateUrl,
|
|
1234
|
-
entityName: entityName,
|
|
1235
|
-
handleRegenerate: handleRegenerate,
|
|
1236
|
-
isRegenerating: isRegenerating,
|
|
1237
|
-
previewUrl: previewUrl,
|
|
1238
|
-
url: url
|
|
1239
|
-
}), /*#__PURE__*/React__default["default"].createElement(SocialMedia, {
|
|
1240
|
-
entity: entity,
|
|
1241
|
-
entityName: entityName,
|
|
1242
|
-
postTitle: socialMediaPostTitle,
|
|
1243
|
-
url: url
|
|
1244
|
-
}));
|
|
1245
|
-
};
|
|
1246
|
-
|
|
1247
|
-
module.exports = ShareViaLink;
|
|
6
|
+
*/function T(e,t=0){const n=[];return e.forEach((function(e,r){let a=null;e.forEach((function(o,l){if(!o&&null!==a)return n.push(`M${a+t} ${r+t}h${l-a}v1H${a+t}z`),void(a=null);if(l!==e.length-1)o&&null===a&&(a=l);else{if(!o)return;null===a?n.push(`M${l+t},${r+t} h1v1H${l+t}z`):n.push(`M${a+t},${r+t} h${l+1-a}v1H${a+t}z`)}}))})),n.join("")}function x(e,t){return e.slice().map(((e,n)=>n<t.y||n>=t.y+t.h?e:e.map(((e,n)=>(n<t.x||n>=t.x+t.w)&&e))))}function U(e,t,n,r){if(null==r)return null;const a=n?L:0,o=e.length+2*a,l=Math.floor(t*O),i=o/t,s=(r.width||l)*i,u=(r.height||l)*i,c=null==r.x?e.length/2-s/2:r.x*i,d=null==r.y?e.length/2-u/2:r.y*i;let h=null;if(r.excavate){let e=Math.floor(c),t=Math.floor(d);h={x:e,y:t,w:Math.ceil(s+c-e),h:Math.ceil(u+d-t)}}return{x:c,y:d,h:u,w:s,excavation:h}}var _=function(){try{(new Path2D).addPath(new Path2D)}catch(e){return!1}return!0}();function B(t){const n=t,{value:r,size:a=A,level:o=k,bgColor:l=S,fgColor:s=I,includeMargin:u=P,style:c,imageSettings:d}=n,h=v(n,["value","size","level","bgColor","fgColor","includeMargin","style","imageSettings"]),f=null==d?void 0:d.src,m=e.useRef(null),g=e.useRef(null),[E,y]=e.useState(!1);e.useEffect((()=>{if(null!=m.current){const e=m.current,t=e.getContext("2d");if(!t)return;let n=R.QrCode.encodeText(r,N[o]).getModules();const i=u?L:0,c=n.length+2*i,h=U(n,a,u,d),f=g.current,E=null!=h&&null!==f&&f.complete&&0!==f.naturalHeight&&0!==f.naturalWidth;E&&null!=h.excavation&&(n=x(n,h.excavation));const y=window.devicePixelRatio||1;e.height=e.width=a*y;const p=a/c*y;t.scale(p,p),t.fillStyle=l,t.fillRect(0,0,c,c),t.fillStyle=s,_?t.fill(new Path2D(T(n,i))):n.forEach((function(e,n){e.forEach((function(e,r){e&&t.fillRect(r+i,n+i,1,1)}))})),E&&t.drawImage(f,h.x+i,h.y+i,h.w,h.h)}})),e.useEffect((()=>{y(!1)}),[f]);const p=b({height:a,width:a},c);let M=null;return null!=f&&(M=i.default.createElement("img",{src:f,key:f,style:{display:"none"},onLoad:()=>{y(!0)},ref:g})),i.default.createElement(i.default.Fragment,null,i.default.createElement("canvas",b({style:p,height:a,width:a,ref:m},h)),M)}function F(e){const t=e,{value:n,size:r=A,level:a=k,bgColor:o=S,fgColor:l=I,includeMargin:s=P,imageSettings:u}=t,c=v(t,["value","size","level","bgColor","fgColor","includeMargin","imageSettings"]);let d=R.QrCode.encodeText(n,N[a]).getModules();const h=s?L:0,f=d.length+2*h,m=U(d,r,s,u);let g=null;null!=u&&null!=m&&(null!=m.excavation&&(d=x(d,m.excavation)),g=i.default.createElement("image",{xlinkHref:u.src,height:m.h,width:m.w,x:m.x+h,y:m.y+h,preserveAspectRatio:"none"}));const E=T(d,h);return i.default.createElement("svg",b({height:r,width:r,viewBox:`0 0 ${f} ${f}`},c),i.default.createElement("path",{fill:o,d:`M0,0 h${f}v${f}H0z`,shapeRendering:"crispEdges"}),i.default.createElement("path",{fill:l,d:E,shapeRendering:"crispEdges"}),g)}var z=e=>{const t=e,{renderAs:n}=t,r=v(t,["renderAs"]);return"svg"===n?i.default.createElement(F,b({},r)):i.default.createElement(B,b({},r))},H=function(e){var n=e.entity,r=e.entityName,l=e.isOpen,s=e.onClose,u=e.url,c=o.useTranslation().t;if(!n)return null;var d=n.id,h=n.name,f="qrcode-share-".concat(d);return i.default.createElement(a.Modal,{"data-testid":"qr-code-modal",isOpen:l,onClose:s},i.default.createElement(a.Modal.Header,{description:c("neetoMolecules.shareViaLink.socialMediaShare.qrCodeInfo",{entity:r})},i.default.createElement(a.Typography,{className:"mb-0.5",lineHeight:"normal",style:"h3",weight:"semibold"},c("neetoMolecules.shareViaLink.socialMediaShare.qrCodeDownload"))),i.default.createElement(a.Modal.Body,null,i.default.createElement(z,{"data-testid":f,id:f,value:u})),i.default.createElement(a.Modal.Footer,{className:"space-x-2"},i.default.createElement(a.Button,{"data-testid":"qr-code-download-button",label:c("neetoMolecules.shareViaLink.socialMediaShare.qrCodeDownload"),onClick:function(){var e=document.getElementById(f);e&&function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.name,r=void 0===n?"image":n,a=t.extension,o=void 0===a?"png":a,l=e.toDataURL("image/".concat(o)),i=document.createElement("a");i.href=l,i.download="".concat(r,".").concat(o),i.click(),i.remove()}(e,{name:t.slugify(h)})}}),i.default.createElement(a.Button,{label:c("neetoMolecules.common.actions.cancel"),style:"text",onClick:s})))},D=function(t){var n=t.entity,l=t.entityName,s=t.postTitle,c=t.url,d=u(e.useState(!1),2),h=d[0],f=d[1],m=o.useTranslation().t,g="neeto-ui-bg-gray-200 hover:neeto-ui-bg-gray-300 flex h-12 w-12 cursor-pointer items-center justify-center rounded-md transition-colors duration-300 ease-in-out";return i.default.createElement("div",{className:"space-y-4","data-testid":"social-media-block"},i.default.createElement(a.Typography,{className:"neeto-ui-text-gray-800",lineHeight:"snug",style:"body2",weight:"medium"},m("neetoMolecules.shareViaLink.socialMediaShare.title")),i.default.createElement("div",{className:"flex items-center gap-4"},Object.entries(E).map((function(e){var t=u(e,2),r=t[0],a=t[1],o=a.label,l=a.icon,c=a.generateShareUrl;return i.default.createElement("a",{className:g,"data-testid":"social-media-button-".concat(r),href:c({id:n.id,title:s}),key:r,rel:"noopener noreferrer",target:"_blank",title:o},i.default.createElement(l,{size:24}))})),i.default.createElement(a.Tooltip,{content:m("neetoMolecules.shareViaLink.socialMediaShare.qrCode")},i.default.createElement("button",{className:g,"data-testid":"qr-code-button",onClick:function(){return f(!0)}},i.default.createElement(r.QrCode,null)))),i.default.createElement(H,{entity:n,entityName:l,isOpen:h,url:c,onClose:function(){return f(!1)}}))};module.exports=function(e){var n=e.isRegenerating,r=void 0!==n&&n,a=e.enableRegenerateUrl,o=void 0!==a&&a,l=e.entity,s=e.entityName,u=e.handleRegenerate,c=void 0===u?t.noop:u,d=e.previewUrl,h=void 0===d?"":d,f=e.socialMediaPostTitle,m=e.url;return i.default.createElement("div",{className:"neeto-ui-border-gray-400 neeto-ui-shadow-xs neeto-ui-rounded-lg neeto-ui-bg-white col-span-2 space-y-4 border p-8","data-testid":"share-via-link"},i.default.createElement(g,{enableRegenerateUrl:o,entityName:s,handleRegenerate:c,isRegenerating:r,previewUrl:h,url:m}),i.default.createElement(D,{entity:l,entityName:s,postTitle:f,url:m}))};
|