@genai-fi/base 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +18 -0
  3. package/dist/Button-DQwRVw4a.js +1918 -0
  4. package/dist/DefaultPropsProvider-C0Ib4Mye.js +520 -0
  5. package/dist/DialogQR-BU45QB3i.js +1625 -0
  6. package/dist/FileSaver.min-DhePf63e.js +2397 -0
  7. package/dist/FlashWifi-CaAOKd3g.js +33 -0
  8. package/dist/_commonjsHelpers-DaMA6jEr.js +8 -0
  9. package/dist/assets/AlertPara.css +1 -0
  10. package/dist/assets/ConnectionStatus.css +1 -0
  11. package/dist/assets/DialogQR.css +1 -0
  12. package/dist/assets/Motd.css +1 -0
  13. package/dist/assets/Privacy.css +1 -0
  14. package/dist/assets/Spinner.css +1 -0
  15. package/dist/assets/Webcam.css +1 -0
  16. package/dist/assets/style.css +1 -0
  17. package/dist/assets/theme.css +1 -0
  18. package/dist/colours.module.css +19 -0
  19. package/dist/components/AlertPara/AlertPara.d.ts +8 -0
  20. package/dist/components/AlertPara/AlertPara.js +19 -0
  21. package/dist/components/BusyButton/BusyButton.d.ts +7 -0
  22. package/dist/components/BusyButton/BusyButton.js +25 -0
  23. package/dist/components/Button/Button.d.ts +6 -0
  24. package/dist/components/Button/Button.js +6 -0
  25. package/dist/components/ConnectionStatus/ConnectionStatus.d.ts +12 -0
  26. package/dist/components/ConnectionStatus/ConnectionStatus.js +82 -0
  27. package/dist/components/ConnectionStatus/FlashWifi.d.ts +1 -0
  28. package/dist/components/ConnectionStatus/FlashWifi.js +6 -0
  29. package/dist/components/ConnectionStatus/check.d.ts +1 -0
  30. package/dist/components/ConnectionStatus/check.js +10 -0
  31. package/dist/components/ConnectionStatus/ice.d.ts +13 -0
  32. package/dist/components/ConnectionStatus/ice.js +12 -0
  33. package/dist/components/ContentLoader/ContentError.d.ts +5 -0
  34. package/dist/components/ContentLoader/ContentError.js +21 -0
  35. package/dist/components/ContentLoader/ContentLoader.d.ts +8 -0
  36. package/dist/components/ContentLoader/ContentLoader.js +51 -0
  37. package/dist/components/ContentLoader/ContentProgress.d.ts +6 -0
  38. package/dist/components/ContentLoader/ContentProgress.js +31 -0
  39. package/dist/components/Motd/Motd.d.ts +5 -0
  40. package/dist/components/Motd/Motd.js +48 -0
  41. package/dist/components/Privacy/Privacy.d.ts +7 -0
  42. package/dist/components/Privacy/Privacy.js +57 -0
  43. package/dist/components/QRCode/DialogQR.d.ts +7 -0
  44. package/dist/components/QRCode/DialogQR.js +14 -0
  45. package/dist/components/QRCode/QRCode.d.ts +9 -0
  46. package/dist/components/QRCode/QRCode.js +61 -0
  47. package/dist/components/Spinner/Spinner.d.ts +6 -0
  48. package/dist/components/Spinner/Spinner.js +33 -0
  49. package/dist/components/Webcam/Webcam.d.ts +15 -0
  50. package/dist/components/Webcam/Webcam.js +397 -0
  51. package/dist/components/Webcam/webcamClass.d.ts +32 -0
  52. package/dist/components/Webcam/webcamClass.js +76 -0
  53. package/dist/createSvgIcon-BfF8yuCp.js +249 -0
  54. package/dist/createTheme-BIcG8YPQ.js +2895 -0
  55. package/dist/hooks/id.d.ts +1 -0
  56. package/dist/hooks/id.js +16 -0
  57. package/dist/hooks/onlyOnce.d.ts +1 -0
  58. package/dist/hooks/onlyOnce.js +7 -0
  59. package/dist/hooks/peer.d.ts +25 -0
  60. package/dist/hooks/peer.js +70 -0
  61. package/dist/hooks/random.d.ts +1 -0
  62. package/dist/hooks/random.js +9 -0
  63. package/dist/hooks/useTabActive.d.ts +1 -0
  64. package/dist/hooks/useTabActive.js +17 -0
  65. package/dist/index-SOhdqzHq.js +113 -0
  66. package/dist/main.d.ts +21 -0
  67. package/dist/main.js +49 -0
  68. package/dist/react-D-b-Xrzv.js +98 -0
  69. package/dist/services/peer2peer/Incoming.d.ts +13 -0
  70. package/dist/services/peer2peer/Incoming.js +39 -0
  71. package/dist/services/peer2peer/Outgoing.d.ts +25 -0
  72. package/dist/services/peer2peer/Outgoing.js +65 -0
  73. package/dist/services/peer2peer/Peer2Peer.d.ts +80 -0
  74. package/dist/services/peer2peer/Peer2Peer.js +3367 -0
  75. package/dist/services/peer2peer/PeerConnection.d.ts +40 -0
  76. package/dist/services/peer2peer/PeerConnection.js +155 -0
  77. package/dist/services/peer2peer/error.d.ts +2 -0
  78. package/dist/services/peer2peer/error.js +5 -0
  79. package/dist/services/peer2peer/types.d.ts +38 -0
  80. package/dist/services/peer2peer/types.js +1 -0
  81. package/dist/state/webrtcState.d.ts +12 -0
  82. package/dist/state/webrtcState.js +6 -0
  83. package/dist/style/theme.d.ts +1 -0
  84. package/dist/style/theme.js +33 -0
  85. package/dist/style.module-DSFm2eLD.js +9 -0
  86. package/dist/util/backoff.d.ts +1 -0
  87. package/dist/util/backoff.js +6 -0
  88. package/dist/util/base64.d.ts +2 -0
  89. package/dist/util/base64.js +19 -0
  90. package/dist/util/canvas.d.ts +7 -0
  91. package/dist/util/canvas.js +92 -0
  92. package/dist/util/crypto.d.ts +7 -0
  93. package/dist/util/crypto.js +50 -0
  94. package/dist/util/randomId.d.ts +1 -0
  95. package/dist/util/randomId.js +8 -0
  96. package/dist/util/zip.d.ts +13 -0
  97. package/dist/util/zip.js +94 -0
  98. package/dist/webrtcState-D0nJpE9Z.js +406 -0
  99. package/package.json +88 -0
