@svelte-plugins/tooltips
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
(function(g,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("svelte")):typeof define=="function"&&define.amd?define(["exports","svelte"],d):(g=typeof globalThis<"u"?globalThis:g||self,d(g.SvelteTooltips={},g.svelte))})(this,function(g,d){"use strict";var so=Object.defineProperty;var fo=(g,d,_)=>d in g?so(g,d,{enumerable:!0,configurable:!0,writable:!0,value:_}):g[d]=_;var T=(g,d,_)=>(fo(g,typeof d!="symbol"?d+"":d,_),_);function _(){}function Tt(o,t){for(const e in t)o[e]=t[e];return o}function it(o){return o()}function nt(){return Object.create(null)}function j(o){o.forEach(it)}function lt(o){return typeof o=="function"}function at(o,t){return o!=o?t==t:o!==t||o&&typeof o=="object"||typeof o=="function"}function Lt(o){return Object.keys(o).length===0}function rt(o,t,e,i){if(o){const n=st(o,t,e,i);return o[0](n)}}function st(o,t,e,i){return o[1]&&i?Tt(e.ctx.slice(),o[1](i(t))):e.ctx}function ft(o,t,e,i){if(o[2]&&i){const n=o[2](i(e));if(t.dirty===void 0)return n;if(typeof n=="object"){const a=[],f=Math.max(t.dirty.length,n.length);for(let s=0;s<f;s+=1)a[s]=t.dirty[s]|n[s];return a}return t.dirty|n}return t.dirty}function ct(o,t,e,i,n,a){if(n){const f=st(t,e,i,a);o.p(f,n)}}function pt(o){if(o.ctx.length>32){const t=[],e=o.ctx.length/32;for(let i=0;i<e;i++)t[i]=-1;return t}return-1}function Ct(o,t){o.appendChild(t)}function ut(o,t,e){const i=St(o);if(!i.getElementById(t)){const n=B("style");n.id=t,n.textContent=e,Nt(i,n)}}function St(o){if(!o)return document;const t=o.getRootNode?o.getRootNode():o.ownerDocument;return t&&t.host?t:o.ownerDocument}function Nt(o,t){return Ct(o.head||o,t),t.sheet}function E(o,t,e){o.insertBefore(t,e||null)}function k(o){o.parentNode&&o.parentNode.removeChild(o)}function B(o){return document.createElement(o)}function At(o){return document.createElementNS("http://www.w3.org/2000/svg",o)}function ht(o){return document.createTextNode(o)}function Rt(){return ht(" ")}function F(){return ht("")}function H(o,t,e){e==null?o.removeAttribute(t):o.getAttribute(t)!==e&&o.setAttribute(t,e)}function Wt(o){return Array.from(o.childNodes)}function h(o,t,e,i){e==null?o.style.removeProperty(t):o.style.setProperty(t,e,i?"important":"")}function z(o,t,e){o.classList.toggle(t,!!e)}class mt{constructor(t=!1){T(this,"is_svg",!1);T(this,"e");T(this,"n");T(this,"t");T(this,"a");this.is_svg=t,this.e=this.n=null}c(t){this.h(t)}m(t,e,i=null){this.e||(this.is_svg?this.e=At(e.nodeName):this.e=B(e.nodeType===11?"TEMPLATE":e.nodeName),this.t=e.tagName!=="TEMPLATE"?e:e.content,this.c(t)),this.i(i)}h(t){this.e.innerHTML=t,this.n=Array.from(this.e.nodeName==="TEMPLATE"?this.e.content.childNodes:this.e.childNodes)}i(t){for(let e=0;e<this.n.length;e+=1)E(this.t,this.n[e],t)}p(t){this.d(),this.h(t),this.i(this.a)}d(){this.n.forEach(k)}}let Q;function I(o){Q=o}const S=[],O=[];let N=[];const dt=[],Mt=Promise.resolve();let $=!1;function jt(){$||($=!0,Mt.then(vt))}function tt(o){N.push(o)}const ot=new Set;let A=0;function vt(){if(A!==0)return;const o=Q;do{try{for(;A<S.length;){const t=S[A];A++,I(t),Bt(t.$$)}}catch(t){throw S.length=0,A=0,t}for(I(null),S.length=0,A=0;O.length;)O.pop()();for(let t=0;t<N.length;t+=1){const e=N[t];ot.has(e)||(ot.add(e),e())}N.length=0}while(S.length);for(;dt.length;)dt.pop()();$=!1,ot.clear(),I(o)}function Bt(o){if(o.fragment!==null){o.update(),j(o.before_update);const t=o.dirty;o.dirty=[-1],o.fragment&&o.fragment.p(o.ctx,t),o.after_update.forEach(tt)}}function Ht(o){const t=[],e=[];N.forEach(i=>o.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),N=t}const K=new Set;let L;function It(){L={r:0,c:[],p:L}}function Ot(){L.r||j(L.c),L=L.p}function D(o,t){o&&o.i&&(K.delete(o),o.i(t))}function X(o,t,e,i){if(o&&o.o){if(K.has(o))return;K.add(o),L.c.push(()=>{K.delete(o),i&&(e&&o.d(1),i())}),o.o(t)}else i&&i()}function Dt(o,t,e){const{fragment:i,after_update:n}=o.$$;i&&i.m(t,e),tt(()=>{const a=o.$$.on_mount.map(it).filter(lt);o.$$.on_destroy?o.$$.on_destroy.push(...a):j(a),o.$$.on_mount=[]}),n.forEach(tt)}function Vt(o,t){const e=o.$$;e.fragment!==null&&(Ht(e.after_update),j(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function Ut(o,t){o.$$.dirty[0]===-1&&(S.push(o),jt(),o.$$.dirty.fill(0)),o.$$.dirty[t/31|0]|=1<<t%31}function bt(o,t,e,i,n,a,f=null,s=[-1]){const r=Q;I(o);const l=o.$$={fragment:null,ctx:[],props:a,update:_,not_equal:n,bound:nt(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(r?r.$$.context:[])),callbacks:nt(),dirty:s,skip_bound:!1,root:t.target||r.$$.root};f&&f(l.root);let u=!1;if(l.ctx=e?e(o,t.props||{},(m,x,...w)=>{const P=w.length?w[0]:x;return l.ctx&&n(l.ctx[m],l.ctx[m]=P)&&(!l.skip_bound&&l.bound[m]&&l.bound[m](P),u&&Ut(o,m)),x}):[],l.update(),u=!0,j(l.before_update),l.fragment=i?i(l.ctx):!1,t.target){if(t.hydrate){const m=Wt(t.target);l.fragment&&l.fragment.l(m),m.forEach(k)}else l.fragment&&l.fragment.c();t.intro&&D(o.$$.fragment),Dt(o,t.target,t.anchor),vt()}I(r)}class gt{constructor(){T(this,"$$");T(this,"$$set")}$destroy(){Vt(this,1),this.$destroy=_}$on(t,e){if(!lt(e))return _;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(e),()=>{const n=i.indexOf(e);n!==-1&&i.splice(n,1)}}$set(t){this.$$set&&!Lt(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Zt="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Zt);const yt=o=>o.replace(/-_$/g,"").replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z])(?=[a-z])/g,"$1-$2").toLowerCase(),wt=(o,t)=>{const i=o.getBoundingClientRect().width+2,n=window.getComputedStyle(o),a=parseInt(n.getPropertyValue("padding-left"),10),f=parseInt(n.getPropertyValue("padding-right"),10),s=a+f,r=i-s;return Math.round(Math.min(t,r||t))},_t=(o,t=null,e)=>{const i=o.getBoundingClientRect(),n=window.innerWidth||document.documentElement.clientWidth,a=window.innerHeight||document.documentElement.clientHeight;let f=i.bottom>0&&i.top<a&&i.right>0&&i.left<n;if(t){const s=t.getBoundingClientRect();return e==="top"||e==="bottom"?f=s.bottom+s.height<a&&s.top<a:f=s.right+s.width<n&&s.left<n,f}return f},et=(o,t,e,i)=>{if(!o||!t)return i;const n=o.getBoundingClientRect(),a=t.getBoundingClientRect();switch(e){case"top":i.top=n.top,i.left=n.left+n.width/2;break;case"bottom":i.top=n.top-a.height,i.left=n.left+n.width/2;break;case"left":i.left=n.left,i.top=n.top+n.height/2;break;case"right":i.left=n.right-a.width,i.top=n.top+n.height/2;break}return i.top+=window.scrollY,i.left+=window.scrollX,i},xt={left:"right",right:"left",top:"bottom",bottom:"top"};function Ft(o){ut(o,"svelte-1fqbu6l",`:root{--tooltip-arrow-size:10px;--tooltip-background-color:rgba(0, 0, 0, 0.9);--tooltip-border-radius:4px;--tooltip-box-shadow:0 1px 20px rgba(0, 0, 0, 0.25);--tooltip-font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, | ||
(function(w,v){typeof exports=="object"&&typeof module<"u"?v(exports,require("svelte")):typeof define=="function"&&define.amd?define(["exports","svelte"],v):(w=typeof globalThis<"u"?globalThis:w||self,v(w.SvelteTooltips={},w.svelte))})(this,function(w,v){"use strict";var ro=Object.defineProperty;var fo=(w,v,k)=>v in w?ro(w,v,{enumerable:!0,configurable:!0,writable:!0,value:k}):w[v]=k;var z=(w,v,k)=>(fo(w,typeof v!="symbol"?v+"":v,k),k);function k(){}function Lt(t,o){for(const e in o)t[e]=o[e];return t}function it(t){return t()}function nt(){return Object.create(null)}function M(t){t.forEach(it)}function lt(t){return typeof t=="function"}function at(t,o){return t!=t?o==o:t!==o||t&&typeof t=="object"||typeof t=="function"}function zt(t){return Object.keys(t).length===0}function st(t,o,e,i){if(t){const n=rt(t,o,e,i);return t[0](n)}}function rt(t,o,e,i){return t[1]&&i?Lt(e.ctx.slice(),t[1](i(o))):e.ctx}function ft(t,o,e,i){if(t[2]&&i){const n=t[2](i(e));if(o.dirty===void 0)return n;if(typeof n=="object"){const a=[],c=Math.max(o.dirty.length,n.length);for(let r=0;r<c;r+=1)a[r]=o.dirty[r]|n[r];return a}return o.dirty|n}return o.dirty}function ct(t,o,e,i,n,a){if(n){const c=rt(o,e,i,a);t.p(c,n)}}function pt(t){if(t.ctx.length>32){const o=[],e=t.ctx.length/32;for(let i=0;i<e;i++)o[i]=-1;return o}return-1}function Ct(t,o){t.appendChild(o)}function ut(t,o,e){const i=St(t);if(!i.getElementById(o)){const n=O("style");n.id=o,n.textContent=e,Nt(i,n)}}function St(t){if(!t)return document;const o=t.getRootNode?t.getRootNode():t.ownerDocument;return o&&o.host?o:t.ownerDocument}function Nt(t,o){return Ct(t.head||t,o),o.sheet}function P(t,o,e){t.insertBefore(o,e||null)}function E(t){t.parentNode&&t.parentNode.removeChild(t)}function O(t){return document.createElement(t)}function Rt(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function ht(t){return document.createTextNode(t)}function At(){return ht(" ")}function X(){return ht("")}function j(t,o,e){e==null?t.removeAttribute(o):t.getAttribute(o)!==e&&t.setAttribute(o,e)}function Wt(t){return Array.from(t.childNodes)}function h(t,o,e,i){e==null?t.style.removeProperty(o):t.style.setProperty(o,e,i?"important":"")}function L(t,o,e){t.classList.toggle(o,!!e)}class mt{constructor(o=!1){z(this,"is_svg",!1);z(this,"e");z(this,"n");z(this,"t");z(this,"a");this.is_svg=o,this.e=this.n=null}c(o){this.h(o)}m(o,e,i=null){this.e||(this.is_svg?this.e=Rt(e.nodeName):this.e=O(e.nodeType===11?"TEMPLATE":e.nodeName),this.t=e.tagName!=="TEMPLATE"?e:e.content,this.c(o)),this.i(i)}h(o){this.e.innerHTML=o,this.n=Array.from(this.e.nodeName==="TEMPLATE"?this.e.content.childNodes:this.e.childNodes)}i(o){for(let e=0;e<this.n.length;e+=1)P(this.t,this.n[e],o)}p(o){this.d(),this.h(o),this.i(this.a)}d(){this.n.forEach(E)}}let Q;function H(t){Q=t}const N=[],I=[];let R=[];const dt=[],Bt=Promise.resolve();let $=!1;function Mt(){$||($=!0,Bt.then(vt))}function tt(t){R.push(t)}const ot=new Set;let A=0;function vt(){if(A!==0)return;const t=Q;do{try{for(;A<N.length;){const o=N[A];A++,H(o),Ot(o.$$)}}catch(o){throw N.length=0,A=0,o}for(H(null),N.length=0,A=0;I.length;)I.pop()();for(let o=0;o<R.length;o+=1){const e=R[o];ot.has(e)||(ot.add(e),e())}R.length=0}while(N.length);for(;dt.length;)dt.pop()();$=!1,ot.clear(),H(t)}function Ot(t){if(t.fragment!==null){t.update(),M(t.before_update);const o=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,o),t.after_update.forEach(tt)}}function jt(t){const o=[],e=[];R.forEach(i=>t.indexOf(i)===-1?o.push(i):e.push(i)),e.forEach(i=>i()),R=o}const Z=new Set;let C;function Ht(){C={r:0,c:[],p:C}}function It(){C.r||M(C.c),C=C.p}function D(t,o){t&&t.i&&(Z.delete(t),t.i(o))}function Y(t,o,e,i){if(t&&t.o){if(Z.has(t))return;Z.add(t),C.c.push(()=>{Z.delete(t),i&&(e&&t.d(1),i())}),t.o(o)}else i&&i()}function Dt(t,o,e){const{fragment:i,after_update:n}=t.$$;i&&i.m(o,e),tt(()=>{const a=t.$$.on_mount.map(it).filter(lt);t.$$.on_destroy?t.$$.on_destroy.push(...a):M(a),t.$$.on_mount=[]}),n.forEach(tt)}function Vt(t,o){const e=t.$$;e.fragment!==null&&(jt(e.after_update),M(e.on_destroy),e.fragment&&e.fragment.d(o),e.on_destroy=e.fragment=null,e.ctx=[])}function Ut(t,o){t.$$.dirty[0]===-1&&(N.push(t),Mt(),t.$$.dirty.fill(0)),t.$$.dirty[o/31|0]|=1<<o%31}function bt(t,o,e,i,n,a,c=null,r=[-1]){const s=Q;H(t);const l=t.$$={fragment:null,ctx:[],props:a,update:k,not_equal:n,bound:nt(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(o.context||(s?s.$$.context:[])),callbacks:nt(),dirty:r,skip_bound:!1,root:o.target||s.$$.root};c&&c(l.root);let f=!1;if(l.ctx=e?e(t,o.props||{},(m,b,...d)=>{const x=d.length?d[0]:b;return l.ctx&&n(l.ctx[m],l.ctx[m]=x)&&(!l.skip_bound&&l.bound[m]&&l.bound[m](x),f&&Ut(t,m)),b}):[],l.update(),f=!0,M(l.before_update),l.fragment=i?i(l.ctx):!1,o.target){if(o.hydrate){const m=Wt(o.target);l.fragment&&l.fragment.l(m),m.forEach(E)}else l.fragment&&l.fragment.c();o.intro&&D(t.$$.fragment),Dt(t,o.target,o.anchor),vt()}H(s)}class gt{constructor(){z(this,"$$");z(this,"$$set")}$destroy(){Vt(this,1),this.$destroy=k}$on(o,e){if(!lt(e))return k;const i=this.$$.callbacks[o]||(this.$$.callbacks[o]=[]);return i.push(e),()=>{const n=i.indexOf(e);n!==-1&&i.splice(n,1)}}$set(o){this.$$set&&!zt(o)&&(this.$$.skip_bound=!0,this.$$set(o),this.$$.skip_bound=!1)}}const Ft="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Ft);const yt=t=>t.replace(/-_$/g,"").replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z])(?=[a-z])/g,"$1-$2").toLowerCase(),wt=(t,o)=>{const i=t.getBoundingClientRect().width+2,n=window.getComputedStyle(t),a=parseInt(n.getPropertyValue("padding-left"),10),c=parseInt(n.getPropertyValue("padding-right"),10),r=a+c,s=i-r;return Math.round(Math.min(o,s||o))},_t=(t,o=null,e)=>{const i=t.getBoundingClientRect(),n=window.innerWidth||document.documentElement.clientWidth,a=window.innerHeight||document.documentElement.clientHeight;let c=i.bottom>0&&i.top<a&&i.right>0&&i.left<n;if(o){const r=o.getBoundingClientRect();return e==="top"||e==="bottom"?c=r.bottom+r.height<a&&r.top<a:c=r.right+r.width<n&&r.left<n,c}return c},et=(t,o,e,i)=>{if(!t||!o)return i;let n=0,a=0,c=0,r=0,s=0,l=t;for(;l!==document.body;){const x=window.getComputedStyle(l),q=x.position;q==="fixed"?(c+=l.getBoundingClientRect().top+window.scrollY,s+=l.getBoundingClientRect().left+window.scrollX):q==="sticky"?(r+=l.getBoundingClientRect().top,s+=l.getBoundingClientRect().left+window.scrollX):(q==="absolute"||q==="relative")&&(n-=parseFloat(x.top)||0,a-=parseFloat(x.left)||0),l=l.parentElement}const f=t.getBoundingClientRect(),m=o.getBoundingClientRect();let b=f.top+n+r-c,d=f.left+a-s;switch(e){case"top":i.top=b,i.left=d+f.width/2;break;case"bottom":i.top=b-m.height,i.left=d+f.width/2;break;case"left":i.left=d,i.top=b+f.height/2;break;case"right":i.left=d+f.width-m.width,i.top=b+f.height/2;break}return i.top+=window.scrollY,i.left+=window.scrollX,i},xt={left:"right",right:"left",top:"bottom",bottom:"top"};function Xt(t){ut(t,"svelte-1fqbu6l",`:root{--tooltip-arrow-size:10px;--tooltip-background-color:rgba(0, 0, 0, 0.9);--tooltip-border-radius:4px;--tooltip-box-shadow:0 1px 20px rgba(0, 0, 0, 0.25);--tooltip-font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, | ||
'Helvetica Neue', sans-serif;--tooltip-font-size:14px;--tooltip-font-weight:500;--tooltip-line-height:1.25rem;--tooltip-color:#fff;--tooltip-offset-x:0px;--tooltip-offset-y:0px;--tooltip-padding:12px;--tooltip-pointer-events:none;--tooltip-white-space-hidden:nowrap;--tooltip-white-space-shown:normal;--tooltip-z-index:100}.tooltip.svelte-1fqbu6l{background-color:var(--tooltip-background-color);box-shadow:var(--tooltip-box-shadow);border-radius:var(--tooltip-border-radius);color:var(--tooltip-color);opacity:0;font-family:var(--tooltip-font-family);font-size:var(--tooltip-font-size);font-style:normal;font-weight:var(--tooltip-font-weight);line-height:var(--tooltip-line-height);padding:var(--tooltip-padding);pointer-events:var(--tooltip-pointer-events);position:absolute;text-align:left;visibility:hidden;white-space:var(--tooltip-white-space-hidden);z-index:var(--tooltip-z-index)}.tooltip.show.svelte-1fqbu6l{opacity:1;visibility:visible;white-space:var(--tooltip-white-space-shown)}.tooltip.bottom.svelte-1fqbu6l:after,.tooltip.left.svelte-1fqbu6l:after,.tooltip.right.svelte-1fqbu6l:after,.tooltip.top.svelte-1fqbu6l:after{border:var(--tooltip-arrow-size) solid var(--tooltip-background-color);content:' ';position:absolute}.tooltip.arrowless.svelte-1fqbu6l:after{border:0 !important}.tooltip.bottom.svelte-1fqbu6l,.tooltip.top.svelte-1fqbu6l{--tooltip-offset-x:0px;--tooltip-offset-y:12px}.tooltip.left.svelte-1fqbu6l,.tooltip.right.svelte-1fqbu6l{--tooltip-offset-x:12px;--tooltip-offset-y:0px}.tooltip.bottom.svelte-1fqbu6l{bottom:0;left:50%;transform:translate( | ||
@@ -59,3 +59,3 @@ calc(-50% + var(--tooltip-offset-x)), | ||
calc(100% + var(--tooltip-offset-y)) | ||
) scale(1, 1)}`)}function Kt(o){let t;const e=o[20].default,i=rt(e,o,o[19],null);return{c(){i&&i.c()},m(n,a){i&&i.m(n,a),t=!0},p(n,a){i&&i.p&&(!t||a&524288)&&ct(i,e,n,n[19],t?ft(e,n[19],a,null):pt(n[19]),null)},i(n){t||(D(i,n),t=!0)},o(n){X(i,n),t=!1},d(n){i&&i.d(n)}}}function Xt(o){let t,e,i,n,a;const f=o[20].default,s=rt(f,o,o[19],null);let r=!o[12]&&kt(o);return{c(){t=B("span"),s&&s.c(),e=Rt(),i=B("div"),r&&r.c(),H(t,"class","tooltip-container"),H(i,"class",n="tooltip animation-"+o[9]+" "+o[0]+" "+o[4]+" svelte-1fqbu6l"),h(i,"bottom","auto"),h(i,"right","auto"),h(i,"left",o[11].left+"px"),h(i,"min-width",o[8]+"px"),h(i,"max-width",o[3]+"px"),h(i,"text-align",o[2]),h(i,"top",o[11].top+"px"),z(i,"arrowless",!o[5]),z(i,"show",o[10])},m(l,u){E(l,t,u),s&&s.m(t,null),o[21](t),E(l,e,u),E(l,i,u),r&&r.m(i,null),o[22](i),a=!0},p(l,u){s&&s.p&&(!a||u&524288)&&ct(s,f,l,l[19],a?ft(f,l[19],u,null):pt(l[19]),null),l[12]?r&&(r.d(1),r=null):r?r.p(l,u):(r=kt(l),r.c(),r.m(i,null)),(!a||u&529&&n!==(n="tooltip animation-"+l[9]+" "+l[0]+" "+l[4]+" svelte-1fqbu6l"))&&H(i,"class",n),(!a||u&2048)&&h(i,"left",l[11].left+"px"),(!a||u&256)&&h(i,"min-width",l[8]+"px"),(!a||u&8)&&h(i,"max-width",l[3]+"px"),(!a||u&4)&&h(i,"text-align",l[2]),(!a||u&2048)&&h(i,"top",l[11].top+"px"),(!a||u&561)&&z(i,"arrowless",!l[5]),(!a||u&1553)&&z(i,"show",l[10])},i(l){a||(D(s,l),a=!0)},o(l){X(s,l),a=!1},d(l){l&&(k(t),k(e),k(i)),s&&s.d(l),o[21](null),r&&r.d(),o[22](null)}}}function kt(o){let t,e;return{c(){t=new mt(!1),e=F(),t.a=e},m(i,n){t.m(o[1],i,n),E(i,e,n)},p(i,n){n&2&&t.p(i[1])},d(i){i&&(k(e),t.d())}}}function Yt(o){let t,e,i,n;const a=[Xt,Kt],f=[];function s(r,l){return r[1]?0:1}return t=s(o),e=f[t]=a[t](o),{c(){e.c(),i=F()},m(r,l){f[t].m(r,l),E(r,i,l),n=!0},p(r,[l]){let u=t;t=s(r),t===u?f[t].p(r,l):(It(),X(f[u],1,1,()=>{f[u]=null}),Ot(),e=f[t],e?e.p(r,l):(e=f[t]=a[t](r),e.c()),D(e,1),e.m(i.parentNode,i))},i(r){n||(D(e),n=!0)},o(r){X(e),n=!1},d(r){r&&k(i),f[t].d(r)}}}function Gt(o,t,e){let i,{$$slots:n={},$$scope:a}=t,{action:f="hover"}=t,{content:s=""}=t,{align:r="left"}=t,{position:l="top"}=t,{maxWidth:u=200}=t,{style:m=null}=t,{theme:x=""}=t,{animation:w=""}=t,{delay:P=200}=t,{arrow:R=!0}=t,{autoPosition:C=!1}=t,{show:y=!1}=t,v=null,b=null,V=0,q=null,U=l,W=null,M=null,c=!1,Z={bottom:0,top:0,right:0,left:0};const Y=()=>{c?J():G()},G=()=>{const p=w?P:0;C&&!_t(v,b,l)&&e(0,l=xt[l]),e(11,Z=et(v,b,l,Z)),w&&e(9,W=w),M=setTimeout(()=>e(10,c=!0),p)},J=()=>{e(10,c=!1),e(0,l=U),e(9,W=null),M&&(clearTimeout(M),M=null)},Pt=()=>{v!==null&&(zt(),f==="click"&&v.addEventListener("click",Y),f==="hover"&&(v.addEventListener("mouseenter",G),v.addEventListener("mouseleave",J)))},zt=()=>{v!==null&&(v.removeEventListener("click",Y),v.removeEventListener("mouseenter",G),v.removeEventListener("mouseleave",J))};d.onMount(()=>{if(Pt(),et(),b!==null&&(i&&!q&&(q=new s.component({target:b,props:s.props})),e(8,V=wt(b,u)),m&&typeof m=="object"))for(let p in m){const ao=yt(p),ro=m[p];b.style.setProperty(`--tooltip-${ao}`,ro)}}),d.onDestroy(()=>{q&&(q.$destroy(),q=null),zt()});function no(p){O[p?"unshift":"push"](()=>{v=p,e(7,v)})}function lo(p){O[p?"unshift":"push"](()=>{b=p,e(6,b)})}return o.$$set=p=>{"action"in p&&e(13,f=p.action),"content"in p&&e(1,s=p.content),"align"in p&&e(2,r=p.align),"position"in p&&e(0,l=p.position),"maxWidth"in p&&e(3,u=p.maxWidth),"style"in p&&e(14,m=p.style),"theme"in p&&e(4,x=p.theme),"animation"in p&&e(15,w=p.animation),"delay"in p&&e(16,P=p.delay),"arrow"in p&&e(5,R=p.arrow),"autoPosition"in p&&e(17,C=p.autoPosition),"show"in p&&e(18,y=p.show),"$$scope"in p&&e(19,a=p.$$scope)},o.$$.update=()=>{o.$$.dirty&2&&e(12,i=typeof s=="object"),o.$$.dirty&8192&&Pt(),o.$$.dirty&262208&&(b&&y?G():J())},[l,s,r,u,x,R,b,v,V,W,c,Z,i,f,m,w,P,C,y,a,n,no,lo]}const Jt=class extends gt{constructor(t){super(),bt(this,t,Gt,Yt,at,{action:13,content:1,align:2,position:0,maxWidth:3,style:14,theme:4,animation:15,delay:16,arrow:5,autoPosition:17,show:18},Ft)}};function Qt(o){ut(o,"svelte-hla1ha",`:root{--tooltip-arrow-size:10px;--tooltip-background-color:rgba(0, 0, 0, 0.9);--tooltip-border-radius:4px;--tooltip-box-shadow:0 1px 20px rgba(0, 0, 0, 0.25);--tooltip-font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, | ||
) scale(1, 1)}`)}function Zt(t){let o;const e=t[20].default,i=st(e,t,t[19],null);return{c(){i&&i.c()},m(n,a){i&&i.m(n,a),o=!0},p(n,a){i&&i.p&&(!o||a&524288)&&ct(i,e,n,n[19],o?ft(e,n[19],a,null):pt(n[19]),null)},i(n){o||(D(i,n),o=!0)},o(n){Y(i,n),o=!1},d(n){i&&i.d(n)}}}function Yt(t){let o,e,i,n,a;const c=t[20].default,r=st(c,t,t[19],null);let s=!t[12]&&kt(t);return{c(){o=O("span"),r&&r.c(),e=At(),i=O("div"),s&&s.c(),j(o,"class","tooltip-container"),j(i,"class",n="tooltip animation-"+t[9]+" "+t[0]+" "+t[4]+" svelte-1fqbu6l"),h(i,"bottom","auto"),h(i,"right","auto"),h(i,"left",t[11].left+"px"),h(i,"min-width",t[8]+"px"),h(i,"max-width",t[3]+"px"),h(i,"text-align",t[2]),h(i,"top",t[11].top+"px"),L(i,"arrowless",!t[5]),L(i,"show",t[10])},m(l,f){P(l,o,f),r&&r.m(o,null),t[21](o),P(l,e,f),P(l,i,f),s&&s.m(i,null),t[22](i),a=!0},p(l,f){r&&r.p&&(!a||f&524288)&&ct(r,c,l,l[19],a?ft(c,l[19],f,null):pt(l[19]),null),l[12]?s&&(s.d(1),s=null):s?s.p(l,f):(s=kt(l),s.c(),s.m(i,null)),(!a||f&529&&n!==(n="tooltip animation-"+l[9]+" "+l[0]+" "+l[4]+" svelte-1fqbu6l"))&&j(i,"class",n),(!a||f&2048)&&h(i,"left",l[11].left+"px"),(!a||f&256)&&h(i,"min-width",l[8]+"px"),(!a||f&8)&&h(i,"max-width",l[3]+"px"),(!a||f&4)&&h(i,"text-align",l[2]),(!a||f&2048)&&h(i,"top",l[11].top+"px"),(!a||f&561)&&L(i,"arrowless",!l[5]),(!a||f&1553)&&L(i,"show",l[10])},i(l){a||(D(r,l),a=!0)},o(l){Y(r,l),a=!1},d(l){l&&(E(o),E(e),E(i)),r&&r.d(l),t[21](null),s&&s.d(),t[22](null)}}}function kt(t){let o,e;return{c(){o=new mt(!1),e=X(),o.a=e},m(i,n){o.m(t[1],i,n),P(i,e,n)},p(i,n){n&2&&o.p(i[1])},d(i){i&&(E(e),o.d())}}}function Kt(t){let o,e,i,n;const a=[Yt,Zt],c=[];function r(s,l){return s[1]?0:1}return o=r(t),e=c[o]=a[o](t),{c(){e.c(),i=X()},m(s,l){c[o].m(s,l),P(s,i,l),n=!0},p(s,[l]){let f=o;o=r(s),o===f?c[o].p(s,l):(Ht(),Y(c[f],1,1,()=>{c[f]=null}),It(),e=c[o],e?e.p(s,l):(e=c[o]=a[o](s),e.c()),D(e,1),e.m(i.parentNode,i))},i(s){n||(D(e),n=!0)},o(s){Y(e),n=!1},d(s){s&&E(i),c[o].d(s)}}}function Gt(t,o,e){let i,{$$slots:n={},$$scope:a}=o,{action:c="hover"}=o,{content:r=""}=o,{align:s="left"}=o,{position:l="top"}=o,{maxWidth:f=200}=o,{style:m=null}=o,{theme:b=""}=o,{animation:d=""}=o,{delay:x=200}=o,{arrow:q=!0}=o,{autoPosition:S=!1}=o,{show:_=!1}=o,g=null,y=null,V=0,T=null,U=l,W=null,B=null,p=!1,F={bottom:0,top:0,right:0,left:0};const K=()=>{p?J():G()},G=()=>{const u=d?x:0;S&&!_t(g,y,l)&&e(0,l=xt[l]),e(11,F=et(g,y,l,F)),d&&e(9,W=d),B=setTimeout(()=>e(10,p=!0),u)},J=()=>{e(10,p=!1),e(0,l=U),e(9,W=null),B&&(clearTimeout(B),B=null)},Tt=()=>{g!==null&&(Pt(),c==="click"&&g.addEventListener("click",K),c==="hover"&&(g.addEventListener("mouseenter",G),g.addEventListener("mouseleave",J)))},Pt=()=>{g!==null&&(g.removeEventListener("click",K),g.removeEventListener("mouseenter",G),g.removeEventListener("mouseleave",J))};v.onMount(()=>{if(Tt(),et(),y!==null&&(i&&!T&&(T=new r.component({target:y,props:r.props})),e(8,V=wt(y,f)),m&&typeof m=="object"))for(let u in m){const ao=yt(u),so=m[u];y.style.setProperty(`--tooltip-${ao}`,so)}}),v.onDestroy(()=>{T&&(T.$destroy(),T=null),Pt()});function no(u){I[u?"unshift":"push"](()=>{g=u,e(7,g)})}function lo(u){I[u?"unshift":"push"](()=>{y=u,e(6,y)})}return t.$$set=u=>{"action"in u&&e(13,c=u.action),"content"in u&&e(1,r=u.content),"align"in u&&e(2,s=u.align),"position"in u&&e(0,l=u.position),"maxWidth"in u&&e(3,f=u.maxWidth),"style"in u&&e(14,m=u.style),"theme"in u&&e(4,b=u.theme),"animation"in u&&e(15,d=u.animation),"delay"in u&&e(16,x=u.delay),"arrow"in u&&e(5,q=u.arrow),"autoPosition"in u&&e(17,S=u.autoPosition),"show"in u&&e(18,_=u.show),"$$scope"in u&&e(19,a=u.$$scope)},t.$$.update=()=>{t.$$.dirty&2&&e(12,i=typeof r=="object"),t.$$.dirty&8192&&Tt(),t.$$.dirty&262208&&(y&&_?G():J())},[l,r,s,f,b,q,y,g,V,W,p,F,i,c,m,d,x,S,_,a,n,no,lo]}const Jt=class extends gt{constructor(o){super(),bt(this,o,Gt,Kt,at,{action:13,content:1,align:2,position:0,maxWidth:3,style:14,theme:4,animation:15,delay:16,arrow:5,autoPosition:17,show:18},Xt)}};function Qt(t){ut(t,"svelte-hla1ha",`:root{--tooltip-arrow-size:10px;--tooltip-background-color:rgba(0, 0, 0, 0.9);--tooltip-border-radius:4px;--tooltip-box-shadow:0 1px 20px rgba(0, 0, 0, 0.25);--tooltip-font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, | ||
'Helvetica Neue', sans-serif;--tooltip-font-size:14px;--tooltip-font-weight:500;--tooltip-line-height:1.25rem;--tooltip-color:#fff;--tooltip-offset-x:12px;--tooltip-offset-y:12px;--tooltip-padding:12px;--tooltip-pointer-events:none;--tooltip-white-space-hidden:nowrap;--tooltip-white-space-shown:normal;--tooltip-z-index:100}.tooltip.svelte-hla1ha{background-color:var(--tooltip-background-color);box-shadow:var(--tooltip-box-shadow);border-radius:var(--tooltip-border-radius);color:var(--tooltip-color);opacity:0;font-family:var(--tooltip-font-family);font-size:var(--tooltip-font-size);font-style:normal;font-weight:var(--tooltip-font-weight);line-height:var(--tooltip-line-height);padding:var(--tooltip-padding);pointer-events:var(---tooltip-pointer-events);position:absolute;text-align:left;visibility:hidden;white-space:var(--tooltip-white-space-hidden);z-index:var(--tooltip-z-index)}.tooltip.show.svelte-hla1ha{opacity:1;visibility:visible;white-space:var(--tooltip-white-space-shown)}.tooltip.bottom.svelte-hla1ha:after,.tooltip.left.svelte-hla1ha:after,.tooltip.right.svelte-hla1ha:after,.tooltip.top.svelte-hla1ha:after{border:var(--tooltip-arrow-size) solid var(--tooltip-background-color);content:' ';position:absolute}.tooltip.arrowless.svelte-hla1ha:after{border:0 !important}.tooltip.bottom.svelte-hla1ha,.tooltip.top.svelte-hla1ha{--tooltip-offset-x:0px;--tooltip-offset-y:12px}.tooltip.left.svelte-hla1ha,.tooltip.right.svelte-hla1ha{--tooltip-offset-x:12px;--tooltip-offset-y:0px}.tooltip.bottom.svelte-hla1ha{bottom:0;left:50%;transform:translate( | ||
@@ -118,2 +118,2 @@ calc(-50% + var(--tooltip-offset-x)), | ||
calc(100% + var(--tooltip-offset-y)) | ||
) scale(1, 1)}`)}function qt(o){let t,e,i=!o[11]&&Et(o);return{c(){t=B("div"),i&&i.c(),H(t,"class",e="tooltip animation-"+o[8]+" "+o[0]+" "+o[4]+" svelte-hla1ha"),h(t,"bottom","auto"),h(t,"right","auto"),h(t,"left",o[10].left+"px"),h(t,"min-width",o[7]+"px"),h(t,"max-width",o[3]+"px"),h(t,"text-align",o[2]),h(t,"top",o[10].top+"px"),z(t,"show",o[9]),z(t,"arrowless",!o[5])},m(n,a){E(n,t,a),i&&i.m(t,null),o[19](t)},p(n,a){n[11]?i&&(i.d(1),i=null):i?i.p(n,a):(i=Et(n),i.c(),i.m(t,null)),a&273&&e!==(e="tooltip animation-"+n[8]+" "+n[0]+" "+n[4]+" svelte-hla1ha")&&H(t,"class",e),a&1024&&h(t,"left",n[10].left+"px"),a&128&&h(t,"min-width",n[7]+"px"),a&8&&h(t,"max-width",n[3]+"px"),a&4&&h(t,"text-align",n[2]),a&1024&&h(t,"top",n[10].top+"px"),a&785&&z(t,"show",n[9]),a&305&&z(t,"arrowless",!n[5])},d(n){n&&k(t),i&&i.d(),o[19](null)}}}function Et(o){let t,e;return{c(){t=new mt(!1),e=F(),t.a=e},m(i,n){t.m(o[1],i,n),E(i,e,n)},p(i,n){n&2&&t.p(i[1])},d(i){i&&(k(e),t.d())}}}function $t(o){let t,e=o[1]&&qt(o);return{c(){e&&e.c(),t=F()},m(i,n){e&&e.m(i,n),E(i,t,n)},p(i,[n]){i[1]?e?e.p(i,n):(e=qt(i),e.c(),e.m(t.parentNode,t)):e&&(e.d(1),e=null)},i:_,o:_,d(i){i&&k(t),e&&e.d(i)}}}function to(o,t,e){let i,{targetElement:n=null}=t,{action:a="hover"}=t,{content:f=""}=t,{align:s="left"}=t,{position:r="top"}=t,{maxWidth:l=200}=t,{style:u=null}=t,{theme:m=""}=t,{animation:x=""}=t,{delay:w=200}=t,{arrow:P=!0}=t,{autoPosition:R=!1}=t,{show:C=!1}=t,y=null,v=0,b=null,V=null,q=!1,U={bottom:0,top:0,right:0,left:0};const W=x?w:0;d.onMount(()=>{if(y!==null&&(i&&!b&&(b=new f.component({target:y,props:{action:a,...f.props}})),e(7,v=wt(y,l)),u&&typeof u=="object"))for(let c in u){const Z=yt(c),Y=u[c];y.style.setProperty(`--tooltip-${Z}`,Y)}R&&!_t(y,n,r)&&e(0,r=xt[r]),e(10,U=et(n,y,r,U)),x&&e(8,V=x),setTimeout(()=>e(9,q=!0),W)}),d.onDestroy(()=>{b&&(b.$destroy(),b=null)});function M(c){O[c?"unshift":"push"](()=>{y=c,e(6,y)})}return o.$$set=c=>{"targetElement"in c&&e(12,n=c.targetElement),"action"in c&&e(13,a=c.action),"content"in c&&e(1,f=c.content),"align"in c&&e(2,s=c.align),"position"in c&&e(0,r=c.position),"maxWidth"in c&&e(3,l=c.maxWidth),"style"in c&&e(14,u=c.style),"theme"in c&&e(4,m=c.theme),"animation"in c&&e(15,x=c.animation),"delay"in c&&e(16,w=c.delay),"arrow"in c&&e(5,P=c.arrow),"autoPosition"in c&&e(17,R=c.autoPosition),"show"in c&&e(18,C=c.show)},o.$$.update=()=>{o.$$.dirty&2&&e(11,i=typeof f=="object"),o.$$.dirty&262208&&(y&&C?setTimeout(()=>e(9,q=!0),W):e(9,q=!1))},[r,f,s,l,m,P,y,v,V,q,U,i,n,a,u,x,w,R,C,M]}class oo extends gt{constructor(t){super(),bt(this,t,to,$t,at,{targetElement:12,action:13,content:1,align:2,position:0,maxWidth:3,style:14,theme:4,animation:15,delay:16,arrow:5,autoPosition:17,show:18},Qt)}}const eo=oo,io=(o,t)=>{let e=null,i=o.getAttribute("title"),n=(t==null?void 0:t.action)||o.getAttribute("action")||"hover";const a={...t,targetElement:o};i&&(o.removeAttribute("title"),a.content=i);const f=()=>{e?r():s()},s=()=>{e||(e=new eo({target:o,props:a}))},r=()=>{e&&(e.$destroy(),e=null)},l=()=>{o!==null&&(u(),a.show&&s(),n==="click"&&o.addEventListener("click",f),n==="hover"&&(o.addEventListener("mouseenter",s),o.addEventListener("mouseleave",r)))},u=()=>{o!==null&&(o.removeEventListener("click",f),o.removeEventListener("mouseenter",s),o.removeEventListener("mouseleave",r))};return l(),{destroy(){u(),i&&o.setAttribute("title",i)}}};g.Tooltip=Jt,g.tooltip=io,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}); | ||
) scale(1, 1)}`)}function qt(t){let o,e,i=!t[11]&&Et(t);return{c(){o=O("div"),i&&i.c(),j(o,"class",e="tooltip animation-"+t[8]+" "+t[0]+" "+t[4]+" svelte-hla1ha"),h(o,"bottom","auto"),h(o,"right","auto"),h(o,"left",t[10].left+"px"),h(o,"min-width",t[7]+"px"),h(o,"max-width",t[3]+"px"),h(o,"text-align",t[2]),h(o,"top",t[10].top+"px"),L(o,"show",t[9]),L(o,"arrowless",!t[5])},m(n,a){P(n,o,a),i&&i.m(o,null),t[19](o)},p(n,a){n[11]?i&&(i.d(1),i=null):i?i.p(n,a):(i=Et(n),i.c(),i.m(o,null)),a&273&&e!==(e="tooltip animation-"+n[8]+" "+n[0]+" "+n[4]+" svelte-hla1ha")&&j(o,"class",e),a&1024&&h(o,"left",n[10].left+"px"),a&128&&h(o,"min-width",n[7]+"px"),a&8&&h(o,"max-width",n[3]+"px"),a&4&&h(o,"text-align",n[2]),a&1024&&h(o,"top",n[10].top+"px"),a&785&&L(o,"show",n[9]),a&305&&L(o,"arrowless",!n[5])},d(n){n&&E(o),i&&i.d(),t[19](null)}}}function Et(t){let o,e;return{c(){o=new mt(!1),e=X(),o.a=e},m(i,n){o.m(t[1],i,n),P(i,e,n)},p(i,n){n&2&&o.p(i[1])},d(i){i&&(E(e),o.d())}}}function $t(t){let o,e=t[1]&&qt(t);return{c(){e&&e.c(),o=X()},m(i,n){e&&e.m(i,n),P(i,o,n)},p(i,[n]){i[1]?e?e.p(i,n):(e=qt(i),e.c(),e.m(o.parentNode,o)):e&&(e.d(1),e=null)},i:k,o:k,d(i){i&&E(o),e&&e.d(i)}}}function to(t,o,e){let i,{targetElement:n=null}=o,{action:a="hover"}=o,{content:c=""}=o,{align:r="left"}=o,{position:s="top"}=o,{maxWidth:l=200}=o,{style:f=null}=o,{theme:m=""}=o,{animation:b=""}=o,{delay:d=200}=o,{arrow:x=!0}=o,{autoPosition:q=!1}=o,{show:S=!1}=o,_=null,g=0,y=null,V=null,T=!1,U={bottom:0,top:0,right:0,left:0};const W=b?d:0;v.onMount(()=>{if(_!==null&&(i&&!y&&(y=new c.component({target:_,props:{action:a,...c.props}})),e(7,g=wt(_,l)),f&&typeof f=="object"))for(let p in f){const F=yt(p),K=f[p];_.style.setProperty(`--tooltip-${F}`,K)}q&&!_t(_,n,s)&&e(0,s=xt[s]),e(10,U=et(n,_,s,U)),b&&e(8,V=b),setTimeout(()=>e(9,T=!0),W)}),v.onDestroy(()=>{y&&(y.$destroy(),y=null)});function B(p){I[p?"unshift":"push"](()=>{_=p,e(6,_)})}return t.$$set=p=>{"targetElement"in p&&e(12,n=p.targetElement),"action"in p&&e(13,a=p.action),"content"in p&&e(1,c=p.content),"align"in p&&e(2,r=p.align),"position"in p&&e(0,s=p.position),"maxWidth"in p&&e(3,l=p.maxWidth),"style"in p&&e(14,f=p.style),"theme"in p&&e(4,m=p.theme),"animation"in p&&e(15,b=p.animation),"delay"in p&&e(16,d=p.delay),"arrow"in p&&e(5,x=p.arrow),"autoPosition"in p&&e(17,q=p.autoPosition),"show"in p&&e(18,S=p.show)},t.$$.update=()=>{t.$$.dirty&2&&e(11,i=typeof c=="object"),t.$$.dirty&262208&&(_&&S?setTimeout(()=>e(9,T=!0),W):e(9,T=!1))},[s,c,r,l,m,x,_,g,V,T,U,i,n,a,f,b,d,q,S,B]}class oo extends gt{constructor(o){super(),bt(this,o,to,$t,at,{targetElement:12,action:13,content:1,align:2,position:0,maxWidth:3,style:14,theme:4,animation:15,delay:16,arrow:5,autoPosition:17,show:18},Qt)}}const eo=oo,io=(t,o)=>{let e=null,i=t.getAttribute("title"),n=(o==null?void 0:o.action)||t.getAttribute("action")||"hover";const a={...o,targetElement:t};i&&(t.removeAttribute("title"),a.content=i);const c=()=>{e?s():r()},r=()=>{e||(e=new eo({target:t,props:a}))},s=()=>{e&&(e.$destroy(),e=null)},l=()=>{t!==null&&(f(),a.show&&r(),n==="click"&&t.addEventListener("click",c),n==="hover"&&(t.addEventListener("mouseenter",r),t.addEventListener("mouseleave",s)))},f=()=>{t!==null&&(t.removeEventListener("click",c),t.removeEventListener("mouseenter",r),t.removeEventListener("mouseleave",s))};return l(),{destroy(){f(),i&&t.setAttribute("title",i)}}};w.Tooltip=Jt,w.tooltip=io,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})}); |
{ | ||
"name": "@svelte-plugins/tooltips", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "A simple tooltip action and component designed for Svelte.", |
@@ -26,8 +26,3 @@ export const formatVariableKey = (str) => { | ||
let isInsideViewport = ( | ||
rect.bottom > 0 && | ||
rect.top < viewportHeight && | ||
rect.right > 0 && | ||
rect.left < viewportWidth | ||
); | ||
let isInsideViewport = rect.bottom > 0 && rect.top < viewportHeight && rect.right > 0 && rect.left < viewportWidth; | ||
@@ -38,11 +33,7 @@ if (container) { | ||
if (position === 'top' || position === 'bottom') { | ||
isInsideViewport = ( | ||
(containerRect.bottom + containerRect.height) < viewportHeight && | ||
containerRect.top < viewportHeight | ||
); | ||
isInsideViewport = | ||
containerRect.bottom + containerRect.height < viewportHeight && containerRect.top < viewportHeight; | ||
} else { | ||
isInsideViewport = ( | ||
(containerRect.right + containerRect.width) < viewportWidth && | ||
containerRect.left < viewportWidth | ||
); | ||
isInsideViewport = | ||
containerRect.right + containerRect.width < viewportWidth && containerRect.left < viewportWidth; | ||
} | ||
@@ -61,21 +52,51 @@ | ||
let cumulativeOffsetTop = 0; | ||
let cumulativeOffsetLeft = 0; | ||
let fixedOffsetTop = 0; | ||
let stickyOffsetTop = 0; | ||
let fixedOffsetLeft = 0; | ||
let currentElement = containerRef; | ||
while (currentElement !== document.body) { | ||
const computedStyle = window.getComputedStyle(currentElement); | ||
const elementPosition = computedStyle.position; | ||
if (elementPosition === 'fixed') { | ||
fixedOffsetTop += currentElement.getBoundingClientRect().top + window.scrollY; | ||
fixedOffsetLeft += currentElement.getBoundingClientRect().left + window.scrollX; | ||
} else if (elementPosition === 'sticky') { | ||
stickyOffsetTop += currentElement.getBoundingClientRect().top; | ||
fixedOffsetLeft += currentElement.getBoundingClientRect().left + window.scrollX; | ||
} else if (elementPosition === 'absolute' || elementPosition === 'relative') { | ||
cumulativeOffsetTop -= parseFloat(computedStyle.top) || 0; | ||
cumulativeOffsetLeft -= parseFloat(computedStyle.left) || 0; | ||
} | ||
currentElement = currentElement.parentElement; | ||
} | ||
const containerRect = containerRef.getBoundingClientRect(); | ||
const tooltipRect = tooltipRef.getBoundingClientRect(); | ||
let finalTop = containerRect.top + cumulativeOffsetTop + stickyOffsetTop - fixedOffsetTop; | ||
let finalLeft = containerRect.left + cumulativeOffsetLeft - fixedOffsetLeft; | ||
switch (position) { | ||
case 'top': | ||
coords.top = containerRect.top; | ||
coords.left = containerRect.left + (containerRect.width / 2); | ||
coords.top = finalTop; | ||
coords.left = finalLeft + containerRect.width / 2; | ||
break; | ||
case 'bottom': | ||
coords.top = containerRect.top - tooltipRect.height; | ||
coords.left = containerRect.left + (containerRect.width / 2); | ||
coords.top = finalTop - tooltipRect.height; | ||
coords.left = finalLeft + containerRect.width / 2; | ||
break; | ||
case 'left': | ||
coords.left = containerRect.left; | ||
coords.top = containerRect.top + (containerRect.height / 2); | ||
coords.left = finalLeft; | ||
coords.top = finalTop + containerRect.height / 2; | ||
break; | ||
case 'right': | ||
coords.left = containerRect.right - tooltipRect.width; | ||
coords.top = containerRect.top + (containerRect.height / 2); | ||
coords.left = finalLeft + containerRect.width - tooltipRect.width; | ||
coords.top = finalTop + containerRect.height / 2; | ||
break; | ||
@@ -82,0 +103,0 @@ } |
Sorry, the diff of this file is not supported yet
115055
1.8%1721
1.29%