@shop-on/theme-runtime 0.13.1 → 0.14.0-next.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.
@@ -0,0 +1,5 @@
1
+ /** True when an installed app claims `product`'s buy button: open its product
2
+ * page instead of adding it here. */
3
+ export declare function mustOpenProductPage(product: {
4
+ buyButtonAppIds?: readonly string[] | null;
5
+ } | null | undefined): boolean;
@@ -0,0 +1,7 @@
1
+ // src/app-intercepts.ts
2
+ /** True when an installed app claims `product`'s buy button: open its product
3
+ * page instead of adding it here. */
4
+ function mustOpenProductPage(product) {
5
+ return (product?.buyButtonAppIds?.length ?? 0) > 0;
6
+ }
7
+ export { mustOpenProductPage };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Whole seconds left on a line's hold at `nowMs`, never below 0; null when no
3
+ * app holds the line (or the time does not parse).
4
+ *
5
+ * Rounded UP, so the label reads "0:01" through the last second and the line
6
+ * reaches 0 only once the hold has actually passed, which is when the api
7
+ * stops answering it.
8
+ */
9
+ export declare function holdSecondsLeft(holdExpiresAt: string | null, nowMs: number): number | null;
10
+ /**
11
+ * The countdown as a clock: `m:ss` under an hour, `h:mm:ss` from an hour up
12
+ * (a hold runs a day at most). Minutes are not padded under an hour, so a
13
+ * five-minute hold reads "4:59", not "04:59".
14
+ */
15
+ export declare function formatHoldCountdown(seconds: number): string;
16
+ /**
17
+ * A held line's countdown label at `nowMs`: `formatHoldCountdown` of the
18
+ * seconds left, or the placeholder `–:––` while there is no clock yet
19
+ * (`nowMs` null) or the time does not parse. Null when no app holds the line,
20
+ * which draws no countdown.
21
+ */
22
+ export declare function holdCountdownText(holdExpiresAt: string | null, nowMs: number | null): string | null;
@@ -0,0 +1,40 @@
1
+ // src/cart-hold.ts
2
+ /**
3
+ * Whole seconds left on a line's hold at `nowMs`, never below 0; null when no
4
+ * app holds the line (or the time does not parse).
5
+ *
6
+ * Rounded UP, so the label reads "0:01" through the last second and the line
7
+ * reaches 0 only once the hold has actually passed, which is when the api
8
+ * stops answering it.
9
+ */
10
+ function holdSecondsLeft(holdExpiresAt, nowMs) {
11
+ if (holdExpiresAt === null) return null;
12
+ const expiresMs = Date.parse(holdExpiresAt);
13
+ if (Number.isNaN(expiresMs)) return null;
14
+ return Math.max(0, Math.ceil((expiresMs - nowMs) / 1e3));
15
+ }
16
+ /**
17
+ * The countdown as a clock: `m:ss` under an hour, `h:mm:ss` from an hour up
18
+ * (a hold runs a day at most). Minutes are not padded under an hour, so a
19
+ * five-minute hold reads "4:59", not "04:59".
20
+ */
21
+ function formatHoldCountdown(seconds) {
22
+ const total = Math.max(0, Math.floor(seconds));
23
+ const h = Math.floor(total / 3600);
24
+ const m = Math.floor(total % 3600 / 60);
25
+ const ss = String(total % 60).padStart(2, "0");
26
+ return h > 0 ? `${h}:${String(m).padStart(2, "0")}:${ss}` : `${m}:${ss}`;
27
+ }
28
+ const NO_TIME = "–:––";
29
+ /**
30
+ * A held line's countdown label at `nowMs`: `formatHoldCountdown` of the
31
+ * seconds left, or the placeholder `–:––` while there is no clock yet
32
+ * (`nowMs` null) or the time does not parse. Null when no app holds the line,
33
+ * which draws no countdown.
34
+ */
35
+ function holdCountdownText(holdExpiresAt, nowMs) {
36
+ if (holdExpiresAt === null) return null;
37
+ const seconds = nowMs === null ? null : holdSecondsLeft(holdExpiresAt, nowMs);
38
+ return seconds === null ? NO_TIME : formatHoldCountdown(seconds);
39
+ }
40
+ export { formatHoldCountdown, holdCountdownText, holdSecondsLeft };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shop-on/theme-runtime",
3
- "version": "0.13.1",
3
+ "version": "0.14.0-next.0",
4
4
  "license": "SEE LICENSE IN dist/LICENSE.md",
5
5
  "files": [
6
6
  "dist"
@@ -8,8 +8,10 @@
8
8
  "type": "module",
9
9
  "exports": {
10
10
  ".": "./dist/index.js",
11
+ "./app-intercepts": "./dist/app-intercepts.js",
11
12
  "./badge-tags": "./dist/badge-tags.js",
12
13
  "./bytes": "./dist/bytes.js",
14
+ "./cart-hold": "./dist/cart-hold.js",
13
15
  "./cart-note": "./dist/cart-note.js",
14
16
  "./color": "./dist/color.js",
15
17
  "./fonts": "./dist/fonts.js",
@@ -33,7 +35,7 @@
33
35
  "./package.json": "./package.json"
34
36
  },
35
37
  "dependencies": {
36
- "@shop-on/theme-contract": "0.13.1",
38
+ "@shop-on/theme-contract": "0.14.0-next.0",
37
39
  "thumbhash": "0.1.1"
38
40
  },
39
41
  "devDependencies": {