@wix/himalaya-cli 0.1820.0 → 0.1822.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.
@@ -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 a = hhmm(start);
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 = hhmm(end);
122
+ const b = clock(end);
93
123
  if (!b || b === a) return a;
94
124
  return `${a} \u2013 ${b}`;
95
125
  }
96
- function durationLabel(start, end) {
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 `${m} min`;
105
- if (m === 0) return `${h} h`;
106
- return `${h} h ${m} min`;
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) || "Location to be announced";
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 hasIntl() {
178
- return typeof Intl !== "undefined" && typeof Intl.DateTimeFormat === "function";
179
- }
180
- function weekdayMonthDay(d) {
181
- if (hasIntl()) {
182
- return new Intl.DateTimeFormat("en", { weekday: "short", month: "short", day: "numeric" }).format(d);
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
- if (hasIntl()) {
188
- return new Intl.DateTimeFormat("en", { hour: "numeric", minute: "2-digit" }).format(d);
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(/[  ]/g, " ");
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) || "Date to be announced";
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 "Date to be announced";
212
- const date = s.getFullYear() === new Date(now).getFullYear() ? weekdayMonthDay(s) : `${weekdayMonthDay(s)}, ${s.getFullYear()}`;
213
- const time = clockTime(s);
214
- if (!end) return `${date} at ${time}`;
215
- const eDate = new Date(end);
216
- if (Number.isNaN(eDate.getTime()) || eDate.getTime() <= s.getTime()) return `${date} at ${time}`;
217
- return `${date} \xB7 ${clockRange(s, eDate)}`;
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 || "Event";
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()) ? MONTHS_SHORT[date.getMonth()].toUpperCase() : "",
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 ? "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 formatMoney(amount, currency) {
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("en", { style: "currency", currency, maximumFractionDigits: MAX_PRICE_DIGITS }).format(num);
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,