@erain20029/tooltips 2.0.7 → 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.
- package/dist/tooltip-overlay.umd.cjs +8 -8
- package/dist/tooltip.css +33 -28
- package/package.json +1 -1
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
(function(
|
|
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
|
-
${
|
|
4
|
-
${
|
|
3
|
+
${l.image==="left"?`<div class="tooltip-media">
|
|
4
|
+
${s}
|
|
5
5
|
</div>`:""}
|
|
6
6
|
|
|
7
7
|
<div class="tooltip-text">
|
|
8
|
-
<div class="tooltip-title">
|
|
8
|
+
<div class="tooltip-title" style="font-size: ${i.title}px; text-align: ${l.title}">
|
|
9
9
|
${e.title}
|
|
10
10
|
</div>
|
|
11
|
-
<div class="tooltip-desc">
|
|
11
|
+
<div class="tooltip-desc" style="font-size: ${i.description}px; text-align: ${l.description}">
|
|
12
12
|
${e.description}
|
|
13
13
|
</div>
|
|
14
14
|
</div>
|
|
15
15
|
|
|
16
|
-
${
|
|
17
|
-
${
|
|
16
|
+
${l.image==="right"?`<div class="tooltip-media">
|
|
17
|
+
${s}
|
|
18
18
|
</div>`:""}
|
|
19
19
|
</div>
|
|
20
|
-
`,document.body.appendChild(o),$(),r=o,m=t.rect,o}function
|
|
20
|
+
`,document.body.appendChild(o),$(),r=o,m=t.rect,o}function C(t){const e=window.innerWidth/2,o=window.innerHeight/2,i=t.left+t.width/2,l=t.top+t.height/2,n=i<e,s=l<o;return n&&s?"left-bottom":!n&&s?"right-bottom":n&&!s?"left-top":"right-top"}}));
|
package/dist/tooltip.css
CHANGED
|
@@ -1,48 +1,53 @@
|
|
|
1
1
|
.overlay {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
22
|
+
display: flex;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
.tooltip-image {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
width: 120px;
|
|
27
|
+
height: 120px;
|
|
28
|
+
object-fit: cover;
|
|
29
|
+
border-radius: 8px;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
.tooltip-text {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
42
|
-
|
|
46
|
+
font-weight: 600;
|
|
47
|
+
line-height: 1.3;
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
.tooltip-desc {
|
|
46
|
-
|
|
47
|
-
|
|
51
|
+
line-height: 1.5;
|
|
52
|
+
overflow-wrap: anywhere;
|
|
48
53
|
}
|