coupdoeil 1.0.0.pre.beta.2 → 1.0.0.pre.beta.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed6dba2c7479bf3bc8c8bc7a7dc64ff2337e48bfcc73f1676155b299397abfa7
4
- data.tar.gz: 517aedf83960f882ded74e7c1ff9af8aa8fcf965c5a708ea764b1fb481af8752
3
+ metadata.gz: e2ebf522828aa33fb0f943d7cbf3dc3db3f9471920160b14bd277943326bf820
4
+ data.tar.gz: 782ef7753a18dbb3412a79b2c2198cea52f8b5126d0b1db07bb4357698afda91
5
5
  SHA512:
6
- metadata.gz: 0dcbb4dffc044a7b211ab4e34b0b174ed4a1af787f9838ec16de7c5295c359f0646e161d0562c2bd7971cac655edbaaefac98b184b3dd0a62e6474052351e158
7
- data.tar.gz: abed2844c081804342c98eddb10898bf74a1f2c8341c232c809c04474e91bc5577b8f48ece9be506309eaa8f2cf75c7472ba8dcb0e51e9881c646f3d8fec8755
6
+ metadata.gz: da6adbf61cdfaa30ae1b219102257abb54af09329a702d51f90bf04ceffbb088571adbec2f6dc24de7033bd3bcddc0eeab49bed22f4332e1d4ad6d804c302c2d
7
+ data.tar.gz: 92d42e920cde5415a9e8c8c4ff71bb4ed7d9ad3cd56d29c5d7bc7fab9df15f05aeb5303af61a5f96f73d0fb5b87f3906d5430a40bb3562630f5e8a6fc9f7c8ac
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
+ ### v1.0.0-beta.3
4
+ - change `coupdoeil_popover_tag` helper signature to disambiguate options and attributes, following common rails helpers signature. (8910538)
5
+ - better documentation for `options_parser.js` (26bab97)
6
+ - improve offset option validation (fd8259d)
7
+ - OptionsSet#validate! is a no-op outside local envs (dev, test) (fd8259d)
8
+ - more efficient and robust action_methods definition for popover (9c878e2)
9
+ - documentations fixes and updates (431da72, aab026b) (feat guillaume@kuartz.fr (afef027))
10
+ - fix gemspec changelog uri (b65c7d0)
11
+ - add CONTRIBUTING.md (241d02e) and add it to README (795a7c4)
12
+
3
13
  ### v1.0.0-beta.2
4
14
  - change hovercard naming for popover
5
15
 
