catchup-library-web 1.21.9 → 1.21.11

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 CHANGED
@@ -5819,32 +5819,41 @@ var MatchingActivityMaterialContent = ({
5819
5819
  ).answerMap = materialMap;
5820
5820
  }, [showCorrectAnswer, answer, materialMap]);
5821
5821
  (0, import_react21.useEffect)(() => {
5822
- if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
5823
- const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5824
- if (dropZoneElement) {
5825
- const targetPosition = dropZoneElement.getBoundingClientRect().top + window.pageYOffset;
5826
- const startPosition = window.pageYOffset;
5827
- const distance = targetPosition - startPosition - window.innerHeight / 2 + dropZoneElement.offsetHeight / 2;
5828
- const duration = 800;
5829
- let start = null;
5830
- const easeInOutQuad = (t) => {
5831
- return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
5832
- };
5833
- const animation = (currentTime) => {
5834
- if (start === null) start = currentTime;
5835
- const timeElapsed = currentTime - start;
5836
- const progress = Math.min(timeElapsed / duration, 1);
5837
- window.scrollTo(
5838
- 0,
5839
- startPosition + distance * easeInOutQuad(progress)
5840
- );
5841
- if (timeElapsed < duration) {
5842
- requestAnimationFrame(animation);
5843
- }
5844
- };
5845
- requestAnimationFrame(animation);
5822
+ if (!dropTargetKey || !dropZoneRefs.current[dropTargetKey]) return;
5823
+ const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5824
+ if (!dropZoneElement) return;
5825
+ const rect = dropZoneElement.getBoundingClientRect();
5826
+ const elementTop = rect.top + window.scrollY;
5827
+ const elementHeight = rect.height;
5828
+ const viewportHeight = window.innerHeight;
5829
+ const targetScroll = elementTop - viewportHeight / 2 + elementHeight / 2;
5830
+ const startScroll = window.scrollY;
5831
+ const distance = targetScroll - startScroll;
5832
+ console.log("Scrolling to element:", dropTargetKey);
5833
+ console.log("Current scroll:", startScroll);
5834
+ console.log("Target scroll:", targetScroll);
5835
+ console.log("Distance:", distance);
5836
+ if (Math.abs(distance) < 10) return;
5837
+ const duration = 800;
5838
+ let startTime = null;
5839
+ const easeInOutQuad = (t) => {
5840
+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
5841
+ };
5842
+ const animate = (currentTime) => {
5843
+ if (startTime === null) startTime = currentTime;
5844
+ console.log("startTime:", startTime);
5845
+ const elapsed = currentTime - startTime;
5846
+ console.log("elapsed:", elapsed);
5847
+ const progress = Math.min(elapsed / duration, 1);
5848
+ console.log("progress:", progress);
5849
+ const easedProgress = easeInOutQuad(progress);
5850
+ console.log("eased progressed: ", easedProgress);
5851
+ window.scrollTo(0, startScroll + distance * easedProgress);
5852
+ if (progress < 1) {
5853
+ requestAnimationFrame(animate);
5846
5854
  }
5847
- }
5855
+ };
5856
+ requestAnimationFrame(animate);
5848
5857
  }, [dropTargetKey]);
