@maas/vue-equipment 0.12.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@maas/vue-equipment",
3
3
  "configKey": "vueEquipment",
4
- "version": "0.11.6"
4
+ "version": "0.12.0"
5
5
  }
@@ -11,6 +11,7 @@
11
11
  class="magic-player-video"
12
12
  preload="auto"
13
13
  playsinline
14
+ disablePictureInPicture
14
15
  />
15
16
  <div v-show="!loaded || !touched" class="magic-player-poster">
16
17
  <slot name="poster" />
@@ -20,7 +21,7 @@
20
21
  </template>
21
22
 
22
23
  <script setup lang="ts">
23
- import { ref, computed, toRefs } from 'vue'
24
+ import { ref, computed } from 'vue'
24
25
  import { useIntersectionObserver } from '@vueuse/core'
25
26
  import { usePlayerApi } from '../composables/usePlayerApi'
26
27
 
@@ -32,6 +33,7 @@ export type MagicPlayerProps = {
32
33
  src: string
33
34
  ratio?: string
34
35
  fill?: boolean
36
+ autoplay?: boolean
35
37
  }
36
38
 
37
39
  const props = withDefaults(defineProps<MagicPlayerProps>(), {
@@ -39,6 +41,7 @@ const props = withDefaults(defineProps<MagicPlayerProps>(), {
39
41
  src: '',
40
42
  ratio: '16:9',
41
43
  fill: false,
44
+ autoplay: false,
42
45
  })
43
46
 
44
47
  const playerRef = ref<HTMLDivElement | undefined>(undefined)
@@ -53,16 +56,24 @@ const { instance } = usePlayerApi({
53
56
  src: props.src,
54
57
  })
55
58
 
56
- const { playing } = toRefs(instance.value?.mediaApi)
57
- const { touched } = toRefs(instance.value?.playerApi)
59
+ const { playing } = instance.value?.mediaApi
60
+ const { touched } = instance.value?.playerApi
58
61
  const { onMouseenter, onMouseleave } = instance.value?.playerApi
59
- const { loaded } = toRefs(instance.value?.runtimeProvider)
62
+ const { loaded } = instance.value?.runtimeProvider
60
63
 
61
- useIntersectionObserver(playerRef, ([{ isIntersecting }]) => {
62
- if (!isIntersecting && playing.value) {
63
- instance.value.playerApi.pause()
64
- }
65
- })
64
+ useIntersectionObserver(
65
+ playerRef,
66
+ ([{ isIntersecting }]) => {
67
+ if (!isIntersecting && playing.value) {
68
+ instance.value.playerApi.pause()
69
+ } else if (isIntersecting && !playing.value && props.autoplay) {
70
+ instance.value.playerApi.play()
71
+ }
72
+ },
73
+ {
74
+ immediate: true,
75
+ },
76
+ )
66
77
 
67
78
  const computedRatio = computed(() => {
68
79
  if (props.ratio) {
@@ -84,12 +95,15 @@ const computedStyle = computed(() => {
84
95
  </script>
85
96
 
86
97
  <style lang="css">
98
+ :root {
99
+ --magic-player-aspect-ratio: 16 / 9;
100
+ }
101
+
87
102
  .magic-player {
88
- --aspect-ratio: 16 / 9;
89
103
  position: relative;
90
104
  width: 100%;
91
105
  overflow: hidden;
92
- aspect-ratio: var(--aspect-ratio);
106
+ aspect-ratio: var(--magic-player-aspect-ratio);
93
107
  }
94
108
 
95
109
  .magic-player-video {
@@ -5,6 +5,7 @@ export type MagicPlayerProps = {
5
5
  src: string;
6
6
  ratio?: string;
7
7
  fill?: boolean;
8
+ autoplay?: boolean;
8
9
  };
9
10
  declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
10
11
  fill: {
@@ -28,6 +29,10 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
28
29
  type: import("vue").PropType<string>;
29
30
  default: string;
30
31
  };
32
+ autoplay: {
33
+ type: import("vue").PropType<boolean>;
34
+ default: boolean;
35
+ };
31
36
  }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
32
37
  fill: {
33
38
  type: import("vue").PropType<boolean>;
@@ -50,11 +55,16 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
50
55
  type: import("vue").PropType<string>;
51
56
  default: string;
52
57
  };
58
+ autoplay: {
59
+ type: import("vue").PropType<boolean>;
60
+ default: boolean;
61
+ };
53
62
  }>>, {
54
63
  fill: boolean;
55
64
  srcType: SourceType;
56
65
  src: string;
57
66
  ratio: string;
67
+ autoplay: boolean;
58
68
  }, {}>, {
59
69
  poster?(_: {}): any;
60
70
  default?(_: {}): any;
@@ -72,7 +72,7 @@
72
72
  </template>
73
73
 
74
74
  <script setup lang="ts">
75
- import { ref, toRefs } from 'vue'
75
+ import { ref } from 'vue'
76
76
  import { useIdle } from '@vueuse/core'
77
77
  import IconPlay from './icons/Play.vue'
78
78
  import IconPause from './icons/Pause.vue'
@@ -99,11 +99,9 @@ const { instance } = usePlayerApi({
99
99
  popoverRef: popoverRef,
100
100
  })
101
101
 
102
- const { playing, waiting, muted } = toRefs(instance.value?.mediaApi)
103
- const { touched, mouseEntered, isFullscreen } = toRefs(
104
- instance.value?.playerApi,
105
- )
106
- const { popoverOffsetX, seekedTime } = toRefs(instance.value?.controlsApi)
102
+ const { playing, waiting, muted } = instance.value.mediaApi
103
+ const { touched, mouseEntered, isFullscreen } = instance.value.playerApi
104
+ const { popoverOffsetX, seekedTime } = instance.value.controlsApi
107
105
 
108
106
  const { play, pause, mute, unmute, enterFullscreen, exitFullscreen } =
109
107
  instance.value.playerApi
@@ -14,7 +14,7 @@
14
14
  </div>
15
15
  </template>
16
16
  <script setup lang="ts">
17
- import { shallowRef, onMounted, watch, computed, toRefs, type Ref } from 'vue'
17
+ import { shallowRef, onMounted, watch, computed, type Ref } from 'vue'
18
18
  import { useDevicePixelRatio } from '@vueuse/core'
19
19
  import { usePlayerApi } from '../composables/usePlayerApi'
20
20
 
@@ -39,7 +39,7 @@ const props = defineProps<Props>()
39
39
 
40
40
  const { instance } = usePlayerApi(props.id)
41
41
 
42
- const { seekedTime } = toRefs(instance.value.controlsApi)
42
+ const { seekedTime } = instance.value.controlsApi
43
43
  const { pixelRatio } = useDevicePixelRatio()
44
44
 
45
45
  const canvas = shallowRef() as Ref<HTMLCanvasElement>
@@ -34,7 +34,7 @@
34
34
  </template>
35
35
 
36
36
  <script setup lang="ts">
37
- import { toRefs } from 'vue'
37
+ import {} from 'vue'
38
38
  import { useIdle } from '@vueuse/core'
39
39
  import IconPlay from './icons/Play.vue'
40
40
  import IconPause from './icons/Pause.vue'
@@ -49,9 +49,8 @@ const props = defineProps<Props>()
49
49
 
50
50
  const { instance } = usePlayerApi(props.id)
51
51
 
52
- const { playing, waiting } = toRefs(instance.value.mediaApi)
53
- const { mouseEntered } = toRefs(instance.value.playerApi)
54
- const { togglePlay } = instance.value.playerApi
52
+ const { playing, waiting } = instance.value.mediaApi
53
+ const { mouseEntered, togglePlay } = instance.value.playerApi
55
54
 
56
55
  const { idle } = useIdle(3000)
57
56
  </script>
@@ -36,7 +36,7 @@
36
36
  </template>
37
37
 
38
38
  <script setup lang="ts">
39
- import { toRefs } from 'vue'
39
+ import {} from 'vue'
40
40
  import { usePlayerApi } from '../composables/usePlayerApi'
41
41
 
42
42
  interface Props {
@@ -51,7 +51,7 @@ const {
51
51
  seekedPercentage,
52
52
  scrubbedPercentage,
53
53
  bufferedPercentage,
54
- } = toRefs(instance.value.controlsApi)
54
+ } = instance.value.controlsApi
55
55
 
56
56
  const {
57
57
  onMouseenter,
@@ -1,4 +1,4 @@
1
- import { ref, computed, watch, toValue, toRefs } from "vue";
1
+ import { ref, computed, watch, toValue } from "vue";
2
2
  import {
3
3
  useResizeObserver,
4
4
  useEventListener,
@@ -9,7 +9,7 @@ import { usePlayerStore } from "./usePlayerStore.mjs";
9
9
  export function useControlsApi(args) {
10
10
  const { findInstance } = usePlayerStore();
11
11
  const instance = findInstance(toValue(args.id));
12
- const { buffered, duration, playing, currentTime } = toRefs(instance.mediaApi);
12
+ const { buffered, duration, playing, currentTime } = instance.mediaApi;
13
13
  const { play, pause, seek } = instance.playerApi;
14
14
  const dragging = ref(false);
15
15
  const mouseEntered = ref(false);
@@ -1,4 +1,4 @@
1
- import { ref, watch, toRefs, toValue } from "vue";
1
+ import { ref, watch, toValue } from "vue";
2
2
  import { useFullscreen } from "@vueuse/core";
3
3
  import { isIOS } from "@maas/vue-equipment/utils";
4
4
  import { usePlayerStore } from "./usePlayerStore.mjs";
@@ -8,7 +8,7 @@ export function usePlayerInternalApi(args) {
8
8
  const fullscreenTarget = isIOS() ? args.videoRef : args.playerRef;
9
9
  const { findInstance } = usePlayerStore();
10
10
  const instance = findInstance(toValue(args.id));
11
- const { currentTime, playing, muted } = toRefs(instance.mediaApi);
11
+ const { currentTime, playing, muted } = instance.mediaApi;
12
12
  const {
13
13
  isFullscreen,
14
14
  enter: enterFullscreen,
@@ -1,17 +1,19 @@
1
- import { type Ref } from 'vue';
1
+ import { type ShallowRef } from 'vue';
2
2
  import type { UseMediaApiReturn } from './useMediaApi.js';
3
3
  import type { UsePlayerInternalApiReturn } from './usePlayerInternalApi.js';
4
4
  import type { UseRuntimeSourceProviderReturn } from './useRuntimeSourceProvider.js';
5
5
  import type { UseControlsApiReturn } from './useControlsApi.js';
6
+ import type { UsePlayerApiArgs } from '../../types.js';
6
7
  export interface PlayerInstance {
7
8
  id: string;
8
9
  mediaApi: UseMediaApiReturn;
9
10
  playerApi: UsePlayerInternalApiReturn;
10
11
  controlsApi: UseControlsApiReturn;
11
12
  runtimeProvider: UseRuntimeSourceProviderReturn;
13
+ args: UsePlayerApiArgs;
12
14
  }
13
15
  export declare function usePlayerStore(): {
14
- playerStore: Ref<PlayerInstance[]>;
16
+ playerStore: ShallowRef<PlayerInstance[]>;
15
17
  findInstance: (id: string) => PlayerInstance;
16
18
  addInstance: (id: string) => PlayerInstance;
17
19
  removeInstance: (id: string) => void;
@@ -1,13 +1,19 @@
1
- import { ref, reactive } from "vue";
2
- const playerStore = ref([]);
1
+ import { shallowRef, reactive } from "vue";
2
+ const playerStore = shallowRef([]);
3
3
  export function usePlayerStore() {
4
+ const defaultMediaApi = reactive({});
5
+ const defaultPlayerApi = reactive({});
6
+ const defaultControlsApi = reactive({});
7
+ const defaultRuntimeProvider = reactive({});
8
+ const defaultArgs = reactive({});
4
9
  function createInstance(id) {
5
10
  const instance = {
6
11
  id,
7
- mediaApi: reactive({}),
8
- playerApi: reactive({}),
9
- controlsApi: reactive({}),
10
- runtimeProvider: reactive({})
12
+ mediaApi: defaultMediaApi,
13
+ playerApi: defaultPlayerApi,
14
+ controlsApi: defaultControlsApi,
15
+ runtimeProvider: defaultRuntimeProvider,
16
+ args: defaultArgs
11
17
  };
12
18
  return instance;
13
19
  }
@@ -1,5 +1,6 @@
1
+ import { type MaybeRef } from 'vue';
1
2
  import type { UsePlayerApiArgs } from '../types.js';
2
- export declare function usePlayerApi(args: UsePlayerApiArgs): {
3
+ export declare function usePlayerApi(args: UsePlayerApiArgs | MaybeRef<string>): {
3
4
  instance: import("vue").ComputedRef<import("./private/usePlayerStore").PlayerInstance>;
4
5
  };
5
6
  export type UsePlayerApiReturn = ReturnType<typeof usePlayerApi>;
@@ -19,7 +19,7 @@ type UseRuntimeSourceProviderArgs = {
19
19
  srcType: SourceType;
20
20
  src: string;
21
21
  };
22
- type UsePlayerApiArgs = MaybeRef<string> | (Partial<UseMediaApiArgs & UseControlsApiArgs & UsePlayerInternalApiArgs & UseRuntimeSourceProviderArgs> & {
22
+ type UsePlayerApiArgs = Partial<UseMediaApiArgs & UseControlsApiArgs & UsePlayerInternalApiArgs & UseRuntimeSourceProviderArgs> & {
23
23
  id: MaybeRef<string>;
24
- });
24
+ };
25
25
  export type { SourceType, UseMediaApiArgs, UsePlayerApiArgs, UseControlsApiArgs, UsePlayerInternalApiArgs, UseRuntimeSourceProviderArgs, };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maas/vue-equipment",
3
3
  "description": "A magic collection of Vue composables, plugins, components and directives",
4
- "version": "0.12.0",
4
+ "version": "0.12.1",
5
5
  "author": "Robin Scholz <https://github.com/robinscholz>, Christoph Jeworutzki <https://github.com/ChristophJeworutzki>",
6
6
  "devDependencies": {
7
7
  "@antfu/ni": "^0.21.5",