// SPDX-FileCopyrightText: Chris Pressey, the creator of this work, has dedicated it to the public domain.
// For more information, please refer to <https://unlicense.org/>
// SPDX-License-Identifier: Unlicense
/* dam-download-image-button.js version 0.2-2025.12 */
(function() {
function makeDownloadImageButton(config) {
var button = DAM.maker('button');
var canvas = config.canvas;
var label = config.label || "Download Image";
var basename = config.basename || "canvas";
return button(label, {
onclick: function() {
const timestamp = new Date().toISOString().slice(0, 19).replace(/[T:]/g, '-');
const filename = basename + "-" + timestamp + ".png";
canvas.toBlob(function(blob) {
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.download = filename;
link.href = url;
link.click();
URL.revokeObjectURL(url);
}, 'image/png');
}
})
}
if (typeof module !== 'undefined') {
module.exports = { makeDownloadImageButton: makeDownloadImageButton };
} else if (typeof window !== 'undefined') {
window.DAM = window.DAM || {};
DAM.makeDownloadImageButton = makeDownloadImageButton;
}
})();