@widgetic/file-browser 0.5.34 → 0.5.36

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.
Files changed (68) hide show
  1. package/README.md +1 -0
  2. package/dist/components/FolderTree.svelte +46 -97
  3. package/dist/components/FolderTree.svelte.d.ts +7 -7
  4. package/dist/components/core/Dropzone.svelte +127 -0
  5. package/dist/components/core/Dropzone.svelte.d.ts +15 -0
  6. package/dist/components/core/FileBrowser.css +11 -79
  7. package/dist/components/core/FileBrowser.svelte +278 -150
  8. package/dist/components/core/FileBrowser.svelte.d.ts +0 -1
  9. package/dist/components/core/FileUploader.svelte +204 -418
  10. package/dist/components/core/FileUploader.svelte.d.ts +1 -0
  11. package/dist/components/core/Header.svelte +49 -58
  12. package/dist/components/core/Header.svelte.d.ts +1 -0
  13. package/dist/components/core/RecentFiles.svelte +135 -562
  14. package/dist/components/core/RecentFiles.svelte.d.ts +2 -4
  15. package/dist/components/core/UploadPanel.svelte +169 -0
  16. package/dist/components/core/UploadPanel.svelte.d.ts +40 -0
  17. package/dist/components/core/UploadRow.svelte +90 -0
  18. package/dist/components/core/UploadRow.svelte.d.ts +21 -0
  19. package/dist/components/core/UploadStatus.svelte +34 -128
  20. package/dist/components/core/UploadStatus.svelte.d.ts +0 -1
  21. package/dist/components/core/UploadStatusList.svelte +61 -77
  22. package/dist/components/items/FileItem.svelte +190 -532
  23. package/dist/components/items/FileItem.svelte.d.ts +1 -1
  24. package/dist/components/items/FolderItem.svelte +46 -36
  25. package/dist/components/items/FolderItem.svelte.d.ts +1 -1
  26. package/dist/components/modals/MoveDialog.svelte +142 -281
  27. package/dist/components/modals/NewFolderButton.svelte +13 -14
  28. package/dist/components/modals/SearchModal.svelte +112 -264
  29. package/dist/components/modals/SearchModal.svelte.d.ts +0 -1
  30. package/dist/components/modals/SelectedFilesModal.svelte +91 -167
  31. package/dist/components/previews/AudioPlayer.svelte +75 -58
  32. package/dist/components/previews/ErrorPreview.svelte +9 -6
  33. package/dist/components/previews/FilePreview.svelte +182 -53
  34. package/dist/components/previews/FontPreview.svelte +37 -54
  35. package/dist/components/previews/ImagePreview.svelte +9 -2
  36. package/dist/components/previews/ImagePreview.svelte.d.ts +1 -0
  37. package/dist/components/previews/PreviewHeaderBar.svelte +70 -0
  38. package/dist/components/previews/PreviewHeaderBar.svelte.d.ts +32 -0
  39. package/dist/components/previews/TextPreview.svelte +32 -40
  40. package/dist/components/previews/VideoPlayer.svelte +124 -149
  41. package/dist/components/previews/WaveformVisualizer.svelte +42 -222
  42. package/dist/components/previews/WaveformVisualizer.svelte.d.ts +1 -1
  43. package/dist/components/ui/ControlToolbar.svelte +113 -288
  44. package/dist/components/ui/ControlToolbar.svelte.d.ts +2 -3
  45. package/dist/components/ui/DragSelect.svelte +41 -248
  46. package/dist/components/ui/DropdownMenu.svelte +56 -55
  47. package/dist/components/ui/DropdownMenu.svelte.d.ts +1 -1
  48. package/dist/components/ui/FileIcon.svelte +168 -51
  49. package/dist/components/ui/FileIcon.svelte.d.ts +13 -20
  50. package/dist/components/ui/FileMetadata.svelte +20 -9
  51. package/dist/components/ui/LoadingSkeleton.svelte +5 -20
  52. package/dist/components/ui/SearchResults.svelte +50 -26
  53. package/dist/components/ui/SearchResults.svelte.d.ts +4 -0
  54. package/dist/components/ui/SelectedBadge.svelte +25 -0
  55. package/dist/components/ui/SelectedBadge.svelte.d.ts +9 -0
  56. package/dist/components/ui/TileSkeleton.svelte +15 -0
  57. package/dist/components/ui/TileSkeleton.svelte.d.ts +18 -0
  58. package/dist/components/ui/VirtualList.svelte +3 -0
  59. package/dist/components/ui/index.d.ts +1 -0
  60. package/dist/components/ui/index.js +1 -0
  61. package/dist/i18n/messages.d.ts +40 -27
  62. package/dist/i18n/messages.js +41 -28
  63. package/dist/stores/fileStore.d.ts +2 -2
  64. package/dist/stores/navigationStore.d.ts +1 -1
  65. package/dist/stores/persistentSelectStore.d.ts +1 -1
  66. package/dist/utils/gridLayout.d.ts +2 -0
  67. package/dist/utils/gridLayout.js +10 -0
  68. 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 { ImagePreview, VideoPlayer, AudioPlayer, ErrorPreview, FontPreview, TextPreview } from './';
