@uibit/video 0.1.1 → 0.2.0

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,40 +1,39 @@
1
1
  import { Component, ChangeDetectionStrategy, ElementRef, input, effect, output, booleanAttribute } from '@angular/core';
2
2
  import '@uibit/video';
3
3
  import type { Video as HTMLElementClass } from '@uibit/video';
4
-
5
4
  @Component({
6
- selector: 'uibit-video',
7
- template: '<ng-content></ng-content>',
8
- changeDetection: ChangeDetectionStrategy.OnPush,
9
- standalone: true,
10
- host: {
11
- '(play)': 'play.emit($event)',
12
- '(pause)': 'pause.emit($event)'
13
- }
5
+ selector: 'uibit-video',
6
+ template: '<ng-content></ng-content>',
7
+ changeDetection: ChangeDetectionStrategy.OnPush,
8
+ standalone: true,
9
+ host: {
10
+ '(play)': 'play.emit($event)',
11
+ '(pause)': 'pause.emit($event)'
12
+ }
14
13
  })
15
14
  export class NgxVideo {
16
- constructor(private el: ElementRef<HTMLElementClass>) {
17
- effect(() => {
18
- if (this.el.nativeElement) {
19
- this.el.nativeElement.poster = this.poster();
20
- }
15
+ constructor(private el: ElementRef<HTMLElementClass>){
16
+ effect(()=>{
17
+ if (this.el.nativeElement) {
18
+ this.el.nativeElement.poster = this.poster();
19
+ }
20
+ });
21
+ effect(()=>{
22
+ if (this.el.nativeElement) {
23
+ this.el.nativeElement.controls = this.controls();
24
+ }
25
+ });
26
+ effect(()=>{
27
+ if (this.el.nativeElement) {
28
+ this.el.nativeElement.locale = this.locale();
29
+ }
30
+ });
31
+ }
32
+ readonly poster = input<string>('');
33
+ readonly controls = input<boolean, any>(true, {
34
+ transform: booleanAttribute
21
35
  });
22
- effect(() => {
23
- if (this.el.nativeElement) {
24
- this.el.nativeElement.controls = this.controls();
25
- }
26
- });
27
- effect(() => {
28
- if (this.el.nativeElement) {
29
- this.el.nativeElement.locale = this.locale();
30
- }
31
- });
32
- }
33
-
34
- readonly poster = input<string, any>('');
35
- readonly controls = input<boolean, any>(true, { transform: booleanAttribute });
36
- readonly locale = input<string, any>('');
37
-
38
- readonly play = output<CustomEvent<any>>();
39
- readonly pause = output<CustomEvent<any>>();
36
+ readonly locale = input<string>('');
37
+ readonly play = output<CustomEvent<any>>();
38
+ readonly pause = output<CustomEvent<any>>();
40
39
  }
@@ -4,7 +4,13 @@ import '@uibit/video';
4
4
  declare global {
5
5
  namespace astroHTML.JSX {
6
6
  interface IntrinsicElements {
7
- 'uibit-video': Partial<HTMLElementClass> & astroHTML.JSX.HTMLAttributes;
7
+ 'uibit-video': Partial<HTMLElementClass> & astroHTML.JSX.HTMLAttributes & {
8
+ poster?: string;
9
+ controls?: boolean;
10
+ locale?: string;
11
+ "on:play"?: (event: Event) => void;
12
+ "on:pause"?: (event: Event) => void;
13
+ };
8
14
  }
9
15
  }
10
16
  }
@@ -9,6 +9,10 @@ declare module 'preact' {
9
9
  poster?: string;
10
10
  controls?: boolean;
11
11
  locale?: string;
12
+ onPlay?: (event: Event) => void;
13
+ "on:play"?: (event: Event) => void;
14
+ onPause?: (event: Event) => void;
15
+ "on:pause"?: (event: Event) => void;
12
16
  };
13
17
  }
14
18
  }
