@erain20029/tooltips 2.0.32 → 2.0.33

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,14 +1,15 @@
1
- (function(a){typeof define=="function"&&define.amd?define(a):a()})((function(){"use strict";const a=".overlay{background:#fff;color:#111;position:fixed;border-radius:10px;z-index:99999;box-shadow:0 0 34px #223c5033;overflow:hidden}.tooltip-card{display:flex;height:100%;align-items:center;gap:16px;padding:16px 20px;max-width:500px;box-sizing:border-box;background:#53616e}.tooltip-media{display:flex;justify-content:center}.tooltip-image{width:120px;height:120px;object-fit:cover;border-radius:8px}.tooltip-text{flex:1;min-width:0;display:flex;flex-direction:column;gap:8px}.tooltip-text div{width:100%;display:block}.tooltip-title{font-weight:600;line-height:1.3}.tooltip-desc{line-height:1.5;overflow-wrap:anywhere}",s={tooltips:[],ready:!1},m=new Set;let l=null,d=null,g=!1;function v(t){return m.has(t)?Promise.resolve():new Promise((e,n)=>{const o=document.createElement("script");o.src=t,o.async=!0,o.onload=()=>{m.add(t),e()},o.onerror=()=>n(new Error(`Failed to load script: ${t}`)),document.head.appendChild(o)})}async function w(){if(s.ready)return;const t=localStorage.getItem("product");if(!t)return;const e=JSON.parse(t).id;if(await v(`http://localhost:3000/documentation/${e}/tooltip.js`),typeof window.tooltipGetter!="function"){console.warn("tooltipGetter not ready");return}s.tooltips=await window.tooltipGetter(),s.ready=!0}document.addEventListener("mouseenter",async t=>{if(t.target.closest(".tooltip-overlay")||(await w(),!s.ready))return;const e=t.target;if(!(e instanceof Element))return;const n=s.tooltips.find(p=>e.closest(p.selector));if(!n)return;const o=e.closest(n.selector),i=o.getBoundingClientRect(),c=$(i),{x:r,y}=T(c,i);z({tooltip:n,x:r,y,target:o})},!0),document.addEventListener("mouseleave",t=>{if(!l||!d)return;const e=t.relatedTarget;e&&!l.contains(e)&&!d.contains(e)&&x()},!0);const h=document.querySelector(".tooltip-card"),f=h.offsetWidth,u=h.offsetHeight;function b(){if(g)return;const t=document.createElement("style");t.textContent=a,document.head.appendChild(t),g=!0}function x(){l&&(l.remove(),l=null,d=null)}function T(t,e){let n=0,o=0;const i=16;switch(t){case"left-bottom":n=e.left,o=e.bottom+i;break;case"right-bottom":n=e.right-f,o=e.bottom+i;break;case"left-top":n=e.left,o=e.top-u-i;break;case"right-top":n=e.right-f,o=e.top-u-i;break}return n=Math.max(8,Math.min(n,window.innerWidth-f-8)),o=Math.max(8,Math.min(o,window.innerHeight-u-8)),{x:n,y:o}}function $(t){const e=t.left+t.width/2,n=t.top+t.height/2,o=e<window.innerWidth/2,i=n<window.innerHeight/2;return o&&i?"left-bottom":!o&&i?"right-bottom":o&&!i?"left-top":"right-top"}function S({title:t,description:e}){return{title:t==="large"?20:t==="small"?14:16,description:e==="large"?16:e==="small"?12:14}}function E({title:t,description:e,image:n}){return{title:t||"left",description:e||"left",image:n||"left"}}function z({tooltip:t,x:e,y:n,target:o}){x(),b();const i=document.createElement("div");i.className="tooltip-overlay",i.style.position="fixed",i.style.maxWidth=t.img?500:300,i.style.left=`${e}px`,i.style.top=`${n}px`,i.style.zIndex="999999";const c=S(t.size||{}),r=E(t.position||{}),p=t.image?`<img class="tooltip-image" src="http://localhost:3000${t.image}" />`:"";i.innerHTML=`
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;margin:0}.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}",d={tooltips:[],ready:!1},m=new Set;let s=null,p=null,g=!1;function $(t){return m.has(t)?Promise.resolve():new Promise((e,n)=>{const o=document.createElement("script");o.src=t,o.async=!0,o.onload=()=>{m.add(t),e()},o.onerror=()=>n(new Error(`Failed to load script: ${t}`)),document.head.appendChild(o)})}async function P(){if(d.ready)return;const t=localStorage.getItem("product");if(!t)return;const e=JSON.parse(t).id;if(await $(`http://localhost:3000/documentation/${e}/tooltip.js`),typeof window.tooltipGetter!="function"){console.warn("tooltipGetter not ready");return}d.tooltips=await window.tooltipGetter(),d.ready=!0}document.addEventListener("mouseenter",async t=>{if(t.target.closest(".tooltip-overlay")||(await P(),!d.ready))return;const e=t.target;if(!(e instanceof Element))return;const n=d.tooltips.find(f=>e.closest(f.selector));if(!n)return;const o=e.closest(n.selector),i=o.getBoundingClientRect(),r=y(i),{x:l,y:b}=w(r,i);C({tooltip:n,x:l,y:b,target:o})},!0),document.addEventListener("mouseleave",t=>{if(!s||!p)return;const e=t.relatedTarget;e&&!s.contains(e)&&!p.contains(e)&&x()},!0);const h=document.querySelector(".tooltip-card");h.offsetWidth,h.offsetHeight;function S(){if(g)return;const t=document.createElement("style");t.textContent=c,document.head.appendChild(t),g=!0}function x(){s&&(s.remove(),s=null,p=null)}function w(t,e,n,o){let r=0,l=0;switch(t){case"left-top":r=e.left,l=e.top-o-16;break;case"right-top":r=e.right-n,l=e.top-o-16;break;case"left-bottom":r=e.left,l=e.bottom+48;break;case"right-bottom":r=e.right-n,l=e.bottom+48;break}return{x:Math.max(8,Math.min(r,window.innerWidth-n-8)),y:Math.max(8,Math.min(l,window.innerHeight-o-8))}}function y(t){const e=t.left+t.width/2,n=t.top+t.height/2,o=e<window.innerWidth/2,i=n<window.innerHeight/2;return o&&i?"left-bottom":!o&&i?"right-bottom":o&&!i?"left-top":"right-top"}function E({title:t,description:e}){return{title:t==="large"?20:t==="small"?14:16,description:e==="large"?16:e==="small"?12:14}}function L({title:t,description:e,image:n}){return{title:t||"left",description:e||"left",image:n||"left"}}function C({tooltip:t,x:e,y:n,target:o}){x(),S();const i=document.createElement("div");i.className="tooltip-overlay",i.style.left="-9999px",i.style.top="-9999px";const r=E(t.size||{}),l=L(t.position||{});t.image&&i.classList.add("with-image");const f=window.TOOLTIP_UPLOAD_URL||"http://localhost:3000",v=t.image?`<img class="tooltip-image" src="${f}${t.image}" />`:"";i.innerHTML=`
2
+ <div class="tooltip-arrow"></div>
2
3
  <div class="tooltip-card">
3
- ${r.image==="left"?`<div>${p}</div>`:""}
4
+ ${l.image==="left"?v:""}
4
5
  <div class="tooltip-text">
5
- <div class="tooltip-title" style="font-size:${c.title}px;text-align:${r.title}">
6
+ <div class="tooltip-title" style="font-size:${r.title}px;text-align:${l.title}">
6
7
  ${t.title}
7
8
  </div>
8
- <div class="tooltip-desc" style="font-size:${c.description}px;text-align:${r.description}">
9
+ <div class="tooltip-desc" style="font-size:${r.description}px;text-align:${l.description}">
9
10
  ${t.description}
10
11
  </div>
11
12
  </div>
12
- ${r.image==="right"?`<div>${p}</div>`:""}
13
+ ${l.image==="right"?v:""}
13
14
  </div>
14
- `,document.body.appendChild(i),l=i,d=o}}));
15
+ `,document.body.appendChild(i);const{width:G,height:z}=i.getBoundingClientRect(),u=y(o.getBoundingClientRect()),T=w(u,o.getBoundingClientRect(),G,z);i.style.left=`${T.x}px`,i.style.top=`${T.y}px`;const a=i.querySelector(".tooltip-arrow");u.includes("top")?(a.classList.add("bottom"),a.style.top="100%",a.style.left=u.includes("right")?"94%":"20px"):(a.classList.add("top"),a.style.bottom="100%",a.style.left=u.includes("right")?"94%":"20px"),s=i,p=o}}));
package/dist/tooltip.css CHANGED
@@ -1,55 +1,64 @@
1
- .overlay {
2
- background: white;
3
- color: #111;
1
+ .tooltip-overlay {
4
2
  position: fixed;
5
- border-radius: 10px;
6
- z-index: 99999;
7
- box-shadow: 0 0 34px rgba(34, 60, 80, 0.2);
8
- overflow: hidden;
3
+ z-index: 9999;
4
+ pointer-events: none;
5
+ background: #53616E;
6
+ border-radius: 8px;
7
+ box-shadow: 0 4px 20px rgba(0,0,0,.25);
8
+ color: #DADADB;
9
+ max-width: 300px;
10
+ }
11
+
12
+ .tooltip-overlay.with-image {
13
+ max-width: 500px;
9
14
  }
10
15
 
11
16
  .tooltip-card {
12
17
  display: flex;
13
- height: 100%;
14
18
  align-items: center;
15
19
  gap: 16px;
16
20
  padding: 16px 20px;
17
- max-width: 500px;
18
21
  box-sizing: border-box;
19
- background: #53616E;
20
- }
21
-
22
- .tooltip-media {
23
- display: flex;
24
- justify-content: center;
25
22
  }
26
23
 
27
24
  .tooltip-image {
28
25
  width: 120px;
29
26
  height: 120px;
30
- object-fit: cover;
31
27
  border-radius: 8px;
28
+ object-fit: cover;
32
29
  }
33
30
 
34
31
  .tooltip-text {
35
32
  flex: 1;
36
33
  min-width: 0;
37
- display: flex;
38
- flex-direction: column;
39
- gap: 8px;
40
- }
41
-
42
- .tooltip-text div {
43
- width: 100%;
44
- display: block;
45
34
  }
46
35
 
47
36
  .tooltip-title {
48
- font-weight: 600;
37
+ font-weight: 300;
49
38
  line-height: 1.3;
39
+ margin: 0;
50
40
  }
51
41
 
52
42
  .tooltip-desc {
43
+ margin-top: 12px;
53
44
  line-height: 1.5;
54
- overflow-wrap: anywhere;
55
- }
45
+ font-weight: 300;
46
+ letter-spacing: 0.2px;
47
+ overflow-wrap: break-word;
48
+ }
49
+
50
+ .tooltip-arrow {
51
+ position: absolute;
52
+ width: 0;
53
+ height: 0;
54
+ border-left: 14px solid transparent;
55
+ border-right: 14px solid transparent;
56
+ }
57
+
58
+ .tooltip-arrow.top {
59
+ border-bottom: 30px solid #53616E;
60
+ }
61
+
62
+ .tooltip-arrow.bottom {
63
+ border-top: 30px solid #53616E;
64
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erain20029/tooltips",
3
- "version": "2.0.32",
3
+ "version": "2.0.33",
4
4
  "description": "Universal tooltip overlay for any HTML project",
5
5
  "license": "MIT",
6
6
  "author": "Erik",