@vidispine/vdt-js 23.4.0-pre.2 → 23.4.0-pre.4

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
@@ -1,12 +1,32 @@
1
- import { filesize as y } from "filesize";
2
- const ue = (e, t) => t ? ue(t, e % t) : e, H = (e) => {
3
- const { width: t, height: r } = e || {};
4
- if (t === void 0 || r === void 0)
1
+ import { filesize as w } from "filesize";
2
+ import $t from "url-join";
3
+ import Ut from "lodash.merge";
4
+ const pt = (e, t) => t ? pt(t, e % t) : e, J = (e) => {
5
+ const { width: t, height: s } = e || {};
6
+ if (t === void 0 || s === void 0)
5
7
  return;
6
- const n = ue(t, r);
7
- let o = t / n, s = r / n;
8
- return o > 21 && (s = 1, o = (t / r).toFixed(2)), [o, s].join(":");
9
- }, N = (e) => Object.fromEntries((e == null ? void 0 : e.map(({ key: t, value: r }) => [t, r])) || []), Ct = {
8
+ const n = pt(t, s);
9
+ let r = t / n, i = s / n;
10
+ return r > 21 && (i = 1, r = (t / s).toFixed(2)), [r, i].join(":");
11
+ }, F = (e) => Object.fromEntries((e == null ? void 0 : e.map(({ key: t, value: s }) => [t, s])) || []), Gt = (e, t, s) => {
12
+ let n;
13
+ return (r) => {
14
+ const o = () => {
15
+ n = null, s || e.apply(void 0, r);
16
+ }, a = s && !n;
17
+ clearTimeout(n), n = setTimeout(o, t), a && e.apply(void 0, r);
18
+ };
19
+ };
20
+ function zt() {
21
+ return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(
22
+ /[018]/g,
23
+ (e) => (
24
+ // eslint-disable-next-line
25
+ (e ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> e / 4).toString(16)
26
+ )
27
+ );
28
+ }
29
+ const os = {
10
30
  ACCESSCONTROL_READ: "_accesscontrol_read",
11
31
  ACCESSCONTROL_WRITE: "_accesscontrol_write",
12
32
  ADMINISTRATOR: "_administrator",
@@ -116,7 +136,7 @@ const ue = (e, t) => t ? ue(t, e % t) : e, H = (e) => {
116
136
  USER: "_user",
117
137
  VXA: "_vxa",
118
138
  VXA_READ: "_vxa_read"
119
- }, Lt = [
139
+ }, cs = [
120
140
  "stl_subtitle",
121
141
  "stl_tti",
122
142
  "stl_gsi",
@@ -128,7 +148,7 @@ const ue = (e, t) => t ? ue(t, e % t) : e, H = (e) => {
128
148
  "facedetect_face",
129
149
  "originalTrackFilename",
130
150
  "stl_gsiHeader"
131
- ], Bt = [
151
+ ], us = [
132
152
  "title",
133
153
  "user",
134
154
  "shapeTag",
@@ -267,291 +287,291 @@ const ue = (e, t) => t ? ue(t, e % t) : e, H = (e) => {
267
287
  "jc",
268
288
  "vp",
269
289
  "sn"
270
- ], Y = [
290
+ ], q = [
271
291
  "uuid",
272
292
  "user",
273
293
  "timestamp",
274
294
  "change",
275
295
  "conflict",
276
296
  "mode"
277
- ], le = [
297
+ ], _t = [
278
298
  "name",
279
299
  "id",
280
300
  "referenced",
281
301
  "data",
282
302
  "inheritance"
283
- ], we = [
284
- ...Y,
303
+ ], Vt = [
304
+ ...q,
285
305
  "value",
286
306
  "lang"
287
- ], Ce = [
288
- ...Y,
289
- ...le,
307
+ ], Ht = [
308
+ ...q,
309
+ ..._t,
290
310
  "value",
291
311
  "reference",
292
312
  "type",
293
313
  "track"
294
- ], Le = [
295
- ...Y,
296
- ...le,
314
+ ], Yt = [
315
+ ...q,
316
+ ..._t,
297
317
  "cycle",
298
318
  "field",
299
319
  "group"
300
- ], k = (e) => Object.prototype.toString.call(e) === "[object Object]" && e.value !== void 0, _e = (e) => ["string", "boolean", "number"].includes(typeof e), me = (e) => k(e) && ((e == null ? void 0 : e.value) === null || k(e.value) || _e(e.value)), Be = (e) => Object.prototype.toString.call(e) === "[object Object]", pe = (e) => Object.prototype.toString.call(e) === "[object Date]", fe = (e) => e === null ? !0 : Array.isArray(e) ? e.some(fe) : _e(e) || me(e) || pe(e), Te = (e) => {
301
- const t = (r) => Be(r) && r.value === void 0 && !!Object.entries(e);
302
- return Array.isArray(e) ? e.every(Te) : t(e);
303
- }, We = (e, t) => e + (t.length > 1 ? "s" : ""), Ee = (e, t) => {
304
- const r = e.filter((n) => !t.includes(n));
305
- if (r.length)
320
+ ], K = (e) => Object.prototype.toString.call(e) === "[object Object]" && e.value !== void 0, Tt = (e) => ["string", "boolean", "number"].includes(typeof e), gt = (e) => K(e) && ((e == null ? void 0 : e.value) === null || K(e.value) || Tt(e.value)), Kt = (e) => Object.prototype.toString.call(e) === "[object Object]", Et = (e) => Object.prototype.toString.call(e) === "[object Date]", At = (e) => e === null ? !0 : Array.isArray(e) ? e.some(At) : Tt(e) || gt(e) || Et(e), It = (e) => {
321
+ const t = (s) => Kt(s) && s.value === void 0 && !!Object.entries(e);
322
+ return Array.isArray(e) ? e.every(It) : t(e);
323
+ }, Jt = (e, t) => e + (t.length > 1 ? "s" : ""), Ot = (e, t) => {
324
+ const s = e.filter((n) => !t.includes(n));
325
+ if (s.length)
306
326
  throw Error(
307
- `Unsupported ${We("key", r)} (${r.join(", ")})`
327
+ `Unsupported ${Jt("key", s)} (${s.join(", ")})`
308
328
  );
309
- }, he = (e) => {
329
+ }, bt = (e) => {
310
330
  if (Array.isArray(e))
311
331
  throw Error("Invalid value inside value object, cannot be array");
312
- return [void 0, null].includes(e) ? {} : pe(e) ? { value: e.toISOString() } : { value: e.toString() };
313
- }, je = (e) => {
314
- if (Ee(Object.keys(e), we), Object.keys(e).length === 0)
332
+ return [void 0, null].includes(e) ? {} : Et(e) ? { value: e.toISOString() } : { value: e.toString() };
333
+ }, qt = (e) => {
334
+ if (Ot(Object.keys(e), Vt), Object.keys(e).length === 0)
315
335
  throw Error("Invalid value object, cannot be empty object");
316
336
  if (typeof (e == null ? void 0 : e.value) == "string")
317
337
  return e;
318
- const t = he(e == null ? void 0 : e.value);
338
+ const t = bt(e == null ? void 0 : e.value);
319
339
  return { ...e, ...t !== void 0 ? t : {} };
320
- }, K = (e) => {
340
+ }, X = (e) => {
321
341
  if (![void 0, null].includes(e))
322
- return Array.isArray(e) ? e.flatMap(K) : k(e) ? je(e) : he(e);
323
- }, xe = (e) => {
324
- Ee(Object.keys(e), Ce);
325
- const t = K(e == null ? void 0 : e.value);
342
+ return Array.isArray(e) ? e.flatMap(X) : K(e) ? qt(e) : bt(e);
343
+ }, Xt = (e) => {
344
+ Ot(Object.keys(e), Ht);
345
+ const t = X(e == null ? void 0 : e.value);
326
346
  if (t === void 0) {
327
- const { value: r, ...n } = e;
347
+ const { value: s, ...n } = e;
328
348
  return n;
329
349
  }
330
350
  return {
331
351
  ...e,
332
352
  value: [...Array.isArray(t) ? t : [t]]
333
353
  };
334
- }, Pe = (e) => {
335
- if (me(e))
336
- return xe(e);
337
- const t = K(e);
354
+ }, Qt = (e) => {
355
+ if (gt(e))
356
+ return Xt(e);
357
+ const t = X(e);
338
358
  if (t !== void 0)
339
359
  return { value: [...Array.isArray(t) ? t : [t]] };
340
- }, Ae = (e) => {
341
- const t = [], r = [];
360
+ }, Rt = (e) => {
361
+ const t = [], s = [];
342
362
  let n = {};
343
- return Object.entries(e || {}).forEach(([o, s]) => {
344
- if (Le.includes(o))
345
- n = { ...n, [o]: s };
346
- else if (fe(s))
363
+ return Object.entries(e || {}).forEach(([r, i]) => {
364
+ if (Yt.includes(r))
365
+ n = { ...n, [r]: i };
366
+ else if (At(i))
347
367
  try {
348
- r.push({ name: o, ...Pe(s) });
349
- } catch (a) {
350
- throw Error(a.message + (o ? ` for field "${o}"` : ""));
368
+ s.push({ name: r, ...Qt(i) });
369
+ } catch (o) {
370
+ throw Error(o.message + (r ? ` for field "${r}"` : ""));
351
371
  }
352
- else if (Te(s))
353
- (Array.isArray(s) ? s : [s]).forEach((a) => {
354
- t.push({ name: o, ...Ae(a) });
372
+ else if (It(i))
373
+ (Array.isArray(i) ? i : [i]).forEach((o) => {
374
+ t.push({ name: r, ...Rt(o) });
355
375
  });
356
376
  else
357
- throw Error(`Unhandled value for "${o}"`);
377
+ throw Error(`Unhandled value for "${r}"`);
358
378
  }), {
359
379
  ...n,
360
380
  ...t.length > 0 ? { group: t } : {},
361
- ...r.length > 0 ? { field: r } : {}
381
+ ...s.length > 0 ? { field: s } : {}
362
382
  };
363
- }, Ue = (e) => {
364
- const { start: t = "-INF", end: r = "+INF", base: n = void 0, ...o } = e, { group: s, field: a } = Ae(o);
383
+ }, Zt = (e) => {
384
+ const { start: t = "-INF", end: s = "+INF", base: n = void 0, ...r } = e, { group: i, field: o } = Rt(r);
365
385
  return {
366
- ...s ? { group: s } : {},
367
- ...a ? { field: a } : {},
386
+ ...i ? { group: i } : {},
387
+ ...o ? { field: o } : {},
368
388
  start: t.toString(),
369
- end: r.toString(),
389
+ end: s.toString(),
370
390
  ...n ? { base: n } : {}
371
391
  };
372
- }, Wt = (e) => ({
373
- timespan: (Array.isArray(e) ? e : [e || {}]).map((t) => Ue(t))
374
- }), Ge = (e, t) => {
375
- var o, s;
376
- const [r] = ((o = e == null ? void 0 : e.start) == null ? void 0 : o.split("@")) || [], [n] = ((s = t == null ? void 0 : t.start) == null ? void 0 : s.split("@")) || [];
377
- return Number(r) < Number(n) ? -1 : Number(r) > Number(n) ? 1 : 0;
378
- }, b = (e) => Array.isArray(e) ? e : e && [e] || [], re = (e) => Array.isArray(e) ? e.pop() : e, $e = (e) => (e == null ? void 0 : e.every((t) => typeof t == "string")) || !1, Oe = {
392
+ }, ls = (e) => ({
393
+ timespan: (Array.isArray(e) ? e : [e || {}]).map((t) => Zt(t))
394
+ }), te = (e, t) => {
395
+ var r, i;
396
+ const [s] = ((r = e == null ? void 0 : e.start) == null ? void 0 : r.split("@")) || [], [n] = ((i = t == null ? void 0 : t.start) == null ? void 0 : i.split("@")) || [];
397
+ return Number(s) < Number(n) ? -1 : Number(s) > Number(n) ? 1 : 0;
398
+ }, D = (e) => Array.isArray(e) ? e : e && [e] || [], at = (e) => Array.isArray(e) ? e.pop() : e, ee = (e) => (e == null ? void 0 : e.every((t) => typeof t == "string")) || !1, yt = {
379
399
  includeValueAttributes: !1
380
400
  };
381
- function Ve(e, t) {
382
- const { includeValueAttributes: r } = {
383
- ...Oe,
401
+ function se(e, t) {
402
+ const { includeValueAttributes: s } = {
403
+ ...yt,
384
404
  ...t || {}
385
405
  };
386
- if (r === !1)
406
+ if (s === !1)
387
407
  return e == null ? void 0 : e.value;
388
- const { value: n, ...o } = e;
389
- return { ...r === !0 && o || Array.isArray(r) && Object.fromEntries(
390
- Object.entries(o).filter(
391
- ([a]) => r.includes(a)
408
+ const { value: n, ...r } = e;
409
+ return { ...s === !0 && r || Array.isArray(s) && Object.fromEntries(
410
+ Object.entries(r).filter(
411
+ ([o]) => s.includes(o)
392
412
  )
393
413
  ) || {}, value: n };
394
414
  }
395
- const Ie = {
396
- ...Oe,
415
+ const St = {
416
+ ...yt,
397
417
  joinValue: void 0,
398
418
  arrayOnSingleValue: !0
399
419
  };
400
- function ke(e, t) {
401
- const { joinValue: r, arrayOnSingleValue: n, ...o } = {
402
- ...Ie,
420
+ function re(e, t) {
421
+ const { joinValue: s, arrayOnSingleValue: n, ...r } = {
422
+ ...St,
403
423
  ...t || {}
404
- }, s = e == null ? void 0 : e.map((a) => Ve(a, o));
405
- return $e(s) && r ? s == null ? void 0 : s.join(r) : n !== !0 && (s == null ? void 0 : s.length) <= 1 ? s == null ? void 0 : s[0] : s;
424
+ }, i = e == null ? void 0 : e.map((o) => se(o, r));
425
+ return ee(i) && s ? i == null ? void 0 : i.join(s) : n !== !0 && (i == null ? void 0 : i.length) <= 1 ? i == null ? void 0 : i[0] : i;
406
426
  }
407
- const Re = {
427
+ const vt = {
408
428
  includeFieldAttributes: !1,
409
- ...Ie
410
- }, He = (e, t) => {
411
- const { includeFieldAttributes: r, ...n } = {
412
- ...Re,
429
+ ...St
430
+ }, ne = (e, t) => {
431
+ const { includeFieldAttributes: s, ...n } = {
432
+ ...vt,
413
433
  ...t || {}
414
- }, { value: o, ...s } = e, a = ke(o, n), i = r === !0 && s || Array.isArray(r) && Object.fromEntries(
415
- Object.entries(s).filter(
416
- ([c]) => r.includes(c)
434
+ }, { value: r, ...i } = e, o = re(r, n), a = s === !0 && i || Array.isArray(s) && Object.fromEntries(
435
+ Object.entries(i).filter(
436
+ ([c]) => s.includes(c)
417
437
  )
418
438
  ) || {};
419
- return r ? { ...i, value: a } : a;
420
- }, j = {
421
- ...Re,
439
+ return s ? { ...a, value: o } : o;
440
+ }, G = {
441
+ ...vt,
422
442
  fieldAsList: !1,
423
443
  arrayOnSingleField: !1,
424
444
  overrideField: void 0
425
- }, Se = (e, t) => {
426
- const r = {
427
- ...j,
445
+ }, Mt = (e, t) => {
446
+ const s = {
447
+ ...G,
428
448
  ...t || {}
429
- }, { fieldAsList: n, arrayOnSingleField: o, overrideField: s } = r, a = s === !0 && n === !1, i = {};
449
+ }, { fieldAsList: n, arrayOnSingleField: r, overrideField: i } = s, o = i === !0 && n === !1, a = {};
430
450
  return e == null || e.forEach((c) => {
431
- const { name: l } = c, d = He(c, r), _ = o === !0 ? b(d) : d, p = i[l];
432
- p ? a ? i[l] = d : i[l] = [b(p), b(d)].flat() : i[l] = _;
433
- }), n === !0 ? Object.values(i).flat() : i;
434
- }, ge = {
435
- ...j,
451
+ const { name: d } = c, u = ne(c, s), f = r === !0 ? D(u) : u, m = a[d];
452
+ m ? o ? a[d] = u : a[d] = [D(m), D(u)].flat() : a[d] = f;
453
+ }), n === !0 ? Object.values(a).flat() : a;
454
+ }, Dt = {
455
+ ...G,
436
456
  includeGroupAttributes: !1,
437
457
  groupAsList: !1,
438
458
  arrayOnSingleGroup: !1,
439
459
  overrideGroup: void 0
440
- }, Ye = (e, t) => {
441
- const r = {
442
- ...ge,
460
+ }, ie = (e, t) => {
461
+ const s = {
462
+ ...Dt,
443
463
  ...t || {}
444
- }, { includeGroupAttributes: n } = r, o = Object.fromEntries(
445
- Object.entries(r).filter(
446
- ([_]) => Object.keys(j).includes(_)
464
+ }, { includeGroupAttributes: n } = s, r = Object.fromEntries(
465
+ Object.entries(s).filter(
466
+ ([f]) => Object.keys(G).includes(f)
447
467
  )
448
- ), { field: s, group: a, ...i } = e, c = s && Se(s, o), l = a && be(a, r);
468
+ ), { field: i, group: o, ...a } = e, c = i && Mt(i, r), d = o && Ft(o, s);
449
469
  return {
450
- ...n === !0 && i || Array.isArray(n) && Object.fromEntries(
451
- Object.entries(i).filter(
452
- ([_]) => n.includes(_)
470
+ ...n === !0 && a || Array.isArray(n) && Object.fromEntries(
471
+ Object.entries(a).filter(
472
+ ([f]) => n.includes(f)
453
473
  )
454
474
  ) || {},
455
- ...o != null && o.fieldAsList ? c && { field: c } || {} : c,
456
- ...r != null && r.groupAsList ? l && { group: l } || {} : l
475
+ ...r != null && r.fieldAsList ? c && { field: c } || {} : c,
476
+ ...s != null && s.groupAsList ? d && { group: d } || {} : d
457
477
  };
458
- }, z = ge, be = (e, t) => {
459
- const r = { ...z, ...t || {} }, { groupAsList: n, arrayOnSingleGroup: o, overrideGroup: s } = r, a = s === !0 && n === !1, i = {};
478
+ }, Q = Dt, Ft = (e, t) => {
479
+ const s = { ...Q, ...t || {} }, { groupAsList: n, arrayOnSingleGroup: r, overrideGroup: i } = s, o = i === !0 && n === !1, a = {};
460
480
  return e == null || e.forEach((c) => {
461
- const { name: l } = c, d = Ye(c, r), _ = o === !0 ? b(d) : d, p = i[l];
462
- p ? a ? i[l] = d : i[l] = [
463
- b(p),
464
- b(d)
465
- ].flat() : i[l] = _;
466
- }), n ? Object.values(i).flat() : i;
467
- }, Ne = {
468
- ...z,
481
+ const { name: d } = c, u = ie(c, s), f = r === !0 ? D(u) : u, m = a[d];
482
+ m ? o ? a[d] = u : a[d] = [
483
+ D(m),
484
+ D(u)
485
+ ].flat() : a[d] = f;
486
+ }), n ? Object.values(a).flat() : a;
487
+ }, Nt = {
488
+ ...Q,
469
489
  includeTimespanAttributes: !1,
470
490
  flat: !1,
471
491
  arrayOnSingle: !1,
472
492
  arrayOnSingleValue: !0,
473
493
  arrayOnSingleGroup: void 0,
474
494
  arrayOnSingleField: void 0
475
- }, Ke = (e, t) => {
476
- const r = {
477
- ...Ne,
495
+ }, ae = (e, t) => {
496
+ const s = {
497
+ ...Nt,
478
498
  ...t || {}
479
- }, { includeTimespanAttributes: n, arrayOnSingle: o, flat: s } = r, a = Object.fromEntries(
480
- Object.entries(t).map(([u, m]) => {
481
- if (Object.keys(z).includes(u))
482
- return ["arrayOnSingleGroup", "arrayOnSingleField", "arrayOnSingleValue"].includes(u) && (m !== void 0 ? m : o === !0) ? [u, !0] : ["overrideGroup", "overrideField"].includes(u) && (m !== void 0 ? m : s === !0) ? [u, !0] : [u, m];
483
- }).filter((u) => !!u)
484
- ), i = Object.fromEntries(
485
- Object.entries(t).map(([u, m]) => {
486
- if (Object.keys(j).includes(u))
487
- return ["arrayOnSingleField", "arrayOnSingleValue"].includes(u) && (m !== void 0 ? m : o === !0) ? [u, !0] : ["overrideField"].includes(u) && (m !== void 0 ? m : s === !0) ? [u, !0] : [u, m];
488
- }).filter((u) => !!u)
489
- ), { field: c, group: l, ...d } = e || {}, _ = c && Se(c, i), p = l && be(l, a);
499
+ }, { includeTimespanAttributes: n, arrayOnSingle: r, flat: i } = s, o = Object.fromEntries(
500
+ Object.entries(t).map(([l, h]) => {
501
+ if (Object.keys(Q).includes(l))
502
+ return ["arrayOnSingleGroup", "arrayOnSingleField", "arrayOnSingleValue"].includes(l) && (h !== void 0 ? h : r === !0) ? [l, !0] : ["overrideGroup", "overrideField"].includes(l) && (h !== void 0 ? h : i === !0) ? [l, !0] : [l, h];
503
+ }).filter((l) => !!l)
504
+ ), a = Object.fromEntries(
505
+ Object.entries(t).map(([l, h]) => {
506
+ if (Object.keys(G).includes(l))
507
+ return ["arrayOnSingleField", "arrayOnSingleValue"].includes(l) && (h !== void 0 ? h : r === !0) ? [l, !0] : ["overrideField"].includes(l) && (h !== void 0 ? h : i === !0) ? [l, !0] : [l, h];
508
+ }).filter((l) => !!l)
509
+ ), { field: c, group: d, ...u } = e || {}, f = c && Mt(c, a), m = d && Ft(d, o);
490
510
  return {
491
- ...n === !0 && d || Array.isArray(n) && Object.fromEntries(
492
- Object.entries(d).filter(
493
- ([u]) => n.includes(u)
511
+ ...n === !0 && u || Array.isArray(n) && Object.fromEntries(
512
+ Object.entries(u).filter(
513
+ ([l]) => n.includes(l)
494
514
  )
495
515
  ) || {},
496
- ...i != null && i.fieldAsList ? { field: _ } : _,
497
- ...a != null && a.groupAsList ? { group: p } : p
516
+ ...a != null && a.fieldAsList ? { field: f } : f,
517
+ ...o != null && o.groupAsList ? { group: m } : m
498
518
  };
499
- }, J = {
500
- ...Ne,
519
+ }, Z = {
520
+ ...Nt,
501
521
  timespanAsList: !1,
502
522
  joinTimespan: "_",
503
523
  sortTimespan: !1,
504
524
  flat: !1,
505
525
  flatTimespan: void 0
506
- }, ye = (e, t) => {
507
- const r = {
508
- ...J,
526
+ }, Ct = (e, t) => {
527
+ const s = {
528
+ ...Z,
509
529
  ...t || {}
510
- }, { timespanAsList: n, joinTimespan: o, sortTimespan: s, flat: a, flatTimespan: i, ...c } = r, l = { flat: a, ...c };
511
- s && e.sort(Ge);
512
- const d = (i !== void 0 ? i === !0 : a === !0) && n === !1, _ = {};
513
- return e == null || e.forEach((p) => {
514
- const { start: f, end: u } = p, m = d ? "flat" : [f, u].join(o), T = Ke(p, l), E = _[m];
515
- E ? d ? f === "-INF" && u === "+INF" ? _[m] = { ...re(E), ...T } : _[m] = { ...T, ...re(E) } : _[m] = [...b(E), T] : _[m] = T;
516
- }), n === !0 ? Object.values(_) : d ? Object.values(_).pop() : _;
517
- }, ze = {
518
- ...J,
530
+ }, { timespanAsList: n, joinTimespan: r, sortTimespan: i, flat: o, flatTimespan: a, ...c } = s, d = { flat: o, ...c };
531
+ i && e.sort(te);
532
+ const u = (a !== void 0 ? a === !0 : o === !0) && n === !1, f = {};
533
+ return e == null || e.forEach((m) => {
534
+ const { start: p, end: l } = m, h = u ? "flat" : [p, l].join(r), g = ae(m, d), E = f[h];
535
+ E ? u ? p === "-INF" && l === "+INF" ? f[h] = { ...at(E), ...g } : f[h] = { ...g, ...at(E) } : f[h] = [...D(E), g] : f[h] = g;
536
+ }), n === !0 ? Object.values(f) : u ? Object.values(f).pop() : f;
537
+ }, oe = {
538
+ ...Z,
519
539
  includeMetadataAttributes: !1,
520
540
  flat: !1
521
541
  };
522
- function jt(e, t) {
523
- const r = {
524
- ...ze,
542
+ function ce(e, t) {
543
+ const s = {
544
+ ...oe,
525
545
  ...t || {}
526
- }, { includeMetadataAttributes: n, flat: o } = r, { timespan: s = [], ...a } = e || {}, i = Object.fromEntries(
527
- Object.entries(t).map(([d, _]) => {
528
- if (Object.keys(J).includes(d))
529
- return ["onlyGeneric", "overrideGroup", "overrideField"].includes(d) && (_ !== void 0 ? _ : o === !0) ? [d, !0] : [d, _];
530
- }).filter((d) => !!d)
531
- ), c = ye(
532
- s,
533
- i
546
+ }, { includeMetadataAttributes: n, flat: r } = s, { timespan: i = [], ...o } = e || {}, a = Object.fromEntries(
547
+ Object.entries(t).map(([u, f]) => {
548
+ if (Object.keys(Z).includes(u))
549
+ return ["onlyGeneric", "overrideGroup", "overrideField"].includes(u) && (f !== void 0 ? f : r === !0) ? [u, !0] : [u, f];
550
+ }).filter((u) => !!u)
551
+ ), c = Ct(
552
+ i,
553
+ a
534
554
  );
535
555
  return {
536
556
  ...n === !0 && {
537
- ...a,
538
- ...a.revision ? { revision: a.revision.split(",") } : {}
557
+ ...o,
558
+ ...o.revision ? { revision: o.revision.split(",") } : {}
539
559
  } || Array.isArray(n) && Object.fromEntries(
540
- Object.entries(a).map(([d, _]) => {
541
- if (n.includes(d))
560
+ Object.entries(o).map(([u, f]) => {
561
+ if (n.includes(u))
542
562
  return [
543
- d,
544
- d === "revision" && typeof _ == "string" ? _.split(",") : _
563
+ u,
564
+ u === "revision" && typeof f == "string" ? f.split(",") : f
545
565
  ];
546
- }).filter((d) => !!d)
566
+ }).filter((u) => !!u)
547
567
  ) || {},
548
- ...i != null && i.timespanAsList ? { timespan: c } : c
568
+ ...a != null && a.timespanAsList ? { timespan: c } : c
549
569
  };
550
570
  }
551
- const xt = (e) => {
571
+ const ds = (e) => {
552
572
  const { field: t = [] } = e || {};
553
- return N(t);
554
- }, X = {
573
+ return F(t);
574
+ }, tt = {
555
575
  PAL: { denominator: 25, numerator: 1 },
556
576
  NTSC: { denominator: 3e4, numerator: 1001 },
557
577
  NTSC30: { denominator: 30, numerator: 1 },
@@ -559,7 +579,7 @@ const xt = (e) => {
559
579
  59.94: { denominator: 6e4, numerator: 1001 },
560
580
  23.976: { denominator: 48e3, numerator: 2002 },
561
581
  23.98: { denominator: 48e3, numerator: 2002 }
562
- }, oe = Object.keys(X), ne = {
582
+ }, ot = Object.keys(tt), ct = {
563
583
  toText: {
564
584
  constant: !1,
565
585
  fraction: !1
@@ -569,7 +589,7 @@ const xt = (e) => {
569
589
  rounded: !1
570
590
  }
571
591
  };
572
- class I {
592
+ class R {
573
593
  /**
574
594
  * Constructor for TimeBase
575
595
  *
@@ -577,8 +597,8 @@ class I {
577
597
  */
578
598
  constructor(t) {
579
599
  this.numerator = 1, this.denominator = 1;
580
- const { numerator: r = 1, denominator: n = 1 } = t || {};
581
- this.numerator = Number(r), this.denominator = Number(n);
600
+ const { numerator: s = 1, denominator: n = 1 } = t || {};
601
+ this.numerator = Number(s), this.denominator = Number(n);
582
602
  }
583
603
  /**
584
604
  * Get TimeBase in a constant representation (e.g. "PAL") if possible, otherwise undefined
@@ -586,9 +606,9 @@ class I {
586
606
  */
587
607
  toConstant() {
588
608
  let t;
589
- return Object.entries(X).find((r) => {
590
- const [n, o] = r, { numerator: s, denominator: a } = o;
591
- return s === this.numerator && a === this.denominator ? (t = n, !0) : !1;
609
+ return Object.entries(tt).find((s) => {
610
+ const [n, r] = s, { numerator: i, denominator: o } = r;
611
+ return i === this.numerator && o === this.denominator ? (t = n, !0) : !1;
592
612
  }), t;
593
613
  }
594
614
  /**
@@ -603,11 +623,11 @@ class I {
603
623
  * @returns Text representation of the TimeBase
604
624
  */
605
625
  toText(t) {
606
- const { constant: r, fraction: n } = { ...ne.toText, ...t };
607
- if (r) {
608
- const s = this.toConstant();
609
- if (s)
610
- return s;
626
+ const { constant: s, fraction: n } = { ...ct.toText, ...t };
627
+ if (s) {
628
+ const i = this.toConstant();
629
+ if (i)
630
+ return i;
611
631
  }
612
632
  return n || this.numerator > 1 ? [this.denominator, this.numerator].join(":") : String(this.denominator);
613
633
  }
@@ -624,11 +644,11 @@ class I {
624
644
  * @return Rate of the TimeBase
625
645
  */
626
646
  toRate(t) {
627
- const r = this.denominator / this.numerator;
628
- if (Number.isInteger(r))
629
- return r;
630
- const { rounded: n, fixed: o } = { ...ne.toRate, ...t || {} };
631
- return n ? Math.round(r) : o === !0 || typeof o == "number" ? Number(r.toFixed(typeof o == "boolean" ? 2 : o)) : r;
647
+ const s = this.denominator / this.numerator;
648
+ if (Number.isInteger(s))
649
+ return s;
650
+ const { rounded: n, fixed: r } = { ...ct.toRate, ...t || {} };
651
+ return n ? Math.round(s) : r === !0 || typeof r == "number" ? Number(s.toFixed(typeof r == "boolean" ? 2 : r)) : s;
632
652
  }
633
653
  /**
634
654
  * Get TimeBase in a object representation
@@ -650,39 +670,39 @@ class I {
650
670
  return console.warn("Deprecated - use toObject instead"), this.toObject();
651
671
  }
652
672
  }
653
- const q = (e) => {
673
+ const et = (e) => {
654
674
  if (e === void 0)
655
- return new I();
675
+ return new R();
656
676
  if (typeof e == "number")
657
- return new I({ denominator: e });
677
+ return new R({ denominator: e });
658
678
  if (typeof e == "string" && e.includes(":")) {
659
- const [t, r] = e.split(":");
660
- return new I({ denominator: t, numerator: r });
679
+ const [t, s] = e.split(":");
680
+ return new R({ denominator: t, numerator: s });
661
681
  }
662
- if (oe.includes(e))
663
- return new I(X[e]);
682
+ if (ot.includes(e))
683
+ return new R(tt[e]);
664
684
  if (!["string", "number"].includes(typeof e) || Number.isNaN(Number(e)))
665
685
  throw new Error(
666
- `timeBaseText must be a number or ${oe.join(",")} - is ${JSON.stringify(
686
+ `timeBaseText must be a number or ${ot.join(",")} - is ${JSON.stringify(
667
687
  e
668
688
  )}`
669
689
  );
670
- return new I({ denominator: Number(e) });
671
- }, M = (e) => new I(e), v = (e) => e instanceof I ? e : typeof e == "string" || typeof e == "number" ? q(e) : M(e), Q = (e) => {
690
+ return new R({ denominator: Number(e) });
691
+ }, L = (e) => new R(e), $ = (e) => e instanceof R ? e : typeof e == "string" || typeof e == "number" ? et(e) : L(e), st = (e) => {
672
692
  const t = e.toConstant();
673
693
  return t === "59.94" && 4 || ["NTSC", "29.97"].includes(t) && 2 || void 0;
674
- }, Fe = (e) => Q(e) > 0, se = (e) => {
675
- const { samples: t, timeBase: r } = e, n = Q(r);
694
+ }, wt = (e) => st(e) > 0, ut = (e) => {
695
+ const { samples: t, timeBase: s } = e, n = st(s);
676
696
  if (!n)
677
697
  return 0;
678
- const o = r.toRate({ rounded: !0 }), s = 60 * o, a = 60 * o - n, i = 10 * (s - n) + n, c = Math.floor((t + 1) / i), l = Math.max(
698
+ const r = s.toRate({ rounded: !0 }), i = 60 * r, o = 60 * r - n, a = 10 * (i - n) + n, c = Math.floor((t + 1) / a), d = Math.max(
679
699
  0,
680
- (t + 1) % i - s
681
- ), d = Math.floor(
682
- l / a
683
- ), p = l % a > 0 ? n : 0;
684
- return c * 9 * n + d * n + p;
685
- }, G = {
700
+ (t + 1) % a - i
701
+ ), u = Math.floor(
702
+ d / o
703
+ ), m = d % o > 0 ? n : 0;
704
+ return c * 9 * n + u * n + m;
705
+ }, V = {
686
706
  conformTimeBase: {
687
707
  dropFrame: void 0,
688
708
  frameSeparator: void 0
@@ -696,16 +716,16 @@ const q = (e) => {
696
716
  format: void 0
697
717
  }
698
718
  };
699
- class g {
719
+ class S {
700
720
  /**
701
721
  * Constructor for TimeCode
702
722
  *
703
723
  * @param timeCodeType Object to create TimeCode of
704
724
  * @param options Options for the timeCode
705
725
  */
706
- constructor(t, r) {
707
- this.samples = 0, this.timeBase = new I();
708
- const { samples: n, timeBase: o } = t || {};
726
+ constructor(t, s) {
727
+ this.samples = 0, this.timeBase = new R();
728
+ const { samples: n, timeBase: r } = t || {};
709
729
  if (n !== void 0)
710
730
  if (typeof n == "number")
711
731
  this.samples = n;
@@ -713,7 +733,7 @@ class g {
713
733
  n === "-INF" ? this.samples = -1 / 0 : n === "+INF" ? this.samples = 1 / 0 : this.samples = Number(n);
714
734
  else
715
735
  throw new Error(`samples is not number/string/-Inf/+Inf is: ${n}`);
716
- o !== void 0 && (o instanceof I ? this.timeBase = o : this.timeBase = v(o)), this.dropFrame = (r == null ? void 0 : r.dropFrame) ?? Fe(this.timeBase), this.frameSeparator = (r == null ? void 0 : r.frameSeparator) ?? (this.dropFrame ? ";" : ":");
736
+ r !== void 0 && (r instanceof R ? this.timeBase = r : this.timeBase = $(r)), this.dropFrame = (s == null ? void 0 : s.dropFrame) ?? wt(this.timeBase), this.frameSeparator = (s == null ? void 0 : s.frameSeparator) ?? (this.dropFrame ? ";" : ":");
717
737
  }
718
738
  /**
719
739
  * Return this TimeCode added with the supplied timeCodeType
@@ -733,11 +753,11 @@ class g {
733
753
  add(t) {
734
754
  if (!(t != null && t.timeBase) || (t == null ? void 0 : t.samples) === void 0)
735
755
  throw Error("Invalid timeCodeType, cannot be added");
736
- const { numerator: r, denominator: n } = (t == null ? void 0 : t.timeBase) || {};
737
- let o = t;
738
- (r !== this.timeBase.numerator || n !== this.timeBase.denominator) && (o = t.conformTimeBase(this.timeBase));
739
- const { samples: s } = o;
740
- return new g({ samples: this.samples + s, timeBase: this.timeBase });
756
+ const { numerator: s, denominator: n } = (t == null ? void 0 : t.timeBase) || {};
757
+ let r = t;
758
+ (s !== this.timeBase.numerator || n !== this.timeBase.denominator) && (r = t.conformTimeBase(this.timeBase));
759
+ const { samples: i } = r;
760
+ return new S({ samples: this.samples + i, timeBase: this.timeBase });
741
761
  }
742
762
  /**
743
763
  * Return this TimeCode subtracted with the supplied timeCodeType
@@ -757,33 +777,43 @@ class g {
757
777
  subtract(t) {
758
778
  if (!(t != null && t.timeBase) || (t == null ? void 0 : t.samples) === void 0)
759
779
  throw Error("Invalid timeCodeType, cannot be subtracted");
760
- const { timeBase: { numerator: r, denominator: n } = {} } = t;
761
- let o = t;
762
- (r !== this.timeBase.numerator || n !== this.timeBase.denominator) && (o = t.conformTimeBase(this.timeBase));
763
- const { samples: s } = o;
764
- return new g({ samples: this.samples - s, timeBase: this.timeBase });
780
+ const { timeBase: { numerator: s, denominator: n } = {} } = t;
781
+ let r = t;
782
+ (s !== this.timeBase.numerator || n !== this.timeBase.denominator) && (r = t.conformTimeBase(this.timeBase));
783
+ const { samples: i } = r;
784
+ return new S({ samples: this.samples - i, timeBase: this.timeBase });
765
785
  }
766
786
  /**
767
787
  * Creates a new TimeCode instance with specified timeBase and samples adjusted to that.
768
788
  *
769
789
  * @remarks
770
- * If it conforms to a less granular time base - it will floor samples (hasn't reached that sample yet)
790
+ * It floors samples when conforming to a less granular time base (can be changed with `options.mode`)
791
+ *
771
792
  * - e.g. "51@50".conformTo("PAL") => "25@PAL" (not "26@PAL")
772
793
  *
773
794
  * @param timeBase The TimeBase it should conform the TimeCode to
774
- * @param options Explicitly set TimeCode options, by default these are derived from `timeBase`
795
+ * @param options Explicitly set conform options, by default these are derived from `timeBase`
775
796
  * @returns A new TimeCode instance with the conformTo timeBase applied
776
797
  */
777
- conformTimeBase(t, r) {
778
- const n = t instanceof I ? t : v(t), o = Math.floor(
798
+ conformTimeBase(t, s) {
799
+ const n = t instanceof R ? t : $(t), r = (s == null ? void 0 : s.roundingMode) ?? "floor";
800
+ if (!["floor", "ceil", "round"].includes(r))
801
+ throw Error(
802
+ `Invalid mode selection "${r}". Has to be one of "${[
803
+ "floor",
804
+ "ceil",
805
+ "round"
806
+ ].join(", ")}"`
807
+ );
808
+ const i = Math[r](
779
809
  this.samples / (this.timeBase.toRate({ fixed: !1 }) / n.toRate({ fixed: !1 }))
780
- ), s = { ...G.conformTimeBase, ...r || {} };
781
- return new g(
810
+ ), o = { ...V.conformTimeBase, ...s || {} };
811
+ return new S(
782
812
  {
783
- samples: o,
813
+ samples: i,
784
814
  timeBase: n
785
815
  },
786
- s
816
+ o
787
817
  );
788
818
  }
789
819
  /**
@@ -798,9 +828,9 @@ class g {
798
828
  * @returns Text representation of TimeCode
799
829
  */
800
830
  toText(t) {
801
- let r = `${this.samples}`;
802
- const n = { ...G.toText, ...t || {} }, o = this.timeBase.toText(n);
803
- return (t != null && t.includeTimeBaseForSeconds || !["1", "1:1"].includes(o)) && (r = [this.samples, o].join("@")), r;
831
+ let s = `${this.samples}`;
832
+ const n = { ...V.toText, ...t || {} }, r = this.timeBase.toText(n);
833
+ return (t != null && t.includeTimeBaseForSeconds || !["1", "1:1"].includes(r)) && (s = [this.samples, r].join("@")), s;
804
834
  }
805
835
  /**
806
836
  * Get TimeCode in a units object representation
@@ -818,15 +848,15 @@ class g {
818
848
  seconds: 1 / 0,
819
849
  frames: 1 / 0
820
850
  };
821
- const t = this.samples + (this.dropFrame ? se(this) : 0);
822
- let r = this.timeBase.toRate({ rounded: !0 });
823
- ["23.976", "23.98"].includes(this.timeBase.toConstant()) && (r = this.timeBase.toRate({ fixed: !0 }));
824
- const n = Math.floor(t / (3600 * r)), o = Math.floor(t / (60 * r)) % 60, s = Math.floor(t / r) % 60, a = Math.floor(t % r);
851
+ const t = this.samples + (this.dropFrame ? ut(this) : 0);
852
+ let s = this.timeBase.toRate({ rounded: !0 });
853
+ ["23.976", "23.98"].includes(this.timeBase.toConstant()) && (s = this.timeBase.toRate({ fixed: !0 }));
854
+ const n = Math.floor(t / (3600 * s)), r = Math.floor(t / (60 * s)) % 60, i = Math.floor(t / s) % 60, o = Math.floor(t % s);
825
855
  return {
826
856
  hours: n,
827
- minutes: o,
828
- seconds: s,
829
- frames: a
857
+ minutes: r,
858
+ seconds: i,
859
+ frames: o
830
860
  };
831
861
  }
832
862
  /**
@@ -837,12 +867,12 @@ class g {
837
867
  * @returns Time for the time code
838
868
  */
839
869
  toTime() {
840
- const t = this.samples + se(this), { hours: r, minutes: n, seconds: o } = this.toUnits(), s = this.timeBase.toRate({ rounded: !0 }), a = t % s, i = Math.floor(1e3 * a / s), c = a / s;
870
+ const t = this.samples + ut(this), { hours: s, minutes: n, seconds: r } = this.toUnits(), i = this.timeBase.toRate({ rounded: !0 }), o = t % i, a = Math.floor(1e3 * o / i), c = o / i;
841
871
  return {
842
- hours: r,
872
+ hours: s,
843
873
  minutes: n,
844
- seconds: o,
845
- milliseconds: i,
874
+ seconds: r,
875
+ milliseconds: a,
846
876
  partialSeconds: c
847
877
  };
848
878
  }
@@ -851,9 +881,9 @@ class g {
851
881
  *
852
882
  * @returns Total seconds for the time code
853
883
  */
854
- toSeconds() {
855
- const { numerator: t, denominator: r } = this.timeBase;
856
- return Math.round(1e3 * +(this.samples * t / r)) / 1e3;
884
+ toSeconds(t) {
885
+ const { numerator: s, denominator: n } = this.timeBase, r = +(this.samples * s / n);
886
+ return t != null && t.round ? Math.round(1e3 * r) / 1e3 : r;
857
887
  }
858
888
  /**
859
889
  * Get TimeCode in a duration representation
@@ -875,70 +905,76 @@ class g {
875
905
  * @returns Duration representation of the TimeCode
876
906
  */
877
907
  toDuration(t) {
878
- const { format: r } = { ...G.toDuration, ...t || {} }, { hours: n, ...o } = this.toTime();
879
- let { minutes: s, seconds: a, milliseconds: i } = o;
880
- if (r && typeof r != "string")
908
+ const { format: s } = { ...V.toDuration, ...t || {} }, { hours: n, ...r } = this.toTime();
909
+ let { minutes: i, seconds: o, milliseconds: a } = r;
910
+ if (s && typeof s != "string")
881
911
  throw Error("format has to be a string");
882
- const c = (p, f) => !r.includes(p) || !f.some((u) => r.includes(u) && r.lastIndexOf(p) > r.indexOf(u));
883
- if (r && !(c("h", ["m", "s", "S"]) && c("m", ["s", "S"]) && c("s", ["S"])))
912
+ const c = (m, p) => !s.includes(m) || !p.some((l) => s.includes(l) && s.lastIndexOf(m) > s.indexOf(l));
913
+ if (s && !(c("h", ["m", "s", "S"]) && c("m", ["s", "S"]) && c("s", ["S"])))
884
914
  throw Error("format order is unsupported (has to be h, m, s then S)");
885
- if (!r)
886
- return `${n > 0 ? `${n}:${`${s}`.padStart(2, "0")}` : s}:${`${a}`.padStart(2, "0")}`;
887
- const l = (p, f) => {
888
- let u = p;
889
- for (; f[u] === f[u + 1]; )
890
- u += 1;
891
- return u - p + 1;
892
- }, d = ["h", "m", "s", "S"], _ = [];
893
- return [...r].forEach((p, f, u) => {
894
- switch (p) {
915
+ if (!s)
916
+ return `${n > 0 ? `${n}:${`${i}`.padStart(2, "0")}` : i}:${`${o}`.padStart(2, "0")}`;
917
+ const d = (m, p) => {
918
+ let l = m;
919
+ for (; p[l] === p[l + 1]; )
920
+ l += 1;
921
+ return l - m + 1;
922
+ }, u = ["h", "m", "s", "S"], f = [];
923
+ return [...s].forEach((m, p, l) => {
924
+ switch (m) {
895
925
  case "h": {
896
- if (u[f - 1] === "h")
926
+ if (l[p - 1] === "h")
897
927
  break;
898
- const m = l(f, u);
899
- _.push(`${n}`.padStart(m, "0")), d.includes(u[f + m]) && _.push(":");
928
+ const h = d(p, l);
929
+ f.push(`${n}`.padStart(h, "0")), u.includes(l[p + h]) && f.push(":");
900
930
  break;
901
931
  }
902
932
  case "m": {
903
- if (u[f - 1] === "m")
933
+ if (l[p - 1] === "m")
904
934
  break;
905
- const m = l(f, u);
906
- r.includes("h") || (s += n * 60), _.push(`${s}`.padStart(m, "0")), d.includes(u[f + m]) && _.push(":");
935
+ const h = d(p, l);
936
+ s.includes("h") || (i += n * 60), f.push(`${i}`.padStart(h, "0")), u.includes(l[p + h]) && f.push(":");
907
937
  break;
908
938
  }
909
939
  case "s": {
910
- if (u[f - 1] === "s")
940
+ if (l[p - 1] === "s")
911
941
  break;
912
- const m = l(f, u);
913
- r.includes("m") || (a += s * 60), _.push(`${a}`.padStart(m, "0")), d.includes(u[f + m]) && _.push(".");
942
+ const h = d(p, l);
943
+ s.includes("m") || (o += i * 60), f.push(`${o}`.padStart(h, "0")), u.includes(l[p + h]) && f.push(".");
914
944
  break;
915
945
  }
916
946
  case "S": {
917
- if (u[f - 1] === "S")
947
+ if (l[p - 1] === "S")
918
948
  break;
919
- const m = l(f, u);
920
- r.includes("s") || (i += a * 1e3), _.push(`${Math.round(i / 10 ** (3 - m))}`.padStart(m, "0"));
949
+ const h = d(p, l);
950
+ s.includes("s") || (a += o * 1e3), f.push(`${Math.round(a / 10 ** (3 - h))}`.padStart(h, "0"));
921
951
  break;
922
952
  }
923
953
  default:
924
- _.push(p);
954
+ f.push(m);
925
955
  }
926
- }), _.join("");
956
+ }), f.join("");
927
957
  }
928
958
  /**
929
959
  * Get TimeCode in a smpte representation
930
960
  *
961
+ * @param {Object} options
962
+ * @param {boolean} options.uniformSeparators Use the frame separator for all separators in the smpte string
931
963
  * @returns Smpte representation of the TimeCode
932
964
  */
933
- toSmpte() {
965
+ toSmpte(t) {
966
+ const { uniformSeparators: s } = {
967
+ uniformSeparators: !1,
968
+ ...t
969
+ };
934
970
  if (this.samples === -1 / 0)
935
971
  return "00:00:00:00";
936
- const { hours: t, minutes: r, seconds: n, frames: o } = this.toUnits(), s = [
937
- t.toFixed().padStart(2, "0"),
972
+ const { hours: n, minutes: r, seconds: i, frames: o } = this.toUnits(), a = s ? this.frameSeparator : ":", c = [
973
+ n.toFixed().padStart(2, "0"),
938
974
  r.toFixed().padStart(2, "0"),
939
- n.toFixed().padStart(2, "0")
940
- ].join(":"), a = Math.max(2, `${this.timeBase.toRate({ rounded: !0 }) - 1}`.length);
941
- return [s, `${o}`.padStart(a, "0")].join(this.frameSeparator);
975
+ i.toFixed().padStart(2, "0")
976
+ ].join(a), d = Math.max(2, `${this.timeBase.toRate({ rounded: !0 }) - 1}`.length);
977
+ return [c, `${o}`.padStart(d, "0")].join(this.frameSeparator);
942
978
  }
943
979
  /**
944
980
  * Get TimeCode as a VidiCore TimeCodeType object
@@ -960,401 +996,403 @@ class g {
960
996
  return console.warn("Deprecated - use toObject instead"), this.toObject();
961
997
  }
962
998
  }
963
- const Je = (e, t) => {
964
- let r = Math.abs(e), n = Math.abs(t);
965
- for (; r && n && r !== n; )
966
- r > n ? [r, n] = [r - n, n] : [r, n] = [r, n - r];
967
- return r || n;
968
- }, Xe = (e, t) => {
969
- const { timeBase: r, useGCD: n = !1, ...o } = t || {}, s = `${e}`.replace(/,/g, ".");
970
- if (Number.isNaN(+s))
999
+ const ue = (e, t) => {
1000
+ let s = Math.abs(e), n = Math.abs(t);
1001
+ for (; s && n && s !== n; )
1002
+ s > n ? [s, n] = [s - n, n] : [s, n] = [s, n - s];
1003
+ return s || n;
1004
+ }, le = (e, t) => {
1005
+ const { timeBase: s, useGCD: n = !1, roundingMode: r, ...i } = t || {}, o = `${e}`.replace(/,/g, ".");
1006
+ if (Number.isNaN(+o))
971
1007
  throw new Error(`seconds must be digits, is ${e}`);
972
- let a = 1, i;
973
- if (Number.isInteger(+s))
974
- i = +s * a;
1008
+ let a = 1, c;
1009
+ if (Number.isInteger(+o))
1010
+ c = +o * a;
975
1011
  else {
976
- const [, l] = s.split("."), d = Math.min((l == null ? void 0 : l.length) ?? 0, 16);
977
- a *= 10 ** d, i = Math.round(Number(s) * a);
1012
+ const [, u] = o.split("."), f = Math.min((u == null ? void 0 : u.length) ?? 0, 16);
1013
+ a *= 10 ** f, c = Math.round(Number(o) * a);
978
1014
  }
979
- if (r === void 0 && n) {
980
- const l = Je(a, i);
981
- i /= l, a /= l;
1015
+ if (s === void 0 && n) {
1016
+ const u = ue(a, c);
1017
+ c /= u, a /= u;
982
1018
  }
983
- const c = new g(
984
- { samples: i, timeBase: { denominator: a, numerator: 1 } },
985
- o
1019
+ const d = new S(
1020
+ { samples: c, timeBase: { denominator: a, numerator: 1 } },
1021
+ i
986
1022
  );
987
- return r !== void 0 ? c.conformTimeBase(v(r), o) : c;
988
- }, qe = ([e, t, r, n], o, s) => {
989
- const a = s.toRate({ rounded: !0 }), i = Q(s);
990
- if (o === 0 || !i)
1023
+ return s !== void 0 ? d.conformTimeBase(s, { ...i, roundingMode: r }) : d;
1024
+ }, de = ([e, t, s, n], r, i) => {
1025
+ const o = i.toRate({ rounded: !0 }), a = st(i);
1026
+ if (r === 0 || !a)
991
1027
  return 0;
992
- const c = t % 10 !== 0, l = c && r === 0, d = e * (3600 * a - 54 * i), _ = t * 60 * a - (t - Math.ceil(t / 10)) * i, p = r * a - (c && r > 1 ? i : 0);
993
- if (l && n < i)
1028
+ const c = t % 10 !== 0, d = c && s === 0, u = e * (3600 * o - 54 * a), f = t * 60 * o - (t - Math.ceil(t / 10)) * a, m = s * o - (c && s > 1 ? a : 0);
1029
+ if (d && n < a)
994
1030
  throw new Error(
995
- `Frame does not exist for ${s.toConstant() || s.toRate()} drop-frame`
1031
+ `Frame does not exist for ${i.toConstant() || i.toRate()} drop-frame`
996
1032
  );
997
- const f = l ? n - i : n, u = d + _ + p + f;
998
- return o - u;
999
- }, $ = (e, t, r) => {
1000
- const [n, o, s, a] = e, i = t.toRate({ rounded: !0 }), c = n * 3600 * i + o * 60 * i + s * i + a;
1001
- return c - (r ? qe(e, c, t) : 0);
1002
- }, Qe = (e) => {
1033
+ const p = d ? n - a : n, l = u + f + m + p;
1034
+ return r - l;
1035
+ }, H = (e, t, s) => {
1036
+ const [n, r, i, o] = e, a = t.toRate({ rounded: !0 }), c = n * 3600 * a + r * 60 * a + i * a + o;
1037
+ return c - (s ? de(e, c, t) : 0);
1038
+ }, fe = (e) => {
1003
1039
  const [t] = (e == null ? void 0 : e.match(/[^0-9:\-_]/)) || [];
1004
- let r = [];
1040
+ let s = [];
1005
1041
  if (t) {
1006
- const [o, s] = e.split(t);
1007
- r = [...o.split(":"), s];
1042
+ const [r, i] = e.split(t);
1043
+ s = [...r.split(":"), i];
1008
1044
  } else
1009
- r = e.split(":");
1010
- if (r.length !== 4)
1045
+ s = e.split(":");
1046
+ if (s.length !== 4)
1011
1047
  throw new Error('Invalid format, must be "##:##:##:##');
1012
- if (r.some((o) => Number.isNaN(o)))
1048
+ if (s.some((r) => Number.isNaN(r)))
1013
1049
  throw new Error("Invalid format, values must be numbers");
1014
1050
  const n = t || ":";
1015
1051
  return {
1016
- smpteValues: r.map(Number),
1052
+ smpteValues: s.map(Number),
1017
1053
  smpteFrameSeparator: n
1018
1054
  };
1019
- }, Ze = ["error", "add", "ignore"], et = {
1055
+ }, me = ["error", "add", "ignore"], he = {
1020
1056
  exceedingMode: "error",
1021
1057
  timeBase: void 0,
1022
1058
  dropFrame: void 0,
1023
1059
  frameSeparator: void 0
1024
- }, tt = (e, t) => {
1025
- const { exceedingMode: r, timeBase: n, ...o } = { ...et, ...t };
1060
+ }, pe = (e, t) => {
1061
+ const { exceedingMode: s, timeBase: n, ...r } = { ...he, ...t };
1026
1062
  if ([null, void 0].includes(e))
1027
1063
  throw new Error("smpte cannot be undefined or null");
1028
1064
  if (typeof e != "string")
1029
1065
  throw new Error(`smpte must be a string, is ${JSON.stringify(e)}`);
1030
- const { smpteValues: s, smpteFrameSeparator: a } = Qe(e), i = v(n), c = {
1031
- ...o,
1032
- frameSeparator: (o == null ? void 0 : o.frameSeparator) || a,
1033
- ...(o == null ? void 0 : o.dropFrame) === void 0 ? {
1034
- dropFrame: n !== void 0 ? Fe(i) : [";", ","].includes(a)
1066
+ const { smpteValues: i, smpteFrameSeparator: o } = fe(e), a = $(n), c = {
1067
+ ...r,
1068
+ frameSeparator: (r == null ? void 0 : r.frameSeparator) || o,
1069
+ ...(r == null ? void 0 : r.dropFrame) === void 0 ? {
1070
+ dropFrame: n !== void 0 ? wt(a) : [";", ","].includes(o)
1035
1071
  } : {}
1036
- }, l = i.toRate({ rounded: !0 }), d = Math.max(0, l - 1);
1037
- if (s.some((p) => p < 0))
1072
+ }, d = a.toRate({ rounded: !0 }), u = Math.max(0, d - 1);
1073
+ if (i.some((m) => m < 0))
1038
1074
  throw new Error("Negative values are not supported");
1039
- let _;
1040
- switch (r) {
1075
+ let f;
1076
+ switch (s) {
1041
1077
  case "error": {
1042
- const [p, f, u, m] = s;
1043
- if (p >= 100 || f >= 60)
1078
+ const [m, p, l, h] = i;
1079
+ if (m >= 100 || p >= 60)
1044
1080
  throw Error("Minutes has to be less than 60");
1045
- if (u >= 60)
1081
+ if (l >= 60)
1046
1082
  throw Error("Seconds has to be less than 60");
1047
- if (m > d)
1048
- throw Error(`Frames has to be less or equal to ${d}`);
1049
- _ = $(s, i, c == null ? void 0 : c.dropFrame);
1083
+ if (h > u)
1084
+ throw Error(`Frames has to be less or equal to ${u}`);
1085
+ f = H(i, a, c == null ? void 0 : c.dropFrame);
1050
1086
  break;
1051
1087
  }
1052
1088
  case "ignore": {
1053
- const [p, f, u, m] = s, T = [
1054
- Math.min(100, p),
1055
- Math.min(59, f),
1056
- Math.min(59, u),
1057
- Math.min(d, m)
1089
+ const [m, p, l, h] = i, g = [
1090
+ Math.min(100, m),
1091
+ Math.min(59, p),
1092
+ Math.min(59, l),
1093
+ Math.min(u, h)
1058
1094
  ];
1059
- _ = $(
1060
- T,
1061
- i,
1095
+ f = H(
1096
+ g,
1097
+ a,
1062
1098
  c == null ? void 0 : c.dropFrame
1063
1099
  );
1064
1100
  break;
1065
1101
  }
1066
1102
  case "add": {
1067
- _ = $(s, i, c == null ? void 0 : c.dropFrame);
1103
+ f = H(i, a, c == null ? void 0 : c.dropFrame);
1068
1104
  break;
1069
1105
  }
1070
1106
  default:
1071
- throw new Error(`Invalid exceedingMode, options are ${JSON.stringify(Ze)}`);
1107
+ throw new Error(`Invalid exceedingMode, options are ${JSON.stringify(me)}`);
1072
1108
  }
1073
- return new g({ samples: _, timeBase: i }, c);
1074
- }, rt = {
1109
+ return new S({ samples: f, timeBase: a }, c);
1110
+ }, _e = {
1075
1111
  timeBase: void 0,
1076
1112
  dropFrame: void 0,
1077
1113
  frameSeparator: void 0
1078
- }, B = (e, t) => {
1079
- const { timeBase: r, ...n } = { ...rt, ...t };
1080
- let o;
1114
+ }, U = (e, t) => {
1115
+ const { timeBase: s, ...n } = { ..._e, ...t };
1116
+ let r;
1081
1117
  if (e === void 0)
1082
- o = { samples: 0 };
1118
+ r = { samples: 0 };
1083
1119
  else if (typeof e == "number")
1084
- o = { samples: e };
1120
+ r = { samples: e };
1085
1121
  else if (e.includes("@")) {
1086
- const [a, i] = e.split("@");
1087
- o = { samples: Number(a), timeBase: q(i) };
1122
+ const [o, a] = e.split("@");
1123
+ r = { samples: Number(o), timeBase: et(a) };
1088
1124
  } else
1089
- e === "-INF" ? o = { samples: -1 / 0 } : e === "+INF" ? o = { samples: 1 / 0 } : o = { samples: Number(e) };
1090
- if (Number.isNaN(o == null ? void 0 : o.samples) || o.timeBase && !(o.timeBase instanceof I))
1125
+ e === "-INF" ? r = { samples: -1 / 0 } : e === "+INF" ? r = { samples: 1 / 0 } : r = { samples: Number(e) };
1126
+ if (Number.isNaN(r == null ? void 0 : r.samples) || r.timeBase && !(r.timeBase instanceof R))
1091
1127
  throw new Error(`timeCodeText must be a number or sample@timeBase - is ${e}`);
1092
- const s = new g(o, n);
1093
- return r ? s.conformTimeBase(v(r), n) : s;
1094
- }, ot = {
1128
+ const i = new S(r, n);
1129
+ return s ? i.conformTimeBase($(s), n) : i;
1130
+ }, Te = {
1095
1131
  dropFrame: void 0,
1096
1132
  frameSeparator: void 0
1097
- }, D = (e, t) => new g(e, { ...ot, ...t }), nt = (e) => !!e.match(/^(\d\d+):(\d\d+):(\d\d+)(:|;|\.|,)(\d\d+)$/), st = (e) => !Number.isNaN(Number(e)), W = (e, t) => {
1098
- if (e instanceof g)
1133
+ }, P = (e, t) => new S(e, { ...Te, ...t }), ge = (e) => !!e.match(/^(\d\d+):(\d\d+):(\d\d+)(:|;|\.|,)(\d\d+)$/), Ee = (e) => !Number.isNaN(Number(e)), j = (e, t) => {
1134
+ if (e instanceof S)
1099
1135
  return e;
1100
1136
  if (typeof e != "string" && typeof e != "number")
1101
- return D(e, t);
1102
- if (typeof e == "string" && nt(e))
1103
- return tt(e, t);
1104
- if (["string", "number"].includes(typeof e) && st(e))
1105
- return Xe(e, t);
1137
+ return P(e, t);
1138
+ if (typeof e == "string" && ge(e))
1139
+ return pe(e, t);
1140
+ if (["string", "number"].includes(typeof e) && Ee(e))
1141
+ return le(e, t);
1106
1142
  if (typeof e == "string")
1107
- return B(e, t);
1143
+ return U(e, t);
1108
1144
  };
1109
- function ie({ hours: e = 0, minutes: t = 0, seconds: r = 0, partialSeconds: n = 0 }) {
1110
- const o = e.toFixed().padStart(2, "0"), s = t.toFixed().padStart(2, "0"), a = r.toFixed().padStart(2, "0"), i = (n * 10).toFixed().padStart(3, "0");
1111
- return `${o}:${s}:${a}.${i}`;
1145
+ function lt({ hours: e = 0, minutes: t = 0, seconds: s = 0, partialSeconds: n = 0 }) {
1146
+ const r = e.toFixed().padStart(2, "0"), i = t.toFixed().padStart(2, "0"), o = s.toFixed().padStart(2, "0"), a = (n * 10).toFixed().padStart(3, "0");
1147
+ return `${r}:${i}:${o}.${a}`;
1112
1148
  }
1113
- const it = {
1149
+ const Ae = {
1114
1150
  subtitleGroup: "stl_subtitle",
1115
1151
  subtitleField: "stl_text"
1116
- }, Pt = (e, t) => {
1117
- const { subtitleGroup: r, subtitleField: n } = { ...it, ...t || {} }, { timespan: o = [] } = e || {};
1118
- return o.length === 0 ? "" : `WEBVTT
1119
-
1120
-
1121
- ${ye(o, {
1152
+ }, fs = (e, t) => {
1153
+ const { subtitleGroup: s, subtitleField: n } = { ...Ae, ...t || {} }, { timespan: r = [] } = e || {};
1154
+ if (r.length === 0)
1155
+ return "";
1156
+ const o = Ct(r, {
1122
1157
  includeTimespanAttributes: !0,
1123
1158
  sortTimespan: !0,
1124
1159
  timespanAsList: !0,
1125
1160
  overrideGroup: !0,
1126
1161
  joinValue: ","
1127
- }).map((i) => {
1162
+ }).map((a) => {
1128
1163
  const {
1129
1164
  start: c,
1130
- end: l,
1131
- [r]: { [n]: d } = {}
1132
- } = (Array.isArray(i) ? i[0] : i) || {};
1133
- if (!d)
1165
+ end: d,
1166
+ [s]: { [n]: u } = {}
1167
+ } = (Array.isArray(a) ? a[0] : a) || {};
1168
+ if (!u)
1134
1169
  return "";
1135
- const _ = ie(B(c).toTime()), p = ie(B(l).toTime());
1136
- return `${_} --> ${p} line:0%\r${d}\r`;
1137
- }).join(`
1170
+ const f = lt(U(c).toTime()), m = lt(U(d).toTime());
1171
+ return `${f} --> ${m} line:0%\r${u}\r`;
1172
+ });
1173
+ if (o.some((a) => !!a))
1174
+ return `WEBVTT
1175
+
1176
+
1177
+ ${o.join(`
1138
1178
  `)}`;
1139
- }, at = { count: !0, exclude: !0 }, Ut = (e = [], t = {}) => {
1140
- const r = { ...at, ...t }, { count: n, exclude: o } = r;
1141
- return e.map((s) => typeof s == "string" ? {
1142
- field: s,
1143
- name: s,
1179
+ }, Ie = { count: !0, exclude: !0 }, ms = (e = [], t = {}) => {
1180
+ const s = { ...Ie, ...t }, { count: n, exclude: r } = s;
1181
+ return e.map((i) => typeof i == "string" ? {
1182
+ field: i,
1183
+ name: i,
1144
1184
  count: n,
1145
- ...o === !0 ? { exclude: [s] } : {}
1146
- } : s);
1147
- }, Gt = (e = []) => e == null ? void 0 : e.map(({ name: t, field: r, count: n, range: o }) => ({
1185
+ ...r === !0 ? { exclude: [i] } : {}
1186
+ } : i);
1187
+ }, hs = (e = []) => e == null ? void 0 : e.map(({ name: t, field: s, count: n, range: r }) => ({
1148
1188
  facetName: t,
1149
- fieldName: r,
1150
- count: n == null ? void 0 : n.reduce((s, { fieldValue: a, value: i }) => ({ ...s, [a]: i }), {}),
1151
- ...o ? {
1152
- range: o.map(({ value: s, start: a, end: i }) => ({
1153
- start: Number.isNaN(+a) ? a : Number(a),
1154
- end: Number.isNaN(+i) ? i : Number(i),
1155
- count: Number(s) || 0
1189
+ fieldName: s,
1190
+ count: n == null ? void 0 : n.reduce((i, { fieldValue: o, value: a }) => ({ ...i, [o]: a }), {}),
1191
+ ...r ? {
1192
+ range: r.map(({ value: i, start: o, end: a }) => ({
1193
+ start: Number.isNaN(+o) ? o : Number(o),
1194
+ end: Number.isNaN(+a) ? a : Number(a),
1195
+ count: Number(i) || 0
1156
1196
  }))
1157
1197
  } : {}
1158
- })), $t = (e = []) => {
1198
+ })), ps = (e = []) => {
1159
1199
  const t = {};
1160
- return e.forEach(({ name: r, field: n, count: o }) => {
1161
- t[r || n] = o.reduce(
1162
- (s, { fieldValue: a, value: i }) => ({ ...s, [a]: i }),
1200
+ return e.forEach(({ name: s, field: n, count: r }) => {
1201
+ t[s || n] = r.reduce(
1202
+ (i, { fieldValue: o, value: a }) => ({ ...i, [o]: a }),
1163
1203
  {}
1164
1204
  );
1165
1205
  }), t;
1166
- }, De = {
1206
+ }, Bt = {
1167
1207
  arrayOnSingle: !0,
1168
1208
  joinValue: void 0,
1169
1209
  timespanAsList: !1
1170
- }, V = (e, t) => {
1210
+ }, Y = (e, t) => {
1171
1211
  const {
1172
- arrayOnSingle: r = !0,
1212
+ arrayOnSingle: s = !0,
1173
1213
  joinValue: n = void 0,
1174
- timespanAsList: o = !1
1175
- } = { ...De, ...t || {} }, { field: s = [], start: a, end: i } = e || {}, c = o ? { start: a, end: i } : {};
1176
- return s.reduce((d, _) => {
1177
- const { name: p, value: f = [] } = _;
1178
- if (f.length === 0)
1179
- return d;
1180
- let u;
1181
- return r === !1 && f.length === 1 ? [u] = f : n ? u = f.join(n) : u = f, { ...d, [p]: u };
1214
+ timespanAsList: r = !1
1215
+ } = { ...Bt, ...t || {} }, { field: i = [], start: o, end: a } = e || {}, c = r ? { start: o, end: a } : {};
1216
+ return i.reduce((u, f) => {
1217
+ const { name: m, value: p = [] } = f;
1218
+ if (p.length === 0)
1219
+ return u;
1220
+ let l;
1221
+ return s === !1 && p.length === 1 ? [l] = p : n ? l = p.join(n) : l = p, { ...u, [m]: l };
1182
1222
  }, c);
1183
- }, ct = {
1184
- ...De,
1223
+ }, Oe = {
1224
+ ...Bt,
1185
1225
  timespanAsList: !1,
1186
1226
  joinTimespan: "_",
1187
1227
  flat: !1,
1188
1228
  flatTimespan: !1
1189
- }, Vt = (e = [], t) => {
1229
+ }, _s = (e = [], t) => {
1190
1230
  const {
1191
- timespanAsList: r,
1231
+ timespanAsList: s,
1192
1232
  joinTimespan: n = "_",
1193
- flat: o,
1194
- flatTimespan: s,
1195
- ...a
1196
- } = { ...ct, ...t || {} };
1197
- return r === !0 ? e.map(
1198
- (i) => V(i, { ...a, timespanAsList: r })
1199
- ) : o === !0 || s === !0 ? e.reduce(
1200
- (i, c) => ({ ...i, ...V(c, t) }),
1233
+ flat: r,
1234
+ flatTimespan: i,
1235
+ ...o
1236
+ } = { ...Oe, ...t || {} };
1237
+ return s === !0 ? e.map(
1238
+ (a) => Y(a, { ...o, timespanAsList: s })
1239
+ ) : r === !0 || i === !0 ? e.reduce(
1240
+ (a, c) => ({ ...a, ...Y(c, t) }),
1201
1241
  {}
1202
1242
  ) : e.reduce(
1203
- (i, c) => ({
1204
- ...i,
1205
- [[c.start, c.end].join(n)]: V(
1243
+ (a, c) => ({
1244
+ ...a,
1245
+ [[c.start, c.end].join(n)]: Y(
1206
1246
  c,
1207
1247
  t
1208
1248
  )
1209
1249
  }),
1210
1250
  {}
1211
1251
  );
1212
- }, dt = (e, t) => {
1213
- const r = W(t).toSeconds(), { thumbnails: n = {} } = e || {}, { uri: o = [] } = n, s = o.map((i) => {
1214
- const c = i.split("/").pop().split("?").shift();
1215
- return B(c).toSeconds();
1216
- }), a = s.reduce(
1217
- (i, c, l) => Math.abs(c - r) < Math.abs(s[i] - r) ? l : i,
1252
+ }, be = (e, t) => {
1253
+ const s = j(t).toSeconds(), { thumbnails: n = {} } = e || {}, { uri: r = [] } = n, i = r.map((a) => {
1254
+ const c = a.split("/").pop().split("?").shift();
1255
+ return U(c).toSeconds();
1256
+ }), o = i.reduce(
1257
+ (a, c, d) => Math.abs(c - s) < Math.abs(i[a] - s) ? d : a,
1218
1258
  0
1219
1259
  );
1220
- return o[a];
1221
- }, ut = {
1260
+ return r[o];
1261
+ }, Re = {
1222
1262
  includeGroupMetadata: !1,
1223
1263
  flatEvents: !1,
1224
1264
  includeEntityType: !1,
1225
1265
  includeNearestThumbnail: !1
1226
- }, lt = ({
1266
+ }, ye = ({
1227
1267
  start: e,
1228
1268
  end: t,
1229
- group: r = [{ id: "unknown", name: "unknown" }]
1269
+ group: s = [{ id: "unknown", name: "unknown" }]
1230
1270
  }) => {
1231
- const [{ id: n, name: o }] = r, s = W(e).toSeconds(), a = W(t).toSeconds();
1232
- return { start: e, end: t, startSeconds: s, endSeconds: a, group: { uuid: n, name: o } };
1233
- }, kt = (e = {}, t) => {
1234
- const { entry: r = [] } = e, n = {
1235
- ...ut,
1271
+ const [{ id: n, name: r }] = s, i = j(e).toSeconds(), o = j(t).toSeconds();
1272
+ return { start: e, end: t, startSeconds: i, endSeconds: o, group: { uuid: n, name: r } };
1273
+ }, Ts = (e = {}, t) => {
1274
+ const { entry: s = [] } = e, n = {
1275
+ ...Re,
1236
1276
  ...t || {}
1237
- }, { includeGroupMetadata: o, flatEvents: s, includeEntityType: a, includeNearestThumbnail: i } = n, c = r.map((l) => {
1238
- const { type: d, item: { metadata: _ = {}, id: p, thumbnails: f = {} } = {}, timespan: u, item: m } = l;
1239
- let T = u.map(
1240
- (E) => lt(E)
1277
+ }, { includeGroupMetadata: r, flatEvents: i, includeEntityType: o, includeNearestThumbnail: a } = n, c = s.map((d) => {
1278
+ const { type: u, item: { metadata: f = {}, id: m, thumbnails: p = {} } = {}, timespan: l, item: h } = d;
1279
+ let g = l.map(
1280
+ (E) => ye(E)
1241
1281
  );
1242
- if (i && d === "Item" && f.uri && (T = T.map((E) => {
1243
- const { start: h } = E, O = dt(m, W(h));
1282
+ if (a && u === "Item" && p.uri && (g = g.map((E) => {
1283
+ const { start: A } = E, O = be(h, j(A));
1244
1284
  return { ...E, thumbnail: O };
1245
- })), o && d === "Item") {
1246
- const { timespan: E = [] } = _, h = E.flatMap(
1285
+ })), r && u === "Item") {
1286
+ const { timespan: E = [] } = f, A = E.flatMap(
1247
1287
  (O) => O.group
1248
1288
  );
1249
- if (h.length > 0) {
1250
- const O = T.map((A) => {
1289
+ if (A.length > 0) {
1290
+ const O = g.map((I) => {
1251
1291
  const {
1252
- group: { uuid: R }
1253
- } = A, [w] = R.split("/"), { field: P = [], group: U = [] } = h.find(
1254
- ({ uuid: C }) => C === w
1292
+ group: { uuid: b }
1293
+ } = I, [M] = b.split("/"), { field: N = [], group: C = [] } = A.find(
1294
+ ({ uuid: v }) => v === M
1255
1295
  );
1256
1296
  return {
1257
- ...A,
1297
+ ...I,
1258
1298
  group: {
1259
- ...A.group,
1260
- field: P,
1261
- group: U
1299
+ ...I.group,
1300
+ field: N,
1301
+ group: C
1262
1302
  }
1263
1303
  };
1264
1304
  });
1265
1305
  return {
1266
1306
  entityType: "Item",
1267
- entityId: p,
1268
- events: O.sort((A, R) => A.startSeconds - R.startSeconds),
1269
- ...a ? { itemType: m } : {}
1307
+ entityId: m,
1308
+ events: O.sort((I, b) => I.startSeconds - b.startSeconds),
1309
+ ...o ? { itemType: h } : {}
1270
1310
  };
1271
1311
  }
1272
1312
  }
1273
1313
  return {
1274
- entityType: d === "Item" ? "Item" : "Collection",
1275
- entityId: p,
1276
- events: T.sort((E, h) => E.startSeconds - h.startSeconds),
1277
- ...a && d === "Item" ? { itemType: m } : {},
1278
- ...a && d === "Collection" ? { collectionType: m } : {}
1314
+ entityType: u === "Item" ? "Item" : "Collection",
1315
+ entityId: m,
1316
+ events: g.sort((E, A) => E.startSeconds - A.startSeconds),
1317
+ ...o && u === "Item" ? { itemType: h } : {},
1318
+ ...o && u === "Collection" ? { collectionType: h } : {}
1279
1319
  };
1280
1320
  });
1281
- return s ? c.flatMap(
1282
- ({ events: l, entityType: d, entityId: _, itemType: p, collectionType: f }) => l.map(
1283
- (u) => ({
1284
- ...u,
1285
- entityType: d,
1286
- entityId: _,
1287
- ...p && { itemType: p },
1288
- ...f && { collectionType: f }
1321
+ return i ? c.flatMap(
1322
+ ({ events: d, entityType: u, entityId: f, itemType: m, collectionType: p }) => d.map(
1323
+ (l) => ({
1324
+ ...l,
1325
+ entityType: u,
1326
+ entityId: f,
1327
+ ...m && { itemType: m },
1328
+ ...p && { collectionType: p }
1289
1329
  })
1290
1330
  )
1291
- ).sort((l, d) => l.startSeconds - d.startSeconds) : c;
1292
- }, Ht = (e = "NOW") => {
1331
+ ).sort((d, u) => d.startSeconds - u.startSeconds) : c;
1332
+ }, gs = (e = "NOW") => {
1293
1333
  if (e.startsWith("NOW")) {
1294
1334
  if (e === "NOW")
1295
1335
  return /* @__PURE__ */ new Date();
1296
- const t = e[3], r = Number(e.match(/(\d+)/)[0]), n = e.match(/(\d.*)/)[0].replace(/\d/g, ""), o = /* @__PURE__ */ new Date();
1336
+ const t = e[3], s = Number(e.match(/(\d+)/)[0]), n = e.match(/(\d.*)/)[0].replace(/\d/g, ""), r = /* @__PURE__ */ new Date();
1297
1337
  switch (n) {
1298
1338
  case "HOUR":
1299
1339
  case "HOURS":
1300
- t === "+" && o.setHours(o.getHours() + r), t === "-" && o.setHours(o.getHours() - r);
1340
+ t === "+" && r.setHours(r.getHours() + s), t === "-" && r.setHours(r.getHours() - s);
1301
1341
  break;
1302
1342
  case "DAY":
1303
1343
  case "DAYS":
1304
- t === "+" && o.setDate(o.getDate() + r), t === "-" && o.setDate(o.getDate() - r);
1344
+ t === "+" && r.setDate(r.getDate() + s), t === "-" && r.setDate(r.getDate() - s);
1305
1345
  break;
1306
1346
  case "MONTH":
1307
1347
  case "MONTHS":
1308
- t === "+" && o.setMonth(o.getMonth() + r), t === "-" && o.setMonth(o.getMonth() - r);
1348
+ t === "+" && r.setMonth(r.getMonth() + s), t === "-" && r.setMonth(r.getMonth() - s);
1309
1349
  break;
1310
1350
  case "YEAR":
1311
1351
  case "YEARS":
1312
- t === "+" && o.setFullYear(o.getFullYear() + r), t === "-" && o.setFullYear(o.getFullYear() - r);
1352
+ t === "+" && r.setFullYear(r.getFullYear() + s), t === "-" && r.setFullYear(r.getFullYear() - s);
1313
1353
  break;
1314
1354
  }
1315
- return o;
1355
+ return r;
1316
1356
  }
1317
1357
  return new Date(e);
1318
- }, x = (e) => {
1319
- const { property: t = [], ...r } = e || {};
1320
- return { ...N(t), ...r };
1321
- }, _t = (e) => x(e), mt = (e) => x(e), pt = { kB: "kHz", B: "Hz", mB: "mHz" }, ae = { kB: "kbps", B: "bps", MB: "mbps" }, ft = (e) => {
1322
- var T;
1358
+ }, z = (e) => {
1359
+ const { property: t = [], ...s } = e || {};
1360
+ return { ...F(t), ...s };
1361
+ }, Se = (e) => z(e), ve = (e) => z(e), Me = { kB: "kHz", B: "Hz", mB: "mHz" }, dt = { kB: "kbps", B: "bps", MB: "mbps" }, De = (e) => {
1362
+ var g;
1323
1363
  const {
1324
1364
  timeBase: t,
1325
- channelCount: r,
1365
+ channelCount: s,
1326
1366
  codec: n,
1327
- mediaInfo: o,
1328
- bitrate: s,
1329
- metadata: a
1330
- } = e, i = _t(o), {
1367
+ mediaInfo: r,
1368
+ bitrate: i,
1369
+ metadata: o
1370
+ } = e, a = Se(r), {
1331
1371
  Format: c,
1332
- Resolution: l,
1333
- Bit_rate_mode: d
1334
- } = i, _ = N(a || []), p = t != null && t.denominator ? ((t == null ? void 0 : t.denominator) || 1) / ((t == null ? void 0 : t.numerator) || 1) : void 0, f = p !== void 0 ? y(p, {
1372
+ Resolution: d,
1373
+ Bit_rate_mode: u
1374
+ } = a, f = F(o || []), m = t != null && t.denominator ? ((t == null ? void 0 : t.denominator) || 1) / ((t == null ? void 0 : t.numerator) || 1) : void 0, p = m !== void 0 ? w(m, {
1335
1375
  base: 10,
1336
1376
  round: 1,
1337
- // @ts-expect-error (incorrect symbols typing)
1338
- symbols: pt
1377
+ symbols: Me
1339
1378
  }) : void 0;
1340
- let u, m;
1341
- return s !== void 0 && (u = y(s, { round: 2, symbols: ae }), m = Number(
1342
- // @ts-expect-error (incorrect symbols typing)
1343
- (T = y(s, { exponent: 1, symbols: ae }).split(" kbps")) == null ? void 0 : T[0]
1379
+ let l, h;
1380
+ return i !== void 0 && (l = w(i, { round: 2, symbols: dt }), h = Number(
1381
+ (g = w(i, { exponent: 1, symbols: dt }).split(" kbps")) == null ? void 0 : g[0]
1344
1382
  )), {
1345
1383
  audioFormat: c,
1346
1384
  audioCodec: n,
1347
- audioSamplerate: f,
1348
- audioSamplerateSamples: p,
1349
- audioBitDepth: l,
1350
- audioBitrate: u,
1351
- audioBitrateKbps: m,
1352
- audioBitRateMode: d,
1353
- audioChannels: r,
1354
- audioMediaInfo: i,
1355
- audioMetadata: _
1385
+ audioSamplerate: p,
1386
+ audioSamplerateSamples: m,
1387
+ audioBitDepth: d,
1388
+ audioBitrate: l,
1389
+ audioBitrateKbps: h,
1390
+ audioBitRateMode: u,
1391
+ audioChannels: s,
1392
+ audioMediaInfo: a,
1393
+ audioMetadata: f
1356
1394
  };
1357
- }, Yt = {
1395
+ }, Es = {
1358
1396
  /** Just created, not used. */
1359
1397
  NONE: "NONE",
1360
1398
  /** Discovered or created, not yet marked as finished. */
@@ -1377,203 +1415,217 @@ ${ye(o, {
1377
1415
  ARCHIVED: "ARCHIVED",
1378
1416
  /** File will be synchronized by multi-site agent. */
1379
1417
  AWAITING_SYNC: "AWAITING_SYNC"
1380
- }, Me = (e) => {
1418
+ }, xt = (e) => {
1381
1419
  const {
1382
1420
  uri: t = [],
1383
- size: r,
1421
+ size: s,
1384
1422
  hash: n,
1385
- path: o,
1386
- id: s,
1387
- storage: a
1388
- } = e, [i] = t, c = r !== void 0 ? y(r, { base: 2, standard: "jedec" }) : "", l = (o == null ? void 0 : o.split("/")) || [], d = l.pop() || "", _ = l.map((p) => `${p}/`).join("") || void 0;
1423
+ path: r,
1424
+ id: i,
1425
+ storage: o
1426
+ } = e, [a] = t, c = s !== void 0 ? w(s, { base: 2, standard: "jedec" }) : "", d = (r == null ? void 0 : r.split("/")) || [], u = d.pop() || "", f = d.map((m) => `${m}/`).join("") || void 0;
1389
1427
  return {
1390
- uri: i,
1428
+ uri: a,
1391
1429
  hash: n,
1392
1430
  fileSize: c,
1393
- fileSizeBytes: r,
1394
- path: o,
1395
- fileName: d,
1396
- fileId: s,
1397
- storageId: a,
1398
- folderPath: _
1431
+ fileSizeBytes: s,
1432
+ path: r,
1433
+ fileName: u,
1434
+ fileId: i,
1435
+ storageId: o,
1436
+ folderPath: f
1399
1437
  };
1400
- }, Tt = (e = {}) => {
1401
- const { file: t, mediaInfo: r, metadata: n = [] } = e, o = N(n), s = x(r);
1402
- let a = { binaryMetadata: o, binaryMediaInfo: s };
1438
+ }, Fe = (e = {}) => {
1439
+ const { file: t, mediaInfo: s, metadata: n = [] } = e, r = F(n), i = z(s);
1440
+ let o = { binaryMetadata: r, binaryMediaInfo: i };
1403
1441
  if (t) {
1404
- const [i] = t, c = Me(i);
1405
- a = {
1406
- ...a,
1442
+ const [a] = t, c = xt(a);
1443
+ o = {
1444
+ ...o,
1407
1445
  ...c
1408
1446
  };
1409
1447
  }
1410
- return a;
1411
- }, Et = (e = {}) => {
1448
+ return o;
1449
+ }, Ne = (e = {}) => {
1412
1450
  const {
1413
1451
  mediaInfo: t,
1414
- metadata: r,
1452
+ metadata: s,
1415
1453
  file: n,
1416
- duration: o,
1417
- startTimestamp: s,
1418
- startTimecode: a,
1419
- timeCodeTimeBase: i
1420
- } = e, c = N(r || []), l = x(t);
1421
- let { Format: d } = l;
1454
+ duration: r,
1455
+ startTimestamp: i,
1456
+ startTimecode: o,
1457
+ timeCodeTimeBase: a
1458
+ } = e, c = F(s || []), d = z(t);
1459
+ let { Format: u } = d;
1422
1460
  const {
1423
- Video_Format_List: _,
1424
- Audio_Format_List: p,
1425
- Text_Format_List: f
1426
- } = l;
1427
- if (d === void 0) {
1428
- const { format: m } = e;
1429
- d = m, m && m.includes(",") && ([d] = m.split(","));
1430
- }
1431
- let u = {
1432
- containerFormat: d,
1433
- videoFormat: _,
1434
- audioFormat: p,
1435
- textFormat: f,
1461
+ Video_Format_List: f,
1462
+ Audio_Format_List: m,
1463
+ Text_Format_List: p
1464
+ } = d;
1465
+ if (u === void 0) {
1466
+ const { format: h } = e;
1467
+ u = h, h && h.includes(",") && ([u] = h.split(","));
1468
+ }
1469
+ let l = {
1470
+ containerFormat: u,
1471
+ videoFormat: f,
1472
+ audioFormat: m,
1473
+ textFormat: p,
1436
1474
  containerMetadata: c,
1437
- containerMediaInfo: l
1475
+ containerMediaInfo: d
1438
1476
  };
1439
- if (c.componentOriginalFilename && (u.originalFilename = c.componentOriginalFilename), o !== void 0 && o.samples !== 0) {
1440
- const m = D(o);
1441
- u.durationTimeCode = m.toObject(), u.duration = m.toDuration();
1477
+ if (c.componentOriginalFilename && (l.originalFilename = c.componentOriginalFilename), r !== void 0 && r.samples !== 0) {
1478
+ const h = P(r);
1479
+ l.durationTimeCode = h.toObject(), l.duration = h.toDuration();
1442
1480
  }
1443
- if (s && (u.startTimestamp = D(s).toObject()), a !== void 0 && i && (u.startTimecode = D({
1444
- samples: a,
1445
- timeBase: i
1481
+ if (i && (l.startTimestamp = P(i).toObject()), o !== void 0 && a && (l.startTimecode = P({
1482
+ samples: o,
1483
+ timeBase: a
1446
1484
  })), n) {
1447
- const [m] = n, T = Me(m);
1448
- u = {
1449
- ...u,
1450
- ...T
1485
+ const [h] = n, g = xt(h);
1486
+ l = {
1487
+ ...l,
1488
+ ...g
1451
1489
  };
1452
1490
  }
1453
- return u;
1454
- }, ce = { kB: "kbps", B: "bps", MB: "mbps" }, ht = (e = {}) => {
1455
- var ee;
1491
+ return l;
1492
+ }, ft = { kB: "kbps", B: "bps", MB: "mbps" }, Ce = (e = {}) => {
1493
+ var k;
1456
1494
  const {
1457
1495
  codec: t,
1458
- bitrate: r,
1496
+ bitrate: s,
1459
1497
  fieldOrder: n,
1460
- resolution: o,
1461
- mediaInfo: s,
1462
- metadata: a = []
1463
- } = e, i = mt(s), c = N(a), {
1464
- Format: l,
1465
- "Frame rate": d,
1466
- "Color space": _,
1467
- "Color primaries": p,
1468
- Colorimetry: f
1469
- } = i;
1470
- let u;
1471
- const { averageFrameRate: m, realBaseFrameRate: T } = e;
1472
- T !== void 0 ? u = M({
1473
- numerator: T.denominator,
1474
- denominator: T.numerator
1475
- }) : d !== void 0 ? u = q(d) : m !== void 0 && (u = M({
1476
- numerator: m.denominator,
1477
- denominator: m.numerator
1498
+ resolution: r,
1499
+ mediaInfo: i,
1500
+ metadata: o = []
1501
+ } = e, a = ve(i), c = F(o), {
1502
+ Format: d,
1503
+ "Frame rate": u,
1504
+ "Color space": f,
1505
+ "Color primaries": m,
1506
+ Colorimetry: p
1507
+ } = a;
1508
+ let l;
1509
+ const { averageFrameRate: h, realBaseFrameRate: g } = e;
1510
+ g !== void 0 ? l = L({
1511
+ numerator: g.denominator,
1512
+ denominator: g.numerator
1513
+ }) : u !== void 0 ? l = et(u) : h !== void 0 && (l = L({
1514
+ numerator: h.denominator,
1515
+ denominator: h.numerator
1478
1516
  }));
1479
- let { "Frame count": E } = i;
1517
+ let { "Frame count": E } = a;
1480
1518
  if (E === void 0) {
1481
- const { numberOfPackets: te } = e;
1482
- te !== void 0 && (E = te.toString());
1483
- }
1484
- let h, O, A;
1485
- E && u && (h = D({ samples: E, timeBase: u }), O = h.timeBase.toConstant() || h.timeBase.toRate(), A = h.toSmpte());
1486
- const { height: R, width: w } = o || {}, P = H(o), U = `${w}x${R}`;
1487
- let C, Z;
1488
- return r !== void 0 && (C = y(r, { round: 2, symbols: ce }), Z = Number(
1489
- // @ts-expect-error (incorrect symbols typing)
1490
- (ee = y(r, { exponent: 2, symbols: ce }).split(" mbps")) == null ? void 0 : ee[0]
1519
+ const { numberOfPackets: it } = e;
1520
+ it !== void 0 && (E = it.toString());
1521
+ }
1522
+ let A, O, I;
1523
+ E && l && (A = P({ samples: E, timeBase: l }), O = A.timeBase.toConstant() || A.timeBase.toRate(), I = A.toSmpte());
1524
+ const { height: b, width: M } = r || {}, N = J(r), C = `${M}x${b}`;
1525
+ let v, B;
1526
+ return s !== void 0 && (v = w(s, { round: 2, symbols: ft }), B = Number(
1527
+ (k = w(s, { exponent: 2, symbols: ft }).split(" mbps")) == null ? void 0 : k[0]
1491
1528
  )), {
1492
- videoFormat: l,
1493
- dimension: U,
1529
+ videoFormat: d,
1530
+ dimension: C,
1494
1531
  frameRate: O,
1495
- height: R,
1496
- width: w,
1497
- timeBase: u,
1498
- timeCode: h,
1532
+ height: b,
1533
+ width: M,
1534
+ timeBase: l,
1535
+ timeCode: A,
1499
1536
  videoCodec: t,
1500
- smpte: A,
1501
- videoBitrate: C,
1502
- videoBitrateMbps: Z,
1537
+ smpte: I,
1538
+ videoBitrate: v,
1539
+ videoBitrateMbps: B,
1503
1540
  fieldOrder: n,
1504
- colorSpace: _,
1505
- chromaSubsampling: f,
1506
- aspectRatio: P,
1507
- colorPrimaries: p,
1541
+ colorSpace: f,
1542
+ chromaSubsampling: p,
1543
+ aspectRatio: N,
1544
+ colorPrimaries: m,
1508
1545
  videoMetadata: c,
1509
- videoMediaInfo: i
1546
+ videoMediaInfo: a
1510
1547
  };
1511
- }, ve = (e = {}) => {
1512
- let t = {};
1513
- const {
1548
+ }, rt = (e = {}, t = {}) => {
1549
+ let s = {};
1550
+ const { priority: n = ["container", "video", "audio", "binary"] } = t, {
1514
1551
  containerComponent: r,
1515
- videoComponent: n,
1552
+ videoComponent: i,
1516
1553
  audioComponent: o,
1517
- binaryComponent: s,
1518
- mimeType: a = [],
1519
- tag: i = []
1554
+ binaryComponent: a,
1555
+ mimeType: c = [],
1556
+ tag: d = []
1520
1557
  } = e;
1521
- if ([t.tag] = i, [t.mimeType] = a, r) {
1522
- const c = Et(r);
1523
- t = {
1524
- ...t,
1525
- ...c
1526
- };
1527
- }
1528
- if (n) {
1529
- const [c] = n, l = ht(c);
1530
- t = {
1531
- ...t,
1532
- ...l
1533
- };
1534
- }
1535
- if (o) {
1536
- const [c] = o, l = ft(c);
1537
- t = {
1538
- ...t,
1539
- ...l
1540
- };
1541
- }
1542
- if (s) {
1543
- const [c] = s, l = Tt(c);
1544
- t = {
1545
- ...t,
1546
- ...l
1547
- };
1548
- }
1549
- return t;
1550
- }, F = {
1558
+ [s.tag] = d, [s.mimeType] = c;
1559
+ const u = (f, m) => Object.fromEntries(
1560
+ [.../* @__PURE__ */ new Set([...Object.keys(m), ...Object.keys(f)])].map((p) => [
1561
+ p,
1562
+ m[p] ?? f[p]
1563
+ ])
1564
+ );
1565
+ return n.reverse().forEach((f) => {
1566
+ switch (f) {
1567
+ case "container":
1568
+ r && (s = u(
1569
+ s,
1570
+ Ne(r)
1571
+ ));
1572
+ break;
1573
+ case "video":
1574
+ if (i) {
1575
+ const [m] = i;
1576
+ s = u(
1577
+ s,
1578
+ Ce(m)
1579
+ );
1580
+ }
1581
+ break;
1582
+ case "audio":
1583
+ if (o) {
1584
+ const [m] = o;
1585
+ s = u(
1586
+ s,
1587
+ De(m)
1588
+ );
1589
+ }
1590
+ break;
1591
+ case "binary":
1592
+ if (a) {
1593
+ const [m] = a;
1594
+ s = u(
1595
+ s,
1596
+ Fe(m)
1597
+ );
1598
+ }
1599
+ break;
1600
+ }
1601
+ }), s;
1602
+ }, x = {
1551
1603
  PDF: "PDF",
1552
1604
  TEXT: "TEXT",
1553
1605
  MSWORD: "MSWORD",
1554
1606
  JSON: "JSON",
1555
1607
  XML: "XML"
1556
- }, S = {
1608
+ }, y = {
1557
1609
  IMAGE: "IMAGE",
1558
1610
  AUDIO: "AUDIO",
1559
1611
  VIDEO: "VIDEO",
1560
1612
  DOCUMENT: "DOCUMENT",
1561
1613
  BINARY: "BINARY"
1562
- }, Kt = (e = {}) => {
1563
- const { mimeType: t } = e, r = Array.isArray(t) ? t[0] : t;
1564
- if (r) {
1565
- if (r.endsWith("/pdf"))
1566
- return F.PDF;
1567
- if (r.startsWith("text/"))
1568
- return F.TEXT;
1569
- if (r.endsWith("/msword"))
1570
- return F.MSWORD;
1571
- if (r.endsWith("/json"))
1572
- return F.JSON;
1573
- if (r.endsWith("/xml"))
1574
- return F.XML;
1575
- }
1576
- }, At = [
1614
+ }, As = (e = {}) => {
1615
+ const { mimeType: t } = e, s = Array.isArray(t) ? t[0] : t;
1616
+ if (s) {
1617
+ if (s.endsWith("/pdf"))
1618
+ return x.PDF;
1619
+ if (s.startsWith("text/"))
1620
+ return x.TEXT;
1621
+ if (s.endsWith("/msword"))
1622
+ return x.MSWORD;
1623
+ if (s.endsWith("/json"))
1624
+ return x.JSON;
1625
+ if (s.endsWith("/xml"))
1626
+ return x.XML;
1627
+ }
1628
+ }, we = [
1577
1629
  "image/apng",
1578
1630
  "image/bmp",
1579
1631
  "image/gif",
@@ -1581,7 +1633,7 @@ ${ye(o, {
1581
1633
  "image/x-icon",
1582
1634
  "image/png",
1583
1635
  "image/svg+xml"
1584
- ], Ot = ["video/mp4"], It = [
1636
+ ], Be = ["video/mp4"], xe = [
1585
1637
  "audio/mp4",
1586
1638
  "audio/mpeg",
1587
1639
  "audio/x-aac",
@@ -1592,135 +1644,190 @@ ${ye(o, {
1592
1644
  "audio/ogg",
1593
1645
  "audio/webm",
1594
1646
  "audio/x-flac"
1595
- ], Rt = [...Ot, ...At, ...It], St = ["http", "https"], gt = "video/mp4", bt = "video/quicktime", Nt = "video/x-m4v", yt = "MPEG-4", Ft = "mov", Dt = "h264", L = [
1647
+ ], Pe = [...Be, ...we, ...xe], Le = ["http", "https"], je = "video/mp4", ke = "video/quicktime", We = "video/x-m4v", $e = "MPEG-4", Ue = "mov", Ge = "h264", W = [
1596
1648
  "__mp4",
1597
1649
  "__mp3_160k",
1598
1650
  "__png",
1599
1651
  "__jpeg",
1600
1652
  "__gif",
1601
1653
  "original"
1602
- ].reverse(), de = ({ parsedShape: { tag: e } }, { parsedShape: { tag: t } }) => L.includes(e) || L.includes(t) ? L.indexOf(t) - L.indexOf(e) : e.toLowerCase().localeCompare(t.toLowerCase()), zt = (e, t) => {
1654
+ ].reverse(), mt = ({ parsedShape: { tag: e } }, { parsedShape: { tag: t } }) => W.includes(e) || W.includes(t) ? W.indexOf(t) - W.indexOf(e) : e.toLowerCase().localeCompare(t.toLowerCase()), Is = (e, t) => {
1603
1655
  const {
1604
- allowedMimeTypes: r = Rt,
1605
- allowedMethods: n = St,
1606
- sortPriority: o = de,
1607
- sourceKey: s = "src",
1608
- mimeTypeKey: a = "type",
1609
- shapeKey: i = "shape",
1656
+ allowedMimeTypes: s = Pe,
1657
+ allowedMethods: n = Le,
1658
+ sortPriority: r = mt,
1659
+ sourceKey: i = "src",
1660
+ mimeTypeKey: o = "type",
1661
+ shapeKey: a = "shape",
1610
1662
  parsedShapeKey: c = "parsedShape"
1611
- } = t || {}, { shape: l = [] } = e || {}, d = l.reduce((_, p) => {
1612
- let f, u;
1613
- const m = ve(p), { uri: T, mimeType: E, containerFormat: h, videoCodec: O } = m;
1614
- if (E && (f = E, (E === bt || E === Nt) && (h === yt || h === Ft) && O === Dt && (f = gt)), T)
1663
+ } = t || {}, { shape: d = [] } = e || {}, u = d.reduce((f, m) => {
1664
+ let p, l;
1665
+ const h = rt(m), { uri: g, mimeType: E, containerFormat: A, videoCodec: O } = h;
1666
+ if (E && (p = E, (E === ke || E === We) && (A === $e || A === Ue) && O === Ge && (p = je)), g)
1615
1667
  if (n) {
1616
- const [A] = T.split("://");
1617
- n.includes(A) && (u = T);
1668
+ const [I] = g.split("://");
1669
+ n.includes(I) && (l = g);
1618
1670
  } else
1619
- u = T;
1620
- return u && r.includes(f) && _.push({
1621
- [s]: u,
1622
- [a]: f,
1623
- [i]: p,
1624
- [c]: m
1625
- }), _;
1671
+ l = g;
1672
+ return l && s.includes(p) && f.push({
1673
+ [i]: l,
1674
+ [o]: p,
1675
+ [a]: m,
1676
+ [c]: h
1677
+ }), f;
1626
1678
  }, []);
1627
- return typeof o == "function" && d.sort(de), d;
1628
- }, Jt = (e) => {
1629
- const t = ve(e), { mimeType: r, videoCodec: n, audioCodec: o } = t;
1630
- if (r) {
1631
- if (r.startsWith("audio/") && o !== void 0)
1632
- return S.AUDIO;
1633
- if (r.startsWith("video/")) {
1679
+ return typeof r == "function" && u.sort(mt), u;
1680
+ }, Os = (e) => {
1681
+ const t = rt(e), { mimeType: s, videoCodec: n, audioCodec: r } = t;
1682
+ if (s) {
1683
+ if (s.startsWith("audio/") && r !== void 0)
1684
+ return y.AUDIO;
1685
+ if (s.startsWith("video/")) {
1634
1686
  if (n !== void 0)
1635
- return S.VIDEO;
1636
- if (o !== void 0)
1637
- return S.AUDIO;
1687
+ return y.VIDEO;
1688
+ if (r !== void 0)
1689
+ return y.AUDIO;
1638
1690
  }
1639
- if (r.startsWith("image/"))
1640
- return S.IMAGE;
1641
- if (r.endsWith("/pdf") || r.startsWith("text/") || r.endsWith("/msword") || r.endsWith("/json") || r.endsWith("/xml"))
1642
- return S.DOCUMENT;
1643
- if (r.endsWith("/octet-stream"))
1644
- return S.BINARY;
1645
- }
1646
- }, Mt = (e) => {
1647
- const t = {}, { outputSetting: r = [] } = e || {};
1648
- if (r.length === 0)
1691
+ if (s.startsWith("image/"))
1692
+ return y.IMAGE;
1693
+ if (s.endsWith("/pdf") || s.startsWith("text/") || s.endsWith("/msword") || s.endsWith("/json") || s.endsWith("/xml"))
1694
+ return y.DOCUMENT;
1695
+ if (s.endsWith("/octet-stream"))
1696
+ return y.BINARY;
1697
+ }
1698
+ }, Pt = "video/mp4", Lt = "video/quicktime", jt = "video/x-m4v", ze = "MPEG-4", Ve = "mov", He = "h264", Ye = [Pt, Lt, jt], kt = [
1699
+ "video/x-mxf-h264",
1700
+ "video/x-mxf-h264-aac",
1701
+ "video/x-mxf-h264-pcm_s24le",
1702
+ "video/x-mxf-mpeg2video-pcm_s24le",
1703
+ "video/x-mxf-mpeg2video-pcm_s16le",
1704
+ "video/x-mxf-prores-pcm_s16le",
1705
+ "video/x-mxf-h264-pcm_s16le"
1706
+ ], Ke = [...Ye, ...kt], Je = [
1707
+ "audio/mp4",
1708
+ "audio/mpeg",
1709
+ "audio/x-aac",
1710
+ "audio/aac",
1711
+ "audio/x-wav",
1712
+ "audio/wav",
1713
+ "audio/accp",
1714
+ "audio/ogg",
1715
+ "audio/webm",
1716
+ "audio/x-flac"
1717
+ ], qe = [...Ke, ...Je], Xe = ["http", "https"], Qe = ({
1718
+ streamingServers: e,
1719
+ url: t,
1720
+ ending: s
1721
+ }) => $t(e[0], window.btoa(t), `.${s}`), bs = (e, t) => {
1722
+ const {
1723
+ allowedMimeTypes: s = qe,
1724
+ allowedMethods: n = Xe,
1725
+ streamingServers: r = []
1726
+ } = t || {}, { shape: i = [] } = e || {}, { startTimeCode: o } = ce(e == null ? void 0 : e.metadata, {
1727
+ flat: !0,
1728
+ arrayOnSingleValue: !1
1729
+ });
1730
+ return i.reduce((c, d) => {
1731
+ var M, N, C;
1732
+ let u, f, m;
1733
+ const p = rt(d), { uri: l, mimeType: h, containerFormat: g, videoCodec: E } = p;
1734
+ if (!(s != null && s.includes(h)) || !(n != null && n.includes((M = l == null ? void 0 : l.split("://")) == null ? void 0 : M[0])))
1735
+ return c;
1736
+ if (m = p.tag, !m) {
1737
+ const v = (C = (N = h == null ? void 0 : h.split) == null ? void 0 : N.call(h, "/")) == null ? void 0 : C.pop(), B = c.filter((k) => k.label === v).length;
1738
+ B === 0 ? m = v : m = v + (B + 1);
1739
+ }
1740
+ const { timeBase: A, startTimecode: O } = p, I = o ?? O, b = I && j(I);
1741
+ return f = l, u = h, (h === Lt || h === jt) && (g === ze || g === Ve) && E === He && (u = Pt), r != null && r.length && kt.includes(h) && (f = Qe({
1742
+ url: l,
1743
+ streamingServers: r,
1744
+ ending: "mpd"
1745
+ }), u = "application/dash+xml"), f && c.push({
1746
+ src: f,
1747
+ ...u ? { type: u } : {},
1748
+ ...m ? { label: m } : {},
1749
+ ...A ? { timeBase: A } : {},
1750
+ ...b ? { startTimeCode: b } : {}
1751
+ }), c;
1752
+ }, []);
1753
+ }, Ze = (e) => {
1754
+ const t = {}, { outputSetting: s = [] } = e || {};
1755
+ if (s.length === 0)
1649
1756
  return t;
1650
- const n = JSON.parse(r[0]), { Settings: { ContainerSettings: o, VideoDescription: s, AudioDescriptions: a } = {} } = n;
1651
- if (o && (t.containerFormat = o.Container), s) {
1652
- const { CodecSettings: i = {} } = s, { Codec: c, ...l } = i;
1757
+ const n = JSON.parse(s[0]), { Settings: { ContainerSettings: r, VideoDescription: i, AudioDescriptions: o } = {} } = n;
1758
+ if (r && (t.containerFormat = r.Container), i) {
1759
+ const { CodecSettings: a = {} } = i, { Codec: c, ...d } = a;
1653
1760
  t.videoFormat = c;
1654
- const { Height: d, Width: _ } = s;
1655
- t.height = d, t.width = _, d && _ && (t.dimension = `${_}x${d}`, t.aspectRatio = H({ height: d, width: _ }));
1656
- const [p] = Object.values(l);
1657
- if (p) {
1658
- t.fieldOrder = p.InterlaceMode, t.fieldOrder && t.fieldOrder.includes("TOP") && (t.fieldOrder = "interlaced"), t.videoBitrate = p.Bitrate;
1659
- const f = p.FramerateDenominator, u = p.FramerateNumerator, m = M({ denominator: u, numerator: f });
1660
- t.timeBase = m, t.frameRate = m.toConstant() || m.toRate();
1761
+ const { Height: u, Width: f } = i;
1762
+ t.height = u, t.width = f, u && f && (t.dimension = `${f}x${u}`, t.aspectRatio = J({ height: u, width: f }));
1763
+ const [m] = Object.values(d);
1764
+ if (m) {
1765
+ t.fieldOrder = m.InterlaceMode, t.fieldOrder && t.fieldOrder.includes("TOP") && (t.fieldOrder = "interlaced"), t.videoBitrate = m.Bitrate;
1766
+ const p = m.FramerateDenominator, l = m.FramerateNumerator, h = L({ denominator: l, numerator: p });
1767
+ t.timeBase = h, t.frameRate = h.toConstant() || h.toRate();
1661
1768
  }
1662
1769
  }
1663
- if (a && a.length > 0) {
1664
- const { CodecSettings: i = {} } = a[0], { Codec: c, ...l } = i;
1770
+ if (o && o.length > 0) {
1771
+ const { CodecSettings: a = {} } = o[0], { Codec: c, ...d } = a;
1665
1772
  t.audioFormat = c;
1666
- const [d] = Object.values(l);
1667
- d && (t.audioSamplerate = d.SampleRate, t.audioBitrate = d.Bitrate, t.audioBitRateMode = d.RateControlMode);
1773
+ const [u] = Object.values(d);
1774
+ u && (t.audioSamplerate = u.SampleRate, t.audioBitrate = u.Bitrate, t.audioBitRateMode = u.RateControlMode);
1668
1775
  }
1669
1776
  return t;
1670
- }, Xt = (e) => {
1671
- const t = {}, { description: r, format: n, audio: o, video: s, mediaconvert: a } = e || {};
1672
- if (a)
1673
- return { description: r, ...Mt(a) };
1674
- if (t.description = r, t.containerFormat = n, s) {
1675
- if (t.videoFormat = s.codec, t.videoBitrate = s.bitrate, s.framerate) {
1676
- const i = M(s.framerate);
1677
- t.timeBase = i, t.frameRate = i.toConstant() || i.toRate();
1777
+ }, Rs = (e) => {
1778
+ const t = {}, { description: s, format: n, audio: r, video: i, mediaconvert: o } = e || {};
1779
+ if (o)
1780
+ return { description: s, ...Ze(o) };
1781
+ if (t.description = s, t.containerFormat = n, i) {
1782
+ if (t.videoFormat = i.codec, t.videoBitrate = i.bitrate, i.framerate) {
1783
+ const a = L(i.framerate);
1784
+ t.timeBase = a, t.frameRate = a.toConstant() || a.toRate();
1678
1785
  }
1679
- if (s.scaling) {
1680
- const { height: i, width: c } = s.scaling;
1681
- t.height = i, t.width = c, i && c && (t.dimension = `${c}x${i}`, t.aspectRatio = H({ height: i, width: c }));
1786
+ if (i.scaling) {
1787
+ const { height: a, width: c } = i.scaling;
1788
+ t.height = a, t.width = c, a && c && (t.dimension = `${c}x${a}`, t.aspectRatio = J({ height: a, width: c }));
1682
1789
  }
1683
1790
  }
1684
- if (o) {
1685
- const { codec: i, channel: c } = o;
1686
- t.audioFormat = i, c && (t.audioChannels = c.length);
1791
+ if (r) {
1792
+ const { codec: a, channel: c } = r;
1793
+ t.audioFormat = a, c && (t.audioChannels = c.length);
1687
1794
  }
1688
1795
  return t;
1689
- }, vt = (e) => {
1796
+ }, ts = (e) => {
1690
1797
  if (!e)
1691
1798
  return;
1692
1799
  const {
1693
1800
  name: t,
1694
- type: r,
1801
+ type: s,
1695
1802
  defaultValue: n,
1696
- stringRestriction: o,
1697
- floatRestriction: s,
1698
- integerRestriction: a,
1699
- longRestriction: i,
1803
+ stringRestriction: r,
1804
+ floatRestriction: i,
1805
+ integerRestriction: o,
1806
+ longRestriction: a,
1700
1807
  data: c,
1701
- values: l,
1702
- system: d
1703
- } = e, { minLength: _, maxLength: p, pattern: f } = o || {}, { minInclusive: u, maxInclusive: m } = s || a || i || {}, T = ((l == null ? void 0 : l.field) || []).map(({ key: A, value: R }) => ({
1704
- label: R ?? A,
1705
- value: A
1706
- })), h = ((A) => Object.fromEntries(Object.entries(A).filter(([, R]) => R !== void 0)))({
1707
- min: u,
1708
- max: m,
1709
- minLength: _,
1710
- maxLength: p,
1711
- pattern: f ? new RegExp(f) : void 0
1712
- }), O = N(c);
1808
+ values: d,
1809
+ system: u
1810
+ } = e, { minLength: f, maxLength: m, pattern: p } = r || {}, { minInclusive: l, maxInclusive: h } = i || o || a || {}, g = ((d == null ? void 0 : d.field) || []).map(({ key: I, value: b }) => ({
1811
+ label: b ?? I,
1812
+ value: I
1813
+ })), A = ((I) => Object.fromEntries(Object.entries(I).filter(([, b]) => b !== void 0)))({
1814
+ min: l,
1815
+ max: h,
1816
+ minLength: f,
1817
+ maxLength: m,
1818
+ pattern: p ? new RegExp(p) : void 0
1819
+ }), O = F(c);
1713
1820
  return {
1714
1821
  name: t,
1715
- type: r,
1822
+ type: s,
1716
1823
  defaultValue: n,
1717
- required: u !== void 0 || _ !== void 0 && _ > 0,
1718
- restrictions: h,
1824
+ required: l !== void 0 || f !== void 0 && f > 0,
1825
+ restrictions: A,
1719
1826
  data: O,
1720
- options: T,
1721
- system: d === "true"
1827
+ options: g,
1828
+ system: u === "true"
1722
1829
  };
1723
- }, qt = (e) => e == null ? void 0 : e.map(vt).filter((t) => !!t), Qt = [
1830
+ }, ys = (e) => e == null ? void 0 : e.map(ts).filter((t) => !!t), Ss = [
1724
1831
  "date",
1725
1832
  "float",
1726
1833
  "integer",
@@ -1730,55 +1837,583 @@ ${ye(o, {
1730
1837
  "boolean",
1731
1838
  "timeCode"
1732
1839
  ];
1840
+ class nt {
1841
+ // custom events model
1842
+ constructor() {
1843
+ this.events = {};
1844
+ }
1845
+ /**
1846
+ * Add a callback for a specific event type
1847
+ *
1848
+ * @param event event type
1849
+ * @param callback function receiving state of chunk, transfer manager or chunked upload instance
1850
+ */
1851
+ on(t, s) {
1852
+ const n = this.events[t] || [];
1853
+ n.push(s), this.events[t] = n;
1854
+ }
1855
+ /**
1856
+ * Remove all callbacks for a specific event type
1857
+ *
1858
+ * @param event event type
1859
+ */
1860
+ off(t) {
1861
+ this.events[t] && (this.events[t] = []);
1862
+ }
1863
+ /**
1864
+ * Trigger callbacks for a specific event
1865
+ *
1866
+ * @param event
1867
+ * @param data
1868
+ * @returns
1869
+ */
1870
+ trigger(t, s, n) {
1871
+ const r = this.events[t];
1872
+ !r || r.length < 1 || r.forEach((i) => {
1873
+ i(s, n);
1874
+ });
1875
+ }
1876
+ }
1877
+ var _ = /* @__PURE__ */ ((e) => (e[e.transferring = 1] = "transferring", e[e.paused = 2] = "paused", e[e.complete = 3] = "complete", e[e.failed = 4] = "failed", e[e.idle = 5] = "idle", e[e.canceled = 6] = "canceled", e[e.offline = 7] = "offline", e))(_ || {}), T = /* @__PURE__ */ ((e) => (e.progress = "progress", e.update = "update", e.complete = "complete", e.error = "error", e.added = "upload-added", e.removed = "upload-removed", e.failed = "upload-failed", e.retry = "retry", e.pausing = "pausing", e.paused = "paused", e.resuming = "resuming", e.offline = "offline", e.online = "online", e))(T || {});
1878
+ class es {
1879
+ constructor(t = {}) {
1880
+ this.blobSlice = (t == null ? void 0 : t.blobSlice) ?? null, this.fileSize = (t == null ? void 0 : t.fileSize) ?? null, this.start = (t == null ? void 0 : t.start) ?? null, this.end = (t == null ? void 0 : t.end) ?? null, this.api = (t == null ? void 0 : t.api) ?? null, this.state = {
1881
+ retries: 0,
1882
+ status: _.idle,
1883
+ startTime: null,
1884
+ completeTime: null,
1885
+ response: null,
1886
+ bytesTransferred: null
1887
+ }, this.eventBus = new nt();
1888
+ }
1889
+ /**
1890
+ * Attempt to transfer chunk with some fault resilience.
1891
+ *
1892
+ * - 3 retires with 1 second apart in case of failure
1893
+ * - Pauses/resumes chunk transfer when network is offline/online
1894
+ *
1895
+ * @returns Promise of the transfer request
1896
+ */
1897
+ tryTransfer() {
1898
+ return this.state.status = _.transferring, this.state.startTime = performance.now(), new Promise((t, s) => {
1899
+ const n = () => {
1900
+ this.transfer().then((r) => {
1901
+ this.state.response = r, this.onComplete(), t(this);
1902
+ }).catch(() => {
1903
+ this.state.retries > 3 ? (this.state.status = _.failed, s(new Error(`Chunk ${this.start}-${this.end} failed`))) : this.state.status !== _.paused ? (this.state.retries += 1, this.tryTimeout = setTimeout(() => {
1904
+ n();
1905
+ }, 1e3)) : clearTimeout(this.tryTimeout);
1906
+ });
1907
+ };
1908
+ n(), window.addEventListener(T.online, () => {
1909
+ this.resume();
1910
+ }), window.addEventListener(T.offline, () => {
1911
+ this.pause();
1912
+ });
1913
+ });
1914
+ }
1915
+ /**
1916
+ * Transfers `blobSlice` on this object with the `api.method`
1917
+ *
1918
+ * Triggers: `EVENTS.progress`
1919
+ * Status: `STATUSES.transferring`
1920
+ *
1921
+ * @returns Promise for the transfer
1922
+ */
1923
+ transfer() {
1924
+ let t = {
1925
+ file: this.blobSlice,
1926
+ onUploadProgress: (s) => {
1927
+ [_.complete, _.offline].includes(this.state.status) || (this.state.bytesTransferred = s == null ? void 0 : s.loaded, this.eventBus.trigger(T.progress, this.state));
1928
+ }
1929
+ };
1930
+ return this.end - this.start !== this.fileSize && (t.headers = {
1931
+ index: this.start,
1932
+ size: this.fileSize
1933
+ }), t = { ...t, ...this.api.props || {} }, this.transferPromise = this.api.method(t), this.state.status = _.transferring, this.transferPromise;
1934
+ }
1935
+ pause() {
1936
+ this.state.status !== _.complete && (this.state.status = _.paused);
1937
+ }
1938
+ resume() {
1939
+ this.state.status !== _.complete && (this.state.status = _.transferring);
1940
+ }
1941
+ cancel() {
1942
+ this.state.status !== _.complete && (this.state.status = _.canceled);
1943
+ }
1944
+ get transferRate() {
1945
+ if (this.state.bytesTransferred) {
1946
+ const t = (this.state.completeTime - this.state.startTime) / 1e3;
1947
+ return this.state.bytesTransferred / t;
1948
+ }
1949
+ return 0;
1950
+ }
1951
+ onComplete() {
1952
+ this.state.status = _.complete, this.state.bytesTransferred = this.end - this.start, this.state.completeTime = performance.now(), this.eventBus.trigger(T.complete, this.state);
1953
+ }
1954
+ }
1955
+ class ht {
1956
+ constructor(t, s) {
1957
+ var n, r, i, o, a, c;
1958
+ if (this.DEFAULT_OPTIONS = Object.freeze({
1959
+ targetRate: 4e6,
1960
+ // 4mb sec,
1961
+ chunkSize: 8388608,
1962
+ // 8mb chunks
1963
+ minChunkSize: 8388608,
1964
+ // 8mb chunks
1965
+ maxConcurrentTransfers: 1,
1966
+ maxConcurrentFileTransfers: 1,
1967
+ autoMaxConcurrentTransfers: !1,
1968
+ minFileSize: 104857600,
1969
+ // 100MB
1970
+ autoResume: !0,
1971
+ // ChunkedTransferManager -> automatically resume transfers on network
1972
+ api: void 0
1973
+ }), this.eventBus = new nt(), !s.api.method)
1974
+ throw new Error("No api method specified");
1975
+ console.log(s), this.options = {
1976
+ ...this.DEFAULT_OPTIONS,
1977
+ ...s,
1978
+ api: {
1979
+ ...s.api ?? {},
1980
+ props: {
1981
+ ...((n = s.api) == null ? void 0 : n.props) ?? {},
1982
+ queryParams: {
1983
+ transferId: zt(),
1984
+ ...((i = (r = s.api) == null ? void 0 : r.props) == null ? void 0 : i.queryParams) ?? {}
1985
+ }
1986
+ }
1987
+ }
1988
+ }, this.state = {
1989
+ blob: null,
1990
+ chunks: [],
1991
+ transferPromises: [],
1992
+ targetRate: this.options.targetRate,
1993
+ rate: 0,
1994
+ // bytes / sec transfer rate updated on progress
1995
+ autoMaxConcurrentTransfers: this.options.autoMaxConcurrentTransfers,
1996
+ // this one is self adjusting, start off small...
1997
+ maxConcurrentTransfers: this.options.maxConcurrentTransfers,
1998
+ mime: "",
1999
+ status: _.idle,
2000
+ transferId: (c = (a = (o = s.api) == null ? void 0 : o.props) == null ? void 0 : a.queryParams) == null ? void 0 : c.transferId,
2001
+ lastStats: {}
2002
+ }, typeof t == "object" ? (this.state.blob = t, this.state.mime = t.type, this.addChunksFromBlob(t)) : console.error(new Error(`Expected a File or a Blob object, but got ${typeof t}`));
2003
+ }
2004
+ upload() {
2005
+ const { status: t } = this.state;
2006
+ if (console.log("status", t), t !== _.complete)
2007
+ if (t === _.idle || t === _.transferring) {
2008
+ this.state.transferPromises = [];
2009
+ const s = () => {
2010
+ const n = this.state.chunks[0].state.status, r = this.state.transferPromises.length < this.state.maxConcurrentTransfers && n !== _.transferring;
2011
+ return console.log("isOK", r), console.log("this.state", this.state), r;
2012
+ };
2013
+ s() && (console.log("this.state.chunks", this.state.chunks), this.state.chunks.forEach((n) => {
2014
+ n.state.status !== _.complete && n.state.status !== _.transferring && s() && (this.state.status = _.transferring, this.state.transferPromises.push(n.tryTransfer()));
2015
+ }), this.state.transferPromises.length > 0 && Promise.all(this.state.transferPromises).then(() => {
2016
+ this.upload();
2017
+ }).catch((n) => {
2018
+ console.log(
2019
+ "Failed on this upload() cycle, check connectivity and try to resume :(",
2020
+ n
2021
+ ), this.state.status !== _.offline ? (this.state.status = _.failed, this.eventBus.trigger(T.failed, this.state, n)) : setTimeout(() => this.retry(), 5e3);
2022
+ }));
2023
+ } else
2024
+ this.retry();
2025
+ }
2026
+ // get all byte ranges for splitting in chunks
2027
+ getByteRangesForChunks(t, s = this.options.chunkSize) {
2028
+ const n = [], { minChunkSize: r } = this.options;
2029
+ let o = s >= r ? s : r, a = Math.floor(t.size / o);
2030
+ if (t.size - (t.size - t.size / a) >= r || (a -= 1, o = Math.floor(t.size / a)), a < 2 || t.size < this.options.minFileSize)
2031
+ n.push({ start: 0, end: t.size });
2032
+ else
2033
+ for (let c = 0; c <= a; c += 1) {
2034
+ const d = o * c;
2035
+ let u = o * c + o;
2036
+ t.size - o * c <= r && (u = t.size);
2037
+ const m = {
2038
+ start: d,
2039
+ end: u
2040
+ };
2041
+ if (n.push(m), u === t.size)
2042
+ break;
2043
+ }
2044
+ return n;
2045
+ }
2046
+ addChunksFromBlob(t) {
2047
+ this.getByteRangesForChunks(t).forEach((n) => {
2048
+ const r = new es({
2049
+ start: n.start,
2050
+ end: n.end,
2051
+ blobSlice: t.slice(n.start, n.end),
2052
+ fileSize: t.size,
2053
+ api: this.options.api
2054
+ });
2055
+ r.eventBus.on(T.progress, () => {
2056
+ this.onProgress();
2057
+ }), r.eventBus.on(T.complete, () => {
2058
+ this.onProgress();
2059
+ }), this.state.chunks.push(r);
2060
+ });
2061
+ }
2062
+ retry() {
2063
+ this.state.status === _.failed && (this.resume(), this.eventBus.trigger(T.retry, this.state));
2064
+ }
2065
+ resume() {
2066
+ this.state.status = _.transferring, this.eventBus.trigger(T.resuming, this.state), this.state.chunks.length > 0 && this.state.chunks.forEach((t) => {
2067
+ t.resume();
2068
+ });
2069
+ }
2070
+ pause() {
2071
+ this.state.status = _.paused, this.state.chunks.length > 0 && this.state.chunks.forEach((s) => {
2072
+ s.pause();
2073
+ });
2074
+ const t = Promise.all(this.state.transferPromises);
2075
+ return this.eventBus.trigger(T.pausing, this.state), t.then(() => {
2076
+ this.eventBus.trigger(T.paused, this.state);
2077
+ }), Promise.all(this.state.transferPromises);
2078
+ }
2079
+ cancel() {
2080
+ this.state.status = _.canceled, this.state.chunks.length > 0 && this.state.chunks.forEach((s) => {
2081
+ s.cancel();
2082
+ }), this.upload = () => {
2083
+ };
2084
+ const t = Promise.all(this.state.transferPromises);
2085
+ return t.then(() => {
2086
+ this.eventBus.trigger(T.removed, this.state);
2087
+ }), t;
2088
+ }
2089
+ // TODO - remove this, seems to be too flaky
2090
+ autoAdjustMaxConcurrentTransfers(t) {
2091
+ if (this.state.autoMaxConcurrentTransfers && this.state.status !== _.complete) {
2092
+ const s = t.avgTransferRate / this.state.targetRate;
2093
+ if (s > 1.2)
2094
+ this.state.maxConcurrentTransfers += 1;
2095
+ else if (s < 0.3)
2096
+ this.state.maxConcurrentTransfers = 1;
2097
+ else {
2098
+ const n = this.options.maxConcurrentTransfers - 1;
2099
+ this.state.maxConcurrentTransfers = Math.max(
2100
+ this.options.maxConcurrentTransfers,
2101
+ Math.min(n, this.options.maxConcurrentTransfers)
2102
+ );
2103
+ }
2104
+ }
2105
+ }
2106
+ onProgress() {
2107
+ try {
2108
+ const t = this.getStats();
2109
+ t !== this.state.lastStats && (this.state.lastStats = t, Gt(
2110
+ () => {
2111
+ this.autoAdjustMaxConcurrentTransfers(t);
2112
+ },
2113
+ 1e3,
2114
+ !1
2115
+ )({}), this.state.status !== _.complete && (t.totalChunks === t.completedChunks ? this.onComplete() : (this.eventBus.trigger(T.progress, this.state), this.options.onProgress && this.options.onProgress(t))));
2116
+ } catch (t) {
2117
+ console.error(t);
2118
+ }
2119
+ }
2120
+ onComplete() {
2121
+ const t = this.getStats();
2122
+ this.state.lastStats = t, this.state.status = _.complete, this.eventBus.trigger(T.complete, this.state), this.options.onComplete && this.options.onComplete(this.finalResponse);
2123
+ }
2124
+ getStats() {
2125
+ const t = this.state.chunks.length, s = this.state.chunks.filter(
2126
+ (d) => d.state.status === _.complete
2127
+ ), n = this.state.chunks.filter(
2128
+ (d) => d.state.status === _.transferring
2129
+ ), r = s.length;
2130
+ let i = 0, o = 0;
2131
+ s.forEach((d) => {
2132
+ i += d.transferRate, o += d.blobSlice.size;
2133
+ }), n.forEach((d) => {
2134
+ o += d.state.bytesTransferred;
2135
+ });
2136
+ const a = i / r, c = {
2137
+ totalChunks: t,
2138
+ completedChunks: r,
2139
+ totalBytes: this.state.blob.size,
2140
+ transferredBytes: o,
2141
+ avgTransferRate: a,
2142
+ concurrentTransfers: this.state.maxConcurrentTransfers
2143
+ };
2144
+ return this.state.rate = c.avgTransferRate, c;
2145
+ }
2146
+ // if a setter is used, stop the automatic adjustment
2147
+ set concurrentTransfers(t) {
2148
+ this.state.autoMaxConcurrentTransfers = !1, this.state.maxConcurrentTransfers = t;
2149
+ }
2150
+ set rate(t) {
2151
+ this.state.targetRate = t;
2152
+ }
2153
+ get rate() {
2154
+ return this.state.rate;
2155
+ }
2156
+ get finalResponse() {
2157
+ const t = this.state.chunks.length - 1, s = !1;
2158
+ for (let n = t; n >= 0; n -= 1) {
2159
+ const r = this.state.chunks[n];
2160
+ if (typeof r.state.response.data == "object")
2161
+ return r.state.response;
2162
+ }
2163
+ return s;
2164
+ }
2165
+ get transferId() {
2166
+ return this.state.transferId;
2167
+ }
2168
+ }
2169
+ function ss(e, t) {
2170
+ return e === 0 || t === 0 ? 0 : Math.floor(e / t * 100);
2171
+ }
2172
+ const rs = {
2173
+ maxConcurrentFileTransfers: 1,
2174
+ autoResume: !0
2175
+ };
2176
+ class vs {
2177
+ constructor(t) {
2178
+ this.initialState = Object.freeze({
2179
+ status: _.idle,
2180
+ transfers: [],
2181
+ bytesDone: 0,
2182
+ bytesTotal: 0,
2183
+ lastStats: {
2184
+ // helps evaluate progress change
2185
+ bytesDone: 0,
2186
+ bytesTotal: 0
2187
+ }
2188
+ }), this.state = { ...this.initialState }, this.options = {
2189
+ ...rs,
2190
+ ...t
2191
+ }, this.events = new nt(), this.bindNetworkEvents();
2192
+ }
2193
+ get transfers() {
2194
+ return Object.values(this.state.transfers) || [];
2195
+ }
2196
+ get status() {
2197
+ return this.state.status;
2198
+ }
2199
+ set status(t) {
2200
+ this.events.trigger(T.update, this.state), this.state.status = t;
2201
+ }
2202
+ get bytesTotal() {
2203
+ let t = 0;
2204
+ return this.transfers.forEach((s) => {
2205
+ t += s.state.blob.size;
2206
+ }), t;
2207
+ }
2208
+ get bytesDone() {
2209
+ let t = 0;
2210
+ return this.transfers.forEach((s) => {
2211
+ t += s.getStats().transferredBytes;
2212
+ }), t;
2213
+ }
2214
+ get isUploading() {
2215
+ return this.state.status === _.transferring;
2216
+ }
2217
+ get paused() {
2218
+ let t = !0;
2219
+ return this.transfers.forEach((s) => {
2220
+ s.state.status !== _.paused && (t = !1);
2221
+ }), t;
2222
+ }
2223
+ bindNetworkEvents() {
2224
+ typeof window > "u" || (window.addEventListener(T.online, () => {
2225
+ this.events.trigger(T.online, this.state), this.state.status = _.transferring, this.options.autoResume && setTimeout(() => {
2226
+ this.retry();
2227
+ }, 1500);
2228
+ }), window.addEventListener(T.offline, () => {
2229
+ this.events.trigger(T.offline, this.state), this.state.status = _.offline;
2230
+ }));
2231
+ }
2232
+ addChunkedUpload(t) {
2233
+ console.log("chunkedUpload", t), t.transferId !== null && (this.state.transfers[t.transferId] = t, t.eventBus.on(T.progress, () => {
2234
+ this.onProgress();
2235
+ }), t.eventBus.on(T.complete, () => {
2236
+ this.upload(), this.onProgress();
2237
+ }), t.eventBus.on(T.failed, (s, n) => {
2238
+ this.onFail(n, s);
2239
+ }), t.eventBus.on(T.retry, () => {
2240
+ this.events.trigger(T.retry, this.state);
2241
+ }), t.eventBus.on(T.paused, () => {
2242
+ this.paused && this.events.trigger(T.paused, this.state);
2243
+ }), this.updateStats(), this.events.trigger(T.added, this.state), this.events.trigger(T.update, this.state));
2244
+ }
2245
+ // param can be file or a reference to transfer, or a transferId
2246
+ removeChunkedUpload(t, s = !1) {
2247
+ const n = (r) => r ? r.state.status === _.complete && !s ? (console.error(
2248
+ "Can't cancel complete transfers, pass true as a second argument in .removeChunkedUpload() to force removal."
2249
+ ), !1) : (Object.keys(this.state.transfers).forEach((i) => {
2250
+ r === this.state.transfers[i] && delete this.state.transfers[i];
2251
+ }), this.events.trigger(T.removed, this.state), r.cancel(), !0) : (console.error("Could not find a matching transfer to cancel."), !1);
2252
+ t instanceof ht ? n(t) : t instanceof File ? n(this.exists(t)) : typeof t == "string" ? n(this.transfers.find((r) => r.transferId === t)) : console.error(
2253
+ "Invalid object to remove - has to be either ChunkedUpload, File or transferId"
2254
+ );
2255
+ }
2256
+ onProgress() {
2257
+ this.updateStats(), this.hasCompleted ? this.onComplete() : this.state.bytesDone !== this.state.lastStats.bytesDone && (this.state.status = _.transferring, this.events.trigger(T.progress, this.state));
2258
+ }
2259
+ onComplete() {
2260
+ this.state.status = _.complete, this.events.trigger(T.complete, this.state);
2261
+ }
2262
+ exists(t) {
2263
+ let s;
2264
+ for (let n = 0; n < this.transfers.length; n += 1) {
2265
+ const r = this.transfers[n];
2266
+ if (r.state.blob.name === t.name && r.state.blob.lastModified === t.lastModified && r.state.blob.size && t.size)
2267
+ return s = r, s;
2268
+ }
2269
+ return s;
2270
+ }
2271
+ // eslint-disable-next-line class-methods-use-this
2272
+ isTransferAvailable(t) {
2273
+ return t.state.status !== _.complete && t.state.status !== _.transferring || t.state.status === _.idle;
2274
+ }
2275
+ pause() {
2276
+ let t = Promise.resolve(!0);
2277
+ if (!this.paused) {
2278
+ this.events.trigger(T.pausing, this.state);
2279
+ const s = [];
2280
+ this.transfers.forEach((n) => {
2281
+ s.push(n.pause());
2282
+ }), t = Promise.all(s), t.then(() => {
2283
+ this.events.trigger(T.paused, this.state);
2284
+ });
2285
+ }
2286
+ return t;
2287
+ }
2288
+ resume() {
2289
+ this.events.trigger(T.update, this.state), this.transfers.forEach((t) => {
2290
+ this.isTransferAvailable(t) && t.state.status !== _.idle && t.resume();
2291
+ });
2292
+ }
2293
+ retry() {
2294
+ this.status === _.failed && (this.resume(), this.events.trigger(T.retry, this.state));
2295
+ }
2296
+ upload() {
2297
+ let t = 0;
2298
+ console.log("this.transfers", this.transfers), console.log("this.options.maxConcurrentFileTransfers", this.options.maxConcurrentFileTransfers), console.log("before ongoingTransfers", t), this.transfers.forEach((s) => {
2299
+ this.isTransferAvailable(s) ? t < this.options.maxConcurrentFileTransfers && (this.events.trigger(T.update, this.state), s.upload(), t += 1) : s.state.status !== _.complete && (t += 1);
2300
+ }), t > 0 && (this.status = _.transferring), t < this.options.maxConcurrentFileTransfers && this.transfers.length < t && this.upload(), console.log("after ongoingTransfers", t);
2301
+ }
2302
+ onFail(t, s) {
2303
+ this.status = _.failed, this.events.trigger(T.error, s, t);
2304
+ }
2305
+ reset() {
2306
+ this.transfers.forEach((t) => {
2307
+ t.constructor.name === ht.name && this.removeChunkedUpload(t, !0);
2308
+ }), this.state = { ...this.initialState }, this.events.trigger(T.update, this.state), this.events.trigger(T.complete, this.state);
2309
+ }
2310
+ destroy() {
2311
+ this.reset();
2312
+ }
2313
+ get hasCompleted() {
2314
+ let t = !0;
2315
+ return this.transfers.forEach((s) => {
2316
+ s.state.status !== _.complete && (t = !1);
2317
+ }), t;
2318
+ }
2319
+ updateStats() {
2320
+ this.state.lastStats.bytesDone = this.state.bytesDone, this.state.lastStats.bytesTotal = this.state.bytesTotal, this.state.bytesTotal = this.bytesTotal, this.state.bytesDone = this.bytesDone;
2321
+ }
2322
+ // these are convenient for displaying data
2323
+ get percentDone() {
2324
+ return ss(this.state.bytesDone, this.state.bytesTotal);
2325
+ }
2326
+ get fileList() {
2327
+ const t = [];
2328
+ return this.transfers.forEach((s) => {
2329
+ const n = s.getStats(), { totalChunks: r, completedChunks: i } = n, o = {
2330
+ name: s.state.blob.name,
2331
+ bytesDone: n.transferredBytes,
2332
+ bytesTotal: s.state.blob.size,
2333
+ totalChunks: r,
2334
+ completedChunks: i,
2335
+ transfer: s
2336
+ };
2337
+ t.push(o);
2338
+ }), t;
2339
+ }
2340
+ }
2341
+ const Wt = (e, t, s = "") => {
2342
+ const n = (a) => {
2343
+ const c = a.startsWith("/") ? a.slice(1) : a, d = (c == null ? void 0 : c.search("/")) ?? -1;
2344
+ return d === -1 ? [c] : [c.slice(0, d), c.slice(d + 1)];
2345
+ }, [r, i] = n(t), o = [s, r].filter(Boolean).join("/");
2346
+ return i ? {
2347
+ [r]: {
2348
+ file: new File([e], r, { ...e, type: "folder" }),
2349
+ path: o,
2350
+ progress: { totalBytes: e.size ?? 0, transferredBytes: 0 },
2351
+ files: Wt(e, i, o)
2352
+ }
2353
+ } : {
2354
+ [r]: {
2355
+ file: e,
2356
+ path: o,
2357
+ progress: { totalBytes: e.size ?? 0, transferredBytes: 0 }
2358
+ }
2359
+ };
2360
+ }, Ms = (e) => e.map((t) => Wt(t, t.path ?? t.webkitRelativePath)).reduce((t, s) => Ut(t, s), {});
1733
2361
  export {
1734
- F as DOCUMENT_TYPES,
1735
- Ce as FIELD_ATTRIBUTE_KEYS,
1736
- Qt as FIELD_DEFINITION_TYPES,
1737
- we as FIELD_VALUE_ATTRIBUTE_KEYS,
1738
- Yt as FILE_STATES,
1739
- Le as GROUP_ATTRIBUTE_KEYS,
1740
- Ct as ROLE_NAMES,
1741
- S as SHAPE_MEDIA_TYPES,
1742
- Lt as SYSTEM_FIELDGROUPS,
1743
- Bt as SYSTEM_FIELDS,
1744
- I as TimeBase,
1745
- g as TimeCode,
1746
- Wt as createMetadataType,
1747
- Ut as createSearchFacetList,
1748
- v as createTimeBase,
1749
- W as createTimeCode,
1750
- ut as defaultOptions,
1751
- zt as filterShapeSource,
1752
- dt as findNearestThumbnail,
1753
- q as formatTimeBaseText,
1754
- M as formatTimeBaseType,
1755
- Xe as formatTimeCodeSeconds,
1756
- tt as formatTimeCodeSmpte,
1757
- B as formatTimeCodeText,
1758
- D as formatTimeCodeType,
1759
- Kt as getShapeDocumentType,
1760
- Jt as getShapeMediaType,
1761
- Pt as metadataTypeToWebVtt,
1762
- ft as parseAudioComponent,
1763
- Tt as parseBinaryComponent,
1764
- Et as parseContainerComponent,
1765
- Gt as parseFacetList,
1766
- $t as parseFacetType,
1767
- qt as parseFieldDefinitionList,
1768
- Se as parseFieldList,
1769
- Me as parseFileType,
1770
- be as parseGroupList,
1771
- V as parseHighlightTimespan,
1772
- Vt as parseHighlightTimespanList,
1773
- N as parseKeyValuePairType,
1774
- Mt as parseMediaConvertPreset,
1775
- jt as parseMetadataType,
1776
- Ht as parseNowDate,
1777
- kt as parseSearchResultEvents,
1778
- ve as parseShapeType,
1779
- xt as parseSimpleMetadataType,
1780
- Ke as parseTimespan,
1781
- ye as parseTimespanList,
1782
- Xt as parseTranscodePreset,
1783
- ht as parseVideoComponent
2362
+ es as Chunk,
2363
+ vs as ChunkedTransferManager,
2364
+ ht as ChunkedUpload,
2365
+ nt as ChunkedUploadEventBus,
2366
+ x as DOCUMENT_TYPES,
2367
+ T as EVENTS,
2368
+ Ht as FIELD_ATTRIBUTE_KEYS,
2369
+ Ss as FIELD_DEFINITION_TYPES,
2370
+ Vt as FIELD_VALUE_ATTRIBUTE_KEYS,
2371
+ Es as FILE_STATES,
2372
+ Yt as GROUP_ATTRIBUTE_KEYS,
2373
+ os as ROLE_NAMES,
2374
+ y as SHAPE_MEDIA_TYPES,
2375
+ _ as STATUSES,
2376
+ cs as SYSTEM_FIELDGROUPS,
2377
+ us as SYSTEM_FIELDS,
2378
+ R as TimeBase,
2379
+ S as TimeCode,
2380
+ ls as createMetadataType,
2381
+ ms as createSearchFacetList,
2382
+ $ as createTimeBase,
2383
+ j as createTimeCode,
2384
+ Ms as fileListToFileTree,
2385
+ Is as filterShapeSource,
2386
+ be as findNearestThumbnail,
2387
+ et as formatTimeBaseText,
2388
+ L as formatTimeBaseType,
2389
+ le as formatTimeCodeSeconds,
2390
+ pe as formatTimeCodeSmpte,
2391
+ U as formatTimeCodeText,
2392
+ P as formatTimeCodeType,
2393
+ bs as getPlayerSources,
2394
+ As as getShapeDocumentType,
2395
+ Os as getShapeMediaType,
2396
+ fs as metadataTypeToWebVtt,
2397
+ De as parseAudioComponent,
2398
+ Fe as parseBinaryComponent,
2399
+ Ne as parseContainerComponent,
2400
+ hs as parseFacetList,
2401
+ ps as parseFacetType,
2402
+ ys as parseFieldDefinitionList,
2403
+ Mt as parseFieldList,
2404
+ xt as parseFileType,
2405
+ Ft as parseGroupList,
2406
+ Y as parseHighlightTimespan,
2407
+ _s as parseHighlightTimespanList,
2408
+ F as parseKeyValuePairType,
2409
+ Ze as parseMediaConvertPreset,
2410
+ ce as parseMetadataType,
2411
+ gs as parseNowDate,
2412
+ Ts as parseSearchResultEvents,
2413
+ rt as parseShapeType,
2414
+ ds as parseSimpleMetadataType,
2415
+ ae as parseTimespan,
2416
+ Ct as parseTimespanList,
2417
+ Rs as parseTranscodePreset,
2418
+ Ce as parseVideoComponent
1784
2419
  };