@canvas3/nuxt 0.1.10 → 0.1.12
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 +1 -1
- package/dist/runtime/components/canvas3-image.vue +19 -12
- package/dist/runtime/constants/studio783Log.js +1 -1
- package/dist/runtime/directives/canvas3-image.client.js +35 -25
- package/dist/runtime/utils/canvas3/canvas3.d.ts +1 -0
- package/dist/runtime/utils/canvas3/canvas3.js +28 -10
- package/dist/runtime/utils/exports.d.ts +2 -1
- package/dist/runtime/utils/exports.js +2 -1
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -29,19 +29,26 @@ const reducedMotion = computed(() => Canvas3.options?.disabled ?? null);
|
|
|
29
29
|
const image = ref();
|
|
30
30
|
const generatedMeshId = "image_" + crypto.randomUUID();
|
|
31
31
|
const imgAddedToCanvas = ref(false);
|
|
32
|
+
const imgIsAdding = ref(false);
|
|
32
33
|
const addImageToCanvas = async () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
image.value
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
if (imgAddedToCanvas.value || imgIsAdding.value) return;
|
|
35
|
+
imgIsAdding.value = true;
|
|
36
|
+
try {
|
|
37
|
+
await nextTick();
|
|
38
|
+
if (!image.value || Canvas3.canvasInitiated.value === false || Canvas3.options?.disabled || imgAddedToCanvas.value) return;
|
|
39
|
+
if (image.value.naturalWidth === 0) return;
|
|
40
|
+
image.value.dataset.meshId = generatedMeshId;
|
|
41
|
+
await Canvas3.addImageAsMesh(
|
|
42
|
+
image.value,
|
|
43
|
+
props.options.shaderName ?? null,
|
|
44
|
+
generatedMeshId,
|
|
45
|
+
props.options.uniforms ?? {},
|
|
46
|
+
props.options.activateMeshUniforms ?? {}
|
|
47
|
+
);
|
|
48
|
+
imgAddedToCanvas.value = true;
|
|
49
|
+
} finally {
|
|
50
|
+
imgIsAdding.value = false;
|
|
51
|
+
}
|
|
45
52
|
};
|
|
46
53
|
watch(() => Canvas3.canvasInitiated.value, (ready) => {
|
|
47
54
|
if (ready) addImageToCanvas();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const studio783log = () => {
|
|
2
2
|
console.log(`
|
|
3
|
-
|
|
3
|
+
Nuxt module Canvas3 developed by
|
|
4
4
|
|
|
5
5
|
\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2588 \u2588 \u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2588\u2588\u2588\u2588
|
|
6
6
|
\u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588
|
|
@@ -2,38 +2,48 @@ import { watch, nextTick } from "vue";
|
|
|
2
2
|
import { Canvas3 } from "#canvas3-nuxt/utils/canvas3/canvas3";
|
|
3
3
|
const meshIdMap = /* @__PURE__ */ new WeakMap();
|
|
4
4
|
const addedMap = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
const loadingSet = /* @__PURE__ */ new WeakSet();
|
|
5
6
|
const stopMap = /* @__PURE__ */ new WeakMap();
|
|
6
7
|
const srcMap = /* @__PURE__ */ new WeakMap();
|
|
7
8
|
function getImgSrc(el) {
|
|
8
9
|
return el.currentSrc || el.src || "";
|
|
9
10
|
}
|
|
10
11
|
async function tryAdd(el, options) {
|
|
11
|
-
if (addedMap.get(el)) return;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
el.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
meshId =
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
if (addedMap.get(el) || loadingSet.has(el)) return;
|
|
13
|
+
loadingSet.add(el);
|
|
14
|
+
try {
|
|
15
|
+
await nextTick();
|
|
16
|
+
if (!el.isConnected) return;
|
|
17
|
+
if (Canvas3.options?.disabled) {
|
|
18
|
+
el.classList.add("reduced-motion");
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (Canvas3.canvasInitiated.value === false) return;
|
|
22
|
+
if (!el.complete || el.naturalWidth === 0) return;
|
|
23
|
+
let meshId = meshIdMap.get(el);
|
|
24
|
+
if (!meshId) {
|
|
25
|
+
meshId = "image_" + crypto.randomUUID();
|
|
26
|
+
meshIdMap.set(el, meshId);
|
|
27
|
+
el.dataset.meshId = meshId;
|
|
28
|
+
}
|
|
29
|
+
await Canvas3.addImageAsMesh(
|
|
30
|
+
el,
|
|
31
|
+
options.shaderName ?? null,
|
|
32
|
+
meshId,
|
|
33
|
+
options?.uniforms ?? {},
|
|
34
|
+
options?.activateMeshUniforms ?? {}
|
|
35
|
+
);
|
|
36
|
+
if (!el.isConnected) {
|
|
37
|
+
Canvas3.removeMesh(meshId);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
addedMap.set(el, true);
|
|
41
|
+
srcMap.set(el, getImgSrc(el));
|
|
42
|
+
el.classList.add("webgl-img");
|
|
43
|
+
el.style.opacity = "0";
|
|
44
|
+
} finally {
|
|
45
|
+
loadingSet.delete(el);
|
|
25
46
|
}
|
|
26
|
-
await Canvas3.addImageAsMesh(
|
|
27
|
-
el,
|
|
28
|
-
options.shaderName ?? null,
|
|
29
|
-
meshId,
|
|
30
|
-
options?.uniforms ?? {},
|
|
31
|
-
options?.activateMeshUniforms ?? {}
|
|
32
|
-
);
|
|
33
|
-
addedMap.set(el, true);
|
|
34
|
-
srcMap.set(el, getImgSrc(el));
|
|
35
|
-
el.classList.add("webgl-img");
|
|
36
|
-
el.style.opacity = "0";
|
|
37
47
|
}
|
|
38
48
|
function remove(el) {
|
|
39
49
|
const meshId = meshIdMap.get(el);
|
|
@@ -47,6 +47,7 @@ declare class Canvas3Class {
|
|
|
47
47
|
removeScrollActiveElement(elNode: HTMLElement): void;
|
|
48
48
|
removeMesh(id: string): void;
|
|
49
49
|
addAnimationToRender(callBackName: string, callBackFunction: AnimationCallback): void;
|
|
50
|
+
removeAnimationFromRender(callBackName: string): void;
|
|
50
51
|
addImageAsMesh(imgHtmlEl: HTMLImageElement, shaderName: string | null, meshId: string, meshUniforms: MeshMaterialUniform, activateMeshUniforms: MeshMaterialUniform): Promise<void>;
|
|
51
52
|
composerPass(): void;
|
|
52
53
|
setSize(): void;
|
|
@@ -223,23 +223,41 @@ class Canvas3Class {
|
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
removeMesh(id) {
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
226
|
+
const meshesToRemove = /* @__PURE__ */ new Set();
|
|
227
|
+
let meshInScene = this.scene.getObjectByName(id);
|
|
228
|
+
while (meshInScene) {
|
|
229
|
+
meshesToRemove.add(meshInScene);
|
|
230
|
+
this.scene.remove(meshInScene);
|
|
231
|
+
meshInScene = this.scene.getObjectByName(id);
|
|
232
|
+
}
|
|
233
|
+
for (const item of this.imageStore) {
|
|
233
234
|
if (item.name === id) {
|
|
234
|
-
|
|
235
|
-
this.materials.splice(index, 1);
|
|
236
|
-
break;
|
|
235
|
+
meshesToRemove.add(item.mesh);
|
|
237
236
|
}
|
|
238
237
|
}
|
|
238
|
+
for (const mesh of meshesToRemove) {
|
|
239
|
+
mesh.geometry?.dispose();
|
|
240
|
+
const material = getShaderMaterial(mesh);
|
|
241
|
+
if (material) {
|
|
242
|
+
const materialIndex = this.materials.indexOf(material);
|
|
243
|
+
if (materialIndex !== -1)
|
|
244
|
+
this.materials.splice(materialIndex, 1);
|
|
245
|
+
if (material.uniforms?.uImage?.value) {
|
|
246
|
+
material.uniforms.uImage.value.dispose();
|
|
247
|
+
}
|
|
248
|
+
material.dispose();
|
|
249
|
+
}
|
|
250
|
+
this.scene.remove(mesh);
|
|
251
|
+
}
|
|
252
|
+
this.activateMeshUniformMap.delete(id);
|
|
253
|
+
this.imageStore = this.imageStore.filter((item) => item.name !== id);
|
|
239
254
|
}
|
|
240
255
|
addAnimationToRender(callBackName, callBackFunction) {
|
|
241
256
|
this.animations.set(callBackName, callBackFunction);
|
|
242
257
|
}
|
|
258
|
+
removeAnimationFromRender(callBackName) {
|
|
259
|
+
this.animations.delete(callBackName);
|
|
260
|
+
}
|
|
243
261
|
// addTextAsMSDF(shaderName: string, meshId: string, htmlEl: HTMLElement, textContent: string, theme: string, meshUniforms: MeshMaterialUniform, activateMeshUniforms: MeshMaterialUniform) {
|
|
244
262
|
// this.activateMeshUniformMap.set(meshId, activateMeshUniforms)
|
|
245
263
|
//
|
|
@@ -4,9 +4,10 @@ export declare const Canvas3: {
|
|
|
4
4
|
addMeshToScene: (mesh: Mesh) => void;
|
|
5
5
|
getMeshFromSceneByName: (meshName: string) => import("three").Object3D<import("three").Object3DEventMap> | undefined;
|
|
6
6
|
addAnimationToRender: (callBackName: string, callBackFunction: import("../types/types.js").AnimationCallback) => void;
|
|
7
|
+
removeAnimationFromRender: (callBackName: string) => void;
|
|
7
8
|
addImageAsMesh: (imgHtmlEl: HTMLImageElement, shaderName: string | null, meshId: string, meshUniforms: import("../types/types.js").MeshMaterialUniform, activateMeshUniforms: import("../types/types.js").MeshMaterialUniform) => Promise<void>;
|
|
8
9
|
getShaderMaterial: typeof getShaderMaterial;
|
|
9
|
-
removeMesh: (
|
|
10
|
+
removeMesh: (id: string) => void;
|
|
10
11
|
resizeOnChange: () => void;
|
|
11
12
|
scrollToElBySelector: (elQuerySelector: string, delay?: number) => void;
|
|
12
13
|
setMeshPositionsUpdate: (state: boolean) => void;
|
|
@@ -8,9 +8,10 @@ export const Canvas3 = {
|
|
|
8
8
|
return mainClass.scene.getObjectByName(meshName);
|
|
9
9
|
},
|
|
10
10
|
addAnimationToRender: mainClass.addAnimationToRender.bind(mainClass),
|
|
11
|
+
removeAnimationFromRender: mainClass.removeAnimationFromRender.bind(mainClass),
|
|
11
12
|
addImageAsMesh: mainClass.addImageAsMesh.bind(mainClass),
|
|
12
13
|
getShaderMaterial,
|
|
13
|
-
removeMesh: mainClass.
|
|
14
|
+
removeMesh: mainClass.removeMesh.bind(mainClass),
|
|
14
15
|
resizeOnChange: mainClass.resizeOnChange.bind(mainClass),
|
|
15
16
|
scrollToElBySelector: mainClass.scrollToElBySelector.bind(mainClass),
|
|
16
17
|
setMeshPositionsUpdate: mainClass.setMeshPositionsUpdate.bind(mainClass),
|