coupdoeil 1.0.0.pre.alpha.2 → 1.0.0.pre.alpha.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: 692dde641a7454618ccdfced914f4a42fcba0259e69147598b0c95bc51c8fae0
4
- data.tar.gz: 5c384435d015f13eaa720d1710c7f789dae8c3b8619cf9202abfe3284c554cc1
3
+ metadata.gz: '0871a9b627344de4a1fe232f327a356ae872276aad53fe80f02484f597c1f2e2'
4
+ data.tar.gz: ab0f944bd59bc7459f4e8dd12f3bdfbbbf28d52a7687434db49cffa2e364bd86
5
5
  SHA512:
6
- metadata.gz: 84570a2fbca462e2c611b9c0064bc8864097e2bdbea4828ba09c85978d00a7bdb49fe73ef2ccf2efe9ea722c6a952507e3784c7d0faa0a052b3dddd2156e0121
7
- data.tar.gz: fa9bddb68087382174d222bf4160973655d95433d7d222396204c08a98b9bead48bf3dfb64b6984e5ba614726d49e22493a64b5ab5c5b584fdbe170e1e544be9
6
+ metadata.gz: b6c7fe4cdf5617157b0262055890657092d907decb2c73f7873d6a2ffd9664218740a8369615207945dea2e2570a2616aba025d8be39abe8b3bf690b47fa083a
7
+ data.tar.gz: 98f0fd4ed2eaca581be298319d4de20465490f08dbba2223ab712dcd5be51c3a946d19176a079074451b0d290bf7385f3e5fb22387c86f19ba4d9c5efd22401a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # CHANGELOG
2
2
 
3
+ ### ???
4
+ - update getting-started docs
5
+ - remove JS console logs
6
+ - remove width: max-content from layout template
7
+ - update docs
8
+ - fix Coupdoeil::Hovercard::OptionSet#preload?
9
+
3
10
  ### 1.0.0-alpha.2
4
11
  - refactor `opening.js`
5
12
  - fix the load of Coupdoeil::Engine
@@ -1763,6 +1763,80 @@ const computePosition = (reference, floating, options) => {
1763
1763
  });
1764
1764
  };
1765
1765
 
