@erain20029/tooltips 2.0.10 → 2.0.14
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 +23 -0
- package/package.json +12 -25
- package/dist/tooltip-overlay.umd.cjs +0 -23
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
(function(r,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(r=typeof globalThis<"u"?globalThis:r||self,a(r.TooltipOverlay={}))})(this,(function(r){"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}",f={tooltips:[],ready:!1},h=new Set;function w(t){return h.has(t)?Promise.resolve():new Promise((e,o)=>{const i=document.createElement("script");i.src=t,i.async=!0,i.onload=()=>{h.add(t),e()},i.onerror=()=>o(new Error(`Failed to load script: ${t}`)),document.head.appendChild(i)})}async function x(){if(f.ready)return;const t=localStorage.getItem("product");if(!t)return;const e=JSON.parse(t).id;await w(`http://localhost:3000/documentation/${e}/tooltip.js`),f.tooltips=await window.tooltipGetter(),f.ready=!0}async function b(t){await x();const e=t.target;if(!(e instanceof Element))return;const o=f.tooltips.find(j=>e.matches(j.selector));if(!o)return;const i=e.getBoundingClientRect(),l=O(i),{x:n,y:s}=C(l,i.left,i.top);k({tooltip:o,rect:i,x:n,y:s})}function $(t){c&&(t.target===c||t.target===g)&&y()}let v=!1;async function T(){v||(v=!0,await x(),document.addEventListener("mouseenter",b,!0),document.addEventListener("mouseleave",$,!0))}function z({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 S({title:t,description:e}){const o={small:14,medium:16,large:20};return{title:o[t]??16,description:o[e]??14}}const u=500,m=200;let d=0,p=0,c=null,g=null;function y(){c&&(c.remove(),c=null,g=null)}function C(t,e,o){switch(t){case"left-bottom":d=e,p=o+36;break;case"right-bottom":d=e-u+45,p=o+36;break;case"left-top":d=e,p=o-m-18;break;case"right-top":d=e-u+45,p=o-m-18;break}return{x:d,y:p}}function E(){const t=document.createElement("style");t.textContent=a,document.body.appendChild(t)}function H(t){const e=document.createElement("div");return e.className=t,e}function k(t){if(!t?.tooltip)return null;y();const e=t.tooltip,o=H("overlay");o.style.position="fixed",o.style.width=`${u}px`,o.style.height=`${m}px`,o.style.left=`${t.x}px`,o.style.top=`${t.y}px`;const i=S({title:e.size.title,description:e.size.description}),l=z({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
|
+
${l.image==="top"?`<div class="tooltip-media">
|
|
3
|
+
${s}
|
|
4
|
+
</div>`:""}
|
|
5
|
+
<div class="tooltip-card">
|
|
6
|
+
${l.image==="left"?`<div class="tooltip-media">
|
|
7
|
+
${s}
|
|
8
|
+
</div>`:""}
|
|
9
|
+
|
|
10
|
+
<div class="tooltip-text">
|
|
11
|
+
<div class="tooltip-title" style="font-size: ${i.title}px; text-align: ${l.title}">
|
|
12
|
+
${e.title}
|
|
13
|
+
</div>
|
|
14
|
+
<div class="tooltip-desc" style="font-size: ${i.description}px; text-align: ${l.description}">
|
|
15
|
+
${e.description}
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
${l.image==="right"?`<div class="tooltip-media">
|
|
20
|
+
${s}
|
|
21
|
+
</div>`:""}
|
|
22
|
+
</div>
|
|
23
|
+
`,document.body.appendChild(o),E(),c=o,g=t.rect,o}function O(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"}r.initTooltips=T,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@erain20029/tooltips",
|
|
3
|
-
"
|
|
4
|
-
"version": "2.0.10",
|
|
3
|
+
"version": "2.0.14",
|
|
5
4
|
"description": "Universal tooltip overlay for any HTML project",
|
|
6
|
-
"
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Erik",
|
|
7
|
+
"main": "dist/tooltip-overlay.umd.cjs",
|
|
8
|
+
"module": "dist/tooltip-overlay.es.js",
|
|
7
9
|
"style": "dist/tooltip.css",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/tooltip-overlay.es.js",
|
|
13
|
+
"require": "./dist/tooltip-overlay.umd.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
8
16
|
"files": [
|
|
9
17
|
"dist"
|
|
10
18
|
],
|
|
@@ -14,31 +22,10 @@
|
|
|
14
22
|
"html",
|
|
15
23
|
"js"
|
|
16
24
|
],
|
|
17
|
-
"author": "Erik",
|
|
18
|
-
"license": "MIT",
|
|
19
|
-
"type": "module",
|
|
20
25
|
"scripts": {
|
|
21
|
-
"
|
|
22
|
-
"build": "vite build && cp src/tooltip/tooltip.css dist/tooltip.css",
|
|
23
|
-
"lint": "eslint .",
|
|
24
|
-
"preview": "vite preview"
|
|
25
|
-
},
|
|
26
|
-
"dependencies": {
|
|
27
|
-
"react": "^19.2.0",
|
|
28
|
-
"react-dom": "^19.2.0"
|
|
26
|
+
"build": "vite build && cp src/tooltip/tooltip.css dist/tooltip.css"
|
|
29
27
|
},
|
|
30
28
|
"devDependencies": {
|
|
31
|
-
"@eslint/js": "^9.39.1",
|
|
32
|
-
"@types/node": "^24.10.1",
|
|
33
|
-
"@types/react": "^19.2.5",
|
|
34
|
-
"@types/react-dom": "^19.2.3",
|
|
35
|
-
"@vitejs/plugin-react": "^5.1.1",
|
|
36
|
-
"eslint": "^9.39.1",
|
|
37
|
-
"eslint-plugin-react-hooks": "^7.0.1",
|
|
38
|
-
"eslint-plugin-react-refresh": "^0.4.24",
|
|
39
|
-
"globals": "^16.5.0",
|
|
40
|
-
"typescript": "~5.9.3",
|
|
41
|
-
"typescript-eslint": "^8.46.4",
|
|
42
29
|
"vite": "^7.2.4"
|
|
43
30
|
}
|
|
44
31
|
}
|
|
@@ -1,23 +0,0 @@
|
|
|
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}",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
|
-
${l.image==="top"?`<div class="tooltip-media">
|
|
3
|
-
${s}
|
|
4
|
-
</div>`:""}
|
|
5
|
-
<div class="tooltip-card">
|
|
6
|
-
${l.image==="left"?`<div class="tooltip-media">
|
|
7
|
-
${s}
|
|
8
|
-
</div>`:""}
|
|
9
|
-
|
|
10
|
-
<div class="tooltip-text">
|
|
11
|
-
<div class="tooltip-title" style="font-size: ${i.title}px; text-align: ${l.title}">
|
|
12
|
-
${e.title}
|
|
13
|
-
</div>
|
|
14
|
-
<div class="tooltip-desc" style="font-size: ${i.description}px; text-align: ${l.description}">
|
|
15
|
-
${e.description}
|
|
16
|
-
</div>
|
|
17
|
-
</div>
|
|
18
|
-
|
|
19
|
-
${l.image==="right"?`<div class="tooltip-media">
|
|
20
|
-
${s}
|
|
21
|
-
</div>`:""}
|
|
22
|
-
</div>
|
|
23
|
-
`,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"}}));
|