@design.estate/dees-wcctools 1.2.1 → 2.0.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 (42) hide show
  1. package/dist_bundle/bundle.js +1764 -218
  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 +11 -10
  7. package/dist_ts_web/elements/wcc-dashboard.js +370 -246
  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 +1067 -0
  16. package/dist_ts_web/elements/wcc-sidebar.d.ts +7 -5
  17. package/dist_ts_web/elements/wcc-sidebar.js +250 -81
  18. package/dist_ts_web/elements/wcctools.helpers.d.ts +13 -0
  19. package/dist_ts_web/elements/wcctools.helpers.js +26 -1
  20. package/dist_ts_web/index.d.ts +3 -0
  21. package/dist_ts_web/index.js +5 -1
  22. package/dist_ts_web/services/ffmpeg.service.d.ts +42 -0
  23. package/dist_ts_web/services/ffmpeg.service.js +276 -0
  24. package/dist_ts_web/services/mp4.service.d.ts +32 -0
  25. package/dist_ts_web/services/mp4.service.js +139 -0
  26. package/dist_ts_web/services/recorder.service.d.ts +44 -0
  27. package/dist_ts_web/services/recorder.service.js +307 -0
  28. package/dist_watch/bundle.js +2126 -541
  29. package/dist_watch/bundle.js.map +4 -4
  30. package/package.json +8 -8
  31. package/readme.md +133 -141
  32. package/ts_web/00_commitinfo_data.ts +1 -1
  33. package/ts_web/elements/wcc-dashboard.ts +86 -26
  34. package/ts_web/elements/wcc-frame.ts +3 -3
  35. package/ts_web/elements/wcc-properties.ts +53 -9
  36. package/ts_web/elements/wcc-record-button.ts +108 -0
  37. package/ts_web/elements/wcc-recording-panel.ts +978 -0
  38. package/ts_web/elements/wcc-sidebar.ts +133 -22
  39. package/ts_web/elements/wcctools.helpers.ts +31 -0
  40. package/ts_web/index.ts +5 -0
  41. package/ts_web/readme.md +123 -0
  42. package/ts_web/services/recorder.service.ts +393 -0
