@scarlett-player/embed 1.0.0 → 1.0.2

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/embed.js CHANGED
@@ -277,6 +277,11 @@ function setupVideoEventHandlers(video, api) {
277
277
  api.setState("duration", video.duration);
278
278
  api.setState("mediaType", video.videoWidth > 0 ? "video" : "audio");
279
279
  });
280
+ addHandler("loadeddata", () => {
281
+ if (video.videoWidth > 0) {
282
+ api.setState("mediaType", "video");
283
+ }
284
+ });
280
285
  addHandler("error", () => {
281
286
  const error = video.error;
282
287
  if (error) {
@@ -4954,7 +4959,10 @@ function createPlaylistPlugin(config) {
4954
4959
  const mergedConfig = { ...DEFAULT_CONFIG$1, ...config };
4955
4960
  let api = null;
4956
4961
  let tracks = mergedConfig.tracks || [];
4957
- let currentIndex = -1;
4962
+ let currentIndex = mergedConfig.initialIndex ?? -1;
4963
+ if (currentIndex < -1 || currentIndex >= tracks.length) {
4964
+ currentIndex = -1;
4965
+ }
4958
4966
  let shuffle = mergedConfig.shuffle || false;
4959
4967
  let repeat = mergedConfig.repeat || "none";
4960
4968
  let shuffleOrder = [];
@@ -5569,13 +5577,15 @@ function createMediaSessionPlugin(config) {
5569
5577
  return plugin;
5570
5578
  }
5571
5579
  var POSITIONS = ["top-left", "top-right", "bottom-left", "bottom-right", "center"];
5572
- var POSITION_STYLES = {
5573
- "top-left": "top:10px;left:10px;",
5574
- "top-right": "top:10px;right:10px;",
5575
- "bottom-left": "bottom:40px;left:10px;",
5576
- "bottom-right": "bottom:40px;right:10px;",
5577
- "center": "top:50%;left:50%;transform:translate(-50%,-50%);"
5578
- };
5580
+ function getPositionStyles(padding, bottomPadding) {
5581
+ return {
5582
+ "top-left": `top:${padding}px;left:${padding}px;`,
5583
+ "top-right": `top:${padding}px;right:${padding}px;`,
5584
+ "bottom-left": `bottom:${bottomPadding}px;left:${padding}px;`,
5585
+ "bottom-right": `bottom:${bottomPadding}px;right:${padding}px;`,
5586
+ "center": "top:50%;left:50%;transform:translate(-50%,-50%);"
5587
+ };
5588
+ }
5579
5589
  function createWatermarkPlugin(config = {}) {
5580
5590
  let api = null;
5581
5591
  let element = null;
@@ -5584,13 +5594,17 @@ function createWatermarkPlugin(config = {}) {
5584
5594
  let currentPosition = config.position || "bottom-right";
5585
5595
  const opacity = config.opacity ?? 0.5;
5586
5596
  const fontSize = config.fontSize ?? 14;
5597
+ let currentImageHeight = config.imageHeight ?? 40;
5598
+ let currentPadding = config.padding ?? 10;
5599
+ let currentBottomPadding = config.padding ?? 40;
5587
5600
  const dynamic = config.dynamic ?? false;
5588
5601
  const dynamicInterval = config.dynamicInterval ?? 1e4;
5589
5602
  const showDelay = config.showDelay ?? 0;
5603
+ let positionStyles = getPositionStyles(currentPadding, currentBottomPadding);
5590
5604
  const createElement2 = () => {
5591
5605
  const el = document.createElement("div");
5592
5606
  el.className = "sp-watermark sp-watermark--hidden";
5593
- el.style.cssText = `position:absolute;z-index:10;pointer-events:none;opacity:${opacity};font-size:${fontSize}px;color:#fff;text-shadow:0 1px 2px rgba(0,0,0,0.6);font-family:sans-serif;transition:all 0.5s ease;${POSITION_STYLES[currentPosition]}`;
5607
+ el.style.cssText = `position:absolute;z-index:10;pointer-events:none;opacity:${opacity};font-size:${fontSize}px;color:#fff;text-shadow:0 1px 2px rgba(0,0,0,0.6);font-family:sans-serif;transition:all 0.5s ease;${positionStyles[currentPosition]}`;
5594
5608
  el.setAttribute("data-position", currentPosition);
5595
5609
  updateContent(el);
5596
5610
  return el;
@@ -5602,7 +5616,7 @@ function createWatermarkPlugin(config = {}) {
5602
5616
  if (img) {
5603
5617
  const imgEl = document.createElement("img");
5604
5618
  imgEl.src = img;
5605
- imgEl.style.cssText = `max-height:${fontSize * 2}px;opacity:inherit;display:block;`;
5619
+ imgEl.style.cssText = `max-height:${currentImageHeight}px;opacity:inherit;display:block;`;
5606
5620
  imgEl.alt = "";
5607
5621
  el.appendChild(imgEl);
5608
5622
  } else if (txt) {
@@ -5617,7 +5631,7 @@ function createWatermarkPlugin(config = {}) {
5617
5631
  element.style.bottom = "";
5618
5632
  element.style.left = "";
5619
5633
  element.style.transform = "";
5620
- const styles2 = POSITION_STYLES[position];
5634
+ const styles2 = positionStyles[position];
5621
5635
  styles2.split(";").filter(Boolean).forEach((rule) => {
5622
5636
  const colonIdx = rule.indexOf(":");
5623
5637
  if (colonIdx === -1) return;
@@ -5736,10 +5750,23 @@ function createWatermarkPlugin(config = {}) {
5736
5750
  setOpacity(value) {
5737
5751
  if (element) element.style.opacity = String(Math.max(0, Math.min(1, value)));
5738
5752
  },
5753
+ setImageHeight(height) {
5754
+ currentImageHeight = Math.max(1, height);
5755
+ if (element) {
5756
+ const img = element.querySelector("img");
5757
+ if (img) img.style.maxHeight = `${currentImageHeight}px`;
5758
+ }
5759
+ },
5760
+ setPadding(value) {
5761
+ currentPadding = Math.max(0, value);
5762
+ currentBottomPadding = currentPadding;
5763
+ positionStyles = getPositionStyles(currentPadding, currentBottomPadding);
5764
+ setPosition(currentPosition);
5765
+ },
5739
5766
  show,
5740
5767
  hide,
5741
5768
  getConfig() {
5742
- return { ...config, position: currentPosition, opacity: element ? parseFloat(element.style.opacity) || opacity : opacity };
5769
+ return { ...config, position: currentPosition, opacity: element ? parseFloat(element.style.opacity) || opacity : opacity, imageHeight: currentImageHeight, padding: currentPadding };
5743
5770
  }
5744
5771
  };
5745
5772
  }