/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
import{inherits as t,createSuper as i,classCallCheck as n,possibleConstructorReturn as e,createClass as o,typeof as s}from"../_virtual/_rollupPluginBabelHelpers.js";import r from"../../../../_virtual/index.js";function a(t){var i=parseFloat(t);return-1===t.indexOf("%")&&!Number.isNaN(i)&&i}var h=["paddingLeft","paddingRight","paddingTop","paddingBottom","marginLeft","marginRight","marginTop","marginBottom","borderLeftWidth","borderRightWidth","borderTopWidth","borderBottomWidth"],d=h.length;function u(t){if("string"==typeof t&&(t=document.querySelector(t)),t&&"object"===s(t)&&t.nodeType){var i=function(t){return window.getComputedStyle(t)}(t);if("none"===i.display)return function(){for(var t={width:0,height:0,innerWidth:0,innerHeight:0,outerWidth:0,outerHeight:0},i=0;i<d;i++)t[h[i]]=0;return t}();var n={};n.width=t.offsetWidth,n.height=t.offsetHeight;for(var e=n.isBorderBox="border-box"===i.boxSizing,o=0;o<d;o++){var r=h[o],u=i[r],c=parseFloat(u);n[r]=Number.isNaN(c)?0:c}var g=n.paddingLeft+n.paddingRight,v=n.paddingTop+n.paddingBottom,l=n.marginLeft+n.marginRight,f=n.marginTop+n.marginBottom,p=n.borderLeftWidth+n.borderRightWidth,m=n.borderTopWidth+n.borderBottomWidth,y=e,_=a(i.width);!1!==_&&(n.width=_+(y?0:g+p));var P=a(i.height);return!1!==P&&(n.height=P+(y?0:v+m)),n.innerWidth=n.width-(g+p),n.innerHeight=n.height-(v+m),n.outerWidth=n.width+l,n.outerHeight=n.height+f,n}}function c(t,i){for(var n=0;n<t.length;n++){var e=t[n];if(e.identifier===i)return e}}var g="dragStart",v="dragMove",l="dragEnded",f={mousedown:["mousemove","mouseup"],touchstart:["touchmove","touchend","touchcancel"],pointerdown:["pointermove","pointerup","pointercancel"]},p=/* @__PURE__ */function(){t(a,r);var s=i(a);function a(t){var i,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return n(this,a),(i=s.call(this)).isEnabled=!0,i.isDragging=!1,i.isDown=!1,i.position={},i.downPoint={},i.dragPoint={x:0,y:0},i.startPos={x:0,y:0},i._root=t instanceof Element?t:document.querySelector(t),i._handlerDom=o.handle instanceof Element?o.handle:document.querySelector(o.handle),i._root&&i._handlerDom?(i._bindStartEvent(),i):e(i)}return o(a,[{key:"_bindStartEvent",value:function(){var t=this;"ontouchstart"in window?this._startKey="touchstart":this._startKey="mousedown",this["on".concat(this._startKey)]=this["on".concat(this._startKey)].bind(this),this._handlerDom.addEventListener(this._startKey,this["on".concat(this._startKey)]),f[this._startKey].map(function(i){t["on".concat(i)]=t["on".concat(i)].bind(t)})}},{key:"_unbindStartEvent",value:function(){this._handlerDom.removeEventListener(this._startKey,this["on".concat(this._startKey)])}},{key:"_bindPostStartEvents",value:function(t){var i=this;if(t){var n=f[this._startKey];n.map(function(t){window.addEventListener(t,i["on".concat(t)])}),this._boundPointerEvents=n}}},{key:"_unbindPostStartEvents",value:function(){var t=this;this._boundPointerEvents&&(this._boundPointerEvents.map(function(i){window.removeEventListener(i,t["on".concat(i)])}),delete this._boundPointerEvents)}},{key:"enable",value:function(){this.isEnabled=!0}},{key:"disable",value:function(){this.isEnabled=!1,this.isDragging&&this.onUp()}},{key:"onDocUp",value:function(t){this.onUp()}},{key:"animate",value:function(){var t=this;this.isDragging&&(this.positionDrag(),window.requestAnimationFrame(function(){t.animate()}))}},{key:"positionDrag",value:function(){var t="translate3d(".concat(this.dragPoint.x,"px, ").concat(this.dragPoint.y,"px, 0)");this._root.style.transform=t,this._root.style.webKitTransform=t}},{key:"setLeftTop",value:function(){this._root.style.left=this.position.x+"px",this._root.style.top=this.position.y+"px"}},{key:"onmousedown",value:function(t){this.dragStart(t,t)}},{key:"onmousemove",value:function(t){this.dragMove(t,t)}},{key:"onmouseup",value:function(t){this.dragEnd(t,t)}},{key:"ontouchstart",value:function(t){var i=t.changedTouches[0];this.dragStart(t,i),this.touchIdentifier=void 0!==i.pointerId?i.pointerId:i.identifier,t.preventDefault()}},{key:"ontouchmove",value:function(t){var i=c(t.changedTouches,this.touchIdentifier);i&&this.dragMove(t,i)}},{key:"ontouchend",value:function(t){var i=c(t.changedTouches,this.touchIdentifier);i&&this.dragEnd(t,i),t.preventDefault()}},{key:"ontouchcancel",value:function(t){var i=c(t.changedTouches,this.touchIdentifier);i&&this.dragCancel(t,i)}},{key:"dragStart",value:function(t,i){if(this._root&&!this.isDown&&this.isEnabled){this.downPoint=i,this.dragPoint.x=0,this.dragPoint.y=0,this._getPosition();var n=u(this._root);this.startPos.x=this.position.x,this.startPos.y=this.position.y,this.startPos.maxY=window.innerHeight-n.height,this.startPos.maxX=window.innerWidth-n.width,this.setLeftTop(),this.isDown=!0,this._bindPostStartEvents(t)}}},{key:"dragRealStart",value:function(t,i){this.isDragging=!0,this.animate(),this.emit(g,this.startPos)}},{key:"dragEnd",value:function(t,i){this._root&&(this._unbindPostStartEvents(),this.isDragging&&(this._root.style.transform="",this.setLeftTop(),this.emit(l)),this.presetInfo())}},{key:"_dragPointerMove",value:function(t,i){var n={x:i.pageX-this.downPoint.pageX,y:i.pageY-this.downPoint.pageY};return!this.isDragging&&this.hasDragStarted(n)&&this.dragRealStart(t,i),n}},{key:"dragMove",value:function(t,i){if(t=t||window.event,this.isDown){var n=this.startPos,e=n.x,o=n.y,s=this._dragPointerMove(t,i),r=s.x,a=s.y;r=this.checkContain("x",r,e),a=this.checkContain("y",a,o),this.position.x=e+r,this.position.y=o+a,this.dragPoint.x=r,this.dragPoint.y=a,this.emit(v,this.position)}}},{key:"dragCancel",value:function(t,i){this.dragEnd(t,i)}},{key:"presetInfo",value:function(){this.isDragging=!1,this.startPos={x:0,y:0},this.dragPoint={x:0,y:0},this.isDown=!1}},{key:"destroy",value:function(){this._unbindStartEvent(),this._unbindPostStartEvents(),this.isDragging&&this.dragEnd(),this.removeAllListeners(),this._handlerDom=null}},{key:"hasDragStarted",value:function(t){return Math.abs(t.x)>3||Math.abs(t.y)>3}},{key:"checkContain",value:function(t,i,n){return i+n<0?0-n:"x"===t&&i+n>this.startPos.maxX?this.startPos.maxX-n:"y"===t&&i+n>this.startPos.maxY?this.startPos.maxY-n:i}},{key:"_getPosition",value:function(){var t=window.getComputedStyle(this._root),i=this._getPositionCoord(t.left,"width"),n=this._getPositionCoord(t.top,"height");this.position.x=Number.isNaN(i)?0:i,this.position.y=Number.isNaN(n)?0:n,this._addTransformPosition(t)}},{key:"_addTransformPosition",value:function(t){var i=t.transform;if(0===i.indexOf("matrix")){var n=i.split(","),e=0===i.indexOf("matrix3d")?12:4,o=parseInt(n[e],10),s=parseInt(n[e+1],10);this.position.x+=o,this.position.y+=s}}},{key:"_getPositionCoord",value:function(t,i){if(-1!==t.indexOf("%")){var n=u(this._root.parentNode);return n?parseFloat(t)/100*n[i]:0}return parseInt(t,10)}}]),a}();export{p as default};