Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add part attribute to timeline #3481

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/plugins/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ class TimelinePlugin extends BasePlugin<TimelinePluginEvents, TimelinePluginOpti
},
})

timeline.setAttribute('part', 'timeline')

if (typeof this.options.style === 'string') {
timeline.setAttribute('style', timeline.getAttribute('style') + this.options.style)
} else if (typeof this.options.style === 'object') {
Expand Down
6 changes: 5 additions & 1 deletion src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class Renderer extends EventEmitter<RendererEvents> {

<div class="scroll" part="scroll">
<div class="wrapper" part="wrapper">
<div class="canvases"></div>
<div class="canvases" part="canvases"></div>
<div class="progress" part="progress"></div>
<div class="cursor" part="cursor"></div>
</div>
Expand Down Expand Up @@ -424,6 +424,7 @@ class Renderer extends EventEmitter<RendererEvents> {
) {
const pixelRatio = window.devicePixelRatio || 1
const canvas = document.createElement('canvas')
canvas.setAttribute('part', 'canvas canvas-wave')
const length = channelData[0].length
canvas.width = Math.round((width * (end - start)) / length)
canvas.height = height * pixelRatio
Expand All @@ -443,6 +444,7 @@ class Renderer extends EventEmitter<RendererEvents> {
// Draw a progress canvas
if (canvas.width > 0 && canvas.height > 0) {
const progressCanvas = canvas.cloneNode() as HTMLCanvasElement
progressCanvas.setAttribute('part', 'canvas canvas-progress');
const progressCtx = progressCanvas.getContext('2d') as CanvasRenderingContext2D
progressCtx.drawImage(canvas, 0, 0)
// Set the composition method to draw only where the waveform is drawn
Expand All @@ -457,13 +459,15 @@ class Renderer extends EventEmitter<RendererEvents> {
private renderChannel(channelData: Array<Float32Array | number[]>, options: WaveSurferOptions, width: number) {
// A container for canvases
const canvasContainer = document.createElement('div')
canvasContainer.setAttribute('part', 'canvas-container')
const height = this.getHeight(options.height)
canvasContainer.style.height = `${height}px`
this.canvasWrapper.style.minHeight = `${height}px`
this.canvasWrapper.appendChild(canvasContainer)

// A container for progress canvases
const progressContainer = canvasContainer.cloneNode() as HTMLElement
progressContainer.setAttribute('part', 'progress-container')
this.progressWrapper.appendChild(progressContainer)

// Determine the currently visible part of the waveform
Expand Down