@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.
@@ -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) {
@@ -3617,13 +3622,15 @@ function uiPlugin(config = {}) {
3617
3622
  };
3618
3623
  }
3619
3624
  var POSITIONS = ["top-left", "top-right", "bottom-left", "bottom-right", "center"];
3620
- var POSITION_STYLES = {
3621
- "top-left": "top:10px;left:10px;",
3622
- "top-right": "top:10px;right:10px;",
3623
- "bottom-left": "bottom:40px;left:10px;",
3624
- "bottom-right": "bottom:40px;right:10px;",
3625
- "center": "top:50%;left:50%;transform:translate(-50%,-50%);"
3626
- };
3625
+ function getPositionStyles(padding, bottomPadding) {
3626
+ return {
3627
+ "top-left": `top:${padding}px;left:${padding}px;`,
3628
+ "top-right": `top:${padding}px;right:${padding}px;`,
3629
+ "bottom-left": `bottom:${bottomPadding}px;left:${padding}px;`,
3630
+ "bottom-right": `bottom:${bottomPadding}px;right:${padding}px;`,
3631
+ "center": "top:50%;left:50%;transform:translate(-50%,-50%);"
3632
+ };
3633
+ }
3627
3634
  function createWatermarkPlugin(config = {}) {
3628
3635
  let api = null;
3629
3636
  let element = null;
@@ -3632,13 +3639,17 @@ function createWatermarkPlugin(config = {}) {
3632
3639
  let currentPosition = config.position || "bottom-right";
3633
3640
  const opacity = config.opacity ?? 0.5;
3634
3641
  const fontSize = config.fontSize ?? 14;
3642
+ let currentImageHeight = config.imageHeight ?? 40;
3643
+ let currentPadding = config.padding ?? 10;
3644
+ let currentBottomPadding = config.padding ?? 40;
3635
3645
  const dynamic = config.dynamic ?? false;
3636
3646
  const dynamicInterval = config.dynamicInterval ?? 1e4;
3637
3647
  const showDelay = config.showDelay ?? 0;
3648
+ let positionStyles = getPositionStyles(currentPadding, currentBottomPadding);
3638
3649
  const createElement2 = () => {
3639
3650
  const el = document.createElement("div");
3640
3651
  el.className = "sp-watermark sp-watermark--hidden";
3641
- 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]}`;
3652
+ 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]}`;
3642
3653
  el.setAttribute("data-position", currentPosition);
3643
3654
  updateContent(el);
3644
3655
  return el;
@@ -3650,7 +3661,7 @@ function createWatermarkPlugin(config = {}) {
3650
3661
  if (img) {
3651
3662
  const imgEl = document.createElement("img");
3652
3663
  imgEl.src = img;
3653
- imgEl.style.cssText = `max-height:${fontSize * 2}px;opacity:inherit;display:block;`;
3664
+ imgEl.style.cssText = `max-height:${currentImageHeight}px;opacity:inherit;display:block;`;
3654
3665
  imgEl.alt = "";
3655
3666
  el.appendChild(imgEl);
3656
3667
  } else if (txt) {
@@ -3665,7 +3676,7 @@ function createWatermarkPlugin(config = {}) {
3665
3676
  element.style.bottom = "";
3666
3677
  element.style.left = "";
3667
3678
  element.style.transform = "";
3668
- const styles2 = POSITION_STYLES[position];
3679
+ const styles2 = positionStyles[position];
3669
3680
  styles2.split(";").filter(Boolean).forEach((rule) => {
3670
3681
  const colonIdx = rule.indexOf(":");
3671
3682
  if (colonIdx === -1) return;
@@ -3784,10 +3795,23 @@ function createWatermarkPlugin(config = {}) {
3784
3795
  setOpacity(value) {
3785
3796
  if (element) element.style.opacity = String(Math.max(0, Math.min(1, value)));
3786
3797
  },
3798
+ setImageHeight(height) {
3799
+ currentImageHeight = Math.max(1, height);
3800
+ if (element) {
3801
+ const img = element.querySelector("img");
3802
+ if (img) img.style.maxHeight = `${currentImageHeight}px`;
3803
+ }
3804
+ },
3805
+ setPadding(value) {
3806
+ currentPadding = Math.max(0, value);
3807
+ currentBottomPadding = currentPadding;
3808
+ positionStyles = getPositionStyles(currentPadding, currentBottomPadding);
3809
+ setPosition(currentPosition);
3810
+ },
3787
3811
  show,
3788
3812
  hide,
3789
3813
  getConfig() {
3790
- return { ...config, position: currentPosition, opacity: element ? parseFloat(element.style.opacity) || opacity : opacity };
3814
+ return { ...config, position: currentPosition, opacity: element ? parseFloat(element.style.opacity) || opacity : opacity, imageHeight: currentImageHeight, padding: currentPadding };
3791
3815
  }
3792
3816
  };
3793
3817
  }