@geekapps/silo-elements-nextjs 0.3.18 → 0.3.20

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
@@ -1559,24 +1559,98 @@ function deviceSupportsOpus() {
1559
1559
  return false;
1560
1560
  }
1561
1561
  }
1562
- function deviceSupportsCodec(codecStr) {
1563
- if (typeof window === "undefined") return true;
1562
+ function deviceSupportsVideoCodec(codec) {
1563
+ if (!codec || typeof window === "undefined") return true;
1564
+ if (/^avc1/i.test(codec)) return true;
1564
1565
  try {
1565
1566
  if (typeof MediaSource !== "undefined" && MediaSource.isTypeSupported) {
1566
- return MediaSource.isTypeSupported(`video/mp4; codecs="${codecStr}"`);
1567
+ return MediaSource.isTypeSupported(`video/mp4; codecs="${codec}"`);
1567
1568
  }
1568
1569
  return true;
1569
1570
  } catch {
1570
1571
  return true;
1571
1572
  }
1572
1573
  }
1574
+ function deviceSupportsAudioCodec(codec) {
1575
+ if (!codec || typeof window === "undefined") return true;
1576
+ if (/^mp4a/i.test(codec)) return true;
1577
+ if (/^opus/i.test(codec)) return deviceSupportsOpus();
1578
+ try {
1579
+ if (typeof MediaSource !== "undefined" && MediaSource.isTypeSupported) {
1580
+ return MediaSource.isTypeSupported(`audio/mp4; codecs="${codec}"`);
1581
+ }
1582
+ const a = document.createElement("audio");
1583
+ return a.canPlayType(`audio/mp4; codecs="${codec}"`) !== "";
1584
+ } catch {
1585
+ return true;
1586
+ }
1587
+ }
1588
+ var LANG_NAMES = {
1589
+ pt: "Portugu\xEAs",
1590
+ "pt-br": "Portugu\xEAs (Brasil)",
1591
+ "pt-pt": "Portugu\xEAs (Portugal)",
1592
+ en: "English",
1593
+ "en-us": "English (US)",
1594
+ "en-gb": "English (UK)",
1595
+ es: "Espa\xF1ol",
1596
+ "es-419": "Espa\xF1ol (Latino)",
1597
+ fr: "Fran\xE7ais",
1598
+ de: "Deutsch",
1599
+ it: "Italiano",
1600
+ ja: "\u65E5\u672C\u8A9E",
1601
+ ko: "\uD55C\uAD6D\uC5B4",
1602
+ zh: "\u4E2D\u6587",
1603
+ "zh-cn": "\u666E\u901A\u8BDD",
1604
+ "zh-tw": "\u7E41\u9AD4\u4E2D\u6587",
1605
+ ru: "\u0420\u0443\u0441\u0441\u043A\u0438\u0439",
1606
+ ar: "\u0627\u0644\u0639\u0631\u0628\u064A\u0629",
1607
+ hi: "\u0939\u093F\u0928\u094D\u0926\u0940",
1608
+ nl: "Nederlands",
1609
+ pl: "Polski",
1610
+ sv: "Svenska",
1611
+ tr: "T\xFCrk\xE7e",
1612
+ und: "Original"
1613
+ };
1614
+ var CODEC_LABELS = {
1615
+ "truehd": "Dolby TrueHD",
1616
+ "atmos": "Dolby Atmos",
1617
+ "eac3": "Dolby Digital Plus",
1618
+ "ec-3": "Dolby Digital Plus",
1619
+ "e-ac-3": "Dolby Digital Plus",
1620
+ "ac3": "Dolby Digital",
1621
+ "ac-3": "Dolby Digital",
1622
+ "dts-hd": "DTS-HD",
1623
+ "dts-hd ma": "DTS-HD MA",
1624
+ "dtshd": "DTS-HD MA",
1625
+ "dts": "DTS",
1626
+ "aac": "AAC",
1627
+ "opus": "Opus",
1628
+ "mp3": "MP3",
1629
+ "flac": "FLAC",
1630
+ "alac": "ALAC"
1631
+ };
1632
+ var CHANNEL_LABELS = {
1633
+ 1: "Mono",
1634
+ 2: "Est\xE9reo",
1635
+ 6: "5.1",
1636
+ 7: "6.1",
1637
+ 8: "7.1"
1638
+ };
1639
+ function friendlyAudioLabel(rawName, lang, codec, channels) {
1640
+ const langKey = (lang ?? "").toLowerCase();
1641
+ const langLabel = LANG_NAMES[langKey] ?? (lang ? lang.toUpperCase() : null);
1642
+ const codecKey = Object.keys(CODEC_LABELS).find((k) => codec.toLowerCase().includes(k));
1643
+ const codecLabel = codecKey ? CODEC_LABELS[codecKey] : null;
1644
+ const chLabel = channels ? CHANNEL_LABELS[channels] ?? `${channels}ch` : null;
1645
+ const looksHuman = rawName && !/^(und|dts|ac3|eac3|aac|opus|truehd|atmos|\w{2,3}-\d+ch|\w{2})/i.test(rawName) && rawName.length > 1;
1646
+ const baseName = looksHuman ? rawName : langLabel ?? "\xC1udio";
1647
+ const suffix = [codecLabel, chLabel].filter(Boolean).join(" ");
1648
+ return suffix ? `${baseName} \u2014 ${suffix}` : baseName;
1649
+ }
1573
1650
  function isHdrLevel(level) {
1574
1651
  const range = level?.videoRange ?? level?.video_range ?? "";
1575
1652
  return range === "PQ" || range === "HLG" || range === "HDR10" || typeof level?.name === "string" && /hdr/i.test(level.name);
1576
1653
  }
1577
- function isHdrAudioCodec(codecStr) {
1578
- return /opus/i.test(codecStr);
1579
- }
1580
1654
  var PLAYBACK_SPEEDS = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 2];
