@cntrl-site/components 1.0.103 → 1.0.104

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.
Files changed (41) hide show
  1. package/dist/Components/helpers/LazyVideo/LazyVideo.d.ts +4 -0
  2. package/dist/Components/utils/index.d.ts +1 -0
  3. package/dist/Components/utils/useLazyVideos.d.ts +15 -0
  4. package/dist/Grid-B2_o1dvz.mjs +1576 -0
  5. package/dist/Grid-Bq6bk2AQ.js +374 -0
  6. package/dist/{Helix-2Vr-9WBa.js → Helix-B7rxlvKq.js} +2 -2
  7. package/dist/{Helix-BmkAKT1G.mjs → Helix-BrKQzGX5.mjs} +53 -53
  8. package/dist/{Hive-BGMWinrW.mjs → Hive-BusARSOi.mjs} +114 -111
  9. package/dist/Hive-Dh5nKPGm.js +321 -0
  10. package/dist/LazyVideo-Cn_vmMq8.js +1 -0
  11. package/dist/LazyVideo-D8eVYFyw.mjs +15 -0
  12. package/dist/Marquee-CdtAqhQE.mjs +563 -0
  13. package/dist/Marquee-DUN8wUax.js +133 -0
  14. package/dist/{Mercury-DuKJQ1Zo.mjs → Mercury-BRqlbk4i.mjs} +55 -54
  15. package/dist/Mercury-C-O2VGkK.js +267 -0
  16. package/dist/{PretextComponent-CGycuNNn.js → PretextComponent-D5P0AjnL.js} +1 -1
  17. package/dist/{PretextComponent-DN8cyZ8x.mjs → PretextComponent-s4DDfmzY.mjs} +6 -6
  18. package/dist/{Waterfall-A0FjM2my.mjs → Waterfall-DKuh4bnv.mjs} +299 -295
  19. package/dist/Waterfall-fdiHR0Rc.js +287 -0
  20. package/dist/{components-DTCDEBo0.js → components-DzNixU7Q.js} +1 -1
  21. package/dist/{components-BFJINCME.mjs → components-Yf9Zjska.mjs} +1 -1
  22. package/dist/elements.js +1 -1
  23. package/dist/elements.mjs +6 -6
  24. package/dist/elements.node.js +1 -1
  25. package/dist/elements.node.mjs +1 -1
  26. package/dist/index.js +1 -1
  27. package/dist/index.mjs +2 -2
  28. package/dist/sources.js +125 -49
  29. package/dist/sources.mjs +129 -53
  30. package/dist/useLazyVideos-BbgdvELi.js +1 -0
  31. package/dist/useLazyVideos-CZLyNolX.mjs +72 -0
  32. package/dist/utils.js +1 -1
  33. package/dist/utils.mjs +14 -12
  34. package/package.json +5 -3
  35. package/dist/Grid-CemGhf3F.js +0 -374
  36. package/dist/Grid-cfQsXW3b.mjs +0 -1553
  37. package/dist/Hive-BC6zQBsv.js +0 -321
  38. package/dist/Marquee-BYClHHws.mjs +0 -551
  39. package/dist/Marquee-vmHaTGIP.js +0 -133
  40. package/dist/Mercury-BwF_XW2w.js +0 -267
  41. package/dist/Waterfall-DnPDHbCL.js +0 -287
