lobsterboard 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1195 @@
1
+ /*!
2
+ * LobsterBoard v0.1.0
3
+ * Dashboard builder with customizable widgets
4
+ * https://github.com/curbob/LobsterBoard
5
+ * @license MIT
6
+ */
7
+ /**
8
+ * LobsterBoard - Widget Definitions
9
+ * Each widget defines its default size, properties, and generated code
10
+ *
11
+ * @module lobsterboard/widgets
12
+ */
13
+
14
+ const WIDGETS = {
15
+ // ─────────────────────────────────────────────
16
+ // SMALL CARDS (KPI style)
17
+ // ─────────────────────────────────────────────
18
+
19
+ 'weather': {
20
+ name: 'Local Weather',
21
+ icon: '🌡️',
22
+ category: 'small',
23
+ description: 'Shows current weather for a single location using wttr.in (no API key needed).',
24
+ defaultWidth: 200,
25
+ defaultHeight: 120,
26
+ hasApiKey: false,
27
+ properties: {
28
+ title: 'Local Weather',
29
+ location: 'Atlanta',
30
+ units: 'F',
31
+ refreshInterval: 600
32
+ },
33
+ preview: `<div style="text-align:center;padding:8px;">
34
+ <div style="font-size:24px;">72°F</div>
35
+ <div style="font-size:11px;color:#8b949e;">Atlanta</div>
36
+ </div>`,
37
+ generateHtml: (props) => `
38
+ <div class="dash-card" id="widget-${props.id}" style="height:100%;">
39
+ <div class="dash-card-head">
40
+ <span class="dash-card-title">🌡️ ${props.title || 'Local Weather'}</span>
41
+ </div>
42
+ <div class="dash-card-body" style="display:flex;align-items:center;justify-content:center;gap:10px;">
43
+ <span id="${props.id}-icon" style="font-size:24px;">🌡️</span>
44
+ <div>
45
+ <div class="kpi-value blue" id="${props.id}-value">—</div>
46
+ <div class="kpi-label" id="${props.id}-label">${props.location || 'Location'}</div>
47
+ </div>
48
+ </div>
49
+ </div>`,
50
+ generateJs: (props) => `
51
+ // Weather Widget: ${props.id} (uses free wttr.in API - no key needed)
52
+ async function update_${props.id.replace(/-/g, '_')}() {
53
+ try {
54
+ const location = encodeURIComponent('${props.location || 'Atlanta'}');
55
+ const res = await fetch('https://wttr.in/' + location + '?format=j1');
56
+ const data = await res.json();
57
+ const current = data.current_condition[0];
58
+ const temp = '${props.units}' === 'C' ? current.temp_C : current.temp_F;
59
+ const unit = '${props.units}' === 'C' ? '°C' : '°F';
60
+ document.getElementById('${props.id}-value').textContent = temp + unit;
61
+ document.getElementById('${props.id}-label').textContent = current.weatherDesc[0].value;
62
+ const code = parseInt(current.weatherCode);
63
+ let icon = '🌡️';
64
+ if (code === 113) icon = '☀️';
65
+ else if (code === 116 || code === 119) icon = '⛅';
66
+ else if (code >= 176 && code <= 359) icon = '🌧️';
67
+ else if (code >= 368 && code <= 395) icon = '❄️';
68
+ document.getElementById('${props.id}-icon').textContent = icon;
69
+ } catch (e) {
70
+ console.error('Weather widget error:', e);
71
+ document.getElementById('${props.id}-value').textContent = '—';
72
+ }
73
+ }
74
+ update_${props.id.replace(/-/g, '_')}();
75
+ setInterval(update_${props.id.replace(/-/g, '_')}, ${(props.refreshInterval || 600) * 1000});
76
+ `
77
+ },
78
+
79
+ 'clock': {
80
+ name: 'Clock',
81
+ icon: '🕐',
82
+ category: 'small',
83
+ description: 'Simple digital clock. Supports 12h or 24h format.',
84
+ defaultWidth: 200,
85
+ defaultHeight: 120,
86
+ hasApiKey: false,
87
+ properties: {
88
+ title: 'Clock',
89
+ timezone: 'local',
90
+ format24h: false
91
+ },
92
+ preview: `<div style="text-align:center;padding:8px;">
93
+ <div style="font-size:24px;">3:45 PM</div>
94
+ <div style="font-size:11px;color:#8b949e;">Wed, Feb 5</div>
95
+ </div>`,
96
+ generateHtml: (props) => `
97
+ <div class="dash-card" id="widget-${props.id}" style="height:100%;">
98
+ <div class="dash-card-head">
99
+ <span class="dash-card-title">🕐 ${props.title || 'Clock'}</span>
100
+ </div>
101
+ <div class="dash-card-body" style="display:flex;flex-direction:column;align-items:center;justify-content:center;">
102
+ <div class="kpi-value" id="${props.id}-time">—</div>
103
+ <div class="kpi-label" id="${props.id}-date">—</div>
104
+ </div>
105
+ </div>`,
106
+ generateJs: (props) => `
107
+ // Clock Widget: ${props.id}
108
+ function updateClock_${props.id.replace(/-/g, '_')}() {
109
+ const now = new Date();
110
+ const timeEl = document.getElementById('${props.id}-time');
111
+ const dateEl = document.getElementById('${props.id}-date');
112
+ const opts = { hour: 'numeric', minute: '2-digit', hour12: ${!props.format24h} };
113
+ timeEl.textContent = now.toLocaleTimeString('en-US', opts);
114
+ dateEl.textContent = now.toLocaleDateString('en-US', { weekday: 'short', month: 'short', day: 'numeric' });
115
+ }
116
+ updateClock_${props.id.replace(/-/g, '_')}();
117
+ setInterval(updateClock_${props.id.replace(/-/g, '_')}, 1000);
118
+ `
119
+ },
120
+
121
+ 'auth-status': {
122
+ name: 'Auth Status',
123
+ icon: '🔐',
124
+ category: 'small',
125
+ description: 'Shows if OpenClaw is using Anthropic Max subscription (green) or API key fallback (yellow).',
126
+ defaultWidth: 180,
127
+ defaultHeight: 100,
128
+ hasApiKey: true,
129
+ apiKeyName: 'OPENCLAW_API',
130
+ properties: {
131
+ title: 'Auth Type',
132
+ endpoint: '/api/status',
133
+ refreshInterval: 30
134
+ },
135
+ preview: `<div style="text-align:center;padding:8px;">
136
+ <div style="width:10px;height:10px;background:#3fb950;border-radius:50%;margin:0 auto 4px;"></div>
137
+ <div style="font-size:13px;">OAuth</div>
138
+ <div style="font-size:11px;color:#8b949e;">Auth</div>
139
+ </div>`,
140
+ generateHtml: (props) => `
141
+ <div class="dash-card" id="widget-${props.id}" style="height:100%;">
142
+ <div class="dash-card-head">
143
+ <span class="dash-card-title">🔐 ${props.title || 'Auth Type'}</span>
144
+ </div>
145
+ <div class="dash-card-body" style="display:flex;align-items:center;justify-content:center;gap:10px;">
146
+ <div class="kpi-indicator" id="${props.id}-dot"></div>
147
+ <div class="kpi-value" id="${props.id}-value">—</div>
148
+ </div>
149
+ </div>`,
150
+ generateJs: (props) => `
151
+ // Auth Status Widget: ${props.id}
152
+ async function update_${props.id.replace(/-/g, '_')}() {
153
+ try {
154
+ const res = await fetch('${props.endpoint || '/api/status'}');
155
+ const json = await res.json();
156
+ const data = json.data || json;
157
+ const dot = document.getElementById('${props.id}-dot');
158
+ const val = document.getElementById('${props.id}-value');
159
+ val.textContent = data.authMode === 'oauth' ? 'Subscription' : 'API';
160
+ dot.className = 'kpi-indicator ' + (data.authMode === 'oauth' ? 'green' : 'yellow');
161
+ } catch (e) {
162
+ console.error('Auth status widget error:', e);
163
+ document.getElementById('${props.id}-value').textContent = '—';
164
+ }
165
+ }
166
+ update_${props.id.replace(/-/g, '_')}();
167
+ setInterval(update_${props.id.replace(/-/g, '_')}, ${(props.refreshInterval || 30) * 1000});
168
+ `
169
+ },
170
+
171
+ 'session-count': {
172
+ name: 'Active Sessions',
173
+ icon: '💬',
174
+ category: 'small',
175
+ description: 'Shows count of active OpenClaw sessions.',
176
+ defaultWidth: 160,
177
+ defaultHeight: 100,
178
+ hasApiKey: true,
179
+ apiKeyName: 'OPENCLAW_API',
180
+ properties: {
181
+ title: 'Sessions',
182
+ endpoint: '/api/sessions',
183
+ refreshInterval: 30
184
+ },
185
+ preview: `<div style="text-align:center;padding:8px;">
186
+ <div style="font-size:28px;color:#58a6ff;">3</div>
187
+ <div style="font-size:11px;color:#8b949e;">Active</div>
188
+ </div>`,
189
+ generateHtml: (props) => `
190
+ <div class="kpi-card kpi-sm" id="widget-${props.id}">
191
+ <div class="kpi-icon">💬</div>
192
+ <div class="kpi-data">
193
+ <div class="kpi-value blue" id="${props.id}-count">—</div>
194
+ <div class="kpi-label">Active</div>
195
+ </div>
196
+ </div>`,
197
+ generateJs: (props) => `
198
+ // Session Count Widget: ${props.id}
199
+ async function update_${props.id.replace(/-/g, '_')}() {
200
+ try {
201
+ const res = await fetch('${props.endpoint || '/api/sessions'}');
202
+ const json = await res.json();
203
+ const data = json.data || json;
204
+ document.getElementById('${props.id}-count').textContent = data.active || data.length || 0;
205
+ } catch (e) {
206
+ document.getElementById('${props.id}-count').textContent = '—';
207
+ }
208
+ }
209
+ update_${props.id.replace(/-/g, '_')}();
210
+ setInterval(update_${props.id.replace(/-/g, '_')}, ${(props.refreshInterval || 30) * 1000});
211
+ `
212
+ },
213
+
214
+ // ─────────────────────────────────────────────
215
+ // LARGE CARDS (Content)
216
+ // ─────────────────────────────────────────────
217
+
218
+ 'activity-list': {
219
+ name: 'Activity List',
220
+ icon: '📋',
221
+ category: 'large',
222
+ description: 'Shows recent OpenClaw activity from /api/activity endpoint.',
223
+ defaultWidth: 400,
224
+ defaultHeight: 300,
225
+ hasApiKey: true,
226
+ apiKeyName: 'OPENCLAW_API',
227
+ properties: {
228
+ title: 'Today',
229
+ endpoint: '/api/activity',
230
+ maxItems: 10,
231
+ refreshInterval: 60
232
+ },
233
+ preview: `<div style="padding:4px;font-size:11px;color:#8b949e;">
234
+ <div>• Meeting at 2pm</div>
235
+ <div>• Review PR #42</div>
236
+ <div>• Deploy v1.2</div>
237
+ </div>`,
238
+ generateHtml: (props) => `
239
+ <div class="dash-card" id="widget-${props.id}" style="height:100%;">
240
+ <div class="dash-card-head">
241
+ <span class="dash-card-title">📋 ${props.title || 'Today'}</span>
242
+ <span class="dash-card-badge" id="${props.id}-badge">—</span>
243
+ </div>
244
+ <div class="dash-card-body compact-list" id="${props.id}-list">
245
+ <div class="list-item">• Team standup at 10am</div>
246
+ <div class="list-item">• Review PR #42</div>
247
+ </div>
248
+ </div>`,
249
+ generateJs: (props) => `
250
+ // Activity List Widget: ${props.id}
251
+ async function update_${props.id.replace(/-/g, '_')}() {
252
+ try {
253
+ const res = await fetch('${props.endpoint || '/api/activity'}');
254
+ const json = await res.json();
255
+ const data = json.data || json;
256
+ const list = document.getElementById('${props.id}-list');
257
+ const badge = document.getElementById('${props.id}-badge');
258
+ const items = data.items || [];
259
+ list.innerHTML = items.slice(0, ${props.maxItems || 10}).map(item =>
260
+ '<div class="list-item">' + item.text + '</div>'
261
+ ).join('');
262
+ badge.textContent = items.length + ' items';
263
+ } catch (e) {
264
+ console.error('Activity list widget error:', e);
265
+ document.getElementById('${props.id}-list').innerHTML = '<div class="list-item">—</div>';
266
+ }
267
+ }
268
+ update_${props.id.replace(/-/g, '_')}();
269
+ setInterval(update_${props.id.replace(/-/g, '_')}, ${(props.refreshInterval || 60) * 1000});
270
+ `
271
+ },
272
+
273
+ 'cron-jobs': {
274
+ name: 'Cron Jobs',
275
+ icon: '⏰',
276
+ category: 'large',
277
+ description: 'Lists scheduled cron jobs from OpenClaw /api/cron endpoint.',
278
+ defaultWidth: 400,
279
+ defaultHeight: 250,
280
+ hasApiKey: true,
281
+ apiKeyName: 'OPENCLAW_API',
282
+ properties: {
283
+ title: 'Cron',
284
+ endpoint: '/api/cron',
285
+ refreshInterval: 30
286
+ },
287
+ preview: `<div style="padding:4px;font-size:11px;color:#8b949e;">
288
+ <div>⏰ Daily backup - 2am</div>
289
+ <div>⏰ Sync data - */5 *</div>
290
+ </div>`,
291
+ generateHtml: (props) => `
292
+ <div class="dash-card" id="widget-${props.id}" style="height:100%;">
293
+ <div class="dash-card-head">
294
+ <span class="dash-card-title">⏰ ${props.title || 'Cron'}</span>
295
+ <span class="dash-card-badge" id="${props.id}-badge">—</span>
296
+ </div>
297
+ <div class="dash-card-body" id="${props.id}-list">
298
+ <div class="cron-item"><span class="cron-name">Daily backup</span><span class="cron-next">2:00 AM</span></div>
299
+ </div>
300
+ </div>`,
301
+ generateJs: (props) => `
302
+ // Cron Jobs Widget: ${props.id}
303
+ async function update_${props.id.replace(/-/g, '_')}() {
304
+ try {
305
+ const res = await fetch('${props.endpoint || '/api/cron'}');
306
+ const json = await res.json();
307
+ const data = json.data || json;
308
+ const list = document.getElementById('${props.id}-list');
309
+ const badge = document.getElementById('${props.id}-badge');
310
+ const jobs = data.jobs || [];
311
+ list.innerHTML = jobs.map(job =>
312
+ '<div class="cron-item"><span class="cron-name">' + job.name + '</span><span class="cron-next">' + job.next + '</span></div>'
313
+ ).join('');
314
+ badge.textContent = jobs.length + ' jobs';
315
+ } catch (e) {
316
+ console.error('Cron jobs widget error:', e);
317
+ document.getElementById('${props.id}-list').innerHTML = '<div class="cron-item"><span class="cron-name">—</span></div>';
318
+ }
319
+ }
320
+ update_${props.id.replace(/-/g, '_')}();
321
+ setInterval(update_${props.id.replace(/-/g, '_')}, ${(props.refreshInterval || 30) * 1000});
322
+ `
323
+ },
324
+
325
+ 'system-log': {
326
+ name: 'System Log',
327
+ icon: '🔧',
328
+ category: 'large',
329
+ description: 'Shows recent system logs from OpenClaw /api/logs endpoint.',
330
+ defaultWidth: 500,
331
+ defaultHeight: 400,
332
+ hasApiKey: true,
333
+ apiKeyName: 'OPENCLAW_API',
334
+ properties: {
335
+ title: 'System Log',
336
+ endpoint: '/api/logs',
337
+ maxLines: 50,
338
+ refreshInterval: 10
339
+ },
340
+ preview: `<div style="padding:4px;font-size:10px;font-family:monospace;color:#8b949e;">
341
+ <div>[INFO] System started</div>
342
+ <div>[DEBUG] Loading config</div>
343
+ </div>`,
344
+ generateHtml: (props) => `
345
+ <div class="dash-card" id="widget-${props.id}" style="height:100%;">
346
+ <div class="dash-card-head">
347
+ <span class="dash-card-title">🔧 ${props.title || 'System Log'}</span>
348
+ <span class="dash-card-badge" id="${props.id}-badge">—</span>
349
+ </div>
350
+ <div class="dash-card-body compact-list syslog-scroll" id="${props.id}-log">
351
+ <div class="log-line">[INFO] System started successfully</div>
352
+ </div>
353
+ </div>`,
354
+ generateJs: (props) => `
355
+ // System Log Widget: ${props.id}
356
+ async function update_${props.id.replace(/-/g, '_')}() {
357
+ try {
358
+ const res = await fetch('${props.endpoint || '/api/logs'}');
359
+ const json = await res.json();
360
+ const data = json.data || json;
361
+ const log = document.getElementById('${props.id}-log');
362
+ const badge = document.getElementById('${props.id}-badge');
363
+ const lines = data.lines || [];
364
+ log.innerHTML = lines.slice(-${props.maxLines || 50}).map(line =>
365
+ '<div class="log-line">' + line + '</div>'
366
+ ).join('');
367
+ badge.textContent = lines.length + ' lines';
368
+ log.scrollTop = log.scrollHeight;
369
+ } catch (e) {
370
+ console.error('System log widget error:', e);
371
+ document.getElementById('${props.id}-log').innerHTML = '<div class="log-line">—</div>';
372
+ }
373
+ }
374
+ update_${props.id.replace(/-/g, '_')}();
375
+ setInterval(update_${props.id.replace(/-/g, '_')}, ${(props.refreshInterval || 10) * 1000});
376
+ `
377
+ },
378
+
379
+ // ─────────────────────────────────────────────
380
+ // BARS
381
+ // ─────────────────────────────────────────────
382
+
383
+ 'topbar': {
384
+ name: 'Top Nav Bar',
385
+ icon: '🔝',
386
+ category: 'bar',
387
+ description: 'Navigation bar with clock, weather, and system stats.',
388
+ defaultWidth: 1920,
389
+ defaultHeight: 48,
390
+ hasApiKey: false,
391
+ properties: {
392
+ title: 'OpenClaw',
393
+ links: 'Dashboard,Activity,Settings'
394
+ },
395
+ preview: `<div style="background:#161b22;padding:8px;font-size:11px;display:flex;gap:12px;">
396
+ <span>🤖 OpenClaw</span>
397
+ <span style="color:#58a6ff;">Dashboard</span>
398
+ </div>`,
399
+ generateHtml: (props) => `
400
+ <nav class="topbar" id="widget-${props.id}">
401
+ <div class="topbar-left">
402
+ <span class="topbar-brand">🤖 ${props.title || 'OpenClaw'}</span>
403
+ ${(props.links || 'Dashboard').split(',').map((link, i) =>
404
+ `<a href="#" class="topbar-link${i === 0 ? ' active' : ''}">${link.trim()}</a>`
405
+ ).join('')}
406
+ </div>
407
+ <div class="topbar-right">
408
+ <span class="topbar-meta" id="${props.id}-refresh">—</span>
409
+ <button class="topbar-refresh" onclick="location.reload()" title="Refresh">↻</button>
410
+ </div>
411
+ </nav>`,
412
+ generateJs: (props) => `
413
+ // Top Bar Widget: ${props.id}
414
+ document.getElementById('${props.id}-refresh').textContent =
415
+ new Date().toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit' });
416
+ `
417
+ }
418
+ };
419
+
420
+ // Helper to get widget categories
421
+ function getWidgetCategories() {
422
+ const categories = {};
423
+ for (const [key, widget] of Object.entries(WIDGETS)) {
424
+ const cat = widget.category || 'other';
425
+ if (!categories[cat]) categories[cat] = [];
426
+ categories[cat].push({ key, ...widget });
427
+ }
428
+ return categories;
429
+ }
430
+
431
+ // Helper to get widget by type
432
+ function getWidget(type) {
433
+ return WIDGETS[type] || null;
434
+ }
435
+
436
+ // Helper to list all widget types
437
+ function getWidgetTypes() {
438
+ return Object.keys(WIDGETS);
439
+ }
440
+
441
+ /**
442
+ * LobsterBoard - Dashboard Builder Core
443
+ * Provides utilities for generating dashboard HTML, CSS, and JS
444
+ *
445
+ * @module lobsterboard/builder
446
+ */
447
+
448
+
449
+ // ─────────────────────────────────────────────
450
+ // SECURITY HELPERS
451
+ // ─────────────────────────────────────────────
452
+
453
+ /**
454
+ * Escape HTML to prevent XSS attacks
455
+ * @param {string} str - String to escape
456
+ * @returns {string} Escaped string
457
+ */
458
+ function escapeHtml(str) {
459
+ if (!str) return '';
460
+ if (typeof document !== 'undefined') {
461
+ const div = document.createElement('div');
462
+ div.textContent = str;
463
+ return div.innerHTML;
464
+ }
465
+ // Fallback for Node.js
466
+ return str
467
+ .replace(/&/g, '&amp;')
468
+ .replace(/</g, '&lt;')
469
+ .replace(/>/g, '&gt;')
470
+ .replace(/"/g, '&quot;')
471
+ .replace(/'/g, '&#039;');
472
+ }
473
+
474
+ // ─────────────────────────────────────────────
475
+ // HTML PROCESSING
476
+ // ─────────────────────────────────────────────
477
+
478
+ /**
479
+ * Process widget HTML to conditionally remove header
480
+ * @param {string} html - Widget HTML
481
+ * @param {boolean} showHeader - Whether to show the header
482
+ * @returns {string} Processed HTML
483
+ */
484
+ function processWidgetHtml(html, showHeader) {
485
+ if (showHeader !== false) return html;
486
+ const headerRegex = /<div\s+class="dash-card-head"[^>]*>[\s\S]*?<\/div>/i;
487
+ return html.replace(headerRegex, '');
488
+ }
489
+
490
+ // ─────────────────────────────────────────────
491
+ // CSS GENERATION
492
+ // ─────────────────────────────────────────────
493
+
494
+ /**
495
+ * Generate the base dashboard CSS
496
+ * @returns {string} CSS styles
497
+ */
498
+ function generateDashboardCss() {
499
+ return `/* LobsterBoard Dashboard - Generated Styles */
500
+
501
+ :root {
502
+ --bg-primary: #0d1117;
503
+ --bg-secondary: #161b22;
504
+ --bg-tertiary: #21262d;
505
+ --bg-hover: #30363d;
506
+ --border: #30363d;
507
+ --text-primary: #e6edf3;
508
+ --text-secondary: #8b949e;
509
+ --text-muted: #6e7681;
510
+ --accent-blue: #58a6ff;
511
+ --accent-green: #3fb950;
512
+ --accent-orange: #d29922;
513
+ --accent-red: #f85149;
514
+ --accent-purple: #a371f7;
515
+ }
516
+
517
+ * {
518
+ box-sizing: border-box;
519
+ margin: 0;
520
+ padding: 0;
521
+ }
522
+
523
+ body {
524
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
525
+ background: var(--bg-primary);
526
+ color: var(--text-primary);
527
+ min-height: 100vh;
528
+ }
529
+
530
+ .dashboard {
531
+ margin: 0 auto;
532
+ overflow: hidden;
533
+ }
534
+
535
+ .widget-container {
536
+ overflow: hidden;
537
+ }
538
+
539
+ /* KPI Cards */
540
+ .kpi-card {
541
+ background: var(--bg-secondary);
542
+ border: 1px solid var(--border);
543
+ border-radius: 8px;
544
+ padding: 16px;
545
+ display: flex;
546
+ align-items: center;
547
+ gap: 12px;
548
+ height: 100%;
549
+ }
550
+
551
+ .kpi-sm {
552
+ padding: 12px;
553
+ }
554
+
555
+ .kpi-icon {
556
+ font-size: 24px;
557
+ }
558
+
559
+ .kpi-data {
560
+ flex: 1;
561
+ }
562
+
563
+ .kpi-value {
564
+ font-size: 20px;
565
+ font-weight: 600;
566
+ }
567
+
568
+ .kpi-value.blue { color: var(--accent-blue); }
569
+ .kpi-value.green { color: var(--accent-green); }
570
+ .kpi-value.orange { color: var(--accent-orange); }
571
+ .kpi-value.red { color: var(--accent-red); }
572
+
573
+ .kpi-label {
574
+ font-size: 12px;
575
+ color: var(--text-secondary);
576
+ margin-top: 2px;
577
+ }
578
+
579
+ .kpi-indicator {
580
+ width: 10px;
581
+ height: 10px;
582
+ border-radius: 50%;
583
+ background: var(--text-muted);
584
+ }
585
+
586
+ .kpi-indicator.green { background: var(--accent-green); }
587
+ .kpi-indicator.yellow { background: var(--accent-orange); }
588
+ .kpi-indicator.red { background: var(--accent-red); }
589
+
590
+ /* Dash Cards */
591
+ .dash-card {
592
+ background: var(--bg-secondary);
593
+ border: 1px solid var(--border);
594
+ border-radius: 8px;
595
+ display: flex;
596
+ flex-direction: column;
597
+ height: 100%;
598
+ overflow: hidden;
599
+ }
600
+
601
+ .dash-card-head {
602
+ display: flex;
603
+ justify-content: space-between;
604
+ align-items: center;
605
+ padding: 12px 16px;
606
+ border-bottom: 1px solid var(--border);
607
+ background: var(--bg-tertiary);
608
+ }
609
+
610
+ .dash-card-title {
611
+ font-size: 13px;
612
+ font-weight: 600;
613
+ }
614
+
615
+ .dash-card-badge {
616
+ font-size: 11px;
617
+ color: var(--text-secondary);
618
+ background: var(--bg-primary);
619
+ padding: 2px 8px;
620
+ border-radius: 10px;
621
+ }
622
+
623
+ .dash-card-body {
624
+ flex: 1;
625
+ padding: 12px 16px;
626
+ overflow-y: auto;
627
+ }
628
+
629
+ .compact-list {
630
+ font-size: 12px;
631
+ }
632
+
633
+ .syslog-scroll {
634
+ font-family: 'SF Mono', Monaco, monospace;
635
+ font-size: 11px;
636
+ }
637
+
638
+ /* Top Bar */
639
+ .topbar {
640
+ display: flex;
641
+ justify-content: space-between;
642
+ align-items: center;
643
+ padding: 8px 20px;
644
+ background: var(--bg-secondary);
645
+ border-bottom: 1px solid var(--border);
646
+ height: 100%;
647
+ }
648
+
649
+ .topbar-left {
650
+ display: flex;
651
+ align-items: center;
652
+ gap: 20px;
653
+ }
654
+
655
+ .topbar-brand {
656
+ font-weight: 600;
657
+ font-size: 14px;
658
+ }
659
+
660
+ .topbar-link {
661
+ color: var(--text-secondary);
662
+ text-decoration: none;
663
+ font-size: 13px;
664
+ }
665
+
666
+ .topbar-link:hover,
667
+ .topbar-link.active {
668
+ color: var(--accent-blue);
669
+ }
670
+
671
+ .topbar-right {
672
+ display: flex;
673
+ align-items: center;
674
+ gap: 12px;
675
+ }
676
+
677
+ .topbar-meta {
678
+ font-size: 12px;
679
+ color: var(--text-muted);
680
+ }
681
+
682
+ .topbar-refresh {
683
+ background: var(--bg-tertiary);
684
+ border: 1px solid var(--border);
685
+ color: var(--text-secondary);
686
+ padding: 4px 8px;
687
+ border-radius: 4px;
688
+ cursor: pointer;
689
+ }
690
+
691
+ /* List Items */
692
+ .list-item {
693
+ padding: 6px 0;
694
+ border-bottom: 1px solid var(--border);
695
+ }
696
+
697
+ .list-item:last-child {
698
+ border-bottom: none;
699
+ }
700
+
701
+ .cron-item {
702
+ display: flex;
703
+ justify-content: space-between;
704
+ padding: 6px 0;
705
+ border-bottom: 1px solid var(--border);
706
+ }
707
+
708
+ .cron-name {
709
+ color: var(--text-primary);
710
+ }
711
+
712
+ .cron-next {
713
+ color: var(--text-muted);
714
+ font-size: 11px;
715
+ }
716
+
717
+ .log-line {
718
+ padding: 2px 0;
719
+ border-bottom: 1px solid rgba(48, 54, 61, 0.5);
720
+ }
721
+
722
+ /* Weather */
723
+ .weather-row {
724
+ display: flex;
725
+ align-items: center;
726
+ gap: 10px;
727
+ padding: 8px 0;
728
+ border-bottom: 1px solid var(--border);
729
+ }
730
+
731
+ .weather-row:last-child {
732
+ border-bottom: none;
733
+ }
734
+
735
+ .weather-icon {
736
+ font-size: 18px;
737
+ }
738
+
739
+ .weather-loc {
740
+ flex: 1;
741
+ color: var(--text-primary);
742
+ }
743
+
744
+ .weather-temp {
745
+ font-weight: 600;
746
+ color: var(--accent-blue);
747
+ }
748
+
749
+ /* Utilities */
750
+ .loading-sm {
751
+ display: flex;
752
+ align-items: center;
753
+ justify-content: center;
754
+ padding: 20px;
755
+ }
756
+
757
+ .spinner-sm {
758
+ width: 20px;
759
+ height: 20px;
760
+ border: 2px solid var(--bg-tertiary);
761
+ border-top-color: var(--accent-blue);
762
+ border-radius: 50%;
763
+ animation: spin 1s linear infinite;
764
+ }
765
+
766
+ @keyframes spin {
767
+ to { transform: rotate(360deg); }
768
+ }
769
+
770
+ .error {
771
+ color: var(--accent-red);
772
+ padding: 10px;
773
+ text-align: center;
774
+ }
775
+
776
+ ::-webkit-scrollbar {
777
+ width: 6px;
778
+ }
779
+
780
+ ::-webkit-scrollbar-track {
781
+ background: var(--bg-primary);
782
+ }
783
+
784
+ ::-webkit-scrollbar-thumb {
785
+ background: var(--bg-tertiary);
786
+ border-radius: 3px;
787
+ }
788
+
789
+ /* Post-Export Edit Mode */
790
+ .edit-mode .widget-container {
791
+ cursor: move;
792
+ outline: 2px dashed #3b82f6;
793
+ outline-offset: -2px;
794
+ }
795
+
796
+ .edit-mode .widget-container:hover {
797
+ outline-color: #60a5fa;
798
+ }
799
+
800
+ .edit-mode .widget-container.dragging {
801
+ opacity: 0.8;
802
+ z-index: 1000;
803
+ }
804
+
805
+ .resize-handle-edit {
806
+ display: none;
807
+ position: absolute;
808
+ bottom: 0;
809
+ right: 0;
810
+ width: 16px;
811
+ height: 16px;
812
+ cursor: se-resize;
813
+ background: #3b82f6;
814
+ border-radius: 2px 0 0 0;
815
+ z-index: 10;
816
+ }
817
+
818
+ .edit-mode .resize-handle-edit {
819
+ display: block;
820
+ }
821
+
822
+ #edit-toggle {
823
+ position: fixed;
824
+ bottom: 20px;
825
+ right: 20px;
826
+ z-index: 9999;
827
+ padding: 8px 16px;
828
+ background: #1e293b;
829
+ color: white;
830
+ border: none;
831
+ border-radius: 6px;
832
+ cursor: pointer;
833
+ font-size: 13px;
834
+ font-weight: 500;
835
+ box-shadow: 0 2px 8px rgba(0,0,0,0.3);
836
+ }
837
+
838
+ #edit-toggle:hover {
839
+ background: #334155;
840
+ }
841
+
842
+ #edit-toggle.active {
843
+ background: #3b82f6;
844
+ }
845
+ `;
846
+ }
847
+
848
+ // ─────────────────────────────────────────────
849
+ // JS GENERATION
850
+ // ─────────────────────────────────────────────
851
+
852
+ /**
853
+ * Generate the post-export edit mode JS
854
+ * @returns {string} JavaScript code
855
+ */
856
+ function generateEditJs() {
857
+ return `
858
+ // ─────────────────────────────────────────────
859
+ // POST-EXPORT LAYOUT EDITING
860
+ // ─────────────────────────────────────────────
861
+
862
+ (function() {
863
+ const STORAGE_KEY = 'lobsterboard-layout';
864
+ const GRID_SIZE = 20;
865
+ const MIN_WIDTH = 100;
866
+ const MIN_HEIGHT = 60;
867
+
868
+ let editMode = false;
869
+ let activeWidget = null;
870
+ let startX, startY, origLeft, origTop, origWidth, origHeight;
871
+ let isResizing = false;
872
+
873
+ document.addEventListener('DOMContentLoaded', initEditMode);
874
+
875
+ function initEditMode() {
876
+ const btn = document.createElement('button');
877
+ btn.id = 'edit-toggle';
878
+ btn.textContent = '✏️ Edit Layout';
879
+ btn.onclick = toggleEditMode;
880
+ document.body.appendChild(btn);
881
+ document.querySelectorAll('.widget-container').forEach(initWidget);
882
+ loadPositions();
883
+ }
884
+
885
+ function initWidget(widget) {
886
+ const handle = document.createElement('div');
887
+ handle.className = 'resize-handle-edit';
888
+ widget.appendChild(handle);
889
+ widget.addEventListener('mousedown', onWidgetMouseDown);
890
+ handle.addEventListener('mousedown', onResizeMouseDown);
891
+ }
892
+
893
+ function toggleEditMode() {
894
+ editMode = !editMode;
895
+ document.body.classList.toggle('edit-mode', editMode);
896
+ document.getElementById('edit-toggle').classList.toggle('active', editMode);
897
+ document.getElementById('edit-toggle').textContent = editMode ? '💾 Save Layout' : '✏️ Edit Layout';
898
+ if (!editMode) savePositions();
899
+ }
900
+
901
+ function onWidgetMouseDown(e) {
902
+ if (!editMode) return;
903
+ if (e.target.classList.contains('resize-handle-edit')) return;
904
+ if (e.button !== 0) return;
905
+ e.preventDefault();
906
+ activeWidget = e.currentTarget;
907
+ isResizing = false;
908
+ startX = e.clientX;
909
+ startY = e.clientY;
910
+ origLeft = activeWidget.offsetLeft;
911
+ origTop = activeWidget.offsetTop;
912
+ activeWidget.classList.add('dragging');
913
+ document.addEventListener('mousemove', onMouseMove);
914
+ document.addEventListener('mouseup', onMouseUp);
915
+ }
916
+
917
+ function onResizeMouseDown(e) {
918
+ if (!editMode) return;
919
+ e.preventDefault();
920
+ e.stopPropagation();
921
+ activeWidget = e.target.parentElement;
922
+ isResizing = true;
923
+ startX = e.clientX;
924
+ startY = e.clientY;
925
+ origWidth = activeWidget.offsetWidth;
926
+ origHeight = activeWidget.offsetHeight;
927
+ activeWidget.classList.add('dragging');
928
+ document.addEventListener('mousemove', onMouseMove);
929
+ document.addEventListener('mouseup', onMouseUp);
930
+ }
931
+
932
+ function onMouseMove(e) {
933
+ if (!activeWidget) return;
934
+ const dx = e.clientX - startX;
935
+ const dy = e.clientY - startY;
936
+ if (isResizing) {
937
+ activeWidget.style.width = Math.max(MIN_WIDTH, origWidth + dx) + 'px';
938
+ activeWidget.style.height = Math.max(MIN_HEIGHT, origHeight + dy) + 'px';
939
+ } else {
940
+ activeWidget.style.left = Math.max(0, origLeft + dx) + 'px';
941
+ activeWidget.style.top = Math.max(0, origTop + dy) + 'px';
942
+ }
943
+ }
944
+
945
+ function onMouseUp() {
946
+ if (!activeWidget) return;
947
+ if (isResizing) {
948
+ activeWidget.style.width = snapToGrid(activeWidget.offsetWidth) + 'px';
949
+ activeWidget.style.height = snapToGrid(activeWidget.offsetHeight) + 'px';
950
+ } else {
951
+ activeWidget.style.left = snapToGrid(activeWidget.offsetLeft) + 'px';
952
+ activeWidget.style.top = snapToGrid(activeWidget.offsetTop) + 'px';
953
+ }
954
+ activeWidget.classList.remove('dragging');
955
+ activeWidget = null;
956
+ isResizing = false;
957
+ document.removeEventListener('mousemove', onMouseMove);
958
+ document.removeEventListener('mouseup', onMouseUp);
959
+ }
960
+
961
+ function snapToGrid(value) {
962
+ return Math.round(value / GRID_SIZE) * GRID_SIZE;
963
+ }
964
+
965
+ function savePositions() {
966
+ const positions = {};
967
+ document.querySelectorAll('.widget-container').forEach(widget => {
968
+ const id = widget.dataset.widgetId;
969
+ if (id) {
970
+ positions[id] = {
971
+ left: widget.offsetLeft,
972
+ top: widget.offsetTop,
973
+ width: widget.offsetWidth,
974
+ height: widget.offsetHeight
975
+ };
976
+ }
977
+ });
978
+ try {
979
+ localStorage.setItem(STORAGE_KEY, JSON.stringify(positions));
980
+ } catch (e) {}
981
+ }
982
+
983
+ function loadPositions() {
984
+ try {
985
+ const saved = localStorage.getItem(STORAGE_KEY);
986
+ if (!saved) return;
987
+ const positions = JSON.parse(saved);
988
+ document.querySelectorAll('.widget-container').forEach(widget => {
989
+ const id = widget.dataset.widgetId;
990
+ const pos = positions[id];
991
+ if (pos) {
992
+ widget.style.left = pos.left + 'px';
993
+ widget.style.top = pos.top + 'px';
994
+ widget.style.width = pos.width + 'px';
995
+ widget.style.height = pos.height + 'px';
996
+ }
997
+ });
998
+ } catch (e) {}
999
+ }
1000
+ })();
1001
+ `;
1002
+ }
1003
+
1004
+ // ─────────────────────────────────────────────
1005
+ // DASHBOARD GENERATION
1006
+ // ─────────────────────────────────────────────
1007
+
1008
+ /**
1009
+ * Generate widget HTML for a widget configuration
1010
+ * @param {Object} widget - Widget configuration
1011
+ * @returns {string} Widget HTML
1012
+ */
1013
+ function generateWidgetHtml(widget) {
1014
+ const template = WIDGETS[widget.type];
1015
+ if (!template) return '';
1016
+
1017
+ const props = { ...widget.properties, id: widget.id };
1018
+ let html = processWidgetHtml(template.generateHtml(props), widget.properties.showHeader);
1019
+
1020
+ return `
1021
+ <div class="widget-container" data-widget-id="${widget.id}" style="position:absolute;left:${widget.x}px;top:${widget.y}px;width:${widget.width}px;height:${widget.height}px;">
1022
+ ${html}
1023
+ </div>`;
1024
+ }
1025
+
1026
+ /**
1027
+ * Generate widget JavaScript for a widget configuration
1028
+ * @param {Object} widget - Widget configuration
1029
+ * @returns {string} Widget JavaScript
1030
+ */
1031
+ function generateWidgetJs(widget) {
1032
+ const template = WIDGETS[widget.type];
1033
+ if (!template || !template.generateJs) return '';
1034
+
1035
+ const props = { ...widget.properties, id: widget.id };
1036
+ return template.generateJs(props);
1037
+ }
1038
+
1039
+ /**
1040
+ * Generate complete dashboard HTML
1041
+ * @param {Object} config - Dashboard configuration
1042
+ * @param {Object} config.canvas - Canvas dimensions { width, height }
1043
+ * @param {Array} config.widgets - Array of widget configurations
1044
+ * @returns {string} Complete HTML document
1045
+ */
1046
+ function generateDashboardHtml(config) {
1047
+ const { canvas, widgets } = config;
1048
+ const widgetHtml = widgets.map(generateWidgetHtml).join('\n');
1049
+
1050
+ return `<!DOCTYPE html>
1051
+ <html lang="en">
1052
+ <head>
1053
+ <meta charset="UTF-8">
1054
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
1055
+ <title>My LobsterBoard Dashboard</title>
1056
+ <link rel="stylesheet" href="css/style.css">
1057
+ </head>
1058
+ <body>
1059
+ <main class="dashboard" style="width:${canvas.width}px;height:${canvas.height}px;position:relative;">
1060
+ ${widgetHtml}
1061
+ </main>
1062
+ <script src="js/dashboard.js"></script>
1063
+ </body>
1064
+ </html>`;
1065
+ }
1066
+
1067
+ /**
1068
+ * Generate complete dashboard JavaScript
1069
+ * @param {Array} widgets - Array of widget configurations
1070
+ * @returns {string} Complete JavaScript
1071
+ */
1072
+ function generateDashboardJs(widgets) {
1073
+ const widgetJs = widgets.map(generateWidgetJs).filter(Boolean).join('\n\n');
1074
+ const editJs = generateEditJs();
1075
+
1076
+ return `/**
1077
+ * LobsterBoard Dashboard - Generated JavaScript
1078
+ * Replace YOUR_*_API_KEY placeholders with your actual API keys
1079
+ */
1080
+
1081
+ document.addEventListener('DOMContentLoaded', () => {
1082
+ console.log('Dashboard loaded');
1083
+ });
1084
+
1085
+ ${widgetJs}
1086
+
1087
+ ${editJs}
1088
+ `;
1089
+ }
1090
+
1091
+ /**
1092
+ * Generate README for exported dashboard
1093
+ * @param {Array} widgets - Array of widget configurations
1094
+ * @returns {string} README markdown
1095
+ */
1096
+ function generateReadme(widgets) {
1097
+ const apiKeys = [];
1098
+ const needsOpenClaw = widgets.some(w =>
1099
+ ['openclaw-release', 'auth-status', 'activity-list', 'cron-jobs', 'system-log', 'session-count', 'token-gauge'].includes(w.type)
1100
+ );
1101
+
1102
+ widgets.forEach(widget => {
1103
+ const template = WIDGETS[widget.type];
1104
+ if (template?.hasApiKey && template.apiKeyName) {
1105
+ if (!apiKeys.includes(template.apiKeyName)) {
1106
+ apiKeys.push(template.apiKeyName);
1107
+ }
1108
+ }
1109
+ });
1110
+
1111
+ return `# LobsterBoard Dashboard
1112
+
1113
+ This dashboard was generated with LobsterBoard Dashboard Builder.
1114
+
1115
+ ## Quick Start
1116
+
1117
+ ${needsOpenClaw ? `### Running with OpenClaw widgets
1118
+
1119
+ Your dashboard includes widgets that connect to OpenClaw. Run the included server:
1120
+
1121
+ \`\`\`bash
1122
+ node server.js
1123
+ \`\`\`
1124
+
1125
+ Open http://localhost:8080 in your browser.
1126
+ ` : ''}
1127
+ ### Static mode
1128
+
1129
+ Open \`index.html\` directly in a browser.
1130
+
1131
+ ## Files
1132
+
1133
+ | File | Description |
1134
+ |------|-------------|
1135
+ | \`index.html\` | Dashboard page |
1136
+ | \`css/style.css\` | Styles |
1137
+ | \`js/dashboard.js\` | Widget logic |
1138
+ | \`server.js\` | Server with OpenClaw API proxy |
1139
+
1140
+ ${apiKeys.length > 0 ? `## API Keys
1141
+
1142
+ Edit \`js/dashboard.js\` and replace these placeholders:
1143
+ ${apiKeys.map(key => `- \`YOUR_${key}\``).join('\n')}
1144
+ ` : ''}
1145
+
1146
+ ---
1147
+
1148
+ Generated with LobsterBoard - https://github.com/curbob/LobsterBoard
1149
+ `;
1150
+ }
1151
+
1152
+ var builder = {
1153
+ escapeHtml,
1154
+ processWidgetHtml,
1155
+ generateDashboardCss,
1156
+ generateEditJs,
1157
+ generateWidgetHtml,
1158
+ generateWidgetJs,
1159
+ generateDashboardHtml,
1160
+ generateDashboardJs,
1161
+ generateReadme
1162
+ };
1163
+
1164
+ /**
1165
+ * LobsterBoard - Dashboard Builder Library
1166
+ *
1167
+ * A library for building and generating dashboard configurations
1168
+ * with customizable widgets.
1169
+ *
1170
+ * @module lobsterboard
1171
+ * @example
1172
+ * // ESM
1173
+ * import { WIDGETS, generateDashboardHtml, generateDashboardCss } from 'lobsterboard';
1174
+ *
1175
+ * // CommonJS
1176
+ * const { WIDGETS, generateDashboardHtml } = require('lobsterboard');
1177
+ *
1178
+ * // Browser (UMD)
1179
+ * <script src="https://unpkg.com/lobsterboard"></script>
1180
+ * const { WIDGETS } = LobsterBoard;
1181
+ */
1182
+
1183
+
1184
+ // Version (will be replaced during build)
1185
+ const VERSION = '0.1.0';
1186
+
1187
+ // Default export for convenience
1188
+ var index = {
1189
+ VERSION,
1190
+ WIDGETS,
1191
+ ...builder
1192
+ };
1193
+
1194
+ export { VERSION, WIDGETS, index as default, escapeHtml, generateDashboardCss, generateDashboardHtml, generateDashboardJs, generateEditJs, generateReadme, generateWidgetHtml, generateWidgetJs, getWidget, getWidgetCategories, getWidgetTypes, processWidgetHtml };
1195
+ //# sourceMappingURL=lobsterboard.esm.js.map