@matter-server/dashboard 1.2.4 → 1.2.5

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 (50) hide show
  1. package/README.md +15 -2
  2. package/dist/esm/pages/components/node-details.d.ts.map +1 -1
  3. package/dist/esm/pages/components/node-details.js +14 -1
  4. package/dist/esm/pages/components/node-details.js.map +1 -1
  5. package/dist/esm/pages/matter-cluster-view.d.ts +1 -0
  6. package/dist/esm/pages/matter-cluster-view.d.ts.map +1 -1
  7. package/dist/esm/pages/matter-cluster-view.js +8 -0
  8. package/dist/esm/pages/matter-cluster-view.js.map +1 -1
  9. package/dist/esm/pages/matter-dashboard-app.d.ts.map +1 -1
  10. package/dist/esm/pages/matter-dashboard-app.js +1 -0
  11. package/dist/esm/pages/matter-dashboard-app.js.map +1 -1
  12. package/dist/esm/pages/network/network-details.d.ts.map +1 -1
  13. package/dist/esm/pages/network/network-details.js +20 -7
  14. package/dist/esm/pages/network/network-details.js.map +1 -1
  15. package/dist/esm/pages/network/network-types.d.ts +2 -0
  16. package/dist/esm/pages/network/network-types.d.ts.map +1 -1
  17. package/dist/esm/pages/network/network-utils.d.ts +16 -0
  18. package/dist/esm/pages/network/network-utils.d.ts.map +1 -1
  19. package/dist/esm/pages/network/network-utils.js +33 -0
  20. package/dist/esm/pages/network/network-utils.js.map +1 -1
  21. package/dist/esm/pages/network/thread-graph.d.ts.map +1 -1
  22. package/dist/esm/pages/network/thread-graph.js +13 -0
  23. package/dist/esm/pages/network/thread-graph.js.map +1 -1
  24. package/dist/esm/util/pairing-code.d.ts +18 -0
  25. package/dist/esm/util/pairing-code.d.ts.map +1 -0
  26. package/dist/esm/util/pairing-code.js +24 -0
  27. package/dist/esm/util/pairing-code.js.map +6 -0
  28. package/dist/web/js/{attribute-write-dialog-fBF9_jCK.js → attribute-write-dialog-yHLoNOkW.js} +1 -1
  29. package/dist/web/js/{command-invoke-dialog-DWMBX1gN.js → command-invoke-dialog-ByzPtgEb.js} +1 -1
  30. package/dist/web/js/{commission-node-dialog-BptZBF2k.js → commission-node-dialog-BlT9WOki.js} +5 -5
  31. package/dist/web/js/{commission-node-existing-yUyavzOc.js → commission-node-existing-DMPiGpS5.js} +1 -1
  32. package/dist/web/js/{commission-node-thread-Cb5v-CtI.js → commission-node-thread-D3X-Not8.js} +1 -1
  33. package/dist/web/js/{commission-node-wifi-R0fGOeQ-.js → commission-node-wifi-3sLvZVvY.js} +1 -1
  34. package/dist/web/js/{dialog-box-DLCbBR3S.js → dialog-box-DXneB7f7.js} +1 -1
  35. package/dist/web/js/{fabric-label-dialog-tW-AnWBx.js → fabric-label-dialog-DoBL1t3o.js} +1 -1
  36. package/dist/web/js/main.js +1 -1
  37. package/dist/web/js/{matter-dashboard-app-BGWRh_7q.js → matter-dashboard-app-mMXFHv8v.js} +1787 -17
  38. package/dist/web/js/{node-acl-add-dialog-DMKY5qsl.js → node-acl-add-dialog-DJrFkAp9.js} +1 -1
  39. package/dist/web/js/{node-binding-dialog-bephut8j.js → node-binding-dialog-CQt-LbiG.js} +1 -1
  40. package/dist/web/js/{node-label-dialog-CHDD9Bk1.js → node-label-dialog-D1CyUaCS.js} +1 -1
  41. package/dist/web/js/{settings-dialog-BT_YDlXZ.js → settings-dialog-B9ctg2Ji.js} +1 -1
  42. package/package.json +8 -5
  43. package/src/pages/components/node-details.ts +14 -1
  44. package/src/pages/matter-cluster-view.ts +9 -0
  45. package/src/pages/matter-dashboard-app.ts +3 -0
  46. package/src/pages/network/network-details.ts +22 -7
  47. package/src/pages/network/network-types.ts +2 -0
  48. package/src/pages/network/network-utils.ts +45 -0
  49. package/src/pages/network/thread-graph.ts +17 -0
  50. package/src/util/pairing-code.ts +32 -0
@@ -4557,7 +4557,7 @@ MdListItem = __decorate([t$1('md-list-item')], MdListItem);
4557
4557
  * SPDX-License-Identifier: Apache-2.0
4558
4558
  */
