@canvas3/nuxt 0.0.1 → 0.0.3

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.
Files changed (29) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/runtime/components/canvas3-image.vue +1 -1
  3. package/dist/runtime/constants/studio783Log.d.ts +1 -0
  4. package/dist/runtime/constants/studio783Log.js +22 -0
  5. package/dist/runtime/directives/canvas3-image.client.d.ts +3 -0
  6. package/dist/runtime/directives/{canvas3-image-directive.client.js → canvas3-image.client.js} +4 -4
  7. package/dist/runtime/plugins/directives.js +1 -1
  8. package/dist/runtime/types/types.d.ts +30 -10
  9. package/dist/runtime/types/types.js +1 -0
  10. package/dist/runtime/types/vue-directives.d.ts +10 -0
  11. package/dist/runtime/utils/canvas3/canvas3.d.ts +5 -10
  12. package/dist/runtime/utils/canvas3/canvas3.js +66 -81
  13. package/dist/runtime/utils/canvas3/helpers.d.ts +5 -3
  14. package/dist/runtime/utils/canvas3/helpers.js +4 -4
  15. package/package.json +1 -1
  16. package/dist/runtime/directives/canvas3-image-directive.client.d.ts +0 -6
  17. package/dist/runtime/plugin.d.ts +0 -2
  18. package/dist/runtime/plugin.js +0 -3
  19. package/dist/runtime/types/three-msdf-text-utils.d.ts +0 -36
  20. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/TextLayout.d.ts +0 -1
  21. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/TextLayout.js +0 -0
  22. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/createIndices.d.ts +0 -1
  23. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/createIndices.js +0 -0
  24. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/index.d.ts +0 -1
  25. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/index.js +0 -0
  26. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/utils.d.ts +0 -1
  27. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/utils.js +0 -0
  28. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/vertices.d.ts +0 -1
  29. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/vertices.js +0 -0
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "canvas-nuxt-layout",
3
3
  "configKey": "canvas3Layout",
