Skip to content

Commit

Permalink
Enable isolatedDeclarations
Browse files Browse the repository at this point in the history
  • Loading branch information
enjikaka committed Feb 17, 2025
1 parent 018d06f commit a549c31
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
21 changes: 9 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function generateCoordinates(i, frequencyData, canvasWidth, canvasHeight) {
return [x, y];
}

export const html = (...args) => {
export const html: (args: TemplateStringsArray) => Node = (...args) => {
// @ts-ignore
const text = String.raw(...args);

Expand Down Expand Up @@ -46,10 +46,7 @@ export default class AudioVisualiser extends HTMLElement {
this.#resizeObserver = new ResizeObserver(entry => requestAnimationFrame(() => this.updateCanvasSize(entry[0])));
}

/**
* @param {AnalyserNode} analyser
*/
set analyser(analyser) {
set analyser(analyser: AnalyserNode) {
if (analyser instanceof AnalyserNode) {
this.#analyser = analyser;
} else {
Expand All @@ -59,24 +56,24 @@ export default class AudioVisualiser extends HTMLElement {
}
}

static get observedAttributes() {
static get observedAttributes(): string[] {
return ['color'];
}

attributeChangedCallback(name, oldValue, newValue) {
attributeChangedCallback(name: string, oldValue: string, newValue: string): void {
if (name === 'color' && newValue && newValue !== oldValue) {
this.fillStyle = newValue;
this.updateCanvasColor();
}
}

stop() {
stop(): void {
cancelAnimationFrame(this.#animationLoop);

this.#animationLoop = undefined;
}

start() {
start(): void {
if (!this.#analyser) {
throw new ReferenceError('Analyser has not been set');
}
Expand Down Expand Up @@ -119,13 +116,13 @@ export default class AudioVisualiser extends HTMLElement {
}
}

updateCanvasColor() {
updateCanvasColor(): void {
if (this.#context) {
this.#context.fillStyle = this.fillStyle;
}
}

render() {
render(): void {
const sDOM = this.#sDOM;

sDOM.appendChild(template.cloneNode(true));
Expand All @@ -140,7 +137,7 @@ export default class AudioVisualiser extends HTMLElement {
this.#resizeObserver.observe(this.#canvas);
}

connectedCallback() {
connectedCallback(): void {
this.#sDOM = this.attachShadow({ mode: 'closed' });

this.render();
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"target": "ES2024",
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "pkg"
"outDir": "pkg",
"isolatedDeclarations": true
},
"include": ["src/*"]
}

0 comments on commit a549c31

Please sign in to comment.