@remcostoeten/dev-widget 0.0.1

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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +132 -0
  3. package/dist/chunk-6OCSDLNS.mjs +16 -0
  4. package/dist/chunk-6OCSDLNS.mjs.map +1 -0
  5. package/dist/chunk-VI7WXBU2.mjs +2 -0
  6. package/dist/chunk-VI7WXBU2.mjs.map +1 -0
  7. package/dist/chunk-X3LYXERT.mjs +2 -0
  8. package/dist/chunk-X3LYXERT.mjs.map +1 -0
  9. package/dist/cli.js +104 -0
  10. package/dist/index.d.mts +18 -0
  11. package/dist/index.d.ts +18 -0
  12. package/dist/index.js +16 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/index.mjs +2 -0
  15. package/dist/index.mjs.map +1 -0
  16. package/dist/internal-Bhwt8k21.d.mts +51 -0
  17. package/dist/internal-C3TqZPIi.d.ts +51 -0
  18. package/dist/internal.d.mts +2 -0
  19. package/dist/internal.d.ts +2 -0
  20. package/dist/internal.js +2 -0
  21. package/dist/internal.js.map +1 -0
  22. package/dist/internal.mjs +1 -0
  23. package/dist/internal.mjs.map +1 -0
  24. package/dist/next.d.mts +13 -0
  25. package/dist/next.d.ts +13 -0
  26. package/dist/next.js +2 -0
  27. package/dist/next.js.map +1 -0
  28. package/dist/next.mjs +2 -0
  29. package/dist/next.mjs.map +1 -0
  30. package/dist/public-CgTT_99y.d.mts +365 -0
  31. package/dist/public-CgTT_99y.d.ts +365 -0
  32. package/dist/react.d.mts +5 -0
  33. package/dist/react.d.ts +5 -0
  34. package/dist/react.js +16 -0
  35. package/dist/react.js.map +1 -0
  36. package/dist/react.mjs +2 -0
  37. package/dist/react.mjs.map +1 -0
  38. package/dist/routeHandler-CwUVepQp.d.mts +7 -0
  39. package/dist/routeHandler-DMHcrvQO.d.ts +7 -0
  40. package/dist/tauri.d.mts +5 -0
  41. package/dist/tauri.d.ts +5 -0
  42. package/dist/tauri.js +2 -0
  43. package/dist/tauri.js.map +1 -0
  44. package/dist/tauri.mjs +2 -0
  45. package/dist/tauri.mjs.map +1 -0
  46. package/package.json +100 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Remco Stoeten
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,132 @@
1
+ # @remcostoeten/dev-widget
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@remcostoeten/dev-widget)](https://www.npmjs.com/package/@remcostoeten/dev-widget)
4
+ [![CI](https://github.com/remcostoeten/dev-widget/actions/workflows/ci.yml/badge.svg)](https://github.com/remcostoeten/dev-widget/actions/workflows/ci.yml)
5
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
+
7
+ Minimal, type-safe dev widget for React apps.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ bun add @remcostoeten/dev-widget
13
+ ```
14
+
15
+ ## React usage
16
+
17
+ ```tsx
18
+ import { DevWidget } from '@remcostoeten/dev-widget/react'
19
+
20
+ export function App(): React.ReactElement {
21
+ return (
22
+ <>
23
+ <main>App</main>
24
+ <DevWidget
25
+ mode='development-only'
26
+ theme={{ mode: 'system', accent: '#3bb273' }}
27
+ features={{
28
+ performance: { enabled: true, fpsThreshold: 50 },
29
+ auth: { enabled: true, provider: 'better-auth' }
30
+ }}
31
+ />
32
+ </>
33
+ )
34
+ }
35
+ ```
36
+
37
+ ## Features
38
+
39
+ - Auth domain
40
+ - Routes domain
41
+ - Links domain
42
+ - Performance domain
43
+ - System domain
44
+ - Monitor domain
45
+
46
+ ## Feature checklist
47
+
48
+ - [x] React widget shell with tab categories
49
+ - [x] Domain lifecycle (setup/start/stop) via runtime registry
50
+ - [x] Plugin API with typed event subscription
51
+ - [x] Event bus for cross-domain communication
52
+ - [x] Next.js log ingestion route handler
53
+ - [x] In-memory storage adapter
54
+ - [x] Tauri storage adapter export
55
+ - [x] Route discovery adapter for Next.js and React projects
56
+ - [x] Right rail with diagnostics render panel
57
+ - [x] Keyboard shortcuts (toggle + Escape)
58
+ - [x] Accessibility: focus-visible, reduced-motion handling, live region announcements
59
+ - [x] Internal subpath export (`@remcostoeten/dev-widget/internal`)
60
+ - [x] Source maps and declaration output in package build
61
+ - [x] CI publish artifact validation step
62
+ - [x] Demo app build pipeline
63
+
64
+ ## Needs additional work
65
+
66
+ - AI providers: `openai` and `local` modes are declared but not implemented yet; only `rules` and `custom` are active (`src/domains/performance/aiProviderFactory.ts`).
67
+ - Runtime prop updates: `DevWidget` memoizes runtime by `shouldRender` only, so runtime does not re-bootstrap when non-visibility props change after mount (`src/devWidget.tsx`).
68
+ - Storage wiring: `providers.storage` is part of public config but not wired into runtime/domain persistence flow yet (`src/types/public.ts` and `src/core/bootstrap.ts`).
69
+ - Endpoint validation: Next log handler accepts event payloads without schema validation; malformed event shapes can be persisted (`src/adapters/next/routeHandler.ts`).
70
+ - CI parity: local checks pass, but final release confidence still depends on a pushed branch and green remote GitHub Actions run.
71
+
72
+ ## Plugin API
73
+
74
+ ```ts
75
+ import { createRuntime } from '@remcostoeten/dev-widget'
76
+
77
+ const runtime = createRuntime({ mode: 'always' })
78
+
79
+ await runtime.registerPlugin({
80
+ id: 'my-plugin',
81
+ version: '1.0.0',
82
+ register(ctx) {
83
+ ctx.onEvent('performance/drop-detected', function onDrop(payload) {
84
+ console.log('FPS drop:', payload.fps)
85
+ })
86
+ }
87
+ })
88
+ ```
89
+
90
+ ## Subpath exports
91
+
92
+ ```ts
93
+ import { DevWidget } from '@remcostoeten/dev-widget/react'
94
+ import { createLogHandler } from '@remcostoeten/dev-widget/next'
95
+ import { createTauriStorage } from '@remcostoeten/dev-widget/tauri'
96
+ import type { WidgetDomain } from '@remcostoeten/dev-widget/internal'
97
+ ```
98
+
99
+ ## Accessibility
100
+
101
+ The widget includes keyboard shortcuts, focus-visible styling, live announcements, and reduced-motion support.
102
+ See `specs/10-dev-widget-accessibility-keyboard-spec.md` for the detailed behavior contract.
103
+
104
+ ## Core options
105
+
106
+ - `enabled?: boolean`
107
+ - `mode?: 'development-only' | 'always'`
108
+ - `theme?: { mode?: 'system' | 'light' | 'dark'; accent?: string; density?: 'compact' | 'comfortable'; radius?: 'none' | 'sm' | 'md' | 'lg' }`
109
+ - `features?: { auth?: boolean | AuthOptions; routes?: boolean | RoutesOptions; performance?: boolean | PerfOptions; system?: boolean | SystemOptions; links?: boolean | LinksOptions }`
110
+ - `disable?: FeatureId[]`
111
+ - `providers?: { auth?: AuthConfig; ai?: AiConfig; storage?: StorageConfig }`
112
+ - `keyboard?: { toggleKey?: string; enableShortcuts?: boolean }`
113
+ - `accessibility?: { reducedMotion?: 'system' | 'always' | 'never'; announceUpdates?: boolean }`
114
+ - `rightRail?: { enabled?: boolean; defaultPanel?: string | null; collapsible?: boolean; panels?: PanelConfig[] }`
115
+
116
+ ## Changelog
117
+
118
+ - [CHANGELOG.md](CHANGELOG.md)
119
+
120
+ ## Contributing
121
+
122
+ ```bash
123
+ bun run lint
124
+ bun run format:check
125
+ bun run type-check
126
+ bun test
127
+ bun run build
128
+ ```
129
+
130
+ ## License
131
+
132
+ MIT
@@ -0,0 +1,16 @@
1
+ var ne=["auth","routes","performance","system","links","monitor"];function Se(e){try{return e()}catch{return}}async function J(e){try{return await e()}catch{return}}function ke(){let e={listeners:new Map};function t(o,i){let s=e.listeners.get(o);if(s)for(let d of s)Se(function(){d(i)})}function r(o,i){let s=e.listeners.get(o);s||(s=new Set,e.listeners.set(o,s)),s.add(i);let d=s;return function(){d.delete(i)}}function n(){e.listeners.clear()}return{publish:t,subscribe:r,clear:n}}function Te(){let e=new Map,t=new Map;function r(g){e.set(g.id,{domain:g,started:!1})}function n(g){let b=e.get(g);b?.started&&b.domain.stop(),e.delete(g)}function o(g){let b=e.get(g);return b?b.domain:null}function i(){return Array.from(e.keys())}function s(g){let b=e.get(g);b&&(b.started=!0)}function d(g){return e.get(g)?.started??!1}function c(g,b){t.set(g.id,{category:g,presenter:b})}function u(g){t.delete(g)}function a(){return Array.from(t.values()).sort(function(b,h){let l=b.category.order??999,m=h.category.order??999;return l!==m?l-m:b.category.label.localeCompare(h.category.label)})}function y(g){return t.get(g)?.presenter??null}function p(){e.clear(),t.clear()}return{registerDomain:r,unregisterDomain:n,getDomain:o,listDomains:i,markStarted:s,isStarted:d,registerCategory:c,unregisterCategory:u,getCategories:a,getPresenter:y,clear:p}}var B={enabled:!0,mode:"development-only",theme:{mode:"system",accent:"#3bb273",density:"compact",radius:"md"},features:{auth:{enabled:!0,provider:"better-auth"},routes:{enabled:!0,includeApiRoutes:!0,includeDynamic:!0},performance:{enabled:!0,fpsThreshold:50,hourlyIssueThreshold:5,captureReactCommits:!0,captureLongTasks:!0},system:{enabled:!0,includeUserAgent:!0,includeEnv:!0},links:{enabled:!0,includeExternal:!0,validateInternal:!0},monitor:{enabled:!0}},keyboard:{toggleKey:"`",enableShortcuts:!0},accessibility:{reducedMotion:"system",announceUpdates:!0},rightRail:{enabled:!1,defaultPanel:null,collapsible:!0,panels:[]}};function Pe(e){let t=new Set(e.disable??[]),r={};for(let n of ne){let o=B.features[n],i=e.features?.[n];if(i!==void 0){typeof i=="boolean"?r[n]={...o,enabled:i}:r[n]={...o,...i,enabled:i.enabled??o.enabled};continue}if(t.has(n)){r[n]={...o,enabled:!1};continue}r[n]={...o}}return{enabled:e.enabled??B.enabled,mode:e.mode??B.mode,theme:{mode:e.theme?.mode??B.theme.mode,accent:e.theme?.accent??B.theme.accent,density:e.theme?.density??B.theme.density,radius:e.theme?.radius??B.theme.radius},features:r,keyboard:{toggleKey:e.keyboard?.toggleKey??B.keyboard.toggleKey,enableShortcuts:e.keyboard?.enableShortcuts??B.keyboard.enableShortcuts},accessibility:{reducedMotion:e.accessibility?.reducedMotion??B.accessibility.reducedMotion,announceUpdates:e.accessibility?.announceUpdates??B.accessibility.announceUpdates},rightRail:{enabled:e.rightRail?.enabled??B.rightRail.enabled,defaultPanel:e.rightRail?.defaultPanel??B.rightRail.defaultPanel,collapsible:e.rightRail?.collapsible??B.rightRail.collapsible,panels:e.rightRail?.panels??B.rightRail.panels}}}function Ee(e){let t=Pe(e),r=ke(),n=Te(),o=!1;function i(){return{registerDomain(u){n.registerDomain(u)},registerCategory(u,a){n.registerCategory(u,a)},onEvent(u,a){return r.subscribe(u,a)}}}async function s(){if(o)return;let u=ne.filter(function(y){return t.features[y]?.enabled!==!1});for(let a of u){let y=n.getDomain(a);y&&await J(async function(){await y.setup(t.features[a]??{})})}for(let a of u){let y=n.getDomain(a);y&&(await J(async function(){await y.start()}),n.markStarted(a))}o=!0}async function d(){if(!o)return;let u=n.listDomains().reverse();for(let a of u){if(!n.isStarted(a))continue;let y=n.getDomain(a);y&&await J(async function(){await y.stop()})}r.clear(),o=!1}async function c(u){let a=i();await J(async function(){await u.register(a)})}return{config:t,bus:r,registry:n,start:s,stop:d,registerPlugin:c}}function Me(e){let t=(e?e.baseUrl:void 0)??"/api/auth";async function r(){try{let o=await fetch(`${t}/session`,{credentials:"include"});if(!o.ok)return null;let i=await o.json();if(!i||typeof i!="object")return null;let s=i.user,d=i.session;if(!s||!d)return null;let c={userId:String(s.id??"")},u=s.email;typeof u=="string"&&(c.email=u);let a=s.role;typeof a=="string"&&(c.role=a);let y=s.image;typeof y=="string"&&(c.image=y);let p=d.expiresAt;return typeof p=="string"?c.expiresAt=p:p instanceof Date&&(c.expiresAt=p.toISOString()),c}catch{return null}}async function n(){await fetch(`${t}/sign-out`,{method:"POST",credentials:"include"})}return{id:"better-auth",getSession:r,signOut:n}}function Ce(){async function e(){if(typeof document>"u")return null;let t=document.cookie.split(";").reduce(function(o,i){let[s,d]=i.trim().split("=");return s&&(o[s]=d??""),o},{});return t.session??t["auth-token"]??t.__session?{userId:"inferred"}:null}return{id:"cookie",getSession:e}}function De(){function e(r){try{let o=r.split(".")[1];if(!o)return null;let i=atob(o.replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(i)}catch{return null}}async function t(){if(typeof document>"u")return null;let r=document.cookie.split(";"),n=null;for(let u of r){let a=u.trim();if(a.startsWith("token=")||a.startsWith("jwt=")){n=a.split("=").slice(1).join("=");break}}if(!n)return null;let o=e(n);if(!o)return null;let i={userId:String(o.sub??o.id??"unknown")},s=o.email;typeof s=="string"&&(i.email=s);let d=o.role;typeof d=="string"&&(i.role=d);let c=o.exp;return typeof c=="number"&&(i.expiresAt=new Date(c*1e3).toISOString()),i}return{id:"jwt",getSession:t}}function Ft(e){if(e?.customProvider)return e.customProvider;switch(e?.provider){case"cookie":return Ce();case"jwt":return De();default:return Me(e?.options)}}function Ae(e,t){let r,n={provider:"unknown",authenticated:!1,confidence:"unknown",session:null,error:null},o=new Set,i=null,s=null;function d(){for(let l of o)l(n)}async function c(){try{let l=await r.getSession(),m=n.authenticated;n={provider:r.id,authenticated:l!==null,confidence:r.id==="better-auth"?"confirmed":"inferred",session:l,error:null},d(),n.authenticated!==m&&e.publish("auth/state-changed",{provider:n.provider,authenticated:n.authenticated})}catch(l){n={...n,error:l instanceof Error?l.message:"Session check failed"},d()}}function u(l){r=Ft(t),n={...n,provider:r.id}}async function a(){await c(),i=setInterval(c,3e4),s=e.subscribe("auth/sign-out",async()=>{r.signOut&&(await r.signOut(),await c())})}function y(){i&&(clearInterval(i),i=null),s&&(s(),s=null)}function p(){return n}function g(l){return o.add(l),function(){o.delete(l)}}function b(){return{provider:n.provider,authenticated:n.authenticated,confidence:n.confidence,hasSession:n.session!==null,error:n.error}}function h(){return n.error===null}return{id:"auth",setup:u,start:a,stop:y,getState:p,subscribe:g,serializeDiagnostics:b,runHealthCheck:h,signOut:async()=>{e.publish("auth/sign-out",{})}}}function Ie(e){let t=0,r=0,n=null,o=!1;function i(c){if(!o)return;t++,r===0&&(r=c);let u=c-r;if(u>=1e3){let a=Math.round(t*1e3/u);e(a),t=0,r=c}n=requestAnimationFrame(i)}function s(){o||(o=!0,t=0,r=0,n=requestAnimationFrame(i))}function d(){o=!1,n!==null&&(cancelAnimationFrame(n),n=null)}return{start:s,stop:d}}function ze(e){let t=Array.from({length:e}),r=0,n=0;function o(u){t[r]=u,r=(r+1)%e,n<e&&n++}function i(){return n<e?t.slice(0,n):[...t.slice(r),...t.slice(0,r)]}function s(u){let a=i();return a.slice(Math.max(0,a.length-u))}function d(){return n}function c(){r=0,n=0}return{push:o,getAll:i,getRecent:s,count:d,clear:c}}function Le(e,t){let r=[],n=null;async function o(){if(r.length===0)return;let c=r.splice(0);try{await e(c)}catch{}}function i(c){r.push(c)}function s(){n||(n=setInterval(o,t))}function d(){n&&(clearInterval(n),n=null),o()}return{add:i,flush:o,start:s,stop:d}}var Bt={fps_drop:{low:1,medium:2,high:3},long_task:{low:1,medium:2,high:4},react_commit_burst:{low:1,medium:2,high:3},dom_mutation_burst:{low:1,medium:2,high:3},scroll_pressure:{low:0,medium:1,high:2},route_transition_slow:{low:1,medium:2,high:3},hydration_warning:{low:1,medium:2,high:3}};function Ot(e,t){let r=t??Bt,n=0;for(let o of e){let i=r[o.eventType];i&&(n+=i[o.severity]??0)}return n}function Fe(e,t,r){return Ot(e,r)>=t}function Be(e){let t=new Set;for(let o of e)if(o.suspects?.components)for(let i of o.suspects.components)t.add(i);let r=new Set;for(let o of e)r.add(o.route);let n={events:e,suspects:Array.from(t)};if(r.size===1){let o=Array.from(r)[0];o&&(n.route=o)}return n}function Oe(e){let t=new Map;for(let s of e.events)t.set(s.eventType,(t.get(s.eventType)??0)+1);let r=e.events.filter(function(d){return d.severity==="high"}),n=e.suspects??[],o=[];return t.get("fps_drop")&&o.push("Investigate render-heavy components for unnecessary re-renders"),t.get("long_task")&&o.push("Move expensive computations to Web Workers or useMemo"),t.get("react_commit_burst")&&o.push("Check for cascading state updates causing commit bursts"),t.get("dom_mutation_burst")&&o.push("Batch DOM mutations or use virtualization for large lists"),t.get("scroll_pressure")&&o.push("Add scroll event throttling or passive listeners"),t.get("route_transition_slow")&&o.push("Lazy-load route components and preload critical data"),{summary:`Detected ${e.events.length} performance events (${r.length} high severity). ${n.length} suspect component(s) identified.`,hotspots:Array.from(n),suggestions:o,confidence:n.length>0?.7:.4}}function j(e){return typeof e=="object"&&e!==null}function Nt(e){return typeof e=="function"}function Wt(e){return j(e)}function $t(e){return j(e)}function Ht(){let t=globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__;return Wt(t)?t:null}function We(e){return typeof e=="number"&&Number.isFinite(e)?e:0}function Kt(e){let t=e[0];return t?t.toUpperCase()===t:!1}function Ne(e){if(typeof e=="function"){let t=e;return t.displayName??t.name??null}if(typeof e=="string")return Kt(e)?e:null;if(j(e)){let t=e.displayName;if(typeof t=="string"&&t.length>0)return t}return null}function _t(e){let t=Ne(e.elementType)??Ne(e.type);if(t)return t;if(j(e.stateNode)){let r=e.stateNode.constructor;if(j(r)){let n=r.name;if(typeof n=="string"&&n.length>0)return n}}return null}function fe(e,t){if(!e)return;let r=We(e.actualDuration),n=_t(e);n&&r>0&&t.push({name:n,duration:r}),e.child&&fe(e.child,t),e.sibling&&fe(e.sibling,t)}function qt(e,t){let r=e.sort(function(s,d){return d.duration-s.duration}),n=[],o=new Set;for(let i of r)if(!o.has(i.name)&&(o.add(i.name),n.push(i.name),n.length>=t))break;return n}function Ut(e){if(!j(e))return null;let t=e.current;if(!$t(t))return null;let r=t,n=We(r.actualDuration),o=[];fe(r,o);let i=qt(o,5);return{duration:n,components:i}}function $e(e){let t=Ht();if(!t)return null;let r=t.onCommitFiberRoot;function n(o,i,s){try{let d=Ut(i);d&&e(d)}catch{}Nt(r)&&r(o,i,s)}return t.onCommitFiberRoot=n,function(){t.onCommitFiberRoot=r}}var Vt=0;function Xt(){return`perf-${Date.now()}-${Vt++}`}function jt(){return`sess-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}var Gt=new Set(["DevWidget","Shell","ThemeProvider","Panel","Header","Footer","TabsView","RightRail","AuthTab","PerfTab","RoutesTab","MonitorTab"]),Jt=new Set(["App","Root","Layout","Page","Provider"]);function Yt(e){let t=[];for(let r of e)Gt.has(r)||t.push(r);return t}function Qt(e){let t=[];for(let r of e)Jt.has(r)||t.push(r);return t}function Zt(e){let t=Yt(e),r=Qt(t);return r.length>0?r.slice(0,5):t.slice(0,5)}function He(e,t){let r=jt(),n=ze(500),o=Le(async function(){},3e4),i={},s={fps:60,isScrolling:!1,scrollFps:60,events:[],hourlyCount:0,analysisRunning:!1,lastReport:null},d=new Set,c=null,u=null,a=null,y=null,p=null,g=null,b=[],h=0;function l(){for(let R of d)R(s)}function m(R,C){return R<C*.5?"high":R<C*.75?"medium":"low"}function S(){return typeof window<"u"?window.location.pathname:"/"}function k(){return typeof window>"u"?{}:{userAgent:navigator.userAgent,viewport:{w:window.innerWidth,h:window.innerHeight}}}function w(R){n.push(R),o.add(R),s={...s,events:n.getRecent(50),hourlyCount:s.hourlyCount+1},l(),R.severity==="high"&&e.publish("performance/drop-detected",{fps:R.metrics.fps??0,reasons:[R.eventType]})}function F(R,C,O,I){let L={id:Xt(),timestamp:new Date().toISOString(),sessionId:r,route:S(),eventType:R,severity:C,metrics:O,context:k()};return I&&(L.suspects=I),L}let $=Ie(function(C){let O={...s,fps:C};if(s.isScrolling){let L=s.scrollFps,_=Math.round(L*.7+C*.3);O={...O,scrollFps:_}}s=O,l();let I=i.fpsThreshold??50;if(C<I){let L=m(C,I);w(F("fps_drop",L,{fps:C}))}});function A(){if(typeof window>"u")return;let R=()=>{s.isScrolling||(s={...s,isScrolling:!0},l()),p&&clearTimeout(p),p=setTimeout(()=>{s={...s,isScrolling:!1},l(),p=null},150)};return window.addEventListener("scroll",R,{passive:!0}),()=>{window.removeEventListener("scroll",R),p&&clearTimeout(p)}}let T=null;function P(){if(!(typeof PerformanceObserver>"u")&&(i.captureLongTasks??!0))try{c=new PerformanceObserver(function(C){for(let O of C.getEntries()){let I=O.duration,L="low";I>200?L="high":I>100&&(L="medium"),w(F("long_task",L,{longTaskDurationMs:I}))}}),c.observe({type:"longtask",buffered:!1})}catch{}}function H(){if(typeof MutationObserver>"u"||typeof document>"u")return;let R=0,C=null;u=new MutationObserver(function(I){R+=I.length,!C&&(C=setTimeout(function(){if(R>50){let _=R>200?"high":R>100?"medium":"low";w(F("dom_mutation_burst",_,{mutationCount:R}))}R=0,C=null},1e3))}),u.observe(document.body,{childList:!0,subtree:!0,attributes:!0})}function V(R){if(R.duration<16)return;let O=R.duration>80?"high":R.duration>40?"medium":"low",I=Zt(R.components),L=I.length>0?{components:I}:void 0;w(F("react_commit_burst",O,{commitCount:1},L));let _=Date.now();for(b.push(_);b.length>0;){let f=b[0];if(f===void 0||_-f<=2e3)break;b.shift()}b.length>=5&&_-h>5e3&&(h=_,w(F("react_commit_burst","high",{commitCount:b.length},L)))}async function se(){let R=i.hourlyIssueThreshold??5,C=n.getAll();if(Fe(C,R*3)){s={...s,analysisRunning:!0},l();try{let O=Be(C),I;t?I=await t.analyze(O):I=Oe(O);let L=`report-${Date.now()}`;s={...s,analysisRunning:!1,lastReport:I.summary},l(),e.publish("performance/analysis-complete",{reportId:L})}catch{s={...s,analysisRunning:!1},l()}}}function ae(R){i=R}async function de(){$.start(),P(),H(),T=A()||null,o.start(),(i.captureReactCommits??!0)&&(g=$e(V)),a=setInterval(function(){s={...s,hourlyCount:0},l()},36e5),y=setInterval(se,6e4)}function ue(){$.stop(),o.stop(),c&&(c.disconnect(),c=null),u&&(u.disconnect(),u=null),a&&(clearInterval(a),a=null),y&&(clearInterval(y),y=null),T&&(T(),T=null),g&&(g(),g=null)}function le(){return s}function ce(R){return d.add(R),function(){d.delete(R)}}function Z(){return{fps:s.fps,totalEvents:n.count(),hourlyCount:s.hourlyCount,analysisRunning:s.analysisRunning,lastReport:s.lastReport}}function ee(){return s.fps>0}function te(){n.clear(),b.length=0,s={fps:60,isScrolling:!1,scrollFps:60,events:[],hourlyCount:0,analysisRunning:!1,lastReport:null},l()}return{id:"performance",setup:ae,start:de,stop:ue,getState:le,subscribe:ce,serializeDiagnostics:Z,runHealthCheck:ee,reset:te}}var Ke="/api/dev-widget/routes";function _e(e){let t={routes:[],loading:!1,error:null},r=new Set,n=Ke,o=!1;function i(){for(let p of r)p(t)}function s(p){n=p.endpoint??Ke,o=p.includeApiRoutes??!1,t={...t,loading:!0},i()}async function d(){try{let p=new URL(n,globalThis.location?.origin??"http://localhost:3000");o&&p.searchParams.set("includeApiRoutes","true");let g=await fetch(p.toString());if(!g.ok){t={...t,loading:!1,error:`Route discovery failed (${g.status})`},i();return}let b=await g.json();if(b.error){t={...t,loading:!1,error:b.error},i();return}let h=b.routes??[];t={routes:h,loading:!1,error:null},i(),e.publish("routes/discovered",{count:h.length,routes:h})}catch(p){let g=p instanceof Error?p.message:"Route discovery failed";t={...t,loading:!1,error:g},i()}}function c(){t={routes:[],loading:!1,error:null}}function u(){return t}function a(p){return r.add(p),function(){r.delete(p)}}function y(){return{routeCount:t.routes.length,loading:t.loading,error:t.error}}return{id:"routes",setup:s,start:d,stop:c,getState:u,subscribe:a,serializeDiagnostics:y}}function qe(e){if(e){if(e.provider==="custom")return e.customProvider;e.provider}}import{useState as en,useEffect as tn}from"react";import{Fragment as ge,jsx as N,jsxs as q}from"react/jsx-runtime";function Ue({domain:e}){let[t,r]=en(e.getState());tn(function(){return e.subscribe(r)},[e]);let n=t.confidence==="confirmed"?"Confirmed":t.confidence==="inferred"?"Inferred":"Unknown";return q("div",{role:"region","aria-label":"Authentication status",style:{display:"flex",flexDirection:"column",gap:"var(--dw-gap)"},children:[q("div",{"data-dw-section":"auth-header",style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[q("span",{"data-dw-label":"provider",children:["Provider: ",t.provider]}),q("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[N("span",{"data-dw-badge":t.confidence,children:n}),t.authenticated&&N("button",{onClick:()=>e.signOut?.(),style:{background:"transparent",border:"1px solid var(--dw-border)",color:"var(--dw-text-muted)",borderRadius:"4px",padding:"2px 6px",fontSize:"10px",cursor:"pointer"},"data-dw-action":"sign-out",children:"Sign Out"})]})]}),t.error&&N("div",{"data-dw-alert":"warning",role:"alert",style:{color:"var(--dw-warning)",padding:"var(--dw-padding)",background:"var(--dw-bg-secondary)",borderRadius:"var(--dw-radius)"},children:t.error}),t.session?q("dl",{"data-dw-section":"auth-details",style:{display:"grid",gridTemplateColumns:"auto 1fr",gap:"var(--dw-gap)",fontSize:"11px"},children:[N("dt",{style:{color:"var(--dw-text-muted)"},children:"User ID"}),N("dd",{style:{fontFamily:"monospace"},children:t.session.userId}),t.session.email&&q(ge,{children:[N("dt",{style:{color:"var(--dw-text-muted)"},children:"Email"}),N("dd",{style:{fontFamily:"monospace"},children:t.session.email})]}),t.session.role&&q(ge,{children:[N("dt",{style:{color:"var(--dw-text-muted)"},children:"Role"}),N("dd",{style:{fontFamily:"monospace"},children:t.session.role})]}),t.session.expiresAt&&q(ge,{children:[N("dt",{style:{color:"var(--dw-text-muted)"},children:"Expires"}),N("dd",{style:{fontFamily:"monospace"},children:t.session.expiresAt})]})]}):q("div",{"data-dw-empty":!0,style:{textAlign:"center",padding:"var(--dw-padding)",color:"var(--dw-text-muted)",background:"var(--dw-bg-secondary)",borderRadius:"var(--dw-radius)"},children:[N("p",{style:{margin:0},children:"No active session"}),N("p",{style:{margin:0,fontSize:"10px",opacity:.8},children:"Sign in to see session details"})]})]})}import{useState as re,useEffect as Ve,useMemo as Xe}from"react";import{jsx as D,jsxs as z}from"react/jsx-runtime";function nn(e){let t=[];return e.metrics.fps&&t.push(`FPS ${Math.round(e.metrics.fps)}`),e.metrics.longTaskDurationMs&&t.push(`Long task ${Math.round(e.metrics.longTaskDurationMs)}ms`),e.metrics.commitCount&&t.push(`Commits ${e.metrics.commitCount}`),e.metrics.mutationCount&&t.push(`Mutations ${e.metrics.mutationCount}`),e.metrics.scrollEventCount&&t.push(`Scroll ${e.metrics.scrollEventCount}`),t.length>0?t.join(" | "):null}function je(e){return e.suspects?.components?.slice(0,5)??[]}function rn(e){return e==="App"||e==="Root"||e==="Layout"||e==="Page"||e==="Provider"}function on(e){switch(e.eventType){case"fps_drop":return{what:"Frame rate dropped under your FPS threshold.",where:`Route ${e.route} at ${new Date(e.timestamp).toLocaleTimeString()}.`,fix:"Reduce render work, virtualize long lists, and split heavy components."};case"long_task":return{what:"Main thread was blocked by a long task.",where:`Detected on ${e.route} (${Math.round(e.metrics.longTaskDurationMs??0)}ms).`,fix:"Move heavy work to workers, chunk loops, and defer non-critical JS."};case"react_commit_burst":return{what:"React commit activity spiked and likely caused UI jank.",where:`Commit burst on ${e.route}.`,fix:"Memoize expensive trees and avoid state updates that fan out broadly."};case"dom_mutation_burst":return{what:"DOM mutation volume was unusually high.",where:`Mutation burst on ${e.route}.`,fix:"Batch DOM writes and avoid repeated mount/unmount loops."};default:return{what:"A performance signal was recorded.",where:`Route ${e.route}.`,fix:"Inspect the latest event details and test with the same user flow."}}}function Ge(e){return e==="high"?"var(--dw-danger)":e==="medium"?"var(--dw-warning)":"var(--dw-success)"}function sn(e){return e.toLowerCase().replace(/[^a-z0-9_-]/g,"")}function an(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[^a-zA-Z0-9-]/g,"").toLowerCase()}function dn(e){if(typeof document>"u")return[];let t=sn(e),r=an(e),n=[`[data-component="${e}"]`,`[data-testid*="${t}"]`,`[id*="${t}"]`,`[class*="${t}"]`,r],o=new Set;for(let i of n)try{let s=document.querySelectorAll(i);for(let d of s)d instanceof HTMLElement&&o.add(d)}catch{}return Array.from(o).slice(0,6)}function Je({domain:e}){let[t,r]=re(e.getState()),[n,o]=re(null),[i,s]=re(null),[d,c]=re(null);Ve(function(){return e.subscribe(r)},[e]);let u=Xe(function(){return t.events.slice(-12).reverse()},[t.events]);Ve(function(){if(!n)return;u.some(function(k){return k.id===n})||o(u[0]?.id??null)},[n,u]);let a=Xe(function(){return u.length===0?null:n?u.find(function(S){return S.id===n})??u[0]??null:u[0]??null},[n,u]);function y(l){s(l);let m=dn(l);if(m.length===0){c(`No DOM node matched "${l}". Add data-component="${l}" for direct targeting.`);return}c(`Highlighted ${m.length} node${m.length>1?"s":""} for "${l}".`);let S=m.map(function(w){return{target:w,outline:w.style.outline,outlineOffset:w.style.outlineOffset,transition:w.style.transition,boxShadow:w.style.boxShadow}});for(let k of S)k.target.style.transition="outline 0.15s ease, box-shadow 0.15s ease",k.target.style.outline="2px solid var(--dw-accent)",k.target.style.outlineOffset="2px",k.target.style.boxShadow="0 0 0 4px rgba(59, 130, 246, 0.2)";m[0]?.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"}),setTimeout(function(){for(let w of S)w.target.style.outline=w.outline,w.target.style.outlineOffset=w.outlineOffset,w.target.style.transition=w.transition,w.target.style.boxShadow=w.boxShadow},2200)}let p=t.fps>=55?"var(--dw-success)":t.fps>=40?"var(--dw-warning)":"var(--dw-danger)",g=a?on(a):null,b=a?je(a):[],h=b.some(function(m){return!rn(m)});return z("div",{role:"region","aria-label":"Performance monitor",style:{display:"flex",flexDirection:"column",gap:"12px"},children:[z("div",{"data-dw-section":"perf-header",style:{display:"grid",gridTemplateColumns:"1fr auto auto",alignItems:"center",gap:"10px",padding:"10px",borderRadius:"var(--dw-radius)",border:"1px solid var(--dw-border)",background:"var(--dw-bg-secondary)"},children:[z("div",{style:{display:"flex",alignItems:"baseline",gap:"8px"},children:[z("span",{"data-dw-metric":"fps",style:{color:p,fontWeight:"bold"},children:[t.fps," FPS"]}),z("span",{"data-dw-metric":"scroll-fps",style:{fontSize:"10px",color:t.isScrolling?"var(--dw-accent)":"var(--dw-text-muted)",fontWeight:t.isScrolling?"bold":"normal",transition:"color 0.2s"},children:[t.scrollFps," Scroll FPS"]})]}),z("span",{"data-dw-label":"events",style:{color:"var(--dw-text-muted)"},children:[t.hourlyCount," events/hr"]}),t.analysisRunning&&D("span",{"data-dw-badge":"analyzing","aria-live":"polite",style:{color:"var(--dw-accent)",fontSize:"10px",fontWeight:700,padding:"2px 6px",borderRadius:"999px",border:"1px solid var(--dw-accent)"},children:"Analyzing..."})]}),t.lastReport&&z("div",{"data-dw-section":"perf-report","aria-live":"polite",style:{padding:"var(--dw-padding)",background:"var(--dw-bg-secondary)",borderRadius:"var(--dw-radius)"},children:[D("h4",{style:{margin:"0 0 4px 0",fontSize:"11px",color:"var(--dw-text-muted)",textTransform:"uppercase"},children:"Latest Analysis"}),D("p",{style:{margin:0},children:t.lastReport})]}),a&&g&&z("div",{"data-dw-section":"perf-guide",style:{display:"grid",gap:"8px",padding:"10px",background:"var(--dw-bg-secondary)",borderRadius:"var(--dw-radius)",border:`1px solid ${Ge(a.severity)}`},children:[D("h4",{style:{margin:0,fontSize:"11px",textTransform:"uppercase"},children:"Issue Guide"}),z("div",{style:{display:"grid",gap:"2px"},children:[D("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:"What"}),D("span",{style:{fontSize:"11px"},children:g.what})]}),z("div",{style:{display:"grid",gap:"2px"},children:[D("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:"Where"}),D("span",{style:{fontSize:"11px"},children:g.where})]}),z("div",{style:{display:"grid",gap:"2px"},children:[D("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:"How to fix"}),D("span",{style:{fontSize:"11px"},children:g.fix})]}),b.length>0&&z("div",{style:{display:"grid",gap:"4px"},children:[D("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:"Suspect components"}),D("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap"},children:b.map(function(m){let S=i===m;return D("button",{onClick:function(){y(m)},style:{borderRadius:"999px",border:"1px solid var(--dw-border)",padding:"2px 8px",fontSize:"10px",cursor:"pointer",background:S?"var(--dw-accent)":"var(--dw-bg)",color:S?"#fff":"var(--dw-text)"},children:m},m)})}),D("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:h?"Click a suspect to highlight likely DOM nodes.":"Only generic names detected. Add data-component on app nodes for precise mapping."}),d&&D("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:d})]})]}),z("div",{"data-dw-section":"perf-events",style:{display:"flex",flexDirection:"column",gap:"8px"},children:[z("h4",{style:{margin:0,fontSize:"11px",color:"var(--dw-text-muted)",textTransform:"uppercase"},children:["Recent Events (",u.length,")"]}),u.length===0?z("div",{"data-dw-empty":!0,style:{textAlign:"center",padding:"var(--dw-padding)",color:"var(--dw-text-muted)",background:"var(--dw-bg-secondary)",borderRadius:"var(--dw-radius)"},children:[D("p",{style:{margin:0},children:"No performance issues detected"}),D("p",{style:{margin:0,fontSize:"10px",opacity:.8},children:"Events appear when thresholds are crossed"})]}):D("ul",{"data-dw-list":"events",style:{listStyle:"none",padding:0,margin:0,display:"flex",flexDirection:"column",gap:"4px"},children:u.map(function(m){let S=nn(m),k=je(m),w=a?.id===m.id;return D("li",{children:z("button",{onClick:function(){o(m.id)},"data-dw-severity":m.severity,style:{display:"grid",gridTemplateColumns:"1fr auto",gap:"4px",padding:"8px",background:w?"rgba(255, 255, 255, 0.06)":"var(--dw-bg-secondary)",borderRadius:"var(--dw-radius)",border:`1px solid ${w?"var(--dw-accent)":"var(--dw-border)"}`,borderLeft:`3px solid ${Ge(m.severity)}`,textAlign:"left",cursor:"pointer",width:"100%"},children:[z("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:[z("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[D("span",{"data-dw-label":"type",style:{fontWeight:500},children:m.eventType}),D("span",{"data-dw-label":"route",style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:m.route})]}),S&&D("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:S}),k.length>0&&z("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:["Suspects: ",k.join(", ")]})]}),D("time",{dateTime:m.timestamp,style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:new Date(m.timestamp).toLocaleTimeString()})]})},m.id)})})]})]})}import{useState as un,useEffect as ln}from"react";import{jsx as K,jsxs as me}from"react/jsx-runtime";function Ye({domain:e}){let[t,r]=un(e.getState());if(ln(function(){return e.subscribe(r)},[e]),t.loading)return K("div",{role:"region","aria-label":"Routes","aria-busy":"true",children:K("p",{children:"Discovering routes..."})});if(t.error)return K("div",{role:"region","aria-label":"Routes",children:K("div",{"data-dw-alert":"warning",role:"alert",children:t.error})});let n=new Map;for(let o of t.routes){let i=o.group??"ungrouped",s=n.get(i)??[];s.push(o),n.set(i,s)}return K("div",{role:"region","aria-label":"Routes",style:{display:"flex",flexDirection:"column",gap:"var(--dw-gap)"},children:t.routes.length===0?me("div",{"data-dw-empty":!0,style:{textAlign:"center",padding:"var(--dw-padding)",color:"var(--dw-text-muted)",background:"var(--dw-bg-secondary)",borderRadius:"var(--dw-radius)"},children:[K("p",{style:{margin:0},children:"No routes discovered"}),K("p",{style:{margin:0,fontSize:"10px",opacity:.8},children:"Routes are detected from app directory structure"})]}):Array.from(n.entries()).map(function([i,s]){return me("div",{"data-dw-section":"route-group",style:{display:"flex",flexDirection:"column",gap:"4px"},children:[K("h4",{style:{margin:"8px 0 4px 0",fontSize:"11px",color:"var(--dw-text-muted)",textTransform:"uppercase"},children:i}),K("ul",{"data-dw-list":"routes",style:{listStyle:"none",padding:0,margin:0,display:"flex",flexDirection:"column",gap:"2px"},children:s.map(function(c){return me("li",{"data-dw-dynamic":c.isDynamic,style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 8px",background:"var(--dw-bg-secondary)",borderRadius:"var(--dw-radius)",fontSize:"11px"},children:[K("code",{style:{color:c.isDynamic?"var(--dw-accent)":"var(--dw-text)"},children:c.path}),c.sourceFile&&K("span",{"data-dw-label":"source",style:{fontSize:"10px",color:"var(--dw-text-muted)",opacity:.7},children:c.sourceFile.split("/").pop()})]},c.path)})})]},i)})})}function Qe(e){if(typeof console>"u")return()=>{};let t=console.log,r=console.warn,n=console.error;function o(i,s){try{e({type:i,args:s})}catch{}}return console.log=(...i)=>{t.apply(console,i),o("log",i)},console.warn=(...i)=>{r.apply(console,i),o("warn",i)},console.error=(...i)=>{n.apply(console,i),o("error",i)},()=>{console.log=t,console.warn=r,console.error=n}}function tt(e){return e?e.includes("application/json")||e.includes("text/")||e.includes("application/javascript"):!1}function Ze(e){let t=[];return e.forEach(function(n,o){t.push({name:o,value:n})}),t}function G(e,t,r){let n=new TextEncoder().encode(e),o=n.length,i=o>r,s=i?n.slice(0,r):n;return{text:new TextDecoder().decode(s),size:o,truncated:i,contentType:t}}async function cn(e,t){let r=e.headers.get("content-type");if(tt(r))try{let n=await e.text();return G(n,r,t)}catch{return}}async function pn(e,t){let r=e.headers.get("content-type");if(tt(r))try{let n=await e.text();return G(n,r,t)}catch{return}}function fn(e){let t=e.split(/\r?\n/),r=[];for(let n of t){if(!n)continue;let o=n.indexOf(":");if(o===-1)continue;let i=n.slice(0,o).trim(),s=n.slice(o+1).trim();r.push({name:i,value:s})}return r}function ye(e){return e.__dwInfo??null}function gn(e,t){let r=e;r.__dwInfo=t}function mn(e,t,r){if(t!=null){if(typeof t=="string"){e.body=G(t,null,r);return}if(t instanceof URLSearchParams){e.body=G(t.toString(),"application/x-www-form-urlencoded",r);return}if(t instanceof FormData){let n=[];t.forEach(function(i,s){n.push(`${s}=${String(i)}`)}),e.body=G(n.join("&"),"multipart/form-data",r)}}}function ve(e,t,r,n){return n?{url:e,method:t,headers:r,body:n}:{url:e,method:t,headers:r}}function et(e,t,r,n,o){return o?{status:e,statusText:t,ok:r,headers:n,body:o}:{status:e,statusText:t,ok:r,headers:n}}function nt(e){if(typeof window>"u")return()=>{};let t=window.fetch,r=window.XMLHttpRequest,n=r.prototype.open,o=r.prototype.send,i=r.prototype.setRequestHeader,s=65536,d=async function(...c){let u=performance.now(),a=null,y=[],p;try{a=new Request(c[0],c[1]),y=Ze(a.headers);let g=a.clone();p=await pn(g,s)}catch{}try{let g=await t(...c),b=Math.round(performance.now()-u),h=Ze(g.headers),l;try{let m=g.clone();l=await cn(m,s)}catch{}return e({request:ve(a?.url??String(c[0]),a?.method??"GET",y,p),response:et(g.status,g.statusText,g.ok,h,l),durationMs:b}),g}catch(g){let b=Math.round(performance.now()-u),h={request:ve(a?.url??String(c[0]),a?.method??"GET",y,p),durationMs:b};throw g instanceof Error?h.error=g.message:h.error="Network error",e(h),g}};return window.fetch=d,r.prototype.open=function(c,u,a,y,p){return gn(this,{method:c,url:u,headers:[],start:0}),n.call(this,c,u,a??!0,y??null,p??null)},r.prototype.setRequestHeader=function(c,u){let a=ye(this);return a&&a.headers.push({name:c,value:u}),i.call(this,c,u)},r.prototype.send=function(c){let u=ye(this);u&&(u.start=performance.now(),mn(u,c,s));let a=()=>{this.removeEventListener("loadend",a);let y=ye(this);if(!y)return;let p=Math.round(performance.now()-y.start),g=fn(this.getAllResponseHeaders()),b=this.status,h=this.statusText||"",l=b>=200&&b<300,m;(this.responseType===""||this.responseType==="text")&&typeof this.responseText=="string"&&(m=G(this.responseText,this.getResponseHeader("content-type"),s));let S={request:ve(y.url,y.method,y.headers,y.body),response:et(b,h,l,g,m),durationMs:p};!l&&this.statusText&&(S.error=this.statusText),e(S)};return this.addEventListener("loadend",a),o.call(this,c??null)},()=>{window.fetch=t,r.prototype.open=n,r.prototype.send=o,r.prototype.setRequestHeader=i}}function rt(){let e={rules:[],matches:[],isListening:!1},t=new Set,r=null,n=null;function o(){for(let l of t)l(e)}function i(l){let m={...l,id:Math.random().toString(36).slice(2),enabled:!0};e={...e,rules:[...e.rules,m]},o()}function s(l){e={...e,rules:e.rules.filter(m=>m.id!==l)},o()}function d(){e={...e,matches:[]},o()}function c(l){e={...e,rules:e.rules.map(m=>m.id===l?{...m,enabled:!m.enabled}:m)},o()}function u(l,m){if(!m.enabled)return!1;try{if(m.match.startsWith("/")&&m.match.lastIndexOf("/")>0){let S=m.match.lastIndexOf("/"),k=m.match.slice(1,S),w=m.match.slice(S+1);return new RegExp(k,w).test(l)}return l.includes(m.match)}catch{return l.includes(m.match)}}function a(l){let m=l.args.map(function(w){if(typeof w=="string")return w;try{return JSON.stringify(w)}catch{return String(w)}}).join(" "),S=e.rules.filter(function(w){return w.type==="console"}).filter(function(w){return u(m,w)});if(S.length>0){let k=S.map(function(F){let $={type:"console",level:l.type,args:l.args};return{id:Math.random().toString(36).slice(2),ruleId:F.id,timestamp:Date.now(),content:m,details:$}});e={...e,matches:[...k,...e.matches].slice(0,100)},o()}}function y(l){let m=l.response?.status??0,S=l.request.method,k=l.request.url,w=`${S} ${k} ${m}`,F=e.rules.filter(function(A){return A.type==="network"}).filter(function(A){return u(w,A)});if(F.length>0){let $=F.map(function(T){let P={type:"network",request:l.request,durationMs:l.durationMs};return l.response&&(P.response=l.response),l.error&&(P.error=l.error),{id:Math.random().toString(36).slice(2),ruleId:T.id,timestamp:Date.now(),content:w,details:P}});e={...e,matches:[...$,...e.matches].slice(0,100)},o()}}function p(l){}function g(){e.isListening||(r=Qe(a),n=nt(y),e={...e,isListening:!0},o())}function b(){r&&(r(),r=null),n&&(n(),n=null),e={...e,isListening:!1},o()}return{id:"monitor",setup:p,start:g,stop:b,getState:function(){return e},subscribe:function(m){return t.add(m),function(){t.delete(m)}},addRule:i,removeRule:s,toggleRule:c,clearMatches:d}}import{useState as U,useEffect as be}from"react";import{Fragment as wn,jsx as v,jsxs as x}from"react/jsx-runtime";function ot(e){return new Date(e).toLocaleTimeString([],{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})}function yn(e){if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e,null,2)}catch{return String(e)}}function vn(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function it(){if(typeof document>"u")return 0;let e=document.cookie.split(";"),t=0;for(let r of e){let[n]=r.split("="),o=n?.trim();o&&(document.cookie=`${o}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`,t++)}return t}function st(){if(typeof window>"u")return 0;let e=window.localStorage.length+window.sessionStorage.length;return window.localStorage.clear(),window.sessionStorage.clear(),e}async function at(){if(typeof window>"u"||!("caches"in window))return 0;let e=await window.caches.keys();for(let t of e)await window.caches.delete(t);return e.length}function bn(){typeof window>"u"||window.location.reload()}function hn(){if(typeof window>"u")return;let e=new URL(window.location.href);e.searchParams.set("dwcb",String(Date.now())),window.location.assign(e.toString())}function dt({domain:e}){let[t,r]=U(e.getState()),[n,o]=U(""),[i,s]=U("console"),[d,c]=U(!1),[u,a]=U(null),[y,p]=U(!1),[g,b]=U(!1),[h,l]=U(!1),[m,S]=U("");be(()=>e.subscribe(r),[e]),be(function(){if(!u)return;t.matches.some(function(X){return X.id===u})||a(null)},[u,t.matches]),be(function(){p(!1),b(!1)},[u]);function k(){n.trim()&&(e.addRule({type:i,match:n}),o(""))}function w(){t.isListening?e.stop():e.start()}function F(f){s(f.target.value)}function $(f){o(f.target.value)}function A(){c(!0)}function T(){c(!1)}function P(f){f.key==="Enter"&&k()}function H(){e.clearMatches(),a(null)}function V(f){a(f)}async function se(){l(!0);try{let f=st(),E=it();S(`Cleared storage (${f}) and cookies (${E}).`)}finally{l(!1)}}async function ae(){l(!0);try{let f=await at();S(`Cleared cache buckets (${f}).`)}finally{l(!1)}}async function de(){l(!0);try{let f=st(),E=it(),M=await at();S(`Cleared storage (${f}), cookies (${E}), cache (${M}).`)}finally{l(!1)}}async function ue(){l(!0);try{(await fetch("/api/dev-widget/restart",{method:"POST"})).ok?S("Restart request sent to /api/dev-widget/restart."):S("Restart endpoint found but returned non-success status.")}catch{S("No restart endpoint found. Add POST /api/dev-widget/restart to enable it.")}finally{l(!1)}}function le(){p(function(E){return!E})}function ce(){b(function(E){return!E})}function Z(f){return t.rules.find(function(M){return M.id===f})}function ee(f){return f.length===0?v("span",{style:{color:"var(--dw-text-muted)"},children:"None"}):v("ul",{style:{listStyle:"none",margin:0,padding:0,display:"grid",gap:"6px"},children:f.map(function(M){return x("li",{style:{display:"grid",gap:"2px"},children:[v("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:M.name}),v("code",{style:{fontSize:"11px",color:"var(--dw-text)"},children:M.value})]},`${M.name}-${M.value}`)})})}function te(f){return!f||!f.text?v("span",{style:{color:"var(--dw-text-muted)"},children:"No body captured"}):x("div",{style:{display:"grid",gap:"6px"},children:[v("code",{style:{whiteSpace:"pre-wrap",fontSize:"11px",lineHeight:"1.4"},children:f.text}),x("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:[vn(f.size),f.truncated?" (truncated)":""]})]})}function R(){return x("div",{style:{display:"grid",gap:"10px",padding:"12px",borderRadius:"var(--dw-radius)",border:"1px solid var(--dw-border)",background:"var(--dw-bg-secondary)"},children:[x("div",{style:{display:"grid",gap:"2px"},children:[v("span",{style:{fontSize:"10px",textTransform:"uppercase",letterSpacing:"0.05em",color:"var(--dw-text-muted)"},children:"Network Recorder Example"}),v("span",{style:{fontSize:"11px",color:"var(--dw-text)"},children:"Type a rule, press Track, then trigger a request that matches it."})]}),x("div",{style:{display:"grid",gap:"6px"},children:[v("code",{style:{fontSize:"11px"},children:"Rule: `GET /api/orders 500`"}),v("code",{style:{fontSize:"11px"},children:"Rule (regex): `/POST .*checkout/i`"}),v("code",{style:{fontSize:"11px"},children:"Captured: `POST /api/checkout 502 | 784ms`"})]})]})}function C(f){return f.type!=="console"?null:x("div",{style:{display:"grid",gap:"10px"},children:[x("div",{style:{display:"grid",gap:"4px"},children:[v("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:"Level"}),v("code",{style:{fontSize:"11px"},children:f.level})]}),x("div",{style:{display:"grid",gap:"4px"},children:[v("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:"Arguments"}),v("code",{style:{whiteSpace:"pre-wrap",fontSize:"11px"},children:f.args.map(function(M,X){return`${X+1}. ${yn(M)}`}).join(`
2
+ `)})]})]})}function O(f){return f.type!=="network"?null:x("div",{style:{display:"grid",gap:"14px"},children:[x("div",{style:{display:"grid",gap:"6px"},children:[v("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:"Summary"}),x("div",{style:{display:"grid",gap:"4px"},children:[x("code",{style:{fontSize:"11px"},children:[f.request.method," ",f.request.url]}),x("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:["Status ",f.response?.status??0," \u2022 ",f.durationMs,"ms"]}),f.error&&v("span",{style:{fontSize:"10px",color:"var(--dw-danger)"},children:f.error})]})]}),x("div",{style:{display:"grid",gap:"8px"},children:[v("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:"Request"}),ee(f.request.headers),f.request.body&&v("button",{onClick:le,style:{border:"none",background:"transparent",color:"var(--dw-accent)",fontSize:"10px",cursor:"pointer",padding:0,textAlign:"left"},children:y?"Hide body":"Show body"}),y&&te(f.request.body)]}),x("div",{style:{display:"grid",gap:"8px"},children:[v("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:"Response"}),f.response?x(wn,{children:[ee(f.response.headers),f.response.body&&v("button",{onClick:ce,style:{border:"none",background:"transparent",color:"var(--dw-accent)",fontSize:"10px",cursor:"pointer",padding:0,textAlign:"left"},children:g?"Hide body":"Show body"}),g&&te(f.response.body)]}):v("span",{style:{color:"var(--dw-text-muted)"},children:"No response captured"})]})]})}function I(f,E){let M=Z(f.ruleId),X=f.id===u,pe=M?.type??f.details?.type??"console",Lt=pe==="network"?"NET":"LOG";return x("button",{onClick:function(){V(f.id)},style:{display:"flex",flexDirection:"column",gap:"4px",padding:"10px",borderRadius:"8px",background:X?"rgba(59, 130, 246, 0.15)":"var(--dw-bg-secondary)",border:X?"1px solid rgba(59, 130, 246, 0.4)":"1px solid var(--dw-border)",animation:`dw-slide-up 0.3s ease-out backwards ${E*.05}s relative`,position:"relative",overflow:"hidden",textAlign:"left",cursor:"pointer"},children:[v("div",{style:{position:"absolute",left:0,top:0,bottom:0,width:"3px",background:"var(--dw-accent)"}}),x("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[x("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[v("span",{style:{fontSize:"9px",fontWeight:700,color:"var(--dw-text-muted)",fontFamily:"var(--dw-font-mono)"},children:ot(f.timestamp)}),v("span",{style:{padding:"2px 4px",borderRadius:"4px",fontSize:"9px",fontWeight:800,textTransform:"uppercase",background:pe==="network"?"rgba(59, 130, 246, 0.15)":"rgba(245, 158, 11, 0.15)",color:pe==="network"?"#3b82f6":"#f59e0b"},children:Lt})]}),f.details?.type==="console"&&v("span",{style:{fontSize:"9px",fontWeight:800,color:f.details.level==="error"?"#ef4444":f.details.level==="warn"?"#f59e0b":"var(--dw-text-muted)",textTransform:"uppercase"},children:f.details.level}),f.details?.type==="network"&&v("span",{style:{fontSize:"9px",color:"var(--dw-text-muted)"},children:f.details.response?.status??0})]}),v("code",{style:{whiteSpace:"pre-wrap",wordBreak:"break-all",fontFamily:"var(--dw-font-mono)",fontSize:"11px",lineHeight:"1.4",color:"var(--dw-text)"},children:f.content})]},f.id)}function L(f){if(!f)return v("div",{style:{padding:"24px",borderRadius:"12px",border:"1px dashed var(--dw-border)",background:"rgba(255, 255, 255, 0.02)",textAlign:"center",color:"var(--dw-text-muted)",fontSize:"11px"},children:"Select an intercept to inspect full details."});let E=Z(f.ruleId),M=f.details;return x("div",{style:{display:"grid",gap:"14px"},children:[x("div",{style:{display:"grid",gap:"6px"},children:[v("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:"Rule"}),x("div",{style:{display:"grid",gap:"2px"},children:[v("code",{style:{fontSize:"11px"},children:E?.match??"unknown"}),x("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:[E?.type??"unknown"," \u2022 ",ot(f.timestamp)]})]})]}),M?M.type==="network"?O(M):C(M):v("span",{style:{color:"var(--dw-text-muted)"},children:"No details available"})]})}let _=u===null?t.matches[0]??null:t.matches.find(function(E){return E.id===u})??null;return x("div",{style:{display:"flex",flexDirection:"column",gap:"20px",animation:"dw-fade-in 0.3s ease-out"},children:[x("div",{"data-dw-section":"monitor-header",style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"12px",background:"var(--dw-bg-secondary)",borderRadius:"var(--dw-radius)",border:"1px solid var(--dw-border)",gap:"8px"},children:[x("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[v("button",{onClick:w,style:{padding:"6px 10px",borderRadius:"6px",background:t.isListening?"var(--dw-success)":"var(--dw-bg)",border:"1px solid var(--dw-border)",color:t.isListening?"#fff":"var(--dw-text)",cursor:"pointer",fontSize:"11px",fontWeight:600},"aria-label":t.isListening?"Stop monitoring":"Start monitoring",children:t.isListening?"Stop Recorder":"Start Recorder"}),x("div",{style:{display:"flex",flexDirection:"column"},children:[v("span",{style:{fontSize:"12px",fontWeight:600,color:"var(--dw-text)"},children:"Network Recorder"}),x("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)",display:"flex",alignItems:"center",gap:"4px"},children:[v("span",{style:{width:"6px",height:"6px",borderRadius:"50%",background:t.isListening?"#10b981":"#6b7280"}}),t.isListening?"Listening":"Idle"]})]})]}),v("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:x("div",{style:{textAlign:"right"},children:[v("div",{style:{fontSize:"10px",color:"var(--dw-text-muted)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Total Matches"}),v("div",{style:{fontSize:"18px",fontWeight:700,color:"var(--dw-accent)"},children:t.matches.length})]})})]}),x("div",{style:{display:"grid",gap:"8px",padding:"12px",borderRadius:"var(--dw-radius)",border:"1px solid var(--dw-border)",background:"var(--dw-bg-secondary)"},children:[v("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--dw-text-muted)"},children:"Browser Tools"}),x("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:[v("button",{onClick:bn,disabled:h,style:{padding:"6px 10px",borderRadius:"6px",border:"1px solid var(--dw-border)",background:"var(--dw-bg)",color:"var(--dw-text)",fontSize:"11px",cursor:"pointer"},children:"Refresh"}),v("button",{onClick:hn,disabled:h,style:{padding:"6px 10px",borderRadius:"6px",border:"1px solid var(--dw-border)",background:"var(--dw-bg)",color:"var(--dw-text)",fontSize:"11px",cursor:"pointer"},children:"Bust + Refresh"}),v("button",{onClick:ae,disabled:h,style:{padding:"6px 10px",borderRadius:"6px",border:"1px solid var(--dw-border)",background:"var(--dw-bg)",color:"var(--dw-text)",fontSize:"11px",cursor:"pointer"},children:"Clear Cache"}),v("button",{onClick:se,disabled:h,style:{padding:"6px 10px",borderRadius:"6px",border:"1px solid var(--dw-border)",background:"var(--dw-bg)",color:"var(--dw-text)",fontSize:"11px",cursor:"pointer"},children:"Clear Storage"}),v("button",{onClick:de,disabled:h,style:{padding:"6px 10px",borderRadius:"6px",border:"1px solid var(--dw-border)",background:"var(--dw-bg)",color:"var(--dw-text)",fontSize:"11px",cursor:"pointer"},children:"Clear All"}),v("button",{onClick:ue,disabled:h,style:{padding:"6px 10px",borderRadius:"6px",border:"1px solid var(--dw-border)",background:"var(--dw-bg)",color:"var(--dw-text)",fontSize:"11px",cursor:"pointer"},children:"Restart Next Dev"})]}),m&&v("span",{style:{fontSize:"10px",color:"var(--dw-text-muted)"},children:m})]}),x("div",{style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",background:"rgba(255, 255, 255, 0.03)",borderRadius:"var(--dw-radius)",border:d?"1px solid var(--dw-accent)":"1px solid var(--dw-border)",transition:"all 0.2s"},children:[v("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--dw-text-muted)"},children:"Create Watch Rule"}),x("div",{style:{display:"flex",gap:"8px"},children:[x("select",{value:i,onChange:F,style:{padding:"6px 8px",borderRadius:"6px",border:"1px solid var(--dw-border)",background:"var(--dw-bg)",color:"var(--dw-text)",fontSize:"11px",cursor:"pointer",outline:"none"},children:[v("option",{value:"console",children:"Console Log"}),v("option",{value:"network",children:"Network Req"})]}),v("input",{type:"text",value:n,onFocus:A,onBlur:T,onChange:$,placeholder:"Filter string or /regex/i",style:{flex:1,padding:"6px 10px",borderRadius:"6px",border:"1px solid var(--dw-border)",background:"var(--dw-bg)",color:"var(--dw-text)",fontSize:"11px",outline:"none"},onKeyDown:P}),v("button",{onClick:k,disabled:!n.trim(),style:{padding:"6px 12px",borderRadius:"6px",background:n.trim()?"var(--dw-accent)":"var(--dw-bg-tertiary)",color:"white",border:"none",cursor:"pointer",fontSize:"11px",fontWeight:600,transition:"all 0.2s",opacity:n.trim()?1:.5},children:"Track"})]})]}),R(),t.rules.length>0&&v("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:v("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px"},children:t.rules.map(function(E){return x("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"4px 8px",paddingRight:"4px",borderRadius:"8px",background:"var(--dw-bg-secondary)",border:"1px solid var(--dw-border)",fontSize:"11px",animation:"dw-scale-in 0.2s ease-out"},children:[v("span",{style:{padding:"2px 4px",borderRadius:"4px",fontSize:"9px",fontWeight:800,textTransform:"uppercase",background:E.type==="console"?"rgba(245, 158, 11, 0.15)":"rgba(59, 130, 246, 0.15)",color:E.type==="console"?"#f59e0b":"#3b82f6"},children:E.type==="console"?"LOG":"NET"}),v("span",{style:{fontFamily:"var(--dw-font-mono)",color:"var(--dw-text)"},children:E.match}),v("button",{onClick:function(){e.removeRule(E.id)},style:{width:"18px",height:"18px",borderRadius:"4px",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--dw-text-muted)",transition:"all 0.2s",fontSize:"14px"},onMouseEnter:M=>{M.currentTarget.style.background="rgba(239, 68, 68, 0.1)",M.currentTarget.style.color="#ef4444"},onMouseLeave:M=>{M.currentTarget.style.background="transparent",M.currentTarget.style.color="var(--dw-text-muted)"},children:"x"})]},E.id)})})}),x("div",{"data-dw-section":"monitor-main",style:{display:"grid",gridTemplateColumns:"1.2fr 1fr",gap:"16px"},children:[x("div",{"data-dw-section":"matches",style:{display:"flex",flexDirection:"column",gap:"12px"},children:[x("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline"},children:[v("h4",{style:{margin:0,fontSize:"12px",fontWeight:600,color:"var(--dw-text-muted)",textTransform:"uppercase"},children:"Intercepted Feed"}),t.matches.length>0&&v("button",{onClick:H,style:{border:"none",background:"transparent",fontSize:"10px",color:"var(--dw-text-muted)",cursor:"pointer",padding:"2px 4px",borderRadius:"4px",transition:"color 0.2s"},onMouseEnter:f=>f.currentTarget.style.color="var(--dw-accent)",onMouseLeave:f=>f.currentTarget.style.color="var(--dw-text-muted)",children:"Clear Feed"})]}),v("div",{style:{display:"flex",flexDirection:"column",gap:"8px",maxHeight:"350px",overflowY:"auto",paddingRight:"4px"},children:t.matches.length===0?x("div",{style:{padding:"40px 20px",textAlign:"center",background:"rgba(255, 255, 255, 0.02)",borderRadius:"var(--dw-radius)",border:"1px dashed var(--dw-border)"},children:[v("div",{style:{fontSize:"12px",color:"var(--dw-text)",fontWeight:600},children:"No Signals Captured"}),v("p",{style:{fontSize:"10px",color:"var(--dw-text-muted)",margin:"4px 0 0 0"},children:"Set up rules and start monitoring to see data here."})]}):t.matches.map(I)})]}),x("div",{"data-dw-section":"details",style:{display:"flex",flexDirection:"column",gap:"12px",padding:"12px",background:"var(--dw-bg-secondary)",border:"1px solid var(--dw-border)",borderRadius:"var(--dw-radius)",maxHeight:"350px",overflowY:"auto"},children:[v("h4",{style:{margin:0,fontSize:"12px",fontWeight:600,color:"var(--dw-text-muted)",textTransform:"uppercase"},children:"Details"}),L(_)]})]}),v("style",{children:`
3
+ @keyframes dw-fade-in {
4
+ from { opacity: 0; }
5
+ to { opacity: 1; }
6
+ }
7
+ @keyframes dw-slide-up {
8
+ from { opacity: 0; transform: translateY(10px); }
9
+ to { opacity: 1; transform: translateY(0); }
10
+ }
11
+ @keyframes dw-scale-in {
12
+ from { opacity: 0; transform: scale(0.95); }
13
+ to { opacity: 1; transform: scale(1); }
14
+ }
15
+ `})]})}import oe from"react";function ut(e){let t=Ee(e),{bus:r,registry:n}=t,o=qe(e.providers?.ai),i=Ae(r,e.providers?.auth),s=He(r,o),d=_e(r),c=rt();return n.registerDomain(i),n.registerDomain(s),n.registerDomain(d),n.registerDomain(c),n.registerCategory({id:"auth",label:"Auth",order:1},{render(){return oe.createElement(Ue,{domain:i})}}),n.registerCategory({id:"performance",label:"Perf",order:2},{render(){return oe.createElement(Je,{domain:s})}}),n.registerCategory({id:"routes",label:"Routes",order:3},{render(){return oe.createElement(Ye,{domain:d})}}),n.registerCategory({id:"monitor",label:"Monitor",order:4},{render(){return oe.createElement(dt,{domain:c})}}),t}import{useEffect as Un,useRef as Vn,useMemo as Xn}from"react";import{useState as Y,useCallback as Re,useEffect as ie,useMemo as Dt,useRef as At}from"react";import{createContext as Sn,useContext as kn,useState as Tn,useEffect as Pn,useMemo as En}from"react";var xn={bg:"#0a0a0b",bgSecondary:"#141416",border:"#2a2a2e",text:"#e4e4e7",textMuted:"#71717a",accent:"#3bb273",accentSoft:"rgba(59, 178, 115, 0.15)",danger:"#ef4444",warning:"#f59e0b",success:"#22c55e"},Rn={bg:"#fafafa",bgSecondary:"#f4f4f5",border:"#e4e4e7",text:"#18181b",textMuted:"#71717a",accent:"#16a34a",accentSoft:"rgba(22, 163, 74, 0.1)",danger:"#dc2626",warning:"#d97706",success:"#16a34a"};function lt(e,t){let r=e==="light"?Rn:xn;return t?{...r,accent:t,accentSoft:`color-mix(in srgb, ${t}, transparent 85%)`}:r}function ct(e){switch(e){case"none":return"0";case"sm":return"2px";case"md":return"4px";case"lg":return"6px"}}function pt(e){switch(e){case"compact":return{unit:4,gap:4,padding:8};case"comfortable":return{unit:6,gap:8,padding:12}}}function ft(e,t,r){let n=pt(r);return[`--dw-bg: ${e.bg}`,`--dw-bg-secondary: ${e.bgSecondary}`,`--dw-border: ${e.border}`,`--dw-text: ${e.text}`,`--dw-text-muted: ${e.textMuted}`,`--dw-accent: ${e.accent}`,`--dw-accent-soft: ${e.accentSoft}`,`--dw-danger: ${e.danger}`,`--dw-warning: ${e.warning}`,`--dw-success: ${e.success}`,`--dw-radius: ${ct(t)}`,`--dw-unit: ${n.unit}px`,`--dw-gap: ${n.gap}px`,`--dw-padding: ${n.padding}px`].join("; ")}function gt(e,t,r){let n=pt(r);return{"--dw-bg":e.bg,"--dw-bg-secondary":e.bgSecondary,"--dw-border":e.border,"--dw-text":e.text,"--dw-text-muted":e.textMuted,"--dw-accent":e.accent,"--dw-accent-soft":e.accentSoft,"--dw-danger":e.danger,"--dw-warning":e.warning,"--dw-success":e.success,"--dw-radius":ct(t),"--dw-unit":`${n.unit}px`,"--dw-gap":`${n.gap}px`,"--dw-padding":`${n.padding}px`}}import{jsx as Cn}from"react/jsx-runtime";var mt=Sn(null);function Mn(){let[e,t]=Tn(function(){return typeof window>"u"?!0:window.matchMedia("(prefers-color-scheme: dark)").matches});return Pn(function(){if(typeof window>"u")return;let n=window.matchMedia("(prefers-color-scheme: dark)");function o(i){t(i.matches)}return n.addEventListener("change",o),function(){n.removeEventListener("change",o)}},[]),e?"dark":"light"}function yt({mode:e,accent:t,density:r,radius:n,children:o}){let i=Mn(),s=e==="system"?i:e,d=En(function(){let u=lt(s,t),a=ft(u,n,r);return{mode:s,tokens:u,density:r,radius:n,cssVars:a}},[s,t,r,n]);return Cn(mt.Provider,{value:d,children:o})}function vt(){let e=kn(mt);if(!e)throw new Error("useTheme must be used within ThemeProvider");return e}import{jsx as he,jsxs as bt}from"react/jsx-runtime";function ht({title:e,onMinimize:t,onClose:r}){return bt("div",{"data-dw-header":!0,role:"banner",style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"var(--dw-padding)",borderBottom:"1px solid var(--dw-border)",background:"var(--dw-bg-secondary)",color:"var(--dw-text)",fontSize:"12px",fontFamily:"ui-monospace, monospace",userSelect:"none"},children:[he("span",{"data-dw-title":!0,style:{fontWeight:600},children:e??"DevWidget"}),bt("div",{"data-dw-actions":!0,style:{display:"flex",gap:"var(--dw-gap)"},children:[he("button",{type:"button",onClick:t,"aria-label":"Minimize widget",style:{background:"none",border:"none",color:"var(--dw-text-muted)",cursor:"pointer",padding:"2px 6px",fontSize:"12px",lineHeight:1},children:"\u2013"}),he("button",{type:"button",onClick:r,"aria-label":"Close widget",style:{background:"none",border:"none",color:"var(--dw-text-muted)",cursor:"pointer",padding:"2px 6px",fontSize:"12px",lineHeight:1},children:"\u2715"})]})]})}import{jsx as Dn,jsxs as we}from"react/jsx-runtime";function wt({toggleKey:e,diagnosticCount:t}){return we("div",{"data-dw-footer":!0,style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"var(--dw-padding)",borderTop:"1px solid var(--dw-border)",background:"var(--dw-bg-secondary)",color:"var(--dw-text-muted)",fontSize:"10px",fontFamily:"ui-monospace, monospace"},children:[we("span",{children:[Dn("kbd",{style:{padding:"1px 4px",border:"1px solid var(--dw-border)",borderRadius:"2px",fontSize:"10px",fontFamily:"ui-monospace, monospace",background:"var(--dw-bg)"},children:e})," ","toggle"]}),t!==void 0&&t>0&&we("span",{"data-dw-badge":"info",children:[t," diagnostic",t!==1?"s":""]})]})}import{jsx as An}from"react/jsx-runtime";function xt({id:e,active:t,children:r}){return An("div",{role:"tabpanel",id:`dw-panel-${e}`,"aria-labelledby":`dw-tab-${e}`,hidden:!t,tabIndex:t?0:-1,style:{padding:"var(--dw-padding)",overflow:"auto",flex:1,color:"var(--dw-text)",fontSize:"12px",fontFamily:"ui-monospace, monospace",display:t?"block":"none"},children:t&&r})}import{useState as Ln,useEffect as Fn,useCallback as Bn,useRef as On}from"react";import{forwardRef as In}from"react";import{jsx as zn}from"react/jsx-runtime";var Rt=In(function({children:t,variant:r="ghost",size:n="sm",active:o=!1,style:i,type:s="button",disabled:d,...c},u){let a={fontFamily:"ui-monospace, monospace",cursor:d?"not-allowed":"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",transition:"all 0.15s ease",whiteSpace:"nowrap",opacity:d?.5:1,...i},y={ghost:{color:o?"var(--dw-text)":"var(--dw-text-muted)",background:o?"var(--dw-bg-secondary)":"transparent"},solid:{background:"var(--dw-accent)",color:"#fff",borderRadius:"var(--dw-radius)"},outline:{border:`1px solid ${o?"var(--dw-accent)":"var(--dw-border)"}`,color:o?"var(--dw-accent)":"var(--dw-text)",borderRadius:"var(--dw-radius)"},tab:{background:o?"var(--dw-accent-soft)":"transparent",borderBottom:o?"2px solid var(--dw-accent)":"2px solid transparent",color:o?"var(--dw-text)":"var(--dw-text-muted)",borderRadius:"0"}},p={sm:{fontSize:"11px",padding:r==="tab"?"6px 12px":"4px 8px"},md:{fontSize:"12px",padding:"6px 12px"}};return zn("button",{ref:u,type:s,disabled:d,"aria-pressed":o,style:{...a,...y[r],...p[n],...i},...c,children:t})});import{jsx as St,jsxs as Nn}from"react/jsx-runtime";function kt({runtime:e}){let[,t]=Ln(0),r=On(null);Fn(function(){return e.subscribe(function(){t(function(u){return u+1})})},[e]);let n=e.getSorted(),o=e.getActive(),i=Bn(function(d){let c=n.findIndex(function(p){return p.category.id===o});if(c===-1)return;let u=c;switch(d.key){case"ArrowRight":u=(c+1)%n.length,d.preventDefault();break;case"ArrowLeft":u=(c-1+n.length)%n.length,d.preventDefault();break;case"Home":u=0,d.preventDefault();break;case"End":u=n.length-1,d.preventDefault();break;default:return}let a=n[u];a&&(e.setActive(a.category.id),r.current?.querySelector(`[data-dw-tab-id="${a.category.id}"]`)?.focus())},[n,o,e]);return St("div",{ref:r,role:"tablist","aria-label":"Widget tabs",onKeyDown:i,style:{display:"flex",borderBottom:"1px solid var(--dw-border)",background:"var(--dw-bg)",overflowX:"auto",scrollbarWidth:"none"},children:n.map(function(d){let c=d.category.id===o;return Nn(Rt,{variant:"tab",role:"tab",id:`dw-tab-${d.category.id}`,"aria-controls":`dw-panel-${d.category.id}`,"aria-selected":c,tabIndex:c?0:-1,"data-dw-tab-id":d.category.id,active:c,onClick:function(){e.setActive(d.category.id)},style:{position:"relative"},children:[d.category.label,(d.category.badgeCount??0)>0&&St("span",{style:{marginLeft:"4px",padding:"0 4px",fontSize:"9px",borderRadius:"8px",background:"var(--dw-accent)",color:"#fff",lineHeight:"14px",display:"inline-block",minWidth:"14px",textAlign:"center"},children:d.category.badgeCount})]},d.category.id)})})}import{useState as Wn,useCallback as Tt}from"react";import{jsx as xe,jsxs as Pt}from"react/jsx-runtime";function Et({panels:e,defaultPanel:t,collapsible:r,children:n}){let[o,i]=Wn(t??null),s=Tt(function(a){i(function(p){return p===a&&(r??!0)?null:a})},[r]),d=Tt(function(a){let y=e.filter(function(l){return l.enabled??!0}),p=y.findIndex(function(l){return l.id===o}),g=p;switch(a.key){case"ArrowDown":g=(p+1)%y.length,a.preventDefault();break;case"ArrowUp":g=(p-1+y.length)%y.length,a.preventDefault();break;case"Enter":case" ":if(p>=0){let h=y[p];h&&s(h.id)}a.preventDefault();return;default:return}let b=y[g];b&&s(b.id)},[e,o,s]),c=e.filter(function(a){return a.enabled??!0}).sort(function(a,y){return(a.order??999)-(y.order??999)});return Pt("div",{"data-dw-right-rail":!0,style:{display:"flex",flexDirection:"row",borderLeft:"1px solid var(--dw-border)",height:"100%"},children:[o&&n&&xe("div",{"data-dw-rail-panel":!0,role:"complementary","aria-label":c.find(function(a){return a.id===o})?.label??"Panel",style:{width:"280px",overflow:"auto",padding:"var(--dw-padding)",borderRight:"1px solid var(--dw-border)",background:"var(--dw-bg)",color:"var(--dw-text)",fontSize:"12px",fontFamily:"ui-monospace, monospace"},children:n(o)}),xe("nav",{"data-dw-rail-icons":!0,role:"toolbar","aria-label":"Side panels",onKeyDown:d,style:{display:"flex",flexDirection:"column",width:"40px",background:"var(--dw-bg-secondary)",padding:"4px 0",gap:"2px",alignItems:"center"},children:c.map(function(a){let y=a.id===o;return Pt("button",{type:"button","aria-label":a.label,"aria-pressed":y,onClick:function(){s(a.id)},style:{width:"32px",height:"32px",display:"flex",alignItems:"center",justifyContent:"center",background:y?"var(--dw-accent-soft)":"transparent",border:"none",borderRadius:"var(--dw-radius)",color:y?"var(--dw-accent)":"var(--dw-text-muted)",cursor:"pointer",fontSize:"14px",position:"relative"},children:[a.icon,(a.badgeCount??0)>0&&xe("span",{style:{position:"absolute",top:"2px",right:"2px",width:"8px",height:"8px",borderRadius:"50%",background:"var(--dw-accent)",fontSize:"0"},children:a.badgeCount})]},a.id)})})]})}import{useEffect as $n,useCallback as Hn}from"react";function Mt(e){let{toggleKey:t,enableShortcuts:r,onToggle:n,onEscape:o}=e,i=Hn(function(d){if(!r||d.repeat||d.target instanceof HTMLInputElement||d.target instanceof HTMLTextAreaElement||d.target instanceof HTMLElement&&d.target.isContentEditable)return;if(d.key==="Escape"){d.preventDefault(),o?o():n();return}(d.key===t||t==="`"&&d.code==="Backquote")&&!d.ctrlKey&&!d.metaKey&&!d.altKey&&(d.preventDefault(),n())},[t,r,n,o]);$n(function(){return window.addEventListener("keydown",i,!0),function(){window.removeEventListener("keydown",i,!0)}},[i])}function Ct(){let e=new Map,t=null,r=new Set;function n(){for(let p of r)p()}function o(p,g){e.set(p.id,{category:p,presenter:g}),!t&&(p.enabled??!0)&&(t=p.id),n()}function i(p){e.delete(p),t===p&&(t=c()[0]?.category.id??null),n()}function s(p){e.has(p)&&(t=p,n())}function d(){return t}function c(){return Array.from(e.values()).filter(function(g){return g.category.enabled??!0}).sort(function(g,b){let h=g.category.order??999,l=b.category.order??999;return h!==l?h-l:g.category.label.localeCompare(b.category.label)})}function u(p){return e.get(p)?.presenter??null}function a(p){return r.add(p),function(){r.delete(p)}}function y(p,g){let b=e.get(p);b&&(b.category={...b.category,badgeCount:g},n())}return{register:o,unregister:i,setActive:s,getActive:d,getSorted:c,getPresenter:u,subscribe:a,updateBadge:y}}import{Fragment as qn,jsx as W,jsxs as Q}from"react/jsx-runtime";function It(e){return e==="always"?!0:e==="never"||typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches}function Kn({message:e}){return W("div",{role:"status","aria-live":"polite","aria-atomic":"true",style:{position:"absolute",width:"1px",height:"1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap"},children:e})}function _n({runtime:e}){let{config:t}=e,{tokens:r,density:n,radius:o}=vt(),[i,s]=Y(!0),[d,c]=Y(!1),[u,a]=Y(""),[y,p]=Y(function(){return It(t.accessibility.reducedMotion)}),[,g]=Y(0),b=At(0),h=At(null),l=Dt(function(){return Ct()},[]);ie(function(){if(t.accessibility.reducedMotion!=="system"){p(It(t.accessibility.reducedMotion));return}if(typeof window>"u"||typeof window.matchMedia!="function"){p(!1);return}let T=window.matchMedia("(prefers-reduced-motion: reduce)");p(T.matches);function P(H){p(H.matches)}return T.addEventListener("change",P),function(){T.removeEventListener("change",P)}},[t.accessibility.reducedMotion]),ie(function(){let T=e.registry.getCategories();for(let P of T)l.register(P.category,P.presenter)},[e,l]),ie(function(){return l.subscribe(function(){g(function(H){return H+1})})},[l]),ie(function(){if(!t.accessibility.announceUpdates)return;let T=e.bus.subscribe("performance/drop-detected",function(){b.current+=1,h.current&&clearTimeout(h.current),h.current=setTimeout(function(){let V=b.current;a(`${V} performance drop${V===1?"":"s"} detected in the last few seconds`),b.current=0,h.current=null},2e3)});return function(){T(),h.current&&(clearTimeout(h.current),h.current=null),b.current=0}},[e,t.accessibility.announceUpdates]);let m=Re(function(){s(function(P){return!P})},[]),S=Re(function(){c(function(P){return!P})},[]),k=Re(function(){s(!1)},[]);Mt({toggleKey:t.keyboard.toggleKey,enableShortcuts:t.keyboard.enableShortcuts,onToggle:m,onEscape:m,reducedMotion:t.accessibility.reducedMotion});let w=Dt(function(){return gt(r,o,n)},[r,o,n]);if(!i)return null;let F=l.getSorted(),$=l.getActive();return Q("div",{"data-dw-shell":!0,role:"region","aria-label":"Development Widget",style:{display:"flex",flexDirection:"column",background:"var(--dw-bg)",border:"1px solid var(--dw-border)",borderBottom:"none",borderTopLeftRadius:"var(--dw-radius)",borderTopRightRadius:"var(--dw-radius)",boxShadow:"0 -4px 32px rgba(0, 0, 0, 0.2)",overflow:"hidden",zIndex:99999,fontFamily:"ui-monospace, monospace",fontSize:"12px",color:"var(--dw-text)",position:"fixed",bottom:0,left:0,right:0,height:d?"auto":"400px",maxHeight:"100vh",transition:y?"none":"height 0.2s ease-in-out",...w},children:[W("style",{children:"[data-dw-shell] button:focus-visible,[data-dw-shell] [role='tab']:focus-visible{outline:2px solid var(--dw-accent);outline-offset:-2px;}[data-dw-shell] *:focus:not(:focus-visible){outline:none;}@media (prefers-reduced-motion: reduce){[data-dw-shell] *{transition:none !important;animation:none !important;}}"}),W(ht,{onMinimize:S,onClose:k}),!d&&Q(qn,{children:[Q("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[Q("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},children:[W(kt,{runtime:l}),W("div",{style:{flex:1,overflow:"auto"},children:F.map(function(T){let P=T.category.id===$;return W(xt,{id:T.category.id,active:P,children:T.presenter.render(e.registry.getDomain(T.category.id)?.getState()??null)},T.category.id)})})]}),t.rightRail.enabled&&t.rightRail.panels.length>0&&W(Et,{panels:t.rightRail.panels,defaultPanel:t.rightRail.defaultPanel,collapsible:t.rightRail.collapsible,children:function(T){let P=e.registry.getDomain(T);if(!P)return Q("span",{children:["No content for ",T]});let H=P.serializeDiagnostics?.();return H?W("pre",{style:{margin:0,whiteSpace:"pre-wrap",fontSize:"11px"},children:JSON.stringify(H,null,2)}):W("span",{children:"No diagnostics"})}})]}),W(wt,{toggleKey:t.keyboard.toggleKey})]}),W(Kn,{message:u})]})}function zt({runtime:e}){let{config:t}=e;return W(yt,{mode:t.theme.mode,accent:t.theme.accent,density:t.theme.density,radius:t.theme.radius,children:W(_n,{runtime:e})})}import{jsx as Gn}from"react/jsx-runtime";function jn(){return typeof process<"u"&&process.env?process.env.NODE_ENV==="development":!0}function Uo(e={}){let{enabled:t=!0,mode:r="development-only"}=e,n=t&&(r==="always"||jn()),o=Xn(function(){return n?ut(e):null},[n]),i=Vn(!1);return Un(function(){if(!(!o||i.current))return i.current=!0,o.start(),function(){o.stop(),i.current=!1}},[o]),!n||!o?null:Gn(zt,{runtime:o})}export{ne as a,Se as b,J as c,ke as d,Te as e,B as f,Pe as g,Ee as h,ut as i,Uo as j};
16
+ //# sourceMappingURL=chunk-6OCSDLNS.mjs.map