@whittlelabs/sifter 0.28.0 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/bin.js +1815 -22
  2. package/bin.js.map +4 -4
  3. package/package.json +1 -1
package/bin.js CHANGED
@@ -11705,7 +11705,7 @@ var require_checks = __commonJS({
11705
11705
  async run(probes, subject) {
11706
11706
  const result = probes.readConfig();
11707
11707
  if (!result.ok) {
11708
- return fail("config-loadable", firstLine(result.error), `fix the config, or run \`${subject.brand.product.cliBinary} init\` to rewrite it from this pairing`);
11708
+ return fail("config-loadable", oneLine(result.error), `fix the config, or run \`${subject.brand.product.cliBinary} init\` to rewrite it from this pairing`);
11709
11709
  }
11710
11710
  const pools = result.value.pools.length;
11711
11711
  const executors = configuredExecutors(result.value);
@@ -11722,7 +11722,7 @@ var require_checks = __commonJS({
11722
11722
  }
11723
11723
  const minted = await probes.mintAgentToken(stored.value);
11724
11724
  if (!minted.ok) {
11725
- return fail("pairing-live", `Keep did not issue a token: ${firstLine(minted.error)}`, `check ${stored.value.keepApiUrl} is reachable, then run \`${subject.brand.product.cliBinary} init\` if the pairing was revoked`);
11725
+ return fail("pairing-live", `Keep did not issue a token: ${oneLine(minted.error)}`, `check ${stored.value.keepApiUrl} is reachable, then run \`${subject.brand.product.cliBinary} init\` if the pairing was revoked`);
11726
11726
  }
11727
11727
  return pass("pairing-live", `Keep issued a token from ${stored.value.keepApiUrl}`);
11728
11728
  }
@@ -11756,7 +11756,7 @@ var require_checks = __commonJS({
11756
11756
  const keepUrl = subject.brand.keepRegistration.keepApiUrl.replace(/\/$/, "");
11757
11757
  const result = await probes.reach(`${keepUrl}/.well-known/jwks.json`);
11758
11758
  if (!result.ok) {
11759
- return fail("keep-reachable", `${keepUrl} did not answer: ${firstLine(result.error)}`, "check your network, then confirm the URL with --keep-url");
11759
+ return fail("keep-reachable", `${keepUrl} did not answer: ${oneLine(result.error)}`, "check your network, then confirm the URL with --keep-url");
11760
11760
  }
11761
11761
  if (result.value.status >= 500) {
11762
11762
  return fail("keep-reachable", `${result.value.host} answered ${result.value.status}`, "Keep is not serving; wait for it to come back and try again");
@@ -11776,7 +11776,7 @@ var require_checks = __commonJS({
11776
11776
  return withConfig("jobs-reachable", probes, async (config) => {
11777
11777
  const result = await probes.reachJobs(config, pairing);
11778
11778
  if (!result.ok) {
11779
- return warn("jobs-reachable", `${config.auth.jobsApiUrl} did not answer: ${firstLine(result.error)}`, "nothing to do if this is a deployment window; the run loop will keep trying");
11779
+ return warn("jobs-reachable", `${config.auth.jobsApiUrl} did not answer: ${oneLine(result.error)}`, "nothing to do if this is a deployment window; the run loop will keep trying");
11780
11780
  }
11781
11781
  return pass("jobs-reachable", `${config.auth.jobsApiUrl} answered`);
11782
11782
  });
@@ -11864,7 +11864,7 @@ var require_checks = __commonJS({
11864
11864
  if (subject.deep) {
11865
11865
  const round = await probes.claudeRoundTrip();
11866
11866
  if (!round.ok) {
11867
- return fail("claude-auth", `the claude CLI refused a one-turn call: ${firstLine(round.error)}`, "run `claude` once and sign in, then re-run doctor --deep");
11867
+ return fail("claude-auth", `the claude CLI refused a one-turn call: ${oneLine(round.error)}`, "run `claude` once and sign in, then re-run doctor --deep");
11868
11868
  }
11869
11869
  return pass("claude-auth", "one-turn call through the claude CLI succeeded");
11870
11870
  }
@@ -11891,7 +11891,7 @@ var require_checks = __commonJS({
11891
11891
  for (const [label, dir] of targets) {
11892
11892
  const probe = await probes.mkdtemp(dir);
11893
11893
  if (!probe.ok) {
11894
- return fail("run-root-writable", `cannot create a directory in the ${label} ${dir}: ${firstLine(probe.error)}`, `make ${dir} writable by the user running this (chown -R $(whoami) ${dir})`);
11894
+ return fail("run-root-writable", `cannot create a directory in the ${label} ${dir}: ${oneLine(probe.error)}`, `make ${dir} writable by the user running this (chown -R $(whoami) ${dir})`);
11895
11895
  }
11896
11896
  }
11897
11897
  return pass("run-root-writable", targets.map(([, dir]) => dir).join(" and "));
@@ -11994,8 +11994,8 @@ var require_checks = __commonJS({
11994
11994
  function osTmpDirOf(probes) {
11995
11995
  return probes.osTmpDir();
11996
11996
  }
11997
- function firstLine(message) {
11998
- return message.split("\n")[0].trim();
11997
+ function oneLine(message) {
11998
+ return message.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).join(" ");
11999
11999
  }
12000
12000
  function normalizeUrl(url) {
12001
12001
  return url.replace(/\/+$/, "").toLowerCase();
@@ -20572,15 +20572,1769 @@ var require_doctor = __commonJS({
20572
20572
  }
20573
20573
  });
20574
20574
 
20575
+ // ../../node_modules/.pnpm/qrcode-generator@2.0.4/node_modules/qrcode-generator/dist/qrcode.js
20576
+ var require_qrcode = __commonJS({
20577
+ "../../node_modules/.pnpm/qrcode-generator@2.0.4/node_modules/qrcode-generator/dist/qrcode.js"(exports2, module2) {
20578
+ var qrcode = (function() {
20579
+ var qrcode2 = function(typeNumber, errorCorrectionLevel) {
20580
+ var PAD0 = 236;
20581
+ var PAD1 = 17;
20582
+ var _typeNumber = typeNumber;
20583
+ var _errorCorrectionLevel = QRErrorCorrectionLevel[errorCorrectionLevel];
20584
+ var _modules = null;
20585
+ var _moduleCount = 0;
20586
+ var _dataCache = null;
20587
+ var _dataList = [];
20588
+ var _this = {};
20589
+ var makeImpl = function(test, maskPattern) {
20590
+ _moduleCount = _typeNumber * 4 + 17;
20591
+ _modules = (function(moduleCount) {
20592
+ var modules = new Array(moduleCount);
20593
+ for (var row = 0; row < moduleCount; row += 1) {
20594
+ modules[row] = new Array(moduleCount);
20595
+ for (var col = 0; col < moduleCount; col += 1) {
20596
+ modules[row][col] = null;
20597
+ }
20598
+ }
20599
+ return modules;
20600
+ })(_moduleCount);
20601
+ setupPositionProbePattern(0, 0);
20602
+ setupPositionProbePattern(_moduleCount - 7, 0);
20603
+ setupPositionProbePattern(0, _moduleCount - 7);
20604
+ setupPositionAdjustPattern();
20605
+ setupTimingPattern();
20606
+ setupTypeInfo(test, maskPattern);
20607
+ if (_typeNumber >= 7) {
20608
+ setupTypeNumber(test);
20609
+ }
20610
+ if (_dataCache == null) {
20611
+ _dataCache = createData(_typeNumber, _errorCorrectionLevel, _dataList);
20612
+ }
20613
+ mapData(_dataCache, maskPattern);
20614
+ };
20615
+ var setupPositionProbePattern = function(row, col) {
20616
+ for (var r = -1; r <= 7; r += 1) {
20617
+ if (row + r <= -1 || _moduleCount <= row + r) continue;
20618
+ for (var c = -1; c <= 7; c += 1) {
20619
+ if (col + c <= -1 || _moduleCount <= col + c) continue;
20620
+ 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) {
20621
+ _modules[row + r][col + c] = true;
20622
+ } else {
20623
+ _modules[row + r][col + c] = false;
20624
+ }
20625
+ }
20626
+ }
20627
+ };
20628
+ var getBestMaskPattern = function() {
20629
+ var minLostPoint = 0;
20630
+ var pattern = 0;
20631
+ for (var i = 0; i < 8; i += 1) {
20632
+ makeImpl(true, i);
20633
+ var lostPoint = QRUtil.getLostPoint(_this);
20634
+ if (i == 0 || minLostPoint > lostPoint) {
20635
+ minLostPoint = lostPoint;
20636
+ pattern = i;
20637
+ }
20638
+ }
20639
+ return pattern;
20640
+ };
20641
+ var setupTimingPattern = function() {
20642
+ for (var r = 8; r < _moduleCount - 8; r += 1) {
20643
+ if (_modules[r][6] != null) {
20644
+ continue;
20645
+ }
20646
+ _modules[r][6] = r % 2 == 0;
20647
+ }
20648
+ for (var c = 8; c < _moduleCount - 8; c += 1) {
20649
+ if (_modules[6][c] != null) {
20650
+ continue;
20651
+ }
20652
+ _modules[6][c] = c % 2 == 0;
20653
+ }
20654
+ };
20655
+ var setupPositionAdjustPattern = function() {
20656
+ var pos = QRUtil.getPatternPosition(_typeNumber);
20657
+ for (var i = 0; i < pos.length; i += 1) {
20658
+ for (var j = 0; j < pos.length; j += 1) {
20659
+ var row = pos[i];
20660
+ var col = pos[j];
20661
+ if (_modules[row][col] != null) {
20662
+ continue;
20663
+ }
20664
+ for (var r = -2; r <= 2; r += 1) {
20665
+ for (var c = -2; c <= 2; c += 1) {
20666
+ if (r == -2 || r == 2 || c == -2 || c == 2 || r == 0 && c == 0) {
20667
+ _modules[row + r][col + c] = true;
20668
+ } else {
20669
+ _modules[row + r][col + c] = false;
20670
+ }
20671
+ }
20672
+ }
20673
+ }
20674
+ }
20675
+ };
20676
+ var setupTypeNumber = function(test) {
20677
+ var bits = QRUtil.getBCHTypeNumber(_typeNumber);
20678
+ for (var i = 0; i < 18; i += 1) {
20679
+ var mod = !test && (bits >> i & 1) == 1;
20680
+ _modules[Math.floor(i / 3)][i % 3 + _moduleCount - 8 - 3] = mod;
20681
+ }
20682
+ for (var i = 0; i < 18; i += 1) {
20683
+ var mod = !test && (bits >> i & 1) == 1;
20684
+ _modules[i % 3 + _moduleCount - 8 - 3][Math.floor(i / 3)] = mod;
20685
+ }
20686
+ };
20687
+ var setupTypeInfo = function(test, maskPattern) {
20688
+ var data = _errorCorrectionLevel << 3 | maskPattern;
20689
+ var bits = QRUtil.getBCHTypeInfo(data);
20690
+ for (var i = 0; i < 15; i += 1) {
20691
+ var mod = !test && (bits >> i & 1) == 1;
20692
+ if (i < 6) {
20693
+ _modules[i][8] = mod;
20694
+ } else if (i < 8) {
20695
+ _modules[i + 1][8] = mod;
20696
+ } else {
20697
+ _modules[_moduleCount - 15 + i][8] = mod;
20698
+ }
20699
+ }
20700
+ for (var i = 0; i < 15; i += 1) {
20701
+ var mod = !test && (bits >> i & 1) == 1;
20702
+ if (i < 8) {
20703
+ _modules[8][_moduleCount - i - 1] = mod;
20704
+ } else if (i < 9) {
20705
+ _modules[8][15 - i - 1 + 1] = mod;
20706
+ } else {
20707
+ _modules[8][15 - i - 1] = mod;
20708
+ }
20709
+ }
20710
+ _modules[_moduleCount - 8][8] = !test;
20711
+ };
20712
+ var mapData = function(data, maskPattern) {
20713
+ var inc = -1;
20714
+ var row = _moduleCount - 1;
20715
+ var bitIndex = 7;
20716
+ var byteIndex = 0;
20717
+ var maskFunc = QRUtil.getMaskFunction(maskPattern);
20718
+ for (var col = _moduleCount - 1; col > 0; col -= 2) {
20719
+ if (col == 6) col -= 1;
20720
+ while (true) {
20721
+ for (var c = 0; c < 2; c += 1) {
20722
+ if (_modules[row][col - c] == null) {
20723
+ var dark = false;
20724
+ if (byteIndex < data.length) {
20725
+ dark = (data[byteIndex] >>> bitIndex & 1) == 1;
20726
+ }
20727
+ var mask = maskFunc(row, col - c);
20728
+ if (mask) {
20729
+ dark = !dark;
20730
+ }
20731
+ _modules[row][col - c] = dark;
20732
+ bitIndex -= 1;
20733
+ if (bitIndex == -1) {
20734
+ byteIndex += 1;
20735
+ bitIndex = 7;
20736
+ }
20737
+ }
20738
+ }
20739
+ row += inc;
20740
+ if (row < 0 || _moduleCount <= row) {
20741
+ row -= inc;
20742
+ inc = -inc;
20743
+ break;
20744
+ }
20745
+ }
20746
+ }
20747
+ };
20748
+ var createBytes = function(buffer, rsBlocks) {
20749
+ var offset = 0;
20750
+ var maxDcCount = 0;
20751
+ var maxEcCount = 0;
20752
+ var dcdata = new Array(rsBlocks.length);
20753
+ var ecdata = new Array(rsBlocks.length);
20754
+ for (var r = 0; r < rsBlocks.length; r += 1) {
20755
+ var dcCount = rsBlocks[r].dataCount;
20756
+ var ecCount = rsBlocks[r].totalCount - dcCount;
20757
+ maxDcCount = Math.max(maxDcCount, dcCount);
20758
+ maxEcCount = Math.max(maxEcCount, ecCount);
20759
+ dcdata[r] = new Array(dcCount);
20760
+ for (var i = 0; i < dcdata[r].length; i += 1) {
20761
+ dcdata[r][i] = 255 & buffer.getBuffer()[i + offset];
20762
+ }
20763
+ offset += dcCount;
20764
+ var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
20765
+ var rawPoly = qrPolynomial(dcdata[r], rsPoly.getLength() - 1);
20766
+ var modPoly = rawPoly.mod(rsPoly);
20767
+ ecdata[r] = new Array(rsPoly.getLength() - 1);
20768
+ for (var i = 0; i < ecdata[r].length; i += 1) {
20769
+ var modIndex = i + modPoly.getLength() - ecdata[r].length;
20770
+ ecdata[r][i] = modIndex >= 0 ? modPoly.getAt(modIndex) : 0;
20771
+ }
20772
+ }
20773
+ var totalCodeCount = 0;
20774
+ for (var i = 0; i < rsBlocks.length; i += 1) {
20775
+ totalCodeCount += rsBlocks[i].totalCount;
20776
+ }
20777
+ var data = new Array(totalCodeCount);
20778
+ var index = 0;
20779
+ for (var i = 0; i < maxDcCount; i += 1) {
20780
+ for (var r = 0; r < rsBlocks.length; r += 1) {
20781
+ if (i < dcdata[r].length) {
20782
+ data[index] = dcdata[r][i];
20783
+ index += 1;
20784
+ }
20785
+ }
20786
+ }
20787
+ for (var i = 0; i < maxEcCount; i += 1) {
20788
+ for (var r = 0; r < rsBlocks.length; r += 1) {
20789
+ if (i < ecdata[r].length) {
20790
+ data[index] = ecdata[r][i];
20791
+ index += 1;
20792
+ }
20793
+ }
20794
+ }
20795
+ return data;
20796
+ };
20797
+ var createData = function(typeNumber2, errorCorrectionLevel2, dataList) {
20798
+ var rsBlocks = QRRSBlock.getRSBlocks(typeNumber2, errorCorrectionLevel2);
20799
+ var buffer = qrBitBuffer();
20800
+ for (var i = 0; i < dataList.length; i += 1) {
20801
+ var data = dataList[i];
20802
+ buffer.put(data.getMode(), 4);
20803
+ buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber2));
20804
+ data.write(buffer);
20805
+ }
20806
+ var totalDataCount = 0;
20807
+ for (var i = 0; i < rsBlocks.length; i += 1) {
20808
+ totalDataCount += rsBlocks[i].dataCount;
20809
+ }
20810
+ if (buffer.getLengthInBits() > totalDataCount * 8) {
20811
+ throw "code length overflow. (" + buffer.getLengthInBits() + ">" + totalDataCount * 8 + ")";
20812
+ }
20813
+ if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) {
20814
+ buffer.put(0, 4);
20815
+ }
20816
+ while (buffer.getLengthInBits() % 8 != 0) {
20817
+ buffer.putBit(false);
20818
+ }
20819
+ while (true) {
20820
+ if (buffer.getLengthInBits() >= totalDataCount * 8) {
20821
+ break;
20822
+ }
20823
+ buffer.put(PAD0, 8);
20824
+ if (buffer.getLengthInBits() >= totalDataCount * 8) {
20825
+ break;
20826
+ }
20827
+ buffer.put(PAD1, 8);
20828
+ }
20829
+ return createBytes(buffer, rsBlocks);
20830
+ };
20831
+ _this.addData = function(data, mode) {
20832
+ mode = mode || "Byte";
20833
+ var newData = null;
20834
+ switch (mode) {
20835
+ case "Numeric":
20836
+ newData = qrNumber(data);
20837
+ break;
20838
+ case "Alphanumeric":
20839
+ newData = qrAlphaNum(data);
20840
+ break;
20841
+ case "Byte":
20842
+ newData = qr8BitByte(data);
20843
+ break;
20844
+ case "Kanji":
20845
+ newData = qrKanji(data);
20846
+ break;
20847
+ default:
20848
+ throw "mode:" + mode;
20849
+ }
20850
+ _dataList.push(newData);
20851
+ _dataCache = null;
20852
+ };
20853
+ _this.isDark = function(row, col) {
20854
+ if (row < 0 || _moduleCount <= row || col < 0 || _moduleCount <= col) {
20855
+ throw row + "," + col;
20856
+ }
20857
+ return _modules[row][col];
20858
+ };
20859
+ _this.getModuleCount = function() {
20860
+ return _moduleCount;
20861
+ };
20862
+ _this.make = function() {
20863
+ if (_typeNumber < 1) {
20864
+ var typeNumber2 = 1;
20865
+ for (; typeNumber2 < 40; typeNumber2++) {
20866
+ var rsBlocks = QRRSBlock.getRSBlocks(typeNumber2, _errorCorrectionLevel);
20867
+ var buffer = qrBitBuffer();
20868
+ for (var i = 0; i < _dataList.length; i++) {
20869
+ var data = _dataList[i];
20870
+ buffer.put(data.getMode(), 4);
20871
+ buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber2));
20872
+ data.write(buffer);
20873
+ }
20874
+ var totalDataCount = 0;
20875
+ for (var i = 0; i < rsBlocks.length; i++) {
20876
+ totalDataCount += rsBlocks[i].dataCount;
20877
+ }
20878
+ if (buffer.getLengthInBits() <= totalDataCount * 8) {
20879
+ break;
20880
+ }
20881
+ }
20882
+ _typeNumber = typeNumber2;
20883
+ }
20884
+ makeImpl(false, getBestMaskPattern());
20885
+ };
20886
+ _this.createTableTag = function(cellSize, margin) {
20887
+ cellSize = cellSize || 2;
20888
+ margin = typeof margin == "undefined" ? cellSize * 4 : margin;
20889
+ var qrHtml = "";
20890
+ qrHtml += '<table style="';
20891
+ qrHtml += " border-width: 0px; border-style: none;";
20892
+ qrHtml += " border-collapse: collapse;";
20893
+ qrHtml += " padding: 0px; margin: " + margin + "px;";
20894
+ qrHtml += '">';
20895
+ qrHtml += "<tbody>";
20896
+ for (var r = 0; r < _this.getModuleCount(); r += 1) {
20897
+ qrHtml += "<tr>";
20898
+ for (var c = 0; c < _this.getModuleCount(); c += 1) {
20899
+ qrHtml += '<td style="';
20900
+ qrHtml += " border-width: 0px; border-style: none;";
20901
+ qrHtml += " border-collapse: collapse;";
20902
+ qrHtml += " padding: 0px; margin: 0px;";
20903
+ qrHtml += " width: " + cellSize + "px;";
20904
+ qrHtml += " height: " + cellSize + "px;";
20905
+ qrHtml += " background-color: ";
20906
+ qrHtml += _this.isDark(r, c) ? "#000000" : "#ffffff";
20907
+ qrHtml += ";";
20908
+ qrHtml += '"/>';
20909
+ }
20910
+ qrHtml += "</tr>";
20911
+ }
20912
+ qrHtml += "</tbody>";
20913
+ qrHtml += "</table>";
20914
+ return qrHtml;
20915
+ };
20916
+ _this.createSvgTag = function(cellSize, margin, alt, title) {
20917
+ var opts = {};
20918
+ if (typeof arguments[0] == "object") {
20919
+ opts = arguments[0];
20920
+ cellSize = opts.cellSize;
20921
+ margin = opts.margin;
20922
+ alt = opts.alt;
20923
+ title = opts.title;
20924
+ }
20925
+ cellSize = cellSize || 2;
20926
+ margin = typeof margin == "undefined" ? cellSize * 4 : margin;
20927
+ alt = typeof alt === "string" ? { text: alt } : alt || {};
20928
+ alt.text = alt.text || null;
20929
+ alt.id = alt.text ? alt.id || "qrcode-description" : null;
20930
+ title = typeof title === "string" ? { text: title } : title || {};
20931
+ title.text = title.text || null;
20932
+ title.id = title.text ? title.id || "qrcode-title" : null;
20933
+ var size = _this.getModuleCount() * cellSize + margin * 2;
20934
+ var c, mc, r, mr, qrSvg = "", rect;
20935
+ rect = "l" + cellSize + ",0 0," + cellSize + " -" + cellSize + ",0 0,-" + cellSize + "z ";
20936
+ qrSvg += '<svg version="1.1" xmlns="http://www.w3.org/2000/svg"';
20937
+ qrSvg += !opts.scalable ? ' width="' + size + 'px" height="' + size + 'px"' : "";
20938
+ qrSvg += ' viewBox="0 0 ' + size + " " + size + '" ';
20939
+ qrSvg += ' preserveAspectRatio="xMinYMin meet"';
20940
+ qrSvg += title.text || alt.text ? ' role="img" aria-labelledby="' + escapeXml([title.id, alt.id].join(" ").trim()) + '"' : "";
20941
+ qrSvg += ">";
20942
+ qrSvg += title.text ? '<title id="' + escapeXml(title.id) + '">' + escapeXml(title.text) + "</title>" : "";
20943
+ qrSvg += alt.text ? '<description id="' + escapeXml(alt.id) + '">' + escapeXml(alt.text) + "</description>" : "";
20944
+ qrSvg += '<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>';
20945
+ qrSvg += '<path d="';
20946
+ for (r = 0; r < _this.getModuleCount(); r += 1) {
20947
+ mr = r * cellSize + margin;
20948
+ for (c = 0; c < _this.getModuleCount(); c += 1) {
20949
+ if (_this.isDark(r, c)) {
20950
+ mc = c * cellSize + margin;
20951
+ qrSvg += "M" + mc + "," + mr + rect;
20952
+ }
20953
+ }
20954
+ }
20955
+ qrSvg += '" stroke="transparent" fill="black"/>';
20956
+ qrSvg += "</svg>";
20957
+ return qrSvg;
20958
+ };
20959
+ _this.createDataURL = function(cellSize, margin) {
20960
+ cellSize = cellSize || 2;
20961
+ margin = typeof margin == "undefined" ? cellSize * 4 : margin;
20962
+ var size = _this.getModuleCount() * cellSize + margin * 2;
20963
+ var min = margin;
20964
+ var max = size - margin;
20965
+ return createDataURL(size, size, function(x, y) {
20966
+ if (min <= x && x < max && min <= y && y < max) {
20967
+ var c = Math.floor((x - min) / cellSize);
20968
+ var r = Math.floor((y - min) / cellSize);
20969
+ return _this.isDark(r, c) ? 0 : 1;
20970
+ } else {
20971
+ return 1;
20972
+ }
20973
+ });
20974
+ };
20975
+ _this.createImgTag = function(cellSize, margin, alt) {
20976
+ cellSize = cellSize || 2;
20977
+ margin = typeof margin == "undefined" ? cellSize * 4 : margin;
20978
+ var size = _this.getModuleCount() * cellSize + margin * 2;
20979
+ var img = "";
20980
+ img += "<img";
20981
+ img += ' src="';
20982
+ img += _this.createDataURL(cellSize, margin);
20983
+ img += '"';
20984
+ img += ' width="';
20985
+ img += size;
20986
+ img += '"';
20987
+ img += ' height="';
20988
+ img += size;
20989
+ img += '"';
20990
+ if (alt) {
20991
+ img += ' alt="';
20992
+ img += escapeXml(alt);
20993
+ img += '"';
20994
+ }
20995
+ img += "/>";
20996
+ return img;
20997
+ };
20998
+ var escapeXml = function(s) {
20999
+ var escaped = "";
21000
+ for (var i = 0; i < s.length; i += 1) {
21001
+ var c = s.charAt(i);
21002
+ switch (c) {
21003
+ case "<":
21004
+ escaped += "&lt;";
21005
+ break;
21006
+ case ">":
21007
+ escaped += "&gt;";
21008
+ break;
21009
+ case "&":
21010
+ escaped += "&amp;";
21011
+ break;
21012
+ case '"':
21013
+ escaped += "&quot;";
21014
+ break;
21015
+ default:
21016
+ escaped += c;
21017
+ break;
21018
+ }
21019
+ }
21020
+ return escaped;
21021
+ };
21022
+ var _createHalfASCII = function(margin) {
21023
+ var cellSize = 1;
21024
+ margin = typeof margin == "undefined" ? cellSize * 2 : margin;
21025
+ var size = _this.getModuleCount() * cellSize + margin * 2;
21026
+ var min = margin;
21027
+ var max = size - margin;
21028
+ var y, x, r1, r2, p;
21029
+ var blocks = {
21030
+ "\u2588\u2588": "\u2588",
21031
+ "\u2588 ": "\u2580",
21032
+ " \u2588": "\u2584",
21033
+ " ": " "
21034
+ };
21035
+ var blocksLastLineNoMargin = {
21036
+ "\u2588\u2588": "\u2580",
21037
+ "\u2588 ": "\u2580",
21038
+ " \u2588": " ",
21039
+ " ": " "
21040
+ };
21041
+ var ascii = "";
21042
+ for (y = 0; y < size; y += 2) {
21043
+ r1 = Math.floor((y - min) / cellSize);
21044
+ r2 = Math.floor((y + 1 - min) / cellSize);
21045
+ for (x = 0; x < size; x += 1) {
21046
+ p = "\u2588";
21047
+ if (min <= x && x < max && min <= y && y < max && _this.isDark(r1, Math.floor((x - min) / cellSize))) {
21048
+ p = " ";
21049
+ }
21050
+ if (min <= x && x < max && min <= y + 1 && y + 1 < max && _this.isDark(r2, Math.floor((x - min) / cellSize))) {
21051
+ p += " ";
21052
+ } else {
21053
+ p += "\u2588";
21054
+ }
21055
+ ascii += margin < 1 && y + 1 >= max ? blocksLastLineNoMargin[p] : blocks[p];
21056
+ }
21057
+ ascii += "\n";
21058
+ }
21059
+ if (size % 2 && margin > 0) {
21060
+ return ascii.substring(0, ascii.length - size - 1) + Array(size + 1).join("\u2580");
21061
+ }
21062
+ return ascii.substring(0, ascii.length - 1);
21063
+ };
21064
+ _this.createASCII = function(cellSize, margin) {
21065
+ cellSize = cellSize || 1;
21066
+ if (cellSize < 2) {
21067
+ return _createHalfASCII(margin);
21068
+ }
21069
+ cellSize -= 1;
21070
+ margin = typeof margin == "undefined" ? cellSize * 2 : margin;
21071
+ var size = _this.getModuleCount() * cellSize + margin * 2;
21072
+ var min = margin;
21073
+ var max = size - margin;
21074
+ var y, x, r, p;
21075
+ var white = Array(cellSize + 1).join("\u2588\u2588");
21076
+ var black = Array(cellSize + 1).join(" ");
21077
+ var ascii = "";
21078
+ var line = "";
21079
+ for (y = 0; y < size; y += 1) {
21080
+ r = Math.floor((y - min) / cellSize);
21081
+ line = "";
21082
+ for (x = 0; x < size; x += 1) {
21083
+ p = 1;
21084
+ if (min <= x && x < max && min <= y && y < max && _this.isDark(r, Math.floor((x - min) / cellSize))) {
21085
+ p = 0;
21086
+ }
21087
+ line += p ? white : black;
21088
+ }
21089
+ for (r = 0; r < cellSize; r += 1) {
21090
+ ascii += line + "\n";
21091
+ }
21092
+ }
21093
+ return ascii.substring(0, ascii.length - 1);
21094
+ };
21095
+ _this.renderTo2dContext = function(context, cellSize) {
21096
+ cellSize = cellSize || 2;
21097
+ var length = _this.getModuleCount();
21098
+ for (var row = 0; row < length; row++) {
21099
+ for (var col = 0; col < length; col++) {
21100
+ context.fillStyle = _this.isDark(row, col) ? "black" : "white";
21101
+ context.fillRect(col * cellSize, row * cellSize, cellSize, cellSize);
21102
+ }
21103
+ }
21104
+ };
21105
+ return _this;
21106
+ };
21107
+ qrcode2.stringToBytesFuncs = {
21108
+ "default": function(s) {
21109
+ var bytes = [];
21110
+ for (var i = 0; i < s.length; i += 1) {
21111
+ var c = s.charCodeAt(i);
21112
+ bytes.push(c & 255);
21113
+ }
21114
+ return bytes;
21115
+ }
21116
+ };
21117
+ qrcode2.stringToBytes = qrcode2.stringToBytesFuncs["default"];
21118
+ qrcode2.createStringToBytes = function(unicodeData, numChars) {
21119
+ var unicodeMap = (function() {
21120
+ var bin = base64DecodeInputStream(unicodeData);
21121
+ var read = function() {
21122
+ var b = bin.read();
21123
+ if (b == -1) throw "eof";
21124
+ return b;
21125
+ };
21126
+ var count = 0;
21127
+ var unicodeMap2 = {};
21128
+ while (true) {
21129
+ var b0 = bin.read();
21130
+ if (b0 == -1) break;
21131
+ var b1 = read();
21132
+ var b2 = read();
21133
+ var b3 = read();
21134
+ var k = String.fromCharCode(b0 << 8 | b1);
21135
+ var v = b2 << 8 | b3;
21136
+ unicodeMap2[k] = v;
21137
+ count += 1;
21138
+ }
21139
+ if (count != numChars) {
21140
+ throw count + " != " + numChars;
21141
+ }
21142
+ return unicodeMap2;
21143
+ })();
21144
+ var unknownChar = "?".charCodeAt(0);
21145
+ return function(s) {
21146
+ var bytes = [];
21147
+ for (var i = 0; i < s.length; i += 1) {
21148
+ var c = s.charCodeAt(i);
21149
+ if (c < 128) {
21150
+ bytes.push(c);
21151
+ } else {
21152
+ var b = unicodeMap[s.charAt(i)];
21153
+ if (typeof b == "number") {
21154
+ if ((b & 255) == b) {
21155
+ bytes.push(b);
21156
+ } else {
21157
+ bytes.push(b >>> 8);
21158
+ bytes.push(b & 255);
21159
+ }
21160
+ } else {
21161
+ bytes.push(unknownChar);
21162
+ }
21163
+ }
21164
+ }
21165
+ return bytes;
21166
+ };
21167
+ };
21168
+ var QRMode = {
21169
+ MODE_NUMBER: 1 << 0,
21170
+ MODE_ALPHA_NUM: 1 << 1,
21171
+ MODE_8BIT_BYTE: 1 << 2,
21172
+ MODE_KANJI: 1 << 3
21173
+ };
21174
+ var QRErrorCorrectionLevel = {
21175
+ L: 1,
21176
+ M: 0,
21177
+ Q: 3,
21178
+ H: 2
21179
+ };
21180
+ var QRMaskPattern = {
21181
+ PATTERN000: 0,
21182
+ PATTERN001: 1,
21183
+ PATTERN010: 2,
21184
+ PATTERN011: 3,
21185
+ PATTERN100: 4,
21186
+ PATTERN101: 5,
21187
+ PATTERN110: 6,
21188
+ PATTERN111: 7
21189
+ };
21190
+ var QRUtil = (function() {
21191
+ var PATTERN_POSITION_TABLE = [
21192
+ [],
21193
+ [6, 18],
21194
+ [6, 22],
21195
+ [6, 26],
21196
+ [6, 30],
21197
+ [6, 34],
21198
+ [6, 22, 38],
21199
+ [6, 24, 42],
21200
+ [6, 26, 46],
21201
+ [6, 28, 50],
21202
+ [6, 30, 54],
21203
+ [6, 32, 58],
21204
+ [6, 34, 62],
21205
+ [6, 26, 46, 66],
21206
+ [6, 26, 48, 70],
21207
+ [6, 26, 50, 74],
21208
+ [6, 30, 54, 78],
21209
+ [6, 30, 56, 82],
21210
+ [6, 30, 58, 86],
21211
+ [6, 34, 62, 90],
21212
+ [6, 28, 50, 72, 94],
21213
+ [6, 26, 50, 74, 98],
21214
+ [6, 30, 54, 78, 102],
21215
+ [6, 28, 54, 80, 106],
21216
+ [6, 32, 58, 84, 110],
21217
+ [6, 30, 58, 86, 114],
21218
+ [6, 34, 62, 90, 118],
21219
+ [6, 26, 50, 74, 98, 122],
21220
+ [6, 30, 54, 78, 102, 126],
21221
+ [6, 26, 52, 78, 104, 130],
21222
+ [6, 30, 56, 82, 108, 134],
21223
+ [6, 34, 60, 86, 112, 138],
21224
+ [6, 30, 58, 86, 114, 142],
21225
+ [6, 34, 62, 90, 118, 146],
21226
+ [6, 30, 54, 78, 102, 126, 150],
21227
+ [6, 24, 50, 76, 102, 128, 154],
21228
+ [6, 28, 54, 80, 106, 132, 158],
21229
+ [6, 32, 58, 84, 110, 136, 162],
21230
+ [6, 26, 54, 82, 110, 138, 166],
21231
+ [6, 30, 58, 86, 114, 142, 170]
21232
+ ];
21233
+ var G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0;
21234
+ var G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0;
21235
+ var G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;
21236
+ var _this = {};
21237
+ var getBCHDigit = function(data) {
21238
+ var digit = 0;
21239
+ while (data != 0) {
21240
+ digit += 1;
21241
+ data >>>= 1;
21242
+ }
21243
+ return digit;
21244
+ };
21245
+ _this.getBCHTypeInfo = function(data) {
21246
+ var d = data << 10;
21247
+ while (getBCHDigit(d) - getBCHDigit(G15) >= 0) {
21248
+ d ^= G15 << getBCHDigit(d) - getBCHDigit(G15);
21249
+ }
21250
+ return (data << 10 | d) ^ G15_MASK;
21251
+ };
21252
+ _this.getBCHTypeNumber = function(data) {
21253
+ var d = data << 12;
21254
+ while (getBCHDigit(d) - getBCHDigit(G18) >= 0) {
21255
+ d ^= G18 << getBCHDigit(d) - getBCHDigit(G18);
21256
+ }
21257
+ return data << 12 | d;
21258
+ };
21259
+ _this.getPatternPosition = function(typeNumber) {
21260
+ return PATTERN_POSITION_TABLE[typeNumber - 1];
21261
+ };
21262
+ _this.getMaskFunction = function(maskPattern) {
21263
+ switch (maskPattern) {
21264
+ case QRMaskPattern.PATTERN000:
21265
+ return function(i, j) {
21266
+ return (i + j) % 2 == 0;
21267
+ };
21268
+ case QRMaskPattern.PATTERN001:
21269
+ return function(i, j) {
21270
+ return i % 2 == 0;
21271
+ };
21272
+ case QRMaskPattern.PATTERN010:
21273
+ return function(i, j) {
21274
+ return j % 3 == 0;
21275
+ };
21276
+ case QRMaskPattern.PATTERN011:
21277
+ return function(i, j) {
21278
+ return (i + j) % 3 == 0;
21279
+ };
21280
+ case QRMaskPattern.PATTERN100:
21281
+ return function(i, j) {
21282
+ return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0;
21283
+ };
21284
+ case QRMaskPattern.PATTERN101:
21285
+ return function(i, j) {
21286
+ return i * j % 2 + i * j % 3 == 0;
21287
+ };
21288
+ case QRMaskPattern.PATTERN110:
21289
+ return function(i, j) {
21290
+ return (i * j % 2 + i * j % 3) % 2 == 0;
21291
+ };
21292
+ case QRMaskPattern.PATTERN111:
21293
+ return function(i, j) {
21294
+ return (i * j % 3 + (i + j) % 2) % 2 == 0;
21295
+ };
21296
+ default:
21297
+ throw "bad maskPattern:" + maskPattern;
21298
+ }
21299
+ };
21300
+ _this.getErrorCorrectPolynomial = function(errorCorrectLength) {
21301
+ var a = qrPolynomial([1], 0);
21302
+ for (var i = 0; i < errorCorrectLength; i += 1) {
21303
+ a = a.multiply(qrPolynomial([1, QRMath.gexp(i)], 0));
21304
+ }
21305
+ return a;
21306
+ };
21307
+ _this.getLengthInBits = function(mode, type) {
21308
+ if (1 <= type && type < 10) {
21309
+ switch (mode) {
21310
+ case QRMode.MODE_NUMBER:
21311
+ return 10;
21312
+ case QRMode.MODE_ALPHA_NUM:
21313
+ return 9;
21314
+ case QRMode.MODE_8BIT_BYTE:
21315
+ return 8;
21316
+ case QRMode.MODE_KANJI:
21317
+ return 8;
21318
+ default:
21319
+ throw "mode:" + mode;
21320
+ }
21321
+ } else if (type < 27) {
21322
+ switch (mode) {
21323
+ case QRMode.MODE_NUMBER:
21324
+ return 12;
21325
+ case QRMode.MODE_ALPHA_NUM:
21326
+ return 11;
21327
+ case QRMode.MODE_8BIT_BYTE:
21328
+ return 16;
21329
+ case QRMode.MODE_KANJI:
21330
+ return 10;
21331
+ default:
21332
+ throw "mode:" + mode;
21333
+ }
21334
+ } else if (type < 41) {
21335
+ switch (mode) {
21336
+ case QRMode.MODE_NUMBER:
21337
+ return 14;
21338
+ case QRMode.MODE_ALPHA_NUM:
21339
+ return 13;
21340
+ case QRMode.MODE_8BIT_BYTE:
21341
+ return 16;
21342
+ case QRMode.MODE_KANJI:
21343
+ return 12;
21344
+ default:
21345
+ throw "mode:" + mode;
21346
+ }
21347
+ } else {
21348
+ throw "type:" + type;
21349
+ }
21350
+ };
21351
+ _this.getLostPoint = function(qrcode3) {
21352
+ var moduleCount = qrcode3.getModuleCount();
21353
+ var lostPoint = 0;
21354
+ for (var row = 0; row < moduleCount; row += 1) {
21355
+ for (var col = 0; col < moduleCount; col += 1) {
21356
+ var sameCount = 0;
21357
+ var dark = qrcode3.isDark(row, col);
21358
+ for (var r = -1; r <= 1; r += 1) {
21359
+ if (row + r < 0 || moduleCount <= row + r) {
21360
+ continue;
21361
+ }
21362
+ for (var c = -1; c <= 1; c += 1) {
21363
+ if (col + c < 0 || moduleCount <= col + c) {
21364
+ continue;
21365
+ }
21366
+ if (r == 0 && c == 0) {
21367
+ continue;
21368
+ }
21369
+ if (dark == qrcode3.isDark(row + r, col + c)) {
21370
+ sameCount += 1;
21371
+ }
21372
+ }
21373
+ }
21374
+ if (sameCount > 5) {
21375
+ lostPoint += 3 + sameCount - 5;
21376
+ }
21377
+ }
21378
+ }
21379
+ ;
21380
+ for (var row = 0; row < moduleCount - 1; row += 1) {
21381
+ for (var col = 0; col < moduleCount - 1; col += 1) {
21382
+ var count = 0;
21383
+ if (qrcode3.isDark(row, col)) count += 1;
21384
+ if (qrcode3.isDark(row + 1, col)) count += 1;
21385
+ if (qrcode3.isDark(row, col + 1)) count += 1;
21386
+ if (qrcode3.isDark(row + 1, col + 1)) count += 1;
21387
+ if (count == 0 || count == 4) {
21388
+ lostPoint += 3;
21389
+ }
21390
+ }
21391
+ }
21392
+ for (var row = 0; row < moduleCount; row += 1) {
21393
+ for (var col = 0; col < moduleCount - 6; col += 1) {
21394
+ if (qrcode3.isDark(row, col) && !qrcode3.isDark(row, col + 1) && qrcode3.isDark(row, col + 2) && qrcode3.isDark(row, col + 3) && qrcode3.isDark(row, col + 4) && !qrcode3.isDark(row, col + 5) && qrcode3.isDark(row, col + 6)) {
21395
+ lostPoint += 40;
21396
+ }
21397
+ }
21398
+ }
21399
+ for (var col = 0; col < moduleCount; col += 1) {
21400
+ for (var row = 0; row < moduleCount - 6; row += 1) {
21401
+ if (qrcode3.isDark(row, col) && !qrcode3.isDark(row + 1, col) && qrcode3.isDark(row + 2, col) && qrcode3.isDark(row + 3, col) && qrcode3.isDark(row + 4, col) && !qrcode3.isDark(row + 5, col) && qrcode3.isDark(row + 6, col)) {
21402
+ lostPoint += 40;
21403
+ }
21404
+ }
21405
+ }
21406
+ var darkCount = 0;
21407
+ for (var col = 0; col < moduleCount; col += 1) {
21408
+ for (var row = 0; row < moduleCount; row += 1) {
21409
+ if (qrcode3.isDark(row, col)) {
21410
+ darkCount += 1;
21411
+ }
21412
+ }
21413
+ }
21414
+ var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
21415
+ lostPoint += ratio * 10;
21416
+ return lostPoint;
21417
+ };
21418
+ return _this;
21419
+ })();
21420
+ var QRMath = (function() {
21421
+ var EXP_TABLE = new Array(256);
21422
+ var LOG_TABLE = new Array(256);
21423
+ for (var i = 0; i < 8; i += 1) {
21424
+ EXP_TABLE[i] = 1 << i;
21425
+ }
21426
+ for (var i = 8; i < 256; i += 1) {
21427
+ EXP_TABLE[i] = EXP_TABLE[i - 4] ^ EXP_TABLE[i - 5] ^ EXP_TABLE[i - 6] ^ EXP_TABLE[i - 8];
21428
+ }
21429
+ for (var i = 0; i < 255; i += 1) {
21430
+ LOG_TABLE[EXP_TABLE[i]] = i;
21431
+ }
21432
+ var _this = {};
21433
+ _this.glog = function(n) {
21434
+ if (n < 1) {
21435
+ throw "glog(" + n + ")";
21436
+ }
21437
+ return LOG_TABLE[n];
21438
+ };
21439
+ _this.gexp = function(n) {
21440
+ while (n < 0) {
21441
+ n += 255;
21442
+ }
21443
+ while (n >= 256) {
21444
+ n -= 255;
21445
+ }
21446
+ return EXP_TABLE[n];
21447
+ };
21448
+ return _this;
21449
+ })();
21450
+ function qrPolynomial(num, shift) {
21451
+ if (typeof num.length == "undefined") {
21452
+ throw num.length + "/" + shift;
21453
+ }
21454
+ var _num = (function() {
21455
+ var offset = 0;
21456
+ while (offset < num.length && num[offset] == 0) {
21457
+ offset += 1;
21458
+ }
21459
+ var _num2 = new Array(num.length - offset + shift);
21460
+ for (var i = 0; i < num.length - offset; i += 1) {
21461
+ _num2[i] = num[i + offset];
21462
+ }
21463
+ return _num2;
21464
+ })();
21465
+ var _this = {};
21466
+ _this.getAt = function(index) {
21467
+ return _num[index];
21468
+ };
21469
+ _this.getLength = function() {
21470
+ return _num.length;
21471
+ };
21472
+ _this.multiply = function(e) {
21473
+ var num2 = new Array(_this.getLength() + e.getLength() - 1);
21474
+ for (var i = 0; i < _this.getLength(); i += 1) {
21475
+ for (var j = 0; j < e.getLength(); j += 1) {
21476
+ num2[i + j] ^= QRMath.gexp(QRMath.glog(_this.getAt(i)) + QRMath.glog(e.getAt(j)));
21477
+ }
21478
+ }
21479
+ return qrPolynomial(num2, 0);
21480
+ };
21481
+ _this.mod = function(e) {
21482
+ if (_this.getLength() - e.getLength() < 0) {
21483
+ return _this;
21484
+ }
21485
+ var ratio = QRMath.glog(_this.getAt(0)) - QRMath.glog(e.getAt(0));
21486
+ var num2 = new Array(_this.getLength());
21487
+ for (var i = 0; i < _this.getLength(); i += 1) {
21488
+ num2[i] = _this.getAt(i);
21489
+ }
21490
+ for (var i = 0; i < e.getLength(); i += 1) {
21491
+ num2[i] ^= QRMath.gexp(QRMath.glog(e.getAt(i)) + ratio);
21492
+ }
21493
+ return qrPolynomial(num2, 0).mod(e);
21494
+ };
21495
+ return _this;
21496
+ }
21497
+ ;
21498
+ var QRRSBlock = (function() {
21499
+ var RS_BLOCK_TABLE = [
21500
+ // L
21501
+ // M
21502
+ // Q
21503
+ // H
21504
+ // 1
21505
+ [1, 26, 19],
21506
+ [1, 26, 16],
21507
+ [1, 26, 13],
21508
+ [1, 26, 9],
21509
+ // 2
21510
+ [1, 44, 34],
21511
+ [1, 44, 28],
21512
+ [1, 44, 22],
21513
+ [1, 44, 16],
21514
+ // 3
21515
+ [1, 70, 55],
21516
+ [1, 70, 44],
21517
+ [2, 35, 17],
21518
+ [2, 35, 13],
21519
+ // 4
21520
+ [1, 100, 80],
21521
+ [2, 50, 32],
21522
+ [2, 50, 24],
21523
+ [4, 25, 9],
21524
+ // 5
21525
+ [1, 134, 108],
21526
+ [2, 67, 43],
21527
+ [2, 33, 15, 2, 34, 16],
21528
+ [2, 33, 11, 2, 34, 12],
21529
+ // 6
21530
+ [2, 86, 68],
21531
+ [4, 43, 27],
21532
+ [4, 43, 19],
21533
+ [4, 43, 15],
21534
+ // 7
21535
+ [2, 98, 78],
21536
+ [4, 49, 31],
21537
+ [2, 32, 14, 4, 33, 15],
21538
+ [4, 39, 13, 1, 40, 14],
21539
+ // 8
21540
+ [2, 121, 97],
21541
+ [2, 60, 38, 2, 61, 39],
21542
+ [4, 40, 18, 2, 41, 19],
21543
+ [4, 40, 14, 2, 41, 15],
21544
+ // 9
21545
+ [2, 146, 116],
21546
+ [3, 58, 36, 2, 59, 37],
21547
+ [4, 36, 16, 4, 37, 17],
21548
+ [4, 36, 12, 4, 37, 13],
21549
+ // 10
21550
+ [2, 86, 68, 2, 87, 69],
21551
+ [4, 69, 43, 1, 70, 44],
21552
+ [6, 43, 19, 2, 44, 20],
21553
+ [6, 43, 15, 2, 44, 16],
21554
+ // 11
21555
+ [4, 101, 81],
21556
+ [1, 80, 50, 4, 81, 51],
21557
+ [4, 50, 22, 4, 51, 23],
21558
+ [3, 36, 12, 8, 37, 13],
21559
+ // 12
21560
+ [2, 116, 92, 2, 117, 93],
21561
+ [6, 58, 36, 2, 59, 37],
21562
+ [4, 46, 20, 6, 47, 21],
21563
+ [7, 42, 14, 4, 43, 15],
21564
+ // 13
21565
+ [4, 133, 107],
21566
+ [8, 59, 37, 1, 60, 38],
21567
+ [8, 44, 20, 4, 45, 21],
21568
+ [12, 33, 11, 4, 34, 12],
21569
+ // 14
21570
+ [3, 145, 115, 1, 146, 116],
21571
+ [4, 64, 40, 5, 65, 41],
21572
+ [11, 36, 16, 5, 37, 17],
21573
+ [11, 36, 12, 5, 37, 13],
21574
+ // 15
21575
+ [5, 109, 87, 1, 110, 88],
21576
+ [5, 65, 41, 5, 66, 42],
21577
+ [5, 54, 24, 7, 55, 25],
21578
+ [11, 36, 12, 7, 37, 13],
21579
+ // 16
21580
+ [5, 122, 98, 1, 123, 99],
21581
+ [7, 73, 45, 3, 74, 46],
21582
+ [15, 43, 19, 2, 44, 20],
21583
+ [3, 45, 15, 13, 46, 16],
21584
+ // 17
21585
+ [1, 135, 107, 5, 136, 108],
21586
+ [10, 74, 46, 1, 75, 47],
21587
+ [1, 50, 22, 15, 51, 23],
21588
+ [2, 42, 14, 17, 43, 15],
21589
+ // 18
21590
+ [5, 150, 120, 1, 151, 121],
21591
+ [9, 69, 43, 4, 70, 44],
21592
+ [17, 50, 22, 1, 51, 23],
21593
+ [2, 42, 14, 19, 43, 15],
21594
+ // 19
21595
+ [3, 141, 113, 4, 142, 114],
21596
+ [3, 70, 44, 11, 71, 45],
21597
+ [17, 47, 21, 4, 48, 22],
21598
+ [9, 39, 13, 16, 40, 14],
21599
+ // 20
21600
+ [3, 135, 107, 5, 136, 108],
21601
+ [3, 67, 41, 13, 68, 42],
21602
+ [15, 54, 24, 5, 55, 25],
21603
+ [15, 43, 15, 10, 44, 16],
21604
+ // 21
21605
+ [4, 144, 116, 4, 145, 117],
21606
+ [17, 68, 42],
21607
+ [17, 50, 22, 6, 51, 23],
21608
+ [19, 46, 16, 6, 47, 17],
21609
+ // 22
21610
+ [2, 139, 111, 7, 140, 112],
21611
+ [17, 74, 46],
21612
+ [7, 54, 24, 16, 55, 25],
21613
+ [34, 37, 13],
21614
+ // 23
21615
+ [4, 151, 121, 5, 152, 122],
21616
+ [4, 75, 47, 14, 76, 48],
21617
+ [11, 54, 24, 14, 55, 25],
21618
+ [16, 45, 15, 14, 46, 16],
21619
+ // 24
21620
+ [6, 147, 117, 4, 148, 118],
21621
+ [6, 73, 45, 14, 74, 46],
21622
+ [11, 54, 24, 16, 55, 25],
21623
+ [30, 46, 16, 2, 47, 17],
21624
+ // 25
21625
+ [8, 132, 106, 4, 133, 107],
21626
+ [8, 75, 47, 13, 76, 48],
21627
+ [7, 54, 24, 22, 55, 25],
21628
+ [22, 45, 15, 13, 46, 16],
21629
+ // 26
21630
+ [10, 142, 114, 2, 143, 115],
21631
+ [19, 74, 46, 4, 75, 47],
21632
+ [28, 50, 22, 6, 51, 23],
21633
+ [33, 46, 16, 4, 47, 17],
21634
+ // 27
21635
+ [8, 152, 122, 4, 153, 123],
21636
+ [22, 73, 45, 3, 74, 46],
21637
+ [8, 53, 23, 26, 54, 24],
21638
+ [12, 45, 15, 28, 46, 16],
21639
+ // 28
21640
+ [3, 147, 117, 10, 148, 118],
21641
+ [3, 73, 45, 23, 74, 46],
21642
+ [4, 54, 24, 31, 55, 25],
21643
+ [11, 45, 15, 31, 46, 16],
21644
+ // 29
21645
+ [7, 146, 116, 7, 147, 117],
21646
+ [21, 73, 45, 7, 74, 46],
21647
+ [1, 53, 23, 37, 54, 24],
21648
+ [19, 45, 15, 26, 46, 16],
21649
+ // 30
21650
+ [5, 145, 115, 10, 146, 116],
21651
+ [19, 75, 47, 10, 76, 48],
21652
+ [15, 54, 24, 25, 55, 25],
21653
+ [23, 45, 15, 25, 46, 16],
21654
+ // 31
21655
+ [13, 145, 115, 3, 146, 116],
21656
+ [2, 74, 46, 29, 75, 47],
21657
+ [42, 54, 24, 1, 55, 25],
21658
+ [23, 45, 15, 28, 46, 16],
21659
+ // 32
21660
+ [17, 145, 115],
21661
+ [10, 74, 46, 23, 75, 47],
21662
+ [10, 54, 24, 35, 55, 25],
21663
+ [19, 45, 15, 35, 46, 16],
21664
+ // 33
21665
+ [17, 145, 115, 1, 146, 116],
21666
+ [14, 74, 46, 21, 75, 47],
21667
+ [29, 54, 24, 19, 55, 25],
21668
+ [11, 45, 15, 46, 46, 16],
21669
+ // 34
21670
+ [13, 145, 115, 6, 146, 116],
21671
+ [14, 74, 46, 23, 75, 47],
21672
+ [44, 54, 24, 7, 55, 25],
21673
+ [59, 46, 16, 1, 47, 17],
21674
+ // 35
21675
+ [12, 151, 121, 7, 152, 122],
21676
+ [12, 75, 47, 26, 76, 48],
21677
+ [39, 54, 24, 14, 55, 25],
21678
+ [22, 45, 15, 41, 46, 16],
21679
+ // 36
21680
+ [6, 151, 121, 14, 152, 122],
21681
+ [6, 75, 47, 34, 76, 48],
21682
+ [46, 54, 24, 10, 55, 25],
21683
+ [2, 45, 15, 64, 46, 16],
21684
+ // 37
21685
+ [17, 152, 122, 4, 153, 123],
21686
+ [29, 74, 46, 14, 75, 47],
21687
+ [49, 54, 24, 10, 55, 25],
21688
+ [24, 45, 15, 46, 46, 16],
21689
+ // 38
21690
+ [4, 152, 122, 18, 153, 123],
21691
+ [13, 74, 46, 32, 75, 47],
21692
+ [48, 54, 24, 14, 55, 25],
21693
+ [42, 45, 15, 32, 46, 16],
21694
+ // 39
21695
+ [20, 147, 117, 4, 148, 118],
21696
+ [40, 75, 47, 7, 76, 48],
21697
+ [43, 54, 24, 22, 55, 25],
21698
+ [10, 45, 15, 67, 46, 16],
21699
+ // 40
21700
+ [19, 148, 118, 6, 149, 119],
21701
+ [18, 75, 47, 31, 76, 48],
21702
+ [34, 54, 24, 34, 55, 25],
21703
+ [20, 45, 15, 61, 46, 16]
21704
+ ];
21705
+ var qrRSBlock = function(totalCount, dataCount) {
21706
+ var _this2 = {};
21707
+ _this2.totalCount = totalCount;
21708
+ _this2.dataCount = dataCount;
21709
+ return _this2;
21710
+ };
21711
+ var _this = {};
21712
+ var getRsBlockTable = function(typeNumber, errorCorrectionLevel) {
21713
+ switch (errorCorrectionLevel) {
21714
+ case QRErrorCorrectionLevel.L:
21715
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];
21716
+ case QRErrorCorrectionLevel.M:
21717
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
21718
+ case QRErrorCorrectionLevel.Q:
21719
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
21720
+ case QRErrorCorrectionLevel.H:
21721
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
21722
+ default:
21723
+ return void 0;
21724
+ }
21725
+ };
21726
+ _this.getRSBlocks = function(typeNumber, errorCorrectionLevel) {
21727
+ var rsBlock = getRsBlockTable(typeNumber, errorCorrectionLevel);
21728
+ if (typeof rsBlock == "undefined") {
21729
+ throw "bad rs block @ typeNumber:" + typeNumber + "/errorCorrectionLevel:" + errorCorrectionLevel;
21730
+ }
21731
+ var length = rsBlock.length / 3;
21732
+ var list = [];
21733
+ for (var i = 0; i < length; i += 1) {
21734
+ var count = rsBlock[i * 3 + 0];
21735
+ var totalCount = rsBlock[i * 3 + 1];
21736
+ var dataCount = rsBlock[i * 3 + 2];
21737
+ for (var j = 0; j < count; j += 1) {
21738
+ list.push(qrRSBlock(totalCount, dataCount));
21739
+ }
21740
+ }
21741
+ return list;
21742
+ };
21743
+ return _this;
21744
+ })();
21745
+ var qrBitBuffer = function() {
21746
+ var _buffer = [];
21747
+ var _length = 0;
21748
+ var _this = {};
21749
+ _this.getBuffer = function() {
21750
+ return _buffer;
21751
+ };
21752
+ _this.getAt = function(index) {
21753
+ var bufIndex = Math.floor(index / 8);
21754
+ return (_buffer[bufIndex] >>> 7 - index % 8 & 1) == 1;
21755
+ };
21756
+ _this.put = function(num, length) {
21757
+ for (var i = 0; i < length; i += 1) {
21758
+ _this.putBit((num >>> length - i - 1 & 1) == 1);
21759
+ }
21760
+ };
21761
+ _this.getLengthInBits = function() {
21762
+ return _length;
21763
+ };
21764
+ _this.putBit = function(bit) {
21765
+ var bufIndex = Math.floor(_length / 8);
21766
+ if (_buffer.length <= bufIndex) {
21767
+ _buffer.push(0);
21768
+ }
21769
+ if (bit) {
21770
+ _buffer[bufIndex] |= 128 >>> _length % 8;
21771
+ }
21772
+ _length += 1;
21773
+ };
21774
+ return _this;
21775
+ };
21776
+ var qrNumber = function(data) {
21777
+ var _mode = QRMode.MODE_NUMBER;
21778
+ var _data = data;
21779
+ var _this = {};
21780
+ _this.getMode = function() {
21781
+ return _mode;
21782
+ };
21783
+ _this.getLength = function(buffer) {
21784
+ return _data.length;
21785
+ };
21786
+ _this.write = function(buffer) {
21787
+ var data2 = _data;
21788
+ var i = 0;
21789
+ while (i + 2 < data2.length) {
21790
+ buffer.put(strToNum(data2.substring(i, i + 3)), 10);
21791
+ i += 3;
21792
+ }
21793
+ if (i < data2.length) {
21794
+ if (data2.length - i == 1) {
21795
+ buffer.put(strToNum(data2.substring(i, i + 1)), 4);
21796
+ } else if (data2.length - i == 2) {
21797
+ buffer.put(strToNum(data2.substring(i, i + 2)), 7);
21798
+ }
21799
+ }
21800
+ };
21801
+ var strToNum = function(s) {
21802
+ var num = 0;
21803
+ for (var i = 0; i < s.length; i += 1) {
21804
+ num = num * 10 + chatToNum(s.charAt(i));
21805
+ }
21806
+ return num;
21807
+ };
21808
+ var chatToNum = function(c) {
21809
+ if ("0" <= c && c <= "9") {
21810
+ return c.charCodeAt(0) - "0".charCodeAt(0);
21811
+ }
21812
+ throw "illegal char :" + c;
21813
+ };
21814
+ return _this;
21815
+ };
21816
+ var qrAlphaNum = function(data) {
21817
+ var _mode = QRMode.MODE_ALPHA_NUM;
21818
+ var _data = data;
21819
+ var _this = {};
21820
+ _this.getMode = function() {
21821
+ return _mode;
21822
+ };
21823
+ _this.getLength = function(buffer) {
21824
+ return _data.length;
21825
+ };
21826
+ _this.write = function(buffer) {
21827
+ var s = _data;
21828
+ var i = 0;
21829
+ while (i + 1 < s.length) {
21830
+ buffer.put(
21831
+ getCode(s.charAt(i)) * 45 + getCode(s.charAt(i + 1)),
21832
+ 11
21833
+ );
21834
+ i += 2;
21835
+ }
21836
+ if (i < s.length) {
21837
+ buffer.put(getCode(s.charAt(i)), 6);
21838
+ }
21839
+ };
21840
+ var getCode = function(c) {
21841
+ if ("0" <= c && c <= "9") {
21842
+ return c.charCodeAt(0) - "0".charCodeAt(0);
21843
+ } else if ("A" <= c && c <= "Z") {
21844
+ return c.charCodeAt(0) - "A".charCodeAt(0) + 10;
21845
+ } else {
21846
+ switch (c) {
21847
+ case " ":
21848
+ return 36;
21849
+ case "$":
21850
+ return 37;
21851
+ case "%":
21852
+ return 38;
21853
+ case "*":
21854
+ return 39;
21855
+ case "+":
21856
+ return 40;
21857
+ case "-":
21858
+ return 41;
21859
+ case ".":
21860
+ return 42;
21861
+ case "/":
21862
+ return 43;
21863
+ case ":":
21864
+ return 44;
21865
+ default:
21866
+ throw "illegal char :" + c;
21867
+ }
21868
+ }
21869
+ };
21870
+ return _this;
21871
+ };
21872
+ var qr8BitByte = function(data) {
21873
+ var _mode = QRMode.MODE_8BIT_BYTE;
21874
+ var _data = data;
21875
+ var _bytes = qrcode2.stringToBytes(data);
21876
+ var _this = {};
21877
+ _this.getMode = function() {
21878
+ return _mode;
21879
+ };
21880
+ _this.getLength = function(buffer) {
21881
+ return _bytes.length;
21882
+ };
21883
+ _this.write = function(buffer) {
21884
+ for (var i = 0; i < _bytes.length; i += 1) {
21885
+ buffer.put(_bytes[i], 8);
21886
+ }
21887
+ };
21888
+ return _this;
21889
+ };
21890
+ var qrKanji = function(data) {
21891
+ var _mode = QRMode.MODE_KANJI;
21892
+ var _data = data;
21893
+ var stringToBytes = qrcode2.stringToBytesFuncs["SJIS"];
21894
+ if (!stringToBytes) {
21895
+ throw "sjis not supported.";
21896
+ }
21897
+ !(function(c, code) {
21898
+ var test = stringToBytes(c);
21899
+ if (test.length != 2 || (test[0] << 8 | test[1]) != code) {
21900
+ throw "sjis not supported.";
21901
+ }
21902
+ })("\u53CB", 38726);
21903
+ var _bytes = stringToBytes(data);
21904
+ var _this = {};
21905
+ _this.getMode = function() {
21906
+ return _mode;
21907
+ };
21908
+ _this.getLength = function(buffer) {
21909
+ return ~~(_bytes.length / 2);
21910
+ };
21911
+ _this.write = function(buffer) {
21912
+ var data2 = _bytes;
21913
+ var i = 0;
21914
+ while (i + 1 < data2.length) {
21915
+ var c = (255 & data2[i]) << 8 | 255 & data2[i + 1];
21916
+ if (33088 <= c && c <= 40956) {
21917
+ c -= 33088;
21918
+ } else if (57408 <= c && c <= 60351) {
21919
+ c -= 49472;
21920
+ } else {
21921
+ throw "illegal char at " + (i + 1) + "/" + c;
21922
+ }
21923
+ c = (c >>> 8 & 255) * 192 + (c & 255);
21924
+ buffer.put(c, 13);
21925
+ i += 2;
21926
+ }
21927
+ if (i < data2.length) {
21928
+ throw "illegal char at " + (i + 1);
21929
+ }
21930
+ };
21931
+ return _this;
21932
+ };
21933
+ var byteArrayOutputStream = function() {
21934
+ var _bytes = [];
21935
+ var _this = {};
21936
+ _this.writeByte = function(b) {
21937
+ _bytes.push(b & 255);
21938
+ };
21939
+ _this.writeShort = function(i) {
21940
+ _this.writeByte(i);
21941
+ _this.writeByte(i >>> 8);
21942
+ };
21943
+ _this.writeBytes = function(b, off, len) {
21944
+ off = off || 0;
21945
+ len = len || b.length;
21946
+ for (var i = 0; i < len; i += 1) {
21947
+ _this.writeByte(b[i + off]);
21948
+ }
21949
+ };
21950
+ _this.writeString = function(s) {
21951
+ for (var i = 0; i < s.length; i += 1) {
21952
+ _this.writeByte(s.charCodeAt(i));
21953
+ }
21954
+ };
21955
+ _this.toByteArray = function() {
21956
+ return _bytes;
21957
+ };
21958
+ _this.toString = function() {
21959
+ var s = "";
21960
+ s += "[";
21961
+ for (var i = 0; i < _bytes.length; i += 1) {
21962
+ if (i > 0) {
21963
+ s += ",";
21964
+ }
21965
+ s += _bytes[i];
21966
+ }
21967
+ s += "]";
21968
+ return s;
21969
+ };
21970
+ return _this;
21971
+ };
21972
+ var base64EncodeOutputStream = function() {
21973
+ var _buffer = 0;
21974
+ var _buflen = 0;
21975
+ var _length = 0;
21976
+ var _base64 = "";
21977
+ var _this = {};
21978
+ var writeEncoded = function(b) {
21979
+ _base64 += String.fromCharCode(encode(b & 63));
21980
+ };
21981
+ var encode = function(n) {
21982
+ if (n < 0) {
21983
+ } else if (n < 26) {
21984
+ return 65 + n;
21985
+ } else if (n < 52) {
21986
+ return 97 + (n - 26);
21987
+ } else if (n < 62) {
21988
+ return 48 + (n - 52);
21989
+ } else if (n == 62) {
21990
+ return 43;
21991
+ } else if (n == 63) {
21992
+ return 47;
21993
+ }
21994
+ throw "n:" + n;
21995
+ };
21996
+ _this.writeByte = function(n) {
21997
+ _buffer = _buffer << 8 | n & 255;
21998
+ _buflen += 8;
21999
+ _length += 1;
22000
+ while (_buflen >= 6) {
22001
+ writeEncoded(_buffer >>> _buflen - 6);
22002
+ _buflen -= 6;
22003
+ }
22004
+ };
22005
+ _this.flush = function() {
22006
+ if (_buflen > 0) {
22007
+ writeEncoded(_buffer << 6 - _buflen);
22008
+ _buffer = 0;
22009
+ _buflen = 0;
22010
+ }
22011
+ if (_length % 3 != 0) {
22012
+ var padlen = 3 - _length % 3;
22013
+ for (var i = 0; i < padlen; i += 1) {
22014
+ _base64 += "=";
22015
+ }
22016
+ }
22017
+ };
22018
+ _this.toString = function() {
22019
+ return _base64;
22020
+ };
22021
+ return _this;
22022
+ };
22023
+ var base64DecodeInputStream = function(str) {
22024
+ var _str = str;
22025
+ var _pos = 0;
22026
+ var _buffer = 0;
22027
+ var _buflen = 0;
22028
+ var _this = {};
22029
+ _this.read = function() {
22030
+ while (_buflen < 8) {
22031
+ if (_pos >= _str.length) {
22032
+ if (_buflen == 0) {
22033
+ return -1;
22034
+ }
22035
+ throw "unexpected end of file./" + _buflen;
22036
+ }
22037
+ var c = _str.charAt(_pos);
22038
+ _pos += 1;
22039
+ if (c == "=") {
22040
+ _buflen = 0;
22041
+ return -1;
22042
+ } else if (c.match(/^\s$/)) {
22043
+ continue;
22044
+ }
22045
+ _buffer = _buffer << 6 | decode(c.charCodeAt(0));
22046
+ _buflen += 6;
22047
+ }
22048
+ var n = _buffer >>> _buflen - 8 & 255;
22049
+ _buflen -= 8;
22050
+ return n;
22051
+ };
22052
+ var decode = function(c) {
22053
+ if (65 <= c && c <= 90) {
22054
+ return c - 65;
22055
+ } else if (97 <= c && c <= 122) {
22056
+ return c - 97 + 26;
22057
+ } else if (48 <= c && c <= 57) {
22058
+ return c - 48 + 52;
22059
+ } else if (c == 43) {
22060
+ return 62;
22061
+ } else if (c == 47) {
22062
+ return 63;
22063
+ } else {
22064
+ throw "c:" + c;
22065
+ }
22066
+ };
22067
+ return _this;
22068
+ };
22069
+ var gifImage = function(width, height) {
22070
+ var _width = width;
22071
+ var _height = height;
22072
+ var _data = new Array(width * height);
22073
+ var _this = {};
22074
+ _this.setPixel = function(x, y, pixel) {
22075
+ _data[y * _width + x] = pixel;
22076
+ };
22077
+ _this.write = function(out) {
22078
+ out.writeString("GIF87a");
22079
+ out.writeShort(_width);
22080
+ out.writeShort(_height);
22081
+ out.writeByte(128);
22082
+ out.writeByte(0);
22083
+ out.writeByte(0);
22084
+ out.writeByte(0);
22085
+ out.writeByte(0);
22086
+ out.writeByte(0);
22087
+ out.writeByte(255);
22088
+ out.writeByte(255);
22089
+ out.writeByte(255);
22090
+ out.writeString(",");
22091
+ out.writeShort(0);
22092
+ out.writeShort(0);
22093
+ out.writeShort(_width);
22094
+ out.writeShort(_height);
22095
+ out.writeByte(0);
22096
+ var lzwMinCodeSize = 2;
22097
+ var raster = getLZWRaster(lzwMinCodeSize);
22098
+ out.writeByte(lzwMinCodeSize);
22099
+ var offset = 0;
22100
+ while (raster.length - offset > 255) {
22101
+ out.writeByte(255);
22102
+ out.writeBytes(raster, offset, 255);
22103
+ offset += 255;
22104
+ }
22105
+ out.writeByte(raster.length - offset);
22106
+ out.writeBytes(raster, offset, raster.length - offset);
22107
+ out.writeByte(0);
22108
+ out.writeString(";");
22109
+ };
22110
+ var bitOutputStream = function(out) {
22111
+ var _out = out;
22112
+ var _bitLength = 0;
22113
+ var _bitBuffer = 0;
22114
+ var _this2 = {};
22115
+ _this2.write = function(data, length) {
22116
+ if (data >>> length != 0) {
22117
+ throw "length over";
22118
+ }
22119
+ while (_bitLength + length >= 8) {
22120
+ _out.writeByte(255 & (data << _bitLength | _bitBuffer));
22121
+ length -= 8 - _bitLength;
22122
+ data >>>= 8 - _bitLength;
22123
+ _bitBuffer = 0;
22124
+ _bitLength = 0;
22125
+ }
22126
+ _bitBuffer = data << _bitLength | _bitBuffer;
22127
+ _bitLength = _bitLength + length;
22128
+ };
22129
+ _this2.flush = function() {
22130
+ if (_bitLength > 0) {
22131
+ _out.writeByte(_bitBuffer);
22132
+ }
22133
+ };
22134
+ return _this2;
22135
+ };
22136
+ var getLZWRaster = function(lzwMinCodeSize) {
22137
+ var clearCode = 1 << lzwMinCodeSize;
22138
+ var endCode = (1 << lzwMinCodeSize) + 1;
22139
+ var bitLength = lzwMinCodeSize + 1;
22140
+ var table = lzwTable();
22141
+ for (var i = 0; i < clearCode; i += 1) {
22142
+ table.add(String.fromCharCode(i));
22143
+ }
22144
+ table.add(String.fromCharCode(clearCode));
22145
+ table.add(String.fromCharCode(endCode));
22146
+ var byteOut = byteArrayOutputStream();
22147
+ var bitOut = bitOutputStream(byteOut);
22148
+ bitOut.write(clearCode, bitLength);
22149
+ var dataIndex = 0;
22150
+ var s = String.fromCharCode(_data[dataIndex]);
22151
+ dataIndex += 1;
22152
+ while (dataIndex < _data.length) {
22153
+ var c = String.fromCharCode(_data[dataIndex]);
22154
+ dataIndex += 1;
22155
+ if (table.contains(s + c)) {
22156
+ s = s + c;
22157
+ } else {
22158
+ bitOut.write(table.indexOf(s), bitLength);
22159
+ if (table.size() < 4095) {
22160
+ if (table.size() == 1 << bitLength) {
22161
+ bitLength += 1;
22162
+ }
22163
+ table.add(s + c);
22164
+ }
22165
+ s = c;
22166
+ }
22167
+ }
22168
+ bitOut.write(table.indexOf(s), bitLength);
22169
+ bitOut.write(endCode, bitLength);
22170
+ bitOut.flush();
22171
+ return byteOut.toByteArray();
22172
+ };
22173
+ var lzwTable = function() {
22174
+ var _map = {};
22175
+ var _size = 0;
22176
+ var _this2 = {};
22177
+ _this2.add = function(key) {
22178
+ if (_this2.contains(key)) {
22179
+ throw "dup key:" + key;
22180
+ }
22181
+ _map[key] = _size;
22182
+ _size += 1;
22183
+ };
22184
+ _this2.size = function() {
22185
+ return _size;
22186
+ };
22187
+ _this2.indexOf = function(key) {
22188
+ return _map[key];
22189
+ };
22190
+ _this2.contains = function(key) {
22191
+ return typeof _map[key] != "undefined";
22192
+ };
22193
+ return _this2;
22194
+ };
22195
+ return _this;
22196
+ };
22197
+ var createDataURL = function(width, height, getPixel) {
22198
+ var gif = gifImage(width, height);
22199
+ for (var y = 0; y < height; y += 1) {
22200
+ for (var x = 0; x < width; x += 1) {
22201
+ gif.setPixel(x, y, getPixel(x, y));
22202
+ }
22203
+ }
22204
+ var b = byteArrayOutputStream();
22205
+ gif.write(b);
22206
+ var base64 = base64EncodeOutputStream();
22207
+ var bytes = b.toByteArray();
22208
+ for (var i = 0; i < bytes.length; i += 1) {
22209
+ base64.writeByte(bytes[i]);
22210
+ }
22211
+ base64.flush();
22212
+ return "data:image/gif;base64," + base64;
22213
+ };
22214
+ return qrcode2;
22215
+ })();
22216
+ !(function() {
22217
+ qrcode.stringToBytesFuncs["UTF-8"] = function(s) {
22218
+ function toUTF8Array(str) {
22219
+ var utf8 = [];
22220
+ for (var i = 0; i < str.length; i++) {
22221
+ var charcode = str.charCodeAt(i);
22222
+ if (charcode < 128) utf8.push(charcode);
22223
+ else if (charcode < 2048) {
22224
+ utf8.push(
22225
+ 192 | charcode >> 6,
22226
+ 128 | charcode & 63
22227
+ );
22228
+ } else if (charcode < 55296 || charcode >= 57344) {
22229
+ utf8.push(
22230
+ 224 | charcode >> 12,
22231
+ 128 | charcode >> 6 & 63,
22232
+ 128 | charcode & 63
22233
+ );
22234
+ } else {
22235
+ i++;
22236
+ charcode = 65536 + ((charcode & 1023) << 10 | str.charCodeAt(i) & 1023);
22237
+ utf8.push(
22238
+ 240 | charcode >> 18,
22239
+ 128 | charcode >> 12 & 63,
22240
+ 128 | charcode >> 6 & 63,
22241
+ 128 | charcode & 63
22242
+ );
22243
+ }
22244
+ }
22245
+ return utf8;
22246
+ }
22247
+ return toUTF8Array(s);
22248
+ };
22249
+ })();
22250
+ (function(factory) {
22251
+ if (typeof define === "function" && define.amd) {
22252
+ define([], factory);
22253
+ } else if (typeof exports2 === "object") {
22254
+ module2.exports = factory();
22255
+ }
22256
+ })(function() {
22257
+ return qrcode;
22258
+ });
22259
+ }
22260
+ });
22261
+
22262
+ // ../../packages/shuttle/dist/pairing/terminal.js
22263
+ var require_terminal = __commonJS({
22264
+ "../../packages/shuttle/dist/pairing/terminal.js"(exports2) {
22265
+ "use strict";
22266
+ var __importDefault = exports2 && exports2.__importDefault || function(mod) {
22267
+ return mod && mod.__esModule ? mod : { "default": mod };
22268
+ };
22269
+ Object.defineProperty(exports2, "__esModule", { value: true });
22270
+ exports2.renderPairingInvitation = renderPairingInvitation;
22271
+ exports2.hyperlink = hyperlink;
22272
+ exports2.qrBlock = qrBlock;
22273
+ var qrcode_generator_1 = __importDefault(require_qrcode());
22274
+ var INK = 0;
22275
+ var PAPER = 15;
22276
+ var HALF = "\u2580";
22277
+ var RESET = "\x1B[0m";
22278
+ var QUIET = 4;
22279
+ function renderPairingInvitation(invitation) {
22280
+ const lines = [invitation.header, ""];
22281
+ if (invitation.rich) {
22282
+ const code = qrBlock(invitation.verificationUriComplete, invitation.columns);
22283
+ if (code.length > 0) {
22284
+ lines.push(...code, "");
22285
+ }
22286
+ }
22287
+ lines.push(`Open: ${invitation.rich ? hyperlink(invitation.verificationUriComplete) : invitation.verificationUriComplete}`);
22288
+ lines.push(`User code: ${invitation.userCode}`);
22289
+ lines.push("");
22290
+ lines.push(`Waiting for verification (expires in ${invitation.expiresIn}s)...`);
22291
+ return lines;
22292
+ }
22293
+ function hyperlink(url, label = url) {
22294
+ return `\x1B]8;;${url}\x1B\\${label}\x1B]8;;\x1B\\`;
22295
+ }
22296
+ function qrBlock(text, columns) {
22297
+ const qr = (0, qrcode_generator_1.default)(0, "M");
22298
+ qr.addData(text);
22299
+ qr.make();
22300
+ const count = qr.getModuleCount();
22301
+ const size = count + QUIET * 2;
22302
+ if (columns !== void 0 && size > columns)
22303
+ return [];
22304
+ const dark = (row, column) => {
22305
+ const r = row - QUIET;
22306
+ const c = column - QUIET;
22307
+ if (r < 0 || c < 0 || r >= count || c >= count)
22308
+ return false;
22309
+ return qr.isDark(r, c);
22310
+ };
22311
+ const lines = [];
22312
+ for (let row = 0; row < size; row += 2) {
22313
+ let line = "";
22314
+ for (let column = 0; column < size; column++) {
22315
+ const top = dark(row, column) ? INK : PAPER;
22316
+ const bottom = row + 1 < size && dark(row + 1, column) ? INK : PAPER;
22317
+ line += `\x1B[38;5;${top};48;5;${bottom}m${HALF}`;
22318
+ }
22319
+ lines.push(line + RESET);
22320
+ }
22321
+ return lines;
22322
+ }
22323
+ }
22324
+ });
22325
+
20575
22326
  // ../../packages/shuttle/dist/pairing/device-code.js
20576
22327
  var require_device_code = __commonJS({
20577
22328
  "../../packages/shuttle/dist/pairing/device-code.js"(exports2) {
20578
22329
  "use strict";
20579
22330
  Object.defineProperty(exports2, "__esModule", { value: true });
20580
22331
  exports2.pair = pair;
22332
+ exports2.webFirstRemedy = webFirstRemedy;
20581
22333
  var os_1 = require("os");
20582
22334
  var apply_1 = require_apply();
20583
22335
  var version_check_1 = require_version_check();
22336
+ var typed_exit_1 = require_typed_exit();
22337
+ var terminal_1 = require_terminal();
20584
22338
  async function pair(opts) {
20585
22339
  const fetcher = opts.fetcher ?? globalThis.fetch;
20586
22340
  const log = opts.log ?? ((line) => console.log(line));
@@ -20602,18 +22356,30 @@ var require_device_code = __commonJS({
20602
22356
  });
20603
22357
  log(opts.brand.strings?.pairingDoneMessage ?? `Paired ${displayName}.`);
20604
22358
  } else {
20605
- const device = await startDeviceCode({
20606
- keepApiUrl: reg.keepApiUrl,
20607
- oauthClientId: reg.oauthClientId,
20608
- fetcher,
20609
- brand: opts.brand
22359
+ let device;
22360
+ try {
22361
+ device = await startDeviceCode({
22362
+ keepApiUrl: reg.keepApiUrl,
22363
+ oauthClientId: reg.oauthClientId,
22364
+ fetcher,
22365
+ brand: opts.brand
22366
+ });
22367
+ } catch (err) {
22368
+ if ((0, typed_exit_1.isTypedExit)(err))
22369
+ throw err;
22370
+ throw new Error(webFirstRemedy(opts.brand, err));
22371
+ }
22372
+ const invitation = (0, terminal_1.renderPairingInvitation)({
22373
+ header: opts.brand.strings?.pairingHeader ?? `Pair your ${opts.brand.product.title}`,
22374
+ verificationUri: device.verificationUri,
22375
+ verificationUriComplete: device.verificationUriComplete ?? device.verificationUri,
22376
+ userCode: device.userCode,
22377
+ expiresIn: device.expiresIn,
22378
+ rich: opts.rich ?? Boolean(process.stdout.isTTY),
22379
+ ...columnsOf(opts) !== void 0 ? { columns: columnsOf(opts) } : {}
20610
22380
  });
20611
- log(opts.brand.strings?.pairingHeader ?? `Pair your ${opts.brand.product.title}`);
20612
- log("");
20613
- log(`Visit: ${device.verificationUri}`);
20614
- log(`User code: ${device.userCode}`);
20615
- log("");
20616
- log(`Waiting for verification (expires in ${device.expiresIn}s)...`);
22381
+ for (const line of invitation)
22382
+ log(line);
20617
22383
  token = await pollForToken({
20618
22384
  keepApiUrl: reg.keepApiUrl,
20619
22385
  oauthClientId: reg.oauthClientId,
@@ -20681,6 +22447,19 @@ var require_device_code = __commonJS({
20681
22447
  const poolsJson = await readJson(poolsRes);
20682
22448
  return poolsJson.data.pools;
20683
22449
  }
22450
+ function webFirstRemedy(brand, cause) {
22451
+ const reason = cause instanceof Error ? cause.message : String(cause);
22452
+ const where = brand.product.webPairingUrl ? brand.product.webPairingUrl : `your ${brand.product.title} web app, under Settings, Sifters`;
22453
+ return [
22454
+ `Could not start browser pairing: ${reason}`,
22455
+ "",
22456
+ `Pair from the web instead: open ${where}, press Pair a Sifter, and run the`,
22457
+ `command it shows (${brand.product.cliBinary} init --pairing-code=<code>).`
22458
+ ].join("\n");
22459
+ }
22460
+ function columnsOf(opts) {
22461
+ return opts.columns ?? process.stdout.columns;
22462
+ }
20684
22463
  async function startDeviceCode(opts) {
20685
22464
  const url = `${opts.keepApiUrl.replace(/\/$/, "")}/api/oauth/device`;
20686
22465
  const response = await opts.fetcher(url, {
@@ -23480,7 +25259,7 @@ var import_path = require("path");
23480
25259
  var import_promises = require("fs/promises");
23481
25260
  var import_yaml = __toESM(require_dist4());
23482
25261
  var import_shuttle = __toESM(require_dist5());
23483
- var buildVersion = true ? "0.28.0" : pkg.version;
25262
+ var buildVersion = true ? "0.29.0" : pkg.version;
23484
25263
  var sifterBrand = {
23485
25264
  product: {
23486
25265
  id: "sifter",
@@ -23488,7 +25267,12 @@ var sifterBrand = {
23488
25267
  cliBinary: "whittle-sifter",
23489
25268
  packageName: "@whittlelabs/sifter",
23490
25269
  version: buildVersion,
23491
- description: "Pairs with Whittle Sift to run AI code reviews on your hardware with your credentials."
25270
+ description: "Pairs with Whittle Sift to run AI code reviews on your hardware with your credentials.",
25271
+ // Production's own pairing page. The published binary defaults to the
25272
+ // production backend, so this is the surface the person holding that
25273
+ // binary actually has; a non-prod pairing arrives with its command
25274
+ // already built by the tier that printed it.
25275
+ webPairingUrl: "https://sift.whittlelabs.com/settings/sifters"
23492
25276
  },
23493
25277
  paths: {
23494
25278
  configDir: "~/.sifter",
@@ -23642,7 +25426,16 @@ async function buildExecutorBlock(executor, ctx) {
23642
25426
  console.error("Keep refused its credentials \u2014 it was decommissioned from the");
23643
25427
  console.error("web app, or its secret was rotated by a newer pairing.");
23644
25428
  console.error("");
23645
- console.error(`Run \`${sifterBrand.product.cliBinary} init\` to pair again.`);
25429
+ console.error("Two ways to pair again:");
25430
+ console.error("");
25431
+ console.error(
25432
+ ` 1. Run \`${sifterBrand.product.cliBinary} init\` and scan the QR code it prints,`
25433
+ );
25434
+ console.error(" or open the link beside it.");
25435
+ console.error(
25436
+ ` 2. Open ${sifterBrand.product.webPairingUrl ?? "the web app, under Settings, Sifters"},`
25437
+ );
25438
+ console.error(" press Pair a Sifter, and run the command it shows.");
23646
25439
  console.error("");
23647
25440
  process.exit(3);
23648
25441
  }