Skip to content

Commit

Permalink
fix: vue composable type
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernankez committed Apr 2, 2024
1 parent 9e067cf commit 29b4b59
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
7 changes: 5 additions & 2 deletions packages/vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { type ComputedRef, type MaybeRefOrGetter, computed, onMounted, ref, toVa

export type BackmojiResult = ReturnType<typeof backmoji>;

export function useBackmoji(renderer: MaybeRefOrGetter<Renderer>, canvas: MaybeRefOrGetter<HTMLCanvasElement | undefined>, options?: MaybeRefOrGetter<Omit<BackmojiOptions, "canvas"> | undefined>) {
export function useBackmoji(renderer: MaybeRefOrGetter<Renderer | undefined>, canvas: MaybeRefOrGetter<HTMLCanvasElement | undefined>, options?: MaybeRefOrGetter<Omit<BackmojiOptions, "canvas"> | undefined>) {
return computed(() => {
const _renderer = toValue(renderer);
const _options = toValue(options);
const _canvas = toValue(canvas);
if (!_canvas) {
if (!_canvas || !_renderer) {
return undefined;
}
return backmoji(_renderer, {
Expand Down Expand Up @@ -48,6 +48,9 @@ export function useImageRenderer(image: MaybeRefOrGetter<HTMLImageElement | unde
return computed(() => {
const _image = toValue(image);
const _options = toValue(options);
if (!_image) {
return undefined;
}
return createImageRenderer(_image, _options);
});
}
1 change: 1 addition & 0 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@backmoji/vue": "workspace:*",
"@types/react": "^18.2.73",
"@types/react-dom": "^18.2.23",
"@vueuse/core": "^10.9.0",
"ahooks": "^3.7.10",
"astro": "^4.5.12",
"react": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion playground/src/demos/WithReact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function WithReact() {
}, [canvas]);

return (
<div ref={divRef}>
<div ref={divRef} className="rounded-md bg-orange-50">
<canvas ref={canvasRef}></canvas>
</div>
);
Expand Down
9 changes: 8 additions & 1 deletion playground/src/demos/WithVue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import { ref, watchEffect } from "vue";
import { useBackmoji, useImageLoader, useImageRenderer, useTextRenderer } from "@backmoji/vue";
import VueLogo from "/vue.svg?url";
import { useElementSize } from "@vueuse/core";
const divRef = ref<HTMLDivElement>();
const { width, height } = useElementSize(divRef);
const canvasRef = ref<HTMLCanvasElement>();
const image = useImageLoader(VueLogo);
Expand All @@ -12,11 +16,14 @@ const backmojiResult = useBackmoji(renderer, canvasRef, {
});
watchEffect(() => {
if (backmojiResult.value) {
backmojiResult.value.setSize(width.value, height.value);
backmojiResult.value.render();
}
});
</script>

<template>
<canvas ref="canvasRef"></canvas>
<div ref="divRef" class="rounded-md bg-orange-50">
<canvas ref="canvasRef"></canvas>
</div>
</template>
35 changes: 33 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 29b4b59

Please sign in to comment.