import { toUint8 as e, bytesMatch as f, bytesToNumber as A, numberToBytes as T } from "./byte-helpers.js";
var y = {
  EBML: e([26, 69, 223, 163]),
  DocType: e([66, 130]),
  Segment: e([24, 83, 128, 103]),
  SegmentInfo: e([21, 73, 169, 102]),
  Tracks: e([22, 84, 174, 107]),
  Track: e([174]),
  TrackNumber: e([215]),
  DefaultDuration: e([35, 227, 131]),
  TrackEntry: e([174]),
  TrackType: e([131]),
  FlagDefault: e([136]),
  CodecID: e([134]),
  CodecPrivate: e([99, 162]),
  VideoTrack: e([224]),
  AudioTrack: e([225]),
  // Not used yet, but will be used for live webm/mkv
  // see https://www.matroska.org/technical/basics.html#block-structure
  // see https://www.matroska.org/technical/basics.html#simpleblock-structure
  Cluster: e([31, 67, 182, 117]),
  Timestamp: e([231]),
  TimestampScale: e([42, 215, 177]),
  BlockGroup: e([160]),
  BlockDuration: e([155]),
  Block: e([161]),
  SimpleBlock: e([163])
}, g = [128, 64, 32, 16, 8, 4, 2, 1], B = function(r) {
  for (var n = 1, l = 0; l < g.length && !(r & g[l]); l++)
    n++;
  return n;
}, a = function(r, n, l, i) {
  l === void 0 && (l = !0), i === void 0 && (i = !1);
  var u = B(r[n]), x = r.subarray(n, n + u);
  return l && (x = Array.prototype.slice.call(r, n, n + u), x[0] ^= g[u - 1]), {
    length: u,
    value: A(x, {
      signed: i
    }),
    bytes: x
  };
}, o = function t(r) {
  return typeof r == "string" ? r.match(/.{1,2}/g).map(function(n) {
    return t(n);
  }) : typeof r == "number" ? T(r) : r;
}, k = function(r) {
  return Array.isArray(r) ? r.map(function(n) {
    return o(n);
  }) : [o(r)];
}, E = function t(r, n, l) {
  if (l >= n.length)
    return n.length;
  var i = a(n, l, !1);
  if (f(r.bytes, i.bytes))
    return l;
  var u = a(n, l + i.length);
  return t(r, n, l + u.length + u.value + i.length);
}, z = function t(r, n) {
  n = k(n), r = e(r);
  var l = [];
  if (!n.length)
    return l;
  for (var i = 0; i < r.length; ) {
    var u = a(r, i, !1), x = a(r, i + u.length), v = i + u.length + x.length;
    x.value === 127 && (x.value = E(u, r, v), x.value !== r.length && (x.value -= v));
    var m = v + x.value > r.length ? r.length : v + x.value, c = r.subarray(v, m);
    f(n[0], u.bytes) && (n.length === 1 ? l.push(c) : l = l.concat(t(c, n.slice(1))));
    var h = u.length + x.length + c.length;
    i += h;
  }
  return l;
};
export {
  y as EBML_TAGS,
  z as findEbml
};
//# sourceMappingURL=ebml-helpers.js.map
