dev-tooltip 1.0.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,23 @@
1
+ # dev-tooltip
2
+
3
+ Dev-only tooltips for frontend apps using `debug_*` attributes.
4
+ All debug attributes are automatically **removed from production builds**.
5
+
6
+ Built for **Vite + React**, with zero runtime cost in production.
7
+
8
+ ---
9
+
10
+ ## ✨ Features
11
+
12
+ - ✅ Dev-only tooltips (no production leakage)
13
+ - ✅ Build-time removal of `debug_*` attributes
14
+ - ✅ No manual runtime imports needed
15
+ - ✅ One-line Vite setup
16
+ - ✅ Zero impact on production bundle
17
+
18
+ ---
19
+
20
+ ## 📦 Installation
21
+
22
+ ```bash
23
+ npm install dev-tooltip
@@ -0,0 +1,16 @@
1
+ // dev-tooltip-build.js
2
+ export function devTooltipBuild(prefix = "debug_") {
3
+ return {
4
+ name: "dev-tooltip-build",
5
+ enforce: "pre",
6
+ transform(code, id) {
7
+ if (!/\.(jsx|tsx)$/.test(id)) return code;
8
+
9
+ const isProd = process.env.MODE === "production" || process.env.NODE_ENV === "production";
10
+ if (!isProd) return code;
11
+
12
+ const regex = new RegExp(`\\s${prefix}[a-zA-Z0-9_-]+=(?:"[^"]*"|'[^']*')`, "g");
13
+ return code.replace(regex, "");
14
+ },
15
+ };
16
+ }
@@ -0,0 +1,54 @@
1
+ // dev-tooltip-dev.js
2
+ export function devTooltipDev(prefix = "debug_") {
3
+ return {
4
+ name: "dev-tooltip-dev",
5
+ apply: "serve", // only runs in dev mode
6
+ transformIndexHtml() {
7
+ return {
8
+ tags: [
9
+ {
10
+ tag: "script",
11
+ injectTo: "body",
12
+ children: `
13
+ document.addEventListener("mouseover", (e) => {
14
+ const el = e.target.closest("[${prefix}title]");
15
+ if (!el) return;
16
+
17
+ const tooltip = document.createElement("div");
18
+ tooltip.textContent = el.getAttribute("${prefix}title");
19
+ tooltip.style.cssText = \`
20
+ position: fixed;
21
+ background: black;
22
+ color: white;
23
+ padding: 6px 10px;
24
+ font-size: 12px;
25
+ border-radius: 4px;
26
+ z-index: 9999;
27
+ pointer-events: none;
28
+ \`;
29
+
30
+ document.body.appendChild(tooltip);
31
+
32
+ const move = (ev) => {
33
+ tooltip.style.left = ev.clientX + 10 + "px";
34
+ tooltip.style.top = ev.clientY + 10 + "px";
35
+ };
36
+
37
+ document.addEventListener("mousemove", move);
38
+
39
+ el.addEventListener(
40
+ "mouseleave",
41
+ () => {
42
+ tooltip.remove();
43
+ document.removeEventListener("mousemove", move);
44
+ },
45
+ { once: true }
46
+ );
47
+ });
48
+ `,
49
+ },
50
+ ],
51
+ };
52
+ },
53
+ };
54
+ }
package/index.js ADDED
@@ -0,0 +1,12 @@
1
+ import { devTooltipDev } from "./dev-tooltip-dev.js";
2
+ import { devTooltipBuild } from "./dev-tooltip-build.js";
3
+
4
+ export function devTooltip(options = {}) {
5
+ const prefix = options.prefix ?? "debug_";
6
+ return [
7
+ devTooltipDev(prefix),
8
+ devTooltipBuild(prefix)
9
+ ];
10
+ }
11
+
12
+ export default devTooltip;
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "dev-tooltip",
3
+ "version": "1.0.0",
4
+ "description": "Dev-only tooltips using debug_* attributes, stripped from production builds",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "exports": {
8
+ ".": "./index.js"
9
+ },
10
+ "files": [
11
+ "index.js",
12
+ "dev-tooltip-dev.js",
13
+ "dev-tooltip-build.js"
14
+ ],
15
+ "keywords": [
16
+ "vite",
17
+ "debug",
18
+ "tooltip",
19
+ "react",
20
+ "devtools"
21
+ ],
22
+ "author": "Abhishek Kumar",
23
+ "license": "MIT"
24
+ }