@canvas3/nuxt 0.0.1 → 0.0.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.
Files changed (32) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/runtime/components/canvas3-image.vue +10 -13
  3. package/dist/runtime/components/canvas3-image.vue.d.ts +7 -4
  4. package/dist/runtime/components/canvas3-text.vue.d.ts +9 -8
  5. package/dist/runtime/constants/studio783Log.d.ts +1 -0
  6. package/dist/runtime/constants/studio783Log.js +22 -0
  7. package/dist/runtime/directives/canvas3-image.client.d.ts +3 -0
  8. package/dist/runtime/directives/{canvas3-image-directive.client.js → canvas3-image.client.js} +5 -4
  9. package/dist/runtime/layouts/canvas3-layout.vue.d.ts +9 -8
  10. package/dist/runtime/plugins/directives.js +1 -1
  11. package/dist/runtime/types/types.d.ts +62 -12
  12. package/dist/runtime/types/types.js +1 -0
  13. package/dist/runtime/types/vue-directives.d.ts +10 -0
  14. package/dist/runtime/utils/canvas3/canvas3.d.ts +5 -10
  15. package/dist/runtime/utils/canvas3/canvas3.js +68 -83
  16. package/dist/runtime/utils/canvas3/helpers.d.ts +5 -3
  17. package/dist/runtime/utils/canvas3/helpers.js +5 -5
  18. package/package.json +1 -1
  19. package/dist/runtime/directives/canvas3-image-directive.client.d.ts +0 -6
  20. package/dist/runtime/plugin.d.ts +0 -2
  21. package/dist/runtime/plugin.js +0 -3
  22. package/dist/runtime/types/three-msdf-text-utils.d.ts +0 -36
  23. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/TextLayout.d.ts +0 -1
  24. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/TextLayout.js +0 -0
  25. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/createIndices.d.ts +0 -1
  26. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/createIndices.js +0 -0
  27. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/index.d.ts +0 -1
  28. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/index.js +0 -0
  29. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/utils.d.ts +0 -1
  30. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/utils.js +0 -0
  31. package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/vertices.d.ts +0 -1
  32. 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.4",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.0"
@@ -16,20 +16,17 @@
16
16
  import { ref, computed, watch, onMounted, nextTick, onBeforeUnmount } from "vue";
17
17
  import { Canvas3 } from "#canvas3-nuxt/utils/canvas3/canvas3";
18
18
  const props = defineProps({
19
- options: {
20
- type: Object,
21
- default: () => ({
22
- alt: "",
23
- src: "",
24
- loadStrategy: "lazy",
25
- shaderName: void 0,
26
- uniforms: {},
27
- activateMeshUniforms: {}
28
- })
29
- }
19
+ options: { type: Object, required: true, default: () => ({
20
+ alt: "",
21
+ src: "",
22
+ loadStrategy: "lazy",
23
+ shaderName: void 0,
24
+ uniforms: {},
25
+ activateMeshUniforms: {}
26
+ }) }
30
27
  });
31
28
  const reducedMotion = computed(() => Canvas3.options?.disabled ?? null);
32
- const image = ref(null);
29
+ const image = ref();
33
30
  const generatedMeshId = "image_" + crypto.randomUUID();
34
31
  const imgAddedToCanvas = ref(false);
