@ussebastian/kitdigital
Version:
Kit Digital de la Universidad San Sebastián
3 lines (2 loc) • 22.3 kB
JavaScript
System.register([],(function(t){"use strict";return{execute:function(){const e=["start","end"],n=["top","right","bottom","left"].reduce(((t,n)=>t.concat(n,n+"-"+e[0],n+"-"+e[1])),[]),i=Math.min,o=Math.max,r=Math.round,s=Math.floor,l=t=>({x:t,y:t}),a={left:"right",right:"left",bottom:"top",top:"bottom"},c={start:"end",end:"start"};function u(t,e,n){return o(t,i(e,n))}function f(t,e){return"function"==typeof t?t(e):t}function d(t){return t.split("-")[0]}function h(t){return t.split("-")[1]}function p(t){return"x"===t?"y":"x"}function m(t){return"y"===t?"height":"width"}function g(t){return["top","bottom"].includes(d(t))?"y":"x"}function y(t){return p(g(t))}function w(t,e,n){void 0===n&&(n=!1);const i=h(t),o=y(t),r=m(o);let s="x"===o?i===(n?"end":"start")?"right":"left":"start"===i?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=b(s)),[s,b(s)]}function v(t){return t.replace(/start|end/g,(t=>c[t]))}function b(t){return t.replace(/left|right|bottom|top/g,(t=>a[t]))}function x(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(t){return{...t,top:t.y,left:t.x,right:t.x+t.width,bottom:t.y+t.height}}function E(t,e,n){let{reference:i,floating:o}=t;const r=g(e),s=y(e),l=m(s),a=d(e),c="y"===r,u=i.x+i.width/2-o.width/2,f=i.y+i.height/2-o.height/2,p=i[l]/2-o[l]/2;let w;switch(a){case"top":w={x:u,y:i.y-o.height};break;case"bottom":w={x:u,y:i.y+i.height};break;case"right":w={x:i.x+i.width,y:f};break;case"left":w={x:i.x-o.width,y:f};break;default:w={x:i.x,y:i.y}}switch(h(e)){case"start":w[s]-=p*(n&&c?-1:1);break;case"end":w[s]+=p*(n&&c?-1:1)}return w}async function L(t,e){var n;void 0===e&&(e={});const{x:i,y:o,platform:r,rects:s,elements:l,strategy:a}=t,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:d="floating",altBoundary:h=!1,padding:p=0}=f(e,t),m=x(p),g=l[h?"floating"===d?"reference":"floating":d],y=T(await r.getClippingRect({element:null==(n=await(null==r.isElement?void 0:r.isElement(g)))||n?g:g.contextElement||await(null==r.getDocumentElement?void 0:r.getDocumentElement(l.floating)),boundary:c,rootBoundary:u,strategy:a})),w="floating"===d?{...s.floating,x:i,y:o}:s.reference,v=await(null==r.getOffsetParent?void 0:r.getOffsetParent(l.floating)),b=await(null==r.isElement?void 0:r.isElement(v))&&await(null==r.getScale?void 0:r.getScale(v))||{x:1,y:1},E=T(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:w,offsetParent:v,strategy:a}):w);return{top:(y.top-E.top+m.top)/b.y,bottom:(E.bottom-y.bottom+m.bottom)/b.y,left:(y.left-E.left+m.left)/b.x,right:(E.right-y.right+m.right)/b.x}}const A=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var n,i;const{x:o,y:r,placement:s,middlewareData:l}=e,a=await async function(t,e){const{placement:n,platform:i,elements:o}=t,r=await(null==i.isRTL?void 0:i.isRTL(o.floating)),s=d(n),l=h(n),a="y"===g(n),c=["left","top"].includes(s)?-1:1,u=r&&a?-1:1,p=f(e,t);let{mainAxis:m,crossAxis:y,alignmentAxis:w}="number"==typeof p?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...p};return l&&"number"==typeof w&&(y="end"===l?-1*w:w),a?{x:y*u,y:m*c}:{x:m*c,y:y*u}}(e,t);return s===(null==(n=l.offset)?void 0:n.placement)&&null!=(i=l.arrow)&&i.alignmentOffset?{}:{x:o+a.x,y:r+a.y,data:{...a,placement:s}}}}};function O(t){return P(t)?(t.nodeName||"").toLowerCase():"#document"}function R(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function S(t){var e;return null==(e=(P(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function P(t){return t instanceof Node||t instanceof R(t).Node}function k(t){return t instanceof Element||t instanceof R(t).Element}function D(t){return t instanceof HTMLElement||t instanceof R(t).HTMLElement}function B(t){return"undefined"!=typeof ShadowRoot&&(t instanceof ShadowRoot||t instanceof R(t).ShadowRoot)}function C(t){const{overflow:e,overflowX:n,overflowY:i,display:o}=$(t);return/auto|scroll|overlay|hidden|clip/.test(e+i+n)&&!["inline","contents"].includes(o)}function F(t){return["table","td","th"].includes(O(t))}function H(t){const e=M(),n=$(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 M(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function W(t){return["html","body","#document"].includes(O(t))}function $(t){return R(t).getComputedStyle(t)}function N(t){return k(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.pageXOffset,scrollTop:t.pageYOffset}}function V(t){if("html"===O(t))return t;const e=t.assignedSlot||t.parentNode||B(t)&&t.host||S(t);return B(e)?e.host:e}function q(t){const e=V(t);return W(e)?t.ownerDocument?t.ownerDocument.body:t.body:D(e)&&C(e)?e:q(e)}function z(t,e,n){var i;void 0===e&&(e=[]),void 0===n&&(n=!0);const o=q(t),r=o===(null==(i=t.ownerDocument)?void 0:i.body),s=R(o);return r?e.concat(s,s.visualViewport||[],C(o)?o:[],s.frameElement&&n?z(s.frameElement):[]):e.concat(o,z(o,[],n))}function I(t){const e=$(t);let n=parseFloat(e.width)||0,i=parseFloat(e.height)||0;const o=D(t),s=o?t.offsetWidth:n,l=o?t.offsetHeight:i,a=r(n)!==s||r(i)!==l;return a&&(n=s,i=l),{width:n,height:i,$:a}}function j(t){return k(t)?t:t.contextElement}function K(t){const e=j(t);if(!D(e))return l(1);const n=e.getBoundingClientRect(),{width:i,height:o,$:s}=I(e);let a=(s?r(n.width):n.width)/i,c=(s?r(n.height):n.height)/o;return a&&Number.isFinite(a)||(a=1),c&&Number.isFinite(c)||(c=1),{x:a,y:c}}const X=l(0);function Y(t){const e=R(t);return M()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:X}function _(t,e,n,i){void 0===e&&(e=!1),void 0===n&&(n=!1);const o=t.getBoundingClientRect(),r=j(t);let s=l(1);e&&(i?k(i)&&(s=K(i)):s=K(t));const a=function(t,e,n){return void 0===e&&(e=!1),!(!n||e&&n!==R(t))&&e}(r,n,i)?Y(r):l(0);let c=(o.left+a.x)/s.x,u=(o.top+a.y)/s.y,f=o.width/s.x,d=o.height/s.y;if(r){const t=R(r),e=i&&k(i)?R(i):i;let n=t,o=n.frameElement;for(;o&&i&&e!==n;){const t=K(o),e=o.getBoundingClientRect(),i=$(o),r=e.left+(o.clientLeft+parseFloat(i.paddingLeft))*t.x,s=e.top+(o.clientTop+parseFloat(i.paddingTop))*t.y;c*=t.x,u*=t.y,f*=t.x,d*=t.y,c+=r,u+=s,n=R(o),o=n.frameElement}}return T({width:f,height:d,x:c,y:u})}const G=[":popover-open",":modal"];function J(t){return G.some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function Q(t){return _(S(t)).left+N(t).scrollLeft}function U(t,e,n){let i;if("viewport"===e)i=function(t,e){const n=R(t),i=S(t),o=n.visualViewport;let r=i.clientWidth,s=i.clientHeight,l=0,a=0;if(o){r=o.width,s=o.height;const t=M();(!t||t&&"fixed"===e)&&(l=o.offsetLeft,a=o.offsetTop)}return{width:r,height:s,x:l,y:a}}(t,n);else if("document"===e)i=function(t){const e=S(t),n=N(t),i=t.ownerDocument.body,r=o(e.scrollWidth,e.clientWidth,i.scrollWidth,i.clientWidth),s=o(e.scrollHeight,e.clientHeight,i.scrollHeight,i.clientHeight);let l=-n.scrollLeft+Q(t);const a=-n.scrollTop;return"rtl"===$(i).direction&&(l+=o(e.clientWidth,i.clientWidth)-r),{width:r,height:s,x:l,y:a}}(S(t));else if(k(e))i=function(t,e){const n=_(t,!0,"fixed"===e),i=n.top+t.clientTop,o=n.left+t.clientLeft,r=D(t)?K(t):l(1);return{width:t.clientWidth*r.x,height:t.clientHeight*r.y,x:o*r.x,y:i*r.y}}(e,n);else{const n=Y(t);i={...e,x:e.x-n.x,y:e.y-n.y}}return T(i)}function Z(t,e){const n=V(t);return!(n===e||!k(n)||W(n))&&("fixed"===$(n).position||Z(n,e))}function tt(t,e,n){const i=D(e),o=S(e),r="fixed"===n,s=_(t,!0,r,e);let a={scrollLeft:0,scrollTop:0};const c=l(0);if(i||!i&&!r)if(("body"!==O(e)||C(o))&&(a=N(e)),i){const t=_(e,!0,r,e);c.x=t.x+e.clientLeft,c.y=t.y+e.clientTop}else o&&(c.x=Q(o));return{x:s.left+a.scrollLeft-c.x,y:s.top+a.scrollTop-c.y,width:s.width,height:s.height}}function et(t,e){return D(t)&&"fixed"!==$(t).position?e?e(t):t.offsetParent:null}function nt(t,e){const n=R(t);if(!D(t)||J(t))return n;let i=et(t,e);for(;i&&F(i)&&"static"===$(i).position;)i=et(i,e);return i&&("html"===O(i)||"body"===O(i)&&"static"===$(i).position&&!H(i))?n:i||function(t){let e=V(t);for(;D(e)&&!W(e);){if(H(e))return e;e=V(e)}return null}(t)||n}const it={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:n,offsetParent:i,strategy:o}=t;const r="fixed"===o,s=S(i),a=!!e&&J(e.floating);if(i===s||a&&r)return n;let c={scrollLeft:0,scrollTop:0},u=l(1);const f=l(0),d=D(i);if((d||!d&&!r)&&(("body"!==O(i)||C(s))&&(c=N(i)),D(i))){const t=_(i);u=K(i),f.x=t.x+i.clientLeft,f.y=t.y+i.clientTop}return{width:n.width*u.x,height:n.height*u.y,x:n.x*u.x-c.scrollLeft*u.x+f.x,y:n.y*u.y-c.scrollTop*u.y+f.y}},getDocumentElement:S,getClippingRect:function(t){let{element:e,boundary:n,rootBoundary:r,strategy:s}=t;const l=[..."clippingAncestors"===n?function(t,e){const n=e.get(t);if(n)return n;let i=z(t,[],!1).filter((t=>k(t)&&"body"!==O(t))),o=null;const r="fixed"===$(t).position;let s=r?V(t):t;for(;k(s)&&!W(s);){const e=$(s),n=H(s);n||"fixed"!==e.position||(o=null),(r?!n&&!o:!n&&"static"===e.position&&o&&["absolute","fixed"].includes(o.position)||C(s)&&!n&&Z(t,s))?i=i.filter((t=>t!==s)):o=e,s=V(s)}return e.set(t,i),i}(e,this._c):[].concat(n),r],a=l[0],c=l.reduce(((t,n)=>{const r=U(e,n,s);return t.top=o(r.top,t.top),t.right=i(r.right,t.right),t.bottom=i(r.bottom,t.bottom),t.left=o(r.left,t.left),t}),U(e,a,s));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}},getOffsetParent:nt,getElementRects:async function(t){const e=this.getOffsetParent||nt,n=this.getDimensions;return{reference:tt(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,...await n(t.floating)}}},getClientRects:function(t){return Array.from(t.getClientRects())},getDimensions:function(t){const{width:e,height:n}=I(t);return{width:e,height:n}},getScale:K,isElement:k,isRTL:function(t){return"rtl"===$(t).direction}};function ot(t,e,n,r){void 0===r&&(r={});const{ancestorScroll:l=!0,ancestorResize:a=!0,elementResize:c="function"==typeof ResizeObserver,layoutShift:u="function"==typeof IntersectionObserver,animationFrame:f=!1}=r,d=j(t),h=l||a?[...d?z(d):[],...z(e)]:[];h.forEach((t=>{l&&t.addEventListener("scroll",n,{passive:!0}),a&&t.addEventListener("resize",n)}));const p=d&&u?function(t,e){let n,r=null;const l=S(t);function a(){var t;clearTimeout(n),null==(t=r)||t.disconnect(),r=null}return function c(u,f){void 0===u&&(u=!1),void 0===f&&(f=1),a();const{left:d,top:h,width:p,height:m}=t.getBoundingClientRect();if(u||e(),!p||!m)return;const g={rootMargin:-s(h)+"px "+-s(l.clientWidth-(d+p))+"px "+-s(l.clientHeight-(h+m))+"px "+-s(d)+"px",threshold:o(0,i(1,f))||1};let y=!0;function w(t){const e=t[0].intersectionRatio;if(e!==f){if(!y)return c();e?c(!1,e):n=setTimeout((()=>{c(!1,1e-7)}),100)}y=!1}try{r=new IntersectionObserver(w,{...g,root:l.ownerDocument})}catch(t){r=new IntersectionObserver(w,g)}r.observe(t)}(!0),a}(d,n):null;let m,g=-1,y=null;c&&(y=new ResizeObserver((t=>{let[i]=t;i&&i.target===d&&y&&(y.unobserve(e),cancelAnimationFrame(g),g=requestAnimationFrame((()=>{var t;null==(t=y)||t.observe(e)}))),n()})),d&&!f&&y.observe(d),y.observe(e));let w=f?_(t):null;return f&&function e(){const i=_(t);!w||i.x===w.x&&i.y===w.y&&i.width===w.width&&i.height===w.height||n();w=i,m=requestAnimationFrame(e)}(),n(),()=>{var t;h.forEach((t=>{l&&t.removeEventListener("scroll",n),a&&t.removeEventListener("resize",n)})),null==p||p(),null==(t=y)||t.disconnect(),y=null,f&&cancelAnimationFrame(m)}}const rt=function(t){return void 0===t&&(t={}),{name:"autoPlacement",options:t,async fn(e){var i,o,r;const{rects:s,middlewareData:l,placement:a,platform:c,elements:u}=e,{crossAxis:p=!1,alignment:m,allowedPlacements:g=n,autoAlignment:y=!0,...b}=f(t,e),x=void 0!==m||g===n?function(t,e,n){return(t?[...n.filter((e=>h(e)===t)),...n.filter((e=>h(e)!==t))]:n.filter((t=>d(t)===t))).filter((n=>!t||h(n)===t||!!e&&v(n)!==n))}(m||null,y,g):g,T=await L(e,b),E=(null==(i=l.autoPlacement)?void 0:i.index)||0,A=x[E];if(null==A)return{};const O=w(A,s,await(null==c.isRTL?void 0:c.isRTL(u.floating)));if(a!==A)return{reset:{placement:x[0]}};const R=[T[d(A)],T[O[0]],T[O[1]]],S=[...(null==(o=l.autoPlacement)?void 0:o.overflows)||[],{placement:A,overflows:R}],P=x[E+1];if(P)return{data:{index:E+1,overflows:S},reset:{placement:P}};const k=S.map((t=>{const e=h(t.placement);return[t.placement,e&&p?t.overflows.slice(0,2).reduce(((t,e)=>t+e),0):t.overflows[0],t.overflows]})).sort(((t,e)=>t[1]-e[1])),D=(null==(r=k.filter((t=>t[2].slice(0,h(t[0])?2:3).every((t=>t<=0))))[0])?void 0:r[0])||k[0][0];return D!==a?{data:{index:E+1,overflows:S},reset:{placement:D}}:{}}}},st=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:i,placement:o}=e,{mainAxis:r=!0,crossAxis:s=!1,limiter:l={fn:t=>{let{x:e,y:n}=t;return{x:e,y:n}}},...a}=f(t,e),c={x:n,y:i},h=await L(e,a),m=g(d(o)),y=p(m);let w=c[y],v=c[m];if(r){const t="y"===y?"bottom":"right";w=u(w+h["y"===y?"top":"left"],w,w-h[t])}if(s){const t="y"===m?"bottom":"right";v=u(v+h["y"===m?"top":"left"],v,v-h[t])}const b=l.fn({...e,[y]:w,[m]:v});return{...b,data:{x:b.x-n,y:b.y-i}}}}},lt=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var n,i;const{placement:o,middlewareData:r,rects:s,initialPlacement:l,platform:a,elements:c}=e,{mainAxis:u=!0,crossAxis:p=!0,fallbackPlacements:m,fallbackStrategy:g="bestFit",fallbackAxisSideDirection:y="none",flipAlignment:x=!0,...T}=f(t,e);if(null!=(n=r.arrow)&&n.alignmentOffset)return{};const E=d(o),A=d(l)===l,O=await(null==a.isRTL?void 0:a.isRTL(c.floating)),R=m||(A||!x?[b(l)]:function(t){const e=b(t);return[v(t),e,v(e)]}(l));m||"none"===y||R.push(...function(t,e,n,i){const o=h(t);let r=function(t,e,n){const i=["left","right"],o=["right","left"],r=["top","bottom"],s=["bottom","top"];switch(t){case"top":case"bottom":return n?e?o:i:e?i:o;case"left":case"right":return e?r:s;default:return[]}}(d(t),"start"===n,i);return o&&(r=r.map((t=>t+"-"+o)),e&&(r=r.concat(r.map(v)))),r}(l,x,y,O));const S=[l,...R],P=await L(e,T),k=[];let D=(null==(i=r.flip)?void 0:i.overflows)||[];if(u&&k.push(P[E]),p){const t=w(o,s,O);k.push(P[t[0]],P[t[1]])}if(D=[...D,{placement:o,overflows:k}],!k.every((t=>t<=0))){var B,C;const t=((null==(B=r.flip)?void 0:B.index)||0)+1,e=S[t];if(e)return{data:{index:t,overflows:D},reset:{placement:e}};let n=null==(C=D.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:C.placement;if(!n)switch(g){case"bestFit":{var F;const t=null==(F=D.map((t=>[t.placement,t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)])).sort(((t,e)=>t[1]-e[1]))[0])?void 0:F[0];t&&(n=t);break}case"initialPlacement":n=l}if(o!==n)return{reset:{placement:n}}}return{}}}},at=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:o,placement:r,rects:s,platform:l,elements:a,middlewareData:c}=e,{element:d,padding:p=0}=f(t,e)||{};if(null==d)return{};const g=x(p),w={x:n,y:o},v=y(r),b=m(v),T=await l.getDimensions(d),E="y"===v,L=E?"top":"left",A=E?"bottom":"right",O=E?"clientHeight":"clientWidth",R=s.reference[b]+s.reference[v]-w[v]-s.floating[b],S=w[v]-s.reference[v],P=await(null==l.getOffsetParent?void 0:l.getOffsetParent(d));let k=P?P[O]:0;k&&await(null==l.isElement?void 0:l.isElement(P))||(k=a.floating[O]||s.floating[b]);const D=R/2-S/2,B=k/2-T[b]/2-1,C=i(g[L],B),F=i(g[A],B),H=C,M=k-T[b]-F,W=k/2-T[b]/2+D,$=u(H,W,M),N=!c.arrow&&null!=h(r)&&W!==$&&s.reference[b]/2-(W<H?C:F)-T[b]/2<0,V=N?W<H?W-H:W-M:0;return{[v]:w[v]+V,data:{[v]:$,centerOffset:W-$-V,...N&&{alignmentOffset:V}},reset:N}}}),ct=(t,e,n)=>{const i=new Map,o={platform:it,...n},r={...o.platform,_c:i};return(async(t,e,n)=>{const{placement:i="bottom",strategy:o="absolute",middleware:r=[],platform:s}=n,l=r.filter(Boolean),a=await(null==s.isRTL?void 0:s.isRTL(e));let c=await s.getElementRects({reference:t,floating:e,strategy:o}),{x:u,y:f}=E(c,i,a),d=i,h={},p=0;for(let n=0;n<l.length;n++){const{name:r,fn:m}=l[n],{x:g,y:y,data:w,reset:v}=await m({x:u,y:f,initialPlacement:i,placement:d,strategy:o,middlewareData:h,rects:c,platform:s,elements:{reference:t,floating:e}});u=null!=g?g:u,f=null!=y?y:f,h={...h,[r]:{...h[r],...w}},v&&p<=50&&(p++,"object"==typeof v&&(v.placement&&(d=v.placement),v.rects&&(c=!0===v.rects?await s.getElementRects({reference:t,floating:e,strategy:o}):v.rects),({x:u,y:f}=E(c,d,a))),n=-1)}return{x:u,y:f,placement:d,strategy:o,middlewareData:h}})(t,e,{...o,platform:r})};t("Tooltip",class{constructor(t,e){this.key=e,this.element=t,this.setupInitialState()}setupInitialState(){this.tooltip=null,this.arrow=null,this.cleanup=()=>{},this.delay=350,this.placement="top",this.isOpen=!1,this.isOverTrigger=!1,this.shiftPadding=0,this.autoPlacement=!1,this.startOpen=!1,this.validPlacements=["top","right","bottom","left","top-start","top-end","right-start","right-end","bottom-start","bottom-end","left-start","left-end"]}setAriaAttributes(){this.element.setAttribute("aria-describedby",this.key),this.tooltip.setAttribute("id",this.key),this.tooltip.setAttribute("role","tooltip")}mount(){this.handleDataSet(),this.buildTooltipElement(),this.setAriaAttributes(),this.updateTooltipPosition(),this.setEventListeners(),this.hideTooltip(!0)}handleDataSet(){const{ussTooltipDelay:t,ussTooltipPlacement:e,ussTooltipShiftPadding:n,ussTooltipAutoPlacement:i,ussTooltipStartOpen:o}=this.element.dataset,r=this.validPlacements.includes(e);if(e&&!r)throw new Error(`El valor de data-uss-tooltip-placement: ${e} no es válido.`);this.delay=t?Number(t):this.delay,this.placement=e||this.placement,this.shiftPadding=Number(n)||this.shiftPadding,this.autoPlacement=Boolean(i)||this.autoPlacement,this.startOpen=Boolean(o)||this.startOpen}buildTooltipElement(){const t=this.element.getAttribute("data-uss-tooltip-content-element-id"),e=this.element.getAttribute("data-uss-tooltip-content");this.validateContent(e,t),this.tooltip=this.findOrCreateTooltip(t,e),this.cannotHaveButtonsOrLinks(),this.buildArrow()}validateContent(t,e){if(!t&&!e)throw new Error("El Tooltip debe tener contenido o un elemento asociado.")}findOrCreateTooltip(t,e){if(t){const e=document.querySelectorAll(`[data-uss-tooltip-content-id="${t}"]`);if(1!==e.length)throw new Error(`Elemento con data-uss-tooltip-content-id: ${t} ${e.length>1?"no es único.":"no existe."}`);return e[0]}if(e.includes("<")||e.includes(">"))throw new Error("El attributo 'data-uss-tooltip-content' no puede contener HTML.");const n=document.createElement("div");return n.innerHTML=e,this.element.parentNode.insertBefore(n,this.element.nextSibling),n.setAttribute("data-uss-tooltip-content-id",this.key),this.element.removeAttribute("data-uss-tooltip-content"),n}cannotHaveButtonsOrLinks(){const t=this.tooltip.querySelectorAll("button"),e=this.tooltip.querySelectorAll("a"),n=this.tooltip.querySelectorAll("input"),i=this.tooltip.querySelectorAll("[tabindex]");if(t.length||e.length||n.length||i.length)throw new Error("El tooltip no puede contener botones, inputs, links ni nada que lleve tabindex. Evaluar otras soluciones")}buildArrow(){this.arrow=document.createElement("div"),this.arrow.setAttribute("data-uss-tooltip-arrow",this.key),this.tooltip.appendChild(this.arrow)}getAntiOverflowStrategy(){return this.autoPlacement?rt:lt}updateTooltipPosition(){ct(this.element,this.tooltip,{placement:this.placement,middleware:[A(12),this.getAntiOverflowStrategy()({padding:10}),st({padding:this.shiftPadding}),at({element:this.arrow})]}).then((({x:t,y:e,placement:n,middlewareData:i})=>{this.positionTooltip({x:t,y:e}),this.positionArrow(i.arrow,n)}))}positionTooltip({x:t,y:e}){Object.assign(this.tooltip.style,{left:`${t}px`,top:`${e}px`})}positionArrow({x:t,y:e},n){const i=this.getStaticSide(n);Object.assign(this.arrow.style,this.getArrowStyle(t,e,i,n))}getStaticSide(t){return{top:"bottom",right:"left",bottom:"top",left:"right"}[t.split("-")[0]]}getArrowStyle(t,e,n,i){const o=i.split("-")[0];return{left:t?`${t}px`:"auto",top:e?`${e}px`:"auto",right:"",bottom:"",[n]:"-4px",...this.getArrowBorderStyle(o)}}getArrowBorderStyle(t){return{top:{borderTop:"none",borderRight:"inherit",borderBottom:"inherit",borderLeft:"none"},bottom:{borderTop:"inherit",borderRight:"none",borderBottom:"none",borderLeft:"inherit"},left:{borderTop:"inherit",borderRight:"inherit",borderBottom:"none",borderLeft:"none"},right:{borderTop:"none",borderRight:"none",borderBottom:"inherit",borderLeft:"inherit"}}[t]}setEventListeners(){this.element.addEventListener("mouseenter",this.handleMouseEnter.bind(this)),this.element.addEventListener("mouseleave",this.handleMouseLeave.bind(this)),this.element.addEventListener("focus",(()=>this.showTooltip(!0))),this.element.addEventListener("blur",(()=>this.hideTooltip())),this.element.addEventListener("keydown",this.handleKeydown.bind(this))}handleMouseEnter(){this.isOverTrigger=!0,setTimeout((()=>{this.isOverTrigger&&this.showTooltip()}),this.delay)}handleMouseLeave(){this.isOverTrigger=!1,setTimeout((()=>{this.isOverTrigger||this.hideTooltip()}),this.delay/2)}handleKeydown(t){["Escape","Enter"," "].includes(t.key)&&this.hideTooltip()}showTooltip(t=!1){t||(this.tooltip.addEventListener("mouseenter",(()=>{this.isOverTrigger=!0})),this.tooltip.addEventListener("mouseleave",(()=>{this.isOverTrigger=!1,setTimeout((()=>{this.isOverTrigger||this.hideTooltip()}),this.delay/4)})),setTimeout((()=>{this.isOverTrigger||this.hideTooltip()}),this.delay/4),this.tooltip.addEventListener("mouseenter",(()=>{this.isOverTrigger=!0})),this.tooltip.addEventListener("mouseleave",(()=>{this.isOverTrigger=!1})),setTimeout((()=>{this.isOverTrigger||this.hideTooltip()}),this.delay/4)),document.addEventListener("keydown",this.hideOnEscape.bind(this)),document.body.append(this.tooltip),this.cleanup=ot(this.element,this.tooltip,(()=>this.updateTooltipPosition())),this.isOpen=!0}hideTooltip(t=!1){document.removeEventListener("keydown",this.hideOnEscape.bind(this)),this.tooltip&&this.tooltip.remove(),this.isOpen=!1,t||this.cleanup()}hideOnEscape(t){"Escape"===t.key&&this.hideTooltip()}})}}}));
//# sourceMappingURL=Tooltip.js.map