@erain20029/tooltips 2.0.24 → 2.0.26

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 +1,123 @@
1
-
1
+ const x = ".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;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 = {
2
+ tooltips: [],
3
+ ready: !1
4
+ }, m = /* @__PURE__ */ new Set();
5
+ let r = null, f = null, h = !1;
6
+ function y(t) {
7
+ return m.has(t) ? Promise.resolve() : new Promise((e, n) => {
8
+ const o = document.createElement("script");
9
+ o.src = t, o.async = !0, o.onload = () => {
10
+ m.add(t), e();
11
+ }, o.onerror = () => n(new Error(`Failed to load script: ${t}`)), document.head.appendChild(o);
12
+ });
13
+ }
14
+ async function v() {
15
+ if (s.ready) return;
16
+ const t = localStorage.getItem("product");
17
+ if (!t) return;
18
+ const e = JSON.parse(t).id;
19
+ if (await y(
20
+ `http://localhost:3000/documentation/${e}/tooltip.js`
21
+ ), typeof window.tooltipGetter != "function") {
22
+ console.warn("tooltipGetter not ready");
23
+ return;
24
+ }
25
+ s.tooltips = await window.tooltipGetter(), s.ready = !0;
26
+ }
27
+ document.addEventListener(
28
+ "mouseenter",
29
+ async (t) => {
30
+ if (t.target.closest(".tooltip-overlay") || (await v(), !s.ready)) return;
31
+ const e = t.target;
32
+ if (!(e instanceof Element)) return;
33
+ const n = s.tooltips.find(
34
+ (d) => e.closest(d.selector)
35
+ );
36
+ if (!n) return;
37
+ const o = e.closest(n.selector), i = o.getBoundingClientRect(), a = T(i), { x: l, y: u } = b(
38
+ a,
39
+ i
40
+ );
41
+ S({
42
+ tooltip: n,
43
+ x: l,
44
+ y: u,
45
+ target: o
46
+ });
47
+ },
48
+ !0
49
+ );
50
+ document.addEventListener(
51
+ "mouseleave",
52
+ (t) => {
53
+ if (!r || !f) return;
54
+ const e = t.relatedTarget;
55
+ e && !r.contains(e) && !f.contains(e) && g();
56
+ },
57
+ !0
58
+ );
59
+ const c = 500, p = 200;
60
+ function w() {
61
+ if (h) return;
62
+ const t = document.createElement("style");
63
+ t.textContent = x, document.head.appendChild(t), h = !0;
64
+ }
65
+ function g() {
66
+ r && (r.remove(), r = null, f = null);
67
+ }
68
+ function b(t, e) {
69
+ let n = 0, o = 0;
70
+ const i = 16;
71
+ switch (t) {
72
+ case "left-bottom":
73
+ n = e.left, o = e.bottom + i;
74
+ break;
75
+ case "right-bottom":
76
+ n = e.right - c, o = e.bottom + i;
77
+ break;
78
+ case "left-top":
79
+ n = e.left, o = e.top - p - i;
80
+ break;
81
+ case "right-top":
82
+ n = e.right - c, o = e.top - p - i;
83
+ break;
84
+ }
85
+ return n = Math.max(8, Math.min(n, window.innerWidth - c - 8)), o = Math.max(8, Math.min(o, window.innerHeight - p - 8)), { x: n, y: o };
86
+ }
87
+ function T(t) {
88
+ const e = t.left + t.width / 2, n = t.top + t.height / 2, o = e < window.innerWidth / 2, i = n < window.innerHeight / 2;
89
+ return o && i ? "left-bottom" : !o && i ? "right-bottom" : o && !i ? "left-top" : "right-top";
90
+ }
91
+ function $({ title: t, description: e }) {
92
+ return {
93
+ title: t === "large" ? 20 : t === "small" ? 14 : 16,
94
+ description: e === "large" ? 16 : e === "small" ? 12 : 14
95
+ };
96
+ }
97
+ function E({ title: t, description: e, image: n }) {
98
+ return {
99
+ title: t || "left",
100
+ description: e || "left",
101
+ image: n || "left"
102
+ };
103
+ }
104
+ function S({ tooltip: t, x: e, y: n, target: o }) {
105
+ g(), w();
106
+ const i = document.createElement("div");
107
+ i.className = "tooltip-overlay", i.style.position = "fixed", i.style.width = `${c}px`, i.style.height = `${p}px`, i.style.left = `${e}px`, i.style.top = `${n}px`, i.style.zIndex = "999999";
108
+ const a = $(t.size || {}), l = E(t.position || {}), d = t.image ? `<img class="tooltip-image" src="http://localhost:3000${t.image}" />` : "";
109
+ i.innerHTML = `
110
+ <div class="tooltip-card">
111
+ ${l.image === "left" ? `<div>${d}</div>` : ""}
112
+ <div class="tooltip-text">
113
+ <div class="tooltip-title" style="font-size:${a.title}px;text-align:${l.title}">
114
+ ${t.title}
115
+ </div>
116
+ <div class="tooltip-desc" style="font-size:${a.description}px;text-align:${l.description}">
117
+ ${t.description}
118
+ </div>
119
+ </div>
120
+ ${l.image === "right" ? `<div>${d}</div>` : ""}
121
+ </div>
122
+ `, document.body.appendChild(i), r = i, f = o;
123
+ }
@@ -1 +1,14 @@
1
- (function(n){typeof define=="function"&&define.amd?define(n):n()})((function(){"use strict"}));
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;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,h=!1;function y(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 v(){if(s.ready)return;const t=localStorage.getItem("product");if(!t)return;const e=JSON.parse(t).id;if(await y(`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 v(),!s.ready))return;const e=t.target;if(!(e instanceof Element))return;const n=s.tooltips.find(u=>e.closest(u.selector));if(!n)return;const o=e.closest(n.selector),i=o.getBoundingClientRect(),f=T(i),{x:r,y:x}=b(f,i);S({tooltip:n,x:r,y:x,target:o})},!0),document.addEventListener("mouseleave",t=>{if(!l||!d)return;const e=t.relatedTarget;e&&!l.contains(e)&&!d.contains(e)&&g()},!0);const c=500,p=200;function w(){if(h)return;const t=document.createElement("style");t.textContent=a,document.head.appendChild(t),h=!0}function g(){l&&(l.remove(),l=null,d=null)}function b(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-c,o=e.bottom+i;break;case"left-top":n=e.left,o=e.top-p-i;break;case"right-top":n=e.right-c,o=e.top-p-i;break}return n=Math.max(8,Math.min(n,window.innerWidth-c-8)),o=Math.max(8,Math.min(o,window.innerHeight-p-8)),{x:n,y:o}}function T(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 $({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 S({tooltip:t,x:e,y:n,target:o}){g(),w();const i=document.createElement("div");i.className="tooltip-overlay",i.style.position="fixed",i.style.width=`${c}px`,i.style.height=`${p}px`,i.style.left=`${e}px`,i.style.top=`${n}px`,i.style.zIndex="999999";const f=$(t.size||{}),r=E(t.position||{}),u=t.image?`<img class="tooltip-image" src="http://localhost:3000${t.image}" />`:"";i.innerHTML=`
2
+ <div class="tooltip-card">
3
+ ${r.image==="left"?`<div>${u}</div>`:""}
4
+ <div class="tooltip-text">
5
+ <div class="tooltip-title" style="font-size:${f.title}px;text-align:${r.title}">
6
+ ${t.title}
7
+ </div>
8
+ <div class="tooltip-desc" style="font-size:${f.description}px;text-align:${r.description}">
9
+ ${t.description}
10
+ </div>
11
+ </div>
12
+ ${r.image==="right"?`<div>${u}</div>`:""}
13
+ </div>
14
+ `,document.body.appendChild(i),l=i,d=o}}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erain20029/tooltips",
3
- "version": "2.0.24",
3
+ "version": "2.0.26",
4
4
  "description": "Universal tooltip overlay for any HTML project",
5
5
  "license": "MIT",
6
6
  "author": "Erik",