@canvas3/nuxt 0.1.17 → 0.1.19

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.17",
4
+ "version": "0.1.19",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.0"
@@ -19,7 +19,14 @@ type MeshAnimation = {
19
19
  ease: string;
20
20
  };
21
21
  export type AnimationCallback = () => void;
22
- export type AnimationCallbacks = Map<string, AnimationCallback>;
22
+ export type AnimationCallOptions = {
23
+ onScroll: boolean;
24
+ onResize: boolean;
25
+ onMouseMove: boolean;
26
+ onAnimationsRender: boolean;
27
+ animationCallback: AnimationCallback;
28
+ };
29
+ export type AnimationCallbacks = Map<string, AnimationCallOptions>;
23
30
  export type MeshMaterialUniform = Record<string, {
24
31
  duration: number;
25
32
  ease: string | null | undefined;
@@ -4,10 +4,13 @@ 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 { AnimationCallback, AnimationCallbacks, Canvas3OptionsType, ScrollActionBinding, MeshMaterialUniform, MeshType, myEffectType } from '#canvas3-nuxt/types/types';
7
+ import type { AnimationCallbacks, Canvas3OptionsType, ScrollActionBinding, MeshMaterialUniform, MeshType, myEffectType, AnimationCallOptions } from '#canvas3-nuxt/types/types';
8
8
  declare class Canvas3Class {
9
9
  canvasInitiated: import("vue").Ref<boolean, boolean>;
10
- animateImageMesh: boolean;
10
+ mouseMoveInProgress: boolean;
11
+ animationsRender: boolean;
12
+ resizeInProgress: boolean;
13
+ meshPositionsUpdate: boolean;
11
14
  canvasContainer: HTMLElement | null;
12
15
  scrollableContent: HTMLElement | null;
13
16
  time: number;
@@ -46,7 +49,7 @@ declare class Canvas3Class {
46
49
  updateOnScrollActiveElement(updatedBinding: ScrollActionBinding): void;
47
50
  removeScrollActiveElement(elNode: HTMLElement): void;
48
51
  removeMesh(id: string): void;
49
- addAnimationToRender(callBackName: string, callBackFunction: AnimationCallback): void;
52
+ addAnimationToRender(callBackName: string, callBackOptions: AnimationCallOptions): void;
50
53
  removeAnimationFromRender(callBackName: string): void;
51
54
  addImageAsMesh(imgHtmlEl: HTMLImageElement, shaderName: string | null, meshId: string, meshUniforms: MeshMaterialUniform, activateMeshUniforms: MeshMaterialUniform): Promise<void>;
52
55
  composerPass(): void;
@@ -55,6 +58,8 @@ declare class Canvas3Class {
55
58
  scrollTo(position: number, delay?: number): void;
56
59
  scrollToElBySelector(elQuerySelector: string, delay?: number, margin?: number): void;
57
60
  setMeshPositionsUpdate(state: boolean): void;
61
+ setAnimationsToRender(state: boolean): void;
62
+ externalAnimationsRender(): void;
58
63
  render(): void;
59
64
  }
60
65
  export declare const Canvas3: Canvas3Class;
@@ -14,7 +14,10 @@ import { studio783log } from "#canvas3-nuxt/constants/studio783Log";
14
14
  const canvasInitiated = ref(false);
15
15
  class Canvas3Class {
16
16
  canvasInitiated = canvasInitiated;
17
- animateImageMesh = false;
17
+ mouseMoveInProgress = false;
18
+ animationsRender = false;
19
+ resizeInProgress = false;
20
+ meshPositionsUpdate = false;
18
21
  canvasContainer = null;
19
22
  scrollableContent = null;
20
23
  time = 0;
@@ -59,6 +62,7 @@ class Canvas3Class {
59
62
  this.composerPass();
60
63
  this.render();
61
64
  window.addEventListener("mousemove", (event) => {
65
+ this.mouseMoveInProgress = true;
62
66
  this.mouse.x = event.clientX / this.width;
63
67
  this.mouse.y = event.clientY / this.height;
64
68
  setTimeout(() => {
@@ -69,6 +73,9 @@ class Canvas3Class {
69
73
  this.mouse.movementX = this.mouse.x;
70
74
  this.mouse.movementY = this.mouse.y;
71
75
  }
76
+ setTimeout(() => {
77
+ this.mouseMoveInProgress = false;
78
+ }, 0);
72
79
  });
73
80
  this.canvasInitiated.value = true;
74
81
  studio783log();
@@ -91,10 +98,14 @@ class Canvas3Class {
91
98
  this.canvasContainer?.appendChild(this.renderer.domElement);
92
99
  }
93
100
  resizeOnChange() {
101
+ this.resizeInProgress = true;
94
102
  this.setSize();
95
103
  this.resizeImageStore();
96
104
  this.scroll?.resizeMobileBreakEvents();
97
105
  this.scroll?.setSize();
106
+ setTimeout(() => {
107
+ this.resizeInProgress = false;
108
+ }, 0);
98
109
  }
99
110
  resizeImageStore() {
100
111
  for (const item of this.imageStore) {
@@ -110,19 +121,6 @@ class Canvas3Class {
110
121
  }
111
122
  this.setImageMeshPositions();
112
123
  }
113
- // resizeTextStore() {
114
- // for (const item of this.textStore) {
115
- // const bounds = item.htmlEl.getBoundingClientRect()
116
- // const { scaleX, scaleY } = getMSDFFontMeshScales(
117
- // bounds.width,
118
- // item.mesh.geometry?._layout?._width,
119
- // )
120
- // item.mesh.scale.set(scaleX, scaleY, 1)
121
- // item.width = bounds.width
122
- // item.height = bounds.height * heightPositionCoef
123
- // }
124
- // this.setTextMeshPositions()
125
- // }
126
124
  setImageMeshPositions() {
127
125
  if (this.imageStore.length === 0) return;
128
126
  for (const item of this.imageStore) {
@@ -130,17 +128,6 @@ class Canvas3Class {
130
128
  item.mesh.position.y = -item.htmlEl.getBoundingClientRect().top + this.height / 2 - item.height / 2;
131
129
  }
132
130
  }
133
- // setTextMeshPositions() {
134
- // if (this.textStore.length === 0) return
135
- // for (const item of this.textStore) {
136
- // item.mesh.position.x
137
- // = item.htmlEl.getBoundingClientRect().left - this.width / 2
138
- // item.mesh.position.y
139
- // = -item.htmlEl.getBoundingClientRect().top
140
- // + this.height / 2
141
- // - item.height / 2
142
- // }
143
- // }
144
131
  meshUniformsUpdate(id, uniforms) {
145
132
  const mesh = this.scene.getObjectByName(id);
146
133
  if (!mesh) return;
@@ -200,7 +187,6 @@ class Canvas3Class {
200
187
  addOnScrollActivateElement(binding) {
201
188
  const newBinding = generateBindingLogic(binding);
202
189
  this.scroll?.DOM.onScrollActivateElements.push(newBinding);
203
- console.log("this.scroll?.DOM.onScrollActivateElements", this.scroll?.DOM.onScrollActivateElements.length);
204
190
  }
205
191
  updateOnScrollActiveElement(updatedBinding) {
206
192
  if (!this.scroll) return;
@@ -253,113 +239,13 @@ class Canvas3Class {
253
239
  this.activateMeshUniformMap.delete(id);
254
240
  this.imageStore = this.imageStore.filter((item) => item.name !== id);
255
241
  }
256
- addAnimationToRender(callBackName, callBackFunction) {
242
+ addAnimationToRender(callBackName, callBackOptions) {
257
243
  if (this.animations.has(callBackName)) return;
258
- this.animations.set(callBackName, callBackFunction);
259
- console.log("addAnimationToRender", this.animations);
244
+ this.animations.set(callBackName, callBackOptions);
260
245
  }
261
246
  removeAnimationFromRender(callBackName) {
262
247
  this.animations.delete(callBackName);
263
248
  }
264
- // addTextAsMSDF(shaderName: string, meshId: string, htmlEl: HTMLElement, textContent: string, theme: string, meshUniforms: MeshMaterialUniform, activateMeshUniforms: MeshMaterialUniform) {
265
- // this.activateMeshUniformMap.set(meshId, activateMeshUniforms)
266
- //
267
- // let vertexShader = this.options.shaders.default.textVertex
268
- // let fragmentShader = this.options.shaders.default.textFragment
269
- // if (shaderName && this.options.shaders[shaderName]) {
270
- // vertexShader = this.options.shaders[shaderName].vertexShader
271
- // fragmentShader = this.options.shaders[shaderName].fragmentShader
272
- // }
273
- //
274
- // const bounds = htmlEl.getBoundingClientRect()
275
- // const position = { top: bounds.top, left: bounds.left }
276
- // position.top += this.currentScroll
277
- //
278
- // //* ****************************
279
- // // MSDF
280
- // //* ****************************
281
- //
282
- // const geometry = new MSDFTextGeometry({
283
- // text: textContent.trim(),
284
- // font: this.MSDFTextGeometryFont.data,
285
- // })
286
- //
287
- // const material = new THREE.ShaderMaterial({
288
- // side: THREE.DoubleSide,
289
- // transparent: true,
290
- // defines: {
291
- // IS_SMALL: false, // false,
292
- // },
293
- // uniforms: {
294
- // uDevicePixelRatio: { value: window.devicePixelRatio },
295
- // uColor: {
296
- // // TODO: colors dynamic from component
297
- // value: new THREE.Vector4(
298
- // theme === 'dark' ? 27 / 255 : 191 / 255, // R
299
- // theme === 'dark' ? 24 / 255 : 192 / 255, // G
300
- // theme === 'dark' ? 24 / 255 : 178 / 255, // B
301
- // ),
302
- // },
303
- // uViewport: {
304
- // value: new THREE.Vector2(this.width, this.height),
305
- // },
306
- // // Common
307
- // uMouse: { value: new THREE.Vector2(0, 0) },
308
- // uMouseMovement: { value: new THREE.Vector2(0, 0) },
309
- // uFooterGameBall: { value: new THREE.Vector2(0, 0) },
310
- // uMap: { value: null },
311
- // // Rendering
312
- // uThreshold: { value: 0.05 },
313
- // uAlphaTest: { value: 0.01 },
314
- // uStrokeOutsetWidth: { value: 0.0 },
315
- // uStrokeInsetWidth: { value: 0.3 }, // 0.3
316
- // // new generic
317
- // uTime: { value: 0 },
318
- // uMeshSize: { value: new THREE.Vector2(bounds.width, bounds.height) },
319
- // ...this.options.activateMeshOptions.text,
320
- // ...activateMeshUniforms,
321
- // ...meshUniforms,
322
- // },
323
- // vertexShader: vertexShader,
324
- // fragmentShader: fragmentShader,
325
- // })
326
- //
327
- // if (material.uniforms.uMap)
328
- // material.uniforms.uMap.value = this.MSDFTextGeometryAtlas
329
- //
330
- // this.materials.push(material)
331
- //
332
- // const mesh = new THREE.Mesh(geometry, material)
333
- // mesh.name = meshId
334
- // mesh.renderOrder = 1
335
- //
336
- // const { scaleX, scaleY } = getMSDFFontMeshScales(
337
- // bounds.width,
338
- // mesh.geometry?._layout?._width,
339
- // )
340
- //
341
- // mesh.scale.set(scaleX, scaleY, 1)
342
- //
343
- // this.scene.add(mesh)
344
- //
345
- // const newMesh: MeshType = {
346
- // name: meshId,
347
- // htmlEl: htmlEl,
348
- // mesh: mesh,
349
- // top: position.top,
350
- // left: position.left,
351
- // width: bounds.width,
352
- // height: bounds.height * heightPositionCoef,
353
- // }
354
- //
355
- // this.textStore.push(newMesh)
356
- //
357
- // this.setTextMeshPositions()
358
- //
359
- // if (htmlEl.dataset.activeScroll === 'true') {
360
- // this.activateMesh(meshId, true)
361
- // }
362
- // }
363
249
  async addImageAsMesh(imgHtmlEl, shaderName, meshId, meshUniforms, activateMeshUniforms) {
364
250
  if (activateMeshUniforms) {
365
251
  this.activateMeshUniformMap.set(meshId, activateMeshUniforms);
@@ -476,7 +362,23 @@ class Canvas3Class {
476
362
  }, delay * 1e3);
477
363
  }
478
364
  setMeshPositionsUpdate(state) {
479
- this.animateImageMesh = state;
365
+ this.meshPositionsUpdate = state;
366
+ }
367
+ setAnimationsToRender(state) {
368
+ this.animationsRender = state;
369
+ }
370
+ externalAnimationsRender() {
371
+ for (const [_key, callbackOption] of this.animations.entries()) {
372
+ const callBack = callbackOption.animationCallback;
373
+ if (!callBack) return;
374
+ const shouldRunOnScroll = callbackOption.onScroll && this.scroll?.scrollInProgress;
375
+ const shouldRunOnAnimationsRender = callbackOption.onAnimationsRender && this.animationsRender;
376
+ const shouldRunOnResize = callbackOption.onResize && this.resizeInProgress;
377
+ const shouldRunOnMouseMove = callbackOption.onMouseMove && this.mouseMoveInProgress;
378
+ if (shouldRunOnScroll || shouldRunOnAnimationsRender || shouldRunOnResize || shouldRunOnMouseMove) {
379
+ callBack();
380
+ }
381
+ }
480
382
  }
481
383
  render() {
482
384
  this.time += 0.05;
@@ -486,9 +388,10 @@ class Canvas3Class {
486
388
  this.customPass.uniforms.scrollSpeed.value = this.scroll?.speedTarget;
487
389
  this.setImageMeshPositions();
488
390
  }
489
- if (this.animateImageMesh) {
391
+ if (this.meshPositionsUpdate) {
490
392
  this.resizeImageStore();
491
393
  }
394
+ this.externalAnimationsRender();
492
395
  if (this.materials.length > 0) {
493
396
  for (const material of this.materials) {
494
397
  if (material.uniforms.uTime)
@@ -505,9 +408,6 @@ class Canvas3Class {
505
408
  );
506
409
  }
507
410
  }
508
- for (const [_key, callback] of this.animations.entries()) {
509
- callback?.();
510
- }
511
411
  if (this.composer) {
512
412
  this.composer.render();
513
413
  } else if (this.renderer && this.camera) {
@@ -3,11 +3,12 @@ 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, callBackFunction: import("../types/types.js").AnimationCallback) => void;
6
+ addAnimationToRender: (callBackName: string, callBackOptions: import("../types/types.js").AnimationCallOptions) => 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
+ setAnimationsToRender: (state: boolean) => void;
11
12
  resizeOnChange: () => void;
12
13
  scrollToElBySelector: (elQuerySelector: string, delay?: number, margin?: number) => void;
13
14
  setMeshPositionsUpdate: (state: boolean) => void;
@@ -12,6 +12,7 @@ export const Canvas3 = {
12
12
  addImageAsMesh: mainClass.addImageAsMesh.bind(mainClass),
13
13
  getShaderMaterial,
14
14
  removeMesh: mainClass.removeMesh.bind(mainClass),
15
+ setAnimationsToRender: mainClass.setAnimationsToRender.bind(mainClass),
15
16
  resizeOnChange: mainClass.resizeOnChange.bind(mainClass),
16
17
  scrollToElBySelector: mainClass.scrollToElBySelector.bind(mainClass),
17
18
  setMeshPositionsUpdate: mainClass.setMeshPositionsUpdate.bind(mainClass),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canvas3/nuxt",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },