@design.estate/dees-wcctools 1.2.0 → 1.3.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.
Files changed (35) hide show
  1. package/dist_bundle/bundle.js +1700 -264
  2. package/dist_bundle/bundle.js.map +4 -4
  3. package/dist_ts_demotools/demotools.d.ts +1 -1
  4. package/dist_ts_demotools/demotools.js +86 -38
  5. package/dist_ts_web/00_commitinfo_data.js +1 -1
  6. package/dist_ts_web/elements/wcc-dashboard.d.ts +10 -10
  7. package/dist_ts_web/elements/wcc-dashboard.js +317 -245
  8. package/dist_ts_web/elements/wcc-frame.d.ts +3 -3
  9. package/dist_ts_web/elements/wcc-frame.js +108 -57
  10. package/dist_ts_web/elements/wcc-properties.d.ts +14 -8
  11. package/dist_ts_web/elements/wcc-properties.js +442 -323
  12. package/dist_ts_web/elements/wcc-record-button.d.ts +12 -0
  13. package/dist_ts_web/elements/wcc-record-button.js +165 -0
  14. package/dist_ts_web/elements/wcc-recording-panel.d.ts +42 -0
  15. package/dist_ts_web/elements/wcc-recording-panel.js +1063 -0
  16. package/dist_ts_web/elements/wcc-sidebar.d.ts +4 -4
  17. package/dist_ts_web/elements/wcc-sidebar.js +125 -71
  18. package/dist_ts_web/index.d.ts +3 -0
  19. package/dist_ts_web/index.js +5 -1
  20. package/dist_ts_web/services/recorder.service.d.ts +44 -0
  21. package/dist_ts_web/services/recorder.service.js +306 -0
  22. package/dist_watch/bundle.js +1939 -521
  23. package/dist_watch/bundle.js.map +4 -4
  24. package/package.json +10 -10
  25. package/readme.md +133 -141
  26. package/ts_web/00_commitinfo_data.ts +1 -1
  27. package/ts_web/elements/wcc-dashboard.ts +10 -10
  28. package/ts_web/elements/wcc-frame.ts +3 -3
  29. package/ts_web/elements/wcc-properties.ts +53 -9
  30. package/ts_web/elements/wcc-record-button.ts +108 -0
  31. package/ts_web/elements/wcc-recording-panel.ts +974 -0
  32. package/ts_web/elements/wcc-sidebar.ts +4 -4
  33. package/ts_web/index.ts +5 -0
  34. package/ts_web/readme.md +123 -0
  35. package/ts_web/services/recorder.service.ts +391 -0