@@ -0,0 +1,40 @@
1
+ import { default as EventEmitter } from 'eventemitter3';
2
+ import { default as Peer, DataConnection } from 'peerjs';
3
+ import { PeerConnectionType, PeerStatus } from './types';
4
+ export default class PeerConnection extends EventEmitter<'open' | 'data' | 'close' | 'error' | 'crypto' | 'timeout'> {
5
+ private dataConnection?;
6
+ readonly peerInstance: Peer;
7
+ readonly peer: string;
8
+ private _connType;
9
+ private pubKey?;
10
+ private createCrypto?;
11
+ private encrypt?;
12
+ private decrypt?;
13
+ private queue?;
14
+ private connectTimeout;
15
+ readonly initiated: boolean;
16
+ private wsListener?;
17
+ get connectionType(): PeerConnectionType;
18
+ get open(): boolean;
19
+ get connectionId(): string;
20
+ /** Quality of the connection from 0 to 3. */
21
+ get quality(): number;
22
+ /** Create a connection. If the dataConnection parameter is missing then it uses the websocket as a relay. */
23
+ constructor(peer: string, peerInstance: Peer, initiated: boolean, dataConnection?: DataConnection, dropICE?: boolean);
24
+ getPublicKey(): string | undefined;
25
+ /** Set the remote public key */
26
+ setKey(key: string): Promise<void>;
27
+ /** Send our public key to the remote */
28
+ sendCryptoHandshake(): void;
29
+ /** For websocket data, decrypt it and emit the event */
30
+ decryptPayload(data: string): Promise<void>;
31
+ private sendEncrypted;
32
+ send(data: unknown): void;
33
+ close(): void;
34
+ }
35
+ export interface IConnectionIO extends EventEmitter<'connect' | 'retry' | 'close' | 'data'> {
36
+ direction: 'outgoing' | 'incoming';
37
+ connection: PeerConnection;
38
+ close: () => void;
39
+ status: PeerStatus;
40
+ }
@@ -0,0 +1,155 @@
1
+ var u = Object.defineProperty;
2
+ var f = (h, c, e) => c in h ? u(h, c, { enumerable: !0, configurable: !0, writable: !0, value: e }) : h[c] = e;
3
+ var o = (h, c, e) => f(h, typeof c != "symbol" ? c + "" : c, e);
4
+ import { E as m } from "../../index-SOhdqzHq.js";
5
+ import { createAsym as w } from "../../util/crypto.js";
6
+ import { base64ToBytes as d, bytesToBase64 as l } from "../../util/base64.js";
7
+ import y from "./error.js";
8
+ const T = 1e4;
9
+ class K extends m {
10
+ /** Create a connection. If the dataConnection parameter is missing then it uses the websocket as a relay. */
11
+ constructor(e, s, r, t, a) {
12
+ super();
13
+ o(this, "dataConnection");
14
+ o(this, "peerInstance");
15
+ o(this, "peer");
16
+ o(this, "_connType", "server");
17
+ o(this, "pubKey");
18
+ o(this, "createCrypto");
19
+ o(this, "encrypt");
20
+ o(this, "decrypt");
21
+ o(this, "queue");
22
+ o(this, "connectTimeout", -1);
23
+ o(this, "initiated");
24
+ o(this, "wsListener");
25
+ if (this.initiated = r, this.peerInstance = s, this.dataConnection = t, this.peer = e, t)
26
+ this._connType = "relay", t.on("open", () => {
27
+ clearTimeout(this.connectTimeout), this.connectTimeout = -1, t.peerConnection.getStats().then((i) => {
28
+ i.forEach((n) => {
29
+ if (n.type === "candidate-pair" && (n.state === "succeeded" || n.state === "in-progress")) {
30
+ const p = i.get(n.remoteCandidateId);
31
+ (p == null ? void 0 : p.candidateType) === "relay" ? this._connType = "relay" : p && (this._connType = "p2p");
32
+ }
33
+ }), this._connType === "server" && console.warn("Failed to find p2p candidate", Array.from(i)), this.emit("open", this);
34
+ });
35
+ }), t.on("close", () => {
36
+ this.emit("close", this, !1);
37
+ }), t.on("data", (i) => {
38
+ this.emit("data", i, this);
39
+ }), t.on("error", (i) => {
40
+ this.emit("error", i, this);
41
+ }), t.on("iceStateChanged", (i) => {
42
+ i === "disconnected" && t.open && t.close(), a && i === "checking" && (t.close(), this.emit("close", this, !1));
43
+ });
44
+ else {
45
+ this._connType = "server", w().then(({ createSymCrypto: n, publicKey: p }) => {
46
+ this.createCrypto = n, this.pubKey = p, this.sendCryptoHandshake(), this.emit("crypto");
47
+ }).catch(() => {
48
+ this.emit("error", { type: "no-crypto" }, this), this.close();
49
+ });
50
+ const i = (n) => {
51
+ n.src === this.peer && n.payload && (n.type === "KEY" ? this.setKey(n.payload) : n.type === "DATA" && this.decryptPayload(n.payload));
52
+ };
53
+ this.wsListener = i, this.peerInstance.socket.on("message", i), this.peerInstance.once("disconnected", () => {
54
+ this.wsListener && (this.peerInstance.socket.off("message", this.wsListener), this.wsListener = void 0), this.emit("close", this, !1);
55
+ });
56
+ }
57
+ this.initiated && (this.connectTimeout = window.setTimeout(() => {
58
+ this.connectTimeout = -1, this.open ? console.warn("Timeout, but already open") : (console.warn("Connect timeout", this), this.close(), this.emit("timeout", this));
59
+ }, T));
60
+ }
61
+ get connectionType() {
62
+ return this._connType;
63
+ }
64
+ get open() {
65
+ return this.dataConnection ? this.dataConnection.open : !!this.encrypt;
66
+ }
67
+ get connectionId() {
68
+ return this.peer;
69
+ }
70
+ /** Quality of the connection from 0 to 3. */
71
+ get quality() {
72
+ if (!this.open) return 0;
73
+ switch (this.connectionType) {
74
+ case "p2p":
75
+ return 3;
76
+ case "relay":
77
+ return 2;
78
+ case "server":
79
+ return 1;
80
+ }
81
+ }
82
+ getPublicKey() {
83
+ return this.pubKey;
84
+ }
85
+ /** Set the remote public key */
86
+ async setKey(e) {
87
+ if (this.dataConnection)
88
+ throw new y("Public key is not needed on P2P connection");
89
+ if (this.createCrypto) {
90
+ this.encrypt && console.warn("Key already received");
91
+ const { encrypt: s, decrypt: r } = await this.createCrypto(e);
92
+ this.encrypt = s, this.decrypt = r, clearTimeout(this.connectTimeout), this.connectTimeout = -1, this.emit("open", this), this.queue && (this.queue.forEach((t) => {
93
+ this.decryptPayload(t);
94
+ }), this.queue = void 0);
95
+ } else
96
+ this.once("crypto", () => {
97
+ this.setKey(e);
98
+ });
99
+ }
100
+ /** Send our public key to the remote */
101
+ sendCryptoHandshake() {
102
+ this.peerInstance.open && this.peerInstance.socket.send({
103
+ type: "KEY",
104
+ src: this.peerInstance.id,
105
+ dst: this.peer,
106
+ payload: this.pubKey
107
+ });
108
+ }
109
+ /** For websocket data, decrypt it and emit the event */
110
+ async decryptPayload(e) {
111
+ if (this.decrypt) {
112
+ const s = JSON.parse(e);
113
+ if (!s || !s.data || !s.iv) throw new y("Invalid encrypted packet");
114
+ const r = await d(s.data), t = await d(s.iv);
115
+ try {
116
+ const a = await this.decrypt(new Uint8Array(r), new Uint8Array(t));
117
+ this.emit("data", JSON.parse(a), this);
118
+ } catch {
119
+ console.error("Decryption error");
120
+ }
121
+ } else {
122
+ const s = this.queue || [];
123
+ s.push(e), this.queue = s;
124
+ }
125
+ }
126
+ async sendEncrypted(e) {
127
+ if (this.encrypt) {
128
+ const s = await this.encrypt(JSON.stringify(e)), r = await l(s[0]), t = await l(s[1]), a = JSON.stringify({
129
+ data: r,
130
+ iv: t
131
+ });
132
+ this.peerInstance.socket.send({
133
+ type: "DATA",
134
+ src: this.peerInstance.id,
135
+ dst: this.peer,
136
+ payload: a
137
+ });
138
+ } else
139
+ throw new y("Failed to send, no key");
140
+ }
141
+ send(e) {
142
+ this.dataConnection ? this.dataConnection.send(e) : this.sendEncrypted(e);
143
+ }
144
+ close() {
145
+ if (this.connectTimeout >= 0 && (clearTimeout(this.connectTimeout), this.connectTimeout = -1), this.dataConnection) {
146
+ this.dataConnection.removeAllListeners();
147
+ const e = this.dataConnection.open;
148
+ this.dataConnection.close(), e && this.emit("close", this, !0);
149
+ } else this.open && (this.encrypt = void 0, this.decrypt = void 0, this.emit("close", this, !0));
150
+ this.wsListener && (this.peerInstance.socket.off("message", this.wsListener), this.wsListener = void 0);
151
+ }
152
+ }
153
+ export {
154
+ K as default
155
+ };
@@ -0,0 +1,2 @@
1
+ export default class P2PException extends Error {
2
+ }
@@ -0,0 +1,5 @@
1
+ class r extends Error {
2
+ }
3
+ export {
4
+ r as default
5
+ };
@@ -0,0 +1,38 @@
1
+ export type PeerStatus = 'connecting' | 'ready' | 'failed';
2
+ export type PeerErrorType = 'none' | 'id-in-use' | 'peer-not-found' | 'no-signaling' | 'missing-ice' | 'unknown' | 'bad-browser';
3
+ export type PeerConnectionType = 'p2p' | 'relay' | 'server';
4
+ export interface PeerEvent {
5
+ event: string;
6
+ }
7
+ interface PeerCloseEvent extends PeerEvent {
8
+ event: 'eter:close';
9
+ }
10
+ interface PeerPingEvent extends PeerEvent {
11
+ event: 'ping';
12
+ }
13
+ interface PeerJoinEvent extends PeerEvent {
14
+ event: 'eter:join';
15
+ }
16
+ interface PeerWelcomeEvent extends PeerEvent {
17
+ event: 'eter:welcome';
18
+ }
19
+ interface PeerChainEvent extends PeerEvent {
20
+ event: 'eter:connect';
21
+ code: string;
22
+ }
23
+ export interface PeerJSMessage {
24
+ type: string;
25
+ dst: string;
26
+ src: string;
27
+ payload?: string;
28
+ }
29
+ export type BuiltinEvent = PeerWelcomeEvent | PeerCloseEvent | PeerJoinEvent | PeerChainEvent | PeerPingEvent;
30
+ export type SenderType<T> = (data: T | BuiltinEvent, exclude?: string[]) => void;
31
+ export interface Connection<T extends PeerEvent> {
32
+ send: (data: T) => void;
33
+ open: boolean;
34
+ quality: number;
35
+ connectionType: PeerConnectionType;
36
+ connectionId: string;
37
+ }
38
+ export {};
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,12 @@
1
+ import { CommunicationRelayConfiguration } from '../components/ConnectionStatus/ice';
2
+ type WebRTCPermissions = 'disabled' | 'unset' | 'full' | 'relay';
3
+ export declare const webrtcActive: import('jotai').PrimitiveAtom<WebRTCPermissions> & {
4
+ init: WebRTCPermissions;
5
+ };
6
+ export declare const iceConfig: import('jotai').PrimitiveAtom<CommunicationRelayConfiguration | undefined> & {
7
+ init: CommunicationRelayConfiguration | undefined;
8
+ };
9
+ export declare const webrtcCandidate: import('jotai').PrimitiveAtom<"unset" | "relay" | "other"> & {
10
+ init: "unset" | "relay" | "other";
11
+ };
12
+ export {};
@@ -0,0 +1,6 @@
1
+ import { i, w as t, a as c } from "../webrtcState-D0nJpE9Z.js";
2
+ export {
3
+ i as iceConfig,
4
+ t as webrtcActive,
5
+ c as webrtcCandidate
6
+ };
@@ -0,0 +1 @@
1
+ export declare const theme: import('@mui/material').Theme;
@@ -0,0 +1,33 @@
1
+ import { c as s } from "../createTheme-BIcG8YPQ.js";
2
+ import '../assets/theme.css';const t = "#008297", a = {
3
+ primary: t
4
+ };
5
+ var e, o;
6
+ const i = ((o = (e = globalThis == null ? void 0 : globalThis.process) == null ? void 0 : e.env) == null ? void 0 : o.NODE_ENV) === "test", m = s({
7
+ palette: {
8
+ primary: {
9
+ main: i ? "#fff" : a.primary
10
+ },
11
+ success: {
12
+ main: "#00972e"
13
+ }
14
+ },
15
+ typography: {
16
+ fontFamily: [
17
+ "Andika",
18
+ "-apple-system",
19
+ "BlinkMacSystemFont",
20
+ '"Segoe UI"',
21
+ "Roboto",
22
+ '"Helvetica Neue"',
23
+ "Arial",
24
+ "sans-serif",
25
+ '"Apple Color Emoji"',
26
+ '"Segoe UI Emoji"',
27
+ '"Segoe UI Symbol"'
28
+ ].join(",")
29
+ }
30
+ });
31
+ export {
32
+ m as theme
33
+ };
@@ -0,0 +1,9 @@
1
+ import './assets/style.css';const t = "_title_1bpz2_3", e = "_content_1bpz2_8", r = "_errorTitle_1bpz2_18", o = "_errorContent_1bpz2_23", n = {
2
+ title: t,
3
+ content: e,
4
+ errorTitle: r,
5
+ errorContent: o
6
+ };
7
+ export {
8
+ n as s
9
+ };
@@ -0,0 +1 @@
1
+ export declare function expBackoff(count: number, max?: number): number;
@@ -0,0 +1,6 @@
1
+ function o(t, n = 3) {
2
+ return Math.pow(2, Math.min(t, n)) * 1e3;
3
+ }
4
+ export {
5
+ o as expBackoff
6
+ };
@@ -0,0 +1,2 @@
1
+ export declare function bytesToBase64(bytes: BlobPart, type?: string): Promise<string>;
2
+ export declare function base64ToBytes(data: string): Promise<ArrayBuffer>;
@@ -0,0 +1,19 @@
1
+ async function c(e, t = "application/octet-stream") {
2
+ return await new Promise((n, s) => {
3
+ const a = Object.assign(new FileReader(), {
4
+ onload: () => {
5
+ const r = a.result, o = r.indexOf(","), i = r.substring(o + 1);
6
+ n(i);
7
+ },
8
+ onerror: () => s(a.error)
9
+ });
10
+ a.readAsDataURL(new File([e], "", { type: t }));
11
+ });
12
+ }
13
+ async function d(e) {
14
+ return await (await fetch(`data:application/octet-stream;base64,${e}`)).arrayBuffer();
15
+ }
16
+ export {
17
+ d as base64ToBytes,
18
+ c as bytesToBase64
19
+ };
@@ -0,0 +1,7 @@
1
+ export declare function cropTo(image: HTMLImageElement | HTMLVideoElement, size: number, flipped: boolean, canvas: HTMLCanvasElement): HTMLCanvasElement;
2
+ export declare function canvasFromFile(file: File, size?: number): Promise<HTMLCanvasElement>;
3
+ export declare function canvasesFromFiles(files: File[], size?: number): Promise<HTMLCanvasElement[]>;
4
+ export declare function canvasFromImage(image: HTMLImageElement, size?: number): Promise<HTMLCanvasElement>;
5
+ export declare function canvasFromURL(url: string, size?: number): Promise<HTMLCanvasElement>;
6
+ export declare function canvasFromDataTransfer(item: DataTransfer | DragEvent, size?: number): Promise<HTMLCanvasElement[]>;
7
+ export declare function urlFromDataTransfer(item: DataTransfer | DragEvent, size?: number): Promise<string[]>;
@@ -0,0 +1,92 @@
1
+ function f(t, e, s, r) {
2
+ let n = t.width, o = t.height;
3
+ t instanceof HTMLVideoElement && (n = t.videoWidth, o = t.videoHeight);
4
+ const a = Math.min(n, o), c = e / a, l = Math.ceil(n * c), d = Math.ceil(o * c), h = l - e, u = d - e;
5
+ r.width = r.height = e;
6
+ const i = r.getContext("2d");
7
+ return i && (i.drawImage(t, ~~(h / 2) * -1, ~~(u / 2) * -1, l, d), s && (i.scale(-1, 1), i.drawImage(r, e * -1, 0))), r;
8
+ }
9
+ function m(t, e = 224) {
10
+ return new Promise((s, r) => {
11
+ const n = new FileReader();
12
+ n.onabort = () => r(), n.onerror = () => r(), n.onload = () => {
13
+ var c, l;
14
+ const o = document.createElement("canvas");
15
+ o.width = e, o.height = e;
16
+ const a = new Image();
17
+ a.onload = () => {
18
+ f(a, e, !1, o), s(o);
19
+ }, a.onerror = () => {
20
+ s(o);
21
+ }, a.src = n.result, ((l = (c = global == null ? void 0 : global.process) == null ? void 0 : c.env) == null ? void 0 : l.NODE_ENV) === "test" && a.onload(new Event("onload"));
22
+ }, n.readAsDataURL(t);
23
+ });
24
+ }
25
+ async function v(t, e = 224) {
26
+ const s = t.filter((n) => n.type.startsWith("image/"));
27
+ if (s.length === 0)
28
+ return [];
29
+ const r = s.map((n) => m(n, e));
30
+ return Promise.all(r);
31
+ }
32
+ function g(t, e = 224) {
33
+ return new Promise((s, r) => {
34
+ const n = document.createElement("canvas");
35
+ n.width = e, n.height = e, t.onload = () => {
36
+ f(t, e, !1, n), s(n);
37
+ }, t.onerror = r, t.onabort = r;
38
+ });
39
+ }
40
+ function w(t, e = 224) {
41
+ return new Promise((s, r) => {
42
+ const n = document.createElement("canvas");
43
+ n.width = e, n.height = e;
44
+ const o = new Image();
45
+ o.crossOrigin = "anonymous", o.onload = () => {
46
+ f(o, e, !1, n), s(n);
47
+ }, o.onerror = r, o.onabort = r, o.src = t;
48
+ });
49
+ }
50
+ async function p(t, e = 224) {
51
+ var s;
52
+ if ("files" in t && ((s = t.files) == null ? void 0 : s.length) > 0) {
53
+ const n = Array.from(t.files).filter((a) => a.type.startsWith("image/"));
54
+ if (n.length === 0)
55
+ return [];
56
+ const o = n.map((a) => m(a, e));
57
+ return Promise.all(o);
58
+ }
59
+ if ("html" in t && typeof t.html == "string") {
60
+ const r = document.createElement("html");
61
+ r.innerHTML = t.html;
62
+ const n = r.getElementsByTagName("img");
63
+ if (n.length > 0) {
64
+ const o = Array.from(n).map((a) => (a.crossOrigin = "anonymous", g(a, e)));
65
+ return Promise.all(o);
66
+ }
67
+ }
68
+ if ("dataTransfer" in t && t.dataTransfer) {
69
+ const r = t.dataTransfer.types;
70
+ if (r && r.includes("text/uri-list")) {
71
+ const n = t.dataTransfer.getData("text/uri-list");
72
+ if (n.length > 0) {
73
+ const a = n.split(`
74
+ `).map((c) => w(c), e);
75
+ return Promise.all(a);
76
+ }
77
+ }
78
+ }
79
+ return [];
80
+ }
81
+ async function y(t, e = 224) {
82
+ return (await p(t, e)).map((r) => r.toDataURL());
83
+ }
84
+ export {
85
+ p as canvasFromDataTransfer,
86
+ m as canvasFromFile,
87
+ g as canvasFromImage,
88
+ w as canvasFromURL,
89
+ v as canvasesFromFiles,
90
+ f as cropTo,
91
+ y as urlFromDataTransfer
92
+ };
@@ -0,0 +1,7 @@
1
+ export declare function createAsym(): Promise<{
2
+ createSymCrypto: (rkey: string) => Promise<{
3
+ encrypt: (data: string) => Promise<[ArrayBuffer, Uint8Array]>;
4
+ decrypt: (data: ArrayBuffer, iv: Uint8Array) => Promise<string>;
5
+ }>;
6
+ publicKey: string;
7
+ }>;
@@ -0,0 +1,50 @@
1
+ function y(e) {
2
+ return new TextDecoder().decode(e);
3
+ }
4
+ function o(e) {
5
+ return new TextEncoder().encode(e);
6
+ }
7
+ async function s() {
8
+ const e = await crypto.subtle.generateKey(
9
+ {
10
+ name: "ECDH",
11
+ namedCurve: "P-384"
12
+ },
13
+ !0,
14
+ ["deriveKey", "deriveKey"]
15
+ );
16
+ return {
17
+ createSymCrypto: async (r) => {
18
+ const n = await crypto.subtle.importKey(
19
+ "jwk",
20
+ JSON.parse(r),
21
+ { name: "ECDH", namedCurve: "P-384" },
22
+ !1,
23
+ []
24
+ ), a = await crypto.subtle.deriveKey(
25
+ {
26
+ name: "ECDH",
27
+ public: n
28
+ },
29
+ e.privateKey,
30
+ {
31
+ name: "AES-GCM",
32
+ length: 256
33
+ },
34
+ !1,
35
+ ["encrypt", "decrypt"]
36
+ );
37
+ return {
38
+ encrypt: async (c) => {
39
+ const t = crypto.getRandomValues(new Uint8Array(12));
40
+ return [await crypto.subtle.encrypt({ name: "AES-GCM", iv: t }, a, o(c)), t];
41
+ },
42
+ decrypt: async (c, t) => y(await crypto.subtle.decrypt({ name: "AES-GCM", iv: t }, a, c))
43
+ };
44
+ },
45
+ publicKey: JSON.stringify(await crypto.subtle.exportKey("jwk", e.publicKey))
46
+ };
47
+ }
48
+ export {
49
+ s as createAsym
50
+ };
@@ -0,0 +1 @@
1
+ export default function randomId(length?: number): string;
@@ -0,0 +1,8 @@
1
+ const a = "0123456789";
2
+ function e(t = 8) {
3
+ const r = new Uint32Array(t);
4
+ return crypto.getRandomValues(r), Array.from(r).map((n) => a.charAt(n % a.length)).join("");
5
+ }
6
+ export {
7
+ e as default
8
+ };
@@ -0,0 +1,13 @@
1
+ import { default as JSZip } from 'jszip';
2
+ export declare function getZipBlob(content: string | ArrayBuffer | File, progress?: (percent: number) => void): Promise<Blob>;
3
+ export interface ZipData {
4
+ [key: string]: unknown;
5
+ images?: Map<string, string>;
6
+ }
7
+ export declare function loadZipFile(file: File | Blob | ArrayBuffer | string): Promise<ZipData>;
8
+ type ZipOutput<T extends JSZip.OutputType> = ReturnType<typeof JSZip.prototype.generateAsync<T>>;
9
+ export declare function createZip<T extends JSZip.OutputType>(type: T, data: ZipData): Promise<ZipOutput<T>>;
10
+ export declare function createZipBlob(data: ZipData): Promise<Blob>;
11
+ export declare function createZipArrayBuffer(data: ZipData): Promise<ArrayBuffer>;
12
+ export declare function saveZipFile(data: ZipData, name?: string): Promise<Blob>;
13
+ export {};
@@ -0,0 +1,94 @@
1
+ import { J as l, F as b } from "../FileSaver.min-DhePf63e.js";
2
+ async function m(n, e) {
3
+ if (typeof n == "string") {
4
+ e && e(0);
5
+ const i = await fetch(n);
6
+ if (i.status !== 200)
7
+ throw console.error(i), new Error("zip_fetch_failed");
8
+ const t = [];
9
+ if (i.body) {
10
+ const a = i.body.getReader(), f = parseInt(i.headers.get("Content-Length") || "1");
11
+ let s = 0;
12
+ for (; s < f; ) {
13
+ const { done: r, value: o } = await a.read();
14
+ if (r)
15
+ break;
16
+ t.push(o), s += o.length, e && e(Math.floor(s / f * 100));
17
+ }
18
+ }
19
+ return new Blob(t);
20
+ } else if (n instanceof File) {
21
+ const i = await n.arrayBuffer();
22
+ return e && e(100), new Blob([i]);
23
+ } else
24
+ return e && e(100), new Blob([n]);
25
+ }
26
+ async function h(n) {
27
+ const e = n instanceof Blob ? n : m(n), i = await l.loadAsync(e), t = {}, a = [];
28
+ return i.forEach((f, s) => {
29
+ if (/\.json$/.test(s.name))
30
+ a.push(
31
+ s.async("string").then((r) => {
32
+ const o = s.name.replace(".json", "");
33
+ t[o] = JSON.parse(r);
34
+ })
35
+ );
36
+ else if (/\.bin$/.test(s.name))
37
+ a.push(
38
+ s.async("arraybuffer").then((r) => {
39
+ const o = s.name.replace(".bin", "");
40
+ t[o] = r;
41
+ })
42
+ );
43
+ else {
44
+ const r = s.name.split("/");
45
+ if (r.length === 2 && r[1] && (r[0] === "images" || r[0] === "samples")) {
46
+ t.images = /* @__PURE__ */ new Map();
47
+ const o = r[1].split(".");
48
+ o.length === 2 && a.push(
49
+ s.async("base64").then((u) => {
50
+ var c;
51
+ (c = t.images) == null || c.set(
52
+ o[0],
53
+ `data:image/${o[1] === "png" ? "png" : "jpeg"};base64,${u}`
54
+ );
55
+ })
56
+ );
57
+ }
58
+ }
59
+ }), await Promise.all(a), t;
60
+ }
61
+ async function p(n, e) {
62
+ const i = new l();
63
+ if (e.images) {
64
+ const t = i.folder("images");
65
+ t && e.images.forEach((a, f) => {
66
+ const s = a.split(";base64,");
67
+ t.file(`${f}.${s[0] === "png" ? "png" : "jpg"}`, s[1], { base64: !0 });
68
+ });
69
+ }
70
+ for (const t in e) {
71
+ if (t === "images") continue;
72
+ const a = e[t];
73
+ a instanceof ArrayBuffer ? i.file(`${t}.bin`, a) : i.file(`${t}.json`, JSON.stringify(e[t], void 0, 4));
74
+ }
75
+ return i.generateAsync({ type: n });
76
+ }
77
+ async function y(n) {
78
+ return p("blob", n);
79
+ }
80
+ async function w(n) {
81
+ return p("arraybuffer", n);
82
+ }
83
+ async function B(n, e) {
84
+ const i = await y(n);
85
+ return b.saveAs(i, `${e || "data"}.zip`), i;
86
+ }
87
+ export {
88
+ p as createZip,
89
+ w as createZipArrayBuffer,
90
+ y as createZipBlob,
91
+ m as getZipBlob,
92
+ h as loadZipFile,
93
+ B as saveZipFile
94
+ };