@waveform-playlist/core 13.0.0-next.0 → 13.0.0-next.2
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 +3 -0
- package/dist/index.d.mts +58 -3
- package/dist/index.d.ts +58 -3
- package/dist/index.js +97 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +95 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1203,6 +1203,99 @@ function resolveAnnotationShortcuts(remap) {
|
|
|
1203
1203
|
});
|
|
1204
1204
|
}
|
|
1205
1205
|
|
|
1206
|
+
// src/annotations/devFreeze.ts
|
|
1207
|
+
function isDevelopmentBuild() {
|
|
1208
|
+
try {
|
|
1209
|
+
return process.env.NODE_ENV !== "production";
|
|
1210
|
+
} catch {
|
|
1211
|
+
return false;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
function freezeAnnotations(list) {
|
|
1215
|
+
if (!isDevelopmentBuild()) return list;
|
|
1216
|
+
for (const annotation of list) {
|
|
1217
|
+
if (Array.isArray(annotation.lines)) Object.freeze(annotation.lines);
|
|
1218
|
+
Object.freeze(annotation);
|
|
1219
|
+
}
|
|
1220
|
+
return Object.freeze(list);
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
// src/annotations/store.ts
|
|
1224
|
+
function invalid(message) {
|
|
1225
|
+
return new TypeError("[waveform-playlist] Invalid annotations: " + message);
|
|
1226
|
+
}
|
|
1227
|
+
function validateAnnotations(list) {
|
|
1228
|
+
if (!Array.isArray(list)) throw invalid("expected an array.");
|
|
1229
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1230
|
+
for (const annotation of list) {
|
|
1231
|
+
const { id, start, end } = annotation ?? {};
|
|
1232
|
+
if (!Number.isFinite(start) || !Number.isFinite(end)) {
|
|
1233
|
+
throw invalid(
|
|
1234
|
+
`annotation "${String(id)}" needs numeric start and end (got ${typeof start} and ${typeof end}). Parse text formats first, e.g. parseAeneas() from @waveform-playlist/annotations.`
|
|
1235
|
+
);
|
|
1236
|
+
}
|
|
1237
|
+
if (seen.has(id)) throw invalid(`two annotations have the id "${id}".`);
|
|
1238
|
+
seen.add(id);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
function createAnnotationStore(initial = [], options = {}) {
|
|
1242
|
+
validateAnnotations(initial);
|
|
1243
|
+
let annotations = freezeAnnotations(initial);
|
|
1244
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1245
|
+
const { beforeChange } = options;
|
|
1246
|
+
const commit = (proposed) => {
|
|
1247
|
+
if (proposed === annotations) return;
|
|
1248
|
+
validateAnnotations(proposed);
|
|
1249
|
+
let next = proposed;
|
|
1250
|
+
if (beforeChange) {
|
|
1251
|
+
next = beforeChange(proposed, annotations);
|
|
1252
|
+
if (next === annotations) return;
|
|
1253
|
+
if (next !== proposed) validateAnnotations(next);
|
|
1254
|
+
}
|
|
1255
|
+
annotations = freezeAnnotations(next);
|
|
1256
|
+
for (const entry of [...listeners]) {
|
|
1257
|
+
if (!listeners.has(entry)) continue;
|
|
1258
|
+
try {
|
|
1259
|
+
entry.listener();
|
|
1260
|
+
} catch (error) {
|
|
1261
|
+
console.warn("[waveform-playlist] Error in an annotation store subscriber:", error);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
};
|
|
1265
|
+
return {
|
|
1266
|
+
getAnnotations: () => annotations,
|
|
1267
|
+
subscribe(listener) {
|
|
1268
|
+
const entry = { listener };
|
|
1269
|
+
listeners.add(entry);
|
|
1270
|
+
return () => {
|
|
1271
|
+
listeners.delete(entry);
|
|
1272
|
+
};
|
|
1273
|
+
},
|
|
1274
|
+
set(next) {
|
|
1275
|
+
commit(next);
|
|
1276
|
+
},
|
|
1277
|
+
update(fn) {
|
|
1278
|
+
commit(fn(annotations));
|
|
1279
|
+
}
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
// src/annotations/bounds.ts
|
|
1284
|
+
function applyAnnotationBounds(current, changes) {
|
|
1285
|
+
if (changes.length === 0) return current;
|
|
1286
|
+
const byId = new Map(changes.map((change) => [change.id, change]));
|
|
1287
|
+
let changed = false;
|
|
1288
|
+
const next = current.map((annotation) => {
|
|
1289
|
+
const change = byId.get(annotation.id);
|
|
1290
|
+
if (!change || change.start === annotation.start && change.end === annotation.end) {
|
|
1291
|
+
return annotation;
|
|
1292
|
+
}
|
|
1293
|
+
changed = true;
|
|
1294
|
+
return { ...annotation, start: change.start, end: change.end };
|
|
1295
|
+
});
|
|
1296
|
+
return changed ? next : current;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1206
1299
|
// src/panStage.ts
|
|
1207
1300
|
var PREFIX = "[waveform-playlist] ";
|
|
1208
1301
|
function panMatrix(pan, sourceChannelCount) {
|
|
@@ -1628,6 +1721,7 @@ export {
|
|
|
1628
1721
|
annotationMinDurationTicks,
|
|
1629
1722
|
appendPeaks,
|
|
1630
1723
|
appendToAudioBuffer,
|
|
1724
|
+
applyAnnotationBounds,
|
|
1631
1725
|
applyFadeIn,
|
|
1632
1726
|
applyFadeOut,
|
|
1633
1727
|
assertTrackKind,
|
|
@@ -1645,6 +1739,7 @@ export {
|
|
|
1645
1739
|
clipsOverlap,
|
|
1646
1740
|
computeMusicalTicks,
|
|
1647
1741
|
concatenateAudioData,
|
|
1742
|
+
createAnnotationStore,
|
|
1648
1743
|
createAudioBuffer,
|
|
1649
1744
|
createClip,
|
|
1650
1745
|
createClipFromSeconds,
|