@authowl/react 0.20.0 → 0.21.1

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/index.cjs CHANGED
@@ -6,8 +6,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __esm = (fn, res) => function __init() {
10
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
+ var __esm = (fn, res, err) => function __init() {
10
+ if (err) throw err[0];
11
+ try {
12
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
13
+ } catch (e) {
14
+ throw err = [e], e;
15
+ }
11
16
  };
12
17
  var __export = (target, all) => {
13
18
  for (var name in all)
@@ -316,6 +321,43 @@ function useOrganization() {
316
321
  isLoaded: !isPending && orgLoaded
317
322
  };
318
323
  }
324
+ function useInvitationRecipientHint() {
325
+ const client = useAuthClient();
326
+ const apiRef = React.useRef(client.organization);
327
+ apiRef.current = client.organization;
328
+ const [result, setResult] = React.useState({
329
+ recipientHint: null,
330
+ isLoaded: false
331
+ });
332
+ React.useEffect(() => {
333
+ let active = true;
334
+ const claim = (0, import_core.readInvitationClaim)();
335
+ if (!claim) {
336
+ setResult({ recipientHint: null, isLoaded: true });
337
+ return () => {
338
+ active = false;
339
+ };
340
+ }
341
+ void (async () => {
342
+ try {
343
+ const response = await apiRef.current.getInvitationRecipientHint({
344
+ invitationId: claim.id
345
+ });
346
+ if (!active) return;
347
+ setResult({
348
+ recipientHint: response.data?.recipientHint ?? null,
349
+ isLoaded: true
350
+ });
351
+ } catch {
352
+ if (active) setResult({ recipientHint: null, isLoaded: true });
353
+ }
354
+ })();
355
+ return () => {
356
+ active = false;
357
+ };
358
+ }, []);
359
+ return result;
360
+ }
319
361
  function useOrganizationInvitation() {
320
362
  const client = useAuthClient();
321
363
  const apiRef = React.useRef(client.organization);
@@ -888,195 +930,1865 @@ var init_FormError = __esm({
888
930
  }
889
931
  });
890
932
 
891
- // src/components/organization/model.ts
892
- function organizationSlugFromName(name) {
893
- return name.normalize("NFKD").toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 63);
894
- }
895
- function organizationRoles(role) {
896
- return role.split(",").map((value) => value.trim()).filter(Boolean);
897
- }
898
- function hasOrganizationRole(member, role) {
899
- return member ? organizationRoles(member.role).includes(role) : false;
900
- }
901
- function canManageOrganization(member) {
902
- return hasOrganizationRole(member, "owner") || hasOrganizationRole(member, "admin");
903
- }
904
- function roleHasStatement(roles, heldRoles, resource, action) {
905
- return roles.some((role) => {
906
- if (!heldRoles.has(role.role) || typeof role.permission !== "object" || role.permission === null) {
907
- return false;
908
- }
909
- const actions = role.permission[resource];
910
- return Array.isArray(actions) && actions.includes(action);
911
- });
912
- }
913
- function teamManagementCapabilities(member, dynamicRoles) {
914
- const heldRoles = new Set(organizationRoles(member.role));
915
- if (heldRoles.has("owner") || heldRoles.has("admin")) {
916
- return {
917
- createTeam: true,
918
- updateTeam: true,
919
- deleteTeam: true,
920
- addTeamMember: true,
921
- removeTeamMember: true
922
- };
923
- }
924
- return {
925
- createTeam: roleHasStatement(dynamicRoles, heldRoles, "team", "create"),
926
- updateTeam: roleHasStatement(dynamicRoles, heldRoles, "team", "update"),
927
- deleteTeam: roleHasStatement(dynamicRoles, heldRoles, "team", "delete"),
928
- addTeamMember: roleHasStatement(dynamicRoles, heldRoles, "member", "update"),
929
- removeTeamMember: roleHasStatement(dynamicRoles, heldRoles, "member", "delete")
930
- };
931
- }
932
- var init_model = __esm({
933
- "src/components/organization/model.ts"() {
933
+ // ../../node_modules/.pnpm/qrcode-generator@2.0.4/node_modules/qrcode-generator/dist/qrcode.mjs
934
+ var qrcode, QRMode, QRErrorCorrectionLevel, QRMaskPattern, QRUtil, QRMath, qrPolynomial, QRRSBlock, qrBitBuffer, qrNumber, qrAlphaNum, qr8BitByte, qrKanji, byteArrayOutputStream, base64EncodeOutputStream, base64DecodeInputStream, gifImage, createDataURL, qrcode_default, stringToBytes;
935
+ var init_qrcode = __esm({
936
+ "../../node_modules/.pnpm/qrcode-generator@2.0.4/node_modules/qrcode-generator/dist/qrcode.mjs"() {
934
937
  "use strict";
935
- }
936
- });
937
-
938
- // src/components/organization/use-organization-roles.ts
939
- function useOrganizationRoles(organizationId) {
940
- const api = useAuthClient().organization;
941
- const apiRef = React49.useRef(api);
942
- apiRef.current = api;
943
- const [dynamicRoles, setDynamicRoles] = React49.useState([]);
944
- const requestRef = React49.useRef(0);
945
- React49.useEffect(() => {
946
- const token = ++requestRef.current;
947
- setDynamicRoles([]);
948
- if (!organizationId) return;
949
- void (async () => {
950
- try {
951
- const result = await apiRef.current.listRoles({ organizationId });
952
- if (token !== requestRef.current) return;
953
- setDynamicRoles((result.data ?? []).filter((entry) => entry.role.trim().length > 0));
954
- } catch {
955
- }
956
- })();
957
- return () => {
958
- requestRef.current += 1;
938
+ qrcode = function(typeNumber, errorCorrectionLevel) {
939
+ const PAD0 = 236;
940
+ const PAD1 = 17;
941
+ let _typeNumber = typeNumber;
942
+ const _errorCorrectionLevel = QRErrorCorrectionLevel[errorCorrectionLevel];
943
+ let _modules = null;
944
+ let _moduleCount = 0;
945
+ let _dataCache = null;
946
+ const _dataList = [];
947
+ const _this = {};
948
+ const makeImpl = function(test, maskPattern) {
949
+ _moduleCount = _typeNumber * 4 + 17;
950
+ _modules = (function(moduleCount) {
951
+ const modules = new Array(moduleCount);
952
+ for (let row = 0; row < moduleCount; row += 1) {
953
+ modules[row] = new Array(moduleCount);
954
+ for (let col = 0; col < moduleCount; col += 1) {
955
+ modules[row][col] = null;
956
+ }
957
+ }
958
+ return modules;
959
+ })(_moduleCount);
960
+ setupPositionProbePattern(0, 0);
961
+ setupPositionProbePattern(_moduleCount - 7, 0);
962
+ setupPositionProbePattern(0, _moduleCount - 7);
963
+ setupPositionAdjustPattern();
964
+ setupTimingPattern();
965
+ setupTypeInfo(test, maskPattern);
966
+ if (_typeNumber >= 7) {
967
+ setupTypeNumber(test);
968
+ }
969
+ if (_dataCache == null) {
970
+ _dataCache = createData(_typeNumber, _errorCorrectionLevel, _dataList);
971
+ }
972
+ mapData(_dataCache, maskPattern);
973
+ };
974
+ const setupPositionProbePattern = function(row, col) {
975
+ for (let r = -1; r <= 7; r += 1) {
976
+ if (row + r <= -1 || _moduleCount <= row + r) continue;
977
+ for (let c = -1; c <= 7; c += 1) {
978
+ if (col + c <= -1 || _moduleCount <= col + c) continue;
979
+ 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) {
980
+ _modules[row + r][col + c] = true;
981
+ } else {
982
+ _modules[row + r][col + c] = false;
983
+ }
984
+ }
985
+ }
986
+ };
987
+ const getBestMaskPattern = function() {
988
+ let minLostPoint = 0;
989
+ let pattern = 0;
990
+ for (let i = 0; i < 8; i += 1) {
991
+ makeImpl(true, i);
992
+ const lostPoint = QRUtil.getLostPoint(_this);
993
+ if (i == 0 || minLostPoint > lostPoint) {
994
+ minLostPoint = lostPoint;
995
+ pattern = i;
996
+ }
997
+ }
998
+ return pattern;
999
+ };
1000
+ const setupTimingPattern = function() {
1001
+ for (let r = 8; r < _moduleCount - 8; r += 1) {
1002
+ if (_modules[r][6] != null) {
1003
+ continue;
1004
+ }
1005
+ _modules[r][6] = r % 2 == 0;
1006
+ }
1007
+ for (let c = 8; c < _moduleCount - 8; c += 1) {
1008
+ if (_modules[6][c] != null) {
1009
+ continue;
1010
+ }
1011
+ _modules[6][c] = c % 2 == 0;
1012
+ }
1013
+ };
1014
+ const setupPositionAdjustPattern = function() {
1015
+ const pos = QRUtil.getPatternPosition(_typeNumber);
1016
+ for (let i = 0; i < pos.length; i += 1) {
1017
+ for (let j = 0; j < pos.length; j += 1) {
1018
+ const row = pos[i];
1019
+ const col = pos[j];
1020
+ if (_modules[row][col] != null) {
1021
+ continue;
1022
+ }
1023
+ for (let r = -2; r <= 2; r += 1) {
1024
+ for (let c = -2; c <= 2; c += 1) {
1025
+ if (r == -2 || r == 2 || c == -2 || c == 2 || r == 0 && c == 0) {
1026
+ _modules[row + r][col + c] = true;
1027
+ } else {
1028
+ _modules[row + r][col + c] = false;
1029
+ }
1030
+ }
1031
+ }
1032
+ }
1033
+ }
1034
+ };
1035
+ const setupTypeNumber = function(test) {
1036
+ const bits = QRUtil.getBCHTypeNumber(_typeNumber);
1037
+ for (let i = 0; i < 18; i += 1) {
1038
+ const mod = !test && (bits >> i & 1) == 1;
1039
+ _modules[Math.floor(i / 3)][i % 3 + _moduleCount - 8 - 3] = mod;
1040
+ }
1041
+ for (let i = 0; i < 18; i += 1) {
1042
+ const mod = !test && (bits >> i & 1) == 1;
1043
+ _modules[i % 3 + _moduleCount - 8 - 3][Math.floor(i / 3)] = mod;
1044
+ }
1045
+ };
1046
+ const setupTypeInfo = function(test, maskPattern) {
1047
+ const data = _errorCorrectionLevel << 3 | maskPattern;
1048
+ const bits = QRUtil.getBCHTypeInfo(data);
1049
+ for (let i = 0; i < 15; i += 1) {
1050
+ const mod = !test && (bits >> i & 1) == 1;
1051
+ if (i < 6) {
1052
+ _modules[i][8] = mod;
1053
+ } else if (i < 8) {
1054
+ _modules[i + 1][8] = mod;
1055
+ } else {
1056
+ _modules[_moduleCount - 15 + i][8] = mod;
1057
+ }
1058
+ }
1059
+ for (let i = 0; i < 15; i += 1) {
1060
+ const mod = !test && (bits >> i & 1) == 1;
1061
+ if (i < 8) {
1062
+ _modules[8][_moduleCount - i - 1] = mod;
1063
+ } else if (i < 9) {
1064
+ _modules[8][15 - i - 1 + 1] = mod;
1065
+ } else {
1066
+ _modules[8][15 - i - 1] = mod;
1067
+ }
1068
+ }
1069
+ _modules[_moduleCount - 8][8] = !test;
1070
+ };
1071
+ const mapData = function(data, maskPattern) {
1072
+ let inc = -1;
1073
+ let row = _moduleCount - 1;
1074
+ let bitIndex = 7;
1075
+ let byteIndex = 0;
1076
+ const maskFunc = QRUtil.getMaskFunction(maskPattern);
1077
+ for (let col = _moduleCount - 1; col > 0; col -= 2) {
1078
+ if (col == 6) col -= 1;
1079
+ while (true) {
1080
+ for (let c = 0; c < 2; c += 1) {
1081
+ if (_modules[row][col - c] == null) {
1082
+ let dark = false;
1083
+ if (byteIndex < data.length) {
1084
+ dark = (data[byteIndex] >>> bitIndex & 1) == 1;
1085
+ }
1086
+ const mask = maskFunc(row, col - c);
1087
+ if (mask) {
1088
+ dark = !dark;
1089
+ }
1090
+ _modules[row][col - c] = dark;
1091
+ bitIndex -= 1;
1092
+ if (bitIndex == -1) {
1093
+ byteIndex += 1;
1094
+ bitIndex = 7;
1095
+ }
1096
+ }
1097
+ }
1098
+ row += inc;
1099
+ if (row < 0 || _moduleCount <= row) {
1100
+ row -= inc;
1101
+ inc = -inc;
1102
+ break;
1103
+ }
1104
+ }
1105
+ }
1106
+ };
1107
+ const createBytes = function(buffer, rsBlocks) {
1108
+ let offset = 0;
1109
+ let maxDcCount = 0;
1110
+ let maxEcCount = 0;
1111
+ const dcdata = new Array(rsBlocks.length);
1112
+ const ecdata = new Array(rsBlocks.length);
1113
+ for (let r = 0; r < rsBlocks.length; r += 1) {
1114
+ const dcCount = rsBlocks[r].dataCount;
1115
+ const ecCount = rsBlocks[r].totalCount - dcCount;
1116
+ maxDcCount = Math.max(maxDcCount, dcCount);
1117
+ maxEcCount = Math.max(maxEcCount, ecCount);
1118
+ dcdata[r] = new Array(dcCount);
1119
+ for (let i = 0; i < dcdata[r].length; i += 1) {
1120
+ dcdata[r][i] = 255 & buffer.getBuffer()[i + offset];
1121
+ }
1122
+ offset += dcCount;
1123
+ const rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
1124
+ const rawPoly = qrPolynomial(dcdata[r], rsPoly.getLength() - 1);
1125
+ const modPoly = rawPoly.mod(rsPoly);
1126
+ ecdata[r] = new Array(rsPoly.getLength() - 1);
1127
+ for (let i = 0; i < ecdata[r].length; i += 1) {
1128
+ const modIndex = i + modPoly.getLength() - ecdata[r].length;
1129
+ ecdata[r][i] = modIndex >= 0 ? modPoly.getAt(modIndex) : 0;
1130
+ }
1131
+ }
1132
+ let totalCodeCount = 0;
1133
+ for (let i = 0; i < rsBlocks.length; i += 1) {
1134
+ totalCodeCount += rsBlocks[i].totalCount;
1135
+ }
1136
+ const data = new Array(totalCodeCount);
1137
+ let index = 0;
1138
+ for (let i = 0; i < maxDcCount; i += 1) {
1139
+ for (let r = 0; r < rsBlocks.length; r += 1) {
1140
+ if (i < dcdata[r].length) {
1141
+ data[index] = dcdata[r][i];
1142
+ index += 1;
1143
+ }
1144
+ }
1145
+ }
1146
+ for (let i = 0; i < maxEcCount; i += 1) {
1147
+ for (let r = 0; r < rsBlocks.length; r += 1) {
1148
+ if (i < ecdata[r].length) {
1149
+ data[index] = ecdata[r][i];
1150
+ index += 1;
1151
+ }
1152
+ }
1153
+ }
1154
+ return data;
1155
+ };
1156
+ const createData = function(typeNumber2, errorCorrectionLevel2, dataList) {
1157
+ const rsBlocks = QRRSBlock.getRSBlocks(typeNumber2, errorCorrectionLevel2);
1158
+ const buffer = qrBitBuffer();
1159
+ for (let i = 0; i < dataList.length; i += 1) {
1160
+ const data = dataList[i];
1161
+ buffer.put(data.getMode(), 4);
1162
+ buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber2));
1163
+ data.write(buffer);
1164
+ }
1165
+ let totalDataCount = 0;
1166
+ for (let i = 0; i < rsBlocks.length; i += 1) {
1167
+ totalDataCount += rsBlocks[i].dataCount;
1168
+ }
1169
+ if (buffer.getLengthInBits() > totalDataCount * 8) {
1170
+ throw "code length overflow. (" + buffer.getLengthInBits() + ">" + totalDataCount * 8 + ")";
1171
+ }
1172
+ if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) {
1173
+ buffer.put(0, 4);
1174
+ }
1175
+ while (buffer.getLengthInBits() % 8 != 0) {
1176
+ buffer.putBit(false);
1177
+ }
1178
+ while (true) {
1179
+ if (buffer.getLengthInBits() >= totalDataCount * 8) {
1180
+ break;
1181
+ }
1182
+ buffer.put(PAD0, 8);
1183
+ if (buffer.getLengthInBits() >= totalDataCount * 8) {
1184
+ break;
1185
+ }
1186
+ buffer.put(PAD1, 8);
1187
+ }
1188
+ return createBytes(buffer, rsBlocks);
1189
+ };
1190
+ _this.addData = function(data, mode) {
1191
+ mode = mode || "Byte";
1192
+ let newData = null;
1193
+ switch (mode) {
1194
+ case "Numeric":
1195
+ newData = qrNumber(data);
1196
+ break;
1197
+ case "Alphanumeric":
1198
+ newData = qrAlphaNum(data);
1199
+ break;
1200
+ case "Byte":
1201
+ newData = qr8BitByte(data);
1202
+ break;
1203
+ case "Kanji":
1204
+ newData = qrKanji(data);
1205
+ break;
1206
+ default:
1207
+ throw "mode:" + mode;
1208
+ }
1209
+ _dataList.push(newData);
1210
+ _dataCache = null;
1211
+ };
1212
+ _this.isDark = function(row, col) {
1213
+ if (row < 0 || _moduleCount <= row || col < 0 || _moduleCount <= col) {
1214
+ throw row + "," + col;
1215
+ }
1216
+ return _modules[row][col];
1217
+ };
1218
+ _this.getModuleCount = function() {
1219
+ return _moduleCount;
1220
+ };
1221
+ _this.make = function() {
1222
+ if (_typeNumber < 1) {
1223
+ let typeNumber2 = 1;
1224
+ for (; typeNumber2 < 40; typeNumber2++) {
1225
+ const rsBlocks = QRRSBlock.getRSBlocks(typeNumber2, _errorCorrectionLevel);
1226
+ const buffer = qrBitBuffer();
1227
+ for (let i = 0; i < _dataList.length; i++) {
1228
+ const data = _dataList[i];
1229
+ buffer.put(data.getMode(), 4);
1230
+ buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber2));
1231
+ data.write(buffer);
1232
+ }
1233
+ let totalDataCount = 0;
1234
+ for (let i = 0; i < rsBlocks.length; i++) {
1235
+ totalDataCount += rsBlocks[i].dataCount;
1236
+ }
1237
+ if (buffer.getLengthInBits() <= totalDataCount * 8) {
1238
+ break;
1239
+ }
1240
+ }
1241
+ _typeNumber = typeNumber2;
1242
+ }
1243
+ makeImpl(false, getBestMaskPattern());
1244
+ };
1245
+ _this.createTableTag = function(cellSize, margin) {
1246
+ cellSize = cellSize || 2;
1247
+ margin = typeof margin == "undefined" ? cellSize * 4 : margin;
1248
+ let qrHtml = "";
1249
+ qrHtml += '<table style="';
1250
+ qrHtml += " border-width: 0px; border-style: none;";
1251
+ qrHtml += " border-collapse: collapse;";
1252
+ qrHtml += " padding: 0px; margin: " + margin + "px;";
1253
+ qrHtml += '">';
1254
+ qrHtml += "<tbody>";
1255
+ for (let r = 0; r < _this.getModuleCount(); r += 1) {
1256
+ qrHtml += "<tr>";
1257
+ for (let c = 0; c < _this.getModuleCount(); c += 1) {
1258
+ qrHtml += '<td style="';
1259
+ qrHtml += " border-width: 0px; border-style: none;";
1260
+ qrHtml += " border-collapse: collapse;";
1261
+ qrHtml += " padding: 0px; margin: 0px;";
1262
+ qrHtml += " width: " + cellSize + "px;";
1263
+ qrHtml += " height: " + cellSize + "px;";
1264
+ qrHtml += " background-color: ";
1265
+ qrHtml += _this.isDark(r, c) ? "#000000" : "#ffffff";
1266
+ qrHtml += ";";
1267
+ qrHtml += '"/>';
1268
+ }
1269
+ qrHtml += "</tr>";
1270
+ }
1271
+ qrHtml += "</tbody>";
1272
+ qrHtml += "</table>";
1273
+ return qrHtml;
1274
+ };
1275
+ _this.createSvgTag = function(cellSize, margin, alt, title) {
1276
+ let opts = {};
1277
+ if (typeof arguments[0] == "object") {
1278
+ opts = arguments[0];
1279
+ cellSize = opts.cellSize;
1280
+ margin = opts.margin;
1281
+ alt = opts.alt;
1282
+ title = opts.title;
1283
+ }
1284
+ cellSize = cellSize || 2;
1285
+ margin = typeof margin == "undefined" ? cellSize * 4 : margin;
1286
+ alt = typeof alt === "string" ? { text: alt } : alt || {};
1287
+ alt.text = alt.text || null;
1288
+ alt.id = alt.text ? alt.id || "qrcode-description" : null;
1289
+ title = typeof title === "string" ? { text: title } : title || {};
1290
+ title.text = title.text || null;
1291
+ title.id = title.text ? title.id || "qrcode-title" : null;
1292
+ const size = _this.getModuleCount() * cellSize + margin * 2;
1293
+ let c, mc, r, mr, qrSvg = "", rect;
1294
+ rect = "l" + cellSize + ",0 0," + cellSize + " -" + cellSize + ",0 0,-" + cellSize + "z ";
1295
+ qrSvg += '<svg version="1.1" xmlns="http://www.w3.org/2000/svg"';
1296
+ qrSvg += !opts.scalable ? ' width="' + size + 'px" height="' + size + 'px"' : "";
1297
+ qrSvg += ' viewBox="0 0 ' + size + " " + size + '" ';
1298
+ qrSvg += ' preserveAspectRatio="xMinYMin meet"';
1299
+ qrSvg += title.text || alt.text ? ' role="img" aria-labelledby="' + escapeXml([title.id, alt.id].join(" ").trim()) + '"' : "";
1300
+ qrSvg += ">";
1301
+ qrSvg += title.text ? '<title id="' + escapeXml(title.id) + '">' + escapeXml(title.text) + "</title>" : "";
1302
+ qrSvg += alt.text ? '<description id="' + escapeXml(alt.id) + '">' + escapeXml(alt.text) + "</description>" : "";
1303
+ qrSvg += '<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>';
1304
+ qrSvg += '<path d="';
1305
+ for (r = 0; r < _this.getModuleCount(); r += 1) {
1306
+ mr = r * cellSize + margin;
1307
+ for (c = 0; c < _this.getModuleCount(); c += 1) {
1308
+ if (_this.isDark(r, c)) {
1309
+ mc = c * cellSize + margin;
1310
+ qrSvg += "M" + mc + "," + mr + rect;
1311
+ }
1312
+ }
1313
+ }
1314
+ qrSvg += '" stroke="transparent" fill="black"/>';
1315
+ qrSvg += "</svg>";
1316
+ return qrSvg;
1317
+ };
1318
+ _this.createDataURL = function(cellSize, margin) {
1319
+ cellSize = cellSize || 2;
1320
+ margin = typeof margin == "undefined" ? cellSize * 4 : margin;
1321
+ const size = _this.getModuleCount() * cellSize + margin * 2;
1322
+ const min = margin;
1323
+ const max = size - margin;
1324
+ return createDataURL(size, size, function(x, y) {
1325
+ if (min <= x && x < max && min <= y && y < max) {
1326
+ const c = Math.floor((x - min) / cellSize);
1327
+ const r = Math.floor((y - min) / cellSize);
1328
+ return _this.isDark(r, c) ? 0 : 1;
1329
+ } else {
1330
+ return 1;
1331
+ }
1332
+ });
1333
+ };
1334
+ _this.createImgTag = function(cellSize, margin, alt) {
1335
+ cellSize = cellSize || 2;
1336
+ margin = typeof margin == "undefined" ? cellSize * 4 : margin;
1337
+ const size = _this.getModuleCount() * cellSize + margin * 2;
1338
+ let img = "";
1339
+ img += "<img";
1340
+ img += ' src="';
1341
+ img += _this.createDataURL(cellSize, margin);
1342
+ img += '"';
1343
+ img += ' width="';
1344
+ img += size;
1345
+ img += '"';
1346
+ img += ' height="';
1347
+ img += size;
1348
+ img += '"';
1349
+ if (alt) {
1350
+ img += ' alt="';
1351
+ img += escapeXml(alt);
1352
+ img += '"';
1353
+ }
1354
+ img += "/>";
1355
+ return img;
1356
+ };
1357
+ const escapeXml = function(s) {
1358
+ let escaped = "";
1359
+ for (let i = 0; i < s.length; i += 1) {
1360
+ const c = s.charAt(i);
1361
+ switch (c) {
1362
+ case "<":
1363
+ escaped += "&lt;";
1364
+ break;
1365
+ case ">":
1366
+ escaped += "&gt;";
1367
+ break;
1368
+ case "&":
1369
+ escaped += "&amp;";
1370
+ break;
1371
+ case '"':
1372
+ escaped += "&quot;";
1373
+ break;
1374
+ default:
1375
+ escaped += c;
1376
+ break;
1377
+ }
1378
+ }
1379
+ return escaped;
1380
+ };
1381
+ const _createHalfASCII = function(margin) {
1382
+ const cellSize = 1;
1383
+ margin = typeof margin == "undefined" ? cellSize * 2 : margin;
1384
+ const size = _this.getModuleCount() * cellSize + margin * 2;
1385
+ const min = margin;
1386
+ const max = size - margin;
1387
+ let y, x, r1, r2, p;
1388
+ const blocks = {
1389
+ "\u2588\u2588": "\u2588",
1390
+ "\u2588 ": "\u2580",
1391
+ " \u2588": "\u2584",
1392
+ " ": " "
1393
+ };
1394
+ const blocksLastLineNoMargin = {
1395
+ "\u2588\u2588": "\u2580",
1396
+ "\u2588 ": "\u2580",
1397
+ " \u2588": " ",
1398
+ " ": " "
1399
+ };
1400
+ let ascii = "";
1401
+ for (y = 0; y < size; y += 2) {
1402
+ r1 = Math.floor((y - min) / cellSize);
1403
+ r2 = Math.floor((y + 1 - min) / cellSize);
1404
+ for (x = 0; x < size; x += 1) {
1405
+ p = "\u2588";
1406
+ if (min <= x && x < max && min <= y && y < max && _this.isDark(r1, Math.floor((x - min) / cellSize))) {
1407
+ p = " ";
1408
+ }
1409
+ if (min <= x && x < max && min <= y + 1 && y + 1 < max && _this.isDark(r2, Math.floor((x - min) / cellSize))) {
1410
+ p += " ";
1411
+ } else {
1412
+ p += "\u2588";
1413
+ }
1414
+ ascii += margin < 1 && y + 1 >= max ? blocksLastLineNoMargin[p] : blocks[p];
1415
+ }
1416
+ ascii += "\n";
1417
+ }
1418
+ if (size % 2 && margin > 0) {
1419
+ return ascii.substring(0, ascii.length - size - 1) + Array(size + 1).join("\u2580");
1420
+ }
1421
+ return ascii.substring(0, ascii.length - 1);
1422
+ };
1423
+ _this.createASCII = function(cellSize, margin) {
1424
+ cellSize = cellSize || 1;
1425
+ if (cellSize < 2) {
1426
+ return _createHalfASCII(margin);
1427
+ }
1428
+ cellSize -= 1;
1429
+ margin = typeof margin == "undefined" ? cellSize * 2 : margin;
1430
+ const size = _this.getModuleCount() * cellSize + margin * 2;
1431
+ const min = margin;
1432
+ const max = size - margin;
1433
+ let y, x, r, p;
1434
+ const white = Array(cellSize + 1).join("\u2588\u2588");
1435
+ const black = Array(cellSize + 1).join(" ");
1436
+ let ascii = "";
1437
+ let line = "";
1438
+ for (y = 0; y < size; y += 1) {
1439
+ r = Math.floor((y - min) / cellSize);
1440
+ line = "";
1441
+ for (x = 0; x < size; x += 1) {
1442
+ p = 1;
1443
+ if (min <= x && x < max && min <= y && y < max && _this.isDark(r, Math.floor((x - min) / cellSize))) {
1444
+ p = 0;
1445
+ }
1446
+ line += p ? white : black;
1447
+ }
1448
+ for (r = 0; r < cellSize; r += 1) {
1449
+ ascii += line + "\n";
1450
+ }
1451
+ }
1452
+ return ascii.substring(0, ascii.length - 1);
1453
+ };
1454
+ _this.renderTo2dContext = function(context, cellSize) {
1455
+ cellSize = cellSize || 2;
1456
+ const length = _this.getModuleCount();
1457
+ for (let row = 0; row < length; row++) {
1458
+ for (let col = 0; col < length; col++) {
1459
+ context.fillStyle = _this.isDark(row, col) ? "black" : "white";
1460
+ context.fillRect(col * cellSize, row * cellSize, cellSize, cellSize);
1461
+ }
1462
+ }
1463
+ };
1464
+ return _this;
959
1465
  };
960
- }, [organizationId]);
961
- const roles = React49.useMemo(() => {
962
- const seen = /* @__PURE__ */ new Set();
963
- const out = [];
964
- for (const candidate of [...BUILTIN_ROLES, ...dynamicRoles.map((entry) => entry.role)]) {
965
- const key = candidate.trim();
966
- if (!key || seen.has(key)) continue;
967
- seen.add(key);
968
- out.push(key);
969
- }
970
- return out;
971
- }, [dynamicRoles]);
972
- return { roles, dynamicRoles };
973
- }
974
- var React49, BUILTIN_ROLES;
975
- var init_use_organization_roles = __esm({
976
- "src/components/organization/use-organization-roles.ts"() {
977
- "use strict";
978
- "use client";
979
- React49 = __toESM(require("react"), 1);
980
- init_hooks();
981
- BUILTIN_ROLES = ["owner", "admin", "member"];
982
- }
983
- });
984
-
985
- // src/components/organization/use-organization-list-resource.ts
986
- function useOrganizationListResource({
987
- enabled,
988
- resourceKey,
989
- request,
990
- fallback,
991
- inactiveData = null
992
- }) {
993
- const toServerError = useServerError();
994
- const requestFn = React51.useRef(request);
995
- requestFn.current = request;
996
- const [data, setData] = React51.useState(null);
997
- const [error, setError] = React51.useState(null);
998
- const requestToken = React51.useRef(0);
999
- const refresh = React51.useCallback(async () => {
1000
- const token = ++requestToken.current;
1001
- if (!enabled || !resourceKey) {
1002
- setData(inactiveData);
1003
- setError(null);
1004
- return;
1005
- }
1006
- setError(null);
1007
- try {
1008
- const result = await requestFn.current();
1009
- if (token !== requestToken.current) return;
1010
- if (result.error) {
1011
- setError(toServerError(result.error, fallback));
1012
- return;
1466
+ qrcode.stringToBytes = function(s) {
1467
+ const bytes = [];
1468
+ for (let i = 0; i < s.length; i += 1) {
1469
+ const c = s.charCodeAt(i);
1470
+ bytes.push(c & 255);
1013
1471
  }
1014
- setData(result.data ?? []);
1015
- } catch {
1016
- if (token === requestToken.current) setError(fallback);
1017
- }
1018
- }, [enabled, fallback, inactiveData, resourceKey, toServerError]);
1019
- React51.useEffect(() => {
1020
- setData(enabled && resourceKey ? null : inactiveData);
1021
- setError(null);
1022
- void refresh();
1023
- return () => {
1024
- requestToken.current += 1;
1472
+ return bytes;
1025
1473
  };
1026
- }, [enabled, inactiveData, refresh, resourceKey]);
1027
- return { data, isLoading: data === null && error === null, error, refresh };
1474
+ qrcode.createStringToBytes = function(unicodeData, numChars) {
1475
+ const unicodeMap = (function() {
1476
+ const bin = base64DecodeInputStream(unicodeData);
1477
+ const read = function() {
1478
+ const b = bin.read();
1479
+ if (b == -1) throw "eof";
1480
+ return b;
1481
+ };
1482
+ let count = 0;
1483
+ const unicodeMap2 = {};
1484
+ while (true) {
1485
+ const b0 = bin.read();
1486
+ if (b0 == -1) break;
1487
+ const b1 = read();
1488
+ const b2 = read();
1489
+ const b3 = read();
1490
+ const k = String.fromCharCode(b0 << 8 | b1);
1491
+ const v = b2 << 8 | b3;
1492
+ unicodeMap2[k] = v;
1493
+ count += 1;
1494
+ }
1495
+ if (count != numChars) {
1496
+ throw count + " != " + numChars;
1497
+ }
1498
+ return unicodeMap2;
1499
+ })();
1500
+ const unknownChar = "?".charCodeAt(0);
1501
+ return function(s) {
1502
+ const bytes = [];
1503
+ for (let i = 0; i < s.length; i += 1) {
1504
+ const c = s.charCodeAt(i);
1505
+ if (c < 128) {
1506
+ bytes.push(c);
1507
+ } else {
1508
+ const b = unicodeMap[s.charAt(i)];
1509
+ if (typeof b == "number") {
1510
+ if ((b & 255) == b) {
1511
+ bytes.push(b);
1512
+ } else {
1513
+ bytes.push(b >>> 8);
1514
+ bytes.push(b & 255);
1515
+ }
1516
+ } else {
1517
+ bytes.push(unknownChar);
1518
+ }
1519
+ }
1520
+ }
1521
+ return bytes;
1522
+ };
1523
+ };
1524
+ QRMode = {
1525
+ MODE_NUMBER: 1 << 0,
1526
+ MODE_ALPHA_NUM: 1 << 1,
1527
+ MODE_8BIT_BYTE: 1 << 2,
1528
+ MODE_KANJI: 1 << 3
1529
+ };
1530
+ QRErrorCorrectionLevel = {
1531
+ L: 1,
1532
+ M: 0,
1533
+ Q: 3,
1534
+ H: 2
1535
+ };
1536
+ QRMaskPattern = {
1537
+ PATTERN000: 0,
1538
+ PATTERN001: 1,
1539
+ PATTERN010: 2,
1540
+ PATTERN011: 3,
1541
+ PATTERN100: 4,
1542
+ PATTERN101: 5,
1543
+ PATTERN110: 6,
1544
+ PATTERN111: 7
1545
+ };
1546
+ QRUtil = (function() {
1547
+ const PATTERN_POSITION_TABLE = [
1548
+ [],
1549
+ [6, 18],
1550
+ [6, 22],
1551
+ [6, 26],
1552
+ [6, 30],
1553
+ [6, 34],
1554
+ [6, 22, 38],
1555
+ [6, 24, 42],
1556
+ [6, 26, 46],
1557
+ [6, 28, 50],
1558
+ [6, 30, 54],
1559
+ [6, 32, 58],
1560
+ [6, 34, 62],
1561
+ [6, 26, 46, 66],
1562
+ [6, 26, 48, 70],
1563
+ [6, 26, 50, 74],
1564
+ [6, 30, 54, 78],
1565
+ [6, 30, 56, 82],
1566
+ [6, 30, 58, 86],
1567
+ [6, 34, 62, 90],
1568
+ [6, 28, 50, 72, 94],
1569
+ [6, 26, 50, 74, 98],
1570
+ [6, 30, 54, 78, 102],
1571
+ [6, 28, 54, 80, 106],
1572
+ [6, 32, 58, 84, 110],
1573
+ [6, 30, 58, 86, 114],
1574
+ [6, 34, 62, 90, 118],
1575
+ [6, 26, 50, 74, 98, 122],
1576
+ [6, 30, 54, 78, 102, 126],
1577
+ [6, 26, 52, 78, 104, 130],
1578
+ [6, 30, 56, 82, 108, 134],
1579
+ [6, 34, 60, 86, 112, 138],
1580
+ [6, 30, 58, 86, 114, 142],
1581
+ [6, 34, 62, 90, 118, 146],
1582
+ [6, 30, 54, 78, 102, 126, 150],
1583
+ [6, 24, 50, 76, 102, 128, 154],
1584
+ [6, 28, 54, 80, 106, 132, 158],
1585
+ [6, 32, 58, 84, 110, 136, 162],
1586
+ [6, 26, 54, 82, 110, 138, 166],
1587
+ [6, 30, 58, 86, 114, 142, 170]
1588
+ ];
1589
+ const G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0;
1590
+ const G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0;
1591
+ const G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;
1592
+ const _this = {};
1593
+ const getBCHDigit = function(data) {
1594
+ let digit = 0;
1595
+ while (data != 0) {
1596
+ digit += 1;
1597
+ data >>>= 1;
1598
+ }
1599
+ return digit;
1600
+ };
1601
+ _this.getBCHTypeInfo = function(data) {
1602
+ let d = data << 10;
1603
+ while (getBCHDigit(d) - getBCHDigit(G15) >= 0) {
1604
+ d ^= G15 << getBCHDigit(d) - getBCHDigit(G15);
1605
+ }
1606
+ return (data << 10 | d) ^ G15_MASK;
1607
+ };
1608
+ _this.getBCHTypeNumber = function(data) {
1609
+ let d = data << 12;
1610
+ while (getBCHDigit(d) - getBCHDigit(G18) >= 0) {
1611
+ d ^= G18 << getBCHDigit(d) - getBCHDigit(G18);
1612
+ }
1613
+ return data << 12 | d;
1614
+ };
1615
+ _this.getPatternPosition = function(typeNumber) {
1616
+ return PATTERN_POSITION_TABLE[typeNumber - 1];
1617
+ };
1618
+ _this.getMaskFunction = function(maskPattern) {
1619
+ switch (maskPattern) {
1620
+ case QRMaskPattern.PATTERN000:
1621
+ return function(i, j) {
1622
+ return (i + j) % 2 == 0;
1623
+ };
1624
+ case QRMaskPattern.PATTERN001:
1625
+ return function(i, j) {
1626
+ return i % 2 == 0;
1627
+ };
1628
+ case QRMaskPattern.PATTERN010:
1629
+ return function(i, j) {
1630
+ return j % 3 == 0;
1631
+ };
1632
+ case QRMaskPattern.PATTERN011:
1633
+ return function(i, j) {
1634
+ return (i + j) % 3 == 0;
1635
+ };
1636
+ case QRMaskPattern.PATTERN100:
1637
+ return function(i, j) {
1638
+ return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0;
1639
+ };
1640
+ case QRMaskPattern.PATTERN101:
1641
+ return function(i, j) {
1642
+ return i * j % 2 + i * j % 3 == 0;
1643
+ };
1644
+ case QRMaskPattern.PATTERN110:
1645
+ return function(i, j) {
1646
+ return (i * j % 2 + i * j % 3) % 2 == 0;
1647
+ };
1648
+ case QRMaskPattern.PATTERN111:
1649
+ return function(i, j) {
1650
+ return (i * j % 3 + (i + j) % 2) % 2 == 0;
1651
+ };
1652
+ default:
1653
+ throw "bad maskPattern:" + maskPattern;
1654
+ }
1655
+ };
1656
+ _this.getErrorCorrectPolynomial = function(errorCorrectLength) {
1657
+ let a = qrPolynomial([1], 0);
1658
+ for (let i = 0; i < errorCorrectLength; i += 1) {
1659
+ a = a.multiply(qrPolynomial([1, QRMath.gexp(i)], 0));
1660
+ }
1661
+ return a;
1662
+ };
1663
+ _this.getLengthInBits = function(mode, type) {
1664
+ if (1 <= type && type < 10) {
1665
+ switch (mode) {
1666
+ case QRMode.MODE_NUMBER:
1667
+ return 10;
1668
+ case QRMode.MODE_ALPHA_NUM:
1669
+ return 9;
1670
+ case QRMode.MODE_8BIT_BYTE:
1671
+ return 8;
1672
+ case QRMode.MODE_KANJI:
1673
+ return 8;
1674
+ default:
1675
+ throw "mode:" + mode;
1676
+ }
1677
+ } else if (type < 27) {
1678
+ switch (mode) {
1679
+ case QRMode.MODE_NUMBER:
1680
+ return 12;
1681
+ case QRMode.MODE_ALPHA_NUM:
1682
+ return 11;
1683
+ case QRMode.MODE_8BIT_BYTE:
1684
+ return 16;
1685
+ case QRMode.MODE_KANJI:
1686
+ return 10;
1687
+ default:
1688
+ throw "mode:" + mode;
1689
+ }
1690
+ } else if (type < 41) {
1691
+ switch (mode) {
1692
+ case QRMode.MODE_NUMBER:
1693
+ return 14;
1694
+ case QRMode.MODE_ALPHA_NUM:
1695
+ return 13;
1696
+ case QRMode.MODE_8BIT_BYTE:
1697
+ return 16;
1698
+ case QRMode.MODE_KANJI:
1699
+ return 12;
1700
+ default:
1701
+ throw "mode:" + mode;
1702
+ }
1703
+ } else {
1704
+ throw "type:" + type;
1705
+ }
1706
+ };
1707
+ _this.getLostPoint = function(qrcode2) {
1708
+ const moduleCount = qrcode2.getModuleCount();
1709
+ let lostPoint = 0;
1710
+ for (let row = 0; row < moduleCount; row += 1) {
1711
+ for (let col = 0; col < moduleCount; col += 1) {
1712
+ let sameCount = 0;
1713
+ const dark = qrcode2.isDark(row, col);
1714
+ for (let r = -1; r <= 1; r += 1) {
1715
+ if (row + r < 0 || moduleCount <= row + r) {
1716
+ continue;
1717
+ }
1718
+ for (let c = -1; c <= 1; c += 1) {
1719
+ if (col + c < 0 || moduleCount <= col + c) {
1720
+ continue;
1721
+ }
1722
+ if (r == 0 && c == 0) {
1723
+ continue;
1724
+ }
1725
+ if (dark == qrcode2.isDark(row + r, col + c)) {
1726
+ sameCount += 1;
1727
+ }
1728
+ }
1729
+ }
1730
+ if (sameCount > 5) {
1731
+ lostPoint += 3 + sameCount - 5;
1732
+ }
1733
+ }
1734
+ }
1735
+ ;
1736
+ for (let row = 0; row < moduleCount - 1; row += 1) {
1737
+ for (let col = 0; col < moduleCount - 1; col += 1) {
1738
+ let count = 0;
1739
+ if (qrcode2.isDark(row, col)) count += 1;
1740
+ if (qrcode2.isDark(row + 1, col)) count += 1;
1741
+ if (qrcode2.isDark(row, col + 1)) count += 1;
1742
+ if (qrcode2.isDark(row + 1, col + 1)) count += 1;
1743
+ if (count == 0 || count == 4) {
1744
+ lostPoint += 3;
1745
+ }
1746
+ }
1747
+ }
1748
+ for (let row = 0; row < moduleCount; row += 1) {
1749
+ for (let col = 0; col < moduleCount - 6; col += 1) {
1750
+ if (qrcode2.isDark(row, col) && !qrcode2.isDark(row, col + 1) && qrcode2.isDark(row, col + 2) && qrcode2.isDark(row, col + 3) && qrcode2.isDark(row, col + 4) && !qrcode2.isDark(row, col + 5) && qrcode2.isDark(row, col + 6)) {
1751
+ lostPoint += 40;
1752
+ }
1753
+ }
1754
+ }
1755
+ for (let col = 0; col < moduleCount; col += 1) {
1756
+ for (let row = 0; row < moduleCount - 6; row += 1) {
1757
+ if (qrcode2.isDark(row, col) && !qrcode2.isDark(row + 1, col) && qrcode2.isDark(row + 2, col) && qrcode2.isDark(row + 3, col) && qrcode2.isDark(row + 4, col) && !qrcode2.isDark(row + 5, col) && qrcode2.isDark(row + 6, col)) {
1758
+ lostPoint += 40;
1759
+ }
1760
+ }
1761
+ }
1762
+ let darkCount = 0;
1763
+ for (let col = 0; col < moduleCount; col += 1) {
1764
+ for (let row = 0; row < moduleCount; row += 1) {
1765
+ if (qrcode2.isDark(row, col)) {
1766
+ darkCount += 1;
1767
+ }
1768
+ }
1769
+ }
1770
+ const ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
1771
+ lostPoint += ratio * 10;
1772
+ return lostPoint;
1773
+ };
1774
+ return _this;
1775
+ })();
1776
+ QRMath = (function() {
1777
+ const EXP_TABLE = new Array(256);
1778
+ const LOG_TABLE = new Array(256);
1779
+ for (let i = 0; i < 8; i += 1) {
1780
+ EXP_TABLE[i] = 1 << i;
1781
+ }
1782
+ for (let i = 8; i < 256; i += 1) {
1783
+ EXP_TABLE[i] = EXP_TABLE[i - 4] ^ EXP_TABLE[i - 5] ^ EXP_TABLE[i - 6] ^ EXP_TABLE[i - 8];
1784
+ }
1785
+ for (let i = 0; i < 255; i += 1) {
1786
+ LOG_TABLE[EXP_TABLE[i]] = i;
1787
+ }
1788
+ const _this = {};
1789
+ _this.glog = function(n) {
1790
+ if (n < 1) {
1791
+ throw "glog(" + n + ")";
1792
+ }
1793
+ return LOG_TABLE[n];
1794
+ };
1795
+ _this.gexp = function(n) {
1796
+ while (n < 0) {
1797
+ n += 255;
1798
+ }
1799
+ while (n >= 256) {
1800
+ n -= 255;
1801
+ }
1802
+ return EXP_TABLE[n];
1803
+ };
1804
+ return _this;
1805
+ })();
1806
+ qrPolynomial = function(num, shift) {
1807
+ if (typeof num.length == "undefined") {
1808
+ throw num.length + "/" + shift;
1809
+ }
1810
+ const _num = (function() {
1811
+ let offset = 0;
1812
+ while (offset < num.length && num[offset] == 0) {
1813
+ offset += 1;
1814
+ }
1815
+ const _num2 = new Array(num.length - offset + shift);
1816
+ for (let i = 0; i < num.length - offset; i += 1) {
1817
+ _num2[i] = num[i + offset];
1818
+ }
1819
+ return _num2;
1820
+ })();
1821
+ const _this = {};
1822
+ _this.getAt = function(index) {
1823
+ return _num[index];
1824
+ };
1825
+ _this.getLength = function() {
1826
+ return _num.length;
1827
+ };
1828
+ _this.multiply = function(e) {
1829
+ const num2 = new Array(_this.getLength() + e.getLength() - 1);
1830
+ for (let i = 0; i < _this.getLength(); i += 1) {
1831
+ for (let j = 0; j < e.getLength(); j += 1) {
1832
+ num2[i + j] ^= QRMath.gexp(QRMath.glog(_this.getAt(i)) + QRMath.glog(e.getAt(j)));
1833
+ }
1834
+ }
1835
+ return qrPolynomial(num2, 0);
1836
+ };
1837
+ _this.mod = function(e) {
1838
+ if (_this.getLength() - e.getLength() < 0) {
1839
+ return _this;
1840
+ }
1841
+ const ratio = QRMath.glog(_this.getAt(0)) - QRMath.glog(e.getAt(0));
1842
+ const num2 = new Array(_this.getLength());
1843
+ for (let i = 0; i < _this.getLength(); i += 1) {
1844
+ num2[i] = _this.getAt(i);
1845
+ }
1846
+ for (let i = 0; i < e.getLength(); i += 1) {
1847
+ num2[i] ^= QRMath.gexp(QRMath.glog(e.getAt(i)) + ratio);
1848
+ }
1849
+ return qrPolynomial(num2, 0).mod(e);
1850
+ };
1851
+ return _this;
1852
+ };
1853
+ QRRSBlock = (function() {
1854
+ const RS_BLOCK_TABLE = [
1855
+ // L
1856
+ // M
1857
+ // Q
1858
+ // H
1859
+ // 1
1860
+ [1, 26, 19],
1861
+ [1, 26, 16],
1862
+ [1, 26, 13],
1863
+ [1, 26, 9],
1864
+ // 2
1865
+ [1, 44, 34],
1866
+ [1, 44, 28],
1867
+ [1, 44, 22],
1868
+ [1, 44, 16],
1869
+ // 3
1870
+ [1, 70, 55],
1871
+ [1, 70, 44],
1872
+ [2, 35, 17],
1873
+ [2, 35, 13],
1874
+ // 4
1875
+ [1, 100, 80],
1876
+ [2, 50, 32],
1877
+ [2, 50, 24],
1878
+ [4, 25, 9],
1879
+ // 5
1880
+ [1, 134, 108],
1881
+ [2, 67, 43],
1882
+ [2, 33, 15, 2, 34, 16],
1883
+ [2, 33, 11, 2, 34, 12],
1884
+ // 6
1885
+ [2, 86, 68],
1886
+ [4, 43, 27],
1887
+ [4, 43, 19],
1888
+ [4, 43, 15],
1889
+ // 7
1890
+ [2, 98, 78],
1891
+ [4, 49, 31],
1892
+ [2, 32, 14, 4, 33, 15],
1893
+ [4, 39, 13, 1, 40, 14],
1894
+ // 8
1895
+ [2, 121, 97],
1896
+ [2, 60, 38, 2, 61, 39],
1897
+ [4, 40, 18, 2, 41, 19],
1898
+ [4, 40, 14, 2, 41, 15],
1899
+ // 9
1900
+ [2, 146, 116],
1901
+ [3, 58, 36, 2, 59, 37],
1902
+ [4, 36, 16, 4, 37, 17],
1903
+ [4, 36, 12, 4, 37, 13],
1904
+ // 10
1905
+ [2, 86, 68, 2, 87, 69],
1906
+ [4, 69, 43, 1, 70, 44],
1907
+ [6, 43, 19, 2, 44, 20],
1908
+ [6, 43, 15, 2, 44, 16],
1909
+ // 11
1910
+ [4, 101, 81],
1911
+ [1, 80, 50, 4, 81, 51],
1912
+ [4, 50, 22, 4, 51, 23],
1913
+ [3, 36, 12, 8, 37, 13],
1914
+ // 12
1915
+ [2, 116, 92, 2, 117, 93],
1916
+ [6, 58, 36, 2, 59, 37],
1917
+ [4, 46, 20, 6, 47, 21],
1918
+ [7, 42, 14, 4, 43, 15],
1919
+ // 13
1920
+ [4, 133, 107],
1921
+ [8, 59, 37, 1, 60, 38],
1922
+ [8, 44, 20, 4, 45, 21],
1923
+ [12, 33, 11, 4, 34, 12],
1924
+ // 14
1925
+ [3, 145, 115, 1, 146, 116],
1926
+ [4, 64, 40, 5, 65, 41],
1927
+ [11, 36, 16, 5, 37, 17],
1928
+ [11, 36, 12, 5, 37, 13],
1929
+ // 15
1930
+ [5, 109, 87, 1, 110, 88],
1931
+ [5, 65, 41, 5, 66, 42],
1932
+ [5, 54, 24, 7, 55, 25],
1933
+ [11, 36, 12, 7, 37, 13],
1934
+ // 16
1935
+ [5, 122, 98, 1, 123, 99],
1936
+ [7, 73, 45, 3, 74, 46],
1937
+ [15, 43, 19, 2, 44, 20],
1938
+ [3, 45, 15, 13, 46, 16],
1939
+ // 17
1940
+ [1, 135, 107, 5, 136, 108],
1941
+ [10, 74, 46, 1, 75, 47],
1942
+ [1, 50, 22, 15, 51, 23],
1943
+ [2, 42, 14, 17, 43, 15],
1944
+ // 18
1945
+ [5, 150, 120, 1, 151, 121],
1946
+ [9, 69, 43, 4, 70, 44],
1947
+ [17, 50, 22, 1, 51, 23],
1948
+ [2, 42, 14, 19, 43, 15],
1949
+ // 19
1950
+ [3, 141, 113, 4, 142, 114],
1951
+ [3, 70, 44, 11, 71, 45],
1952
+ [17, 47, 21, 4, 48, 22],
1953
+ [9, 39, 13, 16, 40, 14],
1954
+ // 20
1955
+ [3, 135, 107, 5, 136, 108],
1956
+ [3, 67, 41, 13, 68, 42],
1957
+ [15, 54, 24, 5, 55, 25],
1958
+ [15, 43, 15, 10, 44, 16],
1959
+ // 21
1960
+ [4, 144, 116, 4, 145, 117],
1961
+ [17, 68, 42],
1962
+ [17, 50, 22, 6, 51, 23],
1963
+ [19, 46, 16, 6, 47, 17],
1964
+ // 22
1965
+ [2, 139, 111, 7, 140, 112],
1966
+ [17, 74, 46],
1967
+ [7, 54, 24, 16, 55, 25],
1968
+ [34, 37, 13],
1969
+ // 23
1970
+ [4, 151, 121, 5, 152, 122],
1971
+ [4, 75, 47, 14, 76, 48],
1972
+ [11, 54, 24, 14, 55, 25],
1973
+ [16, 45, 15, 14, 46, 16],
1974
+ // 24
1975
+ [6, 147, 117, 4, 148, 118],
1976
+ [6, 73, 45, 14, 74, 46],
1977
+ [11, 54, 24, 16, 55, 25],
1978
+ [30, 46, 16, 2, 47, 17],
1979
+ // 25
1980
+ [8, 132, 106, 4, 133, 107],
1981
+ [8, 75, 47, 13, 76, 48],
1982
+ [7, 54, 24, 22, 55, 25],
1983
+ [22, 45, 15, 13, 46, 16],
1984
+ // 26
1985
+ [10, 142, 114, 2, 143, 115],
1986
+ [19, 74, 46, 4, 75, 47],
1987
+ [28, 50, 22, 6, 51, 23],
1988
+ [33, 46, 16, 4, 47, 17],
1989
+ // 27
1990
+ [8, 152, 122, 4, 153, 123],
1991
+ [22, 73, 45, 3, 74, 46],
1992
+ [8, 53, 23, 26, 54, 24],
1993
+ [12, 45, 15, 28, 46, 16],
1994
+ // 28
1995
+ [3, 147, 117, 10, 148, 118],
1996
+ [3, 73, 45, 23, 74, 46],
1997
+ [4, 54, 24, 31, 55, 25],
1998
+ [11, 45, 15, 31, 46, 16],
1999
+ // 29
2000
+ [7, 146, 116, 7, 147, 117],
2001
+ [21, 73, 45, 7, 74, 46],
2002
+ [1, 53, 23, 37, 54, 24],
2003
+ [19, 45, 15, 26, 46, 16],
2004
+ // 30
2005
+ [5, 145, 115, 10, 146, 116],
2006
+ [19, 75, 47, 10, 76, 48],
2007
+ [15, 54, 24, 25, 55, 25],
2008
+ [23, 45, 15, 25, 46, 16],
2009
+ // 31
2010
+ [13, 145, 115, 3, 146, 116],
2011
+ [2, 74, 46, 29, 75, 47],
2012
+ [42, 54, 24, 1, 55, 25],
2013
+ [23, 45, 15, 28, 46, 16],
2014
+ // 32
2015
+ [17, 145, 115],
2016
+ [10, 74, 46, 23, 75, 47],
2017
+ [10, 54, 24, 35, 55, 25],
2018
+ [19, 45, 15, 35, 46, 16],
2019
+ // 33
2020
+ [17, 145, 115, 1, 146, 116],
2021
+ [14, 74, 46, 21, 75, 47],
2022
+ [29, 54, 24, 19, 55, 25],
2023
+ [11, 45, 15, 46, 46, 16],
2024
+ // 34
2025
+ [13, 145, 115, 6, 146, 116],
2026
+ [14, 74, 46, 23, 75, 47],
2027
+ [44, 54, 24, 7, 55, 25],
2028
+ [59, 46, 16, 1, 47, 17],
2029
+ // 35
2030
+ [12, 151, 121, 7, 152, 122],
2031
+ [12, 75, 47, 26, 76, 48],
2032
+ [39, 54, 24, 14, 55, 25],
2033
+ [22, 45, 15, 41, 46, 16],
2034
+ // 36
2035
+ [6, 151, 121, 14, 152, 122],
2036
+ [6, 75, 47, 34, 76, 48],
2037
+ [46, 54, 24, 10, 55, 25],
2038
+ [2, 45, 15, 64, 46, 16],
2039
+ // 37
2040
+ [17, 152, 122, 4, 153, 123],
2041
+ [29, 74, 46, 14, 75, 47],
2042
+ [49, 54, 24, 10, 55, 25],
2043
+ [24, 45, 15, 46, 46, 16],
2044
+ // 38
2045
+ [4, 152, 122, 18, 153, 123],
2046
+ [13, 74, 46, 32, 75, 47],
2047
+ [48, 54, 24, 14, 55, 25],
2048
+ [42, 45, 15, 32, 46, 16],
2049
+ // 39
2050
+ [20, 147, 117, 4, 148, 118],
2051
+ [40, 75, 47, 7, 76, 48],
2052
+ [43, 54, 24, 22, 55, 25],
2053
+ [10, 45, 15, 67, 46, 16],
2054
+ // 40
2055
+ [19, 148, 118, 6, 149, 119],
2056
+ [18, 75, 47, 31, 76, 48],
2057
+ [34, 54, 24, 34, 55, 25],
2058
+ [20, 45, 15, 61, 46, 16]
2059
+ ];
2060
+ const qrRSBlock = function(totalCount, dataCount) {
2061
+ const _this2 = {};
2062
+ _this2.totalCount = totalCount;
2063
+ _this2.dataCount = dataCount;
2064
+ return _this2;
2065
+ };
2066
+ const _this = {};
2067
+ const getRsBlockTable = function(typeNumber, errorCorrectionLevel) {
2068
+ switch (errorCorrectionLevel) {
2069
+ case QRErrorCorrectionLevel.L:
2070
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];
2071
+ case QRErrorCorrectionLevel.M:
2072
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
2073
+ case QRErrorCorrectionLevel.Q:
2074
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
2075
+ case QRErrorCorrectionLevel.H:
2076
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
2077
+ default:
2078
+ return void 0;
2079
+ }
2080
+ };
2081
+ _this.getRSBlocks = function(typeNumber, errorCorrectionLevel) {
2082
+ const rsBlock = getRsBlockTable(typeNumber, errorCorrectionLevel);
2083
+ if (typeof rsBlock == "undefined") {
2084
+ throw "bad rs block @ typeNumber:" + typeNumber + "/errorCorrectionLevel:" + errorCorrectionLevel;
2085
+ }
2086
+ const length = rsBlock.length / 3;
2087
+ const list = [];
2088
+ for (let i = 0; i < length; i += 1) {
2089
+ const count = rsBlock[i * 3 + 0];
2090
+ const totalCount = rsBlock[i * 3 + 1];
2091
+ const dataCount = rsBlock[i * 3 + 2];
2092
+ for (let j = 0; j < count; j += 1) {
2093
+ list.push(qrRSBlock(totalCount, dataCount));
2094
+ }
2095
+ }
2096
+ return list;
2097
+ };
2098
+ return _this;
2099
+ })();
2100
+ qrBitBuffer = function() {
2101
+ const _buffer = [];
2102
+ let _length = 0;
2103
+ const _this = {};
2104
+ _this.getBuffer = function() {
2105
+ return _buffer;
2106
+ };
2107
+ _this.getAt = function(index) {
2108
+ const bufIndex = Math.floor(index / 8);
2109
+ return (_buffer[bufIndex] >>> 7 - index % 8 & 1) == 1;
2110
+ };
2111
+ _this.put = function(num, length) {
2112
+ for (let i = 0; i < length; i += 1) {
2113
+ _this.putBit((num >>> length - i - 1 & 1) == 1);
2114
+ }
2115
+ };
2116
+ _this.getLengthInBits = function() {
2117
+ return _length;
2118
+ };
2119
+ _this.putBit = function(bit) {
2120
+ const bufIndex = Math.floor(_length / 8);
2121
+ if (_buffer.length <= bufIndex) {
2122
+ _buffer.push(0);
2123
+ }
2124
+ if (bit) {
2125
+ _buffer[bufIndex] |= 128 >>> _length % 8;
2126
+ }
2127
+ _length += 1;
2128
+ };
2129
+ return _this;
2130
+ };
2131
+ qrNumber = function(data) {
2132
+ const _mode = QRMode.MODE_NUMBER;
2133
+ const _data = data;
2134
+ const _this = {};
2135
+ _this.getMode = function() {
2136
+ return _mode;
2137
+ };
2138
+ _this.getLength = function(buffer) {
2139
+ return _data.length;
2140
+ };
2141
+ _this.write = function(buffer) {
2142
+ const data2 = _data;
2143
+ let i = 0;
2144
+ while (i + 2 < data2.length) {
2145
+ buffer.put(strToNum(data2.substring(i, i + 3)), 10);
2146
+ i += 3;
2147
+ }
2148
+ if (i < data2.length) {
2149
+ if (data2.length - i == 1) {
2150
+ buffer.put(strToNum(data2.substring(i, i + 1)), 4);
2151
+ } else if (data2.length - i == 2) {
2152
+ buffer.put(strToNum(data2.substring(i, i + 2)), 7);
2153
+ }
2154
+ }
2155
+ };
2156
+ const strToNum = function(s) {
2157
+ let num = 0;
2158
+ for (let i = 0; i < s.length; i += 1) {
2159
+ num = num * 10 + chatToNum(s.charAt(i));
2160
+ }
2161
+ return num;
2162
+ };
2163
+ const chatToNum = function(c) {
2164
+ if ("0" <= c && c <= "9") {
2165
+ return c.charCodeAt(0) - "0".charCodeAt(0);
2166
+ }
2167
+ throw "illegal char :" + c;
2168
+ };
2169
+ return _this;
2170
+ };
2171
+ qrAlphaNum = function(data) {
2172
+ const _mode = QRMode.MODE_ALPHA_NUM;
2173
+ const _data = data;
2174
+ const _this = {};
2175
+ _this.getMode = function() {
2176
+ return _mode;
2177
+ };
2178
+ _this.getLength = function(buffer) {
2179
+ return _data.length;
2180
+ };
2181
+ _this.write = function(buffer) {
2182
+ const s = _data;
2183
+ let i = 0;
2184
+ while (i + 1 < s.length) {
2185
+ buffer.put(
2186
+ getCode(s.charAt(i)) * 45 + getCode(s.charAt(i + 1)),
2187
+ 11
2188
+ );
2189
+ i += 2;
2190
+ }
2191
+ if (i < s.length) {
2192
+ buffer.put(getCode(s.charAt(i)), 6);
2193
+ }
2194
+ };
2195
+ const getCode = function(c) {
2196
+ if ("0" <= c && c <= "9") {
2197
+ return c.charCodeAt(0) - "0".charCodeAt(0);
2198
+ } else if ("A" <= c && c <= "Z") {
2199
+ return c.charCodeAt(0) - "A".charCodeAt(0) + 10;
2200
+ } else {
2201
+ switch (c) {
2202
+ case " ":
2203
+ return 36;
2204
+ case "$":
2205
+ return 37;
2206
+ case "%":
2207
+ return 38;
2208
+ case "*":
2209
+ return 39;
2210
+ case "+":
2211
+ return 40;
2212
+ case "-":
2213
+ return 41;
2214
+ case ".":
2215
+ return 42;
2216
+ case "/":
2217
+ return 43;
2218
+ case ":":
2219
+ return 44;
2220
+ default:
2221
+ throw "illegal char :" + c;
2222
+ }
2223
+ }
2224
+ };
2225
+ return _this;
2226
+ };
2227
+ qr8BitByte = function(data) {
2228
+ const _mode = QRMode.MODE_8BIT_BYTE;
2229
+ const _data = data;
2230
+ const _bytes = qrcode.stringToBytes(data);
2231
+ const _this = {};
2232
+ _this.getMode = function() {
2233
+ return _mode;
2234
+ };
2235
+ _this.getLength = function(buffer) {
2236
+ return _bytes.length;
2237
+ };
2238
+ _this.write = function(buffer) {
2239
+ for (let i = 0; i < _bytes.length; i += 1) {
2240
+ buffer.put(_bytes[i], 8);
2241
+ }
2242
+ };
2243
+ return _this;
2244
+ };
2245
+ qrKanji = function(data) {
2246
+ const _mode = QRMode.MODE_KANJI;
2247
+ const _data = data;
2248
+ const stringToBytes2 = qrcode.stringToBytes;
2249
+ !(function(c, code) {
2250
+ const test = stringToBytes2(c);
2251
+ if (test.length != 2 || (test[0] << 8 | test[1]) != code) {
2252
+ throw "sjis not supported.";
2253
+ }
2254
+ })("\u53CB", 38726);
2255
+ const _bytes = stringToBytes2(data);
2256
+ const _this = {};
2257
+ _this.getMode = function() {
2258
+ return _mode;
2259
+ };
2260
+ _this.getLength = function(buffer) {
2261
+ return ~~(_bytes.length / 2);
2262
+ };
2263
+ _this.write = function(buffer) {
2264
+ const data2 = _bytes;
2265
+ let i = 0;
2266
+ while (i + 1 < data2.length) {
2267
+ let c = (255 & data2[i]) << 8 | 255 & data2[i + 1];
2268
+ if (33088 <= c && c <= 40956) {
2269
+ c -= 33088;
2270
+ } else if (57408 <= c && c <= 60351) {
2271
+ c -= 49472;
2272
+ } else {
2273
+ throw "illegal char at " + (i + 1) + "/" + c;
2274
+ }
2275
+ c = (c >>> 8 & 255) * 192 + (c & 255);
2276
+ buffer.put(c, 13);
2277
+ i += 2;
2278
+ }
2279
+ if (i < data2.length) {
2280
+ throw "illegal char at " + (i + 1);
2281
+ }
2282
+ };
2283
+ return _this;
2284
+ };
2285
+ byteArrayOutputStream = function() {
2286
+ const _bytes = [];
2287
+ const _this = {};
2288
+ _this.writeByte = function(b) {
2289
+ _bytes.push(b & 255);
2290
+ };
2291
+ _this.writeShort = function(i) {
2292
+ _this.writeByte(i);
2293
+ _this.writeByte(i >>> 8);
2294
+ };
2295
+ _this.writeBytes = function(b, off, len) {
2296
+ off = off || 0;
2297
+ len = len || b.length;
2298
+ for (let i = 0; i < len; i += 1) {
2299
+ _this.writeByte(b[i + off]);
2300
+ }
2301
+ };
2302
+ _this.writeString = function(s) {
2303
+ for (let i = 0; i < s.length; i += 1) {
2304
+ _this.writeByte(s.charCodeAt(i));
2305
+ }
2306
+ };
2307
+ _this.toByteArray = function() {
2308
+ return _bytes;
2309
+ };
2310
+ _this.toString = function() {
2311
+ let s = "";
2312
+ s += "[";
2313
+ for (let i = 0; i < _bytes.length; i += 1) {
2314
+ if (i > 0) {
2315
+ s += ",";
2316
+ }
2317
+ s += _bytes[i];
2318
+ }
2319
+ s += "]";
2320
+ return s;
2321
+ };
2322
+ return _this;
2323
+ };
2324
+ base64EncodeOutputStream = function() {
2325
+ let _buffer = 0;
2326
+ let _buflen = 0;
2327
+ let _length = 0;
2328
+ let _base64 = "";
2329
+ const _this = {};
2330
+ const writeEncoded = function(b) {
2331
+ _base64 += String.fromCharCode(encode(b & 63));
2332
+ };
2333
+ const encode = function(n) {
2334
+ if (n < 0) {
2335
+ throw "n:" + n;
2336
+ } else if (n < 26) {
2337
+ return 65 + n;
2338
+ } else if (n < 52) {
2339
+ return 97 + (n - 26);
2340
+ } else if (n < 62) {
2341
+ return 48 + (n - 52);
2342
+ } else if (n == 62) {
2343
+ return 43;
2344
+ } else if (n == 63) {
2345
+ return 47;
2346
+ } else {
2347
+ throw "n:" + n;
2348
+ }
2349
+ };
2350
+ _this.writeByte = function(n) {
2351
+ _buffer = _buffer << 8 | n & 255;
2352
+ _buflen += 8;
2353
+ _length += 1;
2354
+ while (_buflen >= 6) {
2355
+ writeEncoded(_buffer >>> _buflen - 6);
2356
+ _buflen -= 6;
2357
+ }
2358
+ };
2359
+ _this.flush = function() {
2360
+ if (_buflen > 0) {
2361
+ writeEncoded(_buffer << 6 - _buflen);
2362
+ _buffer = 0;
2363
+ _buflen = 0;
2364
+ }
2365
+ if (_length % 3 != 0) {
2366
+ const padlen = 3 - _length % 3;
2367
+ for (let i = 0; i < padlen; i += 1) {
2368
+ _base64 += "=";
2369
+ }
2370
+ }
2371
+ };
2372
+ _this.toString = function() {
2373
+ return _base64;
2374
+ };
2375
+ return _this;
2376
+ };
2377
+ base64DecodeInputStream = function(str) {
2378
+ const _str = str;
2379
+ let _pos = 0;
2380
+ let _buffer = 0;
2381
+ let _buflen = 0;
2382
+ const _this = {};
2383
+ _this.read = function() {
2384
+ while (_buflen < 8) {
2385
+ if (_pos >= _str.length) {
2386
+ if (_buflen == 0) {
2387
+ return -1;
2388
+ }
2389
+ throw "unexpected end of file./" + _buflen;
2390
+ }
2391
+ const c = _str.charAt(_pos);
2392
+ _pos += 1;
2393
+ if (c == "=") {
2394
+ _buflen = 0;
2395
+ return -1;
2396
+ } else if (c.match(/^\s$/)) {
2397
+ continue;
2398
+ }
2399
+ _buffer = _buffer << 6 | decode(c.charCodeAt(0));
2400
+ _buflen += 6;
2401
+ }
2402
+ const n = _buffer >>> _buflen - 8 & 255;
2403
+ _buflen -= 8;
2404
+ return n;
2405
+ };
2406
+ const decode = function(c) {
2407
+ if (65 <= c && c <= 90) {
2408
+ return c - 65;
2409
+ } else if (97 <= c && c <= 122) {
2410
+ return c - 97 + 26;
2411
+ } else if (48 <= c && c <= 57) {
2412
+ return c - 48 + 52;
2413
+ } else if (c == 43) {
2414
+ return 62;
2415
+ } else if (c == 47) {
2416
+ return 63;
2417
+ } else {
2418
+ throw "c:" + c;
2419
+ }
2420
+ };
2421
+ return _this;
2422
+ };
2423
+ gifImage = function(width, height) {
2424
+ const _width = width;
2425
+ const _height = height;
2426
+ const _data = new Array(width * height);
2427
+ const _this = {};
2428
+ _this.setPixel = function(x, y, pixel) {
2429
+ _data[y * _width + x] = pixel;
2430
+ };
2431
+ _this.write = function(out) {
2432
+ out.writeString("GIF87a");
2433
+ out.writeShort(_width);
2434
+ out.writeShort(_height);
2435
+ out.writeByte(128);
2436
+ out.writeByte(0);
2437
+ out.writeByte(0);
2438
+ out.writeByte(0);
2439
+ out.writeByte(0);
2440
+ out.writeByte(0);
2441
+ out.writeByte(255);
2442
+ out.writeByte(255);
2443
+ out.writeByte(255);
2444
+ out.writeString(",");
2445
+ out.writeShort(0);
2446
+ out.writeShort(0);
2447
+ out.writeShort(_width);
2448
+ out.writeShort(_height);
2449
+ out.writeByte(0);
2450
+ const lzwMinCodeSize = 2;
2451
+ const raster = getLZWRaster(lzwMinCodeSize);
2452
+ out.writeByte(lzwMinCodeSize);
2453
+ let offset = 0;
2454
+ while (raster.length - offset > 255) {
2455
+ out.writeByte(255);
2456
+ out.writeBytes(raster, offset, 255);
2457
+ offset += 255;
2458
+ }
2459
+ out.writeByte(raster.length - offset);
2460
+ out.writeBytes(raster, offset, raster.length - offset);
2461
+ out.writeByte(0);
2462
+ out.writeString(";");
2463
+ };
2464
+ const bitOutputStream = function(out) {
2465
+ const _out = out;
2466
+ let _bitLength = 0;
2467
+ let _bitBuffer = 0;
2468
+ const _this2 = {};
2469
+ _this2.write = function(data, length) {
2470
+ if (data >>> length != 0) {
2471
+ throw "length over";
2472
+ }
2473
+ while (_bitLength + length >= 8) {
2474
+ _out.writeByte(255 & (data << _bitLength | _bitBuffer));
2475
+ length -= 8 - _bitLength;
2476
+ data >>>= 8 - _bitLength;
2477
+ _bitBuffer = 0;
2478
+ _bitLength = 0;
2479
+ }
2480
+ _bitBuffer = data << _bitLength | _bitBuffer;
2481
+ _bitLength = _bitLength + length;
2482
+ };
2483
+ _this2.flush = function() {
2484
+ if (_bitLength > 0) {
2485
+ _out.writeByte(_bitBuffer);
2486
+ }
2487
+ };
2488
+ return _this2;
2489
+ };
2490
+ const getLZWRaster = function(lzwMinCodeSize) {
2491
+ const clearCode = 1 << lzwMinCodeSize;
2492
+ const endCode = (1 << lzwMinCodeSize) + 1;
2493
+ let bitLength = lzwMinCodeSize + 1;
2494
+ const table = lzwTable();
2495
+ for (let i = 0; i < clearCode; i += 1) {
2496
+ table.add(String.fromCharCode(i));
2497
+ }
2498
+ table.add(String.fromCharCode(clearCode));
2499
+ table.add(String.fromCharCode(endCode));
2500
+ const byteOut = byteArrayOutputStream();
2501
+ const bitOut = bitOutputStream(byteOut);
2502
+ bitOut.write(clearCode, bitLength);
2503
+ let dataIndex = 0;
2504
+ let s = String.fromCharCode(_data[dataIndex]);
2505
+ dataIndex += 1;
2506
+ while (dataIndex < _data.length) {
2507
+ const c = String.fromCharCode(_data[dataIndex]);
2508
+ dataIndex += 1;
2509
+ if (table.contains(s + c)) {
2510
+ s = s + c;
2511
+ } else {
2512
+ bitOut.write(table.indexOf(s), bitLength);
2513
+ if (table.size() < 4095) {
2514
+ if (table.size() == 1 << bitLength) {
2515
+ bitLength += 1;
2516
+ }
2517
+ table.add(s + c);
2518
+ }
2519
+ s = c;
2520
+ }
2521
+ }
2522
+ bitOut.write(table.indexOf(s), bitLength);
2523
+ bitOut.write(endCode, bitLength);
2524
+ bitOut.flush();
2525
+ return byteOut.toByteArray();
2526
+ };
2527
+ const lzwTable = function() {
2528
+ const _map = {};
2529
+ let _size = 0;
2530
+ const _this2 = {};
2531
+ _this2.add = function(key) {
2532
+ if (_this2.contains(key)) {
2533
+ throw "dup key:" + key;
2534
+ }
2535
+ _map[key] = _size;
2536
+ _size += 1;
2537
+ };
2538
+ _this2.size = function() {
2539
+ return _size;
2540
+ };
2541
+ _this2.indexOf = function(key) {
2542
+ return _map[key];
2543
+ };
2544
+ _this2.contains = function(key) {
2545
+ return typeof _map[key] != "undefined";
2546
+ };
2547
+ return _this2;
2548
+ };
2549
+ return _this;
2550
+ };
2551
+ createDataURL = function(width, height, getPixel) {
2552
+ const gif = gifImage(width, height);
2553
+ for (let y = 0; y < height; y += 1) {
2554
+ for (let x = 0; x < width; x += 1) {
2555
+ gif.setPixel(x, y, getPixel(x, y));
2556
+ }
2557
+ }
2558
+ const b = byteArrayOutputStream();
2559
+ gif.write(b);
2560
+ const base64 = base64EncodeOutputStream();
2561
+ const bytes = b.toByteArray();
2562
+ for (let i = 0; i < bytes.length; i += 1) {
2563
+ base64.writeByte(bytes[i]);
2564
+ }
2565
+ base64.flush();
2566
+ return "data:image/gif;base64," + base64;
2567
+ };
2568
+ qrcode_default = qrcode;
2569
+ stringToBytes = qrcode.stringToBytes;
2570
+ }
2571
+ });
2572
+
2573
+ // src/components/qr.ts
2574
+ var qr_exports = {};
2575
+ __export(qr_exports, {
2576
+ qrPath: () => qrPath
2577
+ });
2578
+ function qrPath(value) {
2579
+ if (!value) return null;
2580
+ try {
2581
+ const qr = qrcode_default(0, "M");
2582
+ qr.addData(value);
2583
+ qr.make();
2584
+ const count = qr.getModuleCount();
2585
+ let d = "";
2586
+ for (let row = 0; row < count; row++) {
2587
+ for (let col = 0; col < count; col++) {
2588
+ if (qr.isDark(row, col)) d += `M${col} ${row}h1v1h-1z`;
2589
+ }
2590
+ }
2591
+ return { d, count };
2592
+ } catch {
2593
+ return null;
2594
+ }
1028
2595
  }
