@markdy/renderer-dom 0.5.5 → 0.5.7
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.js +24 -8
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -540,6 +540,7 @@ function buildAction(ev, el, s, baseOpts, delayMs, durMs, ast, states, scene, as
|
|
|
540
540
|
transformOrigin: "center bottom",
|
|
541
541
|
background: "white",
|
|
542
542
|
border: "2px solid #222",
|
|
543
|
+
color: "#222",
|
|
543
544
|
borderRadius: "12px",
|
|
544
545
|
padding: "6px 14px",
|
|
545
546
|
fontFamily: "system-ui, sans-serif",
|
|
@@ -636,9 +637,26 @@ function buildAction(ev, el, s, baseOpts, delayMs, durMs, ast, states, scene, as
|
|
|
636
637
|
}
|
|
637
638
|
|
|
638
639
|
// src/player.ts
|
|
640
|
+
function bgToTextColor(bg) {
|
|
641
|
+
let hex = bg.trim().replace(/^#/, "");
|
|
642
|
+
if (hex.length === 3) hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
|
|
643
|
+
if (hex.length === 6) {
|
|
644
|
+
const r = parseInt(hex.slice(0, 2), 16);
|
|
645
|
+
const g = parseInt(hex.slice(2, 4), 16);
|
|
646
|
+
const b = parseInt(hex.slice(4, 6), 16);
|
|
647
|
+
return 0.299 * r + 0.587 * g + 0.114 * b > 140 ? "#1a1a1a" : "#f0f0f0";
|
|
648
|
+
}
|
|
649
|
+
const named = {
|
|
650
|
+
white: "#1a1a1a",
|
|
651
|
+
black: "#f0f0f0",
|
|
652
|
+
transparent: "#1a1a1a"
|
|
653
|
+
};
|
|
654
|
+
return named[bg.toLowerCase()] ?? "#1a1a1a";
|
|
655
|
+
}
|
|
639
656
|
function createPlayer(opts) {
|
|
640
657
|
const { container, code, assets: assetOverrides = {}, autoplay = true, loop = true, copyright = true, progressBar = true } = opts;
|
|
641
658
|
const ast = parse(code);
|
|
659
|
+
const totalDurationMs = (ast.meta.duration ?? 0) * 1e3;
|
|
642
660
|
const viewport = document.createElement("div");
|
|
643
661
|
Object.assign(viewport.style, {
|
|
644
662
|
position: "relative",
|
|
@@ -711,6 +729,7 @@ function createPlayer(opts) {
|
|
|
711
729
|
width: `${ast.meta.width}px`,
|
|
712
730
|
height: `${ast.meta.height}px`,
|
|
713
731
|
background: ast.meta.bg,
|
|
732
|
+
color: bgToTextColor(ast.meta.bg),
|
|
714
733
|
overflow: "hidden",
|
|
715
734
|
userSelect: "none",
|
|
716
735
|
transformOrigin: "0 0"
|
|
@@ -776,12 +795,11 @@ function createPlayer(opts) {
|
|
|
776
795
|
sceneMs += timestamp - lastRafTs;
|
|
777
796
|
}
|
|
778
797
|
lastRafTs = timestamp;
|
|
779
|
-
|
|
780
|
-
if (totalMs > 0 && sceneMs >= totalMs) {
|
|
798
|
+
if (totalDurationMs > 0 && sceneMs >= totalDurationMs) {
|
|
781
799
|
if (loop) {
|
|
782
|
-
sceneMs = sceneMs %
|
|
800
|
+
sceneMs = sceneMs % totalDurationMs;
|
|
783
801
|
} else {
|
|
784
|
-
sceneMs =
|
|
802
|
+
sceneMs = totalDurationMs;
|
|
785
803
|
applyCurrentTime();
|
|
786
804
|
isPlaying = false;
|
|
787
805
|
lastRafTs = null;
|
|
@@ -790,8 +808,7 @@ function createPlayer(opts) {
|
|
|
790
808
|
}
|
|
791
809
|
}
|
|
792
810
|
applyCurrentTime();
|
|
793
|
-
|
|
794
|
-
if (totalMsP > 0) updateProgressBar(sceneMs / totalMsP);
|
|
811
|
+
if (totalDurationMs > 0) updateProgressBar(sceneMs / totalDurationMs);
|
|
795
812
|
rafId = requestAnimationFrame(rafTick);
|
|
796
813
|
}
|
|
797
814
|
const player = {
|
|
@@ -813,8 +830,7 @@ function createPlayer(opts) {
|
|
|
813
830
|
seek(seconds) {
|
|
814
831
|
sceneMs = seconds * 1e3;
|
|
815
832
|
applyCurrentTime();
|
|
816
|
-
|
|
817
|
-
if (totalMsS > 0) updateProgressBar(sceneMs / totalMsS);
|
|
833
|
+
if (totalDurationMs > 0) updateProgressBar(sceneMs / totalDurationMs);
|
|
818
834
|
},
|
|
819
835
|
destroy() {
|
|
820
836
|
player.pause();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markdy/renderer-dom",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.7",
|
|
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.7"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"tsup": "^8.5.1",
|