@erain20029/tooltips 2.0.35 → 2.0.36
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.
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
.tooltip-arrow.bottom {
|
|
63
63
|
border-top: 30px solid #53616E;
|
|
64
64
|
}
|
|
65
|
-
`,a={tooltips:[],ready:!1};let r=null,p=null,
|
|
65
|
+
`,a={tooltips:[],ready:!1};let r=null,p=null,u=!1;const m=new Set;function w(){if(u)return;const t=document.createElement("style");t.textContent=c,document.head.appendChild(t),u=!0}function y(t){return m.has(t)?Promise.resolve():new Promise((e,o)=>{const i=document.createElement("script");i.src=t,i.async=!0,i.onload=()=>{m.add(t),e()},i.onerror=()=>o(new Error("Failed to load "+t)),document.head.appendChild(i)})}function g(){r&&(r.remove(),r=null,p=null)}async function b(){if(a.ready)return;const t=localStorage.getItem("product");if(!t)return;const e=JSON.parse(t).id;await y(`http://localhost:3000/documentation/${e}/tooltip.js`),typeof window.tooltipGetter=="function"&&(a.tooltips=await window.tooltipGetter(),a.ready=!0)}function v({title:t,description:e}){return{title:t==="large"?22:t==="small"?14:18,description:e==="large"?16:e==="small"?12:14}}function $({title:t,description:e,image:o}){return{title:t||"left",description:e||"left",image:o||"left"}}function E(t){const e=t.left+t.width/2,o=t.top+t.height/2,i=e<window.innerWidth/2,n=o<window.innerHeight/2;return i&&n?"left-bottom":!i&&n?"right-bottom":i&&!n?"left-top":"right-top"}function P(t,e,o,i){let s=0,l=0;switch(t){case"left-top":s=e.left,l=e.top-i-16;break;case"right-top":s=e.right-o,l=e.top-i-16;break;case"left-bottom":s=e.left,l=e.bottom+48;break;case"right-bottom":s=e.right-o,l=e.bottom+48;break}return{x:Math.max(8,Math.min(s,window.innerWidth-o-8)),y:Math.max(8,Math.min(l,window.innerHeight-i-8))}}function S({tooltip:t,target:e}){if(g(),w(),!(e instanceof Element))return;const o=document.createElement("div");o.className="tooltip-overlay",o.style.left="-9999px",o.style.top="-9999px";const i=v(t.size||{}),n=$(t.position||{});t.image&&o.classList.add("with-image");const l=window.TOOLTIP_UPLOAD_URL||"http://localhost:3000",h=t.image?`<img class="tooltip-image" src="${l}${t.image}" />`:"";o.innerHTML=`
|
|
66
66
|
<div class="tooltip-arrow"></div>
|
|
67
67
|
<div class="tooltip-card">
|
|
68
68
|
${n.image==="left"?h:""}
|
|
@@ -76,4 +76,4 @@
|
|
|
76
76
|
</div>
|
|
77
77
|
${n.image==="right"?h:""}
|
|
78
78
|
</div>
|
|
79
|
-
`,document.body.appendChild(o);const x=e.getBoundingClientRect(),{width:
|
|
79
|
+
`,document.body.appendChild(o);const x=e.getBoundingClientRect(),{width:T,height:A}=o.getBoundingClientRect(),f=E(x),{x:L,y:z}=P(f,x,T,A);o.style.left=`${L}px`,o.style.top=`${z}px`;const d=o.querySelector(".tooltip-arrow");f.includes("top")?(d.classList.add("bottom"),d.style.top="100%"):(d.classList.add("top"),d.style.bottom="100%"),d.style.left=f.includes("right")?"94%":"20px",r=o,p=e}document.addEventListener("mouseenter",async t=>{if(t.target.closest(".tooltip-overlay")||(await b(),!a.ready))return;const e=t.target;if(!(e instanceof Element))return;const o=a.tooltips.find(i=>e.closest(i.selector));o&&S({tooltip:o,target:e.closest(o.selector)})},!0),document.addEventListener("mouseleave",t=>{if(!r||!p)return;const e=t.relatedTarget;e&&!r.contains(e)&&!p.contains(e)&&g()},!0)})()}));
|