binja 0.5.3 → 0.6.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.
@@ -14,6 +14,14 @@ class DebugCollector {
14
14
  testsUsed: new Map,
15
15
  cacheHits: 0,
16
16
  cacheMisses: 0,
17
+ queries: [],
18
+ queryStats: {
19
+ count: 0,
20
+ totalDuration: 0,
21
+ slowCount: 0,
22
+ n1Count: 0,
23
+ queryCounts: new Map
24
+ },
17
25
  warnings: []
18
26
  };
19
27
  }
@@ -154,6 +162,33 @@ class DebugCollector {
154
162
  addWarning(message) {
155
163
  this.data.warnings.push(message);
156
164
  }
165
+ recordQuery(query) {
166
+ const normalizedSql = this.normalizeQuery(query.sql);
167
+ const currentCount = this.data.queryStats.queryCounts.get(normalizedSql) || 0;
168
+ this.data.queryStats.queryCounts.set(normalizedSql, currentCount + 1);
169
+ const isN1 = currentCount >= 2;
170
+ const queryInfo = {
171
+ ...query,
172
+ timestamp: performance.now(),
173
+ isN1
174
+ };
175
+ this.data.queries.push(queryInfo);
176
+ this.data.queryStats.count++;
177
+ this.data.queryStats.totalDuration += query.duration;
178
+ if (query.duration > 100) {
179
+ this.data.queryStats.slowCount++;
180
+ }
181
+ if (isN1 && currentCount === 2) {
182
+ this.data.queryStats.n1Count++;
183
+ this.addWarning(`N+1 query detected: ${normalizedSql.slice(0, 50)}...`);
184
+ }
185
+ }
186
+ normalizeQuery(sql) {
187
+ return sql.replace(/\s+/g, " ").replace(/= \?/g, "= ?").replace(/= \$\d+/g, "= ?").replace(/= '\w+'/g, "= '?'").replace(/= \d+/g, "= ?").replace(/IN \([^)]+\)/gi, "IN (?)").trim();
188
+ }
189
+ getQueryStats() {
190
+ return this.data.queryStats;
191
+ }
157
192
  getData() {
158
193
  return this.data;
159
194
  }
