@waveform-playlist/core 13.0.0-next.11 → 13.0.0-next.12

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/README.md CHANGED
@@ -13,7 +13,7 @@ Used by nearly every `@waveform-playlist/*` and `@dawcore/*` package (`engine`,
13
13
  - **Peaks generation** — real-time min/max peak extraction during recording
14
14
  - **Musical time** — PPQN tick math, bar/beat conversion, time-signature meter detection, grid snapping
15
15
  - **Keyboard shortcuts** — a framework-agnostic shortcut matcher shared by the React and Web Components layers
16
- - **Annotation store** — `createAnnotationStore`, the one owner of a list of annotations that both React providers take as `annotationStore`: `set` / `update` apply at once, every list is validated, and an optional `beforeChange` rule can accept, refuse or adjust each change
16
+ - **Annotation store** — `createAnnotationStore`, the one owner of a list of annotations that both React providers take as `annotationStore`: `set` / `update` apply at once, every list is checked for finite times and unique ids (not for order, overlaps or an end before its start), and an optional `beforeChange` rule can accept, refuse or adjust each change
17
17
  - **Spectrogram canvas-ID contract** — canonical build/parse helpers for the `${clipId}-ch${n}-chunk${m}` canvas ID format shared by the worker pool and rendering layers
18
18
  - **HTTP range support probing** — detect whether an audio host supports byte-range seeking
19
19
 
package/dist/index.d.mts CHANGED
@@ -1394,10 +1394,18 @@ interface AnnotationBoundaryUpdate {
1394
1394
  linkEndpoints: boolean;
1395
1395
  }
1396
1396
  /**
1397
- * Pure boundary-update logic shared by the React annotations package and the
1398
- * dawcore annotation web components. Handles linked endpoints (moving one edge
1399
- * drags the linked neighbor edge, with cascade) and collision push-back.
1400
- * Returns a NEW array; never mutates inputs.
1397
+ * Pure boundary-update logic of an annotation edge drag and of the boundary
1398
+ * keys, used by `@waveform-playlist/browser` and by the dawcore annotation
1399
+ * elements, and exported for a custom annotation UI. Returns a NEW array;
1400
+ * never mutates inputs. Expects annotations in time order that do not
1401
+ * overlap; an overlapping list is invalid data (maintainer, #748), and an
1402
+ * out-of-order one is too (dawcore sorts its elements; React's store does not).
1403
+ *
1404
+ * A neighbour is a hard stop: a dragged edge stops at the neighbour's edge,
1405
+ * and the neighbour does not move (#748). With `linkEndpoints`, a neighbour
1406
+ * whose edge is within the link threshold is carried instead: its edge moves
1407
+ * with the dragged edge, which stops where the neighbour reaches the minimum
1408
+ * duration. Annotations further along never move.
1401
1409
  */
1402
1410
  declare function updateAnnotationBoundaries(params: AnnotationBoundaryUpdate, options?: AnnotationBoundaryOptions): AnnotationData[];
1403
1411
 
package/dist/index.d.ts CHANGED
@@ -1394,10 +1394,18 @@ interface AnnotationBoundaryUpdate {
1394
1394
  linkEndpoints: boolean;
1395
1395
  }
1396
1396
  /**
1397
- * Pure boundary-update logic shared by the React annotations package and the
1398
- * dawcore annotation web components. Handles linked endpoints (moving one edge
1399
- * drags the linked neighbor edge, with cascade) and collision push-back.
1400
- * Returns a NEW array; never mutates inputs.
1397
+ * Pure boundary-update logic of an annotation edge drag and of the boundary
1398
+ * keys, used by `@waveform-playlist/browser` and by the dawcore annotation
1399
+ * elements, and exported for a custom annotation UI. Returns a NEW array;
1400
+ * never mutates inputs. Expects annotations in time order that do not
1401
+ * overlap; an overlapping list is invalid data (maintainer, #748), and an
1402
+ * out-of-order one is too (dawcore sorts its elements; React's store does not).
1403
+ *
1404
+ * A neighbour is a hard stop: a dragged edge stops at the neighbour's edge,
1405
+ * and the neighbour does not move (#748). With `linkEndpoints`, a neighbour
1406
+ * whose edge is within the link threshold is carried instead: its edge moves
1407
+ * with the dragged edge, which stops where the neighbour reaches the minimum
1408
+ * duration. Annotations further along never move.
1401
1409
  */
1402
1410
  declare function updateAnnotationBoundaries(params: AnnotationBoundaryUpdate, options?: AnnotationBoundaryOptions): AnnotationData[];
1403
1411
 
package/dist/index.js CHANGED
@@ -1229,81 +1229,43 @@ function annotationMinDurationTicks(ppqn) {
1229
1229
  return Math.max(1, Math.round(ppqn / 32));
1230
1230
  }
1231
1231
  function updateAnnotationBoundaries(params, options = {}) {
1232
- const { annotationIndex, newTime, isDraggingStart, annotations, duration, linkEndpoints } = params;
1233
- const linkThreshold = options.linkThreshold ?? LINK_THRESHOLD;
1234
- const minDuration = options.minDuration ?? MIN_ANNOTATION_DURATION;
1235
- const updatedAnnotations = [...annotations];
1232
+ const units = {
1233
+ linkThreshold: options.linkThreshold ?? LINK_THRESHOLD,
1234
+ minDuration: options.minDuration ?? MIN_ANNOTATION_DURATION
1235
+ };
1236
+ return params.isDraggingStart ? moveStart(params, units) : moveEnd(params, units);
1237
+ }
1238
+ function moveStart({ annotationIndex, newTime, annotations, linkEndpoints }, { linkThreshold, minDuration }) {
1239
+ const updated = [...annotations];
1236
1240
  const annotation = annotations[annotationIndex];
1237
- if (isDraggingStart) {
1238
- const constrainedStart = Math.min(annotation.end - minDuration, Math.max(0, newTime));
1239
- updatedAnnotations[annotationIndex] = { ...annotation, start: constrainedStart };
1240
- if (linkEndpoints && annotationIndex > 0) {
1241
- const prevAnnotation = updatedAnnotations[annotationIndex - 1];
1242
- if (Math.abs(prevAnnotation.end - annotation.start) < linkThreshold) {
1243
- updatedAnnotations[annotationIndex - 1] = {
1244
- ...prevAnnotation,
1245
- end: Math.max(prevAnnotation.start + minDuration, constrainedStart)
1246
- };
1247
- } else if (constrainedStart <= prevAnnotation.end) {
1248
- updatedAnnotations[annotationIndex] = {
1249
- ...updatedAnnotations[annotationIndex],
1250
- start: prevAnnotation.end
1251
- };
1252
- }
1253
- } else if (!linkEndpoints && annotationIndex > 0 && constrainedStart < updatedAnnotations[annotationIndex - 1].end) {
1254
- updatedAnnotations[annotationIndex - 1] = {
1255
- ...updatedAnnotations[annotationIndex - 1],
1256
- end: constrainedStart
1257
- };
1258
- }
1241
+ const prev = annotationIndex > 0 ? annotations[annotationIndex - 1] : void 0;
1242
+ const start = Math.max(0, Math.min(annotation.end - minDuration, newTime));
1243
+ if (!prev) {
1244
+ updated[annotationIndex] = { ...annotation, start };
1245
+ } else if (linkEndpoints && Math.abs(prev.end - annotation.start) < linkThreshold) {
1246
+ const shared = Math.max(start, Math.min(prev.start + minDuration, prev.end));
1247
+ updated[annotationIndex - 1] = { ...prev, end: shared };
1248
+ updated[annotationIndex] = { ...annotation, start: shared };
1259
1249
  } else {
1260
- const constrainedEnd = Math.max(annotation.start + minDuration, Math.min(newTime, duration));
1261
- updatedAnnotations[annotationIndex] = { ...annotation, end: constrainedEnd };
1262
- if (linkEndpoints && annotationIndex < updatedAnnotations.length - 1) {
1263
- const nextAnnotation = updatedAnnotations[annotationIndex + 1];
1264
- if (Math.abs(nextAnnotation.start - annotation.end) < linkThreshold) {
1265
- updatedAnnotations[annotationIndex + 1] = {
1266
- ...nextAnnotation,
1267
- start: Math.min(nextAnnotation.end - minDuration, constrainedEnd)
1268
- };
1269
- let currentIndex = annotationIndex + 1;
1270
- while (currentIndex < updatedAnnotations.length - 1) {
1271
- const current = updatedAnnotations[currentIndex];
1272
- const next = updatedAnnotations[currentIndex + 1];
1273
- if (Math.abs(next.start - current.end) < linkThreshold) {
1274
- const nextDelta = current.end - annotations[currentIndex].end;
1275
- updatedAnnotations[currentIndex + 1] = {
1276
- ...next,
1277
- start: Math.min(next.end - minDuration, next.start + nextDelta)
1278
- };
1279
- currentIndex++;
1280
- } else {
1281
- break;
1282
- }
1283
- }
1284
- } else if (constrainedEnd >= nextAnnotation.start) {
1285
- updatedAnnotations[annotationIndex] = {
1286
- ...updatedAnnotations[annotationIndex],
1287
- end: nextAnnotation.start
1288
- };
1289
- }
1290
- } else if (!linkEndpoints && annotationIndex < updatedAnnotations.length - 1 && constrainedEnd > updatedAnnotations[annotationIndex + 1].start) {
1291
- const nextAnnotation = updatedAnnotations[annotationIndex + 1];
1292
- updatedAnnotations[annotationIndex + 1] = { ...nextAnnotation, start: constrainedEnd };
1293
- let currentIndex = annotationIndex + 1;
1294
- while (currentIndex < updatedAnnotations.length - 1) {
1295
- const current = updatedAnnotations[currentIndex];
1296
- const next = updatedAnnotations[currentIndex + 1];
1297
- if (current.end > next.start) {
1298
- updatedAnnotations[currentIndex + 1] = { ...next, start: current.end };
1299
- currentIndex++;
1300
- } else {
1301
- break;
1302
- }
1303
- }
1304
- }
1250
+ updated[annotationIndex] = { ...annotation, start: Math.max(start, prev.end) };
1251
+ }
1252
+ return updated;
1253
+ }
1254
+ function moveEnd({ annotationIndex, newTime, annotations, duration, linkEndpoints }, { linkThreshold, minDuration }) {
1255
+ const updated = [...annotations];
1256
+ const annotation = annotations[annotationIndex];
1257
+ const next = annotations[annotationIndex + 1];
1258
+ const end = Math.max(annotation.start + minDuration, Math.min(newTime, duration));
1259
+ if (!next) {
1260
+ updated[annotationIndex] = { ...annotation, end };
1261
+ } else if (linkEndpoints && Math.abs(next.start - annotation.end) < linkThreshold) {
1262
+ const shared = Math.min(end, Math.max(next.end - minDuration, next.start));
1263
+ updated[annotationIndex] = { ...annotation, end: shared };
1264
+ updated[annotationIndex + 1] = { ...next, start: shared };
1265
+ } else {
1266
+ updated[annotationIndex] = { ...annotation, end: Math.min(end, next.start) };
1305
1267
  }
1306
- return updatedAnnotations;
1268
+ return updated;
1307
1269
  }
1308
1270
 
1309
1271
  // src/annotations/shortcuts.ts