@cntrl-site/components 0.1.8-0 → 0.1.8-1
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/index.js +34 -46
- package/dist/index.mjs +35 -47
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1105,19 +1105,37 @@ function ImageRevealSlider({ settings, content, isEditor }) {
|
|
|
1105
1105
|
const [counter, setCounter] = React.useState(0);
|
|
1106
1106
|
const imageIdCounter = React.useRef(0);
|
|
1107
1107
|
const defaultScale = 32;
|
|
1108
|
-
const [cursorCenter, setCursorCenter] = React.useState({ x:
|
|
1108
|
+
const [cursorCenter, setCursorCenter] = React.useState({ x: 0, y: 0 });
|
|
1109
1109
|
const [cursorSize, setCursorSize] = React.useState({ w: 32, h: 32 });
|
|
1110
1110
|
const [customCursorImg, setCustomCursorImg] = React.useState("none");
|
|
1111
1111
|
const lastMousePos = React.useRef({ x: 0, y: 0 });
|
|
1112
1112
|
const [isInside, setIsInside] = React.useState(false);
|
|
1113
|
+
const { sizeType, imageWidth: customWidth, randomRangeImageWidth: randomRange } = settings.imageSize;
|
|
1114
|
+
const { revealPosition, visible } = settings.position;
|
|
1115
|
+
const { cursorType, target, defaultCursorScale, defaultCursor, hoverCursorScale, hoverCursor } = settings.cursor;
|
|
1113
1116
|
React.useEffect(() => {
|
|
1114
1117
|
if (!divRef) return;
|
|
1115
1118
|
const updateCursorPosition = (clientX, clientY) => {
|
|
1116
1119
|
const rect = divRef.getBoundingClientRect();
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1120
|
+
const x = clientX - rect.left;
|
|
1121
|
+
const y = clientY - rect.top;
|
|
1122
|
+
setCursorCenter({ x, y });
|
|
1123
|
+
if (cursorType === "system") {
|
|
1124
|
+
setCustomCursorImg("none");
|
|
1125
|
+
setCursorSize({ w: defaultScale, h: defaultScale });
|
|
1126
|
+
return;
|
|
1127
|
+
}
|
|
1128
|
+
const cx = x;
|
|
1129
|
+
const cy = y;
|
|
1130
|
+
const el = document.elementFromPoint(rect.left + cx, rect.top + cy);
|
|
1131
|
+
if (el && el.closest("a")) {
|
|
1132
|
+
setCustomCursorImg("none");
|
|
1133
|
+
setCursorSize({ w: defaultScale, h: defaultScale });
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1136
|
+
const next = isMouseOverImage(cx, cy, placedImages) || target === "area" ? { img: hoverCursor ?? "none", w: defaultScale * hoverCursorScale, h: defaultScale * hoverCursorScale } : { img: defaultCursor ?? "none", w: defaultScale * defaultCursorScale, h: defaultScale * defaultCursorScale };
|
|
1137
|
+
setCustomCursorImg(next.img);
|
|
1138
|
+
setCursorSize({ w: next.w, h: next.h });
|
|
1121
1139
|
};
|
|
1122
1140
|
const mouseMove = (e) => {
|
|
1123
1141
|
e.stopPropagation();
|
|
@@ -1134,42 +1152,9 @@ function ImageRevealSlider({ settings, content, isEditor }) {
|
|
|
1134
1152
|
divRef.removeEventListener("mousemove", mouseMove);
|
|
1135
1153
|
window.removeEventListener("scroll", handleScroll, true);
|
|
1136
1154
|
};
|
|
1137
|
-
}, [divRef, isInside]);
|
|
1138
|
-
React.useEffect(() => {
|
|
1139
|
-
if (!isInside) {
|
|
1140
|
-
setCustomCursorImg("none");
|
|
1141
|
-
setCursorSize({ w: 0, h: 0 });
|
|
1142
|
-
}
|
|
1143
|
-
}, [isInside]);
|
|
1144
|
-
const { sizeType, imageWidth: customWidth, randomRangeImageWidth: randomRange } = settings.imageSize;
|
|
1145
|
-
const { revealPosition, visible } = settings.position;
|
|
1146
|
-
const { cursorType, target, defaultCursorScale, defaultCursor, hoverCursorScale, hoverCursor } = settings.cursor;
|
|
1147
|
-
React.useEffect(() => {
|
|
1148
|
-
const updateCursor = () => {
|
|
1149
|
-
if (!divRef) return;
|
|
1150
|
-
if (cursorType === "system") {
|
|
1151
|
-
setCustomCursorImg("none");
|
|
1152
|
-
setCursorSize({ w: defaultScale, h: defaultScale });
|
|
1153
|
-
return;
|
|
1154
|
-
}
|
|
1155
|
-
const cx = cursorCenter.x;
|
|
1156
|
-
const cy = cursorCenter.y;
|
|
1157
|
-
const rect = divRef.getBoundingClientRect();
|
|
1158
|
-
const el = document.elementFromPoint(
|
|
1159
|
-
rect.left + cx,
|
|
1160
|
-
rect.top + cy
|
|
1161
|
-
);
|
|
1162
|
-
if (el && el.closest("a")) {
|
|
1163
|
-
setCustomCursorImg("none");
|
|
1164
|
-
setCursorSize({ w: defaultScale, h: defaultScale });
|
|
1165
|
-
return;
|
|
1166
|
-
}
|
|
1167
|
-
const next = isMouseOverImage(cx, cy, placedImages) || target === "area" ? { img: hoverCursor ?? "none", w: defaultScale * hoverCursorScale, h: defaultScale * hoverCursorScale } : { img: defaultCursor ?? "none", w: defaultScale * defaultCursorScale, h: defaultScale * defaultCursorScale };
|
|
1168
|
-
setCustomCursorImg(next.img);
|
|
1169
|
-
setCursorSize({ w: next.w, h: next.h });
|
|
1170
|
-
};
|
|
1171
|
-
updateCursor();
|
|
1172
1155
|
}, [
|
|
1156
|
+
divRef,
|
|
1157
|
+
isInside,
|
|
1173
1158
|
cursorCenter,
|
|
1174
1159
|
cursorType,
|
|
1175
1160
|
target,
|
|
@@ -1177,8 +1162,15 @@ function ImageRevealSlider({ settings, content, isEditor }) {
|
|
|
1177
1162
|
defaultCursor,
|
|
1178
1163
|
hoverCursorScale,
|
|
1179
1164
|
defaultCursorScale,
|
|
1180
|
-
placedImages
|
|
1165
|
+
placedImages,
|
|
1166
|
+
window.scrollY
|
|
1181
1167
|
]);
|
|
1168
|
+
React.useEffect(() => {
|
|
1169
|
+
if (!isInside) {
|
|
1170
|
+
setCustomCursorImg("none");
|
|
1171
|
+
setCursorSize({ w: 0, h: 0 });
|
|
1172
|
+
}
|
|
1173
|
+
}, [isInside]);
|
|
1182
1174
|
const createNewImage = async (imgData, containerWidth, containerHeight, position = {}) => {
|
|
1183
1175
|
const { width, height, finalWidth } = await calculateImageWidthHeight(
|
|
1184
1176
|
imgData.image.url,
|
|
@@ -1206,10 +1198,6 @@ function ImageRevealSlider({ settings, content, isEditor }) {
|
|
|
1206
1198
|
width: finalWidth
|
|
1207
1199
|
};
|
|
1208
1200
|
};
|
|
1209
|
-
const defaultContentUrls = React.useMemo(() => {
|
|
1210
|
-
const defaultContentLength = Math.min(content.length, 1);
|
|
1211
|
-
return content.filter((_, i) => i < defaultContentLength).map((c) => c.image.url).join("-");
|
|
1212
|
-
}, [content]);
|
|
1213
1201
|
React.useEffect(() => {
|
|
1214
1202
|
if (!divRef || content.length === 0) return;
|
|
1215
1203
|
const rect = divRef.getBoundingClientRect();
|
|
@@ -1226,7 +1214,7 @@ function ImageRevealSlider({ settings, content, isEditor }) {
|
|
|
1226
1214
|
setCounter(1 % content.length);
|
|
1227
1215
|
};
|
|
1228
1216
|
placeImages();
|
|
1229
|
-
}, [
|
|
1217
|
+
}, [sizeType, customWidth, randomRange, revealPosition, divRef]);
|
|
1230
1218
|
React.useEffect(() => {
|
|
1231
1219
|
if (visible === "last One") {
|
|
1232
1220
|
setPlacedImages((prev) => prev.length > 0 ? [prev[prev.length - 1]] : []);
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import React, { useState, useEffect, useRef,
|
|
2
|
+
import React, { useState, useEffect, useRef, useCallback } from "react";
|
|
3
3
|
import { Splide, SplideSlide } from "@splidejs/react-splide";
|
|
4
4
|
import cn from "classnames";
|
|
5
5
|
import { createPortal } from "react-dom";
|
|
@@ -1103,19 +1103,37 @@ function ImageRevealSlider({ settings, content, isEditor }) {
|
|
|
1103
1103
|
const [counter, setCounter] = useState(0);
|
|
1104
1104
|
const imageIdCounter = useRef(0);
|
|
1105
1105
|
const defaultScale = 32;
|
|
1106
|
-
const [cursorCenter, setCursorCenter] = useState({ x:
|
|
1106
|
+
const [cursorCenter, setCursorCenter] = useState({ x: 0, y: 0 });
|
|
1107
1107
|
const [cursorSize, setCursorSize] = useState({ w: 32, h: 32 });
|
|
1108
1108
|
const [customCursorImg, setCustomCursorImg] = useState("none");
|
|
1109
1109
|
const lastMousePos = useRef({ x: 0, y: 0 });
|
|
1110
1110
|
const [isInside, setIsInside] = useState(false);
|
|
1111
|
+
const { sizeType, imageWidth: customWidth, randomRangeImageWidth: randomRange } = settings.imageSize;
|
|
1112
|
+
const { revealPosition, visible } = settings.position;
|
|
1113
|
+
const { cursorType, target, defaultCursorScale, defaultCursor, hoverCursorScale, hoverCursor } = settings.cursor;
|
|
1111
1114
|
useEffect(() => {
|
|
1112
1115
|
if (!divRef) return;
|
|
1113
1116
|
const updateCursorPosition = (clientX, clientY) => {
|
|
1114
1117
|
const rect = divRef.getBoundingClientRect();
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1118
|
+
const x = clientX - rect.left;
|
|
1119
|
+
const y = clientY - rect.top;
|
|
1120
|
+
setCursorCenter({ x, y });
|
|
1121
|
+
if (cursorType === "system") {
|
|
1122
|
+
setCustomCursorImg("none");
|
|
1123
|
+
setCursorSize({ w: defaultScale, h: defaultScale });
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
const cx = x;
|
|
1127
|
+
const cy = y;
|
|
1128
|
+
const el = document.elementFromPoint(rect.left + cx, rect.top + cy);
|
|
1129
|
+
if (el && el.closest("a")) {
|
|
1130
|
+
setCustomCursorImg("none");
|
|
1131
|
+
setCursorSize({ w: defaultScale, h: defaultScale });
|
|
1132
|
+
return;
|
|
1133
|
+
}
|
|
1134
|
+
const next = isMouseOverImage(cx, cy, placedImages) || target === "area" ? { img: hoverCursor ?? "none", w: defaultScale * hoverCursorScale, h: defaultScale * hoverCursorScale } : { img: defaultCursor ?? "none", w: defaultScale * defaultCursorScale, h: defaultScale * defaultCursorScale };
|
|
1135
|
+
setCustomCursorImg(next.img);
|
|
1136
|
+
setCursorSize({ w: next.w, h: next.h });
|
|
1119
1137
|
};
|
|
1120
1138
|
const mouseMove = (e) => {
|
|
1121
1139
|
e.stopPropagation();
|
|
@@ -1132,42 +1150,9 @@ function ImageRevealSlider({ settings, content, isEditor }) {
|
|
|
1132
1150
|
divRef.removeEventListener("mousemove", mouseMove);
|
|
1133
1151
|
window.removeEventListener("scroll", handleScroll, true);
|
|
1134
1152
|
};
|
|
1135
|
-
}, [divRef, isInside]);
|
|
1136
|
-
useEffect(() => {
|
|
1137
|
-
if (!isInside) {
|
|
1138
|
-
setCustomCursorImg("none");
|
|
1139
|
-
setCursorSize({ w: 0, h: 0 });
|
|
1140
|
-
}
|
|
1141
|
-
}, [isInside]);
|
|
1142
|
-
const { sizeType, imageWidth: customWidth, randomRangeImageWidth: randomRange } = settings.imageSize;
|
|
1143
|
-
const { revealPosition, visible } = settings.position;
|
|
1144
|
-
const { cursorType, target, defaultCursorScale, defaultCursor, hoverCursorScale, hoverCursor } = settings.cursor;
|
|
1145
|
-
useEffect(() => {
|
|
1146
|
-
const updateCursor = () => {
|
|
1147
|
-
if (!divRef) return;
|
|
1148
|
-
if (cursorType === "system") {
|
|
1149
|
-
setCustomCursorImg("none");
|
|
1150
|
-
setCursorSize({ w: defaultScale, h: defaultScale });
|
|
1151
|
-
return;
|
|
1152
|
-
}
|
|
1153
|
-
const cx = cursorCenter.x;
|
|
1154
|
-
const cy = cursorCenter.y;
|
|
1155
|
-
const rect = divRef.getBoundingClientRect();
|
|
1156
|
-
const el = document.elementFromPoint(
|
|
1157
|
-
rect.left + cx,
|
|
1158
|
-
rect.top + cy
|
|
1159
|
-
);
|
|
1160
|
-
if (el && el.closest("a")) {
|
|
1161
|
-
setCustomCursorImg("none");
|
|
1162
|
-
setCursorSize({ w: defaultScale, h: defaultScale });
|
|
1163
|
-
return;
|
|
1164
|
-
}
|
|
1165
|
-
const next = isMouseOverImage(cx, cy, placedImages) || target === "area" ? { img: hoverCursor ?? "none", w: defaultScale * hoverCursorScale, h: defaultScale * hoverCursorScale } : { img: defaultCursor ?? "none", w: defaultScale * defaultCursorScale, h: defaultScale * defaultCursorScale };
|
|
1166
|
-
setCustomCursorImg(next.img);
|
|
1167
|
-
setCursorSize({ w: next.w, h: next.h });
|
|
1168
|
-
};
|
|
1169
|
-
updateCursor();
|
|
1170
1153
|
}, [
|
|
1154
|
+
divRef,
|
|
1155
|
+
isInside,
|
|
1171
1156
|
cursorCenter,
|
|
1172
1157
|
cursorType,
|
|
1173
1158
|
target,
|
|
@@ -1175,8 +1160,15 @@ function ImageRevealSlider({ settings, content, isEditor }) {
|
|
|
1175
1160
|
defaultCursor,
|
|
1176
1161
|
hoverCursorScale,
|
|
1177
1162
|
defaultCursorScale,
|
|
1178
|
-
placedImages
|
|
1163
|
+
placedImages,
|
|
1164
|
+
window.scrollY
|
|
1179
1165
|
]);
|
|
1166
|
+
useEffect(() => {
|
|
1167
|
+
if (!isInside) {
|
|
1168
|
+
setCustomCursorImg("none");
|
|
1169
|
+
setCursorSize({ w: 0, h: 0 });
|
|
1170
|
+
}
|
|
1171
|
+
}, [isInside]);
|
|
1180
1172
|
const createNewImage = async (imgData, containerWidth, containerHeight, position = {}) => {
|
|
1181
1173
|
const { width, height, finalWidth } = await calculateImageWidthHeight(
|
|
1182
1174
|
imgData.image.url,
|
|
@@ -1204,10 +1196,6 @@ function ImageRevealSlider({ settings, content, isEditor }) {
|
|
|
1204
1196
|
width: finalWidth
|
|
1205
1197
|
};
|
|
1206
1198
|
};
|
|
1207
|
-
const defaultContentUrls = useMemo(() => {
|
|
1208
|
-
const defaultContentLength = Math.min(content.length, 1);
|
|
1209
|
-
return content.filter((_, i) => i < defaultContentLength).map((c) => c.image.url).join("-");
|
|
1210
|
-
}, [content]);
|
|
1211
1199
|
useEffect(() => {
|
|
1212
1200
|
if (!divRef || content.length === 0) return;
|
|
1213
1201
|
const rect = divRef.getBoundingClientRect();
|
|
@@ -1224,7 +1212,7 @@ function ImageRevealSlider({ settings, content, isEditor }) {
|
|
|
1224
1212
|
setCounter(1 % content.length);
|
|
1225
1213
|
};
|
|
1226
1214
|
placeImages();
|
|
1227
|
-
}, [
|
|
1215
|
+
}, [sizeType, customWidth, randomRange, revealPosition, divRef]);
|
|
1228
1216
|
useEffect(() => {
|
|
1229
1217
|
if (visible === "last One") {
|
|
1230
1218
|
setPlacedImages((prev) => prev.length > 0 ? [prev[prev.length - 1]] : []);
|