18
- import { FileMetadata } from '../ui';
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,20 +51,28 @@
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
- // Update constants for modal spacing to account for all padding
46
- const MODAL_PADDING = 32; // 16px top + 16px bottom padding
47
- const TITLE_HEIGHT = 70; // Height of the title bar
48
- const CONTENT_PADDING = 16; // 16px padding from content div
49
- const SCROLL_AREA_PADDING = 16; // 16px padding from ScrollArea
50
- const TOTAL_VERTICAL_SPACE = MODAL_PADDING + TITLE_HEIGHT + CONTENT_PADDING + SCROLL_AREA_PADDING;
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;
54
64
 
55
65
  // The preview sits in the file browser, not in the whole window. Measuring the window first
56
66
  // paints the card at the site's width, then the portal shrinks it to this box.
67
+ // The preview is portaled into the library. In the CDN module that library sits in a shadow root,
68
+ // which document.querySelector cannot see, so a measure from the window sizes the picture too tall
69
+ // and the library box cuts the bottom off.
70
+ let measureFrom: HTMLElement | undefined;
71
+
57
72
  function hostFrame() {
58
- const host = document.querySelector(`.${target}`) || document.querySelector('.file-browser-module');
73
+ const rootNode = measureFrom?.getRootNode();
74
+ const scope = rootNode instanceof ShadowRoot ? rootNode : document;
75
+ const host = scope.querySelector(`.${target}`) || scope.querySelector('.file-browser-module');
59
76
  const width = host instanceof HTMLElement && host.clientWidth > 0 ? host.clientWidth : window.innerWidth;
60
77
  const height = host instanceof HTMLElement && host.clientHeight > 0 ? host.clientHeight : window.innerHeight;
61
78
  return { width, height };
@@ -81,23 +98,29 @@
81
98
 
82
99
  // Determine modal dimensions based on file type
83
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
+ };
84
107
  case 'audio':
85
108
  return {
86
- width: '410px',
87
- height: '234px'
109
+ width: `${Math.min(410, maxWidth)}px`,
110
+ height: '236px'
88
111
  };
89
112
  case 'image':
90
113
  case 'video':
91
- // A 100px box, then it grows to the picture. Shrinking from a large card reads as a jump.
114
+ // The size of the loading card (Figma "Preview Dialog / Loading"), then it moves to the size of the picture.
92
115
  return {
93
- width: '100px',
94
- height: '100px',
116
+ width: `${Math.min(410, maxWidth)}px`,
117
+ height: '256px',
95
118
  dynamicHeight: true
96
119
  };
97
120
  case 'font':
98
121
  return {
99
- width: '600px',
100
- height: `${400 + TOTAL_VERTICAL_SPACE}px`
122
+ width: `${Math.min(600, maxWidth)}px`,
123
+ height: `${336}px`
101
124
  };
102
125
  case 'document': {
103
126
  // For PDFs, use larger dimensions similar to images
@@ -113,18 +136,18 @@
113
136
  // For other document types (txt, md, csv, etc.), use smaller dimensions
114
137
  return {
115
138
  width: `${Math.min(566, maxWidth)}px`,
116
- height: `${360 + TOTAL_VERTICAL_SPACE}px`
139
+ height: `${460}px`
117
140
  };
118
141
  }
119
142
  case 'svg':
120
143
  return {
121
- width: '566px',
122
- height: `${360 + TOTAL_VERTICAL_SPACE}px`
144
+ width: `${Math.min(566, maxWidth)}px`,
145
+ height: `${460}px`
123
146
  };
124
147
  default:
