@tansy/theme-storefront 0.1.0 → 0.1.1

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/index.js CHANGED
@@ -5,15 +5,24 @@ const options = z.object({
5
5
  tagline: z.string().max(300).optional(),
6
6
  search: z.boolean(),
7
7
  accountLinks: z.boolean(),
8
+ library: z.boolean(),
8
9
  colorScheme: z.enum(["auto", "light"]),
9
10
  });
10
11
  /** What a card shows. Kept short, as every list here is read on every visit. */
11
- const CARD_FIELDS = "id,title,summary,price,compareAtPrice,images,stock,categories";
12
+ const CARD_FIELDS = "id,title,summary,price,compareAtPrice,images,stock,categories,format,membership";
12
13
  const CARD = { collection: "shop-products", sort: "-createdAt", fields: CARD_FIELDS, urls: "1" };
13
14
  const CATEGORIES = { collection: "shop-categories", sort: "name", perPage: 50, fields: "id,name", urls: "1" };
14
15
  /** The Shop page, for its currency and its address. Replaces the plugin's `store`, which reads the currency alone. */
15
16
  const STORE = { collection: "shop-store", perPage: 1, fields: "id,currency", urls: "1" };
16
17
  const PER_PAGE = 12;
18
+ /**
19
+ * Memberships, from Payments: what each access is called, and the published plans that sell it.
20
+ * Both are public, for a pricing page. Only the library files themselves are for members.
21
+ */
22
+ const ACCESS = { collection: "payments-access", perPage: 50, fields: "id,name,description" };
23
+ const PLANS = { collection: "payments-plans", filter: 'status = "published"', sort: "amount", perPage: 12, fields: "id,name,title,description,amount,annualAmount,currency,featured,includes" };
24
+ /** The library files the signed-in visitor's membership opens, read as them, so the rule decides. Empty for everyone else. */
25
+ const OPEN_FILES = { collection: "library-files", perPage: 200, fields: "id,product,label,file", viewer: true };
17
26
  /** The front page, at the site's root and at the shop's own address. `products` replaces the shop plugin's list of the same name, to add summaries and categories. */
