@markdy/renderer-dom 0.5.1 → 0.5.3

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/README.md CHANGED
@@ -50,7 +50,10 @@ player.destroy(); // clean up DOM + cancel animations
50
50
  | `container` | `HTMLElement` | *(required)* | DOM element to mount the scene into |
51
51
  | `code` | `string` | *(required)* | MarkdyScript source code |
52
52
  | `assets` | `Record<string, string>` | `{}` | Asset URL overrides (key = asset name) |
53
- | `autoplay` | `boolean` | `false` | Start playing immediately |
53
+ | `autoplay` | `boolean` | `true` | Start playing immediately |
54
+ | `loop` | `boolean` | `true` | Loop the animation when it reaches the end |
55
+ | `copyright` | `boolean` | `true` | Show a small "Powered by Markdy" badge below the animation |
56
+ | `progressBar` | `boolean` | `true` | Show a rainbow progress bar around the viewport border |
54
57
 
55
58
  ### `Player`
56
59
 
package/dist/index.d.ts CHANGED
@@ -28,6 +28,8 @@ interface PlayerOptions {
28
28
  loop?: boolean;
29
29
  /** Show a small "Powered by Markdy" badge below the animation. Defaults to true. */
30
30
  copyright?: boolean;
31
+ /** Show a rainbow progress bar around the viewport border. Defaults to true. */
32
+ progressBar?: boolean;
31
33
  }
32
34
  interface Player {
33
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, copyright = 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,29 @@ 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 315deg, ${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
+ }
650
673
  let badge = null;
651
674
  if (copyright) {
652
675
  badge = document.createElement("a");
@@ -663,7 +686,9 @@ function createPlayer(opts) {
663
686
  textDecoration: "none",
664
687
  padding: "3px 6px 0",
665
688
  opacity: "0.7",
666
- transition: "opacity 0.2s"
689
+ transition: "opacity 0.2s",
690
+ maxWidth: container.style.maxWidth || "100%",
691
+ width: "100%"
667
692
  });
668
693
  badge.addEventListener("mouseenter", () => {
669
694
  badge.style.opacity = "1";
@@ -671,7 +696,11 @@ function createPlayer(opts) {
671
696
  badge.addEventListener("mouseleave", () => {
672
697
  badge.style.opacity = "0.7";
673
698
  });
674
- container.appendChild(badge);
699
+ if (container.parentNode) {
700
+ container.parentNode.insertBefore(badge, container.nextSibling);
701
+ } else {
702
+ container.appendChild(badge);
703
+ }
675
704
  }
676
705
  const scene = document.createElement("div");
677
706
  Object.assign(scene.style, {
@@ -760,6 +789,8 @@ function createPlayer(opts) {
760
789
  }
761
790
  }
762
791
  applyCurrentTime();
792
+ const totalMsP = (ast.meta.duration ?? 0) * 1e3;
793
+ if (totalMsP > 0) updateProgressBar(sceneMs / totalMsP);
763
794
  rafId = requestAnimationFrame(rafTick);
764
795
  }
765
796
  const player = {
@@ -781,12 +812,15 @@ function createPlayer(opts) {
781
812
  seek(seconds) {
782
813
  sceneMs = seconds * 1e3;
783
814
  applyCurrentTime();
815
+ const totalMsS = (ast.meta.duration ?? 0) * 1e3;
816
+ if (totalMsS > 0) updateProgressBar(sceneMs / totalMsS);
784
817
  },
785
818
  destroy() {
786
819
  player.pause();
787
820
  for (const anim of allAnims) anim.cancel();
788
821
  resizeObserver.disconnect();
789
- if (badge?.parentNode === container) container.removeChild(badge);
822
+ if (progressEl?.parentNode === viewport) viewport.removeChild(progressEl);
823
+ if (badge?.parentNode) badge.parentNode.removeChild(badge);
790
824
  if (viewport.parentNode === container) container.removeChild(viewport);
791
825
  }
792
826
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markdy/renderer-dom",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
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.1"
46
+ "@markdy/core": "0.5.3"
47
47
  },
48
48
  "devDependencies": {
49
49
  "tsup": "^8.5.1",