mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-08-26 22:29:24 +00:00
Integration with new changes - fix problems with icons
This commit is contained in:
parent
9cdeb013e6
commit
5025e06289
@ -1,7 +1,6 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
const { icons } = require('@iconify-json/material-symbols');
|
const { icons } = require('@iconify-json/material-symbols');
|
||||||
const { getIcons } = require('@iconify/utils');
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
@ -89,6 +88,8 @@ function scanForUsedIcons() {
|
|||||||
return iconArray;
|
return iconArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Main async function
|
||||||
|
async function main() {
|
||||||
// Auto-detect used icons
|
// Auto-detect used icons
|
||||||
const usedIcons = scanForUsedIcons();
|
const usedIcons = scanForUsedIcons();
|
||||||
|
|
||||||
@ -119,6 +120,9 @@ if (!needsRegeneration) {
|
|||||||
|
|
||||||
info(`🔍 Extracting ${usedIcons.length} icons from Material Symbols...`);
|
info(`🔍 Extracting ${usedIcons.length} icons from Material Symbols...`);
|
||||||
|
|
||||||
|
// Dynamic import of ES module
|
||||||
|
const { getIcons } = await import('@iconify/utils');
|
||||||
|
|
||||||
// Extract only our used icons from the full set
|
// Extract only our used icons from the full set
|
||||||
const extractedIcons = getIcons(icons, usedIcons);
|
const extractedIcons = getIcons(icons, usedIcons);
|
||||||
|
|
||||||
@ -173,3 +177,10 @@ fs.writeFileSync(typesPath, typesContent);
|
|||||||
|
|
||||||
info(`📝 Generated types: ${typesPath}`);
|
info(`📝 Generated types: ${typesPath}`);
|
||||||
info(`🎉 Icon extraction complete!`);
|
info(`🎉 Icon extraction complete!`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run the main function
|
||||||
|
main().catch(error => {
|
||||||
|
console.error('❌ Script failed:', error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
@ -327,7 +327,22 @@ const PageEditor = ({
|
|||||||
return sourceFiles.size > 0 ? sourceFiles : null;
|
return sourceFiles.size > 0 ? sourceFiles : null;
|
||||||
}, [activeFileIds, selectors]);
|
}, [activeFileIds, selectors]);
|
||||||
|
|
||||||
|
// Helper function to generate proper filename for exports
|
||||||
|
const getExportFilename = useCallback((): string => {
|
||||||
|
if (activeFileIds.length <= 1) {
|
||||||
|
// Single file - use original name
|
||||||
|
return displayDocument?.name || 'document.pdf';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiple files - use first file name with " (merged)" suffix
|
||||||
|
const firstFile = selectors.getFile(activeFileIds[0]);
|
||||||
|
if (firstFile) {
|
||||||
|
const baseName = firstFile.name.replace(/\.pdf$/i, '');
|
||||||
|
return `${baseName} (merged).pdf`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'merged-document.pdf';
|
||||||
|
}, [activeFileIds, selectors, displayDocument]);
|
||||||
|
|
||||||
const onExportSelected = useCallback(async () => {
|
const onExportSelected = useCallback(async () => {
|
||||||
if (!displayDocument || selectedPageNumbers.length === 0) return;
|
if (!displayDocument || selectedPageNumbers.length === 0) return;
|
||||||
@ -355,17 +370,18 @@ const PageEditor = ({
|
|||||||
console.log('Exporting selected pages:', selectedPageNumbers, 'with DOM rotations applied');
|
console.log('Exporting selected pages:', selectedPageNumbers, 'with DOM rotations applied');
|
||||||
|
|
||||||
const sourceFiles = getSourceFiles();
|
const sourceFiles = getSourceFiles();
|
||||||
|
const exportFilename = getExportFilename();
|
||||||
const result = sourceFiles
|
const result = sourceFiles
|
||||||
? await pdfExportService.exportPDFMultiFile(
|
? await pdfExportService.exportPDFMultiFile(
|
||||||
documentWithDOMState,
|
documentWithDOMState,
|
||||||
sourceFiles,
|
sourceFiles,
|
||||||
selectedPageIds,
|
selectedPageIds,
|
||||||
{ selectedOnly: true, filename: documentWithDOMState.name }
|
{ selectedOnly: true, filename: exportFilename }
|
||||||
)
|
)
|
||||||
: await pdfExportService.exportPDF(
|
: await pdfExportService.exportPDF(
|
||||||
documentWithDOMState,
|
documentWithDOMState,
|
||||||
selectedPageIds,
|
selectedPageIds,
|
||||||
{ selectedOnly: true, filename: documentWithDOMState.name }
|
{ selectedOnly: true, filename: exportFilename }
|
||||||
);
|
);
|
||||||
|
|
||||||
// Step 4: Download the result
|
// Step 4: Download the result
|
||||||
@ -376,7 +392,7 @@ const PageEditor = ({
|
|||||||
console.error('Export failed:', error);
|
console.error('Export failed:', error);
|
||||||
setExportLoading(false);
|
setExportLoading(false);
|
||||||
}
|
}
|
||||||
}, [displayDocument, selectedPageNumbers, mergedPdfDocument, splitPositions, getSourceFiles]);
|
}, [displayDocument, selectedPageNumbers, mergedPdfDocument, splitPositions, getSourceFiles, getExportFilename]);
|
||||||
|
|
||||||
const onExportAll = useCallback(async () => {
|
const onExportAll = useCallback(async () => {
|
||||||
if (!displayDocument) return;
|
if (!displayDocument) return;
|
||||||
@ -399,10 +415,11 @@ const PageEditor = ({
|
|||||||
const filenames: string[] = [];
|
const filenames: string[] = [];
|
||||||
|
|
||||||
const sourceFiles = getSourceFiles();
|
const sourceFiles = getSourceFiles();
|
||||||
|
const exportFilename = getExportFilename();
|
||||||
for (const doc of processedDocuments) {
|
for (const doc of processedDocuments) {
|
||||||
const result = sourceFiles
|
const result = sourceFiles
|
||||||
? await pdfExportService.exportPDFMultiFile(doc, sourceFiles, [], { filename: doc.name })
|
? await pdfExportService.exportPDFMultiFile(doc, sourceFiles, [], { filename: exportFilename })
|
||||||
: await pdfExportService.exportPDF(doc, [], { filename: doc.name });
|
: await pdfExportService.exportPDF(doc, [], { filename: exportFilename });
|
||||||
blobs.push(result.blob);
|
blobs.push(result.blob);
|
||||||
filenames.push(result.filename);
|
filenames.push(result.filename);
|
||||||
}
|
}
|
||||||
@ -416,24 +433,25 @@ const PageEditor = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const zipBlob = await zip.generateAsync({ type: 'blob' });
|
const zipBlob = await zip.generateAsync({ type: 'blob' });
|
||||||
const zipFilename = displayDocument.name.replace(/\.pdf$/i, '.zip');
|
const zipFilename = exportFilename.replace(/\.pdf$/i, '.zip');
|
||||||
|
|
||||||
pdfExportService.downloadFile(zipBlob, zipFilename);
|
pdfExportService.downloadFile(zipBlob, zipFilename);
|
||||||
} else {
|
} else {
|
||||||
// Single document - regular export
|
// Single document - regular export
|
||||||
console.log('Exporting as single PDF');
|
console.log('Exporting as single PDF');
|
||||||
const sourceFiles = getSourceFiles();
|
const sourceFiles = getSourceFiles();
|
||||||
|
const exportFilename = getExportFilename();
|
||||||
const result = sourceFiles
|
const result = sourceFiles
|
||||||
? await pdfExportService.exportPDFMultiFile(
|
? await pdfExportService.exportPDFMultiFile(
|
||||||
processedDocuments,
|
processedDocuments,
|
||||||
sourceFiles,
|
sourceFiles,
|
||||||
[],
|
[],
|
||||||
{ selectedOnly: false, filename: processedDocuments.name }
|
{ selectedOnly: false, filename: exportFilename }
|
||||||
)
|
)
|
||||||
: await pdfExportService.exportPDF(
|
: await pdfExportService.exportPDF(
|
||||||
processedDocuments,
|
processedDocuments,
|
||||||
[],
|
[],
|
||||||
{ selectedOnly: false, filename: processedDocuments.name }
|
{ selectedOnly: false, filename: exportFilename }
|
||||||
);
|
);
|
||||||
|
|
||||||
pdfExportService.downloadFile(result.blob, result.filename);
|
pdfExportService.downloadFile(result.blob, result.filename);
|
||||||
@ -444,7 +462,7 @@ const PageEditor = ({
|
|||||||
console.error('Export failed:', error);
|
console.error('Export failed:', error);
|
||||||
setExportLoading(false);
|
setExportLoading(false);
|
||||||
}
|
}
|
||||||
}, [displayDocument, mergedPdfDocument, splitPositions, getSourceFiles]);
|
}, [displayDocument, mergedPdfDocument, splitPositions, getSourceFiles, getExportFilename]);
|
||||||
|
|
||||||
// Apply DOM changes to document state using dedicated service
|
// Apply DOM changes to document state using dedicated service
|
||||||
const applyChanges = useCallback(() => {
|
const applyChanges = useCallback(() => {
|
||||||
@ -543,32 +561,6 @@ const PageEditor = ({
|
|||||||
|
|
||||||
{displayDocument && (
|
{displayDocument && (
|
||||||
<Box ref={gridContainerRef} p={0} style={{ position: 'relative' }}>
|
<Box ref={gridContainerRef} p={0} style={{ position: 'relative' }}>
|
||||||
{/* File name and basic controls */}
|
|
||||||
<Group mb="md" p="md" justify="space-between">
|
|
||||||
<TextInput
|
|
||||||
placeholder="Enter filename"
|
|
||||||
defaultValue={displayDocument.name.replace(/\.pdf$/i, '')}
|
|
||||||
style={{ minWidth: 300 }}
|
|
||||||
/>
|
|
||||||
<Group>
|
|
||||||
<Button
|
|
||||||
variant={selectionMode ? "filled" : "outline"}
|
|
||||||
onClick={() => setSelectionMode(!selectionMode)}
|
|
||||||
>
|
|
||||||
{selectionMode ? "Exit Selection" : "Select Pages"}
|
|
||||||
</Button>
|
|
||||||
{selectionMode && (
|
|
||||||
<>
|
|
||||||
<Button variant="outline" onClick={() => toggleSelectAll(displayDocument?.pages.length || 0)}>
|
|
||||||
{selectedPageNumbers.length === displayDocument.pages.length ? "Deselect All" : "Select All"}
|
|
||||||
</Button>
|
|
||||||
<Text size="sm" c="dimmed">
|
|
||||||
{selectedPageNumbers.length} selected
|
|
||||||
</Text>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Group>
|
|
||||||
</Group>
|
|
||||||
|
|
||||||
|
|
||||||
{/* Split Lines Overlay */}
|
{/* Split Lines Overlay */}
|
||||||
|
@ -31,7 +31,7 @@ export class PDFExportService {
|
|||||||
const originalPDFBytes = await pdfDocument.file.arrayBuffer();
|
const originalPDFBytes = await pdfDocument.file.arrayBuffer();
|
||||||
const sourceDoc = await PDFLibDocument.load(originalPDFBytes);
|
const sourceDoc = await PDFLibDocument.load(originalPDFBytes);
|
||||||
const blob = await this.createSingleDocument(sourceDoc, pagesToExport);
|
const blob = await this.createSingleDocument(sourceDoc, pagesToExport);
|
||||||
const exportFilename = this.generateFilename(filename || pdfDocument.name, selectedOnly);
|
const exportFilename = this.generateFilename(filename || pdfDocument.name, selectedOnly, false);
|
||||||
|
|
||||||
return { blob, filename: exportFilename };
|
return { blob, filename: exportFilename };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -62,7 +62,7 @@ export class PDFExportService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const blob = await this.createMultiSourceDocument(sourceFiles, pagesToExport);
|
const blob = await this.createMultiSourceDocument(sourceFiles, pagesToExport);
|
||||||
const exportFilename = this.generateFilename(filename || pdfDocument.name, selectedOnly);
|
const exportFilename = this.generateFilename(filename || pdfDocument.name, selectedOnly, false);
|
||||||
|
|
||||||
return { blob, filename: exportFilename };
|
return { blob, filename: exportFilename };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -51,6 +51,8 @@ export interface PageEditorFunctions {
|
|||||||
handleDelete: () => void;
|
handleDelete: () => void;
|
||||||
handleSplit: () => void;
|
handleSplit: () => void;
|
||||||
handleSplitAll: () => void;
|
handleSplitAll: () => void;
|
||||||
|
handlePageBreak: () => void;
|
||||||
|
handlePageBreakAll: () => void;
|
||||||
onExportSelected: () => void;
|
onExportSelected: () => void;
|
||||||
onExportAll: () => void;
|
onExportAll: () => void;
|
||||||
exportLoading: boolean;
|
exportLoading: boolean;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user