@canvas3/nuxt 0.1.20 → 0.1.22
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
|
@@ -19,14 +19,17 @@ type MeshAnimation = {
|
|
|
19
19
|
ease: string;
|
|
20
20
|
};
|
|
21
21
|
export type AnimationCallback = () => void;
|
|
22
|
-
|
|
22
|
+
type BaseAnimationCall = {
|
|
23
23
|
onScroll: boolean;
|
|
24
24
|
onResize: boolean;
|
|
25
25
|
onMouseMove: boolean;
|
|
26
26
|
onAnimationsRender: boolean;
|
|
27
27
|
render: boolean;
|
|
28
|
+
animationIds: string[];
|
|
28
29
|
animationCallback: AnimationCallback;
|
|
29
30
|
};
|
|
31
|
+
export type AnimationCallSetup = Omit<BaseAnimationCall, 'animationIds'>;
|
|
32
|
+
export type AnimationCallOptions = BaseAnimationCall;
|
|
30
33
|
export type AnimationCallbacks = Map<string, AnimationCallOptions>;
|
|
31
34
|
export type MeshMaterialUniform = Record<string, {
|
|
32
35
|
duration: number;
|
|
@@ -4,11 +4,12 @@ import type { Pass } from 'three/addons/postprocessing/Pass.js';
|
|
|
4
4
|
import { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';
|
|
5
5
|
import type { ShaderMaterial, WebGLRenderer } from 'three';
|
|
6
6
|
import Scroll from '#canvas3-nuxt/utils/canvas3/scroll';
|
|
7
|
-
import type { AnimationCallbacks, Canvas3OptionsType, ScrollActionBinding, MeshMaterialUniform, MeshType, myEffectType,
|
|
7
|
+
import type { AnimationCallbacks, Canvas3OptionsType, ScrollActionBinding, MeshMaterialUniform, MeshType, myEffectType, AnimationCallSetup } from '#canvas3-nuxt/types/types';
|
|
8
8
|
declare class Canvas3Class {
|
|
9
9
|
canvasInitiated: import("vue").Ref<boolean, boolean>;
|
|
10
10
|
mouseMoveInProgress: boolean;
|
|
11
11
|
animationsRender: boolean;
|
|
12
|
+
documentVisibility: boolean;
|
|
12
13
|
resizeInProgress: boolean;
|
|
13
14
|
meshPositionsUpdate: boolean;
|
|
14
15
|
canvasContainer: HTMLElement | null;
|
|
@@ -49,7 +50,7 @@ declare class Canvas3Class {
|
|
|
49
50
|
updateOnScrollActiveElement(updatedBinding: ScrollActionBinding): void;
|
|
50
51
|
removeScrollActiveElement(elNode: HTMLElement): void;
|
|
51
52
|
removeMesh(id: string): void;
|
|
52
|
-
addAnimationToRender(callBackName: string,
|
|
53
|
+
addAnimationToRender(callBackName: string, callBackSetup: AnimationCallSetup): void;
|
|
53
54
|
removeAnimationFromRender(callBackName: string): void;
|
|
54
55
|
addImageAsMesh(imgHtmlEl: HTMLImageElement, shaderName: string | null, meshId: string, meshUniforms: MeshMaterialUniform, activateMeshUniforms: MeshMaterialUniform): Promise<void>;
|
|
55
56
|
composerPass(): void;
|
|
@@ -59,7 +60,7 @@ declare class Canvas3Class {
|
|
|
59
60
|
scrollToElBySelector(elQuerySelector: string, delay?: number, margin?: number): void;
|
|
60
61
|
setMeshPositionsUpdate(state: boolean): void;
|
|
61
62
|
setAnimationsToRender(state: boolean): void;
|
|
62
|
-
setAnimationToRender(callBackName: string, state: boolean): void;
|
|
63
|
+
setAnimationToRender(callBackName: string, state: boolean, animationId: string): void;
|
|
63
64
|
externalAnimationsRender(): void;
|
|
64
65
|
render(): void;
|
|
65
66
|
}
|
|
@@ -16,6 +16,7 @@ class Canvas3Class {
|
|
|
16
16
|
canvasInitiated = canvasInitiated;
|
|
17
17
|
mouseMoveInProgress = false;
|
|
18
18
|
animationsRender = false;
|
|
19
|
+
documentVisibility = true;
|
|
19
20
|
resizeInProgress = false;
|
|
20
21
|
meshPositionsUpdate = false;
|
|
21
22
|
canvasContainer = null;
|
|
@@ -77,6 +78,14 @@ class Canvas3Class {
|
|
|
77
78
|
this.mouseMoveInProgress = false;
|
|
78
79
|
}, 0);
|
|
79
80
|
});
|
|
81
|
+
document.addEventListener("visibilitychange", () => {
|
|
82
|
+
if (document.hidden) {
|
|
83
|
+
this.documentVisibility = false;
|
|
84
|
+
} else {
|
|
85
|
+
this.documentVisibility = true;
|
|
86
|
+
this.render();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
80
89
|
this.canvasInitiated.value = true;
|
|
81
90
|
studio783log();
|
|
82
91
|
}
|
|
@@ -239,9 +248,10 @@ class Canvas3Class {
|
|
|
239
248
|
this.activateMeshUniformMap.delete(id);
|
|
240
249
|
this.imageStore = this.imageStore.filter((item) => item.name !== id);
|
|
241
250
|
}
|
|
242
|
-
addAnimationToRender(callBackName,
|
|
251
|
+
addAnimationToRender(callBackName, callBackSetup) {
|
|
243
252
|
if (this.animations.has(callBackName)) return;
|
|
244
|
-
|
|
253
|
+
const newCallbackFunction = { ...callBackSetup, animationIds: [] };
|
|
254
|
+
this.animations.set(callBackName, newCallbackFunction);
|
|
245
255
|
}
|
|
246
256
|
removeAnimationFromRender(callBackName) {
|
|
247
257
|
this.animations.delete(callBackName);
|
|
@@ -367,9 +377,15 @@ class Canvas3Class {
|
|
|
367
377
|
setAnimationsToRender(state) {
|
|
368
378
|
this.animationsRender = state;
|
|
369
379
|
}
|
|
370
|
-
setAnimationToRender(callBackName, state) {
|
|
380
|
+
setAnimationToRender(callBackName, state, animationId) {
|
|
371
381
|
const animationToUpdate = this.animations.get(callBackName);
|
|
372
|
-
if (animationToUpdate)
|
|
382
|
+
if (!animationToUpdate) return;
|
|
383
|
+
if (state) {
|
|
384
|
+
animationToUpdate.animationIds.push(animationId);
|
|
385
|
+
} else {
|
|
386
|
+
animationToUpdate.animationIds.splice(animationToUpdate.animationIds.indexOf(animationId), 1);
|
|
387
|
+
}
|
|
388
|
+
animationToUpdate.render = animationToUpdate.animationIds.length > 0;
|
|
373
389
|
}
|
|
374
390
|
externalAnimationsRender() {
|
|
375
391
|
for (const [_key, callbackOption] of this.animations.entries()) {
|
|
@@ -419,6 +435,7 @@ class Canvas3Class {
|
|
|
419
435
|
this.renderer.render(this.scene, this.camera);
|
|
420
436
|
}
|
|
421
437
|
try {
|
|
438
|
+
if (!this.documentVisibility) return;
|
|
422
439
|
requestAnimationFrame(this.render.bind(this));
|
|
423
440
|
} catch (e) {
|
|
424
441
|
console.error(e);
|
|
@@ -3,13 +3,13 @@ import { getShaderMaterial } from '#canvas3-nuxt/utils/canvas3/helpers';
|
|
|
3
3
|
export declare const Canvas3: {
|
|
4
4
|
addMeshToScene: (mesh: Mesh) => void;
|
|
5
5
|
getMeshFromSceneByName: (meshName: string) => import("three").Object3D<import("three").Object3DEventMap> | undefined;
|
|
6
|
-
addAnimationToRender: (callBackName: string,
|
|
6
|
+
addAnimationToRender: (callBackName: string, callBackSetup: import("../types/types.js").AnimationCallSetup) => void;
|
|
7
7
|
removeAnimationFromRender: (callBackName: string) => void;
|
|
8
8
|
addImageAsMesh: (imgHtmlEl: HTMLImageElement, shaderName: string | null, meshId: string, meshUniforms: import("../types/types.js").MeshMaterialUniform, activateMeshUniforms: import("../types/types.js").MeshMaterialUniform) => Promise<void>;
|
|
9
9
|
getShaderMaterial: typeof getShaderMaterial;
|
|
10
10
|
removeMesh: (id: string) => void;
|
|
11
11
|
setAnimationsToRender: (state: boolean) => void;
|
|
12
|
-
setAnimationToRender: (callBackName: string, state: boolean) => void;
|
|
12
|
+
setAnimationToRender: (callBackName: string, state: boolean, animationId: string) => void;
|
|
13
13
|
resizeOnChange: () => void;
|
|
14
14
|
scrollToElBySelector: (elQuerySelector: string, delay?: number, margin?: number) => void;
|
|
15
15
|
setMeshPositionsUpdate: (state: boolean) => void;
|