-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
161 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,27 @@ | ||
export const a = 1; | ||
import { type BackmojiOptions, type CreateTextRendererOptions, type Renderer, backmoji, createTextRenderer } from "backmoji"; | ||
import { type ComputedRef, type MaybeRefOrGetter, computed, toValue } from "vue"; | ||
|
||
export type BackmojiResult = ReturnType<typeof backmoji>; | ||
|
||
export function useBackmoji(renderer: MaybeRefOrGetter<Renderer>, 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) { | ||
return undefined; | ||
} | ||
return backmoji(_renderer, { | ||
..._options, | ||
canvas: _canvas, | ||
}); | ||
}); | ||
} | ||
|
||
export function useTextRenderer(text: MaybeRefOrGetter<string>, options?: MaybeRefOrGetter<CreateTextRendererOptions | undefined>) { | ||
return computed(() => { | ||
const _text = toValue(text); | ||
const _options = toValue(options); | ||
return createTextRenderer(_text, _options); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script setup lang="ts"> | ||
import { ref, watchEffect } from "vue"; | ||
import { useBackmoji, useTextRenderer } from "@backmoji/vue"; | ||
import VueLogo from "/vue.svg?url"; | ||
const canvasRef = ref<HTMLCanvasElement>(); | ||
const renderer = useTextRenderer("vue"); | ||
const backmojiResult = useBackmoji(renderer, canvasRef, { | ||
rowGap: 30, | ||
columnGap: 30, | ||
}); | ||
watchEffect(() => { | ||
if (backmojiResult.value) { | ||
backmojiResult.value.render(); | ||
} | ||
}); | ||
</script> | ||
|
||
<template> | ||
<canvas ref="canvasRef"></canvas> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.