4559
4559
  const showSettingsDialog = async section => {
4560
- await import('./settings-dialog-BT_YDlXZ.js');
4560
+ await import('./settings-dialog-B9ctg2Ji.js');
4561
4561
  const dialog = document.createElement("settings-dialog");
4562
4562
  if (section) dialog.scrollToSection = section;
4563
4563
  document.querySelector("matter-dashboard-app")?.renderRoot.appendChild(dialog);
@@ -22772,7 +22772,7 @@ const clusters = {
22772
22772
  * SPDX-License-Identifier: Apache-2.0
22773
22773
  */
22774
22774
  const showDialogBox = async (type, dialogParams) => {
22775
- await import('./dialog-box-DLCbBR3S.js');
22775
+ await import('./dialog-box-DXneB7f7.js');
22776
22776
  return new Promise(resolve => {
22777
22777
  const dialog = document.createElement("dialog-box");
22778
22778
  dialog.params = dialogParams;
@@ -22790,7 +22790,7 @@ const showPromptDialog = dialogParams => showDialogBox("prompt", dialogParams);
22790
22790
  * SPDX-License-Identifier: Apache-2.0
22791
22791
  */
22792
22792
  const showAttributeWriteDialog = async options => {
22793
- await import('./attribute-write-dialog-fBF9_jCK.js');
22793
+ await import('./attribute-write-dialog-yHLoNOkW.js');
22794
22794
  const dialog = document.createElement("attribute-write-dialog");
22795
22795
  dialog.client = options.client;
22796
22796
  dialog.nodeId = options.nodeId;
@@ -22808,7 +22808,7 @@ const showAttributeWriteDialog = async options => {
22808
22808
  * SPDX-License-Identifier: Apache-2.0
22809
22809
  */
22810
22810
  const showCommandInvokeDialog = async options => {
22811
- await import('./command-invoke-dialog-DWMBX1gN.js');
22811
+ await import('./command-invoke-dialog-ByzPtgEb.js');
22812
22812
  const dialog = document.createElement("command-invoke-dialog");
22813
22813
  dialog.client = options.client;
22814
22814
  dialog.nodeId = options.nodeId;
@@ -22980,7 +22980,7 @@ MdTextButton = __decorate([t$1('md-text-button')], MdTextButton);
22980
22980
  * SPDX-License-Identifier: Apache-2.0
22981
22981
  */
22982
22982
  const showNodeLabelDialog = async (client, node) => {
22983
- await import('./node-label-dialog-CHDD9Bk1.js');
22983
+ await import('./node-label-dialog-D1CyUaCS.js');
22984
22984
  const dialog = document.createElement("node-label-dialog");
22985
22985
  dialog.client = client;
22986
22986
  dialog.node = node;
@@ -29935,6 +29935,1711 @@ function parseMultiAdminDetails(message) {
29935
29935
  return void 0;
29936
29936
  }
29937
29937
 
29938
+ //---------------------------------------------------------------------
29939
+ //
29940
+ // QR Code Generator for JavaScript
29941
+ //
29942
+ // Copyright (c) 2009 Kazuhiko Arase
29943
+ //
29944
+ // URL: http://www.d-project.com/
29945
+ //
29946
+ // Licensed under the MIT license:
29947
+ // http://www.opensource.org/licenses/mit-license.php
29948
+ //
29949
+ // The word 'QR Code' is registered trademark of
29950
+ // DENSO WAVE INCORPORATED
29951
+ // http://www.denso-wave.com/qrcode/faqpatent-e.html
29952
+ //
29953
+ //---------------------------------------------------------------------
29954
+
29955
+ //---------------------------------------------------------------------
29956
+ // qrcode
29957
+ //---------------------------------------------------------------------
29958
+
29959
+ /**
29960
+ * qrcode
29961
+ * @param typeNumber 1 to 40
29962
+ * @param errorCorrectionLevel 'L','M','Q','H'
29963
+ */
29964
+ const qrcode = function (typeNumber, errorCorrectionLevel) {
29965
+ const PAD0 = 0xEC;
29966
+ const PAD1 = 0x11;
29967
+ let _typeNumber = typeNumber;
29968
+ const _errorCorrectionLevel = QRErrorCorrectionLevel[errorCorrectionLevel];
29969
+ let _modules = null;
29970
+ let _moduleCount = 0;
29971
+ let _dataCache = null;
29972
+ const _dataList = [];
29973
+ const _this = {};
29974
+ const makeImpl = function (test, maskPattern) {
29975
+ _moduleCount = _typeNumber * 4 + 17;
29976
+ _modules = function (moduleCount) {
29977
+ const modules = new Array(moduleCount);
29978
+ for (let row = 0; row < moduleCount; row += 1) {
29979
+ modules[row] = new Array(moduleCount);
29980
+ for (let col = 0; col < moduleCount; col += 1) {
29981
+ modules[row][col] = null;
29982
+ }
29983
+ }
29984
+ return modules;
29985
+ }(_moduleCount);
29986
+ setupPositionProbePattern(0, 0);
29987
+ setupPositionProbePattern(_moduleCount - 7, 0);
29988
+ setupPositionProbePattern(0, _moduleCount - 7);
29989
+ setupPositionAdjustPattern();
29990
+ setupTimingPattern();
29991
+ setupTypeInfo(test, maskPattern);
29992
+ if (_typeNumber >= 7) {
29993
+ setupTypeNumber(test);
29994
+ }
29995
+ if (_dataCache == null) {
29996
+ _dataCache = createData(_typeNumber, _errorCorrectionLevel, _dataList);
29997
+ }
29998
+ mapData(_dataCache, maskPattern);
29999
+ };
30000
+ const setupPositionProbePattern = function (row, col) {
30001
+ for (let r = -1; r <= 7; r += 1) {
30002
+ if (row + r <= -1 || _moduleCount <= row + r) continue;
30003
+ for (let c = -1; c <= 7; c += 1) {
30004
+ if (col + c <= -1 || _moduleCount <= col + c) continue;
30005
+ if (0 <= r && r <= 6 && (c == 0 || c == 6) || 0 <= c && c <= 6 && (r == 0 || r == 6) || 2 <= r && r <= 4 && 2 <= c && c <= 4) {
30006
+ _modules[row + r][col + c] = true;
30007
+ } else {
30008
+ _modules[row + r][col + c] = false;
30009
+ }
30010
+ }
30011
+ }
30012
+ };
30013
+ const getBestMaskPattern = function () {
30014
+ let minLostPoint = 0;
30015
+ let pattern = 0;
30016
+ for (let i = 0; i < 8; i += 1) {
30017
+ makeImpl(true, i);
30018
+ const lostPoint = QRUtil.getLostPoint(_this);
30019
+ if (i == 0 || minLostPoint > lostPoint) {
30020
+ minLostPoint = lostPoint;
30021
+ pattern = i;
30022
+ }
30023
+ }
30024
+ return pattern;
30025
+ };
30026
+ const setupTimingPattern = function () {
30027
+ for (let r = 8; r < _moduleCount - 8; r += 1) {
30028
+ if (_modules[r][6] != null) {
30029
+ continue;
30030
+ }
30031
+ _modules[r][6] = r % 2 == 0;
30032
+ }
30033
+ for (let c = 8; c < _moduleCount - 8; c += 1) {
30034
+ if (_modules[6][c] != null) {
30035
+ continue;
30036
+ }
30037
+ _modules[6][c] = c % 2 == 0;
30038
+ }
30039
+ };
30040
+ const setupPositionAdjustPattern = function () {
30041
+ const pos = QRUtil.getPatternPosition(_typeNumber);
30042
+ for (let i = 0; i < pos.length; i += 1) {
30043
+ for (let j = 0; j < pos.length; j += 1) {
30044
+ const row = pos[i];
30045
+ const col = pos[j];
30046
+ if (_modules[row][col] != null) {
30047
+ continue;
30048
+ }
30049
+ for (let r = -2; r <= 2; r += 1) {
30050
+ for (let c = -2; c <= 2; c += 1) {
30051
+ if (r == -2 || r == 2 || c == -2 || c == 2 || r == 0 && c == 0) {
30052
+ _modules[row + r][col + c] = true;
30053
+ } else {
30054
+ _modules[row + r][col + c] = false;
30055
+ }
30056
+ }
30057
+ }
30058
+ }
30059
+ }
30060
+ };
30061
+ const setupTypeNumber = function (test) {
30062
+ const bits = QRUtil.getBCHTypeNumber(_typeNumber);
30063
+ for (let i = 0; i < 18; i += 1) {
30064
+ const mod = !test && (bits >> i & 1) == 1;
30065
+ _modules[Math.floor(i / 3)][i % 3 + _moduleCount - 8 - 3] = mod;
30066
+ }
30067
+ for (let i = 0; i < 18; i += 1) {
30068
+ const mod = !test && (bits >> i & 1) == 1;
30069
+ _modules[i % 3 + _moduleCount - 8 - 3][Math.floor(i / 3)] = mod;
30070
+ }
30071
+ };
30072
+ const setupTypeInfo = function (test, maskPattern) {
30073
+ const data = _errorCorrectionLevel << 3 | maskPattern;
30074
+ const bits = QRUtil.getBCHTypeInfo(data);
30075
+
30076
+ // vertical
30077
+ for (let i = 0; i < 15; i += 1) {
30078
+ const mod = !test && (bits >> i & 1) == 1;
30079
+ if (i < 6) {
30080
+ _modules[i][8] = mod;
30081
+ } else if (i < 8) {
30082
+ _modules[i + 1][8] = mod;
30083
+ } else {
30084
+ _modules[_moduleCount - 15 + i][8] = mod;
30085
+ }
30086
+ }
30087
+
30088
+ // horizontal
30089
+ for (let i = 0; i < 15; i += 1) {
30090
+ const mod = !test && (bits >> i & 1) == 1;
30091
+ if (i < 8) {
30092
+ _modules[8][_moduleCount - i - 1] = mod;
30093
+ } else if (i < 9) {
30094
+ _modules[8][15 - i - 1 + 1] = mod;
30095
+ } else {
30096
+ _modules[8][15 - i - 1] = mod;
30097
+ }
30098
+ }
30099
+
30100
+ // fixed module
30101
+ _modules[_moduleCount - 8][8] = !test;
30102
+ };
30103
+ const mapData = function (data, maskPattern) {
30104
+ let inc = -1;
30105
+ let row = _moduleCount - 1;
30106
+ let bitIndex = 7;
30107
+ let byteIndex = 0;
30108
+ const maskFunc = QRUtil.getMaskFunction(maskPattern);
30109
+ for (let col = _moduleCount - 1; col > 0; col -= 2) {
30110
+ if (col == 6) col -= 1;
30111
+ while (true) {
30112
+ for (let c = 0; c < 2; c += 1) {
30113
+ if (_modules[row][col - c] == null) {
30114
+ let dark = false;
30115
+ if (byteIndex < data.length) {
30116
+ dark = (data[byteIndex] >>> bitIndex & 1) == 1;
30117
+ }
30118
+ const mask = maskFunc(row, col - c);
30119
+ if (mask) {
30120
+ dark = !dark;
30121
+ }
30122
+ _modules[row][col - c] = dark;
30123
+ bitIndex -= 1;
30124
+ if (bitIndex == -1) {
30125
+ byteIndex += 1;
30126
+ bitIndex = 7;
30127
+ }
30128
+ }
30129
+ }
30130
+ row += inc;
30131
+ if (row < 0 || _moduleCount <= row) {
30132
+ row -= inc;
30133
+ inc = -inc;
30134
+ break;
30135
+ }
30136
+ }
30137
+ }
30138
+ };
30139
+ const createBytes = function (buffer, rsBlocks) {
30140
+ let offset = 0;
30141
+ let maxDcCount = 0;
30142
+ let maxEcCount = 0;
30143
+ const dcdata = new Array(rsBlocks.length);
30144
+ const ecdata = new Array(rsBlocks.length);
30145
+ for (let r = 0; r < rsBlocks.length; r += 1) {
30146
+ const dcCount = rsBlocks[r].dataCount;
30147
+ const ecCount = rsBlocks[r].totalCount - dcCount;
30148
+ maxDcCount = Math.max(maxDcCount, dcCount);
30149
+ maxEcCount = Math.max(maxEcCount, ecCount);
30150
+ dcdata[r] = new Array(dcCount);
30151
+ for (let i = 0; i < dcdata[r].length; i += 1) {
30152
+ dcdata[r][i] = 0xff & buffer.getBuffer()[i + offset];
30153
+ }
30154
+ offset += dcCount;
30155
+ const rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
30156
+ const rawPoly = qrPolynomial(dcdata[r], rsPoly.getLength() - 1);
30157
+ const modPoly = rawPoly.mod(rsPoly);
30158
+ ecdata[r] = new Array(rsPoly.getLength() - 1);
30159
+ for (let i = 0; i < ecdata[r].length; i += 1) {
30160
+ const modIndex = i + modPoly.getLength() - ecdata[r].length;
30161
+ ecdata[r][i] = modIndex >= 0 ? modPoly.getAt(modIndex) : 0;
30162
+ }
30163
+ }
30164
+ let totalCodeCount = 0;
30165
+ for (let i = 0; i < rsBlocks.length; i += 1) {
30166
+ totalCodeCount += rsBlocks[i].totalCount;
30167
+ }
30168
+ const data = new Array(totalCodeCount);
30169
+ let index = 0;
30170
+ for (let i = 0; i < maxDcCount; i += 1) {
30171
+ for (let r = 0; r < rsBlocks.length; r += 1) {
30172
+ if (i < dcdata[r].length) {
30173
+ data[index] = dcdata[r][i];
30174
+ index += 1;
30175
+ }
30176
+ }
30177
+ }
30178
+ for (let i = 0; i < maxEcCount; i += 1) {
30179
+ for (let r = 0; r < rsBlocks.length; r += 1) {
30180
+ if (i < ecdata[r].length) {
30181
+ data[index] = ecdata[r][i];
30182
+ index += 1;
30183
+ }
30184
+ }
30185
+ }
30186
+ return data;
30187
+ };
30188
+ const createData = function (typeNumber, errorCorrectionLevel, dataList) {
30189
+ const rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectionLevel);
30190
+ const buffer = qrBitBuffer();
30191
+ for (let i = 0; i < dataList.length; i += 1) {
30192
+ const data = dataList[i];
30193
+ buffer.put(data.getMode(), 4);
30194
+ buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber));
30195
+ data.write(buffer);
30196
+ }
30197
+
30198
+ // calc num max data.
30199
+ let totalDataCount = 0;
30200
+ for (let i = 0; i < rsBlocks.length; i += 1) {
30201
+ totalDataCount += rsBlocks[i].dataCount;
30202
+ }
30203
+ if (buffer.getLengthInBits() > totalDataCount * 8) {
30204
+ throw 'code length overflow. (' + buffer.getLengthInBits() + '>' + totalDataCount * 8 + ')';
30205
+ }
30206
+
30207
+ // end code
30208
+ if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) {
30209
+ buffer.put(0, 4);
30210
+ }
30211
+
30212
+ // padding
30213
+ while (buffer.getLengthInBits() % 8 != 0) {
30214
+ buffer.putBit(false);
30215
+ }
30216
+
30217
+ // padding
30218
+ while (true) {
30219
+ if (buffer.getLengthInBits() >= totalDataCount * 8) {
30220
+ break;
30221
+ }
30222
+ buffer.put(PAD0, 8);
30223
+ if (buffer.getLengthInBits() >= totalDataCount * 8) {
30224
+ break;
30225
+ }
30226
+ buffer.put(PAD1, 8);
30227
+ }
30228
+ return createBytes(buffer, rsBlocks);
30229
+ };
30230
+ _this.addData = function (data, mode) {
30231
+ mode = mode || 'Byte';
30232
+ let newData = null;
30233
+ switch (mode) {
30234
+ case 'Numeric':
30235
+ newData = qrNumber(data);
30236
+ break;
30237
+ case 'Alphanumeric':
30238
+ newData = qrAlphaNum(data);
30239
+ break;
30240
+ case 'Byte':
30241
+ newData = qr8BitByte(data);
30242
+ break;
30243
+ case 'Kanji':
30244
+ newData = qrKanji(data);
30245
+ break;
30246
+ default:
30247
+ throw 'mode:' + mode;
30248
+ }
30249
+ _dataList.push(newData);
30250
+ _dataCache = null;
30251
+ };
30252
+ _this.isDark = function (row, col) {
30253
+ if (row < 0 || _moduleCount <= row || col < 0 || _moduleCount <= col) {
30254
+ throw row + ',' + col;
30255
+ }
30256
+ return _modules[row][col];
30257
+ };
30258
+ _this.getModuleCount = function () {
30259
+ return _moduleCount;
30260
+ };
30261
+ _this.make = function () {
30262
+ if (_typeNumber < 1) {
30263
+ let typeNumber = 1;
30264
+ for (; typeNumber < 40; typeNumber++) {
30265
+ const rsBlocks = QRRSBlock.getRSBlocks(typeNumber, _errorCorrectionLevel);
30266
+ const buffer = qrBitBuffer();
30267
+ for (let i = 0; i < _dataList.length; i++) {
30268
+ const data = _dataList[i];
30269
+ buffer.put(data.getMode(), 4);
30270
+ buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber));
30271
+ data.write(buffer);
30272
+ }
30273
+ let totalDataCount = 0;
30274
+ for (let i = 0; i < rsBlocks.length; i++) {
30275
+ totalDataCount += rsBlocks[i].dataCount;
30276
+ }
30277
+ if (buffer.getLengthInBits() <= totalDataCount * 8) {
30278
+ break;
30279
+ }
30280
+ }
30281
+ _typeNumber = typeNumber;
30282
+ }
30283
+ makeImpl(false, getBestMaskPattern());
30284
+ };
30285
+ _this.createTableTag = function (cellSize, margin) {
30286
+ cellSize = cellSize || 2;
30287
+ margin = typeof margin == 'undefined' ? cellSize * 4 : margin;
30288
+ let qrHtml = '';
30289
+ qrHtml += '<table style="';
30290
+ qrHtml += ' border-width: 0px; border-style: none;';
30291
+ qrHtml += ' border-collapse: collapse;';
30292
+ qrHtml += ' padding: 0px; margin: ' + margin + 'px;';
30293
+ qrHtml += '">';
30294
+ qrHtml += '<tbody>';
30295
+ for (let r = 0; r < _this.getModuleCount(); r += 1) {
30296
+ qrHtml += '<tr>';
30297
+ for (let c = 0; c < _this.getModuleCount(); c += 1) {
30298
+ qrHtml += '<td style="';
30299
+ qrHtml += ' border-width: 0px; border-style: none;';
30300
+ qrHtml += ' border-collapse: collapse;';
30301
+ qrHtml += ' padding: 0px; margin: 0px;';
30302
+ qrHtml += ' width: ' + cellSize + 'px;';
30303
+ qrHtml += ' height: ' + cellSize + 'px;';
30304
+ qrHtml += ' background-color: ';
30305
+ qrHtml += _this.isDark(r, c) ? '#000000' : '#ffffff';
30306
+ qrHtml += ';';
30307
+ qrHtml += '"/>';
30308
+ }
30309
+ qrHtml += '</tr>';
30310
+ }
30311
+ qrHtml += '</tbody>';
30312
+ qrHtml += '</table>';
30313
+ return qrHtml;
30314
+ };
30315
+ _this.createSvgTag = function (cellSize, margin, alt, title) {
30316
+ let opts = {};
30317
+ if (typeof arguments[0] == 'object') {
30318
+ // Called by options.
30319
+ opts = arguments[0];
30320
+ // overwrite cellSize and margin.
30321
+ cellSize = opts.cellSize;
30322
+ margin = opts.margin;
30323
+ alt = opts.alt;
30324
+ title = opts.title;
30325
+ }
30326
+ cellSize = cellSize || 2;
30327
+ margin = typeof margin == 'undefined' ? cellSize * 4 : margin;
30328
+
30329
+ // Compose alt property surrogate
30330
+ alt = typeof alt === 'string' ? {
30331
+ text: alt
30332
+ } : alt || {};
30333
+ alt.text = alt.text || null;
30334
+ alt.id = alt.text ? alt.id || 'qrcode-description' : null;
30335
+
30336
+ // Compose title property surrogate
30337
+ title = typeof title === 'string' ? {
30338
+ text: title
30339
+ } : title || {};
30340
+ title.text = title.text || null;
30341
+ title.id = title.text ? title.id || 'qrcode-title' : null;
30342
+ const size = _this.getModuleCount() * cellSize + margin * 2;
30343
+ let c,
30344
+ mc,
30345
+ r,
30346
+ mr,
30347
+ qrSvg = '',
30348
+ rect;
30349
+ rect = 'l' + cellSize + ',0 0,' + cellSize + ' -' + cellSize + ',0 0,-' + cellSize + 'z ';
30350
+ qrSvg += '<svg version="1.1" xmlns="http://www.w3.org/2000/svg"';
30351
+ qrSvg += !opts.scalable ? ' width="' + size + 'px" height="' + size + 'px"' : '';
30352
+ qrSvg += ' viewBox="0 0 ' + size + ' ' + size + '" ';
30353
+ qrSvg += ' preserveAspectRatio="xMinYMin meet"';
30354
+ qrSvg += title.text || alt.text ? ' role="img" aria-labelledby="' + escapeXml([title.id, alt.id].join(' ').trim()) + '"' : '';
30355
+ qrSvg += '>';
30356
+ qrSvg += title.text ? '<title id="' + escapeXml(title.id) + '">' + escapeXml(title.text) + '</title>' : '';
30357
+ qrSvg += alt.text ? '<description id="' + escapeXml(alt.id) + '">' + escapeXml(alt.text) + '</description>' : '';
30358
+ qrSvg += '<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>';
30359
+ qrSvg += '<path d="';
30360
+ for (r = 0; r < _this.getModuleCount(); r += 1) {
30361
+ mr = r * cellSize + margin;
30362
+ for (c = 0; c < _this.getModuleCount(); c += 1) {
30363
+ if (_this.isDark(r, c)) {
30364
+ mc = c * cellSize + margin;
30365
+ qrSvg += 'M' + mc + ',' + mr + rect;
30366
+ }
30367
+ }
30368
+ }
30369
+ qrSvg += '" stroke="transparent" fill="black"/>';
30370
+ qrSvg += '</svg>';
30371
+ return qrSvg;
30372
+ };
30373
+ _this.createDataURL = function (cellSize, margin) {
30374
+ cellSize = cellSize || 2;
30375
+ margin = typeof margin == 'undefined' ? cellSize * 4 : margin;
30376
+ const size = _this.getModuleCount() * cellSize + margin * 2;
30377
+ const min = margin;
30378
+ const max = size - margin;
30379
+ return createDataURL(size, size, function (x, y) {
30380
+ if (min <= x && x < max && min <= y && y < max) {
30381
+ const c = Math.floor((x - min) / cellSize);
30382
+ const r = Math.floor((y - min) / cellSize);
30383
+ return _this.isDark(r, c) ? 0 : 1;
30384
+ } else {
30385
+ return 1;
30386
+ }
30387
+ });
30388
+ };
30389
+ _this.createImgTag = function (cellSize, margin, alt) {
30390
+ cellSize = cellSize || 2;
30391
+ margin = typeof margin == 'undefined' ? cellSize * 4 : margin;
30392
+ const size = _this.getModuleCount() * cellSize + margin * 2;
30393
+ let img = '';
30394
+ img += '<img';
30395
+ img += '\u0020src="';
30396
+ img += _this.createDataURL(cellSize, margin);
30397
+ img += '"';
30398
+ img += '\u0020width="';
30399
+ img += size;
30400
+ img += '"';
30401
+ img += '\u0020height="';
30402
+ img += size;
30403
+ img += '"';
30404
+ if (alt) {
30405
+ img += '\u0020alt="';
30406
+ img += escapeXml(alt);
30407
+ img += '"';
30408
+ }
30409
+ img += '/>';
30410
+ return img;
30411
+ };
30412
+ const escapeXml = function (s) {
30413
+ let escaped = '';
30414
+ for (let i = 0; i < s.length; i += 1) {
30415
+ const c = s.charAt(i);
30416
+ switch (c) {
30417
+ case '<':
30418
+ escaped += '&lt;';
30419
+ break;
30420
+ case '>':
30421
+ escaped += '&gt;';
30422
+ break;
30423
+ case '&':
30424
+ escaped += '&amp;';
30425
+ break;
30426
+ case '"':
30427
+ escaped += '&quot;';
30428
+ break;
30429
+ default:
30430
+ escaped += c;
30431
+ break;
30432
+ }
30433
+ }
30434
+ return escaped;
30435
+ };
30436
+ const _createHalfASCII = function (margin) {
30437
+ const cellSize = 1;
30438
+ margin = typeof margin == 'undefined' ? cellSize * 2 : margin;
30439
+ const size = _this.getModuleCount() * cellSize + margin * 2;
30440
+ const min = margin;
30441
+ const max = size - margin;
30442
+ let y, x, r1, r2, p;
30443
+ const blocks = {
30444
+ '██': '█',
30445
+ '█ ': '▀',
30446
+ ' █': '▄',
30447
+ ' ': ' '
30448
+ };
30449
+ const blocksLastLineNoMargin = {
30450
+ '██': '▀',
30451
+ '█ ': '▀',
30452
+ ' █': ' ',
30453
+ ' ': ' '
30454
+ };
30455
+ let ascii = '';
30456
+ for (y = 0; y < size; y += 2) {
30457
+ r1 = Math.floor((y - min) / cellSize);
30458
+ r2 = Math.floor((y + 1 - min) / cellSize);
30459
+ for (x = 0; x < size; x += 1) {
30460
+ p = '█';
30461
+ if (min <= x && x < max && min <= y && y < max && _this.isDark(r1, Math.floor((x - min) / cellSize))) {
30462
+ p = ' ';
30463
+ }
30464
+ if (min <= x && x < max && min <= y + 1 && y + 1 < max && _this.isDark(r2, Math.floor((x - min) / cellSize))) {
30465
+ p += ' ';
30466
+ } else {
30467
+ p += '█';
30468
+ }
30469
+
30470
+ // Output 2 characters per pixel, to create full square. 1 character per pixels gives only half width of square.
30471
+ ascii += margin < 1 && y + 1 >= max ? blocksLastLineNoMargin[p] : blocks[p];
30472
+ }
30473
+ ascii += '\n';
30474
+ }
30475
+ if (size % 2 && margin > 0) {
30476
+ return ascii.substring(0, ascii.length - size - 1) + Array(size + 1).join('▀');
30477
+ }
30478
+ return ascii.substring(0, ascii.length - 1);
30479
+ };
30480
+ _this.createASCII = function (cellSize, margin) {
30481
+ cellSize = cellSize || 1;
30482
+ if (cellSize < 2) {
30483
+ return _createHalfASCII(margin);
30484
+ }
30485
+ cellSize -= 1;
30486
+ margin = typeof margin == 'undefined' ? cellSize * 2 : margin;
30487
+ const size = _this.getModuleCount() * cellSize + margin * 2;
30488
+ const min = margin;
30489
+ const max = size - margin;
30490
+ let y, x, r, p;
30491
+ const white = Array(cellSize + 1).join('██');
30492
+ const black = Array(cellSize + 1).join(' ');
30493
+ let ascii = '';
30494
+ let line = '';
30495
+ for (y = 0; y < size; y += 1) {
30496
+ r = Math.floor((y - min) / cellSize);
30497
+ line = '';
30498
+ for (x = 0; x < size; x += 1) {
30499
+ p = 1;
30500
+ if (min <= x && x < max && min <= y && y < max && _this.isDark(r, Math.floor((x - min) / cellSize))) {
30501
+ p = 0;
30502
+ }
30503
+
30504
+ // Output 2 characters per pixel, to create full square. 1 character per pixels gives only half width of square.
30505
+ line += p ? white : black;
30506
+ }
30507
+ for (r = 0; r < cellSize; r += 1) {
30508
+ ascii += line + '\n';
30509
+ }
30510
+ }
30511
+ return ascii.substring(0, ascii.length - 1);
30512
+ };
30513
+ _this.renderTo2dContext = function (context, cellSize) {
30514
+ cellSize = cellSize || 2;
30515
+ const length = _this.getModuleCount();
30516
+ for (let row = 0; row < length; row++) {
30517
+ for (let col = 0; col < length; col++) {
30518
+ context.fillStyle = _this.isDark(row, col) ? 'black' : 'white';
30519
+ context.fillRect(col * cellSize, row * cellSize, cellSize, cellSize);
30520
+ }
30521
+ }
30522
+ };
30523
+ return _this;
30524
+ };
30525
+
30526
+ //---------------------------------------------------------------------
30527
+ // qrcode.stringToBytes
30528
+ //---------------------------------------------------------------------
30529
+
30530
+ qrcode.stringToBytes = function (s) {
30531
+ const bytes = [];
30532
+ for (let i = 0; i < s.length; i += 1) {
30533
+ const c = s.charCodeAt(i);
30534
+ bytes.push(c & 0xff);
30535
+ }
30536
+ return bytes;
30537
+ };
30538
+
30539
+ //---------------------------------------------------------------------
30540
+ // qrcode.createStringToBytes
30541
+ //---------------------------------------------------------------------
30542
+
30543
+ /**
30544
+ * @param unicodeData base64 string of byte array.
30545
+ * [16bit Unicode],[16bit Bytes], ...
30546
+ * @param numChars
30547
+ */
30548
+ qrcode.createStringToBytes = function (unicodeData, numChars) {
30549
+ // create conversion map.
30550
+
30551
+ const unicodeMap = function () {
30552
+ const bin = base64DecodeInputStream(unicodeData);
30553
+ const read = function () {
30554
+ const b = bin.read();
30555
+ if (b == -1) throw 'eof';
30556
+ return b;
30557
+ };
30558
+ let count = 0;
30559
+ const unicodeMap = {};
30560
+ while (true) {
30561
+ const b0 = bin.read();
30562
+ if (b0 == -1) break;
30563
+ const b1 = read();
30564
+ const b2 = read();
30565
+ const b3 = read();
30566
+ const k = String.fromCharCode(b0 << 8 | b1);
30567
+ const v = b2 << 8 | b3;
30568
+ unicodeMap[k] = v;
30569
+ count += 1;
30570
+ }
30571
+ if (count != numChars) {
30572
+ throw count + ' != ' + numChars;
30573
+ }
30574
+ return unicodeMap;
30575
+ }();
30576
+ const unknownChar = '?'.charCodeAt(0);
30577
+ return function (s) {
30578
+ const bytes = [];
30579
+ for (let i = 0; i < s.length; i += 1) {
30580
+ const c = s.charCodeAt(i);
30581
+ if (c < 128) {
30582
+ bytes.push(c);
30583
+ } else {
30584
+ const b = unicodeMap[s.charAt(i)];
30585
+ if (typeof b == 'number') {
30586
+ if ((b & 0xff) == b) {
30587
+ // 1byte
30588
+ bytes.push(b);
30589
+ } else {
30590
+ // 2bytes
30591
+ bytes.push(b >>> 8);
30592
+ bytes.push(b & 0xff);
30593
+ }
30594
+ } else {
30595
+ bytes.push(unknownChar);
30596
+ }
30597
+ }
30598
+ }
30599
+ return bytes;
30600
+ };
30601
+ };
30602
+
30603
+ //---------------------------------------------------------------------
30604
+ // QRMode
30605
+ //---------------------------------------------------------------------
30606
+
30607
+ const QRMode = {
30608
+ MODE_NUMBER: 1 << 0,
30609
+ MODE_ALPHA_NUM: 1 << 1,
30610
+ MODE_8BIT_BYTE: 1 << 2,
30611
+ MODE_KANJI: 1 << 3
30612
+ };
30613
+
30614
+ //---------------------------------------------------------------------
30615
+ // QRErrorCorrectionLevel
30616
+ //---------------------------------------------------------------------
30617
+
30618
+ const QRErrorCorrectionLevel = {
30619
+ L: 1,
30620
+ M: 0,
30621
+ Q: 3,
30622
+ H: 2
30623
+ };
30624
+
30625
+ //---------------------------------------------------------------------
30626
+ // QRMaskPattern
30627
+ //---------------------------------------------------------------------
30628
+
30629
+ const QRMaskPattern = {
30630
+ PATTERN000: 0,
30631
+ PATTERN001: 1,
30632
+ PATTERN010: 2,
30633
+ PATTERN011: 3,
30634
+ PATTERN100: 4,
30635
+ PATTERN101: 5,
30636
+ PATTERN110: 6,
30637
+ PATTERN111: 7
30638
+ };
30639
+
30640
+ //---------------------------------------------------------------------
30641
+ // QRUtil
30642
+ //---------------------------------------------------------------------
30643
+
30644
+ const QRUtil = function () {
30645
+ const PATTERN_POSITION_TABLE = [[], [6, 18], [6, 22], [6, 26], [6, 30], [6, 34], [6, 22, 38], [6, 24, 42], [6, 26, 46], [6, 28, 50], [6, 30, 54], [6, 32, 58], [6, 34, 62], [6, 26, 46, 66], [6, 26, 48, 70], [6, 26, 50, 74], [6, 30, 54, 78], [6, 30, 56, 82], [6, 30, 58, 86], [6, 34, 62, 90], [6, 28, 50, 72, 94], [6, 26, 50, 74, 98], [6, 30, 54, 78, 102], [6, 28, 54, 80, 106], [6, 32, 58, 84, 110], [6, 30, 58, 86, 114], [6, 34, 62, 90, 118], [6, 26, 50, 74, 98, 122], [6, 30, 54, 78, 102, 126], [6, 26, 52, 78, 104, 130], [6, 30, 56, 82, 108, 134], [6, 34, 60, 86, 112, 138], [6, 30, 58, 86, 114, 142], [6, 34, 62, 90, 118, 146], [6, 30, 54, 78, 102, 126, 150], [6, 24, 50, 76, 102, 128, 154], [6, 28, 54, 80, 106, 132, 158], [6, 32, 58, 84, 110, 136, 162], [6, 26, 54, 82, 110, 138, 166], [6, 30, 58, 86, 114, 142, 170]];
30646
+ const G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0;
30647
+ const G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0;
30648
+ const G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;
30649
+ const _this = {};
30650
+ const getBCHDigit = function (data) {
30651
+ let digit = 0;
30652
+ while (data != 0) {
30653
+ digit += 1;
30654
+ data >>>= 1;
30655
+ }
30656
+ return digit;
30657
+ };
30658
+ _this.getBCHTypeInfo = function (data) {
30659
+ let d = data << 10;
30660
+ while (getBCHDigit(d) - getBCHDigit(G15) >= 0) {
30661
+ d ^= G15 << getBCHDigit(d) - getBCHDigit(G15);
30662
+ }
30663
+ return (data << 10 | d) ^ G15_MASK;
30664
+ };
30665
+ _this.getBCHTypeNumber = function (data) {
30666
+ let d = data << 12;
30667
+ while (getBCHDigit(d) - getBCHDigit(G18) >= 0) {
30668
+ d ^= G18 << getBCHDigit(d) - getBCHDigit(G18);
30669
+ }
30670
+ return data << 12 | d;
30671
+ };
30672
+ _this.getPatternPosition = function (typeNumber) {
30673
+ return PATTERN_POSITION_TABLE[typeNumber - 1];
30674
+ };
30675
+ _this.getMaskFunction = function (maskPattern) {
30676
+ switch (maskPattern) {
30677
+ case QRMaskPattern.PATTERN000:
30678
+ return function (i, j) {
30679
+ return (i + j) % 2 == 0;
30680
+ };
30681
+ case QRMaskPattern.PATTERN001:
30682
+ return function (i, j) {
30683
+ return i % 2 == 0;
30684
+ };
30685
+ case QRMaskPattern.PATTERN010:
30686
+ return function (i, j) {
30687
+ return j % 3 == 0;
30688
+ };
30689
+ case QRMaskPattern.PATTERN011:
30690
+ return function (i, j) {
30691
+ return (i + j) % 3 == 0;
30692
+ };
30693
+ case QRMaskPattern.PATTERN100:
30694
+ return function (i, j) {
30695
+ return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0;
30696
+ };
30697
+ case QRMaskPattern.PATTERN101:
30698
+ return function (i, j) {
30699
+ return i * j % 2 + i * j % 3 == 0;
30700
+ };
30701
+ case QRMaskPattern.PATTERN110:
30702
+ return function (i, j) {
30703
+ return (i * j % 2 + i * j % 3) % 2 == 0;
30704
+ };
30705
+ case QRMaskPattern.PATTERN111:
30706
+ return function (i, j) {
30707
+ return (i * j % 3 + (i + j) % 2) % 2 == 0;
30708
+ };
30709
+ default:
30710
+ throw 'bad maskPattern:' + maskPattern;
30711
+ }
30712
+ };
30713
+ _this.getErrorCorrectPolynomial = function (errorCorrectLength) {
30714
+ let a = qrPolynomial([1], 0);
30715
+ for (let i = 0; i < errorCorrectLength; i += 1) {
30716
+ a = a.multiply(qrPolynomial([1, QRMath.gexp(i)], 0));
30717
+ }
30718
+ return a;
30719
+ };
30720
+ _this.getLengthInBits = function (mode, type) {
30721
+ if (1 <= type && type < 10) {
30722
+ // 1 - 9
30723
+
30724
+ switch (mode) {
30725
+ case QRMode.MODE_NUMBER:
30726
+ return 10;
30727
+ case QRMode.MODE_ALPHA_NUM:
30728
+ return 9;
30729
+ case QRMode.MODE_8BIT_BYTE:
30730
+ return 8;
30731
+ case QRMode.MODE_KANJI:
30732
+ return 8;
30733
+ default:
30734
+ throw 'mode:' + mode;
30735
+ }
30736
+ } else if (type < 27) {
30737
+ // 10 - 26
30738
+
30739
+ switch (mode) {
30740
+ case QRMode.MODE_NUMBER:
30741
+ return 12;
30742
+ case QRMode.MODE_ALPHA_NUM:
30743
+ return 11;
30744
+ case QRMode.MODE_8BIT_BYTE:
30745
+ return 16;
30746
+ case QRMode.MODE_KANJI:
30747
+ return 10;
30748
+ default:
30749
+ throw 'mode:' + mode;
30750
+ }
30751
+ } else if (type < 41) {
30752
+ // 27 - 40
30753
+
30754
+ switch (mode) {
30755
+ case QRMode.MODE_NUMBER:
30756
+ return 14;
30757
+ case QRMode.MODE_ALPHA_NUM:
30758
+ return 13;
30759
+ case QRMode.MODE_8BIT_BYTE:
30760
+ return 16;
30761
+ case QRMode.MODE_KANJI:
30762
+ return 12;
30763
+ default:
30764
+ throw 'mode:' + mode;
30765
+ }
30766
+ } else {
30767
+ throw 'type:' + type;
30768
+ }
30769
+ };
30770
+ _this.getLostPoint = function (qrcode) {
30771
+ const moduleCount = qrcode.getModuleCount();
30772
+ let lostPoint = 0;
30773
+
30774
+ // LEVEL1
30775
+
30776
+ for (let row = 0; row < moduleCount; row += 1) {
30777
+ for (let col = 0; col < moduleCount; col += 1) {
30778
+ let sameCount = 0;
30779
+ const dark = qrcode.isDark(row, col);
30780
+ for (let r = -1; r <= 1; r += 1) {
30781
+ if (row + r < 0 || moduleCount <= row + r) {
30782
+ continue;
30783
+ }
30784
+ for (let c = -1; c <= 1; c += 1) {
30785
+ if (col + c < 0 || moduleCount <= col + c) {
30786
+ continue;
30787
+ }
30788
+ if (r == 0 && c == 0) {
30789
+ continue;
30790
+ }
30791
+ if (dark == qrcode.isDark(row + r, col + c)) {
30792
+ sameCount += 1;
30793
+ }
30794
+ }
30795
+ }
30796
+ if (sameCount > 5) {
30797
+ lostPoint += 3 + sameCount - 5;
30798
+ }
30799
+ }
30800
+ }
30801
+
30802
+ // LEVEL2
30803
+
30804
+ for (let row = 0; row < moduleCount - 1; row += 1) {
30805
+ for (let col = 0; col < moduleCount - 1; col += 1) {
30806
+ let count = 0;
30807
+ if (qrcode.isDark(row, col)) count += 1;
30808
+ if (qrcode.isDark(row + 1, col)) count += 1;
30809
+ if (qrcode.isDark(row, col + 1)) count += 1;
30810
+ if (qrcode.isDark(row + 1, col + 1)) count += 1;
30811
+ if (count == 0 || count == 4) {
30812
+ lostPoint += 3;
30813
+ }
30814
+ }
30815
+ }
30816
+
30817
+ // LEVEL3
30818
+
30819
+ for (let row = 0; row < moduleCount; row += 1) {
30820
+ for (let col = 0; col < moduleCount - 6; col += 1) {
30821
+ if (qrcode.isDark(row, col) && !qrcode.isDark(row, col + 1) && qrcode.isDark(row, col + 2) && qrcode.isDark(row, col + 3) && qrcode.isDark(row, col + 4) && !qrcode.isDark(row, col + 5) && qrcode.isDark(row, col + 6)) {
30822
+ lostPoint += 40;
30823
+ }
30824
+ }
30825
+ }
30826
+ for (let col = 0; col < moduleCount; col += 1) {
30827
+ for (let row = 0; row < moduleCount - 6; row += 1) {
30828
+ if (qrcode.isDark(row, col) && !qrcode.isDark(row + 1, col) && qrcode.isDark(row + 2, col) && qrcode.isDark(row + 3, col) && qrcode.isDark(row + 4, col) && !qrcode.isDark(row + 5, col) && qrcode.isDark(row + 6, col)) {
30829
+ lostPoint += 40;
30830
+ }
30831
+ }
30832
+ }
30833
+
30834
+ // LEVEL4
30835
+
30836
+ let darkCount = 0;
30837
+ for (let col = 0; col < moduleCount; col += 1) {
30838
+ for (let row = 0; row < moduleCount; row += 1) {
30839
+ if (qrcode.isDark(row, col)) {
30840
+ darkCount += 1;
30841
+ }
30842
+ }
30843
+ }
30844
+ const ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
30845
+ lostPoint += ratio * 10;
30846
+ return lostPoint;
30847
+ };
30848
+ return _this;
30849
+ }();
30850
+
30851
+ //---------------------------------------------------------------------
30852
+ // QRMath
30853
+ //---------------------------------------------------------------------
30854
+
30855
+ const QRMath = function () {
30856
+ const EXP_TABLE = new Array(256);
30857
+ const LOG_TABLE = new Array(256);
30858
+
30859
+ // initialize tables
30860
+ for (let i = 0; i < 8; i += 1) {
30861
+ EXP_TABLE[i] = 1 << i;
30862
+ }
30863
+ for (let i = 8; i < 256; i += 1) {
30864
+ EXP_TABLE[i] = EXP_TABLE[i - 4] ^ EXP_TABLE[i - 5] ^ EXP_TABLE[i - 6] ^ EXP_TABLE[i - 8];
30865
+ }
30866
+ for (let i = 0; i < 255; i += 1) {
30867
+ LOG_TABLE[EXP_TABLE[i]] = i;
30868
+ }
30869
+ const _this = {};
30870
+ _this.glog = function (n) {
30871
+ if (n < 1) {
30872
+ throw 'glog(' + n + ')';
30873
+ }
30874
+ return LOG_TABLE[n];
30875
+ };
30876
+ _this.gexp = function (n) {
30877
+ while (n < 0) {
30878
+ n += 255;
30879
+ }
30880
+ while (n >= 256) {
30881
+ n -= 255;
30882
+ }
30883
+ return EXP_TABLE[n];
30884
+ };
30885
+ return _this;
30886
+ }();
30887
+
30888
+ //---------------------------------------------------------------------
30889
+ // qrPolynomial
30890
+ //---------------------------------------------------------------------
30891
+
30892
+ const qrPolynomial = function (num, shift) {
30893
+ if (typeof num.length == 'undefined') {
30894
+ throw num.length + '/' + shift;
30895
+ }
30896
+ const _num = function () {
30897
+ let offset = 0;
30898
+ while (offset < num.length && num[offset] == 0) {
30899
+ offset += 1;
30900
+ }
30901
+ const _num = new Array(num.length - offset + shift);
30902
+ for (let i = 0; i < num.length - offset; i += 1) {
30903
+ _num[i] = num[i + offset];
30904
+ }
30905
+ return _num;
30906
+ }();
30907
+ const _this = {};
30908
+ _this.getAt = function (index) {
30909
+ return _num[index];
30910
+ };
30911
+ _this.getLength = function () {
30912
+ return _num.length;
30913
+ };
30914
+ _this.multiply = function (e) {
30915
+ const num = new Array(_this.getLength() + e.getLength() - 1);
30916
+ for (let i = 0; i < _this.getLength(); i += 1) {
30917
+ for (let j = 0; j < e.getLength(); j += 1) {
30918
+ num[i + j] ^= QRMath.gexp(QRMath.glog(_this.getAt(i)) + QRMath.glog(e.getAt(j)));
30919
+ }
30920
+ }
30921
+ return qrPolynomial(num, 0);
30922
+ };
30923
+ _this.mod = function (e) {
30924
+ if (_this.getLength() - e.getLength() < 0) {
30925
+ return _this;
30926
+ }
30927
+ const ratio = QRMath.glog(_this.getAt(0)) - QRMath.glog(e.getAt(0));
30928
+ const num = new Array(_this.getLength());
30929
+ for (let i = 0; i < _this.getLength(); i += 1) {
30930
+ num[i] = _this.getAt(i);
30931
+ }
30932
+ for (let i = 0; i < e.getLength(); i += 1) {
30933
+ num[i] ^= QRMath.gexp(QRMath.glog(e.getAt(i)) + ratio);
30934
+ }
30935
+
30936
+ // recursive call
30937
+ return qrPolynomial(num, 0).mod(e);
30938
+ };
30939
+ return _this;
30940
+ };
30941
+
30942
+ //---------------------------------------------------------------------
30943
+ // QRRSBlock
30944
+ //---------------------------------------------------------------------
30945
+
30946
+ const QRRSBlock = function () {
30947
+ const RS_BLOCK_TABLE = [
30948
+ // L
30949
+ // M
30950
+ // Q
30951
+ // H
30952
+
30953
+ // 1
30954
+ [1, 26, 19], [1, 26, 16], [1, 26, 13], [1, 26, 9],
30955
+ // 2
30956
+ [1, 44, 34], [1, 44, 28], [1, 44, 22], [1, 44, 16],
30957
+ // 3
30958
+ [1, 70, 55], [1, 70, 44], [2, 35, 17], [2, 35, 13],
30959
+ // 4
30960
+ [1, 100, 80], [2, 50, 32], [2, 50, 24], [4, 25, 9],
30961
+ // 5
30962
+ [1, 134, 108], [2, 67, 43], [2, 33, 15, 2, 34, 16], [2, 33, 11, 2, 34, 12],
30963
+ // 6
30964
+ [2, 86, 68], [4, 43, 27], [4, 43, 19], [4, 43, 15],
30965
+ // 7
30966
+ [2, 98, 78], [4, 49, 31], [2, 32, 14, 4, 33, 15], [4, 39, 13, 1, 40, 14],
30967
+ // 8
30968
+ [2, 121, 97], [2, 60, 38, 2, 61, 39], [4, 40, 18, 2, 41, 19], [4, 40, 14, 2, 41, 15],
30969
+ // 9
30970
+ [2, 146, 116], [3, 58, 36, 2, 59, 37], [4, 36, 16, 4, 37, 17], [4, 36, 12, 4, 37, 13],
30971
+ // 10
30972
+ [2, 86, 68, 2, 87, 69], [4, 69, 43, 1, 70, 44], [6, 43, 19, 2, 44, 20], [6, 43, 15, 2, 44, 16],
30973
+ // 11
30974
+ [4, 101, 81], [1, 80, 50, 4, 81, 51], [4, 50, 22, 4, 51, 23], [3, 36, 12, 8, 37, 13],
30975
+ // 12
30976
+ [2, 116, 92, 2, 117, 93], [6, 58, 36, 2, 59, 37], [4, 46, 20, 6, 47, 21], [7, 42, 14, 4, 43, 15],
30977
+ // 13
30978
+ [4, 133, 107], [8, 59, 37, 1, 60, 38], [8, 44, 20, 4, 45, 21], [12, 33, 11, 4, 34, 12],
30979
+ // 14
30980
+ [3, 145, 115, 1, 146, 116], [4, 64, 40, 5, 65, 41], [11, 36, 16, 5, 37, 17], [11, 36, 12, 5, 37, 13],
30981
+ // 15
30982
+ [5, 109, 87, 1, 110, 88], [5, 65, 41, 5, 66, 42], [5, 54, 24, 7, 55, 25], [11, 36, 12, 7, 37, 13],
30983
+ // 16
30984
+ [5, 122, 98, 1, 123, 99], [7, 73, 45, 3, 74, 46], [15, 43, 19, 2, 44, 20], [3, 45, 15, 13, 46, 16],
30985
+ // 17
30986
+ [1, 135, 107, 5, 136, 108], [10, 74, 46, 1, 75, 47], [1, 50, 22, 15, 51, 23], [2, 42, 14, 17, 43, 15],
30987
+ // 18
30988
+ [5, 150, 120, 1, 151, 121], [9, 69, 43, 4, 70, 44], [17, 50, 22, 1, 51, 23], [2, 42, 14, 19, 43, 15],
30989
+ // 19
30990
+ [3, 141, 113, 4, 142, 114], [3, 70, 44, 11, 71, 45], [17, 47, 21, 4, 48, 22], [9, 39, 13, 16, 40, 14],
30991
+ // 20
30992
+ [3, 135, 107, 5, 136, 108], [3, 67, 41, 13, 68, 42], [15, 54, 24, 5, 55, 25], [15, 43, 15, 10, 44, 16],
30993
+ // 21
30994
+ [4, 144, 116, 4, 145, 117], [17, 68, 42], [17, 50, 22, 6, 51, 23], [19, 46, 16, 6, 47, 17],
30995
+ // 22
30996
+ [2, 139, 111, 7, 140, 112], [17, 74, 46], [7, 54, 24, 16, 55, 25], [34, 37, 13],
30997
+ // 23
30998
+ [4, 151, 121, 5, 152, 122], [4, 75, 47, 14, 76, 48], [11, 54, 24, 14, 55, 25], [16, 45, 15, 14, 46, 16],
30999
+ // 24
31000
+ [6, 147, 117, 4, 148, 118], [6, 73, 45, 14, 74, 46], [11, 54, 24, 16, 55, 25], [30, 46, 16, 2, 47, 17],
31001
+ // 25
31002
+ [8, 132, 106, 4, 133, 107], [8, 75, 47, 13, 76, 48], [7, 54, 24, 22, 55, 25], [22, 45, 15, 13, 46, 16],
31003
+ // 26
31004
+ [10, 142, 114, 2, 143, 115], [19, 74, 46, 4, 75, 47], [28, 50, 22, 6, 51, 23], [33, 46, 16, 4, 47, 17],
31005
+ // 27
31006
+ [8, 152, 122, 4, 153, 123], [22, 73, 45, 3, 74, 46], [8, 53, 23, 26, 54, 24], [12, 45, 15, 28, 46, 16],
31007
+ // 28
31008
+ [3, 147, 117, 10, 148, 118], [3, 73, 45, 23, 74, 46], [4, 54, 24, 31, 55, 25], [11, 45, 15, 31, 46, 16],
31009
+ // 29
31010
+ [7, 146, 116, 7, 147, 117], [21, 73, 45, 7, 74, 46], [1, 53, 23, 37, 54, 24], [19, 45, 15, 26, 46, 16],
31011
+ // 30
31012
+ [5, 145, 115, 10, 146, 116], [19, 75, 47, 10, 76, 48], [15, 54, 24, 25, 55, 25], [23, 45, 15, 25, 46, 16],
31013
+ // 31
31014
+ [13, 145, 115, 3, 146, 116], [2, 74, 46, 29, 75, 47], [42, 54, 24, 1, 55, 25], [23, 45, 15, 28, 46, 16],
31015
+ // 32
31016
+ [17, 145, 115], [10, 74, 46, 23, 75, 47], [10, 54, 24, 35, 55, 25], [19, 45, 15, 35, 46, 16],
31017
+ // 33
31018
+ [17, 145, 115, 1, 146, 116], [14, 74, 46, 21, 75, 47], [29, 54, 24, 19, 55, 25], [11, 45, 15, 46, 46, 16],
31019
+ // 34
31020
+ [13, 145, 115, 6, 146, 116], [14, 74, 46, 23, 75, 47], [44, 54, 24, 7, 55, 25], [59, 46, 16, 1, 47, 17],
31021
+ // 35
31022
+ [12, 151, 121, 7, 152, 122], [12, 75, 47, 26, 76, 48], [39, 54, 24, 14, 55, 25], [22, 45, 15, 41, 46, 16],
31023
+ // 36
31024
+ [6, 151, 121, 14, 152, 122], [6, 75, 47, 34, 76, 48], [46, 54, 24, 10, 55, 25], [2, 45, 15, 64, 46, 16],
31025
+ // 37
31026
+ [17, 152, 122, 4, 153, 123], [29, 74, 46, 14, 75, 47], [49, 54, 24, 10, 55, 25], [24, 45, 15, 46, 46, 16],
31027
+ // 38
31028
+ [4, 152, 122, 18, 153, 123], [13, 74, 46, 32, 75, 47], [48, 54, 24, 14, 55, 25], [42, 45, 15, 32, 46, 16],
31029
+ // 39
31030
+ [20, 147, 117, 4, 148, 118], [40, 75, 47, 7, 76, 48], [43, 54, 24, 22, 55, 25], [10, 45, 15, 67, 46, 16],
31031
+ // 40
31032
+ [19, 148, 118, 6, 149, 119], [18, 75, 47, 31, 76, 48], [34, 54, 24, 34, 55, 25], [20, 45, 15, 61, 46, 16]];
31033
+ const qrRSBlock = function (totalCount, dataCount) {
31034
+ const _this = {};
31035
+ _this.totalCount = totalCount;
31036
+ _this.dataCount = dataCount;
31037
+ return _this;
31038
+ };
31039
+ const _this = {};
31040
+ const getRsBlockTable = function (typeNumber, errorCorrectionLevel) {
31041
+ switch (errorCorrectionLevel) {
31042
+ case QRErrorCorrectionLevel.L:
31043
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];
31044
+ case QRErrorCorrectionLevel.M:
31045
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
31046
+ case QRErrorCorrectionLevel.Q:
31047
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
31048
+ case QRErrorCorrectionLevel.H:
31049
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
31050
+ default:
31051
+ return undefined;
31052
+ }
31053
+ };
31054
+ _this.getRSBlocks = function (typeNumber, errorCorrectionLevel) {
31055
+ const rsBlock = getRsBlockTable(typeNumber, errorCorrectionLevel);
31056
+ if (typeof rsBlock == 'undefined') {
31057
+ throw 'bad rs block @ typeNumber:' + typeNumber + '/errorCorrectionLevel:' + errorCorrectionLevel;
31058
+ }
31059
+ const length = rsBlock.length / 3;
31060
+ const list = [];
31061
+ for (let i = 0; i < length; i += 1) {
31062
+ const count = rsBlock[i * 3 + 0];
31063
+ const totalCount = rsBlock[i * 3 + 1];
31064
+ const dataCount = rsBlock[i * 3 + 2];
31065
+ for (let j = 0; j < count; j += 1) {
31066
+ list.push(qrRSBlock(totalCount, dataCount));
31067
+ }
31068
+ }
31069
+ return list;
31070
+ };
31071
+ return _this;
31072
+ }();
31073
+
31074
+ //---------------------------------------------------------------------
31075
+ // qrBitBuffer
31076
+ //---------------------------------------------------------------------
31077
+
31078
+ const qrBitBuffer = function () {
31079
+ const _buffer = [];
31080
+ let _length = 0;
31081
+ const _this = {};
31082
+ _this.getBuffer = function () {
31083
+ return _buffer;
31084
+ };
31085
+ _this.getAt = function (index) {
31086
+ const bufIndex = Math.floor(index / 8);
31087
+ return (_buffer[bufIndex] >>> 7 - index % 8 & 1) == 1;
31088
+ };
31089
+ _this.put = function (num, length) {
31090
+ for (let i = 0; i < length; i += 1) {
31091
+ _this.putBit((num >>> length - i - 1 & 1) == 1);
31092
+ }
31093
+ };
31094
+ _this.getLengthInBits = function () {
31095
+ return _length;
31096
+ };
31097
+ _this.putBit = function (bit) {
31098
+ const bufIndex = Math.floor(_length / 8);
31099
+ if (_buffer.length <= bufIndex) {
31100
+ _buffer.push(0);
31101
+ }
31102
+ if (bit) {
31103
+ _buffer[bufIndex] |= 0x80 >>> _length % 8;
31104
+ }
31105
+ _length += 1;
31106
+ };
31107
+ return _this;
31108
+ };
31109
+
31110
+ //---------------------------------------------------------------------
31111
+ // qrNumber
31112
+ //---------------------------------------------------------------------
31113
+
31114
+ const qrNumber = function (data) {
31115
+ const _mode = QRMode.MODE_NUMBER;
31116
+ const _data = data;
31117
+ const _this = {};
31118
+ _this.getMode = function () {
31119
+ return _mode;
31120
+ };
31121
+ _this.getLength = function (buffer) {
31122
+ return _data.length;
31123
+ };
31124
+ _this.write = function (buffer) {
31125
+ const data = _data;
31126
+ let i = 0;
31127
+ while (i + 2 < data.length) {
31128
+ buffer.put(strToNum(data.substring(i, i + 3)), 10);
31129
+ i += 3;
31130
+ }
31131
+ if (i < data.length) {
31132
+ if (data.length - i == 1) {
31133
+ buffer.put(strToNum(data.substring(i, i + 1)), 4);
31134
+ } else if (data.length - i == 2) {
31135
+ buffer.put(strToNum(data.substring(i, i + 2)), 7);
31136
+ }
31137
+ }
31138
+ };
31139
+ const strToNum = function (s) {
31140
+ let num = 0;
31141
+ for (let i = 0; i < s.length; i += 1) {
31142
+ num = num * 10 + chatToNum(s.charAt(i));
31143
+ }
31144
+ return num;
31145
+ };
31146
+ const chatToNum = function (c) {
31147
+ if ('0' <= c && c <= '9') {
31148
+ return c.charCodeAt(0) - '0'.charCodeAt(0);
31149
+ }
31150
+ throw 'illegal char :' + c;
31151
+ };
31152
+ return _this;
31153
+ };
31154
+
31155
+ //---------------------------------------------------------------------
31156
+ // qrAlphaNum
31157
+ //---------------------------------------------------------------------
31158
+
31159
+ const qrAlphaNum = function (data) {
31160
+ const _mode = QRMode.MODE_ALPHA_NUM;
31161
+ const _data = data;
31162
+ const _this = {};
31163
+ _this.getMode = function () {
31164
+ return _mode;
31165
+ };
31166
+ _this.getLength = function (buffer) {
31167
+ return _data.length;
31168
+ };
31169
+ _this.write = function (buffer) {
31170
+ const s = _data;
31171
+ let i = 0;
31172
+ while (i + 1 < s.length) {
31173
+ buffer.put(getCode(s.charAt(i)) * 45 + getCode(s.charAt(i + 1)), 11);
31174
+ i += 2;
31175
+ }
31176
+ if (i < s.length) {
31177
+ buffer.put(getCode(s.charAt(i)), 6);
31178
+ }
31179
+ };
31180
+ const getCode = function (c) {
31181
+ if ('0' <= c && c <= '9') {
31182
+ return c.charCodeAt(0) - '0'.charCodeAt(0);
31183
+ } else if ('A' <= c && c <= 'Z') {
31184
+ return c.charCodeAt(0) - 'A'.charCodeAt(0) + 10;
31185
+ } else {
31186
+ switch (c) {
31187
+ case '\u0020':
31188
+ return 36;
31189
+ case '$':
31190
+ return 37;
31191
+ case '%':
31192
+ return 38;
31193
+ case '*':
31194
+ return 39;
31195
+ case '+':
31196
+ return 40;
31197
+ case '-':
31198
+ return 41;
31199
+ case '.':
31200
+ return 42;
31201
+ case '/':
31202
+ return 43;
31203
+ case ':':
31204
+ return 44;
31205
+ default:
31206
+ throw 'illegal char :' + c;
31207
+ }
31208
+ }
31209
+ };
31210
+ return _this;
31211
+ };
31212
+
31213
+ //---------------------------------------------------------------------
31214
+ // qr8BitByte
31215
+ //---------------------------------------------------------------------
31216
+
31217
+ const qr8BitByte = function (data) {
31218
+ const _mode = QRMode.MODE_8BIT_BYTE;
31219
+ const _bytes = qrcode.stringToBytes(data);
31220
+ const _this = {};
31221
+ _this.getMode = function () {
31222
+ return _mode;
31223
+ };
31224
+ _this.getLength = function (buffer) {
31225
+ return _bytes.length;
31226
+ };
31227
+ _this.write = function (buffer) {
31228
+ for (let i = 0; i < _bytes.length; i += 1) {
31229
+ buffer.put(_bytes[i], 8);
31230
+ }
31231
+ };
31232
+ return _this;
31233
+ };
31234
+
31235
+ //---------------------------------------------------------------------
31236
+ // qrKanji
31237
+ //---------------------------------------------------------------------
31238
+
31239
+ const qrKanji = function (data) {
31240
+ const _mode = QRMode.MODE_KANJI;
31241
+ const stringToBytes = qrcode.stringToBytes;
31242
+ !function (c, code) {
31243
+ // self test for sjis support.
31244
+ const test = stringToBytes(c);
31245
+ if (test.length != 2 || (test[0] << 8 | test[1]) != code) {
31246
+ throw 'sjis not supported.';
31247
+ }
31248
+ }('\u53cb', 0x9746);
31249
+ const _bytes = stringToBytes(data);
31250
+ const _this = {};
31251
+ _this.getMode = function () {
31252
+ return _mode;
31253
+ };
31254
+ _this.getLength = function (buffer) {
31255
+ return ~~(_bytes.length / 2);
31256
+ };
31257
+ _this.write = function (buffer) {
31258
+ const data = _bytes;
31259
+ let i = 0;
31260
+ while (i + 1 < data.length) {
31261
+ let c = (0xff & data[i]) << 8 | 0xff & data[i + 1];
31262
+ if (0x8140 <= c && c <= 0x9FFC) {
31263
+ c -= 0x8140;
31264
+ } else if (0xE040 <= c && c <= 0xEBBF) {
31265
+ c -= 0xC140;
31266
+ } else {
31267
+ throw 'illegal char at ' + (i + 1) + '/' + c;
31268
+ }
31269
+ c = (c >>> 8 & 0xff) * 0xC0 + (c & 0xff);
31270
+ buffer.put(c, 13);
31271
+ i += 2;
31272
+ }
31273
+ if (i < data.length) {
31274
+ throw 'illegal char at ' + (i + 1);
31275
+ }
31276
+ };
31277
+ return _this;
31278
+ };
31279
+
31280
+ //=====================================================================
31281
+ // GIF Support etc.
31282
+ //
31283
+
31284
+ //---------------------------------------------------------------------
31285
+ // byteArrayOutputStream
31286
+ //---------------------------------------------------------------------
31287
+
31288
+ const byteArrayOutputStream = function () {
31289
+ const _bytes = [];
31290
+ const _this = {};
31291
+ _this.writeByte = function (b) {
31292
+ _bytes.push(b & 0xff);
31293
+ };
31294
+ _this.writeShort = function (i) {
31295
+ _this.writeByte(i);
31296
+ _this.writeByte(i >>> 8);
31297
+ };
31298
+ _this.writeBytes = function (b, off, len) {
31299
+ off = off || 0;
31300
+ len = len || b.length;
31301
+ for (let i = 0; i < len; i += 1) {
31302
+ _this.writeByte(b[i + off]);
31303
+ }
31304
+ };
31305
+ _this.writeString = function (s) {
31306
+ for (let i = 0; i < s.length; i += 1) {
31307
+ _this.writeByte(s.charCodeAt(i));
31308
+ }
31309
+ };
31310
+ _this.toByteArray = function () {
31311
+ return _bytes;
31312
+ };
31313
+ _this.toString = function () {
31314
+ let s = '';
31315
+ s += '[';
31316
+ for (let i = 0; i < _bytes.length; i += 1) {
31317
+ if (i > 0) {
31318
+ s += ',';
31319
+ }
31320
+ s += _bytes[i];
31321
+ }
31322
+ s += ']';
31323
+ return s;
31324
+ };
31325
+ return _this;
31326
+ };
31327
+
31328
+ //---------------------------------------------------------------------
31329
+ // base64EncodeOutputStream
31330
+ //---------------------------------------------------------------------
31331
+
31332
+ const base64EncodeOutputStream = function () {
31333
+ let _buffer = 0;
31334
+ let _buflen = 0;
31335
+ let _length = 0;
31336
+ let _base64 = '';
31337
+ const _this = {};
31338
+ const writeEncoded = function (b) {
31339
+ _base64 += String.fromCharCode(encode(b & 0x3f));
31340
+ };
31341
+ const encode = function (n) {
31342
+ if (n < 0) {
31343
+ throw 'n:' + n;
31344
+ } else if (n < 26) {
31345
+ return 0x41 + n;
31346
+ } else if (n < 52) {
31347
+ return 0x61 + (n - 26);
31348
+ } else if (n < 62) {
31349
+ return 0x30 + (n - 52);
31350
+ } else if (n == 62) {
31351
+ return 0x2b;
31352
+ } else if (n == 63) {
31353
+ return 0x2f;
31354
+ } else {
31355
+ throw 'n:' + n;
31356
+ }
31357
+ };
31358
+ _this.writeByte = function (n) {
31359
+ _buffer = _buffer << 8 | n & 0xff;
31360
+ _buflen += 8;
31361
+ _length += 1;
31362
+ while (_buflen >= 6) {
31363
+ writeEncoded(_buffer >>> _buflen - 6);
31364
+ _buflen -= 6;
31365
+ }
31366
+ };
31367
+ _this.flush = function () {
31368
+ if (_buflen > 0) {
31369
+ writeEncoded(_buffer << 6 - _buflen);
31370
+ _buffer = 0;
31371
+ _buflen = 0;
31372
+ }
31373
+ if (_length % 3 != 0) {
31374
+ // padding
31375
+ const padlen = 3 - _length % 3;
31376
+ for (let i = 0; i < padlen; i += 1) {
31377
+ _base64 += '=';
31378
+ }
31379
+ }
31380
+ };
31381
+ _this.toString = function () {
31382
+ return _base64;
31383
+ };
31384
+ return _this;
31385
+ };
31386
+
31387
+ //---------------------------------------------------------------------
31388
+ // base64DecodeInputStream
31389
+ //---------------------------------------------------------------------
31390
+
31391
+ const base64DecodeInputStream = function (str) {
31392
+ const _str = str;
31393
+ let _pos = 0;
31394
+ let _buffer = 0;
31395
+ let _buflen = 0;
31396
+ const _this = {};
31397
+ _this.read = function () {
31398
+ while (_buflen < 8) {
31399
+ if (_pos >= _str.length) {
31400
+ if (_buflen == 0) {
31401
+ return -1;
31402
+ }
31403
+ throw 'unexpected end of file./' + _buflen;
31404
+ }
31405
+ const c = _str.charAt(_pos);
31406
+ _pos += 1;
31407
+ if (c == '=') {
31408
+ _buflen = 0;
31409
+ return -1;
31410
+ } else if (c.match(/^\s$/)) {
31411
+ // ignore if whitespace.
31412
+ continue;
31413
+ }
31414
+ _buffer = _buffer << 6 | decode(c.charCodeAt(0));
31415
+ _buflen += 6;
31416
+ }
31417
+ const n = _buffer >>> _buflen - 8 & 0xff;
31418
+ _buflen -= 8;
31419
+ return n;
31420
+ };
31421
+ const decode = function (c) {
31422
+ if (0x41 <= c && c <= 0x5a) {
31423
+ return c - 0x41;
31424
+ } else if (0x61 <= c && c <= 0x7a) {
31425
+ return c - 0x61 + 26;
31426
+ } else if (0x30 <= c && c <= 0x39) {
31427
+ return c - 0x30 + 52;
31428
+ } else if (c == 0x2b) {
31429
+ return 62;
31430
+ } else if (c == 0x2f) {
31431
+ return 63;
31432
+ } else {
31433
+ throw 'c:' + c;
31434
+ }
31435
+ };
31436
+ return _this;
31437
+ };
31438
+
31439
+ //---------------------------------------------------------------------
31440
+ // gifImage (B/W)
31441
+ //---------------------------------------------------------------------
31442
+
31443
+ const gifImage = function (width, height) {
31444
+ const _width = width;
31445
+ const _height = height;
31446
+ const _data = new Array(width * height);
31447
+ const _this = {};
31448
+ _this.setPixel = function (x, y, pixel) {
31449
+ _data[y * _width + x] = pixel;
31450
+ };
31451
+ _this.write = function (out) {
31452
+ //---------------------------------
31453
+ // GIF Signature
31454
+
31455
+ out.writeString('GIF87a');
31456
+
31457
+ //---------------------------------
31458
+ // Screen Descriptor
31459
+
31460
+ out.writeShort(_width);
31461
+ out.writeShort(_height);
31462
+ out.writeByte(0x80); // 2bit
31463
+ out.writeByte(0);
31464
+ out.writeByte(0);
31465
+
31466
+ //---------------------------------
31467
+ // Global Color Map
31468
+
31469
+ // black
31470
+ out.writeByte(0x00);
31471
+ out.writeByte(0x00);
31472
+ out.writeByte(0x00);
31473
+
31474
+ // white
31475
+ out.writeByte(0xff);
31476
+ out.writeByte(0xff);
31477
+ out.writeByte(0xff);
31478
+
31479
+ //---------------------------------
31480
+ // Image Descriptor
31481
+
31482
+ out.writeString(',');
31483
+ out.writeShort(0);
31484
+ out.writeShort(0);
31485
+ out.writeShort(_width);
31486
+ out.writeShort(_height);
31487
+ out.writeByte(0);
31488
+
31489
+ //---------------------------------
31490
+ // Local Color Map
31491
+
31492
+ //---------------------------------
31493
+ // Raster Data
31494
+
31495
+ const lzwMinCodeSize = 2;
31496
+ const raster = getLZWRaster(lzwMinCodeSize);
31497
+ out.writeByte(lzwMinCodeSize);
31498
+ let offset = 0;
31499
+ while (raster.length - offset > 255) {
31500
+ out.writeByte(255);
31501
+ out.writeBytes(raster, offset, 255);
31502
+ offset += 255;
31503
+ }
31504
+ out.writeByte(raster.length - offset);
31505
+ out.writeBytes(raster, offset, raster.length - offset);
31506
+ out.writeByte(0x00);
31507
+
31508
+ //---------------------------------
31509
+ // GIF Terminator
31510
+ out.writeString(';');
31511
+ };
31512
+ const bitOutputStream = function (out) {
31513
+ const _out = out;
31514
+ let _bitLength = 0;
31515
+ let _bitBuffer = 0;
31516
+ const _this = {};
31517
+ _this.write = function (data, length) {
31518
+ if (data >>> length != 0) {
31519
+ throw 'length over';
31520
+ }
31521
+ while (_bitLength + length >= 8) {
31522
+ _out.writeByte(0xff & (data << _bitLength | _bitBuffer));
31523
+ length -= 8 - _bitLength;
31524
+ data >>>= 8 - _bitLength;
31525
+ _bitBuffer = 0;
31526
+ _bitLength = 0;
31527
+ }
31528
+ _bitBuffer = data << _bitLength | _bitBuffer;
31529
+ _bitLength = _bitLength + length;
31530
+ };
31531
+ _this.flush = function () {
31532
+ if (_bitLength > 0) {
31533
+ _out.writeByte(_bitBuffer);
31534
+ }
31535
+ };
31536
+ return _this;
31537
+ };
31538
+ const getLZWRaster = function (lzwMinCodeSize) {
31539
+ const clearCode = 1 << lzwMinCodeSize;
31540
+ const endCode = (1 << lzwMinCodeSize) + 1;
31541
+ let bitLength = lzwMinCodeSize + 1;
31542
+
31543
+ // Setup LZWTable
31544
+ const table = lzwTable();
31545
+ for (let i = 0; i < clearCode; i += 1) {
31546
+ table.add(String.fromCharCode(i));
31547
+ }
31548
+ table.add(String.fromCharCode(clearCode));
31549
+ table.add(String.fromCharCode(endCode));
31550
+ const byteOut = byteArrayOutputStream();
31551
+ const bitOut = bitOutputStream(byteOut);
31552
+
31553
+ // clear code
31554
+ bitOut.write(clearCode, bitLength);
31555
+ let dataIndex = 0;
31556
+ let s = String.fromCharCode(_data[dataIndex]);
31557
+ dataIndex += 1;
31558
+ while (dataIndex < _data.length) {
31559
+ const c = String.fromCharCode(_data[dataIndex]);
31560
+ dataIndex += 1;
31561
+ if (table.contains(s + c)) {
31562
+ s = s + c;
31563
+ } else {
31564
+ bitOut.write(table.indexOf(s), bitLength);
31565
+ if (table.size() < 0xfff) {
31566
+ if (table.size() == 1 << bitLength) {
31567
+ bitLength += 1;
31568
+ }
31569
+ table.add(s + c);
31570
+ }
31571
+ s = c;
31572
+ }
31573
+ }
31574
+ bitOut.write(table.indexOf(s), bitLength);
31575
+
31576
+ // end code
31577
+ bitOut.write(endCode, bitLength);
31578
+ bitOut.flush();
31579
+ return byteOut.toByteArray();
31580
+ };
31581
+ const lzwTable = function () {
31582
+ const _map = {};
31583
+ let _size = 0;
31584
+ const _this = {};
31585
+ _this.add = function (key) {
31586
+ if (_this.contains(key)) {
31587
+ throw 'dup key:' + key;
31588
+ }
31589
+ _map[key] = _size;
31590
+ _size += 1;
31591
+ };
31592
+ _this.size = function () {
31593
+ return _size;
31594
+ };
31595
+ _this.indexOf = function (key) {
31596
+ return _map[key];
31597
+ };
31598
+ _this.contains = function (key) {
31599
+ return typeof _map[key] != 'undefined';
31600
+ };
31601
+ return _this;
31602
+ };
31603
+ return _this;
31604
+ };
31605
+ const createDataURL = function (width, height, getPixel) {
31606
+ const gif = gifImage(width, height);
31607
+ for (let y = 0; y < height; y += 1) {
31608
+ for (let x = 0; x < width; x += 1) {
31609
+ gif.setPixel(x, y, getPixel(x, y));
31610
+ }
31611
+ }
31612
+ const b = byteArrayOutputStream();
31613
+ gif.write(b);
31614
+ const base64 = base64EncodeOutputStream();
31615
+ const bytes = b.toByteArray();
31616
+ for (let i = 0; i < bytes.length; i += 1) {
31617
+ base64.writeByte(bytes[i]);
31618
+ }
31619
+ base64.flush();
31620
+ return 'data:image/gif;base64,' + base64;
31621
+ };
31622
+ qrcode.stringToBytes;
31623
+
31624
+ /**
31625
+ * @license
31626
+ * Copyright 2025-2026 Open Home Foundation
31627
+ * SPDX-License-Identifier: Apache-2.0
31628
+ */
31629
+ function formatManualPairingCode(code) {
31630
+ const digits = code.replace(/\D/g, "");
31631
+ if (digits.length === 11) {
31632
+ return `${digits.slice(0, 4)}-${digits.slice(4, 7)}-${digits.slice(7, 11)}`;
31633
+ }
31634
+ return digits || code;
31635
+ }
31636
+ function renderPairingQrCodeDataUri(qrPayload, cellSize = 5, margin = 4) {
31637
+ const qr = qrcode(0, "M");
31638
+ qr.addData(qrPayload);
31639
+ qr.make();
31640
+ return `data:image/svg+xml,${encodeURIComponent(qr.createSvgTag(cellSize, margin))}`;
31641
+ }
31642
+
29938
31643
  /**
29939
31644
  * @license
29940
31645
  * Copyright 2025-2026 Open Home Foundation
@@ -30188,9 +31893,21 @@ let NodeDetails = class extends i$4 {
30188
31893
  }
30189
31894
  try {
30190
31895
  const shareCode = await this.client.openCommissioningWindow(this.node.node_id);
31896
+ const manualCode = formatManualPairingCode(shareCode.setup_manual_code);
31897
+ const qrDataUri = renderPairingQrCodeDataUri(shareCode.setup_qr_code);
30191
31898
  showAlertDialog({
30192
31899
  title: "Share device",
30193
- text: `Setup code: ${shareCode.setup_manual_code}`
31900
+ text: b`
31901
+ <div style="display:flex;flex-direction:column;align-items:center;gap:16px;">
31902
+ <img src=${qrDataUri} alt="Commissioning QR code" style="width:200px;height:200px;" />
31903
+ <div style="text-align:center;">
31904
+ <div style="font-size:0.8rem;color:var(--md-sys-color-on-surface-variant);">Setup code</div>
31905
+ <div style="font-size:1.4rem;font-family:monospace;letter-spacing:0.05em;">
31906
+ ${manualCode}
31907
+ </div>
31908
+ </div>
31909
+ </div>
31910
+ `
30194
31911
  });
30195
31912
  } catch (err) {
30196
31913
  showAlertDialog({
@@ -30530,7 +32247,7 @@ async function downgradeToOperate(client, nodeId, keys) {
30530
32247
  * SPDX-License-Identifier: Apache-2.0
30531
32248
  */
30532
32249
  const showNodeAclAddDialog = async node => {
30533
- await import('./node-acl-add-dialog-DMKY5qsl.js');
32250
+ await import('./node-acl-add-dialog-DJrFkAp9.js');
30534
32251
  const dialog = document.createElement("node-acl-add-dialog");
30535
32252
  dialog.node = node;
30536
32253
  document.querySelector("matter-dashboard-app")?.renderRoot.appendChild(dialog);
@@ -32825,7 +34542,7 @@ async function deleteBindingAtIndex(client, sourceNode, sourceEndpoint, index) {
32825
34542
  * SPDX-License-Identifier: Apache-2.0
32826
34543
  */
32827
34544
  const showNodeBindingDialog = async (node, endpoint) => {
32828
- await import('./node-binding-dialog-bephut8j.js');
34545
+ await import('./node-binding-dialog-CQt-LbiG.js');
32829
34546
  const dialog = document.createElement("node-binding-dialog");
32830
34547
  dialog.node = node;
32831
34548
  dialog.endpoint = endpoint;
@@ -35346,6 +37063,7 @@ let MatterClusterView = class extends i$4 {
35346
37063
  super.updated(changedProperties);
35347
37064
  if (changedProperties.has("cluster") || changedProperties.has("endpoint")) {
35348
37065
  this._refreshState = {};
37066
+ this._scrollCommandPanelIntoView();
35349
37067
  }
35350
37068
  const container = this.shadowRoot?.getElementById("cluster-commands-container");
35351
37069
  if (container && this.node && this.endpoint !== void 0 && this.cluster !== void 0) {
@@ -35357,6 +37075,16 @@ let MatterClusterView = class extends i$4 {
35357
37075
  }
35358
37076
  }
35359
37077
  }
37078
+ // Route change resets scroll to top; for clusters with a command panel land on the panel instead.
37079
+ _scrollCommandPanelIntoView() {
37080
+ requestAnimationFrame(() => {
37081
+ const container = this.shadowRoot?.getElementById("cluster-commands-container");
37082
+ container?.scrollIntoView({
37083
+ block: "start",
37084
+ behavior: "auto"
37085
+ });
37086
+ });
37087
+ }
35360
37088
  _goBack() {
35361
37089
  history.back();
35362
37090
  }
@@ -35926,6 +37654,29 @@ function getThreadRoleName(role) {
35926
37654
  return "Unknown";
35927
37655
  }
35928
37656
  }
37657
+ function getThreadRoleDescription(role) {
37658
+ switch (role) {
37659
+ case 2:
37660
+ return "Sleepy End Device: keeps its radio off while idle to save battery and reaches the mesh only through a parent router. The links shown for it can include stale router-table entries for Thread addresses it no longer uses.";
37661
+ case 3:
37662
+ return "End Device: a leaf node that reaches the mesh through a parent router and does not route for other nodes. The links shown for it can include stale router-table entries for old or unused Thread addresses.";
37663
+ case 4:
37664
+ return "REED (Router-Eligible End Device): currently acts as an end device but can be promoted to a full Router when the mesh needs more routing capacity.";
37665
+ case 5:
37666
+ return "Router: forwards traffic for other nodes in the Thread mesh.";
37667
+ case 6:
37668
+ return "Leader: the elected node that manages router assignments for the Thread network.";
37669
+ case 0:
37670
+ case 1:
37671
+ return "Thread routing role is unassigned or unspecified.";
37672
+ default:
37673
+ return "Thread routing role could not be determined.";
37674
+ }
37675
+ }
37676
+ const EXTERNAL_THREAD_DEVICE_CASES = ["a device commissioned to another Matter fabric on the same Thread network", "a native (non-Matter) Thread accessory", "a Border Router whose Thread radio MAC differs from its MeshCoP border-agent ID (common with Apple and Aqara)", "a stale neighbor entry for a device that has left"];
37677
+ const EXTERNAL_THREAD_DEVICE_EXPLANATION = `Seen in a commissioned node's Thread neighbor table but not part of this fabric. It may be ${EXTERNAL_THREAD_DEVICE_CASES.slice(0, -1).join(", ")}, or ${EXTERNAL_THREAD_DEVICE_CASES[EXTERNAL_THREAD_DEVICE_CASES.length - 1]}.`;
37678
+ const EXTERNAL_ROUTER_CAPABLE_NOTE = `"Router" here means the neighbor advertised rx-on-when-idle (mains-powered / router-capable), not a confirmed routing role.`;
37679
+ const DIAGNOSTIC_MESH_NODE_EXPLANATION = "Inferred from Border Router diagnostics (Route64 / child table) and not commissioned to this fabric, so no device details are available.";
35929
37680
  function getWiFiSecurityTypeName(securityType) {
35930
37681
  switch (securityType) {
35931
37682
  case 0:
@@ -37635,6 +39386,7 @@ let NetworkDetails = class extends i$4 {
37635
39386
  <span class="label">Role:</span>
37636
39387
  <span class="value">${getThreadRoleName(threadRole)}</span>
37637
39388
  </div>
39389
+ <p class="hint-text inline-note">${getThreadRoleDescription(threadRole)}</p>
37638
39390
  ${threadVersion !== void 0 ? b`
37639
39391
  <div class="info-row">
37640
39392
  <span class="label">Thread version:</span>
@@ -37827,10 +39579,7 @@ let NetworkDetails = class extends i$4 {
37827
39579
 
37828
39580
  <md-divider></md-divider>
37829
39581
  <div class="section">
37830
- <p class="hint-text">
37831
- This node was inferred from Border Router diagnostics (Route64 / child table) and is not
37832
- commissioned to this fabric, so no device details are available.
37833
- </p>
39582
+ <p class="hint-text">${DIAGNOSTIC_MESH_NODE_EXPLANATION}</p>
37834
39583
  </div>
37835
39584
  `;
37836
39585
  }
@@ -37847,6 +39596,7 @@ let NetworkDetails = class extends i$4 {
37847
39596
  <span class="label">Type:</span>
37848
39597
  <span class="value">${unknown.isRouter ? "Router (external)" : "End Device (external)"}</span>
37849
39598
  </div>
39599
+ ${unknown.isRouter ? b`<p class="hint-text inline-note">${EXTERNAL_ROUTER_CAPABLE_NOTE}</p>` : A}
37850
39600
  <div class="info-row">
37851
39601
  <span class="label">Extended Address:</span>
37852
39602
  <span class="value mono">${unknown.extAddressHex}</span>
@@ -37876,10 +39626,12 @@ let NetworkDetails = class extends i$4 {
37876
39626
  <md-divider></md-divider>
37877
39627
  <div class="section">
37878
39628
  <p class="hint-text">
37879
- This device appears in Thread neighbor tables but is not commissioned to this fabric. It may be a
37880
- Thread Border Router whose Thread radio MAC differs from its MeshCoP border-agent ID (common with
37881
- Apple and Aqara), or a device from another Matter ecosystem.
39629
+ This device appears in a commissioned node's Thread neighbor table but is not part of this fabric.
39630
+ It may be:
37882
39631
  </p>
39632
+ <ul class="hint-text">
39633
+ ${EXTERNAL_THREAD_DEVICE_CASES.map(c => b`<li>${c}</li>`)}
39634
+ </ul>
37883
39635
  </div>
37884
39636
  `;
37885
39637
  }
@@ -38962,6 +40714,14 @@ NetworkDetails.styles = [reducedMotionStyles, i$7`
38962
40714
  margin: 0;
38963
40715
  }
38964
40716
 
40717
+ .hint-text.inline-note {
40718
+ margin-top: 6px;
40719
+ margin-bottom: 4px;
40720
+ padding-left: 10px;
40721
+ border-left: 2px solid var(--md-sys-color-outline-variant, #ccc);
40722
+ font-size: 0.72rem;
40723
+ }
40724
+
38965
40725
  .connected-nodes-list {
38966
40726
  display: flex;
38967
40727
  flex-direction: column;
@@ -47573,6 +49333,7 @@ let ThreadGraph = class extends BaseNetworkGraph {
47573
49333
  return {
47574
49334
  id: nodeId,
47575
49335
  label: getDeviceName(node),
49336
+ title: getThreadRoleDescription(threadRole),
47576
49337
  image: createNodeIconDataUrl(node, threadRole, false, isOffline),
47577
49338
  shape: "image",
47578
49339
  networkType: "thread",
@@ -47619,9 +49380,14 @@ ${suffixParts.join(" \xB7 ")}` : top;
47619
49380
  const decodedState = decodeMeshcopStateBitmap(device.stateBitmapHex);
47620
49381
  const isLeader = decodedState?.threadRoleValue === 3;
47621
49382
  const isPrimaryBbr = decodedState?.bbr === true && decodedState.bbrFunction === "primary";
49383
+ const brRole = new Array();
49384
+ if (isLeader) brRole.push("currently the Thread Leader");
49385
+ if (isPrimaryBbr) brRole.push("Primary Backbone Border Router (BBR)");
49386
+ const brTitle = "Thread Border Router bridging the Thread mesh to the IP network" + (brRole.length > 0 ? ` \u2014 ${brRole.join("; ")}.` : ".");
47622
49387
  graphNodes.push({
47623
49388
  id: device.id,
47624
49389
  label,
49390
+ title: brTitle,
47625
49391
  image: createBorderRouterIconDataUrl(isSelected, isLeader, isPrimaryBbr),
47626
49392
  shape: "image",
47627
49393
  networkType: "thread",
@@ -47633,9 +49399,11 @@ ${suffixParts.join(" \xB7 ")}` : top;
47633
49399
  const typeLabel = diagNode?.vendorName !== void 0 ? `${baseType} (${diagNode.vendorName})` : baseType;
47634
49400
  const suffix = device.networkName !== void 0 ? `
47635
49401
  ${device.networkName}` : "";
49402
+ const title = device.isRouter ? `${EXTERNAL_THREAD_DEVICE_EXPLANATION} ${EXTERNAL_ROUTER_CAPABLE_NOTE}` : EXTERNAL_THREAD_DEVICE_EXPLANATION;
47636
49403
  graphNodes.push({
47637
49404
  id: device.id,
47638
49405
  label: `${typeLabel} [${device.extAddressHex.slice(-8)}]${suffix}`,
49406
+ title,
47639
49407
  image: createUnknownDeviceIconDataUrl(device.isRouter, isSelected),
47640
49408
  shape: "image",
47641
49409
  networkType: "thread",
@@ -47688,6 +49456,7 @@ ${meshNode.networkName}`;
47688
49456
  graphNodes.push({
47689
49457
  id: meshNode.id,
47690
49458
  label,
49459
+ title: DIAGNOSTIC_MESH_NODE_EXPLANATION,
47691
49460
  image: createUnknownDeviceIconDataUrl(meshNode.isRouter, meshNode.id === this._selectedNodeId),
47692
49461
  shape: "image",
47693
49462
  networkType: "thread",
@@ -49122,7 +50891,7 @@ MatterNodeView = __decorateClass$3([t$1("matter-node-view")], MatterNodeView);
49122
50891
  * SPDX-License-Identifier: Apache-2.0
49123
50892
  */
49124
50893
  const showCommissionNodeDialog = async () => {
49125
- await import('./commission-node-dialog-BptZBF2k.js');
50894
+ await import('./commission-node-dialog-BlT9WOki.js');
49126
50895
  const dialog = document.createElement("commission-node-dialog");
49127
50896
  document.querySelector("matter-dashboard-app")?.renderRoot.appendChild(dialog);
49128
50897
  };
@@ -49133,7 +50902,7 @@ const showCommissionNodeDialog = async () => {
49133
50902
  * SPDX-License-Identifier: Apache-2.0
49134
50903
  */
49135
50904
  const showFabricLabelDialog = async (client, currentLabel, onSaved) => {
49136
- await import('./fabric-label-dialog-tW-AnWBx.js');
50905
+ await import('./fabric-label-dialog-DoBL1t3o.js');
49137
50906
  const dialog = document.createElement("fabric-label-dialog");
49138
50907
  dialog.client = client;
49139
50908
  dialog.currentLabel = currentLabel;
@@ -49539,6 +51308,7 @@ let MatterDashboardApp = class extends i$4 {
49539
51308
  this._updateRoute = () => {
49540
51309
  const hash = location.hash.substring(1);
49541
51310
  const pathParts = hash.split("/");
51311
+ window.scrollTo(0, 0);
49542
51312
  this._initialSelectedNodeId = null;
49543
51313
  const {
49544
51314
  hasThreadDevices,