@canvas3/nuxt 0.1.33 → 0.1.34

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "canvas-nuxt-layout",
3
3
  "configKey": "canvas3Layout",
4
- "version": "0.1.33",
4
+ "version": "0.1.34",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.0"
@@ -93,13 +93,13 @@ export const vCanvas3Image = {
93
93
  const stop = watch(
94
94
  () => Canvas3.canvasInitiated.value,
95
95
  (ready) => {
96
- if (ready) tryAdd(el, options);
96
+ if (ready) tryAdd(el, options).then();
97
97
  },
98
98
  { immediate: true }
99
99
  );
100
100
  stopMap.set(el, stop);
101
101
  if (el.complete) {
102
- tryAdd(el, options);
102
+ tryAdd(el, options).then();
103
103
  } else {
104
104
  const onLoad = () => tryAdd(el, options);
105
105
  el.addEventListener("load", onLoad, { once: true });
@@ -2,8 +2,7 @@ import { watch } from "vue";
2
2
  import { Canvas3 } from "#canvas3-nuxt/utils/canvas3/canvas3";
3
3
  export const vCanvas3ScrollAction = {
4
4
  mounted(el, binding) {
5
- const id = crypto.randomUUID();
6
- el.dataset.scrollActivateId = id;
5
+ el.dataset.scrollActivateId = crypto.randomUUID();
7
6
  if (binding.value?.scrollSpeedSetTo?.value) {
8
7
  el.dataset.scrollSpeed = binding.value?.scrollSpeedSetTo?.value;
9
8
  }
@@ -27,24 +26,6 @@ export const vCanvas3ScrollAction = {
27
26
  );
28
27
  }
29
28
  },
30
- //* ************************
31
- // DEACTIVATE UPDATES - no need as uniforms are reference based and do not need updates
32
- // updated(el, binding) {
33
- // const existingElement = Canvas3.getScrollActiveElement(el.dataset.scrollActivateId)
34
- // if (existingElement) {
35
- // const oldBinding = existingElement.options
36
- //
37
- // const isSame = shallowEqualObject(binding.value, oldBinding)
38
- // if (!isSame) {
39
- // console.log('isSame', isSame, el.dataset.scrollActivateId)
40
- // Canvas3.updateOnScrollActiveElement({
41
- // elNode: el,
42
- // options: binding.value,
43
- // arg: binding.arg,
44
- // })
45
- // }
46
- // }
47
- // },
48
29
  unmounted(el) {
49
30
  Canvas3.removeScrollActiveElement(el);
50
31
  },
@@ -1,5 +1,6 @@
1
1
  import type { Mesh, Vector2 } from 'three';
2
2
  import type { DirectiveBinding } from 'vue';
3
+ import type * as THREE from 'three';
3
4
  type Shader = {
4
5
  fragmentShader: string;
5
6
  vertexShader: string;
@@ -37,7 +38,7 @@ export type MeshMaterialUniform = Record<string, {
37
38
  value: number;
38
39
  }>;
39
40
  export type BaseUniform = Record<string, {
40
- value: Vector2 | number | null;
41
+ value: Vector2 | THREE.Texture | number | null;
41
42
  duration?: number;
42
43
  ease?: string | null | undefined;
43
44
  }>;
@@ -54,6 +55,7 @@ export type Canvas3OptionsType = {
54
55
  prefersReducedMotion: boolean;
55
56
  isMobile: boolean;
56
57
  disabled: boolean;
58
+ mouseTrackingEnabled?: boolean;
57
59
  };
58
60
  export type MeshType = {
59
61
  name: string;
@@ -113,15 +115,7 @@ export type myEffectType = {
113
115
  };
114
116
  export type Canvas3ImageBinding = {
115
117
  shaderName?: string;
116
- uniforms?: MeshMaterialUniform;
117
- activateMeshUniforms?: MeshMaterialUniform;
118
- };
119
- export type Canvas3ImageBindType = {
120
- alt: string;
121
- src: string;
122
- loadStrategy?: 'lazy' | 'eager' | undefined;
123
- shaderName?: string;
124
- uniforms?: MeshMaterialUniform | undefined;
118
+ uniforms?: MeshMaterialUniform | BaseUniform;
125
119
  activateMeshUniforms?: MeshMaterialUniform;
126
120
  };
127
121
  export type AttrsType = Record<string, number | string>;
@@ -4,7 +4,7 @@ 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, AnimationCallSetup, ScrollActionType } from '#canvas3-nuxt/types/types';
7
+ import type { AnimationCallbacks, Canvas3OptionsType, ScrollActionBinding, MeshMaterialUniform, MeshType, myEffectType, AnimationCallSetup, BaseUniform } from '#canvas3-nuxt/types/types';
8
8
  declare class Canvas3Class {
9
9
  canvasInitiated: import("vue").Ref<boolean, boolean>;
10
10
  renderDisabled: boolean;
@@ -48,16 +48,14 @@ declare class Canvas3Class {
48
48
  resizeOnChange(): void;
49
49
  resizeImageStore(): void;
50
50
  setImageMeshPositions(): void;
51
- meshUniformsUpdate(id: string, uniforms: MeshMaterialUniform): void;
51
+ meshUniformsUpdate(id: string, uniforms: MeshMaterialUniform | BaseUniform): void;
52
52
  activateMesh(meshId: string, isActive: boolean): void;
53
53
  addOnScrollActivateElement(binding: ScrollActionBinding): void;
54
- getScrollActiveElement(scrollActiveElementId: string): ScrollActionType | undefined;
55
- updateOnScrollActiveElement(updatedBinding: ScrollActionBinding): void;
56
54
  removeScrollActiveElement(elNode: HTMLElement): void;
57
55
  removeMesh(id: string): void;
58
56
  addAnimationToRender(callBackName: string, callBackSetup: AnimationCallSetup): void;
59
57
  removeAnimationFromRender(callBackName: string): void;
60
- addImageAsMesh(imgHtmlEl: HTMLImageElement, shaderName: string | null, meshId: string, meshUniforms: MeshMaterialUniform, activateMeshUniforms: MeshMaterialUniform): Promise<void>;
58
+ addImageAsMesh(imgHtmlEl: HTMLImageElement, shaderName: string | null, meshId: string, meshUniforms: MeshMaterialUniform | BaseUniform, activateMeshUniforms: MeshMaterialUniform): Promise<void>;
61
59
  composerPass(): void;
62
60
  setSize(): void;
63
61
  scrollToTop(delay?: number): void;
@@ -66,22 +66,24 @@ class Canvas3Class {
66
66
  this.setSize();
67
67
  this.composerPass();
68
68
  this.startRenderLoop();
69
- window.addEventListener("mousemove", (event) => {
70
- this.mouseMoveInProgress = true;
71
- this.mouse.x = event.clientX / this.width;
72
- this.mouse.y = event.clientY / this.height;
73
- setTimeout(() => {
74
- this.mouse.movementX = event.clientX / this.width;
75
- this.mouse.movementY = event.clientY / this.height;
76
- }, 70);
77
- if (this.mouse.movementX === 0 && this.mouse.movementY === 0) {
78
- this.mouse.movementX = this.mouse.x;
79
- this.mouse.movementY = this.mouse.y;
80
- }
81
- setTimeout(() => {
82
- this.mouseMoveInProgress = false;
83
- }, 0);
84
- });
69
+ if (canvas3Options.mouseTrackingEnabled) {
70
+ window.addEventListener("mousemove", (event) => {
71
+ this.mouseMoveInProgress = true;
72
+ this.mouse.x = event.clientX / this.width;
73
+ this.mouse.y = event.clientY / this.height;
74
+ setTimeout(() => {
75
+ this.mouse.movementX = event.clientX / this.width;
76
+ this.mouse.movementY = event.clientY / this.height;
77
+ }, 70);
78
+ if (this.mouse.movementX === 0 && this.mouse.movementY === 0) {
79
+ this.mouse.movementX = this.mouse.x;
80
+ this.mouse.movementY = this.mouse.y;
81
+ }
82
+ setTimeout(() => {
83
+ this.mouseMoveInProgress = false;
84
+ }, 0);
85
+ });
86
+ }
85
87
  document.addEventListener("visibilitychange", () => {
86
88
  if (document.hidden) {
87
89
  this.documentVisibility = false;
@@ -162,7 +164,7 @@ class Canvas3Class {
162
164
  value: uniforms[uniKey].value
163
165
  };
164
166
  gsap.to(material.uniforms[uniKey], {
165
- duration: uniforms[uniKey].duration,
167
+ duration: uniforms[uniKey].duration ?? 0,
166
168
  value: uniforms[uniKey].value,
167
169
  ease: uniforms[uniKey].ease ?? "power1.inOut"
168
170
  });
@@ -211,30 +213,6 @@ class Canvas3Class {
211
213
  const newBinding = generateBindingLogic(binding);
212
214
  this.scroll?.DOM.onScrollActivateElements.push(newBinding);
213
215
  }
214
- getScrollActiveElement(scrollActiveElementId) {
215
- if (!this.scroll) return;
216
- let scrollActiveElement;
217
- for (const [
218
- index,
219
- item
220
- ] of this.scroll.DOM.onScrollActivateElements.entries()) {
221
- if (item.elNode.dataset.scrollActivateId === scrollActiveElementId) {
222
- scrollActiveElement = this.scroll.DOM.onScrollActivateElements[index];
223
- }
224
- }
225
- return scrollActiveElement;
226
- }
227
- updateOnScrollActiveElement(updatedBinding) {
228
- if (!this.scroll) return;
229
- for (const [
230
- index,
231
- item
232
- ] of this.scroll.DOM.onScrollActivateElements.entries()) {
233
- if (item.elNode.dataset.scrollActivateId === updatedBinding.elNode.dataset.scrollActivateId) {
234
- this.scroll.DOM.onScrollActivateElements[index] = generateBindingLogic(updatedBinding);
235
- }
236
- }
237
- }
238
216
  removeScrollActiveElement(elNode) {
239
217
  if (!elNode || !this.scroll?.DOM.onScrollActivateElements || this.scroll?.DOM.onScrollActivateElements.length === 0)
240
218
  return;
@@ -476,6 +454,9 @@ class Canvas3Class {
476
454
  this.externalAnimationsRender();
477
455
  if (this.materials.length > 0) {
478
456
  for (const material of this.materials) {
457
+ if (!material.uniforms) {
458
+ continue;
459
+ }
479
460
  if (material.uniforms.uTime)
480
461
  material.uniforms.uTime.value = this.time;
481
462
  if (this.mouseMoveInProgress) {
@@ -1,13 +1,7 @@
1
1
  import type { ScrollActionBinding, ScrollActionType } from '#canvas3-nuxt/types/types';
2
- import type { Mesh, ShaderMaterial, Texture } from 'three';
2
+ import type { Mesh, ShaderMaterial } from 'three';
3
3
  export declare function generateBindingLogic(newBindingData: ScrollActionBinding): ScrollActionType;
4
4
  export declare function findMeshIDs(elParent: HTMLElement): false | string[];
5
- export declare function loadTexture(src: string): Promise<Texture>;
6
- export declare const heightPositionCoef = 1.38;
7
- export declare function getMSDFFontMeshScales(boundsWidth: number, geometryWidth: number): {
8
- scaleX: number;
9
- scaleY: number;
10
- };
11
5
  export declare function setScrollActiveElements(elNode: HTMLElement, meshIds: string[], state: string): void;
12
6
  export declare function elementNearViewport(bounds: DOMRect, activeRangeInPx: number): boolean;
13
7
  export declare const lerp: (a: number, b: number, n: number) => number;
@@ -1,4 +1,3 @@
1
- import * as THREE from "three";
2
1
  import { gsap } from "gsap";
3
2
  export function generateBindingLogic(newBindingData) {
4
3
  const binding = { ...newBindingData, isInView: false };
@@ -59,24 +58,6 @@ export function findMeshIDs(elParent) {
59
58
  }
60
59
  return meshIds;
61
60
  }
62
- export function loadTexture(src) {
63
- return new Promise((resolve, reject) => {
64
- const loader = new THREE.TextureLoader();
65
- return loader.load(
66
- src,
67
- (texture) => resolve(texture),
68
- void 0,
69
- (err) => reject(err)
70
- );
71
- });
72
- }
73
- const heightSizeCoef = 1;
74
- export const heightPositionCoef = 1.38;
75
- export function getMSDFFontMeshScales(boundsWidth, geometryWidth) {
76
- const scaleX = boundsWidth / geometryWidth * heightSizeCoef;
77
- const scaleY = -1 * scaleX * heightSizeCoef;
78
- return { scaleX, scaleY };
79
- }
80
61
  export function setScrollActiveElements(elNode, meshIds, state) {
81
62
  if (!meshIds || meshIds.length === 0) return;
82
63
  for (const id of meshIds) {
@@ -1,11 +1,12 @@
1
- import type { Mesh } from 'three';
1
+ import type { Mesh, ShaderMaterial } from 'three';
2
2
  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
+ addMaterialForGlobalUniformUpdates: (material: ShaderMaterial) => void;
6
7
  addAnimationToRender: (callBackName: string, callBackSetup: import("../types/types.js").AnimationCallSetup) => void;
7
8
  removeAnimationFromRender: (callBackName: string) => void;
8
- addImageAsMesh: (imgHtmlEl: HTMLImageElement, shaderName: string | null, meshId: string, meshUniforms: import("../types/types.js").MeshMaterialUniform, activateMeshUniforms: import("../types/types.js").MeshMaterialUniform) => Promise<void>;
9
+ addImageAsMesh: (imgHtmlEl: HTMLImageElement, shaderName: string | null, meshId: string, meshUniforms: import("../types/types.js").MeshMaterialUniform | import("../types/types.js").BaseUniform, activateMeshUniforms: import("../types/types.js").MeshMaterialUniform) => Promise<void>;
9
10
  getShaderMaterial: typeof getShaderMaterial;
10
11
  removeMesh: (id: string) => void;
11
12
  setAnimationsToRender: (state: boolean) => void;
@@ -7,6 +7,9 @@ export const Canvas3 = {
7
7
  getMeshFromSceneByName: (meshName) => {
8
8
  return mainClass.scene.getObjectByName(meshName);
9
9
  },
10
+ addMaterialForGlobalUniformUpdates: (material) => {
11
+ mainClass.materials.push(material);
12
+ },
10
13
  addAnimationToRender: mainClass.addAnimationToRender.bind(mainClass),
11
14
  removeAnimationFromRender: mainClass.removeAnimationFromRender.bind(mainClass),
12
15
  addImageAsMesh: mainClass.addImageAsMesh.bind(mainClass),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canvas3/nuxt",
3
- "version": "0.1.33",
3
+ "version": "0.1.34",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },