@auxilium/datalynk-client 1.1.10 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Database } from '@ztimson/utils';
2
2
  import { BehaviorSubject } from 'rxjs';
3
3
  import { Auth } from './auth';
4
+ import { PWA } from './pwa';
4
5
  import { Files } from './files';
5
6
  import { Meta } from './meta';
6
7
  import { Pdf } from './pdf';
@@ -98,6 +99,8 @@ export declare class Api {
98
99
  readonly files: Files;
99
100
  /** PDF */
100
101
  readonly pdf: Pdf;
102
+ /** PWA setup & prompt */
103
+ readonly pwa: PWA;
101
104
  /** Socket */
102
105
  readonly socket: Socket;
103
106
  /** Superuser */
package/dist/api.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoD,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAAC,eAAe,EAAuB,MAAM,MAAM,CAAC;AAC3D,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,MAAM,SAAS,CAAC;AACvC,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAEhC,MAAM,MAAM,UAAU,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAA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,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,CAAC,CAAC;IAU7E;;;;;;;;;;;OAWG;IACI,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,CAAC,CAAC;IAqC/E;;;;;;;;;;;;OAYG;IACI,KAAK,CAAC,CAAC,SAAS,IAAI,GAAG,GAAG,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC;CAIjE"}
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export * from './files';
4
4
  export * from './login-prompt';
5
5
  export * from './meta';
6
6
  export * from './pdf';
7
+ export * from './pwa';
7
8
  export * from './serializer';
8
9
  export * from './slice';
9
10
  export * from './socket';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -1166,20 +1166,20 @@ var Subscription = function() {
1166
1166
  }
1167
1167
  }
1168
1168
  };
1169
- Subscription2.prototype._hasParent = function(parent) {
1169
+ Subscription2.prototype._hasParent = function(parent2) {
1170
1170
  var _parentage = this._parentage;
1171
- return _parentage === parent || Array.isArray(_parentage) && _parentage.includes(parent);
1171
+ return _parentage === parent2 || Array.isArray(_parentage) && _parentage.includes(parent2);
1172
1172
  };
1173
- Subscription2.prototype._addParent = function(parent) {
1173
+ Subscription2.prototype._addParent = function(parent2) {
1174
1174
  var _parentage = this._parentage;
1175
- this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
1175
+ this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent2), _parentage) : _parentage ? [_parentage, parent2] : parent2;
1176
1176
  };