18
27
  const FRONT = {
19
28
  store: STORE,
@@ -25,13 +34,13 @@ const FRONT = {
25
34
  * image stage, option chips and a quantity stepper, and a two-column cart. Checkout, orders
26
35
  * and the cart itself are the plugin's parts, so they behave as on the plugin's own pages.
27
36
  */
28
- export const storefront = ({ tagline, search = true, accountLinks = true, colorScheme = "auto" } = {}) => defineTheme({
37
+ export const storefront = ({ tagline, search = true, accountLinks = true, library = false, colorScheme = "auto" } = {}) => defineTheme({
29
38
  name: "storefront",
30
- version: "0.1.0",
39
+ version: "0.1.1",
31
40
  apiVersion: 1,
32
41
  render: "@tansy/theme-storefront/render",
33
42
  requires: { plugins: ["shop"] },
34
- options: { schema: options, value: { tagline, search, accountLinks, colorScheme } },
43
+ options: { schema: options, value: { tagline, search, accountLinks, library, colorScheme } },
35
44
  schema,
36
45
  tokens: {
37
46
  color: {
@@ -61,9 +70,21 @@ export const storefront = ({ tagline, search = true, accountLinks = true, colorS
61
70
  // Beside the plugin's own `variants`, which the buy box reads.
62
71
  "shop-products": {
63
72
  store: STORE,
73
+ access: ACCESS,
74
+ plans: PLANS,
75
+ files: { ...OPEN_FILES, filter: "product = @record.id" },
64
76
  related: { ...CARD, filter: "categories ?= @record.categories && id != @record.id", perPage: 4 },
65
77
  latest: { ...CARD, filter: "id != @record.id", perPage: 4 },
66
78
  categories: CATEGORIES,
67
79
  },
80
+ // The members' library: every product in a membership, the plans, and what the visitor may open.
81
+ library: {
82
+ store: STORE,
83
+ books: { ...CARD, filter: "membership:length > 0", perPage: 48 },
84
+ access: ACCESS,
85
+ plans: PLANS,
86
+ files: OPEN_FILES,
87
+ categories: CATEGORIES,
88
+ },
68
89
  },
69
90
  });
package/lib.d.ts CHANGED
@@ -7,3 +7,5 @@ export declare const ids: (value: unknown) => number[];
7
7
  export declare const fileIds: (value: unknown) => string[];
8
8
  /** A price in the shop's currency, in the page's language. A currency Intl doesn't know still shows the amount. */
9
9
  export declare function money(formatNumber: TemplateProps["formatNumber"], amount: number, currency: string): string;
10
+ /** The id of a product's card in a list, which a back arrow returns to. */
11
+ export declare const cardAnchor: (id: number | string) => string;
package/lib.js CHANGED
@@ -13,3 +13,5 @@ export function money(formatNumber, amount, currency) {
13
13
  return `${amount.toFixed(2)} ${currency.toUpperCase()}`;
14
14
  }
15
15
  }
16
+ /** The id of a product's card in a list, which a back arrow returns to. */
17
+ export const cardAnchor = (id) => `sf-item-${id}`;
package/messages.d.ts CHANGED
@@ -51,6 +51,29 @@ export declare const messages: {
51
51
  orders: string;
52
52
  menu: string;
53
53
  openMenu: string;
54
+ tabs: string;
55
+ tabShop: string;
56
+ tabSearch: string;
57
+ tabOrders: string;
58
+ formatPhysical: string;
59
+ formatDigital: string;
60
+ formatBoth: string;
61
+ library: string;
62
+ inTheLibrary: string;
63
+ memberships: string;
64
+ perMonth: string;
65
+ perYear: string;
66
+ join: string;
67
+ youAreMember: string;
68
+ membersOnly: string;
69
+ libraryEmpty: string;
70
+ memberRead: string;
71
+ includedIn: string;
72
+ fromPrice: string;
73
+ download: string;
74
+ edition: string;
75
+ zoomIn: string;
76
+ closeZoom: string;
54
77
  footerMenu: string;
55
78
  language: string;
56
79
  skip: string;
@@ -104,6 +127,29 @@ export declare const messages: {
104
127
  orders: string;
105
128
  menu: string;
106
129
  openMenu: string;
130
+ tabs: string;
131
+ tabShop: string;
132
+ tabSearch: string;
133
+ tabOrders: string;
134
+ formatPhysical: string;
135
+ formatDigital: string;
136
+ formatBoth: string;
137
+ library: string;
138
+ inTheLibrary: string;
139
+ memberships: string;
140
+ perMonth: string;
141
+ perYear: string;
142
+ join: string;
143
+ youAreMember: string;
144
+ membersOnly: string;
145
+ libraryEmpty: string;
146
+ memberRead: string;
147
+ includedIn: string;
148
+ fromPrice: string;
149
+ download: string;
150
+ edition: string;
151
+ zoomIn: string;
152
+ closeZoom: string;
107
153
  footerMenu: string;
108
154
  language: string;
109
155
  skip: string;
package/messages.js CHANGED
@@ -51,6 +51,29 @@ export const messages = {
51
51
  orders: "Your orders",
52
52
  menu: "Main",
53
53
  openMenu: "Menu",
54
+ tabs: "Shop sections",
55
+ tabShop: "Shop",
56
+ tabSearch: "Search",
57
+ tabOrders: "Orders",
58
+ formatPhysical: "Physical",
59
+ formatDigital: "Digital",
60
+ formatBoth: "Physical + digital",
61
+ library: "Library",
62
+ inTheLibrary: "In the library",
63
+ memberships: "Memberships",
64
+ perMonth: "a month",
65
+ perYear: "or {price} a year",
66
+ join: "Join",
67
+ youAreMember: "You're a member. Everything below is yours to read.",
68
+ membersOnly: "Members only",
69
+ libraryEmpty: "Nothing in the library yet.",
70
+ memberRead: "Yours to read with your membership",
71
+ includedIn: "Free to read with {name}",
72
+ fromPrice: "From {price} a month",
73
+ download: "Download {label}",
74
+ edition: "edition",
75
+ zoomIn: "Zoom in",
76
+ closeZoom: "Close",
54
77
  footerMenu: "Footer",
55
78
  language: "Language",
56
79
  skip: "Skip to content",
@@ -104,6 +127,29 @@ export const messages = {
104
127
  orders: "طلباتك",
105
128
  menu: "القائمة الرئيسية",
106
129
  openMenu: "القائمة",
130
+ tabs: "أقسام المتجر",
131
+ tabShop: "المتجر",
132
+ tabSearch: "بحث",
133
+ tabOrders: "الطلبات",
134
+ formatPhysical: "مطبوع",
135
+ formatDigital: "رقمي",
136
+ formatBoth: "مطبوع ورقمي",
137
+ library: "المكتبة",
138
+ inTheLibrary: "في المكتبة",
139
+ memberships: "العضويات",
140
+ perMonth: "شهريًا",
141
+ perYear: "أو {price} سنويًا",
142
+ join: "انضم",
143
+ youAreMember: "أنت عضو. كل ما يلي متاح لك للقراءة.",
144
+ membersOnly: "للأعضاء فقط",
145
+ libraryEmpty: "لا شيء في المكتبة بعد.",
146
+ memberRead: "متاح لك للقراءة بعضويتك",
147
+ includedIn: "اقرأه مجانًا مع {name}",
148
+ fromPrice: "ابتداءً من {price} شهريًا",
149
+ download: "تنزيل {label}",
150
+ edition: "النسخة",
151
+ zoomIn: "تكبير",
152
+ closeZoom: "إغلاق",
107
153
  footerMenu: "روابط التذييل",
108
154
  language: "اللغة",
109
155
  skip: "انتقل إلى المحتوى",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tansy/theme-storefront",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A storefront look for the shop plugin: soft rounded product cards, a product stage with a size picker and quantity stepper, and a two-column cart.",
5
5
  "keywords": [
6
6
  "tansy-theme"
@@ -25,10 +25,11 @@
25
25
  }
26
26
  },
27
27
  "peerDependencies": {
28
- "@tansy/shop": "^0.1.0",
28
+ "@tansy/payments": "^0.1.1",
29
+ "@tansy/shop": "^0.1.1",
29
30
  "next": "^16.4.6",
30
31
  "react": "^19.3.0",
31
- "tansy": "^0.1.0"
32
+ "tansy": "^0.1.1"
32
33
  },
33
34
  "dependencies": {
34
35
  "zod": "^4.6.7"
package/render.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import localFont from "next/font/local";
3
- import Link from "next/link";
3
+ import { BillingButton, SubscribeButton } from "@tansy/payments/react";
4
4
  import { Cart as ShopCart, CartLink, OrderReturn } from "@tansy/shop/react";
5
5
  import { OrderList } from "@tansy/shop/render";
6
6
  import { Menu, Pager, pickWords, RichText, StreamField } from "tansy/react";
7
7
  import { defineThemeComponents } from "tansy/theme";
8
- import { BuyBox, ProductGallery, ProductSearch, ShareButton } from "./client";
9
- import { ArrowUpRight, Bag, Bars, ChevronLeft, Globe, User } from "./icons";
10
- import { cx, fileIds, ids, money, num, text } from "./lib";
8
+ import { BackLink, BuyBox, PageTransition, ProductGallery, ProductSearch, ShareButton, ViewTransitionNames } from "./client";
9
+ import { ArrowUpRight, Bag, Bars, BookOpen, ChevronLeft, Download, Globe, Lock, Search, Store, User } from "./icons";
10
+ import { cardAnchor, cx, fileIds, ids, money, num, text } from "./lib";
11
11
  import { messages } from "./messages";
12
12
  import "./theme.css";
13
13
  // Served from the site's own origin, as font-src 'self' requires.
@@ -32,7 +32,7 @@ function SectionHeading({ id, title, aside }) {
32
32
  }
33
33
  /* ------------------------------------------------------------------ layout */
34
34
  function Brand({ branding, language }) {
35
- return (_jsxs(Link, { href: inLanguage({ language }, "/"), prefetch: false, className: "sf:flex sf:shrink-0 sf:items-center sf:gap-2.5 sf:text-2xl sf:font-bold sf:tracking-tight sf:text-ink sf:no-underline", children: [branding.logoUrl && _jsx("img", { src: branding.logoUrl, alt: "", width: 32, height: 32, className: "sf:size-8 sf:rounded-full sf:object-cover" }), _jsx("span", { children: branding.name })] }));
35
+ return (_jsxs("a", { href: inLanguage({ language }, "/"), className: "sf:flex sf:shrink-0 sf:items-center sf:gap-2.5 sf:text-2xl sf:font-bold sf:tracking-tight sf:text-ink sf:no-underline", children: [branding.logoUrl && _jsx("img", { src: branding.logoUrl, alt: "", width: 32, height: 32, className: "sf:size-8 sf:rounded-full sf:object-cover" }), _jsx("span", { children: branding.name })] }));
36
36
  }
37
37
  /** The same page in each language it's published in, as one button however many languages the site adds. */
38
38
  function LanguageSwitcher({ language, t }) {
@@ -43,13 +43,55 @@ function LanguageSwitcher({ language, t }) {
43
43
  return null;
44
44
  return (_jsx("nav", { "aria-label": t("storefront.language"), children: _jsxs("details", { className: "sf-popover sf:relative", children: [_jsxs("summary", { className: iconButton, children: [_jsx(Globe, {}), _jsx("span", { className: "sf:sr-only", children: t("storefront.language") })] }), _jsx("ul", { className: "sf:absolute sf:end-0 sf:top-full sf:z-40 sf:mt-2 sf:min-w-48 sf:rounded-3xl sf:border sf:border-line sf:bg-page sf:p-2 sf:shadow-card", children: available.map((locale) => (_jsx("li", { children: _jsxs("a", { href: language.alternates[locale.code], hrefLang: locale.code, lang: locale.code, "aria-current": locale.code === language.locale ? "true" : undefined, className: "sf:flex sf:items-center sf:justify-between sf:gap-4 sf:rounded-2xl sf:px-3 sf:py-2 sf:text-ink sf:no-underline sf:hover:bg-surface sf:aria-[current]:font-semibold sf:aria-[current]:text-accent", children: [_jsx("span", { children: locale.label }), _jsx("span", { className: "sf:text-xs sf:text-muted sf:uppercase", children: locale.code })] }) }, locale.code))) })] }) }));
45
45
  }
46
+ /**
47
+ * Moving between the theme's pages animates where the browser can: the page fades through, and a
48
+ * product's picture flies from its card to the product page and back. Every link here is a
49
+ * plain page load, so this is the browser's cross-document view transition, switched on only
50
+ * while a page in this theme's layout is showing, and never for visitors who ask for less motion.
51
+ * The animations themselves are in styles.css.
52
+ */
53
+ const VIEW_TRANSITIONS = "@media (prefers-reduced-motion: no-preference) { @view-transition { navigation: auto; } }";
54
+ /** Which tab of the bar at the bottom of small screens a page belongs to. */
55
+ const TAB_OF = { home: "shop", "shop-store": "shop", "shop-categories": "shop", "shop-products": "shop", library: "library", "shop-cart": "cart", "shop-account": "orders" };
56
+ /**
57
+ * A dot under the current tab. It carries the same view-transition name on every page, so moving
58
+ * between tabs slides it from one to the other.
59
+ */
60
+ const TabDot = () => _jsx("span", { "aria-hidden": "true", className: "sf-tab-dot", style: { viewTransitionName: "sf-tab-dot" } });
61
+ const tab = "sf-tab sf:relative sf:flex sf:min-w-0 sf:flex-1 sf:flex-col sf:items-center sf:justify-center sf:gap-1 sf:pt-2 sf:pb-1.5 sf:text-[0.6875rem] sf:font-medium sf:text-muted sf:no-underline sf:select-none sf:aria-[current]:text-accent";
62
+ /**
63
+ * The bar at the bottom of small screens, as an app has: the shop, search, the cart with its
64
+ * count, orders and the menu. The menu opens as a sheet from the bottom, with no script.
65
+ */
66
+ function TabBar({ props, menu, current }) {
67
+ const { options, language, t, words } = props;
68
+ const shop = shopHref(props);
69
+ return (_jsx("nav", { "aria-label": t("storefront.tabs"), className: "sf-tabbar sf:fixed sf:inset-x-0 sf:bottom-0 sf:z-40 sf:border-t sf:border-line/70 sf:lg:hidden", children: _jsxs("div", { className: "sf:mx-auto sf:flex sf:max-w-xl sf:items-stretch sf:px-2", children: [_jsxs("a", { href: shop, className: tab, "aria-current": current === "shop" ? "page" : undefined, children: [_jsx(Store, { className: "sf:size-6" }), _jsx("span", { children: t("storefront.tabShop") }), current === "shop" && _jsx(TabDot, {})] }), options.search && _jsxs("a", { href: `${shop}#sf-search`, className: tab, children: [_jsx(Search, { className: "sf:size-6" }), _jsx("span", { children: t("storefront.tabSearch") })] }), options.library && _jsxs("a", { href: inLanguage({ language }, "/library"), className: tab, "aria-current": current === "library" ? "page" : undefined, children: [_jsx(BookOpen, { className: "sf:size-6" }), _jsx("span", { children: t("storefront.library") }), current === "library" && _jsx(TabDot, {})] }), _jsx(CartLink, { className: cx(tab, "sf-tab-cart"), label: _jsxs(_Fragment, { children: [_jsx(Bag, { className: "sf:size-6" }), _jsx("span", { children: t("storefront.cart") }), current === "cart" && _jsx(TabDot, {})] }), words: words ? pickWords(words, "shop") : undefined }), options.accountLinks && _jsxs("a", { href: inLanguage({ language }, "/orders"), className: tab, "aria-current": current === "orders" ? "page" : undefined, children: [_jsx(User, { className: "sf:size-6" }), _jsx("span", { children: t("storefront.tabOrders") }), current === "orders" && _jsx(TabDot, {})] }), menu && (_jsxs("details", { className: "sf-sheet sf:flex sf:min-w-0 sf:flex-1", children: [_jsxs("summary", { className: cx(tab, "sf:w-full"), children: [_jsx(Bars, { className: "sf:size-6" }), _jsx("span", { children: t("storefront.openMenu") })] }), _jsxs("nav", { "aria-label": t("storefront.menu"), className: "sf-sheet-panel sf-menu sf-menu-stacked sf:fixed sf:inset-x-0 sf:bottom-0 sf:z-50 sf:max-h-[70dvh] sf:overflow-y-auto sf:rounded-t-[2rem] sf:border-t sf:border-line sf:bg-page sf:px-4 sf:pt-3 sf:shadow-card", children: [_jsx("span", { "aria-hidden": "true", className: "sf:mx-auto sf:mb-3 sf:block sf:h-1 sf:w-10 sf:rounded-full sf:bg-line" }), _jsx(Menu, { items: menu })] })] }))] }) }));
70
+ }
46
71
  function Layout(props) {
47
- const { branding, globals, options, children, language, t, words } = props;
72
+ const { branding, globals, options, children, language, t, words, collection } = props;
48
73
  const menu = globals["site-menu"]?.items;
49
74
  const hasMenu = Array.isArray(menu) && menu.length > 0;
50
- return (_jsxs("div", { className: "sf-shell sf:flex sf:min-h-screen sf:flex-col sf:bg-page sf:font-sans sf:text-ink sf:antialiased", "data-scheme": options.colorScheme, children: [_jsx("a", { href: "#sf-content", className: "sf:sr-only sf:focus:not-sr-only sf:focus:fixed sf:focus:start-4 sf:focus:top-4 sf:focus:z-50 sf:focus:rounded-full sf:focus:bg-ink sf:focus:px-5 sf:focus:py-3 sf:focus:text-page", children: t("storefront.skip") }), _jsx("header", { className: "sf:sticky sf:top-0 sf:z-30 sf:border-b sf:border-line/70 sf:bg-page/85 sf:backdrop-blur-xl", children: _jsxs("div", { className: cx(container, "sf:flex sf:h-20 sf:items-center sf:gap-8"), children: [_jsx(Brand, { branding: branding, language: language }), hasMenu && _jsx("nav", { className: "sf-menu sf:hidden sf:lg:block", "aria-label": t("storefront.menu"), children: _jsx(Menu, { items: menu }) }), _jsxs("div", { className: "sf:ms-auto sf:flex sf:items-center sf:gap-2", children: [_jsx(LanguageSwitcher, { language: language, t: t }), options.accountLinks && (_jsxs("a", { href: inLanguage({ language }, "/orders"), className: iconButton, children: [_jsx(User, {}), _jsx("span", { className: "sf:sr-only", children: t("storefront.orders") })] })), _jsx(CartLink, { className: cx("sf-cart-button", iconButton), label: _jsxs(_Fragment, { children: [_jsx(Bag, {}), _jsx("span", { className: "sf:sr-only", children: t("storefront.cart") })] }), words: words ? pickWords(words, "shop") : undefined }), hasMenu && (_jsxs("details", { className: "sf-popover sf:lg:hidden", children: [_jsxs("summary", { className: iconButton, children: [_jsx(Bars, {}), _jsx("span", { className: "sf:sr-only", children: t("storefront.openMenu") })] }), _jsx("nav", { "aria-label": t("storefront.menu"), className: "sf-menu sf-menu-stacked sf:absolute sf:inset-x-gutter sf:top-full sf:z-40 sf:mt-2 sf:rounded-3xl sf:border sf:border-line sf:bg-page sf:p-3 sf:shadow-card", children: _jsx(Menu, { items: menu }) })] }))] })] }) }), _jsx("div", { id: "sf-content", className: "sf:flex-1", children: children }), _jsx("footer", { className: "sf:mt-24 sf:rounded-t-[3rem] sf:bg-surface", children: _jsxs("div", { className: cx(container, "sf:grid sf:gap-10 sf:py-14 sf:md:grid-cols-[1fr_auto]"), children: [_jsxs("div", { className: "sf:flex sf:max-w-sm sf:flex-col sf:gap-3", children: [_jsx(Brand, { branding: branding, language: language }), _jsx("p", { className: "sf:text-muted", children: options.tagline || t("storefront.heroIntro") })] }), hasMenu && _jsx("nav", { className: "sf-menu sf-menu-footer", "aria-label": t("storefront.footerMenu"), children: _jsx(Menu, { items: menu }) }), _jsxs("p", { className: "sf:border-t sf:border-line sf:pt-6 sf:text-sm sf:text-muted sf:md:col-span-2", children: ["\u00A9 ", new Date().getFullYear(), " ", branding.name, ". ", t("storefront.rights")] })] }) })] }));
75
+ const page = collection ?? "home";
76
+ return (_jsxs("div", { className: "sf-shell sf:flex sf:min-h-dvh sf:flex-col sf:bg-page sf:font-sans sf:text-ink sf:antialiased", "data-scheme": options.colorScheme, "data-page": page, children: [_jsx("style", { href: "sf-view-transitions", precedence: "default", children: VIEW_TRANSITIONS }), _jsx(ViewTransitionNames, {}), _jsx("a", { href: "#sf-content", className: "sf:sr-only sf:focus:not-sr-only sf:focus:fixed sf:focus:start-4 sf:focus:top-4 sf:focus:z-50 sf:focus:rounded-full sf:focus:bg-ink sf:focus:px-5 sf:focus:py-3 sf:focus:text-page", children: t("storefront.skip") }), _jsx("header", { className: "sf-header sf:sticky sf:top-0 sf:z-30 sf:border-b sf:border-line/70 sf:bg-page/85 sf:backdrop-blur-xl", children: _jsxs("div", { className: cx(container, "sf:flex sf:h-16 sf:items-center sf:gap-8 sf:lg:h-20"), children: [_jsx(Brand, { branding: branding, language: language }), hasMenu && _jsx("nav", { className: "sf-menu sf:hidden sf:lg:block", "aria-label": t("storefront.menu"), children: _jsx(Menu, { items: menu }) }), _jsxs("div", { className: "sf:ms-auto sf:flex sf:items-center sf:gap-2", children: [_jsx(LanguageSwitcher, { language: language, t: t }), options.library && (_jsxs("a", { href: inLanguage({ language }, "/library"), className: cx(iconButton, "sf:max-lg:hidden"), "aria-current": collection === "library" ? "page" : undefined, children: [_jsx(BookOpen, {}), _jsx("span", { className: "sf:sr-only", children: t("storefront.library") })] })), options.accountLinks && (_jsxs("a", { href: inLanguage({ language }, "/orders"), className: cx(iconButton, "sf:max-lg:hidden"), children: [_jsx(User, {}), _jsx("span", { className: "sf:sr-only", children: t("storefront.orders") })] })), _jsx(CartLink, { className: cx("sf-cart-button sf-header-cart", iconButton), label: _jsxs(_Fragment, { children: [_jsx(Bag, {}), _jsx("span", { className: "sf:sr-only", children: t("storefront.cart") })] }), words: words ? pickWords(words, "shop") : undefined })] })] }) }), _jsx("div", { id: "sf-content", className: "sf:flex-1", children: _jsx(PageTransition, { children: children }) }), _jsx(TabBar, { props: props, menu: hasMenu ? menu : null, current: TAB_OF[page] }), _jsx("footer", { className: "sf:mt-24 sf:rounded-t-[3rem] sf:bg-surface", children: _jsxs("div", { className: cx(container, "sf:grid sf:gap-10 sf:py-14 sf:md:grid-cols-[1fr_auto]"), children: [_jsxs("div", { className: "sf:flex sf:max-w-sm sf:flex-col sf:gap-3", children: [_jsx(Brand, { branding: branding, language: language }), _jsx("p", { className: "sf:text-muted", children: options.tagline || t("storefront.heroIntro") })] }), hasMenu && _jsx("nav", { className: "sf-menu sf-menu-footer", "aria-label": t("storefront.footerMenu"), children: _jsx(Menu, { items: menu }) }), _jsxs("p", { className: "sf:border-t sf:border-line sf:pt-6 sf:text-sm sf:text-muted sf:md:col-span-2", children: ["\u00A9 ", new Date().getFullYear(), " ", branding.name, ". ", t("storefront.rights")] })] }) })] }));
51
77
  }
52
78
  /* -------------------------------------------------------------- products */
79
+ /**
80
+ * The name a product's picture carries on its card and on its own page, so moving between them
81
+ * flies the picture from one to the other. Unique per product, as a page may name each only once.
82
+ */
83
+ const productTransition = (id) => `sf-product-${id}`;
84
+ /**
85
+ * Marks a picture that leads to a product's page. A page may show the same product twice, such
86
+ * as the front page's spotlight beside its card, and may name it only once. So the picture tapped
87
+ * gets the name as the page is left (ViewTransitionNames in client.tsx), and that one flies.
88
+ */
89
+ const flies = (product, href) => (href ? { "data-sf-vt": productTransition(product.id), "data-sf-vt-href": href } : {});
90
+ /** Physical, digital, or both, from the product's Format, for a badge. Empty when it has none. */
91
+ function formatLabel(product, t) {
92
+ const format = text(product.format);
93
+ return format === "physical" ? t("storefront.formatPhysical") : format === "digital" ? t("storefront.formatDigital") : format === "both" ? t("storefront.formatBoth") : "";
94
+ }
53
95
  /** A product as a tall soft card: its picture with an arrow over it, then price and name. The whole card is one link. */
54
96
  function ProductCard({ product, categories, props, eager = false }) {
55
97
  const href = hrefOf(product, props);
@@ -58,13 +100,14 @@ function ProductCard({ product, categories, props, eager = false }) {
58
100
  const was = num(product.compareAtPrice);
59
101
  const onSale = price !== null && was !== null && was > price;
60
102
  const soldOut = product.stock === 0;
103
+ const format = formatLabel(product, props.t);
61
104
  const category = categories.get(ids(product.categories)[0] ?? -1);
62
105
  const subtitle = text(category?.name) || text(product.summary);
63
106
  const currency = currencyOf(props.data);
64
- return (_jsxs("article", { className: "sf:group sf:relative sf:flex sf:flex-col sf:gap-4", lang: typeof product.locale === "string" ? product.locale : undefined, children: [_jsxs("div", { className: "sf:relative sf:isolate sf:grid sf:aspect-[4/5] sf:place-items-center sf:overflow-hidden sf:rounded-[3rem] sf:bg-surface sf:transition-shadow sf:duration-300 sf:group-hover:shadow-card", children: [_jsx("span", { "aria-hidden": "true", className: "sf:absolute sf:inset-x-[12%] sf:top-[14%] sf:-z-10 sf:aspect-square sf:rounded-full sf:bg-page/60 sf:blur-xl" }), image
107
+ return (_jsxs("article", { id: cardAnchor(product.id), className: "sf-press sf-card sf:group sf:relative sf:flex sf:flex-col sf:gap-4", lang: typeof product.locale === "string" ? product.locale : undefined, children: [_jsxs("div", { className: "sf:relative sf:isolate sf:grid sf:aspect-[4/5] sf:place-items-center sf:overflow-hidden sf:rounded-[3rem] sf:bg-surface sf:transition-shadow sf:duration-300 sf:group-hover:shadow-card", children: [_jsx("span", { "aria-hidden": "true", className: "sf:absolute sf:inset-x-[12%] sf:top-[14%] sf:-z-10 sf:aspect-square sf:rounded-full sf:bg-page/60 sf:blur-xl" }), image
65
108
  // eslint-disable-next-line @next/next/no-img-element -- an access-checked API address that redirects to a signed URL, which next/image can't optimize
66
- ? _jsx("img", { src: props.fileUrl(image, "800x0"), alt: props.fileText(image).alt, loading: eager ? "eager" : "lazy", className: cx("sf:size-[80%] sf:object-contain sf:drop-shadow-[0_18px_22px_rgba(0,0,0,0.16)] sf:transition-transform sf:duration-500 sf:ease-out sf:group-hover:scale-105 sf:group-hover:-rotate-2 sf:motion-reduce:transition-none", soldOut && "sf:opacity-60 sf:grayscale") })
67
- : _jsx(Bag, { className: "sf:size-12 sf:text-muted/50", strokeWidth: 1 }), _jsx("span", { "aria-hidden": "true", className: "sf:absolute sf:top-1/2 sf:left-1/2 sf:grid sf:size-14 sf:-translate-1/2 sf:place-items-center sf:rounded-full sf:border sf:border-page/60 sf:bg-page/40 sf:text-ink sf:backdrop-blur-md sf:transition sf:duration-300 sf:group-hover:scale-110 sf:group-hover:border-accent sf:group-hover:bg-accent sf:group-hover:text-on-accent", children: _jsx(ArrowUpRight, { className: "sf:size-5 sf:rtl:-scale-x-100" }) }), (onSale || soldOut) && (_jsx("span", { className: cx("sf:absolute sf:start-5 sf:top-5 sf:rounded-full sf:px-3 sf:py-1 sf:text-xs sf:font-semibold", soldOut ? "sf:bg-ink sf:text-page" : "sf:bg-accent sf:text-on-accent"), children: soldOut ? props.t("storefront.soldOut") : props.t("storefront.sale") }))] }), _jsxs("div", { className: "sf:flex sf:flex-col sf:gap-1 sf:px-2", children: [price !== null && (_jsxs("p", { className: "sf:flex sf:items-baseline sf:gap-2 sf:text-xl sf:font-semibold sf:tracking-tight sf:text-ink sf:tabular-nums", children: [money(props.formatNumber, price, currency), onSale && _jsx("s", { className: "sf:text-sm sf:font-normal sf:text-muted", children: money(props.formatNumber, was, currency) })] })), _jsx("h3", { className: "sf:text-base sf:font-medium sf:text-ink", children: href
109
+ ? _jsx("img", { src: props.fileUrl(image, "800x0"), alt: props.fileText(image).alt, loading: eager ? "eager" : "lazy", style: { viewTransitionName: productTransition(product.id) }, ...flies(product, href), className: cx("sf-vt-product sf:size-[80%] sf:object-contain sf:drop-shadow-[0_18px_22px_rgba(0,0,0,0.16)] sf:transition-transform sf:duration-500 sf:ease-out sf:group-hover:scale-105 sf:group-hover:-rotate-2 sf:motion-reduce:transition-none", soldOut && "sf:opacity-60 sf:grayscale") })
110
+ : _jsx(Bag, { className: "sf:size-12 sf:text-muted/50", strokeWidth: 1 }), _jsx("span", { "aria-hidden": "true", className: "sf:absolute sf:top-1/2 sf:left-1/2 sf:grid sf:size-14 sf:-translate-1/2 sf:place-items-center sf:rounded-full sf:border sf:border-page/60 sf:bg-page/40 sf:text-ink sf:backdrop-blur-md sf:transition sf:duration-300 sf:group-hover:scale-110 sf:group-hover:border-accent sf:group-hover:bg-accent sf:group-hover:text-on-accent", children: _jsx(ArrowUpRight, { className: "sf:size-5 sf:rtl:-scale-x-100" }) }), format && _jsx("span", { className: "sf:absolute sf:end-5 sf:top-5 sf:rounded-full sf:bg-page/80 sf:px-3 sf:py-1 sf:text-xs sf:font-medium sf:text-ink sf:backdrop-blur", children: format }), (onSale || soldOut) && (_jsx("span", { className: cx("sf:absolute sf:start-5 sf:top-5 sf:rounded-full sf:px-3 sf:py-1 sf:text-xs sf:font-semibold", soldOut ? "sf:bg-ink sf:text-page" : "sf:bg-accent sf:text-on-accent"), children: soldOut ? props.t("storefront.soldOut") : props.t("storefront.sale") }))] }), _jsxs("div", { className: "sf:flex sf:flex-col sf:gap-1 sf:px-2", children: [price !== null && (_jsxs("p", { className: "sf:flex sf:items-baseline sf:gap-2 sf:text-xl sf:font-semibold sf:tracking-tight sf:text-ink sf:tabular-nums", children: [money(props.formatNumber, price, currency), onSale && _jsx("s", { className: "sf:text-sm sf:font-normal sf:text-muted", children: money(props.formatNumber, was, currency) })] })), _jsx("h3", { className: "sf:text-base sf:font-medium sf:text-ink", children: href
68
111
  ? _jsx("a", { href: href, className: "sf:text-inherit sf:no-underline sf:outline-none sf:after:absolute sf:after:inset-0 sf:after:rounded-[3rem] sf:focus-visible:after:outline-2 sf:focus-visible:after:outline-offset-4 sf:focus-visible:after:outline-accent", children: text(product.title) })
69
112
  : text(product.title) }), subtitle && _jsx("p", { className: "sf:line-clamp-1 sf:text-sm sf:text-muted", children: subtitle })] })] }));
70
113
  }
@@ -81,10 +124,12 @@ function CategoryChips({ props, current }) {
81
124
  if (!categories.length)
82
125
  return null;
83
126
  const chip = (active) => cx(pill, active ? "sf:border-ink sf:bg-ink sf:text-page" : "sf:border-line sf:bg-page sf:text-ink sf:hover:border-ink");
84
- return (_jsx("nav", { "aria-label": props.t("storefront.categories"), className: "sf:-mx-gutter sf:mb-10 sf:overflow-x-auto sf:px-gutter", children: _jsxs("ul", { className: "sf:flex sf:w-max sf:gap-2", children: [_jsx("li", { children: _jsx("a", { href: shopHref(props), className: chip(current === "all"), "aria-current": current === "all" ? "page" : undefined, children: props.t("storefront.all") }) }), categories.map((category) => {
127
+ // The chosen chip has the same name on every page, so moving between categories slides it across.
128
+ const slide = (active) => (active ? { viewTransitionName: "sf-chip" } : undefined);
129
+ return (_jsx("nav", { "aria-label": props.t("storefront.categories"), className: "sf-chips sf:-mx-gutter sf:mb-10 sf:overflow-x-auto sf:px-gutter", children: _jsxs("ul", { className: "sf:flex sf:w-max sf:gap-2", children: [_jsx("li", { children: _jsx("a", { href: shopHref(props), className: chip(current === "all"), style: slide(current === "all"), "aria-current": current === "all" ? "page" : undefined, children: props.t("storefront.all") }) }), categories.map((category) => {
85
130
  const href = hrefOf(category, props);
86
131
  const active = current === category.id;
87
- return _jsx("li", { children: href ? _jsx("a", { href: href, className: chip(active), "aria-current": active ? "page" : undefined, children: text(category.name) }) : _jsx("span", { className: chip(active), children: text(category.name) }) }, category.id);
132
+ return _jsx("li", { children: href ? _jsx("a", { href: href, className: chip(active), style: slide(active), "aria-current": active ? "page" : undefined, children: text(category.name) }) : _jsx("span", { className: chip(active), children: text(category.name) }) }, category.id);
88
133
  })] }) }));
89
134
  }
90
135
  function ProductPager({ props, list }) {
@@ -95,7 +140,7 @@ function Spotlight({ product, props }) {
95
140
  const image = fileIds(product.images)[0];
96
141
  const href = hrefOf(product, props);
97
142
  const price = num(product.price);
98
- return (_jsxs("div", { className: "sf:relative sf:isolate sf:mx-auto sf:hidden sf:aspect-square sf:w-full sf:max-w-[34rem] sf:place-items-center sf:lg:grid", children: [_jsx("span", { "aria-hidden": "true", className: "sf:absolute sf:inset-[6%] sf:-z-20 sf:rounded-full sf:bg-surface" }), _jsx("span", { "aria-hidden": "true", className: "sf:absolute sf:top-[56%] sf:left-1/2 sf:-z-10 sf:h-[24%] sf:w-[112%] sf:-translate-x-1/2 sf:-rotate-6 sf:rounded-[50%] sf:border sf:border-ink/15" }), image ? _jsx("img", { src: props.fileUrl(image, "800x0"), alt: props.fileText(image).alt, className: "sf:size-[74%] sf:object-contain sf:drop-shadow-[0_30px_36px_rgba(0,0,0,0.2)]" }) : _jsx(Bag, { className: "sf:size-20 sf:text-muted/40", strokeWidth: 1 }), _jsxs("div", { className: "sf:absolute sf:start-0 sf:bottom-[8%] sf:flex sf:max-w-[18rem] sf:items-center sf:gap-4 sf:rounded-3xl sf:border sf:border-line sf:bg-page/90 sf:p-4 sf:pe-5 sf:shadow-card sf:backdrop-blur", children: [_jsxs("div", { className: "sf:min-w-0", children: [_jsx("p", { className: "sf:text-xs sf:font-medium sf:tracking-wide sf:text-accent sf:uppercase", children: props.t("storefront.featured") }), _jsx("p", { className: "sf:truncate sf:font-semibold sf:text-ink", children: href ? _jsx("a", { href: href, className: "sf:text-inherit sf:no-underline sf:after:absolute sf:after:inset-0 sf:after:rounded-3xl", children: text(product.title) }) : text(product.title) }), price !== null && _jsx("p", { className: "sf:text-sm sf:text-muted sf:tabular-nums", children: money(props.formatNumber, price, currencyOf(props.data)) })] }), _jsx("span", { "aria-hidden": "true", className: "sf:grid sf:size-10 sf:shrink-0 sf:place-items-center sf:rounded-full sf:bg-accent sf:text-on-accent", children: _jsx(ArrowUpRight, { className: "sf:size-4 sf:rtl:-scale-x-100" }) })] })] }));
143
+ return (_jsxs("div", { className: "sf:relative sf:isolate sf:mx-auto sf:hidden sf:aspect-square sf:w-full sf:max-w-[34rem] sf:place-items-center sf:lg:grid", children: [_jsx("span", { "aria-hidden": "true", className: "sf:absolute sf:inset-[6%] sf:-z-20 sf:rounded-full sf:bg-surface" }), _jsx("span", { "aria-hidden": "true", className: "sf:absolute sf:top-[56%] sf:left-1/2 sf:-z-10 sf:h-[24%] sf:w-[112%] sf:-translate-x-1/2 sf:-rotate-6 sf:rounded-[50%] sf:border sf:border-ink/15" }), image ? _jsx("img", { src: props.fileUrl(image, "800x0"), alt: props.fileText(image).alt, ...flies(product, href), className: "sf-vt-product sf:size-[74%] sf:object-contain sf:drop-shadow-[0_30px_36px_rgba(0,0,0,0.2)]" }) : _jsx(Bag, { className: "sf:size-20 sf:text-muted/40", strokeWidth: 1 }), _jsxs("div", { className: "sf:absolute sf:start-0 sf:bottom-[8%] sf:flex sf:max-w-[18rem] sf:items-center sf:gap-4 sf:rounded-3xl sf:border sf:border-line sf:bg-page/90 sf:p-4 sf:pe-5 sf:shadow-card sf:backdrop-blur", children: [_jsxs("div", { className: "sf:min-w-0", children: [_jsx("p", { className: "sf:text-xs sf:font-medium sf:tracking-wide sf:text-accent sf:uppercase", children: props.t("storefront.featured") }), _jsx("p", { className: "sf:truncate sf:font-semibold sf:text-ink", children: href ? _jsx("a", { href: href, className: "sf:text-inherit sf:no-underline sf:after:absolute sf:after:inset-0 sf:after:rounded-3xl", children: text(product.title) }) : text(product.title) }), price !== null && _jsx("p", { className: "sf:text-sm sf:text-muted sf:tabular-nums", children: money(props.formatNumber, price, currencyOf(props.data)) })] }), _jsx("span", { "aria-hidden": "true", className: "sf:grid sf:size-10 sf:shrink-0 sf:place-items-center sf:rounded-full sf:bg-accent sf:text-on-accent", children: _jsx(ArrowUpRight, { className: "sf:size-4 sf:rtl:-scale-x-100" }) })] })] }));
99
144
  }
100
145
  /* --------------------------------------------------------------- templates */
101
146
  /**
@@ -109,13 +154,13 @@ function Front(props) {
109
154
  const intro = record?.intro !== undefined && record?.intro !== null
110
155
  ? _jsx("div", { className: "sf-prose sf:max-w-lg sf:text-lg sf:text-muted", children: _jsx(RichText, { doc: record.intro }) })
111
156
  : _jsx("p", { className: "sf:max-w-lg sf:text-lg sf:text-muted", children: options.tagline || t("storefront.heroIntro") });
112
- return (_jsxs("main", { children: [firstPage && (_jsxs("section", { className: cx(container, "sf:grid sf:items-center sf:gap-10 sf:pt-10 sf:pb-14 sf:lg:grid-cols-[1.1fr_1fr] sf:lg:pt-16"), children: [_jsxs("div", { className: "sf:flex sf:flex-col sf:items-start sf:gap-6", children: [_jsx("p", { className: "sf:rounded-full sf:bg-accent/10 sf:px-4 sf:py-1.5 sf:text-sm sf:font-medium sf:text-accent", children: t("storefront.kicker") }), _jsx("h1", { className: "sf:max-w-[12ch] sf:text-5xl sf:leading-[1.02] sf:font-semibold sf:tracking-tight sf:text-balance sf:text-ink sf:sm:text-6xl sf:xl:text-7xl", children: text(record?.title) || t("storefront.heroTitle") }), intro, options.search && _jsx(ProductSearch, { words: forClient(words), currency: currencyOf(data) })] }), products[0] && _jsx(Spotlight, { product: products[0], props: props })] })), _jsxs("section", { "aria-labelledby": "sf-products", className: cx(container, !firstPage && "sf:pt-12"), children: [_jsx(CategoryChips, { props: props, current: record ? "all" : null }), _jsx(SectionHeading, { id: "sf-products", title: firstPage ? t("storefront.newArrivals") : t("storefront.pageOf", { page: data.products?.page ?? 1 }), aside: data.products?.totalItems ? t("storefront.products", { count: data.products.totalItems }) : undefined }), _jsx(ProductGrid, { products: products, props: props, empty: t("storefront.noProducts") }), _jsx(ProductPager, { props: props, list: data.products })] })] }));
157
+ return (_jsxs("main", { children: [firstPage && (_jsxs("section", { className: cx(container, "sf:grid sf:items-center sf:gap-10 sf:pt-10 sf:pb-14 sf:lg:grid-cols-[1.1fr_1fr] sf:lg:pt-16"), children: [_jsxs("div", { className: "sf:flex sf:flex-col sf:items-start sf:gap-6", children: [_jsx("p", { className: "sf:rounded-full sf:bg-accent/10 sf:px-4 sf:py-1.5 sf:text-sm sf:font-medium sf:text-accent", children: t("storefront.kicker") }), _jsx("h1", { className: "sf:max-w-[12ch] sf:text-5xl sf:leading-[1.02] sf:font-semibold sf:tracking-tight sf:text-balance sf:text-ink sf:sm:text-6xl sf:xl:text-7xl", children: text(record?.title) || t("storefront.heroTitle") }), intro, options.search && _jsx(ProductSearch, { id: "sf-search", words: forClient(words), currency: currencyOf(data) })] }), products[0] && _jsx(Spotlight, { product: products[0], props: props })] })), _jsxs("section", { "aria-labelledby": "sf-products", className: cx(container, !firstPage && "sf:pt-12"), children: [_jsx(CategoryChips, { props: props, current: record ? "all" : null }), _jsx(SectionHeading, { id: "sf-products", title: firstPage ? t("storefront.newArrivals") : t("storefront.pageOf", { page: data.products?.page ?? 1 }), aside: data.products?.totalItems ? t("storefront.products", { count: data.products.totalItems }) : undefined }), _jsx(ProductGrid, { products: products, props: props, empty: t("storefront.noProducts") }), _jsx(ProductPager, { props: props, list: data.products })] })] }));
113
158
  }
114
159
  function Category(props) {
115
160
  const { record, data, t } = props;
116
161
  if (!record)
117
162
  return null;
118
- return (_jsxs("main", { children: [_jsxs("header", { className: cx(container, "sf:flex sf:flex-col sf:items-start sf:gap-4 sf:pt-10 sf:pb-10 sf:lg:pt-14"), children: [_jsxs("a", { href: shopHref(props), className: "sf:inline-flex sf:items-center sf:gap-1 sf:text-sm sf:font-medium sf:text-muted sf:no-underline sf:hover:text-ink", children: [_jsx(ChevronLeft, { className: "sf:size-4 sf:rtl:-scale-x-100" }), t("storefront.back")] }), _jsx("h1", { className: "sf:text-5xl sf:font-semibold sf:tracking-tight sf:text-ink sf:sm:text-6xl", children: text(record.name) }), text(record.description) && _jsx("p", { className: "sf:max-w-2xl sf:text-lg sf:text-muted", children: text(record.description) })] }), _jsxs("section", { "aria-label": text(record.name), className: container, children: [_jsx(CategoryChips, { props: props, current: record.id }), (data.products?.totalItems ?? 0) > 0 && _jsx("p", { className: "sf:mb-6 sf:text-sm sf:text-muted", children: t("storefront.products", { count: data.products.totalItems }) }), _jsx(ProductGrid, { products: items(data.products), props: props, empty: t("storefront.emptyCategory") }), _jsx(ProductPager, { props: props, list: data.products })] })] }));
163
+ return (_jsxs("main", { children: [_jsxs("header", { className: cx(container, "sf:flex sf:flex-col sf:items-start sf:gap-4 sf:pt-10 sf:pb-10 sf:lg:pt-14"), children: [_jsxs(BackLink, { href: shopHref(props), className: "sf:inline-flex sf:items-center sf:gap-1 sf:text-sm sf:font-medium sf:text-muted sf:no-underline sf:hover:text-ink", children: [_jsx(ChevronLeft, { className: "sf:size-4 sf:rtl:-scale-x-100" }), t("storefront.back")] }), _jsx("h1", { className: "sf:text-5xl sf:font-semibold sf:tracking-tight sf:text-ink sf:sm:text-6xl", children: text(record.name) }), text(record.description) && _jsx("p", { className: "sf:max-w-2xl sf:text-lg sf:text-muted", children: text(record.description) })] }), _jsxs("section", { "aria-label": text(record.name), className: container, children: [_jsx(CategoryChips, { props: props, current: record.id }), (data.products?.totalItems ?? 0) > 0 && _jsx("p", { className: "sf:mb-6 sf:text-sm sf:text-muted", children: t("storefront.products", { count: data.products.totalItems }) }), _jsx(ProductGrid, { products: items(data.products), props: props, empty: t("storefront.emptyCategory") }), _jsx(ProductPager, { props: props, list: data.products })] })] }));
119
164
  }
120
165
  /**
121
166
  * A product: its pictures on a stage, and beside them a panel with the price, options and two
@@ -132,7 +177,61 @@ function Product(props) {
132
177
  const variants = items(data.variants).map((variant) => ({ id: variant.id, title: text(variant.title), price: num(variant.price), stock: num(variant.stock) }));
133
178
  const more = (items(data.related).length ? items(data.related) : items(data.latest)).filter((product) => product.id !== record.id).slice(0, 4);
134
179
  const description = Array.isArray(record.description) && record.description.length > 0;
135
- return (_jsxs("main", { className: cx(container, "sf:pt-6 sf:lg:pt-10"), children: [_jsxs("div", { className: "sf:mb-6 sf:flex sf:items-center sf:justify-between sf:gap-4", children: [_jsxs("nav", { "aria-label": t("storefront.back"), className: "sf:flex sf:min-w-0 sf:items-center sf:gap-3", children: [_jsxs("a", { href: shopHref(props), className: iconButton, children: [_jsx(ChevronLeft, { className: "sf:size-5 sf:rtl:-scale-x-100" }), _jsx("span", { className: "sf:sr-only", children: t("storefront.back") })] }), category && hrefOf(category, props) && _jsx("a", { href: hrefOf(category, props), className: "sf:hidden sf:truncate sf:text-sm sf:font-medium sf:text-muted sf:no-underline sf:hover:text-ink sf:sm:inline", children: text(category.name) })] }), _jsx(ShareButton, { title: text(record.title), words: forClient(words), className: iconButton })] }), _jsxs("div", { className: "sf:grid sf:items-start sf:gap-8 sf:lg:grid-cols-[minmax(0,1.1fr)_minmax(0,1fr)] sf:lg:gap-14", children: [_jsx(ProductGallery, { images: images, words: forClient(words) }), _jsxs("div", { className: "sf:flex sf:flex-col sf:gap-7 sf:rounded-card sf:border sf:border-line sf:bg-page sf:p-6 sf:shadow-card sf:sm:p-10 sf:lg:sticky sf:lg:top-28", children: [_jsx("span", { "aria-hidden": "true", className: "sf:mx-auto sf:-mt-2 sf:h-1 sf:w-12 sf:rounded-full sf:bg-line sf:lg:hidden" }), _jsxs("div", { className: "sf:flex sf:flex-col sf:gap-2", children: [category && _jsx("p", { className: "sf:text-sm sf:font-medium sf:text-accent", children: text(category.name) }), _jsx("h1", { className: "sf:text-3xl sf:font-semibold sf:tracking-tight sf:text-balance sf:text-ink sf:sm:text-4xl", children: text(record.title) }), text(record.summary) && _jsx("p", { className: "sf:text-muted", children: text(record.summary) })] }), _jsx(BuyBox, { product: record.id, price: num(record.price), compareAt: num(record.compareAtPrice), stock: num(record.stock), variants: variants, currency: currency, words: forClient(words) }), text(record.sku) && _jsx("p", { className: "sf:border-t sf:border-line sf:pt-5 sf:text-xs sf:text-muted", children: t("shop.sku", { sku: text(record.sku) }) })] })] }), description && (_jsxs("section", { "aria-labelledby": "sf-details", className: "sf:mt-20 sf:grid sf:gap-6 sf:border-t sf:border-line sf:pt-12 sf:lg:grid-cols-[16rem_minmax(0,1fr)] sf:lg:gap-14", children: [_jsx("h2", { id: "sf-details", className: "sf:text-2xl sf:font-semibold sf:tracking-tight sf:text-ink", children: t("storefront.details") }), _jsx("div", { className: "sf-prose sf:max-w-measure", children: _jsx(StreamField, { blocks: record.description, ...stream }) })] })), more.length > 0 && (_jsxs("section", { "aria-labelledby": "sf-more", className: "sf:mt-20", children: [_jsx(SectionHeading, { id: "sf-more", title: t("storefront.youMayLike") }), _jsx(ProductGrid, { products: more, props: props, empty: "" })] }))] }));
180
+ return (_jsxs("main", { className: cx(container, "sf:pt-6 sf:lg:pt-10"), children: [_jsxs("div", { className: "sf:mb-6 sf:flex sf:items-center sf:justify-between sf:gap-4", children: [_jsxs("nav", { "aria-label": t("storefront.back"), className: "sf:flex sf:min-w-0 sf:items-center sf:gap-3", children: [_jsxs(BackLink, { href: shopHref(props), card: record.id, className: iconButton, children: [_jsx(ChevronLeft, { className: "sf:size-5 sf:rtl:-scale-x-100" }), _jsx("span", { className: "sf:sr-only", children: t("storefront.back") })] }), category && hrefOf(category, props) && _jsx("a", { href: hrefOf(category, props), className: "sf:hidden sf:truncate sf:text-sm sf:font-medium sf:text-muted sf:no-underline sf:hover:text-ink sf:sm:inline", children: text(category.name) })] }), _jsx(ShareButton, { title: text(record.title), words: forClient(words), className: iconButton })] }), _jsxs("div", { className: "sf:grid sf:items-start sf:gap-8 sf:lg:grid-cols-[minmax(0,1.1fr)_minmax(0,1fr)] sf:lg:gap-14", children: [_jsx(ProductGallery, { images: images, transitionName: productTransition(record.id), words: forClient(words) }), _jsxs("div", { className: "sf:flex sf:flex-col sf:gap-7 sf:rounded-card sf:border sf:border-line sf:bg-page sf:p-6 sf:shadow-card sf:sm:p-10 sf:lg:sticky sf:lg:top-28", children: [_jsx("span", { "aria-hidden": "true", className: "sf:mx-auto sf:-mt-2 sf:h-1 sf:w-12 sf:rounded-full sf:bg-line sf:lg:hidden" }), _jsxs("div", { className: "sf:flex sf:flex-col sf:gap-2", children: [(category || formatLabel(record, t)) && (_jsxs("p", { className: "sf:flex sf:flex-wrap sf:items-center sf:gap-2 sf:text-sm sf:font-medium", children: [category && _jsx("span", { className: "sf:text-accent", children: text(category.name) }), formatLabel(record, t) && _jsx("span", { className: "sf:rounded-full sf:bg-surface sf:px-3 sf:py-0.5 sf:text-ink", children: formatLabel(record, t) })] })), _jsx("h1", { className: "sf:text-3xl sf:font-semibold sf:tracking-tight sf:text-balance sf:text-ink sf:sm:text-4xl", children: text(record.title) }), text(record.summary) && _jsx("p", { className: "sf:text-muted", children: text(record.summary) })] }), _jsx(BuyBox, { product: record.id, price: num(record.price), compareAt: num(record.compareAtPrice), stock: num(record.stock), variants: variants, currency: currency, words: forClient(words) }), _jsx(MembershipPanel, { props: props }), text(record.sku) && _jsx("p", { className: "sf:border-t sf:border-line sf:pt-5 sf:text-xs sf:text-muted", children: t("shop.sku", { sku: text(record.sku) }) })] })] }), description && (_jsxs("section", { "aria-labelledby": "sf-details", className: "sf:mt-20 sf:grid sf:gap-6 sf:border-t sf:border-line sf:pt-12 sf:lg:grid-cols-[16rem_minmax(0,1fr)] sf:lg:gap-14", children: [_jsx("h2", { id: "sf-details", className: "sf:text-2xl sf:font-semibold sf:tracking-tight sf:text-ink", children: t("storefront.details") }), _jsx("div", { className: "sf-prose sf:max-w-measure", children: _jsx(StreamField, { blocks: record.description, ...stream }) })] })), more.length > 0 && (_jsxs("section", { "aria-labelledby": "sf-more", className: "sf:mt-20", children: [_jsx(SectionHeading, { id: "sf-more", title: t("storefront.youMayLike") }), _jsx(ProductGrid, { products: more, props: props, empty: "" })] }))] }));
181
+ }
182
+ const plansOf = (data) => items(data.plans).map((plan) => ({
183
+ name: text(plan.name),
184
+ title: text(plan.title) || text(plan.name),
185
+ description: text(plan.description),
186
+ amount: num(plan.amount),
187
+ annualAmount: num(plan.annualAmount),
188
+ currency: text(plan.currency) || currencyOf(data),
189
+ featured: plan.featured === true,
190
+ includes: ids(plan.includes),
191
+ }));
192
+ /** A member's downloads: each library file is fetched through the files API, which checks the same rule again. */
193
+ function Downloads({ files, props }) {
194
+ return (_jsx("ul", { className: "sf:flex sf:flex-wrap sf:gap-2", children: files.map((file) => {
195
+ const id = text(file.file);
196
+ return id ? (_jsx("li", { children: _jsxs("a", { href: props.fileUrl(id), download: true, className: "sf-press sf:inline-flex sf:h-10 sf:items-center sf:gap-2 sf:rounded-full sf:bg-accent sf:px-4 sf:text-sm sf:font-semibold sf:text-on-accent sf:no-underline", children: [_jsx(Download, { className: "sf:size-4" }), props.t("storefront.download", { label: text(file.label) || props.t("storefront.edition") })] }) }, file.id)) : null;
197
+ }) }));
198
+ }
199
+ /**
200
+ * On a product in a membership: a member gets its digital edition here, and everyone else sees
201
+ * which membership opens it, from what price, and a way to the library to join.
202
+ */
203
+ function MembershipPanel({ props }) {
204
+ const { record, data, t } = props;
205
+ const access = ids(record?.membership);
206
+ if (!record || !access.length)
207
+ return null;
208
+ const files = items(data.files);
209
+ const names = items(data.access).filter((item) => access.includes(item.id)).map((item) => text(item.name)).filter(Boolean);
210
+ const plans = plansOf(data).filter((plan) => plan.includes.some((id) => access.includes(id)) && plan.amount !== null);
211
+ const cheapest = plans.sort((a, b) => (a.amount ?? 0) - (b.amount ?? 0))[0];
212
+ return (_jsxs("section", { "aria-label": t("storefront.library"), className: "sf:flex sf:flex-col sf:gap-3 sf:rounded-3xl sf:bg-accent/10 sf:p-5", children: [_jsxs("p", { className: "sf:flex sf:items-center sf:gap-2 sf:font-semibold sf:text-ink", children: [_jsx(BookOpen, { className: "sf:size-5 sf:text-accent" }), files.length ? t("storefront.memberRead") : t("storefront.includedIn", { name: names[0] ?? t("storefront.library") })] }), files.length ? _jsx(Downloads, { files: files, props: props }) : (_jsxs("p", { className: "sf:flex sf:flex-wrap sf:items-center sf:gap-x-3 sf:gap-y-1 sf:text-sm sf:text-muted", children: [cheapest && _jsx("span", { children: t("storefront.fromPrice", { price: money(props.formatNumber, cheapest.amount, cheapest.currency) }) }), _jsx("a", { href: inLanguage(props, "/library"), className: "sf:font-semibold sf:text-accent sf:underline sf:underline-offset-4", children: t("storefront.join") })] }))] }));
213
+ }
214
+ /** One membership to choose, with its price and the provider's checkout behind Subscribe. */
215
+ function PlanCard({ plan, props, member }) {
216
+ const { t, words } = props;
217
+ return (_jsxs("li", { className: cx("sf:flex sf:flex-col sf:gap-4 sf:rounded-card sf:border sf:p-7", plan.featured ? "sf:border-accent sf:bg-accent/5 sf:shadow-card" : "sf:border-line sf:bg-page"), children: [_jsxs("div", { className: "sf:flex sf:flex-col sf:gap-1", children: [_jsx("h3", { className: "sf:text-xl sf:font-semibold sf:text-ink", children: plan.title }), plan.description && _jsx("p", { className: "sf:text-muted", children: plan.description })] }), plan.amount !== null && (_jsxs("p", { className: "sf:flex sf:flex-wrap sf:items-baseline sf:gap-x-2 sf:text-ink", children: [_jsx("span", { className: "sf:text-4xl sf:font-semibold sf:tracking-tight sf:tabular-nums", children: money(props.formatNumber, plan.amount, plan.currency) }), _jsx("span", { className: "sf:text-muted", children: t("storefront.perMonth") }), plan.annualAmount !== null && _jsx("span", { className: "sf:basis-full sf:text-sm sf:text-muted", children: t("storefront.perYear", { price: money(props.formatNumber, plan.annualAmount, plan.currency) }) })] })), _jsx("div", { className: "sf-plan-action sf:mt-auto", children: member ? _jsx(BillingButton, { words: words ? pickWords(words, "payments") : undefined }) : _jsx(SubscribeButton, { plan: plan.name, label: t("storefront.join"), words: words ? pickWords(words, "payments") : undefined }) })] }));
218
+ }
219
+ /**
220
+ * The members' library: the memberships to join, then every product in one. A member's own
221
+ * editions show their downloads, read through the rule as them. The rest show a lock.
222
+ */
223
+ function Library(props) {
224
+ const { record, data, t } = props;
225
+ const books = items(data.books);
226
+ const files = items(data.files);
227
+ const member = files.length > 0;
228
+ const plans = plansOf(data);
229
+ const categories = byId(data.categories);
230
+ const filesOf = (product) => files.filter((file) => file.product === product);
231
+ return (_jsxs("main", { className: cx(container, "sf:pt-10 sf:lg:pt-14"), children: [_jsx(PageHeading, { title: text(record?.title) || t("storefront.library"), record: record }), member && _jsxs("p", { className: "sf:mb-8 sf:inline-flex sf:items-center sf:gap-2 sf:rounded-full sf:bg-accent/10 sf:px-4 sf:py-2 sf:text-sm sf:font-medium sf:text-accent", children: [_jsx(BookOpen, { className: "sf:size-4" }), t("storefront.youAreMember")] }), plans.length > 0 && (_jsxs("section", { "aria-labelledby": "sf-plans", className: "sf:mb-16", children: [_jsx(SectionHeading, { id: "sf-plans", title: t("storefront.memberships") }), _jsx("ul", { className: "sf:grid sf:gap-5 sf:md:grid-cols-2 sf:xl:grid-cols-3", children: plans.map((plan) => _jsx(PlanCard, { plan: plan, props: props, member: member }, plan.name)) })] })), _jsxs("section", { "aria-labelledby": "sf-library-books", children: [_jsx(SectionHeading, { id: "sf-library-books", title: t("storefront.inTheLibrary"), aside: books.length ? t("storefront.products", { count: books.length }) : undefined }), books.length ? (_jsx("ul", { className: "sf:grid sf:grid-cols-2 sf:gap-x-4 sf:gap-y-10 sf:sm:gap-x-6 sf:md:grid-cols-3 sf:xl:grid-cols-4", children: books.map((book, index) => {
232
+ const open = filesOf(book.id);
233
+ return (_jsxs("li", { className: "sf:flex sf:flex-col sf:gap-3", children: [_jsx(ProductCard, { product: book, categories: categories, props: props, eager: index < 4 }), _jsx("div", { className: "sf:px-2", children: open.length ? _jsx(Downloads, { files: open, props: props }) : _jsxs("p", { className: "sf:inline-flex sf:items-center sf:gap-1.5 sf:text-sm sf:text-muted", children: [_jsx(Lock, { className: "sf:size-4" }), t("storefront.membersOnly")] }) })] }, book.id));
234
+ }) })) : _jsx("p", { className: "sf:text-muted", children: t("storefront.libraryEmpty") })] })] }));
136
235
  }
137
236
  function PageHeading({ title, record, back }) {
138
237
  return (_jsxs("header", { className: "sf:mb-10 sf:flex sf:flex-col sf:items-start sf:gap-4", children: [back, _jsx("h1", { className: "sf:text-4xl sf:font-semibold sf:tracking-tight sf:text-ink sf:sm:text-5xl", children: title }), record?.intro !== undefined && record?.intro !== null && _jsx("div", { className: "sf-prose sf:max-w-2xl sf:text-muted", children: _jsx(RichText, { doc: record.intro }) })] }));
@@ -140,7 +239,7 @@ function PageHeading({ title, record, back }) {
140
239
  /** The cart is the shop plugin's, laid out in two columns by theme.css: lines, then where it goes and the total. */
141
240
  function CartPage(props) {
142
241
  const { record, t, words } = props;
143
- return (_jsxs("main", { className: cx(container, "sf:pt-10 sf:lg:pt-14"), children: [_jsx(PageHeading, { title: text(record?.title) || t("shop.yourCart"), record: record, back: _jsxs("a", { href: shopHref(props), className: "sf:inline-flex sf:items-center sf:gap-1 sf:text-sm sf:font-medium sf:text-muted sf:no-underline sf:hover:text-ink", children: [_jsx(ChevronLeft, { className: "sf:size-4 sf:rtl:-scale-x-100" }), t("storefront.back")] }) }), _jsx("div", { className: "sf-cart", children: _jsx(ShopCart, { words: words ? pickWords(words, "shop") : undefined }) })] }));
242
+ return (_jsxs("main", { className: cx(container, "sf:pt-10 sf:lg:pt-14"), children: [_jsx(PageHeading, { title: text(record?.title) || t("shop.yourCart"), record: record, back: _jsxs(BackLink, { href: shopHref(props), className: "sf:inline-flex sf:items-center sf:gap-1 sf:text-sm sf:font-medium sf:text-muted sf:no-underline sf:hover:text-ink", children: [_jsx(ChevronLeft, { className: "sf:size-4 sf:rtl:-scale-x-100" }), t("storefront.back")] }) }), _jsx("div", { className: "sf-cart", children: _jsx(ShopCart, { words: words ? pickWords(words, "shop") : undefined }) })] }));
144
243
  }
145
244
  /** The signed-in customer's orders, read as them, as the shop plugin lists them. */
146
245
  function OrdersPage(props) {
@@ -167,7 +266,7 @@ function metadata({ record }) {
167
266
  }
168
267
  export default defineThemeComponents({
169
268
  // The shop's blocks (product grids, add to cart) come from the plugin and are restyled in theme.css.
170
- templates: { home: Front, "shop-store": Front, "shop-categories": Category, "shop-products": Product, "shop-cart": CartPage, "shop-account": OrdersPage, default: Page },
269
+ templates: { home: Front, "shop-store": Front, "shop-categories": Category, "shop-products": Product, library: Library, "shop-cart": CartPage, "shop-account": OrdersPage, default: Page },
171
270
  layouts: { default: Layout },
172
271
  metadata,
173
272
  fontClassName: font.variable,
package/schema.json CHANGED
@@ -25,6 +25,81 @@
25
25
  }
26
26
  }
27
27
  ]
28
+ },
29
+ {
30
+ "slug": "shop-products",
31
+ "name": "Products",
32
+ "type": "base",
33
+ "urlPattern": "/shop/:slug",
34
+ "rules": {
35
+ "listRule": "status = \"published\"",
36
+ "viewRule": "status = \"published\"",
37
+ "createRule": null,
38
+ "updateRule": null,
39
+ "deleteRule": null
40
+ },
41
+ "fields": [
42
+ {
43
+ "name": "format",
44
+ "type": "radio",
45
+ "config": {
46
+ "options": [
47
+ { "label": "Physical", "value": "physical" },
48
+ { "label": "Digital", "value": "digital" },
49
+ { "label": "Physical and digital", "value": "both" }
50
+ ],
51
+ "description": "The badge the storefront shows. What is posted still follows Shipping, and what buyers download follows Download."
52
+ }
53
+ },
54
+ {
55
+ "name": "membership",
56
+ "type": "reference",
57
+ "config": {
58
+ "collection": "payments-access",
59
+ "displayField": "name",
60
+ "allowMultiple": true,
61
+ "description": "Memberships whose members read its digital edition in the library for free. Add the file under Library files."
62
+ }
63
+ }
64
+ ]
65
+ },
66
+ {
67
+ "slug": "library",
68
+ "name": "Library page",
69
+ "description": "The members' library: digital editions members read for free, and the memberships that open them.",
70
+ "type": "singleton",
71
+ "urlPattern": "/library",
72
+ "rules": {
73
+ "listRule": "",
74
+ "viewRule": "",
75
+ "createRule": null,
76
+ "updateRule": null,
77
+ "deleteRule": null
78
+ },
79
+ "fields": [
80
+ { "name": "title", "type": "text", "config": { "required": true, "maxLength": 120 } },
81
+ { "name": "intro", "type": "rich_text", "config": {} }
82
+ ]
83
+ },
84
+ {
85
+ "slug": "library-files",
86
+ "name": "Library files",
87
+ "description": "Digital editions for members. Only people whose membership includes one of a file's Included in can see it or download it. A file in no membership is shown to nobody.",
88
+ "type": "base",
89
+ "urlPattern": null,
90
+ "rules": {
91
+ "listRule": "status = \"published\" && included:length > 0 && included ?= @request.auth.payments_access",
92
+ "viewRule": "status = \"published\" && included:length > 0 && included ?= @request.auth.payments_access",
93
+ "createRule": null,
94
+ "updateRule": null,
95
+ "deleteRule": null
96
+ },
97
+ "fields": [
98
+ { "name": "product", "type": "reference", "config": { "collection": "shop-products", "displayField": "title", "required": true } },
99
+ { "name": "label", "type": "text", "config": { "maxLength": 40, "description": "What the download is, such as EPUB or PDF." } },
100
+ { "name": "file", "type": "file", "config": { "required": true } },
101
+ { "name": "included", "type": "reference", "config": { "collection": "payments-access", "displayField": "name", "allowMultiple": true, "required": true, "label": "Included in" } }
102
+ ]
28
103
  }
29
104
  ],
30
105
  "blocks": []