detail-panel.svelte 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <script lang="ts">
  2. import Close from 'svelte-material-icons/Close.svelte';
  3. import Calendar from 'svelte-material-icons/Calendar.svelte';
  4. import ImageOutline from 'svelte-material-icons/ImageOutline.svelte';
  5. import CameraIris from 'svelte-material-icons/CameraIris.svelte';
  6. import MapMarkerOutline from 'svelte-material-icons/MapMarkerOutline.svelte';
  7. import { createEventDispatcher, onMount } from 'svelte';
  8. import { browser } from '$app/environment';
  9. import { AssetResponseDto, AlbumResponseDto } from '@api';
  10. import { asByteUnitString } from '../../utils/byte-units';
  11. type Leaflet = typeof import('leaflet');
  12. type LeafletMap = import('leaflet').Map;
  13. type LeafletMarker = import('leaflet').Marker;
  14. // Map Property
  15. let map: LeafletMap;
  16. let leaflet: Leaflet;
  17. let marker: LeafletMarker;
  18. export let asset: AssetResponseDto;
  19. $: if (asset.exifInfo?.latitude != null && asset.exifInfo?.longitude != null) {
  20. drawMap(asset.exifInfo.latitude, asset.exifInfo.longitude);
  21. }
  22. export let albums: AlbumResponseDto[];
  23. onMount(async () => {
  24. if (browser) {
  25. if (asset.exifInfo?.latitude != null && asset.exifInfo?.longitude != null) {
  26. await drawMap(asset.exifInfo.latitude, asset.exifInfo.longitude);
  27. }
  28. }
  29. });
  30. async function drawMap(lat: number, lon: number) {
  31. if (!leaflet) {
  32. leaflet = await import('leaflet');
  33. }
  34. if (!map) {
  35. map = leaflet.map('map');
  36. leaflet
  37. .tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  38. attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
  39. })
  40. .addTo(map);
  41. }
  42. if (marker) {
  43. map.removeLayer(marker);
  44. }
  45. map.setView([lat || 0, lon || 0], 17);
  46. marker = leaflet.marker([lat || 0, lon || 0]);
  47. marker.bindPopup(`${(lat || 0).toFixed(7)},${(lon || 0).toFixed(7)}`);
  48. map.addLayer(marker);
  49. }
  50. const dispatch = createEventDispatcher();
  51. const getMegapixel = (width: number, height: number): number | undefined => {
  52. const megapixel = Math.round((height * width) / 1_000_000);
  53. if (megapixel) {
  54. return megapixel;
  55. }
  56. return undefined;
  57. };
  58. const locale = navigator.language;
  59. </script>
  60. <section class="p-2 dark:bg-immich-dark-bg dark:text-immich-dark-fg">
  61. <div class="flex place-items-center gap-2">
  62. <button
  63. class="rounded-full p-3 flex place-items-center place-content-center hover:bg-gray-200 transition-colors dark:text-immich-dark-fg dark:hover:bg-gray-900"
  64. on:click={() => dispatch('close')}
  65. >
  66. <Close size="24" />
  67. </button>
  68. <p class="text-immich-fg dark:text-immich-dark-fg text-lg">Info</p>
  69. </div>
  70. <div class="px-4 py-4">
  71. {#if !asset.exifInfo}
  72. <p class="text-sm pb-4">NO EXIF INFO AVAILABLE</p>
  73. {:else}
  74. <p class="text-sm pb-4">DETAILS</p>
  75. {/if}
  76. {#if asset.exifInfo?.dateTimeOriginal}
  77. {@const assetDateTimeOriginal = new Date(asset.exifInfo.dateTimeOriginal)}
  78. <div class="flex gap-4 py-4">
  79. <div>
  80. <Calendar size="24" />
  81. </div>
  82. <div>
  83. <p>
  84. {assetDateTimeOriginal.toLocaleDateString(locale, {
  85. month: 'short',
  86. day: 'numeric',
  87. year: 'numeric'
  88. })}
  89. </p>
  90. <div class="flex gap-2 text-sm">
  91. <p>
  92. {assetDateTimeOriginal.toLocaleString(locale, {
  93. weekday: 'short',
  94. hour: 'numeric',
  95. minute: '2-digit',
  96. timeZoneName: 'longOffset'
  97. })}
  98. </p>
  99. </div>
  100. </div>
  101. </div>{/if}
  102. {#if asset.exifInfo?.fileSizeInByte}
  103. <div class="flex gap-4 py-4">
  104. <div><ImageOutline size="24" /></div>
  105. <div>
  106. <p>{`${asset.exifInfo.imageName}.${asset.originalPath.split('.')[1]}` || ''}</p>
  107. <div class="flex text-sm gap-2">
  108. {#if asset.exifInfo.exifImageHeight && asset.exifInfo.exifImageWidth}
  109. {#if getMegapixel(asset.exifInfo.exifImageHeight, asset.exifInfo.exifImageWidth)}
  110. <p>
  111. {getMegapixel(asset.exifInfo.exifImageHeight, asset.exifInfo.exifImageWidth)} MP
  112. </p>
  113. {/if}
  114. <p>{asset.exifInfo.exifImageHeight} x {asset.exifInfo.exifImageWidth}</p>
  115. {/if}
  116. <p>{asByteUnitString(asset.exifInfo.fileSizeInByte)}</p>
  117. </div>
  118. </div>
  119. </div>
  120. {/if}
  121. {#if asset.exifInfo?.fNumber}
  122. <div class="flex gap-4 py-4">
  123. <div><CameraIris size="24" /></div>
  124. <div>
  125. <p>{asset.exifInfo.make || ''} {asset.exifInfo.model || ''}</p>
  126. <div class="flex text-sm gap-2">
  127. <p>{`ƒ/${asset.exifInfo.fNumber.toLocaleString(locale)}` || ''}</p>
  128. {#if asset.exifInfo.exposureTime}
  129. <p>{`1/${Math.floor(1 / asset.exifInfo.exposureTime)}`}</p>
  130. {/if}
  131. {#if asset.exifInfo.focalLength}
  132. <p>{`${asset.exifInfo.focalLength.toLocaleString(locale)} mm`}</p>
  133. {/if}
  134. {#if asset.exifInfo.iso}
  135. <p>
  136. {`ISO${asset.exifInfo.iso}`}
  137. </p>
  138. {/if}
  139. </div>
  140. </div>
  141. </div>
  142. {/if}
  143. {#if asset.exifInfo?.city}
  144. <div class="flex gap-4 py-4">
  145. <div><MapMarkerOutline size="24" /></div>
  146. <div>
  147. <p>{asset.exifInfo.city}</p>
  148. <div class="flex text-sm gap-2">
  149. <p>{asset.exifInfo.state}</p>
  150. </div>
  151. <div class="flex text-sm gap-2">
  152. <p>{asset.exifInfo.country}</p>
  153. </div>
  154. </div>
  155. </div>
  156. {/if}
  157. </div>
  158. </section>
  159. <div class={`${asset.exifInfo?.latitude ? 'visible' : 'hidden'}`}>
  160. <div class="h-[360px] w-full" id="map" />
  161. </div>
  162. <section class="p-2 dark:text-immich-dark-fg">
  163. <div class="px-4 py-4">
  164. {#if albums.length > 0}
  165. <p class="text-sm pb-4 ">APPEARS IN</p>
  166. {/if}
  167. {#each albums as album}
  168. <a data-sveltekit-preload-data="hover" href={`/albums/${album.id}`}>
  169. <div
  170. class="flex gap-4 py-2 hover:cursor-pointer"
  171. on:click={() => dispatch('click', album)}
  172. on:keydown={() => dispatch('click', album)}
  173. >
  174. <div>
  175. <img
  176. alt={album.albumName}
  177. class="w-[50px] h-[50px] object-cover rounded"
  178. src={`/api/asset/thumbnail/${album.albumThumbnailAssetId}?format=JPEG`}
  179. />
  180. </div>
  181. <div class="mt-auto mb-auto">
  182. <p class="dark:text-immich-dark-primary">{album.albumName}</p>
  183. <div class="flex gap-2 text-sm">
  184. <p>{album.assetCount} items</p>
  185. {#if album.shared}
  186. <p>· Shared</p>
  187. {/if}
  188. </div>
  189. </div>
  190. </div>
  191. </a>
  192. {/each}
  193. </div>
  194. </section>
  195. <style>
  196. @import 'https://unpkg.com/leaflet@1.7.1/dist/leaflet.css';
  197. </style>