UNPKG

@freeunionp/btcdonate

Version:

A standalone React component for BTC donations.

1,343 lines (1,335 loc) 52.8 kB
import y, { useState as T, useEffect as G, useCallback as ge } from "react"; var V = { exports: {} }, U = {}; /** * @license React * react-jsx-runtime.production.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var Z; function xe() { if (Z) return U; Z = 1; var d = Symbol.for("react.transitional.element"), a = Symbol.for("react.fragment"); function s(l, h, u) { var E = null; if (u !== void 0 && (E = "" + u), h.key !== void 0 && (E = "" + h.key), "key" in h) { u = {}; for (var w in h) w !== "key" && (u[w] = h[w]); } else u = h; return h = u.ref, { $$typeof: d, type: l, key: E, ref: h !== void 0 ? h : null, props: u }; } return U.Fragment = a, U.jsx = s, U.jsxs = s, U; } var q; function we() { return q || (q = 1, V.exports = xe()), V.exports; } var x = we(), Ce = Object.defineProperty, $ = Object.getOwnPropertySymbols, ee = Object.prototype.hasOwnProperty, te = Object.prototype.propertyIsEnumerable, K = (d, a, s) => a in d ? Ce(d, a, { enumerable: !0, configurable: !0, writable: !0, value: s }) : d[a] = s, X = (d, a) => { for (var s in a || (a = {})) ee.call(a, s) && K(d, s, a[s]); if ($) for (var s of $(a)) te.call(a, s) && K(d, s, a[s]); return d; }, J = (d, a) => { var s = {}; for (var l in d) ee.call(d, l) && a.indexOf(l) < 0 && (s[l] = d[l]); if (d != null && $) for (var l of $(d)) a.indexOf(l) < 0 && te.call(d, l) && (s[l] = d[l]); return s; }; /** * @license QR Code generator library (TypeScript) * Copyright (c) Project Nayuki. * SPDX-License-Identifier: MIT */ var O; ((d) => { const a = class g { /*-- Constructor (low level) and fields --*/ // Creates a new QR Code with the given version number, // error correction level, data codeword bytes, and mask number. // This is a low-level API that most users should not use directly. // A mid-level API is the encodeSegments() function. constructor(e, o, t, r) { if (this.version = e, this.errorCorrectionLevel = o, this.modules = [], this.isFunction = [], e < g.MIN_VERSION || e > g.MAX_VERSION) throw new RangeError("Version value out of range"); if (r < -1 || r > 7) throw new RangeError("Mask value out of range"); this.size = e * 4 + 17; let n = []; for (let i = 0; i < this.size; i++) n.push(!1); for (let i = 0; i < this.size; i++) this.modules.push(n.slice()), this.isFunction.push(n.slice()); this.drawFunctionPatterns(); const c = this.addEccAndInterleave(t); if (this.drawCodewords(c), r == -1) { let i = 1e9; for (let p = 0; p < 8; p++) { this.applyMask(p), this.drawFormatBits(p); const f = this.getPenaltyScore(); f < i && (r = p, i = f), this.applyMask(p); } } h(0 <= r && r <= 7), this.mask = r, this.applyMask(r), this.drawFormatBits(r), this.isFunction = []; } /*-- Static factory functions (high level) --*/ // Returns a QR Code representing the given Unicode text string at the given error correction level. // As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer // Unicode code points (not UTF-16 code units) if the low error correction level is used. The smallest possible // QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the // ecl argument if it can be done without increasing the version. static encodeText(e, o) { const t = d.QrSegment.makeSegments(e); return g.encodeSegments(t, o); } // Returns a QR Code representing the given binary data at the given error correction level. // This function always encodes using the binary segment mode, not any text mode. The maximum number of // bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output. // The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version. static encodeBinary(e, o) { const t = d.QrSegment.makeBytes(e); return g.encodeSegments([t], o); } /*-- Static factory functions (mid level) --*/ // Returns a QR Code representing the given segments with the given encoding parameters. // The smallest possible QR Code version within the given range is automatically // chosen for the output. Iff boostEcl is true, then the ECC level of the result // may be higher than the ecl argument if it can be done without increasing the // version. The mask number is either between 0 to 7 (inclusive) to force that // mask, or -1 to automatically choose an appropriate mask (which may be slow). // This function allows the user to create a custom sequence of segments that switches // between modes (such as alphanumeric and byte) to encode text in less space. // This is a mid-level API; the high-level API is encodeText() and encodeBinary(). static encodeSegments(e, o, t = 1, r = 40, n = -1, c = !0) { if (!(g.MIN_VERSION <= t && t <= r && r <= g.MAX_VERSION) || n < -1 || n > 7) throw new RangeError("Invalid value"); let i, p; for (i = t; ; i++) { const m = g.getNumDataCodewords(i, o) * 8, R = E.getTotalBits(e, i); if (R <= m) { p = R; break; } if (i >= r) throw new RangeError("Data too long"); } for (const m of [g.Ecc.MEDIUM, g.Ecc.QUARTILE, g.Ecc.HIGH]) c && p <= g.getNumDataCodewords(i, m) * 8 && (o = m); let f = []; for (const m of e) { s(m.mode.modeBits, 4, f), s(m.numChars, m.mode.numCharCountBits(i), f); for (const R of m.getData()) f.push(R); } h(f.length == p); const N = g.getNumDataCodewords(i, o) * 8; h(f.length <= N), s(0, Math.min(4, N - f.length), f), s(0, (8 - f.length % 8) % 8, f), h(f.length % 8 == 0); for (let m = 236; f.length < N; m ^= 253) s(m, 8, f); let v = []; for (; v.length * 8 < f.length; ) v.push(0); return f.forEach((m, R) => v[R >>> 3] |= m << 7 - (R & 7)), new g(i, o, v, n); } /*-- Accessor methods --*/ // Returns the color of the module (pixel) at the given coordinates, which is false // for light or true for dark. The top left corner has the coordinates (x=0, y=0). // If the given coordinates are out of bounds, then false (light) is returned. getModule(e, o) { return 0 <= e && e < this.size && 0 <= o && o < this.size && this.modules[o][e]; } // Modified to expose modules for easy access getModules() { return this.modules; } /*-- Private helper methods for constructor: Drawing function modules --*/ // Reads this object's version field, and draws and marks all function modules. drawFunctionPatterns() { for (let t = 0; t < this.size; t++) this.setFunctionModule(6, t, t % 2 == 0), this.setFunctionModule(t, 6, t % 2 == 0); this.drawFinderPattern(3, 3), this.drawFinderPattern(this.size - 4, 3), this.drawFinderPattern(3, this.size - 4); const e = this.getAlignmentPatternPositions(), o = e.length; for (let t = 0; t < o; t++) for (let r = 0; r < o; r++) t == 0 && r == 0 || t == 0 && r == o - 1 || t == o - 1 && r == 0 || this.drawAlignmentPattern(e[t], e[r]); this.drawFormatBits(0), this.drawVersion(); } // Draws two copies of the format bits (with its own error correction code) // based on the given mask and this object's error correction level field. drawFormatBits(e) { const o = this.errorCorrectionLevel.formatBits << 3 | e; let t = o; for (let n = 0; n < 10; n++) t = t << 1 ^ (t >>> 9) * 1335; const r = (o << 10 | t) ^ 21522; h(r >>> 15 == 0); for (let n = 0; n <= 5; n++) this.setFunctionModule(8, n, l(r, n)); this.setFunctionModule(8, 7, l(r, 6)), this.setFunctionModule(8, 8, l(r, 7)), this.setFunctionModule(7, 8, l(r, 8)); for (let n = 9; n < 15; n++) this.setFunctionModule(14 - n, 8, l(r, n)); for (let n = 0; n < 8; n++) this.setFunctionModule(this.size - 1 - n, 8, l(r, n)); for (let n = 8; n < 15; n++) this.setFunctionModule(8, this.size - 15 + n, l(r, n)); this.setFunctionModule(8, this.size - 8, !0); } // Draws two copies of the version bits (with its own error correction code), // based on this object's version field, iff 7 <= version <= 40. drawVersion() { if (this.version < 7) return; let e = this.version; for (let t = 0; t < 12; t++) e = e << 1 ^ (e >>> 11) * 7973; const o = this.version << 12 | e; h(o >>> 18 == 0); for (let t = 0; t < 18; t++) { const r = l(o, t), n = this.size - 11 + t % 3, c = Math.floor(t / 3); this.setFunctionModule(n, c, r), this.setFunctionModule(c, n, r); } } // Draws a 9*9 finder pattern including the border separator, // with the center module at (x, y). Modules can be out of bounds. drawFinderPattern(e, o) { for (let t = -4; t <= 4; t++) for (let r = -4; r <= 4; r++) { const n = Math.max(Math.abs(r), Math.abs(t)), c = e + r, i = o + t; 0 <= c && c < this.size && 0 <= i && i < this.size && this.setFunctionModule(c, i, n != 2 && n != 4); } } // Draws a 5*5 alignment pattern, with the center module // at (x, y). All modules must be in bounds. drawAlignmentPattern(e, o) { for (let t = -2; t <= 2; t++) for (let r = -2; r <= 2; r++) this.setFunctionModule(e + r, o + t, Math.max(Math.abs(r), Math.abs(t)) != 1); } // Sets the color of a module and marks it as a function module. // Only used by the constructor. Coordinates must be in bounds. setFunctionModule(e, o, t) { this.modules[o][e] = t, this.isFunction[o][e] = !0; } /*-- Private helper methods for constructor: Codewords and masking --*/ // Returns a new byte string representing the given data with the appropriate error correction // codewords appended to it, based on this object's version and error correction level. addEccAndInterleave(e) { const o = this.version, t = this.errorCorrectionLevel; if (e.length != g.getNumDataCodewords(o, t)) throw new RangeError("Invalid argument"); const r = g.NUM_ERROR_CORRECTION_BLOCKS[t.ordinal][o], n = g.ECC_CODEWORDS_PER_BLOCK[t.ordinal][o], c = Math.floor(g.getNumRawDataModules(o) / 8), i = r - c % r, p = Math.floor(c / r); let f = []; const N = g.reedSolomonComputeDivisor(n); for (let m = 0, R = 0; m < r; m++) { let M = e.slice(R, R + p - n + (m < i ? 0 : 1)); R += M.length; const P = g.reedSolomonComputeRemainder(M, N); m < i && M.push(0), f.push(M.concat(P)); } let v = []; for (let m = 0; m < f[0].length; m++) f.forEach((R, M) => { (m != p - n || M >= i) && v.push(R[m]); }); return h(v.length == c), v; } // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire // data area of this QR Code. Function modules need to be marked off before this is called. drawCodewords(e) { if (e.length != Math.floor(g.getNumRawDataModules(this.version) / 8)) throw new RangeError("Invalid argument"); let o = 0; for (let t = this.size - 1; t >= 1; t -= 2) { t == 6 && (t = 5); for (let r = 0; r < this.size; r++) for (let n = 0; n < 2; n++) { const c = t - n, p = (t + 1 & 2) == 0 ? this.size - 1 - r : r; !this.isFunction[p][c] && o < e.length * 8 && (this.modules[p][c] = l(e[o >>> 3], 7 - (o & 7)), o++); } } h(o == e.length * 8); } // XORs the codeword modules in this QR Code with the given mask pattern. // The function modules must be marked and the codeword bits must be drawn // before masking. Due to the arithmetic of XOR, calling applyMask() with // the same mask value a second time will undo the mask. A final well-formed // QR Code needs exactly one (not zero, two, etc.) mask applied. applyMask(e) { if (e < 0 || e > 7) throw new RangeError("Mask value out of range"); for (let o = 0; o < this.size; o++) for (let t = 0; t < this.size; t++) { let r; switch (e) { case 0: r = (t + o) % 2 == 0; break; case 1: r = o % 2 == 0; break; case 2: r = t % 3 == 0; break; case 3: r = (t + o) % 3 == 0; break; case 4: r = (Math.floor(t / 3) + Math.floor(o / 2)) % 2 == 0; break; case 5: r = t * o % 2 + t * o % 3 == 0; break; case 6: r = (t * o % 2 + t * o % 3) % 2 == 0; break; case 7: r = ((t + o) % 2 + t * o % 3) % 2 == 0; break; default: throw new Error("Unreachable"); } !this.isFunction[o][t] && r && (this.modules[o][t] = !this.modules[o][t]); } } // Calculates and returns the penalty score based on state of this QR Code's current modules. // This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score. getPenaltyScore() { let e = 0; for (let n = 0; n < this.size; n++) { let c = !1, i = 0, p = [0, 0, 0, 0, 0, 0, 0]; for (let f = 0; f < this.size; f++) this.modules[n][f] == c ? (i++, i == 5 ? e += g.PENALTY_N1 : i > 5 && e++) : (this.finderPenaltyAddHistory(i, p), c || (e += this.finderPenaltyCountPatterns(p) * g.PENALTY_N3), c = this.modules[n][f], i = 1); e += this.finderPenaltyTerminateAndCount(c, i, p) * g.PENALTY_N3; } for (let n = 0; n < this.size; n++) { let c = !1, i = 0, p = [0, 0, 0, 0, 0, 0, 0]; for (let f = 0; f < this.size; f++) this.modules[f][n] == c ? (i++, i == 5 ? e += g.PENALTY_N1 : i > 5 && e++) : (this.finderPenaltyAddHistory(i, p), c || (e += this.finderPenaltyCountPatterns(p) * g.PENALTY_N3), c = this.modules[f][n], i = 1); e += this.finderPenaltyTerminateAndCount(c, i, p) * g.PENALTY_N3; } for (let n = 0; n < this.size - 1; n++) for (let c = 0; c < this.size - 1; c++) { const i = this.modules[n][c]; i == this.modules[n][c + 1] && i == this.modules[n + 1][c] && i == this.modules[n + 1][c + 1] && (e += g.PENALTY_N2); } let o = 0; for (const n of this.modules) o = n.reduce((c, i) => c + (i ? 1 : 0), o); const t = this.size * this.size, r = Math.ceil(Math.abs(o * 20 - t * 10) / t) - 1; return h(0 <= r && r <= 9), e += r * g.PENALTY_N4, h(0 <= e && e <= 2568888), e; } /*-- Private helper functions --*/ // Returns an ascending list of positions of alignment patterns for this version number. // Each position is in the range [0,177), and are used on both the x and y axes. // This could be implemented as lookup table of 40 variable-length lists of integers. getAlignmentPatternPositions() { if (this.version == 1) return []; { const e = Math.floor(this.version / 7) + 2, o = this.version == 32 ? 26 : Math.ceil((this.version * 4 + 4) / (e * 2 - 2)) * 2; let t = [6]; for (let r = this.size - 7; t.length < e; r -= o) t.splice(1, 0, r); return t; } } // Returns the number of data bits that can be stored in a QR Code of the given version number, after // all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8. // The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table. static getNumRawDataModules(e) { if (e < g.MIN_VERSION || e > g.MAX_VERSION) throw new RangeError("Version number out of range"); let o = (16 * e + 128) * e + 64; if (e >= 2) { const t = Math.floor(e / 7) + 2; o -= (25 * t - 10) * t - 55, e >= 7 && (o -= 36); } return h(208 <= o && o <= 29648), o; } // Returns the number of 8-bit data (i.e. not error correction) codewords contained in any // QR Code of the given version number and error correction level, with remainder bits discarded. // This stateless pure function could be implemented as a (40*4)-cell lookup table. static getNumDataCodewords(e, o) { return Math.floor(g.getNumRawDataModules(e) / 8) - g.ECC_CODEWORDS_PER_BLOCK[o.ordinal][e] * g.NUM_ERROR_CORRECTION_BLOCKS[o.ordinal][e]; } // Returns a Reed-Solomon ECC generator polynomial for the given degree. This could be // implemented as a lookup table over all possible parameter values, instead of as an algorithm. static reedSolomonComputeDivisor(e) { if (e < 1 || e > 255) throw new RangeError("Degree out of range"); let o = []; for (let r = 0; r < e - 1; r++) o.push(0); o.push(1); let t = 1; for (let r = 0; r < e; r++) { for (let n = 0; n < o.length; n++) o[n] = g.reedSolomonMultiply(o[n], t), n + 1 < o.length && (o[n] ^= o[n + 1]); t = g.reedSolomonMultiply(t, 2); } return o; } // Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials. static reedSolomonComputeRemainder(e, o) { let t = o.map((r) => 0); for (const r of e) { const n = r ^ t.shift(); t.push(0), o.forEach((c, i) => t[i] ^= g.reedSolomonMultiply(c, n)); } return t; } // Returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and result // are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8. static reedSolomonMultiply(e, o) { if (e >>> 8 || o >>> 8) throw new RangeError("Byte out of range"); let t = 0; for (let r = 7; r >= 0; r--) t = t << 1 ^ (t >>> 7) * 285, t ^= (o >>> r & 1) * e; return h(t >>> 8 == 0), t; } // Can only be called immediately after a light run is added, and // returns either 0, 1, or 2. A helper function for getPenaltyScore(). finderPenaltyCountPatterns(e) { const o = e[1]; h(o <= this.size * 3); const t = o > 0 && e[2] == o && e[3] == o * 3 && e[4] == o && e[5] == o; return (t && e[0] >= o * 4 && e[6] >= o ? 1 : 0) + (t && e[6] >= o * 4 && e[0] >= o ? 1 : 0); } // Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore(). finderPenaltyTerminateAndCount(e, o, t) { return e && (this.finderPenaltyAddHistory(o, t), o = 0), o += this.size, this.finderPenaltyAddHistory(o, t), this.finderPenaltyCountPatterns(t); } // Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore(). finderPenaltyAddHistory(e, o) { o[0] == 0 && (e += this.size), o.pop(), o.unshift(e); } }; a.MIN_VERSION = 1, a.MAX_VERSION = 40, a.PENALTY_N1 = 3, a.PENALTY_N2 = 3, a.PENALTY_N3 = 40, a.PENALTY_N4 = 10, a.ECC_CODEWORDS_PER_BLOCK = [ // Version: (note that index 0 is for padding, and is set to an illegal value) //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level [-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // Low [-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28], // Medium [-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // Quartile [-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30] // High ], a.NUM_ERROR_CORRECTION_BLOCKS = [ // Version: (note that index 0 is for padding, and is set to an illegal value) //0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level [-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25], // Low [-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49], // Medium [-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68], // Quartile [-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81] // High ], d.QrCode = a; function s(w, e, o) { if (e < 0 || e > 31 || w >>> e) throw new RangeError("Value out of range"); for (let t = e - 1; t >= 0; t--) o.push(w >>> t & 1); } function l(w, e) { return (w >>> e & 1) != 0; } function h(w) { if (!w) throw new Error("Assertion error"); } const u = class b { /*-- Constructor (low level) and fields --*/ // Creates a new QR Code segment with the given attributes and data. // The character count (numChars) must agree with the mode and the bit buffer length, // but the constraint isn't checked. The given bit buffer is cloned and stored. constructor(e, o, t) { if (this.mode = e, this.numChars = o, this.bitData = t, o < 0) throw new RangeError("Invalid argument"); this.bitData = t.slice(); } /*-- Static factory functions (mid level) --*/ // Returns a segment representing the given binary data encoded in // byte mode. All input byte arrays are acceptable. Any text string // can be converted to UTF-8 bytes and encoded as a byte mode segment. static makeBytes(e) { let o = []; for (const t of e) s(t, 8, o); return new b(b.Mode.BYTE, e.length, o); } // Returns a segment representing the given string of decimal digits encoded in numeric mode. static makeNumeric(e) { if (!b.isNumeric(e)) throw new RangeError("String contains non-numeric characters"); let o = []; for (let t = 0; t < e.length; ) { const r = Math.min(e.length - t, 3); s(parseInt(e.substring(t, t + r), 10), r * 3 + 1, o), t += r; } return new b(b.Mode.NUMERIC, e.length, o); } // Returns a segment representing the given text string encoded in alphanumeric mode. // The characters allowed are: 0 to 9, A to Z (uppercase only), space, // dollar, percent, asterisk, plus, hyphen, period, slash, colon. static makeAlphanumeric(e) { if (!b.isAlphanumeric(e)) throw new RangeError("String contains unencodable characters in alphanumeric mode"); let o = [], t; for (t = 0; t + 2 <= e.length; t += 2) { let r = b.ALPHANUMERIC_CHARSET.indexOf(e.charAt(t)) * 45; r += b.ALPHANUMERIC_CHARSET.indexOf(e.charAt(t + 1)), s(r, 11, o); } return t < e.length && s(b.ALPHANUMERIC_CHARSET.indexOf(e.charAt(t)), 6, o), new b(b.Mode.ALPHANUMERIC, e.length, o); } // Returns a new mutable list of zero or more segments to represent the given Unicode text string. // The result may use various segment modes and switch modes to optimize the length of the bit stream. static makeSegments(e) { return e == "" ? [] : b.isNumeric(e) ? [b.makeNumeric(e)] : b.isAlphanumeric(e) ? [b.makeAlphanumeric(e)] : [b.makeBytes(b.toUtf8ByteArray(e))]; } // Returns a segment representing an Extended Channel Interpretation // (ECI) designator with the given assignment value. static makeEci(e) { let o = []; if (e < 0) throw new RangeError("ECI assignment value out of range"); if (e < 128) s(e, 8, o); else if (e < 16384) s(2, 2, o), s(e, 14, o); else if (e < 1e6) s(6, 3, o), s(e, 21, o); else throw new RangeError("ECI assignment value out of range"); return new b(b.Mode.ECI, 0, o); } // Tests whether the given string can be encoded as a segment in numeric mode. // A string is encodable iff each character is in the range 0 to 9. static isNumeric(e) { return b.NUMERIC_REGEX.test(e); } // Tests whether the given string can be encoded as a segment in alphanumeric mode. // A string is encodable iff each character is in the following set: 0 to 9, A to Z // (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon. static isAlphanumeric(e) { return b.ALPHANUMERIC_REGEX.test(e); } /*-- Methods --*/ // Returns a new copy of the data bits of this segment. getData() { return this.bitData.slice(); } // (Package-private) Calculates and returns the number of bits needed to encode the given segments at // the given version. The result is infinity if a segment has too many characters to fit its length field. static getTotalBits(e, o) { let t = 0; for (const r of e) { const n = r.mode.numCharCountBits(o); if (r.numChars >= 1 << n) return 1 / 0; t += 4 + n + r.bitData.length; } return t; } // Returns a new array of bytes representing the given string encoded in UTF-8. static toUtf8ByteArray(e) { e = encodeURI(e); let o = []; for (let t = 0; t < e.length; t++) e.charAt(t) != "%" ? o.push(e.charCodeAt(t)) : (o.push(parseInt(e.substring(t + 1, t + 3), 16)), t += 2); return o; } }; u.NUMERIC_REGEX = /^[0-9]*$/, u.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/, u.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"; let E = u; d.QrSegment = u; })(O || (O = {})); ((d) => { ((a) => { const s = class { // The QR Code can tolerate about 30% erroneous codewords /*-- Constructor and fields --*/ constructor(h, u) { this.ordinal = h, this.formatBits = u; } }; s.LOW = new s(0, 1), s.MEDIUM = new s(1, 0), s.QUARTILE = new s(2, 3), s.HIGH = new s(3, 2), a.Ecc = s; })(d.QrCode || (d.QrCode = {})); })(O || (O = {})); ((d) => { ((a) => { const s = class { /*-- Constructor and fields --*/ constructor(h, u) { this.modeBits = h, this.numBitsCharCount = u; } /*-- Method --*/ // (Package-private) Returns the bit width of the character count field for a segment in // this mode in a QR Code at the given version number. The result is in the range [0, 16]. numCharCountBits(h) { return this.numBitsCharCount[Math.floor((h + 7) / 17)]; } }; s.NUMERIC = new s(1, [10, 12, 14]), s.ALPHANUMERIC = new s(2, [9, 11, 13]), s.BYTE = new s(4, [8, 16, 16]), s.KANJI = new s(8, [8, 10, 12]), s.ECI = new s(7, [0, 0, 0]), a.Mode = s; })(d.QrSegment || (d.QrSegment = {})); })(O || (O = {})); var F = O; /** * @license qrcode.react * Copyright (c) Paul O'Shannessy * SPDX-License-Identifier: ISC */ var Ee = { L: F.QrCode.Ecc.LOW, M: F.QrCode.Ecc.MEDIUM, Q: F.QrCode.Ecc.QUARTILE, H: F.QrCode.Ecc.HIGH }, oe = 128, re = "L", ne = "#FFFFFF", se = "#000000", ie = !1, ae = 1, be = 4, Re = 0, ve = 0.1; function le(d, a = 0) { const s = []; return d.forEach(function(l, h) { let u = null; l.forEach(function(E, w) { if (!E && u !== null) { s.push( `M${u + a} ${h + a}h${w - u}v1H${u + a}z` ), u = null; return; } if (w === l.length - 1) { if (!E) return; u === null ? s.push(`M${w + a},${h + a} h1v1H${w + a}z`) : s.push( `M${u + a},${h + a} h${w + 1 - u}v1H${u + a}z` ); return; } E && u === null && (u = w); }); }), s.join(""); } function ce(d, a) { return d.slice().map((s, l) => l < a.y || l >= a.y + a.h ? s : s.map((h, u) => u < a.x || u >= a.x + a.w ? h : !1)); } function ye(d, a, s, l) { if (l == null) return null; const h = d.length + s * 2, u = Math.floor(a * ve), E = h / a, w = (l.width || u) * E, e = (l.height || u) * E, o = l.x == null ? d.length / 2 - w / 2 : l.x * E, t = l.y == null ? d.length / 2 - e / 2 : l.y * E, r = l.opacity == null ? 1 : l.opacity; let n = null; if (l.excavate) { let i = Math.floor(o), p = Math.floor(t), f = Math.ceil(w + o - i), N = Math.ceil(e + t - p); n = { x: i, y: p, w: f, h: N }; } const c = l.crossOrigin; return { x: o, y: t, h: e, w, excavation: n, opacity: r, crossOrigin: c }; } function Me(d, a) { return a != null ? Math.max(Math.floor(a), 0) : d ? be : Re; } function de({ value: d, level: a, minVersion: s, includeMargin: l, marginSize: h, imageSettings: u, size: E, boostLevel: w }) { let e = y.useMemo(() => { const i = (Array.isArray(d) ? d : [d]).reduce((p, f) => (p.push(...F.QrSegment.makeSegments(f)), p), []); return F.QrCode.encodeSegments( i, Ee[a], s, void 0, void 0, w ); }, [d, a, s, w]); const { cells: o, margin: t, numCells: r, calculatedImageSettings: n } = y.useMemo(() => { let c = e.getModules(); const i = Me(l, h), p = c.length + i * 2, f = ye( c, E, i, u ); return { cells: c, margin: i, numCells: p, calculatedImageSettings: f }; }, [e, E, u, l, h]); return { qrcode: e, margin: t, cells: o, numCells: r, calculatedImageSettings: n }; } var Ae = function() { try { new Path2D().addPath(new Path2D()); } catch { return !1; } return !0; }(), ue = y.forwardRef( function(a, s) { const l = a, { value: h, size: u = oe, level: E = re, bgColor: w = ne, fgColor: e = se, includeMargin: o = ie, minVersion: t = ae, boostLevel: r, marginSize: n, imageSettings: c } = l, p = J(l, [ "value", "size", "level", "bgColor", "fgColor", "includeMargin", "minVersion", "boostLevel", "marginSize", "imageSettings" ]), { style: f } = p, N = J(p, ["style"]), v = c?.src, m = y.useRef(null), R = y.useRef(null), M = y.useCallback( (L) => { m.current = L, typeof s == "function" ? s(L) : s && (s.current = L); }, [s] ), [P, _] = y.useState(!1), { margin: k, cells: B, numCells: j, calculatedImageSettings: S } = de({ value: h, level: E, minVersion: t, boostLevel: r, includeMargin: o, marginSize: n, imageSettings: c, size: u }); y.useEffect(() => { if (m.current != null) { const L = m.current, I = L.getContext("2d"); if (!I) return; let C = B; const A = R.current, z = S != null && A !== null && A.complete && A.naturalHeight !== 0 && A.naturalWidth !== 0; z && S.excavation != null && (C = ce( B, S.excavation )); const Y = window.devicePixelRatio || 1; L.height = L.width = u * Y; const D = u / j * Y; I.scale(D, D), I.fillStyle = w, I.fillRect(0, 0, j, j), I.fillStyle = e, Ae ? I.fill(new Path2D(le(C, k))) : B.forEach(function(he, fe) { he.forEach(function(pe, me) { pe && I.fillRect(me + k, fe + k, 1, 1); }); }), S && (I.globalAlpha = S.opacity), z && I.drawImage( A, S.x + k, S.y + k, S.w, S.h ); } }), y.useEffect(() => { _(!1); }, [v]); const H = X({ height: u, width: u }, f); let Q = null; return v != null && (Q = /* @__PURE__ */ y.createElement( "img", { src: v, key: v, style: { display: "none" }, onLoad: () => { _(!0); }, ref: R, crossOrigin: S?.crossOrigin } )), /* @__PURE__ */ y.createElement(y.Fragment, null, /* @__PURE__ */ y.createElement( "canvas", X({ style: H, height: u, width: u, ref: M, role: "img" }, N) ), Q); } ); ue.displayName = "QRCodeCanvas"; var Ne = y.forwardRef( function(a, s) { const l = a, { value: h, size: u = oe, level: E = re, bgColor: w = ne, fgColor: e = se, includeMargin: o = ie, minVersion: t = ae, boostLevel: r, title: n, marginSize: c, imageSettings: i } = l, p = J(l, [ "value", "size", "level", "bgColor", "fgColor", "includeMargin", "minVersion", "boostLevel", "title", "marginSize", "imageSettings" ]), { margin: f, cells: N, numCells: v, calculatedImageSettings: m } = de({ value: h, level: E, minVersion: t, boostLevel: r, includeMargin: o, marginSize: c, imageSettings: i, size: u }); let R = N, M = null; i != null && m != null && (m.excavation != null && (R = ce( N, m.excavation )), M = /* @__PURE__ */ y.createElement( "image", { href: i.src, height: m.h, width: m.w, x: m.x + f, y: m.y + f, preserveAspectRatio: "none", opacity: m.opacity, crossOrigin: m.crossOrigin } )); const P = le(R, f); return /* @__PURE__ */ y.createElement( "svg", X({ height: u, width: u, viewBox: `0 0 ${v} ${v}`, ref: s, role: "img" }, p), !!n && /* @__PURE__ */ y.createElement("title", null, n), /* @__PURE__ */ y.createElement( "path", { fill: w, d: `M0,0 h${v}v${v}H0z`, shapeRendering: "crispEdges" } ), /* @__PURE__ */ y.createElement("path", { fill: e, d: P, shapeRendering: "crispEdges" }), M ); } ); Ne.displayName = "QRCodeSVG"; const W = (d) => { switch (d) { case "usd": return "$"; case "eur": return "€"; case "gbp": return "£"; case "jpy": case "cny": return "¥"; case "aed": return "د.إ"; // 迪拉姆符號 case "zar": return "R"; // 蘭特符號 case "brl": return "R$"; // 雷亞爾符號 default: return "$"; } }, Se = () => { const [d, a] = T(!1), [s, l] = T("複製"), h = ge((u) => { navigator.clipboard.writeText(u).then( () => { a(!0), l("已複製!"), setTimeout(() => { a(!1), l("複製"); }, 2e3); }, (E) => { console.error("無法複製到剪貼簿", E), l("複製失敗"), setTimeout(() => l("複製"), 2e3); } ); }, []); return [d, h, s]; }, Te = ({ address: d = "bc1qx6xswq65n5x864vwj77lrtn0xn2rmlh3ypfkk8", title: a = "Donate", description: s = "Use this QR code or address below", currency: l = "usd", presets: h = [50, 100, 200], showButton: u = !0, buttonText: E = "Support Bitcoin.org", onClose: w }) => { const [e, o] = T(!1), [t, r] = T(""), [n, c] = T(""), [i, p] = T(112776), [f, N] = T(""), [v, m, R] = Se(), [M, P] = T(null), [_, k] = T(W(l.toLowerCase())); G(() => { (async () => { try { const A = l.toLowerCase(); k(W(A)); const z = await fetch(`https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=${A}`); if (!z.ok) throw new Error(`HTTP error! Status: ${z.status}`); const D = (await z.json()).bitcoin?.[A]; D ? p(D) : console.warn(`Could not find rate for currency: ${A}`); } catch (A) { console.error("Error fetching Bitcoin rate:", A), p(112776), l = "usd"; const z = l.toLowerCase(); k(W(z)); } })(); }, [l]), G(() => { if (M === "usd") { const C = parseFloat(t); if (isNaN(C)) c(""); else { const A = (C / i).toFixed(8); c(A); } } }, [t, i, M]), G(() => { if (M === "btc") { const C = parseFloat(n); if (isNaN(C)) r(""); else { const A = (C * i).toFixed(2); r(A); } } }, [n, i, M]); const B = `bitcoin:${d}?amount=${parseFloat(n)}${f ? `&message=${encodeURIComponent(f)}` : ""}`, j = () => { o(!1), w?.(); }, S = (C) => { r(C.target.value), P("usd"); }, H = (C) => { c(C.target.value), P("btc"); }, Q = (C) => { r(C.toString()), P("usd"); }, L = () => /* @__PURE__ */ x.jsxs( "svg", { xmlns: "http://www.w3.org/2000/svg", width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [ /* @__PURE__ */ x.jsx("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" }), /* @__PURE__ */ x.jsx("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" }) ] } ), I = () => /* @__PURE__ */ x.jsx( "svg", { xmlns: "http://www.w3.org/2000/svg", width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ x.jsx("polyline", { points: "20 6 9 17 4 12" }) } ); return /* @__PURE__ */ x.jsxs(x.Fragment, { children: [ u && /* @__PURE__ */ x.jsx( "button", { onClick: () => o(!0), style: { padding: "12px 24px", backgroundColor: "#2a2a2a", color: "white", borderRadius: "8px", boxShadow: "0 4px 6px rgba(0, 0, 0, 0.1)", transition: "all 0.2s", border: "none", cursor: "pointer", fontSize: "1rem", fontWeight: "bold" }, onMouseOver: (C) => C.currentTarget.style.backgroundColor = "#4a4a4a", onMouseOut: (C) => C.currentTarget.style.backgroundColor = "#2a2a2a", children: E } ), e && /* @__PURE__ */ x.jsxs( "div", { style: { position: "fixed", inset: 0, backgroundColor: "rgba(0, 0, 0, 0.5)", zIndex: 50, display: "flex", alignItems: "center", justifyContent: "center", overflowY: "auto", padding: "1rem" }, children: [ /* @__PURE__ */ x.jsx("style", { children: ` @keyframes fadeInZoom { 0% { opacity: 0; transform: scale(0.5); } 100% { opacity: 1; transform: scale(1); } } h2{ margin-top: 0; } .donate-modal { background-color: white; width: 100%; width: 770px; max-width: 770px; margin: 0; padding: 1.5rem; height: 755px; padding: 20px 90px; border-radius: 1rem; box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2); position: relative; box-sizing: border-box; color: "#646464"; animation: fadeInZoom 0.3s ease-out; transform-origin: top; } .donate-modal textarea{ box-sizing: border-box; } .donate-modal input::placeholder { color: #555; /* 選擇你想要的顏色,這裡使用較深的灰色 */ opacity: 1; /* 瀏覽器可能會預設降低 opacity,這會強制它為 1 */ } .donate-modal input::-webkit-input-placeholder { color: #555; /* 選擇你想要的顏色,這裡使用較深的灰色 */ } .donate-modal input::-moz-placeholder { color: #555; /* 選擇你想要的顏色,這裡使用較深的灰色 */ } .donate-modal textarea::placeholder { color: #555; /* 選擇你想要的顏色,這裡使用較深的灰色 */ opacity: 1; /* 瀏覽器可能會預設降低 opacity,這會強制它為 1 */ } .donate-modal textarea::-webkit-input-placeholder { color: #555; /* 選擇你想要的顏色,這裡使用較深的灰色 */ } .donate-modal textarea::-moz-placeholder { color: #555; /* 選擇你想要的顏色,這裡使用較深的灰色 */ } .focus-effect:focus { border-width: 2px; /* 變粗 */ border-color: #555; /* 顏色變深 */ } .copy-btn{ padding:0 } .donate-presets { box-sizing: border-box; display: flex; gap: 0.5rem; justify-content: center; justify-content: space-between; margin-bottom: 2rem; } .donate-inputs { box-sizing: border-box; display: flex; gap: 1rem; } .donate-input-wrapper { box-sizing: border-box; position: relative; flex: 1; } .donate-input-wrapper input { box-sizing: border-box; width: 100%; border: 1px solid #d1d5db; padding: 15px 15px 15px 20px; border-radius: 6px; border-radius: 1px; line-height: 1.25rem; outline: none; box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.075); } .donate-input-wrapper input:focus { border-radius: 4px; } .donate-input-wrapper span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: #6b7280; font-size: 0.875rem; } @media handheld, only screen and ( max-width: 60em ), only screen and ( max-device-width: 60em ){ .donate-modal { padding: 20px 38px; width: 620px; height: 700px; } } @media (max-width: 640px) { .donate-modal { padding: 1rem; border-radius: 0.5rem; } .donate-presets { flex-wrap: wrap; } .donate-presets button { flex: auto; width: auto; } .donate-inputs { flex-direction: column; flex-direction: row; } .donate-input-wrapper { flex: auto; } .focus-effect:focus { border-color: #F7931A; /* 顏色變深 */ } } ` }), /* @__PURE__ */ x.jsxs("div", { className: "donate-modal", children: [ /* @__PURE__ */ x.jsx( "div", { onClick: j, style: { position: "absolute", top: "1rem", right: "1rem", fontSize: "2rem", lineHeight: 0.5, height: "32px", width: "32px", padding: "0.5rem", color: "#6b7280", border: "none", background: "transparent", cursor: "pointer" }, onMouseOver: (C) => C.currentTarget.style.color = "#4a4a4a", onMouseOut: (C) => C.currentTarget.style.color = "#6b7280", children: "×" } ), /* @__PURE__ */ x.jsx( "h2", { style: { fontSize: "1.5rem", textAlign: "center", color: "#FF7E00", fontWeight: "normal", marginBottom: "20px", lineHeight: "65px" }, children: a } ), /* @__PURE__ */ x.jsx( "p", { style: { textAlign: "center", fontSize: "20px", lineHeight: "34px", color: "#6b7280", marginBottom: "1rem" }, children: s } ), /* @__PURE__ */ x.jsx( "div", { style: { display: "flex", justifyContent: "center", marginBottom: "0.75rem" }, children: /* @__PURE__ */ x.jsx(ue, { value: B, size: 160, level: "L" }) } ), /* @__PURE__ */ x.jsxs( "div", { style: { textAlign: "center", position: "relative", marginBottom: "1.5rem" }, children: [ /* @__PURE__ */ x.jsx( "p", { style: { color: "#3498db", fontSize: "0.875rem", wordBreak: "break-all", paddingRight: "35px", paddingLeft: "35px", fontWeight: "bold", margin: "27px 0 25px" }, children: /* @__PURE__ */ x.jsx("a", { style: { color: "#3498db", fontSize: "0.875rem", wordBreak: "break-all", fontWeight: "bold" }, href: B, target: "_blank", children: d }) } ), /* @__PURE__ */ x.jsx( "button", { onClick: () => m(d), title: "複製比特幣地址", "aria-label": "複製比特幣地址", "data-status": R, style: { position: "absolute", right: "0", top: "50%", transform: "translateY(-50%)", backgroundColor: "transparent", border: "none", cursor: "pointer", color: "#6b7280", padding: "0.25rem" }, children: v ? /* @__PURE__ */ x.jsx(I, {}) : /* @__PURE__ */ x.jsx(L, {}) } ) ] } ), /* @__PURE__ */ x.jsx("div", { className: "donate-presets", children: h.map((C) => /* @__PURE__ */ x.jsxs( "button", { onClick: () => Q(C), style: { flex: 1, padding: "8px 0", borderRadius: "1px", transition: "all 0.15s", border: "none", cursor: "pointer", backgroundColor: "#F7931A", maxWidth: "170px", color: "white", height: "65px" }, children: [ _, " ", C, /* @__PURE__ */ x.jsx("br", {}), /* @__PURE__ */ x.jsxs( "span", { style: { fontSize: "0.75rem", display: "block", color: "white" }, children: [ "(", (C / i).toFixed(6), " BTC)" ] } ) ] }, C )) }), /* @__PURE__ */ x.jsxs("div", { className: "donate-inputs", children: [ /* @__PURE__ */ x.jsx("div", { className: "donate-input-wrapper", children: /* @__PURE__ */ x.jsx( "input", { type: "text", placeholder: "Custom amount(BTC)", value: n, onChange: H, onBlur: () => P(null), className: "focus-effect" } ) }), /* @__PURE__ */ x.jsx("div", { className: "donate-input-wrapper", children: /* @__PURE__ */ x.jsx( "input", { type: "text",