@sybilion/uilib 1.4.29 → 1.4.30
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.
|
@@ -20,6 +20,9 @@ function VimeoEmbed({ videoId, videoHash, gifMode = false, playButtonColor, clas
|
|
|
20
20
|
const playerRef = useRef(null);
|
|
21
21
|
const [isPlaying, setIsPlaying] = useState(false);
|
|
22
22
|
const [isPlayerReady, setIsPlayerReady] = useState(false);
|
|
23
|
+
// Intrinsic video aspect ratio (width / height) reported by the Vimeo SDK.
|
|
24
|
+
// Null until the player reports it; falls back to the CSS default meanwhile.
|
|
25
|
+
const [aspectRatio, setAspectRatio] = useState(null);
|
|
23
26
|
const parsed = parseVimeoUrl(videoId);
|
|
24
27
|
const id = parsed.id;
|
|
25
28
|
const hash = videoHash ?? parsed.hash;
|
|
@@ -31,6 +34,7 @@ function VimeoEmbed({ videoId, videoHash, gifMode = false, playButtonColor, clas
|
|
|
31
34
|
const embedUrl = `https://player.vimeo.com/video/${id}?${baseParams}&${gifParams}${hashParam}`;
|
|
32
35
|
// Cleanup player when id/hash changes
|
|
33
36
|
useEffect(() => {
|
|
37
|
+
setAspectRatio(null);
|
|
34
38
|
if (playerRef.current) {
|
|
35
39
|
playerRef.current
|
|
36
40
|
.destroy()
|
|
@@ -67,6 +71,17 @@ function VimeoEmbed({ videoId, videoHash, gifMode = false, playButtonColor, clas
|
|
|
67
71
|
.ready()
|
|
68
72
|
.then(() => {
|
|
69
73
|
setIsPlayerReady(true);
|
|
74
|
+
// Read the video's intrinsic dimensions so the container can adopt
|
|
75
|
+
// the exact aspect ratio — eliminates letterbox stripes from the
|
|
76
|
+
// hardcoded box ratio mismatching the source video.
|
|
77
|
+
Promise.all([player.getVideoWidth(), player.getVideoHeight()])
|
|
78
|
+
.then(([w, h]) => {
|
|
79
|
+
if (w > 0 && h > 0)
|
|
80
|
+
setAspectRatio(w / h);
|
|
81
|
+
})
|
|
82
|
+
.catch(() => {
|
|
83
|
+
// Ignore dimension errors; CSS fallback ratio stays in effect
|
|
84
|
+
});
|
|
70
85
|
// Listen to SDK events
|
|
71
86
|
player.on('play', () => setIsPlaying(true));
|
|
72
87
|
player.on('pause', () => setIsPlaying(false));
|
|
@@ -131,7 +146,7 @@ function VimeoEmbed({ videoId, videoHash, gifMode = false, playButtonColor, clas
|
|
|
131
146
|
observer.disconnect();
|
|
132
147
|
};
|
|
133
148
|
}, [play, pause]);
|
|
134
|
-
return (jsxs("div", { ref: containerRef, className: cn(S.root, className, isPlaying && S.isPlaying), ...props, children: [jsx("iframe", { ref: iframeRef, src: embedUrl, className: S.iframe, allow: "autoplay; fullscreen; picture-in-picture; encrypted-media", allowFullScreen: true, title: "Vimeo video player", onLoad: handleIframeLoad }), !gifMode && (jsx("button", { type: "button", className: S.playButton, onClick: play, "aria-label": "Play video", children: jsx("svg", { className: S.playIcon, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: jsx("path", { d: "M8 5v14l11-7z", fill: "currentColor" }) }) }))] }));
|
|
149
|
+
return (jsxs("div", { ref: containerRef, className: cn(S.root, className, isPlaying && S.isPlaying), style: aspectRatio ? { aspectRatio: String(aspectRatio) } : undefined, ...props, children: [jsx("iframe", { ref: iframeRef, src: embedUrl, className: S.iframe, allow: "autoplay; fullscreen; picture-in-picture; encrypted-media", allowFullScreen: true, title: "Vimeo video player", onLoad: handleIframeLoad }), !gifMode && (jsx("button", { type: "button", className: S.playButton, onClick: play, "aria-label": "Play video", children: jsx("svg", { className: S.playIcon, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: jsx("path", { d: "M8 5v14l11-7z", fill: "currentColor" }) }) }))] }));
|
|
135
150
|
}
|
|
136
151
|
|
|
137
152
|
export { VimeoEmbed };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import styleInject from 'style-inject';
|
|
2
2
|
|
|
3
|
-
var css_248z = ".VimeoEmbed_root__22Izc{align-self:stretch;aspect-ratio:16/9
|
|
3
|
+
var css_248z = ".VimeoEmbed_root__22Izc{align-self:stretch;aspect-ratio:16/9;border-radius:var(--p-5);box-shadow:0 0 0 1px var(--border);flex-shrink:0;height:auto!important;height:0;margin:0;min-width:0;overflow:hidden;padding-bottom:0;position:relative}.VimeoEmbed_iframe__fuiCR{border:none;border-radius:var(--p-5);display:block;height:100%;left:0;margin:0;opacity:.5;padding:0;position:absolute;top:0;transition:opacity .5s ease;width:100%;z-index:1}.VimeoEmbed_isPlaying__IU81- .VimeoEmbed_iframe__fuiCR{opacity:1}.VimeoEmbed_playButton__2T-Wn{align-items:center;background:var(--background-alpha-500);border:none;box-shadow:0 2px 16px var(--page-color);cursor:pointer;display:flex;height:100%;justify-content:center;position:absolute;transition:all .2s ease;width:100%;z-index:3}.VimeoEmbed_playButton__2T-Wn:hover{background:transparent}.VimeoEmbed_isPlaying__IU81- .VimeoEmbed_playButton__2T-Wn{opacity:0;pointer-events:none}.VimeoEmbed_playIcon__GlKI1{color:var(--brand-color-400);height:var(--p-16);margin-left:4px;width:var(--p-16)}";
|
|
4
4
|
var S = {"root":"VimeoEmbed_root__22Izc","iframe":"VimeoEmbed_iframe__fuiCR","isPlaying":"VimeoEmbed_isPlaying__IU81-","playButton":"VimeoEmbed_playButton__2T-Wn","playIcon":"VimeoEmbed_playIcon__GlKI1"};
|
|
5
5
|
styleInject(css_248z);
|
|
6
6
|
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
margin 0
|
|
7
7
|
padding-bottom 0
|
|
8
8
|
|
|
9
|
-
aspect-ratio 16 / 9
|
|
9
|
+
aspect-ratio 16 / 9
|
|
10
10
|
overflow hidden
|
|
11
11
|
border-radius var(--p-5)
|
|
12
12
|
|
|
@@ -30,8 +30,6 @@
|
|
|
30
30
|
opacity .5
|
|
31
31
|
transition opacity 0.5s ease
|
|
32
32
|
|
|
33
|
-
transform scale(1.01) // fix rounded border cut off issue
|
|
34
|
-
|
|
35
33
|
.isPlaying &
|
|
36
34
|
opacity 1
|
|
37
35
|
|
|
@@ -32,6 +32,9 @@ function VimeoEmbed({
|
|
|
32
32
|
const playerRef = useRef<Player | null>(null);
|
|
33
33
|
const [isPlaying, setIsPlaying] = useState(false);
|
|
34
34
|
const [isPlayerReady, setIsPlayerReady] = useState(false);
|
|
35
|
+
// Intrinsic video aspect ratio (width / height) reported by the Vimeo SDK.
|
|
36
|
+
// Null until the player reports it; falls back to the CSS default meanwhile.
|
|
37
|
+
const [aspectRatio, setAspectRatio] = useState<number | null>(null);
|
|
35
38
|
|
|
36
39
|
const parsed = parseVimeoUrl(videoId);
|
|
37
40
|
const id = parsed.id;
|
|
@@ -46,6 +49,7 @@ function VimeoEmbed({
|
|
|
46
49
|
|
|
47
50
|
// Cleanup player when id/hash changes
|
|
48
51
|
useEffect(() => {
|
|
52
|
+
setAspectRatio(null);
|
|
49
53
|
if (playerRef.current) {
|
|
50
54
|
playerRef.current
|
|
51
55
|
.destroy()
|
|
@@ -87,6 +91,17 @@ function VimeoEmbed({
|
|
|
87
91
|
.then(() => {
|
|
88
92
|
setIsPlayerReady(true);
|
|
89
93
|
|
|
94
|
+
// Read the video's intrinsic dimensions so the container can adopt
|
|
95
|
+
// the exact aspect ratio — eliminates letterbox stripes from the
|
|
96
|
+
// hardcoded box ratio mismatching the source video.
|
|
97
|
+
Promise.all([player.getVideoWidth(), player.getVideoHeight()])
|
|
98
|
+
.then(([w, h]) => {
|
|
99
|
+
if (w > 0 && h > 0) setAspectRatio(w / h);
|
|
100
|
+
})
|
|
101
|
+
.catch(() => {
|
|
102
|
+
// Ignore dimension errors; CSS fallback ratio stays in effect
|
|
103
|
+
});
|
|
104
|
+
|
|
90
105
|
// Listen to SDK events
|
|
91
106
|
player.on('play', () => setIsPlaying(true));
|
|
92
107
|
player.on('pause', () => setIsPlaying(false));
|
|
@@ -156,6 +171,7 @@ function VimeoEmbed({
|
|
|
156
171
|
<div
|
|
157
172
|
ref={containerRef}
|
|
158
173
|
className={cn(S.root, className, isPlaying && S.isPlaying)}
|
|
174
|
+
style={aspectRatio ? { aspectRatio: String(aspectRatio) } : undefined}
|
|
159
175
|
{...props}
|
|
160
176
|
>
|
|
161
177
|
<iframe
|