mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-20 12:11:20 -08:00
refactor: improve document Picture-in-Picture support checks and update type definitions
- Renamed variable `dpipOK` to `isSupported` for clarity in checking Document Picture-in-Picture support. - Updated the `open` function to use the new `isSupported` variable. - Removed redundant checks in the `close` function related to Document Picture-in-Picture support. - Added `isSupported` and `isActive` properties to the plugin's result interface in TypeScript definitions. - Cleaned up the code for better readability and maintainability.
This commit is contained in:
1 parent
a7d77f4f70
commit
657dd7e77c
13 files changed
+25
-38
No files matched your search
@@ -173,7 +173,7 @@ function artplayerPluginDocumentPip(userOptions = {}) {
|
||||
...userOptions
|
||||
};
|
||||
return (art)=>{
|
||||
const dpipOK = 'documentPictureInPicture' in window && typeof window.documentPictureInPicture?.requestWindow === 'function';
|
||||
const isSupported = 'documentPictureInPicture' in window && typeof window.documentPictureInPicture?.requestWindow === 'function';
|
||||
const { proxy, icons, i18n, template: { $container }, constructor: { utils: { append, tooltip, addClass, removeClass } } } = art;
|
||||
const state = {
|
||||
win: null,
|
||||
@@ -216,7 +216,7 @@ function artplayerPluginDocumentPip(userOptions = {}) {
|
||||
} catch {}
|
||||
}
|
||||
async function open() {
|
||||
if (!dpipOK && options.fallbackToVideoPiP) {
|
||||
if (!isSupported && options.fallbackToVideoPiP) {
|
||||
art.pip = true;
|
||||
console.warn('[artplayer-plugin-document-pip] Document Picture-in-Picture is not supported, falling back to Video Picture-in-Picture');
|
||||
return;
|
||||
@@ -270,10 +270,6 @@ function artplayerPluginDocumentPip(userOptions = {}) {
|
||||
state.currentDoc = backDoc;
|
||||
}
|
||||
function close() {
|
||||
if (!dpipOK && options.fallbackToVideoPiP) {
|
||||
art.pip = false;
|
||||
return;
|
||||
}
|
||||
if (!state.win) return;
|
||||
try {
|
||||
state.cleanup?.();
|
||||
@@ -307,7 +303,12 @@ function artplayerPluginDocumentPip(userOptions = {}) {
|
||||
art.on('destroy', close);
|
||||
return {
|
||||
name: 'artplayerPluginDocumentPip',
|
||||
state,
|
||||
get isSupported () {
|
||||
return isSupported;
|
||||
},
|
||||
get isActive () {
|
||||
return !!state.win;
|
||||
},
|
||||
open,
|
||||
close,
|
||||
toggle
|
||||
|
||||
Reference in new issue
Block a user