@chinggis.systems/collection-ui 1.0.0 → 1.0.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.
Files changed (42) hide show
  1. package/README.md +21 -36
  2. package/dist/CollectionRenderer.d.ts +2 -2
  3. package/dist/CollectionRenderer.d.ts.map +1 -1
  4. package/dist/CollectionRenderer.js +305 -292
  5. package/dist/CollectionRenderer.js.map +1 -1
  6. package/dist/CollectionView.d.ts +13 -0
  7. package/dist/CollectionView.d.ts.map +1 -0
  8. package/dist/CollectionView.js +42 -0
  9. package/dist/CollectionView.js.map +1 -0
  10. package/dist/assets/spine/BurnBlend.png +0 -0
  11. package/dist/assets/spine/FlatEdges.webp +0 -0
  12. package/dist/assets/spine/FlatShadow.webp +0 -0
  13. package/dist/assets/spine/NormalBlend.webp +0 -0
  14. package/dist/assets/spine/SoftLightBlend.webp +0 -0
  15. package/dist/collectionV2Model.d.ts +43 -0
  16. package/dist/collectionV2Model.d.ts.map +1 -0
  17. package/dist/collectionV2Model.js +4 -0
  18. package/dist/collectionV2Model.js.map +1 -0
  19. package/dist/createAdapters.d.ts +66 -74
  20. package/dist/createAdapters.d.ts.map +1 -1
  21. package/dist/createAdapters.js +223 -223
  22. package/dist/createAdapters.js.map +1 -1
  23. package/dist/defaultAdapters.d.ts +7 -7
  24. package/dist/defaultAdapters.js +8 -8
  25. package/dist/index.d.ts +14 -11
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +7 -6
  28. package/dist/index.js.map +1 -1
  29. package/dist/layoutPresets.d.ts +18 -18
  30. package/dist/layoutPresets.js +129 -129
  31. package/dist/primitives/BookSpine.d.ts +11 -11
  32. package/dist/primitives/BookSpine.js +10 -10
  33. package/dist/primitives/CollectionCarousel.d.ts +3 -3
  34. package/dist/primitives/CollectionCarousel.d.ts.map +1 -1
  35. package/dist/primitives/CollectionCarousel.js +22 -13
  36. package/dist/primitives/CollectionCarousel.js.map +1 -1
  37. package/dist/styles.css +236 -51
  38. package/dist/types.d.ts +141 -141
  39. package/dist/types.js +1 -1
  40. package/dist/utils.d.ts +8 -8
  41. package/dist/utils.js +26 -26
  42. package/package.json +1 -1
