@tokshare/pick 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +152 -2
- package/dist/index.cjs +2449 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +231 -0
- package/dist/index.d.ts +231 -0
- package/dist/index.js +2415 -0
- package/dist/index.js.map +1 -0
- package/dist/picker.global.js +250 -0
- package/dist/react.cjs +157 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +65 -0
- package/dist/react.d.ts +65 -0
- package/dist/react.js +140 -0
- package/dist/react.js.map +1 -0
- package/package.json +71 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,2415 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// ../protocol/src/limits.ts
|
|
6
|
+
var MiB = 1024 * 1024;
|
|
7
|
+
var LIMITS = {
|
|
8
|
+
/** Free tier ceilings, in decimal megabytes as phones show sizes. A site can ask for less, never more. */
|
|
9
|
+
maxFileBytes: 5e7,
|
|
10
|
+
maxFiles: 20,
|
|
11
|
+
maxSessionBytes: 2e8,
|
|
12
|
+
/** Up to this size a file goes up in one presigned PUT; above it, multipart. */
|
|
13
|
+
singlePutBytes: 16 * MiB,
|
|
14
|
+
/** Multipart parts are all the same size (R2), at least 5 MiB; we use 8 MiB. */
|
|
15
|
+
minPartBytes: 8 * MiB,
|
|
16
|
+
maxParts: 1e4,
|
|
17
|
+
/** How many part URLs the phone may ask for at once. */
|
|
18
|
+
partBatch: 10,
|
|
19
|
+
/** Session lifetime. */
|
|
20
|
+
idleMs: 30 * 6e4,
|
|
21
|
+
absoluteMs: 2 * 60 * 6e4,
|
|
22
|
+
/** A ready file is deleted this long after it arrived, downloaded or not. */
|
|
23
|
+
fileTtlMs: 10 * 6e4,
|
|
24
|
+
/** The typed short code works for this long after the session is created. */
|
|
25
|
+
codeTtlMs: 10 * 6e4,
|
|
26
|
+
/** Times the desktop may download one file (retries after a dropped connection). */
|
|
27
|
+
maxDownloads: 3,
|
|
28
|
+
/** Presigned URLs expire after this many seconds. */
|
|
29
|
+
presignSeconds: 15 * 60,
|
|
30
|
+
/** Bytes of a finished upload read back to check its real type. */
|
|
31
|
+
sniffBytes: 4096,
|
|
32
|
+
/** Direct (local network) transfers: bytes per data-channel message, how long the phone waits for
|
|
33
|
+
* the link before using the cloud, and for the website's "got" after the last byte. */
|
|
34
|
+
directChunkBytes: 64 * 1024,
|
|
35
|
+
directConnectMs: 8e3,
|
|
36
|
+
directWaitMs: 2500,
|
|
37
|
+
directConfirmMs: 2e4,
|
|
38
|
+
/** Largest WebRTC setup message the relay passes on. */
|
|
39
|
+
maxSignalBytes: 16384
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// ../protocol/src/errors.ts
|
|
43
|
+
var PickError = class extends Error {
|
|
44
|
+
constructor(code, message, status = 400) {
|
|
45
|
+
super(message || code);
|
|
46
|
+
__publicField(this, "code");
|
|
47
|
+
__publicField(this, "status");
|
|
48
|
+
this.name = "PickError";
|
|
49
|
+
this.code = code;
|
|
50
|
+
this.status = status;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// ../protocol/src/filename.ts
|
|
55
|
+
function extensionOf(name) {
|
|
56
|
+
const dot = name.lastIndexOf(".");
|
|
57
|
+
return dot > 0 ? name.slice(dot).toLowerCase() : "";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ../protocol/src/mime.ts
|
|
61
|
+
function parseAccept(accept = "") {
|
|
62
|
+
const rule = { extensions: [], types: [], wildcards: [] };
|
|
63
|
+
for (const raw of accept.split(",")) {
|
|
64
|
+
const token = raw.trim().toLowerCase();
|
|
65
|
+
if (!token) continue;
|
|
66
|
+
if (token.startsWith(".")) rule.extensions.push(token);
|
|
67
|
+
else if (/^[a-z0-9.+-]+\/\*$/.test(token)) rule.wildcards.push(token.slice(0, -1));
|
|
68
|
+
else if (/^[a-z0-9.+-]+\/[a-z0-9.+-]+$/.test(token)) rule.types.push(token);
|
|
69
|
+
}
|
|
70
|
+
return rule;
|
|
71
|
+
}
|
|
72
|
+
function typeMatches(rule, type) {
|
|
73
|
+
const lower = type.toLowerCase();
|
|
74
|
+
return rule.types.includes(lower) || rule.wildcards.some((prefix) => lower.startsWith(prefix));
|
|
75
|
+
}
|
|
76
|
+
function matchesAccept(accept, name, type) {
|
|
77
|
+
const rule = parseAccept(accept);
|
|
78
|
+
if (!rule.extensions.length && !rule.types.length && !rule.wildcards.length) return true;
|
|
79
|
+
return rule.extensions.includes(extensionOf(name)) || Boolean(type) && typeMatches(rule, type);
|
|
80
|
+
}
|
|
81
|
+
var ascii = (bytes, start, length) => String.fromCharCode(...bytes.subarray(start, start + length));
|
|
82
|
+
var starts = (bytes, signature, offset = 0) => signature.every((value, index) => bytes[offset + index] === value);
|
|
83
|
+
function sniff(bytes) {
|
|
84
|
+
if (bytes.length < 4) return null;
|
|
85
|
+
if (starts(bytes, [255, 216, 255])) return "image/jpeg";
|
|
86
|
+
if (starts(bytes, [137, 80, 78, 71, 13, 10, 26, 10])) return "image/png";
|
|
87
|
+
if (ascii(bytes, 0, 4) === "GIF8") return "image/gif";
|
|
88
|
+
if (ascii(bytes, 0, 4) === "RIFF" && ascii(bytes, 8, 4) === "WEBP") return "image/webp";
|
|
89
|
+
if (ascii(bytes, 0, 4) === "RIFF" && ascii(bytes, 8, 4) === "WAVE") return "audio/wav";
|
|
90
|
+
if (ascii(bytes, 0, 4) === "RIFF" && ascii(bytes, 8, 4) === "AVI ") return "video/x-msvideo";
|
|
91
|
+
if (ascii(bytes, 4, 4) === "ftyp") {
|
|
92
|
+
const brand = ascii(bytes, 8, 4);
|
|
93
|
+
if (/^(heic|heix|hevc|hevx|heim|heis)$/.test(brand)) return "image/heic";
|
|
94
|
+
if (brand === "mif1" || brand === "msf1") return "image/heif";
|
|
95
|
+
if (brand === "avif" || brand === "avis") return "image/avif";
|
|
96
|
+
if (brand === "qt ") return "video/quicktime";
|
|
97
|
+
if (/^(M4A |M4B )$/.test(brand)) return "audio/mp4";
|
|
98
|
+
if (/^3g/.test(brand)) return "video/3gpp";
|
|
99
|
+
return "video/mp4";
|
|
100
|
+
}
|
|
101
|
+
if (ascii(bytes, 0, 5) === "%PDF-") return "application/pdf";
|
|
102
|
+
if (starts(bytes, [80, 75, 3, 4]) || starts(bytes, [80, 75, 5, 6])) return "application/zip";
|
|
103
|
+
if (starts(bytes, [31, 139])) return "application/gzip";
|
|
104
|
+
if (starts(bytes, [55, 122, 188, 175, 39, 28])) return "application/x-7z-compressed";
|
|
105
|
+
if (ascii(bytes, 0, 4) === "Rar!") return "application/vnd.rar";
|
|
106
|
+
if (ascii(bytes, 0, 3) === "ID3" || starts(bytes, [255, 251]) || starts(bytes, [255, 243])) return "audio/mpeg";
|
|
107
|
+
if (ascii(bytes, 0, 4) === "OggS") return "audio/ogg";
|
|
108
|
+
if (ascii(bytes, 0, 4) === "fLaC") return "audio/flac";
|
|
109
|
+
if (starts(bytes, [26, 69, 223, 163])) return "video/webm";
|
|
110
|
+
if (starts(bytes, [208, 207, 17, 224, 161, 177, 26, 225])) return "application/x-ole-storage";
|
|
111
|
+
if (ascii(bytes, 0, 2) === "MZ") return "application/x-msdownload";
|
|
112
|
+
if (starts(bytes, [127, 69, 76, 70])) return "application/x-elf";
|
|
113
|
+
if (starts(bytes, [207, 250, 237, 254]) || starts(bytes, [254, 237, 250, 207])) return "application/x-mach-binary";
|
|
114
|
+
const head = ascii(bytes, 0, Math.min(bytes.length, 256)).replace(/^/, "").trimStart().toLowerCase();
|
|
115
|
+
if (head.startsWith("<svg") || head.startsWith("<?xml") && head.includes("<svg")) return "image/svg+xml";
|
|
116
|
+
if (head.startsWith("<!doctype html") || head.startsWith("<html")) return "text/html";
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
var ZIP_FAMILY = /^(application\/(zip|x-zip-compressed|epub\+zip|vnd\.android\.package-archive|java-archive|vnd\.openxmlformats-officedocument\..+|vnd\.oasis\.opendocument\..+))$/;
|
|
120
|
+
var OLE_FAMILY = /^application\/(msword|vnd\.ms-excel|vnd\.ms-powerpoint|vnd\.ms-outlook|x-ole-storage)$/;
|
|
121
|
+
var DANGEROUS = /* @__PURE__ */ new Set(["application/x-msdownload", "application/x-elf", "application/x-mach-binary", "text/html", "image/svg+xml"]);
|
|
122
|
+
function checkSniffed(accept, name, declared, sniffed) {
|
|
123
|
+
if (!sniffed) return true;
|
|
124
|
+
const rule = parseAccept(accept);
|
|
125
|
+
const declaredLower = declared.toLowerCase();
|
|
126
|
+
const compatible = (type) => type === sniffed || sniffed === "application/zip" && ZIP_FAMILY.test(type) || sniffed === "application/x-ole-storage" && OLE_FAMILY.test(type) || sniffed === "image/heif" && type === "image/heic" || sniffed === "video/mp4" && /^(video|audio)\//.test(type);
|
|
127
|
+
if (DANGEROUS.has(sniffed)) {
|
|
128
|
+
return rule.types.includes(sniffed) || sniffed === "image/svg+xml" && rule.extensions.includes(".svg");
|
|
129
|
+
}
|
|
130
|
+
if (!rule.types.length && !rule.wildcards.length) return true;
|
|
131
|
+
if (rule.types.some(compatible)) return true;
|
|
132
|
+
if (rule.wildcards.some((prefix) => sniffed.startsWith(prefix))) return true;
|
|
133
|
+
return rule.extensions.includes(extensionOf(name)) && (compatible(declaredLower) || !declaredLower);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// src/config.ts
|
|
137
|
+
var DEFAULT_RELAY = "https://tokshare-pick.pjturki.workers.dev";
|
|
138
|
+
var SDK_VERSION = "0.1.0";
|
|
139
|
+
|
|
140
|
+
// src/direct.ts
|
|
141
|
+
function verifyDirectFile(meta, chunks, size, accept, maxBytes) {
|
|
142
|
+
if (size !== meta.size || size > maxBytes) return { ok: false, code: "size_mismatch" };
|
|
143
|
+
const head = new Uint8Array(Math.min(size, LIMITS.sniffBytes));
|
|
144
|
+
let filled = 0;
|
|
145
|
+
for (const chunk of chunks) {
|
|
146
|
+
if (filled >= head.length) break;
|
|
147
|
+
const take = chunk.subarray(0, head.length - filled);
|
|
148
|
+
head.set(take, filled);
|
|
149
|
+
filled += take.length;
|
|
150
|
+
}
|
|
151
|
+
const sniffed = sniff(head);
|
|
152
|
+
if (!checkSniffed(accept, meta.name, meta.type, sniffed)) return { ok: false, code: "type_rejected" };
|
|
153
|
+
const file = new File(chunks, meta.name, { type: meta.type || sniffed || "", lastModified: meta.lastModified });
|
|
154
|
+
return { ok: true, file, sniffed };
|
|
155
|
+
}
|
|
156
|
+
var DirectReceiver = class _DirectReceiver {
|
|
157
|
+
constructor(signal, handlers) {
|
|
158
|
+
__publicField(this, "signal", signal);
|
|
159
|
+
__publicField(this, "handlers", handlers);
|
|
160
|
+
__publicField(this, "pc", null);
|
|
161
|
+
__publicField(this, "channel", null);
|
|
162
|
+
__publicField(this, "id", "");
|
|
163
|
+
__publicField(this, "isOpen", false);
|
|
164
|
+
__publicField(this, "current", null);
|
|
165
|
+
}
|
|
166
|
+
static supported() {
|
|
167
|
+
return typeof RTCPeerConnection === "function";
|
|
168
|
+
}
|
|
169
|
+
onSignal(d) {
|
|
170
|
+
if (d.kind === "offer" && d.sdp) {
|
|
171
|
+
this.answer(d.pc, d.sdp);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (d.pc !== this.id || !this.pc) return;
|
|
175
|
+
if (d.kind === "ice" && d.candidate) this.pc.addIceCandidate(d.candidate).catch(() => void 0);
|
|
176
|
+
else if (d.kind === "bye") this.close();
|
|
177
|
+
}
|
|
178
|
+
/** A new offer replaces any earlier link (the phone reloaded, or retried after a network change). */
|
|
179
|
+
answer(id, sdp) {
|
|
180
|
+
if (!_DirectReceiver.supported()) return;
|
|
181
|
+
this.close();
|
|
182
|
+
this.id = id;
|
|
183
|
+
const pc = new RTCPeerConnection({ iceServers: [] });
|
|
184
|
+
this.pc = pc;
|
|
185
|
+
pc.onicecandidate = (event) => {
|
|
186
|
+
if (this.id === id) this.signal({ pc: id, kind: "ice", candidate: event.candidate ? event.candidate.toJSON() : null });
|
|
187
|
+
};
|
|
188
|
+
pc.onconnectionstatechange = () => {
|
|
189
|
+
if (this.id === id && (pc.connectionState === "failed" || pc.connectionState === "closed")) this.close();
|
|
190
|
+
};
|
|
191
|
+
pc.ondatachannel = (event) => {
|
|
192
|
+
if (this.id !== id) return;
|
|
193
|
+
const channel = event.channel;
|
|
194
|
+
channel.binaryType = "arraybuffer";
|
|
195
|
+
this.channel = channel;
|
|
196
|
+
const opened = () => {
|
|
197
|
+
if (this.channel === channel && !this.isOpen) {
|
|
198
|
+
this.isOpen = true;
|
|
199
|
+
this.handlers.state(true);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
channel.onopen = opened;
|
|
203
|
+
channel.onclose = () => {
|
|
204
|
+
if (this.channel === channel) this.close();
|
|
205
|
+
};
|
|
206
|
+
channel.onmessage = (message) => this.onMessage(channel, message.data);
|
|
207
|
+
if (channel.readyState === "open") opened();
|
|
208
|
+
};
|
|
209
|
+
pc.setRemoteDescription({ type: "offer", sdp }).then(() => pc.createAnswer()).then((answer) => pc.setLocalDescription(answer)).then(() => {
|
|
210
|
+
if (this.id === id) this.signal({ pc: id, kind: "answer", sdp: pc.localDescription.sdp });
|
|
211
|
+
}).catch(() => this.close());
|
|
212
|
+
}
|
|
213
|
+
onMessage(channel, data) {
|
|
214
|
+
if (typeof data !== "string") {
|
|
215
|
+
const current = this.current;
|
|
216
|
+
if (!current || !(data instanceof ArrayBuffer)) return;
|
|
217
|
+
current.chunks.push(new Uint8Array(data));
|
|
218
|
+
current.received += data.byteLength;
|
|
219
|
+
if (current.received > current.size) {
|
|
220
|
+
current.chunks = [];
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
this.handlers.progress(current.id, current.received, current.size);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
let message;
|
|
227
|
+
try {
|
|
228
|
+
message = JSON.parse(data);
|
|
229
|
+
} catch {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (message.t === "file" && typeof message.id === "string" && Number.isSafeInteger(message.size)) {
|
|
233
|
+
this.current = { id: message.id, size: message.size, chunks: [], received: 0 };
|
|
234
|
+
} else if (message.t === "end" && this.current?.id === message.id) {
|
|
235
|
+
const { id, chunks, received } = this.current;
|
|
236
|
+
this.current = null;
|
|
237
|
+
this.handlers.complete(id, chunks, received).then((result) => result, () => ({ ok: false, code: "failed" })).then((result) => {
|
|
238
|
+
const reply = result.ok ? { t: "got", id } : { t: "bad", id, code: result.code };
|
|
239
|
+
try {
|
|
240
|
+
channel.send(JSON.stringify(reply));
|
|
241
|
+
} catch {
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
close() {
|
|
247
|
+
const wasOpen = this.isOpen;
|
|
248
|
+
this.isOpen = false;
|
|
249
|
+
const { pc, channel } = this;
|
|
250
|
+
this.pc = null;
|
|
251
|
+
this.channel = null;
|
|
252
|
+
this.current = null;
|
|
253
|
+
try {
|
|
254
|
+
channel?.close();
|
|
255
|
+
} catch {
|
|
256
|
+
}
|
|
257
|
+
try {
|
|
258
|
+
pc?.close();
|
|
259
|
+
} catch {
|
|
260
|
+
}
|
|
261
|
+
if (wasOpen) this.handlers.state(false);
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
// src/announce.ts
|
|
266
|
+
var HIDDEN_KEY = "tokshare.announce.hidden";
|
|
267
|
+
var LINK = "https://tokshare.vercel.app/?ref=pick";
|
|
268
|
+
var hidden = () => {
|
|
269
|
+
try {
|
|
270
|
+
return localStorage.getItem(HIDDEN_KEY) === "1";
|
|
271
|
+
} catch {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
function announcement(enabled, t) {
|
|
276
|
+
if (enabled === false || hidden()) return null;
|
|
277
|
+
const box = document.createElement("p");
|
|
278
|
+
box.className = "announce";
|
|
279
|
+
const dot = document.createElement("i");
|
|
280
|
+
dot.setAttribute("aria-hidden", "true");
|
|
281
|
+
const text = document.createElement("span");
|
|
282
|
+
text.textContent = `${t("announceText")} `;
|
|
283
|
+
const link = document.createElement("a");
|
|
284
|
+
link.href = LINK;
|
|
285
|
+
link.target = "_blank";
|
|
286
|
+
link.rel = "noopener";
|
|
287
|
+
link.textContent = t("announceLink");
|
|
288
|
+
text.append(link);
|
|
289
|
+
const hide = document.createElement("button");
|
|
290
|
+
hide.type = "button";
|
|
291
|
+
hide.className = "announce-hide";
|
|
292
|
+
hide.textContent = "\xD7";
|
|
293
|
+
hide.setAttribute("aria-label", t("announceHide"));
|
|
294
|
+
hide.addEventListener("click", () => {
|
|
295
|
+
try {
|
|
296
|
+
localStorage.setItem(HIDDEN_KEY, "1");
|
|
297
|
+
} catch {
|
|
298
|
+
}
|
|
299
|
+
box.remove();
|
|
300
|
+
});
|
|
301
|
+
box.append(dot, text, hide);
|
|
302
|
+
return box;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// src/i18n.ts
|
|
306
|
+
var en = {
|
|
307
|
+
title: "Pick files from your phone",
|
|
308
|
+
titleOne: "Pick a file from your phone",
|
|
309
|
+
scan: "Scan with your phone's camera",
|
|
310
|
+
orType: "No camera? Open {host} on your phone and type",
|
|
311
|
+
loading: "Getting a code\u2026",
|
|
312
|
+
waiting: "Waiting for your phone\u2026",
|
|
313
|
+
connected: "Connected: {label}",
|
|
314
|
+
connectedDirect: "Connected over Wi-Fi: {label}",
|
|
315
|
+
disconnect: "Not you? Disconnect",
|
|
316
|
+
phoneLeft: "Your phone disconnected. It reconnects by itself when the page is open.",
|
|
317
|
+
approveTitle: "Approve this phone?",
|
|
318
|
+
approveMatch: "Your phone should show {match}.",
|
|
319
|
+
approve: "Approve",
|
|
320
|
+
reject: "Reject",
|
|
321
|
+
sending: "Sending from phone {percent}%",
|
|
322
|
+
receiving: "Receiving {percent}%",
|
|
323
|
+
received: "Received",
|
|
324
|
+
failed: "Not received",
|
|
325
|
+
cancel: "Cancel",
|
|
326
|
+
done: "Done",
|
|
327
|
+
useFiles: "Use {count} files",
|
|
328
|
+
useFile: "Use this file",
|
|
329
|
+
expired: "This code expired.",
|
|
330
|
+
newCode: "Get a new code",
|
|
331
|
+
error: "Couldn't start: {message}",
|
|
332
|
+
tryAgain: "Try again",
|
|
333
|
+
close: "Close",
|
|
334
|
+
privacy: "Files go straight to this site and are deleted from TokShare once received.",
|
|
335
|
+
// Upload field
|
|
336
|
+
dropTitle: "Drag & drop files here",
|
|
337
|
+
dropTitleOne: "Drag & drop a file here",
|
|
338
|
+
dropActive: "Drop to add",
|
|
339
|
+
or: "or",
|
|
340
|
+
browse: "Browse files",
|
|
341
|
+
usePhone: "Use your phone",
|
|
342
|
+
hintTypes: "{types} \xB7 up to {size}",
|
|
343
|
+
hintAny: "Any file \xB7 up to {size}",
|
|
344
|
+
hintCount: "Up to {count} files",
|
|
345
|
+
phoneTitle: "Scan with your phone",
|
|
346
|
+
phoneStep1: "Open your phone's camera and scan the code",
|
|
347
|
+
phoneStep2: "Pick photos or files on your phone",
|
|
348
|
+
phoneStep3: "They appear here as they arrive",
|
|
349
|
+
phoneCode: "No camera? Open {host} and type",
|
|
350
|
+
back: "Back",
|
|
351
|
+
doneWithPhone: "Done",
|
|
352
|
+
sourcePhone: "From phone",
|
|
353
|
+
sourceDevice: "This device",
|
|
354
|
+
remove: "Remove {name}",
|
|
355
|
+
tooLarge: "{name} is larger than {size}.",
|
|
356
|
+
wrongType: "{name} isn't an accepted file type.",
|
|
357
|
+
tooMany: "You can add up to {count} files.",
|
|
358
|
+
fileCount: "{count} files",
|
|
359
|
+
clearAll: "Remove all",
|
|
360
|
+
// TokShare for desktop
|
|
361
|
+
announceText: "Move photos between your phone and your own PC anytime, over Wi-Fi.",
|
|
362
|
+
announceLink: "Get TokShare for desktop",
|
|
363
|
+
announceHide: "Hide"
|
|
364
|
+
};
|
|
365
|
+
var ar = {
|
|
366
|
+
title: "\u0627\u062E\u062A\u0631 \u0645\u0644\u0641\u0627\u062A \u0645\u0646 \u0647\u0627\u062A\u0641\u0643",
|
|
367
|
+
titleOne: "\u0627\u062E\u062A\u0631 \u0645\u0644\u0641\u064B\u0627 \u0645\u0646 \u0647\u0627\u062A\u0641\u0643",
|
|
368
|
+
scan: "\u0627\u0645\u0633\u062D \u0627\u0644\u0631\u0645\u0632 \u0628\u0643\u0627\u0645\u064A\u0631\u0627 \u0647\u0627\u062A\u0641\u0643",
|
|
369
|
+
orType: "\u0644\u0627 \u062A\u0648\u062C\u062F \u0643\u0627\u0645\u064A\u0631\u0627\u061F \u0627\u0641\u062A\u062D {host} \u0639\u0644\u0649 \u0647\u0627\u062A\u0641\u0643 \u0648\u0627\u0643\u062A\u0628",
|
|
370
|
+
loading: "\u062C\u0627\u0631\u064D \u062A\u062C\u0647\u064A\u0632 \u0627\u0644\u0631\u0645\u0632\u2026",
|
|
371
|
+
waiting: "\u0641\u064A \u0627\u0646\u062A\u0638\u0627\u0631 \u0647\u0627\u062A\u0641\u0643\u2026",
|
|
372
|
+
connected: "\u0645\u062A\u0635\u0644: {label}",
|
|
373
|
+
connectedDirect: "\u0645\u062A\u0635\u0644 \u0639\u0628\u0631 Wi-Fi: {label}",
|
|
374
|
+
disconnect: "\u0644\u064A\u0633 \u0647\u0627\u062A\u0641\u0643\u061F \u0627\u0641\u0635\u0644\u0647",
|
|
375
|
+
phoneLeft: "\u0627\u0646\u0642\u0637\u0639 \u0627\u062A\u0635\u0627\u0644 \u0647\u0627\u062A\u0641\u0643. \u0633\u064A\u0639\u0648\u062F \u062A\u0644\u0642\u0627\u0626\u064A\u064B\u0627 \u0645\u0627 \u062F\u0627\u0645\u062A \u0627\u0644\u0635\u0641\u062D\u0629 \u0645\u0641\u062A\u0648\u062D\u0629 \u0639\u0644\u064A\u0647.",
|
|
376
|
+
approveTitle: "\u0647\u0644 \u062A\u0648\u0627\u0641\u0642 \u0639\u0644\u0649 \u0647\u0630\u0627 \u0627\u0644\u0647\u0627\u062A\u0641\u061F",
|
|
377
|
+
approveMatch: "\u064A\u062C\u0628 \u0623\u0646 \u064A\u0639\u0631\u0636 \u0647\u0627\u062A\u0641\u0643 \u0627\u0644\u0631\u0642\u0645 {match}.",
|
|
378
|
+
approve: "\u0645\u0648\u0627\u0641\u0642\u0629",
|
|
379
|
+
reject: "\u0631\u0641\u0636",
|
|
380
|
+
sending: "\u062C\u0627\u0631\u064D \u0627\u0644\u0625\u0631\u0633\u0627\u0644 \u0645\u0646 \u0627\u0644\u0647\u0627\u062A\u0641 {percent}%",
|
|
381
|
+
receiving: "\u062C\u0627\u0631\u064D \u0627\u0644\u0627\u0633\u062A\u0644\u0627\u0645 {percent}%",
|
|
382
|
+
received: "\u062A\u0645 \u0627\u0644\u0627\u0633\u062A\u0644\u0627\u0645",
|
|
383
|
+
failed: "\u0644\u0645 \u064A\u064F\u0633\u062A\u0644\u0645",
|
|
384
|
+
cancel: "\u0625\u0644\u063A\u0627\u0621",
|
|
385
|
+
done: "\u062A\u0645",
|
|
386
|
+
useFiles: "\u0627\u0633\u062A\u062E\u062F\u0645 {count} \u0645\u0644\u0641\u0627\u062A",
|
|
387
|
+
useFile: "\u0627\u0633\u062A\u062E\u062F\u0645 \u0647\u0630\u0627 \u0627\u0644\u0645\u0644\u0641",
|
|
388
|
+
expired: "\u0627\u0646\u062A\u0647\u062A \u0635\u0644\u0627\u062D\u064A\u0629 \u0647\u0630\u0627 \u0627\u0644\u0631\u0645\u0632.",
|
|
389
|
+
newCode: "\u0627\u062D\u0635\u0644 \u0639\u0644\u0649 \u0631\u0645\u0632 \u062C\u062F\u064A\u062F",
|
|
390
|
+
error: "\u062A\u0639\u0630\u0651\u0631 \u0627\u0644\u0628\u062F\u0621: {message}",
|
|
391
|
+
tryAgain: "\u062D\u0627\u0648\u0644 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649",
|
|
392
|
+
close: "\u0625\u063A\u0644\u0627\u0642",
|
|
393
|
+
privacy: "\u062A\u0635\u0644 \u0627\u0644\u0645\u0644\u0641\u0627\u062A \u0645\u0628\u0627\u0634\u0631\u0629 \u0625\u0644\u0649 \u0647\u0630\u0627 \u0627\u0644\u0645\u0648\u0642\u0639\u060C \u0648\u064A\u062D\u0630\u0641\u0647\u0627 TokShare \u0641\u0648\u0631 \u0627\u0633\u062A\u0644\u0627\u0645\u0647\u0627.",
|
|
394
|
+
dropTitle: "\u0627\u0633\u062D\u0628 \u0627\u0644\u0645\u0644\u0641\u0627\u062A \u0648\u0623\u0641\u0644\u062A\u0647\u0627 \u0647\u0646\u0627",
|
|
395
|
+
dropTitleOne: "\u0627\u0633\u062D\u0628 \u0645\u0644\u0641\u064B\u0627 \u0648\u0623\u0641\u0644\u062A\u0647 \u0647\u0646\u0627",
|
|
396
|
+
dropActive: "\u0623\u0641\u0644\u062A \u0644\u0644\u0625\u0636\u0627\u0641\u0629",
|
|
397
|
+
or: "\u0623\u0648",
|
|
398
|
+
browse: "\u062A\u0635\u0641\u0651\u062D \u0627\u0644\u0645\u0644\u0641\u0627\u062A",
|
|
399
|
+
usePhone: "\u0627\u0633\u062A\u062E\u062F\u0645 \u0647\u0627\u062A\u0641\u0643",
|
|
400
|
+
hintTypes: "{types} \xB7 \u062D\u062A\u0649 {size}",
|
|
401
|
+
hintAny: "\u0623\u064A \u0645\u0644\u0641 \xB7 \u062D\u062A\u0649 {size}",
|
|
402
|
+
hintCount: "\u062D\u062A\u0649 {count} \u0645\u0644\u0641\u0627\u062A",
|
|
403
|
+
phoneTitle: "\u0627\u0645\u0633\u062D \u0627\u0644\u0631\u0645\u0632 \u0628\u0647\u0627\u062A\u0641\u0643",
|
|
404
|
+
phoneStep1: "\u0627\u0641\u062A\u062D \u0643\u0627\u0645\u064A\u0631\u0627 \u0647\u0627\u062A\u0641\u0643 \u0648\u0627\u0645\u0633\u062D \u0627\u0644\u0631\u0645\u0632",
|
|
405
|
+
phoneStep2: "\u0627\u062E\u062A\u0631 \u0627\u0644\u0635\u0648\u0631 \u0623\u0648 \u0627\u0644\u0645\u0644\u0641\u0627\u062A \u0639\u0644\u0649 \u0647\u0627\u062A\u0641\u0643",
|
|
406
|
+
phoneStep3: "\u062A\u0638\u0647\u0631 \u0647\u0646\u0627 \u0641\u0648\u0631 \u0648\u0635\u0648\u0644\u0647\u0627",
|
|
407
|
+
phoneCode: "\u0644\u0627 \u062A\u0648\u062C\u062F \u0643\u0627\u0645\u064A\u0631\u0627\u061F \u0627\u0641\u062A\u062D {host} \u0648\u0627\u0643\u062A\u0628",
|
|
408
|
+
back: "\u0631\u062C\u0648\u0639",
|
|
409
|
+
doneWithPhone: "\u062A\u0645",
|
|
410
|
+
sourcePhone: "\u0645\u0646 \u0627\u0644\u0647\u0627\u062A\u0641",
|
|
411
|
+
sourceDevice: "\u0647\u0630\u0627 \u0627\u0644\u062C\u0647\u0627\u0632",
|
|
412
|
+
remove: "\u0625\u0632\u0627\u0644\u0629 {name}",
|
|
413
|
+
tooLarge: "{name} \u0623\u0643\u0628\u0631 \u0645\u0646 {size}.",
|
|
414
|
+
wrongType: "{name} \u0644\u064A\u0633 \u0645\u0646 \u0623\u0646\u0648\u0627\u0639 \u0627\u0644\u0645\u0644\u0641\u0627\u062A \u0627\u0644\u0645\u0642\u0628\u0648\u0644\u0629.",
|
|
415
|
+
tooMany: "\u064A\u0645\u0643\u0646\u0643 \u0625\u0636\u0627\u0641\u0629 {count} \u0645\u0644\u0641\u0627\u062A \u0643\u062D\u062F \u0623\u0642\u0635\u0649.",
|
|
416
|
+
fileCount: "{count} \u0645\u0644\u0641\u0627\u062A",
|
|
417
|
+
clearAll: "\u0625\u0632\u0627\u0644\u0629 \u0627\u0644\u0643\u0644",
|
|
418
|
+
announceText: "\u0627\u0646\u0642\u0644 \u0627\u0644\u0635\u0648\u0631 \u0628\u064A\u0646 \u0647\u0627\u062A\u0641\u0643 \u0648\u0643\u0645\u0628\u064A\u0648\u062A\u0631\u0643 \u0641\u064A \u0623\u064A \u0648\u0642\u062A \u0639\u0628\u0631 Wi-Fi.",
|
|
419
|
+
announceLink: "\u062D\u0645\u0651\u0644 TokShare \u0644\u0644\u0643\u0645\u0628\u064A\u0648\u062A\u0631",
|
|
420
|
+
announceHide: "\u0625\u062E\u0641\u0627\u0621"
|
|
421
|
+
};
|
|
422
|
+
var STRINGS = { en, ar };
|
|
423
|
+
function resolveLocale(requested) {
|
|
424
|
+
if (requested === "en" || requested === "ar") return requested;
|
|
425
|
+
const page = typeof document !== "undefined" ? document.documentElement.lang : "";
|
|
426
|
+
const language = page || (typeof navigator !== "undefined" ? navigator.language : "en");
|
|
427
|
+
return /^ar\b/i.test(language) ? "ar" : "en";
|
|
428
|
+
}
|
|
429
|
+
function translator(locale, overrides = {}) {
|
|
430
|
+
return (key, values = {}) => (overrides[key] ?? STRINGS[locale][key]).replace(/\{(\w+)\}/g, (_, name) => String(values[name] ?? ""));
|
|
431
|
+
}
|
|
432
|
+
function formatBytes(bytes, locale) {
|
|
433
|
+
const units = locale === "ar" ? ["\u0628\u0627\u064A\u062A", "\u0643.\u0628", "\u0645.\u0628", "\u062C.\u0628"] : ["B", "KB", "MB", "GB"];
|
|
434
|
+
let value = bytes;
|
|
435
|
+
let unit = 0;
|
|
436
|
+
while (value >= 1e3 && unit < units.length - 1) {
|
|
437
|
+
value /= 1e3;
|
|
438
|
+
unit++;
|
|
439
|
+
}
|
|
440
|
+
return `${(value >= 100 || unit === 0 ? Math.round(value) : Math.round(value * 10) / 10).toLocaleString(locale)} ${units[unit]}`;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// ../../node_modules/.pnpm/uqr@0.1.3/node_modules/uqr/dist/index.mjs
|
|
444
|
+
var QrCodeDataType = /* @__PURE__ */ ((QrCodeDataType2) => {
|
|
445
|
+
QrCodeDataType2[QrCodeDataType2["Border"] = -1] = "Border";
|
|
446
|
+
QrCodeDataType2[QrCodeDataType2["Data"] = 0] = "Data";
|
|
447
|
+
QrCodeDataType2[QrCodeDataType2["Function"] = 1] = "Function";
|
|
448
|
+
QrCodeDataType2[QrCodeDataType2["Position"] = 2] = "Position";
|
|
449
|
+
QrCodeDataType2[QrCodeDataType2["Timing"] = 3] = "Timing";
|
|
450
|
+
QrCodeDataType2[QrCodeDataType2["Alignment"] = 4] = "Alignment";
|
|
451
|
+
return QrCodeDataType2;
|
|
452
|
+
})(QrCodeDataType || {});
|
|
453
|
+
var LOW = [0, 1];
|
|
454
|
+
var MEDIUM = [1, 0];
|
|
455
|
+
var QUARTILE = [2, 3];
|
|
456
|
+
var HIGH = [3, 2];
|
|
457
|
+
var EccMap = {
|
|
458
|
+
L: LOW,
|
|
459
|
+
M: MEDIUM,
|
|
460
|
+
Q: QUARTILE,
|
|
461
|
+
H: HIGH
|
|
462
|
+
};
|
|
463
|
+
var NUMERIC_REGEX = /^\d*$/;
|
|
464
|
+
var ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+./:-]*$/;
|
|
465
|
+
var ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
|
|
466
|
+
var MIN_VERSION = 1;
|
|
467
|
+
var MAX_VERSION = 40;
|
|
468
|
+
var PENALTY_N1 = 3;
|
|
469
|
+
var PENALTY_N2 = 3;
|
|
470
|
+
var PENALTY_N3 = 40;
|
|
471
|
+
var PENALTY_N4 = 10;
|
|
472
|
+
var ECC_CODEWORDS_PER_BLOCK = [
|
|
473
|
+
// Version: (note that index 0 is for padding, and is set to an illegal value)
|
|
474
|
+
// 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
|
|
475
|
+
[-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],
|
|
476
|
+
// Low
|
|
477
|
+
[-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],
|
|
478
|
+
// Medium
|
|
479
|
+
[-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],
|
|
480
|
+
// Quartile
|
|
481
|
+
[-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]
|
|
482
|
+
// High
|
|
483
|
+
];
|
|
484
|
+
var NUM_ERROR_CORRECTION_BLOCKS = [
|
|
485
|
+
// Version: (note that index 0 is for padding, and is set to an illegal value)
|
|
486
|
+
// 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
|
|
487
|
+
[-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],
|
|
488
|
+
// Low
|
|
489
|
+
[-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],
|
|
490
|
+
// Medium
|
|
491
|
+
[-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],
|
|
492
|
+
// Quartile
|
|
493
|
+
[-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]
|
|
494
|
+
// High
|
|
495
|
+
];
|
|
496
|
+
var QrCode = class {
|
|
497
|
+
/* -- Constructor (low level) and fields -- */
|
|
498
|
+
// Creates a new QR Code with the given version number,
|
|
499
|
+
// error correction level, data codeword bytes, and mask number.
|
|
500
|
+
// This is a low-level API that most users should not use directly.
|
|
501
|
+
// A mid-level API is the encodeSegments() function.
|
|
502
|
+
constructor(version, ecc, dataCodewords, msk) {
|
|
503
|
+
/* -- Fields -- */
|
|
504
|
+
// The width and height of this QR Code, measured in modules, between
|
|
505
|
+
// 21 and 177 (inclusive). This is equal to version * 4 + 17.
|
|
506
|
+
__publicField(this, "size");
|
|
507
|
+
// The index of the mask pattern used in this QR Code, which is between 0 and 7 (inclusive).
|
|
508
|
+
// Even if a QR Code is created with automatic masking requested (mask = -1),
|
|
509
|
+
// the resulting object still has a mask value between 0 and 7.
|
|
510
|
+
__publicField(this, "mask");
|
|
511
|
+
// The modules of this QR Code (false = light, true = dark).
|
|
512
|
+
// Immutable after constructor finishes. Accessed through getModule().
|
|
513
|
+
__publicField(this, "modules", []);
|
|
514
|
+
__publicField(this, "types", []);
|
|
515
|
+
this.version = version;
|
|
516
|
+
this.ecc = ecc;
|
|
517
|
+
if (version < MIN_VERSION || version > MAX_VERSION)
|
|
518
|
+
throw new RangeError("Version value out of range");
|
|
519
|
+
if (msk < -1 || msk > 7)
|
|
520
|
+
throw new RangeError("Mask value out of range");
|
|
521
|
+
this.size = version * 4 + 17;
|
|
522
|
+
const row = Array.from({ length: this.size }).fill(false);
|
|
523
|
+
for (let i = 0; i < this.size; i++) {
|
|
524
|
+
this.modules.push(row.slice());
|
|
525
|
+
this.types.push(row.map(() => 0));
|
|
526
|
+
}
|
|
527
|
+
this.drawFunctionPatterns();
|
|
528
|
+
const allCodewords = this.addEccAndInterleave(dataCodewords);
|
|
529
|
+
this.drawCodewords(allCodewords);
|
|
530
|
+
if (msk === -1) {
|
|
531
|
+
let minPenalty = 1e9;
|
|
532
|
+
for (let i = 0; i < 8; i++) {
|
|
533
|
+
this.applyMask(i);
|
|
534
|
+
this.drawFormatBits(i);
|
|
535
|
+
const penalty = this.getPenaltyScore();
|
|
536
|
+
if (penalty < minPenalty) {
|
|
537
|
+
msk = i;
|
|
538
|
+
minPenalty = penalty;
|
|
539
|
+
}
|
|
540
|
+
this.applyMask(i);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
this.mask = msk;
|
|
544
|
+
this.applyMask(msk);
|
|
545
|
+
this.drawFormatBits(msk);
|
|
546
|
+
}
|
|
547
|
+
/* -- Accessor methods -- */
|
|
548
|
+
// Returns the color of the module (pixel) at the given coordinates, which is false
|
|
549
|
+
// for light or true for dark. The top left corner has the coordinates (x=0, y=0).
|
|
550
|
+
// If the given coordinates are out of bounds, then false (light) is returned.
|
|
551
|
+
getModule(x, y) {
|
|
552
|
+
return x >= 0 && x < this.size && y >= 0 && y < this.size && this.modules[y][x];
|
|
553
|
+
}
|
|
554
|
+
/* -- Private helper methods for constructor: Drawing function modules -- */
|
|
555
|
+
// Reads this object's version field, and draws and marks all function modules.
|
|
556
|
+
drawFunctionPatterns() {
|
|
557
|
+
for (let i = 0; i < this.size; i++) {
|
|
558
|
+
this.setFunctionModule(6, i, i % 2 === 0, QrCodeDataType.Timing);
|
|
559
|
+
this.setFunctionModule(i, 6, i % 2 === 0, QrCodeDataType.Timing);
|
|
560
|
+
}
|
|
561
|
+
this.drawFinderPattern(3, 3);
|
|
562
|
+
this.drawFinderPattern(this.size - 4, 3);
|
|
563
|
+
this.drawFinderPattern(3, this.size - 4);
|
|
564
|
+
const alignPatPos = this.getAlignmentPatternPositions();
|
|
565
|
+
const numAlign = alignPatPos.length;
|
|
566
|
+
for (let i = 0; i < numAlign; i++) {
|
|
567
|
+
for (let j = 0; j < numAlign; j++) {
|
|
568
|
+
if (!(i === 0 && j === 0 || i === 0 && j === numAlign - 1 || i === numAlign - 1 && j === 0))
|
|
569
|
+
this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
this.drawFormatBits(0);
|
|
573
|
+
this.drawVersion();
|
|
574
|
+
}
|
|
575
|
+
// Draws two copies of the format bits (with its own error correction code)
|
|
576
|
+
// based on the given mask and this object's error correction level field.
|
|
577
|
+
drawFormatBits(mask) {
|
|
578
|
+
const data = this.ecc[1] << 3 | mask;
|
|
579
|
+
let rem = data;
|
|
580
|
+
for (let i = 0; i < 10; i++)
|
|
581
|
+
rem = rem << 1 ^ (rem >>> 9) * 1335;
|
|
582
|
+
const bits = (data << 10 | rem) ^ 21522;
|
|
583
|
+
for (let i = 0; i <= 5; i++)
|
|
584
|
+
this.setFunctionModule(8, i, getBit(bits, i));
|
|
585
|
+
this.setFunctionModule(8, 7, getBit(bits, 6));
|
|
586
|
+
this.setFunctionModule(8, 8, getBit(bits, 7));
|
|
587
|
+
this.setFunctionModule(7, 8, getBit(bits, 8));
|
|
588
|
+
for (let i = 9; i < 15; i++)
|
|
589
|
+
this.setFunctionModule(14 - i, 8, getBit(bits, i));
|
|
590
|
+
for (let i = 0; i < 8; i++)
|
|
591
|
+
this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
|
|
592
|
+
for (let i = 8; i < 15; i++)
|
|
593
|
+
this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
|
|
594
|
+
this.setFunctionModule(8, this.size - 8, true);
|
|
595
|
+
}
|
|
596
|
+
// Draws two copies of the version bits (with its own error correction code),
|
|
597
|
+
// based on this object's version field, iff 7 <= version <= 40.
|
|
598
|
+
drawVersion() {
|
|
599
|
+
if (this.version < 7)
|
|
600
|
+
return;
|
|
601
|
+
let rem = this.version;
|
|
602
|
+
for (let i = 0; i < 12; i++)
|
|
603
|
+
rem = rem << 1 ^ (rem >>> 11) * 7973;
|
|
604
|
+
const bits = this.version << 12 | rem;
|
|
605
|
+
for (let i = 0; i < 18; i++) {
|
|
606
|
+
const color = getBit(bits, i);
|
|
607
|
+
const a = this.size - 11 + i % 3;
|
|
608
|
+
const b = Math.floor(i / 3);
|
|
609
|
+
this.setFunctionModule(a, b, color);
|
|
610
|
+
this.setFunctionModule(b, a, color);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
// Draws a 9*9 finder pattern including the border separator,
|
|
614
|
+
// with the center module at (x, y). Modules can be out of bounds.
|
|
615
|
+
drawFinderPattern(x, y) {
|
|
616
|
+
for (let dy = -4; dy <= 4; dy++) {
|
|
617
|
+
for (let dx = -4; dx <= 4; dx++) {
|
|
618
|
+
const dist = Math.max(Math.abs(dx), Math.abs(dy));
|
|
619
|
+
const xx = x + dx;
|
|
620
|
+
const yy = y + dy;
|
|
621
|
+
if (xx >= 0 && xx < this.size && yy >= 0 && yy < this.size)
|
|
622
|
+
this.setFunctionModule(xx, yy, dist !== 2 && dist !== 4, QrCodeDataType.Position);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
// Draws a 5*5 alignment pattern, with the center module
|
|
627
|
+
// at (x, y). All modules must be in bounds.
|
|
628
|
+
drawAlignmentPattern(x, y) {
|
|
629
|
+
for (let dy = -2; dy <= 2; dy++) {
|
|
630
|
+
for (let dx = -2; dx <= 2; dx++) {
|
|
631
|
+
this.setFunctionModule(
|
|
632
|
+
x + dx,
|
|
633
|
+
y + dy,
|
|
634
|
+
Math.max(Math.abs(dx), Math.abs(dy)) !== 1,
|
|
635
|
+
QrCodeDataType.Alignment
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
// Sets the color of a module and marks it as a function module.
|
|
641
|
+
// Only used by the constructor. Coordinates must be in bounds.
|
|
642
|
+
setFunctionModule(x, y, isDark, type = QrCodeDataType.Function) {
|
|
643
|
+
this.modules[y][x] = isDark;
|
|
644
|
+
this.types[y][x] = type;
|
|
645
|
+
}
|
|
646
|
+
/* -- Private helper methods for constructor: Codewords and masking -- */
|
|
647
|
+
// Returns a new byte string representing the given data with the appropriate error correction
|
|
648
|
+
// codewords appended to it, based on this object's version and error correction level.
|
|
649
|
+
addEccAndInterleave(data) {
|
|
650
|
+
const ver = this.version;
|
|
651
|
+
const ecl = this.ecc;
|
|
652
|
+
if (data.length !== getNumDataCodewords(ver, ecl))
|
|
653
|
+
throw new RangeError("Invalid argument");
|
|
654
|
+
const numBlocks = NUM_ERROR_CORRECTION_BLOCKS[ecl[0]][ver];
|
|
655
|
+
const blockEccLen = ECC_CODEWORDS_PER_BLOCK[ecl[0]][ver];
|
|
656
|
+
const rawCodewords = Math.floor(getNumRawDataModules(ver) / 8);
|
|
657
|
+
const numShortBlocks = numBlocks - rawCodewords % numBlocks;
|
|
658
|
+
const shortBlockLen = Math.floor(rawCodewords / numBlocks);
|
|
659
|
+
const blocks = [];
|
|
660
|
+
const rsDiv = reedSolomonComputeDivisor(blockEccLen);
|
|
661
|
+
for (let i = 0, k = 0; i < numBlocks; i++) {
|
|
662
|
+
const dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
|
|
663
|
+
k += dat.length;
|
|
664
|
+
const ecc = reedSolomonComputeRemainder(dat, rsDiv);
|
|
665
|
+
if (i < numShortBlocks)
|
|
666
|
+
dat.push(0);
|
|
667
|
+
blocks.push(dat.concat(ecc));
|
|
668
|
+
}
|
|
669
|
+
const result = [];
|
|
670
|
+
for (let i = 0; i < blocks[0].length; i++) {
|
|
671
|
+
blocks.forEach((block, j) => {
|
|
672
|
+
if (i !== shortBlockLen - blockEccLen || j >= numShortBlocks)
|
|
673
|
+
result.push(block[i]);
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
return result;
|
|
677
|
+
}
|
|
678
|
+
// Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
|
|
679
|
+
// data area of this QR Code. Function modules need to be marked off before this is called.
|
|
680
|
+
drawCodewords(data) {
|
|
681
|
+
if (data.length !== Math.floor(getNumRawDataModules(this.version) / 8))
|
|
682
|
+
throw new RangeError("Invalid argument");
|
|
683
|
+
let i = 0;
|
|
684
|
+
for (let right = this.size - 1; right >= 1; right -= 2) {
|
|
685
|
+
if (right === 6)
|
|
686
|
+
right = 5;
|
|
687
|
+
for (let vert = 0; vert < this.size; vert++) {
|
|
688
|
+
for (let j = 0; j < 2; j++) {
|
|
689
|
+
const x = right - j;
|
|
690
|
+
const upward = (right + 1 & 2) === 0;
|
|
691
|
+
const y = upward ? this.size - 1 - vert : vert;
|
|
692
|
+
if (!this.types[y][x] && i < data.length * 8) {
|
|
693
|
+
this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
|
|
694
|
+
i++;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
// XORs the codeword modules in this QR Code with the given mask pattern.
|
|
701
|
+
// The function modules must be marked and the codeword bits must be drawn
|
|
702
|
+
// before masking. Due to the arithmetic of XOR, calling applyMask() with
|
|
703
|
+
// the same mask value a second time will undo the mask. A final well-formed
|
|
704
|
+
// QR Code needs exactly one (not zero, two, etc.) mask applied.
|
|
705
|
+
applyMask(mask) {
|
|
706
|
+
if (mask < 0 || mask > 7)
|
|
707
|
+
throw new RangeError("Mask value out of range");
|
|
708
|
+
for (let y = 0; y < this.size; y++) {
|
|
709
|
+
for (let x = 0; x < this.size; x++) {
|
|
710
|
+
let invert;
|
|
711
|
+
switch (mask) {
|
|
712
|
+
case 0:
|
|
713
|
+
invert = (x + y) % 2 === 0;
|
|
714
|
+
break;
|
|
715
|
+
case 1:
|
|
716
|
+
invert = y % 2 === 0;
|
|
717
|
+
break;
|
|
718
|
+
case 2:
|
|
719
|
+
invert = x % 3 === 0;
|
|
720
|
+
break;
|
|
721
|
+
case 3:
|
|
722
|
+
invert = (x + y) % 3 === 0;
|
|
723
|
+
break;
|
|
724
|
+
case 4:
|
|
725
|
+
invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0;
|
|
726
|
+
break;
|
|
727
|
+
case 5:
|
|
728
|
+
invert = x * y % 2 + x * y % 3 === 0;
|
|
729
|
+
break;
|
|
730
|
+
case 6:
|
|
731
|
+
invert = (x * y % 2 + x * y % 3) % 2 === 0;
|
|
732
|
+
break;
|
|
733
|
+
case 7:
|
|
734
|
+
invert = ((x + y) % 2 + x * y % 3) % 2 === 0;
|
|
735
|
+
break;
|
|
736
|
+
default:
|
|
737
|
+
throw new Error("Unreachable");
|
|
738
|
+
}
|
|
739
|
+
if (!this.types[y][x] && invert)
|
|
740
|
+
this.modules[y][x] = !this.modules[y][x];
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
// Calculates and returns the penalty score based on state of this QR Code's current modules.
|
|
745
|
+
// This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
|
|
746
|
+
getPenaltyScore() {
|
|
747
|
+
let result = 0;
|
|
748
|
+
for (let y = 0; y < this.size; y++) {
|
|
749
|
+
let runColor = false;
|
|
750
|
+
let runX = 0;
|
|
751
|
+
const runHistory = [0, 0, 0, 0, 0, 0, 0];
|
|
752
|
+
for (let x = 0; x < this.size; x++) {
|
|
753
|
+
if (this.modules[y][x] === runColor) {
|
|
754
|
+
runX++;
|
|
755
|
+
if (runX === 5)
|
|
756
|
+
result += PENALTY_N1;
|
|
757
|
+
else if (runX > 5)
|
|
758
|
+
result++;
|
|
759
|
+
} else {
|
|
760
|
+
this.finderPenaltyAddHistory(runX, runHistory);
|
|
761
|
+
if (!runColor)
|
|
762
|
+
result += this.finderPenaltyCountPatterns(runHistory) * PENALTY_N3;
|
|
763
|
+
runColor = this.modules[y][x];
|
|
764
|
+
runX = 1;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * PENALTY_N3;
|
|
768
|
+
}
|
|
769
|
+
for (let x = 0; x < this.size; x++) {
|
|
770
|
+
let runColor = false;
|
|
771
|
+
let runY = 0;
|
|
772
|
+
const runHistory = [0, 0, 0, 0, 0, 0, 0];
|
|
773
|
+
for (let y = 0; y < this.size; y++) {
|
|
774
|
+
if (this.modules[y][x] === runColor) {
|
|
775
|
+
runY++;
|
|
776
|
+
if (runY === 5)
|
|
777
|
+
result += PENALTY_N1;
|
|
778
|
+
else if (runY > 5)
|
|
779
|
+
result++;
|
|
780
|
+
} else {
|
|
781
|
+
this.finderPenaltyAddHistory(runY, runHistory);
|
|
782
|
+
if (!runColor)
|
|
783
|
+
result += this.finderPenaltyCountPatterns(runHistory) * PENALTY_N3;
|
|
784
|
+
runColor = this.modules[y][x];
|
|
785
|
+
runY = 1;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
result += this.finderPenaltyTerminateAndCount(runColor, runY, runHistory) * PENALTY_N3;
|
|
789
|
+
}
|
|
790
|
+
for (let y = 0; y < this.size - 1; y++) {
|
|
791
|
+
for (let x = 0; x < this.size - 1; x++) {
|
|
792
|
+
const color = this.modules[y][x];
|
|
793
|
+
if (color === this.modules[y][x + 1] && color === this.modules[y + 1][x] && color === this.modules[y + 1][x + 1]) {
|
|
794
|
+
result += PENALTY_N2;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
let dark = 0;
|
|
799
|
+
for (const row of this.modules)
|
|
800
|
+
dark = row.reduce((sum, color) => sum + (color ? 1 : 0), dark);
|
|
801
|
+
const total = this.size * this.size;
|
|
802
|
+
const k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
|
|
803
|
+
result += k * PENALTY_N4;
|
|
804
|
+
return result;
|
|
805
|
+
}
|
|
806
|
+
/* -- Private helper functions -- */
|
|
807
|
+
// Returns an ascending list of positions of alignment patterns for this version number.
|
|
808
|
+
// Each position is in the range [0,177), and are used on both the x and y axes.
|
|
809
|
+
// This could be implemented as lookup table of 40 variable-length lists of integers.
|
|
810
|
+
getAlignmentPatternPositions() {
|
|
811
|
+
if (this.version === 1) {
|
|
812
|
+
return [];
|
|
813
|
+
} else {
|
|
814
|
+
const numAlign = Math.floor(this.version / 7) + 2;
|
|
815
|
+
const step = this.version === 32 ? 26 : Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
|
|
816
|
+
const result = [6];
|
|
817
|
+
for (let pos = this.size - 7; result.length < numAlign; pos -= step)
|
|
818
|
+
result.splice(1, 0, pos);
|
|
819
|
+
return result;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
// Can only be called immediately after a light run is added, and
|
|
823
|
+
// returns either 0, 1, or 2. A helper function for getPenaltyScore().
|
|
824
|
+
finderPenaltyCountPatterns(runHistory) {
|
|
825
|
+
const n = runHistory[1];
|
|
826
|
+
const core = n > 0 && runHistory[2] === n && runHistory[3] === n * 3 && runHistory[4] === n && runHistory[5] === n;
|
|
827
|
+
return (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0) + (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0);
|
|
828
|
+
}
|
|
829
|
+
// Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
|
|
830
|
+
finderPenaltyTerminateAndCount(currentRunColor, currentRunLength, runHistory) {
|
|
831
|
+
if (currentRunColor) {
|
|
832
|
+
this.finderPenaltyAddHistory(currentRunLength, runHistory);
|
|
833
|
+
currentRunLength = 0;
|
|
834
|
+
}
|
|
835
|
+
currentRunLength += this.size;
|
|
836
|
+
this.finderPenaltyAddHistory(currentRunLength, runHistory);
|
|
837
|
+
return this.finderPenaltyCountPatterns(runHistory);
|
|
838
|
+
}
|
|
839
|
+
// Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
|
|
840
|
+
finderPenaltyAddHistory(currentRunLength, runHistory) {
|
|
841
|
+
if (runHistory[0] === 0)
|
|
842
|
+
currentRunLength += this.size;
|
|
843
|
+
runHistory.pop();
|
|
844
|
+
runHistory.unshift(currentRunLength);
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
function appendBits(val, len, bb) {
|
|
848
|
+
if (len < 0 || len > 31 || val >>> len !== 0)
|
|
849
|
+
throw new RangeError("Value out of range");
|
|
850
|
+
for (let i = len - 1; i >= 0; i--)
|
|
851
|
+
bb.push(val >>> i & 1);
|
|
852
|
+
}
|
|
853
|
+
function getBit(x, i) {
|
|
854
|
+
return (x >>> i & 1) !== 0;
|
|
855
|
+
}
|
|
856
|
+
var QrSegment = class {
|
|
857
|
+
// Creates a new QR Code segment with the given attributes and data.
|
|
858
|
+
// The character count (numChars) must agree with the mode and the bit buffer length,
|
|
859
|
+
// but the constraint isn't checked. The given bit buffer is cloned and stored.
|
|
860
|
+
constructor(mode, numChars, bitData) {
|
|
861
|
+
this.mode = mode;
|
|
862
|
+
this.numChars = numChars;
|
|
863
|
+
this.bitData = bitData;
|
|
864
|
+
if (numChars < 0)
|
|
865
|
+
throw new RangeError("Invalid argument");
|
|
866
|
+
this.bitData = bitData.slice();
|
|
867
|
+
}
|
|
868
|
+
/* -- Methods -- */
|
|
869
|
+
// Returns a new copy of the data bits of this segment.
|
|
870
|
+
getData() {
|
|
871
|
+
return this.bitData.slice();
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
var MODE_NUMERIC = [1, 10, 12, 14];
|
|
875
|
+
var MODE_ALPHANUMERIC = [2, 9, 11, 13];
|
|
876
|
+
var MODE_BYTE = [4, 8, 16, 16];
|
|
877
|
+
function numCharCountBits(mode, ver) {
|
|
878
|
+
return mode[Math.floor((ver + 7) / 17) + 1];
|
|
879
|
+
}
|
|
880
|
+
function makeBytes(data) {
|
|
881
|
+
const bb = [];
|
|
882
|
+
for (const b of data)
|
|
883
|
+
appendBits(b, 8, bb);
|
|
884
|
+
return new QrSegment(MODE_BYTE, data.length, bb);
|
|
885
|
+
}
|
|
886
|
+
function makeNumeric(digits) {
|
|
887
|
+
if (!isNumeric(digits))
|
|
888
|
+
throw new RangeError("String contains non-numeric characters");
|
|
889
|
+
const bb = [];
|
|
890
|
+
for (let i = 0; i < digits.length; ) {
|
|
891
|
+
const n = Math.min(digits.length - i, 3);
|
|
892
|
+
appendBits(Number.parseInt(digits.substring(i, i + n), 10), n * 3 + 1, bb);
|
|
893
|
+
i += n;
|
|
894
|
+
}
|
|
895
|
+
return new QrSegment(MODE_NUMERIC, digits.length, bb);
|
|
896
|
+
}
|
|
897
|
+
function makeAlphanumeric(text) {
|
|
898
|
+
if (!isAlphanumeric(text))
|
|
899
|
+
throw new RangeError("String contains unencodable characters in alphanumeric mode");
|
|
900
|
+
const bb = [];
|
|
901
|
+
let i;
|
|
902
|
+
for (i = 0; i + 2 <= text.length; i += 2) {
|
|
903
|
+
let temp = ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
|
|
904
|
+
temp += ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
|
|
905
|
+
appendBits(temp, 11, bb);
|
|
906
|
+
}
|
|
907
|
+
if (i < text.length)
|
|
908
|
+
appendBits(ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
|
|
909
|
+
return new QrSegment(MODE_ALPHANUMERIC, text.length, bb);
|
|
910
|
+
}
|
|
911
|
+
function makeSegments(text) {
|
|
912
|
+
if (text === "")
|
|
913
|
+
return [];
|
|
914
|
+
else if (isNumeric(text))
|
|
915
|
+
return [makeNumeric(text)];
|
|
916
|
+
else if (isAlphanumeric(text))
|
|
917
|
+
return [makeAlphanumeric(text)];
|
|
918
|
+
else
|
|
919
|
+
return [makeBytes(toUtf8ByteArray(text))];
|
|
920
|
+
}
|
|
921
|
+
function isNumeric(text) {
|
|
922
|
+
return NUMERIC_REGEX.test(text);
|
|
923
|
+
}
|
|
924
|
+
function isAlphanumeric(text) {
|
|
925
|
+
return ALPHANUMERIC_REGEX.test(text);
|
|
926
|
+
}
|
|
927
|
+
function getTotalBits(segs, version) {
|
|
928
|
+
let result = 0;
|
|
929
|
+
for (const seg of segs) {
|
|
930
|
+
const ccbits = numCharCountBits(seg.mode, version);
|
|
931
|
+
if (seg.numChars >= 1 << ccbits)
|
|
932
|
+
return Number.POSITIVE_INFINITY;
|
|
933
|
+
result += 4 + ccbits + seg.bitData.length;
|
|
934
|
+
}
|
|
935
|
+
return result;
|
|
936
|
+
}
|
|
937
|
+
function toUtf8ByteArray(str) {
|
|
938
|
+
str = encodeURI(str);
|
|
939
|
+
const result = [];
|
|
940
|
+
for (let i = 0; i < str.length; i++) {
|
|
941
|
+
if (str.charAt(i) !== "%") {
|
|
942
|
+
result.push(str.charCodeAt(i));
|
|
943
|
+
} else {
|
|
944
|
+
result.push(Number.parseInt(str.substring(i + 1, i + 3), 16));
|
|
945
|
+
i += 2;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
return result;
|
|
949
|
+
}
|
|
950
|
+
function getNumRawDataModules(ver) {
|
|
951
|
+
if (ver < MIN_VERSION || ver > MAX_VERSION)
|
|
952
|
+
throw new RangeError("Version number out of range");
|
|
953
|
+
let result = (16 * ver + 128) * ver + 64;
|
|
954
|
+
if (ver >= 2) {
|
|
955
|
+
const numAlign = Math.floor(ver / 7) + 2;
|
|
956
|
+
result -= (25 * numAlign - 10) * numAlign - 55;
|
|
957
|
+
if (ver >= 7)
|
|
958
|
+
result -= 36;
|
|
959
|
+
}
|
|
960
|
+
return result;
|
|
961
|
+
}
|
|
962
|
+
function getNumDataCodewords(ver, ecl) {
|
|
963
|
+
return Math.floor(getNumRawDataModules(ver) / 8) - ECC_CODEWORDS_PER_BLOCK[ecl[0]][ver] * NUM_ERROR_CORRECTION_BLOCKS[ecl[0]][ver];
|
|
964
|
+
}
|
|
965
|
+
function reedSolomonComputeDivisor(degree) {
|
|
966
|
+
if (degree < 1 || degree > 255)
|
|
967
|
+
throw new RangeError("Degree out of range");
|
|
968
|
+
const result = [];
|
|
969
|
+
for (let i = 0; i < degree - 1; i++)
|
|
970
|
+
result.push(0);
|
|
971
|
+
result.push(1);
|
|
972
|
+
let root = 1;
|
|
973
|
+
for (let i = 0; i < degree; i++) {
|
|
974
|
+
for (let j = 0; j < result.length; j++) {
|
|
975
|
+
result[j] = reedSolomonMultiply(result[j], root);
|
|
976
|
+
if (j + 1 < result.length)
|
|
977
|
+
result[j] ^= result[j + 1];
|
|
978
|
+
}
|
|
979
|
+
root = reedSolomonMultiply(root, 2);
|
|
980
|
+
}
|
|
981
|
+
return result;
|
|
982
|
+
}
|
|
983
|
+
function reedSolomonComputeRemainder(data, divisor) {
|
|
984
|
+
const result = divisor.map((_) => 0);
|
|
985
|
+
for (const b of data) {
|
|
986
|
+
const factor = b ^ result.shift();
|
|
987
|
+
result.push(0);
|
|
988
|
+
divisor.forEach((coef, i) => result[i] ^= reedSolomonMultiply(coef, factor));
|
|
989
|
+
}
|
|
990
|
+
return result;
|
|
991
|
+
}
|
|
992
|
+
function reedSolomonMultiply(x, y) {
|
|
993
|
+
if (x >>> 8 !== 0 || y >>> 8 !== 0)
|
|
994
|
+
throw new RangeError("Byte out of range");
|
|
995
|
+
let z = 0;
|
|
996
|
+
for (let i = 7; i >= 0; i--) {
|
|
997
|
+
z = z << 1 ^ (z >>> 7) * 285;
|
|
998
|
+
z ^= (y >>> i & 1) * x;
|
|
999
|
+
}
|
|
1000
|
+
return z;
|
|
1001
|
+
}
|
|
1002
|
+
function encodeSegments(segs, ecl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
|
|
1003
|
+
if (!(MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= MAX_VERSION) || mask < -1 || mask > 7) {
|
|
1004
|
+
throw new RangeError("Invalid value");
|
|
1005
|
+
}
|
|
1006
|
+
let version;
|
|
1007
|
+
let dataUsedBits;
|
|
1008
|
+
for (version = minVersion; ; version++) {
|
|
1009
|
+
const dataCapacityBits2 = getNumDataCodewords(version, ecl) * 8;
|
|
1010
|
+
const usedBits = getTotalBits(segs, version);
|
|
1011
|
+
if (usedBits <= dataCapacityBits2) {
|
|
1012
|
+
dataUsedBits = usedBits;
|
|
1013
|
+
break;
|
|
1014
|
+
}
|
|
1015
|
+
if (version >= maxVersion)
|
|
1016
|
+
throw new RangeError("Data too long");
|
|
1017
|
+
}
|
|
1018
|
+
for (const newEcl of [MEDIUM, QUARTILE, HIGH]) {
|
|
1019
|
+
if (boostEcl && dataUsedBits <= getNumDataCodewords(version, newEcl) * 8)
|
|
1020
|
+
ecl = newEcl;
|
|
1021
|
+
}
|
|
1022
|
+
const bb = [];
|
|
1023
|
+
for (const seg of segs) {
|
|
1024
|
+
appendBits(seg.mode[0], 4, bb);
|
|
1025
|
+
appendBits(seg.numChars, numCharCountBits(seg.mode, version), bb);
|
|
1026
|
+
for (const b of seg.getData())
|
|
1027
|
+
bb.push(b);
|
|
1028
|
+
}
|
|
1029
|
+
const dataCapacityBits = getNumDataCodewords(version, ecl) * 8;
|
|
1030
|
+
appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
|
|
1031
|
+
appendBits(0, (8 - bb.length % 8) % 8, bb);
|
|
1032
|
+
for (let padByte = 236; bb.length < dataCapacityBits; padByte ^= 236 ^ 17)
|
|
1033
|
+
appendBits(padByte, 8, bb);
|
|
1034
|
+
const dataCodewords = Array.from({ length: Math.ceil(bb.length / 8) }, () => 0);
|
|
1035
|
+
bb.forEach((b, i) => dataCodewords[i >>> 3] |= b << 7 - (i & 7));
|
|
1036
|
+
return new QrCode(version, ecl, dataCodewords, mask);
|
|
1037
|
+
}
|
|
1038
|
+
function encode(data, options) {
|
|
1039
|
+
const {
|
|
1040
|
+
ecc = "L",
|
|
1041
|
+
boostEcc = false,
|
|
1042
|
+
minVersion = 1,
|
|
1043
|
+
maxVersion = 40,
|
|
1044
|
+
maskPattern = -1,
|
|
1045
|
+
border = 1
|
|
1046
|
+
} = options || {};
|
|
1047
|
+
const segment = typeof data === "string" ? makeSegments(data) : Array.isArray(data) ? [makeBytes(data)] : void 0;
|
|
1048
|
+
if (!segment)
|
|
1049
|
+
throw new Error(`uqr only supports encoding string and binary data, but got: ${typeof data}`);
|
|
1050
|
+
const qr = encodeSegments(
|
|
1051
|
+
segment,
|
|
1052
|
+
EccMap[ecc],
|
|
1053
|
+
minVersion,
|
|
1054
|
+
maxVersion,
|
|
1055
|
+
maskPattern,
|
|
1056
|
+
boostEcc
|
|
1057
|
+
);
|
|
1058
|
+
const result = addBorder({
|
|
1059
|
+
version: qr.version,
|
|
1060
|
+
maskPattern: qr.mask,
|
|
1061
|
+
size: qr.size,
|
|
1062
|
+
data: qr.modules,
|
|
1063
|
+
types: qr.types
|
|
1064
|
+
}, border);
|
|
1065
|
+
if (options?.invert)
|
|
1066
|
+
result.data = result.data.map((row) => row.map((mod) => !mod));
|
|
1067
|
+
options?.onEncoded?.(result);
|
|
1068
|
+
return result;
|
|
1069
|
+
}
|
|
1070
|
+
function addBorder(input, border = 1) {
|
|
1071
|
+
if (!border)
|
|
1072
|
+
return input;
|
|
1073
|
+
const { size } = input;
|
|
1074
|
+
const newSize = size + border * 2;
|
|
1075
|
+
input.size = newSize;
|
|
1076
|
+
input.data.forEach((row) => {
|
|
1077
|
+
for (let i = 0; i < border; i++) {
|
|
1078
|
+
row.unshift(false);
|
|
1079
|
+
row.push(false);
|
|
1080
|
+
}
|
|
1081
|
+
});
|
|
1082
|
+
for (let i = 0; i < border; i++) {
|
|
1083
|
+
input.data.unshift(Array.from({ length: newSize }, (_) => false));
|
|
1084
|
+
input.data.push(Array.from({ length: newSize }, (_) => false));
|
|
1085
|
+
}
|
|
1086
|
+
const b = QrCodeDataType.Border;
|
|
1087
|
+
input.types.forEach((row) => {
|
|
1088
|
+
for (let i = 0; i < border; i++) {
|
|
1089
|
+
row.unshift(b);
|
|
1090
|
+
row.push(b);
|
|
1091
|
+
}
|
|
1092
|
+
});
|
|
1093
|
+
for (let i = 0; i < border; i++) {
|
|
1094
|
+
input.types.unshift(Array.from({ length: newSize }, (_) => b));
|
|
1095
|
+
input.types.push(Array.from({ length: newSize }, (_) => b));
|
|
1096
|
+
}
|
|
1097
|
+
return input;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
// src/qr.ts
|
|
1101
|
+
function drawQr(canvas, text, cssSize) {
|
|
1102
|
+
const qr = encode(text, { ecc: "M", border: 2 });
|
|
1103
|
+
const scale = Math.max(1, Math.min(window.devicePixelRatio || 1, 3));
|
|
1104
|
+
canvas.width = canvas.height = Math.round(cssSize * scale);
|
|
1105
|
+
const context = canvas.getContext("2d");
|
|
1106
|
+
if (!context) return;
|
|
1107
|
+
const cell = canvas.width / qr.size;
|
|
1108
|
+
context.fillStyle = "#fff";
|
|
1109
|
+
context.fillRect(0, 0, canvas.width, canvas.height);
|
|
1110
|
+
context.fillStyle = "#000";
|
|
1111
|
+
qr.data.forEach((line, y) => line.forEach((dark, x) => {
|
|
1112
|
+
if (dark) context.fillRect(Math.floor(x * cell), Math.floor(y * cell), Math.ceil(cell), Math.ceil(cell));
|
|
1113
|
+
}));
|
|
1114
|
+
}
|
|
1115
|
+
var formatCode = (code) => `${code.slice(0, 4)}-${code.slice(4)}`;
|
|
1116
|
+
|
|
1117
|
+
// src/theme.ts
|
|
1118
|
+
function luminance(color) {
|
|
1119
|
+
const match = /rgba?\(([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)(?:[,\s/]+([\d.]+%?))?\)/.exec(color);
|
|
1120
|
+
if (!match) return null;
|
|
1121
|
+
const alpha = match[4] === void 0 ? 1 : match[4].endsWith("%") ? Number.parseFloat(match[4]) / 100 : Number(match[4]);
|
|
1122
|
+
if (alpha < 0.5) return null;
|
|
1123
|
+
const [r, g, b] = [match[1], match[2], match[3]].map((value) => {
|
|
1124
|
+
const channel = Number(value) / 255;
|
|
1125
|
+
return channel <= 0.03928 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
|
|
1126
|
+
});
|
|
1127
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
1128
|
+
}
|
|
1129
|
+
function pageTheme(element) {
|
|
1130
|
+
for (let node = element; node; node = node.parentElement) {
|
|
1131
|
+
const value = luminance(getComputedStyle(node).backgroundColor);
|
|
1132
|
+
if (value !== null) return value < 0.3 ? "dark" : "light";
|
|
1133
|
+
}
|
|
1134
|
+
const scheme = getComputedStyle(document.documentElement).colorScheme || "";
|
|
1135
|
+
if (/\bdark\b/.test(scheme) && !/\blight\b/.test(scheme)) return "dark";
|
|
1136
|
+
if (/\blight\b/.test(scheme) && /\bdark\b/.test(scheme)) return matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
1137
|
+
return "light";
|
|
1138
|
+
}
|
|
1139
|
+
function resolveTheme(requested, element) {
|
|
1140
|
+
return requested === "light" || requested === "dark" ? requested : pageTheme(element);
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
// src/styles.ts
|
|
1144
|
+
var STYLES = `
|
|
1145
|
+
:host { all: initial; }
|
|
1146
|
+
.overlay {
|
|
1147
|
+
/* Light. Lime is unreadable as text on white, so links and focus rings use a deeper violet. */
|
|
1148
|
+
--accent: var(--tsp-accent, #c8ff4d);
|
|
1149
|
+
--accent-text: var(--tsp-accent-text, #0b0d12);
|
|
1150
|
+
--accent-ink: var(--tsp-accent-ink, var(--tsp-accent, #6b4fe0));
|
|
1151
|
+
--accent-2: var(--tsp-accent-2, var(--tsp-accent, #8a6cf5));
|
|
1152
|
+
--button-edge: rgba(11, 13, 18, .1);
|
|
1153
|
+
--bg: var(--tsp-bg, #fff);
|
|
1154
|
+
--text: var(--tsp-text, #0b0d12);
|
|
1155
|
+
--muted: var(--tsp-muted, #5d6270);
|
|
1156
|
+
--line: var(--tsp-line, rgba(11, 13, 18, .12));
|
|
1157
|
+
--track: rgba(11, 13, 18, .08);
|
|
1158
|
+
--ok: #1a8a4c;
|
|
1159
|
+
--error: #c42f3d;
|
|
1160
|
+
--radius: var(--tsp-radius, 18px);
|
|
1161
|
+
position: fixed; inset: 0; z-index: 2147483000;
|
|
1162
|
+
display: grid; place-items: center; padding: 16px;
|
|
1163
|
+
background: rgba(9, 11, 16, .6);
|
|
1164
|
+
font: 15px/1.5 var(--tsp-font, Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif);
|
|
1165
|
+
color: var(--text);
|
|
1166
|
+
animation: fade .15s ease-out;
|
|
1167
|
+
}
|
|
1168
|
+
@media (prefers-color-scheme: dark) {
|
|
1169
|
+
.overlay[data-theme="auto"] { --accent-ink: var(--tsp-accent-ink, var(--tsp-accent, #c8ff4d)); --accent-2: var(--tsp-accent-2, var(--tsp-accent, #9a7cff)); --button-edge: transparent; --bg: var(--tsp-bg, #12151c); --text: var(--tsp-text, #f4f4f5); --muted: var(--tsp-muted, #9297a4); --line: var(--tsp-line, rgba(255,255,255,.09)); --track: rgba(255,255,255,.08); --ok: #c8ff4d; --error: #ff8a94; }
|
|
1170
|
+
}
|
|
1171
|
+
.overlay[data-theme="dark"] { --accent-ink: var(--tsp-accent-ink, var(--tsp-accent, #c8ff4d)); --accent-2: var(--tsp-accent-2, var(--tsp-accent, #9a7cff)); --button-edge: transparent; --bg: var(--tsp-bg, #12151c); --text: var(--tsp-text, #f4f4f5); --muted: var(--tsp-muted, #9297a4); --line: var(--tsp-line, rgba(255,255,255,.09)); --track: rgba(255,255,255,.08); --ok: #c8ff4d; --error: #ff8a94; }
|
|
1172
|
+
* { box-sizing: border-box; }
|
|
1173
|
+
[hidden] { display: none !important; }
|
|
1174
|
+
.dialog {
|
|
1175
|
+
width: min(420px, 100%); max-height: calc(100dvh - 32px); overflow: auto;
|
|
1176
|
+
background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
|
|
1177
|
+
box-shadow: 0 30px 80px rgba(0, 0, 0, .35); padding: 20px; display: grid; gap: 14px; outline: none;
|
|
1178
|
+
}
|
|
1179
|
+
.header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
|
1180
|
+
.title { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.3; }
|
|
1181
|
+
.icon-button { all: unset; cursor: pointer; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; font-size: 22px; color: var(--muted); }
|
|
1182
|
+
.icon-button:hover { background: var(--track); color: var(--text); }
|
|
1183
|
+
.qr-block { display: grid; justify-items: center; gap: 8px; text-align: center; }
|
|
1184
|
+
.qr { width: 220px; height: 220px; border-radius: 12px; background: #fff; border: 1px solid var(--line); image-rendering: pixelated; }
|
|
1185
|
+
.lead { margin: 4px 0 0; font-weight: 600; }
|
|
1186
|
+
.muted { margin: 0; color: var(--muted); font-size: 13.5px; }
|
|
1187
|
+
.small { font-size: 12px; }
|
|
1188
|
+
.code { display: inline-block; direction: ltr; font: 700 15px/1.3 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 1.5px; color: var(--text); padding: 2px 8px; border-radius: 6px; background: var(--track); }
|
|
1189
|
+
.status { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 10px; text-align: center; font-size: 14px; min-height: 22px; }
|
|
1190
|
+
.approval { display: grid; gap: 8px; width: 100%; padding: 14px; border: 1px solid var(--line); border-radius: 14px; text-align: center; }
|
|
1191
|
+
.files { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
|
|
1192
|
+
.files:empty { display: none; }
|
|
1193
|
+
.file { display: grid; gap: 3px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
|
|
1194
|
+
.file .name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1195
|
+
.file .meta { color: var(--muted); font-size: 12px; }
|
|
1196
|
+
.file .bar { height: 4px; border-radius: 4px; background: var(--track); overflow: hidden; margin-top: 3px; }
|
|
1197
|
+
.file .fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width .2s; }
|
|
1198
|
+
.file.received .meta { color: var(--ok); }
|
|
1199
|
+
.file.received .fill { background: var(--ok); }
|
|
1200
|
+
.file.failed .meta { color: var(--error); }
|
|
1201
|
+
.file.failed .bar { display: none; }
|
|
1202
|
+
.footer { display: grid; gap: 12px; }
|
|
1203
|
+
.buttons { display: flex; gap: 10px; justify-content: flex-end; }
|
|
1204
|
+
button.primary, button.secondary { font: inherit; font-weight: 600; cursor: pointer; border-radius: 12px; padding: 10px 16px; min-height: 42px; border: 1px solid transparent; }
|
|
1205
|
+
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--button-edge); box-shadow: inset 0 1px 0 rgba(255,255,255,.45), 0 8px 24px -8px color-mix(in srgb, var(--accent) 60%, transparent); }
|
|
1206
|
+
button.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 85%, #fff); }
|
|
1207
|
+
button.primary:disabled { opacity: .45; cursor: default; box-shadow: none; }
|
|
1208
|
+
button.secondary { background: transparent; color: var(--text); border-color: var(--line); }
|
|
1209
|
+
button.secondary:hover { background: var(--track); }
|
|
1210
|
+
button.link { all: unset; cursor: pointer; color: var(--accent-ink); font-weight: 600; font-size: 13.5px; text-decoration: underline; text-underline-offset: 3px; }
|
|
1211
|
+
button:focus-visible, .icon-button:focus-visible { outline: 3px solid var(--accent-ink); outline-offset: 2px; }
|
|
1212
|
+
/* ---- TokShare for desktop ---- */
|
|
1213
|
+
.announce { margin: 0; display: flex; align-items: center; gap: 10px; padding: 9px 8px 9px 12px; border-radius: 12px; border: 1px solid var(--line); background: color-mix(in srgb, var(--accent-2) 7%, transparent); color: var(--muted); font-size: 12.5px; line-height: 1.45; text-align: start; }
|
|
1214
|
+
.announce i { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--accent-2); }
|
|
1215
|
+
.announce span { flex: 1; min-width: 0; }
|
|
1216
|
+
.announce a { color: var(--accent-ink); font-weight: 650; text-decoration: underline; text-underline-offset: 2px; white-space: nowrap; }
|
|
1217
|
+
.announce-hide { all: unset; cursor: pointer; flex: none; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; font-size: 16px; color: var(--muted); }
|
|
1218
|
+
.announce-hide:hover { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); }
|
|
1219
|
+
.announce-hide:focus-visible, .announce a:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent-ink) 60%, transparent); outline-offset: 2px; }
|
|
1220
|
+
@keyframes fade { from { opacity: 0; } }
|
|
1221
|
+
@media (prefers-reduced-motion: reduce) { .overlay { animation: none; } .file .fill { transition: none; } }
|
|
1222
|
+
`;
|
|
1223
|
+
|
|
1224
|
+
// src/modal.ts
|
|
1225
|
+
function mountModal(controller, options) {
|
|
1226
|
+
const locale = resolveLocale(options.locale);
|
|
1227
|
+
const t = translator(locale, options.strings);
|
|
1228
|
+
const previousFocus = document.activeElement;
|
|
1229
|
+
const host = document.createElement("div");
|
|
1230
|
+
host.setAttribute("data-tokshare-pick", "");
|
|
1231
|
+
const root = host.attachShadow({ mode: "open" });
|
|
1232
|
+
if ("adoptedStyleSheets" in Document.prototype && "replaceSync" in CSSStyleSheet.prototype) {
|
|
1233
|
+
const sheet = new CSSStyleSheet();
|
|
1234
|
+
sheet.replaceSync(STYLES);
|
|
1235
|
+
root.adoptedStyleSheets = [sheet];
|
|
1236
|
+
} else {
|
|
1237
|
+
const style = document.createElement("style");
|
|
1238
|
+
style.textContent = STYLES;
|
|
1239
|
+
root.append(style);
|
|
1240
|
+
}
|
|
1241
|
+
const el = (tag, className = "", text = "") => {
|
|
1242
|
+
const node = document.createElement(tag);
|
|
1243
|
+
if (className) node.className = className;
|
|
1244
|
+
if (text) node.textContent = text;
|
|
1245
|
+
return node;
|
|
1246
|
+
};
|
|
1247
|
+
const overlay = el("div", "overlay");
|
|
1248
|
+
overlay.dataset.theme = resolveTheme(options.theme, document.body);
|
|
1249
|
+
const dialog = el("div", "dialog");
|
|
1250
|
+
dialog.setAttribute("role", "dialog");
|
|
1251
|
+
dialog.setAttribute("aria-modal", "true");
|
|
1252
|
+
dialog.setAttribute("aria-labelledby", "tsp-title");
|
|
1253
|
+
dialog.dir = locale === "ar" ? "rtl" : "ltr";
|
|
1254
|
+
dialog.lang = locale;
|
|
1255
|
+
dialog.tabIndex = -1;
|
|
1256
|
+
const header = el("div", "header");
|
|
1257
|
+
const title = el("h2", "title", t(options.multiple === false ? "titleOne" : "title"));
|
|
1258
|
+
title.id = "tsp-title";
|
|
1259
|
+
const closeButton = el("button", "icon-button", "\xD7");
|
|
1260
|
+
closeButton.type = "button";
|
|
1261
|
+
closeButton.setAttribute("aria-label", t("close"));
|
|
1262
|
+
header.append(title, closeButton);
|
|
1263
|
+
const qrBlock = el("div", "qr-block");
|
|
1264
|
+
const canvas = el("canvas", "qr");
|
|
1265
|
+
canvas.setAttribute("role", "img");
|
|
1266
|
+
canvas.setAttribute("aria-label", t("scan"));
|
|
1267
|
+
const scan = el("p", "lead", t("scan"));
|
|
1268
|
+
const typeLine = el("p", "muted");
|
|
1269
|
+
const code = el("span", "code");
|
|
1270
|
+
qrBlock.append(canvas, scan, typeLine);
|
|
1271
|
+
const status = el("div", "status");
|
|
1272
|
+
status.setAttribute("role", "status");
|
|
1273
|
+
status.setAttribute("aria-live", "polite");
|
|
1274
|
+
const list = el("ul", "files");
|
|
1275
|
+
const footer = el("div", "footer");
|
|
1276
|
+
const privacy = el("p", "muted small", t("privacy"));
|
|
1277
|
+
const buttons = el("div", "buttons");
|
|
1278
|
+
const cancelButton = el("button", "secondary", t("cancel"));
|
|
1279
|
+
cancelButton.type = "button";
|
|
1280
|
+
const doneButton = el("button", "primary", t("done"));
|
|
1281
|
+
doneButton.type = "button";
|
|
1282
|
+
doneButton.disabled = true;
|
|
1283
|
+
buttons.append(cancelButton, doneButton);
|
|
1284
|
+
const promo = announcement(options.announce, t);
|
|
1285
|
+
footer.append(...promo ? [promo] : [], privacy, buttons);
|
|
1286
|
+
dialog.append(header, qrBlock, status, list, footer);
|
|
1287
|
+
overlay.append(dialog);
|
|
1288
|
+
root.append(overlay);
|
|
1289
|
+
document.body.append(host);
|
|
1290
|
+
dialog.focus();
|
|
1291
|
+
const rows = /* @__PURE__ */ new Map();
|
|
1292
|
+
let phoneLabel = "";
|
|
1293
|
+
const setStatus = (text, extra) => {
|
|
1294
|
+
status.replaceChildren(el("span", "", text), ...extra ? [extra] : []);
|
|
1295
|
+
};
|
|
1296
|
+
const showQr = (claimUrl, value) => {
|
|
1297
|
+
drawQr(canvas, claimUrl, 220);
|
|
1298
|
+
const host2 = new URL(claimUrl).host;
|
|
1299
|
+
code.textContent = `${value.slice(0, 4)}-${value.slice(4)}`;
|
|
1300
|
+
typeLine.replaceChildren(document.createTextNode(`${t("orType", { host: host2 })} `), code);
|
|
1301
|
+
qrBlock.hidden = false;
|
|
1302
|
+
setStatus(t("waiting"));
|
|
1303
|
+
};
|
|
1304
|
+
const updateDone = () => {
|
|
1305
|
+
const count = controller.files.length;
|
|
1306
|
+
doneButton.disabled = count === 0;
|
|
1307
|
+
doneButton.textContent = count === 0 ? t("done") : count === 1 ? t("useFile") : t("useFiles", { count });
|
|
1308
|
+
};
|
|
1309
|
+
const renderRow = (row) => {
|
|
1310
|
+
const label = row.state === "sending" ? t("sending", { percent: row.percent }) : row.state === "receiving" ? t("receiving", { percent: row.percent }) : t(row.state);
|
|
1311
|
+
row.element.className = `file ${row.state}`;
|
|
1312
|
+
const bar = el("span", "bar");
|
|
1313
|
+
const fill = el("i", "fill");
|
|
1314
|
+
fill.style.width = `${row.state === "received" ? 100 : row.percent}%`;
|
|
1315
|
+
bar.append(fill);
|
|
1316
|
+
row.element.replaceChildren(el("span", "name", row.meta.name), el("span", "meta", `${formatBytes(row.meta.size, locale)} \xB7 ${label}`), bar);
|
|
1317
|
+
};
|
|
1318
|
+
const rowFor = (meta) => {
|
|
1319
|
+
let row = rows.get(meta.id);
|
|
1320
|
+
if (!row) {
|
|
1321
|
+
row = { element: el("li"), meta, state: "sending", percent: 0 };
|
|
1322
|
+
rows.set(meta.id, row);
|
|
1323
|
+
list.append(row.element);
|
|
1324
|
+
}
|
|
1325
|
+
return row;
|
|
1326
|
+
};
|
|
1327
|
+
let direct = false;
|
|
1328
|
+
const showConnected = () => {
|
|
1329
|
+
const disconnect = el("button", "link", t("disconnect"));
|
|
1330
|
+
disconnect.type = "button";
|
|
1331
|
+
disconnect.addEventListener("click", () => {
|
|
1332
|
+
controller.disconnect().catch(() => void 0);
|
|
1333
|
+
});
|
|
1334
|
+
setStatus(t(direct ? "connectedDirect" : "connected", { label: phoneLabel }), disconnect);
|
|
1335
|
+
};
|
|
1336
|
+
const closeModal = () => {
|
|
1337
|
+
document.removeEventListener("keydown", onKey, true);
|
|
1338
|
+
host.remove();
|
|
1339
|
+
previousFocus?.focus?.();
|
|
1340
|
+
};
|
|
1341
|
+
const onKey = (event) => {
|
|
1342
|
+
if (event.key === "Escape") {
|
|
1343
|
+
event.stopPropagation();
|
|
1344
|
+
controller.cancel();
|
|
1345
|
+
}
|
|
1346
|
+
if (event.key === "Tab") {
|
|
1347
|
+
const focusable = [...root.querySelectorAll("button:not([disabled])")];
|
|
1348
|
+
if (!focusable.length) return;
|
|
1349
|
+
const first = focusable[0];
|
|
1350
|
+
const last = focusable[focusable.length - 1];
|
|
1351
|
+
const active = root.activeElement;
|
|
1352
|
+
if (event.shiftKey && (active === first || active === dialog)) {
|
|
1353
|
+
event.preventDefault();
|
|
1354
|
+
last.focus();
|
|
1355
|
+
} else if (!event.shiftKey && active === last) {
|
|
1356
|
+
event.preventDefault();
|
|
1357
|
+
first.focus();
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
};
|
|
1361
|
+
document.addEventListener("keydown", onKey, true);
|
|
1362
|
+
closeButton.addEventListener("click", () => controller.cancel());
|
|
1363
|
+
cancelButton.addEventListener("click", () => controller.cancel());
|
|
1364
|
+
doneButton.addEventListener("click", () => controller.finish());
|
|
1365
|
+
overlay.addEventListener("click", (event) => {
|
|
1366
|
+
if (event.target === overlay) controller.cancel();
|
|
1367
|
+
});
|
|
1368
|
+
qrBlock.hidden = true;
|
|
1369
|
+
setStatus(t("loading"));
|
|
1370
|
+
controller.on("ready", ({ claimUrl, code: value }) => showQr(claimUrl, value));
|
|
1371
|
+
controller.on("phone", ({ phone, needsApproval, match }) => {
|
|
1372
|
+
phoneLabel = phone.label;
|
|
1373
|
+
qrBlock.hidden = true;
|
|
1374
|
+
if (needsApproval) {
|
|
1375
|
+
const box = el("div", "approval");
|
|
1376
|
+
const approve = el("button", "primary", t("approve"));
|
|
1377
|
+
const reject = el("button", "secondary", t("reject"));
|
|
1378
|
+
approve.type = reject.type = "button";
|
|
1379
|
+
approve.addEventListener("click", () => {
|
|
1380
|
+
controller.approve();
|
|
1381
|
+
showConnected();
|
|
1382
|
+
});
|
|
1383
|
+
reject.addEventListener("click", () => controller.reject());
|
|
1384
|
+
box.append(el("strong", "", t("approveTitle")), el("span", "muted", `${phone.label} \xB7 ${t("approveMatch", { match: match ?? "" })}`), el("div", "buttons", ""));
|
|
1385
|
+
box.lastElementChild.append(reject, approve);
|
|
1386
|
+
status.replaceChildren(box);
|
|
1387
|
+
approve.focus();
|
|
1388
|
+
} else showConnected();
|
|
1389
|
+
});
|
|
1390
|
+
controller.on("phone_left", () => {
|
|
1391
|
+
direct = false;
|
|
1392
|
+
setStatus(t("phoneLeft"));
|
|
1393
|
+
});
|
|
1394
|
+
controller.on("direct", ({ connected }) => {
|
|
1395
|
+
direct = connected;
|
|
1396
|
+
if (phoneLabel) showConnected();
|
|
1397
|
+
});
|
|
1398
|
+
controller.on("file_started", (meta) => renderRow(rowFor(meta)));
|
|
1399
|
+
controller.on("progress", (progress) => {
|
|
1400
|
+
const row = rows.get(progress.id);
|
|
1401
|
+
if (!row) return;
|
|
1402
|
+
row.state = progress.phase === "upload" ? "sending" : "receiving";
|
|
1403
|
+
row.percent = progress.total ? Math.floor(progress.sent / progress.total * 100) : 0;
|
|
1404
|
+
renderRow(row);
|
|
1405
|
+
});
|
|
1406
|
+
controller.on("received", ({ id }) => {
|
|
1407
|
+
const row = rows.get(id);
|
|
1408
|
+
if (row) {
|
|
1409
|
+
row.state = "received";
|
|
1410
|
+
renderRow(row);
|
|
1411
|
+
}
|
|
1412
|
+
updateDone();
|
|
1413
|
+
});
|
|
1414
|
+
controller.on("file_failed", ({ id }) => {
|
|
1415
|
+
const row = rows.get(id);
|
|
1416
|
+
if (row) {
|
|
1417
|
+
row.state = "failed";
|
|
1418
|
+
renderRow(row);
|
|
1419
|
+
}
|
|
1420
|
+
});
|
|
1421
|
+
controller.on("error", (error) => {
|
|
1422
|
+
qrBlock.hidden = true;
|
|
1423
|
+
const retry = el("button", "link", t("tryAgain"));
|
|
1424
|
+
retry.type = "button";
|
|
1425
|
+
retry.addEventListener("click", () => {
|
|
1426
|
+
setStatus(t("loading"));
|
|
1427
|
+
controller.restart();
|
|
1428
|
+
});
|
|
1429
|
+
setStatus(t("error", { message: error.message }), retry);
|
|
1430
|
+
});
|
|
1431
|
+
controller.on("close", (reason) => {
|
|
1432
|
+
if (reason === "finished" || reason === "canceled" || controller.files.length) return closeModal();
|
|
1433
|
+
qrBlock.hidden = true;
|
|
1434
|
+
const again = el("button", "link", t("newCode"));
|
|
1435
|
+
again.type = "button";
|
|
1436
|
+
again.addEventListener("click", () => {
|
|
1437
|
+
setStatus(t("loading"));
|
|
1438
|
+
controller.restart();
|
|
1439
|
+
});
|
|
1440
|
+
setStatus(t("expired"), again);
|
|
1441
|
+
});
|
|
1442
|
+
controller.done.then(closeModal);
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
// src/session.ts
|
|
1446
|
+
async function post(url, body) {
|
|
1447
|
+
let response;
|
|
1448
|
+
try {
|
|
1449
|
+
response = await fetch(url, { method: "POST", headers: { "Content-Type": "text/plain" }, body: JSON.stringify(body), cache: "no-store", credentials: "omit" });
|
|
1450
|
+
} catch {
|
|
1451
|
+
throw new PickError("network", "Can't reach TokShare Pick.", 0);
|
|
1452
|
+
}
|
|
1453
|
+
if (!response.ok) {
|
|
1454
|
+
const data = await response.json().catch(() => ({}));
|
|
1455
|
+
throw new PickError(data.error || "internal", data.message || `HTTP ${response.status}`, response.status);
|
|
1456
|
+
}
|
|
1457
|
+
return response;
|
|
1458
|
+
}
|
|
1459
|
+
var RelaySession = class _RelaySession {
|
|
1460
|
+
constructor(relay, info, onEvent) {
|
|
1461
|
+
__publicField(this, "info");
|
|
1462
|
+
__publicField(this, "relay");
|
|
1463
|
+
__publicField(this, "ws", null);
|
|
1464
|
+
__publicField(this, "lastSeq", 0);
|
|
1465
|
+
__publicField(this, "closed", false);
|
|
1466
|
+
__publicField(this, "attempt", 0);
|
|
1467
|
+
__publicField(this, "pinger");
|
|
1468
|
+
__publicField(this, "onEvent");
|
|
1469
|
+
this.relay = relay;
|
|
1470
|
+
this.info = info;
|
|
1471
|
+
this.onEvent = onEvent;
|
|
1472
|
+
}
|
|
1473
|
+
static async create(relay, key, options, onEvent) {
|
|
1474
|
+
const response = await post(`${relay}/v1/sessions`, { key, options, client: `sdk/${SDK_VERSION}` });
|
|
1475
|
+
const session = new _RelaySession(relay, await response.json(), onEvent);
|
|
1476
|
+
session.connect();
|
|
1477
|
+
return session;
|
|
1478
|
+
}
|
|
1479
|
+
connect() {
|
|
1480
|
+
if (this.closed) return;
|
|
1481
|
+
const ws = new WebSocket(this.info.wsUrl);
|
|
1482
|
+
this.ws = ws;
|
|
1483
|
+
ws.addEventListener("open", () => {
|
|
1484
|
+
this.attempt = 0;
|
|
1485
|
+
ws.send(JSON.stringify({ t: "auth", token: this.info.desktopToken, lastSeq: this.lastSeq }));
|
|
1486
|
+
this.pinger = setInterval(() => {
|
|
1487
|
+
if (ws.readyState === WebSocket.OPEN) ws.send("ping");
|
|
1488
|
+
}, 25e3);
|
|
1489
|
+
});
|
|
1490
|
+
ws.addEventListener("message", (message) => {
|
|
1491
|
+
if (message.data === "pong") return;
|
|
1492
|
+
let event;
|
|
1493
|
+
try {
|
|
1494
|
+
event = JSON.parse(message.data);
|
|
1495
|
+
} catch {
|
|
1496
|
+
return;
|
|
1497
|
+
}
|
|
1498
|
+
if ("seq" in event && event.t !== "hello") {
|
|
1499
|
+
if (event.seq <= this.lastSeq) return;
|
|
1500
|
+
this.lastSeq = event.seq;
|
|
1501
|
+
}
|
|
1502
|
+
if (event.t === "closed") this.closed = true;
|
|
1503
|
+
this.onEvent(event);
|
|
1504
|
+
});
|
|
1505
|
+
ws.addEventListener("close", (event) => {
|
|
1506
|
+
clearInterval(this.pinger);
|
|
1507
|
+
if (this.closed || event.code === 4401) return;
|
|
1508
|
+
setTimeout(() => this.connect(), Math.min(1e4, 400 * 2 ** this.attempt++));
|
|
1509
|
+
});
|
|
1510
|
+
}
|
|
1511
|
+
send(command) {
|
|
1512
|
+
if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(JSON.stringify(command));
|
|
1513
|
+
}
|
|
1514
|
+
/** Streams a finished file from the relay. Reports bytes received; retries a dropped stream. */
|
|
1515
|
+
async download(meta, onProgress) {
|
|
1516
|
+
for (let attempt = 0; ; attempt++) {
|
|
1517
|
+
try {
|
|
1518
|
+
const response = await post(`${this.relay}/v1/sessions/${this.info.sid}/files/${meta.id}/download`, { token: this.info.desktopToken });
|
|
1519
|
+
const reader = response.body.getReader();
|
|
1520
|
+
const chunks = [];
|
|
1521
|
+
let received = 0;
|
|
1522
|
+
for (; ; ) {
|
|
1523
|
+
const { done, value } = await reader.read();
|
|
1524
|
+
if (done) break;
|
|
1525
|
+
chunks.push(value);
|
|
1526
|
+
received += value.byteLength;
|
|
1527
|
+
onProgress(received);
|
|
1528
|
+
}
|
|
1529
|
+
if (received !== meta.size) throw new PickError("network", "Incomplete download.", 0);
|
|
1530
|
+
return new File(chunks, meta.name, { type: meta.type || meta.sniffed || "", lastModified: meta.lastModified });
|
|
1531
|
+
} catch (error) {
|
|
1532
|
+
if (!(error instanceof PickError && error.code === "network") || attempt >= 2) throw error;
|
|
1533
|
+
await new Promise((resolve) => setTimeout(resolve, 600 * (attempt + 1)));
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
/** A file that came over the direct link: delivered (counted, phone told), or refused and why. */
|
|
1538
|
+
directResult(id, ok, code) {
|
|
1539
|
+
return post(`${this.relay}/v1/sessions/${this.info.sid}/files/${id}/direct`, { token: this.info.desktopToken, ok, ...code ? { code } : {} }).catch(() => void 0);
|
|
1540
|
+
}
|
|
1541
|
+
ack(id) {
|
|
1542
|
+
return post(`${this.relay}/v1/sessions/${this.info.sid}/files/${id}/ack`, { token: this.info.desktopToken }).catch(() => void 0);
|
|
1543
|
+
}
|
|
1544
|
+
/** Forget the connected phone and get a new QR and code. */
|
|
1545
|
+
async rekey() {
|
|
1546
|
+
const response = await post(`${this.relay}/v1/sessions/${this.info.sid}/rekey`, { token: this.info.desktopToken });
|
|
1547
|
+
const fresh = await response.json();
|
|
1548
|
+
Object.assign(this.info, fresh);
|
|
1549
|
+
return fresh;
|
|
1550
|
+
}
|
|
1551
|
+
/** Ends the session: the relay deletes anything left. Uses a beacon while the page is unloading. */
|
|
1552
|
+
close(unloading = false) {
|
|
1553
|
+
if (this.closed) return;
|
|
1554
|
+
this.closed = true;
|
|
1555
|
+
clearInterval(this.pinger);
|
|
1556
|
+
const url = `${this.relay}/v1/sessions/${this.info.sid}/close`;
|
|
1557
|
+
const body = JSON.stringify({ token: this.info.desktopToken });
|
|
1558
|
+
if (unloading && typeof navigator !== "undefined" && navigator.sendBeacon) navigator.sendBeacon(url, new Blob([body], { type: "text/plain" }));
|
|
1559
|
+
else post(url, { token: this.info.desktopToken }).catch(() => void 0);
|
|
1560
|
+
try {
|
|
1561
|
+
this.ws?.close(1e3, "closed");
|
|
1562
|
+
} catch {
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
get isClosed() {
|
|
1566
|
+
return this.closed;
|
|
1567
|
+
}
|
|
1568
|
+
};
|
|
1569
|
+
|
|
1570
|
+
// src/picker.ts
|
|
1571
|
+
function open(options) {
|
|
1572
|
+
if (!options || typeof options.key !== "string") throw new PickError("key_invalid", "Pass your publishable key: open({ key: 'pk_live_\u2026' }).");
|
|
1573
|
+
const relay = (options.relay || DEFAULT_RELAY).replace(/\/+$/, "");
|
|
1574
|
+
const handlers = /* @__PURE__ */ new Map();
|
|
1575
|
+
const emit = (event, detail) => {
|
|
1576
|
+
for (const handler of handlers.get(event) ?? []) {
|
|
1577
|
+
try {
|
|
1578
|
+
handler(detail);
|
|
1579
|
+
} catch (error) {
|
|
1580
|
+
console.error(error);
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
};
|
|
1584
|
+
const files = [];
|
|
1585
|
+
const handled = /* @__PURE__ */ new Set();
|
|
1586
|
+
const metas = /* @__PURE__ */ new Map();
|
|
1587
|
+
const pending = /* @__PURE__ */ new Set();
|
|
1588
|
+
const directDone = /* @__PURE__ */ new Set();
|
|
1589
|
+
const metaWaiters = /* @__PURE__ */ new Map();
|
|
1590
|
+
let session = null;
|
|
1591
|
+
let receiver = null;
|
|
1592
|
+
let settled = false;
|
|
1593
|
+
let resolveDone;
|
|
1594
|
+
const done = new Promise((resolve) => {
|
|
1595
|
+
resolveDone = resolve;
|
|
1596
|
+
});
|
|
1597
|
+
const multiple = options.multiple !== false;
|
|
1598
|
+
const sessionOptions = {
|
|
1599
|
+
...options.accept !== void 0 ? { accept: options.accept } : {},
|
|
1600
|
+
multiple,
|
|
1601
|
+
...options.maxFiles !== void 0 ? { maxFiles: options.maxFiles } : {},
|
|
1602
|
+
...options.maxFileBytes !== void 0 ? { maxFileBytes: options.maxFileBytes } : {},
|
|
1603
|
+
...options.resizeImages ? { resizeImages: options.resizeImages } : {},
|
|
1604
|
+
...options.confirmPhone ? { confirmPhone: true } : {},
|
|
1605
|
+
...options.siteName ? { siteName: options.siteName } : {},
|
|
1606
|
+
...options.locale === "ar" || options.locale === "en" ? { locale: options.locale } : {},
|
|
1607
|
+
...options.direct === false ? { direct: false } : {}
|
|
1608
|
+
};
|
|
1609
|
+
let maxFiles = multiple ? options.maxFiles ?? 20 : 1;
|
|
1610
|
+
const settle = (reason, result) => {
|
|
1611
|
+
if (settled) return;
|
|
1612
|
+
settled = true;
|
|
1613
|
+
removeEventListener("pagehide", onPageHide);
|
|
1614
|
+
receiver?.close();
|
|
1615
|
+
session?.close();
|
|
1616
|
+
emit("close", reason);
|
|
1617
|
+
resolveDone(result);
|
|
1618
|
+
};
|
|
1619
|
+
const onPageHide = () => session?.close(true);
|
|
1620
|
+
const receive = (meta) => {
|
|
1621
|
+
if (directDone.has(meta.id)) {
|
|
1622
|
+
session?.ack(meta.id);
|
|
1623
|
+
return;
|
|
1624
|
+
}
|
|
1625
|
+
if (handled.has(meta.id) || !session) return;
|
|
1626
|
+
handled.add(meta.id);
|
|
1627
|
+
const current = session;
|
|
1628
|
+
const task = current.download(meta, (received) => emit("progress", { id: meta.id, name: meta.name, sent: received, total: meta.size, phase: "download" })).then(async (file) => {
|
|
1629
|
+
await current.ack(meta.id);
|
|
1630
|
+
if (settled) return;
|
|
1631
|
+
files.push(file);
|
|
1632
|
+
emit("received", { id: meta.id, file });
|
|
1633
|
+
emit("file", file);
|
|
1634
|
+
if (files.length >= maxFiles) controller.finish();
|
|
1635
|
+
}).catch((error) => emit("file_failed", { id: meta.id, code: error instanceof PickError ? error.code : "network" })).finally(() => pending.delete(task));
|
|
1636
|
+
pending.add(task);
|
|
1637
|
+
};
|
|
1638
|
+
const knownMeta = (id) => {
|
|
1639
|
+
const meta = metas.get(id);
|
|
1640
|
+
if (meta) return Promise.resolve(meta);
|
|
1641
|
+
return new Promise((resolve) => {
|
|
1642
|
+
const timer = setTimeout(() => {
|
|
1643
|
+
metaWaiters.delete(id);
|
|
1644
|
+
resolve(null);
|
|
1645
|
+
}, 1e4);
|
|
1646
|
+
metaWaiters.set(id, (value) => {
|
|
1647
|
+
clearTimeout(timer);
|
|
1648
|
+
metaWaiters.delete(id);
|
|
1649
|
+
resolve(value);
|
|
1650
|
+
});
|
|
1651
|
+
});
|
|
1652
|
+
};
|
|
1653
|
+
const completeDirect = async (id, chunks, size) => {
|
|
1654
|
+
const current = session;
|
|
1655
|
+
const meta = await knownMeta(id);
|
|
1656
|
+
if (!current || !meta || settled || handled.has(id)) return { ok: false, code: "failed" };
|
|
1657
|
+
const result = verifyDirectFile(meta, chunks, size, current.info.options.accept, current.info.options.maxFileBytes);
|
|
1658
|
+
if (!result.ok) {
|
|
1659
|
+
current.directResult(id, false, result.code);
|
|
1660
|
+
return result;
|
|
1661
|
+
}
|
|
1662
|
+
handled.add(id);
|
|
1663
|
+
directDone.add(id);
|
|
1664
|
+
current.directResult(id, true);
|
|
1665
|
+
files.push(result.file);
|
|
1666
|
+
emit("received", { id, file: result.file });
|
|
1667
|
+
emit("file", result.file);
|
|
1668
|
+
if (files.length >= maxFiles) controller.finish();
|
|
1669
|
+
return { ok: true };
|
|
1670
|
+
};
|
|
1671
|
+
const directReceiver = (current) => {
|
|
1672
|
+
if (options.direct === false || !DirectReceiver.supported()) return null;
|
|
1673
|
+
if (!receiver) {
|
|
1674
|
+
receiver = new DirectReceiver((d) => current.send({ t: "rtc", d }), {
|
|
1675
|
+
progress: (id, received, total) => emit("progress", { id, name: metas.get(id)?.name ?? "", sent: received, total, phase: "upload" }),
|
|
1676
|
+
complete: completeDirect,
|
|
1677
|
+
state: (connected) => emit("direct", { connected })
|
|
1678
|
+
});
|
|
1679
|
+
}
|
|
1680
|
+
return receiver;
|
|
1681
|
+
};
|
|
1682
|
+
const onEvent = (event) => {
|
|
1683
|
+
switch (event.t) {
|
|
1684
|
+
case "rtc":
|
|
1685
|
+
if (session) directReceiver(session)?.onSignal(event.d);
|
|
1686
|
+
break;
|
|
1687
|
+
case "hello":
|
|
1688
|
+
for (const meta of event.files) {
|
|
1689
|
+
if (!handled.has(meta.id)) {
|
|
1690
|
+
metas.set(meta.id, meta);
|
|
1691
|
+
emit("file_started", meta);
|
|
1692
|
+
}
|
|
1693
|
+
receive(meta);
|
|
1694
|
+
}
|
|
1695
|
+
break;
|
|
1696
|
+
case "phone":
|
|
1697
|
+
emit("phone", { phone: event.phone, needsApproval: event.needsApproval, ...event.match ? { match: event.match } : {} });
|
|
1698
|
+
break;
|
|
1699
|
+
case "phone_left":
|
|
1700
|
+
receiver?.close();
|
|
1701
|
+
emit("phone_left", void 0);
|
|
1702
|
+
break;
|
|
1703
|
+
case "file_started":
|
|
1704
|
+
metas.set(event.file.id, event.file);
|
|
1705
|
+
metaWaiters.get(event.file.id)?.(event.file);
|
|
1706
|
+
emit("file_started", event.file);
|
|
1707
|
+
break;
|
|
1708
|
+
case "progress":
|
|
1709
|
+
emit("progress", { id: event.id, name: metas.get(event.id)?.name ?? "", sent: event.sent, total: event.total, phase: "upload" });
|
|
1710
|
+
break;
|
|
1711
|
+
case "file_ready":
|
|
1712
|
+
receive(event.file);
|
|
1713
|
+
break;
|
|
1714
|
+
case "file_failed":
|
|
1715
|
+
emit("file_failed", { id: event.id, code: event.code });
|
|
1716
|
+
break;
|
|
1717
|
+
case "phone_done":
|
|
1718
|
+
if (files.length || pending.size) controller.finish();
|
|
1719
|
+
break;
|
|
1720
|
+
case "closed":
|
|
1721
|
+
if (files.length) settle(event.reason, [...files]);
|
|
1722
|
+
else emit("close", event.reason);
|
|
1723
|
+
break;
|
|
1724
|
+
}
|
|
1725
|
+
};
|
|
1726
|
+
const start = () => {
|
|
1727
|
+
RelaySession.create(relay, options.key, sessionOptions, onEvent).then((created) => {
|
|
1728
|
+
if (settled) {
|
|
1729
|
+
created.close();
|
|
1730
|
+
return;
|
|
1731
|
+
}
|
|
1732
|
+
session = created;
|
|
1733
|
+
maxFiles = created.info.options.maxFiles;
|
|
1734
|
+
emit("ready", { claimUrl: created.info.claimUrl, code: created.info.code });
|
|
1735
|
+
}, (error) => emit("error", error));
|
|
1736
|
+
};
|
|
1737
|
+
const controller = {
|
|
1738
|
+
done,
|
|
1739
|
+
get files() {
|
|
1740
|
+
return files;
|
|
1741
|
+
},
|
|
1742
|
+
get claimUrl() {
|
|
1743
|
+
return session?.info.claimUrl ?? null;
|
|
1744
|
+
},
|
|
1745
|
+
get code() {
|
|
1746
|
+
return session?.info.code ?? null;
|
|
1747
|
+
},
|
|
1748
|
+
on(event, handler) {
|
|
1749
|
+
if (!handlers.has(event)) handlers.set(event, /* @__PURE__ */ new Set());
|
|
1750
|
+
handlers.get(event).add(handler);
|
|
1751
|
+
return () => handlers.get(event)?.delete(handler);
|
|
1752
|
+
},
|
|
1753
|
+
finish() {
|
|
1754
|
+
if (settled) return;
|
|
1755
|
+
Promise.allSettled([...pending]).then(() => settle("finished", [...files]));
|
|
1756
|
+
},
|
|
1757
|
+
cancel() {
|
|
1758
|
+
settle("canceled", []);
|
|
1759
|
+
},
|
|
1760
|
+
approve() {
|
|
1761
|
+
session?.send({ t: "approve" });
|
|
1762
|
+
},
|
|
1763
|
+
reject() {
|
|
1764
|
+
session?.send({ t: "reject" });
|
|
1765
|
+
},
|
|
1766
|
+
async disconnect() {
|
|
1767
|
+
if (!session) return;
|
|
1768
|
+
receiver?.close();
|
|
1769
|
+
const fresh = await session.rekey();
|
|
1770
|
+
emit("ready", fresh);
|
|
1771
|
+
},
|
|
1772
|
+
restart() {
|
|
1773
|
+
if (settled) return;
|
|
1774
|
+
receiver?.close();
|
|
1775
|
+
receiver = null;
|
|
1776
|
+
session?.close();
|
|
1777
|
+
session = null;
|
|
1778
|
+
start();
|
|
1779
|
+
}
|
|
1780
|
+
};
|
|
1781
|
+
addEventListener("pagehide", onPageHide);
|
|
1782
|
+
options.signal?.addEventListener("abort", () => controller.cancel(), { once: true });
|
|
1783
|
+
if (options.ui !== false) mountModal(controller, options);
|
|
1784
|
+
start();
|
|
1785
|
+
return controller;
|
|
1786
|
+
}
|
|
1787
|
+
function pick(options) {
|
|
1788
|
+
return open(options).done;
|
|
1789
|
+
}
|
|
1790
|
+
function attach(input, options) {
|
|
1791
|
+
if (!(input instanceof HTMLInputElement) || input.type !== "file") throw new PickError("bad_request", 'attach() needs an <input type="file">.');
|
|
1792
|
+
return async () => {
|
|
1793
|
+
const received = await pick({ ...options, accept: input.accept, multiple: input.multiple });
|
|
1794
|
+
if (!received.length) return received;
|
|
1795
|
+
const transfer = new DataTransfer();
|
|
1796
|
+
if (options.mode === "append" && input.multiple) for (const file of Array.from(input.files ?? [])) transfer.items.add(file);
|
|
1797
|
+
for (const file of input.multiple ? received : received.slice(0, 1)) transfer.items.add(file);
|
|
1798
|
+
input.files = transfer.files;
|
|
1799
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
1800
|
+
input.dispatchEvent(new Event("change", { bubbles: true }));
|
|
1801
|
+
return received;
|
|
1802
|
+
};
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1805
|
+
// src/fieldStyles.ts
|
|
1806
|
+
var FIELD_STYLES = `
|
|
1807
|
+
:host { display: block; }
|
|
1808
|
+
* { box-sizing: border-box; }
|
|
1809
|
+
[hidden] { display: none !important; }
|
|
1810
|
+
.wrap {
|
|
1811
|
+
/* Light. Lime is unreadable as text or a thin line on white, so those use a deeper violet. */
|
|
1812
|
+
--accent: var(--tsp-accent, #c8ff4d);
|
|
1813
|
+
--accent-text: var(--tsp-accent-text, #0b0d12);
|
|
1814
|
+
--accent-ink: var(--tsp-accent-ink, var(--tsp-accent, #6b4fe0));
|
|
1815
|
+
--accent-2: var(--tsp-accent-2, var(--tsp-accent, #8a6cf5));
|
|
1816
|
+
--button-edge: rgba(11, 13, 18, .1);
|
|
1817
|
+
--bg: var(--tsp-bg, #ffffff);
|
|
1818
|
+
--surface: var(--tsp-surface, #f6f7f9);
|
|
1819
|
+
--text: var(--tsp-text, #0b0d12);
|
|
1820
|
+
--muted: var(--tsp-muted, #5d6270);
|
|
1821
|
+
--line: var(--tsp-line, rgba(11, 13, 18, .12));
|
|
1822
|
+
--ok: #1a8a4c;
|
|
1823
|
+
--error: #c42f3d;
|
|
1824
|
+
--radius: var(--tsp-radius, 18px);
|
|
1825
|
+
container-type: inline-size;
|
|
1826
|
+
font: 14px/1.5 var(--tsp-font, Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif);
|
|
1827
|
+
color: var(--text);
|
|
1828
|
+
}
|
|
1829
|
+
@media (prefers-color-scheme: dark) {
|
|
1830
|
+
.wrap[data-theme="auto"] { --accent-ink: var(--tsp-accent-ink, var(--tsp-accent, #c8ff4d)); --accent-2: var(--tsp-accent-2, var(--tsp-accent, #9a7cff)); --button-edge: transparent; --bg: var(--tsp-bg, #171a22); --surface: var(--tsp-surface, #12151c); --text: var(--tsp-text, #f4f4f5); --muted: var(--tsp-muted, #9297a4); --line: var(--tsp-line, rgba(255,255,255,.09)); --ok: #c8ff4d; --error: #ff8a94; }
|
|
1831
|
+
}
|
|
1832
|
+
.wrap[data-theme="dark"] { --accent-ink: var(--tsp-accent-ink, var(--tsp-accent, #c8ff4d)); --accent-2: var(--tsp-accent-2, var(--tsp-accent, #9a7cff)); --button-edge: transparent; --bg: var(--tsp-bg, #171a22); --surface: var(--tsp-surface, #12151c); --text: var(--tsp-text, #f4f4f5); --muted: var(--tsp-muted, #9297a4); --line: var(--tsp-line, rgba(255,255,255,.09)); --ok: #c8ff4d; --error: #ff8a94; }
|
|
1833
|
+
|
|
1834
|
+
/* ---- drop zone ---- */
|
|
1835
|
+
.zone {
|
|
1836
|
+
position: relative;
|
|
1837
|
+
border: 1.5px dashed color-mix(in srgb, var(--accent-ink) 42%, transparent);
|
|
1838
|
+
border-radius: var(--radius);
|
|
1839
|
+
background:
|
|
1840
|
+
radial-gradient(120% 90% at 50% 0%, color-mix(in srgb, var(--accent-2) 12%, transparent), transparent 70%),
|
|
1841
|
+
var(--surface);
|
|
1842
|
+
padding: 30px 22px;
|
|
1843
|
+
min-height: 232px;
|
|
1844
|
+
display: grid;
|
|
1845
|
+
align-items: center;
|
|
1846
|
+
transition: border-color .18s, background-color .18s, box-shadow .18s;
|
|
1847
|
+
}
|
|
1848
|
+
.zone[data-state="idle"]:hover { border-color: color-mix(in srgb, var(--accent-ink) 70%, transparent); }
|
|
1849
|
+
.zone[data-drag] {
|
|
1850
|
+
border-style: solid;
|
|
1851
|
+
border-color: var(--accent-ink);
|
|
1852
|
+
background-color: color-mix(in srgb, var(--accent-ink) 8%, var(--surface));
|
|
1853
|
+
box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent-ink) 16%, transparent);
|
|
1854
|
+
}
|
|
1855
|
+
.zone[data-drag] .tile { transform: translateY(-3px) scale(1.06); }
|
|
1856
|
+
.idle { display: grid; justify-items: center; text-align: center; gap: 6px; }
|
|
1857
|
+
.tile {
|
|
1858
|
+
width: 56px; height: 56px; margin-bottom: 8px;
|
|
1859
|
+
display: grid; place-items: center;
|
|
1860
|
+
border-radius: 16px;
|
|
1861
|
+
background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 80%, #fff), var(--accent));
|
|
1862
|
+
color: var(--accent-text);
|
|
1863
|
+
box-shadow: inset 0 1px 0 rgba(255,255,255,.45), inset 0 0 0 1px var(--button-edge), 0 12px 26px -6px color-mix(in srgb, var(--accent) 45%, transparent);
|
|
1864
|
+
transition: transform .2s;
|
|
1865
|
+
}
|
|
1866
|
+
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
|
|
1867
|
+
.tile svg { width: 26px; height: 26px; stroke-width: 2; }
|
|
1868
|
+
.title { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
|
|
1869
|
+
.hint { margin: 0; color: var(--muted); font-size: 13px; }
|
|
1870
|
+
.actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; margin-top: 12px; }
|
|
1871
|
+
.or { color: var(--muted); font-size: 12.5px; }
|
|
1872
|
+
|
|
1873
|
+
button { font: inherit; cursor: pointer; }
|
|
1874
|
+
.primary, .ghost {
|
|
1875
|
+
display: inline-flex; align-items: center; gap: 8px;
|
|
1876
|
+
min-height: 40px; padding: 8px 16px;
|
|
1877
|
+
border-radius: 11px; font-weight: 600; font-size: 14px;
|
|
1878
|
+
border: 1px solid transparent;
|
|
1879
|
+
transition: transform .12s, box-shadow .15s, background-color .15s, border-color .15s;
|
|
1880
|
+
}
|
|
1881
|
+
.primary { background: var(--accent); color: var(--accent-text); border-color: var(--button-edge); box-shadow: inset 0 1px 0 rgba(255,255,255,.45), 0 8px 22px -8px color-mix(in srgb, var(--accent) 60%, transparent); }
|
|
1882
|
+
.primary:hover { background: color-mix(in srgb, var(--accent) 85%, #fff); box-shadow: inset 0 1px 0 rgba(255,255,255,.5), 0 12px 28px -8px color-mix(in srgb, var(--accent) 70%, transparent); }
|
|
1883
|
+
.ghost { background: var(--bg); color: var(--text); border-color: var(--line); }
|
|
1884
|
+
.ghost:hover { border-color: color-mix(in srgb, var(--accent-ink) 55%, transparent); color: var(--accent-ink); }
|
|
1885
|
+
.primary:active, .ghost:active { transform: translateY(1px); }
|
|
1886
|
+
.primary.small { min-height: 34px; padding: 6px 14px; font-size: 13px; }
|
|
1887
|
+
.link { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 600; font-size: 13px; }
|
|
1888
|
+
.link:hover { color: var(--text); }
|
|
1889
|
+
button:focus-visible, .link:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent-ink) 60%, transparent); outline-offset: 2px; border-radius: 10px; }
|
|
1890
|
+
[dir="rtl"] .flip { transform: scaleX(-1); }
|
|
1891
|
+
|
|
1892
|
+
/* ---- phone, inside the field ---- */
|
|
1893
|
+
.phone-view { display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: center; }
|
|
1894
|
+
.qr-box { position: relative; width: 184px; height: 184px; padding: 8px; border-radius: 16px; background: #fff; border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(15, 18, 30, .1); }
|
|
1895
|
+
.qr { width: 100%; height: 100%; display: block; image-rendering: pixelated; transition: opacity .25s, filter .25s; }
|
|
1896
|
+
.qr-box.dim .qr { opacity: .18; filter: blur(1px); }
|
|
1897
|
+
.qr-loading { display: none; position: absolute; inset: 8px; border-radius: 10px; background: linear-gradient(100deg, #eef0f5 30%, #f8f9fc 50%, #eef0f5 70%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
|
|
1898
|
+
.qr-box.loading .qr-loading { display: block; }
|
|
1899
|
+
.phone-info { display: grid; gap: 10px; min-width: 0; }
|
|
1900
|
+
.steps { margin: 0; padding: 0; list-style: none; counter-reset: step; display: grid; gap: 7px; }
|
|
1901
|
+
.steps li { counter-increment: step; display: flex; gap: 10px; align-items: baseline; color: var(--muted); font-size: 13.5px; }
|
|
1902
|
+
.steps li::before { content: counter(step); flex: none; width: 20px; height: 20px; display: inline-grid; place-items: center; border-radius: 50%; font-size: 11px; font-weight: 700; color: var(--accent-ink); background: color-mix(in srgb, var(--accent-ink) 14%, transparent); transform: translateY(4px); }
|
|
1903
|
+
.code-line { margin: 0; color: var(--muted); font-size: 12.5px; }
|
|
1904
|
+
.code-line b { direction: ltr; display: inline-block; font: 700 13px/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 1.2px; color: var(--text); background: var(--bg); border: 1px solid var(--line); padding: 1px 7px; border-radius: 6px; }
|
|
1905
|
+
.status { margin: 0; justify-self: start; display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-size: 13px; font-weight: 600; }
|
|
1906
|
+
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: .6; }
|
|
1907
|
+
.status.live i { background: var(--ok); opacity: 1; box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); animation: pulse 1.8s infinite; }
|
|
1908
|
+
.phone-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 2px; }
|
|
1909
|
+
.announce-slot { grid-column: 1 / -1; }
|
|
1910
|
+
/* ---- TokShare for desktop ---- */
|
|
1911
|
+
.announce { margin: 0; display: flex; align-items: center; gap: 10px; padding: 9px 8px 9px 12px; border-radius: 12px; border: 1px solid var(--line); background: color-mix(in srgb, var(--accent-2) 7%, transparent); color: var(--muted); font-size: 12.5px; line-height: 1.45; text-align: start; }
|
|
1912
|
+
.announce i { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--accent-2); }
|
|
1913
|
+
.announce span { flex: 1; min-width: 0; }
|
|
1914
|
+
.announce a { color: var(--accent-ink); font-weight: 650; text-decoration: underline; text-underline-offset: 2px; white-space: nowrap; }
|
|
1915
|
+
.announce-hide { all: unset; cursor: pointer; flex: none; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; font-size: 16px; color: var(--muted); }
|
|
1916
|
+
.announce-hide:hover { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); }
|
|
1917
|
+
.announce-hide:focus-visible, .announce a:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent-ink) 60%, transparent); outline-offset: 2px; }
|
|
1918
|
+
|
|
1919
|
+
/* ---- messages and list ---- */
|
|
1920
|
+
.message { margin: 10px 2px 0; color: var(--error); font-size: 13px; }
|
|
1921
|
+
.list-head { display: flex; justify-content: space-between; align-items: center; margin: 14px 2px 6px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
|
|
1922
|
+
.list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
|
|
1923
|
+
.list-head:not([hidden]) + .list { margin-top: 0; }
|
|
1924
|
+
.item { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 9px 10px 9px 9px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); animation: rise .2s ease-out; }
|
|
1925
|
+
.thumb { width: 44px; height: 44px; border-radius: 10px; overflow: hidden; display: grid; place-items: center; background: color-mix(in srgb, var(--accent-ink) 12%, transparent); color: var(--accent-ink); font-size: 10.5px; font-weight: 800; letter-spacing: .4px; }
|
|
1926
|
+
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
|
|
1927
|
+
.body { display: grid; gap: 2px; min-width: 0; }
|
|
1928
|
+
.name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1929
|
+
.meta { color: var(--muted); font-size: 12px; }
|
|
1930
|
+
.bar { height: 4px; border-radius: 4px; margin-top: 4px; background: color-mix(in srgb, var(--accent-ink) 12%, transparent); overflow: hidden; }
|
|
1931
|
+
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent-2), var(--accent)); border-radius: inherit; transition: width .2s; }
|
|
1932
|
+
.item.failed .meta { color: var(--error); }
|
|
1933
|
+
.remove { all: unset; cursor: pointer; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; color: var(--muted); }
|
|
1934
|
+
.remove:hover { background: color-mix(in srgb, var(--error) 10%, transparent); color: var(--error); }
|
|
1935
|
+
.remove svg { width: 16px; height: 16px; }
|
|
1936
|
+
|
|
1937
|
+
@container (max-width: 520px) {
|
|
1938
|
+
.zone { padding: 24px 16px; }
|
|
1939
|
+
.phone-view { grid-template-columns: 1fr; justify-items: center; text-align: center; gap: 16px; }
|
|
1940
|
+
.steps li { text-align: start; }
|
|
1941
|
+
.status { justify-self: center; }
|
|
1942
|
+
}
|
|
1943
|
+
@keyframes shimmer { to { background-position: -200% 0; } }
|
|
1944
|
+
@keyframes pulse { 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
|
|
1945
|
+
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }
|
|
1946
|
+
@media (prefers-reduced-motion: reduce) { .zone, .tile, .qr, .bar i, .item { transition: none; animation: none; } .qr-loading, .status.live i { animation: none; } }
|
|
1947
|
+
`;
|
|
1948
|
+
|
|
1949
|
+
// src/field.ts
|
|
1950
|
+
var ICONS = {
|
|
1951
|
+
upload: '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 15V4m0 0L7.5 8.5M12 4l4.5 4.5M5 14v4a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-4"/></svg>',
|
|
1952
|
+
folder: '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3.5 7.5a2 2 0 0 1 2-2h4l2 2h7a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2z"/></svg>',
|
|
1953
|
+
phone: '<svg viewBox="0 0 24 24" aria-hidden="true"><rect x="7" y="2.5" width="10" height="19" rx="2.5"/><path d="M11 18.5h2"/></svg>',
|
|
1954
|
+
close: '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M7 7l10 10M17 7 7 17"/></svg>',
|
|
1955
|
+
back: '<svg viewBox="0 0 24 24" aria-hidden="true" class="flip"><path d="M14.5 6 8.5 12l6 6"/></svg>'
|
|
1956
|
+
};
|
|
1957
|
+
function parseSize(value) {
|
|
1958
|
+
if (value === null || value === void 0 || value === "") return void 0;
|
|
1959
|
+
if (typeof value === "number") return value > 0 ? value : void 0;
|
|
1960
|
+
const match = /^\s*([\d.]+)\s*(b|kb|mb|gb)?\s*$/i.exec(value);
|
|
1961
|
+
if (!match) return void 0;
|
|
1962
|
+
const units = { b: 1, kb: 1e3, mb: 1e6, gb: 1e9 };
|
|
1963
|
+
const bytes = Number(match[1]) * units[(match[2] ?? "b").toLowerCase()];
|
|
1964
|
+
return bytes > 0 ? Math.round(bytes) : void 0;
|
|
1965
|
+
}
|
|
1966
|
+
function acceptLabel(accept) {
|
|
1967
|
+
return accept.split(",").map((part) => part.trim()).filter(Boolean).map((part) => {
|
|
1968
|
+
if (part.endsWith("/*")) return part.slice(0, -2).replace(/^./, (letter) => letter.toUpperCase()) + "s";
|
|
1969
|
+
if (part.startsWith(".")) return part.slice(1).toUpperCase();
|
|
1970
|
+
const sub = part.split("/")[1] ?? part;
|
|
1971
|
+
return sub === "jpeg" ? "JPG" : sub.replace(/^(x-|vnd\.)/, "").split(/[.+-]/)[0].toUpperCase();
|
|
1972
|
+
}).filter((label, index, all) => all.indexOf(label) === index).join(", ");
|
|
1973
|
+
}
|
|
1974
|
+
var isPhonePage = () => typeof matchMedia === "function" && matchMedia("(pointer: coarse)").matches && innerWidth < 820;
|
|
1975
|
+
function mountField(target, options) {
|
|
1976
|
+
const container = typeof target === "string" ? document.querySelector(target) : target;
|
|
1977
|
+
if (!container) throw new Error(`TokShare Pick: ${String(target)} not found`);
|
|
1978
|
+
const locale = resolveLocale(options.locale);
|
|
1979
|
+
const t = translator(locale, options.strings);
|
|
1980
|
+
const multiple = options.multiple !== false;
|
|
1981
|
+
const maxFiles = multiple ? Math.min(options.maxFiles ?? LIMITS.maxFiles, LIMITS.maxFiles) : 1;
|
|
1982
|
+
const maxBytes = Math.min(options.maxFileBytes ?? LIMITS.maxFileBytes, LIMITS.maxFileBytes);
|
|
1983
|
+
const accept = options.accept ?? "";
|
|
1984
|
+
const phoneMode = options.phone === false ? false : options.phone ?? "inline";
|
|
1985
|
+
const showPhone = phoneMode !== false && (options.phoneOnMobile || !isPhonePage());
|
|
1986
|
+
const input = document.createElement("input");
|
|
1987
|
+
input.type = "file";
|
|
1988
|
+
input.hidden = true;
|
|
1989
|
+
input.multiple = multiple;
|
|
1990
|
+
if (accept) input.accept = accept;
|
|
1991
|
+
if (options.name) input.name = options.name;
|
|
1992
|
+
const host = document.createElement("div");
|
|
1993
|
+
host.setAttribute("data-tokshare-pick-field", "");
|
|
1994
|
+
container.append(host, input);
|
|
1995
|
+
const root = host.attachShadow({ mode: "open" });
|
|
1996
|
+
if ("adoptedStyleSheets" in Document.prototype && "replaceSync" in CSSStyleSheet.prototype) {
|
|
1997
|
+
const sheet = new CSSStyleSheet();
|
|
1998
|
+
sheet.replaceSync(FIELD_STYLES);
|
|
1999
|
+
root.adoptedStyleSheets = [sheet];
|
|
2000
|
+
} else {
|
|
2001
|
+
const style = document.createElement("style");
|
|
2002
|
+
style.textContent = FIELD_STYLES;
|
|
2003
|
+
root.append(style);
|
|
2004
|
+
}
|
|
2005
|
+
const hint = [
|
|
2006
|
+
accept ? t("hintTypes", { types: acceptLabel(accept), size: formatBytes(maxBytes, locale) }) : t("hintAny", { size: formatBytes(maxBytes, locale) }),
|
|
2007
|
+
multiple ? t("hintCount", { count: maxFiles }) : ""
|
|
2008
|
+
].filter(Boolean).join(" \xB7 ");
|
|
2009
|
+
const wrap = document.createElement("div");
|
|
2010
|
+
wrap.className = "wrap";
|
|
2011
|
+
wrap.dir = locale === "ar" ? "rtl" : "ltr";
|
|
2012
|
+
wrap.lang = locale;
|
|
2013
|
+
wrap.dataset.theme = resolveTheme(options.theme, container);
|
|
2014
|
+
wrap.innerHTML = `
|
|
2015
|
+
<div class="zone" data-state="idle" role="group">
|
|
2016
|
+
<div class="idle">
|
|
2017
|
+
<div class="tile">${ICONS.upload}</div>
|
|
2018
|
+
<p class="title"></p>
|
|
2019
|
+
<p class="hint"></p>
|
|
2020
|
+
<div class="actions">
|
|
2021
|
+
<button type="button" class="primary browse">${ICONS.folder}<span></span></button>
|
|
2022
|
+
<span class="or"></span>
|
|
2023
|
+
<button type="button" class="ghost phone">${ICONS.phone}<span></span></button>
|
|
2024
|
+
</div>
|
|
2025
|
+
</div>
|
|
2026
|
+
<div class="phone-view" hidden>
|
|
2027
|
+
<div class="qr-box"><canvas class="qr" role="img"></canvas><div class="qr-loading"></div></div>
|
|
2028
|
+
<div class="phone-info">
|
|
2029
|
+
<p class="title phone-title"></p>
|
|
2030
|
+
<ol class="steps"><li></li><li></li><li></li></ol>
|
|
2031
|
+
<p class="code-line"></p>
|
|
2032
|
+
<p class="status" role="status" aria-live="polite"><i></i><span></span></p>
|
|
2033
|
+
<div class="phone-actions">
|
|
2034
|
+
<button type="button" class="link back">${ICONS.back}<span></span></button>
|
|
2035
|
+
<button type="button" class="primary small done" hidden></button>
|
|
2036
|
+
</div>
|
|
2037
|
+
</div>
|
|
2038
|
+
<div class="announce-slot"></div>
|
|
2039
|
+
</div>
|
|
2040
|
+
<input type="file" class="native" hidden>
|
|
2041
|
+
</div>
|
|
2042
|
+
<p class="message" role="alert" hidden></p>
|
|
2043
|
+
<div class="list-head" hidden><span class="count"></span><button type="button" class="link clear"></button></div>
|
|
2044
|
+
<ul class="list"></ul>`;
|
|
2045
|
+
root.append(wrap);
|
|
2046
|
+
const $ = (selector) => wrap.querySelector(selector);
|
|
2047
|
+
const zone = $(".zone");
|
|
2048
|
+
const native = $(".native");
|
|
2049
|
+
native.multiple = multiple;
|
|
2050
|
+
if (accept) native.accept = accept;
|
|
2051
|
+
$(".idle .title").textContent = options.label ?? t(multiple ? "dropTitle" : "dropTitleOne");
|
|
2052
|
+
$(".hint").textContent = hint;
|
|
2053
|
+
$(".browse span").textContent = t("browse");
|
|
2054
|
+
$(".or").textContent = t("or");
|
|
2055
|
+
$(".phone span").textContent = t("usePhone");
|
|
2056
|
+
$(".phone-title").textContent = t("phoneTitle");
|
|
2057
|
+
const steps = wrap.querySelectorAll(".steps li");
|
|
2058
|
+
["phoneStep1", "phoneStep2", "phoneStep3"].forEach((key, index) => {
|
|
2059
|
+
steps[index].textContent = t(key);
|
|
2060
|
+
});
|
|
2061
|
+
$(".back span").textContent = t("back");
|
|
2062
|
+
$(".done").textContent = t("doneWithPhone");
|
|
2063
|
+
$(".clear").textContent = t("clearAll");
|
|
2064
|
+
if (!showPhone) {
|
|
2065
|
+
$(".phone").hidden = true;
|
|
2066
|
+
$(".or").hidden = true;
|
|
2067
|
+
}
|
|
2068
|
+
const promo = announcement(options.announce, t);
|
|
2069
|
+
if (promo) $(".announce-slot").append(promo);
|
|
2070
|
+
else $(".announce-slot").remove();
|
|
2071
|
+
const items = [];
|
|
2072
|
+
const handlers = /* @__PURE__ */ new Set();
|
|
2073
|
+
let picker = null;
|
|
2074
|
+
let messageTimer;
|
|
2075
|
+
const files = () => items.filter((item) => item.file && !item.failed).map((item) => item.file);
|
|
2076
|
+
const say = (text) => {
|
|
2077
|
+
const message = $(".message");
|
|
2078
|
+
message.textContent = text;
|
|
2079
|
+
message.hidden = !text;
|
|
2080
|
+
clearTimeout(messageTimer);
|
|
2081
|
+
if (text) messageTimer = setTimeout(() => {
|
|
2082
|
+
message.hidden = true;
|
|
2083
|
+
}, 6e3);
|
|
2084
|
+
};
|
|
2085
|
+
const sync = () => {
|
|
2086
|
+
const transfer = new DataTransfer();
|
|
2087
|
+
for (const file of files()) transfer.items.add(file);
|
|
2088
|
+
input.files = transfer.files;
|
|
2089
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
2090
|
+
input.dispatchEvent(new Event("change", { bubbles: true }));
|
|
2091
|
+
for (const handler of handlers) handler(files());
|
|
2092
|
+
};
|
|
2093
|
+
const renderList = () => {
|
|
2094
|
+
const list = $(".list");
|
|
2095
|
+
const shown = items.length;
|
|
2096
|
+
$(".list-head").hidden = shown < 2;
|
|
2097
|
+
$(".count").textContent = t("fileCount", { count: shown });
|
|
2098
|
+
for (const item of items) {
|
|
2099
|
+
if (!item.element) {
|
|
2100
|
+
item.element = document.createElement("li");
|
|
2101
|
+
list.append(item.element);
|
|
2102
|
+
}
|
|
2103
|
+
renderItem(item);
|
|
2104
|
+
}
|
|
2105
|
+
};
|
|
2106
|
+
const renderItem = (item) => {
|
|
2107
|
+
const row = item.element;
|
|
2108
|
+
const extension = (item.name.split(".").pop() ?? "").slice(0, 4).toUpperCase();
|
|
2109
|
+
const pending = !item.file && !item.failed;
|
|
2110
|
+
row.className = `item${pending ? " pending" : ""}${item.failed ? " failed" : ""}`;
|
|
2111
|
+
row.replaceChildren();
|
|
2112
|
+
const thumb = document.createElement("div");
|
|
2113
|
+
thumb.className = "thumb";
|
|
2114
|
+
if (item.url) {
|
|
2115
|
+
const image = document.createElement("img");
|
|
2116
|
+
image.alt = "";
|
|
2117
|
+
image.src = item.url;
|
|
2118
|
+
image.addEventListener("error", () => {
|
|
2119
|
+
image.remove();
|
|
2120
|
+
thumb.textContent = extension;
|
|
2121
|
+
});
|
|
2122
|
+
thumb.append(image);
|
|
2123
|
+
} else thumb.textContent = extension || "FILE";
|
|
2124
|
+
const body = document.createElement("div");
|
|
2125
|
+
body.className = "body";
|
|
2126
|
+
const name = document.createElement("span");
|
|
2127
|
+
name.className = "name";
|
|
2128
|
+
name.textContent = item.name;
|
|
2129
|
+
const meta = document.createElement("span");
|
|
2130
|
+
meta.className = "meta";
|
|
2131
|
+
const state = item.failed ? t("failed") : pending ? t(item.phase === "download" ? "receiving" : "sending", { percent: item.percent }) : "";
|
|
2132
|
+
meta.textContent = [formatBytes(item.size, locale), item.source === "phone" ? t("sourcePhone") : t("sourceDevice"), state].filter(Boolean).join(" \xB7 ");
|
|
2133
|
+
body.append(name, meta);
|
|
2134
|
+
if (pending) {
|
|
2135
|
+
const bar = document.createElement("span");
|
|
2136
|
+
bar.className = "bar";
|
|
2137
|
+
const fill = document.createElement("i");
|
|
2138
|
+
fill.style.width = `${item.percent}%`;
|
|
2139
|
+
bar.append(fill);
|
|
2140
|
+
body.append(bar);
|
|
2141
|
+
}
|
|
2142
|
+
const remove = document.createElement("button");
|
|
2143
|
+
remove.type = "button";
|
|
2144
|
+
remove.className = "remove";
|
|
2145
|
+
remove.innerHTML = ICONS.close;
|
|
2146
|
+
remove.setAttribute("aria-label", t("remove", { name: item.name }));
|
|
2147
|
+
remove.hidden = pending;
|
|
2148
|
+
remove.addEventListener("click", () => removeItem(item));
|
|
2149
|
+
row.append(thumb, body, remove);
|
|
2150
|
+
};
|
|
2151
|
+
const removeItem = (item) => {
|
|
2152
|
+
const index = items.indexOf(item);
|
|
2153
|
+
if (index < 0) return;
|
|
2154
|
+
items.splice(index, 1);
|
|
2155
|
+
if (item.url) URL.revokeObjectURL(item.url);
|
|
2156
|
+
item.element?.remove();
|
|
2157
|
+
renderList();
|
|
2158
|
+
sync();
|
|
2159
|
+
};
|
|
2160
|
+
const makeItem = (file, source) => ({
|
|
2161
|
+
key: Math.random().toString(36).slice(2),
|
|
2162
|
+
file,
|
|
2163
|
+
name: file.name,
|
|
2164
|
+
size: file.size,
|
|
2165
|
+
source,
|
|
2166
|
+
percent: 100,
|
|
2167
|
+
...file.type.startsWith("image/") ? { url: URL.createObjectURL(file) } : {}
|
|
2168
|
+
});
|
|
2169
|
+
const addFiles = (incoming, source) => {
|
|
2170
|
+
const problems = [];
|
|
2171
|
+
if (!multiple && incoming.length) {
|
|
2172
|
+
for (const item of [...items]) removeItem(item);
|
|
2173
|
+
incoming = incoming.slice(0, 1);
|
|
2174
|
+
}
|
|
2175
|
+
for (const file of incoming) {
|
|
2176
|
+
if (items.filter((item) => !item.failed).length >= maxFiles) {
|
|
2177
|
+
problems.push(t("tooMany", { count: maxFiles }));
|
|
2178
|
+
break;
|
|
2179
|
+
}
|
|
2180
|
+
if (file.size > maxBytes) {
|
|
2181
|
+
problems.push(t("tooLarge", { name: file.name, size: formatBytes(maxBytes, locale) }));
|
|
2182
|
+
continue;
|
|
2183
|
+
}
|
|
2184
|
+
if (!matchesAccept(accept, file.name, file.type)) {
|
|
2185
|
+
problems.push(t("wrongType", { name: file.name }));
|
|
2186
|
+
continue;
|
|
2187
|
+
}
|
|
2188
|
+
items.push(makeItem(file, source));
|
|
2189
|
+
}
|
|
2190
|
+
say(problems.join(" "));
|
|
2191
|
+
renderList();
|
|
2192
|
+
sync();
|
|
2193
|
+
};
|
|
2194
|
+
$(".browse").addEventListener("click", () => native.click());
|
|
2195
|
+
native.addEventListener("change", () => {
|
|
2196
|
+
addFiles(Array.from(native.files ?? []), "device");
|
|
2197
|
+
native.value = "";
|
|
2198
|
+
});
|
|
2199
|
+
let depth = 0;
|
|
2200
|
+
zone.addEventListener("dragenter", (event) => {
|
|
2201
|
+
event.preventDefault();
|
|
2202
|
+
depth++;
|
|
2203
|
+
if (zone.dataset.state === "idle") zone.dataset.drag = "true";
|
|
2204
|
+
});
|
|
2205
|
+
zone.addEventListener("dragover", (event) => {
|
|
2206
|
+
event.preventDefault();
|
|
2207
|
+
if (event.dataTransfer) event.dataTransfer.dropEffect = "copy";
|
|
2208
|
+
});
|
|
2209
|
+
zone.addEventListener("dragleave", () => {
|
|
2210
|
+
if (--depth <= 0) {
|
|
2211
|
+
depth = 0;
|
|
2212
|
+
delete zone.dataset.drag;
|
|
2213
|
+
}
|
|
2214
|
+
});
|
|
2215
|
+
zone.addEventListener("drop", (event) => {
|
|
2216
|
+
event.preventDefault();
|
|
2217
|
+
depth = 0;
|
|
2218
|
+
delete zone.dataset.drag;
|
|
2219
|
+
if (zone.dataset.state === "idle") addFiles(Array.from(event.dataTransfer?.files ?? []), "device");
|
|
2220
|
+
});
|
|
2221
|
+
$(".clear").addEventListener("click", () => {
|
|
2222
|
+
for (const item of [...items]) removeItem(item);
|
|
2223
|
+
});
|
|
2224
|
+
const setStatus = (text, live = false) => {
|
|
2225
|
+
$(".status span").textContent = text;
|
|
2226
|
+
$(".status").classList.toggle("live", live);
|
|
2227
|
+
};
|
|
2228
|
+
const showIdle = () => {
|
|
2229
|
+
zone.dataset.state = "idle";
|
|
2230
|
+
$(".idle").hidden = false;
|
|
2231
|
+
$(".phone-view").hidden = true;
|
|
2232
|
+
$(".phone").focus();
|
|
2233
|
+
};
|
|
2234
|
+
const pendingByRelay = /* @__PURE__ */ new Map();
|
|
2235
|
+
const openInline = () => {
|
|
2236
|
+
zone.dataset.state = "phone";
|
|
2237
|
+
$(".idle").hidden = true;
|
|
2238
|
+
$(".phone-view").hidden = false;
|
|
2239
|
+
$(".qr-box").classList.add("loading");
|
|
2240
|
+
$(".done").hidden = true;
|
|
2241
|
+
$(".code-line").textContent = "";
|
|
2242
|
+
setStatus(t("loading"));
|
|
2243
|
+
const room = Math.max(1, maxFiles - files().length);
|
|
2244
|
+
const current = open({ ...options, ui: false, multiple, maxFiles: multiple ? room : 1, maxFileBytes: maxBytes, accept });
|
|
2245
|
+
picker = current;
|
|
2246
|
+
current.on("ready", ({ claimUrl, code }) => {
|
|
2247
|
+
drawQr($(".qr"), claimUrl, 168);
|
|
2248
|
+
$(".qr").setAttribute("aria-label", t("phoneTitle"));
|
|
2249
|
+
$(".qr-box").classList.remove("loading", "dim");
|
|
2250
|
+
const line = $(".code-line");
|
|
2251
|
+
const strong = document.createElement("b");
|
|
2252
|
+
strong.textContent = formatCode(code);
|
|
2253
|
+
line.replaceChildren(document.createTextNode(`${t("phoneCode", { host: new URL(claimUrl).host })} `), strong);
|
|
2254
|
+
setStatus(t("waiting"));
|
|
2255
|
+
});
|
|
2256
|
+
let phoneLabel = "";
|
|
2257
|
+
current.on("phone", ({ phone, needsApproval }) => {
|
|
2258
|
+
phoneLabel = phone.label;
|
|
2259
|
+
$(".qr-box").classList.add("dim");
|
|
2260
|
+
setStatus(t("connected", { label: phone.label }), true);
|
|
2261
|
+
if (needsApproval) current.approve();
|
|
2262
|
+
});
|
|
2263
|
+
current.on("direct", ({ connected }) => {
|
|
2264
|
+
if (phoneLabel) setStatus(t(connected ? "connectedDirect" : "connected", { label: phoneLabel }), true);
|
|
2265
|
+
});
|
|
2266
|
+
current.on("phone_left", () => setStatus(t("phoneLeft")));
|
|
2267
|
+
current.on("file_started", (meta) => {
|
|
2268
|
+
const item = { key: meta.id, file: null, name: meta.name, size: meta.size, source: "phone", percent: 0 };
|
|
2269
|
+
pendingByRelay.set(meta.id, item);
|
|
2270
|
+
items.push(item);
|
|
2271
|
+
renderList();
|
|
2272
|
+
});
|
|
2273
|
+
current.on("progress", ({ id, sent, total, phase }) => {
|
|
2274
|
+
const item = pendingByRelay.get(id);
|
|
2275
|
+
if (!item) return;
|
|
2276
|
+
const share = total ? sent / total : 0;
|
|
2277
|
+
item.phase = phase;
|
|
2278
|
+
item.percent = Math.min(99, Math.floor(phase === "upload" ? share * 90 : 90 + share * 10));
|
|
2279
|
+
renderItem(item);
|
|
2280
|
+
});
|
|
2281
|
+
current.on("received", ({ id, file }) => {
|
|
2282
|
+
const pending = pendingByRelay.get(id);
|
|
2283
|
+
pendingByRelay.delete(id);
|
|
2284
|
+
const ready = makeItem(file, "phone");
|
|
2285
|
+
if (pending) {
|
|
2286
|
+
Object.assign(pending, { file, name: file.name, size: file.size, percent: 100, ...ready.url ? { url: ready.url } : {} });
|
|
2287
|
+
if (!multiple) for (const other of items.filter((item) => item !== pending)) removeItem(other);
|
|
2288
|
+
renderItem(pending);
|
|
2289
|
+
} else items.push(ready);
|
|
2290
|
+
renderList();
|
|
2291
|
+
sync();
|
|
2292
|
+
$(".done").hidden = false;
|
|
2293
|
+
});
|
|
2294
|
+
current.on("file_failed", ({ id }) => {
|
|
2295
|
+
const item = pendingByRelay.get(id);
|
|
2296
|
+
if (item) {
|
|
2297
|
+
item.failed = true;
|
|
2298
|
+
renderItem(item);
|
|
2299
|
+
}
|
|
2300
|
+
});
|
|
2301
|
+
current.on("error", (error) => setStatus(t("error", { message: error.message })));
|
|
2302
|
+
current.on("close", (reason) => {
|
|
2303
|
+
for (const item of pendingByRelay.values()) {
|
|
2304
|
+
item.failed = true;
|
|
2305
|
+
renderItem(item);
|
|
2306
|
+
}
|
|
2307
|
+
pendingByRelay.clear();
|
|
2308
|
+
if (picker === current) picker = null;
|
|
2309
|
+
if (reason === "finished" || reason === "canceled") showIdle();
|
|
2310
|
+
else {
|
|
2311
|
+
$(".qr-box").classList.add("dim");
|
|
2312
|
+
setStatus(t("expired"));
|
|
2313
|
+
}
|
|
2314
|
+
});
|
|
2315
|
+
};
|
|
2316
|
+
const closeInline = () => {
|
|
2317
|
+
if (picker) picker.finish();
|
|
2318
|
+
else showIdle();
|
|
2319
|
+
};
|
|
2320
|
+
$(".phone").addEventListener("click", () => {
|
|
2321
|
+
if (phoneMode === "modal") {
|
|
2322
|
+
const room = Math.max(1, maxFiles - files().length);
|
|
2323
|
+
open({ ...options, ui: true, multiple, maxFiles: multiple ? room : 1, maxFileBytes: maxBytes, accept }).done.then((received) => addFiles(received, "phone"));
|
|
2324
|
+
} else openInline();
|
|
2325
|
+
});
|
|
2326
|
+
$(".back").addEventListener("click", closeInline);
|
|
2327
|
+
$(".done").addEventListener("click", closeInline);
|
|
2328
|
+
wrap.addEventListener("keydown", (event) => {
|
|
2329
|
+
if (event.key === "Escape" && zone.dataset.state === "phone") closeInline();
|
|
2330
|
+
});
|
|
2331
|
+
return {
|
|
2332
|
+
get files() {
|
|
2333
|
+
return files();
|
|
2334
|
+
},
|
|
2335
|
+
input,
|
|
2336
|
+
on(_event, handler) {
|
|
2337
|
+
handlers.add(handler);
|
|
2338
|
+
return () => handlers.delete(handler);
|
|
2339
|
+
},
|
|
2340
|
+
remove(file) {
|
|
2341
|
+
const item = items.find((candidate) => candidate.file === file);
|
|
2342
|
+
if (item) removeItem(item);
|
|
2343
|
+
},
|
|
2344
|
+
clear() {
|
|
2345
|
+
for (const item of [...items]) removeItem(item);
|
|
2346
|
+
},
|
|
2347
|
+
destroy() {
|
|
2348
|
+
picker?.cancel();
|
|
2349
|
+
for (const item of items) if (item.url) URL.revokeObjectURL(item.url);
|
|
2350
|
+
host.remove();
|
|
2351
|
+
input.remove();
|
|
2352
|
+
}
|
|
2353
|
+
};
|
|
2354
|
+
}
|
|
2355
|
+
function defineFieldElement(defaults = {}, tag = "tokshare-pick-field") {
|
|
2356
|
+
if (typeof customElements === "undefined" || customElements.get(tag)) return;
|
|
2357
|
+
customElements.define(tag, class extends HTMLElement {
|
|
2358
|
+
constructor() {
|
|
2359
|
+
super(...arguments);
|
|
2360
|
+
__publicField(this, "controller", null);
|
|
2361
|
+
}
|
|
2362
|
+
connectedCallback() {
|
|
2363
|
+
if (this.controller) return;
|
|
2364
|
+
const attribute = (name) => this.getAttribute(name) ?? void 0;
|
|
2365
|
+
const phone = attribute("phone");
|
|
2366
|
+
const maxFiles = Number(attribute("max-files"));
|
|
2367
|
+
const resize = Number(attribute("resize"));
|
|
2368
|
+
const maxFileBytes = parseSize(attribute("max-size"));
|
|
2369
|
+
this.controller = mountField(this, {
|
|
2370
|
+
...defaults,
|
|
2371
|
+
key: attribute("key") ?? defaults.key ?? "",
|
|
2372
|
+
...attribute("relay") ?? defaults.relay ? { relay: attribute("relay") ?? defaults.relay } : {},
|
|
2373
|
+
...attribute("name") ? { name: attribute("name") } : {},
|
|
2374
|
+
...attribute("accept") ? { accept: attribute("accept") } : {},
|
|
2375
|
+
multiple: this.hasAttribute("multiple"),
|
|
2376
|
+
...maxFiles > 0 ? { maxFiles } : {},
|
|
2377
|
+
...maxFileBytes ? { maxFileBytes } : {},
|
|
2378
|
+
...resize > 0 ? { resizeImages: { maxDimension: resize } } : {},
|
|
2379
|
+
...phone === "off" ? { phone: false } : phone === "modal" ? { phone: "modal" } : {},
|
|
2380
|
+
...attribute("locale") ? { locale: attribute("locale") } : {},
|
|
2381
|
+
...attribute("theme") ? { theme: attribute("theme") } : {},
|
|
2382
|
+
...attribute("label") ? { label: attribute("label") } : {},
|
|
2383
|
+
...attribute("direct") === "off" ? { direct: false } : {},
|
|
2384
|
+
...attribute("announce") === "off" ? { announce: false } : {}
|
|
2385
|
+
});
|
|
2386
|
+
this.controller.on("change", (files) => this.dispatchEvent(new CustomEvent("files", { detail: files, bubbles: true })));
|
|
2387
|
+
}
|
|
2388
|
+
disconnectedCallback() {
|
|
2389
|
+
this.controller?.destroy();
|
|
2390
|
+
this.controller = null;
|
|
2391
|
+
}
|
|
2392
|
+
get files() {
|
|
2393
|
+
return this.controller?.files ?? [];
|
|
2394
|
+
}
|
|
2395
|
+
clear() {
|
|
2396
|
+
this.controller?.clear();
|
|
2397
|
+
}
|
|
2398
|
+
});
|
|
2399
|
+
}
|
|
2400
|
+
|
|
2401
|
+
// src/index.ts
|
|
2402
|
+
var TokSharePick = { pick, open, attach, mountField, defineFieldElement };
|
|
2403
|
+
export {
|
|
2404
|
+
DEFAULT_RELAY,
|
|
2405
|
+
PickError,
|
|
2406
|
+
SDK_VERSION,
|
|
2407
|
+
TokSharePick,
|
|
2408
|
+
attach,
|
|
2409
|
+
defineFieldElement,
|
|
2410
|
+
mountField,
|
|
2411
|
+
open,
|
|
2412
|
+
parseSize,
|
|
2413
|
+
pick
|
|
2414
|
+
};
|
|
2415
|
+
//# sourceMappingURL=index.js.map
|