@blank-utils/llm 0.4.8 → 0.4.9
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.
|
@@ -894,7 +894,6 @@ import { useRef as useRef3, useEffect as useEffect3, useState as useState3, useM
|
|
|
894
894
|
// src/react/chat-input.tsx
|
|
895
895
|
import "react";
|
|
896
896
|
import { useRef as useRef2, useEffect as useEffect2, useCallback as useCallback2, useState as useState2 } from "react";
|
|
897
|
-
import "lucide-react";
|
|
898
897
|
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
899
898
|
function ChatInput({
|
|
900
899
|
value,
|
|
@@ -940,9 +939,10 @@ function ChatInput({
|
|
|
940
939
|
const arrayBuffer = e.target?.result;
|
|
941
940
|
if (!arrayBuffer) return;
|
|
942
941
|
const pdfjsLib = await import("pdfjs-dist");
|
|
943
|
-
pdfjsLib.GlobalWorkerOptions.workerSrc = `https://
|
|
942
|
+
pdfjsLib.GlobalWorkerOptions.workerSrc = `https://unpkg.com/pdfjs-dist@${pdfjsLib.version}/build/pdf.worker.min.mjs`;
|
|
944
943
|
const pdf = await pdfjsLib.getDocument(arrayBuffer).promise;
|
|
945
944
|
let fullText = "";
|
|
945
|
+
const maxPages = Math.min(pdf.numPages, 10);
|
|
946
946
|
for (let i = 1; i <= pdf.numPages; i++) {
|
|
947
947
|
const page = await pdf.getPage(i);
|
|
948
948
|
const textContent = await page.getTextContent();
|
|
@@ -951,8 +951,38 @@ function ChatInput({
|
|
|
951
951
|
${pageText}
|
|
952
952
|
|
|
953
953
|
`;
|
|
954
|
+
if (i <= maxPages && onImageAdd) {
|
|
955
|
+
const viewport = page.getViewport({ scale: 2 });
|
|
956
|
+
const canvas = document.createElement("canvas");
|
|
957
|
+
const context = canvas.getContext("2d");
|
|
958
|
+
if (context) {
|
|
959
|
+
canvas.height = viewport.height;
|
|
960
|
+
canvas.width = viewport.width;
|
|
961
|
+
await page.render({ canvasContext: context, viewport }).promise;
|
|
962
|
+
const dataUrl = canvas.toDataURL("image/jpeg", 0.8);
|
|
963
|
+
const arr = dataUrl.split(",");
|
|
964
|
+
if (arr.length > 1) {
|
|
965
|
+
const mimeMatch = arr[0]?.match(/:(.*?);/);
|
|
966
|
+
const mime = mimeMatch ? mimeMatch[1] : void 0;
|
|
967
|
+
const base64Data = arr[1];
|
|
968
|
+
if (mime && base64Data) {
|
|
969
|
+
const bstr = atob(base64Data);
|
|
970
|
+
let n = bstr.length;
|
|
971
|
+
const u8arr = new Uint8Array(n);
|
|
972
|
+
while (n--) {
|
|
973
|
+
u8arr[n] = bstr.charCodeAt(n);
|
|
974
|
+
}
|
|
975
|
+
const imgFile = new File([u8arr], `__PDF__${file.name}__page${i}.jpg`, { type: mime });
|
|
976
|
+
const id = Math.random().toString(36).substring(7);
|
|
977
|
+
onImageAdd({ id, dataUrl, file: imgFile, name: imgFile.name });
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
954
982
|
}
|
|
955
|
-
const newText =
|
|
983
|
+
const newText = `\u{1F4C4} PDF: ${file.name} (${pdf.numPages} pages total, showing images for first ${maxPages} pages)
|
|
984
|
+
|
|
985
|
+
Extracted Text:
|
|
956
986
|
${fullText}`;
|
|
957
987
|
onChange(value ? `${value}
|
|
958
988
|
|
package/dist/index.js
CHANGED
package/dist/react/index.js
CHANGED
package/package.json
CHANGED