Merge remote-tracking branch 'origin/master'

This commit is contained in:
Bunny 2024-07-31 23:38:44 +08:00
commit ff6dcd05a3
20 changed files with 6882 additions and 7888 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1 +1 @@
{"version":1721834336660}
{"version":1721883990967}

View File

@ -1,18 +1,57 @@
<script setup lang="ts">
<script lang="ts" setup>
import { useWindowSize } from '@vueuse/core';
import { onMounted, ref } from 'vue';
import Konva from 'konva/lib';
import { Circle } from 'konva/lib/shapes/Circle';
import { Text } from 'konva/lib/shapes/Text';
import { Layer } from 'konva/lib/Layer';
import { Stage } from 'konva/lib/Stage';
const { width, height } = useWindowSize();
const circle = ref<Circle>();
const text = ref<Text>();
const stage = ref<Stage>();
const layer = ref<Layer>();
const SCALE_BY = 1.1;
/**
* * 缩放画布
*/
const zoomed = () => {
stage.value?.on('wheel', ev => {
if (!stage.value) return;
// XY
const oldScaleX = stage.value?.scaleX();
const oldScaleY = stage.value?.scaleY();
//
const pointer = stage.value?.getPointerPosition();
const mousePointTo = {
x: (pointer!.x - stage.value?.x()) / oldScaleX,
y: (pointer!.y - stage.value?.y()) / oldScaleY,
};
//
const direction = ev.evt.deltaY > 0 ? -1 : 1;
//
const newScaleX = direction > 0 ? oldScaleX * SCALE_BY : oldScaleX / SCALE_BY;
const newScaleY = direction > 0 ? oldScaleY * SCALE_BY : oldScaleY / SCALE_BY;
//
stage.value!.scale({ x: newScaleX, y: newScaleY });
//
const newPosition = {
x: pointer!.x - mousePointTo.x * newScaleX,
y: pointer!.y - mousePointTo.y * newScaleY,
};
stage.value!.position(newPosition);
});
};
const initial = () => {
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
stage.value = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
layer.value = new Konva.Layer({ draggable: true });
text.value = new Konva.Text({
@ -24,8 +63,8 @@ const initial = () => {
layer.value.add(text.value);
circle.value = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2,
x: stage.value.width() / 2,
y: stage.value.height() / 2,
radius: 70,
fill: '#adf',
stroke: 'black',
@ -42,7 +81,9 @@ const initial = () => {
});
layer.value.add(circle.value);
stage.add(layer.value);
stage.value.add(layer.value);
zoomed();
};
/**
@ -68,10 +109,10 @@ onMounted(() => {
<template>
<div class="container position-absolute start-0 top-6 z-1">
<button type="button" class="btn btn-primary" @click="onStartListening">开始监听</button>
<button type="button" class="btn btn-danger" @click="onRemoveListening">移出监听</button>
<button class="btn btn-primary" type="button" @click="onStartListening">开始监听</button>
<button class="btn btn-danger" type="button" @click="onRemoveListening">移出监听</button>
</div>
<div id="container"></div>
</template>
<style scoped lang="scss"></style>
<style lang="scss" scoped></style>

View File

@ -1,24 +1,63 @@
<template>
<div class="container">
<button type="button" class="btn btn-primary" @click="onRemoveEvent">移出事件</button>
<button class="btn btn-primary" type="button" @click="onRemoveEvent">移出事件</button>
</div>
<div id="container"></div>
</template>
<script setup lang="ts">
<script lang="ts" setup>
import { useWindowSize } from '@vueuse/core';
import { onMounted, ref } from 'vue';
import Konva from 'konva/lib';
import { Text } from 'konva/lib/shapes/Text';
import { Circle } from 'konva/lib/shapes/Circle';
import { Stage } from 'konva/lib/Stage';
const { width, height } = useWindowSize();
const circle = ref<Circle>();
const text = ref<Text>();
const count = ref(0);
const stage = ref<Stage>();
const SCALE_BY = 1.1;
/**
* * 缩放
*/
const zoomed = () => {
stage.value?.on('wheel', ev => {
if (!stage.value) {
return;
}
//
const oldScaleX = stage.value?.scaleX();
const oldScaleY = stage.value?.scaleY();
const pointer = stage.value?.getPointerPosition();
const mousePointTo = {
x: (pointer!.x - stage.value?.x()) / oldScaleX,
y: (pointer!.y - stage.value?.y()) / oldScaleY,
};
//
const direction = ev.evt.deltaY > 0 ? -1 : 1;
//
const newScaleX = direction > 0 ? oldScaleX * SCALE_BY : oldScaleX / SCALE_BY;
const newScaleY = direction > 0 ? oldScaleY * SCALE_BY : oldScaleY / SCALE_BY;
stage.value?.scale({ x: newScaleX, y: newScaleY });
//
const newPosition = {
x: pointer!.x - mousePointTo.x * newScaleX,
y: pointer!.y - mousePointTo.y * newScaleY,
};
stage.value!.position(newPosition);
});
};
const initial = () => {
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
stage.value = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
const layer = new Konva.Layer({ draggable: true });
//
@ -34,8 +73,8 @@ const initial = () => {
//
circle.value = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2 + 10,
x: stage.value.width() / 2,
y: stage.value.height() / 2 + 10,
radius: 70,
fill: 'green',
stroke: 'black',
@ -51,7 +90,9 @@ const initial = () => {
count.value++;
});
stage.add(layer);
stage.value.add(layer);
zoomed();
};
//

View File

@ -1,19 +1,59 @@
<script setup lang="ts">
<script lang="ts" setup>
import { useWindowSize } from '@vueuse/core';
import { onMounted, ref } from 'vue';
import Konva from 'konva/lib';
import { Group } from 'konva/lib/Group';
import { Rect } from 'konva/lib/shapes/Rect';
import { Stage } from 'konva/lib/Stage';
const { width, height } = useWindowSize();
const yellowGroup = ref<Group>();
const blueGroup = ref<Group>();
const box = ref<Rect>();
const SCALE_BY = 1.1;
const stage = ref<Stage>();
/**
* * 缩放画布
*/
const zoomed = () => {
stage.value?.on('wheel', ev => {
if (!stage.value) {
return;
}
//
const oldScaleX = stage.value?.scaleX();
const oldScaleY = stage.value?.scaleY();
//
const pointer = stage.value?.getPointerPosition();
const mousePointTo = {
x: (pointer!.x - stage.value?.x()) / oldScaleX,
y: (pointer!.y - stage.value?.y()) / oldScaleY,
};
//
const direction = ev.evt.deltaY > 0 ? -1 : 1;
//
const newScaleX = direction > 0 ? oldScaleX * SCALE_BY : oldScaleX / SCALE_BY;
const newScaleY = direction > 0 ? oldScaleY * SCALE_BY : oldScaleY / SCALE_BY;
stage.value?.scale({ x: newScaleX, y: newScaleY });
//
const newPosition = {
x: pointer!.x - mousePointTo.x * newScaleX,
y: pointer!.y - mousePointTo.y * newScaleY,
};
stage.value!.position(newPosition);
});
};
const initial = () => {
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
stage.value = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
const layer = new Konva.Layer();
stage.add(layer);
stage.value.add(layer);
yellowGroup.value = new Konva.Group({
x: 100,
@ -52,12 +92,13 @@ const initial = () => {
stroke: 'black',
});
zoomed();
yellowGroup.value.add(yellowCircle);
yellowGroup.value.add(box.value);
blueGroup.value.add(blueCircle);
layer.add(yellowGroup.value);
layer.add(blueGroup.value);
stage.add(layer);
stage.value.add(layer);
};
/**
@ -87,4 +128,4 @@ onMounted(() => {
</div>
</template>
<style scoped lang="scss"></style>
<style lang="scss" scoped></style>

View File

@ -1,14 +1,52 @@
<script setup lang="ts">
<script lang="ts" setup>
import { useWindowSize } from '@vueuse/core';
import { onMounted } from 'vue';
import { onMounted, ref } from 'vue';
import Konva from 'konva/lib';
import { Stage } from 'konva/lib/Stage';
const { width, height } = useWindowSize();
const stage = ref<Stage>();
const SCALE_BY = 1.1;
/**
* * 缩放画布
*/
const zoomed = () => {
stage.value?.on('wheel', ev => {
if (!stage.value) {
return;
}
// XY
const scaleX = stage.value?.scaleX();
const scaleY = stage.value?.scaleY();
//
const pointer = stage.value?.getPointerPosition();
const mousePointTo = {
x: (pointer!.x - stage.value?.x()) / scaleX,
y: (pointer!.y - stage.value?.y()) / scaleY,
};
//
const direction = ev.evt.deltaY > 0 ? -1 : 1;
//
const x = direction > 0 ? scaleX * SCALE_BY : scaleX / SCALE_BY;
const y = direction > 0 ? scaleY * SCALE_BY : scaleY / SCALE_BY;
stage.value?.scale({ x, y });
const position = {
x: pointer!.x - mousePointTo.x * x,
y: pointer!.y - mousePointTo.y * y,
};
stage.value!.position(position);
});
};
const initial = () => {
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
stage.value = new Konva.Stage({ container: 'container', width: width.value, height: height.value, draggable: true });
const layer = new Konva.Layer();
stage.add(layer);
stage.value.add(layer);
const group = new Konva.Group({ x: 120, y: 40, rotation: 20, draggable: true });
const colors = ['red', 'orange', 'yellow'];
@ -26,6 +64,7 @@ const initial = () => {
group.add(rect);
}
zoomed();
layer.add(group);
};
@ -38,4 +77,4 @@ onMounted(() => {
<div id="container"></div>
</template>
<style scoped lang="scss"></style>
<style lang="scss" scoped></style>

View File

@ -1,16 +1,51 @@
<script setup lang="ts">
<script lang="ts" setup>
import { useWindowSize } from '@vueuse/core';
import { onMounted, ref } from 'vue';
import Konva from 'konva/lib';
import { Rect } from 'konva/lib/shapes/Rect';
import { Stage } from 'konva/lib/Stage';
const { width, height } = useWindowSize();
const yellowBox = ref<Rect>();
const stage = ref<Stage>();
const SCALE_BY = 1.1;
/**
* * 缩放画布
*/
const zoomed = () => {
stage.value?.on('wheel', ev => {
if (!stage.value) return;
//
const scaleX = stage.value?.scaleX();
const scaleY = stage.value?.scaleY();
const pointer = stage.value?.getPointerPosition();
const mousePointTo = {
x: (pointer!.x - stage.value?.x()) / scaleX,
y: (pointer!.y - stage.value?.y()) / scaleY,
};
//
const direction = ev.evt.deltaY > 0 ? -1 : 1;
const x = direction > 0 ? scaleX * SCALE_BY : scaleX / SCALE_BY;
const y = direction > 0 ? scaleY * SCALE_BY : scaleY / SCALE_BY;
stage.value?.scale({ x, y });
const position = {
x: pointer!.x - mousePointTo.x * x,
y: pointer!.y - mousePointTo.y * y,
};
stage.value?.position(position);
});
};
const initial = () => {
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
stage.value = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
const layer = new Konva.Layer();
stage.add(layer);
stage.value.add(layer);
const colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'];
@ -42,7 +77,8 @@ const initial = () => {
})();
}
stage.add(layer);
zoomed();
stage.value.add(layer);
};
onMounted(() => {
@ -63,4 +99,4 @@ onMounted(() => {
</div>
</template>
<style scoped lang="scss"></style>
<style lang="scss" scoped></style>

View File

@ -1,16 +1,49 @@
<script setup lang="ts">
<script lang="ts" setup>
import { useWindowSize } from '@vueuse/core';
import Konva from 'konva/lib';
import { onMounted, ref } from 'vue';
import { Circle } from 'konva/lib/shapes/Circle';
import { Stage } from 'konva/lib/Stage';
const { width, height } = useWindowSize();
const circle = ref<Circle>();
const stage = ref<Stage>();
const SCALE_BY = 1.1;
const zoomed = () => {
stage.value?.on('wheel', ev => {
if (!stage.value) {
return;
}
//
const scaleX = stage.value?.scaleX();
const scaleY = stage.value?.scaleY();
const pointer = stage.value?.getPointerPosition();
const mousePointTo = {
x: (pointer!.x - stage.value?.x()) / scaleX,
y: (pointer!.y - stage.value?.y()) / scaleY,
};
const direction = ev.evt.deltaY > 0 ? -1 : 1;
const x = direction > 0 ? scaleX * SCALE_BY : scaleX / SCALE_BY;
const y = direction > 0 ? scaleY * SCALE_BY : scaleY / SCALE_BY;
stage.value?.scale({ x, y });
const position = {
x: pointer!.x - mousePointTo.x * x,
y: pointer!.y - mousePointTo.y * y,
};
stage.value?.position(position);
});
};
const initial = () => {
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
stage.value = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
const layer = new Konva.Layer();
stage.add(layer);
stage.value.add(layer);
const group = new Konva.Group();
layer.add(group);
@ -30,6 +63,8 @@ const initial = () => {
width: 100,
height: 100,
});
zoomed();
group.add(blackRect);
};
@ -52,4 +87,4 @@ onMounted(() => {
</div>
</template>
<style scoped lang="scss"></style>
<style lang="scss" scoped></style>

View File

@ -1,4 +1,4 @@
<script setup lang="ts">
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { useEventListener, useWindowSize } from '@vueuse/core';
import Konva from 'konva/lib';
@ -9,11 +9,46 @@ import { Stage } from 'konva/lib/Stage';
import { Layer } from 'konva/lib/Layer';
const { width, height } = useWindowSize();
// let stage, layer;
const stage = ref<Stage>();
const layer = ref<Layer>();
const tr = ref();
const SCALE_BY = 1.1;
const zoomed = () => {
stage.value?.on('wheel', ev => {
//
if (!stage.value) return;
//
const scaleX = stage.value?.scaleX();
const scaleY = stage.value?.scaleY();
//
const pointer = stage.value?.getPointerPosition();
//
const mousePointTo = {
x: (pointer!.x - stage.value?.x()) / scaleX,
y: (pointer!.y - stage.value?.y()) / scaleY,
};
//
const direction = ev.evt.deltaY > 0 ? -1 : 1;
//
const x = direction > 0 ? scaleX * SCALE_BY : scaleX / SCALE_BY;
const y = direction > 0 ? scaleY * SCALE_BY : scaleY / SCALE_BY;
stage.value?.scale({ x, y });
//
const position = {
x: pointer!.x - mousePointTo.x * x,
y: pointer!.y - mousePointTo.y * y,
};
stage.value?.position(position);
});
};
const initial = () => {
stage.value = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
@ -40,6 +75,8 @@ onMounted(() => {
// tr.value.forceUpdate();
});
zoomed();
});
</script>

View File

@ -1,15 +1,49 @@
<script setup lang="ts">
<script lang="ts" setup>
import { useWindowSize } from '@vueuse/core';
import { onMounted } from 'vue';
import { onMounted, ref } from 'vue';
import Konva from 'konva/lib';
import { Stage } from 'konva/lib/Stage';
const { width, height } = useWindowSize();
const stage = ref<Stage>();
const SCALE_BY = 1.1;
/**
* * 缩放
*/
const zoomed = () => {
stage.value?.on('wheel', ev => {
if (!stage.value) {
return;
}
const scaleX = stage.value?.scaleX();
const scaleY = stage.value?.scaleY();
const pointer = stage.value?.getPointerPosition();
const mousePointTo = {
x: (pointer!.x - stage.value?.x()) / scaleX,
y: (pointer!.y - stage.value?.y()) / scaleY,
};
const direction = ev.evt.deltaY > 0 ? -1 : 1;
const x = direction > 0 ? scaleX * SCALE_BY : scaleX / SCALE_BY;
const y = direction > 0 ? scaleY * SCALE_BY : scaleY / SCALE_BY;
stage.value?.scale({ x, y });
const position = {
x: pointer!.x - mousePointTo.x * x,
y: pointer!.y - mousePointTo.y * y,
};
stage.value?.position(position);
});
};
const initial = () => {
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
stage.value = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
const layer = new Konva.Layer();
stage.add(layer);
stage.value.add(layer);
const circle = new Konva.Circle({
x: 150,
@ -38,6 +72,8 @@ const initial = () => {
},
nodes: [circle],
});
zoomed();
layer.add(tr);
};
@ -50,4 +86,4 @@ onMounted(() => {
<div id="container"></div>
</template>
<style scoped lang="scss"></style>
<style lang="scss" scoped></style>

View File

@ -1,14 +1,51 @@
<script setup lang="ts">
import { onMounted } from 'vue';
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { useWindowSize } from '@vueuse/core';
import Konva from 'konva/lib';
import { Stage } from 'konva/lib/Stage';
const { width, height } = useWindowSize();
const stage = ref<Stage>();
const SCALE_BY = 1.1;
const zoomed = () => {
stage.value?.on('wheel', ev => {
if (!stage.value) return;
//
const scaleX = stage.value?.scaleX();
const scaleY = stage.value?.scaleY();
//
const pointer = stage.value?.getPointerPosition();
//
const mousePointTo = {
x: (pointer!.x - stage.value?.x()) / scaleX,
y: (pointer!.y - stage.value?.y()) / scaleY,
};
//
const direction = ev.evt.deltaY > 0 ? -1 : 1;
//
const x = direction > 0 ? scaleX * SCALE_BY : scaleX / SCALE_BY;
const y = direction > 0 ? scaleY * SCALE_BY : scaleY / SCALE_BY;
stage.value?.scale({ x, y });
//
const position = {
x: pointer!.x - mousePointTo.x * x,
y: pointer!.y - mousePointTo.y * y,
};
stage.value?.position(position);
});
};
const initial = () => {
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
stage.value = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
const layer = new Konva.Layer();
stage.add(layer);
stage.value.add(layer);
const text1 = new Konva.Text({
x: 50,
@ -40,7 +77,10 @@ const initial = () => {
keepRatio: false,
enabledAnchors: ['top-left', 'top-right', 'bottom-left', 'bottom-right'],
});
layer.add(tr2);
zoomed();
};
onMounted(() => {
@ -52,4 +92,4 @@ onMounted(() => {
<div id="container"></div>
</template>
<style scoped lang="scss"></style>
<style lang="scss" scoped></style>

View File

@ -1,16 +1,51 @@
<script setup lang="ts">
<script lang="ts" setup>
import { useWindowSize } from '@vueuse/core';
import { onMounted } from 'vue';
import { onMounted, ref } from 'vue';
import Konva from 'konva/lib';
import { Stage } from 'konva/lib/Stage';
const { width, height } = useWindowSize();
const MAX_WIDTH = 200;
const stage = ref<Stage>();
const SCALE_BY = 1.1;
const zoomed = () => {
stage.value?.on('wheel', ev => {
if (!stage.value) return;
//
const scaleX = stage.value?.scaleX();
const scaleY = stage.value?.scaleY();
//
const pointerPosition = stage.value?.getPointerPosition();
//
const mousePointTo = {
x: (pointerPosition!.x - stage.value?.x()) / scaleX,
y: (pointerPosition!.y - stage.value?.y()) / scaleY,
};
const direction = ev.evt.deltaY > 0 ? -1 : 1;
//
const x = direction > 0 ? scaleX * SCALE_BY : scaleX / SCALE_BY;
const y = direction > 0 ? scaleY * SCALE_BY : scaleY / SCALE_BY;
stage.value?.scale({ x, y });
//
const position = {
x: pointerPosition!.x - mousePointTo.x * x,
y: pointerPosition!.y - mousePointTo.y * y,
};
stage.value?.position(position);
});
};
const initial = () => {
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
stage.value = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
const layer = new Konva.Layer();
stage.add(layer);
stage.value.add(layer);
zoomed();
const rect = new Konva.Rect({
x: 160,
y: 60,

View File

@ -1,25 +1,57 @@
<script setup lang="ts">
<script lang="ts" setup>
import { useWindowSize } from '@vueuse/core';
import Konva from 'konva/lib';
import { onMounted } from 'vue';
import { onMounted, ref } from 'vue';
import { Stage } from 'konva/lib/Stage';
const { width, height } = useWindowSize();
const stage = ref<Stage>();
const SCALE_BY = 1.1;
const zoomed = () => {
stage.value?.on('wheel', ev => {
if (!stage.value) return;
//
const scaleX = stage.value?.scaleX();
const scaleY = stage.value?.scaleY();
//
const pointerPosition = stage.value?.getPointerPosition();
const mousePointTO = {
x: (pointerPosition!.x - stage.value?.x()) / scaleX,
y: (pointerPosition!.y - stage.value?.y()) / scaleY,
};
const direction = ev.evt.deltaY > 0 ? -1 : 1;
//
const x = direction > 0 ? scaleX * SCALE_BY : scaleX / SCALE_BY;
const y = direction > 0 ? scaleY * SCALE_BY : scaleY / SCALE_BY;
stage.value?.scale({ x, y });
//
const position = {
x: pointerPosition!.x - mousePointTO.x * x,
y: pointerPosition!.y - mousePointTO.y * y,
};
stage.value?.position(position);
});
};
const initial = () => {
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
stage.value = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
const layer = new Konva.Layer();
stage.add(layer);
const xSnaps = Math.round(stage.width() / 100);
const ySnaps = Math.round(stage.height() / 100);
const cellWidth = stage.width() / xSnaps;
const cellHeight = stage.height() / ySnaps;
stage.value.add(layer);
zoomed();
const xSnaps = Math.round(stage.value.width() / 100);
const ySnaps = Math.round(stage.value.height() / 100);
const cellWidth = stage.value.width() / xSnaps;
const cellHeight = stage.value.height() / ySnaps;
for (let i = 0; i < xSnaps; i++) {
layer.add(
new Konva.Line({
x: i * cellWidth,
points: [0, 0, 0, stage.height()],
points: [0, 0, 0, stage.value.height()],
stroke: '#96e04d',
strokeWidth: 1,
}),
@ -31,7 +63,7 @@ const initial = () => {
new Konva.Line({
y: i * cellHeight,
// points: [0, 0, stage.width(), 0],
points: [0, 0, stage.width(), 0],
points: [0, 0, stage.value.width(), 0],
stroke: '#96e04d',
strokeWidth: 1,
}),
@ -111,4 +143,4 @@ onMounted(() => {
<div id="container"></div>
</template>
<style scoped lang="scss"></style>
<style lang="scss" scoped></style>

View File

@ -1,15 +1,44 @@
<script setup lang="ts">
<script lang="ts" setup>
import { useWindowSize } from '@vueuse/core';
import { onMounted } from 'vue';
import { onMounted, ref } from 'vue';
import Konva from 'konva/lib';
import { Stage } from 'konva/lib/Stage';
const { width, height } = useWindowSize();
const stage = ref<Stage>();
const SCALE_BY = 1.1;
const zoomed = () => {
stage.value?.on('wheel', ev => {
if (!stage.value) return;
const scaleX = stage.value?.scaleX();
const scaleY = stage.value?.scaleY();
const pointerPosition = stage.value?.getPointerPosition();
const mousePointTo = {
x: (pointerPosition!.x - stage.value?.x()) / scaleX,
y: (pointerPosition!.y - stage.value?.y()) / scaleY,
};
const direction = ev.evt.deltaY > 0 ? -1 : 1;
const x = direction > 0 ? scaleX * SCALE_BY : scaleX / SCALE_BY;
const y = direction > 0 ? scaleY * SCALE_BY : scaleY / SCALE_BY;
stage.value?.scale({ x, y });
const position = {
x: pointerPosition!.x - mousePointTo.x * x,
y: pointerPosition!.y - mousePointTo.y * y,
};
stage.value?.position(position);
});
};
const initial = () => {
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
stage.value = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
const layer = new Konva.Layer();
stage.add(layer);
stage.value.add(layer);
zoomed();
const text = new Konva.Text({ x: 50, y: 70, fontSize: 30, text: '旋转', draggable: true });
layer.add(text);

View File

@ -1,16 +1,46 @@
<script setup lang="ts">
<script lang="ts" setup>
import { useWindowSize } from '@vueuse/core';
import { onMounted } from 'vue';
import { onMounted, ref } from 'vue';
import Konva from 'konva/lib';
import { Stage } from 'konva/lib/Stage';
const { width, height } = useWindowSize();
const stage = ref<Stage>();
const SCALE_BY = 1.1;
const zoomed = () => {
stage.value?.on('wheel', ev => {
if (!stage.value) return;
const scaleX = stage.value?.scaleX();
const scaleY = stage.value?.scaleY();
const pointerPosition = stage.value?.getPointerPosition();
const mousePointTo = {
x: (pointerPosition!.x - stage.value?.x()) / scaleX,
y: (pointerPosition!.y - stage.value?.y()) / scaleY,
};
const direction = ev.evt.deltaY > 0 ? -1 : 1;
const x = direction > 0 ? scaleX * SCALE_BY : scaleX / SCALE_BY;
const y = direction > 0 ? scaleY * SCALE_BY : scaleY / SCALE_BY;
stage.value?.scale({ x, y });
const position = {
x: pointerPosition!.x - mousePointTo.x * x,
y: pointerPosition!.y - mousePointTo.y * y,
};
stage.value?.position(position);
});
};
const initial = () => {
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
stage.value = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
const layer = new Konva.Layer();
stage.add(layer);
stage.value.add(layer);
zoomed();
const text1 = new Konva.Text({
x: 50,
y: 70,
@ -51,4 +81,4 @@ onMounted(() => {
<div id="container"></div>
</template>
<style scoped lang="scss"></style>
<style lang="scss" scoped></style>

View File

@ -1,14 +1,50 @@
<script setup lang="ts">
<script lang="ts" setup>
import { useWindowSize } from '@vueuse/core';
import { onMounted } from 'vue';
import { onMounted, ref } from 'vue';
import Konva from 'konva/lib';
import { Stage } from 'konva/lib/Stage';
const { width, height } = useWindowSize();
const stage = ref<Stage>();
const SCALE_BY = 1.1;
const zoomed = () => {
stage.value?.on('wheel', ev => {
if (!stage.value) return;
//
const scaleX = stage.value?.scaleX();
const scaleY = stage.value?.scaleY();
//
const pointerPosition = stage.value?.getPointerPosition();
//
const mousePointTo = {
x: (pointerPosition!.x - stage.value?.x()) / scaleX,
y: (pointerPosition!.y - stage.value?.y()) / scaleY,
};
const direction = ev.evt.deltaY > 0 ? -1 : 1;
//
const x = direction > 0 ? scaleX * SCALE_BY : scaleX / SCALE_BY;
const y = direction > 0 ? scaleY * SCALE_BY : scaleY / SCALE_BY;
stage.value?.scale({ x, y });
//
const position = {
x: pointerPosition!.x - mousePointTo.x * x,
y: pointerPosition!.y - mousePointTo.y * y,
};
stage.value?.position(position);
});
};
const initial = () => {
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
stage.value = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
const layer = new Konva.Layer();
stage.add(layer);
stage.value.add(layer);
zoomed();
const rect = new Konva.Rect({
x: 100,

View File

@ -1,15 +1,51 @@
<script setup lang="ts">
<script lang="ts" setup>
import { useWindowSize } from '@vueuse/core';
import { onMounted } from 'vue';
import { onMounted, ref } from 'vue';
import Konva from 'konva/lib';
import { Stage } from 'konva/lib/Stage';
const { width, height } = useWindowSize();
const initial = () => {
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
const layer = new Konva.Layer();
stage.add(layer);
const stage = ref<Stage>();
const SCALE_BY = 1.1;
const zoomed = () => {
stage.value?.on('wheel', ev => {
if (!stage.value) return;
//
const scaleX = stage.value?.scaleX();
const scaleY = stage.value?.scaleY();
//
const pointerPosition = stage.value?.getPointerPosition();
//
const mousePointTo = {
x: (pointerPosition!.x - stage.value?.x()) / scaleX,
y: (pointerPosition!.y - stage.value?.y()) / scaleY,
};
const direction = ev.evt.deltaY > 0 ? -1 : 1;
//
const x = direction > 0 ? scaleX * SCALE_BY : scaleX / SCALE_BY;
const y = direction > 0 ? scaleY * SCALE_BY : scaleY / SCALE_BY;
stage.value?.scale({ x, y });
//
const position = {
x: pointerPosition!.x - mousePointTo.x * x,
y: pointerPosition!.y - mousePointTo.y * y,
};
stage.value?.position(position);
});
};
const initial = () => {
stage.value = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
const layer = new Konva.Layer();
stage.value.add(layer);
zoomed();
const circle = new Konva.Circle({
x: 150,
y: 150,
@ -40,4 +76,4 @@ onMounted(() => {
<div id="container"></div>
</template>
<style scoped lang="scss"></style>
<style lang="scss" scoped></style>

View File

@ -1,16 +1,47 @@
<script setup lang="ts">
import { onMounted } from 'vue';
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import Konva from 'konva/lib';
import { useWindowSize } from '@vueuse/core';
import { Stage } from 'konva/lib/Stage';
const { width, height } = useWindowSize();
const MIN_WIDTH = 100;
const initial = () => {
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
const layer = new Konva.Layer();
stage.add(layer);
const stage = ref<Stage>();
const SCALE_BY = 1.1;
const zoomed = () => {
stage.value?.on('wheel', ev => {
if (!stage.value) return;
const scaleX = stage.value?.scaleX();
const scaleY = stage.value?.scaleY();
const pointerPosition = stage.value?.getPointerPosition();
const mousePointTo = {
x: (pointerPosition!.x - stage.value?.x()) / scaleX,
y: (pointerPosition!.y - stage.value?.y()) / scaleY,
};
const direction = ev.evt.deltaY > 0 ? -1 : 1;
const x = direction > 0 ? scaleX * SCALE_BY : scaleX / SCALE_BY;
const y = direction > 0 ? scaleY * SCALE_BY : scaleY / SCALE_BY;
stage.value?.scale({ x, y });
const position = {
x: pointerPosition!.x - mousePointTo.x * x,
y: pointerPosition!.y - mousePointTo.y * y,
};
stage.value?.position(position);
});
};
const initial = () => {
stage.value = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
const layer = new Konva.Layer();
stage.value.add(layer);
zoomed();
const text = new Konva.Text({
x: 50,
y: 60,

View File

@ -2,18 +2,49 @@
<div id="container"></div>
</template>
<script setup lang="ts">
<script lang="ts" setup>
import { useWindowSize } from '@vueuse/core';
import Konva from 'konva/lib';
import { onMounted } from 'vue';
import { onMounted, ref } from 'vue';
import { Stage } from 'konva/lib/Stage';
const { width, height } = useWindowSize();
const stage = ref<Stage>();
const SCALE_BY = 1.1;
const zoomed = () => {
stage.value?.on('wheel', ev => {
if (!stage.value) return;
const scaleX = stage.value?.scaleX();
const scaleY = stage.value?.scaleY();
const pointerPosition = stage.value?.getPointerPosition();
const mousePointTo = {
x: (pointerPosition!.x - stage.value?.x()) / scaleX,
y: (pointerPosition!.y - stage.value?.y()) / scaleY,
};
const direction = ev.evt.deltaY > 0 ? -1 : 1;
const x = direction > 0 ? scaleX * SCALE_BY : scaleX / SCALE_BY;
const y = direction > 0 ? scaleY * SCALE_BY : scaleY / SCALE_BY;
stage.value?.scale({ x, y });
const position = {
x: pointerPosition!.x - mousePointTo.x * x,
y: pointerPosition!.y - mousePointTo.y * y,
};
stage.value?.position(position);
});
};
const initial = () => {
const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
stage.value = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
const layer = new Konva.Layer();
stage.add(layer);
stage.value.add(layer);
zoomed();
//
const rect = new Konva.Rect({

View File

@ -2,21 +2,51 @@
<div id="container"></div>
</template>
<script setup lang="ts">
<script lang="ts" setup>
import { Layer } from 'konva/lib/Layer';
import { Image as KonvaImage } from 'konva/lib/shapes/Image';
import { Stage } from 'konva/lib/Stage';
import { nextTick, onMounted } from 'vue';
import { nextTick, onMounted, ref } from 'vue';
const stage = ref<Stage>();
const SCALE_BY = 1.1;
const zoomed = () => {
stage.value?.on('wheel', ev => {
if (!stage.value) return;
const scaleX = stage.value?.scaleX();
const scaleY = stage.value?.scaleY();
const pointerPosition = stage.value?.getPointerPosition();
const mousePointTo = {
x: (pointerPosition!.x - stage.value?.x()) / scaleX,
y: (pointerPosition!.y - stage.value?.y()) / scaleY,
};
const direction = ev.evt.deltaY > 0 ? -1 : 1;
const x = direction > 0 ? scaleX * SCALE_BY : scaleX / SCALE_BY;
const y = direction > 0 ? scaleY * SCALE_BY : scaleY / SCALE_BY;
stage.value?.scale({ x, y });
const position = {
x: pointerPosition!.x - mousePointTo.x * x,
y: pointerPosition!.y - mousePointTo.y * y,
};
stage.value?.position(position);
});
};
const initial = () => {
const stage = new Stage({
stage.value = new Stage({
container: 'container',
width: 500,
height: 500,
draggable: true,
});
const layer = new Layer({ draggable: true });
zoomed();
const imageObj = new Image();
const konvaImage = new KonvaImage({
x: 50,
@ -40,7 +70,7 @@ const initial = () => {
layer.add(darthNode);
});
stage.add(layer);
stage.value.add(layer);
};
onMounted(() => {