@erain20029/tooltips 2.0.9 → 2.0.12

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,7 @@
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=`
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>`:""}
2
5
  <div class="tooltip-card">
3
6
  ${l.image==="left"?`<div class="tooltip-media">
4
7
  ${s}
@@ -17,4 +20,4 @@
17
20
  ${s}
18
21
  </div>`:""}
19
22
  </div>
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"}}));
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/dist/tooltip.css CHANGED
@@ -20,6 +20,7 @@
20
20
 
21
21
  .tooltip-media {
22
22
  display: flex;
23
+ justify-content: center;
23
24
  }
24
25
 
25
26
  .tooltip-image {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@erain20029/tooltips",
3
3
  "private": false,
4
- "version": "2.0.9",
4
+ "version": "2.0.12",
5
5
  "description": "Universal tooltip overlay for any HTML project",
6
6
  "main": "dist/tooltip-overlay.js",
7
7
  "style": "dist/tooltip.css",
@@ -37,6 +37,7 @@
37
37
  "eslint-plugin-react-hooks": "^7.0.1",
38
38
  "eslint-plugin-react-refresh": "^0.4.24",
39
39
  "globals": "^16.5.0",
40
+ "tailwindcss": "^3.4.19",
40
41
  "typescript": "~5.9.3",
41
42
  "typescript-eslint": "^8.46.4",
42
43
  "vite": "^7.2.4"