@streamscloud/embeddable 5.1.3 → 6.0.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.
Files changed (89) hide show
  1. package/dist/ads/ad-card/mapper.js +1 -1
  2. package/dist/core/continuation-token.d.ts +1 -0
  3. package/dist/core/continuation-token.js +3 -0
  4. package/dist/core/locale.d.ts +0 -1
  5. package/dist/core/locale.js +0 -12
  6. package/dist/core/media/media-item-url.service.d.ts +1 -1
  7. package/dist/core/media/media-item-url.service.js +1 -6
  8. package/dist/media-center/data-provider/index.d.ts +2 -0
  9. package/dist/media-center/data-provider/index.js +1 -0
  10. package/dist/media-center/data-provider/internal-media-center-data-provider.svelte.d.ts +8 -0
  11. package/dist/media-center/data-provider/internal-media-center-data-provider.svelte.js +44 -0
  12. package/dist/media-center/data-provider/operations.generated.d.ts +89 -0
  13. package/dist/media-center/data-provider/operations.generated.js +275 -0
  14. package/dist/media-center/data-provider/operations.graphql +25 -0
  15. package/dist/media-center/data-provider/types.d.ts +24 -0
  16. package/dist/media-center/data-provider/types.js +1 -0
  17. package/dist/media-center/index.d.ts +1 -0
  18. package/dist/media-center/index.js +1 -0
  19. package/dist/media-center/media-center/cmp.media-center.svelte +336 -0
  20. package/dist/media-center/media-center/cmp.media-center.svelte.d.ts +20 -0
  21. package/dist/media-center/media-center/index.d.ts +3 -0
  22. package/dist/media-center/media-center/index.js +2 -0
  23. package/dist/media-center/media-center/media-center-localization.d.ts +11 -0
  24. package/dist/media-center/media-center/media-center-localization.js +15 -0
  25. package/dist/media-center/media-center/overview.svelte +142 -0
  26. package/dist/media-center/media-center/overview.svelte.d.ts +13 -0
  27. package/dist/media-center/media-center/short-video-resources-generator.d.ts +8 -0
  28. package/dist/media-center/media-center/short-video-resources-generator.js +26 -0
  29. package/dist/media-center/media-center/types.d.ts +10 -0
  30. package/dist/media-center/media-center/types.js +5 -0
  31. package/dist/products/product-card/cmp.product-card.svelte +11 -6
  32. package/dist/products/product-card/mapper.js +3 -3
  33. package/dist/short-videos/short-video-card/cmp.short-video-card.svelte +118 -0
  34. package/dist/short-videos/short-video-card/cmp.short-video-card.svelte.d.ts +11 -0
  35. package/dist/short-videos/short-video-card/index.d.ts +2 -0
  36. package/dist/short-videos/short-video-card/index.js +1 -0
  37. package/dist/short-videos/short-video-card/types.d.ts +5 -0
  38. package/dist/short-videos/short-video-card/types.js +1 -0
  39. package/dist/short-videos/short-video-viewer/cmp.short-video-controls.svelte +3 -3
  40. package/dist/short-videos/short-video-viewer/cmp.short-video-controls.svelte.d.ts +2 -2
  41. package/dist/short-videos/short-video-viewer/cmp.short-video-viewer.svelte +8 -26
  42. package/dist/short-videos/short-video-viewer/cmp.short-video-viewer.svelte.d.ts +2 -3
  43. package/dist/short-videos/short-video-viewer/index.d.ts +1 -1
  44. package/dist/short-videos/short-video-viewer/mapper.js +6 -3
  45. package/dist/short-videos/short-video-viewer/types.d.ts +8 -6
  46. package/dist/short-videos/short-video-viewer/ui-manager.svelte.d.ts +0 -5
  47. package/dist/short-videos/short-video-viewer/ui-manager.svelte.js +0 -11
  48. package/dist/short-videos/short-videos-player/cmp.short-videos-player.svelte +16 -12
  49. package/dist/short-videos/short-videos-player/cmp.short-videos-player.svelte.d.ts +5 -15
  50. package/dist/short-videos/short-videos-player/controls.svelte +34 -3
  51. package/dist/short-videos/short-videos-player/controls.svelte.d.ts +3 -2
  52. package/dist/short-videos/short-videos-player/fade-mixins.scss +12 -0
  53. package/dist/short-videos/short-videos-player/index.d.ts +66 -36
  54. package/dist/short-videos/short-videos-player/index.js +40 -104
  55. package/dist/short-videos/short-videos-player/internal-short-video-player-provider.d.ts +17 -0
  56. package/dist/short-videos/short-videos-player/internal-short-video-player-provider.js +59 -0
  57. package/dist/short-videos/short-videos-player/operations.generated.d.ts +1 -0
  58. package/dist/short-videos/short-videos-player/operations.generated.js +2 -1
  59. package/dist/short-videos/short-videos-player/operations.graphql +1 -0
  60. package/dist/short-videos/short-videos-player/short-videos-player-view.svelte +36 -55
  61. package/dist/short-videos/short-videos-player/short-videos-player-view.svelte.d.ts +12 -15
  62. package/dist/short-videos/short-videos-player/types.d.ts +8 -29
  63. package/dist/short-videos/short-videos-player/types.js +1 -6
  64. package/dist/short-videos/short-videos-player/ui-manager.svelte.d.ts +6 -6
  65. package/dist/short-videos/short-videos-player/ui-manager.svelte.js +28 -16
  66. package/dist/streams/layout/element-views/cmp.short-video-stream-element.svelte +6 -1
  67. package/dist/streams/stream-page-viewer/index.d.ts +1 -0
  68. package/dist/streams/stream-page-viewer/index.js +1 -0
  69. package/dist/streams/stream-player/controls.svelte +2 -2
  70. package/dist/streams/stream-player/controls.svelte.d.ts +2 -2
  71. package/dist/streams/stream-player/index.d.ts +84 -27
  72. package/dist/streams/stream-player/index.js +46 -48
  73. package/dist/streams/stream-player/internal-stream-analytics-handler.d.ts +12 -0
  74. package/dist/streams/stream-player/internal-stream-analytics-handler.js +17 -0
  75. package/dist/streams/stream-player/internal-stream-player-data-provider.d.ts +10 -0
  76. package/dist/streams/stream-player/internal-stream-player-data-provider.js +48 -0
  77. package/dist/streams/stream-player/mapper.js +2 -0
  78. package/dist/streams/stream-player/operations.generated.d.ts +0 -2
  79. package/dist/streams/stream-player/operations.generated.js +2 -4
  80. package/dist/streams/stream-player/operations.graphql +0 -1
  81. package/dist/streams/stream-player/stream-player-buffer.svelte.d.ts +5 -5
  82. package/dist/streams/stream-player/stream-player-buffer.svelte.js +12 -27
  83. package/dist/streams/stream-player/{cmp.stream-player.svelte → stream-player.svelte} +19 -37
  84. package/dist/streams/stream-player/stream-player.svelte.d.ts +4 -0
  85. package/dist/streams/stream-player/types.d.ts +40 -0
  86. package/dist/ui/player/index.d.ts +1 -1
  87. package/dist/ui/player/player-buffer.svelte.d.ts +3 -3
  88. package/package.json +5 -1
  89. package/dist/streams/stream-player/cmp.stream-player.svelte.d.ts +0 -22
