Fix pdfjs lib no-loading in static build. Using classic Service Worker
This commit is contained in:
@ -1,14 +1,5 @@
|
||||
// lib/common/services/pdf.service.js
|
||||
|
||||
let pdfjsLib = null;
|
||||
|
||||
async function getPdfJs() {
|
||||
if (!pdfjsLib) {
|
||||
pdfjsLib = await import('https://mozilla.github.io/pdf.js/build/pdf.mjs');
|
||||
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://mozilla.github.io/pdf.js/build/pdf.worker.mjs';
|
||||
}
|
||||
return pdfjsLib;
|
||||
}
|
||||
import * as pdfjsLib from 'pdfjs-dist';
|
||||
import PdfWorkerCtor from 'pdfjs-dist/build/pdf.worker.min.mjs?worker';
|
||||
|
||||
/**
|
||||
* Загрузка PDF документа
|
||||
@ -16,9 +7,9 @@ async function getPdfJs() {
|
||||
*/
|
||||
export async function loadPdfDocument(file) {
|
||||
try {
|
||||
const lib = await getPdfJs();
|
||||
const arrayBuffer = await file.arrayBuffer();
|
||||
const loadingTask = lib.getDocument({ data: arrayBuffer });
|
||||
const worker = new pdfjsLib.PDFWorker({ port: new PdfWorkerCtor() });
|
||||
const loadingTask = pdfjsLib.getDocument({ data: arrayBuffer, worker });
|
||||
return await loadingTask.promise;
|
||||
} catch (err) {
|
||||
console.error('PDF load error:', err);
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events a11y_no_static_element_interactions a11y_interactive_supports_focus -->
|
||||
<!-- lib/pages/print/PreviewOverlay.svelte -->
|
||||
<script>
|
||||
import SelectionPage from './file_preview/SelectionPage.svelte';
|
||||
@ -7,7 +8,7 @@
|
||||
</script>
|
||||
|
||||
{#if store.activeFile}
|
||||
<div class="overlay-backdrop" onclick={store.closeOverlay} role="dialog" aria-modal="true">
|
||||
<div class="overlay-backdrop" onclick={store.closeOverlay} role="dialog" aria-modal="true" tabindex="-1">
|
||||
<div class="overlay-window-wrapper" onclick={(e) => e.stopPropagation()}>
|
||||
{#if store.viewMode === 'gallery'}
|
||||
<SelectionPage
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
let { onBack = () => {} } = $props();
|
||||
const store = createPrintStore();
|
||||
let fileInput;
|
||||
let fileInput = $state(null);
|
||||
|
||||
function handleFileSelect(event) {
|
||||
store.addFiles(event.target.files);
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events a11y_no_static_element_interactions a11y_label_has_associated_control slot_element_deprecated svelte_self_deprecated -->
|
||||
<!-- lib/pages/print/PrintUI.svelte -->
|
||||
<script>
|
||||
import { QUALITIES, COLOR_MODES, FORMATS } from '$lib/common/utils/pricing.util.js';
|
||||
|
||||
Reference in New Issue
Block a user