new release #190

Merged
b merged 68 commits from staging into main 2024-09-06 18:59:34 +00:00
2 changed files with 20 additions and 19 deletions
Showing only changes of commit 59c3fc69a2 - Show all commits

View File

@ -1,29 +1,12 @@
import { useEffect, useState } from 'react'
import { singletonHook } from 'react-singleton-hook'
import { getInnerContentWidth } from '../utils/pdf'
const noScaleInit = {
to: (_: number, v: number) => v,
from: (_: number, v: number) => v
}
const getInnerContentWidth = () => {
// Fetch the first container element we find
const element = document.querySelector('#content-preview')
if (element) {
const style = getComputedStyle(element)
// Calculate width without padding
const widthWithoutPadding =
element.clientWidth - parseFloat(style.padding) * 2
return widthWithoutPadding
}
// Default value
return 620
}
const useScaleImpl = () => {
const [width, setWidth] = useState(getInnerContentWidth())

View File

@ -60,6 +60,24 @@ export const readPdf = (file: File): Promise<string | ArrayBuffer> => {
})
}
export const getInnerContentWidth = () => {
// Fetch the first container element we find
const element = document.querySelector('#content-preview')
if (element) {
const style = getComputedStyle(element)
// Calculate width without padding
const widthWithoutPadding =
element.clientWidth - parseFloat(style.padding) * 2
return widthWithoutPadding
}
// Default value
return 620
}
/**
* Converts pdf to the images
* @param data pdf file bytes
@ -70,7 +88,7 @@ export const pdfToImages = async (
const pages: PdfPage[] = []
const pdf = await PDFJS.getDocument(data).promise
const canvas = document.createElement('canvas')
const width = document.querySelector('#content-preview > *')?.clientWidth || 1
const width = getInnerContentWidth()
for (let i = 0; i < pdf.numPages; i++) {
const page = await pdf.getPage(i + 1)