@@ -0,0 +1,104 @@
1
+ import React, { useRef, useEffect, useLayoutEffect, useImperativeHandle } from 'react';
2
+ import type { Video as HTMLElementClass } from '@uibit/video';
3
+ import '@uibit/video';
4
+ const useTypeOfLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
5
+ export interface VideoProps extends Omit<React.HTMLAttributes<HTMLElementClass>, 'poster' | 'controls' | 'locale' | 'onPlay' | 'onPause'> {
6
+ children?: React.ReactNode;
7
+ poster?: string;
8
+ controls?: boolean;
9
+ locale?: string;
10
+ onPlay?: (event: Event) => void;
11
+ onPause?: (event: Event) => void;
12
+ }
13
+ export const Video = ({ ref, children, ...props }: VideoProps & {
14
+ ref?: React.Ref<HTMLElementClass>;
15
+ })=>{
16
+ const innerRef = useRef<HTMLElementClass>(null);
17
+ const propsRef = useRef(props);
18
+ propsRef.current = props;
19
+ useImperativeHandle(ref, ()=>innerRef.current!);
20
+ useTypeOfLayoutEffect(()=>{
21
+ const element = innerRef.current;
22
+ if (element && props.poster !== undefined) {
23
+ (element as any).poster = props.poster;
24
+ }
25
+ }, [
26
+ props.poster
27
+ ]);
28
+ useTypeOfLayoutEffect(()=>{
29
+ const element = innerRef.current;
30
+ if (element && props.controls !== undefined) {
31
+ (element as any).controls = props.controls;
32
+ }
33
+ }, [
34
+ props.controls
35
+ ]);
36
+ useTypeOfLayoutEffect(()=>{
37
+ const element = innerRef.current;
38
+ if (element && props.locale !== undefined) {
39
+ (element as any).locale = props.locale;
40
+ }
41
+ }, [
42
+ props.locale
43
+ ]);
44
+ useTypeOfLayoutEffect(()=>{
45
+ const element = innerRef.current;
46
+ if (!element) return;
47
+ const handleEvent = (event: Event)=>{
48
+ if (propsRef.current.onPlay) {
49
+ propsRef.current.onPlay(event as any);
50
+ }
51
+ };
52
+ element.addEventListener('play', handleEvent);
53
+ return ()=>{
54
+ element.removeEventListener('play', handleEvent);
55
+ };
56
+ }, []);
57
+ useTypeOfLayoutEffect(()=>{
58
+ const element = innerRef.current;
59
+ if (!element) return;
60
+ const handleEvent = (event: Event)=>{
61
+ if (propsRef.current.onPause) {
62
+ propsRef.current.onPause(event as any);
63
+ }
64
+ };
65
+ element.addEventListener('pause', handleEvent);
66
+ return ()=>{
67
+ element.removeEventListener('pause', handleEvent);
68
+ };
69
+ }, []);
70
+ const domProps = {
71
+ ...props
72
+ };
73
+ const customPropNames = [
74
+ 'poster',
75
+ 'controls',
76
+ 'locale',
77
+ 'onPlay',
78
+ 'onPause'
79
+ ];
80
+ for (const key of customPropNames){
81
+ delete (domProps as any)[key];
82
+ }
83
+ return React.createElement('uibit-video', {
84
+ ref: innerRef,
85
+ ...domProps
86
+ }, children);
87
+ };
88
+ declare global {
89
+ namespace React {
90
+ namespace JSX {
91
+ interface IntrinsicElements {
92
+ 'uibit-video': React.ClassAttributes<HTMLElementClass> & React.HTMLAttributes<HTMLElementClass> & {
93
+ children?: React.ReactNode;
94
+ class?: string;
95
+ poster?: string;
96
+ controls?: boolean;
97
+ locale?: string;
98
+ onPlay?: (event: CustomEvent<any>) => void;
99
+ onPause?: (event: CustomEvent<any>) => void;
100
+ };
101
+ }
102
+ }
103
+ }
104
+ }
@@ -9,8 +9,8 @@ declare module 'solid-js' {
9
9
  poster?: string;
10
10
  controls?: boolean;
11
11
  locale?: string;
12
- "on:play"?: (event: CustomEvent) => void;
13
- "on:pause"?: (event: CustomEvent) => void;
12
+ "on:play"?: (event: Event) => void;
13
+ "on:pause"?: (event: Event) => void;
14
14
  };
15
15
  }
16
16
  }
