@spillway-cms/blocks 0.1.23 → 0.1.24
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/THIRD_PARTY_NOTICES.md +49 -0
- package/dist/breadcrumbs.d.ts +27 -0
- package/dist/breadcrumbs.js +44 -0
- package/dist/breadcrumbs.js.map +1 -0
- package/dist/config.d.ts +50 -4
- package/dist/config.js +103 -23
- package/dist/config.js.map +1 -1
- package/dist/css.js +26 -0
- package/dist/css.js.map +1 -1
- package/dist/examples.js +67 -1
- package/dist/examples.js.map +1 -1
- package/dist/icons-data.d.ts +18 -0
- package/dist/icons-data.js +117 -0
- package/dist/icons-data.js.map +1 -0
- package/dist/icons.d.ts +31 -0
- package/dist/icons.js +49 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/marketing.d.ts +3 -0
- package/dist/marketing.js +5 -2
- package/dist/marketing.js.map +1 -1
- package/dist/meta.js +38 -13
- package/dist/meta.js.map +1 -1
- package/dist/motion.d.ts +1 -1
- package/dist/motion.js +2 -1
- package/dist/motion.js.map +1 -1
- package/dist/styles.css +183 -1
- package/dist/styles.js +95 -0
- package/dist/styles.js.map +1 -1
- package/dist/toc.d.ts +32 -0
- package/dist/toc.js +79 -0
- package/dist/toc.js.map +1 -0
- package/dist/video.d.ts +36 -1
- package/dist/video.js +157 -4
- package/dist/video.js.map +1 -1
- package/dist/widgets.d.ts +95 -0
- package/dist/widgets.js +449 -0
- package/dist/widgets.js.map +1 -0
- package/package.json +4 -3
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Carousel, Accordion and Tabs (docs/dev/blocks-carousel-accordion-tabs.md): blocks whose slides, items and tabs are slots, so
|
|
3
|
+
* each holds any blocks. All three render complete HTML on the server that works with no script: the Carousel is a row that
|
|
4
|
+
* scrolls sideways with scroll snapping, the Accordion shows every item open under its heading, Tabs shows a list of links to
|
|
5
|
+
* the panels and every panel under its heading. WIDGETS_SCRIPT, which the page carries once when it has one of them, adds the
|
|
6
|
+
* controls, collapses, selects and wires up ARIA following the WAI-ARIA Authoring Practices. In the page builder they render the
|
|
7
|
+
* no-script layout with every slot open, so editors can drop blocks into each one. Server-safe: no hooks, no browser APIs.
|
|
8
|
+
*/
|
|
9
|
+
import type { ComponentConfig, Config, Slot } from '@puckeditor/core';
|
|
10
|
+
/** "Visiting campus" → "visiting-campus": a link name for an id and a URL hash. */
|
|
11
|
+
export declare function slugify(text: string): string;
|
|
12
|
+
type HeadingLevel = 'h2' | 'h3' | 'h4';
|
|
13
|
+
export interface AccordionItem {
|
|
14
|
+
title: string;
|
|
15
|
+
/** The item's link name (its id, for `#name` links); empty uses the title. */
|
|
16
|
+
anchor?: string;
|
|
17
|
+
content: Slot;
|
|
18
|
+
}
|
|
19
|
+
export interface AccordionProps {
|
|
20
|
+
title: string;
|
|
21
|
+
items: AccordionItem[];
|
|
22
|
+
/** The heading level of the item titles. */
|
|
23
|
+
headingLevel: HeadingLevel;
|
|
24
|
+
/** One item open at a time, or several. */
|
|
25
|
+
open: 'single' | 'multiple';
|
|
26
|
+
openFirst: boolean;
|
|
27
|
+
/** Mark as FAQ: the titles and their content's text join the page's one FAQPage structured data (a Spillway server adds it). */
|
|
28
|
+
faq: boolean;
|
|
29
|
+
width: 'narrow' | 'normal';
|
|
30
|
+
/** The block style's key (Brand → Styles); empty means the site's default Accordion style. */
|
|
31
|
+
style?: string;
|
|
32
|
+
}
|
|
33
|
+
export declare function accordionComponent(getConfig: () => Config): ComponentConfig<AccordionProps>;
|
|
34
|
+
export interface TabsTab {
|
|
35
|
+
label: string;
|
|
36
|
+
/** The tab's link name (its panel's id, for `#name` links); empty uses the label. */
|
|
37
|
+
anchor?: string;
|
|
38
|
+
content: Slot;
|
|
39
|
+
}
|
|
40
|
+
export interface TabsProps {
|
|
41
|
+
title: string;
|
|
42
|
+
tabs: TabsTab[];
|
|
43
|
+
orientation: 'horizontal' | 'vertical';
|
|
44
|
+
/** The level of the panel headings people see without the script (and in the page builder). */
|
|
45
|
+
headingLevel: HeadingLevel;
|
|
46
|
+
/** The block style's key (Brand → Styles); empty means the site's default Tabs style. */
|
|
47
|
+
style?: string;
|
|
48
|
+
}
|
|
49
|
+
export declare function tabsComponent(getConfig: () => Config): ComponentConfig<TabsProps>;
|
|
50
|
+
export interface CarouselSlide {
|
|
51
|
+
/** The slide's name: the picker's label and the page builder's summary. */
|
|
52
|
+
label: string;
|
|
53
|
+
/** A small picture for the testimonial variant's switcher (a media library image or a URL). */
|
|
54
|
+
thumbnail?: string;
|
|
55
|
+
content: Slot;
|
|
56
|
+
}
|
|
57
|
+
export type CarouselVariant = 'hero' | 'cards' | 'testimonial' | 'stats';
|
|
58
|
+
export interface CarouselProps {
|
|
59
|
+
/** The carousel's name: an H2 above the slides when `showTitle`, else only its accessible name. */
|
|
60
|
+
title: string;
|
|
61
|
+
showTitle: boolean;
|
|
62
|
+
variant: CarouselVariant;
|
|
63
|
+
slides: CarouselSlide[];
|
|
64
|
+
/** Hero: as tall as the content, or the full screen. */
|
|
65
|
+
height: 'auto' | 'screen';
|
|
66
|
+
/** Cards and stats: slides visible on wide screens. */
|
|
67
|
+
perView: 2 | 3 | 4;
|
|
68
|
+
/** Off by default; never plays when the brand's motion is off or the visitor reduces motion. */
|
|
69
|
+
autoplay: boolean;
|
|
70
|
+
/** Seconds per slide while autoplay runs. */
|
|
71
|
+
interval: 5 | 7 | 10;
|
|
72
|
+
/** Next on the last slide goes back to the first, Previous on the first to the last. */
|
|
73
|
+
loop: boolean;
|
|
74
|
+
/** The block style's key (Brand → Styles); empty means the site's default Carousel style. */
|
|
75
|
+
style?: string;
|
|
76
|
+
}
|
|
77
|
+
export declare function carouselComponent(getConfig: () => Config): ComponentConfig<CarouselProps>;
|
|
78
|
+
export declare const WIDGETS_CSS = "\n/* ---------- Carousel, Accordion, Tabs ---------- */\n/* Blocks inside a slide, an item or a tab share its box: no second gutter, one gap between them. */\n.sw-slot-body > .sw-block { padding-block: 0; }\n.sw-slot-body > .sw-block + .sw-block { padding-top: var(--sw-space-2); }\n.sw-slot-body .sw-container { max-width: none; padding-inline: 0; }\n\n/* Accordion: without the script every item is open under its heading; with it the heading holds a button. */\n.sw-accordion__title { margin: 0 0 var(--sw-space-3); }\n.sw-accordion__list { display: grid; gap: var(--sw-accordion-gap, 0); border-top: var(--sw-accordion-rule, 1px solid var(--sw-color-border)); }\n.sw-accordion__item { border-bottom: 1px solid var(--sw-color-border); scroll-margin-top: var(--sw-space-3); }\n.sw-page .sw-accordion__heading { margin: 0; font-size: 1.125rem; line-height: 1.35; letter-spacing: 0; }\n.sw-accordion__heading > .sw-accordion__label { display: block; padding: var(--sw-space-2) 0 var(--sw-space-1); }\n.sw-accordion__trigger { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: var(--sw-space-2); min-height: 3rem; padding: var(--sw-space-2) 0; margin: 0; font: inherit; font-weight: 700; color: inherit; text-align: start; background: none; border: 0; border-radius: 2px; cursor: pointer; }\n.sw-accordion__trigger:hover .sw-accordion__label { text-decoration: underline; text-underline-offset: 0.15em; }\n.sw-accordion__icon { position: relative; flex: none; width: 1rem; height: 1rem; color: var(--sw-color-primary, #1d4ed8); }\n.sw-accordion__icon::before, .sw-accordion__icon::after { content: ''; position: absolute; left: 0; top: calc(50% - 1px); width: 100%; height: 2px; border-radius: 1px; background: currentColor; transition: transform 160ms ease; }\n.sw-accordion__icon::after { transform: rotate(90deg); }\n.sw-accordion__trigger[aria-expanded=\"true\"] .sw-accordion__icon::after { transform: rotate(0deg); }\n.sw-accordion__panel { padding: 0 0 var(--sw-space-2); }\n.sw-accordion__panel[hidden] { display: none; }\n.sw-accordion__panel[hidden=\"until-found\"] { display: block; content-visibility: hidden; padding: 0; }\n\n/* Tabs: without the script, a list of links to the panels and every panel under its heading. */\n.sw-tabs__title { margin: 0 0 var(--sw-space-3); }\n.sw-tabs__layout { display: grid; gap: var(--sw-space-3); }\n.sw-tabs__list { position: relative; display: flex; gap: var(--sw-space-1); margin: 0; padding: 0; list-style: none; overflow-x: auto; scrollbar-width: thin; border-bottom: var(--sw-tabs-rule, 1px solid var(--sw-color-border)); }\n.sw-tabs__item { flex: none; display: flex; }\n.sw-page .sw-tabs__tab { display: inline-flex; align-items: center; min-height: 2.75rem; padding: 0.5rem 1rem; color: var(--sw-color-muted); font-weight: 600; text-decoration: none; white-space: nowrap; border-radius: var(--sw-radius, 8px) var(--sw-radius, 8px) 0 0; }\n.sw-page .sw-tabs__tab:hover { color: var(--sw-color-text); text-decoration: none; }\n.sw-page .sw-tabs__tab[aria-selected=\"true\"] { color: var(--sw-color-text); box-shadow: inset 0 -3px 0 var(--sw-color-primary, #1d4ed8); }\n/* Inside the ring: the list scrolls, so a ring outside the tab would be cut off. */\n.sw-page .sw-tabs__tab:focus-visible { outline: 2px solid var(--sw-color-primary, #1d4ed8); outline-offset: -4px; }\n.sw-tabs__panel { scroll-margin-top: var(--sw-space-3); }\n.sw-tabs__panel + .sw-tabs__panel { margin-top: var(--sw-space-4); }\n.sw-page .sw-tabs__heading { margin: 0 0 var(--sw-space-2); }\n.sw-tabs--on .sw-tabs__panel + .sw-tabs__panel { margin-top: 0; }\n.sw-tabs--on .sw-tabs__heading { display: none; }\n.sw-tabs__panel[hidden] { display: none; }\n.sw-tabs--on .sw-tabs__panel:focus-visible { outline: none; box-shadow: var(--sw-focus-ring); border-radius: 2px; }\n@media (min-width: 760px) {\n .sw-tabs--vertical .sw-tabs__layout { grid-template-columns: minmax(10rem, 15rem) minmax(0, 1fr); align-items: start; }\n .sw-tabs--vertical .sw-tabs__list { flex-direction: column; overflow: visible; border-bottom: 0; border-inline-end: var(--sw-tabs-rule, 1px solid var(--sw-color-border)); }\n .sw-page .sw-tabs--vertical .sw-tabs__tab { width: 100%; white-space: normal; border-radius: var(--sw-radius, 8px) 0 0 var(--sw-radius, 8px); }\n .sw-page .sw-tabs--vertical .sw-tabs__tab[aria-selected=\"true\"] { box-shadow: inset -3px 0 0 var(--sw-color-primary, #1d4ed8); }\n}\n\n/* Carousel: without the script a row that scrolls sideways with snapping; with it, controls and one row position at a time. */\n.sw-carousel { --sw-carousel-gap: var(--sw-space-3, 1.5rem); --sw-carousel-n: 1; --sw-carousel-peek: 0px; position: relative; }\n.sw-carousel__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sw-space-2); margin-bottom: var(--sw-space-3); }\n.sw-carousel__head--empty, .sw-carousel--hero .sw-carousel__head:not(:has(.sw-carousel__title)) { margin-bottom: 0; }\n.sw-carousel__title { margin: 0; }\n.sw-carousel__frame { position: relative; }\n.sw-carousel__track { position: relative; display: flex; gap: var(--sw-carousel-gap); overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x mandatory; scrollbar-width: thin; padding: 6px 6px var(--sw-space-1); margin-inline: -6px; scroll-padding-inline: 6px; }\n.sw-carousel--hero .sw-carousel__track { padding: 0; margin-inline: 0; scroll-padding-inline: 0; }\n.sw-carousel__track:focus-visible { outline: none; box-shadow: var(--sw-focus-ring); border-radius: 2px; }\n.sw-carousel__slide { flex: 0 0 calc((100% - (var(--sw-carousel-n) - 1) * var(--sw-carousel-gap) - var(--sw-carousel-peek)) / var(--sw-carousel-n)); min-width: 0; scroll-snap-align: start; }\n.sw-carousel--cards { --sw-carousel-peek: 15%; }\n@media (min-width: 640px) { .sw-carousel--per-2, .sw-carousel--per-3, .sw-carousel--per-4 { --sw-carousel-n: 2; } .sw-carousel--cards { --sw-carousel-peek: 3rem; } }\n@media (min-width: 900px) { .sw-carousel--per-3, .sw-carousel--per-4 { --sw-carousel-n: 3; } }\n@media (min-width: 1100px) { .sw-carousel--per-4 { --sw-carousel-n: 4; } }\n.sw-carousel--hero { --sw-carousel-gap: 0px; }\n.sw-block.sw-carousel--hero { padding-block: 0; }\n.sw-carousel--hero + .sw-block { padding-top: var(--sw-block-pad, 1.5rem); }\n.sw-carousel--hero .sw-carousel__body { display: flex; flex-direction: column; height: 100%; }\n.sw-carousel--hero .sw-carousel__body > * { flex: 1 0 auto; }\n.sw-carousel--full .sw-carousel__slide { min-height: 100svh; }\n.sw-carousel--testimonial .sw-carousel__slide { text-align: center; }\n.sw-carousel--testimonial .sw-carousel__body { max-width: 46rem; margin-inline: auto; font-size: 1.125rem; }\n.sw-carousel--stats .sw-carousel__slide { text-align: center; }\n.sw-page .sw-carousel--stats .sw-carousel__body > .sw-block:first-child :is(h2, h3, h4) { font-size: clamp(2.25rem, 1.6rem + 3vw, 3.5rem); color: var(--sw-color-primary, #1d4ed8); font-variant-numeric: tabular-nums; }\n.sw-carousel__slide-frame { height: 100%; }\n/* With the script: no scroll bar (the controls move the row), the controls and the picker appear. */\n.sw-carousel--on .sw-carousel__track { scrollbar-width: none; }\n.sw-carousel--on:not(.sw-carousel--hero) .sw-carousel__track { padding-bottom: 6px; }\n.sw-carousel--on .sw-carousel__track::-webkit-scrollbar { display: none; }\n.sw-carousel__controls { display: flex; align-items: center; gap: var(--sw-space-1); margin-inline-start: auto; }\n.sw-carousel__controls[hidden], .sw-carousel__picker[hidden], .sw-carousel__button[hidden] { display: none; }\n.sw-carousel__button { display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem; min-width: 2.75rem; min-height: 2.75rem; padding: 0 0.75rem; font: inherit; font-size: 0.875rem; font-weight: 600; line-height: 1; color: var(--sw-carousel-ink, var(--sw-color-primary-contrast, #ffffff)); background: var(--sw-carousel-fill, var(--sw-color-primary, #1d4ed8)); border: 2px solid var(--sw-carousel-edge, var(--sw-color-primary, #1d4ed8)); border-radius: 999px; cursor: pointer; }\n.sw-carousel__prev, .sw-carousel__next { padding: 0; }\n.sw-carousel__button[aria-disabled=\"true\"] { opacity: 0.45; cursor: default; }\n.sw-carousel__foot { display: flex; justify-content: center; margin-top: var(--sw-space-2); }\n.sw-carousel__picker { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.25rem; }\n.sw-carousel__pick { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 1.75rem; height: 1.75rem; padding: 0; background: none; border: 0; border-radius: 999px; cursor: pointer; color: var(--sw-color-primary, #1d4ed8); }\n.sw-carousel__pick::before { content: ''; width: 0.7rem; height: 0.7rem; border-radius: 999px; border: 2px solid currentColor; background: transparent; }\n.sw-carousel__pick[aria-current=\"true\"]::before { background: currentColor; }\n.sw-carousel__picker--thumbs { gap: var(--sw-space-1); }\n.sw-carousel__picker--thumbs .sw-carousel__pick { width: 3.25rem; height: 3.25rem; border: 2px solid transparent; }\n.sw-carousel__picker--thumbs .sw-carousel__pick::before { content: none; }\n.sw-carousel__picker--thumbs .sw-carousel__pick[aria-current=\"true\"] { border-color: currentColor; }\n.sw-carousel__thumb { width: 2.75rem; height: 2.75rem; border-radius: 999px; object-fit: cover; }\n.sw-carousel__initial { display: inline-flex; align-items: center; justify-content: center; width: 2.75rem; height: 2.75rem; border-radius: 999px; background: var(--sw-color-surface); color: var(--sw-color-text); font-weight: 700; }\n/* Hero: the controls and the picker sit over the slide. */\n.sw-carousel--hero .sw-carousel__head { position: absolute; inset-inline: 0; bottom: var(--sw-space-3); z-index: 2; margin: 0; pointer-events: none; }\n.sw-carousel--hero .sw-carousel__head > * { pointer-events: auto; }\n.sw-carousel--hero .sw-carousel__head:has(.sw-carousel__title) { position: static; margin-block: var(--sw-block-pad, 1.5rem) var(--sw-space-3); pointer-events: auto; }\n.sw-carousel--hero .sw-carousel__foot { position: absolute; inset-inline: 0; bottom: var(--sw-space-3); z-index: 1; justify-content: flex-start; margin: 0; pointer-events: none; }\n.sw-carousel--hero .sw-carousel__picker { pointer-events: auto; padding: 0.15rem 0.35rem; border-radius: 999px; background: rgba(0, 0, 0, 0.55); color: #ffffff; }\n.sw-carousel--hero .sw-carousel__pick { color: #ffffff; }\n.sw-carousel--hero .sw-carousel__pick:focus-visible { box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px #111827; }\n/* The page builder: slides one under the other, each named. */\n.sw-carousel--editing .sw-carousel__edit-slide + .sw-carousel__edit-slide { margin-top: var(--sw-space-3); }\n.sw-page .sw-carousel__edit-label { margin: 0 auto var(--sw-space-1); font-size: 0.8125rem; font-weight: 600; letter-spacing: 0.02em; color: var(--sw-color-muted); }\n@media (prefers-reduced-motion: no-preference) {\n html:not(.sw-reduce-motion) .sw-carousel__track { scroll-behavior: smooth; }\n}\n";
|
|
79
|
+
/** Blocks that need WIDGETS_SCRIPT: the page renderer adds it once when the layout has one of them. */
|
|
80
|
+
export declare const WIDGET_BLOCKS: readonly ["Carousel", "Accordion", "Tabs"];
|
|
81
|
+
/** Whether a block needs WIDGETS_SCRIPT: a Carousel, Accordion or Tabs, or a Video playing a YouTube or Vimeo video (its facade). */
|
|
82
|
+
export declare function needsWidgetsScript(type: string, props: Record<string, unknown> | undefined): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* The page script that enhances every Carousel, Accordion and Tabs block on the page (inline with the page's nonce, once per
|
|
85
|
+
* page). It runs once per document, picks up blocks added later (a Personalize island) and follows the visitor's Reduce motion
|
|
86
|
+
* choice (`sw-reduce-motion` on the root, or the stored choice, or the device's setting): autoplay never runs under it and slide
|
|
87
|
+
* changes jump instead of scrolling smoothly. Autoplay also needs the brand's motion on (`data-sw-motion` on the root).
|
|
88
|
+
*
|
|
89
|
+
* It also plays YouTube and Vimeo videos (the Video block's facade, `data-sw-video`): pressing the facade puts the player in a
|
|
90
|
+
* sandboxed frame in its place, or in the lightbox when it opens (and takes it out when it closes, which stops the video). Nothing
|
|
91
|
+
* is requested from YouTube or Vimeo before that. The consent note goes away once the visitor has allowed marketing and embedded
|
|
92
|
+
* content (the consent banner's cookie, never with Global Privacy Control).
|
|
93
|
+
*/
|
|
94
|
+
export declare const WIDGETS_SCRIPT = "(function(){var d=document,h=d.documentElement;if(h.hasAttribute('data-sw-widgets'))return;h.setAttribute('data-sw-widgets','');\nvar K='sw-reduce-motion',mq=window.matchMedia?matchMedia('(prefers-reduced-motion: reduce)'):null,found=!!(d.body&&'onbeforematch' in d.body),watchers=[];\nfunction stored(){try{return localStorage.getItem(K)}catch(e){return null}}\nfunction reduced(){if(h.classList.contains('sw-reduce-motion'))return true;if(h.classList.contains('sw-motion-allowed'))return false;var s=stored();return s===null?!!(mq&&mq.matches):s==='1'}\nfunction own(root,sel,attr){return [].slice.call(root.querySelectorAll(sel)).filter(function(el){return el.closest('['+attr+']')===root})}\nfunction keyboardFocus(el){try{return el.matches(':focus-visible')}catch(e){return true}}\nfunction setItem(it,open){it._swb.setAttribute('aria-expanded',open?'true':'false');it.classList.toggle('sw-accordion__item--open',open);if(open)it._swp.removeAttribute('hidden');else if(found)it._swp.setAttribute('hidden','until-found');else it._swp.hidden=true}\nfunction accordion(root){if(root._sw)return;root._sw=1;var single=root.getAttribute('data-sw-accordion')==='single',items=own(root,'.sw-accordion__item','data-sw-accordion'),btns=[];\nfunction only(it){if(single)items.forEach(function(o){if(o!==it&&o._swb)setItem(o,false)})}\nitems.forEach(function(it){var hd=it.querySelector('.sw-accordion__heading'),pn=it.querySelector('.sw-accordion__panel');if(!hd||!pn||hd.closest('.sw-accordion__item')!==it)return;\nvar b=d.createElement('button');b.type='button';b.className='sw-accordion__trigger';b.id=pn.id+'-button';b.setAttribute('aria-controls',pn.id);while(hd.firstChild)b.appendChild(hd.firstChild);\nvar ic=d.createElement('span');ic.className='sw-accordion__icon';ic.setAttribute('aria-hidden','true');b.appendChild(ic);hd.appendChild(b);pn.setAttribute('aria-labelledby',b.id);\nit._swb=b;it._swp=pn;btns.push(b);it._swOpen=function(){only(it);setItem(it,true)};\nb.addEventListener('click',function(){var open=b.getAttribute('aria-expanded')!=='true';if(open)only(it);setItem(it,open)});\npn.addEventListener('beforematch',function(){only(it);setItem(it,true)})});\nvar first=true;items.forEach(function(it){if(!it._swb)return;var open=it.hasAttribute('data-open')&&(!single||first);if(open)first=false;setItem(it,open)});\nroot.addEventListener('keydown',function(e){var i=btns.indexOf(e.target);if(i<0)return;var k=e.key,n=k==='ArrowDown'?i+1:k==='ArrowUp'?i-1:k==='Home'?0:k==='End'?btns.length-1:null;if(n===null)return;e.preventDefault();btns[(n+btns.length)%btns.length].focus()});\nroot.classList.add('sw-accordion--on')}\nfunction tabs(root){if(root._sw)return;root._sw=1;var list=own(root,'.sw-tabs__list','data-sw-tabs')[0],ts=own(root,'.sw-tabs__tab','data-sw-tabs'),ps=own(root,'.sw-tabs__panel','data-sw-tabs');if(!list||!ts.length||ts.length!==ps.length)return;\nvar vertical=root.getAttribute('data-sw-tabs')==='vertical',cur=-1;list.setAttribute('role','tablist');if(vertical)list.setAttribute('aria-orientation','vertical');\n[].slice.call(list.children).forEach(function(li){li.setAttribute('role','presentation')});\nfunction reveal(t){if(list.scrollWidth<=list.clientWidth+1)return;var a=t.offsetLeft,b=a+t.offsetWidth;if(a<list.scrollLeft)list.scrollLeft=Math.max(0,a-8);else if(b>list.scrollLeft+list.clientWidth)list.scrollLeft=b-list.clientWidth+8}\nfunction select(i,url){cur=i;ts.forEach(function(t,k){var on=k===i;t.setAttribute('aria-selected',on?'true':'false');t.tabIndex=on?0:-1;ps[k].hidden=!on});reveal(ts[i]);if(url&&history.replaceState)try{history.replaceState(history.state,'','#'+ps[i].id)}catch(e){}}\nts.forEach(function(t,i){var p=ps[i];t.setAttribute('role','tab');t.setAttribute('aria-controls',p.id);p.setAttribute('role','tabpanel');p.setAttribute('aria-labelledby',t.id);p.tabIndex=0;p._swSelect=function(){select(i,false)};\nt.addEventListener('click',function(e){e.preventDefault();select(i,true)})});\nlist.addEventListener('keydown',function(e){var i=ts.indexOf(e.target);if(i<0)return;var k=e.key,n=null;if(k==='ArrowRight'||(vertical&&k==='ArrowDown'))n=i+1;else if(k==='ArrowLeft'||(vertical&&k==='ArrowUp'))n=i-1;else if(k==='Home')n=0;else if(k==='End')n=ts.length-1;\nif(n===null)return;e.preventDefault();n=(n+ts.length)%ts.length;select(n,true);ts[n].focus()});\nselect(0,false);root.classList.add('sw-tabs--on')}\nfunction carousel(root){if(root._sw)return;root._sw=1;var A='data-sw-carousel',track=own(root,'.sw-carousel__track',A)[0];if(!track)return;\nvar slides=own(root,'.sw-carousel__slide',A),n=slides.length;if(n<2)return;\nvar prev=own(root,'[data-sw-carousel-prev]',A)[0],next=own(root,'[data-sw-carousel-next]',A)[0],pause=own(root,'[data-sw-carousel-pause]',A)[0],picks=own(root,'[data-sw-carousel-pick]',A);\nvar loop=root.hasAttribute('data-loop'),auto=+root.getAttribute('data-autoplay')||0,cur=0,timer=0,stopped=false,hover=false,seen=true,st=0,rtl=getComputedStyle(track).direction==='rtl';\nown(root,'[data-sw-carousel-controls],[data-sw-carousel-picker]',A).forEach(function(c){c.hidden=false});root.classList.add('sw-carousel--on');\nfunction pos(i){return Math.abs(slides[i].offsetLeft-slides[0].offsetLeft)}\nfunction max(){return Math.max(0,track.scrollWidth-track.clientWidth)}\nfunction at(){return Math.abs(track.scrollLeft)}\nfunction nearest(){var x=at(),m=max(),best=0,bd=1/0;for(var i=0;i<n;i++){var dd=Math.abs(Math.min(pos(i),m)-x);if(dd<bd-1){bd=dd;best=i}}return best}\nfunction shown(i){var x=at(),p=pos(i);return p>=x-2&&p+slides[i].offsetWidth<=x+track.clientWidth+2}\nfunction sync(){cur=nearest();var lost=false;slides.forEach(function(s,i){var v=shown(i)||i===cur;if(!v&&s.contains(d.activeElement))lost=true;if(v){s.removeAttribute('inert');s.removeAttribute('aria-hidden')}else{s.setAttribute('inert','');s.setAttribute('aria-hidden','true')}});\nif(lost)track.focus({preventScroll:true});\npicks.forEach(function(b,i){if(i===cur)b.setAttribute('aria-current','true');else b.removeAttribute('aria-current');b.tabIndex=i===cur?0:-1});\nif(prev)prev.setAttribute('aria-disabled',!loop&&at()<=2?'true':'false');if(next)next.setAttribute('aria-disabled',!loop&&at()>=max()-2?'true':'false')}\nfunction go(i){i=loop?(i+n)%n:Math.max(0,Math.min(n-1,i));var left=Math.min(pos(i),max());if(Math.abs(left-at())<1){sync();return}track.scrollTo({left:rtl?-left:left,behavior:reduced()?'auto':'smooth'})}\nfunction step(dir){if(dir>0){if(at()>=max()-2){if(loop)go(0);return}go(cur+1)}else{if(at()<=2){if(loop)go(n-1);return}go(cur-1)}}\nfunction allowed(){return auto>0&&h.hasAttribute('data-sw-motion')&&!reduced()}\nfunction schedule(){clearTimeout(timer);timer=0;var on=allowed();if(pause){pause.hidden=!on;pause.textContent=stopped?'Play slides':'Pause slides'}track.setAttribute('aria-live',on&&!stopped?'off':'polite');\nif(on&&!stopped&&!hover&&seen&&!d.hidden)timer=setTimeout(function(){timer=0;if(at()>=max()-2)go(0);else step(1);schedule()},auto*1000)}\nfunction keyStep(e){var k=e.key;if(k==='ArrowRight')return rtl?-1:1;if(k==='ArrowLeft')return rtl?1:-1;if(k==='Home')return 'first';if(k==='End')return 'last';return 0}\ntrack.addEventListener('scroll',function(){clearTimeout(st);st=setTimeout(sync,90)},{passive:true});\ntrack.addEventListener('keydown',function(e){if(e.target!==track)return;var s=keyStep(e);if(!s)return;e.preventDefault();if(s==='first')go(0);else if(s==='last')go(n-1);else step(s)});\npicks.forEach(function(b,i){b.addEventListener('click',function(){go(i);schedule()});b.addEventListener('keydown',function(e){var s=keyStep(e);if(!s)return;e.preventDefault();var j=s==='first'?0:s==='last'?picks.length-1:(i+s+picks.length)%picks.length;go(j);picks[j].tabIndex=0;picks[j].focus()})});\nif(prev)prev.addEventListener('click',function(){if(prev.getAttribute('aria-disabled')!=='true')step(-1);schedule()});\nif(next)next.addEventListener('click',function(){if(next.getAttribute('aria-disabled')!=='true')step(1);schedule()});\nif(pause)pause.addEventListener('click',function(){stopped=!stopped;schedule()});\nroot.addEventListener('focusin',function(e){if(!stopped&&allowed()&&keyboardFocus(e.target)){stopped=true;schedule()}});\nroot.addEventListener('pointerdown',function(e){if(e.pointerType==='touch'&&allowed()&&!stopped){stopped=true;schedule()}});\nroot.addEventListener('mouseenter',function(){hover=true;schedule()});root.addEventListener('mouseleave',function(){hover=false;schedule()});\nif('IntersectionObserver' in window)new IntersectionObserver(function(es){seen=es[es.length-1].isIntersecting;schedule()}).observe(root);\nd.addEventListener('visibilitychange',schedule);window.addEventListener('resize',function(){clearTimeout(st);st=setTimeout(sync,120)});\nwatchers.push(schedule);root._swGo=go;sync();schedule()}\nfunction consented(){if(navigator.globalPrivacyControl===true)return false;return /(?:^|; )sw_consent=(?:1|a[01]m1)(?:;|$)/.test(d.cookie)}\nfunction notes(box,hide){[].forEach.call(box.querySelectorAll('[data-sw-video-consent]'),function(n){n.hidden=hide})}\nfunction frameFor(box){var f=d.createElement('iframe');f.className='sw-video__frame';f.src=box.getAttribute('data-sw-video');f.title=box.getAttribute('data-sw-video-title')||'Video';f.setAttribute('allow','autoplay; encrypted-media; picture-in-picture; fullscreen');var sb=box.getAttribute('data-sw-video-sandbox');if(sb)f.setAttribute('sandbox',sb);f.setAttribute('referrerpolicy','strict-origin-when-cross-origin');return f}\nfunction video(box){if(box._sw)return;box._sw=1;if(!/^https:\\/\\/(www\\.youtube-nocookie\\.com|player\\.vimeo\\.com)\\//.test(box.getAttribute('data-sw-video')||''))return;if(consented())notes(box,true);\nvar a=box.querySelector('[data-sw-video-facade]');if(a){a.setAttribute('role','button');\na.addEventListener('click',function(e){if(e.button||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey)return;e.preventDefault();var f=frameFor(box);a.parentNode.replaceChild(f,a);notes(box,true);try{f.focus()}catch(x){}});\na.addEventListener('keydown',function(e){if(e.key===' '){e.preventDefault();a.click()}})}\nvar b=box.querySelector('[popovertarget]'),pop=b&&d.getElementById(b.getAttribute('popovertarget'));if(!pop||pop._sw)return;pop._sw=1;\npop.addEventListener('toggle',function(e){var st=pop.querySelector('[data-sw-video-stage]');if(!st)return;var open=e.newState?e.newState==='open':pop.matches(':popover-open');\nif(open){if(st.querySelector('iframe'))return;st._kids=[].slice.call(st.childNodes);st._kids.forEach(function(k){st.removeChild(k)});st.appendChild(frameFor(box));notes(box,true)}\nelse{var f=st.querySelector('iframe');if(f)st.removeChild(f);(st._kids||[]).forEach(function(k){st.appendChild(k)})}})}\nfunction init(scope){if(scope.matches){if(scope.matches('[data-sw-accordion]'))accordion(scope);if(scope.matches('[data-sw-tabs]'))tabs(scope);if(scope.matches('[data-sw-carousel]'))carousel(scope);if(scope.matches('[data-sw-video]'))video(scope)}\n[].slice.call(scope.querySelectorAll('[data-sw-accordion]')).forEach(accordion);[].slice.call(scope.querySelectorAll('[data-sw-tabs]')).forEach(tabs);[].slice.call(scope.querySelectorAll('[data-sw-carousel]')).forEach(carousel);[].slice.call(scope.querySelectorAll('[data-sw-video]')).forEach(video)}\nfunction toHash(scroll){var id;try{id=decodeURIComponent(location.hash.slice(1))}catch(e){return}if(!id)return;var t=d.getElementById(id);if(!t)return;var el=t,hit=false,box=t;\nwhile(el){if(el._swOpen){el._swOpen();hit=true}if(el._swSelect){el._swSelect();hit=true;if(el===t)box=el.closest('[data-sw-tabs]')||t}el=el.parentElement}\nif(hit&&scroll)box.scrollIntoView({block:'start'});if(hit){var f=t._swb||(box!==t&&box.querySelector('[role=tab][aria-selected=true]'));if(f)try{f.focus({preventScroll:true})}catch(e){}}}\ninit(d);toHash(true);window.addEventListener('hashchange',function(){toHash(true)});\nfunction motionChanged(){watchers.forEach(function(w){w()})}\nif(mq){if(mq.addEventListener)mq.addEventListener('change',motionChanged);else if(mq.addListener)mq.addListener(motionChanged)}\nwindow.addEventListener('storage',function(e){if(e.key===K)motionChanged()});\nif('MutationObserver' in window){new MutationObserver(motionChanged).observe(h,{attributes:true,attributeFilter:['class','data-sw-motion']});\nnew MutationObserver(function(ms){ms.forEach(function(m){[].forEach.call(m.addedNodes,function(nd){if(nd.nodeType===1&&nd.querySelector)init(nd)})})}).observe(d.body,{childList:true,subtree:true})}\n})();";
|
|
95
|
+
export {};
|
package/dist/widgets.js
ADDED
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { RenderNode } from './shared.js';
|
|
3
|
+
import { styleClassFor } from './styles.js';
|
|
4
|
+
import { remoteVideoOf } from './video.js';
|
|
5
|
+
const cx = (...c) => c.filter(Boolean).join(' ');
|
|
6
|
+
const isNode = (v) => !!v && typeof v === 'object' && typeof v.type === 'string' && !!v.props;
|
|
7
|
+
/**
|
|
8
|
+
* A slot's content: Puck passes a component (the page and the builder); a renderer that hands over the stored array instead (a
|
|
9
|
+
* style preview, a sample) gets its blocks rendered with the library's own config.
|
|
10
|
+
*/
|
|
11
|
+
function SlotContent({ value, className, getConfig }) {
|
|
12
|
+
if (typeof value === 'function') {
|
|
13
|
+
const Content = value;
|
|
14
|
+
return _jsx(Content, { className: className });
|
|
15
|
+
}
|
|
16
|
+
const nodes = Array.isArray(value) ? value.filter(isNode) : [];
|
|
17
|
+
return (_jsx("div", { className: className, children: nodes.map((n, i) => (_jsx(RenderNode, { node: n, config: getConfig() }, String(n.props.id ?? i)))) }));
|
|
18
|
+
}
|
|
19
|
+
/** Text from a prop that is a string on the page and an inline editor (a React element) on the builder's canvas. */
|
|
20
|
+
const textOf = (v) => (typeof v === 'string' ? v : '');
|
|
21
|
+
/** "Visiting campus" → "visiting-campus": a link name for an id and a URL hash. */
|
|
22
|
+
export function slugify(text) {
|
|
23
|
+
return text
|
|
24
|
+
.normalize('NFKD')
|
|
25
|
+
.replace(/[̀-ͯ]/g, '')
|
|
26
|
+
.toLowerCase()
|
|
27
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
28
|
+
.replace(/^-+|-+$/g, '')
|
|
29
|
+
.slice(0, 60)
|
|
30
|
+
.replace(/-+$/, '');
|
|
31
|
+
}
|
|
32
|
+
/** A short, stable key for the ids inside one block: from Puck's block id, else a hash of what the block holds. */
|
|
33
|
+
function blockKey(prefix, id, seed) {
|
|
34
|
+
const clean = typeof id === 'string' ? id.replace(/[^A-Za-z0-9_-]/g, '').slice(-16) : '';
|
|
35
|
+
if (clean)
|
|
36
|
+
return `sw-${prefix}-${clean}`;
|
|
37
|
+
let h = 5381;
|
|
38
|
+
for (let i = 0; i < seed.length; i++)
|
|
39
|
+
h = ((h << 5) + h + seed.charCodeAt(i)) | 0;
|
|
40
|
+
return `sw-${prefix}-${(h >>> 0).toString(36)}`;
|
|
41
|
+
}
|
|
42
|
+
/** Link names for a list of titles: the given one or the title as a slug, made unique within the block. */
|
|
43
|
+
function linkNames(items, key) {
|
|
44
|
+
const seen = new Set();
|
|
45
|
+
return items.map((it, i) => {
|
|
46
|
+
let base = slugify(textOf(it.anchor)) || slugify(it.title) || `${key}-${i + 1}`;
|
|
47
|
+
if (/^\d/.test(base))
|
|
48
|
+
base = `n-${base}`;
|
|
49
|
+
let name = base;
|
|
50
|
+
for (let n = 2; seen.has(name); n++)
|
|
51
|
+
name = `${base}-${n}`;
|
|
52
|
+
seen.add(name);
|
|
53
|
+
return name;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const levelOf = (v) => (v === 'h2' || v === 'h4' ? v : 'h3');
|
|
57
|
+
const headingLevelField = {
|
|
58
|
+
type: 'radio',
|
|
59
|
+
label: 'Heading level',
|
|
60
|
+
options: [
|
|
61
|
+
{ label: 'H2', value: 'h2' },
|
|
62
|
+
{ label: 'H3', value: 'h3' },
|
|
63
|
+
{ label: 'H4', value: 'h4' },
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
export function accordionComponent(getConfig) {
|
|
67
|
+
return {
|
|
68
|
+
label: 'Accordion',
|
|
69
|
+
fields: {
|
|
70
|
+
title: { type: 'text', label: 'Title (an H2 above the items, optional)', contentEditable: true },
|
|
71
|
+
items: {
|
|
72
|
+
type: 'array',
|
|
73
|
+
label: 'Items',
|
|
74
|
+
min: 1,
|
|
75
|
+
max: 30,
|
|
76
|
+
getItemSummary: (item, i) => textOf(item?.title) || `Item ${(i ?? 0) + 1}`,
|
|
77
|
+
arrayFields: {
|
|
78
|
+
title: { type: 'text', label: 'Title', contentEditable: true },
|
|
79
|
+
anchor: { type: 'text', label: 'Link name (optional)', placeholder: 'visiting-campus' },
|
|
80
|
+
content: { type: 'slot', label: 'Content' },
|
|
81
|
+
},
|
|
82
|
+
defaultItemProps: { title: 'A heading people scan for', anchor: '', content: [] },
|
|
83
|
+
},
|
|
84
|
+
headingLevel: headingLevelField,
|
|
85
|
+
open: { type: 'radio', label: 'Open', options: [{ label: 'Several at a time', value: 'multiple' }, { label: 'One at a time', value: 'single' }] },
|
|
86
|
+
openFirst: { type: 'radio', label: 'First item', options: [{ label: 'Closed', value: false }, { label: 'Open', value: true }] },
|
|
87
|
+
faq: { type: 'radio', label: 'Mark as FAQ (show answers in search results)', options: [{ label: 'No', value: false }, { label: 'Yes', value: true }] },
|
|
88
|
+
width: { type: 'radio', label: 'Width', options: [{ label: 'Narrow', value: 'narrow' }, { label: 'Normal', value: 'normal' }] },
|
|
89
|
+
},
|
|
90
|
+
defaultProps: {
|
|
91
|
+
title: '',
|
|
92
|
+
items: [
|
|
93
|
+
{ title: 'Before you visit', anchor: '', content: [] },
|
|
94
|
+
{ title: 'Getting here', anchor: '', content: [] },
|
|
95
|
+
{ title: 'Accessibility', anchor: '', content: [] },
|
|
96
|
+
],
|
|
97
|
+
headingLevel: 'h3',
|
|
98
|
+
open: 'multiple',
|
|
99
|
+
openFirst: false,
|
|
100
|
+
faq: false,
|
|
101
|
+
width: 'normal',
|
|
102
|
+
},
|
|
103
|
+
render: (props) => {
|
|
104
|
+
const { id, title, items, headingLevel, open, openFirst, width, style, puck } = props;
|
|
105
|
+
const editing = Boolean(puck?.isEditing);
|
|
106
|
+
const H = levelOf(headingLevel);
|
|
107
|
+
const list = (items ?? []).filter((it) => editing || typeof it.title !== 'string' || it.title.trim());
|
|
108
|
+
const key = blockKey('accordion', id, list.map((it) => textOf(it.title)).join('|'));
|
|
109
|
+
const names = linkNames(list.map((it) => ({ anchor: it.anchor, title: textOf(it.title) })), key);
|
|
110
|
+
return (_jsx("section", { className: cx('sw-block', 'sw-accordion', editing && 'sw-accordion--editing', styleClassFor('Accordion', style)), "data-sw-accordion": editing ? undefined : open === 'single' ? 'single' : 'multiple', children: _jsxs("div", { className: cx('sw-container', width === 'narrow' && 'sw-container--narrow'), children: [title ? _jsx("h2", { className: "sw-accordion__title", children: title }) : null, _jsx("div", { className: "sw-accordion__list", children: list.map((it, i) => (_jsxs("div", { className: "sw-accordion__item", id: names[i], "data-open": openFirst && i === 0 ? '' : undefined, children: [_jsx(H, { className: "sw-accordion__heading", children: _jsx("span", { className: "sw-accordion__label", children: it.title }) }), _jsx("div", { className: "sw-accordion__panel", id: `${key}-panel-${i + 1}`, children: _jsx(SlotContent, { value: it.content, className: "sw-accordion__body sw-slot-body", getConfig: getConfig }) })] }, i))) })] }) }));
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
export function tabsComponent(getConfig) {
|
|
115
|
+
return {
|
|
116
|
+
label: 'Tabs',
|
|
117
|
+
fields: {
|
|
118
|
+
title: { type: 'text', label: 'Title (an H2 above the tabs that also names them, optional)', contentEditable: true },
|
|
119
|
+
tabs: {
|
|
120
|
+
type: 'array',
|
|
121
|
+
label: 'Tabs',
|
|
122
|
+
min: 1,
|
|
123
|
+
max: 12,
|
|
124
|
+
getItemSummary: (item, i) => textOf(item?.label) || `Tab ${(i ?? 0) + 1}`,
|
|
125
|
+
arrayFields: {
|
|
126
|
+
label: { type: 'text', label: 'Label', contentEditable: true },
|
|
127
|
+
anchor: { type: 'text', label: 'Link name (optional)', placeholder: 'admissions' },
|
|
128
|
+
content: { type: 'slot', label: 'Content' },
|
|
129
|
+
},
|
|
130
|
+
defaultItemProps: { label: 'Tab', anchor: '', content: [] },
|
|
131
|
+
},
|
|
132
|
+
orientation: { type: 'radio', label: 'Tabs', options: [{ label: 'Above the panel', value: 'horizontal' }, { label: 'Beside the panel', value: 'vertical' }] },
|
|
133
|
+
headingLevel: headingLevelField,
|
|
134
|
+
},
|
|
135
|
+
defaultProps: {
|
|
136
|
+
title: '',
|
|
137
|
+
tabs: [
|
|
138
|
+
{ label: 'Overview', anchor: '', content: [] },
|
|
139
|
+
{ label: 'Requirements', anchor: '', content: [] },
|
|
140
|
+
{ label: 'Costs', anchor: '', content: [] },
|
|
141
|
+
],
|
|
142
|
+
orientation: 'horizontal',
|
|
143
|
+
headingLevel: 'h3',
|
|
144
|
+
},
|
|
145
|
+
render: (props) => {
|
|
146
|
+
const { id, title, tabs, orientation, headingLevel, style, puck } = props;
|
|
147
|
+
const editing = Boolean(puck?.isEditing);
|
|
148
|
+
const H = levelOf(headingLevel);
|
|
149
|
+
const vertical = orientation === 'vertical';
|
|
150
|
+
const list = (tabs ?? []).filter((t) => editing || typeof t.label !== 'string' || t.label.trim());
|
|
151
|
+
const key = blockKey('tabs', id, list.map((t) => textOf(t.label)).join('|'));
|
|
152
|
+
const names = linkNames(list.map((t) => ({ anchor: t.anchor, title: textOf(t.label) })), key);
|
|
153
|
+
return (_jsx("section", { className: cx('sw-block', 'sw-tabs', vertical ? 'sw-tabs--vertical' : 'sw-tabs--horizontal', editing && 'sw-tabs--editing', styleClassFor('Tabs', style)), "data-sw-tabs": editing ? undefined : vertical ? 'vertical' : 'horizontal', children: _jsxs("div", { className: "sw-container", children: [title ? (_jsx("h2", { className: "sw-tabs__title", id: `${key}-title`, children: title })) : null, _jsxs("div", { className: "sw-tabs__layout", children: [_jsx("ul", { className: "sw-tabs__list", "aria-labelledby": title ? `${key}-title` : undefined, children: list.map((t, i) => (_jsx("li", { className: "sw-tabs__item", children: _jsx("a", { className: "sw-tabs__tab", id: `${key}-tab-${i + 1}`, href: `#${names[i]}`, children: t.label }) }, i))) }), _jsx("div", { className: "sw-tabs__panels", children: list.map((t, i) => (_jsxs("div", { className: "sw-tabs__panel", id: names[i], children: [_jsx(H, { className: "sw-tabs__heading", children: t.label }), _jsx(SlotContent, { value: t.content, className: "sw-tabs__body sw-slot-body", getConfig: getConfig })] }, i))) })] })] }) }));
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const VARIANTS = ['hero', 'cards', 'testimonial', 'stats'];
|
|
158
|
+
const Arrow = ({ dir }) => (_jsx("svg", { className: "sw-carousel__icon", viewBox: "0 0 24 24", width: "20", height: "20", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: dir === 'prev' ? 'M15 5l-7 7 7 7' : 'M9 5l7 7-7 7', fill: "none", stroke: "currentColor", strokeWidth: "2.25", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
159
|
+
export function carouselComponent(getConfig) {
|
|
160
|
+
return {
|
|
161
|
+
label: 'Carousel',
|
|
162
|
+
fields: {
|
|
163
|
+
title: { type: 'text', label: 'Title (names the carousel for screen readers)', contentEditable: true },
|
|
164
|
+
showTitle: { type: 'radio', label: 'Title', options: [{ label: 'Show above the slides', value: true }, { label: 'Screen readers only', value: false }] },
|
|
165
|
+
variant: {
|
|
166
|
+
type: 'select',
|
|
167
|
+
label: 'Variant',
|
|
168
|
+
options: [
|
|
169
|
+
{ label: 'Hero (full width, one slide at a time)', value: 'hero' },
|
|
170
|
+
{ label: 'Cards (several visible)', value: 'cards' },
|
|
171
|
+
{ label: 'Testimonial (thumbnails to switch)', value: 'testimonial' },
|
|
172
|
+
{ label: 'Stats (big numbers)', value: 'stats' },
|
|
173
|
+
],
|
|
174
|
+
},
|
|
175
|
+
slides: {
|
|
176
|
+
type: 'array',
|
|
177
|
+
label: 'Slides',
|
|
178
|
+
min: 1,
|
|
179
|
+
max: 20,
|
|
180
|
+
getItemSummary: (item, i) => textOf(item?.label) || `Slide ${(i ?? 0) + 1}`,
|
|
181
|
+
arrayFields: {
|
|
182
|
+
label: { type: 'text', label: 'Name' },
|
|
183
|
+
thumbnail: { type: 'text', label: 'Thumbnail image URL (testimonial)', placeholder: '/media/...' },
|
|
184
|
+
content: { type: 'slot', label: 'Content' },
|
|
185
|
+
},
|
|
186
|
+
defaultItemProps: { label: '', thumbnail: '', content: [] },
|
|
187
|
+
},
|
|
188
|
+
height: { type: 'radio', label: 'Height (hero)', options: [{ label: 'Fit the content', value: 'auto' }, { label: 'Full screen', value: 'screen' }] },
|
|
189
|
+
perView: { type: 'radio', label: 'Slides visible (cards and stats)', options: [{ label: '2', value: 2 }, { label: '3', value: 3 }, { label: '4', value: 4 }] },
|
|
190
|
+
autoplay: { type: 'radio', label: 'Autoplay (with a pause button; only when the brand’s motion is on)', options: [{ label: 'Off', value: false }, { label: 'On', value: true }] },
|
|
191
|
+
interval: { type: 'radio', label: 'Seconds per slide', options: [{ label: '5', value: 5 }, { label: '7', value: 7 }, { label: '10', value: 10 }] },
|
|
192
|
+
loop: { type: 'radio', label: 'After the last slide', options: [{ label: 'Stop', value: false }, { label: 'Back to the first', value: true }] },
|
|
193
|
+
},
|
|
194
|
+
defaultProps: {
|
|
195
|
+
title: 'Featured',
|
|
196
|
+
showTitle: true,
|
|
197
|
+
variant: 'cards',
|
|
198
|
+
slides: [
|
|
199
|
+
{ label: 'First slide', thumbnail: '', content: [] },
|
|
200
|
+
{ label: 'Second slide', thumbnail: '', content: [] },
|
|
201
|
+
{ label: 'Third slide', thumbnail: '', content: [] },
|
|
202
|
+
{ label: 'Fourth slide', thumbnail: '', content: [] },
|
|
203
|
+
],
|
|
204
|
+
height: 'auto',
|
|
205
|
+
perView: 3,
|
|
206
|
+
autoplay: false,
|
|
207
|
+
interval: 7,
|
|
208
|
+
loop: false,
|
|
209
|
+
},
|
|
210
|
+
render: (props) => {
|
|
211
|
+
const { id, title, showTitle, variant: v, slides, height, perView, autoplay, interval, loop, style, puck } = props;
|
|
212
|
+
const editing = Boolean(puck?.isEditing);
|
|
213
|
+
const variant = VARIANTS.includes(v) ? v : 'cards';
|
|
214
|
+
const list = slides ?? [];
|
|
215
|
+
const n = list.length;
|
|
216
|
+
const key = blockKey('carousel', id, `${textOf(title)}|${list.map((s) => textOf(s.label)).join('|')}`);
|
|
217
|
+
const name = textOf(title).trim() || 'Carousel';
|
|
218
|
+
const per = perView === 2 || perView === 4 ? perView : 3;
|
|
219
|
+
const several = variant === 'cards' || variant === 'stats';
|
|
220
|
+
const full = variant === 'hero' && height === 'screen';
|
|
221
|
+
const seconds = interval === 5 || interval === 10 ? interval : 7;
|
|
222
|
+
const titleEl = title && showTitle !== false ? (_jsx("h2", { className: "sw-carousel__title", id: `${key}-title`, children: title })) : null;
|
|
223
|
+
const bodyClass = cx('sw-carousel__body', variant !== 'hero' && 'sw-slot-body');
|
|
224
|
+
const classes = cx('sw-block', 'sw-carousel', `sw-carousel--${variant}`, several && `sw-carousel--per-${per}`, full && 'sw-carousel--full', styleClassFor('Carousel', style));
|
|
225
|
+
if (editing) {
|
|
226
|
+
// The page builder: every slide open, one under the other, so each slot takes blocks.
|
|
227
|
+
return (_jsxs("section", { className: cx(classes, 'sw-carousel--editing'), children: [_jsx("div", { className: "sw-container", children: titleEl }), list.map((s, i) => (_jsxs("div", { className: "sw-carousel__edit-slide", children: [_jsxs("p", { className: "sw-carousel__edit-label sw-container", children: ["Slide ", i + 1, " of ", n, textOf(s.label) ? `: ${textOf(s.label)}` : ''] }), _jsx("div", { className: variant === 'hero' ? undefined : 'sw-container', children: _jsx(SlotContent, { value: s.content, className: bodyClass, getConfig: getConfig }) })] }, i)))] }));
|
|
228
|
+
}
|
|
229
|
+
const controls = n > 1 ? (_jsxs("div", { className: "sw-carousel__controls", "data-sw-carousel-controls": "", hidden: true, children: [autoplay ? (_jsx("button", { type: "button", className: "sw-carousel__button sw-carousel__pause", "data-sw-carousel-pause": "", hidden: true, children: "Pause slides" })) : null, _jsxs("button", { type: "button", className: "sw-carousel__button sw-carousel__prev", "data-sw-carousel-prev": "", "aria-controls": `${key}-slides`, children: [_jsx(Arrow, { dir: "prev" }), _jsx("span", { className: "sw-visually-hidden", children: "Previous slide" })] }), _jsxs("button", { type: "button", className: "sw-carousel__button sw-carousel__next", "data-sw-carousel-next": "", "aria-controls": `${key}-slides`, children: [_jsx(Arrow, { dir: "next" }), _jsx("span", { className: "sw-visually-hidden", children: "Next slide" })] })] })) : null;
|
|
230
|
+
const picker = n > 1 && !several ? (_jsx("div", { className: cx('sw-carousel__picker', variant === 'testimonial' && 'sw-carousel__picker--thumbs'), "data-sw-carousel-picker": "", role: "group", "aria-label": "Choose a slide", hidden: true, children: list.map((s, i) => {
|
|
231
|
+
const label = textOf(s.label).trim() ? `Slide ${i + 1}: ${textOf(s.label).trim()}` : `Slide ${i + 1}`;
|
|
232
|
+
return (_jsxs("button", { type: "button", className: "sw-carousel__pick", "data-sw-carousel-pick": "", "aria-controls": `${key}-slide-${i + 1}`, "aria-label": label, children: [variant === 'testimonial' && s.thumbnail ? _jsx("img", { className: "sw-carousel__thumb", src: s.thumbnail, alt: "", width: 48, height: 48, loading: "lazy" }) : null, variant === 'testimonial' && !s.thumbnail ? _jsx("span", { className: "sw-carousel__initial", "aria-hidden": "true", children: (textOf(s.label).trim()[0] ?? String(i + 1)).toUpperCase() }) : null] }, i));
|
|
233
|
+
}) })) : null;
|
|
234
|
+
return (_jsxs("section", { className: classes, "aria-roledescription": "carousel", "aria-labelledby": titleEl ? `${key}-title` : undefined, "aria-label": titleEl ? undefined : name, "data-sw-carousel": variant, "data-autoplay": autoplay && n > 1 ? String(seconds) : undefined, "data-loop": loop ? '' : undefined, children: [_jsxs("div", { className: cx('sw-carousel__head', 'sw-container', !titleEl && !controls && 'sw-carousel__head--empty'), children: [titleEl, controls] }), _jsx("div", { className: variant === 'hero' ? 'sw-carousel__frame' : 'sw-container sw-carousel__frame', children: _jsx("div", { className: "sw-carousel__track", id: `${key}-slides`, role: "group", "aria-label": "Slides", tabIndex: 0, "aria-live": "polite", children: list.map((s, i) => (_jsx("div", { className: "sw-carousel__slide", id: `${key}-slide-${i + 1}`, role: "group", "aria-roledescription": "slide", "aria-label": `${i + 1} of ${n}`, children: _jsx(SlotContent, { value: s.content, className: bodyClass, getConfig: getConfig }) }, i))) }) }), picker ? _jsx("div", { className: "sw-container sw-carousel__foot", children: picker }) : null] }));
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
// ---------- Styles ----------
|
|
239
|
+
export const WIDGETS_CSS = `
|
|
240
|
+
/* ---------- Carousel, Accordion, Tabs ---------- */
|
|
241
|
+
/* Blocks inside a slide, an item or a tab share its box: no second gutter, one gap between them. */
|
|
242
|
+
.sw-slot-body > .sw-block { padding-block: 0; }
|
|
243
|
+
.sw-slot-body > .sw-block + .sw-block { padding-top: var(--sw-space-2); }
|
|
244
|
+
.sw-slot-body .sw-container { max-width: none; padding-inline: 0; }
|
|
245
|
+
|
|
246
|
+
/* Accordion: without the script every item is open under its heading; with it the heading holds a button. */
|
|
247
|
+
.sw-accordion__title { margin: 0 0 var(--sw-space-3); }
|
|
248
|
+
.sw-accordion__list { display: grid; gap: var(--sw-accordion-gap, 0); border-top: var(--sw-accordion-rule, 1px solid var(--sw-color-border)); }
|
|
249
|
+
.sw-accordion__item { border-bottom: 1px solid var(--sw-color-border); scroll-margin-top: var(--sw-space-3); }
|
|
250
|
+
.sw-page .sw-accordion__heading { margin: 0; font-size: 1.125rem; line-height: 1.35; letter-spacing: 0; }
|
|
251
|
+
.sw-accordion__heading > .sw-accordion__label { display: block; padding: var(--sw-space-2) 0 var(--sw-space-1); }
|
|
252
|
+
.sw-accordion__trigger { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: var(--sw-space-2); min-height: 3rem; padding: var(--sw-space-2) 0; margin: 0; font: inherit; font-weight: 700; color: inherit; text-align: start; background: none; border: 0; border-radius: 2px; cursor: pointer; }
|
|
253
|
+
.sw-accordion__trigger:hover .sw-accordion__label { text-decoration: underline; text-underline-offset: 0.15em; }
|
|
254
|
+
.sw-accordion__icon { position: relative; flex: none; width: 1rem; height: 1rem; color: var(--sw-color-primary, #1d4ed8); }
|
|
255
|
+
.sw-accordion__icon::before, .sw-accordion__icon::after { content: ''; position: absolute; left: 0; top: calc(50% - 1px); width: 100%; height: 2px; border-radius: 1px; background: currentColor; transition: transform 160ms ease; }
|
|
256
|
+
.sw-accordion__icon::after { transform: rotate(90deg); }
|
|
257
|
+
.sw-accordion__trigger[aria-expanded="true"] .sw-accordion__icon::after { transform: rotate(0deg); }
|
|
258
|
+
.sw-accordion__panel { padding: 0 0 var(--sw-space-2); }
|
|
259
|
+
.sw-accordion__panel[hidden] { display: none; }
|
|
260
|
+
.sw-accordion__panel[hidden="until-found"] { display: block; content-visibility: hidden; padding: 0; }
|
|
261
|
+
|
|
262
|
+
/* Tabs: without the script, a list of links to the panels and every panel under its heading. */
|
|
263
|
+
.sw-tabs__title { margin: 0 0 var(--sw-space-3); }
|
|
264
|
+
.sw-tabs__layout { display: grid; gap: var(--sw-space-3); }
|
|
265
|
+
.sw-tabs__list { position: relative; display: flex; gap: var(--sw-space-1); margin: 0; padding: 0; list-style: none; overflow-x: auto; scrollbar-width: thin; border-bottom: var(--sw-tabs-rule, 1px solid var(--sw-color-border)); }
|
|
266
|
+
.sw-tabs__item { flex: none; display: flex; }
|
|
267
|
+
.sw-page .sw-tabs__tab { display: inline-flex; align-items: center; min-height: 2.75rem; padding: 0.5rem 1rem; color: var(--sw-color-muted); font-weight: 600; text-decoration: none; white-space: nowrap; border-radius: var(--sw-radius, 8px) var(--sw-radius, 8px) 0 0; }
|
|
268
|
+
.sw-page .sw-tabs__tab:hover { color: var(--sw-color-text); text-decoration: none; }
|
|
269
|
+
.sw-page .sw-tabs__tab[aria-selected="true"] { color: var(--sw-color-text); box-shadow: inset 0 -3px 0 var(--sw-color-primary, #1d4ed8); }
|
|
270
|
+
/* Inside the ring: the list scrolls, so a ring outside the tab would be cut off. */
|
|
271
|
+
.sw-page .sw-tabs__tab:focus-visible { outline: 2px solid var(--sw-color-primary, #1d4ed8); outline-offset: -4px; }
|
|
272
|
+
.sw-tabs__panel { scroll-margin-top: var(--sw-space-3); }
|
|
273
|
+
.sw-tabs__panel + .sw-tabs__panel { margin-top: var(--sw-space-4); }
|
|
274
|
+
.sw-page .sw-tabs__heading { margin: 0 0 var(--sw-space-2); }
|
|
275
|
+
.sw-tabs--on .sw-tabs__panel + .sw-tabs__panel { margin-top: 0; }
|
|
276
|
+
.sw-tabs--on .sw-tabs__heading { display: none; }
|
|
277
|
+
.sw-tabs__panel[hidden] { display: none; }
|
|
278
|
+
.sw-tabs--on .sw-tabs__panel:focus-visible { outline: none; box-shadow: var(--sw-focus-ring); border-radius: 2px; }
|
|
279
|
+
@media (min-width: 760px) {
|
|
280
|
+
.sw-tabs--vertical .sw-tabs__layout { grid-template-columns: minmax(10rem, 15rem) minmax(0, 1fr); align-items: start; }
|
|
281
|
+
.sw-tabs--vertical .sw-tabs__list { flex-direction: column; overflow: visible; border-bottom: 0; border-inline-end: var(--sw-tabs-rule, 1px solid var(--sw-color-border)); }
|
|
282
|
+
.sw-page .sw-tabs--vertical .sw-tabs__tab { width: 100%; white-space: normal; border-radius: var(--sw-radius, 8px) 0 0 var(--sw-radius, 8px); }
|
|
283
|
+
.sw-page .sw-tabs--vertical .sw-tabs__tab[aria-selected="true"] { box-shadow: inset -3px 0 0 var(--sw-color-primary, #1d4ed8); }
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/* Carousel: without the script a row that scrolls sideways with snapping; with it, controls and one row position at a time. */
|
|
287
|
+
.sw-carousel { --sw-carousel-gap: var(--sw-space-3, 1.5rem); --sw-carousel-n: 1; --sw-carousel-peek: 0px; position: relative; }
|
|
288
|
+
.sw-carousel__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sw-space-2); margin-bottom: var(--sw-space-3); }
|
|
289
|
+
.sw-carousel__head--empty, .sw-carousel--hero .sw-carousel__head:not(:has(.sw-carousel__title)) { margin-bottom: 0; }
|
|
290
|
+
.sw-carousel__title { margin: 0; }
|
|
291
|
+
.sw-carousel__frame { position: relative; }
|
|
292
|
+
.sw-carousel__track { position: relative; display: flex; gap: var(--sw-carousel-gap); overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x mandatory; scrollbar-width: thin; padding: 6px 6px var(--sw-space-1); margin-inline: -6px; scroll-padding-inline: 6px; }
|
|
293
|
+
.sw-carousel--hero .sw-carousel__track { padding: 0; margin-inline: 0; scroll-padding-inline: 0; }
|
|
294
|
+
.sw-carousel__track:focus-visible { outline: none; box-shadow: var(--sw-focus-ring); border-radius: 2px; }
|
|
295
|
+
.sw-carousel__slide { flex: 0 0 calc((100% - (var(--sw-carousel-n) - 1) * var(--sw-carousel-gap) - var(--sw-carousel-peek)) / var(--sw-carousel-n)); min-width: 0; scroll-snap-align: start; }
|
|
296
|
+
.sw-carousel--cards { --sw-carousel-peek: 15%; }
|
|
297
|
+
@media (min-width: 640px) { .sw-carousel--per-2, .sw-carousel--per-3, .sw-carousel--per-4 { --sw-carousel-n: 2; } .sw-carousel--cards { --sw-carousel-peek: 3rem; } }
|
|
298
|
+
@media (min-width: 900px) { .sw-carousel--per-3, .sw-carousel--per-4 { --sw-carousel-n: 3; } }
|
|
299
|
+
@media (min-width: 1100px) { .sw-carousel--per-4 { --sw-carousel-n: 4; } }
|
|
300
|
+
.sw-carousel--hero { --sw-carousel-gap: 0px; }
|
|
301
|
+
.sw-block.sw-carousel--hero { padding-block: 0; }
|
|
302
|
+
.sw-carousel--hero + .sw-block { padding-top: var(--sw-block-pad, 1.5rem); }
|
|
303
|
+
.sw-carousel--hero .sw-carousel__body { display: flex; flex-direction: column; height: 100%; }
|
|
304
|
+
.sw-carousel--hero .sw-carousel__body > * { flex: 1 0 auto; }
|
|
305
|
+
.sw-carousel--full .sw-carousel__slide { min-height: 100svh; }
|
|
306
|
+
.sw-carousel--testimonial .sw-carousel__slide { text-align: center; }
|
|
307
|
+
.sw-carousel--testimonial .sw-carousel__body { max-width: 46rem; margin-inline: auto; font-size: 1.125rem; }
|
|
308
|
+
.sw-carousel--stats .sw-carousel__slide { text-align: center; }
|
|
309
|
+
.sw-page .sw-carousel--stats .sw-carousel__body > .sw-block:first-child :is(h2, h3, h4) { font-size: clamp(2.25rem, 1.6rem + 3vw, 3.5rem); color: var(--sw-color-primary, #1d4ed8); font-variant-numeric: tabular-nums; }
|
|
310
|
+
.sw-carousel__slide-frame { height: 100%; }
|
|
311
|
+
/* With the script: no scroll bar (the controls move the row), the controls and the picker appear. */
|
|
312
|
+
.sw-carousel--on .sw-carousel__track { scrollbar-width: none; }
|
|
313
|
+
.sw-carousel--on:not(.sw-carousel--hero) .sw-carousel__track { padding-bottom: 6px; }
|
|
314
|
+
.sw-carousel--on .sw-carousel__track::-webkit-scrollbar { display: none; }
|
|
315
|
+
.sw-carousel__controls { display: flex; align-items: center; gap: var(--sw-space-1); margin-inline-start: auto; }
|
|
316
|
+
.sw-carousel__controls[hidden], .sw-carousel__picker[hidden], .sw-carousel__button[hidden] { display: none; }
|
|
317
|
+
.sw-carousel__button { display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem; min-width: 2.75rem; min-height: 2.75rem; padding: 0 0.75rem; font: inherit; font-size: 0.875rem; font-weight: 600; line-height: 1; color: var(--sw-carousel-ink, var(--sw-color-primary-contrast, #ffffff)); background: var(--sw-carousel-fill, var(--sw-color-primary, #1d4ed8)); border: 2px solid var(--sw-carousel-edge, var(--sw-color-primary, #1d4ed8)); border-radius: 999px; cursor: pointer; }
|
|
318
|
+
.sw-carousel__prev, .sw-carousel__next { padding: 0; }
|
|
319
|
+
.sw-carousel__button[aria-disabled="true"] { opacity: 0.45; cursor: default; }
|
|
320
|
+
.sw-carousel__foot { display: flex; justify-content: center; margin-top: var(--sw-space-2); }
|
|
321
|
+
.sw-carousel__picker { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.25rem; }
|
|
322
|
+
.sw-carousel__pick { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 1.75rem; height: 1.75rem; padding: 0; background: none; border: 0; border-radius: 999px; cursor: pointer; color: var(--sw-color-primary, #1d4ed8); }
|
|
323
|
+
.sw-carousel__pick::before { content: ''; width: 0.7rem; height: 0.7rem; border-radius: 999px; border: 2px solid currentColor; background: transparent; }
|
|
324
|
+
.sw-carousel__pick[aria-current="true"]::before { background: currentColor; }
|
|
325
|
+
.sw-carousel__picker--thumbs { gap: var(--sw-space-1); }
|
|
326
|
+
.sw-carousel__picker--thumbs .sw-carousel__pick { width: 3.25rem; height: 3.25rem; border: 2px solid transparent; }
|
|
327
|
+
.sw-carousel__picker--thumbs .sw-carousel__pick::before { content: none; }
|
|
328
|
+
.sw-carousel__picker--thumbs .sw-carousel__pick[aria-current="true"] { border-color: currentColor; }
|
|
329
|
+
.sw-carousel__thumb { width: 2.75rem; height: 2.75rem; border-radius: 999px; object-fit: cover; }
|
|
330
|
+
.sw-carousel__initial { display: inline-flex; align-items: center; justify-content: center; width: 2.75rem; height: 2.75rem; border-radius: 999px; background: var(--sw-color-surface); color: var(--sw-color-text); font-weight: 700; }
|
|
331
|
+
/* Hero: the controls and the picker sit over the slide. */
|
|
332
|
+
.sw-carousel--hero .sw-carousel__head { position: absolute; inset-inline: 0; bottom: var(--sw-space-3); z-index: 2; margin: 0; pointer-events: none; }
|
|
333
|
+
.sw-carousel--hero .sw-carousel__head > * { pointer-events: auto; }
|
|
334
|
+
.sw-carousel--hero .sw-carousel__head:has(.sw-carousel__title) { position: static; margin-block: var(--sw-block-pad, 1.5rem) var(--sw-space-3); pointer-events: auto; }
|
|
335
|
+
.sw-carousel--hero .sw-carousel__foot { position: absolute; inset-inline: 0; bottom: var(--sw-space-3); z-index: 1; justify-content: flex-start; margin: 0; pointer-events: none; }
|
|
336
|
+
.sw-carousel--hero .sw-carousel__picker { pointer-events: auto; padding: 0.15rem 0.35rem; border-radius: 999px; background: rgba(0, 0, 0, 0.55); color: #ffffff; }
|
|
337
|
+
.sw-carousel--hero .sw-carousel__pick { color: #ffffff; }
|
|
338
|
+
.sw-carousel--hero .sw-carousel__pick:focus-visible { box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px #111827; }
|
|
339
|
+
/* The page builder: slides one under the other, each named. */
|
|
340
|
+
.sw-carousel--editing .sw-carousel__edit-slide + .sw-carousel__edit-slide { margin-top: var(--sw-space-3); }
|
|
341
|
+
.sw-page .sw-carousel__edit-label { margin: 0 auto var(--sw-space-1); font-size: 0.8125rem; font-weight: 600; letter-spacing: 0.02em; color: var(--sw-color-muted); }
|
|
342
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
343
|
+
html:not(.sw-reduce-motion) .sw-carousel__track { scroll-behavior: smooth; }
|
|
344
|
+
}
|
|
345
|
+
`;
|
|
346
|
+
// ---------- Script ----------
|
|
347
|
+
/** Blocks that need WIDGETS_SCRIPT: the page renderer adds it once when the layout has one of them. */
|
|
348
|
+
export const WIDGET_BLOCKS = ['Carousel', 'Accordion', 'Tabs'];
|
|
349
|
+
/** Whether a block needs WIDGETS_SCRIPT: a Carousel, Accordion or Tabs, or a Video playing a YouTube or Vimeo video (its facade). */
|
|
350
|
+
export function needsWidgetsScript(type, props) {
|
|
351
|
+
if (WIDGET_BLOCKS.includes(type))
|
|
352
|
+
return true;
|
|
353
|
+
return type === 'Video' && remoteVideoOf(props?.src) !== null;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* The page script that enhances every Carousel, Accordion and Tabs block on the page (inline with the page's nonce, once per
|
|
357
|
+
* page). It runs once per document, picks up blocks added later (a Personalize island) and follows the visitor's Reduce motion
|
|
358
|
+
* choice (`sw-reduce-motion` on the root, or the stored choice, or the device's setting): autoplay never runs under it and slide
|
|
359
|
+
* changes jump instead of scrolling smoothly. Autoplay also needs the brand's motion on (`data-sw-motion` on the root).
|
|
360
|
+
*
|
|
361
|
+
* It also plays YouTube and Vimeo videos (the Video block's facade, `data-sw-video`): pressing the facade puts the player in a
|
|
362
|
+
* sandboxed frame in its place, or in the lightbox when it opens (and takes it out when it closes, which stops the video). Nothing
|
|
363
|
+
* is requested from YouTube or Vimeo before that. The consent note goes away once the visitor has allowed marketing and embedded
|
|
364
|
+
* content (the consent banner's cookie, never with Global Privacy Control).
|
|
365
|
+
*/
|
|
366
|
+
export const WIDGETS_SCRIPT = `(function(){var d=document,h=d.documentElement;if(h.hasAttribute('data-sw-widgets'))return;h.setAttribute('data-sw-widgets','');
|
|
367
|
+
var K='sw-reduce-motion',mq=window.matchMedia?matchMedia('(prefers-reduced-motion: reduce)'):null,found=!!(d.body&&'onbeforematch' in d.body),watchers=[];
|
|
368
|
+
function stored(){try{return localStorage.getItem(K)}catch(e){return null}}
|
|
369
|
+
function reduced(){if(h.classList.contains('sw-reduce-motion'))return true;if(h.classList.contains('sw-motion-allowed'))return false;var s=stored();return s===null?!!(mq&&mq.matches):s==='1'}
|
|
370
|
+
function own(root,sel,attr){return [].slice.call(root.querySelectorAll(sel)).filter(function(el){return el.closest('['+attr+']')===root})}
|
|
371
|
+
function keyboardFocus(el){try{return el.matches(':focus-visible')}catch(e){return true}}
|
|
372
|
+
function setItem(it,open){it._swb.setAttribute('aria-expanded',open?'true':'false');it.classList.toggle('sw-accordion__item--open',open);if(open)it._swp.removeAttribute('hidden');else if(found)it._swp.setAttribute('hidden','until-found');else it._swp.hidden=true}
|
|
373
|
+
function accordion(root){if(root._sw)return;root._sw=1;var single=root.getAttribute('data-sw-accordion')==='single',items=own(root,'.sw-accordion__item','data-sw-accordion'),btns=[];
|
|
374
|
+
function only(it){if(single)items.forEach(function(o){if(o!==it&&o._swb)setItem(o,false)})}
|
|
375
|
+
items.forEach(function(it){var hd=it.querySelector('.sw-accordion__heading'),pn=it.querySelector('.sw-accordion__panel');if(!hd||!pn||hd.closest('.sw-accordion__item')!==it)return;
|
|
376
|
+
var b=d.createElement('button');b.type='button';b.className='sw-accordion__trigger';b.id=pn.id+'-button';b.setAttribute('aria-controls',pn.id);while(hd.firstChild)b.appendChild(hd.firstChild);
|
|
377
|
+
var ic=d.createElement('span');ic.className='sw-accordion__icon';ic.setAttribute('aria-hidden','true');b.appendChild(ic);hd.appendChild(b);pn.setAttribute('aria-labelledby',b.id);
|
|
378
|
+
it._swb=b;it._swp=pn;btns.push(b);it._swOpen=function(){only(it);setItem(it,true)};
|
|
379
|
+
b.addEventListener('click',function(){var open=b.getAttribute('aria-expanded')!=='true';if(open)only(it);setItem(it,open)});
|
|
380
|
+
pn.addEventListener('beforematch',function(){only(it);setItem(it,true)})});
|
|
381
|
+
var first=true;items.forEach(function(it){if(!it._swb)return;var open=it.hasAttribute('data-open')&&(!single||first);if(open)first=false;setItem(it,open)});
|
|
382
|
+
root.addEventListener('keydown',function(e){var i=btns.indexOf(e.target);if(i<0)return;var k=e.key,n=k==='ArrowDown'?i+1:k==='ArrowUp'?i-1:k==='Home'?0:k==='End'?btns.length-1:null;if(n===null)return;e.preventDefault();btns[(n+btns.length)%btns.length].focus()});
|
|
383
|
+
root.classList.add('sw-accordion--on')}
|
|
384
|
+
function tabs(root){if(root._sw)return;root._sw=1;var list=own(root,'.sw-tabs__list','data-sw-tabs')[0],ts=own(root,'.sw-tabs__tab','data-sw-tabs'),ps=own(root,'.sw-tabs__panel','data-sw-tabs');if(!list||!ts.length||ts.length!==ps.length)return;
|
|
385
|
+
var vertical=root.getAttribute('data-sw-tabs')==='vertical',cur=-1;list.setAttribute('role','tablist');if(vertical)list.setAttribute('aria-orientation','vertical');
|
|
386
|
+
[].slice.call(list.children).forEach(function(li){li.setAttribute('role','presentation')});
|
|
387
|
+
function reveal(t){if(list.scrollWidth<=list.clientWidth+1)return;var a=t.offsetLeft,b=a+t.offsetWidth;if(a<list.scrollLeft)list.scrollLeft=Math.max(0,a-8);else if(b>list.scrollLeft+list.clientWidth)list.scrollLeft=b-list.clientWidth+8}
|
|
388
|
+
function select(i,url){cur=i;ts.forEach(function(t,k){var on=k===i;t.setAttribute('aria-selected',on?'true':'false');t.tabIndex=on?0:-1;ps[k].hidden=!on});reveal(ts[i]);if(url&&history.replaceState)try{history.replaceState(history.state,'','#'+ps[i].id)}catch(e){}}
|
|
389
|
+
ts.forEach(function(t,i){var p=ps[i];t.setAttribute('role','tab');t.setAttribute('aria-controls',p.id);p.setAttribute('role','tabpanel');p.setAttribute('aria-labelledby',t.id);p.tabIndex=0;p._swSelect=function(){select(i,false)};
|
|
390
|
+
t.addEventListener('click',function(e){e.preventDefault();select(i,true)})});
|
|
391
|
+
list.addEventListener('keydown',function(e){var i=ts.indexOf(e.target);if(i<0)return;var k=e.key,n=null;if(k==='ArrowRight'||(vertical&&k==='ArrowDown'))n=i+1;else if(k==='ArrowLeft'||(vertical&&k==='ArrowUp'))n=i-1;else if(k==='Home')n=0;else if(k==='End')n=ts.length-1;
|
|
392
|
+
if(n===null)return;e.preventDefault();n=(n+ts.length)%ts.length;select(n,true);ts[n].focus()});
|
|
393
|
+
select(0,false);root.classList.add('sw-tabs--on')}
|
|
394
|
+
function carousel(root){if(root._sw)return;root._sw=1;var A='data-sw-carousel',track=own(root,'.sw-carousel__track',A)[0];if(!track)return;
|
|
395
|
+
var slides=own(root,'.sw-carousel__slide',A),n=slides.length;if(n<2)return;
|
|
396
|
+
var prev=own(root,'[data-sw-carousel-prev]',A)[0],next=own(root,'[data-sw-carousel-next]',A)[0],pause=own(root,'[data-sw-carousel-pause]',A)[0],picks=own(root,'[data-sw-carousel-pick]',A);
|
|
397
|
+
var loop=root.hasAttribute('data-loop'),auto=+root.getAttribute('data-autoplay')||0,cur=0,timer=0,stopped=false,hover=false,seen=true,st=0,rtl=getComputedStyle(track).direction==='rtl';
|
|
398
|
+
own(root,'[data-sw-carousel-controls],[data-sw-carousel-picker]',A).forEach(function(c){c.hidden=false});root.classList.add('sw-carousel--on');
|
|
399
|
+
function pos(i){return Math.abs(slides[i].offsetLeft-slides[0].offsetLeft)}
|
|
400
|
+
function max(){return Math.max(0,track.scrollWidth-track.clientWidth)}
|
|
401
|
+
function at(){return Math.abs(track.scrollLeft)}
|
|
402
|
+
function nearest(){var x=at(),m=max(),best=0,bd=1/0;for(var i=0;i<n;i++){var dd=Math.abs(Math.min(pos(i),m)-x);if(dd<bd-1){bd=dd;best=i}}return best}
|
|
403
|
+
function shown(i){var x=at(),p=pos(i);return p>=x-2&&p+slides[i].offsetWidth<=x+track.clientWidth+2}
|
|
404
|
+
function sync(){cur=nearest();var lost=false;slides.forEach(function(s,i){var v=shown(i)||i===cur;if(!v&&s.contains(d.activeElement))lost=true;if(v){s.removeAttribute('inert');s.removeAttribute('aria-hidden')}else{s.setAttribute('inert','');s.setAttribute('aria-hidden','true')}});
|
|
405
|
+
if(lost)track.focus({preventScroll:true});
|
|
406
|
+
picks.forEach(function(b,i){if(i===cur)b.setAttribute('aria-current','true');else b.removeAttribute('aria-current');b.tabIndex=i===cur?0:-1});
|
|
407
|
+
if(prev)prev.setAttribute('aria-disabled',!loop&&at()<=2?'true':'false');if(next)next.setAttribute('aria-disabled',!loop&&at()>=max()-2?'true':'false')}
|
|
408
|
+
function go(i){i=loop?(i+n)%n:Math.max(0,Math.min(n-1,i));var left=Math.min(pos(i),max());if(Math.abs(left-at())<1){sync();return}track.scrollTo({left:rtl?-left:left,behavior:reduced()?'auto':'smooth'})}
|
|
409
|
+
function step(dir){if(dir>0){if(at()>=max()-2){if(loop)go(0);return}go(cur+1)}else{if(at()<=2){if(loop)go(n-1);return}go(cur-1)}}
|
|
410
|
+
function allowed(){return auto>0&&h.hasAttribute('data-sw-motion')&&!reduced()}
|
|
411
|
+
function schedule(){clearTimeout(timer);timer=0;var on=allowed();if(pause){pause.hidden=!on;pause.textContent=stopped?'Play slides':'Pause slides'}track.setAttribute('aria-live',on&&!stopped?'off':'polite');
|
|
412
|
+
if(on&&!stopped&&!hover&&seen&&!d.hidden)timer=setTimeout(function(){timer=0;if(at()>=max()-2)go(0);else step(1);schedule()},auto*1000)}
|
|
413
|
+
function keyStep(e){var k=e.key;if(k==='ArrowRight')return rtl?-1:1;if(k==='ArrowLeft')return rtl?1:-1;if(k==='Home')return 'first';if(k==='End')return 'last';return 0}
|
|
414
|
+
track.addEventListener('scroll',function(){clearTimeout(st);st=setTimeout(sync,90)},{passive:true});
|
|
415
|
+
track.addEventListener('keydown',function(e){if(e.target!==track)return;var s=keyStep(e);if(!s)return;e.preventDefault();if(s==='first')go(0);else if(s==='last')go(n-1);else step(s)});
|
|
416
|
+
picks.forEach(function(b,i){b.addEventListener('click',function(){go(i);schedule()});b.addEventListener('keydown',function(e){var s=keyStep(e);if(!s)return;e.preventDefault();var j=s==='first'?0:s==='last'?picks.length-1:(i+s+picks.length)%picks.length;go(j);picks[j].tabIndex=0;picks[j].focus()})});
|
|
417
|
+
if(prev)prev.addEventListener('click',function(){if(prev.getAttribute('aria-disabled')!=='true')step(-1);schedule()});
|
|
418
|
+
if(next)next.addEventListener('click',function(){if(next.getAttribute('aria-disabled')!=='true')step(1);schedule()});
|
|
419
|
+
if(pause)pause.addEventListener('click',function(){stopped=!stopped;schedule()});
|
|
420
|
+
root.addEventListener('focusin',function(e){if(!stopped&&allowed()&&keyboardFocus(e.target)){stopped=true;schedule()}});
|
|
421
|
+
root.addEventListener('pointerdown',function(e){if(e.pointerType==='touch'&&allowed()&&!stopped){stopped=true;schedule()}});
|
|
422
|
+
root.addEventListener('mouseenter',function(){hover=true;schedule()});root.addEventListener('mouseleave',function(){hover=false;schedule()});
|
|
423
|
+
if('IntersectionObserver' in window)new IntersectionObserver(function(es){seen=es[es.length-1].isIntersecting;schedule()}).observe(root);
|
|
424
|
+
d.addEventListener('visibilitychange',schedule);window.addEventListener('resize',function(){clearTimeout(st);st=setTimeout(sync,120)});
|
|
425
|
+
watchers.push(schedule);root._swGo=go;sync();schedule()}
|
|
426
|
+
function consented(){if(navigator.globalPrivacyControl===true)return false;return /(?:^|; )sw_consent=(?:1|a[01]m1)(?:;|$)/.test(d.cookie)}
|
|
427
|
+
function notes(box,hide){[].forEach.call(box.querySelectorAll('[data-sw-video-consent]'),function(n){n.hidden=hide})}
|
|
428
|
+
function frameFor(box){var f=d.createElement('iframe');f.className='sw-video__frame';f.src=box.getAttribute('data-sw-video');f.title=box.getAttribute('data-sw-video-title')||'Video';f.setAttribute('allow','autoplay; encrypted-media; picture-in-picture; fullscreen');var sb=box.getAttribute('data-sw-video-sandbox');if(sb)f.setAttribute('sandbox',sb);f.setAttribute('referrerpolicy','strict-origin-when-cross-origin');return f}
|
|
429
|
+
function video(box){if(box._sw)return;box._sw=1;if(!/^https:\\/\\/(www\\.youtube-nocookie\\.com|player\\.vimeo\\.com)\\//.test(box.getAttribute('data-sw-video')||''))return;if(consented())notes(box,true);
|
|
430
|
+
var a=box.querySelector('[data-sw-video-facade]');if(a){a.setAttribute('role','button');
|
|
431
|
+
a.addEventListener('click',function(e){if(e.button||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey)return;e.preventDefault();var f=frameFor(box);a.parentNode.replaceChild(f,a);notes(box,true);try{f.focus()}catch(x){}});
|
|
432
|
+
a.addEventListener('keydown',function(e){if(e.key===' '){e.preventDefault();a.click()}})}
|
|
433
|
+
var b=box.querySelector('[popovertarget]'),pop=b&&d.getElementById(b.getAttribute('popovertarget'));if(!pop||pop._sw)return;pop._sw=1;
|
|
434
|
+
pop.addEventListener('toggle',function(e){var st=pop.querySelector('[data-sw-video-stage]');if(!st)return;var open=e.newState?e.newState==='open':pop.matches(':popover-open');
|
|
435
|
+
if(open){if(st.querySelector('iframe'))return;st._kids=[].slice.call(st.childNodes);st._kids.forEach(function(k){st.removeChild(k)});st.appendChild(frameFor(box));notes(box,true)}
|
|
436
|
+
else{var f=st.querySelector('iframe');if(f)st.removeChild(f);(st._kids||[]).forEach(function(k){st.appendChild(k)})}})}
|
|
437
|
+
function init(scope){if(scope.matches){if(scope.matches('[data-sw-accordion]'))accordion(scope);if(scope.matches('[data-sw-tabs]'))tabs(scope);if(scope.matches('[data-sw-carousel]'))carousel(scope);if(scope.matches('[data-sw-video]'))video(scope)}
|
|
438
|
+
[].slice.call(scope.querySelectorAll('[data-sw-accordion]')).forEach(accordion);[].slice.call(scope.querySelectorAll('[data-sw-tabs]')).forEach(tabs);[].slice.call(scope.querySelectorAll('[data-sw-carousel]')).forEach(carousel);[].slice.call(scope.querySelectorAll('[data-sw-video]')).forEach(video)}
|
|
439
|
+
function toHash(scroll){var id;try{id=decodeURIComponent(location.hash.slice(1))}catch(e){return}if(!id)return;var t=d.getElementById(id);if(!t)return;var el=t,hit=false,box=t;
|
|
440
|
+
while(el){if(el._swOpen){el._swOpen();hit=true}if(el._swSelect){el._swSelect();hit=true;if(el===t)box=el.closest('[data-sw-tabs]')||t}el=el.parentElement}
|
|
441
|
+
if(hit&&scroll)box.scrollIntoView({block:'start'});if(hit){var f=t._swb||(box!==t&&box.querySelector('[role=tab][aria-selected=true]'));if(f)try{f.focus({preventScroll:true})}catch(e){}}}
|
|
442
|
+
init(d);toHash(true);window.addEventListener('hashchange',function(){toHash(true)});
|
|
443
|
+
function motionChanged(){watchers.forEach(function(w){w()})}
|
|
444
|
+
if(mq){if(mq.addEventListener)mq.addEventListener('change',motionChanged);else if(mq.addListener)mq.addListener(motionChanged)}
|
|
445
|
+
window.addEventListener('storage',function(e){if(e.key===K)motionChanged()});
|
|
446
|
+
if('MutationObserver' in window){new MutationObserver(motionChanged).observe(h,{attributes:true,attributeFilter:['class','data-sw-motion']});
|
|
447
|
+
new MutationObserver(function(ms){ms.forEach(function(m){[].forEach.call(m.addedNodes,function(nd){if(nd.nodeType===1&&nd.querySelector)init(nd)})})}).observe(d.body,{childList:true,subtree:true})}
|
|
448
|
+
})();`;
|
|
449
|
+
//# sourceMappingURL=widgets.js.map
|