@vidispine/vdt-js 23.4.0-pre.3 → 23.4.0

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,13 +1,32 @@
1
- import { filesize as v } from "filesize";
2
- import xe from "url-join";
3
- const le = (e, t) => t ? le(t, e % t) : e, K = (e) => {
4
- const { width: t, height: r } = e || {};
5
- 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)
6
7
  return;
7
- const s = le(t, r);
8
- let o = t / s, n = r / s;
9
- return o > 21 && (n = 1, o = (t / r).toFixed(2)), [o, n].join(":");
10
- }, M = (e) => Object.fromEntries((e == null ? void 0 : e.map(({ key: t, value: r }) => [t, r])) || []), Jt = {
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 = {
11
30
  ACCESSCONTROL_READ: "_accesscontrol_read",
12
31
  ACCESSCONTROL_WRITE: "_accesscontrol_write",
13
32
  ADMINISTRATOR: "_administrator",
@@ -117,7 +136,7 @@ const le = (e, t) => t ? le(t, e % t) : e, K = (e) => {
117
136
  USER: "_user",
118
137
  VXA: "_vxa",
119
138
  VXA_READ: "_vxa_read"
120
- }, Xt = [
139
+ }, cs = [
121
140
  "stl_subtitle",
122
141
  "stl_tti",
123
142
  "stl_gsi",
@@ -129,7 +148,7 @@ const le = (e, t) => t ? le(t, e % t) : e, K = (e) => {
129
148
  "facedetect_face",
130
149
  "originalTrackFilename",
131
150
  "stl_gsiHeader"
132
- ], qt = [
151
+ ], us = [
133
152
  "title",
134
153
  "user",
135
154
  "shapeTag",
@@ -268,291 +287,291 @@ const le = (e, t) => t ? le(t, e % t) : e, K = (e) => {
268
287
  "jc",
269
288
  "vp",
270
289
  "sn"
271
- ], z = [
290
+ ], q = [
272
291
  "uuid",
273
292
  "user",
274
293
  "timestamp",
275
294
  "change",
276
295
  "conflict",
277
296
  "mode"
278
- ], _e = [
297
+ ], _t = [
279
298
  "name",
280
299
  "id",
281
300
  "referenced",
282
301
  "data",
283
302
  "inheritance"
284
- ], We = [
285
- ...z,
303
+ ], Vt = [
304
+ ...q,
286
305
  "value",
287
306
  "lang"
288
- ], Pe = [
289
- ...z,
290
- ..._e,
307
+ ], Ht = [
308
+ ...q,
309
+ ..._t,
291
310
  "value",
292
311
  "reference",
293
312
  "type",
294
313
  "track"
295
- ], je = [
296
- ...z,
297
- ..._e,
314
+ ], Yt = [
315
+ ...q,
316
+ ..._t,
298
317
  "cycle",
299
318
  "field",
300
319
  "group"
301
- ], Y = (e) => Object.prototype.toString.call(e) === "[object Object]" && e.value !== void 0, me = (e) => ["string", "boolean", "number"].includes(typeof e), pe = (e) => Y(e) && ((e == null ? void 0 : e.value) === null || Y(e.value) || me(e.value)), Ue = (e) => Object.prototype.toString.call(e) === "[object Object]", fe = (e) => Object.prototype.toString.call(e) === "[object Date]", Ee = (e) => e === null ? !0 : Array.isArray(e) ? e.some(Ee) : me(e) || pe(e) || fe(e), Te = (e) => {
302
- const t = (r) => Ue(r) && r.value === void 0 && !!Object.entries(e);
303
- return Array.isArray(e) ? e.every(Te) : t(e);
304
- }, $e = (e, t) => e + (t.length > 1 ? "s" : ""), he = (e, t) => {
305
- const r = e.filter((s) => !t.includes(s));
306
- 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)
307
326
  throw Error(
308
- `Unsupported ${$e("key", r)} (${r.join(", ")})`
327
+ `Unsupported ${Jt("key", s)} (${s.join(", ")})`
309
328
  );
310
- }, Ae = (e) => {
329
+ }, bt = (e) => {
311
330
  if (Array.isArray(e))
312
331
  throw Error("Invalid value inside value object, cannot be array");
313
- return [void 0, null].includes(e) ? {} : fe(e) ? { value: e.toISOString() } : { value: e.toString() };
314
- }, Ge = (e) => {
315
- if (he(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)
316
335
  throw Error("Invalid value object, cannot be empty object");
317
336
  if (typeof (e == null ? void 0 : e.value) == "string")
318
337
  return e;
319
- const t = Ae(e == null ? void 0 : e.value);
338
+ const t = bt(e == null ? void 0 : e.value);
320
339
  return { ...e, ...t !== void 0 ? t : {} };
321
- }, J = (e) => {
340
+ }, X = (e) => {
322
341
  if (![void 0, null].includes(e))
323
- return Array.isArray(e) ? e.flatMap(J) : Y(e) ? Ge(e) : Ae(e);
324
- }, Ve = (e) => {
325
- he(Object.keys(e), Pe);
326
- const t = J(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);
327
346
  if (t === void 0) {
328
- const { value: r, ...s } = e;
329
- return s;
347
+ const { value: s, ...n } = e;
348
+ return n;
330
349
  }
331
350
  return {
332
351
  ...e,
333
352
  value: [...Array.isArray(t) ? t : [t]]
334
353
  };
335
- }, ke = (e) => {
336
- if (pe(e))
337
- return Ve(e);
338
- const t = J(e);
354
+ }, Qt = (e) => {
355
+ if (gt(e))
356
+ return Xt(e);
357
+ const t = X(e);
339
358
  if (t !== void 0)
340
359
  return { value: [...Array.isArray(t) ? t : [t]] };
341
- }, Ie = (e) => {
342
- const t = [], r = [];
343
- let s = {};
344
- return Object.entries(e || {}).forEach(([o, n]) => {
345
- if (je.includes(o))
346
- s = { ...s, [o]: n };
347
- else if (Ee(n))
360
+ }, Rt = (e) => {
361
+ const t = [], s = [];
362
+ let n = {};
363
+ return Object.entries(e || {}).forEach(([r, i]) => {
364
+ if (Yt.includes(r))
365
+ n = { ...n, [r]: i };
366
+ else if (At(i))
348
367
  try {
349
- r.push({ name: o, ...ke(n) });
350
- } catch (a) {
351
- 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}"` : ""));
352
371
  }
353
- else if (Te(n))
354
- (Array.isArray(n) ? n : [n]).forEach((a) => {
355
- t.push({ name: o, ...Ie(a) });
372
+ else if (It(i))
373
+ (Array.isArray(i) ? i : [i]).forEach((o) => {
374
+ t.push({ name: r, ...Rt(o) });
356
375
  });
357
376
  else
358
- throw Error(`Unhandled value for "${o}"`);
377
+ throw Error(`Unhandled value for "${r}"`);
359
378
  }), {
360
- ...s,
379
+ ...n,
361
380
  ...t.length > 0 ? { group: t } : {},
362
- ...r.length > 0 ? { field: r } : {}
381
+ ...s.length > 0 ? { field: s } : {}
363
382
  };
364
- }, He = (e) => {
365
- const { start: t = "-INF", end: r = "+INF", base: s = void 0, ...o } = e, { group: n, field: a } = Ie(o);
383
+ }, Zt = (e) => {
384
+ const { start: t = "-INF", end: s = "+INF", base: n = void 0, ...r } = e, { group: i, field: o } = Rt(r);
366
385
  return {
367
- ...n ? { group: n } : {},
368
- ...a ? { field: a } : {},
386
+ ...i ? { group: i } : {},
387
+ ...o ? { field: o } : {},
369
388
  start: t.toString(),
370
- end: r.toString(),
371
- ...s ? { base: s } : {}
389
+ end: s.toString(),
390
+ ...n ? { base: n } : {}
372
391
  };
373
- }, Qt = (e) => ({
374
- timespan: (Array.isArray(e) ? e : [e || {}]).map((t) => He(t))
375
- }), Ye = (e, t) => {
376
- var o, n;
377
- const [r] = ((o = e == null ? void 0 : e.start) == null ? void 0 : o.split("@")) || [], [s] = ((n = t == null ? void 0 : t.start) == null ? void 0 : n.split("@")) || [];
378
- return Number(r) < Number(s) ? -1 : Number(r) > Number(s) ? 1 : 0;
379
- }, D = (e) => Array.isArray(e) ? e : e && [e] || [], oe = (e) => Array.isArray(e) ? e.pop() : e, Ke = (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 = {
380
399
  includeValueAttributes: !1
381
400
  };
382
- function ze(e, t) {
383
- const { includeValueAttributes: r } = {
384
- ...Oe,
401
+ function se(e, t) {
402
+ const { includeValueAttributes: s } = {
403
+ ...yt,
385
404
  ...t || {}
386
405
  };
387
- if (r === !1)
406
+ if (s === !1)
388
407
  return e == null ? void 0 : e.value;
389
- const { value: s, ...o } = e;
390
- return { ...r === !0 && o || Array.isArray(r) && Object.fromEntries(
391
- Object.entries(o).filter(
392
- ([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)
393
412
  )
394
- ) || {}, value: s };
413
+ ) || {}, value: n };
395
414
  }
396
- const Se = {
397
- ...Oe,
415
+ const St = {
416
+ ...yt,
398
417
  joinValue: void 0,
399
418
  arrayOnSingleValue: !0
400
419
  };
401
- function Je(e, t) {
402
- const { joinValue: r, arrayOnSingleValue: s, ...o } = {
403
- ...Se,
420
+ function re(e, t) {
421
+ const { joinValue: s, arrayOnSingleValue: n, ...r } = {
422
+ ...St,
404
423
  ...t || {}
405
- }, n = e == null ? void 0 : e.map((a) => ze(a, o));
406
- return Ke(n) && r ? n == null ? void 0 : n.join(r) : s !== !0 && (n == null ? void 0 : n.length) <= 1 ? n == null ? void 0 : n[0] : n;
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;
407
426
  }
408
- const ge = {
427
+ const vt = {
409
428
  includeFieldAttributes: !1,
410
- ...Se
411
- }, Xe = (e, t) => {
412
- const { includeFieldAttributes: r, ...s } = {
413
- ...ge,
429
+ ...St
430
+ }, ne = (e, t) => {
431
+ const { includeFieldAttributes: s, ...n } = {
432
+ ...vt,
414
433
  ...t || {}
415
- }, { value: o, ...n } = e, a = Je(o, s), i = r === !0 && n || Array.isArray(r) && Object.fromEntries(
416
- Object.entries(n).filter(
417
- ([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)
418
437
  )
419
438
  ) || {};
420
- return r ? { ...i, value: a } : a;
421
- }, $ = {
422
- ...ge,
439
+ return s ? { ...a, value: o } : o;
440
+ }, G = {
441
+ ...vt,
423
442
  fieldAsList: !1,
424
443
  arrayOnSingleField: !1,
425
444
  overrideField: void 0
426
- }, Re = (e, t) => {
427
- const r = {
428
- ...$,
445
+ }, Mt = (e, t) => {
446
+ const s = {
447
+ ...G,
429
448
  ...t || {}
430
- }, { fieldAsList: s, arrayOnSingleField: o, overrideField: n } = r, a = n === !0 && s === !1, i = {};
449
+ }, { fieldAsList: n, arrayOnSingleField: r, overrideField: i } = s, o = i === !0 && n === !1, a = {};
431
450
  return e == null || e.forEach((c) => {
432
- const { name: p } = c, d = Xe(c, r), l = o === !0 ? D(d) : d, _ = i[p];
433
- _ ? a ? i[p] = d : i[p] = [D(_), D(d)].flat() : i[p] = l;
434
- }), s === !0 ? Object.values(i).flat() : i;
435
- }, be = {
436
- ...$,
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,
437
456
  includeGroupAttributes: !1,
438
457
  groupAsList: !1,
439
458
  arrayOnSingleGroup: !1,
440
459
  overrideGroup: void 0
441
- }, qe = (e, t) => {
442
- const r = {
443
- ...be,
460
+ }, ie = (e, t) => {
461
+ const s = {
462
+ ...Dt,
444
463
  ...t || {}
445
- }, { includeGroupAttributes: s } = r, o = Object.fromEntries(
446
- Object.entries(r).filter(
447
- ([l]) => Object.keys($).includes(l)
464
+ }, { includeGroupAttributes: n } = s, r = Object.fromEntries(
465
+ Object.entries(s).filter(
466
+ ([f]) => Object.keys(G).includes(f)
448
467
  )
449
- ), { field: n, group: a, ...i } = e, c = n && Re(n, o), p = a && Ne(a, r);
468
+ ), { field: i, group: o, ...a } = e, c = i && Mt(i, r), d = o && Ft(o, s);
450
469
  return {
451
- ...s === !0 && i || Array.isArray(s) && Object.fromEntries(
452
- Object.entries(i).filter(
453
- ([l]) => s.includes(l)
470
+ ...n === !0 && a || Array.isArray(n) && Object.fromEntries(
471
+ Object.entries(a).filter(
472
+ ([f]) => n.includes(f)
454
473
  )
455
474
  ) || {},
456
- ...o != null && o.fieldAsList ? c && { field: c } || {} : c,
457
- ...r != null && r.groupAsList ? p && { group: p } || {} : p
475
+ ...r != null && r.fieldAsList ? c && { field: c } || {} : c,
476
+ ...s != null && s.groupAsList ? d && { group: d } || {} : d
458
477
  };
459
- }, X = be, Ne = (e, t) => {
460
- const r = { ...X, ...t || {} }, { groupAsList: s, arrayOnSingleGroup: o, overrideGroup: n } = r, a = n === !0 && s === !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 = {};
461
480
  return e == null || e.forEach((c) => {
462
- const { name: p } = c, d = qe(c, r), l = o === !0 ? D(d) : d, _ = i[p];
463
- _ ? a ? i[p] = d : i[p] = [
464
- D(_),
465
- D(d)
466
- ].flat() : i[p] = l;
467
- }), s ? Object.values(i).flat() : i;
468
- }, De = {
469
- ...X,
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,
470
489
  includeTimespanAttributes: !1,
471
490
  flat: !1,
472
491
  arrayOnSingle: !1,
473
492
  arrayOnSingleValue: !0,
474
493
  arrayOnSingleGroup: void 0,
475
494
  arrayOnSingleField: void 0
476
- }, Qe = (e, t) => {
477
- const r = {
478
- ...De,
495
+ }, ae = (e, t) => {
496
+ const s = {
497
+ ...Nt,
479
498
  ...t || {}
480
- }, { includeTimespanAttributes: s, arrayOnSingle: o, flat: n } = r, a = Object.fromEntries(
481
- Object.entries(t).map(([u, m]) => {
482
- if (Object.keys(X).includes(u))
483
- return ["arrayOnSingleGroup", "arrayOnSingleField", "arrayOnSingleValue"].includes(u) && (m !== void 0 ? m : o === !0) ? [u, !0] : ["overrideGroup", "overrideField"].includes(u) && (m !== void 0 ? m : n === !0) ? [u, !0] : [u, m];
484
- }).filter((u) => !!u)
485
- ), i = Object.fromEntries(
486
- Object.entries(t).map(([u, m]) => {
487
- if (Object.keys($).includes(u))
488
- return ["arrayOnSingleField", "arrayOnSingleValue"].includes(u) && (m !== void 0 ? m : o === !0) ? [u, !0] : ["overrideField"].includes(u) && (m !== void 0 ? m : n === !0) ? [u, !0] : [u, m];
489
- }).filter((u) => !!u)
490
- ), { field: c, group: p, ...d } = e || {}, l = c && Re(c, i), _ = p && Ne(p, 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);
491
510
  return {
492
- ...s === !0 && d || Array.isArray(s) && Object.fromEntries(
493
- Object.entries(d).filter(
494
- ([u]) => s.includes(u)
511
+ ...n === !0 && u || Array.isArray(n) && Object.fromEntries(
512
+ Object.entries(u).filter(
513
+ ([l]) => n.includes(l)
495
514
  )
496
515
  ) || {},
497
- ...i != null && i.fieldAsList ? { field: l } : l,
498
- ...a != null && a.groupAsList ? { group: _ } : _
516
+ ...a != null && a.fieldAsList ? { field: f } : f,
517
+ ...o != null && o.groupAsList ? { group: m } : m
499
518
  };
500
- }, q = {
501
- ...De,
519
+ }, Z = {
520
+ ...Nt,
502
521
  timespanAsList: !1,
503
522
  joinTimespan: "_",
504
523
  sortTimespan: !1,
505
524
  flat: !1,
506
525
  flatTimespan: void 0
507
- }, Me = (e, t) => {
508
- const r = {
509
- ...q,
526
+ }, Ct = (e, t) => {
527
+ const s = {
528
+ ...Z,
510
529
  ...t || {}
511
- }, { timespanAsList: s, joinTimespan: o, sortTimespan: n, flat: a, flatTimespan: i, ...c } = r, p = { flat: a, ...c };
512
- n && e.sort(Ye);
513
- const d = (i !== void 0 ? i === !0 : a === !0) && s === !1, l = {};
514
- return e == null || e.forEach((_) => {
515
- const { start: f, end: u } = _, m = d ? "flat" : [f, u].join(o), E = Qe(_, p), T = l[m];
516
- T ? d ? f === "-INF" && u === "+INF" ? l[m] = { ...oe(T), ...E } : l[m] = { ...E, ...oe(T) } : l[m] = [...D(T), E] : l[m] = E;
517
- }), s === !0 ? Object.values(l) : d ? Object.values(l).pop() : l;
518
- }, Ze = {
519
- ...q,
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,
520
539
  includeMetadataAttributes: !1,
521
540
  flat: !1
522
541
  };
523
- function et(e, t) {
524
- const r = {
525
- ...Ze,
542
+ function ce(e, t) {
543
+ const s = {
544
+ ...oe,
526
545
  ...t || {}
527
- }, { includeMetadataAttributes: s, flat: o } = r, { timespan: n = [], ...a } = e || {}, i = Object.fromEntries(
528
- Object.entries(t).map(([d, l]) => {
529
- if (Object.keys(q).includes(d))
530
- return ["onlyGeneric", "overrideGroup", "overrideField"].includes(d) && (l !== void 0 ? l : o === !0) ? [d, !0] : [d, l];
531
- }).filter((d) => !!d)
532
- ), c = Me(
533
- n,
534
- 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
535
554
  );
536
555
  return {
537
- ...s === !0 && {
538
- ...a,
539
- ...a.revision ? { revision: a.revision.split(",") } : {}
540
- } || Array.isArray(s) && Object.fromEntries(
541
- Object.entries(a).map(([d, l]) => {
542
- if (s.includes(d))
556
+ ...n === !0 && {
557
+ ...o,
558
+ ...o.revision ? { revision: o.revision.split(",") } : {}
559
+ } || Array.isArray(n) && Object.fromEntries(
560
+ Object.entries(o).map(([u, f]) => {
561
+ if (n.includes(u))
543
562
  return [
544
- d,
545
- d === "revision" && typeof l == "string" ? l.split(",") : l
563
+ u,
564
+ u === "revision" && typeof f == "string" ? f.split(",") : f
546
565
  ];
547
- }).filter((d) => !!d)
566
+ }).filter((u) => !!u)
548
567
  ) || {},
549
- ...i != null && i.timespanAsList ? { timespan: c } : c
568
+ ...a != null && a.timespanAsList ? { timespan: c } : c
550
569
  };
551
570
  }
552
- const Zt = (e) => {
571
+ const ds = (e) => {
553
572
  const { field: t = [] } = e || {};
554
- return M(t);
555
- }, Q = {
573
+ return F(t);
574
+ }, tt = {
556
575
  PAL: { denominator: 25, numerator: 1 },
557
576
  NTSC: { denominator: 3e4, numerator: 1001 },
558
577
  NTSC30: { denominator: 30, numerator: 1 },
@@ -560,7 +579,7 @@ const Zt = (e) => {
560
579
  59.94: { denominator: 6e4, numerator: 1001 },
561
580
  23.976: { denominator: 48e3, numerator: 2002 },
562
581
  23.98: { denominator: 48e3, numerator: 2002 }
563
- }, se = Object.keys(Q), ne = {
582
+ }, ot = Object.keys(tt), ct = {
564
583
  toText: {
565
584
  constant: !1,
566
585
  fraction: !1
@@ -570,7 +589,7 @@ const Zt = (e) => {
570
589
  rounded: !1
571
590
  }
572
591
  };
573
- class S {
592
+ class R {
574
593
  /**
575
594
  * Constructor for TimeBase
576
595
  *
@@ -578,8 +597,8 @@ class S {
578
597
  */
579
598
  constructor(t) {
580
599
  this.numerator = 1, this.denominator = 1;
581
- const { numerator: r = 1, denominator: s = 1 } = t || {};
582
- this.numerator = Number(r), this.denominator = Number(s);
600
+ const { numerator: s = 1, denominator: n = 1 } = t || {};
601
+ this.numerator = Number(s), this.denominator = Number(n);
583
602
  }
584
603
  /**
585
604
  * Get TimeBase in a constant representation (e.g. "PAL") if possible, otherwise undefined
@@ -587,9 +606,9 @@ class S {
587
606
  */
588
607
  toConstant() {
589
608
  let t;
590
- return Object.entries(Q).find((r) => {
591
- const [s, o] = r, { numerator: n, denominator: a } = o;
592
- return n === this.numerator && a === this.denominator ? (t = s, !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;
593
612
  }), t;
594
613
  }
595
614
  /**
@@ -604,13 +623,13 @@ class S {
604
623
  * @returns Text representation of the TimeBase
605
624
  */
606
625
  toText(t) {
607
- const { constant: r, fraction: s } = { ...ne.toText, ...t };
608
- if (r) {
609
- const n = this.toConstant();
610
- if (n)
611
- return n;
626
+ const { constant: s, fraction: n } = { ...ct.toText, ...t };
627
+ if (s) {
628
+ const i = this.toConstant();
629
+ if (i)
630
+ return i;
612
631
  }
613
- return s || this.numerator > 1 ? [this.denominator, this.numerator].join(":") : String(this.denominator);
632
+ return n || this.numerator > 1 ? [this.denominator, this.numerator].join(":") : String(this.denominator);
614
633
  }
615
634
  /**
616
635
  * Output TimeBase as frame rate (by default max 16 decimal places)
@@ -625,11 +644,11 @@ class S {
625
644
  * @return Rate of the TimeBase
626
645
  */
627
646
  toRate(t) {
628
- const r = this.denominator / this.numerator;
629
- if (Number.isInteger(r))
630
- return r;
631
- const { rounded: s, fixed: o } = { ...ne.toRate, ...t || {} };
632
- return s ? 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;
633
652
  }
634
653
  /**
635
654
  * Get TimeBase in a object representation
@@ -651,38 +670,38 @@ class S {
651
670
  return console.warn("Deprecated - use toObject instead"), this.toObject();
652
671
  }
653
672
  }
654
- const Z = (e) => {
673
+ const et = (e) => {
655
674
  if (e === void 0)
656
- return new S();
675
+ return new R();
657
676
  if (typeof e == "number")
658
- return new S({ denominator: e });
677
+ return new R({ denominator: e });
659
678
  if (typeof e == "string" && e.includes(":")) {
660
- const [t, r] = e.split(":");
661
- return new S({ denominator: t, numerator: r });
679
+ const [t, s] = e.split(":");
680
+ return new R({ denominator: t, numerator: s });
662
681
  }
663
- if (se.includes(e))
664
- return new S(Q[e]);
682
+ if (ot.includes(e))
683
+ return new R(tt[e]);
665
684
  if (!["string", "number"].includes(typeof e) || Number.isNaN(Number(e)))
666
685
  throw new Error(
667
- `timeBaseText must be a number or ${se.join(",")} - is ${JSON.stringify(
686
+ `timeBaseText must be a number or ${ot.join(",")} - is ${JSON.stringify(
668
687
  e
669
688
  )}`
670
689
  );
671
- return new S({ denominator: Number(e) });
672
- }, B = (e) => new S(e), j = (e) => e instanceof S ? e : typeof e == "string" || typeof e == "number" ? Z(e) : B(e), ee = (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) => {
673
692
  const t = e.toConstant();
674
693
  return t === "59.94" && 4 || ["NTSC", "29.97"].includes(t) && 2 || void 0;
675
- }, Fe = (e) => ee(e) > 0, ie = (e) => {
676
- const { samples: t, timeBase: r } = e, s = ee(r);
677
- if (!s)
694
+ }, wt = (e) => st(e) > 0, ut = (e) => {
695
+ const { samples: t, timeBase: s } = e, n = st(s);
696
+ if (!n)
678
697
  return 0;
679
- const o = r.toRate({ rounded: !0 }), n = 60 * o, a = 60 * o - s, i = 10 * (n - s) + s, c = Math.floor((t + 1) / i), p = 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(
680
699
  0,
681
- (t + 1) % i - n
682
- ), d = Math.floor(
683
- p / a
684
- ), _ = p % a > 0 ? s : 0;
685
- return c * 9 * s + d * s + _;
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;
686
705
  }, V = {
687
706
  conformTimeBase: {
688
707
  dropFrame: void 0,
@@ -697,24 +716,24 @@ const Z = (e) => {
697
716
  format: void 0
698
717
  }
699
718
  };
700
- class R {
719
+ class S {
701
720
  /**
702
721
  * Constructor for TimeCode
703
722
  *
704
723
  * @param timeCodeType Object to create TimeCode of
705
724
  * @param options Options for the timeCode
706
725
  */
707
- constructor(t, r) {
708
- this.samples = 0, this.timeBase = new S();
709
- const { samples: s, timeBase: o } = t || {};
710
- if (s !== void 0)
711
- if (typeof s == "number")
712
- this.samples = s;
713
- else if (typeof s == "string")
714
- s === "-INF" ? this.samples = -1 / 0 : s === "+INF" ? this.samples = 1 / 0 : this.samples = Number(s);
726
+ constructor(t, s) {
727
+ this.samples = 0, this.timeBase = new R();
728
+ const { samples: n, timeBase: r } = t || {};
729
+ if (n !== void 0)
730
+ if (typeof n == "number")
731
+ this.samples = n;
732
+ else if (typeof n == "string")
733
+ n === "-INF" ? this.samples = -1 / 0 : n === "+INF" ? this.samples = 1 / 0 : this.samples = Number(n);
715
734
  else
716
- throw new Error(`samples is not number/string/-Inf/+Inf is: ${s}`);
717
- o !== void 0 && (o instanceof S ? this.timeBase = o : this.timeBase = j(o)), this.dropFrame = (r == null ? void 0 : r.dropFrame) ?? Fe(this.timeBase), this.frameSeparator = (r == null ? void 0 : r.frameSeparator) ?? (this.dropFrame ? ";" : ":");
735
+ throw new Error(`samples is not number/string/-Inf/+Inf is: ${n}`);
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 ? ";" : ":");
718
737
  }
719
738
  /**
720
739
  * Return this TimeCode added with the supplied timeCodeType
@@ -734,11 +753,11 @@ class R {
734
753
  add(t) {
735
754
  if (!(t != null && t.timeBase) || (t == null ? void 0 : t.samples) === void 0)
736
755
  throw Error("Invalid timeCodeType, cannot be added");
737
- const { numerator: r, denominator: s } = (t == null ? void 0 : t.timeBase) || {};
738
- let o = t;
739
- (r !== this.timeBase.numerator || s !== this.timeBase.denominator) && (o = t.conformTimeBase(this.timeBase));
740
- const { samples: n } = o;
741
- return new R({ samples: this.samples + n, 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 });
742
761
  }
743
762
  /**
744
763
  * Return this TimeCode subtracted with the supplied timeCodeType
@@ -758,11 +777,11 @@ class R {
758
777
  subtract(t) {
759
778
  if (!(t != null && t.timeBase) || (t == null ? void 0 : t.samples) === void 0)
760
779
  throw Error("Invalid timeCodeType, cannot be subtracted");
761
- const { timeBase: { numerator: r, denominator: s } = {} } = t;
762
- let o = t;
763
- (r !== this.timeBase.numerator || s !== this.timeBase.denominator) && (o = t.conformTimeBase(this.timeBase));
764
- const { samples: n } = o;
765
- return new R({ samples: this.samples - n, 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 });
766
785
  }
767
786
  /**
768
787
  * Creates a new TimeCode instance with specified timeBase and samples adjusted to that.
@@ -776,25 +795,25 @@ class R {
776
795
  * @param options Explicitly set conform options, by default these are derived from `timeBase`
777
796
  * @returns A new TimeCode instance with the conformTo timeBase applied
778
797
  */
779
- conformTimeBase(t, r) {
780
- const s = t instanceof S ? t : j(t), o = (r == null ? void 0 : r.roundingMode) ?? "floor";
781
- if (!["floor", "ceil", "round"].includes(o))
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))
782
801
  throw Error(
783
- `Invalid mode selection "${o}". Has to be one of "${[
802
+ `Invalid mode selection "${r}". Has to be one of "${[
784
803
  "floor",
785
804
  "ceil",
786
805
  "round"
787
806
  ].join(", ")}"`
788
807
  );
789
- const n = Math[o](
790
- this.samples / (this.timeBase.toRate({ fixed: !1 }) / s.toRate({ fixed: !1 }))
791
- ), a = { ...V.conformTimeBase, ...r || {} };
792
- return new R(
808
+ const i = Math[r](
809
+ this.samples / (this.timeBase.toRate({ fixed: !1 }) / n.toRate({ fixed: !1 }))
810
+ ), o = { ...V.conformTimeBase, ...s || {} };
811
+ return new S(
793
812
  {
794
- samples: n,
795
- timeBase: s
813
+ samples: i,
814
+ timeBase: n
796
815
  },
797
- a
816
+ o
798
817
  );
799
818
  }
800
819
  /**
@@ -809,9 +828,9 @@ class R {
809
828
  * @returns Text representation of TimeCode
810
829
  */
811
830
  toText(t) {
812
- let r = `${this.samples}`;
813
- const s = { ...V.toText, ...t || {} }, o = this.timeBase.toText(s);
814
- 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;
815
834
  }
816
835
  /**
817
836
  * Get TimeCode in a units object representation
@@ -829,15 +848,15 @@ class R {
829
848
  seconds: 1 / 0,
830
849
  frames: 1 / 0
831
850
  };
832
- const t = this.samples + (this.dropFrame ? ie(this) : 0);
833
- let r = this.timeBase.toRate({ rounded: !0 });
834
- ["23.976", "23.98"].includes(this.timeBase.toConstant()) && (r = this.timeBase.toRate({ fixed: !0 }));
835
- const s = Math.floor(t / (3600 * r)), o = Math.floor(t / (60 * r)) % 60, n = 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);
836
855
  return {
837
- hours: s,
838
- minutes: o,
839
- seconds: n,
840
- frames: a
856
+ hours: n,
857
+ minutes: r,
858
+ seconds: i,
859
+ frames: o
841
860
  };
842
861
  }
843
862
  /**
@@ -848,12 +867,12 @@ class R {
848
867
  * @returns Time for the time code
849
868
  */
850
869
  toTime() {
851
- const t = this.samples + ie(this), { hours: r, minutes: s, seconds: o } = this.toUnits(), n = this.timeBase.toRate({ rounded: !0 }), a = t % n, i = Math.floor(1e3 * a / n), c = a / n;
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;
852
871
  return {
853
- hours: r,
854
- minutes: s,
855
- seconds: o,
856
- milliseconds: i,
872
+ hours: s,
873
+ minutes: n,
874
+ seconds: r,
875
+ milliseconds: a,
857
876
  partialSeconds: c
858
877
  };
859
878
  }
@@ -863,8 +882,8 @@ class R {
863
882
  * @returns Total seconds for the time code
864
883
  */
865
884
  toSeconds(t) {
866
- const { numerator: r, denominator: s } = this.timeBase, o = +(this.samples * r / s);
867
- return t != null && t.round ? Math.round(1e3 * o) / 1e3 : o;
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;
868
887
  }
869
888
  /**
870
889
  * Get TimeCode in a duration representation
@@ -886,70 +905,76 @@ class R {
886
905
  * @returns Duration representation of the TimeCode
887
906
  */
888
907
  toDuration(t) {
889
- const { format: r } = { ...V.toDuration, ...t || {} }, { hours: s, ...o } = this.toTime();
890
- let { minutes: n, seconds: a, milliseconds: i } = o;
891
- 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")
892
911
  throw Error("format has to be a string");
893
- const c = (_, f) => !r.includes(_) || !f.some((u) => r.includes(u) && r.lastIndexOf(_) > r.indexOf(u));
894
- 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"])))
895
914
  throw Error("format order is unsupported (has to be h, m, s then S)");
896
- if (!r)
897
- return `${s > 0 ? `${s}:${`${n}`.padStart(2, "0")}` : n}:${`${a}`.padStart(2, "0")}`;
898
- const p = (_, f) => {
899
- let u = _;
900
- for (; f[u] === f[u + 1]; )
901
- u += 1;
902
- return u - _ + 1;
903
- }, d = ["h", "m", "s", "S"], l = [];
904
- return [...r].forEach((_, f, u) => {
905
- switch (_) {
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) {
906
925
  case "h": {
907
- if (u[f - 1] === "h")
926
+ if (l[p - 1] === "h")
908
927
  break;
909
- const m = p(f, u);
910
- l.push(`${s}`.padStart(m, "0")), d.includes(u[f + m]) && l.push(":");
928
+ const h = d(p, l);
929
+ f.push(`${n}`.padStart(h, "0")), u.includes(l[p + h]) && f.push(":");
911
930
  break;
912
931
  }
913
932
  case "m": {
914
- if (u[f - 1] === "m")
933
+ if (l[p - 1] === "m")
915
934
  break;
916
- const m = p(f, u);
917
- r.includes("h") || (n += s * 60), l.push(`${n}`.padStart(m, "0")), d.includes(u[f + m]) && l.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(":");
918
937
  break;
919
938
  }
920
939
  case "s": {
921
- if (u[f - 1] === "s")
940
+ if (l[p - 1] === "s")
922
941
  break;
923
- const m = p(f, u);
924
- r.includes("m") || (a += n * 60), l.push(`${a}`.padStart(m, "0")), d.includes(u[f + m]) && l.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(".");
925
944
  break;
926
945
  }
927
946
  case "S": {
928
- if (u[f - 1] === "S")
947
+ if (l[p - 1] === "S")
929
948
  break;
930
- const m = p(f, u);
931
- r.includes("s") || (i += a * 1e3), l.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"));
932
951
  break;
933
952
  }
934
953
  default:
935
- l.push(_);
954
+ f.push(m);
936
955
  }
937
- }), l.join("");
956
+ }), f.join("");
938
957
  }
939
958
  /**
940
959
  * Get TimeCode in a smpte representation
941
960
  *
961
+ * @param {Object} options
962
+ * @param {boolean} options.uniformSeparators Use the frame separator for all separators in the smpte string
942
963
  * @returns Smpte representation of the TimeCode
943
964
  */
944
- toSmpte() {
965
+ toSmpte(t) {
966
+ const { uniformSeparators: s } = {
967
+ uniformSeparators: !1,
968
+ ...t
969
+ };
945
970
  if (this.samples === -1 / 0)
946
971
  return "00:00:00:00";
947
- const { hours: t, minutes: r, seconds: s, frames: o } = this.toUnits(), n = [
948
- 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"),
949
974
  r.toFixed().padStart(2, "0"),
950
- s.toFixed().padStart(2, "0")
951
- ].join(":"), a = Math.max(2, `${this.timeBase.toRate({ rounded: !0 }) - 1}`.length);
952
- return [n, `${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);
953
978
  }
954
979
  /**
955
980
  * Get TimeCode as a VidiCore TimeCodeType object
@@ -971,403 +996,403 @@ class R {
971
996
  return console.warn("Deprecated - use toObject instead"), this.toObject();
972
997
  }
973
998
  }
974
- const tt = (e, t) => {
975
- let r = Math.abs(e), s = Math.abs(t);
976
- for (; r && s && r !== s; )
977
- r > s ? [r, s] = [r - s, s] : [r, s] = [r, s - r];
978
- return r || s;
979
- }, rt = (e, t) => {
980
- const { timeBase: r, useGCD: s = !1, roundingMode: o, ...n } = t || {}, a = `${e}`.replace(/,/g, ".");
981
- if (Number.isNaN(+a))
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))
982
1007
  throw new Error(`seconds must be digits, is ${e}`);
983
- let i = 1, c;
984
- if (Number.isInteger(+a))
985
- c = +a * i;
1008
+ let a = 1, c;
1009
+ if (Number.isInteger(+o))
1010
+ c = +o * a;
986
1011
  else {
987
- const [, d] = a.split("."), l = Math.min((d == null ? void 0 : d.length) ?? 0, 16);
988
- i *= 10 ** l, c = Math.round(Number(a) * i);
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);
989
1014
  }
990
- if (r === void 0 && s) {
991
- const d = tt(i, c);
992
- c /= d, i /= d;
1015
+ if (s === void 0 && n) {
1016
+ const u = ue(a, c);
1017
+ c /= u, a /= u;
993
1018
  }
994
- const p = new R(
995
- { samples: c, timeBase: { denominator: i, numerator: 1 } },
996
- n
1019
+ const d = new S(
1020
+ { samples: c, timeBase: { denominator: a, numerator: 1 } },
1021
+ i
997
1022
  );
998
- return r !== void 0 ? p.conformTimeBase(r, { ...n, roundingMode: o }) : p;
999
- }, ot = ([e, t, r, s], o, n) => {
1000
- const a = n.toRate({ rounded: !0 }), i = ee(n);
1001
- 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)
1002
1027
  return 0;
1003
- const c = t % 10 !== 0, p = c && r === 0, d = e * (3600 * a - 54 * i), l = t * 60 * a - (t - Math.ceil(t / 10)) * i, _ = r * a - (c && r > 1 ? i : 0);
1004
- if (p && s < 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)
1005
1030
  throw new Error(
1006
- `Frame does not exist for ${n.toConstant() || n.toRate()} drop-frame`
1031
+ `Frame does not exist for ${i.toConstant() || i.toRate()} drop-frame`
1007
1032
  );
1008
- const f = p ? s - i : s, u = d + l + _ + f;
1009
- return o - u;
1010
- }, k = (e, t, r) => {
1011
- const [s, o, n, a] = e, i = t.toRate({ rounded: !0 }), c = s * 3600 * i + o * 60 * i + n * i + a;
1012
- return c - (r ? ot(e, c, t) : 0);
1013
- }, st = (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) => {
1014
1039
  const [t] = (e == null ? void 0 : e.match(/[^0-9:\-_]/)) || [];
1015
- let r = [];
1040
+ let s = [];
1016
1041
  if (t) {
1017
- const [o, n] = e.split(t);
1018
- r = [...o.split(":"), n];
1042
+ const [r, i] = e.split(t);
1043
+ s = [...r.split(":"), i];
1019
1044
  } else
1020
- r = e.split(":");
1021
- if (r.length !== 4)
1045
+ s = e.split(":");
1046
+ if (s.length !== 4)
1022
1047
  throw new Error('Invalid format, must be "##:##:##:##');
1023
- if (r.some((o) => Number.isNaN(o)))
1048
+ if (s.some((r) => Number.isNaN(r)))
1024
1049
  throw new Error("Invalid format, values must be numbers");
1025
- const s = t || ":";
1050
+ const n = t || ":";
1026
1051
  return {
1027
- smpteValues: r.map(Number),
1028
- smpteFrameSeparator: s
1052
+ smpteValues: s.map(Number),
1053
+ smpteFrameSeparator: n
1029
1054
  };
1030
- }, nt = ["error", "add", "ignore"], it = {
1055
+ }, me = ["error", "add", "ignore"], he = {
1031
1056
  exceedingMode: "error",
1032
1057
  timeBase: void 0,
1033
1058
  dropFrame: void 0,
1034
1059
  frameSeparator: void 0
1035
- }, at = (e, t) => {
1036
- const { exceedingMode: r, timeBase: s, ...o } = { ...it, ...t };
1060
+ }, pe = (e, t) => {
1061
+ const { exceedingMode: s, timeBase: n, ...r } = { ...he, ...t };
1037
1062
  if ([null, void 0].includes(e))
1038
1063
  throw new Error("smpte cannot be undefined or null");
1039
1064
  if (typeof e != "string")
1040
1065
  throw new Error(`smpte must be a string, is ${JSON.stringify(e)}`);
1041
- const { smpteValues: n, smpteFrameSeparator: a } = st(e), i = j(s), c = {
1042
- ...o,
1043
- frameSeparator: (o == null ? void 0 : o.frameSeparator) || a,
1044
- ...(o == null ? void 0 : o.dropFrame) === void 0 ? {
1045
- dropFrame: s !== 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)
1046
1071
  } : {}
1047
- }, p = i.toRate({ rounded: !0 }), d = Math.max(0, p - 1);
1048
- if (n.some((_) => _ < 0))
1072
+ }, d = a.toRate({ rounded: !0 }), u = Math.max(0, d - 1);
1073
+ if (i.some((m) => m < 0))
1049
1074
  throw new Error("Negative values are not supported");
1050
- let l;
1051
- switch (r) {
1075
+ let f;
1076
+ switch (s) {
1052
1077
  case "error": {
1053
- const [_, f, u, m] = n;
1054
- if (_ >= 100 || f >= 60)
1078
+ const [m, p, l, h] = i;
1079
+ if (m >= 100 || p >= 60)
1055
1080
  throw Error("Minutes has to be less than 60");
1056
- if (u >= 60)
1081
+ if (l >= 60)
1057
1082
  throw Error("Seconds has to be less than 60");
1058
- if (m > d)
1059
- throw Error(`Frames has to be less or equal to ${d}`);
1060
- l = k(n, 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);
1061
1086
  break;
1062
1087
  }
1063
1088
  case "ignore": {
1064
- const [_, f, u, m] = n, E = [
1065
- Math.min(100, _),
1066
- Math.min(59, f),
1067
- Math.min(59, u),
1068
- 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)
1069
1094
  ];
1070
- l = k(
1071
- E,
1072
- i,
1095
+ f = H(
1096
+ g,
1097
+ a,
1073
1098
  c == null ? void 0 : c.dropFrame
1074
1099
  );
1075
1100
  break;
1076
1101
  }
1077
1102
  case "add": {
1078
- l = k(n, i, c == null ? void 0 : c.dropFrame);
1103
+ f = H(i, a, c == null ? void 0 : c.dropFrame);
1079
1104
  break;
1080
1105
  }
1081
1106
  default:
1082
- throw new Error(`Invalid exceedingMode, options are ${JSON.stringify(nt)}`);
1107
+ throw new Error(`Invalid exceedingMode, options are ${JSON.stringify(me)}`);
1083
1108
  }
1084
- return new R({ samples: l, timeBase: i }, c);
1085
- }, ct = {
1109
+ return new S({ samples: f, timeBase: a }, c);
1110
+ }, _e = {
1086
1111
  timeBase: void 0,
1087
1112
  dropFrame: void 0,
1088
1113
  frameSeparator: void 0
1089
1114
  }, U = (e, t) => {
1090
- const { timeBase: r, ...s } = { ...ct, ...t };
1091
- let o;
1115
+ const { timeBase: s, ...n } = { ..._e, ...t };
1116
+ let r;
1092
1117
  if (e === void 0)
1093
- o = { samples: 0 };
1118
+ r = { samples: 0 };
1094
1119
  else if (typeof e == "number")
1095
- o = { samples: e };
1120
+ r = { samples: e };
1096
1121
  else if (e.includes("@")) {
1097
- const [a, i] = e.split("@");
1098
- o = { samples: Number(a), timeBase: Z(i) };
1122
+ const [o, a] = e.split("@");
1123
+ r = { samples: Number(o), timeBase: et(a) };
1099
1124
  } else
1100
- e === "-INF" ? o = { samples: -1 / 0 } : e === "+INF" ? o = { samples: 1 / 0 } : o = { samples: Number(e) };
1101
- if (Number.isNaN(o == null ? void 0 : o.samples) || o.timeBase && !(o.timeBase instanceof S))
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))
1102
1127
  throw new Error(`timeCodeText must be a number or sample@timeBase - is ${e}`);
1103
- const n = new R(o, s);
1104
- return r ? n.conformTimeBase(j(r), s) : n;
1105
- }, dt = {
1128
+ const i = new S(r, n);
1129
+ return s ? i.conformTimeBase($(s), n) : i;
1130
+ }, Te = {
1106
1131
  dropFrame: void 0,
1107
1132
  frameSeparator: void 0
1108
- }, L = (e, t) => new R(e, { ...dt, ...t }), ut = (e) => !!e.match(/^(\d\d+):(\d\d+):(\d\d+)(:|;|\.|,)(\d\d+)$/), lt = (e) => !Number.isNaN(Number(e)), x = (e, t) => {
1109
- if (e instanceof R)
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)
1110
1135
  return e;
1111
1136
  if (typeof e != "string" && typeof e != "number")
1112
- return L(e, t);
1113
- if (typeof e == "string" && ut(e))
1114
- return at(e, t);
1115
- if (["string", "number"].includes(typeof e) && lt(e))
1116
- return rt(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);
1117
1142
  if (typeof e == "string")
1118
1143
  return U(e, t);
1119
1144
  };
1120
- function ae({ hours: e = 0, minutes: t = 0, seconds: r = 0, partialSeconds: s = 0 }) {
1121
- const o = e.toFixed().padStart(2, "0"), n = t.toFixed().padStart(2, "0"), a = r.toFixed().padStart(2, "0"), i = (s * 10).toFixed().padStart(3, "0");
1122
- return `${o}:${n}:${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}`;
1123
1148
  }
1124
- const _t = {
1149
+ const Ae = {
1125
1150
  subtitleGroup: "stl_subtitle",
1126
1151
  subtitleField: "stl_text"
1127
- }, er = (e, t) => {
1128
- const { subtitleGroup: r, subtitleField: s } = { ..._t, ...t || {} }, { timespan: o = [] } = e || {};
1129
- if (o.length === 0)
1152
+ }, fs = (e, t) => {
1153
+ const { subtitleGroup: s, subtitleField: n } = { ...Ae, ...t || {} }, { timespan: r = [] } = e || {};
1154
+ if (r.length === 0)
1130
1155
  return "";
1131
- const a = Me(o, {
1156
+ const o = Ct(r, {
1132
1157
  includeTimespanAttributes: !0,
1133
1158
  sortTimespan: !0,
1134
1159
  timespanAsList: !0,
1135
1160
  overrideGroup: !0,
1136
1161
  joinValue: ","
1137
- }).map((i) => {
1162
+ }).map((a) => {
1138
1163
  const {
1139
1164
  start: c,
1140
- end: p,
1141
- [r]: { [s]: d } = {}
1142
- } = (Array.isArray(i) ? i[0] : i) || {};
1143
- if (!d)
1165
+ end: d,
1166
+ [s]: { [n]: u } = {}
1167
+ } = (Array.isArray(a) ? a[0] : a) || {};
1168
+ if (!u)
1144
1169
  return "";
1145
- const l = ae(U(c).toTime()), _ = ae(U(p).toTime());
1146
- return `${l} --> ${_} line:0%\r${d}\r`;
1170
+ const f = lt(U(c).toTime()), m = lt(U(d).toTime());
1171
+ return `${f} --> ${m} line:0%\r${u}\r`;
1147
1172
  });
1148
- if (a.some((i) => !!i))
1173
+ if (o.some((a) => !!a))
1149
1174
  return `WEBVTT
1150
1175
 
1151
1176
 
1152
- ${a.join(`
1177
+ ${o.join(`
1153
1178
  `)}`;
1154
- }, mt = { count: !0, exclude: !0 }, tr = (e = [], t = {}) => {
1155
- const r = { ...mt, ...t }, { count: s, exclude: o } = r;
1156
- return e.map((n) => typeof n == "string" ? {
1157
- field: n,
1158
- name: n,
1159
- count: s,
1160
- ...o === !0 ? { exclude: [n] } : {}
1161
- } : n);
1162
- }, rr = (e = []) => e == null ? void 0 : e.map(({ name: t, field: r, count: s, range: o }) => ({
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,
1184
+ count: n,
1185
+ ...r === !0 ? { exclude: [i] } : {}
1186
+ } : i);
1187
+ }, hs = (e = []) => e == null ? void 0 : e.map(({ name: t, field: s, count: n, range: r }) => ({
1163
1188
  facetName: t,
1164
- fieldName: r,
1165
- count: s == null ? void 0 : s.reduce((n, { fieldValue: a, value: i }) => ({ ...n, [a]: i }), {}),
1166
- ...o ? {
1167
- range: o.map(({ value: n, start: a, end: i }) => ({
1168
- start: Number.isNaN(+a) ? a : Number(a),
1169
- end: Number.isNaN(+i) ? i : Number(i),
1170
- count: Number(n) || 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
1171
1196
  }))
1172
1197
  } : {}
1173
- })), or = (e = []) => {
1198
+ })), ps = (e = []) => {
1174
1199
  const t = {};
1175
- return e.forEach(({ name: r, field: s, count: o }) => {
1176
- t[r || s] = o.reduce(
1177
- (n, { fieldValue: a, value: i }) => ({ ...n, [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 }),
1178
1203
  {}
1179
1204
  );
1180
1205
  }), t;
1181
- }, ye = {
1206
+ }, Bt = {
1182
1207
  arrayOnSingle: !0,
1183
1208
  joinValue: void 0,
1184
1209
  timespanAsList: !1
1185
- }, H = (e, t) => {
1210
+ }, Y = (e, t) => {
1186
1211
  const {
1187
- arrayOnSingle: r = !0,
1188
- joinValue: s = void 0,
1189
- timespanAsList: o = !1
1190
- } = { ...ye, ...t || {} }, { field: n = [], start: a, end: i } = e || {}, c = o ? { start: a, end: i } : {};
1191
- return n.reduce((d, l) => {
1192
- const { name: _, value: f = [] } = l;
1193
- if (f.length === 0)
1194
- return d;
1195
- let u;
1196
- return r === !1 && f.length === 1 ? [u] = f : s ? u = f.join(s) : u = f, { ...d, [_]: u };
1212
+ arrayOnSingle: s = !0,
1213
+ joinValue: n = void 0,
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 };
1197
1222
  }, c);
1198
- }, pt = {
1199
- ...ye,
1223
+ }, Oe = {
1224
+ ...Bt,
1200
1225
  timespanAsList: !1,
1201
1226
  joinTimespan: "_",
1202
1227
  flat: !1,
1203
1228
  flatTimespan: !1
1204
- }, sr = (e = [], t) => {
1229
+ }, _s = (e = [], t) => {
1205
1230
  const {
1206
- timespanAsList: r,
1207
- joinTimespan: s = "_",
1208
- flat: o,
1209
- flatTimespan: n,
1210
- ...a
1211
- } = { ...pt, ...t || {} };
1212
- return r === !0 ? e.map(
1213
- (i) => H(i, { ...a, timespanAsList: r })
1214
- ) : o === !0 || n === !0 ? e.reduce(
1215
- (i, c) => ({ ...i, ...H(c, t) }),
1231
+ timespanAsList: s,
1232
+ joinTimespan: n = "_",
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) }),
1216
1241
  {}
1217
1242
  ) : e.reduce(
1218
- (i, c) => ({
1219
- ...i,
1220
- [[c.start, c.end].join(s)]: H(
1243
+ (a, c) => ({
1244
+ ...a,
1245
+ [[c.start, c.end].join(n)]: Y(
1221
1246
  c,
1222
1247
  t
1223
1248
  )
1224
1249
  }),
1225
1250
  {}
1226
1251
  );
1227
- }, ft = (e, t) => {
1228
- const r = x(t).toSeconds(), { thumbnails: s = {} } = e || {}, { uri: o = [] } = s, n = o.map((i) => {
1229
- const c = i.split("/").pop().split("?").shift();
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();
1230
1255
  return U(c).toSeconds();
1231
- }), a = n.reduce(
1232
- (i, c, p) => Math.abs(c - r) < Math.abs(n[i] - r) ? p : i,
1256
+ }), o = i.reduce(
1257
+ (a, c, d) => Math.abs(c - s) < Math.abs(i[a] - s) ? d : a,
1233
1258
  0
1234
1259
  );
1235
- return o[a];
1236
- }, Et = {
1260
+ return r[o];
1261
+ }, Re = {
1237
1262
  includeGroupMetadata: !1,
1238
1263
  flatEvents: !1,
1239
1264
  includeEntityType: !1,
1240
1265
  includeNearestThumbnail: !1
1241
- }, Tt = ({
1266
+ }, ye = ({
1242
1267
  start: e,
1243
1268
  end: t,
1244
- group: r = [{ id: "unknown", name: "unknown" }]
1269
+ group: s = [{ id: "unknown", name: "unknown" }]
1245
1270
  }) => {
1246
- const [{ id: s, name: o }] = r, n = x(e).toSeconds(), a = x(t).toSeconds();
1247
- return { start: e, end: t, startSeconds: n, endSeconds: a, group: { uuid: s, name: o } };
1248
- }, nr = (e = {}, t) => {
1249
- const { entry: r = [] } = e, s = {
1250
- ...Et,
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,
1251
1276
  ...t || {}
1252
- }, { includeGroupMetadata: o, flatEvents: n, includeEntityType: a, includeNearestThumbnail: i } = s, c = r.map((p) => {
1253
- const { type: d, item: { metadata: l = {}, id: _, thumbnails: f = {} } = {}, timespan: u, item: m } = p;
1254
- let E = u.map(
1255
- (T) => Tt(T)
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)
1256
1281
  );
1257
- if (i && d === "Item" && f.uri && (E = E.map((T) => {
1258
- const { start: h } = T, I = ft(m, x(h));
1259
- return { ...T, thumbnail: I };
1260
- })), o && d === "Item") {
1261
- const { timespan: T = [] } = l, h = T.flatMap(
1262
- (I) => I.group
1282
+ if (a && u === "Item" && p.uri && (g = g.map((E) => {
1283
+ const { start: A } = E, O = be(h, j(A));
1284
+ return { ...E, thumbnail: O };
1285
+ })), r && u === "Item") {
1286
+ const { timespan: E = [] } = f, A = E.flatMap(
1287
+ (O) => O.group
1263
1288
  );
1264
- if (h.length > 0) {
1265
- const I = E.map((A) => {
1289
+ if (A.length > 0) {
1290
+ const O = g.map((I) => {
1266
1291
  const {
1267
- group: { uuid: O }
1268
- } = A, [N] = O.split("/"), { field: F = [], group: y = [] } = h.find(
1269
- ({ uuid: b }) => b === N
1292
+ group: { uuid: b }
1293
+ } = I, [M] = b.split("/"), { field: N = [], group: C = [] } = A.find(
1294
+ ({ uuid: v }) => v === M
1270
1295
  );
1271
1296
  return {
1272
- ...A,
1297
+ ...I,
1273
1298
  group: {
1274
- ...A.group,
1275
- field: F,
1276
- group: y
1299
+ ...I.group,
1300
+ field: N,
1301
+ group: C
1277
1302
  }
1278
1303
  };
1279
1304
  });
1280
1305
  return {
1281
1306
  entityType: "Item",
1282
- entityId: _,
1283
- events: I.sort((A, O) => A.startSeconds - O.startSeconds),
1284
- ...a ? { itemType: m } : {}
1307
+ entityId: m,
1308
+ events: O.sort((I, b) => I.startSeconds - b.startSeconds),
1309
+ ...o ? { itemType: h } : {}
1285
1310
  };
1286
1311
  }
1287
1312
  }
1288
1313
  return {
1289
- entityType: d === "Item" ? "Item" : "Collection",
1290
- entityId: _,
1291
- events: E.sort((T, h) => T.startSeconds - h.startSeconds),
1292
- ...a && d === "Item" ? { itemType: m } : {},
1293
- ...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 } : {}
1294
1319
  };
1295
1320
  });
1296
- return n ? c.flatMap(
1297
- ({ events: p, entityType: d, entityId: l, itemType: _, collectionType: f }) => p.map(
1298
- (u) => ({
1299
- ...u,
1300
- entityType: d,
1301
- entityId: l,
1302
- ..._ && { itemType: _ },
1303
- ...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 }
1304
1329
  })
1305
1330
  )
1306
- ).sort((p, d) => p.startSeconds - d.startSeconds) : c;
1307
- }, ir = (e = "NOW") => {
1331
+ ).sort((d, u) => d.startSeconds - u.startSeconds) : c;
1332
+ }, gs = (e = "NOW") => {
1308
1333
  if (e.startsWith("NOW")) {
1309
1334
  if (e === "NOW")
1310
1335
  return /* @__PURE__ */ new Date();
1311
- const t = e[3], r = Number(e.match(/(\d+)/)[0]), s = e.match(/(\d.*)/)[0].replace(/\d/g, ""), o = /* @__PURE__ */ new Date();
1312
- switch (s) {
1336
+ const t = e[3], s = Number(e.match(/(\d+)/)[0]), n = e.match(/(\d.*)/)[0].replace(/\d/g, ""), r = /* @__PURE__ */ new Date();
1337
+ switch (n) {
1313
1338
  case "HOUR":
1314
1339
  case "HOURS":
1315
- 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);
1316
1341
  break;
1317
1342
  case "DAY":
1318
1343
  case "DAYS":
1319
- 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);
1320
1345
  break;
1321
1346
  case "MONTH":
1322
1347
  case "MONTHS":
1323
- 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);
1324
1349
  break;
1325
1350
  case "YEAR":
1326
1351
  case "YEARS":
1327
- 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);
1328
1353
  break;
1329
1354
  }
1330
- return o;
1355
+ return r;
1331
1356
  }
1332
1357
  return new Date(e);
1333
- }, G = (e) => {
1334
- const { property: t = [], ...r } = e || {};
1335
- return { ...M(t), ...r };
1336
- }, ht = (e) => G(e), At = (e) => G(e), It = { kB: "kHz", B: "Hz", mB: "mHz" }, ce = { kB: "kbps", B: "bps", MB: "mbps" }, Ot = (e) => {
1337
- var E;
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;
1338
1363
  const {
1339
1364
  timeBase: t,
1340
- channelCount: r,
1341
- codec: s,
1342
- mediaInfo: o,
1343
- bitrate: n,
1344
- metadata: a
1345
- } = e, i = ht(o), {
1365
+ channelCount: s,
1366
+ codec: n,
1367
+ mediaInfo: r,
1368
+ bitrate: i,
1369
+ metadata: o
1370
+ } = e, a = Se(r), {
1346
1371
  Format: c,
1347
- Resolution: p,
1348
- Bit_rate_mode: d
1349
- } = i, l = M(a || []), _ = t != null && t.denominator ? ((t == null ? void 0 : t.denominator) || 1) / ((t == null ? void 0 : t.numerator) || 1) : void 0, f = _ !== void 0 ? v(_, {
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, {
1350
1375
  base: 10,
1351
1376
  round: 1,
1352
- symbols: It
1377
+ symbols: Me
1353
1378
  }) : void 0;
1354
- let u, m;
1355
- return n !== void 0 && (u = v(n, { round: 2, symbols: ce }), m = Number(
1356
- (E = v(n, { exponent: 1, symbols: ce }).split(" kbps")) == null ? void 0 : E[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]
1357
1382
  )), {
1358
1383
  audioFormat: c,
1359
- audioCodec: s,
1360
- audioSamplerate: f,
1361
- audioSamplerateSamples: _,
1362
- audioBitDepth: p,
1363
- audioBitrate: u,
1364
- audioBitrateKbps: m,
1365
- audioBitRateMode: d,
1366
- audioChannels: r,
1367
- audioMediaInfo: i,
1368
- audioMetadata: l
1384
+ audioCodec: n,
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
1369
1394
  };
1370
- }, ar = {
1395
+ }, Es = {
1371
1396
  /** Just created, not used. */
1372
1397
  NONE: "NONE",
1373
1398
  /** Discovered or created, not yet marked as finished. */
@@ -1390,217 +1415,217 @@ ${a.join(`
1390
1415
  ARCHIVED: "ARCHIVED",
1391
1416
  /** File will be synchronized by multi-site agent. */
1392
1417
  AWAITING_SYNC: "AWAITING_SYNC"
1393
- }, ve = (e) => {
1418
+ }, xt = (e) => {
1394
1419
  const {
1395
1420
  uri: t = [],
1396
- size: r,
1397
- hash: s,
1398
- path: o,
1399
- id: n,
1400
- storage: a
1401
- } = e, [i] = t, c = r !== void 0 ? v(r, { base: 2, standard: "jedec" }) : "", p = (o == null ? void 0 : o.split("/")) || [], d = p.pop() || "", l = p.map((_) => `${_}/`).join("") || void 0;
1421
+ size: s,
1422
+ hash: n,
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;
1402
1427
  return {
1403
- uri: i,
1404
- hash: s,
1428
+ uri: a,
1429
+ hash: n,
1405
1430
  fileSize: c,
1406
- fileSizeBytes: r,
1407
- path: o,
1408
- fileName: d,
1409
- fileId: n,
1410
- storageId: a,
1411
- folderPath: l
1431
+ fileSizeBytes: s,
1432
+ path: r,
1433
+ fileName: u,
1434
+ fileId: i,
1435
+ storageId: o,
1436
+ folderPath: f
1412
1437
  };
1413
- }, St = (e = {}) => {
1414
- const { file: t, mediaInfo: r, metadata: s = [] } = e, o = M(s), n = G(r);
1415
- let a = { binaryMetadata: o, binaryMediaInfo: n };
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 };
1416
1441
  if (t) {
1417
- const [i] = t, c = ve(i);
1418
- a = {
1419
- ...a,
1442
+ const [a] = t, c = xt(a);
1443
+ o = {
1444
+ ...o,
1420
1445
  ...c
1421
1446
  };
1422
1447
  }
1423
- return a;
1424
- }, gt = (e = {}) => {
1448
+ return o;
1449
+ }, Ne = (e = {}) => {
1425
1450
  const {
1426
1451
  mediaInfo: t,
1427
- metadata: r,
1428
- file: s,
1429
- duration: o,
1430
- startTimestamp: n,
1431
- startTimecode: a,
1432
- timeCodeTimeBase: i
1433
- } = e, c = M(r || []), p = G(t);
1434
- let { Format: d } = p;
1452
+ metadata: s,
1453
+ file: n,
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;
1435
1460
  const {
1436
- Video_Format_List: l,
1437
- Audio_Format_List: _,
1438
- Text_Format_List: f
1439
- } = p;
1440
- if (d === void 0) {
1441
- const { format: m } = e;
1442
- d = m, m && m.includes(",") && ([d] = m.split(","));
1443
- }
1444
- let u = {
1445
- containerFormat: d,
1446
- videoFormat: l,
1447
- audioFormat: _,
1448
- 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,
1449
1474
  containerMetadata: c,
1450
- containerMediaInfo: p
1475
+ containerMediaInfo: d
1451
1476
  };
1452
- if (c.componentOriginalFilename && (u.originalFilename = c.componentOriginalFilename), o !== void 0 && o.samples !== 0) {
1453
- const m = L(o);
1454
- u.durationTimeCode = m.toObject(), u.duration = m.toDuration();
1455
- }
1456
- if (n && (u.startTimestamp = L(n).toObject()), a !== void 0 && i && (u.startTimecode = L({
1457
- samples: a,
1458
- timeBase: i
1459
- })), s) {
1460
- const [m] = s, E = ve(m);
1461
- u = {
1462
- ...u,
1463
- ...E
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();
1480
+ }
1481
+ if (i && (l.startTimestamp = P(i).toObject()), o !== void 0 && a && (l.startTimecode = P({
1482
+ samples: o,
1483
+ timeBase: a
1484
+ })), n) {
1485
+ const [h] = n, g = xt(h);
1486
+ l = {
1487
+ ...l,
1488
+ ...g
1464
1489
  };
1465
1490
  }
1466
- return u;
1467
- }, de = { kB: "kbps", B: "bps", MB: "mbps" }, Rt = (e = {}) => {
1468
- var W;
1491
+ return l;
1492
+ }, ft = { kB: "kbps", B: "bps", MB: "mbps" }, Ce = (e = {}) => {
1493
+ var k;
1469
1494
  const {
1470
1495
  codec: t,
1471
- bitrate: r,
1472
- fieldOrder: s,
1473
- resolution: o,
1474
- mediaInfo: n,
1475
- metadata: a = []
1476
- } = e, i = At(n), c = M(a), {
1477
- Format: p,
1478
- "Frame rate": d,
1479
- "Color space": l,
1480
- "Color primaries": _,
1481
- Colorimetry: f
1482
- } = i;
1483
- let u;
1484
- const { averageFrameRate: m, realBaseFrameRate: E } = e;
1485
- E !== void 0 ? u = B({
1486
- numerator: E.denominator,
1487
- denominator: E.numerator
1488
- }) : d !== void 0 ? u = Z(d) : m !== void 0 && (u = B({
1489
- numerator: m.denominator,
1490
- denominator: m.numerator
1496
+ bitrate: s,
1497
+ fieldOrder: n,
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
1491
1516
  }));
1492
- let { "Frame count": T } = i;
1493
- if (T === void 0) {
1494
- const { numberOfPackets: re } = e;
1495
- re !== void 0 && (T = re.toString());
1496
- }
1497
- let h, I, A;
1498
- T && u && (h = L({ samples: T, timeBase: u }), I = h.timeBase.toConstant() || h.timeBase.toRate(), A = h.toSmpte());
1499
- const { height: O, width: N } = o || {}, F = K(o), y = `${N}x${O}`;
1500
- let b, w;
1501
- return r !== void 0 && (b = v(r, { round: 2, symbols: de }), w = Number(
1502
- (W = v(r, { exponent: 2, symbols: de }).split(" mbps")) == null ? void 0 : W[0]
1517
+ let { "Frame count": E } = a;
1518
+ if (E === void 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]
1503
1528
  )), {
1504
- videoFormat: p,
1505
- dimension: y,
1506
- frameRate: I,
1507
- height: O,
1508
- width: N,
1509
- timeBase: u,
1510
- timeCode: h,
1529
+ videoFormat: d,
1530
+ dimension: C,
1531
+ frameRate: O,
1532
+ height: b,
1533
+ width: M,
1534
+ timeBase: l,
1535
+ timeCode: A,
1511
1536
  videoCodec: t,
1512
- smpte: A,
1513
- videoBitrate: b,
1514
- videoBitrateMbps: w,
1515
- fieldOrder: s,
1516
- colorSpace: l,
1517
- chromaSubsampling: f,
1518
- aspectRatio: F,
1519
- colorPrimaries: _,
1537
+ smpte: I,
1538
+ videoBitrate: v,
1539
+ videoBitrateMbps: B,
1540
+ fieldOrder: n,
1541
+ colorSpace: f,
1542
+ chromaSubsampling: p,
1543
+ aspectRatio: N,
1544
+ colorPrimaries: m,
1520
1545
  videoMetadata: c,
1521
- videoMediaInfo: i
1546
+ videoMediaInfo: a
1522
1547
  };
1523
- }, te = (e = {}, t = {}) => {
1524
- let r = {};
1525
- const { priority: s = ["container", "video", "audio", "binary"] } = t, {
1526
- containerComponent: o,
1527
- videoComponent: n,
1528
- audioComponent: a,
1529
- binaryComponent: i,
1548
+ }, rt = (e = {}, t = {}) => {
1549
+ let s = {};
1550
+ const { priority: n = ["container", "video", "audio", "binary"] } = t, {
1551
+ containerComponent: r,
1552
+ videoComponent: i,
1553
+ audioComponent: o,
1554
+ binaryComponent: a,
1530
1555
  mimeType: c = [],
1531
- tag: p = []
1556
+ tag: d = []
1532
1557
  } = e;
1533
- [r.tag] = p, [r.mimeType] = c;
1534
- const d = (l, _) => Object.fromEntries(
1535
- [.../* @__PURE__ */ new Set([...Object.keys(_), ...Object.keys(l)])].map((f) => [
1536
- f,
1537
- _[f] ?? l[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]
1538
1563
  ])
1539
1564
  );
1540
- return s.reverse().forEach((l) => {
1541
- switch (l) {
1565
+ return n.reverse().forEach((f) => {
1566
+ switch (f) {
1542
1567
  case "container":
1543
- o && (r = d(
1544
- r,
1545
- gt(o)
1568
+ r && (s = u(
1569
+ s,
1570
+ Ne(r)
1546
1571
  ));
1547
1572
  break;
1548
1573
  case "video":
1549
- if (n) {
1550
- const [_] = n;
1551
- r = d(
1552
- r,
1553
- Rt(_)
1574
+ if (i) {
1575
+ const [m] = i;
1576
+ s = u(
1577
+ s,
1578
+ Ce(m)
1554
1579
  );
1555
1580
  }
1556
1581
  break;
1557
1582
  case "audio":
1558
- if (a) {
1559
- const [_] = a;
1560
- r = d(
1561
- r,
1562
- Ot(_)
1583
+ if (o) {
1584
+ const [m] = o;
1585
+ s = u(
1586
+ s,
1587
+ De(m)
1563
1588
  );
1564
1589
  }
1565
1590
  break;
1566
1591
  case "binary":
1567
- if (i) {
1568
- const [_] = i;
1569
- r = d(
1570
- r,
1571
- St(_)
1592
+ if (a) {
1593
+ const [m] = a;
1594
+ s = u(
1595
+ s,
1596
+ Fe(m)
1572
1597
  );
1573
1598
  }
1574
1599
  break;
1575
1600
  }
1576
- }), r;
1577
- }, C = {
1601
+ }), s;
1602
+ }, x = {
1578
1603
  PDF: "PDF",
1579
1604
  TEXT: "TEXT",
1580
1605
  MSWORD: "MSWORD",
1581
1606
  JSON: "JSON",
1582
1607
  XML: "XML"
1583
- }, g = {
1608
+ }, y = {
1584
1609
  IMAGE: "IMAGE",
1585
1610
  AUDIO: "AUDIO",
1586
1611
  VIDEO: "VIDEO",
1587
1612
  DOCUMENT: "DOCUMENT",
1588
1613
  BINARY: "BINARY"
1589
- }, cr = (e = {}) => {
1590
- const { mimeType: t } = e, r = Array.isArray(t) ? t[0] : t;
1591
- if (r) {
1592
- if (r.endsWith("/pdf"))
1593
- return C.PDF;
1594
- if (r.startsWith("text/"))
1595
- return C.TEXT;
1596
- if (r.endsWith("/msword"))
1597
- return C.MSWORD;
1598
- if (r.endsWith("/json"))
1599
- return C.JSON;
1600
- if (r.endsWith("/xml"))
1601
- return C.XML;
1602
- }
1603
- }, bt = [
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 = [
1604
1629
  "image/apng",
1605
1630
  "image/bmp",
1606
1631
  "image/gif",
@@ -1608,7 +1633,7 @@ ${a.join(`
1608
1633
  "image/x-icon",
1609
1634
  "image/png",
1610
1635
  "image/svg+xml"
1611
- ], Nt = ["video/mp4"], Dt = [
1636
+ ], Be = ["video/mp4"], xe = [
1612
1637
  "audio/mp4",
1613
1638
  "audio/mpeg",
1614
1639
  "audio/x-aac",
@@ -1619,58 +1644,58 @@ ${a.join(`
1619
1644
  "audio/ogg",
1620
1645
  "audio/webm",
1621
1646
  "audio/x-flac"
1622
- ], Mt = [...Nt, ...bt, ...Dt], Ft = ["http", "https"], yt = "video/mp4", vt = "video/quicktime", wt = "video/x-m4v", Ct = "MPEG-4", Lt = "mov", Bt = "h264", P = [
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 = [
1623
1648
  "__mp4",
1624
1649
  "__mp3_160k",
1625
1650
  "__png",
1626
1651
  "__jpeg",
1627
1652
  "__gif",
1628
1653
  "original"
1629
- ].reverse(), ue = ({ parsedShape: { tag: e } }, { parsedShape: { tag: t } }) => P.includes(e) || P.includes(t) ? P.indexOf(t) - P.indexOf(e) : e.toLowerCase().localeCompare(t.toLowerCase()), dr = (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) => {
1630
1655
  const {
1631
- allowedMimeTypes: r = Mt,
1632
- allowedMethods: s = Ft,
1633
- sortPriority: o = ue,
1634
- sourceKey: n = "src",
1635
- mimeTypeKey: a = "type",
1636
- 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",
1637
1662
  parsedShapeKey: c = "parsedShape"
1638
- } = t || {}, { shape: p = [] } = e || {}, d = p.reduce((l, _) => {
1639
- let f, u;
1640
- const m = te(_), { uri: E, mimeType: T, containerFormat: h, videoCodec: I } = m;
1641
- if (T && (f = T, (T === vt || T === wt) && (h === Ct || h === Lt) && I === Bt && (f = yt)), E)
1642
- if (s) {
1643
- const [A] = E.split("://");
1644
- s.includes(A) && (u = E);
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)
1667
+ if (n) {
1668
+ const [I] = g.split("://");
1669
+ n.includes(I) && (l = g);
1645
1670
  } else
1646
- u = E;
1647
- return u && r.includes(f) && l.push({
1648
- [n]: u,
1649
- [a]: f,
1650
- [i]: _,
1651
- [c]: m
1652
- }), l;
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;
1653
1678
  }, []);
1654
- return typeof o == "function" && d.sort(ue), d;
1655
- }, ur = (e) => {
1656
- const t = te(e), { mimeType: r, videoCodec: s, audioCodec: o } = t;
1657
- if (r) {
1658
- if (r.startsWith("audio/") && o !== void 0)
1659
- return g.AUDIO;
1660
- if (r.startsWith("video/")) {
1661
- if (s !== void 0)
1662
- return g.VIDEO;
1663
- if (o !== void 0)
1664
- return g.AUDIO;
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/")) {
1686
+ if (n !== void 0)
1687
+ return y.VIDEO;
1688
+ if (r !== void 0)
1689
+ return y.AUDIO;
1665
1690
  }
1666
- if (r.startsWith("image/"))
1667
- return g.IMAGE;
1668
- if (r.endsWith("/pdf") || r.startsWith("text/") || r.endsWith("/msword") || r.endsWith("/json") || r.endsWith("/xml"))
1669
- return g.DOCUMENT;
1670
- if (r.endsWith("/octet-stream"))
1671
- return g.BINARY;
1672
- }
1673
- }, we = "video/mp4", Ce = "video/quicktime", Le = "video/x-m4v", xt = "MPEG-4", Wt = "mov", Pt = "h264", jt = [we, Ce, Le], Be = [
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 = [
1674
1699
  "video/x-mxf-h264",
1675
1700
  "video/x-mxf-h264-aac",
1676
1701
  "video/x-mxf-h264-pcm_s24le",
@@ -1678,7 +1703,7 @@ ${a.join(`
1678
1703
  "video/x-mxf-mpeg2video-pcm_s16le",
1679
1704
  "video/x-mxf-prores-pcm_s16le",
1680
1705
  "video/x-mxf-h264-pcm_s16le"
1681
- ], Ut = [...jt, ...Be], $t = [
1706
+ ], Ke = [...Ye, ...kt], Je = [
1682
1707
  "audio/mp4",
1683
1708
  "audio/mpeg",
1684
1709
  "audio/x-aac",
@@ -1689,120 +1714,120 @@ ${a.join(`
1689
1714
  "audio/ogg",
1690
1715
  "audio/webm",
1691
1716
  "audio/x-flac"
1692
- ], Gt = [...Ut, ...$t], Vt = ["http", "https"], kt = ({
1717
+ ], qe = [...Ke, ...Je], Xe = ["http", "https"], Qe = ({
1693
1718
  streamingServers: e,
1694
1719
  url: t,
1695
- ending: r
1696
- }) => xe(e[0], window.btoa(t), `.${r}`), lr = (e, t) => {
1720
+ ending: s
1721
+ }) => $t(e[0], window.btoa(t), `.${s}`), bs = (e, t) => {
1697
1722
  const {
1698
- allowedMimeTypes: r = Gt,
1699
- allowedMethods: s = Vt,
1700
- streamingServers: o = []
1701
- } = t || {}, { shape: n = [] } = e || {}, { startTimeCode: a } = et(e == null ? void 0 : e.metadata, {
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, {
1702
1727
  flat: !0,
1703
1728
  arrayOnSingleValue: !1
1704
1729
  });
1705
- return n.reduce((c, p) => {
1706
- var N, F, y;
1707
- let d, l, _;
1708
- const f = te(p), { uri: u, mimeType: m, containerFormat: E, videoCodec: T } = f;
1709
- if (!(r != null && r.includes(m)) || !(s != null && s.includes((N = u == null ? void 0 : u.split("://")) == null ? void 0 : N[0])))
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])))
1710
1735
  return c;
1711
- if (_ = f.tag, !_) {
1712
- const b = (y = (F = m == null ? void 0 : m.split) == null ? void 0 : F.call(m, "/")) == null ? void 0 : y.pop(), w = c.filter((W) => W.label === b).length;
1713
- w === 0 ? _ = b : _ = b + (w + 1);
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);
1714
1739
  }
1715
- const { timeBase: h, startTimecode: I } = f, A = a ?? I, O = A && x(A);
1716
- return l = u, d = m, (m === Ce || m === Le) && (E === xt || E === Wt) && T === Pt && (d = we), o != null && o.length && Be.includes(m) && (l = kt({
1717
- url: u,
1718
- streamingServers: o,
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,
1719
1744
  ending: "mpd"
1720
- }), d = "application/dash+xml"), l && c.push({
1721
- src: l,
1722
- ...d ? { type: d } : {},
1723
- ..._ ? { label: _ } : {},
1724
- ...h ? { timeBase: h } : {},
1725
- ...O ? { startTimeCode: O } : {}
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 } : {}
1726
1751
  }), c;
1727
1752
  }, []);
1728
- }, Ht = (e) => {
1729
- const t = {}, { outputSetting: r = [] } = e || {};
1730
- if (r.length === 0)
1753
+ }, Ze = (e) => {
1754
+ const t = {}, { outputSetting: s = [] } = e || {};
1755
+ if (s.length === 0)
1731
1756
  return t;
1732
- const s = JSON.parse(r[0]), { Settings: { ContainerSettings: o, VideoDescription: n, AudioDescriptions: a } = {} } = s;
1733
- if (o && (t.containerFormat = o.Container), n) {
1734
- const { CodecSettings: i = {} } = n, { Codec: c, ...p } = 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;
1735
1760
  t.videoFormat = c;
1736
- const { Height: d, Width: l } = n;
1737
- t.height = d, t.width = l, d && l && (t.dimension = `${l}x${d}`, t.aspectRatio = K({ height: d, width: l }));
1738
- const [_] = Object.values(p);
1739
- if (_) {
1740
- t.fieldOrder = _.InterlaceMode, t.fieldOrder && t.fieldOrder.includes("TOP") && (t.fieldOrder = "interlaced"), t.videoBitrate = _.Bitrate;
1741
- const f = _.FramerateDenominator, u = _.FramerateNumerator, m = B({ denominator: u, numerator: f });
1742
- 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();
1743
1768
  }
1744
1769
  }
1745
- if (a && a.length > 0) {
1746
- const { CodecSettings: i = {} } = a[0], { Codec: c, ...p } = i;
1770
+ if (o && o.length > 0) {
1771
+ const { CodecSettings: a = {} } = o[0], { Codec: c, ...d } = a;
1747
1772
  t.audioFormat = c;
1748
- const [d] = Object.values(p);
1749
- 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);
1750
1775
  }
1751
1776
  return t;
1752
- }, _r = (e) => {
1753
- const t = {}, { description: r, format: s, audio: o, video: n, mediaconvert: a } = e || {};
1754
- if (a)
1755
- return { description: r, ...Ht(a) };
1756
- if (t.description = r, t.containerFormat = s, n) {
1757
- if (t.videoFormat = n.codec, t.videoBitrate = n.bitrate, n.framerate) {
1758
- const i = B(n.framerate);
1759
- 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();
1760
1785
  }
1761
- if (n.scaling) {
1762
- const { height: i, width: c } = n.scaling;
1763
- t.height = i, t.width = c, i && c && (t.dimension = `${c}x${i}`, t.aspectRatio = K({ 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 }));
1764
1789
  }
1765
1790
  }
1766
- if (o) {
1767
- const { codec: i, channel: c } = o;
1768
- 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);
1769
1794
  }
1770
1795
  return t;
1771
- }, Yt = (e) => {
1796
+ }, ts = (e) => {
1772
1797
  if (!e)
1773
1798
  return;
1774
1799
  const {
1775
1800
  name: t,
1776
- type: r,
1777
- defaultValue: s,
1778
- stringRestriction: o,
1779
- floatRestriction: n,
1780
- integerRestriction: a,
1781
- longRestriction: i,
1801
+ type: s,
1802
+ defaultValue: n,
1803
+ stringRestriction: r,
1804
+ floatRestriction: i,
1805
+ integerRestriction: o,
1806
+ longRestriction: a,
1782
1807
  data: c,
1783
- values: p,
1784
- system: d
1785
- } = e, { minLength: l, maxLength: _, pattern: f } = o || {}, { minInclusive: u, maxInclusive: m } = n || a || i || {}, E = ((p == null ? void 0 : p.field) || []).map(({ key: A, value: O }) => ({
1786
- label: O ?? A,
1787
- value: A
1788
- })), h = ((A) => Object.fromEntries(Object.entries(A).filter(([, O]) => O !== void 0)))({
1789
- min: u,
1790
- max: m,
1791
- minLength: l,
1792
- maxLength: _,
1793
- pattern: f ? new RegExp(f) : void 0
1794
- }), I = M(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);
1795
1820
  return {
1796
1821
  name: t,
1797
- type: r,
1798
- defaultValue: s,
1799
- required: u !== void 0 || l !== void 0 && l > 0,
1800
- restrictions: h,
1801
- data: I,
1802
- options: E,
1803
- system: d === "true"
1822
+ type: s,
1823
+ defaultValue: n,
1824
+ required: l !== void 0 || f !== void 0 && f > 0,
1825
+ restrictions: A,
1826
+ data: O,
1827
+ options: g,
1828
+ system: u !== void 0 ? u === "true" : void 0
1804
1829
  };
1805
- }, mr = (e) => e == null ? void 0 : e.map(Yt).filter((t) => !!t), pr = [
1830
+ }, ys = (e) => e == null ? void 0 : e.map(ts).filter((t) => !!t), Ss = [
1806
1831
  "date",
1807
1832
  "float",
1808
1833
  "integer",
@@ -1812,56 +1837,583 @@ ${a.join(`
1812
1837
  "boolean",
1813
1838
  "timeCode"
1814
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), {});
1815
2361
  export {
1816
- C as DOCUMENT_TYPES,
1817
- Pe as FIELD_ATTRIBUTE_KEYS,
1818
- pr as FIELD_DEFINITION_TYPES,
1819
- We as FIELD_VALUE_ATTRIBUTE_KEYS,
1820
- ar as FILE_STATES,
1821
- je as GROUP_ATTRIBUTE_KEYS,
1822
- Jt as ROLE_NAMES,
1823
- g as SHAPE_MEDIA_TYPES,
1824
- Xt as SYSTEM_FIELDGROUPS,
1825
- qt as SYSTEM_FIELDS,
1826
- S as TimeBase,
1827
- R as TimeCode,
1828
- Qt as createMetadataType,
1829
- tr as createSearchFacetList,
1830
- j as createTimeBase,
1831
- x as createTimeCode,
1832
- Et as defaultOptions,
1833
- dr as filterShapeSource,
1834
- ft as findNearestThumbnail,
1835
- Z as formatTimeBaseText,
1836
- B as formatTimeBaseType,
1837
- rt as formatTimeCodeSeconds,
1838
- at as formatTimeCodeSmpte,
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,
1839
2391
  U as formatTimeCodeText,
1840
- L as formatTimeCodeType,
1841
- lr as getPlayerSources,
1842
- cr as getShapeDocumentType,
1843
- ur as getShapeMediaType,
1844
- er as metadataTypeToWebVtt,
1845
- Ot as parseAudioComponent,
1846
- St as parseBinaryComponent,
1847
- gt as parseContainerComponent,
1848
- rr as parseFacetList,
1849
- or as parseFacetType,
1850
- mr as parseFieldDefinitionList,
1851
- Re as parseFieldList,
1852
- ve as parseFileType,
1853
- Ne as parseGroupList,
1854
- H as parseHighlightTimespan,
1855
- sr as parseHighlightTimespanList,
1856
- M as parseKeyValuePairType,
1857
- Ht as parseMediaConvertPreset,
1858
- et as parseMetadataType,
1859
- ir as parseNowDate,
1860
- nr as parseSearchResultEvents,
1861
- te as parseShapeType,
1862
- Zt as parseSimpleMetadataType,
1863
- Qe as parseTimespan,
1864
- Me as parseTimespanList,
1865
- _r as parseTranscodePreset,
1866
- Rt as parseVideoComponent
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
1867
2419
  };