Skip to content

Commit fbb021f

Browse files
committed
Feat(Core): Audio support
Implements support for the `<audio>` tag using the `Goatee.Audio()` class.
1 parent f9ab940 commit fbb021f

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.2.6] - 2025-04-09
9+
10+
### Added
11+
12+
- Adds support for the "<audio>" tag using the "Goatee.Audio()" class.
13+
814
## [0.2.5] - 2025-04-09
915

1016
### Fixed

src/Goatee.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Script } from "./core/Script.js";
1212
import { Head } from "./core/Head.js";
1313
import { Body } from "./core/Body.js";
1414
import { Image } from "./core/Image.js";
15+
import { Audio } from "./core/Audio.js";
1516
import { Heading } from "./core/Heading.js";
1617
import { Separator } from "./core/Separator.js";
1718
import { Text } from "./core/Text.js";
@@ -36,6 +37,7 @@ export class Goatee {
3637
this.Head = Head;
3738
this.Body = Body;
3839
this.Image = Image;
40+
this.Audio = Audio;
3941
this.Heading = Heading;
4042
this.Separator = Separator;
4143
this.Text = Text;

src/core/Audio.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Element } from "./Element.js";
2+
3+
export class Audio extends Element {
4+
constructor({
5+
src,
6+
type = null,
7+
controls = true,
8+
autoplay = false,
9+
loop = false,
10+
muted = false,
11+
preload = "metadata",
12+
sources = null // Optional array of { src, type }
13+
}) {
14+
super();
15+
this.src = src;
16+
this.type = type;
17+
this.controls = controls;
18+
this.autoplay = autoplay;
19+
this.loop = loop;
20+
this.muted = muted;
21+
this.preload = preload;
22+
this.sources = sources;
23+
}
24+
25+
render() {
26+
let attrs = `preload="${this.preload}"`;
27+
if (this.controls) attrs += ` controls`;
28+
if (this.autoplay) attrs += ` autoplay`;
29+
if (this.loop) attrs += ` loop`;
30+
if (this.muted) attrs += ` muted`;
31+
32+
if (this.sources && Array.isArray(this.sources)) {
33+
const sourceTags = this.sources
34+
.map(src => `<source src="${src.src}"${src.type ? ` type="${src.type}"` : ""}>`)
35+
.join("\n");
36+
return `<audio ${attrs}>\n${sourceTags}\n</audio>`;
37+
}
38+
39+
return `<audio src="${this.src}"${this.type ? ` type="${this.type}"` : ""} ${attrs}></audio>`;
40+
}
41+
}

0 commit comments

Comments
 (0)