1177
- Subscription2.prototype._removeParent = function(parent) {
1177
+ Subscription2.prototype._removeParent = function(parent2) {
1178
1178
  var _parentage = this._parentage;
1179
- if (_parentage === parent) {
1179
+ if (_parentage === parent2) {
1180
1180
  this._parentage = null;
1181
1181
  } else if (Array.isArray(_parentage)) {
1182
- arrRemove(_parentage, parent);
1182
+ arrRemove(_parentage, parent2);
1183
1183
  }
1184
1184
  };
1185
1185
  Subscription2.prototype.remove = function(teardown) {
@@ -2321,6 +2321,183 @@ class Auth {
2321
2321
  return this.api.request({ "$/auth/mobile/generate": { user: login, method: mode } });
2322
2322
  }
2323
2323
  }
2324
+ class PWA {
2325
+ constructor(api) {
2326
+ this.api = api;
2327
+ }
2328
+ get iframe() {
2329
+ return (parent == null ? void 0 : parent.location) != location;
2330
+ }
2331
+ get mobile() {
2332
+ return ["android", "ios"].includes(this.platform);
2333
+ }
2334
+ get platform() {
2335
+ const userAgent = navigator.userAgent || navigator.vendor;
2336
+ if (/windows/i.test(userAgent)) return "windows";
2337
+ else if (/android/i.test(userAgent)) return "android";
2338
+ else if (/iPad|iPhone|iPod/.test(userAgent)) return "ios";
2339
+ else if (/macintosh|mac os x/i.test(userAgent)) return "mac";
2340
+ else if (/linux/i.test(userAgent)) return "linux";
2341
+ else return "unknown";
2342
+ }
2343
+ get pwa() {
2344
+ return matchMedia("(display-mode: standalone)").matches || (navigator == null ? void 0 : navigator.standalone) || document.referrer.includes("android-app://");
2345
+ }
2346
+ /** Setup the PWA */
2347
+ async setup(manifest = {}) {
2348
+ const meta = (key, name, value) => {
2349
+ const exists = document.querySelector(`meta[${key}="${name}"]`);
2350
+ if (value === void 0 || exists) return exists;
2351
+ const meta2 = document.createElement("meta");
2352
+ meta2.setAttribute(key, name);
2353
+ meta2.content = value;
2354
+ document.head.append(meta2);
2355
+ };
2356
+ meta("name", "mobile-web-app-capable", "yes");
2357
+ meta("name", "apple-mobile-web-app-status-bar-style", "default");
2358
+ meta("name", "apple-mobile-web-app-title", this.api.options.name);
2359
+ meta("name", "apple-touch-icon", `https://datalynk-client.scarborough.auxilium.world/logo.png`);
2360
+ meta("name", "apple-touch-startup-image", `https://datalynk-client.scarborough.auxilium.world/logo.png`);
2361
+ if (!document.querySelector('link[rel="manifest"]')) {
2362
+ const link = document.createElement("link");
2363
+ link.setAttribute("rel", "manifest");
2364
+ link.setAttribute("href", `${this.api.url}/manifest?json=${encodeURI(JSON.stringify({
2365
+ name: this.api.options.name,
2366
+ short_name: this.api.options.name,
2367
+ start_url: location.origin + location.pathname,
2368
+ ...this.api.options.manifest,
2369
+ ...manifest
2370
+ }))}`);
2371
+ document.head.append(link);
2372
+ }
2373
+ if (!this.iframe && !this.pwa && this.platform != "mac") setTimeout(() => {
2374
+ const dismissed = !!localStorage.getItem(`${this.api.options.name}:pwa`);
2375
+ if (!dismissed) this.prompt();
2376
+ }, 6e4);
2377
+ }
2378
+ /** Prompt user to install the app */
2379
+ async prompt(platform) {
2380
+ if (document.querySelector(".pwa-prompt")) return;
2381
+ this.api.url;
2382
+ const android = (platform || this.platform) == "android";
2383
+ let style = document.querySelector("style.pwa");
2384
+ if (!style) {
2385
+ style = document.createElement("style");
2386
+ style.innerHTML = `
2387
+ .pwa-prompt-backdrop {
2388
+ position: fixed;
2389
+ display: relative;
2390
+ left: 0;
2391
+ top: 0;
2392
+ right: 0;
2393
+ bottom: 0;
2394
+ background: rgba(0,0,0,.5);
2395
+ z-index: 9999;
2396
+ animation: fadeIn 0.5s ease-in-out forwards;
2397
+ opacity: 0;
2398
+ }
2399
+ .pwa-prompt-backdrop.exit {
2400
+ animation: fadeOut 0.5s ease-in-out forwards !important;
2401
+ }
2402
+ .pwa-prompt {
2403
+ position: fixed;
2404
+ background: #fff;
2405
+ color: black;
2406
+ bottom: 0;
2407
+ left: 50%;
2408
+ width: min(100vw, 450px);
2409
+ transform: translate(-50%, 0);
2410
+ animation: slideUp 0.5s ease-in-out forwards;
2411
+ }
2412
+ .pwa-prompt.exit {
2413
+ animation: slideDown 0.5s ease-in-out forwards !important;
2414
+ }
2415
+ .pwa-prompt img {
2416
+ width: 18px;
2417
+ height: 18px;
2418
+ }
2419
+ .pwa-prompt h1 {
2420
+ font-size: 1.25rem;
2421
+ font-weight: bold;
2422
+ }
2423
+ .pwa-prompt-close {
2424
+ position: absolute;
2425
+ right: 5px;
2426
+ top: 10px;
2427
+ background: transparent;
2428
+ border: none;
2429
+ cursor: pointer;
2430
+ }
2431
+
2432
+ @keyframes fadeIn {
2433
+ from { opacity: 0; }
2434
+ to { opacity: 1; }
2435
+ }
2436
+ @keyframes fadeOut {
2437
+ from { opacity: 1; }
2438
+ to { opacity: 0; }
2439
+ }
2440
+
2441
+ @keyframes slideUp {
2442
+ from { transform: translate(-50%, 100%); }
2443
+ to { transform: translate(-50%, 0); }
2444
+ }
2445
+ @keyframes slideDown {
2446
+ from { transform: translate(-50%, 0); }
2447
+ to { transform: translate(-50%, 100%); }
2448
+ }
2449
+ `;
2450
+ document.head.append(style);
2451
+ }
2452
+ const backdrop = document.createElement("div");
2453
+ backdrop.classList.add("pwa-prompt-backdrop");
2454
+ const prompt = document.createElement("div");
2455
+ prompt.classList.add("pwa-prompt");
2456
+ prompt.innerHTML = `
2457
+ <div style="display: flex; padding: 1rem; align-items: center">
2458
+ <img src="https://datalynk-client.scarborough.auxilium.world/logo.png" alt="Logo" style="height: 40px; width: auto; margin-right: .5rem;" />
2459
+ <h1 style="margin: 0">Install ${this.api.options.name}</h1>
2460
+ </div>
2461
+ <div style="display: flex; flex-direction: column; align-items: center">
2462
+ <div style="border-top: 2px solid #00000020; border-bottom: 2px solid #00000020; padding: 0 1rem">
2463
+ <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>
2464
+ </div>
2465
+ <table style="margin: 1.5rem 0">
2466
+ <tr>
2467
+ <td style="width: 50px; text-align: center">
2468
+ ${android ? '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="black" style="transform: scale(1.5)"><path d="M480-160q-33 0-56.5-23.5T400-240q0-33 23.5-56.5T480-320q33 0 56.5 23.5T560-240q0 33-23.5 56.5T480-160Zm0-240q-33 0-56.5-23.5T400-480q0-33 23.5-56.5T480-560q33 0 56.5 23.5T560-480q0 33-23.5 56.5T480-400Zm0-240q-33 0-56.5-23.5T400-720q0-33 23.5-56.5T480-800q33 0 56.5 23.5T560-720q0 33-23.5 56.5T480-640Z"/></svg>' : '<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>'}
2469
+ </td>
2470
+ <td>
2471
+ <p style="margin: 1rem 0">1) ${android ? "Open the dropdown menu" : 'Press the "Share" button'}</p>
2472
+ </td>
2473
+ </tr>
2474
+ <tr>
2475
+ <td style="width: 50px; text-align: center">
2476
+ ${android ? '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="black" style="transform: scale(-1.5, 1.5)"><path d="M280-40q-33 0-56.5-23.5T200-120v-720q0-33 23.5-56.5T280-920h280v80H280v40h280v80H280v480h400v-80h80v200q0 33-23.5 56.5T680-40H280Zm0-120v40h400v-40H280Zm440-240L520-600l56-56 104 104v-288h80v288l104-104 56 56-200 200ZM280-800v-40 40Zm0 640v40-40Z"/></svg>' : '<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>'}
2477
+ </td>
2478
+ <td>
2479
+ <p style="margin: 1rem 0">2) Press "Add to Home Screen"</p>
2480
+ </td>
2481
+ </tr>
2482
+ </table>
2483
+ </div>`;
2484
+ const close = document.createElement("button");
2485
+ close.classList.add("pwa-prompt-close");
2486
+ close.innerText = "x";
2487
+ close.onclick = () => {
2488
+ prompt.classList.add("exit");
2489
+ backdrop.classList.add("exit");
2490
+ localStorage.setItem(`${this.api.options.name}:pwa`, "dismissed");
2491
+ setTimeout(() => {
2492
+ prompt.remove();
2493
+ backdrop.remove();
2494
+ }, 500);
2495
+ };
2496
+ prompt.append(close);
2497
+ backdrop.append(prompt);
2498
+ document.body.append(backdrop);
2499
+ }
2500
+ }
2324
2501
  class Files {
2325
2502
  constructor(api) {
2326
2503
  this.api = api;
@@ -3245,7 +3422,7 @@ class Superuser {
3245
3422
  } });
3246
3423
  }
3247
3424
  }
