animot-presenter 0.2.7 → 0.2.8
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/AnimotPresenter.svelte +22 -4
- package/dist/cdn/animot-presenter.esm.js +1227 -1220
- package/dist/cdn/animot-presenter.min.js +8 -8
- package/package.json +1 -1
|
@@ -100,10 +100,23 @@
|
|
|
100
100
|
for (const seg of segs) {
|
|
101
101
|
if (accum + seg.length >= targetLength || seg === segs[segs.length - 1]) {
|
|
102
102
|
const t = Math.max(0, Math.min(1, seg.length > 0 ? (targetLength - accum) / seg.length : 0));
|
|
103
|
+
let dx = cubicBezDeriv(seg.p0x, seg.p1x, seg.p2x, seg.p3x, t);
|
|
104
|
+
let dy = cubicBezDeriv(seg.p0y, seg.p1y, seg.p2y, seg.p3y, t);
|
|
105
|
+
// Degenerate tangent at endpoints (no Bezier handles) — sample nearby
|
|
106
|
+
if (Math.abs(dx) < 0.001 && Math.abs(dy) < 0.001) {
|
|
107
|
+
const epsilon = t < 0.5 ? 0.01 : -0.01;
|
|
108
|
+
dx = cubicBezDeriv(seg.p0x, seg.p1x, seg.p2x, seg.p3x, t + epsilon);
|
|
109
|
+
dy = cubicBezDeriv(seg.p0y, seg.p1y, seg.p2y, seg.p3y, t + epsilon);
|
|
110
|
+
}
|
|
111
|
+
// Still zero (fully degenerate segment) — use chord direction
|
|
112
|
+
if (Math.abs(dx) < 0.001 && Math.abs(dy) < 0.001) {
|
|
113
|
+
dx = seg.p3x - seg.p0x;
|
|
114
|
+
dy = seg.p3y - seg.p0y;
|
|
115
|
+
}
|
|
103
116
|
return {
|
|
104
117
|
x: cubicBez(seg.p0x, seg.p1x, seg.p2x, seg.p3x, t),
|
|
105
118
|
y: cubicBez(seg.p0y, seg.p1y, seg.p2y, seg.p3y, t),
|
|
106
|
-
angle: Math.atan2(
|
|
119
|
+
angle: Math.atan2(dy, dx) * (180 / Math.PI)
|
|
107
120
|
};
|
|
108
121
|
}
|
|
109
122
|
accum += seg.length;
|
|
@@ -114,8 +127,12 @@
|
|
|
114
127
|
function computeMotionPathPosition(
|
|
115
128
|
mpPoint: { x: number; y: number; angle: number },
|
|
116
129
|
startPoint: { x: number; y: number; angle: number },
|
|
117
|
-
animX: number, animY: number, animW: number, animH: number
|
|
130
|
+
animX: number, animY: number, animW: number, animH: number,
|
|
131
|
+
closed: boolean
|
|
118
132
|
): { x: number; y: number } {
|
|
133
|
+
if (!closed) {
|
|
134
|
+
return { x: mpPoint.x - animW / 2, y: mpPoint.y - animH / 2 };
|
|
135
|
+
}
|
|
119
136
|
const offsetX = (animX + animW / 2) - startPoint.x;
|
|
120
137
|
const offsetY = (animY + animH / 2) - startPoint.y;
|
|
121
138
|
const angleDelta = (mpPoint.angle - startPoint.angle) * Math.PI / 180;
|
|
@@ -1017,10 +1034,11 @@
|
|
|
1017
1034
|
{@const mpProgress = animated?.motionPathProgress?.current ?? 0}
|
|
1018
1035
|
{@const mpPoint = mpElement && mpConfig ? getPresenterPointOnPath(mpElement.points, mpElement.closed, (mpConfig.startPercent + (mpConfig.endPercent - mpConfig.startPercent) * mpProgress) / 100) : null}
|
|
1019
1036
|
{@const mpStartPoint = mpElement && mpConfig ? getPresenterPointOnPath(mpElement.points, mpElement.closed, mpConfig.startPercent / 100) : null}
|
|
1020
|
-
{@const mpPos = mpPoint && mpStartPoint && animated
|
|
1037
|
+
{@const mpPos = mpPoint && mpStartPoint && animated && mpElement
|
|
1021
1038
|
? computeMotionPathPosition(mpPoint, mpStartPoint,
|
|
1022
1039
|
animated.x.current, animated.y.current,
|
|
1023
|
-
animated.width.current, animated.height.current
|
|
1040
|
+
animated.width.current, animated.height.current,
|
|
1041
|
+
mpElement.closed)
|
|
1024
1042
|
: null}
|
|
1025
1043
|
{@const elemX = mpPos ? mpPos.x : (animated?.x.current ?? 0)}
|
|
1026
1044
|
{@const elemY = mpPos ? mpPos.y : (animated?.y.current ?? 0)}
|