1029
- var React51;
1030
- var init_use_organization_list_resource = __esm({
1031
- "src/components/organization/use-organization-list-resource.ts"() {
2596
+ var init_qr = __esm({
2597
+ "src/components/qr.ts"() {
1032
2598
  "use strict";
1033
- "use client";
1034
- React51 = __toESM(require("react"), 1);
1035
- init_i18n();
2599
+ init_qrcode();
1036
2600
  }
1037
2601
  });
1038
2602
 
1039
- // src/components/organization/use-team-resources.ts
1040
- function useTeamsResource(organizationId) {
1041
- const api = useAuthClient().organization;
1042
- const apiRef = React52.useRef(api);
1043
- apiRef.current = api;
1044
- const t = useT();
1045
- const resource = useOrganizationListResource({
1046
- enabled: true,
1047
- resourceKey: organizationId,
1048
- request: () => apiRef.current.listTeams({ organizationId }),
1049
- fallback: t("organization.profile.loadError")
1050
- });
1051
- return { teams: resource.data, error: resource.error, reload: resource.refresh };
2603
+ // src/components/organization/model.ts
2604
+ function organizationSlugFromName(name) {
2605
+ return name.normalize("NFKD").toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 63);
1052
2606
  }
1053
- function useTeamMembersResource(selectedTeamId) {
1054
- const api = useAuthClient().organization;
1055
- const apiRef = React52.useRef(api);
1056
- apiRef.current = api;
1057
- const t = useT();
1058
- const resource = useOrganizationListResource({
1059
- enabled: selectedTeamId !== null,
1060
- resourceKey: selectedTeamId,
1061
- request: () => apiRef.current.listTeamMembers({ teamId: selectedTeamId }),
1062
- fallback: t("organization.profile.loadError")
2607
+ function organizationRoles(role) {
2608
+ return role.split(",").map((value) => value.trim()).filter(Boolean);
2609
+ }
2610
+ function hasOrganizationRole(member, role) {
2611
+ return member ? organizationRoles(member.role).includes(role) : false;
2612
+ }
2613
+ function canManageOrganization(member) {
2614
+ return hasOrganizationRole(member, "owner") || hasOrganizationRole(member, "admin");
2615
+ }
2616
+ function roleHasStatement(roles, heldRoles, resource, action) {
2617
+ return roles.some((role) => {
2618
+ if (!heldRoles.has(role.role) || typeof role.permission !== "object" || role.permission === null) {
2619
+ return false;
2620
+ }
2621
+ const actions = role.permission[resource];
2622
+ return Array.isArray(actions) && actions.includes(action);
1063
2623
  });
1064
- return { members: resource.data, error: resource.error, reload: resource.refresh };
1065
2624
  }
1066
- var React52;
1067
- var init_use_team_resources = __esm({
1068
- "src/components/organization/use-team-resources.ts"() {
2625
+ function teamManagementCapabilities(member, dynamicRoles) {
2626
+ const heldRoles = new Set(organizationRoles(member.role));
2627
+ if (heldRoles.has("owner") || heldRoles.has("admin")) {
2628
+ return {
2629
+ createTeam: true,
2630
+ updateTeam: true,
2631
+ deleteTeam: true,
2632
+ addTeamMember: true,
2633
+ removeTeamMember: true
2634
+ };
2635
+ }
2636
+ return {
2637
+ createTeam: roleHasStatement(dynamicRoles, heldRoles, "team", "create"),
2638
+ updateTeam: roleHasStatement(dynamicRoles, heldRoles, "team", "update"),
2639
+ deleteTeam: roleHasStatement(dynamicRoles, heldRoles, "team", "delete"),
2640
+ addTeamMember: roleHasStatement(dynamicRoles, heldRoles, "member", "update"),
2641
+ removeTeamMember: roleHasStatement(dynamicRoles, heldRoles, "member", "delete")
2642
+ };
2643
+ }
2644
+ var init_model = __esm({
2645
+ "src/components/organization/model.ts"() {
1069
2646
  "use strict";
1070
- "use client";
1071
- React52 = __toESM(require("react"), 1);
1072
- init_hooks();
1073
- init_i18n();
1074
- init_use_organization_list_resource();
1075
2647
  }
1076
2648
  });
1077
2649
 
1078
- // src/components/organization/TeamMembersPanel.tsx
1079
- function TeamMembersPanel({
2650
+ // src/components/organization/use-organization-roles.ts
2651
+ function useOrganizationRoles(organizationId) {
2652
+ const api = useAuthClient().organization;
2653
+ const apiRef = React49.useRef(api);
2654
+ apiRef.current = api;
2655
+ const [dynamicRoles, setDynamicRoles] = React49.useState([]);
2656
+ const requestRef = React49.useRef(0);
2657
+ React49.useEffect(() => {
2658
+ const token = ++requestRef.current;
2659
+ setDynamicRoles([]);
2660
+ if (!organizationId) return;
2661
+ void (async () => {
2662
+ try {
2663
+ const result = await apiRef.current.listRoles({ organizationId });
2664
+ if (token !== requestRef.current) return;
2665
+ setDynamicRoles((result.data ?? []).filter((entry) => entry.role.trim().length > 0));
2666
+ } catch {
2667
+ }
2668
+ })();
2669
+ return () => {
2670
+ requestRef.current += 1;
2671
+ };
2672
+ }, [organizationId]);
2673
+ const roles = React49.useMemo(() => {
2674
+ const seen = /* @__PURE__ */ new Set();
2675
+ const out = [];
2676
+ for (const candidate of [...BUILTIN_ROLES, ...dynamicRoles.map((entry) => entry.role)]) {
2677
+ const key = candidate.trim();
2678
+ if (!key || seen.has(key)) continue;
2679
+ seen.add(key);
2680
+ out.push(key);
2681
+ }
2682
+ return out;
2683
+ }, [dynamicRoles]);
2684
+ return { roles, dynamicRoles };
2685
+ }
2686
+ var React49, BUILTIN_ROLES;
2687
+ var init_use_organization_roles = __esm({
2688
+ "src/components/organization/use-organization-roles.ts"() {
2689
+ "use strict";
2690
+ "use client";
2691
+ React49 = __toESM(require("react"), 1);
2692
+ init_hooks();
2693
+ BUILTIN_ROLES = ["owner", "admin", "member"];
2694
+ }
2695
+ });
2696
+
2697
+ // src/components/organization/use-organization-list-resource.ts
2698
+ function useOrganizationListResource({
2699
+ enabled,
2700
+ resourceKey,
2701
+ request,
2702
+ fallback,
2703
+ inactiveData = null
2704
+ }) {
2705
+ const toServerError = useServerError();
2706
+ const requestFn = React51.useRef(request);
2707
+ requestFn.current = request;
2708
+ const [data, setData] = React51.useState(null);
2709
+ const [error, setError] = React51.useState(null);
2710
+ const requestToken = React51.useRef(0);
2711
+ const refresh = React51.useCallback(async () => {
2712
+ const token = ++requestToken.current;
2713
+ if (!enabled || !resourceKey) {
2714
+ setData(inactiveData);
2715
+ setError(null);
2716
+ return;
2717
+ }
2718
+ setError(null);
2719
+ try {
2720
+ const result = await requestFn.current();
2721
+ if (token !== requestToken.current) return;
2722
+ if (result.error) {
2723
+ setError(toServerError(result.error, fallback));
2724
+ return;
2725
+ }
2726
+ setData(result.data ?? []);
2727
+ } catch {
2728
+ if (token === requestToken.current) setError(fallback);
2729
+ }
2730
+ }, [enabled, fallback, inactiveData, resourceKey, toServerError]);
2731
+ React51.useEffect(() => {
2732
+ setData(enabled && resourceKey ? null : inactiveData);
2733
+ setError(null);
2734
+ void refresh();
2735
+ return () => {
2736
+ requestToken.current += 1;
2737
+ };
2738
+ }, [enabled, inactiveData, refresh, resourceKey]);
2739
+ return { data, isLoading: data === null && error === null, error, refresh };
2740
+ }
2741
+ var React51;
2742
+ var init_use_organization_list_resource = __esm({
2743
+ "src/components/organization/use-organization-list-resource.ts"() {
2744
+ "use strict";
2745
+ "use client";
2746
+ React51 = __toESM(require("react"), 1);
2747
+ init_i18n();
2748
+ }
2749
+ });
2750
+
2751
+ // src/components/organization/use-team-resources.ts
2752
+ function useTeamsResource(organizationId) {
2753
+ const api = useAuthClient().organization;
2754
+ const apiRef = React52.useRef(api);
2755
+ apiRef.current = api;
2756
+ const t = useT();
2757
+ const resource = useOrganizationListResource({
2758
+ enabled: true,
2759
+ resourceKey: organizationId,
2760
+ request: () => apiRef.current.listTeams({ organizationId }),
2761
+ fallback: t("organization.profile.loadError")
2762
+ });
2763
+ return { teams: resource.data, error: resource.error, reload: resource.refresh };
2764
+ }
2765
+ function useTeamMembersResource(selectedTeamId) {
2766
+ const api = useAuthClient().organization;
2767
+ const apiRef = React52.useRef(api);
2768
+ apiRef.current = api;
2769
+ const t = useT();
2770
+ const resource = useOrganizationListResource({
2771
+ enabled: selectedTeamId !== null,
2772
+ resourceKey: selectedTeamId,
2773
+ request: () => apiRef.current.listTeamMembers({ teamId: selectedTeamId }),
2774
+ fallback: t("organization.profile.loadError")
2775
+ });
2776
+ return { members: resource.data, error: resource.error, reload: resource.refresh };
2777
+ }
2778
+ var React52;
2779
+ var init_use_team_resources = __esm({
2780
+ "src/components/organization/use-team-resources.ts"() {
2781
+ "use strict";
2782
+ "use client";
2783
+ React52 = __toESM(require("react"), 1);
2784
+ init_hooks();
2785
+ init_i18n();
2786
+ init_use_organization_list_resource();
2787
+ }
2788
+ });
2789
+
2790
+ // src/components/organization/TeamMembersPanel.tsx
2791
+ function TeamMembersPanel({
1080
2792
  organization,
1081
2793
  team,
1082
2794
  canAdd,
@@ -1364,6 +3076,7 @@ __export(index_exports, {
1364
3076
  useAuthOwlContext: () => useAuthOwlContext,
1365
3077
  useConsent: () => useConsent,
1366
3078
  useEmailVerification: () => useEmailVerification,
3079
+ useInvitationRecipientHint: () => useInvitationRecipientHint,
1367
3080
  useLocale: () => useLocale,
1368
3081
  useMFA: () => useMFA,
1369
3082
  useOrganization: () => useOrganization,
@@ -1923,1880 +3636,239 @@ function useAuthChallenge() {
1923
3636
  };
1924
3637
  }
1925
3638
  },
1926
- [isLoading, tokenFor]
1927
- );
1928
- const control = siteKey ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "ba-auth-challenge", "data-testid": "auth-challenge", children: [
1929
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "ba-turnstile", ref: container }),
1930
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: "ba-sr-only", role: "status", "aria-live": "polite", children: status === "checking" ? t("authChallenge.checking") : status === "failed" ? t("authChallenge.error.failed") : "" })
1931
- ] }) : null;
1932
- return { run, control, configPending: isLoading };
1933
- }
1934
-
1935
- // src/components/ForgotPassword.tsx
1936
- init_FormError();
1937
- var import_jsx_runtime12 = require("react/jsx-runtime");
1938
- function ForgotPassword({ resetPasswordUrl, onBack }) {
1939
- const t = useT();
1940
- const { requestPasswordReset } = usePasswordReset();
1941
- const { pending, error, run } = useSubmitAction();
1942
- const authChallenge = useAuthChallenge();
1943
- const [email, setEmail] = React11.useState("");
1944
- const [sent, setSent] = React11.useState(false);
1945
- if (sent) {
1946
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "ba-fields", "data-testid": "forgot-sent", children: [
1947
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { className: "ba-muted", children: richMessage(t("forgotPassword.sent"), { email: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Bidi, { children: email }) }) }),
1948
- onBack && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("button", { type: "button", className: "ba-link-button", onClick: onBack, children: t("forgotPassword.backToSignIn") })
1949
- ] });
1950
- }
1951
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
1952
- "form",
1953
- {
1954
- method: "post",
1955
- className: "ba-fields",
1956
- "data-testid": "forgot-form",
1957
- onSubmit: (e) => {
1958
- e.preventDefault();
1959
- void run(() => authChallenge.run(AUTH_CHALLENGE_ACTIONS.reset, (options) => requestPasswordReset({ email, redirectTo: resetPasswordUrl }, options)), {
1960
- failure: t("forgotPassword.error.sendFailed"),
1961
- onSuccess: () => setSent(true)
1962
- });
1963
- },
1964
- children: [
1965
- /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("label", { className: "ba-label", children: [
1966
- t("common.emailLabel"),
1967
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1968
- "input",
1969
- {
1970
- className: "ba-input",
1971
- type: "email",
1972
- autoComplete: "email",
1973
- value: email,
1974
- onChange: (e) => setEmail(e.target.value),
1975
- required: true
1976
- }
1977
- )
1978
- ] }),
1979
- authChallenge.control,
1980
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(FormError, { children: error }),
1981
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1982
- "button",
1983
- {
1984
- className: "ba-button",
1985
- type: "submit",
1986
- disabled: pending || authChallenge.configPending,
1987
- "aria-busy": pending || void 0,
1988
- children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Busy, { busy: pending, label: t("common.sending"), children: t("forgotPassword.submit") })
1989
- }
1990
- ),
1991
- onBack && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("button", { type: "button", className: "ba-link-button", onClick: onBack, children: t("forgotPassword.backToSignIn") })
1992
- ]
1993
- }
1994
- );
1995
- }
1996
-
1997
- // src/components/OtpCodeForm.tsx
1998
- init_i18n();
1999
- init_Spinner();
2000
- init_FormError();
2001
- var import_jsx_runtime13 = require("react/jsx-runtime");
2002
- function OtpCodeForm({
2003
- email,
2004
- code,
2005
- onCodeChange,
2006
- onSubmit,
2007
- onChangeEmail,
2008
- pending,
2009
- error
2010
- }) {
2011
- const t = useT();
2012
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
2013
- "form",
2014
- {
2015
- method: "post",
2016
- className: "ba-fields",
2017
- "data-testid": "emailotp-code",
2018
- onSubmit: (e) => {
2019
- e.preventDefault();
2020
- onSubmit();
2021
- },
2022
- children: [
2023
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("label", { className: "ba-label", children: [
2024
- richMessage(t("emailOtp.codeLabel"), { email: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Bidi, { children: email }) }),
2025
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
2026
- "input",
2027
- {
2028
- className: "ba-input",
2029
- inputMode: "numeric",
2030
- autoComplete: "one-time-code",
2031
- value: code,
2032
- onChange: (e) => onCodeChange(e.target.value),
2033
- autoFocus: true,
2034
- required: true
2035
- }
2036
- )
2037
- ] }),
2038
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(FormError, { children: error }),
2039
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { className: "ba-button", type: "submit", disabled: pending, "aria-busy": pending || void 0, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Busy, { busy: pending, label: t("common.verifying"), children: t("emailOtp.verifySubmit") }) }),
2040
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { type: "button", className: "ba-link-button", onClick: onChangeEmail, children: t("emailOtp.changeEmail") })
2041
- ]
2042
- }
2043
- );
2044
- }
2045
-
2046
- // src/components/MFAChallenge.tsx
2047
- var React12 = __toESM(require("react"), 1);
2048
- init_hooks();
2049
- init_i18n();
2050
- init_use_submit_action();
2051
- init_Spinner();
2052
- init_FormError();
2053
- var import_jsx_runtime14 = require("react/jsx-runtime");
2054
- function MFAChallenge({ onVerified, allowTrustDevice = true }) {
2055
- const t = useT();
2056
- const { verifyTotp, verifyBackupCode, sendOtp, verifyOtp } = useMFA();
2057
- const { pending, error, setError, run } = useSubmitAction();
2058
- const [mode, setMode] = React12.useState("totp");
2059
- const [code, setCode] = React12.useState("");
2060
- const [trustDevice, setTrustDevice] = React12.useState(false);
2061
- const switchMode = (next) => {
2062
- setMode(next);
2063
- setCode("");
2064
- setError(null);
2065
- };
2066
- const requestOtp = () => void run(() => sendOtp({}), {
2067
- failure: t("mfa.challenge.error.otpSendFailed"),
2068
- onSuccess: () => {
2069
- setMode("otp");
2070
- setCode("");
2071
- }
2072
- });
2073
- const submit = (e) => {
2074
- e.preventDefault();
2075
- const action = mode === "totp" ? () => verifyTotp({ code, trustDevice }) : mode === "backup" ? () => verifyBackupCode({ code }) : () => verifyOtp({ code, trustDevice });
2076
- void run(action, {
2077
- failure: mode === "totp" ? t("mfa.challenge.error.invalidTotp") : mode === "backup" ? t("mfa.challenge.error.invalidBackup") : t("mfa.challenge.error.invalidOtp"),
2078
- onSuccess: () => onVerified?.()
2079
- });
2080
- };
2081
- const hint = mode === "totp" ? t("mfa.challenge.totpHint") : mode === "backup" ? t("mfa.challenge.backupHint") : t("mfa.challenge.otpHint");
2082
- const label2 = mode === "totp" ? t("mfa.challenge.totpLabel") : mode === "backup" ? t("mfa.challenge.backupLabel") : t("mfa.challenge.otpLabel");
2083
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("form", { method: "post", className: "ba-fields", "data-testid": "mfa-challenge", onSubmit: submit, children: [
2084
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("h2", { className: "ba-title", children: t("mfa.challenge.title") }),
2085
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("p", { className: "ba-muted", children: hint }),
2086
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("label", { className: "ba-label", children: [
2087
- label2,
2088
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2089
- "input",
2090
- {
2091
- className: "ba-input",
2092
- value: code,
2093
- onChange: (e) => {
2094
- setCode(e.target.value.trim());
2095
- setError(null);
2096
- },
2097
- inputMode: mode === "backup" ? "text" : "numeric",
2098
- autoComplete: "one-time-code",
2099
- autoFocus: true,
2100
- required: true
2101
- }
2102
- )
2103
- ] }),
2104
- mode !== "backup" && allowTrustDevice && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("label", { className: "ba-consent ba-consent-centered", children: [
2105
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("span", { className: "ba-checkbox-control", children: [
2106
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("input", { className: "ba-checkbox", type: "checkbox", checked: trustDevice, onChange: (e) => setTrustDevice(e.target.checked) }),
2107
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "ba-checkbox-visual", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "ba-checkbox-check" }) })
2108
- ] }),
2109
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { children: t("mfa.challenge.trustDevice", { days: 30 }) })
2110
- ] }),
2111
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(FormError, { children: error }),
2112
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { className: "ba-button", type: "submit", disabled: pending || !code, "aria-busy": pending || void 0, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Busy, { busy: pending, label: t("common.verifying"), children: t("mfa.challenge.submit") }) }),
2113
- mode !== "totp" && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "button", className: "ba-link-button", onClick: () => switchMode("totp"), children: t("mfa.challenge.useTotp") }),
2114
- mode !== "backup" && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "button", className: "ba-link-button", onClick: () => switchMode("backup"), children: t("mfa.challenge.useBackup") }),
2115
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "button", className: "ba-link-button", disabled: pending, onClick: requestOtp, children: t(mode === "otp" ? "mfa.challenge.resendOtp" : "mfa.challenge.useEmailOtp") })
2116
- ] });
2117
- }
2118
-
2119
- // src/components/mfa-enrollment-step.tsx
2120
- var React15 = __toESM(require("react"), 1);
2121
- init_hooks();
2122
- init_i18n();
2123
-
2124
- // src/components/MFAEnrollment.tsx
2125
- var React14 = __toESM(require("react"), 1);
2126
- init_hooks();
2127
- init_i18n();
2128
- init_use_submit_action();
2129
- init_Spinner();
2130
-
2131
- // src/components/mfa-enrollment.ts
2132
- function shouldDiscardSetup(args) {
2133
- const { isLoaded, hasSetup, setupOwnerId, currentUserId } = args;
2134
- return isLoaded && hasSetup && setupOwnerId !== currentUserId;
2135
- }
2136
-
2137
- // src/components/QrCode.tsx
2138
- var React13 = __toESM(require("react"), 1);
2139
- init_i18n();
2140
-
2141
- // ../../node_modules/.pnpm/qrcode-generator@2.0.4/node_modules/qrcode-generator/dist/qrcode.mjs
2142
- var qrcode = function(typeNumber, errorCorrectionLevel) {
2143
- const PAD0 = 236;
2144
- const PAD1 = 17;
2145
- let _typeNumber = typeNumber;
2146
- const _errorCorrectionLevel = QRErrorCorrectionLevel[errorCorrectionLevel];
2147
- let _modules = null;
2148
- let _moduleCount = 0;
2149
- let _dataCache = null;
2150
- const _dataList = [];
2151
- const _this = {};
2152
- const makeImpl = function(test, maskPattern) {
2153
- _moduleCount = _typeNumber * 4 + 17;
2154
- _modules = (function(moduleCount) {
2155
- const modules = new Array(moduleCount);
2156
- for (let row = 0; row < moduleCount; row += 1) {
2157
- modules[row] = new Array(moduleCount);
2158
- for (let col = 0; col < moduleCount; col += 1) {
2159
- modules[row][col] = null;
2160
- }
2161
- }
2162
- return modules;
2163
- })(_moduleCount);
2164
- setupPositionProbePattern(0, 0);
2165
- setupPositionProbePattern(_moduleCount - 7, 0);
2166
- setupPositionProbePattern(0, _moduleCount - 7);
2167
- setupPositionAdjustPattern();
2168
- setupTimingPattern();
2169
- setupTypeInfo(test, maskPattern);
2170
- if (_typeNumber >= 7) {
2171
- setupTypeNumber(test);
2172
- }
2173
- if (_dataCache == null) {
2174
- _dataCache = createData(_typeNumber, _errorCorrectionLevel, _dataList);
2175
- }
2176
- mapData(_dataCache, maskPattern);
2177
- };
2178
- const setupPositionProbePattern = function(row, col) {
2179
- for (let r = -1; r <= 7; r += 1) {
2180
- if (row + r <= -1 || _moduleCount <= row + r) continue;
2181
- for (let c = -1; c <= 7; c += 1) {
2182
- if (col + c <= -1 || _moduleCount <= col + c) continue;
2183
- 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) {
2184
- _modules[row + r][col + c] = true;
2185
- } else {
2186
- _modules[row + r][col + c] = false;
2187
- }
2188
- }
2189
- }
2190
- };
2191
- const getBestMaskPattern = function() {
2192
- let minLostPoint = 0;
2193
- let pattern = 0;
2194
- for (let i = 0; i < 8; i += 1) {
2195
- makeImpl(true, i);
2196
- const lostPoint = QRUtil.getLostPoint(_this);
2197
- if (i == 0 || minLostPoint > lostPoint) {
2198
- minLostPoint = lostPoint;
2199
- pattern = i;
2200
- }
2201
- }
2202
- return pattern;
2203
- };
2204
- const setupTimingPattern = function() {
2205
- for (let r = 8; r < _moduleCount - 8; r += 1) {
2206
- if (_modules[r][6] != null) {
2207
- continue;
2208
- }
2209
- _modules[r][6] = r % 2 == 0;
2210
- }
2211
- for (let c = 8; c < _moduleCount - 8; c += 1) {
2212
- if (_modules[6][c] != null) {
2213
- continue;
2214
- }
2215
- _modules[6][c] = c % 2 == 0;
2216
- }
2217
- };
2218
- const setupPositionAdjustPattern = function() {
2219
- const pos = QRUtil.getPatternPosition(_typeNumber);
2220
- for (let i = 0; i < pos.length; i += 1) {
2221
- for (let j = 0; j < pos.length; j += 1) {
2222
- const row = pos[i];
2223
- const col = pos[j];
2224
- if (_modules[row][col] != null) {
2225
- continue;
2226
- }
2227
- for (let r = -2; r <= 2; r += 1) {
2228
- for (let c = -2; c <= 2; c += 1) {
2229
- if (r == -2 || r == 2 || c == -2 || c == 2 || r == 0 && c == 0) {
2230
- _modules[row + r][col + c] = true;
2231
- } else {
2232
- _modules[row + r][col + c] = false;
2233
- }
2234
- }
2235
- }
2236
- }
2237
- }
2238
- };
2239
- const setupTypeNumber = function(test) {
2240
- const bits = QRUtil.getBCHTypeNumber(_typeNumber);
2241
- for (let i = 0; i < 18; i += 1) {
2242
- const mod = !test && (bits >> i & 1) == 1;
2243
- _modules[Math.floor(i / 3)][i % 3 + _moduleCount - 8 - 3] = mod;
2244
- }
2245
- for (let i = 0; i < 18; i += 1) {
2246
- const mod = !test && (bits >> i & 1) == 1;
2247
- _modules[i % 3 + _moduleCount - 8 - 3][Math.floor(i / 3)] = mod;
2248
- }
2249
- };
2250
- const setupTypeInfo = function(test, maskPattern) {
2251
- const data = _errorCorrectionLevel << 3 | maskPattern;
2252
- const bits = QRUtil.getBCHTypeInfo(data);
2253
- for (let i = 0; i < 15; i += 1) {
2254
- const mod = !test && (bits >> i & 1) == 1;
2255
- if (i < 6) {
2256
- _modules[i][8] = mod;
2257
- } else if (i < 8) {
2258
- _modules[i + 1][8] = mod;
2259
- } else {
2260
- _modules[_moduleCount - 15 + i][8] = mod;
2261
- }
2262
- }
2263
- for (let i = 0; i < 15; i += 1) {
2264
- const mod = !test && (bits >> i & 1) == 1;
2265
- if (i < 8) {
2266
- _modules[8][_moduleCount - i - 1] = mod;
2267
- } else if (i < 9) {
2268
- _modules[8][15 - i - 1 + 1] = mod;
2269
- } else {
2270
- _modules[8][15 - i - 1] = mod;
2271
- }
2272
- }
2273
- _modules[_moduleCount - 8][8] = !test;
2274
- };
2275
- const mapData = function(data, maskPattern) {
2276
- let inc = -1;
2277
- let row = _moduleCount - 1;
2278
- let bitIndex = 7;
2279
- let byteIndex = 0;
2280
- const maskFunc = QRUtil.getMaskFunction(maskPattern);
2281
- for (let col = _moduleCount - 1; col > 0; col -= 2) {
2282
- if (col == 6) col -= 1;
2283
- while (true) {
2284
- for (let c = 0; c < 2; c += 1) {
2285
- if (_modules[row][col - c] == null) {
2286
- let dark = false;
2287
- if (byteIndex < data.length) {
2288
- dark = (data[byteIndex] >>> bitIndex & 1) == 1;
2289
- }
2290
- const mask = maskFunc(row, col - c);
2291
- if (mask) {
2292
- dark = !dark;
2293
- }
2294
- _modules[row][col - c] = dark;
2295
- bitIndex -= 1;
2296
- if (bitIndex == -1) {
2297
- byteIndex += 1;
2298
- bitIndex = 7;
2299
- }
2300
- }
2301
- }
2302
- row += inc;
2303
- if (row < 0 || _moduleCount <= row) {
2304
- row -= inc;
2305
- inc = -inc;
2306
- break;
2307
- }
2308
- }
2309
- }
2310
- };
2311
- const createBytes = function(buffer, rsBlocks) {
2312
- let offset = 0;
2313
- let maxDcCount = 0;
2314
- let maxEcCount = 0;
2315
- const dcdata = new Array(rsBlocks.length);
2316
- const ecdata = new Array(rsBlocks.length);
2317
- for (let r = 0; r < rsBlocks.length; r += 1) {
2318
- const dcCount = rsBlocks[r].dataCount;
2319
- const ecCount = rsBlocks[r].totalCount - dcCount;
2320
- maxDcCount = Math.max(maxDcCount, dcCount);
2321
- maxEcCount = Math.max(maxEcCount, ecCount);
2322
- dcdata[r] = new Array(dcCount);
2323
- for (let i = 0; i < dcdata[r].length; i += 1) {
2324
- dcdata[r][i] = 255 & buffer.getBuffer()[i + offset];
2325
- }
2326
- offset += dcCount;
2327
- const rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
2328
- const rawPoly = qrPolynomial(dcdata[r], rsPoly.getLength() - 1);
2329
- const modPoly = rawPoly.mod(rsPoly);
2330
- ecdata[r] = new Array(rsPoly.getLength() - 1);
2331
- for (let i = 0; i < ecdata[r].length; i += 1) {
2332
- const modIndex = i + modPoly.getLength() - ecdata[r].length;
2333
- ecdata[r][i] = modIndex >= 0 ? modPoly.getAt(modIndex) : 0;
2334
- }
2335
- }
2336
- let totalCodeCount = 0;
2337
- for (let i = 0; i < rsBlocks.length; i += 1) {
2338
- totalCodeCount += rsBlocks[i].totalCount;
2339
- }
2340
- const data = new Array(totalCodeCount);
2341
- let index = 0;
2342
- for (let i = 0; i < maxDcCount; i += 1) {
2343
- for (let r = 0; r < rsBlocks.length; r += 1) {
2344
- if (i < dcdata[r].length) {
2345
- data[index] = dcdata[r][i];
2346
- index += 1;
2347
- }
2348
- }
2349
- }
2350
- for (let i = 0; i < maxEcCount; i += 1) {
2351
- for (let r = 0; r < rsBlocks.length; r += 1) {
2352
- if (i < ecdata[r].length) {
2353
- data[index] = ecdata[r][i];
2354
- index += 1;
2355
- }
2356
- }
2357
- }
2358
- return data;
2359
- };
2360
- const createData = function(typeNumber2, errorCorrectionLevel2, dataList) {
2361
- const rsBlocks = QRRSBlock.getRSBlocks(typeNumber2, errorCorrectionLevel2);
2362
- const buffer = qrBitBuffer();
2363
- for (let i = 0; i < dataList.length; i += 1) {
2364
- const data = dataList[i];
2365
- buffer.put(data.getMode(), 4);
2366
- buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber2));
2367
- data.write(buffer);
2368
- }
2369
- let totalDataCount = 0;
2370
- for (let i = 0; i < rsBlocks.length; i += 1) {
2371
- totalDataCount += rsBlocks[i].dataCount;
2372
- }
2373
- if (buffer.getLengthInBits() > totalDataCount * 8) {
2374
- throw "code length overflow. (" + buffer.getLengthInBits() + ">" + totalDataCount * 8 + ")";
2375
- }
2376
- if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) {
2377
- buffer.put(0, 4);
2378
- }
2379
- while (buffer.getLengthInBits() % 8 != 0) {
2380
- buffer.putBit(false);
2381
- }
2382
- while (true) {
2383
- if (buffer.getLengthInBits() >= totalDataCount * 8) {
2384
- break;
2385
- }
2386
- buffer.put(PAD0, 8);
2387
- if (buffer.getLengthInBits() >= totalDataCount * 8) {
2388
- break;
2389
- }
2390
- buffer.put(PAD1, 8);
2391
- }
2392
- return createBytes(buffer, rsBlocks);
2393
- };
2394
- _this.addData = function(data, mode) {
2395
- mode = mode || "Byte";
2396
- let newData = null;
2397
- switch (mode) {
2398
- case "Numeric":
2399
- newData = qrNumber(data);
2400
- break;
2401
- case "Alphanumeric":
2402
- newData = qrAlphaNum(data);
2403
- break;
2404
- case "Byte":
2405
- newData = qr8BitByte(data);
2406
- break;
2407
- case "Kanji":
2408
- newData = qrKanji(data);
2409
- break;
2410
- default:
2411
- throw "mode:" + mode;
2412
- }
2413
- _dataList.push(newData);
2414
- _dataCache = null;
2415
- };
2416
- _this.isDark = function(row, col) {
2417
- if (row < 0 || _moduleCount <= row || col < 0 || _moduleCount <= col) {
2418
- throw row + "," + col;
2419
- }
2420
- return _modules[row][col];
2421
- };
2422
- _this.getModuleCount = function() {
2423
- return _moduleCount;
2424
- };
2425
- _this.make = function() {
2426
- if (_typeNumber < 1) {
2427
- let typeNumber2 = 1;
2428
- for (; typeNumber2 < 40; typeNumber2++) {
2429
- const rsBlocks = QRRSBlock.getRSBlocks(typeNumber2, _errorCorrectionLevel);
2430
- const buffer = qrBitBuffer();
2431
- for (let i = 0; i < _dataList.length; i++) {
2432
- const data = _dataList[i];
2433
- buffer.put(data.getMode(), 4);
2434
- buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber2));
2435
- data.write(buffer);
2436
- }
2437
- let totalDataCount = 0;
2438
- for (let i = 0; i < rsBlocks.length; i++) {
2439
- totalDataCount += rsBlocks[i].dataCount;
2440
- }
2441
- if (buffer.getLengthInBits() <= totalDataCount * 8) {
2442
- break;
2443
- }
2444
- }
2445
- _typeNumber = typeNumber2;
2446
- }
2447
- makeImpl(false, getBestMaskPattern());
2448
- };
2449
- _this.createTableTag = function(cellSize, margin) {
2450
- cellSize = cellSize || 2;
2451
- margin = typeof margin == "undefined" ? cellSize * 4 : margin;
2452
- let qrHtml = "";
2453
- qrHtml += '<table style="';
2454
- qrHtml += " border-width: 0px; border-style: none;";
2455
- qrHtml += " border-collapse: collapse;";
2456
- qrHtml += " padding: 0px; margin: " + margin + "px;";
2457
- qrHtml += '">';
2458
- qrHtml += "<tbody>";
2459
- for (let r = 0; r < _this.getModuleCount(); r += 1) {
2460
- qrHtml += "<tr>";
2461
- for (let c = 0; c < _this.getModuleCount(); c += 1) {
2462
- qrHtml += '<td style="';
2463
- qrHtml += " border-width: 0px; border-style: none;";
2464
- qrHtml += " border-collapse: collapse;";
2465
- qrHtml += " padding: 0px; margin: 0px;";
2466
- qrHtml += " width: " + cellSize + "px;";
2467
- qrHtml += " height: " + cellSize + "px;";
2468
- qrHtml += " background-color: ";
2469
- qrHtml += _this.isDark(r, c) ? "#000000" : "#ffffff";
2470
- qrHtml += ";";
2471
- qrHtml += '"/>';
2472
- }
2473
- qrHtml += "</tr>";
2474
- }
2475
- qrHtml += "</tbody>";
2476
- qrHtml += "</table>";
2477
- return qrHtml;
2478
- };
2479
- _this.createSvgTag = function(cellSize, margin, alt, title) {
2480
- let opts = {};
2481
- if (typeof arguments[0] == "object") {
2482
- opts = arguments[0];
2483
- cellSize = opts.cellSize;
2484
- margin = opts.margin;
2485
- alt = opts.alt;
2486
- title = opts.title;
2487
- }
2488
- cellSize = cellSize || 2;
2489
- margin = typeof margin == "undefined" ? cellSize * 4 : margin;
2490
- alt = typeof alt === "string" ? { text: alt } : alt || {};
2491
- alt.text = alt.text || null;
2492
- alt.id = alt.text ? alt.id || "qrcode-description" : null;
2493
- title = typeof title === "string" ? { text: title } : title || {};
2494
- title.text = title.text || null;
2495
- title.id = title.text ? title.id || "qrcode-title" : null;
2496
- const size = _this.getModuleCount() * cellSize + margin * 2;
2497
- let c, mc, r, mr, qrSvg = "", rect;
2498
- rect = "l" + cellSize + ",0 0," + cellSize + " -" + cellSize + ",0 0,-" + cellSize + "z ";
2499
- qrSvg += '<svg version="1.1" xmlns="http://www.w3.org/2000/svg"';
2500
- qrSvg += !opts.scalable ? ' width="' + size + 'px" height="' + size + 'px"' : "";
2501
- qrSvg += ' viewBox="0 0 ' + size + " " + size + '" ';
2502
- qrSvg += ' preserveAspectRatio="xMinYMin meet"';
2503
- qrSvg += title.text || alt.text ? ' role="img" aria-labelledby="' + escapeXml([title.id, alt.id].join(" ").trim()) + '"' : "";
2504
- qrSvg += ">";
2505
- qrSvg += title.text ? '<title id="' + escapeXml(title.id) + '">' + escapeXml(title.text) + "</title>" : "";
2506
- qrSvg += alt.text ? '<description id="' + escapeXml(alt.id) + '">' + escapeXml(alt.text) + "</description>" : "";
2507
- qrSvg += '<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>';
2508
- qrSvg += '<path d="';
2509
- for (r = 0; r < _this.getModuleCount(); r += 1) {
2510
- mr = r * cellSize + margin;
2511
- for (c = 0; c < _this.getModuleCount(); c += 1) {
2512
- if (_this.isDark(r, c)) {
2513
- mc = c * cellSize + margin;
2514
- qrSvg += "M" + mc + "," + mr + rect;
2515
- }
2516
- }
2517
- }
2518
- qrSvg += '" stroke="transparent" fill="black"/>';
2519
- qrSvg += "</svg>";
2520
- return qrSvg;
2521
- };
2522
- _this.createDataURL = function(cellSize, margin) {
2523
- cellSize = cellSize || 2;
2524
- margin = typeof margin == "undefined" ? cellSize * 4 : margin;
2525
- const size = _this.getModuleCount() * cellSize + margin * 2;
2526
- const min = margin;
2527
- const max = size - margin;
2528
- return createDataURL(size, size, function(x, y) {
2529
- if (min <= x && x < max && min <= y && y < max) {
2530
- const c = Math.floor((x - min) / cellSize);
2531
- const r = Math.floor((y - min) / cellSize);
2532
- return _this.isDark(r, c) ? 0 : 1;
2533
- } else {
2534
- return 1;
2535
- }
2536
- });
2537
- };
2538
- _this.createImgTag = function(cellSize, margin, alt) {
2539
- cellSize = cellSize || 2;
2540
- margin = typeof margin == "undefined" ? cellSize * 4 : margin;
2541
- const size = _this.getModuleCount() * cellSize + margin * 2;
2542
- let img = "";
2543
- img += "<img";
2544
- img += ' src="';
2545
- img += _this.createDataURL(cellSize, margin);
2546
- img += '"';
2547
- img += ' width="';
2548
- img += size;
2549
- img += '"';
2550
- img += ' height="';
2551
- img += size;
2552
- img += '"';
2553
- if (alt) {
2554
- img += ' alt="';
2555
- img += escapeXml(alt);
2556
- img += '"';
2557
- }
2558
- img += "/>";
2559
- return img;
2560
- };
2561
- const escapeXml = function(s) {
2562
- let escaped = "";
2563
- for (let i = 0; i < s.length; i += 1) {
2564
- const c = s.charAt(i);
2565
- switch (c) {
2566
- case "<":
2567
- escaped += "&lt;";
2568
- break;
2569
- case ">":
2570
- escaped += "&gt;";
2571
- break;
2572
- case "&":
2573
- escaped += "&amp;";
2574
- break;
2575
- case '"':
2576
- escaped += "&quot;";
2577
- break;
2578
- default:
2579
- escaped += c;
2580
- break;
2581
- }
2582
- }
2583
- return escaped;
2584
- };
2585
- const _createHalfASCII = function(margin) {
2586
- const cellSize = 1;
2587
- margin = typeof margin == "undefined" ? cellSize * 2 : margin;
2588
- const size = _this.getModuleCount() * cellSize + margin * 2;
2589
- const min = margin;
2590
- const max = size - margin;
2591
- let y, x, r1, r2, p;
2592
- const blocks = {
2593
- "\u2588\u2588": "\u2588",
2594
- "\u2588 ": "\u2580",
2595
- " \u2588": "\u2584",
2596
- " ": " "
2597
- };
2598
- const blocksLastLineNoMargin = {
2599
- "\u2588\u2588": "\u2580",
2600
- "\u2588 ": "\u2580",
2601
- " \u2588": " ",
2602
- " ": " "
2603
- };
2604
- let ascii = "";
2605
- for (y = 0; y < size; y += 2) {
2606
- r1 = Math.floor((y - min) / cellSize);
2607
- r2 = Math.floor((y + 1 - min) / cellSize);
2608
- for (x = 0; x < size; x += 1) {
2609
- p = "\u2588";
2610
- if (min <= x && x < max && min <= y && y < max && _this.isDark(r1, Math.floor((x - min) / cellSize))) {
2611
- p = " ";
2612
- }
2613
- if (min <= x && x < max && min <= y + 1 && y + 1 < max && _this.isDark(r2, Math.floor((x - min) / cellSize))) {
2614
- p += " ";
2615
- } else {
2616
- p += "\u2588";
2617
- }
2618
- ascii += margin < 1 && y + 1 >= max ? blocksLastLineNoMargin[p] : blocks[p];
2619
- }
2620
- ascii += "\n";
2621
- }
2622
- if (size % 2 && margin > 0) {
2623
- return ascii.substring(0, ascii.length - size - 1) + Array(size + 1).join("\u2580");
2624
- }
2625
- return ascii.substring(0, ascii.length - 1);
2626
- };
2627
- _this.createASCII = function(cellSize, margin) {
2628
- cellSize = cellSize || 1;
2629
- if (cellSize < 2) {
2630
- return _createHalfASCII(margin);
2631
- }
2632
- cellSize -= 1;
2633
- margin = typeof margin == "undefined" ? cellSize * 2 : margin;
2634
- const size = _this.getModuleCount() * cellSize + margin * 2;
2635
- const min = margin;
2636
- const max = size - margin;
2637
- let y, x, r, p;
2638
- const white = Array(cellSize + 1).join("\u2588\u2588");
2639
- const black = Array(cellSize + 1).join(" ");
2640
- let ascii = "";
2641
- let line = "";
2642
- for (y = 0; y < size; y += 1) {
2643
- r = Math.floor((y - min) / cellSize);
2644
- line = "";
2645
- for (x = 0; x < size; x += 1) {
2646
- p = 1;
2647
- if (min <= x && x < max && min <= y && y < max && _this.isDark(r, Math.floor((x - min) / cellSize))) {
2648
- p = 0;
2649
- }
2650
- line += p ? white : black;
2651
- }
2652
- for (r = 0; r < cellSize; r += 1) {
2653
- ascii += line + "\n";
2654
- }
2655
- }
2656
- return ascii.substring(0, ascii.length - 1);
2657
- };
2658
- _this.renderTo2dContext = function(context, cellSize) {
2659
- cellSize = cellSize || 2;
2660
- const length = _this.getModuleCount();
2661
- for (let row = 0; row < length; row++) {
2662
- for (let col = 0; col < length; col++) {
2663
- context.fillStyle = _this.isDark(row, col) ? "black" : "white";
2664
- context.fillRect(col * cellSize, row * cellSize, cellSize, cellSize);
2665
- }
2666
- }
2667
- };
2668
- return _this;
2669
- };
2670
- qrcode.stringToBytes = function(s) {
2671
- const bytes = [];
2672
- for (let i = 0; i < s.length; i += 1) {
2673
- const c = s.charCodeAt(i);
2674
- bytes.push(c & 255);
2675
- }
2676
- return bytes;
2677
- };
2678
- qrcode.createStringToBytes = function(unicodeData, numChars) {
2679
- const unicodeMap = (function() {
2680
- const bin = base64DecodeInputStream(unicodeData);
2681
- const read = function() {
2682
- const b = bin.read();
2683
- if (b == -1) throw "eof";
2684
- return b;
2685
- };
2686
- let count = 0;
2687
- const unicodeMap2 = {};
2688
- while (true) {
2689
- const b0 = bin.read();
2690
- if (b0 == -1) break;
2691
- const b1 = read();
2692
- const b2 = read();
2693
- const b3 = read();
2694
- const k = String.fromCharCode(b0 << 8 | b1);
2695
- const v = b2 << 8 | b3;
2696
- unicodeMap2[k] = v;
2697
- count += 1;
2698
- }
2699
- if (count != numChars) {
2700
- throw count + " != " + numChars;
2701
- }
2702
- return unicodeMap2;
2703
- })();
2704
- const unknownChar = "?".charCodeAt(0);
2705
- return function(s) {
2706
- const bytes = [];
2707
- for (let i = 0; i < s.length; i += 1) {
2708
- const c = s.charCodeAt(i);
2709
- if (c < 128) {
2710
- bytes.push(c);
2711
- } else {
2712
- const b = unicodeMap[s.charAt(i)];
2713
- if (typeof b == "number") {
2714
- if ((b & 255) == b) {
2715
- bytes.push(b);
2716
- } else {
2717
- bytes.push(b >>> 8);
2718
- bytes.push(b & 255);
2719
- }
2720
- } else {
2721
- bytes.push(unknownChar);
2722
- }
2723
- }
2724
- }
2725
- return bytes;
2726
- };
2727
- };
2728
- var QRMode = {
2729
- MODE_NUMBER: 1 << 0,
2730
- MODE_ALPHA_NUM: 1 << 1,
2731
- MODE_8BIT_BYTE: 1 << 2,
2732
- MODE_KANJI: 1 << 3
2733
- };
2734
- var QRErrorCorrectionLevel = {
2735
- L: 1,
2736
- M: 0,
2737
- Q: 3,
2738
- H: 2
2739
- };
2740
- var QRMaskPattern = {
2741
- PATTERN000: 0,
2742
- PATTERN001: 1,
2743
- PATTERN010: 2,
2744
- PATTERN011: 3,
2745
- PATTERN100: 4,
2746
- PATTERN101: 5,
2747
- PATTERN110: 6,
2748
- PATTERN111: 7
2749
- };
2750
- var QRUtil = (function() {
2751
- const PATTERN_POSITION_TABLE = [
2752
- [],
2753
- [6, 18],
2754
- [6, 22],
2755
- [6, 26],
2756
- [6, 30],
2757
- [6, 34],
2758
- [6, 22, 38],
2759
- [6, 24, 42],
2760
- [6, 26, 46],
2761
- [6, 28, 50],
2762
- [6, 30, 54],
2763
- [6, 32, 58],
2764
- [6, 34, 62],
2765
- [6, 26, 46, 66],
2766
- [6, 26, 48, 70],
2767
- [6, 26, 50, 74],
2768
- [6, 30, 54, 78],
2769
- [6, 30, 56, 82],
2770
- [6, 30, 58, 86],
2771
- [6, 34, 62, 90],
2772
- [6, 28, 50, 72, 94],
2773
- [6, 26, 50, 74, 98],
2774
- [6, 30, 54, 78, 102],
2775
- [6, 28, 54, 80, 106],
2776
- [6, 32, 58, 84, 110],
2777
- [6, 30, 58, 86, 114],
2778
- [6, 34, 62, 90, 118],
2779
- [6, 26, 50, 74, 98, 122],
2780
- [6, 30, 54, 78, 102, 126],
2781
- [6, 26, 52, 78, 104, 130],
2782
- [6, 30, 56, 82, 108, 134],
2783
- [6, 34, 60, 86, 112, 138],
2784
- [6, 30, 58, 86, 114, 142],
2785
- [6, 34, 62, 90, 118, 146],
2786
- [6, 30, 54, 78, 102, 126, 150],
2787
- [6, 24, 50, 76, 102, 128, 154],
2788
- [6, 28, 54, 80, 106, 132, 158],
2789
- [6, 32, 58, 84, 110, 136, 162],
2790
- [6, 26, 54, 82, 110, 138, 166],
2791
- [6, 30, 58, 86, 114, 142, 170]
2792
- ];
2793
- const G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0;
2794
- const G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0;
2795
- const G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;
2796
- const _this = {};
2797
- const getBCHDigit = function(data) {
2798
- let digit = 0;
2799
- while (data != 0) {
2800
- digit += 1;
2801
- data >>>= 1;
2802
- }
2803
- return digit;
2804
- };
2805
- _this.getBCHTypeInfo = function(data) {
2806
- let d = data << 10;
2807
- while (getBCHDigit(d) - getBCHDigit(G15) >= 0) {
2808
- d ^= G15 << getBCHDigit(d) - getBCHDigit(G15);
2809
- }
2810
- return (data << 10 | d) ^ G15_MASK;
2811
- };
2812
- _this.getBCHTypeNumber = function(data) {
2813
- let d = data << 12;
2814
- while (getBCHDigit(d) - getBCHDigit(G18) >= 0) {
2815
- d ^= G18 << getBCHDigit(d) - getBCHDigit(G18);
2816
- }
2817
- return data << 12 | d;
2818
- };
2819
- _this.getPatternPosition = function(typeNumber) {
2820
- return PATTERN_POSITION_TABLE[typeNumber - 1];
2821
- };
2822
- _this.getMaskFunction = function(maskPattern) {
2823
- switch (maskPattern) {
2824
- case QRMaskPattern.PATTERN000:
2825
- return function(i, j) {
2826
- return (i + j) % 2 == 0;
2827
- };
2828
- case QRMaskPattern.PATTERN001:
2829
- return function(i, j) {
2830
- return i % 2 == 0;
2831
- };
2832
- case QRMaskPattern.PATTERN010:
2833
- return function(i, j) {
2834
- return j % 3 == 0;
2835
- };
2836
- case QRMaskPattern.PATTERN011:
2837
- return function(i, j) {
2838
- return (i + j) % 3 == 0;
2839
- };
2840
- case QRMaskPattern.PATTERN100:
2841
- return function(i, j) {
2842
- return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0;
2843
- };
2844
- case QRMaskPattern.PATTERN101:
2845
- return function(i, j) {
2846
- return i * j % 2 + i * j % 3 == 0;
2847
- };
2848
- case QRMaskPattern.PATTERN110:
2849
- return function(i, j) {
2850
- return (i * j % 2 + i * j % 3) % 2 == 0;
2851
- };
2852
- case QRMaskPattern.PATTERN111:
2853
- return function(i, j) {
2854
- return (i * j % 3 + (i + j) % 2) % 2 == 0;
2855
- };
2856
- default:
2857
- throw "bad maskPattern:" + maskPattern;
2858
- }
2859
- };
2860
- _this.getErrorCorrectPolynomial = function(errorCorrectLength) {
2861
- let a = qrPolynomial([1], 0);
2862
- for (let i = 0; i < errorCorrectLength; i += 1) {
2863
- a = a.multiply(qrPolynomial([1, QRMath.gexp(i)], 0));
2864
- }
2865
- return a;
2866
- };
2867
- _this.getLengthInBits = function(mode, type) {
2868
- if (1 <= type && type < 10) {
2869
- switch (mode) {
2870
- case QRMode.MODE_NUMBER:
2871
- return 10;
2872
- case QRMode.MODE_ALPHA_NUM:
2873
- return 9;
2874
- case QRMode.MODE_8BIT_BYTE:
2875
- return 8;
2876
- case QRMode.MODE_KANJI:
2877
- return 8;
2878
- default:
2879
- throw "mode:" + mode;
2880
- }
2881
- } else if (type < 27) {
2882
- switch (mode) {
2883
- case QRMode.MODE_NUMBER:
2884
- return 12;
2885
- case QRMode.MODE_ALPHA_NUM:
2886
- return 11;
2887
- case QRMode.MODE_8BIT_BYTE:
2888
- return 16;
2889
- case QRMode.MODE_KANJI:
2890
- return 10;
2891
- default:
2892
- throw "mode:" + mode;
2893
- }
2894
- } else if (type < 41) {
2895
- switch (mode) {
2896
- case QRMode.MODE_NUMBER:
2897
- return 14;
2898
- case QRMode.MODE_ALPHA_NUM:
2899
- return 13;
2900
- case QRMode.MODE_8BIT_BYTE:
2901
- return 16;
2902
- case QRMode.MODE_KANJI:
2903
- return 12;
2904
- default:
2905
- throw "mode:" + mode;
2906
- }
2907
- } else {
2908
- throw "type:" + type;
2909
- }
2910
- };
2911
- _this.getLostPoint = function(qrcode2) {
2912
- const moduleCount = qrcode2.getModuleCount();
2913
- let lostPoint = 0;
2914
- for (let row = 0; row < moduleCount; row += 1) {
2915
- for (let col = 0; col < moduleCount; col += 1) {
2916
- let sameCount = 0;
2917
- const dark = qrcode2.isDark(row, col);
2918
- for (let r = -1; r <= 1; r += 1) {
2919
- if (row + r < 0 || moduleCount <= row + r) {
2920
- continue;
2921
- }
2922
- for (let c = -1; c <= 1; c += 1) {
2923
- if (col + c < 0 || moduleCount <= col + c) {
2924
- continue;
2925
- }
2926
- if (r == 0 && c == 0) {
2927
- continue;
2928
- }
2929
- if (dark == qrcode2.isDark(row + r, col + c)) {
2930
- sameCount += 1;
2931
- }
2932
- }
2933
- }
2934
- if (sameCount > 5) {
2935
- lostPoint += 3 + sameCount - 5;
2936
- }
2937
- }
2938
- }
2939
- ;
2940
- for (let row = 0; row < moduleCount - 1; row += 1) {
2941
- for (let col = 0; col < moduleCount - 1; col += 1) {
2942
- let count = 0;
2943
- if (qrcode2.isDark(row, col)) count += 1;
2944
- if (qrcode2.isDark(row + 1, col)) count += 1;
2945
- if (qrcode2.isDark(row, col + 1)) count += 1;
2946
- if (qrcode2.isDark(row + 1, col + 1)) count += 1;
2947
- if (count == 0 || count == 4) {
2948
- lostPoint += 3;
2949
- }
2950
- }
2951
- }
2952
- for (let row = 0; row < moduleCount; row += 1) {
2953
- for (let col = 0; col < moduleCount - 6; col += 1) {
2954
- if (qrcode2.isDark(row, col) && !qrcode2.isDark(row, col + 1) && qrcode2.isDark(row, col + 2) && qrcode2.isDark(row, col + 3) && qrcode2.isDark(row, col + 4) && !qrcode2.isDark(row, col + 5) && qrcode2.isDark(row, col + 6)) {
2955
- lostPoint += 40;
2956
- }
2957
- }
2958
- }
2959
- for (let col = 0; col < moduleCount; col += 1) {
2960
- for (let row = 0; row < moduleCount - 6; row += 1) {
2961
- if (qrcode2.isDark(row, col) && !qrcode2.isDark(row + 1, col) && qrcode2.isDark(row + 2, col) && qrcode2.isDark(row + 3, col) && qrcode2.isDark(row + 4, col) && !qrcode2.isDark(row + 5, col) && qrcode2.isDark(row + 6, col)) {
2962
- lostPoint += 40;
2963
- }
2964
- }
2965
- }
2966
- let darkCount = 0;
2967
- for (let col = 0; col < moduleCount; col += 1) {
2968
- for (let row = 0; row < moduleCount; row += 1) {
2969
- if (qrcode2.isDark(row, col)) {
2970
- darkCount += 1;
2971
- }
2972
- }
2973
- }
2974
- const ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
2975
- lostPoint += ratio * 10;
2976
- return lostPoint;
2977
- };
2978
- return _this;
2979
- })();
2980
- var QRMath = (function() {
2981
- const EXP_TABLE = new Array(256);
2982
- const LOG_TABLE = new Array(256);
2983
- for (let i = 0; i < 8; i += 1) {
2984
- EXP_TABLE[i] = 1 << i;
2985
- }
2986
- for (let i = 8; i < 256; i += 1) {
2987
- EXP_TABLE[i] = EXP_TABLE[i - 4] ^ EXP_TABLE[i - 5] ^ EXP_TABLE[i - 6] ^ EXP_TABLE[i - 8];
2988
- }
2989
- for (let i = 0; i < 255; i += 1) {
2990
- LOG_TABLE[EXP_TABLE[i]] = i;
2991
- }
2992
- const _this = {};
2993
- _this.glog = function(n) {
2994
- if (n < 1) {
2995
- throw "glog(" + n + ")";
2996
- }
2997
- return LOG_TABLE[n];
2998
- };
2999
- _this.gexp = function(n) {
3000
- while (n < 0) {
3001
- n += 255;
3002
- }
3003
- while (n >= 256) {
3004
- n -= 255;
3005
- }
3006
- return EXP_TABLE[n];
3007
- };
3008
- return _this;
3009
- })();
3010
- var qrPolynomial = function(num, shift) {
3011
- if (typeof num.length == "undefined") {
3012
- throw num.length + "/" + shift;
3013
- }
3014
- const _num = (function() {
3015
- let offset = 0;
3016
- while (offset < num.length && num[offset] == 0) {
3017
- offset += 1;
3018
- }
3019
- const _num2 = new Array(num.length - offset + shift);
3020
- for (let i = 0; i < num.length - offset; i += 1) {
3021
- _num2[i] = num[i + offset];
3022
- }
3023
- return _num2;
3024
- })();
3025
- const _this = {};
3026
- _this.getAt = function(index) {
3027
- return _num[index];
3028
- };
3029
- _this.getLength = function() {
3030
- return _num.length;
3031
- };
3032
- _this.multiply = function(e) {
3033
- const num2 = new Array(_this.getLength() + e.getLength() - 1);
3034
- for (let i = 0; i < _this.getLength(); i += 1) {
3035
- for (let j = 0; j < e.getLength(); j += 1) {
3036
- num2[i + j] ^= QRMath.gexp(QRMath.glog(_this.getAt(i)) + QRMath.glog(e.getAt(j)));
3037
- }
3038
- }
3039
- return qrPolynomial(num2, 0);
3040
- };
3041
- _this.mod = function(e) {
3042
- if (_this.getLength() - e.getLength() < 0) {
3043
- return _this;
3044
- }
3045
- const ratio = QRMath.glog(_this.getAt(0)) - QRMath.glog(e.getAt(0));
3046
- const num2 = new Array(_this.getLength());
3047
- for (let i = 0; i < _this.getLength(); i += 1) {
3048
- num2[i] = _this.getAt(i);
3049
- }
3050
- for (let i = 0; i < e.getLength(); i += 1) {
3051
- num2[i] ^= QRMath.gexp(QRMath.glog(e.getAt(i)) + ratio);
3052
- }
3053
- return qrPolynomial(num2, 0).mod(e);
3054
- };
3055
- return _this;
3056
- };
3057
- var QRRSBlock = (function() {
3058
- const RS_BLOCK_TABLE = [
3059
- // L
3060
- // M
3061
- // Q
3062
- // H
3063
- // 1
3064
- [1, 26, 19],
3065
- [1, 26, 16],
3066
- [1, 26, 13],
3067
- [1, 26, 9],
3068
- // 2
3069
- [1, 44, 34],
3070
- [1, 44, 28],
3071
- [1, 44, 22],
3072
- [1, 44, 16],
3073
- // 3
3074
- [1, 70, 55],
3075
- [1, 70, 44],
3076
- [2, 35, 17],
3077
- [2, 35, 13],
3078
- // 4
3079
- [1, 100, 80],
3080
- [2, 50, 32],
3081
- [2, 50, 24],
3082
- [4, 25, 9],
3083
- // 5
3084
- [1, 134, 108],
3085
- [2, 67, 43],
3086
- [2, 33, 15, 2, 34, 16],
3087
- [2, 33, 11, 2, 34, 12],
3088
- // 6
3089
- [2, 86, 68],
3090
- [4, 43, 27],
3091
- [4, 43, 19],
3092
- [4, 43, 15],
3093
- // 7
3094
- [2, 98, 78],
3095
- [4, 49, 31],
3096
- [2, 32, 14, 4, 33, 15],
3097
- [4, 39, 13, 1, 40, 14],
3098
- // 8
3099
- [2, 121, 97],
3100
- [2, 60, 38, 2, 61, 39],
3101
- [4, 40, 18, 2, 41, 19],
3102
- [4, 40, 14, 2, 41, 15],
3103
- // 9
3104
- [2, 146, 116],
3105
- [3, 58, 36, 2, 59, 37],
3106
- [4, 36, 16, 4, 37, 17],
3107
- [4, 36, 12, 4, 37, 13],
3108
- // 10
3109
- [2, 86, 68, 2, 87, 69],
3110
- [4, 69, 43, 1, 70, 44],
3111
- [6, 43, 19, 2, 44, 20],
3112
- [6, 43, 15, 2, 44, 16],
3113
- // 11
3114
- [4, 101, 81],
3115
- [1, 80, 50, 4, 81, 51],
3116
- [4, 50, 22, 4, 51, 23],
3117
- [3, 36, 12, 8, 37, 13],
3118
- // 12
3119
- [2, 116, 92, 2, 117, 93],
3120
- [6, 58, 36, 2, 59, 37],
3121
- [4, 46, 20, 6, 47, 21],
3122
- [7, 42, 14, 4, 43, 15],
3123
- // 13
3124
- [4, 133, 107],
3125
- [8, 59, 37, 1, 60, 38],
3126
- [8, 44, 20, 4, 45, 21],
3127
- [12, 33, 11, 4, 34, 12],
3128
- // 14
3129
- [3, 145, 115, 1, 146, 116],
3130
- [4, 64, 40, 5, 65, 41],
3131
- [11, 36, 16, 5, 37, 17],
3132
- [11, 36, 12, 5, 37, 13],
3133
- // 15
3134
- [5, 109, 87, 1, 110, 88],
3135
- [5, 65, 41, 5, 66, 42],
3136
- [5, 54, 24, 7, 55, 25],
3137
- [11, 36, 12, 7, 37, 13],
3138
- // 16
3139
- [5, 122, 98, 1, 123, 99],
3140
- [7, 73, 45, 3, 74, 46],
3141
- [15, 43, 19, 2, 44, 20],
3142
- [3, 45, 15, 13, 46, 16],
3143
- // 17
3144
- [1, 135, 107, 5, 136, 108],
3145
- [10, 74, 46, 1, 75, 47],
3146
- [1, 50, 22, 15, 51, 23],
3147
- [2, 42, 14, 17, 43, 15],
3148
- // 18
3149
- [5, 150, 120, 1, 151, 121],
3150
- [9, 69, 43, 4, 70, 44],
3151
- [17, 50, 22, 1, 51, 23],
3152
- [2, 42, 14, 19, 43, 15],
3153
- // 19
3154
- [3, 141, 113, 4, 142, 114],
3155
- [3, 70, 44, 11, 71, 45],
3156
- [17, 47, 21, 4, 48, 22],
3157
- [9, 39, 13, 16, 40, 14],
3158
- // 20
3159
- [3, 135, 107, 5, 136, 108],
3160
- [3, 67, 41, 13, 68, 42],
3161
- [15, 54, 24, 5, 55, 25],
3162
- [15, 43, 15, 10, 44, 16],
3163
- // 21
3164
- [4, 144, 116, 4, 145, 117],
3165
- [17, 68, 42],
3166
- [17, 50, 22, 6, 51, 23],
3167
- [19, 46, 16, 6, 47, 17],
3168
- // 22
3169
- [2, 139, 111, 7, 140, 112],
3170
- [17, 74, 46],
3171
- [7, 54, 24, 16, 55, 25],
3172
- [34, 37, 13],
3173
- // 23
3174
- [4, 151, 121, 5, 152, 122],
3175
- [4, 75, 47, 14, 76, 48],
3176
- [11, 54, 24, 14, 55, 25],
3177
- [16, 45, 15, 14, 46, 16],
3178
- // 24
3179
- [6, 147, 117, 4, 148, 118],
3180
- [6, 73, 45, 14, 74, 46],
3181
- [11, 54, 24, 16, 55, 25],
3182
- [30, 46, 16, 2, 47, 17],
3183
- // 25
3184
- [8, 132, 106, 4, 133, 107],
3185
- [8, 75, 47, 13, 76, 48],
3186
- [7, 54, 24, 22, 55, 25],
3187
- [22, 45, 15, 13, 46, 16],
3188
- // 26
3189
- [10, 142, 114, 2, 143, 115],
3190
- [19, 74, 46, 4, 75, 47],
3191
- [28, 50, 22, 6, 51, 23],
3192
- [33, 46, 16, 4, 47, 17],
3193
- // 27
3194
- [8, 152, 122, 4, 153, 123],
3195
- [22, 73, 45, 3, 74, 46],
3196
- [8, 53, 23, 26, 54, 24],
3197
- [12, 45, 15, 28, 46, 16],
3198
- // 28
3199
- [3, 147, 117, 10, 148, 118],
3200
- [3, 73, 45, 23, 74, 46],
3201
- [4, 54, 24, 31, 55, 25],
3202
- [11, 45, 15, 31, 46, 16],
3203
- // 29
3204
- [7, 146, 116, 7, 147, 117],
3205
- [21, 73, 45, 7, 74, 46],
3206
- [1, 53, 23, 37, 54, 24],
3207
- [19, 45, 15, 26, 46, 16],
3208
- // 30
3209
- [5, 145, 115, 10, 146, 116],
3210
- [19, 75, 47, 10, 76, 48],
3211
- [15, 54, 24, 25, 55, 25],
3212
- [23, 45, 15, 25, 46, 16],
3213
- // 31
3214
- [13, 145, 115, 3, 146, 116],
3215
- [2, 74, 46, 29, 75, 47],
3216
- [42, 54, 24, 1, 55, 25],
3217
- [23, 45, 15, 28, 46, 16],
3218
- // 32
3219
- [17, 145, 115],
3220
- [10, 74, 46, 23, 75, 47],
3221
- [10, 54, 24, 35, 55, 25],
3222
- [19, 45, 15, 35, 46, 16],
3223
- // 33
3224
- [17, 145, 115, 1, 146, 116],
3225
- [14, 74, 46, 21, 75, 47],
3226
- [29, 54, 24, 19, 55, 25],
3227
- [11, 45, 15, 46, 46, 16],
3228
- // 34
3229
- [13, 145, 115, 6, 146, 116],
3230
- [14, 74, 46, 23, 75, 47],
3231
- [44, 54, 24, 7, 55, 25],
3232
- [59, 46, 16, 1, 47, 17],
3233
- // 35
3234
- [12, 151, 121, 7, 152, 122],
3235
- [12, 75, 47, 26, 76, 48],
3236
- [39, 54, 24, 14, 55, 25],
3237
- [22, 45, 15, 41, 46, 16],
3238
- // 36
3239
- [6, 151, 121, 14, 152, 122],
3240
- [6, 75, 47, 34, 76, 48],
3241
- [46, 54, 24, 10, 55, 25],
3242
- [2, 45, 15, 64, 46, 16],
3243
- // 37
3244
- [17, 152, 122, 4, 153, 123],
3245
- [29, 74, 46, 14, 75, 47],
3246
- [49, 54, 24, 10, 55, 25],
3247
- [24, 45, 15, 46, 46, 16],
3248
- // 38
3249
- [4, 152, 122, 18, 153, 123],
3250
- [13, 74, 46, 32, 75, 47],
3251
- [48, 54, 24, 14, 55, 25],
3252
- [42, 45, 15, 32, 46, 16],
3253
- // 39
3254
- [20, 147, 117, 4, 148, 118],
3255
- [40, 75, 47, 7, 76, 48],
3256
- [43, 54, 24, 22, 55, 25],
3257
- [10, 45, 15, 67, 46, 16],
3258
- // 40
3259
- [19, 148, 118, 6, 149, 119],
3260
- [18, 75, 47, 31, 76, 48],
3261
- [34, 54, 24, 34, 55, 25],
3262
- [20, 45, 15, 61, 46, 16]
3263
- ];
3264
- const qrRSBlock = function(totalCount, dataCount) {
3265
- const _this2 = {};
3266
- _this2.totalCount = totalCount;
3267
- _this2.dataCount = dataCount;
3268
- return _this2;
3269
- };
3270
- const _this = {};
3271
- const getRsBlockTable = function(typeNumber, errorCorrectionLevel) {
3272
- switch (errorCorrectionLevel) {
3273
- case QRErrorCorrectionLevel.L:
3274
- return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];
3275
- case QRErrorCorrectionLevel.M:
3276
- return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
3277
- case QRErrorCorrectionLevel.Q:
3278
- return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
3279
- case QRErrorCorrectionLevel.H:
3280
- return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
3281
- default:
3282
- return void 0;
3283
- }
3284
- };
3285
- _this.getRSBlocks = function(typeNumber, errorCorrectionLevel) {
3286
- const rsBlock = getRsBlockTable(typeNumber, errorCorrectionLevel);
3287
- if (typeof rsBlock == "undefined") {
3288
- throw "bad rs block @ typeNumber:" + typeNumber + "/errorCorrectionLevel:" + errorCorrectionLevel;
3289
- }
3290
- const length = rsBlock.length / 3;
3291
- const list = [];
3292
- for (let i = 0; i < length; i += 1) {
3293
- const count = rsBlock[i * 3 + 0];
3294
- const totalCount = rsBlock[i * 3 + 1];
3295
- const dataCount = rsBlock[i * 3 + 2];
3296
- for (let j = 0; j < count; j += 1) {
3297
- list.push(qrRSBlock(totalCount, dataCount));
3298
- }
3299
- }
3300
- return list;
3301
- };
3302
- return _this;
3303
- })();
3304
- var qrBitBuffer = function() {
3305
- const _buffer = [];
3306
- let _length = 0;
3307
- const _this = {};
3308
- _this.getBuffer = function() {
3309
- return _buffer;
3310
- };
3311
- _this.getAt = function(index) {
3312
- const bufIndex = Math.floor(index / 8);
3313
- return (_buffer[bufIndex] >>> 7 - index % 8 & 1) == 1;
3314
- };
3315
- _this.put = function(num, length) {
3316
- for (let i = 0; i < length; i += 1) {
3317
- _this.putBit((num >>> length - i - 1 & 1) == 1);
3318
- }
3319
- };
3320
- _this.getLengthInBits = function() {
3321
- return _length;
3322
- };
3323
- _this.putBit = function(bit) {
3324
- const bufIndex = Math.floor(_length / 8);
3325
- if (_buffer.length <= bufIndex) {
3326
- _buffer.push(0);
3327
- }
3328
- if (bit) {
3329
- _buffer[bufIndex] |= 128 >>> _length % 8;
3330
- }
3331
- _length += 1;
3332
- };
3333
- return _this;
3334
- };
3335
- var qrNumber = function(data) {
3336
- const _mode = QRMode.MODE_NUMBER;
3337
- const _data = data;
3338
- const _this = {};
3339
- _this.getMode = function() {
3340
- return _mode;
3341
- };
3342
- _this.getLength = function(buffer) {
3343
- return _data.length;
3344
- };
3345
- _this.write = function(buffer) {
3346
- const data2 = _data;
3347
- let i = 0;
3348
- while (i + 2 < data2.length) {
3349
- buffer.put(strToNum(data2.substring(i, i + 3)), 10);
3350
- i += 3;
3351
- }
3352
- if (i < data2.length) {
3353
- if (data2.length - i == 1) {
3354
- buffer.put(strToNum(data2.substring(i, i + 1)), 4);
3355
- } else if (data2.length - i == 2) {
3356
- buffer.put(strToNum(data2.substring(i, i + 2)), 7);
3357
- }
3358
- }
3359
- };
3360
- const strToNum = function(s) {
3361
- let num = 0;
3362
- for (let i = 0; i < s.length; i += 1) {
3363
- num = num * 10 + chatToNum(s.charAt(i));
3364
- }
3365
- return num;
3366
- };
3367
- const chatToNum = function(c) {
3368
- if ("0" <= c && c <= "9") {
3369
- return c.charCodeAt(0) - "0".charCodeAt(0);
3370
- }
3371
- throw "illegal char :" + c;
3372
- };
3373
- return _this;
3374
- };
3375
- var qrAlphaNum = function(data) {
3376
- const _mode = QRMode.MODE_ALPHA_NUM;
3377
- const _data = data;
3378
- const _this = {};
3379
- _this.getMode = function() {
3380
- return _mode;
3381
- };
3382
- _this.getLength = function(buffer) {
3383
- return _data.length;
3384
- };
3385
- _this.write = function(buffer) {
3386
- const s = _data;
3387
- let i = 0;
3388
- while (i + 1 < s.length) {
3389
- buffer.put(
3390
- getCode(s.charAt(i)) * 45 + getCode(s.charAt(i + 1)),
3391
- 11
3392
- );
3393
- i += 2;
3394
- }
3395
- if (i < s.length) {
3396
- buffer.put(getCode(s.charAt(i)), 6);
3397
- }
3398
- };
3399
- const getCode = function(c) {
3400
- if ("0" <= c && c <= "9") {
3401
- return c.charCodeAt(0) - "0".charCodeAt(0);
3402
- } else if ("A" <= c && c <= "Z") {
3403
- return c.charCodeAt(0) - "A".charCodeAt(0) + 10;
3404
- } else {
3405
- switch (c) {
3406
- case " ":
3407
- return 36;
3408
- case "$":
3409
- return 37;
3410
- case "%":
3411
- return 38;
3412
- case "*":
3413
- return 39;
3414
- case "+":
3415
- return 40;
3416
- case "-":
3417
- return 41;
3418
- case ".":
3419
- return 42;
3420
- case "/":
3421
- return 43;
3422
- case ":":
3423
- return 44;
3424
- default:
3425
- throw "illegal char :" + c;
3426
- }
3427
- }
3428
- };
3429
- return _this;
3430
- };
3431
- var qr8BitByte = function(data) {
3432
- const _mode = QRMode.MODE_8BIT_BYTE;
3433
- const _data = data;
3434
- const _bytes = qrcode.stringToBytes(data);
3435
- const _this = {};
3436
- _this.getMode = function() {
3437
- return _mode;
3438
- };
3439
- _this.getLength = function(buffer) {
3440
- return _bytes.length;
3441
- };
3442
- _this.write = function(buffer) {
3443
- for (let i = 0; i < _bytes.length; i += 1) {
3444
- buffer.put(_bytes[i], 8);
3445
- }
3446
- };
3447
- return _this;
3448
- };
3449
- var qrKanji = function(data) {
3450
- const _mode = QRMode.MODE_KANJI;
3451
- const _data = data;
3452
- const stringToBytes2 = qrcode.stringToBytes;
3453
- !(function(c, code) {
3454
- const test = stringToBytes2(c);
3455
- if (test.length != 2 || (test[0] << 8 | test[1]) != code) {
3456
- throw "sjis not supported.";
3457
- }
3458
- })("\u53CB", 38726);
3459
- const _bytes = stringToBytes2(data);
3460
- const _this = {};
3461
- _this.getMode = function() {
3462
- return _mode;
3463
- };
3464
- _this.getLength = function(buffer) {
3465
- return ~~(_bytes.length / 2);
3466
- };
3467
- _this.write = function(buffer) {
3468
- const data2 = _bytes;
3469
- let i = 0;
3470
- while (i + 1 < data2.length) {
3471
- let c = (255 & data2[i]) << 8 | 255 & data2[i + 1];
3472
- if (33088 <= c && c <= 40956) {
3473
- c -= 33088;
3474
- } else if (57408 <= c && c <= 60351) {
3475
- c -= 49472;
3476
- } else {
3477
- throw "illegal char at " + (i + 1) + "/" + c;
3478
- }
3479
- c = (c >>> 8 & 255) * 192 + (c & 255);
3480
- buffer.put(c, 13);
3481
- i += 2;
3482
- }
3483
- if (i < data2.length) {
3484
- throw "illegal char at " + (i + 1);
3485
- }
3486
- };
3487
- return _this;
3488
- };
3489
- var byteArrayOutputStream = function() {
3490
- const _bytes = [];
3491
- const _this = {};
3492
- _this.writeByte = function(b) {
3493
- _bytes.push(b & 255);
3494
- };
3495
- _this.writeShort = function(i) {
3496
- _this.writeByte(i);
3497
- _this.writeByte(i >>> 8);
3498
- };
3499
- _this.writeBytes = function(b, off, len) {
3500
- off = off || 0;
3501
- len = len || b.length;
3502
- for (let i = 0; i < len; i += 1) {
3503
- _this.writeByte(b[i + off]);
3504
- }
3505
- };
3506
- _this.writeString = function(s) {
3507
- for (let i = 0; i < s.length; i += 1) {
3508
- _this.writeByte(s.charCodeAt(i));
3509
- }
3510
- };
3511
- _this.toByteArray = function() {
3512
- return _bytes;
3513
- };
3514
- _this.toString = function() {
3515
- let s = "";
3516
- s += "[";
3517
- for (let i = 0; i < _bytes.length; i += 1) {
3518
- if (i > 0) {
3519
- s += ",";
3520
- }
3521
- s += _bytes[i];
3522
- }
3523
- s += "]";
3524
- return s;
3525
- };
3526
- return _this;
3527
- };
3528
- var base64EncodeOutputStream = function() {
3529
- let _buffer = 0;
3530
- let _buflen = 0;
3531
- let _length = 0;
3532
- let _base64 = "";
3533
- const _this = {};
3534
- const writeEncoded = function(b) {
3535
- _base64 += String.fromCharCode(encode(b & 63));
3536
- };
3537
- const encode = function(n) {
3538
- if (n < 0) {
3539
- throw "n:" + n;
3540
- } else if (n < 26) {
3541
- return 65 + n;
3542
- } else if (n < 52) {
3543
- return 97 + (n - 26);
3544
- } else if (n < 62) {
3545
- return 48 + (n - 52);
3546
- } else if (n == 62) {
3547
- return 43;
3548
- } else if (n == 63) {
3549
- return 47;
3550
- } else {
3551
- throw "n:" + n;
3552
- }
3553
- };
3554
- _this.writeByte = function(n) {
3555
- _buffer = _buffer << 8 | n & 255;
3556
- _buflen += 8;
3557
- _length += 1;
3558
- while (_buflen >= 6) {
3559
- writeEncoded(_buffer >>> _buflen - 6);
3560
- _buflen -= 6;
3561
- }
3562
- };
3563
- _this.flush = function() {
3564
- if (_buflen > 0) {
3565
- writeEncoded(_buffer << 6 - _buflen);
3566
- _buffer = 0;
3567
- _buflen = 0;
3568
- }
3569
- if (_length % 3 != 0) {
3570
- const padlen = 3 - _length % 3;
3571
- for (let i = 0; i < padlen; i += 1) {
3572
- _base64 += "=";
3573
- }
3574
- }
3575
- };
3576
- _this.toString = function() {
3577
- return _base64;
3578
- };
3579
- return _this;
3580
- };
3581
- var base64DecodeInputStream = function(str) {
3582
- const _str = str;
3583
- let _pos = 0;
3584
- let _buffer = 0;
3585
- let _buflen = 0;
3586
- const _this = {};
3587
- _this.read = function() {
3588
- while (_buflen < 8) {
3589
- if (_pos >= _str.length) {
3590
- if (_buflen == 0) {
3591
- return -1;
3592
- }
3593
- throw "unexpected end of file./" + _buflen;
3594
- }
3595
- const c = _str.charAt(_pos);
3596
- _pos += 1;
3597
- if (c == "=") {
3598
- _buflen = 0;
3599
- return -1;
3600
- } else if (c.match(/^\s$/)) {
3601
- continue;
3602
- }
3603
- _buffer = _buffer << 6 | decode(c.charCodeAt(0));
3604
- _buflen += 6;
3639
+ [isLoading, tokenFor]
3640
+ );
3641
+ const control = siteKey ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "ba-auth-challenge", "data-testid": "auth-challenge", children: [
3642
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "ba-turnstile", ref: container }),
3643
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: "ba-sr-only", role: "status", "aria-live": "polite", children: status === "checking" ? t("authChallenge.checking") : status === "failed" ? t("authChallenge.error.failed") : "" })
3644
+ ] }) : null;
3645
+ return { run, control, configPending: isLoading };
3646
+ }
3647
+
3648
+ // src/components/ForgotPassword.tsx
3649
+ init_FormError();
3650
+ var import_jsx_runtime12 = require("react/jsx-runtime");
3651
+ function ForgotPassword({ resetPasswordUrl, onBack }) {
3652
+ const t = useT();
3653
+ const { requestPasswordReset } = usePasswordReset();
3654
+ const { pending, error, run } = useSubmitAction();
3655
+ const authChallenge = useAuthChallenge();
3656
+ const [email, setEmail] = React11.useState("");
3657
+ const [sent, setSent] = React11.useState(false);
3658
+ if (sent) {
3659
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "ba-fields", "data-testid": "forgot-sent", children: [
3660
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { className: "ba-muted", children: richMessage(t("forgotPassword.sent"), { email: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Bidi, { children: email }) }) }),
3661
+ onBack && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("button", { type: "button", className: "ba-link-button", onClick: onBack, children: t("forgotPassword.backToSignIn") })
3662
+ ] });
3663
+ }
3664
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
3665
+ "form",
3666
+ {
3667
+ method: "post",
3668
+ className: "ba-fields",
3669
+ "data-testid": "forgot-form",
3670
+ onSubmit: (e) => {
3671
+ e.preventDefault();
3672
+ void run(() => authChallenge.run(AUTH_CHALLENGE_ACTIONS.reset, (options) => requestPasswordReset({ email, redirectTo: resetPasswordUrl }, options)), {
3673
+ failure: t("forgotPassword.error.sendFailed"),
3674
+ onSuccess: () => setSent(true)
3675
+ });
3676
+ },
3677
+ children: [
3678
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("label", { className: "ba-label", children: [
3679
+ t("common.emailLabel"),
3680
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3681
+ "input",
3682
+ {
3683
+ className: "ba-input",
3684
+ type: "email",
3685
+ autoComplete: "email",
3686
+ value: email,
3687
+ onChange: (e) => setEmail(e.target.value),
3688
+ required: true
3689
+ }
3690
+ )
3691
+ ] }),
3692
+ authChallenge.control,
3693
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(FormError, { children: error }),
3694
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3695
+ "button",
3696
+ {
3697
+ className: "ba-button",
3698
+ type: "submit",
3699
+ disabled: pending || authChallenge.configPending,
3700
+ "aria-busy": pending || void 0,
3701
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Busy, { busy: pending, label: t("common.sending"), children: t("forgotPassword.submit") })
3702
+ }
3703
+ ),
3704
+ onBack && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("button", { type: "button", className: "ba-link-button", onClick: onBack, children: t("forgotPassword.backToSignIn") })
3705
+ ]
3605
3706
  }
