From 7945707b2e0a71fa63aac3693eb427770d2b92cc Mon Sep 17 00:00:00 2001 From: nidhal-labidi Date: Mon, 17 Feb 2025 22:52:14 +0100 Subject: [PATCH 1/4] feat: encrypt signaling data, fix: update all the demos and where-are-you.at Signed-off-by: nidhal-labidi --- flottform/forms/src/default-component.ts | 12 +- flottform/forms/src/encryption.ts | 106 + .../forms/src/flottform-channel-client.ts | 48 +- flottform/forms/src/flottform-channel-host.ts | 59 +- .../forms/src/flottform-file-input-client.ts | 3 + .../forms/src/flottform-file-input-host.ts | 6 +- .../forms/src/flottform-text-input-client.ts | 3 + .../forms/src/flottform-text-input-host.ts | 6 +- flottform/forms/src/internal.ts | 8 +- flottform/forms/src/types.ts | 6 +- flottform/server/src/database.ts | 20 +- .../chrome-extension/src/routes/+page.svelte | 24 +- .../static/scripts/flottform-bundle.js | 2106 +++++++++-------- .../static/scripts/flottform-bundle.js.map | 2 +- servers/demo/src/api.ts | 66 +- .../[endpointId]/+page.svelte | 5 +- .../[endpointId]/+page.svelte | 4 +- .../[endpointId]/+page.svelte | 5 +- .../[endpointId]/+page.svelte | 5 +- .../[endpointId]/+page.svelte | 5 +- .../[endpointId]/+page.svelte | 4 +- .../[endpointId]/+page.svelte | 5 +- .../[endpointId]/+page.svelte | 5 +- .../signaling-server/src/lib/validations.ts | 4 + .../flottform/[endpointId]/client/+server.ts | 5 +- .../flottform/[endpointId]/host/+server.ts | 5 +- .../src/routes/flottform/create/+server.ts | 11 +- .../src/routes/now/[endpointId]/+page.svelte | 4 +- 28 files changed, 1477 insertions(+), 1065 deletions(-) create mode 100644 flottform/forms/src/encryption.ts diff --git a/flottform/forms/src/default-component.ts b/flottform/forms/src/default-component.ts index c772b8c..c03719f 100644 --- a/flottform/forms/src/default-component.ts +++ b/flottform/forms/src/default-component.ts @@ -92,7 +92,11 @@ export const createDefaultFlottformComponent = ({ onSuccessText }: { flottformApi: string; - createClientUrl: (params: { endpointId: string }) => Promise; + createClientUrl: (params: { + endpointId: string; + encryptionKey: string; + optionalData?: object; + }) => Promise; inputField: HTMLInputElement; id?: string; additionalItemClasses?: string; @@ -147,7 +151,11 @@ export const createDefaultFlottformComponent = ({ onSuccessText }: { flottformApi: string; - createClientUrl: (params: { endpointId: string }) => Promise; + createClientUrl: (params: { + endpointId: string; + encryptionKey: string; + optionalData?: object; + }) => Promise; inputField?: HTMLInputElement | HTMLTextAreaElement; id?: string; additionalItemClasses?: string; diff --git a/flottform/forms/src/encryption.ts b/flottform/forms/src/encryption.ts new file mode 100644 index 0000000..e7e2916 --- /dev/null +++ b/flottform/forms/src/encryption.ts @@ -0,0 +1,106 @@ +export async function generateKey(): Promise { + return await crypto.subtle.generateKey( + { + name: 'AES-GCM', + length: 256 + }, + true, // extractable + ['encrypt', 'decrypt'] + ); +} + +export async function cryptoKeyToEncryptionKey(key: CryptoKey) { + // CryptoKey --> Exported bytes of the cryptoKey (i.e. the encryption key) + return (await crypto.subtle.exportKey('jwk', key)).k; +} + +export async function encryptionKeyToCryptoKey(encryptionKey: string) { + // Create a complete JWK object structure + const jwk = { + kty: 'oct', + k: encryptionKey, + alg: 'A256GCM', + ext: true, + key_ops: ['encrypt', 'decrypt'] + }; + + // Import the complete JWK + return await crypto.subtle.importKey( + 'jwk', + jwk, + { + name: 'AES-GCM', + length: 256 + }, + true, // extractable + ['encrypt', 'decrypt'] + ); +} + +export async function encrypt(plaintext: string, cryptoKey: CryptoKey): Promise { + const data = plaintextToTypedArray(plaintext); + const iv = getInitializationVector(); + + const encryptedData = await crypto.subtle.encrypt( + { + name: 'AES-GCM', + iv + }, + cryptoKey, + data + ); + + // Prepend the cyphertext with the initialization vector. + const combinedData = new Uint8Array(iv.length + encryptedData.byteLength); + combinedData.set(iv, 0); + combinedData.set(new Uint8Array(encryptedData), iv.length); + + return typedArrayToBase64(combinedData); +} + +export async function decrypt(ciphertext: string, cryptoKey: CryptoKey) { + const combinedData = base64ToTypedArray(ciphertext); + + // Step 2: Extract IV and ciphertext + const iv = combinedData.slice(0, 12); + const data = combinedData.slice(12); + + const decryptedData = await crypto.subtle.decrypt( + { + name: 'AES-GCM', + iv + }, + cryptoKey, + data + ); + + return typedArrayToPlaintext(new Uint8Array(decryptedData)); +} + +function plaintextToTypedArray(plainText: string): Uint8Array { + // Then encode to Uint8Array + const encoder = new TextEncoder(); + return encoder.encode(plainText); +} + +function getInitializationVector(): Uint8Array { + return crypto.getRandomValues(new Uint8Array(12)); +} + +function typedArrayToBase64(typedArray: Uint8Array): string { + // Uint8Array --> Base64 + return btoa(String.fromCharCode(...new Uint8Array(typedArray))); +} + +function base64ToTypedArray(messageAsBase64: string): Uint8Array { + // Base64 --> Uint8Array + const binaryString = atob(messageAsBase64); + return Uint8Array.from(binaryString, (char) => char.charCodeAt(0)); +} + +function typedArrayToPlaintext(typedArray: Uint8Array, isOriginalDataJson = true) { + // Uint8Array --> data (string, number, object, array..) + const decoder = new TextDecoder(); + const plaintext = decoder.decode(typedArray); + return isOriginalDataJson ? JSON.parse(plaintext) : plaintext; +} diff --git a/flottform/forms/src/flottform-channel-client.ts b/flottform/forms/src/flottform-channel-client.ts index f1e1db2..949b96f 100644 --- a/flottform/forms/src/flottform-channel-client.ts +++ b/flottform/forms/src/flottform-channel-client.ts @@ -1,3 +1,4 @@ +import { decrypt, encrypt, encryptionKeyToCryptoKey } from './encryption'; import { ClientState, EventEmitter, @@ -28,6 +29,8 @@ export class FlottformChannelClient extends EventEmitter { private pollTimeForIceInMs: number; private logger: Logger; + private cryptoKey: CryptoKey | null = null; + private encryptionKey: string; private state: ClientState = 'init'; private openPeerConnection: RTCPeerConnection | null = null; private dataChannel: RTCDataChannel | null = null; @@ -38,12 +41,14 @@ export class FlottformChannelClient extends EventEmitter { endpointId, flottformApi, rtcConfiguration, + encryptionKey, pollTimeForIceInMs = POLL_TIME_IN_MS, logger = console }: { endpointId: string; flottformApi: string | URL; rtcConfiguration: RTCConfiguration; + encryptionKey: string; pollTimeForIceInMs?: number; logger?: Logger; }) { @@ -51,6 +56,7 @@ export class FlottformChannelClient extends EventEmitter { this.endpointId = endpointId; this.flottformApi = flottformApi; this.rtcConfiguration = rtcConfiguration; + this.encryptionKey = encryptionKey; this.pollTimeForIceInMs = pollTimeForIceInMs; this.logger = logger; } @@ -66,6 +72,9 @@ export class FlottformChannelClient extends EventEmitter { if (this.openPeerConnection) { this.close(); } + // Import cryptoKey from encryptionKey + this.cryptoKey = await encryptionKeyToCryptoKey(this.encryptionKey); + const baseApi = ( this.flottformApi instanceof URL ? this.flottformApi : new URL(this.flottformApi) ) @@ -73,7 +82,7 @@ export class FlottformChannelClient extends EventEmitter { .replace(/\/$/, ''); // For now the fetching can be done outside of these classes and should be passed as an argument. - + /* try { this.rtcConfiguration.iceServers = await this.fetchIceServers(baseApi); } catch (error) { @@ -89,7 +98,12 @@ export class FlottformChannelClient extends EventEmitter { this.changeState('retrieving-info-from-endpoint'); const { hostInfo } = await retrieveEndpointInfo(getEndpointInfoUrl); - await this.openPeerConnection.setRemoteDescription(hostInfo.session); + if (!this.cryptoKey) { + throw new Error('CryptoKey is null! Decryption is not possible!!'); + } + const hostSession: RTCSessionDescriptionInit = await decrypt(hostInfo.session, this.cryptoKey); + + await this.openPeerConnection.setRemoteDescription(hostSession); const session = await this.openPeerConnection.createAnswer(); await this.openPeerConnection.setLocalDescription(session); @@ -179,6 +193,7 @@ export class FlottformChannelClient extends EventEmitter { this.logger.error(`onicecandidateerror - ${this.openPeerConnection!.connectionState}`, e); }; }; + private setUpConnectionStateGathering = (getEndpointInfoUrl: string) => { if (this.openPeerConnection === null) { this.changeState( @@ -216,12 +231,14 @@ export class FlottformChannelClient extends EventEmitter { } }; }; + private stopPollingForIceCandidates = async () => { if (this.pollForIceTimer) { clearTimeout(this.pollForIceTimer); } this.pollForIceTimer = null; }; + private startPollingForIceCandidates = async (getEndpointInfoUrl: string) => { if (this.pollForIceTimer) { clearTimeout(this.pollForIceTimer); @@ -231,6 +248,7 @@ export class FlottformChannelClient extends EventEmitter { this.pollForIceTimer = setTimeout(this.startPollingForIceCandidates, this.pollTimeForIceInMs); }; + private pollForConnection = async (getEndpointInfoUrl: string) => { if (this.openPeerConnection === null) { this.changeState('error', "openPeerConnection is null. Unable to retrieve Host's details"); @@ -239,10 +257,20 @@ export class FlottformChannelClient extends EventEmitter { this.logger.log('polling for host ice candidates', this.openPeerConnection.iceGatheringState); const { hostInfo } = await retrieveEndpointInfo(getEndpointInfoUrl); - for (const iceCandidate of hostInfo.iceCandidates) { + + if (!this.cryptoKey) { + throw new Error('CryptoKey is null! Decryption is not possible!!'); + } + const hostIceCandidates: RTCIceCandidateInit[] = await decrypt( + hostInfo.iceCandidates, + this.cryptoKey + ); + + for (const iceCandidate of hostIceCandidates) { await this.openPeerConnection.addIceCandidate(iceCandidate); } }; + private putClientInfo = async ( putClientInfoUrl: string, clientKey: string, @@ -250,13 +278,23 @@ export class FlottformChannelClient extends EventEmitter { session: RTCSessionDescriptionInit ) => { this.logger.log('Updating client info with new list of ice candidates'); + if (!this.cryptoKey) { + throw new Error('CryptoKey is null! Encryption is not possible!!'); + } + + const encryptedIceCandidates = await encrypt( + JSON.stringify([...clientIceCandidates]), + this.cryptoKey + ); + const encryptedSession = await encrypt(JSON.stringify(session), this.cryptoKey); + const response = await fetch(putClientInfoUrl, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ clientKey, - iceCandidates: [...clientIceCandidates], - session + iceCandidates: encryptedIceCandidates, + session: encryptedSession }) }); if (!response.ok) { diff --git a/flottform/forms/src/flottform-channel-host.ts b/flottform/forms/src/flottform-channel-host.ts index 997edae..10aadb0 100644 --- a/flottform/forms/src/flottform-channel-host.ts +++ b/flottform/forms/src/flottform-channel-host.ts @@ -7,14 +7,20 @@ import { retrieveEndpointInfo, setIncludes } from './internal'; +import { cryptoKeyToEncryptionKey, decrypt, encrypt, generateKey } from './encryption'; export class FlottformChannelHost extends EventEmitter { private flottformApi: string | URL; - private createClientUrl: (params: { endpointId: string }) => Promise; + private createClientUrl: (params: { + endpointId: string; + encryptionKey: string; + optionalData?: object; + }) => Promise; private rtcConfiguration: RTCConfiguration; private pollTimeForIceInMs: number; private logger: Logger; + private cryptoKey: CryptoKey | null = null; private state: FlottformState | 'disconnected' = 'new'; private channelNumber: number = 0; private openPeerConnection: RTCPeerConnection | null = null; @@ -29,7 +35,11 @@ export class FlottformChannelHost extends EventEmitter { logger }: { flottformApi: string | URL; - createClientUrl: (params: { endpointId: string }) => Promise; + createClientUrl: (params: { + endpointId: string; + encryptionKey: string; + optionalData?: object; + }) => Promise; rtcConfiguration: RTCConfiguration; pollTimeForIceInMs: number; logger: Logger; @@ -56,6 +66,9 @@ export class FlottformChannelHost extends EventEmitter { if (this.openPeerConnection) { this.close(); } + // Generate Encryption/Decryption Key. + this.cryptoKey = await generateKey(); + const baseApi = ( this.flottformApi instanceof URL ? this.flottformApi : new URL(this.flottformApi) ) @@ -89,7 +102,11 @@ export class FlottformChannelHost extends EventEmitter { this.setupHostIceGathering(putHostInfoUrl, hostKey, hostIceCandidates, session); this.setupDataChannelForTransfer(); - const connectLink = await this.createClientUrl({ endpointId }); + const encryptionKey = await cryptoKeyToEncryptionKey(this.cryptoKey); + if (!encryptionKey) { + throw new Error('Encryption Key is undefined!'); + } + const connectLink = await this.createClientUrl({ endpointId, encryptionKey }); this.changeState('waiting-for-client', { qrCode: await toDataURL(connectLink), link: connectLink, @@ -214,13 +231,18 @@ export class FlottformChannelHost extends EventEmitter { }; private createEndpoint = async (baseApi: string, session: RTCSessionDescriptionInit) => { + if (!this.cryptoKey) { + throw new Error('CryptoKey is null! Encryption is not possible!!'); + } + const encryptedSession = await encrypt(JSON.stringify(session), this.cryptoKey); + const response = await fetch(`${baseApi}/create`, { method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json' }, - body: JSON.stringify({ session }) + body: JSON.stringify({ session: encryptedSession }) }); return response.json(); @@ -254,13 +276,24 @@ export class FlottformChannelHost extends EventEmitter { this.logger.log('polling for client ice candidates', this.openPeerConnection.iceGatheringState); const { clientInfo } = await retrieveEndpointInfo(getEndpointInfoUrl); + if (!this.cryptoKey) { + throw new Error('CryptoKey is null! Decryption is not possible!!'); + } + let decryptedSession; + let decryptedIceCandidates: RTCIceCandidateInit[] = []; + + if (clientInfo) { + decryptedSession = await decrypt(clientInfo.session, this.cryptoKey); + decryptedIceCandidates = await decrypt(clientInfo.iceCandidates, this.cryptoKey); + } + if (clientInfo && this.state === 'waiting-for-client') { this.logger.log('Found a client that wants to connect!'); this.changeState('waiting-for-ice'); - await this.openPeerConnection.setRemoteDescription(clientInfo.session); + await this.openPeerConnection.setRemoteDescription(decryptedSession); } - for (const iceCandidate of clientInfo?.iceCandidates ?? []) { + for (const iceCandidate of decryptedIceCandidates ?? []) { await this.openPeerConnection.addIceCandidate(iceCandidate); } }; @@ -305,13 +338,23 @@ export class FlottformChannelHost extends EventEmitter { ) => { try { this.logger.log('Updating host info with new list of ice candidates'); + if (!this.cryptoKey) { + throw new Error('CryptoKey is null! Encryption is not possible!!'); + } + + const encryptedIceCandidates = await encrypt( + JSON.stringify([...hostIceCandidates]), + this.cryptoKey + ); + const encryptedSession = await encrypt(JSON.stringify(session), this.cryptoKey); + const response = await fetch(putHostInfoUrl, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ hostKey, - iceCandidates: [...hostIceCandidates], - session + iceCandidates: encryptedIceCandidates, + session: encryptedSession }) }); if (!response.ok) { diff --git a/flottform/forms/src/flottform-file-input-client.ts b/flottform/forms/src/flottform-file-input-client.ts index 7151e81..a99059f 100644 --- a/flottform/forms/src/flottform-file-input-client.ts +++ b/flottform/forms/src/flottform-file-input-client.ts @@ -32,6 +32,7 @@ export class FlottformFileInputClient extends EventEmitter { endpointId, fileInput, flottformApi, + encryptionKey, rtcConfiguration = DEFAULT_WEBRTC_CONFIG, pollTimeForIceInMs = POLL_TIME_IN_MS, logger = console @@ -39,6 +40,7 @@ export class FlottformFileInputClient extends EventEmitter { endpointId: string; fileInput: HTMLInputElement; flottformApi: string; + encryptionKey: string; rtcConfiguration?: RTCConfiguration; pollTimeForIceInMs?: number; logger?: Logger; @@ -48,6 +50,7 @@ export class FlottformFileInputClient extends EventEmitter { endpointId, flottformApi, rtcConfiguration, + encryptionKey, pollTimeForIceInMs, logger }); diff --git a/flottform/forms/src/flottform-file-input-host.ts b/flottform/forms/src/flottform-file-input-host.ts index 42f838b..9a3b292 100644 --- a/flottform/forms/src/flottform-file-input-host.ts +++ b/flottform/forms/src/flottform-file-input-host.ts @@ -45,7 +45,11 @@ export class FlottformFileInputHost extends BaseInputHost { logger = console }: { flottformApi: string | URL; - createClientUrl: (params: { endpointId: string }) => Promise; + createClientUrl: (params: { + endpointId: string; + encryptionKey: string; + optionalData?: object; + }) => Promise; inputField?: HTMLInputElement; rtcConfiguration?: RTCConfiguration; pollTimeForIceInMs?: number; diff --git a/flottform/forms/src/flottform-text-input-client.ts b/flottform/forms/src/flottform-text-input-client.ts index c0e11ce..4a64b84 100644 --- a/flottform/forms/src/flottform-text-input-client.ts +++ b/flottform/forms/src/flottform-text-input-client.ts @@ -17,6 +17,7 @@ export class FlottformTextInputClient extends EventEmitter { constructor({ endpointId, flottformApi, + encryptionKey, rtcConfiguration = DEFAULT_WEBRTC_CONFIG, pollTimeForIceInMs = POLL_TIME_IN_MS, logger = console @@ -24,6 +25,7 @@ export class FlottformTextInputClient extends EventEmitter { endpointId: string; flottformApi: string; rtcConfiguration?: RTCConfiguration; + encryptionKey: string; pollTimeForIceInMs?: number; logger?: Logger; }) { @@ -32,6 +34,7 @@ export class FlottformTextInputClient extends EventEmitter { endpointId, flottformApi, rtcConfiguration, + encryptionKey, pollTimeForIceInMs, logger }); diff --git a/flottform/forms/src/flottform-text-input-host.ts b/flottform/forms/src/flottform-text-input-host.ts index e2d342d..6373ab2 100644 --- a/flottform/forms/src/flottform-text-input-host.ts +++ b/flottform/forms/src/flottform-text-input-host.ts @@ -30,7 +30,11 @@ export class FlottformTextInputHost extends BaseInputHost { logger = console }: { flottformApi: string | URL; - createClientUrl: (params: { endpointId: string }) => Promise; + createClientUrl: (params: { + endpointId: string; + encryptionKey: string; + optionalData?: object; + }) => Promise; inputField?: HTMLInputElement | HTMLTextAreaElement; rtcConfiguration?: RTCConfiguration; pollTimeForIceInMs?: number; diff --git a/flottform/forms/src/internal.ts b/flottform/forms/src/internal.ts index 2658b9c..2ad42cf 100644 --- a/flottform/forms/src/internal.ts +++ b/flottform/forms/src/internal.ts @@ -7,13 +7,13 @@ type EndpointInfo = { hostKey: HostKey; endpointId: EndpointId; hostInfo: { - session: RTCSessionDescriptionInit; - iceCandidates: RTCIceCandidateInit[]; + session: string; + iceCandidates: string; }; clientKey?: ClientKey; clientInfo?: { - session: RTCSessionDescriptionInit; - iceCandidates: RTCIceCandidateInit[]; + session: string; + iceCandidates: string; }; }; diff --git a/flottform/forms/src/types.ts b/flottform/forms/src/types.ts index 95bb10c..6057abc 100644 --- a/flottform/forms/src/types.ts +++ b/flottform/forms/src/types.ts @@ -1,6 +1,10 @@ export interface FlottformCreateItemParams { flottformApi: string; - createClientUrl: (params: { endpointId: string }) => Promise; + createClientUrl: (params: { + endpointId: string; + encryptionKey: string; + optionalData?: object; + }) => Promise; id?: string; additionalItemClasses?: string; label?: string; diff --git a/flottform/server/src/database.ts b/flottform/server/src/database.ts index 271a410..2510228 100644 --- a/flottform/server/src/database.ts +++ b/flottform/server/src/database.ts @@ -5,13 +5,13 @@ type EndpointInfo = { hostKey: HostKey; endpointId: EndpointId; hostInfo: { - session: RTCSessionDescriptionInit; - iceCandidates: RTCIceCandidateInit[]; + session: string; + iceCandidates: string; }; clientKey?: ClientKey; clientInfo?: { - session: RTCSessionDescriptionInit; - iceCandidates: RTCIceCandidateInit[]; + session: string; + iceCandidates: string; }; }; type SafeEndpointInfo = Omit; @@ -28,13 +28,13 @@ class FlottformDatabase { constructor() {} - async createEndpoint({ session }: { session: RTCSessionDescriptionInit }): Promise { + async createEndpoint({ session }: { session: string }): Promise { const entry = { hostKey: createRandomHostKey(), endpointId: createRandomEndpointId(), hostInfo: { session, - iceCandidates: [] + iceCandidates: '' } }; this.map.set(entry.endpointId, entry); @@ -59,8 +59,8 @@ class FlottformDatabase { }: { endpointId: EndpointId; hostKey: HostKey; - session: RTCSessionDescriptionInit; - iceCandidates: RTCIceCandidateInit[]; + session: string; + iceCandidates: string; }): Promise { const existingSession = this.map.get(endpointId); if (!existingSession) { @@ -89,8 +89,8 @@ class FlottformDatabase { }: { endpointId: EndpointId; clientKey: ClientKey; - session: RTCSessionDescriptionInit; - iceCandidates: RTCIceCandidateInit[]; + session: string; + iceCandidates: string; }): Promise> { const existingSession = this.map.get(endpointId); if (!existingSession) { diff --git a/servers/chrome-extension/src/routes/+page.svelte b/servers/chrome-extension/src/routes/+page.svelte index ab85462..c90b4b8 100644 --- a/servers/chrome-extension/src/routes/+page.svelte +++ b/servers/chrome-extension/src/routes/+page.svelte @@ -254,8 +254,16 @@ // Instantiate the FlottformTextInputHost with the provided inputId let flottformTextInputHost = new FlottformTextInputHost({ - createClientUrl: async ({ endpointId }: { endpointId: string }) => - `${extensionClientUrlBase}/${endpointId}/#${encodeURIComponent(JSON.stringify(data))}`, + createClientUrl: async ({ + endpointId, + encryptionKey, + optionalData = data + }: { + endpointId: string; + encryptionKey: string; + optionalData?: object; + }) => + `${extensionClientUrlBase}/${endpointId}/#${encodeURIComponent(JSON.stringify({ encKey: encryptionKey, ...optionalData }))}`, flottformApi: signalingServerUrlBase }); @@ -286,8 +294,16 @@ // Instantiate the FlottformFileInputHost with the provided inputId let flottformFileInputHost = new FlottformFileInputHost({ - createClientUrl: async ({ endpointId }: { endpointId: string }) => - `${extensionClientUrlBase}/${endpointId}/#${encodeURIComponent(JSON.stringify(data))}`, + createClientUrl: async ({ + endpointId, + encryptionKey, + optionalData = data + }: { + endpointId: string; + encryptionKey: string; + optionalData?: object; + }) => + `${extensionClientUrlBase}/${endpointId}/#${encodeURIComponent(JSON.stringify({ encKey: encryptionKey, ...optionalData }))}`, flottformApi: signalingServerUrlBase, inputField: targetedInputField }); diff --git a/servers/chrome-extension/static/scripts/flottform-bundle.js b/servers/chrome-extension/static/scripts/flottform-bundle.js index 491d7f1..828c650 100644 --- a/servers/chrome-extension/static/scripts/flottform-bundle.js +++ b/servers/chrome-extension/static/scripts/flottform-bundle.js @@ -1,6 +1,6 @@ -var gt = Object.defineProperty; -var pt = (r, o, t) => o in r ? gt(r, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[o] = t; -var u = (r, o, t) => pt(r, typeof o != "symbol" ? o + "" : o, t); +var me = Object.defineProperty; +var Ce = (o, r, e) => r in o ? me(o, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[r] = e; +var u = (o, r, e) => Ce(o, typeof r != "symbol" ? r + "" : r, e); const q = class q { constructor() { u(this, "activeConnections"); @@ -9,35 +9,35 @@ const q = class q { static getInstance() { return q.instance || (q.instance = new q()), q.instance; } - addConnection(o, t) { - this.activeConnections.set(o, t); + addConnection(r, e) { + this.activeConnections.set(r, e); } - getConnection(o) { - return this.activeConnections.get(o); + getConnection(r) { + return this.activeConnections.get(r); } closeAllConnections() { - this.activeConnections.forEach((o) => { - o.close(); + this.activeConnections.forEach((r) => { + r.close(); }); } - removeConnection(o) { - this.activeConnections.delete(o); + removeConnection(r) { + this.activeConnections.delete(r); } }; u(q, "instance"); -let Ae = q; -var H = {}, X, Be; -function mt() { - return Be || (Be = 1, X = function() { +let vt = q; +var x = {}, et, Lt; +function ye() { + return Lt || (Lt = 1, et = function() { return typeof Promise == "function" && Promise.prototype && Promise.prototype.then; - }), X; + }), et; } -var ee = {}, U = {}, ve; -function z() { - if (ve) return U; - ve = 1; - let r; - const o = [ +var nt = {}, U = {}, Mt; +function K() { + if (Mt) return U; + Mt = 1; + let o; + const r = [ 0, // Not used 26, @@ -81,121 +81,121 @@ function z() { 3532, 3706 ]; - return U.getSymbolSize = function(e) { - if (!e) throw new Error('"version" cannot be null or undefined'); - if (e < 1 || e > 40) throw new Error('"version" should be in range from 1 to 40'); - return e * 4 + 17; - }, U.getSymbolTotalCodewords = function(e) { - return o[e]; - }, U.getBCHDigit = function(t) { - let e = 0; - for (; t !== 0; ) - e++, t >>>= 1; - return e; - }, U.setToSJISFunction = function(e) { - if (typeof e != "function") + return U.getSymbolSize = function(t) { + if (!t) throw new Error('"version" cannot be null or undefined'); + if (t < 1 || t > 40) throw new Error('"version" should be in range from 1 to 40'); + return t * 4 + 17; + }, U.getSymbolTotalCodewords = function(t) { + return r[t]; + }, U.getBCHDigit = function(e) { + let t = 0; + for (; e !== 0; ) + t++, e >>>= 1; + return t; + }, U.setToSJISFunction = function(t) { + if (typeof t != "function") throw new Error('"toSJISFunc" is not a valid function.'); - r = e; + o = t; }, U.isKanjiModeEnabled = function() { - return typeof r < "u"; - }, U.toSJIS = function(e) { - return r(e); + return typeof o < "u"; + }, U.toSJIS = function(t) { + return o(t); }, U; } -var te = {}, Le; -function Ee() { - return Le || (Le = 1, function(r) { - r.L = { bit: 1 }, r.M = { bit: 0 }, r.Q = { bit: 3 }, r.H = { bit: 2 }; - function o(t) { - if (typeof t != "string") +var it = {}, Nt; +function Tt() { + return Nt || (Nt = 1, function(o) { + o.L = { bit: 1 }, o.M = { bit: 0 }, o.Q = { bit: 3 }, o.H = { bit: 2 }; + function r(e) { + if (typeof e != "string") throw new Error("Param is not a string"); - switch (t.toLowerCase()) { + switch (e.toLowerCase()) { case "l": case "low": - return r.L; + return o.L; case "m": case "medium": - return r.M; + return o.M; case "q": case "quartile": - return r.Q; + return o.Q; case "h": case "high": - return r.H; + return o.H; default: - throw new Error("Unknown EC Level: " + t); + throw new Error("Unknown EC Level: " + e); } } - r.isValid = function(e) { - return e && typeof e.bit < "u" && e.bit >= 0 && e.bit < 4; - }, r.from = function(e, n) { - if (r.isValid(e)) - return e; + o.isValid = function(t) { + return t && typeof t.bit < "u" && t.bit >= 0 && t.bit < 4; + }, o.from = function(t, n) { + if (o.isValid(t)) + return t; try { - return o(e); + return r(t); } catch { return n; } }; - }(te)), te; + }(it)), it; } -var ne, Me; -function Ct() { - if (Me) return ne; - Me = 1; - function r() { +var ot, Rt; +function we() { + if (Rt) return ot; + Rt = 1; + function o() { this.buffer = [], this.length = 0; } - return r.prototype = { - get: function(o) { - const t = Math.floor(o / 8); - return (this.buffer[t] >>> 7 - o % 8 & 1) === 1; + return o.prototype = { + get: function(r) { + const e = Math.floor(r / 8); + return (this.buffer[e] >>> 7 - r % 8 & 1) === 1; }, - put: function(o, t) { - for (let e = 0; e < t; e++) - this.putBit((o >>> t - e - 1 & 1) === 1); + put: function(r, e) { + for (let t = 0; t < e; t++) + this.putBit((r >>> e - t - 1 & 1) === 1); }, getLengthInBits: function() { return this.length; }, - putBit: function(o) { - const t = Math.floor(this.length / 8); - this.buffer.length <= t && this.buffer.push(0), o && (this.buffer[t] |= 128 >>> this.length % 8), this.length++; + putBit: function(r) { + const e = Math.floor(this.length / 8); + this.buffer.length <= e && this.buffer.push(0), r && (this.buffer[e] |= 128 >>> this.length % 8), this.length++; } - }, ne = r, ne; + }, ot = o, ot; } -var ie, Re; -function wt() { - if (Re) return ie; - Re = 1; - function r(o) { - if (!o || o < 1) +var rt, Dt; +function be() { + if (Dt) return rt; + Dt = 1; + function o(r) { + if (!r || r < 1) throw new Error("BitMatrix size must be defined and greater than 0"); - this.size = o, this.data = new Uint8Array(o * o), this.reservedBit = new Uint8Array(o * o); + this.size = r, this.data = new Uint8Array(r * r), this.reservedBit = new Uint8Array(r * r); } - return r.prototype.set = function(o, t, e, n) { - const i = o * this.size + t; - this.data[i] = e, n && (this.reservedBit[i] = !0); - }, r.prototype.get = function(o, t) { - return this.data[o * this.size + t]; - }, r.prototype.xor = function(o, t, e) { - this.data[o * this.size + t] ^= e; - }, r.prototype.isReserved = function(o, t) { - return this.reservedBit[o * this.size + t]; - }, ie = r, ie; + return o.prototype.set = function(r, e, t, n) { + const i = r * this.size + e; + this.data[i] = t, n && (this.reservedBit[i] = !0); + }, o.prototype.get = function(r, e) { + return this.data[r * this.size + e]; + }, o.prototype.xor = function(r, e, t) { + this.data[r * this.size + e] ^= t; + }, o.prototype.isReserved = function(r, e) { + return this.reservedBit[r * this.size + e]; + }, rt = o, rt; } -var oe = {}, Ne; -function yt() { - return Ne || (Ne = 1, function(r) { - const o = z().getSymbolSize; - r.getRowColCoords = function(e) { - if (e === 1) return []; - const n = Math.floor(e / 7) + 2, i = o(e), s = i === 145 ? 26 : Math.ceil((i - 13) / (2 * n - 2)) * 2, a = [i - 7]; +var st = {}, kt; +function Se() { + return kt || (kt = 1, function(o) { + const r = K().getSymbolSize; + o.getRowColCoords = function(t) { + if (t === 1) return []; + const n = Math.floor(t / 7) + 2, i = r(t), s = i === 145 ? 26 : Math.ceil((i - 13) / (2 * n - 2)) * 2, a = [i - 7]; for (let c = 1; c < n - 1; c++) a[c] = a[c - 1] - s; return a.push(6), a.reverse(); - }, r.getPositions = function(e) { - const n = [], i = r.getRowColCoords(e), s = i.length; + }, o.getPositions = function(t) { + const n = [], i = o.getRowColCoords(t), s = i.length; for (let a = 0; a < s; a++) for (let c = 0; c < s; c++) a === 0 && c === 0 || // top-left @@ -203,29 +203,29 @@ function yt() { a === s - 1 && c === 0 || n.push([i[a], i[c]]); return n; }; - }(oe)), oe; + }(st)), st; } -var re = {}, De; -function bt() { - if (De) return re; - De = 1; - const r = z().getSymbolSize, o = 7; - return re.getPositions = function(e) { - const n = r(e); +var at = {}, Ut; +function Ee() { + if (Ut) return at; + Ut = 1; + const o = K().getSymbolSize, r = 7; + return at.getPositions = function(t) { + const n = o(t); return [ // top-left [0, 0], // top-right - [n - o, 0], + [n - r, 0], // bottom-left - [0, n - o] + [0, n - r] ]; - }, re; + }, at; } -var se = {}, ke; -function St() { - return ke || (ke = 1, function(r) { - r.Patterns = { +var ct = {}, qt; +function Fe() { + return qt || (qt = 1, function(o) { + o.Patterns = { PATTERN000: 0, PATTERN001: 1, PATTERN010: 2, @@ -235,29 +235,29 @@ function St() { PATTERN110: 6, PATTERN111: 7 }; - const o = { + const r = { N1: 3, N2: 3, N3: 40, N4: 10 }; - r.isValid = function(n) { + o.isValid = function(n) { return n != null && n !== "" && !isNaN(n) && n >= 0 && n <= 7; - }, r.from = function(n) { - return r.isValid(n) ? parseInt(n, 10) : void 0; - }, r.getPenaltyN1 = function(n) { + }, o.from = function(n) { + return o.isValid(n) ? parseInt(n, 10) : void 0; + }, o.getPenaltyN1 = function(n) { const i = n.size; let s = 0, a = 0, c = 0, l = null, h = null; for (let f = 0; f < i; f++) { a = c = 0, l = h = null; for (let g = 0; g < i; g++) { let d = n.get(f, g); - d === l ? a++ : (a >= 5 && (s += o.N1 + (a - 5)), l = d, a = 1), d = n.get(g, f), d === h ? c++ : (c >= 5 && (s += o.N1 + (c - 5)), h = d, c = 1); + d === l ? a++ : (a >= 5 && (s += r.N1 + (a - 5)), l = d, a = 1), d = n.get(g, f), d === h ? c++ : (c >= 5 && (s += r.N1 + (c - 5)), h = d, c = 1); } - a >= 5 && (s += o.N1 + (a - 5)), c >= 5 && (s += o.N1 + (c - 5)); + a >= 5 && (s += r.N1 + (a - 5)), c >= 5 && (s += r.N1 + (c - 5)); } return s; - }, r.getPenaltyN2 = function(n) { + }, o.getPenaltyN2 = function(n) { const i = n.size; let s = 0; for (let a = 0; a < i - 1; a++) @@ -265,8 +265,8 @@ function St() { const l = n.get(a, c) + n.get(a, c + 1) + n.get(a + 1, c) + n.get(a + 1, c + 1); (l === 4 || l === 0) && s++; } - return s * o.N2; - }, r.getPenaltyN3 = function(n) { + return s * r.N2; + }, o.getPenaltyN3 = function(n) { const i = n.size; let s = 0, a = 0, c = 0; for (let l = 0; l < i; l++) { @@ -274,57 +274,57 @@ function St() { for (let h = 0; h < i; h++) a = a << 1 & 2047 | n.get(l, h), h >= 10 && (a === 1488 || a === 93) && s++, c = c << 1 & 2047 | n.get(h, l), h >= 10 && (c === 1488 || c === 93) && s++; } - return s * o.N3; - }, r.getPenaltyN4 = function(n) { + return s * r.N3; + }, o.getPenaltyN4 = function(n) { let i = 0; const s = n.data.length; for (let c = 0; c < s; c++) i += n.data[c]; - return Math.abs(Math.ceil(i * 100 / s / 5) - 10) * o.N4; + return Math.abs(Math.ceil(i * 100 / s / 5) - 10) * r.N4; }; - function t(e, n, i) { - switch (e) { - case r.Patterns.PATTERN000: + function e(t, n, i) { + switch (t) { + case o.Patterns.PATTERN000: return (n + i) % 2 === 0; - case r.Patterns.PATTERN001: + case o.Patterns.PATTERN001: return n % 2 === 0; - case r.Patterns.PATTERN010: + case o.Patterns.PATTERN010: return i % 3 === 0; - case r.Patterns.PATTERN011: + case o.Patterns.PATTERN011: return (n + i) % 3 === 0; - case r.Patterns.PATTERN100: + case o.Patterns.PATTERN100: return (Math.floor(n / 2) + Math.floor(i / 3)) % 2 === 0; - case r.Patterns.PATTERN101: + case o.Patterns.PATTERN101: return n * i % 2 + n * i % 3 === 0; - case r.Patterns.PATTERN110: + case o.Patterns.PATTERN110: return (n * i % 2 + n * i % 3) % 2 === 0; - case r.Patterns.PATTERN111: + case o.Patterns.PATTERN111: return (n * i % 3 + (n + i) % 2) % 2 === 0; default: - throw new Error("bad maskPattern:" + e); + throw new Error("bad maskPattern:" + t); } } - r.applyMask = function(n, i) { + o.applyMask = function(n, i) { const s = i.size; for (let a = 0; a < s; a++) for (let c = 0; c < s; c++) - i.isReserved(c, a) || i.xor(c, a, t(n, c, a)); - }, r.getBestMask = function(n, i) { - const s = Object.keys(r.Patterns).length; + i.isReserved(c, a) || i.xor(c, a, e(n, c, a)); + }, o.getBestMask = function(n, i) { + const s = Object.keys(o.Patterns).length; let a = 0, c = 1 / 0; for (let l = 0; l < s; l++) { - i(l), r.applyMask(l, n); - const h = r.getPenaltyN1(n) + r.getPenaltyN2(n) + r.getPenaltyN3(n) + r.getPenaltyN4(n); - r.applyMask(l, n), h < c && (c = h, a = l); + i(l), o.applyMask(l, n); + const h = o.getPenaltyN1(n) + o.getPenaltyN2(n) + o.getPenaltyN3(n) + o.getPenaltyN4(n); + o.applyMask(l, n), h < c && (c = h, a = l); } return a; }; - }(se)), se; + }(ct)), ct; } -var G = {}, Ue; -function it() { - if (Ue) return G; - Ue = 1; - const r = Ee(), o = [ +var j = {}, Kt; +function re() { + if (Kt) return j; + Kt = 1; + const o = Tt(), r = [ // L M Q H 1, 1, @@ -486,7 +486,7 @@ function it() { 49, 68, 81 - ], t = [ + ], e = [ // L M Q H 7, 10, @@ -649,240 +649,240 @@ function it() { 2040, 2430 ]; - return G.getBlocksCount = function(n, i) { + return j.getBlocksCount = function(n, i) { switch (i) { - case r.L: - return o[(n - 1) * 4 + 0]; - case r.M: - return o[(n - 1) * 4 + 1]; - case r.Q: - return o[(n - 1) * 4 + 2]; - case r.H: - return o[(n - 1) * 4 + 3]; + case o.L: + return r[(n - 1) * 4 + 0]; + case o.M: + return r[(n - 1) * 4 + 1]; + case o.Q: + return r[(n - 1) * 4 + 2]; + case o.H: + return r[(n - 1) * 4 + 3]; default: return; } - }, G.getTotalCodewordsCount = function(n, i) { + }, j.getTotalCodewordsCount = function(n, i) { switch (i) { - case r.L: - return t[(n - 1) * 4 + 0]; - case r.M: - return t[(n - 1) * 4 + 1]; - case r.Q: - return t[(n - 1) * 4 + 2]; - case r.H: - return t[(n - 1) * 4 + 3]; + case o.L: + return e[(n - 1) * 4 + 0]; + case o.M: + return e[(n - 1) * 4 + 1]; + case o.Q: + return e[(n - 1) * 4 + 2]; + case o.H: + return e[(n - 1) * 4 + 3]; default: return; } - }, G; + }, j; } -var ae = {}, O = {}, qe; -function Ft() { - if (qe) return O; - qe = 1; - const r = new Uint8Array(512), o = new Uint8Array(256); +var lt = {}, H = {}, zt; +function Ie() { + if (zt) return H; + zt = 1; + const o = new Uint8Array(512), r = new Uint8Array(256); return function() { - let e = 1; + let t = 1; for (let n = 0; n < 255; n++) - r[n] = e, o[e] = n, e <<= 1, e & 256 && (e ^= 285); + o[n] = t, r[t] = n, t <<= 1, t & 256 && (t ^= 285); for (let n = 255; n < 512; n++) - r[n] = r[n - 255]; - }(), O.log = function(e) { - if (e < 1) throw new Error("log(" + e + ")"); - return o[e]; - }, O.exp = function(e) { - return r[e]; - }, O.mul = function(e, n) { - return e === 0 || n === 0 ? 0 : r[o[e] + o[n]]; - }, O; + o[n] = o[n - 255]; + }(), H.log = function(t) { + if (t < 1) throw new Error("log(" + t + ")"); + return r[t]; + }, H.exp = function(t) { + return o[t]; + }, H.mul = function(t, n) { + return t === 0 || n === 0 ? 0 : o[r[t] + r[n]]; + }, H; } -var ze; -function Et() { - return ze || (ze = 1, function(r) { - const o = Ft(); - r.mul = function(e, n) { - const i = new Uint8Array(e.length + n.length - 1); - for (let s = 0; s < e.length; s++) +var _t; +function Te() { + return _t || (_t = 1, function(o) { + const r = Ie(); + o.mul = function(t, n) { + const i = new Uint8Array(t.length + n.length - 1); + for (let s = 0; s < t.length; s++) for (let a = 0; a < n.length; a++) - i[s + a] ^= o.mul(e[s], n[a]); + i[s + a] ^= r.mul(t[s], n[a]); return i; - }, r.mod = function(e, n) { - let i = new Uint8Array(e); + }, o.mod = function(t, n) { + let i = new Uint8Array(t); for (; i.length - n.length >= 0; ) { const s = i[0]; for (let c = 0; c < n.length; c++) - i[c] ^= o.mul(n[c], s); + i[c] ^= r.mul(n[c], s); let a = 0; for (; a < i.length && i[a] === 0; ) a++; i = i.slice(a); } return i; - }, r.generateECPolynomial = function(e) { + }, o.generateECPolynomial = function(t) { let n = new Uint8Array([1]); - for (let i = 0; i < e; i++) - n = r.mul(n, new Uint8Array([1, o.exp(i)])); + for (let i = 0; i < t; i++) + n = o.mul(n, new Uint8Array([1, r.exp(i)])); return n; }; - }(ae)), ae; + }(lt)), lt; } -var ce, _e; -function It() { - if (_e) return ce; - _e = 1; - const r = Et(); - function o(t) { - this.genPoly = void 0, this.degree = t, this.degree && this.initialize(this.degree); +var ut, xt; +function Ae() { + if (xt) return ut; + xt = 1; + const o = Te(); + function r(e) { + this.genPoly = void 0, this.degree = e, this.degree && this.initialize(this.degree); } - return o.prototype.initialize = function(e) { - this.degree = e, this.genPoly = r.generateECPolynomial(this.degree); - }, o.prototype.encode = function(e) { + return r.prototype.initialize = function(t) { + this.degree = t, this.genPoly = o.generateECPolynomial(this.degree); + }, r.prototype.encode = function(t) { if (!this.genPoly) throw new Error("Encoder not initialized"); - const n = new Uint8Array(e.length + this.degree); - n.set(e); - const i = r.mod(n, this.genPoly), s = this.degree - i.length; + const n = new Uint8Array(t.length + this.degree); + n.set(t); + const i = o.mod(n, this.genPoly), s = this.degree - i.length; if (s > 0) { const a = new Uint8Array(this.degree); return a.set(i, s), a; } return i; - }, ce = o, ce; + }, ut = r, ut; } -var le = {}, ue = {}, he = {}, $e; -function ot() { - return $e || ($e = 1, he.isValid = function(o) { - return !isNaN(o) && o >= 1 && o <= 40; - }), he; +var ht = {}, ft = {}, dt = {}, $t; +function se() { + return $t || ($t = 1, dt.isValid = function(r) { + return !isNaN(r) && r >= 1 && r <= 40; + }), dt; } -var R = {}, He; -function rt() { - if (He) return R; - He = 1; - const r = "[0-9]+", o = "[A-Z $%*+\\-./:]+"; - let t = "(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+"; - t = t.replace(/u/g, "\\u"); - const e = "(?:(?![A-Z0-9 $%*+\\-./:]|" + t + `)(?:.|[\r +var N = {}, Ht; +function ae() { + if (Ht) return N; + Ht = 1; + const o = "[0-9]+", r = "[A-Z $%*+\\-./:]+"; + let e = "(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+"; + e = e.replace(/u/g, "\\u"); + const t = "(?:(?![A-Z0-9 $%*+\\-./:]|" + e + `)(?:.|[\r ]))+`; - R.KANJI = new RegExp(t, "g"), R.BYTE_KANJI = new RegExp("[^A-Z0-9 $%*+\\-./:]+", "g"), R.BYTE = new RegExp(e, "g"), R.NUMERIC = new RegExp(r, "g"), R.ALPHANUMERIC = new RegExp(o, "g"); - const n = new RegExp("^" + t + "$"), i = new RegExp("^" + r + "$"), s = new RegExp("^[A-Z0-9 $%*+\\-./:]+$"); - return R.testKanji = function(c) { + N.KANJI = new RegExp(e, "g"), N.BYTE_KANJI = new RegExp("[^A-Z0-9 $%*+\\-./:]+", "g"), N.BYTE = new RegExp(t, "g"), N.NUMERIC = new RegExp(o, "g"), N.ALPHANUMERIC = new RegExp(r, "g"); + const n = new RegExp("^" + e + "$"), i = new RegExp("^" + o + "$"), s = new RegExp("^[A-Z0-9 $%*+\\-./:]+$"); + return N.testKanji = function(c) { return n.test(c); - }, R.testNumeric = function(c) { + }, N.testNumeric = function(c) { return i.test(c); - }, R.testAlphanumeric = function(c) { + }, N.testAlphanumeric = function(c) { return s.test(c); - }, R; + }, N; } -var xe; -function _() { - return xe || (xe = 1, function(r) { - const o = ot(), t = rt(); - r.NUMERIC = { +var Ot; +function z() { + return Ot || (Ot = 1, function(o) { + const r = se(), e = ae(); + o.NUMERIC = { id: "Numeric", bit: 1, ccBits: [10, 12, 14] - }, r.ALPHANUMERIC = { + }, o.ALPHANUMERIC = { id: "Alphanumeric", bit: 2, ccBits: [9, 11, 13] - }, r.BYTE = { + }, o.BYTE = { id: "Byte", bit: 4, ccBits: [8, 16, 16] - }, r.KANJI = { + }, o.KANJI = { id: "Kanji", bit: 8, ccBits: [8, 10, 12] - }, r.MIXED = { + }, o.MIXED = { bit: -1 - }, r.getCharCountIndicator = function(i, s) { + }, o.getCharCountIndicator = function(i, s) { if (!i.ccBits) throw new Error("Invalid mode: " + i); - if (!o.isValid(s)) + if (!r.isValid(s)) throw new Error("Invalid version: " + s); return s >= 1 && s < 10 ? i.ccBits[0] : s < 27 ? i.ccBits[1] : i.ccBits[2]; - }, r.getBestModeForData = function(i) { - return t.testNumeric(i) ? r.NUMERIC : t.testAlphanumeric(i) ? r.ALPHANUMERIC : t.testKanji(i) ? r.KANJI : r.BYTE; - }, r.toString = function(i) { + }, o.getBestModeForData = function(i) { + return e.testNumeric(i) ? o.NUMERIC : e.testAlphanumeric(i) ? o.ALPHANUMERIC : e.testKanji(i) ? o.KANJI : o.BYTE; + }, o.toString = function(i) { if (i && i.id) return i.id; throw new Error("Invalid mode"); - }, r.isValid = function(i) { + }, o.isValid = function(i) { return i && i.bit && i.ccBits; }; - function e(n) { + function t(n) { if (typeof n != "string") throw new Error("Param is not a string"); switch (n.toLowerCase()) { case "numeric": - return r.NUMERIC; + return o.NUMERIC; case "alphanumeric": - return r.ALPHANUMERIC; + return o.ALPHANUMERIC; case "kanji": - return r.KANJI; + return o.KANJI; case "byte": - return r.BYTE; + return o.BYTE; default: throw new Error("Unknown mode: " + n); } } - r.from = function(i, s) { - if (r.isValid(i)) + o.from = function(i, s) { + if (o.isValid(i)) return i; try { - return e(i); + return t(i); } catch { return s; } }; - }(ue)), ue; + }(ft)), ft; } -var Oe; -function Pt() { - return Oe || (Oe = 1, function(r) { - const o = z(), t = it(), e = Ee(), n = _(), i = ot(), s = 7973, a = o.getBCHDigit(s); - function c(g, d, T) { +var Jt; +function Pe() { + return Jt || (Jt = 1, function(o) { + const r = K(), e = re(), t = Tt(), n = z(), i = se(), s = 7973, a = r.getBCHDigit(s); + function c(g, d, A) { for (let I = 1; I <= 40; I++) - if (d <= r.getCapacity(I, T, g)) + if (d <= o.getCapacity(I, A, g)) return I; } function l(g, d) { return n.getCharCountIndicator(g, d) + 4; } function h(g, d) { - let T = 0; + let A = 0; return g.forEach(function(I) { const L = l(I.mode, d); - T += L + I.getBitsLength(); - }), T; + A += L + I.getBitsLength(); + }), A; } function f(g, d) { - for (let T = 1; T <= 40; T++) - if (h(g, T) <= r.getCapacity(T, d, n.MIXED)) - return T; + for (let A = 1; A <= 40; A++) + if (h(g, A) <= o.getCapacity(A, d, n.MIXED)) + return A; } - r.from = function(d, T) { - return i.isValid(d) ? parseInt(d, 10) : T; - }, r.getCapacity = function(d, T, I) { + o.from = function(d, A) { + return i.isValid(d) ? parseInt(d, 10) : A; + }, o.getCapacity = function(d, A, I) { if (!i.isValid(d)) throw new Error("Invalid QR Code version"); typeof I > "u" && (I = n.BYTE); - const L = o.getSymbolTotalCodewords(d), y = t.getTotalCodewordsCount(d, T), B = (L - y) * 8; + const L = r.getSymbolTotalCodewords(d), w = e.getTotalCodewordsCount(d, A), B = (L - w) * 8; if (I === n.MIXED) return B; - const P = B - l(I, d); + const T = B - l(I, d); switch (I) { case n.NUMERIC: - return Math.floor(P / 10 * 3); + return Math.floor(T / 10 * 3); case n.ALPHANUMERIC: - return Math.floor(P / 11 * 2); + return Math.floor(T / 11 * 2); case n.KANJI: - return Math.floor(P / 13); + return Math.floor(T / 13); case n.BYTE: default: - return Math.floor(P / 8); + return Math.floor(T / 8); } - }, r.getBestVersionForData = function(d, T) { + }, o.getBestVersionForData = function(d, A) { let I; - const L = e.from(T, e.M); + const L = t.from(A, t.M); if (Array.isArray(d)) { if (d.length > 1) return f(d, L); @@ -892,56 +892,56 @@ function Pt() { } else I = d; return c(I.mode, I.getLength(), L); - }, r.getEncodedBits = function(d) { + }, o.getEncodedBits = function(d) { if (!i.isValid(d) || d < 7) throw new Error("Invalid QR Code version"); - let T = d << 12; - for (; o.getBCHDigit(T) - a >= 0; ) - T ^= s << o.getBCHDigit(T) - a; - return d << 12 | T; + let A = d << 12; + for (; r.getBCHDigit(A) - a >= 0; ) + A ^= s << r.getBCHDigit(A) - a; + return d << 12 | A; }; - }(le)), le; + }(ht)), ht; } -var fe = {}, Je; -function Tt() { - if (Je) return fe; - Je = 1; - const r = z(), o = 1335, t = 21522, e = r.getBCHDigit(o); - return fe.getEncodedBits = function(i, s) { +var gt = {}, Gt; +function Be() { + if (Gt) return gt; + Gt = 1; + const o = K(), r = 1335, e = 21522, t = o.getBCHDigit(r); + return gt.getEncodedBits = function(i, s) { const a = i.bit << 3 | s; let c = a << 10; - for (; r.getBCHDigit(c) - e >= 0; ) - c ^= o << r.getBCHDigit(c) - e; - return (a << 10 | c) ^ t; - }, fe; + for (; o.getBCHDigit(c) - t >= 0; ) + c ^= r << o.getBCHDigit(c) - t; + return (a << 10 | c) ^ e; + }, gt; } -var de = {}, ge, Ve; -function At() { - if (Ve) return ge; - Ve = 1; - const r = _(); - function o(t) { - this.mode = r.NUMERIC, this.data = t.toString(); +var pt = {}, mt, Vt; +function ve() { + if (Vt) return mt; + Vt = 1; + const o = z(); + function r(e) { + this.mode = o.NUMERIC, this.data = e.toString(); } - return o.getBitsLength = function(e) { - return 10 * Math.floor(e / 3) + (e % 3 ? e % 3 * 3 + 1 : 0); - }, o.prototype.getLength = function() { + return r.getBitsLength = function(t) { + return 10 * Math.floor(t / 3) + (t % 3 ? t % 3 * 3 + 1 : 0); + }, r.prototype.getLength = function() { return this.data.length; - }, o.prototype.getBitsLength = function() { - return o.getBitsLength(this.data.length); - }, o.prototype.write = function(e) { + }, r.prototype.getBitsLength = function() { + return r.getBitsLength(this.data.length); + }, r.prototype.write = function(t) { let n, i, s; for (n = 0; n + 3 <= this.data.length; n += 3) - i = this.data.substr(n, 3), s = parseInt(i, 10), e.put(s, 10); + i = this.data.substr(n, 3), s = parseInt(i, 10), t.put(s, 10); const a = this.data.length - n; - a > 0 && (i = this.data.substr(n), s = parseInt(i, 10), e.put(s, a * 3 + 1)); - }, ge = o, ge; + a > 0 && (i = this.data.substr(n), s = parseInt(i, 10), t.put(s, a * 3 + 1)); + }, mt = r, mt; } -var pe, Ke; -function Bt() { - if (Ke) return pe; - Ke = 1; - const r = _(), o = [ +var Ct, jt; +function Le() { + if (jt) return Ct; + jt = 1; + const o = z(), r = [ "0", "1", "2", @@ -988,61 +988,61 @@ function Bt() { "/", ":" ]; - function t(e) { - this.mode = r.ALPHANUMERIC, this.data = e; + function e(t) { + this.mode = o.ALPHANUMERIC, this.data = t; } - return t.getBitsLength = function(n) { + return e.getBitsLength = function(n) { return 11 * Math.floor(n / 2) + 6 * (n % 2); - }, t.prototype.getLength = function() { + }, e.prototype.getLength = function() { return this.data.length; - }, t.prototype.getBitsLength = function() { - return t.getBitsLength(this.data.length); - }, t.prototype.write = function(n) { + }, e.prototype.getBitsLength = function() { + return e.getBitsLength(this.data.length); + }, e.prototype.write = function(n) { let i; for (i = 0; i + 2 <= this.data.length; i += 2) { - let s = o.indexOf(this.data[i]) * 45; - s += o.indexOf(this.data[i + 1]), n.put(s, 11); + let s = r.indexOf(this.data[i]) * 45; + s += r.indexOf(this.data[i + 1]), n.put(s, 11); } - this.data.length % 2 && n.put(o.indexOf(this.data[i]), 6); - }, pe = t, pe; + this.data.length % 2 && n.put(r.indexOf(this.data[i]), 6); + }, Ct = e, Ct; } -var me, Ge; -function vt() { - if (Ge) return me; - Ge = 1; - const r = _(); - function o(t) { - this.mode = r.BYTE, typeof t == "string" ? this.data = new TextEncoder().encode(t) : this.data = new Uint8Array(t); +var yt, Yt; +function Me() { + if (Yt) return yt; + Yt = 1; + const o = z(); + function r(e) { + this.mode = o.BYTE, typeof e == "string" ? this.data = new TextEncoder().encode(e) : this.data = new Uint8Array(e); } - return o.getBitsLength = function(e) { - return e * 8; - }, o.prototype.getLength = function() { + return r.getBitsLength = function(t) { + return t * 8; + }, r.prototype.getLength = function() { return this.data.length; - }, o.prototype.getBitsLength = function() { - return o.getBitsLength(this.data.length); - }, o.prototype.write = function(t) { - for (let e = 0, n = this.data.length; e < n; e++) - t.put(this.data[e], 8); - }, me = o, me; + }, r.prototype.getBitsLength = function() { + return r.getBitsLength(this.data.length); + }, r.prototype.write = function(e) { + for (let t = 0, n = this.data.length; t < n; t++) + e.put(this.data[t], 8); + }, yt = r, yt; } -var Ce, je; -function Lt() { - if (je) return Ce; - je = 1; - const r = _(), o = z(); - function t(e) { - this.mode = r.KANJI, this.data = e; +var wt, Qt; +function Ne() { + if (Qt) return wt; + Qt = 1; + const o = z(), r = K(); + function e(t) { + this.mode = o.KANJI, this.data = t; } - return t.getBitsLength = function(n) { + return e.getBitsLength = function(n) { return n * 13; - }, t.prototype.getLength = function() { + }, e.prototype.getLength = function() { return this.data.length; - }, t.prototype.getBitsLength = function() { - return t.getBitsLength(this.data.length); - }, t.prototype.write = function(e) { + }, e.prototype.getBitsLength = function() { + return e.getBitsLength(this.data.length); + }, e.prototype.write = function(t) { let n; for (n = 0; n < this.data.length; n++) { - let i = o.toSJIS(this.data[n]); + let i = r.toSJIS(this.data[n]); if (i >= 33088 && i <= 40956) i -= 33088; else if (i >= 57408 && i <= 60351) @@ -1052,38 +1052,38 @@ function Lt() { "Invalid SJIS character: " + this.data[n] + ` Make sure your charset is UTF-8` ); - i = (i >>> 8 & 255) * 192 + (i & 255), e.put(i, 13); + i = (i >>> 8 & 255) * 192 + (i & 255), t.put(i, 13); } - }, Ce = t, Ce; + }, wt = e, wt; } -var we = { exports: {} }, Ye; -function Mt() { - return Ye || (Ye = 1, function(r) { - var o = { - single_source_shortest_paths: function(t, e, n) { +var bt = { exports: {} }, Wt; +function Re() { + return Wt || (Wt = 1, function(o) { + var r = { + single_source_shortest_paths: function(e, t, n) { var i = {}, s = {}; - s[e] = 0; - var a = o.PriorityQueue.make(); - a.push(e, 0); - for (var c, l, h, f, g, d, T, I, L; !a.empty(); ) { - c = a.pop(), l = c.value, f = c.cost, g = t[l] || {}; + s[t] = 0; + var a = r.PriorityQueue.make(); + a.push(t, 0); + for (var c, l, h, f, g, d, A, I, L; !a.empty(); ) { + c = a.pop(), l = c.value, f = c.cost, g = e[l] || {}; for (h in g) - g.hasOwnProperty(h) && (d = g[h], T = f + d, I = s[h], L = typeof s[h] > "u", (L || I > T) && (s[h] = T, a.push(h, T), i[h] = l)); + g.hasOwnProperty(h) && (d = g[h], A = f + d, I = s[h], L = typeof s[h] > "u", (L || I > A) && (s[h] = A, a.push(h, A), i[h] = l)); } if (typeof n < "u" && typeof s[n] > "u") { - var y = ["Could not find a path from ", e, " to ", n, "."].join(""); - throw new Error(y); + var w = ["Could not find a path from ", t, " to ", n, "."].join(""); + throw new Error(w); } return i; }, - extract_shortest_path_from_predecessor_list: function(t, e) { - for (var n = [], i = e; i; ) - n.push(i), t[i], i = t[i]; + extract_shortest_path_from_predecessor_list: function(e, t) { + for (var n = [], i = t; i; ) + n.push(i), e[i], i = e[i]; return n.reverse(), n; }, - find_path: function(t, e, n) { - var i = o.single_source_shortest_paths(t, e, n); - return o.extract_shortest_path_from_predecessor_list( + find_path: function(e, t, n) { + var i = r.single_source_shortest_paths(e, t, n); + return r.extract_shortest_path_from_predecessor_list( i, n ); @@ -1092,22 +1092,22 @@ function Mt() { * A very naive priority queue implementation. */ PriorityQueue: { - make: function(t) { - var e = o.PriorityQueue, n = {}, i; - t = t || {}; - for (i in e) - e.hasOwnProperty(i) && (n[i] = e[i]); - return n.queue = [], n.sorter = t.sorter || e.default_sorter, n; + make: function(e) { + var t = r.PriorityQueue, n = {}, i; + e = e || {}; + for (i in t) + t.hasOwnProperty(i) && (n[i] = t[i]); + return n.queue = [], n.sorter = e.sorter || t.default_sorter, n; }, - default_sorter: function(t, e) { - return t.cost - e.cost; + default_sorter: function(e, t) { + return e.cost - t.cost; }, /** * Add a new item to the queue and ensure the highest priority element * is at the front of the queue. */ - push: function(t, e) { - var n = { value: t, cost: e }; + push: function(e, t) { + var n = { value: e, cost: t }; this.queue.push(n), this.queue.sort(this.sorter); }, /** @@ -1121,20 +1121,20 @@ function Mt() { } } }; - r.exports = o; - }(we)), we.exports; + o.exports = r; + }(bt)), bt.exports; } -var Qe; -function Rt() { - return Qe || (Qe = 1, function(r) { - const o = _(), t = At(), e = Bt(), n = vt(), i = Lt(), s = rt(), a = z(), c = Mt(); - function l(y) { - return unescape(encodeURIComponent(y)).length; +var Zt; +function De() { + return Zt || (Zt = 1, function(o) { + const r = z(), e = ve(), t = Le(), n = Me(), i = Ne(), s = ae(), a = K(), c = Re(); + function l(w) { + return unescape(encodeURIComponent(w)).length; } - function h(y, B, P) { + function h(w, B, T) { const b = []; let M; - for (; (M = y.exec(P)) !== null; ) + for (; (M = w.exec(T)) !== null; ) b.push({ data: M[0], index: M.index, @@ -1143,374 +1143,374 @@ function Rt() { }); return b; } - function f(y) { - const B = h(s.NUMERIC, o.NUMERIC, y), P = h(s.ALPHANUMERIC, o.ALPHANUMERIC, y); + function f(w) { + const B = h(s.NUMERIC, r.NUMERIC, w), T = h(s.ALPHANUMERIC, r.ALPHANUMERIC, w); let b, M; - return a.isKanjiModeEnabled() ? (b = h(s.BYTE, o.BYTE, y), M = h(s.KANJI, o.KANJI, y)) : (b = h(s.BYTE_KANJI, o.BYTE, y), M = []), B.concat(P, b, M).sort(function(F, S) { - return F.index - S.index; - }).map(function(F) { + return a.isKanjiModeEnabled() ? (b = h(s.BYTE, r.BYTE, w), M = h(s.KANJI, r.KANJI, w)) : (b = h(s.BYTE_KANJI, r.BYTE, w), M = []), B.concat(T, b, M).sort(function(E, S) { + return E.index - S.index; + }).map(function(E) { return { - data: F.data, - mode: F.mode, - length: F.length + data: E.data, + mode: E.mode, + length: E.length }; }); } - function g(y, B) { + function g(w, B) { switch (B) { - case o.NUMERIC: - return t.getBitsLength(y); - case o.ALPHANUMERIC: - return e.getBitsLength(y); - case o.KANJI: - return i.getBitsLength(y); - case o.BYTE: - return n.getBitsLength(y); + case r.NUMERIC: + return e.getBitsLength(w); + case r.ALPHANUMERIC: + return t.getBitsLength(w); + case r.KANJI: + return i.getBitsLength(w); + case r.BYTE: + return n.getBitsLength(w); } } - function d(y) { - return y.reduce(function(B, P) { + function d(w) { + return w.reduce(function(B, T) { const b = B.length - 1 >= 0 ? B[B.length - 1] : null; - return b && b.mode === P.mode ? (B[B.length - 1].data += P.data, B) : (B.push(P), B); + return b && b.mode === T.mode ? (B[B.length - 1].data += T.data, B) : (B.push(T), B); }, []); } - function T(y) { + function A(w) { const B = []; - for (let P = 0; P < y.length; P++) { - const b = y[P]; + for (let T = 0; T < w.length; T++) { + const b = w[T]; switch (b.mode) { - case o.NUMERIC: + case r.NUMERIC: B.push([ b, - { data: b.data, mode: o.ALPHANUMERIC, length: b.length }, - { data: b.data, mode: o.BYTE, length: b.length } + { data: b.data, mode: r.ALPHANUMERIC, length: b.length }, + { data: b.data, mode: r.BYTE, length: b.length } ]); break; - case o.ALPHANUMERIC: + case r.ALPHANUMERIC: B.push([ b, - { data: b.data, mode: o.BYTE, length: b.length } + { data: b.data, mode: r.BYTE, length: b.length } ]); break; - case o.KANJI: + case r.KANJI: B.push([ b, - { data: b.data, mode: o.BYTE, length: l(b.data) } + { data: b.data, mode: r.BYTE, length: l(b.data) } ]); break; - case o.BYTE: + case r.BYTE: B.push([ - { data: b.data, mode: o.BYTE, length: l(b.data) } + { data: b.data, mode: r.BYTE, length: l(b.data) } ]); } } return B; } - function I(y, B) { - const P = {}, b = { start: {} }; + function I(w, B) { + const T = {}, b = { start: {} }; let M = ["start"]; - for (let p = 0; p < y.length; p++) { - const F = y[p], S = []; - for (let m = 0; m < F.length; m++) { - const A = F[m], C = "" + p + m; - S.push(C), P[C] = { node: A, lastCount: 0 }, b[C] = {}; - for (let E = 0; E < M.length; E++) { - const w = M[E]; - P[w] && P[w].node.mode === A.mode ? (b[w][C] = g(P[w].lastCount + A.length, A.mode) - g(P[w].lastCount, A.mode), P[w].lastCount += A.length) : (P[w] && (P[w].lastCount = A.length), b[w][C] = g(A.length, A.mode) + 4 + o.getCharCountIndicator(A.mode, B)); + for (let p = 0; p < w.length; p++) { + const E = w[p], S = []; + for (let m = 0; m < E.length; m++) { + const P = E[m], C = "" + p + m; + S.push(C), T[C] = { node: P, lastCount: 0 }, b[C] = {}; + for (let F = 0; F < M.length; F++) { + const y = M[F]; + T[y] && T[y].node.mode === P.mode ? (b[y][C] = g(T[y].lastCount + P.length, P.mode) - g(T[y].lastCount, P.mode), T[y].lastCount += P.length) : (T[y] && (T[y].lastCount = P.length), b[y][C] = g(P.length, P.mode) + 4 + r.getCharCountIndicator(P.mode, B)); } } M = S; } for (let p = 0; p < M.length; p++) b[M[p]].end = 0; - return { map: b, table: P }; + return { map: b, table: T }; } - function L(y, B) { - let P; - const b = o.getBestModeForData(y); - if (P = o.from(B, b), P !== o.BYTE && P.bit < b.bit) - throw new Error('"' + y + '" cannot be encoded with mode ' + o.toString(P) + `. - Suggested mode is: ` + o.toString(b)); - switch (P === o.KANJI && !a.isKanjiModeEnabled() && (P = o.BYTE), P) { - case o.NUMERIC: - return new t(y); - case o.ALPHANUMERIC: - return new e(y); - case o.KANJI: - return new i(y); - case o.BYTE: - return new n(y); + function L(w, B) { + let T; + const b = r.getBestModeForData(w); + if (T = r.from(B, b), T !== r.BYTE && T.bit < b.bit) + throw new Error('"' + w + '" cannot be encoded with mode ' + r.toString(T) + `. + Suggested mode is: ` + r.toString(b)); + switch (T === r.KANJI && !a.isKanjiModeEnabled() && (T = r.BYTE), T) { + case r.NUMERIC: + return new e(w); + case r.ALPHANUMERIC: + return new t(w); + case r.KANJI: + return new i(w); + case r.BYTE: + return new n(w); } } - r.fromArray = function(B) { - return B.reduce(function(P, b) { - return typeof b == "string" ? P.push(L(b, null)) : b.data && P.push(L(b.data, b.mode)), P; + o.fromArray = function(B) { + return B.reduce(function(T, b) { + return typeof b == "string" ? T.push(L(b, null)) : b.data && T.push(L(b.data, b.mode)), T; }, []); - }, r.fromString = function(B, P) { - const b = f(B, a.isKanjiModeEnabled()), M = T(b), p = I(M, P), F = c.find_path(p.map, "start", "end"), S = []; - for (let m = 1; m < F.length - 1; m++) - S.push(p.table[F[m]].node); - return r.fromArray(d(S)); - }, r.rawSplit = function(B) { - return r.fromArray( + }, o.fromString = function(B, T) { + const b = f(B, a.isKanjiModeEnabled()), M = A(b), p = I(M, T), E = c.find_path(p.map, "start", "end"), S = []; + for (let m = 1; m < E.length - 1; m++) + S.push(p.table[E[m]].node); + return o.fromArray(d(S)); + }, o.rawSplit = function(B) { + return o.fromArray( f(B, a.isKanjiModeEnabled()) ); }; - }(de)), de; + }(pt)), pt; } -var We; -function Nt() { - if (We) return ee; - We = 1; - const r = z(), o = Ee(), t = Ct(), e = wt(), n = yt(), i = bt(), s = St(), a = it(), c = It(), l = Pt(), h = Tt(), f = _(), g = Rt(); - function d(p, F) { - const S = p.size, m = i.getPositions(F); - for (let A = 0; A < m.length; A++) { - const C = m[A][0], E = m[A][1]; - for (let w = -1; w <= 7; w++) - if (!(C + w <= -1 || S <= C + w)) +var Xt; +function ke() { + if (Xt) return nt; + Xt = 1; + const o = K(), r = Tt(), e = we(), t = be(), n = Se(), i = Ee(), s = Fe(), a = re(), c = Ae(), l = Pe(), h = Be(), f = z(), g = De(); + function d(p, E) { + const S = p.size, m = i.getPositions(E); + for (let P = 0; P < m.length; P++) { + const C = m[P][0], F = m[P][1]; + for (let y = -1; y <= 7; y++) + if (!(C + y <= -1 || S <= C + y)) for (let v = -1; v <= 7; v++) - E + v <= -1 || S <= E + v || (w >= 0 && w <= 6 && (v === 0 || v === 6) || v >= 0 && v <= 6 && (w === 0 || w === 6) || w >= 2 && w <= 4 && v >= 2 && v <= 4 ? p.set(C + w, E + v, !0, !0) : p.set(C + w, E + v, !1, !0)); + F + v <= -1 || S <= F + v || (y >= 0 && y <= 6 && (v === 0 || v === 6) || v >= 0 && v <= 6 && (y === 0 || y === 6) || y >= 2 && y <= 4 && v >= 2 && v <= 4 ? p.set(C + y, F + v, !0, !0) : p.set(C + y, F + v, !1, !0)); } } - function T(p) { - const F = p.size; - for (let S = 8; S < F - 8; S++) { + function A(p) { + const E = p.size; + for (let S = 8; S < E - 8; S++) { const m = S % 2 === 0; p.set(S, 6, m, !0), p.set(6, S, m, !0); } } - function I(p, F) { - const S = n.getPositions(F); + function I(p, E) { + const S = n.getPositions(E); for (let m = 0; m < S.length; m++) { - const A = S[m][0], C = S[m][1]; - for (let E = -2; E <= 2; E++) - for (let w = -2; w <= 2; w++) - E === -2 || E === 2 || w === -2 || w === 2 || E === 0 && w === 0 ? p.set(A + E, C + w, !0, !0) : p.set(A + E, C + w, !1, !0); + const P = S[m][0], C = S[m][1]; + for (let F = -2; F <= 2; F++) + for (let y = -2; y <= 2; y++) + F === -2 || F === 2 || y === -2 || y === 2 || F === 0 && y === 0 ? p.set(P + F, C + y, !0, !0) : p.set(P + F, C + y, !1, !0); } } - function L(p, F) { - const S = p.size, m = l.getEncodedBits(F); - let A, C, E; - for (let w = 0; w < 18; w++) - A = Math.floor(w / 3), C = w % 3 + S - 8 - 3, E = (m >> w & 1) === 1, p.set(A, C, E, !0), p.set(C, A, E, !0); + function L(p, E) { + const S = p.size, m = l.getEncodedBits(E); + let P, C, F; + for (let y = 0; y < 18; y++) + P = Math.floor(y / 3), C = y % 3 + S - 8 - 3, F = (m >> y & 1) === 1, p.set(P, C, F, !0), p.set(C, P, F, !0); } - function y(p, F, S) { - const m = p.size, A = h.getEncodedBits(F, S); - let C, E; + function w(p, E, S) { + const m = p.size, P = h.getEncodedBits(E, S); + let C, F; for (C = 0; C < 15; C++) - E = (A >> C & 1) === 1, C < 6 ? p.set(C, 8, E, !0) : C < 8 ? p.set(C + 1, 8, E, !0) : p.set(m - 15 + C, 8, E, !0), C < 8 ? p.set(8, m - C - 1, E, !0) : C < 9 ? p.set(8, 15 - C - 1 + 1, E, !0) : p.set(8, 15 - C - 1, E, !0); + F = (P >> C & 1) === 1, C < 6 ? p.set(C, 8, F, !0) : C < 8 ? p.set(C + 1, 8, F, !0) : p.set(m - 15 + C, 8, F, !0), C < 8 ? p.set(8, m - C - 1, F, !0) : C < 9 ? p.set(8, 15 - C - 1 + 1, F, !0) : p.set(8, 15 - C - 1, F, !0); p.set(m - 8, 8, 1, !0); } - function B(p, F) { + function B(p, E) { const S = p.size; - let m = -1, A = S - 1, C = 7, E = 0; - for (let w = S - 1; w > 0; w -= 2) - for (w === 6 && w--; ; ) { + let m = -1, P = S - 1, C = 7, F = 0; + for (let y = S - 1; y > 0; y -= 2) + for (y === 6 && y--; ; ) { for (let v = 0; v < 2; v++) - if (!p.isReserved(A, w - v)) { + if (!p.isReserved(P, y - v)) { let k = !1; - E < F.length && (k = (F[E] >>> C & 1) === 1), p.set(A, w - v, k), C--, C === -1 && (E++, C = 7); + F < E.length && (k = (E[F] >>> C & 1) === 1), p.set(P, y - v, k), C--, C === -1 && (F++, C = 7); } - if (A += m, A < 0 || S <= A) { - A -= m, m = -m; + if (P += m, P < 0 || S <= P) { + P -= m, m = -m; break; } } } - function P(p, F, S) { - const m = new t(); + function T(p, E, S) { + const m = new e(); S.forEach(function(v) { m.put(v.mode.bit, 4), m.put(v.getLength(), f.getCharCountIndicator(v.mode, p)), v.write(m); }); - const A = r.getSymbolTotalCodewords(p), C = a.getTotalCodewordsCount(p, F), E = (A - C) * 8; - for (m.getLengthInBits() + 4 <= E && m.put(0, 4); m.getLengthInBits() % 8 !== 0; ) + const P = o.getSymbolTotalCodewords(p), C = a.getTotalCodewordsCount(p, E), F = (P - C) * 8; + for (m.getLengthInBits() + 4 <= F && m.put(0, 4); m.getLengthInBits() % 8 !== 0; ) m.putBit(0); - const w = (E - m.getLengthInBits()) / 8; - for (let v = 0; v < w; v++) + const y = (F - m.getLengthInBits()) / 8; + for (let v = 0; v < y; v++) m.put(v % 2 ? 17 : 236, 8); - return b(m, p, F); + return b(m, p, E); } - function b(p, F, S) { - const m = r.getSymbolTotalCodewords(F), A = a.getTotalCodewordsCount(F, S), C = m - A, E = a.getBlocksCount(F, S), w = m % E, v = E - w, k = Math.floor(m / E), x = Math.floor(C / E), ht = x + 1, Ie = k - x, ft = new c(Ie); - let Y = 0; - const K = new Array(E), Pe = new Array(E); - let Q = 0; - const dt = new Uint8Array(p.buffer); - for (let $ = 0; $ < E; $++) { - const Z = $ < v ? x : ht; - K[$] = dt.slice(Y, Y + Z), Pe[$] = ft.encode(K[$]), Y += Z, Q = Math.max(Q, Z); + function b(p, E, S) { + const m = o.getSymbolTotalCodewords(E), P = a.getTotalCodewordsCount(E, S), C = m - P, F = a.getBlocksCount(E, S), y = m % F, v = F - y, k = Math.floor(m / F), $ = Math.floor(C / F), de = $ + 1, At = k - $, ge = new c(At); + let W = 0; + const V = new Array(F), Pt = new Array(F); + let Z = 0; + const pe = new Uint8Array(p.buffer); + for (let _ = 0; _ < F; _++) { + const tt = _ < v ? $ : de; + V[_] = pe.slice(W, W + tt), Pt[_] = ge.encode(V[_]), W += tt, Z = Math.max(Z, tt); } - const W = new Uint8Array(m); - let Te = 0, N, D; - for (N = 0; N < Q; N++) - for (D = 0; D < E; D++) - N < K[D].length && (W[Te++] = K[D][N]); - for (N = 0; N < Ie; N++) - for (D = 0; D < E; D++) - W[Te++] = Pe[D][N]; - return W; + const X = new Uint8Array(m); + let Bt = 0, R, D; + for (R = 0; R < Z; R++) + for (D = 0; D < F; D++) + R < V[D].length && (X[Bt++] = V[D][R]); + for (R = 0; R < At; R++) + for (D = 0; D < F; D++) + X[Bt++] = Pt[D][R]; + return X; } - function M(p, F, S, m) { - let A; + function M(p, E, S, m) { + let P; if (Array.isArray(p)) - A = g.fromArray(p); + P = g.fromArray(p); else if (typeof p == "string") { - let k = F; + let k = E; if (!k) { - const x = g.rawSplit(p); - k = l.getBestVersionForData(x, S); + const $ = g.rawSplit(p); + k = l.getBestVersionForData($, S); } - A = g.fromString(p, k || 40); + P = g.fromString(p, k || 40); } else throw new Error("Invalid data"); - const C = l.getBestVersionForData(A, S); + const C = l.getBestVersionForData(P, S); if (!C) throw new Error("The amount of data is too big to be stored in a QR Code"); - if (!F) - F = C; - else if (F < C) + if (!E) + E = C; + else if (E < C) throw new Error( ` The chosen QR Code version cannot contain this amount of data. Minimum version required to store current data is: ` + C + `. ` ); - const E = P(F, S, A), w = r.getSymbolSize(F), v = new e(w); - return d(v, F), T(v), I(v, F), y(v, S, 0), F >= 7 && L(v, F), B(v, E), isNaN(m) && (m = s.getBestMask( + const F = T(E, S, P), y = o.getSymbolSize(E), v = new t(y); + return d(v, E), A(v), I(v, E), w(v, S, 0), E >= 7 && L(v, E), B(v, F), isNaN(m) && (m = s.getBestMask( v, - y.bind(null, v, S) - )), s.applyMask(m, v), y(v, S, m), { + w.bind(null, v, S) + )), s.applyMask(m, v), w(v, S, m), { modules: v, - version: F, + version: E, errorCorrectionLevel: S, maskPattern: m, - segments: A + segments: P }; } - return ee.create = function(F, S) { - if (typeof F > "u" || F === "") + return nt.create = function(E, S) { + if (typeof E > "u" || E === "") throw new Error("No input text"); - let m = o.M, A, C; - return typeof S < "u" && (m = o.from(S.errorCorrectionLevel, o.M), A = l.from(S.version), C = s.from(S.maskPattern), S.toSJISFunc && r.setToSJISFunction(S.toSJISFunc)), M(F, A, m, C); - }, ee; + let m = r.M, P, C; + return typeof S < "u" && (m = r.from(S.errorCorrectionLevel, r.M), P = l.from(S.version), C = s.from(S.maskPattern), S.toSJISFunc && o.setToSJISFunction(S.toSJISFunc)), M(E, P, m, C); + }, nt; } -var ye = {}, be = {}, Ze; -function st() { - return Ze || (Ze = 1, function(r) { - function o(t) { - if (typeof t == "number" && (t = t.toString()), typeof t != "string") +var St = {}, Et = {}, te; +function ce() { + return te || (te = 1, function(o) { + function r(e) { + if (typeof e == "number" && (e = e.toString()), typeof e != "string") throw new Error("Color should be defined as hex string"); - let e = t.slice().replace("#", "").split(""); - if (e.length < 3 || e.length === 5 || e.length > 8) - throw new Error("Invalid hex color: " + t); - (e.length === 3 || e.length === 4) && (e = Array.prototype.concat.apply([], e.map(function(i) { + let t = e.slice().replace("#", "").split(""); + if (t.length < 3 || t.length === 5 || t.length > 8) + throw new Error("Invalid hex color: " + e); + (t.length === 3 || t.length === 4) && (t = Array.prototype.concat.apply([], t.map(function(i) { return [i, i]; - }))), e.length === 6 && e.push("F", "F"); - const n = parseInt(e.join(""), 16); + }))), t.length === 6 && t.push("F", "F"); + const n = parseInt(t.join(""), 16); return { r: n >> 24 & 255, g: n >> 16 & 255, b: n >> 8 & 255, a: n & 255, - hex: "#" + e.slice(0, 6).join("") + hex: "#" + t.slice(0, 6).join("") }; } - r.getOptions = function(e) { - e || (e = {}), e.color || (e.color = {}); - const n = typeof e.margin > "u" || e.margin === null || e.margin < 0 ? 4 : e.margin, i = e.width && e.width >= 21 ? e.width : void 0, s = e.scale || 4; + o.getOptions = function(t) { + t || (t = {}), t.color || (t.color = {}); + const n = typeof t.margin > "u" || t.margin === null || t.margin < 0 ? 4 : t.margin, i = t.width && t.width >= 21 ? t.width : void 0, s = t.scale || 4; return { width: i, scale: i ? 4 : s, margin: n, color: { - dark: o(e.color.dark || "#000000ff"), - light: o(e.color.light || "#ffffffff") + dark: r(t.color.dark || "#000000ff"), + light: r(t.color.light || "#ffffffff") }, - type: e.type, - rendererOpts: e.rendererOpts || {} + type: t.type, + rendererOpts: t.rendererOpts || {} }; - }, r.getScale = function(e, n) { - return n.width && n.width >= e + n.margin * 2 ? n.width / (e + n.margin * 2) : n.scale; - }, r.getImageWidth = function(e, n) { - const i = r.getScale(e, n); - return Math.floor((e + n.margin * 2) * i); - }, r.qrToImageData = function(e, n, i) { - const s = n.modules.size, a = n.modules.data, c = r.getScale(s, i), l = Math.floor((s + i.margin * 2) * c), h = i.margin * c, f = [i.color.light, i.color.dark]; + }, o.getScale = function(t, n) { + return n.width && n.width >= t + n.margin * 2 ? n.width / (t + n.margin * 2) : n.scale; + }, o.getImageWidth = function(t, n) { + const i = o.getScale(t, n); + return Math.floor((t + n.margin * 2) * i); + }, o.qrToImageData = function(t, n, i) { + const s = n.modules.size, a = n.modules.data, c = o.getScale(s, i), l = Math.floor((s + i.margin * 2) * c), h = i.margin * c, f = [i.color.light, i.color.dark]; for (let g = 0; g < l; g++) for (let d = 0; d < l; d++) { - let T = (g * l + d) * 4, I = i.color.light; + let A = (g * l + d) * 4, I = i.color.light; if (g >= h && d >= h && g < l - h && d < l - h) { - const L = Math.floor((g - h) / c), y = Math.floor((d - h) / c); - I = f[a[L * s + y] ? 1 : 0]; + const L = Math.floor((g - h) / c), w = Math.floor((d - h) / c); + I = f[a[L * s + w] ? 1 : 0]; } - e[T++] = I.r, e[T++] = I.g, e[T++] = I.b, e[T] = I.a; + t[A++] = I.r, t[A++] = I.g, t[A++] = I.b, t[A] = I.a; } }; - }(be)), be; + }(Et)), Et; } -var Xe; -function Dt() { - return Xe || (Xe = 1, function(r) { - const o = st(); - function t(n, i, s) { +var ee; +function Ue() { + return ee || (ee = 1, function(o) { + const r = ce(); + function e(n, i, s) { n.clearRect(0, 0, i.width, i.height), i.style || (i.style = {}), i.height = s, i.width = s, i.style.height = s + "px", i.style.width = s + "px"; } - function e() { + function t() { try { return document.createElement("canvas"); } catch { throw new Error("You need to specify a canvas element"); } } - r.render = function(i, s, a) { + o.render = function(i, s, a) { let c = a, l = s; - typeof c > "u" && (!s || !s.getContext) && (c = s, s = void 0), s || (l = e()), c = o.getOptions(c); - const h = o.getImageWidth(i.modules.size, c), f = l.getContext("2d"), g = f.createImageData(h, h); - return o.qrToImageData(g.data, i, c), t(f, l, h), f.putImageData(g, 0, 0), l; - }, r.renderToDataURL = function(i, s, a) { + typeof c > "u" && (!s || !s.getContext) && (c = s, s = void 0), s || (l = t()), c = r.getOptions(c); + const h = r.getImageWidth(i.modules.size, c), f = l.getContext("2d"), g = f.createImageData(h, h); + return r.qrToImageData(g.data, i, c), e(f, l, h), f.putImageData(g, 0, 0), l; + }, o.renderToDataURL = function(i, s, a) { let c = a; typeof c > "u" && (!s || !s.getContext) && (c = s, s = void 0), c || (c = {}); - const l = r.render(i, s, c), h = c.type || "image/png", f = c.rendererOpts || {}; + const l = o.render(i, s, c), h = c.type || "image/png", f = c.rendererOpts || {}; return l.toDataURL(h, f.quality); }; - }(ye)), ye; + }(St)), St; } -var Se = {}, et; -function kt() { - if (et) return Se; - et = 1; - const r = st(); - function o(n, i) { +var Ft = {}, ne; +function qe() { + if (ne) return Ft; + ne = 1; + const o = ce(); + function r(n, i) { const s = n.a / 255, a = i + '="' + n.hex + '"'; return s < 1 ? a + " " + i + '-opacity="' + s.toFixed(2).slice(1) + '"' : a; } - function t(n, i, s) { + function e(n, i, s) { let a = n + i; return typeof s < "u" && (a += " " + s), a; } - function e(n, i, s) { + function t(n, i, s) { let a = "", c = 0, l = !1, h = 0; for (let f = 0; f < n.length; f++) { const g = Math.floor(f % i), d = Math.floor(f / i); - !g && !l && (l = !0), n[f] ? (h++, f > 0 && g > 0 && n[f - 1] || (a += l ? t("M", g + s, 0.5 + d + s) : t("m", c, 0), c = 0, l = !1), g + 1 < i && n[f + 1] || (a += t("h", h), h = 0)) : c++; + !g && !l && (l = !0), n[f] ? (h++, f > 0 && g > 0 && n[f - 1] || (a += l ? e("M", g + s, 0.5 + d + s) : e("m", c, 0), c = 0, l = !1), g + 1 < i && n[f + 1] || (a += e("h", h), h = 0)) : c++; } return a; } - return Se.render = function(i, s, a) { - const c = r.getOptions(s), l = i.modules.size, h = i.modules.data, f = l + c.margin * 2, g = c.color.light.a ? "' : "", d = "', T = 'viewBox="0 0 ' + f + " " + f + '"', L = '' + g + d + ` + return Ft.render = function(i, s, a) { + const c = o.getOptions(s), l = i.modules.size, h = i.modules.data, f = l + c.margin * 2, g = c.color.light.a ? "' : "", d = "', A = 'viewBox="0 0 ' + f + " " + f + '"', L = '' + g + d + ` `; return typeof a == "function" && a(null, L), L; - }, Se; + }, Ft; } -var tt; -function Ut() { - if (tt) return H; - tt = 1; - const r = mt(), o = Nt(), t = Dt(), e = kt(); +var ie; +function Ke() { + if (ie) return x; + ie = 1; + const o = ye(), r = ke(), e = Ue(), t = qe(); function n(i, s, a, c, l) { const h = [].slice.call(arguments, 1), f = h.length, g = typeof h[f - 1] == "function"; - if (!g && !r()) + if (!g && !o()) throw new Error("Callback required as last argument"); if (g) { if (f < 2) @@ -1519,70 +1519,144 @@ function Ut() { } else { if (f < 1) throw new Error("Too few arguments provided"); - return f === 1 ? (a = s, s = c = void 0) : f === 2 && !s.getContext && (c = a, a = s, s = void 0), new Promise(function(d, T) { + return f === 1 ? (a = s, s = c = void 0) : f === 2 && !s.getContext && (c = a, a = s, s = void 0), new Promise(function(d, A) { try { - const I = o.create(a, c); + const I = r.create(a, c); d(i(I, s, c)); } catch (I) { - T(I); + A(I); } }); } try { - const d = o.create(a, c); + const d = r.create(a, c); l(null, i(d, s, c)); } catch (d) { l(d); } } - return H.create = o.create, H.toCanvas = n.bind(null, t.render), H.toDataURL = n.bind(null, t.renderToDataURL), H.toString = n.bind(null, function(i, s, a) { - return e.render(i, a); - }), H; + return x.create = r.create, x.toCanvas = n.bind(null, e.render), x.toDataURL = n.bind(null, e.renderToDataURL), x.toString = n.bind(null, function(i, s, a) { + return t.render(i, a); + }), x; } -var qt = Ut(); -const J = 1e3, j = { +var ze = Ke(); +const J = 1e3, Q = { iceServers: [ { urls: ["stun:stun1.l.google.com:19302"] } ] }; -function zt() { +function _e() { return crypto.randomUUID(); } -async function Fe(r) { - return await (await fetch(r)).json(); +async function It(o) { + return await (await fetch(o)).json(); } -function at(r, o) { - for (const t of r) - if (JSON.stringify(t) === JSON.stringify(o)) +function le(o, r) { + for (const e of o) + if (JSON.stringify(e) === JSON.stringify(r)) return !0; return !1; } -class V { +class G { constructor() { u(this, "eventListeners", {}); } - on(o, t) { - const e = this.eventListeners[o] ?? /* @__PURE__ */ new Set(); - e.add(t), this.eventListeners[o] = e; + on(r, e) { + const t = this.eventListeners[r] ?? /* @__PURE__ */ new Set(); + t.add(e), this.eventListeners[r] = t; } - off(o, t) { - const e = this.eventListeners[o]; - e && (e.delete(t), e.size === 0 && delete this.eventListeners[o]); + off(r, e) { + const t = this.eventListeners[r]; + t && (t.delete(e), t.size === 0 && delete this.eventListeners[r]); } - emit(o, ...t) { - const e = this.eventListeners[o] ?? /* @__PURE__ */ new Set(); - for (const n of e) - n(...t); + emit(r, ...e) { + const t = this.eventListeners[r] ?? /* @__PURE__ */ new Set(); + for (const n of t) + n(...e); } } -class ct extends V { +class ue extends G { +} +async function xe() { + return await crypto.subtle.generateKey( + { + name: "AES-GCM", + length: 256 + }, + !0, + // extractable + ["encrypt", "decrypt"] + ); +} +async function $e(o) { + return (await crypto.subtle.exportKey("jwk", o)).k; +} +async function He(o) { + const r = { + kty: "oct", + k: o, + alg: "A256GCM", + ext: !0, + key_ops: ["encrypt", "decrypt"] + }; + return await crypto.subtle.importKey( + "jwk", + r, + { + name: "AES-GCM", + length: 256 + // Make sure this matches your key length + }, + !0, + // extractable + ["encrypt", "decrypt"] + ); +} +async function O(o, r) { + const e = Oe(o), t = Je(), n = await crypto.subtle.encrypt( + { + name: "AES-GCM", + iv: t + }, + r, + e + ), i = new Uint8Array(t.length + n.byteLength); + return i.set(t, 0), i.set(new Uint8Array(n), t.length), Ge(i); +} +async function Y(o, r) { + const e = Ve(o), t = e.slice(0, 12), n = e.slice(12), i = await crypto.subtle.decrypt( + { + name: "AES-GCM", + iv: t + }, + r, + n + ); + return je(new Uint8Array(i)); +} +function Oe(o) { + return new TextEncoder().encode(o); +} +function Je() { + return crypto.getRandomValues(new Uint8Array(12)); +} +function Ge(o) { + return btoa(String.fromCharCode(...new Uint8Array(o))); +} +function Ve(o) { + const r = atob(o); + return Uint8Array.from(r, (e) => e.charCodeAt(0)); +} +function je(o, r = !0) { + const t = new TextDecoder().decode(o); + return r ? JSON.parse(t) : t; } -class lt extends V { +class he extends G { constructor({ - flottformApi: t, - createClientUrl: e, + flottformApi: e, + createClientUrl: t, rtcConfiguration: n, pollTimeForIceInMs: i, logger: s @@ -1593,29 +1667,33 @@ class lt extends V { u(this, "rtcConfiguration"); u(this, "pollTimeForIceInMs"); u(this, "logger"); + u(this, "cryptoKey", null); u(this, "state", "new"); u(this, "channelNumber", 0); u(this, "openPeerConnection", null); u(this, "dataChannel", null); u(this, "pollForIceTimer", null); // eslint-disable-next-line @typescript-eslint/no-explicit-any - u(this, "changeState", (t, e) => { - this.state = t, this.emit(t, e), this.logger.info(`State changed to: ${t}`, e ?? ""); + u(this, "changeState", (e, t) => { + this.state = e, this.emit(e, t), this.logger.info(`State changed to: ${e}`, t ?? ""); }); u(this, "start", async () => { - this.openPeerConnection && this.close(); - const t = (this.flottformApi instanceof URL ? this.flottformApi : new URL(this.flottformApi)).toString().replace(/\/$/, ""); + this.openPeerConnection && this.close(), this.cryptoKey = await xe(); + const e = (this.flottformApi instanceof URL ? this.flottformApi : new URL(this.flottformApi)).toString().replace(/\/$/, ""); this.openPeerConnection = new RTCPeerConnection(this.rtcConfiguration), this.dataChannel = this.createDataChannel(); - const e = await this.openPeerConnection.createOffer(); - await this.openPeerConnection.setLocalDescription(e); - const { endpointId: n, hostKey: i } = await this.createEndpoint(t, e); + const t = await this.openPeerConnection.createOffer(); + await this.openPeerConnection.setLocalDescription(t); + const { endpointId: n, hostKey: i } = await this.createEndpoint(e, t); this.logger.log("Created endpoint", { endpointId: n, hostKey: i }); - const s = `${t}/${n}`, a = `${t}/${n}/host`, c = /* @__PURE__ */ new Set(); - await this.putHostInfo(a, i, c, e), this.setUpConnectionStateGathering(s), this.setupHostIceGathering(a, i, c, e), this.setupDataChannelForTransfer(); - const l = await this.createClientUrl({ endpointId: n }); + const s = `${e}/${n}`, a = `${e}/${n}/host`, c = /* @__PURE__ */ new Set(); + await this.putHostInfo(a, i, c, t), this.setUpConnectionStateGathering(s), this.setupHostIceGathering(a, i, c, t), this.setupDataChannelForTransfer(); + const l = await $e(this.cryptoKey); + if (!l) + throw new Error("Encryption Key is undefined!"); + const h = await this.createClientUrl({ endpointId: n, encryptionKey: l }); this.changeState("waiting-for-client", { - qrCode: await qt.toDataURL(l), - link: l, + qrCode: await ze.toDataURL(h), + link: h, channel: this }), this.setupDataChannelListener(); }); @@ -1630,11 +1708,11 @@ class lt extends V { ); return; } - this.dataChannel.onmessage = (t) => { - this.emit("receiving-data", t); + this.dataChannel.onmessage = (e) => { + this.emit("receiving-data", e); }; }); - u(this, "setupHostIceGathering", (t, e, n, i) => { + u(this, "setupHostIceGathering", (e, t, n, i) => { if (this.openPeerConnection === null) { this.changeState("error", "openPeerConnection is null. Unable to gather Host ICE candidates"); return; @@ -1642,7 +1720,7 @@ class lt extends V { this.openPeerConnection.onicecandidate = async (s) => { this.logger.info( `onicecandidate - ${this.openPeerConnection.connectionState} - ${s.candidate}` - ), s.candidate && (at(n, s.candidate) || (this.logger.log("host found new ice candidate! Adding it to our list"), n.add(s.candidate), await this.putHostInfo(t, e, n, i))); + ), s.candidate && (le(n, s.candidate) || (this.logger.log("host found new ice candidate! Adding it to our list"), n.add(s.candidate), await this.putHostInfo(e, t, n, i))); }, this.openPeerConnection.onicegatheringstatechange = async (s) => { this.logger.info( `onicegatheringstatechange - ${this.openPeerConnection.iceGatheringState} - ${s}` @@ -1651,7 +1729,7 @@ class lt extends V { this.logger.error("peerConnection.onicecandidateerror", s); }; }); - u(this, "setUpConnectionStateGathering", (t) => { + u(this, "setUpConnectionStateGathering", (e) => { if (this.openPeerConnection === null) { this.changeState( "error", @@ -1659,54 +1737,62 @@ class lt extends V { ); return; } - this.startPollingForConnection(t), this.openPeerConnection.onconnectionstatechange = () => { - this.logger.info(`onconnectionstatechange - ${this.openPeerConnection.connectionState}`), this.openPeerConnection.connectionState === "connected" && this.stopPollingForConnection(), this.openPeerConnection.connectionState === "disconnected" && this.startPollingForConnection(t), this.openPeerConnection.connectionState === "failed" && (this.stopPollingForConnection(), this.changeState("error", { message: "connection-failed" })); - }, this.openPeerConnection.oniceconnectionstatechange = async (e) => { + this.startPollingForConnection(e), this.openPeerConnection.onconnectionstatechange = () => { + this.logger.info(`onconnectionstatechange - ${this.openPeerConnection.connectionState}`), this.openPeerConnection.connectionState === "connected" && this.stopPollingForConnection(), this.openPeerConnection.connectionState === "disconnected" && this.startPollingForConnection(e), this.openPeerConnection.connectionState === "failed" && (this.stopPollingForConnection(), this.changeState("error", { message: "connection-failed" })); + }, this.openPeerConnection.oniceconnectionstatechange = async (t) => { this.logger.info( - `oniceconnectionstatechange - ${this.openPeerConnection.iceConnectionState} - ${e}` + `oniceconnectionstatechange - ${this.openPeerConnection.iceConnectionState} - ${t}` ), this.openPeerConnection.iceConnectionState === "failed" && (this.logger.log("Failed to find a possible connection path"), this.changeState("error", { message: "connection-impossible" })); }; }); u(this, "stopPollingForConnection", async () => { this.pollForIceTimer && clearTimeout(this.pollForIceTimer), this.pollForIceTimer = null; }); - u(this, "startPollingForConnection", async (t) => { - this.pollForIceTimer && clearTimeout(this.pollForIceTimer), await this.pollForConnection(t), this.pollForIceTimer = setTimeout(() => { - this.startPollingForConnection(t); + u(this, "startPollingForConnection", async (e) => { + this.pollForIceTimer && clearTimeout(this.pollForIceTimer), await this.pollForConnection(e), this.pollForIceTimer = setTimeout(() => { + this.startPollingForConnection(e); }, this.pollTimeForIceInMs); }); - u(this, "createEndpoint", async (t, e) => (await fetch(`${t}/create`, { - method: "POST", - headers: { - Accept: "application/json", - "Content-Type": "application/json" - }, - body: JSON.stringify({ session: e }) - })).json()); - u(this, "fetchIceServers", async (t) => { - const e = await fetch(`${t}/ice-server-credentials`, { + u(this, "createEndpoint", async (e, t) => { + if (!this.cryptoKey) + throw new Error("CryptoKey is null! Encryption is not possible!!"); + const n = await O(JSON.stringify(t), this.cryptoKey); + return (await fetch(`${e}/create`, { + method: "POST", + headers: { + Accept: "application/json", + "Content-Type": "application/json" + }, + body: JSON.stringify({ session: n }) + })).json(); + }); + u(this, "fetchIceServers", async (e) => { + const t = await fetch(`${e}/ice-server-credentials`, { method: "GET", headers: { Accept: "application/json" } }); - if (!e.ok) + if (!t.ok) throw new Error("Fetching Error!"); - const n = await e.json(); + const n = await t.json(); if (n.success === !1) throw new Error(n.message || "Unknown error occurred"); return n.iceServers; }); - u(this, "pollForConnection", async (t) => { + u(this, "pollForConnection", async (e) => { if (this.openPeerConnection === null) { this.changeState("error", "openPeerConnection is null. Unable to retrieve Client's details"); return; } this.logger.log("polling for client ice candidates", this.openPeerConnection.iceGatheringState); - const { clientInfo: e } = await Fe(t); - e && this.state === "waiting-for-client" && (this.logger.log("Found a client that wants to connect!"), this.changeState("waiting-for-ice"), await this.openPeerConnection.setRemoteDescription(e.session)); - for (const n of (e == null ? void 0 : e.iceCandidates) ?? []) - await this.openPeerConnection.addIceCandidate(n); + const { clientInfo: t } = await It(e); + if (!this.cryptoKey) + throw new Error("CryptoKey is null! Decryption is not possible!!"); + let n, i = []; + t && (n = await Y(t.session, this.cryptoKey), i = await Y(t.iceCandidates, this.cryptoKey)), t && this.state === "waiting-for-client" && (this.logger.log("Found a client that wants to connect!"), this.changeState("waiting-for-ice"), await this.openPeerConnection.setRemoteDescription(n)); + for (const s of i ?? []) + await this.openPeerConnection.addIceCandidate(s); }); u(this, "setupDataChannelForTransfer", () => { if (this.dataChannel === null) { @@ -1717,26 +1803,32 @@ class lt extends V { this.logger.log("data channel opened"), this.changeState("waiting-for-data"); }, this.dataChannel.onclose = () => { this.logger.log("data channel closed"); - }, this.dataChannel.onerror = (t) => { - this.logger.log("channel.onerror", t), this.changeState("error", { message: "file-transfer" }); + }, this.dataChannel.onerror = (e) => { + this.logger.log("channel.onerror", e), this.changeState("error", { message: "file-transfer" }); }; }); u(this, "createDataChannel", () => { if (this.openPeerConnection === null) return this.changeState("error", "openPeerConnection is null. Unable to create a new Data Channel"), null; this.channelNumber++; - const t = `data-channel-${this.channelNumber}`; - return this.openPeerConnection.createDataChannel(t); + const e = `data-channel-${this.channelNumber}`; + return this.openPeerConnection.createDataChannel(e); }); - u(this, "putHostInfo", async (t, e, n, i) => { + u(this, "putHostInfo", async (e, t, n, i) => { try { - if (this.logger.log("Updating host info with new list of ice candidates"), !(await fetch(t, { + if (this.logger.log("Updating host info with new list of ice candidates"), !this.cryptoKey) + throw new Error("CryptoKey is null! Encryption is not possible!!"); + const s = await O( + JSON.stringify([...n]), + this.cryptoKey + ), a = await O(JSON.stringify(i), this.cryptoKey); + if (!(await fetch(e, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ - hostKey: e, - iceCandidates: [...n], - session: i + hostKey: t, + iceCandidates: s, + session: a }) })).ok) throw Error("Could not update host info"); @@ -1744,17 +1836,17 @@ class lt extends V { this.changeState("error", s); } }); - this.flottformApi = t, this.createClientUrl = e, this.rtcConfiguration = n, this.pollTimeForIceInMs = i, this.logger = s, Promise.resolve().then(() => { + this.flottformApi = e, this.createClientUrl = t, this.rtcConfiguration = n, this.pollTimeForIceInMs = i, this.logger = s, Promise.resolve().then(() => { this.changeState("new", { channel: this }); }); } } -class _t extends ct { +class Ye extends ue { constructor({ - flottformApi: t, - createClientUrl: e, + flottformApi: e, + createClientUrl: t, inputField: n, - rtcConfiguration: i = j, + rtcConfiguration: i = Q, pollTimeForIceInMs: s = J, logger: a = console }) { @@ -1769,12 +1861,12 @@ class _t extends ct { u(this, "link", ""); u(this, "qrCode", ""); u(this, "start", () => { - var t; - (t = this.channel) == null || t.start(); + var e; + (e = this.channel) == null || e.start(); }); u(this, "close", () => { - var t; - (t = this.channel) == null || t.close(); + var e; + (e = this.channel) == null || e.close(); }); u(this, "getLink", () => (this.link === "" && this.logger.error( "Flottform is currently establishing the connection. Link is unavailable for now!" @@ -1782,13 +1874,13 @@ class _t extends ct { u(this, "getQrCode", () => (this.qrCode === "" && this.logger.error( "Flottform is currently establishing the connection. qrCode is unavailable for now!" ), this.qrCode)); - u(this, "handleIncomingData", (t) => { - var e, n, i; - if (typeof t.data == "string") { - const s = JSON.parse(t.data); - s.type === "file-transfer-meta" ? (this.filesMetaData = s.filesQueue, this.currentFile = { index: 0, receivedSize: 0, arrayBuffer: [] }, this.filesTotalSize = s.totalSize, this.emit("receive")) : s.type === "transfer-complete" && (this.emit("done"), (e = this.channel) == null || e.close()); - } else if (t.data instanceof ArrayBuffer && this.currentFile) { - this.currentFile.arrayBuffer.push(t.data), this.currentFile.receivedSize += t.data.byteLength, this.receivedDataSize += t.data.byteLength; + u(this, "handleIncomingData", (e) => { + var t, n, i; + if (typeof e.data == "string") { + const s = JSON.parse(e.data); + s.type === "file-transfer-meta" ? (this.filesMetaData = s.filesQueue, this.currentFile = { index: 0, receivedSize: 0, arrayBuffer: [] }, this.filesTotalSize = s.totalSize, this.emit("receive")) : s.type === "transfer-complete" && (this.emit("done"), (t = this.channel) == null || t.close()); + } else if (e.data instanceof ArrayBuffer && this.currentFile) { + this.currentFile.arrayBuffer.push(e.data), this.currentFile.receivedSize += e.data.byteLength, this.receivedDataSize += e.data.byteLength; const s = (n = this.filesMetaData[this.currentFile.index]) == null ? void 0 : n.name, a = (i = this.filesMetaData[this.currentFile.index]) == null ? void 0 : i.size, c = (this.currentFile.receivedSize / a).toFixed( 2 ), l = (this.receivedDataSize / this.filesTotalSize).toFixed(2); @@ -1805,9 +1897,9 @@ class _t extends ct { }); } }); - u(this, "appendFileToInputField", (t) => { + u(this, "appendFileToInputField", (e) => { var a, c, l; - const e = ((a = this.filesMetaData[t]) == null ? void 0 : a.name) ?? "no-name", n = ((c = this.filesMetaData[t]) == null ? void 0 : c.type) ?? "application/octet-stream", i = new File((l = this.currentFile) == null ? void 0 : l.arrayBuffer, e, { + const t = ((a = this.filesMetaData[e]) == null ? void 0 : a.name) ?? "no-name", n = ((c = this.filesMetaData[e]) == null ? void 0 : c.type) ?? "application/octet-stream", i = new File((l = this.currentFile) == null ? void 0 : l.arrayBuffer, t, { type: n }); if (this.emit("single-file-transferred", i), !this.inputField) { @@ -1825,10 +1917,10 @@ class _t extends ct { ), s.items.clear()), s.items.add(i), this.inputField.files = s.files; }); u(this, "registerListeners", () => { - var t, e, n, i, s, a, c; - (t = this.channel) == null || t.on("new", () => { + var e, t, n, i, s, a, c; + (e = this.channel) == null || e.on("new", () => { this.emit("new"); - }), (e = this.channel) == null || e.on("waiting-for-client", (l) => { + }), (t = this.channel) == null || t.on("waiting-for-client", (l) => { this.emit("webrtc:waiting-for-client", l); const { qrCode: h, link: f } = l; this.emit("endpoint-created", { link: f, qrCode: h }), this.link = f, this.qrCode = h; @@ -1844,23 +1936,24 @@ class _t extends ct { this.emit("error", l); }); }); - this.channel = new lt({ - flottformApi: t, - createClientUrl: e, + this.channel = new he({ + flottformApi: e, + createClientUrl: t, rtcConfiguration: i, pollTimeForIceInMs: s, logger: a }), this.inputField = n, this.logger = a, this.registerListeners(); } } -class ut extends V { +class fe extends G { // 128KB buffer threshold (maximum of 4 chunks in the buffer waiting to be sent over the network) constructor({ - endpointId: t, - flottformApi: e, + endpointId: e, + flottformApi: t, rtcConfiguration: n, - pollTimeForIceInMs: i = J, - logger: s = console + encryptionKey: i, + pollTimeForIceInMs: s = J, + logger: a = console }) { super(); u(this, "flottformApi"); @@ -1868,36 +1961,41 @@ class ut extends V { u(this, "rtcConfiguration"); u(this, "pollTimeForIceInMs"); u(this, "logger"); + u(this, "cryptoKey", null); + u(this, "encryptionKey"); u(this, "state", "init"); u(this, "openPeerConnection", null); u(this, "dataChannel", null); u(this, "pollForIceTimer", null); u(this, "BUFFER_THRESHOLD", 128 * 1024); // eslint-disable-next-line @typescript-eslint/no-explicit-any - u(this, "changeState", (t, e) => { - this.state = t, this.emit(t, e), this.logger.info(`**Client State changed to: ${t}`, e ?? ""); + u(this, "changeState", (e, t) => { + this.state = e, this.emit(e, t), this.logger.info(`**Client State changed to: ${e}`, t ?? ""); }); u(this, "start", async () => { - this.openPeerConnection && this.close(), (this.flottformApi instanceof URL ? this.flottformApi : new URL(this.flottformApi)).toString().replace(/\/$/, ""), this.openPeerConnection = new RTCPeerConnection(this.rtcConfiguration); - const t = zt(), e = /* @__PURE__ */ new Set(), n = `${this.flottformApi}/${this.endpointId}`, i = `${this.flottformApi}/${this.endpointId}/client`; + this.openPeerConnection && this.close(), this.cryptoKey = await He(this.encryptionKey), this.openPeerConnection = new RTCPeerConnection(this.rtcConfiguration); + const e = _e(), t = /* @__PURE__ */ new Set(), n = `${this.flottformApi}/${this.endpointId}`, i = `${this.flottformApi}/${this.endpointId}/client`; this.changeState("retrieving-info-from-endpoint"); - const { hostInfo: s } = await Fe(n); - await this.openPeerConnection.setRemoteDescription(s.session); - const a = await this.openPeerConnection.createAnswer(); - await this.openPeerConnection.setLocalDescription(a), this.setUpConnectionStateGathering(n), this.setUpClientIceGathering(i, t, e, a), this.openPeerConnection.ondatachannel = (c) => { - this.logger.info(`ondatachannel: ${c.channel}`), this.changeState("connected"), this.dataChannel = c.channel, this.dataChannel.bufferedAmountLowThreshold = this.BUFFER_THRESHOLD, this.dataChannel.onbufferedamountlow = () => { + const { hostInfo: s } = await It(n); + if (!this.cryptoKey) + throw new Error("CryptoKey is null! Decryption is not possible!!"); + const a = await Y(s.session, this.cryptoKey); + await this.openPeerConnection.setRemoteDescription(a); + const c = await this.openPeerConnection.createAnswer(); + await this.openPeerConnection.setLocalDescription(c), this.setUpConnectionStateGathering(n), this.setUpClientIceGathering(i, e, t, c), this.openPeerConnection.ondatachannel = (l) => { + this.logger.info(`ondatachannel: ${l.channel}`), this.changeState("connected"), this.dataChannel = l.channel, this.dataChannel.bufferedAmountLowThreshold = this.BUFFER_THRESHOLD, this.dataChannel.onbufferedamountlow = () => { this.emit("bufferedamountlow"); - }, this.dataChannel.onopen = (l) => { - this.logger.info(`ondatachannel - onopen: ${l.type}`); + }, this.dataChannel.onopen = (h) => { + this.logger.info(`ondatachannel - onopen: ${h.type}`); }; - }, this.changeState("sending-client-info"), await this.putClientInfo(i, t, e, a), this.changeState("connecting-to-host"), this.startPollingForIceCandidates(n); + }, this.changeState("sending-client-info"), await this.putClientInfo(i, e, t, c), this.changeState("connecting-to-host"), this.startPollingForIceCandidates(n); }); u(this, "close", () => { this.openPeerConnection && (this.openPeerConnection.close(), this.openPeerConnection = null, this.stopPollingForIceCandidates()), this.changeState("disconnected"); }); // sendData = (data: string | Blob | ArrayBuffer | ArrayBufferView) => { // eslint-disable-next-line @typescript-eslint/no-explicit-any - u(this, "sendData", (t) => { + u(this, "sendData", (e) => { if (this.dataChannel == null) { this.changeState("error", "dataChannel is null. Unable to send the file to the Host!"); return; @@ -1905,10 +2003,10 @@ class ut extends V { this.logger.warn("Data channel is full! Cannot send data at the moment"); return; } - this.dataChannel.send(t); + this.dataChannel.send(e); }); u(this, "canSendMoreData", () => this.dataChannel && this.dataChannel.bufferedAmount < this.dataChannel.bufferedAmountLowThreshold); - u(this, "setUpClientIceGathering", (t, e, n, i) => { + u(this, "setUpClientIceGathering", (e, t, n, i) => { if (this.openPeerConnection === null) { this.changeState( "error", @@ -1919,14 +2017,14 @@ class ut extends V { this.openPeerConnection.onicecandidate = async (s) => { this.logger.info( `onicecandidate - ${this.openPeerConnection.connectionState} - ${s.candidate}` - ), s.candidate && (at(n, s.candidate) || (this.logger.log("client found new ice candidate! Adding it to our list"), n.add(s.candidate), await this.putClientInfo(t, e, n, i))); + ), s.candidate && (le(n, s.candidate) || (this.logger.log("client found new ice candidate! Adding it to our list"), n.add(s.candidate), await this.putClientInfo(e, t, n, i))); }, this.openPeerConnection.onicegatheringstatechange = async () => { this.logger.info(`onicegatheringstatechange - ${this.openPeerConnection.iceGatheringState}`); }, this.openPeerConnection.onicecandidateerror = (s) => { this.logger.error(`onicecandidateerror - ${this.openPeerConnection.connectionState}`, s); }; }); - u(this, "setUpConnectionStateGathering", (t) => { + u(this, "setUpConnectionStateGathering", (e) => { if (this.openPeerConnection === null) { this.changeState( "error", @@ -1935,7 +2033,7 @@ class ut extends V { return; } this.openPeerConnection.onconnectionstatechange = () => { - this.logger.info(`onconnectionstatechange - ${this.openPeerConnection.connectionState}`), this.openPeerConnection.connectionState === "connected" && (this.stopPollingForIceCandidates(), this.state === "connecting-to-host" && this.changeState("connected")), this.openPeerConnection.connectionState === "disconnected" && this.startPollingForIceCandidates(t), this.openPeerConnection.connectionState === "failed" && (this.stopPollingForIceCandidates(), this.state !== "done" && this.changeState("disconnected")); + this.logger.info(`onconnectionstatechange - ${this.openPeerConnection.connectionState}`), this.openPeerConnection.connectionState === "connected" && (this.stopPollingForIceCandidates(), this.state === "connecting-to-host" && this.changeState("connected")), this.openPeerConnection.connectionState === "disconnected" && this.startPollingForIceCandidates(e), this.openPeerConnection.connectionState === "failed" && (this.stopPollingForIceCandidates(), this.state !== "done" && this.changeState("disconnected")); }, this.openPeerConnection.oniceconnectionstatechange = () => { this.logger.info( `oniceconnectionstatechange - ${this.openPeerConnection.iceConnectionState}` @@ -1945,56 +2043,69 @@ class ut extends V { u(this, "stopPollingForIceCandidates", async () => { this.pollForIceTimer && clearTimeout(this.pollForIceTimer), this.pollForIceTimer = null; }); - u(this, "startPollingForIceCandidates", async (t) => { - this.pollForIceTimer && clearTimeout(this.pollForIceTimer), await this.pollForConnection(t), this.pollForIceTimer = setTimeout(this.startPollingForIceCandidates, this.pollTimeForIceInMs); + u(this, "startPollingForIceCandidates", async (e) => { + this.pollForIceTimer && clearTimeout(this.pollForIceTimer), await this.pollForConnection(e), this.pollForIceTimer = setTimeout(this.startPollingForIceCandidates, this.pollTimeForIceInMs); }); - u(this, "pollForConnection", async (t) => { + u(this, "pollForConnection", async (e) => { if (this.openPeerConnection === null) { this.changeState("error", "openPeerConnection is null. Unable to retrieve Host's details"); return; } this.logger.log("polling for host ice candidates", this.openPeerConnection.iceGatheringState); - const { hostInfo: e } = await Fe(t); - for (const n of e.iceCandidates) - await this.openPeerConnection.addIceCandidate(n); + const { hostInfo: t } = await It(e); + if (!this.cryptoKey) + throw new Error("CryptoKey is null! Decryption is not possible!!"); + const n = await Y( + t.iceCandidates, + this.cryptoKey + ); + for (const i of n) + await this.openPeerConnection.addIceCandidate(i); }); - u(this, "putClientInfo", async (t, e, n, i) => { - if (this.logger.log("Updating client info with new list of ice candidates"), !(await fetch(t, { + u(this, "putClientInfo", async (e, t, n, i) => { + if (this.logger.log("Updating client info with new list of ice candidates"), !this.cryptoKey) + throw new Error("CryptoKey is null! Encryption is not possible!!"); + const s = await O( + JSON.stringify([...n]), + this.cryptoKey + ), a = await O(JSON.stringify(i), this.cryptoKey); + if (!(await fetch(e, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ - clientKey: e, - iceCandidates: [...n], - session: i + clientKey: t, + iceCandidates: s, + session: a }) })).ok) throw Error("Could not update client info. Did another peer already connect?"); }); - u(this, "fetchIceServers", async (t) => { - const e = await fetch(`${t}/ice-server-credentials`, { + u(this, "fetchIceServers", async (e) => { + const t = await fetch(`${e}/ice-server-credentials`, { method: "GET", headers: { Accept: "application/json" } }); - if (!e.ok) + if (!t.ok) throw new Error("Fetching Error!"); - const n = await e.json(); + const n = await t.json(); if (n.success === !1) throw new Error(n.message || "Unknown error occurred"); return n.iceServers; }); - this.endpointId = t, this.flottformApi = e, this.rtcConfiguration = n, this.pollTimeForIceInMs = i, this.logger = s; + this.endpointId = e, this.flottformApi = t, this.rtcConfiguration = n, this.encryptionKey = i, this.pollTimeForIceInMs = s, this.logger = a; } } -class un extends V { +class bn extends G { constructor({ - endpointId: t, - fileInput: e, + endpointId: e, + fileInput: t, flottformApi: n, - rtcConfiguration: i = j, - pollTimeForIceInMs: s = J, - logger: a = console + encryptionKey: i, + rtcConfiguration: s = Q, + pollTimeForIceInMs: a = J, + logger: c = console }) { super(); u(this, "channel", null); @@ -2008,16 +2119,16 @@ class un extends V { u(this, "allFilesSent", !1); u(this, "logger"); u(this, "start", () => { - var t; - (t = this.channel) == null || t.start(); + var e; + (e = this.channel) == null || e.start(); }); u(this, "close", () => { - var t; - (t = this.channel) == null || t.close(); + var e; + (e = this.channel) == null || e.close(); }); - u(this, "createMetaData", (t) => { - if (!t.files) return null; - const n = Array.from(t.files).map((i) => ({ + u(this, "createMetaData", (e) => { + if (!e.files) return null; + const n = Array.from(e.files).map((i) => ({ name: i.name, type: i.type, // We're dividing each file into chuncks no matter what the type of the file. @@ -2029,32 +2140,32 @@ class un extends V { totalSize: n.reduce((i, s) => i + s.size, 0) }; }); - u(this, "createArrayBuffers", async (t) => { - if (!t.files) return null; - const e = Array.from(t.files); - return await Promise.all(e.map(async (n) => await n.arrayBuffer())); + u(this, "createArrayBuffers", async (e) => { + if (!e.files) return null; + const t = Array.from(e.files); + return await Promise.all(t.map(async (n) => await n.arrayBuffer())); }); u(this, "sendFiles", async () => { var n; - const t = this.createMetaData(this.inputField), e = await this.createArrayBuffers(this.inputField); - if (!t || !e) + const e = this.createMetaData(this.inputField), t = await this.createArrayBuffers(this.inputField); + if (!e || !t) throw new Error("Can't find the files that you want to send!"); - this.filesMetaData = t.filesQueue, this.filesArrayBuffer = e, (n = this.channel) == null || n.sendData(JSON.stringify(t)), this.emit("sending"), this.startSendingFiles(); + this.filesMetaData = e.filesQueue, this.filesArrayBuffer = t, (n = this.channel) == null || n.sendData(JSON.stringify(e)), this.emit("sending"), this.startSendingFiles(); }); u(this, "startSendingFiles", () => { this.sendNextChunk(); }); u(this, "sendNextChunk", async () => { var s, a, c, l; - const t = this.filesMetaData.length; - if (this.allFilesSent || this.currentFileIndex >= t) { + const e = this.filesMetaData.length; + if (this.allFilesSent || this.currentFileIndex >= e) { this.logger.log("All files are sent"), (s = this.channel) == null || s.sendData(JSON.stringify({ type: "transfer-complete" })), this.allFilesSent = !0, (a = this.channel) == null || a.off("bufferedamountlow", this.startSendingFiles), this.emit("done"); return; } - const e = this.filesArrayBuffer[this.currentFileIndex]; - if (!e) + const t = this.filesArrayBuffer[this.currentFileIndex]; + if (!t) throw new Error(`Can't find the ArrayBuffer for the file number ${this.currentFileIndex}`); - const n = e.byteLength, i = this.filesMetaData[this.currentFileIndex].name; + const n = t.byteLength, i = this.filesMetaData[this.currentFileIndex].name; for (; this.currentChunkIndex * this.chunkSize < n; ) { if (!((c = this.channel) != null && c.canSendMoreData())) { this.logger.log("Buffer is full. Pausing sending chunks!"); @@ -2067,14 +2178,14 @@ class un extends V { progress: parseFloat(h) }); const f = this.currentChunkIndex * this.chunkSize, g = Math.min((this.currentChunkIndex + 1) * this.chunkSize, n); - (l = this.channel) == null || l.sendData(e.slice(f, g)), this.currentChunkIndex++; + (l = this.channel) == null || l.sendData(t.slice(f, g)), this.currentChunkIndex++; } this.currentChunkIndex * this.chunkSize >= n ? (this.logger.log(`File ${i} fully sent. Moving to next file.`), this.currentFileIndex++, this.currentChunkIndex = 0, this.sendNextChunk()) : setTimeout(this.sendNextChunk, 100); }); u(this, "registerListeners", () => { - var t, e, n, i, s, a, c, l, h, f; - (t = this.channel) == null || t.on("init", () => { - }), (e = this.channel) == null || e.on("retrieving-info-from-endpoint", () => { + var e, t, n, i, s, a, c, l, h, f; + (e = this.channel) == null || e.on("init", () => { + }), (t = this.channel) == null || t.on("retrieving-info-from-endpoint", () => { }), (n = this.channel) == null || n.on("sending-client-info", () => { }), (i = this.channel) == null || i.on("connecting-to-host", () => { }), (s = this.channel) == null || s.on("connected", () => { @@ -2089,42 +2200,44 @@ class un extends V { this.emit("error", g); }), (f = this.channel) == null || f.on("bufferedamountlow", this.startSendingFiles); }); - this.channel = new ut({ - endpointId: t, + this.channel = new fe({ + endpointId: e, flottformApi: n, - rtcConfiguration: i, - pollTimeForIceInMs: s, - logger: a - }), this.inputField = e, this.logger = a, this.registerListeners(); + rtcConfiguration: s, + encryptionKey: i, + pollTimeForIceInMs: a, + logger: c + }), this.inputField = t, this.logger = c, this.registerListeners(); } } -class hn extends V { +class Sn extends G { constructor({ - endpointId: t, - flottformApi: e, - rtcConfiguration: n = j, - pollTimeForIceInMs: i = J, - logger: s = console + endpointId: e, + flottformApi: t, + encryptionKey: n, + rtcConfiguration: i = Q, + pollTimeForIceInMs: s = J, + logger: a = console }) { super(); u(this, "channel", null); u(this, "logger"); u(this, "start", () => { - var t; - (t = this.channel) == null || t.start(); + var e; + (e = this.channel) == null || e.start(); }); u(this, "close", () => { - var t; - (t = this.channel) == null || t.close(); - }); - u(this, "sendText", (t) => { var e; - this.emit("sending"), (e = this.channel) == null || e.sendData(t), this.emit("done"); + (e = this.channel) == null || e.close(); + }); + u(this, "sendText", (e) => { + var t; + this.emit("sending"), (t = this.channel) == null || t.sendData(e), this.emit("done"); }); u(this, "registerListeners", () => { - var t, e, n, i, s, a, c, l, h; - (t = this.channel) == null || t.on("init", () => { - }), (e = this.channel) == null || e.on("retrieving-info-from-endpoint", () => { + var e, t, n, i, s, a, c, l, h; + (e = this.channel) == null || e.on("init", () => { + }), (t = this.channel) == null || t.on("retrieving-info-from-endpoint", () => { }), (n = this.channel) == null || n.on("sending-client-info", () => { }), (i = this.channel) == null || i.on("connecting-to-host", () => { }), (s = this.channel) == null || s.on("connected", () => { @@ -2139,21 +2252,22 @@ class hn extends V { this.emit("error", f); }); }); - this.channel = new ut({ - endpointId: t, - flottformApi: e, - rtcConfiguration: n, - pollTimeForIceInMs: i, - logger: s - }), this.logger = s, this.registerListeners(); + this.channel = new fe({ + endpointId: e, + flottformApi: t, + rtcConfiguration: i, + encryptionKey: n, + pollTimeForIceInMs: s, + logger: a + }), this.logger = a, this.registerListeners(); } } -class $t extends ct { +class Qe extends ue { constructor({ - flottformApi: t, - createClientUrl: e, + flottformApi: e, + createClientUrl: t, inputField: n = void 0, - rtcConfiguration: i = j, + rtcConfiguration: i = Q, pollTimeForIceInMs: s = J, logger: a = console }) { @@ -2164,12 +2278,12 @@ class $t extends ct { u(this, "qrCode", ""); u(this, "inputField"); u(this, "start", () => { - var t; - (t = this.channel) == null || t.start(); + var e; + (e = this.channel) == null || e.start(); }); u(this, "close", () => { - var t; - (t = this.channel) == null || t.close(); + var e; + (e = this.channel) == null || e.close(); }); u(this, "getLink", () => (this.link === "" && this.logger.error( "Flottform is currently establishing the connection. Link is unavailable for now!" @@ -2177,18 +2291,18 @@ class $t extends ct { u(this, "getQrCode", () => (this.qrCode === "" && this.logger.error( "Flottform is currently establishing the connection. qrCode is unavailable for now!" ), this.qrCode)); - u(this, "handleIncomingData", (t) => { - if (this.emit("receive"), this.emit("done", t.data), this.inputField) { - this.inputField.value = t.data; - const e = new Event("change"); - this.inputField.dispatchEvent(e); + u(this, "handleIncomingData", (e) => { + if (this.emit("receive"), this.emit("done", e.data), this.inputField) { + this.inputField.value = e.data; + const t = new Event("change"); + this.inputField.dispatchEvent(t); } }); u(this, "registerListeners", () => { - var t, e, n, i, s, a, c; - (t = this.channel) == null || t.on("new", () => { + var e, t, n, i, s, a, c; + (e = this.channel) == null || e.on("new", () => { this.emit("new"); - }), (e = this.channel) == null || e.on("waiting-for-client", (l) => { + }), (t = this.channel) == null || t.on("waiting-for-client", (l) => { this.emit("webrtc:waiting-for-client", l); const { qrCode: h, link: f } = l; this.emit("endpoint-created", { link: f, qrCode: h }), this.link = f, this.qrCode = h; @@ -2204,46 +2318,46 @@ class $t extends ct { this.emit("error", l); }); }); - this.channel = new lt({ - flottformApi: t, - createClientUrl: e, + this.channel = new he({ + flottformApi: e, + createClientUrl: t, rtcConfiguration: i, pollTimeForIceInMs: s, logger: a }), this.logger = a, this.inputField = n, this.registerListeners(); } } -const Ht = () => { - const r = document.querySelector( +const We = () => { + const o = document.querySelector( ".flottform-elements-container-wrapper" - ), o = document.querySelector(".flottform-opener-triangle"); - r.classList.toggle("flottform-open"), o.classList.toggle("flottform-button-svg-open"); -}, xt = (r, o, t) => { - const e = document.createElement("div"); - e.setAttribute("class", `flottform-root${t ?? ""}`); - const n = Kt(r); - e.appendChild(n); - const i = Gt(o); - return e.appendChild(i), e; -}, Ot = (r, o) => { - const t = document.createElement("img"); - t.setAttribute("class", "flottform-qr-code"), t.setAttribute("src", r); - const e = document.createElement("div"); - return e.setAttribute("class", "flottform-link-offer"), e.innerText = o, { - createChannelQrCode: t, - createChannelLinkWithOffer: e + ), r = document.querySelector(".flottform-opener-triangle"); + o.classList.toggle("flottform-open"), r.classList.toggle("flottform-button-svg-open"); +}, Ze = (o, r, e) => { + const t = document.createElement("div"); + t.setAttribute("class", `flottform-root${e ?? ""}`); + const n = nn(o); + t.appendChild(n); + const i = on(r); + return t.appendChild(i), t; +}, Xe = (o, r) => { + const e = document.createElement("img"); + e.setAttribute("class", "flottform-qr-code"), e.setAttribute("src", o); + const t = document.createElement("div"); + return t.setAttribute("class", "flottform-link-offer"), t.innerText = r, { + createChannelQrCode: e, + createChannelLinkWithOffer: t }; -}, fn = ({ - flottformAnchorElement: r, - flottformRootElement: o, - additionalComponentClass: t, - flottformRootTitle: e, +}, En = ({ + flottformAnchorElement: o, + flottformRootElement: r, + additionalComponentClass: e, + flottformRootTitle: t, flottformRootDescription: n }) => { - const i = o ?? document.querySelector(".flottform-root") ?? xt(e, n, t), s = i.querySelector(".flottform-elements-container"), a = i.querySelector( + const i = r ?? document.querySelector(".flottform-root") ?? Ze(t, n, e), s = i.querySelector(".flottform-elements-container"), a = i.querySelector( ".flottform-elements-container-wrapper" ); - return a.appendChild(s), i.appendChild(a), r.appendChild(i), { + return a.appendChild(s), i.appendChild(a), o.appendChild(i), { flottformRoot: i, getAllFlottformItems: () => { const c = i.querySelector(".flottform-inputs-list"); @@ -2256,32 +2370,32 @@ const Ht = () => { id: f, additionalItemClasses: g, label: d, - buttonLabel: T, + buttonLabel: A, onErrorText: I, onSuccessText: L }) => { - const y = new _t({ + const w = new Ye({ flottformApi: c, createClientUrl: l, inputField: h }), { flottformItem: B, - statusInformation: P, + statusInformation: T, refreshChannelButton: b, flottformStateItemsContainer: M - } = nt({ - flottformBaseInputHost: y, + } = oe({ + flottformBaseInputHost: w, additionalItemClasses: g, label: d, - buttonLabel: T, + buttonLabel: A, onErrorText: I }), p = i.querySelector(".flottform-inputs-list"); - p.appendChild(B), s.appendChild(p), Jt({ + p.appendChild(B), s.appendChild(p), tn({ flottformItem: B, - statusInformation: P, + statusInformation: T, refreshChannelButton: b, flottformStateItemsContainer: M, - flottformFileInputHost: y, + flottformFileInputHost: w, id: f, onSuccessText: L }); @@ -2293,208 +2407,208 @@ const Ht = () => { id: f, additionalItemClasses: g, label: d, - buttonLabel: T, + buttonLabel: A, onErrorText: I, onSuccessText: L }) => { - const y = new $t({ + const w = new Qe({ flottformApi: c, createClientUrl: l, inputField: h - }), { flottformItem: B, statusInformation: P, refreshChannelButton: b } = nt({ - flottformBaseInputHost: y, + }), { flottformItem: B, statusInformation: T, refreshChannelButton: b } = oe({ + flottformBaseInputHost: w, additionalItemClasses: g, label: d, - buttonLabel: T, + buttonLabel: A, onErrorText: I }), M = i.querySelector(".flottform-inputs-list"); - M.appendChild(B), s.appendChild(M), Vt({ + M.appendChild(B), s.appendChild(M), en({ flottformItem: B, - statusInformation: P, + statusInformation: T, refreshChannelButton: b, - flottformTextInputHost: y, + flottformTextInputHost: w, id: f, onSuccessText: L }); } }; -}, nt = ({ - flottformBaseInputHost: r, - additionalItemClasses: o, - label: t, - buttonLabel: e, +}, oe = ({ + flottformBaseInputHost: o, + additionalItemClasses: r, + label: e, + buttonLabel: t, onErrorText: n }) => { - const i = jt(o); - en({ label: t, flottformItem: i }); - const s = Yt(), a = Wt(e); - a.addEventListener("click", () => r.start()); - const c = Qt(a); + const i = rn(r); + hn({ label: e, flottformItem: i }); + const s = sn(), a = cn(t); + a.addEventListener("click", () => o.start()); + const c = an(a); i.appendChild(c); - const l = Zt(); - return l.addEventListener("click", () => r.start()), r.on("endpoint-created", ({ link: h, qrCode: f }) => { - const { createChannelQrCode: g, createChannelLinkWithOffer: d } = Ot(f, h), T = tn(); + const l = ln(); + return l.addEventListener("click", () => o.start()), o.on("endpoint-created", ({ link: h, qrCode: f }) => { + const { createChannelQrCode: g, createChannelLinkWithOffer: d } = Xe(f, h), A = fn(); c.replaceChildren(g); const I = document.createElement("div"); - I.setAttribute("class", "flottform-copy-button-link-wrapper"), I.appendChild(T), I.appendChild(d), c.appendChild(I); - }), r.on("connected", () => { + I.setAttribute("class", "flottform-copy-button-link-wrapper"), I.appendChild(A), I.appendChild(d), c.appendChild(I); + }), o.on("connected", () => { s.innerHTML = "Connected", s.appendChild(l), c.replaceChildren(s); - }), r.on("error", (h) => { + }), o.on("error", (h) => { s.innerHTML = typeof n == "function" ? n(h) : n ?? `🚨 An error occured (${h.message}). Please try again`, a.innerText = "Retry", c.replaceChildren(s), c.appendChild(a); }), { flottformItem: i, statusInformation: s, refreshChannelButton: l, flottformStateItemsContainer: c }; -}, Jt = ({ - flottformItem: r, - statusInformation: o, - refreshChannelButton: t, - flottformStateItemsContainer: e, +}, tn = ({ + flottformItem: o, + statusInformation: r, + refreshChannelButton: e, + flottformStateItemsContainer: t, flottformFileInputHost: n, id: i, onSuccessText: s }) => { - i && r.setAttribute("id", i), n.on( + i && o.setAttribute("id", i), n.on( "progress", ({ currentFileProgress: a, overallProgress: c, fileIndex: l, totalFileCount: h, fileName: f }) => { - nn(e), cn( - e, + dn(t), yn( + t, c, l, h ); - const g = on(e); - sn( + const g = gn(t); + mn( l, f, a, g, - e + t ); } ), n.on("done", () => { - o.innerHTML = s ?? "✨ You have succesfully downloaded all your files.", o.appendChild(t), e.replaceChildren(o); + r.innerHTML = s ?? "✨ You have succesfully downloaded all your files.", r.appendChild(e), t.replaceChildren(r); }); -}, Vt = ({ - flottformItem: r, - statusInformation: o, - refreshChannelButton: t, - flottformTextInputHost: e, +}, en = ({ + flottformItem: o, + statusInformation: r, + refreshChannelButton: e, + flottformTextInputHost: t, id: n, onSuccessText: i }) => { - n && r.setAttribute("id", n), e.on("done", (s) => { - if (o.innerHTML = i ?? "✨ You have succesfully submitted your message", o.appendChild(t), r.replaceChildren(o), inputField) { + n && o.setAttribute("id", n), t.on("done", (s) => { + if (r.innerHTML = i ?? "✨ You have succesfully submitted your message", r.appendChild(e), o.replaceChildren(r), inputField) { inputField.setAttribute("value", s); const a = new Event("change"); inputField.dispatchEvent(a); } }); -}, Kt = (r) => { - const o = document.createElement("button"); - return o.setAttribute("type", "button"), o.setAttribute("class", "flottform-root-opener-button"), o.innerHTML = `${r ?? "Fill from Another Device"}`, o.addEventListener("click", () => Ht()), o; -}, Gt = (r) => { - const o = document.createElement("div"); - o.setAttribute("class", "flottform-elements-container"); - const t = document.createElement("div"); - if (t.setAttribute("class", "flottform-elements-container-wrapper"), r !== "") { +}, nn = (o) => { + const r = document.createElement("button"); + return r.setAttribute("type", "button"), r.setAttribute("class", "flottform-root-opener-button"), r.innerHTML = `${o ?? "Fill from Another Device"}`, r.addEventListener("click", () => We()), r; +}, on = (o) => { + const r = document.createElement("div"); + r.setAttribute("class", "flottform-elements-container"); + const e = document.createElement("div"); + if (e.setAttribute("class", "flottform-elements-container-wrapper"), o !== "") { const n = document.createElement("div"); - n.setAttribute("class", "flottform-root-description"), n.innerText = r ?? "This form is powered by Flottform. Need to add details from another device? Simply click a button below to generate a QR code or link, and easily upload information from your other device.", o.appendChild(n); + n.setAttribute("class", "flottform-root-description"), n.innerText = o ?? "This form is powered by Flottform. Need to add details from another device? Simply click a button below to generate a QR code or link, and easily upload information from your other device.", r.appendChild(n); } - const e = document.createElement("ul"); - return e.setAttribute("class", "flottform-inputs-list"), o.appendChild(e), t.appendChild(o), t; -}, jt = (r) => { - const o = document.createElement("li"); - return o.setAttribute("class", `flottform-item${r ?? ""}`), o; -}, Yt = () => { - const r = document.createElement("div"); - return r.setAttribute("class", "flottform-status-information"), r; -}, Qt = (r) => { + const t = document.createElement("ul"); + return t.setAttribute("class", "flottform-inputs-list"), r.appendChild(t), e.appendChild(r), e; +}, rn = (o) => { + const r = document.createElement("li"); + return r.setAttribute("class", `flottform-item${o ?? ""}`), r; +}, sn = () => { const o = document.createElement("div"); - return o.setAttribute("class", "flottform-state-items-container"), o.appendChild(r), o; -}, Wt = (r) => { - const o = document.createElement("button"); - return o.setAttribute("type", "button"), o.setAttribute("class", "flottform-button"), o.innerText = r ?? "Get a link", o; -}, Zt = () => { + return o.setAttribute("class", "flottform-status-information"), o; +}, an = (o) => { + const r = document.createElement("div"); + return r.setAttribute("class", "flottform-state-items-container"), r.appendChild(o), r; +}, cn = (o) => { const r = document.createElement("button"); - return r.setAttribute("type", "button"), r.setAttribute("class", "flottform-refresh-connection-button"), r.setAttribute( + return r.setAttribute("type", "button"), r.setAttribute("class", "flottform-button"), r.innerText = o ?? "Get a link", r; +}, ln = () => { + const o = document.createElement("button"); + return o.setAttribute("type", "button"), o.setAttribute("class", "flottform-refresh-connection-button"), o.setAttribute( "title", "Click this button to refresh Flottform connection for the input field. Previous connection will be closed" - ), r.setAttribute( + ), o.setAttribute( "aria-label", "Click this button to refresh Flottform connection for the input field. Previous connection will be closed" - ), r.innerHTML = '', r; + ), o.innerHTML = '', o; }; -let Xt = 1; -const en = ({ - label: r, - flottformItem: o +let un = 1; +const hn = ({ + label: o, + flottformItem: r }) => { - const t = document.createElement("p"), e = r ?? `File input ${Xt++}`; - e && (t.innerHTML = e, o.appendChild(t)); -}, tn = () => { - const r = document.createElement("button"); - return r.setAttribute("class", "flottform-copy-to-clipboard"), r.setAttribute("type", "button"), r.setAttribute("title", "Copy Flottform link to clipboard"), r.setAttribute("aria-label", "Copy Flottform link to clipboard"), r.innerText = "📋", r.addEventListener("click", async () => { - const o = document.querySelector(".flottform-link-offer").innerText; - navigator.clipboard.writeText(o).then(() => { - r.innerText = "✅", setTimeout(() => { - r.innerText = "📋"; + const e = document.createElement("p"), t = o ?? `File input ${un++}`; + t && (e.innerHTML = t, r.appendChild(e)); +}, fn = () => { + const o = document.createElement("button"); + return o.setAttribute("class", "flottform-copy-to-clipboard"), o.setAttribute("type", "button"), o.setAttribute("title", "Copy Flottform link to clipboard"), o.setAttribute("aria-label", "Copy Flottform link to clipboard"), o.innerText = "📋", o.addEventListener("click", async () => { + const r = document.querySelector(".flottform-link-offer").innerText; + navigator.clipboard.writeText(r).then(() => { + o.innerText = "✅", setTimeout(() => { + o.innerText = "📋"; }, 1e3); - }).catch((t) => { - r.innerText = `❌ Failed to copy: ${t}`, setTimeout(() => { - r.innerText = "📋"; + }).catch((e) => { + o.innerText = `❌ Failed to copy: ${e}`, setTimeout(() => { + o.innerText = "📋"; }, 1e3); }); - }), r; -}, nn = (r) => { - r.querySelector( + }), o; +}, dn = (o) => { + o.querySelector( ".flottform-status-information" - ) && (r.innerHTML = ""); -}, on = (r) => { - let o = r.querySelector("details"); - if (!o) { - o = document.createElement("details"); - const t = document.createElement("summary"); - t.innerText = "Details", o.appendChild(t); - const e = document.createElement("div"); - e.classList.add("details-container"), o.appendChild(e), r.appendChild(o); + ) && (o.innerHTML = ""); +}, gn = (o) => { + let r = o.querySelector("details"); + if (!r) { + r = document.createElement("details"); + const e = document.createElement("summary"); + e.innerText = "Details", r.appendChild(e); + const t = document.createElement("div"); + t.classList.add("details-container"), r.appendChild(t), o.appendChild(r); } - return o; -}, rn = (r, o) => { - const t = document.createElement("label"); - t.setAttribute("id", `flottform-status-bar-${r}`), t.classList.add("flottform-progress-bar-label"), t.innerText = `File ${o} progress:`; - const e = document.createElement("progress"); - return e.setAttribute("id", `flottform-status-bar-${r}`), e.classList.add("flottform-status-bar"), e.setAttribute("max", "100"), e.setAttribute("value", "0"), { currentFileLabel: t, progressBar: e }; -}, sn = (r, o, t, e, n) => { + return r; +}, pn = (o, r) => { + const e = document.createElement("label"); + e.setAttribute("id", `flottform-status-bar-${o}`), e.classList.add("flottform-progress-bar-label"), e.innerText = `File ${r} progress:`; + const t = document.createElement("progress"); + return t.setAttribute("id", `flottform-status-bar-${o}`), t.classList.add("flottform-status-bar"), t.setAttribute("max", "100"), t.setAttribute("value", "0"), { currentFileLabel: e, progressBar: t }; +}, mn = (o, r, e, t, n) => { let i = n.querySelector( - `progress#flottform-status-bar-${r}` + `progress#flottform-status-bar-${o}` ); if (!i) { - const { currentFileLabel: s, progressBar: a } = rn(r, o); + const { currentFileLabel: s, progressBar: a } = pn(o, r); i = a; - const c = e.querySelector(".details-container"); + const c = t.querySelector(".details-container"); c.appendChild(s), c.appendChild(i); } - i.value = t * 100, i.innerText = `${t * 100}%`; -}, an = () => { - const r = document.createElement("label"); - r.setAttribute("id", "flottform-status-bar-overall-progress"), r.classList.add("flottform-progress-bar-label"), r.innerText = "Receiving Files Progress"; - const o = document.createElement("progress"); - return o.setAttribute("id", "flottform-status-bar-overall-progress"), o.classList.add("flottform-status-bar"), o.setAttribute("max", "100"), o.setAttribute("value", "0"), { overallFilesLabel: r, progressBar: o }; -}, cn = (r, o, t, e) => { - let n = r.querySelector("progress#flottform-status-bar-overall-progress"); + i.value = e * 100, i.innerText = `${e * 100}%`; +}, Cn = () => { + const o = document.createElement("label"); + o.setAttribute("id", "flottform-status-bar-overall-progress"), o.classList.add("flottform-progress-bar-label"), o.innerText = "Receiving Files Progress"; + const r = document.createElement("progress"); + return r.setAttribute("id", "flottform-status-bar-overall-progress"), r.classList.add("flottform-status-bar"), r.setAttribute("max", "100"), r.setAttribute("value", "0"), { overallFilesLabel: o, progressBar: r }; +}, yn = (o, r, e, t) => { + let n = o.querySelector("progress#flottform-status-bar-overall-progress"); if (!n) { - const { overallFilesLabel: s, progressBar: a } = an(); - n = a, r.appendChild(s), r.appendChild(n); + const { overallFilesLabel: s, progressBar: a } = Cn(); + n = a, o.appendChild(s), o.appendChild(n); } - const i = r.querySelector( + const i = o.querySelector( "label#flottform-status-bar-overall-progress" ); - n.value = o * 100, n.innerText = `${o * 100}%`, i.innerText = `Receiving file ${t + 1} of ${e}`; + n.value = r * 100, n.innerText = `${r * 100}%`, i.innerText = `Receiving file ${e + 1} of ${t}`; }; export { - Ae as ConnectionManager, - un as FlottformFileInputClient, - _t as FlottformFileInputHost, - hn as FlottformTextInputClient, - $t as FlottformTextInputHost, - fn as createDefaultFlottformComponent + vt as ConnectionManager, + bn as FlottformFileInputClient, + Ye as FlottformFileInputHost, + Sn as FlottformTextInputClient, + Qe as FlottformTextInputHost, + En as createDefaultFlottformComponent }; //# sourceMappingURL=flottform-bundle.js.map diff --git a/servers/chrome-extension/static/scripts/flottform-bundle.js.map b/servers/chrome-extension/static/scripts/flottform-bundle.js.map index a6e23e1..da11e0f 100644 --- a/servers/chrome-extension/static/scripts/flottform-bundle.js.map +++ b/servers/chrome-extension/static/scripts/flottform-bundle.js.map @@ -1 +1 @@ -{"version":3,"file":"flottform-bundle.js","sources":["../../src/connection-manager.ts","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/can-promise.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-level.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-buffer.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-matrix.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alignment-pattern.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/finder-pattern.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mask-pattern.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-code.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/galois-field.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/polynomial.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/reed-solomon-encoder.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version-check.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/regex.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/format-info.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/numeric-data.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alphanumeric-data.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/byte-data.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/kanji-data.js","../../../../node_modules/.pnpm/dijkstrajs@1.0.3/node_modules/dijkstrajs/dijkstra.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/segments.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/qrcode.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utils.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/canvas.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg-tag.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/browser.js","../../src/internal.ts","../../src/flottform-channel-host.ts","../../src/flottform-file-input-host.ts","../../src/flottform-channel-client.ts","../../src/flottform-file-input-client.ts","../../src/flottform-text-input-client.ts","../../src/flottform-text-input-host.ts","../../src/default-component.ts"],"sourcesContent":["import { FlottformFileInputHost } from './flottform-file-input-host';\nimport { FlottformTextInputHost } from './flottform-text-input-host';\n\nexport class ConnectionManager {\n\tprivate static instance: ConnectionManager;\n\tprivate activeConnections: Map;\n\n\tprivate constructor() {\n\t\tthis.activeConnections = new Map();\n\t}\n\n\tpublic static getInstance(): ConnectionManager {\n\t\tif (!ConnectionManager.instance) {\n\t\t\tConnectionManager.instance = new ConnectionManager();\n\t\t}\n\t\treturn ConnectionManager.instance;\n\t}\n\n\tpublic addConnection(key: string, connection: FlottformFileInputHost | FlottformTextInputHost) {\n\t\tthis.activeConnections.set(key, connection);\n\t}\n\n\tpublic getConnection(key: string) {\n\t\treturn this.activeConnections.get(key);\n\t}\n\n\tpublic closeAllConnections() {\n\t\tthis.activeConnections.forEach((connection) => {\n\t\t\tconnection.close();\n\t\t});\n\t\t//this.activeConnections.clear();\n\t}\n\n\tpublic removeConnection(key: string) {\n\t\tthis.activeConnections.delete(key);\n\t}\n}\n","// can-promise has a crash in some versions of react native that dont have\n// standard global objects\n// https://github.com/soldair/node-qrcode/issues/157\n\nmodule.exports = function () {\n return typeof Promise === 'function' && Promise.prototype && Promise.prototype.then\n}\n","let toSJISFunction\nconst CODEWORDS_COUNT = [\n 0, // Not used\n 26, 44, 70, 100, 134, 172, 196, 242, 292, 346,\n 404, 466, 532, 581, 655, 733, 815, 901, 991, 1085,\n 1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185,\n 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706\n]\n\n/**\n * Returns the QR Code size for the specified version\n *\n * @param {Number} version QR Code version\n * @return {Number} size of QR code\n */\nexports.getSymbolSize = function getSymbolSize (version) {\n if (!version) throw new Error('\"version\" cannot be null or undefined')\n if (version < 1 || version > 40) throw new Error('\"version\" should be in range from 1 to 40')\n return version * 4 + 17\n}\n\n/**\n * Returns the total number of codewords used to store data and EC information.\n *\n * @param {Number} version QR Code version\n * @return {Number} Data length in bits\n */\nexports.getSymbolTotalCodewords = function getSymbolTotalCodewords (version) {\n return CODEWORDS_COUNT[version]\n}\n\n/**\n * Encode data with Bose-Chaudhuri-Hocquenghem\n *\n * @param {Number} data Value to encode\n * @return {Number} Encoded value\n */\nexports.getBCHDigit = function (data) {\n let digit = 0\n\n while (data !== 0) {\n digit++\n data >>>= 1\n }\n\n return digit\n}\n\nexports.setToSJISFunction = function setToSJISFunction (f) {\n if (typeof f !== 'function') {\n throw new Error('\"toSJISFunc\" is not a valid function.')\n }\n\n toSJISFunction = f\n}\n\nexports.isKanjiModeEnabled = function () {\n return typeof toSJISFunction !== 'undefined'\n}\n\nexports.toSJIS = function toSJIS (kanji) {\n return toSJISFunction(kanji)\n}\n","exports.L = { bit: 1 }\nexports.M = { bit: 0 }\nexports.Q = { bit: 3 }\nexports.H = { bit: 2 }\n\nfunction fromString (string) {\n if (typeof string !== 'string') {\n throw new Error('Param is not a string')\n }\n\n const lcStr = string.toLowerCase()\n\n switch (lcStr) {\n case 'l':\n case 'low':\n return exports.L\n\n case 'm':\n case 'medium':\n return exports.M\n\n case 'q':\n case 'quartile':\n return exports.Q\n\n case 'h':\n case 'high':\n return exports.H\n\n default:\n throw new Error('Unknown EC Level: ' + string)\n }\n}\n\nexports.isValid = function isValid (level) {\n return level && typeof level.bit !== 'undefined' &&\n level.bit >= 0 && level.bit < 4\n}\n\nexports.from = function from (value, defaultValue) {\n if (exports.isValid(value)) {\n return value\n }\n\n try {\n return fromString(value)\n } catch (e) {\n return defaultValue\n }\n}\n","function BitBuffer () {\n this.buffer = []\n this.length = 0\n}\n\nBitBuffer.prototype = {\n\n get: function (index) {\n const bufIndex = Math.floor(index / 8)\n return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) === 1\n },\n\n put: function (num, length) {\n for (let i = 0; i < length; i++) {\n this.putBit(((num >>> (length - i - 1)) & 1) === 1)\n }\n },\n\n getLengthInBits: function () {\n return this.length\n },\n\n putBit: function (bit) {\n const bufIndex = Math.floor(this.length / 8)\n if (this.buffer.length <= bufIndex) {\n this.buffer.push(0)\n }\n\n if (bit) {\n this.buffer[bufIndex] |= (0x80 >>> (this.length % 8))\n }\n\n this.length++\n }\n}\n\nmodule.exports = BitBuffer\n","/**\n * Helper class to handle QR Code symbol modules\n *\n * @param {Number} size Symbol size\n */\nfunction BitMatrix (size) {\n if (!size || size < 1) {\n throw new Error('BitMatrix size must be defined and greater than 0')\n }\n\n this.size = size\n this.data = new Uint8Array(size * size)\n this.reservedBit = new Uint8Array(size * size)\n}\n\n/**\n * Set bit value at specified location\n * If reserved flag is set, this bit will be ignored during masking process\n *\n * @param {Number} row\n * @param {Number} col\n * @param {Boolean} value\n * @param {Boolean} reserved\n */\nBitMatrix.prototype.set = function (row, col, value, reserved) {\n const index = row * this.size + col\n this.data[index] = value\n if (reserved) this.reservedBit[index] = true\n}\n\n/**\n * Returns bit value at specified location\n *\n * @param {Number} row\n * @param {Number} col\n * @return {Boolean}\n */\nBitMatrix.prototype.get = function (row, col) {\n return this.data[row * this.size + col]\n}\n\n/**\n * Applies xor operator at specified location\n * (used during masking process)\n *\n * @param {Number} row\n * @param {Number} col\n * @param {Boolean} value\n */\nBitMatrix.prototype.xor = function (row, col, value) {\n this.data[row * this.size + col] ^= value\n}\n\n/**\n * Check if bit at specified location is reserved\n *\n * @param {Number} row\n * @param {Number} col\n * @return {Boolean}\n */\nBitMatrix.prototype.isReserved = function (row, col) {\n return this.reservedBit[row * this.size + col]\n}\n\nmodule.exports = BitMatrix\n","/**\n * Alignment pattern are fixed reference pattern in defined positions\n * in a matrix symbology, which enables the decode software to re-synchronise\n * the coordinate mapping of the image modules in the event of moderate amounts\n * of distortion of the image.\n *\n * Alignment patterns are present only in QR Code symbols of version 2 or larger\n * and their number depends on the symbol version.\n */\n\nconst getSymbolSize = require('./utils').getSymbolSize\n\n/**\n * Calculate the row/column coordinates of the center module of each alignment pattern\n * for the specified QR Code version.\n *\n * The alignment patterns are positioned symmetrically on either side of the diagonal\n * running from the top left corner of the symbol to the bottom right corner.\n *\n * Since positions are simmetrical only half of the coordinates are returned.\n * Each item of the array will represent in turn the x and y coordinate.\n * @see {@link getPositions}\n *\n * @param {Number} version QR Code version\n * @return {Array} Array of coordinate\n */\nexports.getRowColCoords = function getRowColCoords (version) {\n if (version === 1) return []\n\n const posCount = Math.floor(version / 7) + 2\n const size = getSymbolSize(version)\n const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2\n const positions = [size - 7] // Last coord is always (size - 7)\n\n for (let i = 1; i < posCount - 1; i++) {\n positions[i] = positions[i - 1] - intervals\n }\n\n positions.push(6) // First coord is always 6\n\n return positions.reverse()\n}\n\n/**\n * Returns an array containing the positions of each alignment pattern.\n * Each array's element represent the center point of the pattern as (x, y) coordinates\n *\n * Coordinates are calculated expanding the row/column coordinates returned by {@link getRowColCoords}\n * and filtering out the items that overlaps with finder pattern\n *\n * @example\n * For a Version 7 symbol {@link getRowColCoords} returns values 6, 22 and 38.\n * The alignment patterns, therefore, are to be centered on (row, column)\n * positions (6,22), (22,6), (22,22), (22,38), (38,22), (38,38).\n * Note that the coordinates (6,6), (6,38), (38,6) are occupied by finder patterns\n * and are not therefore used for alignment patterns.\n *\n * let pos = getPositions(7)\n * // [[6,22], [22,6], [22,22], [22,38], [38,22], [38,38]]\n *\n * @param {Number} version QR Code version\n * @return {Array} Array of coordinates\n */\nexports.getPositions = function getPositions (version) {\n const coords = []\n const pos = exports.getRowColCoords(version)\n const posLength = pos.length\n\n for (let i = 0; i < posLength; i++) {\n for (let j = 0; j < posLength; j++) {\n // Skip if position is occupied by finder patterns\n if ((i === 0 && j === 0) || // top-left\n (i === 0 && j === posLength - 1) || // bottom-left\n (i === posLength - 1 && j === 0)) { // top-right\n continue\n }\n\n coords.push([pos[i], pos[j]])\n }\n }\n\n return coords\n}\n","const getSymbolSize = require('./utils').getSymbolSize\nconst FINDER_PATTERN_SIZE = 7\n\n/**\n * Returns an array containing the positions of each finder pattern.\n * Each array's element represent the top-left point of the pattern as (x, y) coordinates\n *\n * @param {Number} version QR Code version\n * @return {Array} Array of coordinates\n */\nexports.getPositions = function getPositions (version) {\n const size = getSymbolSize(version)\n\n return [\n // top-left\n [0, 0],\n // top-right\n [size - FINDER_PATTERN_SIZE, 0],\n // bottom-left\n [0, size - FINDER_PATTERN_SIZE]\n ]\n}\n","/**\n * Data mask pattern reference\n * @type {Object}\n */\nexports.Patterns = {\n PATTERN000: 0,\n PATTERN001: 1,\n PATTERN010: 2,\n PATTERN011: 3,\n PATTERN100: 4,\n PATTERN101: 5,\n PATTERN110: 6,\n PATTERN111: 7\n}\n\n/**\n * Weighted penalty scores for the undesirable features\n * @type {Object}\n */\nconst PenaltyScores = {\n N1: 3,\n N2: 3,\n N3: 40,\n N4: 10\n}\n\n/**\n * Check if mask pattern value is valid\n *\n * @param {Number} mask Mask pattern\n * @return {Boolean} true if valid, false otherwise\n */\nexports.isValid = function isValid (mask) {\n return mask != null && mask !== '' && !isNaN(mask) && mask >= 0 && mask <= 7\n}\n\n/**\n * Returns mask pattern from a value.\n * If value is not valid, returns undefined\n *\n * @param {Number|String} value Mask pattern value\n * @return {Number} Valid mask pattern or undefined\n */\nexports.from = function from (value) {\n return exports.isValid(value) ? parseInt(value, 10) : undefined\n}\n\n/**\n* Find adjacent modules in row/column with the same color\n* and assign a penalty value.\n*\n* Points: N1 + i\n* i is the amount by which the number of adjacent modules of the same color exceeds 5\n*/\nexports.getPenaltyN1 = function getPenaltyN1 (data) {\n const size = data.size\n let points = 0\n let sameCountCol = 0\n let sameCountRow = 0\n let lastCol = null\n let lastRow = null\n\n for (let row = 0; row < size; row++) {\n sameCountCol = sameCountRow = 0\n lastCol = lastRow = null\n\n for (let col = 0; col < size; col++) {\n let module = data.get(row, col)\n if (module === lastCol) {\n sameCountCol++\n } else {\n if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5)\n lastCol = module\n sameCountCol = 1\n }\n\n module = data.get(col, row)\n if (module === lastRow) {\n sameCountRow++\n } else {\n if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5)\n lastRow = module\n sameCountRow = 1\n }\n }\n\n if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5)\n if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5)\n }\n\n return points\n}\n\n/**\n * Find 2x2 blocks with the same color and assign a penalty value\n *\n * Points: N2 * (m - 1) * (n - 1)\n */\nexports.getPenaltyN2 = function getPenaltyN2 (data) {\n const size = data.size\n let points = 0\n\n for (let row = 0; row < size - 1; row++) {\n for (let col = 0; col < size - 1; col++) {\n const last = data.get(row, col) +\n data.get(row, col + 1) +\n data.get(row + 1, col) +\n data.get(row + 1, col + 1)\n\n if (last === 4 || last === 0) points++\n }\n }\n\n return points * PenaltyScores.N2\n}\n\n/**\n * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column,\n * preceded or followed by light area 4 modules wide\n *\n * Points: N3 * number of pattern found\n */\nexports.getPenaltyN3 = function getPenaltyN3 (data) {\n const size = data.size\n let points = 0\n let bitsCol = 0\n let bitsRow = 0\n\n for (let row = 0; row < size; row++) {\n bitsCol = bitsRow = 0\n for (let col = 0; col < size; col++) {\n bitsCol = ((bitsCol << 1) & 0x7FF) | data.get(row, col)\n if (col >= 10 && (bitsCol === 0x5D0 || bitsCol === 0x05D)) points++\n\n bitsRow = ((bitsRow << 1) & 0x7FF) | data.get(col, row)\n if (col >= 10 && (bitsRow === 0x5D0 || bitsRow === 0x05D)) points++\n }\n }\n\n return points * PenaltyScores.N3\n}\n\n/**\n * Calculate proportion of dark modules in entire symbol\n *\n * Points: N4 * k\n *\n * k is the rating of the deviation of the proportion of dark modules\n * in the symbol from 50% in steps of 5%\n */\nexports.getPenaltyN4 = function getPenaltyN4 (data) {\n let darkCount = 0\n const modulesCount = data.data.length\n\n for (let i = 0; i < modulesCount; i++) darkCount += data.data[i]\n\n const k = Math.abs(Math.ceil((darkCount * 100 / modulesCount) / 5) - 10)\n\n return k * PenaltyScores.N4\n}\n\n/**\n * Return mask value at given position\n *\n * @param {Number} maskPattern Pattern reference value\n * @param {Number} i Row\n * @param {Number} j Column\n * @return {Boolean} Mask value\n */\nfunction getMaskAt (maskPattern, i, j) {\n switch (maskPattern) {\n case exports.Patterns.PATTERN000: return (i + j) % 2 === 0\n case exports.Patterns.PATTERN001: return i % 2 === 0\n case exports.Patterns.PATTERN010: return j % 3 === 0\n case exports.Patterns.PATTERN011: return (i + j) % 3 === 0\n case exports.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0\n case exports.Patterns.PATTERN101: return (i * j) % 2 + (i * j) % 3 === 0\n case exports.Patterns.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 === 0\n case exports.Patterns.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 === 0\n\n default: throw new Error('bad maskPattern:' + maskPattern)\n }\n}\n\n/**\n * Apply a mask pattern to a BitMatrix\n *\n * @param {Number} pattern Pattern reference number\n * @param {BitMatrix} data BitMatrix data\n */\nexports.applyMask = function applyMask (pattern, data) {\n const size = data.size\n\n for (let col = 0; col < size; col++) {\n for (let row = 0; row < size; row++) {\n if (data.isReserved(row, col)) continue\n data.xor(row, col, getMaskAt(pattern, row, col))\n }\n }\n}\n\n/**\n * Returns the best mask pattern for data\n *\n * @param {BitMatrix} data\n * @return {Number} Mask pattern reference number\n */\nexports.getBestMask = function getBestMask (data, setupFormatFunc) {\n const numPatterns = Object.keys(exports.Patterns).length\n let bestPattern = 0\n let lowerPenalty = Infinity\n\n for (let p = 0; p < numPatterns; p++) {\n setupFormatFunc(p)\n exports.applyMask(p, data)\n\n // Calculate penalty\n const penalty =\n exports.getPenaltyN1(data) +\n exports.getPenaltyN2(data) +\n exports.getPenaltyN3(data) +\n exports.getPenaltyN4(data)\n\n // Undo previously applied mask\n exports.applyMask(p, data)\n\n if (penalty < lowerPenalty) {\n lowerPenalty = penalty\n bestPattern = p\n }\n }\n\n return bestPattern\n}\n","const ECLevel = require('./error-correction-level')\r\n\r\nconst EC_BLOCKS_TABLE = [\r\n// L M Q H\r\n 1, 1, 1, 1,\r\n 1, 1, 1, 1,\r\n 1, 1, 2, 2,\r\n 1, 2, 2, 4,\r\n 1, 2, 4, 4,\r\n 2, 4, 4, 4,\r\n 2, 4, 6, 5,\r\n 2, 4, 6, 6,\r\n 2, 5, 8, 8,\r\n 4, 5, 8, 8,\r\n 4, 5, 8, 11,\r\n 4, 8, 10, 11,\r\n 4, 9, 12, 16,\r\n 4, 9, 16, 16,\r\n 6, 10, 12, 18,\r\n 6, 10, 17, 16,\r\n 6, 11, 16, 19,\r\n 6, 13, 18, 21,\r\n 7, 14, 21, 25,\r\n 8, 16, 20, 25,\r\n 8, 17, 23, 25,\r\n 9, 17, 23, 34,\r\n 9, 18, 25, 30,\r\n 10, 20, 27, 32,\r\n 12, 21, 29, 35,\r\n 12, 23, 34, 37,\r\n 12, 25, 34, 40,\r\n 13, 26, 35, 42,\r\n 14, 28, 38, 45,\r\n 15, 29, 40, 48,\r\n 16, 31, 43, 51,\r\n 17, 33, 45, 54,\r\n 18, 35, 48, 57,\r\n 19, 37, 51, 60,\r\n 19, 38, 53, 63,\r\n 20, 40, 56, 66,\r\n 21, 43, 59, 70,\r\n 22, 45, 62, 74,\r\n 24, 47, 65, 77,\r\n 25, 49, 68, 81\r\n]\r\n\r\nconst EC_CODEWORDS_TABLE = [\r\n// L M Q H\r\n 7, 10, 13, 17,\r\n 10, 16, 22, 28,\r\n 15, 26, 36, 44,\r\n 20, 36, 52, 64,\r\n 26, 48, 72, 88,\r\n 36, 64, 96, 112,\r\n 40, 72, 108, 130,\r\n 48, 88, 132, 156,\r\n 60, 110, 160, 192,\r\n 72, 130, 192, 224,\r\n 80, 150, 224, 264,\r\n 96, 176, 260, 308,\r\n 104, 198, 288, 352,\r\n 120, 216, 320, 384,\r\n 132, 240, 360, 432,\r\n 144, 280, 408, 480,\r\n 168, 308, 448, 532,\r\n 180, 338, 504, 588,\r\n 196, 364, 546, 650,\r\n 224, 416, 600, 700,\r\n 224, 442, 644, 750,\r\n 252, 476, 690, 816,\r\n 270, 504, 750, 900,\r\n 300, 560, 810, 960,\r\n 312, 588, 870, 1050,\r\n 336, 644, 952, 1110,\r\n 360, 700, 1020, 1200,\r\n 390, 728, 1050, 1260,\r\n 420, 784, 1140, 1350,\r\n 450, 812, 1200, 1440,\r\n 480, 868, 1290, 1530,\r\n 510, 924, 1350, 1620,\r\n 540, 980, 1440, 1710,\r\n 570, 1036, 1530, 1800,\r\n 570, 1064, 1590, 1890,\r\n 600, 1120, 1680, 1980,\r\n 630, 1204, 1770, 2100,\r\n 660, 1260, 1860, 2220,\r\n 720, 1316, 1950, 2310,\r\n 750, 1372, 2040, 2430\r\n]\r\n\r\n/**\r\n * Returns the number of error correction block that the QR Code should contain\r\n * for the specified version and error correction level.\r\n *\r\n * @param {Number} version QR Code version\r\n * @param {Number} errorCorrectionLevel Error correction level\r\n * @return {Number} Number of error correction blocks\r\n */\r\nexports.getBlocksCount = function getBlocksCount (version, errorCorrectionLevel) {\r\n switch (errorCorrectionLevel) {\r\n case ECLevel.L:\r\n return EC_BLOCKS_TABLE[(version - 1) * 4 + 0]\r\n case ECLevel.M:\r\n return EC_BLOCKS_TABLE[(version - 1) * 4 + 1]\r\n case ECLevel.Q:\r\n return EC_BLOCKS_TABLE[(version - 1) * 4 + 2]\r\n case ECLevel.H:\r\n return EC_BLOCKS_TABLE[(version - 1) * 4 + 3]\r\n default:\r\n return undefined\r\n }\r\n}\r\n\r\n/**\r\n * Returns the number of error correction codewords to use for the specified\r\n * version and error correction level.\r\n *\r\n * @param {Number} version QR Code version\r\n * @param {Number} errorCorrectionLevel Error correction level\r\n * @return {Number} Number of error correction codewords\r\n */\r\nexports.getTotalCodewordsCount = function getTotalCodewordsCount (version, errorCorrectionLevel) {\r\n switch (errorCorrectionLevel) {\r\n case ECLevel.L:\r\n return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0]\r\n case ECLevel.M:\r\n return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1]\r\n case ECLevel.Q:\r\n return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2]\r\n case ECLevel.H:\r\n return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3]\r\n default:\r\n return undefined\r\n }\r\n}\r\n","const EXP_TABLE = new Uint8Array(512)\nconst LOG_TABLE = new Uint8Array(256)\n/**\n * Precompute the log and anti-log tables for faster computation later\n *\n * For each possible value in the galois field 2^8, we will pre-compute\n * the logarithm and anti-logarithm (exponential) of this value\n *\n * ref {@link https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Introduction_to_mathematical_fields}\n */\n;(function initTables () {\n let x = 1\n for (let i = 0; i < 255; i++) {\n EXP_TABLE[i] = x\n LOG_TABLE[x] = i\n\n x <<= 1 // multiply by 2\n\n // The QR code specification says to use byte-wise modulo 100011101 arithmetic.\n // This means that when a number is 256 or larger, it should be XORed with 0x11D.\n if (x & 0x100) { // similar to x >= 256, but a lot faster (because 0x100 == 256)\n x ^= 0x11D\n }\n }\n\n // Optimization: double the size of the anti-log table so that we don't need to mod 255 to\n // stay inside the bounds (because we will mainly use this table for the multiplication of\n // two GF numbers, no more).\n // @see {@link mul}\n for (let i = 255; i < 512; i++) {\n EXP_TABLE[i] = EXP_TABLE[i - 255]\n }\n}())\n\n/**\n * Returns log value of n inside Galois Field\n *\n * @param {Number} n\n * @return {Number}\n */\nexports.log = function log (n) {\n if (n < 1) throw new Error('log(' + n + ')')\n return LOG_TABLE[n]\n}\n\n/**\n * Returns anti-log value of n inside Galois Field\n *\n * @param {Number} n\n * @return {Number}\n */\nexports.exp = function exp (n) {\n return EXP_TABLE[n]\n}\n\n/**\n * Multiplies two number inside Galois Field\n *\n * @param {Number} x\n * @param {Number} y\n * @return {Number}\n */\nexports.mul = function mul (x, y) {\n if (x === 0 || y === 0) return 0\n\n // should be EXP_TABLE[(LOG_TABLE[x] + LOG_TABLE[y]) % 255] if EXP_TABLE wasn't oversized\n // @see {@link initTables}\n return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]]\n}\n","const GF = require('./galois-field')\n\n/**\n * Multiplies two polynomials inside Galois Field\n *\n * @param {Uint8Array} p1 Polynomial\n * @param {Uint8Array} p2 Polynomial\n * @return {Uint8Array} Product of p1 and p2\n */\nexports.mul = function mul (p1, p2) {\n const coeff = new Uint8Array(p1.length + p2.length - 1)\n\n for (let i = 0; i < p1.length; i++) {\n for (let j = 0; j < p2.length; j++) {\n coeff[i + j] ^= GF.mul(p1[i], p2[j])\n }\n }\n\n return coeff\n}\n\n/**\n * Calculate the remainder of polynomials division\n *\n * @param {Uint8Array} divident Polynomial\n * @param {Uint8Array} divisor Polynomial\n * @return {Uint8Array} Remainder\n */\nexports.mod = function mod (divident, divisor) {\n let result = new Uint8Array(divident)\n\n while ((result.length - divisor.length) >= 0) {\n const coeff = result[0]\n\n for (let i = 0; i < divisor.length; i++) {\n result[i] ^= GF.mul(divisor[i], coeff)\n }\n\n // remove all zeros from buffer head\n let offset = 0\n while (offset < result.length && result[offset] === 0) offset++\n result = result.slice(offset)\n }\n\n return result\n}\n\n/**\n * Generate an irreducible generator polynomial of specified degree\n * (used by Reed-Solomon encoder)\n *\n * @param {Number} degree Degree of the generator polynomial\n * @return {Uint8Array} Buffer containing polynomial coefficients\n */\nexports.generateECPolynomial = function generateECPolynomial (degree) {\n let poly = new Uint8Array([1])\n for (let i = 0; i < degree; i++) {\n poly = exports.mul(poly, new Uint8Array([1, GF.exp(i)]))\n }\n\n return poly\n}\n","const Polynomial = require('./polynomial')\n\nfunction ReedSolomonEncoder (degree) {\n this.genPoly = undefined\n this.degree = degree\n\n if (this.degree) this.initialize(this.degree)\n}\n\n/**\n * Initialize the encoder.\n * The input param should correspond to the number of error correction codewords.\n *\n * @param {Number} degree\n */\nReedSolomonEncoder.prototype.initialize = function initialize (degree) {\n // create an irreducible generator polynomial\n this.degree = degree\n this.genPoly = Polynomial.generateECPolynomial(this.degree)\n}\n\n/**\n * Encodes a chunk of data\n *\n * @param {Uint8Array} data Buffer containing input data\n * @return {Uint8Array} Buffer containing encoded data\n */\nReedSolomonEncoder.prototype.encode = function encode (data) {\n if (!this.genPoly) {\n throw new Error('Encoder not initialized')\n }\n\n // Calculate EC for this data block\n // extends data size to data+genPoly size\n const paddedData = new Uint8Array(data.length + this.degree)\n paddedData.set(data)\n\n // The error correction codewords are the remainder after dividing the data codewords\n // by a generator polynomial\n const remainder = Polynomial.mod(paddedData, this.genPoly)\n\n // return EC data blocks (last n byte, where n is the degree of genPoly)\n // If coefficients number in remainder are less than genPoly degree,\n // pad with 0s to the left to reach the needed number of coefficients\n const start = this.degree - remainder.length\n if (start > 0) {\n const buff = new Uint8Array(this.degree)\n buff.set(remainder, start)\n\n return buff\n }\n\n return remainder\n}\n\nmodule.exports = ReedSolomonEncoder\n","/**\n * Check if QR Code version is valid\n *\n * @param {Number} version QR Code version\n * @return {Boolean} true if valid version, false otherwise\n */\nexports.isValid = function isValid (version) {\n return !isNaN(version) && version >= 1 && version <= 40\n}\n","const numeric = '[0-9]+'\nconst alphanumeric = '[A-Z $%*+\\\\-./:]+'\nlet kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' +\n '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' +\n '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' +\n '[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+'\nkanji = kanji.replace(/u/g, '\\\\u')\n\nconst byte = '(?:(?![A-Z0-9 $%*+\\\\-./:]|' + kanji + ')(?:.|[\\r\\n]))+'\n\nexports.KANJI = new RegExp(kanji, 'g')\nexports.BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\\\-./:]+', 'g')\nexports.BYTE = new RegExp(byte, 'g')\nexports.NUMERIC = new RegExp(numeric, 'g')\nexports.ALPHANUMERIC = new RegExp(alphanumeric, 'g')\n\nconst TEST_KANJI = new RegExp('^' + kanji + '$')\nconst TEST_NUMERIC = new RegExp('^' + numeric + '$')\nconst TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\\\-./:]+$')\n\nexports.testKanji = function testKanji (str) {\n return TEST_KANJI.test(str)\n}\n\nexports.testNumeric = function testNumeric (str) {\n return TEST_NUMERIC.test(str)\n}\n\nexports.testAlphanumeric = function testAlphanumeric (str) {\n return TEST_ALPHANUMERIC.test(str)\n}\n","const VersionCheck = require('./version-check')\nconst Regex = require('./regex')\n\n/**\n * Numeric mode encodes data from the decimal digit set (0 - 9)\n * (byte values 30HEX to 39HEX).\n * Normally, 3 data characters are represented by 10 bits.\n *\n * @type {Object}\n */\nexports.NUMERIC = {\n id: 'Numeric',\n bit: 1 << 0,\n ccBits: [10, 12, 14]\n}\n\n/**\n * Alphanumeric mode encodes data from a set of 45 characters,\n * i.e. 10 numeric digits (0 - 9),\n * 26 alphabetic characters (A - Z),\n * and 9 symbols (SP, $, %, *, +, -, ., /, :).\n * Normally, two input characters are represented by 11 bits.\n *\n * @type {Object}\n */\nexports.ALPHANUMERIC = {\n id: 'Alphanumeric',\n bit: 1 << 1,\n ccBits: [9, 11, 13]\n}\n\n/**\n * In byte mode, data is encoded at 8 bits per character.\n *\n * @type {Object}\n */\nexports.BYTE = {\n id: 'Byte',\n bit: 1 << 2,\n ccBits: [8, 16, 16]\n}\n\n/**\n * The Kanji mode efficiently encodes Kanji characters in accordance with\n * the Shift JIS system based on JIS X 0208.\n * The Shift JIS values are shifted from the JIS X 0208 values.\n * JIS X 0208 gives details of the shift coded representation.\n * Each two-byte character value is compacted to a 13-bit binary codeword.\n *\n * @type {Object}\n */\nexports.KANJI = {\n id: 'Kanji',\n bit: 1 << 3,\n ccBits: [8, 10, 12]\n}\n\n/**\n * Mixed mode will contain a sequences of data in a combination of any of\n * the modes described above\n *\n * @type {Object}\n */\nexports.MIXED = {\n bit: -1\n}\n\n/**\n * Returns the number of bits needed to store the data length\n * according to QR Code specifications.\n *\n * @param {Mode} mode Data mode\n * @param {Number} version QR Code version\n * @return {Number} Number of bits\n */\nexports.getCharCountIndicator = function getCharCountIndicator (mode, version) {\n if (!mode.ccBits) throw new Error('Invalid mode: ' + mode)\n\n if (!VersionCheck.isValid(version)) {\n throw new Error('Invalid version: ' + version)\n }\n\n if (version >= 1 && version < 10) return mode.ccBits[0]\n else if (version < 27) return mode.ccBits[1]\n return mode.ccBits[2]\n}\n\n/**\n * Returns the most efficient mode to store the specified data\n *\n * @param {String} dataStr Input data string\n * @return {Mode} Best mode\n */\nexports.getBestModeForData = function getBestModeForData (dataStr) {\n if (Regex.testNumeric(dataStr)) return exports.NUMERIC\n else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC\n else if (Regex.testKanji(dataStr)) return exports.KANJI\n else return exports.BYTE\n}\n\n/**\n * Return mode name as string\n *\n * @param {Mode} mode Mode object\n * @returns {String} Mode name\n */\nexports.toString = function toString (mode) {\n if (mode && mode.id) return mode.id\n throw new Error('Invalid mode')\n}\n\n/**\n * Check if input param is a valid mode object\n *\n * @param {Mode} mode Mode object\n * @returns {Boolean} True if valid mode, false otherwise\n */\nexports.isValid = function isValid (mode) {\n return mode && mode.bit && mode.ccBits\n}\n\n/**\n * Get mode object from its name\n *\n * @param {String} string Mode name\n * @returns {Mode} Mode object\n */\nfunction fromString (string) {\n if (typeof string !== 'string') {\n throw new Error('Param is not a string')\n }\n\n const lcStr = string.toLowerCase()\n\n switch (lcStr) {\n case 'numeric':\n return exports.NUMERIC\n case 'alphanumeric':\n return exports.ALPHANUMERIC\n case 'kanji':\n return exports.KANJI\n case 'byte':\n return exports.BYTE\n default:\n throw new Error('Unknown mode: ' + string)\n }\n}\n\n/**\n * Returns mode from a value.\n * If value is not a valid mode, returns defaultValue\n *\n * @param {Mode|String} value Encoding mode\n * @param {Mode} defaultValue Fallback value\n * @return {Mode} Encoding mode\n */\nexports.from = function from (value, defaultValue) {\n if (exports.isValid(value)) {\n return value\n }\n\n try {\n return fromString(value)\n } catch (e) {\n return defaultValue\n }\n}\n","const Utils = require('./utils')\nconst ECCode = require('./error-correction-code')\nconst ECLevel = require('./error-correction-level')\nconst Mode = require('./mode')\nconst VersionCheck = require('./version-check')\n\n// Generator polynomial used to encode version information\nconst G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0)\nconst G18_BCH = Utils.getBCHDigit(G18)\n\nfunction getBestVersionForDataLength (mode, length, errorCorrectionLevel) {\n for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {\n if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {\n return currentVersion\n }\n }\n\n return undefined\n}\n\nfunction getReservedBitsCount (mode, version) {\n // Character count indicator + mode indicator bits\n return Mode.getCharCountIndicator(mode, version) + 4\n}\n\nfunction getTotalBitsFromDataArray (segments, version) {\n let totalBits = 0\n\n segments.forEach(function (data) {\n const reservedBits = getReservedBitsCount(data.mode, version)\n totalBits += reservedBits + data.getBitsLength()\n })\n\n return totalBits\n}\n\nfunction getBestVersionForMixedData (segments, errorCorrectionLevel) {\n for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {\n const length = getTotalBitsFromDataArray(segments, currentVersion)\n if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {\n return currentVersion\n }\n }\n\n return undefined\n}\n\n/**\n * Returns version number from a value.\n * If value is not a valid version, returns defaultValue\n *\n * @param {Number|String} value QR Code version\n * @param {Number} defaultValue Fallback value\n * @return {Number} QR Code version number\n */\nexports.from = function from (value, defaultValue) {\n if (VersionCheck.isValid(value)) {\n return parseInt(value, 10)\n }\n\n return defaultValue\n}\n\n/**\n * Returns how much data can be stored with the specified QR code version\n * and error correction level\n *\n * @param {Number} version QR Code version (1-40)\n * @param {Number} errorCorrectionLevel Error correction level\n * @param {Mode} mode Data mode\n * @return {Number} Quantity of storable data\n */\nexports.getCapacity = function getCapacity (version, errorCorrectionLevel, mode) {\n if (!VersionCheck.isValid(version)) {\n throw new Error('Invalid QR Code version')\n }\n\n // Use Byte mode as default\n if (typeof mode === 'undefined') mode = Mode.BYTE\n\n // Total codewords for this QR code version (Data + Error correction)\n const totalCodewords = Utils.getSymbolTotalCodewords(version)\n\n // Total number of error correction codewords\n const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)\n\n // Total number of data codewords\n const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8\n\n if (mode === Mode.MIXED) return dataTotalCodewordsBits\n\n const usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version)\n\n // Return max number of storable codewords\n switch (mode) {\n case Mode.NUMERIC:\n return Math.floor((usableBits / 10) * 3)\n\n case Mode.ALPHANUMERIC:\n return Math.floor((usableBits / 11) * 2)\n\n case Mode.KANJI:\n return Math.floor(usableBits / 13)\n\n case Mode.BYTE:\n default:\n return Math.floor(usableBits / 8)\n }\n}\n\n/**\n * Returns the minimum version needed to contain the amount of data\n *\n * @param {Segment} data Segment of data\n * @param {Number} [errorCorrectionLevel=H] Error correction level\n * @param {Mode} mode Data mode\n * @return {Number} QR Code version\n */\nexports.getBestVersionForData = function getBestVersionForData (data, errorCorrectionLevel) {\n let seg\n\n const ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M)\n\n if (Array.isArray(data)) {\n if (data.length > 1) {\n return getBestVersionForMixedData(data, ecl)\n }\n\n if (data.length === 0) {\n return 1\n }\n\n seg = data[0]\n } else {\n seg = data\n }\n\n return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl)\n}\n\n/**\n * Returns version information with relative error correction bits\n *\n * The version information is included in QR Code symbols of version 7 or larger.\n * It consists of an 18-bit sequence containing 6 data bits,\n * with 12 error correction bits calculated using the (18, 6) Golay code.\n *\n * @param {Number} version QR Code version\n * @return {Number} Encoded version info bits\n */\nexports.getEncodedBits = function getEncodedBits (version) {\n if (!VersionCheck.isValid(version) || version < 7) {\n throw new Error('Invalid QR Code version')\n }\n\n let d = version << 12\n\n while (Utils.getBCHDigit(d) - G18_BCH >= 0) {\n d ^= (G18 << (Utils.getBCHDigit(d) - G18_BCH))\n }\n\n return (version << 12) | d\n}\n","const Utils = require('./utils')\n\nconst G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0)\nconst G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1)\nconst G15_BCH = Utils.getBCHDigit(G15)\n\n/**\n * Returns format information with relative error correction bits\n *\n * The format information is a 15-bit sequence containing 5 data bits,\n * with 10 error correction bits calculated using the (15, 5) BCH code.\n *\n * @param {Number} errorCorrectionLevel Error correction level\n * @param {Number} mask Mask pattern\n * @return {Number} Encoded format information bits\n */\nexports.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask) {\n const data = ((errorCorrectionLevel.bit << 3) | mask)\n let d = data << 10\n\n while (Utils.getBCHDigit(d) - G15_BCH >= 0) {\n d ^= (G15 << (Utils.getBCHDigit(d) - G15_BCH))\n }\n\n // xor final data with mask pattern in order to ensure that\n // no combination of Error Correction Level and data mask pattern\n // will result in an all-zero data string\n return ((data << 10) | d) ^ G15_MASK\n}\n","const Mode = require('./mode')\n\nfunction NumericData (data) {\n this.mode = Mode.NUMERIC\n this.data = data.toString()\n}\n\nNumericData.getBitsLength = function getBitsLength (length) {\n return 10 * Math.floor(length / 3) + ((length % 3) ? ((length % 3) * 3 + 1) : 0)\n}\n\nNumericData.prototype.getLength = function getLength () {\n return this.data.length\n}\n\nNumericData.prototype.getBitsLength = function getBitsLength () {\n return NumericData.getBitsLength(this.data.length)\n}\n\nNumericData.prototype.write = function write (bitBuffer) {\n let i, group, value\n\n // The input data string is divided into groups of three digits,\n // and each group is converted to its 10-bit binary equivalent.\n for (i = 0; i + 3 <= this.data.length; i += 3) {\n group = this.data.substr(i, 3)\n value = parseInt(group, 10)\n\n bitBuffer.put(value, 10)\n }\n\n // If the number of input digits is not an exact multiple of three,\n // the final one or two digits are converted to 4 or 7 bits respectively.\n const remainingNum = this.data.length - i\n if (remainingNum > 0) {\n group = this.data.substr(i)\n value = parseInt(group, 10)\n\n bitBuffer.put(value, remainingNum * 3 + 1)\n }\n}\n\nmodule.exports = NumericData\n","const Mode = require('./mode')\n\n/**\n * Array of characters available in alphanumeric mode\n *\n * As per QR Code specification, to each character\n * is assigned a value from 0 to 44 which in this case coincides\n * with the array index\n *\n * @type {Array}\n */\nconst ALPHA_NUM_CHARS = [\n '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\n 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',\n 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',\n ' ', '$', '%', '*', '+', '-', '.', '/', ':'\n]\n\nfunction AlphanumericData (data) {\n this.mode = Mode.ALPHANUMERIC\n this.data = data\n}\n\nAlphanumericData.getBitsLength = function getBitsLength (length) {\n return 11 * Math.floor(length / 2) + 6 * (length % 2)\n}\n\nAlphanumericData.prototype.getLength = function getLength () {\n return this.data.length\n}\n\nAlphanumericData.prototype.getBitsLength = function getBitsLength () {\n return AlphanumericData.getBitsLength(this.data.length)\n}\n\nAlphanumericData.prototype.write = function write (bitBuffer) {\n let i\n\n // Input data characters are divided into groups of two characters\n // and encoded as 11-bit binary codes.\n for (i = 0; i + 2 <= this.data.length; i += 2) {\n // The character value of the first character is multiplied by 45\n let value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45\n\n // The character value of the second digit is added to the product\n value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1])\n\n // The sum is then stored as 11-bit binary number\n bitBuffer.put(value, 11)\n }\n\n // If the number of input data characters is not a multiple of two,\n // the character value of the final character is encoded as a 6-bit binary number.\n if (this.data.length % 2) {\n bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6)\n }\n}\n\nmodule.exports = AlphanumericData\n","const Mode = require('./mode')\n\nfunction ByteData (data) {\n this.mode = Mode.BYTE\n if (typeof (data) === 'string') {\n this.data = new TextEncoder().encode(data)\n } else {\n this.data = new Uint8Array(data)\n }\n}\n\nByteData.getBitsLength = function getBitsLength (length) {\n return length * 8\n}\n\nByteData.prototype.getLength = function getLength () {\n return this.data.length\n}\n\nByteData.prototype.getBitsLength = function getBitsLength () {\n return ByteData.getBitsLength(this.data.length)\n}\n\nByteData.prototype.write = function (bitBuffer) {\n for (let i = 0, l = this.data.length; i < l; i++) {\n bitBuffer.put(this.data[i], 8)\n }\n}\n\nmodule.exports = ByteData\n","const Mode = require('./mode')\nconst Utils = require('./utils')\n\nfunction KanjiData (data) {\n this.mode = Mode.KANJI\n this.data = data\n}\n\nKanjiData.getBitsLength = function getBitsLength (length) {\n return length * 13\n}\n\nKanjiData.prototype.getLength = function getLength () {\n return this.data.length\n}\n\nKanjiData.prototype.getBitsLength = function getBitsLength () {\n return KanjiData.getBitsLength(this.data.length)\n}\n\nKanjiData.prototype.write = function (bitBuffer) {\n let i\n\n // In the Shift JIS system, Kanji characters are represented by a two byte combination.\n // These byte values are shifted from the JIS X 0208 values.\n // JIS X 0208 gives details of the shift coded representation.\n for (i = 0; i < this.data.length; i++) {\n let value = Utils.toSJIS(this.data[i])\n\n // For characters with Shift JIS values from 0x8140 to 0x9FFC:\n if (value >= 0x8140 && value <= 0x9FFC) {\n // Subtract 0x8140 from Shift JIS value\n value -= 0x8140\n\n // For characters with Shift JIS values from 0xE040 to 0xEBBF\n } else if (value >= 0xE040 && value <= 0xEBBF) {\n // Subtract 0xC140 from Shift JIS value\n value -= 0xC140\n } else {\n throw new Error(\n 'Invalid SJIS character: ' + this.data[i] + '\\n' +\n 'Make sure your charset is UTF-8')\n }\n\n // Multiply most significant byte of result by 0xC0\n // and add least significant byte to product\n value = (((value >>> 8) & 0xff) * 0xC0) + (value & 0xff)\n\n // Convert result to a 13-bit binary string\n bitBuffer.put(value, 13)\n }\n}\n\nmodule.exports = KanjiData\n","'use strict';\n\n/******************************************************************************\n * Created 2008-08-19.\n *\n * Dijkstra path-finding functions. Adapted from the Dijkstar Python project.\n *\n * Copyright (C) 2008\n * Wyatt Baldwin \n * All rights reserved\n *\n * Licensed under the MIT license.\n *\n * http://www.opensource.org/licenses/mit-license.php\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n *****************************************************************************/\nvar dijkstra = {\n single_source_shortest_paths: function(graph, s, d) {\n // Predecessor map for each node that has been encountered.\n // node ID => predecessor node ID\n var predecessors = {};\n\n // Costs of shortest paths from s to all nodes encountered.\n // node ID => cost\n var costs = {};\n costs[s] = 0;\n\n // Costs of shortest paths from s to all nodes encountered; differs from\n // `costs` in that it provides easy access to the node that currently has\n // the known shortest path from s.\n // XXX: Do we actually need both `costs` and `open`?\n var open = dijkstra.PriorityQueue.make();\n open.push(s, 0);\n\n var closest,\n u, v,\n cost_of_s_to_u,\n adjacent_nodes,\n cost_of_e,\n cost_of_s_to_u_plus_cost_of_e,\n cost_of_s_to_v,\n first_visit;\n while (!open.empty()) {\n // In the nodes remaining in graph that have a known cost from s,\n // find the node, u, that currently has the shortest path from s.\n closest = open.pop();\n u = closest.value;\n cost_of_s_to_u = closest.cost;\n\n // Get nodes adjacent to u...\n adjacent_nodes = graph[u] || {};\n\n // ...and explore the edges that connect u to those nodes, updating\n // the cost of the shortest paths to any or all of those nodes as\n // necessary. v is the node across the current edge from u.\n for (v in adjacent_nodes) {\n if (adjacent_nodes.hasOwnProperty(v)) {\n // Get the cost of the edge running from u to v.\n cost_of_e = adjacent_nodes[v];\n\n // Cost of s to u plus the cost of u to v across e--this is *a*\n // cost from s to v that may or may not be less than the current\n // known cost to v.\n cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;\n\n // If we haven't visited v yet OR if the current known cost from s to\n // v is greater than the new cost we just found (cost of s to u plus\n // cost of u to v across e), update v's cost in the cost list and\n // update v's predecessor in the predecessor list (it's now u).\n cost_of_s_to_v = costs[v];\n first_visit = (typeof costs[v] === 'undefined');\n if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {\n costs[v] = cost_of_s_to_u_plus_cost_of_e;\n open.push(v, cost_of_s_to_u_plus_cost_of_e);\n predecessors[v] = u;\n }\n }\n }\n }\n\n if (typeof d !== 'undefined' && typeof costs[d] === 'undefined') {\n var msg = ['Could not find a path from ', s, ' to ', d, '.'].join('');\n throw new Error(msg);\n }\n\n return predecessors;\n },\n\n extract_shortest_path_from_predecessor_list: function(predecessors, d) {\n var nodes = [];\n var u = d;\n var predecessor;\n while (u) {\n nodes.push(u);\n predecessor = predecessors[u];\n u = predecessors[u];\n }\n nodes.reverse();\n return nodes;\n },\n\n find_path: function(graph, s, d) {\n var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);\n return dijkstra.extract_shortest_path_from_predecessor_list(\n predecessors, d);\n },\n\n /**\n * A very naive priority queue implementation.\n */\n PriorityQueue: {\n make: function (opts) {\n var T = dijkstra.PriorityQueue,\n t = {},\n key;\n opts = opts || {};\n for (key in T) {\n if (T.hasOwnProperty(key)) {\n t[key] = T[key];\n }\n }\n t.queue = [];\n t.sorter = opts.sorter || T.default_sorter;\n return t;\n },\n\n default_sorter: function (a, b) {\n return a.cost - b.cost;\n },\n\n /**\n * Add a new item to the queue and ensure the highest priority element\n * is at the front of the queue.\n */\n push: function (value, cost) {\n var item = {value: value, cost: cost};\n this.queue.push(item);\n this.queue.sort(this.sorter);\n },\n\n /**\n * Return the highest priority element in the queue.\n */\n pop: function () {\n return this.queue.shift();\n },\n\n empty: function () {\n return this.queue.length === 0;\n }\n }\n};\n\n\n// node.js module exports\nif (typeof module !== 'undefined') {\n module.exports = dijkstra;\n}\n","const Mode = require('./mode')\nconst NumericData = require('./numeric-data')\nconst AlphanumericData = require('./alphanumeric-data')\nconst ByteData = require('./byte-data')\nconst KanjiData = require('./kanji-data')\nconst Regex = require('./regex')\nconst Utils = require('./utils')\nconst dijkstra = require('dijkstrajs')\n\n/**\n * Returns UTF8 byte length\n *\n * @param {String} str Input string\n * @return {Number} Number of byte\n */\nfunction getStringByteLength (str) {\n return unescape(encodeURIComponent(str)).length\n}\n\n/**\n * Get a list of segments of the specified mode\n * from a string\n *\n * @param {Mode} mode Segment mode\n * @param {String} str String to process\n * @return {Array} Array of object with segments data\n */\nfunction getSegments (regex, mode, str) {\n const segments = []\n let result\n\n while ((result = regex.exec(str)) !== null) {\n segments.push({\n data: result[0],\n index: result.index,\n mode: mode,\n length: result[0].length\n })\n }\n\n return segments\n}\n\n/**\n * Extracts a series of segments with the appropriate\n * modes from a string\n *\n * @param {String} dataStr Input string\n * @return {Array} Array of object with segments data\n */\nfunction getSegmentsFromString (dataStr) {\n const numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr)\n const alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr)\n let byteSegs\n let kanjiSegs\n\n if (Utils.isKanjiModeEnabled()) {\n byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr)\n kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr)\n } else {\n byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr)\n kanjiSegs = []\n }\n\n const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs)\n\n return segs\n .sort(function (s1, s2) {\n return s1.index - s2.index\n })\n .map(function (obj) {\n return {\n data: obj.data,\n mode: obj.mode,\n length: obj.length\n }\n })\n}\n\n/**\n * Returns how many bits are needed to encode a string of\n * specified length with the specified mode\n *\n * @param {Number} length String length\n * @param {Mode} mode Segment mode\n * @return {Number} Bit length\n */\nfunction getSegmentBitsLength (length, mode) {\n switch (mode) {\n case Mode.NUMERIC:\n return NumericData.getBitsLength(length)\n case Mode.ALPHANUMERIC:\n return AlphanumericData.getBitsLength(length)\n case Mode.KANJI:\n return KanjiData.getBitsLength(length)\n case Mode.BYTE:\n return ByteData.getBitsLength(length)\n }\n}\n\n/**\n * Merges adjacent segments which have the same mode\n *\n * @param {Array} segs Array of object with segments data\n * @return {Array} Array of object with segments data\n */\nfunction mergeSegments (segs) {\n return segs.reduce(function (acc, curr) {\n const prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null\n if (prevSeg && prevSeg.mode === curr.mode) {\n acc[acc.length - 1].data += curr.data\n return acc\n }\n\n acc.push(curr)\n return acc\n }, [])\n}\n\n/**\n * Generates a list of all possible nodes combination which\n * will be used to build a segments graph.\n *\n * Nodes are divided by groups. Each group will contain a list of all the modes\n * in which is possible to encode the given text.\n *\n * For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte.\n * The group for '12345' will contain then 3 objects, one for each\n * possible encoding mode.\n *\n * Each node represents a possible segment.\n *\n * @param {Array} segs Array of object with segments data\n * @return {Array} Array of object with segments data\n */\nfunction buildNodes (segs) {\n const nodes = []\n for (let i = 0; i < segs.length; i++) {\n const seg = segs[i]\n\n switch (seg.mode) {\n case Mode.NUMERIC:\n nodes.push([seg,\n { data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },\n { data: seg.data, mode: Mode.BYTE, length: seg.length }\n ])\n break\n case Mode.ALPHANUMERIC:\n nodes.push([seg,\n { data: seg.data, mode: Mode.BYTE, length: seg.length }\n ])\n break\n case Mode.KANJI:\n nodes.push([seg,\n { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }\n ])\n break\n case Mode.BYTE:\n nodes.push([\n { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }\n ])\n }\n }\n\n return nodes\n}\n\n/**\n * Builds a graph from a list of nodes.\n * All segments in each node group will be connected with all the segments of\n * the next group and so on.\n *\n * At each connection will be assigned a weight depending on the\n * segment's byte length.\n *\n * @param {Array} nodes Array of object with segments data\n * @param {Number} version QR Code version\n * @return {Object} Graph of all possible segments\n */\nfunction buildGraph (nodes, version) {\n const table = {}\n const graph = { start: {} }\n let prevNodeIds = ['start']\n\n for (let i = 0; i < nodes.length; i++) {\n const nodeGroup = nodes[i]\n const currentNodeIds = []\n\n for (let j = 0; j < nodeGroup.length; j++) {\n const node = nodeGroup[j]\n const key = '' + i + j\n\n currentNodeIds.push(key)\n table[key] = { node: node, lastCount: 0 }\n graph[key] = {}\n\n for (let n = 0; n < prevNodeIds.length; n++) {\n const prevNodeId = prevNodeIds[n]\n\n if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {\n graph[prevNodeId][key] =\n getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) -\n getSegmentBitsLength(table[prevNodeId].lastCount, node.mode)\n\n table[prevNodeId].lastCount += node.length\n } else {\n if (table[prevNodeId]) table[prevNodeId].lastCount = node.length\n\n graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) +\n 4 + Mode.getCharCountIndicator(node.mode, version) // switch cost\n }\n }\n }\n\n prevNodeIds = currentNodeIds\n }\n\n for (let n = 0; n < prevNodeIds.length; n++) {\n graph[prevNodeIds[n]].end = 0\n }\n\n return { map: graph, table: table }\n}\n\n/**\n * Builds a segment from a specified data and mode.\n * If a mode is not specified, the more suitable will be used.\n *\n * @param {String} data Input data\n * @param {Mode | String} modesHint Data mode\n * @return {Segment} Segment\n */\nfunction buildSingleSegment (data, modesHint) {\n let mode\n const bestMode = Mode.getBestModeForData(data)\n\n mode = Mode.from(modesHint, bestMode)\n\n // Make sure data can be encoded\n if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {\n throw new Error('\"' + data + '\"' +\n ' cannot be encoded with mode ' + Mode.toString(mode) +\n '.\\n Suggested mode is: ' + Mode.toString(bestMode))\n }\n\n // Use Mode.BYTE if Kanji support is disabled\n if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {\n mode = Mode.BYTE\n }\n\n switch (mode) {\n case Mode.NUMERIC:\n return new NumericData(data)\n\n case Mode.ALPHANUMERIC:\n return new AlphanumericData(data)\n\n case Mode.KANJI:\n return new KanjiData(data)\n\n case Mode.BYTE:\n return new ByteData(data)\n }\n}\n\n/**\n * Builds a list of segments from an array.\n * Array can contain Strings or Objects with segment's info.\n *\n * For each item which is a string, will be generated a segment with the given\n * string and the more appropriate encoding mode.\n *\n * For each item which is an object, will be generated a segment with the given\n * data and mode.\n * Objects must contain at least the property \"data\".\n * If property \"mode\" is not present, the more suitable mode will be used.\n *\n * @param {Array} array Array of objects with segments data\n * @return {Array} Array of Segments\n */\nexports.fromArray = function fromArray (array) {\n return array.reduce(function (acc, seg) {\n if (typeof seg === 'string') {\n acc.push(buildSingleSegment(seg, null))\n } else if (seg.data) {\n acc.push(buildSingleSegment(seg.data, seg.mode))\n }\n\n return acc\n }, [])\n}\n\n/**\n * Builds an optimized sequence of segments from a string,\n * which will produce the shortest possible bitstream.\n *\n * @param {String} data Input string\n * @param {Number} version QR Code version\n * @return {Array} Array of segments\n */\nexports.fromString = function fromString (data, version) {\n const segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled())\n\n const nodes = buildNodes(segs)\n const graph = buildGraph(nodes, version)\n const path = dijkstra.find_path(graph.map, 'start', 'end')\n\n const optimizedSegs = []\n for (let i = 1; i < path.length - 1; i++) {\n optimizedSegs.push(graph.table[path[i]].node)\n }\n\n return exports.fromArray(mergeSegments(optimizedSegs))\n}\n\n/**\n * Splits a string in various segments with the modes which\n * best represent their content.\n * The produced segments are far from being optimized.\n * The output of this function is only used to estimate a QR Code version\n * which may contain the data.\n *\n * @param {string} data Input string\n * @return {Array} Array of segments\n */\nexports.rawSplit = function rawSplit (data) {\n return exports.fromArray(\n getSegmentsFromString(data, Utils.isKanjiModeEnabled())\n )\n}\n","const Utils = require('./utils')\nconst ECLevel = require('./error-correction-level')\nconst BitBuffer = require('./bit-buffer')\nconst BitMatrix = require('./bit-matrix')\nconst AlignmentPattern = require('./alignment-pattern')\nconst FinderPattern = require('./finder-pattern')\nconst MaskPattern = require('./mask-pattern')\nconst ECCode = require('./error-correction-code')\nconst ReedSolomonEncoder = require('./reed-solomon-encoder')\nconst Version = require('./version')\nconst FormatInfo = require('./format-info')\nconst Mode = require('./mode')\nconst Segments = require('./segments')\n\n/**\n * QRCode for JavaScript\n *\n * modified by Ryan Day for nodejs support\n * Copyright (c) 2011 Ryan Day\n *\n * Licensed under the MIT license:\n * http://www.opensource.org/licenses/mit-license.php\n *\n//---------------------------------------------------------------------\n// QRCode for JavaScript\n//\n// Copyright (c) 2009 Kazuhiko Arase\n//\n// URL: http://www.d-project.com/\n//\n// Licensed under the MIT license:\n// http://www.opensource.org/licenses/mit-license.php\n//\n// The word \"QR Code\" is registered trademark of\n// DENSO WAVE INCORPORATED\n// http://www.denso-wave.com/qrcode/faqpatent-e.html\n//\n//---------------------------------------------------------------------\n*/\n\n/**\n * Add finder patterns bits to matrix\n *\n * @param {BitMatrix} matrix Modules matrix\n * @param {Number} version QR Code version\n */\nfunction setupFinderPattern (matrix, version) {\n const size = matrix.size\n const pos = FinderPattern.getPositions(version)\n\n for (let i = 0; i < pos.length; i++) {\n const row = pos[i][0]\n const col = pos[i][1]\n\n for (let r = -1; r <= 7; r++) {\n if (row + r <= -1 || size <= row + r) continue\n\n for (let c = -1; c <= 7; c++) {\n if (col + c <= -1 || size <= col + c) continue\n\n if ((r >= 0 && r <= 6 && (c === 0 || c === 6)) ||\n (c >= 0 && c <= 6 && (r === 0 || r === 6)) ||\n (r >= 2 && r <= 4 && c >= 2 && c <= 4)) {\n matrix.set(row + r, col + c, true, true)\n } else {\n matrix.set(row + r, col + c, false, true)\n }\n }\n }\n }\n}\n\n/**\n * Add timing pattern bits to matrix\n *\n * Note: this function must be called before {@link setupAlignmentPattern}\n *\n * @param {BitMatrix} matrix Modules matrix\n */\nfunction setupTimingPattern (matrix) {\n const size = matrix.size\n\n for (let r = 8; r < size - 8; r++) {\n const value = r % 2 === 0\n matrix.set(r, 6, value, true)\n matrix.set(6, r, value, true)\n }\n}\n\n/**\n * Add alignment patterns bits to matrix\n *\n * Note: this function must be called after {@link setupTimingPattern}\n *\n * @param {BitMatrix} matrix Modules matrix\n * @param {Number} version QR Code version\n */\nfunction setupAlignmentPattern (matrix, version) {\n const pos = AlignmentPattern.getPositions(version)\n\n for (let i = 0; i < pos.length; i++) {\n const row = pos[i][0]\n const col = pos[i][1]\n\n for (let r = -2; r <= 2; r++) {\n for (let c = -2; c <= 2; c++) {\n if (r === -2 || r === 2 || c === -2 || c === 2 ||\n (r === 0 && c === 0)) {\n matrix.set(row + r, col + c, true, true)\n } else {\n matrix.set(row + r, col + c, false, true)\n }\n }\n }\n }\n}\n\n/**\n * Add version info bits to matrix\n *\n * @param {BitMatrix} matrix Modules matrix\n * @param {Number} version QR Code version\n */\nfunction setupVersionInfo (matrix, version) {\n const size = matrix.size\n const bits = Version.getEncodedBits(version)\n let row, col, mod\n\n for (let i = 0; i < 18; i++) {\n row = Math.floor(i / 3)\n col = i % 3 + size - 8 - 3\n mod = ((bits >> i) & 1) === 1\n\n matrix.set(row, col, mod, true)\n matrix.set(col, row, mod, true)\n }\n}\n\n/**\n * Add format info bits to matrix\n *\n * @param {BitMatrix} matrix Modules matrix\n * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level\n * @param {Number} maskPattern Mask pattern reference value\n */\nfunction setupFormatInfo (matrix, errorCorrectionLevel, maskPattern) {\n const size = matrix.size\n const bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern)\n let i, mod\n\n for (i = 0; i < 15; i++) {\n mod = ((bits >> i) & 1) === 1\n\n // vertical\n if (i < 6) {\n matrix.set(i, 8, mod, true)\n } else if (i < 8) {\n matrix.set(i + 1, 8, mod, true)\n } else {\n matrix.set(size - 15 + i, 8, mod, true)\n }\n\n // horizontal\n if (i < 8) {\n matrix.set(8, size - i - 1, mod, true)\n } else if (i < 9) {\n matrix.set(8, 15 - i - 1 + 1, mod, true)\n } else {\n matrix.set(8, 15 - i - 1, mod, true)\n }\n }\n\n // fixed module\n matrix.set(size - 8, 8, 1, true)\n}\n\n/**\n * Add encoded data bits to matrix\n *\n * @param {BitMatrix} matrix Modules matrix\n * @param {Uint8Array} data Data codewords\n */\nfunction setupData (matrix, data) {\n const size = matrix.size\n let inc = -1\n let row = size - 1\n let bitIndex = 7\n let byteIndex = 0\n\n for (let col = size - 1; col > 0; col -= 2) {\n if (col === 6) col--\n\n while (true) {\n for (let c = 0; c < 2; c++) {\n if (!matrix.isReserved(row, col - c)) {\n let dark = false\n\n if (byteIndex < data.length) {\n dark = (((data[byteIndex] >>> bitIndex) & 1) === 1)\n }\n\n matrix.set(row, col - c, dark)\n bitIndex--\n\n if (bitIndex === -1) {\n byteIndex++\n bitIndex = 7\n }\n }\n }\n\n row += inc\n\n if (row < 0 || size <= row) {\n row -= inc\n inc = -inc\n break\n }\n }\n }\n}\n\n/**\n * Create encoded codewords from data input\n *\n * @param {Number} version QR Code version\n * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level\n * @param {ByteData} data Data input\n * @return {Uint8Array} Buffer containing encoded codewords\n */\nfunction createData (version, errorCorrectionLevel, segments) {\n // Prepare data buffer\n const buffer = new BitBuffer()\n\n segments.forEach(function (data) {\n // prefix data with mode indicator (4 bits)\n buffer.put(data.mode.bit, 4)\n\n // Prefix data with character count indicator.\n // The character count indicator is a string of bits that represents the\n // number of characters that are being encoded.\n // The character count indicator must be placed after the mode indicator\n // and must be a certain number of bits long, depending on the QR version\n // and data mode\n // @see {@link Mode.getCharCountIndicator}.\n buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version))\n\n // add binary data sequence to buffer\n data.write(buffer)\n })\n\n // Calculate required number of bits\n const totalCodewords = Utils.getSymbolTotalCodewords(version)\n const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)\n const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8\n\n // Add a terminator.\n // If the bit string is shorter than the total number of required bits,\n // a terminator of up to four 0s must be added to the right side of the string.\n // If the bit string is more than four bits shorter than the required number of bits,\n // add four 0s to the end.\n if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {\n buffer.put(0, 4)\n }\n\n // If the bit string is fewer than four bits shorter, add only the number of 0s that\n // are needed to reach the required number of bits.\n\n // After adding the terminator, if the number of bits in the string is not a multiple of 8,\n // pad the string on the right with 0s to make the string's length a multiple of 8.\n while (buffer.getLengthInBits() % 8 !== 0) {\n buffer.putBit(0)\n }\n\n // Add pad bytes if the string is still shorter than the total number of required bits.\n // Extend the buffer to fill the data capacity of the symbol corresponding to\n // the Version and Error Correction Level by adding the Pad Codewords 11101100 (0xEC)\n // and 00010001 (0x11) alternately.\n const remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8\n for (let i = 0; i < remainingByte; i++) {\n buffer.put(i % 2 ? 0x11 : 0xEC, 8)\n }\n\n return createCodewords(buffer, version, errorCorrectionLevel)\n}\n\n/**\n * Encode input data with Reed-Solomon and return codewords with\n * relative error correction bits\n *\n * @param {BitBuffer} bitBuffer Data to encode\n * @param {Number} version QR Code version\n * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level\n * @return {Uint8Array} Buffer containing encoded codewords\n */\nfunction createCodewords (bitBuffer, version, errorCorrectionLevel) {\n // Total codewords for this QR code version (Data + Error correction)\n const totalCodewords = Utils.getSymbolTotalCodewords(version)\n\n // Total number of error correction codewords\n const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)\n\n // Total number of data codewords\n const dataTotalCodewords = totalCodewords - ecTotalCodewords\n\n // Total number of blocks\n const ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel)\n\n // Calculate how many blocks each group should contain\n const blocksInGroup2 = totalCodewords % ecTotalBlocks\n const blocksInGroup1 = ecTotalBlocks - blocksInGroup2\n\n const totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks)\n\n const dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks)\n const dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1\n\n // Number of EC codewords is the same for both groups\n const ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1\n\n // Initialize a Reed-Solomon encoder with a generator polynomial of degree ecCount\n const rs = new ReedSolomonEncoder(ecCount)\n\n let offset = 0\n const dcData = new Array(ecTotalBlocks)\n const ecData = new Array(ecTotalBlocks)\n let maxDataSize = 0\n const buffer = new Uint8Array(bitBuffer.buffer)\n\n // Divide the buffer into the required number of blocks\n for (let b = 0; b < ecTotalBlocks; b++) {\n const dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2\n\n // extract a block of data from buffer\n dcData[b] = buffer.slice(offset, offset + dataSize)\n\n // Calculate EC codewords for this data block\n ecData[b] = rs.encode(dcData[b])\n\n offset += dataSize\n maxDataSize = Math.max(maxDataSize, dataSize)\n }\n\n // Create final data\n // Interleave the data and error correction codewords from each block\n const data = new Uint8Array(totalCodewords)\n let index = 0\n let i, r\n\n // Add data codewords\n for (i = 0; i < maxDataSize; i++) {\n for (r = 0; r < ecTotalBlocks; r++) {\n if (i < dcData[r].length) {\n data[index++] = dcData[r][i]\n }\n }\n }\n\n // Apped EC codewords\n for (i = 0; i < ecCount; i++) {\n for (r = 0; r < ecTotalBlocks; r++) {\n data[index++] = ecData[r][i]\n }\n }\n\n return data\n}\n\n/**\n * Build QR Code symbol\n *\n * @param {String} data Input string\n * @param {Number} version QR Code version\n * @param {ErrorCorretionLevel} errorCorrectionLevel Error level\n * @param {MaskPattern} maskPattern Mask pattern\n * @return {Object} Object containing symbol data\n */\nfunction createSymbol (data, version, errorCorrectionLevel, maskPattern) {\n let segments\n\n if (Array.isArray(data)) {\n segments = Segments.fromArray(data)\n } else if (typeof data === 'string') {\n let estimatedVersion = version\n\n if (!estimatedVersion) {\n const rawSegments = Segments.rawSplit(data)\n\n // Estimate best version that can contain raw splitted segments\n estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel)\n }\n\n // Build optimized segments\n // If estimated version is undefined, try with the highest version\n segments = Segments.fromString(data, estimatedVersion || 40)\n } else {\n throw new Error('Invalid data')\n }\n\n // Get the min version that can contain data\n const bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel)\n\n // If no version is found, data cannot be stored\n if (!bestVersion) {\n throw new Error('The amount of data is too big to be stored in a QR Code')\n }\n\n // If not specified, use min version as default\n if (!version) {\n version = bestVersion\n\n // Check if the specified version can contain the data\n } else if (version < bestVersion) {\n throw new Error('\\n' +\n 'The chosen QR Code version cannot contain this amount of data.\\n' +\n 'Minimum version required to store current data is: ' + bestVersion + '.\\n'\n )\n }\n\n const dataBits = createData(version, errorCorrectionLevel, segments)\n\n // Allocate matrix buffer\n const moduleCount = Utils.getSymbolSize(version)\n const modules = new BitMatrix(moduleCount)\n\n // Add function modules\n setupFinderPattern(modules, version)\n setupTimingPattern(modules)\n setupAlignmentPattern(modules, version)\n\n // Add temporary dummy bits for format info just to set them as reserved.\n // This is needed to prevent these bits from being masked by {@link MaskPattern.applyMask}\n // since the masking operation must be performed only on the encoding region.\n // These blocks will be replaced with correct values later in code.\n setupFormatInfo(modules, errorCorrectionLevel, 0)\n\n if (version >= 7) {\n setupVersionInfo(modules, version)\n }\n\n // Add data codewords\n setupData(modules, dataBits)\n\n if (isNaN(maskPattern)) {\n // Find best mask pattern\n maskPattern = MaskPattern.getBestMask(modules,\n setupFormatInfo.bind(null, modules, errorCorrectionLevel))\n }\n\n // Apply mask pattern\n MaskPattern.applyMask(maskPattern, modules)\n\n // Replace format info bits with correct values\n setupFormatInfo(modules, errorCorrectionLevel, maskPattern)\n\n return {\n modules: modules,\n version: version,\n errorCorrectionLevel: errorCorrectionLevel,\n maskPattern: maskPattern,\n segments: segments\n }\n}\n\n/**\n * QR Code\n *\n * @param {String | Array} data Input data\n * @param {Object} options Optional configurations\n * @param {Number} options.version QR Code version\n * @param {String} options.errorCorrectionLevel Error correction level\n * @param {Function} options.toSJISFunc Helper func to convert utf8 to sjis\n */\nexports.create = function create (data, options) {\n if (typeof data === 'undefined' || data === '') {\n throw new Error('No input text')\n }\n\n let errorCorrectionLevel = ECLevel.M\n let version\n let mask\n\n if (typeof options !== 'undefined') {\n // Use higher error correction level as default\n errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M)\n version = Version.from(options.version)\n mask = MaskPattern.from(options.maskPattern)\n\n if (options.toSJISFunc) {\n Utils.setToSJISFunction(options.toSJISFunc)\n }\n }\n\n return createSymbol(data, version, errorCorrectionLevel, mask)\n}\n","function hex2rgba (hex) {\n if (typeof hex === 'number') {\n hex = hex.toString()\n }\n\n if (typeof hex !== 'string') {\n throw new Error('Color should be defined as hex string')\n }\n\n let hexCode = hex.slice().replace('#', '').split('')\n if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {\n throw new Error('Invalid hex color: ' + hex)\n }\n\n // Convert from short to long form (fff -> ffffff)\n if (hexCode.length === 3 || hexCode.length === 4) {\n hexCode = Array.prototype.concat.apply([], hexCode.map(function (c) {\n return [c, c]\n }))\n }\n\n // Add default alpha value\n if (hexCode.length === 6) hexCode.push('F', 'F')\n\n const hexValue = parseInt(hexCode.join(''), 16)\n\n return {\n r: (hexValue >> 24) & 255,\n g: (hexValue >> 16) & 255,\n b: (hexValue >> 8) & 255,\n a: hexValue & 255,\n hex: '#' + hexCode.slice(0, 6).join('')\n }\n}\n\nexports.getOptions = function getOptions (options) {\n if (!options) options = {}\n if (!options.color) options.color = {}\n\n const margin = typeof options.margin === 'undefined' ||\n options.margin === null ||\n options.margin < 0\n ? 4\n : options.margin\n\n const width = options.width && options.width >= 21 ? options.width : undefined\n const scale = options.scale || 4\n\n return {\n width: width,\n scale: width ? 4 : scale,\n margin: margin,\n color: {\n dark: hex2rgba(options.color.dark || '#000000ff'),\n light: hex2rgba(options.color.light || '#ffffffff')\n },\n type: options.type,\n rendererOpts: options.rendererOpts || {}\n }\n}\n\nexports.getScale = function getScale (qrSize, opts) {\n return opts.width && opts.width >= qrSize + opts.margin * 2\n ? opts.width / (qrSize + opts.margin * 2)\n : opts.scale\n}\n\nexports.getImageWidth = function getImageWidth (qrSize, opts) {\n const scale = exports.getScale(qrSize, opts)\n return Math.floor((qrSize + opts.margin * 2) * scale)\n}\n\nexports.qrToImageData = function qrToImageData (imgData, qr, opts) {\n const size = qr.modules.size\n const data = qr.modules.data\n const scale = exports.getScale(size, opts)\n const symbolSize = Math.floor((size + opts.margin * 2) * scale)\n const scaledMargin = opts.margin * scale\n const palette = [opts.color.light, opts.color.dark]\n\n for (let i = 0; i < symbolSize; i++) {\n for (let j = 0; j < symbolSize; j++) {\n let posDst = (i * symbolSize + j) * 4\n let pxColor = opts.color.light\n\n if (i >= scaledMargin && j >= scaledMargin &&\n i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {\n const iSrc = Math.floor((i - scaledMargin) / scale)\n const jSrc = Math.floor((j - scaledMargin) / scale)\n pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0]\n }\n\n imgData[posDst++] = pxColor.r\n imgData[posDst++] = pxColor.g\n imgData[posDst++] = pxColor.b\n imgData[posDst] = pxColor.a\n }\n }\n}\n","const Utils = require('./utils')\n\nfunction clearCanvas (ctx, canvas, size) {\n ctx.clearRect(0, 0, canvas.width, canvas.height)\n\n if (!canvas.style) canvas.style = {}\n canvas.height = size\n canvas.width = size\n canvas.style.height = size + 'px'\n canvas.style.width = size + 'px'\n}\n\nfunction getCanvasElement () {\n try {\n return document.createElement('canvas')\n } catch (e) {\n throw new Error('You need to specify a canvas element')\n }\n}\n\nexports.render = function render (qrData, canvas, options) {\n let opts = options\n let canvasEl = canvas\n\n if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {\n opts = canvas\n canvas = undefined\n }\n\n if (!canvas) {\n canvasEl = getCanvasElement()\n }\n\n opts = Utils.getOptions(opts)\n const size = Utils.getImageWidth(qrData.modules.size, opts)\n\n const ctx = canvasEl.getContext('2d')\n const image = ctx.createImageData(size, size)\n Utils.qrToImageData(image.data, qrData, opts)\n\n clearCanvas(ctx, canvasEl, size)\n ctx.putImageData(image, 0, 0)\n\n return canvasEl\n}\n\nexports.renderToDataURL = function renderToDataURL (qrData, canvas, options) {\n let opts = options\n\n if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {\n opts = canvas\n canvas = undefined\n }\n\n if (!opts) opts = {}\n\n const canvasEl = exports.render(qrData, canvas, opts)\n\n const type = opts.type || 'image/png'\n const rendererOpts = opts.rendererOpts || {}\n\n return canvasEl.toDataURL(type, rendererOpts.quality)\n}\n","const Utils = require('./utils')\n\nfunction getColorAttrib (color, attrib) {\n const alpha = color.a / 255\n const str = attrib + '=\"' + color.hex + '\"'\n\n return alpha < 1\n ? str + ' ' + attrib + '-opacity=\"' + alpha.toFixed(2).slice(1) + '\"'\n : str\n}\n\nfunction svgCmd (cmd, x, y) {\n let str = cmd + x\n if (typeof y !== 'undefined') str += ' ' + y\n\n return str\n}\n\nfunction qrToPath (data, size, margin) {\n let path = ''\n let moveBy = 0\n let newRow = false\n let lineLength = 0\n\n for (let i = 0; i < data.length; i++) {\n const col = Math.floor(i % size)\n const row = Math.floor(i / size)\n\n if (!col && !newRow) newRow = true\n\n if (data[i]) {\n lineLength++\n\n if (!(i > 0 && col > 0 && data[i - 1])) {\n path += newRow\n ? svgCmd('M', col + margin, 0.5 + row + margin)\n : svgCmd('m', moveBy, 0)\n\n moveBy = 0\n newRow = false\n }\n\n if (!(col + 1 < size && data[i + 1])) {\n path += svgCmd('h', lineLength)\n lineLength = 0\n }\n } else {\n moveBy++\n }\n }\n\n return path\n}\n\nexports.render = function render (qrData, options, cb) {\n const opts = Utils.getOptions(options)\n const size = qrData.modules.size\n const data = qrData.modules.data\n const qrcodesize = size + opts.margin * 2\n\n const bg = !opts.color.light.a\n ? ''\n : ''\n\n const path =\n ''\n\n const viewBox = 'viewBox=\"' + '0 0 ' + qrcodesize + ' ' + qrcodesize + '\"'\n\n const width = !opts.width ? '' : 'width=\"' + opts.width + '\" height=\"' + opts.width + '\" '\n\n const svgTag = '' + bg + path + '\\n'\n\n if (typeof cb === 'function') {\n cb(null, svgTag)\n }\n\n return svgTag\n}\n","\nconst canPromise = require('./can-promise')\n\nconst QRCode = require('./core/qrcode')\nconst CanvasRenderer = require('./renderer/canvas')\nconst SvgRenderer = require('./renderer/svg-tag.js')\n\nfunction renderCanvas (renderFunc, canvas, text, opts, cb) {\n const args = [].slice.call(arguments, 1)\n const argsNum = args.length\n const isLastArgCb = typeof args[argsNum - 1] === 'function'\n\n if (!isLastArgCb && !canPromise()) {\n throw new Error('Callback required as last argument')\n }\n\n if (isLastArgCb) {\n if (argsNum < 2) {\n throw new Error('Too few arguments provided')\n }\n\n if (argsNum === 2) {\n cb = text\n text = canvas\n canvas = opts = undefined\n } else if (argsNum === 3) {\n if (canvas.getContext && typeof cb === 'undefined') {\n cb = opts\n opts = undefined\n } else {\n cb = opts\n opts = text\n text = canvas\n canvas = undefined\n }\n }\n } else {\n if (argsNum < 1) {\n throw new Error('Too few arguments provided')\n }\n\n if (argsNum === 1) {\n text = canvas\n canvas = opts = undefined\n } else if (argsNum === 2 && !canvas.getContext) {\n opts = text\n text = canvas\n canvas = undefined\n }\n\n return new Promise(function (resolve, reject) {\n try {\n const data = QRCode.create(text, opts)\n resolve(renderFunc(data, canvas, opts))\n } catch (e) {\n reject(e)\n }\n })\n }\n\n try {\n const data = QRCode.create(text, opts)\n cb(null, renderFunc(data, canvas, opts))\n } catch (e) {\n cb(e)\n }\n}\n\nexports.create = QRCode.create\nexports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render)\nexports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL)\n\n// only svg for now.\nexports.toString = renderCanvas.bind(null, function (data, _, opts) {\n return SvgRenderer.render(data, opts)\n})\n","import { FlottformChannelHost } from './flottform-channel-host';\n\ntype HostKey = string;\ntype ClientKey = string;\ntype EndpointId = string;\ntype EndpointInfo = {\n\thostKey: HostKey;\n\tendpointId: EndpointId;\n\thostInfo: {\n\t\tsession: RTCSessionDescriptionInit;\n\t\ticeCandidates: RTCIceCandidateInit[];\n\t};\n\tclientKey?: ClientKey;\n\tclientInfo?: {\n\t\tsession: RTCSessionDescriptionInit;\n\t\ticeCandidates: RTCIceCandidateInit[];\n\t};\n};\n\nexport type BaseListeners = {\n\tnew: [];\n\tdisconnected: [];\n\terror: [error: Error];\n\tconnected: [];\n\t'endpoint-created': [{ link: string; qrCode: string }];\n\t'webrtc:waiting-for-client': [\n\t\tevent: { link: string; qrCode: string; channel: FlottformChannelHost }\n\t];\n\t'webrtc:waiting-for-ice': [];\n};\n\nexport type SafeEndpointInfo = Omit;\n\nexport type ClientState =\n\t| 'init'\n\t| 'retrieving-info-from-endpoint' // first request to server\n\t| 'sending-client-info' // initial request to endpoint\n\t| 'connecting-to-host' // initial connection\n\t| 'connection-impossible' // if a connection is not possible due to network restrictions\n\t| 'connected' // waiting for user input, having a connection\n\t| 'disconnected' // failed after having a connection\n\t| 'done' // done with sending\n\t| 'error';\n\nexport type FlottformState =\n\t| 'new'\n\t| 'waiting-for-client'\n\t| 'waiting-for-ice'\n\t| 'waiting-for-data'\n\t| 'receiving-data'\n\t| 'done'\n\t| 'error';\n\nexport type Logger = {\n\tdebug: typeof console.debug;\n\tinfo: typeof console.info;\n\tlog: typeof console.log;\n\twarn: typeof console.warn;\n\terror: typeof console.error;\n};\n\nexport type FileMetaInfos = {\n\tdata: string;\n\tlastModified?: number;\n\tname?: string;\n\tsize: number;\n\ttype?: string;\n};\n\nexport const POLL_TIME_IN_MS: number = 1000;\n\nexport const DEFAULT_WEBRTC_CONFIG: RTCConfiguration = {\n\ticeServers: [\n\t\t{\n\t\t\turls: ['stun:stun1.l.google.com:19302']\n\t\t}\n\t]\n};\n\nexport function generateSecretKey(): string {\n\treturn crypto.randomUUID();\n}\n\nexport async function retrieveEndpointInfo(getEndpointInfoUrl: string) {\n\tconst response = await fetch(getEndpointInfoUrl);\n\treturn (await response.json()) as SafeEndpointInfo;\n}\n\nexport async function addIceCandidatesToConnection(\n\tconnection: RTCPeerConnection,\n\ticeCandidates: RTCIceCandidateInit[]\n) {\n\tfor (const iceCandidate of iceCandidates) {\n\t\tawait connection.addIceCandidate(iceCandidate);\n\t}\n}\n\nexport function setIncludes(set: Set, x: T): boolean {\n\tfor (const item of set) {\n\t\tif (JSON.stringify(item) === JSON.stringify(x)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\ntype Listener> = (...args: T) => void; // eslint-disable-line @typescript-eslint/no-explicit-any\nexport type FlottformEventMap = {\n\tnew: [details: { channel: FlottformChannelHost }];\n\t'waiting-for-client': [\n\t\tdetails: {\n\t\t\tqrCode: string;\n\t\t\tlink: string;\n\t\t\tchannel: FlottformChannelHost;\n\t\t}\n\t];\n\t'waiting-for-data': [];\n\t'waiting-for-ice': [];\n\t'receiving-data': [e: MessageEvent];\n\t'file-received': [{ fileMeta: FileMetaInfos; arrayBuffer: Array }];\n\tdone: [];\n\terror: [error: Error];\n\tconnected: [];\n\tdisconnected: [];\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class EventEmitter>> {\n\tprivate eventListeners: { [K in keyof EventMap]?: Set> } = {};\n\n\ton(eventName: K, listener: Listener) {\n\t\tconst listeners = this.eventListeners[eventName] ?? new Set();\n\t\tlisteners.add(listener);\n\t\tthis.eventListeners[eventName] = listeners;\n\t}\n\n\toff(eventName: K, listener: Listener) {\n\t\tconst listeners = this.eventListeners[eventName];\n\t\tif (listeners) {\n\t\t\tlisteners.delete(listener);\n\t\t\tif (listeners.size === 0) {\n\t\t\t\tdelete this.eventListeners[eventName];\n\t\t\t}\n\t\t}\n\t}\n\n\temit(eventName: K, ...args: EventMap[K]) {\n\t\tconst listeners = this.eventListeners[eventName] ?? new Set();\n\t\tfor (const listener of listeners) {\n\t\t\tlistener(...args);\n\t\t}\n\t}\n}\n\nexport abstract class BaseInputHost extends EventEmitter {\n\tabstract start();\n\tabstract close();\n}\n","import { toDataURL } from 'qrcode';\nimport {\n\tEventEmitter,\n\tFlottformEventMap,\n\tFlottformState,\n\tLogger,\n\tretrieveEndpointInfo,\n\tsetIncludes\n} from './internal';\n\nexport class FlottformChannelHost extends EventEmitter {\n\tprivate flottformApi: string | URL;\n\tprivate createClientUrl: (params: { endpointId: string }) => Promise;\n\tprivate rtcConfiguration: RTCConfiguration;\n\tprivate pollTimeForIceInMs: number;\n\tprivate logger: Logger;\n\n\tprivate state: FlottformState | 'disconnected' = 'new';\n\tprivate channelNumber: number = 0;\n\tprivate openPeerConnection: RTCPeerConnection | null = null;\n\tprivate dataChannel: RTCDataChannel | null = null;\n\tprivate pollForIceTimer: NodeJS.Timeout | number | null = null;\n\n\tconstructor({\n\t\tflottformApi,\n\t\tcreateClientUrl,\n\t\trtcConfiguration,\n\t\tpollTimeForIceInMs,\n\t\tlogger\n\t}: {\n\t\tflottformApi: string | URL;\n\t\tcreateClientUrl: (params: { endpointId: string }) => Promise;\n\t\trtcConfiguration: RTCConfiguration;\n\t\tpollTimeForIceInMs: number;\n\t\tlogger: Logger;\n\t}) {\n\t\tsuper();\n\t\tthis.flottformApi = flottformApi;\n\t\tthis.createClientUrl = createClientUrl;\n\t\tthis.rtcConfiguration = rtcConfiguration;\n\t\tthis.pollTimeForIceInMs = pollTimeForIceInMs;\n\t\tthis.logger = logger;\n\t\tPromise.resolve().then(() => {\n\t\t\tthis.changeState('new', { channel: this });\n\t\t});\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate changeState = (newState: FlottformState | 'disconnected', details?: any) => {\n\t\tthis.state = newState;\n\t\tthis.emit(newState, details);\n\t\tthis.logger.info(`State changed to: ${newState}`, details == undefined ? '' : details);\n\t};\n\n\tstart = async () => {\n\t\tif (this.openPeerConnection) {\n\t\t\tthis.close();\n\t\t}\n\t\tconst baseApi = (\n\t\t\tthis.flottformApi instanceof URL ? this.flottformApi : new URL(this.flottformApi)\n\t\t)\n\t\t\t.toString()\n\t\t\t.replace(/\\/$/, '');\n\n\t\t// For now the fetching can be done outside of these classes and should be passed as an argument.\n\t\t/* try {\n\t\t\tthis.rtcConfiguration.iceServers = await this.fetchIceServers(baseApi);\n\t\t} catch (error) {\n\t\t\t// Use the default configuration as a fallback\n\t\t\tthis.logger.error(error);\n\t\t} */\n\t\tthis.openPeerConnection = new RTCPeerConnection(this.rtcConfiguration);\n\n\t\tthis.dataChannel = this.createDataChannel();\n\n\t\tconst session = await this.openPeerConnection.createOffer();\n\t\tawait this.openPeerConnection.setLocalDescription(session);\n\n\t\tconst { endpointId, hostKey } = await this.createEndpoint(baseApi, session);\n\t\tthis.logger.log('Created endpoint', { endpointId, hostKey });\n\n\t\tconst getEndpointInfoUrl = `${baseApi}/${endpointId}`;\n\t\tconst putHostInfoUrl = `${baseApi}/${endpointId}/host`;\n\n\t\tconst hostIceCandidates = new Set();\n\t\tawait this.putHostInfo(putHostInfoUrl, hostKey, hostIceCandidates, session);\n\n\t\tthis.setUpConnectionStateGathering(getEndpointInfoUrl);\n\t\tthis.setupHostIceGathering(putHostInfoUrl, hostKey, hostIceCandidates, session);\n\t\tthis.setupDataChannelForTransfer();\n\n\t\tconst connectLink = await this.createClientUrl({ endpointId });\n\t\tthis.changeState('waiting-for-client', {\n\t\t\tqrCode: await toDataURL(connectLink),\n\t\t\tlink: connectLink,\n\t\t\tchannel: this\n\t\t});\n\t\t// Setup listener for messages incoming from the client\n\t\tthis.setupDataChannelListener();\n\t};\n\n\tclose = () => {\n\t\tif (this.openPeerConnection) {\n\t\t\tthis.openPeerConnection.close();\n\t\t\tthis.openPeerConnection = null;\n\t\t\tthis.stopPollingForConnection();\n\t\t}\n\t\tthis.changeState('disconnected');\n\t};\n\n\tprivate setupDataChannelListener = () => {\n\t\tif (this.dataChannel == null) {\n\t\t\tthis.changeState(\n\t\t\t\t'error',\n\t\t\t\t'dataChannel is null. Unable to setup the listeners for the data channel'\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.dataChannel.onmessage = (e) => {\n\t\t\t// Handling the incoming data from the client depends on the use case.\n\t\t\tthis.emit('receiving-data', e);\n\t\t};\n\t};\n\n\tprivate setupHostIceGathering = (\n\t\tputHostInfoUrl: string,\n\t\thostKey: string,\n\t\thostIceCandidates: Set,\n\t\tsession: RTCSessionDescriptionInit\n\t) => {\n\t\tif (this.openPeerConnection === null) {\n\t\t\tthis.changeState('error', 'openPeerConnection is null. Unable to gather Host ICE candidates');\n\t\t\treturn;\n\t\t}\n\n\t\tthis.openPeerConnection.onicecandidate = async (e) => {\n\t\t\tthis.logger.info(\n\t\t\t\t`onicecandidate - ${this.openPeerConnection!.connectionState} - ${e.candidate}`\n\t\t\t);\n\t\t\tif (e.candidate) {\n\t\t\t\tif (!setIncludes(hostIceCandidates, e.candidate)) {\n\t\t\t\t\tthis.logger.log('host found new ice candidate! Adding it to our list');\n\t\t\t\t\thostIceCandidates.add(e.candidate);\n\t\t\t\t\tawait this.putHostInfo(putHostInfoUrl, hostKey, hostIceCandidates, session);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tthis.openPeerConnection.onicegatheringstatechange = async (e) => {\n\t\t\tthis.logger.info(\n\t\t\t\t`onicegatheringstatechange - ${this.openPeerConnection!.iceGatheringState} - ${e}`\n\t\t\t);\n\t\t};\n\n\t\tthis.openPeerConnection.onicecandidateerror = async (e) => {\n\t\t\tthis.logger.error('peerConnection.onicecandidateerror', e);\n\t\t};\n\t};\n\n\tprivate setUpConnectionStateGathering = (getEndpointInfoUrl: string) => {\n\t\tif (this.openPeerConnection === null) {\n\t\t\tthis.changeState(\n\t\t\t\t'error',\n\t\t\t\t\"openPeerConnection is null. Unable to poll for the client's details\"\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.startPollingForConnection(getEndpointInfoUrl);\n\n\t\tthis.openPeerConnection.onconnectionstatechange = () => {\n\t\t\tthis.logger.info(`onconnectionstatechange - ${this.openPeerConnection!.connectionState}`);\n\t\t\tif (this.openPeerConnection!.connectionState === 'connected') {\n\t\t\t\tthis.stopPollingForConnection();\n\t\t\t}\n\t\t\tif (this.openPeerConnection!.connectionState === 'disconnected') {\n\t\t\t\tthis.startPollingForConnection(getEndpointInfoUrl);\n\t\t\t}\n\t\t\tif (this.openPeerConnection!.connectionState === 'failed') {\n\t\t\t\tthis.stopPollingForConnection();\n\t\t\t\tthis.changeState('error', { message: 'connection-failed' });\n\t\t\t}\n\t\t};\n\n\t\tthis.openPeerConnection.oniceconnectionstatechange = async (e) => {\n\t\t\tthis.logger.info(\n\t\t\t\t`oniceconnectionstatechange - ${this.openPeerConnection!.iceConnectionState} - ${e}`\n\t\t\t);\n\t\t\tif (this.openPeerConnection!.iceConnectionState === 'failed') {\n\t\t\t\tthis.logger.log('Failed to find a possible connection path');\n\t\t\t\tthis.changeState('error', { message: 'connection-impossible' });\n\t\t\t}\n\t\t};\n\t};\n\n\tprivate stopPollingForConnection = async () => {\n\t\tif (this.pollForIceTimer) {\n\t\t\tclearTimeout(this.pollForIceTimer);\n\t\t}\n\t\tthis.pollForIceTimer = null;\n\t};\n\n\tprivate startPollingForConnection = async (getEndpointInfoUrl: string) => {\n\t\tif (this.pollForIceTimer) {\n\t\t\tclearTimeout(this.pollForIceTimer);\n\t\t}\n\n\t\tawait this.pollForConnection(getEndpointInfoUrl);\n\n\t\tthis.pollForIceTimer = setTimeout(() => {\n\t\t\tthis.startPollingForConnection(getEndpointInfoUrl);\n\t\t}, this.pollTimeForIceInMs);\n\t};\n\n\tprivate createEndpoint = async (baseApi: string, session: RTCSessionDescriptionInit) => {\n\t\tconst response = await fetch(`${baseApi}/create`, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\tAccept: 'application/json',\n\t\t\t\t'Content-Type': 'application/json'\n\t\t\t},\n\t\t\tbody: JSON.stringify({ session })\n\t\t});\n\n\t\treturn response.json();\n\t};\n\n\tprivate fetchIceServers = async (baseApi: string) => {\n\t\tconst response = await fetch(`${baseApi}/ice-server-credentials`, {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\tAccept: 'application/json'\n\t\t\t}\n\t\t});\n\t\tif (!response.ok) {\n\t\t\tthrow new Error('Fetching Error!');\n\t\t}\n\t\tconst data = await response.json();\n\n\t\tif (data.success === false) {\n\t\t\tthrow new Error(data.message || 'Unknown error occurred');\n\t\t}\n\n\t\treturn data.iceServers;\n\t};\n\n\tprivate pollForConnection = async (getEndpointInfoUrl: string) => {\n\t\tif (this.openPeerConnection === null) {\n\t\t\tthis.changeState('error', \"openPeerConnection is null. Unable to retrieve Client's details\");\n\t\t\treturn;\n\t\t}\n\n\t\tthis.logger.log('polling for client ice candidates', this.openPeerConnection.iceGatheringState);\n\t\tconst { clientInfo } = await retrieveEndpointInfo(getEndpointInfoUrl);\n\n\t\tif (clientInfo && this.state === 'waiting-for-client') {\n\t\t\tthis.logger.log('Found a client that wants to connect!');\n\t\t\tthis.changeState('waiting-for-ice');\n\t\t\tawait this.openPeerConnection.setRemoteDescription(clientInfo.session);\n\t\t}\n\n\t\tfor (const iceCandidate of clientInfo?.iceCandidates ?? []) {\n\t\t\tawait this.openPeerConnection.addIceCandidate(iceCandidate);\n\t\t}\n\t};\n\n\tprivate setupDataChannelForTransfer = () => {\n\t\tif (this.dataChannel === null) {\n\t\t\tthis.changeState('error', 'dataChannel is null. Unable to setup a Data Channel');\n\t\t\treturn;\n\t\t}\n\n\t\tthis.dataChannel.onopen = () => {\n\t\t\tthis.logger.log('data channel opened');\n\t\t\tthis.changeState('waiting-for-data');\n\t\t};\n\n\t\tthis.dataChannel.onclose = () => {\n\t\t\tthis.logger.log('data channel closed');\n\t\t};\n\n\t\tthis.dataChannel.onerror = (e) => {\n\t\t\tthis.logger.log('channel.onerror', e);\n\t\t\tthis.changeState('error', { message: 'file-transfer' });\n\t\t};\n\t};\n\n\tprivate createDataChannel = () => {\n\t\tif (this.openPeerConnection === null) {\n\t\t\tthis.changeState('error', 'openPeerConnection is null. Unable to create a new Data Channel');\n\t\t\treturn null;\n\t\t}\n\n\t\tthis.channelNumber++;\n\t\tconst channelName = `data-channel-${this.channelNumber}`;\n\t\treturn this.openPeerConnection.createDataChannel(channelName);\n\t};\n\n\tprivate putHostInfo = async (\n\t\tputHostInfoUrl: string,\n\t\thostKey: string,\n\t\thostIceCandidates: Set,\n\t\tsession: RTCSessionDescriptionInit\n\t) => {\n\t\ttry {\n\t\t\tthis.logger.log('Updating host info with new list of ice candidates');\n\t\t\tconst response = await fetch(putHostInfoUrl, {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\thostKey,\n\t\t\t\t\ticeCandidates: [...hostIceCandidates],\n\t\t\t\t\tsession\n\t\t\t\t})\n\t\t\t});\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow Error('Could not update host info');\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tthis.changeState('error', err);\n\t\t}\n\t};\n}\n","import { FlottformChannelHost } from './flottform-channel-host';\nimport {\n\tBaseInputHost,\n\tBaseListeners,\n\tDEFAULT_WEBRTC_CONFIG,\n\tLogger,\n\tPOLL_TIME_IN_MS\n} from './internal';\n\ntype Listeners = BaseListeners & {\n\treceive: []; // Emitted to signal the start of receiving the file(s)\n\tprogress: {\n\t\tfileIndex: number;\n\t\ttotalFileCount: number;\n\t\tfileName: string;\n\t\tcurrentFileProgress: number;\n\t\toverallProgress: number;\n\t}[]; // Emitted to signal the progress of receiving the file(s)\n\tdone: [];\n\t'webrtc:waiting-for-file': [];\n\t'single-file-transferred': [file: File];\n};\n\nexport class FlottformFileInputHost extends BaseInputHost {\n\tprivate channel: FlottformChannelHost | null = null;\n\tprivate inputField?: HTMLInputElement;\n\tprivate logger: Logger;\n\tprivate filesMetaData: { name: string; type: string; size: number }[] = [];\n\tprivate filesTotalSize: number = 0;\n\tprivate receivedDataSize: number = 0;\n\tprivate currentFile: {\n\t\tindex: number;\n\t\treceivedSize: number;\n\t\tarrayBuffer: ArrayBuffer[];\n\t} | null = null;\n\tprivate link: string = '';\n\tprivate qrCode: string = '';\n\n\tconstructor({\n\t\tflottformApi,\n\t\tcreateClientUrl,\n\t\tinputField,\n\t\trtcConfiguration = DEFAULT_WEBRTC_CONFIG,\n\t\tpollTimeForIceInMs = POLL_TIME_IN_MS,\n\t\tlogger = console\n\t}: {\n\t\tflottformApi: string | URL;\n\t\tcreateClientUrl: (params: { endpointId: string }) => Promise;\n\t\tinputField?: HTMLInputElement;\n\t\trtcConfiguration?: RTCConfiguration;\n\t\tpollTimeForIceInMs?: number;\n\t\ttheme?: (myself: FlottformFileInputHost) => void;\n\t\tlogger?: Logger;\n\t}) {\n\t\tsuper();\n\t\tthis.channel = new FlottformChannelHost({\n\t\t\tflottformApi,\n\t\t\tcreateClientUrl,\n\t\t\trtcConfiguration,\n\t\t\tpollTimeForIceInMs,\n\t\t\tlogger\n\t\t});\n\t\tthis.inputField = inputField;\n\t\tthis.logger = logger;\n\n\t\tthis.registerListeners();\n\t}\n\n\tstart = () => {\n\t\tthis.channel?.start();\n\t};\n\n\tclose = () => {\n\t\tthis.channel?.close();\n\t};\n\n\tgetLink = () => {\n\t\tif (this.link === '') {\n\t\t\tthis.logger.error(\n\t\t\t\t'Flottform is currently establishing the connection. Link is unavailable for now!'\n\t\t\t);\n\t\t}\n\t\treturn this.link;\n\t};\n\n\tgetQrCode = () => {\n\t\tif (this.qrCode === '') {\n\t\t\tthis.logger.error(\n\t\t\t\t'Flottform is currently establishing the connection. qrCode is unavailable for now!'\n\t\t\t);\n\t\t}\n\t\treturn this.qrCode;\n\t};\n\n\tprivate handleIncomingData = (e: MessageEvent) => {\n\t\tif (typeof e.data === 'string') {\n\t\t\t// string can be either metadata or end transfer marker.\n\t\t\tconst message = JSON.parse(e.data);\n\t\t\tif (message.type === 'file-transfer-meta') {\n\t\t\t\t// Handle file metadata\n\t\t\t\tthis.filesMetaData = message.filesQueue;\n\t\t\t\tthis.currentFile = { index: 0, receivedSize: 0, arrayBuffer: [] };\n\t\t\t\tthis.filesTotalSize = message.totalSize;\n\t\t\t\t// Emit the start of receiving data\n\t\t\t\tthis.emit('receive');\n\t\t\t} else if (message.type === 'transfer-complete') {\n\t\t\t\tthis.emit('done');\n\t\t\t\tthis.channel?.close();\n\t\t\t}\n\t\t} else if (e.data instanceof ArrayBuffer) {\n\t\t\t// Handle file chunk\n\t\t\tif (this.currentFile) {\n\t\t\t\tthis.currentFile.arrayBuffer.push(e.data);\n\t\t\t\tthis.currentFile.receivedSize += e.data.byteLength;\n\t\t\t\tthis.receivedDataSize += e.data.byteLength;\n\n\t\t\t\tconst currentFileName = this.filesMetaData[this.currentFile.index]?.name as string;\n\n\t\t\t\tconst currentFileTotalSize = this.filesMetaData[this.currentFile.index]?.size as number;\n\n\t\t\t\tconst currentFileProgress = (this.currentFile.receivedSize / currentFileTotalSize).toFixed(\n\t\t\t\t\t2\n\t\t\t\t);\n\t\t\t\tconst overallProgress = (this.receivedDataSize / this.filesTotalSize).toFixed(2);\n\n\t\t\t\tthis.emit('progress', {\n\t\t\t\t\tfileIndex: this.currentFile.index,\n\t\t\t\t\ttotalFileCount: this.filesMetaData.length,\n\t\t\t\t\tfileName: currentFileName,\n\t\t\t\t\tcurrentFileProgress: parseFloat(currentFileProgress),\n\t\t\t\t\toverallProgress: parseFloat(overallProgress)\n\t\t\t\t});\n\n\t\t\t\tif (this.currentFile.receivedSize === currentFileTotalSize) {\n\t\t\t\t\t// Attach the current file to the given input field\n\t\t\t\t\tthis.appendFileToInputField(this.currentFile.index);\n\t\t\t\t\t// Initialize the values of currentFile to receive the next file\n\t\t\t\t\tthis.currentFile = {\n\t\t\t\t\t\tindex: this.currentFile.index + 1,\n\t\t\t\t\t\treceivedSize: 0,\n\t\t\t\t\t\tarrayBuffer: []\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate appendFileToInputField = (fileIndex: number) => {\n\t\tconst fileName = this.filesMetaData[fileIndex]?.name ?? 'no-name';\n\t\tconst fileType = this.filesMetaData[fileIndex]?.type ?? 'application/octet-stream';\n\n\t\tconst receivedFile = new File(this.currentFile?.arrayBuffer as ArrayBuffer[], fileName, {\n\t\t\ttype: fileType\n\t\t});\n\t\tthis.emit('single-file-transferred', receivedFile);\n\n\t\tif (!this.inputField) {\n\t\t\tthis.logger.warn(\n\t\t\t\t\"No input field provided!! You can listen to the 'single-file-transferred' event to handle the newly received file!\"\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst dt = new DataTransfer();\n\n\t\t// Add existing files from the input field to the DataTransfer object to avoid loosing them.\n\t\tif (this.inputField.files) {\n\t\t\tfor (const file of Array.from(this.inputField.files)) {\n\t\t\t\tdt.items.add(file);\n\t\t\t}\n\t\t}\n\n\t\tif (!this.inputField.multiple) {\n\t\t\tthis.logger.warn(\n\t\t\t\t\"The host's input field only supports one file. Incoming files from the client will overwrite any existing file, and only the last file received will remain attached.\"\n\t\t\t);\n\t\t\tdt.items.clear();\n\t\t}\n\n\t\tdt.items.add(receivedFile);\n\t\tthis.inputField.files = dt.files;\n\t};\n\n\tprivate registerListeners = () => {\n\t\tthis.channel?.on('new', () => {\n\t\t\tthis.emit('new');\n\t\t});\n\t\tthis.channel?.on('waiting-for-client', (event) => {\n\t\t\tthis.emit('webrtc:waiting-for-client', event);\n\t\t\tconst { qrCode, link } = event;\n\t\t\tthis.emit('endpoint-created', { link, qrCode });\n\t\t\tthis.link = link;\n\t\t\tthis.qrCode = qrCode;\n\t\t});\n\t\tthis.channel?.on('waiting-for-ice', () => {\n\t\t\tthis.emit('webrtc:waiting-for-ice');\n\t\t});\n\t\tthis.channel?.on('waiting-for-data', () => {\n\t\t\tthis.emit('webrtc:waiting-for-file');\n\t\t\tthis.emit('connected');\n\t\t});\n\t\tthis.channel?.on('receiving-data', (e) => {\n\t\t\tthis.handleIncomingData(e);\n\t\t});\n\t\tthis.channel?.on('disconnected', () => {\n\t\t\tthis.emit('disconnected');\n\t\t});\n\t\tthis.channel?.on('error', (error) => {\n\t\t\tthis.emit('error', error);\n\t\t});\n\t};\n}\n","import {\n\tClientState,\n\tEventEmitter,\n\tLogger,\n\tPOLL_TIME_IN_MS,\n\tgenerateSecretKey,\n\tretrieveEndpointInfo,\n\tsetIncludes\n} from './internal';\n\ntype Listeners = {\n\tinit: [];\n\t'retrieving-info-from-endpoint': [];\n\t'sending-client-info': [];\n\t'connecting-to-host': [];\n\tconnected: [];\n\t'connection-impossible': [];\n\tdone: [];\n\tdisconnected: [];\n\terror: [e: string];\n\tbufferedamountlow: [];\n};\n\nexport class FlottformChannelClient extends EventEmitter {\n\tprivate flottformApi: string | URL;\n\tprivate endpointId: string;\n\tprivate rtcConfiguration: RTCConfiguration;\n\tprivate pollTimeForIceInMs: number;\n\tprivate logger: Logger;\n\n\tprivate state: ClientState = 'init';\n\tprivate openPeerConnection: RTCPeerConnection | null = null;\n\tprivate dataChannel: RTCDataChannel | null = null;\n\tprivate pollForIceTimer: NodeJS.Timeout | number | null = null;\n\tprivate BUFFER_THRESHOLD = 128 * 1024; // 128KB buffer threshold (maximum of 4 chunks in the buffer waiting to be sent over the network)\n\n\tconstructor({\n\t\tendpointId,\n\t\tflottformApi,\n\t\trtcConfiguration,\n\t\tpollTimeForIceInMs = POLL_TIME_IN_MS,\n\t\tlogger = console\n\t}: {\n\t\tendpointId: string;\n\t\tflottformApi: string | URL;\n\t\trtcConfiguration: RTCConfiguration;\n\t\tpollTimeForIceInMs?: number;\n\t\tlogger?: Logger;\n\t}) {\n\t\tsuper();\n\t\tthis.endpointId = endpointId;\n\t\tthis.flottformApi = flottformApi;\n\t\tthis.rtcConfiguration = rtcConfiguration;\n\t\tthis.pollTimeForIceInMs = pollTimeForIceInMs;\n\t\tthis.logger = logger;\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate changeState = (newState: ClientState, details?: any) => {\n\t\tthis.state = newState;\n\t\tthis.emit(newState, details);\n\t\tthis.logger.info(`**Client State changed to: ${newState}`, details == undefined ? '' : details);\n\t};\n\n\tstart = async () => {\n\t\tif (this.openPeerConnection) {\n\t\t\tthis.close();\n\t\t}\n\t\tconst baseApi = (\n\t\t\tthis.flottformApi instanceof URL ? this.flottformApi : new URL(this.flottformApi)\n\t\t)\n\t\t\t.toString()\n\t\t\t.replace(/\\/$/, '');\n\n\t\t// For now the fetching can be done outside of these classes and should be passed as an argument.\n\t\t\n\t\t/* try {\n\t\t\tthis.rtcConfiguration.iceServers = await this.fetchIceServers(baseApi);\n\t\t} catch (error) {\n\t\t\t// Use the default configuration as a fallback\n\t\t\tthis.logger.error(error);\n\t\t} */\n\n\t\tthis.openPeerConnection = new RTCPeerConnection(this.rtcConfiguration);\n\t\tconst clientKey = generateSecretKey();\n\t\tconst clientIceCandidates = new Set();\n\t\tconst getEndpointInfoUrl = `${this.flottformApi}/${this.endpointId}`;\n\t\tconst putClientInfoUrl = `${this.flottformApi}/${this.endpointId}/client`;\n\n\t\tthis.changeState('retrieving-info-from-endpoint');\n\t\tconst { hostInfo } = await retrieveEndpointInfo(getEndpointInfoUrl);\n\t\tawait this.openPeerConnection.setRemoteDescription(hostInfo.session);\n\t\tconst session = await this.openPeerConnection.createAnswer();\n\t\tawait this.openPeerConnection.setLocalDescription(session);\n\n\t\tthis.setUpConnectionStateGathering(getEndpointInfoUrl);\n\t\tthis.setUpClientIceGathering(putClientInfoUrl, clientKey, clientIceCandidates, session);\n\t\tthis.openPeerConnection.ondatachannel = (e) => {\n\t\t\tthis.logger.info(`ondatachannel: ${e.channel}`);\n\t\t\tthis.changeState('connected');\n\t\t\tthis.dataChannel = e.channel;\n\t\t\t// Set the maximum amount of data waiting inside the datachannel's buffer\n\t\t\tthis.dataChannel.bufferedAmountLowThreshold = this.BUFFER_THRESHOLD;\n\t\t\t// Set the listener to listen then emit an event when the buffer has more space available and can be used to send more data\n\t\t\tthis.dataChannel.onbufferedamountlow = () => {\n\t\t\t\tthis.emit('bufferedamountlow');\n\t\t\t};\n\t\t\tthis.dataChannel.onopen = (e) => {\n\t\t\t\tthis.logger.info(`ondatachannel - onopen: ${e.type}`);\n\t\t\t};\n\t\t};\n\n\t\tthis.changeState('sending-client-info');\n\t\tawait this.putClientInfo(putClientInfoUrl, clientKey, clientIceCandidates, session);\n\n\t\tthis.changeState('connecting-to-host');\n\t\tthis.startPollingForIceCandidates(getEndpointInfoUrl);\n\t};\n\n\tclose = () => {\n\t\tif (this.openPeerConnection) {\n\t\t\tthis.openPeerConnection.close();\n\t\t\tthis.openPeerConnection = null;\n\t\t\tthis.stopPollingForIceCandidates();\n\t\t}\n\t\tthis.changeState('disconnected');\n\t};\n\n\t// sendData = (data: string | Blob | ArrayBuffer | ArrayBufferView) => {\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tsendData = (data: any) => {\n\t\tif (this.dataChannel == null) {\n\t\t\tthis.changeState('error', 'dataChannel is null. Unable to send the file to the Host!');\n\t\t\treturn;\n\t\t} else if (!this.canSendMoreData()) {\n\t\t\tthis.logger.warn('Data channel is full! Cannot send data at the moment');\n\t\t\treturn;\n\t\t}\n\t\tthis.dataChannel.send(data);\n\t};\n\n\tcanSendMoreData = () => {\n\t\treturn (\n\t\t\tthis.dataChannel &&\n\t\t\tthis.dataChannel.bufferedAmount < this.dataChannel.bufferedAmountLowThreshold\n\t\t);\n\t};\n\n\tprivate setUpClientIceGathering = (\n\t\tputClientInfoUrl: string,\n\t\tclientKey: string,\n\t\tclientIceCandidates: Set,\n\t\tsession: RTCSessionDescriptionInit\n\t) => {\n\t\tif (this.openPeerConnection === null) {\n\t\t\tthis.changeState(\n\t\t\t\t'error',\n\t\t\t\t'openPeerConnection is null. Unable to gather Client ICE candidates'\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.openPeerConnection.onicecandidate = async (e) => {\n\t\t\tthis.logger.info(\n\t\t\t\t`onicecandidate - ${this.openPeerConnection!.connectionState} - ${e.candidate}`\n\t\t\t);\n\t\t\tif (e.candidate) {\n\t\t\t\tif (!setIncludes(clientIceCandidates, e.candidate)) {\n\t\t\t\t\tthis.logger.log('client found new ice candidate! Adding it to our list');\n\t\t\t\t\tclientIceCandidates.add(e.candidate);\n\t\t\t\t\tawait this.putClientInfo(putClientInfoUrl, clientKey, clientIceCandidates, session);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tthis.openPeerConnection.onicegatheringstatechange = async () => {\n\t\t\tthis.logger.info(`onicegatheringstatechange - ${this.openPeerConnection!.iceGatheringState}`);\n\t\t};\n\t\tthis.openPeerConnection.onicecandidateerror = (e) => {\n\t\t\tthis.logger.error(`onicecandidateerror - ${this.openPeerConnection!.connectionState}`, e);\n\t\t};\n\t};\n\tprivate setUpConnectionStateGathering = (getEndpointInfoUrl: string) => {\n\t\tif (this.openPeerConnection === null) {\n\t\t\tthis.changeState(\n\t\t\t\t'error',\n\t\t\t\t'openPeerConnection is null. Unable to gather Client ICE candidates'\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tthis.openPeerConnection.onconnectionstatechange = () => {\n\t\t\tthis.logger.info(`onconnectionstatechange - ${this.openPeerConnection!.connectionState}`);\n\t\t\tif (this.openPeerConnection!.connectionState === 'connected') {\n\t\t\t\tthis.stopPollingForIceCandidates();\n\t\t\t\tif (this.state === 'connecting-to-host') {\n\t\t\t\t\tthis.changeState('connected');\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (this.openPeerConnection!.connectionState === 'disconnected') {\n\t\t\t\tthis.startPollingForIceCandidates(getEndpointInfoUrl);\n\t\t\t}\n\t\t\tif (this.openPeerConnection!.connectionState === 'failed') {\n\t\t\t\tthis.stopPollingForIceCandidates();\n\t\t\t\tif (this.state !== 'done') {\n\t\t\t\t\tthis.changeState('disconnected');\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tthis.openPeerConnection.oniceconnectionstatechange = () => {\n\t\t\tthis.logger.info(\n\t\t\t\t`oniceconnectionstatechange - ${this.openPeerConnection!.iceConnectionState}`\n\t\t\t);\n\t\t\tif (this.openPeerConnection!.iceConnectionState === 'failed') {\n\t\t\t\tthis.logger.log('Failed to find a possible connection path');\n\t\t\t\tthis.changeState('connection-impossible');\n\t\t\t}\n\t\t};\n\t};\n\tprivate stopPollingForIceCandidates = async () => {\n\t\tif (this.pollForIceTimer) {\n\t\t\tclearTimeout(this.pollForIceTimer);\n\t\t}\n\t\tthis.pollForIceTimer = null;\n\t};\n\tprivate startPollingForIceCandidates = async (getEndpointInfoUrl: string) => {\n\t\tif (this.pollForIceTimer) {\n\t\t\tclearTimeout(this.pollForIceTimer);\n\t\t}\n\n\t\tawait this.pollForConnection(getEndpointInfoUrl);\n\n\t\tthis.pollForIceTimer = setTimeout(this.startPollingForIceCandidates, this.pollTimeForIceInMs);\n\t};\n\tprivate pollForConnection = async (getEndpointInfoUrl: string) => {\n\t\tif (this.openPeerConnection === null) {\n\t\t\tthis.changeState('error', \"openPeerConnection is null. Unable to retrieve Host's details\");\n\t\t\treturn;\n\t\t}\n\n\t\tthis.logger.log('polling for host ice candidates', this.openPeerConnection.iceGatheringState);\n\t\tconst { hostInfo } = await retrieveEndpointInfo(getEndpointInfoUrl);\n\t\tfor (const iceCandidate of hostInfo.iceCandidates) {\n\t\t\tawait this.openPeerConnection.addIceCandidate(iceCandidate);\n\t\t}\n\t};\n\tprivate putClientInfo = async (\n\t\tputClientInfoUrl: string,\n\t\tclientKey: string,\n\t\tclientIceCandidates: Set,\n\t\tsession: RTCSessionDescriptionInit\n\t) => {\n\t\tthis.logger.log('Updating client info with new list of ice candidates');\n\t\tconst response = await fetch(putClientInfoUrl, {\n\t\t\tmethod: 'PUT',\n\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\tbody: JSON.stringify({\n\t\t\t\tclientKey,\n\t\t\t\ticeCandidates: [...clientIceCandidates],\n\t\t\t\tsession\n\t\t\t})\n\t\t});\n\t\tif (!response.ok) {\n\t\t\tthrow Error('Could not update client info. Did another peer already connect?');\n\t\t}\n\t};\n\tprivate fetchIceServers = async (baseApi: string) => {\n\t\tconst response = await fetch(`${baseApi}/ice-server-credentials`, {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\tAccept: 'application/json'\n\t\t\t}\n\t\t});\n\t\tif (!response.ok) {\n\t\t\tthrow new Error('Fetching Error!');\n\t\t}\n\t\tconst data = await response.json();\n\n\t\tif (data.success === false) {\n\t\t\tthrow new Error(data.message || 'Unknown error occurred');\n\t\t}\n\n\t\treturn data.iceServers;\n\t};\n}\n","import { FlottformChannelClient } from './flottform-channel-client';\nimport { DEFAULT_WEBRTC_CONFIG, EventEmitter, Logger, POLL_TIME_IN_MS } from './internal';\n\ntype Listeners = {\n\tconnected: [];\n\t'webrtc:connection-impossible': [];\n\tsending: []; // Emitted to signal the start of sending the file(s)\n\tprogress: [{ fileIndex: number; fileName: string; progress: number }]; // Emitted to signal the progress of sending the file(s)\n\tdone: [];\n\tdisconnected: [];\n\terror: [e: string];\n};\n\ntype MetaData = {\n\ttype: 'file-transfer-meta';\n\tfilesQueue: { name: string; type: string; size: number }[];\n\ttotalSize: number;\n};\n\nexport class FlottformFileInputClient extends EventEmitter {\n\tprivate channel: FlottformChannelClient | null = null;\n\tprivate inputField: HTMLInputElement;\n\tprivate chunkSize: number = 16384; // 16 KB chunks\n\tprivate filesMetaData: { name: string; type: string; size: number }[] = [];\n\tprivate filesArrayBuffer: ArrayBuffer[] = [];\n\tprivate currentFileIndex = 0;\n\tprivate currentChunkIndex = 0;\n\tprivate allFilesSent = false;\n\tprivate logger: Logger;\n\n\tconstructor({\n\t\tendpointId,\n\t\tfileInput,\n\t\tflottformApi,\n\t\trtcConfiguration = DEFAULT_WEBRTC_CONFIG,\n\t\tpollTimeForIceInMs = POLL_TIME_IN_MS,\n\t\tlogger = console\n\t}: {\n\t\tendpointId: string;\n\t\tfileInput: HTMLInputElement;\n\t\tflottformApi: string;\n\t\trtcConfiguration?: RTCConfiguration;\n\t\tpollTimeForIceInMs?: number;\n\t\tlogger?: Logger;\n\t}) {\n\t\tsuper();\n\t\tthis.channel = new FlottformChannelClient({\n\t\t\tendpointId,\n\t\t\tflottformApi,\n\t\t\trtcConfiguration,\n\t\t\tpollTimeForIceInMs,\n\t\t\tlogger\n\t\t});\n\t\tthis.inputField = fileInput;\n\t\tthis.logger = logger;\n\t\tthis.registerListeners();\n\t}\n\tstart = () => {\n\t\tthis.channel?.start();\n\t};\n\n\tclose = () => {\n\t\tthis.channel?.close();\n\t};\n\n\tprivate createMetaData = (inputElement: HTMLInputElement): MetaData | null => {\n\t\tif (!inputElement.files) return null;\n\n\t\t// Generate all the metadata necessary to send all of the files\n\t\tconst files = Array.from(inputElement.files);\n\t\tconst filesQueue = files.map((file) => ({\n\t\t\tname: file.name,\n\t\t\ttype: file.type, // We're dividing each file into chuncks no matter what the type of the file.\n\t\t\tsize: file.size\n\t\t}));\n\t\treturn {\n\t\t\ttype: 'file-transfer-meta',\n\t\t\tfilesQueue,\n\t\t\ttotalSize: filesQueue.reduce((sum, file) => sum + file.size, 0)\n\t\t};\n\t};\n\n\tprivate createArrayBuffers = async (inputElement: HTMLInputElement) => {\n\t\tif (!inputElement.files) return null;\n\n\t\t// Generate all the arrayBuffers of the available files\n\t\tconst files = Array.from(inputElement.files);\n\t\treturn await Promise.all(files.map(async (file) => await file.arrayBuffer()));\n\t};\n\n\tsendFiles = async () => {\n\t\tconst metaData = this.createMetaData(this.inputField);\n\t\tconst filesArrayBuffer = await this.createArrayBuffers(this.inputField);\n\t\tif (!metaData || !filesArrayBuffer)\n\t\t\tthrow new Error(\"Can't find the files that you want to send!\");\n\n\t\tthis.filesMetaData = metaData.filesQueue;\n\t\tthis.filesArrayBuffer = filesArrayBuffer;\n\n\t\tthis.channel?.sendData(JSON.stringify(metaData));\n\n\t\tthis.emit('sending');\n\t\tthis.startSendingFiles();\n\t};\n\n\tprivate startSendingFiles = () => {\n\t\tthis.sendNextChunk();\n\t};\n\n\tprivate sendNextChunk = async () => {\n\t\tconst totalNumberOfFiles = this.filesMetaData.length;\n\t\tif (this.allFilesSent || this.currentFileIndex >= totalNumberOfFiles) {\n\t\t\t// All files are sent\n\t\t\tthis.logger.log('All files are sent');\n\t\t\tthis.channel?.sendData(JSON.stringify({ type: 'transfer-complete' }));\n\t\t\tthis.allFilesSent = true;\n\t\t\tthis.channel?.off('bufferedamountlow', this.startSendingFiles);\n\t\t\tthis.emit('done');\n\t\t\treturn;\n\t\t}\n\t\tconst currentFileArrayBuffer = this.filesArrayBuffer[this.currentFileIndex];\n\t\tif (!currentFileArrayBuffer) {\n\t\t\tthrow new Error(`Can't find the ArrayBuffer for the file number ${this.currentFileIndex}`);\n\t\t}\n\t\tconst currentFileSize = currentFileArrayBuffer.byteLength;\n\t\tconst fileName = this.filesMetaData[this.currentFileIndex]!.name;\n\n\t\twhile (this.currentChunkIndex * this.chunkSize < currentFileSize) {\n\t\t\t// The file still has some chunks left\n\t\t\tif (!this.channel?.canSendMoreData()) {\n\t\t\t\t// Buffer is full. Pause sending the chunks\n\t\t\t\tthis.logger.log('Buffer is full. Pausing sending chunks!');\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tconst progress = ((this.currentChunkIndex * this.chunkSize) / currentFileSize).toFixed(2);\n\n\t\t\tthis.emit('progress', {\n\t\t\t\tfileIndex: this.currentFileIndex,\n\t\t\t\tfileName,\n\t\t\t\tprogress: parseFloat(progress)\n\t\t\t});\n\n\t\t\tconst start = this.currentChunkIndex * this.chunkSize;\n\t\t\tconst end = Math.min((this.currentChunkIndex + 1) * this.chunkSize, currentFileSize);\n\t\t\tthis.channel?.sendData(currentFileArrayBuffer.slice(start, end));\n\t\t\tthis.currentChunkIndex++;\n\t\t}\n\t\t// Now either: the buffer is full OR all the chunks of the file have been sent.\n\t\tif (this.currentChunkIndex * this.chunkSize >= currentFileSize) {\n\t\t\t// File is fully sent move to the next one\n\t\t\tthis.logger.log(`File ${fileName} fully sent. Moving to next file.`);\n\t\t\tthis.currentFileIndex++;\n\t\t\tthis.currentChunkIndex = 0;\n\t\t\tthis.sendNextChunk(); // Recursion used to send the chunks of the next file\n\t\t} else {\n\t\t\t// Paused waiting for buffer space. Will try again shortly.\n\t\t\tsetTimeout(this.sendNextChunk, 100); // Retry after a short delay\n\t\t}\n\t};\n\n\tprivate registerListeners = () => {\n\t\tthis.channel?.on('init', () => {\n\t\t\t// TODO: Implement Default UI.\n\t\t});\n\t\tthis.channel?.on('retrieving-info-from-endpoint', () => {\n\t\t\t// TODO: Implement Default UI.\n\t\t});\n\t\tthis.channel?.on('sending-client-info', () => {\n\t\t\t// TODO: Implement Default UI.\n\t\t});\n\t\tthis.channel?.on('connecting-to-host', () => {\n\t\t\t// TODO: Implement Default UI.\n\t\t});\n\t\tthis.channel?.on('connected', () => {\n\t\t\tthis.emit('connected');\n\t\t\t// TODO: Implement Default UI.\n\t\t});\n\t\tthis.channel?.on('connection-impossible', () => {\n\t\t\tthis.emit('webrtc:connection-impossible');\n\t\t\t// TODO: Implement Default UI.\n\t\t});\n\t\tthis.channel?.on('done', () => {\n\t\t\tthis.emit('done');\n\t\t\t// TODO: Implement Default UI.\n\t\t});\n\t\tthis.channel?.on('disconnected', () => {\n\t\t\tthis.emit('disconnected');\n\t\t\t// TODO: Implement Default UI.\n\t\t});\n\t\tthis.channel?.on('error', (e) => {\n\t\t\tthis.emit('error', e);\n\t\t\t// TODO: Implement Default UI.\n\t\t});\n\t\tthis.channel?.on('bufferedamountlow', this.startSendingFiles);\n\t};\n}\n","import { FlottformChannelClient } from './flottform-channel-client';\nimport { DEFAULT_WEBRTC_CONFIG, EventEmitter, Logger, POLL_TIME_IN_MS } from './internal';\n\ntype Listeners = {\n\tconnected: [];\n\t'webrtc:connection-impossible': [];\n\tsending: []; // Emitted to signal the start of sending the file(s)\n\tdone: [];\n\tdisconnected: [];\n\terror: [e: string];\n};\n\nexport class FlottformTextInputClient extends EventEmitter {\n\tprivate channel: FlottformChannelClient | null = null;\n\tprivate logger: Logger;\n\n\tconstructor({\n\t\tendpointId,\n\t\tflottformApi,\n\t\trtcConfiguration = DEFAULT_WEBRTC_CONFIG,\n\t\tpollTimeForIceInMs = POLL_TIME_IN_MS,\n\t\tlogger = console\n\t}: {\n\t\tendpointId: string;\n\t\tflottformApi: string;\n\t\trtcConfiguration?: RTCConfiguration;\n\t\tpollTimeForIceInMs?: number;\n\t\tlogger?: Logger;\n\t}) {\n\t\tsuper();\n\t\tthis.channel = new FlottformChannelClient({\n\t\t\tendpointId,\n\t\t\tflottformApi,\n\t\t\trtcConfiguration,\n\t\t\tpollTimeForIceInMs,\n\t\t\tlogger\n\t\t});\n\t\tthis.logger = logger;\n\t\tthis.registerListeners();\n\t}\n\tstart = () => {\n\t\tthis.channel?.start();\n\t};\n\n\tclose = () => {\n\t\t// Should be called once all the text has been sent.\n\t\tthis.channel?.close();\n\t};\n\n\tsendText = (text: string) => {\n\t\t// For now, I didn't handle very large texts since for most use cases the text won't exceed the size of 1 chunk ( 16KB )\n\t\tthis.emit('sending');\n\t\tthis.channel?.sendData(text);\n\t\tthis.emit('done');\n\t};\n\n\tprivate registerListeners = () => {\n\t\tthis.channel?.on('init', () => {});\n\t\tthis.channel?.on('retrieving-info-from-endpoint', () => {});\n\t\tthis.channel?.on('sending-client-info', () => {});\n\t\tthis.channel?.on('connecting-to-host', () => {});\n\t\tthis.channel?.on('connected', () => {\n\t\t\tthis.emit('connected');\n\t\t});\n\t\tthis.channel?.on('connection-impossible', () => {\n\t\t\tthis.emit('webrtc:connection-impossible');\n\t\t});\n\t\tthis.channel?.on('done', () => {\n\t\t\tthis.emit('done');\n\t\t});\n\t\tthis.channel?.on('disconnected', () => {\n\t\t\tthis.emit('disconnected');\n\t\t});\n\t\tthis.channel?.on('error', (e) => {\n\t\t\tthis.emit('error', e);\n\t\t});\n\t};\n}\n","import { FlottformChannelHost } from './flottform-channel-host';\nimport {\n\tBaseInputHost,\n\tBaseListeners,\n\tDEFAULT_WEBRTC_CONFIG,\n\tLogger,\n\tPOLL_TIME_IN_MS\n} from './internal';\n\ntype Listeners = BaseListeners & {\n\tdone: [data: string];\n\t'webrtc:waiting-for-text': [];\n\treceive: [];\n\t'webrtc:waiting-for-data': [];\n};\n\nexport class FlottformTextInputHost extends BaseInputHost {\n\tprivate channel: FlottformChannelHost | null = null;\n\tprivate logger: Logger;\n\tprivate link: string = '';\n\tprivate qrCode: string = '';\n\tprivate inputField: HTMLInputElement | HTMLTextAreaElement | undefined = undefined;\n\n\tconstructor({\n\t\tflottformApi,\n\t\tcreateClientUrl,\n\t\tinputField = undefined,\n\t\trtcConfiguration = DEFAULT_WEBRTC_CONFIG,\n\t\tpollTimeForIceInMs = POLL_TIME_IN_MS,\n\t\tlogger = console\n\t}: {\n\t\tflottformApi: string | URL;\n\t\tcreateClientUrl: (params: { endpointId: string }) => Promise;\n\t\tinputField?: HTMLInputElement | HTMLTextAreaElement;\n\t\trtcConfiguration?: RTCConfiguration;\n\t\tpollTimeForIceInMs?: number;\n\t\tlogger?: Logger;\n\t}) {\n\t\tsuper();\n\t\tthis.channel = new FlottformChannelHost({\n\t\t\tflottformApi,\n\t\t\tcreateClientUrl,\n\t\t\trtcConfiguration,\n\t\t\tpollTimeForIceInMs,\n\t\t\tlogger\n\t\t});\n\t\tthis.logger = logger;\n\t\tthis.inputField = inputField;\n\n\t\tthis.registerListeners();\n\t}\n\n\tstart = () => {\n\t\tthis.channel?.start();\n\t};\n\n\tclose = () => {\n\t\tthis.channel?.close();\n\t};\n\n\tgetLink = () => {\n\t\tif (this.link === '') {\n\t\t\tthis.logger.error(\n\t\t\t\t'Flottform is currently establishing the connection. Link is unavailable for now!'\n\t\t\t);\n\t\t}\n\t\treturn this.link;\n\t};\n\n\tgetQrCode = () => {\n\t\tif (this.qrCode === '') {\n\t\t\tthis.logger.error(\n\t\t\t\t'Flottform is currently establishing the connection. qrCode is unavailable for now!'\n\t\t\t);\n\t\t}\n\t\treturn this.qrCode;\n\t};\n\n\tprivate handleIncomingData = (e: MessageEvent) => {\n\t\tthis.emit('receive');\n\t\t// We suppose that the data received is small enough to be all included in 1 message\n\t\tthis.emit('done', e.data);\n\t\tif (this.inputField) {\n\t\t\tthis.inputField.value = e.data;\n\t\t\tconst event = new Event('change');\n\t\t\tthis.inputField.dispatchEvent(event);\n\t\t}\n\t};\n\n\tprivate registerListeners = () => {\n\t\tthis.channel?.on('new', () => {\n\t\t\tthis.emit('new');\n\t\t});\n\t\tthis.channel?.on('waiting-for-client', (event) => {\n\t\t\tthis.emit('webrtc:waiting-for-client', event);\n\t\t\tconst { qrCode, link } = event;\n\t\t\tthis.emit('endpoint-created', { link, qrCode });\n\t\t\tthis.link = link;\n\t\t\tthis.qrCode = qrCode;\n\t\t});\n\t\tthis.channel?.on('waiting-for-ice', () => {\n\t\t\tthis.emit('webrtc:waiting-for-ice');\n\t\t});\n\t\tthis.channel?.on('waiting-for-data', () => {\n\t\t\tthis.emit('webrtc:waiting-for-data');\n\t\t\tthis.emit('connected');\n\t\t});\n\t\tthis.channel?.on('receiving-data', (e) => {\n\t\t\tthis.handleIncomingData(e);\n\t\t});\n\t\tthis.channel?.on('disconnected', () => {\n\t\t\tthis.emit('disconnected');\n\t\t});\n\t\tthis.channel?.on('error', (error) => {\n\t\t\tthis.emit('error', error);\n\t\t});\n\t};\n}\n","import { FlottformFileInputHost } from './flottform-file-input-host';\nimport { FlottformTextInputHost } from './flottform-text-input-host';\nimport { BaseInputHost, BaseListeners } from './internal';\nimport { FlottformCreateFileParams, FlottformCreateTextParams } from './types';\n\nconst openInputsList = () => {\n\tconst flottformElementsContainerWrapper: HTMLDivElement = document.querySelector(\n\t\t'.flottform-elements-container-wrapper'\n\t)!;\n\tconst openerSvg: SVGElement = document.querySelector('.flottform-opener-triangle')!;\n\tflottformElementsContainerWrapper.classList.toggle('flottform-open');\n\topenerSvg.classList.toggle('flottform-button-svg-open');\n};\n\nconst initRoot = (\n\tflottformRootTitle?: string,\n\tflottformRootDescription?: string,\n\tadditionalComponentClass?: string\n) => {\n\tconst flottformRoot = document.createElement('div');\n\tflottformRoot.setAttribute('class', `flottform-root${additionalComponentClass ?? ''}`);\n\tconst flottformListOpenerButton = createFlottformOpenerButton(flottformRootTitle);\n\tflottformRoot.appendChild(flottformListOpenerButton);\n\tconst flottformElementsContainerWrapper =\n\t\tcreateFlottformItemsContainerWithTransition(flottformRootDescription);\n\tflottformRoot.appendChild(flottformElementsContainerWrapper);\n\treturn flottformRoot;\n};\n\nconst createLinkAndQrCode = (qrCode: string, link: string) => {\n\tconst createChannelQrCode = document.createElement('img');\n\tcreateChannelQrCode.setAttribute('class', 'flottform-qr-code');\n\tcreateChannelQrCode.setAttribute('src', qrCode);\n\n\tconst createChannelLinkWithOffer = document.createElement('div');\n\tcreateChannelLinkWithOffer.setAttribute('class', 'flottform-link-offer');\n\tcreateChannelLinkWithOffer.innerText = link;\n\treturn {\n\t\tcreateChannelQrCode,\n\t\tcreateChannelLinkWithOffer\n\t};\n};\nexport const createDefaultFlottformComponent = ({\n\tflottformAnchorElement,\n\tflottformRootElement,\n\tadditionalComponentClass,\n\tflottformRootTitle,\n\tflottformRootDescription\n}: {\n\tflottformAnchorElement: HTMLElement;\n\tflottformRootElement?: HTMLElement;\n\tadditionalComponentClass?: string;\n\tflottformRootTitle?: string;\n\tflottformRootDescription?: string;\n}): {\n\tflottformRoot: HTMLElement;\n\tcreateFileItem: (params: FlottformCreateFileParams) => void;\n\tcreateTextItem: (params: FlottformCreateTextParams) => void;\n\tgetAllFlottformItems: () => NodeListOf | null;\n} => {\n\tconst flottformRoot: HTMLElement =\n\t\tflottformRootElement ??\n\t\tdocument.querySelector('.flottform-root') ??\n\t\tinitRoot(flottformRootTitle, flottformRootDescription, additionalComponentClass);\n\tconst flottformElementsContainer = flottformRoot.querySelector('.flottform-elements-container')!;\n\tconst flottformElementsContainerWrapper = flottformRoot.querySelector(\n\t\t'.flottform-elements-container-wrapper'\n\t)!;\n\tflottformElementsContainerWrapper.appendChild(flottformElementsContainer);\n\tflottformRoot.appendChild(flottformElementsContainerWrapper);\n\n\tflottformAnchorElement.appendChild(flottformRoot);\n\treturn {\n\t\tflottformRoot,\n\t\tgetAllFlottformItems: () => {\n\t\t\tconst flottformInputsList = flottformRoot.querySelector('.flottform-inputs-list');\n\t\t\tif (!flottformInputsList) {\n\t\t\t\tconsole.error('No element with class .flottform-inputs-list found');\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn flottformInputsList.childNodes as NodeListOf;\n\t\t},\n\t\tcreateFileItem: ({\n\t\t\tflottformApi,\n\t\t\tcreateClientUrl,\n\t\t\tinputField,\n\t\t\tid,\n\t\t\tadditionalItemClasses,\n\t\t\tlabel,\n\t\t\tbuttonLabel,\n\t\t\tonErrorText,\n\t\t\tonSuccessText\n\t\t}: {\n\t\t\tflottformApi: string;\n\t\t\tcreateClientUrl: (params: { endpointId: string }) => Promise;\n\t\t\tinputField: HTMLInputElement;\n\t\t\tid?: string;\n\t\t\tadditionalItemClasses?: string;\n\t\t\tlabel?: string;\n\t\t\tbuttonLabel?: string;\n\t\t\tonErrorText?: string | ((error: Error) => string);\n\t\t\tonSuccessText?: string;\n\t\t}) => {\n\t\t\tconst flottformBaseInputHost = new FlottformFileInputHost({\n\t\t\t\tflottformApi,\n\t\t\t\tcreateClientUrl,\n\t\t\t\tinputField\n\t\t\t});\n\n\t\t\tconst {\n\t\t\t\tflottformItem,\n\t\t\t\tstatusInformation,\n\t\t\t\trefreshChannelButton,\n\t\t\t\tflottformStateItemsContainer\n\t\t\t} = createBaseFlottformItems({\n\t\t\t\tflottformBaseInputHost,\n\t\t\t\tadditionalItemClasses,\n\t\t\t\tlabel,\n\t\t\t\tbuttonLabel,\n\t\t\t\tonErrorText\n\t\t\t});\n\n\t\t\tconst flottformItemsList = flottformRoot.querySelector('.flottform-inputs-list')!;\n\n\t\t\tflottformItemsList.appendChild(flottformItem);\n\t\t\tflottformElementsContainer.appendChild(flottformItemsList);\n\n\t\t\thandleFileInputStates({\n\t\t\t\tflottformItem,\n\t\t\t\tstatusInformation,\n\t\t\t\trefreshChannelButton,\n\t\t\t\tflottformStateItemsContainer,\n\t\t\t\tflottformFileInputHost: flottformBaseInputHost,\n\t\t\t\tid,\n\t\t\t\tonSuccessText\n\t\t\t});\n\t\t},\n\t\tcreateTextItem: ({\n\t\t\tflottformApi,\n\t\t\tcreateClientUrl,\n\t\t\tinputField,\n\t\t\tid,\n\t\t\tadditionalItemClasses,\n\t\t\tlabel,\n\t\t\tbuttonLabel,\n\t\t\tonErrorText,\n\t\t\tonSuccessText\n\t\t}: {\n\t\t\tflottformApi: string;\n\t\t\tcreateClientUrl: (params: { endpointId: string }) => Promise;\n\t\t\tinputField?: HTMLInputElement | HTMLTextAreaElement;\n\t\t\tid?: string;\n\t\t\tadditionalItemClasses?: string;\n\t\t\tlabel?: string;\n\t\t\tbuttonLabel?: string;\n\t\t\tonErrorText?: string | ((error: Error) => string);\n\t\t\tonSuccessText?: string;\n\t\t}) => {\n\t\t\tconst flottformBaseInputHost = new FlottformTextInputHost({\n\t\t\t\tflottformApi,\n\t\t\t\tcreateClientUrl,\n\t\t\t\tinputField\n\t\t\t});\n\n\t\t\tconst { flottformItem, statusInformation, refreshChannelButton } = createBaseFlottformItems({\n\t\t\t\tflottformBaseInputHost,\n\t\t\t\tadditionalItemClasses,\n\t\t\t\tlabel,\n\t\t\t\tbuttonLabel,\n\t\t\t\tonErrorText\n\t\t\t});\n\t\t\tconst flottformItemsList = flottformRoot.querySelector('.flottform-inputs-list')!;\n\n\t\t\tflottformItemsList.appendChild(flottformItem);\n\t\t\tflottformElementsContainer.appendChild(flottformItemsList);\n\n\t\t\thandleTextInputStates({\n\t\t\t\tflottformItem,\n\t\t\t\tstatusInformation,\n\t\t\t\trefreshChannelButton,\n\t\t\t\tflottformTextInputHost: flottformBaseInputHost,\n\t\t\t\tid,\n\t\t\t\tonSuccessText\n\t\t\t});\n\t\t}\n\t};\n};\n\nconst createBaseFlottformItems = ({\n\tflottformBaseInputHost,\n\tadditionalItemClasses,\n\tlabel,\n\tbuttonLabel,\n\tonErrorText\n}: {\n\tflottformBaseInputHost: BaseInputHost;\n\n\tadditionalItemClasses?: string;\n\tlabel?: string;\n\tbuttonLabel?: string;\n\tonErrorText?: string | ((error: Error) => string);\n}) => {\n\tconst flottformItem = createFlottformListItem(additionalItemClasses);\n\tsetLabelForFlottformItem({ label, flottformItem });\n\tconst statusInformation = createStatusInformation();\n\tconst createChannelButton = createFlottformChannelButton(buttonLabel);\n\tcreateChannelButton.addEventListener('click', () => flottformBaseInputHost.start());\n\tconst flottformStateItemsContainer = createStateItemsContainer(createChannelButton);\n\tflottformItem.appendChild(flottformStateItemsContainer);\n\tconst refreshChannelButton = createFlottformChannelRefreshButton();\n\trefreshChannelButton.addEventListener('click', () => flottformBaseInputHost.start());\n\n\t// listen to events -> change elements depending on them\n\tflottformBaseInputHost.on('endpoint-created', ({ link, qrCode }) => {\n\t\tconst { createChannelQrCode, createChannelLinkWithOffer } = createLinkAndQrCode(qrCode, link);\n\t\tconst copyToClipboardButton = createCopyToClipboardButton();\n\t\tflottformStateItemsContainer.replaceChildren(createChannelQrCode);\n\t\tconst linkAndCopyButtonWrapper = document.createElement('div');\n\t\tlinkAndCopyButtonWrapper.setAttribute('class', 'flottform-copy-button-link-wrapper');\n\t\tlinkAndCopyButtonWrapper.appendChild(copyToClipboardButton);\n\t\tlinkAndCopyButtonWrapper.appendChild(createChannelLinkWithOffer);\n\t\tflottformStateItemsContainer.appendChild(linkAndCopyButtonWrapper);\n\t});\n\tflottformBaseInputHost.on('connected', () => {\n\t\tstatusInformation.innerHTML = 'Connected';\n\t\tstatusInformation.appendChild(refreshChannelButton);\n\t\tflottformStateItemsContainer.replaceChildren(statusInformation);\n\t});\n\tflottformBaseInputHost.on('error', (error) => {\n\t\tstatusInformation.innerHTML =\n\t\t\ttypeof onErrorText === 'function'\n\t\t\t\t? onErrorText(error)\n\t\t\t\t: (onErrorText ?? `🚨 An error occured (${error.message}). Please try again`);\n\t\tcreateChannelButton.innerText = 'Retry';\n\t\tflottformStateItemsContainer.replaceChildren(statusInformation);\n\t\tflottformStateItemsContainer.appendChild(createChannelButton);\n\t});\n\treturn { flottformItem, statusInformation, refreshChannelButton, flottformStateItemsContainer };\n};\n\nconst handleFileInputStates = ({\n\tflottformItem,\n\tstatusInformation,\n\trefreshChannelButton,\n\tflottformStateItemsContainer,\n\tflottformFileInputHost,\n\tid,\n\tonSuccessText\n}: {\n\tflottformItem: HTMLLIElement;\n\tstatusInformation: HTMLDivElement;\n\trefreshChannelButton: HTMLButtonElement;\n\tflottformStateItemsContainer: HTMLDivElement;\n\tflottformFileInputHost: FlottformFileInputHost;\n\tid?: string;\n\tonSuccessText?: string;\n}) => {\n\tif (id) {\n\t\tflottformItem.setAttribute('id', id);\n\t}\n\n\tflottformFileInputHost.on(\n\t\t'progress',\n\t\t({ currentFileProgress, overallProgress, fileIndex, totalFileCount, fileName }) => {\n\t\t\tremoveConnectionStatusInformation(flottformStateItemsContainer);\n\t\t\tupdateOverallFilesStatusBar(\n\t\t\t\tflottformStateItemsContainer,\n\t\t\t\toverallProgress,\n\t\t\t\tfileIndex,\n\t\t\t\ttotalFileCount\n\t\t\t);\n\t\t\tconst details = getDetailsOfFilesTransfer(flottformStateItemsContainer);\n\t\t\tupdateCurrentFileStatusBar(\n\t\t\t\tfileIndex,\n\t\t\t\tfileName,\n\t\t\t\tcurrentFileProgress,\n\t\t\t\tdetails,\n\t\t\t\tflottformStateItemsContainer\n\t\t\t);\n\t\t}\n\t);\n\tflottformFileInputHost.on('done', () => {\n\t\tstatusInformation.innerHTML =\n\t\t\tonSuccessText ?? `✨ You have succesfully downloaded all your files.`;\n\t\tstatusInformation.appendChild(refreshChannelButton);\n\t\tflottformStateItemsContainer.replaceChildren(statusInformation);\n\t});\n};\n\nconst handleTextInputStates = ({\n\tflottformItem,\n\tstatusInformation,\n\trefreshChannelButton,\n\tflottformTextInputHost,\n\tid,\n\tonSuccessText\n}: {\n\tflottformItem: HTMLLIElement;\n\tstatusInformation: HTMLDivElement;\n\trefreshChannelButton: HTMLButtonElement;\n\tflottformTextInputHost: FlottformTextInputHost;\n\tid?: string;\n\tonSuccessText?: string;\n}) => {\n\tif (id) {\n\t\tflottformItem.setAttribute('id', id);\n\t}\n\tflottformTextInputHost.on('done', (message: string) => {\n\t\tstatusInformation.innerHTML = onSuccessText ?? `✨ You have succesfully submitted your message`;\n\t\tstatusInformation.appendChild(refreshChannelButton);\n\t\tflottformItem.replaceChildren(statusInformation);\n\t\tif (inputField) {\n\t\t\tinputField.setAttribute('value', message);\n\t\t\tconst event = new Event('change');\n\t\t\tinputField.dispatchEvent(event);\n\t\t}\n\t});\n};\n\nconst createFlottformOpenerButton = (flottformRootTitle: string | undefined) => {\n\tconst flottformListOpenerButton = document.createElement('button');\n\tflottformListOpenerButton.setAttribute('type', 'button');\n\tflottformListOpenerButton.setAttribute('class', 'flottform-root-opener-button');\n\tflottformListOpenerButton.innerHTML = `${flottformRootTitle ?? 'Fill from Another Device'}`;\n\tflottformListOpenerButton.addEventListener('click', () => openInputsList());\n\treturn flottformListOpenerButton;\n};\n\nconst createFlottformItemsContainerWithTransition = (\n\tflottformRootDescription: string | undefined\n) => {\n\tconst flottformElementsContainer = document.createElement('div');\n\tflottformElementsContainer.setAttribute('class', 'flottform-elements-container');\n\tconst flottformElementsContainerWrapper = document.createElement('div');\n\tflottformElementsContainerWrapper.setAttribute('class', 'flottform-elements-container-wrapper');\n\tif (flottformRootDescription !== '') {\n\t\tconst flottformDescription = document.createElement('div');\n\t\tflottformDescription.setAttribute('class', 'flottform-root-description');\n\t\tflottformDescription.innerText =\n\t\t\tflottformRootDescription ??\n\t\t\t'This form is powered by Flottform. Need to add details from another device? Simply click a button below to generate a QR code or link, and easily upload information from your other device.';\n\t\tflottformElementsContainer.appendChild(flottformDescription);\n\t}\n\tconst flottformItemsList = document.createElement('ul');\n\tflottformItemsList.setAttribute('class', 'flottform-inputs-list');\n\tflottformElementsContainer.appendChild(flottformItemsList);\n\tflottformElementsContainerWrapper.appendChild(flottformElementsContainer);\n\treturn flottformElementsContainerWrapper;\n};\n\nconst createFlottformListItem = (additionalItemClasses?: string) => {\n\tconst flottformItem = document.createElement('li');\n\tflottformItem.setAttribute('class', `flottform-item${additionalItemClasses ?? ''}`);\n\treturn flottformItem;\n};\n\nconst createStatusInformation = () => {\n\tconst statusInformation = document.createElement('div');\n\tstatusInformation.setAttribute('class', 'flottform-status-information');\n\treturn statusInformation;\n};\n\nconst createStateItemsContainer = (createChannelButton: HTMLButtonElement) => {\n\tconst flottformStateItemsContainer = document.createElement('div');\n\tflottformStateItemsContainer.setAttribute('class', 'flottform-state-items-container');\n\tflottformStateItemsContainer.appendChild(createChannelButton);\n\treturn flottformStateItemsContainer;\n};\n\nconst createFlottformChannelButton = (label: string | undefined) => {\n\tconst createChannelButton = document.createElement('button');\n\tcreateChannelButton.setAttribute('type', 'button');\n\tcreateChannelButton.setAttribute('class', 'flottform-button');\n\tcreateChannelButton.innerText = label ?? 'Get a link';\n\treturn createChannelButton;\n};\n\nconst createFlottformChannelRefreshButton = () => {\n\tconst refreshChannelButton = document.createElement('button');\n\trefreshChannelButton.setAttribute('type', 'button');\n\trefreshChannelButton.setAttribute('class', 'flottform-refresh-connection-button');\n\trefreshChannelButton.setAttribute(\n\t\t'title',\n\t\t'Click this button to refresh Flottform connection for the input field. Previous connection will be closed'\n\t);\n\trefreshChannelButton.setAttribute(\n\t\t'aria-label',\n\t\t'Click this button to refresh Flottform connection for the input field. Previous connection will be closed'\n\t);\n\trefreshChannelButton.innerHTML = ``;\n\treturn refreshChannelButton;\n};\n\n// Set an index for inputs for an edge cases when user hasn't provided a label and input has no id or name\nlet inputIndex = 1;\n\nconst setLabelForFlottformItem = ({\n\tlabel,\n\tflottformItem\n}: {\n\tlabel: string | undefined;\n\tflottformItem: HTMLLIElement;\n}) => {\n\tconst inputLabel = document.createElement('p');\n\tconst labelContent = label ?? `File input ${inputIndex++}`;\n\tif (labelContent) {\n\t\tinputLabel.innerHTML = labelContent;\n\t\tflottformItem.appendChild(inputLabel);\n\t}\n};\n\nconst createCopyToClipboardButton = () => {\n\tconst copyToClipboardButton = document.createElement('button');\n\tcopyToClipboardButton.setAttribute('class', 'flottform-copy-to-clipboard');\n\tcopyToClipboardButton.setAttribute('type', 'button');\n\tcopyToClipboardButton.setAttribute('title', 'Copy Flottform link to clipboard');\n\tcopyToClipboardButton.setAttribute('aria-label', 'Copy Flottform link to clipboard');\n\tcopyToClipboardButton.innerText = '📋';\n\tcopyToClipboardButton.addEventListener('click', async () => {\n\t\tconst flottformLink = (document.querySelector('.flottform-link-offer') as HTMLDivElement)\n\t\t\t.innerText;\n\t\tnavigator.clipboard\n\t\t\t.writeText(flottformLink)\n\t\t\t.then(() => {\n\t\t\t\tcopyToClipboardButton.innerText = '✅';\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tcopyToClipboardButton.innerText = '📋';\n\t\t\t\t}, 1000);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tcopyToClipboardButton.innerText = `❌ Failed to copy: ${error}`;\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tcopyToClipboardButton.innerText = '📋';\n\t\t\t\t}, 1000);\n\t\t\t});\n\t});\n\treturn copyToClipboardButton;\n};\n\nconst removeConnectionStatusInformation = (flottformStateItemsContainer: HTMLDivElement) => {\n\tconst connectionStatusInformation = flottformStateItemsContainer.querySelector(\n\t\t'.flottform-status-information'\n\t);\n\tif (connectionStatusInformation) {\n\t\t// Remove the connection status information\n\t\tflottformStateItemsContainer.innerHTML = '';\n\t}\n};\n\nconst getDetailsOfFilesTransfer = (flottformStateItemsContainer: HTMLDivElement) => {\n\tlet details = flottformStateItemsContainer.querySelector('details');\n\tif (!details) {\n\t\tdetails = document.createElement('details');\n\t\tconst summary = document.createElement('summary');\n\t\tsummary.innerText = 'Details';\n\t\tdetails.appendChild(summary);\n\t\tconst detailsContainer = document.createElement('div');\n\t\tdetailsContainer.classList.add('details-container');\n\t\tdetails.appendChild(detailsContainer);\n\t\tflottformStateItemsContainer.appendChild(details);\n\t}\n\treturn details;\n};\n\nconst createCurrentFileStatusBar = (fileIndex: number, fileName: string) => {\n\tconst currentFileLabel = document.createElement('label');\n\tcurrentFileLabel.setAttribute('id', `flottform-status-bar-${fileIndex}`);\n\tcurrentFileLabel.classList.add('flottform-progress-bar-label');\n\tcurrentFileLabel.innerText = `File ${fileName} progress:`;\n\n\tconst progressBar = document.createElement('progress');\n\tprogressBar.setAttribute('id', `flottform-status-bar-${fileIndex}`);\n\tprogressBar.classList.add('flottform-status-bar');\n\tprogressBar.setAttribute('max', '100');\n\tprogressBar.setAttribute('value', '0');\n\n\treturn { currentFileLabel, progressBar };\n};\n\nconst updateCurrentFileStatusBar = (\n\tfileIndex: number,\n\tfileName: string,\n\tcurrentFileProgress: number,\n\tdetails: HTMLDetailsElement,\n\tflottformStateItemsContainer: HTMLDivElement\n) => {\n\tlet currentFileStatusBar: HTMLProgressElement | null = flottformStateItemsContainer.querySelector(\n\t\t`progress#flottform-status-bar-${fileIndex}`\n\t);\n\tif (!currentFileStatusBar) {\n\t\tconst { currentFileLabel, progressBar } = createCurrentFileStatusBar(fileIndex, fileName);\n\t\tcurrentFileStatusBar = progressBar;\n\n\t\tconst detailsContainer = details.querySelector('.details-container')!;\n\n\t\tdetailsContainer.appendChild(currentFileLabel);\n\t\tdetailsContainer.appendChild(currentFileStatusBar);\n\t}\n\tcurrentFileStatusBar.value = currentFileProgress * 100;\n\tcurrentFileStatusBar.innerText = `${currentFileProgress * 100}%`;\n};\n\nconst createOverallFilesStatusBar = () => {\n\tconst overallFilesLabel = document.createElement('label');\n\toverallFilesLabel.setAttribute('id', 'flottform-status-bar-overall-progress');\n\toverallFilesLabel.classList.add('flottform-progress-bar-label');\n\toverallFilesLabel.innerText = 'Receiving Files Progress';\n\n\tconst progressBar = document.createElement('progress');\n\tprogressBar.setAttribute('id', 'flottform-status-bar-overall-progress');\n\tprogressBar.classList.add('flottform-status-bar');\n\tprogressBar.setAttribute('max', '100');\n\tprogressBar.setAttribute('value', '0');\n\n\treturn { overallFilesLabel, progressBar };\n};\n\nconst updateOverallFilesStatusBar = (\n\tflottformStateItemsContainer: HTMLDivElement,\n\toverallProgress: number,\n\tfileIndex: number,\n\ttotalFileCount: number\n) => {\n\tlet overallFilesStatusBar: HTMLProgressElement | null =\n\t\tflottformStateItemsContainer.querySelector('progress#flottform-status-bar-overall-progress');\n\tif (!overallFilesStatusBar) {\n\t\tconst { overallFilesLabel, progressBar } = createOverallFilesStatusBar();\n\t\toverallFilesStatusBar = progressBar;\n\n\t\tflottformStateItemsContainer.appendChild(overallFilesLabel);\n\t\tflottformStateItemsContainer.appendChild(overallFilesStatusBar);\n\t}\n\tconst overallFilesLabel: HTMLLabelElement = flottformStateItemsContainer.querySelector(\n\t\t'label#flottform-status-bar-overall-progress'\n\t)!;\n\toverallFilesStatusBar.value = overallProgress * 100;\n\toverallFilesStatusBar.innerText = `${overallProgress * 100}%`;\n\toverallFilesLabel.innerText = `Receiving file ${fileIndex + 1} of ${totalFileCount}`;\n};\n"],"names":["_ConnectionManager","__publicField","key","connection","ConnectionManager","canPromise","toSJISFunction","CODEWORDS_COUNT","utils","version","data","digit","f","kanji","exports","fromString","string","level","value","defaultValue","BitBuffer","index","bufIndex","num","length","i","bit","bitBuffer","BitMatrix","size","row","col","reserved","bitMatrix","getSymbolSize","require$$0","posCount","intervals","positions","coords","pos","posLength","j","FINDER_PATTERN_SIZE","finderPattern","PenaltyScores","mask","points","sameCountCol","sameCountRow","lastCol","lastRow","module","last","bitsCol","bitsRow","darkCount","modulesCount","getMaskAt","maskPattern","pattern","setupFormatFunc","numPatterns","bestPattern","lowerPenalty","p","penalty","ECLevel","EC_BLOCKS_TABLE","EC_CODEWORDS_TABLE","errorCorrectionCode","errorCorrectionLevel","EXP_TABLE","LOG_TABLE","x","galoisField","n","y","GF","p1","p2","coeff","divident","divisor","result","offset","degree","poly","Polynomial","ReedSolomonEncoder","paddedData","remainder","start","buff","reedSolomonEncoder","versionCheck","numeric","alphanumeric","byte","regex","TEST_KANJI","TEST_NUMERIC","TEST_ALPHANUMERIC","str","VersionCheck","Regex","require$$1","mode","dataStr","Utils","ECCode","require$$2","Mode","require$$3","require$$4","G18","G18_BCH","getBestVersionForDataLength","currentVersion","getReservedBitsCount","getTotalBitsFromDataArray","segments","totalBits","reservedBits","getBestVersionForMixedData","totalCodewords","ecTotalCodewords","dataTotalCodewordsBits","usableBits","seg","ecl","d","G15","G15_MASK","G15_BCH","formatInfo","NumericData","group","remainingNum","numericData","ALPHA_NUM_CHARS","AlphanumericData","alphanumericData","ByteData","l","byteData","KanjiData","kanjiData","dijkstra","graph","s","predecessors","costs","open","closest","u","v","cost_of_s_to_u","adjacent_nodes","cost_of_e","cost_of_s_to_u_plus_cost_of_e","cost_of_s_to_v","first_visit","msg","nodes","opts","T","t","a","b","cost","item","require$$5","require$$6","require$$7","getStringByteLength","getSegments","getSegmentsFromString","numSegs","alphaNumSegs","byteSegs","kanjiSegs","s1","s2","obj","getSegmentBitsLength","mergeSegments","segs","acc","curr","prevSeg","buildNodes","buildGraph","table","prevNodeIds","nodeGroup","currentNodeIds","node","prevNodeId","buildSingleSegment","modesHint","bestMode","array","path","optimizedSegs","AlignmentPattern","FinderPattern","MaskPattern","require$$8","Version","require$$9","FormatInfo","require$$10","require$$11","Segments","require$$12","setupFinderPattern","matrix","r","c","setupTimingPattern","setupAlignmentPattern","setupVersionInfo","bits","mod","setupFormatInfo","setupData","inc","bitIndex","byteIndex","dark","createData","buffer","remainingByte","createCodewords","dataTotalCodewords","ecTotalBlocks","blocksInGroup2","blocksInGroup1","totalCodewordsInGroup1","dataCodewordsInGroup1","dataCodewordsInGroup2","ecCount","rs","dcData","ecData","maxDataSize","dataSize","createSymbol","estimatedVersion","rawSegments","bestVersion","dataBits","moduleCount","modules","qrcode","options","hex2rgba","hex","hexCode","hexValue","margin","width","scale","qrSize","imgData","qr","symbolSize","scaledMargin","palette","posDst","pxColor","iSrc","jSrc","clearCanvas","ctx","canvas","getCanvasElement","qrData","canvasEl","image","type","rendererOpts","getColorAttrib","color","attrib","alpha","svgCmd","cmd","qrToPath","moveBy","newRow","lineLength","svgTag","cb","qrcodesize","bg","viewBox","QRCode","CanvasRenderer","SvgRenderer","renderCanvas","renderFunc","text","args","argsNum","isLastArgCb","resolve","reject","e","browser","_","POLL_TIME_IN_MS","DEFAULT_WEBRTC_CONFIG","generateSecretKey","retrieveEndpointInfo","getEndpointInfoUrl","setIncludes","set","EventEmitter","eventName","listener","listeners","BaseInputHost","FlottformChannelHost","flottformApi","createClientUrl","rtcConfiguration","pollTimeForIceInMs","logger","newState","details","baseApi","session","endpointId","hostKey","putHostInfoUrl","hostIceCandidates","connectLink","toDataURL","response","clientInfo","iceCandidate","channelName","err","FlottformFileInputHost","inputField","_a","_b","_c","message","currentFileName","currentFileTotalSize","currentFileProgress","overallProgress","fileIndex","fileName","fileType","receivedFile","dt","file","_d","_e","_f","_g","event","qrCode","link","error","FlottformChannelClient","clientKey","clientIceCandidates","putClientInfoUrl","hostInfo","FlottformFileInputClient","fileInput","inputElement","filesQueue","sum","files","metaData","filesArrayBuffer","totalNumberOfFiles","currentFileArrayBuffer","currentFileSize","progress","end","_h","_i","_j","FlottformTextInputClient","FlottformTextInputHost","openInputsList","flottformElementsContainerWrapper","openerSvg","initRoot","flottformRootTitle","flottformRootDescription","additionalComponentClass","flottformRoot","flottformListOpenerButton","createFlottformOpenerButton","createFlottformItemsContainerWithTransition","createLinkAndQrCode","createChannelQrCode","createChannelLinkWithOffer","createDefaultFlottformComponent","flottformAnchorElement","flottformRootElement","flottformElementsContainer","flottformInputsList","id","additionalItemClasses","label","buttonLabel","onErrorText","onSuccessText","flottformBaseInputHost","flottformItem","statusInformation","refreshChannelButton","flottformStateItemsContainer","createBaseFlottformItems","flottformItemsList","handleFileInputStates","handleTextInputStates","createFlottformListItem","setLabelForFlottformItem","createStatusInformation","createChannelButton","createFlottformChannelButton","createStateItemsContainer","createFlottformChannelRefreshButton","copyToClipboardButton","createCopyToClipboardButton","linkAndCopyButtonWrapper","flottformFileInputHost","totalFileCount","removeConnectionStatusInformation","updateOverallFilesStatusBar","getDetailsOfFilesTransfer","updateCurrentFileStatusBar","flottformTextInputHost","flottformDescription","inputIndex","inputLabel","labelContent","flottformLink","summary","detailsContainer","createCurrentFileStatusBar","currentFileLabel","progressBar","currentFileStatusBar","createOverallFilesStatusBar","overallFilesLabel","overallFilesStatusBar"],"mappings":";;;AAGO,MAAMA,IAAN,MAAMA,EAAkB;AAAA,EAItB,cAAc;AAFd,IAAAC,EAAA;AAGF,SAAA,wCAAwB,IAA6D;AAAA,EAAA;AAAA,EAG3F,OAAc,cAAiC;AAC1C,WAACD,EAAkB,aACJA,EAAA,WAAW,IAAIA,EAAkB,IAE7CA,EAAkB;AAAA,EAAA;AAAA,EAGnB,cAAcE,GAAaC,GAA6D;AACzF,SAAA,kBAAkB,IAAID,GAAKC,CAAU;AAAA,EAAA;AAAA,EAGpC,cAAcD,GAAa;AAC1B,WAAA,KAAK,kBAAkB,IAAIA,CAAG;AAAA,EAAA;AAAA,EAG/B,sBAAsB;AACvB,SAAA,kBAAkB,QAAQ,CAACC,MAAe;AAC9C,MAAAA,EAAW,MAAM;AAAA,IAAA,CACjB;AAAA,EAAA;AAAA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,gDAAgD;AAC5F,MAAI,CAACmC,GAAuB;AAC3B,UAAM,EAAE,mBAAAD,GAAmB,aAAAH,EAAA,IAAgBE,GAA4B;AAC/C,IAAAE,IAAAJ,GAExB/B,EAA6B,YAAYkC,CAAiB,GAC1DlC,EAA6B,YAAYmC,CAAqB;AAAA,EAAA;AAE/D,QAAMD,IAAsClC,EAA6B;AAAA,IACxE;AAAA,EACD;AACA,EAAAmC,EAAsB,QAAQtG,IAAkB,KAC1BsG,EAAA,YAAY,GAAGtG,IAAkB,GAAG,KAC1DqG,EAAkB,YAAY,kBAAkBpG,IAAY,CAAC,OAAOkF,CAAc;AACnF;","x_google_ignoreList":[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]} \ No newline at end of file +{"version":3,"file":"flottform-bundle.js","sources":["../../src/connection-manager.ts","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/can-promise.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-level.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-buffer.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-matrix.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alignment-pattern.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/finder-pattern.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mask-pattern.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-code.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/galois-field.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/polynomial.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/reed-solomon-encoder.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version-check.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/regex.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/format-info.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/numeric-data.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alphanumeric-data.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/byte-data.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/kanji-data.js","../../../../node_modules/.pnpm/dijkstrajs@1.0.3/node_modules/dijkstrajs/dijkstra.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/segments.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/qrcode.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/utils.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/canvas.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg-tag.js","../../../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/browser.js","../../src/internal.ts","../../src/encryption.ts","../../src/flottform-channel-host.ts","../../src/flottform-file-input-host.ts","../../src/flottform-channel-client.ts","../../src/flottform-file-input-client.ts","../../src/flottform-text-input-client.ts","../../src/flottform-text-input-host.ts","../../src/default-component.ts"],"sourcesContent":["import { FlottformFileInputHost } from './flottform-file-input-host';\nimport { FlottformTextInputHost } from './flottform-text-input-host';\n\nexport class ConnectionManager {\n\tprivate static instance: ConnectionManager;\n\tprivate activeConnections: Map;\n\n\tprivate constructor() {\n\t\tthis.activeConnections = new Map();\n\t}\n\n\tpublic static getInstance(): ConnectionManager {\n\t\tif (!ConnectionManager.instance) {\n\t\t\tConnectionManager.instance = new ConnectionManager();\n\t\t}\n\t\treturn ConnectionManager.instance;\n\t}\n\n\tpublic addConnection(key: string, connection: FlottformFileInputHost | FlottformTextInputHost) {\n\t\tthis.activeConnections.set(key, connection);\n\t}\n\n\tpublic getConnection(key: string) {\n\t\treturn this.activeConnections.get(key);\n\t}\n\n\tpublic closeAllConnections() {\n\t\tthis.activeConnections.forEach((connection) => {\n\t\t\tconnection.close();\n\t\t});\n\t\t//this.activeConnections.clear();\n\t}\n\n\tpublic removeConnection(key: string) {\n\t\tthis.activeConnections.delete(key);\n\t}\n}\n","// can-promise has a crash in some versions of react native that dont have\n// standard global objects\n// https://github.com/soldair/node-qrcode/issues/157\n\nmodule.exports = function () {\n return typeof Promise === 'function' && Promise.prototype && Promise.prototype.then\n}\n","let toSJISFunction\nconst CODEWORDS_COUNT = [\n 0, // Not used\n 26, 44, 70, 100, 134, 172, 196, 242, 292, 346,\n 404, 466, 532, 581, 655, 733, 815, 901, 991, 1085,\n 1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185,\n 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706\n]\n\n/**\n * Returns the QR Code size for the specified version\n *\n * @param {Number} version QR Code version\n * @return {Number} size of QR code\n */\nexports.getSymbolSize = function getSymbolSize (version) {\n if (!version) throw new Error('\"version\" cannot be null or undefined')\n if (version < 1 || version > 40) throw new Error('\"version\" should be in range from 1 to 40')\n return version * 4 + 17\n}\n\n/**\n * Returns the total number of codewords used to store data and EC information.\n *\n * @param {Number} version QR Code version\n * @return {Number} Data length in bits\n */\nexports.getSymbolTotalCodewords = function getSymbolTotalCodewords (version) {\n return CODEWORDS_COUNT[version]\n}\n\n/**\n * Encode data with Bose-Chaudhuri-Hocquenghem\n *\n * @param {Number} data Value to encode\n * @return {Number} Encoded value\n */\nexports.getBCHDigit = function (data) {\n let digit = 0\n\n while (data !== 0) {\n digit++\n data >>>= 1\n }\n\n return digit\n}\n\nexports.setToSJISFunction = function setToSJISFunction (f) {\n if (typeof f !== 'function') {\n throw new Error('\"toSJISFunc\" is not a valid function.')\n }\n\n toSJISFunction = f\n}\n\nexports.isKanjiModeEnabled = function () {\n return typeof toSJISFunction !== 'undefined'\n}\n\nexports.toSJIS = function toSJIS (kanji) {\n return toSJISFunction(kanji)\n}\n","exports.L = { bit: 1 }\nexports.M = { bit: 0 }\nexports.Q = { bit: 3 }\nexports.H = { bit: 2 }\n\nfunction fromString (string) {\n if (typeof string !== 'string') {\n throw new Error('Param is not a string')\n }\n\n const lcStr = string.toLowerCase()\n\n switch (lcStr) {\n case 'l':\n case 'low':\n return exports.L\n\n case 'm':\n case 'medium':\n return exports.M\n\n case 'q':\n case 'quartile':\n return exports.Q\n\n case 'h':\n case 'high':\n return exports.H\n\n default:\n throw new Error('Unknown EC Level: ' + string)\n }\n}\n\nexports.isValid = function isValid (level) {\n return level && typeof level.bit !== 'undefined' &&\n level.bit >= 0 && level.bit < 4\n}\n\nexports.from = function from (value, defaultValue) {\n if (exports.isValid(value)) {\n return value\n }\n\n try {\n return fromString(value)\n } catch (e) {\n return defaultValue\n }\n}\n","function BitBuffer () {\n this.buffer = []\n this.length = 0\n}\n\nBitBuffer.prototype = {\n\n get: function (index) {\n const bufIndex = Math.floor(index / 8)\n return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) === 1\n },\n\n put: function (num, length) {\n for (let i = 0; i < length; i++) {\n this.putBit(((num >>> (length - i - 1)) & 1) === 1)\n }\n },\n\n getLengthInBits: function () {\n return this.length\n },\n\n putBit: function (bit) {\n const bufIndex = Math.floor(this.length / 8)\n if (this.buffer.length <= bufIndex) {\n this.buffer.push(0)\n }\n\n if (bit) {\n this.buffer[bufIndex] |= (0x80 >>> (this.length % 8))\n }\n\n this.length++\n }\n}\n\nmodule.exports = BitBuffer\n","/**\n * Helper class to handle QR Code symbol modules\n *\n * @param {Number} size Symbol size\n */\nfunction BitMatrix (size) {\n if (!size || size < 1) {\n throw new Error('BitMatrix size must be defined and greater than 0')\n }\n\n this.size = size\n this.data = new Uint8Array(size * size)\n this.reservedBit = new Uint8Array(size * size)\n}\n\n/**\n * Set bit value at specified location\n * If reserved flag is set, this bit will be ignored during masking process\n *\n * @param {Number} row\n * @param {Number} col\n * @param {Boolean} value\n * @param {Boolean} reserved\n */\nBitMatrix.prototype.set = function (row, col, value, reserved) {\n const index = row * this.size + col\n this.data[index] = value\n if (reserved) this.reservedBit[index] = true\n}\n\n/**\n * Returns bit value at specified location\n *\n * @param {Number} row\n * @param {Number} col\n * @return {Boolean}\n */\nBitMatrix.prototype.get = function (row, col) {\n return this.data[row * this.size + col]\n}\n\n/**\n * Applies xor operator at specified location\n * (used during masking process)\n *\n * @param {Number} row\n * @param {Number} col\n * @param {Boolean} value\n */\nBitMatrix.prototype.xor = function (row, col, value) {\n this.data[row * this.size + col] ^= value\n}\n\n/**\n * Check if bit at specified location is reserved\n *\n * @param {Number} row\n * @param {Number} col\n * @return {Boolean}\n */\nBitMatrix.prototype.isReserved = function (row, col) {\n return this.reservedBit[row * this.size + col]\n}\n\nmodule.exports = BitMatrix\n","/**\n * Alignment pattern are fixed reference pattern in defined positions\n * in a matrix symbology, which enables the decode software to re-synchronise\n * the coordinate mapping of the image modules in the event of moderate amounts\n * of distortion of the image.\n *\n * Alignment patterns are present only in QR Code symbols of version 2 or larger\n * and their number depends on the symbol version.\n */\n\nconst getSymbolSize = require('./utils').getSymbolSize\n\n/**\n * Calculate the row/column coordinates of the center module of each alignment pattern\n * for the specified QR Code version.\n *\n * The alignment patterns are positioned symmetrically on either side of the diagonal\n * running from the top left corner of the symbol to the bottom right corner.\n *\n * Since positions are simmetrical only half of the coordinates are returned.\n * Each item of the array will represent in turn the x and y coordinate.\n * @see {@link getPositions}\n *\n * @param {Number} version QR Code version\n * @return {Array} Array of coordinate\n */\nexports.getRowColCoords = function getRowColCoords (version) {\n if (version === 1) return []\n\n const posCount = Math.floor(version / 7) + 2\n const size = getSymbolSize(version)\n const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2\n const positions = [size - 7] // Last coord is always (size - 7)\n\n for (let i = 1; i < posCount - 1; i++) {\n positions[i] = positions[i - 1] - intervals\n }\n\n positions.push(6) // First coord is always 6\n\n return positions.reverse()\n}\n\n/**\n * Returns an array containing the positions of each alignment pattern.\n * Each array's element represent the center point of the pattern as (x, y) coordinates\n *\n * Coordinates are calculated expanding the row/column coordinates returned by {@link getRowColCoords}\n * and filtering out the items that overlaps with finder pattern\n *\n * @example\n * For a Version 7 symbol {@link getRowColCoords} returns values 6, 22 and 38.\n * The alignment patterns, therefore, are to be centered on (row, column)\n * positions (6,22), (22,6), (22,22), (22,38), (38,22), (38,38).\n * Note that the coordinates (6,6), (6,38), (38,6) are occupied by finder patterns\n * and are not therefore used for alignment patterns.\n *\n * let pos = getPositions(7)\n * // [[6,22], [22,6], [22,22], [22,38], [38,22], [38,38]]\n *\n * @param {Number} version QR Code version\n * @return {Array} Array of coordinates\n */\nexports.getPositions = function getPositions (version) {\n const coords = []\n const pos = exports.getRowColCoords(version)\n const posLength = pos.length\n\n for (let i = 0; i < posLength; i++) {\n for (let j = 0; j < posLength; j++) {\n // Skip if position is occupied by finder patterns\n if ((i === 0 && j === 0) || // top-left\n (i === 0 && j === posLength - 1) || // bottom-left\n (i === posLength - 1 && j === 0)) { // top-right\n continue\n }\n\n coords.push([pos[i], pos[j]])\n }\n }\n\n return coords\n}\n","const getSymbolSize = require('./utils').getSymbolSize\nconst FINDER_PATTERN_SIZE = 7\n\n/**\n * Returns an array containing the positions of each finder pattern.\n * Each array's element represent the top-left point of the pattern as (x, y) coordinates\n *\n * @param {Number} version QR Code version\n * @return {Array} Array of coordinates\n */\nexports.getPositions = function getPositions (version) {\n const size = getSymbolSize(version)\n\n return [\n // top-left\n [0, 0],\n // top-right\n [size - FINDER_PATTERN_SIZE, 0],\n // bottom-left\n [0, size - FINDER_PATTERN_SIZE]\n ]\n}\n","/**\n * Data mask pattern reference\n * @type {Object}\n */\nexports.Patterns = {\n PATTERN000: 0,\n PATTERN001: 1,\n PATTERN010: 2,\n PATTERN011: 3,\n PATTERN100: 4,\n PATTERN101: 5,\n PATTERN110: 6,\n PATTERN111: 7\n}\n\n/**\n * Weighted penalty scores for the undesirable features\n * @type {Object}\n */\nconst PenaltyScores = {\n N1: 3,\n N2: 3,\n N3: 40,\n N4: 10\n}\n\n/**\n * Check if mask pattern value is valid\n *\n * @param {Number} mask Mask pattern\n * @return {Boolean} true if valid, false otherwise\n */\nexports.isValid = function isValid (mask) {\n return mask != null && mask !== '' && !isNaN(mask) && mask >= 0 && mask <= 7\n}\n\n/**\n * Returns mask pattern from a value.\n * If value is not valid, returns undefined\n *\n * @param {Number|String} value Mask pattern value\n * @return {Number} Valid mask pattern or undefined\n */\nexports.from = function from (value) {\n return exports.isValid(value) ? parseInt(value, 10) : undefined\n}\n\n/**\n* Find adjacent modules in row/column with the same color\n* and assign a penalty value.\n*\n* Points: N1 + i\n* i is the amount by which the number of adjacent modules of the same color exceeds 5\n*/\nexports.getPenaltyN1 = function getPenaltyN1 (data) {\n const size = data.size\n let points = 0\n let sameCountCol = 0\n let sameCountRow = 0\n let lastCol = null\n let lastRow = null\n\n for (let row = 0; row < size; row++) {\n sameCountCol = sameCountRow = 0\n lastCol = lastRow = null\n\n for (let col = 0; col < size; col++) {\n let module = data.get(row, col)\n if (module === lastCol) {\n sameCountCol++\n } else {\n if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5)\n lastCol = module\n sameCountCol = 1\n }\n\n module = data.get(col, row)\n if (module === lastRow) {\n sameCountRow++\n } else {\n if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5)\n lastRow = module\n sameCountRow = 1\n }\n }\n\n if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5)\n if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5)\n }\n\n return points\n}\n\n/**\n * Find 2x2 blocks with the same color and assign a penalty value\n *\n * Points: N2 * (m - 1) * (n - 1)\n */\nexports.getPenaltyN2 = function getPenaltyN2 (data) {\n const size = data.size\n let points = 0\n\n for (let row = 0; row < size - 1; row++) {\n for (let col = 0; col < size - 1; col++) {\n const last = data.get(row, col) +\n data.get(row, col + 1) +\n data.get(row + 1, col) +\n data.get(row + 1, col + 1)\n\n if (last === 4 || last === 0) points++\n }\n }\n\n return points * PenaltyScores.N2\n}\n\n/**\n * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column,\n * preceded or followed by light area 4 modules wide\n *\n * Points: N3 * number of pattern found\n */\nexports.getPenaltyN3 = function getPenaltyN3 (data) {\n const size = data.size\n let points = 0\n let bitsCol = 0\n let bitsRow = 0\n\n for (let row = 0; row < size; row++) {\n bitsCol = bitsRow = 0\n for (let col = 0; col < size; col++) {\n bitsCol = ((bitsCol << 1) & 0x7FF) | data.get(row, col)\n if (col >= 10 && (bitsCol === 0x5D0 || bitsCol === 0x05D)) points++\n\n bitsRow = ((bitsRow << 1) & 0x7FF) | data.get(col, row)\n if (col >= 10 && (bitsRow === 0x5D0 || bitsRow === 0x05D)) points++\n }\n }\n\n return points * PenaltyScores.N3\n}\n\n/**\n * Calculate proportion of dark modules in entire symbol\n *\n * Points: N4 * k\n *\n * k is the rating of the deviation of the proportion of dark modules\n * in the symbol from 50% in steps of 5%\n */\nexports.getPenaltyN4 = function getPenaltyN4 (data) {\n let darkCount = 0\n const modulesCount = data.data.length\n\n for (let i = 0; i < modulesCount; i++) darkCount += data.data[i]\n\n const k = Math.abs(Math.ceil((darkCount * 100 / modulesCount) / 5) - 10)\n\n return k * PenaltyScores.N4\n}\n\n/**\n * Return mask value at given position\n *\n * @param {Number} maskPattern Pattern reference value\n * @param {Number} i Row\n * @param {Number} j Column\n * @return {Boolean} Mask value\n */\nfunction getMaskAt (maskPattern, i, j) {\n switch (maskPattern) {\n case exports.Patterns.PATTERN000: return (i + j) % 2 === 0\n case exports.Patterns.PATTERN001: return i % 2 === 0\n case exports.Patterns.PATTERN010: return j % 3 === 0\n case exports.Patterns.PATTERN011: return (i + j) % 3 === 0\n case exports.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0\n case exports.Patterns.PATTERN101: return (i * j) % 2 + (i * j) % 3 === 0\n case exports.Patterns.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 === 0\n case exports.Patterns.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 === 0\n\n default: throw new Error('bad maskPattern:' + maskPattern)\n }\n}\n\n/**\n * Apply a mask pattern to a BitMatrix\n *\n * @param {Number} pattern Pattern reference number\n * @param {BitMatrix} data BitMatrix data\n */\nexports.applyMask = function applyMask (pattern, data) {\n const size = data.size\n\n for (let col = 0; col < size; col++) {\n for (let row = 0; row < size; row++) {\n if (data.isReserved(row, col)) continue\n data.xor(row, col, getMaskAt(pattern, row, col))\n }\n }\n}\n\n/**\n * Returns the best mask pattern for data\n *\n * @param {BitMatrix} data\n * @return {Number} Mask pattern reference number\n */\nexports.getBestMask = function getBestMask (data, setupFormatFunc) {\n const numPatterns = Object.keys(exports.Patterns).length\n let bestPattern = 0\n let lowerPenalty = Infinity\n\n for (let p = 0; p < numPatterns; p++) {\n setupFormatFunc(p)\n exports.applyMask(p, data)\n\n // Calculate penalty\n const penalty =\n exports.getPenaltyN1(data) +\n exports.getPenaltyN2(data) +\n exports.getPenaltyN3(data) +\n exports.getPenaltyN4(data)\n\n // Undo previously applied mask\n exports.applyMask(p, data)\n\n if (penalty < lowerPenalty) {\n lowerPenalty = penalty\n bestPattern = p\n }\n }\n\n return bestPattern\n}\n","const ECLevel = require('./error-correction-level')\r\n\r\nconst EC_BLOCKS_TABLE = [\r\n// L M Q H\r\n 1, 1, 1, 1,\r\n 1, 1, 1, 1,\r\n 1, 1, 2, 2,\r\n 1, 2, 2, 4,\r\n 1, 2, 4, 4,\r\n 2, 4, 4, 4,\r\n 2, 4, 6, 5,\r\n 2, 4, 6, 6,\r\n 2, 5, 8, 8,\r\n 4, 5, 8, 8,\r\n 4, 5, 8, 11,\r\n 4, 8, 10, 11,\r\n 4, 9, 12, 16,\r\n 4, 9, 16, 16,\r\n 6, 10, 12, 18,\r\n 6, 10, 17, 16,\r\n 6, 11, 16, 19,\r\n 6, 13, 18, 21,\r\n 7, 14, 21, 25,\r\n 8, 16, 20, 25,\r\n 8, 17, 23, 25,\r\n 9, 17, 23, 34,\r\n 9, 18, 25, 30,\r\n 10, 20, 27, 32,\r\n 12, 21, 29, 35,\r\n 12, 23, 34, 37,\r\n 12, 25, 34, 40,\r\n 13, 26, 35, 42,\r\n 14, 28, 38, 45,\r\n 15, 29, 40, 48,\r\n 16, 31, 43, 51,\r\n 17, 33, 45, 54,\r\n 18, 35, 48, 57,\r\n 19, 37, 51, 60,\r\n 19, 38, 53, 63,\r\n 20, 40, 56, 66,\r\n 21, 43, 59, 70,\r\n 22, 45, 62, 74,\r\n 24, 47, 65, 77,\r\n 25, 49, 68, 81\r\n]\r\n\r\nconst EC_CODEWORDS_TABLE = [\r\n// L M Q H\r\n 7, 10, 13, 17,\r\n 10, 16, 22, 28,\r\n 15, 26, 36, 44,\r\n 20, 36, 52, 64,\r\n 26, 48, 72, 88,\r\n 36, 64, 96, 112,\r\n 40, 72, 108, 130,\r\n 48, 88, 132, 156,\r\n 60, 110, 160, 192,\r\n 72, 130, 192, 224,\r\n 80, 150, 224, 264,\r\n 96, 176, 260, 308,\r\n 104, 198, 288, 352,\r\n 120, 216, 320, 384,\r\n 132, 240, 360, 432,\r\n 144, 280, 408, 480,\r\n 168, 308, 448, 532,\r\n 180, 338, 504, 588,\r\n 196, 364, 546, 650,\r\n 224, 416, 600, 700,\r\n 224, 442, 644, 750,\r\n 252, 476, 690, 816,\r\n 270, 504, 750, 900,\r\n 300, 560, 810, 960,\r\n 312, 588, 870, 1050,\r\n 336, 644, 952, 1110,\r\n 360, 700, 1020, 1200,\r\n 390, 728, 1050, 1260,\r\n 420, 784, 1140, 1350,\r\n 450, 812, 1200, 1440,\r\n 480, 868, 1290, 1530,\r\n 510, 924, 1350, 1620,\r\n 540, 980, 1440, 1710,\r\n 570, 1036, 1530, 1800,\r\n 570, 1064, 1590, 1890,\r\n 600, 1120, 1680, 1980,\r\n 630, 1204, 1770, 2100,\r\n 660, 1260, 1860, 2220,\r\n 720, 1316, 1950, 2310,\r\n 750, 1372, 2040, 2430\r\n]\r\n\r\n/**\r\n * Returns the number of error correction block that the QR Code should contain\r\n * for the specified version and error correction level.\r\n *\r\n * @param {Number} version QR Code version\r\n * @param {Number} errorCorrectionLevel Error correction level\r\n * @return {Number} Number of error correction blocks\r\n */\r\nexports.getBlocksCount = function getBlocksCount (version, errorCorrectionLevel) {\r\n switch (errorCorrectionLevel) {\r\n case ECLevel.L:\r\n return EC_BLOCKS_TABLE[(version - 1) * 4 + 0]\r\n case ECLevel.M:\r\n return EC_BLOCKS_TABLE[(version - 1) * 4 + 1]\r\n case ECLevel.Q:\r\n return EC_BLOCKS_TABLE[(version - 1) * 4 + 2]\r\n case ECLevel.H:\r\n return EC_BLOCKS_TABLE[(version - 1) * 4 + 3]\r\n default:\r\n return undefined\r\n }\r\n}\r\n\r\n/**\r\n * Returns the number of error correction codewords to use for the specified\r\n * version and error correction level.\r\n *\r\n * @param {Number} version QR Code version\r\n * @param {Number} errorCorrectionLevel Error correction level\r\n * @return {Number} Number of error correction codewords\r\n */\r\nexports.getTotalCodewordsCount = function getTotalCodewordsCount (version, errorCorrectionLevel) {\r\n switch (errorCorrectionLevel) {\r\n case ECLevel.L:\r\n return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0]\r\n case ECLevel.M:\r\n return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1]\r\n case ECLevel.Q:\r\n return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2]\r\n case ECLevel.H:\r\n return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3]\r\n default:\r\n return undefined\r\n }\r\n}\r\n","const EXP_TABLE = new Uint8Array(512)\nconst LOG_TABLE = new Uint8Array(256)\n/**\n * Precompute the log and anti-log tables for faster computation later\n *\n * For each possible value in the galois field 2^8, we will pre-compute\n * the logarithm and anti-logarithm (exponential) of this value\n *\n * ref {@link https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Introduction_to_mathematical_fields}\n */\n;(function initTables () {\n let x = 1\n for (let i = 0; i < 255; i++) {\n EXP_TABLE[i] = x\n LOG_TABLE[x] = i\n\n x <<= 1 // multiply by 2\n\n // The QR code specification says to use byte-wise modulo 100011101 arithmetic.\n // This means that when a number is 256 or larger, it should be XORed with 0x11D.\n if (x & 0x100) { // similar to x >= 256, but a lot faster (because 0x100 == 256)\n x ^= 0x11D\n }\n }\n\n // Optimization: double the size of the anti-log table so that we don't need to mod 255 to\n // stay inside the bounds (because we will mainly use this table for the multiplication of\n // two GF numbers, no more).\n // @see {@link mul}\n for (let i = 255; i < 512; i++) {\n EXP_TABLE[i] = EXP_TABLE[i - 255]\n }\n}())\n\n/**\n * Returns log value of n inside Galois Field\n *\n * @param {Number} n\n * @return {Number}\n */\nexports.log = function log (n) {\n if (n < 1) throw new Error('log(' + n + ')')\n return LOG_TABLE[n]\n}\n\n/**\n * Returns anti-log value of n inside Galois Field\n *\n * @param {Number} n\n * @return {Number}\n */\nexports.exp = function exp (n) {\n return EXP_TABLE[n]\n}\n\n/**\n * Multiplies two number inside Galois Field\n *\n * @param {Number} x\n * @param {Number} y\n * @return {Number}\n */\nexports.mul = function mul (x, y) {\n if (x === 0 || y === 0) return 0\n\n // should be EXP_TABLE[(LOG_TABLE[x] + LOG_TABLE[y]) % 255] if EXP_TABLE wasn't oversized\n // @see {@link initTables}\n return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]]\n}\n","const GF = require('./galois-field')\n\n/**\n * Multiplies two polynomials inside Galois Field\n *\n * @param {Uint8Array} p1 Polynomial\n * @param {Uint8Array} p2 Polynomial\n * @return {Uint8Array} Product of p1 and p2\n */\nexports.mul = function mul (p1, p2) {\n const coeff = new Uint8Array(p1.length + p2.length - 1)\n\n for (let i = 0; i < p1.length; i++) {\n for (let j = 0; j < p2.length; j++) {\n coeff[i + j] ^= GF.mul(p1[i], p2[j])\n }\n }\n\n return coeff\n}\n\n/**\n * Calculate the remainder of polynomials division\n *\n * @param {Uint8Array} divident Polynomial\n * @param {Uint8Array} divisor Polynomial\n * @return {Uint8Array} Remainder\n */\nexports.mod = function mod (divident, divisor) {\n let result = new Uint8Array(divident)\n\n while ((result.length - divisor.length) >= 0) {\n const coeff = result[0]\n\n for (let i = 0; i < divisor.length; i++) {\n result[i] ^= GF.mul(divisor[i], coeff)\n }\n\n // remove all zeros from buffer head\n let offset = 0\n while (offset < result.length && result[offset] === 0) offset++\n result = result.slice(offset)\n }\n\n return result\n}\n\n/**\n * Generate an irreducible generator polynomial of specified degree\n * (used by Reed-Solomon encoder)\n *\n * @param {Number} degree Degree of the generator polynomial\n * @return {Uint8Array} Buffer containing polynomial coefficients\n */\nexports.generateECPolynomial = function generateECPolynomial (degree) {\n let poly = new Uint8Array([1])\n for (let i = 0; i < degree; i++) {\n poly = exports.mul(poly, new Uint8Array([1, GF.exp(i)]))\n }\n\n return poly\n}\n","const Polynomial = require('./polynomial')\n\nfunction ReedSolomonEncoder (degree) {\n this.genPoly = undefined\n this.degree = degree\n\n if (this.degree) this.initialize(this.degree)\n}\n\n/**\n * Initialize the encoder.\n * The input param should correspond to the number of error correction codewords.\n *\n * @param {Number} degree\n */\nReedSolomonEncoder.prototype.initialize = function initialize (degree) {\n // create an irreducible generator polynomial\n this.degree = degree\n this.genPoly = Polynomial.generateECPolynomial(this.degree)\n}\n\n/**\n * Encodes a chunk of data\n *\n * @param {Uint8Array} data Buffer containing input data\n * @return {Uint8Array} Buffer containing encoded data\n */\nReedSolomonEncoder.prototype.encode = function encode (data) {\n if (!this.genPoly) {\n throw new Error('Encoder not initialized')\n }\n\n // Calculate EC for this data block\n // extends data size to data+genPoly size\n const paddedData = new Uint8Array(data.length + this.degree)\n paddedData.set(data)\n\n // The error correction codewords are the remainder after dividing the data codewords\n // by a generator polynomial\n const remainder = Polynomial.mod(paddedData, this.genPoly)\n\n // return EC data blocks (last n byte, where n is the degree of genPoly)\n // If coefficients number in remainder are less than genPoly degree,\n // pad with 0s to the left to reach the needed number of coefficients\n const start = this.degree - remainder.length\n if (start > 0) {\n const buff = new Uint8Array(this.degree)\n buff.set(remainder, start)\n\n return buff\n }\n\n return remainder\n}\n\nmodule.exports = ReedSolomonEncoder\n","/**\n * Check if QR Code version is valid\n *\n * @param {Number} version QR Code version\n * @return {Boolean} true if valid version, false otherwise\n */\nexports.isValid = function isValid (version) {\n return !isNaN(version) && version >= 1 && version <= 40\n}\n","const numeric = '[0-9]+'\nconst alphanumeric = '[A-Z $%*+\\\\-./:]+'\nlet kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' +\n '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' +\n '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' +\n '[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+'\nkanji = kanji.replace(/u/g, '\\\\u')\n\nconst byte = '(?:(?![A-Z0-9 $%*+\\\\-./:]|' + kanji + ')(?:.|[\\r\\n]))+'\n\nexports.KANJI = new RegExp(kanji, 'g')\nexports.BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\\\-./:]+', 'g')\nexports.BYTE = new RegExp(byte, 'g')\nexports.NUMERIC = new RegExp(numeric, 'g')\nexports.ALPHANUMERIC = new RegExp(alphanumeric, 'g')\n\nconst TEST_KANJI = new RegExp('^' + kanji + '$')\nconst TEST_NUMERIC = new RegExp('^' + numeric + '$')\nconst TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\\\-./:]+$')\n\nexports.testKanji = function testKanji (str) {\n return TEST_KANJI.test(str)\n}\n\nexports.testNumeric = function testNumeric (str) {\n return TEST_NUMERIC.test(str)\n}\n\nexports.testAlphanumeric = function testAlphanumeric (str) {\n return TEST_ALPHANUMERIC.test(str)\n}\n","const VersionCheck = require('./version-check')\nconst Regex = require('./regex')\n\n/**\n * Numeric mode encodes data from the decimal digit set (0 - 9)\n * (byte values 30HEX to 39HEX).\n * Normally, 3 data characters are represented by 10 bits.\n *\n * @type {Object}\n */\nexports.NUMERIC = {\n id: 'Numeric',\n bit: 1 << 0,\n ccBits: [10, 12, 14]\n}\n\n/**\n * Alphanumeric mode encodes data from a set of 45 characters,\n * i.e. 10 numeric digits (0 - 9),\n * 26 alphabetic characters (A - Z),\n * and 9 symbols (SP, $, %, *, +, -, ., /, :).\n * Normally, two input characters are represented by 11 bits.\n *\n * @type {Object}\n */\nexports.ALPHANUMERIC = {\n id: 'Alphanumeric',\n bit: 1 << 1,\n ccBits: [9, 11, 13]\n}\n\n/**\n * In byte mode, data is encoded at 8 bits per character.\n *\n * @type {Object}\n */\nexports.BYTE = {\n id: 'Byte',\n bit: 1 << 2,\n ccBits: [8, 16, 16]\n}\n\n/**\n * The Kanji mode efficiently encodes Kanji characters in accordance with\n * the Shift JIS system based on JIS X 0208.\n * The Shift JIS values are shifted from the JIS X 0208 values.\n * JIS X 0208 gives details of the shift coded representation.\n * Each two-byte character value is compacted to a 13-bit binary codeword.\n *\n * @type {Object}\n */\nexports.KANJI = {\n id: 'Kanji',\n bit: 1 << 3,\n ccBits: [8, 10, 12]\n}\n\n/**\n * Mixed mode will contain a sequences of data in a combination of any of\n * the modes described above\n *\n * @type {Object}\n */\nexports.MIXED = {\n bit: -1\n}\n\n/**\n * Returns the number of bits needed to store the data length\n * according to QR Code specifications.\n *\n * @param {Mode} mode Data mode\n * @param {Number} version QR Code version\n * @return {Number} Number of bits\n */\nexports.getCharCountIndicator = function getCharCountIndicator (mode, version) {\n if (!mode.ccBits) throw new Error('Invalid mode: ' + mode)\n\n if (!VersionCheck.isValid(version)) {\n throw new Error('Invalid version: ' + version)\n }\n\n if (version >= 1 && version < 10) return mode.ccBits[0]\n else if (version < 27) return mode.ccBits[1]\n return mode.ccBits[2]\n}\n\n/**\n * Returns the most efficient mode to store the specified data\n *\n * @param {String} dataStr Input data string\n * @return {Mode} Best mode\n */\nexports.getBestModeForData = function getBestModeForData (dataStr) {\n if (Regex.testNumeric(dataStr)) return exports.NUMERIC\n else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC\n else if (Regex.testKanji(dataStr)) return exports.KANJI\n else return exports.BYTE\n}\n\n/**\n * Return mode name as string\n *\n * @param {Mode} mode Mode object\n * @returns {String} Mode name\n */\nexports.toString = function toString (mode) {\n if (mode && mode.id) return mode.id\n throw new Error('Invalid mode')\n}\n\n/**\n * Check if input param is a valid mode object\n *\n * @param {Mode} mode Mode object\n * @returns {Boolean} True if valid mode, false otherwise\n */\nexports.isValid = function isValid (mode) {\n return mode && mode.bit && mode.ccBits\n}\n\n/**\n * Get mode object from its name\n *\n * @param {String} string Mode name\n * @returns {Mode} Mode object\n */\nfunction fromString (string) {\n if (typeof string !== 'string') {\n throw new Error('Param is not a string')\n }\n\n const lcStr = string.toLowerCase()\n\n switch (lcStr) {\n case 'numeric':\n return exports.NUMERIC\n case 'alphanumeric':\n return exports.ALPHANUMERIC\n case 'kanji':\n return exports.KANJI\n case 'byte':\n return exports.BYTE\n default:\n throw new Error('Unknown mode: ' + string)\n }\n}\n\n/**\n * Returns mode from a value.\n * If value is not a valid mode, returns defaultValue\n *\n * @param {Mode|String} value Encoding mode\n * @param {Mode} defaultValue Fallback value\n * @return {Mode} Encoding mode\n */\nexports.from = function from (value, defaultValue) {\n if (exports.isValid(value)) {\n return value\n }\n\n try {\n return fromString(value)\n } catch (e) {\n return defaultValue\n }\n}\n","const Utils = require('./utils')\nconst ECCode = require('./error-correction-code')\nconst ECLevel = require('./error-correction-level')\nconst Mode = require('./mode')\nconst VersionCheck = require('./version-check')\n\n// Generator polynomial used to encode version information\nconst G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0)\nconst G18_BCH = Utils.getBCHDigit(G18)\n\nfunction getBestVersionForDataLength (mode, length, errorCorrectionLevel) {\n for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {\n if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {\n return currentVersion\n }\n }\n\n return undefined\n}\n\nfunction getReservedBitsCount (mode, version) {\n // Character count indicator + mode indicator bits\n return Mode.getCharCountIndicator(mode, version) + 4\n}\n\nfunction getTotalBitsFromDataArray (segments, version) {\n let totalBits = 0\n\n segments.forEach(function (data) {\n const reservedBits = getReservedBitsCount(data.mode, version)\n totalBits += reservedBits + data.getBitsLength()\n })\n\n return totalBits\n}\n\nfunction getBestVersionForMixedData (segments, errorCorrectionLevel) {\n for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {\n const length = getTotalBitsFromDataArray(segments, currentVersion)\n if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {\n return currentVersion\n }\n }\n\n return undefined\n}\n\n/**\n * Returns version number from a value.\n * If value is not a valid version, returns defaultValue\n *\n * @param {Number|String} value QR Code version\n * @param {Number} defaultValue Fallback value\n * @return {Number} QR Code version number\n */\nexports.from = function from (value, defaultValue) {\n if (VersionCheck.isValid(value)) {\n return parseInt(value, 10)\n }\n\n return defaultValue\n}\n\n/**\n * Returns how much data can be stored with the specified QR code version\n * and error correction level\n *\n * @param {Number} version QR Code version (1-40)\n * @param {Number} errorCorrectionLevel Error correction level\n * @param {Mode} mode Data mode\n * @return {Number} Quantity of storable data\n */\nexports.getCapacity = function getCapacity (version, errorCorrectionLevel, mode) {\n if (!VersionCheck.isValid(version)) {\n throw new Error('Invalid QR Code version')\n }\n\n // Use Byte mode as default\n if (typeof mode === 'undefined') mode = Mode.BYTE\n\n // Total codewords for this QR code version (Data + Error correction)\n const totalCodewords = Utils.getSymbolTotalCodewords(version)\n\n // Total number of error correction codewords\n const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)\n\n // Total number of data codewords\n const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8\n\n if (mode === Mode.MIXED) return dataTotalCodewordsBits\n\n const usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version)\n\n // Return max number of storable codewords\n switch (mode) {\n case Mode.NUMERIC:\n return Math.floor((usableBits / 10) * 3)\n\n case Mode.ALPHANUMERIC:\n return Math.floor((usableBits / 11) * 2)\n\n case Mode.KANJI:\n return Math.floor(usableBits / 13)\n\n case Mode.BYTE:\n default:\n return Math.floor(usableBits / 8)\n }\n}\n\n/**\n * Returns the minimum version needed to contain the amount of data\n *\n * @param {Segment} data Segment of data\n * @param {Number} [errorCorrectionLevel=H] Error correction level\n * @param {Mode} mode Data mode\n * @return {Number} QR Code version\n */\nexports.getBestVersionForData = function getBestVersionForData (data, errorCorrectionLevel) {\n let seg\n\n const ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M)\n\n if (Array.isArray(data)) {\n if (data.length > 1) {\n return getBestVersionForMixedData(data, ecl)\n }\n\n if (data.length === 0) {\n return 1\n }\n\n seg = data[0]\n } else {\n seg = data\n }\n\n return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl)\n}\n\n/**\n * Returns version information with relative error correction bits\n *\n * The version information is included in QR Code symbols of version 7 or larger.\n * It consists of an 18-bit sequence containing 6 data bits,\n * with 12 error correction bits calculated using the (18, 6) Golay code.\n *\n * @param {Number} version QR Code version\n * @return {Number} Encoded version info bits\n */\nexports.getEncodedBits = function getEncodedBits (version) {\n if (!VersionCheck.isValid(version) || version < 7) {\n throw new Error('Invalid QR Code version')\n }\n\n let d = version << 12\n\n while (Utils.getBCHDigit(d) - G18_BCH >= 0) {\n d ^= (G18 << (Utils.getBCHDigit(d) - G18_BCH))\n }\n\n return (version << 12) | d\n}\n","const Utils = require('./utils')\n\nconst G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0)\nconst G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1)\nconst G15_BCH = Utils.getBCHDigit(G15)\n\n/**\n * Returns format information with relative error correction bits\n *\n * The format information is a 15-bit sequence containing 5 data bits,\n * with 10 error correction bits calculated using the (15, 5) BCH code.\n *\n * @param {Number} errorCorrectionLevel Error correction level\n * @param {Number} mask Mask pattern\n * @return {Number} Encoded format information bits\n */\nexports.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask) {\n const data = ((errorCorrectionLevel.bit << 3) | mask)\n let d = data << 10\n\n while (Utils.getBCHDigit(d) - G15_BCH >= 0) {\n d ^= (G15 << (Utils.getBCHDigit(d) - G15_BCH))\n }\n\n // xor final data with mask pattern in order to ensure that\n // no combination of Error Correction Level and data mask pattern\n // will result in an all-zero data string\n return ((data << 10) | d) ^ G15_MASK\n}\n","const Mode = require('./mode')\n\nfunction NumericData (data) {\n this.mode = Mode.NUMERIC\n this.data = data.toString()\n}\n\nNumericData.getBitsLength = function getBitsLength (length) {\n return 10 * Math.floor(length / 3) + ((length % 3) ? ((length % 3) * 3 + 1) : 0)\n}\n\nNumericData.prototype.getLength = function getLength () {\n return this.data.length\n}\n\nNumericData.prototype.getBitsLength = function getBitsLength () {\n return NumericData.getBitsLength(this.data.length)\n}\n\nNumericData.prototype.write = function write (bitBuffer) {\n let i, group, value\n\n // The input data string is divided into groups of three digits,\n // and each group is converted to its 10-bit binary equivalent.\n for (i = 0; i + 3 <= this.data.length; i += 3) {\n group = this.data.substr(i, 3)\n value = parseInt(group, 10)\n\n bitBuffer.put(value, 10)\n }\n\n // If the number of input digits is not an exact multiple of three,\n // the final one or two digits are converted to 4 or 7 bits respectively.\n const remainingNum = this.data.length - i\n if (remainingNum > 0) {\n group = this.data.substr(i)\n value = parseInt(group, 10)\n\n bitBuffer.put(value, remainingNum * 3 + 1)\n }\n}\n\nmodule.exports = NumericData\n","const Mode = require('./mode')\n\n/**\n * Array of characters available in alphanumeric mode\n *\n * As per QR Code specification, to each character\n * is assigned a value from 0 to 44 which in this case coincides\n * with the array index\n *\n * @type {Array}\n */\nconst ALPHA_NUM_CHARS = [\n '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\n 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',\n 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',\n ' ', '$', '%', '*', '+', '-', '.', '/', ':'\n]\n\nfunction AlphanumericData (data) {\n this.mode = Mode.ALPHANUMERIC\n this.data = data\n}\n\nAlphanumericData.getBitsLength = function getBitsLength (length) {\n return 11 * Math.floor(length / 2) + 6 * (length % 2)\n}\n\nAlphanumericData.prototype.getLength = function getLength () {\n return this.data.length\n}\n\nAlphanumericData.prototype.getBitsLength = function getBitsLength () {\n return AlphanumericData.getBitsLength(this.data.length)\n}\n\nAlphanumericData.prototype.write = function write (bitBuffer) {\n let i\n\n // Input data characters are divided into groups of two characters\n // and encoded as 11-bit binary codes.\n for (i = 0; i + 2 <= this.data.length; i += 2) {\n // The character value of the first character is multiplied by 45\n let value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45\n\n // The character value of the second digit is added to the product\n value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1])\n\n // The sum is then stored as 11-bit binary number\n bitBuffer.put(value, 11)\n }\n\n // If the number of input data characters is not a multiple of two,\n // the character value of the final character is encoded as a 6-bit binary number.\n if (this.data.length % 2) {\n bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6)\n }\n}\n\nmodule.exports = AlphanumericData\n","const Mode = require('./mode')\n\nfunction ByteData (data) {\n this.mode = Mode.BYTE\n if (typeof (data) === 'string') {\n this.data = new TextEncoder().encode(data)\n } else {\n this.data = new Uint8Array(data)\n }\n}\n\nByteData.getBitsLength = function getBitsLength (length) {\n return length * 8\n}\n\nByteData.prototype.getLength = function getLength () {\n return this.data.length\n}\n\nByteData.prototype.getBitsLength = function getBitsLength () {\n return ByteData.getBitsLength(this.data.length)\n}\n\nByteData.prototype.write = function (bitBuffer) {\n for (let i = 0, l = this.data.length; i < l; i++) {\n bitBuffer.put(this.data[i], 8)\n }\n}\n\nmodule.exports = ByteData\n","const Mode = require('./mode')\nconst Utils = require('./utils')\n\nfunction KanjiData (data) {\n this.mode = Mode.KANJI\n this.data = data\n}\n\nKanjiData.getBitsLength = function getBitsLength (length) {\n return length * 13\n}\n\nKanjiData.prototype.getLength = function getLength () {\n return this.data.length\n}\n\nKanjiData.prototype.getBitsLength = function getBitsLength () {\n return KanjiData.getBitsLength(this.data.length)\n}\n\nKanjiData.prototype.write = function (bitBuffer) {\n let i\n\n // In the Shift JIS system, Kanji characters are represented by a two byte combination.\n // These byte values are shifted from the JIS X 0208 values.\n // JIS X 0208 gives details of the shift coded representation.\n for (i = 0; i < this.data.length; i++) {\n let value = Utils.toSJIS(this.data[i])\n\n // For characters with Shift JIS values from 0x8140 to 0x9FFC:\n if (value >= 0x8140 && value <= 0x9FFC) {\n // Subtract 0x8140 from Shift JIS value\n value -= 0x8140\n\n // For characters with Shift JIS values from 0xE040 to 0xEBBF\n } else if (value >= 0xE040 && value <= 0xEBBF) {\n // Subtract 0xC140 from Shift JIS value\n value -= 0xC140\n } else {\n throw new Error(\n 'Invalid SJIS character: ' + this.data[i] + '\\n' +\n 'Make sure your charset is UTF-8')\n }\n\n // Multiply most significant byte of result by 0xC0\n // and add least significant byte to product\n value = (((value >>> 8) & 0xff) * 0xC0) + (value & 0xff)\n\n // Convert result to a 13-bit binary string\n bitBuffer.put(value, 13)\n }\n}\n\nmodule.exports = KanjiData\n","'use strict';\n\n/******************************************************************************\n * Created 2008-08-19.\n *\n * Dijkstra path-finding functions. Adapted from the Dijkstar Python project.\n *\n * Copyright (C) 2008\n * Wyatt Baldwin \n * All rights reserved\n *\n * Licensed under the MIT license.\n *\n * http://www.opensource.org/licenses/mit-license.php\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n *****************************************************************************/\nvar dijkstra = {\n single_source_shortest_paths: function(graph, s, d) {\n // Predecessor map for each node that has been encountered.\n // node ID => predecessor node ID\n var predecessors = {};\n\n // Costs of shortest paths from s to all nodes encountered.\n // node ID => cost\n var costs = {};\n costs[s] = 0;\n\n // Costs of shortest paths from s to all nodes encountered; differs from\n // `costs` in that it provides easy access to the node that currently has\n // the known shortest path from s.\n // XXX: Do we actually need both `costs` and `open`?\n var open = dijkstra.PriorityQueue.make();\n open.push(s, 0);\n\n var closest,\n u, v,\n cost_of_s_to_u,\n adjacent_nodes,\n cost_of_e,\n cost_of_s_to_u_plus_cost_of_e,\n cost_of_s_to_v,\n first_visit;\n while (!open.empty()) {\n // In the nodes remaining in graph that have a known cost from s,\n // find the node, u, that currently has the shortest path from s.\n closest = open.pop();\n u = closest.value;\n cost_of_s_to_u = closest.cost;\n\n // Get nodes adjacent to u...\n adjacent_nodes = graph[u] || {};\n\n // ...and explore the edges that connect u to those nodes, updating\n // the cost of the shortest paths to any or all of those nodes as\n // necessary. v is the node across the current edge from u.\n for (v in adjacent_nodes) {\n if (adjacent_nodes.hasOwnProperty(v)) {\n // Get the cost of the edge running from u to v.\n cost_of_e = adjacent_nodes[v];\n\n // Cost of s to u plus the cost of u to v across e--this is *a*\n // cost from s to v that may or may not be less than the current\n // known cost to v.\n cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;\n\n // If we haven't visited v yet OR if the current known cost from s to\n // v is greater than the new cost we just found (cost of s to u plus\n // cost of u to v across e), update v's cost in the cost list and\n // update v's predecessor in the predecessor list (it's now u).\n cost_of_s_to_v = costs[v];\n first_visit = (typeof costs[v] === 'undefined');\n if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {\n costs[v] = cost_of_s_to_u_plus_cost_of_e;\n open.push(v, cost_of_s_to_u_plus_cost_of_e);\n predecessors[v] = u;\n }\n }\n }\n }\n\n if (typeof d !== 'undefined' && typeof costs[d] === 'undefined') {\n var msg = ['Could not find a path from ', s, ' to ', d, '.'].join('');\n throw new Error(msg);\n }\n\n return predecessors;\n },\n\n extract_shortest_path_from_predecessor_list: function(predecessors, d) {\n var nodes = [];\n var u = d;\n var predecessor;\n while (u) {\n nodes.push(u);\n predecessor = predecessors[u];\n u = predecessors[u];\n }\n nodes.reverse();\n return nodes;\n },\n\n find_path: function(graph, s, d) {\n var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);\n return dijkstra.extract_shortest_path_from_predecessor_list(\n predecessors, d);\n },\n\n /**\n * A very naive priority queue implementation.\n */\n PriorityQueue: {\n make: function (opts) {\n var T = dijkstra.PriorityQueue,\n t = {},\n key;\n opts = opts || {};\n for (key in T) {\n if (T.hasOwnProperty(key)) {\n t[key] = T[key];\n }\n }\n t.queue = [];\n t.sorter = opts.sorter || T.default_sorter;\n return t;\n },\n\n default_sorter: function (a, b) {\n return a.cost - b.cost;\n },\n\n /**\n * Add a new item to the queue and ensure the highest priority element\n * is at the front of the queue.\n */\n push: function (value, cost) {\n var item = {value: value, cost: cost};\n this.queue.push(item);\n this.queue.sort(this.sorter);\n },\n\n /**\n * Return the highest priority element in the queue.\n */\n pop: function () {\n return this.queue.shift();\n },\n\n empty: function () {\n return this.queue.length === 0;\n }\n }\n};\n\n\n// node.js module exports\nif (typeof module !== 'undefined') {\n module.exports = dijkstra;\n}\n","const Mode = require('./mode')\nconst NumericData = require('./numeric-data')\nconst AlphanumericData = require('./alphanumeric-data')\nconst ByteData = require('./byte-data')\nconst KanjiData = require('./kanji-data')\nconst Regex = require('./regex')\nconst Utils = require('./utils')\nconst dijkstra = require('dijkstrajs')\n\n/**\n * Returns UTF8 byte length\n *\n * @param {String} str Input string\n * @return {Number} Number of byte\n */\nfunction getStringByteLength (str) {\n return unescape(encodeURIComponent(str)).length\n}\n\n/**\n * Get a list of segments of the specified mode\n * from a string\n *\n * @param {Mode} mode Segment mode\n * @param {String} str String to process\n * @return {Array} Array of object with segments data\n */\nfunction getSegments (regex, mode, str) {\n const segments = []\n let result\n\n while ((result = regex.exec(str)) !== null) {\n segments.push({\n data: result[0],\n index: result.index,\n mode: mode,\n length: result[0].length\n })\n }\n\n return segments\n}\n\n/**\n * Extracts a series of segments with the appropriate\n * modes from a string\n *\n * @param {String} dataStr Input string\n * @return {Array} Array of object with segments data\n */\nfunction getSegmentsFromString (dataStr) {\n const numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr)\n const alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr)\n let byteSegs\n let kanjiSegs\n\n if (Utils.isKanjiModeEnabled()) {\n byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr)\n kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr)\n } else {\n byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr)\n kanjiSegs = []\n }\n\n const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs)\n\n return segs\n .sort(function (s1, s2) {\n return s1.index - s2.index\n })\n .map(function (obj) {\n return {\n data: obj.data,\n mode: obj.mode,\n length: obj.length\n }\n })\n}\n\n/**\n * Returns how many bits are needed to encode a string of\n * specified length with the specified mode\n *\n * @param {Number} length String length\n * @param {Mode} mode Segment mode\n * @return {Number} Bit length\n */\nfunction getSegmentBitsLength (length, mode) {\n switch (mode) {\n case Mode.NUMERIC:\n return NumericData.getBitsLength(length)\n case Mode.ALPHANUMERIC:\n return AlphanumericData.getBitsLength(length)\n case Mode.KANJI:\n return KanjiData.getBitsLength(length)\n case Mode.BYTE:\n return ByteData.getBitsLength(length)\n }\n}\n\n/**\n * Merges adjacent segments which have the same mode\n *\n * @param {Array} segs Array of object with segments data\n * @return {Array} Array of object with segments data\n */\nfunction mergeSegments (segs) {\n return segs.reduce(function (acc, curr) {\n const prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null\n if (prevSeg && prevSeg.mode === curr.mode) {\n acc[acc.length - 1].data += curr.data\n return acc\n }\n\n acc.push(curr)\n return acc\n }, [])\n}\n\n/**\n * Generates a list of all possible nodes combination which\n * will be used to build a segments graph.\n *\n * Nodes are divided by groups. Each group will contain a list of all the modes\n * in which is possible to encode the given text.\n *\n * For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte.\n * The group for '12345' will contain then 3 objects, one for each\n * possible encoding mode.\n *\n * Each node represents a possible segment.\n *\n * @param {Array} segs Array of object with segments data\n * @return {Array} Array of object with segments data\n */\nfunction buildNodes (segs) {\n const nodes = []\n for (let i = 0; i < segs.length; i++) {\n const seg = segs[i]\n\n switch (seg.mode) {\n case Mode.NUMERIC:\n nodes.push([seg,\n { data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },\n { data: seg.data, mode: Mode.BYTE, length: seg.length }\n ])\n break\n case Mode.ALPHANUMERIC:\n nodes.push([seg,\n { data: seg.data, mode: Mode.BYTE, length: seg.length }\n ])\n break\n case Mode.KANJI:\n nodes.push([seg,\n { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }\n ])\n break\n case Mode.BYTE:\n nodes.push([\n { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }\n ])\n }\n }\n\n return nodes\n}\n\n/**\n * Builds a graph from a list of nodes.\n * All segments in each node group will be connected with all the segments of\n * the next group and so on.\n *\n * At each connection will be assigned a weight depending on the\n * segment's byte length.\n *\n * @param {Array} nodes Array of object with segments data\n * @param {Number} version QR Code version\n * @return {Object} Graph of all possible segments\n */\nfunction buildGraph (nodes, version) {\n const table = {}\n const graph = { start: {} }\n let prevNodeIds = ['start']\n\n for (let i = 0; i < nodes.length; i++) {\n const nodeGroup = nodes[i]\n const currentNodeIds = []\n\n for (let j = 0; j < nodeGroup.length; j++) {\n const node = nodeGroup[j]\n const key = '' + i + j\n\n currentNodeIds.push(key)\n table[key] = { node: node, lastCount: 0 }\n graph[key] = {}\n\n for (let n = 0; n < prevNodeIds.length; n++) {\n const prevNodeId = prevNodeIds[n]\n\n if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {\n graph[prevNodeId][key] =\n getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) -\n getSegmentBitsLength(table[prevNodeId].lastCount, node.mode)\n\n table[prevNodeId].lastCount += node.length\n } else {\n if (table[prevNodeId]) table[prevNodeId].lastCount = node.length\n\n graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) +\n 4 + Mode.getCharCountIndicator(node.mode, version) // switch cost\n }\n }\n }\n\n prevNodeIds = currentNodeIds\n }\n\n for (let n = 0; n < prevNodeIds.length; n++) {\n graph[prevNodeIds[n]].end = 0\n }\n\n return { map: graph, table: table }\n}\n\n/**\n * Builds a segment from a specified data and mode.\n * If a mode is not specified, the more suitable will be used.\n *\n * @param {String} data Input data\n * @param {Mode | String} modesHint Data mode\n * @return {Segment} Segment\n */\nfunction buildSingleSegment (data, modesHint) {\n let mode\n const bestMode = Mode.getBestModeForData(data)\n\n mode = Mode.from(modesHint, bestMode)\n\n // Make sure data can be encoded\n if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {\n throw new Error('\"' + data + '\"' +\n ' cannot be encoded with mode ' + Mode.toString(mode) +\n '.\\n Suggested mode is: ' + Mode.toString(bestMode))\n }\n\n // Use Mode.BYTE if Kanji support is disabled\n if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {\n mode = Mode.BYTE\n }\n\n switch (mode) {\n case Mode.NUMERIC:\n return new NumericData(data)\n\n case Mode.ALPHANUMERIC:\n return new AlphanumericData(data)\n\n case Mode.KANJI:\n return new KanjiData(data)\n\n case Mode.BYTE:\n return new ByteData(data)\n }\n}\n\n/**\n * Builds a list of segments from an array.\n * Array can contain Strings or Objects with segment's info.\n *\n * For each item which is a string, will be generated a segment with the given\n * string and the more appropriate encoding mode.\n *\n * For each item which is an object, will be generated a segment with the given\n * data and mode.\n * Objects must contain at least the property \"data\".\n * If property \"mode\" is not present, the more suitable mode will be used.\n *\n * @param {Array} array Array of objects with segments data\n * @return {Array} Array of Segments\n */\nexports.fromArray = function fromArray (array) {\n return array.reduce(function (acc, seg) {\n if (typeof seg === 'string') {\n acc.push(buildSingleSegment(seg, null))\n } else if (seg.data) {\n acc.push(buildSingleSegment(seg.data, seg.mode))\n }\n\n return acc\n }, [])\n}\n\n/**\n * Builds an optimized sequence of segments from a string,\n * which will produce the shortest possible bitstream.\n *\n * @param {String} data Input string\n * @param {Number} version QR Code version\n * @return {Array} Array of segments\n */\nexports.fromString = function fromString (data, version) {\n const segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled())\n\n const nodes = buildNodes(segs)\n const graph = buildGraph(nodes, version)\n const path = dijkstra.find_path(graph.map, 'start', 'end')\n\n const optimizedSegs = []\n for (let i = 1; i < path.length - 1; i++) {\n optimizedSegs.push(graph.table[path[i]].node)\n }\n\n return exports.fromArray(mergeSegments(optimizedSegs))\n}\n\n/**\n * Splits a string in various segments with the modes which\n * best represent their content.\n * The produced segments are far from being optimized.\n * The output of this function is only used to estimate a QR Code version\n * which may contain the data.\n *\n * @param {string} data Input string\n * @return {Array} Array of segments\n */\nexports.rawSplit = function rawSplit (data) {\n return exports.fromArray(\n getSegmentsFromString(data, Utils.isKanjiModeEnabled())\n )\n}\n","const Utils = require('./utils')\nconst ECLevel = require('./error-correction-level')\nconst BitBuffer = require('./bit-buffer')\nconst BitMatrix = require('./bit-matrix')\nconst AlignmentPattern = require('./alignment-pattern')\nconst FinderPattern = require('./finder-pattern')\nconst MaskPattern = require('./mask-pattern')\nconst ECCode = require('./error-correction-code')\nconst ReedSolomonEncoder = require('./reed-solomon-encoder')\nconst Version = require('./version')\nconst FormatInfo = require('./format-info')\nconst Mode = require('./mode')\nconst Segments = require('./segments')\n\n/**\n * QRCode for JavaScript\n *\n * modified by Ryan Day for nodejs support\n * Copyright (c) 2011 Ryan Day\n *\n * Licensed under the MIT license:\n * http://www.opensource.org/licenses/mit-license.php\n *\n//---------------------------------------------------------------------\n// QRCode for JavaScript\n//\n// Copyright (c) 2009 Kazuhiko Arase\n//\n// URL: http://www.d-project.com/\n//\n// Licensed under the MIT license:\n// http://www.opensource.org/licenses/mit-license.php\n//\n// The word \"QR Code\" is registered trademark of\n// DENSO WAVE INCORPORATED\n// http://www.denso-wave.com/qrcode/faqpatent-e.html\n//\n//---------------------------------------------------------------------\n*/\n\n/**\n * Add finder patterns bits to matrix\n *\n * @param {BitMatrix} matrix Modules matrix\n * @param {Number} version QR Code version\n */\nfunction setupFinderPattern (matrix, version) {\n const size = matrix.size\n const pos = FinderPattern.getPositions(version)\n\n for (let i = 0; i < pos.length; i++) {\n const row = pos[i][0]\n const col = pos[i][1]\n\n for (let r = -1; r <= 7; r++) {\n if (row + r <= -1 || size <= row + r) continue\n\n for (let c = -1; c <= 7; c++) {\n if (col + c <= -1 || size <= col + c) continue\n\n if ((r >= 0 && r <= 6 && (c === 0 || c === 6)) ||\n (c >= 0 && c <= 6 && (r === 0 || r === 6)) ||\n (r >= 2 && r <= 4 && c >= 2 && c <= 4)) {\n matrix.set(row + r, col + c, true, true)\n } else {\n matrix.set(row + r, col + c, false, true)\n }\n }\n }\n }\n}\n\n/**\n * Add timing pattern bits to matrix\n *\n * Note: this function must be called before {@link setupAlignmentPattern}\n *\n * @param {BitMatrix} matrix Modules matrix\n */\nfunction setupTimingPattern (matrix) {\n const size = matrix.size\n\n for (let r = 8; r < size - 8; r++) {\n const value = r % 2 === 0\n matrix.set(r, 6, value, true)\n matrix.set(6, r, value, true)\n }\n}\n\n/**\n * Add alignment patterns bits to matrix\n *\n * Note: this function must be called after {@link setupTimingPattern}\n *\n * @param {BitMatrix} matrix Modules matrix\n * @param {Number} version QR Code version\n */\nfunction setupAlignmentPattern (matrix, version) {\n const pos = AlignmentPattern.getPositions(version)\n\n for (let i = 0; i < pos.length; i++) {\n const row = pos[i][0]\n const col = pos[i][1]\n\n for (let r = -2; r <= 2; r++) {\n for (let c = -2; c <= 2; c++) {\n if (r === -2 || r === 2 || c === -2 || c === 2 ||\n (r === 0 && c === 0)) {\n matrix.set(row + r, col + c, true, true)\n } else {\n matrix.set(row + r, col + c, false, true)\n }\n }\n }\n }\n}\n\n/**\n * Add version info bits to matrix\n *\n * @param {BitMatrix} matrix Modules matrix\n * @param {Number} version QR Code version\n */\nfunction setupVersionInfo (matrix, version) {\n const size = matrix.size\n const bits = Version.getEncodedBits(version)\n let row, col, mod\n\n for (let i = 0; i < 18; i++) {\n row = Math.floor(i / 3)\n col = i % 3 + size - 8 - 3\n mod = ((bits >> i) & 1) === 1\n\n matrix.set(row, col, mod, true)\n matrix.set(col, row, mod, true)\n }\n}\n\n/**\n * Add format info bits to matrix\n *\n * @param {BitMatrix} matrix Modules matrix\n * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level\n * @param {Number} maskPattern Mask pattern reference value\n */\nfunction setupFormatInfo (matrix, errorCorrectionLevel, maskPattern) {\n const size = matrix.size\n const bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern)\n let i, mod\n\n for (i = 0; i < 15; i++) {\n mod = ((bits >> i) & 1) === 1\n\n // vertical\n if (i < 6) {\n matrix.set(i, 8, mod, true)\n } else if (i < 8) {\n matrix.set(i + 1, 8, mod, true)\n } else {\n matrix.set(size - 15 + i, 8, mod, true)\n }\n\n // horizontal\n if (i < 8) {\n matrix.set(8, size - i - 1, mod, true)\n } else if (i < 9) {\n matrix.set(8, 15 - i - 1 + 1, mod, true)\n } else {\n matrix.set(8, 15 - i - 1, mod, true)\n }\n }\n\n // fixed module\n matrix.set(size - 8, 8, 1, true)\n}\n\n/**\n * Add encoded data bits to matrix\n *\n * @param {BitMatrix} matrix Modules matrix\n * @param {Uint8Array} data Data codewords\n */\nfunction setupData (matrix, data) {\n const size = matrix.size\n let inc = -1\n let row = size - 1\n let bitIndex = 7\n let byteIndex = 0\n\n for (let col = size - 1; col > 0; col -= 2) {\n if (col === 6) col--\n\n while (true) {\n for (let c = 0; c < 2; c++) {\n if (!matrix.isReserved(row, col - c)) {\n let dark = false\n\n if (byteIndex < data.length) {\n dark = (((data[byteIndex] >>> bitIndex) & 1) === 1)\n }\n\n matrix.set(row, col - c, dark)\n bitIndex--\n\n if (bitIndex === -1) {\n byteIndex++\n bitIndex = 7\n }\n }\n }\n\n row += inc\n\n if (row < 0 || size <= row) {\n row -= inc\n inc = -inc\n break\n }\n }\n }\n}\n\n/**\n * Create encoded codewords from data input\n *\n * @param {Number} version QR Code version\n * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level\n * @param {ByteData} data Data input\n * @return {Uint8Array} Buffer containing encoded codewords\n */\nfunction createData (version, errorCorrectionLevel, segments) {\n // Prepare data buffer\n const buffer = new BitBuffer()\n\n segments.forEach(function (data) {\n // prefix data with mode indicator (4 bits)\n buffer.put(data.mode.bit, 4)\n\n // Prefix data with character count indicator.\n // The character count indicator is a string of bits that represents the\n // number of characters that are being encoded.\n // The character count indicator must be placed after the mode indicator\n // and must be a certain number of bits long, depending on the QR version\n // and data mode\n // @see {@link Mode.getCharCountIndicator}.\n buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version))\n\n // add binary data sequence to buffer\n data.write(buffer)\n })\n\n // Calculate required number of bits\n const totalCodewords = Utils.getSymbolTotalCodewords(version)\n const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)\n const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8\n\n // Add a terminator.\n // If the bit string is shorter than the total number of required bits,\n // a terminator of up to four 0s must be added to the right side of the string.\n // If the bit string is more than four bits shorter than the required number of bits,\n // add four 0s to the end.\n if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {\n buffer.put(0, 4)\n }\n\n // If the bit string is fewer than four bits shorter, add only the number of 0s that\n // are needed to reach the required number of bits.\n\n // After adding the terminator, if the number of bits in the string is not a multiple of 8,\n // pad the string on the right with 0s to make the string's length a multiple of 8.\n while (buffer.getLengthInBits() % 8 !== 0) {\n buffer.putBit(0)\n }\n\n // Add pad bytes if the string is still shorter than the total number of required bits.\n // Extend the buffer to fill the data capacity of the symbol corresponding to\n // the Version and Error Correction Level by adding the Pad Codewords 11101100 (0xEC)\n // and 00010001 (0x11) alternately.\n const remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8\n for (let i = 0; i < remainingByte; i++) {\n buffer.put(i % 2 ? 0x11 : 0xEC, 8)\n }\n\n return createCodewords(buffer, version, errorCorrectionLevel)\n}\n\n/**\n * Encode input data with Reed-Solomon and return codewords with\n * relative error correction bits\n *\n * @param {BitBuffer} bitBuffer Data to encode\n * @param {Number} version QR Code version\n * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level\n * @return {Uint8Array} Buffer containing encoded codewords\n */\nfunction createCodewords (bitBuffer, version, errorCorrectionLevel) {\n // Total codewords for this QR code version (Data + Error correction)\n const totalCodewords = Utils.getSymbolTotalCodewords(version)\n\n // Total number of error correction codewords\n const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)\n\n // Total number of data codewords\n const dataTotalCodewords = totalCodewords - ecTotalCodewords\n\n // Total number of blocks\n const ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel)\n\n // Calculate how many blocks each group should contain\n const blocksInGroup2 = totalCodewords % ecTotalBlocks\n const blocksInGroup1 = ecTotalBlocks - blocksInGroup2\n\n const totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks)\n\n const dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks)\n const dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1\n\n // Number of EC codewords is the same for both groups\n const ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1\n\n // Initialize a Reed-Solomon encoder with a generator polynomial of degree ecCount\n const rs = new ReedSolomonEncoder(ecCount)\n\n let offset = 0\n const dcData = new Array(ecTotalBlocks)\n const ecData = new Array(ecTotalBlocks)\n let maxDataSize = 0\n const buffer = new Uint8Array(bitBuffer.buffer)\n\n // Divide the buffer into the required number of blocks\n for (let b = 0; b < ecTotalBlocks; b++) {\n const dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2\n\n // extract a block of data from buffer\n dcData[b] = buffer.slice(offset, offset + dataSize)\n\n // Calculate EC codewords for this data block\n ecData[b] = rs.encode(dcData[b])\n\n offset += dataSize\n maxDataSize = Math.max(maxDataSize, dataSize)\n }\n\n // Create final data\n // Interleave the data and error correction codewords from each block\n const data = new Uint8Array(totalCodewords)\n let index = 0\n let i, r\n\n // Add data codewords\n for (i = 0; i < maxDataSize; i++) {\n for (r = 0; r < ecTotalBlocks; r++) {\n if (i < dcData[r].length) {\n data[index++] = dcData[r][i]\n }\n }\n }\n\n // Apped EC codewords\n for (i = 0; i < ecCount; i++) {\n for (r = 0; r < ecTotalBlocks; r++) {\n data[index++] = ecData[r][i]\n }\n }\n\n return data\n}\n\n/**\n * Build QR Code symbol\n *\n * @param {String} data Input string\n * @param {Number} version QR Code version\n * @param {ErrorCorretionLevel} errorCorrectionLevel Error level\n * @param {MaskPattern} maskPattern Mask pattern\n * @return {Object} Object containing symbol data\n */\nfunction createSymbol (data, version, errorCorrectionLevel, maskPattern) {\n let segments\n\n if (Array.isArray(data)) {\n segments = Segments.fromArray(data)\n } else if (typeof data === 'string') {\n let estimatedVersion = version\n\n if (!estimatedVersion) {\n const rawSegments = Segments.rawSplit(data)\n\n // Estimate best version that can contain raw splitted segments\n estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel)\n }\n\n // Build optimized segments\n // If estimated version is undefined, try with the highest version\n segments = Segments.fromString(data, estimatedVersion || 40)\n } else {\n throw new Error('Invalid data')\n }\n\n // Get the min version that can contain data\n const bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel)\n\n // If no version is found, data cannot be stored\n if (!bestVersion) {\n throw new Error('The amount of data is too big to be stored in a QR Code')\n }\n\n // If not specified, use min version as default\n if (!version) {\n version = bestVersion\n\n // Check if the specified version can contain the data\n } else if (version < bestVersion) {\n throw new Error('\\n' +\n 'The chosen QR Code version cannot contain this amount of data.\\n' +\n 'Minimum version required to store current data is: ' + bestVersion + '.\\n'\n )\n }\n\n const dataBits = createData(version, errorCorrectionLevel, segments)\n\n // Allocate matrix buffer\n const moduleCount = Utils.getSymbolSize(version)\n const modules = new BitMatrix(moduleCount)\n\n // Add function modules\n setupFinderPattern(modules, version)\n setupTimingPattern(modules)\n setupAlignmentPattern(modules, version)\n\n // Add temporary dummy bits for format info just to set them as reserved.\n // This is needed to prevent these bits from being masked by {@link MaskPattern.applyMask}\n // since the masking operation must be performed only on the encoding region.\n // These blocks will be replaced with correct values later in code.\n setupFormatInfo(modules, errorCorrectionLevel, 0)\n\n if (version >= 7) {\n setupVersionInfo(modules, version)\n }\n\n // Add data codewords\n setupData(modules, dataBits)\n\n if (isNaN(maskPattern)) {\n // Find best mask pattern\n maskPattern = MaskPattern.getBestMask(modules,\n setupFormatInfo.bind(null, modules, errorCorrectionLevel))\n }\n\n // Apply mask pattern\n MaskPattern.applyMask(maskPattern, modules)\n\n // Replace format info bits with correct values\n setupFormatInfo(modules, errorCorrectionLevel, maskPattern)\n\n return {\n modules: modules,\n version: version,\n errorCorrectionLevel: errorCorrectionLevel,\n maskPattern: maskPattern,\n segments: segments\n }\n}\n\n/**\n * QR Code\n *\n * @param {String | Array} data Input data\n * @param {Object} options Optional configurations\n * @param {Number} options.version QR Code version\n * @param {String} options.errorCorrectionLevel Error correction level\n * @param {Function} options.toSJISFunc Helper func to convert utf8 to sjis\n */\nexports.create = function create (data, options) {\n if (typeof data === 'undefined' || data === '') {\n throw new Error('No input text')\n }\n\n let errorCorrectionLevel = ECLevel.M\n let version\n let mask\n\n if (typeof options !== 'undefined') {\n // Use higher error correction level as default\n errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M)\n version = Version.from(options.version)\n mask = MaskPattern.from(options.maskPattern)\n\n if (options.toSJISFunc) {\n Utils.setToSJISFunction(options.toSJISFunc)\n }\n }\n\n return createSymbol(data, version, errorCorrectionLevel, mask)\n}\n","function hex2rgba (hex) {\n if (typeof hex === 'number') {\n hex = hex.toString()\n }\n\n if (typeof hex !== 'string') {\n throw new Error('Color should be defined as hex string')\n }\n\n let hexCode = hex.slice().replace('#', '').split('')\n if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {\n throw new Error('Invalid hex color: ' + hex)\n }\n\n // Convert from short to long form (fff -> ffffff)\n if (hexCode.length === 3 || hexCode.length === 4) {\n hexCode = Array.prototype.concat.apply([], hexCode.map(function (c) {\n return [c, c]\n }))\n }\n\n // Add default alpha value\n if (hexCode.length === 6) hexCode.push('F', 'F')\n\n const hexValue = parseInt(hexCode.join(''), 16)\n\n return {\n r: (hexValue >> 24) & 255,\n g: (hexValue >> 16) & 255,\n b: (hexValue >> 8) & 255,\n a: hexValue & 255,\n hex: '#' + hexCode.slice(0, 6).join('')\n }\n}\n\nexports.getOptions = function getOptions (options) {\n if (!options) options = {}\n if (!options.color) options.color = {}\n\n const margin = typeof options.margin === 'undefined' ||\n options.margin === null ||\n options.margin < 0\n ? 4\n : options.margin\n\n const width = options.width && options.width >= 21 ? options.width : undefined\n const scale = options.scale || 4\n\n return {\n width: width,\n scale: width ? 4 : scale,\n margin: margin,\n color: {\n dark: hex2rgba(options.color.dark || '#000000ff'),\n light: hex2rgba(options.color.light || '#ffffffff')\n },\n type: options.type,\n rendererOpts: options.rendererOpts || {}\n }\n}\n\nexports.getScale = function getScale (qrSize, opts) {\n return opts.width && opts.width >= qrSize + opts.margin * 2\n ? opts.width / (qrSize + opts.margin * 2)\n : opts.scale\n}\n\nexports.getImageWidth = function getImageWidth (qrSize, opts) {\n const scale = exports.getScale(qrSize, opts)\n return Math.floor((qrSize + opts.margin * 2) * scale)\n}\n\nexports.qrToImageData = function qrToImageData (imgData, qr, opts) {\n const size = qr.modules.size\n const data = qr.modules.data\n const scale = exports.getScale(size, opts)\n const symbolSize = Math.floor((size + opts.margin * 2) * scale)\n const scaledMargin = opts.margin * scale\n const palette = [opts.color.light, opts.color.dark]\n\n for (let i = 0; i < symbolSize; i++) {\n for (let j = 0; j < symbolSize; j++) {\n let posDst = (i * symbolSize + j) * 4\n let pxColor = opts.color.light\n\n if (i >= scaledMargin && j >= scaledMargin &&\n i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {\n const iSrc = Math.floor((i - scaledMargin) / scale)\n const jSrc = Math.floor((j - scaledMargin) / scale)\n pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0]\n }\n\n imgData[posDst++] = pxColor.r\n imgData[posDst++] = pxColor.g\n imgData[posDst++] = pxColor.b\n imgData[posDst] = pxColor.a\n }\n }\n}\n","const Utils = require('./utils')\n\nfunction clearCanvas (ctx, canvas, size) {\n ctx.clearRect(0, 0, canvas.width, canvas.height)\n\n if (!canvas.style) canvas.style = {}\n canvas.height = size\n canvas.width = size\n canvas.style.height = size + 'px'\n canvas.style.width = size + 'px'\n}\n\nfunction getCanvasElement () {\n try {\n return document.createElement('canvas')\n } catch (e) {\n throw new Error('You need to specify a canvas element')\n }\n}\n\nexports.render = function render (qrData, canvas, options) {\n let opts = options\n let canvasEl = canvas\n\n if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {\n opts = canvas\n canvas = undefined\n }\n\n if (!canvas) {\n canvasEl = getCanvasElement()\n }\n\n opts = Utils.getOptions(opts)\n const size = Utils.getImageWidth(qrData.modules.size, opts)\n\n const ctx = canvasEl.getContext('2d')\n const image = ctx.createImageData(size, size)\n Utils.qrToImageData(image.data, qrData, opts)\n\n clearCanvas(ctx, canvasEl, size)\n ctx.putImageData(image, 0, 0)\n\n return canvasEl\n}\n\nexports.renderToDataURL = function renderToDataURL (qrData, canvas, options) {\n let opts = options\n\n if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {\n opts = canvas\n canvas = undefined\n }\n\n if (!opts) opts = {}\n\n const canvasEl = exports.render(qrData, canvas, opts)\n\n const type = opts.type || 'image/png'\n const rendererOpts = opts.rendererOpts || {}\n\n return canvasEl.toDataURL(type, rendererOpts.quality)\n}\n","const Utils = require('./utils')\n\nfunction getColorAttrib (color, attrib) {\n const alpha = color.a / 255\n const str = attrib + '=\"' + color.hex + '\"'\n\n return alpha < 1\n ? str + ' ' + attrib + '-opacity=\"' + alpha.toFixed(2).slice(1) + '\"'\n : str\n}\n\nfunction svgCmd (cmd, x, y) {\n let str = cmd + x\n if (typeof y !== 'undefined') str += ' ' + y\n\n return str\n}\n\nfunction qrToPath (data, size, margin) {\n let path = ''\n let moveBy = 0\n let newRow = false\n let lineLength = 0\n\n for (let i = 0; i < data.length; i++) {\n const col = Math.floor(i % size)\n const row = Math.floor(i / size)\n\n if (!col && !newRow) newRow = true\n\n if (data[i]) {\n lineLength++\n\n if (!(i > 0 && col > 0 && data[i - 1])) {\n path += newRow\n ? svgCmd('M', col + margin, 0.5 + row + margin)\n : svgCmd('m', moveBy, 0)\n\n moveBy = 0\n newRow = false\n }\n\n if (!(col + 1 < size && data[i + 1])) {\n path += svgCmd('h', lineLength)\n lineLength = 0\n }\n } else {\n moveBy++\n }\n }\n\n return path\n}\n\nexports.render = function render (qrData, options, cb) {\n const opts = Utils.getOptions(options)\n const size = qrData.modules.size\n const data = qrData.modules.data\n const qrcodesize = size + opts.margin * 2\n\n const bg = !opts.color.light.a\n ? ''\n : ''\n\n const path =\n ''\n\n const viewBox = 'viewBox=\"' + '0 0 ' + qrcodesize + ' ' + qrcodesize + '\"'\n\n const width = !opts.width ? '' : 'width=\"' + opts.width + '\" height=\"' + opts.width + '\" '\n\n const svgTag = '' + bg + path + '\\n'\n\n if (typeof cb === 'function') {\n cb(null, svgTag)\n }\n\n return svgTag\n}\n","\nconst canPromise = require('./can-promise')\n\nconst QRCode = require('./core/qrcode')\nconst CanvasRenderer = require('./renderer/canvas')\nconst SvgRenderer = require('./renderer/svg-tag.js')\n\nfunction renderCanvas (renderFunc, canvas, text, opts, cb) {\n const args = [].slice.call(arguments, 1)\n const argsNum = args.length\n const isLastArgCb = typeof args[argsNum - 1] === 'function'\n\n if (!isLastArgCb && !canPromise()) {\n throw new Error('Callback required as last argument')\n }\n\n if (isLastArgCb) {\n if (argsNum < 2) {\n throw new Error('Too few arguments provided')\n }\n\n if (argsNum === 2) {\n cb = text\n text = canvas\n canvas = opts = undefined\n } else if (argsNum === 3) {\n if (canvas.getContext && typeof cb === 'undefined') {\n cb = opts\n opts = undefined\n } else {\n cb = opts\n opts = text\n text = canvas\n canvas = undefined\n }\n }\n } else {\n if (argsNum < 1) {\n throw new Error('Too few arguments provided')\n }\n\n if (argsNum === 1) {\n text = canvas\n canvas = opts = undefined\n } else if (argsNum === 2 && !canvas.getContext) {\n opts = text\n text = canvas\n canvas = undefined\n }\n\n return new Promise(function (resolve, reject) {\n try {\n const data = QRCode.create(text, opts)\n resolve(renderFunc(data, canvas, opts))\n } catch (e) {\n reject(e)\n }\n })\n }\n\n try {\n const data = QRCode.create(text, opts)\n cb(null, renderFunc(data, canvas, opts))\n } catch (e) {\n cb(e)\n }\n}\n\nexports.create = QRCode.create\nexports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render)\nexports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL)\n\n// only svg for now.\nexports.toString = renderCanvas.bind(null, function (data, _, opts) {\n return SvgRenderer.render(data, opts)\n})\n","import { FlottformChannelHost } from './flottform-channel-host';\n\ntype HostKey = string;\ntype ClientKey = string;\ntype EndpointId = string;\ntype EndpointInfo = {\n\thostKey: HostKey;\n\tendpointId: EndpointId;\n\thostInfo: {\n\t\tsession: string;\n\t\ticeCandidates: string;\n\t};\n\tclientKey?: ClientKey;\n\tclientInfo?: {\n\t\tsession: string;\n\t\ticeCandidates: string;\n\t};\n};\n\nexport type BaseListeners = {\n\tnew: [];\n\tdisconnected: [];\n\terror: [error: Error];\n\tconnected: [];\n\t'endpoint-created': [{ link: string; qrCode: string }];\n\t'webrtc:waiting-for-client': [\n\t\tevent: { link: string; qrCode: string; channel: FlottformChannelHost }\n\t];\n\t'webrtc:waiting-for-ice': [];\n};\n\nexport type SafeEndpointInfo = Omit;\n\nexport type ClientState =\n\t| 'init'\n\t| 'retrieving-info-from-endpoint' // first request to server\n\t| 'sending-client-info' // initial request to endpoint\n\t| 'connecting-to-host' // initial connection\n\t| 'connection-impossible' // if a connection is not possible due to network restrictions\n\t| 'connected' // waiting for user input, having a connection\n\t| 'disconnected' // failed after having a connection\n\t| 'done' // done with sending\n\t| 'error';\n\nexport type FlottformState =\n\t| 'new'\n\t| 'waiting-for-client'\n\t| 'waiting-for-ice'\n\t| 'waiting-for-data'\n\t| 'receiving-data'\n\t| 'done'\n\t| 'error';\n\nexport type Logger = {\n\tdebug: typeof console.debug;\n\tinfo: typeof console.info;\n\tlog: typeof console.log;\n\twarn: typeof console.warn;\n\terror: typeof console.error;\n};\n\nexport type FileMetaInfos = {\n\tdata: string;\n\tlastModified?: number;\n\tname?: string;\n\tsize: number;\n\ttype?: string;\n};\n\nexport const POLL_TIME_IN_MS: number = 1000;\n\nexport const DEFAULT_WEBRTC_CONFIG: RTCConfiguration = {\n\ticeServers: [\n\t\t{\n\t\t\turls: ['stun:stun1.l.google.com:19302']\n\t\t}\n\t]\n};\n\nexport function generateSecretKey(): string {\n\treturn crypto.randomUUID();\n}\n\nexport async function retrieveEndpointInfo(getEndpointInfoUrl: string) {\n\tconst response = await fetch(getEndpointInfoUrl);\n\treturn (await response.json()) as SafeEndpointInfo;\n}\n\nexport async function addIceCandidatesToConnection(\n\tconnection: RTCPeerConnection,\n\ticeCandidates: RTCIceCandidateInit[]\n) {\n\tfor (const iceCandidate of iceCandidates) {\n\t\tawait connection.addIceCandidate(iceCandidate);\n\t}\n}\n\nexport function setIncludes(set: Set, x: T): boolean {\n\tfor (const item of set) {\n\t\tif (JSON.stringify(item) === JSON.stringify(x)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\ntype Listener> = (...args: T) => void; // eslint-disable-line @typescript-eslint/no-explicit-any\nexport type FlottformEventMap = {\n\tnew: [details: { channel: FlottformChannelHost }];\n\t'waiting-for-client': [\n\t\tdetails: {\n\t\t\tqrCode: string;\n\t\t\tlink: string;\n\t\t\tchannel: FlottformChannelHost;\n\t\t}\n\t];\n\t'waiting-for-data': [];\n\t'waiting-for-ice': [];\n\t'receiving-data': [e: MessageEvent];\n\t'file-received': [{ fileMeta: FileMetaInfos; arrayBuffer: Array }];\n\tdone: [];\n\terror: [error: Error];\n\tconnected: [];\n\tdisconnected: [];\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class EventEmitter>> {\n\tprivate eventListeners: { [K in keyof EventMap]?: Set> } = {};\n\n\ton(eventName: K, listener: Listener) {\n\t\tconst listeners = this.eventListeners[eventName] ?? new Set();\n\t\tlisteners.add(listener);\n\t\tthis.eventListeners[eventName] = listeners;\n\t}\n\n\toff(eventName: K, listener: Listener) {\n\t\tconst listeners = this.eventListeners[eventName];\n\t\tif (listeners) {\n\t\t\tlisteners.delete(listener);\n\t\t\tif (listeners.size === 0) {\n\t\t\t\tdelete this.eventListeners[eventName];\n\t\t\t}\n\t\t}\n\t}\n\n\temit(eventName: K, ...args: EventMap[K]) {\n\t\tconst listeners = this.eventListeners[eventName] ?? new Set();\n\t\tfor (const listener of listeners) {\n\t\t\tlistener(...args);\n\t\t}\n\t}\n}\n\nexport abstract class BaseInputHost extends EventEmitter {\n\tabstract start();\n\tabstract close();\n}\n","export async function generateKey(): Promise {\n\treturn await crypto.subtle.generateKey(\n\t\t{\n\t\t\tname: 'AES-GCM',\n\t\t\tlength: 256\n\t\t},\n\t\ttrue, // extractable\n\t\t['encrypt', 'decrypt']\n\t);\n}\n\nexport async function cryptoKeyToEncryptionKey(key: CryptoKey) {\n\t// CryptoKey --> Exported bytes of the cryptoKey (i.e. the encryption key)\n\treturn (await crypto.subtle.exportKey('jwk', key)).k;\n}\n\nexport async function encryptionKeyToCryptoKey(encryptionKey: string) {\n\t// Create a complete JWK object structure\n\tconst jwk = {\n\t\tkty: 'oct',\n\t\tk: encryptionKey,\n\t\talg: 'A256GCM',\n\t\text: true,\n\t\tkey_ops: ['encrypt', 'decrypt']\n\t};\n\n\t// Import the complete JWK\n\treturn await crypto.subtle.importKey(\n\t\t'jwk',\n\t\tjwk,\n\t\t{\n\t\t\tname: 'AES-GCM',\n\t\t\tlength: 256 // Make sure this matches your key length\n\t\t},\n\t\ttrue, // extractable\n\t\t['encrypt', 'decrypt']\n\t);\n}\n\nexport async function encrypt(plaintext: string, cryptoKey: CryptoKey): Promise {\n\tconst data = plaintextToTypedArray(plaintext);\n\tconst iv = getInitializationVector();\n\n\tconst encryptedData = await crypto.subtle.encrypt(\n\t\t{\n\t\t\tname: 'AES-GCM',\n\t\t\tiv\n\t\t},\n\t\tcryptoKey,\n\t\tdata\n\t);\n\n\t// Prepend the cyphertext with the initialization vector.\n\tconst combinedData = new Uint8Array(iv.length + encryptedData.byteLength);\n\tcombinedData.set(iv, 0);\n\tcombinedData.set(new Uint8Array(encryptedData), iv.length);\n\n\treturn typedArrayToBase64(combinedData);\n}\n\nexport async function decrypt(ciphertext: string, cryptoKey: CryptoKey) {\n\tconst combinedData = base64ToTypedArray(ciphertext);\n\n\t// Step 2: Extract IV and ciphertext\n\tconst iv = combinedData.slice(0, 12);\n\tconst data = combinedData.slice(12);\n\n\tconst decryptedData = await crypto.subtle.decrypt(\n\t\t{\n\t\t\tname: 'AES-GCM',\n\t\t\tiv\n\t\t},\n\t\tcryptoKey,\n\t\tdata\n\t);\n\n\treturn typedArrayToPlaintext(new Uint8Array(decryptedData));\n}\n\nfunction plaintextToTypedArray(plainText: string): Uint8Array {\n\t// Then encode to Uint8Array\n\tconst encoder = new TextEncoder();\n\treturn encoder.encode(plainText);\n}\n\nfunction getInitializationVector(): Uint8Array {\n\treturn crypto.getRandomValues(new Uint8Array(12));\n}\n\nfunction typedArrayToBase64(typedArray: Uint8Array): string {\n\t// Uint8Array --> Base64\n\treturn btoa(String.fromCharCode(...new Uint8Array(typedArray)));\n}\n\nfunction base64ToTypedArray(messageAsBase64: string): Uint8Array {\n\t// Base64 --> Uint8Array\n\tconst binaryString = atob(messageAsBase64);\n\treturn Uint8Array.from(binaryString, (char) => char.charCodeAt(0));\n}\n\nfunction typedArrayToPlaintext(typedArray: Uint8Array, isOriginalDataJson = true) {\n\t// Uint8Array --> data (string, number, object, array..)\n\tconst decoder = new TextDecoder();\n\tconst plaintext = decoder.decode(typedArray);\n\treturn isOriginalDataJson ? JSON.parse(plaintext) : plaintext;\n}\n","import { toDataURL } from 'qrcode';\nimport {\n\tEventEmitter,\n\tFlottformEventMap,\n\tFlottformState,\n\tLogger,\n\tretrieveEndpointInfo,\n\tsetIncludes\n} from './internal';\nimport { cryptoKeyToEncryptionKey, decrypt, encrypt, generateKey } from './encryption';\n\nexport class FlottformChannelHost extends EventEmitter {\n\tprivate flottformApi: string | URL;\n\tprivate createClientUrl: (params: {\n\t\tendpointId: string;\n\t\tencryptionKey: string;\n\t\toptionalData?: object;\n\t}) => Promise;\n\tprivate rtcConfiguration: RTCConfiguration;\n\tprivate pollTimeForIceInMs: number;\n\tprivate logger: Logger;\n\n\tprivate cryptoKey: CryptoKey | null = null;\n\tprivate state: FlottformState | 'disconnected' = 'new';\n\tprivate channelNumber: number = 0;\n\tprivate openPeerConnection: RTCPeerConnection | null = null;\n\tprivate dataChannel: RTCDataChannel | null = null;\n\tprivate pollForIceTimer: NodeJS.Timeout | number | null = null;\n\n\tconstructor({\n\t\tflottformApi,\n\t\tcreateClientUrl,\n\t\trtcConfiguration,\n\t\tpollTimeForIceInMs,\n\t\tlogger\n\t}: {\n\t\tflottformApi: string | URL;\n\t\tcreateClientUrl: (params: {\n\t\t\tendpointId: string;\n\t\t\tencryptionKey: string;\n\t\t\toptionalData?: object;\n\t\t}) => Promise;\n\t\trtcConfiguration: RTCConfiguration;\n\t\tpollTimeForIceInMs: number;\n\t\tlogger: Logger;\n\t}) {\n\t\tsuper();\n\t\tthis.flottformApi = flottformApi;\n\t\tthis.createClientUrl = createClientUrl;\n\t\tthis.rtcConfiguration = rtcConfiguration;\n\t\tthis.pollTimeForIceInMs = pollTimeForIceInMs;\n\t\tthis.logger = logger;\n\t\tPromise.resolve().then(() => {\n\t\t\tthis.changeState('new', { channel: this });\n\t\t});\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate changeState = (newState: FlottformState | 'disconnected', details?: any) => {\n\t\tthis.state = newState;\n\t\tthis.emit(newState, details);\n\t\tthis.logger.info(`State changed to: ${newState}`, details == undefined ? '' : details);\n\t};\n\n\tstart = async () => {\n\t\tif (this.openPeerConnection) {\n\t\t\tthis.close();\n\t\t}\n\t\t// Generate Encryption/Decryption Key.\n\t\tthis.cryptoKey = await generateKey();\n\n\t\tconst baseApi = (\n\t\t\tthis.flottformApi instanceof URL ? this.flottformApi : new URL(this.flottformApi)\n\t\t)\n\t\t\t.toString()\n\t\t\t.replace(/\\/$/, '');\n\n\t\t// For now the fetching can be done outside of these classes and should be passed as an argument.\n\t\t/* try {\n\t\t\tthis.rtcConfiguration.iceServers = await this.fetchIceServers(baseApi);\n\t\t} catch (error) {\n\t\t\t// Use the default configuration as a fallback\n\t\t\tthis.logger.error(error);\n\t\t} */\n\t\tthis.openPeerConnection = new RTCPeerConnection(this.rtcConfiguration);\n\n\t\tthis.dataChannel = this.createDataChannel();\n\n\t\tconst session = await this.openPeerConnection.createOffer();\n\t\tawait this.openPeerConnection.setLocalDescription(session);\n\n\t\tconst { endpointId, hostKey } = await this.createEndpoint(baseApi, session);\n\t\tthis.logger.log('Created endpoint', { endpointId, hostKey });\n\n\t\tconst getEndpointInfoUrl = `${baseApi}/${endpointId}`;\n\t\tconst putHostInfoUrl = `${baseApi}/${endpointId}/host`;\n\n\t\tconst hostIceCandidates = new Set();\n\t\tawait this.putHostInfo(putHostInfoUrl, hostKey, hostIceCandidates, session);\n\n\t\tthis.setUpConnectionStateGathering(getEndpointInfoUrl);\n\t\tthis.setupHostIceGathering(putHostInfoUrl, hostKey, hostIceCandidates, session);\n\t\tthis.setupDataChannelForTransfer();\n\n\t\tconst encryptionKey = await cryptoKeyToEncryptionKey(this.cryptoKey);\n\t\tif (!encryptionKey) {\n\t\t\tthrow new Error('Encryption Key is undefined!');\n\t\t}\n\t\tconst connectLink = await this.createClientUrl({ endpointId, encryptionKey });\n\t\tthis.changeState('waiting-for-client', {\n\t\t\tqrCode: await toDataURL(connectLink),\n\t\t\tlink: connectLink,\n\t\t\tchannel: this\n\t\t});\n\t\t// Setup listener for messages incoming from the client\n\t\tthis.setupDataChannelListener();\n\t};\n\n\tclose = () => {\n\t\tif (this.openPeerConnection) {\n\t\t\tthis.openPeerConnection.close();\n\t\t\tthis.openPeerConnection = null;\n\t\t\tthis.stopPollingForConnection();\n\t\t}\n\t\tthis.changeState('disconnected');\n\t};\n\n\tprivate setupDataChannelListener = () => {\n\t\tif (this.dataChannel == null) {\n\t\t\tthis.changeState(\n\t\t\t\t'error',\n\t\t\t\t'dataChannel is null. Unable to setup the listeners for the data channel'\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.dataChannel.onmessage = (e) => {\n\t\t\t// Handling the incoming data from the client depends on the use case.\n\t\t\tthis.emit('receiving-data', e);\n\t\t};\n\t};\n\n\tprivate setupHostIceGathering = (\n\t\tputHostInfoUrl: string,\n\t\thostKey: string,\n\t\thostIceCandidates: Set,\n\t\tsession: RTCSessionDescriptionInit\n\t) => {\n\t\tif (this.openPeerConnection === null) {\n\t\t\tthis.changeState('error', 'openPeerConnection is null. Unable to gather Host ICE candidates');\n\t\t\treturn;\n\t\t}\n\n\t\tthis.openPeerConnection.onicecandidate = async (e) => {\n\t\t\tthis.logger.info(\n\t\t\t\t`onicecandidate - ${this.openPeerConnection!.connectionState} - ${e.candidate}`\n\t\t\t);\n\t\t\tif (e.candidate) {\n\t\t\t\tif (!setIncludes(hostIceCandidates, e.candidate)) {\n\t\t\t\t\tthis.logger.log('host found new ice candidate! Adding it to our list');\n\t\t\t\t\thostIceCandidates.add(e.candidate);\n\t\t\t\t\tawait this.putHostInfo(putHostInfoUrl, hostKey, hostIceCandidates, session);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tthis.openPeerConnection.onicegatheringstatechange = async (e) => {\n\t\t\tthis.logger.info(\n\t\t\t\t`onicegatheringstatechange - ${this.openPeerConnection!.iceGatheringState} - ${e}`\n\t\t\t);\n\t\t};\n\n\t\tthis.openPeerConnection.onicecandidateerror = async (e) => {\n\t\t\tthis.logger.error('peerConnection.onicecandidateerror', e);\n\t\t};\n\t};\n\n\tprivate setUpConnectionStateGathering = (getEndpointInfoUrl: string) => {\n\t\tif (this.openPeerConnection === null) {\n\t\t\tthis.changeState(\n\t\t\t\t'error',\n\t\t\t\t\"openPeerConnection is null. Unable to poll for the client's details\"\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.startPollingForConnection(getEndpointInfoUrl);\n\n\t\tthis.openPeerConnection.onconnectionstatechange = () => {\n\t\t\tthis.logger.info(`onconnectionstatechange - ${this.openPeerConnection!.connectionState}`);\n\t\t\tif (this.openPeerConnection!.connectionState === 'connected') {\n\t\t\t\tthis.stopPollingForConnection();\n\t\t\t}\n\t\t\tif (this.openPeerConnection!.connectionState === 'disconnected') {\n\t\t\t\tthis.startPollingForConnection(getEndpointInfoUrl);\n\t\t\t}\n\t\t\tif (this.openPeerConnection!.connectionState === 'failed') {\n\t\t\t\tthis.stopPollingForConnection();\n\t\t\t\tthis.changeState('error', { message: 'connection-failed' });\n\t\t\t}\n\t\t};\n\n\t\tthis.openPeerConnection.oniceconnectionstatechange = async (e) => {\n\t\t\tthis.logger.info(\n\t\t\t\t`oniceconnectionstatechange - ${this.openPeerConnection!.iceConnectionState} - ${e}`\n\t\t\t);\n\t\t\tif (this.openPeerConnection!.iceConnectionState === 'failed') {\n\t\t\t\tthis.logger.log('Failed to find a possible connection path');\n\t\t\t\tthis.changeState('error', { message: 'connection-impossible' });\n\t\t\t}\n\t\t};\n\t};\n\n\tprivate stopPollingForConnection = async () => {\n\t\tif (this.pollForIceTimer) {\n\t\t\tclearTimeout(this.pollForIceTimer);\n\t\t}\n\t\tthis.pollForIceTimer = null;\n\t};\n\n\tprivate startPollingForConnection = async (getEndpointInfoUrl: string) => {\n\t\tif (this.pollForIceTimer) {\n\t\t\tclearTimeout(this.pollForIceTimer);\n\t\t}\n\n\t\tawait this.pollForConnection(getEndpointInfoUrl);\n\n\t\tthis.pollForIceTimer = setTimeout(() => {\n\t\t\tthis.startPollingForConnection(getEndpointInfoUrl);\n\t\t}, this.pollTimeForIceInMs);\n\t};\n\n\tprivate createEndpoint = async (baseApi: string, session: RTCSessionDescriptionInit) => {\n\t\tif (!this.cryptoKey) {\n\t\t\tthrow new Error('CryptoKey is null! Encryption is not possible!!');\n\t\t}\n\t\tconst encryptedSession = await encrypt(JSON.stringify(session), this.cryptoKey);\n\n\t\tconst response = await fetch(`${baseApi}/create`, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\tAccept: 'application/json',\n\t\t\t\t'Content-Type': 'application/json'\n\t\t\t},\n\t\t\tbody: JSON.stringify({ session: encryptedSession })\n\t\t});\n\n\t\treturn response.json();\n\t};\n\n\tprivate fetchIceServers = async (baseApi: string) => {\n\t\tconst response = await fetch(`${baseApi}/ice-server-credentials`, {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\tAccept: 'application/json'\n\t\t\t}\n\t\t});\n\t\tif (!response.ok) {\n\t\t\tthrow new Error('Fetching Error!');\n\t\t}\n\t\tconst data = await response.json();\n\n\t\tif (data.success === false) {\n\t\t\tthrow new Error(data.message || 'Unknown error occurred');\n\t\t}\n\n\t\treturn data.iceServers;\n\t};\n\n\tprivate pollForConnection = async (getEndpointInfoUrl: string) => {\n\t\tif (this.openPeerConnection === null) {\n\t\t\tthis.changeState('error', \"openPeerConnection is null. Unable to retrieve Client's details\");\n\t\t\treturn;\n\t\t}\n\n\t\tthis.logger.log('polling for client ice candidates', this.openPeerConnection.iceGatheringState);\n\t\tconst { clientInfo } = await retrieveEndpointInfo(getEndpointInfoUrl);\n\n\t\tif (!this.cryptoKey) {\n\t\t\tthrow new Error('CryptoKey is null! Decryption is not possible!!');\n\t\t}\n\t\tlet decryptedSession;\n\t\tlet decryptedIceCandidates: RTCIceCandidateInit[] = [];\n\n\t\tif (clientInfo) {\n\t\t\tdecryptedSession = await decrypt(clientInfo.session, this.cryptoKey);\n\t\t\tdecryptedIceCandidates = await decrypt(clientInfo.iceCandidates, this.cryptoKey);\n\t\t}\n\n\t\tif (clientInfo && this.state === 'waiting-for-client') {\n\t\t\tthis.logger.log('Found a client that wants to connect!');\n\t\t\tthis.changeState('waiting-for-ice');\n\t\t\tawait this.openPeerConnection.setRemoteDescription(decryptedSession);\n\t\t}\n\n\t\tfor (const iceCandidate of decryptedIceCandidates ?? []) {\n\t\t\tawait this.openPeerConnection.addIceCandidate(iceCandidate);\n\t\t}\n\t};\n\n\tprivate setupDataChannelForTransfer = () => {\n\t\tif (this.dataChannel === null) {\n\t\t\tthis.changeState('error', 'dataChannel is null. Unable to setup a Data Channel');\n\t\t\treturn;\n\t\t}\n\n\t\tthis.dataChannel.onopen = () => {\n\t\t\tthis.logger.log('data channel opened');\n\t\t\tthis.changeState('waiting-for-data');\n\t\t};\n\n\t\tthis.dataChannel.onclose = () => {\n\t\t\tthis.logger.log('data channel closed');\n\t\t};\n\n\t\tthis.dataChannel.onerror = (e) => {\n\t\t\tthis.logger.log('channel.onerror', e);\n\t\t\tthis.changeState('error', { message: 'file-transfer' });\n\t\t};\n\t};\n\n\tprivate createDataChannel = () => {\n\t\tif (this.openPeerConnection === null) {\n\t\t\tthis.changeState('error', 'openPeerConnection is null. Unable to create a new Data Channel');\n\t\t\treturn null;\n\t\t}\n\n\t\tthis.channelNumber++;\n\t\tconst channelName = `data-channel-${this.channelNumber}`;\n\t\treturn this.openPeerConnection.createDataChannel(channelName);\n\t};\n\n\tprivate putHostInfo = async (\n\t\tputHostInfoUrl: string,\n\t\thostKey: string,\n\t\thostIceCandidates: Set,\n\t\tsession: RTCSessionDescriptionInit\n\t) => {\n\t\ttry {\n\t\t\tthis.logger.log('Updating host info with new list of ice candidates');\n\t\t\tif (!this.cryptoKey) {\n\t\t\t\tthrow new Error('CryptoKey is null! Encryption is not possible!!');\n\t\t\t}\n\n\t\t\tconst encryptedIceCandidates = await encrypt(\n\t\t\t\tJSON.stringify([...hostIceCandidates]),\n\t\t\t\tthis.cryptoKey\n\t\t\t);\n\t\t\tconst encryptedSession = await encrypt(JSON.stringify(session), this.cryptoKey);\n\n\t\t\tconst response = await fetch(putHostInfoUrl, {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\thostKey,\n\t\t\t\t\ticeCandidates: encryptedIceCandidates,\n\t\t\t\t\tsession: encryptedSession\n\t\t\t\t})\n\t\t\t});\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow Error('Could not update host info');\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tthis.changeState('error', err);\n\t\t}\n\t};\n}\n","import { FlottformChannelHost } from './flottform-channel-host';\nimport {\n\tBaseInputHost,\n\tBaseListeners,\n\tDEFAULT_WEBRTC_CONFIG,\n\tLogger,\n\tPOLL_TIME_IN_MS\n} from './internal';\n\ntype Listeners = BaseListeners & {\n\treceive: []; // Emitted to signal the start of receiving the file(s)\n\tprogress: {\n\t\tfileIndex: number;\n\t\ttotalFileCount: number;\n\t\tfileName: string;\n\t\tcurrentFileProgress: number;\n\t\toverallProgress: number;\n\t}[]; // Emitted to signal the progress of receiving the file(s)\n\tdone: [];\n\t'webrtc:waiting-for-file': [];\n\t'single-file-transferred': [file: File];\n};\n\nexport class FlottformFileInputHost extends BaseInputHost {\n\tprivate channel: FlottformChannelHost | null = null;\n\tprivate inputField?: HTMLInputElement;\n\tprivate logger: Logger;\n\tprivate filesMetaData: { name: string; type: string; size: number }[] = [];\n\tprivate filesTotalSize: number = 0;\n\tprivate receivedDataSize: number = 0;\n\tprivate currentFile: {\n\t\tindex: number;\n\t\treceivedSize: number;\n\t\tarrayBuffer: ArrayBuffer[];\n\t} | null = null;\n\tprivate link: string = '';\n\tprivate qrCode: string = '';\n\n\tconstructor({\n\t\tflottformApi,\n\t\tcreateClientUrl,\n\t\tinputField,\n\t\trtcConfiguration = DEFAULT_WEBRTC_CONFIG,\n\t\tpollTimeForIceInMs = POLL_TIME_IN_MS,\n\t\tlogger = console\n\t}: {\n\t\tflottformApi: string | URL;\n\t\tcreateClientUrl: (params: {\n\t\t\tendpointId: string;\n\t\t\tencryptionKey: string;\n\t\t\toptionalData?: object;\n\t\t}) => Promise;\n\t\tinputField?: HTMLInputElement;\n\t\trtcConfiguration?: RTCConfiguration;\n\t\tpollTimeForIceInMs?: number;\n\t\ttheme?: (myself: FlottformFileInputHost) => void;\n\t\tlogger?: Logger;\n\t}) {\n\t\tsuper();\n\t\tthis.channel = new FlottformChannelHost({\n\t\t\tflottformApi,\n\t\t\tcreateClientUrl,\n\t\t\trtcConfiguration,\n\t\t\tpollTimeForIceInMs,\n\t\t\tlogger\n\t\t});\n\t\tthis.inputField = inputField;\n\t\tthis.logger = logger;\n\n\t\tthis.registerListeners();\n\t}\n\n\tstart = () => {\n\t\tthis.channel?.start();\n\t};\n\n\tclose = () => {\n\t\tthis.channel?.close();\n\t};\n\n\tgetLink = () => {\n\t\tif (this.link === '') {\n\t\t\tthis.logger.error(\n\t\t\t\t'Flottform is currently establishing the connection. Link is unavailable for now!'\n\t\t\t);\n\t\t}\n\t\treturn this.link;\n\t};\n\n\tgetQrCode = () => {\n\t\tif (this.qrCode === '') {\n\t\t\tthis.logger.error(\n\t\t\t\t'Flottform is currently establishing the connection. qrCode is unavailable for now!'\n\t\t\t);\n\t\t}\n\t\treturn this.qrCode;\n\t};\n\n\tprivate handleIncomingData = (e: MessageEvent) => {\n\t\tif (typeof e.data === 'string') {\n\t\t\t// string can be either metadata or end transfer marker.\n\t\t\tconst message = JSON.parse(e.data);\n\t\t\tif (message.type === 'file-transfer-meta') {\n\t\t\t\t// Handle file metadata\n\t\t\t\tthis.filesMetaData = message.filesQueue;\n\t\t\t\tthis.currentFile = { index: 0, receivedSize: 0, arrayBuffer: [] };\n\t\t\t\tthis.filesTotalSize = message.totalSize;\n\t\t\t\t// Emit the start of receiving data\n\t\t\t\tthis.emit('receive');\n\t\t\t} else if (message.type === 'transfer-complete') {\n\t\t\t\tthis.emit('done');\n\t\t\t\tthis.channel?.close();\n\t\t\t}\n\t\t} else if (e.data instanceof ArrayBuffer) {\n\t\t\t// Handle file chunk\n\t\t\tif (this.currentFile) {\n\t\t\t\tthis.currentFile.arrayBuffer.push(e.data);\n\t\t\t\tthis.currentFile.receivedSize += e.data.byteLength;\n\t\t\t\tthis.receivedDataSize += e.data.byteLength;\n\n\t\t\t\tconst currentFileName = this.filesMetaData[this.currentFile.index]?.name as string;\n\n\t\t\t\tconst currentFileTotalSize = this.filesMetaData[this.currentFile.index]?.size as number;\n\n\t\t\t\tconst currentFileProgress = (this.currentFile.receivedSize / currentFileTotalSize).toFixed(\n\t\t\t\t\t2\n\t\t\t\t);\n\t\t\t\tconst overallProgress = (this.receivedDataSize / this.filesTotalSize).toFixed(2);\n\n\t\t\t\tthis.emit('progress', {\n\t\t\t\t\tfileIndex: this.currentFile.index,\n\t\t\t\t\ttotalFileCount: this.filesMetaData.length,\n\t\t\t\t\tfileName: currentFileName,\n\t\t\t\t\tcurrentFileProgress: parseFloat(currentFileProgress),\n\t\t\t\t\toverallProgress: parseFloat(overallProgress)\n\t\t\t\t});\n\n\t\t\t\tif (this.currentFile.receivedSize === currentFileTotalSize) {\n\t\t\t\t\t// Attach the current file to the given input field\n\t\t\t\t\tthis.appendFileToInputField(this.currentFile.index);\n\t\t\t\t\t// Initialize the values of currentFile to receive the next file\n\t\t\t\t\tthis.currentFile = {\n\t\t\t\t\t\tindex: this.currentFile.index + 1,\n\t\t\t\t\t\treceivedSize: 0,\n\t\t\t\t\t\tarrayBuffer: []\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate appendFileToInputField = (fileIndex: number) => {\n\t\tconst fileName = this.filesMetaData[fileIndex]?.name ?? 'no-name';\n\t\tconst fileType = this.filesMetaData[fileIndex]?.type ?? 'application/octet-stream';\n\n\t\tconst receivedFile = new File(this.currentFile?.arrayBuffer as ArrayBuffer[], fileName, {\n\t\t\ttype: fileType\n\t\t});\n\t\tthis.emit('single-file-transferred', receivedFile);\n\n\t\tif (!this.inputField) {\n\t\t\tthis.logger.warn(\n\t\t\t\t\"No input field provided!! You can listen to the 'single-file-transferred' event to handle the newly received file!\"\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst dt = new DataTransfer();\n\n\t\t// Add existing files from the input field to the DataTransfer object to avoid loosing them.\n\t\tif (this.inputField.files) {\n\t\t\tfor (const file of Array.from(this.inputField.files)) {\n\t\t\t\tdt.items.add(file);\n\t\t\t}\n\t\t}\n\n\t\tif (!this.inputField.multiple) {\n\t\t\tthis.logger.warn(\n\t\t\t\t\"The host's input field only supports one file. Incoming files from the client will overwrite any existing file, and only the last file received will remain attached.\"\n\t\t\t);\n\t\t\tdt.items.clear();\n\t\t}\n\n\t\tdt.items.add(receivedFile);\n\t\tthis.inputField.files = dt.files;\n\t};\n\n\tprivate registerListeners = () => {\n\t\tthis.channel?.on('new', () => {\n\t\t\tthis.emit('new');\n\t\t});\n\t\tthis.channel?.on('waiting-for-client', (event) => {\n\t\t\tthis.emit('webrtc:waiting-for-client', event);\n\t\t\tconst { qrCode, link } = event;\n\t\t\tthis.emit('endpoint-created', { link, qrCode });\n\t\t\tthis.link = link;\n\t\t\tthis.qrCode = qrCode;\n\t\t});\n\t\tthis.channel?.on('waiting-for-ice', () => {\n\t\t\tthis.emit('webrtc:waiting-for-ice');\n\t\t});\n\t\tthis.channel?.on('waiting-for-data', () => {\n\t\t\tthis.emit('webrtc:waiting-for-file');\n\t\t\tthis.emit('connected');\n\t\t});\n\t\tthis.channel?.on('receiving-data', (e) => {\n\t\t\tthis.handleIncomingData(e);\n\t\t});\n\t\tthis.channel?.on('disconnected', () => {\n\t\t\tthis.emit('disconnected');\n\t\t});\n\t\tthis.channel?.on('error', (error) => {\n\t\t\tthis.emit('error', error);\n\t\t});\n\t};\n}\n","import { decrypt, encrypt, encryptionKeyToCryptoKey } from './encryption';\nimport {\n\tClientState,\n\tEventEmitter,\n\tLogger,\n\tPOLL_TIME_IN_MS,\n\tgenerateSecretKey,\n\tretrieveEndpointInfo,\n\tsetIncludes\n} from './internal';\n\ntype Listeners = {\n\tinit: [];\n\t'retrieving-info-from-endpoint': [];\n\t'sending-client-info': [];\n\t'connecting-to-host': [];\n\tconnected: [];\n\t'connection-impossible': [];\n\tdone: [];\n\tdisconnected: [];\n\terror: [e: string];\n\tbufferedamountlow: [];\n};\n\nexport class FlottformChannelClient extends EventEmitter {\n\tprivate flottformApi: string | URL;\n\tprivate endpointId: string;\n\tprivate rtcConfiguration: RTCConfiguration;\n\tprivate pollTimeForIceInMs: number;\n\tprivate logger: Logger;\n\n\tprivate cryptoKey: CryptoKey | null = null;\n\tprivate encryptionKey: string;\n\tprivate state: ClientState = 'init';\n\tprivate openPeerConnection: RTCPeerConnection | null = null;\n\tprivate dataChannel: RTCDataChannel | null = null;\n\tprivate pollForIceTimer: NodeJS.Timeout | number | null = null;\n\tprivate BUFFER_THRESHOLD = 128 * 1024; // 128KB buffer threshold (maximum of 4 chunks in the buffer waiting to be sent over the network)\n\n\tconstructor({\n\t\tendpointId,\n\t\tflottformApi,\n\t\trtcConfiguration,\n\t\tencryptionKey,\n\t\tpollTimeForIceInMs = POLL_TIME_IN_MS,\n\t\tlogger = console\n\t}: {\n\t\tendpointId: string;\n\t\tflottformApi: string | URL;\n\t\trtcConfiguration: RTCConfiguration;\n\t\tencryptionKey: string;\n\t\tpollTimeForIceInMs?: number;\n\t\tlogger?: Logger;\n\t}) {\n\t\tsuper();\n\t\tthis.endpointId = endpointId;\n\t\tthis.flottformApi = flottformApi;\n\t\tthis.rtcConfiguration = rtcConfiguration;\n\t\tthis.encryptionKey = encryptionKey;\n\t\tthis.pollTimeForIceInMs = pollTimeForIceInMs;\n\t\tthis.logger = logger;\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate changeState = (newState: ClientState, details?: any) => {\n\t\tthis.state = newState;\n\t\tthis.emit(newState, details);\n\t\tthis.logger.info(`**Client State changed to: ${newState}`, details == undefined ? '' : details);\n\t};\n\n\tstart = async () => {\n\t\tif (this.openPeerConnection) {\n\t\t\tthis.close();\n\t\t}\n\t\t// Import cryptoKey from encryptionKey\n\t\tthis.cryptoKey = await encryptionKeyToCryptoKey(this.encryptionKey);\n\n\t\t/* const baseApi = (\n\t\t\tthis.flottformApi instanceof URL ? this.flottformApi : new URL(this.flottformApi)\n\t\t)\n\t\t\t.toString()\n\t\t\t.replace(/\\/$/, ''); */\n\n\t\t// For now the fetching can be done outside of these classes and should be passed as an argument.\n\n\t\t/* try {\n\t\t\tthis.rtcConfiguration.iceServers = await this.fetchIceServers(baseApi);\n\t\t} catch (error) {\n\t\t\t// Use the default configuration as a fallback\n\t\t\tthis.logger.error(error);\n\t\t} */\n\n\t\tthis.openPeerConnection = new RTCPeerConnection(this.rtcConfiguration);\n\t\tconst clientKey = generateSecretKey();\n\t\tconst clientIceCandidates = new Set();\n\t\tconst getEndpointInfoUrl = `${this.flottformApi}/${this.endpointId}`;\n\t\tconst putClientInfoUrl = `${this.flottformApi}/${this.endpointId}/client`;\n\n\t\tthis.changeState('retrieving-info-from-endpoint');\n\t\tconst { hostInfo } = await retrieveEndpointInfo(getEndpointInfoUrl);\n\t\tif (!this.cryptoKey) {\n\t\t\tthrow new Error('CryptoKey is null! Decryption is not possible!!');\n\t\t}\n\t\tconst hostSession: RTCSessionDescriptionInit = await decrypt(hostInfo.session, this.cryptoKey);\n\n\t\tawait this.openPeerConnection.setRemoteDescription(hostSession);\n\t\tconst session = await this.openPeerConnection.createAnswer();\n\t\tawait this.openPeerConnection.setLocalDescription(session);\n\n\t\tthis.setUpConnectionStateGathering(getEndpointInfoUrl);\n\t\tthis.setUpClientIceGathering(putClientInfoUrl, clientKey, clientIceCandidates, session);\n\t\tthis.openPeerConnection.ondatachannel = (e) => {\n\t\t\tthis.logger.info(`ondatachannel: ${e.channel}`);\n\t\t\tthis.changeState('connected');\n\t\t\tthis.dataChannel = e.channel;\n\t\t\t// Set the maximum amount of data waiting inside the datachannel's buffer\n\t\t\tthis.dataChannel.bufferedAmountLowThreshold = this.BUFFER_THRESHOLD;\n\t\t\t// Set the listener to listen then emit an event when the buffer has more space available and can be used to send more data\n\t\t\tthis.dataChannel.onbufferedamountlow = () => {\n\t\t\t\tthis.emit('bufferedamountlow');\n\t\t\t};\n\t\t\tthis.dataChannel.onopen = (e) => {\n\t\t\t\tthis.logger.info(`ondatachannel - onopen: ${e.type}`);\n\t\t\t};\n\t\t};\n\n\t\tthis.changeState('sending-client-info');\n\t\tawait this.putClientInfo(putClientInfoUrl, clientKey, clientIceCandidates, session);\n\n\t\tthis.changeState('connecting-to-host');\n\t\tthis.startPollingForIceCandidates(getEndpointInfoUrl);\n\t};\n\n\tclose = () => {\n\t\tif (this.openPeerConnection) {\n\t\t\tthis.openPeerConnection.close();\n\t\t\tthis.openPeerConnection = null;\n\t\t\tthis.stopPollingForIceCandidates();\n\t\t}\n\t\tthis.changeState('disconnected');\n\t};\n\n\t// sendData = (data: string | Blob | ArrayBuffer | ArrayBufferView) => {\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tsendData = (data: any) => {\n\t\tif (this.dataChannel == null) {\n\t\t\tthis.changeState('error', 'dataChannel is null. Unable to send the file to the Host!');\n\t\t\treturn;\n\t\t} else if (!this.canSendMoreData()) {\n\t\t\tthis.logger.warn('Data channel is full! Cannot send data at the moment');\n\t\t\treturn;\n\t\t}\n\t\tthis.dataChannel.send(data);\n\t};\n\n\tcanSendMoreData = () => {\n\t\treturn (\n\t\t\tthis.dataChannel &&\n\t\t\tthis.dataChannel.bufferedAmount < this.dataChannel.bufferedAmountLowThreshold\n\t\t);\n\t};\n\n\tprivate setUpClientIceGathering = (\n\t\tputClientInfoUrl: string,\n\t\tclientKey: string,\n\t\tclientIceCandidates: Set,\n\t\tsession: RTCSessionDescriptionInit\n\t) => {\n\t\tif (this.openPeerConnection === null) {\n\t\t\tthis.changeState(\n\t\t\t\t'error',\n\t\t\t\t'openPeerConnection is null. Unable to gather Client ICE candidates'\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.openPeerConnection.onicecandidate = async (e) => {\n\t\t\tthis.logger.info(\n\t\t\t\t`onicecandidate - ${this.openPeerConnection!.connectionState} - ${e.candidate}`\n\t\t\t);\n\t\t\tif (e.candidate) {\n\t\t\t\tif (!setIncludes(clientIceCandidates, e.candidate)) {\n\t\t\t\t\tthis.logger.log('client found new ice candidate! Adding it to our list');\n\t\t\t\t\tclientIceCandidates.add(e.candidate);\n\t\t\t\t\tawait this.putClientInfo(putClientInfoUrl, clientKey, clientIceCandidates, session);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tthis.openPeerConnection.onicegatheringstatechange = async () => {\n\t\t\tthis.logger.info(`onicegatheringstatechange - ${this.openPeerConnection!.iceGatheringState}`);\n\t\t};\n\t\tthis.openPeerConnection.onicecandidateerror = (e) => {\n\t\t\tthis.logger.error(`onicecandidateerror - ${this.openPeerConnection!.connectionState}`, e);\n\t\t};\n\t};\n\n\tprivate setUpConnectionStateGathering = (getEndpointInfoUrl: string) => {\n\t\tif (this.openPeerConnection === null) {\n\t\t\tthis.changeState(\n\t\t\t\t'error',\n\t\t\t\t'openPeerConnection is null. Unable to gather Client ICE candidates'\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tthis.openPeerConnection.onconnectionstatechange = () => {\n\t\t\tthis.logger.info(`onconnectionstatechange - ${this.openPeerConnection!.connectionState}`);\n\t\t\tif (this.openPeerConnection!.connectionState === 'connected') {\n\t\t\t\tthis.stopPollingForIceCandidates();\n\t\t\t\tif (this.state === 'connecting-to-host') {\n\t\t\t\t\tthis.changeState('connected');\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (this.openPeerConnection!.connectionState === 'disconnected') {\n\t\t\t\tthis.startPollingForIceCandidates(getEndpointInfoUrl);\n\t\t\t}\n\t\t\tif (this.openPeerConnection!.connectionState === 'failed') {\n\t\t\t\tthis.stopPollingForIceCandidates();\n\t\t\t\tif (this.state !== 'done') {\n\t\t\t\t\tthis.changeState('disconnected');\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tthis.openPeerConnection.oniceconnectionstatechange = () => {\n\t\t\tthis.logger.info(\n\t\t\t\t`oniceconnectionstatechange - ${this.openPeerConnection!.iceConnectionState}`\n\t\t\t);\n\t\t\tif (this.openPeerConnection!.iceConnectionState === 'failed') {\n\t\t\t\tthis.logger.log('Failed to find a possible connection path');\n\t\t\t\tthis.changeState('connection-impossible');\n\t\t\t}\n\t\t};\n\t};\n\n\tprivate stopPollingForIceCandidates = async () => {\n\t\tif (this.pollForIceTimer) {\n\t\t\tclearTimeout(this.pollForIceTimer);\n\t\t}\n\t\tthis.pollForIceTimer = null;\n\t};\n\n\tprivate startPollingForIceCandidates = async (getEndpointInfoUrl: string) => {\n\t\tif (this.pollForIceTimer) {\n\t\t\tclearTimeout(this.pollForIceTimer);\n\t\t}\n\n\t\tawait this.pollForConnection(getEndpointInfoUrl);\n\n\t\tthis.pollForIceTimer = setTimeout(this.startPollingForIceCandidates, this.pollTimeForIceInMs);\n\t};\n\n\tprivate pollForConnection = async (getEndpointInfoUrl: string) => {\n\t\tif (this.openPeerConnection === null) {\n\t\t\tthis.changeState('error', \"openPeerConnection is null. Unable to retrieve Host's details\");\n\t\t\treturn;\n\t\t}\n\n\t\tthis.logger.log('polling for host ice candidates', this.openPeerConnection.iceGatheringState);\n\t\tconst { hostInfo } = await retrieveEndpointInfo(getEndpointInfoUrl);\n\n\t\tif (!this.cryptoKey) {\n\t\t\tthrow new Error('CryptoKey is null! Decryption is not possible!!');\n\t\t}\n\t\tconst hostIceCandidates: RTCIceCandidateInit[] = await decrypt(\n\t\t\thostInfo.iceCandidates,\n\t\t\tthis.cryptoKey\n\t\t);\n\n\t\tfor (const iceCandidate of hostIceCandidates) {\n\t\t\tawait this.openPeerConnection.addIceCandidate(iceCandidate);\n\t\t}\n\t};\n\n\tprivate putClientInfo = async (\n\t\tputClientInfoUrl: string,\n\t\tclientKey: string,\n\t\tclientIceCandidates: Set,\n\t\tsession: RTCSessionDescriptionInit\n\t) => {\n\t\tthis.logger.log('Updating client info with new list of ice candidates');\n\t\tif (!this.cryptoKey) {\n\t\t\tthrow new Error('CryptoKey is null! Encryption is not possible!!');\n\t\t}\n\n\t\tconst encryptedIceCandidates = await encrypt(\n\t\t\tJSON.stringify([...clientIceCandidates]),\n\t\t\tthis.cryptoKey\n\t\t);\n\t\tconst encryptedSession = await encrypt(JSON.stringify(session), this.cryptoKey);\n\n\t\tconst response = await fetch(putClientInfoUrl, {\n\t\t\tmethod: 'PUT',\n\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\tbody: JSON.stringify({\n\t\t\t\tclientKey,\n\t\t\t\ticeCandidates: encryptedIceCandidates,\n\t\t\t\tsession: encryptedSession\n\t\t\t})\n\t\t});\n\t\tif (!response.ok) {\n\t\t\tthrow Error('Could not update client info. Did another peer already connect?');\n\t\t}\n\t};\n\tprivate fetchIceServers = async (baseApi: string) => {\n\t\tconst response = await fetch(`${baseApi}/ice-server-credentials`, {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\tAccept: 'application/json'\n\t\t\t}\n\t\t});\n\t\tif (!response.ok) {\n\t\t\tthrow new Error('Fetching Error!');\n\t\t}\n\t\tconst data = await response.json();\n\n\t\tif (data.success === false) {\n\t\t\tthrow new Error(data.message || 'Unknown error occurred');\n\t\t}\n\n\t\treturn data.iceServers;\n\t};\n}\n","import { FlottformChannelClient } from './flottform-channel-client';\nimport { DEFAULT_WEBRTC_CONFIG, EventEmitter, Logger, POLL_TIME_IN_MS } from './internal';\n\ntype Listeners = {\n\tconnected: [];\n\t'webrtc:connection-impossible': [];\n\tsending: []; // Emitted to signal the start of sending the file(s)\n\tprogress: [{ fileIndex: number; fileName: string; progress: number }]; // Emitted to signal the progress of sending the file(s)\n\tdone: [];\n\tdisconnected: [];\n\terror: [e: string];\n};\n\ntype MetaData = {\n\ttype: 'file-transfer-meta';\n\tfilesQueue: { name: string; type: string; size: number }[];\n\ttotalSize: number;\n};\n\nexport class FlottformFileInputClient extends EventEmitter {\n\tprivate channel: FlottformChannelClient | null = null;\n\tprivate inputField: HTMLInputElement;\n\tprivate chunkSize: number = 16384; // 16 KB chunks\n\tprivate filesMetaData: { name: string; type: string; size: number }[] = [];\n\tprivate filesArrayBuffer: ArrayBuffer[] = [];\n\tprivate currentFileIndex = 0;\n\tprivate currentChunkIndex = 0;\n\tprivate allFilesSent = false;\n\tprivate logger: Logger;\n\n\tconstructor({\n\t\tendpointId,\n\t\tfileInput,\n\t\tflottformApi,\n\t\tencryptionKey,\n\t\trtcConfiguration = DEFAULT_WEBRTC_CONFIG,\n\t\tpollTimeForIceInMs = POLL_TIME_IN_MS,\n\t\tlogger = console\n\t}: {\n\t\tendpointId: string;\n\t\tfileInput: HTMLInputElement;\n\t\tflottformApi: string;\n\t\tencryptionKey: string;\n\t\trtcConfiguration?: RTCConfiguration;\n\t\tpollTimeForIceInMs?: number;\n\t\tlogger?: Logger;\n\t}) {\n\t\tsuper();\n\t\tthis.channel = new FlottformChannelClient({\n\t\t\tendpointId,\n\t\t\tflottformApi,\n\t\t\trtcConfiguration,\n\t\t\tencryptionKey,\n\t\t\tpollTimeForIceInMs,\n\t\t\tlogger\n\t\t});\n\t\tthis.inputField = fileInput;\n\t\tthis.logger = logger;\n\t\tthis.registerListeners();\n\t}\n\tstart = () => {\n\t\tthis.channel?.start();\n\t};\n\n\tclose = () => {\n\t\tthis.channel?.close();\n\t};\n\n\tprivate createMetaData = (inputElement: HTMLInputElement): MetaData | null => {\n\t\tif (!inputElement.files) return null;\n\n\t\t// Generate all the metadata necessary to send all of the files\n\t\tconst files = Array.from(inputElement.files);\n\t\tconst filesQueue = files.map((file) => ({\n\t\t\tname: file.name,\n\t\t\ttype: file.type, // We're dividing each file into chuncks no matter what the type of the file.\n\t\t\tsize: file.size\n\t\t}));\n\t\treturn {\n\t\t\ttype: 'file-transfer-meta',\n\t\t\tfilesQueue,\n\t\t\ttotalSize: filesQueue.reduce((sum, file) => sum + file.size, 0)\n\t\t};\n\t};\n\n\tprivate createArrayBuffers = async (inputElement: HTMLInputElement) => {\n\t\tif (!inputElement.files) return null;\n\n\t\t// Generate all the arrayBuffers of the available files\n\t\tconst files = Array.from(inputElement.files);\n\t\treturn await Promise.all(files.map(async (file) => await file.arrayBuffer()));\n\t};\n\n\tsendFiles = async () => {\n\t\tconst metaData = this.createMetaData(this.inputField);\n\t\tconst filesArrayBuffer = await this.createArrayBuffers(this.inputField);\n\t\tif (!metaData || !filesArrayBuffer)\n\t\t\tthrow new Error(\"Can't find the files that you want to send!\");\n\n\t\tthis.filesMetaData = metaData.filesQueue;\n\t\tthis.filesArrayBuffer = filesArrayBuffer;\n\n\t\tthis.channel?.sendData(JSON.stringify(metaData));\n\n\t\tthis.emit('sending');\n\t\tthis.startSendingFiles();\n\t};\n\n\tprivate startSendingFiles = () => {\n\t\tthis.sendNextChunk();\n\t};\n\n\tprivate sendNextChunk = async () => {\n\t\tconst totalNumberOfFiles = this.filesMetaData.length;\n\t\tif (this.allFilesSent || this.currentFileIndex >= totalNumberOfFiles) {\n\t\t\t// All files are sent\n\t\t\tthis.logger.log('All files are sent');\n\t\t\tthis.channel?.sendData(JSON.stringify({ type: 'transfer-complete' }));\n\t\t\tthis.allFilesSent = true;\n\t\t\tthis.channel?.off('bufferedamountlow', this.startSendingFiles);\n\t\t\tthis.emit('done');\n\t\t\treturn;\n\t\t}\n\t\tconst currentFileArrayBuffer = this.filesArrayBuffer[this.currentFileIndex];\n\t\tif (!currentFileArrayBuffer) {\n\t\t\tthrow new Error(`Can't find the ArrayBuffer for the file number ${this.currentFileIndex}`);\n\t\t}\n\t\tconst currentFileSize = currentFileArrayBuffer.byteLength;\n\t\tconst fileName = this.filesMetaData[this.currentFileIndex]!.name;\n\n\t\twhile (this.currentChunkIndex * this.chunkSize < currentFileSize) {\n\t\t\t// The file still has some chunks left\n\t\t\tif (!this.channel?.canSendMoreData()) {\n\t\t\t\t// Buffer is full. Pause sending the chunks\n\t\t\t\tthis.logger.log('Buffer is full. Pausing sending chunks!');\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tconst progress = ((this.currentChunkIndex * this.chunkSize) / currentFileSize).toFixed(2);\n\n\t\t\tthis.emit('progress', {\n\t\t\t\tfileIndex: this.currentFileIndex,\n\t\t\t\tfileName,\n\t\t\t\tprogress: parseFloat(progress)\n\t\t\t});\n\n\t\t\tconst start = this.currentChunkIndex * this.chunkSize;\n\t\t\tconst end = Math.min((this.currentChunkIndex + 1) * this.chunkSize, currentFileSize);\n\t\t\tthis.channel?.sendData(currentFileArrayBuffer.slice(start, end));\n\t\t\tthis.currentChunkIndex++;\n\t\t}\n\t\t// Now either: the buffer is full OR all the chunks of the file have been sent.\n\t\tif (this.currentChunkIndex * this.chunkSize >= currentFileSize) {\n\t\t\t// File is fully sent move to the next one\n\t\t\tthis.logger.log(`File ${fileName} fully sent. Moving to next file.`);\n\t\t\tthis.currentFileIndex++;\n\t\t\tthis.currentChunkIndex = 0;\n\t\t\tthis.sendNextChunk(); // Recursion used to send the chunks of the next file\n\t\t} else {\n\t\t\t// Paused waiting for buffer space. Will try again shortly.\n\t\t\tsetTimeout(this.sendNextChunk, 100); // Retry after a short delay\n\t\t}\n\t};\n\n\tprivate registerListeners = () => {\n\t\tthis.channel?.on('init', () => {\n\t\t\t// TODO: Implement Default UI.\n\t\t});\n\t\tthis.channel?.on('retrieving-info-from-endpoint', () => {\n\t\t\t// TODO: Implement Default UI.\n\t\t});\n\t\tthis.channel?.on('sending-client-info', () => {\n\t\t\t// TODO: Implement Default UI.\n\t\t});\n\t\tthis.channel?.on('connecting-to-host', () => {\n\t\t\t// TODO: Implement Default UI.\n\t\t});\n\t\tthis.channel?.on('connected', () => {\n\t\t\tthis.emit('connected');\n\t\t\t// TODO: Implement Default UI.\n\t\t});\n\t\tthis.channel?.on('connection-impossible', () => {\n\t\t\tthis.emit('webrtc:connection-impossible');\n\t\t\t// TODO: Implement Default UI.\n\t\t});\n\t\tthis.channel?.on('done', () => {\n\t\t\tthis.emit('done');\n\t\t\t// TODO: Implement Default UI.\n\t\t});\n\t\tthis.channel?.on('disconnected', () => {\n\t\t\tthis.emit('disconnected');\n\t\t\t// TODO: Implement Default UI.\n\t\t});\n\t\tthis.channel?.on('error', (e) => {\n\t\t\tthis.emit('error', e);\n\t\t\t// TODO: Implement Default UI.\n\t\t});\n\t\tthis.channel?.on('bufferedamountlow', this.startSendingFiles);\n\t};\n}\n","import { FlottformChannelClient } from './flottform-channel-client';\nimport { DEFAULT_WEBRTC_CONFIG, EventEmitter, Logger, POLL_TIME_IN_MS } from './internal';\n\ntype Listeners = {\n\tconnected: [];\n\t'webrtc:connection-impossible': [];\n\tsending: []; // Emitted to signal the start of sending the file(s)\n\tdone: [];\n\tdisconnected: [];\n\terror: [e: string];\n};\n\nexport class FlottformTextInputClient extends EventEmitter {\n\tprivate channel: FlottformChannelClient | null = null;\n\tprivate logger: Logger;\n\n\tconstructor({\n\t\tendpointId,\n\t\tflottformApi,\n\t\tencryptionKey,\n\t\trtcConfiguration = DEFAULT_WEBRTC_CONFIG,\n\t\tpollTimeForIceInMs = POLL_TIME_IN_MS,\n\t\tlogger = console\n\t}: {\n\t\tendpointId: string;\n\t\tflottformApi: string;\n\t\trtcConfiguration?: RTCConfiguration;\n\t\tencryptionKey: string;\n\t\tpollTimeForIceInMs?: number;\n\t\tlogger?: Logger;\n\t}) {\n\t\tsuper();\n\t\tthis.channel = new FlottformChannelClient({\n\t\t\tendpointId,\n\t\t\tflottformApi,\n\t\t\trtcConfiguration,\n\t\t\tencryptionKey,\n\t\t\tpollTimeForIceInMs,\n\t\t\tlogger\n\t\t});\n\t\tthis.logger = logger;\n\t\tthis.registerListeners();\n\t}\n\tstart = () => {\n\t\tthis.channel?.start();\n\t};\n\n\tclose = () => {\n\t\t// Should be called once all the text has been sent.\n\t\tthis.channel?.close();\n\t};\n\n\tsendText = (text: string) => {\n\t\t// For now, I didn't handle very large texts since for most use cases the text won't exceed the size of 1 chunk ( 16KB )\n\t\tthis.emit('sending');\n\t\tthis.channel?.sendData(text);\n\t\tthis.emit('done');\n\t};\n\n\tprivate registerListeners = () => {\n\t\tthis.channel?.on('init', () => {});\n\t\tthis.channel?.on('retrieving-info-from-endpoint', () => {});\n\t\tthis.channel?.on('sending-client-info', () => {});\n\t\tthis.channel?.on('connecting-to-host', () => {});\n\t\tthis.channel?.on('connected', () => {\n\t\t\tthis.emit('connected');\n\t\t});\n\t\tthis.channel?.on('connection-impossible', () => {\n\t\t\tthis.emit('webrtc:connection-impossible');\n\t\t});\n\t\tthis.channel?.on('done', () => {\n\t\t\tthis.emit('done');\n\t\t});\n\t\tthis.channel?.on('disconnected', () => {\n\t\t\tthis.emit('disconnected');\n\t\t});\n\t\tthis.channel?.on('error', (e) => {\n\t\t\tthis.emit('error', e);\n\t\t});\n\t};\n}\n","import { FlottformChannelHost } from './flottform-channel-host';\nimport {\n\tBaseInputHost,\n\tBaseListeners,\n\tDEFAULT_WEBRTC_CONFIG,\n\tLogger,\n\tPOLL_TIME_IN_MS\n} from './internal';\n\ntype Listeners = BaseListeners & {\n\tdone: [data: string];\n\t'webrtc:waiting-for-text': [];\n\treceive: [];\n\t'webrtc:waiting-for-data': [];\n};\n\nexport class FlottformTextInputHost extends BaseInputHost {\n\tprivate channel: FlottformChannelHost | null = null;\n\tprivate logger: Logger;\n\tprivate link: string = '';\n\tprivate qrCode: string = '';\n\tprivate inputField: HTMLInputElement | HTMLTextAreaElement | undefined = undefined;\n\n\tconstructor({\n\t\tflottformApi,\n\t\tcreateClientUrl,\n\t\tinputField = undefined,\n\t\trtcConfiguration = DEFAULT_WEBRTC_CONFIG,\n\t\tpollTimeForIceInMs = POLL_TIME_IN_MS,\n\t\tlogger = console\n\t}: {\n\t\tflottformApi: string | URL;\n\t\tcreateClientUrl: (params: {\n\t\t\tendpointId: string;\n\t\t\tencryptionKey: string;\n\t\t\toptionalData?: object;\n\t\t}) => Promise;\n\t\tinputField?: HTMLInputElement | HTMLTextAreaElement;\n\t\trtcConfiguration?: RTCConfiguration;\n\t\tpollTimeForIceInMs?: number;\n\t\tlogger?: Logger;\n\t}) {\n\t\tsuper();\n\t\tthis.channel = new FlottformChannelHost({\n\t\t\tflottformApi,\n\t\t\tcreateClientUrl,\n\t\t\trtcConfiguration,\n\t\t\tpollTimeForIceInMs,\n\t\t\tlogger\n\t\t});\n\t\tthis.logger = logger;\n\t\tthis.inputField = inputField;\n\n\t\tthis.registerListeners();\n\t}\n\n\tstart = () => {\n\t\tthis.channel?.start();\n\t};\n\n\tclose = () => {\n\t\tthis.channel?.close();\n\t};\n\n\tgetLink = () => {\n\t\tif (this.link === '') {\n\t\t\tthis.logger.error(\n\t\t\t\t'Flottform is currently establishing the connection. Link is unavailable for now!'\n\t\t\t);\n\t\t}\n\t\treturn this.link;\n\t};\n\n\tgetQrCode = () => {\n\t\tif (this.qrCode === '') {\n\t\t\tthis.logger.error(\n\t\t\t\t'Flottform is currently establishing the connection. qrCode is unavailable for now!'\n\t\t\t);\n\t\t}\n\t\treturn this.qrCode;\n\t};\n\n\tprivate handleIncomingData = (e: MessageEvent) => {\n\t\tthis.emit('receive');\n\t\t// We suppose that the data received is small enough to be all included in 1 message\n\t\tthis.emit('done', e.data);\n\t\tif (this.inputField) {\n\t\t\tthis.inputField.value = e.data;\n\t\t\tconst event = new Event('change');\n\t\t\tthis.inputField.dispatchEvent(event);\n\t\t}\n\t};\n\n\tprivate registerListeners = () => {\n\t\tthis.channel?.on('new', () => {\n\t\t\tthis.emit('new');\n\t\t});\n\t\tthis.channel?.on('waiting-for-client', (event) => {\n\t\t\tthis.emit('webrtc:waiting-for-client', event);\n\t\t\tconst { qrCode, link } = event;\n\t\t\tthis.emit('endpoint-created', { link, qrCode });\n\t\t\tthis.link = link;\n\t\t\tthis.qrCode = qrCode;\n\t\t});\n\t\tthis.channel?.on('waiting-for-ice', () => {\n\t\t\tthis.emit('webrtc:waiting-for-ice');\n\t\t});\n\t\tthis.channel?.on('waiting-for-data', () => {\n\t\t\tthis.emit('webrtc:waiting-for-data');\n\t\t\tthis.emit('connected');\n\t\t});\n\t\tthis.channel?.on('receiving-data', (e) => {\n\t\t\tthis.handleIncomingData(e);\n\t\t});\n\t\tthis.channel?.on('disconnected', () => {\n\t\t\tthis.emit('disconnected');\n\t\t});\n\t\tthis.channel?.on('error', (error) => {\n\t\t\tthis.emit('error', error);\n\t\t});\n\t};\n}\n","import { FlottformFileInputHost } from './flottform-file-input-host';\nimport { FlottformTextInputHost } from './flottform-text-input-host';\nimport { BaseInputHost, BaseListeners } from './internal';\nimport { FlottformCreateFileParams, FlottformCreateTextParams } from './types';\n\nconst openInputsList = () => {\n\tconst flottformElementsContainerWrapper: HTMLDivElement = document.querySelector(\n\t\t'.flottform-elements-container-wrapper'\n\t)!;\n\tconst openerSvg: SVGElement = document.querySelector('.flottform-opener-triangle')!;\n\tflottformElementsContainerWrapper.classList.toggle('flottform-open');\n\topenerSvg.classList.toggle('flottform-button-svg-open');\n};\n\nconst initRoot = (\n\tflottformRootTitle?: string,\n\tflottformRootDescription?: string,\n\tadditionalComponentClass?: string\n) => {\n\tconst flottformRoot = document.createElement('div');\n\tflottformRoot.setAttribute('class', `flottform-root${additionalComponentClass ?? ''}`);\n\tconst flottformListOpenerButton = createFlottformOpenerButton(flottformRootTitle);\n\tflottformRoot.appendChild(flottformListOpenerButton);\n\tconst flottformElementsContainerWrapper =\n\t\tcreateFlottformItemsContainerWithTransition(flottformRootDescription);\n\tflottformRoot.appendChild(flottformElementsContainerWrapper);\n\treturn flottformRoot;\n};\n\nconst createLinkAndQrCode = (qrCode: string, link: string) => {\n\tconst createChannelQrCode = document.createElement('img');\n\tcreateChannelQrCode.setAttribute('class', 'flottform-qr-code');\n\tcreateChannelQrCode.setAttribute('src', qrCode);\n\n\tconst createChannelLinkWithOffer = document.createElement('div');\n\tcreateChannelLinkWithOffer.setAttribute('class', 'flottform-link-offer');\n\tcreateChannelLinkWithOffer.innerText = link;\n\treturn {\n\t\tcreateChannelQrCode,\n\t\tcreateChannelLinkWithOffer\n\t};\n};\nexport const createDefaultFlottformComponent = ({\n\tflottformAnchorElement,\n\tflottformRootElement,\n\tadditionalComponentClass,\n\tflottformRootTitle,\n\tflottformRootDescription\n}: {\n\tflottformAnchorElement: HTMLElement;\n\tflottformRootElement?: HTMLElement;\n\tadditionalComponentClass?: string;\n\tflottformRootTitle?: string;\n\tflottformRootDescription?: string;\n}): {\n\tflottformRoot: HTMLElement;\n\tcreateFileItem: (params: FlottformCreateFileParams) => void;\n\tcreateTextItem: (params: FlottformCreateTextParams) => void;\n\tgetAllFlottformItems: () => NodeListOf | null;\n} => {\n\tconst flottformRoot: HTMLElement =\n\t\tflottformRootElement ??\n\t\tdocument.querySelector('.flottform-root') ??\n\t\tinitRoot(flottformRootTitle, flottformRootDescription, additionalComponentClass);\n\tconst flottformElementsContainer = flottformRoot.querySelector('.flottform-elements-container')!;\n\tconst flottformElementsContainerWrapper = flottformRoot.querySelector(\n\t\t'.flottform-elements-container-wrapper'\n\t)!;\n\tflottformElementsContainerWrapper.appendChild(flottformElementsContainer);\n\tflottformRoot.appendChild(flottformElementsContainerWrapper);\n\n\tflottformAnchorElement.appendChild(flottformRoot);\n\treturn {\n\t\tflottformRoot,\n\t\tgetAllFlottformItems: () => {\n\t\t\tconst flottformInputsList = flottformRoot.querySelector('.flottform-inputs-list');\n\t\t\tif (!flottformInputsList) {\n\t\t\t\tconsole.error('No element with class .flottform-inputs-list found');\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn flottformInputsList.childNodes as NodeListOf;\n\t\t},\n\t\tcreateFileItem: ({\n\t\t\tflottformApi,\n\t\t\tcreateClientUrl,\n\t\t\tinputField,\n\t\t\tid,\n\t\t\tadditionalItemClasses,\n\t\t\tlabel,\n\t\t\tbuttonLabel,\n\t\t\tonErrorText,\n\t\t\tonSuccessText\n\t\t}: {\n\t\t\tflottformApi: string;\n\t\t\tcreateClientUrl: (params: {\n\t\t\t\tendpointId: string;\n\t\t\t\tencryptionKey: string;\n\t\t\t\toptionalData?: object;\n\t\t\t}) => Promise;\n\t\t\tinputField: HTMLInputElement;\n\t\t\tid?: string;\n\t\t\tadditionalItemClasses?: string;\n\t\t\tlabel?: string;\n\t\t\tbuttonLabel?: string;\n\t\t\tonErrorText?: string | ((error: Error) => string);\n\t\t\tonSuccessText?: string;\n\t\t}) => {\n\t\t\tconst flottformBaseInputHost = new FlottformFileInputHost({\n\t\t\t\tflottformApi,\n\t\t\t\tcreateClientUrl,\n\t\t\t\tinputField\n\t\t\t});\n\n\t\t\tconst {\n\t\t\t\tflottformItem,\n\t\t\t\tstatusInformation,\n\t\t\t\trefreshChannelButton,\n\t\t\t\tflottformStateItemsContainer\n\t\t\t} = createBaseFlottformItems({\n\t\t\t\tflottformBaseInputHost,\n\t\t\t\tadditionalItemClasses,\n\t\t\t\tlabel,\n\t\t\t\tbuttonLabel,\n\t\t\t\tonErrorText\n\t\t\t});\n\n\t\t\tconst flottformItemsList = flottformRoot.querySelector('.flottform-inputs-list')!;\n\n\t\t\tflottformItemsList.appendChild(flottformItem);\n\t\t\tflottformElementsContainer.appendChild(flottformItemsList);\n\n\t\t\thandleFileInputStates({\n\t\t\t\tflottformItem,\n\t\t\t\tstatusInformation,\n\t\t\t\trefreshChannelButton,\n\t\t\t\tflottformStateItemsContainer,\n\t\t\t\tflottformFileInputHost: flottformBaseInputHost,\n\t\t\t\tid,\n\t\t\t\tonSuccessText\n\t\t\t});\n\t\t},\n\t\tcreateTextItem: ({\n\t\t\tflottformApi,\n\t\t\tcreateClientUrl,\n\t\t\tinputField,\n\t\t\tid,\n\t\t\tadditionalItemClasses,\n\t\t\tlabel,\n\t\t\tbuttonLabel,\n\t\t\tonErrorText,\n\t\t\tonSuccessText\n\t\t}: {\n\t\t\tflottformApi: string;\n\t\t\tcreateClientUrl: (params: {\n\t\t\t\tendpointId: string;\n\t\t\t\tencryptionKey: string;\n\t\t\t\toptionalData?: object;\n\t\t\t}) => Promise;\n\t\t\tinputField?: HTMLInputElement | HTMLTextAreaElement;\n\t\t\tid?: string;\n\t\t\tadditionalItemClasses?: string;\n\t\t\tlabel?: string;\n\t\t\tbuttonLabel?: string;\n\t\t\tonErrorText?: string | ((error: Error) => string);\n\t\t\tonSuccessText?: string;\n\t\t}) => {\n\t\t\tconst flottformBaseInputHost = new FlottformTextInputHost({\n\t\t\t\tflottformApi,\n\t\t\t\tcreateClientUrl,\n\t\t\t\tinputField\n\t\t\t});\n\n\t\t\tconst { flottformItem, statusInformation, refreshChannelButton } = createBaseFlottformItems({\n\t\t\t\tflottformBaseInputHost,\n\t\t\t\tadditionalItemClasses,\n\t\t\t\tlabel,\n\t\t\t\tbuttonLabel,\n\t\t\t\tonErrorText\n\t\t\t});\n\t\t\tconst flottformItemsList = flottformRoot.querySelector('.flottform-inputs-list')!;\n\n\t\t\tflottformItemsList.appendChild(flottformItem);\n\t\t\tflottformElementsContainer.appendChild(flottformItemsList);\n\n\t\t\thandleTextInputStates({\n\t\t\t\tflottformItem,\n\t\t\t\tstatusInformation,\n\t\t\t\trefreshChannelButton,\n\t\t\t\tflottformTextInputHost: flottformBaseInputHost,\n\t\t\t\tid,\n\t\t\t\tonSuccessText\n\t\t\t});\n\t\t}\n\t};\n};\n\nconst createBaseFlottformItems = ({\n\tflottformBaseInputHost,\n\tadditionalItemClasses,\n\tlabel,\n\tbuttonLabel,\n\tonErrorText\n}: {\n\tflottformBaseInputHost: BaseInputHost;\n\n\tadditionalItemClasses?: string;\n\tlabel?: string;\n\tbuttonLabel?: string;\n\tonErrorText?: string | ((error: Error) => string);\n}) => {\n\tconst flottformItem = createFlottformListItem(additionalItemClasses);\n\tsetLabelForFlottformItem({ label, flottformItem });\n\tconst statusInformation = createStatusInformation();\n\tconst createChannelButton = createFlottformChannelButton(buttonLabel);\n\tcreateChannelButton.addEventListener('click', () => flottformBaseInputHost.start());\n\tconst flottformStateItemsContainer = createStateItemsContainer(createChannelButton);\n\tflottformItem.appendChild(flottformStateItemsContainer);\n\tconst refreshChannelButton = createFlottformChannelRefreshButton();\n\trefreshChannelButton.addEventListener('click', () => flottformBaseInputHost.start());\n\n\t// listen to events -> change elements depending on them\n\tflottformBaseInputHost.on('endpoint-created', ({ link, qrCode }) => {\n\t\tconst { createChannelQrCode, createChannelLinkWithOffer } = createLinkAndQrCode(qrCode, link);\n\t\tconst copyToClipboardButton = createCopyToClipboardButton();\n\t\tflottformStateItemsContainer.replaceChildren(createChannelQrCode);\n\t\tconst linkAndCopyButtonWrapper = document.createElement('div');\n\t\tlinkAndCopyButtonWrapper.setAttribute('class', 'flottform-copy-button-link-wrapper');\n\t\tlinkAndCopyButtonWrapper.appendChild(copyToClipboardButton);\n\t\tlinkAndCopyButtonWrapper.appendChild(createChannelLinkWithOffer);\n\t\tflottformStateItemsContainer.appendChild(linkAndCopyButtonWrapper);\n\t});\n\tflottformBaseInputHost.on('connected', () => {\n\t\tstatusInformation.innerHTML = 'Connected';\n\t\tstatusInformation.appendChild(refreshChannelButton);\n\t\tflottformStateItemsContainer.replaceChildren(statusInformation);\n\t});\n\tflottformBaseInputHost.on('error', (error) => {\n\t\tstatusInformation.innerHTML =\n\t\t\ttypeof onErrorText === 'function'\n\t\t\t\t? onErrorText(error)\n\t\t\t\t: (onErrorText ?? `🚨 An error occured (${error.message}). Please try again`);\n\t\tcreateChannelButton.innerText = 'Retry';\n\t\tflottformStateItemsContainer.replaceChildren(statusInformation);\n\t\tflottformStateItemsContainer.appendChild(createChannelButton);\n\t});\n\treturn { flottformItem, statusInformation, refreshChannelButton, flottformStateItemsContainer };\n};\n\nconst handleFileInputStates = ({\n\tflottformItem,\n\tstatusInformation,\n\trefreshChannelButton,\n\tflottformStateItemsContainer,\n\tflottformFileInputHost,\n\tid,\n\tonSuccessText\n}: {\n\tflottformItem: HTMLLIElement;\n\tstatusInformation: HTMLDivElement;\n\trefreshChannelButton: HTMLButtonElement;\n\tflottformStateItemsContainer: HTMLDivElement;\n\tflottformFileInputHost: FlottformFileInputHost;\n\tid?: string;\n\tonSuccessText?: string;\n}) => {\n\tif (id) {\n\t\tflottformItem.setAttribute('id', id);\n\t}\n\n\tflottformFileInputHost.on(\n\t\t'progress',\n\t\t({ currentFileProgress, overallProgress, fileIndex, totalFileCount, fileName }) => {\n\t\t\tremoveConnectionStatusInformation(flottformStateItemsContainer);\n\t\t\tupdateOverallFilesStatusBar(\n\t\t\t\tflottformStateItemsContainer,\n\t\t\t\toverallProgress,\n\t\t\t\tfileIndex,\n\t\t\t\ttotalFileCount\n\t\t\t);\n\t\t\tconst details = getDetailsOfFilesTransfer(flottformStateItemsContainer);\n\t\t\tupdateCurrentFileStatusBar(\n\t\t\t\tfileIndex,\n\t\t\t\tfileName,\n\t\t\t\tcurrentFileProgress,\n\t\t\t\tdetails,\n\t\t\t\tflottformStateItemsContainer\n\t\t\t);\n\t\t}\n\t);\n\tflottformFileInputHost.on('done', () => {\n\t\tstatusInformation.innerHTML =\n\t\t\tonSuccessText ?? `✨ You have succesfully downloaded all your files.`;\n\t\tstatusInformation.appendChild(refreshChannelButton);\n\t\tflottformStateItemsContainer.replaceChildren(statusInformation);\n\t});\n};\n\nconst handleTextInputStates = ({\n\tflottformItem,\n\tstatusInformation,\n\trefreshChannelButton,\n\tflottformTextInputHost,\n\tid,\n\tonSuccessText\n}: {\n\tflottformItem: HTMLLIElement;\n\tstatusInformation: HTMLDivElement;\n\trefreshChannelButton: HTMLButtonElement;\n\tflottformTextInputHost: FlottformTextInputHost;\n\tid?: string;\n\tonSuccessText?: string;\n}) => {\n\tif (id) {\n\t\tflottformItem.setAttribute('id', id);\n\t}\n\tflottformTextInputHost.on('done', (message: string) => {\n\t\tstatusInformation.innerHTML = onSuccessText ?? `✨ You have succesfully submitted your message`;\n\t\tstatusInformation.appendChild(refreshChannelButton);\n\t\tflottformItem.replaceChildren(statusInformation);\n\t\tif (inputField) {\n\t\t\tinputField.setAttribute('value', message);\n\t\t\tconst event = new Event('change');\n\t\t\tinputField.dispatchEvent(event);\n\t\t}\n\t});\n};\n\nconst createFlottformOpenerButton = (flottformRootTitle: string | undefined) => {\n\tconst flottformListOpenerButton = document.createElement('button');\n\tflottformListOpenerButton.setAttribute('type', 'button');\n\tflottformListOpenerButton.setAttribute('class', 'flottform-root-opener-button');\n\tflottformListOpenerButton.innerHTML = `${flottformRootTitle ?? 'Fill from Another Device'}`;\n\tflottformListOpenerButton.addEventListener('click', () => openInputsList());\n\treturn flottformListOpenerButton;\n};\n\nconst createFlottformItemsContainerWithTransition = (\n\tflottformRootDescription: string | undefined\n) => {\n\tconst flottformElementsContainer = document.createElement('div');\n\tflottformElementsContainer.setAttribute('class', 'flottform-elements-container');\n\tconst flottformElementsContainerWrapper = document.createElement('div');\n\tflottformElementsContainerWrapper.setAttribute('class', 'flottform-elements-container-wrapper');\n\tif (flottformRootDescription !== '') {\n\t\tconst flottformDescription = document.createElement('div');\n\t\tflottformDescription.setAttribute('class', 'flottform-root-description');\n\t\tflottformDescription.innerText =\n\t\t\tflottformRootDescription ??\n\t\t\t'This form is powered by Flottform. Need to add details from another device? Simply click a button below to generate a QR code or link, and easily upload information from your other device.';\n\t\tflottformElementsContainer.appendChild(flottformDescription);\n\t}\n\tconst flottformItemsList = document.createElement('ul');\n\tflottformItemsList.setAttribute('class', 'flottform-inputs-list');\n\tflottformElementsContainer.appendChild(flottformItemsList);\n\tflottformElementsContainerWrapper.appendChild(flottformElementsContainer);\n\treturn flottformElementsContainerWrapper;\n};\n\nconst createFlottformListItem = (additionalItemClasses?: string) => {\n\tconst flottformItem = document.createElement('li');\n\tflottformItem.setAttribute('class', `flottform-item${additionalItemClasses ?? ''}`);\n\treturn flottformItem;\n};\n\nconst createStatusInformation = () => {\n\tconst statusInformation = document.createElement('div');\n\tstatusInformation.setAttribute('class', 'flottform-status-information');\n\treturn statusInformation;\n};\n\nconst createStateItemsContainer = (createChannelButton: HTMLButtonElement) => {\n\tconst flottformStateItemsContainer = document.createElement('div');\n\tflottformStateItemsContainer.setAttribute('class', 'flottform-state-items-container');\n\tflottformStateItemsContainer.appendChild(createChannelButton);\n\treturn flottformStateItemsContainer;\n};\n\nconst createFlottformChannelButton = (label: string | undefined) => {\n\tconst createChannelButton = document.createElement('button');\n\tcreateChannelButton.setAttribute('type', 'button');\n\tcreateChannelButton.setAttribute('class', 'flottform-button');\n\tcreateChannelButton.innerText = label ?? 'Get a link';\n\treturn createChannelButton;\n};\n\nconst createFlottformChannelRefreshButton = () => {\n\tconst refreshChannelButton = document.createElement('button');\n\trefreshChannelButton.setAttribute('type', 'button');\n\trefreshChannelButton.setAttribute('class', 'flottform-refresh-connection-button');\n\trefreshChannelButton.setAttribute(\n\t\t'title',\n\t\t'Click this button to refresh Flottform connection for the input field. Previous connection will be closed'\n\t);\n\trefreshChannelButton.setAttribute(\n\t\t'aria-label',\n\t\t'Click this button to refresh Flottform connection for the input field. Previous connection will be closed'\n\t);\n\trefreshChannelButton.innerHTML = ``;\n\treturn refreshChannelButton;\n};\n\n// Set an index for inputs for an edge cases when user hasn't provided a label and input has no id or name\nlet inputIndex = 1;\n\nconst setLabelForFlottformItem = ({\n\tlabel,\n\tflottformItem\n}: {\n\tlabel: string | undefined;\n\tflottformItem: HTMLLIElement;\n}) => {\n\tconst inputLabel = document.createElement('p');\n\tconst labelContent = label ?? `File input ${inputIndex++}`;\n\tif (labelContent) {\n\t\tinputLabel.innerHTML = labelContent;\n\t\tflottformItem.appendChild(inputLabel);\n\t}\n};\n\nconst createCopyToClipboardButton = () => {\n\tconst copyToClipboardButton = document.createElement('button');\n\tcopyToClipboardButton.setAttribute('class', 'flottform-copy-to-clipboard');\n\tcopyToClipboardButton.setAttribute('type', 'button');\n\tcopyToClipboardButton.setAttribute('title', 'Copy Flottform link to clipboard');\n\tcopyToClipboardButton.setAttribute('aria-label', 'Copy Flottform link to clipboard');\n\tcopyToClipboardButton.innerText = '📋';\n\tcopyToClipboardButton.addEventListener('click', async () => {\n\t\tconst flottformLink = (document.querySelector('.flottform-link-offer') as HTMLDivElement)\n\t\t\t.innerText;\n\t\tnavigator.clipboard\n\t\t\t.writeText(flottformLink)\n\t\t\t.then(() => {\n\t\t\t\tcopyToClipboardButton.innerText = '✅';\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tcopyToClipboardButton.innerText = '📋';\n\t\t\t\t}, 1000);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tcopyToClipboardButton.innerText = `❌ Failed to copy: ${error}`;\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tcopyToClipboardButton.innerText = '📋';\n\t\t\t\t}, 1000);\n\t\t\t});\n\t});\n\treturn copyToClipboardButton;\n};\n\nconst removeConnectionStatusInformation = (flottformStateItemsContainer: HTMLDivElement) => {\n\tconst connectionStatusInformation = flottformStateItemsContainer.querySelector(\n\t\t'.flottform-status-information'\n\t);\n\tif (connectionStatusInformation) {\n\t\t// Remove the connection status information\n\t\tflottformStateItemsContainer.innerHTML = '';\n\t}\n};\n\nconst getDetailsOfFilesTransfer = (flottformStateItemsContainer: HTMLDivElement) => {\n\tlet details = flottformStateItemsContainer.querySelector('details');\n\tif (!details) {\n\t\tdetails = document.createElement('details');\n\t\tconst summary = document.createElement('summary');\n\t\tsummary.innerText = 'Details';\n\t\tdetails.appendChild(summary);\n\t\tconst detailsContainer = document.createElement('div');\n\t\tdetailsContainer.classList.add('details-container');\n\t\tdetails.appendChild(detailsContainer);\n\t\tflottformStateItemsContainer.appendChild(details);\n\t}\n\treturn details;\n};\n\nconst createCurrentFileStatusBar = (fileIndex: number, fileName: string) => {\n\tconst currentFileLabel = document.createElement('label');\n\tcurrentFileLabel.setAttribute('id', `flottform-status-bar-${fileIndex}`);\n\tcurrentFileLabel.classList.add('flottform-progress-bar-label');\n\tcurrentFileLabel.innerText = `File ${fileName} progress:`;\n\n\tconst progressBar = document.createElement('progress');\n\tprogressBar.setAttribute('id', `flottform-status-bar-${fileIndex}`);\n\tprogressBar.classList.add('flottform-status-bar');\n\tprogressBar.setAttribute('max', '100');\n\tprogressBar.setAttribute('value', '0');\n\n\treturn { currentFileLabel, progressBar };\n};\n\nconst updateCurrentFileStatusBar = (\n\tfileIndex: number,\n\tfileName: string,\n\tcurrentFileProgress: number,\n\tdetails: HTMLDetailsElement,\n\tflottformStateItemsContainer: HTMLDivElement\n) => {\n\tlet currentFileStatusBar: HTMLProgressElement | null = flottformStateItemsContainer.querySelector(\n\t\t`progress#flottform-status-bar-${fileIndex}`\n\t);\n\tif (!currentFileStatusBar) {\n\t\tconst { currentFileLabel, progressBar } = createCurrentFileStatusBar(fileIndex, fileName);\n\t\tcurrentFileStatusBar = progressBar;\n\n\t\tconst detailsContainer = details.querySelector('.details-container')!;\n\n\t\tdetailsContainer.appendChild(currentFileLabel);\n\t\tdetailsContainer.appendChild(currentFileStatusBar);\n\t}\n\tcurrentFileStatusBar.value = currentFileProgress * 100;\n\tcurrentFileStatusBar.innerText = `${currentFileProgress * 100}%`;\n};\n\nconst createOverallFilesStatusBar = () => {\n\tconst overallFilesLabel = document.createElement('label');\n\toverallFilesLabel.setAttribute('id', 'flottform-status-bar-overall-progress');\n\toverallFilesLabel.classList.add('flottform-progress-bar-label');\n\toverallFilesLabel.innerText = 'Receiving Files Progress';\n\n\tconst progressBar = document.createElement('progress');\n\tprogressBar.setAttribute('id', 'flottform-status-bar-overall-progress');\n\tprogressBar.classList.add('flottform-status-bar');\n\tprogressBar.setAttribute('max', '100');\n\tprogressBar.setAttribute('value', '0');\n\n\treturn { overallFilesLabel, progressBar };\n};\n\nconst updateOverallFilesStatusBar = (\n\tflottformStateItemsContainer: HTMLDivElement,\n\toverallProgress: number,\n\tfileIndex: number,\n\ttotalFileCount: number\n) => {\n\tlet overallFilesStatusBar: HTMLProgressElement | null =\n\t\tflottformStateItemsContainer.querySelector('progress#flottform-status-bar-overall-progress');\n\tif (!overallFilesStatusBar) {\n\t\tconst { overallFilesLabel, progressBar } = createOverallFilesStatusBar();\n\t\toverallFilesStatusBar = progressBar;\n\n\t\tflottformStateItemsContainer.appendChild(overallFilesLabel);\n\t\tflottformStateItemsContainer.appendChild(overallFilesStatusBar);\n\t}\n\tconst overallFilesLabel: HTMLLabelElement = flottformStateItemsContainer.querySelector(\n\t\t'label#flottform-status-bar-overall-progress'\n\t)!;\n\toverallFilesStatusBar.value = overallProgress * 100;\n\toverallFilesStatusBar.innerText = `${overallProgress * 100}%`;\n\toverallFilesLabel.innerText = `Receiving file ${fileIndex + 1} of ${totalFileCount}`;\n};\n"],"names":["_ConnectionManager","__publicField","key","connection","ConnectionManager","canPromise","toSJISFunction","CODEWORDS_COUNT","utils","version","data","digit","f","kanji","exports","fromString","string","level","value","defaultValue","BitBuffer","index","bufIndex","num","length","i","bit","bitBuffer","BitMatrix","size","row","col","reserved","bitMatrix","getSymbolSize","require$$0","posCount","intervals","positions","coords","pos","posLength","j","FINDER_PATTERN_SIZE","finderPattern","PenaltyScores","mask","points","sameCountCol","sameCountRow","lastCol","lastRow","module","last","bitsCol","bitsRow","darkCount","modulesCount","getMaskAt","maskPattern","pattern","setupFormatFunc","numPatterns","bestPattern","lowerPenalty","p","penalty","ECLevel","EC_BLOCKS_TABLE","EC_CODEWORDS_TABLE","errorCorrectionCode","errorCorrectionLevel","EXP_TABLE","LOG_TABLE","x","galoisField","n","y","GF","p1","p2","coeff","divident","divisor","result","offset","degree","poly","Polynomial","ReedSolomonEncoder","paddedData","remainder","start","buff","reedSolomonEncoder","versionCheck","numeric","alphanumeric","byte","regex","TEST_KANJI","TEST_NUMERIC","TEST_ALPHANUMERIC","str","VersionCheck","Regex","require$$1","mode","dataStr","Utils","ECCode","require$$2","Mode","require$$3","require$$4","G18","G18_BCH","getBestVersionForDataLength","currentVersion","getReservedBitsCount","getTotalBitsFromDataArray","segments","totalBits","reservedBits","getBestVersionForMixedData","totalCodewords","ecTotalCodewords","dataTotalCodewordsBits","usableBits","seg","ecl","d","G15","G15_MASK","G15_BCH","formatInfo","NumericData","group","remainingNum","numericData","ALPHA_NUM_CHARS","AlphanumericData","alphanumericData","ByteData","l","byteData","KanjiData","kanjiData","dijkstra","graph","s","predecessors","costs","open","closest","u","v","cost_of_s_to_u","adjacent_nodes","cost_of_e","cost_of_s_to_u_plus_cost_of_e","cost_of_s_to_v","first_visit","msg","nodes","opts","T","t","a","b","cost","item","require$$5","require$$6","require$$7","getStringByteLength","getSegments","getSegmentsFromString","numSegs","alphaNumSegs","byteSegs","kanjiSegs","s1","s2","obj","getSegmentBitsLength","mergeSegments","segs","acc","curr","prevSeg","buildNodes","buildGraph","table","prevNodeIds","nodeGroup","currentNodeIds","node","prevNodeId","buildSingleSegment","modesHint","bestMode","array","path","optimizedSegs","AlignmentPattern","FinderPattern","MaskPattern","require$$8","Version","require$$9","FormatInfo","require$$10","require$$11","Segments","require$$12","setupFinderPattern","matrix","r","c","setupTimingPattern","setupAlignmentPattern","setupVersionInfo","bits","mod","setupFormatInfo","setupData","inc","bitIndex","byteIndex","dark","createData","buffer","remainingByte","createCodewords","dataTotalCodewords","ecTotalBlocks","blocksInGroup2","blocksInGroup1","totalCodewordsInGroup1","dataCodewordsInGroup1","dataCodewordsInGroup2","ecCount","rs","dcData","ecData","maxDataSize","dataSize","createSymbol","estimatedVersion","rawSegments","bestVersion","dataBits","moduleCount","modules","qrcode","options","hex2rgba","hex","hexCode","hexValue","margin","width","scale","qrSize","imgData","qr","symbolSize","scaledMargin","palette","posDst","pxColor","iSrc","jSrc","clearCanvas","ctx","canvas","getCanvasElement","qrData","canvasEl","image","type","rendererOpts","getColorAttrib","color","attrib","alpha","svgCmd","cmd","qrToPath","moveBy","newRow","lineLength","svgTag","cb","qrcodesize","bg","viewBox","QRCode","CanvasRenderer","SvgRenderer","renderCanvas","renderFunc","text","args","argsNum","isLastArgCb","resolve","reject","e","browser","_","POLL_TIME_IN_MS","DEFAULT_WEBRTC_CONFIG","generateSecretKey","retrieveEndpointInfo","getEndpointInfoUrl","setIncludes","set","EventEmitter","eventName","listener","listeners","BaseInputHost","generateKey","cryptoKeyToEncryptionKey","encryptionKeyToCryptoKey","encryptionKey","jwk","encrypt","plaintext","cryptoKey","plaintextToTypedArray","iv","getInitializationVector","encryptedData","combinedData","typedArrayToBase64","decrypt","ciphertext","base64ToTypedArray","decryptedData","typedArrayToPlaintext","plainText","typedArray","messageAsBase64","binaryString","char","isOriginalDataJson","FlottformChannelHost","flottformApi","createClientUrl","rtcConfiguration","pollTimeForIceInMs","logger","newState","details","baseApi","session","endpointId","hostKey","putHostInfoUrl","hostIceCandidates","connectLink","toDataURL","encryptedSession","response","clientInfo","decryptedSession","decryptedIceCandidates","iceCandidate","channelName","encryptedIceCandidates","err","FlottformFileInputHost","inputField","_a","_b","_c","message","currentFileName","currentFileTotalSize","currentFileProgress","overallProgress","fileIndex","fileName","fileType","receivedFile","dt","file","_d","_e","_f","_g","event","qrCode","link","error","FlottformChannelClient","clientKey","clientIceCandidates","putClientInfoUrl","hostInfo","hostSession","FlottformFileInputClient","fileInput","inputElement","filesQueue","sum","files","metaData","filesArrayBuffer","totalNumberOfFiles","currentFileArrayBuffer","currentFileSize","progress","end","_h","_i","_j","FlottformTextInputClient","FlottformTextInputHost","openInputsList","flottformElementsContainerWrapper","openerSvg","initRoot","flottformRootTitle","flottformRootDescription","additionalComponentClass","flottformRoot","flottformListOpenerButton","createFlottformOpenerButton","createFlottformItemsContainerWithTransition","createLinkAndQrCode","createChannelQrCode","createChannelLinkWithOffer","createDefaultFlottformComponent","flottformAnchorElement","flottformRootElement","flottformElementsContainer","flottformInputsList","id","additionalItemClasses","label","buttonLabel","onErrorText","onSuccessText","flottformBaseInputHost","flottformItem","statusInformation","refreshChannelButton","flottformStateItemsContainer","createBaseFlottformItems","flottformItemsList","handleFileInputStates","handleTextInputStates","createFlottformListItem","setLabelForFlottformItem","createStatusInformation","createChannelButton","createFlottformChannelButton","createStateItemsContainer","createFlottformChannelRefreshButton","copyToClipboardButton","createCopyToClipboardButton","linkAndCopyButtonWrapper","flottformFileInputHost","totalFileCount","removeConnectionStatusInformation","updateOverallFilesStatusBar","getDetailsOfFilesTransfer","updateCurrentFileStatusBar","flottformTextInputHost","flottformDescription","inputIndex","inputLabel","labelContent","flottformLink","summary","detailsContainer","createCurrentFileStatusBar","currentFileLabel","progressBar","currentFileStatusBar","createOverallFilesStatusBar","overallFilesLabel","overallFilesStatusBar"],"mappings":";;;AAGO,MAAMA,IAAN,MAAMA,EAAkB;AAAA,EAItB,cAAc;AAFd,IAAAC,EAAA;AAGF,SAAA,wCAAwB,IAA6D;AAAA,EAAA;AAAA,EAG3F,OAAc,cAAiC;AAC1C,WAACD,EAAkB,aACJA,EAAA,WAAW,IAAIA,EAAkB,IAE7CA,EAAkB;AAAA,EAAA;AAAA,EAGnB,cAAcE,GAAaC,GAA6D;AACzF,SAAA,kBAAkB,IAAID,GAAKC,CAAU;AAAA,EAAA;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A,YAAY,GAAGvG,IAAkB,GAAG,KAC1DsG,EAAkB,YAAY,kBAAkBrG,IAAY,CAAC,OAAOmF,CAAc;AACnF;","x_google_ignoreList":[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]} \ No newline at end of file diff --git a/servers/demo/src/api.ts b/servers/demo/src/api.ts index 526a36b..7795e8c 100644 --- a/servers/demo/src/api.ts +++ b/servers/demo/src/api.ts @@ -3,21 +3,67 @@ import { env } from '$env/dynamic/public'; export const sdpExchangeServerBase = env.PUBLIC_FLOTTFORM_SERVER_BASE; -export const createClientUrl = async ({ endpointId }: { endpointId: string }) => { - return `${window.location.origin}${base}/flottform-client/${endpointId}`; +export const createClientUrl = async ({ + endpointId, + encryptionKey, + optionalData = {} +}: { + endpointId: string; + encryptionKey: string; + optionalData?: object; +}) => { + const payload = { encKey: encryptionKey, ...optionalData }; + return `${window.location.origin}${base}/flottform-client/${endpointId}/#${encodeURIComponent(JSON.stringify(payload))}`; }; -export const createCustomClientUrl = async ({ endpointId }: { endpointId: string }) => { - return `${window.location.origin}${base}/return-and-complaints-custom-client/${endpointId}`; +export const createCustomClientUrl = async ({ + endpointId, + encryptionKey, + optionalData = {} +}: { + endpointId: string; + encryptionKey: string; + optionalData?: object; +}) => { + const payload = { encKey: encryptionKey, ...optionalData }; + return `${window.location.origin}${base}/return-and-complaints-custom-client/${endpointId}/#${encodeURIComponent(JSON.stringify(payload))}`; }; -export const createCustomizedUiClientUrl = async ({ endpointId }: { endpointId: string }) => { - return `${window.location.origin}${base}/customized-default-ui-client/${endpointId}`; +export const createCustomizedUiClientUrl = async ({ + endpointId, + encryptionKey, + optionalData = {} +}: { + endpointId: string; + encryptionKey: string; + optionalData?: object; +}) => { + const payload = { encKey: encryptionKey, ...optionalData }; + return `${window.location.origin}${base}/customized-default-ui-client/${endpointId}/#${encodeURIComponent(JSON.stringify(payload))}`; }; -export const createExpenseReportClientUrl = async ({ endpointId }: { endpointId: string }) => { - return `${window.location.origin}${base}/expense-report-client/${endpointId}`; +export const createExpenseReportClientUrl = async ({ + endpointId, + encryptionKey, + optionalData = {} +}: { + endpointId: string; + encryptionKey: string; + optionalData?: object; +}) => { + const payload = { encKey: encryptionKey, ...optionalData }; + return `${window.location.origin}${base}/expense-report-client/${endpointId}/#${encodeURIComponent(JSON.stringify(payload))}`; }; -export const createDeExpenseReportClientUrl = async ({ endpointId }: { endpointId: string }) => { - return `${window.location.origin}${base}/belegeinreichung-client/${endpointId}`; + +export const createDeExpenseReportClientUrl = async ({ + endpointId, + encryptionKey, + optionalData = {} +}: { + endpointId: string; + encryptionKey: string; + optionalData?: object; +}) => { + const payload = { encKey: encryptionKey, ...optionalData }; + return `${window.location.origin}${base}/belegeinreichung-client/${endpointId}/#${encodeURIComponent(JSON.stringify(payload))}`; }; diff --git a/servers/demo/src/routes/belegeinreichung-client/[endpointId]/+page.svelte b/servers/demo/src/routes/belegeinreichung-client/[endpointId]/+page.svelte index 1ca32f2..f1b81e2 100644 --- a/servers/demo/src/routes/belegeinreichung-client/[endpointId]/+page.svelte +++ b/servers/demo/src/routes/belegeinreichung-client/[endpointId]/+page.svelte @@ -19,10 +19,13 @@ let currentState: State = 'init'; onMount(async () => { + const hash = JSON.parse(decodeURIComponent($page.url.hash.slice(1))); + const flottformFileInputClient = new FlottformFileInputClient({ endpointId: $page.params.endpointId, fileInput, - flottformApi: sdpExchangeServerBase + flottformApi: sdpExchangeServerBase, + encryptionKey: hash.encKey }); flottformFileInputClient.start(); diff --git a/servers/demo/src/routes/browser-extension/[endpointId]/+page.svelte b/servers/demo/src/routes/browser-extension/[endpointId]/+page.svelte index ca3b00b..ec0aab5 100644 --- a/servers/demo/src/routes/browser-extension/[endpointId]/+page.svelte +++ b/servers/demo/src/routes/browser-extension/[endpointId]/+page.svelte @@ -25,7 +25,8 @@ endpointId: $page.params.endpointId, flottformApi: hash.flottformApi, rtcConfiguration: hash.rtcConfiguration, - type: hash.type + type: hash.type, + encryptionKey: hash.encKey }; console.log({ options }); @@ -43,6 +44,7 @@ endpointId: options.endpointId, fileInput: inputField!, flottformApi: options.flottformApi, + encryptionKey: options.encryptionKey, rtcConfiguration: options.rtcConfiguration }); diff --git a/servers/demo/src/routes/customized-default-ui-client/[endpointId]/+page.svelte b/servers/demo/src/routes/customized-default-ui-client/[endpointId]/+page.svelte index 7da8f22..fe93731 100644 --- a/servers/demo/src/routes/customized-default-ui-client/[endpointId]/+page.svelte +++ b/servers/demo/src/routes/customized-default-ui-client/[endpointId]/+page.svelte @@ -19,10 +19,13 @@ let currentState: State = 'init'; onMount(async () => { + const hash = JSON.parse(decodeURIComponent($page.url.hash.slice(1))); + const flottformFileInputClient = new FlottformFileInputClient({ endpointId: $page.params.endpointId, fileInput, - flottformApi: sdpExchangeServerBase + flottformApi: sdpExchangeServerBase, + encryptionKey: hash.encKey }); flottformFileInputClient.start(); diff --git a/servers/demo/src/routes/expense-report-client/[endpointId]/+page.svelte b/servers/demo/src/routes/expense-report-client/[endpointId]/+page.svelte index 6ae7737..fe9423c 100644 --- a/servers/demo/src/routes/expense-report-client/[endpointId]/+page.svelte +++ b/servers/demo/src/routes/expense-report-client/[endpointId]/+page.svelte @@ -19,10 +19,13 @@ let currentState: State = 'init'; onMount(async () => { + const hash = JSON.parse(decodeURIComponent($page.url.hash.slice(1))); + const flottformFileInputClient = new FlottformFileInputClient({ endpointId: $page.params.endpointId, fileInput, - flottformApi: sdpExchangeServerBase + flottformApi: sdpExchangeServerBase, + encryptionKey: hash.encKey }); flottformFileInputClient.start(); diff --git a/servers/demo/src/routes/flottform-client/[endpointId]/+page.svelte b/servers/demo/src/routes/flottform-client/[endpointId]/+page.svelte index f12f9ac..8b7f935 100644 --- a/servers/demo/src/routes/flottform-client/[endpointId]/+page.svelte +++ b/servers/demo/src/routes/flottform-client/[endpointId]/+page.svelte @@ -20,10 +20,13 @@ let currentState: State = 'init'; onMount(async () => { + const hash = JSON.parse(decodeURIComponent($page.url.hash.slice(1))); + const flottformFileInputClient = new FlottformFileInputClient({ endpointId: $page.params.endpointId, fileInput, - flottformApi: sdpExchangeServerBase + flottformApi: sdpExchangeServerBase, + encryptionKey: hash.encKey }); flottformFileInputClient.start(); diff --git a/servers/demo/src/routes/flottform-text-client/[endpointId]/+page.svelte b/servers/demo/src/routes/flottform-text-client/[endpointId]/+page.svelte index 9257b4d..5a5bc11 100644 --- a/servers/demo/src/routes/flottform-text-client/[endpointId]/+page.svelte +++ b/servers/demo/src/routes/flottform-text-client/[endpointId]/+page.svelte @@ -12,9 +12,11 @@ let textToSend = $state(''); onMount(async () => { + const hash = JSON.parse(decodeURIComponent($page.url.hash.slice(1))); const flottformTextInputClient = new FlottformTextInputClient({ endpointId: $page.params.endpointId, - flottformApi: sdpExchangeServerBase + flottformApi: sdpExchangeServerBase, + encryptionKey: hash.encKey }); // Start the WebRTC connection process as soon as the page loads. flottformTextInputClient.start(); diff --git a/servers/demo/src/routes/multiple-input-form-client/[endpointId]/+page.svelte b/servers/demo/src/routes/multiple-input-form-client/[endpointId]/+page.svelte index 4161a11..b2a628e 100644 --- a/servers/demo/src/routes/multiple-input-form-client/[endpointId]/+page.svelte +++ b/servers/demo/src/routes/multiple-input-form-client/[endpointId]/+page.svelte @@ -20,10 +20,13 @@ let currentState: State = 'init'; onMount(async () => { + const hash = JSON.parse(decodeURIComponent($page.url.hash.slice(1))); + const flottformFileInputClient = new FlottformFileInputClient({ endpointId: $page.params.endpointId, fileInput, - flottformApi: sdpExchangeServerBase + flottformApi: sdpExchangeServerBase, + encryptionKey: hash.encKey }); flottformFileInputClient.start(); diff --git a/servers/demo/src/routes/return-and-complaints-custom-client/[endpointId]/+page.svelte b/servers/demo/src/routes/return-and-complaints-custom-client/[endpointId]/+page.svelte index 5c8dce2..8ee4cb2 100644 --- a/servers/demo/src/routes/return-and-complaints-custom-client/[endpointId]/+page.svelte +++ b/servers/demo/src/routes/return-and-complaints-custom-client/[endpointId]/+page.svelte @@ -20,10 +20,13 @@ let currentState: State = 'init'; onMount(async () => { + const hash = JSON.parse(decodeURIComponent($page.url.hash.slice(1))); + const flottformFileInputClient = new FlottformFileInputClient({ endpointId: $page.params.endpointId, fileInput, - flottformApi: sdpExchangeServerBase + flottformApi: sdpExchangeServerBase, + encryptionKey: hash.encKey }); flottformFileInputClient.start(); diff --git a/servers/signaling-server/src/lib/validations.ts b/servers/signaling-server/src/lib/validations.ts index 7a54ef2..485958c 100644 --- a/servers/signaling-server/src/lib/validations.ts +++ b/servers/signaling-server/src/lib/validations.ts @@ -5,6 +5,10 @@ export const RTCSessionDescriptionInitSchema = z.object({ sdp: z.string().optional() }); +export const CreateEndpointPayloadSchema = z.object({ + session: z.string({ message: 'Expected session of type string' }) +}); + export type RTCSessionDescriptionInitValidated = z.infer; assertType>(); diff --git a/servers/signaling-server/src/routes/flottform/[endpointId]/client/+server.ts b/servers/signaling-server/src/routes/flottform/[endpointId]/client/+server.ts index ee5c78a..0b8ae34 100644 --- a/servers/signaling-server/src/routes/flottform/[endpointId]/client/+server.ts +++ b/servers/signaling-server/src/routes/flottform/[endpointId]/client/+server.ts @@ -1,13 +1,12 @@ import { type RequestHandler, json, error, text } from '@sveltejs/kit'; import { retrieveFlottformDatabase } from '$lib/database'; -import { RTCIceCandidateInitSchema, RTCSessionDescriptionInitSchema } from '$lib/validations'; import { z, ZodError } from 'zod'; import { corsHeaders } from '$lib/cors-headers'; const validatePutPeerInfosBody = z.object({ clientKey: z.string(), - iceCandidates: z.array(RTCIceCandidateInitSchema), - session: RTCSessionDescriptionInitSchema + iceCandidates: z.string(), + session: z.string() }); export const PUT: RequestHandler = async ({ params, request }) => { diff --git a/servers/signaling-server/src/routes/flottform/[endpointId]/host/+server.ts b/servers/signaling-server/src/routes/flottform/[endpointId]/host/+server.ts index ff03513..5e0b484 100644 --- a/servers/signaling-server/src/routes/flottform/[endpointId]/host/+server.ts +++ b/servers/signaling-server/src/routes/flottform/[endpointId]/host/+server.ts @@ -1,13 +1,12 @@ import { type RequestHandler, json, error, text } from '@sveltejs/kit'; import { retrieveFlottformDatabase } from '$lib/database'; -import { RTCIceCandidateInitSchema, RTCSessionDescriptionInitSchema } from '$lib/validations'; import { ZodError, z } from 'zod'; import { corsHeaders } from '$lib/cors-headers'; const validatePutPeerInfosBody = z.object({ hostKey: z.string(), - session: RTCSessionDescriptionInitSchema, - iceCandidates: z.array(RTCIceCandidateInitSchema) + session: z.string(), + iceCandidates: z.string() }); export const PUT: RequestHandler = async ({ params, request }) => { diff --git a/servers/signaling-server/src/routes/flottform/create/+server.ts b/servers/signaling-server/src/routes/flottform/create/+server.ts index 7b39e85..afc7ee1 100644 --- a/servers/signaling-server/src/routes/flottform/create/+server.ts +++ b/servers/signaling-server/src/routes/flottform/create/+server.ts @@ -1,20 +1,17 @@ import { type RequestHandler, json, error, text } from '@sveltejs/kit'; import { retrieveFlottformDatabase } from '$lib/database'; -import { RTCSessionDescriptionInitSchema } from '$lib/validations'; import { corsHeaders } from '$lib/cors-headers'; +import { CreateEndpointPayloadSchema } from '$lib/validations'; export const POST: RequestHandler = async ({ request }) => { const data = await request.json(); - if (!data.session) { - return error(400, 'No session provided.'); - } - let session: RTCSessionDescriptionInit; + let session: string; try { - session = RTCSessionDescriptionInitSchema.parse(data.session); + session = CreateEndpointPayloadSchema.parse(data).session; } catch (e) { console.log(e); - return error(400, 'Could not parse session parameter into RTCSessionDescription.'); + return error(400, 'Could not parse session parameter into string.'); } const db = await retrieveFlottformDatabase(); diff --git a/servers/where-are-you-at/src/routes/now/[endpointId]/+page.svelte b/servers/where-are-you-at/src/routes/now/[endpointId]/+page.svelte index e82df48..e43f091 100644 --- a/servers/where-are-you-at/src/routes/now/[endpointId]/+page.svelte +++ b/servers/where-are-you-at/src/routes/now/[endpointId]/+page.svelte @@ -10,9 +10,11 @@ let updateCurrentPosition = $state<() => void>(); onMount(async () => { + const hash = JSON.parse(decodeURIComponent($page.url.hash.slice(1))); const flottformTextInputClient = new FlottformTextInputClient({ endpointId: $page.params.endpointId, - flottformApi: sdpExchangeServerBase + flottformApi: sdpExchangeServerBase, + encryptionKey: hash.encKey }); // Start the WebRTC connection process as soon as the page loads. flottformTextInputClient.start(); From 720c447c676bb24f1532d0a2c4243bde3f50c353 Mon Sep 17 00:00:00 2001 From: Joern Bernhardt Date: Mon, 24 Feb 2025 01:55:55 +0100 Subject: [PATCH 2/4] chore: Remove need for optionalData, use getIceApi to fetch ice candidate servers Signed-off-by: Joern Bernhardt --- flottform/forms/src/flottform-channel-host.ts | 7 +- .../forms/src/flottform-file-input-host.ts | 6 +- .../forms/src/flottform-text-input-host.ts | 6 +- servers/chrome-extension/src/lib/options.ts | 6 +- .../src/routes/+layout.svelte | 3 - .../chrome-extension/src/routes/+page.svelte | 70 ++++----------- .../src/routes/options/+page.svelte | 19 ++--- .../static/scripts/flottform-bundle.js | 77 +++++++++-------- .../static/scripts/flottform-bundle.js.map | 2 +- .../demo/src/lib/isOfTypeRTCIceServer.test.ts | 85 +++++++++++++++++++ servers/demo/src/lib/isOfTypeRTCIceServer.ts | 31 +++++++ servers/demo/src/routes/+layout.svelte | 3 - .../[endpointId]/+page.svelte | 35 +++++++- 13 files changed, 220 insertions(+), 130 deletions(-) create mode 100644 servers/demo/src/lib/isOfTypeRTCIceServer.test.ts create mode 100644 servers/demo/src/lib/isOfTypeRTCIceServer.ts diff --git a/flottform/forms/src/flottform-channel-host.ts b/flottform/forms/src/flottform-channel-host.ts index 10aadb0..bd537ff 100644 --- a/flottform/forms/src/flottform-channel-host.ts +++ b/flottform/forms/src/flottform-channel-host.ts @@ -14,7 +14,6 @@ export class FlottformChannelHost extends EventEmitter { private createClientUrl: (params: { endpointId: string; encryptionKey: string; - optionalData?: object; }) => Promise; private rtcConfiguration: RTCConfiguration; private pollTimeForIceInMs: number; @@ -35,11 +34,7 @@ export class FlottformChannelHost extends EventEmitter { logger }: { flottformApi: string | URL; - createClientUrl: (params: { - endpointId: string; - encryptionKey: string; - optionalData?: object; - }) => Promise; + createClientUrl: (params: { endpointId: string; encryptionKey: string }) => Promise; rtcConfiguration: RTCConfiguration; pollTimeForIceInMs: number; logger: Logger; diff --git a/flottform/forms/src/flottform-file-input-host.ts b/flottform/forms/src/flottform-file-input-host.ts index 9a3b292..57d132d 100644 --- a/flottform/forms/src/flottform-file-input-host.ts +++ b/flottform/forms/src/flottform-file-input-host.ts @@ -45,11 +45,7 @@ export class FlottformFileInputHost extends BaseInputHost { logger = console }: { flottformApi: string | URL; - createClientUrl: (params: { - endpointId: string; - encryptionKey: string; - optionalData?: object; - }) => Promise; + createClientUrl: (params: { endpointId: string; encryptionKey: string }) => Promise; inputField?: HTMLInputElement; rtcConfiguration?: RTCConfiguration; pollTimeForIceInMs?: number; diff --git a/flottform/forms/src/flottform-text-input-host.ts b/flottform/forms/src/flottform-text-input-host.ts index 6373ab2..e14be86 100644 --- a/flottform/forms/src/flottform-text-input-host.ts +++ b/flottform/forms/src/flottform-text-input-host.ts @@ -30,11 +30,7 @@ export class FlottformTextInputHost extends BaseInputHost { logger = console }: { flottformApi: string | URL; - createClientUrl: (params: { - endpointId: string; - encryptionKey: string; - optionalData?: object; - }) => Promise; + createClientUrl: (params: { endpointId: string; encryptionKey: string }) => Promise; inputField?: HTMLInputElement | HTMLTextAreaElement; rtcConfiguration?: RTCConfiguration; pollTimeForIceInMs?: number; diff --git a/servers/chrome-extension/src/lib/options.ts b/servers/chrome-extension/src/lib/options.ts index 4b48a5d..f4b89bb 100644 --- a/servers/chrome-extension/src/lib/options.ts +++ b/servers/chrome-extension/src/lib/options.ts @@ -1,3 +1,3 @@ -export const defaultTurnServerMeteredEndpointValue = ''; -export const defaultSignalingServerUrlBase = 'https://192.168.0.169:5177/flottform'; //'https://demo.flottform.io/flottform'; -export const defaultExtensionClientUrlBase = 'https://192.168.0.169:5175/browser-extension'; //'https://demo.flottform.io/browser-extension'; +export const defaultGetIceServersEndpoint = ''; +export const defaultSignalingServerUrlBase = 'https://192.168.0.169:5177/flottform'; //'https://api.flottform.io/v1'; +export const defaultExtensionClientUrlBase = 'https://192.168.0.169:5175/browser-extension'; //'https://api.flottform.io/client'; diff --git a/servers/chrome-extension/src/routes/+layout.svelte b/servers/chrome-extension/src/routes/+layout.svelte index 0a59f92..7fe5b48 100644 --- a/servers/chrome-extension/src/routes/+layout.svelte +++ b/servers/chrome-extension/src/routes/+layout.svelte @@ -7,6 +7,3 @@
- - diff --git a/servers/chrome-extension/src/routes/+page.svelte b/servers/chrome-extension/src/routes/+page.svelte index c90b4b8..3b1501a 100644 --- a/servers/chrome-extension/src/routes/+page.svelte +++ b/servers/chrome-extension/src/routes/+page.svelte @@ -1,7 +1,7 @@