@escape-game-over/atlas 0.1.92 → 0.1.94

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@escape-game-over/atlas",
3
- "version": "0.1.92",
3
+ "version": "0.1.94",
4
4
  "type": "module",
5
5
  "description": "Typed, data-driven machinery for static multi-locale, multi-deployment Astro sites.",
6
6
  "private": false,
@@ -275,13 +275,19 @@ const CATEGORY_SIGNALS: Readonly<
275
275
  marketing: ["adStorage", "adUserData", "adPersonalization"],
276
276
  };
277
277
 
278
- /** The signals no answer grants — see `CATEGORY_SIGNALS`. */
279
- const UNASKED = SIGNAL_KEYS.filter(
280
- (key) =>
281
- !CONSENT_CATEGORIES.some((category) =>
282
- CATEGORY_SIGNALS[category].includes(key)
283
- )
284
- );
278
+ /**
279
+ * The signals no answer grants — see `CATEGORY_SIGNALS`. A function, not a
280
+ * value worked out at import: browser bundles import this file for its
281
+ * consent constants and would otherwise compute it on every page.
282
+ */
283
+ function unasked(): readonly (keyof ConsentDefaults)[] {
284
+ return SIGNAL_KEYS.filter(
285
+ (key) =>
286
+ !CONSENT_CATEGORIES.some((category) =>
287
+ CATEGORY_SIGNALS[category].includes(key)
288
+ )
289
+ );
290
+ }
285
291
 
286
292
  /**
287
293
  * What `google-tag.ts` is handed: the settings, already in Google's own names.
@@ -435,7 +441,7 @@ export function googleScripts(
435
441
  }
436
442
 
437
443
  const consent = google.consent ?? DENIED_BY_DEFAULT;
438
- for (const key of UNASKED) {
444
+ for (const key of unasked()) {
439
445
  if (consent.some((given) => given[key] === "denied")) {
440
446
  warn(
441
447
  at,
package/src/hours.ts CHANGED
@@ -356,27 +356,18 @@ export function schemaDays(group: HoursGroup): readonly string[] {
356
356
  }
357
357
 
358
358
  /**
359
- * The day before each day, and the day after, written out rather than worked
360
- * out from positions in `WEEK`.
359
+ * The day `offset` days from `day`: -1 is yesterday, 1 is tomorrow.
360
+ *
361
+ * The week wraps around, so the index is taken modulo 7. The `+ 7` keeps it
362
+ * from going negative: the day before Monday is `(0 - 1 + 7) % 7 = 6`, Sunday.
361
363
  */
362
- const YESTERDAY: Readonly<Record<Weekday, Weekday>> = {
363
- monday: "sunday",
364
- tuesday: "monday",
365
- wednesday: "tuesday",
366
- thursday: "wednesday",
367
- friday: "thursday",
368
- saturday: "friday",
369
- sunday: "saturday",
370
- };
371
- const TOMORROW: Readonly<Record<Weekday, Weekday>> = {
372
- monday: "tuesday",
373
- tuesday: "wednesday",
374
- wednesday: "thursday",
375
- thursday: "friday",
376
- friday: "saturday",
377
- saturday: "sunday",
378
- sunday: "monday",
379
- };
364
+ function dayFrom(day: Weekday, offset: -1 | 1): Weekday {
365
+ const next = WEEK[(WEEK.indexOf(day) + offset + 7) % 7];
366
+ if (next === undefined) {
367
+ throw new Error(`No day ${offset} from ${day}.`);
368
+ }
369
+ return next;
370
+ }
380
371
 
381
372
  /**
382
373
  * The venue's wall clock at `now`: the day, and the time.
@@ -473,7 +464,7 @@ export function openStatus(
473
464
  function statusAt(hours: WeeklyHours, day: Weekday, time: string): OpenStatus {
474
465
  // 1. Still in last night's opening: yesterday has a span past midnight
475
466
  // (`14:00`–`00:45`) and it is not yet 00:45.
476
- const lateYesterday = spansOn(hours, YESTERDAY[day]).find(
467
+ const lateYesterday = spansOn(hours, dayFrom(day, -1)).find(
477
468
  (range) => pastMidnight(range) && time < range.closes
478
469
  );
479
470
  if (lateYesterday !== undefined) {
@@ -499,7 +490,7 @@ function statusAt(hours: WeeklyHours, day: Weekday, time: string): OpenStatus {
499
490
  }
500
491
 
501
492
  // 4. Done for today: when tomorrow's first span opens.
502
- const [tomorrow] = spansOn(hours, TOMORROW[day]);
493
+ const [tomorrow] = spansOn(hours, dayFrom(day, 1));
503
494
  if (tomorrow !== undefined) {
504
495
  return { state: "opensTomorrow", time: tomorrow.opens };
505
496
  }
package/src/warn.ts CHANGED
@@ -43,19 +43,22 @@ const RESET = `${ESC}[0m`;
43
43
  * `process` and simply gets colour, which is what a browser console renders
44
44
  * anyway.
45
45
  */
46
- const env = (
47
- globalThis as {
48
- process?: { env?: Readonly<Record<string, string | undefined>> };
49
- }
50
- ).process?.env;
46
+ const env = () =>
47
+ (
48
+ globalThis as {
49
+ process?: { env?: Readonly<Record<string, string | undefined>> };
50
+ }
51
+ ).process?.env;
51
52
 
52
- const colour = env?.NO_COLOR === undefined;
53
+ // Functions, not values worked out at import: a browser bundle that imports
54
+ // anything near this file would otherwise run the reads on every page.
55
+ const colour = (): boolean => env()?.NO_COLOR === undefined;
53
56
 
54
57
  /** Read per call rather than once, so a test can switch it. */
55
- const strict = (): boolean => env?.ATLAS_STRICT === "1";
58
+ const strict = (): boolean => env()?.ATLAS_STRICT === "1";
56
59
 
57
60
  const paint = (code: string, text: string): string =>
58
- colour ? `${code}${text}${RESET}` : text;
61
+ colour() ? `${code}${text}${RESET}` : text;
59
62
 
60
63
  /**
61
64
  * Warns about one page, or one file.