@drauu/core
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -38,3 +38,10 @@ interface Unsubscribe { | ||
brush?: Brush; | ||
/** | ||
* @default 'brush' | ||
*/ | ||
mode?: DrawingMode; | ||
/** | ||
* @default 1 | ||
*/ | ||
corrdinateScale?: number; | ||
} | ||
@@ -80,2 +87,3 @@ interface EventsMap { | ||
declare class Drauu { | ||
options: Options; | ||
el: SVGSVGElement | null; | ||
@@ -82,0 +90,0 @@ mode: DrawingMode; |
@@ -60,7 +60,17 @@ (() => { | ||
getMousePosition(event) { | ||
var _a; | ||
const rect = this.drauu.el.getBoundingClientRect(); | ||
if (event instanceof MouseEvent) | ||
return { x: event.pageX - rect.left, y: event.pageY - rect.top }; | ||
if (event instanceof Touch) | ||
return { x: event.targetTouches[0].pageX - rect.left, y: event.targetTouches[0].pageY - rect.top }; | ||
const scale = (_a = this.drauu.options.corrdinateScale) != null ? _a : 1; | ||
if (event instanceof MouseEvent) { | ||
return { | ||
x: (event.pageX - rect.left) * scale, | ||
y: (event.pageY - rect.top) * scale | ||
}; | ||
} | ||
if (event instanceof Touch) { | ||
return { | ||
x: (event.targetTouches[0].pageX - rect.left) * scale, | ||
y: (event.targetTouches[0].pageY - rect.top) * scale | ||
}; | ||
} | ||
throw new Error("unsupported event type"); | ||
@@ -333,2 +343,3 @@ } | ||
constructor(options = {}) { | ||
this.options = options; | ||
this.el = null; | ||
@@ -335,0 +346,0 @@ this.shiftPressed = false; |
@@ -73,7 +73,17 @@ var __defProp = Object.defineProperty; | ||
getMousePosition(event) { | ||
var _a; | ||
const rect = this.drauu.el.getBoundingClientRect(); | ||
if (event instanceof MouseEvent) | ||
return { x: event.pageX - rect.left, y: event.pageY - rect.top }; | ||
if (event instanceof Touch) | ||
return { x: event.targetTouches[0].pageX - rect.left, y: event.targetTouches[0].pageY - rect.top }; | ||
const scale = (_a = this.drauu.options.corrdinateScale) != null ? _a : 1; | ||
if (event instanceof MouseEvent) { | ||
return { | ||
x: (event.pageX - rect.left) * scale, | ||
y: (event.pageY - rect.top) * scale | ||
}; | ||
} | ||
if (event instanceof Touch) { | ||
return { | ||
x: (event.targetTouches[0].pageX - rect.left) * scale, | ||
y: (event.targetTouches[0].pageY - rect.top) * scale | ||
}; | ||
} | ||
throw new Error("unsupported event type"); | ||
@@ -346,2 +356,3 @@ } | ||
constructor(options = {}) { | ||
this.options = options; | ||
this.el = null; | ||
@@ -348,0 +359,0 @@ this.shiftPressed = false; |
{ | ||
"name": "@drauu/core", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/index.mjs", |
Sorry, the diff of this file is not supported yet
42300
1492