@erain20029/tooltips 0.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.
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # React + TypeScript + Vite
2
+
3
+ This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
+
5
+ Currently, two official plugins are available:
6
+
7
+ - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
8
+ - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
+
10
+ ## React Compiler
11
+
12
+ The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
13
+
14
+ ## Expanding the ESLint configuration
15
+
16
+ If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
17
+
18
+ ```js
19
+ export default defineConfig([
20
+ globalIgnores(['dist']),
21
+ {
22
+ files: ['**/*.{ts,tsx}'],
23
+ extends: [
24
+ // Other configs...
25
+
26
+ // Remove tseslint.configs.recommended and replace with this
27
+ tseslint.configs.recommendedTypeChecked,
28
+ // Alternatively, use this for stricter rules
29
+ tseslint.configs.strictTypeChecked,
30
+ // Optionally, add this for stylistic rules
31
+ tseslint.configs.stylisticTypeChecked,
32
+
33
+ // Other configs...
34
+ ],
35
+ languageOptions: {
36
+ parserOptions: {
37
+ project: ['./tsconfig.node.json', './tsconfig.app.json'],
38
+ tsconfigRootDir: import.meta.dirname,
39
+ },
40
+ // other options...
41
+ },
42
+ },
43
+ ])
44
+ ```
45
+
46
+ You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
47
+
48
+ ```js
49
+ // eslint.config.js
50
+ import reactX from 'eslint-plugin-react-x'
51
+ import reactDom from 'eslint-plugin-react-dom'
52
+
53
+ export default defineConfig([
54
+ globalIgnores(['dist']),
55
+ {
56
+ files: ['**/*.{ts,tsx}'],
57
+ extends: [
58
+ // Other configs...
59
+ // Enable lint rules for React
60
+ reactX.configs['recommended-typescript'],
61
+ // Enable lint rules for React DOM
62
+ reactDom.configs.recommended,
63
+ ],
64
+ languageOptions: {
65
+ parserOptions: {
66
+ project: ['./tsconfig.node.json', './tsconfig.app.json'],
67
+ tsconfigRootDir: import.meta.dirname,
68
+ },
69
+ // other options...
70
+ },
71
+ },
72
+ ])
73
+ ```
@@ -0,0 +1,39 @@
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>
24
+
25
+ <div>
26
+ <span style="font-size: ${i.description}px; text-align: ${r.description}">
27
+ ${e.description}
28
+ </span>
29
+ <div>
30
+ </div>
31
+ ${r.image==="right"?`
32
+ <img
33
+ id="tooltip-image"
34
+ src="${n}${e.image}"
35
+ >
36
+ `:""}
37
+ </div>
38
+ </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"}}));
@@ -0,0 +1,49 @@
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);
10
+ }
11
+
12
+ .overlay .content {
13
+ width: 100%;
14
+ height: 100%;
15
+ display: flex;
16
+ align-items: center;
17
+ gap: 16px;
18
+ padding: 0 24px;
19
+ }
20
+
21
+ .overlay .content .text-container {
22
+ display: flex;
23
+ }
24
+
25
+ .overlay .content .text-container:nth-child(2) {
26
+ margin-top: 8px;
27
+ }
28
+
29
+ #tooltip-image {
30
+ width: 120px;
31
+ height: 120px;
32
+ object-fit: cover;
33
+ }
34
+
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
45
+ }
46
+
47
+ /* .overlay .content .text-container div #description {
48
+
49
+ } */
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@erain20029/tooltips",
3
+ "private": false,
4
+ "version": "0.1.0",
5
+ "description": "Universal tooltip overlay for any HTML project",
6
+ "main": "dist/tooltip-overlay.js",
7
+ "style": "dist/tooltip.css",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "keywords": [
12
+ "tooltip",
13
+ "overlay",
14
+ "html",
15
+ "js"
16
+ ],
17
+ "author": "Erik",
18
+ "license": "MIT",
19
+ "type": "module",
20
+ "scripts": {
21
+ "dev": "vite",
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"
29
+ },
30
+ "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
+ "vite": "^7.2.4"
43
+ }
44
+ }