@widgetic/file-browser 0.5.48 → 0.5.49

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 (81) hide show
  1. package/dist/actions/dragSelectedToFolder.js +115 -104
  2. package/dist/components/FolderTree.svelte.d.ts +7 -4
  3. package/dist/components/core/FileBrowser.svelte +1 -3
  4. package/dist/components/core/dropzoneClick.js +2 -3
  5. package/dist/components/previews/FilePreview.svelte.d.ts +2 -2
  6. package/dist/config.js +3 -4
  7. package/dist/i18n/context.js +2 -2
  8. package/dist/i18n/errors.js +1 -2
  9. package/dist/i18n/messages.js +2 -2
  10. package/dist/i18n/text.js +2 -2
  11. package/dist/mediaLibrary/capabilities.js +3 -4
  12. package/dist/mediaLibrary/context.js +3 -4
  13. package/dist/mediaLibrary/errors.js +35 -46
  14. package/dist/mediaLibrary/normalize.js +42 -45
  15. package/dist/mediaLibrary/paging.js +45 -100
  16. package/dist/mediaLibrary/resolve.js +95 -214
  17. package/dist/mediaLibrary/treeOps.js +20 -40
  18. package/dist/mediaLibrary/urls.js +10 -12
  19. package/dist/mediaLibrary/widgetic.js +54 -140
  20. package/dist/stores/dragStore.js +1 -1
  21. package/dist/stores/fileStore.d.ts +3 -3
  22. package/dist/stores/fileStore.js +37 -44
  23. package/dist/stores/folderCountStore.js +11 -12
  24. package/dist/stores/missingFilesStore.js +3 -3
  25. package/dist/stores/navigationStore.d.ts +1 -1
  26. package/dist/stores/navigationStore.js +178 -217
  27. package/dist/stores/persistentSelectStore.d.ts +1 -1
  28. package/dist/stores/persistentSelectStore.js +94 -117
  29. package/dist/stores/searchStore.js +1 -1
  30. package/dist/stores/uploadApiStore.js +7 -7
  31. package/dist/stores/viewportStore.js +4 -4
  32. package/dist/types/index.js +1 -0
  33. package/dist/utils/apiConfig.js +9 -9
  34. package/dist/utils/brandKitLibraryTree.js +42 -57
  35. package/dist/utils/dateUtils.js +9 -11
  36. package/dist/utils/dragToFolder/batchMoveResult.js +54 -114
  37. package/dist/utils/dragToFolder/folderDropTarget.js +17 -23
  38. package/dist/utils/dragToFolder/springStep.js +3 -4
  39. package/dist/utils/fileGoneProbe.js +16 -65
  40. package/dist/utils/fileKinds.js +13 -14
  41. package/dist/utils/fileNames.js +7 -7
  42. package/dist/utils/fileOperations.js +332 -440
  43. package/dist/utils/fileTypes.js +14 -19
  44. package/dist/utils/fileUtils.js +31 -85
  45. package/dist/utils/folderUtils.js +4 -5
  46. package/dist/utils/gridLayout.js +7 -7
  47. package/dist/utils/imagePreviewCache.js +15 -26
  48. package/dist/utils/imagePreviewFrame.js +13 -13
  49. package/dist/utils/imagePreviewVisualState.js +4 -5
  50. package/dist/utils/imageTransform.js +14 -27
  51. package/dist/utils/itemMenuCapabilities.js +7 -7
  52. package/dist/utils/libraryTree.js +39 -55
  53. package/dist/utils/pendingUploadDeletes.js +113 -289
  54. package/dist/utils/previewKeys.js +1 -1
  55. package/dist/utils/previewListNavigation.js +11 -13
  56. package/dist/utils/previewNavigation.js +7 -10
  57. package/dist/utils/recentFiles.js +6 -16
  58. package/dist/utils/recentFilesLimit.js +2 -2
  59. package/dist/utils/removeItems.js +29 -61
  60. package/dist/utils/resolveFileUrl.js +6 -6
  61. package/dist/utils/safeText.js +12 -14
  62. package/dist/utils/searchDropdownPhase.js +2 -2
  63. package/dist/utils/searchItems.js +14 -30
  64. package/dist/utils/searchNavigation.js +5 -5
  65. package/dist/utils/uploadAuth.js +36 -111
  66. package/dist/utils/uploadDisplayProgress.js +1 -1
  67. package/dist/utils/uploadLimits.js +66 -138
  68. package/dist/utils/uploadListReconcile.js +11 -24
  69. package/dist/utils/uploadPanelDismiss.js +1 -1
  70. package/dist/utils/uploadPanelProgress.js +4 -4
  71. package/dist/utils/uploadProgressMath.js +11 -13
  72. package/dist/utils/uploadRefusals.js +24 -40
  73. package/dist/utils/uploadResponseMapping.js +8 -9
  74. package/dist/utils/uploadUiHelpers.js +17 -17
  75. package/dist/utils/userUploadsStorage.js +133 -270
  76. package/dist/utils/videoFrame.js +2 -2
  77. package/dist/utils/widgeticDelete.js +30 -103
  78. package/dist/utils/widgeticTusUpload.js +105 -189
  79. package/dist/utils/widgeticUpload.js +62 -130
  80. package/dist/utils/xhrMultipartUpload.js +116 -164
  81. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import { translateEnglish } from '../i18n/context';
