@farm.js/devtools 0.1.61 → 0.1.62

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/dist/hmr.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ interface HotContext {
2
+ on(event: string, listener: () => void): void;
3
+ off(event: string, listener: () => void): void;
4
+ dispose?(listener: () => void): void;
5
+ }
6
+ /** Reuse the app's Vite connection. No polling, second socket, or source payloads. */
7
+ export declare function startDevtoolsUpdates(runtimeWindow?: Window, hot?: HotContext | undefined): {
8
+ dispose(): void;
9
+ };
10
+ export {};
package/dist/hmr.js ADDED
@@ -0,0 +1,24 @@
1
+ /** Reuse the app's Vite connection. No polling, second socket, or source payloads. */
2
+ export function startDevtoolsUpdates(runtimeWindow = window, hot = import.meta.hot) {
3
+ const send = (state) => {
4
+ runtimeWindow.document
5
+ .querySelector("#__farm_devtools_overlay__ > iframe")
6
+ ?.contentWindow?.postMessage({ type: "farm:devtools:hmr", state }, runtimeWindow.location.origin);
7
+ };
8
+ const listeners = [
9
+ ["vite:beforeUpdate", () => send("pending")],
10
+ ["vite:afterUpdate", () => send("ready")],
11
+ ["vite:beforeFullReload", () => send("pending")],
12
+ ["vite:error", () => send("error")],
13
+ ["vite:ws:disconnect", () => send("disconnected")],
14
+ ["vite:ws:connect", () => send("ready")],
15
+ ];
16
+ for (const [event, listener] of listeners)
17
+ hot?.on(event, listener);
18
+ const dispose = () => {
19
+ for (const [event, listener] of listeners)
20
+ hot?.off(event, listener);
21
+ };
22
+ hot?.dispose?.(dispose);
23
+ return { dispose };
24
+ }
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
- import { resolveFarmDevtoolsConfig } from "@farm.js/core";
2
- import { definePlugin } from "@farm.js/core/plugin";
1
+ import { definePlugin, resolveFarmDevtoolsConfig } from "@farm.js/core/plugin";
3
2
  /** Add the development-only workspace inspector. No production runtime is registered. */
