@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://cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjsLib.version}/pdf.worker.min.mjs`;
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 = `[Extracted from ${file.name}]
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
@@ -26,7 +26,7 @@ import {
26
26
  useCompletion,
27
27
  useLLM,
28
28
  useStream
29
- } from "./chunk-S747S23T.js";
29
+ } from "./chunk-ZCKQLTCD.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-ZCKQLTCD.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.9",
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",