@@ -1,293 +1,306 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useId } from "react";
3
- import { defaultAdapters } from "./defaultAdapters";
4
- import { compact, cx, hasCollections, hasItems, sortCollections, } from "./utils";
5
- const defaultLabels = {
6
- all: "All",
7
- viewAll: "View all",
8
- readMore: "Read more",
9
- previous: "Previous",
10
- next: "Next",
11
- };
12
- export function CollectionRenderer({ collection, layout, adapters, labels, className, }) {
13
- const resolvedLayout = layout ?? collection.layout;
14
- if (!resolvedLayout) {
15
- return null;
16
- }
17
- return (_jsx("div", { className: cx("collection-ui", className), "data-layout": resolvedLayout.name, "data-direction": resolvedLayout.direction ?? undefined, style: {
18
- "--collection-ui-columns": resolvedLayout.columns ?? undefined,
19
- }, children: _jsx(CollectionBody, { collection: collection, layout: resolvedLayout, adapters: adapters, labels: { ...defaultLabels, ...labels } }) }));
20
- }
21
- function CollectionBody({ collection, layout, adapters, labels, }) {
22
- switch (layout.name) {
23
- case "dynamic":
24
- case "list": {
25
- if (!hasItems(collection)) {
26
- return null;
27
- }
28
- if (layout.direction === "vertical") {
29
- return (_jsx(VerticalList, { collection: collection, items: compact(collection.items), adapters: adapters, labels: labels, numbered: layout.isNumbered }));
30
- }
31
- return (_jsx(HorizontalList, { collection: collection, items: compact(collection.items), adapters: adapters, labels: labels }));
32
- }
33
- case "grid":
34
- case "relative": {
35
- if (!hasItems(collection)) {
36
- return null;
37
- }
38
- return (_jsx(GridList, { collection: collection, items: compact(collection.items), adapters: adapters, labels: labels }));
39
- }
40
- case "carousel": {
41
- if (!hasItems(collection)) {
42
- return null;
43
- }
44
- return (_jsx(HorizontalList, { collection: collection, items: compact(collection.items), adapters: adapters, labels: labels }));
45
- }
46
- case "grid-title": {
47
- if (!hasCollections(collection)) {
48
- return null;
49
- }
50
- return (_jsx(GridTitle, { collection: collection, adapters: adapters, labels: labels, itemLimit: layout.itemLimit ?? 3 }));
51
- }
52
- case "hero":
53
- case "banner": {
54
- if (!collection.imageUrl) {
55
- return null;
56
- }
57
- return (_jsx(LargeBanner, { collection: collection, adapters: adapters, labels: labels }));
58
- }
59
- case "special": {
60
- if (!hasItems(collection)) {
61
- return null;
62
- }
63
- return (_jsx(SpecialItem, { collection: collection, adapters: adapters, labels: labels }));
64
- }
65
- case "slide":
66
- if (!hasCollections(collection)) {
67
- return null;
68
- }
69
- return (_jsx(SlideShow, { collections: compact(collection.collections), adapters: adapters, labels: labels }));
70
- case "featured": {
71
- if (!hasCollections(collection)) {
72
- return null;
73
- }
74
- return (_jsx(FeaturedBanners, { collections: compact(collection.collections), adapters: adapters, labels: labels }));
75
- }
76
- case "image-grid": {
77
- if (!hasCollections(collection)) {
78
- return null;
79
- }
80
- return (_jsx(ImageGrid, { collection: collection, adapters: adapters, labels: labels, variant: layout.shape === "square" ? "square" : "circle" }));
81
- }
82
- case "block-grid": {
83
- if (!hasCollections(collection)) {
84
- return null;
85
- }
86
- return (_jsx(ImageGrid, { collection: collection, adapters: adapters, labels: labels, variant: "block" }));
87
- }
88
- default:
89
- return null;
90
- }
91
- }
92
- function getAdapters(adapters) {
93
- return { ...defaultAdapters, ...adapters };
94
- }
95
- function renderItem(adapters, props) {
96
- return adapters.renderItem({
97
- ...props,
98
- renderBookMedia: adapters.renderBookMedia,
99
- renderPrice: adapters.renderPrice,
100
- renderHtml: adapters.renderHtml,
101
- });
102
- }
103
- function Container({ adapters, children, className, }) {
104
- const resolved = getAdapters(adapters);
105
- return resolved.renderContainer(children, {
106
- className: cx("collection-ui-container", className),
107
- });
108
- }
109
- function LinkAdapter({ adapters, href, children, className, collection, item, onClick, }) {
110
- const resolved = getAdapters(adapters);
111
- if (!href) {
112
- return _jsx(_Fragment, { children: children });
113
- }
114
- return (_jsx(_Fragment, { children: resolved.renderLink({
115
- href,
116
- children,
117
- className,
118
- collection,
119
- item,
120
- onClick,
121
- }) }));
122
- }
123
- function ImageAdapter(props) {
124
- const resolved = getAdapters(props.adapters);
125
- if (!props.src) {
126
- return null;
127
- }
128
- return _jsx(_Fragment, { children: resolved.renderImage(props) });
129
- }
130
- function SectionTitle({ collection, adapters, labels, small, }) {
131
- const resolved = getAdapters(adapters);
132
- const href = resolved.resolveCollectionHref(collection);
133
- return (_jsxs("div", { className: "collection-ui-title", children: [_jsxs("div", { className: "collection-ui-title__row", children: [_jsx("h2", { className: cx("collection-ui-title__heading", small && "collection-ui-title__heading--small"), children: href ? (_jsx(LinkAdapter, { adapters: adapters, href: href, collection: collection, children: collection.name })) : (collection.name) }), href ? (_jsx(LinkAdapter, { adapters: adapters, href: href, collection: collection, className: "collection-ui-title__link", children: small ? labels.all : labels.viewAll })) : null] }), collection.description ? (_jsx("p", { className: "collection-ui-title__description", children: collection.description })) : null] }));
134
- }
135
- function HorizontalList({ collection, items, adapters, labels, }) {
136
- const id = useId().replaceAll(":", "");
137
- const resolved = getAdapters(adapters);
138
- const collectionHref = resolved.resolveCollectionHref(collection);
139
- const slides = items.map((item, index) => {
140
- const href = resolved.resolveItemHref(item);
141
- return renderItem(resolved, {
142
- item,
143
- href,
144
- index,
145
- variant: "card",
146
- collection,
147
- });
148
- });
149
- if (collectionHref) {
150
- slides.push(_jsxs(LinkAdapter, { adapters: adapters, href: collectionHref, collection: collection, className: "collection-ui-view-all", children: [_jsx("span", { className: "collection-ui-view-all__icon", "aria-hidden": "true", children: ">" }), _jsx("span", { children: labels.viewAll })] }));
151
- }
152
- return (_jsx(Container, { adapters: adapters, children: _jsxs("section", { className: "collection-ui-horizontal", "aria-labelledby": `collection-title-${id}`, children: [_jsx("div", { id: `collection-title-${id}`, children: _jsx(SectionTitle, { collection: collection, adapters: adapters, labels: labels }) }), resolved.renderCarousel({
153
- id: `collection-carousel-${id}`,
154
- slides,
155
- className: "collection-ui-carousel__track",
156
- slideClassName: "collection-ui-carousel__slide",
157
- previousLabel: labels.previous,
158
- nextLabel: labels.next,
159
- showControls: true,
160
- slidesPerView: "auto",
161
- slidesPerGroupAuto: true,
162
- spaceBetween: 20,
163
- })] }) }));
164
- }
165
- function GridList({ collection, items, adapters, labels, }) {
166
- const resolved = getAdapters(adapters);
167
- const collectionHref = resolved.resolveCollectionHref(collection);
168
- const cards = items.map((item, index) => {
169
- const href = resolved.resolveItemHref(item);
170
- return (_jsx("div", { className: "collection-ui-grid__item", children: renderItem(resolved, {
171
- item,
172
- href,
173
- index,
174
- variant: "card",
175
- collection,
176
- }) }, item.id));
177
- });
178
- return (_jsx(Container, { adapters: adapters, children: _jsxs("section", { className: "collection-ui-grid", "aria-label": collection.name ?? undefined, children: [_jsx(SectionTitle, { collection: collection, adapters: adapters, labels: labels }), _jsxs("div", { className: "collection-ui-grid__items", children: [cards, collectionHref ? (_jsxs(LinkAdapter, { adapters: adapters, href: collectionHref, collection: collection, className: "collection-ui-view-all collection-ui-grid__view-all", children: [_jsx("span", { className: "collection-ui-view-all__icon", "aria-hidden": "true", children: ">" }), _jsx("span", { children: labels.viewAll })] })) : null] })] }) }));
179
- }
180
- function VerticalList({ collection, items, adapters, labels, numbered, limit, hideTitle, }) {
181
- const resolved = getAdapters(adapters);
182
- const visibleItems = limit ? items.slice(0, limit) : items;
183
- return (_jsx(Container, { adapters: adapters, children: _jsxs("section", { className: "collection-ui-vertical", children: [hideTitle ? null : (_jsx(SectionTitle, { collection: collection, adapters: adapters, labels: labels })), _jsx("div", { className: "collection-ui-vertical__grid", role: "list", children: visibleItems.map((item, index) => {
184
- const href = resolved.resolveItemHref(item);
185
- return (_jsx("div", { className: "collection-ui-vertical__item", role: "listitem", children: renderItem(resolved, {
186
- item,
187
- href,
188
- index,
189
- number: numbered ? index + 1 : undefined,
190
- variant: "vertical",
191
- collection,
192
- }) }, item.id));
193
- }) })] }) }));
194
- }
195
- function GridTitle({ collection, adapters, labels, itemLimit, }) {
196
- const id = useId().replaceAll(":", "");
197
- const resolved = getAdapters(adapters);
198
- const slides = compact(collection.collections).map((child) => (_jsxs("div", { className: "collection-ui-grid-title__panel", children: [_jsx(SectionTitle, { collection: child, adapters: adapters, labels: labels, small: true }), _jsx(VerticalList, { collection: child, items: compact(child.items), adapters: adapters, labels: labels, numbered: true, limit: itemLimit, hideTitle: true })] }, child.id)));
199
- return (_jsx("section", { className: "collection-ui-band", children: _jsxs(Container, { adapters: adapters, children: [_jsx(SectionTitle, { collection: collection, adapters: adapters, labels: labels }), resolved.renderCarousel({
200
- id: `collection-grid-title-${id}`,
201
- slides,
202
- className: "collection-ui-grid-title",
203
- slideClassName: "collection-ui-grid-title__slide",
204
- previousLabel: labels.previous,
205
- nextLabel: labels.next,
206
- showControls: true,
207
- slidesPerView: 1,
208
- slidesPerGroupAuto: false,
209
- spaceBetween: 24,
210
- breakpoints: {
211
- 1280: {
212
- slidesPerView: 2,
213
- },
214
- },
215
- })] }) }));
216
- }
217
- function LargeBanner({ collection, adapters, labels, }) {
218
- const resolved = getAdapters(adapters);
219
- const href = resolved.resolveCollectionHref(collection);
220
- const handleClick = () => resolved.onCollectionClick?.(collection, href);
221
- return (_jsx(Container, { adapters: adapters, className: "collection-ui-container--wide", children: _jsxs("section", { className: "collection-ui-banner", children: [_jsxs("div", { className: "collection-ui-banner__copy", children: [collection.type ? (_jsx("div", { className: "collection-ui-banner__eyebrow", children: resolved.formatCollectionType(collection.type) })) : null, _jsx("h2", { className: "collection-ui-banner__title", children: collection.name }), collection.description ? (_jsx("p", { className: "collection-ui-banner__description", children: collection.description })) : null, href ? (_jsx(LinkAdapter, { adapters: adapters, href: href, collection: collection, onClick: handleClick, className: "collection-ui-button", children: labels.readMore })) : null] }), collection.imageUrl ? (_jsx(LinkAdapter, { adapters: adapters, href: href ?? "", collection: collection, onClick: handleClick, children: _jsx(ImageAdapter, { adapters: adapters, src: collection.imageUrl, alt: collection.name ?? "Collection banner", width: 1003, height: 564, priority: true, sizes: "(max-width: 768px) 100vw, 1003px", className: "collection-ui-banner__image", collection: collection, style: { height: "auto" } }) })) : null] }) }));
222
- }
223
- function SpecialItem({ collection, adapters, labels, }) {
224
- const item = compact(collection.items)[0];
225
- const resolved = getAdapters(adapters);
226
- if (!item) {
227
- return null;
228
- }
229
- const href = resolved.resolveItemHref(item);
230
- return (_jsx("section", { className: "collection-ui-band", children: _jsx(Container, { adapters: adapters, children: _jsxs("div", { className: "collection-ui-special", children: [renderItem(resolved, {
231
- item,
232
- href,
233
- index: 0,
234
- variant: "special",
235
- collection,
236
- }), href ? (_jsx(LinkAdapter, { adapters: adapters, href: href, item: item, collection: collection, onClick: () => resolved.onItemClick?.(item, href), className: "collection-ui-button collection-ui-special__button", children: labels.readMore })) : null] }) }) }));
237
- }
238
- function FeaturedBanners({ collections, adapters, labels, }) {
239
- return (_jsx(Container, { adapters: adapters, className: "collection-ui-container--wide", children: _jsx("div", { className: cx("collection-ui-featured", collections.length >= 3 && "collection-ui-featured--three"), children: sortCollections(collections).map((collection) => (_jsx(FeaturedBanner, { collection: collection, adapters: adapters, labels: labels }, collection.id))) }) }));
240
- }
241
- function SlideShow({ collections, adapters, labels, }) {
242
- const id = useId().replaceAll(":", "");
243
- const resolved = getAdapters(adapters);
244
- const slides = sortCollections(collections).map((collection) => (_jsx("div", { className: "collection-ui-slide__item", children: _jsx(FeaturedBanner, { collection: collection, adapters: adapters, labels: labels }) }, collection.id)));
245
- return (_jsx(Container, { adapters: adapters, className: "collection-ui-container--wide", children: _jsx("section", { className: "collection-ui-slide", children: resolved.renderCarousel({
246
- id: `collection-slide-${id}`,
247
- slides,
248
- className: "collection-ui-slide__track",
249
- slideClassName: "collection-ui-slide__slide",
250
- previousLabel: labels.previous,
251
- nextLabel: labels.next,
252
- showControls: true,
253
- effect: "coverflow",
254
- centeredSlides: true,
255
- loop: slides.length > 1,
256
- slidesPerView: 1.1,
257
- slidesPerGroupAuto: false,
258
- spaceBetween: 20,
259
- breakpoints: {
260
- 768: {
261
- slidesPerView: 1.35,
262
- spaceBetween: 24,
263
- },
264
- 1200: {
265
- slidesPerView: 1.6,
266
- spaceBetween: 28,
267
- },
268
- },
269
- }) }) }));
270
- }
271
- function FeaturedBanner({ collection, adapters, labels, }) {
272
- const resolved = getAdapters(adapters);
273
- const href = resolved.resolveCollectionHref(collection);
274
- const handleClick = () => resolved.onCollectionClick?.(collection, href);
275
- if (!collection.imageUrl) {
276
- return null;
277
- }
278
- return (_jsxs("article", { className: "collection-ui-featured-card", children: [_jsx(LinkAdapter, { adapters: adapters, href: href ?? "", collection: collection, onClick: handleClick, children: _jsx(ImageAdapter, { adapters: adapters, src: collection.imageUrl, alt: collection.name ?? "", width: 740, height: 417, priority: true, className: "collection-ui-featured-card__image", collection: collection, style: { height: "auto" } }) }), _jsxs("div", { className: "collection-ui-featured-card__body", children: [_jsx("h2", { className: "collection-ui-featured-card__title", children: _jsx(LinkAdapter, { adapters: adapters, href: href ?? "", collection: collection, onClick: handleClick, children: collection.name }) }), collection.description ? (_jsx("p", { className: "collection-ui-featured-card__description", children: collection.description })) : null, href ? (_jsx(LinkAdapter, { adapters: adapters, href: href, collection: collection, onClick: handleClick, className: "collection-ui-featured-card__link", children: labels.readMore })) : null] })] }));
279
- }
280
- function ImageGrid({ collection, adapters, labels, variant, }) {
281
- const resolved = getAdapters(adapters);
282
- const imageCollections = sortCollections(collection.collections).filter((item) => item.imageUrl);
283
- return (_jsx(Container, { adapters: adapters, children: _jsxs("section", { className: cx("collection-ui-image-grid", `collection-ui-image-grid--${variant}`), children: [_jsx(SectionTitle, { collection: collection, adapters: adapters, labels: labels }), _jsx("div", { className: "collection-ui-image-grid__items", children: imageCollections.map((child, index) => {
284
- const href = resolved.resolveCollectionHref(child);
285
- const handleClick = () => resolved.onCollectionClick?.(child, href);
286
- return (_jsx("div", { className: cx("collection-ui-image-grid__item", variant === "block" &&
287
- index % 2 === 0 &&
288
- "collection-ui-image-grid__item--end"), children: _jsx(LinkAdapter, { adapters: adapters, href: href ?? "", collection: child, onClick: handleClick, children: _jsx(ImageAdapter, { adapters: adapters, src: child.imageUrl ?? "", alt: child.name ?? "", width: variant === "circle" ? 200 : 176, height: variant === "circle" ? 200 : 64, className: cx("collection-ui-image-grid__image", variant === "circle" &&
289
- "collection-ui-image-grid__image--circle", variant === "square" &&
290
- "collection-ui-image-grid__image--square"), collection: child }) }) }, child.id));
291
- }) })] }) }));
292
- }
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId, } from "react";
3
+ import { defaultAdapters } from "./defaultAdapters";
4
+ import { compact, cx, hasCollections, hasItems, sortCollections, } from "./utils";
5
+ const defaultLabels = {
6
+ all: "All",
7
+ viewAll: "View all",
8
+ readMore: "Read more",
9
+ previous: "Previous",
10
+ next: "Next",
11
+ };
12
+ export function CollectionRenderer({ collection, layout, adapters, labels, className, }) {
13
+ const resolvedLayout = layout ?? collection.layout;
14
+ const isPreview = className?.split(/\s+/).includes("collection-ui--preview");
15
+ if (!resolvedLayout) {
16
+ return null;
17
+ }
18
+ return (_jsx("div", { className: cx("collection-ui", className), "data-layout": resolvedLayout.name, "data-direction": resolvedLayout.direction ?? undefined, onClickCapture: isPreview ? preventPreviewNavigation : undefined, style: {
19
+ "--collection-ui-columns": resolvedLayout.columns ?? undefined,
20
+ }, children: _jsx(CollectionBody, { collection: collection, layout: resolvedLayout, adapters: adapters, labels: { ...defaultLabels, ...labels } }) }));
21
+ }
22
+ function preventPreviewNavigation(event) {
23
+ const target = event.target;
24
+ if (!(target instanceof Element)) {
25
+ return;
26
+ }
27
+ const link = target.closest("a[href]");
28
+ if (link) {
29
+ event.preventDefault();
30
+ event.stopPropagation();
31
+ }
32
+ }
33
+ function CollectionBody({ collection, layout, adapters, labels, }) {
34
+ switch (layout.name) {
35
+ case "dynamic":
36
+ case "list": {
37
+ if (!hasItems(collection)) {
38
+ return null;
39
+ }
40
+ if (layout.direction === "vertical") {
41
+ return (_jsx(VerticalList, { collection: collection, items: compact(collection.items), adapters: adapters, labels: labels, numbered: layout.isNumbered }));
42
+ }
43
+ return (_jsx(HorizontalList, { collection: collection, items: compact(collection.items), adapters: adapters, labels: labels }));
44
+ }
45
+ case "grid":
46
+ case "relative": {
47
+ if (!hasItems(collection)) {
48
+ return null;
49
+ }
50
+ return (_jsx(GridList, { collection: collection, items: compact(collection.items), adapters: adapters, labels: labels }));
51
+ }
52
+ case "carousel": {
53
+ if (!hasItems(collection)) {
54
+ return null;
55
+ }
56
+ return (_jsx(HorizontalList, { collection: collection, items: compact(collection.items), adapters: adapters, labels: labels }));
57
+ }
58
+ case "grid-title": {
59
+ if (!hasCollections(collection)) {
60
+ return null;
61
+ }
62
+ return (_jsx(GridTitle, { collection: collection, adapters: adapters, labels: labels, itemLimit: layout.itemLimit ?? 3 }));
63
+ }
64
+ case "hero":
65
+ case "banner": {
66
+ if (!collection.imageUrl) {
67
+ return null;
68
+ }
69
+ return (_jsx(LargeBanner, { collection: collection, adapters: adapters, labels: labels }));
70
+ }
71
+ case "special": {
72
+ if (!hasItems(collection)) {
73
+ return null;
74
+ }
75
+ return (_jsx(SpecialItem, { collection: collection, adapters: adapters, labels: labels }));
76
+ }
77
+ case "slide":
78
+ if (!hasCollections(collection)) {
79
+ return null;
80
+ }
81
+ return (_jsx(SlideShow, { collections: compact(collection.collections), adapters: adapters, labels: labels }));
82
+ case "featured": {
83
+ if (!hasCollections(collection)) {
84
+ return null;
85
+ }
86
+ return (_jsx(FeaturedBanners, { collections: compact(collection.collections), adapters: adapters, labels: labels }));
87
+ }
88
+ case "image-grid": {
89
+ if (!hasCollections(collection)) {
90
+ return null;
91
+ }
92
+ return (_jsx(ImageGrid, { collection: collection, adapters: adapters, labels: labels, variant: layout.shape === "square" ? "square" : "circle" }));
93
+ }
94
+ case "block-grid": {
95
+ if (!hasCollections(collection)) {
96
+ return null;
97
+ }
98
+ return (_jsx(ImageGrid, { collection: collection, adapters: adapters, labels: labels, variant: "block" }));
99
+ }
100
+ default:
101
+ return null;
102
+ }
103
+ }
104
+ function getAdapters(adapters) {
105
+ return { ...defaultAdapters, ...adapters };
106
+ }
107
+ function renderItem(adapters, props) {
108
+ return adapters.renderItem({
109
+ ...props,
110
+ renderBookMedia: adapters.renderBookMedia,
111
+ renderPrice: adapters.renderPrice,
112
+ renderHtml: adapters.renderHtml,
113
+ });
114
+ }
115
+ function Container({ adapters, children, className, }) {
116
+ const resolved = getAdapters(adapters);
117
+ return resolved.renderContainer(children, {
118
+ className: cx("collection-ui-container", className),
119
+ });
120
+ }
121
+ function LinkAdapter({ adapters, href, children, className, collection, item, onClick, }) {
122
+ const resolved = getAdapters(adapters);
123
+ if (!href) {
124
+ return _jsx(_Fragment, { children: children });
125
+ }
126
+ return (_jsx(_Fragment, { children: resolved.renderLink({
127
+ href,
128
+ children,
129
+ className,
130
+ collection,
131
+ item,
132
+ onClick,
133
+ }) }));
134
+ }
135
+ function ImageAdapter(props) {
136
+ const resolved = getAdapters(props.adapters);
137
+ if (!props.src) {
138
+ return null;
139
+ }
140
+ return _jsx(_Fragment, { children: resolved.renderImage(props) });
141
+ }
142
+ function SectionTitle({ collection, adapters, labels, small, actions, }) {
143
+ const resolved = getAdapters(adapters);
144
+ const href = resolved.resolveCollectionHref(collection);
145
+ return (_jsxs("div", { className: "collection-ui-title", children: [_jsxs("div", { className: "collection-ui-title__row", children: [_jsx("h2", { className: cx("collection-ui-title__heading", small && "collection-ui-title__heading--small"), children: href ? (_jsx(LinkAdapter, { adapters: adapters, href: href, collection: collection, children: collection.name })) : (collection.name) }), href || actions ? (_jsxs("div", { className: "collection-ui-title__actions", children: [href ? (_jsx(LinkAdapter, { adapters: adapters, href: href, collection: collection, className: "collection-ui-title__link", children: small ? labels.all : labels.viewAll })) : null, actions] })) : null] }), collection.description ? (_jsx("p", { className: "collection-ui-title__description", children: collection.description })) : null] }));
146
+ }
147
+ function HorizontalList({ collection, items, adapters, labels, }) {
148
+ const id = useId().replaceAll(":", "");
149
+ const carouselId = `collection-carousel-${id}`;
150
+ const resolved = getAdapters(adapters);
151
+ const collectionHref = resolved.resolveCollectionHref(collection);
152
+ const slides = items.map((item, index) => {
153
+ const href = resolved.resolveItemHref(item);
154
+ return renderItem(resolved, {
155
+ item,
156
+ href,
157
+ index,
158
+ variant: "card",
159
+ collection,
160
+ });
161
+ });
162
+ if (collectionHref) {
163
+ slides.push(_jsxs(LinkAdapter, { adapters: adapters, href: collectionHref, collection: collection, className: "collection-ui-view-all", children: [_jsx("span", { className: "collection-ui-view-all__icon", "aria-hidden": "true", children: ">" }), _jsx("span", { children: labels.viewAll })] }));
164
+ }
165
+ return (_jsx(Container, { adapters: adapters, children: _jsxs("section", { className: "collection-ui-horizontal", "aria-labelledby": `collection-title-${id}`, children: [_jsx("div", { id: `collection-title-${id}`, children: _jsx(SectionTitle, { collection: collection, adapters: adapters, labels: labels, actions: _jsxs("div", { className: "collection-ui-title__controls", children: [_jsx("button", { type: "button", "aria-controls": carouselId, "aria-label": labels.previous, className: `prev-btn-${carouselId} collection-ui-carousel__prev-${carouselId} prev-btn`, children: "<" }), _jsx("button", { type: "button", "aria-controls": carouselId, "aria-label": labels.next, className: `next-btn-${carouselId} collection-ui-carousel__next-${carouselId} next-btn`, children: ">" })] }) }) }), resolved.renderCarousel({
166
+ id: carouselId,
167
+ slides,
168
+ className: "collection-ui-carousel__track",
169
+ slideClassName: "collection-ui-carousel__slide",
170
+ previousLabel: labels.previous,
171
+ nextLabel: labels.next,
172
+ showControls: false,
173
+ slidesPerView: "auto",
174
+ slidesPerGroupAuto: true,
175
+ spaceBetween: 20,
176
+ })] }) }));
177
+ }
178
+ function GridList({ collection, items, adapters, labels, }) {
179
+ const resolved = getAdapters(adapters);
180
+ const collectionHref = resolved.resolveCollectionHref(collection);
181
+ const cards = items.map((item, index) => {
182
+ const href = resolved.resolveItemHref(item);
183
+ return (_jsx("div", { className: "collection-ui-grid__item", children: renderItem(resolved, {
184
+ item,
185
+ href,
186
+ index,
187
+ variant: "card",
188
+ collection,
189
+ }) }, item.id));
190
+ });
191
+ return (_jsx(Container, { adapters: adapters, children: _jsxs("section", { className: "collection-ui-grid", "aria-label": collection.name ?? undefined, children: [_jsx(SectionTitle, { collection: collection, adapters: adapters, labels: labels }), _jsxs("div", { className: "collection-ui-grid__items", children: [cards, collectionHref ? (_jsxs(LinkAdapter, { adapters: adapters, href: collectionHref, collection: collection, className: "collection-ui-view-all collection-ui-grid__view-all", children: [_jsx("span", { className: "collection-ui-view-all__icon", "aria-hidden": "true", children: ">" }), _jsx("span", { children: labels.viewAll })] })) : null] })] }) }));
192
+ }
193
+ function VerticalList({ collection, items, adapters, labels, numbered, limit, hideTitle, }) {
194
+ const resolved = getAdapters(adapters);
195
+ const visibleItems = limit ? items.slice(0, limit) : items;
196
+ return (_jsx(Container, { adapters: adapters, children: _jsxs("section", { className: "collection-ui-vertical", children: [hideTitle ? null : (_jsx(SectionTitle, { collection: collection, adapters: adapters, labels: labels })), _jsx("div", { className: "collection-ui-vertical__grid", role: "list", children: visibleItems.map((item, index) => {
197
+ const href = resolved.resolveItemHref(item);
198
+ return (_jsx("div", { className: "collection-ui-vertical__item", role: "listitem", children: renderItem(resolved, {
199
+ item,
200
+ href,
201
+ index,
202
+ number: numbered ? index + 1 : undefined,
203
+ variant: "vertical",
204
+ collection,
205
+ }) }, item.id));
206
+ }) })] }) }));
207
+ }
208
+ function GridTitle({ collection, adapters, labels, itemLimit, }) {
209
+ const id = useId().replaceAll(":", "");
210
+ const resolved = getAdapters(adapters);
211
+ const slides = compact(collection.collections).map((child) => (_jsxs("div", { className: "collection-ui-grid-title__panel", children: [_jsx(SectionTitle, { collection: child, adapters: adapters, labels: labels, small: true }), _jsx(VerticalList, { collection: child, items: compact(child.items), adapters: adapters, labels: labels, numbered: true, limit: itemLimit, hideTitle: true })] }, child.id)));
212
+ return (_jsx("section", { className: "collection-ui-band", children: _jsxs(Container, { adapters: adapters, children: [_jsx(SectionTitle, { collection: collection, adapters: adapters, labels: labels }), resolved.renderCarousel({
213
+ id: `collection-grid-title-${id}`,
214
+ slides,
215
+ className: "collection-ui-grid-title",
216
+ slideClassName: "collection-ui-grid-title__slide",
217
+ previousLabel: labels.previous,
218
+ nextLabel: labels.next,
219
+ showControls: true,
220
+ slidesPerView: 1,
221
+ slidesPerGroupAuto: false,
222
+ spaceBetween: 24,
223
+ breakpoints: {
224
+ 1280: {
225
+ slidesPerView: 2,
226
+ },
227
+ },
228
+ })] }) }));
229
+ }
230
+ function LargeBanner({ collection, adapters, labels, }) {
231
+ const resolved = getAdapters(adapters);
232
+ const href = resolved.resolveCollectionHref(collection);
233
+ const handleClick = () => resolved.onCollectionClick?.(collection, href);
234
+ return (_jsx(Container, { adapters: adapters, className: "collection-ui-container--wide", children: _jsxs("section", { className: "collection-ui-banner", children: [_jsxs("div", { className: "collection-ui-banner__copy", children: [collection.type ? (_jsx("div", { className: "collection-ui-banner__eyebrow", children: resolved.formatCollectionType(collection.type) })) : null, _jsx("h2", { className: "collection-ui-banner__title", children: collection.name }), collection.description ? (_jsx("p", { className: "collection-ui-banner__description", children: collection.description })) : null, href ? (_jsx(LinkAdapter, { adapters: adapters, href: href, collection: collection, onClick: handleClick, className: "collection-ui-button", children: labels.readMore })) : null] }), collection.imageUrl ? (_jsx(LinkAdapter, { adapters: adapters, href: href ?? "", collection: collection, onClick: handleClick, children: _jsx(ImageAdapter, { adapters: adapters, src: collection.imageUrl, alt: collection.name ?? "Collection banner", width: 1003, height: 564, priority: true, sizes: "(max-width: 768px) 100vw, 1003px", className: "collection-ui-banner__image", collection: collection, style: { height: "auto" } }) })) : null] }) }));
235
+ }
236
+ function SpecialItem({ collection, adapters, labels, }) {
237
+ const item = compact(collection.items)[0];
238
+ const resolved = getAdapters(adapters);
239
+ if (!item) {
240
+ return null;
241
+ }
242
+ const href = resolved.resolveItemHref(item);
243
+ return (_jsx("section", { className: "collection-ui-band", children: _jsx(Container, { adapters: adapters, children: _jsxs("div", { className: "collection-ui-special", children: [renderItem(resolved, {
244
+ item,
245
+ href,
246
+ index: 0,
247
+ variant: "special",
248
+ collection,
249
+ }), href ? (_jsx(LinkAdapter, { adapters: adapters, href: href, item: item, collection: collection, onClick: () => resolved.onItemClick?.(item, href), className: "collection-ui-button collection-ui-special__button", children: labels.readMore })) : null] }) }) }));
250
+ }
251
+ function FeaturedBanners({ collections, adapters, labels, }) {
252
+ return (_jsx(Container, { adapters: adapters, className: "collection-ui-container--wide", children: _jsx("div", { className: cx("collection-ui-featured", collections.length >= 3 && "collection-ui-featured--three"), children: sortCollections(collections).map((collection) => (_jsx(FeaturedBanner, { collection: collection, adapters: adapters, labels: labels }, collection.id))) }) }));
253
+ }
254
+ function SlideShow({ collections, adapters, labels, }) {
255
+ const id = useId().replaceAll(":", "");
256
+ const resolved = getAdapters(adapters);
257
+ const slides = sortCollections(collections).map((collection) => (_jsx("div", { className: "collection-ui-slide__item", children: _jsx(FeaturedBanner, { collection: collection, adapters: adapters, labels: labels }) }, collection.id)));
258
+ return (_jsx(Container, { adapters: adapters, className: "collection-ui-container--wide", children: _jsx("section", { className: "collection-ui-slide", children: resolved.renderCarousel({
259
+ id: `collection-slide-${id}`,
260
+ slides,
261
+ className: "collection-ui-slide__track",
262
+ slideClassName: "collection-ui-slide__slide",
263
+ previousLabel: labels.previous,
264
+ nextLabel: labels.next,
265
+ showControls: true,
266
+ effect: "coverflow",
267
+ centeredSlides: true,
268
+ loop: slides.length > 1,
269
+ slidesPerView: 1.1,
270
+ slidesPerGroupAuto: false,
271
+ spaceBetween: 20,
272
+ breakpoints: {
273
+ 768: {
274
+ slidesPerView: 1.35,
275
+ spaceBetween: 24,
276
+ },
277
+ 1200: {
278
+ slidesPerView: 1.6,
279
+ spaceBetween: 28,
280
+ },
281
+ },
282
+ }) }) }));
283
+ }
284
+ function FeaturedBanner({ collection, adapters, labels, }) {
285
+ const resolved = getAdapters(adapters);
286
+ const href = resolved.resolveCollectionHref(collection);
287
+ const handleClick = () => resolved.onCollectionClick?.(collection, href);
288
+ if (!collection.imageUrl) {
289
+ return null;
290
+ }
291
+ return (_jsxs("article", { className: "collection-ui-featured-card", children: [_jsx(LinkAdapter, { adapters: adapters, href: href ?? "", collection: collection, onClick: handleClick, children: _jsx(ImageAdapter, { adapters: adapters, src: collection.imageUrl, alt: collection.name ?? "", width: 740, height: 417, priority: true, className: "collection-ui-featured-card__image", collection: collection, style: { height: "auto" } }) }), _jsxs("div", { className: "collection-ui-featured-card__body", children: [_jsx("h2", { className: "collection-ui-featured-card__title", children: _jsx(LinkAdapter, { adapters: adapters, href: href ?? "", collection: collection, onClick: handleClick, children: collection.name }) }), collection.description ? (_jsx("p", { className: "collection-ui-featured-card__description", children: collection.description })) : null, href ? (_jsx(LinkAdapter, { adapters: adapters, href: href, collection: collection, onClick: handleClick, className: "collection-ui-featured-card__link", children: labels.readMore })) : null] })] }));
292
+ }
293
+ function ImageGrid({ collection, adapters, labels, variant, }) {
294
+ const resolved = getAdapters(adapters);
295
+ const imageCollections = sortCollections(collection.collections).filter((item) => item.imageUrl);
296
+ return (_jsx(Container, { adapters: adapters, children: _jsxs("section", { className: cx("collection-ui-image-grid", `collection-ui-image-grid--${variant}`), children: [_jsx(SectionTitle, { collection: collection, adapters: adapters, labels: labels }), _jsx("div", { className: "collection-ui-image-grid__items", children: imageCollections.map((child, index) => {
297
+ const href = resolved.resolveCollectionHref(child);
298
+ const handleClick = () => resolved.onCollectionClick?.(child, href);
299
+ return (_jsx("div", { className: cx("collection-ui-image-grid__item", variant === "block" &&
300
+ index % 2 === 0 &&
301
+ "collection-ui-image-grid__item--end"), children: _jsx(LinkAdapter, { adapters: adapters, href: href ?? "", collection: child, onClick: handleClick, children: _jsx(ImageAdapter, { adapters: adapters, src: child.imageUrl ?? "", alt: child.name ?? "", width: variant === "circle" ? 200 : 176, height: variant === "circle" ? 200 : 64, className: cx("collection-ui-image-grid__image", variant === "circle" &&
302
+ "collection-ui-image-grid__image--circle", variant === "square" &&
303
+ "collection-ui-image-grid__image--square"), collection: child }) }) }, child.id));
304
+ }) })] }) }));
305
+ }
293
306
  //# sourceMappingURL=CollectionRenderer.js.map