@ztimson/momentum 0.28.3 → 0.28.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +251 -85
- package/dist/index.mjs +251 -85
- package/dist/ui.d.ts +1 -0
- package/dist/ui.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var a = (n, e, t) => (
|
|
7
|
-
function
|
|
4
|
+
var v = Object.defineProperty;
|
|
5
|
+
var F = (n, e, t) => e in n ? v(n, e, { enumerable: true, configurable: true, writable: true, value: t }) : n[e] = t;
|
|
6
|
+
var a = (n, e, t) => (F(n, typeof e != "symbol" ? e + "" : e, t), t);
|
|
7
|
+
function W(n, e = false) {
|
|
8
8
|
if (n == null)
|
|
9
9
|
throw new Error("Cannot clean a NULL value");
|
|
10
10
|
return Array.isArray(n) ? n = n.filter((t) => t != null) : Object.entries(n).forEach(([t, r]) => {
|
|
@@ -15,6 +15,13 @@ function b(n, e) {
|
|
|
15
15
|
const t = typeof n, r = typeof e;
|
|
16
16
|
return t != "object" || n == null || r != "object" || e == null ? t == "function" && r == "function" ? n.toString() == e.toString() : n === e : Object.keys(n).length != Object.keys(e).length ? false : Object.keys(n).every((s) => b(n[s], e[s]));
|
|
17
17
|
}
|
|
18
|
+
function q(n) {
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(n);
|
|
21
|
+
} catch {
|
|
22
|
+
return n;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
18
25
|
class E extends Promise {
|
|
19
26
|
constructor(t) {
|
|
20
27
|
super((r, o) => t(
|
|
@@ -52,15 +59,15 @@ class E extends Promise {
|
|
|
52
59
|
return this.from(super.finally(t));
|
|
53
60
|
}
|
|
54
61
|
}
|
|
55
|
-
function
|
|
62
|
+
function Z(n, e) {
|
|
56
63
|
const t = document.createElement("a");
|
|
57
64
|
t.href = n, t.download = e, document.body.appendChild(t), t.click(), document.body.removeChild(t);
|
|
58
65
|
}
|
|
59
|
-
function
|
|
66
|
+
function Bt(n, e) {
|
|
60
67
|
const t = URL.createObjectURL(n);
|
|
61
|
-
|
|
68
|
+
Z(t, e), URL.revokeObjectURL(t);
|
|
62
69
|
}
|
|
63
|
-
function
|
|
70
|
+
function bt(n = {}) {
|
|
64
71
|
return new Promise((e) => {
|
|
65
72
|
const t = document.createElement("input");
|
|
66
73
|
t.type = "file", t.accept = n.accept || "*", t.style.display = "none", t.multiple = !!n.multiple, t.onblur = t.onchange = async () => {
|
|
@@ -68,13 +75,13 @@ function xt(n = {}) {
|
|
|
68
75
|
}, document.body.appendChild(t), t.click();
|
|
69
76
|
});
|
|
70
77
|
}
|
|
71
|
-
function
|
|
78
|
+
function Rt(n) {
|
|
72
79
|
return new E((e, t, r) => {
|
|
73
80
|
const o = new XMLHttpRequest(), s = new FormData();
|
|
74
|
-
n.files.forEach((i) => s.append("file", i)), o.withCredentials = !!n.withCredentials, o.upload.addEventListener("progress", (i) => i.lengthComputable ? r(i.loaded / i.total) : null), o.
|
|
81
|
+
n.files.forEach((i) => s.append("file", i)), o.withCredentials = !!n.withCredentials, o.upload.addEventListener("progress", (i) => i.lengthComputable ? r(i.loaded / i.total) : null), o.addEventListener("loadend", () => e(q(o.responseText))), o.addEventListener("error", () => t(q(o.responseText))), o.addEventListener("timeout", () => t({ error: "Request timed out" })), o.open("POST", n.url), Object.entries(n.headers || {}).forEach(([i, p]) => o.setRequestHeader(i, p)), o.send(s);
|
|
75
82
|
});
|
|
76
83
|
}
|
|
77
|
-
class
|
|
84
|
+
class H {
|
|
78
85
|
constructor() {
|
|
79
86
|
a(this, "listeners", {});
|
|
80
87
|
}
|
|
@@ -115,7 +122,7 @@ class P {
|
|
|
115
122
|
});
|
|
116
123
|
}
|
|
117
124
|
}
|
|
118
|
-
a(
|
|
125
|
+
a(H, "listeners", {});
|
|
119
126
|
class w extends Error {
|
|
120
127
|
constructor(t, r) {
|
|
121
128
|
super(t);
|
|
@@ -144,7 +151,7 @@ class w extends Error {
|
|
|
144
151
|
}
|
|
145
152
|
}
|
|
146
153
|
a(w, "code", 500);
|
|
147
|
-
class
|
|
154
|
+
class X extends w {
|
|
148
155
|
constructor(e = "Bad Request") {
|
|
149
156
|
super(e);
|
|
150
157
|
}
|
|
@@ -152,8 +159,8 @@ class Z extends w {
|
|
|
152
159
|
return e.constructor.code == this.code;
|
|
153
160
|
}
|
|
154
161
|
}
|
|
155
|
-
a(
|
|
156
|
-
class
|
|
162
|
+
a(X, "code", 400);
|
|
163
|
+
class Q extends w {
|
|
157
164
|
constructor(e = "Unauthorized") {
|
|
158
165
|
super(e);
|
|
159
166
|
}
|
|
@@ -161,8 +168,8 @@ class X extends w {
|
|
|
161
168
|
return e.constructor.code == this.code;
|
|
162
169
|
}
|
|
163
170
|
}
|
|
164
|
-
a(
|
|
165
|
-
class
|
|
171
|
+
a(Q, "code", 401);
|
|
172
|
+
class _ extends w {
|
|
166
173
|
constructor(e = "Forbidden") {
|
|
167
174
|
super(e);
|
|
168
175
|
}
|
|
@@ -170,8 +177,8 @@ class Q extends w {
|
|
|
170
177
|
return e.constructor.code == this.code;
|
|
171
178
|
}
|
|
172
179
|
}
|
|
173
|
-
a(
|
|
174
|
-
class
|
|
180
|
+
a(_, "code", 403);
|
|
181
|
+
class tt extends w {
|
|
175
182
|
constructor(e = "Not Found") {
|
|
176
183
|
super(e);
|
|
177
184
|
}
|
|
@@ -179,8 +186,8 @@ class _ extends w {
|
|
|
179
186
|
return e.constructor.code == this.code;
|
|
180
187
|
}
|
|
181
188
|
}
|
|
182
|
-
a(
|
|
183
|
-
class
|
|
189
|
+
a(tt, "code", 404);
|
|
190
|
+
class et extends w {
|
|
184
191
|
constructor(e = "Internal Server Error") {
|
|
185
192
|
super(e);
|
|
186
193
|
}
|
|
@@ -188,7 +195,7 @@ class tt extends w {
|
|
|
188
195
|
return e.constructor.code == this.code;
|
|
189
196
|
}
|
|
190
197
|
}
|
|
191
|
-
a(
|
|
198
|
+
a(et, "code", 500);
|
|
192
199
|
const g = class g2 {
|
|
193
200
|
constructor(e = {}) {
|
|
194
201
|
a(this, "interceptors", {});
|
|
@@ -217,36 +224,36 @@ const g = class g2 {
|
|
|
217
224
|
const s = Array.isArray(e.query) ? e.query : Object.keys(e.query).map((i) => ({ key: i, value: e.query[i] }));
|
|
218
225
|
t += (t.includes("?") ? "&" : "?") + s.map((i) => `${i.key}=${i.value}`).join("&");
|
|
219
226
|
}
|
|
220
|
-
const r =
|
|
227
|
+
const r = W({
|
|
221
228
|
"Content-Type": e.body ? e.body instanceof FormData ? "multipart/form-data" : "application/json" : void 0,
|
|
222
229
|
...g2.headers,
|
|
223
230
|
...this.headers,
|
|
224
231
|
...e.headers
|
|
225
232
|
});
|
|
226
|
-
return typeof e.body == "object" && e.body != null && r["Content-Type"] == "application/json" && (e.body = JSON.stringify(e.body)), new E((s, i,
|
|
233
|
+
return typeof e.body == "object" && e.body != null && r["Content-Type"] == "application/json" && (e.body = JSON.stringify(e.body)), new E((s, i, p) => {
|
|
227
234
|
fetch(t, {
|
|
228
235
|
headers: r,
|
|
229
236
|
method: e.method || (e.body ? "POST" : "GET"),
|
|
230
237
|
body: e.body
|
|
231
238
|
}).then(async (c) => {
|
|
232
|
-
var
|
|
239
|
+
var j, G;
|
|
233
240
|
for (let u of [...Object.values(g2.interceptors), ...Object.values(this.interceptors)])
|
|
234
|
-
await new Promise((
|
|
241
|
+
await new Promise((O) => u(c, () => O()));
|
|
235
242
|
const R = c.headers.get("Content-Length"), N = R ? parseInt(R, 10) : 0;
|
|
236
|
-
let
|
|
237
|
-
const
|
|
243
|
+
let k = 0;
|
|
244
|
+
const T = (j = c.body) == null ? void 0 : j.getReader(), Y = new ReadableStream({
|
|
238
245
|
start(u) {
|
|
239
|
-
function
|
|
240
|
-
|
|
246
|
+
function O() {
|
|
247
|
+
T == null || T.read().then((x) => {
|
|
241
248
|
if (x.done)
|
|
242
249
|
return u.close();
|
|
243
|
-
|
|
250
|
+
k += x.value.byteLength, p(k / N), u.enqueue(x.value), O();
|
|
244
251
|
}).catch((x) => u.error(x));
|
|
245
252
|
}
|
|
246
|
-
|
|
253
|
+
O();
|
|
247
254
|
}
|
|
248
255
|
});
|
|
249
|
-
if (c.data = new Response(
|
|
256
|
+
if (c.data = new Response(Y), e.decode == null || e.decode) {
|
|
250
257
|
const u = (G = c.headers.get("Content-Type")) == null ? void 0 : G.toLowerCase();
|
|
251
258
|
u != null && u.includes("form") ? c.data = await c.data.formData() : u != null && u.includes("json") ? c.data = await c.data.json() : u != null && u.includes("text") ? c.data = await c.data.text() : u != null && u.includes("application") && (c.data = await c.data.blob());
|
|
252
259
|
}
|
|
@@ -265,7 +272,7 @@ const A = {
|
|
|
265
272
|
BLINK: "\x1B[5m",
|
|
266
273
|
REVERSE: "\x1B[7m",
|
|
267
274
|
HIDDEN: "\x1B[8m"
|
|
268
|
-
},
|
|
275
|
+
}, L = {
|
|
269
276
|
BLACK: "\x1B[30m",
|
|
270
277
|
RED: "\x1B[31m",
|
|
271
278
|
GREEN: "\x1B[32m",
|
|
@@ -283,8 +290,8 @@ const A = {
|
|
|
283
290
|
LIGHT_CYAN: "\x1B[96m",
|
|
284
291
|
WHITE: "\x1B[97m"
|
|
285
292
|
};
|
|
286
|
-
var
|
|
287
|
-
const
|
|
293
|
+
var nt = /* @__PURE__ */ ((n) => (n[n.ERROR = 0] = "ERROR", n[n.WARN = 1] = "WARN", n[n.INFO = 2] = "INFO", n[n.LOG = 3] = "LOG", n[n.DEBUG = 4] = "DEBUG", n))(nt || {});
|
|
294
|
+
const y = class y2 extends H {
|
|
288
295
|
constructor(e) {
|
|
289
296
|
super(), this.namespace = e;
|
|
290
297
|
}
|
|
@@ -292,50 +299,50 @@ const p = class p2 extends P {
|
|
|
292
299
|
const s = e.toString(), i = t - s.length;
|
|
293
300
|
if (i <= 0)
|
|
294
301
|
return s;
|
|
295
|
-
const
|
|
296
|
-
return o ? s +
|
|
302
|
+
const p = Array(~~(i / r.length)).fill(r).join("");
|
|
303
|
+
return o ? s + p : p + s;
|
|
297
304
|
}
|
|
298
305
|
format(...e) {
|
|
299
306
|
const t = /* @__PURE__ */ new Date();
|
|
300
307
|
return `${`${t.getFullYear()}-${t.getMonth() + 1}-${t.getDate()} ${this.pad(t.getHours().toString(), 2, "0")}:${this.pad(t.getMinutes().toString(), 2, "0")}:${this.pad(t.getSeconds().toString(), 2, "0")}.${this.pad(t.getMilliseconds().toString(), 3, "0", true)}`}${this.namespace ? ` [${this.namespace}]` : ""} ${e.join(" ")}`;
|
|
301
308
|
}
|
|
302
309
|
debug(...e) {
|
|
303
|
-
if (
|
|
310
|
+
if (y2.LOG_LEVEL < 4)
|
|
304
311
|
return;
|
|
305
312
|
const t = this.format(...e);
|
|
306
|
-
|
|
313
|
+
y2.emit(4, t), console.debug(L.LIGHT_GREY + t + A.CLEAR);
|
|
307
314
|
}
|
|
308
315
|
log(...e) {
|
|
309
|
-
if (
|
|
316
|
+
if (y2.LOG_LEVEL < 3)
|
|
310
317
|
return;
|
|
311
318
|
const t = this.format(...e);
|
|
312
|
-
|
|
319
|
+
y2.emit(3, t), console.log(A.CLEAR + t);
|
|
313
320
|
}
|
|
314
321
|
info(...e) {
|
|
315
|
-
if (
|
|
322
|
+
if (y2.LOG_LEVEL < 2)
|
|
316
323
|
return;
|
|
317
324
|
const t = this.format(...e);
|
|
318
|
-
|
|
325
|
+
y2.emit(2, t), console.info(L.BLUE + t + A.CLEAR);
|
|
319
326
|
}
|
|
320
327
|
warn(...e) {
|
|
321
|
-
if (
|
|
328
|
+
if (y2.LOG_LEVEL < 1)
|
|
322
329
|
return;
|
|
323
330
|
const t = this.format(...e);
|
|
324
|
-
|
|
331
|
+
y2.emit(1, t), console.warn(L.YELLOW + t + A.CLEAR);
|
|
325
332
|
}
|
|
326
333
|
error(...e) {
|
|
327
|
-
if (
|
|
334
|
+
if (y2.LOG_LEVEL < 0)
|
|
328
335
|
return;
|
|
329
336
|
const t = this.format(...e);
|
|
330
|
-
|
|
337
|
+
y2.emit(0, t), console.error(L.RED + t + A.CLEAR);
|
|
331
338
|
}
|
|
332
339
|
};
|
|
333
|
-
a(
|
|
340
|
+
a(y, "LOG_LEVEL", 4);
|
|
334
341
|
class Api extends M {
|
|
335
342
|
constructor(url = location.origin, opts = {}) {
|
|
336
343
|
opts.url = url;
|
|
337
344
|
super(opts);
|
|
338
|
-
__publicField(this, "emitter", new
|
|
345
|
+
__publicField(this, "emitter", new H());
|
|
339
346
|
__publicField(this, "_token", null);
|
|
340
347
|
__publicField(this, "emit", this.emitter.emit.bind(this.emitter));
|
|
341
348
|
__publicField(this, "off", this.emitter.off.bind(this.emitter));
|
|
@@ -373,7 +380,7 @@ var extendStatics = function(d, b2) {
|
|
|
373
380
|
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b3) {
|
|
374
381
|
d2.__proto__ = b3;
|
|
375
382
|
} || function(d2, b3) {
|
|
376
|
-
for (var
|
|
383
|
+
for (var p in b3) if (Object.prototype.hasOwnProperty.call(b3, p)) d2[p] = b3[p];
|
|
377
384
|
};
|
|
378
385
|
return extendStatics(d, b2);
|
|
379
386
|
};
|
|
@@ -1085,7 +1092,7 @@ var ActionType = /* @__PURE__ */ ((ActionType2) => {
|
|
|
1085
1092
|
ActionType2[ActionType2["PUT"] = 6] = "PUT";
|
|
1086
1093
|
return ActionType2;
|
|
1087
1094
|
})(ActionType || {});
|
|
1088
|
-
class Actions extends
|
|
1095
|
+
class Actions extends H {
|
|
1089
1096
|
constructor(api) {
|
|
1090
1097
|
super();
|
|
1091
1098
|
__publicField(this, "api");
|
|
@@ -1151,13 +1158,13 @@ class Totp {
|
|
|
1151
1158
|
return this.api.request({ url: `/api/auth/totp/${username}`, method: "POST" });
|
|
1152
1159
|
}
|
|
1153
1160
|
setup(username, method = "app", totp) {
|
|
1154
|
-
return this.api.request({ url: `/api/auth/totp/${username}`, body:
|
|
1161
|
+
return this.api.request({ url: `/api/auth/totp/${username}`, body: W({
|
|
1155
1162
|
method,
|
|
1156
1163
|
totp
|
|
1157
1164
|
}) });
|
|
1158
1165
|
}
|
|
1159
1166
|
}
|
|
1160
|
-
class Auth extends
|
|
1167
|
+
class Auth extends H {
|
|
1161
1168
|
constructor(api, opts) {
|
|
1162
1169
|
var _a;
|
|
1163
1170
|
super();
|
|
@@ -1288,7 +1295,7 @@ class Auth extends P {
|
|
|
1288
1295
|
});
|
|
1289
1296
|
}
|
|
1290
1297
|
}
|
|
1291
|
-
class Data extends
|
|
1298
|
+
class Data extends H {
|
|
1292
1299
|
constructor(api) {
|
|
1293
1300
|
super();
|
|
1294
1301
|
__publicField(this, "api");
|
|
@@ -1330,7 +1337,7 @@ class Data extends P {
|
|
|
1330
1337
|
});
|
|
1331
1338
|
}
|
|
1332
1339
|
}
|
|
1333
|
-
class Email extends
|
|
1340
|
+
class Email extends H {
|
|
1334
1341
|
constructor(api) {
|
|
1335
1342
|
super();
|
|
1336
1343
|
__publicField(this, "api");
|
|
@@ -1345,7 +1352,7 @@ class Email extends P {
|
|
|
1345
1352
|
});
|
|
1346
1353
|
}
|
|
1347
1354
|
}
|
|
1348
|
-
class Groups extends
|
|
1355
|
+
class Groups extends H {
|
|
1349
1356
|
constructor(api) {
|
|
1350
1357
|
super();
|
|
1351
1358
|
__publicField(this, "api");
|
|
@@ -1427,32 +1434,32 @@ class Logger {
|
|
|
1427
1434
|
return this.api.request({ url: `/api/logs/server${query ? `?${query}` : ""}` }).then((resp) => resp);
|
|
1428
1435
|
}
|
|
1429
1436
|
debug(...logs) {
|
|
1430
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(
|
|
1437
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(nt.DEBUG, logs) }).then(() => {
|
|
1431
1438
|
}).catch(() => {
|
|
1432
1439
|
});
|
|
1433
1440
|
}
|
|
1434
1441
|
log(...logs) {
|
|
1435
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(
|
|
1442
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(nt.LOG, logs) }).then(() => {
|
|
1436
1443
|
}).catch(() => {
|
|
1437
1444
|
});
|
|
1438
1445
|
}
|
|
1439
1446
|
info(...logs) {
|
|
1440
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(
|
|
1447
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(nt.INFO, logs) }).then(() => {
|
|
1441
1448
|
}).catch(() => {
|
|
1442
1449
|
});
|
|
1443
1450
|
}
|
|
1444
1451
|
warn(...logs) {
|
|
1445
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(
|
|
1452
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(nt.WARN, logs) }).then(() => {
|
|
1446
1453
|
}).catch(() => {
|
|
1447
1454
|
});
|
|
1448
1455
|
}
|
|
1449
1456
|
error(...logs) {
|
|
1450
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(
|
|
1457
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(nt.ERROR, logs) }).then(() => {
|
|
1451
1458
|
}).catch(() => {
|
|
1452
1459
|
});
|
|
1453
1460
|
}
|
|
1454
1461
|
}
|
|
1455
|
-
class Payments extends
|
|
1462
|
+
class Payments extends H {
|
|
1456
1463
|
constructor(api, secret) {
|
|
1457
1464
|
super();
|
|
1458
1465
|
__publicField(this, "api");
|
|
@@ -1493,7 +1500,7 @@ class Payments extends P {
|
|
|
1493
1500
|
return history;
|
|
1494
1501
|
}
|
|
1495
1502
|
}
|
|
1496
|
-
class Pdf extends
|
|
1503
|
+
class Pdf extends H {
|
|
1497
1504
|
constructor(api) {
|
|
1498
1505
|
super();
|
|
1499
1506
|
__publicField(this, "api");
|
|
@@ -1503,7 +1510,7 @@ class Pdf extends P {
|
|
|
1503
1510
|
const blob = await resp.blob();
|
|
1504
1511
|
if (fileName) {
|
|
1505
1512
|
const url = URL.createObjectURL(blob);
|
|
1506
|
-
|
|
1513
|
+
Z(url, fileName.endsWith(".pdf") ? fileName : fileName + ".pdf");
|
|
1507
1514
|
URL.revokeObjectURL(url);
|
|
1508
1515
|
}
|
|
1509
1516
|
this.emit("CREATE", blob);
|
|
@@ -1566,7 +1573,7 @@ const _Socket = class _Socket {
|
|
|
1566
1573
|
};
|
|
1567
1574
|
__publicField(_Socket, "timeout", 1e4);
|
|
1568
1575
|
let Socket = _Socket;
|
|
1569
|
-
class Storage extends
|
|
1576
|
+
class Storage extends H {
|
|
1570
1577
|
constructor(api) {
|
|
1571
1578
|
super();
|
|
1572
1579
|
__publicField(this, "api");
|
|
@@ -1586,37 +1593,37 @@ class Storage extends P {
|
|
|
1586
1593
|
});
|
|
1587
1594
|
}
|
|
1588
1595
|
open(path, target = "_blank") {
|
|
1589
|
-
const
|
|
1590
|
-
const link = `${this.api.url}${
|
|
1596
|
+
const p = (path.startsWith("/api/storage/") ? path : "/api/storage/" + path).replaceAll(/\/{2,}/g, "/");
|
|
1597
|
+
const link = `${this.api.url}${p}${this.api.token ? `?token=${this.api.token}` : ""}`;
|
|
1591
1598
|
if (!target) return link;
|
|
1592
1599
|
this.emit("OPEN", path);
|
|
1593
1600
|
return window.open(link, target);
|
|
1594
1601
|
}
|
|
1595
1602
|
mkdir(path) {
|
|
1596
|
-
const
|
|
1597
|
-
return this.api.request({ url:
|
|
1603
|
+
const p = (path.startsWith("/api/storage/") ? path : "/api/storage/" + path).replaceAll(/\/{2,}/g, "/");
|
|
1604
|
+
return this.api.request({ url: p + "?directory", method: "POST" });
|
|
1598
1605
|
}
|
|
1599
1606
|
download(path, opts = {}) {
|
|
1600
|
-
const
|
|
1601
|
-
return this.api.request({ ...opts, url:
|
|
1607
|
+
const p = ("/api/storage/" + path).replaceAll("//", "/");
|
|
1608
|
+
return this.api.request({ ...opts, url: p, decode: false }).then(async (response) => {
|
|
1602
1609
|
const blob = await response.blob();
|
|
1603
1610
|
const name = opts.downloadAs || new URL(path).pathname.split("/").pop();
|
|
1604
1611
|
this.emit("DOWNLOAD", path, blob);
|
|
1605
|
-
|
|
1612
|
+
Bt(blob, name);
|
|
1606
1613
|
return response;
|
|
1607
1614
|
});
|
|
1608
1615
|
}
|
|
1609
1616
|
upload(files, opts = "") {
|
|
1610
1617
|
return new E(async (res, rej, prog) => {
|
|
1611
|
-
if (!files) files = await
|
|
1618
|
+
if (!files) files = await bt();
|
|
1612
1619
|
if (!files || Array.isArray(files) && !files.length) return [];
|
|
1613
1620
|
const url = this.api.url + ("/api/storage/" + (typeof opts == "string" ? opts : opts == null ? void 0 : opts.path)).replaceAll("//", "/");
|
|
1614
|
-
return
|
|
1621
|
+
return Rt({
|
|
1615
1622
|
url,
|
|
1616
1623
|
files: Array.isArray(files) ? files : [files],
|
|
1617
1624
|
headers: this.api.headers
|
|
1618
|
-
}).onProgress((
|
|
1619
|
-
prog(
|
|
1625
|
+
}).onProgress((p) => {
|
|
1626
|
+
prog(p);
|
|
1620
1627
|
}).then((resp) => {
|
|
1621
1628
|
this.emit("UPLOAD", resp);
|
|
1622
1629
|
res(resp);
|
|
@@ -1630,6 +1637,36 @@ class UI {
|
|
|
1630
1637
|
}
|
|
1631
1638
|
async inject(reload = false) {
|
|
1632
1639
|
if (!Object.keys(this.settings.cache).length || reload) await this.settings.list();
|
|
1640
|
+
if (!document.querySelector('meta[name="apple-mobile-web-app-capable"]')) {
|
|
1641
|
+
const meta = document.createElement("meta");
|
|
1642
|
+
meta.name = "apple-mobile-web-app-capable";
|
|
1643
|
+
meta.content = "yes";
|
|
1644
|
+
document.head.append(meta);
|
|
1645
|
+
}
|
|
1646
|
+
if (!document.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]')) {
|
|
1647
|
+
const meta = document.createElement("meta");
|
|
1648
|
+
meta.name = "apple-mobile-web-app-status-bar-style";
|
|
1649
|
+
meta.content = "default";
|
|
1650
|
+
document.head.append(meta);
|
|
1651
|
+
}
|
|
1652
|
+
if (!document.querySelector('meta[name="apple-mobile-web-app-title"]')) {
|
|
1653
|
+
const meta = document.createElement("meta");
|
|
1654
|
+
meta.name = "apple-mobile-web-app-title";
|
|
1655
|
+
meta.content = this.settings.cache.title;
|
|
1656
|
+
document.head.append(meta);
|
|
1657
|
+
}
|
|
1658
|
+
if (!document.querySelector('link[rel="apple-touch-icon"]')) {
|
|
1659
|
+
const meta = document.createElement("link");
|
|
1660
|
+
meta.rel = "apple-touch-icon";
|
|
1661
|
+
meta.href = this.settings.cache.logo;
|
|
1662
|
+
document.head.append(meta);
|
|
1663
|
+
}
|
|
1664
|
+
if (!document.querySelector('link[rel="apple-touch-startup-image"]')) {
|
|
1665
|
+
const meta = document.createElement("link");
|
|
1666
|
+
meta.rel = "apple-touch-startup-image";
|
|
1667
|
+
meta.href = this.settings.cache.logo;
|
|
1668
|
+
document.head.append(meta);
|
|
1669
|
+
}
|
|
1633
1670
|
window.document.body.classList.add(this.settings.cache.theme.darkMode ? "theme-dark" : "theme-light");
|
|
1634
1671
|
window.document.body.classList.remove(this.settings.cache.theme.darkMode ? "theme-light" : "theme-dark");
|
|
1635
1672
|
if (this.settings.cache.title)
|
|
@@ -1666,10 +1703,139 @@ class UI {
|
|
|
1666
1703
|
link.setAttribute("rel", "manifest");
|
|
1667
1704
|
link.setAttribute("href", this.settings.api.url + "/manifest.json");
|
|
1668
1705
|
window.document.head.append(link);
|
|
1706
|
+
this.iosPrompt();
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
iosPrompt() {
|
|
1710
|
+
const url = this.settings.api.url;
|
|
1711
|
+
const settings = this.settings.cache;
|
|
1712
|
+
let dismissed = !!localStorage.getItem("ios-prompt");
|
|
1713
|
+
const ios = /iPad|iPhone|iPod/.test(navigator.platform) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1;
|
|
1714
|
+
const pwa = window.matchMedia("(display-mode: standalone)").matches || (navigator == null ? void 0 : navigator.standalone) || document.referrer.includes("android-app://");
|
|
1715
|
+
function open() {
|
|
1716
|
+
let style = document.querySelector("style.ios-prompt");
|
|
1717
|
+
if (!style) {
|
|
1718
|
+
style = document.createElement("style");
|
|
1719
|
+
style.innerHTML = `
|
|
1720
|
+
.ios-prompt-backdrop {
|
|
1721
|
+
position: fixed;
|
|
1722
|
+
display: relative;
|
|
1723
|
+
left: 0;
|
|
1724
|
+
top: 0;
|
|
1725
|
+
right: 0;
|
|
1726
|
+
bottom: 0;
|
|
1727
|
+
background: rgba(0,0,0,.5);
|
|
1728
|
+
z-index: 9999;
|
|
1729
|
+
animation: fadeIn 0.5s ease-in-out forwards;
|
|
1730
|
+
opacity: 0;
|
|
1731
|
+
}
|
|
1732
|
+
.ios-prompt-backdrop.exit {
|
|
1733
|
+
animation: fadeOut 0.5s ease-in-out forwards !important;
|
|
1734
|
+
}
|
|
1735
|
+
.ios-prompt {
|
|
1736
|
+
position: fixed;
|
|
1737
|
+
background: #fff;
|
|
1738
|
+
color: black;
|
|
1739
|
+
bottom: 0;
|
|
1740
|
+
left: 50%;
|
|
1741
|
+
width: min(100vw, 450px);
|
|
1742
|
+
transform: translate(-50%, 0);
|
|
1743
|
+
animation: slideUp 0.5s ease-in-out forwards;
|
|
1744
|
+
}
|
|
1745
|
+
.ios-prompt.exit {
|
|
1746
|
+
animation: slideDown 0.5s ease-in-out forwards !important;
|
|
1747
|
+
}
|
|
1748
|
+
.ios-prompt img {
|
|
1749
|
+
width: 18px;
|
|
1750
|
+
height: 18px;
|
|
1751
|
+
}
|
|
1752
|
+
.ios-prompt h1 {
|
|
1753
|
+
font-size: 1.25rem;
|
|
1754
|
+
font-weight: bold;
|
|
1755
|
+
}
|
|
1756
|
+
.ios-prompt-close {
|
|
1757
|
+
position: absolute;
|
|
1758
|
+
right: 5px;
|
|
1759
|
+
top: 10px;
|
|
1760
|
+
background: transparent;
|
|
1761
|
+
border: none;
|
|
1762
|
+
cursor: pointer;
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1765
|
+
@keyframes fadeIn {
|
|
1766
|
+
from { opacity: 0; }
|
|
1767
|
+
to { opacity: 1; }
|
|
1768
|
+
}
|
|
1769
|
+
@keyframes fadeOut {
|
|
1770
|
+
from { opacity: 1; }
|
|
1771
|
+
to { opacity: 0; }
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1774
|
+
@keyframes slideUp {
|
|
1775
|
+
from { transform: translate(-50%, 100%); }
|
|
1776
|
+
to { transform: translate(-50%, 0); }
|
|
1777
|
+
}
|
|
1778
|
+
@keyframes slideDown {
|
|
1779
|
+
from { transform: translate(-50%, 0); }
|
|
1780
|
+
to { transform: translate(-50%, 100%); }
|
|
1781
|
+
}
|
|
1782
|
+
`;
|
|
1783
|
+
document.head.append(style);
|
|
1784
|
+
}
|
|
1785
|
+
const backdrop = document.createElement("div");
|
|
1786
|
+
backdrop.classList.add("ios-prompt-backdrop");
|
|
1787
|
+
const prompt = document.createElement("div");
|
|
1788
|
+
prompt.classList.add("ios-prompt");
|
|
1789
|
+
prompt.innerHTML = `
|
|
1790
|
+
<div style="display: flex; padding: 1rem; align-items: center">
|
|
1791
|
+
<img src="${url}${settings.logo}" alt="Logo" style="height: 30px; width: auto; margin-right: .5rem;" />
|
|
1792
|
+
<h1 style="margin: 0">Install ${settings.title}</h1>
|
|
1793
|
+
</div>
|
|
1794
|
+
<div style="display: flex; flex-direction: column; align-items: center">
|
|
1795
|
+
<div style="border-top: 2px solid #00000020; border-bottom: 2px solid #00000020; padding: 0 1rem">
|
|
1796
|
+
<p style="margin-top: 1rem; text-align: center">This website can be installed as an App! Add it to your home screen for quick access & fullscreen use.</p>
|
|
1797
|
+
</div>
|
|
1798
|
+
<table style="margin: 1.5rem 0">
|
|
1799
|
+
<tr>
|
|
1800
|
+
<td style="width: 50px">
|
|
1801
|
+
<svg viewBox="0 0 566 670" xmlns="http://www.w3.org/2000/svg" fill="#0B76FC" height="40px"><path d="M255 12c4-4 10-8 16-8s12 3 16 8l94 89c3 4 6 7 8 12 2 6 0 14-5 19-7 8-20 9-28 2l-7-7-57-60 2 54v276c0 12-10 22-22 22-12 1-24-10-23-22V110l1-43-60 65c-5 5-13 8-21 6a19 19 0 0 1-16-17c-1-7 2-13 7-18l95-91z" /><path d="M43 207c16-17 40-23 63-23h83v46h-79c-12 0-25 3-33 13-8 9-10 21-10 33v260c0 13 0 27 6 38 5 12 18 18 30 19l14 1h302c14 0 28 0 40-8 11-7 16-21 16-34V276c0-11-2-24-9-33-8-10-22-13-34-13h-78v-46h75c13 0 25 1 37 4 16 4 31 13 41 27 11 17 14 37 14 57v280c0 20-3 41-15 58a71 71 0 0 1-45 27c-11 2-23 3-34 3H109c-19-1-40-4-56-15-14-9-23-23-27-38-4-12-5-25-5-38V270c1-22 6-47 22-63z" /></svg>
|
|
1802
|
+
</td>
|
|
1803
|
+
<td>
|
|
1804
|
+
<p style="margin: 1rem 0">1) Press the "Share" button</p>
|
|
1805
|
+
</td>
|
|
1806
|
+
</tr>
|
|
1807
|
+
<tr>
|
|
1808
|
+
<td>
|
|
1809
|
+
<svg viewBox="0 0 578 584" xmlns="http://www.w3.org/2000/svg" fill="black" height="34px"><path d="M101 35l19-1h333c12 0 23 0 35 3 17 3 34 12 44 27 13 16 16 38 16 58v329c0 19 0 39-8 57a65 65 0 0 1-37 37c-18 7-38 7-57 7H130c-21 1-44 0-63-10-14-7-25-20-30-34-6-15-8-30-8-45V121c1-21 5-44 19-61 13-16 33-23 53-25m7 46c-10 1-19 6-24 14-7 8-9 20-9 31v334c0 12 2 25 10 34 9 10 23 12 35 12h336c14 1 30-3 38-15 6-9 8-20 8-31V125c0-12-2-24-10-33-9-9-22-12-35-12H121l-13 1z" /><path d="M271 161c9-11 31-10 38 4 3 5 3 11 3 17v87h88c7 0 16 1 21 7 6 6 7 14 6 22a21 21 0 0 1-10 14c-5 4-11 5-17 5h-88v82c0 7-1 15-6 20-10 10-29 10-37-2-3-6-4-13-4-19v-81h-87c-8-1-17-3-23-9-5-6-6-15-4-22a21 21 0 0 1 11-14c6-3 13-3 19-3h84v-88c0-7 1-14 6-20z" /></svg>
|
|
1810
|
+
</td>
|
|
1811
|
+
<td>
|
|
1812
|
+
<p style="margin: 1rem 0">2) Press "Add to Home Screen"</p>
|
|
1813
|
+
</td>
|
|
1814
|
+
</tr>
|
|
1815
|
+
</table>
|
|
1816
|
+
</div>`;
|
|
1817
|
+
const close = document.createElement("button");
|
|
1818
|
+
close.classList.add("ios-prompt-close");
|
|
1819
|
+
close.innerText = "X";
|
|
1820
|
+
close.onclick = () => {
|
|
1821
|
+
prompt.classList.add("exit");
|
|
1822
|
+
backdrop.classList.add("exit");
|
|
1823
|
+
localStorage.setItem("ios-prompt", "dismissed");
|
|
1824
|
+
setTimeout(() => {
|
|
1825
|
+
prompt.remove();
|
|
1826
|
+
backdrop.remove();
|
|
1827
|
+
}, 500);
|
|
1828
|
+
};
|
|
1829
|
+
prompt.append(close);
|
|
1830
|
+
backdrop.append(prompt);
|
|
1831
|
+
document.body.append(backdrop);
|
|
1669
1832
|
}
|
|
1833
|
+
setTimeout(() => {
|
|
1834
|
+
if (ios && !dismissed && !pwa) open();
|
|
1835
|
+
}, 1e3);
|
|
1670
1836
|
}
|
|
1671
1837
|
}
|
|
1672
|
-
class Users extends
|
|
1838
|
+
class Users extends H {
|
|
1673
1839
|
constructor(api) {
|
|
1674
1840
|
super();
|
|
1675
1841
|
__publicField(this, "api");
|
|
@@ -1734,7 +1900,7 @@ class Users extends P {
|
|
|
1734
1900
|
});
|
|
1735
1901
|
}
|
|
1736
1902
|
uploadImage(username, file) {
|
|
1737
|
-
return
|
|
1903
|
+
return Rt({
|
|
1738
1904
|
url: this.api.url + `/api/users/${username}/image`,
|
|
1739
1905
|
files: [file],
|
|
1740
1906
|
headers: this.api.headers
|
|
@@ -1744,7 +1910,7 @@ class Users extends P {
|
|
|
1744
1910
|
});
|
|
1745
1911
|
}
|
|
1746
1912
|
}
|
|
1747
|
-
class Settings extends
|
|
1913
|
+
class Settings extends H {
|
|
1748
1914
|
constructor(api) {
|
|
1749
1915
|
super();
|
|
1750
1916
|
__publicField(this, "api");
|
|
@@ -1786,7 +1952,7 @@ class Settings extends P {
|
|
|
1786
1952
|
});
|
|
1787
1953
|
}
|
|
1788
1954
|
}
|
|
1789
|
-
class Static extends
|
|
1955
|
+
class Static extends H {
|
|
1790
1956
|
constructor(api) {
|
|
1791
1957
|
super();
|
|
1792
1958
|
__publicField(this, "api");
|
|
@@ -1806,12 +1972,12 @@ class Static extends P {
|
|
|
1806
1972
|
}
|
|
1807
1973
|
upload(files, path = "/") {
|
|
1808
1974
|
return new E(async (res, rej, prog) => {
|
|
1809
|
-
return
|
|
1975
|
+
return Rt({
|
|
1810
1976
|
url: this.api.url + ("/api/static/" + path).replaceAll("//", "/"),
|
|
1811
1977
|
files: Array.isArray(files) ? files : [files],
|
|
1812
1978
|
headers: this.api.headers
|
|
1813
|
-
}).onProgress((
|
|
1814
|
-
prog(
|
|
1979
|
+
}).onProgress((p) => {
|
|
1980
|
+
prog(p);
|
|
1815
1981
|
}).then((resp) => {
|
|
1816
1982
|
this.emit("UPLOAD", resp);
|
|
1817
1983
|
res(resp);
|
|
@@ -1819,7 +1985,7 @@ class Static extends P {
|
|
|
1819
1985
|
});
|
|
1820
1986
|
}
|
|
1821
1987
|
}
|
|
1822
|
-
class Momentum extends
|
|
1988
|
+
class Momentum extends H {
|
|
1823
1989
|
constructor(url, opts) {
|
|
1824
1990
|
super();
|
|
1825
1991
|
__publicField(this, "api");
|
package/dist/ui.d.ts
CHANGED
package/dist/ui.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,qBAAa,EAAE;IAEF,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,QAAQ;IAEzC,MAAM,CAAC,MAAM,UAAQ;
|
|
1
|
+
{"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,qBAAa,EAAE;IAEF,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,QAAQ;IAEzC,MAAM,CAAC,MAAM,UAAQ;IAsF3B,SAAS;CAoIT"}
|