1766
+ async function positionHovercard(target, card, options) {
1767
+ let {placement: placements, offset: offsetValue} = options;
1768
+ const placement = placements[0];
1769
+ const arrowElement = card.querySelector("[data-hovercard-arrow]");
1770
+ const middleware = [ AutoPositioningWithFallbacks(placements) ];
1771
+ if (arrowElement) {
1772
+ const arrowSize = arrowElement.clientWidth;
1773
+ offsetValue += arrowSize;
1774
+ middleware.push(arrow({
1775
+ element: arrowElement
1776
+ }));
1777
+ }
1778
+ middleware.push(offset(offsetValue));
1779
+ const computedPosition = await computePosition(target, card, {
1780
+ placement: placement,
1781
+ middleware: middleware
1782
+ });
1783
+ const {x: x, y: y, placement: actualPlacement} = computedPosition;
1784
+ if (arrowElement) {
1785
+ positionArrow(arrowElement, computedPosition);
1786
+ }
1787
+ card.dataset.placement = actualPlacement;
1788
+ Object.assign(card.style, {
1789
+ left: `${x}px`,
1790
+ top: `${y}px`
1791
+ });
1792
+ }
1793
+
1794
+ const AutoPositioningWithFallbacks = placements => {
1795
+ let placementIndex = 0;
1796
+ return {
1797
+ name: "autoPlacement",
1798
+ async fn(state) {
1799
+ if (state.placement === "auto") {
1800
+ return autoPlacement().fn(state);
1801
+ }
1802
+ const {top: top, bottom: bottom, left: left, right: right} = await detectOverflow(state);
1803
+ const isOverflowing = top > 0 || bottom > 0 || left > 0 || right > 0;
1804
+ if (placements[placementIndex] !== "auto" && isOverflowing) {
1805
+ placementIndex++;
1806
+ return {
1807
+ reset: {
1808
+ placement: placements[placementIndex] || "auto"
1809
+ }
1810
+ };
1811
+ } else if (isOverflowing) {
1812
+ return autoPlacement().fn(state);
1813
+ }
1814
+ return {};
1815
+ }
1816
+ };
1817
+ };
1818
+
1819
+ const OPPOSITE_SIDES = {
1820
+ right: "left",
1821
+ left: "right",
1822
+ top: "bottom",
1823
+ bottom: "top"
1824
+ };
1825
+
1826
+ function positionArrow(arrowElement, computedData) {
1827
+ const arrowSize = arrowElement.clientWidth;
1828
+ const {placement: placement, middlewareData: {arrow: arrowData}} = computedData;
1829
+ const side = placement.split("-")[0];
1830
+ const oppositeSide = OPPOSITE_SIDES[side];
1831
+ const {x: x, y: y} = arrowData;
1832
+ const {borderWidth: parentBorderWidht} = getComputedStyle(arrowElement.parentElement);
1833
+ Object.assign(arrowElement.style, {
1834
+ left: x != null ? `${x}px` : "",
1835
+ top: y != null ? `${y}px` : "",
1836
+ [oppositeSide]: `calc(${-arrowSize}px + ${parentBorderWidht})`
1837
+ });
1838
+ }
1839
+
1766
1840
  async function enter(element, transitionName = null) {
1767
1841
  element.classList.remove("hidden");
1768
1842
  await transition("enter", element, transitionName);
@@ -1843,7 +1917,6 @@ function cancelOpenCloseActions(controller) {
1843
1917
  }
1844
1918
 
1845
1919
  function cancelOpening(controller) {
1846
- console.log("deleting openingHovercard: ", controller.coupdoeilElement.uniqueId);
1847
1920
  delete controller.coupdoeilElement.openingHovercard;
1848
1921
  }
1849
1922
 
@@ -1854,11 +1927,6 @@ function cancelCloseRequest(controller) {
1854
1927
  }
1855
1928
 
1856
1929
  function closeNow(controller, allowAnimation = true) {
1857
- console.log("closing: ", controller.coupdoeilElement.uniqueId);
1858
- console.log({
1859
- closing: controller.closing,
1860
- isClosed: controller.isClosed && !controller.coupdoeilElement.openingHovercard
1861
- });
1862
1930
  if (controller.closing || controller.isClosed && !controller.coupdoeilElement.openingHovercard) return;
1863
1931
  controller.closing = true;
1864
1932
  cancelOpenCloseActions(controller);
@@ -1944,80 +2012,6 @@ function closeTriggeredOnHoverLater() {
1944
2012
  }
1945
2013
  }
1946
2014
 
1947
- async function positionHovercard(target, card, options) {
1948
- let {placement: placements, offset: offsetValue} = options;
1949
- const placement = placements[0];
1950
- const arrowElement = card.querySelector("[data-hovercard-arrow]");
1951
- const middleware = [ AutoPositioningWithFallbacks(placements) ];
1952
- if (arrowElement) {
1953
- const arrowSize = arrowElement.clientWidth;
1954
- offsetValue += arrowSize;
1955
- middleware.push(arrow({
1956
- element: arrowElement
1957
- }));
1958
- }
1959
- middleware.push(offset(offsetValue));
1960
- const computedPosition = await computePosition(target, card, {
1961
- placement: placement,
1962
- middleware: middleware
1963
- });
1964
- const {x: x, y: y, placement: actualPlacement} = computedPosition;
1965
- if (arrowElement) {
1966
- positionArrow(arrowElement, computedPosition);
1967
- }
1968
- card.dataset.placement = actualPlacement;
1969
- Object.assign(card.style, {
1970
- left: `${x}px`,
1971
- top: `${y}px`
1972
- });
1973
- }
1974
-
1975
- const AutoPositioningWithFallbacks = placements => {
1976
- let placementIndex = 0;
1977
- return {
1978
- name: "autoPlacement",
1979
- async fn(state) {
1980
- if (state.placement === "auto") {
1981
- return autoPlacement().fn(state);
1982
- }
1983
- const {top: top, bottom: bottom, left: left, right: right} = await detectOverflow(state);
1984
- const isOverflowing = top > 0 || bottom > 0 || left > 0 || right > 0;
1985
- if (placements[placementIndex] !== "auto" && isOverflowing) {
1986
- placementIndex++;
1987
- return {
1988
- reset: {
1989
- placement: placements[placementIndex] || "auto"
1990
- }
1991
- };
1992
- } else if (isOverflowing) {
1993
- return autoPlacement().fn(state);
1994
- }
1995
- return {};
1996
- }
1997
- };
1998
- };
1999
-
2000
- const OPPOSITE_SIDES = {
2001
- right: "left",
2002
- left: "right",
2003
- top: "bottom",
2004
- bottom: "top"
2005
- };
2006
-
2007
- function positionArrow(arrowElement, computedData) {
2008
- const arrowSize = arrowElement.clientWidth;
2009
- const {placement: placement, middlewareData: {arrow: arrowData}} = computedData;
2010
- const side = placement.split("-")[0];
2011
- const oppositeSide = OPPOSITE_SIDES[side];
2012
- const {x: x, y: y} = arrowData;
2013
- const {borderWidth: parentBorderWidht} = getComputedStyle(arrowElement.parentElement);
2014
- Object.assign(arrowElement.style, {
2015
- left: x != null ? `${x}px` : "",
2016
- top: y != null ? `${y}px` : "",
2017
- [oppositeSide]: `calc(${-arrowSize}px + ${parentBorderWidht})`
2018
- });
2019
- }
2020
-
2021
2015
  function fetchHovercardContent(controller) {
2022
2016
  const type = getType(controller);
2023
2017
  const params = getParams(controller);
@@ -2061,7 +2055,6 @@ async function loadHovercardContentHTML(controller, options, delayOptions) {
2061
2055
  }
2062
2056
 
2063
2057
  async function openHovercard(controller, {parent: parent}) {
2064
- console.log("opening: ", controller.coupdoeilElement.uniqueId);
2065
2058
  if (controller.isOpen) {
2066
2059
  return cancelCloseRequest(controller);
2067
2060
  }
@@ -2088,32 +2081,29 @@ async function display(controller, options) {
2088
2081
  if (options.animation) {
2089
2082
  controller.card.dataset.animation = options.animation;
2090
2083
  }
2091
- requestAnimationFrame((async () => {
2092
- if (!controller.coupdoeilElement.openingHovercard) {
2093
- return clear(controller);
2094
- }
2095
- controller.card.style.opacity = "0";
2096
- controller.card.classList.remove("hidden");
2097
- requestAnimationFrame((async () => {
2098
- if (!controller.coupdoeilElement.openingHovercard) {
2099
- return clear(controller);
2100
- }
2101
- await positionHovercard(controller.coupdoeilElement, controller.card, options);
2102
- controller.card.classList.add("hidden");
2103
- controller.card.style.removeProperty("opacity");
2104
- requestAnimationFrame((async () => {
2105
- if (!controller.coupdoeilElement.openingHovercard) {
2106
- return clear(controller);
2107
- }
2108
- addToCurrents(controller.coupdoeilElement);
2109
- delete controller.coupdoeilElement.openingHovercard;
2110
- controller.coupdoeilElement.dataset.hovercardOpen = true;
2111
- await enter(controller.card, "hovercard");
2112
- }));
2084
+ executeNextFrameIfStillOpening(controller, (async () => {
2085
+ await positionHovercard(controller.coupdoeilElement, controller.card, options);
2086
+ controller.card.classList.add("hidden");
2087
+ controller.card.style.removeProperty("visibility");
2088
+ executeNextFrameIfStillOpening(controller, (async () => {
2089
+ addToCurrents(controller.coupdoeilElement);
2090
+ delete controller.coupdoeilElement.openingHovercard;
2091
+ controller.coupdoeilElement.dataset.hovercardOpen = true;
2092
+ await enter(controller.card, "hovercard");
2113
2093
  }));
2114
2094
  }));
2115
2095
  }
2116
2096
 
2097
+ function executeNextFrameIfStillOpening(controller, callback) {
2098
+ requestAnimationFrame((() => {
2099
+ if (controller.coupdoeilElement.openingHovercard) {
2100
+ callback.call();
2101
+ } else {
2102
+ clear(controller);
2103
+ }
2104
+ }));
2105
+ }
2106
+
2117
2107
  function getDelayOptionsForController(controller) {
2118
2108
  if (triggeredOnClick(controller)) {
2119
2109
  return {
@@ -2134,11 +2124,12 @@ function getDelayOptionsForController(controller) {
2134
2124
  function buildHovercardElement(controller, options) {
2135
2125
  const el = document.createElement("div");
2136
2126
  el.setAttribute("role", "dialog");
2137
- el.classList.add(HOVERCARD_CLASS_NAME, "hidden");
2127
+ el.classList.add(HOVERCARD_CLASS_NAME);
2138
2128
  el.style.cssText = "position: absolute; left: 0; top: 0;";
2139
2129
  el.innerHTML = getHovercardContentHTML(controller);
2140
2130
  el.controller = controller;
2141
2131
  el.dataset.placement = options.placement;
2132
+ el.style.visibility = "hidden";
2142
2133
  return el;
2143
2134
  }
2144
2135
 
@@ -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.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);
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])),[]),O=Math.min,H=Math.max,P=Math.round,A=t=>({x:t,y:t}),S={left:"right",right:"left",bottom:"top",top:"bottom"},$={start:"end",end:"start"};function D(t,e,n){return H(t,O(e,n))}function q(t,e){return"function"==typeof t?t(e):t}function k(t){return t.split("-")[0]}function F(t){return t.split("-")[1]}function W(t){return"x"===t?"y":"x"}function M(t){return"y"===t?"height":"width"}function B(t){return["top","bottom"].includes(k(t))?"y":"x"}function V(t){return W(B(t))}function I(t,e,n){void 0===n&&(n=!1);const o=F(t),r=V(t),i=M(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=B(e),c=V(e),l=M(c),a=k(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(F(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}=q(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=P(n)!==i||P(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 A(1);const n=e.getBoundingClientRect(),{width:o,height:r,$:i}=mt(e);let c=(i?P(n.width):n.width)/o,l=(i?P(n.height):n.height)/r;return c&&Number.isFinite(c)||(c=1),l&&Number.isFinite(l)||(l=1),{x:c,y:l}}const yt=A(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=A(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):A(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=H(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),i=H(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let c=-n.scrollLeft+xt(t);const l=-n.scrollTop;return"rtl"===at(o).direction&&(c+=H(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):A(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=A(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?A(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 Ot(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 Ht={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=A(1);const u=A(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?A(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=H(o.top,t.top),t.right=O(o.right,t.right),t.bottom=O(o.bottom,t.bottom),t.left=H(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:Ot,getElementRects:async function(t){const e=this.getOffsetParent||Ot,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}},Pt=X,At=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=k(n),l=F(n),a="y"===B(n),s=["left","top"].includes(c)?-1:1,u=i&&a?-1:1,f=q(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}=q(t,e),h=void 0!==f||d===R?function(t,e,n){return(t?[...n.filter((e=>F(e)===t)),...n.filter((e=>F(e)!==t))]:n.filter((t=>k(t)===t))).filter((n=>!t||F(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=I(v,i,await(null==a.isRTL?void 0:a.isRTL(s.floating)));if(l!==v)return{reset:{placement:h[0]}};const x=[g[k(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=F(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,F(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}=q(t,e)||{};if(null==s)return{};const f=z(u),d={x:n,y:o},p=V(r),m=M(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=O(f[y],T),H=O(f[v],T),P=R,A=C-h[m]-H,S=C/2-h[m]/2+L,$=D(P,S,A),k=!a.arrow&&null!=F(r)&&S!==$&&i.reference[m]/2-(S<P?R:H)-h[m]/2<0,W=k?S<P?S-P:S-A:0;return{[p]:d[p]+W,data:{[p]:$,centerOffset:S-$-W,...k&&{alignmentOffset:W}},reset:k}}}),Dt=(t,e,n)=>{const o=new Map,r={platform:Ht,...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 qt(t,e,n){let{placement:o,offset:r}=n;const i=o[0],c=e.querySelector("[data-hovercard-arrow]"),l=[kt(o)];if(c){r+=c.clientWidth,l.push($t({element:c}))}l.push(At(r));const a=await Dt(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=Ft[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 kt=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 Pt(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):{}}}},Ft={right:"left",left:"right",top:"bottom",bottom:"top"};async function Wt(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`];Mt(e,c),Mt(e,l),await new Promise((t=>{requestAnimationFrame((()=>{requestAnimationFrame(t)}))})),Bt(e,l),Mt(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),Bt(e,a),Bt(e,c)}function Mt(t,e){t.classList.add(...e)}function Bt(t,e){t.classList.remove(...e)}const Vt=new Map;function It(t){Vt.set(t.uniqueId,t)}function Nt(t){Vt.delete(t.uniqueId)}function jt(t){!function(t){delete t.coupdoeilElement.openingHovercard}(t),zt(t)}function zt(t){clearTimeout(t.closingRequest),t.closingRequest=null,It(t.coupdoeilElement)}function _t(t,e=!0){t.closing||t.isClosed&&!t.coupdoeilElement.openingHovercard||(t.closing=!0,jt(t),t.children.forEach((t=>{_t(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 Wt("leave",t,e),t.classList.add("hidden")}(t.card,"hovercard"),Ut(t)}(t):Ut(t))}function Ut(t){t.card&&(t.card.remove(),t.card=null),delete t.closing,delete t.coupdoeilElement.dataset.hovercardOpen}function Xt(t){jt(t),t.closingRequest=setTimeout((()=>{_t(t)}),o)}function Yt(t){t.children.forEach((t=>{_t(t)}))}function Jt(){for(const t of Vt.values())_t(t.hovercardController),Nt(t)}function Gt(){for(const t of Vt.values())clearHovercard(t.hovercardController),Nt(t)}async function Kt(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 Qt(t,{parent:n}){if(t.isOpen)return zt(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=Kt(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;zt(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=E(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 qt(t.coupdoeilElement,t.card,n),t.card.classList.add("hidden"),t.card.style.removeProperty("visibility"),Zt(t,(async()=>{It(t.coupdoeilElement),delete t.coupdoeilElement.openingHovercard,t.coupdoeilElement.dataset.hovercardOpen=!0,await async function(t,e=null){t.classList.remove("hidden"),await Wt("enter",t,e)}(t.card,"hovercard")}))}))}(t,l)}function Zt(t,e){requestAnimationFrame((()=>{t.coupdoeilElement.openingHovercard?e.call():function(t){_t(t,!1)}(t)}))}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),Qt(this.hovercardController,{parent:t})}closeHovercard(){_t(this.hovercardController)}}function ee(){return Vt.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?_t(e):t.openHovercard()}(e):e?function(t){const e=t.hovercardController;if(g(e))return;e.isOpen?_t(e):(Jt(),t.openHovercard())}(e):o?function(t,e){const n=t.controller;o=e,o.closest("[data-hovercard-close]")||o.dataset.hasOwnProperty("hovercardClose")?_t(n):n.children.size>0&&Yt(n);var o}(o,t):Jt()};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?Yt(n):(Yt(o),t.openHovercard())}(e,o):e?function(t){const e=t.hovercardController;if(v(e))return;e.isClosed?(!function(){for(const t of Vt.values())y(t.hovercardController)&&(_t(t.hovercardController),Nt(t))}(),t.openHovercard()):e.closingRequest&&(zt(e),It(t))}(e):o?function(t){const e=t.controller;e.closingRequest?(zt(e),It(e.coupdoeilElement)):e.children.size>0&&e.children.forEach((t=>{y(t)&&Xt(t)}))}(o):ee()&&function(){for(const t of Vt.values())y(t.hovercardController)&&(Xt(t.hovercardController),Nt(t))}()};document.addEventListener("DOMContentLoaded",(()=>{C(),document.addEventListener("click",ne),document.documentElement.addEventListener("mouseover",oe,{passive:!0}),window.Turbo&&(document.addEventListener("turbo:before-cache",(t=>{Gt()})),document.addEventListener("turbo:load",(t=>{Gt(),C()})))})),void 0===customElements.get("coup-doeil")&&customElements.define("coup-doeil",te);
2
2
  //# sourceMappingURL=coupdoeil.min.js.map