@usequeek/theme-kit 0.5.2 → 0.5.4

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/README.md CHANGED
@@ -560,9 +560,11 @@ export default function Footer() {
560
560
  (`utm_source=powered_by&utm_medium=storefront&utm_campaign=<store slug>`,
561
561
  campaign omitted when the store has no slug); the component reads the slug
562
562
  from the storefront context, so themes pass nothing.
563
- - `hidden` (default false) takes the attribution link's visibility from a prop;
564
- it never hides the cookie preferences button. There is no merchant-facing
565
- toggle for it — always render it visible.
563
+ - A merchant may hide the credit: the component hides itself when
564
+ `config.display.show_powered_by` is `false` (on by default, so a store that
565
+ never saved the setting shows it). A theme places `<PoweredByQueek />` and
566
+ reads nothing. `hidden` (default false) is the same switch from a prop. Neither
567
+ hides the cookie preferences button.
566
568
 
567
569
  ## Cookie consent
568
570
 
@@ -0,0 +1,31 @@
1
+ 'use client';
2
+
3
+ import type { JSX } from 'react';
4
+ import { createContext, useContext, type ReactNode } from 'react';
5
+
6
+ const BlockPositionContext = createContext<number | null>(null);
7
+
8
+ /**
9
+ * How many blocks open a page. A page's hero is its first block, or its second
10
+ * after a short heading or banner, so only these may hold the image the page is
11
+ * judged by (its LCP image).
12
+ */
13
+ export const TOP_BLOCK_COUNT = 2;
14
+
15
+ /**
16
+ * Tells every `<Image>` below it where its block sits on the page. `PageRenderer`
17
+ * mounts one per block; a theme never needs to.
18
+ */
19
+ export function BlockPositionProvider({ index, children }: { index: number; children: ReactNode }): JSX.Element {
20
+ return <BlockPositionContext.Provider value={index}>{children}</BlockPositionContext.Provider>;
21
+ }
22
+
23
+ /** The index of the page block being rendered; null outside a `PageRenderer` block. */
24
+ export function useBlockPosition(): number | null {
25
+ return useContext(BlockPositionContext);
26
+ }
27
+
28
+ /** Whether a block index is past the opening blocks of the page (never true outside a block). */
29
+ export function isBelowTopBlocks(position: number | null): boolean {
30
+ return position !== null && position >= TOP_BLOCK_COUNT;
31
+ }
@@ -1,6 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import { useContext, useState, type ImgHTMLAttributes } from 'react';
4
+ import { isBelowTopBlocks, useBlockPosition } from '../block-position';
4
5
  import { lookupMediaIndex, useMediaIndex } from '../media-index';
5
6
  import { StorefrontContext } from '../provider';
6
7
  import type { ImageVariants } from '../types/media';
@@ -157,6 +158,14 @@ export function Image({ fallback, placeholder, variants: variantsProp, intent: i
157
158
  effectiveSizes = undefined;
158
159
  }
159
160
 
161
+ // A block past the page's opening blocks is below the fold, so its images are
162
+ // lazy and never high priority, whatever the call site asked. A slider marks its
163
+ // first slide eager and high priority because it may be the hero; reused lower
164
+ // on the page, that made the browser (and React's SSR preloads) fetch those
165
+ // photos with the hero: 1.9 MB of a 3.5 MB phone page load on a Beaurify store.
166
+ const belowTop = isBelowTopBlocks(useBlockPosition());
167
+ const fetchPriority = belowTop && props.fetchPriority === 'high' ? undefined : props.fetchPriority;
168
+
160
169
  // Cards sit in grids and rails, mostly below the fold — and a card's hover
161
170
  // image is invisible until hover. Eager, a server-rendered grid of 24 cards
162
171
  // made React preload the first ~10 (also into the 103 Early Hints header) and
@@ -164,12 +173,13 @@ export function Image({ fallback, placeholder, variants: variantsProp, intent: i
164
173
  // first paint went from 1.8 s to 2.9 s on Slow 4G. Lazy is next/image's
165
174
  // default as well. A theme whose card IS the page's main image passes
166
175
  // loading="eager" or fetchPriority="high".
167
- const lazyByDefault = (intent === 'card' || intent === 'card2x') && props.fetchPriority !== 'high';
168
- const loading = props.loading ?? (lazyByDefault ? 'lazy' : undefined);
176
+ const lazyByDefault = (intent === 'card' || intent === 'card2x') && fetchPriority !== 'high';
177
+ const loading = belowTop ? 'lazy' : (props.loading ?? (lazyByDefault ? 'lazy' : undefined));
169
178
 
170
179
  return (
171
180
  <img
172
181
  {...props}
182
+ fetchPriority={fetchPriority}
173
183
  loading={loading}
174
184
  src={effectiveSrc}
175
185
  srcSet={effectiveSrcSet}
@@ -10,9 +10,10 @@ export interface PoweredByQueekProps {
10
10
  /** Extra class so a footer can position the link — styling stays theme-owned. */
11
11
  className?: string;
12
12
  /**
13
- * Lets a caller hide the attribution link from a prop. Defaults to false;
14
- * themes always render it visible — there is no merchant-facing toggle for
15
- * it. It never hides the cookie preferences link, which is not attribution.
13
+ * Lets a caller hide the attribution link from a prop. Defaults to false. The
14
+ * store's own switch (`config.display.show_powered_by`, on by default) hides it
15
+ * the same way, so a theme passes nothing for it. Neither hides the cookie
16
+ * preferences link, which is not attribution.
16
17
  */
17
18
  hidden?: boolean;
18
19
  }
@@ -21,6 +22,10 @@ export interface PoweredByQueekProps {
21
22
  * The storefront attribution link, owned by the kit: themes import and place
22
23
  * it, and never re-implement it.
23
24
  *
25
+ * A merchant may hide the credit (Display, "Show Powered by Queek"): it is on
26
+ * unless `config.display.show_powered_by` is `false`, so a store that never
27
+ * saved the setting, or a payload without it, shows the credit.
28
+ *
24
29
  * Required on every footer variant of every theme (enforced by the
25
30
  * `theme/footer-shows-powered-by` rule of `npm run check`). The link
26
31
  * target (`https://usequeek.com/business`) and `rel` are the contract —
@@ -42,9 +47,10 @@ export interface PoweredByQueekProps {
42
47
  * look).
43
48
  */
44
49
  export function PoweredByQueek({ className, hidden = false }: PoweredByQueekProps): JSX.Element | null {
45
- const vendor = useContext(StorefrontContext)?.vendor;
50
+ const store = useContext(StorefrontContext);
51
+ const vendor = store?.vendor;
46
52
 
47
- if (hidden) return <ConsentPreferencesLink />;
53
+ if (hidden || store?.config?.display?.show_powered_by === false) return <ConsentPreferencesLink />;
48
54
 
49
55
  return (
50
56
  <span className="core-powered-by-group">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usequeek/theme-kit",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
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/page-renderer.tsx CHANGED
@@ -6,6 +6,7 @@ import type { Block, BlockDataMap, MetaobjectsResolved } from './types/block';
6
6
  import type { Product } from './types/product';
7
7
  import { useTheme } from './theme-context';
8
8
  import { useStorefront } from './provider';
9
+ import { BlockPositionProvider, useBlockPosition } from './block-position';
9
10
  import { mediaIndexBackgroundUrl, useMediaIndex } from './media-index';
10
11
  import { expandDesignTokensPartial } from './utils/brand';
11
12
  import {
@@ -98,12 +99,18 @@ export function PageRenderer({ blocks }: { blocks: Block[] }): JSX.Element {
98
99
  const defaultVariants = config.default_variants ?? {};
99
100
  const editMode = useEditMode();
100
101
  const mediaIndex = useMediaIndex();
102
+ // Where each block sits for its images' loading (block-position.tsx): only blocks that render count, and a
103
+ // renderer nested in a block starts at that block's position, so a hero after an empty block keeps its priority.
104
+ const positionOffset = useBlockPosition() ?? 0;
105
+ let renderedCount = 0;
101
106
 
102
107
  const renderBlock = (block: Block, index: number): JSX.Element | null => {
103
108
  const variant = block.variant ?? defaultVariants[block.type] ?? undefined;
104
109
  const key = `${block.type}-${index}`;
105
110
  const node = renderInner(block, variant, key);
106
111
  if (node === null) return null;
112
+ const position = positionOffset + renderedCount;
113
+ renderedCount += 1;
107
114
 
108
115
  // Section-scoped design-token override: only wraps in an extra div when
109
116
  // the section actually sets `tokens` — no-override sections render
@@ -214,7 +221,7 @@ export function PageRenderer({ blocks }: { blocks: Block[] }): JSX.Element {
214
221
 
215
222
  const wrapped = (
216
223
  <EditableBlock key={key} index={index} type={block.type} variant={variant} enabled={editMode}>
217
- {content}
224
+ <BlockPositionProvider index={position}>{content}</BlockPositionProvider>
218
225
  </EditableBlock>
219
226
  );
220
227
 
package/types/vendor.ts CHANGED
@@ -160,6 +160,8 @@ export interface StorefrontConfig {
160
160
  header?: {
161
161
  variant?: string;
162
162
  logo_url?: string | null;
163
+ /** The tier map of `logo_url`; null for an SVG or off-host logo. Render the logo through `logoSrc()`. */
164
+ logo_variants?: ImageVariants | null;
163
165
  announcement?: {
164
166
  enabled: boolean;
165
167
  text: string;
@@ -190,10 +192,13 @@ export interface StorefrontConfig {
190
192
  /**
191
193
  * Store-wide display choices every theme honours. `show_product_counts` (default false): a theme
192
194
  * prints a product count ("6 products") only when the store turns it on; read it through
193
- * `useProductCount()`, never from here.
195
+ * `useProductCount()`, never from here. `show_powered_by` (default true): the footer
196
+ * "Powered by Queek" credit; `PoweredByQueek` hides it when this is `false`, so a theme
197
+ * places the component and reads nothing from here.
194
198
  */
195
199
  display?: {
196
200
  show_product_counts?: boolean;
201
+ show_powered_by?: boolean;
197
202
  };
198
203
  /** Resolved semantic design tokens. Absent for stores that have none. */
199
204
  tokens?: DesignTokens | null;
@@ -192,3 +192,21 @@ export function resolveImageSources(
192
192
 
193
193
  return { src, srcSet, sizes: INTENT_SIZES[intent] };
194
194
  }
195
+
196
+ /**
197
+ * The one url a store logo renders from. A logo reaches a theme as a plain string
198
+ * (`HeaderProps.logo`), so it has no srcset and the call site's box is unknown:
199
+ * the `view` copy (WebP q98, at most 1600 px) holds every pixel a logo box up to
200
+ * 800 CSS px on a 2x screen (533 px on 3x) can show, at a fraction of the upload
201
+ * (a 2048 px JPG of 139 KB is a 38 KB WebP). Never a smaller tier: a wide wordmark
202
+ * on a 3x phone would come out softer than the upload it replaces. The raw `url`
203
+ * when there is no `view` copy, no copies at all (an SVG, an off-host file) or
204
+ * copies of a different file.
205
+ */
206
+ export function logoSrc(url: string | null | undefined, variants: ImageVariants | null | undefined): string | null {
207
+ if (!url) {
208
+ return null;
209
+ }
210
+ const view = variants && variants.original?.url === url ? variants.view : null;
211
+ return usableTier(view) ? view.url : url;
212
+ }