Hide video controls if player too small

This commit is contained in:
Freeplay 2023-05-28 13:57:25 -04:00
parent d8810600bf
commit cb164d0f0a
2 changed files with 48 additions and 17 deletions

View file

@ -6,13 +6,9 @@
:media="media" :media="media"
/> />
<div <div
v-if="mediaList.filter((media) => previewable(media)).length > 0" v-if="previewableCount > 0"
class="grid-container" class="grid-container"
:data-count=" :data-count="previewableCount < 5 ? previewableCount : null"
mediaList.filter((media) => previewable(media)).length < 5
? mediaList.filter((media) => previewable(media)).length
: null
"
:class="{ dmWidth: inDm }" :class="{ dmWidth: inDm }"
> >
<div <div
@ -193,6 +189,7 @@ const previewable = (file: misskey.entities.DriveFile): boolean => {
FILE_TYPE_BROWSERSAFE.includes(file.type) FILE_TYPE_BROWSERSAFE.includes(file.type)
); );
}; };
const previewableCount = props.mediaList.filter((media) => previewable(media)).length;
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View file

@ -12,8 +12,9 @@
<span>{{ i18n.ts.clickToShow }}</span> <span>{{ i18n.ts.clickToShow }}</span>
</div> </div>
</div> </div>
<div v-else class="kkjnbbplepmiyuadieoenjgutgcmtsvu"> <div v-else class="video" :class="{ mini }">
<VuePlyr <VuePlyr
ref="plyr"
:options="{ :options="{
controls: [ controls: [
'play-large', 'play-large',
@ -40,12 +41,18 @@
<source :src="video.url" :type="video.type" /> <source :src="video.url" :type="video.type" />
</video> </video>
</VuePlyr> </VuePlyr>
<i class="ph-eye-slash ph-bold ph-lg" @click="hide = true"></i> <button
v-tooltip="i18n.ts.hide"
class="_button hide"
@click="hide = true"
>
<i class="ph-eye-slash ph-bold ph-lg"></i>
</button>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from "vue"; import { onMounted, ref } from "vue";
import VuePlyr from "vue-plyr"; import VuePlyr from "vue-plyr";
import type * as misskey from "calckey-js"; import type * as misskey from "calckey-js";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";
@ -56,31 +63,47 @@ const props = defineProps<{
video: misskey.entities.DriveFile; video: misskey.entities.DriveFile;
}>(); }>();
const plyr = ref();
const mini = ref(false);
const hide = ref( const hide = ref(
defaultStore.state.nsfw === "force" defaultStore.state.nsfw === "force"
? true ? true
: props.video.isSensitive && defaultStore.state.nsfw !== "ignore" : props.video.isSensitive && defaultStore.state.nsfw !== "ignore"
); );
onMounted(() => {
mini.value = plyr.value.player.media.scrollWidth < 300;
if (mini.value) {
plyr.value.player.on('play', () => {
plyr.value.player.fullscreen.enter();
});
}
})
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.kkjnbbplepmiyuadieoenjgutgcmtsvu { .video {
position: relative; position: relative;
--plyr-color-main: var(--accent); --plyr-color-main: var(--accent);
> i { > .hide {
display: block; display: block;
position: absolute; position: absolute;
border-radius: 6px; border-radius: 6px;
background-color: var(--fg); background-color: var(--accentedBg);
color: var(--accentLighten); -webkit-backdrop-filter: var(--blur, blur(15px));
font-size: 14px; backdrop-filter: var(--blur, blur(15px));
opacity: 0.5; color: var(--accent);
padding: 3px 6px; font-size: 0.8em;
padding: 6px 8px;
text-align: center; text-align: center;
cursor: pointer;
top: 12px; top: 12px;
right: 12px; right: 12px;
> i {
display: block;
}
} }
> video { > video {
@ -95,6 +118,17 @@ const hide = ref(
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
&.mini {
:deep(.plyr:not(:fullscreen)) {
min-width: unset !important;
.plyr__progress__container,
.plyr__volume,
[data-plyr="fullscreen"] {
display: none;
}
}
}
} }
.icozogqfvdetwohsdglrbswgrejoxbdj { .icozogqfvdetwohsdglrbswgrejoxbdj {