@erain20029/tooltips 1.0.0 → 1.1.0

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,39 +1,16 @@
1
- (function(p){typeof define=="function"&&define.amd?define(p):p()})((function(){"use strict";const p=".overlay{background:#fff;color:#111;position:fixed;border-radius:10px;z-index:99999;box-shadow:0 0 34px #223c5033;overflow:hidden}.tooltip-card{width:100%;height:100%;display:flex;flex-direction:column}.tooltip-body{height:100%;display:flex;gap:16px;padding:16px 20px;align-items:center;box-sizing:border-box}.tooltip-media{flex:0 0 auto;display:flex;align-items:center;justify-content:center}.tooltip-media--top{padding:16px 20px 0}.tooltip-image{width:120px;height:120px;object-fit:cover;border-radius:8px;display:block;flex-shrink:0}.tooltip-text{flex:1 1 auto;min-width:0;display:flex;flex-direction:column;gap:8px}.tooltip-title{font-weight:600;line-height:1.25;overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}.tooltip-desc{font-weight:300;line-height:1.5;letter-spacing:.2px;overflow-wrap:anywhere;-webkit-hyphens:auto;hyphens:auto;overflow:hidden;display:-webkit-box;-webkit-line-clamp:5;-webkit-box-orient:vertical}.tooltip--image-top .tooltip-body{align-items:flex-start}",d={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 w(){if(d.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`),d.tooltips=await window.tooltipGetter(),d.ready=!0}document.addEventListener("mouseenter",async t=>{await w();const e=t.target;if(!e||!(e instanceof Element))return;const o=d.tooltips.find(C=>e.matches(C.selector));if(!o)return;const i=e.getBoundingClientRect(),l=z(i),{x:n,y:a}=v(l,i.left,i.top);T({tooltip:o,rect:i,x:n,y:a})},!0),document.addEventListener("mouseleave",t=>{s&&(t.target===s||t.target===m)&&h()},!0);function y({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 b({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 v(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=p,document.body.appendChild(t)}function k(t){const e=document.createElement("div");return e.className=t,e}function T(t){if(!t?.tooltip)return null;h();const e=t.tooltip,o=k("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=b({title:e.size.title,description:e.size.description}),l=y({title:e.position.title,description:e.position.description,image:e.position.image});console.log(e);const n="http://localhost:3000";return o.innerHTML=`
2
- <div class="content">
3
- ${l.image==="top"?`
4
- <div class="image-container">
5
- <img
6
- id="tooltip-image"
7
- src="${n}${e.image}"
8
- >
9
- </div>
10
- `:""}
11
- <div class="text-container">
12
- ${l.image==="left"?`
13
- <img
14
- id="tooltip-image"
15
- src="${n}${e.image}"
16
- >
17
- `:""}
18
- <div class="text-content">
19
- <div>
20
- <span style="font-size: ${i.title}px; text-align: ${l.title}">
21
- ${e.title}
22
- </span>
23
- </div>
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;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 w(){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 w();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 v({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 T(){const t=document.createElement("style");t.textContent=d,document.body.appendChild(t)}function $(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=$("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}),v({title:e.position.title,description:e.position.description,image:e.position.image}),console.log(e);const l=e.image?`<img class="tooltip-image" src="http://localhost:3000${e.image}" alt="" />`:"";return o.innerHTML=`
2
+ <div class="tooltip-card">
3
+ <div class="tooltip-media">
4
+ ${l}
5
+ </div>
24
6
 
25
- <div>
26
- <span style="font-size: ${i.description}px; text-align: ${l.description}">
27
- ${e.description}
28
- </span>
29
- <div>
7
+ <div class="tooltip-text">
8
+ <div class="tooltip-title">
9
+ ${e.title}
10
+ </div>
11
+ <div class="tooltip-desc">
12
+ ${e.description}
30
13
  </div>
31
- ${l.image==="right"?`
32
- <img
33
- id="tooltip-image"
34
- src="${n}${e.image}"
35
- >
36
- `:""}
37
14
  </div>
38
15
  </div>
39
- `,document.body.appendChild(o),$(),s=o,m=t.rect,o}function z(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"}}));
16
+ `,document.body.appendChild(o),T(),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
@@ -5,87 +5,45 @@
5
5
  border-radius: 10px;
6
6
  z-index: 99999;
7
7
  box-shadow: 0 0 34px rgba(34, 60, 80, 0.2);
8
- overflow: hidden; /* важно, чтобы скругление работало */
8
+ overflow: hidden;
9
9
  }
10
10
 
11
11
  .tooltip-card {
12
- width: 100%;
13
- height: 100%;
14
- display: flex;
15
- flex-direction: column;
16
- }
17
-
18
- /* BODY: общий контейнер контента */
19
- .tooltip-body {
20
- height: 100%;
21
12
  display: flex;
22
13
  gap: 16px;
23
14
  padding: 16px 20px;
24
- align-items: center;
15
+ max-width: 500px;
25
16
  box-sizing: border-box;
26
17
  }
27
18
 
28
- /* MEDIA: картинка никогда не сжимается */
19
+ /* КАРТИНКА */
29
20
  .tooltip-media {
30
- flex: 0 0 auto;
21
+ flex: 0 0 120px; /* фикс */
31
22
  display: flex;
32
- align-items: center;
33
- justify-content: center;
34
- }
35
-
36
- /* TOP картинка — отдельный блок сверху */
37
- .tooltip-media--top {
38
- padding: 16px 20px 0 20px;
23
+ align-items: flex-start; /* ❗ не center */
39
24
  }
40
25
 
41
- .tooltip-media--side {
42
- /* сбоку */
43
- }
44
-
45
- /* сама картинка */
46
26
  .tooltip-image {
47
27
  width: 120px;
48
28
  height: 120px;
49
29
  object-fit: cover;
50
30
  border-radius: 8px;
51
- display: block;
52
- flex-shrink: 0; /* критично */
53
31
  }
54
32
 
55
- /* TEXT: занимает всё оставшееся место */
56
33
  .tooltip-text {
57
- flex: 1 1 auto;
58
- min-width: 0; /* критично для переноса/ellipsis в flex */
34
+ flex: 1;
35
+ min-width: 0;
59
36
  display: flex;
60
37
  flex-direction: column;
61
38
  gap: 8px;
62
39
  }
63
40
 
64
- /* Заголовок — максимум 2 строки */
65
41
  .tooltip-title {
66
42
  font-weight: 600;
67
- line-height: 1.25;
68
- overflow: hidden;
69
- display: -webkit-box;
70
- -webkit-line-clamp: 2;
71
- -webkit-box-orient: vertical;
43
+ line-height: 1.3;
72
44
  }
73
45
 
74
- /* Описание — максимум N строк + мягкий перенос */
75
46
  .tooltip-desc {
76
- font-weight: 300;
77
47
  line-height: 1.5;
78
- letter-spacing: .2px;
79
48
  overflow-wrap: anywhere;
80
- hyphens: auto;
81
-
82
- overflow: hidden;
83
- display: -webkit-box;
84
- -webkit-line-clamp: 5; /* регулируй */
85
- -webkit-box-orient: vertical;
86
- }
87
-
88
- /* Если картинка сверху — body должен стартовать сверху, а не по центру */
89
- .tooltip--image-top .tooltip-body {
90
- align-items: flex-start;
91
49
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@erain20029/tooltips",
3
3
  "private": false,
4
- "version": "1.0.0",
4
+ "version": "1.1.0",
5
5
  "description": "Universal tooltip overlay for any HTML project",
6
6
  "main": "dist/tooltip-overlay.js",
7
7
  "style": "dist/tooltip.css",