@@ -1,70 +1,100 @@
1
+ import { type IMediaCenterDataProvider } from '../../media-center/data-provider';
2
+ import type { ShortVideoViewerModel } from '../short-video-viewer';
3
+ import type { IPlayerItemsProvider } from '../../ui/player';
1
4
  import { default as ShortVideosPlayer } from './cmp.short-videos-player.svelte';
2
5
  import type { IShortVideosPlayerLocalization } from './short-videos-player-localization';
3
- import { type OpenShortVideosPlayerInit } from './types';
6
+ import { type PlayerSettings } from './types';
4
7
  export { ShortVideosPlayer };
5
- export type { IShortVideosPlayerLocalization };
8
+ export type { IShortVideosPlayerLocalization, IMediaCenterDataProvider, IPlayerItemsProvider };
6
9
  /**
7
- * Opens the short videos player modal with the specified provider or by fetching videos by IDs.
10
+ * Opens the short videos player modal.
8
11
  *
9
- * You can use either a ready-made provider, or simply pass a list of video IDs and a GraphQL endpoint to fetch them.
12
+ * Two overloads (mutually exclusive):
13
+ * - Provider mode: openShortVideosPlayer({ shortVideosProvider, mediaCenterDataProvider?, ...common })
14
+ * - IDs mode: openShortVideosPlayer({ ids, initiator, graphqlOrigin?, initialId?, mediaPageId?, ...common })
10
15
  *
11
- * @param init - Configuration options.
16
+ * @param init Configuration options.
12
17
  *
13
- * @param {PlayerItemsProvider<ShortVideoViewerModel>} [init.shortVideosProvider]
14
- * The provider instance supplying short video items to the player.
15
- * **Use this if you already have your own provider implementation.**
16
- *
17
- * @param {string[]} [init.ids]
18
- * List of short video IDs to display in the player.
19
- * **Use this if you want the player to fetch and show specific videos.**
20
- *
21
- * @param {string} [init.graphqlUrl]
22
- * The GraphQL endpoint to use when fetching videos by IDs.
23
- * **Required if you use `ids`.**
18
+ * Provider mode (overload 1)
19
+ * @param {IPlayerItemsProvider<ShortVideoViewerModel>} init.shortVideosProvider
20
+ * Provider that supplies short-video items to the player.
21
+ * @param {IMediaCenterDataProvider} [init.mediaCenterDataProvider]
22
+ * Optional media-center data provider.
24
23
  *
24
+ * IDs mode (overload 2)
25
+ * @param {string[]} init.ids
26
+ * List of short-video IDs to display.
27
+ * @param {string} init.initiator
28
+ * Identifier of the initiator (used for tracking/analytics and GraphQL).
29
+ * @param {string} [init.graphqlOrigin]
30
+ * Optional GraphQL origin (base URL). If omitted, the default origin is determined internally.
25
31
  * @param {string} [init.initialId]
26
- * The ID of the video that should be shown first.
27
- * **Optional. Only used when using `ids`.**
32
+ * ID of the video to open first (optional).
33
+ * @param {string} [init.mediaPageId]
34
+ * Optional media page ID used to construct an internal media-center data provider.
28
35
  *
29
- * @param {IShortVideosPlayerLocalization} [init.localization]
30
- * Optional localization settings for the player UI.
36
+ * Common settings
37
+ * @param {IPostSocialInteractionsHandler} [init.socialInteractionsHandler]
38
+ * Handler for social interactions (like, share, etc.).
39
+ * @param {IShortVideosPlayerLocalization | Locale} [init.localization]
40
+ * Localization for the player UI. If omitted, 'en' is used.
41
+ * @param {boolean} [init.disableBackground]
42
+ * If true, hides the player's background image.
43
+ * @param {boolean} [init.showStreamsCloudWatermark]
44
+ * If true, shows the StreamsCloud watermark.
31
45
  *
32
- * @param {object} [init.on]
46
+ * Events
47
+ * @param {{ playerClosed?: () => void; videoActivated?: (id: string) => void }} [init.on]
33
48
  * Optional event handlers.
34
49
  * @param {() => void} [init.on.playerClosed]
35
- * Called when the player is closed.
50
+ * Called after the player is fully closed (after unmount and removal from the DOM).
51
+ * @param {(id: string) => void} [init.on.videoActivated]
52
+ * Called when a video becomes active (receives the video's id).
36
53
  *
37
- * @example <caption>Using a custom provider</caption>
54
+ * @returns {void}
55
+ *
56
+ * @example <caption>Provider mode</caption>
38
57
  * ```ts
39
58
  * import { openShortVideosPlayer } from '@streamscloud/embeddable/short-videos-player';
40
59
  *
41
60
  * openShortVideosPlayer({
42
61
  * shortVideosProvider: myShortVideosProvider,
43
- * localization: {
44
- * next: 'Next',
45
- * previous: 'Previous'
62
+ * mediaCenterDataProvider: myMediaCenterDataProvider,
63
+ * localization: { next: 'Next', previous: 'Previous' },
64
+ * showStreamsCloudWatermark: true,
65
+ * on: {
66
+ * playerClosed: () => console.log('Player closed'),
67
+ * videoActivated: (id) => console.log('Activated', id)
46
68
  * }
47
69
  * });
48
70
  * ```
49
71
  *
50
- * @example <caption>Using a list of IDs</caption>
72
+ * @example <caption>IDs mode</caption>
51
73
  * ```ts
52
74
  * import { openShortVideosPlayer } from '@streamscloud/embeddable/short-videos-player';
53
75
  *
54
76
  * openShortVideosPlayer({
55
77
  * ids: ['id1', 'id2', 'id3'],
56
- * graphqlOrigin: 'https://api.example.com',
78
+ * initiator: 'marketing-campaign',
79
+ * graphqlOrigin: 'https://graphql.example.com',
57
80
  * initialId: 'id2',
58
- * localization: {
59
- * next: 'Next',
60
- * previous: 'Previous'
61
- * },
81
+ * mediaPageId: 'media-page-123',
82
+ * localization: { next: 'Next', previous: 'Previous' },
62
83
  * on: {
63
- * playerClosed: () => {
64
- * console.log('Player was closed');
65
- * }
84
+ * playerClosed: () => console.log('Player closed'),
85
+ * videoActivated: (id) => console.log('Activated', id)
66
86
  * }
67
87
  * });
68
88
  * ```
69
89
  */