@@ -185,388 +220,665 @@ function endDebugCollection() {
185
220
 
186
221
  // src/debug/panel.ts
187
222
  var DEFAULT_OPTIONS = {
188
- position: "bottom-right",
189
- collapsed: true,
190
- dark: true,
191
- width: 420
223
+ position: "bottom",
224
+ height: 300,
225
+ width: 400,
226
+ open: false,
227
+ dark: true
192
228
  };
193
229
  function generateDebugPanel(data, options = {}) {
194
230
  const opts = { ...DEFAULT_OPTIONS, ...options };
195
- const id = `binja-debug-${Date.now()}`;
196
- const colors = opts.dark ? darkTheme : lightTheme;
231
+ const id = `binja-dbg-${Date.now()}`;
232
+ const c = opts.dark ? darkTheme : lightTheme;
197
233
  return `
198
234
  <!-- Binja Debug Panel -->
199
- <div id="${id}" class="binja-debugger" data-theme="${opts.dark ? "dark" : "light"}">
200
- <style>${generateStyles(id, colors, opts)}</style>
201
- ${generateToggle(id, data, colors)}
202
- ${generatePanel(id, data, colors, opts)}
203
- <script>${generateScript(id)}</script>
235
+ <div id="${id}" class="binja-devtools" data-position="${opts.position}" data-open="${opts.open}">
236
+ <style>${generateStyles(id, c, opts)}</style>
237
+ ${generateHTML(id, data, c, opts)}
238
+ <script>${generateScript(id, data, opts)}</script>
204
239
  </div>
205
240
  <!-- /Binja Debug Panel -->
206
241
  `;
207
242
  }
208
243
  var darkTheme = {
209
- bg: "#0f0f0f",
210
- bgSecondary: "#1a1a1a",
211
- bgTertiary: "#242424",
212
- border: "#2a2a2a",
213
- borderLight: "#333",
214
- text: "#e5e5e5",
215
- textSecondary: "#a0a0a0",
216
- textMuted: "#666",
217
- accent: "#3b82f6",
218
- accentHover: "#2563eb",
219
- success: "#22c55e",
220
- warning: "#eab308",
221
- error: "#ef4444",
222
- info: "#06b6d4"
244
+ bg: "#1e1e1e",
245
+ bgPanel: "#252526",
246
+ bgHover: "#2a2d2e",
247
+ bgActive: "#37373d",
248
+ border: "#3c3c3c",
249
+ text: "#cccccc",
250
+ textSecondary: "#969696",
251
+ textMuted: "#6e6e6e",
252
+ accent: "#0078d4",
253
+ accentHover: "#1c86d8",
254
+ success: "#4ec9b0",
255
+ warning: "#dcdcaa",
256
+ error: "#f14c4c",
257
+ info: "#75beff",
258
+ string: "#ce9178",
259
+ number: "#b5cea8",
260
+ keyword: "#569cd6"
223
261
  };
224
262
  var lightTheme = {
225
- bg: "#ffffff",
226
- bgSecondary: "#f8f9fa",
227
- bgTertiary: "#f1f3f4",
228
- border: "#e5e7eb",
229
- borderLight: "#d1d5db",
230
- text: "#111827",
231
- textSecondary: "#4b5563",
232
- textMuted: "#9ca3af",
233
- accent: "#2563eb",
234
- accentHover: "#1d4ed8",
235
- success: "#16a34a",
236
- warning: "#ca8a04",
237
- error: "#dc2626",
238
- info: "#0891b2"
263
+ bg: "#f3f3f3",
264
+ bgPanel: "#ffffff",
265
+ bgHover: "#e8e8e8",
266
+ bgActive: "#d4d4d4",
267
+ border: "#d4d4d4",
268
+ text: "#1e1e1e",
269
+ textSecondary: "#616161",
270
+ textMuted: "#a0a0a0",
271
+ accent: "#0078d4",
272
+ accentHover: "#106ebe",
273
+ success: "#16825d",
274
+ warning: "#bf8803",
275
+ error: "#cd3131",
276
+ info: "#0078d4",
277
+ string: "#a31515",
278
+ number: "#098658",
279
+ keyword: "#0000ff"
239
280
  };
240
281
  function generateStyles(id, c, opts) {
241
- const pos = getPosition(opts.position);
242
282
  return `
243
- #${id} { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif; font-size: 13px; line-height: 1.5; position: fixed; ${pos} z-index: 2147483647; }
283
+ #${id} { --bg: ${c.bg}; --bg-panel: ${c.bgPanel}; --bg-hover: ${c.bgHover}; --bg-active: ${c.bgActive}; --border: ${c.border}; --text: ${c.text}; --text-secondary: ${c.textSecondary}; --text-muted: ${c.textMuted}; --accent: ${c.accent}; --success: ${c.success}; --warning: ${c.warning}; --error: ${c.error}; --string: ${c.string}; --number: ${c.number}; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif; font-size: 12px; line-height: 1.4; color: var(--text); }
244
284
  #${id} * { box-sizing: border-box; margin: 0; padding: 0; }
245
- #${id} .dbg-toggle { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; background: ${c.bg}; border: 1px solid ${c.border}; border-radius: 8px; color: ${c.text}; cursor: pointer; font-size: 12px; font-weight: 500; box-shadow: 0 4px 12px rgba(0,0,0,0.15); transition: all 0.2s ease; }
246
- #${id} .dbg-toggle:hover { border-color: ${c.accent}; box-shadow: 0 4px 16px rgba(0,0,0,0.2); }
247
- #${id} .dbg-toggle svg { width: 16px; height: 16px; }
248
- #${id} .dbg-toggle .dbg-time { font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace; font-size: 11px; padding: 2px 8px; background: ${c.bgTertiary}; border-radius: 4px; color: ${c.success}; }
249
- #${id} .dbg-panel { display: none; width: ${opts.width}px; max-height: 85vh; background: ${c.bg}; border: 1px solid ${c.border}; border-radius: 10px; box-shadow: 0 8px 32px rgba(0,0,0,0.24); overflow: hidden; margin-top: 8px; }
250
- #${id} .dbg-panel.open { display: block; }
251
- #${id} .dbg-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: ${c.bgSecondary}; border-bottom: 1px solid ${c.border}; }
252
- #${id} .dbg-logo { display: flex; align-items: center; gap: 10px; font-weight: 600; color: ${c.text}; }
253
- #${id} .dbg-logo svg { width: 20px; height: 20px; color: ${c.accent}; }
254
- #${id} .dbg-meta { display: flex; align-items: center; gap: 12px; }
255
- #${id} .dbg-badge { font-family: 'SF Mono', Monaco, monospace; font-size: 11px; padding: 3px 10px; border-radius: 4px; font-weight: 500; }
256
- #${id} .dbg-badge.time { background: rgba(34,197,94,0.1); color: ${c.success}; }
257
- #${id} .dbg-badge.mode { background: rgba(59,130,246,0.1); color: ${c.accent}; }
258
- #${id} .dbg-close { background: none; border: none; color: ${c.textMuted}; cursor: pointer; padding: 4px; border-radius: 4px; display: flex; }
259
- #${id} .dbg-close:hover { background: ${c.bgTertiary}; color: ${c.text}; }
260
- #${id} .dbg-close svg { width: 18px; height: 18px; }
261
- #${id} .dbg-body { max-height: calc(85vh - 52px); overflow-y: auto; }
262
- #${id} .dbg-section { border-bottom: 1px solid ${c.border}; }
263
- #${id} .dbg-section:last-child { border-bottom: none; }
264
- #${id} .dbg-section-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; cursor: pointer; user-select: none; transition: background 0.15s; }
265
- #${id} .dbg-section-header:hover { background: ${c.bgSecondary}; }
266
- #${id} .dbg-section-title { display: flex; align-items: center; gap: 8px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: ${c.textSecondary}; }
267
- #${id} .dbg-section-title svg { width: 14px; height: 14px; opacity: 0.7; }
268
- #${id} .dbg-section-meta { font-size: 11px; color: ${c.textMuted}; font-family: 'SF Mono', Monaco, monospace; }
269
- #${id} .dbg-section-content { display: none; padding: 12px 16px; background: ${c.bgSecondary}; }
270
- #${id} .dbg-section.open .dbg-section-content { display: block; }
271
- #${id} .dbg-section .dbg-chevron { transition: transform 0.2s; color: ${c.textMuted}; }
272
- #${id} .dbg-section.open .dbg-chevron { transform: rotate(90deg); }
273
- #${id} .dbg-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid ${c.border}; }
274
- #${id} .dbg-row:last-child { border-bottom: none; }
275
- #${id} .dbg-label { color: ${c.textSecondary}; font-size: 12px; }
276
- #${id} .dbg-value { color: ${c.text}; font-family: 'SF Mono', Monaco, monospace; font-size: 12px; text-align: right; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
277
- #${id} .dbg-bar { height: 3px; background: ${c.bgTertiary}; border-radius: 2px; margin-top: 4px; overflow: hidden; }
278
- #${id} .dbg-bar-fill { height: 100%; border-radius: 2px; transition: width 0.3s ease; }
279
- #${id} .dbg-bar-fill.lexer { background: ${c.info}; }
280
- #${id} .dbg-bar-fill.parser { background: ${c.warning}; }
281
- #${id} .dbg-bar-fill.render { background: ${c.success}; }
282
- #${id} .dbg-templates { display: flex; flex-direction: column; gap: 6px; }
283
- #${id} .dbg-template { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: ${c.bg}; border-radius: 6px; font-size: 12px; }
284
- #${id} .dbg-template-icon { width: 16px; height: 16px; color: ${c.textMuted}; flex-shrink: 0; }
285
- #${id} .dbg-template-name { color: ${c.text}; font-family: 'SF Mono', Monaco, monospace; }
286
- #${id} .dbg-template-tag { font-size: 10px; padding: 2px 6px; border-radius: 3px; font-weight: 500; text-transform: uppercase; }
287
- #${id} .dbg-template-tag.root { background: rgba(59,130,246,0.15); color: ${c.accent}; }
288
- #${id} .dbg-template-tag.extends { background: rgba(168,85,247,0.15); color: #a855f7; }
289
- #${id} .dbg-template-tag.include { background: rgba(34,197,94,0.15); color: ${c.success}; }
290
- #${id} .dbg-ctx-grid { display: flex; flex-direction: column; gap: 4px; }
291
- #${id} .dbg-ctx-item { background: ${c.bg}; border-radius: 6px; overflow: hidden; }
292
- #${id} .dbg-ctx-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; cursor: default; }
293
- #${id} .dbg-ctx-row.expandable { cursor: pointer; }
294
- #${id} .dbg-ctx-row.expandable:hover { background: ${c.bgTertiary}; }
295
- #${id} .dbg-ctx-key { display: flex; align-items: center; gap: 6px; }
296
- #${id} .dbg-ctx-arrow { width: 12px; height: 12px; color: ${c.textMuted}; transition: transform 0.15s; flex-shrink: 0; }
297
- #${id} .dbg-ctx-item.open > .dbg-ctx-row .dbg-ctx-arrow { transform: rotate(90deg); }
298
- #${id} .dbg-ctx-name { color: ${c.text}; font-family: 'SF Mono', Monaco, monospace; font-size: 12px; }
299
- #${id} .dbg-ctx-type { font-size: 10px; color: ${c.accent}; background: rgba(59,130,246,0.1); padding: 1px 5px; border-radius: 3px; }
300
- #${id} .dbg-ctx-preview { color: ${c.textSecondary}; font-family: 'SF Mono', Monaco, monospace; font-size: 11px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
301
- #${id} .dbg-ctx-children { display: none; padding-left: 16px; border-left: 1px solid ${c.border}; margin-left: 10px; }
302
- #${id} .dbg-ctx-item.open > .dbg-ctx-children { display: block; }
303
- #${id} .dbg-ctx-children .dbg-ctx-item { background: transparent; }
304
- #${id} .dbg-ctx-children .dbg-ctx-row { padding: 4px 8px; }
305
- #${id} .dbg-filters { display: flex; flex-wrap: wrap; gap: 6px; }
306
- #${id} .dbg-filter { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; background: ${c.bg}; border-radius: 5px; font-size: 12px; font-family: 'SF Mono', Monaco, monospace; color: ${c.text}; }
307
- #${id} .dbg-filter-count { font-size: 10px; color: ${c.accent}; font-weight: 600; }
308
- #${id} .dbg-cache { display: flex; gap: 16px; }
309
- #${id} .dbg-cache-stat { flex: 1; padding: 12px; background: ${c.bg}; border-radius: 6px; text-align: center; }
310
- #${id} .dbg-cache-num { font-size: 24px; font-weight: 600; font-family: 'SF Mono', Monaco, monospace; }
311
- #${id} .dbg-cache-num.hit { color: ${c.success}; }
312
- #${id} .dbg-cache-num.miss { color: ${c.error}; }
313
- #${id} .dbg-cache-label { font-size: 11px; color: ${c.textMuted}; margin-top: 4px; }
314
- #${id} .dbg-warnings { display: flex; flex-direction: column; gap: 6px; }
315
- #${id} .dbg-warning { display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px; background: rgba(234,179,8,0.1); border-radius: 6px; border-left: 3px solid ${c.warning}; }
316
- #${id} .dbg-warning-icon { color: ${c.warning}; flex-shrink: 0; margin-top: 1px; }
317
- #${id} .dbg-warning-text { color: ${c.text}; font-size: 12px; }
285
+
286
+ /* Toggle Button */
287
+ #${id} .devtools-toggle { position: fixed; bottom: 10px; right: 10px; z-index: 2147483646; display: flex; align-items: center; gap: 6px; padding: 8px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); cursor: pointer; font-size: 11px; font-weight: 500; box-shadow: 0 2px 8px rgba(0,0,0,0.2); transition: all 0.15s; }
288
+ #${id} .devtools-toggle:hover { background: var(--bg-hover); border-color: var(--accent); }
289
+ #${id} .devtools-toggle svg { width: 14px; height: 14px; color: var(--accent); }
290
+ #${id} .devtools-toggle .badge { padding: 2px 6px; background: var(--accent); color: #fff; border-radius: 3px; font-size: 10px; }
291
+ #${id}[data-open="true"] .devtools-toggle { display: none; }
292
+
293
+ /* Panel Container */
294
+ #${id} .devtools-panel { display: none; position: fixed; z-index: 2147483647; background: var(--bg); border: 1px solid var(--border); box-shadow: 0 -2px 12px rgba(0,0,0,0.3); }
295
+ #${id}[data-open="true"] .devtools-panel { display: flex; flex-direction: column; }
296
+ #${id}[data-position="bottom"] .devtools-panel { left: 0; right: 0; bottom: 0; height: ${opts.height}px; border-left: none; border-right: none; border-bottom: none; }
297
+ #${id}[data-position="right"] .devtools-panel { top: 0; right: 0; bottom: 0; width: ${opts.width}px; border-top: none; border-right: none; border-bottom: none; }
298
+ #${id}[data-position="popup"] .devtools-panel { bottom: 50px; right: 20px; width: 700px; height: 500px; border-radius: 8px; }
299
+
300
+ /* Resize Handle */
301
+ #${id} .devtools-resize { position: absolute; background: transparent; }
302
+ #${id}[data-position="bottom"] .devtools-resize { top: 0; left: 0; right: 0; height: 4px; cursor: ns-resize; }
303
+ #${id}[data-position="right"] .devtools-resize { top: 0; left: 0; bottom: 0; width: 4px; cursor: ew-resize; }
304
+ #${id} .devtools-resize:hover { background: var(--accent); }
305
+
306
+ /* Toolbar */
307
+ #${id} .devtools-toolbar { display: flex; align-items: center; justify-content: space-between; height: 30px; padding: 0 8px; background: var(--bg-panel); border-bottom: 1px solid var(--border); flex-shrink: 0; }
308
+ #${id} .devtools-tabs { display: flex; height: 100%; }
309
+ #${id} .devtools-tab { display: flex; align-items: center; gap: 4px; padding: 0 12px; border: none; background: none; color: var(--text-secondary); font-size: 11px; cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.1s; }
310
+ #${id} .devtools-tab:hover { color: var(--text); background: var(--bg-hover); }
311
+ #${id} .devtools-tab.active { color: var(--text); border-bottom-color: var(--accent); }
312
+ #${id} .devtools-tab svg { width: 12px; height: 12px; opacity: 0.7; }
313
+ #${id} .devtools-tab .count { margin-left: 4px; padding: 1px 5px; background: var(--bg-active); border-radius: 8px; font-size: 10px; }
314
+ #${id} .devtools-tab .count.warn { background: rgba(241,76,76,0.2); color: var(--error); }
315
+ #${id} .devtools-actions { display: flex; align-items: center; gap: 4px; }
316
+ #${id} .devtools-btn { display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; border: none; background: none; color: var(--text-secondary); cursor: pointer; border-radius: 3px; }
317
+ #${id} .devtools-btn:hover { background: var(--bg-hover); color: var(--text); }
318
+ #${id} .devtools-btn svg { width: 14px; height: 14px; }
319
+
320
+ /* Content Area */
321
+ #${id} .devtools-content { flex: 1; overflow: hidden; }
322
+ #${id} .devtools-pane { display: none; height: 100%; overflow: auto; padding: 8px; }
323
+ #${id} .devtools-pane.active { display: block; }
324
+
325
+ /* Performance Tab */
326
+ #${id} .perf-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-bottom: 12px; }
327
+ #${id} .perf-card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 4px; padding: 10px; text-align: center; }
328
+ #${id} .perf-card-value { font-size: 20px; font-weight: 600; font-family: 'SF Mono', Monaco, monospace; color: var(--success); }
329
+ #${id} .perf-card-label { font-size: 10px; color: var(--text-muted); margin-top: 4px; text-transform: uppercase; }
330
+ #${id} .perf-breakdown { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
331
+ #${id} .perf-row { display: flex; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border); }
332
+ #${id} .perf-row:last-child { border-bottom: none; }
333
+ #${id} .perf-row-label { flex: 1; font-size: 11px; color: var(--text-secondary); }
334
+ #${id} .perf-row-value { font-family: 'SF Mono', Monaco, monospace; font-size: 11px; min-width: 60px; text-align: right; }
335
+ #${id} .perf-row-bar { flex: 2; height: 4px; background: var(--bg-active); border-radius: 2px; margin: 0 12px; overflow: hidden; }
336
+ #${id} .perf-row-fill { height: 100%; border-radius: 2px; }
337
+ #${id} .perf-row-fill.lexer { background: ${c.info}; }
338
+ #${id} .perf-row-fill.parser { background: ${c.warning}; }
339
+ #${id} .perf-row-fill.render { background: ${c.success}; }
340
+
341
+ /* Context Tab - Tree View */
342
+ #${id} .tree { font-family: 'SF Mono', Monaco, Consolas, monospace; font-size: 11px; }
343
+ #${id} .tree-item { }
344
+ #${id} .tree-row { display: flex; align-items: center; padding: 2px 4px; cursor: default; border-radius: 2px; }
345
+ #${id} .tree-row:hover { background: var(--bg-hover); }
346
+ #${id} .tree-row.expandable { cursor: pointer; }
347
+ #${id} .tree-arrow { width: 12px; height: 12px; color: var(--text-muted); transition: transform 0.1s; flex-shrink: 0; }
348
+ #${id} .tree-item.open > .tree-row .tree-arrow { transform: rotate(90deg); }
349
+ #${id} .tree-key { color: var(--keyword); margin-right: 4px; }
350
+ #${id} .tree-colon { color: var(--text-muted); margin-right: 6px; }
351
+ #${id} .tree-value { color: var(--text); }
352
+ #${id} .tree-value.string { color: var(--string); }
353
+ #${id} .tree-value.number { color: var(--number); }
354
+ #${id} .tree-value.null { color: var(--text-muted); font-style: italic; }
355
+ #${id} .tree-type { color: var(--text-muted); margin-left: 6px; font-size: 10px; }
356
+ #${id} .tree-children { display: none; padding-left: 16px; }
357
+ #${id} .tree-item.open > .tree-children { display: block; }
358
+
359
+ /* Templates Tab */
360
+ #${id} .template-list { display: flex; flex-direction: column; gap: 4px; }
361
+ #${id} .template-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 4px; }
362
+ #${id} .template-icon { width: 14px; height: 14px; color: var(--text-muted); }
363
+ #${id} .template-name { font-family: 'SF Mono', Monaco, monospace; font-size: 11px; }
364
+ #${id} .template-badge { font-size: 9px; padding: 2px 6px; border-radius: 3px; text-transform: uppercase; font-weight: 500; }
365
+ #${id} .template-badge.root { background: rgba(0,120,212,0.15); color: var(--accent); }
366
+ #${id} .template-badge.extends { background: rgba(156,86,246,0.15); color: #9c56f6; }
367
+ #${id} .template-badge.include { background: rgba(78,201,176,0.15); color: var(--success); }
368
+
369
+ /* Queries Tab */
370
+ #${id} .queries-stats { display: flex; gap: 16px; padding: 8px 12px; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 4px; margin-bottom: 8px; }
371
+ #${id} .queries-stat { text-align: center; }
372
+ #${id} .queries-stat-value { font-size: 16px; font-weight: 600; font-family: 'SF Mono', Monaco, monospace; }
373
+ #${id} .queries-stat-value.warn { color: var(--warning); }
374
+ #${id} .queries-stat-value.error { color: var(--error); }
375
+ #${id} .queries-stat-label { font-size: 9px; color: var(--text-muted); text-transform: uppercase; }
376
+ #${id} .query-list { display: flex; flex-direction: column; gap: 4px; }
377
+ #${id} .query-item { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
378
+ #${id} .query-item.n1 { border-left: 3px solid var(--error); }
379
+ #${id} .query-item.slow { border-left: 3px solid var(--warning); }
380
+ #${id} .query-header { display: flex; align-items: center; gap: 8px; padding: 6px 10px; }
381
+ #${id} .query-sql { flex: 1; font-family: 'SF Mono', Monaco, monospace; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
382
+ #${id} .query-meta { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
383
+ #${id} .query-badge { font-size: 9px; padding: 2px 5px; border-radius: 3px; font-weight: 600; }
384
+ #${id} .query-badge.n1 { background: rgba(241,76,76,0.15); color: var(--error); }
385
+ #${id} .query-source { font-size: 9px; padding: 2px 5px; border-radius: 3px; background: var(--bg-active); color: var(--text-muted); text-transform: uppercase; }
386
+ #${id} .query-time { font-family: 'SF Mono', Monaco, monospace; font-size: 10px; color: var(--text-secondary); }
387
+ #${id} .query-time.slow { color: var(--warning); }
388
+ #${id} .query-rows { font-size: 10px; color: var(--text-muted); }
389
+
390
+ /* Filters Tab */
391
+ #${id} .filter-grid { display: flex; flex-wrap: wrap; gap: 6px; }
392
+ #${id} .filter-chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 4px; font-family: 'SF Mono', Monaco, monospace; font-size: 11px; }
393
+ #${id} .filter-count { color: var(--accent); font-weight: 600; font-size: 10px; }
394
+
395
+ /* Cache Tab */
396
+ #${id} .cache-stats { display: flex; gap: 20px; }
397
+ #${id} .cache-stat { flex: 1; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 4px; padding: 16px; text-align: center; }
398
+ #${id} .cache-value { font-size: 32px; font-weight: 600; font-family: 'SF Mono', Monaco, monospace; }
399
+ #${id} .cache-value.hit { color: var(--success); }
400
+ #${id} .cache-value.miss { color: var(--error); }
401
+ #${id} .cache-label { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
402
+
403
+ /* Warnings Tab */
404
+ #${id} .warning-list { display: flex; flex-direction: column; gap: 6px; }
405
+ #${id} .warning-item { display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px; background: rgba(241,76,76,0.08); border: 1px solid rgba(241,76,76,0.2); border-radius: 4px; }
406
+ #${id} .warning-icon { color: var(--error); flex-shrink: 0; width: 14px; height: 14px; }
407
+ #${id} .warning-text { font-size: 11px; color: var(--text); }
408
+
409
+ /* Empty State */
410
+ #${id} .empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); font-size: 12px; }
411
+ #${id} .empty-state svg { width: 32px; height: 32px; margin-bottom: 8px; opacity: 0.5; }
318
412
  `;
319
413
  }
320
- function getPosition(pos) {
321
- switch (pos) {
322
- case "bottom-left":
323
- return "bottom: 16px; left: 16px;";
324
- case "top-right":
325
- return "top: 16px; right: 16px;";
326
- case "top-left":
327
- return "top: 16px; left: 16px;";
328
- default:
329
- return "bottom: 16px; right: 16px;";
330
- }
331
- }
332
414
  var icons = {
333
415
  logo: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2L2 7l10 5 10-5-10-5z"/><path d="M2 17l10 5 10-5"/><path d="M2 12l10 5 10-5"/></svg>`,
334
416
  close: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 6L6 18M6 6l12 12"/></svg>`,
335
- chevron: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 18l6-6-6-6"/></svg>`,
417
+ minimize: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M5 12h14"/></svg>`,
418
+ dock: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M3 15h18"/></svg>`,
419
+ dockRight: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M15 3v18"/></svg>`,
420
+ popup: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M9 3v6h6"/></svg>`,
421
+ arrow: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 18l6-6-6-6"/></svg>`,
336
422
  perf: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"/></svg>`,
337
- template: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><path d="M14 2v6h6"/></svg>`,
338
423
  context: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 16V8a2 2 0 00-1-1.73l-7-4a2 2 0 00-2 0l-7 4A2 2 0 003 8v8a2 2 0 001 1.73l7 4a2 2 0 002 0l7-4A2 2 0 0021 16z"/></svg>`,
424
+ template: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><path d="M14 2v6h6"/></svg>`,
339
425
  filter: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"/></svg>`,
426
+ database: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"/><path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"/></svg>`,
340
427
  cache: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2a10 10 0 1010 10H12V2z"/><path d="M12 2a10 10 0 00-8.66 15"/></svg>`,
341
- warning: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>`,
342
- file: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M13 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V9z"/></svg>`
428
+ warning: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>`
343
429
  };
344
- function generateToggle(id, data, c) {
430
+ function generateHTML(id, data, c, opts) {
345
431
  const time = (data.totalTime || 0).toFixed(1);
432
+ const queryCount = data.queries?.length || 0;
433
+ const hasWarnings = data.warnings.length > 0 || data.queryStats?.n1Count > 0;
434
+ const tabs = [
435
+ { id: "perf", icon: icons.perf, label: "Performance", count: `${time}ms` },
436
+ { id: "context", icon: icons.context, label: "Context", count: Object.keys(data.contextSnapshot).length || null },
437
+ { id: "templates", icon: icons.template, label: "Templates", count: data.templateChain.length || null },
438
+ { id: "filters", icon: icons.filter, label: "Filters", count: data.filtersUsed.size || null },
439
+ { id: "queries", icon: icons.database, label: "Queries", count: queryCount || null, warn: data.queryStats?.n1Count > 0 },
440
+ { id: "cache", icon: icons.cache, label: "Cache", count: data.cacheHits + data.cacheMisses || null },
441
+ { id: "warnings", icon: icons.warning, label: "Warnings", count: data.warnings.length || null, warn: hasWarnings }
442
+ ];
443
+ const tabsHtml = tabs.map((t, i) => {
444
+ const countHtml = t.count !== null ? `<span class="count${t.warn ? " warn" : ""}">${t.count}</span>` : "";
445
+ return `<button class="devtools-tab${i === 0 ? " active" : ""}" data-tab="${t.id}">${t.icon}${t.label}${countHtml}</button>`;
446
+ }).join("");
346
447
  return `
347
- <button class="dbg-toggle" onclick="document.querySelector('#${id} .dbg-panel').classList.add('open');this.style.display='none'">
448
+ <button class="devtools-toggle" onclick="document.getElementById('${id}').dataset.open='true'">
348
449
  ${icons.logo}
349
450
  <span>Binja</span>
350
- <span class="dbg-time">${time}ms</span>
351
- </button>`;
352
- }
353
- function generatePanel(id, data, c, opts) {
354
- const time = (data.totalTime || 0).toFixed(2);
355
- const mode = data.mode === "aot" ? "AOT" : "Runtime";
356
- return `
357
- <div class="dbg-panel">
358
- <div class="dbg-header">
359
- <div class="dbg-logo">${icons.logo} Binja Debugger</div>
360
- <div class="dbg-meta">
361
- <span class="dbg-badge mode">${mode}</span>
362
- <span class="dbg-badge time">${time}ms</span>
363
- <button class="dbg-close" onclick="document.querySelector('#${id} .dbg-panel').classList.remove('open');document.querySelector('#${id} .dbg-toggle').style.display='inline-flex'">${icons.close}</button>
451
+ <span class="badge">${time}ms</span>
452
+ </button>
453
+
454
+ <div class="devtools-panel">
455
+ <div class="devtools-resize"></div>
456
+ <div class="devtools-toolbar">
457
+ <div class="devtools-tabs">${tabsHtml}</div>
458
+ <div class="devtools-actions">
459
+ <button class="devtools-btn" title="Dock to bottom" data-dock="bottom">${icons.dock}</button>
460
+ <button class="devtools-btn" title="Dock to right" data-dock="right">${icons.dockRight}</button>
461
+ <button class="devtools-btn" title="Popup" data-dock="popup">${icons.popup}</button>
462
+ <button class="devtools-btn" title="Close" onclick="document.getElementById('${id}').dataset.open='false'">${icons.close}</button>
364
463
  </div>
365
464
  </div>
366
- <div class="dbg-body">
367
- ${generatePerfSection(data)}
368
- ${generateTemplatesSection(data)}
369
- ${generateContextSection(data)}
370
- ${generateFiltersSection(data)}
371
- ${generateCacheSection(data)}
372
- ${generateWarningsSection(data)}
465
+ <div class="devtools-content">
466
+ ${generatePerfPane(data)}
467
+ ${generateContextPane(data)}
468
+ ${generateTemplatesPane(data)}
469
+ ${generateFiltersPane(data)}
470
+ ${generateQueriesPane(data)}
471
+ ${generateCachePane(data)}
472
+ ${generateWarningsPane(data)}
373
473
  </div>
374
474
  </div>`;
375
475
  }
376
- function generatePerfSection(data) {
476
+ function generatePerfPane(data) {
377
477
  const total = data.totalTime || 0.01;
378
478
  const lexer = data.lexerTime || 0;
379
479
  const parser = data.parserTime || 0;
380
480
  const render = data.renderTime || 0;
481
+ const mode = data.mode === "aot" ? "AOT" : "Runtime";
381
482
  return `
382
- <div class="dbg-section open">
383
- <div class="dbg-section-header" onclick="this.parentElement.classList.toggle('open')">
384
- <span class="dbg-section-title">${icons.perf} Performance</span>
385
- <span class="dbg-chevron">${icons.chevron}</span>
386
- </div>
387
- <div class="dbg-section-content">
388
- <div class="dbg-row">
389
- <span class="dbg-label">Lexer</span>
390
- <span class="dbg-value">${lexer.toFixed(2)}ms</span>
483
+ <div class="devtools-pane active" data-pane="perf">
484
+ <div class="perf-grid">
485
+ <div class="perf-card">
486
+ <div class="perf-card-value">${total.toFixed(2)}ms</div>
487
+ <div class="perf-card-label">Total Time</div>
391
488
  </div>
392
- <div class="dbg-bar"><div class="dbg-bar-fill lexer" style="width:${lexer / total * 100}%"></div></div>
393
- <div class="dbg-row">
394
- <span class="dbg-label">Parser</span>
395
- <span class="dbg-value">${parser.toFixed(2)}ms</span>
489
+ <div class="perf-card">
490
+ <div class="perf-card-value" style="color:var(--accent)">${mode}</div>
491
+ <div class="perf-card-label">Mode</div>
396
492
  </div>
397
- <div class="dbg-bar"><div class="dbg-bar-fill parser" style="width:${parser / total * 100}%"></div></div>
398
- <div class="dbg-row">
399
- <span class="dbg-label">Render</span>
400
- <span class="dbg-value">${render.toFixed(2)}ms</span>
493
+ <div class="perf-card">
494
+ <div class="perf-card-value">${data.templateChain.length}</div>
495
+ <div class="perf-card-label">Templates</div>
401
496
  </div>
402
- <div class="dbg-bar"><div class="dbg-bar-fill render" style="width:${render / total * 100}%"></div></div>
403
- <div class="dbg-row" style="margin-top:8px;padding-top:8px;border-top:1px solid rgba(255,255,255,0.1)">
404
- <span class="dbg-label" style="font-weight:600">Total</span>
405
- <span class="dbg-value" style="font-weight:600">${total.toFixed(2)}ms</span>
497
+ <div class="perf-card">
498
+ <div class="perf-card-value">${data.queries?.length || 0}</div>
499
+ <div class="perf-card-label">Queries</div>
406
500
  </div>
407
501
  </div>
408
- </div>`;
409
- }
410
- function generateTemplatesSection(data) {
411
- if (data.templateChain.length === 0)
412
- return "";
413
- const templates = data.templateChain.map((t) => `
414
- <div class="dbg-template">
415
- ${icons.file}
416
- <span class="dbg-template-name">${t.name}</span>
417
- <span class="dbg-template-tag ${t.type}">${t.type}</span>
502
+ <div class="perf-breakdown">
503
+ <div class="perf-row">
504
+ <span class="perf-row-label">Lexer</span>
505
+ <div class="perf-row-bar"><div class="perf-row-fill lexer" style="width:${lexer / total * 100}%"></div></div>
506
+ <span class="perf-row-value">${lexer.toFixed(2)}ms</span>
507
+ </div>
508
+ <div class="perf-row">
509
+ <span class="perf-row-label">Parser</span>
510
+ <div class="perf-row-bar"><div class="perf-row-fill parser" style="width:${parser / total * 100}%"></div></div>
511
+ <span class="perf-row-value">${parser.toFixed(2)}ms</span>
512
+ </div>
513
+ <div class="perf-row">
514
+ <span class="perf-row-label">Render</span>
515
+ <div class="perf-row-bar"><div class="perf-row-fill render" style="width:${render / total * 100}%"></div></div>
516
+ <span class="perf-row-value">${render.toFixed(2)}ms</span>
418
517
  </div>
419
- `).join("");
420
- return `
421
- <div class="dbg-section">
422
- <div class="dbg-section-header" onclick="this.parentElement.classList.toggle('open')">
423
- <span class="dbg-section-title">${icons.template} Templates</span>
424
- <span class="dbg-section-meta">${data.templateChain.length}</span>
425
- <span class="dbg-chevron">${icons.chevron}</span>
426
- </div>
427
- <div class="dbg-section-content">
428
- <div class="dbg-templates">${templates}</div>
429
518
  </div>
430
519
  </div>`;
431
520
  }
432
- function generateContextSection(data) {
521
+ function generateContextPane(data) {
433
522
  const keys = Object.keys(data.contextSnapshot);
434
- if (keys.length === 0)
435
- return "";
436
- const items = keys.map((key) => renderContextValue(key, data.contextSnapshot[key])).join("");
523
+ if (keys.length === 0) {
524
+ return `<div class="devtools-pane" data-pane="context"><div class="empty-state">${icons.context}<span>No context variables</span></div></div>`;
525
+ }
526
+ const items = keys.map((key) => renderTreeItem(key, data.contextSnapshot[key])).join("");
527
+ return `<div class="devtools-pane" data-pane="context"><div class="tree">${items}</div></div>`;
528
+ }
529
+ function renderTreeItem(key, ctx) {
530
+ const hasChildren = ctx.expandable && ctx.children && Object.keys(ctx.children).length > 0;
531
+ const arrowHtml = hasChildren ? `<span class="tree-arrow">${icons.arrow}</span>` : '<span class="tree-arrow" style="visibility:hidden">${icons.arrow}</span>';
532
+ const expandableClass = hasChildren ? "expandable" : "";
533
+ const valueClass = getValueClass(ctx.type);
534
+ let childrenHtml = "";
535
+ if (hasChildren && ctx.children) {
536
+ childrenHtml = `<div class="tree-children">${Object.entries(ctx.children).map(([k, v]) => renderTreeItem(k, v)).join("")}</div>`;
537
+ }
437
538
  return `
438
- <div class="dbg-section">
439
- <div class="dbg-section-header" onclick="this.parentElement.classList.toggle('open')">
440
- <span class="dbg-section-title">${icons.context} Context</span>
441
- <span class="dbg-section-meta">${keys.length} vars</span>
442
- <span class="dbg-chevron">${icons.chevron}</span>
443
- </div>
444
- <div class="dbg-section-content">
445
- <div class="dbg-ctx-grid">${items}</div>
539
+ <div class="tree-item">
540
+ <div class="tree-row ${expandableClass}">
541
+ ${arrowHtml}
542
+ <span class="tree-key">${escapeHtml(key)}</span>
543
+ <span class="tree-colon">:</span>
544
+ <span class="tree-value ${valueClass}">${escapeHtml(ctx.preview)}</span>
545
+ <span class="tree-type">${ctx.type}</span>
446
546
  </div>
547
+ ${childrenHtml}
447
548
  </div>`;
448
549
  }
449
- function renderContextValue(key, ctx) {
450
- const arrow = ctx.expandable ? `<svg class="dbg-ctx-arrow" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 18l6-6-6-6"/></svg>` : "";
451
- const expandableClass = ctx.expandable ? "expandable" : "";
452
- const onClick = ctx.expandable ? `onclick="this.parentElement.classList.toggle('open')"` : "";
453
- let children = "";
454
- if (ctx.expandable && ctx.children) {
455
- const childItems = Object.entries(ctx.children).map(([k, v]) => renderContextValue(k, v)).join("");
456
- children = `<div class="dbg-ctx-children">${childItems}</div>`;
550
+ function getValueClass(type) {
551
+ if (type === "string")
552
+ return "string";
553
+ if (type === "number" || type === "integer" || type === "float")
554
+ return "number";
555
+ if (type === "null" || type === "undefined")
556
+ return "null";
557
+ return "";
558
+ }
559
+ function generateTemplatesPane(data) {
560
+ if (data.templateChain.length === 0) {
561
+ return `<div class="devtools-pane" data-pane="templates"><div class="empty-state">${icons.template}<span>No templates loaded</span></div></div>`;
457
562
  }
458
- return `
459
- <div class="dbg-ctx-item">
460
- <div class="dbg-ctx-row ${expandableClass}" ${onClick}>
461
- <div class="dbg-ctx-key">
462
- ${arrow}
463
- <span class="dbg-ctx-name">${escapeHtml(key)}</span>
464
- <span class="dbg-ctx-type">${ctx.type}</span>
465
- </div>
466
- <span class="dbg-ctx-preview">${escapeHtml(ctx.preview)}</span>
563
+ const items = data.templateChain.map((t) => `
564
+ <div class="template-item">
565
+ <span class="template-icon">${icons.template}</span>
566
+ <span class="template-name">${escapeHtml(t.name)}</span>
567
+ <span class="template-badge ${t.type}">${t.type}</span>
467
568
  </div>
468
- ${children}
469
- </div>`;
569
+ `).join("");
570
+ return `<div class="devtools-pane" data-pane="templates"><div class="template-list">${items}</div></div>`;
470
571
  }
471
- function generateFiltersSection(data) {
572
+ function generateFiltersPane(data) {
472
573
  const filters = Array.from(data.filtersUsed.entries());
473
- if (filters.length === 0)
474
- return "";
475
- const items = filters.map(([name, count]) => `<span class="dbg-filter">${name}<span class="dbg-filter-count">\xD7${count}</span></span>`).join("");
476
- return `
477
- <div class="dbg-section">
478
- <div class="dbg-section-header" onclick="this.parentElement.classList.toggle('open')">
479
- <span class="dbg-section-title">${icons.filter} Filters</span>
480
- <span class="dbg-section-meta">${filters.length}</span>
481
- <span class="dbg-chevron">${icons.chevron}</span>
482
- </div>
483
- <div class="dbg-section-content">
484
- <div class="dbg-filters">${items}</div>
485
- </div>
486
- </div>`;
574
+ if (filters.length === 0) {
575
+ return `<div class="devtools-pane" data-pane="filters"><div class="empty-state">${icons.filter}<span>No filters used</span></div></div>`;
576
+ }
577
+ const items = filters.map(([name, count]) => `
578
+ <span class="filter-chip">${escapeHtml(name)}<span class="filter-count">\xD7${count}</span></span>
579
+ `).join("");
580
+ return `<div class="devtools-pane" data-pane="filters"><div class="filter-grid">${items}</div></div>`;
487
581
  }
488
- function generateCacheSection(data) {
489
- const total = data.cacheHits + data.cacheMisses;
490
- if (total === 0)
491
- return "";
492
- return `
493
- <div class="dbg-section">
494
- <div class="dbg-section-header" onclick="this.parentElement.classList.toggle('open')">
495
- <span class="dbg-section-title">${icons.cache} Cache</span>
496
- <span class="dbg-section-meta">${(data.cacheHits / total * 100).toFixed(0)}% hit</span>
497
- <span class="dbg-chevron">${icons.chevron}</span>
498
- </div>
499
- <div class="dbg-section-content">
500
- <div class="dbg-cache">
501
- <div class="dbg-cache-stat">
502
- <div class="dbg-cache-num hit">${data.cacheHits}</div>
503
- <div class="dbg-cache-label">Cache Hits</div>
582
+ function generateQueriesPane(data) {
583
+ if (!data.queries || data.queries.length === 0) {
584
+ return `<div class="devtools-pane" data-pane="queries"><div class="empty-state">${icons.database}<span>No queries recorded</span></div></div>`;
585
+ }
586
+ const stats = data.queryStats;
587
+ const statsHtml = `
588
+ <div class="queries-stats">
589
+ <div class="queries-stat">
590
+ <div class="queries-stat-value">${stats.count}</div>
591
+ <div class="queries-stat-label">Queries</div>
592
+ </div>
593
+ <div class="queries-stat">
594
+ <div class="queries-stat-value">${stats.totalDuration.toFixed(1)}ms</div>
595
+ <div class="queries-stat-label">Total</div>
596
+ </div>
597
+ <div class="queries-stat">
598
+ <div class="queries-stat-value ${stats.slowCount > 0 ? "warn" : ""}">${stats.slowCount}</div>
599
+ <div class="queries-stat-label">Slow</div>
504
600
  </div>
505
- <div class="dbg-cache-stat">
506
- <div class="dbg-cache-num miss">${data.cacheMisses}</div>
507
- <div class="dbg-cache-label">Cache Misses</div>
601
+ <div class="queries-stat">
602
+ <div class="queries-stat-value ${stats.n1Count > 0 ? "error" : ""}">${stats.n1Count}</div>
603
+ <div class="queries-stat-label">N+1</div>
508
604
  </div>
605
+ </div>`;
606
+ const queries = data.queries.map((q) => {
607
+ const isSlow = q.duration > 100;
608
+ const classes = ["query-item", q.isN1 ? "n1" : "", isSlow ? "slow" : ""].filter(Boolean).join(" ");
609
+ const badge = q.isN1 ? '<span class="query-badge n1">N+1</span>' : "";
610
+ const source = q.source ? `<span class="query-source">${escapeHtml(q.source)}</span>` : "";
611
+ const rows = q.rows !== undefined ? `<span class="query-rows">${q.rows} rows</span>` : "";
612
+ return `
613
+ <div class="${classes}">
614
+ <div class="query-header">
615
+ <span class="query-sql" title="${escapeHtml(q.sql)}">${escapeHtml(q.sql)}</span>
616
+ <div class="query-meta">
617
+ ${badge}${source}${rows}
618
+ <span class="query-time ${isSlow ? "slow" : ""}">${q.duration.toFixed(1)}ms</span>
619
+ </div>
620
+ </div>
621
+ </div>`;
622
+ }).join("");
623
+ return `<div class="devtools-pane" data-pane="queries">${statsHtml}<div class="query-list">${queries}</div></div>`;
624
+ }
625
+ function generateCachePane(data) {
626
+ const total = data.cacheHits + data.cacheMisses;
627
+ if (total === 0) {
628
+ return `<div class="devtools-pane" data-pane="cache"><div class="empty-state">${icons.cache}<span>No cache activity</span></div></div>`;
629
+ }
630
+ const hitRate = (data.cacheHits / total * 100).toFixed(0);
631
+ return `
632
+ <div class="devtools-pane" data-pane="cache">
633
+ <div class="cache-stats">
634
+ <div class="cache-stat">
635
+ <div class="cache-value hit">${data.cacheHits}</div>
636
+ <div class="cache-label">Cache Hits</div>
637
+ </div>
638
+ <div class="cache-stat">
639
+ <div class="cache-value miss">${data.cacheMisses}</div>
640
+ <div class="cache-label">Cache Misses</div>
641
+ </div>
642
+ <div class="cache-stat">
643
+ <div class="cache-value">${hitRate}%</div>
644
+ <div class="cache-label">Hit Rate</div>
509
645
  </div>
510
646
  </div>
511
647
  </div>`;
512
648
  }
513
- function generateWarningsSection(data) {
514
- if (data.warnings.length === 0)
515
- return "";
649
+ function generateWarningsPane(data) {
650
+ if (data.warnings.length === 0) {
651
+ return `<div class="devtools-pane" data-pane="warnings"><div class="empty-state">${icons.warning}<span>No warnings</span></div></div>`;
652
+ }
516
653
  const items = data.warnings.map((w) => `
517
- <div class="dbg-warning">
518
- ${icons.warning}
519
- <span class="dbg-warning-text">${escapeHtml(w)}</span>
654
+ <div class="warning-item">
655
+ <span class="warning-icon">${icons.warning}</span>
656
+ <span class="warning-text">${escapeHtml(w)}</span>
520
657
  </div>
521
658
  `).join("");
522
- return `
523
- <div class="dbg-section open">
524
- <div class="dbg-section-header" onclick="this.parentElement.classList.toggle('open')">
525
- <span class="dbg-section-title">${icons.warning} Warnings</span>
526
- <span class="dbg-section-meta" style="color:#eab308">${data.warnings.length}</span>
527
- <span class="dbg-chevron">${icons.chevron}</span>
528
- </div>
529
- <div class="dbg-section-content">
530
- <div class="dbg-warnings">${items}</div>
531
- </div>
532
- </div>`;
659
+ return `<div class="devtools-pane" data-pane="warnings"><div class="warning-list">${items}</div></div>`;
533
660
  }
534
- function generateScript(id) {
661
+ function generateScript(id, data, opts) {
535
662
  return `
536
- (function(){
537
- var panel = document.getElementById('${id}');
538
- if (!panel) return;
539
- var header = panel.querySelector('.dbg-header');
540
- if (!header) return;
541
- var isDrag = false, startX, startY, startL, startT;
542
- header.style.cursor = 'grab';
543
- header.onmousedown = function(e) {
544
- if (e.target.closest('.dbg-close')) return;
545
- isDrag = true;
546
- header.style.cursor = 'grabbing';
547
- startX = e.clientX;
548
- startY = e.clientY;
549
- var r = panel.getBoundingClientRect();
550
- startL = r.left;
551
- startT = r.top;
552
- panel.style.right = 'auto';
553
- panel.style.bottom = 'auto';
554
- panel.style.left = startL + 'px';
555
- panel.style.top = startT + 'px';
663
+ (function() {
664
+ var root = document.getElementById('${id}');
665
+ if (!root) return;
666
+
667
+ // Tab switching
668
+ root.querySelectorAll('.devtools-tab').forEach(function(tab) {
669
+ tab.addEventListener('click', function() {
670
+ root.querySelectorAll('.devtools-tab').forEach(function(t) { t.classList.remove('active'); });
671
+ root.querySelectorAll('.devtools-pane').forEach(function(p) { p.classList.remove('active'); });
672
+ tab.classList.add('active');
673
+ var pane = root.querySelector('[data-pane="' + tab.dataset.tab + '"]');
674
+ if (pane) pane.classList.add('active');
675
+ });
676
+ });
677
+
678
+ // Tree expand/collapse
679
+ root.querySelectorAll('.tree-row.expandable').forEach(function(row) {
680
+ row.addEventListener('click', function() {
681
+ row.parentElement.classList.toggle('open');
682
+ });
683
+ });
684
+
685
+ // Dock position switching
686
+ root.querySelectorAll('[data-dock]').forEach(function(btn) {
687
+ btn.addEventListener('click', function() {
688
+ root.dataset.position = btn.dataset.dock;
689
+ });
690
+ });
691
+
692
+ // Resize functionality
693
+ var resize = root.querySelector('.devtools-resize');
694
+ var panel = root.querySelector('.devtools-panel');
695
+ if (resize && panel) {
696
+ var isResizing = false;
697
+ var startY, startX, startHeight, startWidth;
698
+
699
+ resize.addEventListener('mousedown', function(e) {
700
+ isResizing = true;
701
+ startY = e.clientY;
702
+ startX = e.clientX;
703
+ startHeight = panel.offsetHeight;
704
+ startWidth = panel.offsetWidth;
705
+ document.body.style.cursor = root.dataset.position === 'right' ? 'ew-resize' : 'ns-resize';
706
+ e.preventDefault();
707
+ });
708
+
709
+ document.addEventListener('mousemove', function(e) {
710
+ if (!isResizing) return;
711
+ if (root.dataset.position === 'bottom') {
712
+ var newHeight = startHeight - (e.clientY - startY);
713
+ if (newHeight > 100 && newHeight < window.innerHeight * 0.8) {
714
+ panel.style.height = newHeight + 'px';
715
+ }
716
+ } else if (root.dataset.position === 'right') {
717
+ var newWidth = startWidth - (e.clientX - startX);
718
+ if (newWidth > 200 && newWidth < window.innerWidth * 0.6) {
719
+ panel.style.width = newWidth + 'px';
720
+ }
721
+ }
722
+ });
723
+
724
+ document.addEventListener('mouseup', function() {
725
+ isResizing = false;
726
+ document.body.style.cursor = '';
727
+ });
728
+ }
729
+ })();`;
730
+ }
731
+ function escapeHtml(str) {
732
+ return String(str).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
733
+ }
734
+ // src/debug/integrations.ts
735
+ function recordQuery(query) {
736
+ const collector = getDebugCollector();
737
+ if (collector) {
738
+ collector.recordQuery(query);
739
+ }
740
+ }
741
+ function createPrismaMiddleware() {
742
+ return async (params, next) => {
743
+ const collector = getDebugCollector();
744
+ const start = performance.now();
745
+ const result = await next(params);
746
+ const duration = performance.now() - start;
747
+ if (collector) {
748
+ const sql = `${params.action} ${params.model}`;
749
+ collector.recordQuery({
750
+ sql,
751
+ params: params.args ? [JSON.stringify(params.args)] : undefined,
752
+ duration,
753
+ rows: Array.isArray(result) ? result.length : result ? 1 : 0,
754
+ source: "prisma"
755
+ });
756
+ }
757
+ return result;
556
758
  };
557
- document.onmousemove = function(e) {
558
- if (!isDrag) return;
559
- panel.style.left = (startL + e.clientX - startX) + 'px';
560
- panel.style.top = (startT + e.clientY - startY) + 'px';
759
+ }
760
+ function setupPrismaLogging(prisma) {
761
+ prisma.$on("query", (e) => {
762
+ const collector = getDebugCollector();
763
+ if (collector) {
764
+ collector.recordQuery({
765
+ sql: e.query,
766
+ params: e.params ? JSON.parse(e.params) : undefined,
767
+ duration: e.duration,
768
+ source: "prisma"
769
+ });
770
+ }
771
+ });
772
+ }
773
+ function createDrizzleLogger() {
774
+ return {
775
+ logQuery(query, params) {
776
+ const collector = getDebugCollector();
777
+ if (collector) {
778
+ collector.recordQuery({
779
+ sql: query,
780
+ params,
781
+ duration: 0,
782
+ source: "drizzle"
783
+ });
784
+ }
785
+ }
561
786
  };
562
- document.onmouseup = function() {
563
- isDrag = false;
564
- header.style.cursor = 'grab';
787
+ }
788
+ async function wrapDrizzleQuery(query, sql) {
789
+ const collector = getDebugCollector();
790
+ const start = performance.now();
791
+ const result = await query;
792
+ const duration = performance.now() - start;
793
+ if (collector) {
794
+ collector.recordQuery({
795
+ sql: sql || "Drizzle Query",
796
+ duration,
797
+ rows: Array.isArray(result) ? result.length : result ? 1 : 0,
798
+ source: "drizzle"
799
+ });
800
+ }
801
+ return result;
802
+ }
803
+ function wrapBunSQL(db) {
804
+ const handler = {
805
+ get(target, prop) {
806
+ const value = target[prop];
807
+ if (typeof value === "function") {
808
+ if (prop === "query" || prop === "run" || prop === "prepare") {
809
+ return function(...args) {
810
+ const collector = getDebugCollector();
811
+ const sql = typeof args[0] === "string" ? args[0] : "SQL Query";
812
+ const start = performance.now();
813
+ const result = value.apply(target, args);
814
+ if (result && typeof result.all === "function") {
815
+ return wrapPreparedStatement(result, sql);
816
+ }
817
+ const duration = performance.now() - start;
818
+ if (collector) {
819
+ collector.recordQuery({
820
+ sql,
821
+ params: args.slice(1),
822
+ duration,
823
+ rows: Array.isArray(result) ? result.length : undefined,
824
+ source: "bun:sqlite"
825
+ });
826
+ }
827
+ return result;
828
+ };
829
+ }
830
+ }
831
+ return value;
832
+ }
565
833
  };
566
- })();`;
834
+ return new Proxy(db, handler);
567
835
  }
568
- function escapeHtml(str) {
569
- return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
836
+ function wrapPreparedStatement(stmt, sql) {
837
+ const handler = {
838
+ get(target, prop) {
839
+ const value = target[prop];
840
+ if (typeof value === "function" && (prop === "all" || prop === "get" || prop === "run")) {
841
+ return function(...args) {
842
+ const collector = getDebugCollector();
843
+ const start = performance.now();
844
+ const result = value.apply(target, args);
845
+ const duration = performance.now() - start;
846
+ if (collector) {
847
+ collector.recordQuery({
848
+ sql,
849
+ params: args,
850
+ duration,
851
+ rows: Array.isArray(result) ? result.length : result ? 1 : 0,
852
+ source: "bun:sqlite"
853
+ });
854
+ }
855
+ return result;
856
+ };
857
+ }
858
+ return value;
859
+ }
860
+ };
861
+ return new Proxy(stmt, handler);
862
+ }
863
+ async function wrapQuery(sql, queryFn, source = "sql") {
864
+ const collector = getDebugCollector();
865
+ const start = performance.now();
866
+ const result = await queryFn();
867
+ const duration = performance.now() - start;
868
+ if (collector) {
869
+ collector.recordQuery({
870
+ sql,
871
+ duration,
872
+ rows: Array.isArray(result) ? result.length : result ? 1 : 0,
873
+ source
874
+ });
875
+ }
876
+ return result;
877
+ }
878
+ function createQueryWrapper(source) {
879
+ return (sql, queryFn) => {
880
+ return wrapQuery(sql, queryFn, source);
881
+ };
570
882
  }
571
883
 
572
884
  // src/debug/index.ts
@@ -666,13 +978,21 @@ function debugMiddleware(env, options = {}) {
666
978
  };
667
979
  }
668
980
  export {
981
+ wrapQuery,
982
+ wrapDrizzleQuery,
983
+ wrapBunSQL,
669
984
  startDebugCollection,
985
+ setupPrismaLogging,
670
986
  renderWithDebug,
671
987
  renderStringWithDebug,
988
+ recordQuery,
672
989
  getDebugCollector,
673
990
  generateDebugPanel,
674
991
  endDebugCollection,
675
992
  debugMiddleware,
993
+ createQueryWrapper,
994
+ createPrismaMiddleware,
995
+ createDrizzleLogger,
676
996
  createDebugRenderer,
677
997
  DebugCollector
678
998
  };