-
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
1 parent
36c7b68
commit 8eb2a0a
Showing
6 changed files
with
43 additions
and
59 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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { umbra } from '@umbrajs/core' | ||
import { ref, Ref, onMounted } from 'vue' | ||
import { colorName } from './colorName' | ||
import DyeWrapper from '../components/DyeWrapper.vue' | ||
|
||
export function useDye(hex: string) { | ||
const wrapper = ref<InstanceType<typeof DyeWrapper> | null>(null) | ||
const color = ref({ name: colorName(hex).name, hex }) | ||
|
||
function paintComponent(background: string) { | ||
if (!wrapper.value) return | ||
umbra({ background }).apply({ target: wrapper.value.$el }) | ||
} | ||
|
||
onMounted(() => paintComponent(color.value.hex)) | ||
|
||
const [colorCanvas, setColorCanvas] = useColorCanvas() | ||
return { | ||
color, | ||
colorCanvas, | ||
setColorCanvas, | ||
paintComponent, | ||
wrapper | ||
} | ||
} | ||
|
||
type UCCP = [() => Ref<HTMLCanvasElement | null>, (el: HTMLCanvasElement) => void] | ||
export function useColorCanvas(): UCCP { | ||
const colorCanvas = ref<HTMLCanvasElement | null>(null) | ||
return [() => colorCanvas, (el: HTMLCanvasElement) => (colorCanvas.value = el)] | ||
} |
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