You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.3 KiB
HTML
54 lines
1.3 KiB
HTML
<!dhtml lib>
|
|
|
|
<script>
|
|
import {
|
|
attachStageResizer,
|
|
fitImageToStage,
|
|
coverImageToStage,
|
|
} from "./@shared/konva-utils.js"
|
|
</script>
|
|
|
|
<konva-editor>
|
|
<script>
|
|
this.stage = null;
|
|
this._resizeObserver = null;
|
|
|
|
mounted() {
|
|
const width = this.root.clientWidth || 500;
|
|
const height = this.root.clientHeight || 400;
|
|
|
|
this.stage = new Konva.Stage({
|
|
container: this.root,
|
|
width,
|
|
height,
|
|
});
|
|
|
|
this.layer = new Konva.Layer();
|
|
this.stage.add(this.layer);
|
|
|
|
this._resizeObserver = attachStageResizer(this.root, this.stage);
|
|
this.addImage("1.jpg");
|
|
|
|
}
|
|
|
|
// простой метод добавления картинки через Konva
|
|
addImage(url) {
|
|
// опционально: добавить crossOrigin, если нужно
|
|
Konva.Image.fromURL(url, (konvaImage) => {
|
|
coverImageToStage(konvaImage, this.stage); // масштабирование (fit?)
|
|
konvaImage.setAttrs({ x: 0, y: 0, draggable: true, });
|
|
this.layer.add(konvaImage);
|
|
this.layer.draw();
|
|
}, { crossOrigin: 'Anonymous' });
|
|
};
|
|
|
|
unmounted() {
|
|
this._resizeObserver?.disconnect();
|
|
this._resizeObserver = null;
|
|
|
|
this.stage?.destroy();
|
|
this.stage = null;
|
|
}
|
|
</script>
|
|
</konva-editor>
|