@scarlett-player/embed 1.0.1 → 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) {
@@ -5572,13 +5577,15 @@ function createMediaSessionPlugin(config) {
5572
5577
  return plugin;
5573
5578
  }
5574
5579
  var POSITIONS = ["top-left", "top-right", "bottom-left", "bottom-right", "center"];
5575
- var POSITION_STYLES = {
5576
- "top-left": "top:10px;left:10px;",
5577
- "top-right": "top:10px;right:10px;",
5578
- "bottom-left": "bottom:40px;left:10px;",
5579
- "bottom-right": "bottom:40px;right:10px;",
5580
- "center": "top:50%;left:50%;transform:translate(-50%,-50%);"
5581
- };
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
+ }
5582
5589
  function createWatermarkPlugin(config = {}) {
5583
5590
  let api = null;
5584
5591
  let element = null;
@@ -5587,13 +5594,17 @@ function createWatermarkPlugin(config = {}) {
5587
5594
  let currentPosition = config.position || "bottom-right";
5588
5595
  const opacity = config.opacity ?? 0.5;
5589
5596
  const fontSize = config.fontSize ?? 14;
5597
+ let currentImageHeight = config.imageHeight ?? 40;
5598
+ let currentPadding = config.padding ?? 10;
5599
+ let currentBottomPadding = config.padding ?? 40;
5590
5600
  const dynamic = config.dynamic ?? false;
5591
5601
  const dynamicInterval = config.dynamicInterval ?? 1e4;
5592
5602
  const showDelay = config.showDelay ?? 0;
5603
+ let positionStyles = getPositionStyles(currentPadding, currentBottomPadding);
5593
5604
  const createElement2 = () => {
5594
5605
  const el = document.createElement("div");
5595
5606
  el.className = "sp-watermark sp-watermark--hidden";
5596
- 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]}`;
5597
5608
  el.setAttribute("data-position", currentPosition);
5598
5609
  updateContent(el);
5599
5610
  return el;
@@ -5605,7 +5616,7 @@ function createWatermarkPlugin(config = {}) {
5605
5616
  if (img) {
5606
5617
  const imgEl = document.createElement("img");
5607
5618
  imgEl.src = img;
5608
- imgEl.style.cssText = `max-height:${fontSize * 2}px;opacity:inherit;display:block;`;
5619
+ imgEl.style.cssText = `max-height:${currentImageHeight}px;opacity:inherit;display:block;`;
5609
5620
  imgEl.alt = "";
5610
5621
  el.appendChild(imgEl);
5611
5622
  } else if (txt) {
@@ -5620,7 +5631,7 @@ function createWatermarkPlugin(config = {}) {
5620
5631
  element.style.bottom = "";
5621
5632
  element.style.left = "";
5622
5633
  element.style.transform = "";
5623
- const styles2 = POSITION_STYLES[position];
5634
+ const styles2 = positionStyles[position];
5624
5635
  styles2.split(";").filter(Boolean).forEach((rule) => {
5625
5636
  const colonIdx = rule.indexOf(":");
5626
5637
  if (colonIdx === -1) return;
@@ -5739,10 +5750,23 @@ function createWatermarkPlugin(config = {}) {
5739
5750
  setOpacity(value) {
5740
5751
  if (element) element.style.opacity = String(Math.max(0, Math.min(1, value)));
5741
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
+ },
5742
5766
  show,
5743
5767
  hide,
5744
5768
  getConfig() {
5745
- 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 };
5746
5770
  }
5747
5771
  };
5748
5772
  }