@cntrl-site/components 1.0.102 → 1.0.103

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.
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-Ct0newmn.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-DN8cyZ8x.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';
@@ -2663,6 +2663,7 @@ type ClickGallerieSettings = {
2663
2663
  imageSize?: ImageSizeSettings;
2664
2664
  cursor?: 'system' | 'custom';
2665
2665
  target?: 'area' | 'image';
2666
+ origin?: 'random' | 'same' | 'on Click';
2666
2667
  position?: 'random' | 'same' | 'on Click';
2667
2668
  visible?: 'all' | 'last One';
2668
2669
  defaultCursor?: string | null;
@@ -2890,11 +2891,13 @@ export function ClickGallerie({ settings, content = [], isEditor }: ClickGalleri
2890
2891
  imageSize = DEFAULT_IMAGE_SIZE,
2891
2892
  cursor: cursorMode = 'system',
2892
2893
  target = 'area',
2893
- position = 'random',
2894
+ origin: originSetting,
2895
+ position: legacyOrigin,
2894
2896
  visible = 'all',
2895
2897
  defaultCursor = null,
2896
2898
  hoverCursor = null,
2897
2899
  } = settings;
2900
+ const origin = originSetting ?? legacyOrigin ?? 'random';
2898
2901
 
2899
2902
  const validContent = content.filter(
2900
2903
  (item): item is ClickGallerieItem => Boolean(item?.image?.assetId),
@@ -2994,7 +2997,7 @@ export function ClickGallerie({ settings, content = [], isEditor }: ClickGalleri
2994
2997
 
2995
2998
  let x = 0;
2996
2999
  let y = 0;
2997
- if (position === 'same') {
3000
+ if (origin === 'same') {
2998
3001
  ({ x, y } = getSamePosition(containerWidth, containerHeight, widthPx, aspectRatio));
2999
3002
  } else {
3000
3003
  x = clickPosition.x ?? Math.random() * containerWidth;
@@ -3033,7 +3036,7 @@ export function ClickGallerie({ settings, content = [], isEditor }: ClickGalleri
3033
3036
  : resolveImageWidthPx(img.assetId, imageSize, imageMetaByUrlRef.current);
3034
3037
  const { heightPx } = getImageDimensions(widthPx, img.aspectRatio);
3035
3038
 
3036
- if (position === 'same') {
3039
+ if (origin === 'same') {
3037
3040
  const { x, y } = getSamePosition(containerWidth, containerHeight, widthPx, img.aspectRatio);
3038
3041
  return { ...img, x, y, widthPx };
3039
3042
  }
@@ -3064,7 +3067,7 @@ export function ClickGallerie({ settings, content = [], isEditor }: ClickGalleri
3064
3067
 
3065
3068
  setPlacedImages([newImg]);
3066
3069
  setCounter(validContent.length > 1 ? 1 : 0);
3067
- }, [imageSize, position, divRef, content, imagesReady]);
3070
+ }, [imageSize, origin, divRef, content, imagesReady]);
3068
3071
 
3069
3072
  useEffect(() => {
3070
3073
  if (!divRef) return;
@@ -3079,7 +3082,7 @@ export function ClickGallerie({ settings, content = [], isEditor }: ClickGalleri
3079
3082
  ro.disconnect();
3080
3083
  window.removeEventListener('resize', repositionPlacedImages);
3081
3084
  };
3082
- }, [divRef, position, imageSize, placedImages.length]);
3085
+ }, [divRef, origin, imageSize, placedImages.length]);
3083
3086
 
3084
3087
  useEffect(() => {
3085
3088
  if (visible === 'last One') {
@@ -3098,10 +3101,10 @@ export function ClickGallerie({ settings, content = [], isEditor }: ClickGalleri
3098
3101
 
3099
3102
  let x = 0;
3100
3103
  let y = 0;
3101
- if (position === 'on Click') {
3104
+ if (origin === 'on Click') {
3102
3105
  x = clickX;
3103
3106
  y = clickY;
3104
- } else if (position === 'same') {
3107
+ } else if (origin === 'same') {
3105
3108
  x = rect.width / 2;
3106
3109
  y = rect.height / 2;
3107
3110
  } else {
@@ -19795,6 +19798,13 @@ type ScaleSettings = {
19795
19798
  maxHeight?: number;
19796
19799
  transition?: number;
19797
19800
  bgImage?: 'greyscale' | 'blur' | 'as is';
19801
+ origin?: 'center' | 'mouse' | 'random';
19802
+ position?: 'center' | 'mouse' | 'random';
19803
+ };
19804
+
19805
+ type Point = {
19806
+ x: number;
19807
+ y: number;
19798
19808
  };
19799
19809
 
19800
19810
  const GREYSCALE_EFFECT_AMOUNT = 100;
@@ -19827,11 +19837,8 @@ function getCSS(P: string): string {
19827
19837
  overflow: hidden;
19828
19838
  }
19829
19839
  .\${P}-background {
19830
- position: absolute;
19831
- inset: 0;
19832
19840
  z-index: 1;
19833
19841
  pointer-events: none;
19834
- overflow: hidden;
19835
19842
  }
19836
19843
  .\${P}-effect-image {
19837
19844
  width: 100%;
@@ -19865,11 +19872,17 @@ function getCSS(P: string): string {
19865
19872
  }
19866
19873
  .\${P}-outgoing-next {
19867
19874
  z-index: 3;
19868
- transition: transform var(--\${P}-transition-ms) \${TRANSITION_TIMING_FUNCTION};
19875
+ transition:
19876
+ transform var(--\${P}-transition-ms) \${TRANSITION_TIMING_FUNCTION},
19877
+ left var(--\${P}-transition-ms) \${TRANSITION_TIMING_FUNCTION},
19878
+ top var(--\${P}-transition-ms) \${TRANSITION_TIMING_FUNCTION};
19869
19879
  }
19870
19880
  .\${P}-outgoing-prev {
19871
19881
  z-index: 3;
19872
- transition: transform var(--\${P}-transition-ms) \${TRANSITION_TIMING_FUNCTION};
19882
+ transition:
19883
+ transform var(--\${P}-transition-ms) \${TRANSITION_TIMING_FUNCTION},
19884
+ left var(--\${P}-transition-ms) \${TRANSITION_TIMING_FUNCTION},
19885
+ top var(--\${P}-transition-ms) \${TRANSITION_TIMING_FUNCTION};
19873
19886
  }
19874
19887
  .\${P}-outgoing-next .\${P}-effect-image {
19875
19888
  transition: filter var(--\${P}-transition-ms) \${TRANSITION_TIMING_FUNCTION};
@@ -19995,6 +20008,28 @@ function computeFitSize(
19995
20008
  };
19996
20009
  }
19997
20010
 
20011
+ function clampPoint(point: Point, size: SizePercents): Point {
20012
+ const halfW = size.widthPercent / 2;
20013
+ const halfH = size.heightPercent / 2;
20014
+ const minX = halfW;
20015
+ const maxX = 100 - halfW;
20016
+ const minY = halfH;
20017
+ const maxY = 100 - halfH;
20018
+
20019
+ return {
20020
+ x: minX > maxX ? 50 : Math.min(maxX, Math.max(minX, point.x)),
20021
+ y: minY > maxY ? 50 : Math.min(maxY, Math.max(minY, point.y)),
20022
+ };
20023
+ }
20024
+
20025
+ function centerPoint(): Point {
20026
+ return { x: 50, y: 50 };
20027
+ }
20028
+
20029
+ function randomPoint(): Point {
20030
+ return { x: Math.random() * 100, y: Math.random() * 100 };
20031
+ }
20032
+
19998
20033
  function computeCoverScale(
19999
20034
  containerWidth: number,
20000
20035
  containerHeight: number,
@@ -20016,9 +20051,16 @@ function toSizeStyle(size: SizePercents): React.CSSProperties {
20016
20051
  };
20017
20052
  }
20018
20053
 
20019
- function toStageStyle(size: SizePercents, scale: number, prefix: string): React.CSSProperties {
20054
+ function toStageStyle(
20055
+ size: SizePercents,
20056
+ scale: number,
20057
+ prefix: string,
20058
+ position: Point,
20059
+ ): React.CSSProperties {
20020
20060
  return {
20021
20061
  ...toSizeStyle(size),
20062
+ left: \`\${position.x}%\`,
20063
+ top: \`\${position.y}%\`,
20022
20064
  [\`--\${prefix}-stage-scale\`]: scale,
20023
20065
  } as React.CSSProperties;
20024
20066
  }
@@ -20048,7 +20090,10 @@ export function Scale({ settings, content, isEditor, isPreviewMode }: ScaleProps
20048
20090
  maxHeight,
20049
20091
  transition = 1000,
20050
20092
  bgImage = 'greyscale',
20093
+ origin: originSetting,
20094
+ position: legacyOrigin,
20051
20095
  } = settings;
20096
+ const origin = originSetting ?? legacyOrigin ?? 'center';
20052
20097
  const items = content ?? [];
20053
20098
  const initialIndices = getInitialIndices(items.length);
20054
20099
  const [activeIndex, setActiveIndex] = useState(initialIndices.activeIndex);
@@ -20060,17 +20105,19 @@ export function Scale({ settings, content, isEditor, isPreviewMode }: ScaleProps
20060
20105
  const [incomingScale, setIncomingScale] = useState(0);
20061
20106
  const [outgoingScale, setOutgoingScale] = useState(1);
20062
20107
  const [outgoingFilter, setOutgoingFilter] = useState('none');
20108
+ const [outgoingPointOverride, setOutgoingPointOverride] = useState<Point | null>(null);
20063
20109
  const [transitionDirection, setTransitionDirection] = useState<'next' | 'prev'>('next');
20064
20110
  const [imageDimensions, setImageDimensions] = useState<Record<string, ImageDimensions>>({});
20065
20111
  const [containerSize, setContainerSize] = useState({ width: 0, height: 0 });
20112
+ const [imagePositions, setImagePositions] = useState<Record<number, Point>>({});
20066
20113
  const transitionTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
20067
20114
  const wrapperRef = useRef<HTMLDivElement>(null);
20115
+ const imagePositionsRef = useRef<Record<number, Point>>({});
20068
20116
  const isInteractive = !isEditor || Boolean(isPreviewMode);
20069
20117
  const legacyImageSize = imageSize ?? 60;
20070
20118
  const maxWidthPercent = Math.max(10, Math.min(100, maxWidth ?? legacyImageSize));
20071
20119
  const maxHeightPercent = Math.max(10, Math.min(100, maxHeight ?? legacyImageSize));
20072
20120
  const transitionMs = Math.max(100, transition);
20073
- const backgroundFilter = getBackgroundFilter(bgImage);
20074
20121
 
20075
20122
  const getImageSizePercents = useCallback((url: string | undefined): SizePercents => {
20076
20123
  const aspectRatio = getImageAspectRatio(url ? imageDimensions[url] : undefined);
@@ -20118,16 +20165,42 @@ export function Scale({ settings, content, isEditor, isPreviewMode }: ScaleProps
20118
20165
  setIncomingScale(0);
20119
20166
  setOutgoingScale(1);
20120
20167
  setOutgoingFilter('none');
20168
+ setOutgoingPointOverride(null);
20121
20169
  setTransitionDirection('next');
20122
20170
  }, [items.length, content]);
20123
20171
 
20172
+ useEffect(() => {
20173
+ const nextPositions: Record<number, Point> = {};
20174
+ for (let index = 0; index < items.length; index += 1) {
20175
+ nextPositions[index] = origin === 'random' ? randomPoint() : centerPoint();
20176
+ }
20177
+ imagePositionsRef.current = nextPositions;
20178
+ setImagePositions(nextPositions);
20179
+ }, [items.length, content, origin]);
20180
+
20124
20181
  useEffect(() => () => {
20125
20182
  if (transitionTimeoutRef.current) {
20126
20183
  clearTimeout(transitionTimeoutRef.current);
20127
20184
  }
20128
20185
  }, []);
20129
20186
 
20130
- const startTransition = useCallback((direction: 'next' | 'prev') => {
20187
+ const resolvePosition = useCallback((event?: React.MouseEvent): Point => {
20188
+ if (origin === 'random') return randomPoint();
20189
+ if (origin !== 'mouse') return centerPoint();
20190
+
20191
+ const wrapper = wrapperRef.current;
20192
+ if (!wrapper || !event) return centerPoint();
20193
+
20194
+ const rect = wrapper.getBoundingClientRect();
20195
+ if (rect.width <= 0 || rect.height <= 0) return centerPoint();
20196
+
20197
+ return {
20198
+ x: ((event.clientX - rect.left) / rect.width) * 100,
20199
+ y: ((event.clientY - rect.top) / rect.height) * 100,
20200
+ };
20201
+ }, [origin]);
20202
+
20203
+ const startTransition = useCallback((direction: 'next' | 'prev', event?: React.MouseEvent) => {
20131
20204
  if (!isInteractive || isAnimating || items.length <= 1) return;
20132
20205
 
20133
20206
  const targetIndex = direction === 'next'
@@ -20135,8 +20208,21 @@ export function Scale({ settings, content, isEditor, isPreviewMode }: ScaleProps
20135
20208
  : (activeIndex - 1 + items.length) % items.length;
20136
20209
  const activeSize = getImageSizePercents(items[activeIndex]?.image?.assetId);
20137
20210
  const targetSize = getImageSizePercents(items[targetIndex]?.image?.assetId);
20138
- const activeCoverScale = computeCoverScale(containerSize.width, containerSize.height, activeSize);
20139
- const targetCoverScale = computeCoverScale(containerSize.width, containerSize.height, targetSize);
20211
+ const activePoint = clampPoint(imagePositionsRef.current[activeIndex] ?? centerPoint(), activeSize);
20212
+ const targetPoint = clampPoint(resolvePosition(event), targetSize);
20213
+ const nextPositions = { ...imagePositionsRef.current, [targetIndex]: targetPoint };
20214
+ imagePositionsRef.current = nextPositions;
20215
+ setImagePositions(nextPositions);
20216
+ const activeCoverScale = computeCoverScale(
20217
+ containerSize.width,
20218
+ containerSize.height,
20219
+ activeSize,
20220
+ );
20221
+ const targetCoverScale = computeCoverScale(
20222
+ containerSize.width,
20223
+ containerSize.height,
20224
+ targetSize,
20225
+ );
20140
20226
 
20141
20227
  if (transitionTimeoutRef.current) {
20142
20228
  clearTimeout(transitionTimeoutRef.current);
@@ -20147,6 +20233,7 @@ export function Scale({ settings, content, isEditor, isPreviewMode }: ScaleProps
20147
20233
  setIsAnimating(true);
20148
20234
 
20149
20235
  if (direction === 'next') {
20236
+ setOutgoingPointOverride(activePoint);
20150
20237
  setOutgoingIndex(activeIndex);
20151
20238
  setIncomingIndex(targetIndex);
20152
20239
  setIncomingScale(0);
@@ -20157,6 +20244,7 @@ export function Scale({ settings, content, isEditor, isPreviewMode }: ScaleProps
20157
20244
  setOutgoingIndex(targetIndex);
20158
20245
  setIncomingIndex(activeIndex);
20159
20246
  setIncomingScale(1);
20247
+ setOutgoingPointOverride(centerPoint());
20160
20248
  setOutgoingScale(targetCoverScale);
20161
20249
  setOutgoingFilter(getBackgroundFilter(bgImage, 1, targetCoverScale));
20162
20250
  }
@@ -20166,10 +20254,12 @@ export function Scale({ settings, content, isEditor, isPreviewMode }: ScaleProps
20166
20254
  requestAnimationFrame(() => {
20167
20255
  if (direction === 'next') {
20168
20256
  setIncomingScale(1);
20257
+ setOutgoingPointOverride(centerPoint());
20169
20258
  setOutgoingScale(activeCoverScale);
20170
20259
  setOutgoingFilter(getBackgroundFilter(bgImage, 1, activeCoverScale));
20171
20260
  } else {
20172
20261
  setIncomingScale(0);
20262
+ setOutgoingPointOverride(targetPoint);
20173
20263
  setOutgoingScale(1);
20174
20264
  setOutgoingFilter(getBackgroundFilter(bgImage, 0, 1));
20175
20265
  }
@@ -20183,6 +20273,7 @@ export function Scale({ settings, content, isEditor, isPreviewMode }: ScaleProps
20183
20273
  setActiveIndex(targetIndex);
20184
20274
  setOutgoingIndex(null);
20185
20275
  setIncomingIndex(null);
20276
+ setOutgoingPointOverride(null);
20186
20277
  setIsAnimating(false);
20187
20278
  }, transitionMs);
20188
20279
  }, [
@@ -20194,6 +20285,7 @@ export function Scale({ settings, content, isEditor, isPreviewMode }: ScaleProps
20194
20285
  isAnimating,
20195
20286
  isInteractive,
20196
20287
  items,
20288
+ resolvePosition,
20197
20289
  transitionMs,
20198
20290
  ]);
20199
20291
 
@@ -20206,6 +20298,22 @@ export function Scale({ settings, content, isEditor, isPreviewMode }: ScaleProps
20206
20298
  const foregroundSize = getImageSizePercents(foregroundItem?.image?.assetId);
20207
20299
  const outgoingFitSize = getImageSizePercents(outgoingItem?.image?.assetId);
20208
20300
  const incomingFitSize = getImageSizePercents(incomingItem?.image?.assetId);
20301
+ const backgroundSize = getImageSizePercents(backgroundItem?.image?.assetId);
20302
+ const backgroundCoverScale = computeCoverScale(
20303
+ containerSize.width,
20304
+ containerSize.height,
20305
+ backgroundSize,
20306
+ );
20307
+ const backgroundFilter = getBackgroundFilter(bgImage, 1, backgroundCoverScale);
20308
+ const foregroundPoint = clampPoint(imagePositions[activeIndex] ?? centerPoint(), foregroundSize);
20309
+ const outgoingPoint = outgoingPointOverride ?? clampPoint(
20310
+ outgoingIndex !== null ? (imagePositions[outgoingIndex] ?? centerPoint()) : centerPoint(),
20311
+ outgoingFitSize,
20312
+ );
20313
+ const incomingPoint = clampPoint(
20314
+ incomingIndex !== null ? (imagePositions[incomingIndex] ?? centerPoint()) : centerPoint(),
20315
+ incomingFitSize,
20316
+ );
20209
20317
  const wrapperStyle = {
20210
20318
  [\`--\${P}-transition-ms\`]: \`\${transitionMs}ms\`,
20211
20319
  } as React.CSSProperties;
@@ -20220,7 +20328,11 @@ export function Scale({ settings, content, isEditor, isPreviewMode }: ScaleProps
20220
20328
  aria-label="Zoom gallery"
20221
20329
  >
20222
20330
  {backgroundItem?.image?.assetId && (
20223
- <div className={\`\${P}-background\`} aria-hidden="true">
20331
+ <div
20332
+ className={cn(\`\${P}-stage\`, \`\${P}-background\`)}
20333
+ style={toStageStyle(backgroundSize, backgroundCoverScale, P, centerPoint())}
20334
+ aria-hidden="true"
20335
+ >
20224
20336
  <img
20225
20337
  className={\`\${P}-effect-image\`}
20226
20338
  src={backgroundItem.image.assetId}
@@ -20236,7 +20348,7 @@ export function Scale({ settings, content, isEditor, isPreviewMode }: ScaleProps
20236
20348
  \`\${P}-outgoing\`,
20237
20349
  \`\${P}-outgoing-\${transitionDirection}\`,
20238
20350
  )}
20239
- style={toStageStyle(outgoingFitSize, outgoingScale, P)}
20351
+ style={toStageStyle(outgoingFitSize, outgoingScale, P, outgoingPoint)}
20240
20352
  aria-hidden="true"
20241
20353
  >
20242
20354
  <img
@@ -20254,7 +20366,7 @@ export function Scale({ settings, content, isEditor, isPreviewMode }: ScaleProps
20254
20366
  \`\${P}-incoming\`,
20255
20367
  \`\${P}-incoming-\${transitionDirection}\`,
20256
20368
  )}
20257
- style={toStageStyle(incomingFitSize, incomingScale, P)}
20369
+ style={toStageStyle(incomingFitSize, incomingScale, P, incomingPoint)}
20258
20370
  aria-hidden="true"
20259
20371
  >
20260
20372
  <img
@@ -20267,7 +20379,7 @@ export function Scale({ settings, content, isEditor, isPreviewMode }: ScaleProps
20267
20379
  {!isAnimating && foregroundItem?.image?.assetId && (
20268
20380
  <div
20269
20381
  className={cn(\`\${P}-stage\`, \`\${P}-foreground\`)}
20270
- style={toSizeStyle(foregroundSize)}
20382
+ style={toStageStyle(foregroundSize, 1, P, foregroundPoint)}
20271
20383
  >
20272
20384
  <img
20273
20385
  className={\`\${P}-image\`}
@@ -20281,13 +20393,13 @@ export function Scale({ settings, content, isEditor, isPreviewMode }: ScaleProps
20281
20393
  <button
20282
20394
  type="button"
20283
20395
  className={cn(\`\${P}-nav\`, \`\${P}-nav-prev\`)}
20284
- onClick={() => startTransition('prev')}
20396
+ onClick={(event) => startTransition('prev', event)}
20285
20397
  aria-label={\`Show previous image (\${prevIndex + 1} of \${items.length})\`}
20286
20398
  />
20287
20399
  <button
20288
20400
  type="button"
20289
20401
  className={cn(\`\${P}-nav\`, \`\${P}-nav-next\`)}
20290
- onClick={() => startTransition('next')}
20402
+ onClick={(event) => startTransition('next', event)}
20291
20403
  aria-label={\`Show next image (\${nextIndex + 1} of \${items.length})\`}
20292
20404
  />
20293
20405
  </>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/components",
3
- "version": "1.0.102",
3
+ "version": "1.0.103",
4
4
  "description": "Custom components for control editor and public websites.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -1,36 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("react/jsx-runtime"),u=require("react"),D=require("./useScopedStyles-Bf6yohVQ.js"),ee={sizeType:"custom",value:700,min:400,max:700};function z(o,a){return{widthPx:o,heightPx:o*a}}function F(o,a,i,s,t,h){return{x:Math.min(Math.max(o,t/2),i-t/2),y:Math.min(Math.max(a,h/2),s-h/2)}}function A(o,a,i,s){const{heightPx:t}=z(i,s);return F(o/2,a/2,o,a,i,t)}function Z(o,a,i){for(const s of i){const{heightPx:t}=z(s.widthPx,s.aspectRatio),h=s.widthPx/2,f=t/2;if(o>=s.x-h&&o<=s.x+h&&a>=s.y-f&&a<=s.y+f)return!0}return!1}function te(o,a,i,s,t,h,f,p){if(t==="system")return"none";const P=s.getBoundingClientRect(),R=document.elementFromPoint(P.left+o,P.top+a);return R&&R.closest("a")?"none":Z(o,a,i)||h==="area"?f??"none":p??"none"}function H(o,a,i){var p;const{sizeType:s,value:t,min:h,max:f}=a;return s==="custom"?t:s==="as is"?((p=i.get(o))==null?void 0:p.naturalWidth)??t:Math.round(Math.random()*(f-h)+h)}function ne(o){return`
2
- .${o}-root {
3
- position: absolute;
4
- top: 0;
5
- left: 0;
6
- width: 100%;
7
- height: 100%;
8
- overflow: hidden;
9
- }
10
- .${o}-wrapper {
11
- position: absolute;
12
- transform: translate(-50%, -50%);
13
- height: auto;
14
- }
15
- .${o}-image {
16
- display: block;
17
- width: 100%;
18
- height: auto;
19
- object-fit: cover;
20
- position: relative;
21
- user-select: none;
22
- pointer-events: none;
23
- }
24
- .${o}-link {
25
- width: 100%;
26
- display: block;
27
- }
28
- .${o}-cursor {
29
- position: absolute;
30
- top: 0;
31
- left: 0;
32
- pointer-events: none;
33
- width: 32px;
34
- height: 32px;
35
- }
36
- `}function se(o){return new Promise(a=>{const i=new Image;i.onload=()=>{a({aspectRatio:i.naturalHeight/i.naturalWidth,naturalWidth:i.naturalWidth})},i.onerror=()=>{a({aspectRatio:1,naturalWidth:700})},i.src=o})}async function re(o){const a=[...new Set(o.filter(Boolean))],i=await Promise.all(a.map(async s=>[s,await se(s)]));return new Map(i)}function oe({settings:o,content:a=[],isEditor:i}){const{prefix:s}=D.useScopedStyles(),[t,h]=u.useState(null),[f,p]=u.useState([]),[P,R]=u.useState(0),J=u.useRef(0),[O,K]=u.useState({x:0,y:0}),[X,Y]=u.useState("none"),M=u.useRef({x:0,y:0}),[w,G]=u.useState(!1),[N,T]=u.useState(!1),S=u.useRef(new Map),{imageSize:k=ee,cursor:W="system",target:$="area",position:I="random",visible:_="all",defaultCursor:b=null,hoverCursor:j=null}=o,y=a.filter(e=>{var n;return!!((n=e==null?void 0:e.image)!=null&&n.assetId)}),Q=u.useMemo(()=>ne(s),[s]),v=u.useCallback((e,n,r=f)=>{if(!t)return;const d=t.getBoundingClientRect(),c=e-d.left,l=n-d.top;K({x:c,y:l}),Y(te(c,l,r,t,W,$,j,b))},[t,f,W,$,j,b]);u.useEffect(()=>{const e=[...y.map(r=>r.image.assetId),b,j].filter(r=>!!r);if(e.length===0){S.current=new Map,T(!0);return}let n=!1;return T(!1),re(e).then(r=>{n||(S.current=r,T(!0))}),()=>{n=!0}},[a,b,j]),u.useEffect(()=>{if(!t)return;const e=r=>{r.stopPropagation(),M.current={x:r.clientX,y:r.clientY},v(r.clientX,r.clientY)},n=()=>{w&&v(M.current.x,M.current.y)};return t.addEventListener("mousemove",e),window.addEventListener("scroll",n,!0),()=>{t.removeEventListener("mousemove",e),window.removeEventListener("scroll",n,!0)}},[t,w,v]),u.useEffect(()=>{!t||!w||v(M.current.x,M.current.y)},[f,t,w,v]),u.useEffect(()=>{w||Y("none")},[w]);const U=(e,n,r,d={})=>{var C,L;if(!((C=e==null?void 0:e.image)!=null&&C.assetId))return null;const c=((L=S.current.get(e.image.assetId))==null?void 0:L.aspectRatio)??1,l=H(e.image.assetId,k,S.current),{heightPx:E}=z(l,c);let m=0,g=0;return I==="same"?{x:m,y:g}=A(n,r,l,c):(m=d.x??Math.random()*n,g=d.y??Math.random()*r,{x:m,y:g}=F(m,g,n,r,l,E)),{id:J.current++,assetId:e.image.assetId,link:e.link,name:e.image.name,x:m,y:g,xRatio:m/n,yRatio:g/r,aspectRatio:c,widthPx:l}},B=()=>{if(!t)return;const e=t.getBoundingClientRect(),n=e.width,r=e.height;n===0||r===0||p(d=>d.length===0?d:d.map(c=>{const l=k.sizeType==="random"?c.widthPx:H(c.assetId,k,S.current),{heightPx:E}=z(l,c.aspectRatio);if(I==="same"){const{x:C,y:L}=A(n,r,l,c.aspectRatio);return{...c,x:C,y:L,widthPx:l}}const{x:m,y:g}=F(c.xRatio*n,c.yRatio*r,n,r,l,E);return{...c,x:m,y:g,widthPx:l}}))};u.useEffect(()=>{if(!t||y.length===0||!N)return;const e=t.getBoundingClientRect(),n=e.width,r=e.height,d=U(y[0],n,r);d&&(p([d]),R(y.length>1?1:0))},[k,I,t,a,N]),u.useEffect(()=>{if(!t)return;B();const e=new ResizeObserver(B);return e.observe(t),window.addEventListener("resize",B),()=>{e.disconnect(),window.removeEventListener("resize",B)}},[t,I,k,f.length]),u.useEffect(()=>{_==="last One"&&p(e=>e.length>0?[e[e.length-1]]:[])},[_]);const V=e=>{if(!t||y.length===0||!N)return;const n=t.getBoundingClientRect(),r=e.clientX-n.left,d=e.clientY-n.top;if($==="image"&&!Z(r,d,f))return;let c=0,l=0;I==="on Click"?(c=r,l=d):I==="same"?(c=n.width/2,l=n.height/2):(c=Math.random()*n.width,l=Math.random()*n.height);const E=y[P%y.length],m=U(E,n.width,n.height,{x:c,y:l});if(!m)return;const g=_==="all"?[...f,m]:[m];p(g),R(C=>(C+1)%y.length),v(e.clientX,e.clientY,g)},q=W==="custom"&&X!=="none";return x.jsxs(x.Fragment,{children:[x.jsx("style",{dangerouslySetInnerHTML:{__html:Q}}),x.jsxs("div",{ref:h,onClick:V,onMouseEnter:()=>G(!0),onMouseLeave:()=>G(!1),className:`${s}-root`,style:{cursor:q?"none":"default"},children:[f.map(e=>x.jsx("div",{className:`${s}-wrapper`,style:{top:`${e.y}px`,left:`${e.x}px`,width:`${e.widthPx}px`,cursor:q?"none":"default"},children:$==="area"&&e.link?x.jsx("a",{href:e.link,target:"_blank",rel:"noreferrer",className:`${s}-link`,children:x.jsx("img",{src:e.assetId,alt:e.name,className:`${s}-image`})}):x.jsx("img",{src:e.assetId,alt:e.name,className:`${s}-image`})},e.id)),w&&q&&x.jsx("div",{className:`${s}-cursor`,style:{left:`${O.x}px`,top:`${O.y}px`,transform:"translate(-50%, -50%)",backgroundImage:`url('${X}')`,backgroundSize:"cover",backgroundPosition:"center"}})]})]})}exports.ClickGallerie=oe;
@@ -1,111 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),s=require("react"),w=require("classnames"),Fe=require("./useScopedStyles-Bf6yohVQ.js"),Te=100,Me=70,m="cubic-bezier(0.86, 0, 0.07, 1)";function Ce(e){return`
2
- .${e}-wrapper {
3
- position: relative;
4
- width: 100%;
5
- height: 100%;
6
- overflow: hidden;
7
- }
8
- .${e}-background {
9
- position: absolute;
10
- inset: 0;
11
- z-index: 1;
12
- pointer-events: none;
13
- overflow: hidden;
14
- }
15
- .${e}-effect-image {
16
- width: 100%;
17
- height: 100%;
18
- object-fit: cover;
19
- display: block;
20
- }
21
- .${e}-stage {
22
- position: absolute;
23
- left: 50%;
24
- top: 50%;
25
- transform: translate(-50%, -50%) scale(var(--${e}-stage-scale, 1));
26
- overflow: hidden;
27
- }
28
- .${e}-foreground {
29
- z-index: 2;
30
- }
31
- .${e}-incoming {
32
- will-change: transform;
33
- }
34
- .${e}-incoming-next {
35
- z-index: 4;
36
- transition: transform var(--${e}-transition-ms) ${m};
37
- }
38
- .${e}-incoming-prev {
39
- z-index: 4;
40
- transition: transform var(--${e}-transition-ms) ${m};
41
- }
42
- .${e}-outgoing {
43
- will-change: transform;
44
- }
45
- .${e}-outgoing-next {
46
- z-index: 3;
47
- transition: transform var(--${e}-transition-ms) ${m};
48
- }
49
- .${e}-outgoing-prev {
50
- z-index: 3;
51
- transition: transform var(--${e}-transition-ms) ${m};
52
- }
53
- .${e}-outgoing-next .${e}-effect-image {
54
- transition: filter var(--${e}-transition-ms) ${m};
55
- }
56
- .${e}-outgoing-prev .${e}-effect-image {
57
- transition: filter var(--${e}-transition-ms) ${m};
58
- }
59
- .${e}-incoming .${e}-effect-image {
60
- transition: filter var(--${e}-transition-ms) ${m};
61
- }
62
- .${e}-background .${e}-effect-image {
63
- transition: filter var(--${e}-transition-ms) ${m};
64
- }
65
- .${e}-snap .${e}-incoming,
66
- .${e}-snap .${e}-outgoing,
67
- .${e}-snap .${e}-outgoing .${e}-effect-image,
68
- .${e}-snap .${e}-incoming .${e}-effect-image {
69
- transition: none !important;
70
- }
71
- .${e}-nav {
72
- position: absolute;
73
- top: 0;
74
- bottom: 0;
75
- width: 50%;
76
- z-index: 5;
77
- margin: 0;
78
- padding: 0;
79
- border: none;
80
- background: none;
81
- cursor: pointer;
82
- outline: none;
83
- -webkit-tap-highlight-color: transparent;
84
- }
85
- .${e}-nav-prev {
86
- left: 0;
87
- cursor: w-resize;
88
- }
89
- .${e}-nav-next {
90
- right: 0;
91
- cursor: e-resize;
92
- }
93
- .${e}-nav:focus,
94
- .${e}-nav:focus-visible {
95
- outline: none;
96
- }
97
- .${e}-editor .${e}-nav {
98
- cursor: default;
99
- pointer-events: none;
100
- }
101
- .${e}-foreground {
102
- pointer-events: none;
103
- }
104
- .${e}-image {
105
- width: 100%;
106
- height: 100%;
107
- object-fit: contain;
108
- display: block;
109
- pointer-events: none;
110
- }
111
- `}function Re(e){return e==="blur"?Me:e==="greyscale"?Te:0}function T(e,n=1,l=1){const c=Re(e)*Math.max(0,Math.min(1,n));if(e==="greyscale")return`grayscale(${c}%)`;if(e==="blur"){const t=c/4;return t<=0?"none":`blur(${t/Math.max(l,1)}px)`}return"none"}function ue(e){return e<=1?{backgroundIndex:0,activeIndex:0}:{backgroundIndex:0,activeIndex:1}}function Ae(e,n){return n<=1?0:(e-1+n)%n}function Ee(e,n=1){return!e||e.height===0?n:e.width/e.height}function Oe(e,n,l,c,t){if(e<=0||n<=0)return{widthPercent:c,heightPercent:t};const E=e*c/100,M=n*t/100;let y=E,p=y/l;return p>M&&(p=M,y=p*l),{widthPercent:y/e*100,heightPercent:p/n*100}}function de(e,n,l){if(e<=0||n<=0)return 1;const c=e*l.widthPercent/100,t=n*l.heightPercent/100;return c<=0||t<=0?1:Math.max(e/c,n/t)}function fe(e){return{width:`${e.widthPercent}%`,height:`${e.heightPercent}%`}}function he(e,n,l){return{...fe(e),[`--${l}-stage-scale`]:n}}function qe(e,n){[...new Set(e.filter(Boolean))].forEach(c=>{const t=new Image;t.onload=()=>{t.naturalWidth>0&&t.naturalHeight>0&&n(c,{width:t.naturalWidth,height:t.naturalHeight})},t.src=c})}function Be({settings:e,content:n,isEditor:l,isPreviewMode:c}){var ee,te,ne,ie,se,ae,re;const{prefix:t}=Fe.useScopedStyles(),E=s.useMemo(()=>Ce(t),[t]),{imageSize:M,maxWidth:y,maxHeight:p,transition:me=1e3,bgImage:S="greyscale"}=e,i=n??[],L=ue(i.length),[g,D]=s.useState(L.activeIndex),[G,O]=s.useState(L.backgroundIndex),[I,q]=s.useState(!1),[$e,B]=s.useState(!1),[H,C]=s.useState(null),[W,R]=s.useState(null),[xe,z]=s.useState(0),[ve,k]=s.useState(1),[pe,j]=s.useState("none"),[Y,Z]=s.useState("next"),[J,Se]=s.useState({}),[u,Ie]=s.useState({width:0,height:0}),N=s.useRef(null),K=s.useRef(null),_=!l||!!c,Q=M??60,V=Math.max(10,Math.min(100,y??Q)),X=Math.max(10,Math.min(100,p??Q)),U=Math.max(100,me),be=T(S),b=s.useCallback(o=>{const a=Ee(o?J[o]:void 0);return Oe(u.width,u.height,a,V,X)},[u.height,u.width,J,X,V]);s.useEffect(()=>{const o=K.current;if(!o)return;const a=new ResizeObserver(([d])=>{const{width:f,height:v}=d.contentRect;Ie({width:f,height:v})});return a.observe(o),()=>a.disconnect()},[]),s.useEffect(()=>{const o=(n??[]).map(a=>{var d;return(d=a.image)==null?void 0:d.assetId}).filter(a=>!!a);qe(o,(a,d)=>{Se(f=>{var v,F;return((v=f[a])==null?void 0:v.width)===d.width&&((F=f[a])==null?void 0:F.height)===d.height?f:{...f,[a]:d}})})},[n]),s.useEffect(()=>{const{backgroundIndex:o,activeIndex:a}=ue(i.length);D(a),O(o),q(!1),B(!1),C(null),R(null),z(0),k(1),j("none"),Z("next")},[i.length,n]),s.useEffect(()=>()=>{N.current&&clearTimeout(N.current)},[]);const P=s.useCallback(o=>{var oe,ce,le,ge;if(!_||I||i.length<=1)return;const a=o==="next"?(g+1)%i.length:(g-1+i.length)%i.length,d=b((ce=(oe=i[g])==null?void 0:oe.image)==null?void 0:ce.assetId),f=b((ge=(le=i[a])==null?void 0:le.image)==null?void 0:ge.assetId),v=de(u.width,u.height,d),F=de(u.width,u.height,f);N.current&&clearTimeout(N.current),Z(o),B(!0),q(!0),o==="next"?(C(g),R(a),z(0),k(1),j(T(S,0,1))):(O(Ae(a,i.length)),C(a),R(g),z(1),k(F),j(T(S,1,F))),requestAnimationFrame(()=>{B(!1),requestAnimationFrame(()=>{o==="next"?(z(1),k(v),j(T(S,1,v))):(z(0),k(1),j(T(S,0,1)))})}),N.current=setTimeout(()=>{o==="next"&&O(g),D(a),C(null),R(null),q(!1)},U)},[g,S,u.height,u.width,b,I,_,i,U]),h=i[g],A=G!==null?i[G]:null,$=H!==null?i[H]:null,x=W!==null?i[W]:null,we=i.length<=1?0:(g-1+i.length)%i.length,ye=i.length<=1?0:(g+1)%i.length,ze=b((ee=h==null?void 0:h.image)==null?void 0:ee.assetId),ke=b((te=$==null?void 0:$.image)==null?void 0:te.assetId),je=b((ne=x==null?void 0:x.image)==null?void 0:ne.assetId),Ne={[`--${t}-transition-ms`]:`${U}ms`};return r.jsxs(r.Fragment,{children:[r.jsx("style",{dangerouslySetInnerHTML:{__html:E}}),r.jsxs("div",{ref:K,className:w(`${t}-wrapper`,$e&&`${t}-snap`,l&&!c&&`${t}-editor`),style:Ne,"aria-label":"Zoom gallery",children:[((ie=A==null?void 0:A.image)==null?void 0:ie.assetId)&&r.jsx("div",{className:`${t}-background`,"aria-hidden":"true",children:r.jsx("img",{className:`${t}-effect-image`,src:A.image.assetId,alt:"",style:{filter:be}})}),I&&((se=$==null?void 0:$.image)==null?void 0:se.assetId)&&r.jsx("div",{className:w(`${t}-stage`,`${t}-outgoing`,`${t}-outgoing-${Y}`),style:he(ke,ve,t),"aria-hidden":"true",children:r.jsx("img",{className:`${t}-effect-image`,src:$.image.assetId,alt:"",style:{filter:pe}})}),I&&((ae=x==null?void 0:x.image)==null?void 0:ae.assetId)&&r.jsx("div",{className:w(`${t}-stage`,`${t}-incoming`,`${t}-incoming-${Y}`),style:he(je,xe,t),"aria-hidden":"true",children:r.jsx("img",{className:`${t}-image`,src:x.image.assetId,alt:""})}),!I&&((re=h==null?void 0:h.image)==null?void 0:re.assetId)&&r.jsx("div",{className:w(`${t}-stage`,`${t}-foreground`),style:fe(ze),children:r.jsx("img",{className:`${t}-image`,src:h.image.assetId,alt:h.image.name??""})}),_&&i.length>1&&!I&&r.jsxs(r.Fragment,{children:[r.jsx("button",{type:"button",className:w(`${t}-nav`,`${t}-nav-prev`),onClick:()=>P("prev"),"aria-label":`Show previous image (${we+1} of ${i.length})`}),r.jsx("button",{type:"button",className:w(`${t}-nav`,`${t}-nav-next`),onClick:()=>P("next"),"aria-label":`Show next image (${ye+1} of ${i.length})`})]})]})]})}exports.Scale=Be;