coupdoeil 1.0.0.pre.alpha.1 → 1.0.0.pre.alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- class t{constructor(t){this.coupdoeilElement=t,this.card=null,this.children=new Set,this.parent=null,this.closingRequest=null,this.openingDelay=null,this.fetchDelay=null}get isOpen(){return!!this.coupdoeilElement.dataset.hovercardOpen}get isClosed(){return!this.isOpen}}const e="coupdoeil--hovercard",n=`.${e}`,o=150,r=100,i=200,c={animation:{getter:function(t){return s[(56&t)>>4]}},cache:{getter:function(t){return!(8&~t)}},offset:{getter:function(t){const e=Number(BigInt(t)>>BigInt(23));if(0===e)return 0;return function(t){if("number"==typeof t)return t;if(/^(-?\d+\.?\d+)px$/.test(t))return parseFloat(t);if(/^(-?\d*\.?\d+)rem$/.test(t))return parseFloat(t)*parseFloat(getComputedStyle(document.documentElement).fontSize);return 0}(`${1&~e?"":"-"}${e>>13}.${e>>2&2047}${2&~e?"px":"rem"}`)}},placement:{getter:function(t){const e=t>>7&65535;let n=0,o=null;const r=[];for(;"auto"!==o&&n<16;)o=u[e>>n&15],r.push(o),n+=4;return r}},loading:{getter:function(t){return f[1&t]}},trigger:{getter:function(t){return a[1&t]}}},l=["trigger","loading","cache","animation","placement","offset"],a=["hover","click"],s=[!1,"slide-in","fade-in","slide-out","custom"],u=["auto","top","top-start","top-end","right","right-start","right-end","bottom","bottom-start","bottom-end","left","left-start","left-end"],f=["asyn","preload","lazy"];const d={animation:void 0,cache:void 0,offset:void 0,placement:void 0,loading:void 0,trigger:void 0};function p(t){const e=t.getAttribute("hc");return parseInt(e,36)}function h(t){return t.coupdoeilElement.getAttribute("hc-type")}function m(t){return t.coupdoeilElement.getAttribute("hc-params")}function g(t){return function(t,e){const n=t.hovercardController.optionsInt||=p(t);return c[e].getter(n)}(t.coupdoeilElement,"trigger")}function y(t){return"click"!==g(t)}function w(t){return"hover"===g(t)}function v(t){return"hover"!==g(t)}function x(t){return t.coupdoeilElement.querySelector(".hovercard-content")}const b=new Map;function E(t){return x(t)?t.coupdoeilElement.uniqueId:h(t)+m(t)}function T(t){return b.get(E(t))}async function C(t,e,n){const o=e.dataset,r=n?`${n}-${t}`:t;let i=`transition${t.charAt(0).toUpperCase()+t.slice(1)}`;const c=o[i]?o[i].split(" "):[r],l=o[`${i}Start`]?o[`${i}Start`].split(" "):[`${r}-start`],a=o[`${i}End`]?o[`${i}End`].split(" "):[`${r}-end`];L(e,c),L(e,l),await new Promise((t=>{requestAnimationFrame((()=>{requestAnimationFrame(t)}))})),R(e,l),L(e,a),await function(t){return new Promise((e=>{const n=getComputedStyle(t).transitionDuration.split(",")[0],o=1e3*Number(n.replace("s",""));setTimeout((()=>{e()}),o)}))}(e),R(e,a),R(e,c)}function L(t,e){t.classList.add(...e)}function R(t,e){t.classList.remove(...e)}function O(t){clearTimeout(t.closingRequest),t.closingRequest=null}function D(t,e=!0){t.closing||t.isClosed||(t.closing=!0,M(t),t.children.forEach((t=>{D(t)})),function(t){t.parent&&(t.parent.children.delete(t),t.parent=null)}(t),e&&t.card.dataset.animation?async function(t){await async function(t,e=null){await C("leave",t,e),t.classList.add("hidden")}(t.card,"hovercard"),A(t)}(t):A(t))}function A(t){t.card.remove(),t.card=null,delete t.closing,delete t.coupdoeilElement.dataset.hovercardOpen}function P(t){M(t),t.closingRequest=setTimeout((()=>{D(t)}),o)}function S(t){t.children.forEach((t=>{D(t)}))}const $=new Map;function H(){b.clear()}function q(t){$.set(t.uniqueId,t)}function F(){for(const t of $.values())D(t.hovercardController),W(t)}function k(){for(const t of $.values())D(t.hovercardController,!1),W(t)}function W(t){$.delete(t.uniqueId)}function M(t){!function(t){clearTimeout(t.openingDelay),t.openingDelay=null,clearTimeout(t.fetchDelay),t.fetchDelay=null,delete t.coupdoeilElement.openingHovercard}(t),O(t)}window.hovercads=$;const B=["top","right","bottom","left"],V=["start","end"],I=B.reduce(((t,e)=>t.concat(e,e+"-"+V[0],e+"-"+V[1])),[]),N=Math.min,j=Math.max,z=Math.round,_=t=>({x:t,y:t}),U={left:"right",right:"left",bottom:"top",top:"bottom"},X={start:"end",end:"start"};function Y(t,e,n){return j(t,N(e,n))}function J(t,e){return"function"==typeof t?t(e):t}function G(t){return t.split("-")[0]}function K(t){return t.split("-")[1]}function Q(t){return"x"===t?"y":"x"}function Z(t){return"y"===t?"height":"width"}function tt(t){return["top","bottom"].includes(G(t))?"y":"x"}function et(t){return Q(tt(t))}function nt(t,e,n){void 0===n&&(n=!1);const o=K(t),r=et(t),i=Z(r);let c="x"===r?o===(n?"end":"start")?"right":"left":"start"===o?"bottom":"top";return e.reference[i]>e.floating[i]&&(c=rt(c)),[c,rt(c)]}function ot(t){return t.replace(/start|end/g,(t=>X[t]))}function rt(t){return t.replace(/left|right|bottom|top/g,(t=>U[t]))}function it(t){return"number"!=typeof t?function(t){return{top:0,right:0,bottom:0,left:0,...t}}(t):{top:t,right:t,bottom:t,left:t}}function ct(t){const{x:e,y:n,width:o,height:r}=t;return{width:o,height:r,top:n,left:e,right:e+o,bottom:n+r,x:e,y:n}}function lt(t,e,n){let{reference:o,floating:r}=t;const i=tt(e),c=et(e),l=Z(c),a=G(e),s="y"===i,u=o.x+o.width/2-r.width/2,f=o.y+o.height/2-r.height/2,d=o[l]/2-r[l]/2;let p;switch(a){case"top":p={x:u,y:o.y-r.height};break;case"bottom":p={x:u,y:o.y+o.height};break;case"right":p={x:o.x+o.width,y:f};break;case"left":p={x:o.x-r.width,y:f};break;default:p={x:o.x,y:o.y}}switch(K(e)){case"start":p[c]-=d*(n&&s?-1:1);break;case"end":p[c]+=d*(n&&s?-1:1)}return p}async function at(t,e){var n;void 0===e&&(e={});const{x:o,y:r,platform:i,rects:c,elements:l,strategy:a}=t,{boundary:s="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:d=!1,padding:p=0}=J(e,t),h=it(p),m=l[d?"floating"===f?"reference":"floating":f],g=ct(await i.getClippingRect({element:null==(n=await(null==i.isElement?void 0:i.isElement(m)))||n?m:m.contextElement||await(null==i.getDocumentElement?void 0:i.getDocumentElement(l.floating)),boundary:s,rootBoundary:u,strategy:a})),y="floating"===f?{x:o,y:r,width:c.floating.width,height:c.floating.height}:c.reference,w=await(null==i.getOffsetParent?void 0:i.getOffsetParent(l.floating)),v=await(null==i.isElement?void 0:i.isElement(w))&&await(null==i.getScale?void 0:i.getScale(w))||{x:1,y:1},x=ct(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:y,offsetParent:w,strategy:a}):y);return{top:(g.top-x.top+h.top)/v.y,bottom:(x.bottom-g.bottom+h.bottom)/v.y,left:(g.left-x.left+h.left)/v.x,right:(x.right-g.right+h.right)/v.x}}function st(){return"undefined"!=typeof window}function ut(t){return pt(t)?(t.nodeName||"").toLowerCase():"#document"}function ft(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function dt(t){var e;return null==(e=(pt(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function pt(t){return!!st()&&(t instanceof Node||t instanceof ft(t).Node)}function ht(t){return!!st()&&(t instanceof Element||t instanceof ft(t).Element)}function mt(t){return!!st()&&(t instanceof HTMLElement||t instanceof ft(t).HTMLElement)}function gt(t){return!(!st()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof ft(t).ShadowRoot)}function yt(t){const{overflow:e,overflowX:n,overflowY:o,display:r}=Tt(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&!["inline","contents"].includes(r)}function wt(t){return["table","td","th"].includes(ut(t))}function vt(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function xt(t){const e=bt(),n=ht(t)?Tt(t):t;return"none"!==n.transform||"none"!==n.perspective||!!n.containerType&&"normal"!==n.containerType||!e&&!!n.backdropFilter&&"none"!==n.backdropFilter||!e&&!!n.filter&&"none"!==n.filter||["transform","perspective","filter"].some((t=>(n.willChange||"").includes(t)))||["paint","layout","strict","content"].some((t=>(n.contain||"").includes(t)))}function bt(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function Et(t){return["html","body","#document"].includes(ut(t))}function Tt(t){return ft(t).getComputedStyle(t)}function Ct(t){return ht(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function Lt(t){if("html"===ut(t))return t;const e=t.assignedSlot||t.parentNode||gt(t)&&t.host||dt(t);return gt(e)?e.host:e}function Rt(t){const e=Lt(t);return Et(e)?t.ownerDocument?t.ownerDocument.body:t.body:mt(e)&&yt(e)?e:Rt(e)}function Ot(t,e,n){var o;void 0===e&&(e=[]),void 0===n&&(n=!0);const r=Rt(t),i=r===(null==(o=t.ownerDocument)?void 0:o.body),c=ft(r);if(i){const t=Dt(c);return e.concat(c,c.visualViewport||[],yt(r)?r:[],t&&n?Ot(t):[])}return e.concat(r,Ot(r,[],n))}function Dt(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function At(t){const e=Tt(t);let n=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const r=mt(t),i=r?t.offsetWidth:n,c=r?t.offsetHeight:o,l=z(n)!==i||z(o)!==c;return l&&(n=i,o=c),{width:n,height:o,$:l}}function Pt(t){return ht(t)?t:t.contextElement}function St(t){const e=Pt(t);if(!mt(e))return _(1);const n=e.getBoundingClientRect(),{width:o,height:r,$:i}=At(e);let c=(i?z(n.width):n.width)/o,l=(i?z(n.height):n.height)/r;return c&&Number.isFinite(c)||(c=1),l&&Number.isFinite(l)||(l=1),{x:c,y:l}}const $t=_(0);function Ht(t){const e=ft(t);return bt()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:$t}function qt(t,e,n,o){void 0===e&&(e=!1),void 0===n&&(n=!1);const r=t.getBoundingClientRect(),i=Pt(t);let c=_(1);e&&(o?ht(o)&&(c=St(o)):c=St(t));const l=function(t,e,n){return void 0===e&&(e=!1),!(!n||e&&n!==ft(t))&&e}(i,n,o)?Ht(i):_(0);let a=(r.left+l.x)/c.x,s=(r.top+l.y)/c.y,u=r.width/c.x,f=r.height/c.y;if(i){const t=ft(i),e=o&&ht(o)?ft(o):o;let n=t,r=Dt(n);for(;r&&o&&e!==n;){const t=St(r),e=r.getBoundingClientRect(),o=Tt(r),i=e.left+(r.clientLeft+parseFloat(o.paddingLeft))*t.x,c=e.top+(r.clientTop+parseFloat(o.paddingTop))*t.y;a*=t.x,s*=t.y,u*=t.x,f*=t.y,a+=i,s+=c,n=ft(r),r=Dt(n)}}return ct({width:u,height:f,x:a,y:s})}function Ft(t,e){const n=Ct(t).scrollLeft;return e?e.left+n:qt(dt(t)).left+n}function kt(t,e,n){void 0===n&&(n=!1);const o=t.getBoundingClientRect();return{x:o.left+e.scrollLeft-(n?0:Ft(t,o)),y:o.top+e.scrollTop}}function Wt(t,e,n){let o;if("viewport"===e)o=function(t,e){const n=ft(t),o=dt(t),r=n.visualViewport;let i=o.clientWidth,c=o.clientHeight,l=0,a=0;if(r){i=r.width,c=r.height;const t=bt();(!t||t&&"fixed"===e)&&(l=r.offsetLeft,a=r.offsetTop)}return{width:i,height:c,x:l,y:a}}(t,n);else if("document"===e)o=function(t){const e=dt(t),n=Ct(t),o=t.ownerDocument.body,r=j(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),i=j(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let c=-n.scrollLeft+Ft(t);const l=-n.scrollTop;return"rtl"===Tt(o).direction&&(c+=j(e.clientWidth,o.clientWidth)-r),{width:r,height:i,x:c,y:l}}(dt(t));else if(ht(e))o=function(t,e){const n=qt(t,!0,"fixed"===e),o=n.top+t.clientTop,r=n.left+t.clientLeft,i=mt(t)?St(t):_(1);return{width:t.clientWidth*i.x,height:t.clientHeight*i.y,x:r*i.x,y:o*i.y}}(e,n);else{const n=Ht(t);o={x:e.x-n.x,y:e.y-n.y,width:e.width,height:e.height}}return ct(o)}function Mt(t,e){const n=Lt(t);return!(n===e||!ht(n)||Et(n))&&("fixed"===Tt(n).position||Mt(n,e))}function Bt(t,e,n){const o=mt(e),r=dt(e),i="fixed"===n,c=qt(t,!0,i,e);let l={scrollLeft:0,scrollTop:0};const a=_(0);if(o||!o&&!i)if(("body"!==ut(e)||yt(r))&&(l=Ct(e)),o){const t=qt(e,!0,i,e);a.x=t.x+e.clientLeft,a.y=t.y+e.clientTop}else r&&(a.x=Ft(r));const s=!r||o||i?_(0):kt(r,l);return{x:c.left+l.scrollLeft-a.x-s.x,y:c.top+l.scrollTop-a.y-s.y,width:c.width,height:c.height}}function Vt(t){return"static"===Tt(t).position}function It(t,e){if(!mt(t)||"fixed"===Tt(t).position)return null;if(e)return e(t);let n=t.offsetParent;return dt(t)===n&&(n=n.ownerDocument.body),n}function Nt(t,e){const n=ft(t);if(vt(t))return n;if(!mt(t)){let e=Lt(t);for(;e&&!Et(e);){if(ht(e)&&!Vt(e))return e;e=Lt(e)}return n}let o=It(t,e);for(;o&&wt(o)&&Vt(o);)o=It(o,e);return o&&Et(o)&&Vt(o)&&!xt(o)?n:o||function(t){let e=Lt(t);for(;mt(e)&&!Et(e);){if(xt(e))return e;if(vt(e))return null;e=Lt(e)}return null}(t)||n}const jt={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:n,offsetParent:o,strategy:r}=t;const i="fixed"===r,c=dt(o),l=!!e&&vt(e.floating);if(o===c||l&&i)return n;let a={scrollLeft:0,scrollTop:0},s=_(1);const u=_(0),f=mt(o);if((f||!f&&!i)&&(("body"!==ut(o)||yt(c))&&(a=Ct(o)),mt(o))){const t=qt(o);s=St(o),u.x=t.x+o.clientLeft,u.y=t.y+o.clientTop}const d=!c||f||i?_(0):kt(c,a,!0);return{width:n.width*s.x,height:n.height*s.y,x:n.x*s.x-a.scrollLeft*s.x+u.x+d.x,y:n.y*s.y-a.scrollTop*s.y+u.y+d.y}},getDocumentElement:dt,getClippingRect:function(t){let{element:e,boundary:n,rootBoundary:o,strategy:r}=t;const i=[..."clippingAncestors"===n?vt(e)?[]:function(t,e){const n=e.get(t);if(n)return n;let o=Ot(t,[],!1).filter((t=>ht(t)&&"body"!==ut(t))),r=null;const i="fixed"===Tt(t).position;let c=i?Lt(t):t;for(;ht(c)&&!Et(c);){const e=Tt(c),n=xt(c);n||"fixed"!==e.position||(r=null),(i?!n&&!r:!n&&"static"===e.position&&r&&["absolute","fixed"].includes(r.position)||yt(c)&&!n&&Mt(t,c))?o=o.filter((t=>t!==c)):r=e,c=Lt(c)}return e.set(t,o),o}(e,this._c):[].concat(n),o],c=i[0],l=i.reduce(((t,n)=>{const o=Wt(e,n,r);return t.top=j(o.top,t.top),t.right=N(o.right,t.right),t.bottom=N(o.bottom,t.bottom),t.left=j(o.left,t.left),t}),Wt(e,c,r));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}},getOffsetParent:Nt,getElementRects:async function(t){const e=this.getOffsetParent||Nt,n=this.getDimensions,o=await n(t.floating);return{reference:Bt(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}},getClientRects:function(t){return Array.from(t.getClientRects())},getDimensions:function(t){const{width:e,height:n}=At(t);return{width:e,height:n}},getScale:St,isElement:ht,isRTL:function(t){return"rtl"===Tt(t).direction}},zt=at,_t=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var n,o;const{x:r,y:i,placement:c,middlewareData:l}=e,a=await async function(t,e){const{placement:n,platform:o,elements:r}=t,i=await(null==o.isRTL?void 0:o.isRTL(r.floating)),c=G(n),l=K(n),a="y"===tt(n),s=["left","top"].includes(c)?-1:1,u=i&&a?-1:1,f=J(e,t);let{mainAxis:d,crossAxis:p,alignmentAxis:h}="number"==typeof f?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return l&&"number"==typeof h&&(p="end"===l?-1*h:h),a?{x:p*u,y:d*s}:{x:d*s,y:p*u}}(e,t);return c===(null==(n=l.offset)?void 0:n.placement)&&null!=(o=l.arrow)&&o.alignmentOffset?{}:{x:r+a.x,y:i+a.y,data:{...a,placement:c}}}}},Ut=function(t){return void 0===t&&(t={}),{name:"autoPlacement",options:t,async fn(e){var n,o,r;const{rects:i,middlewareData:c,placement:l,platform:a,elements:s}=e,{crossAxis:u=!1,alignment:f,allowedPlacements:d=I,autoAlignment:p=!0,...h}=J(t,e),m=void 0!==f||d===I?function(t,e,n){return(t?[...n.filter((e=>K(e)===t)),...n.filter((e=>K(e)!==t))]:n.filter((t=>G(t)===t))).filter((n=>!t||K(n)===t||!!e&&ot(n)!==n))}(f||null,p,d):d,g=await at(e,h),y=(null==(n=c.autoPlacement)?void 0:n.index)||0,w=m[y];if(null==w)return{};const v=nt(w,i,await(null==a.isRTL?void 0:a.isRTL(s.floating)));if(l!==w)return{reset:{placement:m[0]}};const x=[g[G(w)],g[v[0]],g[v[1]]],b=[...(null==(o=c.autoPlacement)?void 0:o.overflows)||[],{placement:w,overflows:x}],E=m[y+1];if(E)return{data:{index:y+1,overflows:b},reset:{placement:E}};const T=b.map((t=>{const e=K(t.placement);return[t.placement,e&&u?t.overflows.slice(0,2).reduce(((t,e)=>t+e),0):t.overflows[0],t.overflows]})).sort(((t,e)=>t[1]-e[1])),C=(null==(r=T.filter((t=>t[2].slice(0,K(t[0])?2:3).every((t=>t<=0))))[0])?void 0:r[0])||T[0][0];return C!==l?{data:{index:y+1,overflows:b},reset:{placement:C}}:{}}}},Xt=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:o,placement:r,rects:i,platform:c,elements:l,middlewareData:a}=e,{element:s,padding:u=0}=J(t,e)||{};if(null==s)return{};const f=it(u),d={x:n,y:o},p=et(r),h=Z(p),m=await c.getDimensions(s),g="y"===p,y=g?"top":"left",w=g?"bottom":"right",v=g?"clientHeight":"clientWidth",x=i.reference[h]+i.reference[p]-d[p]-i.floating[h],b=d[p]-i.reference[p],E=await(null==c.getOffsetParent?void 0:c.getOffsetParent(s));let T=E?E[v]:0;T&&await(null==c.isElement?void 0:c.isElement(E))||(T=l.floating[v]||i.floating[h]);const C=x/2-b/2,L=T/2-m[h]/2-1,R=N(f[y],L),O=N(f[w],L),D=R,A=T-m[h]-O,P=T/2-m[h]/2+C,S=Y(D,P,A),$=!a.arrow&&null!=K(r)&&P!==S&&i.reference[h]/2-(P<D?R:O)-m[h]/2<0,H=$?P<D?P-D:P-A:0;return{[p]:d[p]+H,data:{[p]:S,centerOffset:P-S-H,...$&&{alignmentOffset:H}},reset:$}}}),Yt=(t,e,n)=>{const o=new Map,r={platform:jt,...n},i={...r.platform,_c:o};return(async(t,e,n)=>{const{placement:o="bottom",strategy:r="absolute",middleware:i=[],platform:c}=n,l=i.filter(Boolean),a=await(null==c.isRTL?void 0:c.isRTL(e));let s=await c.getElementRects({reference:t,floating:e,strategy:r}),{x:u,y:f}=lt(s,o,a),d=o,p={},h=0;for(let n=0;n<l.length;n++){const{name:i,fn:m}=l[n],{x:g,y:y,data:w,reset:v}=await m({x:u,y:f,initialPlacement:o,placement:d,strategy:r,middlewareData:p,rects:s,platform:c,elements:{reference:t,floating:e}});u=null!=g?g:u,f=null!=y?y:f,p={...p,[i]:{...p[i],...w}},v&&h<=50&&(h++,"object"==typeof v&&(v.placement&&(d=v.placement),v.rects&&(s=!0===v.rects?await c.getElementRects({reference:t,floating:e,strategy:r}):v.rects),({x:u,y:f}=lt(s,d,a))),n=-1)}return{x:u,y:f,placement:d,strategy:r,middlewareData:p}})(t,e,{...r,platform:i})};async function Jt(t,e){let{placement:n,offset:o}=e;const r=n[0],i=t.card.querySelector("[data-hovercard-arrow]"),c=[Gt(n)];if(i){o+=i.clientWidth,c.push(Xt({element:i}))}c.push(_t(o));const l=await Yt(t.coupdoeilElement,t.card,{placement:r,middleware:c}),{x:a,y:s,placement:u}=l;i&&function(t,e){const n=t.clientWidth,{placement:o,middlewareData:{arrow:r}}=e,i=o.split("-")[0],c=Kt[i],{x:l,y:a}=r,{borderWidth:s}=getComputedStyle(t.parentElement);Object.assign(t.style,{left:null!=l?`${l}px`:"",top:null!=a?`${a}px`:"",[c]:`calc(${-n}px + ${s})`})}(i,l),t.card.dataset.placement=u,Object.assign(t.card.style,{left:`${a}px`,top:`${s}px`})}const Gt=t=>{let e=0;return{name:"autoPlacement",async fn(n){if("auto"===n.placement)return Ut().fn(n);const{top:o,bottom:r,left:i,right:c}=await zt(n),l=o>0||r>0||i>0||c>0;return"auto"!==t[e]&&l?(e++,{reset:{placement:t[e]||"auto"}}):l?Ut().fn(n):{}}}},Kt={right:"left",left:"right",top:"bottom",bottom:"top"};async function Qt(t,{parent:n}){if(t.isOpen)return O(t),q(t.coupdoeilElement);n&&(t.parent=n,n.children.add(t));const o=function(t){if(function(t){return"click"===g(t)}(t))return{reOpening:0,actualOpening:0,fetch:0};return{fetch:r,reOpening:r+i,actualOpening:i-r}}(t),a=function(t){const e=t.hovercardController.optionsInt||=p(t),n=Object.create(d);for(const t of l)n[t]=c[t].getter(e);return n}(t.coupdoeilElement),{cache:s}=a;if(t.openingDelay=new Promise((e=>{T(t)&&s?setTimeout(e,o.reOpening):setTimeout(e,o.actualOpening)})),!T(t)||!s){if(t.fetchDelay=new Promise((t=>{setTimeout(t,o.fetch)})),await t.fetchDelay,!t.fetchDelay)return;t.fetchDelay=null;const e=x(t)?.innerHTML||await function(t){const e=h(t),n=m(t),o=document.querySelector("meta[name=csrf-token]").content;let r="/coupdoeil/hovercard";const i={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({params:n,action_name:e,authenticity_token:o})};return fetch(r,i).then((t=>{if(t.status>=400)throw"error while fetching hovercard content";return t.text()}))}(t);!function(t,e){b.set(E(t),e)}(t,e)}await t.openingDelay;const u=t.parent&&(t.parent.isClosed||t.parent.closingRequest);t.openingDelay&&!u&&(t.openingDelay=null,await async function(t,n){if(t.isOpen)return;O(t),t.card=function(t,n){const o=document.createElement("div");return o.setAttribute("role","dialog"),o.classList.add(e,"hidden"),o.style.cssText="position: absolute; left: 0; top: 0;",o.innerHTML=T(t),o.controller=t,o.dataset.placement=n.placement,o}(t,n),document.body.appendChild(t.card),n.animation&&(t.card.dataset.animation=n.animation);requestAnimationFrame((async()=>{t.card.style.opacity="0",t.card.classList.remove("hidden"),requestAnimationFrame((async()=>{await Jt(t,n),t.card.classList.add("hidden"),t.card.style.removeProperty("opacity"),requestAnimationFrame((async()=>{q(t.coupdoeilElement),delete t.coupdoeilElement.openingHovercard,t.coupdoeilElement.dataset.hovercardOpen=!0,await async function(t,e=null){t.classList.remove("hidden"),await C("enter",t,e)}(t.card,"hovercard")}))}))}))}(t,a))}class Zt extends HTMLElement{constructor(){super(),this.uniqueId=function(){const t=new Uint32Array(1);return window.crypto.getRandomValues(t),t[0]}(),this.hovercardController=new t(this)}openHovercard(){if(this.openingHovercard||this.hovercardController.isOpen)return;this.openingHovercard=!0;const t=this.closest(n)?.controller;return q(this),Qt(this.hovercardController,{parent:t})}closeHovercard(){D(this.hovercardController)}}function te(){return $.size>0}const ee=({target:t})=>{const e=t.closest("coup-doeil"),o=t.closest(n);e&&o?function(t){const e=t.hovercardController;if(y(e))return;e.isOpen?D(e):t.openHovercard()}(e):e?function(t){const e=t.hovercardController;if(y(e))return;e.isOpen?D(e):(F(),t.openHovercard())}(e):o?function(t,e){const n=t.controller;o=e,o.closest("[data-hovercard-close]")||o.dataset.hasOwnProperty("hovercardClose")?D(n):n.children.size>0&&S(n);var o}(o,t):F()};const ne=({target:t})=>{const e=t.closest("coup-doeil"),o=t.closest(n);e&&o?function(t,e){const n=t.hovercardController,o=e.controller;if(v(n))return;n.isOpen?S(n):(S(o),t.openHovercard())}(e,o):e?function(t){const e=t.hovercardController;if(v(e))return;e.isClosed?(!function(){for(const t of $.values())w(t.hovercardController)&&(D(t.hovercardController),W(t))}(),t.openHovercard()):e.closingRequest&&(O(e),q(t))}(e):o?function(t){const e=t.controller;e.closingRequest?(O(e),q(e.coupdoeilElement)):e.children.size>0&&e.children.forEach((t=>{w(t)&&P(t)}))}(o):te()&&function(){for(const t of $.values())w(t.hovercardController)&&(P(t.hovercardController),W(t))}()};document.addEventListener("DOMContentLoaded",(()=>{H(),document.addEventListener("click",ee),document.documentElement.addEventListener("mouseover",ne,{passive:!0}),window.Turbo&&(document.addEventListener("turbo:before-cache",(t=>{k()})),document.addEventListener("turbo:load",(t=>{k(),H()})))})),void 0===customElements.get("coup-doeil")&&customElements.define("coup-doeil",Zt);
1
+ class t{constructor(t){this.coupdoeilElement=t,this.card=null,this.children=new Set,this.parent=null,this.closingRequest=null}get isOpen(){return!!this.coupdoeilElement.dataset.hovercardOpen}get isClosed(){return!this.isOpen}}const e="coupdoeil--hovercard",n=`.${e}`,o=150,r=200,i={animation:{getter:function(t){return a[(56&t)>>4]}},cache:{getter:function(t){return!(8&~t)}},offset:{getter:function(t){const e=Number(BigInt(t)>>BigInt(23));if(0===e)return 0;return function(t){if("number"==typeof t)return t;if(/^(-?\d+\.?\d+)px$/.test(t))return parseFloat(t);if(/^(-?\d*\.?\d+)rem$/.test(t))return parseFloat(t)*parseFloat(getComputedStyle(document.documentElement).fontSize);return 0}(`${1&~e?"":"-"}${e>>13}.${e>>2&2047}${2&~e?"px":"rem"}`)}},placement:{getter:function(t){const e=t>>7&65535;let n=0,o=null;const r=[];for(;"auto"!==o&&n<16;)o=s[e>>n&15],r.push(o),n+=4;return r}},loading:{getter:function(t){return u[t>>1&3]}},trigger:{getter:function(t){return l[1&t]}}},c=["trigger","loading","cache","animation","placement","offset"],l=["hover","click"],a=[!1,"slide-in","fade-in","slide-out","custom"],s=["auto","top","top-start","top-end","right","right-start","right-end","bottom","bottom-start","bottom-end","left","left-start","left-end"],u=["async","preload","lazy"];const f={animation:void 0,cache:void 0,offset:void 0,placement:void 0,loading:void 0,trigger:void 0};function d(t){const e=t.getAttribute("hc");return parseInt(e,36)}function p(t){return t.coupdoeilElement.getAttribute("hc-type")}function m(t){return t.coupdoeilElement.getAttribute("hc-params")}function h(t){return function(t,e){const n=t.hovercardController.optionsInt||=d(t);return i[e].getter(n)}(t.coupdoeilElement,"trigger")}function g(t){return"click"!==h(t)}function y(t){return"hover"===h(t)}function v(t){return"hover"!==h(t)}function w(t){return t.coupdoeilElement.querySelector(".hovercard-content")}const x=new Map;function b(t){return w(t)?t.coupdoeilElement.uniqueId:p(t)+m(t)}function E(t){return x.get(b(t))}function C(){x.clear()}const L=["top","right","bottom","left"],T=["start","end"],R=L.reduce(((t,e)=>t.concat(e,e+"-"+T[0],e+"-"+T[1])),[]),H=Math.min,O=Math.max,A=Math.round,P=t=>({x:t,y:t}),S={left:"right",right:"left",bottom:"top",top:"bottom"},$={start:"end",end:"start"};function q(t,e,n){return O(t,H(e,n))}function D(t,e){return"function"==typeof t?t(e):t}function F(t){return t.split("-")[0]}function k(t){return t.split("-")[1]}function W(t){return"x"===t?"y":"x"}function I(t){return"y"===t?"height":"width"}function M(t){return["top","bottom"].includes(F(t))?"y":"x"}function B(t){return W(M(t))}function V(t,e,n){void 0===n&&(n=!1);const o=k(t),r=B(t),i=I(r);let c="x"===r?o===(n?"end":"start")?"right":"left":"start"===o?"bottom":"top";return e.reference[i]>e.floating[i]&&(c=j(c)),[c,j(c)]}function N(t){return t.replace(/start|end/g,(t=>$[t]))}function j(t){return t.replace(/left|right|bottom|top/g,(t=>S[t]))}function z(t){return"number"!=typeof t?function(t){return{top:0,right:0,bottom:0,left:0,...t}}(t):{top:t,right:t,bottom:t,left:t}}function _(t){const{x:e,y:n,width:o,height:r}=t;return{width:o,height:r,top:n,left:e,right:e+o,bottom:n+r,x:e,y:n}}function U(t,e,n){let{reference:o,floating:r}=t;const i=M(e),c=B(e),l=I(c),a=F(e),s="y"===i,u=o.x+o.width/2-r.width/2,f=o.y+o.height/2-r.height/2,d=o[l]/2-r[l]/2;let p;switch(a){case"top":p={x:u,y:o.y-r.height};break;case"bottom":p={x:u,y:o.y+o.height};break;case"right":p={x:o.x+o.width,y:f};break;case"left":p={x:o.x-r.width,y:f};break;default:p={x:o.x,y:o.y}}switch(k(e)){case"start":p[c]-=d*(n&&s?-1:1);break;case"end":p[c]+=d*(n&&s?-1:1)}return p}async function X(t,e){var n;void 0===e&&(e={});const{x:o,y:r,platform:i,rects:c,elements:l,strategy:a}=t,{boundary:s="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:d=!1,padding:p=0}=D(e,t),m=z(p),h=l[d?"floating"===f?"reference":"floating":f],g=_(await i.getClippingRect({element:null==(n=await(null==i.isElement?void 0:i.isElement(h)))||n?h:h.contextElement||await(null==i.getDocumentElement?void 0:i.getDocumentElement(l.floating)),boundary:s,rootBoundary:u,strategy:a})),y="floating"===f?{x:o,y:r,width:c.floating.width,height:c.floating.height}:c.reference,v=await(null==i.getOffsetParent?void 0:i.getOffsetParent(l.floating)),w=await(null==i.isElement?void 0:i.isElement(v))&&await(null==i.getScale?void 0:i.getScale(v))||{x:1,y:1},x=_(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:y,offsetParent:v,strategy:a}):y);return{top:(g.top-x.top+m.top)/w.y,bottom:(x.bottom-g.bottom+m.bottom)/w.y,left:(g.left-x.left+m.left)/w.x,right:(x.right-g.right+m.right)/w.x}}function Y(){return"undefined"!=typeof window}function J(t){return Q(t)?(t.nodeName||"").toLowerCase():"#document"}function G(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function K(t){var e;return null==(e=(Q(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function Q(t){return!!Y()&&(t instanceof Node||t instanceof G(t).Node)}function Z(t){return!!Y()&&(t instanceof Element||t instanceof G(t).Element)}function tt(t){return!!Y()&&(t instanceof HTMLElement||t instanceof G(t).HTMLElement)}function et(t){return!(!Y()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof G(t).ShadowRoot)}function nt(t){const{overflow:e,overflowX:n,overflowY:o,display:r}=at(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&!["inline","contents"].includes(r)}function ot(t){return["table","td","th"].includes(J(t))}function rt(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function it(t){const e=ct(),n=Z(t)?at(t):t;return"none"!==n.transform||"none"!==n.perspective||!!n.containerType&&"normal"!==n.containerType||!e&&!!n.backdropFilter&&"none"!==n.backdropFilter||!e&&!!n.filter&&"none"!==n.filter||["transform","perspective","filter"].some((t=>(n.willChange||"").includes(t)))||["paint","layout","strict","content"].some((t=>(n.contain||"").includes(t)))}function ct(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function lt(t){return["html","body","#document"].includes(J(t))}function at(t){return G(t).getComputedStyle(t)}function st(t){return Z(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function ut(t){if("html"===J(t))return t;const e=t.assignedSlot||t.parentNode||et(t)&&t.host||K(t);return et(e)?e.host:e}function ft(t){const e=ut(t);return lt(e)?t.ownerDocument?t.ownerDocument.body:t.body:tt(e)&&nt(e)?e:ft(e)}function dt(t,e,n){var o;void 0===e&&(e=[]),void 0===n&&(n=!0);const r=ft(t),i=r===(null==(o=t.ownerDocument)?void 0:o.body),c=G(r);if(i){const t=pt(c);return e.concat(c,c.visualViewport||[],nt(r)?r:[],t&&n?dt(t):[])}return e.concat(r,dt(r,[],n))}function pt(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function mt(t){const e=at(t);let n=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const r=tt(t),i=r?t.offsetWidth:n,c=r?t.offsetHeight:o,l=A(n)!==i||A(o)!==c;return l&&(n=i,o=c),{width:n,height:o,$:l}}function ht(t){return Z(t)?t:t.contextElement}function gt(t){const e=ht(t);if(!tt(e))return P(1);const n=e.getBoundingClientRect(),{width:o,height:r,$:i}=mt(e);let c=(i?A(n.width):n.width)/o,l=(i?A(n.height):n.height)/r;return c&&Number.isFinite(c)||(c=1),l&&Number.isFinite(l)||(l=1),{x:c,y:l}}const yt=P(0);function vt(t){const e=G(t);return ct()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:yt}function wt(t,e,n,o){void 0===e&&(e=!1),void 0===n&&(n=!1);const r=t.getBoundingClientRect(),i=ht(t);let c=P(1);e&&(o?Z(o)&&(c=gt(o)):c=gt(t));const l=function(t,e,n){return void 0===e&&(e=!1),!(!n||e&&n!==G(t))&&e}(i,n,o)?vt(i):P(0);let a=(r.left+l.x)/c.x,s=(r.top+l.y)/c.y,u=r.width/c.x,f=r.height/c.y;if(i){const t=G(i),e=o&&Z(o)?G(o):o;let n=t,r=pt(n);for(;r&&o&&e!==n;){const t=gt(r),e=r.getBoundingClientRect(),o=at(r),i=e.left+(r.clientLeft+parseFloat(o.paddingLeft))*t.x,c=e.top+(r.clientTop+parseFloat(o.paddingTop))*t.y;a*=t.x,s*=t.y,u*=t.x,f*=t.y,a+=i,s+=c,n=G(r),r=pt(n)}}return _({width:u,height:f,x:a,y:s})}function xt(t,e){const n=st(t).scrollLeft;return e?e.left+n:wt(K(t)).left+n}function bt(t,e,n){void 0===n&&(n=!1);const o=t.getBoundingClientRect();return{x:o.left+e.scrollLeft-(n?0:xt(t,o)),y:o.top+e.scrollTop}}function Et(t,e,n){let o;if("viewport"===e)o=function(t,e){const n=G(t),o=K(t),r=n.visualViewport;let i=o.clientWidth,c=o.clientHeight,l=0,a=0;if(r){i=r.width,c=r.height;const t=ct();(!t||t&&"fixed"===e)&&(l=r.offsetLeft,a=r.offsetTop)}return{width:i,height:c,x:l,y:a}}(t,n);else if("document"===e)o=function(t){const e=K(t),n=st(t),o=t.ownerDocument.body,r=O(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),i=O(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let c=-n.scrollLeft+xt(t);const l=-n.scrollTop;return"rtl"===at(o).direction&&(c+=O(e.clientWidth,o.clientWidth)-r),{width:r,height:i,x:c,y:l}}(K(t));else if(Z(e))o=function(t,e){const n=wt(t,!0,"fixed"===e),o=n.top+t.clientTop,r=n.left+t.clientLeft,i=tt(t)?gt(t):P(1);return{width:t.clientWidth*i.x,height:t.clientHeight*i.y,x:r*i.x,y:o*i.y}}(e,n);else{const n=vt(t);o={x:e.x-n.x,y:e.y-n.y,width:e.width,height:e.height}}return _(o)}function Ct(t,e){const n=ut(t);return!(n===e||!Z(n)||lt(n))&&("fixed"===at(n).position||Ct(n,e))}function Lt(t,e,n){const o=tt(e),r=K(e),i="fixed"===n,c=wt(t,!0,i,e);let l={scrollLeft:0,scrollTop:0};const a=P(0);if(o||!o&&!i)if(("body"!==J(e)||nt(r))&&(l=st(e)),o){const t=wt(e,!0,i,e);a.x=t.x+e.clientLeft,a.y=t.y+e.clientTop}else r&&(a.x=xt(r));const s=!r||o||i?P(0):bt(r,l);return{x:c.left+l.scrollLeft-a.x-s.x,y:c.top+l.scrollTop-a.y-s.y,width:c.width,height:c.height}}function Tt(t){return"static"===at(t).position}function Rt(t,e){if(!tt(t)||"fixed"===at(t).position)return null;if(e)return e(t);let n=t.offsetParent;return K(t)===n&&(n=n.ownerDocument.body),n}function Ht(t,e){const n=G(t);if(rt(t))return n;if(!tt(t)){let e=ut(t);for(;e&&!lt(e);){if(Z(e)&&!Tt(e))return e;e=ut(e)}return n}let o=Rt(t,e);for(;o&&ot(o)&&Tt(o);)o=Rt(o,e);return o&&lt(o)&&Tt(o)&&!it(o)?n:o||function(t){let e=ut(t);for(;tt(e)&&!lt(e);){if(it(e))return e;if(rt(e))return null;e=ut(e)}return null}(t)||n}const Ot={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:n,offsetParent:o,strategy:r}=t;const i="fixed"===r,c=K(o),l=!!e&&rt(e.floating);if(o===c||l&&i)return n;let a={scrollLeft:0,scrollTop:0},s=P(1);const u=P(0),f=tt(o);if((f||!f&&!i)&&(("body"!==J(o)||nt(c))&&(a=st(o)),tt(o))){const t=wt(o);s=gt(o),u.x=t.x+o.clientLeft,u.y=t.y+o.clientTop}const d=!c||f||i?P(0):bt(c,a,!0);return{width:n.width*s.x,height:n.height*s.y,x:n.x*s.x-a.scrollLeft*s.x+u.x+d.x,y:n.y*s.y-a.scrollTop*s.y+u.y+d.y}},getDocumentElement:K,getClippingRect:function(t){let{element:e,boundary:n,rootBoundary:o,strategy:r}=t;const i=[..."clippingAncestors"===n?rt(e)?[]:function(t,e){const n=e.get(t);if(n)return n;let o=dt(t,[],!1).filter((t=>Z(t)&&"body"!==J(t))),r=null;const i="fixed"===at(t).position;let c=i?ut(t):t;for(;Z(c)&&!lt(c);){const e=at(c),n=it(c);n||"fixed"!==e.position||(r=null),(i?!n&&!r:!n&&"static"===e.position&&r&&["absolute","fixed"].includes(r.position)||nt(c)&&!n&&Ct(t,c))?o=o.filter((t=>t!==c)):r=e,c=ut(c)}return e.set(t,o),o}(e,this._c):[].concat(n),o],c=i[0],l=i.reduce(((t,n)=>{const o=Et(e,n,r);return t.top=O(o.top,t.top),t.right=H(o.right,t.right),t.bottom=H(o.bottom,t.bottom),t.left=O(o.left,t.left),t}),Et(e,c,r));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}},getOffsetParent:Ht,getElementRects:async function(t){const e=this.getOffsetParent||Ht,n=this.getDimensions,o=await n(t.floating);return{reference:Lt(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}},getClientRects:function(t){return Array.from(t.getClientRects())},getDimensions:function(t){const{width:e,height:n}=mt(t);return{width:e,height:n}},getScale:gt,isElement:Z,isRTL:function(t){return"rtl"===at(t).direction}},At=X,Pt=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var n,o;const{x:r,y:i,placement:c,middlewareData:l}=e,a=await async function(t,e){const{placement:n,platform:o,elements:r}=t,i=await(null==o.isRTL?void 0:o.isRTL(r.floating)),c=F(n),l=k(n),a="y"===M(n),s=["left","top"].includes(c)?-1:1,u=i&&a?-1:1,f=D(e,t);let{mainAxis:d,crossAxis:p,alignmentAxis:m}="number"==typeof f?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return l&&"number"==typeof m&&(p="end"===l?-1*m:m),a?{x:p*u,y:d*s}:{x:d*s,y:p*u}}(e,t);return c===(null==(n=l.offset)?void 0:n.placement)&&null!=(o=l.arrow)&&o.alignmentOffset?{}:{x:r+a.x,y:i+a.y,data:{...a,placement:c}}}}},St=function(t){return void 0===t&&(t={}),{name:"autoPlacement",options:t,async fn(e){var n,o,r;const{rects:i,middlewareData:c,placement:l,platform:a,elements:s}=e,{crossAxis:u=!1,alignment:f,allowedPlacements:d=R,autoAlignment:p=!0,...m}=D(t,e),h=void 0!==f||d===R?function(t,e,n){return(t?[...n.filter((e=>k(e)===t)),...n.filter((e=>k(e)!==t))]:n.filter((t=>F(t)===t))).filter((n=>!t||k(n)===t||!!e&&N(n)!==n))}(f||null,p,d):d,g=await X(e,m),y=(null==(n=c.autoPlacement)?void 0:n.index)||0,v=h[y];if(null==v)return{};const w=V(v,i,await(null==a.isRTL?void 0:a.isRTL(s.floating)));if(l!==v)return{reset:{placement:h[0]}};const x=[g[F(v)],g[w[0]],g[w[1]]],b=[...(null==(o=c.autoPlacement)?void 0:o.overflows)||[],{placement:v,overflows:x}],E=h[y+1];if(E)return{data:{index:y+1,overflows:b},reset:{placement:E}};const C=b.map((t=>{const e=k(t.placement);return[t.placement,e&&u?t.overflows.slice(0,2).reduce(((t,e)=>t+e),0):t.overflows[0],t.overflows]})).sort(((t,e)=>t[1]-e[1])),L=(null==(r=C.filter((t=>t[2].slice(0,k(t[0])?2:3).every((t=>t<=0))))[0])?void 0:r[0])||C[0][0];return L!==l?{data:{index:y+1,overflows:b},reset:{placement:L}}:{}}}},$t=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:o,placement:r,rects:i,platform:c,elements:l,middlewareData:a}=e,{element:s,padding:u=0}=D(t,e)||{};if(null==s)return{};const f=z(u),d={x:n,y:o},p=B(r),m=I(p),h=await c.getDimensions(s),g="y"===p,y=g?"top":"left",v=g?"bottom":"right",w=g?"clientHeight":"clientWidth",x=i.reference[m]+i.reference[p]-d[p]-i.floating[m],b=d[p]-i.reference[p],E=await(null==c.getOffsetParent?void 0:c.getOffsetParent(s));let C=E?E[w]:0;C&&await(null==c.isElement?void 0:c.isElement(E))||(C=l.floating[w]||i.floating[m]);const L=x/2-b/2,T=C/2-h[m]/2-1,R=H(f[y],T),O=H(f[v],T),A=R,P=C-h[m]-O,S=C/2-h[m]/2+L,$=q(A,S,P),F=!a.arrow&&null!=k(r)&&S!==$&&i.reference[m]/2-(S<A?R:O)-h[m]/2<0,W=F?S<A?S-A:S-P:0;return{[p]:d[p]+W,data:{[p]:$,centerOffset:S-$-W,...F&&{alignmentOffset:W}},reset:F}}}),qt=(t,e,n)=>{const o=new Map,r={platform:Ot,...n},i={...r.platform,_c:o};return(async(t,e,n)=>{const{placement:o="bottom",strategy:r="absolute",middleware:i=[],platform:c}=n,l=i.filter(Boolean),a=await(null==c.isRTL?void 0:c.isRTL(e));let s=await c.getElementRects({reference:t,floating:e,strategy:r}),{x:u,y:f}=U(s,o,a),d=o,p={},m=0;for(let n=0;n<l.length;n++){const{name:i,fn:h}=l[n],{x:g,y:y,data:v,reset:w}=await h({x:u,y:f,initialPlacement:o,placement:d,strategy:r,middlewareData:p,rects:s,platform:c,elements:{reference:t,floating:e}});u=null!=g?g:u,f=null!=y?y:f,p={...p,[i]:{...p[i],...v}},w&&m<=50&&(m++,"object"==typeof w&&(w.placement&&(d=w.placement),w.rects&&(s=!0===w.rects?await c.getElementRects({reference:t,floating:e,strategy:r}):w.rects),({x:u,y:f}=U(s,d,a))),n=-1)}return{x:u,y:f,placement:d,strategy:r,middlewareData:p}})(t,e,{...r,platform:i})};async function Dt(t,e,n){const o=e.dataset,r=n?`${n}-${t}`:t;let i=`transition${t.charAt(0).toUpperCase()+t.slice(1)}`;const c=o[i]?o[i].split(" "):[r],l=o[`${i}Start`]?o[`${i}Start`].split(" "):[`${r}-start`],a=o[`${i}End`]?o[`${i}End`].split(" "):[`${r}-end`];Ft(e,c),Ft(e,l),await new Promise((t=>{requestAnimationFrame((()=>{requestAnimationFrame(t)}))})),kt(e,l),Ft(e,a),await function(t){return new Promise((e=>{const n=getComputedStyle(t).transitionDuration.split(",")[0],o=1e3*Number(n.replace("s",""));setTimeout((()=>{e()}),o)}))}(e),kt(e,a),kt(e,c)}function Ft(t,e){t.classList.add(...e)}function kt(t,e){t.classList.remove(...e)}const Wt=new Map;function It(t){Wt.set(t.uniqueId,t)}function Mt(t){Wt.delete(t.uniqueId)}function Bt(t){!function(t){console.log("deleting openingHovercard: ",t.coupdoeilElement.uniqueId),delete t.coupdoeilElement.openingHovercard}(t),Vt(t)}function Vt(t){clearTimeout(t.closingRequest),t.closingRequest=null,It(t.coupdoeilElement)}function Nt(t,e=!0){console.log("closing: ",t.coupdoeilElement.uniqueId),console.log({closing:t.closing,isClosed:t.isClosed&&!t.coupdoeilElement.openingHovercard}),t.closing||t.isClosed&&!t.coupdoeilElement.openingHovercard||(t.closing=!0,Bt(t),t.children.forEach((t=>{Nt(t)})),function(t){t.parent&&(t.parent.children.delete(t),t.parent=null)}(t),e&&t.card&&t.card.dataset.animation?async function(t){await async function(t,e=null){await Dt("leave",t,e),t.classList.add("hidden")}(t.card,"hovercard"),jt(t)}(t):jt(t))}function jt(t){t.card&&(t.card.remove(),t.card=null),delete t.closing,delete t.coupdoeilElement.dataset.hovercardOpen}function zt(t){Nt(t,!1)}function _t(t){Bt(t),t.closingRequest=setTimeout((()=>{Nt(t)}),o)}function Ut(t){t.children.forEach((t=>{Nt(t)}))}function Xt(){for(const t of Wt.values())Nt(t.hovercardController),Mt(t)}function Yt(){for(const t of Wt.values())clearHovercard(t.hovercardController),Mt(t)}async function Jt(t,e,n){let{placement:o,offset:r}=n;const i=o[0],c=e.querySelector("[data-hovercard-arrow]"),l=[Gt(o)];if(c){r+=c.clientWidth,l.push($t({element:c}))}l.push(Pt(r));const a=await qt(t,e,{placement:i,middleware:l}),{x:s,y:u,placement:f}=a;c&&function(t,e){const n=t.clientWidth,{placement:o,middlewareData:{arrow:r}}=e,i=o.split("-")[0],c=Kt[i],{x:l,y:a}=r,{borderWidth:s}=getComputedStyle(t.parentElement);Object.assign(t.style,{left:null!=l?`${l}px`:"",top:null!=a?`${a}px`:"",[c]:`calc(${-n}px + ${s})`})}(c,a),e.dataset.placement=f,Object.assign(e.style,{left:`${s}px`,top:`${u}px`})}const Gt=t=>{let e=0;return{name:"autoPlacement",async fn(n){if("auto"===n.placement)return St().fn(n);const{top:o,bottom:r,left:i,right:c}=await At(n),l=o>0||r>0||i>0||c>0;return"auto"!==t[e]&&l?(e++,{reset:{placement:t[e]||"auto"}}):l?St().fn(n):{}}}},Kt={right:"left",left:"right",top:"bottom",bottom:"top"};async function Qt(t,e,n){return new Promise((o=>{setTimeout((async()=>{if(t.coupdoeilElement.openingHovercard){if(!1===e.cache||e.cache&&!E(t)){let n;n="preload"===e.loading?w(t).innerHTML:await function(t){const e=p(t),n=m(t),o=document.querySelector("meta[name=csrf-token]").content,r={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({params:n,action_name:e,authenticity_token:o})};return fetch("/coupdoeil/hovercard",r).then((t=>{if(t.status>=400)throw"error while fetching hovercard content";return t.text()}))}(t),function(t,e){x.set(b(t),e)}(t,n)}o()}}),n.fetch)}))}async function Zt(t,{parent:n}){if(console.log("opening: ",t.coupdoeilElement.uniqueId),t.isOpen)return Vt(t);n&&(t.parent=n,n.children.add(t));const o=function(t){if(function(t){return"click"===h(t)}(t))return{fetch:0,opening:0};let e;return e=r/2,{fetch:e,opening:r}}(t),l=function(t){const e=t.hovercardController.optionsInt||=d(t),n=Object.create(f);for(const t of c)n[t]=i[t].getter(e);return n}(t.coupdoeilElement),a=new Promise((t=>setTimeout(t,o.opening))),s=Qt(t,l,o);await Promise.all([s,a]);const u=t.parent&&(t.parent.isClosed||t.parent.closingRequest);t.coupdoeilElement.openingHovercard&&!u&&await async function(t,n){if(t.isOpen)return;Vt(t),t.card=function(t,n){const o=document.createElement("div");return o.setAttribute("role","dialog"),o.classList.add(e,"hidden"),o.style.cssText="position: absolute; left: 0; top: 0;",o.innerHTML=E(t),o.controller=t,o.dataset.placement=n.placement,o}(t,n),document.body.appendChild(t.card),n.animation&&(t.card.dataset.animation=n.animation);requestAnimationFrame((async()=>{if(!t.coupdoeilElement.openingHovercard)return zt(t);t.card.style.opacity="0",t.card.classList.remove("hidden"),requestAnimationFrame((async()=>{if(!t.coupdoeilElement.openingHovercard)return zt(t);await Jt(t.coupdoeilElement,t.card,n),t.card.classList.add("hidden"),t.card.style.removeProperty("opacity"),requestAnimationFrame((async()=>{if(!t.coupdoeilElement.openingHovercard)return zt(t);It(t.coupdoeilElement),delete t.coupdoeilElement.openingHovercard,t.coupdoeilElement.dataset.hovercardOpen=!0,await async function(t,e=null){t.classList.remove("hidden"),await Dt("enter",t,e)}(t.card,"hovercard")}))}))}))}(t,l)}class te extends HTMLElement{constructor(){super(),this.uniqueId=function(){const t=new Uint32Array(1);return window.crypto.getRandomValues(t),t[0]}(),this.hovercardController=new t(this)}openHovercard(){if(this.openingHovercard||this.hovercardController.isOpen)return;this.openingHovercard=!0;const t=this.closest(n)?.controller;return It(this),Zt(this.hovercardController,{parent:t})}closeHovercard(){Nt(this.hovercardController)}}function ee(){return Wt.size>0}const ne=({target:t})=>{const e=t.closest("coup-doeil"),o=t.closest(n);e&&o?function(t){const e=t.hovercardController;if(g(e))return;e.isOpen?Nt(e):t.openHovercard()}(e):e?function(t){const e=t.hovercardController;if(g(e))return;e.isOpen?Nt(e):(Xt(),t.openHovercard())}(e):o?function(t,e){const n=t.controller;o=e,o.closest("[data-hovercard-close]")||o.dataset.hasOwnProperty("hovercardClose")?Nt(n):n.children.size>0&&Ut(n);var o}(o,t):Xt()};const oe=({target:t})=>{const e=t.closest("coup-doeil"),o=t.closest(n);e&&o?function(t,e){const n=t.hovercardController,o=e.controller;if(v(n))return;n.isOpen?Ut(n):(Ut(o),t.openHovercard())}(e,o):e?function(t){const e=t.hovercardController;if(v(e))return;e.isClosed?(!function(){for(const t of Wt.values())y(t.hovercardController)&&(Nt(t.hovercardController),Mt(t))}(),t.openHovercard()):e.closingRequest&&(Vt(e),It(t))}(e):o?function(t){const e=t.controller;e.closingRequest?(Vt(e),It(e.coupdoeilElement)):e.children.size>0&&e.children.forEach((t=>{y(t)&&_t(t)}))}(o):ee()&&function(){for(const t of Wt.values())y(t.hovercardController)&&(_t(t.hovercardController),Mt(t))}()};document.addEventListener("DOMContentLoaded",(()=>{C(),document.addEventListener("click",ne),document.documentElement.addEventListener("mouseover",oe,{passive:!0}),window.Turbo&&(document.addEventListener("turbo:before-cache",(t=>{Yt()})),document.addEventListener("turbo:load",(t=>{Yt(),C()})))})),void 0===customElements.get("coup-doeil")&&customElements.define("coup-doeil",te);
2
2
  //# sourceMappingURL=coupdoeil.min.js.map