3606
- const n = _buffer >>> _buflen - 8 & 255;
3607
- _buflen -= 8;
3608
- return n;
3609
- };
3610
- const decode = function(c) {
3611
- if (65 <= c && c <= 90) {
3612
- return c - 65;
3613
- } else if (97 <= c && c <= 122) {
3614
- return c - 97 + 26;
3615
- } else if (48 <= c && c <= 57) {
3616
- return c - 48 + 52;
3617
- } else if (c == 43) {
3618
- return 62;
3619
- } else if (c == 47) {
3620
- return 63;
3621
- } else {
3622
- throw "c:" + c;
3707
+ );
3708
+ }
3709
+
3710
+ // src/components/OtpCodeForm.tsx
3711
+ init_i18n();
3712
+ init_Spinner();
3713
+ init_FormError();
3714
+ var import_jsx_runtime13 = require("react/jsx-runtime");
3715
+ function OtpCodeForm({
3716
+ email,
3717
+ code,
3718
+ onCodeChange,
3719
+ onSubmit,
3720
+ onChangeEmail,
3721
+ pending,
3722
+ error
3723
+ }) {
3724
+ const t = useT();
3725
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
3726
+ "form",
3727
+ {
3728
+ method: "post",
3729
+ className: "ba-fields",
3730
+ "data-testid": "emailotp-code",
3731
+ onSubmit: (e) => {
3732
+ e.preventDefault();
3733
+ onSubmit();
3734
+ },
3735
+ children: [
3736
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("label", { className: "ba-label", children: [
3737
+ richMessage(t("emailOtp.codeLabel"), { email: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Bidi, { children: email }) }),
3738
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3739
+ "input",
3740
+ {
3741
+ className: "ba-input",
3742
+ inputMode: "numeric",
3743
+ autoComplete: "one-time-code",
3744
+ value: code,
3745
+ onChange: (e) => onCodeChange(e.target.value),
3746
+ autoFocus: true,
3747
+ required: true
3748
+ }
3749
+ )
3750
+ ] }),
3751
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(FormError, { children: error }),
3752
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { className: "ba-button", type: "submit", disabled: pending, "aria-busy": pending || void 0, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Busy, { busy: pending, label: t("common.verifying"), children: t("emailOtp.verifySubmit") }) }),
3753
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { type: "button", className: "ba-link-button", onClick: onChangeEmail, children: t("emailOtp.changeEmail") })
3754
+ ]
3623
3755
  }
