@blank-utils/llm 0.4.8 → 0.4.10
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,13 @@ 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 =
|
|
942
|
+
pdfjsLib.GlobalWorkerOptions.workerSrc = new URL(
|
|
943
|
+
"pdfjs-dist/build/pdf.worker.min.mjs",
|
|
944
|
+
import.meta.url
|
|
945
|
+
).toString();
|
|
944
946
|
const pdf = await pdfjsLib.getDocument(arrayBuffer).promise;
|
|
945
947
|
let fullText = "";
|
|
948
|
+
const maxPages = Math.min(pdf.numPages, 10);
|
|
946
949
|
for (let i = 1; i <= pdf.numPages; i++) {
|
|
947
950
|
const page = await pdf.getPage(i);
|
|
948
951
|
const textContent = await page.getTextContent();
|
|
@@ -951,8 +954,38 @@ function ChatInput({
|
|
|
951
954
|
${pageText}
|
|
952
955
|
|
|
953
956
|
`;
|
|
957
|
+
if (i <= maxPages && onImageAdd) {
|
|
958
|
+
const viewport = page.getViewport({ scale: 2 });
|
|
959
|
+
const canvas = document.createElement("canvas");
|
|
960
|
+
const context = canvas.getContext("2d");
|
|
961
|
+
if (context) {
|
|
962
|
+
canvas.height = viewport.height;
|
|
963
|
+
canvas.width = viewport.width;
|
|
964
|
+
await page.render({ canvasContext: context, viewport }).promise;
|
|
965
|
+
const dataUrl = canvas.toDataURL("image/jpeg", 0.8);
|
|
966
|
+
const arr = dataUrl.split(",");
|
|
967
|
+
if (arr.length > 1) {
|
|
968
|
+
const mimeMatch = arr[0]?.match(/:(.*?);/);
|
|
969
|
+
const mime = mimeMatch ? mimeMatch[1] : void 0;
|
|
970
|
+
const base64Data = arr[1];
|
|
971
|
+
if (mime && base64Data) {
|
|
972
|
+
const bstr = atob(base64Data);
|
|
973
|
+
let n = bstr.length;
|
|
974
|
+
const u8arr = new Uint8Array(n);
|
|
975
|
+
while (n--) {
|
|
976
|
+
u8arr[n] = bstr.charCodeAt(n);
|
|
977
|
+
}
|
|
978
|
+
const imgFile = new File([u8arr], `__PDF__${file.name}__page${i}.jpg`, { type: mime });
|
|
979
|
+
const id = Math.random().toString(36).substring(7);
|
|
980
|
+
onImageAdd({ id, dataUrl, file: imgFile, name: imgFile.name });
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}
|
|
954
985
|
}
|
|
955
|
-
const newText =
|
|
986
|
+
const newText = `\u{1F4C4} PDF: ${file.name} (${pdf.numPages} pages total, showing images for first ${maxPages} pages)
|
|
987
|
+
|
|
988
|
+
Extracted Text:
|
|
956
989
|
${fullText}`;
|
|
957
990
|
onChange(value ? `${value}
|
|
958
991
|
|
package/dist/index.js
CHANGED
package/dist/react/index.js
CHANGED
package/package.json
CHANGED