70
- export declare const openShortVideosPlayer: (init: OpenShortVideosPlayerInit) => Promise<void>;
90
+ export declare function openShortVideosPlayer(init: PlayerSettings & {
91
+ shortVideosProvider: IPlayerItemsProvider<ShortVideoViewerModel>;
92
+ mediaCenterDataProvider?: IMediaCenterDataProvider;
93
+ }): void;
94
+ export declare function openShortVideosPlayer(init: PlayerSettings & {
95
+ ids: string[];
96
+ initiator: string;
97
+ graphqlOrigin?: string;
98
+ initialId?: string;
99
+ mediaPageId?: string;
100
+ }): void;
@@ -1,120 +1,56 @@
1
- import { getLocale } from '../../core/locale';
1
+ import { toastrWarning } from '../../core/toastr';
2
+ import { InternalMediaCenterDataProvider } from '../../media-center/data-provider';
3
+ import { MediaCenter, MediaCenterMode } from '../../media-center/media-center';
2
4
  import { ModalShadowHost } from '../../ui/shadow-dom';
3
5
  import { default as ShortVideosPlayer } from './cmp.short-videos-player.svelte';
4
- import { default as ShortVideosPlayerView } from './short-videos-player-view.svelte';
5
- import { isIdsInit, isShortVideosProviderInit } from './types';
6
+ import { InternalShortVideoPlayerProvider } from './internal-short-video-player-provider';
7
+ import {} from './types';
6
8
  import { mount, unmount } from 'svelte';
