@ztimson/momentum 0.52.2 → 0.52.3
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/client.d.ts +7 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +21 -12
- package/dist/index.mjs +21 -12
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export type Platform = 'windows' | 'android' | 'ios' | 'mac' | 'linux' | 'unknow
|
|
|
5
5
|
export declare class Client extends PathEventEmitter {
|
|
6
6
|
private api;
|
|
7
7
|
private readonly settings;
|
|
8
|
+
/** Check if iframed */
|
|
9
|
+
get iframe(): boolean;
|
|
8
10
|
/** Check if mobile device */
|
|
9
11
|
get mobile(): boolean;
|
|
10
12
|
private _notifications;
|
|
@@ -22,10 +24,13 @@ export declare class Client extends PathEventEmitter {
|
|
|
22
24
|
constructor(api: Api, settings: Settings);
|
|
23
25
|
/**
|
|
24
26
|
* Inject the client theme settings, meta tags & PWA prompt
|
|
25
|
-
* @param
|
|
27
|
+
* @param opts Injection options: reload - use cached settings or reload; pwa - disabled auto pwa prompt
|
|
26
28
|
* @return {Promise<void>} Resolves on completion
|
|
27
29
|
*/
|
|
28
|
-
|
|
30
|
+
init(opts?: {
|
|
31
|
+
reload?: boolean;
|
|
32
|
+
pwa?: boolean;
|
|
33
|
+
}): Promise<void>;
|
|
29
34
|
/**
|
|
30
35
|
* Create UI prompt for user to install as PWA
|
|
31
36
|
* @param platform Platform prompt, leave blank to auto-detect
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,gBAAgB,EAAM,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,M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FvD;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,KAAK;IAqItC;;;OAGG;IACG,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAa1C;;;OAGG;IACG,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;CAO3C"}
|
package/dist/index.cjs
CHANGED
|
@@ -1445,6 +1445,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1445
1445
|
this.settings = settings;
|
|
1446
1446
|
this.pushSubscription.then((resp) => this.notifications = !!resp);
|
|
1447
1447
|
}
|
|
1448
|
+
/** Check if iframed */
|
|
1449
|
+
get iframe() {
|
|
1450
|
+
return (parent == null ? void 0 : parent.location) != location;
|
|
1451
|
+
}
|
|
1448
1452
|
/** Check if mobile device */
|
|
1449
1453
|
get mobile() {
|
|
1450
1454
|
return ["android", "ios"].includes(this.platform);
|
|
@@ -1487,11 +1491,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1487
1491
|
}
|
|
1488
1492
|
/**
|
|
1489
1493
|
* Inject the client theme settings, meta tags & PWA prompt
|
|
1490
|
-
* @param
|
|
1494
|
+
* @param opts Injection options: reload - use cached settings or reload; pwa - disabled auto pwa prompt
|
|
1491
1495
|
* @return {Promise<void>} Resolves on completion
|
|
1492
1496
|
*/
|
|
1493
|
-
async
|
|
1497
|
+
async init(opts = {}) {
|
|
1494
1498
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
1499
|
+
opts = {
|
|
1500
|
+
reload: void 0,
|
|
1501
|
+
pwa: true,
|
|
1502
|
+
...opts
|
|
1503
|
+
};
|
|
1495
1504
|
const meta = (key, name, value) => {
|
|
1496
1505
|
const exists = document.querySelector(`meta[${key}="${name}"]`);
|
|
1497
1506
|
if (value === void 0 || exists) return exists;
|
|
@@ -1500,9 +1509,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1500
1509
|
meta2.content = value;
|
|
1501
1510
|
document.head.append(meta2);
|
|
1502
1511
|
};
|
|
1503
|
-
if (!this.settings.cache.keys().length) reload = true;
|
|
1504
|
-
let settings = await (reload ? this.settings.all(false, true) : this.settings.cache);
|
|
1505
|
-
if (reload == null) this.settings.all(false, true).then(() => this.
|
|
1512
|
+
if (!this.settings.cache.keys().length) opts.reload = true;
|
|
1513
|
+
let settings = await (opts.reload ? this.settings.all(false, true) : this.settings.cache);
|
|
1514
|
+
if (opts.reload == null) this.settings.all(false, true).then(() => this.init({ reload: false }));
|
|
1506
1515
|
if (settings["title"]) document.querySelectorAll(".momentum-title").forEach((el) => el.innerText = settings["title"]);
|
|
1507
1516
|
if (settings["description"]) document.querySelectorAll(".momentum-description").forEach((el) => el.innerText = settings["description"]);
|
|
1508
1517
|
if (settings["version"]) document.querySelectorAll(".momentum-version").forEach((el) => el.innerText = settings["version"]);
|
|
@@ -1520,21 +1529,21 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1520
1529
|
meta("name", "twitter:title", settings["title"]);
|
|
1521
1530
|
meta("name", "twitter:description", settings["description"]);
|
|
1522
1531
|
meta("name", "twitter:image", `${settings["public_url"]}/favicon.png`);
|
|
1523
|
-
meta("name", "mobile-web-app-capable", "yes");
|
|
1524
|
-
meta("name", "apple-mobile-web-app-status-bar-style", "default");
|
|
1525
|
-
meta("name", "apple-mobile-web-app-title", settings["title"]);
|
|
1526
|
-
meta("name", "apple-touch-icon", `${settings["public_url"]}/favicon.png`);
|
|
1527
|
-
meta("name", "apple-touch-startup-image", `${settings["public_url"]}/favicon.png`);
|
|
1528
1532
|
if (settings["pwa"]) {
|
|
1533
|
+
meta("name", "mobile-web-app-capable", "yes");
|
|
1534
|
+
meta("name", "apple-mobile-web-app-status-bar-style", "default");
|
|
1535
|
+
meta("name", "apple-mobile-web-app-title", settings["title"]);
|
|
1536
|
+
meta("name", "apple-touch-icon", `${settings["public_url"]}/favicon.png`);
|
|
1537
|
+
meta("name", "apple-touch-startup-image", `${settings["public_url"]}/favicon.png`);
|
|
1529
1538
|
if (!document.querySelector('link[rel="manifest"]')) {
|
|
1530
1539
|
const link = document.createElement("link");
|
|
1531
1540
|
link.setAttribute("rel", "manifest");
|
|
1532
1541
|
link.setAttribute("href", this.settings.api.url + "/manifest.json");
|
|
1533
1542
|
document.head.append(link);
|
|
1534
1543
|
}
|
|
1535
|
-
setTimeout(() => {
|
|
1544
|
+
if (opts.pwa && !this.iframe && !this.pwa && this.mobile) setTimeout(() => {
|
|
1536
1545
|
const dismissed = !!localStorage.getItem("momentum:install-prompt");
|
|
1537
|
-
if (!dismissed
|
|
1546
|
+
if (!dismissed) this.pwaPrompt();
|
|
1538
1547
|
}, 6e4);
|
|
1539
1548
|
}
|
|
1540
1549
|
meta("name", "theme-color", (_a = settings["theme"]) == null ? void 0 : _a.background);
|
package/dist/index.mjs
CHANGED
|
@@ -1441,6 +1441,10 @@ class Client extends PathEventEmitter {
|
|
|
1441
1441
|
this.settings = settings;
|
|
1442
1442
|
this.pushSubscription.then((resp) => this.notifications = !!resp);
|
|
1443
1443
|
}
|
|
1444
|
+
/** Check if iframed */
|
|
1445
|
+
get iframe() {
|
|
1446
|
+
return (parent == null ? void 0 : parent.location) != location;
|
|
1447
|
+
}
|
|
1444
1448
|
/** Check if mobile device */
|
|
1445
1449
|
get mobile() {
|
|
1446
1450
|
return ["android", "ios"].includes(this.platform);
|
|
@@ -1483,11 +1487,16 @@ class Client extends PathEventEmitter {
|
|
|
1483
1487
|
}
|
|
1484
1488
|
/**
|
|
1485
1489
|
* Inject the client theme settings, meta tags & PWA prompt
|
|
1486
|
-
* @param
|
|
1490
|
+
* @param opts Injection options: reload - use cached settings or reload; pwa - disabled auto pwa prompt
|
|
1487
1491
|
* @return {Promise<void>} Resolves on completion
|
|
1488
1492
|
*/
|
|
1489
|
-
async
|
|
1493
|
+
async init(opts = {}) {
|
|
1490
1494
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
1495
|
+
opts = {
|
|
1496
|
+
reload: void 0,
|
|
1497
|
+
pwa: true,
|
|
1498
|
+
...opts
|
|
1499
|
+
};
|
|
1491
1500
|
const meta = (key, name, value) => {
|
|
1492
1501
|
const exists = document.querySelector(`meta[${key}="${name}"]`);
|
|
1493
1502
|
if (value === void 0 || exists) return exists;
|
|
@@ -1496,9 +1505,9 @@ class Client extends PathEventEmitter {
|
|
|
1496
1505
|
meta2.content = value;
|
|
1497
1506
|
document.head.append(meta2);
|
|
1498
1507
|
};
|
|
1499
|
-
if (!this.settings.cache.keys().length) reload = true;
|
|
1500
|
-
let settings = await (reload ? this.settings.all(false, true) : this.settings.cache);
|
|
1501
|
-
if (reload == null) this.settings.all(false, true).then(() => this.
|
|
1508
|
+
if (!this.settings.cache.keys().length) opts.reload = true;
|
|
1509
|
+
let settings = await (opts.reload ? this.settings.all(false, true) : this.settings.cache);
|
|
1510
|
+
if (opts.reload == null) this.settings.all(false, true).then(() => this.init({ reload: false }));
|
|
1502
1511
|
if (settings["title"]) document.querySelectorAll(".momentum-title").forEach((el) => el.innerText = settings["title"]);
|
|
1503
1512
|
if (settings["description"]) document.querySelectorAll(".momentum-description").forEach((el) => el.innerText = settings["description"]);
|
|
1504
1513
|
if (settings["version"]) document.querySelectorAll(".momentum-version").forEach((el) => el.innerText = settings["version"]);
|
|
@@ -1516,21 +1525,21 @@ class Client extends PathEventEmitter {
|
|
|
1516
1525
|
meta("name", "twitter:title", settings["title"]);
|
|
1517
1526
|
meta("name", "twitter:description", settings["description"]);
|
|
1518
1527
|
meta("name", "twitter:image", `${settings["public_url"]}/favicon.png`);
|
|
1519
|
-
meta("name", "mobile-web-app-capable", "yes");
|
|
1520
|
-
meta("name", "apple-mobile-web-app-status-bar-style", "default");
|
|
1521
|
-
meta("name", "apple-mobile-web-app-title", settings["title"]);
|
|
1522
|
-
meta("name", "apple-touch-icon", `${settings["public_url"]}/favicon.png`);
|
|
1523
|
-
meta("name", "apple-touch-startup-image", `${settings["public_url"]}/favicon.png`);
|
|
1524
1528
|
if (settings["pwa"]) {
|
|
1529
|
+
meta("name", "mobile-web-app-capable", "yes");
|
|
1530
|
+
meta("name", "apple-mobile-web-app-status-bar-style", "default");
|
|
1531
|
+
meta("name", "apple-mobile-web-app-title", settings["title"]);
|
|
1532
|
+
meta("name", "apple-touch-icon", `${settings["public_url"]}/favicon.png`);
|
|
1533
|
+
meta("name", "apple-touch-startup-image", `${settings["public_url"]}/favicon.png`);
|
|
1525
1534
|
if (!document.querySelector('link[rel="manifest"]')) {
|
|
1526
1535
|
const link = document.createElement("link");
|
|
1527
1536
|
link.setAttribute("rel", "manifest");
|
|
1528
1537
|
link.setAttribute("href", this.settings.api.url + "/manifest.json");
|
|
1529
1538
|
document.head.append(link);
|
|
1530
1539
|
}
|
|
1531
|
-
setTimeout(() => {
|
|
1540
|
+
if (opts.pwa && !this.iframe && !this.pwa && this.mobile) setTimeout(() => {
|
|
1532
1541
|
const dismissed = !!localStorage.getItem("momentum:install-prompt");
|
|
1533
|
-
if (!dismissed
|
|
1542
|
+
if (!dismissed) this.pwaPrompt();
|
|
1534
1543
|
}, 6e4);
|
|
1535
1544
|
}
|
|
1536
1545
|
meta("name", "theme-color", (_a = settings["theme"]) == null ? void 0 : _a.background);
|