@canvas3/nuxt 0.0.1
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/README.md +70 -0
- package/dist/module.d.mts +5 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +32 -0
- package/dist/runtime/components/canvas3-image.vue +71 -0
- package/dist/runtime/components/canvas3-image.vue.d.ts +5 -0
- package/dist/runtime/components/canvas3-text.vue +95 -0
- package/dist/runtime/components/canvas3-text.vue.d.ts +11 -0
- package/dist/runtime/constants/default-canvas3-options.d.ts +40 -0
- package/dist/runtime/constants/default-canvas3-options.js +40 -0
- package/dist/runtime/constants/shaders/TextBlurFragment.glsl +126 -0
- package/dist/runtime/constants/shaders/TextBlurVertex.glsl +10 -0
- package/dist/runtime/constants/shaders/projectBlurFragment.glsl +143 -0
- package/dist/runtime/constants/shaders/projectBlurVertex.glsl +11 -0
- package/dist/runtime/constants/shaders/scrollFragment.glsl +7 -0
- package/dist/runtime/constants/shaders/scrollVertex.glsl +8 -0
- package/dist/runtime/directives/action-on-scroll.d.ts +2 -0
- package/dist/runtime/directives/action-on-scroll.js +42 -0
- package/dist/runtime/directives/canvas3-image-directive.client.d.ts +6 -0
- package/dist/runtime/directives/canvas3-image-directive.client.js +104 -0
- package/dist/runtime/directives/set-data-attributes.d.ts +3 -0
- package/dist/runtime/directives/set-data-attributes.js +34 -0
- package/dist/runtime/layouts/canvas3-layout.vue +44 -0
- package/dist/runtime/layouts/canvas3-layout.vue.d.ts +11 -0
- package/dist/runtime/plugin.d.ts +2 -0
- package/dist/runtime/plugin.js +3 -0
- package/dist/runtime/plugins/directives.d.ts +2 -0
- package/dist/runtime/plugins/directives.js +9 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/types/shaders.d.ts +4 -0
- package/dist/runtime/types/three-msdf-text-utils.d.ts +36 -0
- package/dist/runtime/types/types.d.ts +71 -0
- package/dist/runtime/types/types.js +0 -0
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/TextLayout.d.ts +1 -0
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/TextLayout.js +0 -0
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/createIndices.d.ts +1 -0
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/createIndices.js +0 -0
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/index.d.ts +1 -0
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/index.js +0 -0
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/utils.d.ts +1 -0
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/utils.js +0 -0
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/vertices.d.ts +1 -0
- package/dist/runtime/utils/MSDFFont/MSDFTextGeometry/vertices.js +0 -0
- package/dist/runtime/utils/canvas3/canvas3.d.ts +65 -0
- package/dist/runtime/utils/canvas3/canvas3.js +512 -0
- package/dist/runtime/utils/canvas3/helpers.d.ts +12 -0
- package/dist/runtime/utils/canvas3/helpers.js +96 -0
- package/dist/runtime/utils/canvas3/scroll.d.ts +37 -0
- package/dist/runtime/utils/canvas3/scroll.js +191 -0
- package/dist/runtime/utils/exports.d.ts +10 -0
- package/dist/runtime/utils/exports.js +14 -0
- package/dist/types.d.mts +7 -0
- package/package.json +64 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import {
|
|
2
|
+
elementNearViewport,
|
|
3
|
+
lerp,
|
|
4
|
+
setScrollActiveElements
|
|
5
|
+
} from "./helpers.js";
|
|
6
|
+
export default class Scroll {
|
|
7
|
+
activateMeshCallback;
|
|
8
|
+
fixScrollTo;
|
|
9
|
+
// null | {ref: htmlRef, margin: Number}
|
|
10
|
+
scrollToRender;
|
|
11
|
+
scrollRendered;
|
|
12
|
+
current;
|
|
13
|
+
scrollInProgress;
|
|
14
|
+
ease;
|
|
15
|
+
speed;
|
|
16
|
+
speedTarget;
|
|
17
|
+
scrollSpeedBottomMargin;
|
|
18
|
+
DOM;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.DOM = {
|
|
21
|
+
scrollable: options.dom,
|
|
22
|
+
onScrollActivateElements: []
|
|
23
|
+
};
|
|
24
|
+
this.activateMeshCallback = options.activateMeshCallback;
|
|
25
|
+
this.fixScrollTo = { htmlRef: null, margin: 0 };
|
|
26
|
+
this.scrollToRender = 0;
|
|
27
|
+
this.scrollRendered = 0;
|
|
28
|
+
this.current = 0;
|
|
29
|
+
this.scrollInProgress = false;
|
|
30
|
+
this.ease = 0.1;
|
|
31
|
+
this.speed = 0;
|
|
32
|
+
this.speedTarget = 0;
|
|
33
|
+
this.scrollSpeedBottomMargin = 250;
|
|
34
|
+
this.setSize();
|
|
35
|
+
this.getScroll();
|
|
36
|
+
this.init();
|
|
37
|
+
this.initEvents();
|
|
38
|
+
}
|
|
39
|
+
init() {
|
|
40
|
+
this.getScroll();
|
|
41
|
+
this.scrollToRender = this.current;
|
|
42
|
+
this.move();
|
|
43
|
+
}
|
|
44
|
+
getScroll() {
|
|
45
|
+
this.current = window.scrollY || document.documentElement.scrollTop;
|
|
46
|
+
}
|
|
47
|
+
resizeMobileBreakEvents() {
|
|
48
|
+
if (window.innerWidth < 768) {
|
|
49
|
+
for (const item of this.DOM.onScrollActivateElements) {
|
|
50
|
+
if (item.options.fixToParent && item.containerEl) {
|
|
51
|
+
item.bounds = item.elNode.getBoundingClientRect();
|
|
52
|
+
item.containerBottom = item.containerEl.getBoundingClientRect().bottom;
|
|
53
|
+
} else {
|
|
54
|
+
item.elNode.style.transform = `translate3d(0,0px,0)`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
initEvents() {
|
|
60
|
+
window.addEventListener("scroll", () => {
|
|
61
|
+
this.getScroll();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
setSize() {
|
|
65
|
+
document.body.style.height = this.DOM.scrollable.scrollHeight > window.innerHeight ? `${this.DOM.scrollable.scrollHeight}px` : `${window.innerHeight}px`;
|
|
66
|
+
}
|
|
67
|
+
setElementActive(item, isActive) {
|
|
68
|
+
if (!item.containedMeshIds) return;
|
|
69
|
+
if (isActive) {
|
|
70
|
+
item.elNode.dataset.activeScroll = "true";
|
|
71
|
+
setScrollActiveElements(item.elNode, item.containedMeshIds, "true");
|
|
72
|
+
item.elNode.classList.add("active");
|
|
73
|
+
if (item.options.activateCallback) {
|
|
74
|
+
item.options.activateCallback(item);
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
item.elNode.dataset.activeScroll = "false";
|
|
78
|
+
setScrollActiveElements(item.elNode, item.containedMeshIds, "false");
|
|
79
|
+
if (!item.trackOnly) item.elNode.classList.remove("active");
|
|
80
|
+
}
|
|
81
|
+
if (item.containedMeshIds.length > 0 && !item.trackOnly) {
|
|
82
|
+
for (const meshId of item.containedMeshIds) {
|
|
83
|
+
this.activateMeshCallback(meshId, isActive);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
setElementsScrollPositions() {
|
|
88
|
+
if (this.DOM.onScrollActivateElements.length === 0) return;
|
|
89
|
+
for (const item of this.DOM.onScrollActivateElements) {
|
|
90
|
+
const bounds = item.elNode.getBoundingClientRect();
|
|
91
|
+
const itemRangeMargin = item.options.activeRangeMargin ?? 0;
|
|
92
|
+
const elementTrack = elementNearViewport(bounds, 200 + itemRangeMargin);
|
|
93
|
+
if (elementTrack) {
|
|
94
|
+
const activeRange = item.options.activeRange ?? 1;
|
|
95
|
+
const activeRangeOrigin = item.options.activeRangeOrigin ?? 1;
|
|
96
|
+
const activeRangeOriginPx = activeRangeOrigin * window.innerHeight;
|
|
97
|
+
const activeRangeInPx = (1 - activeRange) * activeRangeOriginPx;
|
|
98
|
+
const itemRangeMargin2 = item.options.activeRangeMargin ?? 0;
|
|
99
|
+
const activeFromTop = bounds.top - itemRangeMargin2 <= activeRangeOriginPx - activeRangeInPx;
|
|
100
|
+
const activeFromBottom = !item.options.bidirectionalActivation || bounds.bottom - itemRangeMargin2 >= activeRangeInPx + activeRangeOriginPx;
|
|
101
|
+
if (activeFromTop && activeFromBottom) {
|
|
102
|
+
if (item.options.onScrollCallback && this.scrollInProgress)
|
|
103
|
+
item.options.onScrollCallback(item, this.speed, this.current);
|
|
104
|
+
if (item.elNode.dataset.activeScroll !== "true") {
|
|
105
|
+
this.setElementActive(item, true);
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
if (item.elNode.dataset.activeScroll === "true" && !item.options.activateOnce) {
|
|
109
|
+
this.setElementActive(item, false);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (typeof item.options.scrollSpeed?.value === "number") {
|
|
114
|
+
item.elNode.style.transition = `linear translate3d 0s`;
|
|
115
|
+
if (item.options.fixToParent && item.containerEl && item.childElBounds) {
|
|
116
|
+
const containerBounds = item.containerEl.getBoundingClientRect();
|
|
117
|
+
const fixToOrigin = item.options.fixToParent.fixPosition ?? 0;
|
|
118
|
+
const itemMargin = item.options.fixToParent.margin ?? 0;
|
|
119
|
+
const fixToOriginPx = window.innerHeight * fixToOrigin;
|
|
120
|
+
if (item.childEl && bounds.top < itemMargin + fixToOriginPx && containerBounds.bottom > itemMargin + fixToOriginPx + item.childElBounds.height) {
|
|
121
|
+
const fixedPositionPx = itemMargin - bounds.top + fixToOriginPx;
|
|
122
|
+
item.childEl.style.transform = `translate3d(0,${fixedPositionPx}px,0)`;
|
|
123
|
+
} else if (item.childEl && bounds.top > itemMargin + fixToOriginPx && item.childEl.style.transform !== `translate3d(0px, 0px, 0px)`) {
|
|
124
|
+
item.childEl.style.transform = `translate3d(0px, 0px, 0px)`;
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
const speedTrack = elementNearViewport(
|
|
128
|
+
bounds,
|
|
129
|
+
window.innerHeight * 0.75 + itemRangeMargin
|
|
130
|
+
// 0.75 = maximum amount of project VH bottom
|
|
131
|
+
);
|
|
132
|
+
if (speedTrack) {
|
|
133
|
+
const speed = (window.innerHeight - bounds.top) * item.options.scrollSpeed.value;
|
|
134
|
+
item.elNode.style.transform = `translate3d(0,${speed}px,0)`;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
item.elNode.style.transition = `linear translate3d 0.3s`;
|
|
139
|
+
item.elNode.style.transform = `translate3d(0,0,0)`;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
setScrollPosition() {
|
|
144
|
+
if (Math.round(this.scrollToRender) !== Math.round(this.current) || this.scrollToRender < 10) {
|
|
145
|
+
this.DOM.scrollable.style.transform = `translate3d(0,${-1 * this.scrollToRender}px,0)`;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
scrollRenderToFluid(scrollTo) {
|
|
149
|
+
window.scrollBy(0, scrollTo);
|
|
150
|
+
document.documentElement.scrollTop = scrollTo;
|
|
151
|
+
}
|
|
152
|
+
scrollRenderTo(scrollTo) {
|
|
153
|
+
this.scrollToRender = scrollTo;
|
|
154
|
+
window.scrollTo({
|
|
155
|
+
left: 0,
|
|
156
|
+
top: scrollTo,
|
|
157
|
+
behavior: "instant"
|
|
158
|
+
});
|
|
159
|
+
document.documentElement.scrollTop = scrollTo;
|
|
160
|
+
}
|
|
161
|
+
calculateScrollSpeed() {
|
|
162
|
+
this.speed = Math.min(Math.abs(this.current - this.scrollToRender), 200) / 200;
|
|
163
|
+
this.speedTarget += (this.speed - this.speedTarget) * 0.2;
|
|
164
|
+
}
|
|
165
|
+
move() {
|
|
166
|
+
this.setScrollPosition();
|
|
167
|
+
this.setElementsScrollPositions();
|
|
168
|
+
}
|
|
169
|
+
render(scrollTo, fluid) {
|
|
170
|
+
this.setSize();
|
|
171
|
+
if (this.fixScrollTo.htmlRef) {
|
|
172
|
+
const refPosition = this.fixScrollTo.htmlRef.getBoundingClientRect().top;
|
|
173
|
+
const fixScrollToPosition = Math.round(
|
|
174
|
+
this.scrollToRender + refPosition - this.fixScrollTo.margin
|
|
175
|
+
);
|
|
176
|
+
this.scrollRenderTo(fixScrollToPosition);
|
|
177
|
+
} else if (scrollTo !== null && fluid) {
|
|
178
|
+
this.scrollRenderToFluid(scrollTo);
|
|
179
|
+
} else if (scrollTo !== null && !fluid) {
|
|
180
|
+
this.scrollRenderTo(scrollTo);
|
|
181
|
+
} else {
|
|
182
|
+
this.scrollToRender = Math.round(
|
|
183
|
+
lerp(this.scrollToRender, this.current, this.ease)
|
|
184
|
+
);
|
|
185
|
+
this.scrollInProgress = this.scrollToRender !== this.scrollRendered;
|
|
186
|
+
this.scrollRendered = this.scrollToRender;
|
|
187
|
+
}
|
|
188
|
+
this.calculateScrollSpeed();
|
|
189
|
+
this.move();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Mesh } from 'three';
|
|
2
|
+
export declare const Canvas3: {
|
|
3
|
+
addAnimationToRender: (callBackName: string, callBackFunction: import("../types/types.js").AnimationCallback) => void;
|
|
4
|
+
resizeOnChange: () => void;
|
|
5
|
+
scrollToElBySelector: (elQuerySelector: string, delay?: number) => void;
|
|
6
|
+
setMeshPositionsUpdate: (state: boolean) => void;
|
|
7
|
+
scrollToTop: (delay?: number) => void;
|
|
8
|
+
addMeshToScene: (mesh: Mesh) => void;
|
|
9
|
+
getMeshFromSceneByName: (meshName: string) => import("three").Object3D<import("three").Object3DEventMap> | undefined;
|
|
10
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Canvas3 as mainClass } from "#canvas3-nuxt/utils/canvas3/canvas3";
|
|
2
|
+
export const Canvas3 = {
|
|
3
|
+
addAnimationToRender: mainClass.addAnimationToRender.bind(mainClass),
|
|
4
|
+
resizeOnChange: mainClass.resizeOnChange.bind(mainClass),
|
|
5
|
+
scrollToElBySelector: mainClass.scrollToElBySelector.bind(mainClass),
|
|
6
|
+
setMeshPositionsUpdate: mainClass.setMeshPositionsUpdate.bind(mainClass),
|
|
7
|
+
scrollToTop: mainClass.scrollToTop.bind(mainClass),
|
|
8
|
+
addMeshToScene: (mesh) => {
|
|
9
|
+
mainClass.scene.add(mesh);
|
|
10
|
+
},
|
|
11
|
+
getMeshFromSceneByName: (meshName) => {
|
|
12
|
+
return mainClass.scene.getObjectByName(meshName);
|
|
13
|
+
}
|
|
14
|
+
};
|
package/dist/types.d.mts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@canvas3/nuxt",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "Module for ThreeJS",
|
|
8
|
+
"repository": "https://github.com/kmettom/Canvas3Nuxt",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/types.d.mts",
|
|
14
|
+
"import": "./dist/module.mjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"main": "./dist/module.mjs",
|
|
18
|
+
"typesVersions": {
|
|
19
|
+
"*": {
|
|
20
|
+
".": [
|
|
21
|
+
"./dist/types.d.mts"
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"runtime"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"prepack": "nuxt-module-build build",
|
|
31
|
+
"dev": "npm run dev:prepare && nuxi dev playground",
|
|
32
|
+
"dev:build": "nuxi build playground",
|
|
33
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
34
|
+
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
|
|
35
|
+
"release-public": "npm run prepack && changelogen --release && npm publish --access public && git push --follow-tags",
|
|
36
|
+
"lint": "eslint .",
|
|
37
|
+
"lint-fix": "eslint --fix ; exit 0",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"test:watch": "vitest watch",
|
|
40
|
+
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@nuxt/kit": "^4.0.0",
|
|
44
|
+
"gsap": "^3.13.0",
|
|
45
|
+
"three": "^0.178.0",
|
|
46
|
+
"vite-plugin-glsl": "^1.5.1",
|
|
47
|
+
"vue": "^3.5.18"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@nuxt/devtools": "^2.6.2",
|
|
51
|
+
"@nuxt/eslint-config": "^1.2.0",
|
|
52
|
+
"@nuxt/module-builder": "^1.0.1",
|
|
53
|
+
"@nuxt/schema": "^4.0.0",
|
|
54
|
+
"@nuxt/test-utils": "^3.19.2",
|
|
55
|
+
"@types/node": "latest",
|
|
56
|
+
"@types/three": "^0.178.1",
|
|
57
|
+
"changelogen": "^0.6.2",
|
|
58
|
+
"eslint": "^9.30.1",
|
|
59
|
+
"nuxt": "^4.0.0",
|
|
60
|
+
"typescript": "~5.8.3",
|
|
61
|
+
"vitest": "^3.2.4",
|
|
62
|
+
"vue-tsc": "^3.0.1"
|
|
63
|
+
}
|
|
64
|
+
}
|