@hunterchen/canvas 0.8.0 → 0.9.0
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/components/canvas/backgrounds.js +67 -38
- package/dist/components/canvas/backgrounds.js.map +1 -1
- package/dist/components/canvas/canvas.js +451 -387
- package/dist/components/canvas/canvas.js.map +1 -1
- package/dist/components/canvas/component.js +108 -174
- package/dist/components/canvas/component.js.map +1 -1
- package/dist/components/canvas/draggable.js +168 -151
- package/dist/components/canvas/draggable.js.map +1 -1
- package/dist/components/canvas/navbar/index.js +164 -142
- package/dist/components/canvas/navbar/index.js.map +1 -1
- package/dist/components/canvas/navbar/single-button.js +176 -149
- package/dist/components/canvas/navbar/single-button.js.map +1 -1
- package/dist/components/canvas/toolbar.js +121 -82
- package/dist/components/canvas/toolbar.js.map +1 -1
- package/dist/components/canvas/wrapper.js +127 -99
- package/dist/components/canvas/wrapper.js.map +1 -1
- package/dist/contexts/CanvasContext.js +25 -17
- package/dist/contexts/CanvasContext.js.map +1 -1
- package/dist/contexts/PerformanceContext.js +51 -50
- package/dist/contexts/PerformanceContext.js.map +1 -1
- package/dist/hooks/usePerformanceMode.js +36 -37
- package/dist/hooks/usePerformanceMode.js.map +1 -1
- package/dist/hooks/useWindowDimensions.js +22 -18
- package/dist/hooks/useWindowDimensions.js.map +1 -1
- package/dist/index.js +17 -21
- package/dist/lib/canvas.js +65 -72
- package/dist/lib/canvas.js.map +1 -1
- package/dist/lib/constants.js +78 -92
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/utils.js +10 -5
- package/dist/lib/utils.js.map +1 -1
- package/dist/utils/performance.js +18 -23
- package/dist/utils/performance.js.map +1 -1
- package/package.json +7 -21
- package/dist/components/canvas/offest.js +0 -12
- package/dist/components/canvas/offest.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types/index.js +0 -6
- package/dist/types/index.js.map +0 -1
|
@@ -1,391 +1,455 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
1
|
+
import { CanvasProvider } from "../../contexts/CanvasContext.js";
|
|
2
|
+
import { DEFAULT_CANVAS_HEIGHT, DEFAULT_CANVAS_WIDTH, INTERACTIVE_SELECTOR, MAX_ZOOM, MIN_ZOOMS, MOUSE_WHEEL_ZOOM_SENSITIVITY, STAGE2_TRANSITION, TRACKPAD_ZOOM_SENSITIVITY, ZOOM_BOUND } from "../../lib/constants.js";
|
|
3
|
+
import { calcInitialBoxWidth, getDistance, getMidpoint, getScreenSizeEnum, getSectionPanCoordinates, panToOffsetScene } from "../../lib/canvas.js";
|
|
4
|
+
import useWindowDimensions_default from "../../hooks/useWindowDimensions.js";
|
|
5
|
+
import { usePerformanceMode } from "../../hooks/usePerformanceMode.js";
|
|
6
|
+
import Navbar from "./navbar/index.js";
|
|
7
|
+
import toolbar_default from "./toolbar.js";
|
|
8
|
+
import { CanvasWrapper } from "./wrapper.js";
|
|
9
|
+
import { DefaultCanvasBackground } from "./backgrounds.js";
|
|
10
|
+
import { animate, motion, useMotionValue, useTransform } from "framer-motion";
|
|
11
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
12
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
|
|
14
|
+
//#region src/components/canvas/canvas.tsx
|
|
13
15
|
const stopAllMotion = (x, y, scale) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
x.stop();
|
|
17
|
+
y.stop();
|
|
18
|
+
scale.stop();
|
|
17
19
|
};
|
|
18
|
-
const Canvas = ({ children, homeCoordinates, navItems, skipIntro = false, introContent, loadingText, introBackgroundGradient, canvasBoxGradient, growTransition, blurTransition, canvasBackground, wrapperBackground, toolbarConfig, navbarConfig, canvasHeight, canvasWidth
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
20
|
+
const Canvas = ({ children, homeCoordinates, navItems, skipIntro = false, introContent, loadingText, introBackgroundGradient, canvasBoxGradient, growTransition, blurTransition, canvasBackground, wrapperBackground, toolbarConfig, navbarConfig, canvasHeight, canvasWidth }) => {
|
|
21
|
+
const { height: windowHeight, width: windowWidth } = useWindowDimensions_default();
|
|
22
|
+
const { mode } = usePerformanceMode();
|
|
23
|
+
const hasNavbar = Boolean(navItems && navItems.length > 0);
|
|
24
|
+
const sceneWidth = canvasWidth ?? DEFAULT_CANVAS_WIDTH;
|
|
25
|
+
const sceneHeight = canvasHeight ?? DEFAULT_CANVAS_HEIGHT;
|
|
26
|
+
const MIN_ZOOM = MIN_ZOOMS[getScreenSizeEnum(windowWidth)];
|
|
27
|
+
const [isPanning, setIsPanning] = useState(false);
|
|
28
|
+
const [isSceneMoving, setIsSceneMoving] = useState(false);
|
|
29
|
+
const [panStartPoint, setPanStartPoint] = useState({
|
|
30
|
+
x: 0,
|
|
31
|
+
y: 0
|
|
32
|
+
});
|
|
33
|
+
const [initialPanOffsetOnDrag, setInitialPanOffsetOnDrag] = useState({
|
|
34
|
+
x: 0,
|
|
35
|
+
y: 0
|
|
36
|
+
});
|
|
37
|
+
const [isResetting, setIsResetting] = useState(false);
|
|
38
|
+
const [maxZIndex, setMaxZIndex] = useState(50);
|
|
39
|
+
const [animationStage, setAnimationStage] = useState(0);
|
|
40
|
+
const [nextTargetSection, setNextTargetSection] = useState(null);
|
|
41
|
+
const isIntroAnimatingRef = useRef(true);
|
|
42
|
+
const initialBoxWidth = useMemo(() => calcInitialBoxWidth(windowWidth, windowHeight), [windowWidth, windowHeight]);
|
|
43
|
+
const x = useMotionValue(0);
|
|
44
|
+
const y = useMotionValue(0);
|
|
45
|
+
const scale = useMotionValue(initialBoxWidth);
|
|
46
|
+
const offsetHomeCoordinates = useMemo(() => getSectionPanCoordinates({
|
|
47
|
+
windowDimensions: {
|
|
48
|
+
width: windowWidth,
|
|
49
|
+
height: windowHeight
|
|
50
|
+
},
|
|
51
|
+
coords: homeCoordinates,
|
|
52
|
+
targetZoom: 1
|
|
53
|
+
}), [
|
|
54
|
+
homeCoordinates,
|
|
55
|
+
windowWidth,
|
|
56
|
+
windowHeight
|
|
57
|
+
]);
|
|
58
|
+
const onResetViewAndItems = useCallback((onComplete) => {
|
|
59
|
+
setIsResetting(true);
|
|
60
|
+
panToOffsetScene(offsetHomeCoordinates, x, y, scale, 1).then(() => {
|
|
61
|
+
setIsResetting(false);
|
|
62
|
+
if (onComplete) onComplete();
|
|
63
|
+
});
|
|
64
|
+
}, [
|
|
65
|
+
offsetHomeCoordinates,
|
|
66
|
+
x,
|
|
67
|
+
y,
|
|
68
|
+
scale
|
|
69
|
+
]);
|
|
70
|
+
const introProgress = useMotionValue(0);
|
|
71
|
+
const stage1Targets = useMemo(() => {
|
|
72
|
+
const finalScale = Math.max((windowWidth || 0) / sceneWidth, (windowHeight || 0) / sceneHeight);
|
|
73
|
+
return {
|
|
74
|
+
finalScale,
|
|
75
|
+
endX: (windowWidth - sceneWidth * finalScale) / 2,
|
|
76
|
+
endY: (windowHeight - sceneHeight * finalScale) / 2
|
|
77
|
+
};
|
|
78
|
+
}, [
|
|
79
|
+
windowWidth,
|
|
80
|
+
windowHeight,
|
|
81
|
+
sceneWidth,
|
|
82
|
+
sceneHeight
|
|
83
|
+
]);
|
|
84
|
+
const derivedScale = useTransform(introProgress, [0, 1], [initialBoxWidth, stage1Targets.finalScale]);
|
|
85
|
+
const derivedX = useTransform(introProgress, [0, 1], [0, stage1Targets.endX]);
|
|
86
|
+
const derivedY = useTransform(introProgress, [0, 1], [0, stage1Targets.endY]);
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
const unsubscribeScale = derivedScale.on("change", (v) => {
|
|
89
|
+
if (animationStage === 0) scale.set(v);
|
|
90
|
+
});
|
|
91
|
+
const unsubscribeX = derivedX.on("change", (v) => {
|
|
92
|
+
if (animationStage === 0) x.set(v);
|
|
93
|
+
});
|
|
94
|
+
const unsubscribeY = derivedY.on("change", (v) => {
|
|
95
|
+
if (animationStage === 0) y.set(v);
|
|
96
|
+
});
|
|
97
|
+
return () => {
|
|
98
|
+
unsubscribeScale();
|
|
99
|
+
unsubscribeX();
|
|
100
|
+
unsubscribeY();
|
|
101
|
+
};
|
|
102
|
+
}, [
|
|
103
|
+
derivedScale,
|
|
104
|
+
derivedX,
|
|
105
|
+
derivedY,
|
|
106
|
+
animationStage,
|
|
107
|
+
scale,
|
|
108
|
+
x,
|
|
109
|
+
y
|
|
110
|
+
]);
|
|
111
|
+
const startStage2 = useCallback(() => {
|
|
112
|
+
setAnimationStage(1);
|
|
113
|
+
Promise.all([
|
|
114
|
+
animate(x, offsetHomeCoordinates.x, STAGE2_TRANSITION),
|
|
115
|
+
animate(y, offsetHomeCoordinates.y, STAGE2_TRANSITION),
|
|
116
|
+
animate(scale, 1, STAGE2_TRANSITION)
|
|
117
|
+
]).then(() => {
|
|
118
|
+
setAnimationStage(2);
|
|
119
|
+
isIntroAnimatingRef.current = false;
|
|
120
|
+
}).catch(() => {
|
|
121
|
+
isIntroAnimatingRef.current = false;
|
|
122
|
+
});
|
|
123
|
+
}, [
|
|
124
|
+
offsetHomeCoordinates,
|
|
125
|
+
x,
|
|
126
|
+
y,
|
|
127
|
+
scale
|
|
128
|
+
]);
|
|
129
|
+
const viewportRef = useRef(null);
|
|
130
|
+
const sceneRef = useRef(null);
|
|
131
|
+
const wheelHandlerRef = useRef(null);
|
|
132
|
+
const wheelWrapper = useCallback((e) => {
|
|
133
|
+
wheelHandlerRef.current?.(e);
|
|
134
|
+
}, []);
|
|
135
|
+
const setViewportRef = useCallback((node) => {
|
|
136
|
+
if (viewportRef.current) viewportRef.current.removeEventListener("wheel", wheelWrapper);
|
|
137
|
+
viewportRef.current = node;
|
|
138
|
+
if (node) node.addEventListener("wheel", wheelWrapper, { passive: false });
|
|
139
|
+
}, [wheelWrapper]);
|
|
140
|
+
const activePointersRef = useRef(/* @__PURE__ */ new Map());
|
|
141
|
+
const initialPinchStateRef = useRef(null);
|
|
142
|
+
const panToOffset = useCallback((offset, viewportRef, onComplete, zoom) => {
|
|
143
|
+
if (!viewportRef.current) return;
|
|
144
|
+
setIsSceneMoving(true);
|
|
145
|
+
const viewportWidth = viewportRef.current.offsetWidth;
|
|
146
|
+
const viewportHeight = viewportRef.current.offsetHeight;
|
|
147
|
+
const minPanX = viewportWidth - sceneWidth * (zoom ?? 1);
|
|
148
|
+
const maxPanX = 0;
|
|
149
|
+
const minPanY = viewportHeight - sceneHeight * (zoom ?? 1);
|
|
150
|
+
panToOffsetScene({
|
|
151
|
+
x: Math.min(Math.max(offset.x, minPanX), maxPanX),
|
|
152
|
+
y: Math.min(Math.max(offset.y, minPanY), 0)
|
|
153
|
+
}, x, y, scale, zoom).then(() => {
|
|
154
|
+
setIsSceneMoving(false);
|
|
155
|
+
if (onComplete) onComplete();
|
|
156
|
+
});
|
|
157
|
+
}, [
|
|
158
|
+
sceneWidth,
|
|
159
|
+
sceneHeight,
|
|
160
|
+
x,
|
|
161
|
+
y,
|
|
162
|
+
scale
|
|
163
|
+
]);
|
|
164
|
+
const stopAllSceneMotion = useCallback(() => {
|
|
165
|
+
if (isIntroAnimatingRef.current) return;
|
|
166
|
+
stopAllMotion(x, y, scale);
|
|
167
|
+
}, [
|
|
168
|
+
x,
|
|
169
|
+
y,
|
|
170
|
+
scale
|
|
171
|
+
]);
|
|
172
|
+
const handlePointerDown = useCallback((event) => {
|
|
173
|
+
if (animationStage < 2) return;
|
|
174
|
+
activePointersRef.current.set(event.pointerId, event);
|
|
175
|
+
event.target.setPointerCapture(event.pointerId);
|
|
176
|
+
if (isResetting || isSceneMoving) return;
|
|
177
|
+
stopAllSceneMotion();
|
|
178
|
+
if (activePointersRef.current.size === 1) {
|
|
179
|
+
if (event.target.closest(INTERACTIVE_SELECTOR)) {
|
|
180
|
+
activePointersRef.current.delete(event.pointerId);
|
|
181
|
+
event.target.releasePointerCapture(event.pointerId);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
setIsPanning(true);
|
|
185
|
+
setPanStartPoint({
|
|
186
|
+
x: event.clientX,
|
|
187
|
+
y: event.clientY
|
|
188
|
+
});
|
|
189
|
+
setInitialPanOffsetOnDrag({
|
|
190
|
+
x: x.get(),
|
|
191
|
+
y: y.get()
|
|
192
|
+
});
|
|
193
|
+
if (viewportRef.current) viewportRef.current.style.cursor = "grabbing";
|
|
194
|
+
} else if (activePointersRef.current.size === 2) {
|
|
195
|
+
setIsPanning(false);
|
|
196
|
+
const pointers = Array.from(activePointersRef.current.values());
|
|
197
|
+
initialPinchStateRef.current = {
|
|
198
|
+
distance: getDistance(pointers[0], pointers[1]),
|
|
199
|
+
midpoint: getMidpoint(pointers[0], pointers[1]),
|
|
200
|
+
zoom: scale.get(),
|
|
201
|
+
panOffset: {
|
|
202
|
+
x: x.get(),
|
|
203
|
+
y: y.get()
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
}, [
|
|
208
|
+
isResetting,
|
|
209
|
+
isSceneMoving,
|
|
210
|
+
setIsPanning,
|
|
211
|
+
setPanStartPoint,
|
|
212
|
+
setInitialPanOffsetOnDrag,
|
|
213
|
+
x,
|
|
214
|
+
y,
|
|
215
|
+
scale,
|
|
216
|
+
viewportRef,
|
|
217
|
+
animationStage,
|
|
218
|
+
stopAllSceneMotion
|
|
219
|
+
]);
|
|
220
|
+
const handlePointerMove = useCallback((event) => {
|
|
221
|
+
if (animationStage < 2) return;
|
|
222
|
+
if (isPanning || activePointersRef.current.size >= 2) stopAllSceneMotion();
|
|
223
|
+
if (!activePointersRef.current.has(event.pointerId) || isResetting) return;
|
|
224
|
+
activePointersRef.current.set(event.pointerId, event);
|
|
225
|
+
if (isPanning && activePointersRef.current.size === 1) {
|
|
226
|
+
event.preventDefault();
|
|
227
|
+
const deltaX = event.clientX - panStartPoint.x;
|
|
228
|
+
const deltaY = event.clientY - panStartPoint.y;
|
|
229
|
+
const minPanX = windowWidth - sceneWidth * scale.get();
|
|
230
|
+
const maxPanX = 0;
|
|
231
|
+
const minPanY = windowHeight - sceneHeight * scale.get();
|
|
232
|
+
const maxPanY = 0;
|
|
233
|
+
const newX = Math.min(Math.max(initialPanOffsetOnDrag.x + deltaX, minPanX), maxPanX);
|
|
234
|
+
const newY = Math.min(Math.max(initialPanOffsetOnDrag.y + deltaY, minPanY), maxPanY);
|
|
235
|
+
x.set(newX);
|
|
236
|
+
y.set(newY);
|
|
237
|
+
} else if (activePointersRef.current.size >= 2 && initialPinchStateRef.current) {
|
|
238
|
+
event.preventDefault();
|
|
239
|
+
const pointers = Array.from(activePointersRef.current.values());
|
|
240
|
+
const p1 = pointers[0];
|
|
241
|
+
const p2 = pointers[1];
|
|
242
|
+
const currentDistance = getDistance(p1, p2);
|
|
243
|
+
const currentMidpoint = getMidpoint(p1, p2);
|
|
244
|
+
const { distance: initialDistance, zoom: initialZoom, panOffset: initialPanOffsetPinch } = initialPinchStateRef.current;
|
|
245
|
+
if (initialDistance === 0) return;
|
|
246
|
+
let newZoom = initialZoom * (currentDistance / initialDistance);
|
|
247
|
+
newZoom = Math.max(window.innerWidth / sceneWidth * ZOOM_BOUND, window.innerHeight / sceneHeight * ZOOM_BOUND, Math.min(newZoom, 10), MIN_ZOOM);
|
|
248
|
+
const mx = currentMidpoint.x;
|
|
249
|
+
const my = currentMidpoint.y;
|
|
250
|
+
const minPanX = windowWidth - sceneWidth * newZoom;
|
|
251
|
+
const maxPanX = 0;
|
|
252
|
+
const minPanY = windowHeight - sceneHeight * newZoom;
|
|
253
|
+
const maxPanY = 0;
|
|
254
|
+
let newPanX = mx - (mx - initialPanOffsetPinch.x) / initialZoom * newZoom;
|
|
255
|
+
let newPanY = my - (my - initialPanOffsetPinch.y) / initialZoom * newZoom;
|
|
256
|
+
newPanX = Math.min(Math.max(newPanX, minPanX), maxPanX);
|
|
257
|
+
newPanY = Math.min(Math.max(newPanY, minPanY), maxPanY);
|
|
258
|
+
scale.set(newZoom);
|
|
259
|
+
x.set(newPanX);
|
|
260
|
+
y.set(newPanY);
|
|
261
|
+
}
|
|
262
|
+
}, [
|
|
263
|
+
isPanning,
|
|
264
|
+
isResetting,
|
|
265
|
+
x,
|
|
266
|
+
y,
|
|
267
|
+
scale,
|
|
268
|
+
panStartPoint.x,
|
|
269
|
+
panStartPoint.y,
|
|
270
|
+
windowWidth,
|
|
271
|
+
sceneWidth,
|
|
272
|
+
windowHeight,
|
|
273
|
+
sceneHeight,
|
|
274
|
+
initialPanOffsetOnDrag.x,
|
|
275
|
+
initialPanOffsetOnDrag.y,
|
|
276
|
+
MIN_ZOOM,
|
|
277
|
+
animationStage,
|
|
278
|
+
stopAllSceneMotion
|
|
279
|
+
]);
|
|
280
|
+
const handlePointerUpOrCancel = useCallback((event) => {
|
|
281
|
+
if (animationStage < 2) {
|
|
282
|
+
event.preventDefault();
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
stopAllSceneMotion();
|
|
286
|
+
event.preventDefault();
|
|
287
|
+
if (event.target.hasPointerCapture(event.pointerId)) event.target.releasePointerCapture(event.pointerId);
|
|
288
|
+
activePointersRef.current.delete(event.pointerId);
|
|
289
|
+
if (isPanning && activePointersRef.current.size < 1) {
|
|
290
|
+
setIsPanning(false);
|
|
291
|
+
if (viewportRef.current) viewportRef.current.style.cursor = "url('/customcursor.svg'), grab";
|
|
292
|
+
}
|
|
293
|
+
if (initialPinchStateRef.current && activePointersRef.current.size < 2) initialPinchStateRef.current = null;
|
|
294
|
+
if (!isPanning && activePointersRef.current.size === 1 && !initialPinchStateRef.current) {
|
|
295
|
+
const lastPointer = Array.from(activePointersRef.current.values())[0];
|
|
296
|
+
setIsPanning(true);
|
|
297
|
+
setPanStartPoint({
|
|
298
|
+
x: lastPointer.clientX,
|
|
299
|
+
y: lastPointer.clientY
|
|
300
|
+
});
|
|
301
|
+
setInitialPanOffsetOnDrag({
|
|
302
|
+
x: x.get(),
|
|
303
|
+
y: y.get()
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
}, [
|
|
307
|
+
x,
|
|
308
|
+
y,
|
|
309
|
+
isPanning,
|
|
310
|
+
animationStage,
|
|
311
|
+
stopAllSceneMotion
|
|
312
|
+
]);
|
|
313
|
+
const handleWheelZoom = useCallback((event) => {
|
|
314
|
+
if (animationStage < 2) {
|
|
315
|
+
event.preventDefault();
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
event.preventDefault();
|
|
319
|
+
const isPinch = event.ctrlKey || event.metaKey;
|
|
320
|
+
const ZOOM_SENSITIVITY = event.deltaMode === WheelEvent.DOM_DELTA_LINE || Math.abs(event.deltaY) >= 100 ? MOUSE_WHEEL_ZOOM_SENSITIVITY : TRACKPAD_ZOOM_SENSITIVITY;
|
|
321
|
+
if (isPinch) {
|
|
322
|
+
const currentZoom = scale.get();
|
|
323
|
+
const nextZoom = Math.max(Math.min(currentZoom * (1 - event.deltaY * ZOOM_SENSITIVITY), MAX_ZOOM), MIN_ZOOM, window.innerWidth / sceneWidth * ZOOM_BOUND, window.innerHeight / sceneHeight * ZOOM_BOUND);
|
|
324
|
+
const rect = viewportRef.current?.getBoundingClientRect();
|
|
325
|
+
if (!rect) return;
|
|
326
|
+
const vpLeft = rect.left;
|
|
327
|
+
const vpTop = rect.top;
|
|
328
|
+
const viewportWidth = rect.width;
|
|
329
|
+
const viewportHeight = rect.height;
|
|
330
|
+
const cursorSceneX = (event.clientX - vpLeft - x.get()) / currentZoom;
|
|
331
|
+
const cursorSceneY = (event.clientY - vpTop - y.get()) / currentZoom;
|
|
332
|
+
let newPanX = event.clientX - vpLeft - cursorSceneX * nextZoom;
|
|
333
|
+
let newPanY = event.clientY - vpTop - cursorSceneY * nextZoom;
|
|
334
|
+
const minPanX = viewportWidth - sceneWidth * nextZoom;
|
|
335
|
+
const minPanY = viewportHeight - sceneHeight * nextZoom;
|
|
336
|
+
const maxPanX = 0;
|
|
337
|
+
const maxPanY = 0;
|
|
338
|
+
newPanX = Math.min(maxPanX, Math.max(minPanX, newPanX));
|
|
339
|
+
newPanY = Math.min(maxPanY, Math.max(minPanY, newPanY));
|
|
340
|
+
x.set(newPanX);
|
|
341
|
+
y.set(newPanY);
|
|
342
|
+
scale.set(nextZoom);
|
|
343
|
+
} else {
|
|
344
|
+
stopAllSceneMotion();
|
|
345
|
+
const scrollSpeed = 1;
|
|
346
|
+
const newPanX = x.get() - event.deltaX * scrollSpeed;
|
|
347
|
+
const newPanY = y.get() - event.deltaY * scrollSpeed;
|
|
348
|
+
const minPanX = windowWidth - sceneWidth * scale.get();
|
|
349
|
+
const maxPanX = 0;
|
|
350
|
+
const minPanY = windowHeight - sceneHeight * scale.get();
|
|
351
|
+
const maxPanY = 0;
|
|
352
|
+
const clampedPanX = Math.min(Math.max(newPanX, minPanX), maxPanX);
|
|
353
|
+
const clampedPanY = Math.min(Math.max(newPanY, minPanY), maxPanY);
|
|
354
|
+
x.set(clampedPanX);
|
|
355
|
+
y.set(clampedPanY);
|
|
356
|
+
}
|
|
357
|
+
}, [
|
|
358
|
+
scale,
|
|
359
|
+
MIN_ZOOM,
|
|
360
|
+
x,
|
|
361
|
+
y,
|
|
362
|
+
sceneWidth,
|
|
363
|
+
sceneHeight,
|
|
364
|
+
windowWidth,
|
|
365
|
+
windowHeight,
|
|
366
|
+
animationStage,
|
|
367
|
+
stopAllSceneMotion
|
|
368
|
+
]);
|
|
369
|
+
useEffect(() => {
|
|
370
|
+
wheelHandlerRef.current = handleWheelZoom;
|
|
371
|
+
}, [handleWheelZoom]);
|
|
372
|
+
const handlePanToOffset = useCallback((offset, onComplete, zoom) => {
|
|
373
|
+
panToOffset({
|
|
374
|
+
x: -offset.x,
|
|
375
|
+
y: -offset.y
|
|
376
|
+
}, viewportRef, onComplete, zoom);
|
|
377
|
+
}, [panToOffset, viewportRef]);
|
|
378
|
+
return /* @__PURE__ */ jsx(CanvasWrapper, {
|
|
379
|
+
introProgress,
|
|
380
|
+
onIntroGrowComplete: startStage2,
|
|
381
|
+
skipIntro,
|
|
382
|
+
introContent,
|
|
383
|
+
loadingText,
|
|
384
|
+
introBackgroundGradient,
|
|
385
|
+
wrapperBackground,
|
|
386
|
+
canvasBoxGradient,
|
|
387
|
+
growTransition,
|
|
388
|
+
blurTransition,
|
|
389
|
+
children: /* @__PURE__ */ jsxs(CanvasProvider, {
|
|
390
|
+
x,
|
|
391
|
+
y,
|
|
392
|
+
scale,
|
|
393
|
+
isResetting,
|
|
394
|
+
maxZIndex,
|
|
395
|
+
setMaxZIndex,
|
|
396
|
+
animationStage,
|
|
397
|
+
nextTargetSection,
|
|
398
|
+
setNextTargetSection,
|
|
399
|
+
children: [animationStage >= 2 && /* @__PURE__ */ jsxs(Fragment, { children: [!toolbarConfig?.hidden && /* @__PURE__ */ jsx(toolbar_default, {
|
|
400
|
+
homeCoordinates: offsetHomeCoordinates,
|
|
401
|
+
config: toolbarConfig
|
|
402
|
+
}), hasNavbar && navItems && !navbarConfig?.hidden && /* @__PURE__ */ jsx(Navbar, {
|
|
403
|
+
panToOffset: handlePanToOffset,
|
|
404
|
+
onReset: onResetViewAndItems,
|
|
405
|
+
items: navItems,
|
|
406
|
+
config: navbarConfig
|
|
407
|
+
})] }), /* @__PURE__ */ jsx("div", {
|
|
408
|
+
ref: setViewportRef,
|
|
409
|
+
className: "relative h-full w-full touch-none select-none overflow-hidden",
|
|
410
|
+
style: {
|
|
411
|
+
touchAction: "none",
|
|
412
|
+
pointerEvents: animationStage >= 2 ? "auto" : "none",
|
|
413
|
+
overscrollBehavior: "contain"
|
|
414
|
+
},
|
|
415
|
+
onPointerDown: handlePointerDown,
|
|
416
|
+
onPointerMove: handlePointerMove,
|
|
417
|
+
onPointerUp: handlePointerUpOrCancel,
|
|
418
|
+
onPointerLeave: handlePointerUpOrCancel,
|
|
419
|
+
onPointerCancel: handlePointerUpOrCancel,
|
|
420
|
+
children: /* @__PURE__ */ jsxs(motion.div, {
|
|
421
|
+
ref: sceneRef,
|
|
422
|
+
className: "absolute z-20 origin-top-left",
|
|
423
|
+
initial: { opacity: 0 },
|
|
424
|
+
animate: { opacity: 1 },
|
|
425
|
+
transition: {
|
|
426
|
+
duration: .3,
|
|
427
|
+
ease: "easeIn"
|
|
428
|
+
},
|
|
429
|
+
style: {
|
|
430
|
+
width: `${sceneWidth}px`,
|
|
431
|
+
height: `${sceneHeight}px`,
|
|
432
|
+
x,
|
|
433
|
+
y,
|
|
434
|
+
scale,
|
|
435
|
+
willChange: mode !== "high" && (animationStage < 2 || isPanning) ? "transform" : "auto"
|
|
436
|
+
},
|
|
437
|
+
children: [canvasBackground !== void 0 ? canvasBackground : /* @__PURE__ */ jsx(Fragment, { children: animationStage >= 1 && mode === "high" ? /* @__PURE__ */ jsx(motion.div, {
|
|
438
|
+
initial: { opacity: 0 },
|
|
439
|
+
animate: { opacity: 1 },
|
|
440
|
+
transition: {
|
|
441
|
+
duration: .5,
|
|
442
|
+
ease: "easeIn"
|
|
443
|
+
},
|
|
444
|
+
children: /* @__PURE__ */ jsx(DefaultCanvasBackground, {})
|
|
445
|
+
}) : /* @__PURE__ */ jsx(DefaultCanvasBackground, {}) }), children]
|
|
446
|
+
})
|
|
447
|
+
})]
|
|
448
|
+
})
|
|
449
|
+
});
|
|
389
450
|
};
|
|
390
|
-
|
|
451
|
+
var canvas_default = Canvas;
|
|
452
|
+
|
|
453
|
+
//#endregion
|
|
454
|
+
export { canvas_default as default };
|
|
391
455
|
//# sourceMappingURL=canvas.js.map
|