ferst-core 0.6.2 → 0.7.2

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.
@@ -0,0 +1,157 @@
1
+ ---
2
+ /**
3
+ * Video — a consent-gated YouTube / Vimeo player (including a channel's live stream),
4
+ * the sibling of the map embed. The editor pastes the ordinary link; lib/video turns it
5
+ * into a privacy-friendly embed (youtube-nocookie, Vimeo dnt). Nothing loads from the
6
+ * provider until the visitor agrees, then the player fills a fixed-ratio frame. An
7
+ * unrecognised link degrades to a plain "watch" link.
8
+ */
9
+ import { videoEmbed } from '../../lib/video';
10
+
11
+ interface Props {
12
+ title?: string;
13
+ caption?: string;
14
+ url: string;
15
+ ratio?: '16/9' | '4/3' | '1/1' | '9/16';
16
+ }
17
+ const { title = '', caption = '', url, ratio = '16/9' } = Astro.props;
18
+ const v = videoEmbed(url);
19
+ const safeLink = /^https:\/\//i.test(url) ? url : undefined;
20
+ ---
21
+
22
+ <section class="b-video">
23
+ {title && <h2 class="b-video__title">{title}</h2>}
24
+ {v ? (
25
+ <figure class="b-video__figure">
26
+ <div class="b-video__embed" style={`aspect-ratio: ${ratio}`} data-embed-url={v.embedUrl} data-title={title || `Video on ${v.provider}`}>
27
+ <div class="b-video__consent">
28
+ <p class="b-video__consent-text">
29
+ This video is provided by <strong>{v.provider}</strong>. Playing it here shares your
30
+ device's data (such as your IP address) with {v.provider}.
31
+ </p>
32
+ <div class="b-video__actions">
33
+ <button type="button" class="b-video__load">Show video</button>
34
+ <a class="b-video__link" href={v.watchUrl} target="_blank" rel="noopener">Watch on {v.provider} instead</a>
35
+ </div>
36
+ </div>
37
+ <div class="b-video__frame"></div>
38
+ </div>
39
+ {caption && <figcaption class="b-video__caption">{caption}</figcaption>}
40
+ </figure>
41
+ ) : (
42
+ <p class="b-video__note">
43
+ {safeLink ? <a href={safeLink} target="_blank" rel="noopener">Watch the video</a> : "The video isn't set up yet."}
44
+ </p>
45
+ )}
46
+ </section>
47
+
48
+ <script>
49
+ import { initEmbedConsent, makeEmbedFrame } from '../../lib/embed-consent';
50
+
51
+ initEmbedConsent({
52
+ root: '.b-video__embed',
53
+ frame: '.b-video__frame',
54
+ consent: '.b-video__consent',
55
+ button: '.b-video__load',
56
+ buildFrame: (el, url) => {
57
+ const f = makeEmbedFrame(url, { title: el.dataset.title || 'Video', height: '100%' });
58
+ f.allow = 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; fullscreen';
59
+ f.allowFullscreen = true;
60
+ return f;
61
+ },
62
+ });
63
+ </script>
64
+
65
+ <style>
66
+ .b-video {
67
+ display: flex;
68
+ flex-direction: column;
69
+ gap: 1rem;
70
+ max-width: 60rem;
71
+ margin-inline: auto;
72
+ padding-inline: 1rem;
73
+ width: 100%;
74
+ }
75
+ .b-video__title {
76
+ margin: 0;
77
+ }
78
+ .b-video__figure {
79
+ margin: 0;
80
+ display: flex;
81
+ flex-direction: column;
82
+ gap: 0.6rem;
83
+ }
84
+ .b-video__embed {
85
+ position: relative;
86
+ width: 100%;
87
+ max-width: 100%;
88
+ border-radius: var(--radius);
89
+ overflow: hidden;
90
+ background: var(--bg-section);
91
+ border: var(--card-border);
92
+ }
93
+ .b-video__frame {
94
+ position: absolute;
95
+ inset: 0;
96
+ }
97
+ .b-video__frame :global(iframe) {
98
+ display: block;
99
+ }
100
+ .b-video__consent {
101
+ position: absolute;
102
+ inset: 0;
103
+ z-index: 1;
104
+ display: flex;
105
+ flex-direction: column;
106
+ gap: 1rem;
107
+ align-items: center;
108
+ justify-content: center;
109
+ padding: 1.5rem;
110
+ text-align: center;
111
+ }
112
+ .b-video__consent[hidden] {
113
+ display: none;
114
+ }
115
+ .b-video__consent-text {
116
+ margin: 0;
117
+ max-width: 46ch;
118
+ color: var(--muted);
119
+ line-height: 1.6;
120
+ }
121
+ .b-video__actions {
122
+ display: flex;
123
+ flex-wrap: wrap;
124
+ gap: 0.75rem 1.25rem;
125
+ align-items: center;
126
+ justify-content: center;
127
+ }
128
+ .b-video__load {
129
+ font: inherit;
130
+ font-family: var(--font-heading);
131
+ font-weight: 600;
132
+ padding: 0.6rem 1.4rem;
133
+ border: none;
134
+ border-radius: var(--radius-sm);
135
+ background: var(--gold);
136
+ color: var(--text-light);
137
+ cursor: pointer;
138
+ }
139
+ .b-video__load:hover {
140
+ filter: brightness(0.94);
141
+ }
142
+ .b-video__load:focus-visible {
143
+ outline: 2px solid var(--gold);
144
+ outline-offset: 2px;
145
+ }
146
+ .b-video__link,
147
+ .b-video__note a {
148
+ color: var(--gold);
149
+ font-weight: 600;
150
+ }
151
+ .b-video__caption,
152
+ .b-video__note {
153
+ margin: 0;
154
+ color: var(--muted);
155
+ font-size: 0.9375rem;
156
+ }
157
+ </style>