@erain20029/tooltips 2.0.37 → 2.0.38

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,15 +1,11 @@
1
- (function(c){typeof define=="function"&&define.amd?define(c):c()})((function(){"use strict";const c=".tooltip-overlay{position:fixed;z-index:9999;pointer-events:none;background:#53616e;border-radius:8px;box-shadow:0 4px 20px #00000040;color:#dadadb;max-width:300px}.tooltip-overlay.with-image{max-width:500px}.tooltip-card{display:flex;align-items:center;gap:16px;padding:16px 20px;box-sizing:border-box}.tooltip-image{width:120px;height:120px;border-radius:8px;object-fit:cover}.tooltip-text{flex:1;min-width:0}.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;border-left:14px solid transparent;border-right:14px solid transparent}.tooltip-arrow.top{border-bottom:30px solid #53616E}.tooltip-arrow.bottom{border-top:30px solid #53616E}";(function(){const 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=`
2
- <div class="tooltip-arrow"></div>
3
- <div class="tooltip-card">
4
- ${n.image==="left"?h:""}
5
- <div class="tooltip-text">
6
- <div class="tooltip-title" style="font-size:${i.title}px;text-align:${n.title}">
7
- ${t.title}
8
- </div>
9
- <div class="tooltip-desc" style="font-size:${i.description}px;text-align:${n.description}">
10
- ${t.description}
11
- </div>
12
- </div>
13
- ${n.image==="right"?h:""}
14
- </div>
15
- `,document.body.appendChild(o);const x=e.getBoundingClientRect(),{width:T,height:L}=o.getBoundingClientRect(),f=E(x),{x:z,y:A}=P(f,x,T,L);o.style.left=`${z}px`,o.style.top=`${A}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)})()}));
1
+ (function(c){typeof define=="function"&&define.amd?define(c):c()})((function(){"use strict";const c=".tooltip-overlay{position:fixed;z-index:9999;pointer-events:none;background:#53616e;border-radius:8px;box-shadow:0 4px 20px #00000040;color:#dadadb;max-width:300px}.tooltip-overlay.with-image{max-width:500px}.tooltip-card{display:flex;align-items:center;gap:16px;padding:16px 20px;box-sizing:border-box}.tooltip-image{width:120px;height:120px;border-radius:8px;object-fit:cover}.tooltip-text{flex:1;min-width:0}.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;border-left:14px solid transparent;border-right:14px solid transparent}.tooltip-arrow.top{border-bottom:30px solid #53616E}.tooltip-arrow.bottom{border-top:30px solid #53616E}";(function(){function y(){if(document.getElementById("tooltip-overlay-styles"))return;const t=document.createElement("style");t.id="tooltip-overlay-styles",t.textContent=c,document.head.appendChild(t)}const f=16,m=8,h=24;function v(t,e,o){t.left+t.width/2;const i=t.left+t.width,d=t.top+t.height;let n=0,r=0,a="top",p=h;switch(o){case"top-start":n=t.top-e.height-f,r=t.left,a="bottom";break;case"top-end":n=t.top-e.height-f,r=i-e.width,a="bottom",p=e.width-h;break;case"bottom-start":n=d+f,r=t.left,a="top";break;case"bottom-end":default:n=d+f,r=i-e.width,a="top",p=e.width-h;break}return n=Math.max(m,Math.min(n,window.innerHeight-e.height-m)),r=Math.max(m,Math.min(r,window.innerWidth-e.width-m)),{top:n,left:r,arrowSide:a,arrowOffset:p}}let s=null,u=null,w=[],g=!1;async function E(){if(g)return;const t=localStorage.getItem("product");if(!t)return;const e=JSON.parse(t).id,o=document.createElement("script");o.src=`http://localhost:3000/documentation/${e}/tooltip.js`,await new Promise((i,d)=>{o.onload=i,o.onerror=d,document.head.appendChild(o)}),typeof window.tooltipGetter=="function"&&(w=await window.tooltipGetter(),g=!0)}function x(){s&&(s.remove(),s=null,u=null)}function $(t,e){x(),y();const o=document.createElement("div");o.className="tooltip-overlay",o.style.left="-9999px",o.style.top="-9999px",e.image&&o.classList.add("with-image");const i=e.image?`<img class="tooltip-image" src="${e.image}" />`:"";o.innerHTML=`
2
+ <div class="tooltip-arrow"></div>
3
+ <div class="tooltip-card">
4
+ ${e.position?.image==="left"?i:""}
5
+ <div class="tooltip-text">
6
+ <div class="tooltip-title">${e.title}</div>
7
+ <div class="tooltip-desc">${e.description}</div>
8
+ </div>
9
+ ${e.position?.image==="right"?i:""}
10
+ </div>
11
+ `,document.body.appendChild(o);const d=o.getBoundingClientRect(),n=t.getBoundingClientRect(),{top:r,left:a,arrowSide:p,arrowOffset:b}=v(n,d,e.placement||"bottom-start");o.style.top=`${r}px`,o.style.left=`${a}px`;const l=o.querySelector(".tooltip-arrow");l.classList.add(p),p==="top"?(l.style.top="-30px",l.style.left=`${b}px`,l.style.transform="translateX(-50%)"):(l.style.bottom="-30px",l.style.left=`${b}px`,l.style.transform="translateX(-50%)"),s=o,u=t}document.addEventListener("mouseenter",async t=>{if(!(t.target instanceof Element)||t.target.closest(".tooltip-overlay")||(await E(),!g))return;const e=w.find(i=>t.target.closest(i.selector));if(!e)return;const o=t.target.closest(e.selector);o instanceof Element&&$(o,e)},!0),document.addEventListener("mouseleave",t=>{if(!s||!u)return;const e=t.relatedTarget;e&&!s.contains(e)&&!u.contains(e)&&x()},!0)})()}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erain20029/tooltips",
3
- "version": "2.0.37",
3
+ "version": "2.0.38",
4
4
  "description": "Universal tooltip overlay for any HTML project",
5
5
  "license": "MIT",
6
6
  "author": "Erik",