diff --git a/components/canvas/CanvasEdge.vue b/components/canvas/CanvasEdge.vue index 452e336..585ac7b 100644 --- a/components/canvas/CanvasEdge.vue +++ b/components/canvas/CanvasEdge.vue @@ -24,10 +24,10 @@ const rotation: Record = { \ No newline at end of file diff --git a/components/canvas/CanvasNode.vue b/components/canvas/CanvasNode.vue index b432730..6019a49 100644 --- a/components/canvas/CanvasNode.vue +++ b/components/canvas/CanvasNode.vue @@ -6,50 +6,46 @@ interface Props { zoom: number; } -function getColor(color: string): string -{ - if(props.node?.color?.startsWith('#')) - return hexToRgb(color); - else - return getComputedStyle(document.body, null).getPropertyValue('--canvas-color-' + props.node.color); -} -function hexToRgb(hex: string): string -{ - return `${parseInt(hex.substring(1, 3), 16)},${parseInt(hex.substring(3, 5), 16)},${parseInt(hex.substring(5, 7), 16)}`; -} -function darken(rgb: string): boolean -{ - const [r, g, b] = rgb.split(','); - return (299 * parseInt(r) + 587 * parseInt(g) + 114 * parseInt(b)) / 1e3 >= 150; -} - const props = defineProps(); const size = Math.max(props.node.width, props.node.height); +const colors = computed(() => { + if(props.node.color) + { + const color = props.node.color; + return color?.class ? { bg: `bg-light-${color?.class} dark:bg-dark-${color?.class}`, border: `border-light-${color?.class} dark:border-dark-${color?.class}`} : { bg: `bg-[rgba(var(--canvas-color), 0.3)]`, border: `border-[var(--canvas-color)]` }; + } + else + { + return { border: `border-light-40 dark:border-dark-40`, bg: `bg-light-40 dark:bg-dark-40` }; + } +}) \ No newline at end of file diff --git a/components/canvas/CanvasRenderer.vue b/components/canvas/CanvasRenderer.vue index a8fbf82..46ea2a2 100644 --- a/components/canvas/CanvasRenderer.vue +++ b/components/canvas/CanvasRenderer.vue @@ -7,55 +7,12 @@ interface Props } const props = defineProps(); -let dragging = false, posX = 0, posY = 0, dispX = ref(0), dispY = ref(0), minZoom = ref(0.3), zoom = ref(1); -let centerX = ref(0), centerY = ref(0), canvas = ref(); +let dragging = false, posX = 0, posY = 0, dispX = ref(0), dispY = ref(0), minZoom = ref(0.1), zoom = ref(1); let minX = ref(+Infinity), minY = ref(+Infinity), maxX = ref(-Infinity), maxY = ref(-Infinity); let bbox = ref(); let lastDistance = 0; -let _minX = +Infinity, _minY = +Infinity, _maxX = -Infinity, _maxY = -Infinity; - -onMounted(async () => { - await nextTick(); - - props.canvas.nodes.forEach((e) => { - _minX = Math.min(_minX, e.x); - _minY = Math.min(_minY, e.y); - _maxX = Math.max(_maxX, e.x + e.width); - _maxY = Math.max(_maxY, e.y + e.height); - }); - - await nextTick(); - - window.addEventListener('resize', onResize); - onResize(); - - dispX.value = -(_maxX + _minX) / 2; - dispY.value = -(_maxY + _minY) / 2; - - zoom.value = minZoom.value; -}); - -onUnmounted(() => { - window.removeEventListener('resize', onResize); -}) - -const onResize = (event?: Event) => { - minX.value = _minX = _minX - 32; - minY.value = _minY = _minY - 32; - maxX.value = _maxX = _maxX + 32; - maxY.value = _maxY = _maxY + 32; - - minZoom.value = Math.min((canvas.value?.clientWidth ?? 1920) / (_maxX - _minX), (canvas.value?.clientHeight ?? 1080) / (_maxY - _minY), 0.01) * 0.9; - zoom.value = clamp(zoom.value, minZoom.value, 3); - - bbox.value = (canvas.value ?? document.getElementById('canvas'))?.getBoundingClientRect(); - - centerX.value = (bbox.value?.width ?? 0) / 2; - centerY.value = (bbox.value?.height ?? 0) / 2; -} - const onPointerDown = (event: PointerEvent) => { if (event.isPrimary === false) return; dragging = true; @@ -84,6 +41,7 @@ const onPointerUp = (event: PointerEvent) => { } const onWheel = (event: WheelEvent) => { + zoom.value = clamp(zoom.value + (event.deltaY * -0.001), minZoom.value, 3); } @@ -118,8 +76,9 @@ const onTouchMove = (event: TouchEvent) => { const reset = (_: MouseEvent) => { zoom.value = minZoom.value; - dispX.value = -(maxX.value + minX.value) / 2; - dispY.value = -(maxY.value + minY.value) / 2; + + dispX.value = 0; + dispY.value = 0; } function clamp(x: number, min: number, max: number): number { if (x > max) @@ -210,12 +169,64 @@ function getCenter(n: { x: number, y: number }, i: { x: number, y: number }, r: y: s * n.y + l * r.y + c * o.y + u * i.y }; } +/* + +stroke-light-red +stroke-light-orange +stroke-light-yellow +stroke-light-green +stroke-light-cyan +stroke-light-purple +dark:stroke-dark-red +dark:stroke-dark-orange +dark:stroke-dark-yellow +dark:stroke-dark-green +dark:stroke-dark-cyan +dark:stroke-dark-purple +fill-light-red +fill-light-orange +fill-light-yellow +fill-light-green +fill-light-cyan +fill-light-purple +dark:fill-dark-red +dark:fill-dark-orange +dark:fill-dark-yellow +dark:fill-dark-green +dark:fill-dark-cyan +dark:fill-dark-purple +bg-light-red +bg-light-orange +bg-light-yellow +bg-light-green +bg-light-cyan +bg-light-purple +dark:bg-dark-red +dark:bg-dark-orange +dark:bg-dark-yellow +dark:bg-dark-green +dark:bg-dark-cyan +dark:bg-dark-purple +border-light-red +border-light-orange +border-light-yellow +border-light-green +border-light-cyan +border-light-purple +dark:border-dark-red +dark:border-dark-orange +dark:border-dark-yellow +dark:border-dark-green +dark:border-dark-cyan +dark:border-dark-purple + +*/ - - - \ No newline at end of file + \ No newline at end of file diff --git a/db.sqlite b/db.sqlite index 3f20193..382bbec 100644 Binary files a/db.sqlite and b/db.sqlite differ diff --git a/server/tasks/sync.ts b/server/tasks/sync.ts index ecec8b0..357061a 100644 --- a/server/tasks/sync.ts +++ b/server/tasks/sync.ts @@ -1,7 +1,6 @@ import useDatabase from "~/composables/useDatabase"; import { extname, basename } from 'node:path'; import type { File, FileType } from '~/types/api'; -import { InputTypeHTMLAttribute } from "vue"; import { CanvasColor, CanvasContent } from "~/types/canvas"; const typeMapping: Record = { @@ -125,12 +124,12 @@ function reshapeContent(content: string, type: FileType): string | null function getColor(color: string): CanvasColor { const colors: Record = { - '1': 'fill-light-red dark:fill-dark-red stroke-light-red dark:stroke-dark-red', - '2': 'fill-light-orange dark:fill-dark-orange stroke-light-orange dark:stroke-dark-orange', - '3': 'fill-light-yellow dark:fill-dark-yellow stroke-light-yellow dark:stroke-dark-yellow', - '4': 'fill-light-green dark:fill-dark-green stroke-light-green dark:stroke-dark-green', - '5': 'fill-light-cyan dark:fill-dark-cyan stroke-light-cyan dark:stroke-dark-cyan', - '6': 'fill-light-purple dark:fill-dark-purple stroke-light-purple dark:stroke-dark-purple', + '1': 'red', + '2': 'orange', + '3': 'yellow', + '4': 'green', + '5': 'cyan', + '6': 'purple', }; if(colors.hasOwnProperty(color)) return { class: colors[color] };