@erain20029/tooltips 2.0.5 → 2.0.6

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,4 @@
1
- (function(d){typeof define=="function"&&define.amd?define(d):d()})((function(){"use strict";const d=".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{flex:0 0 120px;display:flex;align-items:flex-start}.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-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(E=>e.matches(E.selector));if(!o)return;const i=e.getBoundingClientRect(),l=S(i),{x:n,y:a}=b(l,i.left,i.top);C({tooltip:o,rect:i,x:n,y:a})},!0),document.addEventListener("mouseleave",t=>{s&&(t.target===s||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 r=0,c=0,s=null,m=null;function h(){s&&(s.remove(),s=null,m=null)}function b(t,e,o){switch(t){case"left-bottom":r=e,c=o+36;break;case"right-bottom":r=e-f+45,c=o+36;break;case"left-top":r=e,c=o-u-18;break;case"right-top":r=e-f+45,c=o-u-18;break}return{x:r,y:c}}function $(){const t=document.createElement("style");t.textContent=d,document.body.appendChild(t)}function T(t){const e=document.createElement("div");return e.className=t,e}function C(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`,y({title:e.size.title,description:e.size.description});const i=w({title:e.position.title,description:e.position.description,image:e.position.image});console.log(e);const n=e.image?`<img class="tooltip-image" src="http://localhost:3000${e.image}" alt="" />`:"";return o.innerHTML=`
1
+ (function(d){typeof define=="function"&&define.amd?define(d):d()})((function(){"use strict";const d=".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{flex:0 0 120px;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-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(E=>e.matches(E.selector));if(!o)return;const i=e.getBoundingClientRect(),l=S(i),{x:n,y:a}=b(l,i.left,i.top);C({tooltip:o,rect:i,x:n,y:a})},!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 s=0,c=0,r=null,m=null;function h(){r&&(r.remove(),r=null,m=null)}function b(t,e,o){switch(t){case"left-bottom":s=e,c=o+36;break;case"right-bottom":s=e-f+45,c=o+36;break;case"left-top":s=e,c=o-u-18;break;case"right-top":s=e-f+45,c=o-u-18;break}return{x:s,y:c}}function $(){const t=document.createElement("style");t.textContent=d,document.body.appendChild(t)}function T(t){const e=document.createElement("div");return e.className=t,e}function C(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`,y({title:e.size.title,description:e.size.description});const i=w({title:e.position.title,description:e.position.description,image:e.position.image});console.log(e);const n=e.image?`<img class="tooltip-image" src="http://localhost:3000${e.image}" alt="" />`:"";return o.innerHTML=`
2
2
  <div class="tooltip-card">
3
3
  ${i.image==="left"?`<div class="tooltip-media">
4
4
  ${n}
@@ -17,4 +17,4 @@
17
17
  ${n}
18
18
  </div>`:""}
19
19
  </div>
20
- `,document.body.appendChild(o),$(),s=o,m=t.rect,o}function S(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,a=l<o;return n&&a?"left-bottom":!n&&a?"right-bottom":n&&!a?"left-top":"right-top"}}));
20
+ `,document.body.appendChild(o),$(),r=o,m=t.rect,o}function S(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,a=l<o;return n&&a?"left-bottom":!n&&a?"right-bottom":n&&!a?"left-top":"right-top"}}));
package/dist/tooltip.css CHANGED
@@ -18,11 +18,9 @@
18
18
  box-sizing: border-box;
19
19
  }
20
20
 
21
- /* КАРТИНКА */
22
21
  .tooltip-media {
23
- flex: 0 0 120px; /* фикс */
22
+ flex: 0 0 120px;
24
23
  display: flex;
25
- align-items: flex-start; /* ❗ не center */
26
24
  }
27
25
 
28
26
  .tooltip-image {
@@ -48,4 +46,4 @@
48
46
  .tooltip-desc {
49
47
  line-height: 1.5;
50
48
  overflow-wrap: anywhere;
51
- }
49
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@erain20029/tooltips",
3
3
  "private": false,
4
- "version": "2.0.5",
4
+ "version": "2.0.6",
5
5
  "description": "Universal tooltip overlay for any HTML project",
6
6
  "main": "dist/tooltip-overlay.js",
7
7
  "style": "dist/tooltip.css",