@file-viewer/renderer-archive 3.3.3 → 3.3.5
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/dist/archive.js +157 -95
- package/dist/archiveShared.js +9 -4
- package/package.json +2 -2
package/dist/archive.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolveFileViewerArchiveWasmUrl, resolveFileViewerArchiveWorkerUrl, resolveFileViewerRuntimeAssetBaseUrl, } from '@file-viewer/core/assets';
|
|
2
|
-
import { collectFileViewerRendererPlugins, createFileRenderHandlerLoader, createFileViewerCoreRendererRegistry, createFileViewerTranslator, createRendererRegistry, disposeFileViewerRendered, installFileViewerRendererPlugins, listFileViewerAutoRendererPresets, normalizeFileViewerUiDensity, normalizeSource, resolveFileViewerRendererPresetInputs, } from '@file-viewer/core';
|
|
3
|
-
import { buildArchiveNestedRenderContext, createArchiveCacheKey, flattenArchiveObject,
|
|
2
|
+
import { collectFileViewerRendererPlugins, createFileRenderHandlerLoader, createFileViewerCoreRendererRegistry, createFileViewerTranslator, normalizeFileViewerErrorMessage, createFileViewerI18nBindings, createFileViewerNestedI18n, createRendererRegistry, disposeFileViewerRendered, installFileViewerRendererPlugins, listFileViewerAutoRendererPresets, normalizeFileViewerUiDensity, normalizeSource, resolveFileViewerRendererPresetInputs, } from '@file-viewer/core';
|
|
3
|
+
import { buildArchiveNestedRenderContext, createArchiveCacheKey, flattenArchiveObject, getArchiveEntryExtension, isArchiveEntryDownloadAllowed, } from './archiveShared.js';
|
|
4
4
|
import { readArchiveCache, writeArchiveCache } from './archiveCache.js';
|
|
5
5
|
import { resolveArchiveLimits } from './archiveLimits.js';
|
|
6
6
|
import { hasLikelyGbkZipFilenames, isLikelyEncryptedArchive, loadArchiveEntriesWithoutWorker, } from './archiveFallback.js';
|
|
@@ -88,16 +88,6 @@ const createStyle = (documentRef) => {
|
|
|
88
88
|
style.textContent = archiveStyle;
|
|
89
89
|
return style;
|
|
90
90
|
};
|
|
91
|
-
const createElement = (documentRef, tagName, className, text) => {
|
|
92
|
-
const element = documentRef.createElement(tagName);
|
|
93
|
-
if (className) {
|
|
94
|
-
element.className = className;
|
|
95
|
-
}
|
|
96
|
-
if (text !== undefined) {
|
|
97
|
-
element.textContent = text;
|
|
98
|
-
}
|
|
99
|
-
return element;
|
|
100
|
-
};
|
|
101
91
|
const normalizeWorkerError = (reason) => {
|
|
102
92
|
if (reason instanceof Error) {
|
|
103
93
|
return reason.message;
|
|
@@ -284,12 +274,13 @@ const resolveWorkerCandidates = async (documentRef, options) => {
|
|
|
284
274
|
return candidates;
|
|
285
275
|
};
|
|
286
276
|
const renderNestedWithCurrentOptions = async (buffer, type, target, context) => {
|
|
287
|
-
const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
|
|
277
|
+
const t = createFileViewerTranslator((context === null || context === void 0 ? void 0 : context.i18n) || (context === null || context === void 0 ? void 0 : context.options));
|
|
288
278
|
const registry = await createNestedRendererRegistry(context);
|
|
289
279
|
const renderer = registry.getByExtension(type);
|
|
290
280
|
if (!(renderer === null || renderer === void 0 ? void 0 : renderer.load)) {
|
|
291
|
-
|
|
292
|
-
|
|
281
|
+
const bindings = createFileViewerI18nBindings(context === null || context === void 0 ? void 0 : context.i18n);
|
|
282
|
+
bindings.text(target, () => t('archive.error.nestedUnsupported', { type }));
|
|
283
|
+
return { $el: target, unmount() { bindings.destroy(); target.replaceChildren(); } };
|
|
293
284
|
}
|
|
294
285
|
const session = await renderer.load({
|
|
295
286
|
source: normalizeSource({
|
|
@@ -333,17 +324,27 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
333
324
|
let selectedEntry = null;
|
|
334
325
|
let nestedRendered;
|
|
335
326
|
let loading = false;
|
|
336
|
-
const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
327
|
+
const t = createFileViewerTranslator((context === null || context === void 0 ? void 0 : context.i18n) || (context === null || context === void 0 ? void 0 : context.options));
|
|
328
|
+
const createElement = t.element;
|
|
329
|
+
const formatArchiveBytes = t.formatBytes;
|
|
330
|
+
const bindings = createFileViewerI18nBindings(context === null || context === void 0 ? void 0 : context.i18n);
|
|
331
|
+
const owned = (tag, className, value) => {
|
|
332
|
+
const node = createElement(documentRef, tag, className);
|
|
333
|
+
bindings.text(node, value);
|
|
334
|
+
return node;
|
|
335
|
+
};
|
|
336
|
+
let loadingText = () => t('archive.loading.readingDirectory');
|
|
337
|
+
let loadingHint = () => t('archive.loading.readingDirectoryHint');
|
|
338
|
+
let errorText = () => '';
|
|
339
|
+
let archiveNotice = () => '';
|
|
341
340
|
let encrypted = null;
|
|
342
341
|
let filterText = '';
|
|
343
342
|
let passwordAttempt = 0;
|
|
344
343
|
let passwordResolver = null;
|
|
345
344
|
let sidebarCollapsed = false;
|
|
346
345
|
let previewSequence = 0;
|
|
346
|
+
let destroyPromise;
|
|
347
|
+
const pendingNestedCleanups = new Set();
|
|
347
348
|
const style = createStyle(documentRef);
|
|
348
349
|
const root = createElement(documentRef, 'section', 'archive-shell archive-viewer');
|
|
349
350
|
root.dataset.viewerDensity = normalizeFileViewerUiDensity((_c = (_b = context === null || context === void 0 ? void 0 : context.options) === null || _b === void 0 ? void 0 : _b.ui) === null || _c === void 0 ? void 0 : _c.density);
|
|
@@ -364,7 +365,7 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
364
365
|
const info = createElement(documentRef, 'div', 'archive-info');
|
|
365
366
|
const search = createElement(documentRef, 'input', 'archive-search');
|
|
366
367
|
search.type = 'search';
|
|
367
|
-
search
|
|
368
|
+
bindings.attr(search, 'placeholder', () => t('archive.search.placeholder'));
|
|
368
369
|
const list = createElement(documentRef, 'div', 'archive-list');
|
|
369
370
|
list.setAttribute('role', 'list');
|
|
370
371
|
sidebar.append(head, warning, info, search, list);
|
|
@@ -373,8 +374,8 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
373
374
|
const sidebarShowButton = createElement(documentRef, 'button', 'archive-sidebar-toggle');
|
|
374
375
|
sidebarShowButton.type = 'button';
|
|
375
376
|
const toolbarTitle = createElement(documentRef, 'div', 'archive-preview-title');
|
|
376
|
-
toolbarTitle.append(
|
|
377
|
-
const downloadButton =
|
|
377
|
+
toolbarTitle.append(owned('span', undefined, () => t('archive.preview.title')), owned('strong', undefined, () => t('archive.preview.chooseFile')));
|
|
378
|
+
const downloadButton = owned('button', 'archive-download-button', () => t('archive.preview.downloadFile'));
|
|
378
379
|
downloadButton.type = 'button';
|
|
379
380
|
const nestedTarget = createElement(documentRef, 'div', 'archive-nested-target');
|
|
380
381
|
const comicBook = createComicBookController({
|
|
@@ -387,6 +388,10 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
387
388
|
getEntries: () => entries,
|
|
388
389
|
openEntry: entry => void previewEntry(entry),
|
|
389
390
|
});
|
|
391
|
+
for (const [node, key] of [[comicBook.toolbarElements[0], 'epub.previousPage'], [comicBook.toolbarElements[2], 'epub.nextPage']]) {
|
|
392
|
+
bindings.attr(node, 'title', () => t(key));
|
|
393
|
+
bindings.attr(node, 'aria-label', () => t(key));
|
|
394
|
+
}
|
|
390
395
|
badge.textContent = comicBook.badge;
|
|
391
396
|
toolbar.append(sidebarShowButton, toolbarTitle, ...comicBook.toolbarElements, downloadButton);
|
|
392
397
|
preview.append(toolbar, nestedTarget);
|
|
@@ -395,14 +400,14 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
395
400
|
const stateContent = createElement(documentRef, 'div');
|
|
396
401
|
const spinner = createElement(documentRef, 'span', 'archive-spinner');
|
|
397
402
|
const stateCopy = createElement(documentRef, 'div');
|
|
398
|
-
const stateTitle =
|
|
399
|
-
const stateHint =
|
|
403
|
+
const stateTitle = owned('strong', undefined, () => loadingText());
|
|
404
|
+
const stateHint = owned('p', undefined, () => loadingHint());
|
|
400
405
|
stateCopy.append(stateTitle, stateHint);
|
|
401
406
|
stateContent.append(spinner, stateCopy);
|
|
402
407
|
state.append(stateContent);
|
|
403
408
|
root.append(state);
|
|
404
409
|
const error = createElement(documentRef, 'div', 'archive-error');
|
|
405
|
-
const errorTitle =
|
|
410
|
+
const errorTitle = owned('strong', undefined, () => t('archive.error.title'));
|
|
406
411
|
const errorMessage = createElement(documentRef, 'p');
|
|
407
412
|
error.append(errorTitle, errorMessage);
|
|
408
413
|
root.append(error);
|
|
@@ -410,17 +415,17 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
410
415
|
passwordDialog.setAttribute('role', 'dialog');
|
|
411
416
|
passwordDialog.setAttribute('aria-modal', 'true');
|
|
412
417
|
const passwordCard = createElement(documentRef, 'form', 'archive-password-card');
|
|
413
|
-
const passwordTitle =
|
|
414
|
-
const passwordDescription =
|
|
418
|
+
const passwordTitle = owned('h3', undefined, () => t('archive.password.title'));
|
|
419
|
+
const passwordDescription = owned('p', undefined, () => t('archive.password.description'));
|
|
415
420
|
const passwordInput = createElement(documentRef, 'input');
|
|
416
421
|
passwordInput.type = 'password';
|
|
417
422
|
passwordInput.autocomplete = 'current-password';
|
|
418
|
-
passwordInput
|
|
423
|
+
bindings.attr(passwordInput, 'placeholder', () => t('archive.password.placeholder'));
|
|
419
424
|
const passwordError = createElement(documentRef, 'p', 'archive-password-error');
|
|
420
425
|
const passwordActions = createElement(documentRef, 'div', 'archive-password-actions');
|
|
421
|
-
const passwordCancelButton =
|
|
426
|
+
const passwordCancelButton = owned('button', 'archive-password-cancel', () => t('archive.password.cancel'));
|
|
422
427
|
passwordCancelButton.type = 'button';
|
|
423
|
-
const passwordSubmitButton =
|
|
428
|
+
const passwordSubmitButton = owned('button', 'archive-password-submit', () => t('archive.password.confirm'));
|
|
424
429
|
passwordSubmitButton.type = 'submit';
|
|
425
430
|
passwordActions.append(passwordCancelButton, passwordSubmitButton);
|
|
426
431
|
passwordCard.append(passwordTitle, passwordDescription, passwordInput, passwordError, passwordActions);
|
|
@@ -444,10 +449,8 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
444
449
|
syncState();
|
|
445
450
|
renderEmptyState();
|
|
446
451
|
}
|
|
447
|
-
|
|
448
|
-
passwordError
|
|
449
|
-
? t('archive.password.invalid')
|
|
450
|
-
: '';
|
|
452
|
+
const invalid = Boolean(previousError || reason === 'invalid-password');
|
|
453
|
+
bindings.text(passwordError, () => invalid ? t('archive.password.invalid') : '');
|
|
451
454
|
passwordInput.value = '';
|
|
452
455
|
passwordDialog.classList.remove('archive-hidden');
|
|
453
456
|
targetWindow === null || targetWindow === void 0 ? void 0 : targetWindow.setTimeout(() => passwordInput.focus(), 0);
|
|
@@ -495,7 +498,7 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
495
498
|
event.preventDefault();
|
|
496
499
|
const password = passwordInput.value;
|
|
497
500
|
if (!password) {
|
|
498
|
-
passwordError
|
|
501
|
+
bindings.text(passwordError, () => t('archive.password.required'));
|
|
499
502
|
passwordInput.focus();
|
|
500
503
|
return;
|
|
501
504
|
}
|
|
@@ -535,9 +538,29 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
535
538
|
: visibleEntries;
|
|
536
539
|
return source.slice(0, MAX_LISTED_ENTRIES);
|
|
537
540
|
};
|
|
541
|
+
const disposeNestedPreview = (rendered) => {
|
|
542
|
+
if (!rendered)
|
|
543
|
+
return Promise.resolve();
|
|
544
|
+
const pending = Promise.resolve().then(() => disposeFileViewerRendered(rendered));
|
|
545
|
+
pendingNestedCleanups.add(pending);
|
|
546
|
+
void pending.then(() => { pendingNestedCleanups.delete(pending); }, () => { pendingNestedCleanups.delete(pending); });
|
|
547
|
+
return pending;
|
|
548
|
+
};
|
|
538
549
|
const clearNestedPreview = async () => {
|
|
539
|
-
|
|
550
|
+
const sequence = previewSequence;
|
|
551
|
+
const retired = nestedRendered;
|
|
540
552
|
nestedRendered = undefined;
|
|
553
|
+
try {
|
|
554
|
+
await disposeNestedPreview(retired);
|
|
555
|
+
}
|
|
556
|
+
catch (error) {
|
|
557
|
+
if (sequence !== previewSequence && !destroyPromise)
|
|
558
|
+
console.error(error);
|
|
559
|
+
throw error;
|
|
560
|
+
}
|
|
561
|
+
if (sequence !== previewSequence)
|
|
562
|
+
return;
|
|
563
|
+
bindings.release(nestedTarget);
|
|
541
564
|
nestedTarget.replaceChildren();
|
|
542
565
|
};
|
|
543
566
|
const closeArchive = async () => {
|
|
@@ -546,38 +569,31 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
546
569
|
archiveReader = null;
|
|
547
570
|
};
|
|
548
571
|
const syncSidebarToggleState = () => {
|
|
549
|
-
const showLabel = t('archive.sidebar.show');
|
|
550
|
-
const hideLabel = t('archive.sidebar.hide');
|
|
551
|
-
const activeLabel = sidebarCollapsed ? showLabel : hideLabel;
|
|
552
572
|
root.classList.toggle('archive-sidebar-collapsed', sidebarCollapsed);
|
|
553
573
|
sidebarHideButton.textContent = '‹';
|
|
554
574
|
sidebarShowButton.textContent = sidebarCollapsed ? '☰' : '‹';
|
|
555
|
-
sidebarHideButton
|
|
556
|
-
sidebarShowButton
|
|
557
|
-
|
|
558
|
-
|
|
575
|
+
bindings.attr(sidebarHideButton, 'title', () => t('archive.sidebar.hide'));
|
|
576
|
+
bindings.attr(sidebarShowButton, 'title', () => t(sidebarCollapsed ? 'archive.sidebar.show' : 'archive.sidebar.hide'));
|
|
577
|
+
bindings.attr(sidebarHideButton, 'aria-label', () => t('archive.sidebar.hide'));
|
|
578
|
+
bindings.attr(sidebarShowButton, 'aria-label', () => t(sidebarCollapsed ? 'archive.sidebar.show' : 'archive.sidebar.hide'));
|
|
559
579
|
sidebarHideButton.setAttribute('aria-expanded', String(!sidebarCollapsed));
|
|
560
580
|
sidebarShowButton.setAttribute('aria-expanded', String(!sidebarCollapsed));
|
|
561
581
|
};
|
|
562
582
|
const syncState = () => {
|
|
563
583
|
const archiveStats = getArchiveStats();
|
|
564
|
-
const
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
stats.textContent = statsText;
|
|
570
|
-
stats.title = statsText;
|
|
571
|
-
stats.setAttribute('aria-label', statsText);
|
|
572
|
-
warning.textContent = t('archive.warning.encrypted');
|
|
584
|
+
const label = () => t('archive.stats.summary', { count: archiveStats.count, size: formatArchiveBytes(archiveStats.totalSize), previewable: archiveStats.previewableCount });
|
|
585
|
+
bindings.text(stats, label);
|
|
586
|
+
bindings.attr(stats, 'title', label);
|
|
587
|
+
bindings.attr(stats, 'aria-label', label);
|
|
588
|
+
bindings.text(warning, () => t('archive.warning.encrypted'));
|
|
573
589
|
warning.classList.toggle('archive-hidden', !encrypted);
|
|
574
|
-
info
|
|
575
|
-
info.classList.toggle('archive-hidden', !archiveNotice);
|
|
590
|
+
bindings.text(info, () => archiveNotice());
|
|
591
|
+
info.classList.toggle('archive-hidden', !archiveNotice());
|
|
576
592
|
state.classList.toggle('archive-hidden', !loading);
|
|
577
|
-
stateTitle
|
|
578
|
-
stateHint
|
|
579
|
-
error.classList.toggle('archive-hidden', !errorText);
|
|
580
|
-
errorMessage
|
|
593
|
+
bindings.text(stateTitle, () => loadingText());
|
|
594
|
+
bindings.text(stateHint, () => loadingHint());
|
|
595
|
+
error.classList.toggle('archive-hidden', !errorText());
|
|
596
|
+
bindings.text(errorMessage, () => errorText());
|
|
581
597
|
const downloadAllowed = selectedEntry
|
|
582
598
|
? isArchiveEntryDownloadAllowed(selectedEntry, archiveOptions)
|
|
583
599
|
: false;
|
|
@@ -585,7 +601,7 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
585
601
|
downloadButton.disabled = !downloadAllowed;
|
|
586
602
|
const activeTitle = toolbarTitle.querySelector('strong');
|
|
587
603
|
if (activeTitle) {
|
|
588
|
-
activeTitle
|
|
604
|
+
bindings.text(activeTitle, () => (selectedEntry === null || selectedEntry === void 0 ? void 0 : selectedEntry.name) || t('archive.preview.chooseFile'));
|
|
589
605
|
activeTitle.setAttribute('title', (selectedEntry === null || selectedEntry === void 0 ? void 0 : selectedEntry.path) || (selectedEntry === null || selectedEntry === void 0 ? void 0 : selectedEntry.name) || '');
|
|
590
606
|
}
|
|
591
607
|
comicBook.sync();
|
|
@@ -596,26 +612,26 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
596
612
|
return;
|
|
597
613
|
}
|
|
598
614
|
const empty = createElement(documentRef, 'div', 'archive-empty');
|
|
599
|
-
empty.append(
|
|
615
|
+
empty.append(owned('strong', undefined, () => t('archive.empty.title')), owned('p', undefined, () => t('archive.empty.message')));
|
|
600
616
|
nestedTarget.replaceChildren(empty);
|
|
601
617
|
};
|
|
602
618
|
const renderEntryList = () => {
|
|
619
|
+
t.release(list);
|
|
603
620
|
list.replaceChildren();
|
|
604
621
|
getFilteredEntries().forEach(entry => {
|
|
605
622
|
const button = createElement(documentRef, 'button', 'archive-entry');
|
|
606
623
|
button.type = 'button';
|
|
607
624
|
button.style.setProperty('--entry-depth', String(entry.depth));
|
|
608
625
|
button.classList.toggle('active', (selectedEntry === null || selectedEntry === void 0 ? void 0 : selectedEntry.id) === entry.id);
|
|
609
|
-
const icon = createElement(documentRef, 'span', 'entry-ext', entry.extension || 'file');
|
|
610
|
-
icon.title = entry.extension || 'file';
|
|
626
|
+
const icon = createElement(documentRef, 'span', 'entry-ext', () => entry.extension || t('ui.archive.ui.file.971c41'));
|
|
627
|
+
t.bind(icon, node => { node.title = entry.extension || t('ui.archive.ui.file.971c41'); }, 'title');
|
|
611
628
|
const copy = createElement(documentRef, 'span', 'entry-copy');
|
|
612
629
|
const nameNode = createElement(documentRef, 'strong', undefined, entry.name);
|
|
613
630
|
const pathNode = createElement(documentRef, 'em', undefined, entry.path);
|
|
614
|
-
const
|
|
615
|
-
const sizeNode = createElement(documentRef, 'small', undefined, sizeText);
|
|
631
|
+
const sizeNode = createElement(documentRef, 'small', undefined, () => formatArchiveBytes(entry.size));
|
|
616
632
|
nameNode.title = entry.name;
|
|
617
633
|
pathNode.title = entry.path;
|
|
618
|
-
sizeNode.title =
|
|
634
|
+
t.bind(sizeNode, node => { node.title = formatArchiveBytes(entry.size); }, 'title');
|
|
619
635
|
button.title = entry.path;
|
|
620
636
|
copy.append(nameNode, pathNode);
|
|
621
637
|
button.append(icon, copy, sizeNode);
|
|
@@ -636,8 +652,10 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
636
652
|
syncState();
|
|
637
653
|
renderEmptyState();
|
|
638
654
|
};
|
|
639
|
-
const setError = (
|
|
640
|
-
errorText =
|
|
655
|
+
const setError = (cause) => {
|
|
656
|
+
errorText = typeof cause === 'function'
|
|
657
|
+
? () => String(cause())
|
|
658
|
+
: () => normalizeFileViewerErrorMessage(cause, (context === null || context === void 0 ? void 0 : context.i18n) || (context === null || context === void 0 ? void 0 : context.options));
|
|
641
659
|
syncState();
|
|
642
660
|
};
|
|
643
661
|
const terminateWorkers = (workers) => {
|
|
@@ -669,7 +687,7 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
669
687
|
return worker;
|
|
670
688
|
},
|
|
671
689
|
});
|
|
672
|
-
setLoading(true, t('archive.loading.initializingCandidate', { label: candidate.label }), t('archive.loading.initializingCandidateHint'));
|
|
690
|
+
setLoading(true, () => t('archive.loading.initializingCandidate', { label: candidate.label }), () => t('archive.loading.initializingCandidateHint'));
|
|
673
691
|
const archiveFile = createArchiveFile(documentRef, buffer, filename);
|
|
674
692
|
const archive = await withTimeout(Archive.open(archiveFile), workerTimeoutMs, t('archive.error.candidateInitTimeout', { label: candidate.label }), targetWindow);
|
|
675
693
|
archiveReader = archive;
|
|
@@ -680,7 +698,7 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
680
698
|
if (encrypted) {
|
|
681
699
|
await requestAndApplyPassword('encrypted');
|
|
682
700
|
}
|
|
683
|
-
setLoading(true, t('archive.loading.readingDirectory'), t('archive.loading.directoryReadyHint'));
|
|
701
|
+
setLoading(true, () => t('archive.loading.readingDirectory'), () => t('archive.loading.directoryReadyHint'));
|
|
684
702
|
const fileTree = await readArchiveDirectoryWithPassword(archive, candidate);
|
|
685
703
|
entries = comicBook.sortEntries(flattenArchiveObject(fileTree));
|
|
686
704
|
syncState();
|
|
@@ -698,9 +716,9 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
698
716
|
};
|
|
699
717
|
const tryOpenArchiveWithFallback = async (options = {}) => {
|
|
700
718
|
const showWorkerFallbackNotice = options.showWorkerFallbackNotice !== false;
|
|
701
|
-
setLoading(true, showWorkerFallbackNotice
|
|
719
|
+
setLoading(true, () => showWorkerFallbackNotice
|
|
702
720
|
? t('archive.loading.workerFallback')
|
|
703
|
-
: t('archive.loading.readingDirectory'), showWorkerFallbackNotice
|
|
721
|
+
: t('archive.loading.readingDirectory'), () => showWorkerFallbackNotice
|
|
704
722
|
? t('archive.loading.workerFallbackHint')
|
|
705
723
|
: t('archive.loading.directoryReadyHint'));
|
|
706
724
|
const fallbackEntries = await loadArchiveEntriesWithoutWorker(buffer, filename, {
|
|
@@ -712,7 +730,7 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
712
730
|
}
|
|
713
731
|
entries = comicBook.sortEntries(fallbackEntries);
|
|
714
732
|
encrypted = null;
|
|
715
|
-
archiveNotice = showWorkerFallbackNotice ? t('archive.notice.workerFallback') : '';
|
|
733
|
+
archiveNotice = () => showWorkerFallbackNotice ? t('archive.notice.workerFallback') : '';
|
|
716
734
|
syncState();
|
|
717
735
|
renderEntryList();
|
|
718
736
|
renderEmptyState();
|
|
@@ -721,15 +739,15 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
721
739
|
};
|
|
722
740
|
const openArchive = async () => {
|
|
723
741
|
if (buffer.byteLength > maxArchiveSize) {
|
|
724
|
-
setError(t('archive.error.tooLarge', {
|
|
742
|
+
setError(() => t('archive.error.tooLarge', {
|
|
725
743
|
size: formatArchiveBytes(buffer.byteLength),
|
|
726
744
|
limit: formatArchiveBytes(maxArchiveSize),
|
|
727
745
|
}));
|
|
728
746
|
return;
|
|
729
747
|
}
|
|
730
|
-
setLoading(true, t('archive.loading.initializingWorker'), t('archive.loading.initializingWorkerHint'));
|
|
748
|
+
setLoading(true, () => t('archive.loading.initializingWorker'), () => t('archive.loading.initializingWorkerHint'));
|
|
731
749
|
setError('');
|
|
732
|
-
archiveNotice = '';
|
|
750
|
+
archiveNotice = () => '';
|
|
733
751
|
try {
|
|
734
752
|
if (hasLegacyGbkZipFilenames && !isLikelyEncryptedArchive(buffer, filename)) {
|
|
735
753
|
if (await tryOpenArchiveWithFallback({ showWorkerFallbackNotice: false })) {
|
|
@@ -758,7 +776,7 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
758
776
|
if (isLikelyEncryptedArchive(buffer, filename)) {
|
|
759
777
|
encrypted = true;
|
|
760
778
|
syncState();
|
|
761
|
-
throw
|
|
779
|
+
throw t.error('archive.error.encryptedRequiresWorker');
|
|
762
780
|
}
|
|
763
781
|
if (await tryOpenArchiveWithFallback()) {
|
|
764
782
|
return;
|
|
@@ -767,7 +785,7 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
767
785
|
}
|
|
768
786
|
catch (nextError) {
|
|
769
787
|
console.error(nextError);
|
|
770
|
-
setError(nextError
|
|
788
|
+
setError(nextError);
|
|
771
789
|
}
|
|
772
790
|
finally {
|
|
773
791
|
setLoading(false);
|
|
@@ -781,10 +799,26 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
781
799
|
const child = createElement(documentRef, 'div', 'archive-nested-content');
|
|
782
800
|
nestedTarget.append(child);
|
|
783
801
|
const nestedContext = buildArchiveNestedRenderContext(context, entry, archiveOptions);
|
|
784
|
-
const
|
|
802
|
+
const childI18n = createFileViewerNestedI18n(nestedContext, context === null || context === void 0 ? void 0 : context.i18n, documentRef);
|
|
803
|
+
let rendered;
|
|
804
|
+
try {
|
|
805
|
+
const result = await renderNestedEntry(entryBuffer, entry.extension, child, { ...nestedContext, i18n: childI18n });
|
|
806
|
+
rendered = { $el: (result === null || result === void 0 ? void 0 : result.$el) || child, async unmount() { childI18n.destroy(); await disposeFileViewerRendered(result); } };
|
|
807
|
+
}
|
|
808
|
+
catch (error) {
|
|
809
|
+
childI18n.destroy();
|
|
810
|
+
throw error;
|
|
811
|
+
}
|
|
785
812
|
if (requestId !== previewSequence) {
|
|
786
|
-
|
|
787
|
-
|
|
813
|
+
try {
|
|
814
|
+
await disposeNestedPreview(rendered);
|
|
815
|
+
}
|
|
816
|
+
catch (error) {
|
|
817
|
+
console.error(error);
|
|
818
|
+
}
|
|
819
|
+
finally {
|
|
820
|
+
child.remove();
|
|
821
|
+
}
|
|
788
822
|
return;
|
|
789
823
|
}
|
|
790
824
|
nestedRendered = rendered;
|
|
@@ -835,14 +869,14 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
835
869
|
? shapefileEntries.reduce((sum, component) => sum + component.size, 0)
|
|
836
870
|
: entry.size;
|
|
837
871
|
if (previewSize > maxEntryPreviewSize) {
|
|
838
|
-
setError(t('archive.error.entryTooLarge', {
|
|
872
|
+
setError(() => t('archive.error.entryTooLarge', {
|
|
839
873
|
name: entry.name,
|
|
840
874
|
size: formatArchiveBytes(previewSize),
|
|
841
875
|
limit: formatArchiveBytes(maxEntryPreviewSize),
|
|
842
876
|
}));
|
|
843
877
|
return;
|
|
844
878
|
}
|
|
845
|
-
setLoading(true, t('archive.loading.extracting', { name: entry.name }));
|
|
879
|
+
setLoading(true, () => t('archive.loading.extracting', { name: entry.name }));
|
|
846
880
|
setError('');
|
|
847
881
|
try {
|
|
848
882
|
const entryBuffer = shapefileEntries.length
|
|
@@ -851,13 +885,13 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
851
885
|
if (requestId !== previewSequence) {
|
|
852
886
|
return;
|
|
853
887
|
}
|
|
854
|
-
setLoading(true, t('archive.loading.rendering', { name: entry.name }));
|
|
888
|
+
setLoading(true, () => t('archive.loading.rendering', { name: entry.name }));
|
|
855
889
|
await renderEntryBuffer(entry, entryBuffer, requestId);
|
|
856
890
|
}
|
|
857
891
|
catch (nextError) {
|
|
858
892
|
if (requestId === previewSequence) {
|
|
859
893
|
console.error(nextError);
|
|
860
|
-
setError(nextError
|
|
894
|
+
setError(nextError);
|
|
861
895
|
}
|
|
862
896
|
}
|
|
863
897
|
finally {
|
|
@@ -867,7 +901,7 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
867
901
|
}
|
|
868
902
|
}
|
|
869
903
|
const downloadEntry = async (entry) => {
|
|
870
|
-
setLoading(true, t('archive.loading.exporting', { name: entry.name }));
|
|
904
|
+
setLoading(true, () => t('archive.loading.exporting', { name: entry.name }));
|
|
871
905
|
try {
|
|
872
906
|
const entryBuffer = await extractEntryBuffer(entry);
|
|
873
907
|
const url = URL.createObjectURL(new Blob([entryBuffer]));
|
|
@@ -892,19 +926,47 @@ export default async function renderArchive(buffer, target, _type, context) {
|
|
|
892
926
|
void downloadEntry(selectedEntry);
|
|
893
927
|
}
|
|
894
928
|
});
|
|
895
|
-
syncState();
|
|
929
|
+
t.bind(root, () => syncState(), 'chrome');
|
|
896
930
|
renderEmptyState();
|
|
897
931
|
void openArchive();
|
|
898
932
|
return {
|
|
899
933
|
$el: root,
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
934
|
+
unmount() {
|
|
935
|
+
if (destroyPromise)
|
|
936
|
+
return destroyPromise;
|
|
937
|
+
previewSequence += 1;
|
|
938
|
+
bindings.destroy();
|
|
939
|
+
t.release(root);
|
|
940
|
+
const knownCleanups = [...pendingNestedCleanups];
|
|
941
|
+
destroyPromise = Promise.resolve().then(async () => {
|
|
942
|
+
const failures = [];
|
|
943
|
+
const attempt = async (action) => {
|
|
944
|
+
try {
|
|
945
|
+
await action();
|
|
946
|
+
}
|
|
947
|
+
catch (error) {
|
|
948
|
+
failures.push(error);
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
await attempt(() => closePasswordDialog(null));
|
|
952
|
+
await attempt(() => comicBook.dispose());
|
|
953
|
+
for (const cleanup of cleanups.splice(0))
|
|
954
|
+
await attempt(cleanup);
|
|
955
|
+
const results = await Promise.allSettled([...knownCleanups, clearNestedPreview()]);
|
|
956
|
+
for (const result of results)
|
|
957
|
+
if (result.status === 'rejected')
|
|
958
|
+
failures.push(result.reason);
|
|
959
|
+
await attempt(closeArchive);
|
|
960
|
+
for (const url of objectUrls)
|
|
961
|
+
await attempt(() => URL.revokeObjectURL(url));
|
|
962
|
+
await attempt(() => target.replaceChildren());
|
|
963
|
+
if (failures.length) {
|
|
964
|
+
for (const failure of failures.slice(1))
|
|
965
|
+
console.error(failure);
|
|
966
|
+
throw failures[0];
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
return destroyPromise;
|
|
908
970
|
},
|
|
909
971
|
};
|
|
910
972
|
}
|
package/dist/archiveShared.js
CHANGED
|
@@ -110,10 +110,15 @@ export const isArchiveEntryDownloadAllowed = (entry, archiveOptions) => {
|
|
|
110
110
|
return false;
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
|
-
const buildNestedOptions = (context, archiveOptions) =>
|
|
114
|
-
...
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
const buildNestedOptions = (context, archiveOptions) => {
|
|
114
|
+
const options = { ...context === null || context === void 0 ? void 0 : context.options, archive: archiveOptions };
|
|
115
|
+
if (context === null || context === void 0 ? void 0 : context.i18n) {
|
|
116
|
+
delete options.locale;
|
|
117
|
+
delete options.messages;
|
|
118
|
+
delete options.i18n;
|
|
119
|
+
}
|
|
120
|
+
return options;
|
|
121
|
+
};
|
|
117
122
|
export const buildArchiveNestedRenderContext = (context, entry, archiveOptions) => ({
|
|
118
123
|
...context,
|
|
119
124
|
filename: entry.name,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-archive",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone archive renderer plugin for File Viewer with libarchive worker, ZIP/TAR fallback, IndexedDB cache, and nested previews.",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"README.zh-CN.md"
|
|
73
73
|
],
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@file-viewer/core": "3.3.
|
|
75
|
+
"@file-viewer/core": "3.3.5",
|
|
76
76
|
"jszip": "3.10.2",
|
|
77
77
|
"libarchive.js": "^2.0.2"
|
|
78
78
|
},
|