@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/dist/index.mjs CHANGED
@@ -1103,81 +1103,43 @@ function annotationMinDurationTicks(ppqn) {
1103
1103
  return Math.max(1, Math.round(ppqn / 32));
1104
1104
  }
1105
1105
  function updateAnnotationBoundaries(params, options = {}) {
1106
- const { annotationIndex, newTime, isDraggingStart, annotations, duration, linkEndpoints } = params;
1107
- const linkThreshold = options.linkThreshold ?? LINK_THRESHOLD;
1108
- const minDuration = options.minDuration ?? MIN_ANNOTATION_DURATION;
1109
- const updatedAnnotations = [...annotations];
1106
+ const units = {
1107
+ linkThreshold: options.linkThreshold ?? LINK_THRESHOLD,
1108
+ minDuration: options.minDuration ?? MIN_ANNOTATION_DURATION
1109
+ };
1110
+ return params.isDraggingStart ? moveStart(params, units) : moveEnd(params, units);
1111
+ }
1112
+ function moveStart({ annotationIndex, newTime, annotations, linkEndpoints }, { linkThreshold, minDuration }) {
1113
+ const updated = [...annotations];
1110
1114
  const annotation = annotations[annotationIndex];
1111
- if (isDraggingStart) {
1112
- const constrainedStart = Math.min(annotation.end - minDuration, Math.max(0, newTime));
1113
- updatedAnnotations[annotationIndex] = { ...annotation, start: constrainedStart };
1114
- if (linkEndpoints && annotationIndex > 0) {
1115
- const prevAnnotation = updatedAnnotations[annotationIndex - 1];
1116
- if (Math.abs(prevAnnotation.end - annotation.start) < linkThreshold) {
1117
- updatedAnnotations[annotationIndex - 1] = {
1118
- ...prevAnnotation,
1119
- end: Math.max(prevAnnotation.start + minDuration, constrainedStart)
1120
- };
1121
- } else if (constrainedStart <= prevAnnotation.end) {
1122
- updatedAnnotations[annotationIndex] = {
1123
- ...updatedAnnotations[annotationIndex],
1124
- start: prevAnnotation.end
1125
- };
1126
- }
1127
- } else if (!linkEndpoints && annotationIndex > 0 && constrainedStart < updatedAnnotations[annotationIndex - 1].end) {
1128
- updatedAnnotations[annotationIndex - 1] = {
1129
- ...updatedAnnotations[annotationIndex - 1],
1130
- end: constrainedStart
1131
- };
1132
- }
1115
+ const prev = annotationIndex > 0 ? annotations[annotationIndex - 1] : void 0;
1116
+ const start = Math.max(0, Math.min(annotation.end - minDuration, newTime));
1117
+ if (!prev) {
1118
+ updated[annotationIndex] = { ...annotation, start };
1119
+ } else if (linkEndpoints && Math.abs(prev.end - annotation.start) < linkThreshold) {
1120
+ const shared = Math.max(start, Math.min(prev.start + minDuration, prev.end));
1121
+ updated[annotationIndex - 1] = { ...prev, end: shared };
1122
+ updated[annotationIndex] = { ...annotation, start: shared };
1133
1123
  } else {
1134
- const constrainedEnd = Math.max(annotation.start + minDuration, Math.min(newTime, duration));
1135
- updatedAnnotations[annotationIndex] = { ...annotation, end: constrainedEnd };
1136
- if (linkEndpoints && annotationIndex < updatedAnnotations.length - 1) {
1137
- const nextAnnotation = updatedAnnotations[annotationIndex + 1];
1138
- if (Math.abs(nextAnnotation.start - annotation.end) < linkThreshold) {
1139
- updatedAnnotations[annotationIndex + 1] = {
1140
- ...nextAnnotation,
1141
- start: Math.min(nextAnnotation.end - minDuration, constrainedEnd)
1142
- };
1143
- let currentIndex = annotationIndex + 1;
1144
- while (currentIndex < updatedAnnotations.length - 1) {
1145
- const current = updatedAnnotations[currentIndex];
1146
- const next = updatedAnnotations[currentIndex + 1];
1147
- if (Math.abs(next.start - current.end) < linkThreshold) {
1148
- const nextDelta = current.end - annotations[currentIndex].end;
1149
- updatedAnnotations[currentIndex + 1] = {
1150
- ...next,
1151
- start: Math.min(next.end - minDuration, next.start + nextDelta)
1152
- };
1153
- currentIndex++;
1154
- } else {
1155
- break;
1156
- }
1157
- }
1158
- } else if (constrainedEnd >= nextAnnotation.start) {
1159
- updatedAnnotations[annotationIndex] = {
1160
- ...updatedAnnotations[annotationIndex],
1161
- end: nextAnnotation.start
1162
- };
1163
- }
1164
- } else if (!linkEndpoints && annotationIndex < updatedAnnotations.length - 1 && constrainedEnd > updatedAnnotations[annotationIndex + 1].start) {
1165
- const nextAnnotation = updatedAnnotations[annotationIndex + 1];
1166
- updatedAnnotations[annotationIndex + 1] = { ...nextAnnotation, start: constrainedEnd };
1167
- let currentIndex = annotationIndex + 1;
1168
- while (currentIndex < updatedAnnotations.length - 1) {
1169
- const current = updatedAnnotations[currentIndex];
1170
- const next = updatedAnnotations[currentIndex + 1];
1171
- if (current.end > next.start) {
1172
- updatedAnnotations[currentIndex + 1] = { ...next, start: current.end };
1173
- currentIndex++;
1174
- } else {
1175
- break;
1176
- }
1177
- }
1178
- }
1124
+ updated[annotationIndex] = { ...annotation, start: Math.max(start, prev.end) };
1125
+ }
1126
+ return updated;
1127
+ }
1128
+ function moveEnd({ annotationIndex, newTime, annotations, duration, linkEndpoints }, { linkThreshold, minDuration }) {
1129
+ const updated = [...annotations];
1130
+ const annotation = annotations[annotationIndex];
1131
+ const next = annotations[annotationIndex + 1];
1132
+ const end = Math.max(annotation.start + minDuration, Math.min(newTime, duration));
1133
+ if (!next) {
1134
+ updated[annotationIndex] = { ...annotation, end };
1135
+ } else if (linkEndpoints && Math.abs(next.start - annotation.end) < linkThreshold) {
1136
+ const shared = Math.min(end, Math.max(next.end - minDuration, next.start));
1137
+ updated[annotationIndex] = { ...annotation, end: shared };
1138
+ updated[annotationIndex + 1] = { ...next, start: shared };
1139
+ } else {
1140
+ updated[annotationIndex] = { ...annotation, end: Math.min(end, next.start) };
1179
1141
  }
1180
- return updatedAnnotations;
1142
+ return updated;
1181
1143
  }
1182
1144
 
1183
1145
  // src/annotations/shortcuts.ts