Home-AssistantConfig/config/www/community/frigate-hass-card/zoomer-1857311a.js

12 lines
13 KiB
JavaScript

import{dD as t,dE as e,dF as n,dy as o,d1 as r,s as a,dC as i,y as s,dn as c,bk as l,bm as d,bn as u}from"./card-555679fd.js";var h=function(){return h=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},h.apply(this,arguments)};function p(t,e){for(var n=t.length;n--;)if(t[n].pointerId===e.pointerId)return n;return-1}function m(t,e){var n;if(e.touches){n=0;for(var o=0,r=e.touches;o<r.length;o++){var a=r[o];a.pointerId=n++,m(t,a)}}else(n=p(t,e))>-1&&t.splice(n,1),t.push(e)}function f(t){for(var e,n=(t=t.slice(0)).pop();e=t.pop();)n={clientX:(e.clientX-n.clientX)/2+n.clientX,clientY:(e.clientY-n.clientY)/2+n.clientY};return n}function v(t){if(t.length<2)return 0;var e=t[0],n=t[1];return Math.sqrt(Math.pow(Math.abs(n.clientX-e.clientX),2)+Math.pow(Math.abs(n.clientY-e.clientY),2))}"undefined"!=typeof window&&(window.NodeList&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=Array.prototype.forEach),"function"!=typeof window.CustomEvent&&(window.CustomEvent=function(t,e){e=e||{bubbles:!1,cancelable:!1,detail:null};var n=document.createEvent("CustomEvent");return n.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),n}));var g={down:"mousedown",move:"mousemove",up:"mouseup mouseleave"};function w(t,e,n,o){g[t].split(" ").forEach((function(t){e.addEventListener(t,n,o)}))}function y(t,e,n){g[t].split(" ").forEach((function(t){e.removeEventListener(t,n)}))}function _(t){if(t.parentElement)return t.parentElement;var e=t.getRootNode();return e instanceof ShadowRoot&&e.host instanceof HTMLElement?e.host:void 0}"undefined"!=typeof window&&("function"==typeof window.PointerEvent?g={down:"pointerdown",move:"pointermove",up:"pointerup pointerleave pointercancel"}:"function"==typeof window.TouchEvent&&(g={down:"touchstart",move:"touchmove",up:"touchend touchcancel"}));var b,z="undefined"!=typeof document&&!!document.documentMode;function x(){return b||(b=document.createElement("div").style)}var E=["webkit","moz","ms"],S={};function P(t){if(S[t])return S[t];var e=x();if(t in e)return S[t]=t;for(var n=t[0].toUpperCase()+t.slice(1),o=E.length;o--;){var r="".concat(E[o]).concat(n);if(r in e)return S[t]=r}}function M(t,e){return parseFloat(e[P(t)])||0}function A(t,e,n){void 0===n&&(n=window.getComputedStyle(t));var o="border"===e?"Width":"";return{left:M("".concat(e,"Left").concat(o),n),right:M("".concat(e,"Right").concat(o),n),top:M("".concat(e,"Top").concat(o),n),bottom:M("".concat(e,"Bottom").concat(o),n)}}function O(t,e,n){t.style[P(e)]=n}function C(t){var e=_(t),n=window.getComputedStyle(t),o=window.getComputedStyle(e),r=t.getBoundingClientRect(),a=e.getBoundingClientRect();return{elem:{style:n,width:r.width,height:r.height,top:r.top,bottom:r.bottom,left:r.left,right:r.right,margin:A(t,"margin",n),border:A(t,"border",n)},parent:{style:o,width:a.width,height:a.height,top:a.top,bottom:a.bottom,left:a.left,right:a.right,padding:A(e,"padding",o),border:A(e,"border",o)}}}function H(t,e){return 1===t.nodeType&&" ".concat(function(t){return(t.getAttribute("class")||"").trim()}(t)," ").indexOf(" ".concat(e," "))>-1}var X=/^http:[\w\.\/]+svg$/;var Y={animate:!1,canvas:!1,cursor:"move",disablePan:!1,disableZoom:!1,disableXAxis:!1,disableYAxis:!1,duration:200,easing:"ease-in-out",exclude:[],excludeClass:"panzoom-exclude",handleStartEvent:function(t){t.preventDefault(),t.stopPropagation()},maxScale:4,minScale:.125,overflow:"hidden",panOnlyWhenZoomed:!1,pinchAndPan:!1,relative:!1,setTransform:function(t,e,n){var o=e.x,r=e.y,a=e.scale,i=e.isSVG;if(O(t,"transform","scale(".concat(a,") translate(").concat(o,"px, ").concat(r,"px)")),i&&z){var s=window.getComputedStyle(t).getPropertyValue("transform");t.setAttribute("transform",s)}},startX:0,startY:0,startScale:1,step:.3,touchAction:"none"};function L(t,e){if(!t)throw new Error("Panzoom requires an element as an argument");if(1!==t.nodeType)throw new Error("Panzoom requires an element with a nodeType of 1");if(!function(t){for(var e=t;e&&e.parentNode;){if(e.parentNode===document)return!0;e=e.parentNode instanceof ShadowRoot?e.parentNode.host:e.parentNode}return!1}(t))throw new Error("Panzoom should be called on elements that have been attached to the DOM");e=h(h({},Y),e);var n=function(t){return X.test(t.namespaceURI)&&"svg"!==t.nodeName.toLowerCase()}(t),o=_(t);o.style.overflow=e.overflow,o.style.userSelect="none",o.style.touchAction=e.touchAction,(e.canvas?o:t).style.cursor=e.cursor,t.style.userSelect="none",t.style.touchAction=e.touchAction,O(t,"transformOrigin","string"==typeof e.origin?e.origin:n?"0 0":"50% 50%");var r,a,i,s,c,l,d=0,u=0,b=1,z=!1;function x(e,n,o){if(!o.silent){var r=new CustomEvent(e,{detail:n});t.dispatchEvent(r)}}function E(e,o,r){var a={x:d,y:u,scale:b,isSVG:n,originalEvent:r};return requestAnimationFrame((function(){"boolean"==typeof o.animate&&(o.animate?function(t,e){var n=P("transform");O(t,"transition","".concat(n," ").concat(e.duration,"ms ").concat(e.easing))}(t,o):O(t,"transition","none")),o.setTransform(t,a,o),x(e,a,o),x("panzoomchange",a,o)})),a}function S(n,o,r,a){var i=h(h({},e),a),s={x:d,y:u,opts:i};if(!i.force&&(i.disablePan||i.panOnlyWhenZoomed&&b===i.startScale))return s;if(n=parseFloat(n),o=parseFloat(o),i.disableXAxis||(s.x=(i.relative?d:0)+n),i.disableYAxis||(s.y=(i.relative?u:0)+o),i.contain){var c=C(t),l=c.elem.width/b,p=c.elem.height/b,m=l*r,f=p*r,v=(m-l)/2,g=(f-p)/2;if("inside"===i.contain){var w=(-c.elem.margin.left-c.parent.padding.left+v)/r,y=(c.parent.width-m-c.parent.padding.left-c.elem.margin.left-c.parent.border.left-c.parent.border.right+v)/r;s.x=Math.max(Math.min(s.x,y),w);var _=(-c.elem.margin.top-c.parent.padding.top+g)/r,z=(c.parent.height-f-c.parent.padding.top-c.elem.margin.top-c.parent.border.top-c.parent.border.bottom+g)/r;s.y=Math.max(Math.min(s.y,z),_)}else if("outside"===i.contain){w=(-(m-c.parent.width)-c.parent.padding.left-c.parent.border.left-c.parent.border.right+v)/r,y=(v-c.parent.padding.left)/r;s.x=Math.max(Math.min(s.x,y),w);_=(-(f-c.parent.height)-c.parent.padding.top-c.parent.border.top-c.parent.border.bottom+g)/r,z=(g-c.parent.padding.top)/r;s.y=Math.max(Math.min(s.y,z),_)}}return i.roundPixels&&(s.x=Math.round(s.x),s.y=Math.round(s.y)),s}function M(n,o){var r=h(h({},e),o),a={scale:b,opts:r};if(!r.force&&r.disableZoom)return a;var i=e.minScale,s=e.maxScale;if(r.contain){var c=C(t),l=c.elem.width/b,d=c.elem.height/b;if(l>1&&d>1){var u=(c.parent.width-c.parent.border.left-c.parent.border.right)/l,p=(c.parent.height-c.parent.border.top-c.parent.border.bottom)/d;"inside"===e.contain?s=Math.min(s,u,p):"outside"===e.contain&&(i=Math.max(i,u,p))}}return a.scale=Math.min(Math.max(n,i),s),a}function A(t,e,o,r){var a=S(t,e,b,o);return d!==a.x||u!==a.y?(d=a.x,u=a.y,E("panzoompan",a.opts,r)):{x:d,y:u,scale:b,isSVG:n,originalEvent:r}}function L(t,e,n){var o=M(t,e),r=o.opts;if(r.force||!r.disableZoom){t=o.scale;var a=d,i=u;if(r.focal){var s=r.focal;a=(s.x/t-s.x/b+d*t)/t,i=(s.y/t-s.y/b+u*t)/t}var c=S(a,i,t,{relative:!1,force:!0});return d=c.x,u=c.y,b=t,E("panzoomzoom",r,n)}}function T(t,n){var o=h(h(h({},e),{animate:!0}),n);return L(b*Math.exp((t?1:-1)*o.step),o)}function k(e,o,r,a){var i=C(t),s=i.parent.width-i.parent.padding.left-i.parent.padding.right-i.parent.border.left-i.parent.border.right,c=i.parent.height-i.parent.padding.top-i.parent.padding.bottom-i.parent.border.top-i.parent.border.bottom,l=o.clientX-i.parent.left-i.parent.padding.left-i.parent.border.left-i.elem.margin.left,d=o.clientY-i.parent.top-i.parent.padding.top-i.parent.border.top-i.elem.margin.top;n||(l-=i.elem.width/b/2,d-=i.elem.height/b/2);var u={x:l/s*(s*e),y:d/c*(c*e)};return L(e,h(h({},r),{animate:!1,focal:u}),a)}L(e.startScale,{animate:!1,force:!0}),setTimeout((function(){A(e.startX,e.startY,{animate:!1,force:!0})}));var N=[];function Z(t){if(!function(t,e){for(var n=t;n;n=_(n))if(H(n,e.excludeClass)||e.exclude.indexOf(n)>-1)return!0;return!1}(t.target,e)){m(N,t),z=!0,e.handleStartEvent(t),r=d,a=u,x("panzoomstart",{x:d,y:u,scale:b,isSVG:n,originalEvent:t},e);var o=f(N);i=o.clientX,s=o.clientY,c=b,l=v(N)}}function W(t){if(z&&void 0!==r&&void 0!==a&&void 0!==i&&void 0!==s){m(N,t);var n=f(N),o=N.length>1,d=b;if(o)0===l&&(l=v(N)),k(d=M((v(N)-l)*e.step/80+c).scale,n,{animate:!1},t);o&&!e.pinchAndPan||A(r+(n.clientX-i)/d,a+(n.clientY-s)/d,{animate:!1},t)}}function D(t){1===N.length&&x("panzoomend",{x:d,y:u,scale:b,isSVG:n,originalEvent:t},e),function(t,e){if(e.touches)for(;t.length;)t.pop();else{var n=p(t,e);n>-1&&t.splice(n,1)}}(N,t),z&&(z=!1,r=a=i=s=void 0)}var R=!1;function F(){R||(R=!0,w("down",e.canvas?o:t,Z),w("move",document,W,{passive:!0}),w("up",document,D,{passive:!0}))}return e.noBind||F(),{bind:F,destroy:function(){R=!1,y("down",e.canvas?o:t,Z),y("move",document,W),y("up",document,D)},eventNames:g,getPan:function(){return{x:d,y:u}},getScale:function(){return b},getOptions:function(){return function(t){var e={};for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e}(e)},handleDown:Z,handleMove:W,handleUp:D,pan:A,reset:function(t){var n=h(h(h({},e),{animate:!0,force:!0}),t);b=M(n.startScale,n).scale;var o=S(n.startX,n.startY,b,n);return d=o.x,u=o.y,E("panzoomreset",n)},resetStyle:function(){o.style.overflow="",o.style.userSelect="",o.style.touchAction="",o.style.cursor="",t.style.cursor="",t.style.userSelect="",t.style.touchAction="",O(t,"transformOrigin","")},setOptions:function(n){for(var r in void 0===n&&(n={}),n)n.hasOwnProperty(r)&&(e[r]=n[r]);(n.hasOwnProperty("cursor")||n.hasOwnProperty("canvas"))&&(o.style.cursor=t.style.cursor="",(e.canvas?o:t).style.cursor=e.cursor),n.hasOwnProperty("overflow")&&(o.style.overflow=n.overflow),n.hasOwnProperty("touchAction")&&(o.style.touchAction=n.touchAction,t.style.touchAction=n.touchAction)},setStyle:function(e,n){return O(t,e,n)},zoom:L,zoomIn:function(t){return T(!0,t)},zoomOut:function(t){return T(!1,t)},zoomToPoint:k,zoomWithWheel:function(t,n){t.preventDefault();var o=h(h(h({},e),n),{animate:!1}),r=(0===t.deltaY&&t.deltaX?t.deltaX:t.deltaY)<0?1:-1;return k(M(b*Math.exp(r*o.step/3),o).scale,t,o,t)}}}L.defaultOptions=Y;var T=1/0,k=17976931348623157e292;function N(e){var n=function(e){return e?(e=t(e))===T||e===-T?(e<0?-1:1)*k:e==e?e:0:0===e?e:0}(e),o=n%1;return n==n?o?n-o:n:0}var Z=e.isFinite,W=Math.min;var D,R=(D=Math["round"],function(e,o){if(e=t(e),(o=null==o?0:W(N(o),292))&&Z(e)){var r=(n(e)+"e").split("e"),a=D(r[0]+"e"+(+r[1]+o));return+((r=(n(a)+"e").split("e"))[0]+"e"+(+r[1]-o))}return D(e)});class F{constructor(t){this._zoomed=!1,this._allowClick=!0,this._events=o()?{down:["pointerdown"],move:["pointermove"],up:["pointerup","pointerleave","pointercancel"]}:{down:["touchstart"],move:["touchmove"],up:["touchend","touchcancel"]},this._downHandler=t=>{this._shouldZoomOrPan(t)?(this._panzoom?.handleDown(t),t.stopPropagation(),t.preventDefault(),this._allowClick=!1):this._allowClick=!0},this._clickHandler=t=>{this._allowClick||t.stopPropagation(),this._allowClick=!0},this._moveHandler=t=>{this._shouldZoomOrPan(t)&&(this._panzoom?.handleMove(t),t.stopPropagation())},this._upHandler=t=>{this._shouldZoomOrPan(t)&&(this._panzoom?.handleUp(t),t.stopPropagation())},this._wheelHandler=t=>{t instanceof WheelEvent&&this._shouldZoomOrPan(t)&&(this._panzoom?.zoomWithWheel(t),t.stopPropagation())},this._element=t}_isScaleNormal(t){return void 0!==t&&R(t,4)<=1}_shouldZoomOrPan(t){return!this._isScaleNormal(this._panzoom?.getScale())||window.TouchEvent&&t instanceof TouchEvent&&t.touches.length>1||t instanceof WheelEvent&&t.ctrlKey}_setTouchAction(t){this._element.style.touchAction=t?"":"none"}activate(){this._panzoom=L(this._element,{contain:"outside",maxScale:10,minScale:1,noBind:!0,cursor:void 0,touchAction:""});const t=(t,e,n)=>{t.forEach((t=>{this._element.addEventListener(t,e,n)}))};t(this._events.down,this._downHandler,{capture:!0}),t(this._events.move,this._moveHandler,{capture:!0}),t(this._events.up,this._upHandler,{capture:!0}),t(["wheel"],this._wheelHandler),t(["click"],this._clickHandler,{capture:!0}),this._element.addEventListener("panzoomzoom",(t=>{this._isScaleNormal(t.detail.scale)?(this._zoomed&&(this._setTouchAction(!0),r(this._element,"zoom:unzoomed")),this._zoomed=!1):(this._zoomed||(this._setTouchAction(!1),r(this._element,"zoom:zoomed")),this._zoomed=!0)}))}deactivate(){const t=(t,e)=>{t.forEach((t=>{this._element.removeEventListener(t,e)}))};t(this._events.down,this._downHandler),t(this._events.move,this._moveHandler),t(this._events.up,this._upHandler),t(["wheel"],this._wheelHandler)}}let V=class extends a{constructor(){super(...arguments),this._zoom=new F(this),this._zoomed=!1,this._zoomHandler=()=>this._zoomed=!0,this._unzoomHandler=()=>this._zoomed=!1}connectedCallback(){super.connectedCallback(),this.addEventListener("frigate-card:zoom:zoomed",this._zoomHandler),this.addEventListener("frigate-card:zoom:unzoomed",this._unzoomHandler),this._zoom.activate()}disconnectedCallback(){this._zoom.deactivate(),this.removeEventListener("frigate-card:zoom:zoomed",this._zoomHandler),this.removeEventListener("frigate-card:zoom:unzoomed",this._unzoomHandler)}willUpdate(t){t.has("_zoomed")&&i(this,this._zoomed,"zoomed")}render(){return s` <slot></slot> `}static get styles(){return c`
:host {
width: 100%;
height: 100%;
display: block;
cursor: auto;
}
:host([zoomed]) {
cursor: move;
}
`}};l([d()],V.prototype,"_zoomed",void 0),V=l([u("frigate-card-zoomer")],V);export{V as FrigateCardZoomer};