125
148
  return {
126
- width: '410px',
127
- height: `${260 + TOTAL_VERTICAL_SPACE}px`
149
+ width: `${Math.min(566, maxWidth)}px`,
150
+ height: `${300}px`
128
151
  };
129
152
  }
130
153
  }
@@ -143,8 +166,7 @@
143
166
  const styles = getComputedStyle(element);
144
167
  margin = parseInt(styles.getPropertyValue('--app-margin').trim()) || margin;
145
168
  }
146
- // 16px each side, the same inset the player keeps around the picture.
147
- const sideInset = 32;
169
+ const sideInset = DIALOG_HORIZONTAL_PAD;
148
170
  const maxWidth = Math.max(100, frame.width - 2 * margin - sideInset);
149
171
  const maxHeight = Math.max(100, frame.height - TOTAL_VERTICAL_SPACE - 48);
150
172
  const aspect = videoWidth / videoHeight;
@@ -169,11 +191,16 @@
169
191
  let fittedImage: { width: string; height: string } | null = null;
170
192
  let fittedImageForId = '';
171
193
 
172
- $: modalDimensions = fileType === 'video' && fittedVideo && fittedVideoForId === file.id
173
- ? fittedVideo
174
- : fileType === 'image' && fittedImage && fittedImageForId === file.id
175
- ? fittedImage
176
- : getModalDimensions(fileType);
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);
177
204
  let imageRevealForId = '';
178
205
  let imageRevealTimer: ReturnType<typeof setTimeout> | undefined;
179
206
 
@@ -188,8 +215,9 @@
188
215
  const maxWidth = Math.max(160, frame.width - 2 * margin);
189
216
  const maxHeight = Math.max(120, frame.height - TOTAL_VERTICAL_SPACE - 48);
190
217
  const scale = Math.min(1, maxWidth / width, maxHeight / height);
218
+ const pictureWidth = Math.max(100, Math.round(width * scale));
191
219
  const next = {
192
- width: `${Math.max(100, Math.round(width * scale))}px`,
220
+ width: `${pictureWidth + DIALOG_HORIZONTAL_PAD}px`,
193
221
  height: `${Math.max(100, Math.round(height * scale) + TOTAL_VERTICAL_SPACE)}px`
194
222
  };
195
223
  const id = file.id;
@@ -344,6 +372,13 @@
344
372
  // Add reactive statement to check if current file is missing
345
373
  $: isMissing = $missingFiles.has(file.id);
346
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
+
347
382
  let imageLoaded = false;
348
383
 
349
384
  // Check if image is already in browser cache
@@ -371,14 +406,77 @@
371
406
  }
372
407
 
373
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
+ }
374
472
  </script>
375
473
 
376
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 -->
377
476
  <BaseModal
378
477
  class="file-preview-modal"
379
478
  bind:open
380
- title={file.name}
381
- closeLabel={$t('dialog.close')}
479
+ bare
382
480
  width={modalDimensions.width}
383
481
  height={modalDimensions.height}
384
482
  animateSize={fileType === 'image' || fileType === 'video'}
@@ -417,7 +515,23 @@
417
515
  on:spaceKey={() => dispatch('select', file)}
418
516
  >
419
517
  <!-- Preview Content Area -->
420
- {#if !hasValidUrl || $missingFiles.has(file.id)}
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}
421
535
  <ErrorPreview />
422
536
  {:else if fileType === 'font'}
423
537
  <FontPreview
@@ -427,18 +541,20 @@
427
541
  />
428
542
  {:else if fileType === 'image' || fileType === 'svg'}