2
2
  // Define which document types can be displayed as text
3
- export var PREVIEWABLE_TEXT_EXTENSIONS = ['.txt', '.md', '.csv', '.json', '.xml', '.log'];
4
- export var FILE_TYPES = {
3
+ export const PREVIEWABLE_TEXT_EXTENSIONS = ['.txt', '.md', '.csv', '.json', '.xml', '.log'];
4
+ export const FILE_TYPES = {
5
5
  image: ['.jpg', '.jpeg', '.png', '.gif', '.webp', '.heic', '.heif'],
6
6
  audio: ['.mp3'],
7
7
  video: ['.mp4'],
@@ -9,7 +9,7 @@ export var FILE_TYPES = {
9
9
  font: ['.ttf', '.otf', '.woff', '.woff2'],
10
10
  svg: ['.svg']
11
11
  };
12
- export var FILTER_OPTIONS = ['all', 'image', 'audio', 'video', 'document', 'font', 'svg'];
12
+ export const FILTER_OPTIONS = ['all', 'image', 'audio', 'video', 'document', 'font', 'svg'];
13
13
  export function getAllowedFileTypes(filter) {
14
14
  if (filter === 'all') {
15
15
  return Object.values(FILE_TYPES).flat();
@@ -18,9 +18,8 @@ export function getAllowedFileTypes(filter) {
18
18
  }
19
19
  export function getFileTypeFromExtension(extension) {
20
20
  extension = extension.toLowerCase();
21
- for (var _i = 0, _a = Object.entries(FILE_TYPES); _i < _a.length; _i++) {
22
- var _b = _a[_i], type = _b[0], extensions = _b[1];
23
- if (extensions.some(function (ext) { return ext.toLowerCase() === extension; })) {
21
+ for (const [type, extensions] of Object.entries(FILE_TYPES)) {
22
+ if (extensions.some(ext => ext.toLowerCase() === extension)) {
24
23
  return type;
25
24
  }
26
25
  }
@@ -28,17 +27,15 @@ export function getFileTypeFromExtension(extension) {
28
27
  }
29
28
  // New function to check if a file can be displayed as text
30
29
  export function isPreviewableTextFile(filename) {
31
- var _a;
32
- var extension = '.' + ((_a = filename.split('.').pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase());
30
+ const extension = '.' + filename.split('.').pop()?.toLowerCase();
33
31
  return PREVIEWABLE_TEXT_EXTENSIONS.includes(extension);
34
32
  }
35
33
  /**
36
34
  * One sentence that lists every kind of file with its extensions ("Add images (.jpg, .png), audio (.mp3) ..."). Pass the
37
35
  * `t` of the File Browser to have it in the page's language (English when left out).
38
36
  */
39
- export function formatFileTypesForDisplay(translate) {
40
- if (translate === void 0) { translate = translateEnglish; }
41
- var separator = translate('list.separator');
37
+ export function formatFileTypesForDisplay(translate = translateEnglish) {
38
+ const separator = translate('list.separator');
42
39
  return translate('fileTypes.addAll', {
43
40
  images: FILE_TYPES.image.join(separator),
44
41
  audio: FILE_TYPES.audio.join(separator),
@@ -52,13 +49,12 @@ export function formatFileTypesForDisplay(translate) {
52
49
  * The help text about what can be uploaded under a filter: "Allowed types: .jpg, .png ...", and for fonts how a font
53
50
  * file must be named. Pass the `t` of the File Browser to have it in the page's language (English when left out).
54
51
  */
55
- export function formatAllowedTypesForDisplay(filter, translate) {
56
- if (translate === void 0) { translate = translateEnglish; }
57
- var separator = translate('list.separator');
52
+ export function formatAllowedTypesForDisplay(filter, translate = translateEnglish) {
53
+ const separator = translate('list.separator');
58
54
  if (filter === 'all') {
59
55
  return translate('fileTypes.allowed', { types: Object.values(FILE_TYPES).flat().join(separator) });
60
56
  }
61
- var allowedTypes = '';
57
+ let allowedTypes = '';
62
58
  if (filter === 'svg') {
63
59
  allowedTypes = translate('fileTypes.allowedSvg');
64
60
  }
@@ -69,11 +65,11 @@ export function formatAllowedTypesForDisplay(filter, translate) {
69
65
  allowedTypes = translate('fileTypes.allowed', { types: FILE_TYPES[filter].join(separator) });
70
66
  }
71
67
  if (filter === 'font') {
72
- allowedTypes += "\n\n".concat(translate('fileTypes.fontNaming'));
68
+ allowedTypes += `\n\n${translate('fileTypes.fontNaming')}`;
73
69
  }
74
70
  return allowedTypes;
75
71
  }
76
- export var MIME_TYPES = {
72
+ export const MIME_TYPES = {
77
73
  // Images
78
74
  'image/jpeg': '.jpg',
79
75
  'image/jpg': '.jpg',
@@ -116,10 +112,9 @@ export function getMimeTypeExtension(mimeType) {
116
112
  * uploads declare image/heic.
117
113
  */
118
114
  export function normalizeFileMimeType(file) {
119
- var _a;
120
115
  if (file.type)
121
116
  return file;
122
- var extension = '.' + ((_a = file.name.split('.').pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase());
117
+ const extension = '.' + file.name.split('.').pop()?.toLowerCase();
123
118
  if (extension === '.heic' || extension === '.heif') {
124
119
  return new File([file], file.name, { type: 'image/heic', lastModified: file.lastModified });
125
120
  }
@@ -1,39 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
1
  import { FILE_TYPES } from './fileTypes';
38
2
  import { isKnownNonImageFile } from './fileKinds';
39
3
  import { translateEnglish } from '../i18n/context';
@@ -52,10 +16,10 @@ import icUnorganizedFolder from '../static/icons/unorganized-folder.svg?url';
52
16
  * Pattern to match if a path is already an absolute URL
53
17
  * This will match http://, https://, data:, etc.
54
18
  */
55
- var absoluteUrlPattern = /^(?:[a-z+]+:)?\/\//i;
19
+ const absoluteUrlPattern = /^(?:[a-z+]+:)?\/\//i;
56
20
  // Show logs for debugging
57
- var showLogs = false;
58
- var bundledIconUrls = {
21
+ let showLogs = false;
22
+ const bundledIconUrls = {
59
23
  '/icons/audio.svg': icAudio,
60
24
  '/icons/checked.svg': icChecked,
61
25
  '/icons/document.svg': icDocument,
@@ -69,33 +33,29 @@ var bundledIconUrls = {
69
33
  '/icons/unorganized-folder.svg': icUnorganizedFolder,
70
34
  };
71
35
  /** The message for each unit of size, from bytes to terabytes. */
72
- var SIZE_MESSAGES = ['size.bytes', 'size.kb', 'size.mb', 'size.gb', 'size.tb'];
36
+ const SIZE_MESSAGES = ['size.bytes', 'size.kb', 'size.mb', 'size.gb', 'size.tb'];
73
37
  /** A number of a size, written the way `locale` writes numbers, with up to `fractionDigits` decimals and no thousands separator ("1.5", "1,5"). */
74
38
  function formatSizeNumber(value, locale, minimumFractionDigits, maximumFractionDigits) {
75
- return new Intl.NumberFormat(locale, { minimumFractionDigits: minimumFractionDigits, maximumFractionDigits: maximumFractionDigits, useGrouping: false }).format(value);
39
+ return new Intl.NumberFormat(locale, { minimumFractionDigits, maximumFractionDigits, useGrouping: false }).format(value);
76
40
  }
77
41
  /**
78
42
  * A size in bytes as the biggest unit that keeps it above 1: "0 Bytes", "1.5 MB". The units and the number format
79
43
  * follow the language: pass the `t` and the `locale` of the File Browser (English when left out).
80
44
  */
81
- export function formatFileSize(bytes, translate, locale) {
82
- if (translate === void 0) { translate = translateEnglish; }
83
- if (locale === void 0) { locale = 'en'; }
45
+ export function formatFileSize(bytes, translate = translateEnglish, locale = 'en') {
84
46
  if (bytes === 0)
85
47
  return translate('size.bytes', { size: formatSizeNumber(0, locale, 0, 2) });
86
- var k = 1024;
87
- var unitIndex = Math.min(SIZE_MESSAGES.length - 1, Math.max(0, Math.floor(Math.log(bytes) / Math.log(k))));
48
+ const k = 1024;
49
+ const unitIndex = Math.min(SIZE_MESSAGES.length - 1, Math.max(0, Math.floor(Math.log(bytes) / Math.log(k))));
88
50
  return translate(SIZE_MESSAGES[unitIndex], { size: formatSizeNumber(bytes / Math.pow(k, unitIndex), locale, 0, 2) });
89
51
  }
90
52
  /** A size in bytes as kilobytes with one decimal ("12.3 KB"), the way the upload list shows it. */
91
- export function formatKilobytes(bytes, translate, locale) {
92
- if (translate === void 0) { translate = translateEnglish; }
93
- if (locale === void 0) { locale = 'en'; }
53
+ export function formatKilobytes(bytes, translate = translateEnglish, locale = 'en') {
94
54
  return translate('size.kb', { size: formatSizeNumber(bytes / 1024, locale, 1, 1) });
95
55
  }
96
56
  export function getFileIcon(fileName) {
97
- var fileType = getFileType(fileName);
98
- var extension = getFileExtension(fileName).toLowerCase();
57
+ const fileType = getFileType(fileName);
58
+ const extension = getFileExtension(fileName).toLowerCase();
99
59
  switch (fileType) {
100
60
  case 'audio':
101
61
  return getAssetUrl('/icons/audio.svg');
@@ -115,16 +75,14 @@ export function getFileIcon(fileName) {
115
75
  }
116
76
  }
117
77
  export function getFileExtension(fileNameOrUrl) {
118
- var _a;
119
- var cleanPath = fileNameOrUrl.split(/[?#]/)[0];
120
- var fileName = cleanPath.split('/').pop() || '';
121
- var extension = ((_a = fileName.split('.').pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || '';
122
- return extension ? ".".concat(extension) : '';
78
+ const cleanPath = fileNameOrUrl.split(/[?#]/)[0];
79
+ const fileName = cleanPath.split('/').pop() || '';
80
+ const extension = fileName.split('.').pop()?.toLowerCase() || '';
81
+ return extension ? `.${extension}` : '';
123
82
  }
124
83
  export function getFileType(fileNameOrUrl) {
125
- var extension = getFileExtension(fileNameOrUrl);
126
- for (var _i = 0, _a = Object.entries(FILE_TYPES); _i < _a.length; _i++) {
127
- var _b = _a[_i], type = _b[0], extensions = _b[1];
84
+ const extension = getFileExtension(fileNameOrUrl);
85
+ for (const [type, extensions] of Object.entries(FILE_TYPES)) {
128
86
  if (extensions.includes(extension.toLowerCase())) {
129
87
  return type;
130
88
  }
@@ -133,14 +91,14 @@ export function getFileType(fileNameOrUrl) {
133
91
  }
134
92
  /** Prefer mime / thumbnail URL when the filename has no real image extension (e.g. IMG_8658). */
135
93
  export function getItemFileType(item) {
136
- var mime = (item.mimeType || '').toLowerCase();
94
+ const mime = (item.mimeType || '').toLowerCase();
137
95
  if (mime.startsWith('image/'))
138
96
  return 'image';
139
97
  if (mime.startsWith('video/'))
140
98
  return 'video';
141
99
  if (mime.startsWith('audio/'))
142
100
  return 'audio';
143
- var fromName = getFileType(item.name || '');
101
+ const fromName = getFileType(item.name || '');
144
102
  if (fromName !== 'document')
145
103
  return fromName;
146
104
  // A PDF, a text file or any other named non-picture stays that kind. A thumbnail
@@ -151,34 +109,22 @@ export function getItemFileType(item) {
151
109
  }
152
110
  if (/IMG_\d+/i.test(item.name || ''))
153
111
  return 'image';
154
- var urlHint = item.thumbnail || item.url || '';
112
+ const urlHint = item.thumbnail || item.url || '';
155
113
  if (urlHint && (/^data:image\//i.test(urlHint) || /\.(jpe?g|png|gif|webp|avif|svg)(\?|$)/i.test(urlHint.split(/[?#]/)[0]))) {
156
114
  return 'image';
157
115
  }
158
116
  return getFileType(item.url || item.name || '');
159
117
  }
160
- export function checkFileExists(url) {
161
- return __awaiter(this, void 0, Promise, function () {
162
- var response, error_1;
163
- return __generator(this, function (_a) {
164
- switch (_a.label) {
165
- case 0:
166
- if (!url)
167
- return [2 /*return*/, false];
168
- _a.label = 1;
169
- case 1:
170
- _a.trys.push([1, 3, , 4]);
171
- return [4 /*yield*/, fetch(url, { method: 'HEAD' })];
172
- case 2:
173
- response = _a.sent();
174
- return [2 /*return*/, response.ok];
175
- case 3:
176
- error_1 = _a.sent();
177
- return [2 /*return*/, false];
178
- case 4: return [2 /*return*/];
179
- }
180
- });
181
- });
118
+ export async function checkFileExists(url) {
119
+ if (!url)
120
+ return false;
121
+ try {
122
+ const response = await fetch(url, { method: 'HEAD' });
123
+ return response.ok;
124
+ }
125
+ catch (error) {
126
+ return false;
127
+ }
182
128
  }
183
129
  /**
184
130
  * Gets the correct URL for a static asset using SvelteKit's assets path
@@ -195,7 +141,7 @@ export function getAssetUrl(path) {
195
141
  if (absoluteUrlPattern.test(path) || /^(?:data|blob):/i.test(path))
196
142
  return path;
197
143
  // Ensure path starts with a slash
198
- var normalizedPath = path.startsWith('/') ? path : "/".concat(path);
144
+ let normalizedPath = path.startsWith('/') ? path : `/${path}`;
199
145
  if (bundledIconUrls[normalizedPath]) {
200
146
  return bundledIconUrls[normalizedPath];
201
147
  }
@@ -1,11 +1,10 @@
1
1
  import { getAssetUrl } from './fileUtils';
2
2
  import { getFileTypeOf } from './fileKinds';
3
- var UNORGANIZED_THRESHOLD = 50;
3
+ const UNORGANIZED_THRESHOLD = 50;
4
4
  export function countFilteredItems(folder, filter) {
5
- var count = 0;
5
+ let count = 0;
6
6
  if (folder.type === 'folder' && folder.children) {
7
- for (var _i = 0, _a = folder.children; _i < _a.length; _i++) {
8
- var item = _a[_i];
7
+ for (const item of folder.children) {
9
8
  if (item.type === 'folder') {
10
9
  count += countFilteredItems(item, filter);
11
10
  }
@@ -17,7 +16,7 @@ export function countFilteredItems(folder, filter) {
17
16
  return count;
18
17
  }
19
18
  export function getFolderIcon(folder, filter) {
20
- var fileCount = folder.matchingFileCount || countFilteredItems(folder, filter);
19
+ const fileCount = folder.matchingFileCount || countFilteredItems(folder, filter);
21
20
  if (fileCount === 0) {
22
21
  return getAssetUrl('/icons/empty-folder.svg');
23
22
  }
@@ -2,17 +2,17 @@
2
2
  * Grid column count from the file browser panel width (Figma File Tile ~264px, 16px gap).
3
3
  * At 1152px panel width → 4 columns; scales up to 6 on very wide panels.
4
4
  */
5
- export var GRID_TILE_MIN_WIDTH_PX = 264;
6
- export var GRID_GAP_PX = 16;
7
- export var GRID_MAX_COLUMNS = 6;
5
+ export const GRID_TILE_MIN_WIDTH_PX = 264;
6
+ export const GRID_GAP_PX = 16;
7
+ export const GRID_MAX_COLUMNS = 6;
8
8
  /** Same rhythm for the recent-files strip (Figma 24px gap, ~3 cards at 1152px). */
9
- export var RECENT_TILE_MIN_WIDTH_PX = 352;
10
- export var RECENT_GAP_PX = 24;
11
- export var RECENT_MAX_COLUMNS = 5;
9
+ export const RECENT_TILE_MIN_WIDTH_PX = 352;
10
+ export const RECENT_GAP_PX = 24;
11
+ export const RECENT_MAX_COLUMNS = 5;
12
12
  function columnsForWidth(width, minTile, gap, maxColumns) {
13
13
  if (width < 420)
14
14
  return 1;
15
- var columns = Math.floor((width + gap) / (minTile + gap));
15
+ const columns = Math.floor((width + gap) / (minTile + gap));
16
16
  return Math.min(maxColumns, Math.max(1, columns));
17
17
  }
18
18
  /** Main folder/file grid. */
@@ -1,26 +1,15 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
1
  /** Natural pixel size of a picture the preview has already decoded, keyed by its fetch URL. */
13
- var MAX_CACHED_URLS = 64;
14
- var naturalSizeByUrl = new Map();
2
+ const MAX_CACHED_URLS = 64;
3
+ const naturalSizeByUrl = new Map();
15
4
  export function rememberImageNaturalSize(url, width, height) {
16
5
  if (!url || !width || !height)
17
6
  return;
18
7
  if (naturalSizeByUrl.has(url)) {
19
8
  naturalSizeByUrl.delete(url);
20
9
  }
21
- naturalSizeByUrl.set(url, { width: width, height: height });
10
+ naturalSizeByUrl.set(url, { width, height });
22
11
  while (naturalSizeByUrl.size > MAX_CACHED_URLS) {
23
- var oldest = naturalSizeByUrl.keys().next().value;
12
+ const oldest = naturalSizeByUrl.keys().next().value;
24
13
  if (oldest)
25
14
  naturalSizeByUrl.delete(oldest);
26
15
  }
@@ -28,20 +17,20 @@ export function rememberImageNaturalSize(url, width, height) {
28
17
  export function getCachedImageNaturalSize(url) {
29
18
  if (!url)
30
19
  return undefined;
31
- var hit = naturalSizeByUrl.get(url);
32
- return hit ? __assign({}, hit) : undefined;
20
+ const hit = naturalSizeByUrl.get(url);
21
+ return hit ? { ...hit } : undefined;
33
22
  }
34
23
  /**
35
24
  * The natural size of a picture the browser already holds decoded (shown before, in a tile or in this preview), found at once.
36
25
  * A picture that is not in the browser's memory is not waited for: it starts loading and this returns nothing.
37
26
  */
38
27
  export function probeDecodedImage(url) {
39
- var known = getCachedImageNaturalSize(url);
28
+ const known = getCachedImageNaturalSize(url);
40
29
  if (known)
41
30
  return known;
42
31
  if (!url || typeof Image === 'undefined')
43
32
  return undefined;
44
- var probe = new Image();
33
+ const probe = new Image();
45
34
  probe.src = url;
46
35
  if (probe.complete && probe.naturalWidth > 0 && probe.naturalHeight > 0) {
47
36
  rememberImageNaturalSize(url, probe.naturalWidth, probe.naturalHeight);
@@ -49,27 +38,27 @@ export function probeDecodedImage(url) {
49
38
  }
50
39
  return undefined;
51
40
  }
52
- var inFlightByUrl = new Map();
41
+ const inFlightByUrl = new Map();
53
42
  /** Warm the decoder cache; resolves when decode finishes or the request fails. */
54
43
  export function preloadImageUrl(url) {
55
44
  if (!url)
56
45
  return Promise.resolve();
57
- var cached = naturalSizeByUrl.get(url);
46
+ const cached = naturalSizeByUrl.get(url);
58
47
  if (cached)
59
48
  return Promise.resolve();
60
- var pending = inFlightByUrl.get(url);
49
+ const pending = inFlightByUrl.get(url);
61
50
  if (pending)
62
51
  return pending;
63
- var job = new Promise(function (resolve) {
64
- var img = new Image();
65
- img.onload = function () {
52
+ const job = new Promise((resolve) => {
53
+ const img = new Image();
54
+ img.onload = () => {
66
55
  if (img.naturalWidth && img.naturalHeight) {
67
56
  rememberImageNaturalSize(url, img.naturalWidth, img.naturalHeight);
68
57
  }
69
58
  inFlightByUrl.delete(url);
70
59
  resolve();
71
60
  };
72
- img.onerror = function () {
61
+ img.onerror = () => {
73
62
  inFlightByUrl.delete(url);
74
63
  resolve();
75
64
  };
@@ -1,4 +1,4 @@
1
- var DEFAULTS = {
1
+ const DEFAULTS = {
2
2
  sideMargin: 24,
3
3
  dialogHorizontalPad: 50,
4
4
  headerBlock: 52,
@@ -12,18 +12,18 @@ var DEFAULTS = {
12
12
  * Pictures are not upscaled beyond their natural size.
13
13
  */
14
14
  export function computeImagePreviewModalFrame(naturalWidth, naturalHeight, insets) {
15
- var hostWidth = insets.hostWidth, hostHeight = insets.hostHeight, _a = insets.sideMargin, sideMargin = _a === void 0 ? DEFAULTS.sideMargin : _a, _b = insets.dialogHorizontalPad, dialogHorizontalPad = _b === void 0 ? DEFAULTS.dialogHorizontalPad : _b, _c = insets.headerBlock, headerBlock = _c === void 0 ? DEFAULTS.headerBlock : _c, _d = insets.verticalPad, verticalPad = _d === void 0 ? DEFAULTS.verticalPad : _d, _e = insets.contentVerticalGutter, contentVerticalGutter = _e === void 0 ? DEFAULTS.contentVerticalGutter : _e, _f = insets.minDialogWidth, minDialogWidth = _f === void 0 ? DEFAULTS.minDialogWidth : _f, _g = insets.maxHostFraction, maxHostFraction = _g === void 0 ? DEFAULTS.maxHostFraction : _g;
16
- var totalVerticalSpace = verticalPad + headerBlock;
17
- var maxPictureWidth = Math.max(100, hostWidth * maxHostFraction - 2 * sideMargin - dialogHorizontalPad);
18
- var maxPictureHeight = Math.max(100, hostHeight * maxHostFraction - totalVerticalSpace - contentVerticalGutter);
19
- var scale = Math.min(1, maxPictureWidth / naturalWidth, maxPictureHeight / naturalHeight);
20
- var pictureWidth = Math.max(68, Math.round(naturalWidth * scale));
21
- var pictureHeight = Math.max(68, Math.round(naturalHeight * scale));
22
- var cardWidth = Math.min(Math.max(minDialogWidth, pictureWidth + dialogHorizontalPad), Math.max(pictureWidth + dialogHorizontalPad, hostWidth * maxHostFraction - 2 * sideMargin));
15
+ const { hostWidth, hostHeight, sideMargin = DEFAULTS.sideMargin, dialogHorizontalPad = DEFAULTS.dialogHorizontalPad, headerBlock = DEFAULTS.headerBlock, verticalPad = DEFAULTS.verticalPad, contentVerticalGutter = DEFAULTS.contentVerticalGutter, minDialogWidth = DEFAULTS.minDialogWidth, maxHostFraction = DEFAULTS.maxHostFraction } = insets;
16
+ const totalVerticalSpace = verticalPad + headerBlock;
17
+ const maxPictureWidth = Math.max(100, hostWidth * maxHostFraction - 2 * sideMargin - dialogHorizontalPad);
18
+ const maxPictureHeight = Math.max(100, hostHeight * maxHostFraction - totalVerticalSpace - contentVerticalGutter);
19
+ const scale = Math.min(1, maxPictureWidth / naturalWidth, maxPictureHeight / naturalHeight);
20
+ const pictureWidth = Math.max(68, Math.round(naturalWidth * scale));
21
+ const pictureHeight = Math.max(68, Math.round(naturalHeight * scale));
22
+ const cardWidth = Math.min(Math.max(minDialogWidth, pictureWidth + dialogHorizontalPad), Math.max(pictureWidth + dialogHorizontalPad, hostWidth * maxHostFraction - 2 * sideMargin));
23
23
  return {
24
- width: "".concat(cardWidth, "px"),
25
- height: "".concat(pictureHeight + totalVerticalSpace, "px"),
26
- pictureWidth: pictureWidth,
27
- pictureHeight: pictureHeight
24
+ width: `${cardWidth}px`,
25
+ height: `${pictureHeight + totalVerticalSpace}px`,
26
+ pictureWidth,
27
+ pictureHeight
28
28
  };
29
29
  }
@@ -9,15 +9,14 @@
9
9
  * picture fades in (a picture that arrives long after the card was sized shows at once).
10
10
  */
11
11
  /** How long a picture may take before the spinner shows ("more than a few seconds" in the request, round 26). */
12
- export var IMAGE_SLOW_LOADER_DELAY_MS = 2000;
12
+ export const IMAGE_SLOW_LOADER_DELAY_MS = 2000;
13
13
  /** The card eases to the size of its picture for this long, the picture waits for the end of that move. */
14
- export var IMAGE_FRAME_EASE_MS = 220;
14
+ export const IMAGE_FRAME_EASE_MS = 220;
15
15
  /**
16
16
  * How much longer the picture has to wait, once it has loaded, so that it appears after the card's move.
17
17
  * 0 when the card reached its size long ago; never more than the move itself (a clock that went backwards).
18
18
  */
19
- export function imageRevealDelayMs(frameSizedAtMs, nowMs, easeMs) {
20
- if (easeMs === void 0) { easeMs = IMAGE_FRAME_EASE_MS; }
21
- var elapsedMs = nowMs - frameSizedAtMs;
19
+ export function imageRevealDelayMs(frameSizedAtMs, nowMs, easeMs = IMAGE_FRAME_EASE_MS) {
20
+ const elapsedMs = nowMs - frameSizedAtMs;
22
21
  return Math.min(easeMs, Math.max(0, easeMs - elapsedMs));
23
22
  }
@@ -4,36 +4,25 @@
4
4
  * right-sized variant instead of the full-size original. Non-CDN URLs
5
5
  * (localhost, blob:, external providers) pass through untouched.
6
6
  */
7
- var __assign = (this && this.__assign) || function () {
8
- __assign = Object.assign || function(t) {
9
- for (var s, i = 1, n = arguments.length; i < n; i++) {
10
- s = arguments[i];
11
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
12
- t[p] = s[p];
13
- }
14
- return t;
15
- };
16
- return __assign.apply(this, arguments);
17
- };
18
- var _a;
19
7
  /** Hosts allowed for transformation — keeps unique-transformation billing bounded. */
20
- var TRANSFORM_HOSTS = ((_a = import.meta.env.PUBLIC_IMAGE_TRANSFORM_HOSTS) !== null && _a !== void 0 ? _a : 'static.widgetic.com,cdn.widgetic.com')
8
+ const TRANSFORM_HOSTS = (import.meta.env.PUBLIC_IMAGE_TRANSFORM_HOSTS ??
9
+ 'static.widgetic.com,cdn.widgetic.com')
21
10
  .split(',')
22
- .map(function (host) { return host.trim().toLowerCase(); })
11
+ .map((host) => host.trim().toLowerCase())
23
12
  .filter(Boolean);
24
- var ENABLED = import.meta.env.PUBLIC_IMAGE_TRANSFORMS !== 'false';
13
+ const ENABLED = import.meta.env.PUBLIC_IMAGE_TRANSFORMS !== 'false';
25
14
  function isTransformable(url) {
26
15
  if (!ENABLED || !url)
27
16
  return false;
28
17
  if (url.startsWith('blob:') || url.startsWith('data:'))
29
18
  return false;
30
19
  try {
31
- var parsed = new URL(url);
20
+ const parsed = new URL(url);
32
21
  if (parsed.protocol !== 'https:')
33
22
  return false;
34
23
  return TRANSFORM_HOSTS.includes(parsed.hostname.toLowerCase());
35
24
  }
36
- catch (_a) {
25
+ catch {
37
26
  return false;
38
27
  }
39
28
  }
@@ -42,32 +31,30 @@ function isTransformable(url) {
42
31
  * URL when transformation is disabled or the host is not allowlisted.
43
32
  */
44
33
  export function buildTransformedUrl(url, options) {
45
- var _a;
46
- var source = url !== null && url !== void 0 ? url : '';
34
+ const source = url ?? '';
47
35
  if (!isTransformable(source))
48
36
  return source;
49
- var params = new URLSearchParams();
37
+ const params = new URLSearchParams();
50
38
  params.set('width', String(options.width));
51
39
  if (options.height)
52
40
  params.set('height', String(options.height));
53
41
  if (options.fit)
54
42
  params.set('fit', options.fit);
55
- params.set('q', String((_a = options.quality) !== null && _a !== void 0 ? _a : 75));
43
+ params.set('q', String(options.quality ?? 75));
56
44
  // format=auto lets Cloudflare negotiate AVIF/WebP from the Accept header.
57
45
  params.set('format', 'auto');
58
- var parsed = new URL(source);
59
- return "".concat(parsed.origin, "/cdn-cgi/image?").concat(params.toString(), "/").concat(encodeURIComponent(source));
46
+ const parsed = new URL(source);
47
+ return `${parsed.origin}/cdn-cgi/image?${params.toString()}/${encodeURIComponent(source)}`;
60
48
  }
61
49
  /**
62
50
  * Builds a srcset across a fixed width ladder. Widths should come from a small
63
51
  * allowlist — every unique width is billed as a separate transformation.
64
52
  */
65
- export function buildImageSrcset(url, widths, options) {
66
- if (options === void 0) { options = {}; }
67
- var source = url !== null && url !== void 0 ? url : '';
53
+ export function buildImageSrcset(url, widths, options = {}) {
54
+ const source = url ?? '';
68
55
  if (!isTransformable(source))
69
56
  return undefined;
70
57
  return widths
71
- .map(function (width) { return "".concat(buildTransformedUrl(source, __assign(__assign({}, options), { width: width })), " ").concat(width, "w"); })
58
+ .map((width) => `${buildTransformedUrl(source, { ...options, width })} ${width}w`)
72
59
  .join(', ');
73
60
  }
@@ -3,11 +3,11 @@
3
3
  * The legacy Uploads folder (`folder_my_uploads`) is treated like any other folder — nothing here is reserved.
4
4
  */
5
5
  export function itemMenuCapabilities(input) {
6
- var capabilities = input.capabilities, isFolder = input.isFolder, isMissing = input.isMissing, fileUrl = input.fileUrl;
7
- var canRename = capabilities.rename && !isMissing;
8
- var canMove = capabilities.folders && !isMissing;
9
- var canDownload = capabilities.download && !isMissing && !isFolder && Boolean(fileUrl);
10
- var canDelete = capabilities.delete;
11
- var hasAnyAction = canRename || canMove || canDownload || canDelete;
12
- return { canRename: canRename, canMove: canMove, canDownload: canDownload, canDelete: canDelete, hasAnyAction: hasAnyAction };
6
+ const { capabilities, isFolder, isMissing, fileUrl } = input;
7
+ const canRename = capabilities.rename && !isMissing;
8
+ const canMove = capabilities.folders && !isMissing;
9
+ const canDownload = capabilities.download && !isMissing && !isFolder && Boolean(fileUrl);
10
+ const canDelete = capabilities.delete;
11
+ const hasAnyAction = canRename || canMove || canDownload || canDelete;
12
+ return { canRename, canMove, canDownload, canDelete, hasAnyAction };
13
13
  }