@usequeek/theme-kit 0.1.31 → 0.1.33

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/apps/gtag.ts CHANGED
@@ -6,14 +6,29 @@ declare global {
6
6
  }
7
7
  }
8
8
 
9
+ type GtagParams = Record<string, unknown>;
10
+
9
11
  /**
10
- * Pushes straight to `dataLayer` rather than calling `window.gtag()` directly —
11
- * this queues correctly even before gtag.js has finished loading (the same
12
- * mechanism the inline bootstrap snippet in analytics.tsx relies on), so
13
- * callers never need to guard on load order.
12
+ * Pushes to `dataLayer` rather than calling `window.gtag()` directly — this
13
+ * queues correctly even before gtag.js has finished loading (the same
14
+ * mechanism the inline bootstrap snippet in the storefront's analytics host
15
+ * relies on), so callers never need to guard on load order.
16
+ *
17
+ * It MUST push the function's `arguments` object, never an array built from it.
18
+ * gtag.js only processes `arguments` objects found on `dataLayer`; Google's own
19
+ * snippet is `function gtag(){dataLayer.push(arguments);}` for exactly that
20
+ * reason, and a plain array is silently ignored (the event is never sent). That
21
+ * is why this is a non-arrow `function` with no rest parameter: the overloads
22
+ * below carry the types, and the implementation forwards `arguments` untouched.
14
23
  */