7
9
  export { ShortVideosPlayer };
8
- /**
9
- * Opens the short videos player modal with the specified provider or by fetching videos by IDs.
10
- *
11
- * You can use either a ready-made provider, or simply pass a list of video IDs and a GraphQL endpoint to fetch them.
12
- *
13
- * @param init - Configuration options.
14
- *
15
- * @param {PlayerItemsProvider<ShortVideoViewerModel>} [init.shortVideosProvider]
16
- * The provider instance supplying short video items to the player.
17
- * **Use this if you already have your own provider implementation.**
18
- *
19
- * @param {string[]} [init.ids]
20
- * List of short video IDs to display in the player.
21
- * **Use this if you want the player to fetch and show specific videos.**
22
- *
23
- * @param {string} [init.graphqlUrl]
24
- * The GraphQL endpoint to use when fetching videos by IDs.
25
- * **Required if you use `ids`.**
26
- *
27
- * @param {string} [init.initialId]
28
- * The ID of the video that should be shown first.
29
- * **Optional. Only used when using `ids`.**
30
- *
31
- * @param {IShortVideosPlayerLocalization} [init.localization]
32
- * Optional localization settings for the player UI.
33
- *
34
- * @param {object} [init.on]
35
- * Optional event handlers.
36
- * @param {() => void} [init.on.playerClosed]
37
- * Called when the player is closed.
38
- *
39
- * @example <caption>Using a custom provider</caption>
40
- * ```ts
41
- * import { openShortVideosPlayer } from '@streamscloud/embeddable/short-videos-player';
42
- *
43
- * openShortVideosPlayer({
44
- * shortVideosProvider: myShortVideosProvider,
45
- * localization: {
46
- * next: 'Next',
47
- * previous: 'Previous'
48
- * }
49
- * });
50
- * ```
51
- *
52
- * @example <caption>Using a list of IDs</caption>
53
- * ```ts
54
- * import { openShortVideosPlayer } from '@streamscloud/embeddable/short-videos-player';
55
- *
56
- * openShortVideosPlayer({
57
- * ids: ['id1', 'id2', 'id3'],
58
- * graphqlOrigin: 'https://api.example.com',
59
- * initialId: 'id2',
60
- * localization: {
61
- * next: 'Next',
62
- * previous: 'Previous'
63
- * },
64
- * on: {
65
- * playerClosed: () => {
66
- * console.log('Player was closed');
67
- * }
68
- * }
69
- * });
70
- * ```
71
- */
72
- export const openShortVideosPlayer = async (init) => {
73
- let input = null;
74
- if (isShortVideosProviderInit(init)) {
75
- input = {
76
- type: 'provider',
77
- provider: init.shortVideosProvider
78
- };
10
+ export function openShortVideosPlayer(init) {
11
+ const { shortVideosProvider, ids, graphqlOrigin, initialId, initiator, socialInteractionsHandler, disableBackground, localization, showStreamsCloudWatermark } = init;
12
+ let dataProvider = shortVideosProvider;
13
+ if (!dataProvider && ids) {
14
+ dataProvider = new InternalShortVideoPlayerProvider({ ids, graphqlOrigin, initialId, initiator });
79
15
  }
80
- else if (isIdsInit(init)) {
81
- input = {
82
- type: 'ids',
83
- ids: init.ids,
84
- initialId: init.initialId,
85
- graphqlOrigin: init.graphqlOrigin,
86
- initiator: init.initiator
87
- };
88
- }
89
- else {
90
- input = null;
91
- }
92
- if (!input) {
16
+ if (!dataProvider) {
17
+ toastrWarning('Data provider is not specified.');
93
18
  return;
94
19
  }
20
+ let mediaCenterDataProvider = init.mediaCenterDataProvider;
21
+ if (!mediaCenterDataProvider && init.mediaPageId) {
22
+ mediaCenterDataProvider = new InternalMediaCenterDataProvider(init.mediaPageId, graphqlOrigin);
23
+ }
95
24
  const shadowHost = new ModalShadowHost();
96
- const mounted = mount(ShortVideosPlayerView, {
25
+ const mounted = mount(MediaCenter, {
97
26
  target: shadowHost.shadowRoot,
98
27
  props: {
99
- input,
100
- socialInteractionsHandler: init.socialInteractionsHandler,
101
- localization: getLocale(init.localization),
102
- showStreamsCloudWatermark: init.showStreamsCloudWatermark,
103
- on: {
104
- closePlayer: async () => {
105
- if (init.on?.playerClosed) {
106
- init.on.playerClosed();
107
- }
108
- await unmount(mounted);
109
- shadowHost.remove();
110
- },
111
- videoActivated: (id) => {
112
- if (init.on?.videoActivated) {
113
- init.on.videoActivated(id);
28
+ dataProvider: mediaCenterDataProvider || null,
29
+ playerProps: {
30
+ type: MediaCenterMode.ShortVideos,
31
+ props: {
32
+ dataProvider,
33
+ socialInteractionsHandler,
34
+ disableBackground,
35
+ localization,
36
+ showStreamsCloudWatermark,
37
+ on: {
38
+ playerClosed: async () => {
39
+ await unmount(mounted);
40
+ shadowHost.remove();
41
+ if (init.on?.playerClosed) {
42
+ init.on.playerClosed();
43
+ }
44
+ },
45
+ videoActivated: (id) => {
46
+ if (init.on?.videoActivated) {
47
+ init.on.videoActivated(id);
48
+ }
49
+ }
114
50
  }
115
51
  }
116
52
  }
117
53
  }
118
54
  });
119
55
  shadowHost.attachToBody();
120
- };
56
+ }
@@ -0,0 +1,17 @@
1
+ import { type ShortVideoViewerModel } from '../short-video-viewer';
2
+ import type { IPlayerItemsProvider } from '../../ui/player';
3
+ export declare class InternalShortVideoPlayerProvider implements IPlayerItemsProvider<ShortVideoViewerModel> {
4
+ initialData: IPlayerItemsProvider<ShortVideoViewerModel>['initialData'];
5
+ private ids;
6
+ private initialId?;
7
+ private graphql;
8
+ private dataLoader;
9
+ constructor(input: {
10
+ ids: string[];
11
+ initiator?: string;
12
+ graphqlOrigin?: string;
13
+ initialId?: string;
14
+ });
15
+ loadMore: () => Promise<ShortVideoViewerModel[]>;
16
+ prefetch: () => Promise<void>;
17
+ }
@@ -0,0 +1,59 @@
1
+ import { ImageScale } from '../..';
2
+ import { ContinuationToken } from '../../core/continuation-token';
3
+ import { CursorDataLoader } from '../../core/data-loaders';
4
+ import { createLocalGQLClient } from '../../core/graphql';
5
+ import { mapToShortVideoViewerModel } from '../short-video-viewer';
6
+ import { GetShortVideosDocument } from './operations.generated';
7
+ export class InternalShortVideoPlayerProvider {
8
+ initialData;
9
+ ids;
10
+ initialId;
11
+ graphql;
12
+ dataLoader = new CursorDataLoader({
13
+ loadPage: async (continuationToken) => {
14
+ try {
15
+ const payload = await this.graphql
16
+ .query(GetShortVideosDocument, {
17
+ input: {
18
+ limit: 20,
19
+ continuationToken,
20
+ filter: {
21
+ ids: this.ids
22
+ }
23
+ },
24
+ image_scale: ImageScale.OriginalEncoded
25
+ })
26
+ .toPromise();
27
+ const data = payload.data?.shortVideos;
28
+ if (!data) {
29
+ return null;
30
+ }
31
+ return {
32
+ items: data.items.map(mapToShortVideoViewerModel),
33
+ continuationToken: ContinuationToken.fromPayload(data.continuationToken)
34
+ };
35
+ }
36
+ catch {
37
+ return null;
38
+ }
39
+ }
40
+ });
41
+ constructor(input) {
42
+ const { ids, graphqlOrigin, initiator, initialId } = input;
43
+ this.graphql = createLocalGQLClient(graphqlOrigin, initiator ? { 'x-initiator': initiator } : undefined);
44
+ this.ids = ids;
45
+ this.initialId = initialId;
46
+ this.initialData = { prefetchedItems: [], startIndex: 0 };
47
+ }
48
+ loadMore = () => this.dataLoader.loadMore();
49
+ prefetch = async () => {
50
+ const items = await this.loadMore();
51
+ if (this.initialId && items.length) {
52
+ const initialIndex = items.findIndex((i) => i.id === this.initialId);
53
+ this.initialData = { prefetchedItems: items, startIndex: initialIndex >= 0 ? initialIndex : 0 };
54
+ }
55
+ else {
56
+ this.initialData = { prefetchedItems: items, startIndex: 0 };
57
+ }
58
+ };
59
+ }
@@ -6,6 +6,7 @@ export type GetShortVideosQueryVariables = SchemaTypes.Exact<{
6
6
  }>;
7
7
  export type GetShortVideosQuery = {
8
8
  shortVideos: {
9
+ continuationToken: string | null;
9
10
  items: Array<{
10
11
  id: string;
11
12
  enableSocialInteractions: boolean;
@@ -36,7 +36,8 @@ export const GetShortVideosDocument = {
36
36
  kind: 'SelectionSet',
37
37
  selections: [{ kind: 'FragmentSpread', name: { kind: 'Name', value: 'ShortVideoViewerPayloadFragment' } }]
38
38
  }
39
- }
39
+ },
40
+ { kind: 'Field', name: { kind: 'Name', value: 'continuationToken' } }
40
41
  ]
41
42
  }
42
43
  }
@@ -4,5 +4,6 @@ query GetShortVideos($input: EmbedPostsInput!, $image_scale: ImageScale = ORIGIN
4
4
  items {
5
5
  ...ShortVideoViewerPayloadFragment
6
6
  }
7
+ continuationToken
7
8
  }
8
9
  }
@@ -8,66 +8,34 @@
8
8
  });
9
9
  };
10
10
  import { handleEsc } from '../../core/document.event-handlers';
11
- import { createLocalGQLClient } from '../../core/graphql';
12
- import { mapToShortVideoViewerModel, ShortVideoViewer } from '../short-video-viewer';
11
+ import { ShortVideoViewer } from '../short-video-viewer';
12
+ import { InternalShortVideoPlayerProvider } from './internal-short-video-player-provider';
13
13
  import { Loading } from '../../ui/loading';
14
14
  import { PlayerBuffer, PlayerSlider } from '../../ui/player';
15
15
  import { SpotlightLayout } from '../../ui/spotlight-layout';
16
16
  import { SwipeIndicator } from '../../ui/swipe-indicator';
17
17
  import { default as Controls } from './controls.svelte';
18
- import { GetShortVideosDocument } from './operations.generated';
19
18
  import { ShortVideosPlayerLocalization } from './short-videos-player-localization';
20
19
  import { ShortVideosPlayerUiManager } from './ui-manager.svelte';
21
- import { onMount } from 'svelte';
22
- let { input, socialInteractionsHandler, localization: localizationInit = 'en', showStreamsCloudWatermark, disableBackground, on } = $props();
20
+ import { onMount, untrack } from 'svelte';
21
+ let { dataProvider, socialInteractionsHandler, localization: localizationInit = 'en', showStreamsCloudWatermark, disableBackground, on, categoriesSwitcher, playerLogo = null, fadeContent = false } = $props();
23
22
  const localization = $derived(new ShortVideosPlayerLocalization(localizationInit));
24
23
  let everTouched = $state(false);
25
24
  let background = $state(null);
26
- let buffer = $state(input.type === 'provider' ? new PlayerBuffer(input.provider) : null);
27
- const initBuffer = (input) => __awaiter(void 0, void 0, void 0, function* () {
28
- var _a, _b;
29
- try {
30
- const { graphqlOrigin, ids, initialId } = input;
31
- const graphql = createLocalGQLClient(graphqlOrigin, { 'x-initiator': input.initiator || 'player/short-videos' });
32
- const payload = yield graphql
33
- .query(GetShortVideosDocument, {
34
- input: {
35
- filter: {
36
- ids
37
- }
38
- }
39
- })
40
- .toPromise();
41
- const posts = ((_b = (_a = payload.data) === null || _a === void 0 ? void 0 : _a.shortVideos) === null || _b === void 0 ? void 0 : _b.items) || [];
42
- const idOrder = new Map(ids.map((id, index) => [id, index]));
43
- posts.sort((a, b) => {
44
- var _a, _b;
45
- return ((_a = idOrder.get(a.id)) !== null && _a !== void 0 ? _a : Infinity) - ((_b = idOrder.get(b.id)) !== null && _b !== void 0 ? _b : Infinity);
46
- });
47
- const index = initialId ? posts.findIndex((p) => p.id === initialId) : 0;
48
- const provider = {
49
- initialData: {
50
- prefetchedItems: posts.map(mapToShortVideoViewerModel),
51
- startIndex: index
52
- },
53
- loadMore: () => __awaiter(void 0, void 0, void 0, function* () {
54
- // No more items to load, as all are already prefetched
55
- return [];
56
- })
57
- };
58
- buffer = new PlayerBuffer(provider);
59
- }
60
- catch (_c) {
61
- console.error('Failed to load short videos by IDs:', input.ids);
62
- buffer = null; // Reset buffer on error
63
- }
25
+ let buffer = $derived.by(() => {
26
+ void dataProvider;
27
+ return untrack(() => (dataProvider instanceof InternalShortVideoPlayerProvider ? null : new PlayerBuffer(dataProvider)));
64
28
  });
65
29
  const uiManager = new ShortVideosPlayerUiManager();
66
30
  onMount(() => {
67
- if (input.type === 'ids') {
68
- initBuffer(input);
31
+ if (dataProvider instanceof InternalShortVideoPlayerProvider) {
32
+ initBuffer(dataProvider);
69
33
  }
70
34
  });
35
+ const initBuffer = (provider) => __awaiter(void 0, void 0, void 0, function* () {
36
+ yield provider.prefetch();
37
+ buffer = new PlayerBuffer(provider);
38
+ });
71
39
  const onItemActivated = (id) => {
72
40
  var _a;
73
41
  const shortVideo = buffer === null || buffer === void 0 ? void 0 : buffer.loaded.find((x) => x.id === id);
@@ -96,9 +64,12 @@ const handleDimensionsChanged = (dimensions) => {
96
64
  viewTotalWidth: dimensions.totalWidth
97
65
  });
98
66
  };
67
+ const onMediaCenterHeaderMounted = (data) => {
68
+ uiManager.updateMediaCenterHeaderHeight(data.height);
69
+ };
99
70
  const onPlayerClose = () => {
100
71
  var _a;
101
- (_a = on === null || on === void 0 ? void 0 : on.closePlayer) === null || _a === void 0 ? void 0 : _a.call(on);
72
+ (_a = on === null || on === void 0 ? void 0 : on.playerClosed) === null || _a === void 0 ? void 0 : _a.call(on);
102
73
  };
103
74
  </script>
104
75
 
@@ -107,7 +78,15 @@ const onPlayerClose = () => {
107
78
  <div
108
79
  class="short-videos-player-container"
109
80
  class:short-videos-player-container--background-enabled={!disableBackground}
81
+ class:short-videos-player-container--faded={fadeContent}
110
82
  style={background && !disableBackground ? `--background-image: url(${background})` : null}>
83
+ {#if categoriesSwitcher}
84
+ {@render categoriesSwitcher({
85
+ maxItemsWidth: Math.min(uiManager.mainViewColumnWidth * 1.4, uiManager.viewTotalWidth),
86
+ onMounted: onMediaCenterHeaderMounted
87
+ })}
88
+ {/if}
89
+
111
90
  <div class="short-videos-player" style={uiManager.globalCssVariables}>
112
91
  {#if showStreamsCloudWatermark}
113
92
  <div class="short-videos-player__watermark">
@@ -144,7 +123,8 @@ const onPlayerClose = () => {
144
123
  uiManager={uiManager}
145
124
  localization={localization}
146
125
  socialInteractionsHandler={socialInteractionsHandler}
147
- on={{ closePlayer: on?.closePlayer }} />
126
+ playerLogo={playerLogo}
127
+ on={{ closePlayer: on?.playerClosed }} />
148
128
  {:else}
149
129
  <Loading positionFixedCenter={true} timeout={1000} />
150
130
  {/if}
@@ -163,6 +143,7 @@ const onPlayerClose = () => {
163
143
  }
164
144
  }
165
145
  .short-videos-player-container {
146
+ --short-videos-player--elements-opacity: 1;
166
147
  width: 100%;
167
148
  min-width: 100%;
168
149
  max-width: 100%;
@@ -179,11 +160,14 @@ const onPlayerClose = () => {
179
160
  background-size: cover;
180
161
  background-blend-mode: multiply;
181
162
  }
163
+ .short-videos-player-container--faded {
164
+ --short-videos-player--elements-opacity: 0;
165
+ }
182
166
 
183
167
  .short-videos-player {
184
168
  display: flex;
185
169
  flex: 1;
186
- padding: 0.625rem 0;
170
+ padding: var(--short-videos-player--padding);
187
171
  backdrop-filter: blur(30px);
188
172
  position: relative;
189
173
  /* Set 'container-type: inline-size;' to reference container*/
@@ -197,15 +181,12 @@ const onPlayerClose = () => {
197
181
  position: absolute;
198
182
  bottom: 5rem;
199
183
  left: 5rem;
184
+ opacity: var(--short-videos-player--elements-opacity);
185
+ transition: opacity 0.3s ease-in-out;
200
186
  }
201
187
  .short-videos-player__content {
202
188
  width: 100%;
203
189
  height: 100%;
204
- --short-video-viewer--actions-panel--bottom: 5rem;
205
- /* Set 'container-type: inline-size;' to reference container*/
206
- }
207
- @container (width < 576px) {
208
- .short-videos-player__content {
209
- --short-video-viewer--actions-panel--top: 5rem;
210
- }
190
+ opacity: var(--short-videos-player--elements-opacity);
191
+ transition: opacity 0.3s ease-in-out;
211
192
  }</style>
@@ -1,18 +1,15 @@
1
- import type { Locale } from '../../core/locale';
2
- import { type ShortVideoSocialInteractionsHandler } from '../short-video-viewer';
3
- import { type IShortVideosPlayerLocalization } from './short-videos-player-localization';
4
- import type { PlayerInput } from './types';
5
- type Props = {
6
- input: PlayerInput;
7
- socialInteractionsHandler?: ShortVideoSocialInteractionsHandler;
8
- localization?: IShortVideosPlayerLocalization | Locale;
9
- showStreamsCloudWatermark?: boolean;
10
- disableBackground?: boolean;
11
- on?: {
12
- closePlayer?: () => void;
13
- videoActivated?: (id: string) => void;
14
- };
1
+ import type { ShortVideoPlayerProps } from './types';
2
+ import { type Snippet } from 'svelte';
3
+ type $$ComponentProps = ShortVideoPlayerProps & {
4
+ categoriesSwitcher?: Snippet<[{
5
+ maxItemsWidth: number;
6
+ onMounted: (data: {
7
+ height: number;
8
+ }) => void;
9
+ }]>;
10
+ playerLogo?: string | null;
11
+ fadeContent?: boolean;
15
12
  };
16
- declare const ShortVideosPlayerView: import("svelte").Component<Props, {}, "">;
13
+ declare const ShortVideosPlayerView: import("svelte").Component<$$ComponentProps, {}, "">;
17
14
  type ShortVideosPlayerView = ReturnType<typeof ShortVideosPlayerView>;
18
15
  export default ShortVideosPlayerView;
@@ -1,38 +1,17 @@
1
- import type { ShortVideoViewerModel, ShortVideoSocialInteractionsHandler } from '../short-video-viewer';
2
- import type { PlayerItemsProvider } from '../../ui/player';
1
+ import type { Locale } from '../../core/locale';
2
+ import type { ShortVideoViewerModel, IPostSocialInteractionsHandler } from '../short-video-viewer';
3
+ import type { IPlayerItemsProvider } from '../../ui/player';
3
4
  import type { IShortVideosPlayerLocalization } from './short-videos-player-localization';
4
- export type PlayerInput = ProviderPlayerInput | IdsPlayerInput;
5
- export type ProviderPlayerInput = {
6
- type: 'provider';
7
- provider: PlayerItemsProvider<ShortVideoViewerModel>;
5
+ export type ShortVideoPlayerProps = PlayerSettings & {
6
+ dataProvider: IPlayerItemsProvider<ShortVideoViewerModel>;
8
7
  };
9
- export type IdsPlayerInput = {
10
- type: 'ids';
11
- ids: string[];
12
- initialId?: string;
13
- graphqlOrigin?: string;
14
- initiator?: string;
15
- };
16
- export type OpenShortVideosPlayerInit = ProviderInit | IdsInit;
17
- type ProviderInit = PlayerSettings & {
18
- shortVideosProvider: PlayerItemsProvider<ShortVideoViewerModel>;
19
- };
20
- type IdsInit = PlayerSettings & {
21
- ids: string[];
22
- graphqlOrigin?: string;
23
- initialId?: string;
24
- initiator?: string;
25
- };
26
- type PlayerSettings = {
27
- socialInteractionsHandler?: ShortVideoSocialInteractionsHandler;
8
+ export type PlayerSettings = {
9
+ socialInteractionsHandler?: IPostSocialInteractionsHandler;
28
10
  disableBackground?: boolean;
29
- localization?: IShortVideosPlayerLocalization | 'en' | 'no';
11
+ localization?: IShortVideosPlayerLocalization | Locale;
30
12
  showStreamsCloudWatermark?: boolean;
31
13
  on?: {
32
14
  playerClosed?: () => void;
33
15
  videoActivated?: (id: string) => void;
34
16
  };
35
17
  };
36
- export declare const isShortVideosProviderInit: (init: unknown) => init is ProviderInit;
37
- export declare function isIdsInit(init: unknown): init is IdsInit;
38
- export {};
@@ -1,6 +1 @@
1
- export const isShortVideosProviderInit = (init) => {
2
- return typeof init === 'object' && init !== null && 'shortVideosProvider' in init;
3
- };
4
- export function isIdsInit(init) {
5
- return typeof init === 'object' && init !== null && 'ids' in init && 'graphqlOrigin' in init;
6
- }
1
+ export {};