-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Image support: PDFPointer now can open various images * It's not possible to show the thumbnails and go to the next/previous page, since only few formats support multiple images in the same container * HEIC images will be re-encoded using the heic2any library - Drag files: files can now be dragged on the "Open Files" card, and they'll automatically be open - Improved exportation: on Chromium-based browsers, if only an image must be exported the "showSaveFilePicker" function will be called instead of the "showDirectoryPicker"
- Loading branch information
1 parent
5dc507b
commit a1359e5
Showing
14 changed files
with
298 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.0.4 | ||
2.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ const filestoCache = [ | |
'./assets/index.css', | ||
'./assets/index.js', | ||
'./assets/path2d-polyfill.min.js', | ||
'https://cdn.jsdelivr.net/npm/[email protected]/dist/heic2any.min.js' | ||
]; | ||
let language = navigator.language || navigator.userLanguage; | ||
if (language.indexOf("it") !== -1) filestoCache.push('./translationItems/it.json') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { useEffect, useState } from "react"; | ||
import { useEffect, useRef, useState } from "react"; | ||
import Header from "./Components/Header"; | ||
import Card from "./Components/Card"; | ||
import { DynamicImg } from "./Components/DynamicImg"; | ||
|
@@ -11,14 +11,22 @@ import { CustomProp } from "./Interfaces/CustomOptions"; | |
import ThemeManager from "./Scripts/ThemeManager"; | ||
import Lang from "./Scripts/LanguageTranslations"; | ||
import BackgroundManager from "./Scripts/BackgroundManager"; | ||
import AlertManager from "./Scripts/AlertManager"; | ||
PDFJS.GlobalWorkerOptions.workerSrc = pdfjsWorker; | ||
interface State { | ||
PDFObj: PDFDocumentProxy | null, | ||
PDFObj?: PDFDocumentProxy, | ||
imgObj?: HTMLImageElement | ||
hideTab?: boolean | ||
} | ||
declare global { | ||
interface Window { | ||
heic2any: (e: any) => Promise<Blob> | ||
} | ||
} | ||
let installationPrompt: any; | ||
export default function App() { | ||
let [CurrentState, UpdateState] = useState<State>({ PDFObj: null }); | ||
let [CurrentState, UpdateState] = useState<State>({}); | ||
let cardContainer = useRef<HTMLDivElement>(null); | ||
useEffect(() => { | ||
let theme = JSON.parse(localStorage.getItem("PDFPointer-CurrentTheme") ?? "[]") as CustomProp["lists"]; | ||
if (theme && theme.length !== 0) ThemeManager.apply(theme); | ||
|
@@ -36,24 +44,55 @@ export default function App() { | |
}); | ||
}, []) | ||
async function getNewState(file: File) { | ||
let doc = PDFJS.getDocument(await file.arrayBuffer()); | ||
document.title = `${file.name} - PDFPointer`; | ||
let res = await doc.promise; | ||
UpdateState(prevState => { return { ...prevState, PDFObj: res } }); | ||
if (file.type === "application/pdf") { | ||
let doc = PDFJS.getDocument(await file.arrayBuffer()); | ||
let res = await doc.promise; | ||
UpdateState(prevState => { return { ...prevState, PDFObj: res } }); | ||
} else { | ||
const img = new Image(); | ||
const blob = new Blob([await file.arrayBuffer()]); | ||
let hasTriedError = false; | ||
img.src = URL.createObjectURL(blob); | ||
img.onload = () => UpdateState(prevState => { return { ...prevState, imgObj: img } }); | ||
img.onerror = async () => { | ||
const availableJpgFormats = [".jpg", ".jpeg", ".jfif", ".pjpeg", ".pjp", ".heic", ".heif", ".heifs", ".heics"] // All the extensions that might contain an HEIC image | ||
if (availableJpgFormats.indexOf(file.name.substring(file.name.lastIndexOf("."))) !== -1 && !hasTriedError) { // Try opening HEIC image by transcoding it using the heic2any library | ||
AlertManager.alert({ id: "HeicImage", text: "The image provided might be a HEIC image. Transcoding is being tried." }) | ||
hasTriedError = true; // Stop a possible loop, by executing this only one time | ||
const script = document.createElement("script"); | ||
script.src = `https://cdn.jsdelivr.net/npm/[email protected]/dist/heic2any.min.js`; | ||
script.onload = async () => { | ||
img.src = URL.createObjectURL(await window.heic2any({ blob })); | ||
} | ||
document.body.append(script); | ||
} | ||
} | ||
} | ||
} | ||
return <> | ||
<Header></Header><br></br> | ||
{CurrentState.PDFObj === null ? <> | ||
<div className={!CurrentState.hideTab && !window.matchMedia('(display-mode: standalone)').matches ? "doubleFlex" : undefined}> | ||
{!CurrentState.PDFObj && !CurrentState.imgObj ? <> | ||
<div onDragOver={(e) => e.preventDefault()} ref={cardContainer} onDragEnter={() => cardContainer.current?.classList?.add("drag")} onDragLeave={() => cardContainer.current?.classList?.remove("drag")} onDrop={async (e) => { // Get the dropped file, and open it | ||
e.preventDefault(); | ||
cardContainer.current?.classList?.remove("drag"); | ||
if (e.dataTransfer.items) { | ||
if (e.dataTransfer.items[0].kind === "file") { | ||
const file = e.dataTransfer.items[0].getAsFile(); | ||
file && getNewState(file); | ||
} | ||
} else getNewState(e.dataTransfer.files[0]); | ||
}} className={!CurrentState.hideTab && !window.matchMedia('(display-mode: standalone)').matches ? "doubleFlex" : undefined}> | ||
<Card> | ||
<h2>{Lang("Choose file")}</h2> | ||
<div className="center" style={{ width: "100%" }}> | ||
<DynamicImg id="laptop" width={200}></DynamicImg><br></br> | ||
</div> | ||
<i>{Lang("Don't worry. Everything will stay on your device.")}</i><br></br><br></br> | ||
<i>{`${Lang("Don't worry. Everything will stay on your device.")} ${Lang("You can also drop files here.")} ${window.matchMedia('(display-mode: standalone)').matches ? Lang("Moreover, you can also open the files from the native file picker (Open With -> PDFPointer)") : ""}`}</i><br></br><br></br> | ||
<button onClick={() => { // Get the PDF file | ||
let input = document.createElement("input"); | ||
input.type = "file"; | ||
input.accept = "application/pdf, image/*" | ||
input.onchange = () => { | ||
input.files !== null && getNewState(input.files[0]); | ||
} | ||
|
@@ -76,7 +115,7 @@ export default function App() { | |
</div> | ||
</> : <> | ||
<Card> | ||
<PdfObj pdfObj={CurrentState.PDFObj}></PdfObj> | ||
<PdfObj pdfObj={CurrentState.PDFObj} imgObj={CurrentState.imgObj}></PdfObj> | ||
</Card> | ||
</> | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.