Skip to content

Commit

Permalink
feat: support drawing with pen regradeless enabling
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 13, 2021
1 parent 3b4cc14 commit 2a9b5fb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
7 changes: 3 additions & 4 deletions packages/client/internals/DrawingLayer.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script setup lang="ts">
import { onMounted, ref, watch, inject, onBeforeUnmount } from 'vue'
import { drawingEnabled, drauu, loadCanvas } from '../logic/drawings'
import { drauu, loadCanvas } from '../logic/drawings'
import { injectionSlideScale } from '../constants'
const scale = inject(injectionSlideScale)!
const svg = ref<SVGSVGElement>()
onMounted(() => {
drauu.mount(svg.value!)
drauu.mount(svg.value!, svg.value!.parentElement!)
watch(scale, scale => drauu.options.coordinateScale = 1 / scale, { immediate: true })
loadCanvas()
})
Expand All @@ -20,7 +20,6 @@ onBeforeUnmount(() => {
<template>
<svg
ref="svg"
class="w-full h-full absolute top-0"
:class="{ 'pointer-events-none': !drawingEnabled }"
class="w-full h-full absolute top-0 pointer-events-none"
></svg>
</template>
8 changes: 5 additions & 3 deletions packages/client/logic/drawings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { computed, markRaw, nextTick, reactive, ref, watch } from 'vue'
import { Brush, createDrauu, DrawingMode } from 'drauu'
import { Brush, createDrauu, DrawingMode, Options as DrauuOptions } from 'drauu'
import { serverDrawingState as drawingState } from '../env'
import { currentPage } from './nav'

Expand Down Expand Up @@ -45,9 +45,11 @@ export const canRedo = ref(false)
export const canClear = ref(false)
export const isDrawing = ref(false)

export const drauu = markRaw(createDrauu(reactive({
export const drauuOptions: DrauuOptions = reactive({
brush,
})))
acceptsInputTypes: computed(() => drawingEnabled.value ? undefined : ['pen' as const]),
})
export const drauu = markRaw(createDrauu(drauuOptions))

export function clearDrauu() {
drauu.clear()
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@vueuse/head": "^0.6.0",
"@vueuse/motion": "^1.6.0",
"codemirror": "^5.62.3",
"drauu": "^0.1.0-beta.5",
"drauu": "^0.1.0-beta.6",
"file-saver": "^2.0.5",
"js-base64": "^3.6.1",
"js-yaml": "^4.1.0",
Expand Down
14 changes: 7 additions & 7 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 2a9b5fb

Please sign in to comment.