@livelybone/mouse-mock
Version:
A lib for mock mouse events like click, move
10 lines (8 loc) • 6.22 kB
JavaScript
/**
* Bundle of @livelybone/mouse-mock
* Generated: 2021-07-01
* Version: 1.3.5
* License: MIT
* Author: 2631541504@qq.com
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).RewriteListenerBinderMouseMock={})}(this,function(e){"use strict";function t(t,e){var n,r=Object.keys(t);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(t),e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)),r}function m(r){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{};e%2?t(Object(o),!0).forEach(function(e){var t,n;t=r,e=o[n=e],n in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):t(Object(o)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(o,e))})}return r}function y(e){return function(e){if(Array.isArray(e))return r(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Map"===(n="Object"===n&&e.constructor?e.constructor.name:n)||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function o(n){var e,t;if(n.isTrusted)return n;for(var r={},o=n;o.__proto__;)Object.keys(o.__proto__).forEach(function(t){Object.defineProperty(r,t,{get:function(){var e=n[t];return"function"==typeof e?e.bind(n):e},configurable:!0})}),o=o.__proto__;return r.isTrusted=!0,r.__proto__=(null===(e=n.__proto__)||void 0===e||null===(t=e.constructor)||void 0===t?void 0:t.prototype)||n.__proto__,r}var i=new Map;function n(){window.$$RewriteListenerBinderSuccess$$||(Element.prototype._addEventListener=Element.prototype.addEventListener,Element.prototype._removeEventListener=Element.prototype.removeEventListener,Element.prototype.addEventListener=function(e,t){var n=i.get(t)||function(e){return t(o(e))};this._addEventListener(e,n)},Element.prototype.removeEventListener=function(e,t){var n=i.get(t);n&&(this._removeEventListener(e,n),i.delete(t))},Object.getOwnPropertyNames(HTMLElement.prototype).forEach(function(e){var t;e.startsWith("on")&&(t=Object.getOwnPropertyDescriptor(HTMLElement.prototype,e),Object.defineProperty(HTMLElement.prototype,"_".concat(e),t),Object.defineProperty(HTMLElement.prototype,e,m(m({},t),{},{set:function(t){this["_".concat(e)]="function"==typeof t?function(e){return t.call(this,o(e))}:t}})))}),Object.defineProperty(window,"$$RewriteListenerBinderSuccess$$",{value:!0,writable:!1,configurable:!0}))}function h(e){var t=e.ownerDocument,n=t.getElementById("script-for-inject-owner-window");return!e.ownerWindow&&n&&(n.id="",n=null),n||((n=t.createElement("script")).type="text/javascript",n.id="script-for-inject-owner-window",n.innerHTML="HTMLElement.prototype.ownerWindow = window;",t.head.appendChild(n)),e.ownerWindow}function c(e){var t=window.getComputedStyle(e),n={top:0,left:0};return"HTML"!==e.nodeName&&!["scroll","auto","overlay"].includes(t.overflowX)||(n.left=Math.max(0,e.scrollWidth-e.clientWidth)),"HTML"!==e.nodeName&&!["scroll","auto","overlay"].includes(t.overflowY)||(n.top=Math.max(0,e.scrollHeight-e.clientHeight)),n}function u(e){return!e.top&&!e.left}function v(e){if(null!=e&&e.style){var t=window.getComputedStyle(e);if("fixed"!==t.position){var n=e.ownerDocument;if("absolute"===t.position)return e.offsetParent?v(e.offsetParent):u(c(n.body))?v(n.body):n.body;e=e.parentElement;return e?u(c(e))&&e!==n.documentElement?v(e):e:void 0}}}function l(n){var t,r,o,i,e="nodeType"in n?h(n):window,c=[{x:0,y:0,width:window.innerWidth,height:window.innerHeight}],u="style"in n?n.getBoundingClientRect():n,l=function(){if("style"in n){for(var e=[],t=v(n);t;)e.push(t.getBoundingClientRect()),t=v(t);return e.filter(function(e){return e.width&&e.height})}return[]}(),l=(r=t=-1/0,i=o=1/0,[u].concat(y(l),c).forEach(function(e){t=Math.max(t,e.x),r=Math.max(r,e.y),o=Math.min(o,e.x+e.width),i=Math.min(i,e.y+e.height)}),{x:t,y:r,width:o-t,height:i-r});if(l.width<=0||l.height<=0)return{clientX:-1,clientY:-1,screenY:-1,screenX:-1};var a,f,d={clientX:0,clientY:0},c={screenX:0,screenY:0};if(u){var s=Math.min(l.width/2,l.height/2),p={x:l.x+l.width/2,y:l.y+l.height/2};if(1<=s)for(;d.clientX=Math.floor(p.x+s*Math.random()*(.5<Math.random()?1:-1)),d.clientY=Math.floor(p.y+s*Math.random()*(.5<Math.random()?1:-1)),f=a=void 0,a=d.clientX-p.x,f=d.clientY-p.y,!(a*a+f*f<=s*s););else d.clientX=Math.floor(p.x),d.clientY=Math.floor(p.y)}l=e.innerWidth,e=e.innerHeight;return c.screenX=d.clientX-l,c.screenY=d.clientY-e,m(m({},d),c)}function a(e,t){if(t){var n=l(t),r=t&&"nodeName"in t?t:document.elementFromPoint(n.clientX,n.clientY),o=null==r?void 0:r.ownerDocument.createEvent("MouseEvent");return r?(o.initMouseEvent(e,!0,!0,h(r),0,n.screenX,n.screenY,n.clientX,n.clientY,!1,!1,!1,!1,0,r),i=o,(o=r).dispatchEvent?o.dispatchEvent(i):null!==(r=o.fireEvent)&&void 0!==r&&r.call(o,i)):console.error("Cannot find element for ".concat(e,", it seems that the element or the rect you provide is out of the viewport.\n"),{el:t,point:n}),{point:n}}var i}n(),"undefined"!=typeof document&&(Object.defineProperty(document,"hidden",{get:function(){return!1},configurable:!0}),Object.defineProperty(document,"visibilityState",{get:function(){return"visible"},configurable:!0}),window.requestAnimationFrame=function(e){return setTimeout(e,16)}),e.mockClick=function(e){a("mouseenter",e),a("mouseover",e),a("mousemove",e),a("mousedown",e),a("mouseup",e);var t=a("click",e);return a("mousemove",e),a("mouseout",e),a("mouseleave",e),t},e.mockMouseEvent=a,e.rewriteListenerBinder=n,Object.defineProperty(e,"__esModule",{value:!0})});