4
3
  export function devtools(options = {}) {
5
4
  for (const name of ["launcher", "inspect"]) {
@@ -51,16 +50,49 @@ export function devtools(options = {}) {
51
50
  return {
52
51
  ...config,
53
52
  devtools: devtoolsConfig,
54
- vite: { ...config.vite, plugins: [vitePlugin, ...(config.vite?.plugins ?? [])] },
53
+ vite: {
54
+ ...config.vite,
55
+ plugins: [vitePlugin, ...(config.vite?.plugins ?? [])],
56
+ ...(inspect
57
+ ? {
58
+ optimizeDeps: {
59
+ ...config.vite?.optimizeDeps,
60
+ // This tiny module must retain import.meta.hot instead of being prebundled.
61
+ exclude: [
62
+ ...new Set([
63
+ ...(config.vite?.optimizeDeps?.exclude ?? []),
64
+ "@farm.js/devtools/internal/hmr",
65
+ ]),
66
+ ],
67
+ },
68
+ }
69
+ : {}),
70
+ },
55
71
  };
56
72
  },
57
73
  client: {
58
- public: { launcher },
74
+ public: { launcher, inspect },
59
75
  async setup({ isDev, public: config }) {
60
- if (!isDev || !config.launcher)
76
+ if (!isDev || (!config.launcher && !config.inspect))
61
77
  return;
62
- const { startDevtoolsLauncher } = await import("@farm.js/devtools/client");
63
- return startDevtoolsLauncher();
78
+ const updates = config.inspect
79
+ ? (await import("@farm.js/devtools/internal/hmr")).startDevtoolsUpdates()
80
+ : undefined;
81
+ try {
82
+ const launcher = config.launcher
83
+ ? (await import("@farm.js/devtools/client")).startDevtoolsLauncher()
84
+ : undefined;
85
+ return {
86
+ dispose() {
87
+ launcher?.dispose();
88
+ updates?.dispose();
89
+ },
90
+ };
91
+ }
92
+ catch (error) {
93
+ updates?.dispose();
94
+ throw error;
95
+ }
64
96
  },
65
97
  close({ state }) {
66
98
  state?.dispose();
package/dist/server.js CHANGED
@@ -2,8 +2,14 @@ import { readdir, readFile } from "node:fs/promises";
2
2
  import { isIP } from "node:net";
3
3
  import { createModuleInspector, ModuleInspectionError } from "./modules.js";
4
4
  import { DEVTOOLS_PATH } from "./types.js";
5
+ /** Set by the `farm preview` relay and gateway client on every tunnelled request. */
6
+ const FARM_PREVIEW_REQUEST_HEADER = "x-farm-preview";
5
7
  /** Guard our early middleware, before Vite's own host/CORS middleware runs. */
6
8
  export function isTrustedRequest(req, server) {
9
+ // `farm preview` tunnels public visitors in with a localhost Host and marks them; DevTools
10
+ // describes the developer's machine and is never served on a public preview URL.
11
+ if (req.headers[FARM_PREVIEW_REQUEST_HEADER] !== undefined)
12
+ return false;
7
13
  try {
8
14
  const authority = req.headers.host ?? "";
9
15
  if (!authority || /[\s/@\\?#]/.test(authority))
package/dist/ui/panel.js CHANGED
@@ -1,10 +1,10 @@
1
- var Y="/__farm/devtools";var ce=new Set(["<",">","{","}","[","]"]),Se=new Set(["for","do","while","if","else","return","function","var","let","const","true","false","undefined","this","new","delete","typeof","in","instanceof","void","break","continue","switch","case","default","throw","try","catch","finally","debugger","with","yield","async","await","class","extends","super","import","export","from","static"]),ye=new Set(["+","-","*","/","%","=","!","&","|","^","~","!","?",":",".",",",";","'",'"',".","(",")","[","]","#","@","\\",...ce]),Ce={keywords:Se,onCommentStart:Ue,onCommentEnd:Re},se=["identifier","keyword","string","class","property","entity","jsxliterals","sign","comment","break","space"],[le,Le,G,Ae,fe,Fe,De,q,be,pe,xe]=se.map((t,a)=>a);function ae(t){return/^[^\S\r\n]+$/g.test(t)}function je(t){return ye.has(t)}function He(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function ne(t){return/^[\w_]+$/.test(t)||we(t)}function _e(t){let a=t[0];return ne(a)&&a===a.toUpperCase()||t==="null"}function we(t){return/[^\u0000-\u007f]/.test(t)}function ke(t){return/^[a-zA-Z]$/.test(t)}function $e(t){return ke(t)||we(t)}function re(t){return $e(t[0])&&(t.length===1||ne(t.slice(1)))}function me(t){return t==="`"}function ue(t){return t==='"'||t==="'"}function Be(t){return ue(t)||me(t)}function Ue(t,a){let l=t+a;return l==="/*"?2:l==="//"?1:0}function Re(t,a){return t+a==="*/"?2:a===`
2
- `?1:0}function Ne(t){return t[0]==="/"&&!Ue(t[0],t[1])}function Ie(t,a){let{keywords:l,onCommentStart:x,onCommentEnd:p}={...Ce,...a},s="",c=-1,h=[-1,""],E=[-2,""],T=[],w=!1,d=0,U=!1,D=0,I=()=>w&&!U&&!d,B=()=>d&&!I(),j=()=>!d&&I()&&!U&&D>0,M=null,z=!1,P=0,H=0,v=()=>M!==null,Q=()=>z,A=()=>H>P,W=()=>H>0&&H===P,g=()=>v()||A();function S(i){let r=i===`
3
- `;if(B()){if(v())return G;let[,y]=h;if(re(i)&&(y==="<"||y==="</"))return Fe}if(j())return De;if(v()||A())return G;if(l.has(i))return h[1]==="."?le:Le;if(r)return pe;if(ae(i))return xe;if(i.split("").every(je))return q;if(_e(i))return B()?le:Ae;if(re(i)){let y=h[1]==="."&&re(E[1]);if(!g()&&!y)return le;if(y)return fe}return G}let n=(i,r)=>{if(r&&(s=r),s){c=i||S(s);let F=[c,s];c!==xe&&c!==pe&&(E=h,h=F),T.push(F)}s=""};for(let i=0;i<t.length;i++){let r=t[i],F=t[i-1],y=t[i+1],J=F+r,C=r+y;if(ue(r)&&!j()&&!A()){n(),F!=="\\"&&(M&&r===M?M=null:M||(M=r)),n(G,r);continue}if(!A()&&F!=="\\n"&&me(r)){n(),n(G,r),H++;continue}if(A()){if(F!=="\\n"&&me(r)&&H>0){n(),H--,n(G,r);continue}if(C==="${"){P++,n(G),n(q,C),i++;continue}}if(W()&&r==="}"){n(),P--,n(q,r);continue}if(I()&&r==="{"){n(),n(q,r),U=!0;continue}if(w){if(!d&&r==="<"){n(),y==="/"?(d=2,s=C,i++):(d=1,s=r),n(q);continue}if(d){if(r===">"&&!"/=".includes(F)){n(),d===1?(d=0,D++):(d=0,w=!1),n(q,r);continue}if(C==="/>"||C==="</"){s!=="<"&&s!=="/"&&n(),C==="/>"?d=0:D--,D||(w=!1),s=C,i++,n(q);continue}if(r==="<"){n(),s=r,n(q);continue}if(y==="-"&&!g()&&!j()&&s){n(fe,s+r+y),i++;continue}if(y==="="&&!g()&&!ae(r)){ae(s)&&n();let R=s+r;if(re(R)){n(fe,R);continue}}}}!d&&(r==="<"&&$e(y)||C==="</")&&(d=y==="/"?2:1,r==="<"&&(y==="/"||ke(y))&&!g()&&!j()&&!Q()&&(w=!0));let X=Be(r),de=A(),Z=!w&&Ne(C),ee=j();if(X||de||ue(M))s+=r;else if(Z){n();let[R,K]=h;if(Z&&R!==-1&&!(R===q&&K!==")"||R===be)){s=r,n();continue}z=!0;let V=i++,te=()=>i>=t.length,e=()=>te()||t[i]===`
4
- `,o=!1;for(;!e();i++)if(t[i]==="/"&&t[i-1]!=="\\"){for(o=!0;V!==i&&/^[a-z]$/.test(t[i+1])&&!e();)i++;break}z=!1,V!==i&&o?(s=t.slice(V,i+1),n(G)):(s=r,n(),i=V)}else if(x(r,y)){n();let R=i,K=x(r,y);if(K)for(;i<t.length&&p(t[i-1],t[i])!=K;i++);s=t.slice(R,i+1),n(be)}else r===" "||r===`
5
- `?r===" "&&(ae(s)||!s||ee)?(s+=r,y==="<"&&n()):(n(),s=r,n()):U&&r==="}"?(n(),s=r,n(),U=!1):ee&&!ce.has(r)||A()||(ne(r)===ne(s[s.length-1])||I())&&!ye.has(r)?s+=r:(J==="</"&&(s=J),n(),J!=="</"&&(s=r),C==="</"||C==="/>"?(s=C,n(),i++):ce.has(r)&&n())}return n(),T}function qe(t){let a=[],l=c=>({type:"element",tagName:"span",children:c,properties:{className:"sh__line"}});function x(c){let h=c.map(([E,T])=>{let w=se[E];return{type:"element",tagName:"span",children:[{type:"text",value:T}],properties:{className:`sh__token--${w}`,style:{color:`var(--sh-${w})`}}}});a.push(l(h))}let p=[],s=!1;for(let c=0;c<t.length;c++){let h=t[c],[E,T]=h,w=c===t.length-1;if(E!==pe){if(T.includes(`
6
- `)){let d=T.split(`
7
- `);for(let U=0;U<d.length;U++)p.push([E,d[U]]),U<d.length-1&&(x(p),p.length=0)}else p.push(h);s=!1}else s?x([]):(x(p),p.length=0),w&&x([]),s=!0}return p.length&&x(p),a}var Pe=t=>{let a=`class="${t.className}"`;if(t.style){let l=Object.entries(t.style).map(([x,p])=>`${x}:${p}`).join(";");a+=` style="${l}"`}return a};function Ve(t){return t.map(a=>{let{tagName:l}=a,x=a.children.map(p=>{let{tagName:s,children:c,properties:h}=p;return`<${s} ${Pe(h)}>${He(c[0].value)}</${s}>`}).join("");return`<${l} class="${a.properties.className}">${x}</${l}>`}).join(`
8
- `)}function Me(t,a){let l=Ie(t,a),x=qe(l);return Ve(x)}var Ze={TokenTypes:se,TokenMap:new Map(se.map((t,a)=>[t,a]))};var Ge={activity:'<path d="M22 12h-4l-3 9L9 3l-3 9H2"/>',api:'<path d="M8 3H7a2 2 0 0 0-2 2v4a2 2 0 0 1-2 2 2 2 0 0 1 2 2v4a2 2 0 0 0 2 2h1"/><path d="M16 3h1a2 2 0 0 1 2 2v4a2 2 0 0 0 2 2 2 2 0 0 0-2 2v4a2 2 0 0 1-2 2h-1"/>',app:'<path d="M15 3h6v6"/><path d="M10 14 21 3"/><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>',blocks:'<rect width="7" height="7" x="3" y="3"/><rect width="7" height="7" x="14" y="3"/><rect width="7" height="7" x="14" y="14"/><rect width="7" height="7" x="3" y="14"/>',book:'<path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/><path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/>',clock:'<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>',chevron:'<path d="m9 18 6-6-6-6"/>',close:'<path d="M18 6 6 18M6 6l12 12"/>',copy:'<rect width="14" height="14" x="8" y="8"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/>',database:'<ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M3 5v14c0 1.7 4 3 9 3s9-1.3 9-3V5"/><path d="M3 12c0 1.7 4 3 9 3s9-1.3 9-3"/>',external:'<path d="M15 3h6v6"/><path d="M10 14 21 3"/><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>',layers:'<path d="m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z"/><path d="m22 12.5-9.17 4.17a2 2 0 0 1-1.66 0L2 12.5"/><path d="m22 17.5-9.17 4.17a2 2 0 0 1-1.66 0L2 17.5"/>',overview:'<rect width="7" height="9" x="3" y="3"/><rect width="7" height="5" x="14" y="3"/><rect width="7" height="9" x="14" y="12"/><rect width="7" height="5" x="3" y="16"/>',refresh:'<path d="M20 11a8.1 8.1 0 0 0-15.5-2M4 4v5h5"/><path d="M4 13a8.1 8.1 0 0 0 15.5 2M20 20v-5h-5"/>',route:'<circle cx="6" cy="19" r="3"/><path d="M9 19h5.5a3.5 3.5 0 0 0 0-7h-5a3.5 3.5 0 0 1 0-7H18"/><circle cx="18" cy="5" r="3"/>',runtime:'<rect width="20" height="14" x="2" y="3"/><line x1="8" x2="16" y1="21" y2="21"/><line x1="12" x2="12" y1="17" y2="21"/>',search:'<circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>',sun:'<circle cx="12" cy="12" r="4"/><path d="M12 2v2m0 16v2M2 12h2m16 0h2M4.93 4.93l1.42 1.42m11.3 11.3 1.42 1.42M4.93 19.07l1.42-1.42m11.3-11.3 1.42-1.42"/>',moon:'<path d="M20.9 13A9 9 0 0 1 11 3.1 9 9 0 1 0 20.9 13Z"/>',shield:'<path d="M20 13c0 5-3.5 7.5-8 9-4.5-1.5-8-4-8-9V5l8-3 8 3z"/><path d="m9 12 2 2 4-4"/>',terminal:'<polyline points="4 17 10 11 4 5"/><line x1="12" x2="20" y1="19" y2="19"/>'};function $(t,a=""){return`<svg class="icon ${a}" data-lucide="${t}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${Ge[t]}</svg>`}function u(t){return String(t??"").replace(/[&<>"']/g,a=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[a])}function ie(t,a,l){let x=t.split(`
9
- `),p=x.slice(0,1500).join(`
10
- `);return`<section class="fd-code-pane" aria-label="${u(a)}"><div class="fd-code-title"><span class="fd-label">${u(a)}</span><button type="button" class="fd-link-button" data-copy="${u(l)}" aria-label="Copy ${u(a)}">${$("copy")}<span class="fd-button-label">Copy</span></button></div><pre class="fd-source"><code>${Me(p)}</code></pre>${x.length>1500?'<p class="fd-subtitle">Showing the first 1,500 lines. Copy includes the full bounded source.</p>':""}</section>`}function Te(t,a){let l=t.toLowerCase().split("+").map(d=>d.trim()).filter(Boolean),x=["alt","ctrl","control","meta","cmd","command","mod","shift"],p=l.find(d=>!x.includes(d));if(!p)return()=>!1;let s=l.includes("mod"),c=l.includes("alt"),h=l.includes("shift"),E=l.includes("ctrl")||l.includes("control")||s&&!a,T=l.includes("meta")||l.includes("cmd")||l.includes("command")||s&&a,w=p==="."||p==="period"?"Period":p===","||p==="comma"?"Comma":p==="/"||p==="slash"?"Slash":void 0;return d=>!d.repeat&&d.altKey===c&&d.ctrlKey===E&&d.metaKey===T&&d.shiftKey===h&&(w?d.code===w:String(d.key||"").toLowerCase()===p)}function k(t,a){return`<div class="fd-property"><dt>${u(t)}</dt><dd>${u(a)}</dd></div>`}function O(t,a,l=""){return`<div class="fd-page-heading"><div><h2>${u(t)}</h2><p class="fd-subtitle">${u(a)}</p></div>${l?`<span class="fd-tag">${u(l)}</span>`:""}</div>`}function Oe(t){let a=t.ownerDocument.defaultView,l=t.ownerDocument,x=Te(t.dataset.shortcut??"",/Mac|iPhone|iPad|iPod/.test(a.navigator.platform)),p=[["overview","Overview","overview"],["routes","Routes","route"],["api","API","api"],["systems","Systems","layers"],["runtime","Runtime","runtime"],...t.dataset.inspect==="true"?[["inspect","Inspect","search"]]:[],["diagnostics","Diagnostics","activity"],["raw","Snapshot","terminal"]],s=p.some(([e])=>e===a.location.hash.slice(1))?a.location.hash.slice(1):"overview",c,h=0,E=0,T="",w=[],d=0,U=0,D=!1,I,B,j=new Map,M="system";try{let e=a.localStorage.getItem("farm:devtools:theme");(e==="light"||e==="dark")&&(M=e)}catch{}let z=a.matchMedia("(prefers-color-scheme: dark)"),P=()=>M==="dark"||M==="system"&&z.matches,H=()=>{t.dataset.theme=M,t.style.colorScheme=M==="light"||M==="dark"?M:"light dark";let e=t.querySelector("[data-theme-toggle]");if(e){let o=P()?"Switch to light theme":"Switch to dark theme";e.innerHTML=$(P()?"sun":"moon"),e.setAttribute("aria-label",o),e.title=o}};H(),t.innerHTML=`<header class="fd-header"><img class="fd-logo" src="${Y}/assets/logo.svg" alt="Farm.js logo"><span class="fd-brand">FARM.JS</span><span class="fd-muted">/</span><span>DevTools</span><div class="fd-header-actions"><button type="button" class="fd-icon-button" data-refresh aria-label="Refresh DevTools">${$("refresh")}</button><button type="button" class="fd-icon-button" data-theme-toggle aria-label="Switch theme"></button><button type="button" class="fd-icon-button" data-close aria-label="Close DevTools">${$("close")}</button></div></header><div class="fd-error" role="alert" data-error hidden></div><div class="fd-body"><nav class="fd-sidebar" aria-label="DevTools navigation"><div class="fd-label fd-group-label">WORKSPACE</div>${p.map(([e,o,f])=>`<button type="button" class="fd-nav-button" data-view="${e}">${$(f)}<span class="fd-button-label">${o}</span><span class="fd-count" data-count="${e}"></span></button>`).join("")}</nav><main class="fd-main" data-main></main></div><footer class="fd-footer"><span class="fd-footer-label">Development only</span><div class="fd-footer-status"><span data-status role="status">Loading workspace\u2026</span><span data-feedback role="status"></span></div><span class="fd-footer-label">Esc to close</span></footer>`;let v=t.querySelector("[data-main]"),Q=t.querySelector("[data-status]"),A=t.querySelector("[data-feedback]"),W=t.querySelector("[data-error]"),g=e=>`<div class="fd-empty">${u(e)}</div>`,S=e=>`<code>${u(e)}</code>`,n=e=>e?`${e.runtime}${e.regions?.length?" \xB7 "+e.regions.join(", "):""}${e.maxDuration?" \xB7 "+e.maxDuration+"s":""}`:"Inherited",i=()=>{a.parent!==a?a.parent.postMessage({type:"farm:devtools:close"},a.location.origin):a.location.assign("/")};function r(e){p.some(([o])=>o===e)&&(s=e,a.history.replaceState(null,"",`#${s}`),K())}async function F(e,o){let f=await a.fetch(e,{cache:"no-store",credentials:"same-origin",signal:o});if(!f.ok){let m=await f.json().catch(()=>null);throw new Error(typeof m?.error=="string"?m.error:`DevTools request failed (${f.status}).`)}return f.json()}async function y(){let e=++d;I?.abort(),I=new AbortController,t.setAttribute("aria-busy","true"),Q.textContent="Refreshing workspace\u2026",W.hidden=!0,c||(v.innerHTML=g("Loading the current Farm workspace\u2026"));try{let o=await F(`${Y}.json`,I.signal);if(D||e!==d)return;if(!o.project||!o.counts||!Array.isArray(o.routes))throw new Error("Unexpected DevTools snapshot. Check that core and the plugin are up to date.");c=o,h=Math.min(h,Math.max(0,o.routes.length-1)),E=Math.min(E,Math.max(0,o.apiRoutes.length-1)),Q.textContent=`${o.project.name} \xB7 Updated ${new Date(o.generatedAt).toLocaleTimeString()}`,K()}catch(o){if(D||e!==d)return;W.textContent=o.message,W.hidden=!1,Q.textContent=c?"Showing the last snapshot":"Workspace unavailable",c||(v.innerHTML=g("Use Refresh to reconnect to the development server."))}finally{e===d&&t.removeAttribute("aria-busy")}}function J(){return c.diagnostics.map(e=>`<article class="fd-diagnostic" data-severity="${u(e.severity)}"><span class="${e.severity==="error"?"fd-danger":"fd-amber"}">${$("activity")}</span><div><div class="fd-diagnostic-head"><h3>${u(e.title)}</h3><span class="fd-tag" data-tone="${e.severity==="error"?"bad":e.severity==="warning"?"warn":"info"}">${u(e.severity)}</span></div><div class="fd-label">${u(e.code)}</div><p>${u(e.message)}</p>${e.action?`<p class="fd-diagnostic-action">${u(e.action)}</p>`:""}</div></article>`).join("")||`<div class="fd-diagnostic" data-severity="ok"><span class="fd-green">${$("shield")}</span><div><h3>Framework checks passed</h3><p>No runtime configuration diagnostics in this snapshot.</p></div></div>`}function C(){let e=c;v.innerHTML=O("Overview",`${e.project.name} \xB7 ${e.project.srcDir}`,"Development")+`<div class="fd-stats">${[["Pages",e.counts.pages,"route"],["API routes",e.counts.apiRoutes,"api"],["Integrations",e.counts.integrations,"blocks"]].map(([o,f,m])=>`<div class="fd-stat"><span class="fd-label">${$(m)}${o}</span><span class="fd-stat-value">${f}</span></div>`).join("")}</div><section class="fd-section"><div class="fd-section-heading"><h3>Application routes</h3><button type="button" class="fd-link-button" data-go="routes"><span class="fd-button-label">View all routes</span>${$("external")}</button></div><div class="fd-route-preview">${e.routes.map((o,f)=>({route:o,index:f})).filter(({route:o})=>o.kind==="page").slice(0,5).map(({route:o,index:f})=>`<button type="button" class="fd-preview-row" data-route="${f}">${S(o.pattern)}<span class="fd-preview-meta">${u(n(o.runtime))}</span>${$("chevron")}</button>`).join("")||g("No page routes discovered.")}</div></section><section class="fd-section"><div class="fd-section-heading"><h3>Diagnostics</h3><button type="button" class="fd-link-button" data-go="diagnostics"><span class="fd-button-label">${e.counts.diagnostics} ${e.counts.diagnostics===1?"notice":"notices"}</span>${$("external")}</button></div>${J()}</section>`,v.querySelectorAll("[data-route]").forEach(o=>o.onclick=()=>{h=Number(o.dataset.route),r("routes")})}function X(e){let o=c;v.innerHTML=O(e?"API":"Routes",e?"Registered methods and effective server runtime controls.":"Pages, layouts, loading states, and error boundaries.")+`<div class="fd-filter-row"><label class="fd-search">${$("search")}<input type="search" aria-label="${e?"Filter APIs":"Filter routes"}" placeholder="Filter by path, ${e?"method":"kind"}, or source\u2026" data-filter><kbd>/</kbd></label></div><div class="fd-browser"><div class="fd-list" data-list></div><section class="fd-detail" data-detail aria-label="Selected ${e?"API":"route"}"></section></div>`;let f=e?o.apiRoutes.map((L,b)=>({index:b,path:L.path,kind:L.methods.join(" / "),file:L.filePath})):o.routes.map((L,b)=>({index:b,path:L.pattern,kind:L.kind,file:L.filePath})),m=v.querySelector("[data-filter]"),_=v.querySelector("[data-list]");function N(){let L=e?E:h,b=f[L],he=v.querySelector("[data-detail]");if(!b){he.innerHTML=g("Nothing selected.");return}let oe=e?o.apiRoutes[L]:o.routes[L];he.innerHTML=`<div class="fd-detail-title">${$(e?"api":"route")}${S(b.path)}</div><dl class="fd-properties">${k("Source",b.file)}${k(e?"Methods":"Kind",b.kind)}${k("Runtime",n(oe.runtime))}${k("Regions",oe.runtime?.regions?.join(", ")||"Not overridden")}${k("Max duration",oe.runtime?.maxDuration?`${oe.runtime.maxDuration}s`:"Not overridden")}</dl><div class="fd-detail-sub"><button class="fd-link-button" type="button" data-copy="route-source">${$("copy")}<span class="fd-button-label">Copy source path</span></button></div>${e?'<p class="fd-subtitle">Read-only metadata. Inspecting an endpoint does not send a request.</p>':""}`,j.set("route-source",b.file),_.querySelectorAll("button").forEach(ve=>ve.setAttribute("aria-pressed",String(Number(ve.dataset.select)===L)))}function ge(){let L=m.value.toLowerCase();_.innerHTML=f.filter(b=>(b.path+" "+b.kind+" "+b.file).toLowerCase().includes(L)).map(b=>`<button type="button" class="fd-list-button" data-select="${b.index}" aria-pressed="${b.index===(e?E:h)}">${S(b.path)}<span class="fd-preview-meta">${u(b.kind)}</span></button>`).join("")||g("No matches. Try another path, kind, or source."),_.querySelectorAll("button").forEach(b=>b.onclick=()=>{e?E=Number(b.dataset.select):h=Number(b.dataset.select),N()})}m.oninput=ge,ge(),N()}function de(){let e=c;v.innerHTML=O("Systems","Configured integrations, middleware, and storage.")+`<section class="fd-section fd-flush-top"><div class="fd-section-heading"><h3>Integrations</h3><span class="fd-label">${e.integrations.length} REGISTERED</span></div>${e.integrations.map(o=>`<details><summary>${u(o.key)} <span class="fd-muted">/ ${u(o.type)}</span></summary><dl class="fd-properties">${k("Category",o.category)}${k("Runtime",o.serverRuntime?"Server":"Platform")}${k("Middleware",String(o.middlewareCount))}${k("Providers",String(o.providerCount))}${k("Schema models",String(o.schemaModelCount))}</dl>${o.routes.map(f=>`<div class="fd-tree-item">${S(f.methods.join(" / ")+" "+f.path)}</div>`).join("")}</details>`).join("")||g("No integrations configured.")}</section><section class="fd-section"><h3>Request middleware</h3>${e.middleware.map(o=>`<div class="fd-system-row">${$("shield")}<div>${S(o.path)}<p>${u(o.filePath||o.source)}</p></div><span class="fd-tag">${o.handlerCount} ${o.handlerCount===1?"handler":"handlers"}</span></div>`).join("")||g("No request middleware configured.")}</section><section class="fd-section"><h3>KV mounts</h3>${e.storage.map(o=>`<div class="fd-system-row">${$("database")}<div>${S(o.mount)}<p>${u(o.driver)}</p></div><span class="fd-tag">${o.default?"Default":"Configured"}</span></div>`).join("")||g("No storage mounts.")}</section>`}function Z(){let e=c;v.innerHTML=O("Runtime","Resolved deployment, schedules, layers, and environment.","Read only")+`<section class="fd-section fd-flush-top"><div class="fd-runtime-grid"><dl class="fd-properties">${k("Target",e.deployment.target)}${k("Nitro preset",e.deployment.preset)}${k("Output",e.deployment.outputDir||"Default")}</dl><dl class="fd-properties">${k("Project",e.project.name)}${k("Source",e.project.srcDir)}${k("Base path",e.project.basePath||"/")}</dl></div></section><section class="fd-section"><div class="fd-section-heading"><h3>Environment</h3><span class="fd-label">KEY NAMES ONLY</span></div><dl class="fd-properties">${k("Server",e.environment.server.join(", ")||"None declared")}${k("Public",e.environment.public.join(", ")||"None declared")}</dl><p class="fd-subtitle">Values and credentials are never included.</p></section><section class="fd-section"><h3>Schedules</h3>${e.cron.map(o=>`<div class="fd-system-row">${$("clock")}<div>${S(o.name)}<p>${u(o.path)}</p></div><span class="fd-mono">${u(o.schedule.join(" / "))} UTC</span></div>`).join("")||g("No cron schedules configured.")}<details><summary>Workflows (${e.workflows.length})</summary>${e.workflows.map(o=>`<div class="fd-tree-item">${S(o.id)} ${S(o.routePath)}</div>`).join("")||g("No workflows discovered.")}</details><details><summary>Layers (${e.layers.length})</summary>${e.layers.map(o=>`<div class="fd-tree-item">${S(o.name)} ${S(o.source)}</div>`).join("")||g("No layers configured.")}</details><details><summary>Framework features</summary><dl class="fd-properties">${Object.entries(e.features).map(([o,f])=>k(o,f?"On":"Off")).join("")}</dl></details></section>`}async function ee(){let e=++U;B?.abort(),B=new AbortController;let o=B.signal;v.innerHTML=O("Inspect","Browser source and the JavaScript Vite actually served.","Read only")+`<div class="fd-inspect-toolbar"><label class="fd-label" for="module-select">MODULE</label><select id="module-select" disabled><option>Loading browser modules\u2026</option></select></div><div data-inspected>${g("Loading module graph\u2026")}</div>`;let f=v.querySelector("[data-inspected]"),m=v.querySelector("select");try{let _=await F(`${Y}/modules.json`,o);if(D||e!==U||s!=="inspect")return;if(w=_.modules,!w.length){m.replaceChildren(new Option("No browser modules yet","")),f.innerHTML=g("Visit an app page, then refresh DevTools. Only transformed browser modules inside this project are listed.");return}m.replaceChildren(...w.map(N=>new Option(N.path+(N.url.includes("?")?" "+N.url.slice(N.url.indexOf("?")):""),N.id))),m.disabled=!1,w.some(N=>N.id===T)||(T=w[0].id),m.value=T,m.onchange=()=>{T=m.value,R(T)},_.limited&&(A.textContent="Inspect lists the first 500 browser modules."),await R(T)}catch(_){if(D||e!==U||s!=="inspect")return;f.innerHTML=g(_.message),m.replaceChildren(new Option("Module graph unavailable",""))}}async function R(e){let o=++U;B?.abort(),B=new AbortController;let f=v.querySelector("[data-inspected]");f.innerHTML=g("Reading module\u2026");try{let m=await F(`${Y}/module.json?id=${encodeURIComponent(e)}`,B.signal);if(D||o!==U||s!=="inspect")return;j.set("module-source",m.source),j.set("module-output",m.transformed),f.innerHTML=`<div class="fd-pipeline"><span class="fd-label">SOURCE \u2192 VITE OUTPUT</span><p class="fd-subtitle">Current file on disk and the latest cached browser transform. Refresh the app after edits.</p></div><div class="fd-comparison">${ie(m.source,"Source","module-source")}${ie(m.transformed,"Served JavaScript","module-output")}</div><section class="fd-section"><details><summary>Imports (${m.imports.length})</summary>${m.imports.map(_=>`<div class="fd-tree-item">${S(_)}</div>`).join("")||g("No imports.")}</details><details><summary>Importers (${m.importers.length})</summary>${m.importers.map(_=>`<div class="fd-tree-item">${S(_)}</div>`).join("")||g("No importers.")}</details></section>`}catch(m){if(D||o!==U||s!=="inspect")return;f.innerHTML=g(m.message)}}function K(){if(!c)return;B?.abort(),++U,j.clear(),A.textContent="",t.querySelectorAll("[data-view]").forEach(o=>{o.dataset.view===s?o.setAttribute("aria-current","page"):o.removeAttribute("aria-current")});let e={routes:c.routes.length,api:c.apiRoutes.length,diagnostics:c.diagnostics.length};switch(t.querySelectorAll("[data-count]").forEach(o=>o.textContent=e[o.dataset.count]===void 0?"":String(e[o.dataset.count])),s){case"overview":C();break;case"routes":X(!1);break;case"api":X(!0);break;case"systems":de();break;case"runtime":Z();break;case"diagnostics":v.innerHTML=O("Diagnostics","The same runtime checks used by farm doctor.")+`<section class="fd-section fd-flush-top">${J()}</section>`;break;case"raw":{let o=JSON.stringify(c,null,2);j.set("snapshot",o),v.innerHTML=O("Snapshot","Machine-readable workspace data. Environment values are excluded.")+ie(o,"Runtime JSON","snapshot");break}case"inspect":ee();break}v.querySelectorAll("[data-go]").forEach(o=>o.onclick=()=>r(o.dataset.go))}let V=async e=>{let o=e.target.closest("[data-copy]");if(!o)return;let f=j.get(o.dataset.copy);if(f!==void 0)try{await a.navigator.clipboard.writeText(f),A.textContent="Copied to clipboard"}catch{A.textContent="Copy was blocked. Select the code and copy it manually."}},te=e=>{if(e.key==="Escape"){e.preventDefault(),i();return}if(e.key==="/"&&!["INPUT","SELECT","TEXTAREA"].includes(e.target.tagName)){let o=v.querySelector("[data-filter]");if(o){e.preventDefault(),o.focus();return}}if(e.key==="Tab"){let o=[...t.querySelectorAll("button,input,select,summary,a[href]")].filter(f=>!f.hasAttribute("disabled")&&f.getClientRects().length);e.shiftKey&&l.activeElement===o[0]?(e.preventDefault(),o.at(-1)?.focus()):!e.shiftKey&&l.activeElement===o.at(-1)&&(e.preventDefault(),o[0]?.focus())}a.parent!==a&&x(e)&&a.parent.postMessage({type:"farm:devtools:keydown",event:{key:e.key,code:e.code,altKey:e.altKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey,repeat:e.repeat}},a.location.origin)};return t.querySelectorAll("[data-view]").forEach(e=>e.onclick=()=>r(e.dataset.view)),t.querySelector("[data-close]").onclick=i,t.querySelector("[data-refresh]").onclick=()=>{y()},t.querySelector("[data-theme-toggle]").onclick=()=>{M=P()?"light":"dark",H();try{a.localStorage.setItem("farm:devtools:theme",M)}catch{}A.textContent=M+" theme"},H(),z.addEventListener("change",H),t.addEventListener("click",V),l.addEventListener("keydown",te),t.querySelector("[data-close]").focus(),y(),{dispose(){D=!0,I?.abort(),B?.abort(),t.removeEventListener("click",V),l.removeEventListener("keydown",te),z.removeEventListener("change",H)}}}var Ee=document.getElementById("farm-devtools");Ee&&Oe(Ee);export{Oe as startPanel};
1
+ var ee="/__farm/devtools";var me=new Set(["<",">","{","}","[","]"]),Fe=new Set(["for","do","while","if","else","return","function","var","let","const","true","false","undefined","this","new","delete","typeof","in","instanceof","void","break","continue","switch","case","default","throw","try","catch","finally","debugger","with","yield","async","await","class","extends","super","import","export","from","static"]),Ue=new Set(["+","-","*","/","%","=","!","&","|","^","~","!","?",":",".",",",";","'",'"',".","(",")","[","]","#","@","\\",...me]),De={keywords:Fe,onCommentStart:Ee,onCommentEnd:qe},ie=["identifier","keyword","string","class","property","entity","jsxliterals","sign","comment","break","space"],[ce,He,V,je,pe,Re,Be,q,ke,ue,$e]=ie.map((t,a)=>a);function se(t){return/^[^\S\r\n]+$/g.test(t)}function _e(t){return Ue.has(t)}function Ne(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function de(t){return/^[\w_]+$/.test(t)||Me(t)}function Pe(t){let a=t[0];return de(a)&&a===a.toUpperCase()||t==="null"}function Me(t){return/[^\u0000-\u007f]/.test(t)}function Te(t){return/^[a-zA-Z]$/.test(t)}function Se(t){return Te(t)||Me(t)}function ne(t){return Se(t[0])&&(t.length===1||de(t.slice(1)))}function ge(t){return t==="`"}function he(t){return t==='"'||t==="'"}function Ie(t){return he(t)||ge(t)}function Ee(t,a){let c=t+a;return c==="/*"?2:c==="//"?1:0}function qe(t,a){return t+a==="*/"?2:a===`
2
+ `?1:0}function Ve(t){return t[0]==="/"&&!Ee(t[0],t[1])}function Ge(t,a){let{keywords:c,onCommentStart:y,onCommentEnd:p}={...De,...a},n="",f=-1,h=[-1,""],S=[-2,""],T=[],w=!1,l=0,k=!1,L=0,H=()=>w&&!k&&!l,A=()=>l&&!H(),j=()=>!l&&H()&&!k&&L>0,U=null,R=!1,E=0,B=0,G=()=>U!==null,O=()=>R,m=()=>B>E,z=()=>B>0&&B===E,_=()=>G()||m();function W(s){let i=s===`
3
+ `;if(A()){if(G())return V;let[,v]=h;if(ne(s)&&(v==="<"||v==="</"))return Re}if(j())return Be;if(G()||m())return V;if(c.has(s))return h[1]==="."?ce:He;if(i)return ue;if(se(s))return $e;if(s.split("").every(_e))return q;if(Pe(s))return A()?ce:je;if(ne(s)){let v=h[1]==="."&&ne(S[1]);if(!_()&&!v)return ce;if(v)return pe}return V}let r=(s,i)=>{if(i&&(n=i),n){f=s||W(n);let F=[f,n];f!==$e&&f!==ue&&(S=h,h=F),T.push(F)}n=""};for(let s=0;s<t.length;s++){let i=t[s],F=t[s-1],v=t[s+1],K=F+i,M=i+v;if(he(i)&&!j()&&!m()){r(),F!=="\\"&&(U&&i===U?U=null:U||(U=i)),r(V,i);continue}if(!m()&&F!=="\\n"&&ge(i)){r(),r(V,i),B++;continue}if(m()){if(F!=="\\n"&&ge(i)&&B>0){r(),B--,r(V,i);continue}if(M==="${"){E++,r(V),r(q,M),s++;continue}}if(z()&&i==="}"){r(),E--,r(q,i);continue}if(H()&&i==="{"){r(),r(q,i),k=!0;continue}if(w){if(!l&&i==="<"){r(),v==="/"?(l=2,n=M,s++):(l=1,n=i),r(q);continue}if(l){if(i===">"&&!"/=".includes(F)){r(),l===1?(l=0,L++):(l=0,w=!1),r(q,i);continue}if(M==="/>"||M==="</"){n!=="<"&&n!=="/"&&r(),M==="/>"?l=0:L--,L||(w=!1),n=M,s++,r(q);continue}if(i==="<"){r(),n=i,r(q);continue}if(v==="-"&&!_()&&!j()&&n){r(pe,n+i+v),s++;continue}if(v==="="&&!_()&&!se(i)){se(n)&&r();let N=n+i;if(ne(N)){r(pe,N);continue}}}}!l&&(i==="<"&&Se(v)||M==="</")&&(l=v==="/"?2:1,i==="<"&&(v==="/"||Te(v))&&!_()&&!j()&&!O()&&(w=!0));let te=Ie(i),fe=m(),Y=!w&&Ve(M),oe=j();if(te||fe||he(U))n+=i;else if(Y){r();let[N,Q]=h;if(Y&&N!==-1&&!(N===q&&Q!==")"||N===ke)){n=i,r();continue}R=!0;let J=s++,ae=()=>s>=t.length,X=()=>ae()||t[s]===`
4
+ `,Z=!1;for(;!X();s++)if(t[s]==="/"&&t[s-1]!=="\\"){for(Z=!0;J!==s&&/^[a-z]$/.test(t[s+1])&&!X();)s++;break}R=!1,J!==s&&Z?(n=t.slice(J,s+1),r(V)):(n=i,r(),s=J)}else if(y(i,v)){r();let N=s,Q=y(i,v);if(Q)for(;s<t.length&&p(t[s-1],t[s])!=Q;s++);n=t.slice(N,s+1),r(ke)}else i===" "||i===`
5
+ `?i===" "&&(se(n)||!n||oe)?(n+=i,v==="<"&&r()):(r(),n=i,r()):k&&i==="}"?(r(),n=i,r(),k=!1):oe&&!me.has(i)||m()||(de(i)===de(n[n.length-1])||H())&&!Ue.has(i)?n+=i:(K==="</"&&(n=K),r(),K!=="</"&&(n=i),M==="</"||M==="/>"?(n=M,r(),s++):me.has(i)&&r())}return r(),T}function Oe(t){let a=[],c=f=>({type:"element",tagName:"span",children:f,properties:{className:"sh__line"}});function y(f){let h=f.map(([S,T])=>{let w=ie[S];return{type:"element",tagName:"span",children:[{type:"text",value:T}],properties:{className:`sh__token--${w}`,style:{color:`var(--sh-${w})`}}}});a.push(c(h))}let p=[],n=!1;for(let f=0;f<t.length;f++){let h=t[f],[S,T]=h,w=f===t.length-1;if(S!==ue){if(T.includes(`
6
+ `)){let l=T.split(`
7
+ `);for(let k=0;k<l.length;k++)p.push([S,l[k]]),k<l.length-1&&(y(p),p.length=0)}else p.push(h);n=!1}else n?y([]):(y(p),p.length=0),w&&y([]),n=!0}return p.length&&y(p),a}var ze=t=>{let a=`class="${t.className}"`;if(t.style){let c=Object.entries(t.style).map(([y,p])=>`${y}:${p}`).join(";");a+=` style="${c}"`}return a};function Ke(t){return t.map(a=>{let{tagName:c}=a,y=a.children.map(p=>{let{tagName:n,children:f,properties:h}=p;return`<${n} ${ze(h)}>${Ne(f[0].value)}</${n}>`}).join("");return`<${c} class="${a.properties.className}">${y}</${c}>`}).join(`
8
+ `)}function Ce(t,a){let c=Ge(t,a),y=Oe(c);return Ke(y)}var at={TokenTypes:ie,TokenMap:new Map(ie.map((t,a)=>[t,a]))};var Je={activity:'<path d="M22 12h-4l-3 9L9 3l-3 9H2"/>',api:'<path d="M8 3H7a2 2 0 0 0-2 2v4a2 2 0 0 1-2 2 2 2 0 0 1 2 2v4a2 2 0 0 0 2 2h1"/><path d="M16 3h1a2 2 0 0 1 2 2v4a2 2 0 0 0 2 2 2 2 0 0 0-2 2v4a2 2 0 0 1-2 2h-1"/>',app:'<path d="M15 3h6v6"/><path d="M10 14 21 3"/><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>',blocks:'<rect width="7" height="7" x="3" y="3"/><rect width="7" height="7" x="14" y="3"/><rect width="7" height="7" x="14" y="14"/><rect width="7" height="7" x="3" y="14"/>',book:'<path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/><path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/>',clock:'<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>',chevron:'<path d="m9 18 6-6-6-6"/>',close:'<path d="M18 6 6 18M6 6l12 12"/>',copy:'<rect width="14" height="14" x="8" y="8"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/>',database:'<ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M3 5v14c0 1.7 4 3 9 3s9-1.3 9-3V5"/><path d="M3 12c0 1.7 4 3 9 3s9-1.3 9-3"/>',external:'<path d="M15 3h6v6"/><path d="M10 14 21 3"/><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>',layers:'<path d="m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z"/><path d="m22 12.5-9.17 4.17a2 2 0 0 1-1.66 0L2 12.5"/><path d="m22 17.5-9.17 4.17a2 2 0 0 1-1.66 0L2 17.5"/>',overview:'<rect width="7" height="9" x="3" y="3"/><rect width="7" height="5" x="14" y="3"/><rect width="7" height="9" x="14" y="12"/><rect width="7" height="5" x="3" y="16"/>',refresh:'<path d="M20 11a8.1 8.1 0 0 0-15.5-2M4 4v5h5"/><path d="M4 13a8.1 8.1 0 0 0 15.5 2M20 20v-5h-5"/>',route:'<circle cx="6" cy="19" r="3"/><path d="M9 19h5.5a3.5 3.5 0 0 0 0-7h-5a3.5 3.5 0 0 1 0-7H18"/><circle cx="18" cy="5" r="3"/>',runtime:'<rect width="20" height="14" x="2" y="3"/><line x1="8" x2="16" y1="21" y2="21"/><line x1="12" x2="12" y1="17" y2="21"/>',search:'<circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>',sun:'<circle cx="12" cy="12" r="4"/><path d="M12 2v2m0 16v2M2 12h2m16 0h2M4.93 4.93l1.42 1.42m11.3 11.3 1.42 1.42M4.93 19.07l1.42-1.42m11.3-11.3 1.42-1.42"/>',moon:'<path d="M20.9 13A9 9 0 0 1 11 3.1 9 9 0 1 0 20.9 13Z"/>',shield:'<path d="M20 13c0 5-3.5 7.5-8 9-4.5-1.5-8-4-8-9V5l8-3 8 3z"/><path d="m9 12 2 2 4-4"/>',terminal:'<polyline points="4 17 10 11 4 5"/><line x1="12" x2="20" y1="19" y2="19"/>'};function $(t,a=""){return`<svg class="icon ${a}" data-lucide="${t}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${Je[t]}</svg>`}function u(t){return String(t??"").replace(/[&<>"']/g,a=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[a])}function le(t,a,c){let y=t.split(`
9
+ `),p=y.slice(0,1500).join(`
10
+ `);return`<section class="fd-code-pane" aria-label="${u(a)}"><div class="fd-code-title"><span class="fd-label">${u(a)}</span><button type="button" class="fd-link-button" data-copy="${u(c)}" aria-label="Copy ${u(a)}">${$("copy")}<span class="fd-button-label">Copy</span></button></div><pre class="fd-source"><code>${Ce(p)}</code></pre>${y.length>1500?'<p class="fd-subtitle">Showing the first 1,500 lines. Copy includes the full bounded source.</p>':""}</section>`}function Le(t,a){let c=t.toLowerCase().split("+").map(l=>l.trim()).filter(Boolean),y=["alt","ctrl","control","meta","cmd","command","mod","shift"],p=c.find(l=>!y.includes(l));if(!p)return()=>!1;let n=c.includes("mod"),f=c.includes("alt"),h=c.includes("shift"),S=c.includes("ctrl")||c.includes("control")||n&&!a,T=c.includes("meta")||c.includes("cmd")||c.includes("command")||n&&a,w=p==="."||p==="period"?"Period":p===","||p==="comma"?"Comma":p==="/"||p==="slash"?"Slash":void 0;return l=>!l.repeat&&l.altKey===f&&l.ctrlKey===S&&l.metaKey===T&&l.shiftKey===h&&(w?l.code===w:String(l.key||"").toLowerCase()===p)}function x(t,a){return`<div class="fd-property"><dt>${u(t)}</dt><dd>${u(a)}</dd></div>`}function I(t,a,c=""){return`<div class="fd-page-heading"><div><h2>${u(t)}</h2><p class="fd-subtitle">${u(a)}</p></div>${c?`<span class="fd-tag">${u(c)}</span>`:""}</div>`}function Qe(t){let a=t.ownerDocument.defaultView,c=t.ownerDocument,y=Le(t.dataset.shortcut??"",/Mac|iPhone|iPad|iPod/.test(a.navigator.platform)),p=[["overview","Overview","overview"],["routes","Routes","route"],["api","API","api"],["systems","Systems","layers"],["plugins","Plugins","blocks"],["runtime","Runtime","runtime"],...t.dataset.inspect==="true"?[["inspect","Inspect","search"]]:[],["diagnostics","Diagnostics","activity"],["raw","Snapshot","terminal"]],n=p.some(([e])=>e===a.location.hash.slice(1))?a.location.hash.slice(1):"overview",f,h=0,S=0,T="",w=[],l=0,k=0,L=!1,H,A,j=!1,U="",R=new Map,E="system";try{let e=a.localStorage.getItem("farm:devtools:theme");(e==="light"||e==="dark")&&(E=e)}catch{}let B=a.matchMedia("(prefers-color-scheme: dark)"),G=()=>E==="dark"||E==="system"&&B.matches,O=()=>{t.dataset.theme=E,t.style.colorScheme=E==="light"||E==="dark"?E:"light dark";let e=t.querySelector("[data-theme-toggle]");if(e){let o=G()?"Switch to light theme":"Switch to dark theme";e.innerHTML=$(G()?"sun":"moon"),e.setAttribute("aria-label",o),e.title=o}};O(),t.innerHTML=`<header class="fd-header"><img class="fd-logo" src="${ee}/assets/logo.svg" alt="Farm.js logo"><span class="fd-brand">FARM.JS</span><span class="fd-muted">/</span><span>DevTools</span><div class="fd-header-actions"><button type="button" class="fd-icon-button" data-refresh aria-label="Refresh DevTools">${$("refresh")}</button><button type="button" class="fd-icon-button" data-theme-toggle aria-label="Switch theme"></button><button type="button" class="fd-icon-button" data-close aria-label="Close DevTools">${$("close")}</button></div></header><div class="fd-error" role="alert" data-error hidden></div><div class="fd-body"><nav class="fd-sidebar" aria-label="DevTools navigation"><div class="fd-label fd-group-label">WORKSPACE</div>${p.map(([e,o,d])=>`<button type="button" class="fd-nav-button" data-view="${e}">${$(d)}<span class="fd-button-label">${o}</span><span class="fd-count" data-count="${e}"></span></button>`).join("")}</nav><main class="fd-main" data-main></main></div><footer class="fd-footer"><span class="fd-footer-label">Development only</span><div class="fd-footer-status"><span data-status role="status">Loading workspace\u2026</span><span data-feedback role="status"></span></div><span class="fd-footer-label">Esc to close</span></footer>`;let m=t.querySelector("[data-main]"),z=t.querySelector("[data-status]"),_=t.querySelector("[data-feedback]"),W=t.querySelector("[data-error]"),r=e=>`<div class="fd-empty">${u(e)}</div>`,s=e=>`<code>${u(e)}</code>`,i=e=>e?`${e.runtime}${e.regions?.length?" \xB7 "+e.regions.join(", "):""}${e.maxDuration?" \xB7 "+e.maxDuration+"s":""}`:"Inherited",F=()=>{a.parent!==a?a.parent.postMessage({type:"farm:devtools:close"},a.location.origin):a.location.assign("/")};function v(e){p.some(([o])=>o===e)&&(n=e,a.history.replaceState(null,"",`#${n}`),n==="inspect"&&U&&!j?M():X())}async function K(e,o){let d=await a.fetch(e,{cache:"no-store",credentials:"same-origin",signal:o});if(!d.ok){let g=await d.json().catch(()=>null);throw new Error(typeof g?.error=="string"?g.error:`DevTools request failed (${d.status}).`)}return d.json()}async function M(){if(j)return;let e=++l;H?.abort(),H=new AbortController,t.setAttribute("aria-busy","true"),z.textContent="Refreshing workspace\u2026",W.hidden=!0,f||(m.innerHTML=r("Loading the current Farm workspace\u2026"));try{let o=await K(`${ee}.json`,H.signal);if(L||e!==l)return;if(!o.project||!o.counts||!Array.isArray(o.routes))throw new Error("Unexpected DevTools snapshot. Check that core and the plugin are up to date.");f=o,U="",h=Math.min(h,Math.max(0,o.routes.length-1)),S=Math.min(S,Math.max(0,o.apiRoutes.length-1)),z.textContent=`${o.project.name} \xB7 Updated ${new Date(o.generatedAt).toLocaleTimeString()}`,X()}catch(o){if(L||e!==l)return;W.textContent=o.message,W.hidden=!1,z.textContent=f?"Showing the last snapshot":"Workspace unavailable",f||(m.innerHTML=r("Use Refresh to reconnect to the development server."))}finally{e===l&&t.removeAttribute("aria-busy")}}function te(){return f.diagnostics.map(e=>`<article class="fd-diagnostic" data-severity="${u(e.severity)}"><span class="${e.severity==="error"?"fd-danger":"fd-amber"}">${$("activity")}</span><div><div class="fd-diagnostic-head"><h3>${u(e.title)}</h3><span class="fd-tag" data-tone="${e.severity==="error"?"bad":e.severity==="warning"?"warn":"info"}">${u(e.severity)}</span></div><div class="fd-label">${u(e.code)}</div><p>${u(e.message)}</p>${e.action?`<p class="fd-diagnostic-action">${u(e.action)}</p>`:""}</div></article>`).join("")||`<div class="fd-diagnostic" data-severity="ok"><span class="fd-green">${$("shield")}</span><div><h3>Framework checks passed</h3><p>No runtime configuration diagnostics in this snapshot.</p></div></div>`}function fe(){let e=f;m.innerHTML=I("Overview",`${e.project.name} \xB7 ${e.project.srcDir}`,"Development")+`<div class="fd-stats">${[["Pages",e.counts.pages,"route"],["API routes",e.counts.apiRoutes,"api"],["Integrations",e.counts.integrations,"blocks"]].map(([o,d,g])=>`<div class="fd-stat"><span class="fd-label">${$(g)}${o}</span><span class="fd-stat-value">${d}</span></div>`).join("")}</div><section class="fd-section"><div class="fd-section-heading"><h3>Application routes</h3><button type="button" class="fd-link-button" data-go="routes"><span class="fd-button-label">View all routes</span>${$("external")}</button></div><div class="fd-route-preview">${e.routes.map((o,d)=>({route:o,index:d})).filter(({route:o})=>o.kind==="page").slice(0,5).map(({route:o,index:d})=>`<button type="button" class="fd-preview-row" data-route="${d}">${s(o.pattern)}<span class="fd-preview-meta">${u(i(o.runtime))}</span>${$("chevron")}</button>`).join("")||r("No page routes discovered.")}</div></section><section class="fd-section"><div class="fd-section-heading"><h3>Diagnostics</h3><button type="button" class="fd-link-button" data-go="diagnostics"><span class="fd-button-label">${e.counts.diagnostics} ${e.counts.diagnostics===1?"notice":"notices"}</span>${$("external")}</button></div>${te()}</section>`,m.querySelectorAll("[data-route]").forEach(o=>o.onclick=()=>{h=Number(o.dataset.route),v("routes")})}function Y(e){let o=f;m.innerHTML=I(e?"API":"Routes",e?"Registered methods and effective server runtime controls.":"Pages, layouts, loading states, and error boundaries.")+`<div class="fd-filter-row"><label class="fd-search">${$("search")}<input type="search" aria-label="${e?"Filter APIs":"Filter routes"}" placeholder="Filter by path, ${e?"method":"kind"}, or source\u2026" data-filter><kbd>/</kbd></label></div><div class="fd-browser"><div class="fd-list" data-list></div><section class="fd-detail" data-detail aria-label="Selected ${e?"API":"route"}"></section></div>`;let d=e?o.apiRoutes.map((C,b)=>({index:b,path:C.path,kind:C.methods.join(" / "),file:C.filePath})):o.routes.map((C,b)=>({index:b,path:C.pattern,kind:C.kind,file:C.filePath})),g=m.querySelector("[data-filter]"),D=m.querySelector("[data-list]");function P(){let C=e?S:h,b=d[C],ye=m.querySelector("[data-detail]");if(!b){ye.innerHTML=r("Nothing selected.");return}let re=e?o.apiRoutes[C]:o.routes[C];ye.innerHTML=`<div class="fd-detail-title">${$(e?"api":"route")}${s(b.path)}</div><dl class="fd-properties">${x("Source",b.file)}${x(e?"Methods":"Kind",b.kind)}${x("Runtime",i(re.runtime))}${x("Regions",re.runtime?.regions?.join(", ")||"Not overridden")}${x("Max duration",re.runtime?.maxDuration?`${re.runtime.maxDuration}s`:"Not overridden")}</dl><div class="fd-detail-sub"><button class="fd-link-button" type="button" data-copy="route-source">${$("copy")}<span class="fd-button-label">Copy source path</span></button></div>${e?'<p class="fd-subtitle">Read-only metadata. Inspecting an endpoint does not send a request.</p>':""}`,R.set("route-source",b.file),D.querySelectorAll("button").forEach(we=>we.setAttribute("aria-pressed",String(Number(we.dataset.select)===C)))}function xe(){let C=g.value.toLowerCase();D.innerHTML=d.filter(b=>(b.path+" "+b.kind+" "+b.file).toLowerCase().includes(C)).map(b=>`<button type="button" class="fd-list-button" data-select="${b.index}" aria-pressed="${b.index===(e?S:h)}">${s(b.path)}<span class="fd-preview-meta">${u(b.kind)}</span></button>`).join("")||r("No matches. Try another path, kind, or source."),D.querySelectorAll("button").forEach(b=>b.onclick=()=>{e?S=Number(b.dataset.select):h=Number(b.dataset.select),P()})}g.oninput=xe,xe(),P()}function oe(){let e=f;m.innerHTML=I("Systems","Configured integrations, middleware, and storage.")+`<section class="fd-section fd-flush-top"><div class="fd-section-heading"><h3>Integrations</h3><span class="fd-label">${e.integrations.length} REGISTERED</span></div>${e.integrations.map(o=>`<details><summary>${u(o.key)} <span class="fd-muted">/ ${u(o.type)}</span></summary><dl class="fd-properties">${x("Category",o.category)}${x("Runtime",o.serverRuntime?"Server":"Platform")}${x("Middleware",String(o.middlewareCount))}${x("Providers",String(o.providerCount))}${x("Schema models",String(o.schemaModelCount))}</dl>${o.routes.map(d=>`<div class="fd-tree-item">${s(d.methods.join(" / ")+" "+d.path)}</div>`).join("")}</details>`).join("")||r("No integrations configured.")}</section><section class="fd-section"><h3>Request middleware</h3>${e.middleware.map(o=>`<div class="fd-system-row">${$("shield")}<div>${s(o.path)}<p>${u(o.filePath||o.source)}</p></div><span class="fd-tag">${o.handlerCount} ${o.handlerCount===1?"handler":"handlers"}</span></div>`).join("")||r("No request middleware configured.")}</section><section class="fd-section"><h3>KV mounts</h3>${e.storage.map(o=>`<div class="fd-system-row">${$("database")}<div>${s(o.mount)}<p>${u(o.driver)}</p></div><span class="fd-tag">${o.default?"Default":"Configured"}</span></div>`).join("")||r("No storage mounts.")}</section>`}function N(){let e=f;m.innerHTML=I("Runtime","Resolved deployment, schedules, layers, and environment.","Read only")+`<section class="fd-section fd-flush-top"><div class="fd-runtime-grid"><dl class="fd-properties">${x("Target",e.deployment.target)}${x("Nitro preset",e.deployment.preset)}${x("Output",e.deployment.outputDir||"Default")}</dl><dl class="fd-properties">${x("Project",e.project.name)}${x("Source",e.project.srcDir)}${x("Base path",e.project.basePath||"/")}</dl></div></section><section class="fd-section"><div class="fd-section-heading"><h3>Environment</h3><span class="fd-label">KEY NAMES ONLY</span></div><dl class="fd-properties">${x("Server",e.environment.server.join(", ")||"None declared")}${x("Public",e.environment.public.join(", ")||"None declared")}</dl><p class="fd-subtitle">Values and credentials are never included.</p></section><section class="fd-section"><h3>Schedules</h3>${e.cron.map(o=>`<div class="fd-system-row">${$("clock")}<div>${s(o.name)}<p>${u(o.path)}</p></div><span class="fd-mono">${u(o.schedule.join(" / "))} UTC</span></div>`).join("")||r("No cron schedules configured.")}<details><summary>Workflows (${e.workflows.length})</summary>${e.workflows.map(o=>`<div class="fd-tree-item">${s(o.id)} ${s(o.routePath)}</div>`).join("")||r("No workflows discovered.")}</details><details><summary>Layers (${e.layers.length})</summary>${e.layers.map(o=>`<div class="fd-tree-item">${s(o.name)} ${s(o.source)}</div>`).join("")||r("No layers configured.")}</details><details><summary>Framework features</summary><dl class="fd-properties">${Object.entries(e.features).map(([o,d])=>x(o,d?"On":"Off")).join("")}</dl></details></section>`}function Q(){let e=f.plugins??[],o=d=>d.length?d.map(g=>`<div class="fd-tree-item">${s(g)}</div>`).join(""):'<p class="fd-subtitle">No hooks declared.</p>';m.innerHTML=I("Plugins","Active Farm plugins in execution order. Pre \u2192 normal \u2192 post.",`${e.length} registered`)+`<section class="fd-section fd-flush-top"><p class="fd-subtitle">Hook names describe registration, not a trace of calls. Parallel lifecycle hooks may finish in a different order. Config, public data, and private state are not included.</p>${e.map(d=>`<details class="fd-plugin"><summary><span class="fd-mono">${d.order}.</span> ${u(d.name)} <span class="fd-tag">${u(d.enforce)}</span></summary><dl class="fd-properties">${x("Version",d.version||"Not declared")}${x("API routes",d.routes?"Declared":"None")}</dl><div class="fd-runtime-grid"><section><h3>Server hooks</h3>${o(d.serverHooks)}</section><section><h3>Client hooks</h3>${o(d.clientHooks)}</section></div></details>`).join("")||r("No active Farm plugins. Register a plugin in farm.config.ts to see its lifecycle here.")}</section>`}async function J(){if(j){m.innerHTML=I("Inspect","Browser source and cached Vite output.")+r(U);return}let e=++k;A?.abort(),A=new AbortController;let o=A.signal;m.innerHTML=I("Inspect","Browser source and the JavaScript Vite actually served.","Read only")+`<div class="fd-inspect-toolbar"><label class="fd-label" for="module-select">MODULE</label><select id="module-select" disabled><option>Loading browser modules\u2026</option></select></div><div data-inspected>${r("Loading module graph\u2026")}</div>`;let d=m.querySelector("[data-inspected]"),g=m.querySelector("select");try{let D=await K(`${ee}/modules.json`,o);if(L||e!==k||n!=="inspect")return;if(w=D.modules,!w.length){g.replaceChildren(new Option("No browser modules yet","")),d.innerHTML=r("Visit an app page, then refresh DevTools. Only transformed browser modules inside this project are listed.");return}g.replaceChildren(...w.map(P=>new Option(P.path+(P.url.includes("?")?" "+P.url.slice(P.url.indexOf("?")):""),P.id))),g.disabled=!1,w.some(P=>P.id===T)||(T=w[0].id),g.value=T,g.onchange=()=>{T=g.value,ae(T)},D.limited&&(_.textContent="Inspect lists the first 500 browser modules."),await ae(T)}catch(D){if(L||e!==k||n!=="inspect")return;d.innerHTML=r(D.message),g.replaceChildren(new Option("Module graph unavailable",""))}}async function ae(e){let o=++k;A?.abort(),A=new AbortController;let d=m.querySelector("[data-inspected]");d.innerHTML=r("Reading module\u2026");try{let g=await K(`${ee}/module.json?id=${encodeURIComponent(e)}`,A.signal);if(L||o!==k||n!=="inspect")return;R.set("module-source",g.source),R.set("module-output",g.transformed),d.innerHTML=`<div class="fd-pipeline"><span class="fd-label">SOURCE \u2192 VITE OUTPUT</span><p class="fd-subtitle" data-module-state role="status">${u(U||"Current file on disk and cached browser output. Refreshes after HMR.")}</p></div><div class="fd-comparison">${le(g.source,"Source","module-source")}${le(g.transformed,"Served JavaScript","module-output")}</div><section class="fd-section"><details><summary>Imports (${g.imports.length})</summary>${g.imports.map(D=>`<div class="fd-tree-item">${s(D)}</div>`).join("")||r("No imports.")}</details><details><summary>Importers (${g.importers.length})</summary>${g.importers.map(D=>`<div class="fd-tree-item">${s(D)}</div>`).join("")||r("No importers.")}</details></section>`}catch(g){if(L||o!==k||n!=="inspect")return;d.innerHTML=r(g.message)}}function X(){if(!f)return;A?.abort(),++k,R.clear(),_.textContent="",t.querySelectorAll("[data-view]").forEach(o=>{o.dataset.view===n?o.setAttribute("aria-current","page"):o.removeAttribute("aria-current")});let e={routes:f.routes.length,api:f.apiRoutes.length,diagnostics:f.diagnostics.length,plugins:f.plugins?.length??0};switch(t.querySelectorAll("[data-count]").forEach(o=>o.textContent=e[o.dataset.count]===void 0?"":String(e[o.dataset.count])),n){case"overview":fe();break;case"routes":Y(!1);break;case"api":Y(!0);break;case"systems":oe();break;case"plugins":Q();break;case"runtime":N();break;case"diagnostics":m.innerHTML=I("Diagnostics","The same runtime checks used by farm doctor.")+`<section class="fd-section fd-flush-top">${te()}</section>`;break;case"raw":{let o=JSON.stringify(f,null,2);R.set("snapshot",o),m.innerHTML=I("Snapshot","Machine-readable workspace data. Environment values are excluded.")+le(o,"Runtime JSON","snapshot");break}case"inspect":J();break}m.querySelectorAll("[data-go]").forEach(o=>o.onclick=()=>v(o.dataset.go))}let Z=async e=>{let o=e.target.closest("[data-copy]");if(!o)return;let d=R.get(o.dataset.copy);if(d!==void 0)try{await a.navigator.clipboard.writeText(d),_.textContent="Copied to clipboard"}catch{_.textContent="Copy was blocked. Select the code and copy it manually."}},ve=e=>{if(e.key==="Escape"){e.preventDefault(),F();return}if(e.key==="/"&&!["INPUT","SELECT","TEXTAREA"].includes(e.target.tagName)){let o=m.querySelector("[data-filter]");if(o){e.preventDefault(),o.focus();return}}if(e.key==="Tab"){let o=[...t.querySelectorAll("button,input,select,summary,a[href]")].filter(d=>!d.hasAttribute("disabled")&&d.getClientRects().length);e.shiftKey&&c.activeElement===o[0]?(e.preventDefault(),o.at(-1)?.focus()):!e.shiftKey&&c.activeElement===o.at(-1)&&(e.preventDefault(),o[0]?.focus())}a.parent!==a&&y(e)&&a.parent.postMessage({type:"farm:devtools:keydown",event:{key:e.key,code:e.code,altKey:e.altKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey,repeat:e.repeat}},a.location.origin)},be=e=>{if(L||a.parent===a||e.source!==a.parent||e.origin!==a.location.origin||e.data?.type!=="farm:devtools:hmr")return;let o=e.data.state;if(!["pending","ready","error","disconnected"].includes(o))return;if(j=o==="pending"||o==="disconnected",o==="ready"){n==="inspect"?M():(U="App updated. Refresh to capture the latest workspace.",z.textContent=U);return}H?.abort(),A?.abort(),++l,++k,t.removeAttribute("aria-busy"),U=o==="pending"?"HMR pending \xB7 Showing previous source and output":o==="error"?"HMR failed \xB7 Showing previous source and output":"Disconnected \xB7 Showing previous source and output",z.textContent=U;let d=m.querySelector("[data-module-state]");d&&(d.textContent=U,d.classList.add("fd-amber"))};return t.querySelectorAll("[data-view]").forEach(e=>e.onclick=()=>v(e.dataset.view)),t.querySelector("[data-close]").onclick=F,t.querySelector("[data-refresh]").onclick=()=>{M()},t.querySelector("[data-theme-toggle]").onclick=()=>{E=G()?"light":"dark",O();try{a.localStorage.setItem("farm:devtools:theme",E)}catch{}_.textContent=E+" theme"},O(),B.addEventListener("change",O),t.addEventListener("click",Z),c.addEventListener("keydown",ve),a.addEventListener("message",be),t.querySelector("[data-close]").focus(),M(),{dispose(){L=!0,H?.abort(),A?.abort(),t.removeEventListener("click",Z),c.removeEventListener("keydown",ve),a.removeEventListener("message",be),B.removeEventListener("change",O)}}}var Ae=document.getElementById("farm-devtools");Ae&&Qe(Ae);export{Qe as startPanel};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/devtools",
3
- "version": "0.1.61",
3
+ "version": "0.1.62",
4
4
  "description": "Development workspace inspector for Farm.js routes, runtime, and browser modules",
5
5
  "keywords": [
6
6
  "devtools",
@@ -57,7 +57,7 @@
57
57
  "typescript": "^5.3.3",
58
58
  "vite": "8.3.4",
59
59
  "vitest": "5.0.5",
60
- "@farm.js/core": "0.1.61"
60
+ "@farm.js/core": "0.1.62"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "@farm.js/core": ">=0.1.28 <0.2.0"