move touch.js to canvas

master
JFH 2022-01-05 23:05:41 -03:00
parent 2d5104cdeb
commit b9a89a9789
7 changed files with 12 additions and 23 deletions

View File

@ -15,7 +15,6 @@ const isWebkit_ = userAgent.includes('AppleWebKit')
const isGecko_ = userAgent.includes('Gecko/')
const isChrome_ = userAgent.includes('Chrome/')
const isMac_ = userAgent.includes('Macintosh')
const isTouch_ = 'ontouchstart' in window
// text character positioning (for IE9 and now Chrome)
const supportsGoodTextCharPos_ = (function () {
@ -60,11 +59,6 @@ export const isChrome = () => isChrome_
* @returns {boolean}
*/
export const isMac = () => isMac_
/**
* @function module:browser.isTouch
* @returns {boolean}
*/
export const isTouch = () => isTouch_
/**
* @function module:browser.supportsGoodTextCharPos

View File

@ -16,7 +16,6 @@
import './components/index.js'
import './dialogs/index.js'
import './touch.js'
import { isMac } from '../common/browser.js'
import SvgCanvas from '../svgcanvas/svgcanvas.js'

View File

@ -1,5 +1,4 @@
/* globals seConfirm seAlert */
import './touch.js'
import { convertUnit } from '../common/units.js'
import {
putLocale

View File

@ -443,13 +443,6 @@ export default {
header.textContent = allLibs
back.style.display = 'none'
})
back.addEventListener('touchend', function () {
frame.setAttribute('src', 'about:blank')
frame.style.display = 'none'
libOpts.style.display = 'block'
header.textContent = allLibs
back.style.display = 'none'
})
back.setAttribute('style', 'margin-right: 5px;')
back.style.display = 'none'

View File

@ -6,13 +6,14 @@
* @copyright 2010 Alexis Deveria, 2010 Jeff Schiller
*/
import { isTouch, isWebkit } from '../common/browser.js' // , isOpera
import { isWebkit } from '../common/browser.js' // , isOpera
import { getRotationAngle, getBBox, getStrokedBBox } from './utilities.js'
import { transformListToTransform, transformBox, transformPoint } from './math.js'
let svgCanvas
let selectorManager_ // A Singleton
const gripRadius = isTouch() ? 10 : 4
// change radius if touch screen
const gripRadius = window.ontouchstart ? 10 : 4
/**
* Private class for DOM element selection boxes.

View File

@ -7,7 +7,6 @@
* @copyright 2010 Alexis Deveria, 2010 Pavol Rusnak, 2010 Jeff Schiller, 2021 OptimistikSAS
*
*/
import { Canvg as canvg } from 'canvg'
import 'pathseg' // SVGPathSeg Polyfill (see https://github.com/progers/pathseg)
@ -17,6 +16,7 @@ import * as draw from './draw.js'
import {
init as pasteInit, pasteElementsMethod
} from './paste-elem.js'
import { init as touchInit } from './touch.js'
import { svgRootElement } from './svgroot.js'
import {
init as undoInit, changeSelectedAttributeNoUndoMethod,
@ -162,6 +162,7 @@ class SvgCanvas {
container.append(this.svgroot)
// The actual element that represents the final output SVG element.
this.svgContent = this.svgdoc.createElementNS(NS.SVG, 'svg')
touchInit(this)
clearInit(this)
this.clearSvgContentElement()
// Current `draw.Drawing` object.

View File

@ -4,7 +4,7 @@
* @param {Event} ev
* @returns {void}
*/
function touchHandler (ev) {
const touchHandler = (ev) => {
const { changedTouches } = ev
const first = changedTouches[0]
@ -43,7 +43,9 @@ function touchHandler (ev) {
}
}
document.addEventListener('touchstart', touchHandler, true)
document.addEventListener('touchmove', touchHandler, true)
document.addEventListener('touchend', touchHandler, true)
document.addEventListener('touchcancel', touchHandler, true)
export const init = (_svgCanvas) => {
document.addEventListener('touchstart', touchHandler, true)
document.addEventListener('touchmove', touchHandler, true)
document.addEventListener('touchend', touchHandler, true)
document.addEventListener('touchcancel', touchHandler, true)
}