@cntrl-site/components 1.0.103 → 1.0.105

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 (48) 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/observeIntersection.d.ts +4 -0
  4. package/dist/Components/utils/useLazyVideos.d.ts +12 -0
  5. package/dist/Grid-BBpdl60K.js +374 -0
  6. package/dist/Grid-DS53S_gA.mjs +1576 -0
  7. package/dist/{Helix-BmkAKT1G.mjs → Helix-BPn9V1sg.mjs} +53 -53
  8. package/dist/{Helix-2Vr-9WBa.js → Helix-DcgsCc4D.js} +2 -2
  9. package/dist/{Hive-BGMWinrW.mjs → Hive-D6-R6TwM.mjs} +114 -111
  10. package/dist/Hive-n8Fz-j3o.js +321 -0
  11. package/dist/LazyVideo-CdAWymKO.mjs +15 -0
  12. package/dist/LazyVideo-imbU18js.js +1 -0
  13. package/dist/Marquee-DOIRRCu4.js +133 -0
  14. package/dist/Marquee-O_PDwlIb.mjs +564 -0
  15. package/dist/MarqueeText-DkaO2lQ5.js +132 -0
  16. package/dist/MarqueeText-Rzt2fJYt.mjs +517 -0
  17. package/dist/{Mercury-DuKJQ1Zo.mjs → Mercury-C9D10TTT.mjs} +55 -54
  18. package/dist/Mercury-DynO-NxY.js +267 -0
  19. package/dist/{PretextComponent-CGycuNNn.js → PretextComponent-BnsS2zJ6.js} +1 -1
  20. package/dist/{PretextComponent-DN8cyZ8x.mjs → PretextComponent-j-OsRZTx.mjs} +7 -7
  21. package/dist/Waterfall-DC2WQ3GT.js +287 -0
  22. package/dist/{Waterfall-A0FjM2my.mjs → Waterfall-Yud2VR62.mjs} +299 -295
  23. package/dist/{components-DTCDEBo0.js → components-B9Vdjf0w.js} +1 -1
  24. package/dist/{components-BFJINCME.mjs → components-D2LyuDm-.mjs} +1 -1
  25. package/dist/elements.js +1 -1
  26. package/dist/elements.mjs +7 -7
  27. package/dist/elements.node.js +1 -1
  28. package/dist/elements.node.mjs +1 -1
  29. package/dist/index.js +1 -1
  30. package/dist/index.mjs +2 -2
  31. package/dist/observeIntersection-B0f3L2iK.mjs +23 -0
  32. package/dist/observeIntersection-DxGj9Ctt.js +1 -0
  33. package/dist/sources.js +147 -59
  34. package/dist/sources.mjs +155 -67
  35. package/dist/useLazyVideos-CdCbc2j0.js +1 -0
  36. package/dist/useLazyVideos-CxXyEjRQ.mjs +52 -0
  37. package/dist/utils.js +1 -1
  38. package/dist/utils.mjs +14 -12
  39. package/package.json +5 -3
  40. package/dist/Grid-CemGhf3F.js +0 -374
  41. package/dist/Grid-cfQsXW3b.mjs +0 -1553
  42. package/dist/Hive-BC6zQBsv.js +0 -321
  43. package/dist/Marquee-BYClHHws.mjs +0 -551
  44. package/dist/Marquee-vmHaTGIP.js +0 -133
  45. package/dist/MarqueeText-4Rip_sQX.mjs +0 -515
  46. package/dist/MarqueeText-E6OubMOG.js +0 -132
  47. package/dist/Mercury-BwF_XW2w.js +0 -267
  48. 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-j-OsRZTx.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';
@@ -3173,7 +3173,7 @@ export function ClickGallerie({ settings, content = [], isEditor }: ClickGalleri
3173
3173
  </>
3174
3174
  );
3175
3175
  }
