@waveform-playlist/annotations 13.0.1 → 14.0.0-next.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.
package/dist/index.js CHANGED
@@ -30,19 +30,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- Annotation: () => Annotation,
34
33
  AnnotationBox: () => AnnotationBox,
35
34
  AnnotationBoxesWrapper: () => AnnotationBoxesWrapper,
36
35
  AnnotationProvider: () => AnnotationProvider,
37
- AnnotationText: () => AnnotationText2,
38
- AnnotationsTrack: () => AnnotationsTrack,
36
+ AnnotationText: () => AnnotationText,
39
37
  ContinuousPlayCheckbox: () => ContinuousPlayCheckbox,
40
38
  DownloadAnnotationsButton: () => DownloadAnnotationsButton,
41
39
  EditableCheckbox: () => EditableCheckbox,
42
40
  LinkEndpointsCheckbox: () => LinkEndpointsCheckbox,
43
41
  parseAeneas: () => parseAeneas,
44
- serializeAeneas: () => serializeAeneas,
45
- useAnnotationControls: () => useAnnotationControls
42
+ serializeAeneas: () => serializeAeneas
46
43
  });
47
44
  module.exports = __toCommonJS(index_exports);
48
45
 
@@ -66,202 +63,13 @@ function serializeAeneas(annotation) {
66
63
  };
67
64
  }
68
65
 
69
- // src/components/Annotation.tsx
70
- var import_react = require("react");
71
- var import_styled_components = __toESM(require("styled-components"));
72
- var import_jsx_runtime = require("react/jsx-runtime");
73
- var AnnotationOverlay = import_styled_components.default.div.attrs((props) => ({
74
- style: {
75
- left: `${props.$left}px`,
76
- width: `${props.$width}px`
77
- }
78
- }))`
79
- position: absolute;
80
- top: 0;
81
- background: ${(props) => props.$color};
82
- height: 100%;
83
- z-index: 10;
84
- pointer-events: auto;
85
- opacity: 0.3;
86
- border: 2px solid ${(props) => props.$color};
87
- border-radius: 4px;
88
- cursor: pointer;
89
-
90
- &:hover {
91
- opacity: 0.5;
92
- border-color: ${(props) => props.$color};
93
- }
94
- `;
95
- var AnnotationText = import_styled_components.default.div`
96
- position: absolute;
97
- bottom: 0;
98
- left: 0;
99
- right: 0;
100
- background: rgba(0, 0, 0, 0.7);
101
- color: white;
102
- padding: 4px 8px;
103
- font-size: 12px;
104
- line-height: 1.3;
105
- max-height: 60%;
106
- overflow: hidden;
107
- text-overflow: ellipsis;
108
- pointer-events: none;
109
- white-space: pre-wrap;
110
- word-break: break-word;
111
- `;
112
- var EditableText = import_styled_components.default.textarea`
113
- position: absolute;
114
- bottom: 0;
115
- left: 0;
116
- right: 0;
117
- background: rgba(0, 0, 0, 0.9);
118
- color: white;
119
- padding: 4px 8px;
120
- font-size: 12px;
121
- line-height: 1.3;
122
- max-height: 60%;
123
- overflow: auto;
124
- border: 1px solid #fff;
125
- resize: none;
126
- font-family: inherit;
127
-
128
- &:focus {
129
- outline: none;
130
- border-color: #4caf50;
131
- }
132
- `;
133
- var ControlsBar = import_styled_components.default.div`
134
- position: absolute;
135
- top: 0;
136
- left: 0;
137
- right: 0;
138
- background: rgba(0, 0, 0, 0.8);
139
- display: flex;
140
- gap: 4px;
141
- padding: 4px;
142
- justify-content: flex-start;
143
- align-items: center;
144
- `;
145
- var ControlButton = import_styled_components.default.button`
146
- background: transparent;
147
- border: 1px solid rgba(255, 255, 255, 0.5);
148
- color: white;
149
- padding: 4px 8px;
150
- font-size: 10px;
151
- cursor: pointer;
152
- border-radius: 3px;
153
- display: flex;
154
- align-items: center;
155
- justify-content: center;
156
- min-width: 24px;
157
- height: 24px;
158
-
159
- &:hover {
160
- background: rgba(255, 255, 255, 0.2);
161
- border-color: white;
162
- }
163
-
164
- &:active {
165
- background: rgba(255, 255, 255, 0.3);
166
- }
167
- `;
168
- var Annotation = ({
169
- annotation,
170
- index,
171
- allAnnotations,
172
- startPosition,
173
- endPosition,
174
- color = "#ff9800",
175
- editable = false,
176
- controls = [],
177
- onAnnotationUpdate,
178
- annotationListConfig,
179
- onClick
180
- }) => {
181
- const [isEditing, setIsEditing] = (0, import_react.useState)(false);
182
- const [editedText, setEditedText] = (0, import_react.useState)(annotation.lines.join("\n"));
183
- const width = Math.max(0, endPosition - startPosition);
184
- if (width <= 0) {
185
- return null;
186
- }
187
- const handleClick = () => {
188
- if (onClick) {
189
- onClick(annotation);
190
- }
191
- };
192
- const handleDoubleClick = () => {
193
- if (editable) {
194
- setIsEditing(true);
195
- }
196
- };
197
- const handleTextChange = (e) => {
198
- setEditedText(e.target.value);
199
- };
200
- const handleTextBlur = () => {
201
- setIsEditing(false);
202
- const newLines = editedText.split("\n");
203
- if (newLines.join("\n") !== annotation.lines.join("\n")) {
204
- const updatedAnnotations = [...allAnnotations];
205
- updatedAnnotations[index] = { ...annotation, lines: newLines };
206
- if (onAnnotationUpdate) {
207
- onAnnotationUpdate(updatedAnnotations);
208
- }
209
- }
210
- };
211
- const handleControlClick = (control) => {
212
- const annotationsCopy = [...allAnnotations];
213
- control.action(annotationsCopy[index], index, annotationsCopy, annotationListConfig || {});
214
- if (onAnnotationUpdate) {
215
- onAnnotationUpdate(annotationsCopy);
216
- }
217
- };
218
- const getIconClass = (classString) => {
219
- return classString.replace(/\./g, " ");
220
- };
221
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
222
- AnnotationOverlay,
223
- {
224
- $left: startPosition,
225
- $width: width,
226
- $color: color,
227
- onClick: handleClick,
228
- onDoubleClick: handleDoubleClick,
229
- children: [
230
- controls.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ControlsBar, { children: controls.map((control, idx) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
231
- ControlButton,
232
- {
233
- title: control.title,
234
- onClick: (e) => {
235
- e.stopPropagation();
236
- handleControlClick(control);
237
- },
238
- children: control.text ? control.text : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("i", { className: getIconClass(control.class || "") })
239
- },
240
- idx
241
- )) }),
242
- isEditing ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
243
- EditableText,
244
- {
245
- value: editedText,
246
- onChange: handleTextChange,
247
- onBlur: handleTextBlur,
248
- autoFocus: true,
249
- onClick: (e) => e.stopPropagation(),
250
- onDoubleClick: (e) => e.stopPropagation()
251
- }
252
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AnnotationText, { children: annotation.lines.join("\n") })
253
- ]
254
- }
255
- );
256
- };
257
-
258
66
  // src/components/AnnotationBox.tsx