3756
+ );
3757
+ }
3758
+
3759
+ // src/components/MFAChallenge.tsx
3760
+ var React12 = __toESM(require("react"), 1);
3761
+ init_hooks();
3762
+ init_i18n();
3763
+ init_use_submit_action();
3764
+ init_Spinner();
3765
+ init_FormError();
3766
+ var import_jsx_runtime14 = require("react/jsx-runtime");
3767
+ function MFAChallenge({ onVerified, allowTrustDevice = true }) {
3768
+ const t = useT();
3769
+ const { verifyTotp, verifyBackupCode, sendOtp, verifyOtp } = useMFA();
3770
+ const { pending, error, setError, run } = useSubmitAction();
3771
+ const [mode, setMode] = React12.useState("totp");
3772
+ const [code, setCode] = React12.useState("");
3773
+ const [trustDevice, setTrustDevice] = React12.useState(false);
3774
+ const switchMode = (next) => {
3775
+ setMode(next);
3776
+ setCode("");
3777
+ setError(null);
3624
3778
  };
3625
- return _this;
3626
- };
3627
- var gifImage = function(width, height) {
3628
- const _width = width;
3629
- const _height = height;
3630
- const _data = new Array(width * height);
3631
- const _this = {};
3632
- _this.setPixel = function(x, y, pixel) {
3633
- _data[y * _width + x] = pixel;
3634
- };
3635
- _this.write = function(out) {
3636
- out.writeString("GIF87a");
3637
- out.writeShort(_width);
3638
- out.writeShort(_height);
3639
- out.writeByte(128);
3640
- out.writeByte(0);
3641
- out.writeByte(0);
3642
- out.writeByte(0);
3643
- out.writeByte(0);
3644
- out.writeByte(0);
3645
- out.writeByte(255);
3646
- out.writeByte(255);
3647
- out.writeByte(255);
3648
- out.writeString(",");
3649
- out.writeShort(0);
3650
- out.writeShort(0);
3651
- out.writeShort(_width);
3652
- out.writeShort(_height);
3653
- out.writeByte(0);
3654
- const lzwMinCodeSize = 2;
3655
- const raster = getLZWRaster(lzwMinCodeSize);
3656
- out.writeByte(lzwMinCodeSize);
3657
- let offset = 0;
3658
- while (raster.length - offset > 255) {
3659
- out.writeByte(255);
3660
- out.writeBytes(raster, offset, 255);
3661
- offset += 255;
3779
+ const requestOtp = () => void run(() => sendOtp({}), {
3780
+ failure: t("mfa.challenge.error.otpSendFailed"),
3781
+ onSuccess: () => {
3782
+ setMode("otp");
3783
+ setCode("");
3662
3784
  }
3663
- out.writeByte(raster.length - offset);
3664
- out.writeBytes(raster, offset, raster.length - offset);
3665
- out.writeByte(0);
3666
- out.writeString(";");
3667
- };
3668
- const bitOutputStream = function(out) {
3669
- const _out = out;
3670
- let _bitLength = 0;
3671
- let _bitBuffer = 0;
3672
- const _this2 = {};
3673
- _this2.write = function(data, length) {
3674
- if (data >>> length != 0) {
3675
- throw "length over";
3676
- }
3677
- while (_bitLength + length >= 8) {
3678
- _out.writeByte(255 & (data << _bitLength | _bitBuffer));
3679
- length -= 8 - _bitLength;
3680
- data >>>= 8 - _bitLength;
3681
- _bitBuffer = 0;
3682
- _bitLength = 0;
3683
- }
3684
- _bitBuffer = data << _bitLength | _bitBuffer;
3685
- _bitLength = _bitLength + length;
3686
- };
3687
- _this2.flush = function() {
3688
- if (_bitLength > 0) {
3689
- _out.writeByte(_bitBuffer);
3690
- }
3691
- };
3692
- return _this2;
3785
+ });
3786
+ const submit = (e) => {
3787
+ e.preventDefault();
3788
+ const action = mode === "totp" ? () => verifyTotp({ code, trustDevice }) : mode === "backup" ? () => verifyBackupCode({ code }) : () => verifyOtp({ code, trustDevice });
3789
+ void run(action, {
3790
+ failure: mode === "totp" ? t("mfa.challenge.error.invalidTotp") : mode === "backup" ? t("mfa.challenge.error.invalidBackup") : t("mfa.challenge.error.invalidOtp"),
3791
+ onSuccess: () => onVerified?.()
3792
+ });
3693
3793
  };
3694
- const getLZWRaster = function(lzwMinCodeSize) {
3695
- const clearCode = 1 << lzwMinCodeSize;
3696
- const endCode = (1 << lzwMinCodeSize) + 1;
3697
- let bitLength = lzwMinCodeSize + 1;
3698
- const table = lzwTable();
3699
- for (let i = 0; i < clearCode; i += 1) {
3700
- table.add(String.fromCharCode(i));
3701
- }
3702
- table.add(String.fromCharCode(clearCode));
3703
- table.add(String.fromCharCode(endCode));
3704
- const byteOut = byteArrayOutputStream();
3705
- const bitOut = bitOutputStream(byteOut);
3706
- bitOut.write(clearCode, bitLength);
3707
- let dataIndex = 0;
3708
- let s = String.fromCharCode(_data[dataIndex]);
3709
- dataIndex += 1;
3710
- while (dataIndex < _data.length) {
3711
- const c = String.fromCharCode(_data[dataIndex]);
3712
- dataIndex += 1;
3713
- if (table.contains(s + c)) {
3714
- s = s + c;
3715
- } else {
3716
- bitOut.write(table.indexOf(s), bitLength);
3717
- if (table.size() < 4095) {
3718
- if (table.size() == 1 << bitLength) {
3719
- bitLength += 1;
3720
- }
3721
- table.add(s + c);
3794
+ const hint = mode === "totp" ? t("mfa.challenge.totpHint") : mode === "backup" ? t("mfa.challenge.backupHint") : t("mfa.challenge.otpHint");
3795
+ const label2 = mode === "totp" ? t("mfa.challenge.totpLabel") : mode === "backup" ? t("mfa.challenge.backupLabel") : t("mfa.challenge.otpLabel");
3796
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("form", { method: "post", className: "ba-fields", "data-testid": "mfa-challenge", onSubmit: submit, children: [
3797
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("h2", { className: "ba-title", children: t("mfa.challenge.title") }),
3798
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("p", { className: "ba-muted", children: hint }),
3799
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("label", { className: "ba-label", children: [
3800
+ label2,
3801
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3802
+ "input",
3803
+ {
3804
+ className: "ba-input",
3805
+ value: code,
3806
+ onChange: (e) => {
3807
+ setCode(e.target.value.trim());
3808
+ setError(null);
3809
+ },
3810
+ inputMode: mode === "backup" ? "text" : "numeric",
3811
+ autoComplete: "one-time-code",
3812
+ autoFocus: true,
3813
+ required: true
3722
3814
  }
3723
- s = c;
3724
- }
3725
- }
3726
- bitOut.write(table.indexOf(s), bitLength);
3727
- bitOut.write(endCode, bitLength);
3728
- bitOut.flush();
3729
- return byteOut.toByteArray();
3730
- };
3731
- const lzwTable = function() {
3732
- const _map = {};
3733
- let _size = 0;
3734
- const _this2 = {};
3735
- _this2.add = function(key) {
3736
- if (_this2.contains(key)) {
3737
- throw "dup key:" + key;
3738
- }
3739
- _map[key] = _size;
3740
- _size += 1;
3741
- };
3742
- _this2.size = function() {
3743
- return _size;
3744
- };
3745
- _this2.indexOf = function(key) {
3746
- return _map[key];
3747
- };
3748
- _this2.contains = function(key) {
3749
- return typeof _map[key] != "undefined";
3750
- };
3751
- return _this2;
3752
- };
3753
- return _this;
3754
- };
3755
- var createDataURL = function(width, height, getPixel) {
3756
- const gif = gifImage(width, height);
3757
- for (let y = 0; y < height; y += 1) {
3758
- for (let x = 0; x < width; x += 1) {
3759
- gif.setPixel(x, y, getPixel(x, y));
3760
- }
3761
- }
3762
- const b = byteArrayOutputStream();
3763
- gif.write(b);
3764
- const base64 = base64EncodeOutputStream();
3765
- const bytes = b.toByteArray();
3766
- for (let i = 0; i < bytes.length; i += 1) {
3767
- base64.writeByte(bytes[i]);
3768
- }
3769
- base64.flush();
3770
- return "data:image/gif;base64," + base64;
3771
- };
3772
- var qrcode_default = qrcode;
3773
- var stringToBytes = qrcode.stringToBytes;
3815
+ )
3816
+ ] }),
3817
+ mode !== "backup" && allowTrustDevice && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("label", { className: "ba-consent ba-consent-centered", children: [
3818
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("span", { className: "ba-checkbox-control", children: [
3819
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("input", { className: "ba-checkbox", type: "checkbox", checked: trustDevice, onChange: (e) => setTrustDevice(e.target.checked) }),
3820
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "ba-checkbox-visual", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "ba-checkbox-check" }) })
3821
+ ] }),
3822
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { children: t("mfa.challenge.trustDevice", { days: 30 }) })
3823
+ ] }),
3824
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(FormError, { children: error }),
3825
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { className: "ba-button", type: "submit", disabled: pending || !code, "aria-busy": pending || void 0, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Busy, { busy: pending, label: t("common.verifying"), children: t("mfa.challenge.submit") }) }),
3826
+ mode !== "totp" && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "button", className: "ba-link-button", onClick: () => switchMode("totp"), children: t("mfa.challenge.useTotp") }),
3827
+ mode !== "backup" && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "button", className: "ba-link-button", onClick: () => switchMode("backup"), children: t("mfa.challenge.useBackup") }),
3828
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "button", className: "ba-link-button", disabled: pending, onClick: requestOtp, children: t(mode === "otp" ? "mfa.challenge.resendOtp" : "mfa.challenge.useEmailOtp") })
3829
+ ] });
3830
+ }
3774
3831
 