3176
- `, C = `import { useCallback, useEffect, useMemo, useState } from 'react';
3176
+ `, w = `import { useCallback, useEffect, useMemo, useState } from 'react';
3177
3177
  import cn from 'classnames';
3178
3178
  import { CommonComponentProps } from '../props';
3179
3179
  import { buildColorVars, scalingValue, useScopedStyles } from '../utils/index';
@@ -3921,7 +3921,7 @@ export function FAQ({ settings, content, isEditor, isPreviewMode, isEditMode, ac
3921
3921
  </>
3922
3922
  );
3923
3923
  }
3924
- `, w = `import React, { useMemo, useState } from 'react';
3924
+ `, C = `import React, { useMemo, useState } from 'react';
3925
3925
  import { CommonComponentProps } from '../props';
3926
3926
  import { buildColorVars, getFormFieldValidationError, scalingValue, useScopedStyles } from '../utils/index';
3927
3927
  import { omitTextColors, textStylesToCss, type TextStyles } from '../utils/textStylesToCss';
@@ -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,8 @@ 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 } from '../utils/observeIntersection';
14177
+ import { pauseVideo, playVideo, raisePreload } from '../utils/useLazyVideos';
14135
14178
 
14136
14179
  function getCSS(P: string, setWidthPx: number): string {
14137
14180
  const distance = setWidthPx > 0 ? \`\${setWidthPx}px\` : '0px';
@@ -14276,6 +14319,8 @@ const MIN_CONTENT_SEQUENCE_REPEAT = 3;
14276
14319
  const MAX_CONTENT_SEQUENCE_REPEAT = 12;
14277
14320
  const MIN_TRUSTWORTHY_CYCLE_WIDTH_PX = 32;
14278
14321
  const OUTER_SET_COPIES = 3;
14322
+ const VIDEO_POLL_MS = 250;
14323
+ const VIDEO_LOOKAHEAD_WRAPPER_WIDTHS = 0.5;
14279
14324
 
14280
14325
  const restartTrackAnimation = (track: HTMLElement) => {
14281
14326
  track.style.setProperty('animation-name', 'none');
@@ -14365,7 +14410,7 @@ const isVideoMedia = (media: Pick<NonNullable<MarqueeItem['image']>, 'assetId' |
14365
14410
 
14366
14411
  const isMediaReady = (el: HTMLImageElement | HTMLVideoElement | null): boolean => {
14367
14412
  if (!el) return false;
14368
- if (el instanceof HTMLVideoElement) return el.readyState >= 2;
14413
+ if (el instanceof HTMLVideoElement) return el.readyState >= 1;
14369
14414
  return el.complete;
14370
14415
  };
14371
14416
 
@@ -14449,10 +14494,9 @@ const MarqueeItemCard = ({
14449
14494
  style={mediaStyle}
14450
14495
  muted
14451
14496
  loop
14452
- autoPlay
14453
14497
  playsInline
14454
- preload="auto"
14455
- onLoadedData={isFirstSet ? onFirstSetImageDone : undefined}
14498
+ preload="none"
14499
+ onLoadedMetadata={isFirstSet ? onFirstSetImageDone : undefined}
14456
14500
  onError={isFirstSet ? onFirstSetImageDone : undefined}
14457
14501
  />
14458
14502
  ) : (
@@ -14527,6 +14571,7 @@ export const Marquee = ({ settings, content, isEditor, isPreviewMode, isEditMode
14527
14571
  cornerRadius = 0,
14528
14572
  } = settings;
14529
14573
  const imageFit = useMemo(() => normalizeImageFit(settings.imageFit), [settings.imageFit]);
14574
+ const needsVideoMetadata = imageFit.display !== 'cover';
14530
14575
  const originalItemCount = content?.length ?? 0;
14531
14576
  const showControls = Boolean(isEditMode);
14532
14577
  const showHoverEffects = !isEditor || Boolean(isPreviewMode);
@@ -14624,26 +14669,56 @@ export const Marquee = ({ settings, content, isEditor, isPreviewMode, isEditMode
14624
14669
  };
14625
14670
  }, [hoverEffect, swappedSlots, showHoverEffects]);
14626
14671
 
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
14672
  useEffect(() => {
14630
14673
  const wrapper = wrapperRef.current;
14631
14674
  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();
14675
+ let isNear = false;
14676
+ let isVisible = false;
14677
+ let pollTimer: ReturnType<typeof setInterval> | undefined;
14678
+ const syncVideos = () => {
14679
+ const videos = wrapper.querySelectorAll('video');
14680
+ if (!isNear) {
14681
+ videos.forEach(pauseVideo);
14682
+ return;
14683
+ }
14684
+ const wrapperRect = wrapper.getBoundingClientRect();
14685
+ const lookahead = wrapperRect.width * VIDEO_LOOKAHEAD_WRAPPER_WIDTHS;
14686
+ videos.forEach((video) => {
14687
+ const rect = video.getBoundingClientRect();
14688
+ const isInView = rect.right > wrapperRect.left && rect.left < wrapperRect.right;
14689
+ const isNearView = rect.right > wrapperRect.left - lookahead && rect.left < wrapperRect.right + lookahead;
14690
+ if (isNearView) raisePreload(video, 'auto');
14691
+ else if (needsVideoMetadata) raisePreload(video, 'metadata');
14692
+ if (isVisible && isInView) {
14693
+ if (video.paused) playVideo(video);
14694
+ } else {
14695
+ pauseVideo(video);
14641
14696
  }
14697
+ });
14698
+ };
14699
+ const update = () => {
14700
+ if (isNear && pollTimer === undefined) {
14701
+ pollTimer = setInterval(syncVideos, VIDEO_POLL_MS);
14702
+ } else if (!isNear && pollTimer !== undefined) {
14703
+ clearInterval(pollTimer);
14704
+ pollTimer = undefined;
14642
14705
  }
14643
- }, { threshold: 0 });
14644
- videos.forEach((video) => observer.observe(video));
14645
- return () => observer.disconnect();
14646
- }, [useMarqueeTrack, setContent, copies, swappedSlots]);
14706
+ syncVideos();
14707
+ };
14708
+ const stopNear = observeIntersection(wrapper, NEAR_VIEWPORT_MARGIN, (intersecting) => {
14709
+ isNear = intersecting;
14710
+ update();
14711
+ });
14712
+ const stopVisible = observeIntersection(wrapper, '0px', (intersecting) => {
14713
+ isVisible = intersecting;
14714
+ update();
14715
+ });
14716
+ return () => {
14717
+ stopNear();
14718
+ stopVisible();
14719
+ clearInterval(pollTimer);
14720
+ };
14721
+ }, [useMarqueeTrack, needsVideoMetadata]);
14647
14722
 
14648
14723
  useLayoutEffect(() => {
14649
14724
  if (!useMarqueeTrack) return;
@@ -14937,6 +15012,7 @@ import { CommonComponentProps } from '../props';
14937
15012
  import { scalingValue } from '../utils/scalingValue';
14938
15013
  import { useScopedStyles } from '../utils/useScopedStyles';
14939
15014
  import { textStylesToCss } from '../utils/textStylesToCss';
15015
+ import { observeIntersection } from '../utils/observeIntersection';
14940
15016
 
14941
15017
  function getCSS(P: string, setWidthPx: number, isCurve: boolean): string {
14942
15018
  const distance = setWidthPx > 0 ? \`\${setWidthPx}px\` : '0px';
@@ -15536,9 +15612,11 @@ export const MarqueeText = ({ settings, content, isEditor, isPreviewMode }: Marq
15536
15612
  const wrapper = wrapperRef.current;
15537
15613
  if (!wrapper) return;
15538
15614
 
15615
+ const canObserve = typeof IntersectionObserver !== 'undefined';
15539
15616
  const wave = {
15540
15617
  raf: 0,
15541
15618
  cancelled: false,
15619
+ isOnScreen: !canObserve,
15542
15620
  lut: null as WaveArcLut | null,
15543
15621
  lutKey: '',
15544
15622
  itemsCache: [] as WaveItemCache[],
@@ -15625,18 +15703,24 @@ export const MarqueeText = ({ settings, content, isEditor, isPreviewMode }: Marq
15625
15703
  if (wave.cancelled) return;
15626
15704
  wave.raf = 0;
15627
15705
  applyWave();
15628
- if (waveShouldLoopRef.current && !document.hidden) {
15706
+ if (waveShouldLoopRef.current && wave.isOnScreen && !document.hidden) {
15629
15707
  wave.raf = requestAnimationFrame(tick);
15630
15708
  }
15631
15709
  };
15632
15710
 
15633
15711
  const kick = () => {
15634
- if (wave.cancelled || wave.raf) return;
15712
+ if (wave.cancelled || wave.raf || !wave.isOnScreen) return;
15635
15713
  wave.raf = requestAnimationFrame(tick);
15636
15714
  };
15637
15715
 
15716
+ const stop = () => {
15717
+ cancelAnimationFrame(wave.raf);
15718
+ wave.raf = 0;
15719
+ };
15720
+
15638
15721
  const invalidate = () => {
15639
15722
  wave.cacheDirty = true;
15723
+ if (!wave.isOnScreen) return;
15640
15724
  applyWave();
15641
15725
  kick();
15642
15726
  };
@@ -15645,15 +15729,16 @@ export const MarqueeText = ({ settings, content, isEditor, isPreviewMode }: Marq
15645
15729
  waveInvalidateRef.current = invalidate;
15646
15730
  applyWave();
15647
15731
  kick();
15732
+ const stopObserving = canObserve
15733
+ ? observeIntersection(wrapper, '0px', (isIntersecting) => {
15734
+ wave.isOnScreen = isIntersecting;
15735
+ if (isIntersecting) invalidate();
15736
+ else stop();
15737
+ })
15738
+ : null;
15648
15739
  const onVisibility = () => {
15649
- if (document.hidden) {
15650
- cancelAnimationFrame(wave.raf);
15651
- wave.raf = 0;
15652
- return;
15653
- }
15654
- cancelAnimationFrame(wave.raf);
15655
- wave.raf = 0;
15656
- invalidate();
15740
+ stop();
15741
+ if (!document.hidden) invalidate();
15657
15742
  };
15658
15743
  document.addEventListener('visibilitychange', onVisibility);
15659
15744
  window.addEventListener('pageshow', onVisibility);
@@ -15663,6 +15748,7 @@ export const MarqueeText = ({ settings, content, isEditor, isPreviewMode }: Marq
15663
15748
  wave.cancelled = true;
15664
15749
  waveKickRef.current = null;
15665
15750
  waveInvalidateRef.current = null;
15751
+ stopObserving?.();
15666
15752
  cancelAnimationFrame(wave.raf);
15667
15753
  document.removeEventListener('visibilitychange', onVisibility);
15668
15754
  window.removeEventListener('pageshow', onVisibility);
@@ -15877,6 +15963,7 @@ import {
15877
15963
  } from '../utils/index';
15878
15964
  import { omitTextColors, TextStyles, textStylesToCss } from '../utils/textStylesToCss';
15879
15965
  import { SvgImage } from '../helpers/SvgImage/SvgImage';
15966
+ import { LazyVideo } from '../helpers/LazyVideo/LazyVideo';
15880
15967
 
15881
15968
  const DEFAULT_IMG_WIDTH = 300 / 1440;
15882
15969
  const DEFAULT_CORNER_RADIUS = 8 / 1440;
@@ -17322,7 +17409,7 @@ function GalleryMediaItem({
17322
17409
  const galleryPaddingBetweenHeight = Math.max(galleryPaddingBetween, PADDING_HANDLE_SIZE);
17323
17410
 
17324
17411
  const mediaNode = isVideoMedia(media) ? (
17325
- <video
17412
+ <LazyVideo
17326
17413
  {...mediaProps}
17327
17414
  src={media.assetId}
17328
17415
  muted
@@ -20408,7 +20495,7 @@ export function Scale({ settings, content, isEditor, isPreviewMode }: ScaleProps
20408
20495
  </>
20409
20496
  );
20410
20497
  }
20411
- `, F = `import { useMemo, type CSSProperties, type MouseEvent, type ReactNode } from 'react';
20498
+ `, _ = `import { useMemo, type CSSProperties, type MouseEvent, type ReactNode } from 'react';
20412
20499
  import { SvgImage } from '../helpers/SvgImage/SvgImage';
20413
20500
  import { CommonComponentProps } from '../props';
20414
20501
  import { buildColorVars, scalingValue, useScopedStyles } from '../utils';
@@ -21040,7 +21127,7 @@ export function SimpleButton({ settings, isEditor, isPreviewMode, activeEvent, h
21040
21127
  </>
21041
21128
  );
21042
21129
  }
21043
- `, _ = `import React, { useCallback, useEffect, useRef, useState } from 'react';
21130
+ `, F = `import React, { useCallback, useEffect, useRef, useState } from 'react';
21044
21131
  import cn from 'classnames';
21045
21132
  import { RichTextRenderer } from '../helpers/RichTextRenderer/RichTextRenderer';
21046
21133
  import { scalingValue } from '../utils/scalingValue';
@@ -23355,6 +23442,7 @@ import { createPortal } from 'react-dom';
23355
23442
  import { CommonComponentProps } from '../props';
23356
23443
  import { getContainedMediaTransformOrigin } from '../utils/getImageRect';
23357
23444
  import { scalingValue, useScopedStyles } from '../utils/index';
23445
+ import { LazyVideo } from '../helpers/LazyVideo/LazyVideo';
23358
23446
  import { textStylesToCss, type TextStyles } from '../utils/textStylesToCss';
23359
23447
  import {
23360
23448
  Lightbox,
@@ -23783,7 +23871,7 @@ export function Waterfall({
23783
23871
  ].filter(Boolean).join(' ')}
23784
23872
  >
23785
23873
  {item.image.type === 'video' ? (
23786
- <video
23874
+ <LazyVideo
23787
23875
  ref={syncFitMediaLayout}
23788
23876
  src={item.image.assetId}
23789
23877
  data-waterfall-index={index}
@@ -23793,7 +23881,7 @@ export function Waterfall({
23793
23881
  loop
23794
23882
  autoPlay
23795
23883
  onClick={handleOpen}
23796
- onLoadedData={(e) => syncFitMediaLayout(e.currentTarget)}
23884
+ onLoadedMetadata={(e) => syncFitMediaLayout(e.currentTarget)}
23797
23885
  />
23798
23886
  ) : (
23799
23887
  <img
@@ -23866,8 +23954,8 @@ export function Waterfall({
23866
23954
  `, V = {
23867
23955
  [b.id]: y,
23868
23956
  [x.id]: S,
23869
- [P.id]: C,
23870
- [v.id]: w,
23957
+ [P.id]: w,
23958
+ [v.id]: C,
23871
23959
  [f.id]: $,
23872
23960
  [h.id]: I,
23873
23961
  [p.id]: T,
@@ -23880,8 +23968,8 @@ export function Waterfall({
23880
23968
  [s.id]: N,
23881
23969
  [a.id]: H,
23882
23970
  [r.id]: O,
23883
- [o.id]: F,
23884
- [i.id]: _,
23971
+ [o.id]: _,
23972
+ [i.id]: F,
23885
23973
  [t.id]: W,
23886
23974
  [e.id]: D,
23887
23975
  [n.id]: B
@@ -0,0 +1 @@
1
+ "use strict";const y=require("react"),u=require("./observeIntersection-DxGj9Ctt.js"),E=["none","metadata","auto"];function a(e,s){E.indexOf(e.preload)<E.indexOf(s)&&(e.preload=s)}function R(e){const s=e.play();s&&s.catch(()=>{})}function b(e){e.paused||e.pause()}function A(e){return e.localName==="video"}function N(e,{autoPlay:s=!1,preload:n="auto",selector:f="video",shouldPlay:i}={}){y.useEffect(()=>{if(!e)return;const p=A(e),d=()=>p?[e]:Array.from(e.querySelectorAll(f));if(typeof IntersectionObserver>"u"){d().forEach(t=>{a(t,n),t.autoplay=s});return}let l=!1,V=!1;const c=()=>{d().forEach(t=>{l&&a(t,n),s&&(V&&(!i||i(t))?(t.muted=!0,t.paused&&R(t)):b(t))})},I=u.observeIntersection(e,u.NEAR_VIEWPORT_MARGIN,t=>{l=t,c()}),o=s?u.observeIntersection(e,"0px",t=>{V=t,c()}):null,r=p?null:new MutationObserver(c);return r==null||r.observe(e,{childList:!0,subtree:!0,...i?{attributes:!0,attributeFilter:["class"]}:{}}),()=>{I(),o==null||o(),r==null||r.disconnect()}},[e,s,n,f,i])}exports.pauseVideo=b;exports.playVideo=R;exports.raisePreload=a;exports.useLazyVideos=N;
@@ -0,0 +1,52 @@
1
+ import { useEffect as R } from "react";
2
+ import { o as E, N as A } from "./observeIntersection-B0f3L2iK.mjs";
3
+ const d = ["none", "metadata", "auto"];
4
+ function V(t, r) {
5
+ d.indexOf(t.preload) < d.indexOf(r) && (t.preload = r);
6
+ }
7
+ function b(t) {
8
+ const r = t.play();
9
+ r && r.catch(() => {
10
+ });
11
+ }
12
+ function x(t) {
13
+ t.paused || t.pause();
14
+ }
15
+ function I(t) {
16
+ return t.localName === "video";
17
+ }
18
+ function L(t, { autoPlay: r = !1, preload: n = "auto", selector: o = "video", shouldPlay: i } = {}) {
19
+ R(() => {
20
+ if (!t) return;
21
+ const c = I(t), u = () => c ? [t] : Array.from(t.querySelectorAll(o));
22
+ if (typeof IntersectionObserver > "u") {
23
+ u().forEach((s) => {
24
+ V(s, n), s.autoplay = r;
25
+ });
26
+ return;
27
+ }
28
+ let p = !1, l = !1;
29
+ const f = () => {
30
+ u().forEach((s) => {
31
+ p && V(s, n), r && (l && (!i || i(s)) ? (s.muted = !0, s.paused && b(s)) : x(s));
32
+ });
33
+ }, N = E(t, A, (s) => {
34
+ p = s, f();
35
+ }), a = r ? E(t, "0px", (s) => {
36
+ l = s, f();
37
+ }) : null, e = c ? null : new MutationObserver(f);
38
+ return e == null || e.observe(t, {
39
+ childList: !0,
40
+ subtree: !0,
41
+ ...i ? { attributes: !0, attributeFilter: ["class"] } : {}
42
+ }), () => {
43
+ N(), a == null || a(), e == null || e.disconnect();
44
+ };
45
+ }, [t, r, n, o, i]);
46
+ }
47
+ export {
48
+ b as a,
49
+ x as p,
50
+ V as r,
51
+ L as u
52
+ };
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-CdCbc2j0.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-CxXyEjRQ.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.105",
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
  }