Skip to content

Write HTML. Render video. Built for agents.

fix(registry): svg dash animations measure the path after its d is set (#4082)

Miguel Ángel637ce57994d1
diff --git a/registry/blocks/hw-path-text/demo.html b/registry/blocks/hw-path-text/demo.html
index 3dc31619d8..954f2efdec 100644
--- a/registry/blocks/hw-path-text/demo.html
+++ b/registry/blocks/hw-path-text/demo.html
@@ -149,8 +149,10 @@
});
};
- document.getElementById("hw-pt-path").setAttribute("d", CONFIG.d);
- if (CONFIG.showGuide) document.getElementById("hw-pt-guide").setAttribute("d", CONFIG.d);
+ var pathEl = document.getElementById("hw-pt-path");
+ var guide = document.getElementById("hw-pt-guide");
+ pathEl.setAttribute("d", CONFIG.d);
+ if (CONFIG.showGuide) guide.setAttribute("d", CONFIG.d);
document.getElementById("hw-pt-text").setAttribute("font-size", CONFIG.fontSize);
/* per-char tspans along the path */
@@ -165,7 +167,6 @@
var tl = gsap.timeline({ paused: true });
/* guide draws first, then the handwriting types along it */
- var guide = document.getElementById("hw-pt-guide");
if (CONFIG.showGuide) {
var glen = guide.getTotalLength();
gsap.set(guide, { strokeDasharray: "2 14", strokeDashoffset: glen });
diff --git a/registry/blocks/hw-path-text/hw-path-text.html b/registry/blocks/hw-path-text/hw-path-text.html
index fa10379cd9..4b3a1ed36f 100644
--- a/registry/blocks/hw-path-text/hw-path-text.html
+++ b/registry/blocks/hw-path-text/hw-path-text.html
@@ -146,8 +146,10 @@
});
};
- document.getElementById("hw-pt-path").setAttribute("d", CONFIG.d);
- if (CONFIG.showGuide) document.getElementById("hw-pt-guide").setAttribute("d", CONFIG.d);
+ var pathEl = document.getElementById("hw-pt-path");
+ var guide = document.getElementById("hw-pt-guide");
+ pathEl.setAttribute("d", CONFIG.d);
+ if (CONFIG.showGuide) guide.setAttribute("d", CONFIG.d);
document.getElementById("hw-pt-text").setAttribute("font-size", CONFIG.fontSize);
/* per-char tspans along the path */
@@ -162,7 +164,6 @@
var tl = gsap.timeline({ paused: true });
/* guide draws first, then the handwriting types along it */
- var guide = document.getElementById("hw-pt-guide");
if (CONFIG.showGuide) {
var glen = guide.getTotalLength();
gsap.set(guide, { strokeDasharray: "2 14", strokeDashoffset: glen });
diff --git a/registry/blocks/hw-text-cloud/hw-text-cloud.html b/registry/blocks/hw-text-cloud/hw-text-cloud.html
index 88db90f00b..b3892549a8 100644
--- a/registry/blocks/hw-text-cloud/hw-text-cloud.html
+++ b/registry/blocks/hw-text-cloud/hw-text-cloud.html
@@ -228,8 +228,10 @@
var svg = document.getElementById("hw-tc-svg");
svg.setAttribute("viewBox", "0 0 " + CONFIG.w + " " + CONFIG.h);
var d = cloudPath(CONFIG.w, CONFIG.h, CONFIG.tip, CONFIG.seed);
- document.getElementById("hw-tc-fill").setAttribute("d", d);
- document.getElementById("hw-tc-stroke").setAttribute("d", d);
+ var fillEl = document.getElementById("hw-tc-fill");
+ var stroke = document.getElementById("hw-tc-stroke");
+ fillEl.setAttribute("d", d);
+ stroke.setAttribute("d", d);
var text = document.getElementById("hw-tc-text");
text.style.left = CONFIG.w * 0.12 + "px";
@@ -249,7 +251,6 @@
var tl = gsap.timeline({ paused: true });
/* draw outline, fade fill, type text */
- var stroke = document.getElementById("hw-tc-stroke");
var len = stroke.getTotalLength();
gsap.set(stroke, { strokeDasharray: len, strokeDashoffset: len });
var t0 = CONFIG.animationIn ? 0.3 : 0;