@erain20029/tooltips 2.0.33 → 2.0.35
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.js +77 -13
- package/package.json +1 -1
|
@@ -1,15 +1,79 @@
|
|
|
1
|
-
(function(c){typeof define=="function"&&define.amd?define(c):c()})((function(){"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
(function(c){typeof define=="function"&&define.amd?define(c):c()})((function(){"use strict";(function(){const c=`
|
|
2
|
+
.tooltip-overlay {
|
|
3
|
+
position: fixed;
|
|
4
|
+
z-index: 9999;
|
|
5
|
+
pointer-events: none;
|
|
6
|
+
background: #53616E;
|
|
7
|
+
border-radius: 8px;
|
|
8
|
+
box-shadow: 0 4px 20px rgba(0,0,0,.25);
|
|
9
|
+
color: #DADADB;
|
|
10
|
+
max-width: 300px;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.tooltip-overlay.with-image {
|
|
14
|
+
max-width: 500px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.tooltip-card {
|
|
18
|
+
display: flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
gap: 16px;
|
|
21
|
+
padding: 16px 20px;
|
|
22
|
+
box-sizing: border-box;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.tooltip-image {
|
|
26
|
+
width: 120px;
|
|
27
|
+
height: 120px;
|
|
28
|
+
border-radius: 8px;
|
|
29
|
+
object-fit: cover;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.tooltip-text {
|
|
33
|
+
flex: 1;
|
|
34
|
+
min-width: 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.tooltip-title {
|
|
38
|
+
font-weight: 300;
|
|
39
|
+
line-height: 1.3;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.tooltip-desc {
|
|
43
|
+
margin-top: 12px;
|
|
44
|
+
line-height: 1.5;
|
|
45
|
+
font-weight: 300;
|
|
46
|
+
letter-spacing: .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
|
+
}
|
|
65
|
+
`,a={tooltips:[],ready:!1};let r=null,p=null,f=!1;const m=new Set;function y(){if(f)return;const t=document.createElement("style");t.textContent=c,document.head.appendChild(t),f=!0}function b(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 v(){if(a.ready)return;const t=localStorage.getItem("product");if(!t)return;const e=JSON.parse(t).id;await b(`http://localhost:3000/documentation/${e}/tooltip.js`),typeof window.tooltipGetter=="function"&&(a.tooltips=await window.tooltipGetter(),a.ready=!0)}function E({title:t,description:e}){return{title:t==="large"?22:t==="small"?14:18,description:e==="large"?16:e==="small"?12:14}}function P({title:t,description:e,image:o}){return{title:t||"left",description:e||"left",image:o||"left"}}function $(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 S(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 T({tooltip:t,target:e}){g(),y();const o=document.createElement("div");o.className="tooltip-overlay",o.style.left="-9999px",o.style.top="-9999px";const i=E(t.size||{}),n=P(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
|
+
<div class="tooltip-arrow"></div>
|
|
67
|
+
<div class="tooltip-card">
|
|
68
|
+
${n.image==="left"?h:""}
|
|
69
|
+
<div class="tooltip-text">
|
|
70
|
+
<div class="tooltip-title" style="font-size:${i.title}px;text-align:${n.title}">
|
|
71
|
+
${t.title}
|
|
72
|
+
</div>
|
|
73
|
+
<div class="tooltip-desc" style="font-size:${i.description}px;text-align:${n.description}">
|
|
74
|
+
${t.description}
|
|
75
|
+
</div>
|
|
11
76
|
</div>
|
|
77
|
+
${n.image==="right"?h:""}
|
|
12
78
|
</div>
|
|
13
|
-
|
|
14
|
-
</div>
|
|
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}}));
|
|
79
|
+
`,document.body.appendChild(o);const x=e.getBoundingClientRect(),{width:A,height:L}=o.getBoundingClientRect(),u=$(x),w=S(u,x,A,L);o.style.left=w.x+"px",o.style.top=w.y+"px";const d=o.querySelector(".tooltip-arrow");u.includes("top")?(d.classList.add("bottom"),d.style.top="100%"):(d.classList.add("top"),d.style.bottom="100%"),d.style.left=u.includes("right")?"94%":"20px",r=o,p=e}document.addEventListener("mouseenter",async t=>{if(t.target.closest(".tooltip-overlay")||(await v(),!a.ready))return;const e=t.target;if(!(e instanceof Element))return;const o=a.tooltips.find(i=>e.closest(i.selector));o&&T({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)})()}));
|