sound-visualizer
Version:
94 lines (88 loc) • 3.21 kB
JavaScript
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/current/draw/impure.ts
var impure_exports = {};
__export(impure_exports, {
drawCurrentWave: () => drawCurrentWave
});
module.exports = __toCommonJS(impure_exports);
// src/common/draw/options.ts
var defaultDrawOptions = {
strokeColor: "#000",
rectWidth: 2
};
// src/current/draw/options.ts
var defaultOptions = __spreadProps(__spreadValues({}, defaultDrawOptions), {
heightNorm: 1
});
// src/common/draw/pure.ts
var THICKNESS_MAP = {
thin: 1,
default: 2,
thick: 2.75
};
function widthFromOption(lineWidth, canvasWidth) {
if (typeof lineWidth === "number")
return lineWidth;
return THICKNESS_MAP[lineWidth] / 300 * canvasWidth;
}
// src/current/draw/impure.ts
function drawCurrentWave(canvas, audioData, options = defaultOptions) {
const context = canvas.getContext("2d");
if (!context)
return;
const { strokeColor = "#000", rectWidth = "default", heightNorm = 1 } = options;
const { height, width } = canvas;
const sliceWidth = width / audioData.length;
context.lineWidth = widthFromOption(rectWidth, width);
context.strokeStyle = strokeColor;
context.clearRect(0, 0, width, height);
context.beginPath();
context.moveTo(0, height / 2);
for (let i = 0; i < audioData.length; i++) {
const x = i * sliceWidth;
const fraction = audioData[i] / 255;
const sectionSize = height * heightNorm;
const y = fraction * sectionSize + (height - sectionSize) * 0.5;
context.lineTo(x, y);
}
context.lineTo(sliceWidth * audioData.length, height / 2);
context.stroke();
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
drawCurrentWave
});
;