259
- var import_styled_components2 = __toESM(require("styled-components"));
260
- var import_react2 = require("@dnd-kit/react");
67
+ var import_styled_components = __toESM(require("styled-components"));
68
+ var import_react = require("@dnd-kit/react");
261
69
  var import_dom = require("@dnd-kit/dom");
262
- var import_jsx_runtime2 = require("react/jsx-runtime");
70
+ var import_jsx_runtime = require("react/jsx-runtime");
263
71
  var EDGE_HANDLE_PLUGINS = [import_dom.Feedback.configure({ feedback: "none" })];
264
- var Wrapper = import_styled_components2.default.div.attrs((props) => ({
72
+ var Wrapper = import_styled_components.default.div.attrs((props) => ({
265
73
  style: {
266
74
  left: `${props.$left}px`,
267
75
  width: `${props.$width}px`
@@ -272,7 +80,7 @@ var Wrapper = import_styled_components2.default.div.attrs((props) => ({
272
80
  height: 100%;
273
81
  pointer-events: none; /* Let events pass through to children */
274
82
  `;
275
- var Box = import_styled_components2.default.div`
83
+ var Box = import_styled_components.default.div`
276
84
  position: absolute;
277
85
  top: 0;
278
86
  left: 0;
@@ -289,7 +97,11 @@ var Box = import_styled_components2.default.div`
289
97
  justify-content: center;
290
98
  overflow: hidden;
291
99
  transition: all 0.2s ease;
292
- box-shadow: ${(props) => props.$isActive ? "0 2px 8px rgba(255, 152, 0, 0.4), inset 0 0 0 1px rgba(255, 152, 0, 0.2)" : "0 1px 3px rgba(0, 0, 0, 0.1)"};
100
+ box-shadow: ${(props) => props.$isActive ? (
101
+ // The glow of the active box is the box colour (the theme's
102
+ // `annotationBoxBorder`, through the `color` prop) at 40% and 20%.
103
+ `0 2px 8px color-mix(in srgb, ${props.$color} 40%, transparent), inset 0 0 0 1px color-mix(in srgb, ${props.$color} 20%, transparent)`
104
+ ) : "0 1px 3px rgba(0, 0, 0, 0.1)"};
293
105
 
294
106
  &:hover {
295
107
  background: ${(props) => props.theme?.annotationBoxHoverBackground || "rgba(255, 255, 255, 0.98)"};
@@ -298,7 +110,7 @@ var Box = import_styled_components2.default.div`
298
110
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
299
111
  }
300
112
  `;
301
- var Label = import_styled_components2.default.span`
113
+ var Label = import_styled_components.default.span`
302
114
  font-size: 12px;
303
115
  font-weight: 600;
304
116
  color: ${(props) => props.theme?.annotationLabelColor || "#2a2a2a"};
@@ -309,7 +121,7 @@ var Label = import_styled_components2.default.span`
309
121
  letter-spacing: 0.3px;
310
122
  user-select: none;
311
123
  `;
312
- var ResizeHandle = import_styled_components2.default.div`
124
+ var ResizeHandle = import_styled_components.default.div`
313
125
  position: absolute;
314
126
  top: 0;
315
127
  ${(props) => props.$position === "left" ? "left: 0" : "right: 0"};
@@ -360,14 +172,14 @@ var AnnotationBox = ({
360
172
  }) => {
361
173
  const width = Math.max(0, endPosition - startPosition);
362
174
  const leftBoundaryId = `annotation-boundary-start-${annotationIndex}`;
363
- const { ref: leftRef, isDragSource: isLeftDragging } = (0, import_react2.useDraggable)({
175
+ const { ref: leftRef, isDragSource: isLeftDragging } = (0, import_react.useDraggable)({
364
176
  id: leftBoundaryId,
365
177
  data: { annotationId, annotationIndex, edge: "start" },
366
178
  disabled: !editable,
367
179
  plugins: EDGE_HANDLE_PLUGINS
368
180
  });
369
181
  const rightBoundaryId = `annotation-boundary-end-${annotationIndex}`;
370
- const { ref: rightRef, isDragSource: isRightDragging } = (0, import_react2.useDraggable)({
182
+ const { ref: rightRef, isDragSource: isRightDragging } = (0, import_react.useDraggable)({
371
183
  id: rightBoundaryId,
372
184
  data: { annotationId, annotationIndex, edge: "end" },
373
185
  disabled: !editable,
@@ -379,9 +191,9 @@ var AnnotationBox = ({
379
191
  const handleHandleClick = (e) => {
380
192
  e.stopPropagation();
381
193
  };
382
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Wrapper, { $left: startPosition, $width: width, children: [
383
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Box, { $color: color, $isActive: isActive, onClick, children: label && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { children: label }) }),
384
- editable && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
194
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Wrapper, { $left: startPosition, $width: width, children: [
195
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Box, { $color: color, $isActive: isActive, onClick, children: label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Label, { children: label }) }),
196
+ editable && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
385
197
  ResizeHandle,
386
198
  {
387
199
  ref: leftRef,
@@ -390,7 +202,7 @@ var AnnotationBox = ({
390
202
  onClick: handleHandleClick
391
203
  }
392
204
  ),
393
- editable && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
205
+ editable && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
394
206
  ResizeHandle,
395
207
  {
396
208
  ref: rightRef,
@@ -403,19 +215,19 @@ var AnnotationBox = ({
403
215
  };
404
216
 
405
217
  // src/components/AnnotationBoxesWrapper.tsx
406
- var import_styled_components3 = __toESM(require("styled-components"));
407
- var import_jsx_runtime3 = require("react/jsx-runtime");
408
- var Container = import_styled_components3.default.div.attrs((props) => ({
218
+ var import_styled_components2 = __toESM(require("styled-components"));
219
+ var import_jsx_runtime2 = require("react/jsx-runtime");
220
+ var Container = import_styled_components2.default.div.attrs((props) => ({
409
221
  style: {
410
- height: `${props.$height}px`
222
+ height: `${props.$height}px`,
223
+ width: props.$width !== void 0 ? `${props.$width}px` : void 0
411
224
  }
412
225
  }))`
413
226
  position: relative;
414
- ${(props) => props.$width !== void 0 && `width: ${props.$width}px;`}
415
227
  background: transparent;
416
228
  z-index: 110;
417
229
  `;
418
- var BoxesContainer = import_styled_components3.default.div`
230
+ var BoxesContainer = import_styled_components2.default.div`
419
231
  position: relative;
420
232
  height: 100%;
421
233
  padding-left: ${(props) => props.$offset || 0}px;
@@ -427,78 +239,53 @@ var AnnotationBoxesWrapper = ({
427
239
  offset = 0,
428
240
  width
429
241
  }) => {
430
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Container, { className, $height: height, $width: width, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(BoxesContainer, { $offset: offset, children }) });
431
- };
432
-
433
- // src/components/AnnotationsTrack.tsx
434
- var import_styled_components4 = __toESM(require("styled-components"));
435
- var import_jsx_runtime4 = require("react/jsx-runtime");
436
- var Container2 = import_styled_components4.default.div.attrs((props) => ({
437
- style: {
438
- height: `${props.$height}px`
439
- }
440
- }))`
441
- position: relative;
442
- ${(props) => props.$width !== void 0 && `width: ${props.$width}px;`}
443
- background: transparent;
444
- `;
445
- var AnnotationsContainer = import_styled_components4.default.div`
446
- position: relative;
447
- height: 100%;
448
- padding-left: ${(props) => props.$offset || 0}px;
449
- `;
450
- var AnnotationsTrack = ({
451
- children,
452
- className,
453
- height = 100,
454
- offset = 0,
455
- width
456
- }) => {
457
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Container2, { className, $height: height, $width: width, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AnnotationsContainer, { $offset: offset, children }) });
242
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Container, { className, $height: height, $width: width, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BoxesContainer, { $offset: offset, children }) });
458
243
  };
459
244
 
460
245
  // src/components/AnnotationText.tsx
461
- var import_react3 = __toESM(require("react"));
462
- var import_styled_components5 = __toESM(require("styled-components"));
463
- var import_jsx_runtime5 = require("react/jsx-runtime");
464
- var Container3 = import_styled_components5.default.div`
246
+ var import_react2 = __toESM(require("react"));
247
+ var import_styled_components3 = __toESM(require("styled-components"));
248
+ var import_jsx_runtime3 = require("react/jsx-runtime");
249
+ var activeColor = (props) => props.theme?.annotationTextItemActiveColor || "#ff9800";
250
+ var activeTint = (percent) => (props) => `color-mix(in srgb, ${activeColor(props)} ${percent}%, transparent)`;
251
+ var Container2 = import_styled_components3.default.div`
465
252
  background: ${(props) => props.theme?.backgroundColor || "#fff"};
466
253
  ${(props) => props.$height ? `height: ${props.$height}px;` : "max-height: 200px;"}
467
254
  overflow-y: auto;
468
255
  padding: 8px;
469
256
  `;
470
- var AnnotationItem = import_styled_components5.default.div`
257
+ var AnnotationItem = import_styled_components3.default.div`
471
258
  padding: 12px;
472
259
  margin-bottom: 6px;
473
- border-left: 4px solid ${(props) => props.$isActive ? "#ff9800" : "transparent"};
474
- background: ${(props) => props.$isActive ? "rgba(255, 152, 0, 0.15)" : "transparent"};
260
+ border-left: 4px solid ${(props) => props.$isActive ? activeColor(props) : "transparent"};
261
+ background: ${(props) => props.$isActive ? activeTint(15)(props) : "transparent"};
475
262
  border-radius: 4px;
476
263
  transition: all 0.2s;
477
264
  cursor: pointer;
478
- box-shadow: ${(props) => props.$isActive ? "0 2px 8px rgba(255, 152, 0, 0.25), inset 0 0 0 1px rgba(255, 152, 0, 0.3)" : "none"};
265
+ box-shadow: ${(props) => props.$isActive ? `0 2px 8px ${activeTint(25)(props)}, inset 0 0 0 1px ${activeTint(30)(props)}` : "none"};
479
266
 
480
267
  &:hover {
481
- background: ${(props) => props.$isActive ? "rgba(255, 152, 0, 0.2)" : props.theme?.annotationTextItemHoverBackground || "rgba(0, 0, 0, 0.05)"};
482
- border-left-color: ${(props) => props.$isActive ? "#ff9800" : props.theme?.borderColor || "#ddd"};
268
+ background: ${(props) => props.$isActive ? activeTint(20)(props) : props.theme?.annotationTextItemHoverBackground || "rgba(0, 0, 0, 0.05)"};
269
+ border-left-color: ${(props) => props.$isActive ? activeColor(props) : props.theme?.borderColor || "#ddd"};
483
270
  }
484
271
 
485
272
  &:focus-visible {
486
- outline: 2px solid #ff9800;
273
+ outline: 2px solid ${activeColor};
487
274
  outline-offset: 2px;
488
275
  }
489
276
  `;
490
- var AnnotationHeader = import_styled_components5.default.div`
277
+ var AnnotationHeader = import_styled_components3.default.div`
491
278
  display: flex;
492
279
  justify-content: space-between;
493
280
  align-items: center;
494
281
  margin-bottom: 6px;
495
282
  `;
496
- var AnnotationInfo = import_styled_components5.default.div`
283
+ var AnnotationInfo = import_styled_components3.default.div`
497
284
  display: flex;
498
285
  align-items: center;
499
286
  gap: 8px;
500
287
  `;
501
- var AnnotationIdLabel = import_styled_components5.default.span`
288
+ var AnnotationIdLabel = import_styled_components3.default.span`
502
289
  font-size: 11px;
503
290
  font-weight: 600;
504
291
  color: ${(props) => props.theme?.textColorMuted || "#666"};
@@ -509,22 +296,22 @@ var AnnotationIdLabel = import_styled_components5.default.span`
509
296
  outline: ${(props) => props.$isEditable ? `1px dashed ${props.theme?.borderColor || "#ddd"}` : "none"};
510
297
 
511
298
  &[contenteditable='true']:focus {
512
- outline: 2px solid #ff9800;
513
- background: rgba(255, 152, 0, 0.1);
299
+ outline: 2px solid ${activeColor};
300
+ background: ${activeTint(10)};
514
301
  }
515
302
  `;
516
- var TimeRange = import_styled_components5.default.span`
303
+ var TimeRange = import_styled_components3.default.span`
517
304
  font-size: 12px;
518
305
  font-weight: 500;
519
306
  color: ${(props) => props.theme?.textColorMuted || "#555"};
520
307
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
521
308
  letter-spacing: 0.5px;
522
309
  `;
523
- var AnnotationControls = import_styled_components5.default.div`
310
+ var AnnotationControls = import_styled_components3.default.div`
524
311
  display: flex;
525
312
  gap: 6px;
526
313
  `;
527
- var ControlButton2 = import_styled_components5.default.button`
314
+ var ControlButton = import_styled_components3.default.button`
528
315
  background: ${(props) => props.theme?.surfaceColor || "#f5f5f5"};
529
316
  border: 1px solid ${(props) => props.theme?.borderColor || "#ccc"};
530
317
  color: ${(props) => props.theme?.textColor || "#333"};
@@ -544,7 +331,7 @@ var ControlButton2 = import_styled_components5.default.button`
544
331
  transform: scale(0.95);
545
332
  }
546
333
  `;
547
- var AnnotationTextContent = import_styled_components5.default.div`
334
+ var AnnotationTextContent = import_styled_components3.default.div`
548
335
  font-size: 14px;
549
336
  line-height: 1.6;
550
337
  color: ${(props) => props.theme?.textColor || "#2a2a2a"};
@@ -556,10 +343,99 @@ var AnnotationTextContent = import_styled_components5.default.div`
556
343
  min-height: 20px;
557
344
 
558
345
  &[contenteditable='true']:focus {
559
- outline: 2px solid #ff9800;
560
- background: rgba(255, 152, 0, 0.1);
346
+ outline: 2px solid ${activeColor};
347
+ background: ${activeTint(10)};
561
348
  }
562
349
  `;
350
+ var NO_CONTROLS = [];
351
+ var formatTime = (seconds) => {
352
+ if (isNaN(seconds) || !isFinite(seconds)) {
353
+ return "0:00.000";
354
+ }
355
+ const mins = Math.floor(seconds / 60);
356
+ const secs = (seconds % 60).toFixed(3);
357
+ return `${mins}:${secs.padStart(6, "0")}`;
358
+ };
359
+ var getIconClass = (classString) => {
360
+ return classString.replace(/\./g, " ");
361
+ };
362
+ var blurOnEnter = (e) => {
363
+ if (e.key === "Enter") {
364
+ e.preventDefault();
365
+ e.currentTarget.blur();
366
+ }
367
+ };
368
+ var AnnotationListItem = import_react2.default.memo(function AnnotationListItem2({
369
+ annotation,
370
+ index,
371
+ isActive,
372
+ itemRef,
373
+ editable,
374
+ controls,
375
+ onAnnotationClick,
376
+ onTextEdit,
377
+ onIdEdit,
378
+ onControlClick,
379
+ renderAnnotationItem
380
+ }) {
381
+ const handleClick = () => onAnnotationClick?.(annotation);
382
+ const handleRowClick = (event) => {
383
+ const target = event.target;
384
+ if (target?.closest?.('[contenteditable="true"]')) return;
385
+ handleClick();
386
+ };
387
+ if (renderAnnotationItem) {
388
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { ref: itemRef, children: renderAnnotationItem({
389
+ annotation,
390
+ index,
391
+ isActive,
392
+ onClick: handleClick,
393
+ formatTime
394
+ }) });
395
+ }
396
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(AnnotationItem, { ref: itemRef, $isActive: isActive, onClick: handleRowClick, children: [
397
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(AnnotationHeader, { children: [
398
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(AnnotationInfo, { children: [
399
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
400
+ AnnotationIdLabel,
401
+ {
402
+ $isEditable: editable,
403
+ contentEditable: editable,
404
+ suppressContentEditableWarning: true,
405
+ onBlur: (e) => onIdEdit(index, e.currentTarget.textContent || ""),
406
+ onKeyDown: blurOnEnter,
407
+ children: annotation.id
408
+ }
409
+ ),
410
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(TimeRange, { children: [
411
+ formatTime(annotation.start),
412
+ " - ",
413
+ formatTime(annotation.end)
414
+ ] })
415
+ ] }),
416
+ controls.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(AnnotationControls, { onClick: (e) => e.stopPropagation(), children: controls.map((control, idx) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
417
+ ControlButton,
418
+ {
419
+ title: control.title,
420
+ onClick: () => onControlClick(control, index),
421
+ children: control.text ? control.text : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("i", { className: getIconClass(control.class || "") })
422
+ },
423
+ idx
424
+ )) })
425
+ ] }),
426
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
427
+ AnnotationTextContent,
428
+ {
429
+ $isEditable: editable,
430
+ contentEditable: editable,
431
+ suppressContentEditableWarning: true,
432
+ onBlur: (e) => onTextEdit(index, e.currentTarget.textContent || ""),
433
+ onKeyDown: blurOnEnter,
434
+ children: annotation.lines.join("\n")
435
+ }
436
+ )
437
+ ] });
438
+ });
563
439
  var AnnotationTextComponent = ({
564
440
  annotations,
565
441
  activeAnnotationId,
@@ -567,27 +443,15 @@ var AnnotationTextComponent = ({
567
443
  scrollActivePosition = "center",
568
444
  scrollActiveContainer = "nearest",
569
445
  editable = false,
570
- controls = [],
446
+ controls = NO_CONTROLS,
571
447
  annotationListConfig,
572
448
  height,
573
449
  onAnnotationClick,
574
450
  onAnnotationUpdate,
575
451
  renderAnnotationItem
576
452
  }) => {
577
- const activeAnnotationRef = (0, import_react3.useRef)(null);
578
- const containerRef = (0, import_react3.useRef)(null);
579
- const prevActiveIdRef = (0, import_react3.useRef)(void 0);
580
- (0, import_react3.useEffect)(() => {
581
- });
582
- (0, import_react3.useEffect)(() => {
583
- const container = containerRef.current;
584
- if (!container) return;
585
- const handleScroll = () => {
586
- };
587
- container.addEventListener("scroll", handleScroll);
588
- return () => container.removeEventListener("scroll", handleScroll);
589
- }, []);
590
- (0, import_react3.useEffect)(() => {
453
+ const activeAnnotationRef = (0, import_react2.useRef)(null);
454
+ (0, import_react2.useEffect)(() => {
591
455
  if (activeAnnotationId && activeAnnotationRef.current && shouldScrollToActive) {
592
456
  activeAnnotationRef.current.scrollIntoView({
593
457
  behavior: "smooth",
@@ -595,204 +459,145 @@ var AnnotationTextComponent = ({
595
459
  container: scrollActiveContainer
596
460
  });
597
461
  }
598
- prevActiveIdRef.current = activeAnnotationId;
599
462
  }, [activeAnnotationId, shouldScrollToActive, scrollActivePosition, scrollActiveContainer]);
600
- const formatTime = (seconds) => {
601
- if (isNaN(seconds) || !isFinite(seconds)) {
602
- return "0:00.000";
603
- }
604
- const mins = Math.floor(seconds / 60);
605
- const secs = (seconds % 60).toFixed(3);
606
- return `${mins}:${secs.padStart(6, "0")}`;
607
- };
608
- const handleTextEdit = (index, newText) => {
609
- if (!editable || !onAnnotationUpdate) return;
610
- const updatedAnnotations = [...annotations];
611
- updatedAnnotations[index] = {
612
- ...updatedAnnotations[index],
613
- lines: newText.split("\n")
614
- };
615
- onAnnotationUpdate(updatedAnnotations);
616
- };
617
- const handleIdEdit = (index, newId) => {
618
- if (!editable || !onAnnotationUpdate) return;
619
- const trimmedId = newId.trim();
620
- if (!trimmedId) return;
621
- const updatedAnnotations = [...annotations];
622
- updatedAnnotations[index] = {
623
- ...updatedAnnotations[index],
624
- id: trimmedId
625
- };
626
- onAnnotationUpdate(updatedAnnotations);
627
- };
628
- const handleControlClick = (control, annotation, index) => {
629
- if (!onAnnotationUpdate) return;
630
- const annotationsCopy = [...annotations];
631
- control.action(annotationsCopy[index], index, annotationsCopy, annotationListConfig || {});
632
- onAnnotationUpdate(annotationsCopy);
633
- };
634
- const getIconClass = (classString) => {
635
- return classString.replace(/\./g, " ");
636
- };
637
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Container3, { ref: containerRef, $height: height, children: annotations.map((annotation, index) => {
463
+ const annotationsRef = (0, import_react2.useRef)(annotations);
464
+ annotationsRef.current = annotations;
465
+ const annotationListConfigRef = (0, import_react2.useRef)(annotationListConfig);
466
+ annotationListConfigRef.current = annotationListConfig;
467
+ const handleTextEdit = (0, import_react2.useCallback)(
468
+ (index, newText) => {
469
+ if (!editable || !onAnnotationUpdate) return;
470
+ const updatedAnnotations = [...annotationsRef.current];
471
+ updatedAnnotations[index] = {
472
+ ...updatedAnnotations[index],
473
+ lines: newText.split("\n")
474
+ };
475
+ onAnnotationUpdate(updatedAnnotations);
476
+ },
477
+ [editable, onAnnotationUpdate]
478
+ );
479
+ const handleIdEdit = (0, import_react2.useCallback)(
480
+ (index, newId) => {
481
+ if (!editable || !onAnnotationUpdate) return;
482
+ const trimmedId = newId.trim();
483
+ if (!trimmedId) return;
484
+ const updatedAnnotations = [...annotationsRef.current];
485
+ updatedAnnotations[index] = {
486
+ ...updatedAnnotations[index],
487
+ id: trimmedId
488
+ };
489
+ onAnnotationUpdate(updatedAnnotations);
490
+ },
491
+ [editable, onAnnotationUpdate]
492
+ );
493
+ const handleControlClick = (0, import_react2.useCallback)(
494
+ (control, index) => {
495
+ if (!onAnnotationUpdate) return;
496
+ const annotationsCopy = [...annotationsRef.current];
497
+ control.action(
498
+ annotationsCopy[index],
499
+ index,
500
+ annotationsCopy,
501
+ annotationListConfigRef.current || {}
502
+ );
503
+ onAnnotationUpdate(annotationsCopy);
504
+ },
505
+ [onAnnotationUpdate]
506
+ );
507
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Container2, { $height: height, children: annotations.map((annotation, index) => {
638
508
  const isActive = annotation.id === activeAnnotationId;
639
- const handleClick = () => onAnnotationClick?.(annotation);
640
- if (renderAnnotationItem) {
641
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { ref: isActive ? activeAnnotationRef : null, children: renderAnnotationItem({
509
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
510
+ AnnotationListItem,
511
+ {
642
512
  annotation,
643
513
  index,
644
514
  isActive,
645
- onClick: handleClick,
646
- formatTime
647
- }) }, annotation.id);
648
- }
649
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
650
- AnnotationItem,
651
- {
652
- ref: isActive ? activeAnnotationRef : null,
653
- $isActive: isActive,
654
- onClick: handleClick,
655
- children: [
656
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(AnnotationHeader, { children: [
657
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(AnnotationInfo, { children: [
658
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
659
- AnnotationIdLabel,
660
- {
661
- $isEditable: editable,
662
- contentEditable: editable,
663
- suppressContentEditableWarning: true,
664
- onBlur: (e) => handleIdEdit(index, e.currentTarget.textContent || ""),
665
- onKeyDown: (e) => {
666
- if (e.key === "Enter") {
667
- e.preventDefault();
668
- e.currentTarget.blur();
669
- }
670
- },
671
- children: annotation.id
672
- }
673
- ),
674
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(TimeRange, { children: [
675
- formatTime(annotation.start),
676
- " - ",
677
- formatTime(annotation.end)
678
- ] })
679
- ] }),
680
- controls.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AnnotationControls, { onClick: (e) => e.stopPropagation(), children: controls.map((control, idx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
681
- ControlButton2,
682
- {
683
- title: control.title,
684
- onClick: () => handleControlClick(control, annotation, index),
685
- children: control.text ? control.text : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("i", { className: getIconClass(control.class || "") })
686
- },
687
- idx
688
- )) })
689
- ] }),
690
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
691
- AnnotationTextContent,
692
- {
693
- $isEditable: editable,
694
- contentEditable: editable,
695
- suppressContentEditableWarning: true,
696
- onBlur: (e) => handleTextEdit(index, e.currentTarget.textContent || ""),
697
- onKeyDown: (e) => {
698
- if (e.key === "Enter") {
699
- e.preventDefault();
700
- e.currentTarget.blur();
701
- }
702
- },
703
- children: annotation.lines.join("\n")
704
- }
705
- )
706
- ]
515
+ itemRef: isActive ? activeAnnotationRef : void 0,
516
+ editable,
517
+ controls,
518
+ onAnnotationClick,
519
+ onTextEdit: handleTextEdit,
520
+ onIdEdit: handleIdEdit,
521
+ onControlClick: handleControlClick,
522
+ renderAnnotationItem
707
523
  },
708
524
  annotation.id
709
525
  );
710
526
  }) });
711
527
  };
712
- var AnnotationText2 = import_react3.default.memo(AnnotationTextComponent);
528
+ var AnnotationText = import_react2.default.memo(AnnotationTextComponent);
713
529
 
714
- // src/components/ContinuousPlayCheckbox.tsx
530
+ // src/components/AnnotationCheckboxes.tsx
531
+ var import_react3 = require("react");
715
532
  var import_ui_components = require("@waveform-playlist/ui-components");
716
- var import_jsx_runtime6 = require("react/jsx-runtime");
717
- var ContinuousPlayCheckbox = ({
533
+ var import_browser = require("@waveform-playlist/browser");
534
+ var import_jsx_runtime4 = require("react/jsx-runtime");
535
+ var OptionCheckbox = ({
718
536
  checked,
719
537
  onChange,
720
- disabled = false,
721
- className
538
+ inputClassName,
539
+ className,
540
+ disabled,
541
+ children
722
542
  }) => {
723
- const handleChange = (e) => {
724
- onChange(e.target.checked);
725
- };
726
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui_components.BaseCheckboxWrapper, { className, children: [
727
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
543
+ const id = (0, import_react3.useId)();
544
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_ui_components.BaseCheckboxWrapper, { className, children: [
545
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
728
546
  import_ui_components.BaseCheckbox,
729
547
  {
730
548
  type: "checkbox",
731
- id: "continuous-play",
732
- className: "continuous-play",
549
+ id,
550
+ className: inputClassName,
733
551
  checked,
734
- onChange: handleChange,
552
+ onChange: (e) => onChange(e.target.checked),
735
553
  disabled
736
554
  }
737
555
  ),
738
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui_components.BaseCheckboxLabel, { htmlFor: "continuous-play", children: "Continuous Play" })
556
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui_components.BaseCheckboxLabel, { htmlFor: id, children })
739
557
  ] });
740
558
  };
741
-
742
- // src/components/LinkEndpointsCheckbox.tsx
743
- var import_ui_components2 = require("@waveform-playlist/ui-components");
744
- var import_jsx_runtime7 = require("react/jsx-runtime");
745
- var LinkEndpointsCheckbox = ({
746
- checked,
747
- onChange,
748
- disabled = false,
749
- className
559
+ var ContinuousPlayCheckbox = ({
560
+ children,
561
+ ...rest
750
562
  }) => {
751
- const handleChange = (e) => {
752
- onChange(e.target.checked);
753
- };
754
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui_components2.BaseCheckboxWrapper, { className, children: [
755
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
756
- import_ui_components2.BaseCheckbox,
757
- {
758
- type: "checkbox",
759
- id: "link-endpoints",
760
- className: "link-endpoints",
761
- checked,
762
- onChange: handleChange,
763
- disabled
764
- }
765
- ),
766
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui_components2.BaseCheckboxLabel, { htmlFor: "link-endpoints", children: "Link Endpoints" })
767
- ] });
563
+ const { continuousPlay } = (0, import_browser.useAnnotationOptions)();
564
+ const { setContinuousPlay } = (0, import_browser.usePlaybackControls)();
565
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
566
+ OptionCheckbox,
567
+ {
568
+ ...rest,
569
+ checked: continuousPlay,
570
+ onChange: setContinuousPlay,
571
+ inputClassName: "continuous-play",
572
+ children: children ?? "Continuous Play"
573
+ }
574
+ );
768
575
  };
769
-
770
- // src/components/EditableCheckbox.tsx
771
- var import_ui_components3 = require("@waveform-playlist/ui-components");
772
- var import_jsx_runtime8 = require("react/jsx-runtime");
773
- var EditableCheckbox = ({
774
- checked,
775
- onChange,
776
- className
777
- }) => {
778
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui_components3.BaseCheckboxWrapper, { className, children: [
779
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
780
- import_ui_components3.BaseCheckbox,
781
- {
782
- type: "checkbox",
783
- id: "editable-annotations",
784
- checked,
785
- onChange: (e) => onChange(e.target.checked)
786
- }
787
- ),
788
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui_components3.BaseCheckboxLabel, { htmlFor: "editable-annotations", children: "Editable Annotations" })
789
- ] });
576
+ var LinkEndpointsCheckbox = ({ children, ...rest }) => {
577
+ const { linkEndpoints } = (0, import_browser.useAnnotationOptions)();
578
+ const { setLinkEndpoints } = (0, import_browser.usePlaybackControls)();
579
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
580
+ OptionCheckbox,
581
+ {
582
+ ...rest,
583
+ checked: linkEndpoints,
584
+ onChange: setLinkEndpoints,
585
+ inputClassName: "link-endpoints",
586
+ children: children ?? "Link Endpoints"
587
+ }
588
+ );
589
+ };
590
+ var EditableCheckbox = ({ children, ...rest }) => {
591
+ const { editable } = (0, import_browser.useAnnotationOptions)();
592
+ const { setAnnotationsEditable } = (0, import_browser.usePlaybackControls)();
593
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(OptionCheckbox, { ...rest, checked: editable, onChange: setAnnotationsEditable, children: children ?? "Editable Annotations" });
790
594
  };
791
595
 
792
596
  // src/components/DownloadAnnotationsButton.tsx
793
- var import_styled_components6 = __toESM(require("styled-components"));
794
- var import_jsx_runtime9 = require("react/jsx-runtime");
795
- var StyledButton = import_styled_components6.default.button`
597
+ var import_styled_components4 = __toESM(require("styled-components"));
598
+ var import_browser2 = require("@waveform-playlist/browser");
599
+ var import_jsx_runtime5 = require("react/jsx-runtime");
600
+ var StyledButton = import_styled_components4.default.button`
796
601
  padding: 0.5rem 1rem;
797
602
  background: ${(props) => props.theme?.surfaceColor || "#f5f5f5"};
798
603
  color: ${(props) => props.theme?.textColor || "#333"};
@@ -820,16 +625,14 @@ var StyledButton = import_styled_components6.default.button`
820
625
  }
821
626
  `;
822
627
  var DownloadAnnotationsButton = ({
823
- annotations,
824
628
  filename = "annotations.json",
825
629
  disabled = false,
826
630
  className,
827
- children = "Download JSON"
631
+ children = "Download JSON",
632
+ title
828
633
  }) => {
634
+ const { annotations } = (0, import_browser2.useAnnotations)();
829
635
  const handleDownload = () => {
830
- if (annotations.length === 0) {
831
- return;
832
- }
833
636
  const jsonData = annotations.map((annotation) => serializeAeneas(annotation));
834
637
  const jsonString = JSON.stringify(jsonData, null, 2);
835
638
  const blob = new Blob([jsonString], { type: "application/json" });
@@ -842,69 +645,42 @@ var DownloadAnnotationsButton = ({
842
645
  document.body.removeChild(link);
843
646
  URL.revokeObjectURL(url);
844
647
  };
845
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
648
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
846
649
  StyledButton,
847
650
  {
848
651
  onClick: handleDownload,
849
652
  disabled: disabled || annotations.length === 0,
850
653
  className,
851
- title: annotations.length === 0 ? "No annotations to download" : "Download the annotations as JSON",
654
+ title: title ?? (annotations.length === 0 ? "No annotations to download" : "Download the annotations as JSON"),
852
655
  children
853
656
  }
854
657
  );
855
658
  };
856
659
 
857
660
  // src/AnnotationProvider.tsx
858
- var import_browser = require("@waveform-playlist/browser");
859
- var import_jsx_runtime10 = require("react/jsx-runtime");
661
+ var import_browser3 = require("@waveform-playlist/browser");
662
+ var import_jsx_runtime6 = require("react/jsx-runtime");
860
663
  var annotationIntegration = {
861
664
  parseAeneas,
862
665
  serializeAeneas,
863
- AnnotationText: AnnotationText2,
666
+ AnnotationText,
864
667
  AnnotationBox,
865
- AnnotationBoxesWrapper,
866
- ContinuousPlayCheckbox,
867
- LinkEndpointsCheckbox,
868
- EditableCheckbox,
869
- DownloadAnnotationsButton
668
+ AnnotationBoxesWrapper
870
669
  };
871
670
  var AnnotationProvider = ({ children }) => {
872
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_browser.AnnotationIntegrationProvider, { value: annotationIntegration, children });
873
- };
874
-
875
- // src/hooks/useAnnotationControls.ts
876
- var import_react4 = require("react");
877
- var import_core = require("@waveform-playlist/core");
878
- var useAnnotationControls = (options = {}) => {
879
- const { initialContinuousPlay = false, initialLinkEndpoints = true } = options;
880
- const [continuousPlay, setContinuousPlay] = (0, import_react4.useState)(initialContinuousPlay);
881
- const [linkEndpoints, setLinkEndpoints] = (0, import_react4.useState)(initialLinkEndpoints);
882
- const updateAnnotationBoundaries = (0, import_react4.useCallback)(
883
- (params) => (0, import_core.updateAnnotationBoundaries)(params),
884
- []
885
- );
886
- return {
887
- continuousPlay,
888
- linkEndpoints,
889
- setContinuousPlay,
890
- setLinkEndpoints,
891
- updateAnnotationBoundaries
892
- };
671
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_browser3.AnnotationIntegrationProvider, { value: annotationIntegration, children });
893
672
  };
894
673
  // Annotate the CommonJS export names for ESM import in node:
895
674
  0 && (module.exports = {
896
- Annotation,
897
675
  AnnotationBox,
898
676
  AnnotationBoxesWrapper,
899
677
  AnnotationProvider,
900
678
  AnnotationText,
901
- AnnotationsTrack,
902
679
  ContinuousPlayCheckbox,
903
680
  DownloadAnnotationsButton,
904
681
  EditableCheckbox,
905
682
  LinkEndpointsCheckbox,
906
683
  parseAeneas,
907
- serializeAeneas,
908
- useAnnotationControls
684
+ serializeAeneas
909
685
  });
910
686
  //# sourceMappingURL=index.js.map