2025-06-04 22:27:54 -04:00
|
|
|
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
|
2025-04-28 15:53:26 +02:00
|
|
|
import { locale } from '$lib/stores/preferences.store';
|
2025-05-28 09:55:14 -04:00
|
|
|
import { fromTimelinePlainDateTime } from '$lib/utils/timeline-util';
|
2024-07-07 22:29:56 +00:00
|
|
|
import { t } from 'svelte-i18n';
|
2025-04-28 15:53:26 +02:00
|
|
|
import { derived, get } from 'svelte/store';
|
2024-03-03 16:42:17 -05:00
|
|
|
|
2023-07-02 17:46:20 -05:00
|
|
|
/**
|
|
|
|
|
* Calculate thumbnail size based on number of assets and viewport width
|
|
|
|
|
* @param assetCount Number of assets in the view
|
|
|
|
|
* @param viewWidth viewport width
|
|
|
|
|
* @returns thumbnail size
|
|
|
|
|
*/
|
|
|
|
|
export function getThumbnailSize(assetCount: number, viewWidth: number): number {
|
|
|
|
|
if (assetCount < 6) {
|
|
|
|
|
return Math.min(320, Math.floor(viewWidth / assetCount - assetCount));
|
2023-11-28 15:16:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (viewWidth > 600) {
|
|
|
|
|
return viewWidth / 7 - 7;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (viewWidth > 400) {
|
|
|
|
|
return viewWidth / 4 - 6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (viewWidth > 300) {
|
|
|
|
|
return viewWidth / 2 - 6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (viewWidth > 200) {
|
|
|
|
|
return viewWidth / 2 - 6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (viewWidth > 100) {
|
|
|
|
|
return viewWidth / 1 - 6;
|
2023-07-02 17:46:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 300;
|
|
|
|
|
}
|
2024-03-03 16:42:17 -05:00
|
|
|
|
2024-07-07 22:29:56 +00:00
|
|
|
export const getAltText = derived(t, ($t) => {
|
2025-05-17 22:57:08 -04:00
|
|
|
return (asset: TimelineAsset) => {
|
2025-05-28 09:55:14 -04:00
|
|
|
const date = fromTimelinePlainDateTime(asset.localDateTime).toJSDate().toLocaleString(get(locale), {
|
|
|
|
|
dateStyle: 'long',
|
|
|
|
|
timeZone: 'UTC',
|
|
|
|
|
});
|
2025-05-19 17:40:48 -04:00
|
|
|
const hasPlace = asset.city && asset.country;
|
2025-05-17 22:57:08 -04:00
|
|
|
|
2025-05-19 17:40:48 -04:00
|
|
|
const peopleCount = asset.people.length;
|
2025-05-17 22:57:08 -04:00
|
|
|
const isVideo = asset.isVideo;
|
2024-03-03 16:42:17 -05:00
|
|
|
|
2024-07-26 14:48:40 -04:00
|
|
|
const values = {
|
|
|
|
|
date,
|
2025-05-19 17:40:48 -04:00
|
|
|
city: asset.city,
|
|
|
|
|
country: asset.country,
|
|
|
|
|
person1: asset.people[0],
|
|
|
|
|
person2: asset.people[1],
|
|
|
|
|
person3: asset.people[2],
|
2024-07-26 14:48:40 -04:00
|
|
|
isVideo,
|
|
|
|
|
additionalCount: peopleCount > 3 ? peopleCount - 2 : 0,
|
|
|
|
|
};
|
2024-03-03 16:42:17 -05:00
|
|
|
|
2024-07-26 14:48:40 -04:00
|
|
|
if (peopleCount > 0) {
|
|
|
|
|
switch (peopleCount) {
|
|
|
|
|
case 1: {
|
|
|
|
|
return hasPlace
|
|
|
|
|
? $t('image_alt_text_date_place_1_person', { values })
|
|
|
|
|
: $t('image_alt_text_date_1_person', { values });
|
|
|
|
|
}
|
|
|
|
|
case 2: {
|
|
|
|
|
return hasPlace
|
|
|
|
|
? $t('image_alt_text_date_place_2_people', { values })
|
|
|
|
|
: $t('image_alt_text_date_2_people', { values });
|
|
|
|
|
}
|
|
|
|
|
case 3: {
|
|
|
|
|
return hasPlace
|
|
|
|
|
? $t('image_alt_text_date_place_3_people', { values })
|
|
|
|
|
: $t('image_alt_text_date_3_people', { values });
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
return hasPlace
|
|
|
|
|
? $t('image_alt_text_date_place_4_or_more_people', { values })
|
|
|
|
|
: $t('image_alt_text_date_4_or_more_people', { values });
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-07 22:29:56 +00:00
|
|
|
}
|
2024-03-03 16:42:17 -05:00
|
|
|
|
2024-07-26 14:48:40 -04:00
|
|
|
if (hasPlace) {
|
|
|
|
|
return $t('image_alt_text_date_place', { values });
|
|
|
|
|
}
|
2024-07-07 22:29:56 +00:00
|
|
|
|
2024-07-26 14:48:40 -04:00
|
|
|
return $t('image_alt_text_date', { values });
|
2024-07-07 22:29:56 +00:00
|
|
|
};
|
|
|
|
|
});
|