UNPKG

2.82 kBJavaScriptView Raw
1import{r as t,h as i,g as s,H as o}from"./p-059912fd.js";let h=class{constructor(i){t(this,i),this.views=[],this.scaleLength=0,this.viewsChanged=()=>{this.views=[];const t=this.element.querySelectorAll("taro-movable-view-core");Array.from(t).forEach((t=>{this.views.push(t)})),this.updateArea()},this.handleTouchStart=t=>{const i=t.touches;if(!i||i.length<=1)return;const s=i[1].pageX-i[0].pageX,o=i[1].pageY-i[0].pageY;if(this.scaleLength=Math.sqrt(s*s+o*o),this.scaleArea)return;const h=(t,i)=>{const s=(t,i)=>!!(t=t.parentNode)&&(!(t instanceof HTMLElement)||t!==document.body)&&(t===i||t===i.element||t.element===i||s(t,i));for(let o=0;o<i.length;o++){const h=i[o];if(t===h.element||s(t,h))return h}},e=h(i[0].target,this.views),r=h(i[1].target,this.views);this.scaleTarget=e&&e===r?e:void 0},this.handleTouchMove=t=>{const i=t.touches;if(!i||i.length<=1)return;t.preventDefault();const s=i[1].pageX-i[0].pageX,o=i[1].pageY-i[0].pageY;this.scaleLength>0&&this.updateScale(Math.sqrt(s*s+o*o)/this.scaleLength)},this.handleTouchEnd=t=>{var i,s;t.touches&&t.touches.length||!t.changedTouches||(this.scaleLength=0,this.scaleArea?this.views.forEach((t=>{var i;null===(i=t.endScale)||void 0===i||i.call(t)})):null===(s=null===(i=this.scaleTarget)||void 0===i?void 0:i.endScale)||void 0===s||s.call(i),this.scaleTarget=void 0)},this.updateScale=t=>{var i,s;t&&1!==t&&(this.scaleArea?this.views.forEach((i=>{var s;null===(s=i.setScale)||void 0===s||s.call(i,t)})):null===(s=null===(i=this.scaleTarget)||void 0===i?void 0:i.setScale)||void 0===s||s.call(i,t))},this.updateArea=()=>{const t=window.getComputedStyle(this.element),i=this.element.getBoundingClientRect(),s=["Left","Right"].map((i=>parseFloat(t["border"+i+"Width"])+parseFloat(t["padding"+i]))),o=["Top","Bottom"].map((i=>parseFloat(t["border"+i+"Width"])+parseFloat(t["padding"+i])));this.views.forEach((t=>{var h;null===(h=t.setParent)||void 0===h||h.call(t,{element:this.element,area:{height:i.height-o[0]-o[1],width:i.width-s[0]-s[1]}})}))}}connectedCallback(){this.observer=new MutationObserver((t=>{t.forEach((t=>{var i,s;if("class"===t.attributeName||"style"===t.attributeName){const t=this.element.offsetWidth,o=this.element.offsetHeight;t===(null===(i=this.offset)||void 0===i?void 0:i.width)&&o===(null===(s=this.offset)||void 0===s?void 0:s.height)||this.updateArea(),this.offset={width:t,height:o}}}))})),this.observer.observe(this.element,{attributes:!0})}disconnectedCallback(){var t;null===(t=this.observer)||void 0===t||t.disconnect()}componentDidLoad(){this.viewsChanged()}render(){return i(o,{onTouchStart:this.handleTouchStart,onTouchMove:this.handleTouchMove,onTouchEnd:this.handleTouchEnd})}get element(){return s(this)}};h.style="taro-movable-area-core{display:block;position:relative;width:10px;height:10px}";export{h as taro_movable_area_core}
\No newline at end of file