( html: string, elementId: string, updates: Partial<TimelineElement>, )
| 533 | } |
| 534 | |
| 535 | export function updateElementInHtml( |
| 536 | html: string, |
| 537 | elementId: string, |
| 538 | updates: Partial<TimelineElement>, |
| 539 | ): string { |
| 540 | const parser = new DOMParser(); |
| 541 | const doc = parser.parseFromString(html, "text/html"); |
| 542 | |
| 543 | const el = doc.getElementById(elementId) || queryByAttr(doc, "data-name", elementId); |
| 544 | if (!el) return html; |
| 545 | |
| 546 | if (updates.startTime !== undefined) { |
| 547 | el.setAttribute("data-start", String(updates.startTime)); |
| 548 | if (el.hasAttribute("data-end") && updates.duration !== undefined) { |
| 549 | el.setAttribute("data-end", String(updates.startTime + updates.duration)); |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | if (updates.duration !== undefined) { |
| 554 | const start = parseFloat(el.getAttribute("data-start") || "0"); |
| 555 | el.setAttribute("data-end", String(start + updates.duration)); |
| 556 | el.removeAttribute("data-duration"); // Clean up legacy |
| 557 | } |
| 558 | |
| 559 | if (updates.name !== undefined) { |
| 560 | el.setAttribute("data-name", updates.name); |
| 561 | } |
| 562 | |
| 563 | if (updates.zIndex !== undefined) { |
| 564 | el.setAttribute("data-layer", String(updates.zIndex)); |
| 565 | } |
| 566 | |
| 567 | // Handle media-specific property |
| 568 | if ("src" in updates && updates.src !== undefined) { |
| 569 | el.setAttribute("src", updates.src); |
| 570 | } |
| 571 | |
| 572 | // Handle text-specific properties |
| 573 | if ("content" in updates && updates.content !== undefined) { |
| 574 | const textEl = el.firstElementChild; |
| 575 | if (textEl) { |
| 576 | textEl.textContent = updates.content; |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | if ("color" in updates && updates.color !== undefined) { |
| 581 | el.setAttribute("data-color", updates.color); |
| 582 | } |
| 583 | |
| 584 | if ("fontSize" in updates && updates.fontSize !== undefined) { |
| 585 | el.setAttribute("data-font-size", String(updates.fontSize)); |
| 586 | } |
| 587 | |
| 588 | if ("textShadow" in updates) { |
| 589 | if (updates.textShadow === false) { |
| 590 | el.setAttribute("data-text-shadow", "false"); |
| 591 | } else { |
| 592 | el.removeAttribute("data-text-shadow"); |
no test coverage detected