@erain20029/tooltips 0.1.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-color:#fff;color:#000;position:fixed;border-radius:6px;z-index:99999;-webkit-box-shadow:0px 0px 34px 0px rgba(34,60,80,.2);-moz-box-shadow:0px 0px 34px 0px rgba(34,60,80,.2);box-shadow:0 0 34px #223c5033}.overlay .content{width:100%;height:100%;display:flex;align-items:center;gap:16px;padding:0 24px}.overlay .content .text-container{display:flex}.overlay .content .text-container:nth-child(2){margin-top:8px}#tooltip-image{width:120px;height:120px;object-fit:cover}.overlay .content .text-container div span{max-width:90%;margin:10px auto;font-weight:300;display:block;text-align-last:"center";line-height:1.5;letter-spacing:.2px;-webkit-hyphens:auto;hyphens:auto;overflow-wrap:break-word}',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 v(){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 v();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(),r=k(i),{x:n,y:c}=b(r,i.left,i.top);z({tooltip:o,rect:i,x:n,y:c})},!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",r=n=>n==="top"||n==="right"?n:"left";return{title:i(t),description:i(e),image:r(o)}}function w({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 l=0,a=0,s=null,m=null;function h(){s&&(s.remove(),s=null,m=null)}function b(t,e,o){switch(t){case"left-bottom":l=e,a=o+36;break;case"right-bottom":l=e-f+45,a=o+36;break;case"left-top":l=e,a=o-u-18;break;case"right-top":l=e-f+45,a=o-u-18;break}return{x:l,y:a}}function $(){const t=document.createElement("style");t.textContent=p,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=w({title:e.size.title,description:e.size.description}),r=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
- ${r.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
- ${r.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: ${r.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: ${r.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
- ${r.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 k(t){const e=window.innerWidth/2,o=window.innerHeight/2,i=t.left+t.width/2,r=t.top+t.height/2,n=i<e,c=r<o;return n&&c?"left-bottom":!n&&c?"right-bottom":n&&!c?"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
@@ -1,49 +1,49 @@
1
1
  .overlay {
2
- background-color: white;
3
- color: black;
4
- position: fixed;
5
- border-radius: 6px;
6
- z-index: 99999;
7
- -webkit-box-shadow: 0px 0px 34px 0px rgba(34, 60, 80, 0.2);
8
- -moz-box-shadow: 0px 0px 34px 0px rgba(34, 60, 80, 0.2);
9
- box-shadow: 0px 0px 34px 0px rgba(34, 60, 80, 0.2);
2
+ background: white;
3
+ color: #111;
4
+ position: fixed;
5
+ border-radius: 10px;
6
+ z-index: 99999;
7
+ box-shadow: 0 0 34px rgba(34, 60, 80, 0.2);
8
+ overflow: hidden;
10
9
  }
11
10
 
12
- .overlay .content {
13
- width: 100%;
14
- height: 100%;
15
- display: flex;
16
- align-items: center;
17
- gap: 16px;
18
- padding: 0 24px;
11
+ .tooltip-card {
12
+ display: flex;
13
+ gap: 16px;
14
+ padding: 16px 20px;
15
+ max-width: 500px;
16
+ box-sizing: border-box;
19
17
  }
20
18
 
21
- .overlay .content .text-container {
22
- display: flex;
19
+ /* КАРТИНКА */
20
+ .tooltip-media {
21
+ flex: 0 0 120px; /* фикс */
22
+ display: flex;
23
+ align-items: flex-start; /* ❗ не center */
23
24
  }
24
25
 
25
- .overlay .content .text-container:nth-child(2) {
26
- margin-top: 8px;
26
+ .tooltip-image {
27
+ width: 120px;
28
+ height: 120px;
29
+ object-fit: cover;
30
+ border-radius: 8px;
27
31
  }
28
32
 
29
- #tooltip-image {
30
- width: 120px;
31
- height: 120px;
32
- object-fit: cover;
33
+ .tooltip-text {
34
+ flex: 1;
35
+ min-width: 0;
36
+ display: flex;
37
+ flex-direction: column;
38
+ gap: 8px;
33
39
  }
34
40
 
35
- .overlay .content .text-container div span {
36
- max-width: 90%;
37
- margin: 10px auto;
38
- font-weight: 300;
39
- display: block;
40
- text-align-last: "center";
41
- line-height: 1.5;
42
- letter-spacing: .2px;
43
- hyphens: auto;
44
- overflow-wrap: break-word
41
+ .tooltip-title {
42
+ font-weight: 600;
43
+ line-height: 1.3;
45
44
  }
46
45
 
47
- /* .overlay .content .text-container div #description {
48
-
49
- } */
46
+ .tooltip-desc {
47
+ line-height: 1.5;
48
+ overflow-wrap: anywhere;
49
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@erain20029/tooltips",
3
3
  "private": false,
4
- "version": "0.1.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",
@@ -41,4 +41,4 @@
41
41
  "typescript-eslint": "^8.46.4",
42
42
  "vite": "^7.2.4"
43
43
  }
44
- }
44
+ }