/* One action control for the Downloads page and Settings download manager. */
(function(root) {
'use strict';
// One SVG definition per media concept; every instance inherits its control colour.
const mediaPaths = {
download: '',
offline: '',
progress: ''
};
const variants = {
'classic': mediaPaths,
'f7-swipe': {
download: '',
offline: '',
progress: ''
},
'glass-stage': {
download: '',
offline: '',
progress: ''
},
'bento-hub': {
download: '',
offline: '',
progress: ''
}
};
const use = kind => ``;
const svg = (kind, extra = '') => ``;
const media = { paths: mediaPaths, use, svg };
if (root.document) {
const defs = root.document.createElementNS('http://www.w3.org/2000/svg', 'svg');
defs.setAttribute('aria-hidden', 'true'); defs.setAttribute('width', '0'); defs.setAttribute('height', '0');
defs.style.position = 'absolute'; defs.style.pointerEvents = 'none';
defs.innerHTML = '' + Object.keys(mediaPaths).map(kind => `${Object.entries(variants).map(([layout, paths]) => `${paths[kind]}`).join('')}`).join('') + '';
root.document.body.appendChild(defs);
root.MediaIcons = media;
}
// Select variants on visible use elements: ancestor CSS in referenced SVG groups
// can report changed styles without repainting the cloned geometry in Chromium.
const transportPaths = {
play: '',
pause: '',
previous: '',
next: '',
forward: ''
};
for (const seconds of [10,15]) for (const direction of ['back','forward']) {
transportPaths[direction + seconds] = (direction === 'back'
? ''
: '') +
`${seconds}`;
}
const transportVariants = Object.fromEntries(['classic','f7-swipe','glass-stage','bento-hub'].map(layout => [layout,{...transportPaths}]));
Object.assign(transportVariants['f7-swipe'], {
play: '',
previous: '',
next: ''
});
const transport = {
paths: transportPaths, variants: transportVariants,
svg(kind) {
if (!transportPaths[kind]) throw new Error('Unknown transport icon: ' + kind);
return ``;
},
set(button, kind, label) {
if (!button) return;
const iconId=button.querySelector?.('.transport-icon')?.id;
button.innerHTML = this.svg(kind);
if(iconId)button.querySelector('.transport-icon').id=iconId;
button.setAttribute('aria-label', label || (kind === 'pause' ? 'Pause' : 'Play'));
}
};
if (root.document) {
const defs = root.document.createElementNS('http://www.w3.org/2000/svg','svg');
defs.setAttribute('aria-hidden','true'); defs.setAttribute('width','0'); defs.setAttribute('height','0');
defs.style.position='absolute'; defs.style.pointerEvents='none';
defs.innerHTML=''+Object.keys(transportPaths).flatMap(kind=>Object.entries(transportVariants).map(([layout,paths])=>`${paths[kind]}`)).join('')+'';
root.document.body.appendChild(defs); root.TransportIcons=transport;
}
const paths = {
retry: '',
cancel: '',
pause: '',
resume: '',
};
function create(doc, action, title) {
if (!paths[action]) throw new Error('Unknown download action');
const label = action[0].toUpperCase() + action.slice(1);
const button = doc.createElement('button'); button.type = 'button';
button.className = `dl-act download-action${action === 'cancel' ? ' danger' : ''}`;
button.setAttribute('aria-label', `${label} ${title}`);
const icon = doc.createElementNS('http://www.w3.org/2000/svg', 'svg');
icon.setAttribute('viewBox', '0 0 24 24'); icon.setAttribute('aria-hidden', 'true'); icon.setAttribute('focusable', 'false');
icon.classList.add('download-action-icon'); icon.innerHTML = paths[action];
const text = doc.createElement('span'); text.textContent = label;
button.append(icon, text); return button;
}
const api = { create, media, transport };
if (typeof module !== 'undefined' && module.exports) module.exports = api; else root.DownloadActions = api;
})(globalThis);