429
543
  {#if fileType === 'svg'}
430
- <div class="svg-preview-container h-[600px] mx-4 flex items-center justify-center bg-[hsl(var(--grey1))] rounded-large overflow-hidden widgetic-colors">
431
- <div class="svg-preview-image-container w-[400px] h-[400px] flex items-center justify-center">
432
- <img
433
- src={fileUrl}
434
- alt={file.name}
435
- class="w-full h-full object-contain fade-in"
436
- on:load={() => imageLoaded = true}
437
- />
438
- </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
+ />
439
551
  </div>
440
552
  {:else}
441
- <div class="image-preview-slot relative h-full">
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
+ >
442
558
  <div class="image-preview-frame h-full {imageRevealForId === file.id ? 'opacity-100' : 'opacity-0'}">
443
559
  <ImagePreview
444
560
  hash={file.hash}
@@ -448,6 +564,7 @@
448
564
  height={file.height}
449
565
  initiallyLoaded={imageLoaded}
450
566
  on:load={() => imageLoaded = true}
567
+ on:error={() => (imageFailed = true)}
451
568
  on:dimensions={(event) => {
452
569
  const { width, height } = event.detail;
453
570
  if (!width || !height) return;
@@ -456,8 +573,9 @@
456
573
  />
457
574
  </div>
458
575
  {#if imageRevealForId !== file.id}
459
- <div class="image-preview-loader absolute inset-0 flex items-center justify-center">
460
- <div class="h-8 w-8 animate-spin rounded-full border-2 border-[hsl(var(--forest-green))] border-t-transparent"></div>
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>
461
579
  </div>
462
580
  {/if}
463
581
  </div>
@@ -482,7 +600,11 @@
482
600
  src={fileUrl}
483
601
  />
484
602
  {:else if isPDF}
485
- <PDFViewer class="fb-pdf-viewer"
603
+ {#if pdfLoadError}
604
+ <ErrorPreview message={pdfLoadError} />
605
+ {:else}
606
+ <PDFViewer
607
+ class="fb-pdf-viewer w-full rounded-lg bg-muted"
486
608
  url={fileUrl}
487
609
  enableCacheClearing={true}
488
610
  loadingLabel={$t('preview.pdfLoading')}
@@ -490,15 +612,22 @@
490
612
  pageLabel={$t('preview.pdfPage', { page: '{page}', total: '{total}' })}
491
613
  previousPageLabel={$t('preview.pdfPreviousPage')}
492
614
  nextPageLabel={$t('preview.pdfNextPage')}
493
- on:error={(e) => pdfLoadError = e.detail.message || 'Error loading PDF'}
494
- on:cacheCleared={() => { /* console.log('PDF cache cleared from FilePreview'); */ }}
615
+ on:error={(e) => (pdfLoadError = e.detail.message || $t('preview.pdfFailed'))}
616
+ on:cacheCleared={() => {}}
495
617
  />
618
+ {/if}
496
619
  {:else}
497
- <p class="no-preview-container text-center py-8">{$t('preview.unavailable')}</p>
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>
498
629
  {/if}
499
-
500
- <!-- File Metadata Display -->
501
- <!-- <FileMetadata {file} /> -->
630
+ </div>
502
631
  </BaseModal>
503
632
 
504
633
  <style>
@@ -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
- <div class="font-preview-container flex flex-col mx-4 space-y-8 p-8 bg-[hsl(var(--grey1))] rounded-large widgetic-radius widgetic-colors">
44
- <!-- Font Name and Sample Letters -->
45
- <div class="flex flex-col items-center space-y-4">
46
- <!-- <h3 class="text-lg font-medium text-gray-700">{fontName}</h3> -->
47
- <div
48
- style="font-family: '{safeFontName}', sans-serif;"
49
- class="text-6xl {fontLoaded ? '' : 'opacity-0'} transition-opacity duration-300"
50
- >
51
- aA
52
- </div>
53
- </div>
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
- <!-- Preview Text -->
56
- <div class="space-y-6">
57
- <!-- Large Size -->
58
- <div class="space-y-2">
59
- <p class="text-sm text-gray-500">32px</p>
60
- <p
61
- style="font-family: '{safeFontName}', sans-serif; font-size: 32px;"
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
- <!-- Medium Size -->
69
- <div class="space-y-2">
70
- <p class="text-sm text-gray-500">24px</p>
71
- <p
72
- style="font-family: '{safeFontName}', sans-serif; font-size: 24px;"
73
- class="leading-normal {fontLoaded ? '' : 'opacity-0'} transition-opacity duration-300"
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
- <!-- Small Size -->
80
- <div class="space-y-2">
81
- <p class="text-sm text-gray-500">16px</p>
82
- <p
83
- style="font-family: '{safeFontName}', sans-serif; font-size: 16px;"
84
- class="leading-normal {fontLoaded ? '' : 'opacity-0'} transition-opacity duration-300"
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 flex items-center justify-center px-4 rounded-large overflow-hidden">
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}
@@ -20,6 +20,7 @@ declare const ImagePreview: $$__sveltets_2_IsomorphicComponent<{
20
20
  height?: number | undefined;
21
21
  }, {
22
22
  dimensions: CustomEvent<any>;
23
+ error: CustomEvent<any>;
23
24
  } & {
24
25
  [evt: string]: CustomEvent<any>;
25
26
  }, {}, {}, string>;
@@ -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;