1581
1655
  function Source(_props) {
1582
1656
  return null;
@@ -2362,10 +2436,14 @@ function Video({
2362
2436
  AUTO_QUALITY,
2363
2437
  ...levels.map((level, index) => {
2364
2438
  const hdr = isHdrLevel(level);
2365
- const codecStr = level.videoCodec ?? level.attrs?.CODECS ?? "";
2366
- const supported = hdr ? hdrSupported : deviceSupportsCodec(codecStr);
2439
+ const rawCodecs = (level.attrs?.CODECS ?? "").split(",").map((c) => c.trim());
2440
+ const videoCodec = level.videoCodec ?? rawCodecs.find((c) => /^avc1|^hvc1|^hev1|^av01|^vp09/i.test(c)) ?? rawCodecs[0] ?? "";
2441
+ const audioCodec = level.audioCodec ?? rawCodecs.find((c) => /^mp4a|^opus|^ec-3|^ac-3/i.test(c)) ?? "";
2442
+ const videoOk = deviceSupportsVideoCodec(videoCodec);
2443
+ const audioOk = deviceSupportsAudioCodec(audioCodec);
2444
+ const supported = (hdr ? hdrSupported : true) && videoOk && audioOk;
2367
2445
  const baseName = level.name ?? (level.height ? `${level.height}p` : `${index + 1}`);
2368
- const label = hdr ? `${baseName} HDR` : baseName;
2446
+ const label = hdr && hdrSupported ? `${baseName} HDR` : baseName;
2369
2447
  return { id: `hls-${index}`, label, type: "hls", index, supported, hdr };
2370
2448
  })
2371
2449
  ]);
@@ -2374,9 +2452,10 @@ function Video({
2374
2452
  if (tracks.length > 1) {
2375
2453
  setAudioTracks(
2376
2454
  tracks.map((t, i) => {
2377
- const codec = t.attrs?.CODECS ?? t.codecSet ?? "";
2378
- const supported = isHdrAudioCodec(codec) ? opusSupported : true;
2379
- return { id: i, label: t.name ?? t.lang ?? `Track ${i + 1}`, supported };
2455
+ const codec = (t.attrs?.CODECS ?? t.codecSet ?? "").split(",")[0]?.trim() ?? "";
2456
+ const supported = deviceSupportsAudioCodec(codec);
2457
+ const label = friendlyAudioLabel(t.name, t.lang, codec, t.channels ?? t.attrs?.CHANNELS);
2458
+ return { id: i, label, supported };
2380
2459
  })
2381
2460
  );
2382
2461
  if (pinnedAudio === -1) setSelectedAudio(hls.audioTrack ?? 0);
@@ -2388,13 +2467,13 @@ function Video({
2388
2467
  hls.on(Hls.Events.AUDIO_TRACKS_UPDATED, (_, data) => {
2389
2468
  const tracks = data.audioTracks ?? [];
2390
2469
  console.debug("[Silo/hls] AUDIO_TRACKS_UPDATED", tracks.length);
2391
- const opusSupported = deviceSupportsOpus();
2392
2470
  if (tracks.length > 1) {
2393
2471
  setAudioTracks(
2394
2472
  tracks.map((t, i) => {
2395
- const codec = t.attrs?.CODECS ?? t.codecSet ?? "";
2396
- const supported = isHdrAudioCodec(codec) ? opusSupported : true;
2397
- return { id: i, label: t.name ?? t.lang ?? `Track ${i + 1}`, supported };
2473
+ const codec = (t.attrs?.CODECS ?? t.codecSet ?? "").split(",")[0]?.trim() ?? "";
2474
+ const supported = deviceSupportsAudioCodec(codec);
2475
+ const label = friendlyAudioLabel(t.name, t.lang, codec, t.channels ?? t.attrs?.CHANNELS);
2476
+ return { id: i, label, supported };
2398
2477
  })
2399
2478
  );
2400
2479
  }