@@ -8,6 +8,10 @@ declare module '@stencil/core' {
8
8
  poster?: string;
9
9
  controls?: boolean;
10
10
  locale?: string;
11
+ onPlay?: (event: Event) => void;
12
+ "on:play"?: (event: Event) => void;
13
+ onPause?: (event: Event) => void;
14
+ "on:pause"?: (event: Event) => void;
11
15
  };
12
16
  }
13
17
  }
@@ -1,37 +1,66 @@
1
1
  <script lang="ts">
2
2
  import '@uibit/video';
3
3
  import type { Video as HTMLElementClass } from '@uibit/video';
4
-
5
- let {
6
- poster = undefined,
7
- controls = undefined,
8
- locale = undefined,
9
- children
4
+
5
+ let {
6
+ poster = $bindable(),
7
+ controls = $bindable(),
8
+ locale = $bindable(),
9
+ children,
10
+ ...restProps
10
11
  } = $props<{
11
- children?: any;
12
+ children?: import('svelte').Snippet;
12
13
  poster?: string;
13
14
  controls?: boolean;
14
15
  locale?: string;
15
-
16
+
17
+ [key: string]: any;
16
18
  }>();
17
-
18
- let elementRef: HTMLElementClass | null = $state(null);
19
-
20
- $effect(() => {
21
- if (elementRef && poster !== undefined) {
19
+
20
+ let elementRef: HTMLElementClass | null = $state(null);
21
+
22
+ $effect(() => {
23
+ if (elementRef && poster !== undefined && elementRef.poster !== poster) {
22
24
  elementRef.poster = poster;
23
25
  }
24
- if (elementRef && controls !== undefined) {
26
+ if (elementRef && controls !== undefined && elementRef.controls !== controls) {
25
27
  elementRef.controls = controls;
26
28
  }
27
- if (elementRef && locale !== undefined) {
29
+ if (elementRef && locale !== undefined && elementRef.locale !== locale) {
28
30
  elementRef.locale = locale;
29
31
  }
30
32
  });
31
-
33
+
34
+ $effect(() => {
35
+ const element = elementRef;
36
+ if (!element) return;
37
+
38
+ const handleEvent = () => {
39
+ if (poster !== element.poster) {
40
+ poster = element.poster as any;
41
+ }
42
+ if (controls !== element.controls) {
43
+ controls = element.controls as any;
44
+ }
45
+ if (locale !== element.locale) {
46
+ locale = element.locale as any;
47
+ }
48
+ };
49
+
50
+ const events = ['change', 'input', 'play', 'pause'];
51
+ for (const event of events) {
52
+ element.addEventListener(event, handleEvent);
53
+ }
54
+ return () => {
55
+ for (const event of events) {
56
+ element.removeEventListener(event, handleEvent);
57
+ }
58
+ };
59
+ });
60
+
32
61
  </script>
33
62
 
34
- <uibit-video bind:this={elementRef} {...$$restProps}>
63
+ <uibit-video bind:this={elementRef} {...restProps}>
35
64
 
36
65
  {#if children}
37
66
  {@render children()}
@@ -1,29 +1,87 @@
1
- import { defineComponent, h } from 'vue';
1
+ import { defineComponent, h, ref, watch } from 'vue';
2
2
  import type { Video as HTMLElementClass } from '@uibit/video';
3
3
  import '@uibit/video';
4
-
5
4
  export const Video = defineComponent({
6
- name: 'Video',
7
- props: {
8
- poster: { type: [String, Number, Boolean, Array, Object] as any },
9
- controls: { type: [String, Number, Boolean, Array, Object] as any },
10
- locale: { type: [String, Number, Boolean, Array, Object] as any }
11
- },
12
- emits: ['play', 'pause'],
13
- setup(props, { slots, emit }) {
14
- return () => {
15
- const eventListeners: Record<string, any> = {};
16
- eventListeners['onPlay'] = (event: Event) => {
17
- emit('play', event);
18
- };
19
- eventListeners['onPause'] = (event: Event) => {
20
- emit('pause', event);
21
- };
22
-
23
- return h('uibit-video', {
24
- ...props,
25
- ...eventListeners
26
- }, slots.default?.());
27
- };
28
- }
5
+ name: 'Video',
6
+ props: {
7
+ poster: {
8
+ type: [
9
+ String,
10
+ Number,
11
+ Boolean,
12
+ Array,
13
+ Object
14
+ ] as any
15
+ },
16
+ controls: {
17
+ type: [
18
+ String,
19
+ Number,
20
+ Boolean,
21
+ Array,
22
+ Object
23
+ ] as any
24
+ },
25
+ locale: {
26
+ type: [
27
+ String,
28
+ Number,
29
+ Boolean,
30
+ Array,
31
+ Object
32
+ ] as any
33
+ }
34
+ },
35
+ emits: [
36
+ 'play',
37
+ 'pause'
38
+ ],
39
+ setup (props, { slots, emit }) {
40
+ const elementRef = ref<HTMLElementClass | null>(null);
41
+ if (false) {
42
+ watch(()=>props.modelValue, (newVal)=>{
43
+ if (elementRef.value && newVal !== undefined && elementRef.value.value !== newVal) {
44
+ elementRef.value.value = newVal;
45
+ }
46
+ });
47
+ watch(()=>props.value, (newVal)=>{
48
+ if (elementRef.value && newVal !== undefined && elementRef.value.value !== newVal) {
49
+ elementRef.value.value = newVal;
50
+ }
51
+ });
52
+ }
53
+ watch(()=>props.poster, (newVal)=>{
54
+ if (elementRef.value && newVal !== undefined) {
55
+ (elementRef.value as any).poster = newVal;
56
+ }
57
+ });
58
+ watch(()=>props.controls, (newVal)=>{
59
+ if (elementRef.value && newVal !== undefined) {
60
+ (elementRef.value as any).controls = newVal;
61
+ }
62
+ });
63
+ watch(()=>props.locale, (newVal)=>{
64
+ if (elementRef.value && newVal !== undefined) {
65
+ (elementRef.value as any).locale = newVal;
66
+ }
67
+ });
68
+ return ()=>{
69
+ const eventListeners: Record<string, any> = {};
70
+ eventListeners['onPlay'] = (event: Event)=>{
71
+ emit('play', event);
72
+ };
73
+ eventListeners['onPause'] = (event: Event)=>{
74
+ emit('pause', event);
75
+ };
76
+ const mergedProps = {
77
+ ...props,
78
+ ...eventListeners,
79
+ ref: elementRef
80
+ };
81
+ if (false && props.modelValue !== undefined) {
82
+ (mergedProps as any).value = props.modelValue;
83
+ }
84
+ return h('uibit-video', mergedProps, slots.default?.());
85
+ };
86
+ }
29
87
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uibit/video",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Custom premium customizable wrapper for native video elements and iframe video embeds",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -11,7 +11,7 @@
11
11
  "import": "./dist/index.js"
12
12
  },
13
13
  "./custom-elements.json": "./custom-elements.json",
14
- "./react": "./dist/frameworks/react/index.d.ts",
14
+ "./react": "./dist/frameworks/react/index.ts",
15
15
  "./vue": "./dist/frameworks/vue/index.ts",
16
16
  "./svelte": "./dist/frameworks/svelte/index.svelte",
17
17
  "./angular": "./dist/frameworks/angular/index.ts",
@@ -51,7 +51,7 @@
51
51
  "@types/node": "^20.19.43",
52
52
  "lit": "^3.3.3",
53
53
  "typescript": "7.0.2",
54
- "@uibit/codegen": "0.1.0"
54
+ "@uibit/codegen": "0.2.0"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "lit": "^3.0.0",
@@ -1,21 +0,0 @@
1
- import type { HTMLAttributes, ClassAttributes } from 'react';
2
- import type { Video as HTMLElementClass } from '@uibit/video';
3
- import '@uibit/video';
4
-
5
- declare global {
6
- namespace React {
7
- namespace JSX {
8
- interface IntrinsicElements {
9
- 'uibit-video': ClassAttributes<HTMLElementClass> & HTMLAttributes<HTMLElementClass> & {
10
- children?: React.ReactNode;
11
- class?: string;
12
- poster?: string;
13
- controls?: boolean;
14
- locale?: string;
15
- onPlay?: (event: any) => void;
16
- onPause?: (event: any) => void;
17
- };
18
- }
19
- }
20
- }
21
- }