fix PictureInPicture render on image files (#841)
* fix(pictureInPicture): gate button for video media only * PictureInPicture: simplify media gating checks * PictureInPicture: guard mime check in shouldShowButton * fix replace & typeof * fix ugh * fix(pictureInPicture): handle array-shaped mimeType values * pictureInPicture: simplify mime type handling with join
This commit is contained in:
parent
37e7847ea2
commit
9db2d746e8
1 changed files with 10 additions and 2 deletions
|
|
@ -30,12 +30,20 @@ export default definePlugin({
|
|||
{
|
||||
find: '["VIDEO","CLIP","AUDIO"]',
|
||||
replacement: {
|
||||
match: /(\[\i>0&&\i\.length>0.{0,150}?children:)(\i.slice\(\i\))(?<=showDownload:(\i).+?isVisualMediaType:(\i).+?)/,
|
||||
replace: (_, rest, origChildren, showDownload, isVisualMediaType) => `${rest}[${showDownload}&&${isVisualMediaType}&&$self.PictureInPictureButton(),...${origChildren}]`
|
||||
match: /(\[\i>0&&\i\.length>0.{0,150}?children:)(\i.slice\(\i\))(?<=mimeType:(\i),downloadURL:(\i).+?showDownload:(\i).+?isVisualMediaType:(\i).+?)/,
|
||||
replace: (_, rest, origChildren, mimeType, downloadURL, showDownload, isVisualMediaType) =>
|
||||
`${rest}[${showDownload}&&${isVisualMediaType}&&$self.shouldShowButton(${mimeType},${downloadURL})&&$self.PictureInPictureButton(),...${origChildren}]`
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
shouldShowButton(mimeType: string[] = [], downloadURL?: string) {
|
||||
const normalizedMimeType = mimeType.join("/");
|
||||
if (normalizedMimeType.startsWith("video/")) return true;
|
||||
if (!downloadURL) return false;
|
||||
return /\.(mp4|webm|mov|m4v|ogv|avi)(?:$|[?#])/i.test(downloadURL);
|
||||
},
|
||||
|
||||
PictureInPictureButton: ErrorBoundary.wrap(() => {
|
||||
return (
|
||||
<Tooltip text="Toggle Picture in Picture">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue