@markdy/renderer-dom 0.5.1 → 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 +2 -0
- package/dist/index.js +29 -1
- package/package.json +2 -2
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 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
|
+
}
|
|
650
673
|
let badge = null;
|
|
651
674
|
if (copyright) {
|
|
652
675
|
badge = document.createElement("a");
|
|
@@ -760,6 +783,8 @@ function createPlayer(opts) {
|
|
|
760
783
|
}
|
|
761
784
|
}
|
|
762
785
|
applyCurrentTime();
|
|
786
|
+
const totalMsP = (ast.meta.duration ?? 0) * 1e3;
|
|
787
|
+
if (totalMsP > 0) updateProgressBar(sceneMs / totalMsP);
|
|
763
788
|
rafId = requestAnimationFrame(rafTick);
|
|
764
789
|
}
|
|
765
790
|
const player = {
|
|
@@ -781,11 +806,14 @@ function createPlayer(opts) {
|
|
|
781
806
|
seek(seconds) {
|
|
782
807
|
sceneMs = seconds * 1e3;
|
|
783
808
|
applyCurrentTime();
|
|
809
|
+
const totalMsS = (ast.meta.duration ?? 0) * 1e3;
|
|
810
|
+
if (totalMsS > 0) updateProgressBar(sceneMs / totalMsS);
|
|
784
811
|
},
|
|
785
812
|
destroy() {
|
|
786
813
|
player.pause();
|
|
787
814
|
for (const anim of allAnims) anim.cancel();
|
|
788
815
|
resizeObserver.disconnect();
|
|
816
|
+
if (progressEl?.parentNode === viewport) viewport.removeChild(progressEl);
|
|
789
817
|
if (badge?.parentNode === container) container.removeChild(badge);
|
|
790
818
|
if (viewport.parentNode === container) container.removeChild(viewport);
|
|
791
819
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markdy/renderer-dom",
|
|
3
|
-
"version": "0.5.
|
|
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.
|
|
46
|
+
"@markdy/core": "0.5.2"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"tsup": "^8.5.1",
|