@wix/himalaya-cli 0.1821.0 → 0.1823.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/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/time/src/index.d.ts +22 -4
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/events/src/display.d.ts +20 -4
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/stores-v1/src/display.d.ts +10 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/time.mjs +56 -14
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-events.mjs +85 -33
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-stores.mjs +14 -4
- package/dist/cli.mjs +60 -46
- package/guides/release-notes.md +33 -0
- package/guides/sdk-reference.json +52 -10
- package/guides/testing-himi-apps.md +8 -0
- package/package.json +2 -2
package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/time/src/index.d.ts
CHANGED
|
@@ -88,9 +88,20 @@ export declare function addDays(when: DateLike, days: number): Date | null;
|
|
|
88
88
|
export declare function daysBetween(from: DateLike, to: DateLike): number;
|
|
89
89
|
/** True when both instants land on the same LOCAL calendar day. */
|
|
90
90
|
export declare function isSameDay(a: DateLike, b: DateLike): boolean;
|
|
91
|
+
/** Words this module writes itself. Each is optional; an override wins over the engine's own. */
|
|
92
|
+
export interface TimeLabels {
|
|
93
|
+
/** Heading for undated items in {@link groupByDay} (`dropUndated: false`). Default "Later". */
|
|
94
|
+
later?: string;
|
|
95
|
+
/** Minutes unit in {@link durationLabel}. Default "min" (English) or `Intl` unit style. */
|
|
96
|
+
minutes?: string;
|
|
97
|
+
/** Hours unit in {@link durationLabel}. Default "h" (English) or `Intl` unit style. */
|
|
98
|
+
hours?: string;
|
|
99
|
+
}
|
|
91
100
|
export interface LabelOptions {
|
|
92
|
-
/** BCP-47 locale. Defaults to the host's. */
|
|
101
|
+
/** BCP-47 locale. Defaults to the app's `@himalaya/l10n` locale, else the host's. */
|
|
93
102
|
locale?: string;
|
|
103
|
+
/** Override the words this module writes ("Later", "min", "h"). */
|
|
104
|
+
labels?: TimeLabels;
|
|
94
105
|
/** Anchor for the relative "Today"/"Tomorrow" window. Defaults to now. */
|
|
95
106
|
now?: DateLike;
|
|
96
107
|
/** Suppress the relative window and always format the date. */
|
|
@@ -137,10 +148,17 @@ export declare function timeLabel(when: DateLike, locale?: string): string;
|
|
|
137
148
|
* "09:00 – 09:45", collapsing to just the start when there is no end (or the
|
|
138
149
|
* end is not after the start). The separator is a space-padded en dash (U+2013),
|
|
139
150
|
* matching how the booking screens already render ranges.
|
|
151
|
+
*
|
|
152
|
+
* Follows the locale's hour cycle: an English (or unknown) locale keeps the 24-hour
|
|
153
|
+
* "09:00" this helper has always written, any other locale writes its own clock
|
|
154
|
+
* ("9:00 AM" where it is 12-hour, "09:00" where it is 24-hour).
|
|
140
155
|
*/
|
|
141
|
-
export declare function timeRange(start: DateLike, end: DateLike
|
|
142
|
-
|
|
143
|
-
|
|
156
|
+
export declare function timeRange(start: DateLike, end: DateLike, opts?: {
|
|
157
|
+
locale?: string;
|
|
158
|
+
}): string;
|
|
159
|
+
/** "45 min" / "1 h" / "1 h 30 min". Empty when the span is absent or non-positive. Under a
|
|
160
|
+
* non-English locale the units come from `Intl.NumberFormat` (unit style) when available. */
|
|
161
|
+
export declare function durationLabel(start: DateLike, end: DateLike, opts?: LabelOptions): string;
|
|
144
162
|
export interface GroupOptions extends LabelOptions {
|
|
145
163
|
/** Drop items whose start does not parse. Default true. */
|
|
146
164
|
dropUndated?: boolean;
|
|
@@ -18,6 +18,21 @@ export interface EventRow {
|
|
|
18
18
|
noImage: boolean;
|
|
19
19
|
detailScreenId: string;
|
|
20
20
|
}
|
|
21
|
+
/** The display copy a card shows. Keys are the runtime copy-catalog keys (`$t:` / `@himalaya/l10n`). */
|
|
22
|
+
export interface EventLabels {
|
|
23
|
+
"events.past": string;
|
|
24
|
+
"events.dateTba": string;
|
|
25
|
+
"events.locationTba": string;
|
|
26
|
+
"events.untitled": string;
|
|
27
|
+
}
|
|
28
|
+
/** Generated English defaults — the last stop before the key itself. */
|
|
29
|
+
export declare const EVENT_LABEL_DEFAULTS: Readonly<EventLabels>;
|
|
30
|
+
export interface EventDisplayOptions {
|
|
31
|
+
/** BCP-47 tag. Defaults to the app's `@himalaya/l10n` `locale()`, else "en". */
|
|
32
|
+
locale?: string;
|
|
33
|
+
/** Per-key copy overrides; beat the served catalog and the English default. */
|
|
34
|
+
labels?: Partial<EventLabels>;
|
|
35
|
+
}
|
|
21
36
|
export declare function titleCase(value?: string): string;
|
|
22
37
|
export declare function startDateOf(e: WixEvent): string | undefined;
|
|
23
38
|
export declare function endDateOf(e: WixEvent): string | undefined;
|
|
@@ -30,15 +45,16 @@ export declare function endDateOf(e: WixEvent): string | undefined;
|
|
|
30
45
|
* `WIX_DETAIL_IMAGE` for a full-bleed hero.
|
|
31
46
|
*/
|
|
32
47
|
export declare function eventImage(e: WixEvent, size?: WixImageSize | null): string;
|
|
33
|
-
export declare function eventLocation(e: WixEvent): string;
|
|
48
|
+
export declare function eventLocation(e: WixEvent, options?: EventDisplayOptions): string;
|
|
34
49
|
export declare function eventAddress(e: WixEvent): string;
|
|
35
50
|
export declare function eventMapUrl(e: WixEvent): string;
|
|
36
51
|
export declare function eventStartMillis(e: WixEvent): number | undefined;
|
|
37
52
|
export declare function eventEndMillis(e: WixEvent): number | undefined;
|
|
38
53
|
/** The event's date line. The year is written only when it is not the current year, so a
|
|
39
54
|
* past-year event can no longer pass for an upcoming one ("Sat, Jul 18"). `now` is injectable
|
|
40
|
-
* for tests; it defaults to the wall clock.
|
|
41
|
-
|
|
55
|
+
* for tests; it defaults to the wall clock. Under a non-English locale with ECMA-402 the date and
|
|
56
|
+
* time come from one locale-ordered formatter, so the English " at " never leaks in. */
|
|
57
|
+
export declare function eventWhen(e: WixEvent, now?: number, options?: EventDisplayOptions): string;
|
|
42
58
|
/** Has the event finished? Its end when it has one, else its start. */
|
|
43
59
|
export declare function eventIsPast(e: WixEvent, now?: number): boolean;
|
|
44
60
|
/** One-argument on purpose: callers write `.map(normalizeEvent)`, which would pass the array
|
|
@@ -46,5 +62,5 @@ export declare function eventIsPast(e: WixEvent, now?: number): boolean;
|
|
|
46
62
|
export declare function normalizeEvent(e: WixEvent): EventRow;
|
|
47
63
|
/** {@link normalizeEvent} against an explicit clock (epoch ms): `now` decides whether the date
|
|
48
64
|
* line carries the year and whether `statusLabel` reads "Past". Pure — no API call, any scope. */
|
|
49
|
-
export declare function normalizeEventAt(e: WixEvent, now: number): EventRow;
|
|
65
|
+
export declare function normalizeEventAt(e: WixEvent, now: number, options?: EventDisplayOptions): EventRow;
|
|
50
66
|
export declare function eventDescription(e: WixEvent): string;
|
|
@@ -195,9 +195,18 @@ export declare function productImage(p: StoreProduct, size?: WixImageSize | null
|
|
|
195
195
|
* `WIX_DETAIL_IMAGE` for a full-bleed pager, or `null` for the stored originals.
|
|
196
196
|
*/
|
|
197
197
|
export declare function productGallery(p: StoreProduct, size?: WixImageSize | null): string[];
|
|
198
|
+
/** Display options for the price helpers. Prices carry no copy, so there are no labels to override. */
|
|
199
|
+
export interface StoreDisplayOptions {
|
|
200
|
+
/** BCP-47 tag; callers pass their app locale. Defaults to "en". */
|
|
201
|
+
locale?: string;
|
|
202
|
+
}
|
|
203
|
+
/** Format a raw amount with a currency when one is known. Prefers a real symbol via
|
|
204
|
+
* Intl; falls back to the bare amount when the catalog exposes no currency (e.g. a
|
|
205
|
+
* visitor querying a store that only returns `amount`). */
|
|
206
|
+
export declare function formatMoney(amount: string | number, currency: string, options?: StoreDisplayOptions): string;
|
|
198
207
|
/** Formats Wix-provided price text consistently for display. A recognized symbol after an
|
|
199
208
|
* English-style number moves before the amount; locale-specific decimal and grouping formats
|
|
200
209
|
* remain unchanged. */
|
|
201
210
|
export declare function normalizeFormattedPrice(formatted: string): string;
|
|
202
|
-
export declare function productPrice(p: StoreProduct): string;
|
|
211
|
+
export declare function productPrice(p: StoreProduct, options?: StoreDisplayOptions): string;
|
|
203
212
|
export declare function plainText(value?: string): string;
|
|
@@ -49,6 +49,24 @@ function isSameDay(a, b) {
|
|
|
49
49
|
const ka = dayKey(a);
|
|
50
50
|
return ka !== "" && ka === dayKey(b);
|
|
51
51
|
}
|
|
52
|
+
function appLocale() {
|
|
53
|
+
try {
|
|
54
|
+
const caps = globalThis.himalaya?.capabilities;
|
|
55
|
+
if (!Array.isArray(caps) || !caps.includes("l10n")) return void 0;
|
|
56
|
+
const lookup = "__himalaya_l10n" in globalThis ? globalThis.__himalaya_l10n : void 0;
|
|
57
|
+
if (typeof lookup !== "function") return void 0;
|
|
58
|
+
const data = JSON.parse(lookup(null));
|
|
59
|
+
return data && !data.error && typeof data.locale === "string" && data.locale ? data.locale : void 0;
|
|
60
|
+
} catch {
|
|
61
|
+
return void 0;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function resolveLocale(explicit) {
|
|
65
|
+
return explicit || appLocale();
|
|
66
|
+
}
|
|
67
|
+
function isEnglish(locale) {
|
|
68
|
+
return !locale || /^en(?:[-_]|$)/i.test(locale);
|
|
69
|
+
}
|
|
52
70
|
var RELATIVE_FALLBACK = ["Yesterday", "Today", "Tomorrow"];
|
|
53
71
|
function relativeDayWord(diff, opts) {
|
|
54
72
|
const override = opts.relativeLabels;
|
|
@@ -57,7 +75,7 @@ function relativeDayWord(diff, opts) {
|
|
|
57
75
|
const RTF = globalThis.Intl?.RelativeTimeFormat;
|
|
58
76
|
if (typeof RTF === "function") {
|
|
59
77
|
try {
|
|
60
|
-
const words = new RTF(opts.locale, { numeric: "auto" }).format(diff, "day");
|
|
78
|
+
const words = new RTF(resolveLocale(opts.locale), { numeric: "auto" }).format(diff, "day");
|
|
61
79
|
if (words) return words.charAt(0).toUpperCase() + words.slice(1);
|
|
62
80
|
} catch {
|
|
63
81
|
}
|
|
@@ -72,7 +90,7 @@ function dayLabel(when, opts = {}) {
|
|
|
72
90
|
if (diff === 0 || diff === 1 || diff === -1) return relativeDayWord(diff, opts);
|
|
73
91
|
}
|
|
74
92
|
return d.toLocaleDateString(
|
|
75
|
-
opts.locale,
|
|
93
|
+
resolveLocale(opts.locale),
|
|
76
94
|
opts.format === "compact" ? { weekday: "short", day: "numeric" } : { weekday: "short", month: "short", day: "numeric" }
|
|
77
95
|
);
|
|
78
96
|
}
|
|
@@ -84,16 +102,40 @@ function hhmm(when) {
|
|
|
84
102
|
function timeLabel(when, locale) {
|
|
85
103
|
const d = toDate(when);
|
|
86
104
|
if (!d) return "";
|
|
87
|
-
return d.toLocaleTimeString(locale, { hour: "numeric", minute: "2-digit" });
|
|
105
|
+
return d.toLocaleTimeString(resolveLocale(locale), { hour: "numeric", minute: "2-digit" });
|
|
88
106
|
}
|
|
89
|
-
function timeRange(start, end) {
|
|
90
|
-
const
|
|
107
|
+
function timeRange(start, end, opts = {}) {
|
|
108
|
+
const locale = resolveLocale(opts.locale);
|
|
109
|
+
const clock = (when) => {
|
|
110
|
+
const d = toDate(when);
|
|
111
|
+
if (!d) return "";
|
|
112
|
+
if (!isEnglish(locale) && typeof Intl !== "undefined") {
|
|
113
|
+
try {
|
|
114
|
+
return new Intl.DateTimeFormat(locale, { hour: "numeric", minute: "2-digit" }).format(d);
|
|
115
|
+
} catch {
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return hhmm(when);
|
|
119
|
+
};
|
|
120
|
+
const a = clock(start);
|
|
91
121
|
if (!a) return "";
|
|
92
|
-
const b =
|
|
122
|
+
const b = clock(end);
|
|
93
123
|
if (!b || b === a) return a;
|
|
94
124
|
return `${a} \u2013 ${b}`;
|
|
95
125
|
}
|
|
96
|
-
function
|
|
126
|
+
function durationPart(n, unit, opts) {
|
|
127
|
+
const override = unit === "minute" ? opts.labels?.minutes : opts.labels?.hours;
|
|
128
|
+
if (override) return `${n} ${override}`;
|
|
129
|
+
const locale = resolveLocale(opts.locale);
|
|
130
|
+
if (!isEnglish(locale) && typeof Intl !== "undefined") {
|
|
131
|
+
try {
|
|
132
|
+
return new Intl.NumberFormat(locale, { style: "unit", unit, unitDisplay: "short" }).format(n);
|
|
133
|
+
} catch {
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return unit === "minute" ? `${n} min` : `${n} h`;
|
|
137
|
+
}
|
|
138
|
+
function durationLabel(start, end, opts = {}) {
|
|
97
139
|
const a = toDate(start);
|
|
98
140
|
const b = toDate(end);
|
|
99
141
|
if (!a || !b) return "";
|
|
@@ -101,9 +143,9 @@ function durationLabel(start, end) {
|
|
|
101
143
|
if (mins <= 0) return "";
|
|
102
144
|
const h = Math.floor(mins / 60);
|
|
103
145
|
const m = mins % 60;
|
|
104
|
-
if (h === 0) return
|
|
105
|
-
if (m === 0) return
|
|
106
|
-
return `${h}
|
|
146
|
+
if (h === 0) return durationPart(m, "minute", opts);
|
|
147
|
+
if (m === 0) return durationPart(h, "hour", opts);
|
|
148
|
+
return `${durationPart(h, "hour", opts)} ${durationPart(m, "minute", opts)}`;
|
|
107
149
|
}
|
|
108
150
|
function groupByDay(items, getStart, opts = {}) {
|
|
109
151
|
const buckets = /* @__PURE__ */ new Map();
|
|
@@ -125,7 +167,7 @@ function groupByDay(items, getStart, opts = {}) {
|
|
|
125
167
|
items: bucket.items
|
|
126
168
|
}));
|
|
127
169
|
if (undated.length && opts.dropUndated === false) {
|
|
128
|
-
groups.push({ key: "", label: "Later", items: undated });
|
|
170
|
+
groups.push({ key: "", label: opts.labels?.later ?? "Later", items: undated });
|
|
129
171
|
}
|
|
130
172
|
return groups;
|
|
131
173
|
}
|
|
@@ -167,7 +209,7 @@ function weekdayLabels(firstWeekday = 0, locale, width = "short") {
|
|
|
167
209
|
const anchor = new Date(2024, 0, 7);
|
|
168
210
|
for (let i = 0; i < 7; i++) {
|
|
169
211
|
const d = new Date(anchor.getFullYear(), anchor.getMonth(), anchor.getDate() + firstWeekday + i);
|
|
170
|
-
out.push(d.toLocaleDateString(locale, { weekday: width }));
|
|
212
|
+
out.push(d.toLocaleDateString(resolveLocale(locale), { weekday: width }));
|
|
171
213
|
}
|
|
172
214
|
return out;
|
|
173
215
|
}
|
|
@@ -183,8 +225,8 @@ function slotsToEvents(entries, opts = {}) {
|
|
|
183
225
|
// any shared start time; prefix them with the service id in that case,
|
|
184
226
|
// because a keyed list dedupes on collision and would drop rows.
|
|
185
227
|
id: start,
|
|
186
|
-
title: opts.title ? opts.title(e) : timeRange(start, end),
|
|
187
|
-
subtitle: durationLabel(start, end),
|
|
228
|
+
title: opts.title ? opts.title(e) : timeRange(start, end, opts),
|
|
229
|
+
subtitle: durationLabel(start, end, opts),
|
|
188
230
|
start,
|
|
189
231
|
end,
|
|
190
232
|
colorToken: opts.colorToken
|
|
@@ -83,6 +83,37 @@ function wixMediaUrl(value, size = WIX_LIST_IMAGE) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
// ../../stdlib/wix-sdk/events/src/display.ts
|
|
86
|
+
var EVENT_LABEL_DEFAULTS = {
|
|
87
|
+
"events.past": "Past",
|
|
88
|
+
"events.dateTba": "Date to be announced",
|
|
89
|
+
"events.locationTba": "Location to be announced",
|
|
90
|
+
"events.untitled": "Event"
|
|
91
|
+
};
|
|
92
|
+
function l10nRead(key) {
|
|
93
|
+
try {
|
|
94
|
+
const caps = globalThis.himalaya?.capabilities;
|
|
95
|
+
if (!Array.isArray(caps) || !caps.includes("l10n")) return {};
|
|
96
|
+
const lookup = "__himalaya_l10n" in globalThis ? globalThis.__himalaya_l10n : void 0;
|
|
97
|
+
if (typeof lookup !== "function") return {};
|
|
98
|
+
const data = JSON.parse(lookup(key));
|
|
99
|
+
if (!data || typeof data !== "object" || data.error) return {};
|
|
100
|
+
return {
|
|
101
|
+
locale: typeof data.locale === "string" && data.locale ? data.locale : void 0,
|
|
102
|
+
message: typeof data.message === "string" && data.message ? data.message : void 0
|
|
103
|
+
};
|
|
104
|
+
} catch {
|
|
105
|
+
return {};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function resolveLocale(options) {
|
|
109
|
+
return options?.locale || l10nRead(null).locale || "en";
|
|
110
|
+
}
|
|
111
|
+
function label(key, options) {
|
|
112
|
+
return options?.labels?.[key] ?? l10nRead(key).message ?? EVENT_LABEL_DEFAULTS[key];
|
|
113
|
+
}
|
|
114
|
+
function isEnglish(locale) {
|
|
115
|
+
return /^en(?:[-_]|$)/i.test(locale);
|
|
116
|
+
}
|
|
86
117
|
function titleCase(value) {
|
|
87
118
|
return (value || "").toLowerCase().split(/[_\s-]+/).filter(Boolean).map((part) => part[0].toUpperCase() + part.slice(1)).join(" ");
|
|
88
119
|
}
|
|
@@ -101,9 +132,9 @@ function eventImage(e, size = WIX_LIST_IMAGE) {
|
|
|
101
132
|
const url = typeof raw.mainImage === "string" ? raw.mainImage : raw.mainImage?.url || raw.imageUrl || "";
|
|
102
133
|
return wixMediaUrl(url, size);
|
|
103
134
|
}
|
|
104
|
-
function eventLocation(e) {
|
|
135
|
+
function eventLocation(e, options) {
|
|
105
136
|
const loc = e.location;
|
|
106
|
-
return loc?.name || addressText(loc?.address) || titleCase(loc?.type) || "
|
|
137
|
+
return loc?.name || addressText(loc?.address) || titleCase(loc?.type) || label("events.locationTba", options);
|
|
107
138
|
}
|
|
108
139
|
function addressText(value) {
|
|
109
140
|
if (typeof value === "string") return value;
|
|
@@ -174,47 +205,67 @@ var MONTHS_SHORT = [
|
|
|
174
205
|
"Nov",
|
|
175
206
|
"Dec"
|
|
176
207
|
];
|
|
177
|
-
function
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
208
|
+
function formatter(locale, opts) {
|
|
209
|
+
if (typeof Intl !== "undefined" && typeof Intl.DateTimeFormat === "function") {
|
|
210
|
+
try {
|
|
211
|
+
return new Intl.DateTimeFormat(locale, opts);
|
|
212
|
+
} catch {
|
|
213
|
+
}
|
|
183
214
|
}
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
function weekdayMonthDay(d, locale) {
|
|
218
|
+
const f = formatter(locale, { weekday: "short", month: "short", day: "numeric" });
|
|
219
|
+
if (f) return f.format(d);
|
|
184
220
|
return `${WEEKDAYS_SHORT[d.getDay()]}, ${MONTHS_SHORT[d.getMonth()]} ${d.getDate()}`;
|
|
185
221
|
}
|
|
186
|
-
function clockTime(d) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
222
|
+
function clockTime(d, locale) {
|
|
223
|
+
const f = formatter(locale, { hour: "numeric", minute: "2-digit" });
|
|
224
|
+
if (f) return f.format(d);
|
|
190
225
|
const h = d.getHours();
|
|
191
226
|
const hour = h % 12 === 0 ? 12 : h % 12;
|
|
192
227
|
const minute = d.getMinutes();
|
|
193
228
|
return `${hour}:${minute < 10 ? `0${minute}` : minute} ${h < 12 ? "AM" : "PM"}`;
|
|
194
229
|
}
|
|
195
|
-
function clockParts(d) {
|
|
196
|
-
const clean = clockTime(d).replace(/[
|
|
230
|
+
function clockParts(d, locale) {
|
|
231
|
+
const clean = clockTime(d, locale).replace(/[\u202f\u00a0]/g, " ");
|
|
197
232
|
const m = /^(.*?)\s*([AP]M)$/i.exec(clean);
|
|
198
233
|
return m ? { time: m[1], meridiem: m[2] } : { time: clean, meridiem: "" };
|
|
199
234
|
}
|
|
200
|
-
function clockRange(s, e) {
|
|
201
|
-
const a = clockParts(s);
|
|
202
|
-
const b = clockParts(e);
|
|
235
|
+
function clockRange(s, e, locale) {
|
|
236
|
+
const a = clockParts(s, locale);
|
|
237
|
+
const b = clockParts(e, locale);
|
|
203
238
|
const same = !!a.meridiem && a.meridiem === b.meridiem && e.getTime() - s.getTime() < 12 * 3600 * 1e3;
|
|
204
|
-
return `${same ? a.time : clockTime(s)} \u2013 ${clockTime(e)}`;
|
|
239
|
+
return `${same ? a.time : clockTime(s, locale)} \u2013 ${clockTime(e, locale)}`;
|
|
205
240
|
}
|
|
206
|
-
function eventWhen(e, now = Date.now()) {
|
|
241
|
+
function eventWhen(e, now = Date.now(), options) {
|
|
207
242
|
const start = startDateOf(e);
|
|
208
243
|
const end = endDateOf(e);
|
|
209
|
-
if (!start) return titleCase(e.eventStatus) || "
|
|
244
|
+
if (!start) return titleCase(e.eventStatus) || label("events.dateTba", options);
|
|
210
245
|
const s = new Date(start);
|
|
211
|
-
if (Number.isNaN(s.getTime())) return "
|
|
212
|
-
const
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
if (
|
|
217
|
-
|
|
246
|
+
if (Number.isNaN(s.getTime())) return label("events.dateTba", options);
|
|
247
|
+
const locale = resolveLocale(options);
|
|
248
|
+
const withYear = s.getFullYear() !== new Date(now).getFullYear();
|
|
249
|
+
const eDate = end ? new Date(end) : null;
|
|
250
|
+
const ranged = !!eDate && !Number.isNaN(eDate.getTime()) && eDate.getTime() > s.getTime();
|
|
251
|
+
if (!isEnglish(locale)) {
|
|
252
|
+
const day = { weekday: "short", month: "short", day: "numeric" };
|
|
253
|
+
if (withYear) day.year = "numeric";
|
|
254
|
+
const dateFmt = formatter(locale, day);
|
|
255
|
+
if (dateFmt) {
|
|
256
|
+
if (ranged) return `${dateFmt.format(s)} \xB7 ${clockRange(s, eDate, locale)}`;
|
|
257
|
+
const full = formatter(locale, { ...day, hour: "numeric", minute: "2-digit" });
|
|
258
|
+
if (full) return full.format(s);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
const date = withYear ? `${weekdayMonthDay(s, locale)}, ${s.getFullYear()}` : weekdayMonthDay(s, locale);
|
|
262
|
+
const time = clockTime(s, locale);
|
|
263
|
+
if (!ranged) return `${date} at ${time}`;
|
|
264
|
+
return `${date} \xB7 ${clockRange(s, eDate, locale)}`;
|
|
265
|
+
}
|
|
266
|
+
function monthShort(d, locale) {
|
|
267
|
+
const f = isEnglish(locale) ? null : formatter(locale, { month: "short" });
|
|
268
|
+
return (f ? f.format(d) : MONTHS_SHORT[d.getMonth()]).toUpperCase();
|
|
218
269
|
}
|
|
219
270
|
function eventIsPast(e, now = Date.now()) {
|
|
220
271
|
const ms = eventEndMillis(e) ?? eventStartMillis(e);
|
|
@@ -223,9 +274,9 @@ function eventIsPast(e, now = Date.now()) {
|
|
|
223
274
|
function normalizeEvent(e) {
|
|
224
275
|
return normalizeEventAt(e, Date.now());
|
|
225
276
|
}
|
|
226
|
-
function normalizeEventAt(e, now) {
|
|
277
|
+
function normalizeEventAt(e, now, options) {
|
|
227
278
|
const id = e.id || e.title || "event";
|
|
228
|
-
const title = e.title || "
|
|
279
|
+
const title = e.title || label("events.untitled", options);
|
|
229
280
|
const start = startDateOf(e);
|
|
230
281
|
const date = start ? new Date(start) : null;
|
|
231
282
|
const image = eventImage(e);
|
|
@@ -236,13 +287,13 @@ function normalizeEventAt(e, now) {
|
|
|
236
287
|
day: date && !Number.isNaN(date.getTime()) ? String(date.getDate()) : title.slice(0, 1).toUpperCase(),
|
|
237
288
|
// From the fixed table, not `toLocaleString`: QuickJS (the watch engine) has no ECMA-402 and
|
|
238
289
|
// answers that call with the whole "11/10/2030, 12:00:00 PM" string.
|
|
239
|
-
month: date && !Number.isNaN(date.getTime()) ?
|
|
240
|
-
dateLine: eventWhen(e, now),
|
|
290
|
+
month: date && !Number.isNaN(date.getTime()) ? monthShort(date, resolveLocale(options)) : "",
|
|
291
|
+
dateLine: eventWhen(e, now, options),
|
|
241
292
|
// "Past" for a finished event, "" otherwise — the shared collection row prints it in the
|
|
242
293
|
// meta line, so an event from last month no longer reads as current.
|
|
243
|
-
statusLabel: past ? "
|
|
294
|
+
statusLabel: past ? label("events.past", options) : "",
|
|
244
295
|
isPast: past,
|
|
245
|
-
location: eventLocation(e),
|
|
296
|
+
location: eventLocation(e, options),
|
|
246
297
|
status: titleCase(e.eventStatus) || titleCase(e.status),
|
|
247
298
|
image,
|
|
248
299
|
hasImage: !!image,
|
|
@@ -407,6 +458,7 @@ function getEventsOrder(eventId, orderNumber) {
|
|
|
407
458
|
);
|
|
408
459
|
}
|
|
409
460
|
export {
|
|
461
|
+
EVENT_LABEL_DEFAULTS,
|
|
410
462
|
EVENT_STATUSES,
|
|
411
463
|
cancelTicketReservation,
|
|
412
464
|
checkoutReservation,
|
|
@@ -558,12 +558,21 @@ function roundHalfExpand(abs, digits) {
|
|
|
558
558
|
return Number.isFinite(back) ? back : abs;
|
|
559
559
|
}
|
|
560
560
|
var MAX_PRICE_DIGITS = 2;
|
|
561
|
-
function
|
|
561
|
+
function resolveLocale(options) {
|
|
562
|
+
const given = (options && typeof options === "object" ? options.locale : void 0) || "en";
|
|
563
|
+
try {
|
|
564
|
+
if (hasIntl() && Intl.NumberFormat.supportedLocalesOf(given).length === 0) return "en";
|
|
565
|
+
} catch {
|
|
566
|
+
return "en";
|
|
567
|
+
}
|
|
568
|
+
return given;
|
|
569
|
+
}
|
|
570
|
+
function formatMoney(amount, currency, options) {
|
|
562
571
|
const num = typeof amount === "number" ? amount : Number(amount);
|
|
563
572
|
if (currency && Number.isFinite(num)) {
|
|
564
573
|
if (hasIntl()) {
|
|
565
574
|
try {
|
|
566
|
-
return new Intl.NumberFormat(
|
|
575
|
+
return new Intl.NumberFormat(resolveLocale(options), { style: "currency", currency, maximumFractionDigits: MAX_PRICE_DIGITS }).format(num);
|
|
567
576
|
} catch {
|
|
568
577
|
}
|
|
569
578
|
} else {
|
|
@@ -600,12 +609,12 @@ function normalizeFormattedPrice(formatted) {
|
|
|
600
609
|
function productCurrency(p) {
|
|
601
610
|
return p.currency || p.priceData?.currency || p.price?.currency || p.actualPriceRange?.minValue?.currency || "";
|
|
602
611
|
}
|
|
603
|
-
function productPrice(p) {
|
|
612
|
+
function productPrice(p, options) {
|
|
604
613
|
const preformatted = p.priceData?.formatted?.price || p.price?.formatted?.price || p.actualPriceRange?.minValue?.formattedAmount;
|
|
605
614
|
if (preformatted) return normalizeFormattedPrice(preformatted);
|
|
606
615
|
const amount = p.priceData?.price != null ? p.priceData.price : p.price?.price != null ? p.price.price : p.actualPriceRange?.minValue?.amount ?? "";
|
|
607
616
|
if (amount === "" || amount == null) return "";
|
|
608
|
-
return formatMoney(amount, productCurrency(p));
|
|
617
|
+
return formatMoney(amount, productCurrency(p), options);
|
|
609
618
|
}
|
|
610
619
|
function plainText(value) {
|
|
611
620
|
return (value || "").replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim();
|
|
@@ -870,6 +879,7 @@ export {
|
|
|
870
879
|
defaultSelection,
|
|
871
880
|
deleteProduct,
|
|
872
881
|
forgetCatalogVersion2 as forgetCatalogVersion,
|
|
882
|
+
formatMoney,
|
|
873
883
|
getProduct,
|
|
874
884
|
getStoreProduct,
|
|
875
885
|
isSelectionComplete,
|