package/dist/sources.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { W as n, b as e, T as t, g as i, f as o, S as r, P as a, O as s, h as l, a as c, M as d, L as u, d as g, e as m, H as p, i as h, G as f, F as v, c as P, C as x, B as b } from "./PretextComponent-DN8cyZ8x.mjs";
1
+ import { W as n, b as e, T as t, g as i, f as o, S as r, P as a, O as s, h as l, a as c, M as d, L as u, d as g, e as m, H as p, i as h, G as f, F as v, c as P, C as x, B as b } from "./PretextComponent-s4DDfmzY.mjs";
2
2
  const y = `import { Fragment, useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type MouseEvent, type PointerEvent, type ReactNode } from 'react';
3
3
  import { CommonComponentProps } from '../props';
4
4
  import { buildColorVars, scalingValue, useScopedStyles } from '../utils';
@@ -4566,12 +4566,14 @@ import {
4566
4566
  buildColorVars,
4567
4567
  getFormFieldValidationError,
4568
4568
  scalingValue,
4569
+ useLazyVideos,
4569
4570
  useScopedStyles,
4570
4571
  } from '../utils/index';
4571
4572
  import { useCallback, useEffect, useLayoutEffect, useRef, useState, useMemo } from 'react';
4572
4573
  import { createPortal } from 'react-dom';
4573
4574
  import { omitTextColors, TextStyles, textStylesToCss } from '../utils/textStylesToCss';
4574
4575
  import { SvgImage } from '../helpers/SvgImage/SvgImage';
4576
+ import { LazyVideo } from '../helpers/LazyVideo/LazyVideo';
4575
4577
 
4576
4578
  function sv(px: number): string {
4577
4579
  return \`calc(var(--cntrl-article-width, 100vw) * \${px / 1440})\`;
@@ -5141,10 +5143,13 @@ function collectGridLightboxMedia(content: any[]): GridMedia[] {
5141
5143
  }
5142
5144
 
5143
5145
  function LightboxMediaPreloadPool({ mediaList }: { mediaList: GridMedia[] }) {
5146
+ const [pool, setPool] = useState<HTMLDivElement | null>(null);
5147
+ useLazyVideos(pool, { preload: 'metadata' });
5144
5148
  if (mediaList.length === 0) return null;
5145
5149
 
5146
5150
  return (
5147
5151
  <div
5152
+ ref={setPool}
5148
5153
  aria-hidden
5149
5154
  style={{
5150
5155
  position: 'absolute',
@@ -5160,7 +5165,7 @@ function LightboxMediaPreloadPool({ mediaList }: { mediaList: GridMedia[] }) {
5160
5165
  <video
5161
5166
  key={media.assetId}
5162
5167
  src={media.assetId}
5163
- preload='auto'
5168
+ preload='none'
5164
5169
  muted
5165
5170
  playsInline
5166
5171
  />
@@ -5182,33 +5187,46 @@ function unloadVideoElement(video: HTMLVideoElement) {
5182
5187
  video.load();
5183
5188
  }
5184
5189
 
5190
+ const SPLIDE_SLIDE_VIDEOS = '.splide__slide video';
5191
+
5192
+ function shouldPlaySlideVideo(video: HTMLVideoElement): boolean {
5193
+ if (video.closest('.splide--fade, .splide__slide.is-active:not(.splide__slide--clone), .splide__slide.is-next')) return true;
5194
+ const slide = video.closest<HTMLElement>('.splide__slide');
5195
+ if (!slide || slide.classList.contains('splide__slide--clone')) return false;
5196
+ const slideIndex = slide.dataset.slideIndex;
5197
+ const upcomingSlide = slide.parentElement?.querySelector<HTMLElement>('.splide__slide.is-next');
5198
+ return slideIndex !== undefined && upcomingSlide?.dataset.slideIndex === slideIndex;
5199
+ }
5200
+
5185
5201
  function GridMediaItem({
5186
5202
  media,
5187
5203
  className,
5188
5204
  style,
5205
+ isSplideSlide = false,
5189
5206
  onMediaClick,
5190
5207
  }: {
5191
5208
  media: GridMedia;
5192
5209
  className: string;
5193
5210
  style: React.CSSProperties;
5211
+ isSplideSlide?: boolean;
5194
5212
  onMediaClick?: (e: React.MouseEvent<HTMLElement>) => void;
5195
5213
  }) {
5196
5214
  if (isVideoMedia(media)) {
5197
- return (
5198
- <video
5199
- src={media.assetId}
5200
- className={className}
5201
- style={{
5202
- ...style,
5203
- cursor: onMediaClick ? 'pointer' : 'default',
5204
- }}
5205
- muted
5206
- autoPlay
5207
- loop
5208
- playsInline
5209
- onClick={onMediaClick}
5210
- />
5211
- );
5215
+ const videoProps = {
5216
+ src: media.assetId,
5217
+ className,
5218
+ style: {
5219
+ ...style,
5220
+ cursor: onMediaClick ? 'pointer' : 'default',
5221
+ },
5222
+ muted: true,
5223
+ loop: true,
5224
+ playsInline: true,
5225
+ onClick: onMediaClick,
5226
+ };
5227
+ return isSplideSlide
5228
+ ? <video {...videoProps} preload='none' />
5229
+ : <LazyVideo {...videoProps} autoPlay />;
5212
5230
  }
5213
5231
 
5214
5232
  return (
@@ -5225,6 +5243,25 @@ function GridMediaItem({
5225
5243
  );
5226
5244
  }
5227
5245
 
5246
+ function GridItemMediaWrapper({
5247
+ className,
5248
+ style,
5249
+ children,
5250
+ }: {
5251
+ className: string;
5252
+ style: React.CSSProperties;
5253
+ children: React.ReactNode;
5254
+ }) {
5255
+ const [wrapper, setWrapper] = useState<HTMLDivElement | null>(null);
5256
+ useLazyVideos(wrapper, { autoPlay: true, selector: SPLIDE_SLIDE_VIDEOS, shouldPlay: shouldPlaySlideVideo });
5257
+
5258
+ return (
5259
+ <div ref={setWrapper} className={className} style={style}>
5260
+ {children}
5261
+ </div>
5262
+ );
5263
+ }
5264
+
5228
5265
  function getGhostRect(ghost: HTMLElement): AnimRect {
5229
5266
  const cb = ghost.getBoundingClientRect();
5230
5267
  return { width: cb.width, height: cb.height, left: cb.left, top: cb.top };
@@ -6546,7 +6583,7 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
6546
6583
  .map(entry => entry.lightboxMedia!);
6547
6584
 
6548
6585
  const imageContent = (
6549
- <div className={imageWrapperClassName} style={imageWrapperStyle}>
6586
+ <GridItemMediaWrapper className={imageWrapperClassName} style={imageWrapperStyle}>
6550
6587
  {displayItems.length === 0
6551
6588
  ? null
6552
6589
  : slider === 'off'
@@ -6573,7 +6610,7 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
6573
6610
  <div className={\`\${P}-item-image-wrapper-sizer\`} aria-hidden="true">
6574
6611
  {displayItems.map(({ displayMedia }) => (
6575
6612
  isVideoMedia(displayMedia) ? (
6576
- <video key={\`sizer-\${displayMedia.assetId}\`} src={displayMedia.assetId} muted playsInline />
6613
+ <LazyVideo key={\`sizer-\${displayMedia.assetId}\`} src={displayMedia.assetId} nearPreload='metadata' muted playsInline />
6577
6614
  ) : (
6578
6615
  <img key={\`sizer-\${displayMedia.assetId}\`} src={displayMedia.assetId} alt="" />
6579
6616
  )
@@ -6609,11 +6646,12 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
6609
6646
  ? lightboxItemsForEntry.findIndex(item => item.assetId === lightboxMedia.assetId)
6610
6647
  : -1;
6611
6648
  return (
6612
- <SplideSlide key={imgIndex}>
6649
+ <SplideSlide key={imgIndex} data-slide-index={imgIndex}>
6613
6650
  <GridMediaItem
6614
6651
  media={displayMedia}
6615
6652
  className={\`\${P}-item-\${isVideoMedia(displayMedia) ? 'video' : 'image'}\`.trim()}
6616
6653
  style={imageStyle}
6654
+ isSplideSlide
6617
6655
  onMediaClick={canOpenLightboxMedia && lightboxIndex >= 0
6618
6656
  ? () => openLightbox(lightboxItemsForEntry, lightboxIndex)
6619
6657
  : undefined}
@@ -6624,7 +6662,7 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
6624
6662
  </Splide>
6625
6663
  </>
6626
6664
  }
6627
- </div>
6665
+ </GridItemMediaWrapper>
6628
6666
  );
6629
6667
 
6630
6668
  const typeABText = !isTextBeforeImage ? (
@@ -6831,6 +6869,7 @@ const STATE_KEYS = ['hover', 'focus', 'filled', 'success', 'error'] as const;
6831
6869
  import { CommonComponentProps } from '../props';
6832
6870
  import { scalingValue } from '../utils/scalingValue';
6833
6871
  import { useScopedStyles } from '../utils/useScopedStyles';
6872
+ import { LazyVideo } from '../helpers/LazyVideo/LazyVideo';
6834
6873
 
6835
6874
  const DEG_PER_SEC_PER_SPEED_UNIT = 10;
6836
6875
  const MAX_TOTAL_ITEMS = 400;
@@ -7343,7 +7382,7 @@ export function Helix({
7343
7382
  }
7344
7383
  : mediaStyle;
7345
7384
  const mediaNode = isVideoMedia(media) ? (
7346
- <video
7385
+ <LazyVideo
7347
7386
  className={\`\${P}-media\`}
7348
7387
  style={coverMediaStyle}
7349
7388
  src={media.assetId}
@@ -7351,7 +7390,6 @@ export function Helix({
7351
7390
  loop
7352
7391
  autoPlay
7353
7392
  playsInline
7354
- preload="auto"
7355
7393
  />
7356
7394
  ) : (
7357
7395
  <img
@@ -7388,7 +7426,8 @@ export function Helix({
7388
7426
  );
7389
7427
  }
7390
7428
  `, T = `import { CommonComponentProps } from '../props';
7391
- import { scalingValue, useScopedStyles } from '../utils/index';
7429
+ import { scalingValue, useLazyVideos, useScopedStyles } from '../utils/index';
7430
+ import { LazyVideo } from '../helpers/LazyVideo/LazyVideo';
7392
7431
  import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
7393
7432
  import { createPortal } from 'react-dom';
7394
7433
  import {
@@ -7992,10 +8031,13 @@ function collectAllHiveMedia(content: HiveContentItem[]): HiveMedia[] {
7992
8031
  }
7993
8032
 
7994
8033
  function PreloadedMediaPool({ mediaList }: { mediaList: HiveMedia[] }) {
8034
+ const [pool, setPool] = useState<HTMLDivElement | null>(null);
8035
+ useLazyVideos(pool, { preload: 'metadata' });
7995
8036
  if (mediaList.length === 0) return null;
7996
8037
 
7997
8038
  return (
7998
8039
  <div
8040
+ ref={setPool}
7999
8041
  aria-hidden
8000
8042
  style={{
8001
8043
  position: 'absolute',
@@ -8011,7 +8053,7 @@ function PreloadedMediaPool({ mediaList }: { mediaList: HiveMedia[] }) {
8011
8053
  <video
8012
8054
  key={media.assetId}
8013
8055
  src={media.assetId}
8014
- preload='auto'
8056
+ preload='none'
8015
8057
  muted
8016
8058
  playsInline
8017
8059
  />
@@ -8230,7 +8272,7 @@ function MediaItem({
8230
8272
  }) {
8231
8273
  if (isVideoMedia(media)) {
8232
8274
  return (
8233
- <video
8275
+ <LazyVideo
8234
8276
  src={media.assetId}
8235
8277
  className={className}
8236
8278
  data-hive-grid-index={gridIndex}
@@ -8242,7 +8284,6 @@ function MediaItem({
8242
8284
  autoPlay
8243
8285
  loop
8244
8286
  playsInline
8245
- preload='auto'
8246
8287
  onClick={onMediaClick}
8247
8288
  />
8248
8289
  );
@@ -14132,6 +14173,7 @@ import cn from 'classnames';
14132
14173
  import { CommonComponentProps } from '../props';
14133
14174
  import { scalingValue } from '../utils/scalingValue';
14134
14175
  import { useScopedStyles } from '../utils/useScopedStyles';
14176
+ import { NEAR_VIEWPORT_MARGIN, observeIntersection, pauseVideo, playVideo, raisePreload } from '../utils/useLazyVideos';
14135
14177
 
14136
14178
  function getCSS(P: string, setWidthPx: number): string {
14137
14179
  const distance = setWidthPx > 0 ? \`\${setWidthPx}px\` : '0px';
@@ -14276,6 +14318,8 @@ const MIN_CONTENT_SEQUENCE_REPEAT = 3;
14276
14318
  const MAX_CONTENT_SEQUENCE_REPEAT = 12;
14277
14319
  const MIN_TRUSTWORTHY_CYCLE_WIDTH_PX = 32;
14278
14320
  const OUTER_SET_COPIES = 3;
14321
+ const VIDEO_POLL_MS = 250;
14322
+ const VIDEO_LOOKAHEAD_WRAPPER_WIDTHS = 0.5;
14279
14323
 
14280
14324
  const restartTrackAnimation = (track: HTMLElement) => {
14281
14325
  track.style.setProperty('animation-name', 'none');
@@ -14365,7 +14409,7 @@ const isVideoMedia = (media: Pick<NonNullable<MarqueeItem['image']>, 'assetId' |
14365
14409
 
14366
14410
  const isMediaReady = (el: HTMLImageElement | HTMLVideoElement | null): boolean => {
14367
14411
  if (!el) return false;
14368
- if (el instanceof HTMLVideoElement) return el.readyState >= 2;
14412
+ if (el instanceof HTMLVideoElement) return el.readyState >= 1;
14369
14413
  return el.complete;
14370
14414
  };
14371
14415
 
@@ -14449,10 +14493,9 @@ const MarqueeItemCard = ({
14449
14493
  style={mediaStyle}
14450
14494
  muted
14451
14495
  loop
14452
- autoPlay
14453
14496
  playsInline
14454
- preload="auto"
14455
- onLoadedData={isFirstSet ? onFirstSetImageDone : undefined}
14497
+ preload="none"
14498
+ onLoadedMetadata={isFirstSet ? onFirstSetImageDone : undefined}
14456
14499
  onError={isFirstSet ? onFirstSetImageDone : undefined}
14457
14500
  />
14458
14501
  ) : (
@@ -14527,6 +14570,7 @@ export const Marquee = ({ settings, content, isEditor, isPreviewMode, isEditMode
14527
14570
  cornerRadius = 0,
14528
14571
  } = settings;
14529
14572
  const imageFit = useMemo(() => normalizeImageFit(settings.imageFit), [settings.imageFit]);
14573
+ const needsVideoMetadata = imageFit.display !== 'cover';
14530
14574
  const originalItemCount = content?.length ?? 0;
14531
14575
  const showControls = Boolean(isEditMode);
14532
14576
  const showHoverEffects = !isEditor || Boolean(isPreviewMode);
@@ -14624,26 +14668,56 @@ export const Marquee = ({ settings, content, isEditor, isPreviewMode, isEditMode
14624
14668
  };
14625
14669
  }, [hoverEffect, swappedSlots, showHoverEffects]);
14626
14670
 
14627
- // Only decode videos that are actually visible: the track renders many copies of each item,
14628
- // and playing all of them at once saturates the decoder and drops frames.
14629
14671
  useEffect(() => {
14630
14672
  const wrapper = wrapperRef.current;
14631
14673
  if (!wrapper || typeof IntersectionObserver === 'undefined') return;
14632
- const videos = wrapper.querySelectorAll('video');
14633
- if (videos.length === 0) return;
14634
- const observer = new IntersectionObserver((entries) => {
14635
- for (const entry of entries) {
14636
- const video = entry.target as HTMLVideoElement;
14637
- if (entry.isIntersecting) {
14638
- if (video.paused) video.play().catch(() => {});
14639
- } else if (!video.paused) {
14640
- video.pause();
14674
+ let isNear = false;
14675
+ let isVisible = false;
14676
+ let pollTimer: ReturnType<typeof setInterval> | undefined;
14677
+ const syncVideos = () => {
14678
+ const videos = wrapper.querySelectorAll('video');
14679
+ if (!isNear) {
14680
+ videos.forEach(pauseVideo);
14681
+ return;
14682
+ }
14683
+ const wrapperRect = wrapper.getBoundingClientRect();
14684
+ const lookahead = wrapperRect.width * VIDEO_LOOKAHEAD_WRAPPER_WIDTHS;
14685
+ videos.forEach((video) => {
14686
+ const rect = video.getBoundingClientRect();
14687
+ const isInView = rect.right > wrapperRect.left && rect.left < wrapperRect.right;
14688
+ const isNearView = rect.right > wrapperRect.left - lookahead && rect.left < wrapperRect.right + lookahead;
14689
+ if (isNearView) raisePreload(video, 'auto');
14690
+ else if (needsVideoMetadata) raisePreload(video, 'metadata');
14691
+ if (isVisible && isInView) {
14692
+ if (video.paused) playVideo(video);
14693
+ } else {
14694
+ pauseVideo(video);
14641
14695
  }
14696
+ });
14697
+ };
14698
+ const update = () => {
14699
+ if (isNear && pollTimer === undefined) {
14700
+ pollTimer = setInterval(syncVideos, VIDEO_POLL_MS);
14701
+ } else if (!isNear && pollTimer !== undefined) {
14702
+ clearInterval(pollTimer);
14703
+ pollTimer = undefined;
14642
14704
  }
14643
- }, { threshold: 0 });
14644
- videos.forEach((video) => observer.observe(video));
14645
- return () => observer.disconnect();
14646
- }, [useMarqueeTrack, setContent, copies, swappedSlots]);
14705
+ syncVideos();
14706
+ };
14707
+ const stopNear = observeIntersection(wrapper, NEAR_VIEWPORT_MARGIN, (intersecting) => {
14708
+ isNear = intersecting;
14709
+ update();
14710
+ });
14711
+ const stopVisible = observeIntersection(wrapper, '0px', (intersecting) => {
14712
+ isVisible = intersecting;
14713
+ update();
14714
+ });
14715
+ return () => {
14716
+ stopNear();
14717
+ stopVisible();
14718
+ clearInterval(pollTimer);
14719
+ };
14720
+ }, [useMarqueeTrack, needsVideoMetadata]);
14647
14721
 
14648
14722
  useLayoutEffect(() => {
14649
14723
  if (!useMarqueeTrack) return;
@@ -15877,6 +15951,7 @@ import {
15877
15951
  } from '../utils/index';
15878
15952
  import { omitTextColors, TextStyles, textStylesToCss } from '../utils/textStylesToCss';
15879
15953
  import { SvgImage } from '../helpers/SvgImage/SvgImage';
15954
+ import { LazyVideo } from '../helpers/LazyVideo/LazyVideo';
15880
15955
 
15881
15956
  const DEFAULT_IMG_WIDTH = 300 / 1440;
15882
15957
  const DEFAULT_CORNER_RADIUS = 8 / 1440;
@@ -17322,7 +17397,7 @@ function GalleryMediaItem({
17322
17397
  const galleryPaddingBetweenHeight = Math.max(galleryPaddingBetween, PADDING_HANDLE_SIZE);
17323
17398
 
17324
17399
  const mediaNode = isVideoMedia(media) ? (
17325
- <video
17400
+ <LazyVideo
17326
17401
  {...mediaProps}
17327
17402
  src={media.assetId}
17328
17403
  muted
@@ -20408,7 +20483,7 @@ export function Scale({ settings, content, isEditor, isPreviewMode }: ScaleProps
20408
20483
  </>
20409
20484
  );
20410
20485
  }
20411
- `, F = `import { useMemo, type CSSProperties, type MouseEvent, type ReactNode } from 'react';
20486
+ `, _ = `import { useMemo, type CSSProperties, type MouseEvent, type ReactNode } from 'react';
20412
20487
  import { SvgImage } from '../helpers/SvgImage/SvgImage';
20413
20488
  import { CommonComponentProps } from '../props';
20414
20489
  import { buildColorVars, scalingValue, useScopedStyles } from '../utils';
@@ -21040,7 +21115,7 @@ export function SimpleButton({ settings, isEditor, isPreviewMode, activeEvent, h
21040
21115
  </>
21041
21116
  );
21042
21117
  }
21043
- `, _ = `import React, { useCallback, useEffect, useRef, useState } from 'react';
21118
+ `, F = `import React, { useCallback, useEffect, useRef, useState } from 'react';
21044
21119
  import cn from 'classnames';
21045
21120
  import { RichTextRenderer } from '../helpers/RichTextRenderer/RichTextRenderer';
21046
21121
  import { scalingValue } from '../utils/scalingValue';
@@ -23355,6 +23430,7 @@ import { createPortal } from 'react-dom';
23355
23430
  import { CommonComponentProps } from '../props';
23356
23431
  import { getContainedMediaTransformOrigin } from '../utils/getImageRect';
23357
23432
  import { scalingValue, useScopedStyles } from '../utils/index';
23433
+ import { LazyVideo } from '../helpers/LazyVideo/LazyVideo';
23358
23434
  import { textStylesToCss, type TextStyles } from '../utils/textStylesToCss';
23359
23435
  import {
23360
23436
  Lightbox,
@@ -23783,7 +23859,7 @@ export function Waterfall({
23783
23859
  ].filter(Boolean).join(' ')}
23784
23860
  >
23785
23861
  {item.image.type === 'video' ? (
23786
- <video
23862
+ <LazyVideo
23787
23863
  ref={syncFitMediaLayout}
23788
23864
  src={item.image.assetId}
23789
23865
  data-waterfall-index={index}
@@ -23793,7 +23869,7 @@ export function Waterfall({
23793
23869
  loop
23794
23870
  autoPlay
23795
23871
  onClick={handleOpen}
23796
- onLoadedData={(e) => syncFitMediaLayout(e.currentTarget)}
23872
+ onLoadedMetadata={(e) => syncFitMediaLayout(e.currentTarget)}
23797
23873
  />
23798
23874
  ) : (
23799
23875
  <img
@@ -23880,8 +23956,8 @@ export function Waterfall({
23880
23956
  [s.id]: N,
23881
23957
  [a.id]: H,
23882
23958
  [r.id]: O,
23883
- [o.id]: F,
23884
- [i.id]: _,
23959
+ [o.id]: _,
23960
+ [i.id]: F,
23885
23961
  [t.id]: W,
23886
23962
  [e.id]: D,
23887
23963
  [n.id]: B
@@ -0,0 +1 @@
1
+ "use strict";const w=require("react"),I="100% 0px",V=new Map;function A(e){const t=V.get(e);if(t)return t;const r=new Map,o=new Map,c={observer:new IntersectionObserver(n=>{var a;for(const f of n)o.set(f.target,f.isIntersecting),(a=r.get(f.target))==null||a.forEach(d=>d(f.isIntersecting))},{rootMargin:e}),listeners:r,states:o};return V.set(e,c),c}function b(e,t,r){const{observer:o,listeners:i,states:c}=A(t),n=i.get(e)??new Set;n.size===0&&(i.set(e,n),o.observe(e)),n.add(r);const a=c.get(e);return a!==void 0&&r(a),()=>{n.delete(r),!(n.size>0)&&(i.delete(e),c.delete(e),o.unobserve(e))}}const g=["none","metadata","auto"];function E(e,t){g.indexOf(e.preload)<g.indexOf(t)&&(e.preload=t)}function R(e){const t=e.play();t&&t.catch(()=>{})}function l(e){e.paused||e.pause()}function N(e){return e.localName==="video"}function y(e,{autoPlay:t=!1,preload:r="auto",selector:o="video",shouldPlay:i}={}){w.useEffect(()=>{if(!e)return;const c=N(e),n=()=>c?[e]:Array.from(e.querySelectorAll(o));if(typeof IntersectionObserver>"u"){n().forEach(s=>{E(s,r),s.autoplay=t});return}let a=!1,f=!1;const d=()=>{n().forEach(s=>{a&&E(s,r),t&&(f&&(!i||i(s))?(s.muted=!0,s.paused&&R(s)):l(s))})},O=b(e,I,s=>{a=s,d()}),p=t?b(e,"0px",s=>{f=s,d()}):null,u=c?null:new MutationObserver(d);return u==null||u.observe(e,{childList:!0,subtree:!0,...i?{attributes:!0,attributeFilter:["class"]}:{}}),()=>{O(),p==null||p(),u==null||u.disconnect()}},[e,t,r,o,i])}exports.NEAR_VIEWPORT_MARGIN=I;exports.observeIntersection=b;exports.pauseVideo=l;exports.playVideo=R;exports.raisePreload=E;exports.useLazyVideos=y;
@@ -0,0 +1,72 @@
1
+ import { useEffect as O } from "react";
2
+ const V = "100% 0px", b = /* @__PURE__ */ new Map();
3
+ function l(e) {
4
+ const s = b.get(e);
5
+ if (s) return s;
6
+ const r = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), c = { observer: new IntersectionObserver((n) => {
7
+ var a;
8
+ for (const f of n)
9
+ o.set(f.target, f.isIntersecting), (a = r.get(f.target)) == null || a.forEach((p) => p(f.isIntersecting));
10
+ }, { rootMargin: e }), listeners: r, states: o };
11
+ return b.set(e, c), c;
12
+ }
13
+ function g(e, s, r) {
14
+ const { observer: o, listeners: i, states: c } = l(s), n = i.get(e) ?? /* @__PURE__ */ new Set();
15
+ n.size === 0 && (i.set(e, n), o.observe(e)), n.add(r);
16
+ const a = c.get(e);
17
+ return a !== void 0 && r(a), () => {
18
+ n.delete(r), !(n.size > 0) && (i.delete(e), c.delete(e), o.unobserve(e));
19
+ };
20
+ }
21
+ const E = ["none", "metadata", "auto"];
22
+ function w(e, s) {
23
+ E.indexOf(e.preload) < E.indexOf(s) && (e.preload = s);
24
+ }
25
+ function x(e) {
26
+ const s = e.play();
27
+ s && s.catch(() => {
28
+ });
29
+ }
30
+ function N(e) {
31
+ e.paused || e.pause();
32
+ }
33
+ function R(e) {
34
+ return e.localName === "video";
35
+ }
36
+ function A(e, { autoPlay: s = !1, preload: r = "auto", selector: o = "video", shouldPlay: i } = {}) {
37
+ O(() => {
38
+ if (!e) return;
39
+ const c = R(e), n = () => c ? [e] : Array.from(e.querySelectorAll(o));
40
+ if (typeof IntersectionObserver > "u") {
41
+ n().forEach((t) => {
42
+ w(t, r), t.autoplay = s;
43
+ });
44
+ return;
45
+ }
46
+ let a = !1, f = !1;
47
+ const p = () => {
48
+ n().forEach((t) => {
49
+ a && w(t, r), s && (f && (!i || i(t)) ? (t.muted = !0, t.paused && x(t)) : N(t));
50
+ });
51
+ }, I = g(e, V, (t) => {
52
+ a = t, p();
53
+ }), d = s ? g(e, "0px", (t) => {
54
+ f = t, p();
55
+ }) : null, u = c ? null : new MutationObserver(p);
56
+ return u == null || u.observe(e, {
57
+ childList: !0,
58
+ subtree: !0,
59
+ ...i ? { attributes: !0, attributeFilter: ["class"] } : {}
60
+ }), () => {
61
+ I(), d == null || d(), u == null || u.disconnect();
62
+ };
63
+ }, [e, s, r, o, i]);
64
+ }
65
+ export {
66
+ V as N,
67
+ x as a,
68
+ g as o,
69
+ N as p,
70
+ w as r,
71
+ A as u
72
+ };
package/dist/utils.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./scalingValue-CSHYgTZl.js"),i=require("./buildColorVars-CE2D5cQV.js"),t=require("./getColorAlpha-CoSseoCn.js"),e=require("./formFieldValidation-DZl2KVaF.js"),r=require("./useScopedStyles-Bf6yohVQ.js"),o=require("./readTestimonialTextMeasure-CEPaB4Sy.js"),a=require("./panelAvailability-DnOe0rQ4.js");exports.scalingValue=l.scalingValue;exports.buildColorVars=i.buildColorVars;exports.getColorAlpha=t.getColorAlpha;exports.getFormFieldValidationError=e.getFormFieldValidationError;exports.isValidEmailFormat=e.isValidEmailFormat;exports.isValidPhoneFormat=e.isValidPhoneFormat;exports.useScopedStyles=r.useScopedStyles;exports.readTestimonialTextMeasure=o.readTestimonialTextMeasure;exports.getAvailableStatePanels=a.getAvailableStatePanels;exports.getUnavailableStates=a.getUnavailableStates;exports.isPanelAvailable=a.isPanelAvailable;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./scalingValue-CSHYgTZl.js"),i=require("./buildColorVars-CE2D5cQV.js"),r=require("./getColorAlpha-CoSseoCn.js"),e=require("./formFieldValidation-DZl2KVaF.js"),t=require("./useScopedStyles-Bf6yohVQ.js"),o=require("./useLazyVideos-BbgdvELi.js"),s=require("./readTestimonialTextMeasure-CEPaB4Sy.js"),a=require("./panelAvailability-DnOe0rQ4.js");exports.scalingValue=l.scalingValue;exports.buildColorVars=i.buildColorVars;exports.getColorAlpha=r.getColorAlpha;exports.getFormFieldValidationError=e.getFormFieldValidationError;exports.isValidEmailFormat=e.isValidEmailFormat;exports.isValidPhoneFormat=e.isValidPhoneFormat;exports.useScopedStyles=t.useScopedStyles;exports.useLazyVideos=o.useLazyVideos;exports.readTestimonialTextMeasure=s.readTestimonialTextMeasure;exports.getAvailableStatePanels=a.getAvailableStatePanels;exports.getUnavailableStates=a.getUnavailableStates;exports.isPanelAvailable=a.isPanelAvailable;
package/dist/utils.mjs CHANGED
@@ -1,20 +1,22 @@
1
1
  import { s as o } from "./scalingValue-C9JH5L6O.mjs";
2
2
  import { b as s } from "./buildColorVars-CLyWQm5K.mjs";
3
- import { g as t } from "./getColorAlpha-BVBY0N5x.mjs";
4
- import { g as m, i as p, a as g } from "./formFieldValidation-DvihFrq5.mjs";
5
- import { u as d } from "./useScopedStyles-DhBG3557.mjs";
6
- import { r as n } from "./readTestimonialTextMeasure-BIXpGFEt.mjs";
7
- import { g as u, a as V, i as F } from "./panelAvailability-D179wwJx.mjs";
3
+ import { g as l } from "./getColorAlpha-BVBY0N5x.mjs";
4
+ import { g as m, i as p, a as x } from "./formFieldValidation-DvihFrq5.mjs";
5
+ import { u as f } from "./useScopedStyles-DhBG3557.mjs";
6
+ import { u as n } from "./useLazyVideos-CZLyNolX.mjs";
7
+ import { r as V } from "./readTestimonialTextMeasure-BIXpGFEt.mjs";
8
+ import { g as F, a as S, i as v } from "./panelAvailability-D179wwJx.mjs";
8
9
  export {
9
10
  s as buildColorVars,
10
- u as getAvailableStatePanels,
11
- t as getColorAlpha,
11
+ F as getAvailableStatePanels,
12
+ l as getColorAlpha,
12
13
  m as getFormFieldValidationError,
13
- V as getUnavailableStates,
14
- F as isPanelAvailable,
14
+ S as getUnavailableStates,
15
+ v as isPanelAvailable,
15
16
  p as isValidEmailFormat,
16
- g as isValidPhoneFormat,
17
- n as readTestimonialTextMeasure,
17
+ x as isValidPhoneFormat,
18
+ V as readTestimonialTextMeasure,
18
19
  o as scalingValue,
19
- d as useScopedStyles
20
+ n as useLazyVideos,
21
+ f as useScopedStyles
20
22
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/components",
3
- "version": "1.0.103",
3
+ "version": "1.0.104",
4
4
  "description": "Custom components for control editor and public websites.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -52,7 +52,7 @@
52
52
  }
53
53
  },
54
54
  "scripts": {
55
- "test": "jest",
55
+ "test": "vitest run",
56
56
  "dev": "vite development",
57
57
  "prebuild": "rimraf ./dist",
58
58
  "build": "vite build",
@@ -105,12 +105,14 @@
105
105
  "cross-env": "^10.1.0",
106
106
  "franc-min": "^5.0.0",
107
107
  "hyphen": "^1.14.1",
108
+ "jsdom": "^26.1.0",
108
109
  "react": "^18.2.0",
109
110
  "react-dom": "^18.2.0",
110
111
  "rimraf": "^6.0.1",
111
112
  "sass": "^1.86.3",
112
113
  "typescript": "^5.2.2",
113
114
  "vite": "^6.2.5",
114
- "vite-plugin-dts": "^4.5.3"
115
+ "vite-plugin-dts": "^4.5.3",
116
+ "vitest": "^3.2.7"
115
117
  }
116
118
  }