@blank-utils/llm 0.4.7 → 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 { Send, Square, Paperclip } from "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
 
@@ -1064,7 +1094,6 @@ ${newText}` : newText);
1064
1094
  onClick: () => fileInputRef.current?.click(),
1065
1095
  title: "Attach image or PDF (Ctrl+V to paste)",
1066
1096
  children: [
1067
- /* @__PURE__ */ jsx2(Paperclip, { className: "w-[11px] h-[11px] opacity-70 group-hover:opacity-100 transition-opacity", strokeWidth: 1.5 }),
1068
1097
  /* @__PURE__ */ jsx2("span", { className: "text-[10px] font-bold tracking-[0.2em] uppercase whitespace-nowrap", children: "[ FILE ]" }),
1069
1098
  /* @__PURE__ */ jsx2("span", { className: "text-[9px] opacity-40 group-hover:opacity-60 transition-opacity tracking-widest whitespace-nowrap", children: "\u30D5\u30A1\u30A4\u30EB" })
1070
1099
  ]
@@ -1079,7 +1108,6 @@ ${newText}` : newText);
1079
1108
  className: "group flex items-center justify-center gap-2 px-4 py-2 rounded border bg-red-500/10 border-red-500/30 text-red-500 hover:bg-red-500/20 transition-all duration-300",
1080
1109
  onClick: onStop,
1081
1110
  children: [
1082
- /* @__PURE__ */ jsx2(Square, { className: "w-[11px] h-[11px] opacity-70 group-hover:opacity-100 transition-opacity", strokeWidth: 1.5 }),
1083
1111
  /* @__PURE__ */ jsx2("span", { className: "text-[10px] font-bold tracking-[0.2em] uppercase whitespace-nowrap", children: "[ STOP ]" }),
1084
1112
  /* @__PURE__ */ jsx2("span", { className: "text-[9px] opacity-40 group-hover:opacity-60 transition-opacity tracking-widest whitespace-nowrap", children: "\u505C\u6B62" })
1085
1113
  ]
@@ -1092,7 +1120,6 @@ ${newText}` : newText);
1092
1120
  onClick: onSend,
1093
1121
  disabled: !canSend,
1094
1122
  children: [
1095
- /* @__PURE__ */ jsx2(Send, { className: "w-[11px] h-[11px] opacity-70 group-hover:opacity-100 transition-opacity", strokeWidth: 1.5 }),
1096
1123
  /* @__PURE__ */ jsx2("span", { className: "text-[10px] font-bold tracking-[0.2em] uppercase whitespace-nowrap", children: "[ SEND ]" }),
1097
1124
  /* @__PURE__ */ jsx2("span", { className: "text-[9px] opacity-40 group-hover:opacity-60 transition-opacity tracking-widest whitespace-nowrap", children: "\u9001\u4FE1" })
1098
1125
  ]
@@ -1105,7 +1132,7 @@ ${newText}` : newText);
1105
1132
  }
1106
1133
 
1107
1134
  // src/react/components.tsx
1108
- import { RotateCcw, AlertCircle } from "lucide-react";
1135
+ import { AlertCircle } from "lucide-react";
1109
1136
  import { clsx } from "clsx";
1110
1137
  import { twMerge } from "tailwind-merge";
1111
1138
  import { Streamdown, parseMarkdownIntoBlocks } from "streamdown";
@@ -1471,7 +1498,6 @@ ${systemPrompt}` : systemPrompt;
1471
1498
  onClick: reload,
1472
1499
  className: "group flex items-center justify-center min-w-max gap-3 px-6 py-3 rounded-md border border-red-500/30 bg-red-500/10 text-red-500 hover:bg-red-500/20 transition-all duration-300",
1473
1500
  children: [
1474
- /* @__PURE__ */ jsx3(RotateCcw, { className: "w-[11px] h-[11px] opacity-70 group-hover:opacity-100 transition-opacity", strokeWidth: 1.5 }),
1475
1501
  /* @__PURE__ */ jsx3("span", { className: "text-[11px] font-bold tracking-[0.2em] uppercase", children: "[ REBOOT ]" }),
1476
1502
  /* @__PURE__ */ jsx3("span", { className: "text-[10px] opacity-40 group-hover:opacity-60 transition-opacity tracking-widest", children: "\u518D\u8D77\u52D5" })
1477
1503
  ]
package/dist/index.css CHANGED
@@ -2319,9 +2319,6 @@ video {
2319
2319
  .h-8 {
2320
2320
  height: 2rem;
2321
2321
  }
2322
- .h-\[11px\] {
2323
- height: 11px;
2324
- }
2325
2322
  .h-\[1px\] {
2326
2323
  height: 1px;
2327
2324
  }
@@ -2367,9 +2364,6 @@ video {
2367
2364
  .w-8 {
2368
2365
  width: 2rem;
2369
2366
  }
2370
- .w-\[11px\] {
2371
- width: 11px;
2372
- }
2373
2367
  .w-full {
2374
2368
  width: 100%;
2375
2369
  }
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  useCompletion,
27
27
  useLLM,
28
28
  useStream
29
- } from "./chunk-NMWUZC4S.js";
29
+ } from "./chunk-ZCKQLTCD.js";
30
30
  export {
31
31
  Chat,
32
32
  ChatInput,
@@ -2319,9 +2319,6 @@ video {
2319
2319
  .h-8 {
2320
2320
  height: 2rem;
2321
2321
  }
2322
- .h-\[11px\] {
2323
- height: 11px;
2324
- }
2325
2322
  .h-\[1px\] {
2326
2323
  height: 1px;
2327
2324
  }
@@ -2367,9 +2364,6 @@ video {
2367
2364
  .w-8 {
2368
2365
  width: 2rem;
2369
2366
  }
2370
- .w-\[11px\] {
2371
- width: 11px;
2372
- }
2373
2367
  .w-full {
2374
2368
  width: 100%;
2375
2369
  }
@@ -9,7 +9,7 @@ import {
9
9
  useCompletion,
10
10
  useLLM,
11
11
  useStream
12
- } from "../chunk-NMWUZC4S.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.7",
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",