@widgetic/file-browser 0.5.35 → 0.5.37
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 +1 -0
- package/dist/components/FolderTree.svelte +46 -97
- package/dist/components/FolderTree.svelte.d.ts +5 -1
- package/dist/components/core/Dropzone.svelte +127 -0
- package/dist/components/core/Dropzone.svelte.d.ts +15 -0
- package/dist/components/core/FileBrowser.css +11 -79
- package/dist/components/core/FileBrowser.svelte +277 -149
- package/dist/components/core/FileBrowser.svelte.d.ts +0 -1
- package/dist/components/core/FileUploader.svelte +204 -418
- package/dist/components/core/FileUploader.svelte.d.ts +1 -0
- package/dist/components/core/Header.svelte +51 -68
- package/dist/components/core/Header.svelte.d.ts +1 -0
- package/dist/components/core/RecentFiles.svelte +135 -562
- package/dist/components/core/RecentFiles.svelte.d.ts +2 -4
- package/dist/components/core/UploadPanel.svelte +169 -0
- package/dist/components/core/UploadPanel.svelte.d.ts +40 -0
- package/dist/components/core/UploadRow.svelte +90 -0
- package/dist/components/core/UploadRow.svelte.d.ts +21 -0
- package/dist/components/core/UploadStatus.svelte +34 -128
- package/dist/components/core/UploadStatus.svelte.d.ts +0 -1
- package/dist/components/core/UploadStatusList.svelte +61 -77
- package/dist/components/items/FileItem.svelte +190 -532
- package/dist/components/items/FileItem.svelte.d.ts +1 -1
- package/dist/components/items/FolderItem.svelte +46 -36
- package/dist/components/items/FolderItem.svelte.d.ts +1 -1
- package/dist/components/modals/MoveDialog.svelte +142 -281
- package/dist/components/modals/NewFolderButton.svelte +13 -14
- package/dist/components/modals/SearchModal.svelte +112 -264
- package/dist/components/modals/SearchModal.svelte.d.ts +0 -1
- package/dist/components/modals/SelectedFilesModal.svelte +91 -167
- package/dist/components/previews/AudioPlayer.svelte +75 -58
- package/dist/components/previews/ErrorPreview.svelte +9 -6
- package/dist/components/previews/FilePreview.svelte +173 -53
- package/dist/components/previews/FontPreview.svelte +37 -54
- package/dist/components/previews/ImagePreview.svelte +9 -2
- package/dist/components/previews/ImagePreview.svelte.d.ts +1 -0
- package/dist/components/previews/PreviewHeaderBar.svelte +70 -0
- package/dist/components/previews/PreviewHeaderBar.svelte.d.ts +32 -0
- package/dist/components/previews/TextPreview.svelte +32 -40
- package/dist/components/previews/VideoPlayer.svelte +124 -149
- package/dist/components/previews/WaveformVisualizer.svelte +42 -222
- package/dist/components/previews/WaveformVisualizer.svelte.d.ts +1 -1
- package/dist/components/ui/ControlToolbar.svelte +113 -288
- package/dist/components/ui/ControlToolbar.svelte.d.ts +2 -3
- package/dist/components/ui/DragSelect.svelte +41 -248
- package/dist/components/ui/DropdownMenu.svelte +56 -55
- package/dist/components/ui/DropdownMenu.svelte.d.ts +1 -1
- package/dist/components/ui/FileIcon.svelte +168 -51
- package/dist/components/ui/FileIcon.svelte.d.ts +13 -20
- package/dist/components/ui/FileMetadata.svelte +20 -9
- package/dist/components/ui/LoadingSkeleton.svelte +5 -20
- package/dist/components/ui/SearchResults.svelte +50 -26
- package/dist/components/ui/SearchResults.svelte.d.ts +4 -0
- package/dist/components/ui/SelectedBadge.svelte +25 -0
- package/dist/components/ui/SelectedBadge.svelte.d.ts +9 -0
- package/dist/components/ui/TileSkeleton.svelte +15 -0
- package/dist/components/ui/TileSkeleton.svelte.d.ts +18 -0
- package/dist/components/ui/VirtualList.svelte +3 -0
- package/dist/components/ui/index.d.ts +1 -0
- package/dist/components/ui/index.js +1 -0
- package/dist/i18n/messages.d.ts +38 -25
- package/dist/i18n/messages.js +39 -26
- package/dist/utils/gridLayout.d.ts +2 -0
- package/dist/utils/gridLayout.js +10 -0
- package/package.json +3 -4
|
@@ -10,12 +10,20 @@
|
|
|
10
10
|
const dispatch = createEventDispatcher();
|
|
11
11
|
|
|
12
12
|
// Design System Components imports
|
|
13
|
-
import { BaseModal, PDFViewer } from '@widgetic/design-system/components';
|
|
13
|
+
import { BaseModal, PDFViewer, EmptyState } from '@widgetic/design-system/components';
|
|
14
14
|
import { useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
15
|
+
import { IconFileUnknown, IconLoader2 } from '@widgetic/design-system/icons';
|
|
15
16
|
|
|
16
17
|
// Local Components imports
|
|
17
|
-
import {
|
|
18
|
-
|
|
18
|
+
import {
|
|
19
|
+
ImagePreview,
|
|
20
|
+
VideoPlayer,
|
|
21
|
+
AudioPlayer,
|
|
22
|
+
ErrorPreview,
|
|
23
|
+
FontPreview,
|
|
24
|
+
TextPreview
|
|
25
|
+
} from './';
|
|
26
|
+
import PreviewHeaderBar from './PreviewHeaderBar.svelte';
|
|
19
27
|
|
|
20
28
|
// Types
|
|
21
29
|
import type { FileSystemItem } from '../../types';
|
|
@@ -30,8 +38,9 @@
|
|
|
30
38
|
import { validSelections } from '../../stores/persistentSelectStore';
|
|
31
39
|
import { type FileFilterType, isPreviewableTextFile } from '../../utils/fileTypes';
|
|
32
40
|
import { useI18n } from '../../i18n';
|
|
41
|
+
import { formatFileSize } from '../../utils/fileUtils';
|
|
33
42
|
|
|
34
|
-
const { t } = useI18n();
|
|
43
|
+
const { t, locale } = useI18n();
|
|
35
44
|
// The reading direction the File Browser is laid out in: the arrow keys follow it.
|
|
36
45
|
const textDirection = useTextDirection();
|
|
37
46
|
|
|
@@ -42,12 +51,13 @@
|
|
|
42
51
|
export let currentFiles: FileSystemItem[] = [];
|
|
43
52
|
export let currentFilter: FileFilterType = 'all';
|
|
44
53
|
export let target: string = 'file-preview-modal'; // target for Portal
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
const
|
|
54
|
+
/** Horizontal inset inside the dialog shell (Figma pad 24 each side + the 1px border of the card on each side). */
|
|
55
|
+
const DIALOG_HORIZONTAL_PAD = 50;
|
|
56
|
+
/** Header (title + meta) + gap to body (Figma 36 + 16). */
|
|
57
|
+
const HEADER_BLOCK = 52;
|
|
58
|
+
/** Shell vertical padding (p-6 top + bottom, and the 1px border of the card on each side). */
|
|
59
|
+
const MODAL_VERTICAL_PAD = 50;
|
|
60
|
+
const TOTAL_VERTICAL_SPACE = MODAL_VERTICAL_PAD + HEADER_BLOCK;
|
|
51
61
|
|
|
52
62
|
// STATE VARS
|
|
53
63
|
let showLogs = false;
|
|
@@ -88,23 +98,29 @@
|
|
|
88
98
|
|
|
89
99
|
// Determine modal dimensions based on file type
|
|
90
100
|
switch (fileType) {
|
|
101
|
+
case 'error':
|
|
102
|
+
// The card of a file that cannot be shown (Figma "Preview Dialog / Error")
|
|
103
|
+
return {
|
|
104
|
+
width: `${Math.min(410, maxWidth)}px`,
|
|
105
|
+
height: '256px'
|
|
106
|
+
};
|
|
91
107
|
case 'audio':
|
|
92
108
|
return {
|
|
93
|
-
width:
|
|
94
|
-
height: '
|
|
109
|
+
width: `${Math.min(410, maxWidth)}px`,
|
|
110
|
+
height: '236px'
|
|
95
111
|
};
|
|
96
112
|
case 'image':
|
|
97
113
|
case 'video':
|
|
98
|
-
//
|
|
114
|
+
// The size of the loading card (Figma "Preview Dialog / Loading"), then it moves to the size of the picture.
|
|
99
115
|
return {
|
|
100
|
-
width:
|
|
101
|
-
height: '
|
|
116
|
+
width: `${Math.min(410, maxWidth)}px`,
|
|
117
|
+
height: '256px',
|
|
102
118
|
dynamicHeight: true
|
|
103
119
|
};
|
|
104
120
|
case 'font':
|
|
105
121
|
return {
|
|
106
|
-
width:
|
|
107
|
-
height: `${
|
|
122
|
+
width: `${Math.min(600, maxWidth)}px`,
|
|
123
|
+
height: `${336}px`
|
|
108
124
|
};
|
|
109
125
|
case 'document': {
|
|
110
126
|
// For PDFs, use larger dimensions similar to images
|
|
@@ -120,18 +136,18 @@
|
|
|
120
136
|
// For other document types (txt, md, csv, etc.), use smaller dimensions
|
|
121
137
|
return {
|
|
122
138
|
width: `${Math.min(566, maxWidth)}px`,
|
|
123
|
-
height: `${
|
|
139
|
+
height: `${460}px`
|
|
124
140
|
};
|
|
125
141
|
}
|
|
126
142
|
case 'svg':
|
|
127
143
|
return {
|
|
128
|
-
width:
|
|
129
|
-
height: `${
|
|
144
|
+
width: `${Math.min(566, maxWidth)}px`,
|
|
145
|
+
height: `${460}px`
|
|
130
146
|
};
|
|
131
147
|
default:
|
|
132
148
|
return {
|
|
133
|
-
width:
|
|
134
|
-
height: `${
|
|
149
|
+
width: `${Math.min(566, maxWidth)}px`,
|
|
150
|
+
height: `${300}px`
|
|
135
151
|
};
|
|
136
152
|
}
|
|
137
153
|
}
|
|
@@ -150,8 +166,7 @@
|
|
|
150
166
|
const styles = getComputedStyle(element);
|
|
151
167
|
margin = parseInt(styles.getPropertyValue('--app-margin').trim()) || margin;
|
|
152
168
|
}
|
|
153
|
-
|
|
154
|
-
const sideInset = 32;
|
|
169
|
+
const sideInset = DIALOG_HORIZONTAL_PAD;
|
|
155
170
|
const maxWidth = Math.max(100, frame.width - 2 * margin - sideInset);
|
|
156
171
|
const maxHeight = Math.max(100, frame.height - TOTAL_VERTICAL_SPACE - 48);
|
|
157
172
|
const aspect = videoWidth / videoHeight;
|
|
@@ -176,11 +191,16 @@
|
|
|
176
191
|
let fittedImage: { width: string; height: string } | null = null;
|
|
177
192
|
let fittedImageForId = '';
|
|
178
193
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
194
|
+
// A file the library lost, one without an address, or a picture that does not load: the card says so (Figma "Preview Dialog / Error")
|
|
195
|
+
let imageFailed = false;
|
|
196
|
+
$: showsErrorState = !hasValidUrl || $missingFiles.has(file.id) || imageFailed;
|
|
197
|
+
$: modalDimensions = showsErrorState
|
|
198
|
+
? getModalDimensions('error')
|
|
199
|
+
: fileType === 'video' && fittedVideo && fittedVideoForId === file.id
|
|
200
|
+
? fittedVideo
|
|
201
|
+
: fileType === 'image' && fittedImage && fittedImageForId === file.id
|
|
202
|
+
? fittedImage
|
|
203
|
+
: getModalDimensions(fileType);
|
|
184
204
|
let imageRevealForId = '';
|
|
185
205
|
let imageRevealTimer: ReturnType<typeof setTimeout> | undefined;
|
|
186
206
|
|
|
@@ -195,8 +215,9 @@
|
|
|
195
215
|
const maxWidth = Math.max(160, frame.width - 2 * margin);
|
|
196
216
|
const maxHeight = Math.max(120, frame.height - TOTAL_VERTICAL_SPACE - 48);
|
|
197
217
|
const scale = Math.min(1, maxWidth / width, maxHeight / height);
|
|
218
|
+
const pictureWidth = Math.max(100, Math.round(width * scale));
|
|
198
219
|
const next = {
|
|
199
|
-
width: `${
|
|
220
|
+
width: `${pictureWidth + DIALOG_HORIZONTAL_PAD}px`,
|
|
200
221
|
height: `${Math.max(100, Math.round(height * scale) + TOTAL_VERTICAL_SPACE)}px`
|
|
201
222
|
};
|
|
202
223
|
const id = file.id;
|
|
@@ -351,6 +372,13 @@
|
|
|
351
372
|
// Add reactive statement to check if current file is missing
|
|
352
373
|
$: isMissing = $missingFiles.has(file.id);
|
|
353
374
|
|
|
375
|
+
// A new file starts without a failure
|
|
376
|
+
let failureCheckedFileId = '';
|
|
377
|
+
$: if (file.id !== failureCheckedFileId) {
|
|
378
|
+
failureCheckedFileId = file.id;
|
|
379
|
+
imageFailed = false;
|
|
380
|
+
}
|
|
381
|
+
|
|
354
382
|
let imageLoaded = false;
|
|
355
383
|
|
|
356
384
|
// Check if image is already in browser cache
|
|
@@ -378,14 +406,77 @@
|
|
|
378
406
|
}
|
|
379
407
|
|
|
380
408
|
let pdfLoadError: string | null = null;
|
|
409
|
+
let mediaDuration: number | undefined;
|
|
410
|
+
|
|
411
|
+
function formatDuration(seconds: number): string {
|
|
412
|
+
if (!Number.isFinite(seconds) || seconds <= 0) return '0:00';
|
|
413
|
+
const minutes = Math.floor(seconds / 60);
|
|
414
|
+
const remainingSeconds = Math.floor(seconds % 60);
|
|
415
|
+
return `${minutes}:${remainingSeconds.toString().padStart(2, '0')}`;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function fileExtensionLabel(name: string): string {
|
|
419
|
+
const dot = name.lastIndexOf('.');
|
|
420
|
+
if (dot < 0 || dot === name.length - 1) return '';
|
|
421
|
+
return name.slice(dot + 1).toUpperCase();
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function buildPreviewMeta(
|
|
425
|
+
item: FileSystemItem,
|
|
426
|
+
kind: string,
|
|
427
|
+
durationSeconds: number | undefined
|
|
428
|
+
): string {
|
|
429
|
+
const sep = $t('preview.metaSeparator');
|
|
430
|
+
const parts: string[] = [];
|
|
431
|
+
const ext = fileExtensionLabel(item.name);
|
|
432
|
+
if (ext) parts.push(ext);
|
|
433
|
+
if (kind === 'image' && item.width && item.height) {
|
|
434
|
+
parts.push($t('preview.dimensions', { width: item.width, height: item.height }));
|
|
435
|
+
}
|
|
436
|
+
if ((kind === 'video' || kind === 'audio') && durationSeconds && durationSeconds > 0) {
|
|
437
|
+
parts.push(formatDuration(durationSeconds));
|
|
438
|
+
}
|
|
439
|
+
if (item.size) {
|
|
440
|
+
parts.push(formatFileSize(item.size, $t, $locale));
|
|
441
|
+
}
|
|
442
|
+
return parts.join(sep);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
$: previewMetaLine = buildPreviewMeta(file, fileType, mediaDuration);
|
|
446
|
+
$: showPreviewMeta =
|
|
447
|
+
hasValidUrl &&
|
|
448
|
+
!$missingFiles.has(file.id) &&
|
|
449
|
+
!imageFailed &&
|
|
450
|
+
!pdfLoadError &&
|
|
451
|
+
!(fileType === 'image' && imageRevealForId !== file.id);
|
|
452
|
+
|
|
453
|
+
$: canGoPrevious =
|
|
454
|
+
allowSelecting && findNextAvailableFile(currentIndex, 'prev') !== null;
|
|
455
|
+
$: canGoNext = allowSelecting && findNextAvailableFile(currentIndex, 'next') !== null;
|
|
456
|
+
|
|
457
|
+
function goPreviousFile() {
|
|
458
|
+
const prevFile = findNextAvailableFile(currentIndex, 'prev');
|
|
459
|
+
if (prevFile) dispatch('navigate', prevFile);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function goNextFile() {
|
|
463
|
+
const nextFile = findNextAvailableFile(currentIndex, 'next');
|
|
464
|
+
if (nextFile) dispatch('navigate', nextFile);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
$: if (videoElement?.duration) {
|
|
468
|
+
mediaDuration = videoElement.duration;
|
|
469
|
+
} else if (audioElement?.duration) {
|
|
470
|
+
mediaDuration = audioElement.duration;
|
|
471
|
+
}
|
|
381
472
|
</script>
|
|
382
473
|
|
|
383
474
|
<!-- Preview Modal Container -->
|
|
475
|
+
<!-- A bare modal: the preview draws its own top row (title, meta, picker actions and the close button) and padding -->
|
|
384
476
|
<BaseModal
|
|
385
477
|
class="file-preview-modal"
|
|
386
478
|
bind:open
|
|
387
|
-
|
|
388
|
-
closeLabel={$t('dialog.close')}
|
|
479
|
+
bare
|
|
389
480
|
width={modalDimensions.width}
|
|
390
481
|
height={modalDimensions.height}
|
|
391
482
|
animateSize={fileType === 'image' || fileType === 'video'}
|
|
@@ -424,8 +515,23 @@
|
|
|
424
515
|
on:spaceKey={() => dispatch('select', file)}
|
|
425
516
|
>
|
|
426
517
|
<!-- Preview Content Area -->
|
|
427
|
-
<div bind:this={measureFrom}
|
|
428
|
-
|
|
518
|
+
<div bind:this={measureFrom} class="file-preview-body flex w-full flex-col p-6">
|
|
519
|
+
<PreviewHeaderBar
|
|
520
|
+
title={file.name}
|
|
521
|
+
closeLabel={$t('dialog.close')}
|
|
522
|
+
on:close={handleClose}
|
|
523
|
+
meta={previewMetaLine}
|
|
524
|
+
showMeta={showPreviewMeta}
|
|
525
|
+
{allowSelecting}
|
|
526
|
+
{isSelected}
|
|
527
|
+
{canGoPrevious}
|
|
528
|
+
{canGoNext}
|
|
529
|
+
on:previous={goPreviousFile}
|
|
530
|
+
on:next={goNextFile}
|
|
531
|
+
on:select={() => dispatch('select', file)}
|
|
532
|
+
/>
|
|
533
|
+
|
|
534
|
+
{#if showsErrorState}
|
|
429
535
|
<ErrorPreview />
|
|
430
536
|
{:else if fileType === 'font'}
|
|
431
537
|
<FontPreview
|
|
@@ -435,18 +541,20 @@
|
|
|
435
541
|
/>
|
|
436
542
|
{:else if fileType === 'image' || fileType === 'svg'}
|
|
437
543
|
{#if fileType === 'svg'}
|
|
438
|
-
<div class="svg-preview-container h-[
|
|
439
|
-
<
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
/>
|
|
446
|
-
</div>
|
|
544
|
+
<div class="svg-preview-container flex min-h-[16rem] w-full items-center justify-center overflow-hidden rounded-xl bg-muted p-4">
|
|
545
|
+
<img
|
|
546
|
+
src={fileUrl}
|
|
547
|
+
alt={file.name}
|
|
548
|
+
class="fade-in max-h-[22.5rem] w-full object-contain"
|
|
549
|
+
on:load={() => (imageLoaded = true)}
|
|
550
|
+
/>
|
|
447
551
|
</div>
|
|
448
552
|
{:else}
|
|
449
|
-
|
|
553
|
+
<!-- Until the picture's size is known the slot is the loading card's body (156px); then it is as tall as the picture -->
|
|
554
|
+
<div
|
|
555
|
+
class="image-preview-slot relative h-full"
|
|
556
|
+
style={fittedImageForId === file.id ? '' : 'height: 9.75rem; overflow: hidden;'}
|
|
557
|
+
>
|
|
450
558
|
<div class="image-preview-frame h-full {imageRevealForId === file.id ? 'opacity-100' : 'opacity-0'}">
|
|
451
559
|
<ImagePreview
|
|
452
560
|
hash={file.hash}
|
|
@@ -456,6 +564,7 @@
|
|
|
456
564
|
height={file.height}
|
|
457
565
|
initiallyLoaded={imageLoaded}
|
|
458
566
|
on:load={() => imageLoaded = true}
|
|
567
|
+
on:error={() => (imageFailed = true)}
|
|
459
568
|
on:dimensions={(event) => {
|
|
460
569
|
const { width, height } = event.detail;
|
|
461
570
|
if (!width || !height) return;
|
|
@@ -464,8 +573,9 @@
|
|
|
464
573
|
/>
|
|
465
574
|
</div>
|
|
466
575
|
{#if imageRevealForId !== file.id}
|
|
467
|
-
<div class="image-preview-loader absolute inset-0 flex items-center justify-center">
|
|
468
|
-
<
|
|
576
|
+
<div class="image-preview-loader absolute inset-0 flex flex-col items-center justify-center gap-3">
|
|
577
|
+
<IconLoader2 class="size-8 animate-spin stroke-[1.333] text-primary motion-reduce:animate-none" />
|
|
578
|
+
<p class="text-caption text-muted-foreground">{$t('preview.loading')}</p>
|
|
469
579
|
</div>
|
|
470
580
|
{/if}
|
|
471
581
|
</div>
|
|
@@ -490,7 +600,11 @@
|
|
|
490
600
|
src={fileUrl}
|
|
491
601
|
/>
|
|
492
602
|
{:else if isPDF}
|
|
493
|
-
|
|
603
|
+
{#if pdfLoadError}
|
|
604
|
+
<ErrorPreview message={pdfLoadError} />
|
|
605
|
+
{:else}
|
|
606
|
+
<PDFViewer
|
|
607
|
+
class="fb-pdf-viewer w-full rounded-lg bg-muted"
|
|
494
608
|
url={fileUrl}
|
|
495
609
|
enableCacheClearing={true}
|
|
496
610
|
loadingLabel={$t('preview.pdfLoading')}
|
|
@@ -498,15 +612,21 @@
|
|
|
498
612
|
pageLabel={$t('preview.pdfPage', { page: '{page}', total: '{total}' })}
|
|
499
613
|
previousPageLabel={$t('preview.pdfPreviousPage')}
|
|
500
614
|
nextPageLabel={$t('preview.pdfNextPage')}
|
|
501
|
-
on:error={(e) => pdfLoadError = e.detail.message || '
|
|
502
|
-
on:cacheCleared={() => {
|
|
615
|
+
on:error={(e) => (pdfLoadError = e.detail.message || $t('preview.pdfFailed'))}
|
|
616
|
+
on:cacheCleared={() => {}}
|
|
503
617
|
/>
|
|
618
|
+
{/if}
|
|
504
619
|
{:else}
|
|
505
|
-
|
|
620
|
+
<!-- Figma "Preview Dialog / Unavailable": a holder 200px tall with the state centred in it -->
|
|
621
|
+
<div class="preview-unavailable flex h-[12.5rem] w-full items-center justify-center">
|
|
622
|
+
<EmptyState
|
|
623
|
+
message={$t('preview.unavailable')}
|
|
624
|
+
showActions={false}
|
|
625
|
+
icon={IconFileUnknown}
|
|
626
|
+
height="auto"
|
|
627
|
+
/>
|
|
628
|
+
</div>
|
|
506
629
|
{/if}
|
|
507
|
-
|
|
508
|
-
<!-- File Metadata Display -->
|
|
509
|
-
<!-- <FileMetadata {file} /> -->
|
|
510
630
|
</div>
|
|
511
631
|
</BaseModal>
|
|
512
632
|
|
|
@@ -5,29 +5,23 @@
|
|
|
5
5
|
import { useI18n } from '../../i18n';
|
|
6
6
|
|
|
7
7
|
const { t } = useI18n();
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
export let src: string;
|
|
10
10
|
export let fontName: string;
|
|
11
11
|
/** The sentence shown in the font. Left out, a pangram in the page's language ("The quick brown fox jumps over the lazy dog"). */
|
|
12
12
|
export let previewText: string | undefined = undefined;
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
let hasError = false;
|
|
15
15
|
let fontLoaded = false;
|
|
16
16
|
let fontFace: FontFace;
|
|
17
17
|
|
|
18
|
-
// The name goes inside CSS, so it is reduced to safe characters here too (it is the same name FilePreview
|
|
19
|
-
// passes in, since the reduction gives the same result when repeated).
|
|
20
18
|
$: safeFontName = toSafeFontFamilyName(fontName);
|
|
19
|
+
$: sample = previewText ?? $t('fontPreview.sample');
|
|
21
20
|
|
|
22
21
|
onMount(async () => {
|
|
23
22
|
try {
|
|
24
|
-
// Create a new FontFace object
|
|
25
23
|
fontFace = new FontFace(safeFontName, toCssUrlLiteral(src));
|
|
26
|
-
|
|
27
|
-
// Wait for the font to load
|
|
28
24
|
await fontFace.load();
|
|
29
|
-
|
|
30
|
-
// Add the font to the document
|
|
31
25
|
document.fonts.add(fontFace);
|
|
32
26
|
fontLoaded = true;
|
|
33
27
|
} catch (error) {
|
|
@@ -40,52 +34,41 @@
|
|
|
40
34
|
{#if hasError}
|
|
41
35
|
<ErrorPreview />
|
|
42
36
|
{:else}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
37
|
+
<!-- The specimen (Figma "Preview Dialog / Font"): the letters at 40px, then the sample at 24px, 14px and 12px -->
|
|
38
|
+
<div
|
|
39
|
+
class="font-preview-container flex w-full flex-col gap-3 rounded-xl bg-muted p-6"
|
|
40
|
+
style="font-family: '{safeFontName}', sans-serif;"
|
|
41
|
+
>
|
|
42
|
+
<p
|
|
43
|
+
class="text-start text-[2.5rem] leading-[1.3] text-foreground transition-opacity duration-base {fontLoaded
|
|
44
|
+
? 'opacity-100'
|
|
45
|
+
: 'opacity-0'}"
|
|
46
|
+
>
|
|
47
|
+
Aa
|
|
48
|
+
</p>
|
|
54
49
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
class="leading-normal {fontLoaded ? '' : 'opacity-0'} transition-opacity duration-300"
|
|
63
|
-
>
|
|
64
|
-
{previewText ?? $t('fontPreview.sample')}
|
|
65
|
-
</p>
|
|
66
|
-
</div>
|
|
50
|
+
<p
|
|
51
|
+
class="text-2xl text-foreground transition-opacity duration-base {fontLoaded
|
|
52
|
+
? 'opacity-100'
|
|
53
|
+
: 'opacity-0'}"
|
|
54
|
+
>
|
|
55
|
+
{sample}
|
|
56
|
+
</p>
|
|
67
57
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
{previewText ?? $t('fontPreview.sample')}
|
|
76
|
-
</p>
|
|
77
|
-
</div>
|
|
58
|
+
<p
|
|
59
|
+
class="text-body text-foreground transition-opacity duration-base {fontLoaded
|
|
60
|
+
? 'opacity-100'
|
|
61
|
+
: 'opacity-0'}"
|
|
62
|
+
>
|
|
63
|
+
{sample}
|
|
64
|
+
</p>
|
|
78
65
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
{previewText ?? $t('fontPreview.sample')}
|
|
87
|
-
</p>
|
|
88
|
-
</div>
|
|
89
|
-
</div>
|
|
66
|
+
<p
|
|
67
|
+
class="text-caption text-muted-foreground transition-opacity duration-base {fontLoaded
|
|
68
|
+
? 'opacity-100'
|
|
69
|
+
: 'opacity-0'}"
|
|
70
|
+
>
|
|
71
|
+
{sample}
|
|
72
|
+
</p>
|
|
90
73
|
</div>
|
|
91
|
-
{/if}
|
|
74
|
+
{/if}
|
|
@@ -169,6 +169,12 @@
|
|
|
169
169
|
}, 50);
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
// The file cannot be fetched or is not a picture: tell the preview, so it can say so instead of loading for ever.
|
|
173
|
+
function handleImageError() {
|
|
174
|
+
console.warn('ImagePreview: the image could not be loaded:', src);
|
|
175
|
+
dispatch('error');
|
|
176
|
+
}
|
|
177
|
+
|
|
172
178
|
// Function to log the current state of the thumbhash and main image elements
|
|
173
179
|
function logElementStates() {
|
|
174
180
|
if (!debugMode) return;
|
|
@@ -493,8 +499,8 @@
|
|
|
493
499
|
});
|
|
494
500
|
</script>
|
|
495
501
|
|
|
496
|
-
<div bind:this={previewRoot} class="image-preview-container w-full
|
|
497
|
-
<div
|
|
502
|
+
<div bind:this={previewRoot} class="image-preview-container flex w-full items-center justify-center overflow-hidden rounded-xl bg-muted">
|
|
503
|
+
<div
|
|
498
504
|
class="image-parent-container relative flex items-center justify-center"
|
|
499
505
|
style="width: {containerWidth}; height: {containerHeight};"
|
|
500
506
|
>
|
|
@@ -514,6 +520,7 @@
|
|
|
514
520
|
decoding="async"
|
|
515
521
|
class="preview-image h-full w-full object-contain"
|
|
516
522
|
onload={handleImageLoad}
|
|
523
|
+
onerror={handleImageError}
|
|
517
524
|
/>
|
|
518
525
|
</div>
|
|
519
526
|
{/each}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { createEventDispatcher } from 'svelte';
|
|
3
|
+
import { Button, IconButton } from '@widgetic/design-system/components';
|
|
4
|
+
import { IconChevronLeft, IconChevronRight, IconX } from '@widgetic/design-system/icons';
|
|
5
|
+
import { useI18n } from '../../i18n';
|
|
6
|
+
|
|
7
|
+
const { t } = useI18n();
|
|
8
|
+
const dispatch = createEventDispatcher<{
|
|
9
|
+
previous: void;
|
|
10
|
+
next: void;
|
|
11
|
+
select: void;
|
|
12
|
+
close: void;
|
|
13
|
+
}>();
|
|
14
|
+
|
|
15
|
+
export let title = '';
|
|
16
|
+
export let meta = '';
|
|
17
|
+
export let showMeta = true;
|
|
18
|
+
export let allowSelecting = false;
|
|
19
|
+
export let isSelected = false;
|
|
20
|
+
export let canGoPrevious = false;
|
|
21
|
+
export let canGoNext = false;
|
|
22
|
+
// What a screen reader says for the close button
|
|
23
|
+
export let closeLabel = '';
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<!--
|
|
27
|
+
The whole top row of the preview dialog (the dialog is a bare BaseModal: it has no title row of its own).
|
|
28
|
+
Figma Preview Dialog 277:2013 header: title + meta, picker actions (when selecting), close.
|
|
29
|
+
-->
|
|
30
|
+
<div class="preview-header-bar mb-4 flex items-center gap-2">
|
|
31
|
+
<div class="min-w-0 flex-1 flex flex-col gap-0 text-start">
|
|
32
|
+
<p class="text-heading-section text-foreground truncate" title={title}>{title}</p>
|
|
33
|
+
{#if showMeta && meta}
|
|
34
|
+
<p class="text-caption text-muted-foreground truncate" title={meta}>{meta}</p>
|
|
35
|
+
{/if}
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
{#if allowSelecting}
|
|
39
|
+
<div class="flex shrink-0 items-center gap-1">
|
|
40
|
+
<IconButton
|
|
41
|
+
variant="ghost"
|
|
42
|
+
label={$t('preview.previousFile')}
|
|
43
|
+
disabled={!canGoPrevious}
|
|
44
|
+
onclick={() => dispatch('previous')}
|
|
45
|
+
>
|
|
46
|
+
<IconChevronLeft class="size-4 stroke-[1.333] rtl:rotate-180" />
|
|
47
|
+
</IconButton>
|
|
48
|
+
<IconButton
|
|
49
|
+
variant="ghost"
|
|
50
|
+
label={$t('preview.nextFile')}
|
|
51
|
+
disabled={!canGoNext}
|
|
52
|
+
onclick={() => dispatch('next')}
|
|
53
|
+
>
|
|
54
|
+
<IconChevronRight class="size-4 stroke-[1.333] rtl:rotate-180" />
|
|
55
|
+
</IconButton>
|
|
56
|
+
<Button
|
|
57
|
+
variant="outline"
|
|
58
|
+
size="sm"
|
|
59
|
+
class="press-feedback"
|
|
60
|
+
onclick={() => dispatch('select')}
|
|
61
|
+
>
|
|
62
|
+
{isSelected ? $t('action.selected') : $t('action.select')}
|
|
63
|
+
</Button>
|
|
64
|
+
</div>
|
|
65
|
+
{/if}
|
|
66
|
+
|
|
67
|
+
<IconButton variant="ghost" label={closeLabel} onclick={() => dispatch('close')}>
|
|
68
|
+
<IconX class="size-4 stroke-[1.333]" />
|
|
69
|
+
</IconButton>
|
|
70
|
+
</div>
|
|
@@ -0,0 +1,32 @@
|
|
|
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 PreviewHeaderBar: $$__sveltets_2_IsomorphicComponent<{
|
|
15
|
+
title?: string;
|
|
16
|
+
meta?: string;
|
|
17
|
+
showMeta?: boolean;
|
|
18
|
+
allowSelecting?: boolean;
|
|
19
|
+
isSelected?: boolean;
|
|
20
|
+
canGoPrevious?: boolean;
|
|
21
|
+
canGoNext?: boolean;
|
|
22
|
+
closeLabel?: string;
|
|
23
|
+
}, {
|
|
24
|
+
previous: CustomEvent<void>;
|
|
25
|
+
next: CustomEvent<void>;
|
|
26
|
+
select: CustomEvent<void>;
|
|
27
|
+
close: CustomEvent<void>;
|
|
28
|
+
} & {
|
|
29
|
+
[evt: string]: CustomEvent<any>;
|
|
30
|
+
}, {}, {}, string>;
|
|
31
|
+
type PreviewHeaderBar = InstanceType<typeof PreviewHeaderBar>;
|
|
32
|
+
export default PreviewHeaderBar;
|