data/README.md CHANGED
@@ -74,17 +74,21 @@ parameterized ActionMailer (see [Why does it look like a mailer?](https://coupdo
74
74
 
75
75
  This gem also tries to handle all known issues of such popovers, such as
76
76
  the user's mouse quickly leaving and re-entering popover without closing it,
77
- preventing opening of an popover if mouse did not stop on it, etc.
77
+ preventing opening of a popover if mouse did not stop on it, etc.
78
78
 
79
79
  ### Performances
80
80
 
81
- By default, an popover content is not loaded until it is needed.
81
+ By default, a popover content is not loaded until it is needed.
82
82
  It means the DOM is not cluttered with 'maybe to be used' HTML, hidden in template tags or data-attributes.
83
83
  However, params have to be present in HTML so they are sent for rendering the popover (eg: a record id),
84
84
  so try passing as few as required to build it later during render.
85
- Also, popovers are cached so the fetch happens only the first time an popover is open.
85
+ Also, popovers are cached so the fetch happens only the first time a popover is open.
86
86
 
87
87
  When needed, popovers can still be preloaded and included in DOM on initial page load. See [preload option](https://coupdoeil.org/options/loading.html).
88
88
 
89
89
  ## Licence
90
90
  Coupdoeil is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT)
91
+
92
+ ## Contributing
93
+ This repository is not yet opened for contributions as the gem's internals are still subject to significant changes, although I garantee no breaking change while refactoring.
94
+ However, issues are much welcomed!
@@ -76,8 +76,8 @@ function getOffset(optionsInt) {
76
76
  if (offsetBits === 0) return 0;
77
77
  const isNegative = (offsetBits & 1) === 1;
78
78
  const isREM = (offsetBits & 2) === 2;
79
- const decimals = offsetBits >> 2 & 2047;
80
- const integer = offsetBits >> 2 + 11;
79
+ const decimals = offsetBits >> 2 & 1023;
80
+ const integer = offsetBits >> 12;
81
81
  const CSSSize = `${isNegative ? "-" : ""}${integer}.${decimals}${isREM ? "rem" : "px"}`;
82
82
  return parseCSSSize(CSSSize);
83
83
  }
@@ -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}get isOpen(){return!!this.coupdoeilElement.dataset.popoverOpen}get isClosed(){return!this.isOpen}}const e="coupdoeil--popover",n=`.${e}`,o={animation:{getter:function(t){return l[t>>5&7]}},cache:{getter:function(t){return!(8&~t)}},loading:{getter:function(t){return s[t>>1&3]}},offset:{getter:function(t){const e=Number(BigInt(t)>>BigInt(24));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"}`)}},openingDelay:{getter:function(t){return 1==(t>>4&1)}},placement:{getter:function(t){const e=t>>8&65535;let n=0,o=null;const i=[];for(;"auto"!==o&&n<16;)o=c[e>>n&15],i.push(o),n+=4;return i}},trigger:{getter:function(t){return r[1&t]}}},i=["trigger","loading","cache","openingDelay","animation","placement","offset"],r=["hover","click"],l=[!1,"slide-in","fade-in","slide-out","custom"],c=["auto","top","top-start","top-end","right","right-start","right-end","bottom","bottom-start","bottom-end","left","left-start","left-end"],s=["async","preload","lazy"];const a={animation:void 0,cache:void 0,loading:void 0,offset:void 0,openingDelay:void 0,placement:void 0,trigger:void 0};function u(t){const e=t.getAttribute("popover-options");return parseInt(e,36)}function f(t){return t.coupdoeilElement.getAttribute("popover-type")}function d(t){return t.coupdoeilElement.getAttribute("popover-params")}function p(t){return function(t,e){const n=t.popoverController.optionsInt||=u(t);return o[e].getter(n)}(t.coupdoeilElement,"trigger")}function m(t){return"click"!==p(t)}function h(t){return"hover"===p(t)}function g(t){return"hover"!==p(t)}function y(t){return t.coupdoeilElement.querySelector(".popover-content")}const v=new Map;function w(t){return y(t)?t.coupdoeilElement.uniqueId:f(t)+d(t)}function x(t){return v.get(w(t))}function b(){v.clear()}const E=["top","right","bottom","left"],C=["start","end"],L=E.reduce(((t,e)=>t.concat(e,e+"-"+C[0],e+"-"+C[1])),[]),T=Math.min,P=Math.max,R=Math.round,O=t=>({x:t,y:t}),A={left:"right",right:"left",bottom:"top",top:"bottom"},D={start:"end",end:"start"};function S(t,e,n){return P(t,T(e,n))}function $(t,e){return"function"==typeof t?t(e):t}function q(t){return t.split("-")[0]}function k(t){return t.split("-")[1]}function F(t){return"x"===t?"y":"x"}function H(t){return"y"===t?"height":"width"}function W(t){return["top","bottom"].includes(q(t))?"y":"x"}function M(t){return F(W(t))}function B(t,e,n){void 0===n&&(n=!1);const o=k(t),i=M(t),r=H(i);let l="x"===i?o===(n?"end":"start")?"right":"left":"start"===o?"bottom":"top";return e.reference[r]>e.floating[r]&&(l=V(l)),[l,V(l)]}function I(t){return t.replace(/start|end/g,(t=>D[t]))}function V(t){return t.replace(/left|right|bottom|top/g,(t=>A[t]))}function N(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 j(t){const{x:e,y:n,width:o,height:i}=t;return{width:o,height:i,top:n,left:e,right:e+o,bottom:n+i,x:e,y:n}}function z(t,e,n){let{reference:o,floating:i}=t;const r=W(e),l=M(e),c=H(l),s=q(e),a="y"===r,u=o.x+o.width/2-i.width/2,f=o.y+o.height/2-i.height/2,d=o[c]/2-i[c]/2;let p;switch(s){case"top":p={x:u,y:o.y-i.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-i.width,y:f};break;default:p={x:o.x,y:o.y}}switch(k(e)){case"start":p[l]-=d*(n&&a?-1:1);break;case"end":p[l]+=d*(n&&a?-1:1)}return p}async function _(t,e){var n;void 0===e&&(e={});const{x:o,y:i,platform:r,rects:l,elements:c,strategy:s}=t,{boundary:a="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:d=!1,padding:p=0}=$(e,t),m=N(p),h=c[d?"floating"===f?"reference":"floating":f],g=j(await r.getClippingRect({element:null==(n=await(null==r.isElement?void 0:r.isElement(h)))||n?h:h.contextElement||await(null==r.getDocumentElement?void 0:r.getDocumentElement(c.floating)),boundary:a,rootBoundary:u,strategy:s})),y="floating"===f?{x:o,y:i,width:l.floating.width,height:l.floating.height}:l.reference,v=await(null==r.getOffsetParent?void 0:r.getOffsetParent(c.floating)),w=await(null==r.isElement?void 0:r.isElement(v))&&await(null==r.getScale?void 0:r.getScale(v))||{x:1,y:1},x=j(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:c,rect:y,offsetParent:v,strategy:s}):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 U(){return"undefined"!=typeof window}function X(t){return G(t)?(t.nodeName||"").toLowerCase():"#document"}function Y(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function J(t){var e;return null==(e=(G(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function G(t){return!!U()&&(t instanceof Node||t instanceof Y(t).Node)}function K(t){return!!U()&&(t instanceof Element||t instanceof Y(t).Element)}function Q(t){return!!U()&&(t instanceof HTMLElement||t instanceof Y(t).HTMLElement)}function Z(t){return!(!U()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof Y(t).ShadowRoot)}function tt(t){const{overflow:e,overflowX:n,overflowY:o,display:i}=lt(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&!["inline","contents"].includes(i)}function et(t){return["table","td","th"].includes(X(t))}function nt(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function ot(t){const e=it(),n=K(t)?lt(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 it(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function rt(t){return["html","body","#document"].includes(X(t))}function lt(t){return Y(t).getComputedStyle(t)}function ct(t){return K(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function st(t){if("html"===X(t))return t;const e=t.assignedSlot||t.parentNode||Z(t)&&t.host||J(t);return Z(e)?e.host:e}function at(t){const e=st(t);return rt(e)?t.ownerDocument?t.ownerDocument.body:t.body:Q(e)&&tt(e)?e:at(e)}function ut(t,e,n){var o;void 0===e&&(e=[]),void 0===n&&(n=!0);const i=at(t),r=i===(null==(o=t.ownerDocument)?void 0:o.body),l=Y(i);if(r){const t=ft(l);return e.concat(l,l.visualViewport||[],tt(i)?i:[],t&&n?ut(t):[])}return e.concat(i,ut(i,[],n))}function ft(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function dt(t){const e=lt(t);let n=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const i=Q(t),r=i?t.offsetWidth:n,l=i?t.offsetHeight:o,c=R(n)!==r||R(o)!==l;return c&&(n=r,o=l),{width:n,height:o,$:c}}function pt(t){return K(t)?t:t.contextElement}function mt(t){const e=pt(t);if(!Q(e))return O(1);const n=e.getBoundingClientRect(),{width:o,height:i,$:r}=dt(e);let l=(r?R(n.width):n.width)/o,c=(r?R(n.height):n.height)/i;return l&&Number.isFinite(l)||(l=1),c&&Number.isFinite(c)||(c=1),{x:l,y:c}}const ht=O(0);function gt(t){const e=Y(t);return it()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:ht}function yt(t,e,n,o){void 0===e&&(e=!1),void 0===n&&(n=!1);const i=t.getBoundingClientRect(),r=pt(t);let l=O(1);e&&(o?K(o)&&(l=mt(o)):l=mt(t));const c=function(t,e,n){return void 0===e&&(e=!1),!(!n||e&&n!==Y(t))&&e}(r,n,o)?gt(r):O(0);let s=(i.left+c.x)/l.x,a=(i.top+c.y)/l.y,u=i.width/l.x,f=i.height/l.y;if(r){const t=Y(r),e=o&&K(o)?Y(o):o;let n=t,i=ft(n);for(;i&&o&&e!==n;){const t=mt(i),e=i.getBoundingClientRect(),o=lt(i),r=e.left+(i.clientLeft+parseFloat(o.paddingLeft))*t.x,l=e.top+(i.clientTop+parseFloat(o.paddingTop))*t.y;s*=t.x,a*=t.y,u*=t.x,f*=t.y,s+=r,a+=l,n=Y(i),i=ft(n)}}return j({width:u,height:f,x:s,y:a})}function vt(t,e){const n=ct(t).scrollLeft;return e?e.left+n:yt(J(t)).left+n}function wt(t,e,n){void 0===n&&(n=!1);const o=t.getBoundingClientRect();return{x:o.left+e.scrollLeft-(n?0:vt(t,o)),y:o.top+e.scrollTop}}function xt(t,e,n){let o;if("viewport"===e)o=function(t,e){const n=Y(t),o=J(t),i=n.visualViewport;let r=o.clientWidth,l=o.clientHeight,c=0,s=0;if(i){r=i.width,l=i.height;const t=it();(!t||t&&"fixed"===e)&&(c=i.offsetLeft,s=i.offsetTop)}return{width:r,height:l,x:c,y:s}}(t,n);else if("document"===e)o=function(t){const e=J(t),n=ct(t),o=t.ownerDocument.body,i=P(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),r=P(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let l=-n.scrollLeft+vt(t);const c=-n.scrollTop;return"rtl"===lt(o).direction&&(l+=P(e.clientWidth,o.clientWidth)-i),{width:i,height:r,x:l,y:c}}(J(t));else if(K(e))o=function(t,e){const n=yt(t,!0,"fixed"===e),o=n.top+t.clientTop,i=n.left+t.clientLeft,r=Q(t)?mt(t):O(1);return{width:t.clientWidth*r.x,height:t.clientHeight*r.y,x:i*r.x,y:o*r.y}}(e,n);else{const n=gt(t);o={x:e.x-n.x,y:e.y-n.y,width:e.width,height:e.height}}return j(o)}function bt(t,e){const n=st(t);return!(n===e||!K(n)||rt(n))&&("fixed"===lt(n).position||bt(n,e))}function Et(t,e,n){const o=Q(e),i=J(e),r="fixed"===n,l=yt(t,!0,r,e);let c={scrollLeft:0,scrollTop:0};const s=O(0);if(o||!o&&!r)if(("body"!==X(e)||tt(i))&&(c=ct(e)),o){const t=yt(e,!0,r,e);s.x=t.x+e.clientLeft,s.y=t.y+e.clientTop}else i&&(s.x=vt(i));const a=!i||o||r?O(0):wt(i,c);return{x:l.left+c.scrollLeft-s.x-a.x,y:l.top+c.scrollTop-s.y-a.y,width:l.width,height:l.height}}function Ct(t){return"static"===lt(t).position}function Lt(t,e){if(!Q(t)||"fixed"===lt(t).position)return null;if(e)return e(t);let n=t.offsetParent;return J(t)===n&&(n=n.ownerDocument.body),n}function Tt(t,e){const n=Y(t);if(nt(t))return n;if(!Q(t)){let e=st(t);for(;e&&!rt(e);){if(K(e)&&!Ct(e))return e;e=st(e)}return n}let o=Lt(t,e);for(;o&&et(o)&&Ct(o);)o=Lt(o,e);return o&&rt(o)&&Ct(o)&&!ot(o)?n:o||function(t){let e=st(t);for(;Q(e)&&!rt(e);){if(ot(e))return e;if(nt(e))return null;e=st(e)}return null}(t)||n}const Pt={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:n,offsetParent:o,strategy:i}=t;const r="fixed"===i,l=J(o),c=!!e&&nt(e.floating);if(o===l||c&&r)return n;let s={scrollLeft:0,scrollTop:0},a=O(1);const u=O(0),f=Q(o);if((f||!f&&!r)&&(("body"!==X(o)||tt(l))&&(s=ct(o)),Q(o))){const t=yt(o);a=mt(o),u.x=t.x+o.clientLeft,u.y=t.y+o.clientTop}const d=!l||f||r?O(0):wt(l,s,!0);return{width:n.width*a.x,height:n.height*a.y,x:n.x*a.x-s.scrollLeft*a.x+u.x+d.x,y:n.y*a.y-s.scrollTop*a.y+u.y+d.y}},getDocumentElement:J,getClippingRect:function(t){let{element:e,boundary:n,rootBoundary:o,strategy:i}=t;const r=[..."clippingAncestors"===n?nt(e)?[]:function(t,e){const n=e.get(t);if(n)return n;let o=ut(t,[],!1).filter((t=>K(t)&&"body"!==X(t))),i=null;const r="fixed"===lt(t).position;let l=r?st(t):t;for(;K(l)&&!rt(l);){const e=lt(l),n=ot(l);n||"fixed"!==e.position||(i=null),(r?!n&&!i:!n&&"static"===e.position&&i&&["absolute","fixed"].includes(i.position)||tt(l)&&!n&&bt(t,l))?o=o.filter((t=>t!==l)):i=e,l=st(l)}return e.set(t,o),o}(e,this._c):[].concat(n),o],l=r[0],c=r.reduce(((t,n)=>{const o=xt(e,n,i);return t.top=P(o.top,t.top),t.right=T(o.right,t.right),t.bottom=T(o.bottom,t.bottom),t.left=P(o.left,t.left),t}),xt(e,l,i));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}},getOffsetParent:Tt,getElementRects:async function(t){const e=this.getOffsetParent||Tt,n=this.getDimensions,o=await n(t.floating);return{reference:Et(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}=dt(t);return{width:e,height:n}},getScale:mt,isElement:K,isRTL:function(t){return"rtl"===lt(t).direction}},Rt=_,Ot=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var n,o;const{x:i,y:r,placement:l,middlewareData:c}=e,s=await async function(t,e){const{placement:n,platform:o,elements:i}=t,r=await(null==o.isRTL?void 0:o.isRTL(i.floating)),l=q(n),c=k(n),s="y"===W(n),a=["left","top"].includes(l)?-1:1,u=r&&s?-1:1,f=$(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 c&&"number"==typeof m&&(p="end"===c?-1*m:m),s?{x:p*u,y:d*a}:{x:d*a,y:p*u}}(e,t);return l===(null==(n=c.offset)?void 0:n.placement)&&null!=(o=c.arrow)&&o.alignmentOffset?{}:{x:i+s.x,y:r+s.y,data:{...s,placement:l}}}}},At=function(t){return void 0===t&&(t={}),{name:"autoPlacement",options:t,async fn(e){var n,o,i;const{rects:r,middlewareData:l,placement:c,platform:s,elements:a}=e,{crossAxis:u=!1,alignment:f,allowedPlacements:d=L,autoAlignment:p=!0,...m}=$(t,e),h=void 0!==f||d===L?function(t,e,n){return(t?[...n.filter((e=>k(e)===t)),...n.filter((e=>k(e)!==t))]:n.filter((t=>q(t)===t))).filter((n=>!t||k(n)===t||!!e&&I(n)!==n))}(f||null,p,d):d,g=await _(e,m),y=(null==(n=l.autoPlacement)?void 0:n.index)||0,v=h[y];if(null==v)return{};const w=B(v,r,await(null==s.isRTL?void 0:s.isRTL(a.floating)));if(c!==v)return{reset:{placement:h[0]}};const x=[g[q(v)],g[w[0]],g[w[1]]],b=[...(null==(o=l.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])),T=(null==(i=C.filter((t=>t[2].slice(0,k(t[0])?2:3).every((t=>t<=0))))[0])?void 0:i[0])||C[0][0];return T!==c?{data:{index:y+1,overflows:b},reset:{placement:T}}:{}}}},Dt=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:o,placement:i,rects:r,platform:l,elements:c,middlewareData:s}=e,{element:a,padding:u=0}=$(t,e)||{};if(null==a)return{};const f=N(u),d={x:n,y:o},p=M(i),m=H(p),h=await l.getDimensions(a),g="y"===p,y=g?"top":"left",v=g?"bottom":"right",w=g?"clientHeight":"clientWidth",x=r.reference[m]+r.reference[p]-d[p]-r.floating[m],b=d[p]-r.reference[p],E=await(null==l.getOffsetParent?void 0:l.getOffsetParent(a));let C=E?E[w]:0;C&&await(null==l.isElement?void 0:l.isElement(E))||(C=c.floating[w]||r.floating[m]);const L=x/2-b/2,P=C/2-h[m]/2-1,R=T(f[y],P),O=T(f[v],P),A=R,D=C-h[m]-O,q=C/2-h[m]/2+L,F=S(A,q,D),W=!s.arrow&&null!=k(i)&&q!==F&&r.reference[m]/2-(q<A?R:O)-h[m]/2<0,B=W?q<A?q-A:q-D:0;return{[p]:d[p]+B,data:{[p]:F,centerOffset:q-F-B,...W&&{alignmentOffset:B}},reset:W}}}),St=(t,e,n)=>{const o=new Map,i={platform:Pt,...n},r={...i.platform,_c:o};return(async(t,e,n)=>{const{placement:o="bottom",strategy:i="absolute",middleware:r=[],platform:l}=n,c=r.filter(Boolean),s=await(null==l.isRTL?void 0:l.isRTL(e));let a=await l.getElementRects({reference:t,floating:e,strategy:i}),{x:u,y:f}=z(a,o,s),d=o,p={},m=0;for(let n=0;n<c.length;n++){const{name:r,fn:h}=c[n],{x:g,y:y,data:v,reset:w}=await h({x:u,y:f,initialPlacement:o,placement:d,strategy:i,middlewareData:p,rects:a,platform:l,elements:{reference:t,floating:e}});u=null!=g?g:u,f=null!=y?y:f,p={...p,[r]:{...p[r],...v}},w&&m<=50&&(m++,"object"==typeof w&&(w.placement&&(d=w.placement),w.rects&&(a=!0===w.rects?await l.getElementRects({reference:t,floating:e,strategy:i}):w.rects),({x:u,y:f}=z(a,d,s))),n=-1)}return{x:u,y:f,placement:d,strategy:i,middlewareData:p}})(t,e,{...i,platform:r})};async function $t(t,e,n){let{placement:o,offset:i}=n;const r=o[0],l=e.querySelector("[data-popover-arrow]"),c=[qt(o)];if(l){i+=l.clientWidth,c.push(Dt({element:l}))}c.push(Ot(i));const s=await St(t,e,{placement:r,middleware:c}),{x:a,y:u,placement:f}=s;l&&function(t,e){const n=t.clientWidth,{placement:o,middlewareData:{arrow:i}}=e,r=o.split("-")[0],l=kt[r],{x:c,y:s}=i,{borderWidth:a}=getComputedStyle(t.parentElement);Object.assign(t.style,{left:null!=c?`${c}px`:"",top:null!=s?`${s}px`:"",[l]:`calc(${-n}px + ${a})`})}(l,s),e.dataset.placement=f,Object.assign(e.style,{left:`${a}px`,top:`${u}px`})}const qt=t=>{let e=0;return{name:"autoPlacement",async fn(n){if("auto"===n.placement)return At().fn(n);const{top:o,bottom:i,left:r,right:l}=await Rt(n),c=o>0||i>0||r>0||l>0;return"auto"!==t[e]&&c?(e++,{reset:{placement:t[e]||"auto"}}):c?At().fn(n):{}}}},kt={right:"left",left:"right",top:"bottom",bottom:"top"};async function Ft(t,e,n){const o=e.dataset,i=n?`${n}-${t}`:t;let r=`transition${t.charAt(0).toUpperCase()+t.slice(1)}`;const l=o[r]?o[r].split(" "):[i],c=o[`${r}Start`]?o[`${r}Start`].split(" "):[`${i}-start`],s=o[`${r}End`]?o[`${r}End`].split(" "):[`${i}-end`];Ht(e,l),Ht(e,c),await new Promise((t=>{requestAnimationFrame((()=>{requestAnimationFrame(t)}))})),Wt(e,c),Ht(e,s),await function(t){return new Promise((e=>{const n=getComputedStyle(t).transitionDuration.split(",")[0],o=1e3*Number(n.replace("s",""));setTimeout((()=>{e()}),o)}))}(e),Wt(e,s),Wt(e,l)}function Ht(t,e){t.classList.add(...e)}function Wt(t,e){t.classList.remove(...e)}const Mt=new Map;function Bt(t){Mt.set(t.uniqueId,t)}function It(t){Mt.delete(t.uniqueId)}function Vt(t){!function(t){delete t.coupdoeilElement.openingPopover}(t),Nt(t)}function Nt(t){clearTimeout(t.closingRequest),t.closingRequest=null,Bt(t.coupdoeilElement)}function jt(t,e=!0){t.closing||t.isClosed&&!t.coupdoeilElement.openingPopover||(t.closing=!0,Vt(t),t.children.forEach((t=>{jt(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 Ft("leave",t,e),t.classList.add("hidden")}(t.card,"popover"),zt(t)}(t):zt(t))}function zt(t){t.card&&(t.card.remove(),t.card=null),delete t.closing,delete t.coupdoeilElement.dataset.popoverOpen}function _t(t){jt(t,!1)}function Ut(t){Vt(t),t.closingRequest=setTimeout((()=>{jt(t)}),75)}function Xt(t){t.children.forEach((t=>{jt(t)}))}function Yt(){for(const t of Mt.values())jt(t.popoverController),It(t)}function Jt(){for(const t of Mt.values())_t(t.popoverController),It(t)}function Gt(t){let e=t;for(;e.parent;)e=e.parent;const n=e.coupdoeilElement.uniqueId;for(const t of Mt.values())t.uniqueId!==n&&h(t.popoverController)&&(jt(t.popoverController),It(t))}async function Kt(t,e,n){return new Promise((o=>{setTimeout((async()=>{if(t.coupdoeilElement.openingPopover){if(!1===e.cache||e.cache&&!x(t)){let n;n="preload"===e.loading?y(t).innerHTML:await function(t){const e=f(t),n=d(t),o=document.querySelector("meta[name=csrf-token]").content,i={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({params:n,action_name:e,authenticity_token:o})};return fetch("/coupdoeil/popover",i).then((t=>{if(t.status>=400)throw"error while fetching popover content";return t.text()}))}(t),function(t,e){v.set(w(t),e)}(t,n)}o()}}),n.fetch)}))}async function Qt(t,{parent:n,beforeDisplay:r}){if(t.isOpen)return Nt(t);n&&(t.parent=n,n.children.add(t));const l=function(t){const e=t.popoverController.optionsInt||=u(t),n=Object.create(a);for(const t of i)n[t]=o[t].getter(e);return n}(t.coupdoeilElement),c=function(t,e){if(!1===e.openingDelay||function(t){return"click"===p(t)}(t))return{fetch:0,opening:0};return{fetch:100,opening:200}}(t,l),s=new Promise((t=>setTimeout(t,c.opening))),f=Kt(t,l,c);await Promise.all([f,s]);const d=t.parent&&(t.parent.isClosed||t.parent.closingRequest);t.coupdoeilElement.openingPopover&&!d&&await async function(t,n,o){if(t.isOpen)return;Nt(t),t.card=function(t,n){const o=document.createElement("div");return o.setAttribute("role","dialog"),o.classList.add(e),o.style.cssText="position: absolute; left: 0; top: 0;",o.innerHTML=x(t),o.controller=t,o.dataset.placement=n.placement,o.style.visibility="hidden",o}(t,n),document.body.appendChild(t.card),n.animation&&(t.card.dataset.animation=n.animation);Zt(t,(async()=>{await $t(t.coupdoeilElement,t.card,n),t.card.classList.add("hidden"),t.card.style.removeProperty("visibility"),Zt(t,(async()=>{o&&o(t),Bt(t.coupdoeilElement),delete t.coupdoeilElement.openingPopover,t.coupdoeilElement.dataset.popoverOpen=!0,await async function(t,e=null){t.classList.remove("hidden"),await Ft("enter",t,e)}(t.card,"popover")}))}))}(t,l,r)}function Zt(t,e){requestAnimationFrame((()=>{t.coupdoeilElement.openingPopover?e.call():_t(t)}))}class te extends HTMLElement{constructor(){super(),this.uniqueId=function(){const t=new Uint32Array(1);return window.crypto.getRandomValues(t),t[0]}(),this.popoverController=new t(this)}openPopover(t=null,e){if(this.openingPopover||this.popoverController.isOpen||this.disabled||t===this)return;this.openingPopover=!0;const o=this.closest(n)?.controller;return Bt(this),Qt(this.popoverController,{parent:o,...e})}closePopover(){jt(this.popoverController)}get disabled(){return!!this.getAttribute("disabled")}set disabled(t){t?this.setAttribute("disabled",!0):this.removeAttribute("disabled")}}function ee(){return Mt.size>0}const ne=({target:t})=>{const e=t.closest("coup-doeil"),o=t.closest(n);e&&o?function(t,e,n){const o=t.popoverController;if(m(o))return;o.isOpen?jt(o):t.openPopover(n)}(e,0,t):e?function(t,e){const n=t.popoverController;if(m(n))return;n.isOpen?jt(n):(Yt(),t.openPopover(e))}(e,t):o?function(t,e){const n=t.controller;o=e,o.closest("[data-popover-close]")||o.dataset.hasOwnProperty("popoverClose")?jt(n):n.children.size>0&&Xt(n);var o}(o,t):Yt()};const oe=({target:t})=>{const e=t.closest("coup-doeil"),o=t.closest(n);e&&o?function(t,e,n){const o=t.popoverController,i=e.controller;if(g(o))return;o.isOpen?Xt(o):(Xt(i),t.openPopover(n))}(e,o,t):e?function(t,e){const n=t.popoverController;if(g(n))return;n.isClosed?t.openPopover(e,{beforeDisplay:Gt}):n.closingRequest&&(Nt(n),Bt(t))}(e,t):o?function(t){const e=t.controller;e.closingRequest?(Nt(e),Bt(e.coupdoeilElement)):e.children.size>0&&e.children.forEach((t=>{h(t)&&Ut(t)}))}(o):ee()&&function(){for(const t of Mt.values())h(t.popoverController)&&(Ut(t.popoverController),It(t))}()};document.addEventListener("DOMContentLoaded",(()=>{b(),document.addEventListener("click",ne),document.documentElement.addEventListener("mouseover",oe,{passive:!0}),window.Turbo&&(document.addEventListener("turbo:before-cache",(t=>{Jt()})),document.addEventListener("turbo:load",(t=>{Jt(),b()})))})),void 0===customElements.get("coup-doeil")&&customElements.define("coup-doeil",te);
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.popoverOpen}get isClosed(){return!this.isOpen}}const e="coupdoeil--popover",n=`.${e}`,o={animation:{getter:function(t){return l[t>>5&7]}},cache:{getter:function(t){return!(8&~t)}},loading:{getter:function(t){return s[t>>1&3]}},offset:{getter:function(t){const e=Number(BigInt(t)>>BigInt(24));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>>12}.${e>>2&1023}${2&~e?"px":"rem"}`)}},openingDelay:{getter:function(t){return 1==(t>>4&1)}},placement:{getter:function(t){const e=t>>8&65535;let n=0,o=null;const i=[];for(;"auto"!==o&&n<16;)o=c[e>>n&15],i.push(o),n+=4;return i}},trigger:{getter:function(t){return r[1&t]}}},i=["trigger","loading","cache","openingDelay","animation","placement","offset"],r=["hover","click"],l=[!1,"slide-in","fade-in","slide-out","custom"],c=["auto","top","top-start","top-end","right","right-start","right-end","bottom","bottom-start","bottom-end","left","left-start","left-end"],s=["async","preload","lazy"];const a={animation:void 0,cache:void 0,loading:void 0,offset:void 0,openingDelay:void 0,placement:void 0,trigger:void 0};function u(t){const e=t.getAttribute("popover-options");return parseInt(e,36)}function f(t){return t.coupdoeilElement.getAttribute("popover-type")}function d(t){return t.coupdoeilElement.getAttribute("popover-params")}function p(t){return function(t,e){const n=t.popoverController.optionsInt||=u(t);return o[e].getter(n)}(t.coupdoeilElement,"trigger")}function m(t){return"click"!==p(t)}function h(t){return"hover"===p(t)}function g(t){return"hover"!==p(t)}function y(t){return t.coupdoeilElement.querySelector(".popover-content")}const v=new Map;function w(t){return y(t)?t.coupdoeilElement.uniqueId:f(t)+d(t)}function x(t){return v.get(w(t))}function b(){v.clear()}const E=["top","right","bottom","left"],C=["start","end"],L=E.reduce(((t,e)=>t.concat(e,e+"-"+C[0],e+"-"+C[1])),[]),T=Math.min,P=Math.max,R=Math.round,O=t=>({x:t,y:t}),A={left:"right",right:"left",bottom:"top",top:"bottom"},D={start:"end",end:"start"};function S(t,e,n){return P(t,T(e,n))}function $(t,e){return"function"==typeof t?t(e):t}function q(t){return t.split("-")[0]}function k(t){return t.split("-")[1]}function F(t){return"x"===t?"y":"x"}function H(t){return"y"===t?"height":"width"}function W(t){return["top","bottom"].includes(q(t))?"y":"x"}function M(t){return F(W(t))}function B(t,e,n){void 0===n&&(n=!1);const o=k(t),i=M(t),r=H(i);let l="x"===i?o===(n?"end":"start")?"right":"left":"start"===o?"bottom":"top";return e.reference[r]>e.floating[r]&&(l=V(l)),[l,V(l)]}function I(t){return t.replace(/start|end/g,(t=>D[t]))}function V(t){return t.replace(/left|right|bottom|top/g,(t=>A[t]))}function N(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 j(t){const{x:e,y:n,width:o,height:i}=t;return{width:o,height:i,top:n,left:e,right:e+o,bottom:n+i,x:e,y:n}}function z(t,e,n){let{reference:o,floating:i}=t;const r=W(e),l=M(e),c=H(l),s=q(e),a="y"===r,u=o.x+o.width/2-i.width/2,f=o.y+o.height/2-i.height/2,d=o[c]/2-i[c]/2;let p;switch(s){case"top":p={x:u,y:o.y-i.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-i.width,y:f};break;default:p={x:o.x,y:o.y}}switch(k(e)){case"start":p[l]-=d*(n&&a?-1:1);break;case"end":p[l]+=d*(n&&a?-1:1)}return p}async function _(t,e){var n;void 0===e&&(e={});const{x:o,y:i,platform:r,rects:l,elements:c,strategy:s}=t,{boundary:a="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:d=!1,padding:p=0}=$(e,t),m=N(p),h=c[d?"floating"===f?"reference":"floating":f],g=j(await r.getClippingRect({element:null==(n=await(null==r.isElement?void 0:r.isElement(h)))||n?h:h.contextElement||await(null==r.getDocumentElement?void 0:r.getDocumentElement(c.floating)),boundary:a,rootBoundary:u,strategy:s})),y="floating"===f?{x:o,y:i,width:l.floating.width,height:l.floating.height}:l.reference,v=await(null==r.getOffsetParent?void 0:r.getOffsetParent(c.floating)),w=await(null==r.isElement?void 0:r.isElement(v))&&await(null==r.getScale?void 0:r.getScale(v))||{x:1,y:1},x=j(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:c,rect:y,offsetParent:v,strategy:s}):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 U(){return"undefined"!=typeof window}function X(t){return G(t)?(t.nodeName||"").toLowerCase():"#document"}function Y(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function J(t){var e;return null==(e=(G(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function G(t){return!!U()&&(t instanceof Node||t instanceof Y(t).Node)}function K(t){return!!U()&&(t instanceof Element||t instanceof Y(t).Element)}function Q(t){return!!U()&&(t instanceof HTMLElement||t instanceof Y(t).HTMLElement)}function Z(t){return!(!U()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof Y(t).ShadowRoot)}function tt(t){const{overflow:e,overflowX:n,overflowY:o,display:i}=lt(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&!["inline","contents"].includes(i)}function et(t){return["table","td","th"].includes(X(t))}function nt(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function ot(t){const e=it(),n=K(t)?lt(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 it(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function rt(t){return["html","body","#document"].includes(X(t))}function lt(t){return Y(t).getComputedStyle(t)}function ct(t){return K(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function st(t){if("html"===X(t))return t;const e=t.assignedSlot||t.parentNode||Z(t)&&t.host||J(t);return Z(e)?e.host:e}function at(t){const e=st(t);return rt(e)?t.ownerDocument?t.ownerDocument.body:t.body:Q(e)&&tt(e)?e:at(e)}function ut(t,e,n){var o;void 0===e&&(e=[]),void 0===n&&(n=!0);const i=at(t),r=i===(null==(o=t.ownerDocument)?void 0:o.body),l=Y(i);if(r){const t=ft(l);return e.concat(l,l.visualViewport||[],tt(i)?i:[],t&&n?ut(t):[])}return e.concat(i,ut(i,[],n))}function ft(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function dt(t){const e=lt(t);let n=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const i=Q(t),r=i?t.offsetWidth:n,l=i?t.offsetHeight:o,c=R(n)!==r||R(o)!==l;return c&&(n=r,o=l),{width:n,height:o,$:c}}function pt(t){return K(t)?t:t.contextElement}function mt(t){const e=pt(t);if(!Q(e))return O(1);const n=e.getBoundingClientRect(),{width:o,height:i,$:r}=dt(e);let l=(r?R(n.width):n.width)/o,c=(r?R(n.height):n.height)/i;return l&&Number.isFinite(l)||(l=1),c&&Number.isFinite(c)||(c=1),{x:l,y:c}}const ht=O(0);function gt(t){const e=Y(t);return it()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:ht}function yt(t,e,n,o){void 0===e&&(e=!1),void 0===n&&(n=!1);const i=t.getBoundingClientRect(),r=pt(t);let l=O(1);e&&(o?K(o)&&(l=mt(o)):l=mt(t));const c=function(t,e,n){return void 0===e&&(e=!1),!(!n||e&&n!==Y(t))&&e}(r,n,o)?gt(r):O(0);let s=(i.left+c.x)/l.x,a=(i.top+c.y)/l.y,u=i.width/l.x,f=i.height/l.y;if(r){const t=Y(r),e=o&&K(o)?Y(o):o;let n=t,i=ft(n);for(;i&&o&&e!==n;){const t=mt(i),e=i.getBoundingClientRect(),o=lt(i),r=e.left+(i.clientLeft+parseFloat(o.paddingLeft))*t.x,l=e.top+(i.clientTop+parseFloat(o.paddingTop))*t.y;s*=t.x,a*=t.y,u*=t.x,f*=t.y,s+=r,a+=l,n=Y(i),i=ft(n)}}return j({width:u,height:f,x:s,y:a})}function vt(t,e){const n=ct(t).scrollLeft;return e?e.left+n:yt(J(t)).left+n}function wt(t,e,n){void 0===n&&(n=!1);const o=t.getBoundingClientRect();return{x:o.left+e.scrollLeft-(n?0:vt(t,o)),y:o.top+e.scrollTop}}function xt(t,e,n){let o;if("viewport"===e)o=function(t,e){const n=Y(t),o=J(t),i=n.visualViewport;let r=o.clientWidth,l=o.clientHeight,c=0,s=0;if(i){r=i.width,l=i.height;const t=it();(!t||t&&"fixed"===e)&&(c=i.offsetLeft,s=i.offsetTop)}return{width:r,height:l,x:c,y:s}}(t,n);else if("document"===e)o=function(t){const e=J(t),n=ct(t),o=t.ownerDocument.body,i=P(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),r=P(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let l=-n.scrollLeft+vt(t);const c=-n.scrollTop;return"rtl"===lt(o).direction&&(l+=P(e.clientWidth,o.clientWidth)-i),{width:i,height:r,x:l,y:c}}(J(t));else if(K(e))o=function(t,e){const n=yt(t,!0,"fixed"===e),o=n.top+t.clientTop,i=n.left+t.clientLeft,r=Q(t)?mt(t):O(1);return{width:t.clientWidth*r.x,height:t.clientHeight*r.y,x:i*r.x,y:o*r.y}}(e,n);else{const n=gt(t);o={x:e.x-n.x,y:e.y-n.y,width:e.width,height:e.height}}return j(o)}function bt(t,e){const n=st(t);return!(n===e||!K(n)||rt(n))&&("fixed"===lt(n).position||bt(n,e))}function Et(t,e,n){const o=Q(e),i=J(e),r="fixed"===n,l=yt(t,!0,r,e);let c={scrollLeft:0,scrollTop:0};const s=O(0);if(o||!o&&!r)if(("body"!==X(e)||tt(i))&&(c=ct(e)),o){const t=yt(e,!0,r,e);s.x=t.x+e.clientLeft,s.y=t.y+e.clientTop}else i&&(s.x=vt(i));const a=!i||o||r?O(0):wt(i,c);return{x:l.left+c.scrollLeft-s.x-a.x,y:l.top+c.scrollTop-s.y-a.y,width:l.width,height:l.height}}function Ct(t){return"static"===lt(t).position}function Lt(t,e){if(!Q(t)||"fixed"===lt(t).position)return null;if(e)return e(t);let n=t.offsetParent;return J(t)===n&&(n=n.ownerDocument.body),n}function Tt(t,e){const n=Y(t);if(nt(t))return n;if(!Q(t)){let e=st(t);for(;e&&!rt(e);){if(K(e)&&!Ct(e))return e;e=st(e)}return n}let o=Lt(t,e);for(;o&&et(o)&&Ct(o);)o=Lt(o,e);return o&&rt(o)&&Ct(o)&&!ot(o)?n:o||function(t){let e=st(t);for(;Q(e)&&!rt(e);){if(ot(e))return e;if(nt(e))return null;e=st(e)}return null}(t)||n}const Pt={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:n,offsetParent:o,strategy:i}=t;const r="fixed"===i,l=J(o),c=!!e&&nt(e.floating);if(o===l||c&&r)return n;let s={scrollLeft:0,scrollTop:0},a=O(1);const u=O(0),f=Q(o);if((f||!f&&!r)&&(("body"!==X(o)||tt(l))&&(s=ct(o)),Q(o))){const t=yt(o);a=mt(o),u.x=t.x+o.clientLeft,u.y=t.y+o.clientTop}const d=!l||f||r?O(0):wt(l,s,!0);return{width:n.width*a.x,height:n.height*a.y,x:n.x*a.x-s.scrollLeft*a.x+u.x+d.x,y:n.y*a.y-s.scrollTop*a.y+u.y+d.y}},getDocumentElement:J,getClippingRect:function(t){let{element:e,boundary:n,rootBoundary:o,strategy:i}=t;const r=[..."clippingAncestors"===n?nt(e)?[]:function(t,e){const n=e.get(t);if(n)return n;let o=ut(t,[],!1).filter((t=>K(t)&&"body"!==X(t))),i=null;const r="fixed"===lt(t).position;let l=r?st(t):t;for(;K(l)&&!rt(l);){const e=lt(l),n=ot(l);n||"fixed"!==e.position||(i=null),(r?!n&&!i:!n&&"static"===e.position&&i&&["absolute","fixed"].includes(i.position)||tt(l)&&!n&&bt(t,l))?o=o.filter((t=>t!==l)):i=e,l=st(l)}return e.set(t,o),o}(e,this._c):[].concat(n),o],l=r[0],c=r.reduce(((t,n)=>{const o=xt(e,n,i);return t.top=P(o.top,t.top),t.right=T(o.right,t.right),t.bottom=T(o.bottom,t.bottom),t.left=P(o.left,t.left),t}),xt(e,l,i));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}},getOffsetParent:Tt,getElementRects:async function(t){const e=this.getOffsetParent||Tt,n=this.getDimensions,o=await n(t.floating);return{reference:Et(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}=dt(t);return{width:e,height:n}},getScale:mt,isElement:K,isRTL:function(t){return"rtl"===lt(t).direction}},Rt=_,Ot=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var n,o;const{x:i,y:r,placement:l,middlewareData:c}=e,s=await async function(t,e){const{placement:n,platform:o,elements:i}=t,r=await(null==o.isRTL?void 0:o.isRTL(i.floating)),l=q(n),c=k(n),s="y"===W(n),a=["left","top"].includes(l)?-1:1,u=r&&s?-1:1,f=$(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 c&&"number"==typeof m&&(p="end"===c?-1*m:m),s?{x:p*u,y:d*a}:{x:d*a,y:p*u}}(e,t);return l===(null==(n=c.offset)?void 0:n.placement)&&null!=(o=c.arrow)&&o.alignmentOffset?{}:{x:i+s.x,y:r+s.y,data:{...s,placement:l}}}}},At=function(t){return void 0===t&&(t={}),{name:"autoPlacement",options:t,async fn(e){var n,o,i;const{rects:r,middlewareData:l,placement:c,platform:s,elements:a}=e,{crossAxis:u=!1,alignment:f,allowedPlacements:d=L,autoAlignment:p=!0,...m}=$(t,e),h=void 0!==f||d===L?function(t,e,n){return(t?[...n.filter((e=>k(e)===t)),...n.filter((e=>k(e)!==t))]:n.filter((t=>q(t)===t))).filter((n=>!t||k(n)===t||!!e&&I(n)!==n))}(f||null,p,d):d,g=await _(e,m),y=(null==(n=l.autoPlacement)?void 0:n.index)||0,v=h[y];if(null==v)return{};const w=B(v,r,await(null==s.isRTL?void 0:s.isRTL(a.floating)));if(c!==v)return{reset:{placement:h[0]}};const x=[g[q(v)],g[w[0]],g[w[1]]],b=[...(null==(o=l.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])),T=(null==(i=C.filter((t=>t[2].slice(0,k(t[0])?2:3).every((t=>t<=0))))[0])?void 0:i[0])||C[0][0];return T!==c?{data:{index:y+1,overflows:b},reset:{placement:T}}:{}}}},Dt=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:o,placement:i,rects:r,platform:l,elements:c,middlewareData:s}=e,{element:a,padding:u=0}=$(t,e)||{};if(null==a)return{};const f=N(u),d={x:n,y:o},p=M(i),m=H(p),h=await l.getDimensions(a),g="y"===p,y=g?"top":"left",v=g?"bottom":"right",w=g?"clientHeight":"clientWidth",x=r.reference[m]+r.reference[p]-d[p]-r.floating[m],b=d[p]-r.reference[p],E=await(null==l.getOffsetParent?void 0:l.getOffsetParent(a));let C=E?E[w]:0;C&&await(null==l.isElement?void 0:l.isElement(E))||(C=c.floating[w]||r.floating[m]);const L=x/2-b/2,P=C/2-h[m]/2-1,R=T(f[y],P),O=T(f[v],P),A=R,D=C-h[m]-O,q=C/2-h[m]/2+L,F=S(A,q,D),W=!s.arrow&&null!=k(i)&&q!==F&&r.reference[m]/2-(q<A?R:O)-h[m]/2<0,B=W?q<A?q-A:q-D:0;return{[p]:d[p]+B,data:{[p]:F,centerOffset:q-F-B,...W&&{alignmentOffset:B}},reset:W}}}),St=(t,e,n)=>{const o=new Map,i={platform:Pt,...n},r={...i.platform,_c:o};return(async(t,e,n)=>{const{placement:o="bottom",strategy:i="absolute",middleware:r=[],platform:l}=n,c=r.filter(Boolean),s=await(null==l.isRTL?void 0:l.isRTL(e));let a=await l.getElementRects({reference:t,floating:e,strategy:i}),{x:u,y:f}=z(a,o,s),d=o,p={},m=0;for(let n=0;n<c.length;n++){const{name:r,fn:h}=c[n],{x:g,y:y,data:v,reset:w}=await h({x:u,y:f,initialPlacement:o,placement:d,strategy:i,middlewareData:p,rects:a,platform:l,elements:{reference:t,floating:e}});u=null!=g?g:u,f=null!=y?y:f,p={...p,[r]:{...p[r],...v}},w&&m<=50&&(m++,"object"==typeof w&&(w.placement&&(d=w.placement),w.rects&&(a=!0===w.rects?await l.getElementRects({reference:t,floating:e,strategy:i}):w.rects),({x:u,y:f}=z(a,d,s))),n=-1)}return{x:u,y:f,placement:d,strategy:i,middlewareData:p}})(t,e,{...i,platform:r})};async function $t(t,e,n){let{placement:o,offset:i}=n;const r=o[0],l=e.querySelector("[data-popover-arrow]"),c=[qt(o)];if(l){i+=l.clientWidth,c.push(Dt({element:l}))}c.push(Ot(i));const s=await St(t,e,{placement:r,middleware:c}),{x:a,y:u,placement:f}=s;l&&function(t,e){const n=t.clientWidth,{placement:o,middlewareData:{arrow:i}}=e,r=o.split("-")[0],l=kt[r],{x:c,y:s}=i,{borderWidth:a}=getComputedStyle(t.parentElement);Object.assign(t.style,{left:null!=c?`${c}px`:"",top:null!=s?`${s}px`:"",[l]:`calc(${-n}px + ${a})`})}(l,s),e.dataset.placement=f,Object.assign(e.style,{left:`${a}px`,top:`${u}px`})}const qt=t=>{let e=0;return{name:"autoPlacement",async fn(n){if("auto"===n.placement)return At().fn(n);const{top:o,bottom:i,left:r,right:l}=await Rt(n),c=o>0||i>0||r>0||l>0;return"auto"!==t[e]&&c?(e++,{reset:{placement:t[e]||"auto"}}):c?At().fn(n):{}}}},kt={right:"left",left:"right",top:"bottom",bottom:"top"};async function Ft(t,e,n){const o=e.dataset,i=n?`${n}-${t}`:t;let r=`transition${t.charAt(0).toUpperCase()+t.slice(1)}`;const l=o[r]?o[r].split(" "):[i],c=o[`${r}Start`]?o[`${r}Start`].split(" "):[`${i}-start`],s=o[`${r}End`]?o[`${r}End`].split(" "):[`${i}-end`];Ht(e,l),Ht(e,c),await new Promise((t=>{requestAnimationFrame((()=>{requestAnimationFrame(t)}))})),Wt(e,c),Ht(e,s),await function(t){return new Promise((e=>{const n=getComputedStyle(t).transitionDuration.split(",")[0],o=1e3*Number(n.replace("s",""));setTimeout((()=>{e()}),o)}))}(e),Wt(e,s),Wt(e,l)}function Ht(t,e){t.classList.add(...e)}function Wt(t,e){t.classList.remove(...e)}const Mt=new Map;function Bt(t){Mt.set(t.uniqueId,t)}function It(t){Mt.delete(t.uniqueId)}function Vt(t){!function(t){delete t.coupdoeilElement.openingPopover}(t),Nt(t)}function Nt(t){clearTimeout(t.closingRequest),t.closingRequest=null,Bt(t.coupdoeilElement)}function jt(t,e=!0){t.closing||t.isClosed&&!t.coupdoeilElement.openingPopover||(t.closing=!0,Vt(t),t.children.forEach((t=>{jt(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 Ft("leave",t,e),t.classList.add("hidden")}(t.card,"popover"),zt(t)}(t):zt(t))}function zt(t){t.card&&(t.card.remove(),t.card=null),delete t.closing,delete t.coupdoeilElement.dataset.popoverOpen}function _t(t){jt(t,!1)}function Ut(t){Vt(t),t.closingRequest=setTimeout((()=>{jt(t)}),75)}function Xt(t){t.children.forEach((t=>{jt(t)}))}function Yt(){for(const t of Mt.values())jt(t.popoverController),It(t)}function Jt(){for(const t of Mt.values())_t(t.popoverController),It(t)}function Gt(t){let e=t;for(;e.parent;)e=e.parent;const n=e.coupdoeilElement.uniqueId;for(const t of Mt.values())t.uniqueId!==n&&h(t.popoverController)&&(jt(t.popoverController),It(t))}async function Kt(t,e,n){return new Promise((o=>{setTimeout((async()=>{if(t.coupdoeilElement.openingPopover){if(!1===e.cache||e.cache&&!x(t)){let n;n="preload"===e.loading?y(t).innerHTML:await function(t){const e=f(t),n=d(t),o=document.querySelector("meta[name=csrf-token]").content,i={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({params:n,action_name:e,authenticity_token:o})};return fetch("/coupdoeil/popover",i).then((t=>{if(t.status>=400)throw"error while fetching popover content";return t.text()}))}(t),function(t,e){v.set(w(t),e)}(t,n)}o()}}),n.fetch)}))}async function Qt(t,{parent:n,beforeDisplay:r}){if(t.isOpen)return Nt(t);n&&(t.parent=n,n.children.add(t));const l=function(t){const e=t.popoverController.optionsInt||=u(t),n=Object.create(a);for(const t of i)n[t]=o[t].getter(e);return n}(t.coupdoeilElement),c=function(t,e){if(!1===e.openingDelay||function(t){return"click"===p(t)}(t))return{fetch:0,opening:0};return{fetch:100,opening:200}}(t,l),s=new Promise((t=>setTimeout(t,c.opening))),f=Kt(t,l,c);await Promise.all([f,s]);const d=t.parent&&(t.parent.isClosed||t.parent.closingRequest);t.coupdoeilElement.openingPopover&&!d&&await async function(t,n,o){if(t.isOpen)return;Nt(t),t.card=function(t,n){const o=document.createElement("div");return o.setAttribute("role","dialog"),o.classList.add(e),o.style.cssText="position: absolute; left: 0; top: 0;",o.innerHTML=x(t),o.controller=t,o.dataset.placement=n.placement,o.style.visibility="hidden",o}(t,n),document.body.appendChild(t.card),n.animation&&(t.card.dataset.animation=n.animation);Zt(t,(async()=>{await $t(t.coupdoeilElement,t.card,n),t.card.classList.add("hidden"),t.card.style.removeProperty("visibility"),Zt(t,(async()=>{o&&o(t),Bt(t.coupdoeilElement),delete t.coupdoeilElement.openingPopover,t.coupdoeilElement.dataset.popoverOpen=!0,await async function(t,e=null){t.classList.remove("hidden"),await Ft("enter",t,e)}(t.card,"popover")}))}))}(t,l,r)}function Zt(t,e){requestAnimationFrame((()=>{t.coupdoeilElement.openingPopover?e.call():_t(t)}))}class te extends HTMLElement{constructor(){super(),this.uniqueId=function(){const t=new Uint32Array(1);return window.crypto.getRandomValues(t),t[0]}(),this.popoverController=new t(this)}openPopover(t=null,e){if(this.openingPopover||this.popoverController.isOpen||this.disabled||t===this)return;this.openingPopover=!0;const o=this.closest(n)?.controller;return Bt(this),Qt(this.popoverController,{parent:o,...e})}closePopover(){jt(this.popoverController)}get disabled(){return!!this.getAttribute("disabled")}set disabled(t){t?this.setAttribute("disabled",!0):this.removeAttribute("disabled")}}function ee(){return Mt.size>0}const ne=({target:t})=>{const e=t.closest("coup-doeil"),o=t.closest(n);e&&o?function(t,e,n){const o=t.popoverController;if(m(o))return;o.isOpen?jt(o):t.openPopover(n)}(e,0,t):e?function(t,e){const n=t.popoverController;if(m(n))return;n.isOpen?jt(n):(Yt(),t.openPopover(e))}(e,t):o?function(t,e){const n=t.controller;o=e,o.closest("[data-popover-close]")||o.dataset.hasOwnProperty("popoverClose")?jt(n):n.children.size>0&&Xt(n);var o}(o,t):Yt()};const oe=({target:t})=>{const e=t.closest("coup-doeil"),o=t.closest(n);e&&o?function(t,e,n){const o=t.popoverController,i=e.controller;if(g(o))return;o.isOpen?Xt(o):(Xt(i),t.openPopover(n))}(e,o,t):e?function(t,e){const n=t.popoverController;if(g(n))return;n.isClosed?t.openPopover(e,{beforeDisplay:Gt}):n.closingRequest&&(Nt(n),Bt(t))}(e,t):o?function(t){const e=t.controller;e.closingRequest?(Nt(e),Bt(e.coupdoeilElement)):e.children.size>0&&e.children.forEach((t=>{h(t)&&Ut(t)}))}(o):ee()&&function(){for(const t of Mt.values())h(t.popoverController)&&(Ut(t.popoverController),It(t))}()};document.addEventListener("DOMContentLoaded",(()=>{b(),document.addEventListener("click",ne),document.documentElement.addEventListener("mouseover",oe,{passive:!0}),window.Turbo&&(document.addEventListener("turbo:before-cache",(t=>{Jt()})),document.addEventListener("turbo:load",(t=>{Jt(),b()})))})),void 0===customElements.get("coup-doeil")&&customElements.define("coup-doeil",te);
2
2
  //# sourceMappingURL=coupdoeil.min.js.map