@krizaka/ui 3.85.0 → 3.86.0
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/dist/{chunk-FYPYJ6MW.js → chunk-GOGEYAYK.js} +25 -19
- package/dist/chunk-GOGEYAYK.js.map +1 -0
- package/dist/filter-bar.d.ts +3 -3
- package/dist/media-carousel.d.ts +10 -3
- package/dist/media-carousel.js +23 -14
- package/dist/media-carousel.js.map +1 -1
- package/dist/media-player.d.ts +16 -2
- package/dist/media-player.js +1 -1
- package/dist/pausable-loop.d.ts +27 -0
- package/dist/pausable-loop.js +68 -0
- package/dist/pausable-loop.js.map +1 -0
- package/dist/{player-lightbox-ETBQWDOT.js → player-lightbox-ASFOSUSD.js} +6 -3
- package/dist/{player-lightbox-ETBQWDOT.js.map → player-lightbox-ASFOSUSD.js.map} +1 -1
- package/dist/virtual.d.ts +3 -3
- package/package.json +19 -5
- package/registry/app-frame.json +1 -1
- package/registry/examples/media-gallery/carousel-loop.d.ts +4 -0
- package/registry/examples/media-gallery/carousel-loop.js +26 -0
- package/registry/examples/media-gallery/carousel-loop.tsx +24 -0
- package/registry/examples/media-gallery/carousel-single.d.ts +4 -0
- package/registry/examples/media-gallery/carousel-single.js +12 -0
- package/registry/examples/media-gallery/carousel-single.tsx +12 -0
- package/registry/examples/media-gallery/player-trigger.d.ts +4 -0
- package/registry/examples/media-gallery/player-trigger.js +20 -0
- package/registry/examples/media-gallery/player-trigger.tsx +19 -0
- package/registry/index.json +11 -10
- package/registry/map.json +1 -1
- package/registry/media-gallery.json +43 -7
- package/registry/nav-bar.json +1 -1
- package/registry/rail-nav.json +1 -1
- package/registry/shop.json +1 -1
- package/registry/site-footer.json +1 -1
- package/dist/chunk-FYPYJ6MW.js.map +0 -1
|
@@ -10,10 +10,11 @@ import {
|
|
|
10
10
|
import * as React from "react";
|
|
11
11
|
import { tv } from "tailwind-variants";
|
|
12
12
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
-
var PlayerLightbox = React.lazy(() => import("./player-lightbox-
|
|
13
|
+
var PlayerLightbox = React.lazy(() => import("./player-lightbox-ASFOSUSD.js"));
|
|
14
14
|
var mediaPlayer = tv({
|
|
15
15
|
slots: {
|
|
16
|
-
|
|
16
|
+
frame: "relative block w-full overflow-hidden rounded-xl border border-border-default bg-media p-0 text-fg-on-media",
|
|
17
|
+
poster: "group absolute inset-0 block h-full w-full focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring",
|
|
17
18
|
image: "absolute inset-0 h-full w-full object-cover",
|
|
18
19
|
play: "absolute left-1/2 top-1/2 flex h-14 w-14 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full bg-scrim-strong text-fg-on-media transition-colors group-hover:bg-scrim",
|
|
19
20
|
caption: "pointer-events-none absolute inset-x-0 bottom-0 bg-linear-to-t from-scrim-strong to-transparent p-3 pt-8 text-left text-xs font-semibold"
|
|
@@ -27,29 +28,34 @@ function MediaPlayer({
|
|
|
27
28
|
closeLabel = "Close",
|
|
28
29
|
posterAlt = "",
|
|
29
30
|
caption,
|
|
31
|
+
preview,
|
|
32
|
+
open: given,
|
|
33
|
+
trigger,
|
|
30
34
|
onOpenChange,
|
|
35
|
+
ratio: freeRatio,
|
|
31
36
|
className,
|
|
32
37
|
...player
|
|
33
38
|
}) {
|
|
34
|
-
const ratio = vertical ? "9 / 16" : "16 / 9";
|
|
35
|
-
const [
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
(next)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (!next) poster.current?.focus();
|
|
42
|
-
},
|
|
43
|
-
[onOpenChange]
|
|
44
|
-
);
|
|
39
|
+
const ratio = freeRatio ?? (vertical ? "9 / 16" : "16 / 9");
|
|
40
|
+
const [inner, setInner] = React.useState(false);
|
|
41
|
+
const open = given ?? inner;
|
|
42
|
+
const setOpen = (next) => {
|
|
43
|
+
setInner(next);
|
|
44
|
+
onOpenChange?.(next);
|
|
45
|
+
};
|
|
45
46
|
if (mode === "inline") return /* @__PURE__ */ jsx(VideoPlayer, { ...player, aspectRatio: ratio, className });
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
const name = playLabel ?? player.title;
|
|
48
|
+
const opener = trigger === void 0 ? /* @__PURE__ */ jsxs("div", { className: s.frame({ className }), style: { aspectRatio: ratio }, children: [
|
|
49
|
+
player.poster && /* @__PURE__ */ jsx("img", { src: player.poster, alt: posterAlt, loading: "lazy", decoding: "async", className: s.image() }),
|
|
50
|
+
preview,
|
|
51
|
+
/* @__PURE__ */ jsxs("button", { type: "button", className: s.poster(), "aria-label": caption ? `${caption}. ${name}` : name, onClick: () => setOpen(true), children: [
|
|
49
52
|
/* @__PURE__ */ jsx("span", { className: s.play(), "aria-hidden": true, children: /* @__PURE__ */ jsx(PlayGlyph, { className: "ml-1 h-6 w-6" }) }),
|
|
50
53
|
caption && /* @__PURE__ */ jsx("span", { className: s.caption(), children: caption })
|
|
51
|
-
] })
|
|
52
|
-
|
|
54
|
+
] })
|
|
55
|
+
] }) : trigger?.(() => setOpen(true));
|
|
56
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
57
|
+
opener,
|
|
58
|
+
open && /* @__PURE__ */ jsx(React.Suspense, { fallback: null, children: /* @__PURE__ */ jsx(PlayerLightbox, { player, ratio, vertical, closeLabel, onClose: () => setOpen(false) }) })
|
|
53
59
|
] });
|
|
54
60
|
}
|
|
55
61
|
|
|
@@ -57,4 +63,4 @@ export {
|
|
|
57
63
|
mediaPlayer,
|
|
58
64
|
MediaPlayer
|
|
59
65
|
};
|
|
60
|
-
//# sourceMappingURL=chunk-
|
|
66
|
+
//# sourceMappingURL=chunk-GOGEYAYK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/media-gallery/media-player.tsx"],"sourcesContent":["// Client (a dialog, the video player). ONE designed media player: the same frame inline, in a lightbox, or vertical (9:16).\n// Inline it is the VideoPlayer of `@krizaka/ui/video-player`; as a lightbox a poster with a play button opens the player in a\n// dialog, started by that press, with sound. Nothing moves under the pointer: the poster's hover is a colour.\nimport * as React from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nimport { PlayGlyph } from \"../glyphs\";\nimport { VideoPlayer, type VideoPlayerProps } from \"../video-player\";\n\n// The dialog and the player of the lightbox load when the poster is pressed, not with the page.\nconst PlayerLightbox = React.lazy(() => import(\"./player-lightbox\"));\n\nexport const mediaPlayer = tv({\n slots: {\n frame: \"relative block w-full overflow-hidden rounded-xl border border-border-default bg-media p-0 text-fg-on-media\",\n poster:\n \"group absolute inset-0 block h-full w-full \" +\n \"focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring\",\n image: \"absolute inset-0 h-full w-full object-cover\",\n play:\n \"absolute left-1/2 top-1/2 flex h-14 w-14 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full \" +\n \"bg-scrim-strong text-fg-on-media transition-colors group-hover:bg-scrim\",\n caption: \"pointer-events-none absolute inset-x-0 bottom-0 bg-linear-to-t from-scrim-strong to-transparent p-3 pt-8 text-left text-xs font-semibold\",\n },\n});\nconst s = mediaPlayer();\n\nexport type MediaPlayerProps = Pick<\n VideoPlayerProps,\n \"src\" | \"poster\" | \"title\" | \"tracks\" | \"loadHls\" | \"labels\" | \"onPlay\" | \"onPause\" | \"onEnded\" | \"onError\"\n> & {\n /** `inline`: the player itself. `lightbox`: a poster that opens it in a dialog. Default `inline`. */\n mode?: \"inline\" | \"lightbox\";\n /** `9 / 16` frame and the narrow dialog for a vertical film; default `16 / 9`. */\n vertical?: boolean;\n /** Any frame ratio (`19 / 16`, `4 / 3`): wins over the frame of `vertical` (give both for a portrait ratio: `vertical ratio=\"3 / 4\"`). Default `16 / 9` (`9 / 16` when `vertical`). */\n ratio?: string;\n /** The poster's words in the lightbox (\"Play the film\"), passed translated. Required for `lightbox`. */\n playLabel?: string;\n /** The close button's words, passed translated. Default `Close`. */\n closeLabel?: string;\n /** What the poster shows, in words (the `alt` of its image); default is empty (decorative: `playLabel` names the button). */\n posterAlt?: string;\n /** A line over the foot of the poster (« Fig. 1a »). */\n caption?: string;\n /** Lightbox: drawn over the poster, under its press (the frame is `relative`): a `<PausableLoop>` of `@krizaka/ui/pausable-loop` previews the film with a muted loop. */\n preview?: React.ReactNode;\n /** Lightbox: opens or closes it from outside (controlled). With it, `onOpenChange` is how the lightbox asks to close. */\n open?: boolean;\n /** Lightbox: replaces the poster with your own opener (`(open) => <button onClick={open}>…`); `null` draws nothing, for a lightbox driven by `open` alone. */\n trigger?: ((open: () => void) => React.ReactNode) | null;\n /** Called when the lightbox opens or closes. */\n onOpenChange?: (open: boolean) => void;\n /** Classes merged on the player or the poster. */\n className?: string;\n};\n\n/** A video in one frame: inline, in a lightbox (a press opens it with sound), 16:9 or vertical. */\nexport function MediaPlayer({\n mode = \"inline\",\n vertical = false,\n playLabel,\n closeLabel = \"Close\",\n posterAlt = \"\",\n caption,\n preview,\n open: given,\n trigger,\n onOpenChange,\n ratio: freeRatio,\n className,\n ...player\n}: MediaPlayerProps) {\n const ratio = freeRatio ?? (vertical ? \"9 / 16\" : \"16 / 9\");\n const [inner, setInner] = React.useState(false);\n const open = given ?? inner;\n const setOpen = (next: boolean) => {\n setInner(next);\n onOpenChange?.(next);\n };\n // The dialog hands the focus back to whatever opened it (the poster or the page's own trigger) when it closes.\n if (mode === \"inline\") return <VideoPlayer {...player} aspectRatio={ratio} className={className} />;\n const name = playLabel ?? player.title;\n // The default opener: the poster (and its loop) in a frame, one button named by `playLabel`; the pause is a sibling, never nested.\n const opener =\n trigger === undefined ? (\n <div className={s.frame({ className })} style={{ aspectRatio: ratio }}>\n {player.poster && <img src={player.poster} alt={posterAlt} loading=\"lazy\" decoding=\"async\" className={s.image()} />}\n {preview}\n <button type=\"button\" className={s.poster()} aria-label={caption ? `${caption}. ${name}` : name} onClick={() => setOpen(true)}>\n <span className={s.play()} aria-hidden>\n <PlayGlyph className=\"ml-1 h-6 w-6\" />\n </span>\n {caption && <span className={s.caption()}>{caption}</span>}\n </button>\n </div>\n ) : (\n trigger?.(() => setOpen(true))\n );\n return (\n <>\n {opener}\n {open && (\n <React.Suspense fallback={null}>\n <PlayerLightbox player={player} ratio={ratio} vertical={vertical} closeLabel={closeLabel} onClose={() => setOpen(false)} />\n </React.Suspense>\n )}\n </>\n );\n}\n"],"mappings":";;;;;;;;;AAGA,YAAY,WAAW;AACvB,SAAS,UAAU;AA6Ea,SAmB5B,UAnB4B,KAQxB,YARwB;AAvEhC,IAAM,iBAAuB,WAAK,MAAM,OAAO,+BAAmB,CAAC;AAE5D,IAAM,cAAc,GAAG;AAAA,EAC5B,OAAO;AAAA,IACL,OAAO;AAAA,IACP,QACE;AAAA,IAEF,OAAO;AAAA,IACP,MACE;AAAA,IAEF,SAAS;AAAA,EACX;AACF,CAAC;AACD,IAAM,IAAI,YAAY;AAiCf,SAAS,YAAY;AAAA,EAC1B,OAAO;AAAA,EACP,WAAW;AAAA,EACX;AAAA,EACA,aAAa;AAAA,EACb,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA,MAAM;AAAA,EACN;AAAA,EACA;AAAA,EACA,OAAO;AAAA,EACP;AAAA,EACA,GAAG;AACL,GAAqB;AACnB,QAAM,QAAQ,cAAc,WAAW,WAAW;AAClD,QAAM,CAAC,OAAO,QAAQ,IAAU,eAAS,KAAK;AAC9C,QAAM,OAAO,SAAS;AACtB,QAAM,UAAU,CAAC,SAAkB;AACjC,aAAS,IAAI;AACb,mBAAe,IAAI;AAAA,EACrB;AAEA,MAAI,SAAS,SAAU,QAAO,oBAAC,eAAa,GAAG,QAAQ,aAAa,OAAO,WAAsB;AACjG,QAAM,OAAO,aAAa,OAAO;AAEjC,QAAM,SACJ,YAAY,SACV,qBAAC,SAAI,WAAW,EAAE,MAAM,EAAE,UAAU,CAAC,GAAG,OAAO,EAAE,aAAa,MAAM,GACjE;AAAA,WAAO,UAAU,oBAAC,SAAI,KAAK,OAAO,QAAQ,KAAK,WAAW,SAAQ,QAAO,UAAS,SAAQ,WAAW,EAAE,MAAM,GAAG;AAAA,IAChH;AAAA,IACD,qBAAC,YAAO,MAAK,UAAS,WAAW,EAAE,OAAO,GAAG,cAAY,UAAU,GAAG,OAAO,KAAK,IAAI,KAAK,MAAM,SAAS,MAAM,QAAQ,IAAI,GAC1H;AAAA,0BAAC,UAAK,WAAW,EAAE,KAAK,GAAG,eAAW,MACpC,8BAAC,aAAU,WAAU,gBAAe,GACtC;AAAA,MACC,WAAW,oBAAC,UAAK,WAAW,EAAE,QAAQ,GAAI,mBAAQ;AAAA,OACrD;AAAA,KACF,IAEA,UAAU,MAAM,QAAQ,IAAI,CAAC;AAEjC,SACE,iCACG;AAAA;AAAA,IACA,QACC,oBAAO,gBAAN,EAAe,UAAU,MACxB,8BAAC,kBAAe,QAAgB,OAAc,UAAoB,YAAwB,SAAS,MAAM,QAAQ,KAAK,GAAG,GAC3H;AAAA,KAEJ;AAEJ;","names":[]}
|
package/dist/filter-bar.d.ts
CHANGED
|
@@ -82,12 +82,12 @@ declare function SavedViews({ views, current, modified, onSelect, onSave, onRena
|
|
|
82
82
|
declare const filterBar: tailwind_variants.TVReturnType<{
|
|
83
83
|
[key: string]: {
|
|
84
84
|
[key: string]: tailwind_variants.ClassValue | {
|
|
85
|
-
count?: tailwind_variants.ClassValue;
|
|
86
85
|
root?: tailwind_variants.ClassValue;
|
|
87
86
|
controls?: tailwind_variants.ClassValue;
|
|
88
87
|
active?: tailwind_variants.ClassValue;
|
|
89
88
|
clear?: tailwind_variants.ClassValue;
|
|
90
89
|
results?: tailwind_variants.ClassValue;
|
|
90
|
+
count?: tailwind_variants.ClassValue;
|
|
91
91
|
optionCount?: tailwind_variants.ClassValue;
|
|
92
92
|
trigger?: tailwind_variants.ClassValue;
|
|
93
93
|
};
|
|
@@ -95,12 +95,12 @@ declare const filterBar: tailwind_variants.TVReturnType<{
|
|
|
95
95
|
} | {
|
|
96
96
|
[x: string]: {
|
|
97
97
|
[x: string]: tailwind_variants.ClassValue | {
|
|
98
|
-
count?: tailwind_variants.ClassValue;
|
|
99
98
|
root?: tailwind_variants.ClassValue;
|
|
100
99
|
controls?: tailwind_variants.ClassValue;
|
|
101
100
|
active?: tailwind_variants.ClassValue;
|
|
102
101
|
clear?: tailwind_variants.ClassValue;
|
|
103
102
|
results?: tailwind_variants.ClassValue;
|
|
103
|
+
count?: tailwind_variants.ClassValue;
|
|
104
104
|
optionCount?: tailwind_variants.ClassValue;
|
|
105
105
|
trigger?: tailwind_variants.ClassValue;
|
|
106
106
|
};
|
|
@@ -117,12 +117,12 @@ declare const filterBar: tailwind_variants.TVReturnType<{
|
|
|
117
117
|
}, undefined, {
|
|
118
118
|
[key: string]: {
|
|
119
119
|
[key: string]: tailwind_variants.ClassValue | {
|
|
120
|
-
count?: tailwind_variants.ClassValue;
|
|
121
120
|
root?: tailwind_variants.ClassValue;
|
|
122
121
|
controls?: tailwind_variants.ClassValue;
|
|
123
122
|
active?: tailwind_variants.ClassValue;
|
|
124
123
|
clear?: tailwind_variants.ClassValue;
|
|
125
124
|
results?: tailwind_variants.ClassValue;
|
|
125
|
+
count?: tailwind_variants.ClassValue;
|
|
126
126
|
optionCount?: tailwind_variants.ClassValue;
|
|
127
127
|
trigger?: tailwind_variants.ClassValue;
|
|
128
128
|
};
|
package/dist/media-carousel.d.ts
CHANGED
|
@@ -78,13 +78,13 @@ type CarouselSlide = {
|
|
|
78
78
|
alt: string;
|
|
79
79
|
/** « Fig. 1a »: one line over the foot of the slide. */
|
|
80
80
|
caption?: string;
|
|
81
|
-
/** A muted loop playing while the slide is the one in view. */
|
|
81
|
+
/** A muted loop playing while the slide is the one in view and on screen, after the page's `load`, with a visible pause; a still under reduced motion. On a `film` slide it previews the film. */
|
|
82
82
|
video?: {
|
|
83
83
|
webm?: string;
|
|
84
84
|
mp4?: string;
|
|
85
85
|
};
|
|
86
86
|
/** A film opened by a press, with sound, in the lightbox of the MediaPlayer. */
|
|
87
|
-
film?: Pick<MediaPlayerProps, "src" | "title" | "tracks" | "loadHls"> & {
|
|
87
|
+
film?: Pick<MediaPlayerProps, "src" | "title" | "tracks" | "loadHls" | "labels" | "ratio"> & {
|
|
88
88
|
playLabel: string;
|
|
89
89
|
vertical?: boolean;
|
|
90
90
|
};
|
|
@@ -105,9 +105,16 @@ type MediaCarouselProps = Omit<React.ComponentProps<"section">, "children"> & {
|
|
|
105
105
|
ratio?: string;
|
|
106
106
|
/** The words, passed translated; English by default. `slide` takes `{n}` and `{total}`. */
|
|
107
107
|
labels?: Partial<MediaCarouselLabels>;
|
|
108
|
+
/** The words of the lightbox player of every film (speed, captions, time…), passed translated; a slide's own `film.labels` wins. */
|
|
109
|
+
playerLabels?: MediaPlayerProps["labels"];
|
|
110
|
+
/** Draws a slide's `video`: `(video, { poster, inView }) => <PausableLoop sources={video} poster={poster} active={inView} />` (`@krizaka/ui/pausable-loop`, which brings the pause and play). Without it a slide stays a still, and this entry stays light. */
|
|
111
|
+
renderLoop?: (video: NonNullable<CarouselSlide["video"]>, context: {
|
|
112
|
+
poster: string;
|
|
113
|
+
inView: boolean;
|
|
114
|
+
}) => React.ReactNode;
|
|
108
115
|
};
|
|
109
116
|
/** A few realisations in one frame, one at a time: swipe, buttons or arrow keys on them; nothing advances by itself. */
|
|
110
|
-
declare function MediaCarousel({ slides, label, ratio, labels: given, className, ...props }: Readonly<MediaCarouselProps>): React.JSX.Element;
|
|
117
|
+
declare function MediaCarousel({ slides, label, ratio, labels: given, playerLabels, renderLoop, className, ...props }: Readonly<MediaCarouselProps>): React.JSX.Element;
|
|
111
118
|
|
|
112
119
|
export { MediaCarousel, mediaCarousel, mediaCarouselLabels };
|
|
113
120
|
export type { CarouselSlide, MediaCarouselLabels, MediaCarouselProps };
|
package/dist/media-carousel.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
MediaPlayer
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-GOGEYAYK.js";
|
|
5
5
|
import {
|
|
6
6
|
IconButton
|
|
7
7
|
} from "./chunk-QHVV2JGF.js";
|
|
@@ -44,7 +44,7 @@ function useActiveSlide(track, count) {
|
|
|
44
44
|
setActive(next);
|
|
45
45
|
return next;
|
|
46
46
|
};
|
|
47
|
-
return { active, go
|
|
47
|
+
return { active, go };
|
|
48
48
|
}
|
|
49
49
|
function useSwipe(turn) {
|
|
50
50
|
const from = React.useRef(null);
|
|
@@ -65,31 +65,40 @@ function useSwipe(turn) {
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
function keepFocus(toolbar, at, count) {
|
|
68
|
-
if (!toolbar?.contains(document.activeElement)
|
|
68
|
+
if (!toolbar?.contains(document.activeElement)) return;
|
|
69
69
|
const [previous, next] = toolbar.querySelectorAll("button");
|
|
70
70
|
if (at === 0) next?.focus();
|
|
71
71
|
if (at === count - 1) previous?.focus();
|
|
72
72
|
}
|
|
73
73
|
var ARROWS = { ArrowRight: 1, ArrowLeft: -1 };
|
|
74
|
-
function SlideMedia({ slide,
|
|
74
|
+
function SlideMedia({ slide, loop, ratio, closeLabel, playerLabels }) {
|
|
75
75
|
if (slide.film) {
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
return /* @__PURE__ */ jsx(
|
|
77
|
+
MediaPlayer,
|
|
78
|
+
{
|
|
79
|
+
...slide.film,
|
|
80
|
+
labels: slide.film.labels ?? playerLabels,
|
|
81
|
+
mode: "lightbox",
|
|
82
|
+
poster: slide.src,
|
|
83
|
+
posterAlt: slide.alt,
|
|
84
|
+
caption: slide.caption,
|
|
85
|
+
closeLabel,
|
|
86
|
+
preview: loop,
|
|
87
|
+
className: "h-full rounded-none border-0"
|
|
88
|
+
}
|
|
89
|
+
);
|
|
78
90
|
}
|
|
79
91
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
80
92
|
/* @__PURE__ */ jsx("img", { src: slide.src, alt: slide.alt, loading: "lazy", decoding: "async", draggable: false, className: s.media(), style: { aspectRatio: ratio } }),
|
|
81
|
-
|
|
82
|
-
slide.video.webm && /* @__PURE__ */ jsx("source", { src: slide.video.webm, type: "video/webm" }),
|
|
83
|
-
slide.video.mp4 && /* @__PURE__ */ jsx("source", { src: slide.video.mp4, type: "video/mp4" })
|
|
84
|
-
] }),
|
|
93
|
+
loop,
|
|
85
94
|
slide.caption && /* @__PURE__ */ jsx("figcaption", { className: s.caption(), children: slide.caption })
|
|
86
95
|
] });
|
|
87
96
|
}
|
|
88
|
-
function MediaCarousel({ slides, label, ratio = "16 / 10", labels: given, className, ...props }) {
|
|
97
|
+
function MediaCarousel({ slides, label, ratio = "16 / 10", labels: given, playerLabels, renderLoop, className, ...props }) {
|
|
89
98
|
const labels = { ...mediaCarouselLabels, ...given };
|
|
90
99
|
const track = React.useRef(null);
|
|
91
100
|
const toolbar = React.useRef(null);
|
|
92
|
-
const { active, go
|
|
101
|
+
const { active, go } = useActiveSlide(track, slides.length);
|
|
93
102
|
const turn = (delta) => keepFocus(toolbar.current, go(active + delta), slides.length);
|
|
94
103
|
const swipe = useSwipe(turn);
|
|
95
104
|
const keys = (event) => {
|
|
@@ -100,8 +109,8 @@ function MediaCarousel({ slides, label, ratio = "16 / 10", labels: given, classN
|
|
|
100
109
|
};
|
|
101
110
|
const name = (i) => labels.slide.replace("{n}", String(i + 1)).replace("{total}", String(slides.length));
|
|
102
111
|
return /* @__PURE__ */ jsxs("section", { "aria-roledescription": "carousel", "aria-label": label, className: s.root({ className }), ...props, children: [
|
|
103
|
-
/* @__PURE__ */ jsx("ul", { ref: track, className: s.track(), ...swipe, children: slides.map((slide, i) => /* @__PURE__ */ jsx("li", { "aria-roledescription": "slide", "aria-label": name(i), className: s.slide(), style: { aspectRatio: ratio }, "aria-hidden": i === active ? void 0 : true, inert: i === active ? void 0 : true, children: /* @__PURE__ */ jsx("figure", { className: "m-0 h-full w-full", children: /* @__PURE__ */ jsx(SlideMedia, { slide,
|
|
104
|
-
/* @__PURE__ */ jsxs("div", { className: s.bar(), children: [
|
|
112
|
+
/* @__PURE__ */ jsx("ul", { ref: track, className: s.track(), ...swipe, children: slides.map((slide, i) => /* @__PURE__ */ jsx("li", { "aria-roledescription": "slide", "aria-label": name(i), className: s.slide(), style: { aspectRatio: ratio }, "aria-hidden": i === active ? void 0 : true, inert: i === active ? void 0 : true, children: /* @__PURE__ */ jsx("figure", { className: "m-0 h-full w-full", children: /* @__PURE__ */ jsx(SlideMedia, { slide, loop: slide.video && renderLoop?.(slide.video, { poster: slide.src, inView: i === active }), ratio, closeLabel: labels.close, playerLabels }) }) }, slide.id)) }),
|
|
113
|
+
slides.length > 1 && /* @__PURE__ */ jsxs("div", { className: s.bar(), children: [
|
|
105
114
|
/* @__PURE__ */ jsxs("span", { className: s.count(), "aria-live": "polite", children: [
|
|
106
115
|
active + 1,
|
|
107
116
|
" / ",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/media-gallery/media-carousel.tsx"],"sourcesContent":["// Client (the slide in view, the reader's motion preference). A few realisations in one frame: a scroll-snap track moved by\n// a swipe, previous / next buttons in a toolbar that also takes the arrow keys, a « n / N » count. Nothing advances by itself and nothing moves under the pointer; a loop plays only on the\n// slide in view (a still under reduced motion); a slide with a film opens it in the MediaPlayer lightbox.\nimport * as React from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nimport { IconButton } from \"../button/button\";\nimport { ChevronGlyph } from \"../glyphs\";\nimport { usePrefersReducedMotion } from \"../media\";\nimport { MediaPlayer, type MediaPlayerProps } from \"./media-player\";\n\nexport const mediaCarousel = tv({\n slots: {\n root: \"relative isolate w-full\",\n track: \"m-0 flex list-none snap-x snap-mandatory gap-3 overflow-hidden p-0 touch-pan-y\",\n slide: \"relative m-0 w-full shrink-0 snap-center overflow-hidden rounded-xl border border-border-default bg-media\",\n media: \"absolute inset-0 h-full w-full object-cover\",\n caption: \"absolute inset-x-0 bottom-0 bg-linear-to-t from-scrim-strong to-transparent p-3 pt-8 text-xs font-semibold text-fg-on-media\",\n bar: \"mt-3 flex items-center justify-between gap-3\",\n count: \"text-xs tabular-nums text-fg-secondary\",\n buttons: \"flex gap-2\",\n },\n});\nconst s = mediaCarousel();\n\nexport type CarouselSlide = {\n /** A stable id. */\n id: string;\n /** The still, or the poster of a loop or a film. */\n src: string;\n /** What it shows, in words. */\n alt: string;\n /** « Fig. 1a »: one line over the foot of the slide. */\n caption?: string;\n /** A muted loop playing while the slide is the one in view. */\n video?: { webm?: string; mp4?: string };\n /** A film opened by a press, with sound, in the lightbox of the MediaPlayer. */\n film?: Pick<MediaPlayerProps, \"src\" | \"title\" | \"tracks\" | \"loadHls\"> & { playLabel: string; vertical?: boolean };\n};\n\nexport type MediaCarouselLabels = { previous: string; next: string; close: string; slide: string };\nexport const mediaCarouselLabels: MediaCarouselLabels = { previous: \"Previous\", next: \"Next\", close: \"Close\", slide: \"{n} of {total}\" };\n\nexport type MediaCarouselProps = Omit<React.ComponentProps<\"section\">, \"children\"> & {\n /** The slides, in order: 3 to 4 realisations. */\n slides: readonly CarouselSlide[];\n /** The carousel's accessible name, passed translated. */\n label: string;\n /** The frame ratio of every slide (width / height). Default `16 / 10`. */\n ratio?: string;\n /** The words, passed translated; English by default. `slide` takes `{n}` and `{total}`. */\n labels?: Partial<MediaCarouselLabels>;\n};\n\n/** How far a swipe travels, in CSS pixels, before it turns the slide. */\nconst SWIPE_DISTANCE = 40;\n\n/** The slide in view and the one way to change it: the track scrolls only from here, so it holds no scroll of its own to reach. */\nfunction useActiveSlide(track: React.RefObject<HTMLUListElement | null>, count: number) {\n const [active, setActive] = React.useState(0);\n const reduce = usePrefersReducedMotion();\n const go = (to: number) => {\n const el = track.current;\n if (!el) return active;\n const next = Math.min(count - 1, Math.max(0, to));\n el.scrollTo({ left: next * (el.scrollWidth / count), behavior: reduce ? \"auto\" : \"smooth\" });\n setActive(next);\n return next;\n };\n return { active, go, reduce };\n}\n\n/** A horizontal swipe on the track turns one slide; a vertical one stays the page's scroll (`touch-action: pan-y`). */\nfunction useSwipe(turn: (delta: 1 | -1) => void) {\n const from = React.useRef<number | null>(null);\n return {\n onPointerDown: (event: React.PointerEvent) => {\n from.current = event.clientX;\n },\n onPointerUp: (event: React.PointerEvent) => {\n const start = from.current;\n from.current = null;\n if (start === null) return;\n const distance = event.clientX - start;\n if (Math.abs(distance) >= SWIPE_DISTANCE) turn(distance < 0 ? 1 : -1);\n },\n onPointerCancel: () => {\n from.current = null;\n },\n };\n}\n\n/** At an end the button just used is disabled: the focus moves to the other one, never to the page. */\nfunction keepFocus(toolbar: HTMLElement | null, at: number, count: number) {\n if (!toolbar?.contains(document.activeElement) || count < 2) return;\n const [previous, next] = toolbar.querySelectorAll(\"button\");\n if (at === 0) next?.focus();\n if (at === count - 1) previous?.focus();\n}\n\n/** The arrow keys of the toolbar: right turns forward, left back. */\nconst ARROWS: Partial<Record<string, 1 | -1>> = { ArrowRight: 1, ArrowLeft: -1 };\n\nfunction SlideMedia({ slide, playing, ratio, closeLabel }: Readonly<{ slide: CarouselSlide; playing: boolean; ratio: string; closeLabel: string }>) {\n if (slide.film) {\n const { playLabel, vertical, ...film } = slide.film;\n return <MediaPlayer {...film} mode=\"lightbox\" poster={slide.src} posterAlt={slide.alt} playLabel={playLabel} vertical={vertical} caption={slide.caption} closeLabel={closeLabel} className=\"h-full rounded-none border-0\" />;\n }\n return (\n <>\n <img src={slide.src} alt={slide.alt} loading=\"lazy\" decoding=\"async\" draggable={false} className={s.media()} style={{ aspectRatio: ratio }} />\n {playing && slide.video && (\n <video className={s.media()} poster={slide.src} autoPlay muted loop playsInline aria-hidden tabIndex={-1}>\n {slide.video.webm && <source src={slide.video.webm} type=\"video/webm\" />}\n {slide.video.mp4 && <source src={slide.video.mp4} type=\"video/mp4\" />}\n </video>\n )}\n {slide.caption && <figcaption className={s.caption()}>{slide.caption}</figcaption>}\n </>\n );\n}\n\n/** A few realisations in one frame, one at a time: swipe, buttons or arrow keys on them; nothing advances by itself. */\nexport function MediaCarousel({ slides, label, ratio = \"16 / 10\", labels: given, className, ...props }: Readonly<MediaCarouselProps>) {\n const labels = { ...mediaCarouselLabels, ...given };\n const track = React.useRef<HTMLUListElement>(null);\n const toolbar = React.useRef<HTMLDivElement>(null);\n const { active, go, reduce } = useActiveSlide(track, slides.length);\n const turn = (delta: 1 | -1) => keepFocus(toolbar.current, go(active + delta), slides.length);\n const swipe = useSwipe(turn);\n const keys = (event: React.KeyboardEvent<HTMLDivElement>) => {\n const delta = ARROWS[event.key];\n if (!delta) return;\n event.preventDefault();\n turn(delta);\n };\n const name = (i: number) => labels.slide.replace(\"{n}\", String(i + 1)).replace(\"{total}\", String(slides.length));\n return (\n <section aria-roledescription=\"carousel\" aria-label={label} className={s.root({ className })} {...props}>\n <ul ref={track} className={s.track()} {...swipe}>\n {slides.map((slide, i) => (\n <li key={slide.id} aria-roledescription=\"slide\" aria-label={name(i)} className={s.slide()} style={{ aspectRatio: ratio }} aria-hidden={i === active ? undefined : true} inert={i === active ? undefined : true}>\n <figure className=\"m-0 h-full w-full\">\n <SlideMedia slide={slide} playing={i === active && !reduce} ratio={ratio} closeLabel={labels.close} />\n </figure>\n </li>\n ))}\n </ul>\n <div className={s.bar()}>\n <span className={s.count()} aria-live=\"polite\">{active + 1} / {slides.length}</span>\n <div ref={toolbar} role=\"toolbar\" aria-orientation=\"horizontal\" className={s.buttons()} onKeyDown={keys}>\n <IconButton variant=\"secondary\" label={labels.previous} disabled={active === 0} onClick={() => turn(-1)}>\n <ChevronGlyph direction=\"left\" className=\"h-5 w-5\" />\n </IconButton>\n <IconButton variant=\"secondary\" label={labels.next} disabled={active === slides.length - 1} onClick={() => turn(1)}>\n <ChevronGlyph direction=\"right\" className=\"h-5 w-5\" />\n </IconButton>\n </div>\n </div>\n </section>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAGA,YAAY,WAAW;AACvB,SAAS,UAAU;AAsGR,SAGP,UAHO,KAMH,YANG;AA/FJ,IAAM,gBAAgB,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AAS,MAAK,WAAU,oBAAiB,cAAa,WAAW,EAAE,QAAQ,GAAG,WAAW,MACjG;AAAA,4BAAC,cAAW,SAAQ,aAAY,OAAO,OAAO,UAAU,UAAU,WAAW,GAAG,SAAS,MAAM,KAAK,EAAE,GACpG,8BAAC,gBAAa,WAAU,QAAO,WAAU,WAAU,GACrD;AAAA,QACA,oBAAC,cAAW,SAAQ,aAAY,OAAO,OAAO,MAAM,UAAU,WAAW,OAAO,SAAS,GAAG,SAAS,MAAM,KAAK,CAAC,GAC/G,8BAAC,gBAAa,WAAU,SAAQ,WAAU,WAAU,GACtD;AAAA,SACF;AAAA,OACF;AAAA,KACF;AAEJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/media-gallery/media-carousel.tsx"],"sourcesContent":["// Client (the slide in view, the reader's motion preference). A few realisations in one frame: a scroll-snap track moved by\n// a swipe, previous / next buttons in a toolbar that also takes the arrow keys, a « n / N » count. Nothing advances by itself and nothing moves under the pointer; a loop plays only on the\n// slide in view (a still under reduced motion); a slide with a film opens it in the MediaPlayer lightbox.\nimport * as React from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nimport { IconButton } from \"../button/button\";\nimport { ChevronGlyph } from \"../glyphs\";\nimport { usePrefersReducedMotion } from \"../media\";\nimport { MediaPlayer, type MediaPlayerProps } from \"./media-player\";\n\nexport const mediaCarousel = tv({\n slots: {\n root: \"relative isolate w-full\",\n track: \"m-0 flex list-none snap-x snap-mandatory gap-3 overflow-hidden p-0 touch-pan-y\",\n slide: \"relative m-0 w-full shrink-0 snap-center overflow-hidden rounded-xl border border-border-default bg-media\",\n media: \"absolute inset-0 h-full w-full object-cover\",\n caption: \"absolute inset-x-0 bottom-0 bg-linear-to-t from-scrim-strong to-transparent p-3 pt-8 text-xs font-semibold text-fg-on-media\",\n bar: \"mt-3 flex items-center justify-between gap-3\",\n count: \"text-xs tabular-nums text-fg-secondary\",\n buttons: \"flex gap-2\",\n },\n});\nconst s = mediaCarousel();\n\nexport type CarouselSlide = {\n /** A stable id. */\n id: string;\n /** The still, or the poster of a loop or a film. */\n src: string;\n /** What it shows, in words. */\n alt: string;\n /** « Fig. 1a »: one line over the foot of the slide. */\n caption?: string;\n /** A muted loop playing while the slide is the one in view and on screen, after the page's `load`, with a visible pause; a still under reduced motion. On a `film` slide it previews the film. */\n video?: { webm?: string; mp4?: string };\n /** A film opened by a press, with sound, in the lightbox of the MediaPlayer. */\n film?: Pick<MediaPlayerProps, \"src\" | \"title\" | \"tracks\" | \"loadHls\" | \"labels\" | \"ratio\"> & { playLabel: string; vertical?: boolean };\n};\n\nexport type MediaCarouselLabels = { previous: string; next: string; close: string; slide: string };\nexport const mediaCarouselLabels: MediaCarouselLabels = { previous: \"Previous\", next: \"Next\", close: \"Close\", slide: \"{n} of {total}\" };\n\nexport type MediaCarouselProps = Omit<React.ComponentProps<\"section\">, \"children\"> & {\n /** The slides, in order: 3 to 4 realisations. */\n slides: readonly CarouselSlide[];\n /** The carousel's accessible name, passed translated. */\n label: string;\n /** The frame ratio of every slide (width / height). Default `16 / 10`. */\n ratio?: string;\n /** The words, passed translated; English by default. `slide` takes `{n}` and `{total}`. */\n labels?: Partial<MediaCarouselLabels>;\n /** The words of the lightbox player of every film (speed, captions, time…), passed translated; a slide's own `film.labels` wins. */\n playerLabels?: MediaPlayerProps[\"labels\"];\n /** Draws a slide's `video`: `(video, { poster, inView }) => <PausableLoop sources={video} poster={poster} active={inView} />` (`@krizaka/ui/pausable-loop`, which brings the pause and play). Without it a slide stays a still, and this entry stays light. */\n renderLoop?: (video: NonNullable<CarouselSlide[\"video\"]>, context: { poster: string; inView: boolean }) => React.ReactNode;\n};\n\n/** How far a swipe travels, in CSS pixels, before it turns the slide. */\nconst SWIPE_DISTANCE = 40;\n\n/** The slide in view and the one way to change it: the track scrolls only from here, so it holds no scroll of its own to reach. */\nfunction useActiveSlide(track: React.RefObject<HTMLUListElement | null>, count: number) {\n const [active, setActive] = React.useState(0);\n const reduce = usePrefersReducedMotion();\n const go = (to: number) => {\n const el = track.current;\n if (!el) return active;\n const next = Math.min(count - 1, Math.max(0, to));\n el.scrollTo({ left: next * (el.scrollWidth / count), behavior: reduce ? \"auto\" : \"smooth\" });\n setActive(next);\n return next;\n };\n return { active, go };\n}\n\n/** A horizontal swipe on the track turns one slide; a vertical one stays the page's scroll (`touch-action: pan-y`). */\nfunction useSwipe(turn: (delta: 1 | -1) => void) {\n const from = React.useRef<number | null>(null);\n return {\n onPointerDown: (event: React.PointerEvent) => {\n from.current = event.clientX;\n },\n onPointerUp: (event: React.PointerEvent) => {\n const start = from.current;\n from.current = null;\n if (start === null) return;\n const distance = event.clientX - start;\n if (Math.abs(distance) >= SWIPE_DISTANCE) turn(distance < 0 ? 1 : -1);\n },\n onPointerCancel: () => {\n from.current = null;\n },\n };\n}\n\n/** At an end the button just used is disabled: the focus moves to the other one, never to the page. */\nfunction keepFocus(toolbar: HTMLElement | null, at: number, count: number) {\n if (!toolbar?.contains(document.activeElement)) return;\n const [previous, next] = toolbar.querySelectorAll(\"button\");\n if (at === 0) next?.focus();\n if (at === count - 1) previous?.focus();\n}\n\n/** The arrow keys of the toolbar: right turns forward, left back. */\nconst ARROWS: Partial<Record<string, 1 | -1>> = { ArrowRight: 1, ArrowLeft: -1 };\n\ntype SlideMediaProps = Readonly<{ slide: CarouselSlide; loop: React.ReactNode; ratio: string; closeLabel: string; playerLabels?: MediaPlayerProps[\"labels\"] }>;\n\n/** A poster that opens its film, or a still; its loop, when `renderLoop` draws one, previews the film or plays over the still while the slide is the one in view. */\nfunction SlideMedia({ slide, loop, ratio, closeLabel, playerLabels }: SlideMediaProps) {\n if (slide.film) {\n return (\n <MediaPlayer\n {...slide.film}\n labels={slide.film.labels ?? playerLabels}\n mode=\"lightbox\"\n poster={slide.src}\n posterAlt={slide.alt}\n caption={slide.caption}\n closeLabel={closeLabel}\n preview={loop}\n className=\"h-full rounded-none border-0\"\n />\n );\n }\n return (\n <>\n <img src={slide.src} alt={slide.alt} loading=\"lazy\" decoding=\"async\" draggable={false} className={s.media()} style={{ aspectRatio: ratio }} />\n {loop}\n {slide.caption && <figcaption className={s.caption()}>{slide.caption}</figcaption>}\n </>\n );\n}\n\n/** A few realisations in one frame, one at a time: swipe, buttons or arrow keys on them; nothing advances by itself. */\nexport function MediaCarousel({ slides, label, ratio = \"16 / 10\", labels: given, playerLabels, renderLoop, className, ...props }: Readonly<MediaCarouselProps>) {\n const labels = { ...mediaCarouselLabels, ...given };\n const track = React.useRef<HTMLUListElement>(null);\n const toolbar = React.useRef<HTMLDivElement>(null);\n const { active, go } = useActiveSlide(track, slides.length);\n const turn = (delta: 1 | -1) => keepFocus(toolbar.current, go(active + delta), slides.length);\n const swipe = useSwipe(turn);\n const keys = (event: React.KeyboardEvent<HTMLDivElement>) => {\n const delta = ARROWS[event.key];\n if (!delta) return;\n event.preventDefault();\n turn(delta);\n };\n const name = (i: number) => labels.slide.replace(\"{n}\", String(i + 1)).replace(\"{total}\", String(slides.length));\n return (\n <section aria-roledescription=\"carousel\" aria-label={label} className={s.root({ className })} {...props}>\n <ul ref={track} className={s.track()} {...swipe}>\n {slides.map((slide, i) => (\n <li key={slide.id} aria-roledescription=\"slide\" aria-label={name(i)} className={s.slide()} style={{ aspectRatio: ratio }} aria-hidden={i === active ? undefined : true} inert={i === active ? undefined : true}>\n <figure className=\"m-0 h-full w-full\">\n <SlideMedia slide={slide} loop={slide.video && renderLoop?.(slide.video, { poster: slide.src, inView: i === active })} ratio={ratio} closeLabel={labels.close} playerLabels={playerLabels} />\n </figure>\n </li>\n ))}\n </ul>\n {slides.length > 1 && (\n <div className={s.bar()}>\n <span className={s.count()} aria-live=\"polite\">{active + 1} / {slides.length}</span>\n <div ref={toolbar} role=\"toolbar\" aria-orientation=\"horizontal\" className={s.buttons()} onKeyDown={keys}>\n <IconButton variant=\"secondary\" label={labels.previous} disabled={active === 0} onClick={() => turn(-1)}>\n <ChevronGlyph direction=\"left\" className=\"h-5 w-5\" />\n </IconButton>\n <IconButton variant=\"secondary\" label={labels.next} disabled={active === slides.length - 1} onClick={() => turn(1)}>\n <ChevronGlyph direction=\"right\" className=\"h-5 w-5\" />\n </IconButton>\n </div>\n </div>\n )}\n </section>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAGA,YAAY,WAAW;AACvB,SAAS,UAAU;AA6Gb,SAcF,UAdE,KAcF,YAdE;AAtGC,IAAM,gBAAgB,GAAG;AAAA,EAC9B,OAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA,IACP,SAAS;AAAA,IACT,KAAK;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,EACX;AACF,CAAC;AACD,IAAM,IAAI,cAAc;AAkBjB,IAAM,sBAA2C,EAAE,UAAU,YAAY,MAAM,QAAQ,OAAO,SAAS,OAAO,iBAAiB;AAkBtI,IAAM,iBAAiB;AAGvB,SAAS,eAAe,OAAiD,OAAe;AACtF,QAAM,CAAC,QAAQ,SAAS,IAAU,eAAS,CAAC;AAC5C,QAAM,SAAS,wBAAwB;AACvC,QAAM,KAAK,CAAC,OAAe;AACzB,UAAM,KAAK,MAAM;AACjB,QAAI,CAAC,GAAI,QAAO;AAChB,UAAM,OAAO,KAAK,IAAI,QAAQ,GAAG,KAAK,IAAI,GAAG,EAAE,CAAC;AAChD,OAAG,SAAS,EAAE,MAAM,QAAQ,GAAG,cAAc,QAAQ,UAAU,SAAS,SAAS,SAAS,CAAC;AAC3F,cAAU,IAAI;AACd,WAAO;AAAA,EACT;AACA,SAAO,EAAE,QAAQ,GAAG;AACtB;AAGA,SAAS,SAAS,MAA+B;AAC/C,QAAM,OAAa,aAAsB,IAAI;AAC7C,SAAO;AAAA,IACL,eAAe,CAAC,UAA8B;AAC5C,WAAK,UAAU,MAAM;AAAA,IACvB;AAAA,IACA,aAAa,CAAC,UAA8B;AAC1C,YAAM,QAAQ,KAAK;AACnB,WAAK,UAAU;AACf,UAAI,UAAU,KAAM;AACpB,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;AAAA,QAAI,OAAO;AAAA,SAAO;AAAA,MAC7E,qBAAC,SAAI,KAAK,SAAS,MAAK,WAAU,oBAAiB,cAAa,WAAW,EAAE,QAAQ,GAAG,WAAW,MACjG;AAAA,4BAAC,cAAW,SAAQ,aAAY,OAAO,OAAO,UAAU,UAAU,WAAW,GAAG,SAAS,MAAM,KAAK,EAAE,GACpG,8BAAC,gBAAa,WAAU,QAAO,WAAU,WAAU,GACrD;AAAA,QACA,oBAAC,cAAW,SAAQ,aAAY,OAAO,OAAO,MAAM,UAAU,WAAW,OAAO,SAAS,GAAG,SAAS,MAAM,KAAK,CAAC,GAC/G,8BAAC,gBAAa,WAAU,SAAQ,WAAU,WAAU,GACtD;AAAA,SACF;AAAA,OACF;AAAA,KAEF;AAEJ;","names":[]}
|
package/dist/media-player.d.ts
CHANGED
|
@@ -113,6 +113,7 @@ declare const mediaPlayer: tailwind_variants.TVReturnType<{
|
|
|
113
113
|
[key: string]: {
|
|
114
114
|
[key: string]: tailwind_variants.ClassValue | {
|
|
115
115
|
caption?: tailwind_variants.ClassValue;
|
|
116
|
+
frame?: tailwind_variants.ClassValue;
|
|
116
117
|
image?: tailwind_variants.ClassValue;
|
|
117
118
|
poster?: tailwind_variants.ClassValue;
|
|
118
119
|
play?: tailwind_variants.ClassValue;
|
|
@@ -122,12 +123,14 @@ declare const mediaPlayer: tailwind_variants.TVReturnType<{
|
|
|
122
123
|
[x: string]: {
|
|
123
124
|
[x: string]: tailwind_variants.ClassValue | {
|
|
124
125
|
caption?: tailwind_variants.ClassValue;
|
|
126
|
+
frame?: tailwind_variants.ClassValue;
|
|
125
127
|
image?: tailwind_variants.ClassValue;
|
|
126
128
|
poster?: tailwind_variants.ClassValue;
|
|
127
129
|
play?: tailwind_variants.ClassValue;
|
|
128
130
|
};
|
|
129
131
|
};
|
|
130
132
|
} | {}, {
|
|
133
|
+
frame: string;
|
|
131
134
|
poster: string;
|
|
132
135
|
image: string;
|
|
133
136
|
play: string;
|
|
@@ -136,17 +139,20 @@ declare const mediaPlayer: tailwind_variants.TVReturnType<{
|
|
|
136
139
|
[key: string]: {
|
|
137
140
|
[key: string]: tailwind_variants.ClassValue | {
|
|
138
141
|
caption?: tailwind_variants.ClassValue;
|
|
142
|
+
frame?: tailwind_variants.ClassValue;
|
|
139
143
|
image?: tailwind_variants.ClassValue;
|
|
140
144
|
poster?: tailwind_variants.ClassValue;
|
|
141
145
|
play?: tailwind_variants.ClassValue;
|
|
142
146
|
};
|
|
143
147
|
};
|
|
144
148
|
} | {}, {
|
|
149
|
+
frame: string;
|
|
145
150
|
poster: string;
|
|
146
151
|
image: string;
|
|
147
152
|
play: string;
|
|
148
153
|
caption: string;
|
|
149
154
|
}, tailwind_variants.TVReturnTypeLike<unknown, {
|
|
155
|
+
frame: string;
|
|
150
156
|
poster: string;
|
|
151
157
|
image: string;
|
|
152
158
|
play: string;
|
|
@@ -155,8 +161,10 @@ declare const mediaPlayer: tailwind_variants.TVReturnType<{
|
|
|
155
161
|
type MediaPlayerProps = Pick<VideoPlayerProps, "src" | "poster" | "title" | "tracks" | "loadHls" | "labels" | "onPlay" | "onPause" | "onEnded" | "onError"> & {
|
|
156
162
|
/** `inline`: the player itself. `lightbox`: a poster that opens it in a dialog. Default `inline`. */
|
|
157
163
|
mode?: "inline" | "lightbox";
|
|
158
|
-
/** `9 / 16` frame for a vertical film; default `16 / 9`. */
|
|
164
|
+
/** `9 / 16` frame and the narrow dialog for a vertical film; default `16 / 9`. */
|
|
159
165
|
vertical?: boolean;
|
|
166
|
+
/** Any frame ratio (`19 / 16`, `4 / 3`): wins over the frame of `vertical` (give both for a portrait ratio: `vertical ratio="3 / 4"`). Default `16 / 9` (`9 / 16` when `vertical`). */
|
|
167
|
+
ratio?: string;
|
|
160
168
|
/** The poster's words in the lightbox ("Play the film"), passed translated. Required for `lightbox`. */
|
|
161
169
|
playLabel?: string;
|
|
162
170
|
/** The close button's words, passed translated. Default `Close`. */
|
|
@@ -165,13 +173,19 @@ type MediaPlayerProps = Pick<VideoPlayerProps, "src" | "poster" | "title" | "tra
|
|
|
165
173
|
posterAlt?: string;
|
|
166
174
|
/** A line over the foot of the poster (« Fig. 1a »). */
|
|
167
175
|
caption?: string;
|
|
176
|
+
/** Lightbox: drawn over the poster, under its press (the frame is `relative`): a `<PausableLoop>` of `@krizaka/ui/pausable-loop` previews the film with a muted loop. */
|
|
177
|
+
preview?: React.ReactNode;
|
|
178
|
+
/** Lightbox: opens or closes it from outside (controlled). With it, `onOpenChange` is how the lightbox asks to close. */
|
|
179
|
+
open?: boolean;
|
|
180
|
+
/** Lightbox: replaces the poster with your own opener (`(open) => <button onClick={open}>…`); `null` draws nothing, for a lightbox driven by `open` alone. */
|
|
181
|
+
trigger?: ((open: () => void) => React.ReactNode) | null;
|
|
168
182
|
/** Called when the lightbox opens or closes. */
|
|
169
183
|
onOpenChange?: (open: boolean) => void;
|
|
170
184
|
/** Classes merged on the player or the poster. */
|
|
171
185
|
className?: string;
|
|
172
186
|
};
|
|
173
187
|
/** A video in one frame: inline, in a lightbox (a press opens it with sound), 16:9 or vertical. */
|
|
174
|
-
declare function MediaPlayer({ mode, vertical, playLabel, closeLabel, posterAlt, caption, onOpenChange, className, ...player }: MediaPlayerProps): React.JSX.Element;
|
|
188
|
+
declare function MediaPlayer({ mode, vertical, playLabel, closeLabel, posterAlt, caption, preview, open: given, trigger, onOpenChange, ratio: freeRatio, className, ...player }: MediaPlayerProps): React.JSX.Element;
|
|
175
189
|
|
|
176
190
|
export { MediaPlayer, mediaPlayer };
|
|
177
191
|
export type { MediaPlayerProps };
|
package/dist/media-player.js
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type LoopSources = {
|
|
4
|
+
webm?: string;
|
|
5
|
+
mp4?: string;
|
|
6
|
+
};
|
|
7
|
+
type LoopLabels = {
|
|
8
|
+
pause: string;
|
|
9
|
+
play: string;
|
|
10
|
+
};
|
|
11
|
+
type PausableLoopProps = {
|
|
12
|
+
/** The loop's files; `mp4` and / or `webm`. */
|
|
13
|
+
sources: LoopSources;
|
|
14
|
+
/** The still under the loop, shown first and kept under reduced motion or Save-Data. */
|
|
15
|
+
poster: string;
|
|
16
|
+
/** Plays only while `true` (e.g. the slide in view). Default `true`. */
|
|
17
|
+
active?: boolean;
|
|
18
|
+
/** The pause / play words, passed translated. English by default. */
|
|
19
|
+
labels?: LoopLabels;
|
|
20
|
+
/** Classes of the `<video>`; default fills its frame, cropped. */
|
|
21
|
+
className?: string;
|
|
22
|
+
};
|
|
23
|
+
/** A muted, silent loop over a still, with a visible pause / play. Drop it into a frame that is `relative`: `MediaPlayer`'s `preview`, `MediaCarousel`'s `renderLoop`. */
|
|
24
|
+
declare function PausableLoop({ sources, poster, active, labels, className }: Readonly<PausableLoopProps>): React.JSX.Element;
|
|
25
|
+
|
|
26
|
+
export { PausableLoop };
|
|
27
|
+
export type { LoopLabels, LoopSources, PausableLoopProps };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
playSafely,
|
|
4
|
+
useInView,
|
|
5
|
+
usePrefersReducedMotion
|
|
6
|
+
} from "./chunk-TN5JJ6JI.js";
|
|
7
|
+
import {
|
|
8
|
+
PauseGlyph,
|
|
9
|
+
PlayGlyph
|
|
10
|
+
} from "./chunk-S2O4NSN5.js";
|
|
11
|
+
import {
|
|
12
|
+
cn
|
|
13
|
+
} from "./chunk-NSLXEDIS.js";
|
|
14
|
+
|
|
15
|
+
// src/media-gallery/pausable-loop.tsx
|
|
16
|
+
import * as React from "react";
|
|
17
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
18
|
+
var loopLabels = { pause: "Pause the animation", play: "Play the animation" };
|
|
19
|
+
var subscribeLoad = (notify) => {
|
|
20
|
+
window.addEventListener("load", notify);
|
|
21
|
+
return () => window.removeEventListener("load", notify);
|
|
22
|
+
};
|
|
23
|
+
function usePageLoaded() {
|
|
24
|
+
return React.useSyncExternalStore(subscribeLoad, () => document.readyState === "complete", () => false);
|
|
25
|
+
}
|
|
26
|
+
function useCalm() {
|
|
27
|
+
const reduce = usePrefersReducedMotion();
|
|
28
|
+
return reduce || typeof navigator !== "undefined" && Boolean(navigator.connection?.saveData);
|
|
29
|
+
}
|
|
30
|
+
function PausableLoop({ sources, poster, active = true, labels = loopLabels, className = "absolute inset-0 h-full w-full object-cover" }) {
|
|
31
|
+
const calm = useCalm();
|
|
32
|
+
const loaded = usePageLoaded();
|
|
33
|
+
const mounted = !calm && loaded;
|
|
34
|
+
const holder = React.useRef(null);
|
|
35
|
+
const video = React.useRef(null);
|
|
36
|
+
const [onScreen, setOnScreen] = React.useState(() => typeof IntersectionObserver === "undefined");
|
|
37
|
+
const [paused, setPaused] = React.useState(false);
|
|
38
|
+
useInView(holder, setOnScreen, mounted);
|
|
39
|
+
const playing = mounted && onScreen && active && !paused;
|
|
40
|
+
React.useEffect(() => {
|
|
41
|
+
if (!video.current) return;
|
|
42
|
+
if (playing) playSafely(video.current);
|
|
43
|
+
else video.current.pause?.();
|
|
44
|
+
}, [playing]);
|
|
45
|
+
const Glyph = paused ? PlayGlyph : PauseGlyph;
|
|
46
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
47
|
+
/* @__PURE__ */ jsx("div", { ref: holder, className: "absolute inset-0", children: mounted && /* @__PURE__ */ jsxs("video", { ref: video, className, poster, muted: true, loop: true, playsInline: true, preload: "metadata", "aria-hidden": true, tabIndex: -1, children: [
|
|
48
|
+
sources.webm && /* @__PURE__ */ jsx("source", { src: sources.webm, type: "video/webm" }),
|
|
49
|
+
sources.mp4 && /* @__PURE__ */ jsx("source", { src: sources.mp4, type: "video/mp4" })
|
|
50
|
+
] }) }),
|
|
51
|
+
!calm && /* @__PURE__ */ jsx(
|
|
52
|
+
"button",
|
|
53
|
+
{
|
|
54
|
+
type: "button",
|
|
55
|
+
"aria-label": paused ? labels.play : labels.pause,
|
|
56
|
+
onClick: () => setPaused((p) => !p),
|
|
57
|
+
className: cn(
|
|
58
|
+
"absolute right-2 top-2 z-10 flex h-9 w-9 items-center justify-center rounded-full bg-scrim-strong text-fg-on-media transition-colors hover:bg-scrim focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring motion-reduce:transition-none"
|
|
59
|
+
),
|
|
60
|
+
children: /* @__PURE__ */ jsx(Glyph, { className: "h-4 w-4" })
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
] });
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
PausableLoop
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=pausable-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/media-gallery/pausable-loop.tsx"],"sourcesContent":["// @krizaka/ui/pausable-loop. Client (the page's load, the viewport, the reader's motion and data preferences). A muted, silent loop that previews a still or a\n// film: poster first, nothing fetched before the page's `load`, playing only while on screen, with a visible pause / play\n// control (WCAG 2.2.2). Under reduced motion or Save-Data the poster stays alone and there is nothing to pause.\nimport * as React from \"react\";\n\nimport { cn } from \"../cn\";\nimport { PauseGlyph, PlayGlyph } from \"../glyphs\";\nimport { playSafely, useInView, usePrefersReducedMotion } from \"../media\";\n\nexport type LoopSources = { webm?: string; mp4?: string };\nexport type LoopLabels = { pause: string; play: string };\nexport const loopLabels: LoopLabels = { pause: \"Pause the animation\", play: \"Play the animation\" };\n\nconst subscribeLoad = (notify: () => void) => {\n window.addEventListener(\"load\", notify);\n return () => window.removeEventListener(\"load\", notify);\n};\n/** `true` once the page has finished loading: a loop is not worth bytes before it. */\nfunction usePageLoaded(): boolean {\n return React.useSyncExternalStore(subscribeLoad, () => document.readyState === \"complete\", () => false);\n}\n\ntype SaveDataNavigator = Navigator & { connection?: { saveData?: boolean } };\n/** `true` when the person asked for less motion or less data: a loop stays a poster. */\nfunction useCalm(): boolean {\n const reduce = usePrefersReducedMotion();\n return reduce || (typeof navigator !== \"undefined\" && Boolean((navigator as SaveDataNavigator).connection?.saveData));\n}\n\nexport type PausableLoopProps = {\n /** The loop's files; `mp4` and / or `webm`. */\n sources: LoopSources;\n /** The still under the loop, shown first and kept under reduced motion or Save-Data. */\n poster: string;\n /** Plays only while `true` (e.g. the slide in view). Default `true`. */\n active?: boolean;\n /** The pause / play words, passed translated. English by default. */\n labels?: LoopLabels;\n /** Classes of the `<video>`; default fills its frame, cropped. */\n className?: string;\n};\n\n/** A muted, silent loop over a still, with a visible pause / play. Drop it into a frame that is `relative`: `MediaPlayer`'s `preview`, `MediaCarousel`'s `renderLoop`. */\nexport function PausableLoop({ sources, poster, active = true, labels = loopLabels, className = \"absolute inset-0 h-full w-full object-cover\" }: Readonly<PausableLoopProps>) {\n const calm = useCalm();\n const loaded = usePageLoaded();\n const mounted = !calm && loaded;\n const holder = React.useRef<HTMLDivElement>(null);\n const video = React.useRef<HTMLVideoElement>(null);\n const [onScreen, setOnScreen] = React.useState(() => typeof IntersectionObserver === \"undefined\");\n const [paused, setPaused] = React.useState(false);\n useInView(holder, setOnScreen, mounted);\n const playing = mounted && onScreen && active && !paused;\n React.useEffect(() => {\n if (!video.current) return;\n if (playing) playSafely(video.current);\n else video.current.pause?.();\n }, [playing]);\n const Glyph = paused ? PlayGlyph : PauseGlyph;\n return (\n <>\n <div ref={holder} className=\"absolute inset-0\">\n {mounted && (\n <video ref={video} className={className} poster={poster} muted loop playsInline preload=\"metadata\" aria-hidden tabIndex={-1}>\n {sources.webm && <source src={sources.webm} type=\"video/webm\" />}\n {sources.mp4 && <source src={sources.mp4} type=\"video/mp4\" />}\n </video>\n )}\n </div>\n {!calm && (\n <button\n type=\"button\"\n aria-label={paused ? labels.play : labels.pause}\n onClick={() => setPaused((p) => !p)}\n className={cn(\n \"absolute right-2 top-2 z-10 flex h-9 w-9 items-center justify-center rounded-full bg-scrim-strong text-fg-on-media transition-colors hover:bg-scrim \" +\n \"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring motion-re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WAAsB,QAAgB,OAAK,MAAC,MAAI,MAAC,aAAW,MAAC,SAAQ,YAAW,eAAW,MAAC,UAAU,IACtH;AAAA,cAAQ,QAAQ,oBAAC,YAAO,KAAK,QAAQ,MAAM,MAAK,cAAa;AAAA,MAC7D,QAAQ,OAAO,oBAAC,YAAO,KAAK,QAAQ,KAAK,MAAK,aAAY;AAAA,OAC7D,GAEJ;AAAA,IACC,CAAC,QACA;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,cAAY,SAAS,OAAO,OAAO,OAAO;AAAA,QAC1C,SAAS,MAAM,UAAU,CAAC,MAAM,CAAC,CAAC;AAAA,QAClC,WAAW;AAAA,UACT;AAAA,QAEF;AAAA,QAEA,8BAAC,SAAM,WAAU,WAAU;AAAA;AAAA,IAC7B;AAAA,KAEJ;AAEJ;","names":[]}
|
|
@@ -5,7 +5,9 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
VideoPlayer
|
|
7
7
|
} from "./chunk-VYZFQE3P.js";
|
|
8
|
-
import
|
|
8
|
+
import {
|
|
9
|
+
usePrefersReducedMotion
|
|
10
|
+
} from "./chunk-TN5JJ6JI.js";
|
|
9
11
|
import "./chunk-S2O4NSN5.js";
|
|
10
12
|
import "./chunk-NSLXEDIS.js";
|
|
11
13
|
|
|
@@ -137,12 +139,13 @@ var Dialog = {
|
|
|
137
139
|
// src/media-gallery/player-lightbox.tsx
|
|
138
140
|
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
139
141
|
function PlayerLightbox({ player, ratio, vertical, closeLabel, onClose }) {
|
|
142
|
+
const calm = usePrefersReducedMotion();
|
|
140
143
|
return /* @__PURE__ */ jsx2(Dialog.Root, { open: true, onOpenChange: (open) => !open && onClose(), children: /* @__PURE__ */ jsxs2(Dialog.Content, { size: vertical ? "sm" : "lg", closeLabel, className: "bg-media p-0", children: [
|
|
141
144
|
/* @__PURE__ */ jsx2(Dialog.Title, { className: "sr-only", children: player.title }),
|
|
142
|
-
/* @__PURE__ */ jsx2(VideoPlayer, { ...player, aspectRatio: ratio, playOnMount:
|
|
145
|
+
/* @__PURE__ */ jsx2(VideoPlayer, { ...player, aspectRatio: ratio, playOnMount: !calm, pauseWhenHidden: false })
|
|
143
146
|
] }) });
|
|
144
147
|
}
|
|
145
148
|
export {
|
|
146
149
|
PlayerLightbox as default
|
|
147
150
|
};
|
|
148
|
-
//# sourceMappingURL=player-lightbox-
|
|
151
|
+
//# sourceMappingURL=player-lightbox-ASFOSUSD.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/dialog/dialog.tsx","../src/dialog/return-focus.ts","../src/media-gallery/player-lightbox.tsx"],"sourcesContent":["// Client (a portal). Radix does the focus trap, the scroll lock, Escape, the outside click, aria-modal, the\n// aria-labelledby / aria-describedby wiring and the focus return: this file only holds the shape.\nimport { Dialog as DialogPrimitive } from \"radix-ui\";\nimport type * as React from \"react\";\nimport { tv, type VariantProps } from \"tailwind-variants\";\n\nimport { IconButton } from \"../button/button\";\nimport { useReturnFocus } from \"./return-focus\";\n\nexport const dialog = tv({\n slots: {\n overlay: \"kz-overlay fixed inset-0 z-50 bg-overlay\",\n content:\n \"kz-dialog fixed z-50 flex flex-col overflow-hidden border border-border-default bg-surface-1 text-fg shadow-lg focus:outline-hidden\",\n close: \"absolute right-3 top-3 h-9 w-9\",\n header: \"flex flex-col gap-1 px-5 pb-2 pr-14 pt-5\",\n title: \"text-base font-bold text-fg\",\n description: \"text-sm text-fg-secondary\",\n body: \"min-h-0 flex-1 overflow-y-auto px-5 pb-5\",\n footer:\n \"flex flex-wrap items-center justify-end gap-2 border-t border-border-subtle px-5 py-4 pb-[max(1rem,env(safe-area-inset-bottom))]\",\n },\n variants: {\n placement: {\n center: { content: \"left-1/2 top-1/2 max-h-[85dvh] w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 rounded-xl\" },\n /* A sheet: anchored at the bottom on a phone, centred from `sm` up. */\n bottom: {\n content:\n \"inset-x-0 bottom-0 max-h-[92dvh] rounded-t-[1.75rem] sm:bottom-auto sm:left-1/2 sm:top-1/2 sm:w-full \" +\n \"sm:-translate-x-1/2 sm:-translate-y-1/2 sm:rounded-[1.75rem]\",\n },\n right: { content: \"inset-y-0 right-0 h-full w-full max-w-md rounded-none border-y-0 border-r-0\" },\n /* A navigation drawer: full height, from the left, clear of the notch. */\n left: { content: \"inset-y-0 left-0 h-full w-full max-w-md rounded-none border-y-0 border-l-0 pl-[env(safe-area-inset-left)]\" },\n },\n size: { sm: { content: \"sm:max-w-sm\" }, md: { content: \"sm:max-w-md\" }, lg: { content: \"sm:max-w-2xl\" } },\n },\n defaultVariants: { placement: \"center\", size: \"md\" },\n});\nconst s = dialog();\n\nexport type DialogVariants = VariantProps<typeof dialog>;\n\nfunction CloseIcon() {\n return (\n <svg viewBox=\"0 0 24 24\" className=\"h-4 w-4\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden>\n <path d=\"M18 6 6 18M6 6l12 12\" />\n </svg>\n );\n}\n\ntype CloseButtonProps =\n | {\n /** The accessible name of the close button — passed translated. */\n closeLabel: string;\n /** Leaves the close button out (the content brings its own way out, or none: see `dismissible`). */\n hideClose?: false;\n }\n | { closeLabel?: string; hideClose: true };\n\nexport type DialogContentProps = React.ComponentProps<typeof DialogPrimitive.Content> &\n DialogVariants &\n CloseButtonProps & {\n /**\n * center · bottom (a sheet on a phone, centred from `sm` up) · right (a side panel, full height) · left (a\n * navigation drawer, full height).\n * @default \"center\"\n */\n placement?: DialogVariants[\"placement\"];\n /**\n * sm · md · lg: the width of the dialog.\n * @default \"md\"\n */\n size?: DialogVariants[\"size\"];\n /**\n * `false`: Escape and a click outside do not close it (a gate the user must answer: age, terms). It still closes\n * through `open` / `onOpenChange` and any `Dialog.Close` inside. Default `true`.\n */\n dismissible?: boolean;\n /** The element the portal renders into (default: document.body). */\n container?: HTMLElement | null;\n };\n\nconst prevent = (event: Event) => event.preventDefault();\n\n/** Radix's content, mounted only while open: it remembers the opener then and gives focus back on close (WCAG 2.4.3). */\nfunction ReturnFocusContent({ onCloseAutoFocus, ...props }: React.ComponentProps<typeof DialogPrimitive.Content>) {\n return <DialogPrimitive.Content onCloseAutoFocus={useReturnFocus(onCloseAutoFocus)} {...props} />;\n}\n\n/** The dialog itself, portalled over a dimmed overlay, with a close button. Give it a `Dialog.Title`. */\nexport function DialogContent({\n placement,\n size,\n closeLabel,\n hideClose,\n dismissible = true,\n container,\n className,\n children,\n onEscapeKeyDown,\n onPointerDownOutside,\n onInteractOutside,\n ...props\n}: DialogContentProps) {\n const v = dialog({ placement, size });\n return (\n <DialogPrimitive.Portal container={container}>\n <DialogPrimitive.Overlay className={v.overlay()} />\n <ReturnFocusContent\n data-placement={placement ?? \"center\"}\n data-dismissible={dismissible ? undefined : \"false\"}\n className={v.content({ className })}\n onEscapeKeyDown={dismissible ? onEscapeKeyDown : chain(onEscapeKeyDown, prevent)}\n onPointerDownOutside={dismissible ? onPointerDownOutside : chain(onPointerDownOutside, prevent)}\n onInteractOutside={dismissible ? onInteractOutside : chain(onInteractOutside, prevent)}\n {...props}\n >\n {children}\n {!hideClose && (\n <DialogPrimitive.Close asChild>\n <IconButton label={closeLabel as string} variant=\"ghost\" shape=\"pill\" className={v.close()}>\n <CloseIcon />\n </IconButton>\n </DialogPrimitive.Close>\n )}\n </ReturnFocusContent>\n </DialogPrimitive.Portal>\n );\n}\n\nfunction chain<E extends Event>(handler: ((event: E) => void) | undefined, then: (event: E) => void) {\n return (event: E) => {\n handler?.(event);\n then(event);\n };\n}\n\nexport function DialogHeader({ className, ...props }: React.ComponentProps<\"div\">) {\n return <div className={s.header({ className })} {...props} />;\n}\n\nexport function DialogTitle({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Title>) {\n return <DialogPrimitive.Title className={s.title({ className })} {...props} />;\n}\n\nexport function DialogDescription({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Description>) {\n return <DialogPrimitive.Description className={s.description({ className })} {...props} />;\n}\n\nexport function DialogBody({ className, ...props }: React.ComponentProps<\"div\">) {\n return <div className={s.body({ className })} {...props} />;\n}\n\nexport function DialogFooter({ className, ...props }: React.ComponentProps<\"div\">) {\n return <div className={s.footer({ className })} {...props} />;\n}\n\n/** `Dialog.Root/Trigger/Content/Header/Title/Description/Body/Footer/Close`. `open`/`defaultOpen` + `onOpenChange`. */\nexport const Dialog = {\n Root: DialogPrimitive.Root,\n Trigger: DialogPrimitive.Trigger,\n Close: DialogPrimitive.Close,\n Content: DialogContent,\n Header: DialogHeader,\n Title: DialogTitle,\n Description: DialogDescription,\n Body: DialogBody,\n Footer: DialogFooter,\n};\n\n/** `Omit` that keeps the close-button union (`closeLabel` required unless `hideClose`). */\ntype DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;\n\nexport type SheetProps = DistributiveOmit<DialogContentProps, \"placement\">;\n\n/** A sheet is a dialog anchored at the bottom (centred from `sm` up): `Dialog.Content placement=\"bottom\"`. */\nexport function Sheet(props: SheetProps) {\n return <DialogContent placement=\"bottom\" {...props} />;\n}\n","// Client. WCAG 2.4.3: when a dialog closes, focus goes back to what opened it. Radix only does it for `Dialog.Trigger`;\n// most app dialogs are controlled (`open` / `onOpenChange`) and opened by a plain button, so on Escape focus fell to\n// <body>. The content remembers the focused element when it mounts (it is still the opener: Radix moves focus in an\n// effect) and gives it back on close, unless the consumer's `onCloseAutoFocus` prevented the default.\nimport * as React from \"react\";\n\n/** The handler for `onCloseAutoFocus`: yours first, then focus back on the opener if it is still on the page. */\nexport function useReturnFocus(onCloseAutoFocus?: (event: Event) => void) {\n const [opener] = React.useState<Element | null>(() => (typeof document === \"undefined\" ? null : document.activeElement));\n return React.useCallback(\n (event: Event) => {\n onCloseAutoFocus?.(event);\n if (event.defaultPrevented) return;\n if (opener instanceof HTMLElement && opener !== document.body && opener.isConnected) {\n event.preventDefault();\n opener.focus();\n }\n },\n [opener, onCloseAutoFocus],\n );\n}\n","// Client. The lightbox's dialog and its player: loaded by `MediaPlayer` only when the poster is pressed.\nimport * as React from \"react\";\n\nimport { Dialog } from \"../dialog\";\nimport { VideoPlayer, type VideoPlayerProps } from \"../video-player\";\n\nexport type PlayerLightboxProps = {\n player: Omit<VideoPlayerProps, \"aspectRatio\" | \"className\">;\n ratio: string;\n vertical: boolean;\n closeLabel: string;\n onClose: () => void;\n};\n\n/** The open dialog holding the player, started by the press that opened it. */\nexport default function PlayerLightbox({ player, ratio, vertical, closeLabel, onClose }: Readonly<PlayerLightboxProps>) {\n return (\n <Dialog.Root open onOpenChange={(open) => !open && onClose()}>\n <Dialog.Content size={vertical ? \"sm\" : \"lg\"} closeLabel={closeLabel} className=\"bg-media p-0\">\n <Dialog.Title className=\"sr-only\">{player.title}</Dialog.Title>\n <VideoPlayer {...player} aspectRatio={ratio} playOnMount pauseWhenHidden={false} />\n </Dialog.Content>\n </Dialog.Root>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAEA,SAAS,UAAU,uBAAuB;AAE1C,SAAS,UAA6B;;;ACAtC,YAAY,WAAW;AAGhB,SAAS,eAAe,kBAA2C;AACxE,QAAM,CAAC,MAAM,IAAU,eAAyB,MAAO,OAAO,aAAa,cAAc,OAAO,SAAS,aAAc;AACvH,SAAa;AAAA,IACX,CAAC,UAAiB;AAChB,yBAAmB,KAAK;AACxB,UAAI,MAAM,iBAAkB;AAC5B,UAAI,kBAAkB,eAAe,WAAW,SAAS,QAAQ,OAAO,aAAa;AACnF,cAAM,eAAe;AACrB,eAAO,MAAM;AAAA,MACf;AAAA,IACF;AAAA,IACA,CAAC,QAAQ,gBAAgB;AAAA,EAC3B;AACF;;;AD0BM,cA+DA,YA/DA;AArCC,IAAM,SAAS,GAAG;AAAA,EACvB,OAAO;AAAA,IACL,SAAS;AAAA,IACT,SACE;AAAA,IACF,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAM;AAAA,IACN,Q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,EAAE,OAAO,EAAE,UAAU,CAAC,GAAI,GAAG,OAAO;AAC7D;AAGO,IAAM,SAAS;AAAA,EACpB,MAAM,gBAAgB;AAAA,EACtB,SAAS,gBAAgB;AAAA,EACzB,OAAO,gBAAgB;AAAA,EACvB,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,aAAa;AAAA,EACb,MAAM;AAAA,EACN,QAAQ;AACV;;;AEvJM,SACE,OAAAA,MADF,QAAAC,aAAA;AAHS,SAAR,eAAgC,EAAE,QAAQ,OAAO,UAAU,YAAY,QAAQ,GAAkC;AACtH,SACE,gBAAAD,KAAC,OAAO,MAAP,EAAY,MAAI,MAAC,cAAc,CAAC,SAAS,CAAC,QAAQ,QAAQ,GACzD,0BAAAC,MAAC,OAAO,SAAP,EAAe,MAAM,WAAW,OAAO,MAAM,YAAwB,WAAU,gBAC9E;AAAA,oBAAAD,KAAC,OAAO,OAAP,EAAa,WAAU,WAAW,iBAAO,OAAM;AAAA,IAChD,gBAAAA,KAAC,eAAa,GAAG,QAAQ,aAAa,OAAO,aAAW,MAAC,iBAAiB,OAAO;AAAA,KACnF,GACF;AAEJ;","names":["jsx","jsxs"]}
|
|
1
|
+
{"version":3,"sources":["../src/dialog/dialog.tsx","../src/dialog/return-focus.ts","../src/media-gallery/player-lightbox.tsx"],"sourcesContent":["// Client (a portal). Radix does the focus trap, the scroll lock, Escape, the outside click, aria-modal, the\n// aria-labelledby / aria-describedby wiring and the focus return: this file only holds the shape.\nimport { Dialog as DialogPrimitive } from \"radix-ui\";\nimport type * as React from \"react\";\nimport { tv, type VariantProps } from \"tailwind-variants\";\n\nimport { IconButton } from \"../button/button\";\nimport { useReturnFocus } from \"./return-focus\";\n\nexport const dialog = tv({\n slots: {\n overlay: \"kz-overlay fixed inset-0 z-50 bg-overlay\",\n content:\n \"kz-dialog fixed z-50 flex flex-col overflow-hidden border border-border-default bg-surface-1 text-fg shadow-lg focus:outline-hidden\",\n close: \"absolute right-3 top-3 h-9 w-9\",\n header: \"flex flex-col gap-1 px-5 pb-2 pr-14 pt-5\",\n title: \"text-base font-bold text-fg\",\n description: \"text-sm text-fg-secondary\",\n body: \"min-h-0 flex-1 overflow-y-auto px-5 pb-5\",\n footer:\n \"flex flex-wrap items-center justify-end gap-2 border-t border-border-subtle px-5 py-4 pb-[max(1rem,env(safe-area-inset-bottom))]\",\n },\n variants: {\n placement: {\n center: { content: \"left-1/2 top-1/2 max-h-[85dvh] w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 rounded-xl\" },\n /* A sheet: anchored at the bottom on a phone, centred from `sm` up. */\n bottom: {\n content:\n \"inset-x-0 bottom-0 max-h-[92dvh] rounded-t-[1.75rem] sm:bottom-auto sm:left-1/2 sm:top-1/2 sm:w-full \" +\n \"sm:-translate-x-1/2 sm:-translate-y-1/2 sm:rounded-[1.75rem]\",\n },\n right: { content: \"inset-y-0 right-0 h-full w-full max-w-md rounded-none border-y-0 border-r-0\" },\n /* A navigation drawer: full height, from the left, clear of the notch. */\n left: { content: \"inset-y-0 left-0 h-full w-full max-w-md rounded-none border-y-0 border-l-0 pl-[env(safe-area-inset-left)]\" },\n },\n size: { sm: { content: \"sm:max-w-sm\" }, md: { content: \"sm:max-w-md\" }, lg: { content: \"sm:max-w-2xl\" } },\n },\n defaultVariants: { placement: \"center\", size: \"md\" },\n});\nconst s = dialog();\n\nexport type DialogVariants = VariantProps<typeof dialog>;\n\nfunction CloseIcon() {\n return (\n <svg viewBox=\"0 0 24 24\" className=\"h-4 w-4\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden>\n <path d=\"M18 6 6 18M6 6l12 12\" />\n </svg>\n );\n}\n\ntype CloseButtonProps =\n | {\n /** The accessible name of the close button — passed translated. */\n closeLabel: string;\n /** Leaves the close button out (the content brings its own way out, or none: see `dismissible`). */\n hideClose?: false;\n }\n | { closeLabel?: string; hideClose: true };\n\nexport type DialogContentProps = React.ComponentProps<typeof DialogPrimitive.Content> &\n DialogVariants &\n CloseButtonProps & {\n /**\n * center · bottom (a sheet on a phone, centred from `sm` up) · right (a side panel, full height) · left (a\n * navigation drawer, full height).\n * @default \"center\"\n */\n placement?: DialogVariants[\"placement\"];\n /**\n * sm · md · lg: the width of the dialog.\n * @default \"md\"\n */\n size?: DialogVariants[\"size\"];\n /**\n * `false`: Escape and a click outside do not close it (a gate the user must answer: age, terms). It still closes\n * through `open` / `onOpenChange` and any `Dialog.Close` inside. Default `true`.\n */\n dismissible?: boolean;\n /** The element the portal renders into (default: document.body). */\n container?: HTMLElement | null;\n };\n\nconst prevent = (event: Event) => event.preventDefault();\n\n/** Radix's content, mounted only while open: it remembers the opener then and gives focus back on close (WCAG 2.4.3). */\nfunction ReturnFocusContent({ onCloseAutoFocus, ...props }: React.ComponentProps<typeof DialogPrimitive.Content>) {\n return <DialogPrimitive.Content onCloseAutoFocus={useReturnFocus(onCloseAutoFocus)} {...props} />;\n}\n\n/** The dialog itself, portalled over a dimmed overlay, with a close button. Give it a `Dialog.Title`. */\nexport function DialogContent({\n placement,\n size,\n closeLabel,\n hideClose,\n dismissible = true,\n container,\n className,\n children,\n onEscapeKeyDown,\n onPointerDownOutside,\n onInteractOutside,\n ...props\n}: DialogContentProps) {\n const v = dialog({ placement, size });\n return (\n <DialogPrimitive.Portal container={container}>\n <DialogPrimitive.Overlay className={v.overlay()} />\n <ReturnFocusContent\n data-placement={placement ?? \"center\"}\n data-dismissible={dismissible ? undefined : \"false\"}\n className={v.content({ className })}\n onEscapeKeyDown={dismissible ? onEscapeKeyDown : chain(onEscapeKeyDown, prevent)}\n onPointerDownOutside={dismissible ? onPointerDownOutside : chain(onPointerDownOutside, prevent)}\n onInteractOutside={dismissible ? onInteractOutside : chain(onInteractOutside, prevent)}\n {...props}\n >\n {children}\n {!hideClose && (\n <DialogPrimitive.Close asChild>\n <IconButton label={closeLabel as string} variant=\"ghost\" shape=\"pill\" className={v.close()}>\n <CloseIcon />\n </IconButton>\n </DialogPrimitive.Close>\n )}\n </ReturnFocusContent>\n </DialogPrimitive.Portal>\n );\n}\n\nfunction chain<E extends Event>(handler: ((event: E) => void) | undefined, then: (event: E) => void) {\n return (event: E) => {\n handler?.(event);\n then(event);\n };\n}\n\nexport function DialogHeader({ className, ...props }: React.ComponentProps<\"div\">) {\n return <div className={s.header({ className })} {...props} />;\n}\n\nexport function DialogTitle({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Title>) {\n return <DialogPrimitive.Title className={s.title({ className })} {...props} />;\n}\n\nexport function DialogDescription({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Description>) {\n return <DialogPrimitive.Description className={s.description({ className })} {...props} />;\n}\n\nexport function DialogBody({ className, ...props }: React.ComponentProps<\"div\">) {\n return <div className={s.body({ className })} {...props} />;\n}\n\nexport function DialogFooter({ className, ...props }: React.ComponentProps<\"div\">) {\n return <div className={s.footer({ className })} {...props} />;\n}\n\n/** `Dialog.Root/Trigger/Content/Header/Title/Description/Body/Footer/Close`. `open`/`defaultOpen` + `onOpenChange`. */\nexport const Dialog = {\n Root: DialogPrimitive.Root,\n Trigger: DialogPrimitive.Trigger,\n Close: DialogPrimitive.Close,\n Content: DialogContent,\n Header: DialogHeader,\n Title: DialogTitle,\n Description: DialogDescription,\n Body: DialogBody,\n Footer: DialogFooter,\n};\n\n/** `Omit` that keeps the close-button union (`closeLabel` required unless `hideClose`). */\ntype DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;\n\nexport type SheetProps = DistributiveOmit<DialogContentProps, \"placement\">;\n\n/** A sheet is a dialog anchored at the bottom (centred from `sm` up): `Dialog.Content placement=\"bottom\"`. */\nexport function Sheet(props: SheetProps) {\n return <DialogContent placement=\"bottom\" {...props} />;\n}\n","// Client. WCAG 2.4.3: when a dialog closes, focus goes back to what opened it. Radix only does it for `Dialog.Trigger`;\n// most app dialogs are controlled (`open` / `onOpenChange`) and opened by a plain button, so on Escape focus fell to\n// <body>. The content remembers the focused element when it mounts (it is still the opener: Radix moves focus in an\n// effect) and gives it back on close, unless the consumer's `onCloseAutoFocus` prevented the default.\nimport * as React from \"react\";\n\n/** The handler for `onCloseAutoFocus`: yours first, then focus back on the opener if it is still on the page. */\nexport function useReturnFocus(onCloseAutoFocus?: (event: Event) => void) {\n const [opener] = React.useState<Element | null>(() => (typeof document === \"undefined\" ? null : document.activeElement));\n return React.useCallback(\n (event: Event) => {\n onCloseAutoFocus?.(event);\n if (event.defaultPrevented) return;\n if (opener instanceof HTMLElement && opener !== document.body && opener.isConnected) {\n event.preventDefault();\n opener.focus();\n }\n },\n [opener, onCloseAutoFocus],\n );\n}\n","// Client. The lightbox's dialog and its player: loaded by `MediaPlayer` only when the poster is pressed.\nimport * as React from \"react\";\n\nimport { Dialog } from \"../dialog\";\nimport { usePrefersReducedMotion } from \"../media\";\nimport { VideoPlayer, type VideoPlayerProps } from \"../video-player\";\n\nexport type PlayerLightboxProps = {\n player: Omit<VideoPlayerProps, \"aspectRatio\" | \"className\">;\n ratio: string;\n vertical: boolean;\n closeLabel: string;\n onClose: () => void;\n};\n\n/** The open dialog holding the player, started by the press that opened it, except under reduced motion: it waits on the poster. */\nexport default function PlayerLightbox({ player, ratio, vertical, closeLabel, onClose }: Readonly<PlayerLightboxProps>) {\n const calm = usePrefersReducedMotion();\n return (\n <Dialog.Root open onOpenChange={(open) => !open && onClose()}>\n <Dialog.Content size={vertical ? \"sm\" : \"lg\"} closeLabel={closeLabel} className=\"bg-media p-0\">\n <Dialog.Title className=\"sr-only\">{player.title}</Dialog.Title>\n <VideoPlayer {...player} aspectRatio={ratio} playOnMount={!calm} pauseWhenHidden={false} />\n </Dialog.Content>\n </Dialog.Root>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAEA,SAAS,UAAU,uBAAuB;AAE1C,SAAS,UAA6B;;;ACAtC,YAAY,WAAW;AAGhB,SAAS,eAAe,kBAA2C;AACxE,QAAM,CAAC,MAAM,IAAU,eAAyB,MAAO,OAAO,aAAa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