@jetpack-desktop/client 0.0.0-stage → 0.1.2-rc.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.
- package/LICENSE +30 -0
- package/README.md +81 -2
- package/dist/client.d.ts +122 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +864 -0
- package/dist/client.js.map +1 -0
- package/dist/control-bar.d.ts +78 -0
- package/dist/control-bar.d.ts.map +1 -0
- package/dist/control-bar.js +788 -0
- package/dist/control-bar.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/log-terminal.d.ts +91 -0
- package/dist/log-terminal.d.ts.map +1 -0
- package/dist/log-terminal.js +960 -0
- package/dist/log-terminal.js.map +1 -0
- package/dist/types.d.ts +245 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- package/package.json +60 -4
- package/wasm/jetpack_wasm.d.ts +293 -0
- package/wasm/jetpack_wasm.js +1387 -0
- package/wasm/jetpack_wasm_bg.wasm +0 -0
- package/wasm/jetpack_wasm_bg.wasm.d.ts +61 -0
|
@@ -0,0 +1,960 @@
|
|
|
1
|
+
const DEFAULT_TITLE = 'JetPack Live Logs';
|
|
2
|
+
const DEFAULT_MAX_ENTRIES = 1000;
|
|
3
|
+
const COPIED_RESET_DELAY_MS = 1800;
|
|
4
|
+
const LOG_TERMINAL_OFFSET_CSS_VAR = '--jetpack-log-terminal-offset';
|
|
5
|
+
const FALLBACK_COLLAPSED_HEIGHT_PX = 35;
|
|
6
|
+
const FALLBACK_EXPANDED_HEIGHT_PX = 305;
|
|
7
|
+
const LOG_TERMINAL_STYLES = `
|
|
8
|
+
:host {
|
|
9
|
+
all: initial;
|
|
10
|
+
display: block;
|
|
11
|
+
position: fixed;
|
|
12
|
+
left: 0;
|
|
13
|
+
right: 0;
|
|
14
|
+
bottom: 0;
|
|
15
|
+
z-index: 2147483646;
|
|
16
|
+
font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
17
|
+
color: #e6edf3;
|
|
18
|
+
-webkit-font-smoothing: antialiased;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
:host([hidden]) {
|
|
22
|
+
display: none !important;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
*, *::before, *::after {
|
|
26
|
+
box-sizing: border-box;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.jp-terminal {
|
|
30
|
+
display: flex;
|
|
31
|
+
flex-direction: column;
|
|
32
|
+
width: 100%;
|
|
33
|
+
background: rgba(13, 17, 23, 0.97);
|
|
34
|
+
border-top: 1px solid #2a3447;
|
|
35
|
+
box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.45);
|
|
36
|
+
backdrop-filter: blur(12px);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.jp-header {
|
|
40
|
+
display: flex;
|
|
41
|
+
align-items: center;
|
|
42
|
+
justify-content: space-between;
|
|
43
|
+
gap: 12px;
|
|
44
|
+
width: 100%;
|
|
45
|
+
min-height: 34px;
|
|
46
|
+
padding: 6px 16px;
|
|
47
|
+
background: #131924;
|
|
48
|
+
border: none;
|
|
49
|
+
border-bottom: 1px solid transparent;
|
|
50
|
+
color: #e6edf3;
|
|
51
|
+
font: inherit;
|
|
52
|
+
font-size: 12px;
|
|
53
|
+
font-weight: 600;
|
|
54
|
+
cursor: pointer;
|
|
55
|
+
text-align: left;
|
|
56
|
+
transition: background-color 0.15s ease;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.jp-header:hover {
|
|
60
|
+
background: #192231;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.jp-terminal[data-expanded="true"] .jp-header {
|
|
64
|
+
border-bottom-color: #263143;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.jp-header-left,
|
|
68
|
+
.jp-header-right {
|
|
69
|
+
display: flex;
|
|
70
|
+
align-items: center;
|
|
71
|
+
gap: 8px;
|
|
72
|
+
min-width: 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.jp-dot {
|
|
76
|
+
width: 8px;
|
|
77
|
+
height: 8px;
|
|
78
|
+
border-radius: 50%;
|
|
79
|
+
background: #3fb950;
|
|
80
|
+
box-shadow: 0 0 8px rgba(63, 185, 80, 0.55);
|
|
81
|
+
flex-shrink: 0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.jp-title {
|
|
85
|
+
white-space: nowrap;
|
|
86
|
+
overflow: hidden;
|
|
87
|
+
text-overflow: ellipsis;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.jp-dev-tag {
|
|
91
|
+
padding: 1px 6px;
|
|
92
|
+
border-radius: 999px;
|
|
93
|
+
font-size: 10px;
|
|
94
|
+
font-weight: 700;
|
|
95
|
+
letter-spacing: 0.04em;
|
|
96
|
+
text-transform: uppercase;
|
|
97
|
+
color: #d29922;
|
|
98
|
+
background: rgba(210, 153, 34, 0.14);
|
|
99
|
+
border: 1px solid rgba(210, 153, 34, 0.4);
|
|
100
|
+
flex-shrink: 0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.jp-unread-badge {
|
|
104
|
+
display: inline-flex;
|
|
105
|
+
align-items: center;
|
|
106
|
+
gap: 4px;
|
|
107
|
+
padding: 2px 8px;
|
|
108
|
+
border-radius: 999px;
|
|
109
|
+
font-size: 11px;
|
|
110
|
+
font-weight: 700;
|
|
111
|
+
color: #ffdcd9;
|
|
112
|
+
background: rgba(248, 81, 73, 0.22);
|
|
113
|
+
border: 1px solid rgba(248, 81, 73, 0.55);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.jp-unread-badge[hidden] {
|
|
117
|
+
display: none;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.jp-total-count {
|
|
121
|
+
font-size: 11px;
|
|
122
|
+
font-weight: 500;
|
|
123
|
+
color: #8b949e;
|
|
124
|
+
font-variant-numeric: tabular-nums;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.jp-chevron {
|
|
128
|
+
font-size: 11px;
|
|
129
|
+
color: #9fb0c7;
|
|
130
|
+
flex-shrink: 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.jp-body {
|
|
134
|
+
display: flex;
|
|
135
|
+
flex-direction: column;
|
|
136
|
+
height: 270px;
|
|
137
|
+
max-height: 45vh;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.jp-body[hidden] {
|
|
141
|
+
display: none;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.jp-toolbar {
|
|
145
|
+
display: flex;
|
|
146
|
+
align-items: center;
|
|
147
|
+
justify-content: space-between;
|
|
148
|
+
gap: 10px;
|
|
149
|
+
padding: 6px 14px;
|
|
150
|
+
background: #0f151f;
|
|
151
|
+
border-bottom: 1px solid #222c3d;
|
|
152
|
+
flex-wrap: wrap;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.jp-filters,
|
|
156
|
+
.jp-actions {
|
|
157
|
+
display: flex;
|
|
158
|
+
align-items: center;
|
|
159
|
+
gap: 6px;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.jp-filter-btn,
|
|
163
|
+
.jp-action-btn {
|
|
164
|
+
appearance: none;
|
|
165
|
+
font: inherit;
|
|
166
|
+
font-size: 11px;
|
|
167
|
+
font-weight: 600;
|
|
168
|
+
line-height: 1.2;
|
|
169
|
+
padding: 4px 10px;
|
|
170
|
+
border-radius: 6px;
|
|
171
|
+
border: 1px solid #2c384e;
|
|
172
|
+
background: #17202e;
|
|
173
|
+
color: #b7c4d6;
|
|
174
|
+
cursor: pointer;
|
|
175
|
+
transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.jp-filter-btn:hover,
|
|
179
|
+
.jp-action-btn:hover {
|
|
180
|
+
background: #1f2b3d;
|
|
181
|
+
border-color: #445675;
|
|
182
|
+
color: #ffffff;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.jp-filter-btn[data-active="true"] {
|
|
186
|
+
background: rgba(31, 111, 235, 0.22);
|
|
187
|
+
border-color: #388bfd;
|
|
188
|
+
color: #ffffff;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.jp-action-btn[data-copied="true"] {
|
|
192
|
+
background: rgba(63, 185, 80, 0.2);
|
|
193
|
+
border-color: rgba(63, 185, 80, 0.6);
|
|
194
|
+
color: #56d364;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.jp-viewport {
|
|
198
|
+
flex: 1 1 auto;
|
|
199
|
+
overflow-y: auto;
|
|
200
|
+
padding: 8px 14px;
|
|
201
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
|
|
202
|
+
font-size: 12px;
|
|
203
|
+
line-height: 1.48;
|
|
204
|
+
background: #090d13;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.jp-empty {
|
|
208
|
+
padding: 20px 8px;
|
|
209
|
+
text-align: center;
|
|
210
|
+
color: #7d8590;
|
|
211
|
+
font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
212
|
+
font-size: 12px;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.jp-empty[hidden] {
|
|
216
|
+
display: none;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.jp-log-row {
|
|
220
|
+
display: flex;
|
|
221
|
+
align-items: baseline;
|
|
222
|
+
gap: 8px;
|
|
223
|
+
padding: 2px 4px;
|
|
224
|
+
border-radius: 4px;
|
|
225
|
+
white-space: pre-wrap;
|
|
226
|
+
word-break: break-word;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.jp-log-row:hover {
|
|
230
|
+
background: rgba(255, 255, 255, 0.035);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
.jp-col-time {
|
|
234
|
+
color: #6e7681;
|
|
235
|
+
flex-shrink: 0;
|
|
236
|
+
font-variant-numeric: tabular-nums;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
.jp-col-level {
|
|
240
|
+
display: inline-block;
|
|
241
|
+
min-width: 48px;
|
|
242
|
+
text-align: center;
|
|
243
|
+
padding: 0 5px;
|
|
244
|
+
border-radius: 4px;
|
|
245
|
+
font-size: 11px;
|
|
246
|
+
font-weight: 700;
|
|
247
|
+
flex-shrink: 0;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
.jp-log-row[data-level="INFO"] .jp-col-level {
|
|
251
|
+
color: #79c0ff;
|
|
252
|
+
background: rgba(56, 139, 253, 0.16);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
.jp-log-row[data-level="WARN"] .jp-col-level {
|
|
256
|
+
color: #e3b341;
|
|
257
|
+
background: rgba(210, 153, 34, 0.18);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.jp-log-row[data-level="WARN"] .jp-col-msg {
|
|
261
|
+
color: #f2cc60;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.jp-log-row[data-level="ERROR"] .jp-col-level {
|
|
265
|
+
color: #ff7b72;
|
|
266
|
+
background: rgba(248, 81, 73, 0.2);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
.jp-log-row[data-level="ERROR"] .jp-col-msg {
|
|
270
|
+
color: #ffa198;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
.jp-log-row[data-level="DEBUG"] .jp-col-level {
|
|
274
|
+
color: #d2a8ff;
|
|
275
|
+
background: rgba(163, 113, 247, 0.16);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.jp-log-row[data-level="TRACE"] .jp-col-level {
|
|
279
|
+
color: #8b949e;
|
|
280
|
+
background: rgba(139, 148, 158, 0.14);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.jp-col-source {
|
|
284
|
+
color: #7ee787;
|
|
285
|
+
background: rgba(63, 185, 80, 0.1);
|
|
286
|
+
border: 1px solid rgba(63, 185, 80, 0.24);
|
|
287
|
+
border-radius: 4px;
|
|
288
|
+
padding: 0 5px;
|
|
289
|
+
font-size: 11px;
|
|
290
|
+
flex-shrink: 0;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.jp-log-row[data-source="daemon"] .jp-col-source {
|
|
294
|
+
color: #a5d6ff;
|
|
295
|
+
background: rgba(56, 139, 253, 0.1);
|
|
296
|
+
border-color: rgba(56, 139, 253, 0.25);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
.jp-col-msg {
|
|
300
|
+
color: #e6edf3;
|
|
301
|
+
flex: 1 1 auto;
|
|
302
|
+
min-width: 0;
|
|
303
|
+
}
|
|
304
|
+
`;
|
|
305
|
+
function normalizeLevel(level) {
|
|
306
|
+
const upper = (level ?? 'INFO').trim().toUpperCase();
|
|
307
|
+
if (upper === 'WARNING')
|
|
308
|
+
return 'WARN';
|
|
309
|
+
if (upper === 'CRITICAL' || upper === 'FATAL')
|
|
310
|
+
return 'ERROR';
|
|
311
|
+
if (upper === 'INFO' || upper === 'WARN' || upper === 'ERROR' || upper === 'DEBUG' || upper === 'TRACE') {
|
|
312
|
+
return upper;
|
|
313
|
+
}
|
|
314
|
+
return upper || 'INFO';
|
|
315
|
+
}
|
|
316
|
+
function formatTimestamp(timestampMs) {
|
|
317
|
+
const date = new Date(Number.isFinite(timestampMs) && timestampMs > 0 ? timestampMs : Date.now());
|
|
318
|
+
const hh = String(date.getHours()).padStart(2, '0');
|
|
319
|
+
const mm = String(date.getMinutes()).padStart(2, '0');
|
|
320
|
+
const ss = String(date.getSeconds()).padStart(2, '0');
|
|
321
|
+
const ms = String(date.getMilliseconds()).padStart(3, '0');
|
|
322
|
+
return `${hh}:${mm}:${ss}.${ms}`;
|
|
323
|
+
}
|
|
324
|
+
function matchesSourceFilter(source, filter) {
|
|
325
|
+
if (filter === 'all')
|
|
326
|
+
return true;
|
|
327
|
+
const isDaemon = source.trim().toLowerCase() === 'daemon';
|
|
328
|
+
return filter === 'daemon' ? isDaemon : !isDaemon;
|
|
329
|
+
}
|
|
330
|
+
async function defaultCopyToClipboard(text) {
|
|
331
|
+
const nav = globalThis.navigator;
|
|
332
|
+
if (!nav?.clipboard?.writeText) {
|
|
333
|
+
throw new Error('Clipboard API is unavailable in this environment');
|
|
334
|
+
}
|
|
335
|
+
await nav.clipboard.writeText(text);
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Shadow-DOM isolated bottom drawer rendering live sanitized daemon and worker logs
|
|
339
|
+
* exclusively when Developer Mode is active.
|
|
340
|
+
*/
|
|
341
|
+
export class JetPackLogTerminal {
|
|
342
|
+
options;
|
|
343
|
+
developerMode;
|
|
344
|
+
expanded;
|
|
345
|
+
sourceFilter;
|
|
346
|
+
maxEntries;
|
|
347
|
+
entries = [];
|
|
348
|
+
unreadWarnErrorCount = 0;
|
|
349
|
+
autoScrollEnabled = true;
|
|
350
|
+
copyResetTimer = null;
|
|
351
|
+
host = null;
|
|
352
|
+
shadow = null;
|
|
353
|
+
terminalEl = null;
|
|
354
|
+
headerBtnEl = null;
|
|
355
|
+
titleEl = null;
|
|
356
|
+
unreadBadgeEl = null;
|
|
357
|
+
totalCountEl = null;
|
|
358
|
+
chevronEl = null;
|
|
359
|
+
bodyEl = null;
|
|
360
|
+
filterButtons = new Map();
|
|
361
|
+
copyBtnEl = null;
|
|
362
|
+
viewportEl = null;
|
|
363
|
+
listEl = null;
|
|
364
|
+
emptyEl = null;
|
|
365
|
+
resizeObserver = null;
|
|
366
|
+
windowResizeHandler = null;
|
|
367
|
+
reservedContainer = null;
|
|
368
|
+
savedInlinePaddingBottom = '';
|
|
369
|
+
lastAppliedOffsetPx = 0;
|
|
370
|
+
constructor(options = {}) {
|
|
371
|
+
this.options = { ...options };
|
|
372
|
+
this.developerMode = Boolean(options.developerMode ?? false);
|
|
373
|
+
this.expanded = Boolean(options.expanded ?? false);
|
|
374
|
+
this.sourceFilter = options.sourceFilter ?? 'all';
|
|
375
|
+
this.maxEntries = Math.max(1, options.maxEntries ?? DEFAULT_MAX_ENTRIES);
|
|
376
|
+
if (typeof document !== 'undefined' && options.mountTarget !== null) {
|
|
377
|
+
this.mount(options.mountTarget);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
/** Mounts the terminal host element at the end of `target` (or `document.body`). */
|
|
381
|
+
mount(target) {
|
|
382
|
+
if (typeof document === 'undefined') {
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
const container = target ?? this.options.mountTarget ?? document.body;
|
|
386
|
+
if (!container) {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
if (!this.host) {
|
|
390
|
+
this.buildDom();
|
|
391
|
+
}
|
|
392
|
+
if (!this.host) {
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
if (this.host.parentNode !== container) {
|
|
396
|
+
if (this.reservedContainer && this.reservedContainer !== container) {
|
|
397
|
+
this.clearPageReservation();
|
|
398
|
+
}
|
|
399
|
+
container.appendChild(this.host);
|
|
400
|
+
}
|
|
401
|
+
this.attachResizeTracking();
|
|
402
|
+
this.syncVisibility();
|
|
403
|
+
this.syncLayoutState();
|
|
404
|
+
this.renderVisibleEntries();
|
|
405
|
+
return true;
|
|
406
|
+
}
|
|
407
|
+
/** Unmounts the terminal host element and clears internal timers and layout reservations. */
|
|
408
|
+
unmount() {
|
|
409
|
+
if (this.copyResetTimer !== null) {
|
|
410
|
+
clearTimeout(this.copyResetTimer);
|
|
411
|
+
this.copyResetTimer = null;
|
|
412
|
+
}
|
|
413
|
+
this.detachResizeTracking();
|
|
414
|
+
this.clearPageReservation();
|
|
415
|
+
if (this.host && this.host.parentNode) {
|
|
416
|
+
this.host.parentNode.removeChild(this.host);
|
|
417
|
+
}
|
|
418
|
+
this.host = null;
|
|
419
|
+
this.shadow = null;
|
|
420
|
+
this.terminalEl = null;
|
|
421
|
+
this.headerBtnEl = null;
|
|
422
|
+
this.titleEl = null;
|
|
423
|
+
this.unreadBadgeEl = null;
|
|
424
|
+
this.totalCountEl = null;
|
|
425
|
+
this.chevronEl = null;
|
|
426
|
+
this.bodyEl = null;
|
|
427
|
+
this.filterButtons.clear();
|
|
428
|
+
this.copyBtnEl = null;
|
|
429
|
+
this.viewportEl = null;
|
|
430
|
+
this.listEl = null;
|
|
431
|
+
this.emptyEl = null;
|
|
432
|
+
}
|
|
433
|
+
/** Shows or hides the bottom drawer strictly based on `developerMode`. */
|
|
434
|
+
setDeveloperMode(enabled) {
|
|
435
|
+
const next = Boolean(enabled);
|
|
436
|
+
this.developerMode = next;
|
|
437
|
+
if (!next) {
|
|
438
|
+
this.expanded = false;
|
|
439
|
+
}
|
|
440
|
+
this.syncVisibility();
|
|
441
|
+
this.syncLayoutState();
|
|
442
|
+
}
|
|
443
|
+
/** Returns whether Developer Mode visibility is enabled. */
|
|
444
|
+
isDeveloperMode() {
|
|
445
|
+
return this.developerMode;
|
|
446
|
+
}
|
|
447
|
+
/** Expands or collapses the drawer body, resetting unread warnings/errors when opened. */
|
|
448
|
+
setExpanded(expanded) {
|
|
449
|
+
this.expanded = Boolean(expanded);
|
|
450
|
+
if (this.expanded) {
|
|
451
|
+
this.unreadWarnErrorCount = 0;
|
|
452
|
+
this.autoScrollEnabled = true;
|
|
453
|
+
}
|
|
454
|
+
this.syncLayoutState();
|
|
455
|
+
if (this.expanded) {
|
|
456
|
+
this.scrollToBottom();
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
/** Toggles between collapsed header bar and expanded log viewer. */
|
|
460
|
+
toggle() {
|
|
461
|
+
this.setExpanded(!this.expanded);
|
|
462
|
+
}
|
|
463
|
+
/** Returns whether the log drawer is currently expanded. */
|
|
464
|
+
isExpanded() {
|
|
465
|
+
return this.expanded;
|
|
466
|
+
}
|
|
467
|
+
/** Sets the active source filter (`'all' | 'daemon' | 'worker'`) and refreshes displayed rows. */
|
|
468
|
+
setSourceFilter(filter) {
|
|
469
|
+
if (this.sourceFilter === filter) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
this.sourceFilter = filter;
|
|
473
|
+
this.syncLayoutState();
|
|
474
|
+
this.renderVisibleEntries();
|
|
475
|
+
}
|
|
476
|
+
/** Returns the currently active source filter. */
|
|
477
|
+
getSourceFilter() {
|
|
478
|
+
return this.sourceFilter;
|
|
479
|
+
}
|
|
480
|
+
/** Returns the unread `WARN`/`ERROR` counter accumulated while collapsed. */
|
|
481
|
+
getUnreadWarningErrorCount() {
|
|
482
|
+
return this.unreadWarnErrorCount;
|
|
483
|
+
}
|
|
484
|
+
/** Returns a shallow copy of all buffered log entries. */
|
|
485
|
+
getEntries() {
|
|
486
|
+
return this.entries.map((e) => ({ ...e }));
|
|
487
|
+
}
|
|
488
|
+
/** Returns log entries matching the currently active source filter. */
|
|
489
|
+
getVisibleEntries() {
|
|
490
|
+
return this.entries.filter((e) => matchesSourceFilter(e.source, this.sourceFilter));
|
|
491
|
+
}
|
|
492
|
+
/** Appends a sanitized `LogEntry` to the buffer and updates DOM & unread counters. */
|
|
493
|
+
appendEntry(entry) {
|
|
494
|
+
const normalized = {
|
|
495
|
+
timestamp_ms: typeof entry.timestamp_ms === 'number' ? entry.timestamp_ms : Date.now(),
|
|
496
|
+
level: normalizeLevel(entry.level),
|
|
497
|
+
source: (entry.source || 'daemon').trim() || 'daemon',
|
|
498
|
+
message: String(entry.message ?? ''),
|
|
499
|
+
};
|
|
500
|
+
const evicted = this.entries.length >= this.maxEntries;
|
|
501
|
+
if (evicted) {
|
|
502
|
+
this.entries.shift();
|
|
503
|
+
}
|
|
504
|
+
this.entries.push(normalized);
|
|
505
|
+
if (!this.expanded && (normalized.level === 'WARN' || normalized.level === 'ERROR')) {
|
|
506
|
+
this.unreadWarnErrorCount += 1;
|
|
507
|
+
}
|
|
508
|
+
if (evicted) {
|
|
509
|
+
this.renderVisibleEntries();
|
|
510
|
+
}
|
|
511
|
+
else if (this.listEl && matchesSourceFilter(normalized.source, this.sourceFilter)) {
|
|
512
|
+
this.listEl.appendChild(this.createLogRowElement(normalized));
|
|
513
|
+
this.syncEmptyState();
|
|
514
|
+
if (this.expanded && this.autoScrollEnabled) {
|
|
515
|
+
this.scrollToBottom();
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
this.syncCounts();
|
|
519
|
+
}
|
|
520
|
+
/** Clears all buffered log rows and resets unread counters. */
|
|
521
|
+
clear() {
|
|
522
|
+
this.entries = [];
|
|
523
|
+
this.unreadWarnErrorCount = 0;
|
|
524
|
+
this.renderVisibleEntries();
|
|
525
|
+
this.syncCounts();
|
|
526
|
+
}
|
|
527
|
+
/** Formats the entire buffered log history as plain text for clipboard export. */
|
|
528
|
+
formatAllLogsText() {
|
|
529
|
+
return this.entries
|
|
530
|
+
.map((entry) => `[${formatTimestamp(entry.timestamp_ms)}] [${normalizeLevel(entry.level)}] [${entry.source}] ${entry.message}`)
|
|
531
|
+
.join('\n');
|
|
532
|
+
}
|
|
533
|
+
/** Copies the entire buffered log history to the clipboard and displays `"Copied!"` feedback. */
|
|
534
|
+
async copyLogs() {
|
|
535
|
+
const text = this.formatAllLogsText();
|
|
536
|
+
const copyFn = this.options.copyToClipboard ?? defaultCopyToClipboard;
|
|
537
|
+
try {
|
|
538
|
+
await copyFn(text);
|
|
539
|
+
if (this.copyBtnEl) {
|
|
540
|
+
this.copyBtnEl.textContent = 'Copied!';
|
|
541
|
+
this.copyBtnEl.setAttribute('data-copied', 'true');
|
|
542
|
+
}
|
|
543
|
+
if (this.copyResetTimer !== null) {
|
|
544
|
+
clearTimeout(this.copyResetTimer);
|
|
545
|
+
}
|
|
546
|
+
this.copyResetTimer = setTimeout(() => {
|
|
547
|
+
this.copyResetTimer = null;
|
|
548
|
+
if (this.copyBtnEl) {
|
|
549
|
+
this.copyBtnEl.textContent = 'Copy Logs';
|
|
550
|
+
this.copyBtnEl.removeAttribute('data-copied');
|
|
551
|
+
}
|
|
552
|
+
}, COPIED_RESET_DELAY_MS);
|
|
553
|
+
this.options.onCopySuccess?.(text);
|
|
554
|
+
return true;
|
|
555
|
+
}
|
|
556
|
+
catch (err) {
|
|
557
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
558
|
+
this.options.onCopyError?.(error);
|
|
559
|
+
return false;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
/** Updates mutable options without clearing buffered log entries. */
|
|
563
|
+
updateOptions(partial) {
|
|
564
|
+
this.options = { ...this.options, ...partial };
|
|
565
|
+
if (partial.maxEntries !== undefined) {
|
|
566
|
+
this.maxEntries = Math.max(1, partial.maxEntries);
|
|
567
|
+
if (this.entries.length > this.maxEntries) {
|
|
568
|
+
this.entries = this.entries.slice(this.entries.length - this.maxEntries);
|
|
569
|
+
this.renderVisibleEntries();
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
if (partial.developerMode !== undefined) {
|
|
573
|
+
this.developerMode = Boolean(partial.developerMode);
|
|
574
|
+
if (!this.developerMode) {
|
|
575
|
+
this.expanded = false;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
if (partial.sourceFilter !== undefined) {
|
|
579
|
+
this.sourceFilter = partial.sourceFilter;
|
|
580
|
+
this.renderVisibleEntries();
|
|
581
|
+
}
|
|
582
|
+
if (this.titleEl) {
|
|
583
|
+
this.titleEl.textContent = this.options.title ?? DEFAULT_TITLE;
|
|
584
|
+
}
|
|
585
|
+
this.syncVisibility();
|
|
586
|
+
this.syncLayoutState();
|
|
587
|
+
this.syncCounts();
|
|
588
|
+
}
|
|
589
|
+
/** Returns the mounted host element, or `null` when unmounted. */
|
|
590
|
+
getHostElement() {
|
|
591
|
+
return this.host;
|
|
592
|
+
}
|
|
593
|
+
/** Returns the open ShadowRoot isolating styles and DOM. */
|
|
594
|
+
getShadowRoot() {
|
|
595
|
+
return this.shadow;
|
|
596
|
+
}
|
|
597
|
+
buildDom() {
|
|
598
|
+
const host = document.createElement('div');
|
|
599
|
+
host.id = 'jetpack-log-terminal-host';
|
|
600
|
+
host.setAttribute('data-jetpack-log-terminal', 'true');
|
|
601
|
+
const shadow = host.attachShadow({ mode: 'open' });
|
|
602
|
+
const style = document.createElement('style');
|
|
603
|
+
style.textContent = LOG_TERMINAL_STYLES;
|
|
604
|
+
shadow.appendChild(style);
|
|
605
|
+
const terminal = document.createElement('section');
|
|
606
|
+
terminal.className = 'jp-terminal';
|
|
607
|
+
terminal.setAttribute('data-jp-field', 'terminal');
|
|
608
|
+
terminal.setAttribute('aria-label', 'JetPack Live Logs');
|
|
609
|
+
const headerBtn = document.createElement('button');
|
|
610
|
+
headerBtn.type = 'button';
|
|
611
|
+
headerBtn.className = 'jp-header';
|
|
612
|
+
headerBtn.setAttribute('data-jp-action', 'toggle');
|
|
613
|
+
headerBtn.addEventListener('click', () => {
|
|
614
|
+
this.toggle();
|
|
615
|
+
});
|
|
616
|
+
const headerLeft = document.createElement('span');
|
|
617
|
+
headerLeft.className = 'jp-header-left';
|
|
618
|
+
const dot = document.createElement('span');
|
|
619
|
+
dot.className = 'jp-dot';
|
|
620
|
+
dot.setAttribute('aria-hidden', 'true');
|
|
621
|
+
const titleEl = document.createElement('span');
|
|
622
|
+
titleEl.className = 'jp-title';
|
|
623
|
+
titleEl.setAttribute('data-jp-field', 'title');
|
|
624
|
+
titleEl.textContent = this.options.title ?? DEFAULT_TITLE;
|
|
625
|
+
const devTag = document.createElement('span');
|
|
626
|
+
devTag.className = 'jp-dev-tag';
|
|
627
|
+
devTag.textContent = 'Dev Mode';
|
|
628
|
+
headerLeft.appendChild(dot);
|
|
629
|
+
headerLeft.appendChild(titleEl);
|
|
630
|
+
headerLeft.appendChild(devTag);
|
|
631
|
+
const headerRight = document.createElement('span');
|
|
632
|
+
headerRight.className = 'jp-header-right';
|
|
633
|
+
const unreadBadge = document.createElement('span');
|
|
634
|
+
unreadBadge.className = 'jp-unread-badge';
|
|
635
|
+
unreadBadge.setAttribute('data-jp-field', 'unread-badge');
|
|
636
|
+
unreadBadge.hidden = true;
|
|
637
|
+
const totalCount = document.createElement('span');
|
|
638
|
+
totalCount.className = 'jp-total-count';
|
|
639
|
+
totalCount.setAttribute('data-jp-field', 'total-count');
|
|
640
|
+
const chevron = document.createElement('span');
|
|
641
|
+
chevron.className = 'jp-chevron';
|
|
642
|
+
chevron.setAttribute('data-jp-field', 'chevron');
|
|
643
|
+
headerRight.appendChild(unreadBadge);
|
|
644
|
+
headerRight.appendChild(totalCount);
|
|
645
|
+
headerRight.appendChild(chevron);
|
|
646
|
+
headerBtn.appendChild(headerLeft);
|
|
647
|
+
headerBtn.appendChild(headerRight);
|
|
648
|
+
const body = document.createElement('div');
|
|
649
|
+
body.className = 'jp-body';
|
|
650
|
+
body.setAttribute('data-jp-field', 'drawer-body');
|
|
651
|
+
body.hidden = true;
|
|
652
|
+
const toolbar = document.createElement('div');
|
|
653
|
+
toolbar.className = 'jp-toolbar';
|
|
654
|
+
const filters = document.createElement('div');
|
|
655
|
+
filters.className = 'jp-filters';
|
|
656
|
+
const filterSpecs = [
|
|
657
|
+
{ key: 'all', label: 'All' },
|
|
658
|
+
{ key: 'daemon', label: 'Daemon' },
|
|
659
|
+
{ key: 'worker', label: 'Worker' },
|
|
660
|
+
];
|
|
661
|
+
this.filterButtons.clear();
|
|
662
|
+
for (const spec of filterSpecs) {
|
|
663
|
+
const btn = document.createElement('button');
|
|
664
|
+
btn.type = 'button';
|
|
665
|
+
btn.className = 'jp-filter-btn';
|
|
666
|
+
btn.setAttribute('data-jp-action', 'filter');
|
|
667
|
+
btn.setAttribute('data-jp-filter', spec.key);
|
|
668
|
+
btn.textContent = spec.label;
|
|
669
|
+
btn.addEventListener('click', () => {
|
|
670
|
+
this.setSourceFilter(spec.key);
|
|
671
|
+
});
|
|
672
|
+
this.filterButtons.set(spec.key, btn);
|
|
673
|
+
filters.appendChild(btn);
|
|
674
|
+
}
|
|
675
|
+
const actions = document.createElement('div');
|
|
676
|
+
actions.className = 'jp-actions';
|
|
677
|
+
const clearBtn = document.createElement('button');
|
|
678
|
+
clearBtn.type = 'button';
|
|
679
|
+
clearBtn.className = 'jp-action-btn';
|
|
680
|
+
clearBtn.setAttribute('data-jp-action', 'clear');
|
|
681
|
+
clearBtn.textContent = 'Clear';
|
|
682
|
+
clearBtn.addEventListener('click', () => {
|
|
683
|
+
this.clear();
|
|
684
|
+
});
|
|
685
|
+
const copyBtn = document.createElement('button');
|
|
686
|
+
copyBtn.type = 'button';
|
|
687
|
+
copyBtn.className = 'jp-action-btn';
|
|
688
|
+
copyBtn.setAttribute('data-jp-action', 'copy');
|
|
689
|
+
copyBtn.textContent = 'Copy Logs';
|
|
690
|
+
copyBtn.addEventListener('click', () => {
|
|
691
|
+
void this.copyLogs();
|
|
692
|
+
});
|
|
693
|
+
actions.appendChild(clearBtn);
|
|
694
|
+
actions.appendChild(copyBtn);
|
|
695
|
+
toolbar.appendChild(filters);
|
|
696
|
+
toolbar.appendChild(actions);
|
|
697
|
+
const viewport = document.createElement('div');
|
|
698
|
+
viewport.className = 'jp-viewport';
|
|
699
|
+
viewport.setAttribute('data-jp-field', 'viewport');
|
|
700
|
+
viewport.addEventListener('scroll', () => {
|
|
701
|
+
const vp = this.viewportEl;
|
|
702
|
+
if (!vp)
|
|
703
|
+
return;
|
|
704
|
+
const scrollHeight = typeof vp.scrollHeight === 'number' ? vp.scrollHeight : 0;
|
|
705
|
+
const clientHeight = typeof vp.clientHeight === 'number' ? vp.clientHeight : 0;
|
|
706
|
+
if (scrollHeight > clientHeight && clientHeight > 0) {
|
|
707
|
+
const distanceFromBottom = scrollHeight - (vp.scrollTop + clientHeight);
|
|
708
|
+
this.autoScrollEnabled = distanceFromBottom <= 24;
|
|
709
|
+
}
|
|
710
|
+
});
|
|
711
|
+
const empty = document.createElement('div');
|
|
712
|
+
empty.className = 'jp-empty';
|
|
713
|
+
empty.setAttribute('data-jp-field', 'empty-state');
|
|
714
|
+
empty.textContent = 'No log entries yet.';
|
|
715
|
+
const list = document.createElement('div');
|
|
716
|
+
list.setAttribute('data-jp-field', 'log-list');
|
|
717
|
+
viewport.appendChild(empty);
|
|
718
|
+
viewport.appendChild(list);
|
|
719
|
+
body.appendChild(toolbar);
|
|
720
|
+
body.appendChild(viewport);
|
|
721
|
+
terminal.appendChild(headerBtn);
|
|
722
|
+
terminal.appendChild(body);
|
|
723
|
+
shadow.appendChild(terminal);
|
|
724
|
+
this.host = host;
|
|
725
|
+
this.shadow = shadow;
|
|
726
|
+
this.terminalEl = terminal;
|
|
727
|
+
this.headerBtnEl = headerBtn;
|
|
728
|
+
this.titleEl = titleEl;
|
|
729
|
+
this.unreadBadgeEl = unreadBadge;
|
|
730
|
+
this.totalCountEl = totalCount;
|
|
731
|
+
this.chevronEl = chevron;
|
|
732
|
+
this.bodyEl = body;
|
|
733
|
+
this.copyBtnEl = copyBtn;
|
|
734
|
+
this.viewportEl = viewport;
|
|
735
|
+
this.listEl = list;
|
|
736
|
+
this.emptyEl = empty;
|
|
737
|
+
}
|
|
738
|
+
createLogRowElement(entry) {
|
|
739
|
+
const level = normalizeLevel(entry.level);
|
|
740
|
+
const source = (entry.source || 'daemon').trim() || 'daemon';
|
|
741
|
+
const row = document.createElement('div');
|
|
742
|
+
row.className = 'jp-log-row';
|
|
743
|
+
row.setAttribute('data-jp-field', 'log-row');
|
|
744
|
+
row.setAttribute('data-level', level);
|
|
745
|
+
row.setAttribute('data-source', source);
|
|
746
|
+
const timeSpan = document.createElement('span');
|
|
747
|
+
timeSpan.className = 'jp-col-time';
|
|
748
|
+
timeSpan.textContent = formatTimestamp(entry.timestamp_ms);
|
|
749
|
+
const levelSpan = document.createElement('span');
|
|
750
|
+
levelSpan.className = 'jp-col-level';
|
|
751
|
+
levelSpan.setAttribute('data-jp-col', 'level');
|
|
752
|
+
levelSpan.textContent = level;
|
|
753
|
+
const sourceSpan = document.createElement('span');
|
|
754
|
+
sourceSpan.className = 'jp-col-source';
|
|
755
|
+
sourceSpan.setAttribute('data-jp-col', 'source');
|
|
756
|
+
sourceSpan.textContent = source;
|
|
757
|
+
const msgSpan = document.createElement('span');
|
|
758
|
+
msgSpan.className = 'jp-col-msg';
|
|
759
|
+
msgSpan.setAttribute('data-jp-col', 'message');
|
|
760
|
+
msgSpan.textContent = entry.message;
|
|
761
|
+
row.appendChild(timeSpan);
|
|
762
|
+
row.appendChild(levelSpan);
|
|
763
|
+
row.appendChild(sourceSpan);
|
|
764
|
+
row.appendChild(msgSpan);
|
|
765
|
+
return row;
|
|
766
|
+
}
|
|
767
|
+
renderVisibleEntries() {
|
|
768
|
+
if (!this.listEl)
|
|
769
|
+
return;
|
|
770
|
+
while (this.listEl.children.length > 0) {
|
|
771
|
+
const first = this.listEl.firstChild;
|
|
772
|
+
if (!first)
|
|
773
|
+
break;
|
|
774
|
+
this.listEl.removeChild(first);
|
|
775
|
+
}
|
|
776
|
+
const visible = this.getVisibleEntries();
|
|
777
|
+
for (const entry of visible) {
|
|
778
|
+
this.listEl.appendChild(this.createLogRowElement(entry));
|
|
779
|
+
}
|
|
780
|
+
this.syncEmptyState();
|
|
781
|
+
if (this.expanded && this.autoScrollEnabled) {
|
|
782
|
+
this.scrollToBottom();
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
syncVisibility() {
|
|
786
|
+
if (!this.host)
|
|
787
|
+
return;
|
|
788
|
+
this.host.hidden = !this.developerMode;
|
|
789
|
+
this.host.style.display = this.developerMode ? 'block' : 'none';
|
|
790
|
+
this.host.setAttribute('data-developer-mode', this.developerMode ? 'true' : 'false');
|
|
791
|
+
}
|
|
792
|
+
syncLayoutState() {
|
|
793
|
+
if (this.terminalEl) {
|
|
794
|
+
this.terminalEl.setAttribute('data-expanded', this.expanded ? 'true' : 'false');
|
|
795
|
+
}
|
|
796
|
+
if (this.headerBtnEl) {
|
|
797
|
+
this.headerBtnEl.setAttribute('aria-expanded', this.expanded ? 'true' : 'false');
|
|
798
|
+
}
|
|
799
|
+
if (this.bodyEl) {
|
|
800
|
+
this.bodyEl.hidden = !this.expanded;
|
|
801
|
+
}
|
|
802
|
+
if (this.chevronEl) {
|
|
803
|
+
this.chevronEl.textContent = this.expanded ? '▼' : '▲';
|
|
804
|
+
}
|
|
805
|
+
for (const [key, btn] of this.filterButtons.entries()) {
|
|
806
|
+
const active = key === this.sourceFilter;
|
|
807
|
+
btn.setAttribute('data-active', active ? 'true' : 'false');
|
|
808
|
+
btn.setAttribute('aria-pressed', active ? 'true' : 'false');
|
|
809
|
+
}
|
|
810
|
+
this.syncCounts();
|
|
811
|
+
this.syncPageReservation();
|
|
812
|
+
}
|
|
813
|
+
attachResizeTracking() {
|
|
814
|
+
if (typeof ResizeObserver === 'function' && this.terminalEl && !this.resizeObserver) {
|
|
815
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
816
|
+
this.syncPageReservation();
|
|
817
|
+
});
|
|
818
|
+
this.resizeObserver.observe(this.terminalEl);
|
|
819
|
+
}
|
|
820
|
+
if (typeof window !== 'undefined' &&
|
|
821
|
+
typeof window.addEventListener === 'function' &&
|
|
822
|
+
!this.windowResizeHandler) {
|
|
823
|
+
this.windowResizeHandler = () => {
|
|
824
|
+
this.syncPageReservation();
|
|
825
|
+
};
|
|
826
|
+
window.addEventListener('resize', this.windowResizeHandler);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
detachResizeTracking() {
|
|
830
|
+
if (this.resizeObserver) {
|
|
831
|
+
this.resizeObserver.disconnect();
|
|
832
|
+
this.resizeObserver = null;
|
|
833
|
+
}
|
|
834
|
+
if (this.windowResizeHandler &&
|
|
835
|
+
typeof window !== 'undefined' &&
|
|
836
|
+
typeof window.removeEventListener === 'function') {
|
|
837
|
+
window.removeEventListener('resize', this.windowResizeHandler);
|
|
838
|
+
}
|
|
839
|
+
this.windowResizeHandler = null;
|
|
840
|
+
}
|
|
841
|
+
getMountContainer() {
|
|
842
|
+
const parent = this.host?.parentNode;
|
|
843
|
+
if (parent && typeof parent.style === 'object' && parent.style !== null) {
|
|
844
|
+
return parent;
|
|
845
|
+
}
|
|
846
|
+
return null;
|
|
847
|
+
}
|
|
848
|
+
measureTerminalHeight() {
|
|
849
|
+
if (!this.terminalEl || !this.developerMode || !this.host || this.host.hidden) {
|
|
850
|
+
return 0;
|
|
851
|
+
}
|
|
852
|
+
const rectHeight = typeof this.terminalEl.getBoundingClientRect === 'function'
|
|
853
|
+
? this.terminalEl.getBoundingClientRect().height
|
|
854
|
+
: 0;
|
|
855
|
+
const offsetHeight = typeof this.terminalEl.offsetHeight === 'number'
|
|
856
|
+
? (this.terminalEl.offsetHeight ?? 0)
|
|
857
|
+
: 0;
|
|
858
|
+
const measured = Math.ceil(Math.max(rectHeight, offsetHeight));
|
|
859
|
+
if (measured > 0) {
|
|
860
|
+
return measured;
|
|
861
|
+
}
|
|
862
|
+
return this.expanded ? FALLBACK_EXPANDED_HEIGHT_PX : FALLBACK_COLLAPSED_HEIGHT_PX;
|
|
863
|
+
}
|
|
864
|
+
syncPageReservation() {
|
|
865
|
+
const container = this.getMountContainer();
|
|
866
|
+
if (!container || !this.developerMode) {
|
|
867
|
+
this.clearPageReservation();
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
const offsetPx = this.measureTerminalHeight();
|
|
871
|
+
if (offsetPx <= 0) {
|
|
872
|
+
this.clearPageReservation();
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
875
|
+
if (this.reservedContainer && this.reservedContainer !== container) {
|
|
876
|
+
this.clearPageReservation();
|
|
877
|
+
}
|
|
878
|
+
if (this.reservedContainer === container && this.lastAppliedOffsetPx === offsetPx) {
|
|
879
|
+
this.setRootOffsetCssVar(offsetPx);
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
if (this.reservedContainer !== container) {
|
|
883
|
+
this.reservedContainer = container;
|
|
884
|
+
this.savedInlinePaddingBottom = container.style.paddingBottom ?? '';
|
|
885
|
+
this.lastAppliedOffsetPx = 0;
|
|
886
|
+
}
|
|
887
|
+
// Restore original inline paddingBottom before reading computed style so
|
|
888
|
+
// underlying CSS padding is preserved without double-counting across updates.
|
|
889
|
+
container.style.paddingBottom = this.savedInlinePaddingBottom;
|
|
890
|
+
const basePaddingPx = this.readComputedPaddingBottomPx(container);
|
|
891
|
+
container.style.paddingBottom = `${basePaddingPx + offsetPx}px`;
|
|
892
|
+
this.lastAppliedOffsetPx = offsetPx;
|
|
893
|
+
this.setRootOffsetCssVar(offsetPx);
|
|
894
|
+
}
|
|
895
|
+
clearPageReservation() {
|
|
896
|
+
if (this.reservedContainer) {
|
|
897
|
+
this.reservedContainer.style.paddingBottom = this.savedInlinePaddingBottom;
|
|
898
|
+
this.reservedContainer = null;
|
|
899
|
+
this.savedInlinePaddingBottom = '';
|
|
900
|
+
this.lastAppliedOffsetPx = 0;
|
|
901
|
+
}
|
|
902
|
+
this.setRootOffsetCssVar(0);
|
|
903
|
+
}
|
|
904
|
+
readComputedPaddingBottomPx(container) {
|
|
905
|
+
if (typeof getComputedStyle === 'function') {
|
|
906
|
+
try {
|
|
907
|
+
const raw = getComputedStyle(container).paddingBottom;
|
|
908
|
+
const parsed = Number.parseFloat(raw);
|
|
909
|
+
if (Number.isFinite(parsed) && parsed >= 0) {
|
|
910
|
+
return parsed;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
catch {
|
|
914
|
+
// Ignore in mock DOM environments where container is not a native Element
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
const inlineParsed = Number.parseFloat(this.savedInlinePaddingBottom);
|
|
918
|
+
return Number.isFinite(inlineParsed) && inlineParsed >= 0 ? inlineParsed : 0;
|
|
919
|
+
}
|
|
920
|
+
setRootOffsetCssVar(offsetPx) {
|
|
921
|
+
if (typeof document === 'undefined')
|
|
922
|
+
return;
|
|
923
|
+
const rootStyle = document.documentElement?.style;
|
|
924
|
+
if (!rootStyle)
|
|
925
|
+
return;
|
|
926
|
+
if (offsetPx > 0) {
|
|
927
|
+
rootStyle.setProperty?.(LOG_TERMINAL_OFFSET_CSS_VAR, `${offsetPx}px`);
|
|
928
|
+
}
|
|
929
|
+
else {
|
|
930
|
+
rootStyle.removeProperty?.(LOG_TERMINAL_OFFSET_CSS_VAR);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
syncCounts() {
|
|
934
|
+
if (this.unreadBadgeEl) {
|
|
935
|
+
if (this.unreadWarnErrorCount > 0 && !this.expanded) {
|
|
936
|
+
this.unreadBadgeEl.hidden = false;
|
|
937
|
+
this.unreadBadgeEl.textContent = String(this.unreadWarnErrorCount);
|
|
938
|
+
}
|
|
939
|
+
else {
|
|
940
|
+
this.unreadBadgeEl.hidden = true;
|
|
941
|
+
this.unreadBadgeEl.textContent = '0';
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
if (this.totalCountEl) {
|
|
945
|
+
this.totalCountEl.textContent = `${this.entries.length} line${this.entries.length === 1 ? '' : 's'}`;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
syncEmptyState() {
|
|
949
|
+
if (!this.emptyEl || !this.listEl)
|
|
950
|
+
return;
|
|
951
|
+
this.emptyEl.hidden = this.listEl.children.length > 0;
|
|
952
|
+
}
|
|
953
|
+
scrollToBottom() {
|
|
954
|
+
if (!this.viewportEl)
|
|
955
|
+
return;
|
|
956
|
+
const targetHeight = typeof this.viewportEl.scrollHeight === 'number' ? this.viewportEl.scrollHeight : 0;
|
|
957
|
+
this.viewportEl.scrollTop = targetHeight;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
//# sourceMappingURL=log-terminal.js.map
|