@canvas3/nuxt 0.1.3 → 0.1.4
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/module.json
CHANGED
|
@@ -69,6 +69,7 @@ export type scrollActionBindOptionType = {
|
|
|
69
69
|
duration: number;
|
|
70
70
|
};
|
|
71
71
|
activateCallback?: (item: ScrollActionType) => void;
|
|
72
|
+
deactivateCallback?: (item: ScrollActionType) => void;
|
|
72
73
|
onScrollCallback?: (item: ScrollActionType, scrollSpeed: number, currentPosition: number) => void;
|
|
73
74
|
activeRangeMargin?: number;
|
|
74
75
|
activeRangeOrigin?: number;
|
|
@@ -94,6 +95,7 @@ export type ScrollActionType = {
|
|
|
94
95
|
margin?: number;
|
|
95
96
|
containerBottom?: number;
|
|
96
97
|
trackOnly?: boolean;
|
|
98
|
+
isInView: boolean;
|
|
97
99
|
};
|
|
98
100
|
export type myEffectType = {
|
|
99
101
|
uniforms: BaseUniform;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ScrollActionType } from '#canvas3-nuxt/types/types';
|
|
1
|
+
import type { ScrollActionBinding, ScrollActionType } from '#canvas3-nuxt/types/types';
|
|
2
2
|
import type { Mesh, ShaderMaterial, Texture } from 'three';
|
|
3
|
-
export declare function generateBindingLogic(newBindingData:
|
|
3
|
+
export declare function generateBindingLogic(newBindingData: ScrollActionBinding): ScrollActionType;
|
|
4
4
|
export declare function findMeshIDs(elParent: HTMLElement): false | string[];
|
|
5
5
|
export declare function loadTexture(src: string): Promise<Texture>;
|
|
6
6
|
export declare const heightPositionCoef = 1.38;
|
|
@@ -9,7 +9,7 @@ export declare function getMSDFFontMeshScales(boundsWidth: number, geometryWidth
|
|
|
9
9
|
scaleY: number;
|
|
10
10
|
};
|
|
11
11
|
export declare function setScrollActiveElements(elNode: HTMLElement, meshIds: string[], state: string): void;
|
|
12
|
-
export declare function elementNearViewport(bounds: DOMRect,
|
|
12
|
+
export declare function elementNearViewport(bounds: DOMRect, activeRangeInPx: number): boolean;
|
|
13
13
|
export declare const lerp: (a: number, b: number, n: number) => number;
|
|
14
14
|
export declare function getShaderMaterial(mesh: Mesh): ShaderMaterial;
|
|
15
15
|
export declare function hasTransformTranslate(el: HTMLElement): boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as THREE from "three";
|
|
2
2
|
import { gsap } from "gsap";
|
|
3
3
|
export function generateBindingLogic(newBindingData) {
|
|
4
|
-
const binding = newBindingData;
|
|
4
|
+
const binding = { ...newBindingData, isInView: false };
|
|
5
5
|
binding.elNode.dataset.activeScroll = newBindingData?.elNode?.dataset?.activeScroll ?? "false";
|
|
6
6
|
binding.containedMeshIds = [];
|
|
7
7
|
binding.bounds = binding.elNode.getBoundingClientRect();
|
|
@@ -86,9 +86,8 @@ export function setScrollActiveElements(elNode, meshIds, state) {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
export function elementNearViewport(bounds,
|
|
90
|
-
|
|
91
|
-
return bounds.top >= -margin && bounds.top <= windowHeight || bounds.bottom >= -margin && bounds.bottom <= windowHeight || bounds.top <= -margin && bounds.bottom >= windowHeight;
|
|
89
|
+
export function elementNearViewport(bounds, activeRangeInPx) {
|
|
90
|
+
return bounds.top <= activeRangeInPx && bounds.top >= -bounds.height;
|
|
92
91
|
}
|
|
93
92
|
export const lerp = (a, b, n) => (1 - n) * a + n * b;
|
|
94
93
|
export function getShaderMaterial(mesh) {
|
|
@@ -67,17 +67,20 @@ export default class Scroll {
|
|
|
67
67
|
}
|
|
68
68
|
setElementActive(item, isActive) {
|
|
69
69
|
if (!item.containedMeshIds) return;
|
|
70
|
+
item.isInView = isActive;
|
|
71
|
+
const isActiveString = isActive ? "true" : "false";
|
|
72
|
+
item.elNode.dataset.activeScroll = isActiveString;
|
|
73
|
+
setScrollActiveElements(item.elNode, item.containedMeshIds, isActiveString);
|
|
70
74
|
if (isActive) {
|
|
71
|
-
item.elNode.dataset.activeScroll = "true";
|
|
72
|
-
setScrollActiveElements(item.elNode, item.containedMeshIds, "true");
|
|
73
75
|
item.elNode.classList.add("active");
|
|
74
76
|
if (item.options.activateCallback) {
|
|
75
77
|
item.options.activateCallback(item);
|
|
76
78
|
}
|
|
77
79
|
} else {
|
|
78
|
-
item.elNode.dataset.activeScroll = "false";
|
|
79
|
-
setScrollActiveElements(item.elNode, item.containedMeshIds, "false");
|
|
80
80
|
if (!item.trackOnly) item.elNode.classList.remove("active");
|
|
81
|
+
if (item.options.deactivateCallback) {
|
|
82
|
+
item.options.deactivateCallback(item);
|
|
83
|
+
}
|
|
81
84
|
}
|
|
82
85
|
if (item.containedMeshIds.length > 0 && !item.trackOnly) {
|
|
83
86
|
for (const meshId of item.containedMeshIds) {
|
|
@@ -87,29 +90,20 @@ export default class Scroll {
|
|
|
87
90
|
}
|
|
88
91
|
setElementsScrollPositions() {
|
|
89
92
|
if (this.DOM.onScrollActivateElements.length === 0) return;
|
|
93
|
+
const windowInnerHeight = window.innerHeight;
|
|
90
94
|
for (const item of this.DOM.onScrollActivateElements) {
|
|
91
95
|
const bounds = item.elNode.getBoundingClientRect();
|
|
92
96
|
const itemRangeMargin = item.options.activeRangeMargin ?? 0;
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (item.options.onScrollCallback && this.scrollInProgress)
|
|
104
|
-
item.options.onScrollCallback(item, this.speed, this.current);
|
|
105
|
-
if (item.elNode.dataset.activeScroll !== "true") {
|
|
106
|
-
this.setElementActive(item, true);
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
if (item.elNode.dataset.activeScroll === "true" && !item.options.activateOnce) {
|
|
110
|
-
this.setElementActive(item, false);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
97
|
+
const activeRange = item.options.activeRange ?? 1;
|
|
98
|
+
const activeRangeInPx = activeRange * windowInnerHeight;
|
|
99
|
+
const isInView = elementNearViewport(bounds, activeRangeInPx);
|
|
100
|
+
if (isInView) {
|
|
101
|
+
if (item.options.onScrollCallback && this.scrollInProgress)
|
|
102
|
+
item.options.onScrollCallback(item, this.speed, this.current);
|
|
103
|
+
if (!item.isInView)
|
|
104
|
+
this.setElementActive(item, true);
|
|
105
|
+
} else if (item.isInView && !item.options.activateOnce) {
|
|
106
|
+
this.setElementActive(item, false);
|
|
113
107
|
}
|
|
114
108
|
if (typeof item.options.scrollSpeed?.value === "number") {
|
|
115
109
|
item.elNode.style.transition = `linear translate3d 0s`;
|