@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 = `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjsLib.version}/pdf.worker.min.mjs`;
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 = `[Extracted from ${file.name}]
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
@@ -26,7 +26,7 @@ import {
26
26
  useCompletion,
27
27
  useLLM,
28
28
  useStream
29
- } from "./chunk-S747S23T.js";
29
+ } from "./chunk-JD2HWBEJ.js";
30
30
  export {
31
31
  Chat,
32
32
  ChatInput,
@@ -9,7 +9,7 @@ import {
9
9
  useCompletion,
10
10
  useLLM,
11
11
  useStream
12
- } from "../chunk-S747S23T.js";
12
+ } from "../chunk-JD2HWBEJ.js";
13
13
  export {
14
14
  Chat,
15
15
  ChatApp,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blank-utils/llm",
3
- "version": "0.4.8",
3
+ "version": "0.4.10",
4
4
  "description": "Run LLMs directly in your browser with WebGPU acceleration. Supports React hooks and eager background loading.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",