5849
5858
  const retrieveAnswerMap = () => {
5850
5859
  const foundIndex = answer.data.findIndex(
package/dist/index.mjs CHANGED
@@ -5603,32 +5603,41 @@ var MatchingActivityMaterialContent = ({
5603
5603
  ).answerMap = materialMap;
5604
5604
  }, [showCorrectAnswer, answer, materialMap]);
5605
5605
  useEffect11(() => {
5606
- if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
5607
- const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5608
- if (dropZoneElement) {
5609
- const targetPosition = dropZoneElement.getBoundingClientRect().top + window.pageYOffset;
5610
- const startPosition = window.pageYOffset;
5611
- const distance = targetPosition - startPosition - window.innerHeight / 2 + dropZoneElement.offsetHeight / 2;
5612
- const duration = 800;
5613
- let start = null;
5614
- const easeInOutQuad = (t) => {
5615
- return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
5616
- };
5617
- const animation = (currentTime) => {
5618
- if (start === null) start = currentTime;
5619
- const timeElapsed = currentTime - start;
5620
- const progress = Math.min(timeElapsed / duration, 1);
5621
- window.scrollTo(
5622
- 0,
5623
- startPosition + distance * easeInOutQuad(progress)
5624
- );
5625
- if (timeElapsed < duration) {
5626
- requestAnimationFrame(animation);
5627
- }
5628
- };
5629
- requestAnimationFrame(animation);
5606
+ if (!dropTargetKey || !dropZoneRefs.current[dropTargetKey]) return;
5607
+ const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5608
+ if (!dropZoneElement) return;
5609
+ const rect = dropZoneElement.getBoundingClientRect();
5610
+ const elementTop = rect.top + window.scrollY;
5611
+ const elementHeight = rect.height;
5612
+ const viewportHeight = window.innerHeight;
5613
+ const targetScroll = elementTop - viewportHeight / 2 + elementHeight / 2;
5614
+ const startScroll = window.scrollY;
5615
+ const distance = targetScroll - startScroll;
5616
+ console.log("Scrolling to element:", dropTargetKey);
5617
+ console.log("Current scroll:", startScroll);
5618
+ console.log("Target scroll:", targetScroll);
5619
+ console.log("Distance:", distance);
5620
+ if (Math.abs(distance) < 10) return;
5621
+ const duration = 800;
5622
+ let startTime = null;
5623
+ const easeInOutQuad = (t) => {
5624
+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
5625
+ };
5626
+ const animate = (currentTime) => {
5627
+ if (startTime === null) startTime = currentTime;
5628
+ console.log("startTime:", startTime);
5629
+ const elapsed = currentTime - startTime;
5630
+ console.log("elapsed:", elapsed);
5631
+ const progress = Math.min(elapsed / duration, 1);
5632
+ console.log("progress:", progress);
5633
+ const easedProgress = easeInOutQuad(progress);
5634
+ console.log("eased progressed: ", easedProgress);
5635
+ window.scrollTo(0, startScroll + distance * easedProgress);
5636
+ if (progress < 1) {
5637
+ requestAnimationFrame(animate);
5630
5638
  }
5631
- }
5639
+ };
5640
+ requestAnimationFrame(animate);
5632
5641
  }, [dropTargetKey]);
5633
5642
  const retrieveAnswerMap = () => {
5634
5643
  const foundIndex = answer.data.findIndex(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catchup-library-web",
3
- "version": "1.21.09",
3
+ "version": "1.21.11",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -63,42 +63,56 @@ const MatchingActivityMaterialContent = ({
63
63
  }, [showCorrectAnswer, answer, materialMap]);
64
64
 
65
65
  useEffect(() => {
66
- if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
67
- const dropZoneElement = dropZoneRefs.current[dropTargetKey];
68
- if (dropZoneElement) {
69
- const targetPosition =
70
- dropZoneElement.getBoundingClientRect().top + window.pageYOffset;
71
- const startPosition = window.pageYOffset;
72
- const distance =
73
- targetPosition -
74
- startPosition -
75
- window.innerHeight / 2 +
76
- dropZoneElement.offsetHeight / 2;
77
- const duration = 800; // Adjust this value (in milliseconds) to control speed
78
- let start: number | null = null;
79
-
80
- const easeInOutQuad = (t: number) => {
81
- return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
82
- };
83
-
84
- const animation = (currentTime: number) => {
85
- if (start === null) start = currentTime;
86
- const timeElapsed = currentTime - start;
87
- const progress = Math.min(timeElapsed / duration, 1);
88
-
89
- window.scrollTo(
90
- 0,
91
- startPosition + distance * easeInOutQuad(progress)
92
- );
93
-
94
- if (timeElapsed < duration) {
95
- requestAnimationFrame(animation);
96
- }
97
- };
98
-
99
- requestAnimationFrame(animation);
66
+ if (!dropTargetKey || !dropZoneRefs.current[dropTargetKey]) return;
67
+
68
+ const dropZoneElement = dropZoneRefs.current[dropTargetKey];
69
+ if (!dropZoneElement) return;
70
+
71
+ // Get the element's position relative to the viewport
72
+ const rect = dropZoneElement.getBoundingClientRect();
73
+ const elementTop = rect.top + window.scrollY;
74
+ const elementHeight = rect.height;
75
+ const viewportHeight = window.innerHeight;
76
+
77
+ // Calculate target scroll position (center the element in viewport)
78
+ const targetScroll = elementTop - viewportHeight / 2 + elementHeight / 2;
79
+ const startScroll = window.scrollY;
80
+ const distance = targetScroll - startScroll;
81
+
82
+ console.log("Scrolling to element:", dropTargetKey);
83
+ console.log("Current scroll:", startScroll);
84
+ console.log("Target scroll:", targetScroll);
85
+ console.log("Distance:", distance);
86
+
87
+ // Don't animate if already roughly in position
88
+ if (Math.abs(distance) < 10) return;
89
+
90
+ const duration = 800;
91
+ let startTime: number | null = null;
92
+
93
+ const easeInOutQuad = (t: number): number => {
94
+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
95
+ };
96
+
97
+ const animate = (currentTime: number) => {
98
+ if (startTime === null) startTime = currentTime;
99
+
100
+ console.log("startTime:", startTime);
101
+ const elapsed = currentTime - startTime;
102
+ console.log("elapsed:", elapsed);
103
+ const progress = Math.min(elapsed / duration, 1);
104
+ console.log("progress:", progress);
105
+ const easedProgress = easeInOutQuad(progress);
106
+ console.log("eased progressed: ", easedProgress);
107
+
108
+ window.scrollTo(0, startScroll + distance * easedProgress);
109
+
110
+ if (progress < 1) {
111
+ requestAnimationFrame(animate);
100
112
  }
101
- }
113
+ };
114
+
115
+ requestAnimationFrame(animate);
102
116
  }, [dropTargetKey]);
103
117
 
104
118
  const retrieveAnswerMap = () => {