@erain20029/tooltips 2.0.8 → 2.0.9

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,4 +1,4 @@
1
- (function(d){typeof define=="function"&&define.amd?define(d):d()})((function(){"use strict";const d=".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}.tooltip-media{display:flex}.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-title{font-weight:600;line-height:1.3}.tooltip-desc{line-height:1.5;overflow-wrap:anywhere}",p={tooltips:[],ready:!1},g=new Set;function x(t){return g.has(t)?Promise.resolve():new Promise((e,o)=>{const i=document.createElement("script");i.src=t,i.async=!0,i.onload=()=>{g.add(t),e()},i.onerror=()=>o(new Error(`Failed to load script: ${t}`)),document.head.appendChild(i)})}async function v(){if(p.ready)return;const t=localStorage.getItem("product");if(!t)return;const e=JSON.parse(t).id;await x(`http://localhost:3000/documentation/${e}/tooltip.js`),p.tooltips=await window.tooltipGetter(),p.ready=!0}document.addEventListener("mouseenter",async t=>{await v();const e=t.target;if(!e||!(e instanceof Element))return;const o=p.tooltips.find(S=>e.matches(S.selector));if(!o)return;const i=e.getBoundingClientRect(),l=C(i),{x:n,y:s}=b(l,i.left,i.top);z({tooltip:o,rect:i,x:n,y:s})},!0),document.addEventListener("mouseleave",t=>{r&&(t.target===r||t.target===m)&&h()},!0);function w({title:t,description:e,image:o}){const i=n=>n==="center"||n==="right"?n:"left",l=n=>n==="top"||n==="right"?n:"left";return{title:i(t),description:i(e),image:l(o)}}function y({title:t,description:e}){const o={small:14,medium:16,large:20};return{title:o[t]??16,description:o[e]??14}}const f=500,u=200;let c=0,a=0,r=null,m=null;function h(){r&&(r.remove(),r=null,m=null)}function b(t,e,o){switch(t){case"left-bottom":c=e,a=o+36;break;case"right-bottom":c=e-f+45,a=o+36;break;case"left-top":c=e,a=o-u-18;break;case"right-top":c=e-f+45,a=o-u-18;break}return{x:c,y:a}}function $(){const t=document.createElement("style");t.textContent=d,document.body.appendChild(t)}function T(t){const e=document.createElement("div");return e.className=t,e}function z(t){if(!t?.tooltip)return null;h();const e=t.tooltip,o=T("overlay");o.style.position="fixed",o.style.width=`${f}px`,o.style.height=`${u}px`,o.style.left=`${t.x}px`,o.style.top=`${t.y}px`;const i=y({title:e.size.title,description:e.size.description}),l=w({title:e.position.title,description:e.position.description,image:e.position.image});console.log(e);const s=e.image?`<img class="tooltip-image" src="http://localhost:3000${e.image}" alt="" />`:"";return o.innerHTML=`
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}.tooltip-media{display:flex}.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}",p={tooltips:[],ready:!1},g=new Set;function x(t){return g.has(t)?Promise.resolve():new Promise((e,o)=>{const i=document.createElement("script");i.src=t,i.async=!0,i.onload=()=>{g.add(t),e()},i.onerror=()=>o(new Error(`Failed to load script: ${t}`)),document.head.appendChild(i)})}async function v(){if(p.ready)return;const t=localStorage.getItem("product");if(!t)return;const e=JSON.parse(t).id;await x(`http://localhost:3000/documentation/${e}/tooltip.js`),p.tooltips=await window.tooltipGetter(),p.ready=!0}document.addEventListener("mouseenter",async t=>{await v();const e=t.target;if(!e||!(e instanceof Element))return;const o=p.tooltips.find(S=>e.matches(S.selector));if(!o)return;const i=e.getBoundingClientRect(),l=C(i),{x:n,y:s}=b(l,i.left,i.top);z({tooltip:o,rect:i,x:n,y:s})},!0),document.addEventListener("mouseleave",t=>{r&&(t.target===r||t.target===m)&&h()},!0);function w({title:t,description:e,image:o}){const i=n=>n==="center"||n==="right"?n:"left",l=n=>n==="top"||n==="right"?n:"left";return{title:i(t),description:i(e),image:l(o)}}function y({title:t,description:e}){const o={small:14,medium:16,large:20};return{title:o[t]??16,description:o[e]??14}}const f=500,u=200;let c=0,d=0,r=null,m=null;function h(){r&&(r.remove(),r=null,m=null)}function b(t,e,o){switch(t){case"left-bottom":c=e,d=o+36;break;case"right-bottom":c=e-f+45,d=o+36;break;case"left-top":c=e,d=o-u-18;break;case"right-top":c=e-f+45,d=o-u-18;break}return{x:c,y:d}}function $(){const t=document.createElement("style");t.textContent=a,document.body.appendChild(t)}function T(t){const e=document.createElement("div");return e.className=t,e}function z(t){if(!t?.tooltip)return null;h();const e=t.tooltip,o=T("overlay");o.style.position="fixed",o.style.width=`${f}px`,o.style.height=`${u}px`,o.style.left=`${t.x}px`,o.style.top=`${t.y}px`;const i=y({title:e.size.title,description:e.size.description}),l=w({title:e.position.title,description:e.position.description,image:e.position.image});console.log(e);const s=e.image?`<img class="tooltip-image" src="http://localhost:3000${e.image}" alt="" />`:"";return o.innerHTML=`
2
2
  <div class="tooltip-card">
3
3
  ${l.image==="left"?`<div class="tooltip-media">
4
4
  ${s}
package/dist/tooltip.css CHANGED
@@ -1,48 +1,53 @@
1
1
  .overlay {
2
- background: white;
3
- color: #111;
4
- 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;
2
+ background: white;
3
+ color: #111;
4
+ 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;
9
9
  }
10
10
 
11
11
  .tooltip-card {
12
- display: flex;
13
- height: 100%;
14
- align-items: center;
15
- gap: 16px;
16
- padding: 16px 20px;
17
- max-width: 500px;
18
- box-sizing: border-box;
12
+ display: flex;
13
+ height: 100%;
14
+ align-items: center;
15
+ gap: 16px;
16
+ padding: 16px 20px;
17
+ max-width: 500px;
18
+ box-sizing: border-box;
19
19
  }
20
20
 
21
21
  .tooltip-media {
22
- display: flex;
22
+ display: flex;
23
23
  }
24
24
 
25
25
  .tooltip-image {
26
- width: 120px;
27
- height: 120px;
28
- object-fit: cover;
29
- border-radius: 8px;
26
+ width: 120px;
27
+ height: 120px;
28
+ object-fit: cover;
29
+ border-radius: 8px;
30
30
  }
31
31
 
32
32
  .tooltip-text {
33
- flex: 1;
34
- min-width: 0;
35
- display: flex;
36
- flex-direction: column;
37
- gap: 8px;
33
+ flex: 1;
34
+ min-width: 0;
35
+ display: flex;
36
+ flex-direction: column;
37
+ gap: 8px;
38
+ }
39
+
40
+ .tooltip-text div {
41
+ width: 100%;
42
+ display: block;
38
43
  }
39
44
 
40
45
  .tooltip-title {
41
- font-weight: 600;
42
- line-height: 1.3;
46
+ font-weight: 600;
47
+ line-height: 1.3;
43
48
  }
44
49
 
45
50
  .tooltip-desc {
46
- line-height: 1.5;
47
- overflow-wrap: anywhere;
51
+ line-height: 1.5;
52
+ overflow-wrap: anywhere;
48
53
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@erain20029/tooltips",
3
3
  "private": false,
4
- "version": "2.0.8",
4
+ "version": "2.0.9",
5
5
  "description": "Universal tooltip overlay for any HTML project",
6
6
  "main": "dist/tooltip-overlay.js",
7
7
  "style": "dist/tooltip.css",