@@ -0,0 +1,974 @@
1
+ import { DeesElement, customElement, html, css, property, state, type TemplateResult } from '@design.estate/dees-element';
2
+ import { RecorderService } from '../services/recorder.service.js';
3
+ import type { WccDashboard } from './wcc-dashboard.js';
4
+
5
+ @customElement('wcc-recording-panel')
6
+ export class WccRecordingPanel extends DeesElement {
7
+ // External configuration
8
+ @property({ attribute: false })
9
+ accessor dashboardRef: WccDashboard;
10
+
11
+ // Panel state
12
+ @state()
13
+ accessor panelState: 'options' | 'recording' | 'preview' = 'options';
14
+
15
+ // Recording options
16
+ @state()
17
+ accessor recordingMode: 'viewport' | 'screen' = 'viewport';
18
+
19
+ @state()
20
+ accessor audioEnabled: boolean = false;
21
+
22
+ @state()
23
+ accessor selectedMicrophoneId: string = '';
24
+
25
+ @state()
26
+ accessor availableMicrophones: MediaDeviceInfo[] = [];
27
+
28
+ @state()
29
+ accessor audioLevel: number = 0;
30
+
31
+ // Recording state
32
+ @state()
33
+ accessor recordingDuration: number = 0;
34
+
35
+ // Preview/trim state
36
+ @state()
37
+ accessor previewVideoUrl: string = '';
38
+
39
+ @state()
40
+ accessor trimStart: number = 0;
41
+
42
+ @state()
43
+ accessor trimEnd: number = 0;
44
+
45
+ @state()
46
+ accessor videoDuration: number = 0;
47
+
48
+ @state()
49
+ accessor isDraggingTrim: 'start' | 'end' | null = null;
50
+
51
+ @state()
52
+ accessor isExporting: boolean = false;
53
+
54
+ // Service instance
55
+ private recorderService: RecorderService;
56
+
57
+ constructor() {
58
+ super();
59
+ this.recorderService = new RecorderService({
60
+ onDurationUpdate: (duration) => {
61
+ this.recordingDuration = duration;
62
+ this.dispatchEvent(new CustomEvent('duration-update', {
63
+ detail: { duration },
64
+ bubbles: true,
65
+ composed: true
66
+ }));
67
+ },
68
+ onRecordingComplete: (blob) => {
69
+ this.handleRecordingComplete(blob);
70
+ },
71
+ onAudioLevelUpdate: (level) => {
72
+ this.audioLevel = level;
73
+ },
74
+ onStreamEnded: () => {
75
+ this.stopRecording();
76
+ }
77
+ });
78
+ }
79
+
80
+ public static styles = [
81
+ css`
82
+ :host {
83
+ /* CSS Variables */
84
+ --background: #0a0a0a;
85
+ --foreground: #e5e5e5;
86
+ --input: #141414;
87
+ --primary: #3b82f6;
88
+ --border: rgba(255, 255, 255, 0.06);
89
+ --radius-sm: 2px;
90
+ --radius-md: 4px;
91
+ --radius-lg: 6px;
92
+ }
93
+
94
+ /* Recording Options Panel */
95
+ .recording-options-panel {
96
+ position: fixed;
97
+ right: 16px;
98
+ bottom: 116px;
99
+ width: 360px;
100
+ background: #0c0c0c;
101
+ border: 1px solid rgba(255, 255, 255, 0.1);
102
+ border-radius: var(--radius-md);
103
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
104
+ z-index: 1000;
105
+ overflow: hidden;
106
+ font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
107
+ }
108
+
109
+ .recording-options-header {
110
+ padding: 0.75rem 1rem;
111
+ background: rgba(255, 255, 255, 0.02);
112
+ border-bottom: 1px solid rgba(255, 255, 255, 0.05);
113
+ display: flex;
114
+ justify-content: space-between;
115
+ align-items: center;
116
+ }
117
+
118
+ .recording-options-title {
119
+ font-size: 0.8rem;
120
+ font-weight: 500;
121
+ color: #ccc;
122
+ }
123
+
124
+ .recording-options-close {
125
+ width: 24px;
126
+ height: 24px;
127
+ background: transparent;
128
+ border: none;
129
+ color: #666;
130
+ cursor: pointer;
131
+ display: flex;
132
+ align-items: center;
133
+ justify-content: center;
134
+ border-radius: var(--radius-sm);
135
+ transition: all 0.15s ease;
136
+ }
137
+
138
+ .recording-options-close:hover {
139
+ background: rgba(255, 255, 255, 0.05);
140
+ color: #999;
141
+ }
142
+
143
+ .recording-options-content {
144
+ padding: 1rem;
145
+ }
146
+
147
+ .recording-option-group {
148
+ margin-bottom: 1rem;
149
+ }
150
+
151
+ .recording-option-group:last-child {
152
+ margin-bottom: 0;
153
+ }
154
+
155
+ .recording-option-label {
156
+ font-size: 0.7rem;
157
+ font-weight: 500;
158
+ color: #888;
159
+ text-transform: uppercase;
160
+ letter-spacing: 0.05em;
161
+ margin-bottom: 0.5rem;
162
+ }
163
+
164
+ .recording-mode-buttons {
165
+ display: flex;
166
+ gap: 0.5rem;
167
+ }
168
+
169
+ .recording-mode-btn {
170
+ flex: 1;
171
+ padding: 0.6rem 0.75rem;
172
+ background: var(--input);
173
+ border: 1px solid transparent;
174
+ border-radius: var(--radius-sm);
175
+ color: #999;
176
+ font-size: 0.75rem;
177
+ cursor: pointer;
178
+ transition: all 0.15s ease;
179
+ text-align: center;
180
+ }
181
+
182
+ .recording-mode-btn:hover {
183
+ border-color: var(--primary);
184
+ color: #ccc;
185
+ }
186
+
187
+ .recording-mode-btn.selected {
188
+ background: rgba(59, 130, 246, 0.15);
189
+ border-color: var(--primary);
190
+ color: var(--primary);
191
+ }
192
+
193
+ .audio-toggle {
194
+ display: flex;
195
+ align-items: center;
196
+ gap: 0.5rem;
197
+ margin-bottom: 0.75rem;
198
+ }
199
+
200
+ .audio-toggle input[type="checkbox"] {
201
+ width: 1rem;
202
+ height: 1rem;
203
+ accent-color: var(--primary);
204
+ }
205
+
206
+ .audio-toggle label {
207
+ font-size: 0.75rem;
208
+ color: #999;
209
+ cursor: pointer;
210
+ }
211
+
212
+ .microphone-select {
213
+ width: 100%;
214
+ padding: 0.5rem 0.75rem;
215
+ background: var(--input);
216
+ border: 1px solid transparent;
217
+ border-radius: var(--radius-sm);
218
+ color: var(--foreground);
219
+ font-size: 0.75rem;
220
+ outline: none;
221
+ cursor: pointer;
222
+ transition: all 0.15s ease;
223
+ }
224
+
225
+ .microphone-select:focus {
226
+ border-color: var(--primary);
227
+ }
228
+
229
+ .microphone-select:disabled {
230
+ opacity: 0.5;
231
+ cursor: not-allowed;
232
+ }
233
+
234
+ .audio-level-container {
235
+ margin-top: 0.75rem;
236
+ padding: 0.5rem;
237
+ background: rgba(255, 255, 255, 0.02);
238
+ border-radius: var(--radius-sm);
239
+ }
240
+
241
+ .audio-level-label {
242
+ font-size: 0.65rem;
243
+ color: #666;
244
+ margin-bottom: 0.25rem;
245
+ }
246
+
247
+ .audio-level-bar {
248
+ height: 8px;
249
+ background: var(--input);
250
+ border-radius: 4px;
251
+ overflow: hidden;
252
+ }
253
+
254
+ .audio-level-fill {
255
+ height: 100%;
256
+ background: linear-gradient(90deg, #22c55e, #84cc16, #eab308);
257
+ border-radius: 4px;
258
+ transition: width 0.1s ease;
259
+ }
260
+
261
+ .start-recording-btn {
262
+ width: 100%;
263
+ padding: 0.75rem;
264
+ background: #dc2626;
265
+ border: none;
266
+ border-radius: var(--radius-sm);
267
+ color: white;
268
+ font-size: 0.8rem;
269
+ font-weight: 500;
270
+ cursor: pointer;
271
+ transition: all 0.15s ease;
272
+ margin-top: 1rem;
273
+ display: flex;
274
+ align-items: center;
275
+ justify-content: center;
276
+ gap: 0.5rem;
277
+ }
278
+
279
+ .start-recording-btn:hover {
280
+ background: #b91c1c;
281
+ }
282
+
283
+ .start-recording-btn .rec-dot {
284
+ width: 10px;
285
+ height: 10px;
286
+ background: white;
287
+ border-radius: 50%;
288
+ }
289
+
290
+ /* Preview Modal */
291
+ .preview-modal-overlay {
292
+ position: fixed;
293
+ top: 0;
294
+ left: 0;
295
+ right: 0;
296
+ bottom: 0;
297
+ background: rgba(0, 0, 0, 0.8);
298
+ display: flex;
299
+ align-items: center;
300
+ justify-content: center;
301
+ z-index: 1000;
302
+ backdrop-filter: blur(4px);
303
+ font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
304
+ }
305
+
306
+ .preview-modal {
307
+ width: 90%;
308
+ max-width: 800px;
309
+ background: #0c0c0c;
310
+ border: 1px solid rgba(255, 255, 255, 0.1);
311
+ border-radius: var(--radius-lg);
312
+ overflow: hidden;
313
+ box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
314
+ }
315
+
316
+ .preview-modal-header {
317
+ padding: 1rem 1.25rem;
318
+ background: rgba(255, 255, 255, 0.02);
319
+ border-bottom: 1px solid rgba(255, 255, 255, 0.05);
320
+ display: flex;
321
+ justify-content: space-between;
322
+ align-items: center;
323
+ }
324
+
325
+ .preview-modal-title {
326
+ font-size: 0.9rem;
327
+ font-weight: 500;
328
+ color: #ccc;
329
+ }
330
+
331
+ .preview-modal-close {
332
+ width: 28px;
333
+ height: 28px;
334
+ background: transparent;
335
+ border: none;
336
+ color: #666;
337
+ cursor: pointer;
338
+ display: flex;
339
+ align-items: center;
340
+ justify-content: center;
341
+ border-radius: var(--radius-sm);
342
+ font-size: 1.2rem;
343
+ transition: all 0.15s ease;
344
+ }
345
+
346
+ .preview-modal-close:hover {
347
+ background: rgba(255, 255, 255, 0.05);
348
+ color: #999;
349
+ }
350
+
351
+ .preview-modal-content {
352
+ padding: 1.25rem;
353
+ }
354
+
355
+ .preview-video-container {
356
+ background: #000;
357
+ border-radius: var(--radius-sm);
358
+ overflow: hidden;
359
+ aspect-ratio: 16 / 9;
360
+ }
361
+
362
+ .preview-video {
363
+ width: 100%;
364
+ height: 100%;
365
+ object-fit: contain;
366
+ }
367
+
368
+ .preview-modal-actions {
369
+ padding: 1rem 1.25rem;
370
+ border-top: 1px solid rgba(255, 255, 255, 0.05);
371
+ display: flex;
372
+ justify-content: flex-end;
373
+ gap: 0.75rem;
374
+ }
375
+
376
+ .preview-btn {
377
+ padding: 0.6rem 1.25rem;
378
+ border-radius: var(--radius-sm);
379
+ font-size: 0.8rem;
380
+ font-weight: 500;
381
+ cursor: pointer;
382
+ transition: all 0.15s ease;
383
+ }
384
+
385
+ .preview-btn.secondary {
386
+ background: transparent;
387
+ border: 1px solid rgba(255, 255, 255, 0.1);
388
+ color: #999;
389
+ }
390
+
391
+ .preview-btn.secondary:hover {
392
+ border-color: rgba(255, 255, 255, 0.2);
393
+ color: #ccc;
394
+ }
395
+
396
+ .preview-btn.primary {
397
+ background: var(--primary);
398
+ border: none;
399
+ color: white;
400
+ }
401
+
402
+ .preview-btn.primary:hover {
403
+ background: #2563eb;
404
+ }
405
+
406
+ .preview-btn.primary:disabled {
407
+ background: #1e3a5f;
408
+ cursor: not-allowed;
409
+ opacity: 0.7;
410
+ }
411
+
412
+ /* Trim Timeline Styles */
413
+ .trim-section {
414
+ margin-top: 1.25rem;
415
+ padding-top: 1.25rem;
416
+ border-top: 1px solid rgba(255, 255, 255, 0.05);
417
+ }
418
+
419
+ .trim-section-header {
420
+ display: flex;
421
+ justify-content: space-between;
422
+ align-items: center;
423
+ margin-bottom: 0.75rem;
424
+ }
425
+
426
+ .trim-section-title {
427
+ font-size: 0.75rem;
428
+ font-weight: 500;
429
+ color: #888;
430
+ text-transform: uppercase;
431
+ letter-spacing: 0.05em;
432
+ }
433
+
434
+ .trim-duration-info {
435
+ font-size: 0.7rem;
436
+ color: #666;
437
+ font-family: 'Consolas', 'Monaco', monospace;
438
+ }
439
+
440
+ .trim-timeline {
441
+ position: relative;
442
+ height: 48px;
443
+ background: var(--input);
444
+ border-radius: var(--radius-sm);
445
+ margin-bottom: 0.75rem;
446
+ user-select: none;
447
+ }
448
+
449
+ .trim-track {
450
+ position: absolute;
451
+ top: 50%;
452
+ left: 12px;
453
+ right: 12px;
454
+ height: 6px;
455
+ background: #333;
456
+ transform: translateY(-50%);
457
+ border-radius: 3px;
458
+ }
459
+
460
+ .trim-selected {
461
+ position: absolute;
462
+ top: 50%;
463
+ height: 6px;
464
+ background: var(--primary);
465
+ transform: translateY(-50%);
466
+ border-radius: 3px;
467
+ pointer-events: none;
468
+ }
469
+
470
+ .trim-handle {
471
+ position: absolute;
472
+ top: 50%;
473
+ width: 16px;
474
+ height: 36px;
475
+ background: white;
476
+ border: 2px solid var(--primary);
477
+ border-radius: 4px;
478
+ transform: translate(-50%, -50%);
479
+ cursor: ew-resize;
480
+ z-index: 2;
481
+ display: flex;
482
+ align-items: center;
483
+ justify-content: center;
484
+ transition: background 0.15s ease, transform 0.1s ease;
485
+ }
486
+
487
+ .trim-handle:hover {
488
+ background: #e0e0e0;
489
+ }
490
+
491
+ .trim-handle:active {
492
+ background: var(--primary);
493
+ transform: translate(-50%, -50%) scale(1.05);
494
+ }
495
+
496
+ .trim-handle::before {
497
+ content: '';
498
+ width: 2px;
499
+ height: 16px;
500
+ background: #666;
501
+ border-radius: 1px;
502
+ }
503
+
504
+ .trim-handle:active::before {
505
+ background: white;
506
+ }
507
+
508
+ .trim-time-labels {
509
+ display: flex;
510
+ justify-content: space-between;
511
+ font-size: 0.65rem;
512
+ color: #666;
513
+ font-family: 'Consolas', 'Monaco', monospace;
514
+ padding: 0 12px;
515
+ }
516
+
517
+ .trim-actions {
518
+ display: flex;
519
+ gap: 0.5rem;
520
+ margin-top: 0.75rem;
521
+ }
522
+
523
+ .trim-action-btn {
524
+ flex: 1;
525
+ padding: 0.5rem 0.75rem;
526
+ background: var(--input);
527
+ border: 1px solid transparent;
528
+ border-radius: var(--radius-sm);
529
+ color: #999;
530
+ font-size: 0.75rem;
531
+ cursor: pointer;
532
+ transition: all 0.15s ease;
533
+ text-align: center;
534
+ }
535
+
536
+ .trim-action-btn:hover {
537
+ border-color: var(--primary);
538
+ color: #ccc;
539
+ }
540
+
541
+ .export-spinner {
542
+ display: inline-block;
543
+ width: 14px;
544
+ height: 14px;
545
+ border: 2px solid rgba(255, 255, 255, 0.3);
546
+ border-radius: 50%;
547
+ border-top-color: white;
548
+ animation: spin 0.8s linear infinite;
549
+ margin-right: 0.5rem;
550
+ }
551
+
552
+ @keyframes spin {
553
+ to { transform: rotate(360deg); }
554
+ }
555
+ `
556
+ ];
557
+
558
+ public render(): TemplateResult {
559
+ if (this.panelState === 'options') {
560
+ return this.renderOptionsPanel();
561
+ } else if (this.panelState === 'preview') {
562
+ return this.renderPreviewModal();
563
+ }
564
+ return html``;
565
+ }
566
+
567
+ private renderOptionsPanel(): TemplateResult {
568
+ return html`
569
+ <div class="recording-options-panel">
570
+ <div class="recording-options-header">
571
+ <span class="recording-options-title">Recording Settings</span>
572
+ <button class="recording-options-close" @click=${() => this.close()}>✕</button>
573
+ </div>
574
+ <div class="recording-options-content">
575
+ <div class="recording-option-group">
576
+ <div class="recording-option-label">Record Area</div>
577
+ <div class="recording-mode-buttons">
578
+ <button
579
+ class="recording-mode-btn ${this.recordingMode === 'viewport' ? 'selected' : ''}"
580
+ @click=${() => this.recordingMode = 'viewport'}
581
+ >
582
+ Viewport Only
583
+ </button>
584
+ <button
585
+ class="recording-mode-btn ${this.recordingMode === 'screen' ? 'selected' : ''}"
586
+ @click=${() => this.recordingMode = 'screen'}
587
+ >
588
+ Entire Screen
589
+ </button>
590
+ </div>
591
+ </div>
592
+
593
+ <div class="recording-option-group">
594
+ <div class="recording-option-label">Audio</div>
595
+ <div class="audio-toggle">
596
+ <input
597
+ type="checkbox"
598
+ id="audioToggle"
599
+ ?checked=${this.audioEnabled}
600
+ @change=${(e: Event) => this.handleAudioToggle((e.target as HTMLInputElement).checked)}
601
+ />
602
+ <label for="audioToggle">Enable Microphone</label>
603
+ </div>
604
+
605
+ ${this.audioEnabled ? html`
606
+ <select
607
+ class="microphone-select"
608
+ .value=${this.selectedMicrophoneId}
609
+ @change=${(e: Event) => this.handleMicrophoneChange((e.target as HTMLSelectElement).value)}
610
+ >
611
+ <option value="">Select Microphone...</option>
612
+ ${this.availableMicrophones.map(mic => html`
613
+ <option value=${mic.deviceId}>${mic.label || `Microphone ${mic.deviceId.slice(0, 8)}`}</option>
614
+ `)}
615
+ </select>
616
+
617
+ ${this.selectedMicrophoneId ? html`
618
+ <div class="audio-level-container">
619
+ <div class="audio-level-label">Input Level</div>
620
+ <div class="audio-level-bar">
621
+ <div class="audio-level-fill" style="width: ${this.audioLevel}%"></div>
622
+ </div>
623
+ </div>
624
+ ` : null}
625
+ ` : null}
626
+ </div>
627
+
628
+ <button class="start-recording-btn" @click=${() => this.startRecording()}>
629
+ <div class="rec-dot"></div>
630
+ Start Recording
631
+ </button>
632
+ </div>
633
+ </div>
634
+ `;
635
+ }
636
+
637
+ private renderPreviewModal(): TemplateResult {
638
+ return html`
639
+ <div class="preview-modal-overlay" @click=${(e: Event) => {
640
+ if ((e.target as HTMLElement).classList.contains('preview-modal-overlay')) {
641
+ this.discardRecording();
642
+ }
643
+ }}>
644
+ <div class="preview-modal">
645
+ <div class="preview-modal-header">
646
+ <span class="preview-modal-title">Recording Preview</span>
647
+ <button class="preview-modal-close" @click=${() => this.discardRecording()}>✕</button>
648
+ </div>
649
+ <div class="preview-modal-content">
650
+ <div class="preview-video-container">
651
+ <video
652
+ class="preview-video"
653
+ src=${this.previewVideoUrl}
654
+ controls
655
+ @loadedmetadata=${(e: Event) => this.handleVideoLoaded(e.target as HTMLVideoElement)}
656
+ ></video>
657
+ </div>
658
+
659
+ <!-- Trim Section -->
660
+ <div class="trim-section">
661
+ <div class="trim-section-header">
662
+ <span class="trim-section-title">Trim Video</span>
663
+ <span class="trim-duration-info">
664
+ ${this.formatDuration(Math.floor(this.trimEnd - this.trimStart))}
665
+ ${this.trimStart > 0 || this.trimEnd < this.videoDuration
666
+ ? `(trimmed from ${this.formatDuration(Math.floor(this.videoDuration))})`
667
+ : ''}
668
+ </span>
669
+ </div>
670
+
671
+ <div
672
+ class="trim-timeline"
673
+ @mousedown=${(e: MouseEvent) => this.handleTimelineClick(e)}
674
+ @mousemove=${(e: MouseEvent) => this.handleTimelineDrag(e)}
675
+ @mouseup=${() => this.handleTimelineDragEnd()}
676
+ @mouseleave=${() => this.handleTimelineDragEnd()}
677
+ >
678
+ <div class="trim-track"></div>
679
+ <div
680
+ class="trim-selected"
681
+ style="left: ${this.getHandlePositionStyle(this.trimStart)}; right: ${this.getHandlePositionFromEndStyle(this.trimEnd)};"
682
+ ></div>
683
+ <div
684
+ class="trim-handle start-handle"
685
+ style="left: ${this.getHandlePositionStyle(this.trimStart)};"
686
+ @mousedown=${(e: MouseEvent) => { e.stopPropagation(); this.isDraggingTrim = 'start'; }}
687
+ ></div>
688
+ <div
689
+ class="trim-handle end-handle"
690
+ style="left: ${this.getHandlePositionStyle(this.trimEnd)};"
691
+ @mousedown=${(e: MouseEvent) => { e.stopPropagation(); this.isDraggingTrim = 'end'; }}
692
+ ></div>
693
+ </div>
694
+
695
+ <div class="trim-time-labels">
696
+ <span>${this.formatDuration(Math.floor(this.trimStart))}</span>
697
+ <span>${this.formatDuration(Math.floor(this.trimEnd))}</span>
698
+ </div>
699
+
700
+ <div class="trim-actions">
701
+ <button class="trim-action-btn" @click=${() => this.resetTrim()}>
702
+ Reset Trim
703
+ </button>
704
+ <button class="trim-action-btn" @click=${() => this.previewTrimmedSection()}>
705
+ Preview Selection
706
+ </button>
707
+ </div>
708
+ </div>
709
+ </div>
710
+ <div class="preview-modal-actions">
711
+ <button class="preview-btn secondary" @click=${() => this.discardRecording()}>Discard</button>
712
+ <button
713
+ class="preview-btn primary"
714
+ ?disabled=${this.isExporting}
715
+ @click=${() => this.downloadRecording()}
716
+ >
717
+ ${this.isExporting ? html`<span class="export-spinner"></span>Exporting...` : 'Download'}
718
+ </button>
719
+ </div>
720
+ </div>
721
+ </div>
722
+ `;
723
+ }
724
+
725
+ // ==================== Audio Methods ====================
726
+
727
+ private async handleAudioToggle(enabled: boolean): Promise<void> {
728
+ this.audioEnabled = enabled;
729
+ if (enabled) {
730
+ this.availableMicrophones = await this.recorderService.loadMicrophones(true);
731
+ if (this.availableMicrophones.length > 0 && !this.selectedMicrophoneId) {
732
+ this.selectedMicrophoneId = this.availableMicrophones[0].deviceId;
733
+ await this.recorderService.startAudioMonitoring(this.selectedMicrophoneId);
734
+ }
735
+ } else {
736
+ this.recorderService.stopAudioMonitoring();
737
+ this.selectedMicrophoneId = '';
738
+ this.audioLevel = 0;
739
+ }
740
+ }
741
+
742
+ private async handleMicrophoneChange(deviceId: string): Promise<void> {
743
+ this.selectedMicrophoneId = deviceId;
744
+ if (deviceId) {
745
+ await this.recorderService.startAudioMonitoring(deviceId);
746
+ } else {
747
+ this.recorderService.stopAudioMonitoring();
748
+ this.audioLevel = 0;
749
+ }
750
+ }
751
+
752
+ // ==================== Recording Methods ====================
753
+
754
+ private async startRecording(): Promise<void> {
755
+ try {
756
+ let viewportElement: HTMLElement | undefined;
757
+ if (this.recordingMode === 'viewport' && this.dashboardRef) {
758
+ const wccFrame = await this.dashboardRef.wccFrame;
759
+ viewportElement = await wccFrame.getViewportElement();
760
+ }
761
+
762
+ await this.recorderService.startRecording({
763
+ mode: this.recordingMode,
764
+ audioDeviceId: this.audioEnabled ? this.selectedMicrophoneId : undefined,
765
+ viewportElement
766
+ });
767
+
768
+ this.panelState = 'recording';
769
+ this.dispatchEvent(new CustomEvent('recording-start', {
770
+ bubbles: true,
771
+ composed: true
772
+ }));
773
+ } catch (error) {
774
+ console.error('Failed to start recording:', error);
775
+ this.panelState = 'options';
776
+ }
777
+ }
778
+
779
+ public stopRecording(): void {
780
+ this.recorderService.stopRecording();
781
+ }
782
+
783
+ private handleRecordingComplete(blob: Blob): void {
784
+ if (this.previewVideoUrl) {
785
+ URL.revokeObjectURL(this.previewVideoUrl);
786
+ }
787
+ this.previewVideoUrl = URL.createObjectURL(blob);
788
+ this.panelState = 'preview';
789
+ this.dispatchEvent(new CustomEvent('recording-stop', {
790
+ bubbles: true,
791
+ composed: true
792
+ }));
793
+ }
794
+
795
+ private discardRecording(): void {
796
+ if (this.previewVideoUrl) {
797
+ URL.revokeObjectURL(this.previewVideoUrl);
798
+ this.previewVideoUrl = '';
799
+ }
800
+ this.recorderService.reset();
801
+ this.trimStart = 0;
802
+ this.trimEnd = 0;
803
+ this.videoDuration = 0;
804
+ this.isExporting = false;
805
+ this.recordingDuration = 0;
806
+ this.close();
807
+ }
808
+
809
+ private async downloadRecording(): Promise<void> {
810
+ const recordedBlob = this.recorderService.recordedBlob;
811
+ if (!recordedBlob) return;
812
+
813
+ this.isExporting = true;
814
+
815
+ try {
816
+ let blobToDownload: Blob;
817
+
818
+ const needsTrim = this.trimStart > 0.1 || this.trimEnd < this.videoDuration - 0.1;
819
+
820
+ if (needsTrim) {
821
+ const video = this.shadowRoot?.querySelector('.preview-video') as HTMLVideoElement;
822
+ if (video) {
823
+ blobToDownload = await this.recorderService.exportTrimmedVideo(video, this.trimStart, this.trimEnd);
824
+ } else {
825
+ blobToDownload = recordedBlob;
826
+ }
827
+ } else {
828
+ blobToDownload = recordedBlob;
829
+ }
830
+
831
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
832
+ const filename = `wcctools-recording-${timestamp}.webm`;
833
+
834
+ const url = URL.createObjectURL(blobToDownload);
835
+ const a = document.createElement('a');
836
+ a.href = url;
837
+ a.download = filename;
838
+ document.body.appendChild(a);
839
+ a.click();
840
+ document.body.removeChild(a);
841
+ URL.revokeObjectURL(url);
842
+
843
+ this.discardRecording();
844
+ } catch (error) {
845
+ console.error('Error exporting video:', error);
846
+ this.isExporting = false;
847
+ }
848
+ }
849
+
850
+ // ==================== Trim Methods ====================
851
+
852
+ private handleVideoLoaded(video: HTMLVideoElement): void {
853
+ // WebM files from MediaRecorder may have Infinity/NaN duration
854
+ // Fall back to the tracked recording duration
855
+ const duration = Number.isFinite(video.duration) ? video.duration : this.recordingDuration;
856
+ this.videoDuration = duration;
857
+ this.trimStart = 0;
858
+ this.trimEnd = duration;
859
+ }
860
+
861
+ private formatDuration(seconds: number): string {
862
+ const mins = Math.floor(seconds / 60);
863
+ const secs = seconds % 60;
864
+ return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
865
+ }
866
+
867
+ private getHandlePositionStyle(time: number): string {
868
+ if (this.videoDuration === 0) return '12px';
869
+ const percentage = time / this.videoDuration;
870
+ // Formula: 12px padding + percentage of remaining width (total - 24px padding)
871
+ // At 0%: 12px (left edge of track)
872
+ // At 100%: calc(100% - 12px) (right edge of track)
873
+ return `calc(12px + ${(percentage * 100).toFixed(2)}% - ${(percentage * 24).toFixed(2)}px)`;
874
+ }
875
+
876
+ private getHandlePositionFromEndStyle(time: number): string {
877
+ if (this.videoDuration === 0) return '12px';
878
+ const percentage = time / this.videoDuration;
879
+ const remainingPercentage = 1 - percentage;
880
+ // For CSS 'right' property: distance from right edge
881
+ // At trimEnd = 100%: right = 12px (at right edge of track)
882
+ // At trimEnd = 0%: right = calc(100% - 12px) (at left edge of track)
883
+ return `calc(12px + ${(remainingPercentage * 100).toFixed(2)}% - ${(remainingPercentage * 24).toFixed(2)}px)`;
884
+ }
885
+
886
+ private handleTimelineClick(e: MouseEvent): void {
887
+ if (this.isDraggingTrim) return;
888
+
889
+ const timeline = e.currentTarget as HTMLElement;
890
+ const rect = timeline.getBoundingClientRect();
891
+ const x = e.clientX - rect.left;
892
+ const percentage = Math.max(0, Math.min(1, (x - 12) / (rect.width - 24)));
893
+ const time = percentage * this.videoDuration;
894
+
895
+ const video = this.shadowRoot?.querySelector('.preview-video') as HTMLVideoElement;
896
+ if (video) {
897
+ video.currentTime = time;
898
+ }
899
+ }
900
+
901
+ private handleTimelineDrag(e: MouseEvent): void {
902
+ if (!this.isDraggingTrim) return;
903
+
904
+ const timeline = e.currentTarget as HTMLElement;
905
+ const rect = timeline.getBoundingClientRect();
906
+ const x = e.clientX - rect.left;
907
+ const percentage = Math.max(0, Math.min(1, (x - 12) / (rect.width - 24)));
908
+ const time = percentage * this.videoDuration;
909
+
910
+ const minDuration = 1;
911
+
912
+ if (this.isDraggingTrim === 'start') {
913
+ this.trimStart = Math.min(time, this.trimEnd - minDuration);
914
+ this.trimStart = Math.max(0, this.trimStart);
915
+ } else if (this.isDraggingTrim === 'end') {
916
+ this.trimEnd = Math.max(time, this.trimStart + minDuration);
917
+ this.trimEnd = Math.min(this.videoDuration, this.trimEnd);
918
+ }
919
+
920
+ const video = this.shadowRoot?.querySelector('.preview-video') as HTMLVideoElement;
921
+ if (video) {
922
+ video.currentTime = this.isDraggingTrim === 'start' ? this.trimStart : this.trimEnd;
923
+ }
924
+ }
925
+
926
+ private handleTimelineDragEnd(): void {
927
+ this.isDraggingTrim = null;
928
+ }
929
+
930
+ private resetTrim(): void {
931
+ this.trimStart = 0;
932
+ this.trimEnd = this.videoDuration;
933
+
934
+ const video = this.shadowRoot?.querySelector('.preview-video') as HTMLVideoElement;
935
+ if (video) {
936
+ video.currentTime = 0;
937
+ }
938
+ }
939
+
940
+ private previewTrimmedSection(): void {
941
+ const video = this.shadowRoot?.querySelector('.preview-video') as HTMLVideoElement;
942
+ if (!video) return;
943
+
944
+ video.currentTime = this.trimStart;
945
+ video.play();
946
+
947
+ const checkTime = () => {
948
+ if (video.currentTime >= this.trimEnd) {
949
+ video.pause();
950
+ video.removeEventListener('timeupdate', checkTime);
951
+ }
952
+ };
953
+
954
+ video.addEventListener('timeupdate', checkTime);
955
+ }
956
+
957
+ // ==================== Lifecycle ====================
958
+
959
+ private close(): void {
960
+ this.recorderService.stopAudioMonitoring();
961
+ this.dispatchEvent(new CustomEvent('close', {
962
+ bubbles: true,
963
+ composed: true
964
+ }));
965
+ }
966
+
967
+ async disconnectedCallback(): Promise<void> {
968
+ await super.disconnectedCallback();
969
+ this.recorderService.dispose();
970
+ if (this.previewVideoUrl) {
971
+ URL.revokeObjectURL(this.previewVideoUrl);
972
+ }
973
+ }
974
+ }