3775
- // src/components/qr.ts
3776
- function qrPath(value) {
3777
- if (!value) return null;
3778
- try {
3779
- const qr = qrcode_default(0, "M");
3780
- qr.addData(value);
3781
- qr.make();
3782
- const count = qr.getModuleCount();
3783
- let d = "";
3784
- for (let row = 0; row < count; row++) {
3785
- for (let col = 0; col < count; col++) {
3786
- if (qr.isDark(row, col)) d += `M${col} ${row}h1v1h-1z`;
3787
- }
3788
- }
3789
- return { d, count };
3790
- } catch {
3791
- return null;
3792
- }
3832
+ // src/components/mfa-enrollment-step.tsx
3833
+ var React15 = __toESM(require("react"), 1);
3834
+ init_hooks();
3835
+ init_i18n();
3836
+
3837
+ // src/components/MFAEnrollment.tsx
3838
+ var React14 = __toESM(require("react"), 1);
3839
+ init_hooks();
3840
+ init_i18n();
3841
+ init_use_submit_action();
3842
+ init_Spinner();
3843
+
3844
+ // src/components/mfa-enrollment.ts
3845
+ function shouldDiscardSetup(args) {
3846
+ const { isLoaded, hasSetup, setupOwnerId, currentUserId } = args;
3847
+ return isLoaded && hasSetup && setupOwnerId !== currentUserId;
3793
3848
  }
3794
3849
 
3795
3850
  // src/components/QrCode.tsx
3851
+ var React13 = __toESM(require("react"), 1);
3852
+ init_i18n();
3796
3853
  var import_jsx_runtime15 = require("react/jsx-runtime");
3797
3854
  function QrCode({ value, size = 200 }) {
3798
3855
  const t = useT();
3799
- const path = React13.useMemo(() => qrPath(value), [value]);
3856
+ const [path, setPath] = React13.useState(null);
3857
+ React13.useEffect(() => {
3858
+ let active = true;
3859
+ setPath(null);
3860
+ void Promise.resolve().then(() => (init_qr(), qr_exports)).then(
3861
+ ({ qrPath: qrPath2 }) => {
3862
+ if (active) setPath(qrPath2(value));
3863
+ },
3864
+ () => {
3865
+ if (active) setPath(null);
3866
+ }
3867
+ );
3868
+ return () => {
3869
+ active = false;
3870
+ };
3871
+ }, [value]);
3800
3872
  if (!path) return null;
3801
3873
  const margin = 4;
3802
3874
  const dim = path.count + margin * 2;
@@ -8378,6 +8450,7 @@ var import_core8 = require("@authowl/core");
8378
8450
  useAuthOwlContext,
8379
8451
  useConsent,
8380
8452
  useEmailVerification,
8453
+ useInvitationRecipientHint,
8381
8454
  useLocale,
8382
8455
  useMFA,
8383
8456
  useOrganization,