UNPKG

@tarojs/components

Version:
52 lines (46 loc) 1.59 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const index = require('./index-a7069008.js'); const indexCss = "taro-canvas-core{width:300px;height:150px;display:block;position:relative}"; const LONG_TAP_DELAY = 500; const Canvas = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.onLongTap = index.createEvent(this, "longtap", 7); this.onTouchStart = () => { this.timer = setTimeout(() => { this.onLongTap.emit(); }, LONG_TAP_DELAY); }; this.onTouchMove = () => { clearTimeout(this.timer); }; this.onTouchEnd = () => { clearTimeout(this.timer); }; this.canvasId = undefined; this.height = undefined; this.width = undefined; this.nativeProps = {}; } componentDidRender() { const [canvas] = this.el.children; if (!this.height || !this.width) { let style = window.getComputedStyle(canvas); this.height || (this.height = style.height); this.width || (this.width = style.width); } canvas.height = parseInt(this.height); canvas.width = parseInt(this.width); } render() { const { canvasId, nativeProps } = this; return (index.h("canvas", Object.assign({ "canvas-id": canvasId, style: { width: '100%', height: '100%' }, onTouchStart: this.onTouchStart, onTouchMove: this.onTouchMove, onTouchCancel: this.onTouchEnd, onTouchEnd: this.onTouchEnd }, nativeProps))); } get el() { return index.getElement(this); } }; Canvas.style = indexCss; exports.taro_canvas_core = Canvas;