@cntrl-site/components 1.0.97-1 → 1.0.97-3

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.
@@ -2,7 +2,10 @@ import { CommonComponentProps } from '../props';
2
2
  type HelixMedia = {
3
3
  assetId?: string;
4
4
  name?: string;
5
- type?: 'image' | 'video';
5
+ type?: 'image' | 'video' | 'vimeo' | 'youtube';
6
+ thumbnail?: string;
7
+ width?: number;
8
+ height?: number;
6
9
  };
7
10
  export type HelixContentItem = {
8
11
  image?: HelixMedia;
@@ -21,7 +21,10 @@ type HiveMedia = {
21
21
  assetId: string;
22
22
  name?: string;
23
23
  objectFit?: 'cover' | 'contain';
24
- type?: 'image' | 'video';
24
+ type?: 'image' | 'video' | 'vimeo' | 'youtube';
25
+ thumbnail?: string;
26
+ width?: number;
27
+ height?: number;
25
28
  };
26
29
  type HiveMediaPair = {
27
30
  media: HiveMedia[];
@@ -121,7 +121,10 @@ type ListMedia = {
121
121
  objectFit?: 'cover' | 'contain';
122
122
  assetId: string;
123
123
  name: string;
124
- type?: 'image' | 'video';
124
+ type?: 'image' | 'video' | 'vimeo' | 'youtube';
125
+ thumbnail?: string;
126
+ width?: number;
127
+ height?: number;
125
128
  };
126
129
  type ListContentItem = {
127
130
  AColumn?: string;
@@ -5,7 +5,10 @@ export type MarqueeItem = {
5
5
  image?: {
6
6
  assetId?: string;
7
7
  name?: string;
8
- type?: 'image' | 'video';
8
+ type?: 'image' | 'video' | 'vimeo' | 'youtube';
9
+ thumbnail?: string;
10
+ width?: number;
11
+ height?: number;
9
12
  };
10
13
  link?: ContentLink;
11
14
  };
@@ -3,8 +3,11 @@ import { TextStyles } from '../utils/textStylesToCss';
3
3
  type MercuryMedia = {
4
4
  assetId: string;
5
5
  name?: string;
6
- type?: 'image' | 'video';
6
+ type?: 'image' | 'video' | 'vimeo' | 'youtube';
7
7
  objectFit?: 'cover' | 'contain';
8
+ thumbnail?: string;
9
+ width?: number;
10
+ height?: number;
8
11
  };
9
12
  type MercuryMediaPair = {
10
13
  media: MercuryMedia[];
@@ -3,7 +3,10 @@ export type WaterfallMedia = {
3
3
  assetId: string;
4
4
  name?: string;
5
5
  objectFit?: 'cover' | 'contain';
6
- type?: 'image' | 'video';
6
+ type?: 'image' | 'video' | 'vimeo' | 'youtube';
7
+ thumbnail?: string;
8
+ width?: number;
9
+ height?: number;
7
10
  };
8
11
  export type WaterfallLightboxContentItem = {
9
12
  title?: string;
@@ -0,0 +1,18 @@
1
+ import { FC, HTMLAttributes } from 'react';
2
+ import { EmbedMediaLike, EmbedPlayerMode } from './embedMedia';
3
+ export interface EmbedMediaFrameProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
4
+ media: EmbedMediaLike;
5
+ mode: EmbedPlayerMode;
6
+ /** How the video fills the box, the way an image's object-fit would. */
7
+ fit: 'cover' | 'contain';
8
+ /** Whether the player takes the pointer; a background one leaves it to the box around it. */
9
+ interactive?: boolean;
10
+ /** Framed only while near the viewport, so a track of copies holds one player per visible card. */
11
+ lazy?: boolean;
12
+ }
13
+ /**
14
+ * A Vimeo or YouTube video in the room of an image or a video: a box the caller sizes and places,
15
+ * showing the stored thumbnail until the player is framed over it. A box with no height of its own
16
+ * takes the video's aspect.
17
+ */
18
+ export declare const EmbedMediaFrame: FC<EmbedMediaFrameProps>;
@@ -0,0 +1,21 @@
1
+ export type EmbedProvider = 'vimeo' | 'youtube';
2
+ /** What a media value holds of a Vimeo or YouTube video: its player url, and the picture and size the player has none of. */
3
+ export type EmbedMediaLike = {
4
+ assetId?: string;
5
+ type?: string;
6
+ name?: string;
7
+ thumbnail?: string;
8
+ width?: number;
9
+ height?: number;
10
+ };
11
+ export type EmbedPlayerMode = 'background' | 'player';
12
+ /** The provider whose player a media is framed from, none for a file or a value that only claims to be one. */
13
+ export declare function getEmbedProvider(media: EmbedMediaLike | null | undefined): EmbedProvider | null;
14
+ export declare function isEmbedMedia(media: EmbedMediaLike | null | undefined): boolean;
15
+ /** Width over height of the video, 16:9 when the media does not say. */
16
+ export declare function getEmbedAspect(media: EmbedMediaLike): number;
17
+ /**
18
+ * The player url with the way it plays: `background` runs it the way a muted looping video does,
19
+ * `player` starts it with the provider's own controls.
20
+ */
21
+ export declare function getEmbedPlayerSrc(media: EmbedMediaLike, mode: EmbedPlayerMode): string;
@@ -11,3 +11,7 @@ export { getAvailableStatePanels, getUnavailableStates, isPanelAvailable, } from
11
11
  export type { PanelAvailabilityContext } from './panelAvailability';
12
12
  export { LinkWrapper } from './LinkWrapper';
13
13
  export type { ContentLink } from '../../types/SchemaV1';
14
+ export { getEmbedAspect, getEmbedPlayerSrc, getEmbedProvider, isEmbedMedia } from './embedMedia';
15
+ export type { EmbedMediaLike, EmbedPlayerMode, EmbedProvider } from './embedMedia';
16
+ export { EmbedMediaFrame } from './EmbedMediaFrame';
17
+ export type { EmbedMediaFrameProps } from './EmbedMediaFrame';
@@ -0,0 +1,236 @@
1
+ import { useId as P, useRef as R, useState as x, useEffect as E } from "react";
2
+ import { jsx as g, Fragment as j, jsxs as L } from "react/jsx-runtime";
3
+ function Y(t, e = !1) {
4
+ return e ? `calc(var(--cntrl-article-width) * ${t})` : `${t * 100}vw`;
5
+ }
6
+ const z = (t, e, r, s, n) => {
7
+ const o = {};
8
+ for (const [a, l] of Object.entries(r))
9
+ o[`--${t}-${l}`] = e[a];
10
+ const i = new Set(s);
11
+ if (n)
12
+ for (const a of Object.keys(n))
13
+ i.add(a);
14
+ for (const a of i) {
15
+ const l = n == null ? void 0 : n[a];
16
+ if (l)
17
+ for (const [b, m] of Object.entries(r)) {
18
+ const c = l[b];
19
+ c !== void 0 && (o[`--${t}-${a}-${m}`] = c);
20
+ }
21
+ }
22
+ return o;
23
+ };
24
+ function M(t) {
25
+ const e = t.trim();
26
+ if (!e || e === "none") return 1;
27
+ if (e.endsWith("%")) {
28
+ const s = parseFloat(e);
29
+ return Number.isFinite(s) ? s / 100 : 1;
30
+ }
31
+ const r = parseFloat(e);
32
+ return Number.isFinite(r) ? r : 1;
33
+ }
34
+ function k(t) {
35
+ const e = t.lastIndexOf("/");
36
+ if (e !== -1)
37
+ return M(t.slice(e + 1));
38
+ }
39
+ function G(t) {
40
+ const e = t.trim().toLowerCase();
41
+ if (!e || e === "transparent") return 0;
42
+ const r = e.match(/^(?:oklch|oklab|rgba?|hsla?|hwb|lab|lch|color)\((.+)\)$/);
43
+ if (r) {
44
+ const n = r[1], o = k(n);
45
+ if (o !== void 0) return o;
46
+ if (/^(?:rgba|hsla)$/.test(e.slice(0, 4))) {
47
+ const i = n.split(",").map((a) => parseFloat(a.trim()));
48
+ if (i.length === 4 && Number.isFinite(i[3]))
49
+ return i[3];
50
+ }
51
+ return 1;
52
+ }
53
+ const s = e.match(/^#([0-9a-f]{4}|[0-9a-f]{8})$/);
54
+ if (s) {
55
+ const n = s[1], o = n.length === 4 ? n[3] + n[3] : n.slice(6, 8);
56
+ return parseInt(o, 16) / 255;
57
+ }
58
+ return 1;
59
+ }
60
+ const C = /^[^\s@]+@[^\s@]+\.[^\s@]+$/, W = (t) => C.test(t.trim()), _ = (t) => {
61
+ const e = t.replace(/\D/g, "");
62
+ return e.length >= 7 && e.length <= 15;
63
+ }, J = (t, e) => {
64
+ var r;
65
+ for (const s of t) {
66
+ const n = ((r = e[s.name]) == null ? void 0 : r.trim()) ?? "";
67
+ if (n) {
68
+ if (s.type === "email" && !W(n))
69
+ return "Please enter a valid email address.";
70
+ if (s.type === "phone" && !_(n))
71
+ return "Please enter a valid phone number.";
72
+ }
73
+ }
74
+ return null;
75
+ };
76
+ function K() {
77
+ const e = `cf-${P().replace(/:/g, "")}`;
78
+ return {
79
+ prefix: e,
80
+ cls: (r) => `${e}-${r}`
81
+ };
82
+ }
83
+ const Q = (t, e) => {
84
+ const r = Array.from(t.querySelectorAll('[data-testimonial-measure="text"]')).reduce(
85
+ (n, o) => Math.max(n, o.getBoundingClientRect().height),
86
+ 0
87
+ ), s = Array.from(t.querySelectorAll('[data-testimonial-measure="caption"]')).reduce(
88
+ (n, o) => Math.max(n, o.getBoundingClientRect().height),
89
+ 0
90
+ );
91
+ e({ maxTextPx: r, maxCaptionPx: s });
92
+ };
93
+ function B(t, e) {
94
+ const r = t == null ? void 0 : t.availableWhen;
95
+ return r ? Object.entries(r).every(([s, n]) => {
96
+ if (!(n != null && n.length)) return !0;
97
+ const o = e[s];
98
+ return o === void 0 ? !0 : n.includes(o);
99
+ }) : !0;
100
+ }
101
+ function N(t, e) {
102
+ const r = t == null ? void 0 : t.statePanels;
103
+ return r != null && r.length ? r.filter((s) => {
104
+ var o;
105
+ const n = (o = t == null ? void 0 : t.panels) == null ? void 0 : o.find((i) => i.id === s);
106
+ return B(n, e);
107
+ }) : null;
108
+ }
109
+ function Z(t, e) {
110
+ const r = t == null ? void 0 : t.statePanels;
111
+ if (!(r != null && r.length)) return [];
112
+ const s = new Set(N(t, e) ?? []);
113
+ return r.filter((n) => !s.has(n));
114
+ }
115
+ const T = ["http://", "https://", "/", "mailto:", "tel:", "file:", "ftp:", "javascript", "#"];
116
+ function U(t) {
117
+ return T.some((e) => t.startsWith(e)) ? t : `//${t}`;
118
+ }
119
+ const tt = ({ link: t, className: e, style: r, children: s }) => {
120
+ if (!(t != null && t.value)) return /* @__PURE__ */ g(j, { children: s });
121
+ const n = t.target === "blank" || t.target === "_blank" ? { target: "_blank", rel: "noreferrer" } : {};
122
+ return /* @__PURE__ */ g("a", { href: U(t.value), className: e, style: r, ...n, children: s });
123
+ }, V = {
124
+ vimeo: /^player\.vimeo\.com$/i,
125
+ youtube: /^(?:www\.)?youtube(?:-nocookie)?\.com$/i
126
+ };
127
+ function $(t) {
128
+ if (!(t != null && t.assetId) || t.type !== "vimeo" && t.type !== "youtube") return null;
129
+ try {
130
+ const e = new URL(t.assetId);
131
+ return !V[t.type].test(e.hostname) || t.type === "youtube" && !e.pathname.startsWith("/embed/") ? null : t.type;
132
+ } catch {
133
+ return null;
134
+ }
135
+ }
136
+ function et(t) {
137
+ return $(t) !== null;
138
+ }
139
+ function O(t) {
140
+ const { width: e, height: r } = t;
141
+ return e && r && e > 0 && r > 0 ? e / r : 16 / 9;
142
+ }
143
+ function q(t, e) {
144
+ const r = $(t);
145
+ if (!r || !t.assetId) return t.assetId ?? "";
146
+ const s = new URL(t.assetId), n = s.searchParams;
147
+ return r === "vimeo" ? (n.set("autoplay", "1"), e === "background" && (n.set("background", "1"), n.set("muted", "1"), n.set("loop", "1"))) : (n.set("autoplay", "1"), n.set("playsinline", "1"), n.set("rel", "0"), e === "background" && (n.set("mute", "1"), n.set("loop", "1"), n.set("playlist", s.pathname.slice(7)), n.set("controls", "0"), n.set("modestbranding", "1"))), s.toString();
148
+ }
149
+ function H(t, e, r) {
150
+ const s = t.width / t.height, n = r === "cover" ? e <= s : e >= s, o = n ? t.width : t.height * e, i = n ? t.width / e : t.height;
151
+ return { width: o, height: i, left: (t.width - o) / 2, top: (t.height - i) / 2 };
152
+ }
153
+ const nt = ({
154
+ media: t,
155
+ mode: e,
156
+ fit: r,
157
+ interactive: s = e === "player",
158
+ lazy: n = !0,
159
+ style: o,
160
+ ...i
161
+ }) => {
162
+ const a = R(null), [l, b] = x(null), [m, c] = x(!n), y = O(t);
163
+ E(() => {
164
+ const u = a.current;
165
+ if (!u || typeof ResizeObserver > "u") return;
166
+ const h = () => {
167
+ const { width: w, height: S } = u.getBoundingClientRect();
168
+ b((p) => p && p.width === w && p.height === S ? p : { width: w, height: S });
169
+ };
170
+ h();
171
+ const d = new ResizeObserver(h);
172
+ return d.observe(u), () => d.disconnect();
173
+ }, []), E(() => {
174
+ const u = a.current;
175
+ if (!n || !u || typeof IntersectionObserver > "u") {
176
+ c(!0);
177
+ return;
178
+ }
179
+ const h = new IntersectionObserver(([d]) => c(d.isIntersecting), { rootMargin: "200px" });
180
+ return h.observe(u), () => h.disconnect();
181
+ }, [n]);
182
+ const f = l && l.width > 0 && l.height > 0 ? H(l, y, r) : null, { width: v, ...I } = o ?? {}, F = {
183
+ position: "relative",
184
+ overflow: "hidden",
185
+ aspectRatio: `${y}`,
186
+ width: v === void 0 || v === "auto" ? "100%" : v,
187
+ ...I
188
+ }, A = {
189
+ position: "absolute",
190
+ inset: 0,
191
+ width: "100%",
192
+ height: "100%",
193
+ objectFit: r,
194
+ pointerEvents: "none"
195
+ };
196
+ return /* @__PURE__ */ L("div", { ref: a, "data-embed-frame": "", style: F, ...i, children: [
197
+ t.thumbnail && /* @__PURE__ */ g("img", { src: t.thumbnail, alt: t.name ?? "", draggable: !1, style: A }),
198
+ m && f && /* @__PURE__ */ g(
199
+ "iframe",
200
+ {
201
+ src: q(t, e),
202
+ title: t.name || "Embedded video",
203
+ allow: "autoplay; fullscreen; picture-in-picture",
204
+ allowFullScreen: !0,
205
+ style: {
206
+ position: "absolute",
207
+ left: f.left,
208
+ top: f.top,
209
+ width: f.width,
210
+ height: f.height,
211
+ border: 0,
212
+ pointerEvents: s ? "auto" : "none"
213
+ }
214
+ }
215
+ )
216
+ ] });
217
+ };
218
+ export {
219
+ nt as E,
220
+ tt as L,
221
+ J as a,
222
+ z as b,
223
+ _ as c,
224
+ N as d,
225
+ Z as e,
226
+ B as f,
227
+ G as g,
228
+ O as h,
229
+ W as i,
230
+ q as j,
231
+ $ as k,
232
+ et as l,
233
+ Q as r,
234
+ Y as s,
235
+ K as u
236
+ };
@@ -0,0 +1 @@
1
+ "use strict";const c=require("react"),f=require("react/jsx-runtime");function C(t,e=!1){return e?`calc(var(--cntrl-article-width) * ${t})`:`${t*100}vw`}const L=(t,e,r,s,n)=>{const i={};for(const[a,l]of Object.entries(r))i[`--${t}-${l}`]=e[a];const o=new Set(s);if(n)for(const a of Object.keys(n))o.add(a);for(const a of o){const l=n==null?void 0:n[a];if(l)for(const[m,v]of Object.entries(r)){const h=l[m];h!==void 0&&(i[`--${t}-${a}-${v}`]=h)}}return i};function k(t){const e=t.trim();if(!e||e==="none")return 1;if(e.endsWith("%")){const s=parseFloat(e);return Number.isFinite(s)?s/100:1}const r=parseFloat(e);return Number.isFinite(r)?r:1}function T(t){const e=t.lastIndexOf("/");if(e!==-1)return k(t.slice(e+1))}function W(t){const e=t.trim().toLowerCase();if(!e||e==="transparent")return 0;const r=e.match(/^(?:oklch|oklab|rgba?|hsla?|hwb|lab|lch|color)\((.+)\)$/);if(r){const n=r[1],i=T(n);if(i!==void 0)return i;if(/^(?:rgba|hsla)$/.test(e.slice(0,4))){const o=n.split(",").map(a=>parseFloat(a.trim()));if(o.length===4&&Number.isFinite(o[3]))return o[3]}return 1}const s=e.match(/^#([0-9a-f]{4}|[0-9a-f]{8})$/);if(s){const n=s[1],i=n.length===4?n[3]+n[3]:n.slice(6,8);return parseInt(i,16)/255}return 1}const U=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,F=t=>U.test(t.trim()),P=t=>{const e=t.replace(/\D/g,"");return e.length>=7&&e.length<=15},_=(t,e)=>{var r;for(const s of t){const n=((r=e[s.name])==null?void 0:r.trim())??"";if(n){if(s.type==="email"&&!F(n))return"Please enter a valid email address.";if(s.type==="phone"&&!P(n))return"Please enter a valid phone number."}}return null};function B(){const e=`cf-${c.useId().replace(/:/g,"")}`;return{prefix:e,cls:r=>`${e}-${r}`}}const N=(t,e)=>{const r=Array.from(t.querySelectorAll('[data-testimonial-measure="text"]')).reduce((n,i)=>Math.max(n,i.getBoundingClientRect().height),0),s=Array.from(t.querySelectorAll('[data-testimonial-measure="caption"]')).reduce((n,i)=>Math.max(n,i.getBoundingClientRect().height),0);e({maxTextPx:r,maxCaptionPx:s})};function A(t,e){const r=t==null?void 0:t.availableWhen;return r?Object.entries(r).every(([s,n])=>{if(!(n!=null&&n.length))return!0;const i=e[s];return i===void 0?!0:n.includes(i)}):!0}function $(t,e){const r=t==null?void 0:t.statePanels;return r!=null&&r.length?r.filter(s=>{var i;const n=(i=t==null?void 0:t.panels)==null?void 0:i.find(o=>o.id===s);return A(n,e)}):null}function q(t,e){const r=t==null?void 0:t.statePanels;if(!(r!=null&&r.length))return[];const s=new Set($(t,e)??[]);return r.filter(n=>!s.has(n))}const O=["http://","https://","/","mailto:","tel:","file:","ftp:","javascript","#"];function H(t){return O.some(e=>t.startsWith(e))?t:`//${t}`}const D=({link:t,className:e,style:r,children:s})=>{if(!(t!=null&&t.value))return f.jsx(f.Fragment,{children:s});const n=t.target==="blank"||t.target==="_blank"?{target:"_blank",rel:"noreferrer"}:{};return f.jsx("a",{href:H(t.value),className:e,style:r,...n,children:s})},X={vimeo:/^player\.vimeo\.com$/i,youtube:/^(?:www\.)?youtube(?:-nocookie)?\.com$/i};function w(t){if(!(t!=null&&t.assetId)||t.type!=="vimeo"&&t.type!=="youtube")return null;try{const e=new URL(t.assetId);return!X[t.type].test(e.hostname)||t.type==="youtube"&&!e.pathname.startsWith("/embed/")?null:t.type}catch{return null}}function Y(t){return w(t)!==null}function I(t){const{width:e,height:r}=t;return e&&r&&e>0&&r>0?e/r:16/9}function R(t,e){const r=w(t);if(!r||!t.assetId)return t.assetId??"";const s=new URL(t.assetId),n=s.searchParams;return r==="vimeo"?(n.set("autoplay","1"),e==="background"&&(n.set("background","1"),n.set("muted","1"),n.set("loop","1"))):(n.set("autoplay","1"),n.set("playsinline","1"),n.set("rel","0"),e==="background"&&(n.set("mute","1"),n.set("loop","1"),n.set("playlist",s.pathname.slice(7)),n.set("controls","0"),n.set("modestbranding","1"))),s.toString()}function z(t,e,r){const s=t.width/t.height,n=r==="cover"?e<=s:e>=s,i=n?t.width:t.height*e,o=n?t.width/e:t.height;return{width:i,height:o,left:(t.width-i)/2,top:(t.height-o)/2}}const G=({media:t,mode:e,fit:r,interactive:s=e==="player",lazy:n=!0,style:i,...o})=>{const a=c.useRef(null),[l,m]=c.useState(null),[v,h]=c.useState(!n),S=I(t);c.useEffect(()=>{const u=a.current;if(!u||typeof ResizeObserver>"u")return;const g=()=>{const{width:E,height:x}=u.getBoundingClientRect();m(b=>b&&b.width===E&&b.height===x?b:{width:E,height:x})};g();const p=new ResizeObserver(g);return p.observe(u),()=>p.disconnect()},[]),c.useEffect(()=>{const u=a.current;if(!n||!u||typeof IntersectionObserver>"u"){h(!0);return}const g=new IntersectionObserver(([p])=>h(p.isIntersecting),{rootMargin:"200px"});return g.observe(u),()=>g.disconnect()},[n]);const d=l&&l.width>0&&l.height>0?z(l,S,r):null,{width:y,...j}=i??{},M={position:"relative",overflow:"hidden",aspectRatio:`${S}`,width:y===void 0||y==="auto"?"100%":y,...j},V={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:r,pointerEvents:"none"};return f.jsxs("div",{ref:a,"data-embed-frame":"",style:M,...o,children:[t.thumbnail&&f.jsx("img",{src:t.thumbnail,alt:t.name??"",draggable:!1,style:V}),v&&d&&f.jsx("iframe",{src:R(t,e),title:t.name||"Embedded video",allow:"autoplay; fullscreen; picture-in-picture",allowFullScreen:!0,style:{position:"absolute",left:d.left,top:d.top,width:d.width,height:d.height,border:0,pointerEvents:s?"auto":"none"}})]})};exports.EmbedMediaFrame=G;exports.LinkWrapper=D;exports.buildColorVars=L;exports.getAvailableStatePanels=$;exports.getColorAlpha=W;exports.getEmbedAspect=I;exports.getEmbedPlayerSrc=R;exports.getEmbedProvider=w;exports.getFormFieldValidationError=_;exports.getUnavailableStates=q;exports.isEmbedMedia=Y;exports.isPanelAvailable=A;exports.isValidEmailFormat=F;exports.isValidPhoneFormat=P;exports.readTestimonialTextMeasure=N;exports.scalingValue=C;exports.useScopedStyles=B;