build all

Refactor utility functions for improved readability and consistency

- Updated compatibility.js to use consistent line endings and formatting.
- Refactored component.js for better readability and structure, including consistent use of arrow functions and binding.
- Simplified dom.js functions with consistent formatting and improved readability.
- Enhanced emitter.js with consistent formatting and arrow function usage.
- Streamlined error.js for improved readability and consistency.
- Refactored file.js to use consistent formatting and improved readability.
- Improved format.js functions for better readability and consistency.
- Updated index.js to maintain consistent export formatting.
- Refactored property.js for improved readability and consistency.
- Enhanced subtitle.js with consistent formatting and improved readability.
- Refactored time.js for better readability and consistent formatting.

fix: update lint script to target only source files for consistency

Revert "fix: restore export statements for various plugins and update type definitions for better clarity"

This reverts commit b5e969d81ec765cd8a34b06e6ef4f232ef25087f.

fix: restore export statements for various plugins and update type definitions for better clarity

Refactor type definitions to use interfaces instead of type aliases for better extensibility and clarity across i18n, icons, option, player, quality, setting, subtitle, template, and utils modules.
This commit is contained in:
Harvey Zack committed 2025-08-03 13:17:33 +08:00
1 parent 532dd67cfd
commit 35ad9883af
447 files changed
+18248 -17946

No files matched your search