4
- "version": "0.0.1",
4
+ "version": "0.0.3",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.0"
@@ -37,7 +37,7 @@ const addImageToCanvas = async () => {
37
37
  if (!image.value || Canvas3.canvasInitiated.value === false || Canvas3.options?.disabled || imgAddedToCanvas.value) return;
38
38
  if (image.value.naturalWidth === 0) return;
39
39
  image.value.dataset.meshId = generatedMeshId;
40
- Canvas3.addImageAsMesh(
40
+ await Canvas3.addImageAsMesh(
41
41
  image.value,
42
42
  props.options.shaderName,
43
43
  generatedMeshId,
@@ -0,0 +1 @@
1
+ export declare const studio783log: () => void;
@@ -0,0 +1,22 @@
1
+ export const studio783log = () => {
2
+ console.log(`
3
+ Animation package Canvas3 developed by
4
+
5
+ \u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2588 \u2588 \u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588
6
+ \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588
7
+ \u2588\u2588\u2588\u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588
8
+ \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588
9
+ \u2588\u2588\u2588\u2588 \u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588
10
+
11
+ \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588
12
+ \u2591\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2588\u2588\u2588 \u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2588\u2588\u2588 \u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2588\u2588\u2588
13
+ \u2591\u2591\u2591 \u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2591\u2591\u2591 \u2591\u2588\u2588\u2588
14
+ \u2588\u2588\u2588 \u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2591
15
+ \u2588\u2588\u2588 \u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2588\u2588\u2588 \u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588
16
+ \u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2588\u2588\u2588 \u2591\u2588\u2588\u2588
17
+ \u2588\u2588\u2588 \u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588
18
+ \u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591
19
+
20
+ `);
21
+ console.log("%chttps://783studio.com", "font-size:20px; font-weight:600;");
22
+ };
@@ -0,0 +1,3 @@
1
+ import type { Directive } from 'vue';
2
+ import type { Canvas3ImageBinding } from '~/src/runtime/types/types';
3
+ export declare const vCanvas3Image: Directive<HTMLImageElement, Canvas3ImageBinding>;
@@ -23,9 +23,9 @@ async function tryAdd(el, options) {
23
23
  meshIdMap.set(el, meshId);
24
24
  el.dataset.meshId = meshId;
25
25
  }
26
- Canvas3.addImageAsMesh(
26
+ await Canvas3.addImageAsMesh(
27
27
  el,
28
- options?.shaderName,
28
+ options.shaderName ?? null,
29
29
  meshId,
30
30
  options?.uniforms ?? {},
31
31
  options?.activateMeshUniforms ?? {}
@@ -53,7 +53,7 @@ export const vCanvas3Image = {
53
53
  if (el.tagName !== "IMG") {
54
54
  return;
55
55
  }
56
- const options = binding.value || {};
56
+ const options = binding.value ?? {};
57
57
  const stop = watch(
58
58
  () => Canvas3.canvasInitiated.value,
59
59
  (ready) => {
@@ -70,7 +70,7 @@ export const vCanvas3Image = {
70
70
  }
71
71
  },
72
72
  updated(el, binding) {
73
- const options = binding.value || {};
73
+ const options = binding.value ?? {};
74
74
  const meshId = meshIdMap.get(el);
75
75
  if (meshId && options?.uniforms) {
76
76
  Canvas3.meshUniformsUpdate(meshId, options.uniforms);
@@ -1,6 +1,6 @@
1
1
  import { vOnScrollActivate } from "../directives/action-on-scroll.js";
2
2
  import { vSetDataAttribute } from "../directives/set-data-attributes.js";
3
- import { vCanvas3Image } from "../directives/canvas3-image-directive.client.js";
3
+ import { vCanvas3Image } from "../directives/canvas3-image.client.js";
4
4
  import { defineNuxtPlugin } from "#app";
5
5
  export default defineNuxtPlugin((nuxtApp) => {
6
6
  nuxtApp.vueApp.directive("action-on-scroll", vOnScrollActivate);
@@ -1,12 +1,5 @@
1
- import type { Mesh } from 'three';
2
- import type { DirectiveBinding } from 'vue';
3
- export type AnimationCallback = () => void;
4
- export type AnimationCallbacks = Map<string, AnimationCallback>;
5
- export type MeshMaterialUniform = Record<string, {
6
- duration: number;
7
- ease: string;
8
- value: number;
9
- }>;
1
+ import type { Mesh, Vector2 } from 'three';
2
+ import type { DirectiveBinding, ObjectDirective } from 'vue';
10
3
  type Shader = {
11
4
  fragmentShader: string;
12
5
  vertexShader: string;
@@ -25,6 +18,18 @@ type MeshAnimation = {
25
18
  duration: number;
26
19
  ease: string;
27
20
  };
21
+ export type AnimationCallback = () => void;
22
+ export type AnimationCallbacks = Map<string, AnimationCallback>;
23
+ export type MeshMaterialUniform = Record<string, {
24
+ duration: number;
25
+ ease: string | null | undefined;
26
+ value: number;
27
+ }>;
28
+ export type BaseUniform = Record<string, {
29
+ value: Vector2 | number | null;
30
+ duration?: number;
31
+ ease?: string | null | undefined;
32
+ }>;
28
33
  export type Canvas3OptionsType = {
29
34
  font: Font;
30
35
  shaders: Shaders;
@@ -58,7 +63,7 @@ export type ScrollActionType = {
58
63
  options: DirectiveBinding['value'];
59
64
  arg: DirectiveBinding['arg'];
60
65
  containedMeshIds?: string[];
61
- bounds: DOMRect;
66
+ bounds?: DOMRect;
62
67
  containerId?: string;
63
68
  fixPosition?: number;
64
69
  containerEl?: HTMLElement;
@@ -68,4 +73,19 @@ export type ScrollActionType = {
68
73
  containerBottom?: number;
69
74
  trackOnly?: boolean;
70
75
  };
76
+ export type myEffectType = {
77
+ uniforms: BaseUniform;
78
+ vertexShader: string;
79
+ fragmentShader: string;
80
+ };
81
+ export type Canvas3ImageBinding = {
82
+ shaderName?: string;
83
+ uniforms?: MeshMaterialUniform;
84
+ activateMeshUniforms?: MeshMaterialUniform;
85
+ };
86
+ declare module 'vue' {
87
+ interface GlobalDirectives {
88
+ 'canvas3-image': ObjectDirective<HTMLImageElement, Canvas3ImageBinding>;
89
+ }
90
+ }
71
91
  export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { ObjectDirective } from 'vue'
2
+ import type { Canvas3ImageBinding } from '~/src/runtime/types/types'
3
+
4
+ declare module 'vue' {
5
+ export interface GlobalDirectives {
6
+ 'canvas3-image': ObjectDirective<HTMLImageElement, Canvas3ImageBinding>
7
+ }
8
+ }
9
+
10
+ export {}
@@ -2,9 +2,9 @@ import * as THREE from 'three';
2
2
  import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
3
3
  import type { Pass } from 'three/addons/postprocessing/Pass.js';
4
4
  import { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';
5
- import type { ShaderMaterial } from 'three';
5
+ import type { ShaderMaterial, WebGLRenderer } from 'three';
6
6
  import Scroll from '#canvas3-nuxt/utils/canvas3/scroll';
7
- import type { AnimationCallback, AnimationCallbacks, Canvas3OptionsType, ScrollActionBinding, MeshMaterialUniform, MeshType } from '#canvas3-nuxt/types/types';
7
+ import type { AnimationCallback, AnimationCallbacks, Canvas3OptionsType, ScrollActionBinding, MeshMaterialUniform, MeshType, myEffectType } from '#canvas3-nuxt/types/types';
8
8
  declare class Canvas3Class {
9
9
  canvasInitiated: import("vue").Ref<boolean, boolean>;
10
10
  animateImageMesh: boolean;
@@ -12,11 +12,8 @@ declare class Canvas3Class {
12
12
  scrollableContent: HTMLElement | null;
13
13
  time: number;
14
14
  scene: THREE.Scene;
15
- MSDFTextGeometryAtlas: any;
16
- MSDFTextGeometryFont: any;
17
15
  materials: ShaderMaterial[];
18
16
  imageStore: MeshType[];
19
- textStore: MeshType[];
20
17
  activateMeshUniformMap: Map<string, MeshMaterialUniform>;
21
18
  scroll: Scroll | null;
22
19
  currentScroll: number;
@@ -26,8 +23,8 @@ declare class Canvas3Class {
26
23
  camera: THREE.PerspectiveCamera | null;
27
24
  composer: EffectComposer | null;
28
25
  renderPass: Pass | null;
29
- renderer: any;
30
- myEffect: any;
26
+ renderer: WebGLRenderer | null;
27
+ myEffect: myEffectType;
31
28
  customPass: ShaderPass | null;
32
29
  animations: AnimationCallbacks;
33
30
  mouse: {
@@ -42,9 +39,7 @@ declare class Canvas3Class {
42
39
  setCanvasAndCamera(): void;
43
40
  resizeOnChange(): void;
44
41
  resizeImageStore(): void;
45
- resizeTextStore(): void;
46
42
  setImageMeshPositions(): void;
47
- setTextMeshPositions(): void;
48
43
  meshUniformsUpdate(id: string, uniforms: MeshMaterialUniform): void;
49
44
  activateMesh(meshId: string, isActive: boolean): void;
50
45
  addOnScrollActivateElement(binding: ScrollActionBinding): void;
@@ -52,7 +47,7 @@ declare class Canvas3Class {
52
47
  removeScrollActiveElement(elNode: HTMLElement): void;
53
48
  removeMesh(id: string): void;
54
49
  addAnimationToRender(callBackName: string, callBackFunction: AnimationCallback): void;
55
- addImageAsMesh(imgHtmlEl: HTMLImageElement, shaderName: string, meshId: string, meshUniforms: MeshMaterialUniform, activateMeshUniforms: MeshMaterialUniform): Promise<void>;
50
+ addImageAsMesh(imgHtmlEl: HTMLImageElement, shaderName: string | null, meshId: string, meshUniforms: MeshMaterialUniform, activateMeshUniforms: MeshMaterialUniform): Promise<void>;
56
51
  composerPass(): void;
57
52
  setSize(): void;
58
53
  scrollToTop(delay?: number): void;
@@ -6,12 +6,12 @@ import { ShaderPass } from "three/addons/postprocessing/ShaderPass.js";
6
6
  import { gsap } from "gsap";
7
7
  import {
8
8
  generateBindingLogic,
9
- getMSDFFontMeshScales,
10
- heightPositionCoef,
9
+ getShaderMaterial,
11
10
  loadTexture
12
11
  } from "./helpers.js";
13
12
  import Scroll from "#canvas3-nuxt/utils/canvas3/scroll";
14
13
  import { defaultCanvas3Options } from "#canvas3-nuxt/constants/default-canvas3-options";
14
+ import { studio783log } from "#canvas3-nuxt/constants/studio783Log";
15
15
  const canvasInitiated = ref(false);
16
16
  class Canvas3Class {
17
17
  canvasInitiated = canvasInitiated;
@@ -20,11 +20,11 @@ class Canvas3Class {
20
20
  scrollableContent = null;
21
21
  time = 0;
22
22
  scene = new THREE.Scene();
23
- MSDFTextGeometryAtlas;
24
- MSDFTextGeometryFont;
23
+ // MSDFTextGeometryAtlas: any
24
+ // MSDFTextGeometryFont: any
25
25
  materials = [];
26
26
  imageStore = [];
27
- textStore = [];
27
+ // textStore: MeshType[] = []
28
28
  activateMeshUniformMap = /* @__PURE__ */ new Map();
29
29
  scroll = null;
30
30
  currentScroll = 0;
@@ -34,15 +34,18 @@ class Canvas3Class {
34
34
  camera = null;
35
35
  composer = null;
36
36
  renderPass = null;
37
- renderer;
38
- myEffect;
37
+ renderer = null;
38
+ myEffect = {
39
+ uniforms: {
40
+ tDiffuse: { value: null },
41
+ scrollSpeed: { value: null }
42
+ },
43
+ vertexShader: "",
44
+ fragmentShader: ""
45
+ };
39
46
  customPass = null;
40
47
  animations = /* @__PURE__ */ new Map();
41
48
  mouse = { x: 0, y: 0, movementX: 0, movementY: 0, xPrev: 0, yPrev: 0 };
42
- // triggerSectionPositions= {};
43
- // constructor({ canvasOptions }) {
44
- // this.options = canvasOptions;
45
- // }
46
49
  async init(canvasElement, scrollableContent, canvas3Options) {
47
50
  this.options = canvas3Options;
48
51
  this.scene = new THREE.Scene();
@@ -69,6 +72,7 @@ class Canvas3Class {
69
72
  }
70
73
  });
71
74
  this.canvasInitiated.value = true;
75
+ studio783log();
72
76
  }
73
77
  setCanvasAndCamera() {
74
78
  this.width = this.canvasContainer?.offsetWidth ?? 0;
@@ -87,33 +91,9 @@ class Canvas3Class {
87
91
  this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.5));
88
92
  this.canvasContainer?.appendChild(this.renderer.domElement);
89
93
  }
90
- // async loadFontMSDF() {
91
- // const loadFontAtlas = (path: string) => {
92
- // return new Promise((resolve) => {
93
- // const loader = new THREE.TextureLoader()
94
- // loader.load(path, resolve)
95
- // })
96
- // }
97
- // const loadFont = (path: string) => {
98
- // return new Promise((resolve) => {
99
- // const loader = new FontLoader()
100
- // loader.load(path, resolve)
101
- // })
102
- // }
103
- // await Promise.all([
104
- // loadFontAtlas(this.options.font.atlas),
105
- // loadFont(this.options.font.fnt),
106
- // ]).then(([atlas, font]) => {
107
- // if (atlas)
108
- // this.MSDFTextGeometryAtlas = atlas
109
- // if (font)
110
- // this.MSDFTextGeometryFont = font
111
- // })
112
- // }
113
94
  resizeOnChange() {
114
95
  this.setSize();
115
96
  this.resizeImageStore();
116
- this.resizeTextStore();
117
97
  this.scroll?.resizeMobileBreakEvents();
118
98
  this.scroll?.setSize();
119
99
  }
@@ -123,29 +103,27 @@ class Canvas3Class {
123
103
  const bounds = item.htmlEl.getBoundingClientRect();
124
104
  if (!bounds) return;
125
105
  item.mesh.scale.set(bounds.width, bounds.height, 1);
126
- item.mesh.material.uniforms.uMeshSize.value.set(
127
- bounds.width ?? 0,
128
- bounds.height ?? 0
129
- );
106
+ const material = getShaderMaterial(item.mesh);
107
+ material.uniforms.uMeshSize?.value.set(bounds.width ?? 0, bounds.height ?? 0);
130
108
  item.width = bounds.width;
131
109
  item.height = bounds.height;
132
110
  }
133
111
  }
134
112
  this.setImageMeshPositions();
135
113
  }
136
- resizeTextStore() {
137
- for (const item of this.textStore) {
138
- const bounds = item.htmlEl.getBoundingClientRect();
139
- const { scaleX, scaleY } = getMSDFFontMeshScales(
140
- bounds.width,
141
- item.mesh.geometry?._layout?._width
142
- );
143
- item.mesh.scale.set(scaleX, scaleY, 1);
144
- item.width = bounds.width;
145
- item.height = bounds.height * heightPositionCoef;
146
- }
147
- this.setTextMeshPositions();
148
- }
114
+ // resizeTextStore() {
115
+ // for (const item of this.textStore) {
116
+ // const bounds = item.htmlEl.getBoundingClientRect()
117
+ // const { scaleX, scaleY } = getMSDFFontMeshScales(
118
+ // bounds.width,
119
+ // item.mesh.geometry?._layout?._width,
120
+ // )
121
+ // item.mesh.scale.set(scaleX, scaleY, 1)
122
+ // item.width = bounds.width
123
+ // item.height = bounds.height * heightPositionCoef
124
+ // }
125
+ // this.setTextMeshPositions()
126
+ // }
149
127
  setImageMeshPositions() {
150
128
  if (this.imageStore.length === 0) return;
151
129
  for (const item of this.imageStore) {
@@ -153,24 +131,28 @@ class Canvas3Class {
153
131
  item.mesh.position.y = -item.htmlEl.getBoundingClientRect().top + this.height / 2 - item.height / 2;
154
132
  }
155
133
  }
156
- setTextMeshPositions() {
157
- if (this.textStore.length === 0) return;
158
- for (const item of this.textStore) {
159
- item.mesh.position.x = item.htmlEl.getBoundingClientRect().left - this.width / 2;
160
- item.mesh.position.y = -item.htmlEl.getBoundingClientRect().top + this.height / 2 - item.height / 2;
161
- }
162
- }
134
+ // setTextMeshPositions() {
135
+ // if (this.textStore.length === 0) return
136
+ // for (const item of this.textStore) {
137
+ // item.mesh.position.x
138
+ // = item.htmlEl.getBoundingClientRect().left - this.width / 2
139
+ // item.mesh.position.y
140
+ // = -item.htmlEl.getBoundingClientRect().top
141
+ // + this.height / 2
142
+ // - item.height / 2
143
+ // }
144
+ // }
163
145
  meshUniformsUpdate(id, uniforms) {
164
146
  const mesh = this.scene.getObjectByName(id);
165
147
  if (!mesh) return;
148
+ const material = getShaderMaterial(mesh);
166
149
  for (const uniKey in uniforms) {
167
150
  if (uniforms[uniKey]) {
168
- if (!mesh.material.uniforms[uniKey])
169
- mesh.material.uniforms[uniKey] = {
170
- value: uniforms[uniKey].value,
171
- duration: 0
151
+ if (!material.uniforms[uniKey])
152
+ material.uniforms[uniKey] = {
153
+ value: uniforms[uniKey].value
172
154
  };
173
- gsap.to(mesh.material.uniforms[uniKey], {
155
+ gsap.to(material.uniforms[uniKey], {
174
156
  duration: uniforms[uniKey].duration,
175
157
  value: uniforms[uniKey].value,
176
158
  ease: uniforms[uniKey].ease ?? "power1.inOut"
@@ -184,15 +166,16 @@ class Canvas3Class {
184
166
  console.error("no Mesh found with ID: " + meshId);
185
167
  return;
186
168
  }
187
- if (mesh.material.uniforms.uAniInImage && this.options.activateMeshOptions.image.uAniInImage) {
188
- gsap.to(mesh.material.uniforms.uAniInImage, {
169
+ const material = getShaderMaterial(mesh);
170
+ if (material.uniforms.uAniInImage && this.options.activateMeshOptions.image.uAniInImage) {
171
+ gsap.to(material.uniforms.uAniInImage, {
189
172
  duration: this.options.activateMeshOptions.image.uAniInImage.duration,
190
173
  value: isActive ? 1 : 0,
191
174
  ease: this.options.activateMeshOptions.image.uAniInImage.ease
192
175
  });
193
176
  }
194
- if (mesh.material.uniforms.uAniInText && this.options.activateMeshOptions.text.uAniInText) {
195
- gsap.to(mesh.material.uniforms.uAniInText, {
177
+ if (material.uniforms.uAniInText && this.options.activateMeshOptions.text.uAniInText) {
178
+ gsap.to(material.uniforms.uAniInText, {
196
179
  duration: this.options.activateMeshOptions.text.uAniInText.duration,
197
180
  value: isActive ? 1 : 0,
198
181
  ease: this.options.activateMeshOptions.text.uAniInText.ease
@@ -201,8 +184,9 @@ class Canvas3Class {
201
184
  const activateMeshUniforms = this.activateMeshUniformMap.get(meshId) ?? null;
202
185
  if (activateMeshUniforms) {
203
186
  for (const [key, value] of Object.entries(activateMeshUniforms)) {
204
- if (mesh.material.uniforms[key]) {
205
- gsap.to(mesh.material.uniforms[key], {
187
+ const material2 = getShaderMaterial(mesh);
188
+ if (material2.uniforms[key]) {
189
+ gsap.to(material2.uniforms[key], {
206
190
  duration: value.duration,
207
191
  value: isActive ? 1 : 0,
208
192
  ease: value.ease ?? "power1.inOut"
@@ -240,11 +224,12 @@ class Canvas3Class {
240
224
  }
241
225
  }
242
226
  removeMesh(id) {
243
- const toRemove = this.scene.getObjectByName(id);
244
- if (!toRemove) return;
245
- this.scene.remove(toRemove);
246
- toRemove.geometry.dispose();
247
- toRemove.material.dispose();
227
+ const meshToRemove = this.scene.getObjectByName(id);
228
+ if (!meshToRemove) return;
229
+ this.scene.remove(meshToRemove);
230
+ meshToRemove.geometry.dispose();
231
+ const material = getShaderMaterial(meshToRemove);
232
+ material.dispose();
248
233
  for (const [index, item] of this.imageStore.entries()) {
249
234
  if (item.name === id) {
250
235
  this.imageStore.splice(index, 1);
@@ -417,7 +402,7 @@ class Canvas3Class {
417
402
  this.setImageMeshPositions();
418
403
  }
419
404
  composerPass() {
420
- if (!this.options.shaders.scroll) return;
405
+ if (!this.options.shaders.scroll || !this.renderer) return;
421
406
  this.composer = new EffectComposer(this.renderer);
422
407
  if (this.camera)
423
408
  this.renderPass = new RenderPass(this.scene, this.camera);
@@ -442,9 +427,11 @@ class Canvas3Class {
442
427
  this.camera.aspect = this.width / this.height;
443
428
  this.camera.updateProjectionMatrix();
444
429
  }
445
- this.renderer.setSize(this.width, this.height);
446
- this.renderer.setPixelRatio(window.devicePixelRatio);
447
- this.renderer.render(this.scene, this.camera);
430
+ if (this.renderer) {
431
+ this.renderer.setSize(this.width, this.height);
432
+ this.renderer.setPixelRatio(window.devicePixelRatio);
433
+ this.renderer.render(this.scene, this.camera);
434
+ }
448
435
  }
449
436
  scrollToTop(delay = 0) {
450
437
  setTimeout(() => {
@@ -474,11 +461,9 @@ class Canvas3Class {
474
461
  if (this.customPass && this.customPass.uniforms.scrollSpeed)
475
462
  this.customPass.uniforms.scrollSpeed.value = this.scroll?.speedTarget;
476
463
  this.setImageMeshPositions();
477
- this.setTextMeshPositions();
478
464
  }
479
465
  if (this.animateImageMesh) {
480
466
  this.resizeImageStore();
481
- this.resizeTextStore();
482
467
  }
483
468
  for (const material of this.materials) {
484
469
  if (material.uniforms.uTime)
@@ -1,7 +1,8 @@
1
- import type { ScrollActionBinding, ScrollActionType } from '#canvas3-nuxt/types/types';
2
- export declare function generateBindingLogic(newBindingData: ScrollActionBinding): ScrollActionType;
1
+ import type { ScrollActionType } from '#canvas3-nuxt/types/types';
2
+ import type { Mesh, ShaderMaterial, Texture } from 'three';
3
+ export declare function generateBindingLogic(newBindingData: ScrollActionType): ScrollActionType;
3
4
  export declare function findMeshIDs(elParent: HTMLElement): false | string[];
4
- export declare function loadTexture(src: string): Promise<unknown>;
5
+ export declare function loadTexture(src: string): Promise<Texture>;
5
6
  export declare const heightPositionCoef = 1.38;
6
7
  export declare function getMSDFFontMeshScales(boundsWidth: number, geometryWidth: number): {
7
8
  scaleX: number;
@@ -10,3 +11,4 @@ export declare function getMSDFFontMeshScales(boundsWidth: number, geometryWidth
10
11
  export declare function setScrollActiveElements(elNode: HTMLElement, meshIds: string[], state: string): void;
11
12
  export declare function elementNearViewport(bounds: DOMRect, margin?: number): boolean;
12
13
  export declare const lerp: (a: number, b: number, n: number) => number;
14
+ export declare function getShaderMaterial(mesh: Mesh): ShaderMaterial;
@@ -62,14 +62,11 @@ export function findMeshIDs(elParent) {
62
62
  export function loadTexture(src) {
63
63
  return new Promise((resolve, reject) => {
64
64
  const loader = new THREE.TextureLoader();
65
- loader.load(
65
+ return loader.load(
66
66
  src,
67
67
  (texture) => resolve(texture),
68
- // On success
69
68
  void 0,
70
- // On progress (optional)
71
69
  (err) => reject(err)
72
- // On error
73
70
  );
74
71
  });
75
72
  }
@@ -94,3 +91,6 @@ export function elementNearViewport(bounds, margin = 200) {
94
91
  return bounds.top >= -margin && bounds.top <= windowHeight || bounds.bottom >= -margin && bounds.bottom <= windowHeight || bounds.top <= -margin && bounds.bottom >= windowHeight;
95
92
  }
96
93
  export const lerp = (a, b, n) => (1 - n) * a + n * b;
94
+ export function getShaderMaterial(mesh) {
95
+ return mesh.material;
96
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canvas3/nuxt",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -1,6 +0,0 @@
1
- import type { Directive } from 'vue';
2
- export declare const vCanvas3Image: Directive<HTMLImageElement, {
3
- shaderName?: string;
4
- uniforms?: Record<string, any>;
5
- activateMeshUniforms?: Record<string, any>;
6
- }>;
@@ -1,2 +0,0 @@
1
- declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
2
- export default _default;
@@ -1,3 +0,0 @@
1
- import { defineNuxtPlugin } from "#app";
2
- export default defineNuxtPlugin((_nuxtApp) => {
3
- });
@@ -1,36 +0,0 @@
1
- declare module 'three-msdf-text-utils' {
2
- import * as THREE from 'three'
3
-
4
- export interface GlyphGeometryOptions {
5
- flipY?: boolean
6
- negate?: boolean
7
- multipage?: boolean
8
- }
9
-
10
- export class GlyphGeometry extends THREE.BufferGeometry {
11
- constructor(text: string, font: any, options?: GlyphGeometryOptions)
12
- layout: any
13
- update(text: string): void
14
- }
15
-
16
- export interface MSDFShaderOptions {
17
- map?: THREE.Texture
18
- color?: THREE.Color | string | number
19
- opacity?: number
20
- alphaTest?: number
21
- negate?: boolean
22
- precision?: string
23
- multipage?: boolean
24
- side?: THREE.Side
25
- transparent?: boolean
26
- defines?: { [key: string]: any }
27
- uniforms?: { [key: string]: any }
28
- }
29
-
30
- export function createMSDFShader(options?: MSDFShaderOptions): {
31
- uniforms: { [key: string]: THREE.IUniform }
32
- vertexShader: string
33
- fragmentShader: string
34
- defines: { [key: string]: any }
35
- }
36
- }