@markdy/renderer-dom 0.5.0 → 0.5.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/index.d.ts CHANGED
@@ -26,6 +26,10 @@ interface PlayerOptions {
26
26
  autoplay?: boolean;
27
27
  /** Loop the animation when it reaches the end. Defaults to true. */
28
28
  loop?: boolean;
29
+ /** Show a small "Powered by Markdy" badge below the animation. Defaults to true. */
30
+ copyright?: boolean;
31
+ /** Show a rainbow progress bar around the viewport border. Defaults to true. */
32
+ progressBar?: boolean;
29
33
  }
30
34
  interface Player {
31
35
  play(): void;
package/dist/index.js CHANGED
@@ -637,7 +637,7 @@ function buildAction(ev, el, s, baseOpts, delayMs, durMs, ast, states, scene, as
637
637
 
638
638
  // src/player.ts
639
639
  function createPlayer(opts) {
640
- const { container, code, assets: assetOverrides = {}, autoplay = true, loop = true } = opts;
640
+ const { container, code, assets: assetOverrides = {}, autoplay = true, loop = true, copyright = true, progressBar = true } = opts;
641
641
  const ast = parse(code);
642
642
  const viewport = document.createElement("div");
643
643
  Object.assign(viewport.style, {
@@ -647,6 +647,55 @@ function createPlayer(opts) {
647
647
  overflow: "hidden"
648
648
  });
649
649
  container.appendChild(viewport);
650
+ let progressEl = null;
651
+ if (progressBar) {
652
+ progressEl = document.createElement("div");
653
+ Object.assign(progressEl.style, {
654
+ position: "absolute",
655
+ inset: "0",
656
+ zIndex: "9999",
657
+ pointerEvents: "none",
658
+ borderRadius: "inherit"
659
+ });
660
+ viewport.appendChild(progressEl);
661
+ }
662
+ function updateProgressBar(pct) {
663
+ if (!progressEl) return;
664
+ const deg = pct * 360;
665
+ const rainbow = "hsl(0,90%,60%), hsl(45,90%,55%), hsl(90,80%,50%), hsl(180,80%,50%), hsl(270,80%,55%), hsl(330,90%,60%)";
666
+ progressEl.style.background = `conic-gradient(from 225deg, ${rainbow} ${deg}deg, transparent ${deg}deg)`;
667
+ progressEl.style.mask = `linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)`;
668
+ progressEl.style.webkitMask = progressEl.style.mask;
669
+ progressEl.style.maskComposite = "exclude";
670
+ progressEl.style.webkitMaskComposite = "xor";
671
+ progressEl.style.padding = "2px";
672
+ }
673
+ let badge = null;
674
+ if (copyright) {
675
+ badge = document.createElement("a");
676
+ badge.href = "https://markdy.com";
677
+ badge.target = "_blank";
678
+ badge.rel = "noopener noreferrer";
679
+ badge.textContent = "Powered by Markdy";
680
+ Object.assign(badge.style, {
681
+ display: "block",
682
+ textAlign: "right",
683
+ fontSize: "10px",
684
+ fontFamily: "system-ui, -apple-system, sans-serif",
685
+ color: "#999",
686
+ textDecoration: "none",
687
+ padding: "3px 6px 0",
688
+ opacity: "0.7",
689
+ transition: "opacity 0.2s"
690
+ });
691
+ badge.addEventListener("mouseenter", () => {
692
+ badge.style.opacity = "1";
693
+ });
694
+ badge.addEventListener("mouseleave", () => {
695
+ badge.style.opacity = "0.7";
696
+ });
697
+ container.appendChild(badge);
698
+ }
650
699
  const scene = document.createElement("div");
651
700
  Object.assign(scene.style, {
652
701
  position: "absolute",
@@ -734,6 +783,8 @@ function createPlayer(opts) {
734
783
  }
735
784
  }
736
785
  applyCurrentTime();
786
+ const totalMsP = (ast.meta.duration ?? 0) * 1e3;
787
+ if (totalMsP > 0) updateProgressBar(sceneMs / totalMsP);
737
788
  rafId = requestAnimationFrame(rafTick);
738
789
  }
739
790
  const player = {
@@ -755,11 +806,15 @@ function createPlayer(opts) {
755
806
  seek(seconds) {
756
807
  sceneMs = seconds * 1e3;
757
808
  applyCurrentTime();
809
+ const totalMsS = (ast.meta.duration ?? 0) * 1e3;
810
+ if (totalMsS > 0) updateProgressBar(sceneMs / totalMsS);
758
811
  },
759
812
  destroy() {
760
813
  player.pause();
761
814
  for (const anim of allAnims) anim.cancel();
762
815
  resizeObserver.disconnect();
816
+ if (progressEl?.parentNode === viewport) viewport.removeChild(progressEl);
817
+ if (badge?.parentNode === container) container.removeChild(badge);
763
818
  if (viewport.parentNode === container) container.removeChild(viewport);
764
819
  }
765
820
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markdy/renderer-dom",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Web Animations API renderer for MarkdyScript scenes.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -43,7 +43,7 @@
43
43
  "access": "public"
44
44
  },
45
45
  "dependencies": {
46
- "@markdy/core": "0.5.0"
46
+ "@markdy/core": "0.5.2"
47
47
  },
48
48
  "devDependencies": {
49
49
  "tsup": "^8.5.1",