3248
- const version = "1.1.10";
3425
+ const version = "1.2.0";
3249
3426
  class WebRtc {
3250
3427
  constructor(api) {
3251
3428
  __publicField(this, "ice");
@@ -3394,6 +3571,8 @@ const _Api = class _Api {
3394
3571
  __publicField(this, "files");
3395
3572
  /** PDF */
3396
3573
  __publicField(this, "pdf");
3574
+ /** PWA setup & prompt */
3575
+ __publicField(this, "pwa");
3397
3576
  /** Socket */
3398
3577
  __publicField(this, "socket");
3399
3578
  /** Superuser */
@@ -3442,9 +3621,11 @@ const _Api = class _Api {
3442
3621
  this.auth = new Auth(this);
3443
3622
  this.files = new Files(this);
3444
3623
  this.pdf = new Pdf(this);
3624
+ this.pwa = new PWA(this);
3445
3625
  this.superuser = new Superuser(this);
3446
3626
  this.webrtc = new WebRtc(this);
3447
3627
  if ((_a = this.options.offline) == null ? void 0 : _a.length) {
3628
+ this.pwa.setup();
3448
3629
  if (typeof indexedDB == "undefined") throw new Error("Cannot enable offline support, indexedDB is not available in this environment");
3449
3630
  this.database = new Database("datalynk", this.options.offline);
3450
3631
  (_b = this.options.offline) == null ? void 0 : _b.forEach((id) => this.slice(id));
@@ -3452,17 +3633,6 @@ const _Api = class _Api {
3452
3633
  navigator.serviceWorker.getRegistration(this.options.serviceWorker).then((reg) => reg ?? navigator.serviceWorker.register(this.options.serviceWorker, { scope: "/", type: "module" }));
3453
3634
  }
3454
3635
  }
3455
- if (!document.querySelector('link[rel="manifest"]')) {
3456
- const link = document.createElement("link");
3457
- link.setAttribute("rel", "manifest");
3458
- link.setAttribute("href", `${this.url}/manifest?json=${encodeURI(JSON.stringify({
3459
- name: this.options.name,
3460
- short_name: this.options.name,
3461
- start_url: location.origin + location.pathname,
3462
- ...this.options.manifest
3463
- }))}`);
3464
- document.head.append(link);
3465
- }
3466
3636
  }
3467
3637
  /** Get session info from JWT payload */
3468
3638
  get jwtPayload() {
@@ -3667,6 +3837,7 @@ exports.ApiCall = ApiCall;
3667
3837
  exports.Auth = Auth;
3668
3838
  exports.Files = Files;
3669
3839
  exports.LoginPrompt = LoginPrompt;
3840
+ exports.PWA = PWA;
3670
3841
  exports.Pdf = Pdf;
3671
3842
  exports.Serializer = Serializer;
3672
3843
  exports.Slice = Slice;
package/dist/index.mjs CHANGED
@@ -1164,20 +1164,20 @@ var Subscription = function() {
1164
1164
  }
1165
1165
  }
1166
1166
  };
1167
- Subscription2.prototype._hasParent = function(parent) {
1167
+ Subscription2.prototype._hasParent = function(parent2) {
1168
1168
  var _parentage = this._parentage;
1169
- return _parentage === parent || Array.isArray(_parentage) && _parentage.includes(parent);
1169
+ return _parentage === parent2 || Array.isArray(_parentage) && _parentage.includes(parent2);
1170
1170
  };
1171
- Subscription2.prototype._addParent = function(parent) {
1171
+ Subscription2.prototype._addParent = function(parent2) {
1172
1172
  var _parentage = this._parentage;
1173
- this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
1173
+ this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent2), _parentage) : _parentage ? [_parentage, parent2] : parent2;
1174
1174
  };
1175
- Subscription2.prototype._removeParent = function(parent) {
1175
+ Subscription2.prototype._removeParent = function(parent2) {
1176
1176
  var _parentage = this._parentage;
1177
- if (_parentage === parent) {
1177
+ if (_parentage === parent2) {
1178
1178
  this._parentage = null;
1179
1179
  } else if (Array.isArray(_parentage)) {
1180
- arrRemove(_parentage, parent);
1180
+ arrRemove(_parentage, parent2);
1181
1181
  }
1182
1182
  };
1183
1183
  Subscription2.prototype.remove = function(teardown) {
@@ -2319,6 +2319,183 @@ class Auth {
2319
2319
  return this.api.request({ "$/auth/mobile/generate": { user: login, method: mode } });
2320
2320
  }
2321
2321
  }
2322
+ class PWA {
2323
+ constructor(api) {
2324
+ this.api = api;
2325
+ }
2326
+ get iframe() {
2327
+ return (parent == null ? void 0 : parent.location) != location;
2328
+ }
2329
+ get mobile() {
2330
+ return ["android", "ios"].includes(this.platform);
2331
+ }
2332
+ get platform() {
2333
+ const userAgent = navigator.userAgent || navigator.vendor;
2334
+ if (/windows/i.test(userAgent)) return "windows";
2335
+ else if (/android/i.test(userAgent)) return "android";
2336
+ else if (/iPad|iPhone|iPod/.test(userAgent)) return "ios";
2337
+ else if (/macintosh|mac os x/i.test(userAgent)) return "mac";
2338
+ else if (/linux/i.test(userAgent)) return "linux";
2339
+ else return "unknown";
2340
+ }
2341
+ get pwa() {
2342
+ return matchMedia("(display-mode: standalone)").matches || (navigator == null ? void 0 : navigator.standalone) || document.referrer.includes("android-app://");
2343
+ }
2344
+ /** Setup the PWA */
2345
+ async setup(manifest = {}) {
2346
+ const meta = (key, name, value) => {
2347
+ const exists = document.querySelector(`meta[${key}="${name}"]`);
2348
+ if (value === void 0 || exists) return exists;
2349
+ const meta2 = document.createElement("meta");
2350
+ meta2.setAttribute(key, name);
2351
+ meta2.content = value;
2352
+ document.head.append(meta2);
2353
+ };
2354
+ meta("name", "mobile-web-app-capable", "yes");
2355
+ meta("name", "apple-mobile-web-app-status-bar-style", "default");
2356
+ meta("name", "apple-mobile-web-app-title", this.api.options.name);
2357
+ meta("name", "apple-touch-icon", `https://datalynk-client.scarborough.auxilium.world/logo.png`);
2358
+ meta("name", "apple-touch-startup-image", `https://datalynk-client.scarborough.auxilium.world/logo.png`);
2359
+ if (!document.querySelector('link[rel="manifest"]')) {
2360
+ const link = document.createElement("link");
2361
+ link.setAttribute("rel", "manifest");
2362
+ link.setAttribute("href", `${this.api.url}/manifest?json=${encodeURI(JSON.stringify({
2363
+ name: this.api.options.name,
2364
+ short_name: this.api.options.name,
2365
+ start_url: location.origin + location.pathname,
2366
+ ...this.api.options.manifest,
2367
+ ...manifest
2368
+ }))}`);
2369
+ document.head.append(link);
2370
+ }
2371
+ if (!this.iframe && !this.pwa && this.platform != "mac") setTimeout(() => {
2372
+ const dismissed = !!localStorage.getItem(`${this.api.options.name}:pwa`);
2373
+ if (!dismissed) this.prompt();
2374
+ }, 6e4);
2375
+ }
2376
+ /** Prompt user to install the app */
2377
+ async prompt(platform) {
2378
+ if (document.querySelector(".pwa-prompt")) return;
2379
+ this.api.url;
2380
+ const android = (platform || this.platform) == "android";
2381
+ let style = document.querySelector("style.pwa");
2382
+ if (!style) {
2383
+ style = document.createElement("style");
2384
+ style.innerHTML = `
2385
+ .pwa-prompt-backdrop {
2386
+ position: fixed;
2387
+ display: relative;
2388
+ left: 0;
2389
+ top: 0;
2390
+ right: 0;
2391
+ bottom: 0;
2392
+ background: rgba(0,0,0,.5);
2393
+ z-index: 9999;
2394
+ animation: fadeIn 0.5s ease-in-out forwards;
2395
+ opacity: 0;
2396
+ }
2397
+ .pwa-prompt-backdrop.exit {
2398
+ animation: fadeOut 0.5s ease-in-out forwards !important;
2399
+ }
2400
+ .pwa-prompt {
2401
+ position: fixed;
2402
+ background: #fff;
2403
+ color: black;
2404
+ bottom: 0;
2405
+ left: 50%;
2406
+ width: min(100vw, 450px);
2407
+ transform: translate(-50%, 0);
2408
+ animation: slideUp 0.5s ease-in-out forwards;
2409
+ }
2410
+ .pwa-prompt.exit {
2411
+ animation: slideDown 0.5s ease-in-out forwards !important;
2412
+ }
2413
+ .pwa-prompt img {
2414
+ width: 18px;
2415
+ height: 18px;
2416
+ }
2417
+ .pwa-prompt h1 {
2418
+ font-size: 1.25rem;
2419
+ font-weight: bold;
2420
+ }
2421
+ .pwa-prompt-close {
2422
+ position: absolute;
2423
+ right: 5px;
2424
+ top: 10px;
2425
+ background: transparent;
2426
+ border: none;
2427
+ cursor: pointer;
2428
+ }
2429
+
2430
+ @keyframes fadeIn {
2431
+ from { opacity: 0; }
2432
+ to { opacity: 1; }
2433
+ }
2434
+ @keyframes fadeOut {
2435
+ from { opacity: 1; }
2436
+ to { opacity: 0; }
2437
+ }
2438
+
2439
+ @keyframes slideUp {
2440
+ from { transform: translate(-50%, 100%); }
2441
+ to { transform: translate(-50%, 0); }
2442
+ }
2443
+ @keyframes slideDown {
2444
+ from { transform: translate(-50%, 0); }
2445
+ to { transform: translate(-50%, 100%); }
2446
+ }
2447
+ `;
2448
+ document.head.append(style);
2449
+ }
2450
+ const backdrop = document.createElement("div");
2451
+ backdrop.classList.add("pwa-prompt-backdrop");
2452
+ const prompt = document.createElement("div");
2453
+ prompt.classList.add("pwa-prompt");
2454
+ prompt.innerHTML = `
2455
+ <div style="display: flex; padding: 1rem; align-items: center">
2456
+ <img src="https://datalynk-client.scarborough.auxilium.world/logo.png" alt="Logo" style="height: 40px; width: auto; margin-right: .5rem;" />
2457
+ <h1 style="margin: 0">Install ${this.api.options.name}</h1>
2458
+ </div>
2459
+ <div style="display: flex; flex-direction: column; align-items: center">
2460
+ <div style="border-top: 2px solid #00000020; border-bottom: 2px solid #00000020; padding: 0 1rem">
2461
+ <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>
2462
+ </div>
2463
+ <table style="margin: 1.5rem 0">
2464
+ <tr>
2465
+ <td style="width: 50px; text-align: center">
2466
+ ${android ? '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="black" style="transform: scale(1.5)"><path d="M480-160q-33 0-56.5-23.5T400-240q0-33 23.5-56.5T480-320q33 0 56.5 23.5T560-240q0 33-23.5 56.5T480-160Zm0-240q-33 0-56.5-23.5T400-480q0-33 23.5-56.5T480-560q33 0 56.5 23.5T560-480q0 33-23.5 56.5T480-400Zm0-240q-33 0-56.5-23.5T400-720q0-33 23.5-56.5T480-800q33 0 56.5 23.5T560-720q0 33-23.5 56.5T480-640Z"/></svg>' : '<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>'}
2467
+ </td>
2468
+ <td>
2469
+ <p style="margin: 1rem 0">1) ${android ? "Open the dropdown menu" : 'Press the "Share" button'}</p>
2470
+ </td>
2471
+ </tr>
2472
+ <tr>
2473
+ <td style="width: 50px; text-align: center">
2474
+ ${android ? '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="black" style="transform: scale(-1.5, 1.5)"><path d="M280-40q-33 0-56.5-23.5T200-120v-720q0-33 23.5-56.5T280-920h280v80H280v40h280v80H280v480h400v-80h80v200q0 33-23.5 56.5T680-40H280Zm0-120v40h400v-40H280Zm440-240L520-600l56-56 104 104v-288h80v288l104-104 56 56-200 200ZM280-800v-40 40Zm0 640v40-40Z"/></svg>' : '<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>'}
2475
+ </td>
2476
+ <td>
2477
+ <p style="margin: 1rem 0">2) Press "Add to Home Screen"</p>
2478
+ </td>
2479
+ </tr>
2480
+ </table>
2481
+ </div>`;
2482
+ const close = document.createElement("button");
2483
+ close.classList.add("pwa-prompt-close");
2484
+ close.innerText = "x";
2485
+ close.onclick = () => {
2486
+ prompt.classList.add("exit");
2487
+ backdrop.classList.add("exit");
2488
+ localStorage.setItem(`${this.api.options.name}:pwa`, "dismissed");
2489
+ setTimeout(() => {
2490
+ prompt.remove();
2491
+ backdrop.remove();
2492
+ }, 500);
2493
+ };
2494
+ prompt.append(close);
2495
+ backdrop.append(prompt);
2496
+ document.body.append(backdrop);
2497
+ }
2498
+ }
2322
2499
  class Files {
2323
2500
  constructor(api) {
2324
2501
  this.api = api;
@@ -3243,7 +3420,7 @@ class Superuser {
3243
3420
  } });
3244
3421
  }
3245
3422
  }
3246
- const version = "1.1.10";
3423
+ const version = "1.2.0";
3247
3424
  class WebRtc {
3248
3425
  constructor(api) {
3249
3426
  __publicField(this, "ice");
@@ -3392,6 +3569,8 @@ const _Api = class _Api {
3392
3569
  __publicField(this, "files");
3393
3570
  /** PDF */
3394
3571
  __publicField(this, "pdf");
3572
+ /** PWA setup & prompt */
3573
+ __publicField(this, "pwa");
3395
3574
  /** Socket */
3396
3575
  __publicField(this, "socket");
3397
3576
  /** Superuser */
@@ -3440,9 +3619,11 @@ const _Api = class _Api {
3440
3619
  this.auth = new Auth(this);
3441
3620
  this.files = new Files(this);
3442
3621
  this.pdf = new Pdf(this);
3622
+ this.pwa = new PWA(this);
3443
3623
  this.superuser = new Superuser(this);
3444
3624
  this.webrtc = new WebRtc(this);
3445
3625
  if ((_a = this.options.offline) == null ? void 0 : _a.length) {
3626
+ this.pwa.setup();
3446
3627
  if (typeof indexedDB == "undefined") throw new Error("Cannot enable offline support, indexedDB is not available in this environment");
3447
3628
  this.database = new Database("datalynk", this.options.offline);
3448
3629
  (_b = this.options.offline) == null ? void 0 : _b.forEach((id) => this.slice(id));
@@ -3450,17 +3631,6 @@ const _Api = class _Api {
3450
3631
  navigator.serviceWorker.getRegistration(this.options.serviceWorker).then((reg) => reg ?? navigator.serviceWorker.register(this.options.serviceWorker, { scope: "/", type: "module" }));
3451
3632
  }
3452
3633
  }
3453
- if (!document.querySelector('link[rel="manifest"]')) {
3454
- const link = document.createElement("link");
3455
- link.setAttribute("rel", "manifest");
3456
- link.setAttribute("href", `${this.url}/manifest?json=${encodeURI(JSON.stringify({
3457
- name: this.options.name,
3458
- short_name: this.options.name,
3459
- start_url: location.origin + location.pathname,
3460
- ...this.options.manifest
3461
- }))}`);
3462
- document.head.append(link);
3463
- }
3464
3634
  }
3465
3635
  /** Get session info from JWT payload */
3466
3636
  get jwtPayload() {
@@ -3666,6 +3836,7 @@ export {
3666
3836
  Auth,
3667
3837
  Files,
3668
3838
  LoginPrompt,
3839
+ PWA,
3669
3840
  Pdf,
3670
3841
  Serializer,
3671
3842
  Slice,
package/dist/pwa.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { Api } from './api';
2
+ export declare class PWA {
3
+ private readonly api;
4
+ get iframe(): boolean;
5
+ get mobile(): boolean;
6
+ get platform(): 'android' | 'ios' | 'mac' | 'windows' | 'linux' | 'unknown';
7
+ get pwa(): boolean;
8
+ constructor(api: Api);
9
+ /** Setup the PWA */
10
+ setup(manifest?: any): Promise<void>;
11
+ /** Prompt user to install the app */
12
+ prompt(platform?: 'android' | 'ios'): Promise<void>;
13
+ }
14
+ //# sourceMappingURL=pwa.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pwa.d.ts","sourceRoot":"","sources":["../src/pwa.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,qBAAa,GAAG;IAoBH,OAAO,CAAC,QAAQ,CAAC,GAAG;IAlBhC,IAAI,MAAM,IAAI,OAAO,CAAyC;IAE9D,IAAI,MAAM,IAAI,OAAO,CAAuD;IAE5E,IAAI,QAAQ,IAAI,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAQ1E;IAED,IAAI,GAAG,IAAI,OAAO,CAEjB;gBAE4B,GAAG,EAAE,GAAG;IAErC,oBAAoB;IACd,KAAK,CAAC,QAAQ,GAAE,GAAQ;IAsC9B,qCAAqC;IAC/B,MAAM,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,KAAK;CAiIzC"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@auxilium/datalynk-client",
3
3
  "description": "Datalynk client library",
4
4
  "repository": "https://gitlab.auxiliumgroup.com/auxilium/datalynk/datalynk-client",
5
- "version": "1.1.10",
5
+ "version": "1.2.0",
6
6
  "author": "Zak Timson <zaktimson@gmail.com>",
7
7
  "private": false,
8
8
  "main": "./dist/index.cjs",