35
32
  const addImageToCanvas = async () => {
@@ -37,7 +34,7 @@ const addImageToCanvas = async () => {
37
34
  if (!image.value || Canvas3.canvasInitiated.value === false || Canvas3.options?.disabled || imgAddedToCanvas.value) return;
38
35
  if (image.value.naturalWidth === 0) return;
39
36
  image.value.dataset.meshId = generatedMeshId;
40
- Canvas3.addImageAsMesh(
37
+ await Canvas3.addImageAsMesh(
41
38
  image.value,
42
39
  props.options.shaderName,
43
40
  generatedMeshId,
@@ -1,5 +1,8 @@
1
- declare const _default: import("vue").DefineComponent<{}, {
2
- options: Record<string, any>;
3
- $props: any;
4
- }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
1
+ import type { Canvas3ImageBindType } from '#canvas3-nuxt/types/types';
2
+ type __VLS_Props = {
3
+ options: Canvas3ImageBindType;
4
+ };
5
+ declare const _default: import("vue").DefineComponent<__VLS_Props, void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
6
+ options: Canvas3ImageBindType;
7
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
5
8
  export default _default;
@@ -1,11 +1,12 @@
1
+ declare var __VLS_1: {};
2
+ type __VLS_Slots = {} & {
3
+ default?: (props: typeof __VLS_1) => any;
4
+ };
5
+ declare const __VLS_component: import("vue").DefineSetupFnComponent<Record<string, any>, {}, {}, Record<string, any> & {}, import("vue").PublicProps>;
1
6
  declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
2
7
  export default _default;
3
- type __VLS_WithSlots<T, S> = T & (new () => {
4
- $slots: S;
5
- });
6
- declare const __VLS_component: import("vue").DefineComponent<{}, {
7
- $props: any;
8
- }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
9
- type __VLS_Slots = {
10
- default?: ((props: {}) => any) | undefined;
8
+ type __VLS_WithSlots<T, S> = T & {
9
+ new (): {
10
+ $slots: S;
11
+ };
11
12
  };
@@ -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 ?? {}
@@ -33,6 +33,7 @@ async function tryAdd(el, options) {
33
33
  addedMap.set(el, true);
34
34
  srcMap.set(el, getImgSrc(el));
35
35
  el.classList.add("webgl-img");
36
+ el.style.opacity = "0";
36
37
  }
37
38
  function remove(el) {
38
39
  const meshId = meshIdMap.get(el);
@@ -53,7 +54,7 @@ export const vCanvas3Image = {
53
54
  if (el.tagName !== "IMG") {
54
55
  return;
55
56
  }
56
- const options = binding.value || {};
57
+ const options = binding.value ?? {};
57
58
  const stop = watch(
58
59
  () => Canvas3.canvasInitiated.value,
59
60
  (ready) => {
@@ -70,7 +71,7 @@ export const vCanvas3Image = {
70
71
  }
71
72
  },
72
73
  updated(el, binding) {
73
- const options = binding.value || {};
74
+ const options = binding.value ?? {};
74
75
  const meshId = meshIdMap.get(el);
75
76
  if (meshId && options?.uniforms) {
76
77
  Canvas3.meshUniformsUpdate(meshId, options.uniforms);
@@ -1,11 +1,12 @@
1
+ declare var __VLS_1: {};
2
+ type __VLS_Slots = {} & {
3
+ default?: (props: typeof __VLS_1) => any;
4
+ };
5
+ declare const __VLS_component: import("vue").DefineComponent<{}, void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, any, string, import("vue").PublicProps, any, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
1
6
  declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
2
7
  export default _default;
3
- type __VLS_WithSlots<T, S> = T & (new () => {
4
- $slots: S;
5
- });
6
- declare const __VLS_component: import("vue").DefineComponent<{}, {
7
- $emit: (event: "canvas3-ready", ...args: any[]) => void;
8
- }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
9
- type __VLS_Slots = {
10
- default?: ((props: {}) => any) | undefined;
8
+ type __VLS_WithSlots<T, S> = T & {
9
+ new (): {
10
+ $slots: S;
11
+ };
11
12
  };
@@ -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;
@@ -48,17 +53,39 @@ export type MeshType = {
48
53
  width: number;
49
54
  height: number;
50
55
  };
56
+ export type scrollActionBindOptionType = {
57
+ activateOnce?: boolean;
58
+ trackOnly?: boolean;
59
+ fixToParent?: {
60
+ containerId: string;
61
+ fixPosition: number;
62
+ margin: number;
63
+ };
64
+ scrollSpeed?: {
65
+ value: number;
66
+ };
67
+ scrollSpeedSetTo?: {
68
+ value: number;
69
+ duration: number;
70
+ };
71
+ activateCallback?: (item: ScrollActionType) => void;
72
+ onScrollCallback?: (item: ScrollActionType, scrollSpeed: number, currentPosition: number) => void;
73
+ activeRangeMargin?: number;
74
+ activeRangeOrigin?: number;
75
+ activeRange?: number;
76
+ bidirectionalActivation?: boolean;
77
+ };
51
78
  export type ScrollActionBinding = {
52
79
  elNode: HTMLElement;
53
- options: DirectiveBinding['value'];
80
+ options: scrollActionBindOptionType;
54
81
  arg: DirectiveBinding['arg'];
55
82
  };
56
83
  export type ScrollActionType = {
57
84
  elNode: HTMLElement;
58
- options: DirectiveBinding['value'];
85
+ options: scrollActionBindOptionType;
59
86
  arg: DirectiveBinding['arg'];
60
87
  containedMeshIds?: string[];
61
- bounds: DOMRect;
88
+ bounds?: DOMRect;
62
89
  containerId?: string;
63
90
  fixPosition?: number;
64
91
  containerEl?: HTMLElement;
@@ -68,4 +95,27 @@ export type ScrollActionType = {
68
95
  containerBottom?: number;
69
96
  trackOnly?: boolean;
70
97
  };
98
+ export type myEffectType = {
99
+ uniforms: BaseUniform;
100
+ vertexShader: string;
101
+ fragmentShader: string;
102
+ };
103
+ export type Canvas3ImageBinding = {
104
+ shaderName?: string;
105
+ uniforms?: MeshMaterialUniform;
106
+ activateMeshUniforms?: MeshMaterialUniform;
107
+ };
108
+ export type Canvas3ImageBindType = {
109
+ alt: string;
110
+ src: string;
111
+ loadStrategy?: 'lazy' | 'eager' | undefined;
112
+ shaderName?: string;
113
+ uniforms?: MeshMaterialUniform;
114
+ activateMeshUniforms: MeshMaterialUniform;
115
+ };
116
+ declare module 'vue' {
117
+ interface GlobalDirectives {
118
+ 'canvas3-image': ObjectDirective<HTMLImageElement, Canvas3ImageBinding>;
119
+ }
120
+ }
71
121
  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,11 @@ import { ShaderPass } from "three/addons/postprocessing/ShaderPass.js";
6
6
  import { gsap } from "gsap";
7
7
  import {
8
8
  generateBindingLogic,
9
- getMSDFFontMeshScales,
10
- heightPositionCoef,
11
- loadTexture
9
+ getShaderMaterial
12
10
  } from "./helpers.js";
13
11
  import Scroll from "#canvas3-nuxt/utils/canvas3/scroll";
14
12
  import { defaultCanvas3Options } from "#canvas3-nuxt/constants/default-canvas3-options";
13
+ import { studio783log } from "#canvas3-nuxt/constants/studio783Log";
15
14
  const canvasInitiated = ref(false);
16
15
  class Canvas3Class {
17
16
  canvasInitiated = canvasInitiated;
@@ -20,11 +19,11 @@ class Canvas3Class {
20
19
  scrollableContent = null;
21
20
  time = 0;
22
21
  scene = new THREE.Scene();
23
- MSDFTextGeometryAtlas;
24
- MSDFTextGeometryFont;
22
+ // MSDFTextGeometryAtlas: any
23
+ // MSDFTextGeometryFont: any
25
24
  materials = [];
26
25
  imageStore = [];
27
- textStore = [];
26
+ // textStore: MeshType[] = []
28
27
  activateMeshUniformMap = /* @__PURE__ */ new Map();
29
28
  scroll = null;
30
29
  currentScroll = 0;
@@ -34,15 +33,18 @@ class Canvas3Class {
34
33
  camera = null;
35
34
  composer = null;
36
35
  renderPass = null;
37
- renderer;
38
- myEffect;
36
+ renderer = null;
37
+ myEffect = {
38
+ uniforms: {
39
+ tDiffuse: { value: null },
40
+ scrollSpeed: { value: null }
41
+ },
42
+ vertexShader: "",
43
+ fragmentShader: ""
44
+ };
39
45
  customPass = null;
40
46
  animations = /* @__PURE__ */ new Map();
41
47
  mouse = { x: 0, y: 0, movementX: 0, movementY: 0, xPrev: 0, yPrev: 0 };
42
- // triggerSectionPositions= {};
43
- // constructor({ canvasOptions }) {
44
- // this.options = canvasOptions;
45
- // }
46
48
  async init(canvasElement, scrollableContent, canvas3Options) {
47
49
  this.options = canvas3Options;
48
50
  this.scene = new THREE.Scene();
@@ -69,6 +71,7 @@ class Canvas3Class {
69
71
  }
70
72
  });
71
73
  this.canvasInitiated.value = true;
74
+ studio783log();
72
75
  }
73
76
  setCanvasAndCamera() {
74
77
  this.width = this.canvasContainer?.offsetWidth ?? 0;
@@ -87,33 +90,9 @@ class Canvas3Class {
87
90
  this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.5));
88
91
  this.canvasContainer?.appendChild(this.renderer.domElement);
89
92
  }
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
93
  resizeOnChange() {
114
94
  this.setSize();
115
95
  this.resizeImageStore();
116
- this.resizeTextStore();
117
96
  this.scroll?.resizeMobileBreakEvents();
118
97
  this.scroll?.setSize();
119
98
  }
@@ -123,29 +102,27 @@ class Canvas3Class {
123
102
  const bounds = item.htmlEl.getBoundingClientRect();
124
103
  if (!bounds) return;
125
104
  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
- );
105
+ const material = getShaderMaterial(item.mesh);
106
+ material.uniforms.uMeshSize?.value.set(bounds.width ?? 0, bounds.height ?? 0);
130
107
  item.width = bounds.width;
131
108
  item.height = bounds.height;
132
109
  }
133
110
  }
134
111
  this.setImageMeshPositions();
135
112
  }
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
- }
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
+ // }
149
126
  setImageMeshPositions() {
150
127
  if (this.imageStore.length === 0) return;
151
128
  for (const item of this.imageStore) {
@@ -153,24 +130,28 @@ class Canvas3Class {
153
130
  item.mesh.position.y = -item.htmlEl.getBoundingClientRect().top + this.height / 2 - item.height / 2;
154
131
  }
155
132
  }
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
- }
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
+ // }
163
144
  meshUniformsUpdate(id, uniforms) {
164
145
  const mesh = this.scene.getObjectByName(id);
165
146
  if (!mesh) return;
147
+ const material = getShaderMaterial(mesh);
166
148
  for (const uniKey in uniforms) {
167
149
  if (uniforms[uniKey]) {
168
- if (!mesh.material.uniforms[uniKey])
169
- mesh.material.uniforms[uniKey] = {
170
- value: uniforms[uniKey].value,
171
- duration: 0
150
+ if (!material.uniforms[uniKey])
151
+ material.uniforms[uniKey] = {
152
+ value: uniforms[uniKey].value
172
153
  };
173
- gsap.to(mesh.material.uniforms[uniKey], {
154
+ gsap.to(material.uniforms[uniKey], {
174
155
  duration: uniforms[uniKey].duration,
175
156
  value: uniforms[uniKey].value,
176
157
  ease: uniforms[uniKey].ease ?? "power1.inOut"
@@ -184,15 +165,16 @@ class Canvas3Class {
184
165
  console.error("no Mesh found with ID: " + meshId);
185
166
  return;
186
167
  }
187
- if (mesh.material.uniforms.uAniInImage && this.options.activateMeshOptions.image.uAniInImage) {
188
- gsap.to(mesh.material.uniforms.uAniInImage, {
168
+ const material = getShaderMaterial(mesh);
169
+ if (material.uniforms.uAniInImage && this.options.activateMeshOptions.image.uAniInImage) {
170
+ gsap.to(material.uniforms.uAniInImage, {
189
171
  duration: this.options.activateMeshOptions.image.uAniInImage.duration,
190
172
  value: isActive ? 1 : 0,
191
173
  ease: this.options.activateMeshOptions.image.uAniInImage.ease
192
174
  });
193
175
  }
194
- if (mesh.material.uniforms.uAniInText && this.options.activateMeshOptions.text.uAniInText) {
195
- gsap.to(mesh.material.uniforms.uAniInText, {
176
+ if (material.uniforms.uAniInText && this.options.activateMeshOptions.text.uAniInText) {
177
+ gsap.to(material.uniforms.uAniInText, {
196
178
  duration: this.options.activateMeshOptions.text.uAniInText.duration,
197
179
  value: isActive ? 1 : 0,
198
180
  ease: this.options.activateMeshOptions.text.uAniInText.ease
@@ -201,8 +183,9 @@ class Canvas3Class {
201
183
  const activateMeshUniforms = this.activateMeshUniformMap.get(meshId) ?? null;
202
184
  if (activateMeshUniforms) {
203
185
  for (const [key, value] of Object.entries(activateMeshUniforms)) {
204
- if (mesh.material.uniforms[key]) {
205
- gsap.to(mesh.material.uniforms[key], {
186
+ const material2 = getShaderMaterial(mesh);
187
+ if (material2.uniforms[key]) {
188
+ gsap.to(material2.uniforms[key], {
206
189
  duration: value.duration,
207
190
  value: isActive ? 1 : 0,
208
191
  ease: value.ease ?? "power1.inOut"
@@ -240,11 +223,12 @@ class Canvas3Class {
240
223
  }
241
224
  }
242
225
  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();
226
+ const meshToRemove = this.scene.getObjectByName(id);
227
+ if (!meshToRemove) return;
228
+ this.scene.remove(meshToRemove);
229
+ meshToRemove.geometry.dispose();
230
+ const material = getShaderMaterial(meshToRemove);
231
+ material.dispose();
248
232
  for (const [index, item] of this.imageStore.entries()) {
249
233
  if (item.name === id) {
250
234
  this.imageStore.splice(index, 1);
@@ -367,7 +351,8 @@ class Canvas3Class {
367
351
  const position = { top: bounds.top, left: bounds.left };
368
352
  position.top += this.currentScroll;
369
353
  const geometry = new THREE.PlaneGeometry(1, 1);
370
- const texture = await loadTexture(imgHtmlEl.src);
354
+ const bitmap = await createImageBitmap(imgHtmlEl, { imageOrientation: "flipY" });
355
+ const texture = new THREE.Texture(bitmap);
371
356
  texture.needsUpdate = true;
372
357
  const material = new THREE.ShaderMaterial({
373
358
  uniforms: {
@@ -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;
@@ -38,7 +38,7 @@ export function generateBindingLogic(newBindingData) {
38
38
  duration: newBindingData.options.scrollSpeedSetTo.duration,
39
39
  value: newBindingData.options.scrollSpeedSetTo.value,
40
40
  onComplete: () => {
41
- binding.elNode.dataset.scrollSpeed = newBindingData.options.scrollSpeedSetTo.value;
41
+ binding.elNode.dataset.scrollSpeed = newBindingData.options.scrollSpeedSetTo?.value.toString() ?? "0";
42
42
  }
43
43
  });
44
44
  }
@@ -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.4",
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
- }