@erain20029/tooltips 2.0.74 → 2.0.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(d){typeof define=="function"&&define.amd?define(d):d()})((function(){"use strict";const d=".tooltip-overlay{position:fixed;z-index:9999;pointer-events:none;background:#53616e;border-radius:8px;box-shadow:0 4px 20px #00000040;color:#dadadb;min-width:45px;max-width:300px;overflow:visible}.tooltip-overlay.with-image{max-width:384px}.tooltip-card{display:flex;align-items:center;gap:16px;padding:10px;box-sizing:border-box}.tooltip-image{width:80px;height:80px;border-radius:8px;object-fit:cover}.tooltip-text{flex:1;color:#fff}.tooltip-title{font-weight:300;line-height:1.3}.tooltip-desc{margin-top:12px;line-height:1.5;font-weight:300;letter-spacing:.2px;overflow-wrap:break-word}.tooltip-arrow{position:absolute;width:0;height:0;pointer-events:none;color:#53616e}.tooltip-arrow img{width:24px;height:24px;display:block;position:absolute}.tooltip-arrow.left_top img{top:-24px;left:10px}.tooltip-arrow.left_bottom img{bottom:-24px;left:10px}.tooltip-arrow.right_bottom img{bottom:-24px;right:10px}.tooltip-arrow.right_top img{top:-24px;right:10px}",x="data:image/svg+xml,%3csvg%20width='53'%20height='44'%20viewBox='60%2025%2060%2040'%20xmlns='http://www.w3.org/2000/svg'%3e%3cdefs%3e%3cmask%20id='hide-bottom'%3e%3crect%20x='0'%20y='0'%20width='200'%20height='200'%20fill='white'%20/%3e%3crect%20x='0'%20y='55'%20width='200'%20height='20'%20fill='black'%20/%3e%3c/mask%3e%3c/defs%3e%3cpath%20d='M100.524%2056.5041%20L84.3494%2033.3916%20L68.1748%2056.5041%20Z'%20fill='currentColor'%20/%3e%3c/svg%3e";(function(){function v(){if(document.getElementById("tooltip-overlay-styles"))return;const i=document.createElement("style");i.id="tooltip-overlay-styles",i.textContent=d,document.head.appendChild(i)}let s=null,p=null,u=[],m=!1;function y(i){const t=i.getBoundingClientRect(),e=window.innerWidth,r=window.innerHeight,l=t.left+t.width/2,o=t.top+t.height/2;return{coordinates:{x:t.left,y:t.top,width:t.width,height:t.height},position:{horizontal:l<e/2?"left":"right",vertical:o<r/2?"top":"bottom"}}}function b(i,t){if(!i)return{titleSize:16,descriptionSize:12};let e=16,r=12,l="left",o="left";switch(i.title){case"small":e=16,l="left";break;case"medium":e=18;break;case"large":e=22;break}switch(i.description){case"small":r=12;break;case"medium":r=14;break;case"large":r=16;break}switch(t.title){case"left":l="left";break;case"center":l="center";break;case"right":l="right";break}switch(t.description){case"left":o="left";break;case"center":o="center";break;case"right":o="right";break}return{titleSize:e,descriptionSize:r,titleAlign:l,descriptionAlign:o}}function w(){s&&(s.remove(),s=null,p=null)}async function k(){if(m)return;const i=localStorage.getItem("product");if(!i)return;const{id:t}=JSON.parse(i),e=document.createElement("script");e.src=`http://localhost:3000/documentation/${t}/tooltip.js`,await new Promise((r,l)=>{e.onload=r,e.onerror=l,document.head.appendChild(e)}),typeof window.tooltipGetter=="function"&&(u=await window.tooltipGetter(),m=!0)}function z(i,t){w(),v();const e=document.createElement("div");e.className="tooltip-overlay",e.style.left="-9999px",e.style.top="-9999px",t.image&&e.classList.add("with-image");const r=`http://localhost:3000${t.image}`,l=t.image?`<img class="tooltip-image" src="${r}" />`:"";e.innerHTML=`
|
|
2
2
|
<div class="tooltip-arrow">
|
|
3
|
-
<img src="${
|
|
3
|
+
<img src="${x}" alt="" />
|
|
4
4
|
</div>
|
|
5
5
|
<div class="tooltip-card">
|
|
6
6
|
${t.position?.image==="left"?l:""}
|
|
@@ -10,4 +10,4 @@
|
|
|
10
10
|
</div>
|
|
11
11
|
${t.position?.image==="right"?l:""}
|
|
12
12
|
</div>
|
|
13
|
-
`,document.body.appendChild(e);const{coordinates:o,position:
|
|
13
|
+
`,document.body.appendChild(e);const{coordinates:o,position:n}=y(i),h=e.getBoundingClientRect(),g=16;let a=0,c=0;const f=e.querySelector(".tooltip-arrow"),{titleSize:S,descriptionSize:$,titleAlign:L,descriptionAlign:T}=b(t.size,t.position),_=`font-size: ${S}px; text-align: ${L};`,C=`font-size: ${$}px; text-align: ${T};`,E=e.querySelector(".tooltip-title"),A=e.querySelector(".tooltip-desc");E.style.cssText=_,A.style.cssText=C,n.horizontal==="left"&&n.vertical==="top"?(a=o.x,c=o.y+o.height+g,f.classList.add("left_top")):n.horizontal==="left"&&n.vertical==="bottom"?(a=o.x,c=o.y-h.height-g,f.classList.add("left_bottom")):n.horizontal==="right"&&n.vertical==="top"?(a=o.x+o.width-h.width,c=o.y+o.height+g,f.classList.add("right_top")):n.horizontal==="right"&&n.vertical==="bottom"&&(a=o.x+o.width-h.width,c=o.y-h.height-g,f.classList.add("right_bottom")),e.style.left=`${Math.max(8,a)}px`,e.style.top=`${Math.max(8,c)}px`,console.log(t),s=e,p=i}document.addEventListener("mouseenter",async i=>{if(!(i.target instanceof Element)||i.target.closest(".tooltip-overlay")||(await k(),!m))return;const t=u.find(r=>i.target.closest(r.selector));if(!t)return;const e=i.target.closest(t.selector);e&&z(e,t)},!0),document.addEventListener("mouseleave",i=>{if(!s||!p)return;const t=i.relatedTarget;t&&!s.contains(t)&&!p.contains(t)&&w()},!0)})()}));
|