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

@@ -1,38 +1,38 @@
import { inverseClass, query, queryAll } from '../utils';
import { inverseClass, query, queryAll } from '../utils'
export default function aspectRatio(option) {
return (art) => {
const {
i18n,
constructor: { ASPECT_RATIO },
} = art;
return (art) => {
const {
i18n,
constructor: { ASPECT_RATIO },
} = art
const html = ASPECT_RATIO.map(
(item) => `<span data-value="${item}">${item === 'default' ? i18n.get('Default') : item}</span>`,
).join('');
const html = ASPECT_RATIO.map(
item => `<span data-value="${item}">${item === 'default' ? i18n.get('Default') : item}</span>`,
).join('')
return {
...option,
html: `${i18n.get('Aspect Ratio')}: ${html}`,
click: (contextmenu, event) => {
const { value } = event.target.dataset;
if (value) {
art.aspectRatio = value;
contextmenu.show = false;
}
},
mounted: ($panel) => {
const $default = query('[data-value="default"]', $panel);
if ($default) {
inverseClass($default, 'art-current');
}
art.on('aspectRatio', (value) => {
const $current = queryAll('span', $panel).find((item) => item.dataset.value === value);
if ($current) {
inverseClass($current, 'art-current');
}
});
},
};
};
return {
...option,
html: `${i18n.get('Aspect Ratio')}: ${html}`,
click: (contextmenu, event) => {
const { value } = event.target.dataset
if (value) {
art.aspectRatio = value
contextmenu.show = false
}
},
mounted: ($panel) => {
const $default = query('[data-value="default"]', $panel)
if ($default) {
inverseClass($default, 'art-current')
}
art.on('aspectRatio', (value) => {
const $current = queryAll('span', $panel).find(item => item.dataset.value === value)
if ($current) {
inverseClass($current, 'art-current')
}
})
},
}
}
}
+7 -7
View File
@@ -1,9 +1,9 @@
export default function close(option) {
return (art) => ({
...option,
html: art.i18n.get('Close'),
click: (contextmenu) => {
contextmenu.show = false;
},
});
return art => ({
...option,
html: art.i18n.get('Close'),
click: (contextmenu) => {
contextmenu.show = false
},
})
}
+31 -31
View File
@@ -1,36 +1,36 @@
import { inverseClass, query, queryAll, capitalize } from '../utils';
import { capitalize, inverseClass, query, queryAll } from '../utils'
export default function flip(option) {
return (art) => {
const {
i18n,
constructor: { FLIP },
} = art;
return (art) => {
const {
i18n,
constructor: { FLIP },
} = art
const html = FLIP.map((item) => `<span data-value="${item}">${i18n.get(capitalize(item))}</span>`).join('');
const html = FLIP.map(item => `<span data-value="${item}">${i18n.get(capitalize(item))}</span>`).join('')
return {
...option,
html: `${i18n.get('Video Flip')}: ${html}`,
click: (contextmenu, event) => {
const { value } = event.target.dataset;
if (value) {
art.flip = value.toLowerCase();
contextmenu.show = false;
}
},
mounted: ($panel) => {
const $default = query('[data-value="normal"]', $panel);
if ($default) {
inverseClass($default, 'art-current');
}
art.on('flip', (value) => {
const $current = queryAll('span', $panel).find((item) => item.dataset.value === value);
if ($current) {
inverseClass($current, 'art-current');
}
});
},
};
};
return {
...option,
html: `${i18n.get('Video Flip')}: ${html}`,
click: (contextmenu, event) => {
const { value } = event.target.dataset
if (value) {
art.flip = value.toLowerCase()
contextmenu.show = false
}
},
mounted: ($panel) => {
const $default = query('[data-value="normal"]', $panel)
if ($default) {
inverseClass($default, 'art-current')
}
art.on('flip', (value) => {
const $current = queryAll('span', $panel).find(item => item.dataset.value === value)
if ($current) {
inverseClass($current, 'art-current')
}
})
},
}
}
}
+111 -110
View File
@@ -1,118 +1,119 @@
import { setStyles, includeFromEvent, isMobile, getRect } from '../utils';
import Component from '../utils/component';
import playbackRate from './playbackRate';
import aspectRatio from './aspectRatio';
import flip from './flip';
import info from './info';
import version from './version';
import close from './close';
import { getRect, includeFromEvent, isMobile, setStyles } from '../utils'
import Component from '../utils/component'
import aspectRatio from './aspectRatio'
import close from './close'
import flip from './flip'
import info from './info'
import playbackRate from './playbackRate'
import version from './version'
export default class Contextmenu extends Component {
constructor(art) {
super(art);
constructor(art) {
super(art)
this.name = 'contextmenu';
this.$parent = art.template.$contextmenu;
this.name = 'contextmenu'
this.$parent = art.template.$contextmenu
if (!isMobile) {
this.init();
}
if (!isMobile) {
this.init()
}
}
init() {
const {
option,
proxy,
template: { $player, $contextmenu },
} = this.art
if (option.playbackRate) {
this.add(
playbackRate({
name: 'playbackRate',
index: 10,
}),
)
}
init() {
const {
option,
proxy,
template: { $player, $contextmenu },
} = this.art;
if (option.playbackRate) {
this.add(
playbackRate({
name: 'playbackRate',
index: 10,
}),
);
}
if (option.aspectRatio) {
this.add(
aspectRatio({
name: 'aspectRatio',
index: 20,
}),
);
}
if (option.flip) {
this.add(
flip({
name: 'flip',
index: 30,
}),
);
}
this.add(
info({
name: 'info',
index: 40,
}),
);
this.add(
version({
name: 'version',
index: 50,
}),
);
this.add(
close({
name: 'close',
index: 60,
}),
);
for (let index = 0; index < option.contextmenu.length; index++) {
this.add(option.contextmenu[index]);
}
proxy($player, 'contextmenu', (event) => {
if (!this.art.constructor.CONTEXTMENU) return;
event.preventDefault();
this.show = true;
const mouseX = event.clientX;
const mouseY = event.clientY;
const { height: cHeight, width: cWidth, left: cLeft, top: cTop } = getRect($player);
const { height: mHeight, width: mWidth } = getRect($contextmenu);
let menuLeft = mouseX - cLeft;
let menuTop = mouseY - cTop;
if (mouseX + mWidth > cLeft + cWidth) {
menuLeft = cWidth - mWidth;
}
if (mouseY + mHeight > cTop + cHeight) {
menuTop = cHeight - mHeight;
}
setStyles($contextmenu, {
top: `${menuTop}px`,
left: `${menuLeft}px`,
});
});
proxy($player, 'click', (event) => {
if (!includeFromEvent(event, $contextmenu)) {
this.show = false;
}
});
this.art.on('blur', () => {
this.show = false;
});
if (option.aspectRatio) {
this.add(
aspectRatio({
name: 'aspectRatio',
index: 20,
}),
)
}
if (option.flip) {
this.add(
flip({
name: 'flip',
index: 30,
}),
)
}
this.add(
info({
name: 'info',
index: 40,
}),
)
this.add(
version({
name: 'version',
index: 50,
}),
)
this.add(
close({
name: 'close',
index: 60,
}),
)
for (let index = 0; index < option.contextmenu.length; index++) {
this.add(option.contextmenu[index])
}
proxy($player, 'contextmenu', (event) => {
if (!this.art.constructor.CONTEXTMENU)
return
event.preventDefault()
this.show = true
const mouseX = event.clientX
const mouseY = event.clientY
const { height: cHeight, width: cWidth, left: cLeft, top: cTop } = getRect($player)
const { height: mHeight, width: mWidth } = getRect($contextmenu)
let menuLeft = mouseX - cLeft
let menuTop = mouseY - cTop
if (mouseX + mWidth > cLeft + cWidth) {
menuLeft = cWidth - mWidth
}
if (mouseY + mHeight > cTop + cHeight) {
menuTop = cHeight - mHeight
}
setStyles($contextmenu, {
top: `${menuTop}px`,
left: `${menuLeft}px`,
})
})
proxy($player, 'click', (event) => {
if (!includeFromEvent(event, $contextmenu)) {
this.show = false
}
})
this.art.on('blur', () => {
this.show = false
})
}
}
+8 -8
View File
@@ -1,10 +1,10 @@
export default function info(option) {
return (art) => ({
...option,
html: art.i18n.get('Video Info'),
click: (contextmenu) => {
art.info.show = true;
contextmenu.show = false;
},
});
return art => ({
...option,
html: art.i18n.get('Video Info'),
click: (contextmenu) => {
art.info.show = true
contextmenu.show = false
},
})
}
@@ -1,38 +1,39 @@
import { inverseClass, query, queryAll } from '../utils';
import { inverseClass, query, queryAll } from '../utils'
export default function playbackRate(option) {
return (art) => {
const {
i18n,
constructor: { PLAYBACK_RATE },
} = art;
return (art) => {
const {
i18n,
constructor: { PLAYBACK_RATE },
} = art
const html = PLAYBACK_RATE.map(
(item) => `<span data-value="${item}">${item === 1 ? i18n.get('Normal') : item.toFixed(1)}</span>`,
).join('');
const html = PLAYBACK_RATE.map(
item => `<span data-value="${item}">${item === 1 ? i18n.get('Normal') : item.toFixed(1)}</span>`,
).join('')
return {
...option,
html: `${i18n.get('Play Speed')}: ${html}`,
click: (contextmenu, event) => {
const { value } = event.target.dataset;
if (value) {
art.playbackRate = Number(value);
contextmenu.show = false;
}
},
mounted: ($panel) => {
const $default = query('[data-value="1"]', $panel);
if ($default) inverseClass($default, 'art-current');
art.on('video:ratechange', () => {
const $current = queryAll('span', $panel).find(
(item) => Number(item.dataset.value) === art.playbackRate,
);
if ($current) {
inverseClass($current, 'art-current');
}
});
},
};
};
return {
...option,
html: `${i18n.get('Play Speed')}: ${html}`,
click: (contextmenu, event) => {
const { value } = event.target.dataset
if (value) {
art.playbackRate = Number(value)
contextmenu.show = false
}
},
mounted: ($panel) => {
const $default = query('[data-value="1"]', $panel)
if ($default)
inverseClass($default, 'art-current')
art.on('video:ratechange', () => {
const $current = queryAll('span', $panel).find(
item => Number(item.dataset.value) === art.playbackRate,
)
if ($current) {
inverseClass($current, 'art-current')
}
})
},
}
}
}
@@ -1,8 +1,8 @@
import { version } from '../../package.json';
import { version } from '../../package.json'
export default function (option) {
return {
...option,
html: `<a href="https://artplayer.org" target="_blank">ArtPlayer ${version}</a>`,
};
return {
...option,
html: `<a href="https://artplayer.org" target="_blank">ArtPlayer ${version}</a>`,
}
}