@plumeria/inspector 16.2.1 → 16.2.2

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 CHANGED
@@ -2,11 +2,6 @@
2
2
 
3
3
  A development inspector for visualizing and debugging styled components in the browser.
4
4
 
5
- ## Features
6
-
7
- - **Inlined CSS** — No additional `.css` imports required. The stylesheet is bundled into the JavaScript output.
8
- - **Zero production overhead** — Renders `null` and skips CSS injection when `process.env.NODE_ENV === 'production'`. Safe to leave in your root layout.
9
-
10
5
  ## Documentation(Demo)
11
6
 
12
7
  Read the [documentation](https://plumeria.dev/docs/api-reference/components/inspector) for more details.
@@ -33,9 +28,17 @@ export default function RootLayout({ children }: { children: React.ReactNode })
33
28
  }
34
29
  ```
35
30
 
31
+ ## Props
32
+
33
+ | Prop | Type | Default | Description |
34
+ | --- | --- | --- | --- |
35
+ | `production` | `boolean` | `false` | If `true`, the inspector is enabled in production environments. |
36
+ | `initial` | `boolean` | `false` | If `true`, the inspector starts toggled ON. If `false`, it starts toggled OFF. |
37
+
36
38
  ## Keyboard Shortcuts
37
39
 
38
40
  | Shortcut | Action |
39
41
  | --- | --- |
40
42
  | `Cmd + I` / `Ctrl + I` | Toggle inspector |
41
43
  | `Shift` | Lock / unlock target element |
44
+
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
- export declare const Inspector: ({ production }: {
2
+ export declare const Inspector: ({ production, initial, }: {
3
3
  production?: boolean;
4
+ initial?: boolean;
4
5
  }) => React.JSX.Element | null;
package/dist/index.js CHANGED
@@ -30,21 +30,26 @@ var getClassName = (el) => {
30
30
  };
31
31
  var getStylesForElement = (el) => {
32
32
  const rulesFound = [];
33
- for (const sheet of Array.from(document.styleSheets)) {
33
+ const traverse = (rule) => {
34
34
  try {
35
- const rules = Array.from(sheet.cssRules || sheet.rules || []);
36
- for (const rule of rules) {
37
- if (rule instanceof CSSStyleRule) {
38
- if (el.matches(rule.selectorText)) {
35
+ const rules = "cssRules" in rule ? Array.from(rule.cssRules) : [];
36
+ for (const r of rules) {
37
+ if (r instanceof CSSStyleRule) {
38
+ if (el.matches(r.selectorText)) {
39
39
  rulesFound.push({
40
- selector: rule.selectorText,
41
- cssText: rule.style.cssText
40
+ selector: r.selectorText,
41
+ cssText: r.style.cssText
42
42
  });
43
43
  }
44
+ } else if ("cssRules" in r) {
45
+ traverse(r);
44
46
  }
45
47
  }
46
48
  } catch (e) {
47
49
  }
50
+ };
51
+ for (const sheet of Array.from(document.styleSheets)) {
52
+ traverse(sheet);
48
53
  }
49
54
  return rulesFound;
50
55
  };
@@ -59,11 +64,11 @@ var parseCssText = (cssText) => {
59
64
  };
60
65
  }).filter((x) => x !== null);
61
66
  };
62
- var DevInspector = () => {
67
+ var DevInspector = ({ initial }) => {
63
68
  React.useEffect(() => {
64
69
  injectInspectorCSS();
65
70
  }, []);
66
- const [isActive, setIsActive] = React.useState(true);
71
+ const [isActive, setIsActive] = React.useState(initial);
67
72
  const [isFrozen, setIsFrozen] = React.useState(false);
68
73
  const [hoveredElement, setHoveredElement] = React.useState(null);
69
74
  const [overlayStyle, setOverlayStyle] = React.useState({
@@ -120,6 +125,13 @@ var DevInspector = () => {
120
125
  document.removeEventListener("mouseover", handleMouseOver);
121
126
  };
122
127
  }, [isActive, isFrozen]);
128
+ React.useEffect(() => {
129
+ if (!hoveredElement || !isActive) {
130
+ setRules([]);
131
+ return;
132
+ }
133
+ setRules(getStylesForElement(hoveredElement));
134
+ }, [hoveredElement, isActive]);
123
135
  React.useEffect(() => {
124
136
  if (!hoveredElement || !isActive) return;
125
137
  const update = () => {
@@ -131,8 +143,6 @@ var DevInspector = () => {
131
143
  height: `${rect.height}px`,
132
144
  opacity: 1
133
145
  });
134
- const matchedRules = getStylesForElement(hoveredElement);
135
- setRules(matchedRules);
136
146
  const tooltipWidth = tooltipRef.current ? tooltipRef.current.offsetWidth : 320;
137
147
  const tooltipHeight = tooltipRef.current ? tooltipRef.current.offsetHeight : 180;
138
148
  const margin = 20;
@@ -217,7 +227,7 @@ var DevInspector = () => {
217
227
  getClassName(hoveredElement).split(" ").filter(Boolean).join(" .")
218
228
  ] })
219
229
  ] }),
220
- /* @__PURE__ */ jsx("div", { className: "xf05shqu xwflkjz8 xslz5qa9 xx3zn3a6 x6hkxz0i", children: rules.length === 0 ? /* @__PURE__ */ jsx("div", { className: "x7zjcec6 xw9ej4ts x9jma4hx", children: "No matching Plumeria CSS rules" }) : rules.map((rule, idx) => {
230
+ /* @__PURE__ */ jsx("div", { className: "xf05shqu xwflkjz8 xslz5qa9 xx3zn3a6 x6hkxz0i", children: rules.length === 0 ? /* @__PURE__ */ jsx("div", { className: "x7zjcec6 xw9ej4ts x9jma4hx", children: "No matching CSS rules" }) : rules.map((rule, idx) => {
221
231
  const parsedProps = parseCssText(rule.cssText);
222
232
  return /* @__PURE__ */ jsxs("div", { className: "xs291xkc", children: [
223
233
  /* @__PURE__ */ jsxs("span", { className: "xap91uzz xxkhp7ge x8eb0qpq x7zjcec6 x3f36k41", children: [
@@ -240,11 +250,14 @@ var DevInspector = () => {
240
250
  )
241
251
  ] });
242
252
  };
243
- var Inspector = ({ production = false }) => {
253
+ var Inspector = ({
254
+ production = false,
255
+ initial = false
256
+ }) => {
244
257
  if (!production && process.env.NODE_ENV === "production") {
245
258
  return null;
246
259
  }
247
- return /* @__PURE__ */ jsx(DevInspector, {});
260
+ return /* @__PURE__ */ jsx(DevInspector, { initial });
248
261
  };
249
262
  export {
250
263
  Inspector
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/inspector",
3
- "version": "16.2.1",
3
+ "version": "16.2.2",
4
4
  "description": "Styled components inspector for development",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -35,14 +35,14 @@
35
35
  "dist/"
36
36
  ],
37
37
  "dependencies": {
38
- "@plumeria/headlessui": "^16.2.1"
38
+ "@plumeria/headlessui": "^16.2.2"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/react": "^19.2.17",
42
42
  "@types/react-dom": "^19.2.3",
43
43
  "esbuild": "^0.28.0",
44
- "@plumeria/core": "^16.2.1",
45
- "@plumeria/unplugin": "^16.2.1"
44
+ "@plumeria/core": "^16.2.2",
45
+ "@plumeria/unplugin": "^16.2.2"
46
46
  },
47
47
  "publishConfig": {
48
48
  "access": "public"