@streamscloud/embeddable 8.3.0 → 10.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.
- package/dist/content-player/cmp.content-player.svelte +1 -1
- package/dist/content-player/content-player-config.svelte.d.ts +4 -4
- package/dist/content-player/controls-and-attachments.svelte +1 -1
- package/dist/content-player/header.svelte +1 -1
- package/dist/core/document.event-handlers.d.ts +1 -0
- package/dist/core/document.event-handlers.js +3 -0
- package/dist/media-center/config/internal-media-center-analytics-handler.d.ts +4 -3
- package/dist/media-center/config/internal-media-center-analytics-handler.js +1 -0
- package/dist/media-center/config/internal-media-center-config.d.ts +1 -1
- package/dist/media-center/config/internal-media-center-config.js +38 -48
- package/dist/media-center/config/operations.generated.d.ts +0 -104
- package/dist/media-center/config/operations.generated.js +0 -323
- package/dist/media-center/config/operations.graphql +0 -24
- package/dist/media-center/config/types.d.ts +14 -14
- package/dist/media-center/config/types.js +1 -1
- package/dist/media-center/media-center/cmp.media-center.svelte +101 -24
- package/dist/media-center/media-center/cmp.media-center.svelte.d.ts +5 -5
- package/dist/media-center/media-center/discover-panel-handler.svelte.d.ts +5 -4
- package/dist/media-center/media-center/discover-panel-handler.svelte.js +2 -1
- package/dist/media-center/media-center/discover-panel.svelte +1 -1
- package/dist/media-center/media-center/discover-panel.svelte.d.ts +4 -3
- package/dist/media-center/media-center/post-player-provider-generator.d.ts +8 -0
- package/dist/media-center/media-center/{short-video-resources-generator.js → post-player-provider-generator.js} +9 -3
- package/dist/media-center/media-center/streams-in-category-panel-handler.svelte.d.ts +5 -2
- package/dist/media-center/media-center/streams-in-category-panel-handler.svelte.js +5 -0
- package/dist/media-center/media-center/streams-in-category-panel.svelte +2 -2
- package/dist/media-center/media-center/streams-in-category-panel.svelte.d.ts +3 -2
- package/dist/media-center/media-center/streams-player-provider-generator.d.ts +8 -0
- package/dist/media-center/media-center/streams-player-provider-generator.js +36 -0
- package/dist/media-center/media-center/types.d.ts +1 -7
- package/dist/posts/controls/cmp.controls.svelte +1 -1
- package/dist/posts/data-loaders/index.d.ts +1 -0
- package/dist/posts/data-loaders/index.js +1 -0
- package/dist/posts/data-loaders/mapper.d.ts +3 -0
- package/dist/{short-videos/short-videos-player → posts/data-loaders}/mapper.js +2 -2
- package/dist/{short-videos/short-videos-player → posts/data-loaders}/operations.generated.d.ts +6 -6
- package/dist/{short-videos/short-videos-player → posts/data-loaders}/operations.generated.js +7 -10
- package/dist/posts/data-loaders/operations.graphql +17 -0
- package/dist/posts/data-loaders/posts-loader.d.ts +19 -0
- package/dist/posts/data-loaders/posts-loader.js +28 -0
- package/dist/posts/handlers/index.d.ts +1 -0
- package/dist/posts/handlers/index.js +1 -0
- package/dist/{short-videos/short-videos-player/internal-short-video-analytics-handler.d.ts → posts/handlers/internal-post-analytics-handler.d.ts} +3 -2
- package/dist/{short-videos/short-videos-player/internal-short-video-analytics-handler.js → posts/handlers/internal-post-analytics-handler.js} +2 -1
- package/dist/{short-videos/short-videos-player/cmp.short-videos-player.svelte → posts/posts-player/cmp.posts-player.svelte} +3 -3
- package/dist/posts/posts-player/cmp.posts-player.svelte.d.ts +4 -0
- package/dist/posts/posts-player/index.d.ts +55 -20
- package/dist/posts/posts-player/index.js +48 -32
- package/dist/posts/posts-player/posts-player-view.svelte +65 -15
- package/dist/posts/posts-player/posts-player-view.svelte.d.ts +5 -1
- package/dist/posts/posts-player/types.d.ts +9 -3
- package/dist/short-videos/data-providers/index.d.ts +1 -0
- package/dist/short-videos/data-providers/index.js +1 -0
- package/dist/short-videos/data-providers/internal-short-video-player-items-provider.d.ts +17 -0
- package/dist/short-videos/{short-videos-player/internal-short-video-player-provider.js → data-providers/internal-short-video-player-items-provider.js} +13 -33
- package/dist/short-videos/short-videos-player/index.d.ts +14 -64
- package/dist/short-videos/short-videos-player/index.js +77 -31
- package/dist/streams/data-loaders/index.d.ts +2 -0
- package/dist/streams/data-loaders/index.js +2 -0
- package/dist/streams/{stream-player → data-loaders}/mapper.d.ts +1 -1
- package/dist/streams/{stream-player → data-loaders}/operations.generated.d.ts +27 -24
- package/dist/streams/{stream-player → data-loaders}/operations.generated.js +18 -17
- package/dist/streams/{stream-player → data-loaders}/operations.graphql +6 -3
- package/dist/streams/data-loaders/stream-pages-loader.d.ts +10 -0
- package/dist/streams/data-loaders/stream-pages-loader.js +33 -0
- package/dist/streams/data-loaders/streams-loader.d.ts +19 -0
- package/dist/streams/data-loaders/streams-loader.js +28 -0
- package/dist/streams/{stream-player → streams-player}/index.d.ts +21 -22
- package/dist/streams/{stream-player → streams-player}/index.js +9 -7
- package/dist/streams/streams-player/internal-streams-player-data-provider.d.ts +16 -0
- package/dist/streams/streams-player/internal-streams-player-data-provider.js +55 -0
- package/dist/streams/{stream-player → streams-player}/stream-overview.svelte +18 -15
- package/dist/streams/{stream-player → streams-player}/stream-overview.svelte.d.ts +2 -2
- package/dist/streams/streams-player/streams-player-buffer.svelte.d.ts +8 -0
- package/dist/streams/streams-player/streams-player-buffer.svelte.js +15 -0
- package/dist/streams/{stream-player/stream-player-view.svelte → streams-player/streams-player-view.svelte} +69 -55
- package/dist/streams/streams-player/streams-player-view.svelte.d.ts +8 -0
- package/dist/streams/{stream-player → streams-player}/types.d.ts +9 -7
- package/dist/ui/{player-button → player/button}/cmp.player-button.svelte +1 -1
- package/dist/ui/{player-button → player/button}/cmp.player-button.svelte.d.ts +1 -1
- package/dist/ui/{player-button → player/button}/cmp.player-buttons-group.svelte +1 -1
- package/dist/ui/{player-button → player/button}/types.d.ts +1 -1
- package/dist/ui/player/button/types.js +1 -0
- package/dist/ui/player/providers/chunks-player-buffer/index.d.ts +2 -0
- package/dist/ui/player/providers/chunks-player-buffer/index.js +2 -0
- package/dist/ui/player/providers/chunks-player-buffer/player-chunk-item.svelte.d.ts +11 -0
- package/dist/ui/player/providers/chunks-player-buffer/player-chunk-item.svelte.js +11 -0
- package/dist/ui/player/providers/chunks-player-buffer/player-chunk.svelte.d.ts +31 -0
- package/dist/ui/player/providers/chunks-player-buffer/player-chunk.svelte.js +67 -0
- package/dist/ui/player/providers/chunks-player-buffer/player-chunks-manager.svelte.d.ts +23 -0
- package/dist/ui/player/providers/chunks-player-buffer/player-chunks-manager.svelte.js +119 -0
- package/dist/ui/player/providers/default-chunks-player-buffer.svelte.d.ts +20 -0
- package/dist/ui/player/providers/default-chunks-player-buffer.svelte.js +47 -0
- package/dist/ui/player/providers/default-feed-player-buffer.svelte.d.ts +27 -0
- package/dist/ui/player/providers/default-feed-player-buffer.svelte.js +78 -0
- package/dist/ui/player/providers/index.d.ts +3 -0
- package/dist/ui/player/providers/index.js +2 -0
- package/dist/ui/player/providers/types.d.ts +49 -0
- package/dist/ui/{player-slider → player/slider}/cmp.player-slider.svelte +7 -20
- package/dist/ui/{player-slider → player/slider}/cmp.player-slider.svelte.d.ts +4 -4
- package/dist/ui/{player-slider → player/slider}/index.d.ts +0 -2
- package/dist/ui/{player-slider → player/slider}/index.js +0 -1
- package/dist/ui/player/slider/types.d.ts +16 -0
- package/dist/ui/swipe-indicator/cmp.swipe-indicator.svelte +7 -8
- package/package.json +4 -4
- package/dist/media-center/media-center/short-video-resources-generator.d.ts +0 -8
- package/dist/short-videos/short-videos-player/cmp.short-videos-player.svelte.d.ts +0 -4
- package/dist/short-videos/short-videos-player/internal-short-video-player-provider.d.ts +0 -18
- package/dist/short-videos/short-videos-player/mapper.d.ts +0 -3
- package/dist/short-videos/short-videos-player/operations.graphql +0 -17
- package/dist/short-videos/short-videos-player/short-videos-player-view.svelte +0 -82
- package/dist/short-videos/short-videos-player/short-videos-player-view.svelte.d.ts +0 -8
- package/dist/short-videos/short-videos-player/types.d.ts +0 -26
- package/dist/streams/stream-player/internal-stream-player-data-provider.d.ts +0 -12
- package/dist/streams/stream-player/internal-stream-player-data-provider.js +0 -48
- package/dist/streams/stream-player/stream-player-buffer.svelte.d.ts +0 -28
- package/dist/streams/stream-player/stream-player-buffer.svelte.js +0 -79
- package/dist/streams/stream-player/stream-player-view.svelte.d.ts +0 -8
- package/dist/ui/player-button/types.js +0 -1
- package/dist/ui/player-slider/player-buffer.svelte.d.ts +0 -31
- package/dist/ui/player-slider/player-buffer.svelte.js +0 -76
- package/dist/ui/player-slider/types.d.ts +0 -26
- /package/dist/streams/{stream-player → data-loaders}/mapper.js +0 -0
- /package/dist/streams/{stream-player → streams-player}/internal-stream-analytics-handler.d.ts +0 -0
- /package/dist/streams/{stream-player → streams-player}/internal-stream-analytics-handler.js +0 -0
- /package/dist/streams/{stream-player → streams-player}/stream-player-localization.d.ts +0 -0
- /package/dist/streams/{stream-player → streams-player}/stream-player-localization.js +0 -0
- /package/dist/{short-videos/short-videos-player → streams/streams-player}/types.js +0 -0
- /package/dist/ui/{player-button → player/button}/cmp.player-buttons-group.svelte.d.ts +0 -0
- /package/dist/ui/{player-button → player/button}/index.d.ts +0 -0
- /package/dist/ui/{player-button → player/button}/index.js +0 -0
- /package/dist/{streams/stream-player → ui/player/providers}/types.js +0 -0
- /package/dist/ui/{player-slider → player/slider}/prevent-slider-scroll.d.ts +0 -0
- /package/dist/ui/{player-slider → player/slider}/prevent-slider-scroll.js +0 -0
- /package/dist/ui/{player-slider → player/slider}/types.js +0 -0
- /package/dist/ui/{player-slider → player/slider}/wheel-gestures-adapter.d.ts +0 -0
- /package/dist/ui/{player-slider → player/slider}/wheel-gestures-adapter.js +0 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ContinuationToken } from '../../../../core/continuation-token';
|
|
2
|
+
import { CursorDataLoader } from '../../../../core/data-loaders';
|
|
3
|
+
import { PlayerChunkItem } from './player-chunk-item.svelte';
|
|
4
|
+
const CHUNK_ITEMS_BUFFER_SIZE = 5;
|
|
5
|
+
export class PlayerChunk {
|
|
6
|
+
model;
|
|
7
|
+
items = $derived.by(() => this._chunkItems.map((i) => i.model));
|
|
8
|
+
chunkItems = $derived.by(() => this._chunkItems);
|
|
9
|
+
chunkIndex;
|
|
10
|
+
activeChunkItem = $derived.by(() => this._chunkItems[this._activeItemIndex] ?? null);
|
|
11
|
+
isEmpty = $derived.by(() => this.isFullyLoaded && this._chunkItems.length === 0);
|
|
12
|
+
isFullyLoaded = $state(false);
|
|
13
|
+
_chunkItems = $state.raw([]);
|
|
14
|
+
_activeItemIndex = $state(0);
|
|
15
|
+
_isLoading = $state(false);
|
|
16
|
+
_itemsLoader;
|
|
17
|
+
constructor(data) {
|
|
18
|
+
const { chunk, provider, chunkIndex, callbacks } = data;
|
|
19
|
+
this.model = chunk;
|
|
20
|
+
this.chunkIndex = chunkIndex;
|
|
21
|
+
this._itemsLoader = new CursorDataLoader({
|
|
22
|
+
loadPage: async (continuationToken) => {
|
|
23
|
+
if (this.isFullyLoaded) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const result = await provider.loadChunkItems(this.model.id, continuationToken.toNextChunkString());
|
|
27
|
+
const newItems = result.items;
|
|
28
|
+
this._chunkItems = [
|
|
29
|
+
...this._chunkItems,
|
|
30
|
+
...newItems.map((item, index) => new PlayerChunkItem({
|
|
31
|
+
model: item,
|
|
32
|
+
indexWithinChunk: this._chunkItems.length + index,
|
|
33
|
+
chunkId: this.model.id
|
|
34
|
+
}))
|
|
35
|
+
];
|
|
36
|
+
const continuationTokenResult = ContinuationToken.fromPayload(result.continuationToken);
|
|
37
|
+
if (!continuationTokenResult.canLoadMore) {
|
|
38
|
+
this.isFullyLoaded = true;
|
|
39
|
+
callbacks?.onChunkFullyLoaded(this);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
items: newItems,
|
|
43
|
+
continuationToken: continuationTokenResult
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
loadMore = () => this._itemsLoader.loadMore();
|
|
49
|
+
setActiveItemIndex = async (index, warmUp = true) => {
|
|
50
|
+
this._activeItemIndex = index;
|
|
51
|
+
if (warmUp) {
|
|
52
|
+
await this.warmUp();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
warmUp = async () => {
|
|
56
|
+
if (this._chunkItems.length >= this._activeItemIndex + CHUNK_ITEMS_BUFFER_SIZE || this._isLoading) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this._isLoading = true;
|
|
60
|
+
try {
|
|
61
|
+
await this.loadMore();
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
this._isLoading = false;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PlayerChunk } from './player-chunk.svelte';
|
|
2
|
+
import type { IChunksPlayerDataProvider, WithId } from '../types';
|
|
3
|
+
export declare class PlayerChunksManager<TItem extends WithId, TChunk extends WithId> {
|
|
4
|
+
private provider;
|
|
5
|
+
private callabacks;
|
|
6
|
+
readonly activeChunk: PlayerChunk<TItem, TChunk>;
|
|
7
|
+
readonly loadedChunks: PlayerChunk<TItem, TChunk>[];
|
|
8
|
+
readonly flattenedChunkItems: TItem[];
|
|
9
|
+
readonly flattenedActiveChunkItemIndex: number;
|
|
10
|
+
private _activeChunkIndex;
|
|
11
|
+
private _loadedChunks;
|
|
12
|
+
private _isLoading;
|
|
13
|
+
constructor(provider: IChunksPlayerDataProvider<TItem, TChunk>, callabacks: {
|
|
14
|
+
onInitializationFinished: () => void;
|
|
15
|
+
onEndReached: () => void;
|
|
16
|
+
});
|
|
17
|
+
initialize: () => Promise<void>;
|
|
18
|
+
setActiveChunkIndex: (index: number) => Promise<void>;
|
|
19
|
+
activateItemAtFlattenedIndex: (index: number) => Promise<void>;
|
|
20
|
+
warmUp: () => Promise<void>;
|
|
21
|
+
reset: () => void;
|
|
22
|
+
private populateChunkAtIndex;
|
|
23
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { PlayerChunk } from './player-chunk.svelte';
|
|
2
|
+
const CHUNKS_BUFFER_SIZE = 5;
|
|
3
|
+
const FIXED_START_INDEX = 0;
|
|
4
|
+
export class PlayerChunksManager {
|
|
5
|
+
provider;
|
|
6
|
+
callabacks;
|
|
7
|
+
activeChunk = $derived.by(() => this._loadedChunks[this._activeChunkIndex] ?? null);
|
|
8
|
+
loadedChunks = $derived.by(() => this._loadedChunks);
|
|
9
|
+
flattenedChunkItems = $derived.by(() => this._loadedChunks.reduce((acc, chunk) => {
|
|
10
|
+
acc.push(...chunk.items);
|
|
11
|
+
return acc;
|
|
12
|
+
}, []));
|
|
13
|
+
flattenedActiveChunkItemIndex = $derived.by(() => {
|
|
14
|
+
if (!this.activeChunk || !this.activeChunk.activeChunkItem) {
|
|
15
|
+
return -1;
|
|
16
|
+
}
|
|
17
|
+
let itemsBeforeActiveChunk = 0;
|
|
18
|
+
for (let i = 0; i < this.activeChunk.chunkIndex; i++) {
|
|
19
|
+
itemsBeforeActiveChunk += this._loadedChunks[i].items.length;
|
|
20
|
+
}
|
|
21
|
+
return itemsBeforeActiveChunk + this.activeChunk.activeChunkItem.indexWithinChunk;
|
|
22
|
+
});
|
|
23
|
+
_activeChunkIndex = $state(-1);
|
|
24
|
+
_loadedChunks = $state.raw([]);
|
|
25
|
+
_isLoading = $state(false);
|
|
26
|
+
constructor(provider, callabacks) {
|
|
27
|
+
this.provider = provider;
|
|
28
|
+
this.callabacks = callabacks;
|
|
29
|
+
}
|
|
30
|
+
initialize = async () => {
|
|
31
|
+
const { onInitializationFinished, onEndReached } = this.callabacks;
|
|
32
|
+
const handleInitialized = async () => {
|
|
33
|
+
const startIndex = Math.min(FIXED_START_INDEX, this._loadedChunks.length - 1);
|
|
34
|
+
const populateChunkResult = await this.populateChunkAtIndex(startIndex, (currentIndex) => currentIndex + 1);
|
|
35
|
+
if (!populateChunkResult) {
|
|
36
|
+
onEndReached();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.setActiveChunkIndex(populateChunkResult.closestReadyChunkIndex);
|
|
40
|
+
if (populateChunkResult.closestReadyChunkIndex === FIXED_START_INDEX &&
|
|
41
|
+
this.provider.initialData.startItemIndex &&
|
|
42
|
+
this.provider.initialData.startItemIndex > 0) {
|
|
43
|
+
this.activeChunk.setActiveItemIndex(this.provider.initialData.startItemIndex);
|
|
44
|
+
}
|
|
45
|
+
onInitializationFinished();
|
|
46
|
+
};
|
|
47
|
+
this._loadedChunks = this.provider.initialData.prefetchedChunks.map((chunk, chunkIndex) => new PlayerChunk({ chunk, chunkIndex, provider: { loadChunkItems: this.provider.loadChunkItems } }));
|
|
48
|
+
const considerInitialized = this._loadedChunks.length !== 0;
|
|
49
|
+
if (considerInitialized) {
|
|
50
|
+
handleInitialized();
|
|
51
|
+
}
|
|
52
|
+
await this.warmUp();
|
|
53
|
+
if (!considerInitialized) {
|
|
54
|
+
handleInitialized();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
setActiveChunkIndex = async (index) => {
|
|
58
|
+
this._activeChunkIndex = index;
|
|
59
|
+
this._loadedChunks.forEach((c) => c.setActiveItemIndex(0, false));
|
|
60
|
+
await this.populateChunkAtIndex(this._activeChunkIndex + 1, (currentIndex) => currentIndex + 1);
|
|
61
|
+
};
|
|
62
|
+
activateItemAtFlattenedIndex = async (index) => {
|
|
63
|
+
const activeChunkId = this.activeChunk?.model.id;
|
|
64
|
+
const flattenedItems = this.loadedChunks.flatMap((x) => x.chunkItems);
|
|
65
|
+
const nextItem = flattenedItems[index];
|
|
66
|
+
if (!nextItem) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (nextItem.chunkId !== activeChunkId) {
|
|
70
|
+
this.setActiveChunkIndex(this.loadedChunks.findIndex((c) => c.model.id === nextItem.chunkId));
|
|
71
|
+
this.activeChunk.warmUp();
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
this.activeChunk.setActiveItemIndex(nextItem.indexWithinChunk);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
warmUp = async () => {
|
|
78
|
+
// Early return if manager is sufficient or already loading
|
|
79
|
+
if (this._loadedChunks.length >= this._activeChunkIndex + CHUNKS_BUFFER_SIZE || this._isLoading) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
this._isLoading = true;
|
|
83
|
+
try {
|
|
84
|
+
const result = await this.provider.loadMoreChunks();
|
|
85
|
+
this._loadedChunks = [
|
|
86
|
+
...this._loadedChunks,
|
|
87
|
+
...result.map((chunk, index) => new PlayerChunk({
|
|
88
|
+
chunk,
|
|
89
|
+
chunkIndex: this._loadedChunks.length + index,
|
|
90
|
+
provider: { loadChunkItems: this.provider.loadChunkItems }
|
|
91
|
+
}))
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
this._isLoading = false;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
reset = () => {
|
|
99
|
+
this._activeChunkIndex = -1;
|
|
100
|
+
this._loadedChunks = [];
|
|
101
|
+
this._isLoading = false;
|
|
102
|
+
this.warmUp();
|
|
103
|
+
};
|
|
104
|
+
populateChunkAtIndex = async (index, nextIndexFn) => {
|
|
105
|
+
const chunkAtIndex = this._loadedChunks[index];
|
|
106
|
+
if (!chunkAtIndex) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
await chunkAtIndex.warmUp();
|
|
110
|
+
if (chunkAtIndex.items.length === 0) {
|
|
111
|
+
const nextIndex = nextIndexFn(index);
|
|
112
|
+
if (nextIndex > index) {
|
|
113
|
+
await this.warmUp();
|
|
114
|
+
}
|
|
115
|
+
return await this.populateChunkAtIndex(nextIndexFn(index), nextIndexFn);
|
|
116
|
+
}
|
|
117
|
+
return { closestReadyChunkIndex: index };
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IChunksPlayerBuffer, IChunksPlayerDataProvider, WithId } from './types';
|
|
2
|
+
export declare class DefaultChunksPlayerBuffer<TItem extends WithId, TChunk extends WithId> implements IChunksPlayerBuffer<TItem> {
|
|
3
|
+
readonly kind = "chunks";
|
|
4
|
+
readonly loaded: TItem[];
|
|
5
|
+
readonly currentIndex: number;
|
|
6
|
+
readonly current: TItem | null;
|
|
7
|
+
readonly canLoadNext: boolean;
|
|
8
|
+
readonly canLoadPrevious: boolean;
|
|
9
|
+
readonly navigationDisabled: boolean;
|
|
10
|
+
readonly animationDuration = 500;
|
|
11
|
+
private _playerChunksManager;
|
|
12
|
+
constructor(provider: IChunksPlayerDataProvider<TItem, TChunk>, on?: {
|
|
13
|
+
preloaded?: (self: DefaultChunksPlayerBuffer<TItem, TChunk>) => void;
|
|
14
|
+
});
|
|
15
|
+
get activeChunk(): import("./chunks-player-buffer").PlayerChunk<TItem, TChunk>;
|
|
16
|
+
setActiveChunkItemIndex: (index: number) => void;
|
|
17
|
+
loadNext: () => Promise<void>;
|
|
18
|
+
loadPrevious: () => Promise<void>;
|
|
19
|
+
reset: () => void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Utils } from '../../../core/utils';
|
|
2
|
+
import { PlayerChunksManager } from './chunks-player-buffer';
|
|
3
|
+
export class DefaultChunksPlayerBuffer {
|
|
4
|
+
kind = 'chunks';
|
|
5
|
+
loaded = $derived.by(() => this._playerChunksManager.flattenedChunkItems);
|
|
6
|
+
currentIndex = $derived.by(() => this._playerChunksManager.flattenedActiveChunkItemIndex);
|
|
7
|
+
current = $derived(this.currentIndex >= 0 ? this.loaded[this.currentIndex] : null);
|
|
8
|
+
canLoadNext = $derived(this.currentIndex < this.loaded.length - 1);
|
|
9
|
+
canLoadPrevious = $derived(this.currentIndex > 0);
|
|
10
|
+
navigationDisabled = $derived(!this.canLoadNext && !this.canLoadPrevious);
|
|
11
|
+
animationDuration = 500;
|
|
12
|
+
_playerChunksManager;
|
|
13
|
+
constructor(provider, on) {
|
|
14
|
+
// Throttle navigation methods
|
|
15
|
+
this.loadNext = Utils.throttle(this.loadNext, this.animationDuration);
|
|
16
|
+
this.loadPrevious = Utils.throttle(this.loadPrevious, this.animationDuration);
|
|
17
|
+
this._playerChunksManager = new PlayerChunksManager(provider, {
|
|
18
|
+
onInitializationFinished: () => on?.preloaded?.(this),
|
|
19
|
+
onEndReached: () => console.warn('end reached')
|
|
20
|
+
});
|
|
21
|
+
this._playerChunksManager.initialize();
|
|
22
|
+
}
|
|
23
|
+
get activeChunk() {
|
|
24
|
+
return this._playerChunksManager.activeChunk;
|
|
25
|
+
}
|
|
26
|
+
setActiveChunkItemIndex = (index) => {
|
|
27
|
+
if (!this.activeChunk) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
this.activeChunk.setActiveItemIndex(index);
|
|
31
|
+
};
|
|
32
|
+
loadNext = async () => {
|
|
33
|
+
if (!this.canLoadNext) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this._playerChunksManager.activateItemAtFlattenedIndex(this.currentIndex + 1);
|
|
37
|
+
};
|
|
38
|
+
loadPrevious = async () => {
|
|
39
|
+
if (!this.canLoadPrevious) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
this._playerChunksManager.activateItemAtFlattenedIndex(this.currentIndex - 1);
|
|
43
|
+
};
|
|
44
|
+
reset = () => {
|
|
45
|
+
this._playerChunksManager.reset();
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { IFeedPlayerBuffer, IFeedPlayerDataProvider, WithId } from './types';
|
|
2
|
+
export declare class DefaultFeedPlayerBuffer<T extends WithId> implements IFeedPlayerBuffer<T> {
|
|
3
|
+
readonly kind = "feed";
|
|
4
|
+
readonly loaded: (T & {
|
|
5
|
+
mediaIndex?: number;
|
|
6
|
+
})[];
|
|
7
|
+
readonly currentIndex: number;
|
|
8
|
+
readonly current: (T & {
|
|
9
|
+
mediaIndex?: number;
|
|
10
|
+
}) | null;
|
|
11
|
+
readonly canLoadNext: boolean;
|
|
12
|
+
readonly canLoadPrevious: boolean;
|
|
13
|
+
readonly navigationDisabled: boolean;
|
|
14
|
+
readonly animationDuration = 500;
|
|
15
|
+
private _currentIndex;
|
|
16
|
+
private _loaded;
|
|
17
|
+
private _loadMoreFn;
|
|
18
|
+
private _isLoading;
|
|
19
|
+
constructor(provider: IFeedPlayerDataProvider<T>, on?: {
|
|
20
|
+
preloaded?: (self: DefaultFeedPlayerBuffer<T>) => void;
|
|
21
|
+
});
|
|
22
|
+
loadNext: () => Promise<void>;
|
|
23
|
+
loadPrevious: () => Promise<void>;
|
|
24
|
+
reset: () => void;
|
|
25
|
+
private initializeBuffer;
|
|
26
|
+
private warmUpBuffer;
|
|
27
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Utils } from '../../../core/utils';
|
|
2
|
+
const BUFFER_SIZE = 5;
|
|
3
|
+
export class DefaultFeedPlayerBuffer {
|
|
4
|
+
kind = 'feed';
|
|
5
|
+
loaded = $derived.by(() => this._loaded);
|
|
6
|
+
currentIndex = $derived.by(() => this._currentIndex);
|
|
7
|
+
current = $derived(this.currentIndex >= 0 ? this.loaded[this.currentIndex] : null);
|
|
8
|
+
canLoadNext = $derived(this.currentIndex < this.loaded.length - 1);
|
|
9
|
+
canLoadPrevious = $derived(this.currentIndex > 0);
|
|
10
|
+
navigationDisabled = $derived(!this.canLoadNext && !this.canLoadPrevious);
|
|
11
|
+
animationDuration = 500;
|
|
12
|
+
_currentIndex = $state(-1);
|
|
13
|
+
_loaded = $state.raw([]);
|
|
14
|
+
_loadMoreFn;
|
|
15
|
+
_isLoading = $state(false);
|
|
16
|
+
constructor(provider, on) {
|
|
17
|
+
this._loadMoreFn = provider.loadMore;
|
|
18
|
+
// Throttle navigation methods
|
|
19
|
+
this.loadNext = Utils.throttle(this.loadNext, this.animationDuration);
|
|
20
|
+
this.loadPrevious = Utils.throttle(this.loadPrevious, this.animationDuration);
|
|
21
|
+
this.initializeBuffer({ initialData: provider.initialData, onPreloaded: on?.preloaded });
|
|
22
|
+
}
|
|
23
|
+
loadNext = async () => {
|
|
24
|
+
if (!this.canLoadNext) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
++this._currentIndex;
|
|
28
|
+
this.warmUpBuffer();
|
|
29
|
+
};
|
|
30
|
+
loadPrevious = async () => {
|
|
31
|
+
if (!this.canLoadPrevious) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
--this._currentIndex;
|
|
35
|
+
};
|
|
36
|
+
reset = () => {
|
|
37
|
+
this._loaded = [];
|
|
38
|
+
this._currentIndex = -1;
|
|
39
|
+
this._isLoading = false;
|
|
40
|
+
this.warmUpBuffer();
|
|
41
|
+
};
|
|
42
|
+
initializeBuffer = async (options) => {
|
|
43
|
+
const { initialData, onPreloaded } = options;
|
|
44
|
+
const handleInitialized = () => {
|
|
45
|
+
const startIndex = initialData.startIndex >= 0 ? initialData.startIndex : 0;
|
|
46
|
+
this._currentIndex = Math.min(startIndex, this._loaded.length - 1);
|
|
47
|
+
const hasCustomMediaIndex = initialData.startMediaIndex && initialData.startMediaIndex > 0;
|
|
48
|
+
const activeItem = this._loaded[this._currentIndex];
|
|
49
|
+
if (activeItem && hasCustomMediaIndex) {
|
|
50
|
+
activeItem.mediaIndex = initialData.startMediaIndex;
|
|
51
|
+
}
|
|
52
|
+
onPreloaded?.(this);
|
|
53
|
+
};
|
|
54
|
+
this._loaded = initialData.prefetchedItems;
|
|
55
|
+
const considerInitialized = this._loaded.length > 0;
|
|
56
|
+
if (considerInitialized) {
|
|
57
|
+
handleInitialized();
|
|
58
|
+
}
|
|
59
|
+
await this.warmUpBuffer();
|
|
60
|
+
if (!considerInitialized) {
|
|
61
|
+
handleInitialized();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
warmUpBuffer = async () => {
|
|
65
|
+
// Early return if buffer is sufficient or already loading
|
|
66
|
+
if (this._loaded.length >= this.currentIndex + BUFFER_SIZE || this._isLoading) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this._isLoading = true;
|
|
70
|
+
try {
|
|
71
|
+
const result = await this._loadMoreFn();
|
|
72
|
+
this._loaded = [...this._loaded, ...result];
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
this._isLoading = false;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { IPlayerBuffer, IPlayerDataProvider, IFeedPlayerDataProvider, IChunksPlayerDataProvider } from './types';
|
|
2
|
+
export { DefaultFeedPlayerBuffer } from './default-feed-player-buffer.svelte';
|
|
3
|
+
export { DefaultChunksPlayerBuffer } from './default-chunks-player-buffer.svelte';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export type IPlayerDataProvider<T extends WithId> = IFeedPlayerDataProvider<T> | IChunksPlayerDataProvider<T>;
|
|
2
|
+
export interface IFeedPlayerDataProvider<T extends WithId> {
|
|
3
|
+
kind: 'feed';
|
|
4
|
+
initialData: {
|
|
5
|
+
prefetchedItems: T[];
|
|
6
|
+
startIndex: number;
|
|
7
|
+
startMediaIndex?: number;
|
|
8
|
+
};
|
|
9
|
+
loadMore(): Promise<T[]>;
|
|
10
|
+
}
|
|
11
|
+
export interface IChunksPlayerDataProvider<TItem extends WithId, TChunk extends WithId = WithId> {
|
|
12
|
+
kind: 'chunks';
|
|
13
|
+
initialData: {
|
|
14
|
+
prefetchedChunks: TChunk[];
|
|
15
|
+
startItemIndex?: number;
|
|
16
|
+
};
|
|
17
|
+
loadMoreChunks: () => Promise<TChunk[]>;
|
|
18
|
+
loadChunkItems: (chunkId: string, continuationToken: string | null | undefined) => Promise<{
|
|
19
|
+
items: TItem[];
|
|
20
|
+
continuationToken: string | null;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
23
|
+
export type IPlayerBuffer<T extends WithId> = IFeedPlayerBuffer<T> | IChunksPlayerBuffer<T>;
|
|
24
|
+
export interface IPlayerBufferBase<T extends WithId> {
|
|
25
|
+
readonly kind: 'feed' | 'chunks';
|
|
26
|
+
readonly current: TExtended<T> | null;
|
|
27
|
+
readonly loaded: TExtended<T>[];
|
|
28
|
+
readonly currentIndex: number;
|
|
29
|
+
readonly canLoadNext: boolean;
|
|
30
|
+
readonly canLoadPrevious: boolean;
|
|
31
|
+
readonly navigationDisabled: boolean;
|
|
32
|
+
readonly animationDuration: number;
|
|
33
|
+
loadNext: () => void;
|
|
34
|
+
loadPrevious: () => void;
|
|
35
|
+
reset: () => void;
|
|
36
|
+
}
|
|
37
|
+
type TExtended<T> = T & {
|
|
38
|
+
mediaIndex?: number;
|
|
39
|
+
};
|
|
40
|
+
export interface IFeedPlayerBuffer<T extends WithId> extends IPlayerBufferBase<T> {
|
|
41
|
+
readonly kind: 'feed';
|
|
42
|
+
}
|
|
43
|
+
export interface IChunksPlayerBuffer<T extends WithId> extends IPlayerBufferBase<T> {
|
|
44
|
+
readonly kind: 'chunks';
|
|
45
|
+
}
|
|
46
|
+
export type WithId = {
|
|
47
|
+
id: string;
|
|
48
|
+
};
|
|
49
|
+
export {};
|
|
@@ -6,8 +6,8 @@ let sliderHeight = $state(0);
|
|
|
6
6
|
let swipeTransition = $state(0);
|
|
7
7
|
let cssAnimationDuration = $state(buffer.animationDuration * 0.55);
|
|
8
8
|
let resizeObserver;
|
|
9
|
-
let
|
|
10
|
-
const actualTransition = $derived(-sliderHeight *
|
|
9
|
+
let sliderIndex = $state.raw(buffer.currentIndex);
|
|
10
|
+
const actualTransition = $derived(-sliderHeight * sliderIndex);
|
|
11
11
|
const onKeyPress = (e) => {
|
|
12
12
|
if (e.key === 'ArrowUp' || e.key === 'PageUp') {
|
|
13
13
|
buffer.loadPrevious();
|
|
@@ -17,29 +17,16 @@ const onKeyPress = (e) => {
|
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
$effect(() => {
|
|
20
|
-
if (buffer.currentIndex >= 0 &&
|
|
20
|
+
if (buffer.currentIndex >= 0 && sliderIndex >= 0 && Math.abs(sliderIndex - buffer.currentIndex) === 1) {
|
|
21
21
|
slidesRef.classList.toggle('animate', true);
|
|
22
22
|
}
|
|
23
|
-
else if (buffer.currentIndex >= 0 && (Math.abs(
|
|
23
|
+
else if (buffer.currentIndex >= 0 && (Math.abs(sliderIndex - buffer.currentIndex) !== 0 || !active)) {
|
|
24
24
|
untrack(() => notifyOnItemChanged());
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
|
-
// Notify the parent component that the active item is about to change.
|
|
28
27
|
let active = null;
|
|
29
28
|
$effect(() => {
|
|
30
|
-
|
|
31
|
-
untrack(() => {
|
|
32
|
-
var _a, _b, _c;
|
|
33
|
-
if (active && ((_a = buffer.current) === null || _a === void 0 ? void 0 : _a.id) !== active.id) {
|
|
34
|
-
(_b = on === null || on === void 0 ? void 0 : on.itemPreDeactivated) === null || _b === void 0 ? void 0 : _b.call(on, { itemId: active.id, loadingNext: buffer.currentIndex > activeIndex });
|
|
35
|
-
}
|
|
36
|
-
const nextItem = buffer.loaded[buffer.currentIndex];
|
|
37
|
-
if (nextItem) {
|
|
38
|
-
(_c = on === null || on === void 0 ? void 0 : on.itemPreActivated) === null || _c === void 0 ? void 0 : _c.call(on, nextItem);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
activeIndex = buffer.currentIndex;
|
|
29
|
+
sliderIndex = buffer.currentIndex;
|
|
43
30
|
});
|
|
44
31
|
const notifyOnItemChanged = () => {
|
|
45
32
|
var _a, _b, _c;
|
|
@@ -172,9 +159,9 @@ const wheelCallbacks = {
|
|
|
172
159
|
<div class="player-slider__slides" bind:this={slidesRef} use:createWheelAdapter={{ cbs: wheelCallbacks }} style={styles}>
|
|
173
160
|
{#each buffer.loaded as item, index (item)}
|
|
174
161
|
<div class="player-slider__slide">
|
|
175
|
-
{#if index >=
|
|
162
|
+
{#if index >= sliderIndex - 1 && index <= sliderIndex + 1}
|
|
176
163
|
<!-- Only render the active slide and its immediate neighbors for performance -->
|
|
177
|
-
{@render children({ item, active: index ===
|
|
164
|
+
{@render children({ item, active: index === sliderIndex })}
|
|
178
165
|
{/if}
|
|
179
166
|
</div>
|
|
180
167
|
{/each}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PlayerSliderBuffer, PlayerSliderCallbacks } from './types';
|
|
2
2
|
import { type Snippet } from 'svelte';
|
|
3
3
|
declare class __sveltets_Render<T extends {
|
|
4
4
|
id: string;
|
|
5
5
|
}> {
|
|
6
6
|
props(): {
|
|
7
|
-
buffer:
|
|
8
|
-
on?: PlayerSliderCallbacks
|
|
7
|
+
buffer: PlayerSliderBuffer<T>;
|
|
8
|
+
on?: PlayerSliderCallbacks;
|
|
9
9
|
children: Snippet<[{
|
|
10
|
-
item:
|
|
10
|
+
item: T;
|
|
11
11
|
active?: boolean;
|
|
12
12
|
}]>;
|
|
13
13
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type PlayerSliderCallbacks = {
|
|
2
|
+
itemActivated?: (e: string) => void;
|
|
3
|
+
itemDeactivated?: (e: string) => void;
|
|
4
|
+
};
|
|
5
|
+
export interface PlayerSliderBuffer<T extends {
|
|
6
|
+
id: string;
|
|
7
|
+
}> {
|
|
8
|
+
readonly current: T | null;
|
|
9
|
+
readonly loaded: T[];
|
|
10
|
+
readonly currentIndex: number;
|
|
11
|
+
readonly canLoadNext: boolean;
|
|
12
|
+
readonly canLoadPrevious: boolean;
|
|
13
|
+
readonly animationDuration: number;
|
|
14
|
+
loadNext: () => void;
|
|
15
|
+
loadPrevious: () => void;
|
|
16
|
+
}
|
|
@@ -27,8 +27,7 @@ const indicatorMounted = (_) => {
|
|
|
27
27
|
</div>
|
|
28
28
|
</div>
|
|
29
29
|
|
|
30
|
-
<style>@
|
|
31
|
-
@keyframes fadeIn {
|
|
30
|
+
<style>@keyframes fadeIn {
|
|
32
31
|
0% {
|
|
33
32
|
opacity: 1;
|
|
34
33
|
}
|
|
@@ -87,37 +86,37 @@ const indicatorMounted = (_) => {
|
|
|
87
86
|
transform: translateY(0);
|
|
88
87
|
}
|
|
89
88
|
10% {
|
|
90
|
-
transform: translateY(-24px);
|
|
89
|
+
transform: translateY(-24px);
|
|
91
90
|
}
|
|
92
91
|
18% {
|
|
93
92
|
transform: translateY(0);
|
|
94
93
|
}
|
|
95
94
|
26% {
|
|
96
|
-
transform: translateY(-12px);
|
|
95
|
+
transform: translateY(-12px);
|
|
97
96
|
}
|
|
98
97
|
34% {
|
|
99
98
|
transform: translateY(0);
|
|
100
99
|
}
|
|
101
100
|
41% {
|
|
102
|
-
transform: translateY(-8px);
|
|
101
|
+
transform: translateY(-8px);
|
|
103
102
|
}
|
|
104
103
|
48% {
|
|
105
104
|
transform: translateY(0);
|
|
106
105
|
}
|
|
107
106
|
54% {
|
|
108
|
-
transform: translateY(-4px);
|
|
107
|
+
transform: translateY(-4px);
|
|
109
108
|
}
|
|
110
109
|
60% {
|
|
111
110
|
transform: translateY(0);
|
|
112
111
|
}
|
|
113
112
|
65% {
|
|
114
|
-
transform: translateY(-2px);
|
|
113
|
+
transform: translateY(-2px);
|
|
115
114
|
}
|
|
116
115
|
70% {
|
|
117
116
|
transform: translateY(0);
|
|
118
117
|
}
|
|
119
118
|
75% {
|
|
120
|
-
transform: translateY(-1px);
|
|
119
|
+
transform: translateY(-1px);
|
|
121
120
|
}
|
|
122
121
|
80% {
|
|
123
122
|
transform: translateY(0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamscloud/embeddable",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"author": "StreamsCloud",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"types": "./dist/posts/post-viewer/index.d.ts",
|
|
50
50
|
"svelte": "./dist/posts/post-viewer/index.js"
|
|
51
51
|
},
|
|
52
|
-
"./
|
|
53
|
-
"types": "./dist/streams/
|
|
54
|
-
"svelte": "./dist/streams/
|
|
52
|
+
"./streams-player": {
|
|
53
|
+
"types": "./dist/streams/streams-player/index.d.ts",
|
|
54
|
+
"svelte": "./dist/streams/streams-player/index.js"
|
|
55
55
|
},
|
|
56
56
|
"./short-videos-player": {
|
|
57
57
|
"types": "./dist/short-videos/short-videos-player/index.d.ts",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ShortVideoPlayerModel } from '../../short-videos/short-videos-player';
|
|
2
|
-
import type { IPlayerItemsProvider } from '../../ui/player-slider';
|
|
3
|
-
import type { IMediaCenterConfig } from '../config/types';
|
|
4
|
-
export declare const makeShortVideosProvider: (data: {
|
|
5
|
-
config: IMediaCenterConfig;
|
|
6
|
-
categoryId?: string;
|
|
7
|
-
prefetchedItems?: ShortVideoPlayerModel[];
|
|
8
|
-
}) => IPlayerItemsProvider<ShortVideoPlayerModel>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { IPlayerItemsProvider } from '../../ui/player-slider';
|
|
2
|
-
import type { ShortVideoPlayerModel } from './types';
|
|
3
|
-
export declare class InternalShortVideoPlayerProvider implements IPlayerItemsProvider<ShortVideoPlayerModel> {
|
|
4
|
-
initialData: IPlayerItemsProvider<ShortVideoPlayerModel>['initialData'];
|
|
5
|
-
private ids;
|
|
6
|
-
private idOrder;
|
|
7
|
-
private initialId?;
|
|
8
|
-
private graphql;
|
|
9
|
-
private dataLoader;
|
|
10
|
-
constructor(input: {
|
|
11
|
-
ids: string[];
|
|
12
|
-
initiator?: string;
|
|
13
|
-
graphqlOrigin?: string;
|
|
14
|
-
initialId?: string;
|
|
15
|
-
});
|
|
16
|
-
loadMore: () => Promise<ShortVideoPlayerModel[]>;
|
|
17
|
-
prefetch: () => Promise<void>;
|
|
18
|
-
}
|