UNPKG

2.29 kBJavaScriptView Raw
1import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-8809c729.js';
2import { c as classnames } from './index-1d8e8acd.js';
3
4const indexCss = "body,html{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-tap-highlight-color:rgba(0, 0, 0, 0)}taro-view-core{display:block}";
5
6let View = class {
7 constructor(hostRef) {
8 registerInstance(this, hostRef);
9 this.onLongPress = createEvent(this, "longpress", 7);
10 this.hoverStartTime = 50;
11 this.hoverStayTime = 400;
12 this.hover = false;
13 this.touch = false;
14 this.startTime = 0;
15 }
16 onTouchStart() {
17 if (this.hoverClass) {
18 this.touch = true;
19 setTimeout(() => {
20 if (this.touch) {
21 this.hover = true;
22 }
23 }, this.hoverStartTime);
24 }
25 this.timeoutEvent = setTimeout(() => {
26 this.onLongPress.emit();
27 }, 350);
28 this.startTime = Date.now();
29 }
30 onTouchMove() {
31 clearTimeout(this.timeoutEvent);
32 }
33 onTouchEnd() {
34 const spanTime = Date.now() - this.startTime;
35 if (spanTime < 350) {
36 clearTimeout(this.timeoutEvent);
37 }
38 if (this.hoverClass) {
39 this.touch = false;
40 setTimeout(() => {
41 if (!this.touch) {
42 this.hover = false;
43 }
44 }, this.hoverStayTime);
45 }
46 }
47 componentDidRender() {
48 const el = this.el;
49 el.childNodes.forEach(item => {
50 // Note: ['s-cn'] Content Reference Node
51 if (item.nodeType === document.COMMENT_NODE && item['s-cn'])
52 item['s-cn'] = false;
53 // Note: ['s-sr'] Is a slot reference node (渲染完成后禁用 slotRelocation 特性, 避免 Stencil 组件相互调用时内置排序与第三方 UI 框架冲突导致组件顺序混乱)
54 if (item.nodeType !== document.COMMENT_NODE && item['s-sr'])
55 item['s-sr'] = false;
56 });
57 }
58 render() {
59 const cls = classnames({
60 [`${this.hoverClass}`]: this.hover
61 });
62 let attr = {};
63 if (!!this.animation) {
64 attr['animation'] = this.animation;
65 attr['data-animation'] = this.animation;
66 }
67 return (h(Host, Object.assign({ class: cls }, attr), h("slot", null)));
68 }
69 get el() { return getElement(this); }
70};
71View.style = indexCss;
72
73export { View as taro_view_core };