react-reinspect 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # react-reinspect
2
+
3
+ Visual runtime inspector for React components with render counters and style overrides.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add react-reinspect
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```tsx
14
+ import {
15
+ DEFAULT_EDITABLE_PROPS,
16
+ ReinspectProvider,
17
+ type ReinspectConfig,
18
+ } from 'react-reinspect'
19
+
20
+ const reinspectConfig: ReinspectConfig = {
21
+ enabled: import.meta.env.DEV,
22
+ startActive: true,
23
+ showFloatingToggle: true,
24
+ inspectMode: 'first-party',
25
+ editableProps: DEFAULT_EDITABLE_PROPS,
26
+ }
27
+
28
+ export function AppShell({ children }: { children: React.ReactNode }) {
29
+ return <ReinspectProvider config={reinspectConfig}>{children}</ReinspectProvider>
30
+ }
31
+ ```
32
+
33
+ ## Publish Workflow
34
+
35
+ The repository can still contain a local debug app, but npm publish only ships:
36
+
37
+ - `dist/lib`
38
+ - `README.md`
39
+
40
+ This is controlled by the `files` whitelist in `package.json`.
41
+
42
+ ### 1) Build the publishable package
43
+
44
+ ```bash
45
+ pnpm build:lib
46
+ ```
47
+
48
+ ### 2) Verify what npm will publish
49
+
50
+ ```bash
51
+ pnpm pack:check
52
+ ```
53
+
54
+ ### 3) Publish
55
+
56
+ ```bash
57
+ npm login
58
+ pnpm publish:npm
59
+ ```
60
+
61
+ ## Local Development
62
+
63
+ ```bash
64
+ pnpm dev
65
+ pnpm test
66
+ ```
@@ -0,0 +1,9 @@
1
+ import type { ComponentType } from 'react';
2
+ import type { AutoDiscoverScope } from './types';
3
+ export interface AutoWrapInspectableMetadata {
4
+ componentName?: string;
5
+ fallbackName?: string;
6
+ scope: AutoDiscoverScope;
7
+ }
8
+ export declare function autoWrapInspectable<P extends object>(Component: ComponentType<P>, metadata: AutoWrapInspectableMetadata): ComponentType<P>;
9
+ //# sourceMappingURL=autoWrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autoWrap.d.ts","sourceRoot":"","sources":["../../src/reinspect/autoWrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAIhD,MAAM,WAAW,2BAA2B;IAC1C,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,EAAE,iBAAiB,CAAA;CACzB;AAED,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,EAClD,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,EAC3B,QAAQ,EAAE,2BAA2B,GACpC,aAAa,CAAC,CAAC,CAAC,CAYlB"}
@@ -0,0 +1,7 @@
1
+ import type { EditableStyleProp } from './types';
2
+ export declare const DEFAULT_EDITABLE_PROPS: EditableStyleProp[];
3
+ export declare const DEFAULT_PALETTE: string[];
4
+ export declare const COLOR_STYLE_PROPS: Set<EditableStyleProp>;
5
+ export declare const NUMERIC_STYLE_PROPS: Set<EditableStyleProp>;
6
+ export declare const OPACITY_STYLE_PROP: EditableStyleProp;
7
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/reinspect/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,eAAO,MAAM,sBAAsB,EAAE,iBAAiB,EAarD,CAAA;AAED,eAAO,MAAM,eAAe,UAO3B,CAAA;AAED,eAAO,MAAM,iBAAiB,wBAI5B,CAAA;AAEF,eAAO,MAAM,mBAAmB,wBAS9B,CAAA;AAEF,eAAO,MAAM,kBAAkB,EAAE,iBAA6B,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { ReinspectProviderProps } from './types';
2
+ export declare function ReinspectProvider({ children, config, }: ReinspectProviderProps): import("react/jsx-runtime").JSX.Element;
3
+ export declare function ReinspectFloatingToggle(): import("react/jsx-runtime").JSX.Element | null;
4
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/reinspect/context.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAKV,sBAAsB,EAEvB,MAAM,SAAS,CAAA;AAyChB,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,MAAM,GACP,EAAE,sBAAsB,2CAmJxB;AAED,wBAAgB,uBAAuB,mDA4OtC"}
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`react`),t=require(`react/jsx-runtime`),n=require(`react-dom`);var r=(0,e.createContext)(null);function i(){let t=(0,e.useContext)(r);if(!t)throw Error(`useReinspect must be used within ReinspectProvider`);return t}var a=[`backgroundColor`,`color`,`fontSize`,`padding`,`margin`,`borderRadius`,`borderWidth`,`borderColor`,`opacity`,`width`,`height`,`gap`],o=[`#f97316`,`#2563eb`,`#16a34a`,`#db2777`,`#ca8a04`,`#0f766e`],s=new Set([`backgroundColor`,`color`,`borderColor`]),c=new Set([`fontSize`,`padding`,`margin`,`borderRadius`,`borderWidth`,`width`,`height`,`gap`]),l=2147483e3,u=`reinspect.inspectMode`,d=[`wrapped`,`first-party`,`all`],f=[`attempts`,`commits`,`both`];function p(){return!1}function m(e){return typeof e==`string`&&d.includes(e)}function h(e){return typeof e==`string`&&f.includes(e)}function g(){if(!(typeof window>`u`))try{let e=window.sessionStorage.getItem(u);return m(e)?e:void 0}catch{return}}function _(e){return g()||(m(e)?e:`wrapped`)}function v(e){if(!(typeof window>`u`))try{window.sessionStorage.setItem(u,e)}catch{}}function y(){if(!(typeof window>`u`))try{window.location.reload()}catch{}}function b(e={}){let t=e.enabled??p(),n=e.editableProps&&e.editableProps.length>0?e.editableProps:a,r=e.palette&&e.palette.length>0?e.palette:o;return{enabled:t,startActive:e.startActive??!0,showFloatingToggle:e.showFloatingToggle??t,inspectMode:_(e.inspectMode),editableProps:n,palette:r,zIndexBase:e.zIndexBase??l,shouldCountRenders:e.shouldCountRenders??!1,countRendersForComponents:e.countRendersForComponents??[],renderCaptureMode:h(e.renderCaptureMode)?e.renderCaptureMode:`attempts`}}function x(e){let t=0;for(let n=0;n<e.length;n+=1)t=(t<<5)-t+e.charCodeAt(n),t|=0;return Math.abs(t)}function ee(e,t){return t.length===0?o[0]:t[x(e)%t.length]}function S(e,t){if(!e)return{};let n={};for(let r of t){let t=e[r];t==null||t===``||(n[r]=t)}return n}function te(e){if(!e)return`#1f2937`;if(/^#[0-9a-fA-F]{6}$/.test(e))return e;if(/^#[0-9a-fA-F]{3}$/.test(e)){let[,t,n,r]=e;return`#${t}${t}${n}${n}${r}${r}`}return`#1f2937`}function C(e){let t=Number(e);if(Number.isFinite(t))return t}var w=`Capture rerenders and show totals next to component badges.`,T=`Tracks every rerender after initial mount for wrapped components. Use this toggle to capture for all components, or enable a specific component from its right-click inspector menu.`,E=`Choose whether to count render attempts, committed renders, or both.`,D=`Render attempts track render-phase executions (includes Strict Mode extra passes). Committed renders track completed DOM commits. Both shows both counters together.`,O=`Controls which components are automatically discoverable by Reinspect.`,k=`Only wrapped components uses explicit withReinspect wrappers only. All 1st-party components auto-discovers components under your source tree. All components also attempts dependency components (with safety skips).`;function A(e){let t={};for(let n of e)t[n]=!0;return t}function ne({children:n,config:i}){let a=(0,e.useMemo)(()=>b(i),[i]),[o,s]=(0,e.useState)(a.startActive),[c]=(0,e.useState)(a.inspectMode),[l,u]=(0,e.useState)(a.inspectMode),[d,f]=(0,e.useState)(a.shouldCountRenders),[p,m]=(0,e.useState)(a.renderCaptureMode),[h,g]=(0,e.useState)(()=>A(a.countRendersForComponents)),[_,x]=(0,e.useState)({}),S=(0,e.useCallback)((e,t,n)=>{x(r=>{let i={...r[e]??{}};if(n==null||n===``?delete i[t]:i[t]=n,Object.keys(i).length===0){let t={...r};return delete t[e],t}return{...r,[e]:i}})},[]),te=(0,e.useCallback)((e,t)=>{g(n=>{if(t)return{...n,[e]:!0};if(!n[e])return n;let r={...n};return delete r[e],r})},[]),C=(0,e.useCallback)(e=>d||!!h[e],[d,h]),w=l!==c,T=(0,e.useCallback)(()=>{w&&(v(l),y())},[w,l]),E=(0,e.useCallback)(e=>ee(e,a.palette),[a.palette]),D=(0,e.useMemo)(()=>({config:a,isActive:a.enabled&&o,setIsActive:s,inspectMode:c,pendingInspectMode:l,setPendingInspectMode:u,hasPendingInspectModeChange:w,applyInspectMode:T,shouldCountRenders:d,setShouldCountRenders:f,renderCaptureMode:p,setRenderCaptureMode:m,renderCountComponents:h,setRenderCountingForComponent:te,isRenderCountingEnabledFor:C,overrides:_,updateOverride:S,getBorderColor:E}),[a,o,c,l,u,w,T,d,p,h,te,C,_,S,E]);return(0,t.jsxs)(r.Provider,{value:D,children:[n,a.enabled&&a.showFloatingToggle?(0,t.jsx)(j,{}):null]})}function j(){let{config:n,isActive:r,setIsActive:a,inspectMode:o,pendingInspectMode:s,setPendingInspectMode:c,hasPendingInspectModeChange:l,applyInspectMode:u,shouldCountRenders:d,setShouldCountRenders:f,renderCaptureMode:p,setRenderCaptureMode:g}=i(),[_,v]=(0,e.useState)(!1),y=(0,e.useRef)(null);return(0,e.useEffect)(()=>{if(!_)return;let e=e=>{let t=e.target;y.current?.contains(t)||v(!1)},t=e=>{e.key===`Escape`&&v(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[_]),n.enabled?(0,t.jsxs)(`div`,{className:`reinspect-floating-root`,ref:y,children:[(0,t.jsx)(`button`,{type:`button`,className:`reinspect-floating-toggle`,"data-testid":`reinspect-floating-toggle`,onClick:()=>v(e=>!e),"aria-expanded":_,"aria-controls":`reinspect-settings-menu`,children:`Reinspect settings`}),_?(0,t.jsxs)(`div`,{id:`reinspect-settings-menu`,className:`reinspect-settings-menu`,role:`dialog`,"aria-label":`Reinspect settings`,"data-testid":`reinspect-settings-menu`,children:[(0,t.jsx)(`p`,{className:`reinspect-settings-title`,children:`Reinspect settings`}),(0,t.jsxs)(`label`,{className:`reinspect-settings-toggle-row`,children:[(0,t.jsx)(`span`,{className:`reinspect-settings-toggle-label`,children:`Inspector enabled`}),(0,t.jsx)(`input`,{"data-testid":`reinspect-setting-inspector-active`,type:`checkbox`,checked:r,onChange:e=>a(e.currentTarget.checked)})]}),(0,t.jsx)(`div`,{className:`reinspect-settings-divider`}),(0,t.jsxs)(`section`,{className:`reinspect-setting-block`,children:[(0,t.jsxs)(`header`,{className:`reinspect-setting-header`,children:[(0,t.jsxs)(`div`,{children:[(0,t.jsx)(`p`,{className:`reinspect-setting-name`,children:`INSPECT_MODE`}),(0,t.jsx)(`p`,{className:`reinspect-setting-short-description`,children:O})]}),(0,t.jsxs)(`span`,{className:`reinspect-tooltip-host`,children:[(0,t.jsx)(`button`,{type:`button`,className:`reinspect-tooltip-trigger`,"aria-label":`Explain INSPECT_MODE`,children:`?`}),(0,t.jsx)(`span`,{className:`reinspect-tooltip-content`,role:`tooltip`,children:k})]})]}),(0,t.jsxs)(`label`,{className:`reinspect-settings-select-row`,children:[(0,t.jsx)(`span`,{className:`reinspect-settings-toggle-label`,children:`Inspect Mode`}),(0,t.jsxs)(`select`,{"data-testid":`reinspect-setting-inspect-mode`,value:s,onChange:e=>{let t=e.currentTarget.value;m(t)&&c(t)},children:[(0,t.jsx)(`option`,{value:`wrapped`,children:`Only wrapped components`}),(0,t.jsx)(`option`,{value:`first-party`,children:`All 1st-party components`}),(0,t.jsx)(`option`,{value:`all`,children:`All components`})]})]}),(0,t.jsx)(`button`,{type:`button`,className:`reinspect-apply-button`,"data-testid":`reinspect-apply-inspect-mode`,onClick:u,disabled:!l,children:`Apply & Reload`}),l?(0,t.jsx)(`p`,{className:`reinspect-setting-note`,"data-testid":`reinspect-inspect-mode-reload-note`,children:`Inspect mode changes are applied after reload.`}):(0,t.jsxs)(`p`,{className:`reinspect-setting-note`,children:[`Current mode: `,o]})]}),(0,t.jsx)(`div`,{className:`reinspect-settings-divider`}),(0,t.jsxs)(`section`,{className:`reinspect-setting-block`,children:[(0,t.jsxs)(`header`,{className:`reinspect-setting-header`,children:[(0,t.jsxs)(`div`,{children:[(0,t.jsx)(`p`,{className:`reinspect-setting-name`,children:`SHOULD_COUNT_RENDERS`}),(0,t.jsx)(`p`,{className:`reinspect-setting-short-description`,children:w})]}),(0,t.jsxs)(`span`,{className:`reinspect-tooltip-host`,children:[(0,t.jsx)(`button`,{type:`button`,className:`reinspect-tooltip-trigger`,"aria-label":`Explain SHOULD_COUNT_RENDERS`,children:`?`}),(0,t.jsx)(`span`,{className:`reinspect-tooltip-content`,role:`tooltip`,children:T})]})]}),(0,t.jsxs)(`label`,{className:`reinspect-settings-toggle-row`,children:[(0,t.jsx)(`span`,{className:`reinspect-settings-toggle-label`,children:`Capture render for all components`}),(0,t.jsx)(`input`,{"data-testid":`reinspect-setting-should-count-renders`,type:`checkbox`,checked:d,onChange:e=>f(e.currentTarget.checked)})]}),(0,t.jsxs)(`header`,{className:`reinspect-setting-header`,children:[(0,t.jsxs)(`div`,{children:[(0,t.jsx)(`p`,{className:`reinspect-setting-name`,children:`RENDER_CAPTURE_MODE`}),(0,t.jsx)(`p`,{className:`reinspect-setting-short-description`,children:E})]}),(0,t.jsxs)(`span`,{className:`reinspect-tooltip-host`,children:[(0,t.jsx)(`button`,{type:`button`,className:`reinspect-tooltip-trigger`,"aria-label":`Explain RENDER_CAPTURE_MODE`,children:`?`}),(0,t.jsx)(`span`,{className:`reinspect-tooltip-content`,role:`tooltip`,children:D})]})]}),(0,t.jsxs)(`label`,{className:`reinspect-settings-select-row`,children:[(0,t.jsx)(`span`,{className:`reinspect-settings-toggle-label`,children:`Capture mode`}),(0,t.jsxs)(`select`,{"data-testid":`reinspect-setting-render-capture-mode`,value:p,onChange:e=>{let t=e.currentTarget.value;h(t)&&g(t)},children:[(0,t.jsx)(`option`,{value:`attempts`,children:`Render attempts`}),(0,t.jsx)(`option`,{value:`commits`,children:`Committed renders`}),(0,t.jsx)(`option`,{value:`both`,children:`Both`})]})]})]})]}):null]}):null}var re=4,M=40,N=40,P=`__reinspect_placeholder__`;function F(e,t){return{[P]:e,display:t}}function I(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ie(e){if(!I(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function L(e){return I(e)&&typeof e.__reinspect_placeholder__==`string`&&typeof e.display==`string`}function R(e){try{return JSON.stringify(e,null,2)}catch{return null}}function z(e){try{let t=Function.prototype.toString.call(e);return typeof t!=`string`||t.trim().length===0?`[Function source unavailable]`:t}catch{return`[Function source unavailable]`}}function B(e){let t=e.replace(/\s+/g,` `).trim();return t.length<=120?t:`${t.slice(0,117)}...`}function V(e,t,n){if(n>re)return F(`truncated`,`[Max depth reached]`);if(e===null)return null;let r=typeof e;if(r===`string`||r===`boolean`)return e;if(r===`number`)return Number.isFinite(e)?e:F(`non-finite-number`,String(e));if(r===`undefined`)return F(`undefined`,`undefined`);if(r===`bigint`)return F(`bigint`,`${String(e)}n`);if(r===`symbol`)return F(`symbol`,String(e));if(r===`function`)return F(`function`,`[Function ${e.name||`anonymous`}]`);if(e instanceof Date)return F(`date`,Number.isNaN(e.getTime())?`Invalid Date`:e.toISOString());if(e instanceof RegExp)return F(`regexp`,e.toString());if(r===`object`){let r=e;if(t.has(r))return F(`circular`,`[Circular]`);if(t.add(r),Array.isArray(e)){let i=[],a=Math.min(e.length,N);for(let r=0;r<a;r+=1)i.push(V(e[r],t,n+1));return e.length>N&&i.push(F(`truncated`,`${e.length-N} more items`)),t.delete(r),i}let i={},a=Object.entries(e),o=Math.min(a.length,M);for(let e=0;e<o;e+=1){let[r,o]=a[e];i[r]=V(o,t,n+1)}return a.length>M&&(i.__reinspect_truncated__=F(`truncated`,`${a.length-M} more keys`)),t.delete(r),i}return F(`unsupported`,`[Unsupported value]`)}function H(e){if(e===null)return{kind:`null`,summary:`null`,copyText:`null`};let t=typeof e;if(t===`undefined`)return{kind:`undefined`,summary:`undefined`,copyText:`undefined`};if(t===`boolean`)return{kind:`boolean`,summary:String(e),copyText:String(e)};if(t===`number`)return{kind:`number`,summary:String(e),copyText:String(e)};if(t===`string`)return{kind:`string`,summary:JSON.stringify(e),copyText:String(e)};if(t===`bigint`)return{kind:`bigint`,summary:`${String(e)}n`,copyText:`${String(e)}n`};if(t===`symbol`){let t=String(e);return{kind:`symbol`,summary:t,copyText:t}}if(t===`function`){let t=e,n=z(t),r=t.name||`anonymous`;return{kind:`function`,summary:`Function ${r}(${t.length})`,copyText:n,functionMeta:{name:r,arity:t.length,preview:B(n),source:n}}}if(e instanceof Date){let t=Number.isNaN(e.getTime())?`Invalid Date`:e.toISOString();return{kind:`date`,summary:`Date ${t}`,copyText:t}}if(e instanceof RegExp){let t=e.toString();return{kind:`regexp`,summary:t,copyText:t}}return Array.isArray(e)?{kind:`array`,summary:`Array(${e.length})`}:I(e)?{kind:`object`,summary:`Object(${Object.keys(e).length})`}:{kind:`unknown`,summary:String(e)}}function U(e){if(!L(e)){if(Array.isArray(e)){let t=[];for(let n of e){let e=U(n);if(e===void 0)return;t.push(e)}return t}if(I(e)){let t={};for(let[n,r]of Object.entries(e)){let e=U(r);e!==void 0&&(t[n]=e)}return t}return e}}function ae(e){return Object.keys(e).map(t=>({key:t,value:H(e[t])}))}function oe(e){return R(V(e,new WeakSet,0))??`{}`}function se(e){return R(V(e,new WeakSet,0))}function ce(e){if(e===null)return!0;let t=typeof e;return t===`string`||t===`number`||t===`boolean`||Array.isArray(e)?!0:ie(e)}function le(e){let t=e.trim();if(t.length===0)return{parsed:null,error:`Value JSON cannot be empty.`};try{let e=U(JSON.parse(t));return e===void 0||!ce(e)?{parsed:null,error:`Only objects, arrays, and primitive JSON values are editable.`}:{parsed:e,error:null}}catch{return{parsed:null,error:`Invalid JSON. Fix syntax and try Apply again.`}}}function ue(e){let t=e.trim();if(t.length===0)return{parsed:{},error:null};try{let e=JSON.parse(t);if(typeof e!=`object`||!e||Array.isArray(e))return{parsed:null,error:`Props JSON must be an object (example: {"title":"Demo"}).`};let n={};for(let[t,r]of Object.entries(e)){let e=U(r);e!==void 0&&(n[t]=e)}return{parsed:n,error:null}}catch{return{parsed:null,error:`Invalid JSON. Fix syntax and try Apply again.`}}}var W=Symbol.for(`reinspect.wrapped`);function de(e){return e[W]}var fe={enabled:!1,startActive:!1,showFloatingToggle:!1,inspectMode:`wrapped`,editableProps:[],palette:[],zIndexBase:0,shouldCountRenders:!1,countRendersForComponents:[],renderCaptureMode:`attempts`},pe=new Map;function G(e){let t=pe.get(e);if(t)return t;let n={attempts:0,commits:0,hasCommitted:!1,wasCountingEnabled:!1,shouldCountCommit:!1};return pe.set(e,n),n}function me(e,t){let n=G(e);if(!t)return n.wasCountingEnabled=!1,n.shouldCountCommit=!1,{attempts:n.attempts,commits:n.commits};let r=n.hasCommitted&&n.wasCountingEnabled;return r&&(n.attempts+=1),n.wasCountingEnabled=!0,n.shouldCountCommit=r,{attempts:n.attempts,commits:n.commits+ +!!r}}function he(e){let t=G(e);t.hasCommitted&&t.shouldCountCommit&&(t.commits+=1),t.hasCommitted=!0,t.shouldCountCommit=!1}function ge(e,t){return t===`commits`?`${e.commits} commits`:t===`both`?`${e.attempts} attempts | ${e.commits} commits`:`${e.attempts} attempts`}function _e(e){let t=e.replace(/([A-Z])/g,` $1`).trim();return t.length>0?t[0].toUpperCase()+t.slice(1):e}function ve(e){return e.trim().toLowerCase().replace(/[\s_-]+/g,``)}function K(e){return e!=null&&e!==``}function ye(e){return e.replace(/[^a-zA-Z0-9_-]/g,`-`)}async function be(e){if(typeof navigator>`u`||!navigator.clipboard?.writeText)return!1;try{return await navigator.clipboard.writeText(e),!0}catch{return!1}}function xe({value:e,onCopy:n}){if(e.kind===`function`&&e.functionMeta){let r=e.functionMeta;return(0,t.jsxs)(`div`,{className:`reinspect-prop-function`,children:[(0,t.jsx)(`code`,{children:e.summary}),(0,t.jsx)(`pre`,{children:r.preview}),(0,t.jsx)(`button`,{type:`button`,onClick:()=>n(r.source,`Function source`),disabled:!r.source,children:`Copy function source`})]})}return(0,t.jsxs)(`div`,{className:`reinspect-prop-scalar`,children:[(0,t.jsx)(`code`,{children:e.summary}),e.copyText?(0,t.jsx)(`button`,{type:`button`,onClick:()=>n(e.copyText??``,`Value`),children:`Copy`}):null]})}function Se(e,t){return t?.name?.trim()||e.displayName?.trim()||e.name?.trim()||t?.fallbackName?.trim()||`Component`}function Ce(e,t,n){return e===`manual`||n===`all`||n===`first-party`&&t===`first-party`}function q(i,a){let o=a?.source??`manual`,l=a?.scope??`first-party`,u=de(i);if(u&&o===`auto`)return i;let d=u&&o===`manual`?u.original:i,f=Se(d,a);function p(i){let a=(0,e.useId)(),u=(0,e.useRef)(null),p=(0,e.useRef)(null),[m,h]=(0,e.useState)(null),[g,_]=(0,e.useState)(`css`),[v,y]=(0,e.useState)(`detected`),[b,x]=(0,e.useState)(``),[ee,w]=(0,e.useState)({}),[T,E]=(0,e.useState)(`{}`),[D,O]=(0,e.useState)(null),[k,A]=(0,e.useState)(null),[ne,j]=(0,e.useState)({}),[re,M]=(0,e.useState)({}),[N,P]=(0,e.useState)({}),[F,I]=(0,e.useState)(null),[ie,L]=(0,e.useState)(``),[R,z]=(0,e.useState)(null),B=(0,e.useContext)(r),V=!!B,H=B?.config??fe,U=B?.getBorderColor??(()=>`#f97316`),W=B?.isActive??!1,de=B?.inspectMode??`wrapped`,G=B?.shouldCountRenders??!1,Se=B?.renderCaptureMode??fe.renderCaptureMode,q=B?.overrides??{},J=B?.updateOverride??(()=>void 0),we=B?.renderCountComponents??{},Te=B?.setRenderCountingForComponent??(()=>void 0),Ee=B?.isRenderCountingEnabledFor??(()=>!1),Y=`${f}-${a}`,De=U(f),Oe=Ce(o,l,de),X=H.enabled&&W&&Oe,ke=Oe&&Ee(f),Ae=!!we[f],je=me(Y,ke),Me=q[Y],Ne=X?S(Me,H.editableProps):{},Z={...i,...ee},Q=Z,$=X&&m!==null,Pe=ve(b),Fe=Pe.length===0?H.editableProps:H.editableProps.filter(e=>ve(e).includes(Pe)),Ie=$&&g===`props`&&v===`detected`?ae(Q):[];(0,e.useEffect)(()=>(he(Y),()=>{pe.delete(Y)}),[Y]),(0,e.useEffect)(()=>{if(!$)return;let e=e=>{let t=e.target;u.current?.contains(t)||p.current?.contains(t)||(h(null),I(null),L(``),z(null))},t=e=>{if(e.key===`Escape`){if(F){I(null),L(``),z(null);return}h(null)}};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[F,$]),(0,e.useEffect)(()=>{if(!k)return;let e=globalThis.setTimeout(()=>{A(null)},1400);return()=>{globalThis.clearTimeout(e)}},[k]);let Le={"--reinspect-color":De,"--reinspect-z-base":H.zIndexBase},Re=e=>{X&&(e.preventDefault(),_(`css`),y(`detected`),x(``),O(null),A(null),j({}),M({}),P({}),I(null),L(``),z(null),E(`{}`),h({x:e.clientX,y:e.clientY}))},ze=()=>{let{parsed:e,error:t}=ue(T);if(t||!e){O(t);return}w(e),O(null)},Be=()=>{w({}),v===`raw`&&E(oe(i)),O(null)},Ve=(e,t)=>{be(e).then(e=>{A(e?`${t} copied.`:`Clipboard access is unavailable.`)})},He=(e,t)=>{if(N[e]){P(t=>({...t,[e]:!1}));return}if(!(e in ne)&&!(e in re)){let n=se(t);n===null?M(t=>({...t,[e]:`JSON preview is unavailable for this value.`})):j(t=>({...t,[e]:n}))}P(t=>({...t,[e]:!0}))},Ue=(e,t)=>{if(!ce(t))return;let n=se(t);if(n===null){A(`Unable to open editor for this value.`);return}I(e),L(n),z(null)},We=()=>{if(!F)return;let{parsed:e,error:t}=le(ie);if(t||e===null){z(t);return}w(t=>({...t,[F]:e})),I(null),L(``),z(null)},Ge=$?(0,t.jsxs)(`div`,{ref:u,className:`reinspect-menu`,role:`dialog`,"aria-label":`${f} inspector controls`,style:{top:`${m.y}px`,left:`${m.x}px`},children:[(0,t.jsxs)(`p`,{className:`reinspect-menu-title`,children:[f,` inspector`]}),(0,t.jsxs)(`label`,{className:`reinspect-menu-component-setting`,children:[(0,t.jsx)(`span`,{children:`Capture renders for this component`}),(0,t.jsx)(`input`,{type:`checkbox`,checked:G?!0:Ae,onChange:e=>Te(f,e.currentTarget.checked),disabled:G,"aria-label":`Capture renders for ${f}`,"data-testid":`reinspect-component-render-toggle-${f}`})]}),G?(0,t.jsx)(`p`,{className:`reinspect-setting-note`,children:`Global capture is enabled from Reinspect settings.`}):null,(0,t.jsxs)(`div`,{className:`reinspect-submenu`,children:[(0,t.jsx)(`button`,{type:`button`,"data-state":g===`css`?`active`:`idle`,onClick:()=>_(`css`),children:`CSS`}),(0,t.jsx)(`button`,{type:`button`,"data-state":g===`props`?`active`:`idle`,onClick:()=>_(`props`),children:`Props`})]}),g===`css`?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(`div`,{className:`reinspect-menu-filter`,children:[(0,t.jsx)(`span`,{className:`reinspect-menu-filter-icon`,"aria-hidden":`true`,children:(0,t.jsx)(`svg`,{viewBox:`0 0 24 24`,focusable:`false`,children:(0,t.jsx)(`path`,{d:`M10.5 3a7.5 7.5 0 015.92 12.1l4.24 4.23a1 1 0 01-1.42 1.42l-4.23-4.24A7.5 7.5 0 1110.5 3zm0 2a5.5 5.5 0 100 11 5.5 5.5 0 000-11z`,fill:`currentColor`})})}),(0,t.jsx)(`input`,{id:`${Y}-css-filter`,"data-testid":`reinspect-css-filter-input`,type:`search`,value:b,placeholder:`Filter`,"aria-label":`Filter CSS properties`,onChange:e=>x(e.currentTarget.value)})]}),(0,t.jsx)(`div`,{className:`reinspect-menu-grid`,children:Fe.map(e=>{let n=Me?.[e],r=`${Y}-${e}`;if(s.has(e)){let i=typeof n==`string`?te(n):`#1f2937`;return(0,t.jsxs)(`div`,{className:`reinspect-field`,children:[(0,t.jsx)(`label`,{htmlFor:r,children:_e(e)}),(0,t.jsxs)(`div`,{className:`reinspect-inline-controls`,children:[(0,t.jsx)(`input`,{id:r,type:`color`,value:i,onChange:t=>J(Y,e,t.currentTarget.value)}),(0,t.jsx)(`button`,{type:`button`,onClick:()=>J(Y,e,void 0),disabled:!K(n),children:`reset`})]})]},e)}if(e===`opacity`){let i=typeof n==`number`?n:1;return(0,t.jsxs)(`div`,{className:`reinspect-field`,children:[(0,t.jsx)(`label`,{htmlFor:r,children:`Opacity`}),(0,t.jsxs)(`div`,{className:`reinspect-inline-controls reinspect-opacity-controls`,children:[(0,t.jsx)(`input`,{id:r,type:`range`,min:`0`,max:`1`,step:`0.05`,value:i,onChange:t=>{let n=C(t.currentTarget.value);n!==void 0&&J(Y,e,n)}}),(0,t.jsx)(`output`,{children:i.toFixed(2)}),(0,t.jsx)(`button`,{type:`button`,onClick:()=>J(Y,e,void 0),disabled:!K(n),children:`reset`})]})]},e)}if(c.has(e)){let i=typeof n==`number`?n:``;return(0,t.jsxs)(`div`,{className:`reinspect-field`,children:[(0,t.jsxs)(`label`,{htmlFor:r,children:[_e(e),` (px)`]}),(0,t.jsxs)(`div`,{className:`reinspect-inline-controls`,children:[(0,t.jsx)(`input`,{id:r,type:`number`,step:`1`,value:i,onChange:t=>{if(t.currentTarget.value===``){J(Y,e,void 0);return}let n=C(t.currentTarget.value);n!==void 0&&J(Y,e,n)}}),(0,t.jsx)(`button`,{type:`button`,onClick:()=>J(Y,e,void 0),disabled:!K(n),children:`reset`})]})]},e)}return(0,t.jsxs)(`div`,{className:`reinspect-field`,children:[(0,t.jsx)(`label`,{htmlFor:r,children:_e(e)}),(0,t.jsxs)(`div`,{className:`reinspect-inline-controls`,children:[(0,t.jsx)(`input`,{id:r,type:`text`,value:typeof n==`string`?n:``,onChange:t=>J(Y,e,t.currentTarget.value||void 0)}),(0,t.jsx)(`button`,{type:`button`,onClick:()=>J(Y,e,void 0),disabled:!K(n),children:`reset`})]})]},e)})}),Fe.length===0?(0,t.jsxs)(`p`,{className:`reinspect-menu-empty-state`,children:[`No CSS properties match "`,b.trim(),`".`]}):null]}):(0,t.jsxs)(`div`,{className:`reinspect-props-panel`,children:[(0,t.jsxs)(`div`,{className:`reinspect-props-submenu`,children:[(0,t.jsx)(`button`,{type:`button`,"data-state":v===`detected`?`active`:`idle`,onClick:()=>y(`detected`),children:`Detected`}),(0,t.jsx)(`button`,{type:`button`,"data-state":v===`raw`?`active`:`idle`,onClick:()=>{y(`raw`),O(null),E(oe(Q))},children:`Raw`})]}),v===`detected`?Ie.length>0?(0,t.jsxs)(`div`,{className:`reinspect-props-table`,children:[(0,t.jsxs)(`div`,{className:`reinspect-props-header`,children:[(0,t.jsx)(`span`,{children:`Key`}),(0,t.jsx)(`span`,{children:`Value`})]}),Ie.map(e=>{let n=ye(e.key),r=Q[e.key],i=e.value.kind===`object`||e.value.kind===`array`,a=!!N[e.key],o=ne[e.key],s=re[e.key],c=ce(r);return(0,t.jsxs)(`div`,{className:`reinspect-props-row`,"data-testid":`reinspect-prop-row-${n}`,children:[(0,t.jsx)(`code`,{className:`reinspect-prop-key`,children:e.key}),(0,t.jsxs)(`div`,{className:`reinspect-prop-cell`,"data-testid":`reinspect-prop-value-${n}`,children:[xe({value:e.value,onCopy:Ve}),i||c?(0,t.jsxs)(`div`,{className:`reinspect-prop-actions`,children:[i?(0,t.jsx)(`button`,{type:`button`,"data-testid":`reinspect-prop-show-json-${n}`,onClick:()=>He(e.key,r),children:a?`Hide JSON`:`Show JSON`}):null,c?(0,t.jsx)(`button`,{type:`button`,"data-testid":`reinspect-prop-edit-${n}`,onClick:()=>Ue(e.key,r),children:`Edit`}):null]}):null,a?(0,t.jsx)(`div`,{className:`reinspect-prop-json-preview`,"data-testid":`reinspect-prop-json-preview-${n}`,children:s?(0,t.jsx)(`p`,{className:`reinspect-error`,children:s}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(`pre`,{children:o}),o?(0,t.jsx)(`button`,{type:`button`,"data-testid":`reinspect-prop-copy-json-${n}`,onClick:()=>Ve(o,`JSON value`),children:`Copy JSON`}):null]})}):null]})]},e.key)})]}):(0,t.jsx)(`p`,{className:`reinspect-menu-empty-state`,children:`No props detected.`}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(`label`,{htmlFor:`${Y}-props-json`,children:`Props JSON`}),(0,t.jsx)(`textarea`,{id:`${Y}-props-json`,value:T,onChange:e=>{E(e.currentTarget.value),O(null)},rows:9}),D?(0,t.jsx)(`p`,{className:`reinspect-error`,children:D}):null,(0,t.jsxs)(`div`,{className:`reinspect-inline-controls`,children:[(0,t.jsx)(`button`,{type:`button`,onClick:ze,children:`apply`}),(0,t.jsx)(`button`,{type:`button`,onClick:Be,children:`reset`})]})]}),k?(0,t.jsx)(`p`,{className:`reinspect-setting-note`,"data-testid":`reinspect-props-copy-status`,children:k}):null]})]}):null,Ke=F?(0,n.createPortal)((0,t.jsx)(`div`,{className:`reinspect-modal-backdrop`,role:`dialog`,"aria-modal":`true`,"aria-label":`Edit ${F} prop`,"data-testid":`reinspect-prop-edit-modal`,children:(0,t.jsxs)(`div`,{className:`reinspect-modal`,ref:p,children:[(0,t.jsxs)(`p`,{className:`reinspect-menu-title`,children:[`Edit prop: `,F]}),(0,t.jsx)(`label`,{htmlFor:`${Y}-prop-edit-json`,children:`JSON value`}),(0,t.jsx)(`textarea`,{id:`${Y}-prop-edit-json`,"data-testid":`reinspect-prop-edit-textarea`,value:ie,onChange:e=>{L(e.currentTarget.value),z(null)},rows:10}),R?(0,t.jsx)(`p`,{className:`reinspect-error`,"data-testid":`reinspect-prop-edit-error`,children:R}):null,(0,t.jsxs)(`div`,{className:`reinspect-inline-controls`,children:[(0,t.jsx)(`button`,{type:`button`,onClick:We,children:`apply`}),(0,t.jsx)(`button`,{type:`button`,onClick:()=>{I(null),L(``),z(null)},children:`cancel`})]})]})}),document.body):null;if(!V){if(o===`manual`)throw Error(`useReinspect must be used within ReinspectProvider`);return(0,t.jsx)(d,{...Z})}return o===`auto`&&!Oe?(0,t.jsx)(d,{...Z}):(0,t.jsxs)(`div`,{className:`reinspect-shell`,"data-reinspect-component":f,"data-reinspect-active":X,"data-testid":`reinspect-shell-${f}`,style:Le,onContextMenu:Re,children:[X?(0,t.jsxs)(`span`,{className:`reinspect-name-badge`,children:[f,ke?` | ${ge(je,Se)}`:``]}):null,Ge?(0,n.createPortal)(Ge,document.body):null,Ke,(0,t.jsx)(`div`,{className:`reinspect-content`,"data-reinspect-content":`true`,style:Ne,children:(0,t.jsx)(d,{...Z})})]})}return p.displayName=`withReinspect(${f})`,p[W]={source:o,scope:l,original:d},p}function J(e,t){return de(e)?.source===`manual`?e:q(e,{source:`auto`,scope:t.scope,name:t.componentName,fallbackName:t.fallbackName})}function we(e,t){let n={};for(let r of Object.keys(e)){let i=e[r];n[r]=q(i,typeof t==`function`?t(r,i):t?.[r])}return n}exports.DEFAULT_EDITABLE_PROPS=a,exports.DEFAULT_PALETTE=o,exports.ReinspectFloatingToggle=j,exports.ReinspectProvider=ne,exports.autoWrapInspectable=J,exports.useReinspect=i,exports.withReinspect=q,exports.wrapInspectableMap=we;
@@ -0,0 +1,10 @@
1
+ import './reinspect.css';
2
+ export { ReinspectProvider, ReinspectFloatingToggle } from './context';
3
+ export { useReinspect } from './useReinspect';
4
+ export { autoWrapInspectable } from './autoWrap';
5
+ export { withReinspect } from './withReinspect';
6
+ export { wrapInspectableMap } from './wrapInspectableMap';
7
+ export { DEFAULT_EDITABLE_PROPS, DEFAULT_PALETTE } from './constants';
8
+ export type { EditableStyleProp, InspectMode, AutoDiscoverScope, RenderCaptureMode, ReinspectConfig, ResolvedReinspectConfig, ComponentStyleOverrides, } from './types';
9
+ export type { WithReinspectOptions } from './withReinspect';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/reinspect/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,CAAA;AAExB,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAA;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAErE,YAAY,EACV,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,SAAS,CAAA;AAEhB,YAAY,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA"}