@@ -0,0 +1,978 @@
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
+
559
+ public render(): TemplateResult {
560
+ if (this.panelState === 'options') {
561
+ return this.renderOptionsPanel();
562
+ } else if (this.panelState === 'preview') {
563
+ return this.renderPreviewModal();
564
+ }
565
+ return html``;
566
+ }
567
+
568
+ private renderOptionsPanel(): TemplateResult {
569
+ return html`
570
+ <div class="recording-options-panel">
571
+ <div class="recording-options-header">
572
+ <span class="recording-options-title">Recording Settings</span>
573
+ <button class="recording-options-close" @click=${() => this.close()}>✕</button>
574
+ </div>
575
+ <div class="recording-options-content">
576
+ <div class="recording-option-group">
577
+ <div class="recording-option-label">Record Area</div>
578
+ <div class="recording-mode-buttons">
579
+ <button
580
+ class="recording-mode-btn ${this.recordingMode === 'viewport' ? 'selected' : ''}"
581
+ @click=${() => this.recordingMode = 'viewport'}
582
+ >
583
+ Viewport Only
584
+ </button>
585
+ <button
586
+ class="recording-mode-btn ${this.recordingMode === 'screen' ? 'selected' : ''}"
587
+ @click=${() => this.recordingMode = 'screen'}
588
+ >
589
+ Entire Screen
590
+ </button>
591
+ </div>
592
+ </div>
593
+
594
+ <div class="recording-option-group">
595
+ <div class="recording-option-label">Audio</div>
596
+ <div class="audio-toggle">
597
+ <input
598
+ type="checkbox"
599
+ id="audioToggle"
600
+ ?checked=${this.audioEnabled}
601
+ @change=${(e: Event) => this.handleAudioToggle((e.target as HTMLInputElement).checked)}
602
+ />
603
+ <label for="audioToggle">Enable Microphone</label>
604
+ </div>
605
+
606
+ ${this.audioEnabled ? html`
607
+ <select
608
+ class="microphone-select"
609
+ .value=${this.selectedMicrophoneId}
610
+ @change=${(e: Event) => this.handleMicrophoneChange((e.target as HTMLSelectElement).value)}
611
+ >
612
+ <option value="">Select Microphone...</option>
613
+ ${this.availableMicrophones.map(mic => html`
614
+ <option value=${mic.deviceId}>${mic.label || `Microphone ${mic.deviceId.slice(0, 8)}`}</option>
615
+ `)}
616
+ </select>
617
+
618
+ ${this.selectedMicrophoneId ? html`
619
+ <div class="audio-level-container">
620
+ <div class="audio-level-label">Input Level</div>
621
+ <div class="audio-level-bar">
622
+ <div class="audio-level-fill" style="width: ${this.audioLevel}%"></div>
623
+ </div>
624
+ </div>
625
+ ` : null}
626
+ ` : null}
627
+ </div>
628
+
629
+ <button class="start-recording-btn" @click=${() => this.startRecording()}>
630
+ <div class="rec-dot"></div>
631
+ Start Recording
632
+ </button>
633
+ </div>
634
+ </div>
635
+ `;
636
+ }
637
+
638
+ private renderPreviewModal(): TemplateResult {
639
+ return html`
640
+ <div class="preview-modal-overlay" @click=${(e: Event) => {
641
+ if ((e.target as HTMLElement).classList.contains('preview-modal-overlay')) {
642
+ this.discardRecording();
643
+ }
644
+ }}>
645
+ <div class="preview-modal">
646
+ <div class="preview-modal-header">
647
+ <span class="preview-modal-title">Recording Preview</span>
648
+ <button class="preview-modal-close" @click=${() => this.discardRecording()}>✕</button>
649
+ </div>
650
+ <div class="preview-modal-content">
651
+ <div class="preview-video-container">
652
+ <video
653
+ class="preview-video"
654
+ src=${this.previewVideoUrl}
655
+ controls
656
+ @loadedmetadata=${(e: Event) => this.handleVideoLoaded(e.target as HTMLVideoElement)}
657
+ ></video>
658
+ </div>
659
+
660
+ <!-- Trim Section -->
661
+ <div class="trim-section">
662
+ <div class="trim-section-header">
663
+ <span class="trim-section-title">Trim Video</span>
664
+ <span class="trim-duration-info">
665
+ ${this.formatDuration(Math.floor(this.trimEnd - this.trimStart))}
666
+ ${this.trimStart > 0 || this.trimEnd < this.videoDuration
667
+ ? `(trimmed from ${this.formatDuration(Math.floor(this.videoDuration))})`
668
+ : ''}
669
+ </span>
670
+ </div>
671
+
672
+ <div
673
+ class="trim-timeline"
674
+ @mousedown=${(e: MouseEvent) => this.handleTimelineClick(e)}
675
+ @mousemove=${(e: MouseEvent) => this.handleTimelineDrag(e)}
676
+ @mouseup=${() => this.handleTimelineDragEnd()}
677
+ @mouseleave=${() => this.handleTimelineDragEnd()}
678
+ >
679
+ <div class="trim-track"></div>
680
+ <div
681
+ class="trim-selected"
682
+ style="left: ${this.getHandlePositionStyle(this.trimStart)}; right: ${this.getHandlePositionFromEndStyle(this.trimEnd)};"
683
+ ></div>
684
+ <div
685
+ class="trim-handle start-handle"
686
+ style="left: ${this.getHandlePositionStyle(this.trimStart)};"
687
+ @mousedown=${(e: MouseEvent) => { e.stopPropagation(); this.isDraggingTrim = 'start'; }}
688
+ ></div>
689
+ <div
690
+ class="trim-handle end-handle"
691
+ style="left: ${this.getHandlePositionStyle(this.trimEnd)};"
692
+ @mousedown=${(e: MouseEvent) => { e.stopPropagation(); this.isDraggingTrim = 'end'; }}
693
+ ></div>
694
+ </div>
695
+
696
+ <div class="trim-time-labels">
697
+ <span>${this.formatDuration(Math.floor(this.trimStart))}</span>
698
+ <span>${this.formatDuration(Math.floor(this.trimEnd))}</span>
699
+ </div>
700
+
701
+ <div class="trim-actions">
702
+ <button class="trim-action-btn" @click=${() => this.resetTrim()}>
703
+ Reset Trim
704
+ </button>
705
+ <button class="trim-action-btn" @click=${() => this.previewTrimmedSection()}>
706
+ Preview Selection
707
+ </button>
708
+ </div>
709
+ </div>
710
+
711
+ </div>
712
+ <div class="preview-modal-actions">
713
+ <button class="preview-btn secondary" @click=${() => this.discardRecording()}>Discard</button>
714
+ <button
715
+ class="preview-btn primary"
716
+ ?disabled=${this.isExporting}
717
+ @click=${() => this.downloadRecording()}
718
+ >
719
+ ${this.isExporting ? html`<span class="export-spinner"></span>Exporting...` : 'Download WebM'}
720
+ </button>
721
+ </div>
722
+ </div>
723
+ </div>
724
+ `;
725
+ }
726
+
727
+ // ==================== Audio Methods ====================
728
+
729
+ private async handleAudioToggle(enabled: boolean): Promise<void> {
730
+ this.audioEnabled = enabled;
731
+ if (enabled) {
732
+ this.availableMicrophones = await this.recorderService.loadMicrophones(true);
733
+ if (this.availableMicrophones.length > 0 && !this.selectedMicrophoneId) {
734
+ this.selectedMicrophoneId = this.availableMicrophones[0].deviceId;
735
+ await this.recorderService.startAudioMonitoring(this.selectedMicrophoneId);
736
+ }
737
+ } else {
738
+ this.recorderService.stopAudioMonitoring();
739
+ this.selectedMicrophoneId = '';
740
+ this.audioLevel = 0;
741
+ }
742
+ }
743
+
744
+ private async handleMicrophoneChange(deviceId: string): Promise<void> {
745
+ this.selectedMicrophoneId = deviceId;
746
+ if (deviceId) {
747
+ await this.recorderService.startAudioMonitoring(deviceId);
748
+ } else {
749
+ this.recorderService.stopAudioMonitoring();
750
+ this.audioLevel = 0;
751
+ }
752
+ }
753
+
754
+ // ==================== Recording Methods ====================
755
+
756
+ private async startRecording(): Promise<void> {
757
+ try {
758
+ let viewportElement: HTMLElement | undefined;
759
+ if (this.recordingMode === 'viewport' && this.dashboardRef) {
760
+ const wccFrame = await this.dashboardRef.wccFrame;
761
+ viewportElement = await wccFrame.getViewportElement();
762
+ }
763
+
764
+ await this.recorderService.startRecording({
765
+ mode: this.recordingMode,
766
+ audioDeviceId: this.audioEnabled ? this.selectedMicrophoneId : undefined,
767
+ viewportElement
768
+ });
769
+
770
+ this.panelState = 'recording';
771
+ this.dispatchEvent(new CustomEvent('recording-start', {
772
+ bubbles: true,
773
+ composed: true
774
+ }));
775
+ } catch (error) {
776
+ console.error('Failed to start recording:', error);
777
+ this.panelState = 'options';
778
+ }
779
+ }
780
+
781
+ public stopRecording(): void {
782
+ this.recorderService.stopRecording();
783
+ }
784
+
785
+ private handleRecordingComplete(blob: Blob): void {
786
+ if (this.previewVideoUrl) {
787
+ URL.revokeObjectURL(this.previewVideoUrl);
788
+ }
789
+ this.previewVideoUrl = URL.createObjectURL(blob);
790
+ this.panelState = 'preview';
791
+ this.dispatchEvent(new CustomEvent('recording-stop', {
792
+ bubbles: true,
793
+ composed: true
794
+ }));
795
+ }
796
+
797
+ private discardRecording(): void {
798
+ if (this.previewVideoUrl) {
799
+ URL.revokeObjectURL(this.previewVideoUrl);
800
+ this.previewVideoUrl = '';
801
+ }
802
+ this.recorderService.reset();
803
+ this.trimStart = 0;
804
+ this.trimEnd = 0;
805
+ this.videoDuration = 0;
806
+ this.isExporting = false;
807
+ this.recordingDuration = 0;
808
+ this.close();
809
+ }
810
+
811
+ private async downloadRecording(): Promise<void> {
812
+ const recordedBlob = this.recorderService.recordedBlob;
813
+ if (!recordedBlob) return;
814
+
815
+ this.isExporting = true;
816
+
817
+ try {
818
+ let blobToDownload: Blob;
819
+
820
+ // Handle trimming if needed
821
+ const needsTrim = this.trimStart > 0.1 || this.trimEnd < this.videoDuration - 0.1;
822
+
823
+ if (needsTrim) {
824
+ const video = this.shadowRoot?.querySelector('.preview-video') as HTMLVideoElement;
825
+ if (video) {
826
+ blobToDownload = await this.recorderService.exportTrimmedVideo(video, this.trimStart, this.trimEnd);
827
+ } else {
828
+ blobToDownload = recordedBlob;
829
+ }
830
+ } else {
831
+ blobToDownload = recordedBlob;
832
+ }
833
+
834
+ // Trigger download
835
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
836
+ const filename = `wcctools-recording-${timestamp}.webm`;
837
+
838
+ const url = URL.createObjectURL(blobToDownload);
839
+ const a = document.createElement('a');
840
+ a.href = url;
841
+ a.download = filename;
842
+ document.body.appendChild(a);
843
+ a.click();
844
+ document.body.removeChild(a);
845
+ URL.revokeObjectURL(url);
846
+
847
+ this.discardRecording();
848
+ } catch (error) {
849
+ console.error('Error exporting video:', error);
850
+ this.isExporting = false;
851
+ }
852
+ }
853
+
854
+ // ==================== Trim Methods ====================
855
+
856
+ private handleVideoLoaded(video: HTMLVideoElement): void {
857
+ // WebM files from MediaRecorder may have Infinity/NaN duration
858
+ // Fall back to the tracked recording duration
859
+ const duration = Number.isFinite(video.duration) ? video.duration : this.recordingDuration;
860
+ this.videoDuration = duration;
861
+ this.trimStart = 0;
862
+ this.trimEnd = duration;
863
+ }
864
+
865
+ private formatDuration(seconds: number): string {
866
+ const mins = Math.floor(seconds / 60);
867
+ const secs = seconds % 60;
868
+ return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
869
+ }
870
+
871
+ private getHandlePositionStyle(time: number): string {
872
+ if (this.videoDuration === 0) return '12px';
873
+ const percentage = time / this.videoDuration;
874
+ // Formula: 12px padding + percentage of remaining width (total - 24px padding)
875
+ // At 0%: 12px (left edge of track)
876
+ // At 100%: calc(100% - 12px) (right edge of track)
877
+ return `calc(12px + ${(percentage * 100).toFixed(2)}% - ${(percentage * 24).toFixed(2)}px)`;
878
+ }
879
+
880
+ private getHandlePositionFromEndStyle(time: number): string {
881
+ if (this.videoDuration === 0) return '12px';
882
+ const percentage = time / this.videoDuration;
883
+ const remainingPercentage = 1 - percentage;
884
+ // For CSS 'right' property: distance from right edge
885
+ // At trimEnd = 100%: right = 12px (at right edge of track)
886
+ // At trimEnd = 0%: right = calc(100% - 12px) (at left edge of track)
887
+ return `calc(12px + ${(remainingPercentage * 100).toFixed(2)}% - ${(remainingPercentage * 24).toFixed(2)}px)`;
888
+ }
889
+
890
+ private handleTimelineClick(e: MouseEvent): void {
891
+ if (this.isDraggingTrim) return;
892
+
893
+ const timeline = e.currentTarget as HTMLElement;
894
+ const rect = timeline.getBoundingClientRect();
895
+ const x = e.clientX - rect.left;
896
+ const percentage = Math.max(0, Math.min(1, (x - 12) / (rect.width - 24)));
897
+ const time = percentage * this.videoDuration;
898
+
899
+ const video = this.shadowRoot?.querySelector('.preview-video') as HTMLVideoElement;
900
+ if (video) {
901
+ video.currentTime = time;
902
+ }
903
+ }
904
+
905
+ private handleTimelineDrag(e: MouseEvent): void {
906
+ if (!this.isDraggingTrim) return;
907
+
908
+ const timeline = e.currentTarget as HTMLElement;
909
+ const rect = timeline.getBoundingClientRect();
910
+ const x = e.clientX - rect.left;
911
+ const percentage = Math.max(0, Math.min(1, (x - 12) / (rect.width - 24)));
912
+ const time = percentage * this.videoDuration;
913
+
914
+ const minDuration = 1;
915
+
916
+ if (this.isDraggingTrim === 'start') {
917
+ this.trimStart = Math.min(time, this.trimEnd - minDuration);
918
+ this.trimStart = Math.max(0, this.trimStart);
919
+ } else if (this.isDraggingTrim === 'end') {
920
+ this.trimEnd = Math.max(time, this.trimStart + minDuration);
921
+ this.trimEnd = Math.min(this.videoDuration, this.trimEnd);
922
+ }
923
+
924
+ const video = this.shadowRoot?.querySelector('.preview-video') as HTMLVideoElement;
925
+ if (video) {
926
+ video.currentTime = this.isDraggingTrim === 'start' ? this.trimStart : this.trimEnd;
927
+ }
928
+ }
929
+
930
+ private handleTimelineDragEnd(): void {
931
+ this.isDraggingTrim = null;
932
+ }
933
+
934
+ private resetTrim(): void {
935
+ this.trimStart = 0;
936
+ this.trimEnd = this.videoDuration;
937
+
938
+ const video = this.shadowRoot?.querySelector('.preview-video') as HTMLVideoElement;
939
+ if (video) {
940
+ video.currentTime = 0;
941
+ }
942
+ }
943
+
944
+ private previewTrimmedSection(): void {
945
+ const video = this.shadowRoot?.querySelector('.preview-video') as HTMLVideoElement;
946
+ if (!video) return;
947
+
948
+ video.currentTime = this.trimStart;
949
+ video.play();
950
+
951
+ const checkTime = () => {
952
+ if (video.currentTime >= this.trimEnd) {
953
+ video.pause();
954
+ video.removeEventListener('timeupdate', checkTime);
955
+ }
956
+ };
957
+
958
+ video.addEventListener('timeupdate', checkTime);
959
+ }
960
+
961
+ // ==================== Lifecycle ====================
962
+
963
+ private close(): void {
964
+ this.recorderService.stopAudioMonitoring();
965
+ this.dispatchEvent(new CustomEvent('close', {
966
+ bubbles: true,
967
+ composed: true
968
+ }));
969
+ }
970
+
971
+ async disconnectedCallback(): Promise<void> {
972
+ await super.disconnectedCallback();
973
+ this.recorderService.dispose();
974
+ if (this.previewVideoUrl) {
975
+ URL.revokeObjectURL(this.previewVideoUrl);
976
+ }
977
+ }
978
+ }