@waveform-playlist/core 13.0.0-next.1 → 13.0.0-next.3

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
@@ -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) {
@@ -1511,6 +1604,66 @@ function audioTrack(options) {
1511
1604
  return track;
1512
1605
  }
1513
1606
 
1607
+ // src/mixerGesture.ts
1608
+ var RANGE_KEYS = /* @__PURE__ */ new Set([
1609
+ "ArrowUp",
1610
+ "ArrowDown",
1611
+ "ArrowLeft",
1612
+ "ArrowRight",
1613
+ "PageUp",
1614
+ "PageDown",
1615
+ "Home",
1616
+ "End"
1617
+ ]);
1618
+ var ID_PREFIX = Math.random().toString(36).slice(2, 10);
1619
+ var idCount = 0;
1620
+ function nextId() {
1621
+ idCount += 1;
1622
+ return `mg-${ID_PREFIX}-${idCount}`;
1623
+ }
1624
+ function createMixerGesture() {
1625
+ let id = nextId();
1626
+ const end = () => {
1627
+ id = nextId();
1628
+ };
1629
+ const attach = (input) => {
1630
+ let heldKey = null;
1631
+ const onKeyDown = (event) => {
1632
+ const { key } = event;
1633
+ if (RANGE_KEYS.has(key)) heldKey = key;
1634
+ };
1635
+ const onKeyUp = (event) => {
1636
+ if (event.key !== heldKey) return;
1637
+ heldKey = null;
1638
+ end();
1639
+ };
1640
+ const onChange = () => {
1641
+ if (heldKey === null) end();
1642
+ };
1643
+ const onBlur = () => {
1644
+ heldKey = null;
1645
+ end();
1646
+ };
1647
+ input.addEventListener("keydown", onKeyDown);
1648
+ input.addEventListener("keyup", onKeyUp);
1649
+ input.addEventListener("change", onChange);
1650
+ input.addEventListener("blur", onBlur);
1651
+ return () => {
1652
+ input.removeEventListener("keydown", onKeyDown);
1653
+ input.removeEventListener("keyup", onKeyUp);
1654
+ input.removeEventListener("change", onChange);
1655
+ input.removeEventListener("blur", onBlur);
1656
+ };
1657
+ };
1658
+ return {
1659
+ get id() {
1660
+ return id;
1661
+ },
1662
+ end,
1663
+ attach
1664
+ };
1665
+ }
1666
+
1514
1667
  // src/effects/registry.ts
1515
1668
  var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("@waveform-playlist/core/effect-registry/v1");
1516
1669
  function registryState() {
@@ -1628,6 +1781,7 @@ export {
1628
1781
  annotationMinDurationTicks,
1629
1782
  appendPeaks,
1630
1783
  appendToAudioBuffer,
1784
+ applyAnnotationBounds,
1631
1785
  applyFadeIn,
1632
1786
  applyFadeOut,
1633
1787
  assertTrackKind,
@@ -1645,11 +1799,13 @@ export {
1645
1799
  clipsOverlap,
1646
1800
  computeMusicalTicks,
1647
1801
  concatenateAudioData,
1802
+ createAnnotationStore,
1648
1803
  createAudioBuffer,
1649
1804
  createClip,
1650
1805
  createClipFromSeconds,
1651
1806
  createClipFromTicks,
1652
1807
  createEffectInstance,
1808
+ createMixerGesture,
1653
1809
  createPanStage,
1654
1810
  createSourceLoader,
1655
1811
  createTimeline,