15
- export function gtagPush(...args: unknown[]): void {
24
+ export function gtagPush(command: 'js', date: Date): void;
25
+ export function gtagPush(command: 'config', targetId: string, params?: GtagParams): void;
26
+ export function gtagPush(command: 'set', params: GtagParams): void;
27
+ export function gtagPush(command: 'event', eventName: string, params?: GtagParams): void;
28
+ export function gtagPush(command: 'consent', action: 'default' | 'update', params: GtagParams): void;
29
+ export function gtagPush(): void {
16
30
  if (typeof window === 'undefined') return;
17
31
  window.dataLayer = window.dataLayer || [];
18
- window.dataLayer.push(args);
32
+ // eslint-disable-next-line prefer-rest-params -- gtag.js reads only `arguments` objects (see above)
33
+ window.dataLayer.push(arguments);
19
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usequeek/theme-kit",
3
- "version": "0.1.31",
3
+ "version": "0.1.33",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "The runtime a Queek storefront theme is built on: hooks, stores, page renderer, navigation, shared blocks and locale strings.",
package/utils/brand.ts CHANGED
@@ -227,6 +227,29 @@ function pickReadableTextColor(hex: string): string {
227
227
  return onWhite >= onBlack ? '#ffffff' : '#000000';
228
228
  }
229
229
 
230
+ /** How far a failing white-on-accent pairing may be deepened before it stops being the vendor's colour: past
231
+ * this the label flips to black instead (a pale yellow keeps its look, with black text). */
232
+ const MAX_ACCENT_DEEPENING = 0.25;
233
+
234
+ /** The smallest deepening of `accent` (by `shade`) at which `onAccent` reads at the AA minimum, or null within the bound. */
235
+ function deepenAccentFor(accent: string, onAccent: string): string | null {
236
+ for (let step = 1; step <= MAX_ACCENT_DEEPENING * 100; step += 1) {
237
+ const candidate = shade(accent, step / 100);
238
+ if ((contrastRatio(candidate, onAccent) ?? 0) >= MIN_ON_ACCENT_CONTRAST) return candidate;
239
+ }
240
+ return null;
241
+ }
242
+
243
+ /** `fill` itself, or its deepened form when a lighter `label` fails 4.5:1 on it and a bounded deepening fixes that. */
244
+ function readableFill(fill: string, label: string): string {
245
+ // A legacy colour set can leave the primary unset: nothing to deepen.
246
+ if (!fill || !label) return fill;
247
+ const ratio = contrastRatio(fill, label);
248
+ if (ratio === null || ratio >= MIN_ON_ACCENT_CONTRAST) return fill;
249
+ if ((relativeLuminance(label) ?? 0) <= (relativeLuminance(fill) ?? 0)) return fill;
250
+ return deepenAccentFor(fill, label) ?? fill;
251
+ }
252
+
230
253
  /**
231
254
  * Guards against `on_accent` silently pairing with an `accent` it was never
232
255
  * designed for. `accent` and `on_accent` are independent fields (see
@@ -236,12 +259,23 @@ function pickReadableTextColor(hex: string): string {
236
259
  * shape at all, so `on_accent` falls through to the THEME's own default,
237
260
  * tuned for the theme's own accent color, not the vendor's. Only corrects
238
261
  * when the pairing actually fails contrast; a theme's own (already-tuned)
239
- * accent/on_accent pair is never touched. */
240
- function ensureReadableOnAccent(color: DesignTokenColor & { accent: string; on_accent: string }): void {
262
+ * accent/on_accent pair is never touched.
263
+ *
264
+ * A light label on a mid-tone accent (the default theme's white on #229879) keeps its label: the FILL a button
265
+ * paints under it is deepened just enough to read, and returned. `--brand-accent` itself is never changed, so
266
+ * links, rings and tints keep the vendor's colour. Otherwise the label flips to black or white, as before.
267
+ * Returns the fill (the accent itself when nothing was deepened; only a deepened fill is emitted as `--brand-accent-fill`). */
268
+ function ensureReadableOnAccent(color: DesignTokenColor & { accent: string; on_accent: string }, deepen = true): string {
241
269
  const ratio = contrastRatio(color.accent, color.on_accent);
242
- if (ratio !== null && ratio < MIN_ON_ACCENT_CONTRAST) {
243
- color.on_accent = pickReadableTextColor(color.accent);
270
+ if (ratio === null || ratio >= MIN_ON_ACCENT_CONTRAST) return color.accent;
271
+
272
+ if (deepen && (relativeLuminance(color.on_accent) ?? 0) > (relativeLuminance(color.accent) ?? 0)) {
273
+ const deepened = deepenAccentFor(color.accent, color.on_accent);
274
+ if (deepened !== null) return deepened;
244
275
  }
276
+
277
+ color.on_accent = pickReadableTextColor(color.accent);
278
+ return color.accent;
245
279
  }
246
280
 
247
281
  function px(value: number): string {
@@ -368,9 +402,12 @@ function emitImageVars(
368
402
  * entire groups (or being `null`/`undefined` altogether) still produces
369
403
  * every var with a sane value — never throws, never omits a role.
370
404
  */
371
- export function expandDesignTokens(tokens?: DesignTokens | null): Record<string, string> {
405
+ export function expandDesignTokens(tokens?: DesignTokens | null, { explicitLabel = false }: { explicitLabel?: boolean } = {}): Record<string, string> {
372
406
  const color = { ...DEFAULT_COLOR, ...tokens?.color };
373
- ensureReadableOnAccent(color);
407
+ // A label the merchant chose is theirs: no fill is deepened under it (the derived label flip still applies to --brand-on-accent).
408
+ const accentFill = ensureReadableOnAccent(color, !explicitLabel);
409
+ // --brand-button-bg / --brand-button-text are one pair too (the bg is the primary): the same rule keeps that pair readable.
410
+ const buttonBg = explicitLabel ? color.primary : readableFill(color.primary, color.on_accent);
374
411
  const type = { ...DEFAULT_TYPE, ...tokens?.type };
375
412
  const space = { ...DEFAULT_SPACE, ...tokens?.space };
376
413
  const shape = { ...DEFAULT_SHAPE, ...tokens?.shape };
@@ -382,6 +419,12 @@ export function expandDesignTokens(tokens?: DesignTokens | null): Record<string,
382
419
 
383
420
  // COLOR — every role, fixing the missing-12 bug.
384
421
  emitColorVars(color, vars);
422
+ // Only when the fill had to deepen: every other store's markup is byte-identical, and the CSS falls back to --brand-accent.
423
+ if (accentFill !== color.accent) vars['--brand-accent-fill'] = accentFill;
424
+ if (buttonBg !== color.primary) {
425
+ vars['--brand-button-bg'] = buttonBg;
426
+ vars['--brand-button-hover-bg'] = shade(buttonBg, 0.08);
427
+ }
385
428
 
386
429
  // TYPE
387
430
  emitTypeVars(type, vars);
@@ -503,7 +546,7 @@ export function getBrandCssVariables(
503
546
  config?: StorefrontConfig | null,
504
547
  ): CSSProperties {
505
548
  const tokens = resolveEffectiveTokens(brand, config);
506
- const vars = expandDesignTokens(tokens);
549
+ const vars = expandDesignTokens(tokens, { explicitLabel: !!config?.colors?.button_text });
507
550
 
508
551
  if (config?.footer?.bg) vars['--brand-footer-bg'] = config.footer.bg;
509
552
  if (config?.footer?.text) vars['--brand-footer-text'] = config.footer.text;