feat(editor): add image insertion with OCR support and size limit handling
Add image button with dropdown menu for uploading local images or inserting from URL. Integrate VLM-based OCR to extract text context from images and include in AI suggestions. Implement document size limits to disable AI when exceeding threshold. Refactor copilot plugin with per-view runtime state and OCR context injection. Add OCR cache utility for managing image metadata. Add code splitting configuration for optimized bundle size.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
const SIZE_LIMIT = 64 * 1024
|
||||
|
||||
const ocrCache = new Map()
|
||||
|
||||
export function setOcrCache(filename, text) {
|
||||
ocrCache.set(filename, text)
|
||||
}
|
||||
|
||||
export function getOcrCache(filename) {
|
||||
return ocrCache.get(filename) || ''
|
||||
}
|
||||
|
||||
export function clearOcrCache(filename) {
|
||||
ocrCache.delete(filename)
|
||||
}
|
||||
|
||||
export function hasOcrCache(filename) {
|
||||
return ocrCache.has(filename)
|
||||
}
|
||||
|
||||
export function clearAllOcrCache() {
|
||||
ocrCache.clear()
|
||||
}
|
||||
|
||||
export function calculateOcrSize(imageFilenames) {
|
||||
let total = 0
|
||||
for (const name of imageFilenames) {
|
||||
const text = ocrCache.get(name)
|
||||
if (text) total += new Blob([text]).size
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
export function checkSizeLimit(docTextSize, imageFilenames) {
|
||||
const ocrSize = calculateOcrSize(imageFilenames)
|
||||
const total = docTextSize + ocrSize
|
||||
return {
|
||||
size: total,
|
||||
docSize: docTextSize,
|
||||
ocrSize: ocrSize,
|
||||
overLimit: total > SIZE_LIMIT
|
||||
}
|
||||
}
|
||||
|
||||
export const OCR_SIZE_LIMIT = SIZE_LIMIT
|
||||
Reference in New Issue
Block a user