+131 -125
View File
@@ -1,150 +1,156 @@
import $quality from 'bundle-text:./quality.svg';
import $audio from 'bundle-text:./audio.svg';
import $audio from 'bundle-text:./audio.svg'
import $quality from 'bundle-text:./quality.svg'
function uniqBy(array, property) {
const seen = new Map();
return array.filter((item) => {
const key = item[property];
if (key === undefined) {
return true;
}
return !seen.has(key) && seen.set(key, 1);
});
const seen = new Map()
return array.filter((item) => {
const key = item[property]
if (key === undefined) {
return true
}
return !seen.has(key) && seen.set(key, 1)
})
}
export default function artplayerPluginHlsControl(option = {}) {
return (art) => {
const { $video } = art.template;
const { errorHandle } = art.constructor.utils;
return (art) => {
const { $video } = art.template
const { errorHandle } = art.constructor.utils
function updateQuality(hls) {
if (!hls.levels.length) return;
function updateQuality(hls) {
if (!hls.levels.length)
return
const config = option.quality || {};
const auto = config.auto || 'Auto';
const title = config.title || 'Quality';
const getName = config.getName || ((level) => level.name || level.height + 'P');
const defaultLevel = hls.levels[hls.currentLevel];
const defaultHtml = defaultLevel ? getName(defaultLevel) : auto;
const config = option.quality || {}
const auto = config.auto || 'Auto'
const title = config.title || 'Quality'
const getName = config.getName || (level => level.name || `${level.height}P`)
const defaultLevel = hls.levels[hls.currentLevel]
const defaultHtml = defaultLevel ? getName(defaultLevel) : auto
const selector = uniqBy(
hls.levels.map((item, index) => {
return {
html: getName(item, index),
value: index,
default: hls.currentLevel === index,
};
}),
'html',
).sort((a, b) => b.value - a.value);
const selector = uniqBy(
hls.levels.map((item, index) => {
return {
html: getName(item, index),
value: index,
default: hls.currentLevel === index,
}
}),
'html',
).sort((a, b) => b.value - a.value)
selector.push({
html: auto,
value: -1,
default: hls.currentLevel === -1,
});
selector.push({
html: auto,
value: -1,
default: hls.currentLevel === -1,
})
const onSelect = (item) => {
hls.currentLevel = item.value;
art.notice.show = `${title}: ${item.html}`;
if (config.control) art.controls.check(item);
if (config.setting) art.setting.check(item);
return item.html;
};
const onSelect = (item) => {
hls.currentLevel = item.value
art.notice.show = `${title}: ${item.html}`
if (config.control)
art.controls.check(item)
if (config.setting)
art.setting.check(item)
return item.html
}
if (config.control) {
art.controls.update({
name: 'hls-quality',
position: 'right',
html: defaultHtml,
style: { padding: '0 10px' },
selector: selector,
onSelect: onSelect,
});
}
if (config.control) {
art.controls.update({
name: 'hls-quality',
position: 'right',
html: defaultHtml,
style: { padding: '0 10px' },
selector,
onSelect,
})
}
if (config.setting) {
art.setting.update({
name: 'hls-quality',
tooltip: defaultHtml,
html: title,
icon: $quality,
width: 200,
selector: selector,
onSelect: onSelect,
});
}
}
if (config.setting) {
art.setting.update({
name: 'hls-quality',
tooltip: defaultHtml,
html: title,
icon: $quality,
width: 200,
selector,
onSelect,
})
}
}
function updateAudio(hls) {
if (!hls.audioTracks.length) return;
function updateAudio(hls) {
if (!hls.audioTracks.length)
return
const config = option.audio || {};
const auto = config.auto || 'Auto';
const title = config.title || 'Audio';
const getName = config.getName || ((track) => track.name || track.lang || track.language);
const defaultTrack = hls.audioTracks[hls.audioTrack];
const defaultHtml = defaultTrack ? getName(defaultTrack) : auto;
const config = option.audio || {}
const auto = config.auto || 'Auto'
const title = config.title || 'Audio'
const getName = config.getName || (track => track.name || track.lang || track.language)
const defaultTrack = hls.audioTracks[hls.audioTrack]
const defaultHtml = defaultTrack ? getName(defaultTrack) : auto
const selector = uniqBy(
hls.audioTracks.map((item, index) => {
return {
html: getName(item, index),
value: item.id,
default: hls.audioTrack === item.id,
};
}),
'html',
);
const selector = uniqBy(
hls.audioTracks.map((item, index) => {
return {
html: getName(item, index),
value: item.id,
default: hls.audioTrack === item.id,
}
}),
'html',
)
const onSelect = (item) => {
hls.audioTrack = item.value;
art.notice.show = `${title}: ${item.html}`;
if (config.control) art.controls.check(item);
if (config.setting) art.setting.check(item);
return item.html;
};
const onSelect = (item) => {
hls.audioTrack = item.value
art.notice.show = `${title}: ${item.html}`
if (config.control)
art.controls.check(item)
if (config.setting)
art.setting.check(item)
return item.html
}
if (config.control) {
art.controls.update({
name: 'hls-audio',
position: 'right',
html: defaultHtml,
style: { padding: '0 10px' },
selector: selector,
onSelect: onSelect,
});
}
if (config.control) {
art.controls.update({
name: 'hls-audio',
position: 'right',
html: defaultHtml,
style: { padding: '0 10px' },
selector,
onSelect,
})
}
if (config.setting) {
art.setting.update({
name: 'hls-audio',
tooltip: defaultHtml,
html: title,
icon: $audio,
width: 200,
selector: selector,
onSelect: onSelect,
});
}
}
if (config.setting) {
art.setting.update({
name: 'hls-audio',
tooltip: defaultHtml,
html: title,
icon: $audio,
width: 200,
selector,
onSelect,
})
}
}
function update() {
errorHandle(art.hls?.media === $video, 'Cannot find instance of HLS from "art.hls"');
updateQuality(art.hls);
updateAudio(art.hls);
}
function update() {
errorHandle(art.hls?.media === $video, 'Cannot find instance of HLS from "art.hls"')
updateQuality(art.hls)
updateAudio(art.hls)
}
art.on('ready', update);
art.on('restart', update);
art.on('ready', update)
art.on('restart', update)
return {
name: 'artplayerPluginHlsControl',
update,
};
};
return {
name: 'artplayerPluginHlsControl',
update,
}
}
}
if (typeof window !== 'undefined') {
window['artplayerPluginHlsControl'] = artplayerPluginHlsControl;
window.artplayerPluginHlsControl = artplayerPluginHlsControl
}