@widgetic/file-browser 0.5.17
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/README.md +131 -0
- package/dist/components/FolderTree.svelte +143 -0
- package/dist/components/FolderTree.svelte.d.ts +32 -0
- package/dist/components/core/FileBrowser.css +79 -0
- package/dist/components/core/FileBrowser.svelte +3989 -0
- package/dist/components/core/FileBrowser.svelte.d.ts +55 -0
- package/dist/components/core/FileUploader.svelte +1152 -0
- package/dist/components/core/FileUploader.svelte.d.ts +43 -0
- package/dist/components/core/Header.svelte +143 -0
- package/dist/components/core/Header.svelte.d.ts +36 -0
- package/dist/components/core/RecentFiles.svelte +753 -0
- package/dist/components/core/RecentFiles.svelte.d.ts +37 -0
- package/dist/components/core/UploadStatus.svelte +133 -0
- package/dist/components/core/UploadStatus.svelte.d.ts +28 -0
- package/dist/components/core/UploadStatusList.svelte +138 -0
- package/dist/components/core/UploadStatusList.svelte.d.ts +33 -0
- package/dist/components/core/index.d.ts +4 -0
- package/dist/components/core/index.js +4 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/components/index.js +8 -0
- package/dist/components/items/FileItem.svelte +684 -0
- package/dist/components/items/FileItem.svelte.d.ts +34 -0
- package/dist/components/items/FolderItem.svelte +77 -0
- package/dist/components/items/FolderItem.svelte.d.ts +27 -0
- package/dist/components/items/index.d.ts +2 -0
- package/dist/components/items/index.js +2 -0
- package/dist/components/modals/MoveDialog.svelte +539 -0
- package/dist/components/modals/MoveDialog.svelte.d.ts +32 -0
- package/dist/components/modals/NewFolderButton.svelte +25 -0
- package/dist/components/modals/NewFolderButton.svelte.d.ts +20 -0
- package/dist/components/modals/README.md +99 -0
- package/dist/components/modals/SearchModal.svelte +500 -0
- package/dist/components/modals/SearchModal.svelte.d.ts +28 -0
- package/dist/components/modals/SelectedFilesModal.svelte +291 -0
- package/dist/components/modals/SelectedFilesModal.svelte.d.ts +32 -0
- package/dist/components/modals/index.d.ts +6 -0
- package/dist/components/modals/index.js +9 -0
- package/dist/components/previews/AudioPlayer.svelte +117 -0
- package/dist/components/previews/AudioPlayer.svelte.d.ts +22 -0
- package/dist/components/previews/ErrorPreview.svelte +12 -0
- package/dist/components/previews/ErrorPreview.svelte.d.ts +20 -0
- package/dist/components/previews/FilePreview.svelte +475 -0
- package/dist/components/previews/FilePreview.svelte.d.ts +31 -0
- package/dist/components/previews/FontPreview.svelte +82 -0
- package/dist/components/previews/FontPreview.svelte.d.ts +22 -0
- package/dist/components/previews/ImagePreview.svelte +551 -0
- package/dist/components/previews/ImagePreview.svelte.d.ts +27 -0
- package/dist/components/previews/TextPreview.svelte +92 -0
- package/dist/components/previews/TextPreview.svelte.d.ts +20 -0
- package/dist/components/previews/VideoPlayer.svelte +268 -0
- package/dist/components/previews/VideoPlayer.svelte.d.ts +22 -0
- package/dist/components/previews/WaveformVisualizer.svelte +240 -0
- package/dist/components/previews/WaveformVisualizer.svelte.d.ts +20 -0
- package/dist/components/previews/index.d.ts +8 -0
- package/dist/components/previews/index.js +8 -0
- package/dist/components/ui/ControlToolbar.svelte +342 -0
- package/dist/components/ui/ControlToolbar.svelte.d.ts +36 -0
- package/dist/components/ui/DragSelect.svelte +815 -0
- package/dist/components/ui/DragSelect.svelte.d.ts +31 -0
- package/dist/components/ui/DropdownMenu.svelte +83 -0
- package/dist/components/ui/DropdownMenu.svelte.d.ts +25 -0
- package/dist/components/ui/FileIcon.svelte +65 -0
- package/dist/components/ui/FileIcon.svelte.d.ts +25 -0
- package/dist/components/ui/FileMetadata.svelte +26 -0
- package/dist/components/ui/FileMetadata.svelte.d.ts +21 -0
- package/dist/components/ui/LoadingSkeleton.svelte +26 -0
- package/dist/components/ui/LoadingSkeleton.svelte.d.ts +22 -0
- package/dist/components/ui/SearchResults.svelte +37 -0
- package/dist/components/ui/SearchResults.svelte.d.ts +21 -0
- package/dist/components/ui/VirtualList.svelte +106 -0
- package/dist/components/ui/VirtualList.svelte.d.ts +45 -0
- package/dist/components/ui/index.d.ts +8 -0
- package/dist/components/ui/index.js +8 -0
- package/dist/config.d.ts +7 -0
- package/dist/config.js +14 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +11 -0
- package/dist/static/favicon.png +0 -0
- package/dist/static/files/audio/audio-file.mp3 +0 -0
- package/dist/static/files/document/-missing-file.txt +1 -0
- package/dist/static/files/document/HeliosDesign Website Project Brief Sample.pdf +0 -0
- package/dist/static/files/document/RFP-NEC_Website-Development_2021-August.pdf +0 -0
- package/dist/static/files/document/The World Before Calculus.pdf +0 -0
- package/dist/static/files/document/specs.txt +15 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Bold.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-BoldItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Book.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-BookItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Heavy.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-HeavyItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Light.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-LightItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Medium.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-MediumItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Semibold.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-SemiboldItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Thin.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-ThinItalic.otf +0 -0
- package/dist/static/files/font/Kimpo/Kimpo-Bold.otf +0 -0
- package/dist/static/files/font/Kimpo/Kimpo-Regular.otf +0 -0
- package/dist/static/files/image/image 1.jpg +0 -0
- package/dist/static/files/image/image 10.jpg +0 -0
- package/dist/static/files/image/image 11.jpg +0 -0
- package/dist/static/files/image/image 12.jpg +0 -0
- package/dist/static/files/image/image 13.jpg +0 -0
- package/dist/static/files/image/image 14.jpg +0 -0
- package/dist/static/files/image/image 15.jpg +0 -0
- package/dist/static/files/image/image 16.jpg +0 -0
- package/dist/static/files/image/image 17.jpg +0 -0
- package/dist/static/files/image/image 18.jpg +0 -0
- package/dist/static/files/image/image 19.jpg +0 -0
- package/dist/static/files/image/image 2.jpg +0 -0
- package/dist/static/files/image/image 20.jpg +0 -0
- package/dist/static/files/image/image 21.jpg +0 -0
- package/dist/static/files/image/image 22.jpg +0 -0
- package/dist/static/files/image/image 23.jpg +0 -0
- package/dist/static/files/image/image 24.jpg +0 -0
- package/dist/static/files/image/image 25.jpg +0 -0
- package/dist/static/files/image/image 26.jpg +0 -0
- package/dist/static/files/image/image 27.jpg +0 -0
- package/dist/static/files/image/image 28.jpg +0 -0
- package/dist/static/files/image/image 29.jpg +0 -0
- package/dist/static/files/image/image 3.jpg +0 -0
- package/dist/static/files/image/image 30.jpg +0 -0
- package/dist/static/files/image/image 31.jpg +0 -0
- package/dist/static/files/image/image 32.jpg +0 -0
- package/dist/static/files/image/image 33.jpg +0 -0
- package/dist/static/files/image/image 34.jpg +0 -0
- package/dist/static/files/image/image 35.jpg +0 -0
- package/dist/static/files/image/image 36.jpg +0 -0
- package/dist/static/files/image/image 37.jpg +0 -0
- package/dist/static/files/image/image 38.jpg +0 -0
- package/dist/static/files/image/image 39.jpg +0 -0
- package/dist/static/files/image/image 4.jpg +0 -0
- package/dist/static/files/image/image 40.jpg +0 -0
- package/dist/static/files/image/image 41.jpg +0 -0
- package/dist/static/files/image/image 42.jpg +0 -0
- package/dist/static/files/image/image 43.jpg +0 -0
- package/dist/static/files/image/image 44.jpg +0 -0
- package/dist/static/files/image/image 45.jpg +0 -0
- package/dist/static/files/image/image 46.jpg +0 -0
- package/dist/static/files/image/image 47.jpg +0 -0
- package/dist/static/files/image/image 48.jpg +0 -0
- package/dist/static/files/image/image 49.jpg +0 -0
- package/dist/static/files/image/image 5.jpg +0 -0
- package/dist/static/files/image/image 50.jpg +0 -0
- package/dist/static/files/image/image 51.jpg +0 -0
- package/dist/static/files/image/image 52.jpg +0 -0
- package/dist/static/files/image/image 53.jpg +0 -0
- package/dist/static/files/image/image 54.jpg +0 -0
- package/dist/static/files/image/image 55.jpg +0 -0
- package/dist/static/files/image/image 56.jpg +0 -0
- package/dist/static/files/image/image 57.jpg +0 -0
- package/dist/static/files/image/image 58.jpg +0 -0
- package/dist/static/files/image/image 59.jpg +0 -0
- package/dist/static/files/image/image 6.jpg +0 -0
- package/dist/static/files/image/image 60.jpg +0 -0
- package/dist/static/files/image/image 61.jpg +0 -0
- package/dist/static/files/image/image 62.jpg +0 -0
- package/dist/static/files/image/image 63.jpg +0 -0
- package/dist/static/files/image/image 64.jpg +0 -0
- package/dist/static/files/image/image 65.jpg +0 -0
- package/dist/static/files/image/image 66.jpg +0 -0
- package/dist/static/files/image/image 67.jpg +0 -0
- package/dist/static/files/image/image 68.jpg +0 -0
- package/dist/static/files/image/image 7.jpg +0 -0
- package/dist/static/files/image/image 8.jpg +0 -0
- package/dist/static/files/image/image 9.jpg +0 -0
- package/dist/static/files/svg/astronaut.svg +30 -0
- package/dist/static/files/svg/cook.svg +30 -0
- package/dist/static/files/svg/dj.svg +28 -0
- package/dist/static/files/svg/doctor.svg +29 -0
- package/dist/static/files/svg/farmer.svg +43 -0
- package/dist/static/files/svg/fire fighter.svg +40 -0
- package/dist/static/files/svg/plumber.svg +32 -0
- package/dist/static/files/svg/santa.svg +34 -0
- package/dist/static/files/svg/scientist.svg +31 -0
- package/dist/static/files/svg/student.svg +32 -0
- package/dist/static/files/thumbnail/image 1.jpg +0 -0
- package/dist/static/files/thumbnail/image 10.jpg +0 -0
- package/dist/static/files/thumbnail/image 11.jpg +0 -0
- package/dist/static/files/thumbnail/image 12.jpg +0 -0
- package/dist/static/files/thumbnail/image 13.jpg +0 -0
- package/dist/static/files/thumbnail/image 14.jpg +0 -0
- package/dist/static/files/thumbnail/image 15.jpg +0 -0
- package/dist/static/files/thumbnail/image 16.jpg +0 -0
- package/dist/static/files/thumbnail/image 17.jpg +0 -0
- package/dist/static/files/thumbnail/image 18.jpg +0 -0
- package/dist/static/files/thumbnail/image 19.jpg +0 -0
- package/dist/static/files/thumbnail/image 2.jpg +0 -0
- package/dist/static/files/thumbnail/image 20.jpg +0 -0
- package/dist/static/files/thumbnail/image 21.jpg +0 -0
- package/dist/static/files/thumbnail/image 22.jpg +0 -0
- package/dist/static/files/thumbnail/image 23.jpg +0 -0
- package/dist/static/files/thumbnail/image 24.jpg +0 -0
- package/dist/static/files/thumbnail/image 25.jpg +0 -0
- package/dist/static/files/thumbnail/image 26.jpg +0 -0
- package/dist/static/files/thumbnail/image 27.jpg +0 -0
- package/dist/static/files/thumbnail/image 28.jpg +0 -0
- package/dist/static/files/thumbnail/image 29.jpg +0 -0
- package/dist/static/files/thumbnail/image 3.jpg +0 -0
- package/dist/static/files/thumbnail/image 30.jpg +0 -0
- package/dist/static/files/thumbnail/image 31.jpg +0 -0
- package/dist/static/files/thumbnail/image 32.jpg +0 -0
- package/dist/static/files/thumbnail/image 33.jpg +0 -0
- package/dist/static/files/thumbnail/image 34.jpg +0 -0
- package/dist/static/files/thumbnail/image 35.jpg +0 -0
- package/dist/static/files/thumbnail/image 36.jpg +0 -0
- package/dist/static/files/thumbnail/image 37.jpg +0 -0
- package/dist/static/files/thumbnail/image 38.jpg +0 -0
- package/dist/static/files/thumbnail/image 39.jpg +0 -0
- package/dist/static/files/thumbnail/image 4.jpg +0 -0
- package/dist/static/files/thumbnail/image 40.jpg +0 -0
- package/dist/static/files/thumbnail/image 41.jpg +0 -0
- package/dist/static/files/thumbnail/image 42.jpg +0 -0
- package/dist/static/files/thumbnail/image 43.jpg +0 -0
- package/dist/static/files/thumbnail/image 44.jpg +0 -0
- package/dist/static/files/thumbnail/image 45.jpg +0 -0
- package/dist/static/files/thumbnail/image 46.jpg +0 -0
- package/dist/static/files/thumbnail/image 47.jpg +0 -0
- package/dist/static/files/thumbnail/image 48.jpg +0 -0
- package/dist/static/files/thumbnail/image 49.jpg +0 -0
- package/dist/static/files/thumbnail/image 5.jpg +0 -0
- package/dist/static/files/thumbnail/image 50.jpg +0 -0
- package/dist/static/files/thumbnail/image 51.jpg +0 -0
- package/dist/static/files/thumbnail/image 52.jpg +0 -0
- package/dist/static/files/thumbnail/image 53.jpg +0 -0
- package/dist/static/files/thumbnail/image 54.jpg +0 -0
- package/dist/static/files/thumbnail/image 55.jpg +0 -0
- package/dist/static/files/thumbnail/image 56.jpg +0 -0
- package/dist/static/files/thumbnail/image 57.jpg +0 -0
- package/dist/static/files/thumbnail/image 58.jpg +0 -0
- package/dist/static/files/thumbnail/image 59.jpg +0 -0
- package/dist/static/files/thumbnail/image 6.jpg +0 -0
- package/dist/static/files/thumbnail/image 60.jpg +0 -0
- package/dist/static/files/thumbnail/image 61.jpg +0 -0
- package/dist/static/files/thumbnail/image 62.jpg +0 -0
- package/dist/static/files/thumbnail/image 63.jpg +0 -0
- package/dist/static/files/thumbnail/image 64.jpg +0 -0
- package/dist/static/files/thumbnail/image 65.jpg +0 -0
- package/dist/static/files/thumbnail/image 66.jpg +0 -0
- package/dist/static/files/thumbnail/image 67.jpg +0 -0
- package/dist/static/files/thumbnail/image 68.jpg +0 -0
- package/dist/static/files/thumbnail/image 7.jpg +0 -0
- package/dist/static/files/thumbnail/image 8.jpg +0 -0
- package/dist/static/files/thumbnail/image 9.jpg +0 -0
- package/dist/static/files/video/video-file.mp4 +0 -0
- package/dist/static/files/video/video-file.png +0 -0
- package/dist/static/icons/audio.svg +7 -0
- package/dist/static/icons/check.svg +3 -0
- package/dist/static/icons/checked.svg +4 -0
- package/dist/static/icons/close.svg +11 -0
- package/dist/static/icons/document.svg +11 -0
- package/dist/static/icons/dots.svg +1 -0
- package/dist/static/icons/download.svg +1 -0
- package/dist/static/icons/empty-folder.svg +24 -0
- package/dist/static/icons/error.svg +5 -0
- package/dist/static/icons/file-upload.svg +1 -0
- package/dist/static/icons/folder-plus.svg +1 -0
- package/dist/static/icons/folder.svg +28 -0
- package/dist/static/icons/jump-to-folder.svg +1 -0
- package/dist/static/icons/move.svg +1 -0
- package/dist/static/icons/new-folder.svg +5 -0
- package/dist/static/icons/pdf.svg +6 -0
- package/dist/static/icons/player-pause.svg +1 -0
- package/dist/static/icons/player-play.svg +3 -0
- package/dist/static/icons/plus.svg +1 -0
- package/dist/static/icons/rename.svg +1 -0
- package/dist/static/icons/search.svg +1 -0
- package/dist/static/icons/trash.svg +1 -0
- package/dist/static/icons/unorganized-folder.svg +60 -0
- package/dist/stores/dragStore.d.ts +2 -0
- package/dist/stores/dragStore.js +2 -0
- package/dist/stores/fileStore.d.ts +36 -0
- package/dist/stores/fileStore.js +166 -0
- package/dist/stores/folderCountStore.d.ts +5 -0
- package/dist/stores/folderCountStore.js +49 -0
- package/dist/stores/index.d.ts +7 -0
- package/dist/stores/index.js +8 -0
- package/dist/stores/missingFilesStore.d.ts +3 -0
- package/dist/stores/missingFilesStore.js +14 -0
- package/dist/stores/navigationStore.d.ts +36 -0
- package/dist/stores/navigationStore.js +615 -0
- package/dist/stores/persistentSelectStore.d.ts +17 -0
- package/dist/stores/persistentSelectStore.js +170 -0
- package/dist/stores/searchStore.d.ts +1 -0
- package/dist/stores/searchStore.js +2 -0
- package/dist/stores/uploadApiStore.d.ts +13 -0
- package/dist/stores/uploadApiStore.js +36 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/pdf.d.ts +3 -0
- package/dist/types.d.ts +23 -0
- package/dist/types.js +1 -0
- package/dist/utils/apiConfig.d.ts +9 -0
- package/dist/utils/apiConfig.js +19 -0
- package/dist/utils/dateUtils.d.ts +2 -0
- package/dist/utils/dateUtils.js +38 -0
- package/dist/utils/fileOperations.d.ts +36 -0
- package/dist/utils/fileOperations.js +573 -0
- package/dist/utils/fileTypes.d.ts +17 -0
- package/dist/utils/fileTypes.js +110 -0
- package/dist/utils/fileUtils.d.ts +15 -0
- package/dist/utils/fileUtils.js +112 -0
- package/dist/utils/folderUtils.d.ts +4 -0
- package/dist/utils/folderUtils.js +26 -0
- package/dist/utils/imageTransform.d.ts +22 -0
- package/dist/utils/imageTransform.js +60 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/resolveFileUrl.d.ts +6 -0
- package/dist/utils/resolveFileUrl.js +21 -0
- package/dist/utils/userUploadsStorage.d.ts +27 -0
- package/dist/utils/userUploadsStorage.js +168 -0
- package/dist/utils/widgeticTusUpload.d.ts +18 -0
- package/dist/utils/widgeticTusUpload.js +131 -0
- package/dist/utils/widgeticUpload.d.ts +29 -0
- package/dist/utils/widgeticUpload.js +105 -0
- package/package.json +156 -0
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount, onDestroy, afterUpdate, tick } from 'svelte';
|
|
3
|
+
import { browser } from '$app/environment';
|
|
4
|
+
// import ThumbHashImage from './ThumbHashImage.svelte';
|
|
5
|
+
import { ThumbHashImage } from "@widgetic/design-system/components";
|
|
6
|
+
import { createEventDispatcher } from 'svelte';
|
|
7
|
+
import { tweened } from 'svelte/motion';
|
|
8
|
+
import { cubicOut } from 'svelte/easing';
|
|
9
|
+
import { buildTransformedUrl } from '../../utils/imageTransform';
|
|
10
|
+
|
|
11
|
+
export let hash: string | undefined = undefined;
|
|
12
|
+
export let src: string | undefined = undefined;
|
|
13
|
+
export let alt: string = '';
|
|
14
|
+
export let initiallyLoaded: boolean = false;
|
|
15
|
+
export let width: number | undefined = undefined;
|
|
16
|
+
export let height: number | undefined = undefined;
|
|
17
|
+
|
|
18
|
+
let imageLoaded = initiallyLoaded;
|
|
19
|
+
let isImageCached = false;
|
|
20
|
+
let showThumbhash = false;
|
|
21
|
+
let previousDimensions: { width: number; height: number } | null = null;
|
|
22
|
+
let isTransitioning = false;
|
|
23
|
+
let imageKey = 0; // Add a key to force component recreation when src changes
|
|
24
|
+
let pendingImageRequests: Set<string> = new Set(); // Track pending image requests
|
|
25
|
+
|
|
26
|
+
let containerWidth: string;
|
|
27
|
+
let containerHeight: string;
|
|
28
|
+
let imgElement: HTMLImageElement | null = null;
|
|
29
|
+
|
|
30
|
+
// Debug variables
|
|
31
|
+
let lastOpacityValue = 0;
|
|
32
|
+
let lastThumbhashOpacityValue = 1;
|
|
33
|
+
let transitionPhase = "initial";
|
|
34
|
+
let debugMode = false; // Set to true temporarily to diagnose issues
|
|
35
|
+
let domObserver: MutationObserver | null = null;
|
|
36
|
+
let elementStates: {timestamp: number, mainImage: string, thumbhash: string}[] = [];
|
|
37
|
+
|
|
38
|
+
// Calculate initial dimensions with proper scaling
|
|
39
|
+
$: {
|
|
40
|
+
if (width && height) {
|
|
41
|
+
const maxWidth = typeof window !== 'undefined' ? window.innerWidth - 100 : 1024; // 50px padding each side
|
|
42
|
+
const maxHeight = typeof window !== 'undefined' ? window.innerHeight - 200 : 768; // 100px padding top/bottom
|
|
43
|
+
|
|
44
|
+
const scaleWidth = maxWidth / width;
|
|
45
|
+
const scaleHeight = maxHeight / height;
|
|
46
|
+
const scale = Math.min(1, scaleWidth, scaleHeight);
|
|
47
|
+
|
|
48
|
+
containerWidth = `${Math.round(width * scale)}px`;
|
|
49
|
+
containerHeight = `${Math.round(height * scale)}px`;
|
|
50
|
+
} else {
|
|
51
|
+
containerWidth = "500px";
|
|
52
|
+
containerHeight = "400px";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Only use opacity transition for non-cached images or when switching between images
|
|
57
|
+
let containerOpacity = tweened(1, {
|
|
58
|
+
duration: 300,
|
|
59
|
+
easing: cubicOut
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Subscribe to opacity changes for debugging
|
|
63
|
+
$: if (debugMode && $containerOpacity !== lastOpacityValue) {
|
|
64
|
+
console.log(`[DEBUG] Container opacity changed: ${lastOpacityValue.toFixed(2)} -> ${$containerOpacity.toFixed(2)}, Phase: ${transitionPhase}`);
|
|
65
|
+
lastOpacityValue = $containerOpacity;
|
|
66
|
+
logElementStates();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const dispatch = createEventDispatcher();
|
|
70
|
+
|
|
71
|
+
// Function to clean up any pending image requests
|
|
72
|
+
function cleanupPreviousImage() {
|
|
73
|
+
if (debugMode) console.log(`[DEBUG] Cleaning up previous image, current key: ${imageKey}, new key will be: ${imageKey + 1}`);
|
|
74
|
+
|
|
75
|
+
// Increment the key to force component recreation
|
|
76
|
+
imageKey++;
|
|
77
|
+
|
|
78
|
+
// Reset state variables
|
|
79
|
+
imageLoaded = false;
|
|
80
|
+
isTransitioning = true;
|
|
81
|
+
|
|
82
|
+
// Clear any pending image requests
|
|
83
|
+
pendingImageRequests.clear();
|
|
84
|
+
|
|
85
|
+
// We'll handle container visibility in updateImageContainersVisibility
|
|
86
|
+
// to avoid race conditions
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function checkImageCache(src: string): boolean {
|
|
90
|
+
const img = new Image();
|
|
91
|
+
img.src = src;
|
|
92
|
+
const isCached = img.complete;
|
|
93
|
+
|
|
94
|
+
if (isCached && !imageLoaded) {
|
|
95
|
+
imageLoaded = true;
|
|
96
|
+
isImageCached = true;
|
|
97
|
+
if (debugMode) console.log(`[DEBUG] Image is cached: ${src}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return isCached;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function updateDimensions(imgWidth: number, imgHeight: number) {
|
|
104
|
+
// Use provided dimensions if available, otherwise use image dimensions
|
|
105
|
+
const actualWidth = width || imgWidth;
|
|
106
|
+
const actualHeight = height || imgHeight;
|
|
107
|
+
|
|
108
|
+
// Get viewport dimensions with some padding
|
|
109
|
+
const maxWidth = window.innerWidth - 100; // 50px padding each side
|
|
110
|
+
const maxHeight = window.innerHeight - 200; // 100px padding top/bottom
|
|
111
|
+
|
|
112
|
+
// Calculate scale to fit within bounds while maintaining aspect ratio
|
|
113
|
+
const scaleWidth = maxWidth / actualWidth;
|
|
114
|
+
const scaleHeight = maxHeight / actualHeight;
|
|
115
|
+
const scale = Math.min(1, scaleWidth, scaleHeight);
|
|
116
|
+
|
|
117
|
+
// Apply scale to dimensions
|
|
118
|
+
const finalWidth = Math.round(actualWidth * scale);
|
|
119
|
+
const finalHeight = Math.round(actualHeight * scale);
|
|
120
|
+
|
|
121
|
+
containerWidth = `${finalWidth}px`;
|
|
122
|
+
containerHeight = `${finalHeight}px`;
|
|
123
|
+
|
|
124
|
+
if (debugMode) console.log(`[DEBUG] Dimensions updated: ${finalWidth}x${finalHeight}`);
|
|
125
|
+
|
|
126
|
+
// Only dispatch if dimensions changed significantly
|
|
127
|
+
if (!previousDimensions ||
|
|
128
|
+
Math.abs(previousDimensions.width - finalWidth) > 50 ||
|
|
129
|
+
Math.abs(previousDimensions.height - finalHeight) > 50) {
|
|
130
|
+
previousDimensions = { width: finalWidth, height: finalHeight };
|
|
131
|
+
dispatch('dimensions', { width: finalWidth, height: finalHeight });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function handleImageLoad() {
|
|
136
|
+
if (imageLoaded || isTransitioning) {
|
|
137
|
+
if (debugMode) console.log(`[DEBUG] Image load handler skipped - already loaded: ${imageLoaded}, transitioning: ${isTransitioning}`);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (debugMode) console.log(`[DEBUG] Image loaded, starting transition for key: ${imageKey}`);
|
|
142
|
+
transitionPhase = "image_loaded";
|
|
143
|
+
isTransitioning = true;
|
|
144
|
+
logElementStates();
|
|
145
|
+
|
|
146
|
+
// Wait a bit for the dimensions to be applied
|
|
147
|
+
setTimeout(() => {
|
|
148
|
+
imageLoaded = true;
|
|
149
|
+
transitionPhase = "transition_complete";
|
|
150
|
+
if (debugMode) console.log(`[DEBUG] Image load complete for key: ${imageKey}`);
|
|
151
|
+
isTransitioning = false;
|
|
152
|
+
|
|
153
|
+
// Ensure this container is visible
|
|
154
|
+
updateImageContainersVisibility();
|
|
155
|
+
|
|
156
|
+
logElementStates();
|
|
157
|
+
|
|
158
|
+
// Set up a timer to log element states during the transition
|
|
159
|
+
const startTime = Date.now();
|
|
160
|
+
const logInterval = setInterval(() => {
|
|
161
|
+
logElementStates();
|
|
162
|
+
if (Date.now() - startTime > 1000) {
|
|
163
|
+
clearInterval(logInterval);
|
|
164
|
+
}
|
|
165
|
+
}, 50);
|
|
166
|
+
}, 50);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Function to log the current state of the thumbhash and main image elements
|
|
170
|
+
function logElementStates() {
|
|
171
|
+
if (!debugMode) return;
|
|
172
|
+
|
|
173
|
+
setTimeout(() => {
|
|
174
|
+
const container = document.querySelector('.image-preview-container');
|
|
175
|
+
if (container) {
|
|
176
|
+
// Log all image containers
|
|
177
|
+
const imageContainers = container.querySelectorAll('.image-container');
|
|
178
|
+
console.log(`[DEBUG] Found ${imageContainers.length} image containers`);
|
|
179
|
+
|
|
180
|
+
imageContainers.forEach((container, index) => {
|
|
181
|
+
const containerKey = container.getAttribute('data-image-key');
|
|
182
|
+
const containerSrc = container.getAttribute('data-src');
|
|
183
|
+
const htmlContainer = container as HTMLElement;
|
|
184
|
+
const display = getComputedStyle(htmlContainer).display;
|
|
185
|
+
const opacity = getComputedStyle(htmlContainer).opacity;
|
|
186
|
+
const visibility = getComputedStyle(htmlContainer).visibility;
|
|
187
|
+
|
|
188
|
+
console.log(`[DEBUG] Container ${index}: key=${containerKey}, src=${containerSrc}, display=${display}, opacity=${opacity}, visibility=${visibility}`);
|
|
189
|
+
|
|
190
|
+
// Log thumbhash and main image states
|
|
191
|
+
const thumbhashImg = container.querySelector('img[data-thumbhash]') as HTMLImageElement;
|
|
192
|
+
const mainImg = container.querySelector('img:not([data-thumbhash])') as HTMLImageElement;
|
|
193
|
+
|
|
194
|
+
const thumbhashState = thumbhashImg ?
|
|
195
|
+
`visible: ${!!(thumbhashImg.offsetWidth || thumbhashImg.offsetHeight)}, opacity: ${getComputedStyle(thumbhashImg).opacity}, display: ${getComputedStyle(thumbhashImg).display}` :
|
|
196
|
+
'not found';
|
|
197
|
+
|
|
198
|
+
const mainImgState = mainImg ?
|
|
199
|
+
`visible: ${!!(mainImg.offsetWidth || mainImg.offsetHeight)}, opacity: ${getComputedStyle(mainImg).opacity}, display: ${getComputedStyle(mainImg).display}` :
|
|
200
|
+
'not found';
|
|
201
|
+
|
|
202
|
+
console.log(`[DEBUG] Container ${index} images:
|
|
203
|
+
- Thumbhash: ${thumbhashState}
|
|
204
|
+
- Main Image: ${mainImgState}
|
|
205
|
+
`);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
elementStates.push({
|
|
209
|
+
timestamp: Date.now(),
|
|
210
|
+
thumbhash: 'See console for details',
|
|
211
|
+
mainImage: 'See console for details'
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}, 0);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Function to handle when the actual image is loaded inside ThumbHashImage
|
|
218
|
+
function handleActualImageLoad() {
|
|
219
|
+
// Find the actual image element inside the ThumbHashImage component
|
|
220
|
+
if (!width || !height) {
|
|
221
|
+
setTimeout(() => {
|
|
222
|
+
const container = document.querySelector('.image-preview-container');
|
|
223
|
+
if (container) {
|
|
224
|
+
// Find the current image container
|
|
225
|
+
const currentContainer = container.querySelector(`div[data-image-key="${imageKey}"]`);
|
|
226
|
+
if (currentContainer) {
|
|
227
|
+
// Find the main image inside this container
|
|
228
|
+
const img = currentContainer.querySelector('img:not([data-thumbhash])') as HTMLImageElement;
|
|
229
|
+
if (img && img.complete && img.naturalWidth > 0) {
|
|
230
|
+
updateDimensions(img.naturalWidth, img.naturalHeight);
|
|
231
|
+
imgElement = img;
|
|
232
|
+
if (debugMode) console.log(`[DEBUG] Found main image element, dimensions: ${img.naturalWidth}x${img.naturalHeight}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}, 100); // Give time for the DOM to update
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Function to observe DOM changes in the ThumbHashImage component
|
|
241
|
+
function setupDOMObserver() {
|
|
242
|
+
if (!debugMode || domObserver) return;
|
|
243
|
+
|
|
244
|
+
const container = document.querySelector('.image-preview-container');
|
|
245
|
+
if (container) {
|
|
246
|
+
domObserver = new MutationObserver((mutations) => {
|
|
247
|
+
for (const mutation of mutations) {
|
|
248
|
+
if (mutation.type === 'childList') {
|
|
249
|
+
if (mutation.addedNodes.length > 0) {
|
|
250
|
+
console.log(`[DEBUG] DOM nodes added:`, Array.from(mutation.addedNodes).map(node => node.nodeName));
|
|
251
|
+
}
|
|
252
|
+
if (mutation.removedNodes.length > 0) {
|
|
253
|
+
console.log(`[DEBUG] DOM nodes removed:`, Array.from(mutation.removedNodes).map(node => node.nodeName));
|
|
254
|
+
}
|
|
255
|
+
} else if (mutation.type === 'attributes') {
|
|
256
|
+
const target = mutation.target as HTMLElement;
|
|
257
|
+
console.log(`[DEBUG] Attribute changed: ${mutation.attributeName} on ${target.nodeName}${target.id ? '#'+target.id : ''}, new value: ${target.getAttribute(mutation.attributeName || '')}`);
|
|
258
|
+
}
|
|
259
|
+
logElementStates();
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
domObserver.observe(container, {
|
|
264
|
+
childList: true,
|
|
265
|
+
subtree: true,
|
|
266
|
+
attributes: true,
|
|
267
|
+
attributeFilter: ['style', 'class', 'data-thumbhash', 'data-image-key']
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
console.log(`[DEBUG] DOM observer set up`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Function to update the visibility of image containers based on the current key
|
|
275
|
+
function updateImageContainersVisibility() {
|
|
276
|
+
if (!browser) return;
|
|
277
|
+
|
|
278
|
+
const container = document.querySelector('.image-preview-container');
|
|
279
|
+
if (container) {
|
|
280
|
+
// Find all image containers
|
|
281
|
+
const imageContainers = container.querySelectorAll('div[data-image-key]');
|
|
282
|
+
|
|
283
|
+
if (debugMode) console.log(`[DEBUG] Updating visibility for ${imageContainers.length} containers, current key: ${imageKey}`);
|
|
284
|
+
|
|
285
|
+
// Update visibility based on the current key
|
|
286
|
+
imageContainers.forEach(container => {
|
|
287
|
+
const containerKey = container.getAttribute('data-image-key');
|
|
288
|
+
const htmlContainer = container as HTMLElement;
|
|
289
|
+
|
|
290
|
+
if (containerKey !== imageKey.toString()) {
|
|
291
|
+
// Hide stale containers
|
|
292
|
+
htmlContainer.style.opacity = '0';
|
|
293
|
+
htmlContainer.style.display = 'none';
|
|
294
|
+
htmlContainer.style.visibility = 'hidden';
|
|
295
|
+
htmlContainer.style.position = 'absolute';
|
|
296
|
+
htmlContainer.style.pointerEvents = 'none';
|
|
297
|
+
|
|
298
|
+
if (debugMode) console.log(`[DEBUG] Hiding stale container with key ${containerKey}`);
|
|
299
|
+
|
|
300
|
+
// Also hide any images inside this container
|
|
301
|
+
const images = htmlContainer.querySelectorAll('img');
|
|
302
|
+
images.forEach(img => {
|
|
303
|
+
const htmlImg = img as HTMLImageElement;
|
|
304
|
+
htmlImg.style.display = 'none';
|
|
305
|
+
htmlImg.style.opacity = '0';
|
|
306
|
+
});
|
|
307
|
+
} else {
|
|
308
|
+
// Show current container
|
|
309
|
+
htmlContainer.style.opacity = '1';
|
|
310
|
+
htmlContainer.style.display = 'flex';
|
|
311
|
+
htmlContainer.style.visibility = 'visible';
|
|
312
|
+
htmlContainer.style.position = 'absolute';
|
|
313
|
+
htmlContainer.style.pointerEvents = 'auto';
|
|
314
|
+
|
|
315
|
+
if (debugMode) console.log(`[DEBUG] Showing current container with key ${containerKey}`);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Function to force cleanup of old containers
|
|
322
|
+
async function forceCleanupOldContainers() {
|
|
323
|
+
if (!browser) return;
|
|
324
|
+
|
|
325
|
+
// Wait for the DOM to update
|
|
326
|
+
await tick();
|
|
327
|
+
|
|
328
|
+
const container = document.querySelector('.image-preview-container');
|
|
329
|
+
if (container) {
|
|
330
|
+
// Find all image containers
|
|
331
|
+
const allContainers = container.querySelectorAll('.image-container');
|
|
332
|
+
|
|
333
|
+
if (debugMode) console.log(`[DEBUG] Force cleanup: Found ${allContainers.length} containers, current key: ${imageKey}`);
|
|
334
|
+
|
|
335
|
+
// Remove any containers that don't match the current key
|
|
336
|
+
allContainers.forEach(container => {
|
|
337
|
+
const containerKey = container.getAttribute('data-image-key');
|
|
338
|
+
if (containerKey !== imageKey.toString()) {
|
|
339
|
+
if (debugMode) console.log(`[DEBUG] Force removing stale container with key ${containerKey}`);
|
|
340
|
+
container.parentNode?.removeChild(container);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
onMount(() => {
|
|
347
|
+
if (debugMode) console.log(`[DEBUG] Component mounted, hash: ${!!hash}, src: ${!!src}`);
|
|
348
|
+
|
|
349
|
+
// Set initial dimensions if provided
|
|
350
|
+
if (width && height) {
|
|
351
|
+
updateDimensions(width, height);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (src) {
|
|
355
|
+
isImageCached = checkImageCache(src);
|
|
356
|
+
if (isImageCached) {
|
|
357
|
+
transitionPhase = "cached_image";
|
|
358
|
+
if (debugMode) console.log(`[DEBUG] Image is cached: ${src}`);
|
|
359
|
+
|
|
360
|
+
imageLoaded = true;
|
|
361
|
+
isTransitioning = false;
|
|
362
|
+
|
|
363
|
+
// Try to get dimensions for cached images
|
|
364
|
+
handleActualImageLoad();
|
|
365
|
+
} else {
|
|
366
|
+
// For non-cached images, we'll wait for the load event
|
|
367
|
+
// But still try to get dimensions once mounted
|
|
368
|
+
handleActualImageLoad();
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Add a mutation observer to detect when the actual image is added to the DOM
|
|
373
|
+
if (!width || !height) {
|
|
374
|
+
const observer = new MutationObserver((mutations) => {
|
|
375
|
+
for (const mutation of mutations) {
|
|
376
|
+
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
|
|
377
|
+
handleActualImageLoad();
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
const container = document.querySelector('.image-preview-container');
|
|
383
|
+
if (container) {
|
|
384
|
+
observer.observe(container, { childList: true, subtree: true });
|
|
385
|
+
|
|
386
|
+
// Cleanup
|
|
387
|
+
return () => {
|
|
388
|
+
observer.disconnect();
|
|
389
|
+
if (domObserver) {
|
|
390
|
+
domObserver.disconnect();
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// Set up DOM observer for debugging
|
|
397
|
+
setupDOMObserver();
|
|
398
|
+
|
|
399
|
+
// Initial element state logging
|
|
400
|
+
setTimeout(logElementStates, 100);
|
|
401
|
+
|
|
402
|
+
return () => {
|
|
403
|
+
if (domObserver) {
|
|
404
|
+
domObserver.disconnect();
|
|
405
|
+
}
|
|
406
|
+
if (debugMode) console.log(`[DEBUG] Element state history:`, elementStates);
|
|
407
|
+
};
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
onDestroy(() => {
|
|
411
|
+
// Clean up any pending image requests
|
|
412
|
+
pendingImageRequests.clear();
|
|
413
|
+
|
|
414
|
+
if (debugMode) console.log(`[DEBUG] Component destroyed, cleaning up`);
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
// Reset state when src changes
|
|
418
|
+
$: if (src) {
|
|
419
|
+
transitionPhase = "src_changed";
|
|
420
|
+
if (debugMode) console.log(`[DEBUG] Source changed to: ${src}`);
|
|
421
|
+
|
|
422
|
+
// Clean up previous image before loading the new one
|
|
423
|
+
cleanupPreviousImage();
|
|
424
|
+
|
|
425
|
+
// Force cleanup of old containers
|
|
426
|
+
forceCleanupOldContainers();
|
|
427
|
+
|
|
428
|
+
// Check if the image is cached
|
|
429
|
+
isImageCached = checkImageCache(src);
|
|
430
|
+
|
|
431
|
+
if (isImageCached) {
|
|
432
|
+
// For cached images, show immediately without any transition
|
|
433
|
+
transitionPhase = "cached_image_switch";
|
|
434
|
+
if (debugMode) console.log(`[DEBUG] Cached image switch, showing immediately: ${src}`);
|
|
435
|
+
|
|
436
|
+
// Keep container visible (no fade out/in)
|
|
437
|
+
containerOpacity.set(1, { duration: 0 });
|
|
438
|
+
imageLoaded = true;
|
|
439
|
+
isTransitioning = false;
|
|
440
|
+
|
|
441
|
+
// Update dimensions with provided values
|
|
442
|
+
if (width && height) {
|
|
443
|
+
updateDimensions(width, height);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// Try to get dimensions for cached images
|
|
447
|
+
handleActualImageLoad();
|
|
448
|
+
} else {
|
|
449
|
+
// For non-cached images, use the fade transition
|
|
450
|
+
// Hide the container while we switch images
|
|
451
|
+
containerOpacity.set(0, { duration: 0 });
|
|
452
|
+
imageLoaded = false;
|
|
453
|
+
isTransitioning = true;
|
|
454
|
+
|
|
455
|
+
// Update dimensions with provided values
|
|
456
|
+
if (width && height) {
|
|
457
|
+
updateDimensions(width, height);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// Short delay to ensure the DOM has updated
|
|
461
|
+
setTimeout(() => {
|
|
462
|
+
// Show the container again
|
|
463
|
+
containerOpacity.set(1).then(() => {
|
|
464
|
+
transitionPhase = "src_changed_complete";
|
|
465
|
+
if (debugMode) console.log(`[DEBUG] Source change transition complete`);
|
|
466
|
+
isTransitioning = false;
|
|
467
|
+
logElementStates();
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
// Try to get dimensions
|
|
471
|
+
handleActualImageLoad();
|
|
472
|
+
}, 50);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// Update visibility of image containers after a short delay
|
|
476
|
+
// to ensure the DOM has been updated with the new container
|
|
477
|
+
setTimeout(updateImageContainersVisibility, 10);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// Update visibility when the key changes
|
|
481
|
+
$: {
|
|
482
|
+
imageKey;
|
|
483
|
+
setTimeout(updateImageContainersVisibility, 0);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// Also update visibility after the component updates
|
|
487
|
+
afterUpdate(async () => {
|
|
488
|
+
updateImageContainersVisibility();
|
|
489
|
+
await forceCleanupOldContainers();
|
|
490
|
+
});
|
|
491
|
+
</script>
|
|
492
|
+
|
|
493
|
+
<div class="image-preview-container w-full flex items-center justify-center px-4 rounded-large overflow-hidden">
|
|
494
|
+
<div
|
|
495
|
+
class="image-parent-container relative flex items-center justify-center"
|
|
496
|
+
style="width: {containerWidth}; height: {containerHeight};"
|
|
497
|
+
>
|
|
498
|
+
{#if browser && src}
|
|
499
|
+
{#each [{ src: buildTransformedUrl(src, { width: 1920, fit: 'scale-down', quality: 85 }), key: imageKey }] as item (item.key)}
|
|
500
|
+
<div
|
|
501
|
+
class="image-container absolute inset-0 flex items-center justify-center"
|
|
502
|
+
style="opacity: {$containerOpacity};"
|
|
503
|
+
data-image-key={imageKey}
|
|
504
|
+
data-src={src}
|
|
505
|
+
>
|
|
506
|
+
<!-- Use ThumbHashImage with a wrapper div that has the data attribute -->
|
|
507
|
+
<ThumbHashImage
|
|
508
|
+
src={item.src}
|
|
509
|
+
{alt}
|
|
510
|
+
thumbhash={hash || ''}
|
|
511
|
+
class_="w-full h-full object-cover thumbhash-image"
|
|
512
|
+
roundedCorners="rounded-large"
|
|
513
|
+
style="--thumb-fade: 600ms; --hide-main-image: 0;"
|
|
514
|
+
onLoad={handleImageLoad}
|
|
515
|
+
/>
|
|
516
|
+
</div>
|
|
517
|
+
{/each}
|
|
518
|
+
{/if}
|
|
519
|
+
</div>
|
|
520
|
+
</div>
|
|
521
|
+
|
|
522
|
+
<style>
|
|
523
|
+
/* Prevent dragging on images and interactive elements */
|
|
524
|
+
:global(img),
|
|
525
|
+
:global(button),
|
|
526
|
+
:global(.no-drag) {
|
|
527
|
+
-webkit-user-select: none !important;
|
|
528
|
+
-moz-user-select: none !important;
|
|
529
|
+
-ms-user-select: none !important;
|
|
530
|
+
user-select: none !important;
|
|
531
|
+
-webkit-user-drag: none !important;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/* Fix z-index issues with ThumbHashImage */
|
|
535
|
+
:global(.thumbhash-image img[data-thumbhash]) {
|
|
536
|
+
z-index: 5 !important;
|
|
537
|
+
transition: opacity 600ms ease-out !important;
|
|
538
|
+
will-change: opacity !important;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
:global(.thumbhash-image img:not([data-thumbhash])) {
|
|
542
|
+
z-index: 10 !important;
|
|
543
|
+
will-change: opacity !important;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/* Hide any stale images - we can't use string interpolation in CSS selectors,
|
|
547
|
+
so we'll handle this in JavaScript instead */
|
|
548
|
+
:global(div[data-image-key] img) {
|
|
549
|
+
transition: opacity 300ms ease-out !important;
|
|
550
|
+
}
|
|
551
|
+
</style>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
2
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
+
$$bindings?: Bindings;
|
|
4
|
+
} & Exports;
|
|
5
|
+
(internal: unknown, props: Props & {
|
|
6
|
+
$$events?: Events;
|
|
7
|
+
$$slots?: Slots;
|
|
8
|
+
}): Exports & {
|
|
9
|
+
$set?: any;
|
|
10
|
+
$on?: any;
|
|
11
|
+
};
|
|
12
|
+
z_$$bindings?: Bindings;
|
|
13
|
+
}
|
|
14
|
+
declare const ImagePreview: $$__sveltets_2_IsomorphicComponent<{
|
|
15
|
+
hash?: string | undefined;
|
|
16
|
+
src?: string | undefined;
|
|
17
|
+
alt?: string;
|
|
18
|
+
initiallyLoaded?: boolean;
|
|
19
|
+
width?: number | undefined;
|
|
20
|
+
height?: number | undefined;
|
|
21
|
+
}, {
|
|
22
|
+
dimensions: CustomEvent<any>;
|
|
23
|
+
} & {
|
|
24
|
+
[evt: string]: CustomEvent<any>;
|
|
25
|
+
}, {}, {}, string>;
|
|
26
|
+
type ImagePreview = InstanceType<typeof ImagePreview>;
|
|
27
|
+
export default ImagePreview;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// Svelte imports
|
|
3
|
+
import { onMount } from 'svelte';
|
|
4
|
+
|
|
5
|
+
// Imports from Design System
|
|
6
|
+
import { WScrollArea } from '@widgetic/design-system/components';
|
|
7
|
+
|
|
8
|
+
export let src: string;
|
|
9
|
+
|
|
10
|
+
// Consts
|
|
11
|
+
const scrolledAreaMaxHeight = 600;
|
|
12
|
+
|
|
13
|
+
let content: string = '';
|
|
14
|
+
let isLoading = true;
|
|
15
|
+
let error: string | null = null;
|
|
16
|
+
let formattedContent: string = '';
|
|
17
|
+
let contentElement: HTMLPreElement;
|
|
18
|
+
let contentHeight = 0;
|
|
19
|
+
|
|
20
|
+
function formatContent(text: string, fileType: string): string {
|
|
21
|
+
try {
|
|
22
|
+
switch(fileType.toLowerCase()) {
|
|
23
|
+
case 'json':
|
|
24
|
+
return JSON.stringify(JSON.parse(text), null, 2);
|
|
25
|
+
case 'xml':
|
|
26
|
+
// Basic XML formatting - in a real app you might want to use a proper XML formatter
|
|
27
|
+
return text.replace(/></g, '>\n<')
|
|
28
|
+
.replace(/(<[^>]+>)/g, '\n$1\n')
|
|
29
|
+
.split('\n')
|
|
30
|
+
.filter(line => line.trim())
|
|
31
|
+
.join('\n');
|
|
32
|
+
case 'csv':
|
|
33
|
+
// Basic CSV formatting - in a real app you might want to use a proper CSV parser
|
|
34
|
+
return text.split('\n')
|
|
35
|
+
.map(line => line.trim())
|
|
36
|
+
.filter(line => line)
|
|
37
|
+
.join('\n');
|
|
38
|
+
default:
|
|
39
|
+
return text;
|
|
40
|
+
}
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.warn('Error formatting content, falling back to plain text:', err);
|
|
43
|
+
return text;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
onMount(async () => {
|
|
48
|
+
try {
|
|
49
|
+
const response = await fetch(src);
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
throw new Error(`Failed to load text file: ${response.statusText}`);
|
|
52
|
+
}
|
|
53
|
+
content = await response.text();
|
|
54
|
+
|
|
55
|
+
// Get file extension
|
|
56
|
+
const fileType = src.split('.').pop() || '';
|
|
57
|
+
formattedContent = formatContent(content, fileType);
|
|
58
|
+
|
|
59
|
+
// After content is loaded, check its height
|
|
60
|
+
if (contentElement) {
|
|
61
|
+
contentHeight = contentElement.scrollHeight;
|
|
62
|
+
}
|
|
63
|
+
} catch (err) {
|
|
64
|
+
error = err instanceof Error ? err.message : 'Failed to load text file';
|
|
65
|
+
console.error('Error loading text file:', err);
|
|
66
|
+
} finally {
|
|
67
|
+
isLoading = false;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
<div class="text-preview-container w-full h-full px-4 widgetic-colors" style="max-height: {scrolledAreaMaxHeight}px">
|
|
73
|
+
{#if isLoading}
|
|
74
|
+
<div class="text-[hsl(var(--grey5))] p-6">Loading...</div>
|
|
75
|
+
{:else if error}
|
|
76
|
+
<div class="text-[hsl(var(--error))] p-6">{error}</div>
|
|
77
|
+
{:else}
|
|
78
|
+
<WScrollArea class="text-pre-scroll-area !h-[500px]" viewPortClass="rounded-large widgetic-radius bg-[hsl(var(--grey1))]" scrollOutside={true} type="always">
|
|
79
|
+
<pre bind:this={contentElement}
|
|
80
|
+
class="text-pre-container w-full p-4
|
|
81
|
+
subtext font-mono whitespace-pre-wrap break-words
|
|
82
|
+
text-[hsl(var(--grey7))]"
|
|
83
|
+
>{formattedContent}</pre>
|
|
84
|
+
</WScrollArea>
|
|
85
|
+
{/if}
|
|
86
|
+
</div>
|
|
87
|
+
|
|
88
|
+
<style>
|
|
89
|
+
pre {
|
|
90
|
+
margin: 0;
|
|
91
|
+
}
|
|
92
|
+
</style>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
2
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
+
$$bindings?: Bindings;
|
|
4
|
+
} & Exports;
|
|
5
|
+
(internal: unknown, props: Props & {
|
|
6
|
+
$$events?: Events;
|
|
7
|
+
$$slots?: Slots;
|
|
8
|
+
}): Exports & {
|
|
9
|
+
$set?: any;
|
|
10
|
+
$on?: any;
|
|
11
|
+
};
|
|
12
|
+
z_$$bindings?: Bindings;
|
|
13
|
+
}
|
|
14
|
+
declare const TextPreview: $$__sveltets_2_IsomorphicComponent<{
|
|
15
|
+
src: string;
|
|
16
|
+
}, {
|
|
17
|
+
[evt: string]: CustomEvent<any>;
|
|
18
|
+
}, {}, {}, string>;
|
|
19
|
+
type TextPreview = InstanceType<typeof TextPreview>;
|
|
20
|
+
export default TextPreview;
|