Skip to content

Commit

Permalink
feat: separate draws for pages
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 13, 2021
1 parent 4867749 commit fdbb9ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/client/internals/DrauuLayer.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
<script setup lang="ts">
import { onMounted, ref, watch, inject, onBeforeUnmount } from 'vue'
import { drauuEnabled, drauu } from '../logic/drauu'
import { drauuEnabled, drauu, drauuData } from '../logic/drauu'
import { injectionSlideScale } from '../constants'
import { currentPage } from '../logic/nav'
const scale = inject(injectionSlideScale)!
const svg = ref<SVGSVGElement>()
onMounted(() => {
drauu.mount(svg.value!)
watch(scale, scale => drauu.options.corrdinateScale = 1 / scale, { immediate: true })
drauu.on('changed', () => {
drauuData.set(currentPage.value, drauu.dump())
})
watch(currentPage, (page) => {
const data = drauuData.get(page)
if (data)
drauu.load(data)
else
drauu.clear()
})
})
onBeforeUnmount(() => {
Expand Down
2 changes: 2 additions & 0 deletions packages/client/logic/drauu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const drauuEnabled = ref(false)
export const canUndo = ref(false)
export const canRedo = ref(false)

export const drauuData = new Map<number, string>()

export const drauu = markRaw(createDrauu({
brush: drauuBrush,
mode: drauuMode.value,
Expand Down

0 comments on commit fdbb9ed

Please sign in to comment.