File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed
Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.1.0/ ) ,
66and 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
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { Script } from "./core/Script.js";
1212import { Head } from "./core/Head.js" ;
1313import { Body } from "./core/Body.js" ;
1414import { Image } from "./core/Image.js" ;
15+ import { Audio } from "./core/Audio.js" ;
1516import { Heading } from "./core/Heading.js" ;
1617import { Separator } from "./core/Separator.js" ;
1718import { 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 ;
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments